Lines Matching refs:sm

40  * @sm: Pointer to WPA state machine data from wpa_sm_init()
50 int wpa_eapol_key_send(struct wpa_sm *sm, struct wpa_ptk *ptk,
55 size_t mic_len = wpa_mic_len(sm->key_mgmt, sm->pmk_len);
59 MAC2STR(dest), ver, (int) mic_len, sm->key_mgmt);
60 if (is_zero_ether_addr(dest) && is_zero_ether_addr(sm->bssid)) {
65 if (wpa_sm_get_bssid(sm, sm->bssid) < 0) {
66 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
70 dest = sm->bssid;
71 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
83 wpa_eapol_key_mic(ptk->kck, ptk->kck_len, sm->key_mgmt, ver,
85 wpa_msg(sm->ctx->msg_ctx, MSG_ERROR,
87 ver, sm->key_mgmt);
161 ret = wpa_sm_ether_send(sm, dest, proto, msg, msg_len);
162 eapol_sm_notify_tx_eapol_key(sm->eapol);
171 * @sm: Pointer to WPA state machine data from wpa_sm_init()
179 void wpa_sm_key_request(struct wpa_sm *sm, int error, int pairwise)
186 if (wpa_use_akm_defined(sm->key_mgmt))
188 else if (wpa_key_mgmt_ft(sm->key_mgmt) ||
189 wpa_key_mgmt_sha256(sm->key_mgmt))
191 else if (sm->pairwise_cipher != WPA_CIPHER_TKIP)
196 if (wpa_sm_get_bssid(sm, bssid) < 0) {
197 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
202 mic_len = wpa_mic_len(sm->key_mgmt, sm->pmk_len);
204 rbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY, NULL,
209 reply->type = (sm->proto == WPA_PROTO_RSN ||
210 sm->proto == WPA_PROTO_OSEN) ?
213 if (sm->ptk_set)
215 if (sm->ptk_set && mic_len)
223 os_memcpy(reply->replay_counter, sm->request_counter,
225 inc_byte_array(sm->request_counter, WPA_REPLAY_COUNTER_LEN);
234 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
237 error, pairwise, sm->ptk_set, (unsigned long) rlen);
238 wpa_eapol_key_send(sm, &sm->ptk, ver, bssid, ETH_P_EAPOL, rbuf, rlen,
243 static void wpa_supplicant_key_mgmt_set_pmk(struct wpa_sm *sm)
246 if (sm->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X) {
247 if (wpa_sm_key_mgmt_set_pmk(sm, sm->xxkey, sm->xxkey_len))
248 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
252 if (wpa_sm_key_mgmt_set_pmk(sm, sm->pmk, sm->pmk_len))
253 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
261 static int wpa_supplicant_get_pmk(struct wpa_sm *sm,
267 if (pmkid && !sm->cur_pmksa) {
272 sm->cur_pmksa = pmksa_cache_get(sm->pmksa, src_addr, pmkid,
274 if (sm->cur_pmksa) {
275 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
278 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
284 if (pmkid && sm->cur_pmksa &&
285 os_memcmp_const(pmkid, sm->cur_pmksa->pmkid, PMKID_LEN) == 0) {
287 wpa_sm_set_pmk_from_pmksa(sm);
289 sm->pmk, sm->pmk_len);
290 eapol_sm_notify_cached(sm->eapol);
292 sm->xxkey_len = 0;
294 if (sm->key_mgmt == WPA_KEY_MGMT_FT_SAE &&
295 sm->pmk_len == PMK_LEN) {
301 os_memcpy(sm->xxkey, sm->pmk, sm->pmk_len);
302 sm->xxkey_len = sm->pmk_len;
306 } else if (wpa_key_mgmt_wpa_ieee8021x(sm->key_mgmt) && sm->eapol) {
312 if (wpa_key_mgmt_sha384(sm->key_mgmt))
316 res = eapol_sm_get_key(sm->eapol, sm->pmk, pmk_len);
323 res = eapol_sm_get_key(sm->eapol, sm->pmk, 16);
329 eapol_sm_get_key(sm->eapol, buf, 2 * PMK_LEN) == 0) {
330 if (wpa_key_mgmt_sha384(sm->key_mgmt)) {
331 os_memcpy(sm->xxkey, buf, SHA384_MAC_LEN);
332 sm->xxkey_len = SHA384_MAC_LEN;
334 os_memcpy(sm->xxkey, buf + PMK_LEN, PMK_LEN);
335 sm->xxkey_len = PMK_LEN;
338 if (sm->proto == WPA_PROTO_RSN &&
339 wpa_key_mgmt_ft(sm->key_mgmt)) {
344 if (sm->fils_cache_id_set)
345 fils_cache_id = sm->fils_cache_id;
349 sm->xxkey, sm->xxkey_len);
350 sa = pmksa_cache_add(sm->pmksa,
351 sm->xxkey, sm->xxkey_len,
353 src_addr, sm->own_addr,
354 sm->network_ctx,
355 sm->key_mgmt,
357 if (!sm->cur_pmksa)
358 sm->cur_pmksa = sa;
367 if (sm->fils_cache_id_set)
368 fils_cache_id = sm->fils_cache_id;
372 "machines", sm->pmk, pmk_len);
373 sm->pmk_len = pmk_len;
374 wpa_supplicant_key_mgmt_set_pmk(sm);
375 if (sm->proto == WPA_PROTO_RSN &&
376 !wpa_key_mgmt_suite_b(sm->key_mgmt) &&
377 !wpa_key_mgmt_ft(sm->key_mgmt)) {
378 sa = pmksa_cache_add(sm->pmksa,
379 sm->pmk, pmk_len, NULL,
381 src_addr, sm->own_addr,
382 sm->network_ctx,
383 sm->key_mgmt,
386 if (!sm->cur_pmksa && pmkid &&
387 pmksa_cache_get(sm->pmksa, src_addr, pmkid, NULL,
389 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
393 } else if (sa && !sm->cur_pmksa && pmkid) {
401 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
406 if (!sm->cur_pmksa)
407 sm->cur_pmksa = sa;
409 } else if (wpa_key_mgmt_ft(sm->key_mgmt) && sm->ft_protocol) {
414 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
418 if (sm->cur_pmksa) {
419 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
422 sm->cur_pmksa = NULL;
430 if (abort_cached && wpa_key_mgmt_wpa_ieee8021x(sm->key_mgmt) &&
431 !wpa_key_mgmt_suite_b(sm->key_mgmt) &&
432 !wpa_key_mgmt_ft(sm->key_mgmt) && sm->key_mgmt != WPA_KEY_MGMT_OSEN)
438 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
441 buf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_START,
444 wpa_sm_ether_send(sm, sm->bssid, ETH_P_EAPOL,
459 * @sm: Pointer to WPA state machine data from wpa_sm_init()
469 int wpa_supplicant_send_2_of_4(struct wpa_sm *sm, const unsigned char *dst,
482 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, "WPA: No wpa_ie set - "
488 if (wpa_key_mgmt_ft(sm->key_mgmt)) {
496 sm->assoc_resp_ies_len);
501 sm->pmk_r1_name);
507 if (sm->assoc_resp_ies) {
508 os_memcpy(rsn_ie_buf + wpa_ie_len, sm->assoc_resp_ies,
509 sm->assoc_resp_ies_len);
510 wpa_ie_len += sm->assoc_resp_ies_len;
519 mic_len = wpa_mic_len(sm->key_mgmt, sm->pmk_len);
521 rbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY,
529 reply->type = (sm->proto == WPA_PROTO_RSN ||
530 sm->proto == WPA_PROTO_OSEN) ?
538 if (sm->proto == WPA_PROTO_RSN || sm->proto == WPA_PROTO_OSEN)
554 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Sending EAPOL-Key 2/4");
555 return wpa_eapol_key_send(sm, ptk, ver, dst, ETH_P_EAPOL, rbuf, rlen,
560 static int wpa_derive_ptk(struct wpa_sm *sm, const unsigned char *src_addr,
567 if (wpa_key_mgmt_ft(sm->key_mgmt))
568 return wpa_derive_ptk_ft(sm, src_addr, key, ptk);
572 if (sm->key_mgmt == WPA_KEY_MGMT_DPP && sm->dpp_z) {
573 z = wpabuf_head(sm->dpp_z);
574 z_len = wpabuf_len(sm->dpp_z);
578 return wpa_pmk_to_ptk(sm->pmk, sm->pmk_len, "Pairwise key expansion",
579 sm->own_addr, sm->bssid, sm->snonce,
580 key->key_nonce, ptk, sm->key_mgmt,
581 sm->pairwise_cipher, z, z_len);
585 static void wpa_supplicant_process_1_of_4(struct wpa_sm *sm,
597 if (wpa_sm_get_network_ctx(sm) == NULL) {
598 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, "WPA: No SSID info "
603 wpa_sm_set_state(sm, WPA_4WAY_HANDSHAKE);
604 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: RX message 1 of 4-Way "
609 if (sm->proto == WPA_PROTO_RSN || sm->proto == WPA_PROTO_OSEN) {
621 res = wpa_supplicant_get_pmk(sm, src_addr, ie.pmkid);
623 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: Do not reply to "
630 if (sm->renew_snonce) {
631 if (random_get_bytes(sm->snonce, WPA_NONCE_LEN)) {
632 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
636 sm->renew_snonce = 0;
638 sm->snonce, WPA_NONCE_LEN);
643 ptk = &sm->tptk;
644 if (wpa_derive_ptk(sm, src_addr, key, ptk) < 0)
646 if (sm->pairwise_cipher == WPA_CIPHER_TKIP) {
654 sm->tptk_set = 1;
656 kde = sm->assoc_wpa_ie;
657 kde_len = sm->assoc_wpa_ie_len;
660 if (wpa_sm_ocv_enabled(sm)) {
664 if (wpa_sm_channel_info(sm, &ci) != 0) {
687 if (sm->p2p) {
706 if (wpa_supplicant_send_2_of_4(sm, sm->bssid, key, ver, sm->snonce,
711 os_memcpy(sm->anonce, key->key_nonce, WPA_NONCE_LEN);
716 wpa_sm_deauthenticate(sm, WLAN_REASON_UNSPECIFIED);
722 struct wpa_sm *sm = eloop_ctx;
723 rsn_preauth_candidate_process(sm);
727 static void wpa_supplicant_key_neg_complete(struct wpa_sm *sm,
730 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
733 wpa_cipher_txt(sm->pairwise_cipher),
734 wpa_cipher_txt(sm->group_cipher));
735 wpa_sm_cancel_auth_timeout(sm);
736 wpa_sm_set_state(sm, WPA_COMPLETED);
740 sm, addr, MLME_SETPROTECTION_PROTECT_TYPE_RX_TX,
742 eapol_sm_notify_portValid(sm->eapol, TRUE);
743 if (wpa_key_mgmt_wpa_psk(sm->key_mgmt) ||
744 sm->key_mgmt == WPA_KEY_MGMT_DPP ||
745 sm->key_mgmt == WPA_KEY_MGMT_OWE)
746 eapol_sm_notify_eap_success(sm->eapol, TRUE);
754 if (!dl_list_empty(&sm->pmksa_candidates))
756 sm, NULL);
759 if (sm->cur_pmksa && sm->cur_pmksa->opportunistic) {
760 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
763 sm->cur_pmksa->opportunistic = 0;
767 if (wpa_key_mgmt_ft(sm->key_mgmt)) {
769 wpa_ft_prepare_auth_request(sm, NULL);
777 struct wpa_sm *sm = eloop_ctx;
778 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Request PTK rekeying");
779 wpa_sm_key_request(sm, 0, 1);
783 static int wpa_supplicant_install_ptk(struct wpa_sm *sm,
790 if (sm->ptk.installed) {
791 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
796 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
799 if (sm->pairwise_cipher == WPA_CIPHER_NONE) {
800 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Pairwise Cipher "
805 if (!wpa_cipher_valid_pairwise(sm->pairwise_cipher)) {
806 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
808 sm->pairwise_cipher);
812 alg = wpa_cipher_to_alg(sm->pairwise_cipher);
813 keylen = wpa_cipher_key_len(sm->pairwise_cipher);
814 if (keylen <= 0 || (unsigned int) keylen != sm->ptk.tk_len) {
816 keylen, (long unsigned int) sm->ptk.tk_len);
819 rsclen = wpa_cipher_rsc_len(sm->pairwise_cipher);
821 if (sm->proto == WPA_PROTO_RSN || sm->proto == WPA_PROTO_OSEN) {
828 if (wpa_sm_set_key(sm, alg, sm->bssid, 0, 1, key_rsc, rsclen,
829 sm->ptk.tk, keylen) < 0) {
830 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
833 alg, keylen, MAC2STR(sm->bssid));
838 os_memset(sm->ptk.tk, 0, WPA_TK_MAX_LEN);
839 sm->ptk.tk_len = 0;
840 sm->ptk.installed = 1;
842 if (sm->wpa_ptk_rekey) {
843 eloop_cancel_timeout(wpa_sm_rekey_ptk, sm, NULL);
844 eloop_register_timeout(sm->wpa_ptk_rekey, 0, wpa_sm_rekey_ptk,
845 sm, NULL);
852 static int wpa_supplicant_check_group_cipher(struct wpa_sm *sm,
862 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
871 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
888 static int wpa_supplicant_install_gtk(struct wpa_sm *sm,
896 if ((sm->gtk.gtk_len == (size_t) gd->gtk_len &&
897 os_memcmp(sm->gtk.gtk, gd->gtk, sm->gtk.gtk_len) == 0) ||
898 (sm->gtk_wnm_sleep.gtk_len == (size_t) gd->gtk_len &&
899 os_memcmp(sm->gtk_wnm_sleep.gtk, gd->gtk,
900 sm->gtk_wnm_sleep.gtk_len) == 0)) {
901 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
908 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
912 if (sm->group_cipher == WPA_CIPHER_TKIP) {
919 if (sm->pairwise_cipher == WPA_CIPHER_NONE) {
920 if (wpa_sm_set_key(sm, gd->alg, NULL,
923 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
929 } else if (wpa_sm_set_key(sm, gd->alg, broadcast_ether_addr,
932 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
942 sm->gtk_wnm_sleep.gtk_len = gd->gtk_len;
943 os_memcpy(sm->gtk_wnm_sleep.gtk, gd->gtk,
944 sm->gtk_wnm_sleep.gtk_len);
946 sm->gtk.gtk_len = gd->gtk_len;
947 os_memcpy(sm->gtk.gtk, gd->gtk, sm->gtk.gtk_len);
954 static int wpa_supplicant_gtk_tx_bit_workaround(const struct wpa_sm *sm,
957 if (tx && sm->pairwise_cipher != WPA_CIPHER_NONE) {
963 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
972 static int wpa_supplicant_rsc_relaxation(const struct wpa_sm *sm,
977 if (!sm->wpa_rsc_relaxation)
980 rsclen = wpa_cipher_rsc_len(sm->group_cipher);
990 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
1002 static int wpa_supplicant_pairwise_gtk(struct wpa_sm *sm,
1026 gd.tx = wpa_supplicant_gtk_tx_bit_workaround(sm,
1035 if (wpa_supplicant_rsc_relaxation(sm, key->key_rsc))
1038 if (sm->group_cipher != WPA_CIPHER_GTK_NOT_USED &&
1039 (wpa_supplicant_check_group_cipher(sm, sm->group_cipher,
1042 wpa_supplicant_install_gtk(sm, &gd, key_rsc, 0))) {
1043 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
1055 static int wpa_supplicant_install_igtk(struct wpa_sm *sm,
1059 size_t len = wpa_cipher_key_len(sm->mgmt_group_cipher);
1063 if ((sm->igtk.igtk_len == len &&
1064 os_memcmp(sm->igtk.igtk, igtk->igtk, sm->igtk.igtk_len) == 0) ||
1065 (sm->igtk_wnm_sleep.igtk_len == len &&
1066 os_memcmp(sm->igtk_wnm_sleep.igtk, igtk->igtk,
1067 sm->igtk_wnm_sleep.igtk_len) == 0)) {
1068 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
1074 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
1079 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
1083 if (wpa_sm_set_key(sm, wpa_cipher_to_alg(sm->mgmt_group_cipher),
1101 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
1104 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
1111 sm->igtk_wnm_sleep.igtk_len = len;
1112 os_memcpy(sm->igtk_wnm_sleep.igtk, igtk->igtk,
1113 sm->igtk_wnm_sleep.igtk_len);
1115 sm->igtk.igtk_len = len;
1116 os_memcpy(sm->igtk.igtk, igtk->igtk, sm->igtk.igtk_len);
1124 static int ieee80211w_set_keys(struct wpa_sm *sm,
1128 if (!wpa_cipher_valid_mgmt_group(sm->mgmt_group_cipher))
1135 len = wpa_cipher_key_len(sm->mgmt_group_cipher);
1140 if (wpa_supplicant_install_igtk(sm, igtk, 0) < 0)
1151 static void wpa_report_ie_mismatch(struct wpa_sm *sm,
1156 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, "WPA: %s (src=" MACSTR ")",
1159 if (sm->ap_wpa_ie) {
1161 sm->ap_wpa_ie, sm->ap_wpa_ie_len);
1164 if (!sm->ap_wpa_ie) {
1165 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
1172 if (sm->ap_rsn_ie) {
1174 sm->ap_rsn_ie, sm->ap_rsn_ie_len);
1177 if (!sm->ap_rsn_ie) {
1178 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
1185 wpa_sm_deauthenticate(sm, WLAN_REASON_IE_IN_4WAY_DIFFERS);
1191 static int ft_validate_mdie(struct wpa_sm *sm,
1200 os_memcmp(mdie->mobility_domain, sm->mobility_domain,
1202 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "FT: MDIE in msg 3/4 did "
1210 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "FT: MDIE mismatch");
1222 static int ft_validate_ftie(struct wpa_sm *sm,
1228 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
1238 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "FT: FTIE mismatch");
1250 static int ft_validate_rsnie(struct wpa_sm *sm,
1265 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "FT: No PMKR1Name in "
1270 if (os_memcmp_const(rsn.pmkid, sm->pmk_r1_name, WPA_PMK_NAME_LEN) != 0)
1272 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
1278 sm->pmk_r1_name, WPA_PMK_NAME_LEN);
1286 static int wpa_supplicant_validate_ie_ft(struct wpa_sm *sm,
1292 if (sm->assoc_resp_ies) {
1293 pos = sm->assoc_resp_ies;
1294 end = pos + sm->assoc_resp_ies_len;
1310 if (ft_validate_mdie(sm, src_addr, ie, mdie) < 0 ||
1311 ft_validate_ftie(sm, src_addr, ie, ftie) < 0 ||
1312 ft_validate_rsnie(sm, src_addr, ie) < 0)
1321 static int wpa_supplicant_validate_ie(struct wpa_sm *sm,
1325 if (sm->ap_wpa_ie == NULL && sm->ap_rsn_ie == NULL) {
1326 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
1329 if (wpa_sm_get_beacon_ie(sm) < 0) {
1330 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
1334 wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG,
1341 (sm->ap_wpa_ie || sm->ap_rsn_ie)) {
1342 wpa_report_ie_mismatch(sm, "IE in 3/4 msg does not match "
1349 if ((ie->wpa_ie && sm->ap_wpa_ie &&
1350 (ie->wpa_ie_len != sm->ap_wpa_ie_len ||
1351 os_memcmp(ie->wpa_ie, sm->ap_wpa_ie, ie->wpa_ie_len) != 0)) ||
1352 (ie->rsn_ie && sm->ap_rsn_ie &&
1353 wpa_compare_rsn_ie(wpa_key_mgmt_ft(sm->key_mgmt),
1354 sm->ap_rsn_ie, sm->ap_rsn_ie_len,
1356 wpa_report_ie_mismatch(sm, "IE in 3/4 msg does not match "
1363 if (sm->proto == WPA_PROTO_WPA &&
1364 ie->rsn_ie && sm->ap_rsn_ie == NULL && sm->rsn_enabled) {
1365 wpa_report_ie_mismatch(sm, "Possible downgrade attack "
1375 if (wpa_key_mgmt_ft(sm->key_mgmt) &&
1376 wpa_supplicant_validate_ie_ft(sm, src_addr, ie) < 0)
1386 * @sm: Pointer to WPA state machine data from wpa_sm_init()
1394 int wpa_supplicant_send_4_of_4(struct wpa_sm *sm, const unsigned char *dst,
1403 mic_len = wpa_mic_len(sm->key_mgmt, sm->pmk_len);
1405 rbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY, NULL,
1410 reply->type = (sm->proto == WPA_PROTO_RSN ||
1411 sm->proto == WPA_PROTO_OSEN) ?
1420 if (sm->proto == WPA_PROTO_RSN || sm->proto == WPA_PROTO_OSEN)
1430 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Sending EAPOL-Key 4/4");
1431 return wpa_eapol_key_send(sm, ptk, ver, dst, ETH_P_EAPOL, rbuf, rlen,
1436 static void wpa_supplicant_process_3_of_4(struct wpa_sm *sm,
1444 wpa_sm_set_state(sm, WPA_4WAY_HANDSHAKE);
1445 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: RX message 3 of 4-Way "
1446 "Handshake from " MACSTR " (ver=%d)", MAC2STR(sm->bssid), ver);
1454 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
1460 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
1466 wpa_cipher_valid_mgmt_group(sm->mgmt_group_cipher) &&
1468 (unsigned int) wpa_cipher_key_len(sm->mgmt_group_cipher)) {
1469 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
1476 if (wpa_supplicant_validate_ie(sm, sm->bssid, &ie) < 0)
1479 if (os_memcmp(sm->anonce, key->key_nonce, WPA_NONCE_LEN) != 0) {
1480 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
1483 MACSTR ")", MAC2STR(sm->bssid));
1488 if (keylen != wpa_cipher_key_len(sm->pairwise_cipher)) {
1489 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
1491 ")", wpa_cipher_txt(sm->pairwise_cipher), keylen,
1492 MAC2STR(sm->bssid));
1498 os_memcpy(sm->p2p_ip_addr, ie.ip_addr_alloc, 3 * 4);
1500 sm->p2p_ip_addr, sizeof(sm->p2p_ip_addr));
1505 if (wpa_sm_ocv_enabled(sm)) {
1508 if (wpa_sm_channel_info(sm, &ci) != 0) {
1509 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
1517 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, "%s",
1524 if (wpa_supplicant_send_4_of_4(sm, sm->bssid, key, ver, key_info,
1525 &sm->ptk) < 0) {
1532 sm->renew_snonce = 1;
1535 if (wpa_supplicant_install_ptk(sm, key))
1541 sm, sm->bssid, MLME_SETPROTECTION_PROTECT_TYPE_RX,
1543 eapol_sm_notify_portValid(sm->eapol, TRUE);
1545 wpa_sm_set_state(sm, WPA_GROUP_HANDSHAKE);
1547 if (sm->group_cipher == WPA_CIPHER_GTK_NOT_USED) {
1549 } else if (!ie.gtk && sm->proto == WPA_PROTO_RSN) {
1550 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
1554 wpa_supplicant_pairwise_gtk(sm, key,
1556 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
1561 if (ieee80211w_set_keys(sm, &ie) < 0) {
1562 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
1567 if (sm->group_cipher == WPA_CIPHER_GTK_NOT_USED || ie.gtk)
1568 wpa_supplicant_key_neg_complete(sm, sm->bssid,
1572 wpa_sm_set_rekey_offload(sm);
1579 if (sm->proto == WPA_PROTO_RSN && wpa_key_mgmt_suite_b(sm->key_mgmt) &&
1580 !sm->cur_pmksa) {
1583 sa = pmksa_cache_add(sm->pmksa, sm->pmk, sm->pmk_len, NULL,
1584 sm->ptk.kck, sm->ptk.kck_len,
1585 sm->bssid, sm->own_addr,
1586 sm->network_ctx, sm->key_mgmt, NULL);
1587 if (!sm->cur_pmksa)
1588 sm->cur_pmksa = sa;
1591 sm->msg_3_of_4_ok = 1;
1595 wpa_sm_deauthenticate(sm, WLAN_REASON_UNSPECIFIED);
1599 static int wpa_supplicant_process_1_of_2_rsn(struct wpa_sm *sm,
1613 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
1618 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
1625 if (wpa_sm_ocv_enabled(sm)) {
1628 if (wpa_sm_channel_info(sm, &ci) != 0) {
1629 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
1637 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, "%s",
1644 if (wpa_supplicant_check_group_cipher(sm, sm->group_cipher,
1652 gd->tx = wpa_supplicant_gtk_tx_bit_workaround(sm,
1655 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
1662 if (ieee80211w_set_keys(sm, &ie) < 0)
1663 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
1670 static int wpa_supplicant_process_1_of_2_wpa(struct wpa_sm *sm,
1683 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
1692 wpa_supplicant_check_group_cipher(sm, sm->group_cipher,
1700 if (ver == WPA_KEY_INFO_TYPE_HMAC_MD5_RC4 && sm->ptk.kek_len == 16) {
1702 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
1708 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
1714 os_memcpy(ek + 16, sm->ptk.kek, sm->ptk.kek_len);
1718 wpa_msg(sm->ctx->msg_ctx, MSG_ERROR,
1726 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
1732 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
1739 if (aes_unwrap(sm->ptk.kek, sm->ptk.kek_len, maxkeylen / 8,
1741 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
1747 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
1752 sm, !!(key_info & WPA_KEY_INFO_TXRX));
1757 static int wpa_supplicant_send_2_of_2(struct wpa_sm *sm,
1767 if (wpa_sm_ocv_enabled(sm))
1771 mic_len = wpa_mic_len(sm->key_mgmt, sm->pmk_len);
1773 rbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY, NULL,
1778 reply->type = (sm->proto == WPA_PROTO_RSN ||
1779 sm->proto == WPA_PROTO_OSEN) ?
1788 if (sm->proto == WPA_PROTO_RSN || sm->proto == WPA_PROTO_OSEN)
1799 if (wpa_sm_ocv_enabled(sm)) {
1803 if (wpa_sm_channel_info(sm, &ci) != 0) {
1818 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Sending EAPOL-Key 2/2");
1819 return wpa_eapol_key_send(sm, &sm->ptk, ver, sm->bssid, ETH_P_EAPOL,
1824 static void wpa_supplicant_process_1_of_2(struct wpa_sm *sm,
1835 if (!sm->msg_3_of_4_ok && !wpa_fils_is_completed(sm)) {
1836 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
1843 rekey = wpa_sm_get_state(sm) == WPA_COMPLETED;
1844 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: RX message 1 of Group Key "
1849 if (sm->proto == WPA_PROTO_RSN || sm->proto == WPA_PROTO_OSEN) {
1850 ret = wpa_supplicant_process_1_of_2_rsn(sm, key_data,
1854 ret = wpa_supplicant_process_1_of_2_wpa(sm, key, key_data,
1859 wpa_sm_set_state(sm, WPA_GROUP_HANDSHAKE);
1865 if (wpa_supplicant_rsc_relaxation(sm, key->key_rsc))
1868 if (wpa_supplicant_install_gtk(sm, &gd, key_rsc, 0) ||
1869 wpa_supplicant_send_2_of_2(sm, key, ver, key_info) < 0)
1874 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, "WPA: Group rekeying "
1876 MAC2STR(sm->bssid), wpa_cipher_txt(sm->group_cipher));
1877 wpa_sm_cancel_auth_timeout(sm);
1878 wpa_sm_set_state(sm, WPA_COMPLETED);
1880 wpa_supplicant_key_neg_complete(sm, sm->bssid,
1885 wpa_sm_set_rekey_offload(sm);
1891 wpa_sm_deauthenticate(sm, WLAN_REASON_UNSPECIFIED);
1895 static int wpa_supplicant_verify_eapol_key_mic(struct wpa_sm *sm,
1902 size_t mic_len = wpa_mic_len(sm->key_mgmt, sm->pmk_len);
1905 if (sm->tptk_set) {
1907 if (wpa_eapol_key_mic(sm->tptk.kck, sm->tptk.kck_len,
1908 sm->key_mgmt,
1911 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
1924 sm->tptk_set = 0;
1925 sm->ptk_set = 1;
1926 os_memcpy(&sm->ptk, &sm->tptk, sizeof(sm->ptk));
1927 os_memset(&sm->tptk, 0, sizeof(sm->tptk));
1929 * This assures the same TPTK in sm->tptk can never be
1930 * copied twice to sm->ptk as the new PTK. In
1935 sm->renew_snonce = 1;
1939 if (!ok && sm->ptk_set) {
1941 if (wpa_eapol_key_mic(sm->ptk.kck, sm->ptk.kck_len,
1942 sm->key_mgmt,
1945 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
1962 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
1968 os_memcpy(sm->rx_replay_counter, key->replay_counter,
1970 sm->rx_replay_counter_set = 1;
1976 static int wpa_supplicant_decrypt_key_data(struct wpa_sm *sm,
1983 if (!sm->ptk_set) {
1984 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
1992 if (ver == WPA_KEY_INFO_TYPE_HMAC_MD5_RC4 && sm->ptk.kek_len == 16) {
1994 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
2002 os_memcpy(ek + 16, sm->ptk.kek, sm->ptk.kek_len);
2005 wpa_msg(sm->ctx->msg_ctx, MSG_ERROR,
2013 wpa_use_aes_key_wrap(sm->key_mgmt)) {
2018 (unsigned int) sm->ptk.kek_len);
2020 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
2028 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
2035 if (aes_unwrap(sm->ptk.kek, sm->ptk.kek_len, *key_data_len / 8,
2043 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
2055 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
2067 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2069 void wpa_sm_aborted_cached(struct wpa_sm *sm)
2071 if (sm && sm->cur_pmksa) {
2072 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
2074 sm->cur_pmksa = NULL;
2079 static void wpa_eapol_key_dump(struct wpa_sm *sm,
2087 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, " EAPOL-Key type=%d", key->type);
2088 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
2102 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
2117 static int wpa_supp_aead_decrypt(struct wpa_sm *sm, u8 *buf, size_t buf_len,
2132 if (sm->tptk_set)
2133 ptk = &sm->tptk;
2134 else if (sm->ptk_set)
2135 ptk = &sm->ptk;
2170 if (sm->tptk_set) {
2171 sm->tptk_set = 0;
2172 sm->ptk_set = 1;
2173 os_memcpy(&sm->ptk, &sm->tptk, sizeof(sm->ptk));
2174 os_memset(&sm->tptk, 0, sizeof(sm->tptk));
2177 os_memcpy(sm->rx_replay_counter, key->replay_counter,
2179 sm->rx_replay_counter_set = 1;
2188 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2202 int wpa_sm_rx_eapol(struct wpa_sm *sm, const u8 *src_addr,
2215 sm->ft_completed = 0;
2218 mic_len = wpa_mic_len(sm->key_mgmt, sm->pmk_len);
2222 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
2233 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
2241 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
2249 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
2257 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
2275 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
2283 wpa_eapol_key_dump(sm, key, key_data_len, mic, mic_len);
2286 wpa_msg(sm->ctx->msg_ctx, MSG_INFO, "WPA: Invalid EAPOL-Key "
2293 eapol_sm_notify_lower_layer_success(sm->eapol, 0);
2301 !wpa_use_akm_defined(sm->key_mgmt)) {
2302 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
2308 if (wpa_use_akm_defined(sm->key_mgmt) &&
2310 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
2317 if (wpa_key_mgmt_ft(sm->key_mgmt)) {
2320 !wpa_use_akm_defined(sm->key_mgmt)) {
2321 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
2328 if (wpa_key_mgmt_sha256(sm->key_mgmt)) {
2330 !wpa_use_akm_defined(sm->key_mgmt)) {
2331 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
2338 if (sm->pairwise_cipher == WPA_CIPHER_CCMP &&
2339 !wpa_use_akm_defined(sm->key_mgmt) &&
2341 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
2344 if (sm->group_cipher != WPA_CIPHER_CCMP &&
2350 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
2354 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
2358 } else if (sm->pairwise_cipher == WPA_CIPHER_GCMP &&
2359 !wpa_use_akm_defined(sm->key_mgmt) &&
2361 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
2367 if (sm->rx_replay_counter_set &&
2368 os_memcmp(key->replay_counter, sm->rx_replay_counter,
2370 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
2377 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
2383 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
2389 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
2395 wpa_supplicant_verify_eapol_key_mic(sm, key, ver, tmp, data_len))
2400 if (wpa_supp_aead_decrypt(sm, tmp, data_len, &key_data_len))
2405 if ((sm->proto == WPA_PROTO_RSN || sm->proto == WPA_PROTO_OSEN) &&
2414 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
2418 if (wpa_supplicant_decrypt_key_data(sm, key, mic_len,
2426 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
2434 wpa_supplicant_process_3_of_4(sm, key, ver, key_data,
2438 wpa_supplicant_process_1_of_4(sm, src_addr, key,
2446 wpa_supplicant_process_1_of_2(sm, src_addr, key,
2450 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
2465 static u32 wpa_key_mgmt_suite(struct wpa_sm *sm)
2467 switch (sm->key_mgmt) {
2469 return ((sm->proto == WPA_PROTO_RSN ||
2470 sm->proto == WPA_PROTO_OSEN) ?
2474 return (sm->proto == WPA_PROTO_RSN ?
2490 return (sm->proto == WPA_PROTO_RSN ?
2511 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2518 int wpa_sm_get_mib(struct wpa_sm *sm, char *buf, size_t buflen)
2524 if (sm->cur_pmksa) {
2526 sm->cur_pmksa->pmkid, PMKID_LEN);
2530 if ((wpa_key_mgmt_wpa_psk(sm->key_mgmt) ||
2531 wpa_key_mgmt_wpa_ieee8021x(sm->key_mgmt)) &&
2532 sm->proto == WPA_PROTO_RSN)
2552 wpa_cipher_key_len(sm->group_cipher) * 8,
2553 sm->dot11RSNAConfigPMKLifetime,
2554 sm->dot11RSNAConfigPMKReauthThreshold,
2555 sm->dot11RSNAConfigSATimeout);
2571 RSN_SUITE_ARG(wpa_key_mgmt_suite(sm)),
2572 RSN_SUITE_ARG(wpa_cipher_to_suite(sm->proto,
2573 sm->pairwise_cipher)),
2574 RSN_SUITE_ARG(wpa_cipher_to_suite(sm->proto,
2575 sm->group_cipher)),
2577 RSN_SUITE_ARG(wpa_key_mgmt_suite(sm)),
2578 RSN_SUITE_ARG(wpa_cipher_to_suite(sm->proto,
2579 sm->pairwise_cipher)),
2580 RSN_SUITE_ARG(wpa_cipher_to_suite(sm->proto,
2581 sm->group_cipher)),
2582 sm->dot11RSNA4WayHandshakeFailures);
2594 struct wpa_sm *sm = ctx;
2597 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: PMKSA cache entry free_cb: "
2600 if (sm->cur_pmksa == entry) {
2601 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
2604 pmksa_cache_clear_current(sm);
2617 (sm->pmk_len == entry->pmk_len &&
2618 os_memcmp(sm->pmk, entry->pmk, sm->pmk_len) == 0)) {
2619 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
2621 pmksa_cache_clear_current(sm);
2626 sm->pmk_len = 0;
2627 os_memset(sm->pmk, 0, sizeof(sm->pmk));
2628 wpa_sm_deauthenticate(sm, WLAN_REASON_UNSPECIFIED);
2643 struct wpa_sm *sm;
2645 sm = os_zalloc(sizeof(*sm));
2646 if (sm == NULL)
2648 dl_list_init(&sm->pmksa_candidates);
2649 sm->renew_snonce = 1;
2650 sm->ctx = ctx;
2652 sm->dot11RSNAConfigPMKLifetime = 43200;
2653 sm->dot11RSNAConfigPMKReauthThreshold = 70;
2654 sm->dot11RSNAConfigSATimeout = 60;
2656 sm->pmksa = pmksa_cache_init(wpa_sm_pmksa_free_cb, sm, sm);
2657 if (sm->pmksa == NULL) {
2658 wpa_msg(sm->ctx->msg_ctx, MSG_ERROR,
2660 os_free(sm);
2664 return sm;
2670 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2672 void wpa_sm_deinit(struct wpa_sm *sm)
2674 if (sm == NULL)
2676 pmksa_cache_deinit(sm->pmksa);
2677 eloop_cancel_timeout(wpa_sm_start_preauth, sm, NULL);
2678 eloop_cancel_timeout(wpa_sm_rekey_ptk, sm, NULL);
2679 os_free(sm->assoc_wpa_ie);
2680 os_free(sm->ap_wpa_ie);
2681 os_free(sm->ap_rsn_ie);
2682 wpa_sm_drop_sa(sm);
2683 os_free(sm->ctx);
2685 os_free(sm->assoc_resp_ies);
2688 wpabuf_free(sm->test_assoc_ie);
2691 crypto_ecdh_deinit(sm->fils_ecdh);
2694 wpabuf_free(sm->fils_ft_ies);
2697 crypto_ecdh_deinit(sm->owe_ecdh);
2700 wpabuf_clear_free(sm->dpp_z);
2702 os_free(sm);
2708 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2714 void wpa_sm_notify_assoc(struct wpa_sm *sm, const u8 *bssid)
2718 if (sm == NULL)
2721 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
2723 os_memcpy(sm->bssid, bssid, ETH_ALEN);
2724 os_memset(sm->rx_replay_counter, 0, WPA_REPLAY_COUNTER_LEN);
2725 sm->rx_replay_counter_set = 0;
2726 sm->renew_snonce = 1;
2727 if (os_memcmp(sm->preauth_bssid, bssid, ETH_ALEN) == 0)
2728 rsn_preauth_deinit(sm);
2731 if (wpa_ft_is_completed(sm)) {
2736 eapol_sm_notify_portValid(sm->eapol, FALSE);
2737 wpa_supplicant_key_neg_complete(sm, sm->bssid, 1);
2740 wpa_ft_prepare_auth_request(sm, NULL);
2743 sm->ft_protocol = 1;
2745 sm->ft_protocol = 0;
2749 if (sm->fils_completed) {
2754 wpa_supplicant_key_neg_complete(sm, sm->bssid, 1);
2764 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Clear old PTK");
2765 sm->ptk_set = 0;
2766 os_memset(&sm->ptk, 0, sizeof(sm->ptk));
2767 sm->tptk_set = 0;
2768 os_memset(&sm->tptk, 0, sizeof(sm->tptk));
2769 os_memset(&sm->gtk, 0, sizeof(sm->gtk));
2770 os_memset(&sm->gtk_wnm_sleep, 0, sizeof(sm->gtk_wnm_sleep));
2772 os_memset(&sm->igtk, 0, sizeof(sm->igtk));
2773 os_memset(&sm->igtk_wnm_sleep, 0, sizeof(sm->igtk_wnm_sleep));
2778 wpa_tdls_assoc(sm);
2782 os_memset(sm->p2p_ip_addr, 0, sizeof(sm->p2p_ip_addr));
2789 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2794 void wpa_sm_notify_disassoc(struct wpa_sm *sm)
2796 eloop_cancel_timeout(wpa_sm_start_preauth, sm, NULL);
2797 eloop_cancel_timeout(wpa_sm_rekey_ptk, sm, NULL);
2798 rsn_preauth_deinit(sm);
2799 pmksa_cache_clear_current(sm);
2800 if (wpa_sm_get_state(sm) == WPA_4WAY_HANDSHAKE)
2801 sm->dot11RSNA4WayHandshakeFailures++;
2803 wpa_tdls_disassoc(sm);
2806 sm->fils_completed = 0;
2809 sm->ft_reassoc_completed = 0;
2810 sm->ft_protocol = 0;
2814 wpa_sm_drop_sa(sm);
2816 sm->msg_3_of_4_ok = 0;
2817 os_memset(sm->bssid, 0, ETH_ALEN);
2823 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2831 void wpa_sm_set_pmk(struct wpa_sm *sm, const u8 *pmk, size_t pmk_len,
2834 if (sm == NULL)
2839 sm->pmk_len = pmk_len;
2840 os_memcpy(sm->pmk, pmk, pmk_len);
2844 sm->xxkey_len = pmk_len;
2845 os_memcpy(sm->xxkey, pmk, pmk_len);
2849 pmksa_cache_add(sm->pmksa, pmk, pmk_len, pmkid, NULL, 0,
2850 bssid, sm->own_addr,
2851 sm->network_ctx, sm->key_mgmt, NULL);
2858 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2863 void wpa_sm_set_pmk_from_pmksa(struct wpa_sm *sm)
2865 if (sm == NULL)
2868 if (sm->cur_pmksa) {
2871 sm->cur_pmksa->pmk, sm->cur_pmksa->pmk_len);
2872 sm->pmk_len = sm->cur_pmksa->pmk_len;
2873 os_memcpy(sm->pmk, sm->cur_pmksa->pmk, sm->pmk_len);
2876 sm->pmk_len = 0;
2877 os_memset(sm->pmk, 0, PMK_LEN_MAX);
2884 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2887 void wpa_sm_set_fast_reauth(struct wpa_sm *sm, int fast_reauth)
2889 if (sm)
2890 sm->fast_reauth = fast_reauth;
2896 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2899 void wpa_sm_set_scard_ctx(struct wpa_sm *sm, void *scard_ctx)
2901 if (sm == NULL)
2903 sm->scard_ctx = scard_ctx;
2904 if (sm->preauth_eapol)
2905 eapol_sm_register_scard_ctx(sm->preauth_eapol, scard_ctx);
2911 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2918 void wpa_sm_set_config(struct wpa_sm *sm, struct rsn_supp_config *config)
2920 if (!sm)
2924 sm->network_ctx = config->network_ctx;
2925 sm->allowed_pairwise_cipher = config->allowed_pairwise_cipher;
2926 sm->proactive_key_caching = config->proactive_key_caching;
2927 sm->eap_workaround = config->eap_workaround;
2928 sm->eap_conf_ctx = config->eap_conf_ctx;
2930 os_memcpy(sm->ssid, config->ssid, config->ssid_len);
2931 sm->ssid_len = config->ssid_len;
2933 sm->ssid_len = 0;
2934 sm->wpa_ptk_rekey = config->wpa_ptk_rekey;
2935 sm->p2p = config->p2p;
2936 sm->wpa_rsc_relaxation = config->wpa_rsc_relaxation;
2939 sm->fils_cache_id_set = 1;
2940 os_memcpy(sm->fils_cache_id, config->fils_cache_id,
2943 sm->fils_cache_id_set = 0;
2947 sm->network_ctx = NULL;
2948 sm->allowed_pairwise_cipher = 0;
2949 sm->proactive_key_caching = 0;
2950 sm->eap_workaround = 0;
2951 sm->eap_conf_ctx = NULL;
2952 sm->ssid_len = 0;
2953 sm->wpa_ptk_rekey = 0;
2954 sm->p2p = 0;
2955 sm->wpa_rsc_relaxation = 0;
2962 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2965 void wpa_sm_set_own_addr(struct wpa_sm *sm, const u8 *addr)
2967 if (sm)
2968 os_memcpy(sm->own_addr, addr, ETH_ALEN);
2974 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2978 void wpa_sm_set_ifname(struct wpa_sm *sm, const char *ifname,
2981 if (sm) {
2982 sm->ifname = ifname;
2983 sm->bridge_ifname = bridge_ifname;
2990 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2993 void wpa_sm_set_eapol(struct wpa_sm *sm, struct eapol_sm *eapol)
2995 if (sm)
2996 sm->eapol = eapol;
3002 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3007 int wpa_sm_set_param(struct wpa_sm *sm, enum wpa_sm_conf_params param,
3012 if (sm == NULL)
3018 sm->dot11RSNAConfigPMKLifetime = value;
3024 sm->dot11RSNAConfigPMKReauthThreshold = value;
3030 sm->dot11RSNAConfigSATimeout = value;
3035 sm->proto = value;
3038 sm->pairwise_cipher = value;
3041 sm->group_cipher = value;
3044 sm->key_mgmt = value;
3048 sm->mgmt_group_cipher = value;
3052 sm->rsn_enabled = value;
3055 sm->mfp = value;
3058 sm->ocv = value;
3070 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3080 int wpa_sm_get_status(struct wpa_sm *sm, char *buf, size_t buflen,
3090 wpa_cipher_txt(sm->pairwise_cipher),
3091 wpa_cipher_txt(sm->group_cipher),
3092 wpa_key_mgmt_txt(sm->key_mgmt, sm->proto));
3097 if (sm->mfp != NO_MGMT_FRAME_PROTECTION && sm->ap_rsn_ie) {
3099 if (wpa_parse_wpa_ie_rsn(sm->ap_rsn_ie, sm->ap_rsn_ie_len, &rsn)
3108 sm->mgmt_group_cipher));
3119 int wpa_sm_pmf_enabled(struct wpa_sm *sm)
3123 if (sm->mfp == NO_MGMT_FRAME_PROTECTION || !sm->ap_rsn_ie)
3126 if (wpa_parse_wpa_ie_rsn(sm->ap_rsn_ie, sm->ap_rsn_ie_len, &rsn) >= 0 &&
3134 int wpa_sm_ocv_enabled(struct wpa_sm *sm)
3138 if (!sm->ocv || !sm->ap_rsn_ie)
3141 return wpa_parse_wpa_ie_rsn(sm->ap_rsn_ie, sm->ap_rsn_ie_len,
3149 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3154 int wpa_sm_set_assoc_wpa_ie_default(struct wpa_sm *sm, u8 *wpa_ie,
3159 if (sm == NULL)
3163 if (sm->test_assoc_ie) {
3166 if (*wpa_ie_len < wpabuf_len(sm->test_assoc_ie))
3168 os_memcpy(wpa_ie, wpabuf_head(sm->test_assoc_ie),
3169 wpabuf_len(sm->test_assoc_ie));
3170 res = wpabuf_len(sm->test_assoc_ie);
3173 res = wpa_gen_wpa_ie(sm, wpa_ie, *wpa_ie_len);
3181 if (sm->assoc_wpa_ie == NULL) {
3187 sm->assoc_wpa_ie = os_memdup(wpa_ie, *wpa_ie_len);
3188 if (sm->assoc_wpa_ie == NULL)
3191 sm->assoc_wpa_ie_len = *wpa_ie_len;
3195 sm->assoc_wpa_ie, sm->assoc_wpa_ie_len);
3204 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3213 int wpa_sm_set_assoc_wpa_ie(struct wpa_sm *sm, const u8 *ie, size_t len)
3215 if (sm == NULL)
3218 os_free(sm->assoc_wpa_ie);
3220 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
3222 sm->assoc_wpa_ie = NULL;
3223 sm->assoc_wpa_ie_len = 0;
3226 sm->assoc_wpa_ie = os_memdup(ie, len);
3227 if (sm->assoc_wpa_ie == NULL)
3230 sm->assoc_wpa_ie_len = len;
3239 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3247 int wpa_sm_set_ap_wpa_ie(struct wpa_sm *sm, const u8 *ie, size_t len)
3249 if (sm == NULL)
3252 os_free(sm->ap_wpa_ie);
3254 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
3256 sm->ap_wpa_ie = NULL;
3257 sm->ap_wpa_ie_len = 0;
3260 sm->ap_wpa_ie = os_memdup(ie, len);
3261 if (sm->ap_wpa_ie == NULL)
3264 sm->ap_wpa_ie_len = len;
3273 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3281 int wpa_sm_set_ap_rsn_ie(struct wpa_sm *sm, const u8 *ie, size_t len)
3283 if (sm == NULL)
3286 os_free(sm->ap_rsn_ie);
3288 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
3290 sm->ap_rsn_ie = NULL;
3291 sm->ap_rsn_ie_len = 0;
3294 sm->ap_rsn_ie = os_memdup(ie, len);
3295 if (sm->ap_rsn_ie == NULL)
3298 sm->ap_rsn_ie_len = len;
3307 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3314 int wpa_sm_parse_own_wpa_ie(struct wpa_sm *sm, struct wpa_ie_data *data)
3316 if (sm == NULL)
3319 if (sm->assoc_wpa_ie == NULL) {
3320 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
3324 if (wpa_parse_wpa_ie(sm->assoc_wpa_ie, sm->assoc_wpa_ie_len, data))
3330 int wpa_sm_pmksa_cache_list(struct wpa_sm *sm, char *buf, size_t len)
3332 return pmksa_cache_list(sm->pmksa, buf, len);
3336 struct rsn_pmksa_cache_entry * wpa_sm_pmksa_cache_head(struct wpa_sm *sm)
3338 return pmksa_cache_head(sm->pmksa);
3343 wpa_sm_pmksa_cache_add_entry(struct wpa_sm *sm,
3346 return pmksa_cache_add_entry(sm->pmksa, entry);
3350 void wpa_sm_pmksa_cache_add(struct wpa_sm *sm, const u8 *pmk, size_t pmk_len,
3354 sm->cur_pmksa = pmksa_cache_add(sm->pmksa, pmk, pmk_len, pmkid, NULL, 0,
3355 bssid, sm->own_addr, sm->network_ctx,
3356 sm->key_mgmt, fils_cache_id);
3360 int wpa_sm_pmksa_exists(struct wpa_sm *sm, const u8 *bssid,
3363 return pmksa_cache_get(sm->pmksa, bssid, NULL, network_ctx, 0) != NULL;
3367 void wpa_sm_drop_sa(struct wpa_sm *sm)
3369 wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Clear old PMK and PTK");
3370 sm->ptk_set = 0;
3371 sm->tptk_set = 0;
3372 sm->pmk_len = 0;
3373 os_memset(sm->pmk, 0, sizeof(sm->pmk));
3374 os_memset(&sm->ptk, 0, sizeof(sm->ptk));
3375 os_memset(&sm->tptk, 0, sizeof(sm->tptk));
3376 os_memset(&sm->gtk, 0, sizeof(sm->gtk));
3377 os_memset(&sm->gtk_wnm_sleep, 0, sizeof(sm->gtk_wnm_sleep));
3379 os_memset(&sm->igtk, 0, sizeof(sm->igtk));
3380 os_memset(&sm->igtk_wnm_sleep, 0, sizeof(sm->igtk_wnm_sleep));
3383 os_memset(sm->xxkey, 0, sizeof(sm->xxkey));
3384 sm->xxkey_len = 0;
3385 os_memset(sm->pmk_r0, 0, sizeof(sm->pmk_r0));
3386 sm->pmk_r0_len = 0;
3387 os_memset(sm->pmk_r1, 0, sizeof(sm->pmk_r1));
3388 sm->pmk_r1_len = 0;
3393 int wpa_sm_has_ptk(struct wpa_sm *sm)
3395 if (sm == NULL)
3397 return sm->ptk_set;
3401 void wpa_sm_update_replay_ctr(struct wpa_sm *sm, const u8 *replay_ctr)
3403 os_memcpy(sm->rx_replay_counter, replay_ctr, WPA_REPLAY_COUNTER_LEN);
3407 void wpa_sm_pmksa_cache_flush(struct wpa_sm *sm, void *network_ctx)
3409 pmksa_cache_flush(sm->pmksa, network_ctx, NULL, 0);
3414 int wpa_wnmsleep_install_key(struct wpa_sm *sm, u8 subelem_id, u8 *buf)
3424 keylen = wpa_cipher_key_len(sm->group_cipher);
3425 gd.key_rsc_len = wpa_cipher_rsc_len(sm->group_cipher);
3426 gd.alg = wpa_cipher_to_alg(sm->group_cipher);
3442 sm, !!(keyinfo & WPA_KEY_INFO_TXRX));
3448 if (wpa_supplicant_install_gtk(sm, &gd, key_rsc, 1)) {
3460 if (wpa_supplicant_install_igtk(sm, igtk, 1) < 0)
3475 int wpa_sm_get_p2p_ip_addr(struct wpa_sm *sm, u8 *buf)
3477 if (sm == NULL || WPA_GET_BE32(sm->p2p_ip_addr) == 0)
3479 os_memcpy(buf, sm->p2p_ip_addr, 3 * 4);
3486 void wpa_sm_set_rx_replay_ctr(struct wpa_sm *sm, const u8 *rx_replay_counter)
3491 os_memcpy(sm->rx_replay_counter, rx_replay_counter,
3493 sm->rx_replay_counter_set = 1;
3498 void wpa_sm_set_ptk_kck_kek(struct wpa_sm *sm,
3503 os_memcpy(sm->ptk.kck, ptk_kck, ptk_kck_len);
3504 sm->ptk.kck_len = ptk_kck_len;
3508 os_memcpy(sm->ptk.kek, ptk_kek, ptk_kek_len);
3509 sm->ptk.kek_len = ptk_kek_len;
3512 sm->ptk_set = 1;
3518 void wpa_sm_set_test_assoc_ie(struct wpa_sm *sm, struct wpabuf *buf)
3520 wpabuf_free(sm->test_assoc_ie);
3521 sm->test_assoc_ie = buf;
3525 const u8 * wpa_sm_get_anonce(struct wpa_sm *sm)
3527 return sm->anonce;
3533 unsigned int wpa_sm_get_key_mgmt(struct wpa_sm *sm)
3535 return sm->key_mgmt;
3541 struct wpabuf * fils_build_auth(struct wpa_sm *sm, int dh_group, const u8 *md)
3547 erp_msg = eapol_sm_build_erp_reauth_start(sm->eapol);
3548 if (!erp_msg && !sm->cur_pmksa) {
3555 erp_msg != NULL, sm->cur_pmksa != NULL);
3557 sm->fils_completed = 0;
3559 if (!sm->assoc_wpa_ie) {
3564 if (random_get_bytes(sm->fils_nonce, FILS_NONCE_LEN) < 0 ||
3565 random_get_bytes(sm->fils_session, FILS_SESSION_LEN) < 0)
3569 sm->fils_nonce, FILS_NONCE_LEN);
3571 sm->fils_session, FILS_SESSION_LEN);
3574 sm->fils_dh_group = dh_group;
3576 crypto_ecdh_deinit(sm->fils_ecdh);
3577 sm->fils_ecdh = crypto_ecdh_init(dh_group);
3578 if (!sm->fils_ecdh) {
3584 pub = crypto_ecdh_get_pubkey(sm->fils_ecdh, 1);
3589 sm->fils_dh_elem_len = wpabuf_len(pub);
3593 buf = wpabuf_alloc(1000 + sm->assoc_wpa_ie_len +
3618 sm->assoc_wpa_ie, sm->assoc_wpa_ie_len);
3619 wpabuf_put_data(buf, sm->assoc_wpa_ie, sm->assoc_wpa_ie_len);
3637 wpabuf_put_data(buf, sm->fils_nonce, FILS_NONCE_LEN);
3644 wpabuf_put_data(buf, sm->fils_session, FILS_SESSION_LEN);
3647 sm->fils_erp_pmkid_set = 0;
3656 if (fils_pmkid_erp(sm->key_mgmt, wpabuf_head(erp_msg),
3658 sm->fils_erp_pmkid) == 0)
3659 sm->fils_erp_pmkid_set = 1;
3672 int fils_process_auth(struct wpa_sm *sm, const u8 *bssid, const u8 *data,
3689 os_memcpy(sm->bssid, bssid, ETH_ALEN);
3698 if (sm->fils_dh_group) {
3711 if (group != sm->fils_dh_group) {
3714 group, sm->fils_dh_group);
3719 if ((size_t) (end - pos) < sm->fils_dh_elem_len) {
3724 if (!sm->fils_ecdh) {
3728 dh_ss = crypto_ecdh_set_peerkey(sm->fils_ecdh, 1, pos,
3729 sm->fils_dh_elem_len);
3736 g_ap_len = sm->fils_dh_elem_len;
3737 pos += sm->fils_dh_elem_len;
3761 os_memcpy(sm->fils_anonce, elems.fils_nonce, FILS_NONCE_LEN);
3762 wpa_hexdump(MSG_DEBUG, "FILS: ANonce", sm->fils_anonce, FILS_NONCE_LEN);
3765 if (wpa_key_mgmt_ft(sm->key_mgmt)) {
3774 wpa_key_mgmt_sha384(sm->key_mgmt)) < 0) {
3784 os_memcpy(sm->r0kh_id, parse.r0kh_id, parse.r0kh_id_len);
3785 sm->r0kh_id_len = parse.r0kh_id_len;
3787 sm->r0kh_id, sm->r0kh_id_len);
3794 os_memcpy(sm->r1kh_id, parse.r1kh_id, FT_R1KH_ID_LEN);
3796 sm->r1kh_id, FT_R1KH_ID_LEN);
3800 wpabuf_free(sm->fils_ft_ies);
3801 sm->fils_ft_ies = wpabuf_alloc(2 + elems.mdie_len +
3803 if (!sm->fils_ft_ies)
3805 wpabuf_put_data(sm->fils_ft_ies, elems.mdie - 2,
3807 wpabuf_put_data(sm->fils_ft_ies, elems.ftie - 2,
3810 wpabuf_free(sm->fils_ft_ies);
3811 sm->fils_ft_ies = NULL;
3825 if (os_memcmp(sm->cur_pmksa->pmkid, rsn.pmkid, PMKID_LEN) != 0)
3829 sm->cur_pmksa->pmkid, PMKID_LEN);
3836 if (!pmkid_match && sm->cur_pmksa) {
3839 sm->cur_pmksa = NULL;
3849 if (os_memcmp(sm->fils_session, elems.fils_session, FILS_SESSION_LEN)
3853 sm->fils_session, FILS_SESSION_LEN);
3858 if (!sm->cur_pmksa && elems.fils_wrapped_data) {
3865 eapol_sm_process_erp_finish(sm->eapol, elems.fils_wrapped_data,
3867 if (eapol_sm_failed(sm->eapol))
3871 res = eapol_sm_get_key(sm->eapol, rmsk, rmsk_len);
3874 res = eapol_sm_get_key(sm->eapol, rmsk, rmsk_len);
3879 res = fils_rmsk_to_pmk(sm->key_mgmt, rmsk, rmsk_len,
3880 sm->fils_nonce, sm->fils_anonce,
3883 sm->pmk, &sm->pmk_len);
3894 if (!sm->fils_erp_pmkid_set) {
3898 wpa_hexdump(MSG_DEBUG, "FILS: PMKID", sm->fils_erp_pmkid,
3901 sm->cur_pmksa = pmksa_cache_add(sm->pmksa, sm->pmk, sm->pmk_len,
3902 sm->fils_erp_pmkid, NULL, 0,
3903 sm->bssid, sm->own_addr,
3904 sm->network_ctx, sm->key_mgmt,
3908 if (!sm->cur_pmksa) {
3914 if (fils_pmk_to_ptk(sm->pmk, sm->pmk_len, sm->own_addr, sm->bssid,
3915 sm->fils_nonce, sm->fils_anonce,
3918 &sm->ptk, ick, &ick_len,
3919 sm->key_mgmt, sm->pairwise_cipher,
3920 sm->fils_ft, &sm->fils_ft_len) < 0) {
3928 sm->ptk_set = 1;
3929 sm->tptk_set = 0;
3930 os_memset(&sm->tptk, 0, sizeof(sm->tptk));
3933 if (sm->fils_dh_group) {
3934 if (!sm->fils_ecdh) {
3938 pub = crypto_ecdh_get_pubkey(sm->fils_ecdh, 1);
3952 res = fils_key_auth_sk(ick, ick_len, sm->fils_nonce,
3953 sm->fils_anonce, sm->own_addr, sm->bssid,
3955 sm->key_mgmt, sm->fils_key_auth_sta,
3956 sm->fils_key_auth_ap,
3957 &sm->fils_key_auth_len);
3969 static int fils_ft_build_assoc_req_rsne(struct wpa_sm *sm, struct wpabuf *buf)
3974 int use_sha384 = wpa_key_mgmt_sha384(sm->key_mgmt);
3982 if (!wpa_cipher_valid_group(sm->group_cipher)) {
3984 sm->group_cipher);
3989 sm->group_cipher));
3995 if (!wpa_cipher_valid_pairwise(sm->pairwise_cipher)) {
3997 sm->pairwise_cipher);
4002 sm->pairwise_cipher));
4009 if (sm->key_mgmt == WPA_KEY_MGMT_FT_FILS_SHA256)
4011 else if (sm->key_mgmt == WPA_KEY_MGMT_FT_FILS_SHA384)
4016 sm->key_mgmt);
4023 if (sm->mgmt_group_cipher == WPA_CIPHER_AES_128_CMAC)
4026 if (sm->ocv)
4035 sm->fils_ft, sm->fils_ft_len);
4036 wpa_hexdump_ascii(MSG_DEBUG, "FILS+FT: SSID", sm->ssid, sm->ssid_len);
4038 sm->mobility_domain, MOBILITY_DOMAIN_ID_LEN);
4040 sm->r0kh_id, sm->r0kh_id_len);
4041 if (wpa_derive_pmk_r0(sm->fils_ft, sm->fils_ft_len, sm->ssid,
4042 sm->ssid_len, sm->mobility_domain,
4043 sm->r0kh_id, sm->r0kh_id_len, sm->own_addr,
4044 sm->pmk_r0, sm->pmk_r0_name, use_sha384) < 0) {
4048 sm->pmk_r0_len = use_sha384 ? SHA384_MAC_LEN : PMK_LEN;
4050 sm->pmk_r0, sm->pmk_r0_len);
4052 sm->pmk_r0_name, WPA_PMK_NAME_LEN);
4054 MAC2STR(sm->r1kh_id));
4056 if (wpa_derive_pmk_r1_name(sm->pmk_r0_name, sm->r1kh_id, sm->own_addr,
4057 sm->pmk_r1_name, use_sha384) < 0) {
4061 wpa_hexdump(MSG_DEBUG, "FILS+FT: PMKR1Name", sm->pmk_r1_name,
4063 os_memcpy(pos, sm->pmk_r1_name, WPA_PMK_NAME_LEN);
4066 if (sm->mgmt_group_cipher == WPA_CIPHER_AES_128_CMAC) {
4079 struct wpabuf * fils_build_assoc_req(struct wpa_sm *sm, const u8 **kek,
4091 if (sm->fils_ft_ies)
4092 len += wpabuf_len(sm->fils_ft_ies);
4093 if (wpa_key_mgmt_ft(sm->key_mgmt))
4103 if (wpa_key_mgmt_ft(sm->key_mgmt) && sm->fils_ft_ies) {
4105 wpabuf_put_buf(buf, sm->fils_ft_ies);
4107 if (fils_ft_build_assoc_req_rsne(sm, buf) < 0) {
4119 wpabuf_put_data(buf, sm->fils_session, FILS_SESSION_LEN);
4128 wpabuf_put_u8(buf, 1 + sm->fils_key_auth_len); /* Length */
4131 wpabuf_put_data(buf, sm->fils_key_auth_sta, sm->fils_key_auth_len);
4165 if (wpa_sm_ocv_enabled(sm)) {
4169 if (wpa_sm_channel_info(sm, &ci) != 0) {
4186 *kek = sm->ptk.kek;
4187 *kek_len = sm->ptk.kek_len;
4189 *snonce = sm->fils_nonce;
4192 *anonce = sm->fils_anonce;
4200 static void fils_process_hlp_resp(struct wpa_sm *sm, const u8 *resp, size_t len)
4212 wpa_sm_fils_hlp_rx(sm, resp, resp + ETH_ALEN, pos, end - pos);
4216 static void fils_process_hlp_container(struct wpa_sm *sm, const u8 *pos,
4258 fils_process_hlp_resp(sm, tmp, tmp_pos - tmp);
4265 int fils_process_assoc_resp(struct wpa_sm *sm, const u8 *resp, size_t len)
4276 if (!sm || !sm->ptk_set) {
4281 if (!wpa_key_mgmt_fils(sm->key_mgmt)) {
4286 if (sm->fils_completed) {
4314 if (os_memcmp(elems.fils_session, sm->fils_session,
4320 sm->fils_session, FILS_SESSION_LEN);
4331 } else if (wpa_compare_rsn_ie(wpa_key_mgmt_ft(sm->key_mgmt),
4332 sm->ap_rsn_ie, sm->ap_rsn_ie_len,
4334 wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
4337 sm->ap_rsn_ie, sm->ap_rsn_ie_len);
4349 if (elems.fils_key_confirm_len != sm->fils_key_auth_len) {
4353 (int) sm->fils_key_auth_len);
4356 if (os_memcmp(elems.fils_key_confirm, sm->fils_key_auth_ap,
4357 sm->fils_key_auth_len) != 0) {
4363 sm->fils_key_auth_ap, sm->fils_key_auth_len);
4368 if (wpa_sm_ocv_enabled(sm)) {
4371 if (wpa_sm_channel_info(sm, &ci) != 0) {
4387 if (wpa_key_mgmt_ft(sm->key_mgmt) && sm->fils_ft_ies) {
4395 os_memcmp(rsn.pmkid, sm->pmk_r1_name,
4423 if (wpa_supplicant_check_group_cipher(sm, sm->group_cipher,
4430 gd.tx = wpa_supplicant_gtk_tx_bit_workaround(sm,
4440 if (wpa_supplicant_install_gtk(sm, &gd, elems.key_delivery, 0) < 0) {
4445 if (ieee80211w_set_keys(sm, &kde) < 0) {
4450 alg = wpa_cipher_to_alg(sm->pairwise_cipher);
4451 keylen = wpa_cipher_key_len(sm->pairwise_cipher);
4452 if (keylen <= 0 || (unsigned int) keylen != sm->ptk.tk_len) {
4454 keylen, (long unsigned int) sm->ptk.tk_len);
4457 rsclen = wpa_cipher_rsc_len(sm->pairwise_cipher);
4459 sm->ptk.tk, keylen);
4460 if (wpa_sm_set_key(sm, alg, sm->bssid, 0, 1, null_rsc, rsclen,
4461 sm->ptk.tk, keylen) < 0) {
4462 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
4465 alg, keylen, MAC2STR(sm->bssid));
4472 os_memset(sm->ptk.tk, 0, WPA_TK_MAX_LEN);
4473 sm->ptk.tk_len = 0;
4474 sm->ptk.installed = 1;
4477 fils_process_hlp_container(sm, ie_start, end - ie_start);
4482 sm->fils_completed = 1;
4492 void wpa_sm_set_reset_fils_completed(struct wpa_sm *sm, int set)
4494 if (sm)
4495 sm->fils_completed = !!set;
4501 int wpa_fils_is_completed(struct wpa_sm *sm)
4504 return sm && sm->fils_completed;
4513 struct wpabuf * owe_build_assoc_req(struct wpa_sm *sm, u16 group)
4527 crypto_ecdh_deinit(sm->owe_ecdh);
4528 sm->owe_ecdh = crypto_ecdh_init(group);
4529 if (!sm->owe_ecdh)
4531 sm->owe_group = group;
4532 pub = crypto_ecdh_get_pubkey(sm->owe_ecdh, 0);
4552 crypto_ecdh_deinit(sm->owe_ecdh);
4553 sm->owe_ecdh = NULL;
4558 int owe_process_assoc_resp(struct wpa_sm *sm, const u8 *bssid,
4580 if (sm->cur_pmksa && elems.rsn_ie &&
4584 os_memcmp(sm->cur_pmksa->pmkid, data.pmkid, PMKID_LEN) == 0) {
4586 wpa_sm_set_pmk_from_pmksa(sm);
4597 if (group != sm->owe_group) {
4604 if (!sm->owe_ecdh) {
4618 secret = crypto_ecdh_set_peerkey(sm->owe_ecdh, 0,
4630 pub = crypto_ecdh_get_pubkey(sm->owe_ecdh, 0);
4671 wpabuf_put_le16(hkey, sm->owe_group); /* group */
4692 os_strlen(info), sm->pmk, hash_len);
4695 os_strlen(info), sm->pmk, hash_len);
4698 os_strlen(info), sm->pmk, hash_len);
4701 sm->pmk_len = 0;
4704 sm->pmk_len = hash_len;
4706 wpa_hexdump_key(MSG_DEBUG, "OWE: PMK", sm->pmk, sm->pmk_len);
4708 pmksa_cache_add(sm->pmksa, sm->pmk, sm->pmk_len, pmkid, NULL, 0,
4709 bssid, sm->own_addr, sm->network_ctx, sm->key_mgmt,
4718 void wpa_sm_set_fils_cache_id(struct wpa_sm *sm, const u8 *fils_cache_id)
4721 if (sm && fils_cache_id) {
4722 sm->fils_cache_id_set = 1;
4723 os_memcpy(sm->fils_cache_id, fils_cache_id, FILS_CACHE_ID_LEN);
4730 void wpa_sm_set_dpp_z(struct wpa_sm *sm, const struct wpabuf *z)
4732 if (sm) {
4733 wpabuf_clear_free(sm->dpp_z);
4734 sm->dpp_z = z ? wpabuf_dup(z) : NULL;