Skip to content

Protocol Frames and CCMP

finthetechguy edited this page Nov 23, 2026 · 1 revision

802.11 Frames and CCMP

Once the link is up, everything travels in unicast 802.11 data frames protected with CCMP under the link key from Link Setup. The plaintext of each frame is one YY segment.

Implemented in: wifi::frame, wifi::ccmp, wifi::radiotap.

MAC header

All StreetPass frames use the 24-byte three-address header. Multi-byte fields are little-endian.

Offset Size Field
0 2 Frame control
2 2 Duration
4 6 Address 1 (receiver)
10 6 Address 2 (transmitter)
16 6 Address 3 (BSSID)
22 2 Sequence control: fragment number in bits 0-3, sequence number in bits 4-15

Frame control bits used:

Bits Field
0-1 Protocol version, must be 0
2-3 Type: 0 management, 2 data
4-7 Subtype
8 To DS
9 From DS
11 Retry
14 Protected

Information elements in management frames are the usual id, length, data triples. A truncated element ends the list.

Data frames

Field Value
Type, subtype 2, 0 (plain data, not QoS)
To DS, From DS Both clear
Protected Set
Duration 0x002c
Address 1 Peer MAC
Address 2 Own MAC
Address 3 Host MAC (the BSSID)
Sequence Running 12-bit number shared with the management frames the same side sends

ctrpass sends data frames at 11 Mbit/s. A receiver keeps a data frame only when address 2 is the peer, address 1 is its own MAC, a session is running, and the frame decrypts.

CCMP

The data frame body is standard CCMP (AES-CCM with a 16-byte key, an 8-byte MIC and a 13-byte nonce). ctrpass supports only the frame shape above: non-QoS data with three addresses.

Frame layout

flowchart LR
    h["MAC header, 24 bytes"] --> c["CCMP header, 8 bytes"]
    c --> b["Encrypted body: one YY segment"]
    b --> m["MIC, 8 bytes"]
Loading

CCMP header

Offset Size Field
0 1 PN0
1 1 PN1
2 1 Reserved, 0
3 1 0x20: Ext IV bit set, key ID 0
4 1 PN2
5 1 PN3
6 1 PN4
7 1 PN5

PN is a 48-bit packet number. PN0 is the least significant byte.

Nonce

Offset Size Field
0 1 Priority, 0
1 6 Address 2
7 6 PN, most significant byte first

Additional authenticated data

22 bytes built from the MAC header:

Offset Size Field
0 1 Frame control byte 0 with bits 4-6 cleared (& 0x8f)
1 1 Frame control byte 1 with retry, power management and more-data cleared (& 0xc7), protected set
2 18 Addresses 1, 2 and 3
20 1 Sequence control byte 0 with the sequence bits cleared (& 0x0f)
21 1 0

Packet numbers

  • The sender keeps one counter per link key, starting at 1, and adds 1 for each frame.
  • The receiver keeps the highest PN it accepted from the peer and drops any frame whose PN is not higher. This drops retransmitted and replayed frames.
  • A frame whose MIC fails is dropped.

Radiotap

Received frames and injected frames carry a radiotap header in front of the 802.11 frame. The library parses and builds it. A radio backend that uses radiotap (such as the Linux backend) calls these helpers. The rest of the library only sees bare 802.11 frames without FCS.

On receive

ctrpass reads these fields from the radiotap header:

Present bit Field Use
1 Flags Bit 0x10: frame ends in a 4-byte FCS, which is removed. Bit 0x40: bad FCS, the frame is dropped.
3 Channel Frequency in MHz, used to find the channel a console was heard on
5 Antenna signal Signal in dBm

Fields 0 to 5 are walked in bit order, each aligned to its own size. Extended presence words are skipped.

On send

ctrpass prefixes each injected frame with a fixed 12-byte header:

Offset Size Field Value
0 1 Version 0
1 1 Pad 0
2 2 Length 12
4 4 Present Rate (bit 2) and TX flags (bit 15)
8 1 Rate In 500 kbit/s units: 2 for 1 Mbit/s, 22 for 11 Mbit/s
9 1 Pad 0
10 2 TX flags 0x0008 (no ACK) for broadcast frames, else 0

Rates used

Frames Rate
Probes, directed probes, offers, link-ups 1 Mbit/s
Accepts, data frames 11 Mbit/s

Clone this wiki locally