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

76 lines
2.2 KiB
C++

#ifndef TCP_LINK_HPP_A16QFBX3
#define TCP_LINK_HPP_A16QFBX3
#include "link_layer.hpp"
#include <vanetza/common/byte_buffer.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <array>
#include <list>
static constexpr std::size_t layers_ = num_osi_layers(vanetza::OsiLayer::Physical, vanetza::OsiLayer::Application);
class TcpSocket
{
public:
enum Status
{
UNDEFINED = 0,
CONNECTED = 1,
ACCEPTING = 2,
ERROR = 3
};
using IndicationCallback = std::function<void(vanetza::CohesivePacket&&, const vanetza::EthernetHeader&)>;
TcpSocket(boost::asio::io_context&, IndicationCallback*);
void connect(boost::asio::ip::tcp::endpoint);
void request(std::array<boost::asio::const_buffer, layers_>);
void do_receive();
void receive_handler(boost::system::error_code, std::size_t);
std::size_t get_next_packet_size();
void pass_up(vanetza::ByteBuffer&&);
boost::asio::ip::tcp::socket& socket() { return socket_; }
Status status() { return status_; }
void status(Status s) { status_ = s; }
private:
Status status_ = UNDEFINED;
boost::asio::io_context* io_context_;
boost::asio::ip::tcp::endpoint endpoint_;
boost::asio::ip::tcp::socket socket_;
vanetza::ByteBuffer rx_buffer_;
vanetza::ByteBuffer rx_store_;
IndicationCallback* callback_;
};
class TcpLink : public LinkLayer
{
public:
TcpLink(boost::asio::io_context&);
void indicate(IndicationCallback) override;
void request(const vanetza::access::DataRequest&, std::unique_ptr<vanetza::ChunkPacket>) override;
void connect(boost::asio::ip::tcp::endpoint);
void accept(boost::asio::ip::tcp::endpoint);
void accept_handler(boost::system::error_code& ec, boost::asio::ip::tcp::endpoint ep, TcpSocket* sock);
private:
std::list<TcpSocket> sockets_;
std::map<boost::asio::ip::tcp::endpoint, boost::asio::ip::tcp::acceptor> acceptors_;
IndicationCallback callback_;
boost::asio::io_context* io_context_;
std::array<vanetza::ByteBuffer, layers_> tx_buffers_;
std::list<boost::asio::ip::tcp::endpoint> waiting_endpoints_;
};
#endif /* TCP_LINK_HPP_A16QFBX3 */