Repository navigation
Protocol Library Data Flow
This page follows data through the library: how a pass chooses what to send, and how a received frame becomes a stored message.
Implemented in: exchange, link, yy::session, store.
exchange::run_pass runs one pass on any Radio. A pass waits for a console, exchanges with at most one, and files what arrived.
flowchart TD
start["run_pass"] --> adv["Advertised services from the store"]
adv --> tok["Random 8-byte token"]
tok --> link["Link::new with role, MAC, token, services, channels"]
link --> loop{"Loop"}
loop --> poll["link.poll(now)"]
poll --> send["radio.send each output frame"]
send --> ev["Report events"]
ev --> done{"Finished, stopped, or window over while idle?"}
done -- yes --> finish["StoreHost::finish: file arrivals, update peer book"]
done -- no --> ch["radio.set_channel if the link moved"]
ch --> rx["radio.recv up to 5 ms"]
rx --> on["link.on_frame"]
on --> loop
finish --> report["Report: peer, sent, refused, received, not filed"]
Stopping:
- When the pass window ends and no console is engaged, the pass ends.
- When a stop is asked for, the pass ends at once if no console is engaged. Otherwise the exchange in progress may run up to 10 more seconds.
Before a pass, the store decides the services it advertises in broadcast probes. For each title in the store, in store order:
flowchart TD
t["Title"] --> ob{"Outbox has a sendable message with a nonzero send count?"}
ob -- yes --> mode{"Inbox has room?"}
mode -- yes --> adv1["Advertise its service record with its mode"]
mode -- "no, mode 2 or 3" --> adv2["Advertise with mode 2"]
mode -- "no, mode 0 or 1" --> rcv
ob -- no --> rcv{"Set to receive and inbox has room?"}
rcv -- yes --> adv3["Advertise the record set for the title, else the newest message's record with mode 3"]
rcv -- no --> skip["Not advertised"]
A message is sendable when its signature does not fail against the store's key for the title and it was not received from a console. The record comes from the message's service extension header. If there is none, ctrpass uses a record with flags 0 and no arguments.
When a console engages, StoreHost::choose builds a plan:
- Decline checks. Blocked MAC: decline. MAC in the filter of consoles already exchanged with: decline. Last attempt with this MAC failed less than 60 s ago: decline.
- Match services. For each of the console's records, find the local record of the same title. Keep it if the two pair (see Discovery).
- Pick messages. For each matched title sourced from the outbox, take its sendable messages newest first. Skip any already sent to this MAC or received from it. Give each a fresh random message ID and remember which stored message it stands for.
- Keep services that have a message to send, or whose title is set to receive and has inbox room.
- If no service is left, decline with "nothing to trade".
sequenceDiagram
participant R as Radio
participant L as Link
participant S as Session
participant H as StoreHost
participant St as Store
R->>L: Received frame and radiotap info
L->>L: Parse header, drop own frames
alt management frame
L->>L: Classify probe, offer, accept, directed probe, link-up
L->>H: choose(peer, services) on engage
else protected data frame from the peer
L->>L: CCMP decrypt with the link key, check PN
L->>L: Parse YY segment
L->>S: on_segment(segment, now)
S-->>L: Completed object, if any
L->>H: admit(offer) when the offer arrives
L->>S: Queue the answer
end
L->>L: Encrypt queued segments into data frames
Note over L,H: Session ends
L-->>H: Outcome: delivered, received, admitted, refused
H->>H: Split envelopes into containers
H->>St: file_inbound per title
St->>St: Verify signature, check room, write files
H->>St: Peer book: record exchange or note attempt
Step by step:
- The backend returns a frame without radiotap header or FCS, plus the frequency and signal.
-
Link::on_framedrops frames from its own MAC. A protected data frame goes to the data path. Anything else goes throughstreetpass::ie::classify. - On the data path, the frame must come from the engaged peer and be addressed to the local MAC. It is decrypted with the link key. Its PN must be higher than the last one accepted.
- The plaintext is parsed as a YY segment and handed to the session.
- When the session completes an object,
Linkacts on it: in the Wait role it queues the answer; in the Lead role it builds its verdict or applies the console's verdict. -
Link::flushtakes the session's queued segments, wraps each in a CCMP data frame with the next PN, and queues it for the radio. - When the session ends,
Linkproduces anOutcomewith every object delivered and received, whether the console sent its message list, the admitted offer, and the titles the console refused. -
StoreHost::finishfiles the arrivals.
flowchart TD
out["Outcome"] --> psm{"Console sent its message list?"}
psm -- no --> attempt["Peer book: note a failed attempt"]
psm -- yes --> sent["Map delivered containers back to stored message IDs"]
sent --> split["Split each received envelope"]
split --> m0{"Send mode 0 without a local mode-0 send of that title?"}
m0 -- yes --> nf1["Not filed"]
m0 -- no --> group["Group by title"]
group --> res{"Within the bytes and count the console's offer declared?"}
res -- no --> nf2["Not filed: more than its offer declared"]
res -- yes --> file["Store::file_inbound"]
file --> sig{"Signature matches the store's key, if any?"}
sig -- no --> nf3["Not filed: failed its signature"]
sig -- yes --> room{"All of them fit the inbox?"}
room -- no --> nf4["Not filed: no room"]
room -- yes --> write["Write each to the inbox, origin = peer MAC"]
write --> book["Peer book: record sent and received IDs, add MAC to the filter"]
Notes:
- A title's arrivals are filed all together or not at all. Nothing already in the inbox is dropped to make room.
- If anything was sent or received, the peer book records the exchange and adds the MAC to the filter. If not, and the console was not declined, it notes a failed attempt.
- Messages sent are counted only when the console sent its message list, because a console keeps nothing otherwise.
Each pass returns a report:
| Field | Contents |
|---|---|
peer |
MAC of the console, if one was engaged as far as a link |
sent |
Title and stored message ID of each message the console took |
refused |
Local titles the console's verdict refused |
received |
Title and message ID of each message filed |
not_filed |
Title and reason for each arrival that was not filed |
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