Self-registering IP-protocol and UDP-port dispatch; move picomap-specific constants out of generic net/dispatch layers
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
#include "prepend_buffer.h"
|
||||
#include "udp.h"
|
||||
|
||||
uint16_t dispatch_listen_port_be();
|
||||
|
||||
struct responder {
|
||||
uint32_t message_id;
|
||||
udp::address reply_to;
|
||||
@@ -22,7 +24,7 @@ struct responder {
|
||||
if (!r) return;
|
||||
buf.append(*r);
|
||||
udp::prepend(buf, reply_to.mac, ns.mac, ns.ip, reply_to.ip,
|
||||
PICOMAP_PORT_BE, reply_to.port, *r);
|
||||
dispatch_listen_port_be(), reply_to.port, *r);
|
||||
net_send_raw(buf.span());
|
||||
}
|
||||
};
|
||||
@@ -52,7 +54,7 @@ void typed_handler(const responder& resp, std::span<const uint8_t> payload) {
|
||||
resp.respond(*result);
|
||||
}
|
||||
|
||||
void dispatch_init();
|
||||
void dispatch_init(uint16_t listen_port_be);
|
||||
timer_handle dispatch_schedule_ms(uint32_t ms, void (*fn)());
|
||||
bool dispatch_cancel_timer(timer_handle h);
|
||||
[[noreturn]] void dispatch_run(std::span<const handler_entry> handlers);
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
#include "dispatch.h"
|
||||
#include "ipv4.h"
|
||||
#include "wire.h"
|
||||
|
||||
inline constexpr uint16_t PICOMAP_PORT_BE = __builtin_bswap16(28781);
|
||||
inline constexpr ipv4::ip4_addr PICOMAP_DISCOVERY_GROUP = {239, 112, 77, 1};
|
||||
|
||||
extern std::string_view firmware_name;
|
||||
|
||||
void handlers_init();
|
||||
|
||||
@@ -16,8 +16,7 @@ struct __attribute__((packed)) echo {
|
||||
};
|
||||
static_assert(sizeof(echo) == 8);
|
||||
|
||||
void handle(std::span<const uint8_t> frame, span_writer& tx,
|
||||
eth::mac_addr our_mac, ipv4::ip4_addr our_ip);
|
||||
void handle(std::span<const uint8_t> frame, span_writer& tx);
|
||||
|
||||
template <typename Buf>
|
||||
void prepend_echo_request(Buf& buf,
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
namespace igmp {
|
||||
|
||||
static constexpr ipv4::ip4_addr PICOMAP_DISCOVERY_GROUP = {239, 112, 77, 1};
|
||||
static constexpr ipv4::ip4_addr ALL_HOSTS = {224, 0, 0, 1};
|
||||
|
||||
struct __attribute__((packed)) message {
|
||||
@@ -22,13 +21,11 @@ eth::mac_addr mac_for_ip(const ipv4::ip4_addr& group);
|
||||
bool is_member(const ipv4::ip4_addr& ip);
|
||||
bool is_member_mac(const eth::mac_addr& mac);
|
||||
|
||||
void join(const ipv4::ip4_addr& group,
|
||||
eth::mac_addr our_mac, ipv4::ip4_addr our_ip);
|
||||
void join(const ipv4::ip4_addr& group);
|
||||
|
||||
void send_all_reports(eth::mac_addr our_mac, ipv4::ip4_addr our_ip);
|
||||
void send_all_reports();
|
||||
|
||||
void handle(std::span<const uint8_t> frame, span_writer& tx,
|
||||
eth::mac_addr our_mac, ipv4::ip4_addr our_ip);
|
||||
void handle(std::span<const uint8_t> frame, span_writer& tx);
|
||||
|
||||
template <typename Buf>
|
||||
void prepend_report(Buf& buf, const eth::mac_addr& src_mac, ipv4::ip4_addr src_ip,
|
||||
|
||||
@@ -59,4 +59,9 @@ void prepend(Buf& buf, const eth::mac_addr& dst_mac, const eth::mac_addr& src_ma
|
||||
|
||||
void handle(std::span<const uint8_t> frame, span_writer& tx);
|
||||
|
||||
bool addressed_to_us(ip4_addr dst);
|
||||
|
||||
using protocol_handler = void (*)(std::span<const uint8_t> frame, span_writer& tx);
|
||||
void register_protocol(uint8_t protocol, protocol_handler fn);
|
||||
|
||||
} // namespace ipv4
|
||||
|
||||
@@ -18,8 +18,6 @@ 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);
|
||||
|
||||
@@ -39,10 +39,7 @@ void prepend(Buf& buf, const eth::mac_addr& dst_mac, const eth::mac_addr& src_ma
|
||||
|
||||
void handle(std::span<const uint8_t> frame, span_writer& tx);
|
||||
|
||||
namespace client {
|
||||
// Defined by the higher layer (dispatch) to receive decoded UDP payloads
|
||||
// addressed to PICOMAP_PORT_BE. Resolved at link time.
|
||||
void handler(std::span<const uint8_t> payload, const address& from);
|
||||
} // namespace client
|
||||
using port_handler = void (*)(std::span<const uint8_t> payload, const address& from);
|
||||
void register_port(uint16_t port_be, port_handler fn);
|
||||
|
||||
} // namespace udp
|
||||
|
||||
Reference in New Issue
Block a user