diff --git a/README.md b/README.md
index f9e7a38..4b4d097 100644
--- a/README.md
+++ b/README.md
@@ -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.
diff --git a/TODO.md b/TODO.md
index e5e7d9a..91878f9 100644
--- a/TODO.md
+++ b/TODO.md
@@ -32,8 +32,20 @@ Still open:
- [ ] 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.
-- [ ] Pseudonym rotation: the link has no MAC field any more, so the station ID rotates while the
- GN address stays the ticket's (see README).
+- [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.
+- [ ] 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)
diff --git a/app/src/main/java/com/hawhamburg/micr0bu/data/transport/Esp32Link.kt b/app/src/main/java/com/hawhamburg/micr0bu/data/transport/Esp32Link.kt
index 37d0cad..1864c9c 100644
--- a/app/src/main/java/com/hawhamburg/micr0bu/data/transport/Esp32Link.kt
+++ b/app/src/main/java/com/hawhamburg/micr0bu/data/transport/Esp32Link.kt
@@ -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
diff --git a/app/src/main/java/com/hawhamburg/micr0bu/data/transport/StationLink.kt b/app/src/main/java/com/hawhamburg/micr0bu/data/transport/StationLink.kt
index f1baab7..5ce3496 100644
--- a/app/src/main/java/com/hawhamburg/micr0bu/data/transport/StationLink.kt
+++ b/app/src/main/java/com/hawhamburg/micr0bu/data/transport/StationLink.kt
@@ -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()
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index 7ce4861..3b412be 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -78,9 +78,9 @@
Bluetooth
Bluetooth
Bluetooth-Verbindung ist für Phase 03 geplant und noch nicht implementiert.
- ESP32-C5 (USB Seriell)
+ ESP32-C5
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.
- Nicht verbunden - ESP32-C5 an den nativen USB-C-Port anschließen und Verbinden antippen.
+ Nicht verbunden - Verbinden antippen (USB-C-Verbindung: ESP32-C5 zuerst an den nativen USB-C-Port anschließen).
Gerät erkannt, wird geöffnet…
Warte auf USB-Berechtigung…
Verbunden
@@ -323,7 +323,7 @@
%1$.0f s
ESP32-C5-Verbindung
Bluetooth
- 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.
+ 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.
Senden während der Aufzeichnung
CAM
VAM
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index f2adf6d..13eccbf 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -79,9 +79,9 @@
Bluetooth
Bluetooth
Bluetooth connection is planned for Phase 03 and is not yet implemented.
- ESP32-C5 (USB Serial)
+ ESP32-C5
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.
- Not connected - plug the ESP32-C5 into the native USB-C port and tap Connect.
+ Not connected - tap Connect (USB-C link: plug the ESP32-C5 into the native USB-C port first).
Device detected, opening…
Waiting for USB permission…
Connected
@@ -330,7 +330,7 @@
Trip Review
ESP32-C5 link
Bluetooth
- 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.
+ 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.
Transmit while recording
CAM
VAM
diff --git a/app/src/test/java/com/hawhamburg/micr0bu/StationLinkTest.kt b/app/src/test/java/com/hawhamburg/micr0bu/StationLinkTest.kt
index e449bed..b6e960a 100644
--- a/app/src/test/java/com/hawhamburg/micr0bu/StationLinkTest.kt
+++ b/app/src/test/java/com/hawhamburg/micr0bu/StationLinkTest.kt
@@ -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(
diff --git a/obu-firmware/NOTES.md b/obu-firmware/NOTES.md
index ceaf649..3e51562 100644
--- a/obu-firmware/NOTES.md
+++ b/obu-firmware/NOTES.md
@@ -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
diff --git a/obu-firmware/docs/station-link.synctex(busy) b/obu-firmware/docs/station-link.synctex(busy)
new file mode 100644
index 0000000..e69de29
diff --git a/obu-firmware/docs/station-link.tex b/obu-firmware/docs/station-link.tex
index 4a22288..dcd267f 100644
--- a/obu-firmware/docs/station-link.tex
+++ b/obu-firmware/docs/station-link.tex
@@ -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}
diff --git a/obu-firmware/main/station.cpp b/obu-firmware/main/station.cpp
index 60fcdc0..229ea39 100644
--- a/obu-firmware/main/station.cpp
+++ b/obu-firmware/main/station.cpp
@@ -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((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((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();
diff --git a/obu-firmware/test/host/test_firmware.cpp b/obu-firmware/test/host/test_firmware.cpp
index 5afa969..012ad05 100644
--- a/obu-firmware/test/host/test_firmware.cpp
+++ b/obu-firmware/test/host/test_firmware.cpp
@@ -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));
diff --git a/tools/station_tx_test.py b/tools/station_tx_test.py
new file mode 100644
index 0000000..d7dee03
--- /dev/null
+++ b/tools/station_tx_test.py
@@ -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(" (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("= 4:
+ op, fl, sq = payload[0], payload[1], struct.unpack("= 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("= 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("