30 lines
867 B
C++
30 lines
867 B
C++
#pragma once
|
|
#include <cstdint>
|
|
#include <span>
|
|
#include "eth.h"
|
|
#include "ipv4.h"
|
|
#include "span_writer.h"
|
|
#include "callback_list.h"
|
|
|
|
struct net_state {
|
|
eth::mac_addr mac;
|
|
ipv4::ip4_addr ip;
|
|
};
|
|
|
|
using net_frame_callback = bool (*)(std::span<const uint8_t> frame);
|
|
|
|
using frame_cb_list = callback_list<net_frame_callback, 16>;
|
|
using frame_cb_handle = frame_cb_list::node*;
|
|
|
|
using ethertype_handler = void (*)(std::span<const uint8_t> frame, span_writer& tx);
|
|
|
|
inline constexpr uint16_t PICOMAP_PORT_BE = __builtin_bswap16(28781);
|
|
|
|
bool net_init();
|
|
const net_state& net_get_state();
|
|
frame_cb_handle net_add_frame_callback(net_frame_callback cb);
|
|
void net_remove_frame_callback(frame_cb_handle h);
|
|
void net_poll(std::span<uint8_t> tx);
|
|
void net_send_raw(std::span<const uint8_t> data);
|
|
void net_register_ethertype(uint16_t ethertype_be, ethertype_handler fn);
|