Debug log with dlog_if_slow, MACRAW ping working, wfi disabled
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
#include "net.h"
|
||||
#include <cstring>
|
||||
#include "pico/unique_id.h"
|
||||
#include "pico/time.h"
|
||||
#include "w6300.h"
|
||||
#include "debug_log.h"
|
||||
|
||||
static net_state state;
|
||||
static w6300::socket_id raw_socket{0};
|
||||
@@ -43,8 +45,10 @@ static bool ip_match(const uint8_t* dst) {
|
||||
}
|
||||
|
||||
static void send_raw(const uint8_t* data, size_t len) {
|
||||
w6300::ip_address dummy = {};
|
||||
w6300::sendto(raw_socket, std::span<const uint8_t>{data, len}, dummy, w6300::port_num{0});
|
||||
dlog_if_slow("send_raw", 1000, [&]{
|
||||
w6300::ip_address dummy = {};
|
||||
w6300::sendto(raw_socket, std::span<const uint8_t>{data, len}, dummy, w6300::port_num{0});
|
||||
});
|
||||
}
|
||||
|
||||
static void handle_arp(const uint8_t* frame, size_t len) {
|
||||
@@ -54,6 +58,7 @@ static void handle_arp(const uint8_t* frame, size_t len) {
|
||||
if (read_u16(arp) != 1) return;
|
||||
if (read_u16(arp + 2) != ETHERTYPE_IPV4) return;
|
||||
if (arp[4] != 6 || arp[5] != 4) return;
|
||||
|
||||
if (read_u16(arp + 6) != ARP_OP_REQUEST) return;
|
||||
if (!ip_match(arp + 24)) return;
|
||||
|
||||
@@ -88,6 +93,7 @@ static void handle_icmp(const uint8_t* frame, size_t len) {
|
||||
const uint8_t* icmp = ip + ip_hdr_len;
|
||||
size_t icmp_len = ip_total_len - ip_hdr_len;
|
||||
if (icmp_len < 8) return;
|
||||
|
||||
if (icmp[0] != ICMP_ECHO_REQUEST) return;
|
||||
|
||||
uint8_t reply[1514];
|
||||
@@ -127,9 +133,11 @@ static void handle_ipv4(const uint8_t* frame, size_t len) {
|
||||
|
||||
static void process_frame(const uint8_t* frame, size_t len) {
|
||||
if (len < 14) return;
|
||||
|
||||
if (!mac_match(frame)) return;
|
||||
|
||||
uint16_t ethertype = read_u16(frame + 12);
|
||||
|
||||
switch (ethertype) {
|
||||
case ETHERTYPE_ARP:
|
||||
handle_arp(frame, len);
|
||||
|
||||
Reference in New Issue
Block a user