# s1ap — 3GPP 4G S1-MME eNodeB-to-MME ASN.1 APER over SCTP 36412 (`s1ap`)

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

- **Full Protocol Name:** 4G LTE S1 Application Protocol (S1-MME eNB <-> MME over SCTP)
- **Keyword:** `s1ap`
- **OSI Layer & Transport:** Layer 7 · SCTP 36412 (PPID 18)
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** 3GPP TS 36.413, 3GPP TS 24.301, RFC 9260
- **Wireshark Display Filter:** `s1ap`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> SCTP 36412 (PPID 18) -> 4G S1AP (3GPP TS 36.413)`

## Overview

Test 4G LTE S1-MME security gateways and telecom NDR probes offline: `s1ap` emits 3GPP TS 36.413 ASN.1 APER frames straight inside SCTP `36412` (`PPID 18`) with Castagnoli CRC-32c.

S1 Application Protocol (`s1ap`, 3GPP TS 36.413) is the **4G LTE `S1-MME` control-plane protocol** linking **eNodeB (`eNB`)** radio base stations to the **Mobility Management Entity (`MME`)** exclusively over **SCTP port `36412` (`PPID = 18`)**. Like 5G NGAP, S1AP uses **ASN.1 Aligned PER (APER)** encoding to carry cell-level setup (`S1SetupRequest`/`Response` with `Global-ENB-ID`, `SupportedTAs` 16-bit `TAC`, and `eNBname`) and UE-associated signaling (`InitialUEMessage`, `DownlinkNASTransport`, `UplinkNASTransport`, `UEContextRelease` with `MME-UE-S1AP-ID`, `eNB-UE-S1AP-ID`, and embedded **EPS-NAS `3GPP TS 24.301`** PDUs).

FrameAssembly packs compliant APER S1AP containers inside CRC-32c SCTP `DATA` chunks (`PPID 18`) over IPv4 or IPv6 backhaul hosts.

## Minimal Quickstart (`s1ap_quickstart.frasm`)

```frameassembly
host enb_01  { ip 10.44.1.11 }
host mme_epc { ip 10.44.1.100 }

compile {
    enb_01 -> mme_epc s1ap s1setuprequest enbid 0x001a2 plmn "00101" tac 10 enbname "enb-macro-01" wait 4ms
    enb_01 <- mme_epc s1ap s1setupresponse plmn "00101" enbname "mme-epc-01"
}
```

### Automatic Wire Calculations

- Wraps every S1AP message inside IP Protocol `132` **SCTP (`dstport 36412`, `DATA` chunk `PPID = 18`)** with valid Castagnoli CRC-32c.
- Encodes ASN.1 APER `S1AP-PDU` Procedure Codes (`17` S1Setup, `12` InitialUEMessage, `11` DownlinkNASTransport, `13` UplinkNASTransport, `23` UEContextRelease, `15` ErrorIndication) and sorted ProtocolIE fields.
- Formats 3-byte BCD `PLMNidentity`, 20-bit Macro `eNB-ID`, and 16-bit LTE `TAC` (`0..65535`) automatically.

## Practical Lab Example: 4G LTE S1-MME Attach Signaling: S1Setup, InitialUEMessage, EPS-NAS Auth & Release (`s1ap_lte_attach_flow.frasm`)

Simulates a CBRS private-LTE eNodeB onboarding onto an MME over SCTP `36412`, forwarding an EPS Attach Request (`naspdu "0741..."`), completing mutual authentication, and releasing the S1 UE context.

```frameassembly
host cbrs_enb { ip 172.24.36.12 }
host epc_mme  { ip 172.24.36.100 }

compile {
    // 1. S1Setup Request & Response (Procedure Code 17, SCTP 36412 PPID 18)
    cbrs_enb -> epc_mme s1ap s1setuprequest enbid 0x01020 plmn "315010" tac 401 enbname "cbrs-warehouse-enb1" wait 3ms
    cbrs_enb <- epc_mme s1ap s1setupresponse plmn "315010" enbname "magma-mme-01" wait 6ms
    // 2. UE Attach: InitialUEMessage (Procedure Code 12) carrying EPS Attach Request (0x07 0x41)
    cbrs_enb -> epc_mme s1ap initialuemessage enbueid 101 plmn "315010" tac 401 naspdu "074171080910101234567890" wait 4ms
    // 3. Downlink & Uplink NAS Transport (Authentication Request 0x07 0x52 / Response 0x07 0x53)
    cbrs_enb <- epc_mme s1ap downlinknastransport mmeueid 9001 enbueid 101 naspdu "075200100102030405060708090a0b0c0d0e0f10" wait 4ms
    cbrs_enb -> epc_mme s1ap uplinknastransport mmeueid 9001 enbueid 101 naspdu "075308aabbccddeeff0011" wait 20ms
    // 4. Inactivity S1 UE Context Release (Procedure Code 23)
    cbrs_enb <- epc_mme s1ap uecontextreleasecommand mmeueid 9001 enbueid 101 wait 2ms
    cbrs_enb -> epc_mme s1ap uecontextreleasecomplete mmeueid 9001 enbueid 101
}
```

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

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

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

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

## All `s1ap` Keywords & Header Options

Packet line pattern: `src_host -> dst_host s1ap [s1setuprequest | s1setupresponse | s1setupfailure | initialuemessage | downlinknastransport | uplinknastransport | uecontextreleasecommand | uecontextreleasecomplete | errorindication] [msgtype "<text>"] [proccode <0..255>] [criticality "<text>"] [mmeueid <number>] [enbueid <0..16777215>] [plmn "<text>"] [enbid <number>] [tac <0..65535>] [enbname "<text>"] [naspdu "<hex>"]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `s1setuprequest \| s1setupresponse \| s1setupfailure \| initialuemessage \| downlinknastransport \| uplinknastransport \| uecontextreleasecommand \| uecontextreleasecomplete \| errorindication` | 3GPP TS 36.413 S1AP Elementary Procedure | `s1setuprequest` | Selects the ASN.1 APER PDU Choice and TS 36.413 Procedure Code + mandatory ProtocolIE sequence. |
| `msgtype "<text>" \| proccode <0..255> \| criticality "<text>"` | Explicit APER PDU Choice, ProcedureCode, and Criticality | `Derived from procedure keyword` | Overrides the outer S1AP `procedureCode` and `criticality` (`"reject"`, `"ignore"`, `"notify"`). |
| `mmeueid <number> \| enbueid <0..16777215>` | 32-bit MME-UE-S1AP-ID (IE 0) & 24-bit eNB-UE-S1AP-ID (IE 8) | `mmeueid 1, enbueid 1 on UE messages` | Writes the APER integer UE context identifiers pairing eNB and MME state machines. |
| `plmn "<text>"` | 5- or 6-digit MCC+MNC string (e.g. "00101", "315010") | `"00101"` | Encodes the 3-octet TBCD `PLMNidentity` in Global-ENB-ID, SupportedTAs, TAI, and EUTRAN-CGI. |
| `enbid <number> \| tac <0..65535> \| enbname "<text>"` | 20-bit Macro eNB-ID, 16-bit LTE TAC (0..65535), and PrintableString eNBname | `enbid 1, tac 1, enbname "eNB-01"` | Populates IE `59` (`Global-ENB-ID`), IE `64` (`SupportedTAs`), IE `67` (`TAI`), and IE `60` (`eNBname`). |
| `naspdu "<hex>"` | Even-length hex byte string (IE 26 NAS-PDU) | `"0741" (EPS Attach stub)` | Embeds binary `3GPP TS 24.301` EPS-NAS octets inside IE `26` for Wireshark `nas-eps` dissection. |

## Cross-Layer Options Valid with `s1ap`

| 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), SCTP 36412 (PPID 18)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |
| `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. |

## Common Mistakes & Quick Fixes

### 4G S1AP TAC Is 16-Bit (0..65535), Unlike 5G NGAP 24-Bit TAC

- **Avoid:** `enb -> mme s1ap s1setuprequest tac 100000`
- **Valid v3.3.0 Syntax:** `enb -> mme s1ap s1setuprequest tac 401`

In 4G LTE (`3GPP TS 36.413`), `TAC` is a 2-octet `OCTET STRING (SIZE(2))` (`0..=65535`), whereas 5G NR (`ngap`) widened `TAC` to 3 octets (`0..=16777215`).

### s1ap Is Strictly SCTP-Only (SCTP 36412, PPID 18)

- **Avoid:** `enb -> mme s1ap initialuemessage transport udp`
- **Valid v3.3.0 Syntax:** `enb -> mme s1ap initialuemessage enbueid 1 naspdu "0741"`

3GPP TS 36.412 mandates SCTP for S1-MME; `validate_semantics` rejects `transport tcp` and `transport udp` on `s1ap`.
