]> granicus.if.org Git - esp-idf/commitdiff
lwip: add option to memcopy packet from L2 to L3
authorLiu Zhi Fu <liuzhifu@espressif.com>
Wed, 16 Nov 2016 08:24:41 +0000 (16:24 +0800)
committerLiu Zhi Fu <liuzhifu@espressif.com>
Wed, 16 Nov 2016 08:24:41 +0000 (16:24 +0800)
Menuconfig add an option to copy the packet from layer2 (WIFI driver) to layer3 (LWIP), default not copy

components/lwip/Kconfig
components/lwip/include/lwip/lwip/opt.h
components/lwip/include/lwip/port/lwipopts.h
components/lwip/port/netif/wlanif.c

index 801fa0b51c2ba288b51d87b67d1de288e9947258..90b7c5b5c7fdb87a94c775ac5caea28a2819c064 100644 (file)
@@ -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
index 51d340e00bcfd766bd6c9120941033469ef8a379..9a1d10afbfa0b4af113b27f325e282b2dfbe488e 100755 (executable)
 #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
index d06e75685091ea2e3627259b712089ad6e69c014..26bdc3a4e90d7ffb99660e8960272ab5c50201cd 100755 (executable)
@@ -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)
index ffad69cd46a27674a270ecb76f1443cba89fdf02..3fd2a3192a6beef3cef235481982124dc2b358a2 100755 (executable)
@@ -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"));