arch/risc-v: refactor Wi-Fi driver for ESP32-C3|C6
Fixes low and inconsistent bandwidth issues. Adds new configuration options for buffer management. Moves code around to make the implementation cleaner and easier to debug. Signed-off-by: Filipe Cavalcanti <filipe.cavalcanti@espressif.com>
This commit is contained in:
parent
9c6d502531
commit
1f7c3a32e5
17 changed files with 4591 additions and 8159 deletions
|
|
@ -1051,6 +1051,35 @@ config ESPRESSIF_WIFI_STATION_SOFTAP
|
|||
|
||||
endchoice # ESPRESSIF_WIFI_MODE
|
||||
|
||||
menu "SoftAP Configuration"
|
||||
depends on ESPRESSIF_WIFI_SOFTAP || ESPRESSIF_WIFI_STATION_SOFTAP
|
||||
|
||||
config ESPRESSIF_WIFI_SOFTAP_DEFAULT_SSID
|
||||
string "SoftAP default SSID"
|
||||
default "NuttX"
|
||||
---help---
|
||||
Represents the default SSID configured for the SoftAP when the device is started.
|
||||
|
||||
config ESPRESSIF_WIFI_SOFTAP_DEFAULT_PASSWORD
|
||||
string "SoftAP default password"
|
||||
default "nuttx12345"
|
||||
---help---
|
||||
Represents the default password configured for the SoftAP when the device is started.
|
||||
|
||||
config ESPRESSIF_WIFI_SOFTAP_MAX_CONNECTIONS
|
||||
int "SoftAP max connections"
|
||||
default 3
|
||||
---help---
|
||||
Maximum number of stations connected to the SoftAP.
|
||||
|
||||
config ESPRESSIF_WIFI_SOFTAP_CHANNEL
|
||||
int "SoftAP channel"
|
||||
default 1
|
||||
---help---
|
||||
Channel number for the SoftAP.
|
||||
|
||||
endmenu # SoftAP Configuration
|
||||
|
||||
config ESPRESSIF_WIFI_ENABLE_WPA3_SAE
|
||||
bool "Enable WPA3-Personal"
|
||||
default y
|
||||
|
|
@ -1088,6 +1117,29 @@ config ESPRESSIF_WIFI_ENABLE_WPA3_OWE_STA
|
|||
PMF (Protected Management Frames) is a prerequisite feature for a WPA3 connection, it needs to be
|
||||
explicitly configured before attempting connection. Please refer to the Wi-Fi Driver API Guide for details.
|
||||
|
||||
choice ESPRESSIF_WIFI_MGMT_RX_BUFFER
|
||||
prompt "Type of WiFi RX MGMT buffers"
|
||||
default ESPRESSIF_WIFI_STATIC_RX_MGMT_BUFFER
|
||||
help
|
||||
Select type of WiFi RX MGMT buffers:
|
||||
|
||||
If "Static" is selected, WiFi RX MGMT buffers are allocated when WiFi is initialized and released
|
||||
when WiFi is de-initialized. The size of each static RX MGMT buffer is fixed to about 500 Bytes.
|
||||
|
||||
If "Dynamic" is selected, each WiFi RX MGMT buffer is allocated as needed when a MGMT data frame is
|
||||
received. The MGMT buffer is freed after the MGMT data frame has been processed by the WiFi driver.
|
||||
|
||||
config ESPRESSIF_WIFI_STATIC_RX_MGMT_BUFFER
|
||||
bool "Static"
|
||||
config ESPRESSIF_WIFI_DYNAMIC_RX_MGMT_BUFFER
|
||||
bool "Dynamic"
|
||||
endchoice
|
||||
|
||||
config ESPRESSIF_WIFI_DYNAMIC_RX_MGMT_BUFFER_TYPE
|
||||
int
|
||||
default 0 if ESPRESSIF_WIFI_STATIC_RX_MGMT_BUFFER
|
||||
default 1 if ESPRESSIF_WIFI_DYNAMIC_RX_MGMT_BUFFER
|
||||
|
||||
config ESPRESSIF_WIFI_STATIC_RX_BUFFER_NUM
|
||||
int "Max number of WiFi static RX buffers"
|
||||
range 2 25 if !ESPRESSIF_ESP32C6
|
||||
|
|
@ -1120,6 +1172,53 @@ config ESPRESSIF_WIFI_DYNAMIC_RX_BUFFER_NUM
|
|||
|
||||
If a dynamic RX buffer limit is set, it should be at least the number of static RX buffers.
|
||||
|
||||
choice ESPRESSIF_WIFI_TX_BUFFER
|
||||
prompt "Type of WiFi TX buffers"
|
||||
default ESPRESSIF_WIFI_DYNAMIC_TX_BUFFER
|
||||
help
|
||||
Select type of WiFi TX buffers:
|
||||
|
||||
If "Static" is selected, WiFi TX buffers are allocated when WiFi is initialized and released
|
||||
when WiFi is de-initialized. The size of each static TX buffer is fixed to about 1.6KB.
|
||||
|
||||
If "Dynamic" is selected, each WiFi TX buffer is allocated as needed when a data frame is
|
||||
delivered to the Wifi driver from the TCP/IP stack. The buffer is freed after the data frame
|
||||
has been sent by the WiFi driver. The size of each dynamic TX buffer depends on the length
|
||||
of each data frame sent by the TCP/IP layer.
|
||||
|
||||
If PSRAM is enabled, "Static" should be selected to guarantee enough WiFi TX buffers.
|
||||
If PSRAM is disabled, "Dynamic" should be selected to improve the utilization of RAM.
|
||||
|
||||
TODO: There is a special dependency for Dynamic if SPIRAM is enabled.
|
||||
|
||||
config ESPRESSIF_WIFI_STATIC_TX_BUFFER
|
||||
bool "Static"
|
||||
config ESPRESSIF_WIFI_DYNAMIC_TX_BUFFER
|
||||
bool "Dynamic"
|
||||
endchoice
|
||||
|
||||
config ESPRESSIF_WIFI_TX_BUFFER_TYPE
|
||||
int
|
||||
default 0 if ESPRESSIF_WIFI_STATIC_TX_BUFFER
|
||||
default 1 if ESPRESSIF_WIFI_DYNAMIC_TX_BUFFER
|
||||
|
||||
config ESPRESSIF_WIFI_STATIC_TX_BUFFER_NUM
|
||||
int "Max number of WiFi static TX buffers"
|
||||
range 2 64
|
||||
default 16
|
||||
---help---
|
||||
Set the number of WiFi static TX buffers. Each buffer takes approximately 1.6KB of RAM.
|
||||
The static RX buffers are allocated when esp_wifi_init() is called, they are not released
|
||||
until esp_wifi_deinit() is called.
|
||||
|
||||
This value might be reduced to save memory if the application does not need to send
|
||||
frames at a high rate.
|
||||
|
||||
For each transmitted data frame from the higher layer TCP/IP stack, the WiFi driver makes a
|
||||
copy of it in a TX buffer. For some applications especially UDP applications, the upper
|
||||
layer can deliver frames faster than WiFi layer can transmit. In these cases, we may run out
|
||||
of TX buffers.
|
||||
|
||||
config ESPRESSIF_WIFI_DYNAMIC_TX_BUFFER_NUM
|
||||
int "Max number of WiFi dynamic TX buffers"
|
||||
range 1 128
|
||||
|
|
@ -1133,6 +1232,14 @@ config ESPRESSIF_WIFI_DYNAMIC_TX_BUFFER_NUM
|
|||
can deliver frames faster than WiFi layer can transmit. In these cases, we may run out of TX
|
||||
buffers.
|
||||
|
||||
config ESPRESSIF_WIFI_RX_MGMT_BUF_NUM_DEF
|
||||
int "Max number of WiFi RX MGMT buffers"
|
||||
range 1 10
|
||||
default 5
|
||||
help
|
||||
Set the number of WiFi RX_MGMT buffers.
|
||||
For Management buffers, the number of dynamic and static management buffers is the same.
|
||||
|
||||
config ESPRESSIF_WIFI_AMPDU_TX_ENABLED
|
||||
bool "Wi-Fi TX AMPDU"
|
||||
default y
|
||||
|
|
@ -1197,10 +1304,10 @@ config ESPRESSIF_WIFI_STA_DISCONNECT_PM
|
|||
Select this option to enable power management for station when disconnected.
|
||||
Chip will do modem-sleep when RF module is not in use anymore.
|
||||
|
||||
choice ESP_POWER_SAVE_MODE
|
||||
choice ESPRESSIF_POWER_SAVE_MODE
|
||||
prompt "Wi-Fi Power save mode"
|
||||
default ESP_POWER_SAVE_MIN_MODEM if ESPRESSIF_WIFI_BT_COEXIST
|
||||
default ESP_POWER_SAVE_NONE
|
||||
default ESPRESSIF_POWER_SAVE_MIN_MODEM if ESPRESSIF_WIFI_BT_COEXIST
|
||||
default ESPRESSIF_POWER_SAVE_NONE
|
||||
---help---
|
||||
Wi-Fi supports the Modem-sleep mode which refers to the legacy power-saving mode in the IEEE 802.11 protocol.
|
||||
Modem-sleep mode works in station-only mode and the station must connect to the AP first. If the Modem-sleep
|
||||
|
|
@ -1218,18 +1325,18 @@ choice ESP_POWER_SAVE_MODE
|
|||
state at DTIM time. If listen interval is longer, more power is saved, but broadcast data is more easy to lose.
|
||||
Listen interval can be configured by setting ESPRESSIF_WIFI_LISTEN_INTERVAL.
|
||||
|
||||
ESP_POWER_SAVE_NONE disables Modem-sleep mode entirely. Disabling it increases power consumption, but
|
||||
ESPRESSIF_POWER_SAVE_NONE disables Modem-sleep mode entirely. Disabling it increases power consumption, but
|
||||
minimizes the delay in receiving Wi-Fi data in real time. When Modem-sleep mode is enabled, the delay in
|
||||
receiving Wi-Fi data may be the same as the DTIM cycle (minimum power-saving mode) or the listening interval
|
||||
(maximum power-saving mode). Setting ESP_POWER_SAVE_NONE is suitable when high throughput is required.
|
||||
(maximum power-saving mode). Setting ESPRESSIF_POWER_SAVE_NONE is suitable when high throughput is required.
|
||||
|
||||
config ESP_POWER_SAVE_NONE
|
||||
config ESPRESSIF_POWER_SAVE_NONE
|
||||
bool "No power save"
|
||||
|
||||
config ESP_POWER_SAVE_MIN_MODEM
|
||||
config ESPRESSIF_POWER_SAVE_MIN_MODEM
|
||||
bool "Minimum modem power saving."
|
||||
|
||||
config ESP_POWER_SAVE_MAX_MODEM
|
||||
config ESPRESSIF_POWER_SAVE_MAX_MODEM
|
||||
bool "Maximum modem power saving"
|
||||
|
||||
endchoice # ESP_POWER_SAVE_MODE
|
||||
|
|
|
|||
|
|
@ -152,8 +152,9 @@ endif
|
|||
|
||||
ifeq ($(CONFIG_ESP_WIRELESS),y)
|
||||
ifeq ($(CONFIG_ESPRESSIF_WIFI),y)
|
||||
CHIP_CSRCS += esp_wifi_init.c
|
||||
CHIP_CSRCS += esp_wlan.c
|
||||
CHIP_CSRCS += esp_wifi_event_handler.c
|
||||
CHIP_CSRCS += esp_wifi_api.c
|
||||
CHIP_CSRCS += esp_wlan_netdev.c
|
||||
endif
|
||||
CHIP_CSRCS += esp_wifi_utils.c
|
||||
endif
|
||||
|
|
@ -186,7 +187,7 @@ endif
|
|||
|
||||
ESP_HAL_3RDPARTY_REPO = esp-hal-3rdparty
|
||||
ifndef ESP_HAL_3RDPARTY_VERSION
|
||||
ESP_HAL_3RDPARTY_VERSION = 98dad3d9b4607df319eca4a7baf50545cda0b1a2
|
||||
ESP_HAL_3RDPARTY_VERSION = 8d7f4177afafdb7941182d8997d3589b1152aec0
|
||||
endif
|
||||
|
||||
ifndef ESP_HAL_3RDPARTY_URL
|
||||
|
|
|
|||
2126
arch/risc-v/src/common/espressif/esp_wifi_api.c
Normal file
2126
arch/risc-v/src/common/espressif/esp_wifi_api.c
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* arch/risc-v/src/esp32c3/esp_wifi_adapter.h
|
||||
* arch/risc-v/src/common/espressif/esp_wifi_api.h
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
|
|
@ -20,144 +20,230 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ARCH_RISCV_SRC_ESP32C3_ESP_WIFI_ADAPTER_H
|
||||
#define __ARCH_RISCV_SRC_ESP32C3_ESP_WIFI_ADAPTER_H
|
||||
#ifndef __ARCH_RISCV_SRC_COMMON_ESPRESSIF_ESP_WIFI_API_H
|
||||
#define __ARCH_RISCV_SRC_COMMON_ESPRESSIF_ESP_WIFI_API_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <nuttx/wireless/wireless.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "esp_wlan.h"
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define SSID_MAX_LEN (32)
|
||||
#define PWD_MAX_LEN (64)
|
||||
|
||||
#define CONFIG_IDF_TARGET_ESP32C3 1
|
||||
#include "esp_wlan_netdev.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_adapter_init
|
||||
* Name: esp_wifi_api_adapter_deinit
|
||||
*
|
||||
* Description:
|
||||
* Initialize ESP32S3 Wi-Fi adapter
|
||||
* De-initialize Wi-Fi adapter, freeing all resources allocated by
|
||||
* esp_wifi_init. Also stops the Wi-Fi task.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 if success or -1 if fail
|
||||
* OK on success; Negated errno on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_adapter_init(void);
|
||||
int esp_wifi_api_adapter_deinit(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_notify_subscribe
|
||||
* Name: esp_wifi_api_adapter_init
|
||||
*
|
||||
* Description:
|
||||
* Enable event notification
|
||||
* Initialize the Wi-Fi driver, control structure, buffers and Wi-Fi task.
|
||||
*
|
||||
* Input Parameters:
|
||||
* pid - Task PID
|
||||
* event - Signal event data pointer
|
||||
* None.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 if success or -1 if fail
|
||||
* OK on success; Negated errno on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_notify_subscribe(pid_t pid, struct sigevent *event);
|
||||
int esp_wifi_api_adapter_init(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_api_start
|
||||
*
|
||||
* Description:
|
||||
* Start Wi-Fi station. This will start the proper Wi-Fi mode based on
|
||||
* the AP/Station configuration.
|
||||
*
|
||||
* Warning: On NuttX, WAPI ifup cannot bring up only one of the modes if
|
||||
* both are enabled on Kconfig. This is a hard limitation.
|
||||
*
|
||||
* Input Parameters:
|
||||
* start_mode - The Wi-Fi mode to start (from wireless.h).
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; Negated errno on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_api_start(uint32_t start_mode);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_api_stop
|
||||
*
|
||||
* Description:
|
||||
* Stops Wi-Fi AP, Station or both. Can be later resumed by
|
||||
* esp_wifi_restore, but must be reconfigured.
|
||||
*
|
||||
* If AP + SoftAP are running, be aware that both will be stopped.
|
||||
*
|
||||
* Input Parameters:
|
||||
* stop_mode - The Wi-Fi mode to stop (from wireless.h).
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; Negated errno on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_api_stop(uint32_t stop_mode);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_api_restore
|
||||
*
|
||||
* Description:
|
||||
* Restore WiFi stack persistent settings to default values.
|
||||
* Make sure to call esp_wifi_set_config, mode after this.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None.
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; Negated errno on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_api_restore(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_api_sta_register_rx_callback
|
||||
*
|
||||
* Description:
|
||||
* Register a callback function for the Wi-Fi station interface.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None.
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; Negated errno on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_api_sta_register_rx_callback(void *cb);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_api_softap_register_rx_callback
|
||||
*
|
||||
* Description:
|
||||
* Register a callback function for the Wi-Fi softAP interface.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None.
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; Negated errno on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_api_softap_register_rx_callback(void *cb);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_api_registe_tx_done_callback
|
||||
*
|
||||
* Description:
|
||||
* Register a callback function for transmission done. Valid for
|
||||
* both station and softAP and needs to be called only once on bringup.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None.
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; Negated errno on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_api_register_tx_done_callback(void *cb);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_api_free_rx_buffer
|
||||
*
|
||||
* Description:
|
||||
* Free the RX buffer allocated by the Wi-Fi driver.
|
||||
*
|
||||
* Input Parameters:
|
||||
* eb - The event buffer to free
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp_wifi_api_free_rx_buffer(void *eb);
|
||||
|
||||
/****************************************************************************
|
||||
* Station functions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef ESP_WLAN_HAS_STA
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_sta_start
|
||||
*
|
||||
* Description:
|
||||
* Start Wi-Fi station.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_start(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_sta_stop
|
||||
*
|
||||
* Description:
|
||||
* Stop Wi-Fi station.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_stop(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_sta_send_data
|
||||
*
|
||||
* Description:
|
||||
* Use Wi-Fi station interface to send 802.3 frame
|
||||
* Use Wi-Fi station interface to send 802.3 frame.
|
||||
*
|
||||
* Input Parameters:
|
||||
* pbuf - Packet buffer pointer
|
||||
* len - Packet length
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
* OK on success; Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_send_data(void *pbuf, size_t len);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_set_password
|
||||
* Name: esp_wifi_sta_read_mac
|
||||
*
|
||||
* Description:
|
||||
* Set/Get Wi-Fi station password
|
||||
* Read station interface MAC address from efuse
|
||||
*
|
||||
* Input Parameters:
|
||||
* mac - MAC address buffer pointer
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 if success or -1 if fail
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_read_mac(uint8_t *mac);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_sta_password
|
||||
*
|
||||
* Description:
|
||||
* Set/Get Wi-Fi station password.
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
* OK on success; Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
@ -171,11 +257,10 @@ int esp_wifi_sta_password(struct iwreq *iwr, bool set);
|
|||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
* OK on success; Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
@ -185,15 +270,14 @@ int esp_wifi_sta_essid(struct iwreq *iwr, bool set);
|
|||
* Name: esp_wifi_sta_bssid
|
||||
*
|
||||
* Description:
|
||||
* Set/Get Wi-Fi station BSSID
|
||||
* Set/Get Wi-Fi station BSSID.
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
* OK on success; Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
@ -203,14 +287,13 @@ int esp_wifi_sta_bssid(struct iwreq *iwr, bool set);
|
|||
* Name: esp_wifi_sta_connect
|
||||
*
|
||||
* Description:
|
||||
* Trigger Wi-Fi station connection action
|
||||
* Trigger Wi-Fi station connection action.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
* OK on success; Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
@ -220,18 +303,17 @@ int esp_wifi_sta_connect(void);
|
|||
* Name: esp_wifi_sta_disconnect
|
||||
*
|
||||
* Description:
|
||||
* Trigger Wi-Fi station disconnection action
|
||||
* Trigger Wi-Fi station disconnection action.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
* None.
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
* OK on success; Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_disconnect(void);
|
||||
int esp_wifi_sta_disconnect(bool allow_reconnect);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_sta_mode
|
||||
|
|
@ -244,8 +326,7 @@ int esp_wifi_sta_disconnect(void);
|
|||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
* OK on success; Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
@ -273,15 +354,14 @@ int esp_wifi_sta_auth(struct iwreq *iwr, bool set);
|
|||
* Name: esp_wifi_sta_freq
|
||||
*
|
||||
* Description:
|
||||
* Get station frequency.
|
||||
* Set/Get station frequency.
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
* OK on success; Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
@ -298,33 +378,33 @@ int esp_wifi_sta_freq(struct iwreq *iwr, bool set);
|
|||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
* OK on success; Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_bitrate(struct iwreq *iwr, bool set);
|
||||
|
||||
#endif /* ESP_WLAN_HAS_STA */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_sta_get_txpower
|
||||
* Name: esp_wifi_sta_txpower
|
||||
*
|
||||
* Description:
|
||||
* Get station transmit power (dBm).
|
||||
* Get/Set station transmit power (dBm).
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
* OK on success; Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_txpower(struct iwreq *iwr, bool set);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_sta_get_channel_range
|
||||
* Name: esp_wifi_sta_channel
|
||||
*
|
||||
* Description:
|
||||
* Get station range of channel parameters.
|
||||
|
|
@ -334,8 +414,7 @@ int esp_wifi_sta_txpower(struct iwreq *iwr, bool set);
|
|||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
* OK on success; Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
@ -352,13 +431,14 @@ int esp_wifi_sta_channel(struct iwreq *iwr, bool set);
|
|||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
* OK on success; Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_country(struct iwreq *iwr, bool set);
|
||||
|
||||
#ifdef ESP_WLAN_HAS_STA
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_sta_rssi
|
||||
*
|
||||
|
|
@ -370,68 +450,53 @@ int esp_wifi_sta_country(struct iwreq *iwr, bool set);
|
|||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
* OK on success; Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_rssi(struct iwreq *iwr, bool set);
|
||||
|
||||
#endif /* ESP_WLAN_HAS_STA */
|
||||
|
||||
/****************************************************************************
|
||||
* SoftAP functions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef ESP_WLAN_HAS_SOFTAP
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_softap_start
|
||||
*
|
||||
* Description:
|
||||
* Start Wi-Fi softAP.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_softap_start(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_softap_stop
|
||||
*
|
||||
* Description:
|
||||
* Stop Wi-Fi softAP.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_softap_stop(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_softap_send_data
|
||||
*
|
||||
* Description:
|
||||
* Use Wi-Fi softAP interface to send 802.3 frame
|
||||
* Use Wi-Fi SoftAP interface to send 802.3 frame
|
||||
*
|
||||
* Input Parameters:
|
||||
* pbuf - Packet buffer pointer
|
||||
* len - Packet length
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
* OK on success; Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_softap_send_data(void *pbuf, size_t len);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_softap_read_mac
|
||||
*
|
||||
* Description:
|
||||
* Read softAP interface MAC address from efuse
|
||||
*
|
||||
* Input Parameters:
|
||||
* mac - MAC address buffer pointer
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 if success or -1 if fail
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_softap_read_mac(uint8_t *mac);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_softap_password
|
||||
*
|
||||
|
|
@ -440,11 +505,10 @@ int esp_wifi_softap_send_data(void *pbuf, size_t len);
|
|||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
* OK on success; Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
@ -461,8 +525,7 @@ int esp_wifi_softap_password(struct iwreq *iwr, bool set);
|
|||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
* OK on success; Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
@ -472,7 +535,7 @@ int esp_wifi_softap_essid(struct iwreq *iwr, bool set);
|
|||
* Name: esp_wifi_softap_bssid
|
||||
*
|
||||
* Description:
|
||||
* Set/Get Wi-Fi softAP BSSID
|
||||
* Set/Get Wi-Fi SoftAP BSSID
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
|
|
@ -490,14 +553,13 @@ int esp_wifi_softap_bssid(struct iwreq *iwr, bool set);
|
|||
* Name: esp_wifi_softap_connect
|
||||
*
|
||||
* Description:
|
||||
* Trigger Wi-Fi softAP accept connection action
|
||||
* Trigger Wi-Fi SoftAP accept connection action.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
* config - The Wi-Fi config to set.
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
* OK on success; Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
@ -507,14 +569,13 @@ int esp_wifi_softap_connect(void);
|
|||
* Name: esp_wifi_softap_disconnect
|
||||
*
|
||||
* Description:
|
||||
* Trigger Wi-Fi softAP drop connection action
|
||||
* Trigger Wi-Fi SoftAP drop connection action
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
* OK on success; Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
@ -531,8 +592,7 @@ int esp_wifi_softap_disconnect(void);
|
|||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
* OK on success; Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
@ -542,7 +602,7 @@ int esp_wifi_softap_mode(struct iwreq *iwr, bool set);
|
|||
* Name: esp_wifi_softap_auth
|
||||
*
|
||||
* Description:
|
||||
* Set/Get authentication mode params.
|
||||
* Set/get authentication mode params.
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
|
|
@ -575,7 +635,7 @@ int esp_wifi_softap_auth(struct iwreq *iwr, bool set);
|
|||
int esp_wifi_softap_freq(struct iwreq *iwr, bool set);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_softap_get_bitrate
|
||||
* Name: esp_wifi_softap_bitrate
|
||||
*
|
||||
* Description:
|
||||
* Get SoftAP default bit rate (Mbps).
|
||||
|
|
@ -585,8 +645,7 @@ int esp_wifi_softap_freq(struct iwreq *iwr, bool set);
|
|||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
* OK on success; Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
@ -603,8 +662,7 @@ int esp_wifi_softap_bitrate(struct iwreq *iwr, bool set);
|
|||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
* OK on success; Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
@ -621,8 +679,7 @@ int esp_wifi_softap_txpower(struct iwreq *iwr, bool set);
|
|||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
* OK on success; Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
@ -639,8 +696,7 @@ int esp_wifi_softap_channel(struct iwreq *iwr, bool set);
|
|||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
* OK on success; Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
@ -657,18 +713,12 @@ int esp_wifi_softap_country(struct iwreq *iwr, bool set);
|
|||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
* OK on success; Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_softap_rssi(struct iwreq *iwr, bool set);
|
||||
|
||||
#endif /* ESP_WLAN_HAS_SOFTAP */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#undef EXTERN
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __ARCH_RISCV_SRC_ESP32C3_ESP_WIFI_ADAPTER_H */
|
||||
#endif /* __ARCH_RISCV_SRC_COMMON_ESPRESSIF_ESP_WIFI_API_H */
|
||||
357
arch/risc-v/src/common/espressif/esp_wifi_event_handler.c
Normal file
357
arch/risc-v/src/common/espressif/esp_wifi_event_handler.c
Normal file
|
|
@ -0,0 +1,357 @@
|
|||
/****************************************************************************
|
||||
* arch/risc-v/src/common/espressif/esp_wifi_event_handler.c
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <debug.h>
|
||||
#include <nuttx/spinlock.h>
|
||||
#include <nuttx/signal.h>
|
||||
|
||||
#include "esp_wifi.h"
|
||||
|
||||
#include "esp_wifi_utils.h"
|
||||
#include "esp_wifi_api.h"
|
||||
|
||||
#ifndef CONFIG_SCHED_LPWORK
|
||||
# error "CONFIG_SCHED_LPWORK must be defined"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* CONFIG_POWER_SAVE_MODEM */
|
||||
|
||||
#if defined(CONFIG_ESPRESSIF_POWER_SAVE_MIN_MODEM)
|
||||
# define DEFAULT_PS_MODE WIFI_PS_MIN_MODEM
|
||||
#elif defined(CONFIG_ESPRESSIF_POWER_SAVE_MAX_MODEM)
|
||||
# define DEFAULT_PS_MODE WIFI_PS_MAX_MODEM
|
||||
#elif defined(CONFIG_ESPRESSIF_POWER_SAVE_NONE)
|
||||
# define DEFAULT_PS_MODE WIFI_PS_NONE
|
||||
#else
|
||||
# define DEFAULT_PS_MODE WIFI_PS_NONE
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/* Wi-Fi event notification private data */
|
||||
|
||||
struct wifi_notify
|
||||
{
|
||||
bool assigned; /* Flag indicate if it is used */
|
||||
pid_t pid; /* Signal's target thread PID */
|
||||
struct sigevent event; /* Signal event private data */
|
||||
struct sigwork_s work; /* Signal work private data */
|
||||
};
|
||||
|
||||
/* Wi-Fi event private data */
|
||||
|
||||
struct evt_adpt
|
||||
{
|
||||
sq_entry_t entry; /* Sequence entry */
|
||||
wifi_event_t id; /* Event ID */
|
||||
uint8_t buf[0]; /* Event private data */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static struct wifi_notify g_wifi_notify[WIFI_EVENT_MAX];
|
||||
static struct work_s g_wifi_evt_work;
|
||||
static sq_queue_t g_wifi_evt_queue;
|
||||
static spinlock_t g_lock;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_reconnect_work_cb
|
||||
*
|
||||
* Description:
|
||||
* Function called by a work queue to reconnect to Wi-Fi in case of
|
||||
* a disconnection event and WIFI_REASON_ASSOC_LEAVE reason.
|
||||
* Must check if the failure_retry_cnt is not 0, otherwise it may
|
||||
* reconnect when not desired, such as when the user has actually
|
||||
* asked to disconnect from the AP.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None.
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void esp_reconnect_work_cb(void *arg)
|
||||
{
|
||||
UNUSED(arg);
|
||||
int ret;
|
||||
wifi_config_t wifi_config;
|
||||
|
||||
esp_wifi_get_config(WIFI_IF_STA, &wifi_config);
|
||||
if (wifi_config.sta.failure_retry_cnt == 0)
|
||||
{
|
||||
wlinfo("Reconnect to Wi-Fi on callback: failure_retry_cnt is 0\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = esp_wifi_sta_connect();
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("Failed to reconnect to Wi-Fi on callback\n");
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_evt_work_cb
|
||||
*
|
||||
* Description:
|
||||
* Process Wi-Fi events.
|
||||
*
|
||||
* Input Parameters:
|
||||
* arg - Not used.
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void esp_evt_work_cb(void *arg)
|
||||
{
|
||||
int ret;
|
||||
irqstate_t flags;
|
||||
struct evt_adpt *evt_adpt;
|
||||
struct wifi_notify *notify;
|
||||
wifi_ps_type_t ps_type = DEFAULT_PS_MODE;
|
||||
|
||||
while (1)
|
||||
{
|
||||
flags = spin_lock_irqsave(&g_lock);
|
||||
evt_adpt = (struct evt_adpt *)sq_remfirst(&g_wifi_evt_queue);
|
||||
spin_unlock_irqrestore(&g_lock, flags);
|
||||
if (!evt_adpt)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
/* Some of the following logic (eg. esp_wlan_sta_set_linkstatus)
|
||||
* can take net_lock(). To maintain the consistent locking order,
|
||||
* we take net_lock() here before taking esp_wifi_lock. Note that
|
||||
* net_lock() is a recursive lock.
|
||||
*/
|
||||
|
||||
net_lock();
|
||||
esp_wifi_lock(true);
|
||||
|
||||
switch (evt_adpt->id)
|
||||
{
|
||||
#ifdef ESP_WLAN_DEVS
|
||||
case WIFI_EVENT_SCAN_DONE:
|
||||
esp_wifi_scan_event_parse();
|
||||
break;
|
||||
#endif
|
||||
case WIFI_EVENT_HOME_CHANNEL_CHANGE:
|
||||
wlinfo("Wi-Fi home channel change\n");
|
||||
break;
|
||||
|
||||
#ifdef ESP_WLAN_HAS_STA
|
||||
case WIFI_EVENT_STA_START:
|
||||
wlinfo("Wi-Fi sta start\n");
|
||||
|
||||
ret = esp_wifi_set_ps(ps_type);
|
||||
if (ret)
|
||||
{
|
||||
wlerr("Failed to set power save type\n");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_STA_STOP:
|
||||
wlinfo("Wi-Fi station stopped\n");
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_STA_CONNECTED:
|
||||
wlinfo("Wi-Fi station connected\n");
|
||||
esp_wlan_sta_connect_success_hook();
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_STA_DISCONNECTED:
|
||||
wifi_event_sta_disconnected_t *event =
|
||||
(wifi_event_sta_disconnected_t *)evt_adpt->buf;
|
||||
wifi_err_reason_t reason = event->reason;
|
||||
|
||||
wlinfo("Wi-Fi station disconnected, reason: %u\n", reason);
|
||||
esp_wlan_sta_disconnect_hook();
|
||||
if (reason == WIFI_REASON_ASSOC_LEAVE)
|
||||
{
|
||||
work_queue(LPWORK, &g_wifi_evt_work, esp_reconnect_work_cb,
|
||||
NULL, 0);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_STA_AUTHMODE_CHANGE:
|
||||
wlinfo("Wi-Fi station auth mode change\n");
|
||||
break;
|
||||
#endif /* ESP_WLAN_HAS_STA */
|
||||
|
||||
#ifdef ESP_WLAN_HAS_SOFTAP
|
||||
case WIFI_EVENT_AP_START:
|
||||
wlinfo("INFO: Wi-Fi softap start\n");
|
||||
esp_wlan_softap_connect_success_hook();
|
||||
ret = esp_wifi_set_ps(ps_type);
|
||||
if (ret)
|
||||
{
|
||||
wlerr("Failed to set power save type\n");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_AP_STOP:
|
||||
wlinfo("Wi-Fi softap stop\n");
|
||||
esp_wlan_softap_disconnect_hook();
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_AP_STACONNECTED:
|
||||
wlinfo("Wi-Fi station joined AP\n");
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_AP_STADISCONNECTED:
|
||||
wlinfo("Wi-Fi station left AP\n");
|
||||
break;
|
||||
#endif /* ESP_WLAN_HAS_SOFTAP */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
notify = &g_wifi_notify[evt_adpt->id];
|
||||
if (notify->assigned)
|
||||
{
|
||||
notify->event.sigev_value.sival_ptr = evt_adpt->buf;
|
||||
|
||||
ret = nxsig_notification(notify->pid, ¬ify->event,
|
||||
SI_QUEUE, ¬ify->work);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlwarn("nxsig_notification event ID=%d failed: %d\n",
|
||||
evt_adpt->id, ret);
|
||||
}
|
||||
}
|
||||
|
||||
esp_wifi_lock(false);
|
||||
net_unlock();
|
||||
|
||||
kmm_free(evt_adpt);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_event_post
|
||||
*
|
||||
* Description:
|
||||
* Posts an event to the event loop system. The event is queued in a FIFO
|
||||
* and processed asynchronously in the low-priority work queue.
|
||||
*
|
||||
* Input Parameters:
|
||||
* event_base - Identifier for the event category (e.g. WIFI_EVENT)
|
||||
* event_id - Event ID within the event base category
|
||||
* event_data - Pointer to event data structure
|
||||
* event_data_size - Size of event data structure
|
||||
* ticks - Number of ticks to wait (currently unused)
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 on success
|
||||
* -1 on failure with following error conditions:
|
||||
* - Invalid event ID
|
||||
* - Memory allocation failure
|
||||
*
|
||||
* Assumptions/Limitations:
|
||||
* - Event data is copied into a new buffer, so the original can be freed
|
||||
* - Events are processed in FIFO order in the low priority work queue
|
||||
* - The function is thread-safe and can be called from interrupt context
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_event_post(const char *event_base,
|
||||
int32_t event_id,
|
||||
void *event_data,
|
||||
size_t event_data_size,
|
||||
uint32_t ticks)
|
||||
{
|
||||
size_t size;
|
||||
int32_t id;
|
||||
irqstate_t flags;
|
||||
struct evt_adpt *evt_adpt;
|
||||
|
||||
wlinfo("Event: base=%s id=%ld data=%p data_size=%u ticks=%lu\n",
|
||||
event_base, event_id, event_data, event_data_size, ticks);
|
||||
|
||||
size = event_data_size + sizeof(struct evt_adpt);
|
||||
evt_adpt = kmm_malloc(size);
|
||||
if (!evt_adpt)
|
||||
{
|
||||
wlerr("ERROR: Failed to alloc %d memory\n", size);
|
||||
return -1;
|
||||
}
|
||||
|
||||
evt_adpt->id = event_id;
|
||||
memcpy(evt_adpt->buf, event_data, event_data_size);
|
||||
|
||||
flags = enter_critical_section();
|
||||
sq_addlast(&evt_adpt->entry, &g_wifi_evt_queue);
|
||||
leave_critical_section(flags);
|
||||
|
||||
work_queue(LPWORK, &g_wifi_evt_work, esp_evt_work_cb, NULL, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_evt_work_init
|
||||
*
|
||||
* Description:
|
||||
* Initialize the event work queue
|
||||
*
|
||||
* Input Parameters:
|
||||
* None.
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp_evt_work_init(void)
|
||||
{
|
||||
sq_init(&g_wifi_evt_queue);
|
||||
}
|
||||
|
|
@ -1,467 +0,0 @@
|
|||
/****************************************************************************
|
||||
* arch/risc-v/src/common/espressif/esp_wifi_init.c
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this args for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <esp_event.h>
|
||||
#include <esp_wifi.h>
|
||||
#include "esp_log.h"
|
||||
#include "esp_private/wifi.h"
|
||||
#include "esp_private/adc_share_hw_ctrl.h"
|
||||
#include "esp_private/sleep_modem.h"
|
||||
#include "esp_sleep.h"
|
||||
#include "esp_private/esp_clk.h"
|
||||
#include "esp_wpa.h"
|
||||
#include "private/esp_coexist_internal.h"
|
||||
#include "esp_phy_init.h"
|
||||
#include "esp_private/phy.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#if (CONFIG_ESPRESSIF_WIFI_RX_BA_WIN > CONFIG_ESPRESSIF_WIFI_DYNAMIC_RX_BUFFER_NUM)
|
||||
#error "WiFi configuration check: WARNING, WIFI_RX_BA_WIN should not be larger than WIFI_DYNAMIC_RX_BUFFER_NUM!"
|
||||
#endif
|
||||
|
||||
#if (CONFIG_ESPRESSIF_WIFI_RX_BA_WIN > (CONFIG_ESPRESSIF_WIFI_STATIC_RX_BUFFER_NUM << 1))
|
||||
#error "WiFi configuration check: WARNING, WIFI_RX_BA_WIN should not be larger than double of the WIFI_STATIC_RX_BUFFER_NUM!"
|
||||
#endif
|
||||
|
||||
#if SOC_PM_SUPPORT_PMU_MODEM_STATE
|
||||
# define WIFI_BEACON_MONITOR_CONFIG_DEFAULT(ena) { \
|
||||
.enable = (ena), \
|
||||
.loss_timeout = CONFIG_ESP_WIFI_SLP_BEACON_LOST_TIMEOUT, \
|
||||
.loss_threshold = CONFIG_ESP_WIFI_SLP_BEACON_LOST_THRESHOLD, \
|
||||
.delta_intr_early = 0, \
|
||||
.delta_loss_timeout = 0, \
|
||||
.beacon_abort = 1, \
|
||||
.broadcast_wakeup = 1, \
|
||||
.tsf_time_sync_deviation = 5, \
|
||||
.modem_state_consecutive = 10, \
|
||||
.rf_ctrl_wait_cycle = 20 \
|
||||
}
|
||||
#else
|
||||
# define WIFI_BEACON_MONITOR_CONFIG_DEFAULT(ena) { \
|
||||
.enable = (ena), \
|
||||
.loss_timeout = CONFIG_ESP_WIFI_SLP_BEACON_LOST_TIMEOUT, \
|
||||
.loss_threshold = CONFIG_ESP_WIFI_SLP_BEACON_LOST_THRESHOLD, \
|
||||
.delta_intr_early = CONFIG_ESP_WIFI_SLP_PHY_ON_DELTA_EARLY_TIME, \
|
||||
.delta_loss_timeout = CONFIG_ESP_WIFI_SLP_PHY_OFF_DELTA_TIMEOUT_TIME \
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Set additional WiFi features and capabilities */
|
||||
|
||||
uint64_t g_wifi_feature_caps =
|
||||
#if CONFIG_ESP_WIFI_ENABLE_WPA3_SAE
|
||||
CONFIG_FEATURE_WPA3_SAE_BIT |
|
||||
#endif
|
||||
#if CONFIG_SPIRAM
|
||||
CONFIG_FEATURE_CACHE_TX_BUF_BIT |
|
||||
#endif
|
||||
#if CONFIG_ESP_WIFI_FTM_INITIATOR_SUPPORT
|
||||
CONFIG_FEATURE_FTM_INITIATOR_BIT |
|
||||
#endif
|
||||
#if CONFIG_ESP_WIFI_FTM_RESPONDER_SUPPORT
|
||||
CONFIG_FEATURE_FTM_RESPONDER_BIT |
|
||||
#endif
|
||||
0;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static void esp_wifi_set_log_level(void);
|
||||
static void esp_wifi_config_info(void);
|
||||
|
||||
extern uint8_t esp_wifi_get_user_init_flag_internal(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
ESP_EVENT_DEFINE_BASE(WIFI_EVENT);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_set_log_level
|
||||
*
|
||||
* Description:
|
||||
* Sets the log level for the ESP32 WiFi module based on preprocessor
|
||||
* definitions. The log level can be verbose, warning, or error.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void esp_wifi_set_log_level(void)
|
||||
{
|
||||
wifi_log_level_t wifi_log_level = WIFI_LOG_NONE;
|
||||
|
||||
/* set WiFi log level */
|
||||
|
||||
#if defined(CONFIG_DEBUG_WIRELESS_INFO)
|
||||
wifi_log_level = WIFI_LOG_VERBOSE;
|
||||
#elif defined(CONFIG_DEBUG_WIRELESS_WARN)
|
||||
wifi_log_level = WIFI_LOG_WARNING;
|
||||
#elif defined(CONFIG_LOG_MAXIMUM_LEVEL)
|
||||
wifi_log_level = WIFI_LOG_ERROR;
|
||||
#endif
|
||||
|
||||
esp_wifi_internal_set_log_level(wifi_log_level);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_config_info
|
||||
*
|
||||
* Description:
|
||||
* This function logs the current configuration settings for the Wi-Fi
|
||||
* module. It checks for various configuration options and logs if they
|
||||
* are enabled.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void esp_wifi_config_info(void)
|
||||
{
|
||||
#ifdef CONFIG_ESPRESSIF_WIFI_RX_BA_WIN
|
||||
wlinfo("rx ba win: %d", CONFIG_ESPRESSIF_WIFI_RX_BA_WIN);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP
|
||||
wlinfo("WiFi/LWIP prefer SPIRAM");
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ESP_WIFI_IRAM_OPT
|
||||
wlinfo("WiFi IRAM OP enabled");
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ESP_WIFI_RX_IRAM_OPT
|
||||
wlinfo("WiFi RX IRAM OP enabled");
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ESP_WIFI_SLP_IRAM_OPT
|
||||
wlinfo("WiFi SLP IRAM OP enabled");
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LWIP_IRAM_OPTIMIZATION
|
||||
wlinfo("LWIP IRAM OP enabled");
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_ESP_WIFI_FTM_ENABLE
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ieee80211_ftm_attach
|
||||
*
|
||||
* Description:
|
||||
* This function initializes and attaches the Fine Timing Measurement (FTM)
|
||||
* capabilities to the IEEE 802.11 Wi-Fi driver. FTM is used for precise
|
||||
* distance measurements between Wi-Fi devices.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void ieee80211_ftm_attach(void)
|
||||
{
|
||||
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ESP_WIFI_SOFTAP_SUPPORT
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net80211_softap_funcs_init
|
||||
*
|
||||
* Description:
|
||||
* This function is a placeholder for initializing the SoftAP (Software
|
||||
* Access Point) functionalities of the IEEE 802.11 Wi-Fi driver. It is
|
||||
* only compiled if the CONFIG_ESP_WIFI_SOFTAP_SUPPORT configuration
|
||||
* option is not set.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void net80211_softap_funcs_init(void)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ESP_WIFI_NAN_ENABLE
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nan_start
|
||||
*
|
||||
* Description:
|
||||
* This function is a stub to overwrite a weak link in the Wi-Fi library.
|
||||
* It is used to start the NAN (Neighbor Awareness Networking) service.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* Always returns ESP_OK.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
esp_err_t nan_start(void)
|
||||
{
|
||||
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nan_stop
|
||||
*
|
||||
* Description:
|
||||
* This function is a stub to overwrite a weak link in the Wi-Fi library.
|
||||
* It is used to stop the NAN (Neighbor Awareness Networking) service.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* Always returns ESP_OK.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
esp_err_t nan_stop(void)
|
||||
{
|
||||
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nan_input
|
||||
*
|
||||
* Description:
|
||||
* This function is a stub to overwrite a weak link in the Wi-Fi library.
|
||||
* It is used to handle input for the NAN (Neighbor Awareness Networking)
|
||||
* service.
|
||||
*
|
||||
* Input Parameters:
|
||||
* p1 - First parameter for the input function.
|
||||
* p2 - Second parameter for the input function.
|
||||
* p3 - Third parameter for the input function.
|
||||
*
|
||||
* Returned Value:
|
||||
* Always returns 0.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int nan_input(void *p1, int p2, int p3)
|
||||
{
|
||||
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nan_sm_handle_event
|
||||
*
|
||||
* Description:
|
||||
* This function is a stub to overwrite a weak link in the Wi-Fi library.
|
||||
* It is used to handle events for the NAN (Neighbor Awareness Networking)
|
||||
* service state machine.
|
||||
*
|
||||
* Input Parameters:
|
||||
* p1 - First parameter for the event handler.
|
||||
* p2 - Second parameter for the event handler.
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void nan_sm_handle_event(void *p1, int p2)
|
||||
{
|
||||
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_deinit
|
||||
*
|
||||
* Description:
|
||||
* Deinitialize Wi-Fi and free resource
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Values: esp_err_t
|
||||
* Zero (OK) is returned or a negative error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
esp_err_t esp_wifi_deinit(void)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
#ifdef CONFIG_ESP_WIFI_SLP_BEACON_LOST_OPT
|
||||
wifi_beacon_monitor_config_t monitor_config;
|
||||
#endif
|
||||
|
||||
if (esp_wifi_get_user_init_flag_internal())
|
||||
{
|
||||
wlerr("Wi-Fi not stop");
|
||||
return ESP_ERR_WIFI_NOT_STOPPED;
|
||||
}
|
||||
|
||||
if (esp_wifi_internal_reg_rxcb(WIFI_IF_STA, NULL) != ESP_OK ||
|
||||
esp_wifi_internal_reg_rxcb(WIFI_IF_AP, NULL) != ESP_OK)
|
||||
{
|
||||
wlerr("Failed to unregister Rx callbacks");
|
||||
}
|
||||
|
||||
esp_supplicant_deinit();
|
||||
err = esp_wifi_deinit_internal();
|
||||
if (err != ESP_OK)
|
||||
{
|
||||
wlerr("Failed to deinit Wi-Fi driver (0x%x)", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_ESP_WIFI_SLP_BEACON_LOST_OPT
|
||||
monitor_config = WIFI_BEACON_MONITOR_CONFIG_DEFAULT(false);
|
||||
esp_wifi_beacon_monitor_configure(&monitor_config);
|
||||
#endif
|
||||
|
||||
#if CONFIG_MAC_BB_PD
|
||||
esp_unregister_mac_bb_pd_callback(pm_mac_sleep);
|
||||
esp_unregister_mac_bb_pu_callback(pm_mac_wakeup);
|
||||
#endif
|
||||
esp_wifi_power_domain_off();
|
||||
#if CONFIG_MAC_BB_PD
|
||||
esp_wifi_internal_set_mac_sleep(false);
|
||||
esp_mac_bb_pd_mem_deinit();
|
||||
#endif
|
||||
esp_phy_modem_deinit();
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_init
|
||||
*
|
||||
* Description:
|
||||
* Initialize Wi-Fi
|
||||
*
|
||||
* Input Parameters:
|
||||
* config - Initialization config parameters
|
||||
*
|
||||
* Returned Values: esp_err_t
|
||||
* Zero (OK) is returned or a negative error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
esp_err_t esp_wifi_init(const wifi_init_config_t *config)
|
||||
{
|
||||
esp_err_t result = ESP_OK;
|
||||
#ifdef CONFIG_ESP_WIFI_SLP_BEACON_LOST_OPT
|
||||
wifi_beacon_monitor_config_t monitor_config;
|
||||
#endif
|
||||
|
||||
if ((config->feature_caps & CONFIG_FEATURE_CACHE_TX_BUF_BIT) &&
|
||||
(WIFI_CACHE_TX_BUFFER_NUM == 0))
|
||||
{
|
||||
wlerr("Number of WiFi cache TX buffers should not equal 0 when"
|
||||
"enable SPIRAM");
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
esp_wifi_power_domain_on();
|
||||
|
||||
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
|
||||
coex_init();
|
||||
#endif
|
||||
esp_wifi_set_log_level();
|
||||
|
||||
result = esp_wifi_init_internal(config);
|
||||
if (result == ESP_OK)
|
||||
{
|
||||
#if CONFIG_MAC_BB_PD
|
||||
esp_mac_bb_pd_mem_init();
|
||||
esp_wifi_internal_set_mac_sleep(true);
|
||||
#endif
|
||||
esp_phy_modem_init();
|
||||
|
||||
result = esp_supplicant_init();
|
||||
if (result != ESP_OK)
|
||||
{
|
||||
esp_err_t deinit_ret;
|
||||
|
||||
wlerr("Failed to init supplicant (0x%x)", result);
|
||||
|
||||
deinit_ret = esp_wifi_deinit();
|
||||
if (deinit_ret != ESP_OK)
|
||||
{
|
||||
wlerr("Failed to deinit Wi-Fi (0x%x)", deinit_ret);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
#if CONFIG_ESP_WIFI_SLP_BEACON_LOST_OPT
|
||||
monitor_config = WIFI_BEACON_MONITOR_CONFIG_DEFAULT(true);
|
||||
esp_wifi_beacon_monitor_configure(&monitor_config);
|
||||
#endif
|
||||
adc2_cal_include(); /* This enables the ADC2 calibration constructor at start up */
|
||||
|
||||
esp_wifi_config_info();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -34,24 +34,13 @@
|
|||
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/wireless/wireless.h>
|
||||
#include <nuttx/spinlock.h>
|
||||
|
||||
#ifdef CONFIG_ESPRESSIF_WIFI
|
||||
#include "esp_wifi_adapter.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "esp_mac.h"
|
||||
#include "esp_private/phy.h"
|
||||
#include "esp_private/wifi.h"
|
||||
#include "esp_random.h"
|
||||
#include "esp_timer.h"
|
||||
#include "esp_wpa.h"
|
||||
#include "rom/ets_sys.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#endif /* CONFIG_ESPRESSIF_WIFI */
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_wifi_utils.h"
|
||||
#include "esp_wlan_netdev.h"
|
||||
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_wifi_types_generic.h"
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -75,18 +64,6 @@
|
|||
|
||||
#define CHANNEL_MAX_NUM (14)
|
||||
|
||||
/* CONFIG_POWER_SAVE_MODEM */
|
||||
|
||||
#if defined(CONFIG_ESP_POWER_SAVE_MIN_MODEM)
|
||||
# define DEFAULT_PS_MODE WIFI_PS_MIN_MODEM
|
||||
#elif defined(CONFIG_ESP_POWER_SAVE_MAX_MODEM)
|
||||
# define DEFAULT_PS_MODE WIFI_PS_MAX_MODEM
|
||||
#elif defined(CONFIG_ESP_POWER_SAVE_NONE)
|
||||
# define DEFAULT_PS_MODE WIFI_PS_NONE
|
||||
#else
|
||||
# define DEFAULT_PS_MODE WIFI_PS_NONE
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
|
@ -112,20 +89,6 @@ struct wifi_scan_result
|
|||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/* Wi-Fi interface configuration */
|
||||
|
||||
#ifdef ESP_WLAN_HAS_STA
|
||||
|
||||
extern wifi_config_t g_sta_wifi_cfg;
|
||||
|
||||
#endif /* ESP_WLAN_HAS_STA */
|
||||
|
||||
#ifdef ESP_WLAN_HAS_SOFTAP
|
||||
|
||||
extern wifi_config_t g_softap_wifi_cfg;
|
||||
|
||||
#endif /* ESP_WLAN_HAS_SOFTAP */
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
|
@ -137,11 +100,7 @@ static struct wifi_scan_result g_scan_priv =
|
|||
static uint8_t g_channel_num;
|
||||
static uint8_t g_channel_list[CHANNEL_MAX_NUM];
|
||||
|
||||
static struct wifi_notify g_wifi_notify[WIFI_ADPT_EVT_MAX];
|
||||
static struct work_s g_wifi_evt_work;
|
||||
static sq_queue_t g_wifi_evt_queue;
|
||||
static mutex_t g_wifiexcl_lock = NXMUTEX_INITIALIZER;
|
||||
static spinlock_t g_lock;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
|
|
@ -149,6 +108,99 @@ static spinlock_t g_lock;
|
|||
|
||||
#ifdef CONFIG_ESPRESSIF_WIFI
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_mode_translate
|
||||
*
|
||||
* Description:
|
||||
* Translate wireless mode constants to ESP Wi-Fi mode constants.
|
||||
*
|
||||
* Input Parameters:
|
||||
* wireless_mode - Wireless mode from wireless.h (IW_MODE_*)
|
||||
*
|
||||
* Returned Value:
|
||||
* ESP Wi-Fi mode (WIFI_MODE_*) on success
|
||||
* -EINVAL on failure
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
wifi_mode_t esp_wifi_mode_translate(uint32_t wireless_mode)
|
||||
{
|
||||
switch (wireless_mode)
|
||||
{
|
||||
case IW_MODE_INFRA:
|
||||
return WIFI_MODE_STA;
|
||||
|
||||
case IW_MODE_MASTER:
|
||||
return WIFI_MODE_AP;
|
||||
|
||||
default:
|
||||
wlerr("Invalid wireless mode=%ld\n", wireless_mode);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_freq_to_channel
|
||||
*
|
||||
* Description:
|
||||
* Converts Wi-Fi frequency to channel.
|
||||
*
|
||||
* Input Parameters:
|
||||
* freq - Wi-Fi frequency
|
||||
*
|
||||
* Returned Value:
|
||||
* Wi-Fi channel
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_freq_to_channel(uint16_t freq)
|
||||
{
|
||||
int channel = 0;
|
||||
if (freq >= 2412 && freq <= 2484)
|
||||
{
|
||||
if (freq == 2484)
|
||||
{
|
||||
channel = 14;
|
||||
}
|
||||
else
|
||||
{
|
||||
channel = freq - 2407;
|
||||
if (channel % 5)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
channel /= 5;
|
||||
}
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
if (freq >= 5005 && freq < 5900)
|
||||
{
|
||||
if (freq % 5)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
channel = (freq - 5000) / 5;
|
||||
return channel;
|
||||
}
|
||||
|
||||
if (freq >= 4905 && freq < 5000)
|
||||
{
|
||||
if (freq % 5)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
channel = (freq - 4000) / 5;
|
||||
return channel;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_start_scan
|
||||
*
|
||||
|
|
@ -172,8 +224,8 @@ int esp_wifi_start_scan(struct iwreq *iwr)
|
|||
int ret = 0;
|
||||
int i;
|
||||
uint8_t target_mac[MAC_LEN];
|
||||
uint8_t target_ssid[SSID_MAX_LEN + 1];
|
||||
memset(target_ssid, 0x0, sizeof(SSID_MAX_LEN + 1));
|
||||
uint8_t target_ssid[IW_ESSID_MAX_SIZE + 1];
|
||||
memset(target_ssid, 0x0, sizeof(IW_ESSID_MAX_SIZE + 1));
|
||||
|
||||
if (iwr == NULL)
|
||||
{
|
||||
|
|
@ -251,7 +303,6 @@ int esp_wifi_start_scan(struct iwreq *iwr)
|
|||
config->scan_type = WIFI_SCAN_TYPE_ACTIVE; /* Active scan */
|
||||
}
|
||||
|
||||
esp_wifi_start();
|
||||
ret = esp_wifi_scan_start(config, false);
|
||||
if (ret != OK)
|
||||
{
|
||||
|
|
@ -296,10 +347,10 @@ int esp_wifi_start_scan(struct iwreq *iwr)
|
|||
* Name: esp_wifi_get_scan_results
|
||||
*
|
||||
* Description:
|
||||
* Get scan result
|
||||
* Get Wi-Fi scan results.
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* iwr - The argument of the ioctl cmd.
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
|
|
@ -400,13 +451,13 @@ exit_failed:
|
|||
* Name: esp_wifi_scan_event_parse
|
||||
*
|
||||
* Description:
|
||||
* Parse scan information
|
||||
* Parse scan information Wi-Fi AP scan results.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
* None.
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
@ -495,7 +546,8 @@ void esp_wifi_scan_event_parse(void)
|
|||
/* Copy ESSID */
|
||||
|
||||
essid_len = MIN(strlen((const char *)
|
||||
ap_list_buffer[bss_count].ssid), SSID_MAX_LEN);
|
||||
ap_list_buffer[bss_count].ssid),
|
||||
IW_ESSID_MAX_SIZE);
|
||||
essid_len_aligned = (essid_len + 3) & -4;
|
||||
if (result_size < ESP_IW_EVENT_SIZE(essid) + essid_len_aligned)
|
||||
{
|
||||
|
|
@ -624,10 +676,10 @@ scan_result_full:
|
|||
* Name: esp_wifi_to_errno
|
||||
*
|
||||
* Description:
|
||||
* Transform from ESP Wi-Fi error code to NuttX error code
|
||||
* Transform from ESP Wi-Fi error code to NuttX error code.
|
||||
*
|
||||
* Input Parameters:
|
||||
* err - ESP Wi-Fi error code
|
||||
* err - ESP Wi-Fi error code.
|
||||
*
|
||||
* Returned Value:
|
||||
* NuttX error code defined in errno.h
|
||||
|
|
@ -699,77 +751,6 @@ int32_t esp_wifi_to_errno(int err)
|
|||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_event_id_map
|
||||
*
|
||||
* Description:
|
||||
* Transform from esp-idf event ID to Wi-Fi adapter event ID
|
||||
*
|
||||
* Input Parameters:
|
||||
* event_id - esp-idf event ID
|
||||
*
|
||||
* Returned Value:
|
||||
* Wi-Fi adapter event ID
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_event_id_map(int event_id)
|
||||
{
|
||||
int id;
|
||||
|
||||
switch (event_id)
|
||||
{
|
||||
case WIFI_EVENT_SCAN_DONE:
|
||||
id = WIFI_ADPT_EVT_SCAN_DONE;
|
||||
break;
|
||||
|
||||
#ifdef ESP_WLAN_HAS_STA
|
||||
case WIFI_EVENT_STA_START:
|
||||
id = WIFI_ADPT_EVT_STA_START;
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_STA_CONNECTED:
|
||||
id = WIFI_ADPT_EVT_STA_CONNECT;
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_STA_DISCONNECTED:
|
||||
id = WIFI_ADPT_EVT_STA_DISCONNECT;
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_STA_AUTHMODE_CHANGE:
|
||||
id = WIFI_ADPT_EVT_STA_AUTHMODE_CHANGE;
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_STA_STOP:
|
||||
id = WIFI_ADPT_EVT_STA_STOP;
|
||||
break;
|
||||
#endif /* ESP_WLAN_HAS_STA */
|
||||
|
||||
#ifdef ESP_WLAN_HAS_SOFTAP
|
||||
case WIFI_EVENT_AP_START:
|
||||
id = WIFI_ADPT_EVT_AP_START;
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_AP_STOP:
|
||||
id = WIFI_ADPT_EVT_AP_STOP;
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_AP_STACONNECTED:
|
||||
id = WIFI_ADPT_EVT_AP_STACONNECTED;
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_AP_STADISCONNECTED:
|
||||
id = WIFI_ADPT_EVT_AP_STADISCONNECTED;
|
||||
break;
|
||||
#endif /* ESP_WLAN_HAS_SOFTAP */
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_lock
|
||||
*
|
||||
|
|
@ -807,330 +788,3 @@ int esp_wifi_lock(bool lock)
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_evt_work_cb
|
||||
*
|
||||
* Description:
|
||||
* Process the cached event
|
||||
*
|
||||
* Input Parameters:
|
||||
* arg - No mean
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp_evt_work_cb(void *arg)
|
||||
{
|
||||
int ret;
|
||||
irqstate_t flags;
|
||||
struct evt_adpt *evt_adpt;
|
||||
struct wifi_notify *notify;
|
||||
wifi_ps_type_t ps_type = DEFAULT_PS_MODE;
|
||||
|
||||
while (1)
|
||||
{
|
||||
flags = spin_lock_irqsave(&g_lock);
|
||||
evt_adpt = (struct evt_adpt *)sq_remfirst(&g_wifi_evt_queue);
|
||||
spin_unlock_irqrestore(&g_lock, flags);
|
||||
if (!evt_adpt)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
/* Some of the following logic (eg. esp_wlan_sta_set_linkstatus)
|
||||
* can take net_lock(). To maintain the consistent locking order,
|
||||
* we take net_lock() here before taking esp_wifi_lock. Note that
|
||||
* net_lock() is a recursive lock.
|
||||
*/
|
||||
|
||||
net_lock();
|
||||
esp_wifi_lock(true);
|
||||
|
||||
switch (evt_adpt->id)
|
||||
{
|
||||
case WIFI_ADPT_EVT_SCAN_DONE:
|
||||
#ifdef CONFIG_ESPRESSIF_WIFI
|
||||
esp_wifi_scan_event_parse();
|
||||
#endif
|
||||
break;
|
||||
|
||||
#ifdef ESP_WLAN_HAS_STA
|
||||
case WIFI_ADPT_EVT_STA_START:
|
||||
wlinfo("Wi-Fi sta start\n");
|
||||
|
||||
g_sta_connected = false;
|
||||
|
||||
ret = esp_wifi_set_ps(ps_type);
|
||||
if (ret)
|
||||
{
|
||||
wlerr("Failed to set power save type\n");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
wlinfo("INFO: Set ps type=%d\n", ps_type);
|
||||
}
|
||||
|
||||
ret = esp_wifi_get_config(WIFI_IF_STA, &g_sta_wifi_cfg);
|
||||
if (ret)
|
||||
{
|
||||
wlerr("Failed to get Wi-Fi config data ret=%d\n", ret);
|
||||
}
|
||||
break;
|
||||
|
||||
case WIFI_ADPT_EVT_STA_CONNECT:
|
||||
wlinfo("Wi-Fi sta connect\n");
|
||||
g_sta_connected = true;
|
||||
ret = esp_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 = esp_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();
|
||||
if (ret)
|
||||
{
|
||||
wlerr("Failed to connect AP error=%d\n", ret);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case WIFI_ADPT_EVT_STA_STOP:
|
||||
wlinfo("Wi-Fi sta stop\n");
|
||||
g_sta_connected = false;
|
||||
break;
|
||||
#endif /* ESP_WLAN_HAS_STA */
|
||||
|
||||
#ifdef ESP_WLAN_HAS_SOFTAP
|
||||
case WIFI_ADPT_EVT_AP_START:
|
||||
wlinfo("INFO: Wi-Fi softap start\n");
|
||||
|
||||
ret = esp_wifi_set_ps(ps_type);
|
||||
if (ret)
|
||||
{
|
||||
wlerr("Failed to set power save type\n");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
wlinfo("INFO: Set ps type=%d\n", ps_type);
|
||||
}
|
||||
|
||||
ret = esp_wifi_get_config(WIFI_IF_AP, &g_softap_wifi_cfg);
|
||||
if (ret)
|
||||
{
|
||||
wlerr("Failed to get Wi-Fi config data ret=%d\n", ret);
|
||||
}
|
||||
break;
|
||||
|
||||
case WIFI_ADPT_EVT_AP_STOP:
|
||||
wlinfo("INFO: Wi-Fi softap stop\n");
|
||||
break;
|
||||
|
||||
case WIFI_ADPT_EVT_AP_STACONNECTED:
|
||||
wlinfo("INFO: Wi-Fi station join\n");
|
||||
break;
|
||||
|
||||
case WIFI_ADPT_EVT_AP_STADISCONNECTED:
|
||||
wlinfo("INFO: Wi-Fi station leave\n");
|
||||
break;
|
||||
#endif /* ESP_WLAN_HAS_SOFTAP */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
notify = &g_wifi_notify[evt_adpt->id];
|
||||
if (notify->assigned)
|
||||
{
|
||||
notify->event.sigev_value.sival_ptr = evt_adpt->buf;
|
||||
|
||||
ret = nxsig_notification(notify->pid, ¬ify->event,
|
||||
SI_QUEUE, ¬ify->work);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlwarn("nxsig_notification event ID=%ld failed: %d\n",
|
||||
evt_adpt->id, ret);
|
||||
}
|
||||
}
|
||||
|
||||
esp_wifi_lock(false);
|
||||
net_unlock();
|
||||
|
||||
kmm_free(evt_adpt);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_event_post
|
||||
*
|
||||
* Description:
|
||||
* Posts an event to the event loop system. The event is queued in a FIFO
|
||||
* and processed asynchronously in the low-priority work queue.
|
||||
*
|
||||
* Input Parameters:
|
||||
* event_base - Identifier for the event category (e.g. WIFI_EVENT)
|
||||
* event_id - Event ID within the event base category
|
||||
* event_data - Pointer to event data structure
|
||||
* event_data_size - Size of event data structure
|
||||
* ticks - Number of ticks to wait (currently unused)
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 on success
|
||||
* -1 on failure with following error conditions:
|
||||
* - Invalid event ID
|
||||
* - Memory allocation failure
|
||||
*
|
||||
* Assumptions/Limitations:
|
||||
* - Event data is copied into a new buffer, so the original can be freed
|
||||
* - Events are processed in FIFO order in the low priority work queue
|
||||
* - The function is thread-safe and can be called from interrupt context
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_event_post(const char *event_base,
|
||||
int32_t event_id,
|
||||
void *event_data,
|
||||
size_t event_data_size,
|
||||
uint32_t ticks)
|
||||
{
|
||||
size_t size;
|
||||
int32_t id;
|
||||
irqstate_t flags;
|
||||
struct evt_adpt *evt_adpt;
|
||||
|
||||
wlinfo("Event: base=%s id=%ld data=%p data_size=%u ticks=%lu\n",
|
||||
event_base, event_id, event_data, event_data_size, ticks);
|
||||
|
||||
id = esp_event_id_map(event_id);
|
||||
if (id < 0)
|
||||
{
|
||||
wlerr("ERROR: No process event %ld\n", event_id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
size = event_data_size + sizeof(struct evt_adpt);
|
||||
evt_adpt = kmm_malloc(size);
|
||||
if (!evt_adpt)
|
||||
{
|
||||
wlerr("ERROR: Failed to alloc %d memory\n", size);
|
||||
return -1;
|
||||
}
|
||||
|
||||
evt_adpt->id = id;
|
||||
memcpy(evt_adpt->buf, event_data, event_data_size);
|
||||
|
||||
flags = enter_critical_section();
|
||||
sq_addlast(&evt_adpt->entry, &g_wifi_evt_queue);
|
||||
leave_critical_section(flags);
|
||||
|
||||
work_queue(LPWORK, &g_wifi_evt_work, esp_evt_work_cb, NULL, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_notify_subscribe
|
||||
*
|
||||
* Description:
|
||||
* Enable event notification
|
||||
*
|
||||
* Input Parameters:
|
||||
* pid - Task PID
|
||||
* event - Signal event data pointer
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 if success or -1 if fail
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_notify_subscribe(pid_t pid, struct sigevent *event)
|
||||
{
|
||||
int id;
|
||||
struct wifi_notify *notify;
|
||||
int ret = -1;
|
||||
|
||||
wlinfo("PID=%d event=%p\n", pid, event);
|
||||
|
||||
esp_wifi_lock(true);
|
||||
|
||||
if (event->sigev_notify == SIGEV_SIGNAL)
|
||||
{
|
||||
id = esp_event_id_map(event->sigev_signo);
|
||||
if (id < 0)
|
||||
{
|
||||
wlerr("No process event %d\n", event->sigev_signo);
|
||||
}
|
||||
else
|
||||
{
|
||||
notify = &g_wifi_notify[id];
|
||||
|
||||
if (notify->assigned)
|
||||
{
|
||||
wlerr("sigev_signo %d has subscribed\n",
|
||||
event->sigev_signo);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pid == 0)
|
||||
{
|
||||
pid = nxsched_gettid();
|
||||
wlinfo("Actual PID=%d\n", pid);
|
||||
}
|
||||
|
||||
notify->pid = pid;
|
||||
notify->event = *event;
|
||||
notify->assigned = true;
|
||||
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (event->sigev_notify == SIGEV_NONE)
|
||||
{
|
||||
id = esp_event_id_map(event->sigev_signo);
|
||||
if (id < 0)
|
||||
{
|
||||
wlerr("No process event %d\n", event->sigev_signo);
|
||||
}
|
||||
else
|
||||
{
|
||||
notify = &g_wifi_notify[id];
|
||||
|
||||
if (!notify->assigned)
|
||||
{
|
||||
wlerr("sigev_signo %d has not subscribed\n",
|
||||
event->sigev_signo);
|
||||
}
|
||||
else
|
||||
{
|
||||
notify->assigned = false;
|
||||
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wlerr("sigev_notify %d is invalid\n", event->sigev_signo);
|
||||
}
|
||||
|
||||
esp_wifi_lock(false);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@
|
|||
#include <nuttx/net/netdev.h>
|
||||
#include <nuttx/signal.h>
|
||||
|
||||
#include "esp_wifi_types_generic.h"
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
#include <stdint.h>
|
||||
|
|
@ -44,41 +46,32 @@ extern "C"
|
|||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/* Wi-Fi event ID */
|
||||
#define MAC_LEN (6)
|
||||
|
||||
enum wifi_adpt_evt_e
|
||||
/****************************************************************************
|
||||
* Inline Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nuttx_err_to_common_err
|
||||
*
|
||||
* Description:
|
||||
* Transform from Nuttx OS error code to low level API error code.
|
||||
*
|
||||
* Input Parameters:
|
||||
* ret - NuttX error code
|
||||
*
|
||||
* Returned Value:
|
||||
* Wi-Fi adapter error code
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ESPRESSIF_WIFI
|
||||
static inline int32_t nuttx_err_to_common_err(int ret)
|
||||
{
|
||||
WIFI_ADPT_EVT_SCAN_DONE = 0,
|
||||
WIFI_ADPT_EVT_STA_START,
|
||||
WIFI_ADPT_EVT_STA_CONNECT,
|
||||
WIFI_ADPT_EVT_STA_DISCONNECT,
|
||||
WIFI_ADPT_EVT_STA_AUTHMODE_CHANGE,
|
||||
WIFI_ADPT_EVT_STA_STOP,
|
||||
WIFI_ADPT_EVT_AP_START,
|
||||
WIFI_ADPT_EVT_AP_STOP,
|
||||
WIFI_ADPT_EVT_AP_STACONNECTED,
|
||||
WIFI_ADPT_EVT_AP_STADISCONNECTED,
|
||||
WIFI_ADPT_EVT_MAX,
|
||||
};
|
||||
|
||||
/* Wi-Fi event private data */
|
||||
|
||||
struct evt_adpt
|
||||
{
|
||||
sq_entry_t entry; /* Sequence entry */
|
||||
int32_t id; /* Event ID */
|
||||
uint8_t buf[0]; /* Event private data */
|
||||
};
|
||||
|
||||
/* Wi-Fi event notification private data */
|
||||
|
||||
struct wifi_notify
|
||||
{
|
||||
bool assigned; /* Flag indicate if it is used */
|
||||
pid_t pid; /* Signal's target thread PID */
|
||||
struct sigevent event; /* Signal event private data */
|
||||
struct sigwork_s work; /* Signal work private data */
|
||||
};
|
||||
return ret >= 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
|
|
@ -86,6 +79,38 @@ struct wifi_notify
|
|||
|
||||
#ifdef CONFIG_ESPRESSIF_WIFI
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_freq_to_channel
|
||||
*
|
||||
* Description:
|
||||
* Converts Wi-Fi frequency to channel.
|
||||
*
|
||||
* Input Parameters:
|
||||
* freq - Wi-Fi frequency
|
||||
*
|
||||
* Returned Value:
|
||||
* Wi-Fi channel
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_freq_to_channel(uint16_t freq);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_evt_work_init
|
||||
*
|
||||
* Description:
|
||||
* Initialize the event work queue
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp_evt_work_init(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_start_scan
|
||||
*
|
||||
|
|
@ -124,13 +149,13 @@ int esp_wifi_get_scan_results(struct iwreq *iwr);
|
|||
* Name: esp_wifi_scan_event_parse
|
||||
*
|
||||
* Description:
|
||||
* Parse scan information
|
||||
* Parse scan information Wi-Fi AP scan results.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
* None.
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
@ -155,20 +180,21 @@ void esp_wifi_scan_event_parse(void);
|
|||
int32_t esp_wifi_to_errno(int err);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_event_id_map
|
||||
* Name: esp_wifi_mode_translate
|
||||
*
|
||||
* Description:
|
||||
* Transform from esp-idf event ID to Wi-Fi adapter event ID
|
||||
* Translate wireless mode constants to ESP Wi-Fi mode constants.
|
||||
*
|
||||
* Input Parameters:
|
||||
* event_id - esp-idf event ID
|
||||
* wireless_mode - Wireless mode from wireless.h (IW_MODE_*)
|
||||
*
|
||||
* Returned Value:
|
||||
* Wi-Fi adapter event ID
|
||||
* ESP Wi-Fi mode (WIFI_MODE_*) on success
|
||||
* -EINVAL on failure
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_event_id_map(int event_id);
|
||||
wifi_mode_t esp_wifi_mode_translate(uint32_t wireless_mode);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_lock
|
||||
|
|
@ -186,22 +212,6 @@ int esp_event_id_map(int event_id);
|
|||
|
||||
int esp_wifi_lock(bool lock);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_evt_work_cb
|
||||
*
|
||||
* Description:
|
||||
* Process the cached event
|
||||
*
|
||||
* Input Parameters:
|
||||
* arg - No mean
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp_evt_work_cb(void *arg);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_event_post
|
||||
*
|
||||
|
|
@ -235,23 +245,6 @@ int esp_event_post(const char *event_base,
|
|||
size_t event_data_size,
|
||||
uint32_t ticks);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_notify_subscribe
|
||||
*
|
||||
* Description:
|
||||
* Enable event notification
|
||||
*
|
||||
* Input Parameters:
|
||||
* pid - Task PID
|
||||
* event - Signal event data pointer
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 if success or -1 if fail
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_notify_subscribe(pid_t pid, struct sigevent *event);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
1402
arch/risc-v/src/common/espressif/esp_wlan_netdev.c
Normal file
1402
arch/risc-v/src/common/espressif/esp_wlan_netdev.c
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* arch/risc-v/src/common/espressif/esp_wlan.h
|
||||
* arch/risc-v/src/common/espressif/esp_wlan_netdev.h
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
|
|
@ -20,8 +20,8 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ARCH_RISCV_SRC_COMMON_ESPRESSIF_ESP_WLAN_H
|
||||
#define __ARCH_RISCV_SRC_COMMON_ESPRESSIF_ESP_WLAN_H
|
||||
#ifndef __ARCH_RISCV_SRC_COMMON_ESPRESSIF_ESP_WLAN_NETDEV_H
|
||||
#define __ARCH_RISCV_SRC_COMMON_ESPRESSIF_ESP_WLAN_NETDEV_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
|
|
@ -55,115 +55,118 @@ extern "C"
|
|||
#elif defined(CONFIG_ESPRESSIF_WIFI_STATION_SOFTAP)
|
||||
# define ESP_WLAN_HAS_STA
|
||||
# define ESP_WLAN_HAS_SOFTAP
|
||||
# define ESP_WLAN_HAS_APSTA
|
||||
# define ESP_WLAN_STA_DEVNO 0
|
||||
# define ESP_WLAN_SOFTAP_DEVNO 1
|
||||
# define ESP_WLAN_DEVS 2
|
||||
#endif
|
||||
|
||||
#define MAC_LEN (6)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef ESP_WLAN_HAS_STA
|
||||
|
||||
/* If reconnect automatically */
|
||||
|
||||
extern volatile bool g_sta_reconnect;
|
||||
|
||||
/* If Wi-Fi sta starts */
|
||||
|
||||
extern volatile bool g_sta_started;
|
||||
|
||||
/* If Wi-Fi sta connected */
|
||||
|
||||
extern volatile bool g_sta_connected;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef ESP_WLAN_HAS_SOFTAP
|
||||
|
||||
/* If Wi-Fi SoftAP starts */
|
||||
|
||||
extern volatile bool g_softap_started;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ESPRESSIF_WIFI
|
||||
|
||||
/****************************************************************************
|
||||
* Inline Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nuttx_err_to_freertos
|
||||
*
|
||||
* Description:
|
||||
* Transform from Nuttx OS error code to FreeRTOS's pdTRUE or pdFALSE.
|
||||
*
|
||||
* Input Parameters:
|
||||
* ret - NuttX error code
|
||||
*
|
||||
* Returned Value:
|
||||
* Wi-Fi adapter error code
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline int32_t nuttx_err_to_freertos(int ret)
|
||||
{
|
||||
return ret >= 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef ESP_WLAN_HAS_STA
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wlan_sta_set_linkstatus
|
||||
* Name: esp_wlan_sta_connect_success_hook
|
||||
*
|
||||
* Description:
|
||||
* Set Wi-Fi station link status
|
||||
* Notify the networking layer that connection has succeeded.
|
||||
*
|
||||
* Parameters:
|
||||
* linkstatus - true Notifies the networking layer about an available
|
||||
* carrier, false Notifies the networking layer about an
|
||||
* disappeared carrier.
|
||||
* Input Parameters:
|
||||
* None.
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; Negated errno on failure.
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wlan_sta_set_linkstatus(bool linkstatus);
|
||||
#ifdef ESP_WLAN_HAS_STA
|
||||
void esp_wlan_sta_connect_success_hook(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wlan_sta_disconnect_hook
|
||||
*
|
||||
* Description:
|
||||
* Notify the networking layer that connection has been disconnected.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None.
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef ESP_WLAN_HAS_STA
|
||||
void esp_wlan_sta_disconnect_hook(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wlan_softap_connect_success_hook
|
||||
*
|
||||
* Description:
|
||||
* Notify the networking layer that connection has succeeded.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None.
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef ESP_WLAN_HAS_SOFTAP
|
||||
void esp_wlan_softap_connect_success_hook(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wlan_softap_disconnect_hook
|
||||
*
|
||||
* Description:
|
||||
* Notify the networking layer that connection has been disconnected.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None.
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef ESP_WLAN_HAS_SOFTAP
|
||||
void esp_wlan_softap_disconnect_hook(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wlan_sta_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the ESP32-S3 WLAN station netcard driver
|
||||
* Initialize the Wi-Fi adapter for station mode.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
* None.
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; Negated errno on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef ESP_WLAN_HAS_STA
|
||||
int esp_wlan_sta_initialize(void);
|
||||
#endif /* ESP_WLAN_HAS_STA */
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wlan_softap_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the ESP32-S3 WLAN softAP netcard driver
|
||||
* Initialize the Wi-Fi adapter for SoftAP mode.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
* None.
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success; Negated errno on failure.
|
||||
|
|
@ -172,36 +175,12 @@ int esp_wlan_sta_initialize(void);
|
|||
|
||||
#ifdef ESP_WLAN_HAS_SOFTAP
|
||||
int esp_wlan_softap_initialize(void);
|
||||
#endif /* ESP_WLAN_HAS_SOFTAP */
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_tx_done_cb
|
||||
*
|
||||
* Description:
|
||||
* Wi-Fi TX done callback function.
|
||||
*
|
||||
* Input Parameters:
|
||||
* ifidx - The interface id that the tx callback has been triggered from
|
||||
* data - Pointer to the data transmitted
|
||||
* data_len - Length of the data transmitted
|
||||
* txstatus - True: if the data was transmitted successfully
|
||||
* False: if data transmission failed
|
||||
*
|
||||
* Returned Value:
|
||||
* none
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp_wifi_tx_done_cb(uint8_t ifidx,
|
||||
uint8_t *data,
|
||||
uint16_t *len,
|
||||
bool txstatus);
|
||||
|
||||
#endif /* CONFIG_ESPRESSIF_WIFI */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#undef EXTERN
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __ARCH_RISCV_SRC_COMMON_ESPRESSIF_ESP_WLAN_H */
|
||||
#endif /* __ARCH_RISCV_SRC_COMMON_ESPRESSIF_ESP_WLAN_NETDEV_H */
|
||||
|
|
@ -37,7 +37,6 @@
|
|||
#include <nuttx/kmalloc.h>
|
||||
|
||||
#include "esp_hr_timer.h"
|
||||
#include "esp_wlan.h"
|
||||
|
||||
#include "esp_attr.h"
|
||||
#include "esp_timer.h"
|
||||
|
|
@ -49,6 +48,10 @@
|
|||
#include "soc/system_reg.h"
|
||||
#include "private/esp_modem_wrapper.h"
|
||||
|
||||
#include "espressif/esp_wifi_utils.h"
|
||||
|
||||
#include "esp_coex_adapter.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
|
@ -59,7 +62,7 @@
|
|||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static int64_t esp_coex_esp_timer_get_time_wrapper(void);
|
||||
static IRAM_ATTR int64_t esp_coex_esp_timer_get_time_wrapper(void);
|
||||
static int32_t esp_coex_semphr_take_from_isr_wrapper(void *semphr,
|
||||
void *hptw);
|
||||
static int32_t esp_coex_semphr_give_from_isr_wrapper(void *semphr,
|
||||
|
|
@ -137,7 +140,7 @@ static int32_t IRAM_ATTR esp_coex_semphr_take_from_isr_wrapper(void *semphr,
|
|||
{
|
||||
*(int *)hptw = 0;
|
||||
|
||||
return nuttx_err_to_freertos(nxsem_trywait(semphr));
|
||||
return nuttx_err_to_common_err(nxsem_trywait(semphr));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -418,7 +421,7 @@ int32_t esp_coex_common_semphr_take_wrapper(void *semphr,
|
|||
block_time_tick, ret);
|
||||
}
|
||||
|
||||
return nuttx_err_to_freertos(ret);
|
||||
return nuttx_err_to_common_err(ret);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -449,7 +452,7 @@ int32_t esp_coex_common_semphr_give_wrapper(void *semphr)
|
|||
wlerr("Failed to post sem error=%d\n", ret);
|
||||
}
|
||||
|
||||
return nuttx_err_to_freertos(ret);
|
||||
return nuttx_err_to_common_err(ret);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
|||
82
arch/risc-v/src/esp32c3/esp_coex_adapter.h
Normal file
82
arch/risc-v/src/esp32c3/esp_coex_adapter.h
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
/****************************************************************************
|
||||
* arch/risc-v/src/esp32c3/esp_coex_adapter.h
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ARCH_RISCV_SRC_ESP32C3_ESP_COEX_ADAPTER_H
|
||||
#define __ARCH_RISCV_SRC_ESP32C3_ESP_COEX_ADAPTER_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "esp_attr.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
bool IRAM_ATTR esp_coex_common_env_is_chip_wrapper(void);
|
||||
void *esp_coex_common_spin_lock_create_wrapper(void);
|
||||
uint32_t IRAM_ATTR esp_coex_common_int_disable_wrapper(void *wifi_int_mux);
|
||||
void IRAM_ATTR esp_coex_common_int_restore_wrapper(void *wifi_int_mux,
|
||||
uint32_t tmp);
|
||||
void IRAM_ATTR esp_coex_common_task_yield_from_isr_wrapper(void);
|
||||
void *esp_coex_common_semphr_create_wrapper(uint32_t max, uint32_t init);
|
||||
void esp_coex_common_semphr_delete_wrapper(void *semphr);
|
||||
int32_t esp_coex_common_semphr_take_wrapper(void *semphr,
|
||||
uint32_t block_time_tick);
|
||||
int32_t esp_coex_common_semphr_give_wrapper(void *semphr);
|
||||
void IRAM_ATTR esp_coex_common_timer_disarm_wrapper(void *timer);
|
||||
void esp_coex_common_timer_done_wrapper(void *ptimer);
|
||||
void esp_coex_common_timer_setfn_wrapper(void *ptimer,
|
||||
void *pfunction,
|
||||
void *parg);
|
||||
void IRAM_ATTR esp_coex_common_timer_arm_us_wrapper(void *ptimer,
|
||||
uint32_t us,
|
||||
bool repeat);
|
||||
IRAM_ATTR void *esp_coex_common_malloc_internal_wrapper(size_t size);
|
||||
uint32_t esp_coex_common_clk_slowclk_cal_get_wrapper(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#undef EXTERN
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __ARCH_RISCV_SRC_ESP32C3_ESP_COEX_ADAPTER_H */
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -37,7 +37,7 @@
|
|||
#include <nuttx/kmalloc.h>
|
||||
|
||||
#include "esp_hr_timer.h"
|
||||
#include "esp_wlan.h"
|
||||
#include "esp_wifi_utils.h"
|
||||
|
||||
#include "esp_attr.h"
|
||||
#include "esp_timer.h"
|
||||
|
|
@ -137,7 +137,7 @@ static int32_t IRAM_ATTR esp_coex_semphr_take_from_isr_wrapper(void *semphr,
|
|||
{
|
||||
*(int *)hptw = 0;
|
||||
|
||||
return nuttx_err_to_freertos(nxsem_trywait(semphr));
|
||||
return nuttx_err_to_common_err(nxsem_trywait(semphr));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -418,7 +418,7 @@ int32_t esp_coex_common_semphr_take_wrapper(void *semphr,
|
|||
block_time_tick, ret);
|
||||
}
|
||||
|
||||
return nuttx_err_to_freertos(ret);
|
||||
return nuttx_err_to_common_err(ret);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -449,7 +449,7 @@ int32_t esp_coex_common_semphr_give_wrapper(void *semphr)
|
|||
wlerr("Failed to post sem error=%d\n", ret);
|
||||
}
|
||||
|
||||
return nuttx_err_to_freertos(ret);
|
||||
return nuttx_err_to_common_err(ret);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -28,11 +28,6 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/wireless/wireless.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "esp_wlan.h"
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
|
|
@ -49,622 +44,10 @@ extern "C"
|
|||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define SSID_MAX_LEN (32)
|
||||
#define PWD_MAX_LEN (64)
|
||||
|
||||
#define CONFIG_IDF_TARGET_ESP32C6 1
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_adapter_init
|
||||
*
|
||||
* Description:
|
||||
* Initialize ESP32C6 Wi-Fi adapter
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 if success or -1 if fail
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_adapter_init(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_notify_subscribe
|
||||
*
|
||||
* Description:
|
||||
* Enable event notification
|
||||
*
|
||||
* Input Parameters:
|
||||
* pid - Task PID
|
||||
* event - Signal event data pointer
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 if success or -1 if fail
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_notify_subscribe(pid_t pid, struct sigevent *event);
|
||||
|
||||
#ifdef ESP_WLAN_HAS_STA
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_sta_start
|
||||
*
|
||||
* Description:
|
||||
* Start Wi-Fi station.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_start(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_sta_stop
|
||||
*
|
||||
* Description:
|
||||
* Stop Wi-Fi station.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_stop(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_sta_send_data
|
||||
*
|
||||
* Description:
|
||||
* Use Wi-Fi station interface to send 802.3 frame
|
||||
*
|
||||
* Input Parameters:
|
||||
* pbuf - Packet buffer pointer
|
||||
* len - Packet length
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_send_data(void *pbuf, size_t len);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_set_password
|
||||
*
|
||||
* Description:
|
||||
* Set/Get Wi-Fi station password
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_password(struct iwreq *iwr, bool set);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_sta_essid
|
||||
*
|
||||
* Description:
|
||||
* Set/Get Wi-Fi station ESSID
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_essid(struct iwreq *iwr, bool set);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_sta_bssid
|
||||
*
|
||||
* Description:
|
||||
* Set/Get Wi-Fi station BSSID
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_bssid(struct iwreq *iwr, bool set);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_sta_connect
|
||||
*
|
||||
* Description:
|
||||
* Trigger Wi-Fi station connection action
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_connect(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_sta_disconnect
|
||||
*
|
||||
* Description:
|
||||
* Trigger Wi-Fi station disconnection action
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_disconnect(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_sta_mode
|
||||
*
|
||||
* Description:
|
||||
* Set/Get Wi-Fi Station mode code.
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_mode(struct iwreq *iwr, bool set);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_sta_auth
|
||||
*
|
||||
* Description:
|
||||
* Set/Get station authentication mode params.
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_auth(struct iwreq *iwr, bool set);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_sta_freq
|
||||
*
|
||||
* Description:
|
||||
* Get station frequency.
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_freq(struct iwreq *iwr, bool set);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_sta_bitrate
|
||||
*
|
||||
* Description:
|
||||
* Get station default bit rate (Mbps).
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_bitrate(struct iwreq *iwr, bool set);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_sta_get_txpower
|
||||
*
|
||||
* Description:
|
||||
* Get station transmit power (dBm).
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_txpower(struct iwreq *iwr, bool set);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_sta_get_channel_range
|
||||
*
|
||||
* Description:
|
||||
* Get station range of channel parameters.
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_channel(struct iwreq *iwr, bool set);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_sta_country
|
||||
*
|
||||
* Description:
|
||||
* Configure country info.
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_country(struct iwreq *iwr, bool set);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_sta_rssi
|
||||
*
|
||||
* Description:
|
||||
* Get Wi-Fi sensitivity (dBm).
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_sta_rssi(struct iwreq *iwr, bool set);
|
||||
#endif /* ESP_WLAN_HAS_STA */
|
||||
|
||||
#ifdef ESP_WLAN_HAS_SOFTAP
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_softap_start
|
||||
*
|
||||
* Description:
|
||||
* Start Wi-Fi softAP.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_softap_start(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_softap_stop
|
||||
*
|
||||
* Description:
|
||||
* Stop Wi-Fi softAP.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_softap_stop(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_softap_send_data
|
||||
*
|
||||
* Description:
|
||||
* Use Wi-Fi softAP interface to send 802.3 frame
|
||||
*
|
||||
* Input Parameters:
|
||||
* pbuf - Packet buffer pointer
|
||||
* len - Packet length
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_softap_send_data(void *pbuf, size_t len);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_softap_password
|
||||
*
|
||||
* Description:
|
||||
* Set/Get Wi-Fi SoftAP password
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_softap_password(struct iwreq *iwr, bool set);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_softap_essid
|
||||
*
|
||||
* Description:
|
||||
* Set/Get Wi-Fi SoftAP ESSID
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_softap_essid(struct iwreq *iwr, bool set);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_softap_bssid
|
||||
*
|
||||
* Description:
|
||||
* Set/Get Wi-Fi softAP BSSID
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_softap_bssid(struct iwreq *iwr, bool set);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_softap_connect
|
||||
*
|
||||
* Description:
|
||||
* Trigger Wi-Fi softAP accept connection action
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_softap_connect(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_softap_disconnect
|
||||
*
|
||||
* Description:
|
||||
* Trigger Wi-Fi softAP drop connection action
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_softap_disconnect(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_softap_mode
|
||||
*
|
||||
* Description:
|
||||
* Set/Get Wi-Fi SoftAP mode code.
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_softap_mode(struct iwreq *iwr, bool set);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_softap_auth
|
||||
*
|
||||
* Description:
|
||||
* Set/Get authentication mode params.
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_softap_auth(struct iwreq *iwr, bool set);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_softap_freq
|
||||
*
|
||||
* Description:
|
||||
* Set/Get SoftAP frequency.
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_softap_freq(struct iwreq *iwr, bool set);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_softap_get_bitrate
|
||||
*
|
||||
* Description:
|
||||
* Get SoftAP default bit rate (Mbps).
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_softap_bitrate(struct iwreq *iwr, bool set);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_softap_txpower
|
||||
*
|
||||
* Description:
|
||||
* Get SoftAP transmit power (dBm).
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_softap_txpower(struct iwreq *iwr, bool set);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_softap_channel
|
||||
*
|
||||
* Description:
|
||||
* Get SoftAP range of channel parameters.
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_softap_channel(struct iwreq *iwr, bool set);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_softap_country
|
||||
*
|
||||
* Description:
|
||||
* Configure country info.
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_softap_country(struct iwreq *iwr, bool set);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_softap_rssi
|
||||
*
|
||||
* Description:
|
||||
* Get Wi-Fi sensitivity (dBm).
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
* set - true: set data; false: get data
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_softap_rssi(struct iwreq *iwr, bool set);
|
||||
#endif /* ESP_WLAN_HAS_SOFTAP */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue