From b59778f620046d3b7acab72e4b5a29bc2b93d1fa Mon Sep 17 00:00:00 2001 From: wupeifeng Date: Thu, 22 May 2025 03:34:02 +0000 Subject: [PATCH] script: Add Lwip Unknown hook function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit description: 添加lwip私有协议处理函数 Signed-off-by: wupeifeng --- demos/uvp/component/lwip/lwipopts.h | 4 ++++ src/net/adapter/include/lwipopts.h | 4 ++++ src/net/adapter/src/net_register.c | 11 ++++++++++- src/net/lwip_port/arch/net_register.h | 2 ++ testsuites/lwipTest/lwip_udp.c | 8 ++++++++ 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/demos/uvp/component/lwip/lwipopts.h b/demos/uvp/component/lwip/lwipopts.h index 0e8295b3..6b3221a0 100644 --- a/demos/uvp/component/lwip/lwipopts.h +++ b/demos/uvp/component/lwip/lwipopts.h @@ -385,6 +385,10 @@ ing and verifying the IP, UDP, TCP and ICMP checksums by hardware: #define SOCKETS_DEBUG LWIP_DBG_ON #define TCP_DEBUG LWIP_DBG_ON #define HTTPC_DEBUG LWIP_DBG_ON + +int lwip_hook_unknown_eth_protocol(void *p, void *netif); +#define LWIP_HOOK_UNKNOWN_ETH_PROTOCOL(pbuf, netif) lwip_hook_unknown_eth_protocol(pbuf, netif) + #endif /* __LWIPOPTS_H__ */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ \ No newline at end of file diff --git a/src/net/adapter/include/lwipopts.h b/src/net/adapter/include/lwipopts.h index a7a56c69..94d9e29a 100644 --- a/src/net/adapter/include/lwipopts.h +++ b/src/net/adapter/include/lwipopts.h @@ -362,6 +362,10 @@ ing and verifying the IP, UDP, TCP and ICMP checksums by hardware: #define SOCKETS_DEBUG LWIP_DBG_ON #define TCP_DEBUG LWIP_DBG_ON #define HTTPC_DEBUG LWIP_DBG_ON + +int lwip_hook_unknown_eth_protocol(void *p, void *netif); +#define LWIP_HOOK_UNKNOWN_ETH_PROTOCOL(pbuf, netif) lwip_hook_unknown_eth_protocol(pbuf, netif) + #endif /* __LWIPOPTS_H__ */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ \ No newline at end of file diff --git a/src/net/adapter/src/net_register.c b/src/net/adapter/src/net_register.c index 76fd6c98..ab6f95e2 100644 --- a/src/net/adapter/src/net_register.c +++ b/src/net/adapter/src/net_register.c @@ -1,5 +1,6 @@ #include #include +#include #include "prt_typedef.h" #include "arch/net_register.h" @@ -13,4 +14,12 @@ int ethernetif_api_register(struct ethernet_api *api) memcpy(&g_eth_api, api, sizeof(struct ethernet_api)); return OS_OK; -} \ No newline at end of file +} + +int lwip_hook_unknown_eth_protocol(void *p, void *netif) +{ + if(g_eth_api.unknown_hook != NULL){ + return g_eth_api.unknown_hook(p, netif); + } + return ERR_ARG; +} diff --git a/src/net/lwip_port/arch/net_register.h b/src/net/lwip_port/arch/net_register.h index 7e5947bb..dd97e378 100644 --- a/src/net/lwip_port/arch/net_register.h +++ b/src/net/lwip_port/arch/net_register.h @@ -14,12 +14,14 @@ */ #ifndef __RESGISTER_H__ #define __RESGISTER_H__ +#include "lwipopts.h" #include "lwip/netif.h" struct ethernet_api { int (*init)(struct netif* netif); int (*send)(struct netif* netif, const unsigned char *packet, int length); int (*recv)(struct netif* netif, unsigned char *packet, int length); + int (*unknown_hook)(struct pbuf *p, struct netif *netif); }; int ethernetif_api_register(struct ethernet_api *api); diff --git a/testsuites/lwipTest/lwip_udp.c b/testsuites/lwipTest/lwip_udp.c index 4066ce15..df1d8024 100644 --- a/testsuites/lwipTest/lwip_udp.c +++ b/testsuites/lwipTest/lwip_udp.c @@ -136,6 +136,13 @@ static void EthThread(void *arg) } } +// ˽Эջ +void usr_eth_protocol(struct pbuf *p, struct netif *netif) +{ + pbuf_free(p); // Ҫfree pbuf֮󣬲ſɷERR_OK + return ERR_OK; +} + err_t ethernetif_init(struct netif *netif) { LWIP_ASSERT("netif != NULL", (netif != NULL)); @@ -165,6 +172,7 @@ err_t ethernetif_init(struct netif *netif) (void)g_eth_api.init(netif); } + g_eth_api.unknown_hook = usr_eth_protocol; sys_thread_new((char *)"Eth_if", EthThread, &test_netif1, 0x1000, 0x6); etharp_init(); -- Gitee