Lines Matching refs:sm

40 #define STATE_MACHINE_ADDR wpa_auth_get_spa(sm)
44 static int wpa_sm_step(struct wpa_state_machine *sm);
48 static int wpa_aead_decrypt(struct wpa_state_machine *sm, struct wpa_ptk *ptk,
50 static struct wpabuf * fils_prepare_plainbuf(struct wpa_state_machine *sm,
56 static void wpa_request_new_ptk(struct wpa_state_machine *sm);
61 static int wpa_derive_ptk(struct wpa_state_machine *sm, const u8 *snonce,
72 static int ieee80211w_kde_len(struct wpa_state_machine *sm);
73 static u8 * ieee80211w_kde_add(struct wpa_state_machine *sm, u8 *pos);
89 static const u8 * wpa_auth_get_aa(const struct wpa_state_machine *sm) in wpa_auth_get_aa() argument
92 if (sm->mld_assoc_link_id >= 0) in wpa_auth_get_aa()
93 return sm->wpa_auth->mld_addr; in wpa_auth_get_aa()
95 return sm->wpa_auth->addr; in wpa_auth_get_aa()
99 static const u8 * wpa_auth_get_spa(const struct wpa_state_machine *sm) in wpa_auth_get_spa() argument
102 if (sm->mld_assoc_link_id >= 0) in wpa_auth_get_spa()
103 return sm->peer_mld_addr; in wpa_auth_get_spa()
105 return sm->addr; in wpa_auth_get_spa()
109 static void wpa_gkeydone_sta(struct wpa_state_machine *sm) in wpa_gkeydone_sta() argument
115 if (!sm->wpa_auth) in wpa_gkeydone_sta()
118 sm->wpa_auth->group->GKeyDoneStations--; in wpa_gkeydone_sta()
119 sm->GUpdateStationKeys = false; in wpa_gkeydone_sta()
122 for_each_sm_auth(sm, link_id) in wpa_gkeydone_sta()
123 sm->mld_links[link_id].wpa_auth->group->GKeyDoneStations--; in wpa_gkeydone_sta()
130 void wpa_release_link_auth_ref(struct wpa_state_machine *sm, in wpa_release_link_auth_ref() argument
135 if (!sm || release_link_id >= MAX_NUM_MLD_LINKS) in wpa_release_link_auth_ref()
138 for_each_sm_auth(sm, link_id) { in wpa_release_link_auth_ref()
140 wpa_group_put(sm->mld_links[link_id].wpa_auth, in wpa_release_link_auth_ref()
141 sm->mld_links[link_id].wpa_auth->group); in wpa_release_link_auth_ref()
142 sm->mld_links[link_id].wpa_auth = NULL; in wpa_release_link_auth_ref()
371 int (*cb)(struct wpa_state_machine *sm, void *ctx), in wpa_auth_for_each_sta() argument
603 struct wpa_state_machine *sm = timeout_ctx; in wpa_rekey_ptk() local
605 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm), LOGGER_DEBUG, in wpa_rekey_ptk()
607 wpa_request_new_ptk(sm); in wpa_rekey_ptk()
608 wpa_sm_step(sm); in wpa_rekey_ptk()
612 void wpa_auth_set_ptk_rekey_timer(struct wpa_state_machine *sm) in wpa_auth_set_ptk_rekey_timer() argument
614 if (sm && sm->wpa_auth->conf.wpa_ptk_rekey) { in wpa_auth_set_ptk_rekey_timer()
617 MAC2STR(wpa_auth_get_spa(sm)), in wpa_auth_set_ptk_rekey_timer()
618 sm->wpa_auth->conf.wpa_ptk_rekey); in wpa_auth_set_ptk_rekey_timer()
619 eloop_cancel_timeout(wpa_rekey_ptk, sm->wpa_auth, sm); in wpa_auth_set_ptk_rekey_timer()
620 eloop_register_timeout(sm->wpa_auth->conf.wpa_ptk_rekey, 0, in wpa_auth_set_ptk_rekey_timer()
621 wpa_rekey_ptk, sm->wpa_auth, sm); in wpa_auth_set_ptk_rekey_timer()
626 static int wpa_auth_pmksa_clear_cb(struct wpa_state_machine *sm, void *ctx) in wpa_auth_pmksa_clear_cb() argument
628 if (sm->pmksa == ctx) in wpa_auth_pmksa_clear_cb()
629 sm->pmksa = NULL; in wpa_auth_pmksa_clear_cb()
940 struct wpa_state_machine *sm; local
945 sm = os_zalloc(sizeof(struct wpa_state_machine));
946 if (!sm)
948 os_memcpy(sm->addr, addr, ETH_ALEN);
950 os_memcpy(sm->p2p_dev_addr, p2p_dev_addr, ETH_ALEN);
952 sm->wpa_auth = wpa_auth;
953 sm->group = wpa_auth->group;
954 wpa_group_get(sm->wpa_auth, sm->group);
956 sm->mld_assoc_link_id = -1;
959 return sm;
964 struct wpa_state_machine *sm) argument
966 if (!wpa_auth || !wpa_auth->conf.wpa || !sm)
970 if (sm->ft_completed) {
971 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm), LOGGER_DEBUG,
974 sm->wpa_ptk_state = WPA_PTK_PTKINITDONE;
975 sm->Pair = true;
981 if (sm->fils_completed) {
982 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm), LOGGER_DEBUG,
985 sm->wpa_ptk_state = WPA_PTK_PTKINITDONE;
986 sm->Pair = true;
991 if (sm->started) {
992 os_memset(&sm->key_replay, 0, sizeof(sm->key_replay));
993 sm->ReAuthenticationRequest = true;
994 return wpa_sm_step(sm);
997 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm), LOGGER_DEBUG,
999 sm->started = 1;
1001 sm->Init = true;
1002 if (wpa_sm_step(sm) == 1)
1004 sm->Init = false;
1005 sm->AuthenticationRequest = true;
1006 return wpa_sm_step(sm);
1010 void wpa_auth_sta_no_wpa(struct wpa_state_machine *sm) argument
1015 if (!sm)
1018 sm->wpa_key_mgmt = 0;
1022 static void wpa_free_sta_sm(struct wpa_state_machine *sm) argument
1029 if (WPA_GET_BE32(sm->ip_addr)) {
1033 sm->ip_addr[0], sm->ip_addr[1],
1034 sm->ip_addr[2], sm->ip_addr[3],
1035 MAC2STR(wpa_auth_get_spa(sm)),
1036 sm->ip_addr_bit);
1037 bitfield_clear(sm->wpa_auth->ip_pool, sm->ip_addr_bit);
1040 if (sm->GUpdateStationKeys)
1041 wpa_gkeydone_sta(sm);
1043 os_free(sm->assoc_resp_ftie);
1044 wpabuf_free(sm->ft_pending_req_ies);
1046 os_free(sm->last_rx_eapol_key);
1047 os_free(sm->wpa_ie);
1048 os_free(sm->rsnxe);
1049 os_free(sm->rsn_selection);
1051 for_each_sm_auth(sm, link_id) {
1052 wpa_group_put(sm->mld_links[link_id].wpa_auth,
1053 sm->mld_links[link_id].wpa_auth->group);
1054 sm->mld_links[link_id].wpa_auth = NULL;
1057 wpa_group_put(sm->wpa_auth, sm->group);
1059 wpabuf_clear_free(sm->dpp_z);
1061 bin_clear_free(sm, sizeof(*sm));
1065 void wpa_auth_sta_deinit(struct wpa_state_machine *sm) argument
1069 if (!sm)
1072 wpa_auth = sm->wpa_auth;
1073 if (wpa_auth->conf.wpa_strict_rekey && sm->has_GTK) {
1076 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm), LOGGER_DEBUG,
1090 eloop_cancel_timeout(wpa_send_eapol_timeout, wpa_auth, sm);
1091 sm->pending_1_of_4_timeout = 0;
1092 eloop_cancel_timeout(wpa_sm_call_step, sm, NULL);
1093 eloop_cancel_timeout(wpa_rekey_ptk, wpa_auth, sm);
1095 wpa_ft_sta_deinit(sm);
1097 if (sm->in_step_loop) {
1102 MACSTR, MAC2STR(wpa_auth_get_spa(sm)));
1103 sm->pending_deinit = 1;
1105 wpa_free_sta_sm(sm);
1109 static void wpa_request_new_ptk(struct wpa_state_machine *sm) argument
1111 if (!sm)
1114 if (!sm->use_ext_key_id && sm->wpa_auth->conf.wpa_deny_ptk0_rekey) {
1117 MAC2STR(wpa_auth_get_spa(sm)));
1118 sm->Disconnect = true;
1120 sm->disconnect_reason =
1123 if (sm->use_ext_key_id)
1124 sm->keyidx_active ^= 1; /* flip Key ID */
1125 sm->PTKRequest = true;
1126 sm->PTK_valid = 0;
1162 struct wpa_state_machine *sm, argument
1180 if (wpa_parse_wpa_ie_rsn(sm->wpa_ie, sm->wpa_ie_len, &assoc_ie) < 0) {
1191 if (os_memcmp_const(pmkid, sm->pmk_r1_name,
1219 wpa_auth_logger(sm->wpa_auth, wpa_auth_get_spa(sm),
1226 sm->pmk_r1_name, WPA_PMK_NAME_LEN);
1245 if (sm->assoc_resp_ftie &&
1246 (kde->ftie[1] != sm->assoc_resp_ftie[1] ||
1247 os_memcmp(kde->ftie, sm->assoc_resp_ftie,
1248 2 + sm->assoc_resp_ftie[1]) != 0)) {
1253 sm->assoc_resp_ftie, 2 + sm->assoc_resp_ftie[1]);
1263 struct wpa_state_machine *sm, int group) argument
1266 wpa_auth_vlogger(wpa_auth, wpa_auth_get_spa(sm), LOGGER_INFO,
1271 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm), LOGGER_INFO,
1273 } else if (!group && sm->pairwise != WPA_CIPHER_TKIP) {
1274 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm), LOGGER_INFO,
1278 wpa_auth_get_spa(sm)) > 0)
1280 sm->dot11RSNAStatsTKIPRemoteMICFailures++;
1288 wpa_request_new_ptk(sm);
1293 static int wpa_try_alt_snonce(struct wpa_state_machine *sm, u8 *data, argument
1308 if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) &&
1309 !wpa_key_mgmt_sae(sm->wpa_key_mgmt)) {
1310 pmk = wpa_auth_get_psk(sm->wpa_auth, sm->addr,
1311 sm->p2p_dev_addr, pmk, &pmk_len,
1316 if (wpa_key_mgmt_ft_psk(sm->wpa_key_mgmt)) {
1317 os_memcpy(sm->xxkey, pmk, pmk_len);
1318 sm->xxkey_len = pmk_len;
1322 pmk = sm->PMK;
1323 pmk_len = sm->pmk_len;
1326 if (wpa_derive_ptk(sm, sm->alt_SNonce, pmk, pmk_len, &PTK, 0,
1331 if (wpa_verify_key_mic(sm->wpa_key_mgmt, pmk_len, &PTK,
1333 if (sm->PMK != pmk) {
1334 os_memcpy(sm->PMK, pmk, pmk_len);
1335 sm->pmk_len = pmk_len;
1341 if (!wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) ||
1342 wpa_key_mgmt_sae(sm->wpa_key_mgmt))
1354 sm->alt_snonce_valid = 0;
1356 if (vlan_id && wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) &&
1357 wpa_auth_update_vlan(sm->wpa_auth, sm->addr, vlan_id) < 0)
1361 if (wpa_key_mgmt_ft(sm->wpa_key_mgmt) && !sm->ft_completed) {
1363 wpa_auth_ft_store_keys(sm, pmk_r0, pmk_r1, pmk_r0_name,
1368 os_memcpy(sm->SNonce, sm->alt_SNonce, WPA_NONCE_LEN);
1369 os_memcpy(&sm->PTK, &PTK, sizeof(PTK));
1371 sm->PTK_valid = true;
1396 struct wpa_state_machine *sm, u16 ver) argument
1401 MAC2STR(wpa_auth_get_spa(sm)), ver);
1405 if (!wpa_use_akm_defined(sm->wpa_key_mgmt) &&
1406 wpa_use_cmac(sm->wpa_key_mgmt) &&
1408 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm),
1414 if (sm->pairwise != WPA_CIPHER_TKIP &&
1415 !wpa_use_akm_defined(sm->wpa_key_mgmt) &&
1416 !wpa_use_cmac(sm->wpa_key_mgmt) &&
1418 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm),
1424 if (wpa_use_akm_defined(sm->wpa_key_mgmt) &&
1426 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm),
1437 struct wpa_state_machine *sm, argument
1441 if (sm->req_replay_counter_used &&
1442 os_memcmp(replay_counter, sm->req_replay_counter,
1444 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm),
1455 struct wpa_state_machine *sm, argument
1463 return wpa_auth_valid_request_counter(wpa_auth, sm,
1466 if (wpa_replay_counter_valid(sm->key_replay, key->replay_counter))
1470 wpa_replay_counter_valid(sm->prev_key_replay,
1472 sm->wpa_ptk_state == WPA_PTK_PTKINITNEGOTIATING &&
1473 os_memcmp(sm->SNonce, key->key_nonce, WPA_NONCE_LEN) != 0) {
1481 wpa_auth_vlogger(wpa_auth, wpa_auth_get_spa(sm),
1484 sm->update_snonce = 1;
1485 os_memcpy(sm->alt_SNonce, sm->SNonce, WPA_NONCE_LEN);
1486 sm->alt_snonce_valid = true;
1487 os_memcpy(sm->alt_replay_counter,
1488 sm->key_replay[0].counter,
1493 if (msg == PAIRWISE_4 && sm->alt_snonce_valid &&
1494 sm->wpa_ptk_state == WPA_PTK_PTKINITNEGOTIATING &&
1495 os_memcmp(key->replay_counter, sm->alt_replay_counter,
1502 wpa_auth_vlogger(wpa_auth, wpa_auth_get_spa(sm),
1509 wpa_replay_counter_valid(sm->prev_key_replay,
1511 sm->wpa_ptk_state == WPA_PTK_PTKINITNEGOTIATING) {
1512 wpa_auth_vlogger(wpa_auth, wpa_auth_get_spa(sm),
1517 wpa_auth_vlogger(wpa_auth, wpa_auth_get_spa(sm),
1523 if (!sm->key_replay[i].valid)
1526 sm->key_replay[i].counter,
1536 struct wpa_state_machine *sm, argument
1550 if (!wpa_auth || !wpa_auth->conf.wpa || !sm)
1555 mic_len = wpa_mic_len(sm->wpa_key_mgmt, sm->pmk_len);
1571 MAC2STR(wpa_auth_get_spa(sm)), key_info, key->type,
1586 if (sm->wpa == WPA_VERSION_WPA2) {
1623 if (!wpa_auth_valid_key_desc_ver(wpa_auth, sm, ver))
1626 sm->PTK_valid &&
1629 wpa_use_aes_key_wrap(sm->wpa_key_mgmt)) &&
1636 if (aes_unwrap(sm->PTK.kek, sm->PTK.kek_len,
1654 (sm->wpa == WPA_VERSION_WPA2 &&
1668 if (!wpa_auth_valid_counter(wpa_auth, sm, key, msg, msgtxt))
1672 if (sm->wpa == WPA_VERSION_WPA2 && mic_len == 0 &&
1674 wpa_auth_vlogger(wpa_auth, wpa_auth_get_spa(sm), LOGGER_DEBUG,
1682 if (sm->wpa_ptk_state != WPA_PTK_PTKSTART &&
1683 sm->wpa_ptk_state != WPA_PTK_PTKCALCNEGOTIATING &&
1684 (!sm->update_snonce ||
1685 sm->wpa_ptk_state != WPA_PTK_PTKINITNEGOTIATING)) {
1686 wpa_auth_vlogger(wpa_auth, wpa_auth_get_spa(sm),
1689 sm->wpa_ptk_state);
1693 if (sm->group->reject_4way_hs_for_entropy) {
1706 wpa_sta_disconnect(wpa_auth, sm->addr,
1712 if (sm->wpa_ptk_state != WPA_PTK_PTKINITNEGOTIATING ||
1713 !sm->PTK_valid) {
1714 wpa_auth_vlogger(wpa_auth, wpa_auth_get_spa(sm),
1717 sm->wpa_ptk_state);
1722 if (sm->wpa_ptk_group_state != WPA_PTK_GROUP_REKEYNEGOTIATING
1723 || !sm->PTK_valid) {
1724 wpa_auth_vlogger(wpa_auth, wpa_auth_get_spa(sm),
1727 sm->wpa_ptk_group_state);
1732 if (sm->wpa_ptk_state == WPA_PTK_PTKSTART ||
1733 sm->wpa_ptk_state == WPA_PTK_PTKCALCNEGOTIATING ||
1734 sm->wpa_ptk_state == WPA_PTK_PTKCALCNEGOTIATING2 ||
1735 sm->wpa_ptk_state == WPA_PTK_PTKINITNEGOTIATING) {
1736 wpa_auth_vlogger(wpa_auth, wpa_auth_get_spa(sm),
1739 sm->wpa_ptk_state);
1745 wpa_auth_vlogger(wpa_auth, wpa_auth_get_spa(sm), LOGGER_DEBUG,
1749 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm), LOGGER_INFO,
1754 if (!wpa_key_mgmt_fils(sm->wpa_key_mgmt) &&
1756 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm), LOGGER_INFO,
1762 if (wpa_key_mgmt_fils(sm->wpa_key_mgmt) &&
1764 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm), LOGGER_INFO,
1770 sm->MICVerified = false;
1771 if (sm->PTK_valid && !sm->update_snonce) {
1773 wpa_verify_key_mic(sm->wpa_key_mgmt, sm->pmk_len, &sm->PTK,
1775 (msg != PAIRWISE_4 || !sm->alt_snonce_valid ||
1776 wpa_try_alt_snonce(sm, data, data_len))) {
1777 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm),
1789 wpa_aead_decrypt(sm, &sm->PTK, data, data_len,
1791 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm),
1805 sm->MICVerified = true;
1806 eloop_cancel_timeout(wpa_send_eapol_timeout, wpa_auth, sm);
1807 sm->pending_1_of_4_timeout = 0;
1812 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm),
1817 if (sm->MICVerified) {
1818 sm->req_replay_counter_used = 1;
1819 os_memcpy(sm->req_replay_counter, key->replay_counter,
1822 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm),
1830 wpa_auth, sm,
1834 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm),
1837 wpa_request_new_ptk(sm);
1839 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm),
1855 wpa_replay_counter_mark_invalid(sm->key_replay,
1866 os_memcpy(sm->prev_key_replay, sm->key_replay,
1867 sizeof(sm->key_replay));
1869 os_memset(sm->prev_key_replay, 0,
1870 sizeof(sm->prev_key_replay));
1877 wpa_replay_counter_mark_invalid(sm->key_replay, NULL);
1880 os_free(sm->last_rx_eapol_key);
1881 sm->last_rx_eapol_key = os_memdup(data, data_len);
1882 if (!sm->last_rx_eapol_key)
1884 sm->last_rx_eapol_key_len = data_len;
1886 sm->rx_eapol_key_secure = !!(key_info & WPA_KEY_INFO_SECURE);
1887 sm->EAPOLKeyReceived = true;
1888 sm->EAPOLKeyPairwise = !!(key_info & WPA_KEY_INFO_KEY_TYPE);
1889 sm->EAPOLKeyRequest = !!(key_info & WPA_KEY_INFO_REQUEST);
1891 os_memcpy(sm->SNonce, key->key_nonce, WPA_NONCE_LEN);
1892 wpa_sm_step(sm);
1950 struct wpa_state_machine *sm = timeout_ctx; local
1952 if (sm->waiting_radius_psk) {
1953 wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG,
1958 sm->pending_1_of_4_timeout = 0;
1959 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm), LOGGER_DEBUG,
1961 sm->TimeoutEvt = true;
1962 wpa_sm_step(sm);
1967 struct wpa_state_machine *sm, int key_info, argument
1983 mic_len = wpa_mic_len(sm->wpa_key_mgmt, sm->pmk_len);
1990 else if (wpa_use_akm_defined(sm->wpa_key_mgmt))
1992 else if (wpa_use_cmac(sm->wpa_key_mgmt))
1994 else if (sm->pairwise != WPA_CIPHER_TKIP)
2013 wpa_use_aes_key_wrap(sm->wpa_key_mgmt) ||
2035 key->type = sm->wpa == WPA_VERSION_WPA2 ?
2038 if (encr && sm->wpa == WPA_VERSION_WPA2)
2040 if (sm->wpa != WPA_VERSION_WPA2)
2044 alg = pairwise ? sm->pairwise : conf->wpa_group;
2045 if (sm->wpa == WPA_VERSION_WPA2 && !pairwise)
2051 sm->key_replay[i].valid = sm->key_replay[i - 1].valid;
2052 os_memcpy(sm->key_replay[i].counter,
2053 sm->key_replay[i - 1].counter,
2056 inc_byte_array(sm->key_replay[0].counter, WPA_REPLAY_COUNTER_LEN);
2057 os_memcpy(key->replay_counter, sm->key_replay[0].counter,
2061 sm->key_replay[0].valid = true;
2082 sm->PTK.kek, sm->PTK.kek_len);
2087 if (aes_siv_encrypt(sm->PTK.kek, sm->PTK.kek_len, kde, kde_len,
2113 wpa_use_aes_key_wrap(sm->wpa_key_mgmt) ||
2116 sm->PTK.kek, sm->PTK.kek_len);
2117 if (aes_wrap(sm->PTK.kek, sm->PTK.kek_len,
2128 } else if (sm->PTK.kek_len == 16) {
2134 sm->group->Counter + WPA_NONCE_LEN - 16, 16);
2135 inc_byte_array(sm->group->Counter, WPA_NONCE_LEN);
2137 os_memcpy(ek + 16, sm->PTK.kek, sm->PTK.kek_len);
2151 if (!sm->PTK_valid || !mic_len) {
2152 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm),
2159 if (wpa_eapol_key_mic(sm->PTK.kck, sm->PTK.kck_len,
2160 sm->wpa_key_mgmt, version,
2169 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm),
2177 wpa_auth_set_eapol(wpa_auth, sm->addr, WPA_EAPOL_inc_EapolFramesTx, 1);
2179 wpa_auth_send_eapol(wpa_auth, sm->addr, (u8 *) hdr, len,
2180 sm->pairwise_set);
2195 struct wpa_state_machine *sm, int key_info, argument
2204 if (!sm)
2207 ctr = pairwise ? sm->TimeoutCtr : sm->GTimeoutCtr;
2215 wpa_msg(sm->wpa_auth->conf.msg_ctx, MSG_INFO,
2220 __wpa_send_eapol(wpa_auth, sm, key_info, key_rsc, nonce, kde, kde_len,
2240 sm->pending_1_of_4_timeout = 1;
2248 wpa_send_eapol_timeout, wpa_auth, sm);
2281 void wpa_remove_ptk(struct wpa_state_machine *sm) argument
2283 sm->PTK_valid = false;
2284 os_memset(&sm->PTK, 0, sizeof(sm->PTK));
2286 wpa_auth_remove_ptksa(sm->wpa_auth, sm->addr, sm->pairwise);
2288 if (wpa_auth_set_key(sm->wpa_auth, 0, WPA_ALG_NONE, sm->addr, 0, NULL,
2292 if (sm->use_ext_key_id &&
2293 wpa_auth_set_key(sm->wpa_auth, 0, WPA_ALG_NONE, sm->addr, 1, NULL,
2297 sm->pairwise_set = false;
2298 eloop_cancel_timeout(wpa_rekey_ptk, sm->wpa_auth, sm);
2302 int wpa_auth_sm_event(struct wpa_state_machine *sm, enum wpa_event event) argument
2306 if (!sm)
2309 wpa_auth_vlogger(sm->wpa_auth, wpa_auth_get_spa(sm), LOGGER_DEBUG,
2316 if (wpa_auth_start_ampe(sm->wpa_auth, sm->addr)) {
2326 sm->DeauthenticationRequest = true;
2327 os_memset(sm->PMK, 0, sizeof(sm->PMK));
2328 sm->pmk_len = 0;
2330 os_memset(sm->xxkey, 0, sizeof(sm->xxkey));
2331 sm->xxkey_len = 0;
2332 os_memset(sm->pmk_r1, 0, sizeof(sm->pmk_r1));
2333 sm->pmk_r1_len = 0;
2338 if (!sm->started) {
2348 sm->started = 1;
2349 sm->Init = true;
2350 if (wpa_sm_step(sm) == 1)
2352 sm->Init = false;
2353 sm->AuthenticationRequest = true;
2357 if (sm->ptkstart_without_success > 3) {
2360 MACSTR, MAC2STR(sm->addr));
2361 sm->Disconnect = true;
2365 if (!sm->use_ext_key_id &&
2366 sm->wpa_auth->conf.wpa_deny_ptk0_rekey) {
2369 MACSTR, MAC2STR(wpa_auth_get_spa(sm)));
2370 sm->Disconnect = true;
2372 sm->disconnect_reason =
2377 if (sm->use_ext_key_id)
2378 sm->keyidx_active ^= 1; /* flip Key ID */
2380 if (sm->GUpdateStationKeys) {
2385 wpa_gkeydone_sta(sm);
2386 sm->PtkGroupInit = true;
2388 sm->ReAuthenticationRequest = true;
2394 wpa_ft_install_ptk(sm, 1);
2397 sm->ft_completed = 1;
2398 wpa_auth_set_ptk_rekey_timer(sm);
2407 fils_set_tk(sm);
2408 sm->fils_completed = 1;
2414 sm->tk_already_set = false;
2419 sm->ft_completed = 0;
2422 if (sm->mgmt_frame_prot && event == WPA_AUTH)
2425 if (wpa_key_mgmt_fils(sm->wpa_key_mgmt) &&
2431 sm->PTK_valid = false;
2432 os_memset(&sm->PTK, 0, sizeof(sm->PTK));
2435 wpa_remove_ptk(sm);
2438 if (sm->in_step_loop) {
2443 sm->changed = true;
2446 return wpa_sm_step(sm);
2453 if (sm->Init) {
2456 sm->changed = false;
2459 sm->keycount = 0;
2460 if (sm->GUpdateStationKeys)
2461 wpa_gkeydone_sta(sm);
2462 if (sm->wpa == WPA_VERSION_WPA)
2463 sm->PInitAKeys = false;
2466 sm->Pair = true;
2468 wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_portEnabled, 0);
2469 wpa_remove_ptk(sm);
2470 wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_portValid, 0);
2471 sm->TimeoutCtr = 0;
2472 if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) ||
2473 sm->wpa_key_mgmt == WPA_KEY_MGMT_DPP ||
2474 sm->wpa_key_mgmt == WPA_KEY_MGMT_OWE) {
2475 wpa_auth_set_eapol(sm->wpa_auth, sm->addr,
2483 u16 reason = sm->disconnect_reason;
2486 sm->Disconnect = false;
2487 sm->disconnect_reason = 0;
2490 wpa_sta_disconnect(sm->wpa_auth, sm->addr, reason);
2497 sm->DeauthenticationRequest = false;
2504 os_memset(&sm->PTK, 0, sizeof(sm->PTK));
2505 sm->PTK_valid = false;
2506 wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_portControl_Auto,
2508 wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_portEnabled, 1);
2509 sm->AuthenticationRequest = false;
2550 wpa_group_ensure_init(sm->wpa_auth, sm->group);
2551 sm->ReAuthenticationRequest = false;
2562 if (random_get_bytes(sm->ANonce, WPA_NONCE_LEN)) {
2565 sm->Disconnect = true;
2568 wpa_hexdump(MSG_DEBUG, "WPA: Assign ANonce", sm->ANonce,
2574 sm->TimeoutCtr = 0;
2578 static int wpa_auth_sm_ptk_update(struct wpa_state_machine *sm) argument
2580 if (random_get_bytes(sm->ANonce, WPA_NONCE_LEN)) {
2583 sm->Disconnect = true;
2586 wpa_hexdump(MSG_DEBUG, "WPA: Assign new ANonce", sm->ANonce,
2588 sm->TimeoutCtr = 0;
2600 sm->xxkey_len = 0;
2602 if (sm->pmksa) {
2604 os_memcpy(sm->PMK, sm->pmksa->pmk, sm->pmksa->pmk_len);
2605 sm->pmk_len = sm->pmksa->pmk_len;
2607 } else if (sm->wpa_key_mgmt == WPA_KEY_MGMT_DPP) {
2610 sm->Disconnect = true;
2611 sm->disconnect_reason = WLAN_REASON_INVALID_PMKID;
2614 } else if (wpa_auth_get_msk(sm->wpa_auth, wpa_auth_get_spa(sm),
2618 if (wpa_key_mgmt_sha384(sm->wpa_key_mgmt))
2629 sm->Disconnect = true;
2632 os_memcpy(sm->PMK, msk, pmk_len);
2633 sm->pmk_len = pmk_len;
2636 if (wpa_key_mgmt_sha384(sm->wpa_key_mgmt)) {
2637 os_memcpy(sm->xxkey, msk, SHA384_MAC_LEN);
2638 sm->xxkey_len = SHA384_MAC_LEN;
2640 os_memcpy(sm->xxkey, msk + PMK_LEN, PMK_LEN);
2641 sm->xxkey_len = PMK_LEN;
2647 sm->wpa_auth->cb->get_msk);
2648 sm->Disconnect = true;
2653 sm->req_replay_counter_used = 0;
2662 wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_keyRun, false);
2672 psk = wpa_auth_get_psk(sm->wpa_auth, sm->addr, sm->p2p_dev_addr, NULL,
2675 os_memcpy(sm->PMK, psk, psk_len);
2676 sm->pmk_len = psk_len;
2678 sm->xxkey_len = PMK_LEN;
2680 if (sm->wpa_key_mgmt == WPA_KEY_MGMT_FT_SAE_EXT_KEY &&
2683 sm->xxkey_len = psk_len;
2685 os_memcpy(sm->xxkey, psk, sm->xxkey_len);
2689 if (wpa_auth_uses_sae(sm) && sm->pmksa) {
2691 sm->pmksa->pmk_len);
2692 os_memcpy(sm->PMK, sm->pmksa->pmk, sm->pmksa->pmk_len);
2693 sm->pmk_len = sm->pmksa->pmk_len;
2695 os_memcpy(sm->xxkey, sm->pmksa->pmk, sm->pmksa->pmk_len);
2696 sm->xxkey_len = sm->pmksa->pmk_len;
2700 sm->req_replay_counter_used = 0;
2712 struct wpa_auth_config *conf = &sm->wpa_auth->conf;
2716 sm->PTKRequest = false;
2717 sm->TimeoutEvt = false;
2718 sm->alt_snonce_valid = false;
2719 sm->ptkstart_without_success++;
2721 sm->TimeoutCtr++;
2722 if (sm->TimeoutCtr > sm->wpa_auth->conf.wpa_pairwise_update_count) {
2729 if (sm->mld_assoc_link_id >= 0)
2741 wpa_auth_logger(sm->wpa_auth, wpa_auth_get_spa(sm), LOGGER_DEBUG,
2757 if (sm->wpa == WPA_VERSION_WPA2 &&
2758 (wpa_key_mgmt_wpa_ieee8021x(sm->wpa_key_mgmt) ||
2759 (sm->wpa_key_mgmt == WPA_KEY_MGMT_OWE && sm->pmksa) ||
2760 wpa_key_mgmt_sae(sm->wpa_key_mgmt)) &&
2761 sm->wpa_key_mgmt != WPA_KEY_MGMT_OSEN) {
2767 if (sm->pmksa) {
2770 sm->pmksa->pmkid, PMKID_LEN);
2772 sm->pmksa->pmkid, PMKID_LEN);
2773 } else if (wpa_key_mgmt_suite_b(sm->wpa_key_mgmt)) {
2779 } else if (wpa_key_mgmt_fils(sm->wpa_key_mgmt)) {
2780 if (sm->pmkid_set) {
2783 sm->pmkid, PMKID_LEN);
2785 sm->pmkid, PMKID_LEN);
2794 } else if (wpa_key_mgmt_ft(sm->wpa_key_mgmt) &&
2795 sm->ft_completed) {
2801 } else if (wpa_key_mgmt_sae(sm->wpa_key_mgmt)) {
2802 if (sm->pmkid_set) {
2805 sm->pmkid, PMKID_LEN);
2807 sm->pmkid, PMKID_LEN);
2820 rsn_pmkid(sm->PMK, sm->pmk_len,
2821 wpa_auth_get_aa(sm),
2822 wpa_auth_get_spa(sm),
2824 sm->wpa_key_mgmt);
2834 if (sm->mld_assoc_link_id >= 0) {
2839 sm->wpa_auth->mld_addr, ETH_ALEN, NULL, 0);
2853 if (sm->pairwise_set && sm->wpa != WPA_VERSION_WPA)
2855 wpa_send_eapol(sm->wpa_auth, sm, key_info, NULL,
2856 sm->ANonce, kde_len ? buf : NULL, kde_len, 0, 0);
2861 static int wpa_derive_ptk(struct wpa_state_machine *sm, const u8 *snonce, argument
2872 if (sm->wpa_auth->conf.force_kdk_derivation ||
2873 (!no_kdk && sm->wpa_auth->conf.secure_ltf &&
2874 ieee802_11_rsnx_capab(sm->rsnxe, WLAN_RSNX_CAPAB_SECURE_LTF)))
2880 if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
2881 if (sm->ft_completed) {
2884 ret = wpa_pmk_r1_to_ptk(sm->pmk_r1, sm->pmk_r1_len,
2885 sm->SNonce, sm->ANonce,
2886 wpa_auth_get_spa(sm),
2887 wpa_auth_get_aa(sm),
2888 sm->pmk_r1_name, ptk,
2889 ptk_name, sm->wpa_key_mgmt,
2890 sm->pairwise, kdk_len);
2892 ret = wpa_auth_derive_ptk_ft(sm, ptk, pmk_r0, pmk_r1,
2902 if (!no_kdk && sm->wpa_auth->conf.secure_ltf &&
2903 ieee802_11_rsnx_capab(sm->rsnxe,
2905 ret = wpa_ltf_keyseed(ptk, sm->wpa_key_mgmt,
2906 sm->pairwise);
2918 if (sm->wpa_key_mgmt == WPA_KEY_MGMT_DPP && sm->dpp_z) {
2919 z = wpabuf_head(sm->dpp_z);
2920 z_len = wpabuf_len(sm->dpp_z);
2924 akmp = sm->wpa_key_mgmt;
2928 wpa_auth_get_aa(sm), wpa_auth_get_spa(sm),
2929 sm->ANonce, snonce, ptk, akmp,
2930 sm->pairwise, z, z_len, kdk_len);
2938 if (!no_kdk && sm->wpa_auth->conf.secure_ltf &&
2939 ieee802_11_rsnx_capab(sm->rsnxe, WLAN_RSNX_CAPAB_SECURE_LTF)) {
2940 ret = wpa_ltf_keyseed(ptk, sm->wpa_key_mgmt, sm->pairwise);
2953 int fils_auth_pmk_to_ptk(struct wpa_state_machine *sm, const u8 *pmk, argument
2964 if (sm->wpa_auth->conf.force_kdk_derivation ||
2965 (sm->wpa_auth->conf.secure_ltf &&
2966 ieee802_11_rsnx_capab(sm->rsnxe, WLAN_RSNX_CAPAB_SECURE_LTF)))
2971 res = fils_pmk_to_ptk(pmk, pmk_len, wpa_auth_get_spa(sm),
2972 wpa_auth_get_aa(sm),
2974 &sm->PTK, ick, &ick_len,
2975 sm->wpa_key_mgmt, sm->pairwise,
2981 if (sm->wpa_auth->conf.secure_ltf &&
2982 ieee802_11_rsnx_capab(sm->rsnxe, WLAN_RSNX_CAPAB_SECURE_LTF)) {
2983 res = wpa_ltf_keyseed(&sm->PTK, sm->wpa_key_mgmt, sm->pairwise);
2992 sm->PTK_valid = true;
2993 sm->tk_already_set = false;
2997 struct wpa_authenticator *wpa_auth = sm->wpa_auth;
3006 wpa_auth_get_spa(sm), pmk_r0, pmk_r0_name,
3007 sm->wpa_key_mgmt) < 0)
3010 wpa_ft_store_pmk_fils(sm, pmk_r0, pmk_r0_name);
3014 wpa_auth_get_spa(sm),
3015 sm->pmk_r1_name,
3020 wpa_hexdump(MSG_DEBUG, "FILS+FT: PMKR1Name", sm->pmk_r1_name,
3022 sm->pmk_r1_name_valid = 1;
3027 wpa_auth_get_spa(sm),
3028 wpa_auth_get_aa(sm),
3033 sm->wpa_key_mgmt, sm->fils_key_auth_sta,
3034 sm->fils_key_auth_ap,
3035 &sm->fils_key_auth_len);
3039 os_memcpy(sm->SNonce, snonce, FILS_NONCE_LEN);
3040 os_memcpy(sm->ANonce, anonce, FILS_NONCE_LEN);
3046 static int wpa_aead_decrypt(struct wpa_state_machine *sm, struct wpa_ptk *ptk, argument
3063 wpa_auth_logger(sm->wpa_auth, wpa_auth_get_spa(sm), LOGGER_INFO,
3079 wpa_auth_logger(sm->wpa_auth, wpa_auth_get_spa(sm), LOGGER_INFO,
3101 const u8 * wpa_fils_validate_fils_session(struct wpa_state_machine *sm, argument
3108 if (!wpa_key_mgmt_fils(sm->wpa_key_mgmt)) {
3155 int wpa_fils_validate_key_confirm(struct wpa_state_machine *sm, const u8 *ies, argument
3176 if (elems.fils_key_confirm_len != sm->fils_key_auth_len) {
3180 sm->fils_key_auth_len);
3184 if (os_memcmp(elems.fils_key_confirm, sm->fils_key_auth_sta,
3185 sm->fils_key_auth_len) != 0) {
3190 sm->fils_key_auth_sta, sm->fils_key_auth_len);
3198 int fils_decrypt_assoc(struct wpa_state_machine *sm, const u8 *fils_session, argument
3207 if (!sm || !sm->PTK_valid) {
3213 if (!wpa_key_mgmt_fils(sm->wpa_key_mgmt)) {
3232 session = wpa_fils_validate_fils_session(sm, ie, end - ie,
3256 aad[2] = sm->SNonce;
3259 aad[3] = sm->ANonce;
3268 if (aes_siv_decrypt(sm->PTK.kek, sm->PTK.kek_len, crypt, end - crypt,
3277 if (wpa_fils_validate_key_confirm(sm, pos, left - AES_BLOCK_SIZE) < 0) {
3286 int fils_encrypt_assoc(struct wpa_state_machine *sm, u8 *buf, argument
3297 if (!sm || !sm->PTK_valid)
3315 aad[2] = sm->ANonce;
3318 aad[3] = sm->SNonce;
3329 plain = fils_prepare_plainbuf(sm, hlp);
3345 if (aes_siv_encrypt(sm->PTK.kek, sm->PTK.kek_len,
3358 sm->fils_completed = 1;
3364 static struct wpabuf * fils_prepare_plainbuf(struct wpa_state_machine *sm, argument
3374 struct wpa_auth_config *conf = &sm->wpa_auth->conf;
3376 plain_len = 1000 + ieee80211w_kde_len(sm);
3387 wpabuf_put_u8(plain, 1 + sm->fils_key_auth_len); /* Length */
3390 wpabuf_put_data(plain, sm->fils_key_auth_ap, sm->fils_key_auth_len);
3399 gsm = sm->group;
3403 wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN,
3408 if (conf->disable_gtk || sm->wpa_key_mgmt == WPA_KEY_MGMT_OSEN) {
3428 tmp2 = ieee80211w_kde_add(sm, tmp);
3441 if (wpa_auth_uses_ocv(sm)) {
3445 if (wpa_channel_info(sm->wpa_auth, &ci) != 0) {
3473 int fils_set_tk(struct wpa_state_machine *sm) argument
3478 if (!sm || !sm->PTK_valid) {
3482 if (sm->tk_already_set) {
3487 alg = wpa_cipher_to_alg(sm->pairwise);
3488 klen = wpa_cipher_key_len(sm->pairwise);
3491 if (wpa_auth_set_key(sm->wpa_auth, 0, alg, sm->addr, 0,
3492 sm->PTK.tk, klen, KEY_FLAG_PAIRWISE_RX_TX)) {
3498 if (sm->wpa_auth->conf.secure_ltf &&
3499 ieee802_11_rsnx_capab(sm->rsnxe, WLAN_RSNX_CAPAB_SECURE_LTF) &&
3500 wpa_auth_set_ltf_keyseed(sm->wpa_auth, sm->addr,
3501 sm->PTK.ltf_keyseed,
3502 sm->PTK.ltf_keyseed_len)) {
3509 sm->pairwise_set = true;
3510 sm->tk_already_set = true;
3512 wpa_auth_store_ptksa(sm->wpa_auth, sm->addr, sm->pairwise,
3513 dot11RSNAConfigPMKLifetime, &sm->PTK);
3519 u8 * hostapd_eid_assoc_fils_session(struct wpa_state_machine *sm, u8 *buf, argument
3532 plain = fils_prepare_plainbuf(sm, hlp);
3544 sm->fils_completed = 1;
3552 int get_sta_tx_parameters(struct wpa_state_machine *sm, int ap_max_chanwidth, argument
3555 struct wpa_authenticator *wpa_auth = sm->wpa_auth;
3559 return wpa_auth->cb->get_sta_tx_params(wpa_auth->cb_ctx, sm->addr,
3566 static int wpa_auth_validate_ml_kdes_m2(struct wpa_state_machine *sm, argument
3573 if (sm->mld_assoc_link_id < 0)
3578 !ether_addr_equal(kde->mac_addr, sm->peer_mld_addr)) {
3596 if (!sm->mld_links[i].valid || i == sm->mld_assoc_link_id) {
3602 if (!ether_addr_equal(sm->mld_links[i].peer_addr,
3608 MAC2STR(sm->mld_links[i].peer_addr), i);
3616 if (n_links != sm->n_mld_affiliated_links) {
3619 sm->n_mld_affiliated_links, n_links);
3630 struct wpa_authenticator *wpa_auth = sm->wpa_auth;
3652 sm->EAPOLKeyReceived = false;
3653 sm->update_snonce = false;
3656 mic_len = wpa_mic_len(sm->wpa_key_mgmt, sm->pmk_len);
3658 derive_kdk = sm->wpa_auth->conf.secure_ltf &&
3659 ieee802_11_rsnx_capab(sm->rsnxe, WLAN_RSNX_CAPAB_SECURE_LTF);
3665 if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) &&
3666 !wpa_key_mgmt_sae(sm->wpa_key_mgmt)) {
3667 pmk = wpa_auth_get_psk(sm->wpa_auth, sm->addr,
3668 sm->p2p_dev_addr, pmk, &pmk_len,
3674 if (wpa_key_mgmt_ft_psk(sm->wpa_key_mgmt)) {
3675 os_memcpy(sm->xxkey, pmk, pmk_len);
3676 sm->xxkey_len = pmk_len;
3680 pmk = sm->PMK;
3681 pmk_len = sm->pmk_len;
3684 if ((!pmk || !pmk_len) && sm->pmksa) {
3686 pmk = sm->pmksa->pmk;
3687 pmk_len = sm->pmksa->pmk_len;
3692 if (wpa_derive_ptk(sm, sm->SNonce, pmk, pmk_len, &PTK,
3698 wpa_verify_key_mic(sm->wpa_key_mgmt, pmk_len, &PTK,
3699 sm->last_rx_eapol_key,
3700 sm->last_rx_eapol_key_len) == 0) {
3701 if (sm->PMK != pmk) {
3702 os_memcpy(sm->PMK, pmk, pmk_len);
3703 sm->pmk_len = pmk_len;
3711 wpa_aead_decrypt(sm, &PTK, sm->last_rx_eapol_key,
3712 sm->last_rx_eapol_key_len, NULL) == 0) {
3719 if (sm->wpa_key_mgmt == WPA_KEY_MGMT_OWE && pmk_len > 32 &&
3732 if (!sm->wpa_auth->conf.force_kdk_derivation &&
3740 if (!wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) ||
3741 wpa_key_mgmt_sae(sm->wpa_key_mgmt))
3750 MACSTR, MAC2STR(sm->addr));
3753 if (!ok && wpa_key_mgmt_wpa_psk_no_sae(sm->wpa_key_mgmt) &&
3755 !sm->waiting_radius_psk) {
3757 wpa_auth->cb->request_radius_psk(wpa_auth->cb_ctx, sm->addr,
3758 sm->wpa_key_mgmt,
3759 sm->ANonce,
3760 sm->last_rx_eapol_key,
3761 sm->last_rx_eapol_key_len);
3762 sm->waiting_radius_psk = 1;
3767 wpa_auth_logger(sm->wpa_auth, wpa_auth_get_spa(sm),
3771 wpa_auth_psk_failure_report(sm->wpa_auth, sm->addr);
3779 hdr = (struct ieee802_1x_hdr *) sm->last_rx_eapol_key;
3785 if (key_data_length > sm->last_rx_eapol_key_len - sizeof(*hdr) -
3793 !wpa_use_aes_key_wrap(sm->wpa_key_mgmt)) {
3823 wpa_auth_vlogger(wpa_auth, wpa_auth_get_spa(sm), LOGGER_INFO,
3837 ft = sm->wpa == WPA_VERSION_WPA2 && wpa_key_mgmt_ft(sm->wpa_key_mgmt);
3838 if (!sm->wpa_ie ||
3839 wpa_compare_rsn_ie(ft, sm->wpa_ie, sm->wpa_ie_len,
3841 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm), LOGGER_INFO,
3843 if (sm->wpa_ie) {
3845 sm->wpa_ie, sm->wpa_ie_len);
3850 wpa_sta_disconnect(wpa_auth, sm->addr,
3854 if ((!sm->rsnxe && kde.rsnxe) ||
3855 (sm->rsnxe && !kde.rsnxe) ||
3856 (sm->rsnxe && kde.rsnxe &&
3857 (sm->rsnxe_len != kde.rsnxe_len ||
3858 os_memcmp(sm->rsnxe, kde.rsnxe, sm->rsnxe_len) != 0))) {
3859 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm), LOGGER_INFO,
3862 sm->rsnxe, sm->rsnxe_len);
3866 wpa_sta_disconnect(wpa_auth, sm->addr,
3871 if (wpa_auth_uses_ocv(sm)) {
3878 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm),
3884 if (get_sta_tx_parameters(sm,
3892 if (wpa_auth_uses_ocv(sm) == 2 && res == OCI_NOT_FOUND) {
3894 wpa_auth_vlogger(wpa_auth, wpa_auth_get_spa(sm),
3897 wpa_auth_set_ocv(sm, 0);
3899 wpa_auth_vlogger(wpa_auth, wpa_auth_get_spa(sm),
3906 MAC2STR(wpa_auth_get_spa(sm)),
3913 if (ft && ft_check_msg_2_of_4(wpa_auth, sm, &kde) < 0) {
3914 wpa_sta_disconnect(wpa_auth, sm->addr,
3923 ((rsn_is_snonce_cookie(sm->SNonce) && !kde.rsn_selection) ||
3924 (!rsn_is_snonce_cookie(sm->SNonce) && kde.rsn_selection) ||
3925 (sm->rsn_selection && !kde.rsn_selection) ||
3926 (!sm->rsn_selection && kde.rsn_selection) ||
3927 (sm->rsn_selection && kde.rsn_selection &&
3928 (sm->rsn_selection_len != kde.rsn_selection_len ||
3929 os_memcmp(sm->rsn_selection, kde.rsn_selection,
3930 sm->rsn_selection_len) != 0)))) {
3931 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm), LOGGER_INFO,
3935 rsn_is_snonce_cookie(sm->SNonce) ? "" : "not ");
3937 sm->rsn_selection, sm->rsn_selection_len);
3941 wpa_sta_disconnect(wpa_auth, sm->addr,
3949 wpa_auth->ip_pool && WPA_GET_BE32(sm->ip_addr) == 0) {
3957 sm->ip_addr_bit = idx;
3958 WPA_PUT_BE32(sm->ip_addr, start + idx);
3962 sm->ip_addr[0], sm->ip_addr[1],
3963 sm->ip_addr[2], sm->ip_addr[3],
3964 MAC2STR(wpa_auth_get_spa(sm)),
3965 sm->ip_addr_bit);
3975 if (sm->wpa_key_mgmt == WPA_KEY_MGMT_DPP &&
3978 !sm->dpp_z) {
3981 wpa_sta_disconnect(wpa_auth, sm->addr,
3988 if (wpa_auth_validate_ml_kdes_m2(sm, &kde) < 0) {
3989 wpa_sta_disconnect(wpa_auth, sm->addr,
3994 if (vlan_id && wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) &&
3995 wpa_auth_update_vlan(wpa_auth, sm->addr, vlan_id) < 0) {
3996 wpa_sta_disconnect(wpa_auth, sm->addr,
4001 sm->pending_1_of_4_timeout = 0;
4002 eloop_cancel_timeout(wpa_send_eapol_timeout, sm->wpa_auth, sm);
4004 if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) && sm->PMK != pmk) {
4008 os_memcpy(sm->PMK, pmk, PMK_LEN);
4009 sm->pmk_len = PMK_LEN;
4012 sm->MICVerified = true;
4015 if (wpa_key_mgmt_ft(sm->wpa_key_mgmt) && !sm->ft_completed) {
4017 wpa_auth_ft_store_keys(sm, pmk_r0, pmk_r1, pmk_r0_name,
4022 os_memcpy(&sm->PTK, &PTK, sizeof(PTK));
4024 sm->PTK_valid = true;
4035 sm->TimeoutCtr = 0;
4039 static int ieee80211w_kde_len(struct wpa_state_machine *sm) argument
4042 struct wpa_authenticator *wpa_auth = sm->wpa_auth;
4044 if (sm->mgmt_frame_prot) {
4051 if (sm->mgmt_frame_prot && sm->wpa_auth->conf.beacon_prot) {
4060 static u8 * ieee80211w_kde_add(struct wpa_state_machine *sm, u8 *pos) argument
4064 struct wpa_group *gsm = sm->group;
4066 struct wpa_authenticator *wpa_auth = sm->wpa_auth;
4070 if (!sm->mgmt_frame_prot)
4074 if (sm->mld_assoc_link_id >= 0)
4081 wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN_igtk, rsc) < 0)
4086 if (conf->disable_gtk || sm->wpa_key_mgmt == WPA_KEY_MGMT_OSEN) {
4106 if (!sm->wpa_auth->conf.beacon_prot)
4112 wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN_bigtk, rsc) < 0)
4117 if (sm->wpa_key_mgmt == WPA_KEY_MGMT_OSEN) {
4134 static int ocv_oci_len(struct wpa_state_machine *sm) argument
4137 if (wpa_auth_uses_ocv(sm))
4144 static int ocv_oci_add(struct wpa_state_machine *sm, u8 **argpos, argument
4150 if (!wpa_auth_uses_ocv(sm))
4153 if (wpa_channel_info(sm->wpa_auth, &ci) != 0) {
4268 static size_t wpa_auth_ml_group_kdes_len(struct wpa_state_machine *sm) argument
4274 if (sm->mld_assoc_link_id < 0)
4278 if (!sm->mld_links[link_id].valid)
4281 wpa_auth = sm->mld_links[link_id].wpa_auth;
4290 if (!sm->mgmt_frame_prot)
4316 static u8 * wpa_auth_ml_group_kdes(struct wpa_state_machine *sm, u8 *pos) argument
4324 ml_key_info.n_mld_links = sm->n_mld_affiliated_links + 1;
4330 ml_key_info.mgmt_frame_prot = sm->mgmt_frame_prot;
4331 ml_key_info.beacon_prot = sm->wpa_auth->conf.beacon_prot;
4334 if (!sm->mld_links[link_id].valid)
4340 wpa_auth_get_ml_key_info(sm->wpa_auth, &ml_key_info);
4344 if (!sm->mld_links[link_id].valid ||
4372 if (!sm->mgmt_frame_prot) {
4380 if (!sm->mld_links[link_id].valid ||
4415 if (!sm->wpa_auth->conf.beacon_prot) {
4423 if (!sm->mld_links[link_id].valid ||
4466 static size_t wpa_auth_ml_kdes_len(struct wpa_state_machine *sm) argument
4473 if (sm->mld_assoc_link_id < 0)
4484 wpa_auth = wpa_get_link_auth(sm->wpa_auth, link_id);
4501 if (!rsn_is_snonce_cookie(sm->SNonce))
4523 kde_len += wpa_auth_ml_group_kdes_len(sm);
4530 static u8 * wpa_auth_ml_kdes(struct wpa_state_machine *sm, u8 *pos) argument
4536 if (sm->mld_assoc_link_id < 0)
4541 sm->wpa_auth->mld_addr, ETH_ALEN, NULL, 0);
4549 wpa_auth = wpa_get_link_auth(sm->wpa_auth, link_id);
4595 if (!rsn_is_snonce_cookie(sm->SNonce))
4651 pos = wpa_auth_ml_group_kdes(sm, pos);
4662 struct wpa_group *gsm = sm->group;
4667 struct wpa_auth_config *conf = &sm->wpa_auth->conf;
4669 bool is_mld = sm->mld_assoc_link_id >= 0;
4675 sm->TimeoutEvt = false;
4677 sm->TimeoutCtr++;
4678 if (conf->wpa_disable_eapol_key_retries && sm->TimeoutCtr > 1) {
4682 if (sm->TimeoutCtr > conf->wpa_pairwise_update_count) {
4692 wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN, rsc);
4694 wpa_ie = sm->wpa_auth->wpa_ie;
4695 wpa_ie_len = sm->wpa_auth->wpa_ie_len;
4696 if (sm->wpa == WPA_VERSION_WPA && (conf->wpa & WPA_PROTO_RSN) &&
4707 !rsn_is_snonce_cookie(sm->SNonce)) {
4759 wpa_auth_logger(sm->wpa_auth, wpa_auth_get_spa(sm), LOGGER_DEBUG,
4761 if (sm->wpa == WPA_VERSION_WPA2) {
4762 if (sm->use_ext_key_id && sm->TimeoutCtr == 1 &&
4763 wpa_auth_set_key(sm->wpa_auth, 0,
4764 wpa_cipher_to_alg(sm->pairwise),
4765 sm->addr,
4766 sm->keyidx_active, sm->PTK.tk,
4767 wpa_cipher_key_len(sm->pairwise),
4769 wpa_sta_disconnect(sm->wpa_auth, sm->addr,
4775 if (sm->wpa_auth->conf.secure_ltf &&
4776 ieee802_11_rsnx_capab(sm->rsnxe,
4778 wpa_auth_set_ltf_keyseed(sm->wpa_auth, sm->addr,
4779 sm->PTK.ltf_keyseed,
4780 sm->PTK.ltf_keyseed_len)) {
4783 wpa_sta_disconnect(sm->wpa_auth, sm->addr,
4794 sm->wpa_key_mgmt == WPA_KEY_MGMT_OSEN) {
4813 if (sm->rx_eapol_key_secure) {
4822 wpa_auth_logger(sm->wpa_auth, wpa_auth_get_spa(sm),
4829 kde_len = wpa_ie_len + ieee80211w_kde_len(sm) + ocv_oci_len(sm);
4831 if (sm->use_ext_key_id)
4837 if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
4843 if (WPA_GET_BE32(sm->ip_addr) > 0)
4851 if (sm->wpa_key_mgmt == WPA_KEY_MGMT_DPP)
4855 kde_len += wpa_auth_ml_kdes_len(sm);
4857 if (sm->ssid_protection)
4875 if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
4880 res = wpa_insert_pmkid(kde, &elen, sm->pmk_r1_name, true);
4892 if (sm->use_ext_key_id) {
4893 hdr[0] = sm->keyidx_active & 0x01;
4902 pos = ieee80211w_kde_add(sm, pos);
4903 if (ocv_oci_add(sm, &pos, conf->oci_freq_override_eapol_m3) < 0)
4907 if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
4910 if (sm->assoc_resp_ftie &&
4911 kde + kde_len - pos >= 2 + sm->assoc_resp_ftie[1]) {
4912 os_memcpy(pos, sm->assoc_resp_ftie,
4913 2 + sm->assoc_resp_ftie[1]);
4914 res = 2 + sm->assoc_resp_ftie[1];
4916 res = wpa_write_ftie(conf, sm->wpa_key_mgmt,
4917 sm->xxkey_len,
4947 if (WPA_GET_BE32(sm->ip_addr) > 0) {
4949 os_memcpy(addr, sm->ip_addr, 4);
4962 if (DPP_VERSION > 1 && sm->wpa_key_mgmt == WPA_KEY_MGMT_DPP) {
4977 pos = wpa_auth_ml_kdes(sm, pos);
4983 if (sm->ssid_protection) {
5001 wpa_send_eapol(sm->wpa_auth, sm,
5003 (wpa_mic_len(sm->wpa_key_mgmt, sm->pmk_len) ?
5007 _rsc, sm->ANonce, kde, pos - kde, 0, encr);
5016 static int wpa_auth_validate_ml_kdes_m4(struct wpa_state_machine *sm) argument
5026 if (sm->mld_assoc_link_id < 0)
5033 mic_len = wpa_mic_len(sm->wpa_key_mgmt, sm->pmk_len);
5035 hdr = (const struct ieee802_1x_hdr *) sm->last_rx_eapol_key;
5040 if (key_data_length > sm->last_rx_eapol_key_len - sizeof(*hdr) -
5045 wpa_auth_vlogger(sm->wpa_auth, wpa_auth_get_spa(sm),
5053 !ether_addr_equal(kde.mac_addr, sm->peer_mld_addr)) {
5070 sm->EAPOLKeyReceived = false;
5072 if (wpa_auth_validate_ml_kdes_m4(sm) < 0) {
5073 wpa_sta_disconnect(sm->wpa_auth, sm->addr,
5078 if (sm->Pair) {
5079 enum wpa_alg alg = wpa_cipher_to_alg(sm->pairwise);
5080 int klen = wpa_cipher_key_len(sm->pairwise);
5083 if (sm->use_ext_key_id)
5084 res = wpa_auth_set_key(sm->wpa_auth, 0, 0, sm->addr,
5085 sm->keyidx_active, NULL, 0,
5088 res = wpa_auth_set_key(sm->wpa_auth, 0, alg, sm->addr,
5089 0, sm->PTK.tk, klen,
5092 wpa_sta_disconnect(sm->wpa_auth, sm->addr,
5098 if (sm->wpa_auth->conf.secure_ltf &&
5099 ieee802_11_rsnx_capab(sm->rsnxe,
5101 wpa_auth_set_ltf_keyseed(sm->wpa_auth, sm->addr,
5102 sm->PTK.ltf_keyseed,
5103 sm->PTK.ltf_keyseed_len)) {
5106 wpa_sta_disconnect(sm->wpa_auth, sm->addr,
5113 sm->pairwise_set = true;
5115 wpa_auth_set_ptk_rekey_timer(sm);
5116 wpa_auth_store_ptksa(sm->wpa_auth, sm->addr, sm->pairwise,
5117 dot11RSNAConfigPMKLifetime, &sm->PTK);
5119 if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) ||
5120 sm->wpa_key_mgmt == WPA_KEY_MGMT_DPP ||
5121 sm->wpa_key_mgmt == WPA_KEY_MGMT_OWE) {
5122 wpa_auth_set_eapol(sm->wpa_auth, sm->addr,
5128 sm->keycount++;
5129 if (sm->keycount == 2) {
5130 wpa_auth_set_eapol(sm->wpa_auth, sm->addr,
5134 wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_portValid,
5137 wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_keyAvailable,
5139 wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_keyDone, true);
5140 if (sm->wpa == WPA_VERSION_WPA)
5141 sm->PInitAKeys = true;
5143 sm->has_GTK = true;
5144 wpa_auth_vlogger(sm->wpa_auth, wpa_auth_get_spa(sm), LOGGER_INFO,
5146 sm->wpa == WPA_VERSION_WPA ? "WPA" : "RSN");
5147 wpa_msg(sm->wpa_auth->conf.msg_ctx, MSG_INFO, "EAPOL-4WAY-HS-COMPLETED "
5148 MACSTR, MAC2STR(sm->addr));
5151 wpa_ft_push_pmk_r1(sm->wpa_auth, wpa_auth_get_spa(sm));
5154 sm->ptkstart_without_success = 0;
5160 struct wpa_authenticator *wpa_auth = sm->wpa_auth;
5163 if (sm->Init)
5165 else if (sm->Disconnect
5167 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm), LOGGER_DEBUG,
5171 else if (sm->DeauthenticationRequest)
5173 else if (sm->AuthenticationRequest)
5175 else if (sm->ReAuthenticationRequest)
5177 else if (sm->PTKRequest) {
5178 if (wpa_auth_sm_ptk_update(sm) < 0)
5182 } else switch (sm->wpa_ptk_state) {
5195 if (wpa_key_mgmt_wpa_ieee8021x(sm->wpa_key_mgmt) &&
5196 wpa_auth_get_eapol(wpa_auth, sm->addr,
5199 else if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt) ||
5200 sm->wpa_key_mgmt == WPA_KEY_MGMT_OWE
5203 else if (sm->wpa_key_mgmt == WPA_KEY_MGMT_DPP)
5207 if (wpa_auth_get_eapol(wpa_auth, sm->addr,
5211 } else if (sm->wpa_key_mgmt == WPA_KEY_MGMT_DPP && sm->pmksa) {
5216 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm),
5223 if (wpa_auth_get_psk(wpa_auth, sm->addr, sm->p2p_dev_addr,
5227 } else if (wpa_auth_uses_sae(sm) && sm->pmksa) {
5230 } else if (wpa_key_mgmt_wpa_psk_no_sae(sm->wpa_key_mgmt) &&
5236 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm),
5244 if (sm->EAPOLKeyReceived && !sm->EAPOLKeyRequest &&
5245 sm->EAPOLKeyPairwise)
5247 else if (sm->TimeoutCtr > conf->wpa_pairwise_update_count) {
5249 wpa_auth_vlogger(wpa_auth, wpa_auth_get_spa(sm),
5253 sm->disconnect_reason =
5256 } else if (sm->TimeoutEvt)
5260 if (sm->MICVerified)
5262 else if (sm->EAPOLKeyReceived && !sm->EAPOLKeyRequest &&
5263 sm->EAPOLKeyPairwise)
5265 else if (sm->TimeoutEvt)
5272 if (sm->update_snonce)
5274 else if (sm->EAPOLKeyReceived && !sm->EAPOLKeyRequest &&
5275 sm->EAPOLKeyPairwise && sm->MICVerified)
5277 else if (sm->TimeoutCtr >
5280 sm->TimeoutCtr > 1)) {
5282 wpa_auth_vlogger(wpa_auth, wpa_auth_get_spa(sm),
5286 sm->disconnect_reason =
5289 } else if (sm->TimeoutEvt)
5301 if (sm->Init) {
5304 sm->changed = false;
5306 sm->GTimeoutCtr = 0;
5313 struct wpa_group *gsm = sm->group;
5318 struct wpa_auth_config *conf = &sm->wpa_auth->conf;
5322 is_mld = sm->mld_assoc_link_id >= 0;
5327 sm->GTimeoutCtr++;
5328 if (conf->wpa_disable_eapol_key_retries && sm->GTimeoutCtr > 1) {
5332 if (sm->GTimeoutCtr > conf->wpa_group_update_count) {
5338 if (sm->wpa == WPA_VERSION_WPA)
5339 sm->PInitAKeys = false;
5340 sm->TimeoutEvt = false;
5344 wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN, rsc);
5345 wpa_auth_logger(sm->wpa_auth, wpa_auth_get_spa(sm), LOGGER_DEBUG,
5349 if (conf->disable_gtk || sm->wpa_key_mgmt == WPA_KEY_MGMT_OSEN) {
5359 if (sm->wpa == WPA_VERSION_WPA2 && !is_mld) {
5361 ieee80211w_kde_len(sm) + ocv_oci_len(sm);
5371 pos = ieee80211w_kde_add(sm, pos);
5372 if (ocv_oci_add(sm, &pos,
5379 } else if (sm->wpa == WPA_VERSION_WPA2 && is_mld) {
5380 kde_len = wpa_auth_ml_group_kdes_len(sm);
5387 pos = wpa_auth_ml_group_kdes(sm, pos);
5396 wpa_send_eapol(sm->wpa_auth, sm,
5398 (wpa_mic_len(sm->wpa_key_mgmt, sm->pmk_len) ?
5401 (!sm->Pair ? WPA_KEY_INFO_INSTALL : 0),
5410 struct wpa_authenticator *wpa_auth = sm->wpa_auth;
5421 sm->EAPOLKeyReceived = false;
5424 mic_len = wpa_mic_len(sm->wpa_key_mgmt, sm->pmk_len);
5430 hdr = (struct ieee802_1x_hdr *) sm->last_rx_eapol_key;
5435 if (key_data_length > sm->last_rx_eapol_key_len - sizeof(*hdr) -
5440 wpa_auth_vlogger(wpa_auth, wpa_auth_get_spa(sm), LOGGER_INFO,
5445 if (wpa_auth_uses_ocv(sm)) {
5451 wpa_auth_logger(wpa_auth, wpa_auth_get_spa(sm),
5457 if (get_sta_tx_parameters(sm,
5466 wpa_auth_vlogger(wpa_auth, wpa_auth_get_spa(sm),
5473 MAC2STR(wpa_auth_get_spa(sm)),
5480 if (sm->GUpdateStationKeys)
5481 wpa_gkeydone_sta(sm);
5482 sm->GTimeoutCtr = 0;
5484 wpa_auth_vlogger(wpa_auth, wpa_auth_get_spa(sm), LOGGER_INFO,
5486 sm->wpa == WPA_VERSION_WPA ? "WPA" : "RSN");
5487 sm->has_GTK = true;
5494 if (sm->GUpdateStationKeys)
5495 wpa_gkeydone_sta(sm);
5496 if (sm->wpa_auth->conf.no_disconnect_on_group_keyerror &&
5497 sm->wpa == WPA_VERSION_WPA2) {
5498 wpa_auth_vlogger(sm->wpa_auth, wpa_auth_get_spa(sm),
5501 sm->wpa_auth->conf.wpa_group_update_count);
5504 sm->Disconnect = true;
5505 sm->disconnect_reason = WLAN_REASON_GROUP_KEY_UPDATE_TIMEOUT;
5506 wpa_auth_vlogger(sm->wpa_auth, wpa_auth_get_spa(sm), LOGGER_INFO,
5508 sm->wpa == WPA_VERSION_WPA ? "WPA" : "RSN",
5509 sm->wpa_auth->conf.wpa_group_update_count);
5515 if (sm->Init || sm->PtkGroupInit) {
5517 sm->PtkGroupInit = false;
5518 } else switch (sm->wpa_ptk_group_state) {
5520 if (sm->GUpdateStationKeys ||
5521 (sm->wpa == WPA_VERSION_WPA && sm->PInitAKeys))
5525 if (sm->EAPOLKeyReceived && !sm->EAPOLKeyRequest &&
5526 !sm->EAPOLKeyPairwise && sm->MICVerified)
5528 else if (sm->GTimeoutCtr >
5529 sm->wpa_auth->conf.wpa_group_update_count ||
5530 (sm->wpa_auth->conf.wpa_disable_eapol_key_retries &&
5531 sm->GTimeoutCtr > 1))
5533 else if (sm->TimeoutEvt)
5624 static int wpa_group_update_sta(struct wpa_state_machine *sm, void *ctx) argument
5626 if (ctx != NULL && ctx != sm->group)
5629 if (sm->wpa_ptk_state != WPA_PTK_PTKINITDONE) {
5630 wpa_auth_logger(sm->wpa_auth, wpa_auth_get_spa(sm),
5633 sm->GUpdateStationKeys = false;
5636 if (sm->GUpdateStationKeys) {
5642 wpa_auth_logger(sm->wpa_auth, wpa_auth_get_spa(sm),
5648 if (sm->is_wnmsleep)
5651 sm->group->GKeyDoneStations++;
5652 sm->GUpdateStationKeys = true;
5654 wpa_sm_step(sm);
5661 void wpa_wnmsleep_rekey_gtk(struct wpa_state_machine *sm) argument
5663 if (!sm || sm->is_wnmsleep)
5666 wpa_group_update_sta(sm, NULL);
5670 void wpa_set_wnmsleep(struct wpa_state_machine *sm, int flag) argument
5672 if (sm)
5673 sm->is_wnmsleep = !!flag;
5677 int wpa_wnmsleep_gtk_subelem(struct wpa_state_machine *sm, u8 *pos) argument
5679 struct wpa_auth_config *conf = &sm->wpa_auth->conf;
5680 struct wpa_group *gsm = sm->group;
5694 if (wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN, pos) != 0)
5698 if (conf->disable_gtk || sm->wpa_key_mgmt == WPA_KEY_MGMT_OSEN) {
5717 int wpa_wnmsleep_igtk_subelem(struct wpa_state_machine *sm, u8 *pos) argument
5719 struct wpa_auth_config *conf = &sm->wpa_auth->conf;
5720 struct wpa_group *gsm = sm->group;
5722 size_t len = wpa_cipher_key_len(sm->wpa_auth->conf.group_mgmt_cipher);
5732 if (wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN_igtk, pos) != 0)
5737 if (conf->disable_gtk || sm->wpa_key_mgmt == WPA_KEY_MGMT_OSEN) {
5756 int wpa_wnmsleep_bigtk_subelem(struct wpa_state_machine *sm, u8 *pos) argument
5758 struct wpa_authenticator *wpa_auth = sm->wpa_auth;
5776 if (sm->wpa_key_mgmt == WPA_KEY_MGMT_OSEN) {
5899 static int wpa_group_disconnect_cb(struct wpa_state_machine *sm, void *ctx) argument
5901 if (sm->group == ctx) {
5904 MAC2STR(wpa_auth_get_spa(sm)));
5905 sm->Disconnect = true;
5963 static void wpa_clear_changed(struct wpa_state_machine *sm) argument
5969 sm->changed = false;
5970 sm->wpa_auth->group->changed = false;
5973 for_each_sm_auth(sm, link_id)
5974 sm->mld_links[link_id].wpa_auth->group->changed = false;
5979 static void wpa_group_sm_step_links(struct wpa_state_machine *sm) argument
5985 if (!sm || !sm->wpa_auth)
5987 wpa_group_sm_step(sm->wpa_auth, sm->wpa_auth->group);
5990 for_each_sm_auth(sm, link_id) {
5991 wpa_group_sm_step(sm->mld_links[link_id].wpa_auth,
5992 sm->mld_links[link_id].wpa_auth->group);
5998 static bool wpa_group_sm_changed(struct wpa_state_machine *sm) argument
6005 if (!sm || !sm->wpa_auth)
6007 changed = sm->wpa_auth->group->changed;
6010 for_each_sm_auth(sm, link_id)
6011 changed |= sm->mld_links[link_id].wpa_auth->group->changed;
6018 static int wpa_sm_step(struct wpa_state_machine *sm) argument
6020 if (!sm)
6023 if (sm->in_step_loop) {
6031 sm->in_step_loop = 1;
6033 if (sm->pending_deinit)
6036 wpa_clear_changed(sm);
6039 if (sm->pending_deinit)
6042 if (sm->pending_deinit)
6044 wpa_group_sm_step_links(sm);
6045 } while (sm->changed || wpa_group_sm_changed(sm));
6046 sm->in_step_loop = 0;
6048 if (sm->pending_deinit) {
6051 MACSTR, MAC2STR(wpa_auth_get_spa(sm)));
6052 wpa_free_sta_sm(sm);
6061 struct wpa_state_machine *sm = eloop_ctx; local
6062 wpa_sm_step(sm);
6066 void wpa_auth_sm_notify(struct wpa_state_machine *sm) argument
6068 if (!sm)
6070 eloop_register_timeout(0, 0, wpa_sm_call_step, sm, NULL);
6203 int wpa_get_mib_sta(struct wpa_state_machine *sm, char *buf, size_t buflen) argument
6208 if (!sm)
6215 pairwise = wpa_cipher_to_suite(sm->wpa == WPA_VERSION_WPA2 ?
6217 sm->pairwise);
6233 MAC2STR(sm->addr),
6235 sm->dot11RSNAStatsTKIPLocalMICFailures,
6236 sm->dot11RSNAStatsTKIPRemoteMICFailures);
6248 sm->wpa,
6249 RSN_SUITE_ARG(wpa_akm_to_suite(sm->wpa_key_mgmt)),
6250 sm->wpa_ptk_state,
6251 sm->wpa_ptk_group_state,
6252 sm->mfpr);
6268 int wpa_auth_pairwise_set(struct wpa_state_machine *sm) argument
6270 return sm && sm->pairwise_set;
6274 int wpa_auth_get_pairwise(struct wpa_state_machine *sm) argument
6276 return sm->pairwise;
6280 const u8 * wpa_auth_get_pmk(struct wpa_state_machine *sm, int *len) argument
6282 if (!sm)
6284 *len = sm->pmk_len;
6285 return sm->PMK;
6289 const u8 * wpa_auth_get_dpp_pkhash(struct wpa_state_machine *sm) argument
6291 if (!sm || !sm->pmksa)
6293 return sm->pmksa->dpp_pkhash;
6297 int wpa_auth_sta_key_mgmt(struct wpa_state_machine *sm) argument
6299 if (!sm)
6301 return sm->wpa_key_mgmt;
6305 int wpa_auth_sta_wpa_version(struct wpa_state_machine *sm) argument
6307 if (!sm)
6309 return sm->wpa;
6313 int wpa_auth_sta_ft_tk_already_set(struct wpa_state_machine *sm) argument
6315 if (!sm || !wpa_key_mgmt_ft(sm->wpa_key_mgmt))
6317 return sm->tk_already_set;
6321 int wpa_auth_sta_fils_tk_already_set(struct wpa_state_machine *sm) argument
6323 if (!sm || !wpa_key_mgmt_fils(sm->wpa_key_mgmt))
6325 return sm->tk_already_set;
6329 int wpa_auth_sta_clear_pmksa(struct wpa_state_machine *sm, argument
6332 if (!sm || sm->pmksa != entry)
6334 sm->pmksa = NULL;
6340 wpa_auth_sta_get_pmksa(struct wpa_state_machine *sm) argument
6342 return sm ? sm->pmksa : NULL;
6346 void wpa_auth_sta_local_mic_failure_report(struct wpa_state_machine *sm) argument
6348 if (sm)
6349 sm->dot11RSNAStatsTKIPLocalMICFailures++;
6362 int wpa_auth_pmksa_add(struct wpa_state_machine *sm, const u8 *pmk, argument
6366 if (!sm || sm->wpa != WPA_VERSION_WPA2 ||
6367 sm->wpa_auth->conf.disable_pmksa_caching)
6371 if (pmk_len >= 2 * PMK_LEN && wpa_key_mgmt_ft(sm->wpa_key_mgmt) &&
6372 wpa_key_mgmt_wpa_ieee8021x(sm->wpa_key_mgmt) &&
6373 !wpa_key_mgmt_sha384(sm->wpa_key_mgmt)) {
6379 if (wpa_key_mgmt_sha384(sm->wpa_key_mgmt)) {
6387 if (pmksa_cache_auth_add(sm->wpa_auth->pmksa, pmk, pmk_len, NULL,
6388 sm->PTK.kck, sm->PTK.kck_len,
6389 wpa_auth_get_aa(sm),
6390 wpa_auth_get_spa(sm), session_timeout,
6391 eapol, sm->wpa_key_mgmt))
6436 void wpa_auth_add_sae_pmkid(struct wpa_state_machine *sm, const u8 *pmkid) argument
6438 os_memcpy(sm->pmkid, pmkid, PMKID_LEN);
6439 sm->pmkid_set = 1;
6571 struct wpa_state_machine *sm, argument
6575 if (!sm)
6578 sm->pmksa = pmksa;
6756 int wpa_auth_sta_set_vlan(struct wpa_state_machine *sm, int vlan_id) argument
6760 if (!sm || !sm->wpa_auth)
6763 group = sm->wpa_auth->group;
6771 group = wpa_auth_add_group(sm->wpa_auth, vlan_id);
6776 if (sm->group == group)
6784 MAC2STR(wpa_auth_get_spa(sm)), vlan_id);
6786 wpa_group_get(sm->wpa_auth, group);
6787 wpa_group_put(sm->wpa_auth, sm->group);
6788 sm->group = group;
6795 struct wpa_state_machine *sm, int ack) argument
6797 if (!wpa_auth || !sm)
6800 " ack=%d", MAC2STR(wpa_auth_get_spa(sm)), ack);
6801 if (sm->pending_1_of_4_timeout && ack) {
6816 eloop_cancel_timeout(wpa_send_eapol_timeout, wpa_auth, sm);
6819 wpa_send_eapol_timeout, wpa_auth, sm);
6823 if (sm->eapol_status_cb) {
6824 sm->eapol_status_cb(sm->eapol_status_cb_ctx1,
6825 sm->eapol_status_cb_ctx2);
6826 sm->eapol_status_cb = NULL;
6832 int wpa_auth_uses_sae(struct wpa_state_machine *sm) argument
6834 if (!sm)
6836 return wpa_key_mgmt_sae(sm->wpa_key_mgmt);
6840 int wpa_auth_uses_ft_sae(struct wpa_state_machine *sm) argument
6842 if (!sm)
6844 return sm->wpa_key_mgmt == WPA_KEY_MGMT_FT_SAE ||
6845 sm->wpa_key_mgmt == WPA_KEY_MGMT_FT_SAE_EXT_KEY;
6850 int wpa_auth_get_ip_addr(struct wpa_state_machine *sm, u8 *addr) argument
6852 if (!sm || WPA_GET_BE32(sm->ip_addr) == 0)
6854 os_memcpy(addr, sm->ip_addr, 4);
6922 struct wpa_state_machine *sm, argument
6927 return wpa_write_ftie(conf, sm->wpa_key_mgmt, sm->xxkey_len,
6934 void wpa_auth_get_fils_aead_params(struct wpa_state_machine *sm, argument
6938 os_memcpy(fils_anonce, sm->ANonce, WPA_NONCE_LEN);
6939 os_memcpy(fils_snonce, sm->SNonce, WPA_NONCE_LEN);
6940 os_memcpy(fils_kek, sm->PTK.kek, WPA_KEK_MAX_LEN);
6941 *fils_kek_len = sm->PTK.kek_len;
6945 void wpa_auth_add_fils_pmk_pmkid(struct wpa_state_machine *sm, const u8 *pmk, argument
6948 os_memcpy(sm->PMK, pmk, pmk_len);
6949 sm->pmk_len = pmk_len;
6950 os_memcpy(sm->pmkid, pmkid, PMKID_LEN);
6951 sm->pmkid_set = 1;
6957 void wpa_auth_set_auth_alg(struct wpa_state_machine *sm, u16 auth_alg) argument
6959 if (sm)
6960 sm->auth_alg = auth_alg;
6964 void wpa_auth_set_rsn_selection(struct wpa_state_machine *sm, const u8 *ie, argument
6967 if (!sm)
6969 os_free(sm->rsn_selection);
6970 sm->rsn_selection = NULL;
6971 sm->rsn_selection_len = 0;
6972 sm->rsn_override = false;
6973 sm->rsn_override_2 = false;
6977 sm->rsn_override = true;
6979 sm->rsn_override_2 = true;
6981 sm->rsn_selection = os_memdup(ie, len);
6982 if (sm->rsn_selection)
6983 sm->rsn_selection_len = len;
6989 void wpa_auth_set_dpp_z(struct wpa_state_machine *sm, const struct wpabuf *z) argument
6991 if (sm) {
6992 wpabuf_clear_free(sm->dpp_z);
6993 sm->dpp_z = z ? wpabuf_dup(z) : NULL;
6999 void wpa_auth_set_ssid_protection(struct wpa_state_machine *sm, bool val) argument
7001 if (sm)
7002 sm->ssid_protection = val;
7016 int wpa_auth_resend_m1(struct wpa_state_machine *sm, int change_anonce, argument
7020 const u8 *anonce = sm->ANonce;
7029 wpa_auth_logger(sm->wpa_auth, wpa_auth_get_spa(sm), LOGGER_DEBUG,
7031 wpa_send_eapol(sm->wpa_auth, sm,
7038 int wpa_auth_resend_m3(struct wpa_state_machine *sm, argument
7045 struct wpa_auth_config *conf = &sm->wpa_auth->conf;
7046 struct wpa_group *gsm = sm->group;
7058 wpa_ie = sm->wpa_auth->wpa_ie;
7059 wpa_ie_len = sm->wpa_auth->wpa_ie_len;
7060 if (sm->wpa == WPA_VERSION_WPA &&
7061 (sm->wpa_auth->conf.wpa & WPA_PROTO_RSN) &&
7071 wpa_auth_logger(sm->wpa_auth, wpa_auth_get_spa(sm), LOGGER_DEBUG,
7073 if (sm->wpa == WPA_VERSION_WPA2) {
7087 if (sm->rx_eapol_key_secure) {
7096 wpa_auth_logger(sm->wpa_auth, wpa_auth_get_spa(sm),
7103 kde_len = wpa_ie_len + ieee80211w_kde_len(sm) + ocv_oci_len(sm);
7105 if (sm->use_ext_key_id)
7111 if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
7124 if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
7129 res = wpa_insert_pmkid(kde, &elen, sm->pmk_r1_name, true);
7142 if (sm->use_ext_key_id) {
7143 hdr[0] = sm->keyidx_active & 0x01;
7153 pos = ieee80211w_kde_add(sm, pos);
7159 if (ocv_oci_add(sm, &pos, conf->oci_freq_override_eapol_m3) < 0) {
7165 if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
7168 if (sm->assoc_resp_ftie &&
7169 kde + kde_len - pos >= 2 + sm->assoc_resp_ftie[1]) {
7170 os_memcpy(pos, sm->assoc_resp_ftie,
7171 2 + sm->assoc_resp_ftie[1]);
7172 res = 2 + sm->assoc_resp_ftie[1];
7174 res = wpa_write_ftie(conf, sm->wpa_key_mgmt,
7175 sm->xxkey_len,
7206 wpa_send_eapol(sm->wpa_auth, sm,
7208 (wpa_mic_len(sm->wpa_key_mgmt, sm->pmk_len) ?
7212 _rsc, sm->ANonce, kde, pos - kde, 0, encr);
7218 int wpa_auth_resend_group_m1(struct wpa_state_machine *sm, argument
7223 struct wpa_auth_config *conf = &sm->wpa_auth->conf;
7224 struct wpa_group *gsm = sm->group;
7234 wpa_auth_logger(sm->wpa_auth, wpa_auth_get_spa(sm), LOGGER_DEBUG,
7238 if (sm->wpa == WPA_VERSION_WPA2) {
7240 ieee80211w_kde_len(sm) + ocv_oci_len(sm);
7251 pos = ieee80211w_kde_add(sm, pos);
7258 if (ocv_oci_add(sm, &pos,
7269 sm->eapol_status_cb = cb;
7270 sm->eapol_status_cb_ctx1 = ctx1;
7271 sm->eapol_status_cb_ctx2 = ctx2;
7273 wpa_send_eapol(sm->wpa_auth, sm,
7275 (wpa_mic_len(sm->wpa_key_mgmt, sm->pmk_len) ?
7278 (!sm->Pair ? WPA_KEY_INFO_INSTALL : 0),
7298 struct wpa_state_machine *sm) argument
7300 if (!wpa_auth || !sm)
7302 wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG, "rekeying PTK");
7303 wpa_request_new_ptk(sm);
7304 wpa_sm_step(sm);
7341 void wpa_auth_sta_radius_psk_resp(struct wpa_state_machine *sm, bool success) argument
7343 if (!sm->waiting_radius_psk) {
7347 MAC2STR(sm->addr));
7352 MAC2STR(sm->addr), success ? "success" : "fail");
7353 sm->waiting_radius_psk = 0;
7357 sm->EAPOLKeyReceived = true;
7359 sm->Disconnect = true;
7362 eloop_register_timeout(0, 0, wpa_sm_call_step, sm, NULL);
7366 void wpa_auth_set_ml_info(struct wpa_state_machine *sm, argument
7375 os_memset(sm->mld_links, 0, sizeof(sm->mld_links));
7376 sm->n_mld_affiliated_links = 0;
7378 wpa_auth_logger(sm->wpa_auth, wpa_auth_get_spa(sm), LOGGER_DEBUG,
7381 os_memcpy(sm->peer_mld_addr, info->common_info.mld_addr, ETH_ALEN);
7383 sm->mld_assoc_link_id = mld_assoc_link_id;
7387 struct mld_link *sm_link = &sm->mld_links[link_id];
7402 sm->n_mld_affiliated_links++;
7407 wpa_auth_for_each_auth(sm->wpa_auth,
7415 sm_link->wpa_auth = sm->wpa_auth;
7422 MAC2STR(sm->wpa_auth->mld_addr),