esp32/wifi: notify networking layer about the carrier status

This commit is contained in:
Tiago Medicci Serrano 2023-03-29 14:24:22 -03:00 committed by Gustavo Henrique Nihei
parent eb01b66978
commit 89b966a4f5
3 changed files with 80 additions and 1 deletions

View File

@ -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();

View File

@ -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;

View File

@ -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 */