Lines Matching refs:sm

69 void wpa_sm_set_pmk_from_pmksa(struct wpa_sm *sm);
70 static bool wpa_supplicant_gtk_in_use(struct wpa_sm *sm, struct wpa_gtk_data *gd);
72 static inline enum wpa_states wpa_sm_get_state(struct wpa_sm *sm) in wpa_sm_get_state() argument
74 return sm->wpa_state;; in wpa_sm_get_state()
77 static inline void wpa_sm_cancel_auth_timeout(struct wpa_sm *sm) in wpa_sm_cancel_auth_timeout() argument
202 static inline int wpa_sm_get_bssid(struct wpa_sm *sm, u8 *bssid) in wpa_sm_get_bssid() argument
204 memcpy(bssid, sm->bssid, ETH_ALEN); in wpa_sm_get_bssid()
217 static inline int wpa_sm_ether_send(struct wpa_sm *sm, const u8 *dest, u16 proto, in wpa_sm_ether_send() argument
220 return wpa_ether_send(sm, dest, proto, data, data_len); in wpa_sm_ether_send()
235 void wpa_eapol_key_send(struct wpa_sm *sm, const u8 *kck, size_t kck_len, in wpa_eapol_key_send() argument
239 if (is_zero_ether_addr(dest) && is_zero_ether_addr(sm->bssid)) { in wpa_eapol_key_send()
244 if (wpa_sm_get_bssid(sm, sm->bssid) < 0) { in wpa_eapol_key_send()
248 dest = sm->bssid; in wpa_eapol_key_send()
255 wpa_eapol_key_mic(kck, kck_len, sm->key_mgmt, ver, msg, msg_len, in wpa_eapol_key_send()
259 ver, sm->key_mgmt); in wpa_eapol_key_send()
263 wpa_hexdump(MSG_DEBUG, "WPA: Derived Key MIC", key_mic, wpa_mic_len(sm->key_mgmt, sm->pmk_len)); in wpa_eapol_key_send()
265 wpa_sm_ether_send(sm, dest, proto, msg, msg_len); in wpa_eapol_key_send()
280 static void wpa_sm_key_request(struct wpa_sm *sm, int error, int pairwise) in wpa_sm_key_request() argument
288 if (sm->key_mgmt == WPA_KEY_MGMT_OSEN || wpa_key_mgmt_suite_b(sm->key_mgmt)) in wpa_sm_key_request()
290 else if (wpa_key_mgmt_ft(sm->key_mgmt) || wpa_key_mgmt_sha256(sm->key_mgmt)) in wpa_sm_key_request()
292 else if (sm->pairwise_cipher != WPA_CIPHER_TKIP) in wpa_sm_key_request()
294 else if (sm->key_mgmt == WPA_KEY_MGMT_SAE || sm->key_mgmt == WPA_KEY_MGMT_OWE) in wpa_sm_key_request()
299 if (wpa_sm_get_bssid(sm, bssid) < 0) { in wpa_sm_key_request()
305 mic_len = wpa_mic_len(sm->key_mgmt, sm->pmk_len); in wpa_sm_key_request()
307 rbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY, NULL, in wpa_sm_key_request()
314 reply->type = sm->proto == WPA_PROTO_RSN ? in wpa_sm_key_request()
317 if (sm->ptk_set) in wpa_sm_key_request()
319 if (sm->ptk_set && mic_len) in wpa_sm_key_request()
329 os_memcpy(reply->replay_counter, sm->request_counter, in wpa_sm_key_request()
331 inc_byte_array(sm->request_counter, WPA_REPLAY_COUNTER_LEN); in wpa_sm_key_request()
345 error, pairwise, sm->ptk_set, (unsigned long) rlen); in wpa_sm_key_request()
346 wpa_eapol_key_send(sm, sm->ptk.kck, sm->ptk.kck_len, ver, bssid, in wpa_sm_key_request()
354 struct wpa_sm *sm = ctx; in wpa_sm_pmksa_free_cb() local
360 if (sm->cur_pmksa == entry) { in wpa_sm_pmksa_free_cb()
364 pmksa_cache_clear_current(sm); in wpa_sm_pmksa_free_cb()
377 (sm->pmk_len == entry->pmk_len && in wpa_sm_pmksa_free_cb()
378 os_memcmp(sm->pmk, entry->pmk, sm->pmk_len) == 0)) { in wpa_sm_pmksa_free_cb()
381 pmksa_cache_clear_current(sm); in wpa_sm_pmksa_free_cb()
386 os_memset(sm->pmk, 0, sizeof(sm->pmk)); in wpa_sm_pmksa_free_cb()
387 wpa_sm_deauthenticate(sm, WLAN_REASON_UNSPECIFIED); in wpa_sm_pmksa_free_cb()
394 static int wpa_supplicant_get_pmk(struct wpa_sm *sm, in wpa_supplicant_get_pmk() argument
400 if (pmkid && !sm->cur_pmksa) { in wpa_supplicant_get_pmk()
405 sm->cur_pmksa = pmksa_cache_get(sm->pmksa, src_addr, pmkid, in wpa_supplicant_get_pmk()
407 if (sm->cur_pmksa) { in wpa_supplicant_get_pmk()
417 if (pmkid && sm->cur_pmksa && in wpa_supplicant_get_pmk()
418 os_memcmp_const(pmkid, sm->cur_pmksa->pmkid, PMKID_LEN) == 0) { in wpa_supplicant_get_pmk()
421 wpa_sm_set_pmk_from_pmksa(sm); in wpa_supplicant_get_pmk()
423 sm->pmk, sm->pmk_len); in wpa_supplicant_get_pmk()
426 sm->xxkey_len = 0; in wpa_supplicant_get_pmk()
428 if ((sm->key_mgmt == WPA_KEY_MGMT_FT_SAE) && in wpa_supplicant_get_pmk()
429 sm->pmk_len == PMK_LEN) { in wpa_supplicant_get_pmk()
435 os_memcpy(sm->xxkey, sm->pmk, sm->pmk_len); in wpa_supplicant_get_pmk()
436 sm->xxkey_len = sm->pmk_len; in wpa_supplicant_get_pmk()
441 } else if (wpa_key_mgmt_wpa_ieee8021x(sm->key_mgmt)) { in wpa_supplicant_get_pmk()
445 if (wpa_key_mgmt_sha384(sm->key_mgmt)) in wpa_supplicant_get_pmk()
450 if(!sm->pmk_len) { in wpa_supplicant_get_pmk()
457 "machines", sm->pmk, pmk_len); in wpa_supplicant_get_pmk()
458 sm->pmk_len = pmk_len; in wpa_supplicant_get_pmk()
460 if (sm->proto == WPA_PROTO_RSN && in wpa_supplicant_get_pmk()
461 !wpa_key_mgmt_suite_b(sm->key_mgmt) && in wpa_supplicant_get_pmk()
462 !wpa_key_mgmt_ft(sm->key_mgmt)) { in wpa_supplicant_get_pmk()
463 sa = pmksa_cache_add(sm->pmksa, sm->pmk, pmk_len, in wpa_supplicant_get_pmk()
464 NULL, NULL, 0, src_addr, sm->own_addr, in wpa_supplicant_get_pmk()
465 sm->network_ctx, sm->key_mgmt); in wpa_supplicant_get_pmk()
467 if (!sm->cur_pmksa && pmkid && in wpa_supplicant_get_pmk()
468 pmksa_cache_get(sm->pmksa, src_addr, pmkid, NULL)) in wpa_supplicant_get_pmk()
474 } else if (sa && !sm->cur_pmksa && pmkid) { in wpa_supplicant_get_pmk()
487 if (!sm->cur_pmksa) in wpa_supplicant_get_pmk()
488 sm->cur_pmksa = sa; in wpa_supplicant_get_pmk()
494 if (sm->cur_pmksa) { in wpa_supplicant_get_pmk()
498 sm->cur_pmksa = NULL; in wpa_supplicant_get_pmk()
506 if (abort_cached && wpa_key_mgmt_wpa_ieee8021x(sm->key_mgmt) && in wpa_supplicant_get_pmk()
507 !wpa_key_mgmt_suite_b(sm->key_mgmt) && in wpa_supplicant_get_pmk()
508 !wpa_key_mgmt_ft(sm->key_mgmt) && sm->key_mgmt != WPA_KEY_MGMT_OSEN) in wpa_supplicant_get_pmk()
517 buf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_START, in wpa_supplicant_get_pmk()
520 wpa_sm_ether_send(sm, sm->bssid, ETH_P_EAPOL, in wpa_supplicant_get_pmk()
545 int wpa_supplicant_send_2_of_4(struct wpa_sm *sm, const unsigned char *dst, in wpa_supplicant_send_2_of_4() argument
564 if (wpa_key_mgmt_ft(sm->key_mgmt)) { in wpa_supplicant_send_2_of_4()
574 sm->assoc_resp_ies_len); in wpa_supplicant_send_2_of_4()
579 sm->pmk_r1_name); in wpa_supplicant_send_2_of_4()
588 if (sm->assoc_resp_ies) { in wpa_supplicant_send_2_of_4()
590 sm->assoc_resp_ies, in wpa_supplicant_send_2_of_4()
591 sm->assoc_resp_ies_len); in wpa_supplicant_send_2_of_4()
592 os_memcpy(rsn_ie_buf + wpa_ie_len, sm->assoc_resp_ies, in wpa_supplicant_send_2_of_4()
593 sm->assoc_resp_ies_len); in wpa_supplicant_send_2_of_4()
594 wpa_ie_len += sm->assoc_resp_ies_len; in wpa_supplicant_send_2_of_4()
602 mic_len = wpa_mic_len(sm->key_mgmt, sm->pmk_len); in wpa_supplicant_send_2_of_4()
604 rbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY, in wpa_supplicant_send_2_of_4()
613 reply->type = sm->proto == WPA_PROTO_RSN ? in wpa_supplicant_send_2_of_4()
617 if (sm->proto == WPA_PROTO_RSN) in wpa_supplicant_send_2_of_4()
639 wpa_eapol_key_send(sm, ptk->kck, ptk->kck_len, ver, dst, ETH_P_EAPOL, in wpa_supplicant_send_2_of_4()
646 static int wpa_derive_ptk(struct wpa_sm *sm, const unsigned char *src_addr, in wpa_derive_ptk() argument
650 if (wpa_key_mgmt_ft(sm->key_mgmt)) in wpa_derive_ptk()
651 return wpa_derive_ptk_ft(sm, src_addr, key, ptk); in wpa_derive_ptk()
653 return wpa_pmk_to_ptk(sm->pmk, sm->pmk_len, "Pairwise key expansion", in wpa_derive_ptk()
654 sm->own_addr, sm->bssid, sm->snonce, in wpa_derive_ptk()
655 key->key_nonce, ptk, sm->key_mgmt, in wpa_derive_ptk()
656 sm->pairwise_cipher); in wpa_derive_ptk()
659 void wpa_supplicant_process_1_of_4(struct wpa_sm *sm, in wpa_supplicant_process_1_of_4() argument
688 if (sm->proto == WPA_PROTO_RSN) { in wpa_supplicant_process_1_of_4()
699 res = wpa_supplicant_get_pmk(sm, src_addr, ie.pmkid); in wpa_supplicant_process_1_of_4()
711 pmksa_cache_set_current(sm, NULL, sm->bssid, 0, 0); in wpa_supplicant_process_1_of_4()
715 if (sm->renew_snonce) { in wpa_supplicant_process_1_of_4()
716 if (os_get_random(sm->snonce, WPA_NONCE_LEN)) { in wpa_supplicant_process_1_of_4()
721 sm->renew_snonce = 0; in wpa_supplicant_process_1_of_4()
723 sm->snonce, WPA_NONCE_LEN); in wpa_supplicant_process_1_of_4()
728 ptk = &sm->tptk; in wpa_supplicant_process_1_of_4()
729 wpa_derive_ptk(sm, src_addr, key, ptk); in wpa_supplicant_process_1_of_4()
731 sm->tptk_set = 1; in wpa_supplicant_process_1_of_4()
732 sm->ptk_set = 0; in wpa_supplicant_process_1_of_4()
733 sm->key_install = true; in wpa_supplicant_process_1_of_4()
734 kde = sm->assoc_wpa_ie; in wpa_supplicant_process_1_of_4()
735 kde_len = sm->assoc_wpa_ie_len; in wpa_supplicant_process_1_of_4()
737 sm->assoc_rsnxe_len); in wpa_supplicant_process_1_of_4()
743 if (sm->assoc_rsnxe && sm->assoc_rsnxe_len) { in wpa_supplicant_process_1_of_4()
744 os_memcpy(kde + kde_len, sm->assoc_rsnxe, sm->assoc_rsnxe_len); in wpa_supplicant_process_1_of_4()
745 kde_len += sm->assoc_rsnxe_len; in wpa_supplicant_process_1_of_4()
748 if (wpa_supplicant_send_2_of_4(sm, sm->bssid, key, ver, sm->snonce, in wpa_supplicant_process_1_of_4()
753 memcpy(sm->anonce, key->key_nonce, WPA_NONCE_LEN); in wpa_supplicant_process_1_of_4()
758 wpa_sm_deauthenticate(sm, WLAN_REASON_UNSPECIFIED); in wpa_supplicant_process_1_of_4()
763 struct wpa_sm *sm = eloop_ctx; in wpa_sm_rekey_ptk() local
766 wpa_sm_key_request(sm, 0, 1); in wpa_sm_rekey_ptk()
770 static int wpa_supplicant_install_ptk(struct wpa_sm *sm, enum key_flag key_flag) in wpa_supplicant_install_ptk() argument
775 if (sm->ptk.installed) { in wpa_supplicant_install_ptk()
781 if (sm->pairwise_cipher == WPA_CIPHER_NONE) { in wpa_supplicant_install_ptk()
786 if (!wpa_cipher_valid_pairwise(sm->pairwise_cipher)) { in wpa_supplicant_install_ptk()
787 wpa_printf(MSG_DEBUG, "WPA: Unsupported pairwise cipher %d", sm->pairwise_cipher); in wpa_supplicant_install_ptk()
791 alg = wpa_cipher_to_alg(sm->pairwise_cipher); in wpa_supplicant_install_ptk()
792 keylen = wpa_cipher_key_len(sm->pairwise_cipher); in wpa_supplicant_install_ptk()
799 …if (wpa_sm_set_key(&(sm->install_ptk), alg, sm->bssid, 0, 1, (sm->install_ptk).seq, WPA_KEY_RSC_LE… in wpa_supplicant_install_ptk()
800 sm->ptk.tk, keylen, KEY_FLAG_PAIRWISE | key_flag) < 0) { in wpa_supplicant_install_ptk()
803 alg, keylen, MAC2STR(sm->bssid)); in wpa_supplicant_install_ptk()
807 sm->ptk.installed = 1; in wpa_supplicant_install_ptk()
809 if (sm->wpa_ptk_rekey) { in wpa_supplicant_install_ptk()
810 eloop_cancel_timeout(wpa_sm_rekey_ptk, sm, NULL); in wpa_supplicant_install_ptk()
811 eloop_register_timeout(sm->wpa_ptk_rekey, 0, wpa_sm_rekey_ptk, in wpa_supplicant_install_ptk()
812 sm, NULL); in wpa_supplicant_install_ptk()
818 static int wpa_supplicant_check_group_cipher(struct wpa_sm *sm, in wpa_supplicant_check_group_cipher() argument
845 void wpa_supplicant_key_neg_complete(struct wpa_sm *sm, in wpa_supplicant_key_neg_complete() argument
850 wpa_cipher_txt(sm->pairwise_cipher), in wpa_supplicant_key_neg_complete()
851 wpa_cipher_txt(sm->group_cipher)); in wpa_supplicant_key_neg_complete()
852 wpa_sm_cancel_auth_timeout(sm); in wpa_supplicant_key_neg_complete()
856 sm->eapol1_count = 0; in wpa_supplicant_key_neg_complete()
857 sm->use_ext_key_id = 0; in wpa_supplicant_key_neg_complete()
861 sm, addr, MLME_SETPROTECTION_PROTECT_TYPE_RX_TX, in wpa_supplicant_key_neg_complete()
864 if (wpa_key_mgmt_wpa_psk(sm->key_mgmt) || sm->key_mgmt == WPA_KEY_MGMT_OWE) in wpa_supplicant_key_neg_complete()
875 if (wpa_key_mgmt_ft(sm->key_mgmt)) { in wpa_supplicant_key_neg_complete()
877 wpa_ft_prepare_auth_request(sm, NULL); in wpa_supplicant_key_neg_complete()
878 sm->ft_protocol = 1; in wpa_supplicant_key_neg_complete()
883 static int wpa_supplicant_install_gtk(struct wpa_sm *sm, in wpa_supplicant_install_gtk() argument
888 u8 *key_rsc=(sm->install_gtk).seq; in wpa_supplicant_install_gtk()
893 if ((sm->gtk.gtk_len == (size_t) gd->gtk_len && in wpa_supplicant_install_gtk()
894 os_memcmp(sm->gtk.gtk, gd->gtk, sm->gtk.gtk_len) == 0) || in wpa_supplicant_install_gtk()
895 wpa_supplicant_gtk_in_use(sm, &(sm->gd))) { in wpa_supplicant_install_gtk()
906 if (sm->group_cipher == WPA_CIPHER_TKIP) { in wpa_supplicant_install_gtk()
913 if (sm->pairwise_cipher == WPA_CIPHER_NONE) { in wpa_supplicant_install_gtk()
914 if (wpa_sm_set_key(&(sm->install_gtk), gd->alg, in wpa_supplicant_install_gtk()
915 sm->bssid, //(u8 *) "\xff\xff\xff\xff\xff\xff", in wpa_supplicant_install_gtk()
922 } else if (wpa_sm_set_key(&(sm->install_gtk), gd->alg, in wpa_supplicant_install_gtk()
923 sm->bssid, //(u8 *) "\xff\xff\xff\xff\xff\xff", in wpa_supplicant_install_gtk()
931 sm->gtk.gtk_len = gd->gtk_len; in wpa_supplicant_install_gtk()
932 os_memcpy(sm->gtk.gtk, gd->gtk, sm->gtk.gtk_len); in wpa_supplicant_install_gtk()
937 static bool wpa_supplicant_gtk_in_use(struct wpa_sm *sm, struct wpa_gtk_data *gd) in wpa_supplicant_gtk_in_use() argument
949 if (sm->group_cipher == WPA_CIPHER_TKIP) { in wpa_supplicant_gtk_in_use()
958 if (ifx == 0 && alg == gd->alg && memcmp(bssid, sm->bssid, ETH_ALEN) == 0 && in wpa_supplicant_gtk_in_use()
968 int wpa_supplicant_gtk_tx_bit_workaround(const struct wpa_sm *sm, in wpa_supplicant_gtk_tx_bit_workaround() argument
971 if (tx && sm->pairwise_cipher != WPA_CIPHER_NONE) { in wpa_supplicant_gtk_tx_bit_workaround()
984 int wpa_supplicant_pairwise_gtk(struct wpa_sm *sm, in wpa_supplicant_pairwise_gtk() argument
988 struct wpa_gtk_data *gd=&(sm->gd); in wpa_supplicant_pairwise_gtk()
1006 gd->tx = wpa_supplicant_gtk_tx_bit_workaround(sm, in wpa_supplicant_pairwise_gtk()
1014 if (wpa_supplicant_check_group_cipher(sm, sm->group_cipher, in wpa_supplicant_pairwise_gtk()
1024 static int wpa_supplicant_install_igtk(struct wpa_sm *sm, in wpa_supplicant_install_igtk() argument
1027 size_t len = wpa_cipher_key_len(sm->mgmt_group_cipher); in wpa_supplicant_install_igtk()
1031 if (sm->igtk.igtk_len == len && in wpa_supplicant_install_igtk()
1032 os_memcmp(sm->igtk.igtk, igtk->igtk, sm->igtk.igtk_len) == 0) { in wpa_supplicant_install_igtk()
1054 sm->igtk.igtk_len = len; in wpa_supplicant_install_igtk()
1055 os_memcpy(sm->igtk.igtk, igtk->igtk, sm->igtk.igtk_len); in wpa_supplicant_install_igtk()
1062 void wpa_report_ie_mismatch(struct wpa_sm *sm, in wpa_report_ie_mismatch() argument
1067 void wpa_report_ie_mismatch(struct wpa_sm *sm, const u8 *src_addr, in wpa_report_ie_mismatch()
1074 if (sm->ap_wpa_ie) { in wpa_report_ie_mismatch()
1076 sm->ap_wpa_ie, sm->ap_wpa_ie_len); in wpa_report_ie_mismatch()
1079 if (!sm->ap_wpa_ie) { in wpa_report_ie_mismatch()
1087 if (sm->ap_rsn_ie) { in wpa_report_ie_mismatch()
1089 sm->ap_rsn_ie, sm->ap_rsn_ie_len); in wpa_report_ie_mismatch()
1092 if (!sm->ap_rsn_ie) { in wpa_report_ie_mismatch()
1100 wpa_sm_disassociate(sm, WLAN_REASON_IE_IN_4WAY_DIFFERS); in wpa_report_ie_mismatch()
1103 static int ieee80211w_set_keys(struct wpa_sm *sm, in ieee80211w_set_keys() argument
1109 if (!wpa_cipher_valid_mgmt_group(sm->mgmt_group_cipher)) in ieee80211w_set_keys()
1115 len = wpa_cipher_key_len(sm->mgmt_group_cipher); in ieee80211w_set_keys()
1121 if (wpa_supplicant_install_igtk(sm, igtk) < 0) { in ieee80211w_set_keys()
1129 static int wpa_supplicant_validate_ie(struct wpa_sm *sm, in wpa_supplicant_validate_ie() argument
1134 (sm->ap_wpa_ie || sm->ap_rsn_ie)) { in wpa_supplicant_validate_ie()
1136 wpa_report_ie_mismatch(sm, "IE in 3/4 msg does not match " in wpa_supplicant_validate_ie()
1141 wpa_report_ie_mismatch(sm, in wpa_supplicant_validate_ie()
1148 if ((ie->wpa_ie && sm->ap_wpa_ie && in wpa_supplicant_validate_ie()
1149 (ie->wpa_ie_len != sm->ap_wpa_ie_len || in wpa_supplicant_validate_ie()
1150 memcmp(ie->wpa_ie, sm->ap_wpa_ie, ie->wpa_ie_len) != 0)) || in wpa_supplicant_validate_ie()
1151 (ie->rsn_ie && sm->ap_rsn_ie && in wpa_supplicant_validate_ie()
1152 wpa_compare_rsn_ie(wpa_key_mgmt_ft(sm->key_mgmt), in wpa_supplicant_validate_ie()
1153 sm->ap_rsn_ie, sm->ap_rsn_ie_len, in wpa_supplicant_validate_ie()
1156 wpa_report_ie_mismatch(sm, "IE in 3/4 msg does not match " in wpa_supplicant_validate_ie()
1161 wpa_report_ie_mismatch(sm, in wpa_supplicant_validate_ie()
1168 if (sm->proto == WPA_PROTO_WPA && in wpa_supplicant_validate_ie()
1169 ie->rsn_ie && sm->ap_rsn_ie == NULL && sm->rsn_enabled) { in wpa_supplicant_validate_ie()
1171 wpa_report_ie_mismatch(sm, "Possible downgrade attack " in wpa_supplicant_validate_ie()
1178 wpa_report_ie_mismatch(sm, in wpa_supplicant_validate_ie()
1185 if (sm->proto == WPA_PROTO_RSN && in wpa_supplicant_validate_ie()
1186 ((sm->ap_rsnxe && !ie->rsnxe) || in wpa_supplicant_validate_ie()
1187 (!sm->ap_rsnxe && ie->rsnxe) || in wpa_supplicant_validate_ie()
1188 (sm->ap_rsnxe && ie->rsnxe && in wpa_supplicant_validate_ie()
1189 (sm->ap_rsnxe_len != ie->rsnxe_len || in wpa_supplicant_validate_ie()
1190 os_memcmp(sm->ap_rsnxe, ie->rsnxe, sm->ap_rsnxe_len) != 0)))) { in wpa_supplicant_validate_ie()
1194 sm->ap_rsnxe, sm->ap_rsnxe_len); in wpa_supplicant_validate_ie()
1197 wpa_sm_deauthenticate(sm, WLAN_REASON_IE_IN_4WAY_DIFFERS); in wpa_supplicant_validate_ie()
1214 static int wpa_supplicant_send_4_of_4(struct wpa_sm *sm, const unsigned char *dst, in wpa_supplicant_send_4_of_4() argument
1224 mic_len = wpa_mic_len(sm->key_mgmt, sm->pmk_len); in wpa_supplicant_send_4_of_4()
1227 rbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY, NULL, in wpa_supplicant_send_4_of_4()
1233 sm->txcb_flags |= WPA_4_4_HANDSHAKE_BIT; in wpa_supplicant_send_4_of_4()
1234 wpa_printf(MSG_DEBUG, "tx 4/4 txcb_flags=%d", sm->txcb_flags); in wpa_supplicant_send_4_of_4()
1237 reply->type = sm->proto == WPA_PROTO_RSN ? in wpa_supplicant_send_4_of_4()
1242 if (sm->proto == WPA_PROTO_RSN) in wpa_supplicant_send_4_of_4()
1256 wpa_eapol_key_send(sm, ptk->kck, ptk->kck_len, ver, dst, ETH_P_EAPOL, in wpa_supplicant_send_4_of_4()
1263 static void wpa_sm_set_seq(struct wpa_sm *sm, struct wpa_eapol_key *key, u8 isptk) in wpa_sm_set_seq() argument
1270 if (sm->proto == WPA_PROTO_RSN && isptk) { in wpa_sm_set_seq()
1277 seq=(isptk) ? (sm->install_ptk).seq : (sm->install_gtk).seq; in wpa_sm_set_seq()
1281 static void wpa_supplicant_process_3_of_4(struct wpa_sm *sm, in wpa_supplicant_process_3_of_4() argument
1296 if (wpa_supplicant_validate_ie(sm, sm->bssid, &ie) < 0) in wpa_supplicant_process_3_of_4()
1305 if (memcmp(sm->anonce, key->key_nonce, WPA_NONCE_LEN) != 0) { in wpa_supplicant_process_3_of_4()
1308 " packet (src=" MACSTR ")", MAC2STR(sm->bssid)); in wpa_supplicant_process_3_of_4()
1313 switch (sm->pairwise_cipher) { in wpa_supplicant_process_3_of_4()
1318 keylen, MAC2STR(sm->bssid)); in wpa_supplicant_process_3_of_4()
1326 keylen, MAC2STR(sm->bssid)); in wpa_supplicant_process_3_of_4()
1336 sm->renew_snonce = 1; in wpa_supplicant_process_3_of_4()
1339 wpa_sm_set_seq(sm, key, 1); in wpa_supplicant_process_3_of_4()
1340 sm->key_info=key_info; in wpa_supplicant_process_3_of_4()
1341 (sm->gd).gtk_len=0; //used as flag if gtk is installed in callback in wpa_supplicant_process_3_of_4()
1343 wpa_sm_set_seq(sm, key, 0); in wpa_supplicant_process_3_of_4()
1344 if (wpa_supplicant_pairwise_gtk(sm, in wpa_supplicant_process_3_of_4()
1351 if (sm->pmf_cfg.capable && ieee80211w_set_keys(sm, &ie) < 0) { in wpa_supplicant_process_3_of_4()
1357 wpa_supplicant_transition_disable(sm, ie.transition_disable[0]); in wpa_supplicant_process_3_of_4()
1360 if (sm->key_install && sm->key_info & WPA_KEY_INFO_INSTALL && sm->use_ext_key_id) { in wpa_supplicant_process_3_of_4()
1361 wpa_supplicant_install_ptk(sm, KEY_FLAG_RX); in wpa_supplicant_process_3_of_4()
1364 if (wpa_supplicant_send_4_of_4(sm, sm->bssid, key, ver, key_info, in wpa_supplicant_process_3_of_4()
1365 &sm->ptk)) { in wpa_supplicant_process_3_of_4()
1372 wpa_sm_deauthenticate(sm, WLAN_REASON_UNSPECIFIED); in wpa_supplicant_process_3_of_4()
1375 static int wpa_supplicant_activate_ptk(struct wpa_sm *sm) in wpa_supplicant_activate_ptk() argument
1380 alg = wpa_cipher_to_alg(sm->pairwise_cipher); in wpa_supplicant_activate_ptk()
1381 keylen = wpa_cipher_key_len(sm->pairwise_cipher); in wpa_supplicant_activate_ptk()
1391 MAC2STR(sm->bssid)); in wpa_supplicant_activate_ptk()
1393 if (wpa_sm_set_key(&(sm->install_ptk), alg, sm->bssid, 0, 1, (sm->install_ptk).seq, in wpa_supplicant_activate_ptk()
1394 WPA_KEY_RSC_LEN, sm->ptk.tk, keylen, in wpa_supplicant_activate_ptk()
1398 MACSTR ")", 0, MAC2STR(sm->bssid)); in wpa_supplicant_activate_ptk()
1404 static int wpa_supplicant_send_4_of_4_txcallback(struct wpa_sm *sm) in wpa_supplicant_send_4_of_4_txcallback() argument
1406 u16 key_info=sm->key_info; in wpa_supplicant_send_4_of_4_txcallback()
1408 if (sm->key_install && key_info & WPA_KEY_INFO_INSTALL) { in wpa_supplicant_send_4_of_4_txcallback()
1409 if (sm->use_ext_key_id) { in wpa_supplicant_send_4_of_4_txcallback()
1410 if (wpa_supplicant_activate_ptk(sm)) in wpa_supplicant_send_4_of_4_txcallback()
1413 if (wpa_supplicant_install_ptk(sm, KEY_FLAG_TX | KEY_FLAG_RX)) in wpa_supplicant_send_4_of_4_txcallback()
1417 else if (sm->key_install == false) { in wpa_supplicant_send_4_of_4_txcallback()
1423 if ((sm->gd).gtk_len) { in wpa_supplicant_send_4_of_4_txcallback()
1424 if (sm->key_install) { in wpa_supplicant_send_4_of_4_txcallback()
1425 if (wpa_supplicant_install_gtk(sm, &(sm->gd))) in wpa_supplicant_send_4_of_4_txcallback()
1431 wpa_supplicant_key_neg_complete(sm, sm->bssid, in wpa_supplicant_send_4_of_4_txcallback()
1437 sm, sm->bssid, MLME_SETPROTECTION_PROTECT_TYPE_RX, in wpa_supplicant_send_4_of_4_txcallback()
1441 sm->key_install = false; in wpa_supplicant_send_4_of_4_txcallback()
1449 if (sm->proto == WPA_PROTO_RSN && wpa_key_mgmt_suite_b(sm->key_mgmt) && in wpa_supplicant_send_4_of_4_txcallback()
1450 !sm->cur_pmksa) { in wpa_supplicant_send_4_of_4_txcallback()
1453 sa = pmksa_cache_add(sm->pmksa, sm->pmk, sm->pmk_len, NULL, in wpa_supplicant_send_4_of_4_txcallback()
1454 sm->ptk.kck, sm->ptk.kck_len, in wpa_supplicant_send_4_of_4_txcallback()
1455 sm->bssid, sm->own_addr, in wpa_supplicant_send_4_of_4_txcallback()
1456 sm->network_ctx, sm->key_mgmt); in wpa_supplicant_send_4_of_4_txcallback()
1457 if (!sm->cur_pmksa) in wpa_supplicant_send_4_of_4_txcallback()
1458 sm->cur_pmksa = sa; in wpa_supplicant_send_4_of_4_txcallback()
1468 static int wpa_supplicant_process_1_of_2_rsn(struct wpa_sm *sm, in wpa_supplicant_process_1_of_2_rsn() argument
1489 if (wpa_supplicant_check_group_cipher(sm, sm->group_cipher, in wpa_supplicant_process_1_of_2_rsn()
1497 gd->tx = wpa_supplicant_gtk_tx_bit_workaround(sm, in wpa_supplicant_process_1_of_2_rsn()
1506 if (ieee80211w_set_keys(sm, &ie) < 0) in wpa_supplicant_process_1_of_2_rsn()
1513 static int wpa_supplicant_process_1_of_2_wpa(struct wpa_sm *sm, in wpa_supplicant_process_1_of_2_wpa() argument
1533 if (wpa_supplicant_check_group_cipher(sm, sm->group_cipher, in wpa_supplicant_process_1_of_2_wpa()
1540 if (ver == WPA_KEY_INFO_TYPE_HMAC_MD5_RC4 && sm->ptk.kek_len == 16) { in wpa_supplicant_process_1_of_2_wpa()
1542 os_memcpy(ek + 16, sm->ptk.kek, sm->ptk.kek_len); in wpa_supplicant_process_1_of_2_wpa()
1568 if (aes_unwrap(sm->ptk.kek, sm->ptk.kek_len, maxkeylen / 8, key_data, gd->gtk)) { in wpa_supplicant_process_1_of_2_wpa()
1579 sm, !!(key_info & WPA_KEY_INFO_TXRX)); in wpa_supplicant_process_1_of_2_wpa()
1584 static int wpa_supplicant_send_2_of_2(struct wpa_sm *sm, in wpa_supplicant_send_2_of_2() argument
1593 mic_len = wpa_mic_len(sm->key_mgmt, sm->pmk_len); in wpa_supplicant_send_2_of_2()
1596 rbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY, NULL, in wpa_supplicant_send_2_of_2()
1601 sm->txcb_flags |= WPA_GROUP_HANDSHAKE_BIT; in wpa_supplicant_send_2_of_2()
1602 wpa_printf(MSG_DEBUG, "2/2 txcb_flags=%d", sm->txcb_flags); in wpa_supplicant_send_2_of_2()
1605 reply->type = sm->proto == WPA_PROTO_RSN ? in wpa_supplicant_send_2_of_2()
1610 if (sm->proto == WPA_PROTO_RSN) in wpa_supplicant_send_2_of_2()
1625 wpa_eapol_key_send(sm, sm->ptk.kck, sm->ptk.kck_len, ver, sm->bssid, ETH_P_EAPOL, in wpa_supplicant_send_2_of_2()
1632 static void wpa_supplicant_process_1_of_2(struct wpa_sm *sm, in wpa_supplicant_process_1_of_2() argument
1640 struct wpa_gtk_data *gd=&(sm->gd); in wpa_supplicant_process_1_of_2()
1648 if (sm->proto == WPA_PROTO_RSN) { in wpa_supplicant_process_1_of_2()
1649 ret = wpa_supplicant_process_1_of_2_rsn(sm, key_data, in wpa_supplicant_process_1_of_2()
1652 ret = wpa_supplicant_process_1_of_2_wpa(sm, key, key_data, in wpa_supplicant_process_1_of_2()
1662 wpa_sm_set_seq(sm, key, 0); in wpa_supplicant_process_1_of_2()
1663 sm->key_info=key_info; in wpa_supplicant_process_1_of_2()
1666 if((sm->gd).gtk_len) { in wpa_supplicant_process_1_of_2()
1667 if (wpa_supplicant_install_gtk(sm, &(sm->gd))) in wpa_supplicant_process_1_of_2()
1673 if (wpa_supplicant_send_2_of_2(sm, key, ver, key_info)) in wpa_supplicant_process_1_of_2()
1676 if (WPA_SM_STATE(sm) == WPA_COMPLETED) { in wpa_supplicant_process_1_of_2()
1680 MAC2STR(sm->bssid), wpa_cipher_txt(sm->group_cipher)); in wpa_supplicant_process_1_of_2()
1682 wpa_sm_cancel_auth_timeout(sm); in wpa_supplicant_process_1_of_2()
1685 wpa_supplicant_key_neg_complete(sm, sm->bssid, in wpa_supplicant_process_1_of_2()
1686 sm->key_info &WPA_KEY_INFO_SECURE); in wpa_supplicant_process_1_of_2()
1692 wpa_sm_deauthenticate(sm, WLAN_REASON_UNSPECIFIED); in wpa_supplicant_process_1_of_2()
1695 static int wpa_supplicant_verify_eapol_key_mic(struct wpa_sm *sm, in wpa_supplicant_verify_eapol_key_mic() argument
1702 size_t mic_len = wpa_mic_len(sm->key_mgmt, sm->pmk_len); in wpa_supplicant_verify_eapol_key_mic()
1705 if (sm->tptk_set) { in wpa_supplicant_verify_eapol_key_mic()
1707 wpa_eapol_key_mic(sm->tptk.kck, sm->tptk.kck_len, sm->key_mgmt, in wpa_supplicant_verify_eapol_key_mic()
1714 sm->tptk_set = 0; in wpa_supplicant_verify_eapol_key_mic()
1715 sm->ptk_set = 1; in wpa_supplicant_verify_eapol_key_mic()
1716 memcpy(&sm->ptk, &sm->tptk, sizeof(sm->ptk)); in wpa_supplicant_verify_eapol_key_mic()
1720 if (!ok && sm->ptk_set) { in wpa_supplicant_verify_eapol_key_mic()
1722 wpa_eapol_key_mic(sm->ptk.kck, sm->ptk.kck_len, sm->key_mgmt, in wpa_supplicant_verify_eapol_key_mic()
1738 memcpy(sm->rx_replay_counter, key->replay_counter, in wpa_supplicant_verify_eapol_key_mic()
1740 sm->rx_replay_counter_set = 1; in wpa_supplicant_verify_eapol_key_mic()
1742 memcpy(sm->request_counter, key->replay_counter, in wpa_supplicant_verify_eapol_key_mic()
1749 static int wpa_supplicant_decrypt_key_data(struct wpa_sm *sm, in wpa_supplicant_decrypt_key_data() argument
1755 if (!sm->ptk_set) { in wpa_supplicant_decrypt_key_data()
1763 if (ver == WPA_KEY_INFO_TYPE_HMAC_MD5_RC4 && sm->ptk.kek_len == 16) { in wpa_supplicant_decrypt_key_data()
1766 os_memcpy(ek + 16, sm->ptk.kek, sm->ptk.kek_len); in wpa_supplicant_decrypt_key_data()
1773 wpa_use_aes_key_wrap(sm->key_mgmt)) { in wpa_supplicant_decrypt_key_data()
1792 if (aes_unwrap(sm->ptk.kek, sm->ptk.kek_len, *key_data_len / 8, in wpa_supplicant_decrypt_key_data()
1811 static void wpa_eapol_key_dump(struct wpa_sm *sm, in wpa_eapol_key_dump() argument
1865 struct wpa_sm *sm = &gWpaSm; in wpa_sm_rx_eapol() local
1876 mic_len = wpa_mic_len(sm->key_mgmt, sm->pmk_len); in wpa_sm_rx_eapol()
1942 !wpa_use_akm_defined(sm->key_mgmt)) { in wpa_sm_rx_eapol()
1947 if (wpa_use_akm_defined(sm->key_mgmt) && in wpa_sm_rx_eapol()
1956 if (wpa_key_mgmt_sha256(sm->key_mgmt)) { in wpa_sm_rx_eapol()
1958 !wpa_use_akm_defined(sm->key_mgmt)) { in wpa_sm_rx_eapol()
1964 if (sm->pairwise_cipher == WPA_CIPHER_CCMP && in wpa_sm_rx_eapol()
1965 !wpa_use_akm_defined(sm->key_mgmt) && in wpa_sm_rx_eapol()
1969 if (sm->group_cipher != WPA_CIPHER_CCMP && in wpa_sm_rx_eapol()
1986 if (sm->pairwise_cipher == WPA_CIPHER_GCMP && in wpa_sm_rx_eapol()
1987 !wpa_use_akm_defined(sm->key_mgmt) && in wpa_sm_rx_eapol()
1996 if (sm->rx_replay_counter_set && in wpa_sm_rx_eapol()
1997 os_memcmp(key->replay_counter, sm->rx_replay_counter, in wpa_sm_rx_eapol()
2015 wpa_supplicant_verify_eapol_key_mic(sm, key192, ver, tmp, data_len)) in wpa_sm_rx_eapol()
2024 wpa_eapol_key_dump(sm, key, key_data_len, key192->key_mic, mic_len); in wpa_sm_rx_eapol()
2035 if (sm->proto == WPA_PROTO_RSN && in wpa_sm_rx_eapol()
2044 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_sm_rx_eapol()
2048 if (wpa_supplicant_decrypt_key_data(sm, key, ver, key_data, in wpa_sm_rx_eapol()
2062 wpa_supplicant_process_3_of_4(sm, key, ver, key_data, in wpa_sm_rx_eapol()
2066 sm->eapol1_count++; in wpa_sm_rx_eapol()
2067 if (sm->eapol1_count > MAX_EAPOL_RETRIES) { in wpa_sm_rx_eapol()
2068 … wpa_printf(MSG_INFO, "EAPOL1 received for %d times, sending deauth", sm->eapol1_count); in wpa_sm_rx_eapol()
2072 wpa_supplicant_process_1_of_4(sm, src_addr, key, in wpa_sm_rx_eapol()
2079 wpa_supplicant_process_1_of_2(sm, src_addr, key, in wpa_sm_rx_eapol()
2105 struct wpa_sm *sm = &gWpaSm; in wpa_sm_set_state() local
2106 if(WPA_MIC_FAILURE==WPA_SM_STATE(sm)) in wpa_sm_set_state()
2108 sm->wpa_state= state; in wpa_sm_set_state()
2121 void wpa_sm_set_pmk(struct wpa_sm *sm, const u8 *pmk, size_t pmk_len, in wpa_sm_set_pmk() argument
2124 if (sm == NULL) in wpa_sm_set_pmk()
2127 sm->pmk_len = pmk_len; in wpa_sm_set_pmk()
2128 os_memcpy(sm->pmk, pmk, pmk_len); in wpa_sm_set_pmk()
2132 sm->xxkey_len = pmk_len; in wpa_sm_set_pmk()
2133 os_memcpy(sm->xxkey, pmk, pmk_len); in wpa_sm_set_pmk()
2137 pmksa_cache_add(sm->pmksa, pmk, pmk_len, pmkid, NULL, 0, in wpa_sm_set_pmk()
2138 bssid, sm->own_addr, in wpa_sm_set_pmk()
2139 sm->network_ctx, sm->key_mgmt); in wpa_sm_set_pmk()
2151 void wpa_sm_set_pmk_from_pmksa(struct wpa_sm *sm) in wpa_sm_set_pmk_from_pmksa() argument
2153 if (sm == NULL) in wpa_sm_set_pmk_from_pmksa()
2156 if (sm->cur_pmksa) { in wpa_sm_set_pmk_from_pmksa()
2157 sm->pmk_len = sm->cur_pmksa->pmk_len; in wpa_sm_set_pmk_from_pmksa()
2158 os_memcpy(sm->pmk, sm->cur_pmksa->pmk, sm->pmk_len); in wpa_sm_set_pmk_from_pmksa()
2160 sm->pmk_len = PMK_LEN_MAX; in wpa_sm_set_pmk_from_pmksa()
2161 os_memset(sm->pmk, 0, PMK_LEN_MAX); in wpa_sm_set_pmk_from_pmksa()
2168 struct wpa_sm *sm = &gWpaSm; in wpa_sm_init() local
2171 os_memset(sm, 0, sizeof(struct wpa_sm)); in wpa_sm_init()
2173 sm->eapol_version = DEFAULT_EAPOL_VERSION; /* DEFAULT_EAPOL_VERSION */ in wpa_sm_init()
2176sm->spp_sup.capable = ((spp_attrubute & WPA_CAPABILITY_SPP_CAPABLE) ? SPP_AMSDU_CAP_ENABLE : SPP_A… in wpa_sm_init()
2177sm->spp_sup.require = ((spp_attrubute & WPA_CAPABILITY_SPP_REQUIRED) ? SPP_AMSDU_REQ_ENABLE : SPP_… in wpa_sm_init()
2181 sm->pmksa = pmksa_cache_init(wpa_sm_pmksa_free_cb, sm, sm); in wpa_sm_init()
2182 if (sm->pmksa == NULL) { in wpa_sm_init()
2195 struct wpa_sm *sm = &gWpaSm; in wpa_sm_deinit() local
2196 pmksa_cache_deinit(sm->pmksa); in wpa_sm_deinit()
2197 os_free(sm->ap_rsnxe); in wpa_sm_deinit()
2198 sm->ap_rsnxe = NULL; in wpa_sm_deinit()
2199 os_free(sm->assoc_rsnxe); in wpa_sm_deinit()
2200 wpa_sm_drop_sa(sm); in wpa_sm_deinit()
2201 sm->assoc_rsnxe = NULL; in wpa_sm_deinit()
2214 void wpa_sm_notify_assoc(struct wpa_sm *sm, const u8 *bssid) in wpa_sm_notify_assoc() argument
2218 if (sm == NULL) in wpa_sm_notify_assoc()
2223 os_memcpy(sm->bssid, bssid, ETH_ALEN); in wpa_sm_notify_assoc()
2224 os_memset(sm->rx_replay_counter, 0, WPA_REPLAY_COUNTER_LEN); in wpa_sm_notify_assoc()
2225 sm->rx_replay_counter_set = 0; in wpa_sm_notify_assoc()
2226 sm->renew_snonce = 1; in wpa_sm_notify_assoc()
2229 if (wpa_ft_is_completed(sm)) { in wpa_sm_notify_assoc()
2234 wpa_supplicant_key_neg_complete(sm, sm->bssid, 1); in wpa_sm_notify_assoc()
2237 wpa_ft_prepare_auth_request(sm, NULL); in wpa_sm_notify_assoc()
2240 sm->ft_protocol = 1; in wpa_sm_notify_assoc()
2242 sm->ft_protocol = 0; in wpa_sm_notify_assoc()
2251 sm->ptk_set = 0; in wpa_sm_notify_assoc()
2252 os_memset(&sm->ptk, 0, sizeof(sm->ptk)); in wpa_sm_notify_assoc()
2253 sm->tptk_set = 0; in wpa_sm_notify_assoc()
2254 os_memset(&sm->tptk, 0, sizeof(sm->tptk)); in wpa_sm_notify_assoc()
2255 os_memset(&sm->gtk, 0, sizeof(sm->gtk)); in wpa_sm_notify_assoc()
2256 os_memset(&sm->igtk, 0, sizeof(sm->igtk)); in wpa_sm_notify_assoc()
2268 void wpa_sm_notify_disassoc(struct wpa_sm *sm) in wpa_sm_notify_disassoc() argument
2270 eloop_cancel_timeout(wpa_sm_rekey_ptk, sm, NULL); in wpa_sm_notify_disassoc()
2271 pmksa_cache_clear_current(sm); in wpa_sm_notify_disassoc()
2273 sm->ft_reassoc_completed = 0; in wpa_sm_notify_disassoc()
2274 sm->ft_protocol = 0; in wpa_sm_notify_disassoc()
2278 wpa_sm_drop_sa(sm); in wpa_sm_notify_disassoc()
2280 os_memset(sm->bssid, 0, ETH_ALEN); in wpa_sm_notify_disassoc()
2286 struct wpa_sm *sm = &gWpaSm; in wpa_set_profile() local
2288 sm->proto = wpa_proto; in wpa_set_profile()
2290 sm->key_mgmt = WPA_KEY_MGMT_IEEE8021X; /* for wpa2 enterprise */ in wpa_set_profile()
2292 sm->key_mgmt = WPA_KEY_MGMT_IEEE8021X_SHA256; /* for wpa2 enterprise sha256 */ in wpa_set_profile()
2294 sm->key_mgmt = WPA_KEY_MGMT_PSK_SHA256; in wpa_set_profile()
2296 sm->key_mgmt = WPA_KEY_MGMT_SAE; /* for WPA3 PSK */ in wpa_set_profile()
2298 sm->key_mgmt = WPA_KEY_MGMT_WAPI_PSK; /* for WAPI PSK */ in wpa_set_profile()
2300 sm->key_mgmt = WPA_KEY_MGMT_IEEE8021X_SUITE_B_192; in wpa_set_profile()
2302 sm->key_mgmt = WPA_KEY_MGMT_FT_PSK; in wpa_set_profile()
2304 sm->key_mgmt = WPA_KEY_MGMT_OWE; in wpa_set_profile()
2306 sm->key_mgmt = WPA_KEY_MGMT_PSK; /* fixed to PSK for now */ in wpa_set_profile()
2312 struct wpa_sm *sm = &gWpaSm; in wpa_set_pmk() local
2315 if (wpa_key_mgmt_sha384(sm->key_mgmt)) in wpa_set_pmk()
2317 else if (wpa_key_mgmt_sae(sm->key_mgmt)) in wpa_set_pmk()
2322 memcpy(sm->pmk, pmk, pmk_len); in wpa_set_pmk()
2323 sm->pmk_len = pmk_len; in wpa_set_pmk()
2326 pmksa_cache_add(sm->pmksa, pmk, PMK_LEN, pmkid, NULL, 0, in wpa_set_pmk()
2327 sm->bssid, sm->own_addr, in wpa_set_pmk()
2328 sm->network_ctx, sm->key_mgmt); in wpa_set_pmk()
2335 struct wpa_sm *sm = &gWpaSm; in wpa_set_bss() local
2344 if ((sm->key_mgmt == WPA_KEY_MGMT_SAE) && in wpa_set_bss()
2345 (os_memcmp(sm->bssid, bssid, ETH_ALEN) == 0) && in wpa_set_bss()
2346 (os_memcmp(sm->ssid, ssid, ssid_len) != 0)) { in wpa_set_bss()
2349 sm->pairwise_cipher = BIT(pairwise_cipher); in wpa_set_bss()
2350 sm->group_cipher = BIT(group_cipher); in wpa_set_bss()
2351 sm->rx_replay_counter_set = 0; //init state not intall replay counter value in wpa_set_bss()
2352 memset(sm->rx_replay_counter, 0, WPA_REPLAY_COUNTER_LEN); in wpa_set_bss()
2353 sm->wpa_ptk_rekey = 0; in wpa_set_bss()
2354 sm->renew_snonce = 1; in wpa_set_bss()
2355 memcpy(sm->own_addr, macddr, ETH_ALEN); in wpa_set_bss()
2356 memcpy(sm->bssid, bssid, ETH_ALEN); in wpa_set_bss()
2357 sm->ap_notify_completed_rsne = esp_wifi_sta_is_ap_notify_completed_rsne_internal(); in wpa_set_bss()
2358 sm->use_ext_key_id = (sm->proto == WPA_PROTO_WPA); in wpa_set_bss()
2359 pmksa_cache_clear_current(sm); in wpa_set_bss()
2360 sm->sae_pwe = esp_wifi_get_config_sae_pwe_h2e_internal(WIFI_IF_STA); in wpa_set_bss()
2364 pmksa = pmksa_cache_get(sm->pmksa, (const u8 *)bssid, NULL, NULL); in wpa_set_bss()
2365 if (pmksa && (pmksa->akmp != sm->key_mgmt)) { in wpa_set_bss()
2369 if (wpa_key_mgmt_supports_caching(sm->key_mgmt) && use_pmk_cache) { in wpa_set_bss()
2370 pmksa_cache_set_current(sm, NULL, (const u8*) bssid, 0, 0); in wpa_set_bss()
2371 wpa_sm_set_pmk_from_pmksa(sm); in wpa_set_bss()
2374 pmksa_cache_flush(sm->pmksa, NULL, pmksa->pmk, pmksa->pmk_len); in wpa_set_bss()
2378 sm->eapol1_count = 0; in wpa_set_bss()
2385 sm->pmf_cfg = wifi_cfg.sta.pmf_cfg; in wpa_set_bss()
2386 sm->mgmt_group_cipher = cipher_type_map_public_to_supp(mgmt_cipher); in wpa_set_bss()
2387 if (sm->mgmt_group_cipher == WPA_CIPHER_NONE) { in wpa_set_bss()
2394 if (sm->mgmt_group_cipher != WPA_CIPHER_BIP_GMAC_256) { in wpa_set_bss()
2398 if (sm->group_cipher != WPA_CIPHER_GCMP_256) { in wpa_set_bss()
2402 if (sm->pairwise_cipher != WPA_CIPHER_GCMP_256) { in wpa_set_bss()
2406 if (sm->key_mgmt != WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) { in wpa_set_bss()
2413 memset(&sm->pmf_cfg, 0, sizeof(sm->pmf_cfg)); in wpa_set_bss()
2414 sm->mgmt_group_cipher = WPA_CIPHER_NONE; in wpa_set_bss()
2418 if (sm->key_mgmt == WPA_KEY_MGMT_FT_PSK) { in wpa_set_bss()
2427 if (os_memcmp(md, sm->mobility_domain, MOBILITY_DOMAIN_ID_LEN) != 0) { in wpa_set_bss()
2431 sm->ft_protocol = 0; in wpa_set_bss()
2433 wpa_sm_set_ft_params(sm, ie, ie ? 2 + ie[1] : 0); in wpa_set_bss()
2436 wpa_sm_set_ft_params(sm, NULL, 0); in wpa_set_bss()
2442 res = wpa_gen_wpa_ie(sm, sm->assoc_wpa_ie, sm->assoc_wpa_ie_len); in wpa_set_bss()
2445 sm->assoc_wpa_ie_len = res; in wpa_set_bss()
2450 res = wpa_gen_rsnxe(sm, assoc_rsnxe, assoc_rsnxe_len); in wpa_set_bss()
2454 res = wpa_sm_set_assoc_rsnxe(sm, assoc_rsnxe, assoc_rsnxe_len); in wpa_set_bss()
2458 os_memset(sm->ssid, 0, sizeof(sm->ssid)); in wpa_set_bss()
2459 os_memcpy(sm->ssid, ssid, ssid_len); in wpa_set_bss()
2460 sm->ssid_len = ssid_len; in wpa_set_bss()
2480 struct wpa_sm *sm = &gWpaSm; in wpa_set_passphrase() local
2488 if (sm->key_mgmt == WPA_KEY_MGMT_SAE || sm->key_mgmt == WPA_KEY_MGMT_OWE) in wpa_set_passphrase()
2506 if (sm->key_mgmt == WPA_KEY_MGMT_IEEE8021X) { in wpa_set_passphrase()
2509 memcpy(sm->pmk, esp_wifi_sta_get_ap_info_prof_pmk_internal(), PMK_LEN); in wpa_set_passphrase()
2510 sm->pmk_len = PMK_LEN; in wpa_set_passphrase()
2514 sm->xxkey_len = PMK_LEN; in wpa_set_passphrase()
2515 os_memcpy(sm->xxkey, sm->pmk, PMK_LEN); in wpa_set_passphrase()
2522 struct wpa_sm *sm = &gWpaSm; in set_assoc_ie() local
2524 sm->assoc_wpa_ie = assoc_buf + 2; in set_assoc_ie()
2527 if ( sm->proto == WPA_PROTO_WPA) in set_assoc_ie()
2528 sm->assoc_wpa_ie_len = ASSOC_IE_LEN; in set_assoc_ie()
2530 sm->assoc_wpa_ie_len = ASSOC_IE_LEN - 2; in set_assoc_ie()
2532 wpa_config_assoc_ie(sm->proto, assoc_buf, sm->assoc_wpa_ie_len); in set_assoc_ie()
2541 struct wpa_sm *sm = &gWpaSm; in wpa_sm_set_key() local
2546 sm->mic_errors_seen = 0; in wpa_sm_set_key()
2568 struct wpa_sm *sm = &gWpaSm; in wpa_supplicant_clr_countermeasures() local
2569 sm->mic_errors_seen = 0; in wpa_supplicant_clr_countermeasures()
2578 struct wpa_sm *sm = &gWpaSm; in wpa_supplicant_stop_countermeasures() local
2580 if (sm->countermeasures) { in wpa_supplicant_stop_countermeasures()
2581 sm->countermeasures = 0; in wpa_supplicant_stop_countermeasures()
2593 struct wpa_sm *sm = &gWpaSm; in wpa_michael_mic_failure() local
2597 if (sm->mic_errors_seen) { in wpa_michael_mic_failure()
2602 wpa_sm_key_request(sm, 1, isunicast); in wpa_michael_mic_failure()
2605 sm->countermeasures = 1; in wpa_michael_mic_failure()
2623 sm->mic_errors_seen++; in wpa_michael_mic_failure()
2625 wpa_sm_key_request(sm, 1, isunicast); in wpa_michael_mic_failure()
2642 struct wpa_sm *sm = &gWpaSm; in eapol_txcb() local
2660 switch(WPA_SM_STATE(sm)) { in eapol_txcb()
2671 if (sm->txcb_flags & WPA_4_4_HANDSHAKE_BIT) { in eapol_txcb()
2672 sm->txcb_flags &= ~WPA_4_4_HANDSHAKE_BIT; in eapol_txcb()
2673 isdeauth = wpa_supplicant_send_4_of_4_txcallback(sm); in eapol_txcb()
2675 wpa_printf(MSG_DEBUG, "4/4 txcb, flags=%d", sm->txcb_flags); in eapol_txcb()
2679 wpa_printf(MSG_DEBUG, "2/4 txcb, flags=%d, txfail %d", sm->txcb_flags, tx_failure); in eapol_txcb()
2683 if (sm->txcb_flags & WPA_GROUP_HANDSHAKE_BIT) { in eapol_txcb()
2684 sm->txcb_flags &= ~WPA_GROUP_HANDSHAKE_BIT; in eapol_txcb()
2686 wpa_printf(MSG_DEBUG, "2/2 txcb, flags=%d", sm->txcb_flags); in eapol_txcb()
2695 wpa_sm_deauthenticate(sm, isdeauth); in eapol_txcb()
2701 struct wpa_sm *sm = &gWpaSm; in wpa_sta_in_4way_handshake() local
2702 if ( WPA_SM_STATE(sm) == WPA_MIC_FAILURE || WPA_SM_STATE(sm) == WPA_FIRST_HALF_4WAY_HANDSHAKE in wpa_sta_in_4way_handshake()
2703 || WPA_SM_STATE(sm) == WPA_LAST_HALF_4WAY_HANDSHAKE) { in wpa_sta_in_4way_handshake()
2710 struct wpa_sm *sm = &gWpaSm; in wpa_sta_is_cur_pmksa_set() local
2711 return (pmksa_cache_get_current(sm) != NULL); in wpa_sta_is_cur_pmksa_set()
2715 struct wpa_sm *sm = &gWpaSm; in wpa_sta_cur_pmksa_matches_akm() local
2718 pmksa = pmksa_cache_get_current(sm); in wpa_sta_cur_pmksa_matches_akm()
2720 sm->key_mgmt == pmksa->akmp); in wpa_sta_cur_pmksa_matches_akm()
2724 struct wpa_sm *sm = &gWpaSm; in wpa_sta_clear_curr_pmksa() local
2726 if (sm->pmksa) in wpa_sta_clear_curr_pmksa()
2727 pmksa_cache_flush(sm->pmksa, NULL, sm->pmk, sm->pmk_len); in wpa_sta_clear_curr_pmksa()
2728 pmksa_cache_clear_current(sm); in wpa_sta_clear_curr_pmksa()
2738 struct wpa_sm *sm = &gWpaSm; in wpa_sm_set_ap_rsnxe() local
2739 if (!sm) in wpa_sm_set_ap_rsnxe()
2742 os_free(sm->ap_rsnxe); in wpa_sm_set_ap_rsnxe()
2745 sm->ap_rsnxe = NULL; in wpa_sm_set_ap_rsnxe()
2746 sm->ap_rsnxe_len = 0; in wpa_sm_set_ap_rsnxe()
2749 sm->ap_rsnxe = os_memdup(ie, len); in wpa_sm_set_ap_rsnxe()
2750 if (!sm->ap_rsnxe) in wpa_sm_set_ap_rsnxe()
2753 sm->ap_rsnxe_len = len; in wpa_sm_set_ap_rsnxe()
2756 if (sm->ap_rsnxe != NULL) { in wpa_sm_set_ap_rsnxe()
2757 sm->sae_pwe = esp_wifi_get_config_sae_pwe_h2e_internal(WIFI_IF_STA); in wpa_sm_set_ap_rsnxe()
2762 sm->sae_pk = true; in wpa_sm_set_ap_rsnxe()
2770 int wpa_sm_set_assoc_rsnxe(struct wpa_sm *sm, const u8 *ie, size_t len) in wpa_sm_set_assoc_rsnxe() argument
2772 if (!sm) in wpa_sm_set_assoc_rsnxe()
2775 os_free(sm->assoc_rsnxe); in wpa_sm_set_assoc_rsnxe()
2777 sm->assoc_rsnxe = NULL; in wpa_sm_set_assoc_rsnxe()
2778 sm->assoc_rsnxe_len = 0; in wpa_sm_set_assoc_rsnxe()
2781 sm->assoc_rsnxe = os_memdup(ie, len); in wpa_sm_set_assoc_rsnxe()
2782 if (!sm->assoc_rsnxe) in wpa_sm_set_assoc_rsnxe()
2785 sm->assoc_rsnxe_len = len; in wpa_sm_set_assoc_rsnxe()
2791 void wpa_sm_drop_sa(struct wpa_sm *sm) in wpa_sm_drop_sa() argument
2794 sm->ptk_set = 0; in wpa_sm_drop_sa()
2795 sm->tptk_set = 0; in wpa_sm_drop_sa()
2796 sm->pmk_len = 0; in wpa_sm_drop_sa()
2797 os_memset(&sm->ptk, 0, sizeof(sm->ptk)); in wpa_sm_drop_sa()
2798 os_memset(&sm->tptk, 0, sizeof(sm->tptk)); in wpa_sm_drop_sa()
2799 os_memset(&sm->gtk, 0, sizeof(sm->gtk)); in wpa_sm_drop_sa()
2800 os_memset(&sm->igtk, 0, sizeof(sm->igtk)); in wpa_sm_drop_sa()
2804 struct wpabuf *owe_build_assoc_req(struct wpa_sm *sm, u16 group) in owe_build_assoc_req() argument
2816 sm->owe_ecdh = crypto_ecdh_init(group); in owe_build_assoc_req()
2818 if (!sm->owe_ecdh) { in owe_build_assoc_req()
2823 sm->owe_group = group; in owe_build_assoc_req()
2825 pub = crypto_ecdh_get_pubkey(sm->owe_ecdh, 0); in owe_build_assoc_req()
2835 if (sm->owe_ie) { in owe_build_assoc_req()
2836 wpabuf_free(sm->owe_ie); in owe_build_assoc_req()
2838 sm->owe_ie = wpabuf_alloc(5 + wpabuf_len(pub)); in owe_build_assoc_req()
2840 if (!sm->owe_ie) { in owe_build_assoc_req()
2846 wpabuf_put_u8(sm->owe_ie, WLAN_EID_EXTENSION); in owe_build_assoc_req()
2847 wpabuf_put_u8(sm->owe_ie, 1 + 2 + wpabuf_len(pub)); in owe_build_assoc_req()
2848 wpabuf_put_u8(sm->owe_ie, WLAN_EID_EXT_OWE_DH_PARAM); in owe_build_assoc_req()
2849 wpabuf_put_le16(sm->owe_ie, group); in owe_build_assoc_req()
2850 wpabuf_put_buf(sm->owe_ie, pub); in owe_build_assoc_req()
2853 wpa_hexdump_buf(MSG_DEBUG, "OWE: Diffie-Hellman Parameter element", sm->owe_ie); in owe_build_assoc_req()
2855 return (struct wpabuf *)wpabuf_head(sm->owe_ie); in owe_build_assoc_req()
2859 crypto_ecdh_deinit(sm->owe_ecdh); in owe_build_assoc_req()
2873 struct wpa_sm *sm; in owe_process_assoc_resp() local
2874 sm = get_wpa_sm(); in owe_process_assoc_resp()
2877 wpabuf_free(sm->owe_ie); in owe_process_assoc_resp()
2878 sm->owe_ie = NULL; in owe_process_assoc_resp()
2897 …if (sm->cur_pmksa && parsed_rsn_data && parsed_rsn_data->num_pmkid == 1 && parsed_rsn_data->pmkid)… in owe_process_assoc_resp()
2898 if (os_memcmp(parsed_rsn_data->pmkid, sm->cur_pmksa->pmkid, OWE_PMKID_LEN) == 0) { in owe_process_assoc_resp()
2900 wpa_sm_set_pmk_from_pmksa(sm); in owe_process_assoc_resp()
2925 if ((group != sm->owe_group) || (group != OWE_DH_GRP19)) { in owe_process_assoc_resp()
2933 sh_secret = crypto_ecdh_set_peerkey(sm->owe_ecdh, 0, dh_ie+2, dh_len-2); in owe_process_assoc_resp()
2941 pub = crypto_ecdh_get_pubkey(sm->owe_ecdh, 0); in owe_process_assoc_resp()
2975 wpabuf_put_le16(hkey, sm->owe_group); /* group */ in owe_process_assoc_resp()
2999 os_memcpy(sm->pmk,pmk,hash_len); in owe_process_assoc_resp()
3000 sm->pmk_len = hash_len; in owe_process_assoc_resp()
3001 wpa_hexdump_key(MSG_DEBUG, "OWE: PMK", sm->pmk, sm->pmk_len); in owe_process_assoc_resp()
3003 pmksa_cache_add(sm->pmksa, sm->pmk, sm->pmk_len, pmkid, NULL, 0, in owe_process_assoc_resp()
3004 sm->bssid, sm->own_addr, sm->network_ctx, sm->key_mgmt); in owe_process_assoc_resp()