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.
This commit is contained in:
@@ -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.
|
**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.
|
**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.
|
||||||
|
|
||||||
|
|||||||
@@ -32,8 +32,20 @@ Still open:
|
|||||||
- [ ] The Connection settings text still says "the board only advertises while nothing uses its USB-C port"
|
- [ ] 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
|
(the firmware no longer pauses advertising) and the card header says "ESP32-C5 (USB Serial)" while
|
||||||
connected over Bluetooth.
|
connected over Bluetooth.
|
||||||
- [ ] Pseudonym rotation: the link has no MAC field any more, so the station ID rotates while the
|
- [x] Pseudonym rotation (2026-11-11): the app sends the pseudonym MAC in the 16-octet STATION_CONFIGURE
|
||||||
GN address stays the ticket's (see README).
|
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.
|
||||||
|
- [ ] TX loss: over USB with BLE off 287 of 300 signed CAMs were heard by the COM3 listener (95.7 %) while
|
||||||
|
the board reports 300 submitted and 300 completed, so about 4 % is lost on the air or in the listener
|
||||||
|
even without BLE. The same 5 minutes over BLE from the phone is still to run (needs the phone paired to
|
||||||
|
micrOBU-66AA first).
|
||||||
|
- [ ] 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)
|
### 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 {
|
private suspend fun sendStationLink(its: OutgoingIts): Boolean {
|
||||||
val pv = its.positionVector
|
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
|
// 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
|
// 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
|
// 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
|
* STATION_CONFIGURE body. (Re)creates the GeoNetworking stack and security entity on the micrOBU.
|
||||||
* 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
|
* Without [mid] it is the 6-octet form of docs/station-link.pdf: the GN address derives from the
|
||||||
* and lifetime are fixed by the station (transmit and receive, DP2, 1 s).
|
* 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(
|
data class StationConfigure(
|
||||||
val stationType: Int,
|
val stationType: Int,
|
||||||
@@ -101,10 +107,18 @@ data class StationConfigure(
|
|||||||
val beaconing: Int = 0,
|
val beaconing: Int = 0,
|
||||||
val channelNumber: Int = 180,
|
val channelNumber: Int = 180,
|
||||||
val transmitPowerDbm: Int = 20,
|
val transmitPowerDbm: Int = 20,
|
||||||
|
val mid: ByteArray? = null,
|
||||||
) {
|
) {
|
||||||
fun encode(): ByteArray = LinkWriter()
|
init { require(mid == null || mid.size == 6) }
|
||||||
.u8(stationType).u16(channelNumber).u8(transmitPowerDbm).u8(security).u8(beaconing)
|
|
||||||
.toByteArray()
|
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 equals(other: Any?): Boolean = other is StationConfigure && encode().contentEquals(other.encode())
|
||||||
override fun hashCode(): Int = encode().contentHashCode()
|
override fun hashCode(): Int = encode().contentHashCode()
|
||||||
|
|||||||
@@ -78,9 +78,9 @@
|
|||||||
<string name="conn_bluetooth">Bluetooth</string>
|
<string name="conn_bluetooth">Bluetooth</string>
|
||||||
<string name="conn_bluetooth_phase3">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_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_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_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_permission_requested">Warte auf USB-Berechtigung…</string>
|
||||||
<string name="conn_esp32_state_connected">Verbunden</string>
|
<string name="conn_esp32_state_connected">Verbunden</string>
|
||||||
@@ -323,7 +323,7 @@
|
|||||||
<string name="v2x_spat_countdown">%1$.0f s</string>
|
<string name="v2x_spat_countdown">%1$.0f s</string>
|
||||||
<string name="settings_esp32_link">ESP32-C5-Verbindung</string>
|
<string name="settings_esp32_link">ESP32-C5-Verbindung</string>
|
||||||
<string name="settings_esp32_link_ble">Bluetooth</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">Senden während der Aufzeichnung</string>
|
||||||
<string name="settings_esp32_message_cam">CAM</string>
|
<string name="settings_esp32_message_cam">CAM</string>
|
||||||
<string name="settings_esp32_message_vam">VAM</string>
|
<string name="settings_esp32_message_vam">VAM</string>
|
||||||
|
|||||||
@@ -79,9 +79,9 @@
|
|||||||
<string name="conn_bluetooth">Bluetooth</string>
|
<string name="conn_bluetooth">Bluetooth</string>
|
||||||
<string name="conn_bluetooth_phase3">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_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_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_device_attached">Device detected, opening…</string>
|
||||||
<string name="conn_esp32_state_permission_requested">Waiting for USB permission…</string>
|
<string name="conn_esp32_state_permission_requested">Waiting for USB permission…</string>
|
||||||
<string name="conn_esp32_state_connected">Connected</string>
|
<string name="conn_esp32_state_connected">Connected</string>
|
||||||
@@ -330,7 +330,7 @@
|
|||||||
<string name="trip_review_title">Trip Review</string>
|
<string name="trip_review_title">Trip Review</string>
|
||||||
<string name="settings_esp32_link">ESP32-C5 link</string>
|
<string name="settings_esp32_link">ESP32-C5 link</string>
|
||||||
<string name="settings_esp32_link_ble">Bluetooth</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">Transmit while recording</string>
|
||||||
<string name="settings_esp32_message_cam">CAM</string>
|
<string name="settings_esp32_message_cam">CAM</string>
|
||||||
<string name="settings_esp32_message_vam">VAM</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
|
@Test
|
||||||
fun `POTI_UPDATE matches the Python encoder`() {
|
fun `POTI_UPDATE matches the Python encoder`() {
|
||||||
val body = PotiUpdate(
|
val body = PotiUpdate(
|
||||||
|
|||||||
@@ -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
|
- **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
|
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
|
`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
|
messages" setting decides per message. It bypasses the BLE collision guard's queue but not the
|
||||||
guard itself.
|
guard itself.
|
||||||
- **Radio polled from configure on**, not from the first PoTi, so the 16-frame queue never overflows
|
- **Radio polled from configure on**, not from the first PoTi, so the 16-frame queue never overflows
|
||||||
|
|||||||
@@ -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
|
\toprule\textbf{Parameter} & \textbf{Setting} & \textbf{Description} \\\midrule\endhead
|
||||||
\bottomrule\endfoot
|
\bottomrule\endfoot
|
||||||
{\ttfamily radio} & {\ttfamily transmit-\allowbreak{}and-\allowbreak{}receive} & Enables both transmission and reception. \\
|
{\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 traffic\_\allowbreak{}class} & {\ttfamily 2} & Selects default traffic priority DP2. \\
|
||||||
{\ttfamily lifetime} & {\ttfamily 0x05} & Encodes the default one-second lifetime. \\
|
{\ttfamily lifetime} & {\ttfamily 0x05} & Encodes the default one-second lifetime. \\
|
||||||
\end{longtable}}
|
\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 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. \\
|
{\ttfamily tx\_guard} & {\ttfamily BLE collision guard} & Handed to the radio through the same BLE guard as signed frames. \\
|
||||||
\end{longtable}}
|
\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}
|
\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.
|
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}@{}}
|
{\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
|
\toprule\textbf{Revision} & \textbf{Date} & \textbf{Changes} \\\midrule\endhead
|
||||||
\bottomrule\endfoot
|
\bottomrule\endfoot
|
||||||
1 & 2026-11 & Niklas Dathe: the microbu-firmware interface reference, commit e4e4bd8. \\
|
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{longtable}}
|
||||||
\end{document}
|
\end{document}
|
||||||
|
|||||||
@@ -482,10 +482,16 @@ link::Code Station::configure(const link::StationConfigure& c, link::Bytes& deta
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
config_ = c;
|
config_ = c;
|
||||||
// MicrOBU: a fresh locally administered unicast MAC for unsecured frames on every configuration,
|
// MicrOBU: the MAC of unsecured frames. A phone that sends the 16-octet STATION_CONFIGURE with
|
||||||
// so a station that does not sign does not keep one link-layer identity either.
|
// address_configuration 0 (AUTO) names it itself: it rotates it with its pseudonym on a ride and
|
||||||
esp_fill_random(unsecured_mid_, sizeof unsecured_mid_);
|
// keeps it fixed for the bench pinger. Without one (the 6-octet form) a fresh locally administered
|
||||||
unsecured_mid_[0] = static_cast<std::uint8_t>((unsecured_mid_[0] & 0xFC) | 0x02);
|
// 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
|
link_subscriptions_.clear(); // a configuration starts a phone session: earlier subscriptions are void
|
||||||
counters_ = link::Status {}; // and the session's counters start at zero
|
counters_ = link::Status {}; // and the session's counters start at zero
|
||||||
const auto result = build();
|
const auto result = build();
|
||||||
|
|||||||
@@ -121,6 +121,22 @@ TEST(station_configure_is_the_six_octet_form_the_app_sends) {
|
|||||||
CHECK(!link::decode(hex("02b4001401"), bad)); // five octets
|
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) {
|
TEST(poti_update_decodes_the_apps_31_octets) {
|
||||||
link::PotiUpdate p;
|
link::PotiUpdate p;
|
||||||
CHECK(link::decode(hex("fbb2b7ffa60000002bcbeb1f914bf905e601e60100000e000000001f02d204"), 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