Sign ITS messages on the ESP32-C5 with vanetza-idf, over USB or BLE
obu-firmware is now a port of the colleague's standalone VRU station (microbu-esp32c5/firmware, kept beside this repository and gitignored): the vanetza-idf C-ITS stack with the TS 103 097 security entity, credentials in NVS, the station-link v1 protocol over the native USB port (frame type 0x10 in the existing 0xAA55 framing) and over a BLE GATT peripheral, and its ITS-G5 radio adapter. The phone still builds CAM and VAM; the board adds GeoNetworking/BTP and signs with the provisioned authorization ticket. The private key never leaves the board. Builds with ESP-IDF 6.0.2 only, which vanetza-idf pins for the radio's private driver ABI. The previous C firmware stays on disk unbuilt; a full-flash backup of the bench board is kept in firmware-backups/ (gitignored). Changed against the colleague's firmware, marked MicrOBU: in the sources: - Reception unchanged for the app. vanetza-idf drops what it cannot verify (unsigned traffic, every RSU), so each captured frame also goes through the previous gn_unwrap.c and reaches the phone as link opcode V2X_RX (0x85), whose body is the old SERIAL_MSG_V2X_RX payload. - Unsigned transmission still possible, with the previous geonet.c header; the phone chooses per message. - Console on UART0 (CH343 port); the native USB port carries only link frames. - BLE advertising pauses while the USB link is in use: BLE and ITS-G5 share one RF front end. - NVS 80 KB (app at 0x20000). At 24 KB, with Wi-Fi settings the previous firmware left behind, the BLE bond could not be stored and the phone had to pair on every connection. - Bench fixes: the radio queue is drained before the first PoTi (no RX and ~177 queue drops before); the station loop waited pdMS_TO_TICKS(5) = 0 ticks at 100 Hz and starved the idle task; the 2.4 KB RX capture buffer is off the Wi-Fi task stack; BLE notifications longer than the MTU are dropped instead of cut short, MTU 517; serial writes are skipped with no USB host. - Manual country policy and TX-power read-back from the previous radio setup; logs for BLE encryption changes and the number of stored bonds. Verified on the bench board (COM3) with the phone over USB and BLE: CAM and VAM, signed and unsigned, go out; reception of the sim car and the RSU's CAM/SPATEM/MAPEM continues; the board survives app restarts and reconnects. See docs/06-signed-its-vam-ble.md.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
// Dispatches station-link messages (phone -> micrOBU) to the station and sends the
|
||||
// micrOBU -> phone messages (results, indications, identifier-change events, status).
|
||||
#include "link_protocol.hpp"
|
||||
#include "station.hpp"
|
||||
|
||||
namespace microbu {
|
||||
|
||||
/// @brief Represents the transport mechanism for link messages. Either BLE or Serial
|
||||
enum class LinkTransport : std::uint8_t { serial, ble };
|
||||
|
||||
class LinkService {
|
||||
public:
|
||||
/// @brief Binds the service to a station and subscribes to its indication/id-event callbacks.
|
||||
/// @param station Station to bind to; must outlive the LinkService.
|
||||
explicit LinkService(Station& station);
|
||||
/// @brief Decodes and dispatches one received message; call from the station task.
|
||||
/// @param message Raw message bytes as received from the transport.
|
||||
/// @param origin Transport the message arrived on; replies go back on the same transport.
|
||||
void handle(const link::Bytes& message, LinkTransport origin);
|
||||
/// @brief Periodic work: broadcasts STATUS once a second.
|
||||
void tick();
|
||||
private:
|
||||
/// @brief Encodes and writes one message on the given transport.
|
||||
/// @param transport Transport to write to.
|
||||
/// @param opcode Message opcode.
|
||||
/// @param sequence Sequence number to stamp on the header.
|
||||
/// @param body Encoded message body.
|
||||
void send(LinkTransport transport, link::Opcode opcode, std::uint16_t sequence, const link::Bytes& body);
|
||||
/// @brief Sends a message on serial, and also on BLE when a phone is connected.
|
||||
/// @param opcode Message opcode.
|
||||
/// @param sequence Sequence number to stamp on the header.
|
||||
/// @param body Encoded message body.
|
||||
void broadcast(link::Opcode opcode, std::uint16_t sequence, const link::Bytes& body);
|
||||
/// @brief Sends a RESULT reply to the message's origin transport.
|
||||
/// @param origin Transport to reply on.
|
||||
/// @param sequence Sequence number of the message being replied to.
|
||||
/// @param code Result code to report.
|
||||
/// @param detail Optional result detail bytes.
|
||||
void reply(LinkTransport origin, std::uint16_t sequence, link::Code code, const link::Bytes& detail = {});
|
||||
/// @brief Builds a STATUS snapshot from the station and transport counters.
|
||||
/// @return Current status.
|
||||
link::Status status();
|
||||
Station& station_;
|
||||
std::uint16_t own_sequence_ = 0;
|
||||
link::Bytes bundle_; // credentials being provisioned
|
||||
std::uint16_t bundle_total_ = 0;
|
||||
std::int64_t last_status_us_ = 0;
|
||||
};
|
||||
|
||||
} // namespace microbu
|
||||
Reference in New Issue
Block a user