]> granicus.if.org Git - esp-idf/commitdiff
lwip: optimize low_level_output
authorLiu Zhi Fu <liuzhifu@espressif.com>
Sat, 19 Nov 2016 14:25:30 +0000 (22:25 +0800)
committerLiu Zhi Fu <liuzhifu@espressif.com>
Sat, 19 Nov 2016 14:25:30 +0000 (22:25 +0800)
When the parameter pbuf for low_level_output is a list, malloc a new pbuf of
which the length equals to the total length of pbuf and send the new pbuf to L2

components/lwip/port/netif/wlanif.c

index 3fd2a3192a6beef3cef235481982124dc2b358a2..2c2d75b74dd6d34a60f7153afa8a4fa1028df037 100755 (executable)
@@ -118,37 +118,29 @@ low_level_init(struct netif *netif)
 static err_t
 low_level_output(struct netif *netif, struct pbuf *p)
 {
-  struct pbuf *q;
-  wifi_interface_t wifi_if = tcpip_adapter_get_wifi_if(netif);
+    wifi_interface_t wifi_if = tcpip_adapter_get_wifi_if(netif);
+    struct pbuf *q = p;
+    err_t ret;
+
+    if (wifi_if >= WIFI_IF_MAX) {
+        return ERR_IF;
+    }
 
-  if (wifi_if >= WIFI_IF_MAX) {
-    return ERR_IF;
-  } 
-  
-#if ESP_LWIP
-    q = p;
-    u16_t pbuf_x_len = 0;
-    pbuf_x_len = q->len;
     if(q->next !=NULL)
     {
-        //char cnt = 0;
-        struct pbuf *tmp = q->next;
-        while(tmp != NULL)
-        {
-            memcpy( (u8_t *)( (u8_t *)(q->payload) + pbuf_x_len), (u8_t *)tmp->payload , tmp->len );
-            pbuf_x_len += tmp->len;
-            //cnt++;
-            tmp = tmp->next;
+        LWIP_DEBUGF(PBUF_DEBUG, ("low_level_output: pbuf is a list, application may has bug"));
+        printf("low level_output: len=%d\n", p->tot_len);
+        q = pbuf_alloc(PBUF_RAW_TX, p->tot_len, PBUF_RAM);
+        if (q != NULL) {
+            pbuf_copy(q, p);
+        } else {
+            return ERR_MEM;
         }
     }
-    
-    return esp_wifi_internal_tx(wifi_if, q->payload, pbuf_x_len);
-#else
-    for(q = p; q != NULL; q = q->next) {
-        esp_wifi_internal_tx(wifi_if, q->payload, q->len);
-    }
-  return ERR_OK;
-#endif
+  
+    ret = esp_wifi_internal_tx(wifi_if, q->payload, q->len);
+    pbuf_free(q);
+    return ret; 
 }
 
 /**