• Home
  • Raw
  • Download

Lines Matching refs:sm

46 int wpa_eapol_key_send(struct wpa_sm *sm, struct wpa_ptk *ptk,  in wpa_eapol_key_send()  argument
51 size_t mic_len = wpa_mic_len(sm->key_mgmt); in wpa_eapol_key_send()
53 if (is_zero_ether_addr(dest) && is_zero_ether_addr(sm->bssid)) { in wpa_eapol_key_send()
58 if (wpa_sm_get_bssid(sm, sm->bssid) < 0) { in wpa_eapol_key_send()
59 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_eapol_key_send()
63 dest = sm->bssid; in wpa_eapol_key_send()
64 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_eapol_key_send()
76 wpa_eapol_key_mic(ptk->kck, ptk->kck_len, sm->key_mgmt, ver, in wpa_eapol_key_send()
78 wpa_msg(sm->ctx->msg_ctx, MSG_ERROR, in wpa_eapol_key_send()
80 ver, sm->key_mgmt); in wpa_eapol_key_send()
154 ret = wpa_sm_ether_send(sm, dest, proto, msg, msg_len); in wpa_eapol_key_send()
155 eapol_sm_notify_tx_eapol_key(sm->eapol); in wpa_eapol_key_send()
172 void wpa_sm_key_request(struct wpa_sm *sm, int error, int pairwise) in wpa_sm_key_request() argument
179 if (sm->key_mgmt == WPA_KEY_MGMT_OSEN || in wpa_sm_key_request()
180 wpa_key_mgmt_suite_b(sm->key_mgmt)) in wpa_sm_key_request()
182 else if (wpa_key_mgmt_ft(sm->key_mgmt) || in wpa_sm_key_request()
183 wpa_key_mgmt_sha256(sm->key_mgmt)) in wpa_sm_key_request()
185 else if (sm->pairwise_cipher != WPA_CIPHER_TKIP) in wpa_sm_key_request()
190 if (wpa_sm_get_bssid(sm, bssid) < 0) { in wpa_sm_key_request()
191 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_sm_key_request()
196 mic_len = wpa_mic_len(sm->key_mgmt); in wpa_sm_key_request()
198 rbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY, NULL, in wpa_sm_key_request()
203 reply->type = (sm->proto == WPA_PROTO_RSN || in wpa_sm_key_request()
204 sm->proto == WPA_PROTO_OSEN) ? in wpa_sm_key_request()
207 if (sm->ptk_set) in wpa_sm_key_request()
209 if (sm->ptk_set && mic_len) in wpa_sm_key_request()
217 os_memcpy(reply->replay_counter, sm->request_counter, in wpa_sm_key_request()
219 inc_byte_array(sm->request_counter, WPA_REPLAY_COUNTER_LEN); in wpa_sm_key_request()
228 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_sm_key_request()
231 error, pairwise, sm->ptk_set, (unsigned long) rlen); in wpa_sm_key_request()
232 wpa_eapol_key_send(sm, &sm->ptk, ver, bssid, ETH_P_EAPOL, rbuf, rlen, in wpa_sm_key_request()
237 static void wpa_supplicant_key_mgmt_set_pmk(struct wpa_sm *sm) in wpa_supplicant_key_mgmt_set_pmk() argument
240 if (sm->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X) { in wpa_supplicant_key_mgmt_set_pmk()
241 if (wpa_sm_key_mgmt_set_pmk(sm, sm->xxkey, sm->xxkey_len)) in wpa_supplicant_key_mgmt_set_pmk()
242 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_supplicant_key_mgmt_set_pmk()
246 if (wpa_sm_key_mgmt_set_pmk(sm, sm->pmk, sm->pmk_len)) in wpa_supplicant_key_mgmt_set_pmk()
247 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_supplicant_key_mgmt_set_pmk()
255 static int wpa_supplicant_get_pmk(struct wpa_sm *sm, in wpa_supplicant_get_pmk() argument
261 if (pmkid && !sm->cur_pmksa) { in wpa_supplicant_get_pmk()
266 sm->cur_pmksa = pmksa_cache_get(sm->pmksa, src_addr, pmkid, in wpa_supplicant_get_pmk()
268 if (sm->cur_pmksa) { in wpa_supplicant_get_pmk()
269 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_supplicant_get_pmk()
272 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_supplicant_get_pmk()
278 if (pmkid && sm->cur_pmksa && in wpa_supplicant_get_pmk()
279 os_memcmp_const(pmkid, sm->cur_pmksa->pmkid, PMKID_LEN) == 0) { in wpa_supplicant_get_pmk()
281 wpa_sm_set_pmk_from_pmksa(sm); in wpa_supplicant_get_pmk()
283 sm->pmk, sm->pmk_len); in wpa_supplicant_get_pmk()
284 eapol_sm_notify_cached(sm->eapol); in wpa_supplicant_get_pmk()
286 sm->xxkey_len = 0; in wpa_supplicant_get_pmk()
288 } else if (wpa_key_mgmt_wpa_ieee8021x(sm->key_mgmt) && sm->eapol) { in wpa_supplicant_get_pmk()
291 if (wpa_key_mgmt_sha384(sm->key_mgmt)) in wpa_supplicant_get_pmk()
295 res = eapol_sm_get_key(sm->eapol, sm->pmk, pmk_len); in wpa_supplicant_get_pmk()
302 res = eapol_sm_get_key(sm->eapol, sm->pmk, 16); in wpa_supplicant_get_pmk()
308 if (eapol_sm_get_key(sm->eapol, buf, 2 * PMK_LEN) == 0) in wpa_supplicant_get_pmk()
310 os_memcpy(sm->xxkey, buf + PMK_LEN, PMK_LEN); in wpa_supplicant_get_pmk()
311 sm->xxkey_len = PMK_LEN; in wpa_supplicant_get_pmk()
319 "machines", sm->pmk, pmk_len); in wpa_supplicant_get_pmk()
320 sm->pmk_len = pmk_len; in wpa_supplicant_get_pmk()
321 wpa_supplicant_key_mgmt_set_pmk(sm); in wpa_supplicant_get_pmk()
322 if (sm->proto == WPA_PROTO_RSN && in wpa_supplicant_get_pmk()
323 !wpa_key_mgmt_suite_b(sm->key_mgmt) && in wpa_supplicant_get_pmk()
324 !wpa_key_mgmt_ft(sm->key_mgmt)) { in wpa_supplicant_get_pmk()
325 sa = pmksa_cache_add(sm->pmksa, in wpa_supplicant_get_pmk()
326 sm->pmk, pmk_len, NULL, in wpa_supplicant_get_pmk()
328 src_addr, sm->own_addr, in wpa_supplicant_get_pmk()
329 sm->network_ctx, in wpa_supplicant_get_pmk()
330 sm->key_mgmt); in wpa_supplicant_get_pmk()
332 if (!sm->cur_pmksa && pmkid && in wpa_supplicant_get_pmk()
333 pmksa_cache_get(sm->pmksa, src_addr, pmkid, NULL)) in wpa_supplicant_get_pmk()
335 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_supplicant_get_pmk()
339 } else if (sa && !sm->cur_pmksa && pmkid) { in wpa_supplicant_get_pmk()
347 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_supplicant_get_pmk()
352 if (!sm->cur_pmksa) in wpa_supplicant_get_pmk()
353 sm->cur_pmksa = sa; in wpa_supplicant_get_pmk()
355 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_get_pmk()
359 if (sm->cur_pmksa) { in wpa_supplicant_get_pmk()
360 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_supplicant_get_pmk()
363 sm->cur_pmksa = NULL; in wpa_supplicant_get_pmk()
371 if (abort_cached && wpa_key_mgmt_wpa_ieee8021x(sm->key_mgmt) && in wpa_supplicant_get_pmk()
372 !wpa_key_mgmt_suite_b(sm->key_mgmt) && in wpa_supplicant_get_pmk()
373 !wpa_key_mgmt_ft(sm->key_mgmt) && sm->key_mgmt != WPA_KEY_MGMT_OSEN) in wpa_supplicant_get_pmk()
379 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_supplicant_get_pmk()
382 buf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_START, in wpa_supplicant_get_pmk()
385 wpa_sm_ether_send(sm, sm->bssid, ETH_P_EAPOL, in wpa_supplicant_get_pmk()
410 int wpa_supplicant_send_2_of_4(struct wpa_sm *sm, const unsigned char *dst, in wpa_supplicant_send_2_of_4() argument
423 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, "WPA: No wpa_ie set - " in wpa_supplicant_send_2_of_4()
429 if (wpa_key_mgmt_ft(sm->key_mgmt)) { in wpa_supplicant_send_2_of_4()
437 sm->assoc_resp_ies_len); in wpa_supplicant_send_2_of_4()
442 sm->pmk_r1_name); in wpa_supplicant_send_2_of_4()
448 if (sm->assoc_resp_ies) { in wpa_supplicant_send_2_of_4()
449 os_memcpy(rsn_ie_buf + wpa_ie_len, sm->assoc_resp_ies, in wpa_supplicant_send_2_of_4()
450 sm->assoc_resp_ies_len); in wpa_supplicant_send_2_of_4()
451 wpa_ie_len += sm->assoc_resp_ies_len; in wpa_supplicant_send_2_of_4()
460 mic_len = wpa_mic_len(sm->key_mgmt); in wpa_supplicant_send_2_of_4()
462 rbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY, in wpa_supplicant_send_2_of_4()
470 reply->type = (sm->proto == WPA_PROTO_RSN || in wpa_supplicant_send_2_of_4()
471 sm->proto == WPA_PROTO_OSEN) ? in wpa_supplicant_send_2_of_4()
479 if (sm->proto == WPA_PROTO_RSN || sm->proto == WPA_PROTO_OSEN) in wpa_supplicant_send_2_of_4()
495 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Sending EAPOL-Key 2/4"); in wpa_supplicant_send_2_of_4()
496 return wpa_eapol_key_send(sm, ptk, ver, dst, ETH_P_EAPOL, rbuf, rlen, in wpa_supplicant_send_2_of_4()
501 static int wpa_derive_ptk(struct wpa_sm *sm, const unsigned char *src_addr, in wpa_derive_ptk() argument
505 if (wpa_key_mgmt_ft(sm->key_mgmt)) in wpa_derive_ptk()
506 return wpa_derive_ptk_ft(sm, src_addr, key, ptk); in wpa_derive_ptk()
509 return wpa_pmk_to_ptk(sm->pmk, sm->pmk_len, "Pairwise key expansion", in wpa_derive_ptk()
510 sm->own_addr, sm->bssid, sm->snonce, in wpa_derive_ptk()
511 key->key_nonce, ptk, sm->key_mgmt, in wpa_derive_ptk()
512 sm->pairwise_cipher); in wpa_derive_ptk()
516 static void wpa_supplicant_process_1_of_4(struct wpa_sm *sm, in wpa_supplicant_process_1_of_4() argument
528 if (wpa_sm_get_network_ctx(sm) == NULL) { in wpa_supplicant_process_1_of_4()
529 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, "WPA: No SSID info " in wpa_supplicant_process_1_of_4()
534 wpa_sm_set_state(sm, WPA_4WAY_HANDSHAKE); in wpa_supplicant_process_1_of_4()
535 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: RX message 1 of 4-Way " in wpa_supplicant_process_1_of_4()
540 if (sm->proto == WPA_PROTO_RSN || sm->proto == WPA_PROTO_OSEN) { in wpa_supplicant_process_1_of_4()
552 res = wpa_supplicant_get_pmk(sm, src_addr, ie.pmkid); in wpa_supplicant_process_1_of_4()
554 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: Do not reply to " in wpa_supplicant_process_1_of_4()
561 if (sm->renew_snonce) { in wpa_supplicant_process_1_of_4()
562 if (random_get_bytes(sm->snonce, WPA_NONCE_LEN)) { in wpa_supplicant_process_1_of_4()
563 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_process_1_of_4()
567 sm->renew_snonce = 0; in wpa_supplicant_process_1_of_4()
569 sm->snonce, WPA_NONCE_LEN); in wpa_supplicant_process_1_of_4()
574 ptk = &sm->tptk; in wpa_supplicant_process_1_of_4()
575 wpa_derive_ptk(sm, src_addr, key, ptk); in wpa_supplicant_process_1_of_4()
576 if (sm->pairwise_cipher == WPA_CIPHER_TKIP) { in wpa_supplicant_process_1_of_4()
584 sm->tptk_set = 1; in wpa_supplicant_process_1_of_4()
586 kde = sm->assoc_wpa_ie; in wpa_supplicant_process_1_of_4()
587 kde_len = sm->assoc_wpa_ie_len; in wpa_supplicant_process_1_of_4()
590 if (sm->p2p) { in wpa_supplicant_process_1_of_4()
609 if (wpa_supplicant_send_2_of_4(sm, sm->bssid, key, ver, sm->snonce, in wpa_supplicant_process_1_of_4()
614 os_memcpy(sm->anonce, key->key_nonce, WPA_NONCE_LEN); in wpa_supplicant_process_1_of_4()
619 wpa_sm_deauthenticate(sm, WLAN_REASON_UNSPECIFIED); in wpa_supplicant_process_1_of_4()
625 struct wpa_sm *sm = eloop_ctx; in wpa_sm_start_preauth() local
626 rsn_preauth_candidate_process(sm); in wpa_sm_start_preauth()
630 static void wpa_supplicant_key_neg_complete(struct wpa_sm *sm, in wpa_supplicant_key_neg_complete() argument
633 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_supplicant_key_neg_complete()
636 wpa_cipher_txt(sm->pairwise_cipher), in wpa_supplicant_key_neg_complete()
637 wpa_cipher_txt(sm->group_cipher)); in wpa_supplicant_key_neg_complete()
638 wpa_sm_cancel_auth_timeout(sm); in wpa_supplicant_key_neg_complete()
639 wpa_sm_set_state(sm, WPA_COMPLETED); in wpa_supplicant_key_neg_complete()
643 sm, addr, MLME_SETPROTECTION_PROTECT_TYPE_RX_TX, in wpa_supplicant_key_neg_complete()
645 eapol_sm_notify_portValid(sm->eapol, TRUE); in wpa_supplicant_key_neg_complete()
646 if (wpa_key_mgmt_wpa_psk(sm->key_mgmt)) in wpa_supplicant_key_neg_complete()
647 eapol_sm_notify_eap_success(sm->eapol, TRUE); in wpa_supplicant_key_neg_complete()
655 eloop_register_timeout(1, 0, wpa_sm_start_preauth, sm, NULL); in wpa_supplicant_key_neg_complete()
658 if (sm->cur_pmksa && sm->cur_pmksa->opportunistic) { in wpa_supplicant_key_neg_complete()
659 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_supplicant_key_neg_complete()
662 sm->cur_pmksa->opportunistic = 0; in wpa_supplicant_key_neg_complete()
666 if (wpa_key_mgmt_ft(sm->key_mgmt)) { in wpa_supplicant_key_neg_complete()
668 wpa_ft_prepare_auth_request(sm, NULL); in wpa_supplicant_key_neg_complete()
676 struct wpa_sm *sm = eloop_ctx; in wpa_sm_rekey_ptk() local
677 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Request PTK rekeying"); in wpa_sm_rekey_ptk()
678 wpa_sm_key_request(sm, 0, 1); in wpa_sm_rekey_ptk()
682 static int wpa_supplicant_install_ptk(struct wpa_sm *sm, in wpa_supplicant_install_ptk() argument
689 if (sm->ptk.installed) { in wpa_supplicant_install_ptk()
690 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_supplicant_install_ptk()
695 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_supplicant_install_ptk()
698 if (sm->pairwise_cipher == WPA_CIPHER_NONE) { in wpa_supplicant_install_ptk()
699 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Pairwise Cipher " in wpa_supplicant_install_ptk()
704 if (!wpa_cipher_valid_pairwise(sm->pairwise_cipher)) { in wpa_supplicant_install_ptk()
705 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_install_ptk()
707 sm->pairwise_cipher); in wpa_supplicant_install_ptk()
711 alg = wpa_cipher_to_alg(sm->pairwise_cipher); in wpa_supplicant_install_ptk()
712 keylen = wpa_cipher_key_len(sm->pairwise_cipher); in wpa_supplicant_install_ptk()
713 rsclen = wpa_cipher_rsc_len(sm->pairwise_cipher); in wpa_supplicant_install_ptk()
715 if (sm->proto == WPA_PROTO_RSN || sm->proto == WPA_PROTO_OSEN) { in wpa_supplicant_install_ptk()
722 if (wpa_sm_set_key(sm, alg, sm->bssid, 0, 1, key_rsc, rsclen, in wpa_supplicant_install_ptk()
723 sm->ptk.tk, keylen) < 0) { in wpa_supplicant_install_ptk()
724 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_install_ptk()
727 alg, keylen, MAC2STR(sm->bssid)); in wpa_supplicant_install_ptk()
732 os_memset(sm->ptk.tk, 0, WPA_TK_MAX_LEN); in wpa_supplicant_install_ptk()
733 sm->ptk.installed = 1; in wpa_supplicant_install_ptk()
735 if (sm->wpa_ptk_rekey) { in wpa_supplicant_install_ptk()
736 eloop_cancel_timeout(wpa_sm_rekey_ptk, sm, NULL); in wpa_supplicant_install_ptk()
737 eloop_register_timeout(sm->wpa_ptk_rekey, 0, wpa_sm_rekey_ptk, in wpa_supplicant_install_ptk()
738 sm, NULL); in wpa_supplicant_install_ptk()
745 static int wpa_supplicant_check_group_cipher(struct wpa_sm *sm, in wpa_supplicant_check_group_cipher() argument
755 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_check_group_cipher()
764 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_check_group_cipher()
781 static int wpa_supplicant_install_gtk(struct wpa_sm *sm, in wpa_supplicant_install_gtk() argument
789 if ((sm->gtk.gtk_len == (size_t) gd->gtk_len && in wpa_supplicant_install_gtk()
790 os_memcmp(sm->gtk.gtk, gd->gtk, sm->gtk.gtk_len) == 0) || in wpa_supplicant_install_gtk()
791 (sm->gtk_wnm_sleep.gtk_len == (size_t) gd->gtk_len && in wpa_supplicant_install_gtk()
792 os_memcmp(sm->gtk_wnm_sleep.gtk, gd->gtk, in wpa_supplicant_install_gtk()
793 sm->gtk_wnm_sleep.gtk_len) == 0)) { in wpa_supplicant_install_gtk()
794 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_supplicant_install_gtk()
801 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_supplicant_install_gtk()
805 if (sm->group_cipher == WPA_CIPHER_TKIP) { in wpa_supplicant_install_gtk()
812 if (sm->pairwise_cipher == WPA_CIPHER_NONE) { in wpa_supplicant_install_gtk()
813 if (wpa_sm_set_key(sm, gd->alg, NULL, in wpa_supplicant_install_gtk()
816 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_install_gtk()
822 } else if (wpa_sm_set_key(sm, gd->alg, broadcast_ether_addr, in wpa_supplicant_install_gtk()
825 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_install_gtk()
835 sm->gtk_wnm_sleep.gtk_len = gd->gtk_len; in wpa_supplicant_install_gtk()
836 os_memcpy(sm->gtk_wnm_sleep.gtk, gd->gtk, in wpa_supplicant_install_gtk()
837 sm->gtk_wnm_sleep.gtk_len); in wpa_supplicant_install_gtk()
839 sm->gtk.gtk_len = gd->gtk_len; in wpa_supplicant_install_gtk()
840 os_memcpy(sm->gtk.gtk, gd->gtk, sm->gtk.gtk_len); in wpa_supplicant_install_gtk()
847 static int wpa_supplicant_gtk_tx_bit_workaround(const struct wpa_sm *sm, in wpa_supplicant_gtk_tx_bit_workaround() argument
850 if (tx && sm->pairwise_cipher != WPA_CIPHER_NONE) { in wpa_supplicant_gtk_tx_bit_workaround()
856 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_supplicant_gtk_tx_bit_workaround()
865 static int wpa_supplicant_rsc_relaxation(const struct wpa_sm *sm, in wpa_supplicant_rsc_relaxation() argument
870 if (!sm->wpa_rsc_relaxation) in wpa_supplicant_rsc_relaxation()
873 rsclen = wpa_cipher_rsc_len(sm->group_cipher); in wpa_supplicant_rsc_relaxation()
883 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_rsc_relaxation()
895 static int wpa_supplicant_pairwise_gtk(struct wpa_sm *sm, in wpa_supplicant_pairwise_gtk() argument
919 gd.tx = wpa_supplicant_gtk_tx_bit_workaround(sm, in wpa_supplicant_pairwise_gtk()
928 if (wpa_supplicant_rsc_relaxation(sm, key->key_rsc)) in wpa_supplicant_pairwise_gtk()
931 if (sm->group_cipher != WPA_CIPHER_GTK_NOT_USED && in wpa_supplicant_pairwise_gtk()
932 (wpa_supplicant_check_group_cipher(sm, sm->group_cipher, in wpa_supplicant_pairwise_gtk()
935 wpa_supplicant_install_gtk(sm, &gd, key_rsc, 0))) { in wpa_supplicant_pairwise_gtk()
936 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_supplicant_pairwise_gtk()
943 wpa_supplicant_key_neg_complete(sm, sm->bssid, in wpa_supplicant_pairwise_gtk()
950 static int wpa_supplicant_install_igtk(struct wpa_sm *sm, in wpa_supplicant_install_igtk() argument
954 size_t len = wpa_cipher_key_len(sm->mgmt_group_cipher); in wpa_supplicant_install_igtk()
958 if ((sm->igtk.igtk_len == len && in wpa_supplicant_install_igtk()
959 os_memcmp(sm->igtk.igtk, igtk->igtk, sm->igtk.igtk_len) == 0) || in wpa_supplicant_install_igtk()
960 (sm->igtk_wnm_sleep.igtk_len == len && in wpa_supplicant_install_igtk()
961 os_memcmp(sm->igtk_wnm_sleep.igtk, igtk->igtk, in wpa_supplicant_install_igtk()
962 sm->igtk_wnm_sleep.igtk_len) == 0)) { in wpa_supplicant_install_igtk()
963 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_supplicant_install_igtk()
969 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_supplicant_install_igtk()
974 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_install_igtk()
978 if (wpa_sm_set_key(sm, wpa_cipher_to_alg(sm->mgmt_group_cipher), in wpa_supplicant_install_igtk()
982 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_install_igtk()
988 sm->igtk_wnm_sleep.igtk_len = len; in wpa_supplicant_install_igtk()
989 os_memcpy(sm->igtk_wnm_sleep.igtk, igtk->igtk, in wpa_supplicant_install_igtk()
990 sm->igtk_wnm_sleep.igtk_len); in wpa_supplicant_install_igtk()
992 sm->igtk.igtk_len = len; in wpa_supplicant_install_igtk()
993 os_memcpy(sm->igtk.igtk, igtk->igtk, sm->igtk.igtk_len); in wpa_supplicant_install_igtk()
1001 static int ieee80211w_set_keys(struct wpa_sm *sm, in ieee80211w_set_keys() argument
1005 if (!wpa_cipher_valid_mgmt_group(sm->mgmt_group_cipher)) in ieee80211w_set_keys()
1012 len = wpa_cipher_key_len(sm->mgmt_group_cipher); in ieee80211w_set_keys()
1017 if (wpa_supplicant_install_igtk(sm, igtk, 0) < 0) in ieee80211w_set_keys()
1028 static void wpa_report_ie_mismatch(struct wpa_sm *sm, in wpa_report_ie_mismatch() argument
1033 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, "WPA: %s (src=" MACSTR ")", in wpa_report_ie_mismatch()
1036 if (sm->ap_wpa_ie) { in wpa_report_ie_mismatch()
1038 sm->ap_wpa_ie, sm->ap_wpa_ie_len); in wpa_report_ie_mismatch()
1041 if (!sm->ap_wpa_ie) { in wpa_report_ie_mismatch()
1042 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_report_ie_mismatch()
1049 if (sm->ap_rsn_ie) { in wpa_report_ie_mismatch()
1051 sm->ap_rsn_ie, sm->ap_rsn_ie_len); in wpa_report_ie_mismatch()
1054 if (!sm->ap_rsn_ie) { in wpa_report_ie_mismatch()
1055 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_report_ie_mismatch()
1062 wpa_sm_deauthenticate(sm, WLAN_REASON_IE_IN_4WAY_DIFFERS); in wpa_report_ie_mismatch()
1068 static int ft_validate_mdie(struct wpa_sm *sm, in ft_validate_mdie() argument
1077 os_memcmp(mdie->mobility_domain, sm->mobility_domain, in ft_validate_mdie()
1079 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "FT: MDIE in msg 3/4 did " in ft_validate_mdie()
1087 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "FT: MDIE mismatch"); in ft_validate_mdie()
1099 static int ft_validate_ftie(struct wpa_sm *sm, in ft_validate_ftie() argument
1105 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in ft_validate_ftie()
1115 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "FT: FTIE mismatch"); in ft_validate_ftie()
1127 static int ft_validate_rsnie(struct wpa_sm *sm, in ft_validate_rsnie() argument
1142 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "FT: No PMKR1Name in " in ft_validate_rsnie()
1147 if (os_memcmp_const(rsn.pmkid, sm->pmk_r1_name, WPA_PMK_NAME_LEN) != 0) in ft_validate_rsnie()
1149 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in ft_validate_rsnie()
1155 sm->pmk_r1_name, WPA_PMK_NAME_LEN); in ft_validate_rsnie()
1163 static int wpa_supplicant_validate_ie_ft(struct wpa_sm *sm, in wpa_supplicant_validate_ie_ft() argument
1169 if (sm->assoc_resp_ies) { in wpa_supplicant_validate_ie_ft()
1170 pos = sm->assoc_resp_ies; in wpa_supplicant_validate_ie_ft()
1171 end = pos + sm->assoc_resp_ies_len; in wpa_supplicant_validate_ie_ft()
1187 if (ft_validate_mdie(sm, src_addr, ie, mdie) < 0 || in wpa_supplicant_validate_ie_ft()
1188 ft_validate_ftie(sm, src_addr, ie, ftie) < 0 || in wpa_supplicant_validate_ie_ft()
1189 ft_validate_rsnie(sm, src_addr, ie) < 0) in wpa_supplicant_validate_ie_ft()
1198 static int wpa_supplicant_validate_ie(struct wpa_sm *sm, in wpa_supplicant_validate_ie() argument
1202 if (sm->ap_wpa_ie == NULL && sm->ap_rsn_ie == NULL) { in wpa_supplicant_validate_ie()
1203 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_supplicant_validate_ie()
1206 if (wpa_sm_get_beacon_ie(sm) < 0) { in wpa_supplicant_validate_ie()
1207 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_validate_ie()
1211 wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_supplicant_validate_ie()
1218 (sm->ap_wpa_ie || sm->ap_rsn_ie)) { in wpa_supplicant_validate_ie()
1219 wpa_report_ie_mismatch(sm, "IE in 3/4 msg does not match " in wpa_supplicant_validate_ie()
1226 if ((ie->wpa_ie && sm->ap_wpa_ie && in wpa_supplicant_validate_ie()
1227 (ie->wpa_ie_len != sm->ap_wpa_ie_len || in wpa_supplicant_validate_ie()
1228 os_memcmp(ie->wpa_ie, sm->ap_wpa_ie, ie->wpa_ie_len) != 0)) || in wpa_supplicant_validate_ie()
1229 (ie->rsn_ie && sm->ap_rsn_ie && in wpa_supplicant_validate_ie()
1230 wpa_compare_rsn_ie(wpa_key_mgmt_ft(sm->key_mgmt), in wpa_supplicant_validate_ie()
1231 sm->ap_rsn_ie, sm->ap_rsn_ie_len, in wpa_supplicant_validate_ie()
1233 wpa_report_ie_mismatch(sm, "IE in 3/4 msg does not match " in wpa_supplicant_validate_ie()
1240 if (sm->proto == WPA_PROTO_WPA && in wpa_supplicant_validate_ie()
1241 ie->rsn_ie && sm->ap_rsn_ie == NULL && sm->rsn_enabled) { in wpa_supplicant_validate_ie()
1242 wpa_report_ie_mismatch(sm, "Possible downgrade attack " in wpa_supplicant_validate_ie()
1252 if (wpa_key_mgmt_ft(sm->key_mgmt) && in wpa_supplicant_validate_ie()
1253 wpa_supplicant_validate_ie_ft(sm, src_addr, ie) < 0) in wpa_supplicant_validate_ie()
1271 int wpa_supplicant_send_4_of_4(struct wpa_sm *sm, const unsigned char *dst, in wpa_supplicant_send_4_of_4() argument
1280 mic_len = wpa_mic_len(sm->key_mgmt); in wpa_supplicant_send_4_of_4()
1282 rbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY, NULL, in wpa_supplicant_send_4_of_4()
1287 reply->type = (sm->proto == WPA_PROTO_RSN || in wpa_supplicant_send_4_of_4()
1288 sm->proto == WPA_PROTO_OSEN) ? in wpa_supplicant_send_4_of_4()
1297 if (sm->proto == WPA_PROTO_RSN || sm->proto == WPA_PROTO_OSEN) in wpa_supplicant_send_4_of_4()
1307 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Sending EAPOL-Key 4/4"); in wpa_supplicant_send_4_of_4()
1308 return wpa_eapol_key_send(sm, ptk, ver, dst, ETH_P_EAPOL, rbuf, rlen, in wpa_supplicant_send_4_of_4()
1313 static void wpa_supplicant_process_3_of_4(struct wpa_sm *sm, in wpa_supplicant_process_3_of_4() argument
1321 wpa_sm_set_state(sm, WPA_4WAY_HANDSHAKE); in wpa_supplicant_process_3_of_4()
1322 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: RX message 3 of 4-Way " in wpa_supplicant_process_3_of_4()
1323 "Handshake from " MACSTR " (ver=%d)", MAC2STR(sm->bssid), ver); in wpa_supplicant_process_3_of_4()
1331 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_process_3_of_4()
1337 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_process_3_of_4()
1343 wpa_cipher_valid_mgmt_group(sm->mgmt_group_cipher) && in wpa_supplicant_process_3_of_4()
1345 (unsigned int) wpa_cipher_key_len(sm->mgmt_group_cipher)) { in wpa_supplicant_process_3_of_4()
1346 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_process_3_of_4()
1353 if (wpa_supplicant_validate_ie(sm, sm->bssid, &ie) < 0) in wpa_supplicant_process_3_of_4()
1356 if (os_memcmp(sm->anonce, key->key_nonce, WPA_NONCE_LEN) != 0) { in wpa_supplicant_process_3_of_4()
1357 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_process_3_of_4()
1360 MACSTR ")", MAC2STR(sm->bssid)); in wpa_supplicant_process_3_of_4()
1365 if (keylen != wpa_cipher_key_len(sm->pairwise_cipher)) { in wpa_supplicant_process_3_of_4()
1366 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_process_3_of_4()
1368 ")", wpa_cipher_txt(sm->pairwise_cipher), keylen, in wpa_supplicant_process_3_of_4()
1369 MAC2STR(sm->bssid)); in wpa_supplicant_process_3_of_4()
1375 os_memcpy(sm->p2p_ip_addr, ie.ip_addr_alloc, 3 * 4); in wpa_supplicant_process_3_of_4()
1377 sm->p2p_ip_addr, sizeof(sm->p2p_ip_addr)); in wpa_supplicant_process_3_of_4()
1381 if (wpa_supplicant_send_4_of_4(sm, sm->bssid, key, ver, key_info, in wpa_supplicant_process_3_of_4()
1382 &sm->ptk) < 0) { in wpa_supplicant_process_3_of_4()
1389 sm->renew_snonce = 1; in wpa_supplicant_process_3_of_4()
1392 if (wpa_supplicant_install_ptk(sm, key)) in wpa_supplicant_process_3_of_4()
1398 sm, sm->bssid, MLME_SETPROTECTION_PROTECT_TYPE_RX, in wpa_supplicant_process_3_of_4()
1400 eapol_sm_notify_portValid(sm->eapol, TRUE); in wpa_supplicant_process_3_of_4()
1402 wpa_sm_set_state(sm, WPA_GROUP_HANDSHAKE); in wpa_supplicant_process_3_of_4()
1404 if (sm->group_cipher == WPA_CIPHER_GTK_NOT_USED) { in wpa_supplicant_process_3_of_4()
1405 wpa_supplicant_key_neg_complete(sm, sm->bssid, in wpa_supplicant_process_3_of_4()
1408 wpa_supplicant_pairwise_gtk(sm, key, in wpa_supplicant_process_3_of_4()
1410 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_supplicant_process_3_of_4()
1415 if (ieee80211w_set_keys(sm, &ie) < 0) { in wpa_supplicant_process_3_of_4()
1416 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_supplicant_process_3_of_4()
1422 wpa_sm_set_rekey_offload(sm); in wpa_supplicant_process_3_of_4()
1424 if (sm->proto == WPA_PROTO_RSN && wpa_key_mgmt_suite_b(sm->key_mgmt)) { in wpa_supplicant_process_3_of_4()
1427 sa = pmksa_cache_add(sm->pmksa, sm->pmk, sm->pmk_len, NULL, in wpa_supplicant_process_3_of_4()
1428 sm->ptk.kck, sm->ptk.kck_len, in wpa_supplicant_process_3_of_4()
1429 sm->bssid, sm->own_addr, in wpa_supplicant_process_3_of_4()
1430 sm->network_ctx, sm->key_mgmt); in wpa_supplicant_process_3_of_4()
1431 if (!sm->cur_pmksa) in wpa_supplicant_process_3_of_4()
1432 sm->cur_pmksa = sa; in wpa_supplicant_process_3_of_4()
1435 sm->msg_3_of_4_ok = 1; in wpa_supplicant_process_3_of_4()
1439 wpa_sm_deauthenticate(sm, WLAN_REASON_UNSPECIFIED); in wpa_supplicant_process_3_of_4()
1443 static int wpa_supplicant_process_1_of_2_rsn(struct wpa_sm *sm, in wpa_supplicant_process_1_of_2_rsn() argument
1457 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_process_1_of_2_rsn()
1462 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_supplicant_process_1_of_2_rsn()
1468 if (wpa_supplicant_check_group_cipher(sm, sm->group_cipher, in wpa_supplicant_process_1_of_2_rsn()
1476 gd->tx = wpa_supplicant_gtk_tx_bit_workaround(sm, in wpa_supplicant_process_1_of_2_rsn()
1479 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_supplicant_process_1_of_2_rsn()
1486 if (ieee80211w_set_keys(sm, &ie) < 0) in wpa_supplicant_process_1_of_2_rsn()
1487 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_supplicant_process_1_of_2_rsn()
1494 static int wpa_supplicant_process_1_of_2_wpa(struct wpa_sm *sm, in wpa_supplicant_process_1_of_2_wpa() argument
1507 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_supplicant_process_1_of_2_wpa()
1516 wpa_supplicant_check_group_cipher(sm, sm->group_cipher, in wpa_supplicant_process_1_of_2_wpa()
1524 if (ver == WPA_KEY_INFO_TYPE_HMAC_MD5_RC4 && sm->ptk.kek_len == 16) { in wpa_supplicant_process_1_of_2_wpa()
1526 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_process_1_of_2_wpa()
1532 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_process_1_of_2_wpa()
1538 os_memcpy(ek + 16, sm->ptk.kek, sm->ptk.kek_len); in wpa_supplicant_process_1_of_2_wpa()
1542 wpa_msg(sm->ctx->msg_ctx, MSG_ERROR, in wpa_supplicant_process_1_of_2_wpa()
1550 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_process_1_of_2_wpa()
1556 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_process_1_of_2_wpa()
1563 if (aes_unwrap(sm->ptk.kek, sm->ptk.kek_len, maxkeylen / 8, in wpa_supplicant_process_1_of_2_wpa()
1565 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_process_1_of_2_wpa()
1571 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_process_1_of_2_wpa()
1576 sm, !!(key_info & WPA_KEY_INFO_TXRX)); in wpa_supplicant_process_1_of_2_wpa()
1581 static int wpa_supplicant_send_2_of_2(struct wpa_sm *sm, in wpa_supplicant_send_2_of_2() argument
1589 mic_len = wpa_mic_len(sm->key_mgmt); in wpa_supplicant_send_2_of_2()
1591 rbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY, NULL, in wpa_supplicant_send_2_of_2()
1596 reply->type = (sm->proto == WPA_PROTO_RSN || in wpa_supplicant_send_2_of_2()
1597 sm->proto == WPA_PROTO_OSEN) ? in wpa_supplicant_send_2_of_2()
1604 if (sm->proto == WPA_PROTO_RSN || sm->proto == WPA_PROTO_OSEN) in wpa_supplicant_send_2_of_2()
1614 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Sending EAPOL-Key 2/2"); in wpa_supplicant_send_2_of_2()
1615 return wpa_eapol_key_send(sm, &sm->ptk, ver, sm->bssid, ETH_P_EAPOL, in wpa_supplicant_send_2_of_2()
1620 static void wpa_supplicant_process_1_of_2(struct wpa_sm *sm, in wpa_supplicant_process_1_of_2() argument
1631 if (!sm->msg_3_of_4_ok) { in wpa_supplicant_process_1_of_2()
1632 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_supplicant_process_1_of_2()
1639 rekey = wpa_sm_get_state(sm) == WPA_COMPLETED; in wpa_supplicant_process_1_of_2()
1640 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: RX message 1 of Group Key " in wpa_supplicant_process_1_of_2()
1645 if (sm->proto == WPA_PROTO_RSN || sm->proto == WPA_PROTO_OSEN) { in wpa_supplicant_process_1_of_2()
1646 ret = wpa_supplicant_process_1_of_2_rsn(sm, key_data, in wpa_supplicant_process_1_of_2()
1650 ret = wpa_supplicant_process_1_of_2_wpa(sm, key, key_data, in wpa_supplicant_process_1_of_2()
1655 wpa_sm_set_state(sm, WPA_GROUP_HANDSHAKE); in wpa_supplicant_process_1_of_2()
1661 if (wpa_supplicant_rsc_relaxation(sm, key->key_rsc)) in wpa_supplicant_process_1_of_2()
1664 if (wpa_supplicant_install_gtk(sm, &gd, key_rsc, 0) || in wpa_supplicant_process_1_of_2()
1665 wpa_supplicant_send_2_of_2(sm, key, ver, key_info) < 0) in wpa_supplicant_process_1_of_2()
1670 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, "WPA: Group rekeying " in wpa_supplicant_process_1_of_2()
1672 MAC2STR(sm->bssid), wpa_cipher_txt(sm->group_cipher)); in wpa_supplicant_process_1_of_2()
1673 wpa_sm_cancel_auth_timeout(sm); in wpa_supplicant_process_1_of_2()
1674 wpa_sm_set_state(sm, WPA_COMPLETED); in wpa_supplicant_process_1_of_2()
1676 wpa_supplicant_key_neg_complete(sm, sm->bssid, in wpa_supplicant_process_1_of_2()
1681 wpa_sm_set_rekey_offload(sm); in wpa_supplicant_process_1_of_2()
1687 wpa_sm_deauthenticate(sm, WLAN_REASON_UNSPECIFIED); in wpa_supplicant_process_1_of_2()
1691 static int wpa_supplicant_verify_eapol_key_mic(struct wpa_sm *sm, in wpa_supplicant_verify_eapol_key_mic() argument
1698 size_t mic_len = wpa_mic_len(sm->key_mgmt); in wpa_supplicant_verify_eapol_key_mic()
1701 if (sm->tptk_set) { in wpa_supplicant_verify_eapol_key_mic()
1703 wpa_eapol_key_mic(sm->tptk.kck, sm->tptk.kck_len, sm->key_mgmt, in wpa_supplicant_verify_eapol_key_mic()
1706 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_verify_eapol_key_mic()
1711 sm->tptk_set = 0; in wpa_supplicant_verify_eapol_key_mic()
1712 sm->ptk_set = 1; in wpa_supplicant_verify_eapol_key_mic()
1713 os_memcpy(&sm->ptk, &sm->tptk, sizeof(sm->ptk)); in wpa_supplicant_verify_eapol_key_mic()
1714 os_memset(&sm->tptk, 0, sizeof(sm->tptk)); in wpa_supplicant_verify_eapol_key_mic()
1718 if (!ok && sm->ptk_set) { in wpa_supplicant_verify_eapol_key_mic()
1720 wpa_eapol_key_mic(sm->ptk.kck, sm->ptk.kck_len, sm->key_mgmt, in wpa_supplicant_verify_eapol_key_mic()
1723 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_verify_eapol_key_mic()
1732 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_verify_eapol_key_mic()
1738 os_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()
1746 static int wpa_supplicant_decrypt_key_data(struct wpa_sm *sm, in wpa_supplicant_decrypt_key_data() argument
1753 if (!sm->ptk_set) { in wpa_supplicant_decrypt_key_data()
1754 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_decrypt_key_data()
1762 if (ver == WPA_KEY_INFO_TYPE_HMAC_MD5_RC4 && sm->ptk.kek_len == 16) { in wpa_supplicant_decrypt_key_data()
1764 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_decrypt_key_data()
1770 os_memcpy(ek + 16, sm->ptk.kek, sm->ptk.kek_len); in wpa_supplicant_decrypt_key_data()
1773 wpa_msg(sm->ctx->msg_ctx, MSG_ERROR, in wpa_supplicant_decrypt_key_data()
1781 sm->key_mgmt == WPA_KEY_MGMT_OSEN || in wpa_supplicant_decrypt_key_data()
1782 wpa_key_mgmt_suite_b(sm->key_mgmt)) { in wpa_supplicant_decrypt_key_data()
1785 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_decrypt_key_data()
1793 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_decrypt_key_data()
1797 if (aes_unwrap(sm->ptk.kek, sm->ptk.kek_len, *key_data_len / 8, in wpa_supplicant_decrypt_key_data()
1800 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_decrypt_key_data()
1809 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_supplicant_decrypt_key_data()
1823 void wpa_sm_aborted_cached(struct wpa_sm *sm) in wpa_sm_aborted_cached() argument
1825 if (sm && sm->cur_pmksa) { in wpa_sm_aborted_cached()
1826 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_sm_aborted_cached()
1828 sm->cur_pmksa = NULL; in wpa_sm_aborted_cached()
1833 static void wpa_eapol_key_dump(struct wpa_sm *sm, in wpa_eapol_key_dump() argument
1841 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, " EAPOL-Key type=%d", key->type); in wpa_eapol_key_dump()
1842 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_eapol_key_dump()
1856 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_eapol_key_dump()
1871 static int wpa_supp_aead_decrypt(struct wpa_sm *sm, u8 *buf, size_t buf_len, in wpa_supp_aead_decrypt() argument
1886 if (sm->tptk_set) in wpa_supp_aead_decrypt()
1887 ptk = &sm->tptk; in wpa_supp_aead_decrypt()
1888 else if (sm->ptk_set) in wpa_supp_aead_decrypt()
1889 ptk = &sm->ptk; in wpa_supp_aead_decrypt()
1924 if (sm->tptk_set) { in wpa_supp_aead_decrypt()
1925 sm->tptk_set = 0; in wpa_supp_aead_decrypt()
1926 sm->ptk_set = 1; in wpa_supp_aead_decrypt()
1927 os_memcpy(&sm->ptk, &sm->tptk, sizeof(sm->ptk)); in wpa_supp_aead_decrypt()
1928 os_memset(&sm->tptk, 0, sizeof(sm->tptk)); in wpa_supp_aead_decrypt()
1931 os_memcpy(sm->rx_replay_counter, key->replay_counter, in wpa_supp_aead_decrypt()
1933 sm->rx_replay_counter_set = 1; in wpa_supp_aead_decrypt()
1956 int wpa_sm_rx_eapol(struct wpa_sm *sm, const u8 *src_addr, in wpa_sm_rx_eapol() argument
1970 sm->ft_completed = 0; in wpa_sm_rx_eapol()
1973 mic_len = wpa_mic_len(sm->key_mgmt); in wpa_sm_rx_eapol()
1977 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_sm_rx_eapol()
1988 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_sm_rx_eapol()
1996 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_sm_rx_eapol()
2004 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_sm_rx_eapol()
2012 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_sm_rx_eapol()
2031 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_sm_rx_eapol()
2039 wpa_eapol_key_dump(sm, key, key_data_len, mic, mic_len); in wpa_sm_rx_eapol()
2042 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, "WPA: Invalid EAPOL-Key " in wpa_sm_rx_eapol()
2049 eapol_sm_notify_lower_layer_success(sm->eapol, 0); in wpa_sm_rx_eapol()
2057 !wpa_key_mgmt_suite_b(sm->key_mgmt) && in wpa_sm_rx_eapol()
2058 !wpa_key_mgmt_fils(sm->key_mgmt) && in wpa_sm_rx_eapol()
2059 sm->key_mgmt != WPA_KEY_MGMT_OSEN) { in wpa_sm_rx_eapol()
2060 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_sm_rx_eapol()
2066 if (sm->key_mgmt == WPA_KEY_MGMT_OSEN && in wpa_sm_rx_eapol()
2068 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_sm_rx_eapol()
2074 if ((wpa_key_mgmt_suite_b(sm->key_mgmt) || in wpa_sm_rx_eapol()
2075 wpa_key_mgmt_fils(sm->key_mgmt)) && in wpa_sm_rx_eapol()
2077 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_sm_rx_eapol()
2084 if (wpa_key_mgmt_ft(sm->key_mgmt)) { in wpa_sm_rx_eapol()
2087 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_sm_rx_eapol()
2094 if (wpa_key_mgmt_sha256(sm->key_mgmt)) { in wpa_sm_rx_eapol()
2096 sm->key_mgmt != WPA_KEY_MGMT_OSEN && in wpa_sm_rx_eapol()
2097 !wpa_key_mgmt_fils(sm->key_mgmt) && in wpa_sm_rx_eapol()
2098 !wpa_key_mgmt_suite_b(sm->key_mgmt)) { in wpa_sm_rx_eapol()
2099 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_sm_rx_eapol()
2106 if (sm->pairwise_cipher == WPA_CIPHER_CCMP && in wpa_sm_rx_eapol()
2107 !wpa_key_mgmt_suite_b(sm->key_mgmt) && in wpa_sm_rx_eapol()
2108 !wpa_key_mgmt_fils(sm->key_mgmt) && in wpa_sm_rx_eapol()
2110 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_sm_rx_eapol()
2113 if (sm->group_cipher != WPA_CIPHER_CCMP && in wpa_sm_rx_eapol()
2119 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_sm_rx_eapol()
2123 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_sm_rx_eapol()
2127 } else if (sm->pairwise_cipher == WPA_CIPHER_GCMP && in wpa_sm_rx_eapol()
2128 !wpa_key_mgmt_suite_b(sm->key_mgmt) && in wpa_sm_rx_eapol()
2130 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_sm_rx_eapol()
2137 for (peerkey = sm->peerkey; peerkey; peerkey = peerkey->next) { in wpa_sm_rx_eapol()
2146 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_sm_rx_eapol()
2157 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_sm_rx_eapol()
2167 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_sm_rx_eapol()
2173 if (!peerkey && sm->rx_replay_counter_set && in wpa_sm_rx_eapol()
2174 os_memcmp(key->replay_counter, sm->rx_replay_counter, in wpa_sm_rx_eapol()
2176 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_sm_rx_eapol()
2187 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_sm_rx_eapol()
2193 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, in wpa_sm_rx_eapol()
2199 wpa_supplicant_verify_eapol_key_mic(sm, key, ver, tmp, data_len)) in wpa_sm_rx_eapol()
2204 peerkey_verify_eapol_key_mic(sm, peerkey, key, ver, tmp, in wpa_sm_rx_eapol()
2211 if (wpa_supp_aead_decrypt(sm, tmp, data_len, &key_data_len)) in wpa_sm_rx_eapol()
2216 if ((sm->proto == WPA_PROTO_RSN || sm->proto == WPA_PROTO_OSEN) && in wpa_sm_rx_eapol()
2218 if (wpa_supplicant_decrypt_key_data(sm, key, mic_len, in wpa_sm_rx_eapol()
2226 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_sm_rx_eapol()
2233 peerkey_rx_eapol_4way(sm, peerkey, key, key_info, ver, in wpa_sm_rx_eapol()
2238 wpa_supplicant_process_3_of_4(sm, key, ver, key_data, in wpa_sm_rx_eapol()
2242 wpa_supplicant_process_1_of_4(sm, src_addr, key, in wpa_sm_rx_eapol()
2248 peerkey_rx_eapol_smk(sm, src_addr, key, key_data, key_data_len, in wpa_sm_rx_eapol()
2254 wpa_supplicant_process_1_of_2(sm, src_addr, key, in wpa_sm_rx_eapol()
2258 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in wpa_sm_rx_eapol()
2273 static u32 wpa_key_mgmt_suite(struct wpa_sm *sm) in wpa_key_mgmt_suite() argument
2275 switch (sm->key_mgmt) { in wpa_key_mgmt_suite()
2277 return ((sm->proto == WPA_PROTO_RSN || in wpa_key_mgmt_suite()
2278 sm->proto == WPA_PROTO_OSEN) ? in wpa_key_mgmt_suite()
2282 return (sm->proto == WPA_PROTO_RSN ? in wpa_key_mgmt_suite()
2298 return (sm->proto == WPA_PROTO_RSN ? in wpa_key_mgmt_suite()
2326 int wpa_sm_get_mib(struct wpa_sm *sm, char *buf, size_t buflen) in wpa_sm_get_mib() argument
2332 if (sm->cur_pmksa) { in wpa_sm_get_mib()
2334 sm->cur_pmksa->pmkid, PMKID_LEN); in wpa_sm_get_mib()
2338 if ((wpa_key_mgmt_wpa_psk(sm->key_mgmt) || in wpa_sm_get_mib()
2339 wpa_key_mgmt_wpa_ieee8021x(sm->key_mgmt)) && in wpa_sm_get_mib()
2340 sm->proto == WPA_PROTO_RSN) in wpa_sm_get_mib()
2360 wpa_cipher_key_len(sm->group_cipher) * 8, in wpa_sm_get_mib()
2361 sm->dot11RSNAConfigPMKLifetime, in wpa_sm_get_mib()
2362 sm->dot11RSNAConfigPMKReauthThreshold, in wpa_sm_get_mib()
2363 sm->dot11RSNAConfigSATimeout); in wpa_sm_get_mib()
2379 RSN_SUITE_ARG(wpa_key_mgmt_suite(sm)), in wpa_sm_get_mib()
2380 RSN_SUITE_ARG(wpa_cipher_to_suite(sm->proto, in wpa_sm_get_mib()
2381 sm->pairwise_cipher)), in wpa_sm_get_mib()
2382 RSN_SUITE_ARG(wpa_cipher_to_suite(sm->proto, in wpa_sm_get_mib()
2383 sm->group_cipher)), in wpa_sm_get_mib()
2385 RSN_SUITE_ARG(wpa_key_mgmt_suite(sm)), in wpa_sm_get_mib()
2386 RSN_SUITE_ARG(wpa_cipher_to_suite(sm->proto, in wpa_sm_get_mib()
2387 sm->pairwise_cipher)), in wpa_sm_get_mib()
2388 RSN_SUITE_ARG(wpa_cipher_to_suite(sm->proto, in wpa_sm_get_mib()
2389 sm->group_cipher)), in wpa_sm_get_mib()
2390 sm->dot11RSNA4WayHandshakeFailures); in wpa_sm_get_mib()
2402 struct wpa_sm *sm = ctx; in wpa_sm_pmksa_free_cb() local
2405 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: PMKSA cache entry free_cb: " in wpa_sm_pmksa_free_cb()
2408 if (sm->cur_pmksa == entry) { in wpa_sm_pmksa_free_cb()
2409 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_sm_pmksa_free_cb()
2412 pmksa_cache_clear_current(sm); in wpa_sm_pmksa_free_cb()
2425 (sm->pmk_len == entry->pmk_len && in wpa_sm_pmksa_free_cb()
2426 os_memcmp(sm->pmk, entry->pmk, sm->pmk_len) == 0)) { in wpa_sm_pmksa_free_cb()
2427 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_sm_pmksa_free_cb()
2429 pmksa_cache_clear_current(sm); in wpa_sm_pmksa_free_cb()
2434 os_memset(sm->pmk, 0, sizeof(sm->pmk)); in wpa_sm_pmksa_free_cb()
2435 wpa_sm_deauthenticate(sm, WLAN_REASON_UNSPECIFIED); in wpa_sm_pmksa_free_cb()
2450 struct wpa_sm *sm; in wpa_sm_init() local
2452 sm = os_zalloc(sizeof(*sm)); in wpa_sm_init()
2453 if (sm == NULL) in wpa_sm_init()
2455 dl_list_init(&sm->pmksa_candidates); in wpa_sm_init()
2456 sm->renew_snonce = 1; in wpa_sm_init()
2457 sm->ctx = ctx; in wpa_sm_init()
2459 sm->dot11RSNAConfigPMKLifetime = 43200; in wpa_sm_init()
2460 sm->dot11RSNAConfigPMKReauthThreshold = 70; in wpa_sm_init()
2461 sm->dot11RSNAConfigSATimeout = 60; in wpa_sm_init()
2463 sm->pmksa = pmksa_cache_init(wpa_sm_pmksa_free_cb, sm, sm); in wpa_sm_init()
2464 if (sm->pmksa == NULL) { in wpa_sm_init()
2465 wpa_msg(sm->ctx->msg_ctx, MSG_ERROR, in wpa_sm_init()
2467 os_free(sm); in wpa_sm_init()
2471 return sm; in wpa_sm_init()
2479 void wpa_sm_deinit(struct wpa_sm *sm) in wpa_sm_deinit() argument
2481 if (sm == NULL) in wpa_sm_deinit()
2483 pmksa_cache_deinit(sm->pmksa); in wpa_sm_deinit()
2484 eloop_cancel_timeout(wpa_sm_start_preauth, sm, NULL); in wpa_sm_deinit()
2485 eloop_cancel_timeout(wpa_sm_rekey_ptk, sm, NULL); in wpa_sm_deinit()
2486 os_free(sm->assoc_wpa_ie); in wpa_sm_deinit()
2487 os_free(sm->ap_wpa_ie); in wpa_sm_deinit()
2488 os_free(sm->ap_rsn_ie); in wpa_sm_deinit()
2489 wpa_sm_drop_sa(sm); in wpa_sm_deinit()
2490 os_free(sm->ctx); in wpa_sm_deinit()
2491 peerkey_deinit(sm); in wpa_sm_deinit()
2493 os_free(sm->assoc_resp_ies); in wpa_sm_deinit()
2496 wpabuf_free(sm->test_assoc_ie); in wpa_sm_deinit()
2498 os_free(sm); in wpa_sm_deinit()
2510 void wpa_sm_notify_assoc(struct wpa_sm *sm, const u8 *bssid) in wpa_sm_notify_assoc() argument
2514 if (sm == NULL) in wpa_sm_notify_assoc()
2517 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_sm_notify_assoc()
2519 os_memcpy(sm->bssid, bssid, ETH_ALEN); in wpa_sm_notify_assoc()
2520 os_memset(sm->rx_replay_counter, 0, WPA_REPLAY_COUNTER_LEN); in wpa_sm_notify_assoc()
2521 sm->rx_replay_counter_set = 0; in wpa_sm_notify_assoc()
2522 sm->renew_snonce = 1; in wpa_sm_notify_assoc()
2523 if (os_memcmp(sm->preauth_bssid, bssid, ETH_ALEN) == 0) in wpa_sm_notify_assoc()
2524 rsn_preauth_deinit(sm); in wpa_sm_notify_assoc()
2527 if (wpa_ft_is_completed(sm)) { in wpa_sm_notify_assoc()
2532 eapol_sm_notify_portValid(sm->eapol, FALSE); in wpa_sm_notify_assoc()
2533 wpa_supplicant_key_neg_complete(sm, sm->bssid, 1); in wpa_sm_notify_assoc()
2536 wpa_ft_prepare_auth_request(sm, NULL); in wpa_sm_notify_assoc()
2542 if (sm->fils_completed) { in wpa_sm_notify_assoc()
2547 wpa_supplicant_key_neg_complete(sm, sm->bssid, 1); in wpa_sm_notify_assoc()
2557 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Clear old PTK"); in wpa_sm_notify_assoc()
2558 sm->ptk_set = 0; in wpa_sm_notify_assoc()
2559 os_memset(&sm->ptk, 0, sizeof(sm->ptk)); in wpa_sm_notify_assoc()
2560 sm->tptk_set = 0; in wpa_sm_notify_assoc()
2561 os_memset(&sm->tptk, 0, sizeof(sm->tptk)); in wpa_sm_notify_assoc()
2562 os_memset(&sm->gtk, 0, sizeof(sm->gtk)); in wpa_sm_notify_assoc()
2563 os_memset(&sm->gtk_wnm_sleep, 0, sizeof(sm->gtk_wnm_sleep)); in wpa_sm_notify_assoc()
2565 os_memset(&sm->igtk, 0, sizeof(sm->igtk)); in wpa_sm_notify_assoc()
2566 os_memset(&sm->igtk_wnm_sleep, 0, sizeof(sm->igtk_wnm_sleep)); in wpa_sm_notify_assoc()
2571 wpa_tdls_assoc(sm); in wpa_sm_notify_assoc()
2575 os_memset(sm->p2p_ip_addr, 0, sizeof(sm->p2p_ip_addr)); in wpa_sm_notify_assoc()
2587 void wpa_sm_notify_disassoc(struct wpa_sm *sm) in wpa_sm_notify_disassoc() argument
2589 eloop_cancel_timeout(wpa_sm_start_preauth, sm, NULL); in wpa_sm_notify_disassoc()
2590 eloop_cancel_timeout(wpa_sm_rekey_ptk, sm, NULL); in wpa_sm_notify_disassoc()
2591 peerkey_deinit(sm); in wpa_sm_notify_disassoc()
2592 rsn_preauth_deinit(sm); in wpa_sm_notify_disassoc()
2593 pmksa_cache_clear_current(sm); in wpa_sm_notify_disassoc()
2594 if (wpa_sm_get_state(sm) == WPA_4WAY_HANDSHAKE) in wpa_sm_notify_disassoc()
2595 sm->dot11RSNA4WayHandshakeFailures++; in wpa_sm_notify_disassoc()
2597 wpa_tdls_disassoc(sm); in wpa_sm_notify_disassoc()
2600 sm->fils_completed = 0; in wpa_sm_notify_disassoc()
2603 sm->ft_reassoc_completed = 0; in wpa_sm_notify_disassoc()
2607 wpa_sm_drop_sa(sm); in wpa_sm_notify_disassoc()
2609 sm->msg_3_of_4_ok = 0; in wpa_sm_notify_disassoc()
2623 void wpa_sm_set_pmk(struct wpa_sm *sm, const u8 *pmk, size_t pmk_len, in wpa_sm_set_pmk() argument
2626 if (sm == NULL) in wpa_sm_set_pmk()
2629 sm->pmk_len = pmk_len; in wpa_sm_set_pmk()
2630 os_memcpy(sm->pmk, pmk, pmk_len); in wpa_sm_set_pmk()
2634 sm->xxkey_len = pmk_len; in wpa_sm_set_pmk()
2635 os_memcpy(sm->xxkey, pmk, pmk_len); in wpa_sm_set_pmk()
2639 pmksa_cache_add(sm->pmksa, pmk, pmk_len, pmkid, NULL, 0, in wpa_sm_set_pmk()
2640 bssid, sm->own_addr, in wpa_sm_set_pmk()
2641 sm->network_ctx, sm->key_mgmt); in wpa_sm_set_pmk()
2653 void wpa_sm_set_pmk_from_pmksa(struct wpa_sm *sm) in wpa_sm_set_pmk_from_pmksa() argument
2655 if (sm == NULL) in wpa_sm_set_pmk_from_pmksa()
2658 if (sm->cur_pmksa) { in wpa_sm_set_pmk_from_pmksa()
2659 sm->pmk_len = sm->cur_pmksa->pmk_len; in wpa_sm_set_pmk_from_pmksa()
2660 os_memcpy(sm->pmk, sm->cur_pmksa->pmk, sm->pmk_len); in wpa_sm_set_pmk_from_pmksa()
2662 sm->pmk_len = PMK_LEN; in wpa_sm_set_pmk_from_pmksa()
2663 os_memset(sm->pmk, 0, PMK_LEN); in wpa_sm_set_pmk_from_pmksa()
2673 void wpa_sm_set_fast_reauth(struct wpa_sm *sm, int fast_reauth) in wpa_sm_set_fast_reauth() argument
2675 if (sm) in wpa_sm_set_fast_reauth()
2676 sm->fast_reauth = fast_reauth; in wpa_sm_set_fast_reauth()
2685 void wpa_sm_set_scard_ctx(struct wpa_sm *sm, void *scard_ctx) in wpa_sm_set_scard_ctx() argument
2687 if (sm == NULL) in wpa_sm_set_scard_ctx()
2689 sm->scard_ctx = scard_ctx; in wpa_sm_set_scard_ctx()
2690 if (sm->preauth_eapol) in wpa_sm_set_scard_ctx()
2691 eapol_sm_register_scard_ctx(sm->preauth_eapol, scard_ctx); in wpa_sm_set_scard_ctx()
2704 void wpa_sm_set_config(struct wpa_sm *sm, struct rsn_supp_config *config) in wpa_sm_set_config() argument
2706 if (!sm) in wpa_sm_set_config()
2710 sm->network_ctx = config->network_ctx; in wpa_sm_set_config()
2711 sm->peerkey_enabled = config->peerkey_enabled; in wpa_sm_set_config()
2712 sm->allowed_pairwise_cipher = config->allowed_pairwise_cipher; in wpa_sm_set_config()
2713 sm->proactive_key_caching = config->proactive_key_caching; in wpa_sm_set_config()
2714 sm->eap_workaround = config->eap_workaround; in wpa_sm_set_config()
2715 sm->eap_conf_ctx = config->eap_conf_ctx; in wpa_sm_set_config()
2717 os_memcpy(sm->ssid, config->ssid, config->ssid_len); in wpa_sm_set_config()
2718 sm->ssid_len = config->ssid_len; in wpa_sm_set_config()
2720 sm->ssid_len = 0; in wpa_sm_set_config()
2721 sm->wpa_ptk_rekey = config->wpa_ptk_rekey; in wpa_sm_set_config()
2722 sm->p2p = config->p2p; in wpa_sm_set_config()
2723 sm->wpa_rsc_relaxation = config->wpa_rsc_relaxation; in wpa_sm_set_config()
2725 sm->network_ctx = NULL; in wpa_sm_set_config()
2726 sm->peerkey_enabled = 0; in wpa_sm_set_config()
2727 sm->allowed_pairwise_cipher = 0; in wpa_sm_set_config()
2728 sm->proactive_key_caching = 0; in wpa_sm_set_config()
2729 sm->eap_workaround = 0; in wpa_sm_set_config()
2730 sm->eap_conf_ctx = NULL; in wpa_sm_set_config()
2731 sm->ssid_len = 0; in wpa_sm_set_config()
2732 sm->wpa_ptk_rekey = 0; in wpa_sm_set_config()
2733 sm->p2p = 0; in wpa_sm_set_config()
2734 sm->wpa_rsc_relaxation = 0; in wpa_sm_set_config()
2744 void wpa_sm_set_own_addr(struct wpa_sm *sm, const u8 *addr) in wpa_sm_set_own_addr() argument
2746 if (sm) in wpa_sm_set_own_addr()
2747 os_memcpy(sm->own_addr, addr, ETH_ALEN); in wpa_sm_set_own_addr()
2757 void wpa_sm_set_ifname(struct wpa_sm *sm, const char *ifname, in wpa_sm_set_ifname() argument
2760 if (sm) { in wpa_sm_set_ifname()
2761 sm->ifname = ifname; in wpa_sm_set_ifname()
2762 sm->bridge_ifname = bridge_ifname; in wpa_sm_set_ifname()
2772 void wpa_sm_set_eapol(struct wpa_sm *sm, struct eapol_sm *eapol) in wpa_sm_set_eapol() argument
2774 if (sm) in wpa_sm_set_eapol()
2775 sm->eapol = eapol; in wpa_sm_set_eapol()
2786 int wpa_sm_set_param(struct wpa_sm *sm, enum wpa_sm_conf_params param, in wpa_sm_set_param() argument
2791 if (sm == NULL) in wpa_sm_set_param()
2797 sm->dot11RSNAConfigPMKLifetime = value; in wpa_sm_set_param()
2803 sm->dot11RSNAConfigPMKReauthThreshold = value; in wpa_sm_set_param()
2809 sm->dot11RSNAConfigSATimeout = value; in wpa_sm_set_param()
2814 sm->proto = value; in wpa_sm_set_param()
2817 sm->pairwise_cipher = value; in wpa_sm_set_param()
2820 sm->group_cipher = value; in wpa_sm_set_param()
2823 sm->key_mgmt = value; in wpa_sm_set_param()
2827 sm->mgmt_group_cipher = value; in wpa_sm_set_param()
2831 sm->rsn_enabled = value; in wpa_sm_set_param()
2834 sm->mfp = value; in wpa_sm_set_param()
2856 int wpa_sm_get_status(struct wpa_sm *sm, char *buf, size_t buflen, in wpa_sm_get_status() argument
2866 wpa_cipher_txt(sm->pairwise_cipher), in wpa_sm_get_status()
2867 wpa_cipher_txt(sm->group_cipher), in wpa_sm_get_status()
2868 wpa_key_mgmt_txt(sm->key_mgmt, sm->proto)); in wpa_sm_get_status()
2873 if (sm->mfp != NO_MGMT_FRAME_PROTECTION && sm->ap_rsn_ie) { in wpa_sm_get_status()
2875 if (wpa_parse_wpa_ie_rsn(sm->ap_rsn_ie, sm->ap_rsn_ie_len, &rsn) in wpa_sm_get_status()
2892 int wpa_sm_pmf_enabled(struct wpa_sm *sm) in wpa_sm_pmf_enabled() argument
2896 if (sm->mfp == NO_MGMT_FRAME_PROTECTION || !sm->ap_rsn_ie) in wpa_sm_pmf_enabled()
2899 if (wpa_parse_wpa_ie_rsn(sm->ap_rsn_ie, sm->ap_rsn_ie_len, &rsn) >= 0 && in wpa_sm_pmf_enabled()
2914 int wpa_sm_set_assoc_wpa_ie_default(struct wpa_sm *sm, u8 *wpa_ie, in wpa_sm_set_assoc_wpa_ie_default() argument
2919 if (sm == NULL) in wpa_sm_set_assoc_wpa_ie_default()
2923 if (sm->test_assoc_ie) { in wpa_sm_set_assoc_wpa_ie_default()
2926 if (*wpa_ie_len < wpabuf_len(sm->test_assoc_ie)) in wpa_sm_set_assoc_wpa_ie_default()
2928 os_memcpy(wpa_ie, wpabuf_head(sm->test_assoc_ie), in wpa_sm_set_assoc_wpa_ie_default()
2929 wpabuf_len(sm->test_assoc_ie)); in wpa_sm_set_assoc_wpa_ie_default()
2930 res = wpabuf_len(sm->test_assoc_ie); in wpa_sm_set_assoc_wpa_ie_default()
2933 res = wpa_gen_wpa_ie(sm, wpa_ie, *wpa_ie_len); in wpa_sm_set_assoc_wpa_ie_default()
2941 if (sm->assoc_wpa_ie == NULL) { in wpa_sm_set_assoc_wpa_ie_default()
2947 sm->assoc_wpa_ie = os_malloc(*wpa_ie_len); in wpa_sm_set_assoc_wpa_ie_default()
2948 if (sm->assoc_wpa_ie == NULL) in wpa_sm_set_assoc_wpa_ie_default()
2951 os_memcpy(sm->assoc_wpa_ie, wpa_ie, *wpa_ie_len); in wpa_sm_set_assoc_wpa_ie_default()
2952 sm->assoc_wpa_ie_len = *wpa_ie_len; in wpa_sm_set_assoc_wpa_ie_default()
2956 sm->assoc_wpa_ie, sm->assoc_wpa_ie_len); in wpa_sm_set_assoc_wpa_ie_default()
2974 int wpa_sm_set_assoc_wpa_ie(struct wpa_sm *sm, const u8 *ie, size_t len) in wpa_sm_set_assoc_wpa_ie() argument
2976 if (sm == NULL) in wpa_sm_set_assoc_wpa_ie()
2979 os_free(sm->assoc_wpa_ie); in wpa_sm_set_assoc_wpa_ie()
2981 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_sm_set_assoc_wpa_ie()
2983 sm->assoc_wpa_ie = NULL; in wpa_sm_set_assoc_wpa_ie()
2984 sm->assoc_wpa_ie_len = 0; in wpa_sm_set_assoc_wpa_ie()
2987 sm->assoc_wpa_ie = os_malloc(len); in wpa_sm_set_assoc_wpa_ie()
2988 if (sm->assoc_wpa_ie == NULL) in wpa_sm_set_assoc_wpa_ie()
2991 os_memcpy(sm->assoc_wpa_ie, ie, len); in wpa_sm_set_assoc_wpa_ie()
2992 sm->assoc_wpa_ie_len = len; in wpa_sm_set_assoc_wpa_ie()
3009 int wpa_sm_set_ap_wpa_ie(struct wpa_sm *sm, const u8 *ie, size_t len) in wpa_sm_set_ap_wpa_ie() argument
3011 if (sm == NULL) in wpa_sm_set_ap_wpa_ie()
3014 os_free(sm->ap_wpa_ie); in wpa_sm_set_ap_wpa_ie()
3016 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_sm_set_ap_wpa_ie()
3018 sm->ap_wpa_ie = NULL; in wpa_sm_set_ap_wpa_ie()
3019 sm->ap_wpa_ie_len = 0; in wpa_sm_set_ap_wpa_ie()
3022 sm->ap_wpa_ie = os_malloc(len); in wpa_sm_set_ap_wpa_ie()
3023 if (sm->ap_wpa_ie == NULL) in wpa_sm_set_ap_wpa_ie()
3026 os_memcpy(sm->ap_wpa_ie, ie, len); in wpa_sm_set_ap_wpa_ie()
3027 sm->ap_wpa_ie_len = len; in wpa_sm_set_ap_wpa_ie()
3044 int wpa_sm_set_ap_rsn_ie(struct wpa_sm *sm, const u8 *ie, size_t len) in wpa_sm_set_ap_rsn_ie() argument
3046 if (sm == NULL) in wpa_sm_set_ap_rsn_ie()
3049 os_free(sm->ap_rsn_ie); in wpa_sm_set_ap_rsn_ie()
3051 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_sm_set_ap_rsn_ie()
3053 sm->ap_rsn_ie = NULL; in wpa_sm_set_ap_rsn_ie()
3054 sm->ap_rsn_ie_len = 0; in wpa_sm_set_ap_rsn_ie()
3057 sm->ap_rsn_ie = os_malloc(len); in wpa_sm_set_ap_rsn_ie()
3058 if (sm->ap_rsn_ie == NULL) in wpa_sm_set_ap_rsn_ie()
3061 os_memcpy(sm->ap_rsn_ie, ie, len); in wpa_sm_set_ap_rsn_ie()
3062 sm->ap_rsn_ie_len = len; in wpa_sm_set_ap_rsn_ie()
3078 int wpa_sm_parse_own_wpa_ie(struct wpa_sm *sm, struct wpa_ie_data *data) in wpa_sm_parse_own_wpa_ie() argument
3080 if (sm == NULL) in wpa_sm_parse_own_wpa_ie()
3083 if (sm->assoc_wpa_ie == NULL) { in wpa_sm_parse_own_wpa_ie()
3084 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, in wpa_sm_parse_own_wpa_ie()
3088 if (wpa_parse_wpa_ie(sm->assoc_wpa_ie, sm->assoc_wpa_ie_len, data)) in wpa_sm_parse_own_wpa_ie()
3094 int wpa_sm_pmksa_cache_list(struct wpa_sm *sm, char *buf, size_t len) in wpa_sm_pmksa_cache_list() argument
3096 return pmksa_cache_list(sm->pmksa, buf, len); in wpa_sm_pmksa_cache_list()
3100 struct rsn_pmksa_cache_entry * wpa_sm_pmksa_cache_head(struct wpa_sm *sm) in wpa_sm_pmksa_cache_head() argument
3102 return pmksa_cache_head(sm->pmksa); in wpa_sm_pmksa_cache_head()
3107 wpa_sm_pmksa_cache_add_entry(struct wpa_sm *sm, in wpa_sm_pmksa_cache_add_entry() argument
3110 return pmksa_cache_add_entry(sm->pmksa, entry); in wpa_sm_pmksa_cache_add_entry()
3114 void wpa_sm_drop_sa(struct wpa_sm *sm) in wpa_sm_drop_sa() argument
3116 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Clear old PMK and PTK"); in wpa_sm_drop_sa()
3117 sm->ptk_set = 0; in wpa_sm_drop_sa()
3118 sm->tptk_set = 0; in wpa_sm_drop_sa()
3119 os_memset(sm->pmk, 0, sizeof(sm->pmk)); in wpa_sm_drop_sa()
3120 os_memset(&sm->ptk, 0, sizeof(sm->ptk)); in wpa_sm_drop_sa()
3121 os_memset(&sm->tptk, 0, sizeof(sm->tptk)); in wpa_sm_drop_sa()
3122 os_memset(&sm->gtk, 0, sizeof(sm->gtk)); in wpa_sm_drop_sa()
3123 os_memset(&sm->gtk_wnm_sleep, 0, sizeof(sm->gtk_wnm_sleep)); in wpa_sm_drop_sa()
3125 os_memset(&sm->igtk, 0, sizeof(sm->igtk)); in wpa_sm_drop_sa()
3126 os_memset(&sm->igtk_wnm_sleep, 0, sizeof(sm->igtk_wnm_sleep)); in wpa_sm_drop_sa()
3129 os_memset(sm->xxkey, 0, sizeof(sm->xxkey)); in wpa_sm_drop_sa()
3130 os_memset(sm->pmk_r0, 0, sizeof(sm->pmk_r0)); in wpa_sm_drop_sa()
3131 os_memset(sm->pmk_r1, 0, sizeof(sm->pmk_r1)); in wpa_sm_drop_sa()
3136 int wpa_sm_has_ptk(struct wpa_sm *sm) in wpa_sm_has_ptk() argument
3138 if (sm == NULL) in wpa_sm_has_ptk()
3140 return sm->ptk_set; in wpa_sm_has_ptk()
3144 void wpa_sm_update_replay_ctr(struct wpa_sm *sm, const u8 *replay_ctr) in wpa_sm_update_replay_ctr() argument
3146 os_memcpy(sm->rx_replay_counter, replay_ctr, WPA_REPLAY_COUNTER_LEN); in wpa_sm_update_replay_ctr()
3150 void wpa_sm_pmksa_cache_flush(struct wpa_sm *sm, void *network_ctx) in wpa_sm_pmksa_cache_flush() argument
3152 pmksa_cache_flush(sm->pmksa, network_ctx, NULL, 0); in wpa_sm_pmksa_cache_flush()
3157 int wpa_wnmsleep_install_key(struct wpa_sm *sm, u8 subelem_id, u8 *buf) in wpa_wnmsleep_install_key() argument
3167 keylen = wpa_cipher_key_len(sm->group_cipher); in wpa_wnmsleep_install_key()
3168 gd.key_rsc_len = wpa_cipher_rsc_len(sm->group_cipher); in wpa_wnmsleep_install_key()
3169 gd.alg = wpa_cipher_to_alg(sm->group_cipher); in wpa_wnmsleep_install_key()
3185 sm, !!(keyinfo & WPA_KEY_INFO_TXRX)); in wpa_wnmsleep_install_key()
3191 if (wpa_supplicant_install_gtk(sm, &gd, key_rsc, 1)) { in wpa_wnmsleep_install_key()
3203 if (wpa_supplicant_install_igtk(sm, igtk, 1) < 0) in wpa_wnmsleep_install_key()
3217 int wpa_sm_rx_eapol_peerkey(struct wpa_sm *sm, const u8 *src_addr, in wpa_sm_rx_eapol_peerkey() argument
3222 for (peerkey = sm->peerkey; peerkey; peerkey = peerkey->next) { in wpa_sm_rx_eapol_peerkey()
3230 wpa_sm_rx_eapol(sm, src_addr, buf, len); in wpa_sm_rx_eapol_peerkey()
3239 int wpa_sm_get_p2p_ip_addr(struct wpa_sm *sm, u8 *buf) in wpa_sm_get_p2p_ip_addr() argument
3241 if (sm == NULL || WPA_GET_BE32(sm->p2p_ip_addr) == 0) in wpa_sm_get_p2p_ip_addr()
3243 os_memcpy(buf, sm->p2p_ip_addr, 3 * 4); in wpa_sm_get_p2p_ip_addr()
3250 void wpa_sm_set_rx_replay_ctr(struct wpa_sm *sm, const u8 *rx_replay_counter) in wpa_sm_set_rx_replay_ctr() argument
3255 os_memcpy(sm->rx_replay_counter, rx_replay_counter, in wpa_sm_set_rx_replay_ctr()
3257 sm->rx_replay_counter_set = 1; in wpa_sm_set_rx_replay_ctr()
3262 void wpa_sm_set_ptk_kck_kek(struct wpa_sm *sm, in wpa_sm_set_ptk_kck_kek() argument
3267 os_memcpy(sm->ptk.kck, ptk_kck, ptk_kck_len); in wpa_sm_set_ptk_kck_kek()
3268 sm->ptk.kck_len = ptk_kck_len; in wpa_sm_set_ptk_kck_kek()
3272 os_memcpy(sm->ptk.kek, ptk_kek, ptk_kek_len); in wpa_sm_set_ptk_kck_kek()
3273 sm->ptk.kek_len = ptk_kek_len; in wpa_sm_set_ptk_kck_kek()
3276 sm->ptk_set = 1; in wpa_sm_set_ptk_kck_kek()
3281 void wpa_sm_set_test_assoc_ie(struct wpa_sm *sm, struct wpabuf *buf) in wpa_sm_set_test_assoc_ie() argument
3283 wpabuf_free(sm->test_assoc_ie); in wpa_sm_set_test_assoc_ie()
3284 sm->test_assoc_ie = buf; in wpa_sm_set_test_assoc_ie()
3291 struct wpabuf * fils_build_auth(struct wpa_sm *sm) in fils_build_auth() argument
3296 erp_msg = eapol_sm_build_erp_reauth_start(sm->eapol); in fils_build_auth()
3297 if (!erp_msg && !sm->cur_pmksa) { in fils_build_auth()
3304 erp_msg != NULL, sm->cur_pmksa != NULL); in fils_build_auth()
3306 sm->fils_completed = 0; in fils_build_auth()
3308 if (!sm->assoc_wpa_ie) { in fils_build_auth()
3313 if (random_get_bytes(sm->fils_nonce, FILS_NONCE_LEN) < 0 || in fils_build_auth()
3314 random_get_bytes(sm->fils_session, FILS_SESSION_LEN) < 0) in fils_build_auth()
3318 sm->fils_nonce, FILS_NONCE_LEN); in fils_build_auth()
3320 sm->fils_session, FILS_SESSION_LEN); in fils_build_auth()
3322 buf = wpabuf_alloc(1000 + sm->assoc_wpa_ie_len); in fils_build_auth()
3339 sm->assoc_wpa_ie, sm->assoc_wpa_ie_len); in fils_build_auth()
3340 wpabuf_put_data(buf, sm->assoc_wpa_ie, sm->assoc_wpa_ie_len); in fils_build_auth()
3350 wpabuf_put_data(buf, sm->fils_nonce, FILS_NONCE_LEN); in fils_build_auth()
3357 wpabuf_put_data(buf, sm->fils_session, FILS_SESSION_LEN); in fils_build_auth()
3360 sm->fils_erp_pmkid_set = 0; in fils_build_auth()
3369 if (fils_pmkid_erp(sm->key_mgmt, wpabuf_head(erp_msg), in fils_build_auth()
3371 sm->fils_erp_pmkid) == 0) in fils_build_auth()
3372 sm->fils_erp_pmkid_set = 1; in fils_build_auth()
3384 int fils_process_auth(struct wpa_sm *sm, const u8 *data, size_t len) in fils_process_auth() argument
3422 os_memcpy(sm->fils_anonce, elems.fils_nonce, FILS_NONCE_LEN); in fils_process_auth()
3423 wpa_hexdump(MSG_DEBUG, "FILS: ANonce", sm->fils_anonce, FILS_NONCE_LEN); in fils_process_auth()
3438 if (os_memcmp(sm->cur_pmksa->pmkid, rsn.pmkid, PMKID_LEN) != 0) in fils_process_auth()
3442 sm->cur_pmksa->pmkid, PMKID_LEN); in fils_process_auth()
3449 if (!pmkid_match && sm->cur_pmksa) { in fils_process_auth()
3452 sm->cur_pmksa = NULL; in fils_process_auth()
3462 if (os_memcmp(sm->fils_session, elems.fils_session, FILS_SESSION_LEN) in fils_process_auth()
3466 sm->fils_session, FILS_SESSION_LEN); in fils_process_auth()
3471 if (!sm->cur_pmksa && elems.fils_wrapped_data) { in fils_process_auth()
3478 eapol_sm_process_erp_finish(sm->eapol, elems.fils_wrapped_data, in fils_process_auth()
3480 if (eapol_sm_failed(sm->eapol)) in fils_process_auth()
3484 res = eapol_sm_get_key(sm->eapol, rmsk, rmsk_len); in fils_process_auth()
3487 res = eapol_sm_get_key(sm->eapol, rmsk, rmsk_len); in fils_process_auth()
3492 res = fils_rmsk_to_pmk(sm->key_mgmt, rmsk, rmsk_len, in fils_process_auth()
3493 sm->fils_nonce, sm->fils_anonce, NULL, 0, in fils_process_auth()
3494 sm->pmk, &sm->pmk_len); in fils_process_auth()
3499 if (!sm->fils_erp_pmkid_set) { in fils_process_auth()
3503 wpa_hexdump(MSG_DEBUG, "FILS: PMKID", sm->fils_erp_pmkid, in fils_process_auth()
3506 sm->cur_pmksa = pmksa_cache_add(sm->pmksa, sm->pmk, sm->pmk_len, in fils_process_auth()
3507 sm->fils_erp_pmkid, NULL, 0, in fils_process_auth()
3508 sm->bssid, sm->own_addr, in fils_process_auth()
3509 sm->network_ctx, sm->key_mgmt); in fils_process_auth()
3512 if (!sm->cur_pmksa) { in fils_process_auth()
3518 if (fils_pmk_to_ptk(sm->pmk, sm->pmk_len, sm->own_addr, sm->bssid, in fils_process_auth()
3519 sm->fils_nonce, sm->fils_anonce, &sm->ptk, in fils_process_auth()
3520 ick, &ick_len, sm->key_mgmt, sm->pairwise_cipher) < in fils_process_auth()
3525 sm->ptk_set = 1; in fils_process_auth()
3526 sm->tptk_set = 0; in fils_process_auth()
3527 os_memset(&sm->tptk, 0, sizeof(sm->tptk)); in fils_process_auth()
3529 res = fils_key_auth_sk(ick, ick_len, sm->fils_nonce, in fils_process_auth()
3530 sm->fils_anonce, sm->own_addr, sm->bssid, in fils_process_auth()
3532 sm->key_mgmt, sm->fils_key_auth_sta, in fils_process_auth()
3533 sm->fils_key_auth_ap, in fils_process_auth()
3534 &sm->fils_key_auth_len); in fils_process_auth()
3540 struct wpabuf * fils_build_assoc_req(struct wpa_sm *sm, const u8 **kek, in fils_build_assoc_req() argument
3562 wpabuf_put_data(buf, sm->fils_session, FILS_SESSION_LEN); in fils_build_assoc_req()
3571 wpabuf_put_u8(buf, 1 + sm->fils_key_auth_len); /* Length */ in fils_build_assoc_req()
3574 wpabuf_put_data(buf, sm->fils_key_auth_sta, sm->fils_key_auth_len); in fils_build_assoc_req()
3609 *kek = sm->ptk.kek; in fils_build_assoc_req()
3610 *kek_len = sm->ptk.kek_len; in fils_build_assoc_req()
3612 *snonce = sm->fils_nonce; in fils_build_assoc_req()
3615 *anonce = sm->fils_anonce; in fils_build_assoc_req()
3623 static void fils_process_hlp_resp(struct wpa_sm *sm, const u8 *resp, size_t len) in fils_process_hlp_resp() argument
3635 wpa_sm_fils_hlp_rx(sm, resp, resp + ETH_ALEN, pos, end - pos); in fils_process_hlp_resp()
3639 static void fils_process_hlp_container(struct wpa_sm *sm, const u8 *pos, in fils_process_hlp_container() argument
3681 fils_process_hlp_resp(sm, tmp, tmp_pos - tmp); in fils_process_hlp_container()
3688 int fils_process_assoc_resp(struct wpa_sm *sm, const u8 *resp, size_t len) in fils_process_assoc_resp() argument
3699 if (!sm || !sm->ptk_set) { in fils_process_assoc_resp()
3704 if (!wpa_key_mgmt_fils(sm->key_mgmt)) { in fils_process_assoc_resp()
3731 if (os_memcmp(elems.fils_session, sm->fils_session, in fils_process_assoc_resp()
3737 sm->fils_session, FILS_SESSION_LEN); in fils_process_assoc_resp()
3746 if (elems.fils_key_confirm_len != sm->fils_key_auth_len) { in fils_process_assoc_resp()
3750 (int) sm->fils_key_auth_len); in fils_process_assoc_resp()
3753 if (os_memcmp(elems.fils_key_confirm, sm->fils_key_auth_ap, in fils_process_assoc_resp()
3754 sm->fils_key_auth_len) != 0) { in fils_process_assoc_resp()
3760 sm->fils_key_auth_ap, sm->fils_key_auth_len); in fils_process_assoc_resp()
3783 if (wpa_supplicant_check_group_cipher(sm, sm->group_cipher, in fils_process_assoc_resp()
3790 gd.tx = wpa_supplicant_gtk_tx_bit_workaround(sm, in fils_process_assoc_resp()
3800 if (wpa_supplicant_install_gtk(sm, &gd, elems.key_delivery) < 0) { in fils_process_assoc_resp()
3805 if (ieee80211w_set_keys(sm, &kde) < 0) { in fils_process_assoc_resp()
3810 alg = wpa_cipher_to_alg(sm->pairwise_cipher); in fils_process_assoc_resp()
3811 keylen = wpa_cipher_key_len(sm->pairwise_cipher); in fils_process_assoc_resp()
3812 rsclen = wpa_cipher_rsc_len(sm->pairwise_cipher); in fils_process_assoc_resp()
3814 sm->ptk.tk, keylen); in fils_process_assoc_resp()
3815 if (wpa_sm_set_key(sm, alg, sm->bssid, 0, 1, null_rsc, rsclen, in fils_process_assoc_resp()
3816 sm->ptk.tk, keylen) < 0) { in fils_process_assoc_resp()
3817 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, in fils_process_assoc_resp()
3820 alg, keylen, MAC2STR(sm->bssid)); in fils_process_assoc_resp()
3827 os_memset(sm->ptk.tk, 0, WPA_TK_MAX_LEN); in fils_process_assoc_resp()
3828 sm->ptk.installed = 1; in fils_process_assoc_resp()
3831 fils_process_hlp_container(sm, ie_start, end - ie_start); in fils_process_assoc_resp()
3836 sm->fils_completed = 1; in fils_process_assoc_resp()
3846 int wpa_fils_is_completed(struct wpa_sm *sm) in wpa_fils_is_completed() argument
3849 return sm && sm->fils_completed; in wpa_fils_is_completed()