39 usb_.setReceiver(
this);
40 link_.setFrameReceiver(&down_);
41 TWD_LOGGER.info(
"bridge: host adapter uses MAC %02x:%02x:%02x:%02x:%02x:%02x", link_.macAddress()[0],
42 link_.macAddress()[1], link_.macAddress()[2], link_.macAddress()[3], link_.macAddress()[4],
43 link_.macAddress()[5]);
50 void onFrame(
const uint8_t* frame, uint16_t len)
override {
52 if (memcmp(frame + 6, link_.macAddress(), 6) != 0) {
56 if (link_.sendFrame(frame, len)) {
67 explicit Downstream(
L2Bridge& bridge) : bridge_(bridge) {}
68 void onFrame(
const uint8_t* frame, uint16_t len)
override { bridge_.fromLink(frame, len); }
74 void fromLink(
const uint8_t* frame, uint16_t len) {
76 if (memcmp(frame + 6, link_.macAddress(), 6) == 0) {
80 if (usb_.send(frame, len)) {
Portable abstractions the dongle is built from.
static twd::LoggerClass TWD_LOGGER
The logger used by all components; configure it in the sketch with TWD_LOGGER.begin(Serial).
Raw Ethernet access to the uplink network (bridge mode).
Consumer of Ethernet frames.
Layer-2 bridge between the USB host and the uplink network.
void onFrame(const uint8_t *frame, uint16_t len) override
Host -> uplink (called by the UsbTransport).
void begin()
Start forwarding; both sides must already be started.
L2Bridge(UsbTransport &usb, FrameLink &link)
Bridge usb and link.
Stats stats() const
Current counters.
Moves Ethernet frames between the MCU and the USB host.
uint32_t dropped
frames the other side could not take
uint32_t toHost
frames forwarded uplink -> host
uint32_t toLink
frames forwarded host -> uplink
uint32_t foreign
host frames with a foreign source MAC, dropped
uint32_t reflected
echoes of the host's own frames, dropped