obu-firmware builds against vanetza-idf from microbu-esp32c5/external, but that tree was gitignored, so a clone of this repository could not build the firmware it ships. It is now committed here as ordinary files in its own folder, microbu-esp32c5/: the colleague's commit cf4b99f plus the V2X2MAP bridge's signature verification (--trust) used on the bench. Nothing is fetched from or pushed to the colleague's repository; this repository and its remotes carry everything. The folder's own .gitignore keeps build output, downloaded components and private key material out, as it did there; the committed file set is identical to that repository's tracked files. The ESP32-C5 is still flashed from obu-firmware/, which only takes vanetza-idf from microbu-esp32c5/, so the two stay separate folders. FLASHING.md says how to take a newer version of the colleague's tree (copy it over the folder, rebuild, test, commit).
95 lines
2.4 KiB
C++
95 lines
2.4 KiB
C++
#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
|