diff --git a/arch/xtensa/src/esp32/esp32_wifi_adapter.c b/arch/xtensa/src/esp32/esp32_wifi_adapter.c index 00159f1903..3541e2c1d1 100644 --- a/arch/xtensa/src/esp32/esp32_wifi_adapter.c +++ b/arch/xtensa/src/esp32/esp32_wifi_adapter.c @@ -63,6 +63,7 @@ #include "esp32_wifi_adapter.h" #include "esp32_rt_timer.h" #include "esp32_wifi_utils.h" +#include "esp32_wlan.h" #ifdef CONFIG_PM # include "esp32_pm.h" @@ -2245,11 +2246,23 @@ static void esp_evt_work_cb(void *arg) case WIFI_ADPT_EVT_STA_CONNECT: wlinfo("Wi-Fi sta connect\n"); g_sta_connected = true; + ret = esp32_wlan_sta_set_linkstatus(true); + if (ret < 0) + { + wlerr("ERROR: Failed to set Wi-Fi station link status\n"); + } + break; case WIFI_ADPT_EVT_STA_DISCONNECT: wlinfo("Wi-Fi sta disconnect\n"); g_sta_connected = false; + ret = esp32_wlan_sta_set_linkstatus(false); + if (ret < 0) + { + wlerr("ERROR: Failed to set Wi-Fi station link status\n"); + } + if (g_sta_reconnect) { ret = esp_wifi_connect(); diff --git a/arch/xtensa/src/esp32/esp32_wlan.c b/arch/xtensa/src/esp32/esp32_wlan.c index 161fb9b565..59fe363fff 100644 --- a/arch/xtensa/src/esp32/esp32_wlan.c +++ b/arch/xtensa/src/esp32/esp32_wlan.c @@ -1769,6 +1769,40 @@ static void wlan_softap_tx_done(uint8_t *data, uint16_t *len, bool status) * Public Functions ****************************************************************************/ +/**************************************************************************** + * Name: esp32_wlan_sta_set_linkstatus + * + * Description: + * Set Wi-Fi station link status + * + * Parameters: + * linkstatus - true Notifies the networking layer about an available + * carrier, false Notifies the networking layer about an + * disappeared carrier. + * + * Returned Value: + * OK on success; Negated errno on failure. + * + ****************************************************************************/ + +#ifdef ESP32_WLAN_HAS_STA +int esp32_wlan_sta_set_linkstatus(bool linkstatus) +{ + int ret = -EINVAL; + FAR struct wlan_priv_s *priv = &g_wlan_priv[ESP32_WLAN_STA_DEVNO]; + + if (linkstatus) + { + ret = netdev_carrier_on(&priv->dev); + } + else + { + ret = netdev_carrier_off(&priv->dev); + } + + return ret; +} + /**************************************************************************** * Name: esp32_wlan_sta_initialize * @@ -1783,7 +1817,6 @@ static void wlan_softap_tx_done(uint8_t *data, uint16_t *len, bool status) * ****************************************************************************/ -#ifdef ESP32_WLAN_HAS_STA int esp32_wlan_sta_initialize(void) { int ret; diff --git a/arch/xtensa/src/esp32/esp32_wlan.h b/arch/xtensa/src/esp32/esp32_wlan.h index 1f62689142..70254b98aa 100644 --- a/arch/xtensa/src/esp32/esp32_wlan.h +++ b/arch/xtensa/src/esp32/esp32_wlan.h @@ -61,6 +61,39 @@ extern "C" ****************************************************************************/ #ifdef ESP32_WLAN_HAS_STA + +/**************************************************************************** + * Name: esp32_wlan_sta_set_linkstatus + * + * Description: + * Set Wi-Fi station link status + * + * Parameters: + * linkstatus - true Notifies the networking layer about an available + * carrier, false Notifies the networking layer about an + * disappeared carrier. + * + * Returned Value: + * OK on success; Negated errno on failure. + * + ****************************************************************************/ + +int esp32_wlan_sta_set_linkstatus(bool linkstatus); + +/**************************************************************************** + * Name: esp32_wlan_sta_initialize + * + * Description: + * Initialize the ESP32 WLAN station netcard driver + * + * Input Parameters: + * None + * + * Returned Value: + * OK on success; Negated errno on failure. + * + ****************************************************************************/ + int esp32_wlan_sta_initialize(void); #endif /* ESP32_WLAN_HAS_STA */