iec104 — Port 2404 IEC 60870-5-104 Substation I/S/U APDUs
- Default Port / Protocol
- TCP 2404
- Host Endpoint Rule
- Dual-Stack IPv4/IPv6
- Wireshark Display Filter
- iec60870_104
- Standards & Specs
- IEC 60870-5-104, IEC 60870-5-101
What It Does on the Wire
European and Asian transmission grids run on TCP 2404 (0x68 APCI start byte): iec104 encodes startdt/testfr U-frames, sframe acknowledgments, and IEEE-754 real or integer ASDUs (typeid, cot, ca, ioa).
IEC 60870-5-104 (iec104) is the dominant transmission and distribution power-grid SCADA telecontrol protocol across Europe, Asia, and Latin America (and notorious from the 2016 Industroyer / CrashOverride Ukraine substation incident) on TCP port 2404. Every APDU starts with 0x68, an 8-bit APDU Length, and 4 Application Protocol Control Information (APCI) control octets encoding U-Frames (STARTDT act/con, STOPDT, TESTFR), S-Frames (Supervisory N(R) acknowledgments), or I-Frames (N(S)/N(R) sequence numbers + an IEC 60870-5-101 ASDU: TypeID, VSQ, Cause of Transmission cot, 16-bit Common Address ca, 24-bit Information Object Address ioa, and integer or IEEE 754 real telemetry/command values).
FrameAssembly encodes shifted little-endian (seq << 1) I/S-frame control fields, 16-bit ca, 24-bit ioa, and IEEE 754 single-precision floats (real 49.98 -> TypeID 13 M_ME_NC_1 Short Floating Point).
Industroyer / Substation Breaker Command (TypeID 45/46) IDS Detection
Test Suricata, Zeek, Claroty, and Dragos rules against unauthorized Single Command (typeid 45 C_SC_NA_1) and Double Command (typeid 46 C_DC_NA_1, cot 6 Activation) frames targeting substation RTU ioa addresses.
Control-Center <-> RTU STARTDT Handshake & Periodic Grid Telemetry
Script startdt -> startdt confirm -> M_ME_NC_1 (typeid 13, real 50.01 Hz / 230.4 kV) -> sframe supervisory ACK -> testfr keepalives.
Substation DMZ Firewall Deep Inspection (ca & typeid Whitelisting)
Verify OT firewalls allow read/spontaneous telemetry (typeid 1..36, cot 3 Spontaneous / cot 20 Interrogation) while blocking write/control typeid 45..64 from historian subnets.
RFC Wire Header Layout (iec104)
Select any 32-bit wire word or field slice below to inspect which .frasm modifiers control those octets and what defaults the compiler writes.
Filter with iec60870_104 (or 104apci / 104asdu) on TCP 2404 to verify 0x68 APCI U/S/I frames, Send/Receive sequence numbers, TypeID, Cause of Transmission (COT), Common Address, and IOA values.
Minimal Quickstart (iec104_quickstart.frasm)
Select Preview Packets to compile in-browser and inspect timestamps + wire byte lengths, or open directly in the Playground.
host scada_cc { ip 10.104.1.10 }
host sub_rtu { ip 10.104.2.50 }
compile {
scada_cc -> sub_rtu tcp syn srcport 52404 dstport 2404 wait 1ms
scada_cc <- sub_rtu tcp syn ack wait 1ms
scada_cc -> sub_rtu tcp ack wait 1ms
scada_cc -> sub_rtu iec104 startdt wait 2ms
scada_cc <- sub_rtu iec104 startdt confirm wait 5ms
scada_cc <- sub_rtu iec104 txseq 0 rxseq 0 typeid 13 cot 3 ca 1 ioa 1001 real 49.98
}Handled Automatically on the Wire
- Defaults to stateful TCP port
2404and formats the0x68Start Byte + exactAPDU Length(4for U/S-frames,4 + ASDU_lenfor I-frames). - Encodes 15-bit
txseqandrxseqshifted left by 1 bit (seq << 1) in little-endian APCI octets per IEC 60870-5-104 Section 5.1. - Packs 16-bit little-endian Common Address (
ca), 24-bit little-endian Information Object Address (ioa), Quality Descriptor (QDS = 0x00Good), and 32-bit IEEE 754 little-endian floats whenrealis provided.
Substation Telecontrol Session: U-Frame STARTDT, Spontaneous 50Hz Float Telemetry, S-Frame & Single Command
Activates data transfer (STARTDT act/con), streams spontaneous grid frequency telemetry (TypeID 13, 49.98 Hz), acknowledges via S-Frame, executes a Single Command (TypeID 45, cot 6 -> cot 7), and exchanges TESTFR keepalives.
host dispatch_cc { ip 172.26.1.10 }
host bay_rtu_04 { ip 172.26.4.40 }
compile {
dispatch_cc -> bay_rtu_04 tcp syn srcport 54404 dstport 2404 wait 1ms
dispatch_cc <- bay_rtu_04 tcp syn ack wait 1ms
dispatch_cc -> bay_rtu_04 tcp ack wait 1ms
// 1. U-Frame STARTDT act (0x07) & STARTDT con (0x0b)
dispatch_cc -> bay_rtu_04 iec104 startdt wait 2ms
dispatch_cc <- bay_rtu_04 iec104 startdt confirm wait 5ms
// 2. I-Frame Spontaneous Measured Float (TypeID 13 M_ME_NC_1, COT 3 Spontaneous, IOA 4001 = 49.98 Hz)
dispatch_cc <- bay_rtu_04 iec104 txseq 0 rxseq 0 typeid 13 cot 3 ca 4 ioa 4001 real 49.98 wait 2ms
// 3. Supervisory S-Frame acknowledging RTU txseq 0 (rxseq = 1)
dispatch_cc -> bay_rtu_04 iec104 sframe rxseq 1 wait 10ms
// 4. Breaker Single Command (TypeID 45 C_SC_NA_1, COT 6 Activation -> COT 7 ActivationCon)
dispatch_cc -> bay_rtu_04 iec104 txseq 0 rxseq 1 typeid 45 cot 6 ca 4 ioa 6001 value 1 wait 3ms
dispatch_cc <- bay_rtu_04 iec104 txseq 1 rxseq 1 typeid 45 cot 7 ca 4 ioa 6001 value 1 wait 15ms
// 5. U-Frame TESTFR act & con keepalive
dispatch_cc -> bay_rtu_04 iec104 testfr wait 2ms
dispatch_cc <- bay_rtu_04 iec104 testfr confirm
}# 1. Eyeball relative timestamps, ports & wire lengths in your terminal
frameassembly show iec104_substation_telecontrol.frasm
# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'
frameassembly iec104_substation_telecontrol.frasm iec104_substation_telecontrol.pcap
frameassembly iec104_substation_telecontrol.frasm iec104_substation_telecontrol.pcapng
# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture
frameassembly reverse iec104_substation_telecontrol.pcap iec104_substation_telecontrol_edited.frasm
# 4. Verify dissected protocol fields in tshark
tshark -r iec104_substation_telecontrol.pcap -Y "iec60870_104"All iec104 Keywords & Header Options
Every sub-keyword and header option is lowercase [a-z0-9]+ with zero underscores — mix and match them in any order after iec104:
src_host -> dst_host iec104 [startdt | stopdt | testfr | sframe | msgtype "<text>"] [confirm] [txseq <0..32767>] [rxseq <0..32767>] [typeid <0..255>] [cot "<text_or_num>"] [ca <0..65535>] [ioa <0..16777215>] [value <number>] [real <decimal>]| Keyword / Option | Accepted Value | Default | Effect on Packet |
|---|---|---|---|
| startdt | stopdt | testfr | sframe | msgtype "<text>" | [confirm] | APCI frame format (U-Frame STARTDT/STOPDT/TESTFR, S-Frame, or default I-Frame when ASDU fields are present) | I-Frame (or U-Frame when startdt/stopdt/testfr is set) | Selects U-Frame (0x07/0x0b STARTDT, 0x13/0x23 STOPDT, 0x43/0x83 TESTFR with confirm), S-Frame (0x01), or I-Frame (N(S)/N(R) + ASDU). |
| txseq <0..32767> | rxseq <0..32767> | 15-bit Send N(S) & Receive N(R) sequence numbers | txseq 0, rxseq 0 | Encodes (txseq << 1) and (rxseq << 1) in APCI control octets 1..4. |
| typeid <0..255> | 8-bit IEC 60870-5-101/104 Type Identification | 13 (M_ME_NC_1 when real is set) or 1 (M_SP_NA_1) | Sets ASDU byte 0 (1 Single-Point, 9 Normalized Meas, 13 Short Float, 36 Float w/ CP56Time2a, 45 Single Cmd, 46 Double Cmd, 100 Interrogation). |
| cot "<text_or_num>" | Cause of Transmission (3 Spont, 6 Act, 7 ActCon, 10 ActTerm, 20 Interrogated) | 3 (Spontaneous) | Writes the 16-bit Cause of Transmission field in the ASDU header. |
| ca <0..65535> | ioa <0..16777215> | 16-bit Common Address of ASDU & 24-bit Information Object Address | ca 1, ioa 1 | Writes the 2-byte little-endian station CA and 3-byte little-endian data-point IOA. |
| value <number> | real <decimal> | Integer state/command byte or IEEE 754 floating-point number (e.g. 49.98, -12.5) | value 1 | Encodes Single/Double/Measured integer values (value) or 4-byte IEEE 754 float + QDS (real). |
Cross-Layer Wrappers Valid with iec104
802.1Q VLAN / QinQ / MPLS tags, IPv4/IPv6 QoS & TTL fields, wait gaps, and transport overrides allowed on this protocol
15 options
Cross-Layer Wrappers Valid with iec104
802.1Q VLAN / QinQ / MPLS tags, IPv4/IPv6 QoS & TTL fields, wait gaps, and transport overrides allowed on this protocol
| Option | Range / Format | Default | Effect on Packet |
|---|---|---|---|
| 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. |
| ttl <0..255> [dscp <0..63>] [ecn <0..3>] | TTL/Hop Limit 0..255, DSCP 0..63, ECN 0..3 | ttl 64, dscp 0, ecn 0 | Sets IPv4 TTL or IPv6 Hop Limit plus DiffServ (DSCP) and ECN QoS markings. |
| ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum] | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (20 04 00 00), or corrupts the 16-bit IPv4 header checksum (badipchecksum). |
| flowlabel <0..1048575> | 20-bit IPv6 Flow Label (0..1048575) | 0 | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |
| srcport <0..65535> | dstport <0..65535> | Port number 0..65535 | srcport 49152 (remembered), TCP 2404 | Overrides source or destination port and remembers the port pair automatically on <- replies. |
| transport sctp | Optional SCTP association transport (IP Proto 132) | TCP (TCP 2404) | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP DATA chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |
| badchecksum | L4/ICMP/SCTP checksum fault injection flag | Valid RFC checksum / CRC-32c | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |
| seq <number> | acknum <number> | win|window <0..65535> | urgent <0..65535> | syn | ack | psh | fin | rst | urg | ece | cwr | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | psh ack, win 65535, automatic TCP seq/acknum | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (mss, wscale, sackperm, sackblock, tsval, tsecr, tcpmd5, tfo). |
Gotchas & Quick Fixes
Combine startdt/testfr with confirm (Not response) for U-Frame Confirmations
cc <- rtu iec104 startdt responsecc <- rtu iec104 startdt confirmIEC 60870-5-104 U-Frames pair Activation (act) with Confirmation (con, enabled via the confirm flag keyword).
Do Not Include typeid/ioa on Pure U-Frames If You Want a 6-Byte APCI Packet
cc -> rtu iec104 startdt ca 1 ioa 1001 real 49.98cc -> rtu iec104 startdt
cc <- rtu iec104 typeid 13 cot 3 ca 1 ioa 1001 real 49.98Real substations exchange 6-byte U-Frame STARTDT act / STARTDT con packets first before transmitting ASDU I-Frames (ca, ioa, real).