Skip to content

Commit 3d5bf35

Browse files
sarveshb14nachiketkukade
authored andcommitted
fix(wifi): Fix wrong PMKSA cache entry being used when wifi password is changed
1 parent 1633c1a commit 3d5bf35

File tree

6 files changed

+23
-7
lines changed

6 files changed

+23
-7
lines changed

components/esp_wifi/include/esp_wifi_types_generic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ typedef enum {
355355
* @brief Structure describing parameters for a Wi-Fi fast scan
356356
*/
357357
typedef struct {
358-
int8_t rssi; /**< The minimum rssi to accept in the fast scan mode */
358+
int8_t rssi; /**< The minimum rssi to accept in the fast scan mode. Defaults to -127 if set to >= 0 */
359359
wifi_auth_mode_t authmode; /**< The weakest auth mode to accept in the fast scan mode
360360
Note: In case this value is not set and password is set as per WPA2 standards(password len >= 8), it will be defaulted to WPA2 and device won't connect to deprecated WEP/WPA networks. Please set auth mode threshold as WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK to connect to WEP/WPA networks */
361361
uint8_t rssi_5g_adjustment; /**< The RSSI value of the 5G AP is within the rssi_5g_adjustment range compared to the 2G AP, the 5G AP will be given priority for connection. */
@@ -536,7 +536,7 @@ typedef struct {
536536
wifi_scan_method_t scan_method; /**< Do all channel scan or fast scan */
537537
bool bssid_set; /**< Whether set MAC address of target AP or not. Generally, station_config.bssid_set needs to be 0; and it needs to be 1 only when users need to check the MAC address of the AP.*/
538538
uint8_t bssid[6]; /**< MAC address of target AP*/
539-
uint8_t channel; /**< Channel of target AP. For 2.4G AP, set to 1~13 to scan starting from the specified channel before connecting to AP. For 5G AP, set to 36~177 (36, 40, 44 ... 177) to scan starting from the specified channel before connecting to AP. If the channel of AP is unknown, set it to 0.*/
539+
uint8_t channel; /**< Channel hint for target AP. For 2.4G AP, set to 1~13 to scan starting from the specified channel before connecting to AP. For 5G AP, set to 36~177 (36, 40, 44 ... 177) to scan starting from the specified channel before connecting to AP. Set to 0 for no preference */
540540
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. */
541541
wifi_sort_method_t sort_method; /**< Sort the connect AP in the list by rssi or security mode */
542542
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. */

components/wpa_supplicant/esp_supplicant/src/esp_wifi_driver.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ struct wpa_funcs {
145145
uint8_t *(*owe_build_dhie)(uint16_t group);
146146
int (*owe_process_assoc_resp)(const u8 *rsn_ie, size_t rsn_len, const uint8_t *dh_ie, size_t dh_len);
147147
void (*wpa_sta_clear_curr_pmksa)(void);
148+
void (*wpa_config_reload)(void);
148149
};
149150

150151
struct wpa2_funcs {
@@ -222,7 +223,7 @@ uint8_t esp_wifi_ap_get_prof_authmode_internal(void);
222223
uint8_t esp_wifi_sta_get_prof_authmode_internal(void);
223224
uint8_t *esp_wifi_ap_get_prof_password_internal(void);
224225
struct wifi_ssid *esp_wifi_sta_get_prof_ssid_internal(void);
225-
uint8_t esp_wifi_sta_get_reset_param_internal(void);
226+
uint8_t esp_wifi_sta_get_reset_nvs_pmk_internal(void);
226227
uint8_t esp_wifi_sta_get_pairwise_cipher_internal(void);
227228
uint8_t esp_wifi_sta_get_group_cipher_internal(void);
228229
bool esp_wifi_sta_prof_is_wpa_internal(void);
@@ -242,7 +243,7 @@ int esp_wifi_set_sta_key_internal(int alg, u8 *addr, int key_idx, int set_tx,
242243
int esp_wifi_get_sta_key_internal(uint8_t *ifx, int *alg, u8 *addr, int *key_idx,
243244
u8 *key, size_t key_len, enum key_flag key_flag);
244245
bool esp_wifi_wpa_ptk_init_done_internal(uint8_t *mac);
245-
uint8_t esp_wifi_sta_set_reset_param_internal(uint8_t reset_flag);
246+
uint8_t esp_wifi_sta_set_reset_nvs_pmk_internal(uint8_t reset_flag);
246247
uint8_t esp_wifi_get_sta_gtk_index_internal(void);
247248
int esp_wifi_register_tx_cb_internal(wifi_tx_cb_t fn, u8 id);
248249
int esp_wifi_register_eapol_txdonecb_internal(eapol_txcb_t fn);

components/wpa_supplicant/esp_supplicant/src/esp_wpa_main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "ap/sta_info.h"
4141
#include "wps/wps_defs.h"
4242
#include "wps/wps.h"
43+
#include "rsn_supp/pmksa_cache.h"
4344

4445
#ifdef CONFIG_DPP
4546
#include "common/dpp.h"
@@ -439,6 +440,12 @@ static bool hostap_sta_join(void **sta, u8 *bssid, u8 *wpa_ie, u8 wpa_ie_len, u8
439440
}
440441
#endif
441442

443+
static void wpa_config_reload(void)
444+
{
445+
struct wpa_sm *sm = &gWpaSm;
446+
wpa_sm_pmksa_cache_flush(sm, NULL);
447+
}
448+
442449
int esp_supplicant_init(void)
443450
{
444451
int ret = ESP_OK;
@@ -476,6 +483,7 @@ int esp_supplicant_init(void)
476483
wpa_cb->wpa_michael_mic_failure = wpa_michael_mic_failure;
477484
wpa_cb->wpa_config_done = wpa_config_done;
478485
wpa_cb->wpa_sta_clear_curr_pmksa = wpa_sta_clear_curr_pmksa;
486+
wpa_cb->wpa_config_reload = wpa_config_reload;
479487

480488
esp_wifi_register_wpa3_ap_cb(wpa_cb);
481489
esp_wifi_register_wpa3_cb(wpa_cb);

components/wpa_supplicant/src/rsn_supp/wpa.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,7 +2471,7 @@ wpa_set_passphrase(char * passphrase, u8 *ssid, size_t ssid_len)
24712471
return;
24722472

24732473
/* This is really SLOW, so just re cacl while reset param */
2474-
if (esp_wifi_sta_get_reset_param_internal() != 0) {
2474+
if (esp_wifi_sta_get_reset_nvs_pmk_internal() != 0) {
24752475
// check it's psk
24762476
if (strlen((char *)esp_wifi_sta_get_prof_password_internal()) == 64) {
24772477
if (hexstr2bin((char *)esp_wifi_sta_get_prof_password_internal(),
@@ -2482,7 +2482,7 @@ wpa_set_passphrase(char * passphrase, u8 *ssid, size_t ssid_len)
24822482
4096, esp_wifi_sta_get_ap_info_prof_pmk_internal(), PMK_LEN);
24832483
}
24842484
esp_wifi_sta_update_ap_info_internal();
2485-
esp_wifi_sta_set_reset_param_internal(0);
2485+
esp_wifi_sta_set_reset_nvs_pmk_internal(0);
24862486
}
24872487

24882488
if (sm->key_mgmt == WPA_KEY_MGMT_IEEE8021X) {
@@ -2994,4 +2994,10 @@ int owe_process_assoc_resp(const u8 *rsn_ie, size_t rsn_len, const uint8_t *dh_i
29942994
return -1;
29952995
}
29962996
#endif // CONFIG_OWE_STA
2997+
2998+
2999+
void wpa_sm_pmksa_cache_flush(struct wpa_sm *sm, void *network_ctx)
3000+
{
3001+
pmksa_cache_flush(sm->pmksa, network_ctx, NULL, 0);
3002+
}
29973003
#endif // ESP_SUPPLICANT

components/wpa_supplicant/src/rsn_supp/wpa.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,5 @@ int owe_process_assoc_resp(const u8 *rsn_ie, size_t rsn_len, const uint8_t *dh_i
133133

134134
struct wpabuf *owe_build_assoc_req(struct wpa_sm *sm, u16 group);
135135

136+
void wpa_sm_pmksa_cache_flush(struct wpa_sm *sm, void *network_ctx);
136137
#endif /* WPA_H */

0 commit comments

Comments
 (0)