Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38c21ed2a4 | ||
|
|
d02948d7fc | ||
|
|
03efcfd4ee | ||
|
|
37707548ca | ||
|
|
a7a6c39ca1 | ||
|
|
c78b66341b |
@@ -42,7 +42,7 @@ hardware_paths:
|
||||
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)
|
||||
tests: 131 JVM unit tests, no emulator needed (domain/ has no Android imports)
|
||||
```
|
||||
|
||||
## Project goal
|
||||
@@ -76,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. 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.
|
||||
**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, and the link-layer address (802.11 source and GN address) rotates with it: the app sends the pseudonym's MAC in the 16-octet STATION_CONFIGURE and the board reconfigures on a change. The bench CAM pinger keeps one fixed identity and MAC. 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.
|
||||
|
||||
@@ -124,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 130-test JVM suite possible without an emulator or instrumentation.
|
||||
The `domain/` packages contain no Android imports. That is what makes the 131-test JVM suite possible without an emulator or instrumentation.
|
||||
|
||||
## Connectivity
|
||||
|
||||
@@ -143,9 +143,10 @@ On the ESP32-C5 path there is no network layer. Both links carry the same **stat
|
||||
|
||||
Settings > Connection > ESP32-C5 > link: Bluetooth.
|
||||
|
||||
- **GATT layout**: service `0000C175-BA5E-4C17-8000-00805F9B34FB`, one characteristic per primitive. Each value is one whole link message, never fragmented, so the app raises the ATT MTU to 517 first; the firmware drops a notification rather than send it cut short.
|
||||
- **GATT layout**: service `0000C175-BA5E-4C17-8000-00805F9B34FB`, one characteristic per primitive. Each value is one whole link message, never fragmented, so the app raises the ATT MTU to 517 first (the firmware asks for 517 too); the firmware drops a notification rather than send it cut short.
|
||||
- **Pairing**: the board advertises as `micrOBU-XXXX`. LE Secure Connections with a fixed passkey, **123456**, entered once in Android's own pairing dialog. The bond is kept on both sides (the board stores it in its 80 KB NVS). The passkey is public, so this gives an encrypted link but no protection against an active attacker during that first pairing.
|
||||
- **Reconnect**: after a drop (4 s supervision timeout) the app reconnects by itself, 1 s later and then backing off to 30 s. With several bonded micrOBUs (a replaced board stays bonded), the one that connected last is tried first, then the others in turn.
|
||||
- **Several boards nearby**: with no bond the app connects to the first micrOBU it hears, which on a bench with several is not necessarily yours. Pair the right one in Android's Bluetooth settings first (name `micrOBU-` plus the last two octets of its BLE address); the app then prefers a bonded micrOBU. See [obu-firmware/FLASHING.md](obu-firmware/FLASHING.md).
|
||||
- **BLE and ITS-G5 share the C5's single RF front end**: the firmware holds an ITS-G5 frame out of the BLE connection-event windows (`CONFIG_MICROBU_TX_BLE_GUARD`).
|
||||
- **Permissions**: `BLUETOOTH_SCAN` and `BLUETOOTH_CONNECT` (Android 12+), requested at start-up.
|
||||
|
||||
@@ -232,7 +233,7 @@ The ESP32-C5 station firmware (BTP, GeoNetworking, TS 103 097 security, the stat
|
||||
|
||||
## Status and known limitations
|
||||
|
||||
Bench verified against live ITS-G5 traffic on 2026-08-25: 2868 frames over 305 seconds, zero decode failures, zero USB errors, zero crashes. Signed CAM and VAM, the BLE link and reception over both links were checked on the bench on 2026-09-23; on 2026-10-28 the ESP32-C5 forwarded the bench RSU's MAPEM (295 bytes), SPATEM and CAM with nothing dropped. On 2026-11-10 the firmware was rebuilt on Niklas Dathe's newer microbu-firmware layout and the app's link followed (link spec revision 2); that firmware boots, advertises and answers STATUS on the XIAO, while reception, transmission, signing and the battery guard on real hardware are still to be re-checked (`TODO.md`). Not yet road validated.
|
||||
Bench verified against live ITS-G5 traffic on 2026-08-25: 2868 frames over 305 seconds, zero decode failures, zero USB errors, zero crashes. Signed CAM and VAM, the BLE link and reception over both links were checked on the bench on 2026-09-23; on 2026-10-28 the ESP32-C5 forwarded the bench RSU's MAPEM (295 bytes), SPATEM and CAM with nothing dropped. On 2026-11-11 the production XIAO and a Pixel 9 Pro were run together: the simulated car's CAMs reach the app, signed and unsigned CAMs from the phone are heard by a second board, the BLE bond survives a board reset, and BLE adds no measurable transmit loss over USB (95.7 % of signed CAMs heard in both; about 4 % is lost on the air or at the listener). On 2026-11-10 the firmware was rebuilt on Niklas Dathe's newer microbu-firmware layout and the app's link followed (link spec revision 2); that firmware boots, advertises and answers STATUS on the XIAO, while reception, transmission, signing and the battery guard on real hardware are still to be re-checked (`TODO.md`). Not yet road validated.
|
||||
|
||||
- **Requirement 11.6, Phase A success criteria, is not met.** The bench proves reception. It cannot prove the use case behaves correctly with two genuinely moving stations, because nothing on the bench moves. This is the main open evidence gap for the project's central claim.
|
||||
- **Demo PKI only.** Signed messages carry a throwaway chain shipped with the app, not an EU-registered one; receivers that verify against the EU trust list drop them. No TS 102 941 enrolment. The board's stack verifies signatures (counted in STATUS), but the `V2X_RX` path the app uses delivers everything without a verdict, only whether a signature is present.
|
||||
|
||||
@@ -5,18 +5,51 @@ Engineering to-do list. The reviewer-facing open items live in
|
||||
|
||||
## Waiting on hardware
|
||||
|
||||
### obu-firmware on Niklas Dathe's microbu-firmware (added 2026-11-10)
|
||||
### obu-firmware on Niklas Dathe's microbu-firmware (added 2026-11-10, bench run 2026-11-11)
|
||||
|
||||
Flashed on the XIAO at COM6 (the board that held an Arduino sketch; backup in
|
||||
`firmware-backups/COM6-arduino-first4MB-2026-11-10.bin`). Seen on the bench: boots, advertises BLE
|
||||
as `micrOBU-894A`, answers STATUS (131 octets), STATION_CONFIGURE starts the radio. Not yet seen,
|
||||
because nothing was transmitting nearby and no phone ran the updated app:
|
||||
Flashed on the production XIAO (COM10) and the phone (Pixel 9 Pro, BLE) on 2026-11-11. Done, by hand
|
||||
on the bench with the COM3 board as a listener:
|
||||
|
||||
- [ ] A beacon on air (simulated car on COM8/COM5 or the bench RSU): `py -3.11 tools/station_status_watch.py COM6 30 --configure --rx` prints V2X_RX lines (port 2001, signed=0) and `radio rx` counts up.
|
||||
- [ ] Unsigned CAM from the phone (Sign outgoing messages off) is heard by a second ESP32-C5 receiver (`obu-firmware/test/pcap_gn_tally.py` on its capture).
|
||||
- [ ] Signed CAM with the demo chain: tickets=1 and `signed` counts up in STATUS, `obu-firmware/test/verify_signed_pcap.py` accepts the capture.
|
||||
- [ ] BLE: pairing with passkey 123456, bond survives a reconnect (80 KB NVS), TX while connected (TX BLE guard).
|
||||
- [ ] Battery: with a cell on the BAT pads, `battery` in STATUS matches a multimeter; the shutdown rule is untested on hardware.
|
||||
- [x] Beacon on air: V2X_RX of the simulated car (port 2001, unsigned, -39 to -52 dBm) reaches the app,
|
||||
which shows station 195936478 with speed, heading and distance.
|
||||
- [x] Signed CAM from the phone (CAM pinger, signing on): "tickets 1, signed 113, refused 0, on air 113"
|
||||
on the Connection card; the COM3 listener hears them as signed port 2001 CAMs, 17 in 20 s of a 1 Hz
|
||||
pinger (the signature itself was not verified; `test/verify_signed_pcap.py` on a capture would).
|
||||
- [x] Unsigned CAM from the phone (signing off): the listener hears 82 unsigned in 20 s, simulated car
|
||||
(about 60) plus the phone (about 20), none signed.
|
||||
- [x] BLE: the phone connected and ran the whole test; the demo credentials were provisioned (tickets 1).
|
||||
- [x] Battery: the app shows 4.16 V, about 95 % on the charging cell (the reading was 0 mV until the
|
||||
divider settle-time fix, c78b663).
|
||||
|
||||
Still open:
|
||||
|
||||
- [x] Bond persistence (2026-11-11): the board was reflashed (MTU 517) with its NVS kept; the phone reconnected to
|
||||
micrOBU-66AA without a pairing prompt.
|
||||
- [ ] Verify a captured signature with `test/verify_signed_pcap.py` (needs the sniffer firmware).
|
||||
- [ ] 17 of 20 signed CAMs heard against 20 sent: measure the loss over a few minutes, with and without
|
||||
the BLE link busy (TX BLE guard).
|
||||
- [ ] Battery: no multimeter reference (the board is glued in); compare the plateau at full charge with
|
||||
the charger's 4.20 V, and run the shutdown rule on a flat cell.
|
||||
- [ ] The Connection settings text still says "the board only advertises while nothing uses its USB-C port"
|
||||
(the firmware no longer pauses advertising) and the card header says "ESP32-C5 (USB Serial)" while
|
||||
connected over Bluetooth.
|
||||
- [x] Pseudonym rotation (2026-11-11): the app sends the pseudonym MAC in the 16-octet STATION_CONFIGURE
|
||||
again; checked with `tools/station_tx_test.py` over USB and the station's own raw capture: a named MAC
|
||||
is the 802.11 source of signed and of unsigned frames; without one a signed frame carries the
|
||||
ticket-derived address and an unsigned one a random MAC. Still to see on a ride: the MAC changes at the
|
||||
rotation interval.
|
||||
- [x] TX loss, measured 2026-11-11 with the COM3 listener: USB with BLE off 287 of 300 signed CAMs heard (95.7 %,
|
||||
the board reports 300 submitted and 300 completed); BLE from the phone's pinger with the screen on 180 of
|
||||
the 188 the board put on air (95.7 %). So the BLE link adds no measurable loss, and the ~4 % is on the air
|
||||
or in the listener. One earlier BLE run, during which the phone screen turned off, heard 261 of about
|
||||
305 (86 %): to check whether Android's changed connection interval (the board logged 48.75 ms once; the TX
|
||||
guard is calibrated for 20 ms only) is the cause, log the board's `BLE interval ... no calibrated TX guard`
|
||||
warning over a longer run with the screen off.
|
||||
- [ ] BLE with several boards: with no bond the app connects to the first micrOBU it hears. On the bench four
|
||||
advertise at -49 to -55 dBm (4AFA, 3FAA, A25E, 66AA) and it paired with the wrong one (4AFA). Pair the
|
||||
right board in Android's Bluetooth settings first, or add a choice to the app.
|
||||
- [ ] A phone whose bond is gone (it showed none after a Bluetooth toggle) gets a connect-then-drop loop from a
|
||||
board that still holds the bond: erase the board's NVS (`esptool erase-region 0x9000 0x15000`) and pair again.
|
||||
|
||||
### MAPEM decoder and traffic lights per lane (added 2026-10-28)
|
||||
|
||||
|
||||
@@ -234,7 +234,7 @@ class Esp32Link @Inject constructor(
|
||||
|
||||
private suspend fun sendStationLink(its: OutgoingIts): Boolean {
|
||||
val pv = its.positionVector
|
||||
if (!ensureConfigured(StationConfigure(stationType = pv.stationType))) return false
|
||||
if (!ensureConfigured(StationConfigure(stationType = pv.stationType, mid = pv.mac))) return false
|
||||
// The micrOBU's ITS clock must never be sent backwards: past 1 s it answers
|
||||
// time_regression and rebuilds its whole stack. Two things tried to. The transmit loops
|
||||
// re-send the latest GNSS fix every tick while fused location pauses, so an old fix time
|
||||
|
||||
@@ -90,10 +90,16 @@ internal class LinkWriter {
|
||||
}
|
||||
|
||||
/**
|
||||
* STATION_CONFIGURE body (6 octets). (Re)creates the GeoNetworking stack and security entity on the
|
||||
* micrOBU. The GN address derives from the authorization ticket (signed) or is drawn at random per
|
||||
* configuration (unsigned), so the app's pseudonym MAC is no longer sent; radio mode, traffic class
|
||||
* and lifetime are fixed by the station (transmit and receive, DP2, 1 s).
|
||||
* STATION_CONFIGURE body. (Re)creates the GeoNetworking stack and security entity on the micrOBU.
|
||||
*
|
||||
* Without [mid] it is the 6-octet form of docs/station-link.pdf: the GN address derives from the
|
||||
* authorization ticket (signed) or is drawn at random per configuration (unsigned). With [mid], the
|
||||
* pseudonym MAC, it is the 16-octet form (address_configuration 0, AUTO), which the station still
|
||||
* accepts: [mid] becomes both the GN_ADDR MID and the 802.11 source address, signed or not. A ride
|
||||
* sends the rotating pseudonym's MAC, so the link-layer address rotates with the station ID; the bench
|
||||
* CAM pinger sends its fixed MAC. A different [mid] is a different configuration, so the next message
|
||||
* reconfigures the station. Radio mode, traffic class and lifetime are the station's (transmit and
|
||||
* receive, DP2, 1 s).
|
||||
*/
|
||||
data class StationConfigure(
|
||||
val stationType: Int,
|
||||
@@ -101,10 +107,18 @@ data class StationConfigure(
|
||||
val beaconing: Int = 0,
|
||||
val channelNumber: Int = 180,
|
||||
val transmitPowerDbm: Int = 20,
|
||||
val mid: ByteArray? = null,
|
||||
) {
|
||||
fun encode(): ByteArray = LinkWriter()
|
||||
.u8(stationType).u16(channelNumber).u8(transmitPowerDbm).u8(security).u8(beaconing)
|
||||
.toByteArray()
|
||||
init { require(mid == null || mid.size == 6) }
|
||||
|
||||
fun encode(): ByteArray = if (mid == null) {
|
||||
LinkWriter().u8(stationType).u16(channelNumber).u8(transmitPowerDbm).u8(security).u8(beaconing)
|
||||
.toByteArray()
|
||||
} else {
|
||||
LinkWriter().u8(stationType).u8(security).u8(0).bytes(mid).u8(beaconing)
|
||||
.u16(channelNumber).u8(transmitPowerDbm).u8(2).u8(2).u8(0x05)
|
||||
.toByteArray()
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean = other is StationConfigure && encode().contentEquals(other.encode())
|
||||
override fun hashCode(): Int = encode().contentHashCode()
|
||||
|
||||
@@ -78,9 +78,9 @@
|
||||
<string name="conn_bluetooth">Bluetooth</string>
|
||||
<string name="conn_bluetooth_phase3">Bluetooth</string>
|
||||
<string name="conn_bluetooth_phase3_desc">Bluetooth-Verbindung ist für Phase 03 geplant und noch nicht implementiert.</string>
|
||||
<string name="conn_esp32_title">ESP32-C5 (USB Seriell)</string>
|
||||
<string name="conn_esp32_title">ESP32-C5</string>
|
||||
<string name="conn_esp32_phase3_desc">Die USB-Seriell-Verbindung zum ESP32-C5 ist für Phase 03 vorgesehen, aber noch nicht funktionsfähig - dafür muss zuerst das ESP32-Firmware-Protokoll nach Kotlin übersetzt werden.</string>
|
||||
<string name="conn_esp32_state_disconnected">Nicht verbunden - ESP32-C5 an den nativen USB-C-Port anschließen und Verbinden antippen.</string>
|
||||
<string name="conn_esp32_state_disconnected">Nicht verbunden - Verbinden antippen (USB-C-Verbindung: ESP32-C5 zuerst an den nativen USB-C-Port anschließen).</string>
|
||||
<string name="conn_esp32_state_device_attached">Gerät erkannt, wird geöffnet…</string>
|
||||
<string name="conn_esp32_state_permission_requested">Warte auf USB-Berechtigung…</string>
|
||||
<string name="conn_esp32_state_connected">Verbunden</string>
|
||||
@@ -323,7 +323,7 @@
|
||||
<string name="v2x_spat_countdown">%1$.0f s</string>
|
||||
<string name="settings_esp32_link">ESP32-C5-Verbindung</string>
|
||||
<string name="settings_esp32_link_ble">Bluetooth</string>
|
||||
<string name="settings_esp32_link_ble_note">Beim ersten Verbinden wird das Koppeln mit micrOBU-XXXX angefragt: Passkey 123456 eingeben. Die Platine wirbt nur, solange ihr USB-C-Port nicht benutzt wird. BLE teilt sich das Funk-Frontend mit ITS-G5; der Einfluss auf den 5,9-GHz-Empfang ist noch nicht gemessen.</string>
|
||||
<string name="settings_esp32_link_ble_note">Beim ersten Verbinden wird das Koppeln mit micrOBU-XXXX angefragt: Passkey 123456 eingeben. Sind mehrere micrOBUs in der Nähe, wählt die App den stärksten. BLE teilt sich das Funk-Frontend mit ITS-G5; die Platine hält jedes ITS-G5-Paket aus den BLE-Verbindungsfenstern heraus.</string>
|
||||
<string name="settings_esp32_message">Senden während der Aufzeichnung</string>
|
||||
<string name="settings_esp32_message_cam">CAM</string>
|
||||
<string name="settings_esp32_message_vam">VAM</string>
|
||||
|
||||
@@ -79,9 +79,9 @@
|
||||
<string name="conn_bluetooth">Bluetooth</string>
|
||||
<string name="conn_bluetooth_phase3">Bluetooth</string>
|
||||
<string name="conn_bluetooth_phase3_desc">Bluetooth connection is planned for Phase 03 and is not yet implemented.</string>
|
||||
<string name="conn_esp32_title">ESP32-C5 (USB Serial)</string>
|
||||
<string name="conn_esp32_title">ESP32-C5</string>
|
||||
<string name="conn_esp32_phase3_desc">USB-serial connection to the ESP32-C5 is scaffolded for Phase 03 but not yet functional - it needs the ESP32 firmware protocol translated to Kotlin first.</string>
|
||||
<string name="conn_esp32_state_disconnected">Not connected - plug the ESP32-C5 into the native USB-C port and tap Connect.</string>
|
||||
<string name="conn_esp32_state_disconnected">Not connected - tap Connect (USB-C link: plug the ESP32-C5 into the native USB-C port first).</string>
|
||||
<string name="conn_esp32_state_device_attached">Device detected, opening…</string>
|
||||
<string name="conn_esp32_state_permission_requested">Waiting for USB permission…</string>
|
||||
<string name="conn_esp32_state_connected">Connected</string>
|
||||
@@ -330,7 +330,7 @@
|
||||
<string name="trip_review_title">Trip Review</string>
|
||||
<string name="settings_esp32_link">ESP32-C5 link</string>
|
||||
<string name="settings_esp32_link_ble">Bluetooth</string>
|
||||
<string name="settings_esp32_link_ble_note">The first connection asks to pair with micrOBU-XXXX: enter passkey 123456. The board only advertises while nothing uses its USB-C port. BLE shares the radio front end with ITS-G5; its effect on 5.9 GHz reception has not been measured yet.</string>
|
||||
<string name="settings_esp32_link_ble_note">The first connection asks to pair with micrOBU-XXXX: enter passkey 123456. If several micrOBUs are nearby the app picks the strongest one. BLE shares the radio front end with ITS-G5; the board holds each ITS-G5 frame out of the BLE connection-event windows.</string>
|
||||
<string name="settings_esp32_message">Transmit while recording</string>
|
||||
<string name="settings_esp32_message_cam">CAM</string>
|
||||
<string name="settings_esp32_message_vam">VAM</string>
|
||||
|
||||
@@ -42,6 +42,20 @@ class StationLinkTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `STATION_CONFIGURE with a MAC is the 16-octet form that names the address`() {
|
||||
// type 2, security on, address_configuration 0 (AUTO), the MAC, no beaconing, channel 180, 20 dBm, TX+RX, DP2, 1 s
|
||||
val body = StationConfigure(stationType = 2, mid = "021122334455".hexToBytes()).encode()
|
||||
assertEquals(
|
||||
"0100070002010002112233445500b40014020205",
|
||||
LinkMessage(LinkOpcode.STATION_CONFIGURE, 7, body).encode().hex(),
|
||||
)
|
||||
// another MAC is another configuration (the station is reconfigured), the same MAC is the same one
|
||||
assertEquals(StationConfigure(2, mid = "021122334455".hexToBytes()), StationConfigure(2, mid = "021122334455".hexToBytes()))
|
||||
assertFalse(StationConfigure(2, mid = "021122334455".hexToBytes()) == StationConfigure(2, mid = "021122334466".hexToBytes()))
|
||||
assertFalse(StationConfigure(2, mid = "021122334455".hexToBytes()) == StationConfigure(2))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `POTI_UPDATE matches the Python encoder`() {
|
||||
val body = PotiUpdate(
|
||||
|
||||
@@ -60,6 +60,7 @@ Main changes against Niklas Dathe's firmware:
|
||||
(`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.
|
||||
@@ -78,7 +79,7 @@ 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 (6 octets); starts the radio |
|
||||
| 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 |
|
||||
@@ -89,8 +90,10 @@ firmware is what counts; the current spec table lists the same UUIDs).
|
||||
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 app does not rotate the board's MAC any more (STATION_CONFIGURE has none): a signed
|
||||
station takes its address from the ticket, an unsigned one draws a random MAC per configuration.
|
||||
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.
|
||||
|
||||
## Redundancy and recovery
|
||||
|
||||
|
||||
@@ -60,6 +60,18 @@ STATION_CONFIGURE; the app provisions the demo credentials on the first Connect.
|
||||
paired before must forget `micrOBU-XXXX` in Android's Bluetooth settings and pair again (passkey
|
||||
123456, `CONFIG_MICROBU_BLE_PASSKEY`).
|
||||
|
||||
### Pairing, bonds and several boards
|
||||
|
||||
- The name is `micrOBU-` plus the last two octets of the board's BLE address (`micrOBU-66AA` is the production
|
||||
XIAO on COM10, `10:BD:A3:CF:66:AA`). The board keeps **one** bond in NVS and refuses to replace it.
|
||||
- **With no bond the app connects to the first micrOBU it hears.** On a bench with several (2026-11-11: 4AFA, 3FAA,
|
||||
A25E and 66AA all at -49 to -55 dBm) that is not necessarily yours, and it can bond with the wrong board. Pair the
|
||||
right one first in Android's Bluetooth settings (Pair new device, passkey 123456); the app then prefers a
|
||||
bonded micrOBU. Forget a wrong bond there too.
|
||||
- If the phone has lost its bond but the board still holds one, the phone connects and drops again after about 3 s.
|
||||
Erase the board's NVS (`python -m esptool --chip esp32c5 -p COMx erase-region 0x9000 0x15000`) and pair again.
|
||||
- The bond survives a reflash that keeps the NVS and a reset of the board (checked 2026-11-11).
|
||||
|
||||
## Look at the board from the PC
|
||||
|
||||
```powershell
|
||||
@@ -68,7 +80,16 @@ py -3.11 tools/station_status_watch.py COM6 30 --configure --rx
|
||||
|
||||
prints the log, the STATUS snapshot once a second (uptime, signing and radio counters, heap,
|
||||
battery) and the first V2X_RX messages heard on air. DTR/RTS stay low in the script because toggling
|
||||
them resets the board.
|
||||
them resets the board. **Opening the port resets the board** (USB Serial/JTAG), so a phone on BLE is dropped.
|
||||
|
||||
```powershell
|
||||
py -3.11 tools/station_tx_test.py COMx --seconds 60 --mac 02:aa:bb:cc:dd:01 # signed CAMs from a named MAC
|
||||
py -3.11 tools/station_tx_test.py COMx --seconds 60 --unsigned # unsigned, a random MAC
|
||||
```
|
||||
|
||||
plays the phone over USB (configure, position, a CAM request per second) and reads the station's own raw capture, so it
|
||||
prints the 802.11 source address and whether each frame is signed, plus how many frames the radio submitted and
|
||||
completed. Pair it with a second board listening on the air to count what arrives.
|
||||
|
||||
## Production OBU checklist (board with the cell connected)
|
||||
|
||||
@@ -111,7 +132,10 @@ in `test/host`) adds the protection, every 5 s: the smoothed voltage below 3.30
|
||||
60 s after boot and with **no frame from a phone on USB in the last 5 s**, puts the board into deep
|
||||
sleep; it wakes every 300 s, measures, and runs again from 3.60 V. A phone on USB powers the board,
|
||||
so no shutdown happens then. Thresholds: `menuconfig -> micrOBU firmware`. The app shows
|
||||
low/critical from the same voltage and its own thresholds.
|
||||
low/critical from the same voltage and its own thresholds. The first XIAO build read 0 mV because the divider had
|
||||
no time to settle at `CONFIG_FREERTOS_HZ=100` (fixed 2026-11-11, see NOTES.md); it now reads 4.14-4.16 V on a charging
|
||||
cell. There is no calibration trim and no multimeter reference on the glued-in cell: the plateau at full charge
|
||||
should sit near the charger's 4.20 V.
|
||||
|
||||
## If the build fails
|
||||
|
||||
|
||||
+47
-5
@@ -18,7 +18,7 @@ Layout:
|
||||
| `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 |
|
||||
| `test/host/` | PC tests (`make` in that folder): the MicrOBU C code (`gn_unwrap.c`, `geonet.c`), the battery policy and, with `make firmware`, 40 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
|
||||
@@ -40,7 +40,7 @@ custom PCB; pick it in `menuconfig -> micrOBU firmware -> Board`.
|
||||
- **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. The app's "Sign outgoing
|
||||
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
|
||||
@@ -52,11 +52,22 @@ custom PCB; pick it in `menuconfig -> micrOBU firmware -> Board`.
|
||||
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).
|
||||
- **ATT MTU 517** (`CONFIG_BT_NIMBLE_ATT_PREFERRED_MTU`, Niklas Dathe's 512): the app asks for 517 and a 494-octet
|
||||
V2X_RX is a 512-octet link message, which needs a value of 512, i.e. an MTU of 515. At 512 such a message was
|
||||
split into fragments the app does not reassemble.
|
||||
- **Link-layer address.** A signed station without a named MAC uses the address derived from its ticket; with the
|
||||
16-octet STATION_CONFIGURE the phone names it (see "Unsigned transmission"). The CAM and VAM station ID still
|
||||
rotates in the app; the app now rotates the MAC with it on a ride and keeps one fixed for the bench pinger.
|
||||
|
||||
### Link spec revision 2
|
||||
|
||||
@@ -64,14 +75,45 @@ custom PCB; pick it in `menuconfig -> micrOBU firmware -> Board`.
|
||||
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.
|
||||
revision 1 is unchanged, so a revision 1 host still works. Build the PDF with `pdflatex station-link.tex`
|
||||
(twice) and commit it with the `.tex`; the LaTeX build files next to it are ignored. The section "Naming the MAC"
|
||||
documents the 16-octet STATION_CONFIGURE, which revision 1 retires but the station still decodes.
|
||||
|
||||
### Dropped from the earlier MicrOBU version, and why
|
||||
|
||||
The first port (2026-09-23) carried a few things that Niklas Dathe's current firmware makes unnecessary:
|
||||
|
||||
- **Bench listener** (`CONFIG_MICROBU_BENCH_LISTEN`): his `RAW_CAPTURE` / `RAW_FRAME` does the same over the link.
|
||||
- **BLE pauses advertising while USB is in use**: his TX guard now holds each frame out of the BLE connection-event windows.
|
||||
- **Battery flags at STATUS octets 103-105**: his layout puts channel-load fields there; the app derives low (3.50 V)
|
||||
and critical (3.30 V) from `battery_mv` at octet 129.
|
||||
- **The ETSI test channel** and the UART0 console: the log travels as LOG frames on the USB link.
|
||||
- **`CONFIG_MICROBU_BATTERY_SCALE_PERMILLE`**: his battery code has no trim. The XIAO's reading was never compared
|
||||
with a multimeter on the glued-in cell; the app shows 4.14-4.16 V on a charging cell, close to the charger's 4.20 V.
|
||||
|
||||
### What Niklas Dathe's latest firmware added over his earlier one
|
||||
|
||||
The station grew from about 580 to 1,360 lines. From his commit messages (not all of it read line by line): ITS clock
|
||||
slewing, a TX guard against BLE collisions, stale-request refusal (`generated_at_ms`), a pending queue that replaces an
|
||||
unsent VAM with a newer one, Adaptive DCC with channel-busy-ratio measurement, declared radio operating points from
|
||||
EN 302 571 measurements, robust CCA counters and TX retry, heap diagnostics, asn1c tables kept in flash, BLE with no
|
||||
eFuse-based gates, an on-device TS 102 941 client (enrolment and authorisation relayed by the phone, trust bootstrap and
|
||||
update), the `RAW_CAPTURE` debug path, fragmentation of link messages, the XIAO and `mainboard-v5` boards, and the
|
||||
battery reading.
|
||||
|
||||
### Measured on the bench, 2026-11-11
|
||||
|
||||
Production XIAO on COM10, Pixel 9 Pro on BLE, COM3 board as an on-air listener (details and open points in `TODO.md`):
|
||||
the simulated car's CAMs reach the app; signed CAMs from the phone (tickets 1) and unsigned ones are heard by the
|
||||
listener; over USB with BLE off 95.7 % of 300 signed CAMs were heard and over BLE with the screen on 95.7 % of 188, so
|
||||
the BLE link adds no measurable loss; the BLE bond survives a board reset. `tools/station_tx_test.py` plays the phone
|
||||
over USB and reads the station's own raw capture, which shows the 802.11 source address of what leaves the radio.
|
||||
|
||||
### 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
|
||||
security, beaconing; no MAC unless the 16-octet form names one, else 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.
|
||||
|
||||
@@ -82,6 +82,7 @@ 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,
|
||||
@@ -107,14 +108,14 @@ BLE_pairing:
|
||||
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`).
|
||||
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 # 39 unit tests: link codec, STATUS, reassembly, V2X_RX, policies. PASS or FAIL per test
|
||||
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
|
||||
```
|
||||
|
||||
|
||||
@@ -387,7 +387,7 @@ Send all five fields in the six-byte body to set or replace the station configur
|
||||
\toprule\textbf{Parameter} & \textbf{Setting} & \textbf{Description} \\\midrule\endhead
|
||||
\bottomrule\endfoot
|
||||
{\ttfamily radio} & {\ttfamily transmit-\allowbreak{}and-\allowbreak{}receive} & Enables both transmission and reception. \\
|
||||
{\ttfamily address\_\allowbreak{}configuration} & {\ttfamily anonymous} & Derives the GN address from the ticket identity. MicrOBU extension: unsecured frames carry a random locally administered unicast MAC, drawn anew at every STATION\_CONFIGURE. \\
|
||||
{\ttfamily address\_\allowbreak{}configuration} & {\ttfamily anonymous} & Derives the GN address from the ticket identity. MicrOBU extension: with the 16-octet form (Section~\ref{sec:microbu-mac}) the host names the MAC; without, unsecured frames carry a random locally administered unicast MAC, drawn anew at every STATION\_CONFIGURE. \\
|
||||
{\ttfamily traffic\_\allowbreak{}class} & {\ttfamily 2} & Selects default traffic priority DP2. \\
|
||||
{\ttfamily lifetime} & {\ttfamily 0x05} & Encodes the default one-second lifetime. \\
|
||||
\end{longtable}}
|
||||
@@ -1187,6 +1187,24 @@ A BTP\_DATA\_REQUEST with \texttt{gn\_security\_profile} 0x01, or 0x00 while the
|
||||
{\ttfamily accounting} & {\ttfamily requests\_accepted} & Counted as an accepted or refused stack request; not counted as a signed message. \\
|
||||
{\ttfamily tx\_guard} & {\ttfamily BLE collision guard} & Handed to the radio through the same BLE guard as signed frames. \\
|
||||
\end{longtable}}
|
||||
\Needspace{8\baselineskip}\subsection{Naming the MAC: the 16-octet STATION\_CONFIGURE}\label{sec:microbu-mac}
|
||||
Revision 1 retires the long STATION\_CONFIGURE and defines only the 6-octet form. The station still decodes the long form, and the MicrOBU host uses it to choose the link-layer address: a rider's phone rotates the MAC with its pseudonym, and the bench CAM pinger keeps one fixed MAC so that its frames stay recognisable in a capture. A different MID is a different configuration, so the station is configured again (the radio keeps running).
|
||||
{\small\begin{longtable}{F}
|
||||
\hline\textbf{Offset} & \textbf{Field} & \textbf{Type} & \textbf{Unit / values} & \textbf{Description} \\hline\endfirsthead
|
||||
\hline\textbf{Offset} & \textbf{Field} & \textbf{Type} & \textbf{Unit / values} & \textbf{Description} \\hline\endhead
|
||||
\hline\endfoot
|
||||
{\ttfamily 0} & {\ttfamily station\_\allowbreak{}type} & {\ttfamily u8} & \textemdash & As in the 6-octet form. \
|
||||
{\ttfamily 1} & {\ttfamily security} & {\ttfamily u8} & 0 or 1 & As in the 6-octet form. \
|
||||
{\ttfamily 2} & {\ttfamily address\_\allowbreak{}configuration} & {\ttfamily u8} & 0=AUTO, 1=anonymous & 0 uses the MID below as the GN address MID and the 802.11 source address. \
|
||||
{\ttfamily 3} & {\ttfamily mid} & {\ttfamily u8[6]} & \textemdash & The MAC (locally administered, unicast). Ignored when address\_configuration is 1. \
|
||||
{\ttfamily 9} & {\ttfamily beaconing} & {\ttfamily u8} & 0 or 1 & As in the 6-octet form. \
|
||||
{\ttfamily 10} & {\ttfamily channel\_\allowbreak{}number} & {\ttfamily u16} & \textemdash & As in the 6-octet form. \
|
||||
{\ttfamily 12} & {\ttfamily transmit\_\allowbreak{}power\_\allowbreak{}dbm} & {\ttfamily u8} & dBm & As in the 6-octet form. \
|
||||
{\ttfamily 13} & {\ttfamily radio} & {\ttfamily u8} & 0, 1 or 2 & 2 transmits and receives. \
|
||||
{\ttfamily 14} & {\ttfamily default\_\allowbreak{}traffic\_\allowbreak{}class} & {\ttfamily u8} & raw GN octet & 2 (DP2). \
|
||||
{\ttfamily 15} & {\ttfamily default\_\allowbreak{}lifetime} & {\ttfamily u8} & raw GN octet & 0x05 (1 s). \
|
||||
\end{longtable}}
|
||||
Checked on the bench (2026-11-11) with the station's own raw capture: a signed CAM sent with MID 02:aa:bb:cc:dd:01 left the radio from 802.11 source 02:aa:bb:cc:dd:01; the 6-octet form gave the ticket-derived address of the authorization ticket (4a:38:7a:4c:12:eb) when signed and a fresh random MAC per configuration when unsigned.
|
||||
\Needspace{8\baselineskip}\subsection{Battery protection}\label{sec:microbu-battery}
|
||||
The prototype cell has no protection board. The station samples it every 5 s; the value in the status snapshot is \texttt{battery\_mv}. The shutdown rule is local to the station and has no link message.
|
||||
{\small\begin{longtable}{@{}P{45mm}P{55mm}P{72.8mm}@{}}
|
||||
@@ -1207,6 +1225,6 @@ MicrOBU extension. While no USB host is connected to the native port (the phone
|
||||
\toprule\textbf{Revision} & \textbf{Date} & \textbf{Changes} \\\midrule\endhead
|
||||
\bottomrule\endfoot
|
||||
1 & 2026-11 & Niklas Dathe: the microbu-firmware interface reference, commit e4e4bd8. \\
|
||||
2 & 2026-11-10 & MicrOBU additions: opcode 0x90 V2X\_RX (all heard ITS messages, unverified); unsecured transmission for security profile 0x01 and for profile 0x00 with \texttt{security} 0, from a random MAC per configuration; the radio is polled from STATION\_CONFIGURE on; battery protection by deep sleep; no USB writes without a host. Wire format of revision 1 unchanged; the original is kept as microbu-firmware/docs/station-link.pdf. \\
|
||||
2 & 2026-11-10 & MicrOBU additions: opcode 0x90 V2X\_RX (all heard ITS messages, unverified); unsecured transmission for security profile 0x01 and for profile 0x00 with \texttt{security} 0, from a random MAC per configuration, or the MAC named by the host in the 16-octet STATION\_CONFIGURE; the radio is polled from STATION\_CONFIGURE on; battery protection by deep sleep; no USB writes without a host. Wire format of revision 1 unchanged; the original is kept as microbu-firmware/docs/station-link.pdf. \\
|
||||
\end{longtable}}
|
||||
\end{document}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <freertos/task.h>
|
||||
#include <esp_log.h>
|
||||
#include <esp_sleep.h>
|
||||
#include <esp_rom_sys.h>
|
||||
|
||||
namespace microbu {
|
||||
BatteryMonitor::BatteryMonitor() {
|
||||
@@ -33,7 +34,11 @@ BatteryMonitor::BatteryMonitor() {
|
||||
return;
|
||||
}
|
||||
#if CONFIG_MICROBU_XIAO_C5_BATTERY
|
||||
gpio_set_direction(GPIO_NUM_26, GPIO_MODE_OUTPUT);
|
||||
// MicrOBU: gpio_config, not gpio_set_direction alone, so the pad is certainly a plain GPIO output.
|
||||
gpio_config_t enable = {};
|
||||
enable.pin_bit_mask = 1ULL << 26;
|
||||
enable.mode = GPIO_MODE_OUTPUT;
|
||||
gpio_config(&enable);
|
||||
gpio_set_level(GPIO_NUM_26, 0);
|
||||
#endif
|
||||
#endif
|
||||
@@ -54,7 +59,10 @@ std::uint16_t BatteryMonitor::sample_millivolts() {
|
||||
#if CONFIG_MICROBU_XIAO_C5_BATTERY
|
||||
gpio_set_level(GPIO_NUM_26, 1);
|
||||
#endif
|
||||
vTaskDelay(pdMS_TO_TICKS(5)); // settle the switched 100k/100k divider
|
||||
// MicrOBU: a busy wait. At CONFIG_FREERTOS_HZ=100 pdMS_TO_TICKS(5) is 0 ticks, so vTaskDelay returned at
|
||||
// once, the switched divider had not settled, and every reading came out below the 2.5 V validity floor
|
||||
// (battery_mv 0 on the XIAO, 2026-11-11).
|
||||
esp_rom_delay_us(5000); // settle the switched 100k/100k divider
|
||||
int sum = 0;
|
||||
bool valid = true;
|
||||
for (unsigned i = 0; i < 16; ++i) {
|
||||
|
||||
@@ -482,10 +482,16 @@ link::Code Station::configure(const link::StationConfigure& c, link::Bytes& deta
|
||||
}
|
||||
}
|
||||
config_ = c;
|
||||
// MicrOBU: a fresh locally administered unicast MAC for unsecured frames on every configuration,
|
||||
// so a station that does not sign does not keep one link-layer identity either.
|
||||
esp_fill_random(unsecured_mid_, sizeof unsecured_mid_);
|
||||
unsecured_mid_[0] = static_cast<std::uint8_t>((unsecured_mid_[0] & 0xFC) | 0x02);
|
||||
// MicrOBU: the MAC of unsecured frames. A phone that sends the 16-octet STATION_CONFIGURE with
|
||||
// address_configuration 0 (AUTO) names it itself: it rotates it with its pseudonym on a ride and
|
||||
// keeps it fixed for the bench pinger. Without one (the 6-octet form) a fresh locally administered
|
||||
// unicast MAC is drawn at every configuration.
|
||||
if (c.address_configuration == 0) {
|
||||
std::copy(std::begin(c.mid), std::end(c.mid), unsecured_mid_);
|
||||
} else {
|
||||
esp_fill_random(unsecured_mid_, sizeof unsecured_mid_);
|
||||
unsecured_mid_[0] = static_cast<std::uint8_t>((unsecured_mid_[0] & 0xFC) | 0x02);
|
||||
}
|
||||
link_subscriptions_.clear(); // a configuration starts a phone session: earlier subscriptions are void
|
||||
counters_ = link::Status {}; // and the session's counters start at zero
|
||||
const auto result = build();
|
||||
|
||||
@@ -1427,7 +1427,7 @@ CONFIG_BT_NIMBLE_USE_ESP_TIMER=y
|
||||
#
|
||||
# GATT / ATT
|
||||
#
|
||||
CONFIG_BT_NIMBLE_ATT_PREFERRED_MTU=512
|
||||
CONFIG_BT_NIMBLE_ATT_PREFERRED_MTU=517
|
||||
# default:
|
||||
CONFIG_BT_NIMBLE_ATT_MAX_PREP_ENTRIES=64
|
||||
# default:
|
||||
@@ -3896,7 +3896,7 @@ CONFIG_NIMBLE_RPA_TIMEOUT=900
|
||||
CONFIG_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_NIMBLE_MAX_CCCDS=8
|
||||
# CONFIG_NIMBLE_CRYPTO_STACK_MBEDTLS is not set
|
||||
CONFIG_NIMBLE_ATT_PREFERRED_MTU=512
|
||||
CONFIG_NIMBLE_ATT_PREFERRED_MTU=517
|
||||
CONFIG_NIMBLE_L2CAP_COC_MAX_NUM=0
|
||||
CONFIG_BT_NIMBLE_MSYS1_BLOCK_COUNT=12
|
||||
CONFIG_BT_NIMBLE_ACL_BUF_COUNT=24
|
||||
|
||||
@@ -35,7 +35,8 @@ CONFIG_LOG_COLORS=n
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
CONFIG_BT_NIMBLE_ATT_PREFERRED_MTU=512
|
||||
# MicrOBU: 517, not 512: the app asks for 517 and wants an ATT value of 512 + 3 so that a 512-octet link message (a 494-octet V2X_RX) is not split.
|
||||
CONFIG_BT_NIMBLE_ATT_PREFERRED_MTU=517
|
||||
CONFIG_BT_NIMBLE_SM_SC=y
|
||||
CONFIG_BT_NIMBLE_SM_LEGACY=n
|
||||
CONFIG_BT_NIMBLE_SM_SC_ONLY=1
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
results under "Running". Toolchain: MSYS2 UCRT64 gcc, Option B below (chosen and
|
||||
installed 2026-09-11).
|
||||
|
||||
**Firmware unit tests (`make firmware`, `test_firmware.cpp`, 39 tests):** the station-link codec byte-exact against
|
||||
**Firmware unit tests (`make firmware`, `test_firmware.cpp`, 40 tests):** the station-link codec byte-exact against
|
||||
the app's `StationLinkTest` hex, the 131-octet STATUS offsets, request reassembly, the V2X_RX extension
|
||||
(`main/v2x_rx.hpp`; the 494-octet limit, the 14-octet prefix, TX code -> air frame -> RX path), radio operating
|
||||
points, the BLE TX guard, the ITS clock, CCA counters, BLE security and the battery policy. It prints PASS or FAIL
|
||||
|
||||
@@ -121,6 +121,22 @@ TEST(station_configure_is_the_six_octet_form_the_app_sends) {
|
||||
CHECK(!link::decode(hex("02b4001401"), bad)); // five octets
|
||||
}
|
||||
|
||||
TEST(station_configure_with_a_named_mac_is_the_sixteen_octet_form) {
|
||||
// the app's form for a ride (rotating pseudonym MAC) and for the bench pinger (fixed MAC)
|
||||
link::StationConfigure c;
|
||||
CHECK(link::decode(hex("02010002112233445500b40014020205"), c));
|
||||
CHECK_EQ(c.station_type, 2); CHECK_EQ(c.security, 1);
|
||||
CHECK_EQ(c.address_configuration, 0); // AUTO: the MID below names the address
|
||||
CHECK_STR(to_hex(Bytes(c.mid, c.mid + 6)), std::string("021122334455"));
|
||||
CHECK_EQ(c.channel_number, 180); CHECK_EQ(c.transmit_power_dbm, 20);
|
||||
CHECK_EQ(c.radio, 2); CHECK_EQ(c.default_traffic_class, 2); CHECK_EQ(c.default_lifetime, 0x05);
|
||||
// and the station's own encoder produces the same bytes for the same values
|
||||
CHECK_STR(to_hex(link::encode(c)), std::string("02010002112233445500b40014020205"));
|
||||
link::StationConfigure bad;
|
||||
CHECK(!link::decode(hex("02010002112233445500b4001402"), bad)); // cut short
|
||||
CHECK(!link::decode(hex("02010202112233445500b40014020205"), bad)); // address_configuration 2 does not exist
|
||||
}
|
||||
|
||||
TEST(poti_update_decodes_the_apps_31_octets) {
|
||||
link::PotiUpdate p;
|
||||
CHECK(link::decode(hex("fbb2b7ffa60000002bcbeb1f914bf905e601e60100000e000000001f02d204"), p));
|
||||
|
||||
@@ -0,0 +1,209 @@
|
||||
"""Play the phone over USB: configure the station, send CAMs at a fixed rate, and look at what goes on air.
|
||||
|
||||
py -3.11 tools/station_tx_test.py COM10 [--seconds 60] [--rate 1] [--unsigned] [--mac 02:11:22:33:44:55]
|
||||
|
||||
What it does, all over the native USB Serial/JTAG link (docs/station-link.pdf):
|
||||
- STATION_CONFIGURE: the 6-octet form, or with --mac the 16-octet form (address_configuration 0, the
|
||||
phone names the MAC, as the app does so that a pseudonym rotates it);
|
||||
- POTI_UPDATE once a second and a BTP_DATA_REQUEST (port 2001, ITS-AID 36, SSP 010000) at --rate;
|
||||
- RAW_CAPTURE with the own-transmission bit, so the station copies every frame it puts on the radio back
|
||||
over the link (RAW_FRAME, an ITS5 record): that shows the 802.11 source address and whether the
|
||||
packet is signed, without a second board;
|
||||
- STATUS once a second, and the board's "TX observation" log lines (submitted / completed / failed).
|
||||
|
||||
At the end it prints how many requests were accepted, how many frames the radio submitted, how many
|
||||
the driver reported as completed, and the MAC and security of the captured frames. Pair it with a second
|
||||
board listening on the air (the bench listener on COM3) to count what actually arrives.
|
||||
|
||||
DTR and RTS stay low, but opening the port resets the board (USB Serial/JTAG), so a phone on BLE is dropped.
|
||||
Needs pyserial (the ESP-IDF python env has it). The demo credentials must already be on the board (the app
|
||||
provisions them on its first connect) for signed requests.
|
||||
"""
|
||||
import argparse
|
||||
import collections
|
||||
import struct
|
||||
import sys
|
||||
import time
|
||||
|
||||
import serial
|
||||
|
||||
LINK, LOG = 0x10, 0x7F
|
||||
STATION_CONFIGURE, POTI_UPDATE, BTP_DATA_REQUEST, STATUS_REQUEST, RAW_CAPTURE = 0x01, 0x02, 0x03, 0x0C, 0x0D
|
||||
CONFIRM, RAW_FRAME = 0x80, 0x85
|
||||
ITS_EPOCH_UNIX_MS = 1072915200000 # 2004-01-01T00:00:00Z
|
||||
LEAP_SECONDS_MS = 5000 # TimestampIts counts TAI: 5 leap seconds since 2004
|
||||
|
||||
|
||||
def crc16(data, crc=0xFFFF):
|
||||
for b in data:
|
||||
crc ^= b << 8
|
||||
for _ in range(8):
|
||||
crc = ((crc << 1) ^ 0x1021) & 0xFFFF if crc & 0x8000 else (crc << 1) & 0xFFFF
|
||||
return crc
|
||||
|
||||
|
||||
def frame(ftype, payload):
|
||||
head = bytes([ftype]) + struct.pack("<H", len(payload))
|
||||
return b"\xAA\x55" + head + payload + struct.pack("<H", crc16(head + payload))
|
||||
|
||||
|
||||
def link(opcode, seq, body=b""):
|
||||
return frame(LINK, bytes([opcode, 0]) + struct.pack("<H", seq) + body)
|
||||
|
||||
|
||||
def timestamp_its():
|
||||
return int(time.time() * 1000) - ITS_EPOCH_UNIX_MS + LEAP_SECONDS_MS
|
||||
|
||||
|
||||
def configure_body(mac, secured, power=20):
|
||||
if mac is None: # type cyclist, channel 180, power, security, beaconing off
|
||||
return struct.pack("<BHBBB", 2, 180, power, 1 if secured else 0, 0)
|
||||
# type, security, address_configuration 0 (AUTO, the MID below), mid, beaconing, channel, power, radio 2, DP2, 1 s
|
||||
return struct.pack("<BBB6sBHBBBB", 2, 1 if secured else 0, 0, mac, 0, 180, power, 2, 2, 5)
|
||||
|
||||
|
||||
def poti_body():
|
||||
# Hamburg St. Georg; speed 0, PAI set (flags: speed present + PAI)
|
||||
return struct.pack("<QiiHHHBiHH", timestamp_its(), 535546667, 100223889, 300, 300, 0, 0x02 | 0x08, 0, 0, 0)
|
||||
|
||||
|
||||
def btp_request_body(secured, payload):
|
||||
return (struct.pack("<BHHBBBBBBHHI", 1, 2001, 0, 1, 1, 2 if secured else 1, 0xFF, 0xFF, 0, 0, 0, 36)
|
||||
+ bytes([3]) + bytes.fromhex("010000") + bytes([0]) + struct.pack("<H", len(payload)) + payload)
|
||||
|
||||
|
||||
def parse_raw_frame(body):
|
||||
"""RAW_FRAME body -> (own_tx, rssi, 802.11 frame) or None. Layout: u32 counter, u8 flags, i8 rssi, 'ITS5' record."""
|
||||
if len(body) < 6 + 14 or body[6:10] != b"ITS5":
|
||||
return None
|
||||
flags, rssi = body[4], struct.unpack("<b", body[5:6])[0]
|
||||
length = struct.unpack("<H", body[18:20])[0]
|
||||
return bool(flags & 1), rssi, body[20:20 + length]
|
||||
|
||||
|
||||
def describe_frame(f):
|
||||
"""Source MAC (addr2) and security of a GeoNetworking frame in an 802.11 QoS data frame."""
|
||||
if len(f) < 26 + 8 + 4:
|
||||
return None
|
||||
mac = ":".join("%02x" % b for b in f[10:16])
|
||||
snap = 26 if (f[0] & 0x0F) == 0x08 else 24 # QoS data (subtype 8) or plain data
|
||||
basic_nh = f[snap + 8] & 0x0F # LLC/SNAP is 8 octets; GN basic header next-header: 1 common, 2 secured
|
||||
return mac, "signed" if basic_nh == 2 else "unsigned"
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("port")
|
||||
ap.add_argument("--seconds", type=float, default=60)
|
||||
ap.add_argument("--rate", type=float, default=1.0, help="CAMs per second")
|
||||
ap.add_argument("--unsigned", action="store_true")
|
||||
ap.add_argument("--mac", help="name the MAC (02:11:22:33:44:55); default: the station's own")
|
||||
args = ap.parse_args()
|
||||
mac = bytes(int(x, 16) for x in args.mac.split(":")) if args.mac else None
|
||||
secured = not args.unsigned
|
||||
payload = bytes([2, 2]) + bytes(range(41)) # a 43-octet stand-in for a CAM (protocol 2, messageID 2)
|
||||
|
||||
ser = serial.Serial(args.port, 115200, timeout=0.05)
|
||||
ser.dtr = False
|
||||
ser.rts = False
|
||||
time.sleep(3) # the port open reset the board: let it boot
|
||||
buf = bytearray()
|
||||
seq = 1
|
||||
results = collections.Counter()
|
||||
captured = collections.Counter()
|
||||
fragments = {}
|
||||
tx_obs = []
|
||||
last_status = None
|
||||
|
||||
def send(op, body=b""):
|
||||
nonlocal seq
|
||||
ser.write(link(op, seq, body))
|
||||
seq += 1
|
||||
return seq - 1
|
||||
|
||||
def pump():
|
||||
nonlocal last_status
|
||||
buf.extend(ser.read(8192))
|
||||
while True:
|
||||
i = buf.find(b"\xAA\x55")
|
||||
if i < 0 or len(buf) < i + 7:
|
||||
return
|
||||
ftype, n = buf[i + 2], struct.unpack("<H", buf[i + 3:i + 5])[0]
|
||||
if len(buf) < i + 5 + n + 2:
|
||||
return
|
||||
payload = bytes(buf[i + 5:i + 5 + n])
|
||||
del buf[:i + 5 + n + 2]
|
||||
if ftype == LOG:
|
||||
text = payload.decode("utf-8", "replace")
|
||||
if "TX observation" in text:
|
||||
tx_obs.append(text.strip())
|
||||
elif "BLE interval" in text or "stale" in text or "rror" in text:
|
||||
print("LOG", text.strip())
|
||||
elif ftype == LINK and len(payload) >= 4:
|
||||
op, fl, sq = payload[0], payload[1], struct.unpack("<H", payload[2:4])[0]
|
||||
body = payload[4:]
|
||||
if op == CONFIRM and len(body) >= 2:
|
||||
if body[1] == 131:
|
||||
last_status = body[2:]
|
||||
else:
|
||||
results[body[0]] += 1
|
||||
elif op == RAW_FRAME:
|
||||
if fl: # fragmented: total u16, offset u16, data
|
||||
total, off = struct.unpack("<HH", body[:4])
|
||||
got = fragments.setdefault(sq, bytearray())
|
||||
if off == len(got):
|
||||
got.extend(body[4:])
|
||||
if fl == 3 and len(got) == total:
|
||||
body = bytes(fragments.pop(sq))
|
||||
else:
|
||||
continue
|
||||
parsed = parse_raw_frame(body)
|
||||
if parsed and parsed[0]:
|
||||
d = describe_frame(parsed[2])
|
||||
if d:
|
||||
captured[d] += 1
|
||||
|
||||
send(STATION_CONFIGURE, configure_body(mac, secured))
|
||||
t0 = time.time()
|
||||
while time.time() - t0 < 1.0:
|
||||
pump()
|
||||
send(POTI_UPDATE, poti_body())
|
||||
send(RAW_CAPTURE, bytes([0x05])) # capture on + own transmissions
|
||||
t0 = time.time()
|
||||
next_cam = t0
|
||||
next_poti = t0 + 1
|
||||
next_status = t0 + 1
|
||||
sent = 0
|
||||
while time.time() - t0 < args.seconds:
|
||||
now = time.time()
|
||||
if now >= next_poti:
|
||||
send(POTI_UPDATE, poti_body())
|
||||
next_poti += 1
|
||||
if now >= next_cam:
|
||||
send(BTP_DATA_REQUEST, btp_request_body(secured, payload))
|
||||
sent += 1
|
||||
next_cam += 1.0 / args.rate
|
||||
if now >= next_status:
|
||||
send(STATUS_REQUEST)
|
||||
next_status += 1
|
||||
pump()
|
||||
end = time.time() + 2
|
||||
send(STATUS_REQUEST)
|
||||
while time.time() < end:
|
||||
pump()
|
||||
|
||||
print(f"\nrequests sent {sent}, CONFIRM results {dict(results)} (0 = accepted)")
|
||||
if last_status:
|
||||
u32 = lambda o: struct.unpack_from("<I", last_status, o)[0]
|
||||
print(f"station: signed={u32(23)} requests accepted={u32(51)} refused={u32(55)} radio submitted={u32(63)} "
|
||||
f"failed={u32(67)} sign failed={u32(39)} tickets={last_status[22]}")
|
||||
for (m, kind), n in captured.most_common():
|
||||
print(f"on air (own-TX capture): {n} x {kind}, 802.11 source {m}")
|
||||
if not captured:
|
||||
print("on air (own-TX capture): nothing captured")
|
||||
if tx_obs:
|
||||
print("last radio observation:", tx_obs[-1])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user