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:
Ashin Walpola
2026-11-11 00:13:57 +01:00
parent 1c3a66e4da
commit 50bbf6552d
10307 changed files with 53622 additions and 850451 deletions
@@ -0,0 +1,12 @@
set(CXX_SOURCES
data_indication.cpp
data_request.cpp
header.cpp
port_dispatcher.cpp
)
add_vanetza_component(btp ${CXX_SOURCES})
target_link_libraries(btp PUBLIC Boost::boost geonet)
add_test_subdirectory(tests)
@@ -0,0 +1,39 @@
#include "data_indication.hpp"
#include "header.hpp"
#include <vanetza/geonet/data_indication.hpp>
namespace vanetza
{
namespace btp
{
DataIndication::DataIndication()
{
}
DataIndication::DataIndication(const geonet::DataIndication& ind, const HeaderA& btp) :
source_port(btp.source_port),
destination_port(btp.destination_port),
destination(ind.destination),
its_aid(ind.its_aid),
permissions(ind.permissions),
source_position(ind.source_position),
traffic_class(ind.traffic_class),
remaining_packet_lifetime(ind.remaining_packet_lifetime)
{
}
DataIndication::DataIndication(const geonet::DataIndication& ind, const HeaderB& btp) :
destination_port(btp.destination_port),
destination_port_info(btp.destination_port_info),
destination(ind.destination),
its_aid(ind.its_aid),
permissions(ind.permissions),
source_position(ind.source_position),
traffic_class(ind.traffic_class),
remaining_packet_lifetime(ind.remaining_packet_lifetime)
{
}
} // namespace btp
} // namespace vanetza
@@ -0,0 +1,39 @@
#ifndef DATA_INDICATION_HPP_5YZM172D
#define DATA_INDICATION_HPP_5YZM172D
#include <vanetza/btp/header.hpp>
#include <vanetza/geonet/address.hpp>
#include <vanetza/geonet/areas.hpp>
#include <vanetza/geonet/data_indication.hpp>
#include <vanetza/geonet/lifetime.hpp>
#include <vanetza/geonet/position_vector.hpp>
#include <vanetza/geonet/traffic_class.hpp>
#include <boost/optional.hpp>
#include <boost/variant.hpp>
namespace vanetza
{
namespace btp
{
struct DataIndication
{
DataIndication();
DataIndication(const geonet::DataIndication&, const HeaderA&);
DataIndication(const geonet::DataIndication&, const HeaderB&);
boost::optional<port_type> source_port;
port_type destination_port;
boost::optional<decltype(HeaderB::destination_port_info)> destination_port_info;
decltype(geonet::DataIndication::destination) destination;
decltype(geonet::DataIndication::its_aid) its_aid;
decltype(geonet::DataIndication::permissions) permissions;
geonet::ShortPositionVector source_position;
geonet::TrafficClass traffic_class;
boost::optional<geonet::Lifetime> remaining_packet_lifetime;
};
} // namespace btp
} // namespace vanetza
#endif /* DATA_INDICATION_HPP_5YZM172D */
@@ -0,0 +1,33 @@
#ifndef DATA_INTERFACE_HPP_HKI9B5SC
#define DATA_INTERFACE_HPP_HKI9B5SC
#include <vanetza/btp/data_indication.hpp>
#include <vanetza/btp/data_request.hpp>
#include <vanetza/common/byte_order.hpp>
#include <vanetza/net/packet.hpp>
#include <memory>
namespace vanetza
{
namespace btp
{
class IndicationInterface
{
public:
virtual void indicate(const DataIndication&, std::unique_ptr<UpPacket>) = 0;
virtual ~IndicationInterface() {};
};
class RequestInterface
{
public:
virtual void request(const DataRequestB&, std::unique_ptr<DownPacket>) = 0;
virtual ~RequestInterface() {};
};
} // namespace btp
} // namespace vanetza
#endif /* DATA_INTERFACE_HPP_HKI9B5SC */
@@ -0,0 +1,21 @@
#include <vanetza/btp/data_request.hpp>
namespace vanetza
{
namespace btp
{
DataRequestA::DataRequestA() :
destination_port(0),
source_port(0)
{
}
DataRequestB::DataRequestB() :
destination_port(0),
destination_port_info(0)
{
}
} // namespace btp
} // namespace vanetza
@@ -0,0 +1,50 @@
#ifndef DATA_REQUEST_HPP_BSJC1VFV
#define DATA_REQUEST_HPP_BSJC1VFV
#include <vanetza/btp/header.hpp>
#include <vanetza/common/its_aid.hpp>
#include <vanetza/geonet/data_request.hpp>
#include <vanetza/geonet/destination_variant.hpp>
#include <vanetza/geonet/interface.hpp>
#include <vanetza/geonet/lifetime.hpp>
#include <vanetza/geonet/traffic_class.hpp>
namespace vanetza
{
namespace btp
{
struct DataRequestGeoNetParams
{
geonet::TransportType transport_type;
geonet::DestinationVariant destination;
geonet::CommunicationProfile communication_profile;
ItsAid its_aid;
boost::optional<geonet::Lifetime> maximum_lifetime;
boost::optional<unsigned> maximum_hop_limit;
boost::optional<geonet::DataRequest::Repetition> repetition;
geonet::TrafficClass traffic_class;
};
struct DataRequestA
{
DataRequestA();
decltype(HeaderA::destination_port) destination_port;
decltype(HeaderA::source_port) source_port;
DataRequestGeoNetParams gn;
};
struct DataRequestB
{
DataRequestB();
decltype(HeaderB::destination_port) destination_port;
decltype(HeaderB::destination_port_info) destination_port_info;
DataRequestGeoNetParams gn;
};
} // namespace btp
} // namespace vanetza
#endif /* DATA_REQUEST_HPP_BSJC1VFV */
+109
View File
@@ -0,0 +1,109 @@
#include "header.hpp"
#include <vanetza/common/serialization.hpp>
#include <vanetza/common/serialization_buffer.hpp>
namespace vanetza
{
namespace btp
{
using vanetza::serialize;
using vanetza::deserialize;
constexpr std::size_t HeaderA::length_bytes;
constexpr std::size_t HeaderB::length_bytes;
void serialize(OutputArchive& ar, const HeaderA& hdr)
{
serialize(ar, hdr.destination_port);
serialize(ar, hdr.source_port);
}
void deserialize(InputArchive& ar, HeaderA& hdr)
{
deserialize(ar, hdr.destination_port);
deserialize(ar, hdr.source_port);
}
void serialize(OutputArchive& ar, const HeaderB& hdr)
{
serialize(ar, hdr.destination_port);
serialize(ar, hdr.destination_port_info);
}
void deserialize(InputArchive& ar, HeaderB& hdr)
{
deserialize(ar, hdr.destination_port);
deserialize(ar, hdr.destination_port_info);
}
HeaderA parse_btp_a(CohesivePacket& packet)
{
HeaderA hdr;
deserialize_from_range(hdr, packet[OsiLayer::Transport]);
packet.set_boundary(OsiLayer::Transport, btp::HeaderA::length_bytes);
return hdr;
}
HeaderA parse_btp_a(ChunkPacket& packet)
{
HeaderA hdr;
ByteBuffer tmp;
packet[OsiLayer::Transport].convert(tmp);
deserialize_from_buffer(hdr, tmp);
return hdr;
}
HeaderA parse_btp_a(PacketVariant& packet)
{
struct parse_btp_visitor : public boost::static_visitor<HeaderA>
{
HeaderA operator()(CohesivePacket& packet) {
return parse_btp_a(packet);
}
HeaderA operator()(ChunkPacket& packet) {
return parse_btp_a(packet);
}
};
parse_btp_visitor visitor;
return boost::apply_visitor(visitor, packet);
}
HeaderB parse_btp_b(CohesivePacket& packet)
{
HeaderB hdr;
deserialize_from_range(hdr, packet[OsiLayer::Transport]);
packet.set_boundary(OsiLayer::Transport, btp::HeaderB::length_bytes);
return hdr;
}
HeaderB parse_btp_b(ChunkPacket& packet)
{
HeaderB hdr;
ByteBuffer tmp;
packet[OsiLayer::Transport].convert(tmp);
deserialize_from_buffer(hdr, tmp);
return hdr;
}
HeaderB parse_btp_b(PacketVariant& packet)
{
struct parse_btp_visitor : public boost::static_visitor<HeaderB>
{
HeaderB operator()(CohesivePacket& packet) {
return parse_btp_b(packet);
}
HeaderB operator()(ChunkPacket& packet) {
return parse_btp_b(packet);
}
};
parse_btp_visitor visitor;
return boost::apply_visitor(visitor, packet);
}
} // namespace btp
} // namespace vanetza
+53
View File
@@ -0,0 +1,53 @@
#ifndef HEADER_HPP_FNKGEM7C
#define HEADER_HPP_FNKGEM7C
#include <vanetza/common/byte_order.hpp>
#include <vanetza/common/serialization.hpp>
#include <vanetza/net/packet_variant.hpp>
#include <cstdint>
namespace vanetza
{
namespace btp
{
typedef uint16be_t port_type;
// interactive packet transport
struct HeaderA
{
static constexpr std::size_t length_bytes = 4;
port_type destination_port;
port_type source_port;
};
static_assert(sizeof(HeaderA) == HeaderA::length_bytes, "Wrong size");
void serialize(OutputArchive&, const HeaderA&);
void deserialize(InputArchive&, HeaderA&);
HeaderA parse_btp_a(ChunkPacket&);
HeaderA parse_btp_a(CohesivePacket&);
HeaderA parse_btp_a(PacketVariant&);
// non-interactive packet transport
struct HeaderB
{
static constexpr std::size_t length_bytes = 4;
port_type destination_port;
uint16be_t destination_port_info;
};
static_assert(sizeof(HeaderB) == HeaderB::length_bytes, "Wrong size");
void serialize(OutputArchive&, const HeaderB&);
void deserialize(InputArchive&, HeaderB&);
HeaderB parse_btp_b(ChunkPacket&);
HeaderB parse_btp_b(CohesivePacket&);
HeaderB parse_btp_b(PacketVariant&);
} // namepsace btp
} // namespace vanetza
#endif /* HEADER_HPP_FNKGEM7C */
@@ -0,0 +1,44 @@
#ifndef HEADER_CONVERSION_HPP_SQVEUMFE
#define HEADER_CONVERSION_HPP_SQVEUMFE
#include <vanetza/btp/header.hpp>
#include <vanetza/common/byte_buffer_convertible.hpp>
#include <vanetza/common/serialization_buffer.hpp>
namespace vanetza
{
namespace convertible
{
template<>
struct byte_buffer_impl<btp::HeaderA> : public byte_buffer
{
byte_buffer_impl(const btp::HeaderA& header) : m_header(header) {}
void convert(ByteBuffer& buffer) const override
{
buffer.clear();
serialize_into_buffer(m_header, buffer);
}
std::size_t size() const override { return btp::HeaderA::length_bytes; }
const btp::HeaderA m_header;
};
template<>
struct byte_buffer_impl<btp::HeaderB> : public byte_buffer
{
byte_buffer_impl(const btp::HeaderB& header) : m_header(header) {}
void convert(ByteBuffer& buffer) const override
{
buffer.clear();
serialize_into_buffer(m_header, buffer);
}
std::size_t size() const override { return btp::HeaderB::length_bytes; }
const btp::HeaderB m_header;
};
} // namespace convertible
} // namespace vanetza
#endif /* HEADER_CONVERSION_HPP_SQVEUMFE */
@@ -0,0 +1,94 @@
#include "port_dispatcher.hpp"
#include "data_indication.hpp"
#include <vanetza/geonet/data_indication.hpp>
#include <algorithm>
#include <cassert>
namespace vanetza
{
namespace btp
{
boost::optional<DataIndication> parse_btp_header(const geonet::DataIndication& gn_ind, PacketVariant& packet)
{
boost::optional<DataIndication> indication;
switch (gn_ind.upper_protocol) {
case geonet::UpperProtocol::BTP_A: {
HeaderA hdr = parse_btp_a(packet);
indication = DataIndication(gn_ind, hdr);
}
break;
case geonet::UpperProtocol::BTP_B: {
HeaderB hdr = parse_btp_b(packet);
indication = DataIndication(gn_ind, hdr);
}
break;
default:
// drop non-BTP packet
break;
}
return indication;
}
void PortDispatcher::add_promiscuous_hook(PromiscuousHook* hook)
{
if (hook != nullptr) {
auto it = std::find(m_promiscuous_hooks.begin(), m_promiscuous_hooks.end(), hook);
if (it == m_promiscuous_hooks.end()) {
m_promiscuous_hooks.push_back(hook);
}
}
}
void PortDispatcher::remove_promiscuous_hook(PromiscuousHook* hook)
{
m_promiscuous_hooks.remove(hook);
}
void PortDispatcher::set_interactive_handler(
port_type port,
IndicationInterface* handler)
{
m_interactive_handlers[port] = handler;
}
void PortDispatcher::set_non_interactive_handler(
port_type port,
IndicationInterface* handler)
{
m_non_interactive_handlers[port] = handler;
}
void PortDispatcher::indicate(
const geonet::DataIndication& gn_ind,
std::unique_ptr<UpPacket> packet)
{
assert(packet);
boost::optional<DataIndication> btp_ind = parse_btp_header(gn_ind, *packet);
IndicationInterface* handler = nullptr;
if (btp_ind) {
if (btp_ind->source_port) {
handler = m_interactive_handlers[btp_ind->destination_port];
} else {
handler = m_non_interactive_handlers[btp_ind->destination_port];
}
for (PromiscuousHook* hook : m_promiscuous_hooks) {
hook->tap_packet(*btp_ind, *packet);
}
if (handler) {
handler->indicate(*btp_ind, std::move(packet));
} else {
hook_undispatched(gn_ind, &btp_ind.get());
}
} else {
hook_undispatched(gn_ind, nullptr);
}
}
} // namespace btp
} // namespace vanetza
@@ -0,0 +1,86 @@
#ifndef PORT_DISPATCHER_HPP_YZ0UTAUF
#define PORT_DISPATCHER_HPP_YZ0UTAUF
#include <vanetza/btp/data_interface.hpp>
#include <vanetza/btp/header.hpp>
#include <vanetza/common/hook.hpp>
#include <vanetza/geonet/transport_interface.hpp>
#include <vanetza/net/packet.hpp>
#include <list>
#include <unordered_map>
namespace vanetza
{
namespace btp
{
class PortDispatcher : public geonet::TransportInterface
{
public:
class PromiscuousHook
{
public:
/**
* Called when a BTP packet is received, regardless of its destination port
* \param indication BTP data indication
* \param packet Read-only view of packet
*/
virtual void tap_packet(const DataIndication&, const UpPacket&) = 0;
virtual ~PromiscuousHook() {}
};
/**
* Register a handler for incoming BTP-A (interactive) packets
* \param port BTP-A destination port
* \param interface Handler for given destination port
* \note Use a nullptr as handler to disable dispatching of destination port
* \note Only one handler can be registered per port
*/
void set_interactive_handler(port_type, IndicationInterface*);
/**
* Register a handler for incoming BTP-B (non-interactive) packets
* \param port BTP-B destination port
* \param interface Handler for given destination port
* \note Use a nullptr as handler to disable dispatching of destination port
* \note Only one handler can be registered per port
*/
void set_non_interactive_handler(port_type, IndicationInterface*);
/**
* Add a hook listening for all incoming BTP packets
* \param hook A hook implementing the promiscuous hook interface
* \note Each registered hook is invoked only once per indication
*/
void add_promiscuous_hook(PromiscuousHook* hook);
/**
* Remove promiscuous hook
* \param hook pointer to previously added hook
*/
void remove_promiscuous_hook(PromiscuousHook*);
// Implementation of geonet::TransportInterface
void indicate(const geonet::DataIndication&, std::unique_ptr<UpPacket>) override;
/**
* Hook invoked for all indicated but undispatched packets
* \note BTP data indication can be nullptr
*/
Hook<const geonet::DataIndication&, const btp::DataIndication*> hook_undispatched;
private:
typedef std::unordered_map<port_type, IndicationInterface*> port_map;
typedef std::list<PromiscuousHook*> hook_list;
port_map m_interactive_handlers;
port_map m_non_interactive_handlers;
hook_list m_promiscuous_hooks;
};
} // namespace btp
} // namespace vanetza
#endif /* PORT_DISPATCHER_HPP_YZ0UTAUF */
+55
View File
@@ -0,0 +1,55 @@
#ifndef PORTS_HPP_T2IEFSSC
#define PORTS_HPP_T2IEFSSC
#include <vanetza/common/byte_order.hpp>
namespace vanetza
{
namespace btp
{
typedef uint16be_t port_type;
namespace ports
{
// Port numbers according to ETSI TS 103 248 v2.4.1 (2024-07)
static const port_type CAM = host_cast<uint16_t>(2001);
static const port_type DENM = host_cast<uint16_t>(2002);
static const port_type TOPO = host_cast<uint16_t>(2003);
static const port_type SPAT = host_cast<uint16_t>(2004);
static const port_type SAM = host_cast<uint16_t>(2005);
static const port_type IVIM = host_cast<uint16_t>(2006);
static const port_type SREM = host_cast<uint16_t>(2007);
static const port_type SSEM = host_cast<uint16_t>(2008);
static const port_type CPM = host_cast<uint16_t>(2009);
static const port_type EVCSN_POI = host_cast<uint16_t>(2010);
static const port_type TRM = host_cast<uint16_t>(2011);
static const port_type TCM = host_cast<uint16_t>(2011);
static const port_type VDRM = host_cast<uint16_t>(2011);
static const port_type VDPM = host_cast<uint16_t>(2011);
static const port_type EOFM = host_cast<uint16_t>(2011);
static const port_type EV_RSR = host_cast<uint16_t>(2012);
static const port_type RTCMEM = host_cast<uint16_t>(2013);
static const port_type CTLM = host_cast<uint16_t>(2014);
static const port_type CRLM = host_cast<uint16_t>(2015);
static const port_type EC_AT_REQUEST = host_cast<uint16_t>(2016);
static const port_type MCDM = host_cast<uint16_t>(2017);
static const port_type VAM = host_cast<uint16_t>(2018);
static const port_type IMZM = host_cast<uint16_t>(2019);
static const port_type DSM = host_cast<uint16_t>(2020);
static const port_type P2P_CRL = host_cast<uint16_t>(2021);
static const port_type P2P_DCTL = host_cast<uint16_t>(2022);
static const port_type MRM = host_cast<uint16_t>(2023);
static const port_type P2P_FCTL = host_cast<uint16_t>(2024);
static const port_type POIM_PA = host_cast<uint16_t>(2025);
static const port_type MIM = host_cast<uint16_t>(2026);
static const port_type MVM = host_cast<uint16_t>(2026);
} // namespace ports
} // namespace btp
} // namespace vanetza
#endif /* PORTS_HPP_T2IEFSSC */