Forward MAPEM and VAM from the ESP32-C5, and add a bench listener

gn_unwrap.c now passes BTP ports 2003 (MAPEM) and 2018 (VAM), signed or
not, besides CAM, DENM and SPATEM. A message over 494 bytes still does not
fit one 512-octet link message (also the largest GATT value) and is dropped
and counted, not fragmented. The bench RSU's MAPEM is 295 bytes.

CONFIG_MICROBU_BENCH_LISTEN (off in sdkconfig) is for a board whose only PC
connection is the UART0 console: it configures itself receive-only at boot
and logs every V2X_RX message; tools/bench_listen_watch.py tallies the log.
On air on 2026-10-28 it forwarded 104 MAPEM, 185 SPATEM and 472 CAM in
90 s, with nothing oversize. The RSU sent all of them unsigned.

Host tests: signed GeoBroadcast SPATEM/MAPEM frames of 58 to 1243 bytes
with every truncation length; the replay cuts frames at c5_radio.cpp's
2346 bytes (not the old C firmware's 800) and checks MAPEMs with asn1tools.
This commit is contained in:
Ashin Walpola
2026-10-28 16:48:37 +01:00
parent 9f77f9f0e4
commit fc3354a4ba
12 changed files with 246 additions and 55 deletions
+10
View File
@@ -36,6 +36,16 @@ config MICROBU_TX_LED_BLINK_MS
config MICROBU_LED_INVERTED_RX
bool "Inverted LED mode for receiver/bridge (normally ON, blink OFF on packet)"
default n
config MICROBU_BENCH_LISTEN
bool "Bench listener: receive from boot and log every V2X_RX on the console"
default n
help
For a test board whose PC connection is only the UART0 console (no phone, no USB
Serial/JTAG link): the station configures itself at boot with the radio receive only and
security off, and logs one line per ITS message the raw path (gn_unwrap.c) unwraps: BTP
port, messageID, length, RSSI, signed, GeoBroadcast, and whether it fits a link message.
A phone that configures the station later replaces this configuration. Never enable it in
the production image.
config MICROBU_BATTERY_ADC_GPIO
int "Battery voltage ADC GPIO (-1: no battery monitoring)"
range -1 6
+13
View File
@@ -119,6 +119,19 @@ void station_task(void*) {
microbu::Battery battery;
microbu::BatteryMonitor monitor(battery_config());
std::int64_t next_battery_us = 0;
#if CONFIG_MICROBU_BENCH_LISTEN
{ // MicrOBU: a console-only test board has nothing that would configure it (Kconfig help)
microbu::link::StationConfigure bench;
bench.security = 0;
bench.address_configuration = 0;
bench.beaconing = 0;
bench.radio = 1; // receive only
microbu::link::Bytes detail;
const auto code = station.configure(bench, detail);
ESP_LOGW(TAG, "BENCH LISTEN build: radio receive only, security off, logging every V2X_RX (result %u)",
unsigned(code));
}
#endif
ESP_LOGI(TAG, "station task ready; the phone/PC configures the station over BLE or USB Serial-JTAG");
for (;;) { /// main loop: drain the incoming queue, tick the station and link service, tick the controls
Incoming* incoming = nullptr;
+4 -1
View File
@@ -47,7 +47,9 @@
// NOTE the crossover: SPATEM is BTP port 2004 but ItsPduHeader messageID 4, while MAPEM is port
// 2003 and messageID 5. Port and messageID are NOT the same number - mixing them up routes every
// message to the wrong decoder on the phone.
#define BTP_DEST_PORT_MAPEM (2003)
#define BTP_DEST_PORT_SPATEM (2004)
#define BTP_DEST_PORT_VAM (2018)
static const uint8_t s_llc_snap_prefix[6] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
@@ -249,7 +251,8 @@ bool gn_unwrap_its(const uint8_t *frame, int frame_len, gn_rx_t *out)
}
uint16_t dest_port = be16(frame + offset);
if (dest_port != BTP_DEST_PORT_CAM && dest_port != BTP_DEST_PORT_DENM &&
dest_port != BTP_DEST_PORT_SPATEM) {
dest_port != BTP_DEST_PORT_MAPEM && dest_port != BTP_DEST_PORT_SPATEM &&
dest_port != BTP_DEST_PORT_VAM) {
return false;
}
+16 -12
View File
@@ -47,20 +47,23 @@
// decoders stop where the message ends, which is why nothing visibly broke.
//
// ---- Accepted BTP-B ports (ETSI TS 103 248) ------------------------------------------------
// 2001 (CAM), 2002 (DENM) and 2004 (SPATEM). MAPEM (2003) and the rest are deliberately not
// accepted yet: the phone has no decoder for them, so forwarding would just burn serial
// bandwidth. Adding one is a one-line change here plus a decoder on the phone - the serial
// protocol itself is already generic (see SERIAL_MSG_V2X_RX in serial_link.h).
// 2001 (CAM), 2002 (DENM), 2003 (MAPEM, since 2026-10-28), 2004 (SPATEM) and 2018 (VAM, since
// 2026-10-28; another micrOBU's VAM is demo-signed, so the stack verifies it too, but the app reads
// only this path). Other ports are dropped. The link message itself is generic: the port says what
// the payload is.
//
// SPATEM size caveat: SERIAL_LINK_MAX_PAYLOAD is 512, so a SPATEM whose UPER exceeds 498 bytes is
// counted as an oversize drop rather than forwarded. The bench RSU trigger emits ~58-byte SPATEMs
// and is unaffected, but real road RSUs measured 555 bytes median and 1243 max (2026-03-18 drive,
// 79k messages), i.e. roughly 70% would be dropped. Raising the cap is deliberately deferred: it
// also requires enlarging main.c's RX_FRAME_MAX_LEN.
// Size caveat: a link message is at most 512 octets (link::maximum_message, which is also the
// largest GATT attribute value), so Station::forward_raw() drops a message whose UPER exceeds
// 494 bytes and counts it as oversize instead of forwarding it. Nothing is fragmented. The bench
// RSU's messages all fit (2026-10-28 capture: SPATEM 58, MAPEM 295 bytes); real road SPATEMs and
// MAPEMs often do not (SPATEM 555 bytes median, 1243 max on the 2026-03-18 drive). The radio
// itself captures frames of up to 2346 bytes (c5_radio.cpp), so `truncated` does not happen on
// this firmware.
//
// No FCS/CRC check here: the WiFi driver has already validated the frame.
typedef struct {
// BTP-B destination port, identifying the service: 2001 = CAM, 2002 = DENM, 2004 = SPATEM.
// BTP-B destination port, identifying the service: 2001 = CAM, 2002 = DENM, 2003 = MAPEM,
// 2004 = SPATEM, 2018 = VAM.
uint16_t btp_dest_port;
// ITS payload (UPER message bytes). Points INTO the caller's `frame` buffer - NOT a copy, so
@@ -80,8 +83,9 @@ typedef struct {
// The packet arrived inside a TS 103 097 signed envelope. The signature was NOT checked.
bool signed_unverified;
// The frame ended before the payload its headers declare. On the board only main.c's
// RX_FRAME_MAX_LEN capture limit causes this (the driver drops frames that fail their FCS).
// The frame ended before the payload its headers declare. On the board only a capture limit
// causes this (the driver drops frames that fail their FCS): the old C firmware's 800-byte
// RX_FRAME_MAX_LEN did; c5_radio.cpp keeps whole frames.
// payload/payload_len then cover just the part that arrived, so it must not be forwarded.
bool truncated;
} gn_rx_t;
+9 -2
View File
@@ -366,8 +366,15 @@ void Station::forward_raw(const ByteBuffer& frame, int rssi) {
gn_rx_t rx;
if (!gn_unwrap_its(frame.data(), static_cast<int>(frame.size()), &rx)) return;
constexpr std::size_t prefix = 14;
if (rx.truncated || rx.payload_len <= 0 ||
static_cast<std::size_t>(rx.payload_len) + prefix + link::header_size > link::maximum_message) {
const bool fits = !rx.truncated && rx.payload_len > 0 &&
static_cast<std::size_t>(rx.payload_len) + prefix + link::header_size <= link::maximum_message;
#if CONFIG_MICROBU_BENCH_LISTEN
ESP_LOGI(TAG, "V2X_RX port %u msgid %u, %d bytes, %d dBm%s%s%s", unsigned(rx.btp_dest_port),
rx.payload_len > 1 ? unsigned(rx.payload[1]) : 0u, rx.payload_len, rssi,
rx.signed_unverified ? ", signed" : "", rx.has_geo_area ? ", GBC" : "",
fits ? "" : ", OVERSIZE (dropped)");
#endif
if (!fits) {
++raw_oversize_;
static std::int64_t last_report = 0; // one line per 10 s at most, the counter has the rest
const auto now = esp_timer_get_time();