Add data-flow diagrams of both paths (V2X_RX and RAW_FRAME with the app's Receive path switch) to the app README, the firmware README and docs/06, and bring the draw.io architecture labels up to station-link revision 2. The spec (revision 2) gains "V2X_RX and RAW_FRAME: both stay" and "Fragmentation on the host side". Document the corpus generator in test/host.
180 lines
12 KiB
Markdown
180 lines
12 KiB
Markdown
# 06 – Signed ITS messages, VAM and the BLE link (2026-09-23, firmware part updated 2026-11-10)
|
||
|
||
What changed when the ESP32-C5 OBU moved onto Niklas Dathe's station, how the pieces
|
||
fit together, how it was verified, and what is still open. Since 2026-11-10 the firmware is built on
|
||
Niklas Dathe's newer `microbu-firmware` layout (link spec revision 2, `obu-firmware/docs/station-link.tex`);
|
||
the parts below that describe the earlier vanetza-idf port say so. Hardware checks still to do are in
|
||
`TODO.md` ("Signed-TX firmware ...").
|
||
|
||
## Summary
|
||
|
||
- **Signing lives on the ESP32-C5.** The authorization ticket's private key is in the board's NVS;
|
||
the station's security entity signs every secured message there (IEEE 1609.2 / ETSI TS 103 097,
|
||
ECDSA NIST P-256). The phone never holds a key and never signs.
|
||
- **The phone decides what to send and when.** It builds CAM or VAM (UPER) from its own GNSS/IMU,
|
||
hands each message to the board with the flag "signed" or "unsigned", and keeps the board's clock
|
||
and position current.
|
||
- **Two links, one protocol.** USB-C (native USB Serial/JTAG) or Bluetooth LE, chosen in Settings.
|
||
Both carry Niklas Dathe's station-link protocol (revision 2 of the spec adds the MicrOBU extensions: `V2X_RX`, unsigned sending, battery guard).
|
||
- **Reception is unchanged for the app.** Every ITS message heard on air reaches the phone, signed
|
||
or not, verifiable or not, exactly as with the previous firmware. Since 2026-11-11 the app can instead take the spec's
|
||
`RAW_FRAME` debug capture and unwrap it itself (Settings > Receive path); both paths stay in the firmware.
|
||
- **Demo PKI, not the EU trust list.** Signed messages carry a throwaway chain. Receivers that
|
||
verify against the EU trust list drop them; unsigned sending remains available.
|
||
|
||
## Who does what
|
||
|
||
| | Phone (app) | ESP32-C5 (obu-firmware) |
|
||
|---|---|---|
|
||
| CAM / VAM content and UPER encoding | yes | – |
|
||
| Send cadence (CAM 1 Hz baseline; VAM per TS 103 300-3 clause 6.4) | yes | – |
|
||
| Pseudonym (station ID + MAC, rotated together) | yes | uses the MAC it is configured with |
|
||
| Time and position (PoTi) | yes, per new GNSS fix | keeps an ITS clock from it |
|
||
| GeoNetworking + BTP headers | – | yes |
|
||
| Signing (TS 103 097), certificate handling | – | yes |
|
||
| Credentials | ships the demo bundle, provisions it once | stores it in NVS |
|
||
| 802.11p radio at 5 900 MHz | – | yes |
|
||
| Reception: unwrap GN/BTP, forward | decodes CAM / DENM / SPATEM | yes (all frames) |
|
||
|
||
## Firmware (obu-firmware)
|
||
|
||
obu-firmware is Niklas Dathe's `microbu-firmware` (commit e4e4bd8, HAW GitLab, not part of this
|
||
repository; nothing is pushed there) with the MicrOBU additions: `main/`, `components/microbu_v2x`,
|
||
`components/vanetza` and the patched `external/vanetza` are copied in unchanged, so obu-firmware builds
|
||
from a plain clone. It builds with **ESP-IDF 6.0.2 only**: the raw-TX path uses private Wi-Fi driver
|
||
structures that `microbu_v2x` pins to that version. Setup and flashing: `obu-firmware/FLASHING.md`.
|
||
Design notes and every deviation from Niklas Dathe's code (`MicrOBU:` in the sources):
|
||
`obu-firmware/NOTES.md`. The earlier port (vanetza-idf, 2026-09-23) and the previous C firmware are in
|
||
git history (`1c3a66e`, `7285fa1`).
|
||
|
||
Main changes against Niklas Dathe's firmware:
|
||
|
||
- **Raw receive path kept.** The stack decapsulates strictly and would drop unsigned frames (the
|
||
bench car) and anything not signed under the demo root (every RSU). Every received frame also
|
||
goes through `gn_unwrap.c` and reaches the phone as link opcode `V2X_RX` (**0x90**; 0x85 is the
|
||
spec's RAW_FRAME), whose body is the old `SERIAL_MSG_V2X_RX` payload.
|
||
- **Unsigned sending kept.** Niklas Dathe's station refuses unsecured requests; here they go out
|
||
with `geonet.c`'s header and a random MAC per configuration.
|
||
- **Production board: Seeed XIAO ESP32-C5** (8 MB flash, a single native USB-C port) running from a LiPo
|
||
on its BAT pads. The log travels as LOG frames on the USB link (no UART adapter needed).
|
||
- **Battery:** the XIAO's divider (GPIO6, enabled by GPIO26) is read every 5 s and reported in STATUS
|
||
(`battery_mv`, octets 129-130); the app shows the voltage, a rough percentage and a low (3.50 V) /
|
||
critical (3.30 V) warning on the ESP32-C5 card and in the top bar. Below 3.30 V with no phone on USB
|
||
the board deep-sleeps, because the prototype cell has no protection board. See `obu-firmware/FLASHING.md`.
|
||
- **ATT MTU 517** so that a 494-octet V2X_RX (a 512-octet link message) is not split.
|
||
- **BLE and ITS-G5** share one RF front end. Niklas Dathe's TX guard (`CONFIG_MICROBU_TX_BLE_GUARD`)
|
||
holds a frame out of the BLE connection-event windows; the earlier "pause advertising while USB is
|
||
in use" is gone.
|
||
- **NVS 80 KB instead of 24 KB**, app at 0x20000. At 24 KB the BLE bond could not be stored and the
|
||
phone had to pair on every connection.
|
||
- Fixes carried over from the bench: radio queue drained before the first PoTi; 2.4 KB RX buffer off
|
||
the Wi-Fi task stack; serial writes skipped when no USB host is present; manual country policy.
|
||
|
||
## Link protocol
|
||
|
||
Station-link, revision 2 (`obu-firmware/docs/station-link.tex`; revision 1 is Niklas Dathe's): `[opcode][flags][sequence LE][body]`,
|
||
little-endian, at most 512 octets (bodies above that are fragmented by the spec; this app never needs it). Over USB each message is one `0xAA55` frame of type `0x10`
|
||
(the old framing and CRC). Over BLE each message is one GATT value on service
|
||
`0000C175-BA5E-4C17-8000-00805F9B34FB` (the README describes a different, Nordic-UART layout; the
|
||
firmware is what counts; the current spec table lists the same UUIDs).
|
||
|
||
| Direction | Message | Used for |
|
||
|---|---|---|
|
||
| phone → board | `STATION_CONFIGURE` | station type, channel 180, 20 dBm; the 16-octet form also names the MAC (pseudonym); starts the radio |
|
||
| phone → board | `CREDENTIALS_PROVISION` | the demo bundle, once, when the board reports no ticket |
|
||
| phone → board | `POTI_UPDATE` | position and ITS time, once per new GNSS fix |
|
||
| phone → board | `BTP_DATA_REQUEST` | one CAM (port 2001, psid 36) or VAM (port 2018, psid 638), signed or not |
|
||
| phone → board | `STATUS_REQUEST` | once a second; the answer is the heartbeat |
|
||
| board → phone | `CONFIRM` | answer to a request; for `STATUS_REQUEST` its detail is the 131-octet snapshot: counters, tickets, signed/refused counts, battery |
|
||
| board → phone | `V2X_RX` (0x90, MicrOBU) | every ITS message heard on air |
|
||
| board → phone | `RAW_FRAME` (0x85, spec) | debug copy of each radio frame, only while `RAW_CAPTURE` is on; the app can use it instead of `V2X_RX` (Settings > Receive path) |
|
||
|
||
The app side is `Esp32Link.kt` (session), `StationLink.kt` (codec, pinned by unit tests to bytes
|
||
from Niklas Dathe's Python implementation), `UsbSerialTransport.kt` and `BleLinkTransport.kt`.
|
||
A board still on the previous C firmware is recognised by its old heartbeat and keeps working for
|
||
CAM over USB. The pseudonym's MAC goes to the board in the 16-octet STATION_CONFIGURE (which Niklas Dathe's
|
||
spec retires but the station still decodes, and revision 2 documents): a ride rotates it with the station ID, the bench CAM
|
||
pinger keeps one fixed MAC, and a new MAC reconfigures the station. Without one a signed station takes its address from the
|
||
ticket and an unsigned one draws a random MAC per configuration. With one, signed and unsigned frames both leave from it.
|
||
|
||
Data flow of a received frame, with both paths:
|
||
|
||
```mermaid
|
||
flowchart TB
|
||
subgraph Board[ESP32-C5 board]
|
||
Air[ITS-G5 frame] --> Radio[Radio, promiscuous RX]
|
||
Radio --> Stack[Vanetza: decap, verify]
|
||
Radio --> Unwrap[gn_unwrap.c]
|
||
Radio -->|RAW_CAPTURE on| Tap[Raw capture tap]
|
||
Stack -->|verified| Ind[BTP_DATA_INDICATION]
|
||
Unwrap --> Rx[V2X_RX 0x90]
|
||
Tap --> RawF[RAW_FRAME 0x85, fragmented]
|
||
end
|
||
Ind & Rx & RawF --> Link[USB or BLE link]
|
||
subgraph Phone[Android app]
|
||
Link --> Re[LinkReassembly]
|
||
Re --> Sel{Receive path}
|
||
Sel -->|V2X_RX| Dec[V2xRxFrame]
|
||
Sel -->|Raw frames| Pr[RawFrame, then GnUnwrap]
|
||
Pr --> Dec
|
||
Dec --> Cod[CAM, DENM, SPATEM, MAPEM, VAM codecs]
|
||
Cod --> UI[Use cases, V2X screens, logger]
|
||
end
|
||
```
|
||
|
||
The app also **reassembles fragmented link messages** (flags 1-3 of the spec) and has two receive paths: `V2X_RX`
|
||
(default) and `RAW_FRAME`, which it unwraps itself with `GnUnwrap.kt`; see the README for the comparison.
|
||
|
||
## Redundancy and recovery
|
||
|
||
| Situation | What notices | What happens |
|
||
|---|---|---|
|
||
| USB link dead (board hung, cable) | app watchdog: no frame for 3.5 s (the app polls `STATUS` every second) | link marked ERROR on the card |
|
||
| USB unplugged | Android detach broadcast | port closed; Connect again after re-plugging |
|
||
| BLE link lost | BLE supervision timeout (4 s) | app reconnects by itself: 1 s after a drop, then backing off to 30 s if attempts fail |
|
||
| Board reset / power cycle | first `STATUS` reply says "not configured" | app reconfigures (and re-provisions if needed) without user action |
|
||
| App closed and reopened | new session | app configures the board again; BLE reconnects with the stored bond, no passkey (confirmed) |
|
||
| Phone clock or GNSS time jumping | app tracks the board's clock | PoTi never moves it backwards (except a real correction of ≥ 60 s), so the board does not restart its stack |
|
||
| Board firmware wedged | ESP task watchdog (30 s) | the phone sees it as a dead link (above) |
|
||
|
||
## App changes
|
||
|
||
- Settings > Connection > ESP32-C5: **link** USB-C / Bluetooth, **transmit** CAM / VAM, **sign
|
||
outgoing messages** (on by default). The connection card, top bar and dashboard show the link in
|
||
use, the pairing passkey when needed, and signing counters.
|
||
- VAM encoder (`VamUperCodec.kt`, TS 103 300-3 V2.3.1, checked against asn1tools) and the VAM
|
||
generation rules (`VamGenerationRules.kt`).
|
||
- `GnssTimeSource` keeps the last measured phone-clock error while GNSS time drops out indoors. The
|
||
bench phone's clock was 14 minutes fast; falling back to it made every transmitted timestamp
|
||
jump by 14 minutes.
|
||
- Bluetooth permissions (Android 12+) requested at start-up.
|
||
|
||
## Credentials (demo PKI)
|
||
|
||
`app/src/main/assets/demo-chain.vcr`, generated 2026-09-23 with Niklas Dathe's `vidf_issue`: root
|
||
`6E7D0374FB021901` → AA `B3312F29844299E0` → AT `B80B49387A4C12EB` (two years; psid 36 SSP `010000`,
|
||
psid 638 SSP `01`). It is throwaway and not EU-registered; its private key ships with the app on
|
||
purpose. Niklas Dathe's own demo chain only grants psid 638 and cannot sign CAMs.
|
||
|
||
## Verification
|
||
|
||
- **Unit tests** (103): VAM bytes against asn1tools, station-link messages against Niklas Dathe's
|
||
Python encoder, VAM generation rules.
|
||
- **Signatures on air**: `obu-firmware/test/verify_signed_pcap.py` checks a pcap with asn1tools
|
||
and OpenSSL, sharing no code with the firmware. Pinger capture of 2026-09-23: 12/12 signed CAMs,
|
||
psid 36, signer the demo AT, all signatures valid, chain valid.
|
||
- **Third-party stack**: the CiT One receives the signed CAMs (~1 Hz on `v2x/rx/cam`), so its
|
||
stack unwraps our envelope. Its MQTT interface exposes no security information, and it forwards
|
||
unsigned and unknown-root messages alike, so it cannot tell whether it verified the signature.
|
||
- **V2X2MAP (COM10)**: now Niklas Dathe's v2x2map 0.3.0 bridge from source with a new
|
||
`verify.py` and `--trust demo-chain.vcr`; it shows "signature verified", "SIGNATURE INVALID" or
|
||
"not verified" per packet. Signed CAMs and signed VAMs verified live; a one-bit change in a
|
||
signed CAM comes out invalid. Launcher: `micrOBU_workspace/v2x-obu-esp32c5/start-v2x2map-signed.bat`.
|
||
|
||
## Open
|
||
|
||
- BLE/ITS-G5 coexistence is not measured: does an active BLE connection cost 5.9 GHz reception?
|
||
- `time_regression` standing still indoors for several minutes, and board reset recovery over BLE,
|
||
after the last fixes.
|
||
- Real EU PKI enrolment/authorisation (TS 102 941) instead of the demo chain.
|