Rebuild obu-firmware on Niklas Dathe's microbu-firmware
Replace the vanetza-idf port with his current station firmware (microbu-firmware e4e4bd8: main/, components/microbu_v2x, components/vanetza, external/vanetza) and re-apply the MicrOBU additions, each marked "MicrOBU:" in the sources: - V2X_RX (opcode 0x90): every received ITS message, signed or not, through gn_unwrap.c, because the stack drops unsigned and foreign-root traffic. 0x85 is the spec's RAW_FRAME and 0x86 is reserved. The body is built in v2x_rx.hpp. - Unsigned transmission (geonet.c) for security profile 1 or station security 0, from a random MAC per configuration. - Radio polled from STATION_CONFIGURE on; manual country policy, TX power read-back, static RX buffer, short frames ignored. - Battery guard (battery_policy.hpp): deep sleep below 3.30 V with no phone on USB. - No USB writes without a host; last_frame_ms() for the guard. - 80 KB NVS with the app at 0x20000, 8 MB flash, XIAO ESP32-C5 board, 20 dBm. Remove the old C firmware, the bench listener and the old vanetza-idf copy. Add docs/station-link.tex as revision 2 of the interface reference (V2X_RX, unsigned sending, battery rule, revision history). Add 39 host unit tests (make firmware in test/host) next to the existing chain, replay, fuzz and battery tests, and point tools/station_status_watch.py at the new CONFIRM-based status.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "link_protocol.hpp"
|
||||
#include <algorithm>
|
||||
|
||||
namespace microbu::link {
|
||||
|
||||
@@ -37,15 +38,43 @@ DestinationArea get_area(Reader& r) {
|
||||
// STATION_CONFIGURE
|
||||
Bytes encode(const StationConfigure& c) {
|
||||
Writer w;
|
||||
w.u8(c.station_type); w.u8(c.security); w.u8(c.address_configuration); w.bytes(c.mid, 6); w.u8(c.beaconing);
|
||||
w.u16(c.channel_number); w.u8(c.transmit_power_dbm); w.u8(c.radio); w.u8(c.default_traffic_class); w.u8(c.default_lifetime);
|
||||
const StationConfigure defaults;
|
||||
if (c.radio != 2 || c.address_configuration != 1 || c.default_traffic_class != 2 || c.default_lifetime != 0x05 ||
|
||||
!std::equal(c.mid, c.mid + 6, defaults.mid)) {
|
||||
w.u8(c.station_type); w.u8(c.security); w.u8(c.address_configuration); w.bytes(c.mid, 6); w.u8(c.beaconing);
|
||||
w.u16(c.channel_number); w.u8(c.transmit_power_dbm); w.u8(c.radio); w.u8(c.default_traffic_class); w.u8(c.default_lifetime);
|
||||
return w.out;
|
||||
}
|
||||
// Streamlined 6-octet operational format
|
||||
w.u8(c.station_type);
|
||||
w.u16(c.channel_number);
|
||||
w.u8(c.transmit_power_dbm);
|
||||
w.u8(c.security);
|
||||
w.u8(c.beaconing);
|
||||
return w.out;
|
||||
}
|
||||
bool decode(const Bytes& body, StationConfigure& c) {
|
||||
Reader r(body);
|
||||
c.station_type = r.u8(); c.security = r.u8(); c.address_configuration = r.u8(); r.bytes(c.mid, 6); c.beaconing = r.u8();
|
||||
c.channel_number = r.u16(); c.transmit_power_dbm = r.u8(); c.radio = r.u8(); c.default_traffic_class = r.u8(); c.default_lifetime = r.u8();
|
||||
return r.done() && c.security <= 1 && c.address_configuration <= 1 && c.beaconing <= 1 && c.radio <= 2;
|
||||
if (body.size() == 6) {
|
||||
c = StationConfigure{};
|
||||
Reader r(body);
|
||||
c.station_type = r.u8();
|
||||
c.channel_number = r.u16();
|
||||
c.transmit_power_dbm = r.u8();
|
||||
c.security = r.u8();
|
||||
c.beaconing = r.u8();
|
||||
c.address_configuration = 1;
|
||||
c.radio = 2;
|
||||
c.default_traffic_class = 2;
|
||||
c.default_lifetime = 0x05;
|
||||
return r.done() && c.security <= 1 && c.beaconing <= 1;
|
||||
}
|
||||
if (body.size() == 16) {
|
||||
Reader r(body);
|
||||
c.station_type = r.u8(); c.security = r.u8(); c.address_configuration = r.u8(); r.bytes(c.mid, 6); c.beaconing = r.u8();
|
||||
c.channel_number = r.u16(); c.transmit_power_dbm = r.u8(); c.radio = r.u8(); c.default_traffic_class = r.u8(); c.default_lifetime = r.u8();
|
||||
return r.done() && c.security <= 1 && c.address_configuration <= 1 && c.beaconing <= 1 && c.radio <= 2;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// POTI_UPDATE
|
||||
@@ -72,6 +101,7 @@ Bytes encode(const BtpDataRequest& q) {
|
||||
w.u8(static_cast<std::uint8_t>(q.context.size())); w.bytes(q.context);
|
||||
if (q.gn_packet_transport_type == 3) put_area(w, q.area.value_or(DestinationArea {}));
|
||||
w.u16(static_cast<std::uint16_t>(q.fl_sdu.size())); w.bytes(q.fl_sdu);
|
||||
if (q.generated_at_ms) w.u64(*q.generated_at_ms);
|
||||
return w.out;
|
||||
}
|
||||
bool decode(const Bytes& body, BtpDataRequest& q) {
|
||||
@@ -84,6 +114,8 @@ bool decode(const Bytes& body, BtpDataRequest& q) {
|
||||
q.area.reset();
|
||||
if (q.gn_packet_transport_type == 3) q.area = get_area(r);
|
||||
q.fl_sdu = r.bytes(r.u16());
|
||||
q.generated_at_ms.reset();
|
||||
if (r.ok() && r.remaining() == 8) q.generated_at_ms = r.u64();
|
||||
return r.done() && q.btp_type <= 1 && q.permissions.size() <= 31;
|
||||
}
|
||||
|
||||
@@ -157,11 +189,15 @@ Bytes encode(const Status& s) {
|
||||
w.u32(s.radio_submitted); w.u32(s.radio_failed); w.u32(s.radio_received); w.u32(s.radio_dropped);
|
||||
w.u32(s.link_rx_frames); w.u32(s.link_crc_errors); w.u32(s.link_malformed); w.u32(s.poti_updates);
|
||||
w.u64(s.its_time_ms);
|
||||
w.u16(s.battery_mv); w.u8(s.battery_flags);
|
||||
w.u16(s.cbr_local); w.u16(s.cbr_global); w.u16(s.dcc_delta); w.u16(s.t_gen_vam_dcc_ms);
|
||||
w.u32(s.heap_free); w.u32(s.heap_minimum_free); w.u32(s.heap_largest_block); w.u32(s.dma_largest_block);
|
||||
w.u16(static_cast<std::uint16_t>(s.board_temperature_deci_deg));
|
||||
w.u16(s.battery_mv);
|
||||
return w.out;
|
||||
}
|
||||
bool decode(const Bytes& body, Status& s) {
|
||||
if (body.size() != status_size_base && body.size() < status_size_battery) return false;
|
||||
if (body.size() != 111 && body.size() != 127 && body.size() != 129 && body.size() != 131 && body.size() != 132) return false;
|
||||
s = Status{};
|
||||
Reader r(body);
|
||||
s.uptime_ms = r.u32(); s.configured = r.u8(); r.bytes(s.gn_address, 8); r.bytes(s.identifier, 8); s.change_pending = r.u8(); s.tickets = r.u8();
|
||||
s.signed_messages = r.u32(); s.refused_no_ticket = r.u32(); s.refused_change_pending = r.u32(); s.refused_permission = r.u32();
|
||||
@@ -170,19 +206,25 @@ bool decode(const Bytes& body, Status& s) {
|
||||
s.radio_submitted = r.u32(); s.radio_failed = r.u32(); s.radio_received = r.u32(); s.radio_dropped = r.u32();
|
||||
s.link_rx_frames = r.u32(); s.link_crc_errors = r.u32(); s.link_malformed = r.u32(); s.poti_updates = r.u32();
|
||||
s.its_time_ms = r.u64();
|
||||
if (!r.ok()) return false;
|
||||
s.battery_mv = 0; s.battery_flags = 0;
|
||||
if (r.remaining() >= 3) { s.battery_mv = r.u16(); s.battery_flags = r.u8(); }
|
||||
return r.ok(); // octets beyond the known fields belong to a later extension
|
||||
s.cbr_local = r.u16(); s.cbr_global = r.u16(); s.dcc_delta = r.u16(); s.t_gen_vam_dcc_ms = r.u16();
|
||||
if (r.remaining() == 0) return r.ok(); // a 111-octet STATUS from firmware before the heap diagnostics
|
||||
s.heap_free = r.u32(); s.heap_minimum_free = r.u32(); s.heap_largest_block = r.u32(); s.dma_largest_block = r.u32();
|
||||
if (r.remaining() == 0) return r.ok(); // 127-octet form before temperature
|
||||
s.board_temperature_deci_deg = static_cast<std::int16_t>(r.u16());
|
||||
if (r.remaining() == 0) return r.ok(); // 129-octet form before battery
|
||||
if (body.size() == 132) (void)r.u8(); // Former status format included a battery flag byte.
|
||||
s.battery_mv = r.u16();
|
||||
return r.done();
|
||||
}
|
||||
|
||||
// RESULT
|
||||
Bytes encode(const Result& res) {
|
||||
|
||||
// CONFIRM
|
||||
Bytes encode(const Confirm& res) {
|
||||
Writer w;
|
||||
w.u8(static_cast<std::uint8_t>(res.code)); w.u8(static_cast<std::uint8_t>(res.detail.size())); w.bytes(res.detail);
|
||||
return w.out;
|
||||
}
|
||||
bool decode(const Bytes& body, Result& res) {
|
||||
bool decode(const Bytes& body, Confirm& res) {
|
||||
Reader r(body);
|
||||
res.code = static_cast<Code>(r.u8()); res.detail = r.bytes(r.u8());
|
||||
return r.done();
|
||||
|
||||
Reference in New Issue
Block a user