Compare commits
4 Commits
f64cdcaacf
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
30f3eae111 | ||
|
|
71c07957f8 | ||
|
|
a56e034bfb | ||
|
|
2d7ff98b82 |
@@ -6,16 +6,16 @@ add_subdirectory(debug_log)
|
|||||||
add_subdirectory(msgpack)
|
add_subdirectory(msgpack)
|
||||||
add_subdirectory(eth)
|
add_subdirectory(eth)
|
||||||
add_subdirectory(ipv4)
|
add_subdirectory(ipv4)
|
||||||
|
add_subdirectory(arp)
|
||||||
|
add_subdirectory(icmp)
|
||||||
|
add_subdirectory(igmp)
|
||||||
|
add_subdirectory(udp)
|
||||||
|
|
||||||
add_library(limen STATIC
|
add_library(limen STATIC
|
||||||
src/arp.cpp
|
|
||||||
src/dispatch.cpp
|
src/dispatch.cpp
|
||||||
src/flash.cpp
|
src/flash.cpp
|
||||||
src/handlers.cpp
|
src/handlers.cpp
|
||||||
src/icmp.cpp
|
|
||||||
src/igmp.cpp
|
|
||||||
src/test_handlers.cpp
|
src/test_handlers.cpp
|
||||||
src/udp.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(limen PUBLIC
|
target_include_directories(limen PUBLIC
|
||||||
@@ -31,6 +31,10 @@ target_link_libraries(limen PUBLIC
|
|||||||
msgpack
|
msgpack
|
||||||
eth
|
eth
|
||||||
ipv4
|
ipv4
|
||||||
|
arp
|
||||||
|
icmp
|
||||||
|
igmp
|
||||||
|
udp
|
||||||
pico_stdlib
|
pico_stdlib
|
||||||
pico_sha256
|
pico_sha256
|
||||||
)
|
)
|
||||||
|
|||||||
11
arp/CMakeLists.txt
Normal file
11
arp/CMakeLists.txt
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
add_library(arp STATIC arp.cpp)
|
||||||
|
|
||||||
|
target_include_directories(arp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|
||||||
|
target_compile_options(arp PRIVATE -Wall -Wextra -Wno-unused-parameter)
|
||||||
|
|
||||||
|
target_link_libraries(arp PUBLIC
|
||||||
|
util
|
||||||
|
eth
|
||||||
|
ipv4
|
||||||
|
)
|
||||||
@@ -41,8 +41,7 @@ void handle(std::span<const uint8_t> frame, span_writer& tx) {
|
|||||||
eth::send_raw(buf.span());
|
eth::send_raw(buf.span());
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((constructor))
|
void init() {
|
||||||
static void register_ethertype() {
|
|
||||||
eth::register_ethertype(eth::ETH_ARP, handle);
|
eth::register_ethertype(eth::ETH_ARP, handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,6 +19,7 @@ struct __attribute__((packed)) header {
|
|||||||
};
|
};
|
||||||
static_assert(sizeof(header) == 28);
|
static_assert(sizeof(header) == 28);
|
||||||
|
|
||||||
|
void init();
|
||||||
void handle(std::span<const uint8_t> frame, span_writer& tx);
|
void handle(std::span<const uint8_t> frame, span_writer& tx);
|
||||||
|
|
||||||
} // namespace arp
|
} // namespace arp
|
||||||
@@ -61,11 +61,6 @@ void process_frame(std::span<const uint8_t> frame, span_writer& tx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((constructor))
|
|
||||||
void register_default_mac_filter() {
|
|
||||||
register_mac_filter(default_mac_filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void register_ethertype(uint16_t ethertype_be, ethertype_handler fn) {
|
void register_ethertype(uint16_t ethertype_be, ethertype_handler fn) {
|
||||||
@@ -114,6 +109,8 @@ bool init() {
|
|||||||
w6300::open_socket(raw_socket, w6300::protocol::macraw, w6300::sock_flag::none);
|
w6300::open_socket(raw_socket, w6300::protocol::macraw, w6300::sock_flag::none);
|
||||||
w6300::set_interrupt_mask(w6300::ik_sock_0);
|
w6300::set_interrupt_mask(w6300::ik_sock_0);
|
||||||
|
|
||||||
|
register_mac_filter(default_mac_filter);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
11
icmp/CMakeLists.txt
Normal file
11
icmp/CMakeLists.txt
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
add_library(icmp STATIC icmp.cpp)
|
||||||
|
|
||||||
|
target_include_directories(icmp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|
||||||
|
target_compile_options(icmp PRIVATE -Wall -Wextra -Wno-unused-parameter)
|
||||||
|
|
||||||
|
target_link_libraries(icmp PUBLIC
|
||||||
|
util
|
||||||
|
eth
|
||||||
|
ipv4
|
||||||
|
)
|
||||||
@@ -36,8 +36,7 @@ void handle(std::span<const uint8_t> frame, span_writer& tx) {
|
|||||||
eth::send_raw(buf.span());
|
eth::send_raw(buf.span());
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((constructor))
|
void init() {
|
||||||
static void register_protocol() {
|
|
||||||
ipv4::register_protocol(1, handle);
|
ipv4::register_protocol(1, handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -16,6 +16,7 @@ struct __attribute__((packed)) echo {
|
|||||||
};
|
};
|
||||||
static_assert(sizeof(echo) == 8);
|
static_assert(sizeof(echo) == 8);
|
||||||
|
|
||||||
|
void init();
|
||||||
void handle(std::span<const uint8_t> frame, span_writer& tx);
|
void handle(std::span<const uint8_t> frame, span_writer& tx);
|
||||||
|
|
||||||
template <typename Buf>
|
template <typename Buf>
|
||||||
11
igmp/CMakeLists.txt
Normal file
11
igmp/CMakeLists.txt
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
add_library(igmp STATIC igmp.cpp)
|
||||||
|
|
||||||
|
target_include_directories(igmp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|
||||||
|
target_compile_options(igmp PRIVATE -Wall -Wextra -Wno-unused-parameter)
|
||||||
|
|
||||||
|
target_link_libraries(igmp PUBLIC
|
||||||
|
util
|
||||||
|
eth
|
||||||
|
ipv4
|
||||||
|
)
|
||||||
@@ -78,8 +78,7 @@ void handle(std::span<const uint8_t> frame, span_writer& tx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((constructor))
|
void init() {
|
||||||
static void register_protocol() {
|
|
||||||
ipv4::register_protocol(2, handle);
|
ipv4::register_protocol(2, handle);
|
||||||
eth::register_mac_filter(is_member_mac);
|
eth::register_mac_filter(is_member_mac);
|
||||||
ipv4::register_addr_filter(is_member);
|
ipv4::register_addr_filter(is_member);
|
||||||
@@ -17,6 +17,8 @@ struct __attribute__((packed)) message {
|
|||||||
};
|
};
|
||||||
static_assert(sizeof(message) == 8);
|
static_assert(sizeof(message) == 8);
|
||||||
|
|
||||||
|
void init();
|
||||||
|
|
||||||
eth::mac_addr mac_for_ip(const ipv4::ip4_addr& group);
|
eth::mac_addr mac_for_ip(const ipv4::ip4_addr& group);
|
||||||
bool is_member(const ipv4::ip4_addr& ip);
|
bool is_member(const ipv4::ip4_addr& ip);
|
||||||
bool is_member_mac(const eth::mac_addr& mac);
|
bool is_member_mac(const eth::mac_addr& mac);
|
||||||
@@ -31,6 +31,8 @@ bool default_addr_filter(const ip4_addr& dst) {
|
|||||||
void init() {
|
void init() {
|
||||||
const auto& mac = eth::get_mac();
|
const auto& mac = eth::get_mac();
|
||||||
g_ip = {169, 254, mac[4], mac[5]};
|
g_ip = {169, 254, mac[4], mac[5]};
|
||||||
|
eth::register_ethertype(eth::ETH_IPV4, handle);
|
||||||
|
register_addr_filter(default_addr_filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
const ip4_addr& get_ip() {
|
const ip4_addr& get_ip() {
|
||||||
@@ -101,10 +103,4 @@ void handle(std::span<const uint8_t> frame, span_writer& tx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((constructor))
|
|
||||||
static void register_self() {
|
|
||||||
eth::register_ethertype(eth::ETH_IPV4, handle);
|
|
||||||
register_addr_filter(default_addr_filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace ipv4
|
} // namespace ipv4
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
#include "timer_queue.h"
|
#include "timer_queue.h"
|
||||||
#include "eth.h"
|
#include "eth.h"
|
||||||
#include "ipv4.h"
|
#include "ipv4.h"
|
||||||
|
#include "arp.h"
|
||||||
|
#include "icmp.h"
|
||||||
#include "igmp.h"
|
#include "igmp.h"
|
||||||
#include "udp.h"
|
#include "udp.h"
|
||||||
#include "debug_log.h"
|
#include "debug_log.h"
|
||||||
@@ -34,9 +36,13 @@ static void on_udp_message(std::span<const uint8_t> payload, const udp::address&
|
|||||||
|
|
||||||
void dispatch_init(uint16_t port_be) {
|
void dispatch_init(uint16_t port_be) {
|
||||||
listen_port_be = port_be;
|
listen_port_be = port_be;
|
||||||
udp::register_port(port_be, on_udp_message);
|
|
||||||
eth::init();
|
eth::init();
|
||||||
ipv4::init();
|
ipv4::init();
|
||||||
|
arp::init();
|
||||||
|
icmp::init();
|
||||||
|
igmp::init();
|
||||||
|
udp::init();
|
||||||
|
udp::register_port(port_be, on_udp_message);
|
||||||
dispatch_schedule_ms(60000, igmp_reannounce);
|
dispatch_schedule_ms(60000, igmp_reannounce);
|
||||||
dlog("dispatch_init complete");
|
dlog("dispatch_init complete");
|
||||||
}
|
}
|
||||||
|
|||||||
12
udp/CMakeLists.txt
Normal file
12
udp/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
add_library(udp STATIC udp.cpp)
|
||||||
|
|
||||||
|
target_include_directories(udp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|
||||||
|
target_compile_options(udp PRIVATE -Wall -Wextra -Wno-unused-parameter)
|
||||||
|
|
||||||
|
target_link_libraries(udp PUBLIC
|
||||||
|
util
|
||||||
|
eth
|
||||||
|
ipv4
|
||||||
|
debug_log
|
||||||
|
)
|
||||||
@@ -49,8 +49,7 @@ void handle(std::span<const uint8_t> frame, span_writer& tx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((constructor))
|
void init() {
|
||||||
static void register_protocol() {
|
|
||||||
ipv4::register_protocol(17, handle);
|
ipv4::register_protocol(17, handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,6 +36,7 @@ void prepend(Buf& buf, const eth::mac_addr& dst_mac, const eth::mac_addr& src_ma
|
|||||||
ipv4::prepend(buf, dst_mac, src_mac, src_ip, dst_ip, 17, sizeof(header) + payload_len, ttl);
|
ipv4::prepend(buf, dst_mac, src_mac, src_ip, dst_ip, 17, sizeof(header) + payload_len, ttl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void init();
|
||||||
void handle(std::span<const uint8_t> frame, span_writer& tx);
|
void handle(std::span<const uint8_t> frame, span_writer& tx);
|
||||||
|
|
||||||
using port_handler = void (*)(std::span<const uint8_t> payload, const address& from);
|
using port_handler = void (*)(std::span<const uint8_t> payload, const address& from);
|
||||||
Reference in New Issue
Block a user