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:
@@ -55,11 +55,22 @@ Settings > Developer > V2X data logger. 110 unit tests pass. ESP32-C5 path check
|
||||
- [ ] **CiT One:** same, `source='cit_one'`, `rssi_dbm` NULL, `obu_*` filled from `v2x/rx/obu_gnss`.
|
||||
Expect both `channel='raw'` and `channel='processed'` rows for the same CAM.
|
||||
- [ ] **Screen off for a few minutes** with the log running: rows keep arriving (foreground service).
|
||||
- [ ] **MAPEM and VAM on the ESP32-C5 need a firmware change.** `gn_unwrap.c` accepts only BTP ports
|
||||
2001, 2002, 2004; add 2003 (MAPEM) and 2018 (VAM) and reflash. Real MAPEMs are mostly over the
|
||||
512-byte link limit, so most will still be counted as oversize drops. The app side already logs
|
||||
any port. On the CiT One, MAPEM arrives via `v2x/rx/mapem` (subscribed now) or the processed
|
||||
`v2x-uca/output/json/map` topic; the API lists no VAM topic, so no VAM rows are expected there.
|
||||
- [ ] **MAPEM and VAM on the ESP32-C5.** Firmware side done 2026-10-28: `gn_unwrap.c` accepts 2003
|
||||
(MAPEM) and 2018 (VAM), signed or not. The bench RSU's MAPEM is 295 bytes and fits; real
|
||||
road MAPEMs over 494 bytes are still dropped as oversize (no fragmentation). On air with the
|
||||
bench listener on COM3 (`tools/bench_listen_watch.py COM3 90`): 104 MAPEM (295 B, GBC), 185
|
||||
SPATEM (58 B), 472 CAM in 90 s, 0 oversize. COM10 app-flashed 2026-10-28 (d0fcb45-dirty, NVS
|
||||
kept; STATUS 106 octets, 3999 mV). BLE reconnected to the Pixel on the bond it already had
|
||||
(16:38, bond state 12, ATT MTU 517, credentials loaded, 1 ticket). Still to do (RSU off): a V2X
|
||||
log shows `MAPEM` rows with `source='esp32'`. App side: `CamUseCaseRepository` logs "unexpected BTP
|
||||
port" for 2003/2018 (no decoder there yet). On the CiT One, MAPEM arrives via `v2x/rx/mapem` (subscribed now) or
|
||||
the processed `v2x-uca/output/json/map` topic; the API lists no VAM topic, so no VAM rows are
|
||||
expected there.
|
||||
- [ ] **Signed SPATEM/MAPEM on air.** On 2026-10-28 the bench RSU sent CAM, SPATEM and MAPEM all
|
||||
unsigned, so the signed path for these two is checked on the host only (`test_secured_gbc`
|
||||
in `test_chain.c`; the envelope code is the one real signed CAMs and GBC DENMs pass). Once the
|
||||
RSU signs: `bench_listen_watch.py COM3 60` must show the `signed` column equal to `count` for
|
||||
ports 2003 and 2004.
|
||||
|
||||
### Signed-TX firmware (vanetza-idf port), VAM and BLE: first on-air checks (added 2026-09-23)
|
||||
|
||||
|
||||
@@ -22,7 +22,14 @@ Changed or added for this project (search for `MicrOBU:` in the sources):
|
||||
than the provisioned demo root (every RSU). Every captured frame therefore also goes through the
|
||||
previous firmware's `gn_unwrap.c` and reaches the phone as link opcode `V2X_RX` (0x85), whose body
|
||||
is exactly the old `SERIAL_MSG_V2X_RX` payload (`Station::forward_raw`). The app's receive side is
|
||||
unchanged.
|
||||
unchanged. Signed or not, BTP ports 2001 CAM, 2002 DENM, 2003 MAPEM, 2004 SPATEM and 2018 VAM
|
||||
pass (MAPEM and VAM since 2026-10-28); a message over 494 bytes does not fit a 512-octet link
|
||||
message and is dropped and counted, not fragmented.
|
||||
- **Bench listener** (`CONFIG_MICROBU_BENCH_LISTEN`, off in `sdkconfig`): for a board whose only PC
|
||||
connection is the UART0 console. It configures itself receive-only at boot and logs every V2X_RX;
|
||||
`tools/bench_listen_watch.py COMx` tallies the log. Build it from a copy of `sdkconfig` with the
|
||||
option on and `CONFIG_MICROBU_BATTERY_ADC_GPIO=-1` (on a board without the XIAO's cell divider,
|
||||
GPIO6 floats and can read like a flat cell, which deep-sleeps the board), e.g. `idf.py -B build-bench -DSDKCONFIG=<copy> build`.
|
||||
- **Unsigned transmission is still possible.** The colleague's station refuses unsecured requests.
|
||||
Here a request with GN security profile 1 goes out with the previous firmware's `geonet.c` header
|
||||
and the position of the last PoTi (`Station::unsecured_request`); the app's "Sign outgoing
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -1200,6 +1200,8 @@ CONFIG_MICROBU_TX_LED_BLINK_MS=100
|
||||
# default:
|
||||
# CONFIG_MICROBU_LED_INVERTED_RX is not set
|
||||
# default:
|
||||
# CONFIG_MICROBU_BENCH_LISTEN is not set
|
||||
# default:
|
||||
CONFIG_MICROBU_BATTERY_ADC_GPIO=6
|
||||
# default:
|
||||
CONFIG_MICROBU_BATTERY_EN_GPIO=26
|
||||
|
||||
@@ -22,20 +22,22 @@ import sys
|
||||
import asn1tools
|
||||
|
||||
ROOT = pathlib.Path(__file__).resolve().parents[3]
|
||||
PORT_NAMES = {2001: "CAM", 2002: "DENM", 2004: "SPATEM"}
|
||||
# main.c's RX_FRAME_MAX_LEN: the most of any frame the board hands to gn_unwrap_its. test_replay
|
||||
PORT_NAMES = {2001: "CAM", 2002: "DENM", 2003: "MAPEM", 2004: "SPATEM", 2018: "VAM"}
|
||||
# c5_radio.cpp's Raw::bytes: the most of any frame the board hands to gn_unwrap_its. test_replay
|
||||
# cuts frames to it, so this does too.
|
||||
RX_FRAME_MAX_LEN = 800
|
||||
RX_FRAME_MAX_LEN = 2346
|
||||
|
||||
|
||||
def compile_specs():
|
||||
a = ROOT / "asn1"
|
||||
spat_map = asn1tools.compile_files(
|
||||
[str(a / n) for n in ("spatem_2_2_1.asn", "mapem_2_2_1.asn", "dsrc_2_2_1.asn", "cdd_2_2_1.asn")], "uper")
|
||||
uper = {
|
||||
2001: asn1tools.compile_files([str(a / "cam_1_4_1.asn"), str(a / "cdd_1_3_1_1.asn")], "uper"),
|
||||
2002: asn1tools.compile_files([str(a / "denm_1_3_1.asn"), str(a / "cdd_1_3_1_1.asn")], "uper"),
|
||||
2004: asn1tools.compile_files(
|
||||
[str(a / n) for n in ("spatem_2_2_1.asn", "mapem_2_2_1.asn", "dsrc_2_2_1.asn", "cdd_2_2_1.asn")],
|
||||
"uper"),
|
||||
2003: spat_map,
|
||||
2004: spat_map,
|
||||
# no VAM module in asn1/: VAMs are checked against the C parse only, not decoded
|
||||
}
|
||||
names = ("IEEE1609dot2BaseTypes.asn", "IEEE1609dot2.asn")
|
||||
for d in (a, ROOT / "vanetza" / "asn1"):
|
||||
@@ -205,10 +207,10 @@ def main(argv):
|
||||
for key in got:
|
||||
disagreements.append((key, "row from test_replay for a record this did not see"))
|
||||
|
||||
print("check_replay: %d records (%d cut to %d bytes), %d accepted (CAM %d, DENM %d, SPATEM %d; "
|
||||
"%d signed, %d truncated)"
|
||||
print("check_replay: %d records (%d cut to %d bytes), %d accepted (CAM %d, DENM %d, MAPEM %d, "
|
||||
"SPATEM %d, VAM %d; %d signed, %d truncated)"
|
||||
% (stats["records"], stats["capped"], RX_FRAME_MAX_LEN, stats["accepted"], stats["CAM"],
|
||||
stats["DENM"], stats["SPATEM"], stats["signed"], stats["truncated"]))
|
||||
stats["DENM"], stats["MAPEM"], stats["SPATEM"], stats["VAM"], stats["signed"], stats["truncated"]))
|
||||
if sec_dir:
|
||||
print(" envelopes decoded with asn1tools using %s" % sec_dir.relative_to(ROOT))
|
||||
print(" C vs independent parse: %s" % ("agree on every record" if not disagreements
|
||||
@@ -218,7 +220,10 @@ def main(argv):
|
||||
|
||||
outcome, failures = collections.Counter(), []
|
||||
for (port, payload), key in messages.items():
|
||||
name, spec = PORT_NAMES[port], uper[port]
|
||||
name, spec = PORT_NAMES[port], uper.get(port)
|
||||
if spec is None:
|
||||
outcome[(name, "not decoded (no module)")] += 1
|
||||
continue
|
||||
try:
|
||||
decoded = spec.decode(name, payload)
|
||||
except Exception as e:
|
||||
|
||||
@@ -374,7 +374,9 @@ static uint8_t *put32(uint8_t *p, uint32_t v)
|
||||
return put16(p, (uint16_t)v);
|
||||
}
|
||||
|
||||
static int build_gbc(uint8_t subtype, int32_t area_lat, int32_t area_lon, uint16_t dist_a, uint8_t *f)
|
||||
// Any BTP-B message by GeoBroadcast, the way the bench RSU sends SPATEM and MAPEM too.
|
||||
static int build_gbc_msg(uint8_t subtype, int32_t area_lat, int32_t area_lon, uint16_t dist_a,
|
||||
uint16_t port, const uint8_t *payload, int payload_len, uint8_t *f)
|
||||
{
|
||||
uint8_t *p = f;
|
||||
// 802.11 QoS Data: FC, duration, addr1..3, sequence control, QoS control
|
||||
@@ -392,7 +394,7 @@ static int build_gbc(uint8_t subtype, int32_t area_lat, int32_t area_lon, uint16
|
||||
// Common: NH BTP-B, HT 4 (GBC) / subtype = area shape, TC 1, flags 0 (stationary), PL, MHL, reserved
|
||||
const uint8_t common[4] = {0x20, (uint8_t)(0x40 | subtype), 0x01, 0x00};
|
||||
p = put(p, common, 4);
|
||||
p = put16(p, (uint16_t)(BTP_B + DENM_STUB_LEN));
|
||||
p = put16(p, (uint16_t)(BTP_B + payload_len));
|
||||
*p++ = 10;
|
||||
*p++ = 0;
|
||||
// GBC extended header: SN, reserved, SO PV (GN_ADDR with station type 15 = RSU, MID, TST, lat,
|
||||
@@ -412,13 +414,18 @@ static int build_gbc(uint8_t subtype, int32_t area_lat, int32_t area_lon, uint16
|
||||
p = put16(p, subtype ? 40 : 0);
|
||||
p = put16(p, subtype ? 900 : 0);
|
||||
p = put16(p, 0);
|
||||
// BTP-B: DENM
|
||||
p = put16(p, 2002);
|
||||
// BTP-B
|
||||
p = put16(p, port);
|
||||
p = put16(p, 0);
|
||||
p = put(p, k_denm_stub, DENM_STUB_LEN);
|
||||
p = put(p, payload, payload_len);
|
||||
return (int)(p - f);
|
||||
}
|
||||
|
||||
static int build_gbc(uint8_t subtype, int32_t area_lat, int32_t area_lon, uint16_t dist_a, uint8_t *f)
|
||||
{
|
||||
return build_gbc_msg(subtype, area_lat, area_lon, dist_a, 2002, k_denm_stub, DENM_STUB_LEN, f);
|
||||
}
|
||||
|
||||
static void test_gbc_rx(void)
|
||||
{
|
||||
static const struct { uint8_t subtype; int32_t lat, lon; uint16_t dist_a; } areas[] = {
|
||||
@@ -481,10 +488,12 @@ static void test_rejections(void)
|
||||
{"Beacon (HeaderType 1)", 37, 0x10, false, 0},
|
||||
{"GeoUnicast (HeaderType 2)", 37, 0x20, false, 0},
|
||||
{"multi-hop TSB (HeaderType 5, subtype 1)", 37, 0x51, false, 0},
|
||||
{"BTP port 2003 (MAPEM, not accepted yet)", 73, 0xD3, false, 0},
|
||||
{"BTP port 2018 (VAM, not accepted yet)", 73, 0xE2, false, 0},
|
||||
{"BTP port 2002 (DENM)", 73, 0xD2, true, 2002},
|
||||
{"BTP port 2003 (MAPEM)", 73, 0xD3, true, 2003},
|
||||
{"BTP port 2004 (SPATEM)", 73, 0xD4, true, 2004},
|
||||
{"BTP port 2018 (VAM)", 73, 0xE2, true, 2018},
|
||||
{"BTP port 2005 (IVIM, not accepted)", 73, 0xD5, false, 0},
|
||||
{"BTP port 2006 (SREM, not accepted)", 73, 0xD6, false, 0},
|
||||
};
|
||||
for (size_t i = 0; i < sizeof cases / sizeof cases[0]; i++) {
|
||||
tu_set_context("mutation: %s", cases[i].what);
|
||||
@@ -583,16 +592,14 @@ static int put_coer_length(int len, uint8_t *out)
|
||||
return 3;
|
||||
}
|
||||
|
||||
// A secured CAM frame shaped like the recorded ones: our own SHB packet with the Basic Header's
|
||||
// NextHeader set to 2 and everything after the Basic Header wrapped as `prefix` + COER length +
|
||||
// inner packet, then the signature stand-in. Sets where the ITS payload starts and ends.
|
||||
static int build_secured(const uint8_t *prefix, int prefix_len, const uint8_t *payload,
|
||||
int payload_len, uint8_t *f, int *payload_start, int *payload_end)
|
||||
// Secures an unsecured frame `plain` shaped like the recorded signed ones: the Basic Header (at
|
||||
// `basic`) gets NextHeader 2 and everything after it is wrapped as `prefix` + COER length + inner
|
||||
// packet, then the signature stand-in. `ext_len` is the inner packet's extended-header length.
|
||||
// Sets where the ITS payload starts and ends.
|
||||
static int secure_frame(const uint8_t *plain, int plain_len, int basic, int ext_len,
|
||||
const uint8_t *prefix, int prefix_len, uint8_t *f,
|
||||
int *payload_start, int *payload_end)
|
||||
{
|
||||
const gn_lpv_t lpv = test_lpv();
|
||||
uint8_t plain[FRAME_BUF_LEN];
|
||||
const int plain_len = build(payload, payload_len, &lpv, 2001, false, plain, sizeof plain);
|
||||
const int basic = MAC_HDR + LLC_SNAP;
|
||||
const int inner = basic + GN_BASIC; // the Common Header onward
|
||||
const int inner_len = plain_len - inner;
|
||||
|
||||
@@ -603,7 +610,7 @@ static int build_secured(const uint8_t *prefix, int prefix_len, const uint8_t *p
|
||||
n += prefix_len;
|
||||
n += put_coer_length(inner_len, f + n);
|
||||
memcpy(f + n, plain + inner, (size_t)inner_len);
|
||||
*payload_start = n + GN_COMMON + SHB_EXT + BTP_B;
|
||||
*payload_start = n + GN_COMMON + ext_len + BTP_B;
|
||||
n += inner_len;
|
||||
*payload_end = n;
|
||||
for (int i = 0; i < SIG_STUB_LEN; i++) {
|
||||
@@ -612,6 +619,17 @@ static int build_secured(const uint8_t *prefix, int prefix_len, const uint8_t *p
|
||||
return n;
|
||||
}
|
||||
|
||||
// A secured CAM: our own SHB packet, secured.
|
||||
static int build_secured(const uint8_t *prefix, int prefix_len, const uint8_t *payload,
|
||||
int payload_len, uint8_t *f, int *payload_start, int *payload_end)
|
||||
{
|
||||
const gn_lpv_t lpv = test_lpv();
|
||||
uint8_t plain[FRAME_BUF_LEN];
|
||||
const int plain_len = build(payload, payload_len, &lpv, 2001, false, plain, sizeof plain);
|
||||
return secure_frame(plain, plain_len, MAC_HDR + LLC_SNAP, SHB_EXT, prefix, prefix_len, f,
|
||||
payload_start, payload_end);
|
||||
}
|
||||
|
||||
static const uint8_t k_signed_prefix[] = {0x03, 0x81, 0x00, 0x40, 0x03, 0x80};
|
||||
static const uint8_t k_unsecured_prefix[] = {0x03, 0x80};
|
||||
|
||||
@@ -690,6 +708,51 @@ static void test_secured(void)
|
||||
CHECK(!gn_unwrap_its(tu_guarded(f, len), len, &rx), "payload overrunning its envelope: accepted");
|
||||
}
|
||||
|
||||
// Signed SPATEM and MAPEM by GeoBroadcast. No recording holds one yet (the bench RSU sent all three
|
||||
// of its messages unsigned on 2026-10-28), so these are the RSU's recorded GBC frames with the
|
||||
// signed envelope of the recorded CAMs and DENMs around them. 494 bytes is the largest message a
|
||||
// link message carries (Station::forward_raw); 1243 is the largest SPATEM of the 2026-03-18 drive,
|
||||
// which gn_unwrap_its must still unwrap whole even though the station then drops it as oversize.
|
||||
static void test_secured_gbc(void)
|
||||
{
|
||||
static const struct { const char *what; uint16_t port; uint8_t message_id; int payload_len; } cases[] = {
|
||||
{"signed GBC SPATEM, bench size", 2004, 4, 58},
|
||||
{"signed GBC MAPEM, bench size", 2003, 5, 295},
|
||||
{"signed GBC MAPEM, largest that fits a link message", 2003, 5, 494},
|
||||
{"signed GBC SPATEM, largest seen on the road", 2004, 4, 1243},
|
||||
};
|
||||
static uint8_t payload[1243], plain[1400], f[1400];
|
||||
for (size_t c = 0; c < sizeof cases / sizeof cases[0]; c++) {
|
||||
tu_set_context("%s", cases[c].what);
|
||||
const int n = cases[c].payload_len;
|
||||
payload[0] = 0x02; // ItsPduHeader: protocolVersion 2, messageID, stationID
|
||||
payload[1] = cases[c].message_id;
|
||||
for (int i = 2; i < n; i++) {
|
||||
payload[i] = (uint8_t)(i * 7 + cases[c].port);
|
||||
}
|
||||
const int plain_len = build_gbc_msg(0, 535540000, 100220000, 400, cases[c].port, payload, n, plain);
|
||||
int start, end;
|
||||
const int len = secure_frame(plain, plain_len, MAC_HDR + QOS_CTRL + LLC_SNAP, GBC_EXT,
|
||||
k_signed_prefix, (int)sizeof k_signed_prefix, f, &start, &end);
|
||||
gn_rx_t rx;
|
||||
const uint8_t *g = tu_guarded(f, len);
|
||||
const bool ok = gn_unwrap_its(g, len, &rx);
|
||||
CHECK(ok, "%s: rejected", cases[c].what);
|
||||
if (ok) {
|
||||
CHECK(rx.btp_dest_port == cases[c].port && rx.signed_unverified && !rx.truncated &&
|
||||
rx.has_geo_area && rx.geo_area_distance_a_m == 400,
|
||||
"%s: port %d signed %d truncated %d area %d/%d", cases[c].what, rx.btp_dest_port,
|
||||
rx.signed_unverified, rx.truncated, rx.has_geo_area, rx.geo_area_distance_a_m);
|
||||
CHECK(rx.payload == g + start && rx.payload_len == n &&
|
||||
memcmp(rx.payload, payload, (size_t)n) == 0,
|
||||
"%s: payload offset %d length %d, expected %d / %d", cases[c].what,
|
||||
(int)(rx.payload - g), rx.payload_len, start, n);
|
||||
}
|
||||
tu_pcap_add(f, len);
|
||||
sweep(cases[c].what, f, len, start, end);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_truncation(void)
|
||||
{
|
||||
const gn_lpv_t lpv = test_lpv();
|
||||
@@ -722,6 +785,7 @@ int main(int argc, char **argv)
|
||||
test_payload_length();
|
||||
test_trailer();
|
||||
test_secured();
|
||||
test_secured_gbc();
|
||||
test_truncation();
|
||||
|
||||
tu_pcap_close();
|
||||
|
||||
@@ -17,14 +17,15 @@
|
||||
#include "gn_unwrap.h"
|
||||
#include "test_util.h"
|
||||
|
||||
// main.c's RX_FRAME_MAX_LEN: the promiscuous callback copies at most this many bytes of a frame,
|
||||
// so it is the most gn_unwrap_its ever sees on the board. Keep in step with main.c.
|
||||
#define RX_FRAME_MAX_LEN 800
|
||||
// c5_radio.cpp's Raw::bytes: the promiscuous callback copies at most this many bytes of a frame,
|
||||
// so it is the most gn_unwrap_its ever sees on the board. Keep in step with c5_radio.cpp. (The old
|
||||
// C firmware's main.c cut frames at 800 bytes.)
|
||||
#define RX_FRAME_MAX_LEN 2346
|
||||
|
||||
typedef struct {
|
||||
FILE *out;
|
||||
const char *path;
|
||||
long records, capped, accepted, cam, denm, spatem, signed_frames, truncated, bad;
|
||||
long records, capped, accepted, cam, denm, mapem, spatem, vam, signed_frames, truncated, bad;
|
||||
} replay_t;
|
||||
|
||||
static void on_frame(const uint8_t *frame, int len, int index, void *ctx)
|
||||
@@ -57,7 +58,9 @@ static void on_frame(const uint8_t *frame, int len, int index, void *ctx)
|
||||
r->accepted++;
|
||||
r->cam += rx.btp_dest_port == 2001;
|
||||
r->denm += rx.btp_dest_port == 2002;
|
||||
r->mapem += rx.btp_dest_port == 2003;
|
||||
r->spatem += rx.btp_dest_port == 2004;
|
||||
r->vam += rx.btp_dest_port == 2018;
|
||||
r->signed_frames += rx.signed_unverified;
|
||||
r->truncated += rx.truncated;
|
||||
}
|
||||
@@ -91,9 +94,9 @@ int main(int argc, char **argv)
|
||||
}
|
||||
fclose(r.out);
|
||||
|
||||
printf("test_replay: %ld records (%ld cut to %d bytes as main.c does), %ld accepted (CAM %ld, "
|
||||
"DENM %ld, SPATEM %ld; %ld signed, %ld truncated), %ld bad\n",
|
||||
r.records, r.capped, RX_FRAME_MAX_LEN, r.accepted, r.cam, r.denm, r.spatem,
|
||||
printf("test_replay: %ld records (%ld cut to %d bytes as c5_radio.cpp does), %ld accepted (CAM %ld, "
|
||||
"DENM %ld, MAPEM %ld, SPATEM %ld, VAM %ld; %ld signed, %ld truncated), %ld bad\n",
|
||||
r.records, r.capped, RX_FRAME_MAX_LEN, r.accepted, r.cam, r.denm, r.mapem, r.spatem, r.vam,
|
||||
r.signed_frames, r.truncated, r.bad);
|
||||
return (r.bad || unreadable) ? 1 : 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
"""Tally what an obu-firmware BENCH LISTEN build (CONFIG_MICROBU_BENCH_LISTEN) hears, from its UART0 console.
|
||||
|
||||
py -3.11 tools/bench_listen_watch.py COM3 [seconds]
|
||||
|
||||
The bench build logs one line per message its raw RX path (gn_unwrap.c) unwraps, e.g.
|
||||
I (12345) station: V2X_RX port 2003 msgid 5, 295 bytes, -61 dBm, GBC
|
||||
This counts them per BTP port: how many, sizes, RSSI range, how many signed, how many too big for a
|
||||
link message (dropped). Opening the port resets the board (DTR/RTS), so the first lines are the boot.
|
||||
Needs pyserial (the ESP-IDF python env has it).
|
||||
"""
|
||||
import collections
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
|
||||
import serial
|
||||
|
||||
LINE = re.compile(r"V2X_RX port (\d+) msgid (\d+), (\d+) bytes, (-?\d+) dBm(.*)")
|
||||
NAMES = {2001: 'CAM', 2002: 'DENM', 2003: 'MAPEM', 2004: 'SPATEM', 2018: 'VAM'}
|
||||
|
||||
|
||||
def main():
|
||||
port = sys.argv[1]
|
||||
seconds = float(sys.argv[2]) if len(sys.argv) > 2 else 60
|
||||
stats = collections.defaultdict(lambda: {'n': 0, 'sizes': set(), 'msgids': set(), 'rssi': [],
|
||||
'signed': 0, 'gbc': 0, 'oversize': 0})
|
||||
with serial.Serial(port, 115200, timeout=0.5) as s:
|
||||
end = time.monotonic() + seconds
|
||||
buffer = b''
|
||||
while time.monotonic() < end:
|
||||
buffer += s.read(4096)
|
||||
*lines, buffer = buffer.split(b'\n')
|
||||
for raw in lines:
|
||||
text = raw.decode(errors='replace').rstrip()
|
||||
m = LINE.search(text)
|
||||
if not m:
|
||||
if 'BENCH' in text or 'radio' in text or ' E (' in text or text.startswith('E ('):
|
||||
print(text)
|
||||
continue
|
||||
p, msgid, length, rssi, rest = int(m[1]), int(m[2]), int(m[3]), int(m[4]), m[5]
|
||||
st = stats[p]
|
||||
st['n'] += 1
|
||||
st['sizes'].add(length)
|
||||
st['msgids'].add(msgid)
|
||||
st['rssi'].append(rssi)
|
||||
st['signed'] += 'signed' in rest
|
||||
st['gbc'] += 'GBC' in rest
|
||||
st['oversize'] += 'OVERSIZE' in rest
|
||||
print(f"\n{seconds:.0f} s on {port}:")
|
||||
print(f"{'port':>5} {'type':7} {'count':>6} {'msgid':>6} {'bytes':>12} {'dBm':>10} {'signed':>7} {'GBC':>5} {'oversize':>9}")
|
||||
for p in sorted(stats):
|
||||
st = stats[p]
|
||||
sizes = f"{min(st['sizes'])}-{max(st['sizes'])}" if len(st['sizes']) > 1 else str(min(st['sizes']))
|
||||
msgids = ','.join(map(str, sorted(st['msgids'])))
|
||||
rssi = f"{min(st['rssi'])}..{max(st['rssi'])}"
|
||||
print(f"{p:>5} {NAMES.get(p, '?'):7} {st['n']:>6} {msgids:>6} {sizes:>12} {rssi:>10} {st['signed']:>7} {st['gbc']:>5} {st['oversize']:>9}")
|
||||
if not stats:
|
||||
print(" nothing: is it the bench build (BENCH LISTEN line at boot), and is anything on air?")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user