diff --git a/cpu/esp8266/esp-wifi/esp_wifi_netdev.c b/cpu/esp8266/esp-wifi/esp_wifi_netdev.c index 650b4b61af0342ca00e528fa2ae41ceb295852d1..4865b42b8fc35a6bfe347c9977fdee1f8979ec72 100644 --- a/cpu/esp8266/esp-wifi/esp_wifi_netdev.c +++ b/cpu/esp8266/esp-wifi/esp_wifi_netdev.c @@ -197,14 +197,14 @@ static void _esp_wifi_handle_event_cb(System_Event_t *evt) ESP_WIFI_LOG_INFO("connected to ssid %s, channel %d", evt->event_info.connected.ssid, evt->event_info.connected.channel); - _esp_wifi_dev.connected = true; + _esp_wifi_dev.state = ESP_WIFI_CONNECTED; break; case EVENT_STAMODE_DISCONNECTED: ESP_WIFI_LOG_INFO("disconnected from ssid %s, reason %d", evt->event_info.disconnected.ssid, evt->event_info.disconnected.reason); - _esp_wifi_dev.connected = false; + _esp_wifi_dev.state = ESP_WIFI_DISCONNECTED; /* call disconnect to reset internal state */ if (!wifi_station_disconnect()) { @@ -263,7 +263,7 @@ static int _send(netdev_t *netdev, const iolist_t *iolist) esp_wifi_netdev_t *dev = (esp_wifi_netdev_t*)netdev; critical_enter(); - if (!dev->connected) { + if (dev->state != ESP_WIFI_CONNECTED) { ESP_WIFI_DEBUG("WiFi is still not connected to AP, cannot send"); _in_send = false; critical_exit(); @@ -459,7 +459,7 @@ static int _get(netdev_t *netdev, netopt_t opt, void *val, size_t max_len) case NETOPT_LINK_CONNECTED: assert(max_len == 1); - if (dev->connected) { + if (dev->state == ESP_WIFI_CONNECTED) { *((netopt_enable_t *)val) = NETOPT_ENABLE; } else { @@ -544,7 +544,7 @@ static void _esp_wifi_setup(void) /* initialize netdev data structure */ dev->rx_len = 0; - dev->connected = false; + dev->state = ESP_WIFI_DISCONNECTED; mutex_init(&dev->dev_lock); diff --git a/cpu/esp8266/esp-wifi/esp_wifi_netdev.h b/cpu/esp8266/esp-wifi/esp_wifi_netdev.h index 46d0234dd9ac9cc0d3ebc980051688b99d90bd7e..04014ba91b0a63db9389d9695c4b3212f7635c92 100644 --- a/cpu/esp8266/esp-wifi/esp_wifi_netdev.h +++ b/cpu/esp8266/esp-wifi/esp_wifi_netdev.h @@ -20,12 +20,22 @@ #define ESP_WIFI_NETDEV_H #include "net/netdev.h" -#include "lwip/udp.h" +#include "ringbuffer.h" #ifdef __cplusplus extern "C" { #endif +/** + * @brief State of the WiFi interface + */ +typedef enum { + ESP_WIFI_NOT_WORKING, /**< interface is not working correctly */ + ESP_WIFI_DISCONNECTED, /**< interface is not associated to the AP */ + ESP_WIFI_CONNECTING, /**< interface is trying an association to the AP */ + ESP_WIFI_CONNECTED /**< interface is not associated to the AP */ +} esp_wifi_state_t; + /** * @brief Device descriptor for ESP infrastructure mode WIFI device */ @@ -34,15 +44,14 @@ typedef struct netdev_t netdev; /**< netdev parent 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_MAX_LEN]; /**< receive buffer */ uint16_t rx_len; /**< number of bytes received from lwIP */ - bool connected; /**< indicates the connection state to the AP */ - - mutex_t dev_lock; /**< for exclusive access to buffer in receive functions */ + esp_wifi_state_t state; /**< indicates the interface state */ + mutex_t dev_lock; /**< for exclusive access to buffer in + receive functions */ } esp_wifi_netdev_t; #ifdef __cplusplus