Home | History | Annotate | Download | only in wpa_supplicant

Lines Matching defs:sm

223 static void wpa_supplicant_peerkey_free(struct wpa_sm *sm,
729 struct wpa_sm *sm)
738 (sm->cur_pmksa ? 2 + PMKID_LEN : 0))
800 if (sm->cur_pmksa) {
805 os_memcpy(pos, sm->cur_pmksa->pmkid, PMKID_LEN);
811 if (!sm->cur_pmksa) {
837 * @sm: Pointer to WPA state machine data from wpa_sm_init()
842 static int wpa_gen_wpa_ie(struct wpa_sm *sm, u8 *wpa_ie, size_t wpa_ie_len)
844 if (sm->proto == WPA_PROTO_RSN)
846 sm->pairwise_cipher,
847 sm->group_cipher,
848 sm->key_mgmt, sm->mgmt_group_cipher,
849 sm);
852 sm->pairwise_cipher,
853 sm->group_cipher,
854 sm->key_mgmt);
940 static void wpa_eapol_key_send(struct wpa_sm *sm, const u8 *kck,
945 os_memcmp(sm->bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0) {
950 if (wpa_sm_get_bssid(sm, sm->bssid) < 0) {
954 dest = sm->bssid;
964 wpa_sm_ether_send(sm, dest, proto, msg, msg_len);
965 eapol_sm_notify_tx_eapol_key(sm->eapol);
972 * @sm: Pointer to WPA state machine data from wpa_sm_init()
981 void wpa_sm_key_request(struct wpa_sm *sm, int error, int pairwise)
988 if (sm->pairwise_cipher == WPA_CIPHER_CCMP)
993 if (wpa_sm_get_bssid(sm, bssid) < 0) {
999 rbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY, NULL,
1004 reply->type = sm->proto == WPA_PROTO_RSN ?
1007 if (sm->ptk_set)
1015 os_memcpy(reply->replay_counter, sm->request_counter,
1017 inc_byte_array(sm->request_counter, WPA_REPLAY_COUNTER_LEN);
1023 error, pairwise, sm->ptk_set, (unsigned long) rlen);
1024 wpa_eapol_key_send(sm, sm->ptk.kck, ver, bssid, ETH_P_EAPOL,
1032 * @sm: Pointer to WPA state machine data from wpa_sm_init()
1039 int wpa_sm_stkstart(struct wpa_sm *sm, const u8 *peer)
1047 struct wpa_ssid *ssid = sm->cur_ssid;
1052 if (sm->proto != WPA_PROTO_RSN || !sm->ptk_set ||
1056 if (sm->ap_rsn_ie &&
1057 wpa_parse_wpa_ie_rsn(sm->ap_rsn_ie, sm->ap_rsn_ie_len, &ie) == 0 &&
1063 if (sm->pairwise_cipher == WPA_CIPHER_CCMP)
1068 if (wpa_sm_get_bssid(sm, bssid) < 0) {
1084 * EAPOL-Key(S=1, M=1, A=0, I=0, K=0, SM=1, KeyRSC=0, Nonce=INonce,
1119 rbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY, NULL,
1123 wpa_supplicant_peerkey_free(sm, peerkey);
1132 os_memcpy(req->replay_counter, sm->request_counter,
1134 inc_byte_array(sm->request_counter, WPA_REPLAY_COUNTER_LEN);
1137 wpa_msg(sm->ctx->ctx, MSG_WARNING,
1140 wpa_supplicant_peerkey_free(sm, peerkey);
1157 wpa_eapol_key_send(sm, sm->ptk.kck, ver, bssid, ETH_P_EAPOL,
1160 peerkey->next = sm->peerkey;
1161 sm->peerkey = peerkey;
1345 static int wpa_supplicant_get_pmk(struct wpa_sm *sm,
1351 if (pmkid && !sm->cur_pmksa) {
1356 sm->cur_pmksa = pmksa_cache_get(sm->pmksa, src_addr, pmkid);
1357 if (sm->cur_pmksa) {
1366 if (pmkid && sm->cur_pmksa &&
1367 os_memcmp(pmkid, sm->cur_pmksa->pmkid, PMKID_LEN) == 0) {
1369 wpa_sm_set_pmk_from_pmksa(sm);
1371 sm->pmk, sm->pmk_len);
1372 eapol_sm_notify_cached(sm->eapol);
1373 } else if (sm->key_mgmt == WPA_KEY_MGMT_IEEE8021X && sm->eapol) {
1376 res = eapol_sm_get_key(sm->eapol, sm->pmk, PMK_LEN);
1382 res = eapol_sm_get_key(sm->eapol, sm->pmk, 16);
1387 "machines", sm->pmk, pmk_len);
1388 sm->pmk_len = pmk_len;
1389 pmksa_cache_add(sm->pmksa, sm->pmk, pmk_len, src_addr,
1390 sm->own_addr, sm->cur_ssid);
1391 if (!sm->cur_pmksa && pmkid &&
1392 pmksa_cache_get(sm->pmksa, src_addr, pmkid)) {
1398 wpa_msg(sm->ctx->ctx, MSG_WARNING,
1401 wpa_msg(sm->ctx->ctx, MSG_WARNING,
1403 if (sm->cur_pmksa) {
1406 sm->cur_pmksa = NULL;
1414 if (abort_cached && sm->key_mgmt == WPA_KEY_MGMT_IEEE8021X) {
1421 buf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_START,
1424 wpa_sm_ether_send(sm, sm->bssid, ETH_P_EAPOL,
1436 static int wpa_supplicant_send_2_of_4(struct wpa_sm *sm,
1455 rbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY,
1461 reply->type = sm->proto == WPA_PROTO_RSN ?
1465 if (sm->proto == WPA_PROTO_RSN)
1478 wpa_eapol_key_send(sm, ptk->kck, ver, dst, ETH_P_EAPOL,
1485 static void wpa_supplicant_process_1_of_4(struct wpa_sm *sm,
1494 if (wpa_sm_get_ssid(sm) == NULL) {
1500 wpa_sm_set_state(sm, WPA_4WAY_HANDSHAKE);
1507 if (sm->proto == WPA_PROTO_RSN) {
1520 if (wpa_supplicant_get_pmk(sm, src_addr, ie.pmkid))
1523 if (sm->renew_snonce) {
1524 if (hostapd_get_rand(sm->snonce, WPA_NONCE_LEN)) {
1525 wpa_msg(sm->ctx->ctx, MSG_WARNING,
1529 sm->renew_snonce = 0;
1531 sm->snonce, WPA_NONCE_LEN);
1536 ptk = &sm->tptk;
1537 wpa_pmk_to_ptk(sm->pmk, sm->pmk_len, "Pairwise key expansion",
1538 sm->own_addr, sm->bssid, sm->snonce, key->key_nonce,
1544 sm->tptk_set = 1;
1546 if (wpa_supplicant_send_2_of_4(sm, sm->bssid, key, ver, sm->snonce,
1547 sm->assoc_wpa_ie, sm->assoc_wpa_ie_len,
1551 os_memcpy(sm->anonce, key->key_nonce, WPA_NONCE_LEN);
1557 struct wpa_sm *sm = eloop_ctx;
1558 rsn_preauth_candidate_process(sm);
1562 static void wpa_supplicant_key_neg_complete(struct wpa_sm *sm,
1565 wpa_msg(sm->ctx->ctx, MSG_INFO, "WPA: Key negotiation completed with "
1567 wpa_cipher_txt(sm->pairwise_cipher),
1568 wpa_cipher_txt(sm->group_cipher));
1569 wpa_sm_cancel_auth_timeout(sm);
1570 wpa_sm_set_state(sm, WPA_COMPLETED);
1574 sm, addr, MLME_SETPROTECTION_PROTECT_TYPE_RX_TX,
1576 eapol_sm_notify_portValid(sm->eapol, TRUE);
1577 if (sm->key_mgmt == WPA_KEY_MGMT_PSK)
1578 eapol_sm_notify_eap_success(sm->eapol, TRUE);
1586 eloop_register_timeout(1, 0, wpa_sm_start_preauth, sm, NULL);
1589 if (sm->cur_pmksa && sm->cur_pmksa->opportunistic) {
1592 sm->cur_pmksa->opportunistic = 0;
1597 static int wpa_supplicant_install_ptk(struct wpa_sm *sm,
1607 switch (sm->pairwise_cipher) {
1624 sm->pairwise_cipher);
1628 if (sm->proto == WPA_PROTO_RSN) {
1635 if (wpa_sm_set_key(sm, alg, sm->bssid, 0, 1, key_rsc, rsclen,
1636 (u8 *) sm->ptk.tk1, keylen) < 0) {
1708 static int wpa_supplicant_install_gtk(struct wpa_sm *sm,
1719 if (sm->group_cipher == WPA_CIPHER_TKIP) {
1726 if (sm->pairwise_cipher == WPA_CIPHER_NONE) {
1727 if (wpa_sm_set_key(sm, gd->alg,
1735 } else if (wpa_sm_set_key(sm, gd->alg,
1748 static int wpa_supplicant_gtk_tx_bit_workaround(const struct wpa_sm *sm,
1751 if (tx && sm->pairwise_cipher != WPA_CIPHER_NONE) {
1765 static int wpa_supplicant_pairwise_gtk(struct wpa_sm *sm,
1789 gd.tx = wpa_supplicant_gtk_tx_bit_workaround(sm,
1797 if (wpa_supplicant_check_group_cipher(sm->group_cipher,
1800 wpa_supplicant_install_gtk(sm, &gd, key->key_rsc)) {
1805 wpa_supplicant_key_neg_complete(sm, sm->bssid,
1814 static int ieee80211w_set_keys(struct wpa_sm *sm,
1818 if (sm->mgmt_group_cipher != WPA_CIPHER_AES_128_CMAC)
1838 if (wpa_sm_set_key(sm, WPA_ALG_IGTK,
1854 if (wpa_sm_set_key(sm, WPA_ALG_DHV,
1870 static void wpa_report_ie_mismatch(struct wpa_sm *sm,
1875 wpa_msg(sm->ctx->ctx, MSG_WARNING, "WPA: %s (src=" MACSTR ")",
1878 if (sm->ap_wpa_ie) {
1880 sm->ap_wpa_ie, sm->ap_wpa_ie_len);
1883 if (!sm->ap_wpa_ie) {
1891 if (sm->ap_rsn_ie) {
1893 sm->ap_rsn_ie, sm->ap_rsn_ie_len);
1896 if (!sm->ap_rsn_ie) {
1904 wpa_sm_disassociate(sm, REASON_IE_IN_4WAY_DIFFERS);
1908 static int wpa_supplicant_validate_ie(struct wpa_sm *sm,
1912 struct wpa_ssid *ssid = sm->cur_ssid;
1914 if (sm->ap_wpa_ie == NULL && sm->ap_rsn_ie == NULL) {
1917 if (wpa_sm_get_beacon_ie(sm) < 0) {
1927 (sm->ap_wpa_ie || sm->ap_rsn_ie)) {
1928 wpa_report_ie_mismatch(sm, "IE in 3/4 msg does not match "
1935 if ((ie->wpa_ie && sm->ap_wpa_ie &&
1936 (ie->wpa_ie_len != sm->ap_wpa_ie_len ||
1937 os_memcmp(ie->wpa_ie, sm->ap_wpa_ie, ie->wpa_ie_len) != 0)) ||
1938 (ie->rsn_ie && sm->ap_rsn_ie &&
1939 (ie->rsn_ie_len != sm->ap_rsn_ie_len ||
1940 os_memcmp(ie->rsn_ie, sm->ap_rsn_ie, ie->rsn_ie_len) != 0))) {
1941 wpa_report_ie_mismatch(sm, "IE in 3/4 msg does not match "
1948 if (sm->proto == WPA_PROTO_WPA &&
1949 ie->rsn_ie && sm->ap_rsn_ie == NULL &&
1951 wpa_report_ie_mismatch(sm, "Possible downgrade attack "
1964 static int wpa_supplicant_send_4_of_4(struct wpa_sm *sm,
1978 rbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY, NULL,
1984 reply->type = sm->proto == WPA_PROTO_RSN ?
1989 if (sm->proto == WPA_PROTO_RSN)
2001 wpa_eapol_key_send(sm, ptk->kck, ver, dst, ETH_P_EAPOL,
2008 static void wpa_supplicant_process_3_of_4(struct wpa_sm *sm,
2016 wpa_sm_set_state(sm, WPA_4WAY_HANDSHAKE);
2018 MACSTR " (ver=%d)", MAC2STR(sm->bssid), ver);
2050 if (wpa_supplicant_validate_ie(sm, sm->bssid, &ie) < 0)
2053 if (os_memcmp(sm->anonce, key->key_nonce, WPA_NONCE_LEN) != 0) {
2056 " packet (src=" MACSTR ")", MAC2STR(sm->bssid));
2061 switch (sm->pairwise_cipher) {
2066 keylen, MAC2STR(sm->bssid));
2074 keylen, MAC2STR(sm->bssid));
2080 if (wpa_supplicant_send_4_of_4(sm, sm->bssid, key, ver, key_info,
2081 NULL, 0, &sm->ptk))
2087 sm->renew_snonce = 1;
2090 wpa_supplicant_install_ptk(sm, key);
2095 sm, sm->bssid, MLME_SETPROTECTION_PROTECT_TYPE_RX,
2097 eapol_sm_notify_portValid(sm->eapol, TRUE);
2099 wpa_sm_set_state(sm, WPA_GROUP_HANDSHAKE);
2102 wpa_supplicant_pairwise_gtk(sm, key,
2107 if (ieee80211w_set_keys(sm, &ie) < 0)
2116 struct wpa_sm *sm = eloop_ctx;
2123 static void wpa_supplicant_peerkey_free(struct wpa_sm *sm,
2126 eloop_cancel_timeout(wpa_supplicant_smk_timeout, sm, peerkey);
2131 static int wpa_supplicant_send_smk_error(struct wpa_sm *sm, const u8 *dst,
2147 rbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY,
2159 os_memcpy(err->replay_counter, sm->request_counter,
2161 inc_byte_array(sm->request_counter, WPA_REPLAY_COUNTER_LEN);
2186 wpa_eapol_key_send(sm, sm->ptk.kck, ver, dst, ETH_P_EAPOL,
2196 static int wpa_supplicant_send_smk_m3(struct wpa_sm *sm,
2212 rbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY,
2242 wpa_eapol_key_send(sm, sm->ptk.kck, ver, src_addr, ETH_P_EAPOL,
2250 struct wpa_sm *sm, const unsigned char *src_addr,
2253 struct wpa_ssid *ssid = sm->cur_ssid;
2263 if (ssid == NULL || !ssid->peerkey || sm->proto != WPA_PROTO_RSN) {
2305 wpa_supplicant_send_smk_error(sm, src_addr, kde.mac_addr,
2325 wpa_msg(sm->ctx->ctx, MSG_WARNING,
2327 wpa_supplicant_peerkey_free(sm, peerkey);
2353 wpa_supplicant_send_smk_m3(sm, src_addr, key, ver, peerkey);
2355 peerkey->next = sm->peerkey;
2356 sm->peerkey = peerkey;
2393 static void wpa_supplicant_send_stk_1_of_4(struct wpa_sm *sm,
2404 mbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY, NULL,
2434 wpa_msg(sm->ctx->ctx, MSG_WARNING,
2445 wpa_eapol_key_send(sm, NULL, ver, peerkey->addr, ETH_P_EAPOL,
2450 static void wpa_supplicant_send_stk_3_of_4(struct wpa_sm *sm,
2463 mbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY, NULL,
2500 wpa_eapol_key_send(sm, peerkey->stk.kck, ver, peerkey->addr,
2506 struct wpa_sm *sm, const unsigned char *src_addr,
2509 struct wpa_ssid *ssid = sm->cur_ssid;
2516 if (ssid == NULL || !ssid->peerkey || sm->proto != WPA_PROTO_RSN) {
2537 for (peerkey = sm->peerkey; peerkey; peerkey = peerkey->next) {
2593 sm, src_addr, kde.mac_addr,
2628 sm, peerkey);
2632 peerkey->inonce, sm->own_addr, peerkey->smkid);
2633 wpa_supplicant_send_stk_1_of_4(sm, peerkey);
2635 rsn_smkid(peerkey->smk, peerkey->pnonce, sm->own_addr,
2645 struct wpa_sm *sm, const unsigned char *src_addr,
2648 struct wpa_ssid *ssid = sm->cur_ssid;
2656 if (ssid == NULL || !ssid->peerkey || sm->proto != WPA_PROTO_RSN) {
2677 wpa_msg(sm->ctx->ctx, MSG_INFO,
2688 for (peerkey = sm->peerkey; peerkey; peerkey = peerkey->next) {
2705 static void wpa_supplicant_process_stk_1_of_4(struct wpa_sm *sm,
2737 wpa_msg(sm->ctx->ctx, MSG_WARNING,
2748 sm->own_addr, peerkey->addr,
2770 if (wpa_supplicant_send_2_of_4(sm, peerkey->addr, key, ver,
2782 static void wpa_supplicant_update_smk_lifetime(struct wpa_sm *sm,
2808 eloop_cancel_timeout(wpa_supplicant_smk_timeout, sm, peerkey);
2810 sm, peerkey);
2814 static void wpa_supplicant_process_stk_2_of_4(struct wpa_sm *sm,
2856 wpa_supplicant_update_smk_lifetime(sm, peerkey, &kde);
2858 wpa_supplicant_send_stk_3_of_4(sm, peerkey);
2863 static void wpa_supplicant_process_stk_3_of_4(struct wpa_sm *sm,
2911 wpa_supplicant_update_smk_lifetime(sm, peerkey, &kde);
2913 if (wpa_supplicant_send_4_of_4(sm, peerkey->addr, key, ver,
2930 if (wpa_sm_set_key(sm, peerkey->cipher, peerkey->addr, 0, 1,
2939 static void wpa_supplicant_process_stk_4_of_4(struct wpa_sm *sm,
2950 if (wpa_sm_set_key(sm, peerkey->cipher, peerkey->addr, 0, 1,
2961 static int wpa_supplicant_process_1_of_2_rsn(struct wpa_sm *sm,
2982 if (wpa_supplicant_check_group_cipher(sm->group_cipher,
2990 gd->tx = wpa_supplicant_gtk_tx_bit_workaround(sm,
2999 if (ieee80211w_set_keys(sm, &ie) < 0)
3006 static int wpa_supplicant_process_1_of_2_wpa(struct wpa_sm *sm,
3033 if (wpa_supplicant_check_group_cipher(sm->group_cipher,
3042 os_memcpy(ek + 16, sm->ptk.kek, 16);
3064 if (aes_unwrap(sm->ptk.kek, maxkeylen / 8,
3072 sm, !!(key_info & WPA_KEY_INFO_TXRX));
3077 static int wpa_supplicant_send_2_of_2(struct wpa_sm *sm,
3085 rbuf = wpa_sm_alloc_eapol(sm, IEEE802_1X_TYPE_EAPOL_KEY, NULL,
3090 reply->type = sm->proto == WPA_PROTO_RSN ?
3095 if (sm->proto == WPA_PROTO_RSN)
3105 wpa_eapol_key_send(sm, sm->ptk.kck, ver, sm->bssid, ETH_P_EAPOL,
3112 static void wpa_supplicant_process_1_of_2(struct wpa_sm *sm,
3123 rekey = wpa_sm_get_state(sm) == WPA_COMPLETED;
3130 if (sm->proto == WPA_PROTO_RSN) {
3131 ret = wpa_supplicant_process_1_of_2_rsn(sm,
3136 ret = wpa_supplicant_process_1_of_2_wpa(sm, key, keydatalen,
3141 wpa_sm_set_state(sm, WPA_GROUP_HANDSHAKE);
3146 if (wpa_supplicant_install_gtk(sm, &gd, key->key_rsc) ||
3147 wpa_supplicant_send_2_of_2(sm, key, ver, key_info))
3151 wpa_msg(sm->ctx->ctx, MSG_INFO, "WPA: Group rekeying "
3153 MAC2STR(sm->bssid), wpa_cipher_txt(sm->group_cipher));
3154 wpa_sm_set_state(sm, WPA_COMPLETED);
3156 wpa_supplicant_key_neg_complete(sm, sm->bssid,
3163 static int wpa_supplicant_verify_eapol_key_mic(struct wpa_sm *sm,
3172 if (sm->tptk_set) {
3174 wpa_eapol_key_mic(sm->tptk.kck, ver, buf, len,
3181 sm->tptk_set = 0;
3182 sm->ptk_set = 1;
3183 os_memcpy(&sm->ptk, &sm->tptk, sizeof(sm->ptk));
3187 if (!ok && sm->ptk_set) {
3189 wpa_eapol_key_mic(sm->ptk.kck, ver, buf, len,
3205 os_memcpy(sm->rx_replay_counter, key->replay_counter,
3207 sm->rx_replay_counter_set = 1;
3214 struct wpa_sm *sm, struct wpa_peerkey *peerkey,
3222 sm->own_addr, peerkey->addr,
3272 static int wpa_supplicant_decrypt_key_data(struct wpa_sm *sm,
3279 if (!sm->ptk_set) {
3290 os_memcpy(ek + 16, sm->ptk.kek, 16);
3306 if (aes_unwrap(sm->ptk.kek, keydatalen / 8,
3325 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3327 void wpa_sm_aborted_cached(struct wpa_sm *sm)
3329 if (sm && sm->cur_pmksa) {
3331 sm->cur_pmksa = NULL;
3372 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3386 int wpa_sm_rx_eapol(struct wpa_sm *sm, const u8 *src_addr,
3443 eapol_sm_notify_lower_layer_success(sm->eapol);
3458 if (sm->pairwise_cipher == WPA_CIPHER_CCMP &&
3462 if (sm->group_cipher != WPA_CIPHER_CCMP &&
3476 for (peerkey = sm->peerkey; peerkey; peerkey = peerkey->next) {
3510 if (!peerkey && sm->rx_replay_counter_set &&
3511 os_memcmp(key->replay_counter, sm->rx_replay_counter,
3534 wpa_supplicant_verify_eapol_key_mic(sm, key, ver, tmp, data_len))
3540 sm, peerkey, key, ver, tmp, data_len))
3547 wpa_msg(sm->ctx->ctx, MSG_INFO, "WPA: Invalid EAPOL-Key "
3555 if (sm->proto == WPA_PROTO_RSN &&
3557 if (wpa_supplicant_decrypt_key_data(sm, key, ver))
3573 wpa_supplicant_process_stk_3_of_4(sm, peerkey,
3577 wpa_supplicant_process_stk_1_of_4(sm, peerkey,
3581 wpa_supplicant_process_stk_4_of_4(sm, peerkey,
3585 wpa_supplicant_process_stk_2_of_4(sm, peerkey,
3592 wpa_supplicant_process_3_of_4(sm, key, ver);
3595 wpa_supplicant_process_1_of_4(sm, src_addr, key,
3602 wpa_supplicant_process_smk_error(sm, src_addr, key,
3606 wpa_supplicant_process_smk_m2(sm, src_addr, key,
3610 wpa_supplicant_process_smk_m45(sm, src_addr, key,
3617 wpa_supplicant_process_1_of_2(sm, src_addr, key,
3651 static const u8 * wpa_key_mgmt_suite(struct wpa_sm *sm)
3654 switch (sm->key_mgmt) {
3656 return (sm->proto == WPA_PROTO_RSN ?
3660 return (sm->proto == WPA_PROTO_RSN ?
3671 static const u8 * wpa_cipher_suite(struct wpa_sm *sm, int cipher)
3676 return (sm->proto == WPA_PROTO_RSN ?
3679 return (sm->proto == WPA_PROTO_RSN ?
3682 return (sm->proto == WPA_PROTO_RSN ?
3685 return (sm->proto == WPA_PROTO_RSN ?
3688 return (sm->proto == WPA_PROTO_RSN ?
3701 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3708 int wpa_sm_get_mib(struct wpa_sm *sm, char *buf, size_t buflen)
3714 if (sm->cur_pmksa) {
3716 sm->cur_pmksa->pmkid, PMKID_LEN);
3720 if ((sm->key_mgmt == WPA_KEY_MGMT_PSK ||
3721 sm->key_mgmt == WPA_KEY_MGMT_IEEE8021X) &&
3722 sm->proto == WPA_PROTO_RSN)
3742 wpa_cipher_bits(sm->group_cipher),
3743 sm->dot11RSNAConfigPMKLifetime,
3744 sm->dot11RSNAConfigPMKReauthThreshold,
3745 sm->dot11RSNAConfigSATimeout);
3761 RSN_SUITE_ARG(wpa_key_mgmt_suite(sm)),
3762 RSN_SUITE_ARG(wpa_cipher_suite(sm, sm->pairwise_cipher)),
3763 RSN_SUITE_ARG(wpa_cipher_suite(sm, sm->group_cipher)),
3765 RSN_SUITE_ARG(wpa_key_mgmt_suite(sm)),
3766 RSN_SUITE_ARG(wpa_cipher_suite(sm, sm->pairwise_cipher)),
3767 RSN_SUITE_ARG(wpa_cipher_suite(sm, sm->group_cipher)),
3768 sm->dot11RSNA4WayHandshakeFailures);
3780 struct wpa_sm *sm = ctx;
3782 if (sm->cur_pmksa == entry ||
3783 (sm->pmk_len == entry->pmk_len &&
3784 os_memcmp(sm->pmk, entry->pmk, sm->pmk_len) == 0)) {
3786 sm->cur_pmksa = NULL;
3796 os_memset(sm->pmk, 0, sizeof(sm->pmk));
3797 wpa_sm_deauthenticate(sm, REASON_UNSPECIFIED);
3812 struct wpa_sm *sm;
3814 sm = os_zalloc(sizeof(*sm));
3815 if (sm == NULL)
3817 sm->renew_snonce = 1;
3818 sm->ctx = ctx;
3820 sm->dot11RSNAConfigPMKLifetime = 43200;
3821 sm->dot11RSNAConfigPMKReauthThreshold = 70;
3822 sm->dot11RSNAConfigSATimeout = 60;
3824 sm->pmksa = pmksa_cache_init(wpa_sm_pmksa_free_cb, sm, sm);
3825 if (sm->pmksa == NULL) {
3828 os_free(sm);
3832 return sm;
3838 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3840 void wpa_sm_deinit(struct wpa_sm *sm)
3842 if (sm == NULL)
3844 pmksa_cache_deinit(sm->pmksa);
3845 eloop_cancel_timeout(wpa_sm_start_preauth, sm, NULL);
3846 os_free(sm->assoc_wpa_ie);
3847 os_free(sm->ap_wpa_ie);
3848 os_free(sm->ap_rsn_ie);
3849 os_free(sm->ctx);
3852 struct wpa_peerkey *prev, *peerkey = sm->peerkey;
3860 os_free(sm);
3866 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3872 void wpa_sm_notify_assoc(struct wpa_sm *sm, const u8 *bssid)
3874 if (sm == NULL)
3878 os_memcpy(sm->bssid, bssid, ETH_ALEN);
3879 os_memset(sm->rx_replay_counter, 0, WPA_REPLAY_COUNTER_LEN);
3880 sm->rx_replay_counter_set = 0;
3881 sm->renew_snonce = 1;
3882 if (os_memcmp(sm->preauth_bssid, bssid, ETH_ALEN) == 0)
3883 rsn_preauth_deinit(sm);
3889 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3894 void wpa_sm_notify_disassoc(struct wpa_sm *sm)
3896 rsn_preauth_deinit(sm);
3897 if (wpa_sm_get_state(sm) == WPA_4WAY_HANDSHAKE)
3898 sm->dot11RSNA4WayHandshakeFailures++;
3904 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3910 void wpa_sm_set_pmk(struct wpa_sm *sm, const u8 *pmk, size_t pmk_len)
3912 if (sm == NULL)
3915 sm->pmk_len = pmk_len;
3916 os_memcpy(sm->pmk, pmk, pmk_len);
3922 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3927 void wpa_sm_set_pmk_from_pmksa(struct wpa_sm *sm)
3929 if (sm == NULL)
3932 if (sm->cur_pmksa) {
3933 sm->pmk_len = sm->cur_pmksa->pmk_len;
3934 os_memcpy(sm->pmk, sm->cur_pmksa->pmk, sm->pmk_len);
3936 sm->pmk_len = PMK_LEN;
3937 os_memset(sm->pmk, 0, PMK_LEN);
3944 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3947 void wpa_sm_set_fast_reauth(struct wpa_sm *sm, int fast_reauth)
3949 if (sm)
3950 sm->fast_reauth = fast_reauth;
3956 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3959 void wpa_sm_set_scard_ctx(struct wpa_sm *sm, void *scard_ctx)
3961 if (sm == NULL)
3963 sm->scard_ctx = scard_ctx;
3964 if (sm->preauth_eapol)
3965 eapol_sm_register_scard_ctx(sm->preauth_eapol, scard_ctx);
3971 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3978 void wpa_sm_set_config(struct wpa_sm *sm, struct wpa_ssid *config)
3980 if (sm) {
3981 sm->cur_ssid = config;
3982 pmksa_cache_notify_reconfig(sm->pmksa);
3989 * @sm: Pointer to WPA state machine data from wpa_sm_init()
3992 void wpa_sm_set_own_addr(struct wpa_sm *sm, const u8 *addr)
3994 if (sm)
3995 os_memcpy(sm->own_addr, addr, ETH_ALEN);
4001 * @sm: Pointer to WPA state machine data from wpa_sm_init()
4005 void wpa_sm_set_ifname(struct wpa_sm *sm, const char *ifname,
4008 if (sm) {
4009 sm->ifname = ifname;
4010 sm->bridge_ifname = bridge_ifname;
4017 * @sm: Pointer to WPA state machine data from wpa_sm_init()
4020 void wpa_sm_set_eapol(struct wpa_sm *sm, struct eapol_sm *eapol)
4022 if (sm)
4023 sm->eapol = eapol;
4029 * @sm: Pointer to WPA state machine data from wpa_sm_init()
4034 int wpa_sm_set_param(struct wpa_sm *sm, enum wpa_sm_conf_params param,
4039 if (sm == NULL)
4045 sm->dot11RSNAConfigPMKLifetime = value;
4051 sm->dot11RSNAConfigPMKReauthThreshold = value;
4057 sm->dot11RSNAConfigSATimeout = value;
4062 sm->proto = value;
4065 sm->pairwise_cipher = value;
4068 sm->group_cipher = value;
4071 sm->key_mgmt = value;
4075 sm->mgmt_group_cipher = value;
4088 * @sm: Pointer to WPA state machine data from wpa_sm_init()
4092 unsigned int wpa_sm_get_param(struct wpa_sm *sm, enum wpa_sm_conf_params param)
4094 if (sm == NULL)
4099 return sm->dot11RSNAConfigPMKLifetime;
4101 return sm->dot11RSNAConfigPMKReauthThreshold;
4103 return sm->dot11RSNAConfigSATimeout;
4105 return sm->proto;
4107 return sm->pairwise_cipher;
4109 return sm->group_cipher;
4111 return sm->key_mgmt;
4114 return sm->mgmt_group_cipher;
4124 * @sm: Pointer to WPA state machine data from wpa_sm_init()
4134 int wpa_sm_get_status(struct wpa_sm *sm, char *buf, size_t buflen,
4144 wpa_cipher_txt(sm->pairwise_cipher),
4145 wpa_cipher_txt(sm->group_cipher),
4146 wpa_key_mgmt_txt(sm->key_mgmt, sm->proto));
4156 * @sm: Pointer to WPA state machine data from wpa_sm_init()
4161 int wpa_sm_set_assoc_wpa_ie_default(struct wpa_sm *sm, u8 *wpa_ie,
4166 if (sm == NULL)
4169 res = wpa_gen_wpa_ie(sm, wpa_ie, *wpa_ie_len);
4177 if (sm->assoc_wpa_ie == NULL) {
4183 sm->assoc_wpa_ie = os_malloc(*wpa_ie_len);
4184 if (sm->assoc_wpa_ie == NULL)
4187 os_memcpy(sm->assoc_wpa_ie, wpa_ie, *wpa_ie_len);
4188 sm->assoc_wpa_ie_len = *wpa_ie_len;
4197 * @sm: Pointer to WPA state machine data from wpa_sm_init()
4206 int wpa_sm_set_assoc_wpa_ie(struct wpa_sm *sm, const u8 *ie, size_t len)
4208 if (sm == NULL)
4211 os_free(sm->assoc_wpa_ie);
4214 sm->assoc_wpa_ie = NULL;
4215 sm->assoc_wpa_ie_len = 0;
4218 sm->assoc_wpa_ie = os_malloc(len);
4219 if (sm->assoc_wpa_ie == NULL)
4222 os_memcpy(sm->assoc_wpa_ie, ie, len);
4223 sm->assoc_wpa_ie_len = len;
4232 * @sm: Pointer to WPA state machine data from wpa_sm_init()
4240 int wpa_sm_set_ap_wpa_ie(struct wpa_sm *sm, const u8 *ie, size_t len)
4242 if (sm == NULL)
4245 os_free(sm->ap_wpa_ie);
4248 sm->ap_wpa_ie = NULL;
4249 sm->ap_wpa_ie_len = 0;
4252 sm->ap_wpa_ie = os_malloc(len);
4253 if (sm->ap_wpa_ie == NULL)
4256 os_memcpy(sm->ap_wpa_ie, ie, len);
4257 sm->ap_wpa_ie_len = len;
4266 * @sm: Pointer to WPA state machine data from wpa_sm_init()
4274 int wpa_sm_set_ap_rsn_ie(struct wpa_sm *sm, const u8 *ie, size_t len)
4276 if (sm == NULL)
4279 os_free(sm->ap_rsn_ie);
4282 sm->ap_rsn_ie = NULL;
4283 sm->ap_rsn_ie_len = 0;
4286 sm->ap_rsn_ie = os_malloc(len);
4287 if (sm->ap_rsn_ie == NULL)
4290 os_memcpy(sm->ap_rsn_ie, ie, len);
4291 sm->ap_rsn_ie_len = len;
4300 * @sm: Pointer to WPA state machine data from wpa_sm_init()
4307 int wpa_sm_parse_own_wpa_ie(struct wpa_sm *sm, struct wpa_ie_data *data)
4309 if (sm == NULL || sm->assoc_wpa_ie == NULL) {
4314 if (wpa_parse_wpa_ie(sm->assoc_wpa_ie, sm->assoc_wpa_ie_len, data))