Files
Ashin Walpola d107534eb2 Keep vanetza-idf in obu-firmware, so a plain clone builds the firmware
obu-firmware builds against the vanetza-idf C-ITS library, which until now
came from the colleague's microbu-esp32c5 tree beside the repository and was
not tracked here, so a clone of this repository could not build the firmware
it ships. The library alone is now part of obu-firmware, as
obu-firmware/external/vanetza-idf: their external/vanetza-idf at commit
cf4b99f, unchanged (9775 files; see its PROVENANCE.md). CMake takes it from
there by default; -DVANETZA_IDF_DIR still points the build elsewhere.

The rest of the colleague's tree (their own VAM firmware, PKI tooling,
station-link Python tools, the V2X2MAP bridge) stays out of this repository
and gitignored; nothing is pushed to their repository. NOTES.md, docs/06,
TODO.md and the pcap verifier's usage line point at the new location.
2026-09-24 10:56:05 +02:00

87 lines
2.6 KiB
C++

#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 */