Files
MicrOBU/obu-firmware/NOTES.md
T
Ashin Walpola 37707548ca Rotate the link-layer address with the pseudonym again
The app sends the pseudonym's MAC in the 16-octet STATION_CONFIGURE (address_configuration
0), the station uses it for unsigned frames too, and a different MAC reconfigures the
station. A ride rotates it with the station ID; the bench CAM pinger keeps one. Without a
MAC the station behaves as before (ticket-derived when signed, random when unsigned).

tools/station_tx_test.py plays the phone over USB and reads the station's own raw capture
(source MAC, signed or not, submitted and completed counts). Add the 16-octet form to the
spec (revision 2), a firmware unit test and an app test. Fix the stale Connection texts.
2026-11-11 15:02:39 +01:00

6.5 KiB

obu-firmware

The production OBU firmware: the ESP32-C5 half of the MicrOBU station (Seeed XIAO ESP32-C5).

Since 2026-11-10: Niklas Dathe's microbu-firmware architecture

This tree is the current station firmware written by Niklas Dathe (microbu-firmware, HAW GitLab urban-mobility-lab/microbu/microbu-firmware, commit e4e4bd8) with the MicrOBU additions below. The earlier port of their older microbu-esp32c5 (vanetza-idf, 2026-09-23) is gone.

Layout:

Path What
main/ station and link service: station.cpp, link_*, serial_link.cpp, simple_ble.cpp, c5_radio.cpp, board controls, battery
components/microbu_v2x/ station wrapper, security entity, device PKI client (unchanged from Niklas Dathe's firmware)
components/vanetza/ ESP-IDF component around Vanetza (unchanged)
external/vanetza/ patched upstream Vanetza source (unchanged, see its UPSTREAM)
docs/station-link.tex the link interface reference this firmware and the app implement: revision 2, Niklas Dathe's revision 1 plus our extensions (the original PDF is microbu-firmware/docs/station-link.pdf; build ours with pdflatex, no LaTeX is installed on the lab laptop)
cmake/no_efuse_writes.cmake build guard: nothing in this firmware may program eFuses
test/host/ PC tests (make in that folder): the MicrOBU C code (gn_unwrap.c, geonet.c), the battery policy and, with make firmware, 39 unit tests of the link codec, V2X_RX and the policies

Take a newer release from Niklas Dathe by copying firmware/{main,components,cmake} and external/vanetza over these folders and re-applying the MicrOBU: changes (search the sources for that word). Nothing is fetched from or pushed to their repository.

Board: CONFIG_MICROBU_BOARD_XIAO_C5 (sdkconfig.defaults). Their default is mainboard-v5, the custom PCB; pick it in menuconfig -> micrOBU firmware -> Board.

MicrOBU additions (search for MicrOBU)

  • Reception of everything on air: V2X_RX, opcode 0x90. The stack decapsulates strictly, so it drops unsigned traffic (the bench sim car) and everything signed under a root other than the provisioned one (every RSU). Every received data frame therefore also goes through gn_unwrap.c (Station::forward_raw) and reaches the phone as V2X_RX. Body: u16 port, i8 rssi, u8 flags (bit0 GBC area, bit1 signed), i32 lat, i32 lon, u16 distance_a, ITS payload. 0x85 is the spec's RAW_FRAME debug capture and 0x86 is reserved by Niklas Dathe, hence 0x90. BTP ports 2001 CAM, 2002 DENM, 2003 MAPEM, 2004 SPATEM, 2018 VAM pass; a message over 494 bytes does not fit a 512-octet link message and is dropped and counted (not fragmented).
  • Unsigned transmission. Niklas Dathe's station signs everything. A request with GN security profile 1 (or 0 while the station is configured security = 0) goes out unsigned with geonet.c's header and the position of the last PoTi (Station::unsecured_request), from a random locally administered MAC drawn at every STATION_CONFIGURE, or the MAC the phone names in the 16-octet STATION_CONFIGURE (address_configuration 0), which also sets the address of signed frames: a ride rotates it with the pseudonym, the CAM pinger keeps one. The app's "Sign outgoing messages" setting decides per message. It bypasses the BLE collision guard's queue but not the guard itself.
  • Radio polled from configure on, not from the first PoTi, so the 16-frame queue never overflows while the phone has not sent a fix yet.
  • Radio bring-up from the previous C firmware: manual country policy (5 GHz channels on), TX power read-back logged, 2.4 KB receive buffer static instead of on the Wi-Fi task's stack, frames too short to be GN packets ignored rather than counted as lost.
  • Battery guard. Niklas Dathe's firmware only reports battery_mv in STATUS. A XIAO cell has no protection board, so battery_policy.hpp (smoothing, warning hysteresis, shutdown) deep-sleeps the board below 3.30 V for 30 s when no phone is on USB, re-checks every 5 min, and runs again from 3.60 V. Thresholds: menuconfig -> micrOBU firmware.
  • Battery reading fix (battery_monitor.cpp, found on the XIAO 2026-11-11: battery_mv was 0). At CONFIG_FREERTOS_HZ=100 vTaskDelay(pdMS_TO_TICKS(5)) is zero ticks, so the switched divider never settled before the ADC read it and every sample fell below the 2.5 V validity floor. It is now a 5 ms busy wait, and GPIO26 is set up with gpio_config. Worth telling Niklas Dathe: his mainboard-v5 has no switched divider and is not affected. With the fix the XIAO reads 4153-4156 mV on a charging cell.
  • Serial link: no write attempt while no USB host is connected; last_frame_ms() tells the battery guard whether a phone is powering the board.
  • Partition table: 80 KB NVS (Niklas Dathe's 24 KB filled up and BLE bonds stopped persisting), app at 0x20000. A plain app-only flash of an older layout is wrong: flash everything.
  • Flash size 8 MB (XIAO), TX power ceiling 20 dBm (radio_policy.hpp admits 20 dBm on channel 180).

docs/station-link.tex is revision 2 of the interface reference: Niklas Dathe's revision 1 (microbu-firmware e4e4bd8, kept unchanged as microbu-firmware/docs/station-link.pdf) plus a section "MicrOBU extensions": V2X_RX (0x90), unsigned transmission (security profile 0x01, or 0x00 with security 0; random MAC per configure), the battery shutdown rule, no USB writes without a host, and a revision history. The wire format of revision 1 is unchanged, so a revision 1 host still works. No LaTeX is installed on the lab laptop: build the PDF with pdflatex station-link.tex (twice) elsewhere.

What the new firmware changes for the phone

See docs/station-link.tex (revision history at its end). In short: RESULT/STATUS became CONFIRM (0x80) with the 131-octet status in CONFIRM.detail of STATUS_REQUEST; STATION_CONFIGURE is 6 octets (type, channel, power, security, beaconing; no MAC, the address derives from the ticket); BTP-DATA.request carries generated_at_ms (requests older than 1 s are refused); request bodies up to 1536 and indications up to 65535 octets are fragmented; logs travel as LOG frames (0x7F) on the USB link, so a XIAO needs no UART adapter any more.

Credentials: the app ships assets/demo-chain.vcr, a throwaway chain with psid 36 (CAM) and 638 (VAM). Not EU-registered: receivers that verify against the EU trust list drop what it signs.

Time: TimestampIts counts TAI milliseconds since 2004 (TS 102 894-2), 5 leap seconds ahead of UTC; the app's ItsTime follows that.