Repository navigation
Protocol Library Modules
The ctrpass crate implements the protocol in layers that match the Protocol Overview. The protocol code is platform-neutral. It never runs system commands or opens network interfaces. It reaches the air only through the Radio trait (see Radio Interface). The one exception in the crate is radio::linux, the Linux implementation of that trait. It is compiled only on Linux, no other module depends on it, and it is covered separately on Linux Backend.
The same crate is used by the command-line tool, the Python bindings and, through them, the desktop app.
flowchart TB
exchange["exchange: passes against a store"] --> link["link: one pass, roles and timing"]
exchange --> store["store: CEC folder, state, peer book"]
exchange --> radio["radio: Radio trait"]
scan["scan: find nearby consoles"] --> radio
scan --> ie
link --> ie["streetpass::ie: discovery frames"]
link --> linkkey["streetpass::linkkey: link key"]
link --> service["streetpass::service: service records"]
link --> ccmp["wifi::ccmp"]
link --> yy["yy: segments and session"]
link --> object["cec::object: exchange objects"]
yy --> object
object --> envelope["cec::envelope"]
envelope --> container["cec::container"]
store --> container
store --> identity["identity: seed to MAC and Mii identity"]
export["export: import and delivery"] --> store
export --> container
title["title: fields, Mii slots, signing"] --> plugin["plugin: registry and loading"]
plugin --> layout["plugin::layout: layout files"]
plugin --> wasm["plugin::wasm: WebAssembly modules"]
title --> mii["mii: record and wrap"]
layout --> icon["cec::icon"]
title --> container
ie --> frame["wifi::frame"]
ccmp --> frame
radio --> radiotap["wifi::radiotap types"]
linkkey --> keys["keys"]
mii --> keys
| Module | Role | Protocol page |
|---|---|---|
wifi::frame |
802.11 MAC header and information elements | 802.11 Frames and CCMP |
wifi::ccmp |
CCMP encrypt and decrypt for three-address data frames | 802.11 Frames and CCMP |
wifi::radiotap |
Radiotap parse on receive, build on send | 802.11 Frames and CCMP |
wifi |
Channel and frequency conversion | Discovery |
streetpass::ie |
Build and classify probe, offer, accept, directed probe, link-up | Discovery, Link Setup |
streetpass::service |
Service records, pairing rules, fitting into a budget | Discovery |
streetpass::linkkey |
Link key derivation | Link Setup |
yy::frame |
YY segment encode, parse, and object splitting | YY Transport |
yy::session |
YY state machine: connections, ACKs, resends, turn taking | YY Transport |
cec::object |
Exchange objects, title lists, message list, verdicts | Exchange Objects |
cec::envelope |
Envelopes | CEC Messages |
cec::container |
Containers, extension headers, signing | CEC Messages |
cec::icon |
Tiled RGB565 icons | CEC Messages |
link |
One pass: discovery, link setup, the session, and answering objects | Link Setup, Exchange Flow |
exchange |
Runs a pass on a radio against a store; chooses and files messages | Library Data Flow |
scan |
Listens on each channel and reports consoles | Discovery |
radio |
The Radio trait and Received frame |
Radio Interface |
radio::pcap |
Reads classic pcap files | Radio Interface |
radio::linux |
Linux backend, built only on Linux | Linux Backend |
store |
Console-shaped message store with ctrpass state and a peer book | Store |
identity |
MAC, creator MAC and Mii features from a 32-byte seed | Store |
export |
Reads save images, folders and message files; delivers into CEC folders | Import and Export |
keys |
Key file parsing, key scrambler, HMAC key search | Keys |
mii |
Mii record fields, validation, CRC, AES-CCM wrap | Mii Records |
title |
Fields, value checks and Mii slots of editable titles; builds signed messages | Plugins |
plugin |
Plugin registry: built-in plugins, then the plugin folder; manifests and fields | Plugins |
plugin::layout |
Layout files: placed fields, fill, create values, checks, computed values | Plugins, Mii Plaza Messages |
plugin::wasm |
WebAssembly modules run with wasmi, a fresh sandbox per call | Plugins |
games |
Names of known StreetPass titles | |
sim |
Simulated console, internal to the crate | Simulated Console |
link::Link and yy::session::Session do no I/O and read no clock. The caller passes in each received frame or segment with the current time, calls poll(now) to run timers, and takes queued output with take_output(). This keeps the protocol logic independent of the radio and of real time. The same code runs against a real radio, a capture, or the simulated console.
flowchart LR
caller["Caller loop"] -->|"on_frame(frame, info, now, host)"| link["Link"]
caller -->|"poll(now)"| link
link -->|"take_output(): frames and rates"| caller
link -->|"take_events()"| caller
link -->|"choose, admit"| host["Host trait"]
link knows nothing about where messages are kept. It asks a Host two questions:
| Method | Asked when | Answer |
|---|---|---|
choose(peer, services) |
A console engages | A Plan (services and messages to trade) or None to leave it alone |
admit(offer) |
The console's offer arrives | A verdict code per title |
exchange::StoreHost answers from a Store. Another host could answer from anything else.
Link reports what happened as events: Engaged, Declined, LinkUp, Abandoned with a reason, Finished, and Session notes for resends, give-ups, refused objects and repeats.
The library has no code for any one game's body. title::Title holds a plugin's manifest and fields, and the engine behind them: a layout or a module. Each call goes through Title, which:
- checks values against the fields before the engine sees them;
- passes Mii fields to no engine, and decrypts, edits, validates and protects Mii records itself;
- checks the body the engine returns is between 1 and
0x18000bytes; - turns values the engine reads back that break the field rules into problems.
flowchart LR
front["CLI, Python module"] --> title["title::Title"]
title -->|"plain values"| engine{"Engine"}
engine --> layout["Layout file"]
engine --> wasm["Module in wasmi"]
title -->|"Mii values"| mii["mii: unwrap, edit, validate, wrap"]
title --> sign["title::message: sign with the title key"]
The registry loads once per process, on first use. Built-in plugins are compiled into the crate as layout text.
The library has one error type with these kinds: key file, format, authentication, busy (store locked), no room, key conflict, and I/O.
How to set up
- Overview and requirements
- Choosing a Wi-Fi adapter
- Building and installing
- Making the key file
- Desktop app
- Command line
- Messages and emulators
- Troubleshooting
Plugins
Protocol
- Overview
- Discovery
- Link setup
- Frames and CCMP
- YY transport
- Exchange flow
- Exchange objects
- CEC messages
- CEC message boxes
- Mii records
- Mii Plaza
- Keys
ctrpass library
Linux