From: Liu Zhi Fu Date: Wed, 16 Nov 2016 08:24:41 +0000 (+0800) Subject: lwip: add option to memcopy packet from L2 to L3 X-Git-Tag: v1.0~51^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=69dbc36a1c9338d5829256c8bf69cffaebbb83a8;p=esp-idf lwip: add option to memcopy packet from L2 to L3 Menuconfig add an option to copy the packet from layer2 (WIFI driver) to layer3 (LWIP), default not copy --- diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index 801fa0b51c..90b7c5b5c7 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -1,5 +1,15 @@ menu "LWIP" +config L2_TO_L3_COPY + bool "Enable copy between Layer2 and Layer3 packets" + default 0 + help + If this feature is enabled, then all traffic from layer2(WIFI Driver) + to layer3(LWIP stack) will make a copy, the layer2 buffer will be + freed and the copy will be sent to layer3. Please make sure you fully + understand this feature before you enable this feature. + + config LWIP_MAX_SOCKETS int "Max number of open sockets" range 1 16 diff --git a/components/lwip/include/lwip/lwip/opt.h b/components/lwip/include/lwip/lwip/opt.h index 51d340e00b..9a1d10afbf 100755 --- a/components/lwip/include/lwip/lwip/opt.h +++ b/components/lwip/include/lwip/lwip/opt.h @@ -3008,6 +3008,13 @@ #define LWIP_PERF 0 #endif +/** + * ESP_L2_TO_L3_COPY: enable memcpy when receiving packet from L2 + */ +#ifndef ESP_L2_TO_L3_COPY +#define ESP_L2_TO_L3_COPY 1 +#endif + #ifndef ESP_THREAD_SAFE_DEBUG #define ESP_THREAD_SAFE_DEBUG 0 #endif diff --git a/components/lwip/include/lwip/port/lwipopts.h b/components/lwip/include/lwip/port/lwipopts.h index d06e756850..26bdc3a4e9 100755 --- a/components/lwip/include/lwip/port/lwipopts.h +++ b/components/lwip/include/lwip/port/lwipopts.h @@ -525,6 +525,7 @@ extern unsigned long os_random(void); #define ESP_RANDOM_TCP_PORT 1 #define ESP_IP4_ATON 1 #define ESP_LIGHT_SLEEP 1 +#define ESP_L2_TO_L3_COPY CONFIG_L2_TO_L3_COPY #define TCP_WND_DEFAULT (4*TCP_MSS) #define TCP_SND_BUF_DEFAULT (2*TCP_MSS) diff --git a/components/lwip/port/netif/wlanif.c b/components/lwip/port/netif/wlanif.c index ffad69cd46..3fd2a3192a 100755 --- a/components/lwip/port/netif/wlanif.c +++ b/components/lwip/port/netif/wlanif.c @@ -161,40 +161,37 @@ low_level_output(struct netif *netif, struct pbuf *p) * @param netif the lwip network interface structure for this ethernetif */ void -#if ESP_LWIP wlanif_input(struct netif *netif, void *buffer, u16_t len, void* eb) -#else -wlanif_input(struct netif *netif, void *buffer, uint16 len) -#endif { struct pbuf *p; -#if ESP_LWIP - if(buffer== NULL) - goto _exit; - if(netif == NULL) + if(!buffer || !netif) goto _exit; -#endif -#if ESP_LWIP +#if (ESP_L2_TO_L3_COPY == 1) + //p = pbuf_alloc(PBUF_IP, len, PBUF_POOL); + p = pbuf_alloc(PBUF_RAW, len, PBUF_RAM); + if (p == NULL) { + #if ESP_PERF + g_rx_alloc_pbuf_fail_cnt++; + #endif + esp_wifi_internal_free_rx_buffer(eb); + return; + } + memcpy(p->payload, buffer, len); + esp_wifi_internal_free_rx_buffer(eb); +#else p = pbuf_alloc(PBUF_RAW, len, PBUF_REF); if (p == NULL){ -#if ESP_PERF - g_rx_alloc_pbuf_fail_cnt++; -#endif - return; + #if ESP_PERF + g_rx_alloc_pbuf_fail_cnt++; + #endif + return; } p->payload = buffer; p->eb = eb; -#else - p = pbuf_alloc(PBUF_IP, len, PBUF_POOL); - if (p == NULL) { - return; - } - memcpy(p->payload, buffer, len); #endif - /* full packet send to tcpip_thread to process */ if (netif->input(p, netif) != ERR_OK) { LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));