From 107e196b1836c9b4041f2ef10904ba4357d9defa Mon Sep 17 00:00:00 2001 From: Gunar Schorcht <gunar@schorcht.net> Date: Mon, 21 Jan 2019 16:22:35 +0100 Subject: [PATCH] cpu/esp8266: fix of maximum frame length in esp_wif Since complete MAC frames are handled, ETHERNET_MAX_LEN has to be used instead of ETHERNET_DATA_LEN for receive buffer size and length check. --- cpu/esp8266/esp-wifi/esp_wifi_netdev.c | 13 ++++++++++++- cpu/esp8266/esp-wifi/esp_wifi_netdev.h | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cpu/esp8266/esp-wifi/esp_wifi_netdev.c b/cpu/esp8266/esp-wifi/esp_wifi_netdev.c index 7f705a4e23..66c613e3ef 100644 --- a/cpu/esp8266/esp-wifi/esp_wifi_netdev.c +++ b/cpu/esp8266/esp-wifi/esp_wifi_netdev.c @@ -145,6 +145,17 @@ void _esp_wifi_recv_cb(struct pbuf *pb, struct netif *netif) return; } + /* check whether packet buffer fits into receive buffer */ + if (pb->len > ETHERNET_MAX_LEN) { + ESP_WIFI_DEBUG("frame length is greater than the maximum size of an " + "Ethernet frame (%u > %u)", pb->len, ETHERNET_MAX_LEN); + pbuf_free(pb); + _in_esp_wifi_recv_cb = false; + critical_exit(); + mutex_unlock(&_esp_wifi_dev.dev_lock); + return; + } + /* store the frame in the buffer and free lwIP pbuf */ _esp_wifi_dev.rx_len = pb->tot_len; pbuf_copy_partial(pb, _esp_wifi_dev.rx_buf, _esp_wifi_dev.rx_len, 0); @@ -277,7 +288,7 @@ static int _send(netdev_t *netdev, const iolist_t *iolist) /* limit checks */ if (iol_len > ETHERNET_MAX_LEN) { - ESP_WIFI_DEBUG("frame length exceeds maximum (%u > %u)", + ESP_WIFI_DEBUG("frame length exceeds the maximum (%u > %u)", iol_len, ETHERNET_MAX_LEN); _in_send = false; critical_exit(); diff --git a/cpu/esp8266/esp-wifi/esp_wifi_netdev.h b/cpu/esp8266/esp-wifi/esp_wifi_netdev.h index e25c681a7c..46d0234dd9 100644 --- a/cpu/esp8266/esp-wifi/esp_wifi_netdev.h +++ b/cpu/esp8266/esp-wifi/esp_wifi_netdev.h @@ -36,7 +36,7 @@ typedef struct uint8_t mac[ETHERNET_ADDR_LEN]; /**< MAC address of the device */ ip_addr_t ip; /**< IPv4 address of the device */ - uint8_t rx_buf[ETHERNET_DATA_LEN];/**< receive buffer */ + uint8_t rx_buf[ETHERNET_MAX_LEN]; /**< receive buffer */ uint16_t rx_len; /**< number of bytes received from lwIP */ bool connected; /**< indicates the connection state to the AP */ -- GitLab