diff --git a/components/wpa_supplicant/src/rsn_supp/wpa.c b/components/wpa_supplicant/src/rsn_supp/wpa.c index acfecb5c8e1..26a42bcf942 100644 --- a/components/wpa_supplicant/src/rsn_supp/wpa.c +++ b/components/wpa_supplicant/src/rsn_supp/wpa.c @@ -2331,8 +2331,15 @@ int wpa_set_bss(char *macddr, char * bssid, u8 pairwise_cipher, u8 group_cipher, sm->key_mgmt == WPA_KEY_MGMT_OWE || is_wpa2_enterprise_connection()) { if (!esp_wifi_skip_supp_pmkcaching() && use_pmk_cache) { - pmksa_cache_set_current(sm, NULL, (const u8*) bssid, 0, 0); - wpa_sm_set_pmk_from_pmksa(sm); + if (pmksa_cache_set_current(sm, NULL, (const u8*) bssid, 0, 0) == 0) { + struct rsn_pmksa_cache_entry *pmksa = pmksa_cache_get_current(sm); + if (pmksa && (pmksa->akmp != sm->key_mgmt)) { + pmksa_cache_clear_current(sm); + pmksa_cache_flush(sm->pmksa, NULL, pmksa->pmk, pmksa->pmk_len); + } + } else { + wpa_sm_set_pmk_from_pmksa(sm); + } } else { struct rsn_pmksa_cache_entry *entry = NULL;