2026-04-19 17:28:44 -07:00
|
|
|
#pragma once
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <span>
|
|
|
|
|
#include "eth.h"
|
|
|
|
|
#include "ipv4.h"
|
|
|
|
|
#include "span_writer.h"
|
|
|
|
|
#include "callback_list.h"
|
|
|
|
|
|
2026-05-01 10:15:54 -07:00
|
|
|
namespace net {
|
|
|
|
|
|
|
|
|
|
struct state {
|
2026-04-19 17:28:44 -07:00
|
|
|
eth::mac_addr mac;
|
|
|
|
|
ipv4::ip4_addr ip;
|
|
|
|
|
};
|
|
|
|
|
|
2026-05-01 10:15:54 -07:00
|
|
|
using frame_callback = bool (*)(std::span<const uint8_t> frame);
|
2026-04-19 17:28:44 -07:00
|
|
|
|
2026-05-01 10:15:54 -07:00
|
|
|
using frame_cb_list = callback_list<frame_callback, 16>;
|
2026-04-19 17:28:44 -07:00
|
|
|
using frame_cb_handle = frame_cb_list::node*;
|
|
|
|
|
|
|
|
|
|
using ethertype_handler = void (*)(std::span<const uint8_t> frame, span_writer& tx);
|
2026-05-01 10:15:54 -07:00
|
|
|
using mac_filter = bool (*)(const eth::mac_addr& dst);
|
|
|
|
|
|
|
|
|
|
bool init();
|
|
|
|
|
const state& get_state();
|
|
|
|
|
frame_cb_handle add_frame_callback(frame_callback cb);
|
|
|
|
|
void remove_frame_callback(frame_cb_handle h);
|
|
|
|
|
void poll(std::span<uint8_t> tx);
|
|
|
|
|
void send_raw(std::span<const uint8_t> data);
|
|
|
|
|
void register_ethertype(uint16_t ethertype_be, ethertype_handler fn);
|
|
|
|
|
void register_mac_filter(mac_filter fn);
|
2026-04-19 17:28:44 -07:00
|
|
|
|
2026-05-01 10:15:54 -07:00
|
|
|
} // namespace net
|