Merge branch 'bugfix/fix_some_wifi_bugs_230913_v5.1' into 'release/v5.1'

fix(wifi): fix some wifi bugs 20230913(Backport v5.1)

See merge request espressif/esp-idf!25960
This commit is contained in:
Jiang Jiang Jian 2023-09-18 12:09:31 +08:00
commit 8ce86c32d0
38 changed files with 1094 additions and 183 deletions

View File

@ -1682,7 +1682,7 @@ lmacProcessCollisions_task = 0x40001dbc;
lmacInitAc = 0x40001dc4; lmacInitAc = 0x40001dc4;
lmacInit = 0x40001dc8; lmacInit = 0x40001dc8;
mac_tx_set_txop_q = 0x40001dcc; mac_tx_set_txop_q = 0x40001dcc;
hal_init = 0x40001dd0; /*hal_init = 0x40001dd0;*/
hal_mac_rx_set_policy = 0x40001dd4; hal_mac_rx_set_policy = 0x40001dd4;
hal_mac_set_bssid = 0x40001dd8; hal_mac_set_bssid = 0x40001dd8;
mac_rx_policy_init = 0x40001ddc; mac_rx_policy_init = 0x40001ddc;

View File

@ -38,7 +38,7 @@ ieee80211_is_tx_allowed = 0x40000b8c;
ieee80211_output_pending_eb = 0x40000b90; ieee80211_output_pending_eb = 0x40000b90;
ieee80211_output_process = 0x40000b94; ieee80211_output_process = 0x40000b94;
ieee80211_set_tx_desc = 0x40000b98; ieee80211_set_tx_desc = 0x40000b98;
sta_input = 0x40000b9c; //sta_input = 0x40000b9c;
wifi_get_macaddr = 0x40000ba0; wifi_get_macaddr = 0x40000ba0;
wifi_rf_phy_disable = 0x40000ba4; wifi_rf_phy_disable = 0x40000ba4;
wifi_rf_phy_enable = 0x40000ba8; wifi_rf_phy_enable = 0x40000ba8;

View File

@ -52,7 +52,6 @@
#else #else
#define ESP_TASKD_EVENT_STACK (CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE + TASK_EXTRA_STACK_SIZE) #define ESP_TASKD_EVENT_STACK (CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE + TASK_EXTRA_STACK_SIZE)
#endif /* CONFIG_LWIP_TCPIP_CORE_LOCKING */ #endif /* CONFIG_LWIP_TCPIP_CORE_LOCKING */
#define ESP_TASK_TCPIP_PRIO (ESP_TASK_PRIO_MAX - 7)
#define ESP_TASK_TCPIP_STACK (CONFIG_LWIP_TCPIP_TASK_STACK_SIZE + TASK_EXTRA_STACK_SIZE) #define ESP_TASK_TCPIP_STACK (CONFIG_LWIP_TCPIP_TASK_STACK_SIZE + TASK_EXTRA_STACK_SIZE)
#define ESP_TASK_MAIN_PRIO (ESP_TASK_PRIO_MIN + 1) #define ESP_TASK_MAIN_PRIO (ESP_TASK_PRIO_MIN + 1)
#define ESP_TASK_MAIN_STACK (CONFIG_ESP_MAIN_TASK_STACK_SIZE + TASK_EXTRA_STACK_SIZE) #define ESP_TASK_MAIN_STACK (CONFIG_ESP_MAIN_TASK_STACK_SIZE + TASK_EXTRA_STACK_SIZE)

View File

@ -226,6 +226,15 @@ menu "Wi-Fi"
When this option is disabled, more than 10Kbytes of IRAM memory will be saved When this option is disabled, more than 10Kbytes of IRAM memory will be saved
but Wi-Fi throughput will be reduced. but Wi-Fi throughput will be reduced.
config ESP_WIFI_EXTRA_IRAM_OPT
bool "WiFi EXTRA IRAM speed optimization"
default y if IDF_TARGET_ESP32C6
default n
help
Select this option to place additional frequently called Wi-Fi library functions
in IRAM. When this option is disabled, more than 5Kbytes of IRAM memory will be saved
but Wi-Fi throughput will be reduced.
config ESP_WIFI_RX_IRAM_OPT config ESP_WIFI_RX_IRAM_OPT
bool "WiFi RX IRAM speed optimization" bool "WiFi RX IRAM speed optimization"
default n if (BT_ENABLED && SPIRAM && IDF_TARGET_ESP32) default n if (BT_ENABLED && SPIRAM && IDF_TARGET_ESP32)

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2017-2023 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -1400,7 +1400,7 @@ esp_err_t esp_mesh_set_parent(const wifi_config_t *parent, const mesh_addr_t *pa
* @return * @return
* - ESP_OK * - ESP_OK
* - ESP_ERR_WIFI_NOT_INIT * - ESP_ERR_WIFI_NOT_INIT
* - ESP_ERR_WIFI_ARG * - ESP_ERR_INVALID_ARG
* - ESP_ERR_WIFI_FAIL * - ESP_ERR_WIFI_FAIL
*/ */
esp_err_t esp_mesh_scan_get_ap_ie_len(int *len); esp_err_t esp_mesh_scan_get_ap_ie_len(int *len);
@ -1417,7 +1417,7 @@ esp_err_t esp_mesh_scan_get_ap_ie_len(int *len);
* @return * @return
* - ESP_OK * - ESP_OK
* - ESP_ERR_WIFI_NOT_INIT * - ESP_ERR_WIFI_NOT_INIT
* - ESP_ERR_WIFI_ARG * - ESP_ERR_INVALID_ARG
* - ESP_ERR_WIFI_FAIL * - ESP_ERR_WIFI_FAIL
*/ */
esp_err_t esp_mesh_scan_get_ap_record(wifi_ap_record_t *ap_record, void *buffer); esp_err_t esp_mesh_scan_get_ap_record(wifi_ap_record_t *ap_record, void *buffer);
@ -1506,7 +1506,7 @@ esp_err_t esp_mesh_switch_channel(const uint8_t *new_bssid, int csa_newchan, int
* @return * @return
* - ESP_OK * - ESP_OK
* - ESP_ERR_WIFI_NOT_INIT * - ESP_ERR_WIFI_NOT_INIT
* - ESP_ERR_WIFI_ARG * - ESP_ERR_INVALID_ARG
*/ */
esp_err_t esp_mesh_get_router_bssid(uint8_t *router_bssid); esp_err_t esp_mesh_get_router_bssid(uint8_t *router_bssid);

View File

@ -126,7 +126,7 @@ typedef struct {
* @return * @return
* - ESP_OK * - ESP_OK
* - ESP_FAIL * - ESP_FAIL
* - ESP_ERR_WIFI_ARG * - ESP_ERR_INVALID_ARG
*/ */
esp_err_t esp_mesh_set_beacon_interval(int interval_ms); esp_err_t esp_mesh_set_beacon_interval(int interval_ms);

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -132,7 +132,7 @@ void esp_wifi_internal_free_rx_buffer(void* buffer);
* @return * @return
* - ESP_OK : Successfully transmit the buffer to wifi driver * - ESP_OK : Successfully transmit the buffer to wifi driver
* - ESP_ERR_NO_MEM: out of memory * - ESP_ERR_NO_MEM: out of memory
* - ESP_ERR_WIFI_ARG: invalid argument * - ESP_ERR_INVALID_ARG: invalid argument
* - ESP_ERR_WIFI_IF : WiFi interface is invalid * - ESP_ERR_WIFI_IF : WiFi interface is invalid
* - ESP_ERR_WIFI_CONN : WiFi interface is not created, e.g. send the data to STA while WiFi mode is AP mode * - ESP_ERR_WIFI_CONN : WiFi interface is not created, e.g. send the data to STA while WiFi mode is AP mode
* - ESP_ERR_WIFI_NOT_STARTED : WiFi is not started * - ESP_ERR_WIFI_NOT_STARTED : WiFi is not started
@ -171,7 +171,7 @@ typedef void (*wifi_netstack_buf_free_cb_t)(void *netstack_buf);
* @return * @return
* - ESP_OK : Successfully transmit the buffer to wifi driver * - ESP_OK : Successfully transmit the buffer to wifi driver
* - ESP_ERR_NO_MEM: out of memory * - ESP_ERR_NO_MEM: out of memory
* - ESP_ERR_WIFI_ARG: invalid argument * - ESP_ERR_INVALID_ARG: invalid argument
* - ESP_ERR_WIFI_IF : WiFi interface is invalid * - ESP_ERR_WIFI_IF : WiFi interface is invalid
* - ESP_ERR_WIFI_CONN : WiFi interface is not created, e.g. send the data to STA while WiFi mode is AP mode * - ESP_ERR_WIFI_CONN : WiFi interface is not created, e.g. send the data to STA while WiFi mode is AP mode
* - ESP_ERR_WIFI_NOT_STARTED : WiFi is not started * - ESP_ERR_WIFI_NOT_STARTED : WiFi is not started
@ -439,7 +439,7 @@ esp_err_t esp_wifi_internal_set_log_level(wifi_log_level_t level);
* @return * @return
* - ESP_OK: succeed * - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_ARG: invalid argument * - ESP_ERR_INVALID_ARG: invalid argument
*/ */
esp_err_t esp_wifi_internal_set_log_mod(wifi_log_module_t module, uint32_t submodule, bool enable); esp_err_t esp_wifi_internal_set_log_mod(wifi_log_module_t module, uint32_t submodule, bool enable);

View File

@ -350,9 +350,9 @@ esp_err_t esp_wifi_restore(void);
* @attention 3. The scanning triggered by esp_wifi_scan_start() will not be effective until connection between device and the AP is established. * @attention 3. The scanning triggered by esp_wifi_scan_start() will not be effective until connection between device and the AP is established.
* If device is scanning and connecting at the same time, it will abort scanning and return a warning message and error * If device is scanning and connecting at the same time, it will abort scanning and return a warning message and error
* number ESP_ERR_WIFI_STATE. * number ESP_ERR_WIFI_STATE.
* If you want to do reconnection after device received disconnect event, remember to add the maximum retry time, otherwise the called * @attention 4. This API attempts to connect to an Access Point (AP) only once. To enable reconnection in case of a connection failure, please use
* scan will not work. This is especially true when the AP doesn't exist, and you still try reconnection after device received disconnect * the 'failure_retry_cnt' feature in the 'wifi_sta_config_t'. Users are suggested to implement reconnection logic in their application
* event with the reason code WIFI_REASON_NO_AP_FOUND. * for scenarios where the specified AP does not exist, or reconnection is desired after the device has received a disconnect event.
* *
* @return * @return
* - ESP_OK: succeed * - ESP_OK: succeed
@ -407,7 +407,10 @@ esp_err_t esp_wifi_deauth_sta(uint16_t aid);
* @attention The values of maximum active scan time and passive scan time per channel are limited to 1500 milliseconds. * @attention The values of maximum active scan time and passive scan time per channel are limited to 1500 milliseconds.
* Values above 1500ms may cause station to disconnect from AP and are not recommended. * Values above 1500ms may cause station to disconnect from AP and are not recommended.
* *
* @param config configuration of scanning * @param config configuration settings for scanning, if set to NULL default settings will be used
* of which default values are show_hidden:false, scan_type:active, scan_time.active.min:0,
* scan_time.active.max:120 miliseconds, scan_time.passive:360 miliseconds
*
* @param block if block is true, this API will block the caller until the scan is done, otherwise * @param block if block is true, this API will block the caller until the scan is done, otherwise
* it will return immediately * it will return immediately
* *
@ -792,7 +795,7 @@ esp_err_t esp_wifi_set_promiscuous_ctrl_filter(const wifi_promiscuous_filter_t *
* @return * @return
* - ESP_OK: succeed * - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_ARG: invalid argument * - ESP_ERR_INVALID_ARG: invalid argument
*/ */
esp_err_t esp_wifi_get_promiscuous_ctrl_filter(wifi_promiscuous_filter_t *filter); esp_err_t esp_wifi_get_promiscuous_ctrl_filter(wifi_promiscuous_filter_t *filter);
@ -939,7 +942,7 @@ esp_err_t esp_wifi_set_vendor_ie_cb(esp_vendor_ie_cb_t cb, void *ctx);
* - ESP_OK: succeed * - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start * - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
* - ESP_ERR_WIFI_ARG: invalid argument, e.g. parameter is out of range * - ESP_ERR_INVALID_ARG: invalid argument, e.g. parameter is out of range
*/ */
esp_err_t esp_wifi_set_max_tx_power(int8_t power); esp_err_t esp_wifi_set_max_tx_power(int8_t power);
@ -952,7 +955,7 @@ esp_err_t esp_wifi_set_max_tx_power(int8_t power);
* - ESP_OK: succeed * - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start * - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
* - ESP_ERR_WIFI_ARG: invalid argument * - ESP_ERR_INVALID_ARG: invalid argument
*/ */
esp_err_t esp_wifi_get_max_tx_power(int8_t *power); esp_err_t esp_wifi_get_max_tx_power(int8_t *power);
@ -981,7 +984,7 @@ esp_err_t esp_wifi_set_event_mask(uint32_t mask);
* @return * @return
* - ESP_OK: succeed * - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_ARG: invalid argument * - ESP_ERR_INVALID_ARG: invalid argument
*/ */
esp_err_t esp_wifi_get_event_mask(uint32_t *mask); esp_err_t esp_wifi_get_event_mask(uint32_t *mask);
@ -1001,7 +1004,7 @@ esp_err_t esp_wifi_get_event_mask(uint32_t *mask);
* the system sequence number. * the system sequence number.
* Generally, if esp_wifi_80211_tx is called before the Wi-Fi connection has been set up, both * Generally, if esp_wifi_80211_tx is called before the Wi-Fi connection has been set up, both
* en_sys_seq==true and en_sys_seq==false are fine. However, if the API is called after the Wi-Fi * en_sys_seq==true and en_sys_seq==false are fine. However, if the API is called after the Wi-Fi
* connection has been set up, en_sys_seq must be true, otherwise ESP_ERR_WIFI_ARG is returned. * connection has been set up, en_sys_seq must be true, otherwise ESP_ERR_INVALID_ARG is returned.
* *
* @return * @return
* - ESP_OK: success * - ESP_OK: success
@ -1073,7 +1076,7 @@ esp_err_t esp_wifi_set_csi(bool en);
* @return * @return
* - ESP_OK: succeed * - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_ARG: Invalid argument, e.g. parameter is NULL, invalid GPIO number etc * - ESP_ERR_INVALID_ARG: Invalid argument, e.g. parameter is NULL, invalid GPIO number etc
*/ */
esp_err_t esp_wifi_set_ant_gpio(const wifi_ant_gpio_config_t *config); esp_err_t esp_wifi_set_ant_gpio(const wifi_ant_gpio_config_t *config);
@ -1085,7 +1088,7 @@ esp_err_t esp_wifi_set_ant_gpio(const wifi_ant_gpio_config_t *config);
* @return * @return
* - ESP_OK: succeed * - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_ARG: invalid argument, e.g. parameter is NULL * - ESP_ERR_INVALID_ARG: invalid argument, e.g. parameter is NULL
*/ */
esp_err_t esp_wifi_get_ant_gpio(wifi_ant_gpio_config_t *config); esp_err_t esp_wifi_get_ant_gpio(wifi_ant_gpio_config_t *config);
@ -1098,7 +1101,7 @@ esp_err_t esp_wifi_get_ant_gpio(wifi_ant_gpio_config_t *config);
* @return * @return
* - ESP_OK: succeed * - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_ARG: Invalid argument, e.g. parameter is NULL, invalid antenna mode or invalid GPIO number * - ESP_ERR_INVALID_ARG: Invalid argument, e.g. parameter is NULL, invalid antenna mode or invalid GPIO number
*/ */
esp_err_t esp_wifi_set_ant(const wifi_ant_config_t *config); esp_err_t esp_wifi_set_ant(const wifi_ant_config_t *config);
@ -1110,7 +1113,7 @@ esp_err_t esp_wifi_set_ant(const wifi_ant_config_t *config);
* @return * @return
* - ESP_OK: succeed * - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_ARG: invalid argument, e.g. parameter is NULL * - ESP_ERR_INVALID_ARG: invalid argument, e.g. parameter is NULL
*/ */
esp_err_t esp_wifi_get_ant(wifi_ant_config_t *config); esp_err_t esp_wifi_get_ant(wifi_ant_config_t *config);
@ -1143,7 +1146,7 @@ int64_t esp_wifi_get_tsf_time(wifi_interface_t interface);
* - ESP_OK: succeed * - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start * - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
* - ESP_ERR_WIFI_ARG: invalid argument, For Station, if sec is less than 3. For SoftAP, if sec is less than 10. * - ESP_ERR_INVALID_ARG: invalid argument, For Station, if sec is less than 3. For SoftAP, if sec is less than 10.
*/ */
esp_err_t esp_wifi_set_inactive_time(wifi_interface_t ifx, uint16_t sec); esp_err_t esp_wifi_set_inactive_time(wifi_interface_t ifx, uint16_t sec);
@ -1157,7 +1160,7 @@ esp_err_t esp_wifi_set_inactive_time(wifi_interface_t ifx, uint16_t sec);
* - ESP_OK: succeed * - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start * - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
* - ESP_ERR_WIFI_ARG: invalid argument * - ESP_ERR_INVALID_ARG: invalid argument
*/ */
esp_err_t esp_wifi_get_inactive_time(wifi_interface_t ifx, uint16_t *sec); esp_err_t esp_wifi_get_inactive_time(wifi_interface_t ifx, uint16_t *sec);
@ -1173,16 +1176,17 @@ esp_err_t esp_wifi_get_inactive_time(wifi_interface_t ifx, uint16_t *sec);
esp_err_t esp_wifi_statis_dump(uint32_t modules); esp_err_t esp_wifi_statis_dump(uint32_t modules);
/** /**
* @brief Set RSSI threshold below which APP will get an event * @brief Set RSSI threshold, if average rssi gets lower than threshold, WiFi task will post event WIFI_EVENT_STA_BSS_RSSI_LOW.
* *
* @attention This API needs to be called every time after WIFI_EVENT_STA_BSS_RSSI_LOW event is received. * @attention If the user wants to receive another WIFI_EVENT_STA_BSS_RSSI_LOW event after receiving one, this API needs to be
* called again with an updated/same RSSI threshold.
* *
* @param rssi threshold value in dbm between -100 to 0 * @param rssi threshold value in dbm between -100 to 0
* *
* @return * @return
* - ESP_OK: succeed * - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_ARG: invalid argument * - ESP_ERR_INVALID_ARG: invalid argument
*/ */
esp_err_t esp_wifi_set_rssi_threshold(int32_t rssi); esp_err_t esp_wifi_set_rssi_threshold(int32_t rssi);
@ -1347,8 +1351,6 @@ esp_err_t esp_wifi_sta_get_aid(uint16_t *aid);
* *
* @param[out] phymode store the negotiated phymode. * @param[out] phymode store the negotiated phymode.
* *
* @attention Operation phy mode, BIT[5]: indicate whether LR enabled, BIT[0-4]: wifi_phy_mode_t
*
* @return * @return
* - ESP_OK: succeed * - ESP_OK: succeed
*/ */

View File

@ -56,18 +56,20 @@ typedef struct {
} wifi_country_t; } wifi_country_t;
/* Strength of authmodes */ /* Strength of authmodes */
/* OPEN < WEP < WPA_PSK < OWE < WPA2_PSK = WPA_WPA2_PSK < WAPI_PSK < WPA2_ENTERPRISE < WPA3_PSK = WPA2_WPA3_PSK */ /* OPEN < WEP < WPA_PSK < OWE < WPA2_PSK = WPA_WPA2_PSK < WAPI_PSK < WPA3_PSK = WPA2_WPA3_PSK */
typedef enum { typedef enum {
WIFI_AUTH_OPEN = 0, /**< authenticate mode : open */ WIFI_AUTH_OPEN = 0, /**< authenticate mode : open */
WIFI_AUTH_WEP, /**< authenticate mode : WEP */ WIFI_AUTH_WEP, /**< authenticate mode : WEP */
WIFI_AUTH_WPA_PSK, /**< authenticate mode : WPA_PSK */ WIFI_AUTH_WPA_PSK, /**< authenticate mode : WPA_PSK */
WIFI_AUTH_WPA2_PSK, /**< authenticate mode : WPA2_PSK */ WIFI_AUTH_WPA2_PSK, /**< authenticate mode : WPA2_PSK */
WIFI_AUTH_WPA_WPA2_PSK, /**< authenticate mode : WPA_WPA2_PSK */ WIFI_AUTH_WPA_WPA2_PSK, /**< authenticate mode : WPA_WPA2_PSK */
WIFI_AUTH_WPA2_ENTERPRISE, /**< authenticate mode : WPA2_ENTERPRISE */ WIFI_AUTH_ENTERPRISE, /**< authenticate mode : WiFi EAP security */
WIFI_AUTH_WPA2_ENTERPRISE = WIFI_AUTH_ENTERPRISE, /**< authenticate mode : WiFi EAP security */
WIFI_AUTH_WPA3_PSK, /**< authenticate mode : WPA3_PSK */ WIFI_AUTH_WPA3_PSK, /**< authenticate mode : WPA3_PSK */
WIFI_AUTH_WPA2_WPA3_PSK, /**< authenticate mode : WPA2_WPA3_PSK */ WIFI_AUTH_WPA2_WPA3_PSK, /**< authenticate mode : WPA2_WPA3_PSK */
WIFI_AUTH_WAPI_PSK, /**< authenticate mode : WAPI_PSK */ WIFI_AUTH_WAPI_PSK, /**< authenticate mode : WAPI_PSK */
WIFI_AUTH_OWE, /**< authenticate mode : OWE */ WIFI_AUTH_OWE, /**< authenticate mode : OWE */
WIFI_AUTH_WPA3_ENT_192, /**< authenticate mode : WPA3_ENT_SUITE_B_192_BIT */
WIFI_AUTH_MAX WIFI_AUTH_MAX
} wifi_auth_mode_t; } wifi_auth_mode_t;
@ -308,7 +310,7 @@ typedef struct {
uint8_t channel; /**< channel of target AP. Set to 1~13 to scan starting from the specified channel before connecting to AP. If the channel of AP is unknown, set it to 0.*/ uint8_t channel; /**< channel of target AP. Set to 1~13 to scan starting from the specified channel before connecting to AP. If the channel of AP is unknown, set it to 0.*/
uint16_t listen_interval; /**< Listen interval for ESP32 station to receive beacon when WIFI_PS_MAX_MODEM is set. Units: AP beacon intervals. Defaults to 3 if set to 0. */ uint16_t listen_interval; /**< Listen interval for ESP32 station to receive beacon when WIFI_PS_MAX_MODEM is set. Units: AP beacon intervals. Defaults to 3 if set to 0. */
wifi_sort_method_t sort_method; /**< sort the connect AP in the list by rssi or security mode */ wifi_sort_method_t sort_method; /**< sort the connect AP in the list by rssi or security mode */
wifi_scan_threshold_t threshold; /**< When sort_method is set, only APs which have an auth mode that is more secure than the selected auth mode and a signal stronger than the minimum RSSI will be used. */ wifi_scan_threshold_t threshold; /**< When scan_threshold is set, only APs which have an auth mode that is more secure than the selected auth mode and a signal stronger than the minimum RSSI will be used. */
wifi_pmf_config_t pmf_cfg; /**< Configuration for Protected Management Frame. Will be advertised in RSN Capabilities in RSN IE. */ wifi_pmf_config_t pmf_cfg; /**< Configuration for Protected Management Frame. Will be advertised in RSN Capabilities in RSN IE. */
uint32_t rm_enabled:1; /**< Whether Radio Measurements are enabled for the connection */ uint32_t rm_enabled:1; /**< Whether Radio Measurements are enabled for the connection */
uint32_t btm_enabled:1; /**< Whether BSS Transition Management is enabled for the connection */ uint32_t btm_enabled:1; /**< Whether BSS Transition Management is enabled for the connection */

@ -1 +1 @@
Subproject commit 0a89d5ffd2c452407940c2e617434e54f3c34576 Subproject commit c2b2ae53810965f75d6b866deb802b01d316cc1f

View File

@ -18,6 +18,10 @@ entries:
entries: entries:
.wifislprxiram+ .wifislprxiram+
[sections:wifi_extra_iram]
entries:
.wifiextrairam+
[scheme:wifi_iram] [scheme:wifi_iram]
entries: entries:
wifi_iram -> iram0_text wifi_iram -> iram0_text
@ -43,6 +47,10 @@ entries:
entries: entries:
wifi_slp_rx_iram -> iram0_text wifi_slp_rx_iram -> iram0_text
[scheme:wifi_extra_iram]
entries:
wifi_extra_iram -> iram0_text
[sections:wifi_log_error] [sections:wifi_log_error]
entries: entries:
.rodata_wlog_error+ .rodata_wlog_error+
@ -70,6 +78,7 @@ entries:
wifi_slp_rx_iram -> flash_text wifi_slp_rx_iram -> flash_text
wifi_iram -> flash_text wifi_iram -> flash_text
wifi_rx_iram -> flash_text wifi_rx_iram -> flash_text
wifi_extra_iram -> flash_text
if LOG_MAXIMUM_LEVEL <= 0: if LOG_MAXIMUM_LEVEL <= 0:
wifi_log_error -> rodata_noload wifi_log_error -> rodata_noload
else: else:
@ -117,6 +126,9 @@ entries:
if ESP_ALLOW_BSS_SEG_EXTERNAL_MEMORY = y: if ESP_ALLOW_BSS_SEG_EXTERNAL_MEMORY = y:
* (extram_bss) * (extram_bss)
if ESP_WIFI_EXTRA_IRAM_OPT = y:
* (wifi_extra_iram)
[mapping:net80211] [mapping:net80211]
archive: libnet80211.a archive: libnet80211.a
entries: entries:
@ -135,9 +147,16 @@ entries:
if ESP_WIFI_RX_IRAM_OPT || ESP_WIFI_SLP_IRAM_OPT: if ESP_WIFI_RX_IRAM_OPT || ESP_WIFI_SLP_IRAM_OPT:
* (wifi_slp_rx_iram) * (wifi_slp_rx_iram)
if ESP_WIFI_EXTRA_IRAM_OPT = y:
* (wifi_extra_iram)
[mapping:esp_wifi] [mapping:esp_wifi]
archive: libesp_wifi.a archive: libesp_wifi.a
entries: entries:
if ESP_WIFI_IRAM_OPT = y:
esp_adapter:coex_pti_get_wrapper (noflash)
wifi_netif:wifi_sta_receive (noflash)
wifi_netif:wifi_transmit_wrap (noflash)
if ESP_WIFI_SLP_IRAM_OPT =y: if ESP_WIFI_SLP_IRAM_OPT =y:
esp_adapter:wifi_clock_enable_wrapper (noflash) esp_adapter:wifi_clock_enable_wrapper (noflash)
esp_adapter:wifi_clock_disable_wrapper (noflash) esp_adapter:wifi_clock_disable_wrapper (noflash)

View File

@ -15,6 +15,14 @@ menu "LWIP"
could be used to convert network interface index to name could be used to convert network interface index to name
instead of IDF specific esp-netif APIs (such as esp_netif_get_netif_impl_name()) instead of IDF specific esp-netif APIs (such as esp_netif_get_netif_impl_name())
config LWIP_TCPIP_TASK_PRIO
int "LWIP TCP/IP Task Priority"
default 18
range 1 24
help
LWIP tcpip task priority. In case of high throughput, this parameter
could be changed up to (configMAX_PRIORITIES-1).
config LWIP_TCPIP_CORE_LOCKING config LWIP_TCPIP_CORE_LOCKING
bool "Enable tcpip core locking" bool "Enable tcpip core locking"
default n default n
@ -26,6 +34,15 @@ menu "LWIP"
If disable tcpip core locking,TCP IP will perform tasks through context switching If disable tcpip core locking,TCP IP will perform tasks through context switching
config LWIP_TCPIP_CORE_LOCKING_INPUT
bool "Enable tcpip core locking input"
depends on LWIP_TCPIP_CORE_LOCKING
default n
help
when LWIP_TCPIP_CORE_LOCKING is enabled, this lets tcpip_input() grab the
mutex for input packets as well, instead of allocating a message and passing
it to tcpip_thread.
config LWIP_CHECK_THREAD_SAFETY config LWIP_CHECK_THREAD_SAFETY
bool "Checks that lwip API runs in expected context" bool "Checks that lwip API runs in expected context"
default n default n
@ -70,6 +87,14 @@ menu "LWIP"
If this feature is disabled, all lwip functions will be put into FLASH. If this feature is disabled, all lwip functions will be put into FLASH.
config LWIP_EXTRA_IRAM_OPTIMIZATION
bool "Enable LWIP IRAM optimization for TCP part"
default n
help
If this feature is enabled, some tcp part functions relating to RX/TX in LWIP will be
put into IRAM, it can improve TCP throughput. On the other hand, it needs about 17KB
IRAM for these optimizations.
config LWIP_TIMERS_ONDEMAND config LWIP_TIMERS_ONDEMAND
bool "Enable LWIP Timers on demand" bool "Enable LWIP Timers on demand"
default y default y

View File

@ -3,24 +3,15 @@ archive: liblwip.a
entries: entries:
if LWIP_IRAM_OPTIMIZATION = y: if LWIP_IRAM_OPTIMIZATION = y:
sockets:get_socket (noflash_text) sockets:get_socket (noflash_text)
sockets:tryget_socket (noflash_text)
sockets:tryget_socket_unconn (noflash_text)
sockets:sock_inc_used (noflash_text)
sockets:tryget_socket_unconn_nouse (noflash_text)
sockets:tryget_socket_unconn_locked (noflash_text) sockets:tryget_socket_unconn_locked (noflash_text)
sockets:done_socket (noflash_text) sockets:done_socket (noflash_text)
sockets:lwip_recvfrom (noflash_text) sockets:lwip_recvfrom (noflash_text)
sockets:lwip_recv_tcp (noflash_text) sockets:lwip_recv_tcp (noflash_text)
sockets:lwip_recv_tcp_from (noflash_text)
sockets:lwip_recvfrom_udp_raw (noflash_text)
sockets:lwip_send (noflash_text) sockets:lwip_send (noflash_text)
sockets:lwip_sendto (noflash_text) sockets:lwip_sendto (noflash_text)
sockets:event_callback (noflash_text) sockets:event_callback (noflash_text)
sockets:lwip_select (noflash_text) sockets:lwip_select (noflash_text)
sockets:select_check_waiters (noflash_text)
api_lib:netconn_apimsg (noflash_text)
api_lib:netconn_recv_data (noflash_text) api_lib:netconn_recv_data (noflash_text)
api_lib:netconn_tcp_recvd_msg (noflash_text)
api_lib:netconn_tcp_recvd (noflash_text) api_lib:netconn_tcp_recvd (noflash_text)
api_lib:netconn_recv_data_tcp (noflash_text) api_lib:netconn_recv_data_tcp (noflash_text)
api_lib:netconn_recv_tcp_pbuf_flags (noflash_text) api_lib:netconn_recv_tcp_pbuf_flags (noflash_text)
@ -35,7 +26,6 @@ entries:
netbuf:netbuf_alloc (noflash_text) netbuf:netbuf_alloc (noflash_text)
netbuf:netbuf_free (noflash_text) netbuf:netbuf_free (noflash_text)
tcpip:tcpip_thread (noflash_text) tcpip:tcpip_thread (noflash_text)
tcpip:tcpip_thread_handle_msg (noflash_text)
tcpip:tcpip_inpkt (noflash_text) tcpip:tcpip_inpkt (noflash_text)
tcpip:tcpip_input (noflash_text) tcpip:tcpip_input (noflash_text)
tcpip:tcpip_callback (noflash_text) tcpip:tcpip_callback (noflash_text)
@ -55,14 +45,11 @@ entries:
ip4:ip4_output_if_opt_src (noflash_text) ip4:ip4_output_if_opt_src (noflash_text)
ip4:ip4_output (noflash_text) ip4:ip4_output (noflash_text)
pbuf:pbuf_alloc (noflash_text) pbuf:pbuf_alloc (noflash_text)
pbuf:pbuf_add_header_impl (noflash_text)
pbuf:pbuf_add_header (noflash_text) pbuf:pbuf_add_header (noflash_text)
pbuf:pbuf_remove_header (noflash_text) pbuf:pbuf_remove_header (noflash_text)
pbuf:pbuf_header_impl (noflash_text)
pbuf:pbuf_header (noflash_text) pbuf:pbuf_header (noflash_text)
pbuf:pbuf_free (noflash_text) pbuf:pbuf_free (noflash_text)
pbuf:pbuf_alloced_custom (noflash_text) pbuf:pbuf_alloced_custom (noflash_text)
pbuf:pbuf_init_alloced_pbuf (noflash_text)
udp:udp_input_local_match (noflash_text) udp:udp_input_local_match (noflash_text)
udp:udp_input (noflash_text) udp:udp_input (noflash_text)
udp:udp_send (noflash_text) udp:udp_send (noflash_text)
@ -79,6 +66,71 @@ entries:
sys_arch:sys_mbox_trypost (noflash_text) sys_arch:sys_mbox_trypost (noflash_text)
sys_arch:sys_arch_mbox_fetch (noflash_text) sys_arch:sys_arch_mbox_fetch (noflash_text)
lwip_default_hooks:ip4_route_src_hook (noflash_text) lwip_default_hooks:ip4_route_src_hook (noflash_text)
if COMPILER_OPTIMIZATION_DEBUG = y:
sockets:tryget_socket_unconn (noflash_text)
sockets:tryget_socket (noflash_text)
sockets:lwip_recvfrom_udp_raw (noflash_text)
sockets:tryget_socket_unconn_nouse (noflash_text)
sockets:sock_inc_used (noflash_text)
tcpip:tcpip_thread_handle_msg (noflash_text)
api_lib:netconn_apimsg (noflash_text)
sockets:lwip_recv_tcp_from (noflash_text)
sockets:select_check_waiters (noflash_text)
api_lib:netconn_tcp_recvd_msg (noflash_text)
pbuf:pbuf_header_impl (noflash_text)
pbuf:pbuf_add_header_impl (noflash_text)
pbuf:pbuf_init_alloced_pbuf (noflash_text)
if LWIP_EXTRA_IRAM_OPTIMIZATION = y:
api_msg:recv_udp (noflash_text)
inet_chksum:inet_chksum_pbuf (noflash_text)
inet_chksum:ip_chksum_pseudo (noflash_text)
inet_chksum:inet_chksum (noflash_text)
inet_chksum:lwip_standard_chksum (noflash_text)
pbuf:pbuf_copy (noflash_text)
pbuf:pbuf_copy_partial_pbuf (noflash_text)
pbuf:pbuf_clone (noflash_text)
tcp:tcp_fasttmr (noflash_text)
tcp:tcp_tmr (noflash_text)
tcp:tcp_update_rcv_ann_wnd (noflash_text)
tcp:tcp_recved (noflash_text)
tcp:tcp_slowtmr (noflash_text)
tcp:tcp_process_refused_data (noflash_text)
tcp:tcp_segs_free (noflash_text)
tcp:tcp_seg_free (noflash_text)
tcp:tcp_seg_copy (noflash_text)
tcp:tcp_recv_null (noflash_text)
tcp_in:tcp_input (noflash_text)
tcp_in:tcp_input_delayed_close (noflash_text)
tcp_in:tcp_oos_insert_segment (noflash_text)
tcp_in:tcp_receive (noflash_text)
tcp_in:tcp_parseopt (noflash_text)
tcp_out:tcp_route (noflash_text)
tcp_out:tcp_create_segment (noflash_text)
tcp_out:tcp_write (noflash_text)
tcp_out:tcp_split_unsent_seg (noflash_text)
tcp_out:tcp_rexmit_rto_prepare (noflash_text)
tcp_out:tcp_rexmit (noflash_text)
tcp_out:tcp_rexmit_fast (noflash_text)
tcp_out:tcp_output_control_segment (noflash_text)
tcp_out:tcp_rst (noflash_text)
tcp_out:tcp_send_empty_ack (noflash_text)
sys_arch:sys_arch_protect (noflash_text)
sys_arch:sys_arch_unprotect (noflash_text)
sys_arch:sys_thread_tcpip (noflash_text)
memp:memp_malloc (noflash_text)
mem:mem_malloc (noflash_text)
raw:raw_input (noflash_text)
if COMPILER_OPTIMIZATION_DEBUG = y:
tcp_in:tcp_free_acked_segments (noflash_text)
tcp_in:tcp_process (noflash_text)
tcp_out:tcp_output_segment (noflash_text)
tcp_out:tcp_output_fill_options (noflash_text)
tcp_out:tcp_output_alloc_header (noflash_text)
tcp_out:tcp_pbuf_prealloc (noflash_text)
tcp_out:tcp_write_checks (noflash_text)
raw:raw_input_local_match (noflash_text)
tcp_out:tcp_output_alloc_header_common (noflash_text)
memp:do_memp_malloc_pool (noflash_text)
if ESP_ALLOW_BSS_SEG_EXTERNAL_MEMORY = y: if ESP_ALLOW_BSS_SEG_EXTERNAL_MEMORY = y:
* (extram_bss) * (extram_bss)

View File

@ -43,6 +43,11 @@ extern "C" {
*/ */
#ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING #ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING
#define LWIP_TCPIP_CORE_LOCKING 1 #define LWIP_TCPIP_CORE_LOCKING 1
#ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING_INPUT
#define LWIP_TCPIP_CORE_LOCKING_INPUT 1
#else
#define LWIP_TCPIP_CORE_LOCKING_INPUT 0
#endif
#define LOCK_TCPIP_CORE() do { sys_mutex_lock(&lock_tcpip_core); sys_thread_tcpip(LWIP_CORE_LOCK_MARK_HOLDER); } while(0) #define LOCK_TCPIP_CORE() do { sys_mutex_lock(&lock_tcpip_core); sys_thread_tcpip(LWIP_CORE_LOCK_MARK_HOLDER); } while(0)
#define UNLOCK_TCPIP_CORE() do { sys_thread_tcpip(LWIP_CORE_LOCK_UNMARK_HOLDER); sys_mutex_unlock(&lock_tcpip_core); } while(0) #define UNLOCK_TCPIP_CORE() do { sys_thread_tcpip(LWIP_CORE_LOCK_UNMARK_HOLDER); sys_mutex_unlock(&lock_tcpip_core); } while(0)
#ifdef CONFIG_LWIP_CHECK_THREAD_SAFETY #ifdef CONFIG_LWIP_CHECK_THREAD_SAFETY
@ -51,6 +56,7 @@ extern "C" {
#else #else
#define LWIP_TCPIP_CORE_LOCKING 0 #define LWIP_TCPIP_CORE_LOCKING 0
#define LWIP_TCPIP_CORE_LOCKING_INPUT 0
#ifdef CONFIG_LWIP_CHECK_THREAD_SAFETY #ifdef CONFIG_LWIP_CHECK_THREAD_SAFETY
#define LWIP_ASSERT_CORE_LOCKED() do { LWIP_ASSERT("Required to run in TCPIP context!", sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)); } while(0) #define LWIP_ASSERT_CORE_LOCKED() do { LWIP_ASSERT("Required to run in TCPIP context!", sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)); } while(0)
#endif /* CONFIG_LWIP_CHECK_THREAD_SAFETY */ #endif /* CONFIG_LWIP_CHECK_THREAD_SAFETY */
@ -787,7 +793,7 @@ static inline uint32_t timeout_from_offered(uint32_t lease, uint32_t min)
* The priority value itself is platform-dependent, but is passed to * The priority value itself is platform-dependent, but is passed to
* sys_thread_new() when the thread is created. * sys_thread_new() when the thread is created.
*/ */
#define TCPIP_THREAD_PRIO ESP_TASK_TCPIP_PRIO #define TCPIP_THREAD_PRIO CONFIG_LWIP_TCPIP_TASK_PRIO
/** /**
* TCPIP_MBOX_SIZE: The mailbox size for the tcpip thread messages * TCPIP_MBOX_SIZE: The mailbox size for the tcpip thread messages

View File

@ -50,6 +50,24 @@ typedef struct {
esp_mbedtls_sha1_mode mode; esp_mbedtls_sha1_mode mode;
} mbedtls_sha1_context; } mbedtls_sha1_context;
/**
* \brief Set the SHA-1 mode for a mbedtls_sha1_context.
*
* \param ctx The SHA-1 context structure.
* \param mode The SHA-1 mode to be set. It can be one of the following:
* - ESP_MBEDTLS_SHA1_UNUSED: Indicates that the first block hasn't been processed yet.
* - ESP_MBEDTLS_SHA1_HARDWARE: Specifies the use of hardware SHA engine for SHA-1 calculations.
* - ESP_MBEDTLS_SHA1_SOFTWARE: Specifies the use of software-based SHA-1 calculations.
*
* \return None.
*/
static inline void esp_mbedtls_set_sha1_mode(mbedtls_sha1_context *ctx, esp_mbedtls_sha1_mode mode)
{
if (ctx) {
ctx->mode = mode;
}
}
#elif SOC_SHA_SUPPORT_DMA || SOC_SHA_SUPPORT_RESUME #elif SOC_SHA_SUPPORT_DMA || SOC_SHA_SUPPORT_RESUME
typedef enum { typedef enum {

View File

@ -96,6 +96,7 @@ endif()
if(CONFIG_ESP_WIFI_MBEDTLS_CRYPTO) if(CONFIG_ESP_WIFI_MBEDTLS_CRYPTO)
set(crypto_src set(crypto_src
"esp_supplicant/src/crypto/fastpbkdf2.c"
"esp_supplicant/src/crypto/crypto_mbedtls.c" "esp_supplicant/src/crypto/crypto_mbedtls.c"
"esp_supplicant/src/crypto/crypto_mbedtls-bignum.c" "esp_supplicant/src/crypto/crypto_mbedtls-bignum.c"
"esp_supplicant/src/crypto/crypto_mbedtls-rsa.c" "esp_supplicant/src/crypto/crypto_mbedtls-rsa.c"
@ -229,6 +230,7 @@ target_compile_definitions(${COMPONENT_LIB} PRIVATE
CONFIG_IEEE80211W CONFIG_IEEE80211W
CONFIG_SHA256 CONFIG_SHA256
CONFIG_NO_RADIUS CONFIG_NO_RADIUS
CONFIG_FAST_PBKDF2
) )
if(CONFIG_ESP_WIFI_ENABLE_WPA3_SAE) if(CONFIG_ESP_WIFI_ENABLE_WPA3_SAE)

View File

@ -33,7 +33,7 @@ extern "C" {
* @brief Enable wpa2 enterprise authentication. * @brief Enable wpa2 enterprise authentication.
* *
* @attention 1. wpa2 enterprise authentication can only be used when station mode is enabled. * @attention 1. wpa2 enterprise authentication can only be used when station mode is enabled.
* @attention 2. wpa2 enterprise authentication can only support TLS, PEAP-MSCHAPv2 and TTLS-MSCHAPv2 method. * @attention 2. wpa2 enterprise authentication supports EAP-FAST, TLS, PEAP, TTLS(EAP, MSCHAPv2, MSCHAP, PAP, CHAP) methods.
* *
* @return * @return
* - ESP_OK: succeed. * - ESP_OK: succeed.
@ -45,7 +45,7 @@ esp_err_t esp_wifi_sta_wpa2_ent_enable(void);
* @brief Disable wpa2 enterprise authentication. * @brief Disable wpa2 enterprise authentication.
* *
* @attention 1. wpa2 enterprise authentication can only be used when station mode is enabled. * @attention 1. wpa2 enterprise authentication can only be used when station mode is enabled.
* @attention 2. wpa2 enterprise authentication can only support TLS, PEAP-MSCHAPv2 and TTLS-MSCHAPv2 method. * @attention 2. wpa2 enterprise authentication supports EAP-FAST, TLS, PEAP, TTLS(EAP, MSCHAPv2, MSCHAP, PAP, CHAP) methods.
* *
* @return * @return
* - ESP_OK: succeed. * - ESP_OK: succeed.

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -36,6 +36,10 @@
#include "crypto.h" #include "crypto.h"
#include "mbedtls/esp_config.h" #include "mbedtls/esp_config.h"
#ifdef CONFIG_FAST_PBKDF2
#include "fastpbkdf2.h"
#endif
static int digest_vector(mbedtls_md_type_t md_type, size_t num_elem, static int digest_vector(mbedtls_md_type_t md_type, size_t num_elem,
const u8 *addr[], const size_t *len, u8 *mac) const u8 *addr[], const size_t *len, u8 *mac)
{ {
@ -745,9 +749,14 @@ cleanup:
int pbkdf2_sha1(const char *passphrase, const u8 *ssid, size_t ssid_len, int pbkdf2_sha1(const char *passphrase, const u8 *ssid, size_t ssid_len,
int iterations, u8 *buf, size_t buflen) int iterations, u8 *buf, size_t buflen)
{ {
#ifdef CONFIG_FAST_PBKDF2
fastpbkdf2_hmac_sha1((const u8 *) passphrase, os_strlen(passphrase),
ssid, ssid_len, iterations, buf, buflen);
return 0;
#else
int ret = mbedtls_pkcs5_pbkdf2_hmac_ext(MBEDTLS_MD_SHA1, (const u8 *) passphrase, int ret = mbedtls_pkcs5_pbkdf2_hmac_ext(MBEDTLS_MD_SHA1, (const u8 *) passphrase,
os_strlen(passphrase) , ssid, os_strlen(passphrase) , ssid,
ssid_len, iterations, 32, buf); ssid_len, iterations, buflen, buf);
if (ret != 0) { if (ret != 0) {
ret = -1; ret = -1;
goto cleanup; goto cleanup;
@ -755,6 +764,7 @@ int pbkdf2_sha1(const char *passphrase, const u8 *ssid, size_t ssid_len,
cleanup: cleanup:
return ret; return ret;
#endif
} }
#ifdef MBEDTLS_DES_C #ifdef MBEDTLS_DES_C

View File

@ -0,0 +1,325 @@
/*
* SPDX-FileCopyrightText: 2015 Joseph Birr-Pixton <jpixton@gmail.com>
*
* SPDX-License-Identifier: CC0-1.0
*/
/*
* fast-pbkdf2 - Optimal PBKDF2-HMAC calculation
* Written in 2015 by Joseph Birr-Pixton <jpixton@gmail.com>
*
* To the extent possible under law, the author(s) have dedicated all
* copyright and related and neighboring rights to this software to the
* public domain worldwide. This software is distributed without any
* warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication
* along with this software. If not, see
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#include "utils/common.h"
#include "fastpbkdf2.h"
#include <assert.h>
#include <string.h>
#if defined(__GNUC__)
#include <endian.h>
#endif
#include <mbedtls/sha1.h>
#include "mbedtls/esp_config.h"
#include "utils/wpa_debug.h"
/* --- MSVC doesn't support C99 --- */
#ifdef _MSC_VER
#define restrict
#define _Pragma __pragma
#endif
/* --- Common useful things --- */
#ifndef MIN
#define MIN(a, b) ((a) > (b)) ? (b) : (a)
#endif
static inline void write32_be(uint32_t n, uint8_t out[4])
{
#if defined(__GNUC__) && __GNUC__ >= 4 && __BYTE_ORDER == __LITTLE_ENDIAN
*(uint32_t *)(out) = __builtin_bswap32(n);
#else
out[0] = (n >> 24) & 0xff;
out[1] = (n >> 16) & 0xff;
out[2] = (n >> 8) & 0xff;
out[3] = n & 0xff;
#endif
}
/* Prepare block (of blocksz bytes) to contain md padding denoting a msg-size
* message (in bytes). block has a prefix of used bytes.
*
* Message length is expressed in 32 bits (so suitable for sha1, sha256, sha512). */
static inline void md_pad(uint8_t *block, size_t blocksz, size_t used, size_t msg)
{
memset(block + used, 0, blocksz - used - 4);
block[used] = 0x80;
block += blocksz - 4;
write32_be((uint32_t) (msg * 8), block);
}
/* Internal function/type names for hash-specific things. */
#define HMAC_CTX(_name) HMAC_ ## _name ## _ctx
#define HMAC_INIT(_name) HMAC_ ## _name ## _init
#define HMAC_UPDATE(_name) HMAC_ ## _name ## _update
#define HMAC_FINAL(_name) HMAC_ ## _name ## _final
#define PBKDF2_F(_name) pbkdf2_f_ ## _name
#define PBKDF2(_name) pbkdf2_ ## _name
/* This macro expands to decls for the whole implementation for a given
* hash function. Arguments are:
*
* _name like 'sha1', added to symbol names
* _blocksz block size, in bytes
* _hashsz digest output, in bytes
* _ctx hash context type
* _init hash context initialisation function
* args: (_ctx *c)
* _update hash context update function
* args: (_ctx *c, const void *data, size_t ndata)
* _final hash context finish function
* args: (_ctx *c, void *out)
* _xform hash context raw block update function
* args: (_ctx *c, const void *data)
* _xcpy hash context raw copy function (only need copy hash state)
* args: (_ctx * restrict out, const _ctx *restrict in)
* _xtract hash context state extraction
* args: args (_ctx *restrict c, uint8_t *restrict out)
* _xxor hash context xor function (only need xor hash state)
* args: (_ctx *restrict out, const _ctx *restrict in)
*
* The resulting function is named PBKDF2(_name).
*/
#define DECL_PBKDF2(_name, _blocksz, _hashsz, _ctx, \
_init, _update, _xform, _final, _xcpy, _xtract, _xxor) \
typedef struct { \
_ctx inner; \
_ctx outer; \
} HMAC_CTX(_name); \
\
static inline void HMAC_INIT(_name)(HMAC_CTX(_name) *ctx, \
const uint8_t *key, size_t nkey) \
{ \
/* Prepare key: */ \
uint8_t k[_blocksz]; \
\
/* Shorten long keys. */ \
if (nkey > _blocksz) \
{ \
_init(&ctx->inner); \
_update(&ctx->inner, key, nkey); \
_final(&ctx->inner, k); \
\
key = k; \
nkey = _hashsz; \
} \
\
/* Standard doesn't cover case where blocksz < hashsz. */ \
assert(nkey <= _blocksz); \
\
/* Right zero-pad short keys. */ \
if (k != key) \
memcpy(k, key, nkey); \
if (_blocksz > nkey) \
memset(k + nkey, 0, _blocksz - nkey); \
\
/* Start inner hash computation */ \
uint8_t blk_inner[_blocksz]; \
uint8_t blk_outer[_blocksz]; \
\
for (size_t i = 0; i < _blocksz; i++) \
{ \
blk_inner[i] = 0x36 ^ k[i]; \
blk_outer[i] = 0x5c ^ k[i]; \
} \
\
_init(&ctx->inner); \
_update(&ctx->inner, blk_inner, sizeof blk_inner); \
\
/* And outer. */ \
_init(&ctx->outer); \
_update(&ctx->outer, blk_outer, sizeof blk_outer); \
} \
\
static inline void HMAC_UPDATE(_name)(HMAC_CTX(_name) *ctx, \
const void *data, size_t ndata) \
{ \
_update(&ctx->inner, data, ndata); \
} \
\
static inline void HMAC_FINAL(_name)(HMAC_CTX(_name) *ctx, \
uint8_t out[_hashsz]) \
{ \
_final(&ctx->inner, out); \
_update(&ctx->outer, out, _hashsz); \
_final(&ctx->outer, out); \
} \
\
\
/* --- PBKDF2 --- */ \
static inline void PBKDF2_F(_name)(const HMAC_CTX(_name) *startctx, \
uint32_t counter, \
const uint8_t *salt, size_t nsalt, \
uint32_t iterations, \
uint8_t *out) \
{ \
uint8_t countbuf[4]; \
write32_be(counter, countbuf); \
\
/* Prepare loop-invariant padding block. */ \
uint8_t Ublock[_blocksz]; \
md_pad(Ublock, _blocksz, _hashsz, _blocksz + _hashsz); \
\
/* First iteration: \
* U_1 = PRF(P, S || INT_32_BE(i)) \
*/ \
HMAC_CTX(_name) ctx = *startctx; \
HMAC_UPDATE(_name)(&ctx, salt, nsalt); \
HMAC_UPDATE(_name)(&ctx, countbuf, sizeof countbuf); \
HMAC_FINAL(_name)(&ctx, Ublock); \
_ctx result = ctx.outer; \
\
/* Subsequent iterations: \
* U_c = PRF(P, U_{c-1}) \
*/ \
for (uint32_t i = 1; i < iterations; i++) \
{ \
/* Complete inner hash with previous U */ \
_xcpy(&ctx.inner, &startctx->inner); \
_xform(&ctx.inner, Ublock); \
_xtract(&ctx.inner, Ublock); \
/* Complete outer hash with inner output */ \
_xcpy(&ctx.outer, &startctx->outer); \
_xform(&ctx.outer, Ublock); \
_xtract(&ctx.outer, Ublock); \
_xxor(&result, &ctx.outer); \
} \
\
/* Reform result into output buffer. */ \
_xtract(&result, out); \
} \
\
static inline void PBKDF2(_name)(const uint8_t *pw, size_t npw, \
const uint8_t *salt, size_t nsalt, \
uint32_t iterations, \
uint8_t *out, size_t nout) \
{ \
assert(iterations); \
assert(out && nout); \
\
/* Starting point for inner loop. */ \
HMAC_CTX(_name) ctx; \
HMAC_INIT(_name)(&ctx, pw, npw); \
\
/* How many blocks do we need? */ \
uint32_t blocks_needed = (uint32_t)(nout + _hashsz - 1) / _hashsz; \
\
for (uint32_t counter = 1; counter <= blocks_needed; counter++) \
{ \
uint8_t block[_hashsz]; \
PBKDF2_F(_name)(&ctx, counter, salt, nsalt, iterations, block); \
\
size_t offset = (counter - 1) * _hashsz; \
size_t taken = MIN(nout - offset, _hashsz); \
memcpy(out + offset, block, taken); \
} \
}
static inline void sha1_extract(mbedtls_sha1_context *restrict ctx, uint8_t *restrict out)
{
#if defined(MBEDTLS_SHA1_ALT)
#if CONFIG_IDF_TARGET_ESP32
/* ESP32 stores internal SHA state in BE format similar to software */
write32_be(ctx->state[0], out);
write32_be(ctx->state[1], out + 4);
write32_be(ctx->state[2], out + 8);
write32_be(ctx->state[3], out + 12);
write32_be(ctx->state[4], out + 16);
#else
*(uint32_t *)(out) = ctx->state[0];
*(uint32_t *)(out + 4) = ctx->state[1];
*(uint32_t *)(out + 8) = ctx->state[2];
*(uint32_t *)(out + 12) = ctx->state[3];
*(uint32_t *)(out + 16) = ctx->state[4];
#endif
#else
write32_be(ctx->MBEDTLS_PRIVATE(state)[0], out);
write32_be(ctx->MBEDTLS_PRIVATE(state)[1], out + 4);
write32_be(ctx->MBEDTLS_PRIVATE(state)[2], out + 8);
write32_be(ctx->MBEDTLS_PRIVATE(state)[3], out + 12);
write32_be(ctx->MBEDTLS_PRIVATE(state)[4], out + 16);
#endif
}
static inline void sha1_cpy(mbedtls_sha1_context *restrict out, const mbedtls_sha1_context *restrict in)
{
#if defined(MBEDTLS_SHA1_ALT)
out->state[0] = in->state[0];
out->state[1] = in->state[1];
out->state[2] = in->state[2];
out->state[3] = in->state[3];
out->state[4] = in->state[4];
#else
out->MBEDTLS_PRIVATE(state)[0] = in->MBEDTLS_PRIVATE(state)[0];
out->MBEDTLS_PRIVATE(state)[1] = in->MBEDTLS_PRIVATE(state)[1];
out->MBEDTLS_PRIVATE(state)[2] = in->MBEDTLS_PRIVATE(state)[2];
out->MBEDTLS_PRIVATE(state)[3] = in->MBEDTLS_PRIVATE(state)[3];
out->MBEDTLS_PRIVATE(state)[4] = in->MBEDTLS_PRIVATE(state)[4];
#endif
}
static inline void sha1_xor(mbedtls_sha1_context *restrict out, const mbedtls_sha1_context *restrict in)
{
#if defined(MBEDTLS_SHA1_ALT)
out->state[0] ^= in->state[0];
out->state[1] ^= in->state[1];
out->state[2] ^= in->state[2];
out->state[3] ^= in->state[3];
out->state[4] ^= in->state[4];
#else
out->MBEDTLS_PRIVATE(state)[0] ^= in->MBEDTLS_PRIVATE(state)[0];
out->MBEDTLS_PRIVATE(state)[1] ^= in->MBEDTLS_PRIVATE(state)[1];
out->MBEDTLS_PRIVATE(state)[2] ^= in->MBEDTLS_PRIVATE(state)[2];
out->MBEDTLS_PRIVATE(state)[3] ^= in->MBEDTLS_PRIVATE(state)[3];
out->MBEDTLS_PRIVATE(state)[4] ^= in->MBEDTLS_PRIVATE(state)[4];
#endif
}
static int mbedtls_sha1_init_start(mbedtls_sha1_context *ctx)
{
mbedtls_sha1_init(ctx);
mbedtls_sha1_starts(ctx);
#if defined(CONFIG_IDF_TARGET_ESP32) && defined(MBEDTLS_SHA1_ALT)
/* Use software mode for esp32 since hardware can't give output more than 20 */
esp_mbedtls_set_sha1_mode(ctx, ESP_MBEDTLS_SHA1_SOFTWARE);
#endif
return 0;
}
DECL_PBKDF2(sha1, // _name
64, // _blocksz
20, // _hashsz
mbedtls_sha1_context, // _ctx
mbedtls_sha1_init_start, // _init
mbedtls_sha1_update, // _update
mbedtls_internal_sha1_process, // _xform
mbedtls_sha1_finish, // _final
sha1_cpy, // _xcpy
sha1_extract, // _xtract
sha1_xor) // _xxor
void fastpbkdf2_hmac_sha1(const uint8_t *pw, size_t npw,
const uint8_t *salt, size_t nsalt,
uint32_t iterations,
uint8_t *out, size_t nout)
{
PBKDF2(sha1)(pw, npw, salt, nsalt, iterations, out, nout);
}

View File

@ -0,0 +1,48 @@
/*
* SPDX-FileCopyrightText: 2015 Joseph Birr-Pixton <jpixton@gmail.com>
*
* SPDX-License-Identifier: CC0-1.0
*/
/*
* fastpbkdf2 - Faster PBKDF2-HMAC calculation
* Written in 2015 by Joseph Birr-Pixton <jpixton@gmail.com>
*
* To the extent possible under law, the author(s) have dedicated all
* copyright and related and neighboring rights to this software to the
* public domain worldwide. This software is distributed without any
* warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication
* along with this software. If not, see
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#ifndef FASTPBKDF2_H
#define FASTPBKDF2_H
#include <stdlib.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Calculates PBKDF2-HMAC-SHA1.
*
* @p npw bytes at @p pw are the password input.
* @p nsalt bytes at @p salt are the salt input.
* @p iterations is the PBKDF2 iteration count and must be non-zero.
* @p nout bytes of output are written to @p out. @p nout must be non-zero.
*
* This function cannot fail; it does not report errors.
*/
void fastpbkdf2_hmac_sha1(const uint8_t *pw, size_t npw,
const uint8_t *salt, size_t nsalt,
uint32_t iterations,
uint8_t *out, size_t nout);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,68 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include "string.h"
#include <inttypes.h>
#include "unity.h"
#include "utils/common.h"
#include "mbedtls/pkcs5.h"
#include "crypto/sha1.h"
#if SOC_WIFI_SUPPORTED
#define PMK_LEN 32
TEST_CASE("Test pbkdf2", "[crypto-pbkdf2]")
{
uint8_t PMK[PMK_LEN];
uint8_t ssid_len;
uint8_t passphrase_len;
uint8_t ssid[MAX_SSID_LEN];
uint8_t passphrase[MAX_PASSPHRASE_LEN];
uint8_t expected_pmk1[PMK_LEN] =
{0xe7, 0x90, 0xd0, 0x65, 0x67, 0xf0, 0xbf, 0xca, 0xca, 0x10, 0x88, 0x0b, 0x85, 0xb2, 0x33, 0xe5,
0xe1, 0xd5, 0xe5, 0xb8, 0xd0, 0xfd, 0x94, 0x60, 0x56, 0x95, 0x5e, 0x41, 0x5a, 0x7f, 0xfa, 0xfa};
uint8_t expected_pmk[PMK_LEN];
/* Compare Fast PBKDF output with expected output*/
pbkdf2_sha1("espressif", (uint8_t *)"espressif", strlen("espressif"), 4096, PMK, PMK_LEN);
TEST_ASSERT(memcmp(PMK, expected_pmk1, PMK_LEN) == 0);
/* Compare fast PBKDF output with mbedtls pbkdf2 function's output */
pbkdf2_sha1("espressif2", (uint8_t *)"espressif2", strlen("espressif2"), 4096, PMK, PMK_LEN);
mbedtls_pkcs5_pbkdf2_hmac_ext(MBEDTLS_MD_SHA1, (const unsigned char *) "espressif2",
strlen("espressif2") , (const unsigned char *)"espressif2",
strlen("espressif2"), 4096, PMK_LEN, expected_pmk);
TEST_ASSERT(memcmp(PMK, expected_pmk, PMK_LEN) == 0);
/* Calculate PMK using random ssid and passphrase and compare */
os_memset(ssid, 0, MAX_SSID_LEN);
os_memset(passphrase, 0, MAX_PASSPHRASE_LEN);
ssid_len = os_random();
ssid_len %= MAX_SSID_LEN;
os_get_random(ssid, ssid_len);
passphrase_len = os_random();
passphrase_len %= MAX_PASSPHRASE_LEN;
os_get_random(passphrase, passphrase_len);
pbkdf2_sha1((char *)passphrase, ssid, ssid_len, 4096, PMK, PMK_LEN);
mbedtls_pkcs5_pbkdf2_hmac_ext(MBEDTLS_MD_SHA1, (const unsigned char *) passphrase,
strlen((char *)passphrase) , (const unsigned char *)ssid,
ssid_len, 4096, PMK_LEN, expected_pmk);
/* Dump values if fails */
if (memcmp(PMK, expected_pmk, PMK_LEN) != 0) {
ESP_LOG_BUFFER_HEXDUMP("passphrase", passphrase, passphrase_len, ESP_LOG_INFO);
ESP_LOG_BUFFER_HEXDUMP("ssid", ssid, ssid_len, ESP_LOG_INFO);
ESP_LOG_BUFFER_HEXDUMP("PMK", PMK, PMK_LEN, ESP_LOG_INFO);
ESP_LOG_BUFFER_HEXDUMP("expected_pmk", expected_pmk, PMK_LEN, ESP_LOG_INFO);
}
TEST_ASSERT(memcmp(PMK, expected_pmk, PMK_LEN) == 0);
}
#endif /* SOC_WIFI_SUPPORTED */

View File

@ -177,6 +177,7 @@ INPUT = \
$(PROJECT_PATH)/components/esp_system/include/esp_system.h \ $(PROJECT_PATH)/components/esp_system/include/esp_system.h \
$(PROJECT_PATH)/components/esp_system/include/esp_systick_etm.h \ $(PROJECT_PATH)/components/esp_system/include/esp_systick_etm.h \
$(PROJECT_PATH)/components/esp_system/include/esp_task_wdt.h \ $(PROJECT_PATH)/components/esp_system/include/esp_task_wdt.h \
$(PROJECT_PATH)/components/esp_system/include/esp_task.h \
$(PROJECT_PATH)/components/esp_timer/include/esp_timer.h \ $(PROJECT_PATH)/components/esp_timer/include/esp_timer.h \
$(PROJECT_PATH)/components/esp_wifi/include/esp_mesh.h \ $(PROJECT_PATH)/components/esp_wifi/include/esp_mesh.h \
$(PROJECT_PATH)/components/esp_wifi/include/esp_now.h \ $(PROJECT_PATH)/components/esp_wifi/include/esp_now.h \

View File

@ -27,6 +27,8 @@ These third party libraries can be included into the application (firmware) prod
* `wpa_supplicant`_ Copyright (c) 2003-2022 Jouni Malinen <j@w1.fi> and contributors and licensed under the BSD license. * `wpa_supplicant`_ Copyright (c) 2003-2022 Jouni Malinen <j@w1.fi> and contributors and licensed under the BSD license.
* :component_file:`Fast PBKDF2 <wpa_supplicant/esp_supplicant/src/crypto/crypto_mbedtls.c>` Copyright (c) 2015 Joseph Birr-Pixton and licensed under CC0 Public Domain Dedication license.
* `FreeBSD net80211`_ Copyright (c) 2004-2008 Sam Leffler, Errno Consulting and licensed under the BSD license. * `FreeBSD net80211`_ Copyright (c) 2004-2008 Sam Leffler, Errno Consulting and licensed under the BSD license.
* `argtable3`_ argument parsing library Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann and licensed under 3-clause BSD license. argtable3 also includes the following software components. For details, please see argtable3 :component_file:`LICENSE file<console/argtable3/LICENSE>`. * `argtable3`_ argument parsing library Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann and licensed under 3-clause BSD license. argtable3 also includes the following software components. For details, please see argtable3 :component_file:`LICENSE file<console/argtable3/LICENSE>`.

View File

@ -428,11 +428,11 @@ The :example_file:`wifi/iperf/sdkconfig.defaults` file for the iperf example con
.. important:: Suggest applying changes a few at a time and checking the performance each time with a particular application workload. .. important:: Suggest applying changes a few at a time and checking the performance each time with a particular application workload.
- If a lot of tasks are competing for CPU time on the system, consider that the lwIP task has configurable CPU affinity (:ref:`CONFIG_LWIP_TCPIP_TASK_AFFINITY`) and runs at fixed priority ``ESP_TASK_TCPIP_PRIO`` (18). Configure competing tasks to be pinned to a different core, or to run at a lower priority. See also :ref:`built-in-task-priorities`. - If a lot of tasks are competing for CPU time on the system, consider that the lwIP task has configurable CPU affinity (:ref:`CONFIG_LWIP_TCPIP_TASK_AFFINITY`) and runs at fixed priority (18). Configure competing tasks to be pinned to a different core, or to run at a lower priority. See also :ref:`built-in-task-priorities`.
- If using ``select()`` function with socket arguments only, disabling :ref:`CONFIG_VFS_SUPPORT_SELECT` will make ``select()`` calls faster. - If using ``select()`` function with socket arguments only, disabling :ref:`CONFIG_VFS_SUPPORT_SELECT` will make ``select()`` calls faster.
- If there is enough free IRAM, select :ref:`CONFIG_LWIP_IRAM_OPTIMIZATION` to improve TX/RX throughput - If there is enough free IRAM, select :ref:`CONFIG_LWIP_IRAM_OPTIMIZATION` and :ref:`CONFIG_LWIP_EXTRA_IRAM_OPTIMIZATION` to improve TX/RX throughput
.. only:: SOC_WIFI_SUPPORTED .. only:: SOC_WIFI_SUPPORTED

View File

@ -1,20 +1,22 @@
Maximizing Execution Speed Speed Optimization
========================== ==================
:link_to_translation:`zh_CN:[中文]`
{IDF_TARGET_CONTROLLER_CORE_CONFIG:default="CONFIG_BT_CTRL_PINNED_TO_CORE", esp32="CONFIG_BTDM_CTRL_PINNED_TO_CORE_CHOICE", esp32s3="CONFIG_BT_CTRL_PINNED_TO_CORE_CHOICE"} {IDF_TARGET_CONTROLLER_CORE_CONFIG:default="CONFIG_BT_CTRL_PINNED_TO_CORE", esp32="CONFIG_BTDM_CTRL_PINNED_TO_CORE_CHOICE", esp32s3="CONFIG_BT_CTRL_PINNED_TO_CORE_CHOICE"}
{IDF_TARGET_RF_TYPE:default="Wi-Fi/BT", esp32s2="Wi-Fi", esp32c6="Wi-Fi/BT/802.15.4", esp32h2="BT/802.15.4"} {IDF_TARGET_RF_TYPE:default="Wi-Fi/Bluetooth", esp32s2="Wi-Fi", esp32c6="Wi-Fi/Bluetooth/802.15.4", esp32h2="Bluetooth/802.15.4"}
Overview Overview
-------- --------
Optimizing execution speed is a key element of software performance. Code that executes faster can also have other positive effects, like reducing overall power consumption. However, improving execution speed may have trade-offs with other aspects of performance such as :doc:`size`. Optimizing execution speed is a key element of software performance. Code that executes faster can also have other positive effects, e.g., reducing overall power consumption. However, improving execution speed may have trade-offs with other aspects of performance such as :doc:`size`.
Choose What To Optimize Choose What to Optimize
----------------------- -----------------------
If a function in the application firmware is executed once per week in the background, it may not matter if that function takes 10 ms or 100 ms to execute. If a function is executed constantly at 10 Hz, it matters greatly if it takes 10 ms or 100 ms to execute. If a function in the application firmware is executed once per week in the background, it may not matter if that function takes 10 ms or 100 ms to execute. If a function is executed constantly at 10 Hz, it matters greatly if it takes 10 ms or 100 ms to execute.
Most application firmwares will only have a small set of functions which require optimal performance. Perhaps those functions are executed very often, or have to meet some application requirements for latency or throughput. Optimization efforts should be targeted at these particular functions. Most kinds of application firmware only have a small set of functions that require optimal performance. Perhaps those functions are executed very often, or have to meet some application requirements for latency or throughput. Optimization efforts should be targeted at these particular functions.
Measuring Performance Measuring Performance
--------------------- ---------------------
@ -24,7 +26,7 @@ The first step to improving something is to measure it.
Basic Performance Measurements Basic Performance Measurements
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If measuring performance relative to an external interaction with the world, you may be able to measure this directly (for example see the examples :example:`wifi/iperf` and :example:`ethernet/iperf` for measuring general network performance, or you can use an oscilloscope or logic analyzer to measure timing of an interaction with a device peripheral.) You may be able to measure directly the performance relative to an external interaction with the world, e.g., see the examples :example:`wifi/iperf` and :example:`ethernet/iperf` for measuring general network performance. Or you can use an oscilloscope or logic analyzer to measure the timing of an interaction with a device peripheral.
Otherwise, one way to measure performance is to augment the code to take timing measurements: Otherwise, one way to measure performance is to augment the code to take timing measurements:
@ -46,17 +48,17 @@ Otherwise, one way to measure performance is to augment the code to take timing
MEASUREMENTS, (end - start)/1000, (end - start)/MEASUREMENTS); MEASUREMENTS, (end - start)/1000, (end - start)/MEASUREMENTS);
} }
Executing the target multiple times can help average out factors like RTOS context switches, overhead of measurements, etc. Executing the target multiple times can help average out factors, e.g., RTOS context switches, overhead of measurements, etc.
- Using :cpp:func:`esp_timer_get_time` generates "wall clock" timestamps with microsecond precision, but has moderate overhead each time the timing functions are called. - Using :cpp:func:`esp_timer_get_time` generates "wall clock" timestamps with microsecond precision, but has moderate overhead each time the timing functions are called.
- It's also possible to use the standard Unix ``gettimeofday()`` and ``utime()`` functions, although the overhead is slightly higher. - It is also possible to use the standard Unix ``gettimeofday()`` and ``utime()`` functions, although the overhead is slightly higher.
- Otherwise, including ``hal/cpu_hal.h`` and calling the HAL function ``cpu_hal_get_cycle_count()`` will return the number of CPU cycles executed. This function has lower overhead than the others. It is good for measuring very short execution times with high precision. - Otherwise, including ``hal/cpu_hal.h`` and calling the HAL function ``cpu_hal_get_cycle_count()`` returns the number of CPU cycles executed. This function has lower overhead than the others, which is good for measuring very short execution times with high precision.
.. only:: not CONFIG_FREERTOS_UNICORE .. only:: not CONFIG_FREERTOS_UNICORE
The CPU cycles are counted per-core, so only use this method from an interrupt handler, or a task that is pinned to a single core. The CPU cycles are counted per-core, so only use this method from an interrupt handler, or a task that is pinned to a single core.
- While performing "microbenchmarks" (i.e. benchmarking only a very small routine of code that runs in less than 1-2 milliseconds), the flash cache performance can sometimes cause big variations in timing measurements depending on the binary. This happens because binary layout can cause different patterns of cache misses in a particular sequence of execution. If the test code is larger then this effect usually averages out. Executing a small function multiple times when benchmarking can help reduce the impact of flash cache misses. Alternatively, move this code to IRAM (see :ref:`speed-targeted-optimizations`). - While performing "microbenchmarks" (i.e., benchmarking only a very small routine of code that runs in less than 1-2 milliseconds), the flash cache performance can sometimes cause big variations in timing measurements depending on the binary. This happens because binary layout can cause different patterns of cache misses in a particular sequence of execution. If the test code is larger, then this effect usually averages out. Executing a small function multiple times when benchmarking can help reduce the impact of flash cache misses. Alternatively, move this code to IRAM (see :ref:`speed-targeted-optimizations`).
External Tracing External Tracing
^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^
@ -66,58 +68,58 @@ The :doc:`/api-guides/app_trace` allows measuring code execution with minimal im
Tasks Tasks
^^^^^ ^^^^^
If the option :ref:`CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS` is enabled then the FreeRTOS API :cpp:func:`vTaskGetRunTimeStats` can be used to retrieve runtime information about the processor time used by each FreeRTOS task. If the option :ref:`CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS` is enabled, then the FreeRTOS API :cpp:func:`vTaskGetRunTimeStats` can be used to retrieve runtime information about the processor time used by each FreeRTOS task.
:ref:`SEGGER SystemView <app_trace-system-behaviour-analysis-with-segger-systemview>` is an excellent tool for visualizing task execution and looking for performance issues or improvements in the system as a whole. :ref:`SEGGER SystemView <app_trace-system-behaviour-analysis-with-segger-systemview>` is an excellent tool for visualizing task execution and looking for performance issues or improvements in the system as a whole.
Improving Overall Speed Improving Overall Speed
----------------------- -----------------------
The following optimizations will improve the execution of nearly all code - including boot times, throughput, latency, etc: The following optimizations improve the execution of nearly all code, including boot times, throughput, latency, etc:
.. list:: .. list::
:esp32: - Set :ref:`CONFIG_ESPTOOLPY_FLASHFREQ` to 80 MHz. This is double the 40 MHz default value and will double the speed at which code is loaded or executed from flash. You should verify that the board or module that connects the {IDF_TARGET_NAME} to the flash chip is rated for 80 MHz operation at the relevant temperature ranges, before changing this setting. The hardware datasheet(s) will have this information. :esp32: - Set :ref:`CONFIG_ESPTOOLPY_FLASHFREQ` to 80 MHz. This is double the 40 MHz default value and doubles the speed at which code is loaded or executed from flash. You should verify that the board or module that connects the {IDF_TARGET_NAME} to the flash chip is rated for 80 MHz operation at the relevant temperature ranges before changing this setting. This information is contained in the hardware datasheet(s).
- Set :ref:`CONFIG_ESPTOOLPY_FLASHMODE` to QIO or QOUT mode (Quad I/O). Both will almost double the speed at which code is loaded or executed from flash compared to the default DIO mode. QIO is slightly faster than QOUT if both are supported. Note that both the flash chip model and the electrical connections between the {IDF_TARGET_NAME} and the flash chip must support quad I/O modes or the SoC will not work correctly. - Set :ref:`CONFIG_ESPTOOLPY_FLASHMODE` to QIO or QOUT mode (Quad I/O). Both almost double the speed at which code is loaded or executed from flash compared to the default DIO mode. QIO is slightly faster than QOUT if both are supported. Note that both the flash chip model, and the electrical connections between the {IDF_TARGET_NAME} and the flash chip must support quad I/O modes or the SoC will not work correctly.
- Set :ref:`CONFIG_COMPILER_OPTIMIZATION` to "Optimize for performance (-O2)". This may slightly increase binary size compared to the default setting, but will almost certainly increase performance of some code. Note that if your code contains C or C++ Undefined Behaviour then increasing the compiler optimization level may expose bugs that otherwise are not seen. - Set :ref:`CONFIG_COMPILER_OPTIMIZATION` to ``Optimize for performance (-O2)`` . This may slightly increase binary size compared to the default setting, but almost certainly increases the performance of some code. Note that if your code contains C or C++ Undefined Behavior, then increasing the compiler optimization level may expose bugs that otherwise are not seen.
:esp32: - If the application uses PSRAM and is based on ESP32 rev. 3 (ECO3), setting :ref:`CONFIG_ESP32_REV_MIN` to ``3`` will disable PSRAM bug workarounds, reducing the code size and improving overall performance. :esp32: - If the application uses PSRAM and is based on ESP32 rev. 3 (ECO3), setting :ref:`CONFIG_ESP32_REV_MIN` to ``3`` disables PSRAM bug workarounds, reducing the code size and improving overall performance.
:SOC_CPU_HAS_FPU: - Avoid using floating point arithmetic (``float``). Even though {IDF_TARGET_NAME} has a single precision hardware floating point unit, floating point calculations are always slower than integer calculations. If possible then use fixed point representations, a different method of integer representation, or convert part of the calculation to be integer only before switching to floating point. :SOC_CPU_HAS_FPU: - Avoid using floating point arithmetic ``float``. Even though {IDF_TARGET_NAME} has a single precision hardware floating point unit, floating point calculations are always slower than integer calculations. If possible then use fixed point representations, a different method of integer representation, or convert part of the calculation to be integer only before switching to floating point.
:not SOC_CPU_HAS_FPU: - Avoid using floating point arithmetic (``float``). On {IDF_TARGET_NAME} these calculations are emulated in software and are very slow. If possible then use fixed point representations, a different method of integer representation, or convert part of the calculation to be integer only before switching to floating point. :not SOC_CPU_HAS_FPU: - Avoid using floating point arithmetic ``float``. On {IDF_TARGET_NAME} these calculations are emulated in software and are very slow. If possible, use fixed point representations, a different method of integer representation, or convert part of the calculation to be integer only before switching to floating point.
- Avoid using double precision floating point arithmetic (``double``). These calculations are emulated in software and are very slow. If possible then use an integer-based representation, or single-precision floating point. - Avoid using double precision floating point arithmetic ``double``. These calculations are emulated in software and are very slow. If possible then use an integer-based representation, or single-precision floating point.
Reduce Logging Overhead Reduce Logging Overhead
^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^
Although standard output is buffered, it's possible for an application to be limited by the rate at which it can print data to log output once buffers are full. This is particularly relevant for startup time if a lot of output is logged, but can happen at other times as well. There are multiple ways to solve this problem: Although standard output is buffered, it is possible for an application to be limited by the rate at which it can print data to log output once buffers are full. This is particularly relevant for startup time if a lot of output is logged, but such problem can happen at other times as well. There are multiple ways to solve this problem:
.. list:: .. list::
- Reduce the volume of log output by lowering the app :ref:`CONFIG_LOG_DEFAULT_LEVEL` (the equivalent bootloader setting is :ref:`CONFIG_BOOTLOADER_LOG_LEVEL`). This also reduces the binary size, and saves some CPU time spent on string formatting. - Reduce the volume of log output by lowering the app :ref:`CONFIG_LOG_DEFAULT_LEVEL` (the equivalent bootloader setting is :ref:`CONFIG_BOOTLOADER_LOG_LEVEL`). This also reduces the binary size, and saves some CPU time spent on string formatting.
:not SOC_USB_OTG_SUPPORTED: - Increase the speed of logging output by increasing the :ref:`CONFIG_ESP_CONSOLE_UART_BAUDRATE` :not SOC_USB_OTG_SUPPORTED: - Increase the speed of logging output by increasing the :ref:`CONFIG_ESP_CONSOLE_UART_BAUDRATE`.
:SOC_USB_OTG_SUPPORTED: - Increase the speed of logging output by increasing the :ref:`CONFIG_ESP_CONSOLE_UART_BAUDRATE`. (Unless using internal USB-CDC for serial console, in which case the serial throughput doesn't depend on the configured baud rate.) :SOC_USB_OTG_SUPPORTED: - Increase the speed of logging output by increasing the :ref:`CONFIG_ESP_CONSOLE_UART_BAUDRATE`. However, if you are using internal USB-CDC, the serial throughput is not dependent on the configured baud rate.
Not Recommended Not Recommended
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^
The following options will also increase execution speed, but are not recommended as they also reduce the debuggability of the firmware application and may increase the severity of any bugs. The following options also increase execution speed, but are not recommended as they also reduce the debuggability of the firmware application and may increase the severity of any bugs.
.. list:: .. list::
- Set :ref:`CONFIG_COMPILER_OPTIMIZATION_ASSERTION_LEVEL` to disabled. This also reduces firmware binary size by a small amount. However, it may increase the severity of bugs in the firmware including security-related bugs. If necessary to do this to optimize a particular function, consider adding ``#define NDEBUG`` in the top of that single source file instead. - Set :ref:`CONFIG_COMPILER_OPTIMIZATION_ASSERTION_LEVEL` to disabled. This also reduces firmware binary size by a small amount. However, it may increase the severity of bugs in the firmware including security-related bugs. If it is necessary to do this to optimize a particular function, consider adding ``#define NDEBUG`` at the top of that single source file instead.
.. _speed-targeted-optimizations: .. _speed-targeted-optimizations:
Targeted Optimizations Targeted Optimizations
---------------------- ----------------------
The following changes will increase the speed of a chosen part of the firmware application: The following changes increase the speed of a chosen part of the firmware application:
.. list:: .. list::
- Move frequently executed code to IRAM. By default, all code in the app is executed from flash cache. This means that it's possible for the CPU to have to wait on a "cache miss" while the next instructions are loaded from flash. Functions which are copied into IRAM are loaded once at boot time, and then will always execute at full speed. - Move frequently executed code to IRAM. By default, all code in the app is executed from flash cache. This means that it is possible for the CPU to have to wait on a "cache miss" while the next instructions are loaded from flash. Functions which are copied into IRAM are loaded once at boot time, and then always execute at full speed.
IRAM is a limited resource, and using more IRAM may reduce available DRAM, so a strategic approach is needed when moving code to IRAM. See :ref:`iram` for more information. IRAM is a limited resource, and using more IRAM may reduce available DRAM, so a strategic approach is needed when moving code to IRAM. See :ref:`iram` for more information.
- Jump table optimizations can be re-enabled for individual source files that don't need to be placed in IRAM. For hot paths in large switch cases this will improve performance. For instructions on how to add the -fjump-tables -ftree-switch-conversion options when compiling individual source files, see :ref:`component_build_control` - Jump table optimizations can be re-enabled for individual source files that do not need to be placed in IRAM. For hot paths in large ``switch cases``, this improves performance. For instructions on how to add the ``-fjump-tables`` and ``-ftree-switch-conversion`` options when compiling individual source files, see :ref:`component_build_control`
Improving Startup Time Improving Startup Time
---------------------- ----------------------
@ -126,28 +128,28 @@ In addition to the overall performance improvements shown above, the following o
.. list:: .. list::
- Minimizing the :ref:`CONFIG_LOG_DEFAULT_LEVEL` and :ref:`CONFIG_BOOTLOADER_LOG_LEVEL` has a large impact on startup time. To enable more logging after the app starts up, set the :ref:`CONFIG_LOG_MAXIMUM_LEVEL` as well and then call :cpp:func:`esp_log_level_set` to restore higher level logs. The :example:`system/startup_time` main function shows how to do this. - Minimizing the :ref:`CONFIG_LOG_DEFAULT_LEVEL` and :ref:`CONFIG_BOOTLOADER_LOG_LEVEL` has a large impact on startup time. To enable more logging after the app starts up, set the :ref:`CONFIG_LOG_MAXIMUM_LEVEL` as well, and then call :cpp:func:`esp_log_level_set` to restore higher level logs. The :example:`system/startup_time` main function shows how to do this.
:SOC_RTC_FAST_MEM_SUPPORTED: - If using deep sleep, setting :ref:`CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP` allows a faster wake from sleep. Note that if using Secure Boot this represents a security compromise, as Secure Boot validation will not be performed on wake. :SOC_RTC_FAST_MEM_SUPPORTED: - If using Deep-sleep mode, setting :ref:`CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP` allows a faster wake from sleep. Note that if using Secure Boot, this represents a security compromise, as Secure Boot validation are not be performed on wake.
- Setting :ref:`CONFIG_BOOTLOADER_SKIP_VALIDATE_ON_POWER_ON` will skip verifying the binary on every boot from power-on reset. How much time this saves depends on the binary size and the flash settings. Note that this setting carries some risk if the flash becomes corrupt unexpectedly. Read the help text of the :ref:`config item <CONFIG_BOOTLOADER_SKIP_VALIDATE_ON_POWER_ON>` for an explanation and recommendations if using this option. - Setting :ref:`CONFIG_BOOTLOADER_SKIP_VALIDATE_ON_POWER_ON` skips verifying the binary on every boot from the power-on reset. How much time this saves depends on the binary size and the flash settings. Note that this setting carries some risk if the flash becomes corrupt unexpectedly. Read the help text of the :ref:`config item <CONFIG_BOOTLOADER_SKIP_VALIDATE_ON_POWER_ON>` for an explanation and recommendations if using this option.
- It's possible to save a small amount of time during boot by disabling RTC slow clock calibration. To do so, set :ref:`CONFIG_RTC_CLK_CAL_CYCLES` to 0. Any part of the firmware that uses RTC slow clock as a timing source will be less accurate as a result. - It is possible to save a small amount of time during boot by disabling RTC slow clock calibration. To do so, set :ref:`CONFIG_RTC_CLK_CAL_CYCLES` to 0. Any part of the firmware that uses RTC slow clock as a timing source will be less accurate as a result.
The example project :example:`system/startup_time` is pre-configured to optimize startup time. The file :example_file:`system/startup_time/sdkconfig.defaults` contain all of these settings. You can append these to the end of your project's own ``sdkconfig`` file to merge the settings, but please read the documentation for each setting first. The example project :example:`system/startup_time` is pre-configured to optimize startup time. The file :example_file:`system/startup_time/sdkconfig.defaults` contain all of these settings. You can append these to the end of your project's own ``sdkconfig`` file to merge the settings, but please read the documentation for each setting first.
Task Priorities Task Priorities
--------------- ---------------
As ESP-IDF FreeRTOS is a real-time operating system, it's necessary to ensure that high throughput or low latency tasks are granted a high priority in order to run immediately. Priority is set when calling :cpp:func:`xTaskCreate` or :cpp:func:`xTaskCreatePinnedToCore` and can be changed at runtime by calling :cpp:func:`vTaskPrioritySet`. As ESP-IDF FreeRTOS is a real-time operating system, it is necessary to ensure that high-throughput or low-slatency tasks are granted a high priority in order to run immediately. Priority is set when calling :cpp:func:`xTaskCreate` or :cpp:func:`xTaskCreatePinnedToCore` and can be changed at runtime by calling :cpp:func:`vTaskPrioritySet`.
It's also necessary to ensure that tasks yield CPU (by calling :cpp:func:`vTaskDelay`, ``sleep()``, or by blocking on semaphores, queues, task notifications, etc) in order to not starve lower priority tasks and cause problems for the overall system. The :ref:`task-watchdog-timer` provides a mechanism to automatically detect if task starvation happens, however note that a Task WDT timeout does not always indicate a problem (sometimes the correct operation of the firmware requires some long-running computation). In these cases tweaking the Task WDT timeout or even disabling the Task WDT may be necessary. It is also necessary to ensure that tasks yield CPU (by calling :cpp:func:`vTaskDelay`, ``sleep()``, or by blocking on semaphores, queues, task notifications, etc) in order to not starve lower-priority tasks and cause problems for the overall system. The :ref:`task-watchdog-timer` provides a mechanism to automatically detect if task starvation happens. However, note that a TWDT timeout does not always indicate a problem, because sometimes the correct operation of the firmware requires some long-running computation. In these cases, tweaking the TWDT timeout or even disabling the TWDT may be necessary.
.. _built-in-task-priorities: .. _built-in-task-priorities:
Built-In Task Priorities Built-in Task Priorities
^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^
ESP-IDF starts a number of system tasks at fixed priority levels. Some are automatically started during the boot process, some are started only if the application firmware initializes a particular feature. To optimize performance, structure application task priorities so that they are not delayed by system tasks, while also not starving system tasks and impacting other functions of the system. ESP-IDF starts a number of system tasks at fixed priority levels. Some are automatically started during the boot process, while some are started only if the application firmware initializes a particular feature. To optimize performance, structure the task priorities of your application properly to ensure the tasks are not delayed by the system tasks, while also not starving system tasks and impacting other functions of the system.
This may require splitting up a particular task. For example, perform a time-critical operation in a high priority task or an interrupt handler and do the non-time-critical part in a lower priority task. This may require splitting up a particular task. For example, perform a time-critical operation in a high-priority task or an interrupt handler and do the non-time-critical part in a lower-priority task.
Header :idf_file:`components/esp_system/include/esp_task.h` contains macros for the priority levels used for built-in ESP-IDF tasks system. See :ref:`freertos_system_tasks` for more details about the system tasks. Header :idf_file:`components/esp_system/include/esp_task.h` contains macros for the priority levels used for built-in ESP-IDF tasks system. See :ref:`freertos_system_tasks` for more details about the system tasks.
@ -159,78 +161,80 @@ Common priorities are:
.. list:: .. list::
- :ref:`Main task that executes app_main function <app-main-task>` has minimum priority (1). - :ref:`app-main-task` that executes app_main function has minimum priority (1).
- :doc:`/api-reference/system/esp_timer` system task to manage timer events and execute callbacks has high priority (22, ``ESP_TASK_TIMER_PRIO``) - :doc:`/api-reference/system/esp_timer` system task to manage timer events and execute callbacks has high priority (22, ``ESP_TASK_TIMER_PRIO``)
- FreeRTOS Timer Task to handle FreeRTOS timer callbacks is created when the scheduler initializes and has minimum task priority (1, :ref:`configurable <CONFIG_FREERTOS_TIMER_TASK_PRIORITY>`). - FreeRTOS Timer Task to handle FreeRTOS timer callbacks is created when the scheduler initializes and has minimum task priority (1, :ref:`configurable <CONFIG_FREERTOS_TIMER_TASK_PRIORITY>`).
- :doc:`/api-reference/system/esp_event` system task to manage the default system event loop and execute callbacks has high priority (20, ``ESP_TASK_EVENT_PRIO``). This configuration is only used if the application calls :cpp:func:`esp_event_loop_create_default`, it's possible to call :cpp:func:`esp_event_loop_create` with a custom task configuration instead. - :doc:`/api-reference/system/esp_event` system task to manage the default system event loop and execute callbacks has high priority (20, ``ESP_TASK_EVENT_PRIO``). This configuration is only used if the application calls :cpp:func:`esp_event_loop_create_default`. It is possible to call :cpp:func:`esp_event_loop_create` with a custom task configuration instead.
- :doc:`/api-guides/lwip` TCP/IP task has high priority (18, ``ESP_TASK_TCPIP_PRIO``). - :doc:`/api-guides/lwip` TCP/IP task has high priority (18).
:SOC_WIFI_SUPPORTED: - :doc:`Wi-Fi Driver </api-guides/wifi>` task has high priority (23). :SOC_WIFI_SUPPORTED: - :doc:`/api-guides/wifi` task has high priority (23).
:SOC_WIFI_SUPPORTED: - Wi-Fi wpa_supplicant component may create dedicated tasks while the Wi-Fi Protected Setup (WPS), WPA2 EAP-TLS, Device Provisioning Protocol (DPP) or BSS Transition Management (BTM) features are in use. These tasks all have low priority (2). :SOC_WIFI_SUPPORTED: - Wi-Fi wpa_supplicant component may create dedicated tasks while the Wi-Fi Protected Setup (WPS), WPA2 EAP-TLS, Device Provisioning Protocol (DPP) or BSS Transition Management (BTM) features are in use. These tasks all have low priority (2).
:SOC_BT_SUPPORTED: - :doc:`Bluetooth Controller </api-reference/bluetooth/index>` task has high priority (23, ``ESP_TASK_BT_CONTROLLER_PRIO``). The Bluetooth Controller needs to respond to requests with low latency, so it should always be close to the highest priority task in the system. :SOC_BT_SUPPORTED: - :doc:`/api-reference/bluetooth/controller_vhci` task has high priority (23, ``ESP_TASK_BT_CONTROLLER_PRIO``). The Bluetooth Controller needs to respond to requests with low latency, so it should always be among the highest priority task in the system.
:SOC_BT_SUPPORTED: - :doc:`NimBLE Bluetooth Host </api-reference/bluetooth/nimble/index>` host task has high priority (21). :SOC_BT_SUPPORTED: - :doc:`/api-reference/bluetooth/nimble/index` task has high priority (21).
- The Ethernet driver creates a task for the MAC to receive Ethernet frames. If using the default config ``ETH_MAC_DEFAULT_CONFIG`` then the priority is medium-high (15). This setting can be changed by passing a custom :cpp:class:`eth_mac_config_t` struct when initializing the Ethernet MAC. - The Ethernet driver creates a task for the MAC to receive Ethernet frames. If using the default config ``ETH_MAC_DEFAULT_CONFIG`` then the priority is medium-high (15). This setting can be changed by passing a custom :cpp:class:`eth_mac_config_t` struct when initializing the Ethernet MAC.
- If using the :doc:`MQTT </api-reference/protocols/mqtt>` component, it creates a task with default priority 5 (:ref:`configurable<CONFIG_MQTT_TASK_PRIORITY>`, depends on :ref:`CONFIG_MQTT_USE_CUSTOM_CONFIG` (also configurable runtime by ``task_prio`` field in the :cpp:class:`esp_mqtt_client_config_t`) - If using the :doc:`/api-reference/protocols/mqtt` component, it creates a task with default priority 5 (:ref:`configurable<CONFIG_MQTT_TASK_PRIORITY>`), depending on :ref:`CONFIG_MQTT_USE_CUSTOM_CONFIG`, and also configurable at runtime by ``task_prio`` field in the :cpp:class:`esp_mqtt_client_config_t`)
- To see what is the task priority for ``mDNS`` service, please check `Performance Optimization <https://docs.espressif.com/projects/esp-protocols/mdns/docs/latest/en/index.html#execution-speed>`__. - To see what is the task priority for ``mDNS`` service, please check `Performance Optimization <https://docs.espressif.com/projects/esp-protocols/mdns/docs/latest/en/index.html#performance-optimization>`__.
.. only :: not CONFIG_FREERTOS_UNICORE .. only :: not CONFIG_FREERTOS_UNICORE
.. list:: .. list::
- :ref:`Main task that executes app_main function <app-main-task>` has minimum priority (1). This task is pinned to Core 0 by default (:ref:`configurable<CONFIG_ESP_MAIN_TASK_AFFINITY>`). - :ref:`app-main-task` that executes app_main function has minimum priority (1). This task is pinned to Core 0 by default (:ref:`configurable<CONFIG_ESP_MAIN_TASK_AFFINITY>`).
- :doc:`/api-reference/system/esp_timer` system task to manage high precision timer events and execute callbacks has high priority (22, ``ESP_TASK_TIMER_PRIO``). This task is pinned to Core 0. - :doc:`/api-reference/system/esp_timer` system task to manage high precision timer events and execute callbacks has high priority (22, ``ESP_TASK_TIMER_PRIO``). This task is pinned to Core 0.
- FreeRTOS Timer Task to handle FreeRTOS timer callbacks is created when the scheduler initializes and has minimum task priority (1, :ref:`configurable <CONFIG_FREERTOS_TIMER_TASK_PRIORITY>`). This task is pinned to Core 0. - FreeRTOS Timer Task to handle FreeRTOS timer callbacks is created when the scheduler initializes and has minimum task priority (1, :ref:`configurable <CONFIG_FREERTOS_TIMER_TASK_PRIORITY>`). This task is pinned to Core 0.
- :doc:`/api-reference/system/esp_event` system task to manage the default system event loop and execute callbacks has high priority (20, ``ESP_TASK_EVENT_PRIO``) and pinned to Core 0. This configuration is only used if the application calls :cpp:func:`esp_event_loop_create_default`, it's possible to call :cpp:func:`esp_event_loop_create` with a custom task configuration instead. - :doc:`/api-reference/system/esp_event` system task to manage the default system event loop and execute callbacks has high priority (20, ``ESP_TASK_EVENT_PRIO``) and it is pinned to Core 0. This configuration is only used if the application calls :cpp:func:`esp_event_loop_create_default`, it is possible to call :cpp:func:`esp_event_loop_create` with a custom task configuration instead.
- :doc:`/api-guides/lwip` TCP/IP task has high priority (18, ``ESP_TASK_TCPIP_PRIO``) and is not pinned to any core (:ref:`configurable<CONFIG_LWIP_TCPIP_TASK_AFFINITY>`). - :doc:`/api-guides/lwip` TCP/IP task has high priority (18) and is not pinned to any core (:ref:`configurable<CONFIG_LWIP_TCPIP_TASK_AFFINITY>`).
:SOC_WIFI_SUPPORTED: - :doc:`Wi-Fi Driver </api-guides/wifi>` task has high priority (23) and is pinned to Core 0 by default (:ref:`configurable<CONFIG_ESP_WIFI_TASK_CORE_ID>`). :SOC_WIFI_SUPPORTED: - :doc:`/api-guides/wifi` task has high priority (23) and is pinned to Core 0 by default (:ref:`configurable<CONFIG_ESP_WIFI_TASK_CORE_ID>`).
:SOC_WIFI_SUPPORTED: - Wi-Fi wpa_supplicant component may create dedicated tasks while the Wi-Fi Protected Setup (WPS), WPA2 EAP-TLS, Device Provisioning Protocol (DPP) or BSS Transition Management (BTM) features are in use. These tasks all have low priority (2) and are not pinned to any core. :SOC_WIFI_SUPPORTED: - Wi-Fi wpa_supplicant component may create dedicated tasks while the Wi-Fi Protected Setup (WPS), WPA2 EAP-TLS, Device Provisioning Protocol (DPP) or BSS Transition Management (BTM) features are in use. These tasks all have low priority (2) and are not pinned to any core.
:SOC_BT_SUPPORTED: - :doc:`Bluetooth Controller </api-reference/bluetooth/index>` task has high priority (23, ``ESP_TASK_BT_CONTROLLER_PRIO``) and is pinned to Core 0 by default (:ref:`configurable <{IDF_TARGET_CONTROLLER_CORE_CONFIG}>`). The Bluetooth Controller needs to respond to requests with low latency, so it should always be close to the highest priority task assigned to a single CPU. :SOC_BT_SUPPORTED: - :doc:`/api-reference/bluetooth/controller_vhci` task has high priority (23, ``ESP_TASK_BT_CONTROLLER_PRIO``) and is pinned to Core 0 by default (:ref:`configurable <{IDF_TARGET_CONTROLLER_CORE_CONFIG}>`). The Bluetooth Controller needs to respond to requests with low latency, so it should always be among the highest priority task assigned to a single CPU.
:SOC_BT_SUPPORTED: - :doc:`NimBLE Bluetooth Host </api-reference/bluetooth/nimble/index>` host task has high priority (21) and is pinned to Core 0 by default (:ref:`configurable <CONFIG_BT_NIMBLE_PINNED_TO_CORE_CHOICE>`). :SOC_BT_SUPPORTED: - :doc:`/api-reference/bluetooth/nimble/index` task has high priority (21) and is pinned to Core 0 by default (:ref:`configurable <CONFIG_BT_NIMBLE_PINNED_TO_CORE_CHOICE>`).
:esp32: - :doc:`Bluedroid Bluetooth Host </api-reference/bluetooth/index>` creates multiple tasks when used: :esp32: - :doc:`/api-reference/bluetooth/index` creates multiple tasks when used:
- Stack event callback task ("BTC") has high priority (19). - Stack event callback task ("BTC") has high priority (19).
- Stack BTU layer task has high priority (20). - Stack BTU layer task has high priority (20).
- Host HCI host task has high priority (22). - Host HCI host task has high priority (22).
All Bluedroid Tasks are pinned to the same core, which is Core 0 by default (:ref:`configurable <CONFIG_BT_BLUEDROID_PINNED_TO_CORE_CHOICE>`). All Bluedroid Tasks are pinned to the same core, which is Core 0 by default (:ref:`configurable <CONFIG_BT_BLUEDROID_PINNED_TO_CORE_CHOICE>`).
- The Ethernet driver creates a task for the MAC to receive Ethernet frames. If using the default config ``ETH_MAC_DEFAULT_CONFIG`` then the priority is medium-high (15) and the task is not pinned to any core. These settings can be changed by passing a custom :cpp:class:`eth_mac_config_t` struct when initializing the Ethernet MAC. - The Ethernet driver creates a task for the MAC to receive Ethernet frames. If using the default config ``ETH_MAC_DEFAULT_CONFIG`` then the priority is medium-high (15) and the task is not pinned to any core. These settings can be changed by passing a custom :cpp:class:`eth_mac_config_t` struct when initializing the Ethernet MAC.
- If using the :doc:`MQTT </api-reference/protocols/mqtt>` component, it creates a task with default priority 5 (:ref:`configurable <CONFIG_MQTT_TASK_PRIORITY>`, depends on :ref:`CONFIG_MQTT_USE_CUSTOM_CONFIG`) and not pinned to any core (:ref:`configurable <CONFIG_MQTT_TASK_CORE_SELECTION_ENABLED>`). - If using the :doc:`MQTT </api-reference/protocols/mqtt>` component, it creates a task with default priority 5 (:ref:`configurable <CONFIG_MQTT_TASK_PRIORITY>`, depends on :ref:`CONFIG_MQTT_USE_CUSTOM_CONFIG`) and not pinned to any core (:ref:`configurable <CONFIG_MQTT_TASK_CORE_SELECTION_ENABLED>`).
- To see what is the task priority for ``mDNS`` service, please check `Performance Optimization <https://espressif.github.io/esp-protocols/mdns/en/index.html#execution-speed>`__. - To see what is the task priority for ``mDNS`` service, please check `Performance Optimization <https://espressif.github.io/esp-protocols/mdns/en/index.html#execution-speed>`__.
Choosing application task priorities
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Choosing Task Priorities of the Application
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. only:: CONFIG_FREERTOS_UNICORE .. only:: CONFIG_FREERTOS_UNICORE
In general, it's not recommended to set task priorities higher than the built-in {IDF_TARGET_RF_TYPE} operations as starving them of CPU may make the system unstable. For very short timing-critical operations that don't use the network, use an ISR or a very restricted task (very short bursts of runtime only) at highest priority (24). Choosing priority 19 will allow lower layer {IDF_TARGET_RF_TYPE} functionality to run without delays, but still preempts the lwIP TCP/IP stack and other less time-critical internal functionality - this is the best option for time-critical tasks that don't perform network operations. Any task that does TCP/IP network operations should run at lower priority than the lwIP TCP/IP task (18) to avoid priority inversion issues. In general, it is not recommended to set task priorities higher than the built-in {IDF_TARGET_RF_TYPE} operations as starving them of CPU may make the system unstable. For very short timing-critical operations that do not use the network, use an ISR or a very restricted task (with very short bursts of runtime only) at the highest priority (24). Choosing priority 19 allows lower-layer {IDF_TARGET_RF_TYPE} functionality to run without delays, but still preempts the lwIP TCP/IP stack and other less time-critical internal functionality - this is the best option for time-critical tasks that do not perform network operations. Any task that does TCP/IP network operations should run at a lower priority than the lwIP TCP/IP task (18) to avoid priority-inversion issues.
.. only:: not CONFIG_FREERTOS_UNICORE .. only:: not CONFIG_FREERTOS_UNICORE
With a few exceptions (most importantly the lwIP TCP/IP task), in the default configuration most built-in tasks are pinned to Core 0. This makes it quite easy for the application to place high priority tasks on Core 1. Using priority 19 or higher will guarantee an application task can run on Core 1 without being preempted by any built-in task. To further isolate the tasks running on each CPU, configure the :ref:`lwIP task <CONFIG_LWIP_TCPIP_TASK_AFFINITY>` to only run on Core 0 instead of either core (this may reduce total TCP/IP throughput depending on what other tasks are running). With a few exceptions, most importantly the lwIP TCP/IP task, in the default configuration most built-in tasks are pinned to Core 0. This makes it quite easy for the application to place high priority tasks on Core 1. Using priority 19 or higher guarantees that an application task can run on Core 1 without being preempted by any built-in task. To further isolate the tasks running on each CPU, configure the :ref:`lwIP task <CONFIG_LWIP_TCPIP_TASK_AFFINITY>` to only run on Core 0 instead of either core, which may reduce total TCP/IP throughput depending on what other tasks are running.
In general, it's not recommended to set task priorities on Core 0 higher than the built-in {IDF_TARGET_RF_TYPE} operations as starving them of CPU may make the system unstable. Choosing priority 19 and Core 0 will allow lower layer {IDF_TARGET_RF_TYPE} functionality to run without delays, but still pre-empts the lwIP TCP/IP stack and other less time-critical internal functionality - this is an option for time-critical tasks that don't perform network operations. Any task that does TCP/IP network operations should run at lower priority than the lwIP TCP/IP task (18) to avoid priority inversion issues. In general, it is not recommended to set task priorities on Core 0 higher than the built-in {IDF_TARGET_RF_TYPE} operations as starving them of CPU may make the system unstable. Choosing priority 19 and Core 0 allows lower-layer {IDF_TARGET_RF_TYPE} functionality to run without delays, but still pre-empts the lwIP TCP/IP stack and other less time-critical internal functionality. This is an option for time-critical tasks that do not perform network operations. Any task that does TCP/IP network operations should run at lower priority than the lwIP TCP/IP task (18) to avoid priority-inversion issues.
.. note:: .. note::
Setting a task to always run in preference to built-in ESP-IDF tasks does not require pinning to Core 1. The task can be left unpinned - at priority 17 or lower - to optionally run on Core 0 as well, if no higher priority built-in task is running there. Using unpinned tasks can improve the overall CPU utilization, however it makes reasoning about task scheduling more complex. Setting a task to always run in preference to built-in ESP-IDF tasks does not require pinning the task to Core 1. Instead, the task can be left unpinned and assigned a priority of 17 or lower. This allows the task to optionally run on Core 0 if there are no higher-priority built-in tasks running on that core. Using unpinned tasks can improve the overall CPU utilization, however it makes reasoning about task scheduling more complex.
.. note:: .. note::
Task execution is always completely suspended when writing to the built-in SPI flash chip. Only :ref:`iram-safe-interrupt-handlers` will continue executing. Task execution is always completely suspended when writing to the built-in SPI flash chip. Only :ref:`iram-safe-interrupt-handlers` continues executing.
Improving Interrupt Performance Improving Interrupt Performance
------------------------------- -------------------------------
ESP-IDF supports dynamic :doc:`/api-reference/system/intr_alloc` with interrupt preemption. Each interrupt in the system has a priority, and higher priority interrupts will preempt lower priority ones. ESP-IDF supports dynamic :doc:`/api-reference/system/intr_alloc` with interrupt preemption. Each interrupt in the system has a priority, and higher-priority interrupts preempts lower priority ones.
Interrupt handlers will execute in preference to any task (provided the task is not inside a critical section). For this reason, it's important to minimize the amount of time spent executing in an interrupt handler. Interrupt handlers execute in preference to any task, provided the task is not inside a critical section. For this reason, it is important to minimize the amount of time spent in executing an interrupt handler.
To obtain the best performance for a particular interrupt handler: To obtain the best performance for a particular interrupt handler:
.. list:: .. list::
- Assign more important interrupts a higher priority using a flag such as ``ESP_INTR_FLAG_LEVEL2`` or ``ESP_INTR_FLAG_LEVEL3`` when calling :cpp:func:`esp_intr_alloc`. - Assign more important interrupts a higher priority using a flag such as ``ESP_INTR_FLAG_LEVEL2`` or ``ESP_INTR_FLAG_LEVEL3`` when calling :cpp:func:`esp_intr_alloc`.
:not CONFIG_FREERTOS_UNICORE: - Assign the interrupt on a CPU where built-in {IDF_TARGET_RF_TYPE} tasks are not configured to run (this means assigning on Core 1 by default, see :ref:`built-in-task-priorities`). Interrupts are assigned on the same CPU where the :cpp:func:`esp_intr_alloc` function call is made. :not CONFIG_FREERTOS_UNICORE: - Assign the interrupt on a CPU where built-in {IDF_TARGET_RF_TYPE} tasks are not configured to run, which means assigning the interrupt on Core 1 by default, see :ref:`built-in-task-priorities`. Interrupts are assigned on the same CPU where the :cpp:func:`esp_intr_alloc` function call is made.
- If you're sure the entire interrupt handler can run from IRAM (see :ref:`iram-safe-interrupt-handlers`) then set the ``ESP_INTR_FLAG_IRAM`` flag when calling :cpp:func:`esp_intr_alloc` to assign the interrupt. This prevents it being temporarily disabled if the application firmware writes to the internal SPI flash. - If you are sure the entire interrupt handler can run from IRAM (see :ref:`iram-safe-interrupt-handlers`) then set the ``ESP_INTR_FLAG_IRAM`` flag when calling :cpp:func:`esp_intr_alloc` to assign the interrupt. This prevents it being temporarily disabled if the application firmware writes to the internal SPI flash.
- Even if the interrupt handler is not IRAM safe, if it is going to be executed frequently then consider moving the handler function to IRAM anyhow. This minimizes the chance of a flash cache miss when the interrupt code is executed (see :ref:`speed-targeted-optimizations`). It's possible to do this without adding the ``ESP_INTR_FLAG_IRAM`` flag to mark the interrupt as IRAM-safe, if only part of the handler is guaranteed to be in IRAM. - Even if the interrupt handler is not IRAM-safe, if it is going to be executed frequently then consider moving the handler function to IRAM anyhow. This minimizes the chance of a flash cache miss when the interrupt code is executed (see :ref:`speed-targeted-optimizations`). It is possible to do this without adding the ``ESP_INTR_FLAG_IRAM`` flag to mark the interrupt as IRAM-safe, if only part of the handler is guaranteed to be in IRAM.
Improving Network Speed Improving Network Speed
----------------------- -----------------------
@ -239,21 +243,20 @@ Improving Network Speed
:SOC_WIFI_SUPPORTED: * For Wi-Fi, see :ref:`How-to-improve-Wi-Fi-performance` and :ref:`wifi-buffer-usage` :SOC_WIFI_SUPPORTED: * For Wi-Fi, see :ref:`How-to-improve-Wi-Fi-performance` and :ref:`wifi-buffer-usage`
* For lwIP TCP/IP (Wi-Fi and Ethernet), see :ref:`lwip-performance` * For lwIP TCP/IP (Wi-Fi and Ethernet), see :ref:`lwip-performance`
:SOC_WIFI_SUPPORTED: * The :example:`wifi/iperf` example contains a configuration that is heavily optimized for Wi-Fi TCP/IP throughput. Append the contents of the files :example_file:`wifi/iperf/sdkconfig.defaults`, :example_file:`wifi/iperf/sdkconfig.defaults.{IDF_TARGET_PATH_NAME}` and :example_file:`wifi/iperf/sdkconfig.ci.99` to your project ``sdkconfig`` file in order to add all of these options. Note that some of these options may have trade-offs in terms of reduced debuggability, increased firmware size, increased memory usage, or reduced performance of other features. To get the best result, read the documentation pages linked above and use this information to determine exactly which options are best suited for your app. :SOC_WIFI_SUPPORTED: * The :example:`wifi/iperf` example contains a configuration that is heavily optimized for Wi-Fi TCP/IP throughput. Append the contents of the files :example_file:`wifi/iperf/sdkconfig.defaults`, :example_file:`wifi/iperf/sdkconfig.defaults.{IDF_TARGET_PATH_NAME}` and :example_file:`wifi/iperf/sdkconfig.ci.99` to the ``sdkconfig`` file in your project in order to add all of these options. Note that some of these options may have trade-offs in terms of reduced debuggability, increased firmware size, increased memory usage, or reduced performance of other features. To get the best result, read the documentation pages linked above and use related information to determine exactly which options are best suited for your app.
Improving I/O performance Improving I/O Performance
------------------------- -------------------------
Using standard C library functions like ``fread`` and ``fwrite`` instead of platform specific unbuffered syscalls such as ``read`` and ``write`` can be slow. Using standard C library functions like ``fread`` and ``fwrite`` instead of platform specific unbuffered syscalls such as ``read`` and ``write`` can be slow.These functions are designed to be portable, so they are not necessarily optimized for speed, have a certain overhead and are buffered.
These functions are designed to be portable, so they are not necessarily optimized for speed, have a certain overhead and are buffered.
:doc:`FatFS </api-reference/storage/fatfs>` specific information and tips: :doc:`/api-reference/storage/fatfs` specific information and tips:
.. list:: .. list::
- Maximum size of the R/W request == FatFS cluster size (allocation unit size) - Maximum size of the R/W request = FatFS cluster size (allocation unit size).
- Use ``read`` and ``write`` instead of ``fread`` and ``fwrite`` - Use ``read`` and ``write`` instead of ``fread`` and ``fwrite``.
- To increase speed of buffered reading functions like ``fread`` and ``fgets``, you can increase a size of the file buffer (Newlib's default is 128 bytes) to a higher number like 4096, 8192 or 16384. This can be done locally via ``setvbuf`` function used on a certain file pointer or globally applied to all files via modifying :ref:`CONFIG_FATFS_VFS_FSTAT_BLKSIZE`. - To increase speed of buffered reading functions like ``fread`` and ``fgets``, you can increase a size of the file buffer (Newlib's default is 128 bytes) to a higher number like 4096, 8192 or 16384. This can be done locally via the ``setvbuf`` function used on a certain file pointer or globally applied to all files via modifying :ref:`CONFIG_FATFS_VFS_FSTAT_BLKSIZE`.
.. note:: .. note::
Setting a bigger buffer size will also increase the heap memory usage. Setting a bigger buffer size also increases the heap memory usage.

View File

@ -5,8 +5,9 @@ Wi-Fi Security
----------------------------------------- -----------------------------------------
- Support for Protected Management Frames (PMF) - Support for Protected Management Frames (PMF)
- Support for WPA3-Personal - Support for WPA3-Personal
- Support for Opportunistic Wireless Encryption
In addition to traditional security methods (WEP/WPA-TKIP/WPA2-CCMP), {IDF_TARGET_NAME} Wi-Fi supports state-of-the-art security protocols, namely Protected Management Frames based on 802.11w standard and Wi-Fi Protected Access 3 (WPA3-Personal). Together, PMF and WPA3 provide better privacy and robustness against known attacks on traditional modes. In addition to traditional security methods (WEP/WPA-TKIP/WPA2-CCMP), {IDF_TARGET_NAME} Wi-Fi supports state-of-the-art security protocols, namely Protected Management, Wi-Fi Protected Access 3 and Enhanced Open based on Opportunistic Wireless Encryption. WPA3 provides better privacy and robustness against known attacks on traditional modes. Enhanced Open enhances security and privacy of users connecting to open (public) Wireless Network without authentication.
Protected Management Frames (PMF) Protected Management Frames (PMF)
--------------------------------- ---------------------------------
@ -15,13 +16,7 @@ Introduction
++++++++++++ ++++++++++++
In Wi-Fi, management frames such as beacons, probes, (de)authentication, (dis)association are used by non-AP stations to scan and connect to an AP. Unlike data frames, these frames are sent unencrypted. In Wi-Fi, management frames such as beacons, probes, (de)authentication, (dis)association are used by non-AP stations to scan and connect to an AP. Unlike data frames, these frames are sent unencrypted.
An attacker can use eavesdropping and packet injection to send spoofed (de)authentication/(dis)association frames at the right time, leading to the following attacks in case of unprotected management frame exchanges. An attacker can use eavesdropping and packet injection to send spoofed (de)authentication/(dis)association frames at the right time, leading to attacks such as Denial-of-Service (DOS) and man-in-the-middle
- DOS attack on one or all clients in the range of the attacker.
- Tearing down existing association on AP side by sending association request.
- Forcing a client to perform 4-way handshake again in case PSK is compromised in order to get PTK.
- Getting SSID of hidden network from association request.
- Launching man-in-the-middle attack by forcing clients to deauth from legitimate AP and associating to a rogue one.
PMF provides protection against these attacks by encrypting unicast management frames and providing integrity checks for broadcast management frames. These include deauthentication, disassociation and robust management frames. It also provides Secure Association (SA) teardown mechanism to prevent spoofed association/authentication frames from disconnecting already connected clients. PMF provides protection against these attacks by encrypting unicast management frames and providing integrity checks for broadcast management frames. These include deauthentication, disassociation and robust management frames. It also provides Secure Association (SA) teardown mechanism to prevent spoofed association/authentication frames from disconnecting already connected clients.
@ -30,24 +25,6 @@ There are 3 types of PMF configuration modes on both station and AP side -
- PMF Required - PMF Required
- PMF Disabled - PMF Disabled
Depending on PMF configurations on Station and AP side, the resulting connection will behave differently. The table below summarises all possible outcomes -
+--------------+------------------------+---------------------------+
| STA Setting | AP Setting | Outcome |
+==============+========================+===========================+
| PMF Optional | PMF Optional/Required | Mgmt Frames Protected |
+--------------+------------------------+---------------------------+
| PMF Optional | PMF Disabled | Mgmt Frames Not Protected |
+--------------+------------------------+---------------------------+
| PMF Required | PMF Optional/Required | Mgmt Frames Protected |
+--------------+------------------------+---------------------------+
| PMF Required | PMF Disabled | STA refuses Connection |
+--------------+------------------------+---------------------------+
| PMF Disabled | PMF Optional/Disabled | Mgmt Frames Not Protected |
+--------------+------------------------+---------------------------+
| PMF Disabled | PMF Required | AP refuses Connection |
+--------------+------------------------+---------------------------+
API & Usage API & Usage
+++++++++++ +++++++++++
@ -57,6 +34,29 @@ API & Usage
``capable`` flag in `pmf_cfg` is deprecated and set to true internally. This is to take the additional security benefit of PMF whenever possible. ``capable`` flag in `pmf_cfg` is deprecated and set to true internally. This is to take the additional security benefit of PMF whenever possible.
WiFi Enterprise
---------------------------------
Introduction
++++++++++++
Enterprise security is the secure authentication mechanism for enterprise wireless networks. It uses RADIUS server for authentication of network users before connecting to the Access Point. The authentication process is based on 802.1X policy and comes with different Extended Authentication Protocol (EAP) methods such as TLS, TTLS, PEAP and EAP-FAST. RADIUS server authenticates the users based on their credentials (username and password), digital certificates or both.
**{IDF_TARGET_NAME} supports WiFi Enterprise only in station mode.**
{IDF_TARGET_NAME} Supports **WPA2-Enterprise** and **WPA3-Enterprise**. WPA3-Enterprise builds upon the foundation of WPA2-Enterprise with the additional requirement of using Protected Management Frames (PMF) and server certificate validation on all WPA3 connections. **WPA3-Enterprise also offers an addition secure mode using 192-bit minimum-strength security protocols and cryptographic tools to better protect sensitive data.** The 192-bit security mode offered by WPA3-Enterprise ensures the right combination of cryptographic tools are used and sets a consistent baseline of security within a WPA3 network. WPA3-Enterprise 192-bit mode is only supported by modules having :c:macro:`SOC_WIFI_GCMP_SUPPORT` support. Enable :ref:`CONFIG_ESP_WIFI_SUITE_B_192` flag to support WPA3-Enterprise with 192-bit mode.
{IDF_TARGET_NAME} supports the following EAP methods:
- EAP-TLS: This is a certificate-based method and only requires SSID and EAP-IDF.
- PEAP: This is a Protected EAP method. Username and password are mandatory.
- EAP-TTLS: This is a credential-based method. Only server authentication is mandatory while user authentication is optional. Username and Password are mandatory. It supports different Phase2 methods, such as:
- PAP: Password Authentication Protocol.
- CHAP: Challenge Handshake Authentication Protocol.
- MSCHAP and MSCHAP-V2.
- EAP-FAST: This is an authentication method based on Protected Access Credentials (PAC) which also uses identity and password. Currently, :ref:`CONFIG_ESP_WIFI_MBEDTLS_TLS_CLIENT` flag should be disabled to use this feature.
Example :example:`wifi/wifi_enterprise` demonstrates all the supported WiFi Enterprise methods except EAP-FAST. Please refer :example:`wifi/wifi_eap_fast` for EAP-FAST example. EAP method can be selected from the Example Configuration menu in ``idf.py menuconfig``. Refer to :idf_file:`examples/wifi/wifi_enterprise/README.md` for information on how to generate certificates and run the example.
WPA3-Personal WPA3-Personal
------------- -------------
@ -70,17 +70,40 @@ Wi-Fi Protected Access-3 (WPA3) is a set of enhancements to Wi-Fi access securit
- Mandates Protected Management Frames (PMF), which provides protection for unicast and multicast robust management frames which include Disassoc and Deauth frames. This means that the attacker cannot disrupt an established WPA3 session by sending forged Assoc frames to the AP or Deauth/Disassoc frames to the Station. - Mandates Protected Management Frames (PMF), which provides protection for unicast and multicast robust management frames which include Disassoc and Deauth frames. This means that the attacker cannot disrupt an established WPA3 session by sending forged Assoc frames to the AP or Deauth/Disassoc frames to the Station.
- Provides forward secrecy, which means the captured data cannot be decrypted even if password is compromised after data transmission. - Provides forward secrecy, which means the captured data cannot be decrypted even if password is compromised after data transmission.
**{IDF_TARGET_NAME} station also supports following additional Wi-Fi CERTIFIED WPA3™ features.**
- **Transition Disable** : WPA3 defines transition modes for client devices so that they can connect to a network even when some of the APs in that network do not support the strongest security mode. Client device implementations typically configure network profiles in a transition mode by default. However, such a client device could be subject to an active downgrade attack in which the attacker causes the client device to use a lower security mode in order to exploit a vulnerability with that mode. WPA3 has introduced the Transition Disable feature to mitigate such attacks, by enabling client devices to change from a transition mode to an “only” mode when connecting to a network, once that network indicates it fully supports the higher security mode. Enable :cpp:type:`transition_disable` in :cpp:type:`wifi_sta_config_t` to enable this feature for {IDF_TARGET_NAME} station.
- **SAE PUBLIC-KEY (PK)** : As the password at small public networks is shared with multiple users it may be relatively easy for an attacker to find out the password, which is sufficient to launch an evil twin attack. Such attacks are prevented by an extension to WPA3-Personal called SAE-PK. The SAE-PK authentication exchange is very similar to the regular SAE exchange, with the addition of a digital signature sent by the AP to the client device. The client device validates the public key asserted by the AP based on the password fingerprint, and verifies the signature using the public key. So even if the attacker knows the password, it does not know the private key to generate a valid signature, and therefore the client device is protected against an evil twin attack. Enable :ref:`CONFIG_ESP_WIFI_ENABLE_SAE_PK` and :cpp:type:`sae_pk_mode` in :cpp:type:`wifi_sta_config_t` to add support of SAE PK for {IDF_TARGET_NAME} station.
- **SAE PWE Methods**: {IDF_TARGET_NAME} station as well as softAP supports SAE Password Element derivation method `Hunting And Pecking` and `Hash to Element (H2E)`. H2E is computationally efficient as it uses less iterations than Hunt and Peck, also it mitigates side channel attacks. These can be configured using parameter :cpp:type:`sae_pwe_h2e` from :cpp:type:`wifi_sta_config_t` and :cpp:type:`wifi_ap_config_t` for station and softAP respectively. Hunt and peck, H2E both can be enabled by using :cpp:enumerator:`WPA3_SAE_PWE_BOTH` configuration.
Please refer to `Security <https://www.wi-fi.org/discover-wi-fi/security>`_ section of Wi-Fi Alliance's official website for further details. Please refer to `Security <https://www.wi-fi.org/discover-wi-fi/security>`_ section of Wi-Fi Alliance's official website for further details.
Setting up WPA3 with {IDF_TARGET_NAME} Setting up WPA3 Personal with {IDF_TARGET_NAME}
++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++
In IDF Menuconfig under Wi-Fi component, a config option "Enable WPA3-Personal" is provided to Enable/Disable WPA3 for station. By default it is kept enabled, if disabled {IDF_TARGET_NAME} will not be able to establish a WPA3 connection. Also under WI-FI component a config option "ESP_WIFI_SOFTAP_SAE_SUPPORT" is provided to Enable/Disable WPA3 for softAP. Additionally, since PMF is mandated by WPA3 protocol, PMF Mode Optional is set by default for station and softAP. PMF Required can be configured using WiFi config. For WPA3 softAP, PMF required is mandatory and will be configured and stored in NVS implicitly if not specified by user. A config option :ref:`CONFIG_ESP_WIFI_ENABLE_WPA3_SAE` is provided to Enable/Disable WPA3 for station. By default it is kept enabled, if disabled {IDF_TARGET_NAME} will not be able to establish a WPA3 connection. Also under WI-FI component a config option :ref:`CONFIG_ESP_WIFI_SOFTAP_SAE_SUPPORT` is provided to Enable/Disable WPA3 for softAP. Additionally, since PMF is mandated by WPA3 protocol, PMF Mode Optional is set by default for station and softAP. PMF Required can be configured using WiFi config. For WPA3 softAP, PMF required is mandatory and will be configured and stored in NVS implicitly if not specified by user.
Refer to `Protected Management Frames (PMF)`_ on how to set this mode. Refer to `Protected Management Frames (PMF)`_ on how to set this mode.
After configuring all required settings for WPA3-Personal station, application developers need not worry about the underlying security mode of the AP. WPA3-Personal is now the highest supported protocol in terms of security, so it will be automatically selected for the connection whenever available. For example, if an AP is configured to be in WPA3 Transition Mode, where it will advertise as both WPA2 and WPA3 capable, Station will choose WPA3 for the connection with above settings. After configuring all required settings for WPA3-Personal station, application developers need not worry about the underlying security mode of the AP. WPA3-Personal is now the highest supported protocol in terms of security, so it will be automatically selected for the connection whenever available. For example, if an AP is configured to be in WPA3 Transition Mode, where it will advertise as both WPA2 and WPA3 capable, Station will choose WPA3 for the connection with above settings.
Note that Wi-Fi stack size requirement will increase 3kB when "Enable WPA3-Personal" is used. Note that Wi-Fi stack size requirement will increase 3kB when "Enable WPA3-Personal" is used.
After configuring all required setting for WPA3-Personal softAP, application developers have to set ``WIFI_AUTH_WPA3_PSK`` as WiFi config authmode to start AP in softAP. SoftAP can be also configured to use ``WIFI_AUTH_WPA2_WPA3_PSK`` mixed mode. After configuring all required setting for WPA3-Personal softAP, application developers have to set ``WIFI_AUTH_WPA3_PSK`` for `authmode` in :cpp:type:`wifi_ap_config_t` to start AP in WPA3 security. SoftAP can be also configured to use ``WIFI_AUTH_WPA2_WPA3_PSK`` mixed mode.
Note that flash size will be increased by 6kB after enabling "ESP_WIFI_SOFTAP_SAE_SUPPORT". Note that binary size will be increased by ~6.5 kilobytes after enabling ":ref:`CONFIG_ESP_WIFI_SOFTAP_SAE_SUPPORT`.
Wi-Fi Enhanced Open™
--------------------
Introduction
++++++++++++
Enhanced open is used for providing security and privacy to users connecting to open (public) wireless networks, particularly in scenarios where user authentication is not desired or distribution of credentials impractical. Each user is provided with unique individual encryption keys that protect data exchange between a user device and the Wi-Fi network. Protected Management Frames further protects management traffic between the access point and user device. Enhanced Open is based on Opportunistic Wireless Encryption (OWE) standard. OWE Transition Mode enables a seamless transition from Open unencrypted WLANs to OWE WLANs without adversely impacting the end user experience.
**{IDF_TARGET_NAME} supports WiFi Enhanced Open™ only in station mode.**
Setting up OWE with {IDF_TARGET_NAME}
++++++++++++++++++++++++++++++++++++++
A config option :ref:`CONFIG_ESP_WIFI_ENABLE_WPA3_OWE_STA` and configuration parameter :cpp:type:`owe_enabled` in :cpp:type:`wifi_sta_config_t` is provided to enable OWE support for station. To use OWE transition mode, along with the config provided above, `authmode` from :cpp:type:`wifi_scan_threshold_t` should be set to `WIFI_AUTH_OPEN`.

View File

@ -1654,7 +1654,6 @@ Wi-Fi Vendor IE Configuration
By default, all Wi-Fi management frames are processed by the Wi-Fi driver, and the application can ignore them. However, some applications may have to handle the beacon, probe request, probe response, and other management frames. For example, if you insert some vendor-specific IE into the management frames, it is only the management frames which contain this vendor-specific IE that will be processed. In {IDF_TARGET_NAME}, :cpp:func:`esp_wifi_set_vendor_ie()` and :cpp:func:`esp_wifi_set_vendor_ie_cb()` are responsible for this kind of tasks. By default, all Wi-Fi management frames are processed by the Wi-Fi driver, and the application can ignore them. However, some applications may have to handle the beacon, probe request, probe response, and other management frames. For example, if you insert some vendor-specific IE into the management frames, it is only the management frames which contain this vendor-specific IE that will be processed. In {IDF_TARGET_NAME}, :cpp:func:`esp_wifi_set_vendor_ie()` and :cpp:func:`esp_wifi_set_vendor_ie_cb()` are responsible for this kind of tasks.
Wi-Fi Easy Connect™ (DPP) Wi-Fi Easy Connect™ (DPP)
-------------------------- --------------------------
@ -1708,6 +1707,15 @@ Current implementation of 802.11k includes support for beacon measurement report
Refer ESP-IDF example :idf_file:`examples/wifi/roaming/README.md` to set up and use these APIs. Example code only demonstrates how these APIs can be used, and the application should define its own algorithm and cases as required. Refer ESP-IDF example :idf_file:`examples/wifi/roaming/README.md` to set up and use these APIs. Example code only demonstrates how these APIs can be used, and the application should define its own algorithm and cases as required.
Fast BSS Transition
---------------------------
Fast BSS transition (802.11R FT), is a standard to permit continuous connectivity aboard wireless devices in motion, with fast and secure client transitions from one Basic Service Set (abbreviated BSS, and also known as a base station or more colloquially, an access point) to another performed in a nearly seamless manner **avoiding 802.1i 4 way handshake** . 802.11R specifies transitions between access points by redefining the security key negotiation protocol, allowing both the negotiation and requests for wireless resources to occur in parallel. The key derived from the server to be cached in the wireless network, so that a reasonable number of future connections can be based on the cached key, avoiding the 802.1X process
{IDF_TARGET_NAME} station supports FT for WPA2-PSK networks. Do note that {IDF_TARGET_NAME} station only support FT over the air protocol only.
A config option :ref:`CONFIG_ESP_WIFI_11R_SUPPORT` and configuration parameter :cpp:type:`ft_enabled` in :cpp:type:`wifi_sta_config_t` is provided to enable 802.11R support for station. Refer ESP-IDF example :idf_file:`examples/wifi/roaming/README.md` for further details.
.. only:: SOC_WIFI_FTM_SUPPORT .. only:: SOC_WIFI_FTM_SUPPORT
Wi-Fi Location Wi-Fi Location
@ -2111,7 +2119,7 @@ Theoretically, if the side-effects the API imposes on the Wi-Fi driver or other
The recommendations above are only for avoiding side-effects and can be ignored when there are good reasons. The recommendations above are only for avoiding side-effects and can be ignored when there are good reasons.
* - Have Wi-Fi connection * - Have Wi-Fi connection
- When the Wi-Fi connection is already set up, and the sequence is controlled by the application, the latter may impact the sequence control of the Wi-Fi connection as a whole. So, the ``en_sys_seq`` need to be true, otherwise ``ESP_ERR_WIFI_ARG`` is returned. - When the Wi-Fi connection is already set up, and the sequence is controlled by the application, the latter may impact the sequence control of the Wi-Fi connection as a whole. So, the ``en_sys_seq`` need to be true, otherwise ``ESP_ERR_INVALID_ARG`` is returned.
The MAC-address recommendations in the “No Wi-Fi connection” scenario also apply to this scenario. The MAC-address recommendations in the “No Wi-Fi connection” scenario also apply to this scenario.
@ -2123,7 +2131,7 @@ Theoretically, if the side-effects the API imposes on the Wi-Fi driver or other
- If the packet is sent from station to AP or from AP to station, the Power Management, More Data, and Re-Transmission bits should be 0. Otherwise, the packet will be discarded by Wi-Fi driver. - If the packet is sent from station to AP or from AP to station, the Power Management, More Data, and Re-Transmission bits should be 0. Otherwise, the packet will be discarded by Wi-Fi driver.
``ESP_ERR_WIFI_ARG`` is returned if any check fails. ``ESP_ERR_INVALID_ARG`` is returned if any check fails.
Wi-Fi Sniffer Mode Wi-Fi Sniffer Mode

View File

@ -1,2 +1,262 @@
.. include:: ../../../en/api-guides/performance/speed.rst 速度优化
=========
:link_to_translation:`en:[English]`
{IDF_TARGET_CONTROLLER_CORE_CONFIG:default="CONFIG_BT_CTRL_PINNED_TO_CORE", esp32="CONFIG_BTDM_CTRL_PINNED_TO_CORE_CHOICE", esp32s3="CONFIG_BT_CTRL_PINNED_TO_CORE_CHOICE"}
{IDF_TARGET_RF_TYPE:default="Wi-Fi/蓝牙", esp32s2="Wi-Fi", esp32c6="Wi-Fi/蓝牙/802.15.4", esp32h2="蓝牙/802.15.4"}
概述
-----------
提高代码执行速度是提升软件性能的关键要素,该优化也可能带来其他积极影响,比如降低总体功耗。然而,提高代码执行速度可能会牺牲其他性能,如 :doc:`size`
决定优化目标
-----------------------------
如果应用程序固件中的某个函数仅每周在后台执行一次,其执行时间是 10 ms 还是 100 ms 对整体性能的影响或可忽略不计。但如果某个函数以 10 Hz 的频率持续执行,其执行时间是 10 ms 还是 100 ms 就会对系统性能产生显著影响。
大多数应用程序固件中,只有一小部分函数需要优化性能,例如频繁执行的函数,或者必须满足应用程序对延迟或吞吐量的要求的函数。应针对这些特定函数优化其执行速度。
测量性能
---------------------
想要提升某方面性能,首先要对其进行测量。
基本性能测量方法
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
可以直接测量与外部交互的性能,例如,测量一般网络性能可以参考 :example:`wifi/iperf`:example:`ethernet/iperf` ,或者使用示波器或逻辑分析仪来测量与设备外设的交互时间。
此外,另一种测量性能的方法是在代码中添加计时测量:
.. code-block:: c
#include "esp_timer.h"
void measure_important_function(void) {
const unsigned MEASUREMENTS = 5000;
uint64_t start = esp_timer_get_time();
for (int retries = 0; retries < MEASUREMENTS; retries++) {
important_function(); // 需要测量的代码
}
uint64_t end = esp_timer_get_time();
printf("%u iterations took %llu milliseconds (%llu microseconds per invocation)\n",
MEASUREMENTS, (end - start)/1000, (end - start)/MEASUREMENTS);
}
通过多次执行目标代码可以降低其他因素的影响,例如实时操作系统 (RTOS) 的上下文切换、测量的开销等。
- 使用 :cpp:func:`esp_timer_get_time` 可以生成微秒级精度的“墙钟”时间戳,但每次调用计时函数都会产生适量开销。
- 也可以使用标准 Unix 函数 ``gettimeofday()````utime()`` 来进行计时测量,尽管其开销略高一些。
- 此外,代码中包含 ``hal/cpu_hal.h`` 头文件,并调用 HAL 函数 ``cpu_hal_get_cycle_count()`` 可以返回已执行的 CPU 循环数。该函数开销较低,适用于高精度测量执行时间极短的代码。
.. only:: not CONFIG_FREERTOS_UNICORE
CPU 周期是各核心独立计数的,因此本方法仅适用于测量中断处理程序或固定在单个核心上的任务。
- 在执行“微基准测试”时(即仅对运行时间不到 1-2 ms 的小代码段进行基准测试),二进制文件会影响 flash 缓存的性能,进而可能会导致计时测量出现较大差异。这是因为二进制布局可能会导致在特定的执行顺序中产生不同模式的缓存缺失。执行较大测试代码通常可以抵消这种影响。在基准测试时多次执行一个小函数可以减少 flash 缓存缺失的影响。另外,将该代码移到 IRAM 中(参见 :ref:`speed-targeted-optimizations` )也可以解决这个问题。
外部跟踪
^^^^^^^^^^^^^^^^^^^^
:doc:`/api-guides/app_trace` 可以在几乎不影响代码执行的情况下测量其执行速度。
任务
^^^^^^^
如果启用了选项 :ref:`CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS` ,则可以使用 FreeRTOS API :cpp:func:`vTaskGetRunTimeStats` 来获取各个 FreeRTOS 任务运行时占用处理器的时间。
:ref:`SEGGER SystemView <app_trace-system-behaviour-analysis-with-segger-systemview>` 是一款出色的工具,可将任务执行情况可视化,也可用于排查系统整体的性能问题或改进方向。
提高整体速度
-----------------------------
以下优化措施将提高几乎所有代码的执行效果,包括启动时间、吞吐量、延迟等:
.. list::
:esp32: - 设置 :ref:`CONFIG_ESPTOOLPY_FLASHFREQ` 为 80 MHz。该值为默认值 40 MHz 的两倍,这意味着从 flash 加载或执行代码的速度也将翻倍。在更改此设置之前,应事先确认连接 {IDF_TARGET_NAME} 和 flash 的板或模块在温度限制范围内支持 80 MHz 的操作。相关信息参见硬件数据手册。
- 设置 :ref:`CONFIG_ESPTOOLPY_FLASHMODE` 为 QIO 或 QOUT 模式(四线 I/O 模式)。相较于默认的 DIO 模式,在这两种模式下,从 flash 加载或执行代码的速度几乎翻倍。如果两种模式都支持QIO 会稍微快于 QOUT。请注意flash 芯片以及 {IDF_TARGET_NAME} 与 flash 芯片之间的电气连接都必须支持四线 I/O 模式,否则 SoC 将无法正常工作。
- 设置 :ref:`CONFIG_COMPILER_OPTIMIZATION```Optimize for performance (-O2)`` 。相较于默认设置,这可能会略微增加二进制文件大小,但几乎必然会提高某些代码的性能。请注意,如果代码包含 C 或 C++ 的未定义行为,提高编译器优化级别可能会暴露出原本未发现的错误。
:esp32: - 如果应用程序是基于 ESP32 rev. 3 (ECO3) 的项目并且使用 PSRAM设置 :ref:`CONFIG_ESP32_REV_MIN` 为 ``3`` 将禁用 PSRAM 的错误修复工作,可以减小代码大小并提高整体性能。
:SOC_CPU_HAS_FPU: - 避免使用浮点运算 ``float``。尽管 {IDF_TARGET_NAME} 具备单精度浮点运算器,但是浮点运算总是慢于整数运算。因此可以考虑使用不同的整数表示方法进行运算,如定点表示法,或者将部分计算用整数运算后再切换为浮点运算。
:not SOC_CPU_HAS_FPU: - 避免使用浮点运算 ``float``。{IDF_TARGET_NAME} 通过软件模拟进行浮点运算,因此速度非常慢。可以考虑使用不同的整数表示方法进行运算,如定点表示法,或者将部分计算用整数运算后再切换为浮点运算。
- 避免使用双精度浮点运算 ``double``。{IDF_TARGET_NAME} 通过软件模拟进行双精度浮点运算,因此速度非常慢。可以考虑使用基于整数的表示方法或单精度浮点数。
减少日志开销
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
尽管标准输出会先存储在缓冲区中,但缓冲区缺少可用空间时,应用程序将数据输出到日志的速度可能会受限。这点在程序启动并输出大量日志时尤为明显,但也可能随时发生。为解决这一问题,可以采取以下几种方法:
.. list::
- 通过调低应用日志默认等级 :ref:`CONFIG_LOG_DEFAULT_LEVEL` (引导加载程序日志等级的相应配置为 :ref:`CONFIG_BOOTLOADER_LOG_LEVEL`)来减少日志输出量。这样做不仅可以减小二进制文件大小,还可以节省一些 CPU 用于格式化字符串的时间。
:not SOC_USB_OTG_SUPPORTED: - 增加 :ref:`CONFIG_ESP_CONSOLE_UART_BAUDRATE` ,可以提高日志输出速度。
:SOC_USB_OTG_SUPPORTED: - 增加 :ref:`CONFIG_ESP_CONSOLE_UART_BAUDRATE` ,可以提高日志输出速度。如果使用内置 USB-CDC 作为串口控制台,那么串口传输速率不会受配置的波特率影响。
不建议的选项
^^^^^^^^^^^^^^^^^^
以下选项也可以提高执行速度,但不建议使用,因为它们会降低固件应用程序的可调试性,并可能导致出现更严重的 bug。
.. list::
- 禁用 :ref:`CONFIG_COMPILER_OPTIMIZATION_ASSERTION_LEVEL` 。这也会略微减小固件二进制文件大小。然而,它可能导致出现更严重的 bug甚至出现安全性 bug。如果为了优化特定函数而必须禁用该选项可以考虑在该源文件的顶部单独添加 ``#define NDEBUG``
.. _speed-targeted-optimizations:
针对性优化
---------------------------
以下更改将提高固件应用程序特定部分的速度:
.. list::
- 将频繁执行的代码移至 IRAM。应用程序中的所有代码都默认从 flash 中执行。这意味着缓存缺失时CPU 需要等待从 flash 加载后续指令。如果将函数复制到 IRAM 中,则仅需要在启动时加载一次,然后始终以全速执行。
IRAM 资源有限,使用更多的 IRAM 可能会减少可用的 DRAM。因此将代码移动到 IRAM 需要有所取舍。更多信息参见 :ref:`iram`
- 针对不需要放置在 IRAM 中的单个源文件,可以重新启用跳转表优化。这将提高大型 ``switch cases`` 代码中的热路径性能。关于如何在编译单个源文件时添加 -fjump-tables -ftree-switch-conversion 选项,参见 :ref:`component_build_control`
减少启动时间
----------------------------
除了上述提高整体性能的方法外,还可以微调以下选项来专门减少启动时间:
.. list::
- 最小化 :ref:`CONFIG_LOG_DEFAULT_LEVEL`:ref:`CONFIG_BOOTLOADER_LOG_LEVEL` 可以大幅减少启动时间。如要在应用程序启动后获取更多日志,可以设置 :ref:`CONFIG_LOG_MAXIMUM_LEVEL`,然后调用 :cpp:func:`esp_log_level_set` 来恢复更高级别的日志输出。示例 :example:`system/startup_time` 的主函数展示了如何实现这一点。
:SOC_RTC_FAST_MEM_SUPPORTED: - 如果使用 Deep-sleep 模式,启用 :ref:`CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP` 可以加快从睡眠中唤醒的速度。请注意,启用该选项后在唤醒时将不会执行安全启动验证,需要考量安全风险。
- 设置 :ref:`CONFIG_BOOTLOADER_SKIP_VALIDATE_ON_POWER_ON` 可以在每次上电复位启动时跳过二进制文件验证,节省的时间取决于二进制文件大小和 flash 设置。请注意,如果 flash 意外损坏,此设置将有一定风险。更多关于使用该选项的解释和建议,参见 :ref:`项目配置 <CONFIG_BOOTLOADER_SKIP_VALIDATE_ON_POWER_ON>`
- 禁用 RTC 慢速时钟校准可以节省一小部分启动时间。设置 :ref:`CONFIG_RTC_CLK_CAL_CYCLES` 为 0 可以实现该操作。设置后,以 RTC 慢速时钟为时钟源的固件部分精确度将降低。
示例项目 :example:`system/startup_time` 预配了优化启动时间的设置,文件 :example_file:`system/startup_time/sdkconfig.defaults` 包含了所有相关设置。可以将这些设置追加到项目中 ``sdkconfig`` 文件的末尾并合并,但请事先阅读每个设置的相关说明。
任务优先级
--------------------
ESP-IDF FreeRTOS 是实时操作系统,因此需确保高吞吐量或低延迟的任务获得更高优先级,以便立即运行。调用 :cpp:func:`xTaskCreate`:cpp:func:`xTaskCreatePinnedToCore` 会设定优先级,并且可以在运行时调用 :cpp:func:`vTaskPrioritySet` 进行更改。
此外,还需确保任务适时释放 CPU通过调用 :cpp:func:`vTaskDelay```sleep()`` ,或在信号量、队列、任务通知等方面进行阻塞),以避免低优先级任务饥饿并造成系统性问题。 :ref:`task-watchdog-timer` 提供任务饥饿自动检测机制,但请注意,正确的固件操作有时需要长时间运算,因此任务看门狗定时器超时并不总意味着存在问题。在这些情况下,可能需要微调超时时限,甚至禁用任务看门狗定时器。
.. _built-in-task-priorities:
内置任务优先级
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ESP-IDF 启动的系统任务预设了固定优先级。启动时,一些任务会自动启动,而另一些仅在应用程序固件初始化特定功能时启动。为优化性能,请合理设置应用程序任务优先级,以确保它们不会被系统任务阻塞,同时需确保系统任务不会饥饿进而影响其他系统功能。
为此,可能需要分解特定任务。例如,可以在高优先级任务或中断处理程序中执行实时操作,并在较低优先级任务中处理非实时操作。
头文件 :idf_file:`components/esp_system/include/esp_task.h` 包含了用于设置 ESP-IDF 内置任务系统优先级的宏定义。更多系统任务详情,参见 :ref:`freertos_system_tasks`
常见优先级包括:
.. Note: 以下两个列表应保持一致,但第二个列表还展示了 CPU 亲和性。
.. only:: CONFIG_FREERTOS_UNICORE
.. list::
- :ref:`app-main-task` 中执行 app_main 函数的主任务优先级最低 (1)。
- 系统任务 :doc:`/api-reference/system/esp_timer` 用于管理定时器事件并执行回调函数,优先级较高 (22, ``ESP_TASK_TIMER_PRIO``)。
- FreeRTOS 初始化调度器时会创建定时器任务,用于处理 FreeRTOS 定时器的回调函数优先级最低1, :ref:`可配置 <CONFIG_FREERTOS_TIMER_TASK_PRIORITY>` )。
- 系统任务 :doc:`/api-reference/system/esp_event` 用于管理默认的系统事件循环并执行回调函数,优先级较高 (20, ``ESP_TASK_EVENT_PRIO``)。仅在应用程序调用 :cpp:func:`esp_event_loop_create_default` 时使用此配置。可以调用 :cpp:func:`esp_event_loop_create` 添加自定义任务配置。
- :doc:`/api-guides/lwip` TCP/IP 任务优先级较高 (18)。
:SOC_WIFI_SUPPORTED: - :doc:`/api-guides/wifi` 任务优先级较高 (23).
:SOC_WIFI_SUPPORTED: - 使用 Wi-Fi Protected Setup (WPS)、WPA2 EAP-TLS、Device Provisioning Protocol (DPP) 或 BSS Transition Management (BTM) 等功能时Wi-Fi wpa_supplicant 组件可能会创建优先级较低的专用任务 (2)。
:SOC_BT_SUPPORTED: - :doc:`/api-reference/bluetooth/controller_vhci` 任务优先级较高 (23, ``ESP_TASK_BT_CONTROLLER_PRIO``)。蓝牙控制器需要以低延迟响应请求,因此其任务应始终为系统最高优先级的任务之一。
:SOC_BT_SUPPORTED: - :doc:`/api-reference/bluetooth/nimble/index` 任务优先级较高 (21).
- 以太网驱动程序会创建一个 MAC 任务,用于接收以太网帧。如果使用默认配置 ``ETH_MAC_DEFAULT_CONFIG`` ,则该任务为中高优先级 (15)。可以在以太网 MAC 初始化时输入自定义 :cpp:class:`eth_mac_config_t` 结构体来更改此设置。
- 如果使用 :doc:`/api-reference/protocols/mqtt` 组件,它会创建优先级默认为 5 的任务( :ref:`可配置 <CONFIG_MQTT_TASK_PRIORITY>` ),可通过 :ref:`CONFIG_MQTT_USE_CUSTOM_CONFIG` 调整,也可以在运行时通过 :cpp:class:`esp_mqtt_client_config_t` 结构体中的 ``task_prio`` 字段调整。
- 关于 ``mDNS`` 服务的任务优先级,参见 `性能优化 <https://docs.espressif.com/projects/esp-protocols/mdns/docs/latest/en/index.html#performance-optimization>`__
.. only :: not CONFIG_FREERTOS_UNICORE
.. list::
- :ref:`app-main-task` 中执行 app_main 函数的主任务优先级最低 (1) 且默认固定在核心 0 上执行( :ref:`可配置 <CONFIG_ESP_MAIN_TASK_AFFINITY>` )。
- 系统任务 :doc:`/api-reference/system/esp_timer` 用于管理定时器事件并执行回调函数,优先级较高 (22, ``ESP_TASK_TIMER_PRIO``) 且固定在核心 0 上执行。
- FreeRTOS 初始化调度器时会创建定时器任务,用于处理 FreeRTOS 定时器的回调函数优先级最低1 :ref:`可配置 <CONFIG_FREERTOS_TIMER_TASK_PRIORITY>` )且固定在核心 0 上执行。
- 系统任务 :doc:`/api-reference/system/esp_event` 用于管理默认的系统事件循环并执行回调函数,优先级较高 (20, ``ESP_TASK_EVENT_PRIO``) 且固定在核心 0 上执行。此配置仅在应用程序调用 :cpp:func:`esp_event_loop_create_default` 时使用。可以调用 :cpp:func:`esp_event_loop_create` 添加自定义任务配置。
- :doc:`/api-guides/lwip` TCP/IP 任务优先级较高 (18) 且并未固定在特定核心上执行( :ref:`可配置 <CONFIG_LWIP_TCPIP_TASK_AFFINITY>` )。
:SOC_WIFI_SUPPORTED: - :doc:`/api-guides/wifi` 任务优先级较高 (23) 且默认固定在核心 0 上执行( :ref:`可配置 <CONFIG_ESP_WIFI_TASK_CORE_ID>` )。
:SOC_WIFI_SUPPORTED: - 使用 Wi-Fi Protected Setup (WPS)、WPA2 EAP-TLS、Device Provisioning Protocol (DPP) 或 BSS Transition Management (BTM) 等功能时Wi-Fi wpa_supplicant 组件可能会创建优先级较低的专用任务 (2),这些任务并未固定在特定核心上执行。
:SOC_BT_SUPPORTED: - :doc:`/api-reference/bluetooth/controller_vhci` 任务优先级较高 (23, ``ESP_TASK_BT_CONTROLLER_PRIO``) 且默认固定在核心 0 上执行( :ref:`可配置 <{IDF_TARGET_CONTROLLER_CORE_CONFIG}>` )。蓝牙控制器需要以低延迟响应请求,因此其任务应始终为最高优先级的任务之一并分配给单个 CPU 执行。
:SOC_BT_SUPPORTED: - :doc:`/api-reference/bluetooth/nimble/index` 任务优先级较高 (21) 且默认固定在核心 0 上执行( :ref:`可配置 <CONFIG_BT_NIMBLE_PINNED_TO_CORE_CHOICE>` .
:esp32: - 使用 :doc:`/api-reference/bluetooth/index` 时会创建多个任务:
- 堆栈事件回调任务 ("BTC") 优先级较高 (19)。
- 堆栈 BTU 层任务优先级较高 (20)。
- Host HCI 主任务优先级较高 (22)。
所有 Bluedroid 任务默认固定在同一个核心上执行,即核心 0 :ref:`可配置 <CONFIG_BT_BLUEDROID_PINNED_TO_CORE_CHOICE>` )。
- 以太网驱动程序会创建一个 MAC 任务,用于接收以太网帧。如果使用默认配置 ``ETH_MAC_DEFAULT_CONFIG`` ,则该任务为中高优先级 (15) 且并未固定在特定核心上执行。可以在以太网 MAC 初始化时输入自定义 :cpp:class:`eth_mac_config_t` 结构体来更改此设置。
- 如果使用 :doc:`/api-reference/protocols/mqtt` 组件,它会创建优先级默认为 5 的任务( :ref:`可配置 <CONFIG_MQTT_TASK_PRIORITY>` ,也可通过 :ref:`CONFIG_MQTT_USE_CUSTOM_CONFIG` 调整)。该任务未固定在特定核心上执行( :ref:`可配置 <CONFIG_MQTT_TASK_CORE_SELECTION_ENABLED>` )。
- 关于 ``mDNS`` 服务的任务优先级,参见 `性能优化 <https://espressif.github.io/esp-protocols/mdns/en/index.html#performance-optimization>`__
设定应用程序任务优先级
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. only:: CONFIG_FREERTOS_UNICORE
由于 {IDF_TARGET_RF_TYPE} 操作饥饿可能导致系统不稳定,通常不建议让特定任务的优先级高于 {IDF_TARGET_RF_TYPE} 操作的内置优先级。对于非常短且无需网络的实时操作,可以使用中断服务程序或极受限的任务(仅运行极短时间)并设置为最高优先级 (24)。将特定任务优先级设为 19 不会妨碍较低层级的 {IDF_TARGET_RF_TYPE} 功能无延迟运行,但仍然会抢占 lwIP TCP/IP 堆栈以及其他非实时内部功能这对于不执行网络操作的实时任务而言是最佳选项。lwIP TCP/IP 任务优先级 (18) 应高于所有执行 TCP/IP 网络操作的任务,以保证任务正常执行。
.. only:: not CONFIG_FREERTOS_UNICORE
默认配置下,除了个别例外,尤其是 lwIP TCP/IP 任务,大多数内置任务都固定在核心 0 上执行。因此,应用程序可以方便地将高优先级任务放置在核心 1 上执行。优先级大于等于 19 的应用程序任务在核心 1 上运行时可以确保不会被任何内置任务抢占。为了进一步隔离各个 CPU 上运行的任务,配置 :ref:`lwIP 任务 <CONFIG_LWIP_TCPIP_TASK_AFFINITY>` ,可以使 lwIP 任务仅在核心 0 上运行,而非上述任一核心,这可能会根据其他任务的运行情况减少总 TCP/IP 吞吐量。
由于 {IDF_TARGET_RF_TYPE} 操作饥饿可能导致系统不稳定,通常不建议让核心 0 上特定任务的优先级高于 {IDF_TARGET_RF_TYPE} 操作的内置优先级。将特定任务优先级设置为 19 并在核心 0 上运行,不会妨碍较低层级的 {IDF_TARGET_RF_TYPE} 功能无延迟运行,但仍然会抢占 lwIP TCP/IP 堆栈以及其他非实时内部功能该选项适用于不执行网络操作的实时任务。lwIP TCP/IP 任务优先级 (18) 应高于所有执行 TCP/IP 网络操作的任务,以保证任务正常执行。
.. note::
如果要让特定任务始终先于 ESP-IDF 内置任务运行,并不需要将其固定在核心 1 上。将该任务优先级设置为小于等于 17则无需与核心绑定那么核心 0 上没有执行较高优先级的内置任务时,该任务也可以选择在核心 0 上执行。使用未固定的任务可以提高整体 CPU 利用率,但这会增加任务调度的复杂性。
.. note::
对内置 SPI flash 芯片进行写入操作时,任务会完全暂停执行。只有 :ref:`iram-safe-interrupt-handlers` 会继续执行。
提高中断性能
-------------------------------------
ESP-IDF 支持动态 :doc:`/api-reference/system/intr_alloc` 和中断抢占。系统中每个中断都有相应优先级,较高优先级的中断将优先执行。
只要其他任务不在临界区内,中断处理程序将优先于所有其他任务执行。因此,尽量减少中断处理程序的执行时间十分重要。
要以最佳性能执行特定中断处理程序,可以考虑:
.. list::
- 调用 :cpp:func:`esp_intr_alloc` 时使用 ``ESP_INTR_FLAG_LEVEL2````ESP_INTR_FLAG_LEVEL3`` 等标志,可以为更重要的中断设定更高优先级。
:not CONFIG_FREERTOS_UNICORE: - 将中断分配到不运行内置 {IDF_TARGET_RF_TYPE} 任务的 CPU 上执行,即默认情况下,将中断分配到核心 1 上执行,参见 :ref:`built-in-task-priorities` 。调用 :cpp:func:`esp_intr_alloc` 函数即可将中断分配到函数所在 CPU。
- 如果确定整个中断处理程序可以在 IRAM 中运行(参见 :ref:`iram-safe-interrupt-handlers` ),那么在调用 :cpp:func:`esp_intr_alloc` 分配中断时,请设置 ``ESP_INTR_FLAG_IRAM`` 标志,这样可以防止在应用程序固件写入内置 SPI flash 时临时禁用中断。
- 即使是非 IRAM 安全的中断处理程序,如果需要频繁执行,可以考虑将处理程序的函数移到 IRAM 中,从而尽可能规避执行中断代码时发生 flash 缓存缺失的可能性(参见 :ref:`speed-targeted-optimizations` )。如果可以确保只有部分处理程序位于 IRAM 中,则无需添加 ``ESP_INTR_FLAG_IRAM`` 标志将程序标记为 IRAM 安全。
提高网络速度
-----------------------------
.. list::
:SOC_WIFI_SUPPORTED: * 关于提高 Wi-Fi 网速,参见 :ref:`How-to-improve-Wi-Fi-performance` 和 :ref:`wifi-buffer-usage` 。
* 关于提高 lwIP TCP/IPWi-Fi 和以太网)网速,参见 :ref:`lwip-performance`
:SOC_WIFI_SUPPORTED: * 示例 :example:`wifi/iperf` 包含了一种针对 Wi-Fi TCP/IP 吞吐量进行了大量优化的配置。将文件 :example_file:`wifi/iperf/sdkconfig.defaults` 、 :example_file:`wifi/iperf/sdkconfig.defaults.{IDF_TARGET_PATH_NAME}` 和 :example_file:`wifi/iperf/sdkconfig.ci.99` 的内容追加到项目的 ``sdkconfig`` 文件中,即可添加所有相关选项。请注意,部分选项可能会导致可调试性降低、固件大小增加、内存使用增加或其他功能的性能降低等影响。为了获得最佳结果,请阅读上述链接文档,并据此确定哪些选项最适合当前应用程序。
提高 I/O 性能
----------------------------------
使用标准 C 库函数,如 ``fread````fwrite``相较于使用平台特定的不带缓冲系统调用I/O 性能可能更慢,如 ``read````write`` 。标准 C 库函数是为可移植性而设计的,它们会在执行时会引入一定开销和缓冲延迟,因此并不适用需要较高执行速度的场景。
:doc:`/api-reference/storage/fatfs` 具体信息和提示如下:
.. list::
- 读取/写入请求的最大大小等于 FatFS 簇大小(分配单元大小)。
- 使用 ``read````write`` 而非 ``fread````fwrite`` 可以提高性能。
- 要提高诸如 ``fread````fgets`` 等缓冲读取函数的执行速度可以增加文件缓冲区的大小Newlib 的默认值为 128 字节),例如 4096、8192 或 16384 字节。为此,可以在特定文件的指针上使用 ``setvbuf`` 函数进行局部更改,或者修改 :ref:`CONFIG_FATFS_VFS_FSTAT_BLKSIZE` 实现全局应用。
.. note::
增加缓冲区的大小会增加堆内存的使用量。

View File

@ -2068,7 +2068,7 @@ Wi-Fi 80211 数据包发送
上述建议仅供避免副作用,在有充分理由的情况下可以忽略。 上述建议仅供避免副作用,在有充分理由的情况下可以忽略。
* - 有 Wi-Fi 连接 * - 有 Wi-Fi 连接
- 当 Wi-Fi 已连接,且序列由应用程序控制,应用程序可能会影响整个 Wi-Fi 连接的序列控制。 因此en_sys_seq 要为 true否则将返回 ``ESP_ERR_WIFI_ARG`` - 当 Wi-Fi 已连接,且序列由应用程序控制,应用程序可能会影响整个 Wi-Fi 连接的序列控制。 因此en_sys_seq 要为 true否则将返回 ``ESP_ERR_INVALID_ARG``
“无 Wi-Fi 连接”情况下的 MAC 地址建议也适用于此情况。 “无 Wi-Fi 连接”情况下的 MAC 地址建议也适用于此情况。
@ -2080,7 +2080,7 @@ Wi-Fi 80211 数据包发送
- 如果数据包是从 station 发送到 AP或从 AP 到 stationPower Management、More Data 和 Re-Transmission 位应该为 0否则Wi-Fi 驱动程序不接受该数据包。 - 如果数据包是从 station 发送到 AP或从 AP 到 stationPower Management、More Data 和 Re-Transmission 位应该为 0否则Wi-Fi 驱动程序不接受该数据包。
如果任何检查失败,将返回 ``ESP_ERR_WIFI_ARG`` 如果任何检查失败,将返回 ``ESP_ERR_INVALID_ARG``
Wi-Fi Sniffer 模式 Wi-Fi Sniffer 模式

View File

@ -14,5 +14,18 @@ menu "Iperf Configuration"
The value is used for iperf socket TCP tx timeout, iperf will be aborted The value is used for iperf socket TCP tx timeout, iperf will be aborted
and socket will be closed and shutdown. and socket will be closed and shutdown.
config IPERF_TRAFFIC_TASK_PRIORITY
int "iperf traffic task priority"
default 4
range 1 24
help
The value is used for iperf traffic task priority.
config IPERF_REPORT_TASK_PRIORITY
int "iperf result report task priority"
default 6
range 1 24
help
The value is used for iperf result report task priority.
endmenu endmenu

View File

@ -36,10 +36,10 @@ extern "C" {
#define IPERF_DEFAULT_NO_BW_LIMIT -1 #define IPERF_DEFAULT_NO_BW_LIMIT -1
#define IPERF_TRAFFIC_TASK_NAME "iperf_traffic" #define IPERF_TRAFFIC_TASK_NAME "iperf_traffic"
#define IPERF_TRAFFIC_TASK_PRIORITY 4 #define IPERF_TRAFFIC_TASK_PRIORITY CONFIG_IPERF_TRAFFIC_TASK_PRIORITY
#define IPERF_TRAFFIC_TASK_STACK 4096 #define IPERF_TRAFFIC_TASK_STACK 4096
#define IPERF_REPORT_TASK_NAME "iperf_report" #define IPERF_REPORT_TASK_NAME "iperf_report"
#define IPERF_REPORT_TASK_PRIORITY 6 #define IPERF_REPORT_TASK_PRIORITY CONFIG_IPERF_REPORT_TASK_PRIORITY
#define IPERF_REPORT_TASK_STACK 4096 #define IPERF_REPORT_TASK_STACK 4096
#define IPERF_UDP_TX_LEN (1470) #define IPERF_UDP_TX_LEN (1470)

View File

@ -118,7 +118,7 @@ static esp_err_t iperf_start_report(void)
return ESP_OK; return ESP_OK;
} }
static void socket_recv(int recv_socket, struct sockaddr_storage listen_addr, uint8_t type) static void IRAM_ATTR socket_recv(int recv_socket, struct sockaddr_storage listen_addr, uint8_t type)
{ {
bool iperf_recv_start = true; bool iperf_recv_start = true;
uint8_t *buffer; uint8_t *buffer;
@ -149,7 +149,7 @@ static void socket_recv(int recv_socket, struct sockaddr_storage listen_addr, ui
} }
} }
static void socket_send(int send_socket, struct sockaddr_storage dest_addr, uint8_t type, int bw_lim) static void IRAM_ATTR socket_send(int send_socket, struct sockaddr_storage dest_addr, uint8_t type, int bw_lim)
{ {
uint8_t *buffer; uint8_t *buffer;
int32_t *pkt_id_p; int32_t *pkt_id_p;
@ -222,7 +222,7 @@ static void socket_send(int send_socket, struct sockaddr_storage dest_addr, uint
} }
} }
static esp_err_t IRAM_ATTR iperf_run_tcp_server(void) static esp_err_t iperf_run_tcp_server(void)
{ {
int listen_socket = -1; int listen_socket = -1;
int client_socket = -1; int client_socket = -1;
@ -389,7 +389,7 @@ exit:
return ret; return ret;
} }
static esp_err_t IRAM_ATTR iperf_run_udp_server(void) static esp_err_t iperf_run_udp_server(void)
{ {
int listen_socket = -1; int listen_socket = -1;
int opt = 1; int opt = 1;

View File

@ -243,6 +243,7 @@ static int wifi_cmd_sta(int argc, char **argv)
} }
ESP_LOGI(TAG, "sta connecting to '%s'", sta_args.ssid->sval[0]); ESP_LOGI(TAG, "sta connecting to '%s'", sta_args.ssid->sval[0]);
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE));
wifi_cmd_sta_join(sta_args.ssid->sval[0], sta_args.password->sval[0], false); wifi_cmd_sta_join(sta_args.ssid->sval[0], sta_args.password->sval[0], false);
return 0; return 0;
} }
@ -276,6 +277,7 @@ static int wifi_cmd_sta_mcs89(int argc, char **argv)
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_set_protocol(0, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_11AX)); ESP_ERROR_CHECK(esp_wifi_set_protocol(0, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_11AX));
ESP_ERROR_CHECK(esp_wifi_set_bandwidth(0, WIFI_BW_HT20)); ESP_ERROR_CHECK(esp_wifi_set_bandwidth(0, WIFI_BW_HT20));
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE));
ESP_LOGI(TAG, "sta connecting to '%s'", sta_args.ssid->sval[0]); ESP_LOGI(TAG, "sta connecting to '%s'", sta_args.ssid->sval[0]);
wifi_cmd_sta_join(sta_args.ssid->sval[0], sta_args.password->sval[0], true); wifi_cmd_sta_join(sta_args.ssid->sval[0], sta_args.password->sval[0], true);

View File

@ -8,3 +8,10 @@ CONFIG_ESP_TASK_WDT_EN=n
CONFIG_LWIP_ETHARP_TRUST_IP_MAC=n CONFIG_LWIP_ETHARP_TRUST_IP_MAC=n
CONFIG_LWIP_IRAM_OPTIMIZATION=y CONFIG_LWIP_IRAM_OPTIMIZATION=y
CONFIG_LWIP_TCPIP_TASK_PRIO=23
CONFIG_IPERF_TRAFFIC_TASK_PRIORITY=23
CONFIG_IPERF_REPORT_TASK_PRIORITY=24
CONFIG_LWIP_TCPIP_CORE_LOCKING=y
CONFIG_LWIP_TCPIP_CORE_LOCKING_INPUT=y
CONFIG_COMPILER_OPTIMIZATION_PERF=y

View File

@ -1,17 +1,17 @@
# #
# ESP32C6-Specific # ESP32C6-Specific
# #
CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=20 CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=40
CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM=38 CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM=60
CONFIG_ESP_WIFI_DYNAMIC_TX_BUFFER_NUM=35 CONFIG_ESP_WIFI_DYNAMIC_TX_BUFFER_NUM=40
CONFIG_ESP_WIFI_AMPDU_TX_ENABLED=y CONFIG_ESP_WIFI_AMPDU_TX_ENABLED=y
CONFIG_ESP_WIFI_TX_BA_WIN=20 CONFIG_ESP_WIFI_TX_BA_WIN=32
CONFIG_ESP_WIFI_AMPDU_RX_ENABLED=y CONFIG_ESP_WIFI_AMPDU_RX_ENABLED=y
CONFIG_ESP_WIFI_RX_BA_WIN=20 CONFIG_ESP_WIFI_RX_BA_WIN=32
CONFIG_ESP_WIFI_NVS_ENABLED=n CONFIG_ESP_WIFI_NVS_ENABLED=n
CONFIG_LWIP_TCP_SND_BUF_DEFAULT=30000 CONFIG_LWIP_TCP_SND_BUF_DEFAULT=51200
CONFIG_LWIP_TCP_WND_DEFAULT=34000 CONFIG_LWIP_TCP_WND_DEFAULT=65535
CONFIG_LWIP_TCP_RECVMBOX_SIZE=64 CONFIG_LWIP_TCP_RECVMBOX_SIZE=64
CONFIG_LWIP_UDP_RECVMBOX_SIZE=64 CONFIG_LWIP_UDP_RECVMBOX_SIZE=64
CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=64 CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=64
@ -20,3 +20,6 @@ CONFIG_LWIP_IP_REASS_MAX_PBUFS=15
CONFIG_ESP_WIFI_ENABLE_WIFI_RX_STATS=n CONFIG_ESP_WIFI_ENABLE_WIFI_RX_STATS=n
CONFIG_ESP_WIFI_ENABLE_WIFI_TX_STATS=n CONFIG_ESP_WIFI_ENABLE_WIFI_TX_STATS=n
CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
CONFIG_LWIP_EXTRA_IRAM_OPTIMIZATION=y

View File

@ -43,8 +43,8 @@ static void print_auth_mode(int authmode)
case WIFI_AUTH_WPA_WPA2_PSK: case WIFI_AUTH_WPA_WPA2_PSK:
ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_WPA_WPA2_PSK"); ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_WPA_WPA2_PSK");
break; break;
case WIFI_AUTH_WPA2_ENTERPRISE: case WIFI_AUTH_ENTERPRISE:
ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_WPA2_ENTERPRISE"); ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_ENTERPRISE");
break; break;
case WIFI_AUTH_WPA3_PSK: case WIFI_AUTH_WPA3_PSK:
ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_WPA3_PSK"); ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_WPA3_PSK");
@ -52,6 +52,9 @@ static void print_auth_mode(int authmode)
case WIFI_AUTH_WPA2_WPA3_PSK: case WIFI_AUTH_WPA2_WPA3_PSK:
ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_WPA2_WPA3_PSK"); ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_WPA2_WPA3_PSK");
break; break;
case WIFI_AUTH_WPA3_ENT_192:
ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_WPA3_ENT_192");
break;
default: default:
ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_UNKNOWN"); ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_UNKNOWN");
break; break;

View File

@ -15,7 +15,7 @@ menu "Example Configuration"
bool "WPA3_ENT" bool "WPA3_ENT"
config EXAMPLE_WPA3_192BIT_ENTERPRISE config EXAMPLE_WPA3_192BIT_ENTERPRISE
bool "WPA3_192BIT_ENT" bool "WPA3_192BIT_ENT"
depends on IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3 depends on SOC_WIFI_GCMP_SUPPORT
select ESP_WIFI_GCMP_SUPPORT select ESP_WIFI_GCMP_SUPPORT
select ESP_WIFI_GMAC_SUPPORT select ESP_WIFI_GMAC_SUPPORT
select ESP_WIFI_SUITE_B_192 select ESP_WIFI_SUITE_B_192

View File

@ -186,6 +186,7 @@ ignore:
- components/http_parser/ - components/http_parser/
- components/wpa_supplicant/src/ - components/wpa_supplicant/src/
- '!components/wpa_supplicant/esp_supplicant/' - '!components/wpa_supplicant/esp_supplicant/'
- components/wpa_supplicant/esp_supplicant/src/crypto/fastpbkdf2*
- components/bt/host/bluedroid/ - components/bt/host/bluedroid/
- '!components/bt/host/bluedroid/api/' - '!components/bt/host/bluedroid/api/'
- '!components/bt/host/bluedroid/btc/' - '!components/bt/host/bluedroid/btc/'