Merge branch 'bugfix/fix_some_wifi_bugs_1222_v4.2' into 'release/v4.2'

esp_wifi: fix some wifi bugs 1222 (backport v4.2)

See merge request espressif/esp-idf!11711
This commit is contained in:
Jiang Jiang Jian 2020-12-23 12:04:22 +08:00
commit ac5b7be7c2
14 changed files with 396 additions and 52 deletions

View File

@ -350,7 +350,7 @@ static const esp_err_msg_t esp_err_msg_table[] = {
ERR_TBL_IT(ESP_ERR_WIFI_POST), /* 12306 0x3012 Failed to post the event to WiFi task */
# endif
# ifdef ESP_ERR_WIFI_INIT_STATE
ERR_TBL_IT(ESP_ERR_WIFI_INIT_STATE), /* 12307 0x3013 Invalod WiFi state when init/deinit is called */
ERR_TBL_IT(ESP_ERR_WIFI_INIT_STATE), /* 12307 0x3013 Invalid WiFi state when init/deinit is called */
# endif
# ifdef ESP_ERR_WIFI_STOP_STATE
ERR_TBL_IT(ESP_ERR_WIFI_STOP_STATE), /* 12308 0x3014 Returned when WiFi is stopping */

View File

@ -252,7 +252,7 @@ esp_err_t esp_now_mod_peer(const esp_now_peer_info_t *peer);
esp_err_t esp_now_get_peer(const uint8_t *peer_addr, esp_now_peer_info_t *peer);
/**
* @brief Fetch a peer from peer list
* @brief Fetch a peer from peer list. Only return the peer which address is unicast, for the multicast/broadcast address, the function will ignore and try to find the next in the peer list.
*
* @param from_head fetch from head of list or not
* @param peer peer information

View File

@ -86,7 +86,7 @@ extern "C" {
#define ESP_ERR_WIFI_NOT_CONNECT (ESP_ERR_WIFI_BASE + 15) /*!< Station still in disconnect status */
#define ESP_ERR_WIFI_POST (ESP_ERR_WIFI_BASE + 18) /*!< Failed to post the event to WiFi task */
#define ESP_ERR_WIFI_INIT_STATE (ESP_ERR_WIFI_BASE + 19) /*!< Invalod WiFi state when init/deinit is called */
#define ESP_ERR_WIFI_INIT_STATE (ESP_ERR_WIFI_BASE + 19) /*!< Invalid WiFi state when init/deinit is called */
#define ESP_ERR_WIFI_STOP_STATE (ESP_ERR_WIFI_BASE + 20) /*!< Returned when WiFi is stopping */
#define ESP_ERR_WIFI_NOT_ASSOC (ESP_ERR_WIFI_BASE + 21) /*!< The WiFi connection is not associated */
#define ESP_ERR_WIFI_TX_DISALLOW (ESP_ERR_WIFI_BASE + 22) /*!< The WiFi TX is disallowed */
@ -313,7 +313,7 @@ esp_err_t esp_wifi_stop(void);
* @brief Restore WiFi stack persistent settings to default values
*
* This function will reset settings made using the following APIs:
* - esp_wifi_get_auto_connect,
* - esp_wifi_set_bandwidth,
* - esp_wifi_set_protocol,
* - esp_wifi_set_config related
* - esp_wifi_set_mode
@ -889,32 +889,8 @@ esp_err_t esp_wifi_set_vendor_ie_cb(esp_vendor_ie_cb_t cb, void *ctx);
* @attention 3. Mapping Table {Power, max_tx_power} = {{8, 2}, {20, 5}, {28, 7}, {34, 8}, {44, 11},
* {52, 13}, {56, 14}, {60, 15}, {66, 16}, {72, 18}, {78, 20}}.
* @attention 4. Param power unit is 0.25dBm, range is [8, 78] corresponding to 2dBm - 20dBm.
* @attention 5. Relationship between set value and actual value. As follows:
* +------------+--------------+
* | set value | actual value |
* +============+==============+
* | [8, 19] | 8 |
* +------------+--------------+
* | [20, 27] | 20 |
* +------------+--------------+
* | [28, 33] | 28 |
* +------------+--------------+
* | [34, 43] | 34 |
* +------------+--------------+
* | [44, 51] | 44 |
* +------------+--------------+
* | [52, 55] | 52 |
* +------------+--------------+
* | [56, 59] | 56 |
* +------------+--------------+
* | [60, 65] | 60 |
* +------------+--------------+
* | [66, 71] | 66 |
* +------------+--------------+
* | [72, 77] | 72 |
* +------------+--------------+
* | 78 | 78 |
* +------------+--------------+
* @attention 5. Relationship between set value and actual value. As follows: {set value range, actual value} = {{[8, 19],8}, {[20, 27],20}, {[28, 33],28}, {[34, 43],34}, {[44, 51],44}, {[52, 55],52}, {[56, 59],56}, {[60, 65],60}, {[66, 71],66}, {[72, 77],72}, {78,78}}
*
* @param power Maximum WiFi transmitting power.
*
* @return

View File

@ -214,7 +214,7 @@ typedef struct {
/** @brief Soft-AP configuration settings for the ESP32 */
typedef struct {
uint8_t ssid[32]; /**< SSID of ESP32 soft-AP. If ssid_len field is 0, this must be a Null terminated string. Otherwise, length is set according to ssid_len. */
uint8_t password[64]; /**< Password of ESP32 soft-AP. Null terminated string. */
uint8_t password[64]; /**< Password of ESP32 soft-AP. */
uint8_t ssid_len; /**< Optional length of SSID field. */
uint8_t channel; /**< Channel of ESP32 soft-AP */
wifi_auth_mode_t authmode; /**< Auth mode of ESP32 soft-AP. Do not support AUTH_WEP in soft-AP mode */
@ -225,8 +225,8 @@ typedef struct {
/** @brief STA configuration settings for the ESP32 */
typedef struct {
uint8_t ssid[32]; /**< SSID of target AP. Null terminated string. */
uint8_t password[64]; /**< Password of target AP. Null terminated string.*/
uint8_t ssid[32]; /**< SSID of target AP. */
uint8_t password[64]; /**< Password of target AP. */
wifi_scan_method_t scan_method; /**< do all channel scan or fast scan */
bool bssid_set; /**< whether set MAC address of target AP or not. Generally, station_config.bssid_set needs to be 0; and it needs to be 1 only when users need to check the MAC address of the AP.*/
uint8_t bssid[6]; /**< MAC address of target AP*/

@ -1 +1 @@
Subproject commit 72d8c863a500cfaa7f0e91884c14842838cc29a6
Subproject commit 80360734238c5cebe2d93386701e758cc2f2020c

View File

@ -27,6 +27,7 @@ set(srcs "port/os_xtensa.c"
"src/crypto/crypto_internal-cipher.c"
"src/crypto/crypto_internal-modexp.c"
"src/crypto/crypto_internal-rsa.c"
"src/crypto/crypto_mbedtls-rsa.c"
"src/crypto/crypto_internal.c"
"src/crypto/des-internal.c"
"src/crypto/dh_group5.c"
@ -128,9 +129,12 @@ target_compile_definitions(${COMPONENT_LIB} PRIVATE
ESP32_WORKAROUND
CONFIG_ECC
CONFIG_IEEE80211W
CONFIG_WPA3_SAE
CONFIG_SHA256
CONFIG_DPP
)
if(CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE)
target_compile_definitions(${COMPONENT_LIB} PRIVATE CONFIG_WPA3_SAE)
endif()
set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY LINK_INTERFACE_MULTIPLICITY 3)

View File

@ -26,4 +26,8 @@ else
COMPONENT_OBJEXCLUDE := src/crypto/tls_mbedtls.o
endif
CFLAGS += -DCONFIG_DPP -DCONFIG_WPA3_SAE -DCONFIG_IEEE80211W -DESP_SUPPLICANT -DIEEE8021X_EAPOL -DEAP_PEER_METHOD -DEAP_TLS -DEAP_TTLS -DEAP_PEAP -DEAP_MSCHAPv2 -DUSE_WPA2_TASK -DCONFIG_WPS2 -DCONFIG_WPS_PIN -DUSE_WPS_TASK -DESPRESSIF_USE -DESP32_WORKAROUND -DCONFIG_ECC -D__ets__ -Wno-strict-aliasing
CFLAGS += -DCONFIG_DPP -DCONFIG_IEEE80211W -DESP_SUPPLICANT -DIEEE8021X_EAPOL -DEAP_PEER_METHOD -DEAP_TLS -DEAP_TTLS -DEAP_PEAP -DEAP_MSCHAPv2 -DUSE_WPA2_TASK -DCONFIG_WPS2 -DCONFIG_WPS_PIN -DUSE_WPS_TASK -DESPRESSIF_USE -DESP32_WORKAROUND -DCONFIG_ECC -D__ets__ -Wno-strict-aliasing
ifdef CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE
CFLAGS += -DCONFIG_WPA3_SAE
endif

View File

@ -58,11 +58,11 @@ static int rsn_key_mgmt_to_bitfield(const u8 *s)
if (RSN_SELECTOR_GET(s) == RSN_AUTH_KEY_MGMT_FT_PSK)
return WPA_KEY_MGMT_FT_PSK;
#endif /* CONFIG_IEEE80211R */
#ifdef CONFIG_IEEE80211W
#ifdef CONFIG_WPA3_SAE
if (RSN_SELECTOR_GET(s) == RSN_AUTH_KEY_MGMT_SAE)
return WPA_KEY_MGMT_SAE;
#endif /* CONFIG_WPA3_SAE */
#ifdef CONFIG_IEEE80211W
if (RSN_SELECTOR_GET(s) == RSN_AUTH_KEY_MGMT_802_1X_SHA256)
return WPA_KEY_MGMT_IEEE8021X_SHA256;
if (RSN_SELECTOR_GET(s) == RSN_AUTH_KEY_MGMT_PSK_SHA256)
@ -396,10 +396,10 @@ int wpa_eapol_key_mic(const u8 *key, int ver, const u8 *buf, size_t len,
#ifdef CONFIG_IEEE80211W
#ifdef CONFIG_WPA3_SAE
case WPA_KEY_INFO_TYPE_AKM_DEFINED:
#endif
#endif /* CONFIG_WPA3_SAE */
case WPA_KEY_INFO_TYPE_AES_128_CMAC:
return omac1_aes_128(key, buf, len, mic);
#endif
#endif /* CONFIG_IEEE80211W */
default:
return -1;
}

View File

@ -17,6 +17,7 @@
#include "tls/pkcs1.h"
#include "tls/pkcs8.h"
#ifndef USE_MBEDTLS_CRYPTO
/* Dummy structures; these are just typecast to struct crypto_rsa_key */
struct crypto_public_key;
struct crypto_private_key;
@ -28,7 +29,6 @@ struct crypto_public_key * crypto_public_key_import(const u8 *key, size_t len)
crypto_rsa_import_public_key(key, len);
}
struct crypto_private_key * crypto_private_key_import(const u8 *key,
size_t len,
const char *passwd)
@ -109,3 +109,4 @@ int crypto_public_key_decrypt_pkcs1(struct crypto_public_key *key,
return pkcs1_decrypt_public_key((struct crypto_rsa_key *) key,
crypt, crypt_len, plain, plain_len);
}
#endif

View File

@ -0,0 +1,356 @@
/*
* Copyright (C) Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD, Apache 2.0 License.
*
*
* Licensed 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.
*/
#ifdef ESP_PLATFORM
#include "mbedtls/bignum.h"
#endif
#include "utils/includes.h"
#include "utils/common.h"
#include "crypto.h"
#include "common/defs.h"
#ifdef USE_MBEDTLS_CRYPTO
#include "mbedtls/entropy.h"
#include "mbedtls/ctr_drbg.h"
#include <mbedtls/error.h>
#include <mbedtls/x509_crt.h>
#include <mbedtls/platform.h>
#include <mbedtls/sha256.h>
/* Dummy structures; these are just typecast to struct crypto_rsa_key */
struct crypto_public_key;
struct crypto_private_key;
static void crypto_dump_verify_info(u32 flags)
{
char dump_buffer[1024];
mbedtls_x509_crt_verify_info(dump_buffer, 1024, " ! ", flags );
wpa_printf(MSG_ERROR, "%s", dump_buffer);
}
int crypto_verify_cert(const u8 *cert_start, int certlen, const u8 *ca_cert_start, int ca_certlen)
{
int ret;
u32 flags = 0;
mbedtls_x509_crt *cert = os_zalloc(sizeof(mbedtls_x509_crt));
mbedtls_x509_crt *ca_cert = os_zalloc(sizeof(mbedtls_x509_crt));
if (!cert || !ca_cert) {
if (cert)
os_free(cert);
if (ca_cert)
os_free(ca_cert);
wpa_printf(MSG_ERROR, "%s: memory allocation failed", __func__);
return -1;
}
mbedtls_x509_crt_init(cert);
mbedtls_x509_crt_init(ca_cert);
ret = mbedtls_x509_crt_parse(cert, cert_start, certlen);
if (ret < 0) {
wpa_printf(MSG_ERROR, "peer cert parsing failed");
goto cleanup;
}
ret = mbedtls_x509_crt_parse(ca_cert, ca_cert_start, ca_certlen);
if (ret < 0) {
wpa_printf(MSG_ERROR, "CA cert parsing failed");
goto cleanup;
}
ret = mbedtls_x509_crt_verify(cert, ca_cert, NULL, NULL, &flags, NULL, NULL );
/* Certification is failed, try to get some more info */
if (ret != 0)
crypto_dump_verify_info(flags);
cleanup:
mbedtls_x509_crt_free(cert);
mbedtls_x509_crt_free(ca_cert);
os_free(cert);
os_free(ca_cert);
return ret;
}
struct crypto_public_key * crypto_public_key_import(const u8 *key, size_t len)
{
int ret;
mbedtls_pk_context *pkey = os_zalloc(sizeof(*pkey));
if (!pkey)
return NULL;
mbedtls_pk_init(pkey);
ret = mbedtls_pk_parse_public_key(pkey, key, len);
if (ret < 0) {
wpa_printf(MSG_ERROR, "failed to parse public key");
os_free(pkey);
return NULL;
}
return (struct crypto_public_key *)pkey;
}
struct crypto_private_key * crypto_private_key_import(const u8 *key,
size_t len,
const char *passwd)
{
int ret;
mbedtls_pk_context *pkey = os_zalloc(sizeof(mbedtls_pk_context));
if (!pkey)
return NULL;
mbedtls_pk_init(pkey);
ret = mbedtls_pk_parse_key(pkey, key, len, (const unsigned char *)passwd, passwd ? os_strlen(passwd) : 0);
if (ret < 0) {
wpa_printf(MSG_ERROR, "failed to parse private key");
os_free(pkey);
pkey = NULL;
}
return (struct crypto_private_key *)pkey;
}
struct crypto_public_key *crypto_public_key_from_cert(const u8 *buf,
size_t len)
{
int ret;
mbedtls_x509_crt *cert;
mbedtls_pk_context *kctx = os_zalloc(sizeof(*kctx));
if (!kctx) {
wpa_printf(MSG_ERROR, "failed to allocate memory");
return NULL;
}
cert = os_zalloc(sizeof(mbedtls_x509_crt));
if (!cert) {
wpa_printf(MSG_ERROR, "failed to allocate memory");
goto fail;
}
mbedtls_x509_crt_init(cert);
ret = mbedtls_x509_crt_parse(cert, buf, len);
if (ret < 0) {
wpa_printf(MSG_ERROR, "cert parsing failed");
goto fail;
}
mbedtls_pk_init(kctx);
if(mbedtls_pk_setup(kctx, mbedtls_pk_info_from_type(mbedtls_pk_get_type(&cert->pk))) != 0) {
wpa_printf(MSG_ERROR, "key setup failed");
goto fail;
}
ret = mbedtls_rsa_copy(mbedtls_pk_rsa(*kctx), mbedtls_pk_rsa(cert->pk));
if (ret < 0) {
wpa_printf(MSG_ERROR, "key copy failed");
goto fail;
}
cleanup:
mbedtls_x509_crt_free(cert);
os_free(cert);
return (struct crypto_public_key *)kctx;
fail:
os_free(kctx);
kctx = NULL;
goto cleanup;
}
int crypto_public_key_encrypt_pkcs1_v15(struct crypto_public_key *key,
const u8 *in, size_t inlen,
u8 *out, size_t *outlen)
{
int ret;
mbedtls_pk_context *pkey = (mbedtls_pk_context *)key;
const char *pers = "rsa_encrypt";
mbedtls_entropy_context *entropy = os_zalloc(sizeof(*entropy));
mbedtls_ctr_drbg_context *ctr_drbg = os_zalloc(sizeof(*ctr_drbg));
if (!pkey || !entropy || !ctr_drbg) {
if (entropy)
os_free(entropy);
if (ctr_drbg)
os_free(ctr_drbg);
wpa_printf(MSG_ERROR, "failed to allocate memory");
return -1;
}
mbedtls_entropy_init( entropy );
mbedtls_ctr_drbg_init( ctr_drbg );
ret = mbedtls_ctr_drbg_seed( ctr_drbg, mbedtls_entropy_func,
entropy, (const unsigned char *) pers,
strlen( pers ) );
if( ret != 0 ) {
wpa_printf(MSG_ERROR, " failed ! mbedtls_ctr_drbg_seed returned %d",
ret );
goto cleanup;
}
ret = mbedtls_rsa_pkcs1_encrypt(mbedtls_pk_rsa(*pkey), mbedtls_ctr_drbg_random,
ctr_drbg, MBEDTLS_RSA_PUBLIC, inlen, in, out);
if(ret != 0) {
wpa_printf(MSG_ERROR, " failed ! mbedtls_rsa_pkcs1_encrypt returned -0x%04x", -ret);
goto cleanup;
}
*outlen = mbedtls_pk_rsa(*pkey)->len;
cleanup:
mbedtls_ctr_drbg_free( ctr_drbg );
mbedtls_entropy_free( entropy );
os_free(entropy);
os_free(ctr_drbg);
return ret;
}
int crypto_private_key_decrypt_pkcs1_v15(struct crypto_private_key *key,
const u8 *in, size_t inlen,
u8 *out, size_t *outlen)
{
int ret;
size_t i;
mbedtls_pk_context *pkey = (mbedtls_pk_context *)key;
const char *pers = "rsa_decrypt";
mbedtls_entropy_context *entropy = os_malloc(sizeof(*entropy));
mbedtls_ctr_drbg_context *ctr_drbg = os_malloc(sizeof(*ctr_drbg));
if (!pkey || !entropy || !ctr_drbg) {
if (entropy)
os_free(entropy);
if (ctr_drbg)
os_free(ctr_drbg);
return -1;
}
mbedtls_ctr_drbg_init( ctr_drbg );
mbedtls_entropy_init( entropy );
ret = mbedtls_ctr_drbg_seed(ctr_drbg, mbedtls_entropy_func,
entropy, (const unsigned char *) pers,
strlen(pers));
if (ret < 0)
goto cleanup;
i = mbedtls_pk_rsa(*pkey)->len;
ret = mbedtls_rsa_rsaes_pkcs1_v15_decrypt(mbedtls_pk_rsa(*pkey), mbedtls_ctr_drbg_random,
ctr_drbg, MBEDTLS_RSA_PRIVATE, &i, in, out, *outlen);
*outlen = i;
cleanup:
mbedtls_ctr_drbg_free( ctr_drbg );
mbedtls_entropy_free( entropy );
os_free(entropy);
os_free(ctr_drbg);
return ret;
}
int crypto_private_key_sign_pkcs1(struct crypto_private_key *key,
const u8 *in, size_t inlen,
u8 *out, size_t *outlen)
{
int ret;
mbedtls_pk_context *pkey = (mbedtls_pk_context *)key;
if((ret = mbedtls_rsa_pkcs1_sign(mbedtls_pk_rsa(*pkey), NULL, NULL, MBEDTLS_RSA_PRIVATE,
(mbedtls_pk_rsa(*pkey))->hash_id,
inlen, in, out)) != 0 ) {
wpa_printf(MSG_ERROR, " failed ! mbedtls_rsa_pkcs1_sign returned %d", ret );
return -1;
}
*outlen = mbedtls_pk_rsa(*pkey)->len;
return 0;
}
void crypto_public_key_free(struct crypto_public_key *key)
{
mbedtls_pk_context *pkey = (mbedtls_pk_context *)key;
if (!pkey)
return;
mbedtls_pk_free(pkey);
os_free(pkey);
}
void crypto_private_key_free(struct crypto_private_key *key)
{
mbedtls_pk_context *pkey = (mbedtls_pk_context *)key;
if (!pkey)
return;
mbedtls_pk_free(pkey);
os_free(pkey);
}
int crypto_public_key_decrypt_pkcs1(struct crypto_public_key *key,
const u8 *crypt, size_t crypt_len,
u8 *plain, size_t *plain_len)
{
const char *pers = "rsa_decrypt";
mbedtls_pk_context *pkey = (mbedtls_pk_context *)key;
mbedtls_ctr_drbg_context ctr_drbg;
mbedtls_entropy_context entropy;
size_t i;
mbedtls_entropy_init( &entropy );
mbedtls_ctr_drbg_init( &ctr_drbg );
int ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func,
&entropy, (const unsigned char *) pers,
strlen( pers ) );
if(ret != 0) {
wpa_printf(MSG_ERROR, " failed ! mbedtls_ctr_drbg_seed returned %d",
ret );
goto cleanup;
}
i = mbedtls_pk_rsa(*pkey)->len;
ret = mbedtls_rsa_pkcs1_decrypt(mbedtls_pk_rsa(*pkey), mbedtls_ctr_drbg_random,
&ctr_drbg, MBEDTLS_RSA_PUBLIC, &i,
crypt, plain, *plain_len);
if( ret != 0 ) {
wpa_printf(MSG_ERROR, " failed ! mbedtls_rsa_pkcs1_decrypt returned %d",
ret );
goto cleanup;
}
*plain_len = i;
cleanup:
mbedtls_entropy_free( &entropy );
mbedtls_ctr_drbg_free( &ctr_drbg );
return ret;
}
#endif

View File

@ -31,5 +31,9 @@ static inline void esp_wifi_register_wpa3_cb(struct wpa_funcs *wpa_cb)
wpa_cb->wpa3_parse_sae_msg = NULL;
}
static inline void esp_wpa3_free_sae_data(void)
{
}
#endif /* CONFIG_WPA3_SAE */
#endif /* ESP_WPA3_H */

View File

@ -203,11 +203,11 @@ static int wpa_gen_wpa_ie_rsn(u8 *rsn_ie, size_t rsn_ie_len,
RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_802_1X_SHA256);
} else if (key_mgmt == WPA_KEY_MGMT_PSK_SHA256) {
RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_PSK_SHA256);
#endif /* CONFIG_IEEE80211W */
#ifdef CONFIG_WPA3_SAE
} else if (key_mgmt == WPA_KEY_MGMT_SAE) {
RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_SAE);
#endif /* CONFIG_WPA3_SAE */
#endif /* CONFIG_IEEE80211W */
} else {
wpa_printf(MSG_DEBUG, "Invalid key management type (%d).",
key_mgmt);

View File

@ -163,8 +163,8 @@ WIFI_EVENT_STA_DISCONNECTED
++++++++++++++++++++++++++++++++++++
This event can be generated in the following scenarios:
- When esp_wifi_disconnect(), or esp_wifi_stop(), or esp_wifi_deinit(), or esp_wifi_restart() is called and the station is already connected to the AP.
- When esp_wifi_connect() is called, but the Wi-Fi driver fails to set up a connection with the AP due to certain reasons, e.g. the scan fails to find the target AP, authentication times out, etc. If there are more than one AP with the same SSID, the disconnected event is raised after the station fails to connect all of the found APs.
- When :cpp:func:`esp_wifi_disconnect()`, or :cpp:func:`esp_wifi_stop()`, or :cpp:func:`esp_wifi_deinit()` is called and the station is already connected to the AP.
- When :cpp:func:`esp_wifi_connect()` is called, but the Wi-Fi driver fails to set up a connection with the AP due to certain reasons, e.g. the scan fails to find the target AP, authentication times out, etc. If there are more than one AP with the same SSID, the disconnected event is raised after the station fails to connect all of the found APs.
- When the Wi-Fi connection is disrupted because of specific reasons, e.g., the station continuously loses N beacons, the AP kicks off the station, the AP's authentication mode is changed, etc.
Upon receiving this event, the default behavior of the event task is:
@ -224,8 +224,8 @@ WIFI_EVENT_AP_STADISCONNECTED
++++++++++++++++++++++++++++++++++++
This event can happen in the following scenarios:
- The application calls esp_wifi_disconnect(), or esp_wifi_deauth_sta(), to manually disconnect the station.
- The Wi-Fi driver kicks off the station, e.g. because the AP has not received any packets in the past five minutes, etc.
- The application calls :cpp:func:`esp_wifi_disconnect()`, or esp_wifi_deauth_sta(), to manually disconnect the station.
- The Wi-Fi driver kicks off the station, e.g. because the AP has not received any packets in the past five minutes, etc. The time can be modified by :cpp:func:`esp_wifi_set_inactive_time`.
- The station kicks off the AP.
When this event happens, the event task will do nothing, but the application event callback needs to do something, e.g., close the socket which is related to this station, etc.
@ -1447,7 +1447,7 @@ In maximum power save mode, station wakes up every listen interval to receive be
Call ``esp_wifi_set_ps(WIFI_PS_MIN_MODEM)`` to enable Modem-sleep minimum power save mode or ``esp_wifi_set_ps(WIFI_PS_MAX_MODEM)`` to enable Modem-sleep maximum power save mode after calling :cpp:func:`esp_wifi_init`. When station connects to AP, Modem-sleep will start. When station disconnects from AP, Modem-sleep will stop.
Call ``esp_wifi_set_ps(WIFI_PS_NONE)`` to disable modem sleep entirely. This has much higher power consumption, but provides minimum latency for receiving Wi-Fi data in real time. When modem sleep is enabled, received Wi-Fi data can be delayed for as long as the DTIM period (minimum power save mode) or the listen interval (maximum power save mode).
Call ``esp_wifi_set_ps(WIFI_PS_NONE)`` to disable modem sleep entirely. This has much higher power consumption, but provides minimum latency for receiving Wi-Fi data in real time. When modem sleep is enabled, received Wi-Fi data can be delayed for as long as the DTIM period (minimum power save mode) or the listen interval (maximum power save mode). Disabling modem sleep entirely is not possible for Wi-Fi and Bluetooth coexist mode.
The default Modem-sleep mode is WIFI_PS_MIN_MODEM.
@ -1494,9 +1494,7 @@ When the throughput is tested by iperf example, the sdkconfig is :idf_file:`exam
Wi-Fi 80211 Packet Send
---------------------------
**Important notes: The API esp_wifi_80211_tx is not available in IDF 2.1, but will be so in the upcoming release.**
The esp_wifi_80211_tx API can be used to:
The :cpp:func:`esp_wifi_80211_tx` API can be used to:
- Send the beacon, probe request, probe response, action frame.
- Send the non-QoS data frame.
@ -1834,6 +1832,7 @@ So, the peak memory that the Wi-Fi driver consumes can be calculated with the fo
Generally, we do not need to care about the dynamic tx long buffers and dynamic tx long long buffers, because they are management frames which only have a small impact on the system.
Wi-Fi Menuconfig
-----------------------

View File

@ -124,7 +124,7 @@ static esp_err_t IRAM_ATTR iperf_run_tcp_server(void)
int listen_socket;
struct timeval t;
int sockfd;
int opt;
int opt = 1;
listen_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (listen_socket < 0) {
@ -195,7 +195,7 @@ static esp_err_t IRAM_ATTR iperf_run_udp_server(void)
int want_recv = 0;
uint8_t *buffer;
int sockfd;
int opt;
int opt = 1;
bool udp_recv_start = true ;
sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
@ -253,7 +253,7 @@ static esp_err_t iperf_run_udp_client(void)
int want_send = 0;
uint8_t *buffer;
int sockfd;
int opt;
int opt = 1;
int err;
int id;