# mms — Port 102 ISO 9506 / IEC 61850-8-1 Substation Client/Server (`mms`)

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

- **Full Protocol Name:** Manufacturing Message Specification (IEC 61850 Station Bus)
- **Keyword:** `mms`
- **OSI Layer & Transport:** Layer 7 · TCP 102 (TPKT + COTP + OSI Session/Pres/ACSE)
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** ISO 9506-1 / 9506-2, IEC 61850-8-1, RFC 1006
- **Wireshark Display Filter:** `mms`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> TCP 102 (TPKT + COTP + OSI Session/Pres/ACSE) -> ISO 9506 MMS (IEC 61850-8-1)`

## Overview

Building a valid ISO 9506 MMS packet by hand means nesting seven OSI layers (TPKT -> COTP -> Session -> Presentation -> ACSE -> ASN.1 BER MMS) on TCP `102` — `mms` assembles the entire IEC 61850-8-1 station-bus stack in one line!

Manufacturing Message Specification (`mms`, ISO 9506 / IEC 61850-8-1) is the client-server **station-bus protocol** connecting substation SCADA gateways and HMIs to protection **Intelligent Electronic Devices (IEDs)** over **TCP port `102`**. Manually crafting valid MMS packets is famously painful because every MMS ASN.1 BER PDU sits atop a **5-layer ISO/OSI stack**: `RFC 1006 TPKT` -> `ISO 8073 COTP` -> `ISO 8327 Session` -> `ISO 8823 Presentation` (+ `ISO 8650 ACSE` on Initiate) -> **`ISO 9506 MMS`** (`Initiate-RequestPDU`, `Confirmed-RequestPDU`, `Confirmed-ResponsePDU`, `Unconfirmed-PDU` InformationReport, `Conclude`).

FrameAssembly builds the entire TPKT + COTP + OSI Session/Presentation/ACSE envelope automatically so your IEC 61850 Logical Device (`domain "IED1LD0"`) and Logical Node variable (`item "MMXU1$MX$PhV"` or `"CSWI1$CO$Pos"`) dissect cleanly in Wireshark (`mms`).

## Minimal Quickstart (`mms_quickstart.frasm`)

```frameassembly
host station_hmi { ip 10.61.85.10 }
host relay_ied01 { ip 10.61.85.51 }

compile {
    station_hmi -> relay_ied01 tcp syn srcport 52102 dstport 102 wait 1ms
    station_hmi <- relay_ied01 tcp syn ack wait 1ms
    station_hmi -> relay_ied01 tcp ack wait 1ms
    station_hmi -> relay_ied01 mms read invokeid 1 domain "IED1LD0" item "MMXU1$MX$TotW" wait 3ms
    station_hmi <- relay_ied01 mms read isresponse invokeid 1 value 1450
}
```

### Automatic Wire Calculations

- Defaults to stateful TCP port `102` and constructs the full RFC 1006 `TPKT` + ISO 8073 `COTP DT` + ISO 8327 `Session` + ISO 8823 `Presentation` (+ `ACSE` on `init`/`initack`) stack.
- Encodes ASN.1 BER `Confirmed-RequestPDU` (`0xa0`), `Confirmed-ResponsePDU` (`0xa1`), `Unconfirmed-PDU` (`0xa3` for `report`), `Initiate-RequestPDU` (`0xa8`), `Initiate-ResponsePDU` (`0xa9`), and `Conclude` (`0x8b`).
- Wraps `domain` and `item` (`$`-delimited IEC 61850 functional constraint paths like `"XCBR1$ST$Pos"`) into `ObjectName :: domain-specific` BER sequences.

## Practical Lab Example: IEC 61850 Substation Bay Workflow: MMS Initiate, GetNameList, MMXU Read, Report & CSWI Write (`mms_iec61850_station_bus.frasm`)

Associates an IEC 61850 station HMI with Bay Relay `IED01` (`init`/`initack`), enumerates `IED01LD0` via `getnamelist`, reads `MMXU1$MX$PhV`, receives a spontaneous `RPT` `report`, and writes `CSWI1$CO$Pos`.

```frameassembly
host sub_gateway { ip 172.21.61.10 }
host feeder_ied1 { ip 172.21.61.101 }

compile {
    sub_gateway -> feeder_ied1 tcp syn srcport 54102 dstport 102 wait 1ms
    sub_gateway <- feeder_ied1 tcp syn ack wait 1ms
    sub_gateway -> feeder_ied1 tcp ack wait 1ms
    // 1. OSI ACSE + MMS Initiate Request & Response
    sub_gateway -> feeder_ied1 mms init wait 3ms
    sub_gateway <- feeder_ied1 mms initack wait 4ms
    // 2. GetNameList (InvokeID 1) + Read Phase Voltage MMXU1$MX$PhV (InvokeID 2)
    sub_gateway -> feeder_ied1 mms getnamelist invokeid 1 domain "IED1LD0" wait 2ms
    sub_gateway <- feeder_ied1 mms getnamelist isresponse invokeid 1 domain "IED1LD0" item "MMXU1" wait 4ms
    sub_gateway -> feeder_ied1 mms read invokeid 2 domain "IED1LD0" item "MMXU1$MX$PhV" wait 2ms
    sub_gateway <- feeder_ied1 mms read isresponse invokeid 2 value 138000 wait 10ms
    // 3. Unconfirmed InformationReport from IED (Breaker status change)
    sub_gateway <- feeder_ied1 mms report domain "IED1LD0" item "XCBR1$ST$Pos" value 2 wait 5ms
    // 4. Switch Controller Write (CSWI1$CO$Pos) -> Confirmed Write Response
    sub_gateway -> feeder_ied1 mms write invokeid 3 domain "IED1LD0" item "CSWI1$CO$Pos" value 1 wait 2ms
    sub_gateway <- feeder_ied1 mms write isresponse invokeid 3 value 0
}
```

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

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

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

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

## All `mms` Keywords & Header Options

Packet line pattern: `src_host -> dst_host mms [init | initack | getnamelist | read | write | report | conclude | service "<text>"] [isresponse | response] [invokeid <number>] [domain "<text>"] [item "<text>"] [value <number>]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `init \| initack \| getnamelist \| read \| write \| report \| conclude \| service "<text>"` | ISO 9506 MMS Service selector | `read` | Selects `Initiate-RequestPDU` (`init`), `Initiate-ResponsePDU` (`initack`), `GetNameList` (`1`), `Read` (`4`), `Write` (`5`), `InformationReport` (`report`), or `Conclude`. |
| `isresponse \| response` | Confirmed-ResponsePDU toggle flag | `Request (Confirmed-RequestPDU 0xa0)` | Switches `read` / `write` / `getnamelist` from `Confirmed-RequestPDU` (`0xa0`) to `Confirmed-ResponsePDU` (`0xa1`). |
| `invokeid <number>` | 32-bit unsigned MMS `invokeID` | `1` | Encodes the ASN.1 BER integer `invokeID` correlating Confirmed Requests and Confirmed Responses. |
| `domain "<text>" \| item "<text>"` | IEC 61850 Logical Device `domainId` & `$`-separated `itemId` | `domain "LD0", item "LLN0$ST$Mod"` | Populates the `domain-specific` `(VisibleString domainId, VisibleString itemId)` variable specification. |
| `value <number>` | Integer `Data` access value (`Read` response, `Write` request, or `InformationReport`) | `0` | Encodes an ASN.1 BER `Data :: integer` / `unsigned` element inside `listOfAccessResult` or `listOfData`. |

## Cross-Layer Options Valid with `mms`

| 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. |
| `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 102 (TPKT + COTP + OSI Session/Pres/ACSE)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |
| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 102 (TPKT + COTP + OSI Session/Pres/ACSE))` | 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`). |

## Common Mistakes & Quick Fixes

### Distinguish Station-Bus mms (TCP 102) from Process/Bay-Level goose (L2 0x88b8)

- **Valid v3.3.0 Syntax:** `hmi -> ied mms read invokeid 1 domain "LD0" item "MMXU1$MX$PhV"
ied -> peer_ied goose appid 0x1000 gocbref "IED1/LLN0$GO$gcb01" stnum 2 sqnum 0`

In IEC 61850 substations, client-server SCADA polling/control uses TCP `102` `mms`, whereas sub-4ms relay-to-relay protection trips use Layer 2 multicast `goose` (`0x88b8`).

### Add isresponse (or response) When Returning Confirmed-ResponsePDU Frames

- **Valid v3.3.0 Syntax:** `hmi <- ied mms read isresponse invokeid 1 value 230`

`<-` flips the TCP direction (`102 -> client`), while `isresponse` switches the ASN.1 BER tag from `Confirmed-RequestPDU (0xa0)` to `Confirmed-ResponsePDU (0xa1)`.
