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
+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;