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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user