The firmware dropped every received ITS message over 494 bytes (one link message), so a road RSU's 888-byte SPATEM and 1198-byte MAPEM never reached the phone. V2X_RX now goes out in link fragments up to 2300 bytes, best effort and non-blocking; messages up to 494 bytes are unchanged. The app's SPATEM decoder then refused those messages because they carry intersection and movement names and advisory speed lists. It now reads past both, checked against asn1tools on 718 distinct messages. Adds the pure fragmenter with host tests and a pcap replay, a Kotlin cross-check on the firmware's own fragments, tools/rx_size_compare.py, docs/08-large-message-reception.md and station-link revision 3.
156 lines
7.2 KiB
Markdown
156 lines
7.2 KiB
Markdown
# obu-firmware (micrOBU ESP32-C5)
|
|
|
|
The firmware of the production MicrOBU: the ESP32-C5 half of the station, on the Seeed XIAO ESP32-C5.
|
|
It is the station firmware written by **Niklas Dathe** (`microbu-firmware`, HAW GitLab
|
|
urban-mobility-lab/microbu/microbu-firmware, commit e4e4bd8) with the MicrOBU additions listed in
|
|
[NOTES.md](NOTES.md). The phone builds CAM and VAM messages; this firmware adds BTP and
|
|
GeoNetworking, signs, transmits over ITS-G5, and hands every received ITS message back to the phone.
|
|
|
|
```mermaid
|
|
flowchart LR
|
|
App[Android app: facilities and HMI] <-->|USB or encrypted BLE| Link[Station link]
|
|
App -->|STATUS_REQUEST, 1 Hz| Link
|
|
Link -->|CONFIRM with status| App
|
|
Link <--> Wrapper[microbu_v2x]
|
|
Wrapper <--> GN[Vanetza BTP and GeoNetworking]
|
|
Wrapper <--> Security[Security and device PKI client]
|
|
Security <--> NVS[NVS credentials and keys]
|
|
GN <--> Radio[ESP32-C5 ITS-G5 radio]
|
|
Radio -->|every data frame| Raw[gn_unwrap.c, MicrOBU]
|
|
Raw -->|V2X_RX 0x90, signed or not| Link
|
|
Link -->|unsigned request| Geo[geonet.c, MicrOBU]
|
|
Geo --> Radio
|
|
Battery[Battery guard, MicrOBU] -.->|deep sleep below 3.30 V| Radio
|
|
```
|
|
|
|
```yaml
|
|
target: ESP32-C5
|
|
SDK: ESP-IDF-6.0.2 # exactly; the radio driver ABI is pinned to it
|
|
board: Seeed-XIAO-ESP32-C5 # 8 MB flash, one native USB-C port
|
|
other_board: mainboard-v5 # the custom PCB, menuconfig -> micrOBU firmware -> Board
|
|
runtime:
|
|
main/: station-and-link-service
|
|
components/microbu_v2x: station-wrapper-and-security # Niklas Dathe, unchanged
|
|
components/vanetza: ESP-IDF-component # Niklas Dathe, unchanged
|
|
external/vanetza: patched-upstream-source # see external/vanetza/UPSTREAM
|
|
link:
|
|
spec: docs/station-link.tex (revision 2; revision 1 is Niklas Dathe's)
|
|
transports: USB Serial/JTAG (0xAA55 frames) and BLE GATT (service 0000c175-...)
|
|
max_message: 512 octets, fragmented above that by the spec
|
|
microbu_extensions:
|
|
V2X_RX: opcode 0x90, every ITS message heard on air, verified or not
|
|
receive_paths: V2X_RX and the spec's RAW_FRAME both stay; the app chooses (Settings > Receive path), RAW_CAPTURE mode 3 turns raw on
|
|
unsigned_tx: security profile 1, or 0 with station security 0
|
|
radio: polled from STATION_CONFIGURE on
|
|
battery_guard: deep sleep below 3.30 V, no phone on USB, runs again from 3.60 V
|
|
flash_layout:
|
|
nvs: 80 KB at 0x9000
|
|
app: 3 MB at 0x20000
|
|
telemetry:
|
|
battery: calibrated-divider-voltage # GPIO6, enabled by GPIO26, only + and - are wired
|
|
temperature: unavailable
|
|
charger_source: unavailable
|
|
keys:
|
|
backend: ESP32-PSA
|
|
storage: NVS
|
|
NVS_encryption: only-if-flash-encryption-already-active
|
|
eFuse_writes: forbidden # cmake/no_efuse_writes.cmake
|
|
```
|
|
|
|
## Build and flash
|
|
|
|
```powershell
|
|
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
|
|
$env:IDF_TOOLS_PATH = "C:\Espressif"
|
|
C:\Espressif\frameworks\esp-idf-v6.0.2\export.ps1
|
|
cd obu-firmware
|
|
idf.py set-target esp32c5 # once per clean build folder
|
|
idf.py build
|
|
idf.py -p COMx flash # full flash, never app-flash: the partition table is ours
|
|
```
|
|
|
|
```text
|
|
menuconfig -> micrOBU firmware -> Board, battery thresholds, BLE passkey, TX BLE guard, status LED
|
|
```
|
|
|
|
Everything else (the `--no-stub` fallback, reading a board's app descriptor before flashing, the
|
|
production checklist with the cell, battery and pins): [FLASHING.md](FLASHING.md).
|
|
|
|
## Using it
|
|
|
|
The log arrives as `LOG` frames (type 0x7F) on the USB link, so a XIAO needs no UART adapter. To see
|
|
the board from the PC:
|
|
|
|
```powershell
|
|
py -3.11 tools/station_status_watch.py COMx 30 --configure --rx
|
|
py -3.11 tools/station_tx_test.py COMx --seconds 60 --mac 02:aa:bb:cc:dd:01 # plays the phone, reads the raw own-TX capture
|
|
```
|
|
|
|
It prints the log, the 131-octet STATUS once a second (uptime, signing and radio counters, heap,
|
|
battery) and the first V2X_RX messages. Status exchange: the host sends `STATUS_REQUEST` every
|
|
1000 ms; `CONFIRM.detail` contains the snapshot.
|
|
|
|
Received messages reach the phone on two paths that both stay in the firmware: `V2X_RX` (ours, always on, already unwrapped, one message up to 494 octets, fragmented above that up to 2300) and `RAW_FRAME` (the spec's debug capture, on after `RAW_CAPTURE`, the whole radio frame, fragmented when large). The Android app has a switch for which one it consumes; the board always sends `V2X_RX`. See [NOTES.md](NOTES.md).
|
|
|
|
```mermaid
|
|
flowchart LR
|
|
Air[ITS-G5 frame on air] --> Radio[C5 radio, promiscuous RX]
|
|
Radio --> Stack[Vanetza stack: decap and verify]
|
|
Radio --> Unwrap[gn_unwrap.c: 802.11, LLC, GN, BTP, signature envelope]
|
|
Radio -->|only while RAW_CAPTURE is on| Cap[Raw capture tap: ITS5 record]
|
|
Stack -->|verified only| Ind[BTP_DATA_INDICATION 0x81]
|
|
Unwrap -->|always, signed or not, fragmented above 494 octets| Rx[V2X_RX 0x90, MicrOBU]
|
|
Cap -->|fragmented if large| Raw[RAW_FRAME 0x85, spec]
|
|
Ind --> Link[Station link: USB or BLE]
|
|
Rx --> Link
|
|
Raw --> Link
|
|
Link --> App[Android app]
|
|
App -->|Receive path: V2X_RX| UseA[uses V2X_RX, ignores RAW_FRAME]
|
|
App -->|Receive path: Raw frames| UseB[reassembles, unwraps with GnUnwrap, ignores V2X_RX]
|
|
```
|
|
|
|
|
|
## BLE pairing
|
|
|
|
```yaml
|
|
# as documented for Niklas Dathe's BLE code, which this firmware does not modify
|
|
BLE_pairing:
|
|
compile_time: CONFIG_MICROBU_BLE_PASSKEY
|
|
default: 123456
|
|
disable_value: 0
|
|
unprovisioned_station: USB-only
|
|
bond_storage: NVS # 80 KB, so the bond persists
|
|
owner: first-bond-only
|
|
remote_bond_replacement: refused
|
|
hardware_security: existing-state-only
|
|
generate_hardware_keys: forbidden
|
|
```
|
|
|
|
The passkey is public, so the link is encrypted but not protected against an active attacker during
|
|
the first pairing. A phone that was paired before must forget `micrOBU-XXXX` in Android's Bluetooth
|
|
settings after the board's NVS was erased. BLE and ITS-G5 share one RF front end: the firmware holds a
|
|
frame out of the BLE connection-event windows (`CONFIG_MICROBU_TX_BLE_GUARD`; calibrated for a 20 ms connection interval only). The bond is one per board and survives a reset; with several micrOBUs nearby pair the right one in Android first (FLASHING.md).
|
|
|
|
## Tests
|
|
|
|
```powershell
|
|
$env:PATH = "C:\msys64\ucrt64\bin;C:\msys64\usr\bin;$env:PATH"
|
|
cd obu-firmware\test\host
|
|
make firmware # 40 unit tests: link codec, STATUS, reassembly, V2X_RX, policies. PASS or FAIL per test
|
|
make # everything: chain, replay of recorded frames, fuzz, battery, firmware
|
|
```
|
|
|
|
These run on the PC and cannot test the radio, BLE, NVS or USB. What still needs a board, a phone or a
|
|
second ESP32-C5 is listed in [../TODO.md](../TODO.md). More: [test/host/README.md](test/host/README.md).
|
|
|
|
## More
|
|
|
|
| | |
|
|
|---|---|
|
|
| [NOTES.md](NOTES.md) | Every MicrOBU addition and why, what changed for the phone |
|
|
| [FLASHING.md](FLASHING.md) | Toolchain, flashing, bring-up checklist, battery and pins |
|
|
| [docs/station-link.pdf](docs/station-link.pdf) | The link interface reference, revision 2 (source: `station-link.tex`) |
|
|
| [external/vanetza/LICENSE.md](external/vanetza/LICENSE.md) | Vanetza licence |
|
|
| [external/vanetza/UPSTREAM](external/vanetza/UPSTREAM) | Upstream revision of the vendored Vanetza |
|
|
| [ESP32-C5 flash encryption](https://docs.espressif.com/projects/esp-idf/en/v6.0.2/esp32c5/security/flash-encryption.html) | Existing hardware state only; this firmware never enables it |
|