2021-09-30 15:12:55 +08:00
|
|
|
/*
|
2023-09-15 11:34:03 +08:00
|
|
|
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
2021-09-30 15:12:55 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2017-08-17 09:41:34 +05:30
|
|
|
|
|
|
|
#include <esp_event.h>
|
|
|
|
#include <esp_wifi.h>
|
2017-09-22 23:34:52 +08:00
|
|
|
#include "esp_log.h"
|
2019-03-22 14:21:15 +08:00
|
|
|
#include "esp_private/wifi.h"
|
2022-07-21 11:47:09 +08:00
|
|
|
#include "esp_private/adc_share_hw_ctrl.h"
|
2022-12-12 11:56:11 +08:00
|
|
|
#include "esp_private/sleep_modem.h"
|
2017-09-22 23:34:52 +08:00
|
|
|
#include "esp_pm.h"
|
2020-05-07 16:15:56 +08:00
|
|
|
#include "esp_sleep.h"
|
|
|
|
#include "esp_private/pm_impl.h"
|
2022-03-25 18:41:25 +08:00
|
|
|
#include "esp_private/esp_clk.h"
|
2018-08-13 16:37:56 +08:00
|
|
|
#include "esp_wpa.h"
|
2019-06-28 16:47:34 +02:00
|
|
|
#include "esp_netif.h"
|
2023-08-09 17:41:27 +08:00
|
|
|
#include "private/esp_coexist_internal.h"
|
2021-01-10 16:16:28 +08:00
|
|
|
#include "esp_phy_init.h"
|
2022-12-19 20:29:52 +08:00
|
|
|
#include "esp_private/phy.h"
|
2023-11-16 21:43:36 +08:00
|
|
|
#if __has_include("esp_psram.h")
|
|
|
|
#include "esp_psram.h"
|
|
|
|
#endif
|
2023-02-14 10:06:40 +05:30
|
|
|
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
|
|
|
|
#include "apps_private/wifi_apps_private.h"
|
|
|
|
#endif
|
2018-02-27 18:22:20 +08:00
|
|
|
|
2023-10-27 14:27:11 +08:00
|
|
|
static bool s_wifi_inited = false;
|
|
|
|
|
2023-02-11 07:38:45 +08:00
|
|
|
#if (CONFIG_ESP_WIFI_RX_BA_WIN > CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM)
|
2019-07-19 15:32:05 +08:00
|
|
|
#error "WiFi configuration check: WARNING, WIFI_RX_BA_WIN should not be larger than WIFI_DYNAMIC_RX_BUFFER_NUM!"
|
|
|
|
#endif
|
|
|
|
|
2023-02-11 07:38:45 +08:00
|
|
|
#if (CONFIG_ESP_WIFI_RX_BA_WIN > (CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM << 1))
|
2019-07-19 15:32:05 +08:00
|
|
|
#error "WiFi configuration check: WARNING, WIFI_RX_BA_WIN should not be larger than double of the WIFI_STATIC_RX_BUFFER_NUM!"
|
|
|
|
#endif
|
2018-02-27 18:22:20 +08:00
|
|
|
|
2018-08-23 17:50:16 +08:00
|
|
|
ESP_EVENT_DEFINE_BASE(WIFI_EVENT);
|
2017-09-22 23:34:52 +08:00
|
|
|
|
2020-08-05 11:13:20 +08:00
|
|
|
extern uint8_t esp_wifi_get_user_init_flag_internal(void);
|
2017-09-22 23:34:52 +08:00
|
|
|
#ifdef CONFIG_PM_ENABLE
|
|
|
|
static esp_pm_lock_handle_t s_wifi_modem_sleep_lock;
|
|
|
|
#endif
|
2017-08-17 09:41:34 +05:30
|
|
|
|
2019-06-17 11:50:37 +08:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
2019-02-20 21:01:27 +08:00
|
|
|
/* Callback function to update WiFi MAC time */
|
|
|
|
wifi_mac_time_update_cb_t s_wifi_mac_time_update_cb = NULL;
|
2019-06-17 11:50:37 +08:00
|
|
|
#endif
|
2019-02-20 21:01:27 +08:00
|
|
|
|
2023-02-05 17:03:07 +08:00
|
|
|
#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
|
2020-01-02 10:44:45 +01:00
|
|
|
|
2018-11-06 11:09:32 +08:00
|
|
|
static const char* TAG = "wifi_init";
|
|
|
|
|
2019-07-16 16:33:30 +07:00
|
|
|
static void __attribute__((constructor)) s_set_default_wifi_log_level(void)
|
2018-05-02 15:11:21 +10:00
|
|
|
{
|
|
|
|
/* WiFi libraries aren't compiled to know CONFIG_LOG_DEFAULT_LEVEL,
|
|
|
|
so set it at runtime startup. Done here not in esp_wifi_init() to allow
|
|
|
|
the user to set the level again before esp_wifi_init() is called.
|
|
|
|
*/
|
2020-11-10 18:40:01 +11:00
|
|
|
esp_log_level_set("wifi", CONFIG_LOG_DEFAULT_LEVEL);
|
2019-01-08 22:14:36 +08:00
|
|
|
esp_log_level_set("mesh", CONFIG_LOG_DEFAULT_LEVEL);
|
2020-07-28 17:57:55 +05:30
|
|
|
esp_log_level_set("smartconfig", CONFIG_LOG_DEFAULT_LEVEL);
|
|
|
|
esp_log_level_set("ESPNOW", CONFIG_LOG_DEFAULT_LEVEL);
|
2018-05-02 15:11:21 +10:00
|
|
|
}
|
|
|
|
|
2021-04-07 15:04:51 +08:00
|
|
|
static void esp_wifi_set_log_level(void)
|
2018-10-29 17:12:08 +08:00
|
|
|
{
|
2021-04-07 15:04:51 +08:00
|
|
|
wifi_log_level_t wifi_log_level = WIFI_LOG_INFO;
|
|
|
|
/* set WiFi log level */
|
|
|
|
#if CONFIG_LOG_MAXIMUM_LEVEL == 0
|
|
|
|
wifi_log_level = WIFI_LOG_NONE;
|
|
|
|
#elif CONFIG_LOG_MAXIMUM_LEVEL == 1
|
|
|
|
wifi_log_level = WIFI_LOG_ERROR;
|
|
|
|
#elif CONFIG_LOG_MAXIMUM_LEVEL == 2
|
|
|
|
wifi_log_level = WIFI_LOG_WARNING;
|
|
|
|
#elif CONFIG_LOG_MAXIMUM_LEVEL == 3
|
|
|
|
wifi_log_level = WIFI_LOG_INFO;
|
|
|
|
#elif CONFIG_LOG_MAXIMUM_LEVEL == 4
|
|
|
|
wifi_log_level = WIFI_LOG_DEBUG;
|
|
|
|
#elif CONFIG_LOG_MAXIMUM_LEVEL == 5
|
|
|
|
wifi_log_level = WIFI_LOG_VERBOSE;
|
|
|
|
#endif
|
|
|
|
esp_wifi_internal_set_log_level(wifi_log_level);
|
2018-10-29 17:12:08 +08:00
|
|
|
}
|
|
|
|
|
2023-10-27 14:27:11 +08:00
|
|
|
static esp_err_t wifi_deinit_internal(void)
|
2019-10-24 17:11:30 +08:00
|
|
|
{
|
|
|
|
esp_err_t err = ESP_OK;
|
|
|
|
|
2020-08-05 11:13:20 +08:00
|
|
|
if (esp_wifi_get_user_init_flag_internal()) {
|
|
|
|
ESP_LOGE(TAG, "Wi-Fi not stop");
|
2021-02-04 20:55:48 +05:30
|
|
|
return ESP_ERR_WIFI_NOT_STOPPED;
|
2020-08-05 11:13:20 +08:00
|
|
|
}
|
|
|
|
|
2021-09-30 13:57:53 +02:00
|
|
|
if (esp_wifi_internal_reg_rxcb(WIFI_IF_STA, NULL) != ESP_OK ||
|
|
|
|
esp_wifi_internal_reg_rxcb(WIFI_IF_AP, NULL) != ESP_OK) {
|
|
|
|
ESP_LOGW(TAG, "Failed to unregister Rx callbacks");
|
|
|
|
}
|
|
|
|
|
2023-02-14 10:06:40 +05:30
|
|
|
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
|
|
|
|
esp_nan_app_deinit();
|
|
|
|
#endif
|
|
|
|
|
2019-10-24 17:11:30 +08:00
|
|
|
esp_supplicant_deinit();
|
|
|
|
err = esp_wifi_deinit_internal();
|
|
|
|
if (err != ESP_OK) {
|
|
|
|
ESP_LOGE(TAG, "Failed to deinit Wi-Fi driver (0x%x)", err);
|
2020-03-02 12:05:15 +08:00
|
|
|
return err;
|
2019-10-24 17:11:30 +08:00
|
|
|
}
|
2023-10-27 14:27:11 +08:00
|
|
|
#ifdef CONFIG_PM_ENABLE
|
|
|
|
if (s_wifi_modem_sleep_lock) {
|
|
|
|
esp_pm_lock_delete(s_wifi_modem_sleep_lock);
|
2023-11-28 20:52:42 +08:00
|
|
|
s_wifi_modem_sleep_lock = NULL;
|
2023-10-27 14:27:11 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
esp_wifi_power_domain_off();
|
2019-10-24 17:11:30 +08:00
|
|
|
|
2021-06-02 19:35:41 +08:00
|
|
|
#if CONFIG_ESP_WIFI_SLP_BEACON_LOST_OPT
|
2023-02-05 17:03:07 +08:00
|
|
|
wifi_beacon_monitor_config_t monitor_config = WIFI_BEACON_MONITOR_CONFIG_DEFAULT(false);
|
|
|
|
esp_wifi_beacon_monitor_configure(&monitor_config);
|
2021-06-02 19:35:41 +08:00
|
|
|
#endif
|
|
|
|
|
2021-05-12 17:00:01 +08:00
|
|
|
#if CONFIG_ESP_WIFI_SLP_IRAM_OPT
|
|
|
|
esp_pm_unregister_light_sleep_default_params_config_callback();
|
|
|
|
#endif
|
2020-05-07 16:15:56 +08:00
|
|
|
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
2021-01-10 16:16:28 +08:00
|
|
|
#if SOC_WIFI_HW_TSF
|
2020-05-07 16:15:56 +08:00
|
|
|
esp_pm_unregister_skip_light_sleep_callback(esp_wifi_internal_is_tsf_active);
|
2020-12-30 16:42:39 +08:00
|
|
|
esp_pm_unregister_inform_out_light_sleep_overhead_callback(esp_wifi_internal_update_light_sleep_wake_ahead_time);
|
2021-04-21 15:17:16 +08:00
|
|
|
esp_sleep_disable_wifi_wakeup();
|
2023-02-05 17:03:07 +08:00
|
|
|
# if CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP
|
2022-03-14 11:33:01 +08:00
|
|
|
esp_sleep_disable_wifi_beacon_wakeup();
|
|
|
|
# endif
|
|
|
|
#endif /* SOC_WIFI_HW_TSF */
|
|
|
|
#endif /* CONFIG_FREERTOS_USE_TICKLESS_IDLE */
|
2021-01-28 22:28:04 +08:00
|
|
|
#if CONFIG_MAC_BB_PD
|
|
|
|
esp_unregister_mac_bb_pd_callback(pm_mac_sleep);
|
|
|
|
esp_unregister_mac_bb_pu_callback(pm_mac_wakeup);
|
|
|
|
#endif
|
2022-05-29 00:13:32 +08:00
|
|
|
#if CONFIG_MAC_BB_PD
|
2023-07-31 21:15:13 +08:00
|
|
|
esp_wifi_internal_set_mac_sleep(false);
|
2022-05-29 00:13:32 +08:00
|
|
|
esp_mac_bb_pd_mem_deinit();
|
2023-09-15 11:34:03 +08:00
|
|
|
#endif
|
|
|
|
#if CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP
|
|
|
|
esp_wifi_internal_modem_state_configure(false);
|
|
|
|
esp_pm_unregister_skip_light_sleep_callback(sleep_modem_wifi_modem_state_skip_light_sleep);
|
2022-05-29 00:13:32 +08:00
|
|
|
#endif
|
2022-11-24 20:18:27 +08:00
|
|
|
esp_phy_modem_deinit();
|
2022-06-16 20:27:59 +08:00
|
|
|
|
2023-10-27 14:27:11 +08:00
|
|
|
s_wifi_inited = false;
|
|
|
|
|
2019-10-24 17:11:30 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2023-10-27 14:27:11 +08:00
|
|
|
esp_err_t esp_wifi_deinit(void)
|
|
|
|
{
|
|
|
|
if (s_wifi_inited == false) {
|
|
|
|
return ESP_ERR_WIFI_NOT_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return wifi_deinit_internal();
|
|
|
|
}
|
|
|
|
|
2020-08-14 23:42:57 +08:00
|
|
|
static void esp_wifi_config_info(void)
|
|
|
|
{
|
2023-02-11 07:38:45 +08:00
|
|
|
#ifdef CONFIG_ESP_WIFI_RX_BA_WIN
|
|
|
|
ESP_LOGI(TAG, "rx ba win: %d", CONFIG_ESP_WIFI_RX_BA_WIN);
|
2020-08-14 23:42:57 +08:00
|
|
|
#endif
|
2020-09-11 15:37:28 -07:00
|
|
|
|
|
|
|
#ifdef CONFIG_ESP_NETIF_TCPIP_LWIP
|
2023-12-01 00:07:38 +11:00
|
|
|
ESP_LOGI(TAG, "accept mbox: %d", CONFIG_LWIP_TCP_ACCEPTMBOX_SIZE);
|
2020-08-14 23:42:57 +08:00
|
|
|
ESP_LOGI(TAG, "tcpip mbox: %d", CONFIG_LWIP_TCPIP_RECVMBOX_SIZE);
|
|
|
|
ESP_LOGI(TAG, "udp mbox: %d", CONFIG_LWIP_UDP_RECVMBOX_SIZE);
|
|
|
|
ESP_LOGI(TAG, "tcp mbox: %d", CONFIG_LWIP_TCP_RECVMBOX_SIZE);
|
|
|
|
ESP_LOGI(TAG, "tcp tx win: %d", CONFIG_LWIP_TCP_SND_BUF_DEFAULT);
|
|
|
|
ESP_LOGI(TAG, "tcp rx win: %d", CONFIG_LWIP_TCP_WND_DEFAULT);
|
|
|
|
ESP_LOGI(TAG, "tcp mss: %d", CONFIG_LWIP_TCP_MSS);
|
|
|
|
|
|
|
|
#ifdef CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP
|
|
|
|
ESP_LOGI(TAG, "WiFi/LWIP prefer SPIRAM");
|
|
|
|
#endif
|
|
|
|
|
2023-02-11 07:38:45 +08:00
|
|
|
#ifdef CONFIG_ESP_WIFI_IRAM_OPT
|
2020-08-14 23:42:57 +08:00
|
|
|
ESP_LOGI(TAG, "WiFi IRAM OP enabled");
|
|
|
|
#endif
|
|
|
|
|
2023-02-11 07:38:45 +08:00
|
|
|
#ifdef CONFIG_ESP_WIFI_RX_IRAM_OPT
|
2020-08-14 23:42:57 +08:00
|
|
|
ESP_LOGI(TAG, "WiFi RX IRAM OP enabled");
|
|
|
|
#endif
|
|
|
|
|
2020-12-30 16:42:39 +08:00
|
|
|
#ifdef CONFIG_ESP_WIFI_SLP_IRAM_OPT
|
|
|
|
ESP_LOGI(TAG, "WiFi SLP IRAM OP enabled");
|
|
|
|
#endif
|
|
|
|
|
2020-08-14 23:42:57 +08:00
|
|
|
#ifdef CONFIG_LWIP_IRAM_OPTIMIZATION
|
|
|
|
ESP_LOGI(TAG, "LWIP IRAM OP enabled");
|
|
|
|
#endif
|
2020-09-11 15:37:28 -07:00
|
|
|
|
|
|
|
#else
|
|
|
|
ESP_LOGI(TAG, "LWIP disabled");
|
|
|
|
#endif
|
2020-08-14 23:42:57 +08:00
|
|
|
}
|
|
|
|
|
2023-11-16 21:43:36 +08:00
|
|
|
#if CONFIG_SPIRAM
|
|
|
|
static esp_err_t esp_wifi_psram_check(const wifi_init_config_t *config)
|
|
|
|
{
|
|
|
|
#if CONFIG_SPIRAM_IGNORE_NOTFOUND
|
|
|
|
if (!esp_psram_is_initialized()) {
|
|
|
|
if (config->feature_caps & CONFIG_FEATURE_CACHE_TX_BUF_BIT) {
|
|
|
|
ESP_LOGW(TAG, "WiFi cache TX buffers should be disabled when initialize SPIRAM failed");
|
|
|
|
}
|
|
|
|
if (config->tx_buf_type == 0) {
|
|
|
|
ESP_LOGW(TAG, "TX buffers type should be changed from static to dynamic when initialize SPIRAM failed");
|
|
|
|
}
|
|
|
|
#ifdef CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP
|
|
|
|
ESP_LOGW(TAG, "WiFi/LWIP prefer SPIRAM should be disabled when initialize SPIRAM failed");
|
|
|
|
#endif
|
|
|
|
if (config->amsdu_tx_enable) {
|
|
|
|
ESP_LOGW(TAG, "WiFi AMSDU TX should be disabled when initialize SPIRAM failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if ((config->feature_caps & CONFIG_FEATURE_CACHE_TX_BUF_BIT) && (WIFI_CACHE_TX_BUFFER_NUM == 0)) {
|
|
|
|
ESP_LOGE(TAG, "Number of WiFi cache TX buffers should not equal 0 when enable SPIRAM");
|
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-10-13 09:47:19 +08:00
|
|
|
esp_err_t esp_wifi_init(const wifi_init_config_t *config)
|
2017-08-17 09:41:34 +05:30
|
|
|
{
|
2023-10-27 14:27:11 +08:00
|
|
|
if (s_wifi_inited) {
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
2023-11-16 21:43:36 +08:00
|
|
|
esp_err_t result = ESP_OK;
|
|
|
|
#ifdef CONFIG_SPIRAM
|
|
|
|
result = esp_wifi_psram_check(config);
|
|
|
|
if (result != ESP_OK) {
|
|
|
|
return result;
|
2022-11-02 15:02:02 +08:00
|
|
|
}
|
2023-11-16 21:43:36 +08:00
|
|
|
#endif
|
2021-01-28 22:28:04 +08:00
|
|
|
|
2021-02-23 10:17:27 +08:00
|
|
|
#if CONFIG_ESP_WIFI_SLP_IRAM_OPT
|
|
|
|
int min_freq_mhz = esp_pm_impl_get_cpu_freq(PM_MODE_LIGHT_SLEEP);
|
|
|
|
int max_freq_mhz = esp_pm_impl_get_cpu_freq(PM_MODE_CPU_MAX);
|
|
|
|
esp_wifi_internal_update_light_sleep_default_params(min_freq_mhz, max_freq_mhz);
|
|
|
|
|
2023-09-15 11:34:03 +08:00
|
|
|
esp_pm_register_light_sleep_default_params_config_callback(esp_wifi_internal_update_light_sleep_default_params);
|
|
|
|
|
2021-02-23 10:17:27 +08:00
|
|
|
uint32_t sleep_delay_us = CONFIG_ESP_WIFI_SLP_DEFAULT_MIN_ACTIVE_TIME * 1000;
|
|
|
|
esp_wifi_set_sleep_delay_time(sleep_delay_us);
|
|
|
|
|
|
|
|
uint32_t keep_alive_time_us = CONFIG_ESP_WIFI_SLP_DEFAULT_MAX_ACTIVE_TIME * 1000 * 1000;
|
|
|
|
esp_wifi_set_keep_alive_time(keep_alive_time_us);
|
|
|
|
#endif
|
|
|
|
|
2021-05-12 17:00:01 +08:00
|
|
|
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
|
|
|
#if CONFIG_MAC_BB_PD
|
|
|
|
if (esp_register_mac_bb_pd_callback(pm_mac_sleep) != ESP_OK
|
|
|
|
|| esp_register_mac_bb_pu_callback(pm_mac_wakeup) != ESP_OK) {
|
|
|
|
|
|
|
|
esp_unregister_mac_bb_pd_callback(pm_mac_sleep);
|
|
|
|
esp_unregister_mac_bb_pu_callback(pm_mac_wakeup);
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-01-10 16:16:28 +08:00
|
|
|
#if SOC_WIFI_HW_TSF
|
2020-05-07 16:15:56 +08:00
|
|
|
esp_err_t ret = esp_pm_register_skip_light_sleep_callback(esp_wifi_internal_is_tsf_active);
|
|
|
|
if (ret != ESP_OK) {
|
|
|
|
ESP_LOGE(TAG, "Failed to register skip light sleep callback (0x%x)", ret);
|
2021-01-28 22:28:04 +08:00
|
|
|
#if CONFIG_MAC_BB_PD
|
|
|
|
esp_unregister_mac_bb_pd_callback(pm_mac_sleep);
|
|
|
|
esp_unregister_mac_bb_pu_callback(pm_mac_wakeup);
|
|
|
|
#endif
|
2020-05-07 16:15:56 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2020-12-30 16:42:39 +08:00
|
|
|
ret = esp_pm_register_inform_out_light_sleep_overhead_callback(esp_wifi_internal_update_light_sleep_wake_ahead_time);
|
|
|
|
if (ret != ESP_OK) {
|
|
|
|
ESP_LOGE(TAG, "Failed to register inform light sleep overhead callback (0x%x)", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2020-05-07 16:15:56 +08:00
|
|
|
esp_sleep_enable_wifi_wakeup();
|
2023-02-05 17:03:07 +08:00
|
|
|
# if CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP
|
2022-03-14 11:33:01 +08:00
|
|
|
esp_sleep_enable_wifi_beacon_wakeup();
|
|
|
|
# endif
|
2021-10-25 21:19:47 +08:00
|
|
|
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
|
|
|
|
coex_wifi_register_update_lpclk_callback(esp_wifi_update_tsf_tick_interval);
|
|
|
|
#endif
|
2022-03-14 11:33:01 +08:00
|
|
|
#endif /* SOC_WIFI_HW_TSF */
|
|
|
|
#endif /* CONFIG_FREERTOS_USE_TICKLESS_IDLE */
|
2021-01-28 22:28:04 +08:00
|
|
|
|
2021-01-18 15:55:14 +08:00
|
|
|
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
|
2020-08-26 17:51:13 +08:00
|
|
|
coex_init();
|
2019-06-28 16:47:34 +02:00
|
|
|
#endif
|
2021-04-07 15:04:51 +08:00
|
|
|
esp_wifi_set_log_level();
|
2023-10-27 14:27:11 +08:00
|
|
|
esp_wifi_power_domain_on();
|
2023-11-16 21:43:36 +08:00
|
|
|
result = esp_wifi_init_internal(config);
|
2019-02-20 21:01:27 +08:00
|
|
|
if (result == ESP_OK) {
|
2021-01-28 22:28:04 +08:00
|
|
|
#if CONFIG_MAC_BB_PD
|
|
|
|
esp_mac_bb_pd_mem_init();
|
|
|
|
esp_wifi_internal_set_mac_sleep(true);
|
|
|
|
#endif
|
2022-11-24 20:18:27 +08:00
|
|
|
esp_phy_modem_init();
|
2023-09-15 11:34:03 +08:00
|
|
|
#if CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP
|
|
|
|
if (sleep_modem_wifi_modem_state_enabled()) {
|
|
|
|
esp_pm_register_skip_light_sleep_callback(sleep_modem_wifi_modem_state_skip_light_sleep);
|
|
|
|
esp_wifi_internal_modem_state_configure(true); /* require WiFi to enable automatically receives the beacon */
|
|
|
|
}
|
|
|
|
#endif
|
2019-06-17 11:50:37 +08:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
2019-02-20 21:01:27 +08:00
|
|
|
s_wifi_mac_time_update_cb = esp_wifi_internal_update_mac_time;
|
2019-06-17 11:50:37 +08:00
|
|
|
#endif
|
2018-08-13 16:37:56 +08:00
|
|
|
|
2023-10-27 14:27:11 +08:00
|
|
|
#ifdef CONFIG_PM_ENABLE
|
|
|
|
if (s_wifi_modem_sleep_lock == NULL) {
|
|
|
|
result = esp_pm_lock_create(ESP_PM_APB_FREQ_MAX, 0, "wifi",
|
|
|
|
&s_wifi_modem_sleep_lock);
|
|
|
|
if (result != ESP_OK) {
|
|
|
|
ESP_LOGE(TAG, "Failed to create pm lock (0x%x)", result);
|
|
|
|
goto _deinit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-08-13 16:37:56 +08:00
|
|
|
result = esp_supplicant_init();
|
|
|
|
if (result != ESP_OK) {
|
|
|
|
ESP_LOGE(TAG, "Failed to init supplicant (0x%x)", result);
|
2023-10-27 14:27:11 +08:00
|
|
|
goto _deinit;
|
2020-11-10 18:40:01 +11:00
|
|
|
}
|
2023-10-27 14:27:11 +08:00
|
|
|
} else {
|
|
|
|
goto _deinit;
|
2019-02-20 21:01:27 +08:00
|
|
|
}
|
2021-06-02 19:35:41 +08:00
|
|
|
#if CONFIG_ESP_WIFI_SLP_BEACON_LOST_OPT
|
2023-02-05 17:03:07 +08:00
|
|
|
wifi_beacon_monitor_config_t monitor_config = WIFI_BEACON_MONITOR_CONFIG_DEFAULT(true);
|
|
|
|
esp_wifi_beacon_monitor_configure(&monitor_config);
|
2021-06-02 19:35:41 +08:00
|
|
|
#endif
|
2020-04-02 11:20:38 +08:00
|
|
|
adc2_cal_include(); //This enables the ADC2 calibration constructor at start up.
|
2021-01-21 19:55:39 +05:30
|
|
|
|
2020-08-14 23:42:57 +08:00
|
|
|
esp_wifi_config_info();
|
2023-02-14 10:06:40 +05:30
|
|
|
|
|
|
|
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
|
|
|
|
esp_nan_app_init();
|
|
|
|
#endif
|
|
|
|
|
2023-10-27 14:27:11 +08:00
|
|
|
s_wifi_inited = true;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
_deinit:
|
|
|
|
;
|
|
|
|
esp_err_t deinit_ret = wifi_deinit_internal();
|
|
|
|
if (deinit_ret != ESP_OK) {
|
|
|
|
ESP_LOGE(TAG, "Failed to deinit Wi-Fi (0x%x)", deinit_ret);
|
|
|
|
}
|
|
|
|
|
2018-10-29 17:12:08 +08:00
|
|
|
return result;
|
2017-09-22 23:34:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM_ENABLE
|
|
|
|
void wifi_apb80m_request(void)
|
|
|
|
{
|
|
|
|
assert(s_wifi_modem_sleep_lock);
|
|
|
|
esp_pm_lock_acquire(s_wifi_modem_sleep_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void wifi_apb80m_release(void)
|
|
|
|
{
|
|
|
|
assert(s_wifi_modem_sleep_lock);
|
|
|
|
esp_pm_lock_release(s_wifi_modem_sleep_lock);
|
2017-08-17 09:41:34 +05:30
|
|
|
}
|
2017-09-22 23:34:52 +08:00
|
|
|
#endif //CONFIG_PM_ENABLE
|
2020-01-02 10:44:45 +01:00
|
|
|
|
2021-03-15 14:26:18 +05:30
|
|
|
#ifndef CONFIG_ESP_WIFI_FTM_ENABLE
|
|
|
|
void ieee80211_ftm_attach(void)
|
|
|
|
{
|
|
|
|
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
|
|
|
|
}
|
|
|
|
#endif
|
2021-04-07 15:04:51 +08:00
|
|
|
|
|
|
|
#ifndef CONFIG_ESP_WIFI_SOFTAP_SUPPORT
|
|
|
|
void net80211_softap_funcs_init(void)
|
|
|
|
{
|
2023-08-25 15:30:33 +08:00
|
|
|
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ieee80211_ap_try_sa_query(void *p)
|
|
|
|
{
|
|
|
|
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ieee80211_ap_sa_query_timeout(void *p)
|
|
|
|
{
|
|
|
|
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int add_mic_ie_bip(void *p)
|
|
|
|
{
|
|
|
|
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ieee80211_free_beacon_eb(void)
|
|
|
|
{
|
|
|
|
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
|
|
|
|
}
|
|
|
|
|
|
|
|
int ieee80211_pwrsave(void *p1, void *p2)
|
|
|
|
{
|
|
|
|
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cnx_node_remove(void *p)
|
|
|
|
{
|
|
|
|
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
|
2021-04-07 15:04:51 +08:00
|
|
|
}
|
2023-08-25 15:30:33 +08:00
|
|
|
|
|
|
|
int ieee80211_set_tim(void *p, int arg)
|
|
|
|
{
|
|
|
|
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ieee80211_is_bufferable_mmpdu(void *p)
|
|
|
|
{
|
|
|
|
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cnx_node_leave(void *p, uint8_t arg)
|
|
|
|
{
|
|
|
|
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
|
|
|
|
}
|
|
|
|
|
|
|
|
void ieee80211_beacon_construct(void *p1, void *p2, void *p3, void *p4)
|
|
|
|
{
|
|
|
|
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
|
|
|
|
}
|
|
|
|
|
|
|
|
void * ieee80211_assoc_resp_construct(void *p, int arg)
|
|
|
|
{
|
|
|
|
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void * ieee80211_alloc_proberesp(void *p, int arg)
|
|
|
|
{
|
|
|
|
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-04-07 15:04:51 +08:00
|
|
|
#endif
|
2023-02-14 10:06:40 +05:30
|
|
|
|
|
|
|
#ifndef CONFIG_ESP_WIFI_NAN_ENABLE
|
|
|
|
|
|
|
|
esp_err_t nan_start(void)
|
|
|
|
{
|
|
|
|
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t nan_stop(void)
|
|
|
|
{
|
|
|
|
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int nan_input(void *p1, int p2, int p3)
|
|
|
|
{
|
|
|
|
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nan_sm_handle_event(void *p1, int p2)
|
|
|
|
{
|
|
|
|
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|