# profinet — IEC 61158 Real-Time Cyclic IO & DCP (0x8892 / UDP 34964) (`profinet`)

> **FrameAssembly v3.3.0** · Protocol 15 of 81 · Canonical URL: https://frameassembly-lang.dev/docs/protocols/profinet

- **Full Protocol Name:** IEC 61158 PROFINET Real-Time & DCP (Ethernet 0x8892 / UDP 34964)
- **Keyword:** `profinet`
- **OSI Layer & Transport:** Layer 2 · EtherType 0x8892 (or UDP 34964)
- **Host Endpoint Rule:** MAC-Only or IP
- **Standards:** IEC 61158, IEC 61784-2, PROFINET IO
- **Wireshark Display Filter:** `pn_rt || pn_dcp`
- **Wire Encapsulation:** `Ethernet II -> PROFINET RT (EtherType 0x8892 (or UDP 34964))`

## Overview

Factory-floor deterministic Ethernet on `0x8892` (or routed over UDP `34964` with `transport udp`): `profinet` stamps exact `frameid`, cyclic counters, and DCP identify requests without touching a live Siemens line.

PROFINET (`profinet`, IEC 61158) is the dominant real-time industrial Ethernet fieldbus across discrete manufacturing, robotics, and Siemens SIMATIC automation cells. Cyclic Real-Time (`RT_CLASS_1`/`RT_CLASS_3`) I/O data and Discovery and Basic Configuration Protocol (`DCP`) frames run directly over Layer 2 (`EtherType 0x8892`) prepended with a 16-bit `FrameID` (`0x8000..0xfbff` RT cyclic, `0xfefe`/`0xfeff` DCP Identify) and suffixed with a 4-byte cyclic trailer (`CycleCounter`, `DataStatus`, `TransferStatus`).

FrameAssembly emits native `0x8892` Layer 2 frames over MAC-only or IP hosts by default—and when you append `transport udp` over IP hosts, it automatically switches to **PROFINET RT over UDP (`dstport 34964`)** for routed L3 factory-backbone conduits.

## Minimal Quickstart (`profinet_quickstart.frasm`)

```frameassembly
host io_controller { mac 00:0e:8c:aa:00:01 }
host io_device     { mac 00:0e:8c:bb:00:10 }

compile {
    io_controller -> io_device profinet frameid 0x8000 cycle 100 datastatus 0x35 vlan 0 pcp 6
}
```

### Automatic Wire Calculations

- Sets Ethernet II EtherType to `0x8892` on Layer 2 frames, or encapsulates inside IPv4/IPv6 + UDP `dstport 34964` when `transport udp` is specified.
- Encodes the 16-bit big-endian `FrameID`, pads cyclic RT payloads to minimum length, and appends the 4-byte `CycleCounter` + `DataStatus` (`0x35` Valid/Primary/Run/OK) + `TransferStatus` (`0x00`) trailer.
- Constructs structured PROFINET DCP headers (`ServiceID`, `ServiceType`, `Xid`) when `service` / `get` / `set` / `request` / `response` is selected.

## Practical Lab Example: PROFINET DCP Station Discovery + Cyclic 802.1p Priority-Tagged I/O + Routed UDP (`profinet_dcp_and_rt_io.frasm`)

Captures a PLC IO-Controller discovering a field IO-Device via DCP, exchanging cyclic `0x8000` real-time frames on priority tag `vlan 0 pcp 6`, and sending a routed `transport udp` frame.

```frameassembly
host plc_s7_1500 { ip 10.110.1.10 mac 00:0e:8c:15:00:01 }
host et200sp_io  { ip 10.110.1.20 mac 00:0e:8c:20:00:02 }

compile {
    // 1. DCP Identify request & response over Layer 2 (0x8892)
    plc_s7_1500 -> et200sp_io profinet frameid 0xfefe service "identify" request xid 0x01020304 wait 2ms
    plc_s7_1500 <- et200sp_io profinet frameid 0xfeff service "identify" response xid 0x01020304 wait 2ms
    // 2. Priority-tagged (VLAN 0, PCP 6) cyclic RT_CLASS_1 I/O exchange
    plc_s7_1500 -> et200sp_io profinet frameid 0x8000 cycle 3200 datastatus 0x35 vlan 0 pcp 6 wait 1ms
    plc_s7_1500 <- et200sp_io profinet frameid 0x8001 cycle 3200 datastatus 0x35 vlan 0 pcp 6 wait 2ms
    // 3. Routed PROFINET over UDP port 34964
    plc_s7_1500 -> et200sp_io profinet frameid 0x8000 cycle 3232 datastatus 0x35 transport udp
}
```

```bash
# 1. Eyeball relative timestamps, ports & wire lengths in your terminal
frameassembly show profinet_dcp_and_rt_io.frasm

# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'
frameassembly profinet_dcp_and_rt_io.frasm profinet_dcp_and_rt_io.pcap
frameassembly profinet_dcp_and_rt_io.frasm profinet_dcp_and_rt_io.pcapng

# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture
frameassembly reverse profinet_dcp_and_rt_io.pcap profinet_dcp_and_rt_io_edited.frasm

# 4. Verify dissected protocol fields in tshark
tshark -r profinet_dcp_and_rt_io.pcap
```

## All `profinet` Keywords & Header Options

Packet line pattern: `src_host -> dst_host profinet [frameid <0..65535>] [cycle <0..65535>] [datastatus <0..255>] [transferstatus <0..255>] [service "<text>"] [xid <number>] [request | response | read | write | get | set | connect | release] [transport udp]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `frameid <0..65535>` | 16-bit PROFINET FrameID (e.g. 0x8000, 0xfefe) | `0x8000 (RT_CLASS_1 cyclic)` | Writes the 2-byte PROFINET FrameID ahead of the RT or DCP payload. |
| `cycle <0..65535>` | 16-bit 31.25us Cycle Counter | `0` | Sets the 16-bit CycleCounter in the 4-byte cyclic PROFINET RT trailer. |
| `datastatus <0..255>` | 8-bit RT DataStatus flags | `0x35 (State=Primary, DataValid, ProviderRun, StationOK)` | Sets the DataStatus byte in the cyclic RT trailer (`0x35` healthy; clear bit `0x04` to simulate invalid I/O). |
| `transferstatus <0..255>` | 8-bit TransferStatus byte | `0x00` | Sets the final TransferStatus byte of the cyclic PROFINET RT trailer. |
| `service "<text>" \| get \| set \| read \| write \| connect \| release` | DCP / IO service selector | `Cyclic RT when omitted` | Selects DCP `get`/`set`/`identify` or IO `read`/`write`/`connect`/`release` PDU encoding. |
| `request \| response` | PDU direction role flag | `request` | Toggles DCP `ServiceType` (`0` Request vs `1` Response Success). |
| `xid <number>` | 32-bit DCP Transaction ID | `1` | Sets the 4-byte `Xid` correlation field in PROFINET DCP frames. |
| `transport udp` | Optional UDP encapsulation override (IP hosts required) | `Raw Ethernet 0x8892` | Encapsulates the PROFINET frame inside IPv4/IPv6 + UDP `dstport 34964`. |

## Cross-Layer Options Valid with `profinet`

| Option | Range / Format | Default | Effect |
| --- | --- | --- | --- |
| `wait <number><ns\|us\|ms\|s\|m>` | Time gap (ns, us, ms, s, m) | `10ms` | Advances the packet timestamp clock after sending this packet and before the next packet (`wait 0ns` sends back-to-back). |
| `comment "<text>"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |
| `payload "<text>" \| hexpayload "<hex>"` | Quoted text or hex bytes (choose one) | `Omitted` | Appends or overrides raw payload bytes (`"deadbeef"`, `"de:ad:be:ef"`, or `"\x01\x02"`) and updates packet lengths and checksums. |
| `srcmac <mac> \| dstmac <mac> \| ethertype <0..65535>` | Colon/hyphen/Cisco MAC · EtherType 0..65535 (e.g. 0x0800) | `Host MAC / RFC multicast MAC / auto EtherType` | Overrides the 14-byte Ethernet II source MAC, destination MAC, or standalone Layer 2 16-bit EtherType. |
| `fcs \| badfcs` | Ethernet CRC-32 trailer flags (choose one) | `Omitted` | `fcs` appends a valid IEEE 802.3 4-byte CRC-32 Frame Check Sequence trailer; `badfcs` XOR-corrupts the CRC-32 for NIC/tap negative tests. |
| `vlan <0..4095> [pcp <0..7>] [dei <0\|1>]` | VLAN ID 0..4095, PCP 0..7, DEI 0..1 | `Untagged` | Wraps the packet in an IEEE 802.1Q VLAN tag (`0x8100`) with optional 802.1p QoS priority. |
| `qinq <0..4095> [innervlan <0..4095>]` | Outer S-VLAN 0..4095, Inner C-VLAN 0..4095 | `Untagged (innervlan 1 when qinq is set)` | Double-tags the packet with outer IEEE 802.1ad S-Tag (`0x88a8`) plus inner IEEE 802.1Q C-Tag (`0x8100`). |
| `mpls <0..1048575> [label <0..1048575>] [exp\|tc <0..7>] [bos <0\|1>] [mplsttl <0..255>]` | Repeatable label stack (0..1048575, exp/tc 0..7, bos 0..1, ttl 0..255) | `Unlabeled (auto bos=0 on outer labels, bos=1 on bottom)` | Prepends one or more 32-bit MPLS label shims (`0x8847`, e.g. `mpls 16000 mpls 24010`) ahead of Layer 2 EoMPLS or Layer 3 payloads. |
| `srcport <0..65535> \| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), EtherType 0x8892 (or UDP 34964)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |
| `transport udp` | Optional UDP encapsulation override | `Ethernet 0x8892 (UDP 34964 when transport udp is set)` | Wraps the protocol frame inside an IPv4/IPv6 + UDP header instead of raw Ethernet or raw IP encapsulation. |

## Common Mistakes & Quick Fixes

### transport udp Requires IP Addresses on Both Endpoints

- **Avoid:** `host io1 { mac 00:0e:8c:00:00:01 }
io1 -> io2 profinet transport udp`
- **Valid v3.3.0 Syntax:** `host io1 { ip 10.110.1.10 mac 00:0e:8c:00:00:01 }
io1 -> io2 profinet transport udp`

Native Layer 2 `profinet` (`0x8892`) works on MAC-only hosts, whereas `profinet transport udp` builds an IP + UDP `34964` header and requires `ip` on both hosts.

### PROFINET Supports transport udp Only (Never transport tcp)

- **Avoid:** `plc -> io profinet transport tcp`
- **Valid v3.3.0 Syntax:** `plc -> io profinet transport udp`

Per IEC 61158, routed PROFINET Real-Time uses UDP port `34964`; TCP is not a valid PROFINET RT transport.
