2026-04-05 21:04:56 +09:00
|
|
|
#pragma once
|
2026-04-11 08:15:41 +09:00
|
|
|
#include <expected>
|
2026-04-07 21:36:50 +09:00
|
|
|
#include <functional>
|
|
|
|
|
#include <span>
|
2026-04-11 08:15:41 +09:00
|
|
|
#include "eth.h"
|
|
|
|
|
#include "ipv4.h"
|
2026-04-10 22:18:44 +09:00
|
|
|
#include "span_writer.h"
|
2026-04-10 23:02:07 +09:00
|
|
|
#include "msgpack.h"
|
2026-04-11 14:26:53 +09:00
|
|
|
#include "callback_list.h"
|
2026-04-07 07:34:24 +09:00
|
|
|
|
|
|
|
|
struct net_state {
|
2026-04-11 08:15:41 +09:00
|
|
|
eth::mac_addr mac;
|
|
|
|
|
ipv4::ip4_addr ip;
|
2026-04-07 07:34:24 +09:00
|
|
|
};
|
2026-04-05 21:04:56 +09:00
|
|
|
|
2026-04-11 08:15:41 +09:00
|
|
|
using net_handler = std::function<void(std::span<const uint8_t> payload,
|
|
|
|
|
std::function<void(std::span<const uint8_t>)> send)>;
|
|
|
|
|
|
2026-04-11 14:26:53 +09:00
|
|
|
using net_frame_callback = std::function<bool(std::span<const uint8_t> frame)>;
|
|
|
|
|
|
|
|
|
|
struct frame_callback_entry {
|
|
|
|
|
net_frame_callback fn;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using frame_cb_list = callback_list<frame_callback_entry, 16>;
|
|
|
|
|
using frame_cb_handle = frame_cb_list::node*;
|
2026-04-07 21:36:50 +09:00
|
|
|
|
2026-04-05 21:04:56 +09:00
|
|
|
bool net_init();
|
2026-04-07 07:34:24 +09:00
|
|
|
const net_state& net_get_state();
|
2026-04-07 21:36:50 +09:00
|
|
|
void net_set_handler(net_handler handler);
|
2026-04-11 14:26:53 +09:00
|
|
|
frame_cb_handle net_add_frame_callback(net_frame_callback cb);
|
|
|
|
|
void net_remove_frame_callback(frame_cb_handle h);
|
2026-04-10 22:48:28 +09:00
|
|
|
void net_poll(std::span<uint8_t> tx);
|
2026-04-11 08:15:41 +09:00
|
|
|
void net_send_raw(std::span<const uint8_t> data);
|