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:
Ashin Walpola
2026-11-11 15:02:39 +01:00
parent a7a6c39ca1
commit 37707548ca
13 changed files with 313 additions and 24 deletions
@@ -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()
+3 -3
View File
@@ -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>
+3 -3
View File
@@ -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(