From 96d0910d339ee314db2d94558f620820e21c46a2 Mon Sep 17 00:00:00 2001
From: Gunar Schorcht <gunar@schorcht.net>
Date: Wed, 23 Jan 2019 10:28:06 +0100
Subject: [PATCH] cpu/esp8266: avoid _esp_wifi_recv_cb during send

To avoid conflicts on receiption of a frame while sending, _esp_wifi_recv_cb should not executed while a frame is in transmission
---
 cpu/esp8266/esp-wifi/esp_wifi_netdev.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/cpu/esp8266/esp-wifi/esp_wifi_netdev.c b/cpu/esp8266/esp-wifi/esp_wifi_netdev.c
index ac923b2001..dd511bf767 100644
--- a/cpu/esp8266/esp-wifi/esp_wifi_netdev.c
+++ b/cpu/esp8266/esp-wifi/esp_wifi_netdev.c
@@ -88,6 +88,9 @@ static const struct station_config station_cfg = {
 
 extern struct netif * eagle_lwip_getif(uint8 index);
 
+/** guard variable to avoid reentrance to _send */
+static bool _in_send = false;
+
 /** guard variable to avoid reentrance to _esp_wifi_recv_cb */
 static bool _in_esp_wifi_recv_cb = false;
 
@@ -112,7 +115,7 @@ void _esp_wifi_recv_cb(struct pbuf *pb, struct netif *netif)
      * by a mutex because `esp_wifi_recv_cb` would be reentered from same
      * thread context.
      */
-    if (_in_esp_wifi_recv_cb) {
+    if (_in_esp_wifi_recv_cb || _in_send) {
         pbuf_free(pb);
         return;
     }
@@ -242,8 +245,6 @@ uint8_t _send_pkt_buf[ETHERNET_MAX_LEN];
 extern err_t ieee80211_output_pbuf(struct netif *netif, struct pbuf *p);
 
 /** guard variable to avoid reentrance to _send */
-static bool _in_send = false;
-
 static int _send(netdev_t *netdev, const iolist_t *iolist)
 {
     ESP_WIFI_DEBUG("%p %p", netdev, iolist);
-- 
GitLab