From 6f99154b2389fb6d09082a1374198f4c9da2baac Mon Sep 17 00:00:00 2001 From: Ashin Walpola Date: Wed, 11 Nov 2026 01:30:47 +0100 Subject: [PATCH] Add a firmware README and an architecture overview to the app README obu-firmware/README.md follows Niklas Dathe's microbu-firmware README: station diagram with the MicrOBU raw receive, unsigned transmit and battery paths, a summary block, build and flash, BLE pairing, host tests and links. The app README gets an architecture diagram and a summary block, corrects the pseudonym description for the 2026-11-10 firmware (the link has no MAC field any more) and the unit test count (130). --- README.md | 43 ++++++++++++- obu-firmware/README.md | 133 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 obu-firmware/README.md diff --git a/README.md b/README.md index bf3fccd..f9e7a38 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,45 @@ The app is the HMI for the OBU hardware and, on the ESP32-C5 path, also the ITS **Platform:** Android (Kotlin) / **Min SDK:** 29 (Android 10) / **Target SDK:** 36 / **Version:** 0.1.0 (`versionName`, Phase 03) +```mermaid +flowchart LR + subgraph Phone[Android app] + UI[Compose UI and use cases] + Fac[ITS facilities: CAM, VAM, DENM, SPATEM and MAPEM codecs] + Sens[GNSS, IMU, trip recording] + Link[Esp32Link and StationLink] + end + Sens --> Fac + Fac -->|BTP_DATA_REQUEST, POTI_UPDATE| Link + Link -->|V2X_RX, CONFIRM with status| Fac + Fac --> UI + Link <-->|USB-C or encrypted BLE, station-link rev. 2| OBU[obu-firmware on the XIAO ESP32-C5] + OBU <-->|BTP, GeoNetworking, signing| Air[ITS-G5 5.9 GHz] + UI <-->|IP over USB tethering, MQTT| CiT[consider it CiT One] +``` + +```yaml +platform: Android +language: Kotlin +UI: Jetpack-Compose +DI: Hilt +min_sdk: 29 +target_sdk: 36 +hardware_paths: + esp32_c5: # primary; the app is the ITS facilities layer + firmware: obu-firmware/ # Niklas Dathe's microbu-firmware plus MicrOBU additions + transport: [USB-C native Serial/JTAG, Bluetooth LE GATT] + protocol: station-link revision 2 (obu-firmware/docs/station-link.pdf) + app_builds: [CAM, VAM, decodes CAM, DENM, SPATEM, MAPEM, VAM] + board_does: [BTP, GeoNetworking, signing, radio] + cit_one: # consider it CiT One + transport: IP over USB tethering, MQTT +messages_received: V2X_RX (0x90), signed or not, up to 494 octets +messages_sent: signed or unsigned per setting (Settings > Connection > ESP32-C5) +credentials: throwaway demo chain in app/src/main/assets/demo-chain.vcr +tests: 130 JVM unit tests, no emulator needed (domain/ has no Android imports) +``` + ## Project goal Demonstrate V2X communication with at least one C2C-CC bicycle safety use case working on the ESP32-C5, specifically intersection movement assist: a car approaching an intersection on a path that conflicts with the rider's. @@ -37,7 +76,7 @@ Both paths converge at `CamUseCaseRepository`, which normalises whatever arrived **CAM-based use case detection**; correlates the rider's own state with a short per-station history of received CAMs to evaluate five C2C-CC bicycle safety use cases (IMA-B, IMA-S, RTW-B, LTW-B, SMVA/BCW-B) and raises alerts under the three-tier Info / Awareness / Warning model. None of these use cases generates a DENM. -**Phone-generated CAM or VAM**; on the ESP32-C5 path the app builds a CAM (EN 302 637-2) or a VAM (TS 103 300-3, cyclist profile, its generation rules included) from live GNSS and IMU, UPER-encodes it, and hands it to the board with "signed" or "unsigned" (Settings > Connection > ESP32-C5). The board adds BTP and GeoNetworking, signs it with its authorization ticket, and transmits it over ITS-G5. Each message carries a rotating pseudonym (station ID and MAC change together) and ITS time in TAI. +**Phone-generated CAM or VAM**; on the ESP32-C5 path the app builds a CAM (EN 302 637-2) or a VAM (TS 103 300-3, cyclist profile, its generation rules included) from live GNSS and IMU, UPER-encodes it, and hands it to the board with "signed" or "unsigned" (Settings > Connection > ESP32-C5). The board adds BTP and GeoNetworking, signs it with its authorization ticket, and transmits it over ITS-G5. The CAM and VAM station ID rotates as a pseudonym. The link-layer address is the board's: derived from the authorization ticket when signed, a random MAC per configuration when unsigned (the link has no MAC field since the 2026-11-10 firmware, so the address does not rotate with the station ID). ITS time is TAI. **DENM transmission**; CiT One path only. Triggers the stationary vehicle profile (`hln-sv`, causeCode 94) via the consider it Use Case API. This is a manual antenna and range test tool. It is never triggered by a detected event or a use case alert, and the control is hidden entirely on the ESP32-C5 path. @@ -85,7 +124,7 @@ tools/ Bench scripts: STATUS watcher, bench-listener tally, MAPEM docs/ Requirements traceability, signed ITS / VAM / BLE design, architecture diagrams ``` -The `domain/` packages contain no Android imports. That is what makes the 132-test JVM suite possible without an emulator or instrumentation. +The `domain/` packages contain no Android imports. That is what makes the 130-test JVM suite possible without an emulator or instrumentation. ## Connectivity diff --git a/obu-firmware/README.md b/obu-firmware/README.md new file mode 100644 index 0000000..1e4d4e8 --- /dev/null +++ b/obu-firmware/README.md @@ -0,0 +1,133 @@ +# 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 + 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 +``` + +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. + +## 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`). + +## Tests + +```powershell +$env:PATH = "C:\msys64\ucrt64\bin;C:\msys64\usr\bin;$env:PATH" +cd obu-firmware\test\host +make firmware # 39 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 |