diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index 4b36dcf44b..4c3998b83e 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit 4b36dcf44bef493ce291d24f459d7bdb068fa0dc +Subproject commit 4c3998b83e76d16cd55113d37de317ffa6679150 diff --git a/components/wpa_supplicant/esp_supplicant/include/esp_rrm.h b/components/wpa_supplicant/esp_supplicant/include/esp_rrm.h index 1ffcf18047..fa40e0cd62 100644 --- a/components/wpa_supplicant/esp_supplicant/include/esp_rrm.h +++ b/components/wpa_supplicant/esp_supplicant/include/esp_rrm.h @@ -1,17 +1,7 @@ -/** - * Copyright 2020 Espressif Systems (Shanghai) PTE LTD +/* + * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * SPDX-License-Identifier: Apache-2.0 */ #ifndef _ESP_RRM_H @@ -41,11 +31,22 @@ typedef void (*neighbor_rep_request_cb)(void *ctx, const uint8_t *report, size_t * @param cb_ctx: callback context * * @return - * - 0: success else failure + * - 0: success + * - -1: AP does not support RRM + * - -2: station not connected to AP */ int esp_rrm_send_neighbor_rep_request(neighbor_rep_request_cb cb, void *cb_ctx); +/** + * @brief Check RRM capability of connected AP + * + * @return + * - true: AP supports RRM + * - false: AP does not support RRM or station not connected to AP + */ +bool esp_rrm_is_rrm_supported_connection(void); + #ifdef __cplusplus } #endif diff --git a/components/wpa_supplicant/esp_supplicant/include/esp_wnm.h b/components/wpa_supplicant/esp_supplicant/include/esp_wnm.h index 4301385d2c..2ee95bedd7 100644 --- a/components/wpa_supplicant/esp_supplicant/include/esp_wnm.h +++ b/components/wpa_supplicant/esp_supplicant/include/esp_wnm.h @@ -36,12 +36,23 @@ enum btm_query_reason { * @param cand_list: whether candidate list to be included from scan results available in supplicant's cache. * * @return - * - 0: success else failure + * - 0: success + * - -1: AP does not support BTM + * - -2: station not connected to AP */ int esp_wnm_send_bss_transition_mgmt_query(enum btm_query_reason query_reason, const char *btm_candidates, int cand_list); +/** + * @brief Check bss trasition capability of connected AP + * + * @return + * - true: AP supports BTM + * - false: AP does not support BTM or station not connected to AP + */ +bool esp_wnm_is_btm_supported_connection(void); + #ifdef __cplusplus } #endif diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_common.c b/components/wpa_supplicant/esp_supplicant/src/esp_common.c index 01a0cc1eab..61f19ab3ff 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_common.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_common.c @@ -343,23 +343,83 @@ void esp_supplicant_common_deinit(void) } } +bool esp_rrm_is_rrm_supported_connection(void) +{ + struct wpa_supplicant *wpa_s = &g_wpa_supp; + + if (!wpa_s->current_bss) { + wpa_printf(MSG_DEBUG, "STA not associated, return"); + return false; + } + + if (!(wpa_s->rrm_ie[0] & WLAN_RRM_CAPS_NEIGHBOR_REPORT)) { + wpa_printf(MSG_DEBUG, + "RRM: No network support for Neighbor Report."); + return false; + } + + return true; +} + int esp_rrm_send_neighbor_rep_request(neighbor_rep_request_cb cb, void *cb_ctx) { + struct wpa_supplicant *wpa_s = &g_wpa_supp; struct wpa_ssid_value wpa_ssid = {0}; - struct wifi_ssid *ssid = esp_wifi_sta_get_prof_ssid_internal(); + struct wifi_ssid *ssid; + + if (!wpa_s->current_bss) { + wpa_printf(MSG_ERROR, "STA not associated, return"); + return -2; + } + + if (!(wpa_s->rrm_ie[0] & WLAN_RRM_CAPS_NEIGHBOR_REPORT)) { + wpa_printf(MSG_ERROR, + "RRM: No network support for Neighbor Report."); + return -1; + } + + ssid = esp_wifi_sta_get_prof_ssid_internal(); os_memcpy(wpa_ssid.ssid, ssid->ssid, ssid->len); wpa_ssid.ssid_len = ssid->len; - return wpas_rrm_send_neighbor_rep_request(&g_wpa_supp, &wpa_ssid, 0, 0, cb, cb_ctx); + return wpas_rrm_send_neighbor_rep_request(wpa_s, &wpa_ssid, 0, 0, cb, cb_ctx); +} + +bool esp_wnm_is_btm_supported_connection(void) +{ + struct wpa_supplicant *wpa_s = &g_wpa_supp; + + if (!wpa_s->current_bss) { + wpa_printf(MSG_DEBUG, "STA not associated, return"); + return false; + } + + if (!wpa_bss_ext_capab(wpa_s->current_bss, WLAN_EXT_CAPAB_BSS_TRANSITION)) { + wpa_printf(MSG_DEBUG, "AP doesn't support BTM, return"); + return false; + } + + return true; } int esp_wnm_send_bss_transition_mgmt_query(enum btm_query_reason query_reason, const char *btm_candidates, int cand_list) { - return wnm_send_bss_transition_mgmt_query(&g_wpa_supp, query_reason, btm_candidates, cand_list); + struct wpa_supplicant *wpa_s = &g_wpa_supp; + + if (!wpa_s->current_bss) { + wpa_printf(MSG_ERROR, "STA not associated, return"); + return -2; + } + + if (!wpa_bss_ext_capab(wpa_s->current_bss, WLAN_EXT_CAPAB_BSS_TRANSITION)) { + wpa_printf(MSG_ERROR, "AP doesn't support BTM, return"); + return -1; + } + return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason, btm_candidates, cand_list); } int esp_mbo_update_non_pref_chan(struct non_pref_chan_s *non_pref_chan) @@ -471,9 +531,9 @@ static uint8_t get_extended_caps_ie(uint8_t *ie, size_t len) *pos++ = ext_caps_ie_len; *pos++ = 0; *pos++ = 0; -#define WLAN_EXT_CAPAB_BSS_TRANSITION BIT(3) - *pos |= WLAN_EXT_CAPAB_BSS_TRANSITION; -#undef WLAN_EXT_CAPAB_BSS_TRANSITION +#define CAPAB_BSS_TRANSITION BIT(3) + *pos |= CAPAB_BSS_TRANSITION; +#undef CAPAB_BSS_TRANSITION os_memcpy(ie, ext_caps_ie, sizeof(ext_caps_ie)); return ext_caps_ie_len + 2; diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_wps.c b/components/wpa_supplicant/esp_supplicant/src/esp_wps.c index 7a9d607c01..bf2bc34935 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_wps.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_wps.c @@ -804,6 +804,10 @@ int wps_process_wps_mX_req(u8 *ubuf, int len, enum wps_process_res *res) } if ((flag & WPS_MSG_FLAG_MORE) || wps_buf != NULL) {//frag msg + if (tlen > 50000) { + wpa_printf(MSG_ERROR, "EAP-WSC: Invalid Message Length"); + return ESP_FAIL; + } wpa_printf(MSG_DEBUG, "rx frag msg id:%d, flag:%d, frag_len: %d, tot_len: %d, be_tot_len:%d", sm->current_identifier, flag, frag_len, tlen, be_tot_len); if (ESP_OK != wps_enrollee_process_msg_frag(&wps_buf, tlen, tbuf, frag_len, flag)) { if (wps_buf) { diff --git a/components/wpa_supplicant/src/ap/ap_config.h b/components/wpa_supplicant/src/ap/ap_config.h index ca695851fa..9dad5f902e 100644 --- a/components/wpa_supplicant/src/ap/ap_config.h +++ b/components/wpa_supplicant/src/ap/ap_config.h @@ -219,7 +219,6 @@ struct hostapd_bss_config { int rsn_pairwise; int rsn_preauth; char *rsn_preauth_interfaces; - int peerkey; #ifdef CONFIG_IEEE80211R /* IEEE 802.11r - Fast BSS Transition */ diff --git a/components/wpa_supplicant/src/ap/wpa_auth.c b/components/wpa_supplicant/src/ap/wpa_auth.c index 32868c0137..5fb9199e97 100644 --- a/components/wpa_supplicant/src/ap/wpa_auth.c +++ b/components/wpa_supplicant/src/ap/wpa_auth.c @@ -557,8 +557,7 @@ void wpa_receive(struct wpa_authenticator *wpa_auth, struct wpa_state_machine *s struct ieee802_1x_hdr *hdr; struct wpa_eapol_key *key; u16 key_info, key_data_length; - enum { PAIRWISE_2, PAIRWISE_4, GROUP_2, REQUEST, - SMK_M1, SMK_M3, SMK_ERROR } msg; + enum { PAIRWISE_2, PAIRWISE_4, GROUP_2, REQUEST } msg; struct wpa_eapol_ie_parse kde; int ft; const u8 *eapol_key_ie; @@ -617,16 +616,12 @@ void wpa_receive(struct wpa_authenticator *wpa_auth, struct wpa_state_machine *s /* FIX: verify that the EAPOL-Key frame was encrypted if pairwise keys * are set */ - if ((key_info & (WPA_KEY_INFO_SMK_MESSAGE | WPA_KEY_INFO_REQUEST)) == - (WPA_KEY_INFO_SMK_MESSAGE | WPA_KEY_INFO_REQUEST)) { - if (key_info & WPA_KEY_INFO_ERROR) { - msg = SMK_ERROR; - } else { - msg = SMK_M1; - } - } else if (key_info & WPA_KEY_INFO_SMK_MESSAGE) { - msg = SMK_M3; - } else if (key_info & WPA_KEY_INFO_REQUEST) { + if (key_info & WPA_KEY_INFO_SMK_MESSAGE) { + wpa_printf(MSG_DEBUG, "WPA: Ignore SMK message"); + return; + } + + if (key_info & WPA_KEY_INFO_REQUEST) { msg = REQUEST; } else if (!(key_info & WPA_KEY_INFO_KEY_TYPE)) { msg = GROUP_2; @@ -636,7 +631,6 @@ void wpa_receive(struct wpa_authenticator *wpa_auth, struct wpa_state_machine *s msg = PAIRWISE_2; } - /* TODO: key_info type validation for PeerKey */ if (msg == REQUEST || msg == PAIRWISE_2 || msg == PAIRWISE_4 || msg == GROUP_2) { u16 ver = key_info & WPA_KEY_INFO_TYPE_MASK; @@ -777,25 +771,6 @@ continue_processing: return; } break; -#ifdef CONFIG_PEERKEY - case SMK_M1: - case SMK_M3: - case SMK_ERROR: - if (!wpa_auth->conf.peerkey) { - wpa_printf( MSG_DEBUG, "RSN: SMK M1/M3/Error, but " - "PeerKey use disabled - ignoring message"); - return; - } - if (!sm->PTK_valid) { - return; - } - break; -#else /* CONFIG_PEERKEY */ - case SMK_M1: - case SMK_M3: - case SMK_ERROR: - return; /* STSL disabled - ignore SMK messages */ -#endif /* CONFIG_PEERKEY */ case REQUEST: break; } @@ -836,22 +811,13 @@ continue_processing: * even though MAC address KDE is not normally encrypted, * supplicant is allowed to encrypt it. */ - if (msg == SMK_ERROR) { -#ifdef CONFIG_PEERKEY - wpa_smk_error(wpa_auth, sm, key); -#endif /* CONFIG_PEERKEY */ - return; - } else if (key_info & WPA_KEY_INFO_ERROR) { + if (key_info & WPA_KEY_INFO_ERROR) { if (wpa_receive_error_report( wpa_auth, sm, !(key_info & WPA_KEY_INFO_KEY_TYPE)) > 0) return; /* STA entry was removed */ } else if (key_info & WPA_KEY_INFO_KEY_TYPE) { wpa_request_new_ptk(sm); -#ifdef CONFIG_PEERKEY - } else if (msg == SMK_M1) { - wpa_smk_m1(wpa_auth, sm, key); -#endif /* CONFIG_PEERKEY */ } else if (key_data_length > 0 && wpa_parse_kde_ies((const u8 *) (key + 1), key_data_length, &kde) == 0 && @@ -887,13 +853,6 @@ continue_processing: wpa_replay_counter_mark_invalid(sm->key_replay, NULL); } -#ifdef CONFIG_PEERKEY - if (msg == SMK_M3) { - wpa_smk_m3(wpa_auth, sm, key); - return; - } -#endif /* CONFIG_PEERKEY */ - wpa_printf( MSG_DEBUG, "wpa_rx: free eapol=%p\n", sm->last_rx_eapol_key); os_free(sm->last_rx_eapol_key); sm->last_rx_eapol_key = (u8 *)os_malloc(data_len); @@ -1025,11 +984,11 @@ void __wpa_send_eapol(struct wpa_authenticator *wpa_auth, WPA_PUT_BE16(key->key_info, key_info); alg = pairwise ? sm->pairwise : wpa_auth->conf.wpa_group; - WPA_PUT_BE16(key->key_length, wpa_cipher_key_len(alg)); - if (key_info & WPA_KEY_INFO_SMK_MESSAGE) + if (sm->wpa == WPA_VERSION_WPA2 && !pairwise) WPA_PUT_BE16(key->key_length, 0); + else + WPA_PUT_BE16(key->key_length, wpa_cipher_key_len(alg)); - /* FIX: STSL: what to use as key_replay_counter? */ for (i = RSNA_MAX_EAPOL_RETRIES - 1; i > 0; i--) { sm->key_replay[i].valid = sm->key_replay[i - 1].valid; memcpy(sm->key_replay[i].counter, diff --git a/components/wpa_supplicant/src/ap/wpa_auth.h b/components/wpa_supplicant/src/ap/wpa_auth.h index 4979ec6bae..a4a040fd27 100644 --- a/components/wpa_supplicant/src/ap/wpa_auth.h +++ b/components/wpa_supplicant/src/ap/wpa_auth.h @@ -136,7 +136,6 @@ struct wpa_auth_config { int rsn_pairwise; int rsn_preauth; int eapol_version; - int peerkey; int wmm_enabled; int wmm_uapsd; int disable_pmksa_caching; diff --git a/components/wpa_supplicant/src/ap/wpa_auth_i.h b/components/wpa_supplicant/src/ap/wpa_auth_i.h index fba036732e..8b1c51cb90 100644 --- a/components/wpa_supplicant/src/ap/wpa_auth_i.h +++ b/components/wpa_supplicant/src/ap/wpa_auth_i.h @@ -183,17 +183,6 @@ int wpa_auth_for_each_auth(struct wpa_authenticator *wpa_auth, int (*cb)(struct wpa_authenticator *a, void *ctx), void *cb_ctx); -#ifdef CONFIG_PEERKEY -int wpa_stsl_remove(struct wpa_authenticator *wpa_auth, - struct wpa_stsl_negotiation *neg); -void wpa_smk_error(struct wpa_authenticator *wpa_auth, - struct wpa_state_machine *sm, struct wpa_eapol_key *key); -void wpa_smk_m1(struct wpa_authenticator *wpa_auth, - struct wpa_state_machine *sm, struct wpa_eapol_key *key); -void wpa_smk_m3(struct wpa_authenticator *wpa_auth, - struct wpa_state_machine *sm, struct wpa_eapol_key *key); -#endif /* CONFIG_PEERKEY */ - #ifdef CONFIG_IEEE80211R int wpa_write_mdie(struct wpa_auth_config *conf, u8 *buf, size_t len); int wpa_write_ftie(struct wpa_auth_config *conf, const u8 *r0kh_id, diff --git a/components/wpa_supplicant/src/ap/wpa_auth_ie.c b/components/wpa_supplicant/src/ap/wpa_auth_ie.c index 532127c8e5..6ef4bbe7e7 100644 --- a/components/wpa_supplicant/src/ap/wpa_auth_ie.c +++ b/components/wpa_supplicant/src/ap/wpa_auth_ie.c @@ -216,8 +216,6 @@ int wpa_write_rsn_ie(struct wpa_auth_config *conf, u8 *buf, size_t len, capab = 0; if (conf->rsn_preauth) capab |= WPA_CAPABILITY_PREAUTH; - if (conf->peerkey) - capab |= WPA_CAPABILITY_PEERKEY_ENABLED; if (conf->wmm_enabled) { /* 4 PTKSA replay counters when using WMM */ capab |= (RSN_NUM_REPLAY_COUNTERS_16 << 2); @@ -626,36 +624,6 @@ static int wpa_parse_generic(const u8 *pos, const u8 *end, return 0; } -#ifdef CONFIG_PEERKEY - if (pos[1] > RSN_SELECTOR_LEN + 2 && - RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_SMK) { - ie->smk = pos + 2 + RSN_SELECTOR_LEN; - ie->smk_len = pos[1] - RSN_SELECTOR_LEN; - return 0; - } - - if (pos[1] > RSN_SELECTOR_LEN + 2 && - RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_NONCE) { - ie->nonce = pos + 2 + RSN_SELECTOR_LEN; - ie->nonce_len = pos[1] - RSN_SELECTOR_LEN; - return 0; - } - - if (pos[1] > RSN_SELECTOR_LEN + 2 && - RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_LIFETIME) { - ie->lifetime = pos + 2 + RSN_SELECTOR_LEN; - ie->lifetime_len = pos[1] - RSN_SELECTOR_LEN; - return 0; - } - - if (pos[1] > RSN_SELECTOR_LEN + 2 && - RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_ERROR) { - ie->error = pos + 2 + RSN_SELECTOR_LEN; - ie->error_len = pos[1] - RSN_SELECTOR_LEN; - return 0; - } -#endif /* CONFIG_PEERKEY */ - #ifdef CONFIG_IEEE80211W if (pos[1] > RSN_SELECTOR_LEN + 2 && RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_IGTK) { diff --git a/components/wpa_supplicant/src/ap/wpa_auth_ie.h b/components/wpa_supplicant/src/ap/wpa_auth_ie.h index 4999139510..dfcfbd301e 100644 --- a/components/wpa_supplicant/src/ap/wpa_auth_ie.h +++ b/components/wpa_supplicant/src/ap/wpa_auth_ie.h @@ -19,16 +19,6 @@ struct wpa_eapol_ie_parse { size_t gtk_len; const u8 *mac_addr; size_t mac_addr_len; -#ifdef CONFIG_PEERKEY - const u8 *smk; - size_t smk_len; - const u8 *nonce; - size_t nonce_len; - const u8 *lifetime; - size_t lifetime_len; - const u8 *error; - size_t error_len; -#endif /* CONFIG_PEERKEY */ #ifdef CONFIG_IEEE80211W const u8 *igtk; size_t igtk_len; diff --git a/components/wpa_supplicant/src/common/ieee802_11_defs.h b/components/wpa_supplicant/src/common/ieee802_11_defs.h index d4cab57655..41fac6e7a5 100644 --- a/components/wpa_supplicant/src/common/ieee802_11_defs.h +++ b/components/wpa_supplicant/src/common/ieee802_11_defs.h @@ -250,6 +250,8 @@ #define WLAN_EID_EXT_HE_CAPABILITIES 35 #define WLAN_EID_EXT_HE_OPERATION 36 +#define WLAN_EXT_CAPAB_BSS_TRANSITION 19 + /* Action frame categories (IEEE Std 802.11-2016, 9.4.1.11, Table 9-76) */ #define WLAN_ACTION_SPECTRUM_MGMT 0 #define WLAN_ACTION_QOS 1 diff --git a/components/wpa_supplicant/src/common/sae.c b/components/wpa_supplicant/src/common/sae.c index 469303cb28..af1da9d506 100644 --- a/components/wpa_supplicant/src/common/sae.c +++ b/components/wpa_supplicant/src/common/sae.c @@ -48,7 +48,6 @@ int sae_set_group(struct sae_data *sae, int group) tmp->prime_len = tmp->dh->prime_len; if (tmp->prime_len > SAE_MAX_PRIME_LEN) { sae_clear_data(sae); - os_free(tmp); return ESP_FAIL; } @@ -56,7 +55,6 @@ int sae_set_group(struct sae_data *sae, int group) tmp->prime_len); if (tmp->prime_buf == NULL) { sae_clear_data(sae); - os_free(tmp); return ESP_FAIL; } tmp->prime = tmp->prime_buf; @@ -65,7 +63,6 @@ int sae_set_group(struct sae_data *sae, int group) tmp->dh->order_len); if (tmp->order_buf == NULL) { sae_clear_data(sae); - os_free(tmp); return ESP_FAIL; } tmp->order = tmp->order_buf; @@ -846,7 +843,7 @@ fail: int sae_process_commit(struct sae_data *sae) { - u8 k[SAE_MAX_PRIME_LEN]; + u8 k[SAE_MAX_PRIME_LEN] = {0}; if (sae->tmp == NULL || (sae->tmp->ec && sae_derive_k_ecc(sae, k) < 0) || (sae->tmp->dh && sae_derive_k_ffc(sae, k) < 0) || diff --git a/components/wpa_supplicant/src/common/wpa_common.c b/components/wpa_supplicant/src/common/wpa_common.c index 070ba0887e..9842be0827 100644 --- a/components/wpa_supplicant/src/common/wpa_common.c +++ b/components/wpa_supplicant/src/common/wpa_common.c @@ -646,10 +646,6 @@ const char * wpa_cipher_txt(int cipher) * PTK = PRF-X(PMK, "Pairwise key expansion", * Min(AA, SA) || Max(AA, SA) || * Min(ANonce, SNonce) || Max(ANonce, SNonce)) - * - * STK = PRF-X(SMK, "Peer key expansion", - * Min(MAC_I, MAC_P) || Max(MAC_I, MAC_P) || - * Min(INonce, PNonce) || Max(INonce, PNonce)) */ int wpa_pmk_to_ptk(const u8 *pmk, size_t pmk_len, const char *label, const u8 *addr1, const u8 *addr2, diff --git a/components/wpa_supplicant/src/common/wpa_common.h b/components/wpa_supplicant/src/common/wpa_common.h index da8132e28c..e96afa7d95 100644 --- a/components/wpa_supplicant/src/common/wpa_common.h +++ b/components/wpa_supplicant/src/common/wpa_common.h @@ -94,12 +94,6 @@ RSN_SELECTOR(0x00, 0x0f, 0xac, 13) #define RSN_KEY_DATA_GROUPKEY RSN_SELECTOR(0x00, 0x0f, 0xac, 1) #define RSN_KEY_DATA_MAC_ADDR RSN_SELECTOR(0x00, 0x0f, 0xac, 3) #define RSN_KEY_DATA_PMKID RSN_SELECTOR(0x00, 0x0f, 0xac, 4) -#ifdef CONFIG_PEERKEY -#define RSN_KEY_DATA_SMK RSN_SELECTOR(0x00, 0x0f, 0xac, 5) -#define RSN_KEY_DATA_NONCE RSN_SELECTOR(0x00, 0x0f, 0xac, 6) -#define RSN_KEY_DATA_LIFETIME RSN_SELECTOR(0x00, 0x0f, 0xac, 7) -#define RSN_KEY_DATA_ERROR RSN_SELECTOR(0x00, 0x0f, 0xac, 8) -#endif /* CONFIG_PEERKEY */ #ifdef CONFIG_IEEE80211W #define RSN_KEY_DATA_IGTK RSN_SELECTOR(0x00, 0x0f, 0xac, 9) #endif /* CONFIG_IEEE80211W */ @@ -272,23 +266,6 @@ struct rsn_ie_hdr { u8 version[2]; /* little endian */ } STRUCT_PACKED; - -#ifdef CONFIG_PEERKEY -enum { - STK_MUI_4WAY_STA_AP = 1, - STK_MUI_4WAY_STAT_STA = 2, - STK_MUI_GTK = 3, - STK_MUI_SMK = 4 -}; - -enum { - STK_ERR_STA_NR = 1, - STK_ERR_STA_NRSN = 2, - STK_ERR_CPHR_NS = 3, - STK_ERR_NO_STSL = 4 -}; -#endif /* CONFIG_PEERKEY */ - struct rsn_error_kde { be16 mui; be16 error_type; diff --git a/components/wpa_supplicant/src/crypto/crypto_mbedtls.c b/components/wpa_supplicant/src/crypto/crypto_mbedtls.c index d640a64189..cf37343cfa 100644 --- a/components/wpa_supplicant/src/crypto/crypto_mbedtls.c +++ b/components/wpa_supplicant/src/crypto/crypto_mbedtls.c @@ -120,7 +120,6 @@ struct crypto_hash * crypto_hash_init(enum crypto_hash_alg alg, const u8 *key, struct crypto_hash *ctx; mbedtls_md_type_t md_type; const mbedtls_md_info_t *md_info; - int ret; switch (alg) { case CRYPTO_HASH_ALG_HMAC_MD5: @@ -144,29 +143,37 @@ struct crypto_hash * crypto_hash_init(enum crypto_hash_alg alg, const u8 *key, mbedtls_md_init(&ctx->ctx); md_info = mbedtls_md_info_from_type(md_type); if (!md_info) { - os_free(ctx); - return NULL; + goto cleanup; } - ret = mbedtls_md_setup(&ctx->ctx, md_info, 1); - if (ret != 0) { - os_free(ctx); - return NULL; + if (mbedtls_md_setup(&ctx->ctx, md_info, 1) != 0) { + goto cleanup; + } + if (mbedtls_md_hmac_starts(&ctx->ctx, key, key_len) != 0) { + goto cleanup; } - mbedtls_md_hmac_starts(&ctx->ctx, key, key_len); - return ctx; +cleanup: + os_free(ctx); + return NULL; } void crypto_hash_update(struct crypto_hash *ctx, const u8 *data, size_t len) { + int ret; + if (ctx == NULL) { return; } - mbedtls_md_hmac_update(&ctx->ctx, data, len); + ret = mbedtls_md_hmac_update(&ctx->ctx, data, len); + if (ret != 0) { + wpa_printf(MSG_ERROR, "%s: mbedtls_md_hmac_update failed", __func__); + } } int crypto_hash_finish(struct crypto_hash *ctx, u8 *mac, size_t *len) { + int ret; + if (ctx == NULL) { return -2; } @@ -176,11 +183,11 @@ int crypto_hash_finish(struct crypto_hash *ctx, u8 *mac, size_t *len) bin_clear_free(ctx, sizeof(*ctx)); return 0; } - mbedtls_md_hmac_finish(&ctx->ctx, mac); + ret = mbedtls_md_hmac_finish(&ctx->ctx, mac); mbedtls_md_free(&ctx->ctx); bin_clear_free(ctx, sizeof(*ctx)); - return 0; + return ret; } static int hmac_vector(mbedtls_md_type_t md_type, @@ -205,17 +212,24 @@ static int hmac_vector(mbedtls_md_type_t md_type, return(ret); } - mbedtls_md_hmac_starts(&md_ctx, key, key_len); - - for (i = 0; i < num_elem; i++) { - mbedtls_md_hmac_update(&md_ctx, addr[i], len[i]); + ret = mbedtls_md_hmac_starts(&md_ctx, key, key_len); + if (ret != 0) { + return(ret); } - mbedtls_md_hmac_finish(&md_ctx, mac); + for (i = 0; i < num_elem; i++) { + ret = mbedtls_md_hmac_update(&md_ctx, addr[i], len[i]); + if (ret != 0) { + return(ret); + } + + } + + ret = mbedtls_md_hmac_finish(&md_ctx, mac); mbedtls_md_free(&md_ctx); - return 0; + return ret; } int hmac_sha384_vector(const u8 *key, size_t key_len, size_t num_elem, diff --git a/components/wpa_supplicant/src/eap_peer/eap_fast_pac.c b/components/wpa_supplicant/src/eap_peer/eap_fast_pac.c index 4f92f4ad3d..39821ddb1a 100644 --- a/components/wpa_supplicant/src/eap_peer/eap_fast_pac.c +++ b/components/wpa_supplicant/src/eap_peer/eap_fast_pac.c @@ -552,6 +552,7 @@ static int eap_fast_write_pac(struct eap_sm *sm, const char *pac_file, return -1; } eap_set_config_blob(sm, blob); + os_free(blob); } else { FILE *f; f = fopen(pac_file, "wb"); diff --git a/components/wpa_supplicant/src/rsn_supp/wpa.c b/components/wpa_supplicant/src/rsn_supp/wpa.c index be8c49bdd7..0911e07fe5 100644 --- a/components/wpa_supplicant/src/rsn_supp/wpa.c +++ b/components/wpa_supplicant/src/rsn_supp/wpa.c @@ -44,7 +44,7 @@ #define WPA_4_4_HANDSHAKE_BIT (1<<13) #define WPA_GROUP_HANDSHAKE_BIT (1<<14) - struct wpa_sm gWpaSm; +struct wpa_sm gWpaSm; /* fix buf for tx for now */ #define WPA_TX_MSG_BUFF_MAXLEN 200 @@ -318,9 +318,11 @@ static void wpa_sm_key_request(struct wpa_sm *sm, int error, int pairwise) EAPOL_KEY_TYPE_RSN : EAPOL_KEY_TYPE_WPA; key_info = WPA_KEY_INFO_REQUEST | ver; if (sm->ptk_set) + key_info |= WPA_KEY_INFO_SECURE; + if (sm->ptk_set && mic_len) key_info |= WPA_KEY_INFO_MIC; if (error) - key_info |= WPA_KEY_INFO_ERROR|WPA_KEY_INFO_SECURE; + key_info |= WPA_KEY_INFO_ERROR; if (pairwise) key_info |= WPA_KEY_INFO_KEY_TYPE; @@ -2205,7 +2207,17 @@ int wpa_set_bss(char *macddr, char * bssid, u8 pairwise_cipher, u8 group_cipher, { int res = 0; struct wpa_sm *sm = &gWpaSm; + bool use_pmk_cache = true; + /* Incase AP has changed it's SSID, don't try with PMK caching for SAE connection */ + /* Ideally we should use network_ctx for this purpose however currently network profile block + * is part of libraries, + * TODO Correct this in future during NVS restructuring */ + if ((sm->key_mgmt == WPA_KEY_MGMT_SAE) && + (os_memcmp(sm->bssid, bssid, ETH_ALEN) == 0) && + (os_memcmp(sm->ssid, ssid, ssid_len) != 0)) { + use_pmk_cache = false; + } sm->pairwise_cipher = BIT(pairwise_cipher); sm->group_cipher = BIT(group_cipher); sm->rx_replay_counter_set = 0; //init state not intall replay counter value @@ -2218,7 +2230,7 @@ int wpa_set_bss(char *macddr, char * bssid, u8 pairwise_cipher, u8 group_cipher, if (sm->key_mgmt == WPA_KEY_MGMT_SAE || is_wpa2_enterprise_connection()) { - if (!esp_wifi_skip_supp_pmkcaching()) { + 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); } else { @@ -2265,6 +2277,9 @@ int wpa_set_bss(char *macddr, char * bssid, u8 pairwise_cipher, u8 group_cipher, if (res < 0) return -1; sm->assoc_wpa_ie_len = res; + os_memset(sm->ssid, 0, sizeof(sm->ssid)); + os_memcpy(sm->ssid, ssid, ssid_len); + sm->ssid_len = ssid_len; wpa_set_passphrase(passphrase, ssid, ssid_len); return 0; } @@ -2336,9 +2351,9 @@ wpa_sm_set_key(struct install_key *key_sm, enum wpa_alg alg, struct wpa_sm *sm = &gWpaSm; /*gtk or ptk both need check countermeasures*/ - if (alg == WIFI_WPA_ALG_TKIP && key_len == 32) { + if (alg == WIFI_WPA_ALG_TKIP && key_idx == 0 && key_len == 32) { /* Clear the MIC error counter when setting a new PTK. */ - key_sm->mic_errors_seen = 0; + sm->mic_errors_seen = 0; } key_sm->keys_cleared = 0; @@ -2361,9 +2376,8 @@ wpa_sm_get_key(uint8_t *ifx, int *alg, u8 *addr, int *key_idx, u8 *key, size_t k void wpa_supplicant_clr_countermeasures(u16 *pisunicast) { - struct wpa_sm *sm = &gWpaSm; - (sm->install_ptk).mic_errors_seen=0; - (sm->install_gtk).mic_errors_seen=0; + struct wpa_sm *sm = &gWpaSm; + sm->mic_errors_seen = 0; ets_timer_done(&(sm->cm_timer)); wpa_printf(MSG_DEBUG, "WPA: TKIP countermeasures clean\n"); } @@ -2388,22 +2402,20 @@ void wpa_supplicant_stop_countermeasures(u16 *pisunicast) int wpa_michael_mic_failure(u16 isunicast) { - struct wpa_sm *sm = &gWpaSm; - int *pmic_errors_seen=(isunicast)? &((sm->install_ptk).mic_errors_seen) : &((sm->install_gtk).mic_errors_seen); + struct wpa_sm *sm = &gWpaSm; - wpa_printf(MSG_DEBUG, "\nTKIP MIC failure occur\n"); + wpa_printf(MSG_DEBUG, "TKIP MIC failure occur"); - /*both unicast and multicast mic_errors_seen need statistics*/ - if ((sm->install_ptk).mic_errors_seen + (sm->install_gtk).mic_errors_seen) { + if (sm->mic_errors_seen) { /* Send the new MIC error report immediately since we are going * to start countermeasures and AP better do the same. */ wpa_sm_set_state(WPA_TKIP_COUNTERMEASURES); - wpa_sm_key_request(sm, 1, 0); + wpa_sm_key_request(sm, 1, isunicast); /* initialize countermeasures */ sm->countermeasures = 1; - wpa_printf(MSG_DEBUG, "TKIP countermeasures started\n"); + wpa_printf(MSG_DEBUG, "TKIP countermeasures started"); /* * Need to wait for completion of request frame. We do not get @@ -2422,9 +2434,9 @@ int wpa_michael_mic_failure(u16 isunicast) /* TODO: mark the AP rejected for 60 second. STA is * allowed to associate with another AP.. */ } else { - *pmic_errors_seen=(*pmic_errors_seen)+1; + sm->mic_errors_seen++; wpa_sm_set_state(WPA_MIC_FAILURE); - wpa_sm_key_request(sm, 1, 0); + wpa_sm_key_request(sm, 1, isunicast); /*start 60sec counter to monitor whether next mic_failure occur in this period, or clear mic_errors_seen*/ ets_timer_disarm(&(sm->cm_timer)); ets_timer_done(&(sm->cm_timer)); diff --git a/components/wpa_supplicant/src/rsn_supp/wpa_i.h b/components/wpa_supplicant/src/rsn_supp/wpa_i.h index 9fa4527236..c88185ac84 100644 --- a/components/wpa_supplicant/src/rsn_supp/wpa_i.h +++ b/components/wpa_supplicant/src/rsn_supp/wpa_i.h @@ -16,7 +16,6 @@ #define WPA_I_H struct install_key { - int mic_errors_seen; /* Michael MIC errors with the current PTK */ int keys_cleared; enum wpa_alg alg; u8 addr[ETH_ALEN]; @@ -43,6 +42,8 @@ struct wpa_sm { u8 request_counter[WPA_REPLAY_COUNTER_LEN]; struct rsn_pmksa_cache *pmksa; /* PMKSA cache */ struct rsn_pmksa_cache_entry *cur_pmksa; /* current PMKSA entry */ + u8 ssid[32]; + size_t ssid_len; unsigned int pairwise_cipher; unsigned int group_cipher; @@ -75,6 +76,7 @@ struct wpa_sm { struct install_key install_ptk; struct install_key install_gtk; + int mic_errors_seen; /* Michael MIC errors with the current PTK */ void (* sendto) (void *buffer, uint16_t len); void (*config_assoc_ie) (u8 proto, u8 *assoc_buf, u32 assoc_wpa_ie_len); diff --git a/components/wpa_supplicant/src/rsn_supp/wpa_ie.h b/components/wpa_supplicant/src/rsn_supp/wpa_ie.h index c71a926f2b..98ba648794 100644 --- a/components/wpa_supplicant/src/rsn_supp/wpa_ie.h +++ b/components/wpa_supplicant/src/rsn_supp/wpa_ie.h @@ -25,16 +25,6 @@ struct wpa_eapol_ie_parse { size_t gtk_len; const u8 *mac_addr; size_t mac_addr_len; -#ifdef CONFIG_PEERKEY - const u8 *smk; - size_t smk_len; - const u8 *nonce; - size_t nonce_len; - const u8 *lifetime; - size_t lifetime_len; - const u8 *error; - size_t error_len; -#endif /* CONFIG_PEERKEY */ #ifdef CONFIG_IEEE80211W const u8 *igtk; size_t igtk_len; diff --git a/examples/wifi/roaming/main/roaming_example.c b/examples/wifi/roaming/main/roaming_example.c index 7532d8d4da..2c1ec29bae 100644 --- a/examples/wifi/roaming/main/roaming_example.c +++ b/examples/wifi/roaming/main/roaming_example.c @@ -54,6 +54,17 @@ static void event_handler(void* arg, esp_event_base_t event_base, esp_wifi_set_rssi_threshold(EXAMPLE_WIFI_RSSI_THRESHOLD); } #endif + if (esp_rrm_is_rrm_supported_connection()) { + ESP_LOGI(TAG,"RRM supported"); + } else { + ESP_LOGI(TAG,"RRM not supported"); + } + if (esp_wnm_is_btm_supported_connection()) { + ESP_LOGI(TAG,"BTM supported"); + } else { + ESP_LOGI(TAG,"BTM not supported"); + } + } }