From f9feb970b966ca4b66b3209e1e85e9b3b12a16f2 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Thu, 28 Mar 2024 14:40:19 +0530 Subject: [PATCH] feat(esp_wifi): Provide API to disable PMK caching --- .../esp_supplicant/include/esp_wpa.h | 18 +++++++++++++++++- .../esp_supplicant/src/esp_eap_client.c | 2 +- .../esp_supplicant/src/esp_wpa_main.c | 10 ++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/components/wpa_supplicant/esp_supplicant/include/esp_wpa.h b/components/wpa_supplicant/esp_supplicant/include/esp_wpa.h index 5e232486c5..fd8e82768e 100644 --- a/components/wpa_supplicant/esp_supplicant/include/esp_wpa.h +++ b/components/wpa_supplicant/esp_supplicant/include/esp_wpa.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -57,6 +57,22 @@ esp_err_t esp_supplicant_init(void); */ esp_err_t esp_supplicant_deinit(void); +/** + * @brief Disable or enable the caching of Pairwise Master Keys (PMK) in the supplicant. + * + * This function allows disabling or enabling the caching of Pairwise Master Keys (PMK). + * PMK caching is used in Wi-Fi Protected Access (WPA/WPA2/WPA3) networks to speed up the reconnection process + * by storing the PMK generated during the initial connection. Disabling PMK caching may result in slightly + * longer reconnection times. PMK caching is enabled by default, this configuration has been provided + * in case the AP is known not to support PMK caching or has a buggy implementation for PMK caching. + * + * @param disable Boolean indicating whether to disable (true) or enable (false) PMK caching. + * @return + * - ESP_OK: Success + * - An error code if disabling or enabling PMK caching fails. + */ +esp_err_t esp_supplicant_disable_pmk_caching(bool disable); + /** * @} */ diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_eap_client.c b/components/wpa_supplicant/esp_supplicant/src/esp_eap_client.c index 3d46f7fe12..ba30370e7c 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_eap_client.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_eap_client.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_wpa_main.c b/components/wpa_supplicant/esp_supplicant/src/esp_wpa_main.c index 54fd073869..b3d667bb22 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_wpa_main.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_wpa_main.c @@ -40,6 +40,7 @@ #include "wps/wps_defs.h" #include "wps/wps.h" +bool g_wpa_pmk_caching_disabled = 0; const wifi_osi_funcs_t *wifi_funcs; struct wpa_funcs *wpa_cb; @@ -262,6 +263,9 @@ static void wpa_sta_disconnected_cb(uint8_t reason_code) wpa_sm_notify_disassoc(&gWpaSm); break; default: + if (g_wpa_pmk_caching_disabled) { + wpa_sta_clear_curr_pmksa(); + } break; } #ifdef CONFIG_OWE_STA @@ -460,3 +464,9 @@ int esp_supplicant_deinit(void) wpa_cb = NULL; return esp_wifi_unregister_wpa_cb_internal(); } + +esp_err_t esp_supplicant_disable_pmk_caching(bool disable) +{ + g_wpa_pmk_caching_disabled = disable; + return ESP_OK; +}