2 * IEEE 802.11 RSN / WPA Authenticator
3 * Copyright (c) 2004-2015, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "utils/state_machine.h"
14 #include "utils/bitfield.h"
15 #include "common/ieee802_11_defs.h"
16 #include "crypto/aes_wrap.h"
17 #include "crypto/crypto.h"
18 #include "crypto/sha1.h"
19 #include "crypto/sha256.h"
20 #include "crypto/random.h"
21 #include "eapol_auth/eapol_auth_sm.h"
22 #include "ap_config.h"
23 #include "ieee802_11.h"
25 #include "pmksa_cache_auth.h"
26 #include "wpa_auth_i.h"
27 #include "wpa_auth_ie.h"
29 #define STATE_MACHINE_DATA struct wpa_state_machine
30 #define STATE_MACHINE_DEBUG_PREFIX "WPA"
31 #define STATE_MACHINE_ADDR sm->addr
34 static void wpa_send_eapol_timeout(void *eloop_ctx, void *timeout_ctx);
35 static int wpa_sm_step(struct wpa_state_machine *sm);
36 static int wpa_verify_key_mic(int akmp, struct wpa_ptk *PTK, u8 *data,
38 static void wpa_sm_call_step(void *eloop_ctx, void *timeout_ctx);
39 static void wpa_group_sm_step(struct wpa_authenticator *wpa_auth,
40 struct wpa_group *group);
41 static void wpa_request_new_ptk(struct wpa_state_machine *sm);
42 static int wpa_gtk_update(struct wpa_authenticator *wpa_auth,
43 struct wpa_group *group);
44 static int wpa_group_config_group_keys(struct wpa_authenticator *wpa_auth,
45 struct wpa_group *group);
46 static int wpa_derive_ptk(struct wpa_state_machine *sm, const u8 *snonce,
47 const u8 *pmk, struct wpa_ptk *ptk);
49 static const u32 dot11RSNAConfigGroupUpdateCount = 4;
50 static const u32 dot11RSNAConfigPairwiseUpdateCount = 4;
51 static const u32 eapol_key_timeout_first = 100; /* ms */
52 static const u32 eapol_key_timeout_subseq = 1000; /* ms */
53 static const u32 eapol_key_timeout_first_group = 500; /* ms */
55 /* TODO: make these configurable */
56 static const int dot11RSNAConfigPMKLifetime = 43200;
57 static const int dot11RSNAConfigPMKReauthThreshold = 70;
58 static const int dot11RSNAConfigSATimeout = 60;
61 static inline int wpa_auth_mic_failure_report(
62 struct wpa_authenticator *wpa_auth, const u8 *addr)
64 if (wpa_auth->cb.mic_failure_report)
65 return wpa_auth->cb.mic_failure_report(wpa_auth->cb.ctx, addr);
70 static inline void wpa_auth_set_eapol(struct wpa_authenticator *wpa_auth,
71 const u8 *addr, wpa_eapol_variable var,
74 if (wpa_auth->cb.set_eapol)
75 wpa_auth->cb.set_eapol(wpa_auth->cb.ctx, addr, var, value);
79 static inline int wpa_auth_get_eapol(struct wpa_authenticator *wpa_auth,
80 const u8 *addr, wpa_eapol_variable var)
82 if (wpa_auth->cb.get_eapol == NULL)
84 return wpa_auth->cb.get_eapol(wpa_auth->cb.ctx, addr, var);
88 static inline const u8 * wpa_auth_get_psk(struct wpa_authenticator *wpa_auth,
90 const u8 *p2p_dev_addr,
93 if (wpa_auth->cb.get_psk == NULL)
95 return wpa_auth->cb.get_psk(wpa_auth->cb.ctx, addr, p2p_dev_addr,
100 static inline int wpa_auth_get_msk(struct wpa_authenticator *wpa_auth,
101 const u8 *addr, u8 *msk, size_t *len)
103 if (wpa_auth->cb.get_msk == NULL)
105 return wpa_auth->cb.get_msk(wpa_auth->cb.ctx, addr, msk, len);
109 static inline int wpa_auth_set_key(struct wpa_authenticator *wpa_auth,
111 enum wpa_alg alg, const u8 *addr, int idx,
112 u8 *key, size_t key_len)
114 if (wpa_auth->cb.set_key == NULL)
116 return wpa_auth->cb.set_key(wpa_auth->cb.ctx, vlan_id, alg, addr, idx,
121 static inline int wpa_auth_get_seqnum(struct wpa_authenticator *wpa_auth,
122 const u8 *addr, int idx, u8 *seq)
124 if (wpa_auth->cb.get_seqnum == NULL)
126 return wpa_auth->cb.get_seqnum(wpa_auth->cb.ctx, addr, idx, seq);
131 wpa_auth_send_eapol(struct wpa_authenticator *wpa_auth, const u8 *addr,
132 const u8 *data, size_t data_len, int encrypt)
134 if (wpa_auth->cb.send_eapol == NULL)
136 return wpa_auth->cb.send_eapol(wpa_auth->cb.ctx, addr, data, data_len,
142 static inline int wpa_auth_start_ampe(struct wpa_authenticator *wpa_auth,
145 if (wpa_auth->cb.start_ampe == NULL)
147 return wpa_auth->cb.start_ampe(wpa_auth->cb.ctx, addr);
149 #endif /* CONFIG_MESH */
152 int wpa_auth_for_each_sta(struct wpa_authenticator *wpa_auth,
153 int (*cb)(struct wpa_state_machine *sm, void *ctx),
156 if (wpa_auth->cb.for_each_sta == NULL)
158 return wpa_auth->cb.for_each_sta(wpa_auth->cb.ctx, cb, cb_ctx);
162 int wpa_auth_for_each_auth(struct wpa_authenticator *wpa_auth,
163 int (*cb)(struct wpa_authenticator *a, void *ctx),
166 if (wpa_auth->cb.for_each_auth == NULL)
168 return wpa_auth->cb.for_each_auth(wpa_auth->cb.ctx, cb, cb_ctx);
172 void wpa_auth_logger(struct wpa_authenticator *wpa_auth, const u8 *addr,
173 logger_level level, const char *txt)
175 if (wpa_auth->cb.logger == NULL)
177 wpa_auth->cb.logger(wpa_auth->cb.ctx, addr, level, txt);
181 void wpa_auth_vlogger(struct wpa_authenticator *wpa_auth, const u8 *addr,
182 logger_level level, const char *fmt, ...)
188 if (wpa_auth->cb.logger == NULL)
191 maxlen = os_strlen(fmt) + 100;
192 format = os_malloc(maxlen);
197 vsnprintf(format, maxlen, fmt, ap);
200 wpa_auth_logger(wpa_auth, addr, level, format);
206 static void wpa_sta_disconnect(struct wpa_authenticator *wpa_auth,
209 if (wpa_auth->cb.disconnect == NULL)
211 wpa_printf(MSG_DEBUG, "wpa_sta_disconnect STA " MACSTR, MAC2STR(addr));
212 wpa_auth->cb.disconnect(wpa_auth->cb.ctx, addr,
213 WLAN_REASON_PREV_AUTH_NOT_VALID);
217 static int wpa_use_aes_cmac(struct wpa_state_machine *sm)
220 #ifdef CONFIG_IEEE80211R
221 if (wpa_key_mgmt_ft(sm->wpa_key_mgmt))
223 #endif /* CONFIG_IEEE80211R */
224 #ifdef CONFIG_IEEE80211W
225 if (wpa_key_mgmt_sha256(sm->wpa_key_mgmt))
227 #endif /* CONFIG_IEEE80211W */
228 if (sm->wpa_key_mgmt == WPA_KEY_MGMT_OSEN)
234 static void wpa_rekey_gmk(void *eloop_ctx, void *timeout_ctx)
236 struct wpa_authenticator *wpa_auth = eloop_ctx;
238 if (random_get_bytes(wpa_auth->group->GMK, WPA_GMK_LEN)) {
239 wpa_printf(MSG_ERROR, "Failed to get random data for WPA "
242 wpa_auth_logger(wpa_auth, NULL, LOGGER_DEBUG, "GMK rekeyd");
243 wpa_hexdump_key(MSG_DEBUG, "GMK",
244 wpa_auth->group->GMK, WPA_GMK_LEN);
247 if (wpa_auth->conf.wpa_gmk_rekey) {
248 eloop_register_timeout(wpa_auth->conf.wpa_gmk_rekey, 0,
249 wpa_rekey_gmk, wpa_auth, NULL);
254 static void wpa_rekey_gtk(void *eloop_ctx, void *timeout_ctx)
256 struct wpa_authenticator *wpa_auth = eloop_ctx;
257 struct wpa_group *group;
259 wpa_auth_logger(wpa_auth, NULL, LOGGER_DEBUG, "rekeying GTK");
260 for (group = wpa_auth->group; group; group = group->next) {
261 group->GTKReKey = TRUE;
263 group->changed = FALSE;
264 wpa_group_sm_step(wpa_auth, group);
265 } while (group->changed);
268 if (wpa_auth->conf.wpa_group_rekey) {
269 eloop_register_timeout(wpa_auth->conf.wpa_group_rekey,
270 0, wpa_rekey_gtk, wpa_auth, NULL);
275 static void wpa_rekey_ptk(void *eloop_ctx, void *timeout_ctx)
277 struct wpa_authenticator *wpa_auth = eloop_ctx;
278 struct wpa_state_machine *sm = timeout_ctx;
280 wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG, "rekeying PTK");
281 wpa_request_new_ptk(sm);
286 static int wpa_auth_pmksa_clear_cb(struct wpa_state_machine *sm, void *ctx)
288 if (sm->pmksa == ctx)
294 static void wpa_auth_pmksa_free_cb(struct rsn_pmksa_cache_entry *entry,
297 struct wpa_authenticator *wpa_auth = ctx;
298 wpa_auth_for_each_sta(wpa_auth, wpa_auth_pmksa_clear_cb, entry);
302 static int wpa_group_init_gmk_and_counter(struct wpa_authenticator *wpa_auth,
303 struct wpa_group *group)
305 u8 buf[ETH_ALEN + 8 + sizeof(unsigned long)];
309 if (random_get_bytes(group->GMK, WPA_GMK_LEN) < 0)
311 wpa_hexdump_key(MSG_DEBUG, "GMK", group->GMK, WPA_GMK_LEN);
314 * Counter = PRF-256(Random number, "Init Counter",
315 * Local MAC Address || Time)
317 os_memcpy(buf, wpa_auth->addr, ETH_ALEN);
318 wpa_get_ntp_timestamp(buf + ETH_ALEN);
319 ptr = (unsigned long) group;
320 os_memcpy(buf + ETH_ALEN + 8, &ptr, sizeof(ptr));
321 if (random_get_bytes(rkey, sizeof(rkey)) < 0)
324 if (sha1_prf(rkey, sizeof(rkey), "Init Counter", buf, sizeof(buf),
325 group->Counter, WPA_NONCE_LEN) < 0)
327 wpa_hexdump_key(MSG_DEBUG, "Key Counter",
328 group->Counter, WPA_NONCE_LEN);
334 static struct wpa_group * wpa_group_init(struct wpa_authenticator *wpa_auth,
335 int vlan_id, int delay_init)
337 struct wpa_group *group;
339 group = os_zalloc(sizeof(struct wpa_group));
343 group->GTKAuthenticator = TRUE;
344 group->vlan_id = vlan_id;
345 group->GTK_len = wpa_cipher_key_len(wpa_auth->conf.wpa_group);
347 if (random_pool_ready() != 1) {
348 wpa_printf(MSG_INFO, "WPA: Not enough entropy in random pool "
349 "for secure operations - update keys later when "
350 "the first station connects");
354 * Set initial GMK/Counter value here. The actual values that will be
355 * used in negotiations will be set once the first station tries to
356 * connect. This allows more time for collecting additional randomness
357 * on embedded devices.
359 if (wpa_group_init_gmk_and_counter(wpa_auth, group) < 0) {
360 wpa_printf(MSG_ERROR, "Failed to get random data for WPA "
368 wpa_printf(MSG_DEBUG, "WPA: Delay group state machine start "
369 "until Beacon frames have been configured");
370 /* Initialization is completed in wpa_init_keys(). */
372 wpa_group_sm_step(wpa_auth, group);
373 group->GInit = FALSE;
374 wpa_group_sm_step(wpa_auth, group);
382 * wpa_init - Initialize WPA authenticator
383 * @addr: Authenticator address
384 * @conf: Configuration for WPA authenticator
385 * @cb: Callback functions for WPA authenticator
386 * Returns: Pointer to WPA authenticator data or %NULL on failure
388 struct wpa_authenticator * wpa_init(const u8 *addr,
389 struct wpa_auth_config *conf,
390 struct wpa_auth_callbacks *cb)
392 struct wpa_authenticator *wpa_auth;
394 wpa_auth = os_zalloc(sizeof(struct wpa_authenticator));
395 if (wpa_auth == NULL)
397 os_memcpy(wpa_auth->addr, addr, ETH_ALEN);
398 os_memcpy(&wpa_auth->conf, conf, sizeof(*conf));
399 os_memcpy(&wpa_auth->cb, cb, sizeof(*cb));
401 if (wpa_auth_gen_wpa_ie(wpa_auth)) {
402 wpa_printf(MSG_ERROR, "Could not generate WPA IE.");
407 wpa_auth->group = wpa_group_init(wpa_auth, 0, 1);
408 if (wpa_auth->group == NULL) {
409 os_free(wpa_auth->wpa_ie);
414 wpa_auth->pmksa = pmksa_cache_auth_init(wpa_auth_pmksa_free_cb,
416 if (wpa_auth->pmksa == NULL) {
417 wpa_printf(MSG_ERROR, "PMKSA cache initialization failed.");
418 os_free(wpa_auth->group);
419 os_free(wpa_auth->wpa_ie);
424 #ifdef CONFIG_IEEE80211R
425 wpa_auth->ft_pmk_cache = wpa_ft_pmk_cache_init();
426 if (wpa_auth->ft_pmk_cache == NULL) {
427 wpa_printf(MSG_ERROR, "FT PMK cache initialization failed.");
428 os_free(wpa_auth->group);
429 os_free(wpa_auth->wpa_ie);
430 pmksa_cache_auth_deinit(wpa_auth->pmksa);
434 #endif /* CONFIG_IEEE80211R */
436 if (wpa_auth->conf.wpa_gmk_rekey) {
437 eloop_register_timeout(wpa_auth->conf.wpa_gmk_rekey, 0,
438 wpa_rekey_gmk, wpa_auth, NULL);
441 if (wpa_auth->conf.wpa_group_rekey) {
442 eloop_register_timeout(wpa_auth->conf.wpa_group_rekey, 0,
443 wpa_rekey_gtk, wpa_auth, NULL);
447 if (WPA_GET_BE32(conf->ip_addr_start)) {
448 int count = WPA_GET_BE32(conf->ip_addr_end) -
449 WPA_GET_BE32(conf->ip_addr_start) + 1;
453 wpa_auth->ip_pool = bitfield_alloc(count);
455 #endif /* CONFIG_P2P */
461 int wpa_init_keys(struct wpa_authenticator *wpa_auth)
463 struct wpa_group *group = wpa_auth->group;
465 wpa_printf(MSG_DEBUG, "WPA: Start group state machine to set initial "
467 wpa_group_sm_step(wpa_auth, group);
468 group->GInit = FALSE;
469 wpa_group_sm_step(wpa_auth, group);
470 if (group->wpa_group_state == WPA_GROUP_FATAL_FAILURE)
477 * wpa_deinit - Deinitialize WPA authenticator
478 * @wpa_auth: Pointer to WPA authenticator data from wpa_init()
480 void wpa_deinit(struct wpa_authenticator *wpa_auth)
482 struct wpa_group *group, *prev;
484 eloop_cancel_timeout(wpa_rekey_gmk, wpa_auth, NULL);
485 eloop_cancel_timeout(wpa_rekey_gtk, wpa_auth, NULL);
487 #ifdef CONFIG_PEERKEY
488 while (wpa_auth->stsl_negotiations)
489 wpa_stsl_remove(wpa_auth, wpa_auth->stsl_negotiations);
490 #endif /* CONFIG_PEERKEY */
492 pmksa_cache_auth_deinit(wpa_auth->pmksa);
494 #ifdef CONFIG_IEEE80211R
495 wpa_ft_pmk_cache_deinit(wpa_auth->ft_pmk_cache);
496 wpa_auth->ft_pmk_cache = NULL;
497 #endif /* CONFIG_IEEE80211R */
500 bitfield_free(wpa_auth->ip_pool);
501 #endif /* CONFIG_P2P */
504 os_free(wpa_auth->wpa_ie);
506 group = wpa_auth->group;
518 * wpa_reconfig - Update WPA authenticator configuration
519 * @wpa_auth: Pointer to WPA authenticator data from wpa_init()
520 * @conf: Configuration for WPA authenticator
522 int wpa_reconfig(struct wpa_authenticator *wpa_auth,
523 struct wpa_auth_config *conf)
525 struct wpa_group *group;
526 if (wpa_auth == NULL)
529 os_memcpy(&wpa_auth->conf, conf, sizeof(*conf));
530 if (wpa_auth_gen_wpa_ie(wpa_auth)) {
531 wpa_printf(MSG_ERROR, "Could not generate WPA IE.");
536 * Reinitialize GTK to make sure it is suitable for the new
539 group = wpa_auth->group;
540 group->GTK_len = wpa_cipher_key_len(wpa_auth->conf.wpa_group);
542 wpa_group_sm_step(wpa_auth, group);
543 group->GInit = FALSE;
544 wpa_group_sm_step(wpa_auth, group);
550 struct wpa_state_machine *
551 wpa_auth_sta_init(struct wpa_authenticator *wpa_auth, const u8 *addr,
552 const u8 *p2p_dev_addr)
554 struct wpa_state_machine *sm;
556 if (wpa_auth->group->wpa_group_state == WPA_GROUP_FATAL_FAILURE)
559 sm = os_zalloc(sizeof(struct wpa_state_machine));
562 os_memcpy(sm->addr, addr, ETH_ALEN);
564 os_memcpy(sm->p2p_dev_addr, p2p_dev_addr, ETH_ALEN);
566 sm->wpa_auth = wpa_auth;
567 sm->group = wpa_auth->group;
573 int wpa_auth_sta_associated(struct wpa_authenticator *wpa_auth,
574 struct wpa_state_machine *sm)
576 if (wpa_auth == NULL || !wpa_auth->conf.wpa || sm == NULL)
579 #ifdef CONFIG_IEEE80211R
580 if (sm->ft_completed) {
581 wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG,
582 "FT authentication already completed - do not "
583 "start 4-way handshake");
584 /* Go to PTKINITDONE state to allow GTK rekeying */
585 sm->wpa_ptk_state = WPA_PTK_PTKINITDONE;
588 #endif /* CONFIG_IEEE80211R */
591 os_memset(&sm->key_replay, 0, sizeof(sm->key_replay));
592 sm->ReAuthenticationRequest = TRUE;
593 return wpa_sm_step(sm);
596 wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG,
597 "start authentication");
601 if (wpa_sm_step(sm) == 1)
602 return 1; /* should not really happen */
604 sm->AuthenticationRequest = TRUE;
605 return wpa_sm_step(sm);
609 void wpa_auth_sta_no_wpa(struct wpa_state_machine *sm)
611 /* WPA/RSN was not used - clear WPA state. This is needed if the STA
612 * reassociates back to the same AP while the previous entry for the
613 * STA has not yet been removed. */
617 sm->wpa_key_mgmt = 0;
621 static void wpa_free_sta_sm(struct wpa_state_machine *sm)
624 if (WPA_GET_BE32(sm->ip_addr)) {
626 wpa_printf(MSG_DEBUG, "P2P: Free assigned IP "
627 "address %u.%u.%u.%u from " MACSTR,
628 sm->ip_addr[0], sm->ip_addr[1],
629 sm->ip_addr[2], sm->ip_addr[3],
631 start = WPA_GET_BE32(sm->wpa_auth->conf.ip_addr_start);
632 bitfield_clear(sm->wpa_auth->ip_pool,
633 WPA_GET_BE32(sm->ip_addr) - start);
635 #endif /* CONFIG_P2P */
636 if (sm->GUpdateStationKeys) {
637 sm->group->GKeyDoneStations--;
638 sm->GUpdateStationKeys = FALSE;
640 #ifdef CONFIG_IEEE80211R
641 os_free(sm->assoc_resp_ftie);
642 wpabuf_free(sm->ft_pending_req_ies);
643 #endif /* CONFIG_IEEE80211R */
644 os_free(sm->last_rx_eapol_key);
650 void wpa_auth_sta_deinit(struct wpa_state_machine *sm)
655 if (sm->wpa_auth->conf.wpa_strict_rekey && sm->has_GTK) {
656 wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
657 "strict rekeying - force GTK rekey since STA "
659 eloop_cancel_timeout(wpa_rekey_gtk, sm->wpa_auth, NULL);
660 eloop_register_timeout(0, 500000, wpa_rekey_gtk, sm->wpa_auth,
664 eloop_cancel_timeout(wpa_send_eapol_timeout, sm->wpa_auth, sm);
665 sm->pending_1_of_4_timeout = 0;
666 eloop_cancel_timeout(wpa_sm_call_step, sm, NULL);
667 eloop_cancel_timeout(wpa_rekey_ptk, sm->wpa_auth, sm);
668 if (sm->in_step_loop) {
669 /* Must not free state machine while wpa_sm_step() is running.
670 * Freeing will be completed in the end of wpa_sm_step(). */
671 wpa_printf(MSG_DEBUG, "WPA: Registering pending STA state "
672 "machine deinit for " MACSTR, MAC2STR(sm->addr));
673 sm->pending_deinit = 1;
679 static void wpa_request_new_ptk(struct wpa_state_machine *sm)
684 sm->PTKRequest = TRUE;
689 static int wpa_replay_counter_valid(struct wpa_key_replay_counter *ctr,
690 const u8 *replay_counter)
693 for (i = 0; i < RSNA_MAX_EAPOL_RETRIES; i++) {
696 if (os_memcmp(replay_counter, ctr[i].counter,
697 WPA_REPLAY_COUNTER_LEN) == 0)
704 static void wpa_replay_counter_mark_invalid(struct wpa_key_replay_counter *ctr,
705 const u8 *replay_counter)
708 for (i = 0; i < RSNA_MAX_EAPOL_RETRIES; i++) {
710 (replay_counter == NULL ||
711 os_memcmp(replay_counter, ctr[i].counter,
712 WPA_REPLAY_COUNTER_LEN) == 0))
713 ctr[i].valid = FALSE;
718 #ifdef CONFIG_IEEE80211R
719 static int ft_check_msg_2_of_4(struct wpa_authenticator *wpa_auth,
720 struct wpa_state_machine *sm,
721 struct wpa_eapol_ie_parse *kde)
723 struct wpa_ie_data ie;
724 struct rsn_mdie *mdie;
726 if (wpa_parse_wpa_ie_rsn(kde->rsn_ie, kde->rsn_ie_len, &ie) < 0 ||
727 ie.num_pmkid != 1 || ie.pmkid == NULL) {
728 wpa_printf(MSG_DEBUG, "FT: No PMKR1Name in "
729 "FT 4-way handshake message 2/4");
733 os_memcpy(sm->sup_pmk_r1_name, ie.pmkid, PMKID_LEN);
734 wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name from Supplicant",
735 sm->sup_pmk_r1_name, PMKID_LEN);
737 if (!kde->mdie || !kde->ftie) {
738 wpa_printf(MSG_DEBUG, "FT: No %s in FT 4-way handshake "
739 "message 2/4", kde->mdie ? "FTIE" : "MDIE");
743 mdie = (struct rsn_mdie *) (kde->mdie + 2);
744 if (kde->mdie[1] < sizeof(struct rsn_mdie) ||
745 os_memcmp(wpa_auth->conf.mobility_domain, mdie->mobility_domain,
746 MOBILITY_DOMAIN_ID_LEN) != 0) {
747 wpa_printf(MSG_DEBUG, "FT: MDIE mismatch");
751 if (sm->assoc_resp_ftie &&
752 (kde->ftie[1] != sm->assoc_resp_ftie[1] ||
753 os_memcmp(kde->ftie, sm->assoc_resp_ftie,
754 2 + sm->assoc_resp_ftie[1]) != 0)) {
755 wpa_printf(MSG_DEBUG, "FT: FTIE mismatch");
756 wpa_hexdump(MSG_DEBUG, "FT: FTIE in EAPOL-Key msg 2/4",
757 kde->ftie, kde->ftie_len);
758 wpa_hexdump(MSG_DEBUG, "FT: FTIE in (Re)AssocResp",
759 sm->assoc_resp_ftie, 2 + sm->assoc_resp_ftie[1]);
765 #endif /* CONFIG_IEEE80211R */
768 static int wpa_receive_error_report(struct wpa_authenticator *wpa_auth,
769 struct wpa_state_machine *sm, int group)
771 /* Supplicant reported a Michael MIC error */
772 wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_INFO,
773 "received EAPOL-Key Error Request "
774 "(STA detected Michael MIC failure (group=%d))",
777 if (group && wpa_auth->conf.wpa_group != WPA_CIPHER_TKIP) {
778 wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
779 "ignore Michael MIC failure report since "
780 "group cipher is not TKIP");
781 } else if (!group && sm->pairwise != WPA_CIPHER_TKIP) {
782 wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
783 "ignore Michael MIC failure report since "
784 "pairwise cipher is not TKIP");
786 if (wpa_auth_mic_failure_report(wpa_auth, sm->addr) > 0)
787 return 1; /* STA entry was removed */
788 sm->dot11RSNAStatsTKIPRemoteMICFailures++;
789 wpa_auth->dot11RSNAStatsTKIPRemoteMICFailures++;
793 * Error report is not a request for a new key handshake, but since
794 * Authenticator may do it, let's change the keys now anyway.
796 wpa_request_new_ptk(sm);
801 static int wpa_try_alt_snonce(struct wpa_state_machine *sm, u8 *data,
806 const u8 *pmk = NULL;
809 if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt)) {
810 pmk = wpa_auth_get_psk(sm->wpa_auth, sm->addr,
811 sm->p2p_dev_addr, pmk);
817 wpa_derive_ptk(sm, sm->alt_SNonce, pmk, &PTK);
819 if (wpa_verify_key_mic(sm->wpa_key_mgmt, &PTK, data, data_len)
825 if (!wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt))
830 wpa_printf(MSG_DEBUG,
831 "WPA: Earlier SNonce did not result in matching MIC");
835 wpa_printf(MSG_DEBUG,
836 "WPA: Earlier SNonce resulted in matching MIC");
837 sm->alt_snonce_valid = 0;
838 os_memcpy(sm->SNonce, sm->alt_SNonce, WPA_NONCE_LEN);
839 os_memcpy(&sm->PTK, &PTK, sizeof(PTK));
840 sm->PTK_valid = TRUE;
846 void wpa_receive(struct wpa_authenticator *wpa_auth,
847 struct wpa_state_machine *sm,
848 u8 *data, size_t data_len)
850 struct ieee802_1x_hdr *hdr;
851 struct wpa_eapol_key *key;
852 u16 key_info, key_data_length;
853 enum { PAIRWISE_2, PAIRWISE_4, GROUP_2, REQUEST,
854 SMK_M1, SMK_M3, SMK_ERROR } msg;
856 struct wpa_eapol_ie_parse kde;
858 const u8 *eapol_key_ie;
859 size_t eapol_key_ie_len;
861 if (wpa_auth == NULL || !wpa_auth->conf.wpa || sm == NULL)
864 if (data_len < sizeof(*hdr) + sizeof(*key))
867 hdr = (struct ieee802_1x_hdr *) data;
868 key = (struct wpa_eapol_key *) (hdr + 1);
869 key_info = WPA_GET_BE16(key->key_info);
870 key_data_length = WPA_GET_BE16(key->key_data_length);
871 wpa_printf(MSG_DEBUG, "WPA: Received EAPOL-Key from " MACSTR
872 " key_info=0x%x type=%u key_data_length=%u",
873 MAC2STR(sm->addr), key_info, key->type, key_data_length);
874 if (key_data_length > data_len - sizeof(*hdr) - sizeof(*key)) {
875 wpa_printf(MSG_INFO, "WPA: Invalid EAPOL-Key frame - "
876 "key_data overflow (%d > %lu)",
878 (unsigned long) (data_len - sizeof(*hdr) -
883 if (sm->wpa == WPA_VERSION_WPA2) {
884 if (key->type == EAPOL_KEY_TYPE_WPA) {
886 * Some deployed station implementations seem to send
887 * msg 4/4 with incorrect type value in WPA2 mode.
889 wpa_printf(MSG_DEBUG, "Workaround: Allow EAPOL-Key "
890 "with unexpected WPA type in RSN mode");
891 } else if (key->type != EAPOL_KEY_TYPE_RSN) {
892 wpa_printf(MSG_DEBUG, "Ignore EAPOL-Key with "
893 "unexpected type %d in RSN mode",
898 if (key->type != EAPOL_KEY_TYPE_WPA) {
899 wpa_printf(MSG_DEBUG, "Ignore EAPOL-Key with "
900 "unexpected type %d in WPA mode",
906 wpa_hexdump(MSG_DEBUG, "WPA: Received Key Nonce", key->key_nonce,
908 wpa_hexdump(MSG_DEBUG, "WPA: Received Replay Counter",
909 key->replay_counter, WPA_REPLAY_COUNTER_LEN);
911 /* FIX: verify that the EAPOL-Key frame was encrypted if pairwise keys
914 if ((key_info & (WPA_KEY_INFO_SMK_MESSAGE | WPA_KEY_INFO_REQUEST)) ==
915 (WPA_KEY_INFO_SMK_MESSAGE | WPA_KEY_INFO_REQUEST)) {
916 if (key_info & WPA_KEY_INFO_ERROR) {
918 msgtxt = "SMK Error";
923 } else if (key_info & WPA_KEY_INFO_SMK_MESSAGE) {
926 } else if (key_info & WPA_KEY_INFO_REQUEST) {
929 } else if (!(key_info & WPA_KEY_INFO_KEY_TYPE)) {
931 msgtxt = "2/2 Group";
932 } else if (key_data_length == 0) {
934 msgtxt = "4/4 Pairwise";
937 msgtxt = "2/4 Pairwise";
940 /* TODO: key_info type validation for PeerKey */
941 if (msg == REQUEST || msg == PAIRWISE_2 || msg == PAIRWISE_4 ||
943 u16 ver = key_info & WPA_KEY_INFO_TYPE_MASK;
944 if (sm->pairwise == WPA_CIPHER_CCMP ||
945 sm->pairwise == WPA_CIPHER_GCMP) {
946 if (wpa_use_aes_cmac(sm) &&
947 sm->wpa_key_mgmt != WPA_KEY_MGMT_OSEN &&
948 !wpa_key_mgmt_suite_b(sm->wpa_key_mgmt) &&
949 ver != WPA_KEY_INFO_TYPE_AES_128_CMAC) {
950 wpa_auth_logger(wpa_auth, sm->addr,
952 "advertised support for "
953 "AES-128-CMAC, but did not "
958 if (!wpa_use_aes_cmac(sm) &&
959 ver != WPA_KEY_INFO_TYPE_HMAC_SHA1_AES) {
960 wpa_auth_logger(wpa_auth, sm->addr,
962 "did not use HMAC-SHA1-AES "
968 if (wpa_key_mgmt_suite_b(sm->wpa_key_mgmt) &&
969 ver != WPA_KEY_INFO_TYPE_AKM_DEFINED) {
970 wpa_auth_logger(wpa_auth, sm->addr, LOGGER_WARNING,
971 "did not use EAPOL-Key descriptor version 0 as required for AKM-defined cases");
976 if (key_info & WPA_KEY_INFO_REQUEST) {
977 if (sm->req_replay_counter_used &&
978 os_memcmp(key->replay_counter, sm->req_replay_counter,
979 WPA_REPLAY_COUNTER_LEN) <= 0) {
980 wpa_auth_logger(wpa_auth, sm->addr, LOGGER_WARNING,
981 "received EAPOL-Key request with "
987 if (!(key_info & WPA_KEY_INFO_REQUEST) &&
988 !wpa_replay_counter_valid(sm->key_replay, key->replay_counter)) {
991 if (msg == PAIRWISE_2 &&
992 wpa_replay_counter_valid(sm->prev_key_replay,
993 key->replay_counter) &&
994 sm->wpa_ptk_state == WPA_PTK_PTKINITNEGOTIATING &&
995 os_memcmp(sm->SNonce, key->key_nonce, WPA_NONCE_LEN) != 0)
998 * Some supplicant implementations (e.g., Windows XP
999 * WZC) update SNonce for each EAPOL-Key 2/4. This
1000 * breaks the workaround on accepting any of the
1001 * pending requests, so allow the SNonce to be updated
1002 * even if we have already sent out EAPOL-Key 3/4.
1004 wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG,
1005 "Process SNonce update from STA "
1006 "based on retransmitted EAPOL-Key "
1008 sm->update_snonce = 1;
1009 os_memcpy(sm->alt_SNonce, sm->SNonce, WPA_NONCE_LEN);
1010 sm->alt_snonce_valid = TRUE;
1011 os_memcpy(sm->alt_replay_counter,
1012 sm->key_replay[0].counter,
1013 WPA_REPLAY_COUNTER_LEN);
1014 goto continue_processing;
1017 if (msg == PAIRWISE_4 && sm->alt_snonce_valid &&
1018 sm->wpa_ptk_state == WPA_PTK_PTKINITNEGOTIATING &&
1019 os_memcmp(key->replay_counter, sm->alt_replay_counter,
1020 WPA_REPLAY_COUNTER_LEN) == 0) {
1022 * Supplicant may still be using the old SNonce since
1023 * there was two EAPOL-Key 2/4 messages and they had
1024 * different SNonce values.
1026 wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG,
1027 "Try to process received EAPOL-Key 4/4 based on old Replay Counter and SNonce from an earlier EAPOL-Key 1/4");
1028 goto continue_processing;
1031 if (msg == PAIRWISE_2 &&
1032 wpa_replay_counter_valid(sm->prev_key_replay,
1033 key->replay_counter) &&
1034 sm->wpa_ptk_state == WPA_PTK_PTKINITNEGOTIATING) {
1035 wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG,
1036 "ignore retransmitted EAPOL-Key %s - "
1037 "SNonce did not change", msgtxt);
1039 wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG,
1040 "received EAPOL-Key %s with "
1041 "unexpected replay counter", msgtxt);
1043 for (i = 0; i < RSNA_MAX_EAPOL_RETRIES; i++) {
1044 if (!sm->key_replay[i].valid)
1046 wpa_hexdump(MSG_DEBUG, "pending replay counter",
1047 sm->key_replay[i].counter,
1048 WPA_REPLAY_COUNTER_LEN);
1050 wpa_hexdump(MSG_DEBUG, "received replay counter",
1051 key->replay_counter, WPA_REPLAY_COUNTER_LEN);
1055 continue_processing:
1058 if (sm->wpa_ptk_state != WPA_PTK_PTKSTART &&
1059 sm->wpa_ptk_state != WPA_PTK_PTKCALCNEGOTIATING &&
1060 (!sm->update_snonce ||
1061 sm->wpa_ptk_state != WPA_PTK_PTKINITNEGOTIATING)) {
1062 wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_INFO,
1063 "received EAPOL-Key msg 2/4 in "
1064 "invalid state (%d) - dropped",
1068 random_add_randomness(key->key_nonce, WPA_NONCE_LEN);
1069 if (sm->group->reject_4way_hs_for_entropy) {
1071 * The system did not have enough entropy to generate
1072 * strong random numbers. Reject the first 4-way
1073 * handshake(s) and collect some entropy based on the
1074 * information from it. Once enough entropy is
1075 * available, the next atempt will trigger GMK/Key
1076 * Counter update and the station will be allowed to
1079 wpa_printf(MSG_DEBUG, "WPA: Reject 4-way handshake to "
1080 "collect more entropy for random number "
1082 random_mark_pool_ready();
1083 wpa_sta_disconnect(wpa_auth, sm->addr);
1086 if (wpa_parse_kde_ies((u8 *) (key + 1), key_data_length,
1088 wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_INFO,
1089 "received EAPOL-Key msg 2/4 with "
1090 "invalid Key Data contents");
1094 eapol_key_ie = kde.rsn_ie;
1095 eapol_key_ie_len = kde.rsn_ie_len;
1096 } else if (kde.osen) {
1097 eapol_key_ie = kde.osen;
1098 eapol_key_ie_len = kde.osen_len;
1100 eapol_key_ie = kde.wpa_ie;
1101 eapol_key_ie_len = kde.wpa_ie_len;
1103 ft = sm->wpa == WPA_VERSION_WPA2 &&
1104 wpa_key_mgmt_ft(sm->wpa_key_mgmt);
1105 if (sm->wpa_ie == NULL ||
1106 wpa_compare_rsn_ie(ft,
1107 sm->wpa_ie, sm->wpa_ie_len,
1108 eapol_key_ie, eapol_key_ie_len)) {
1109 wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
1110 "WPA IE from (Re)AssocReq did not "
1111 "match with msg 2/4");
1113 wpa_hexdump(MSG_DEBUG, "WPA IE in AssocReq",
1114 sm->wpa_ie, sm->wpa_ie_len);
1116 wpa_hexdump(MSG_DEBUG, "WPA IE in msg 2/4",
1117 eapol_key_ie, eapol_key_ie_len);
1118 /* MLME-DEAUTHENTICATE.request */
1119 wpa_sta_disconnect(wpa_auth, sm->addr);
1122 #ifdef CONFIG_IEEE80211R
1123 if (ft && ft_check_msg_2_of_4(wpa_auth, sm, &kde) < 0) {
1124 wpa_sta_disconnect(wpa_auth, sm->addr);
1127 #endif /* CONFIG_IEEE80211R */
1129 if (kde.ip_addr_req && kde.ip_addr_req[0] &&
1130 wpa_auth->ip_pool && WPA_GET_BE32(sm->ip_addr) == 0) {
1132 wpa_printf(MSG_DEBUG, "P2P: IP address requested in "
1133 "EAPOL-Key exchange");
1134 idx = bitfield_get_first_zero(wpa_auth->ip_pool);
1136 u32 start = WPA_GET_BE32(wpa_auth->conf.
1138 bitfield_set(wpa_auth->ip_pool, idx);
1139 WPA_PUT_BE32(sm->ip_addr, start + idx);
1140 wpa_printf(MSG_DEBUG, "P2P: Assigned IP "
1141 "address %u.%u.%u.%u to " MACSTR,
1142 sm->ip_addr[0], sm->ip_addr[1],
1143 sm->ip_addr[2], sm->ip_addr[3],
1147 #endif /* CONFIG_P2P */
1150 if (sm->wpa_ptk_state != WPA_PTK_PTKINITNEGOTIATING ||
1152 wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_INFO,
1153 "received EAPOL-Key msg 4/4 in "
1154 "invalid state (%d) - dropped",
1160 if (sm->wpa_ptk_group_state != WPA_PTK_GROUP_REKEYNEGOTIATING
1161 || !sm->PTK_valid) {
1162 wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_INFO,
1163 "received EAPOL-Key msg 2/2 in "
1164 "invalid state (%d) - dropped",
1165 sm->wpa_ptk_group_state);
1169 #ifdef CONFIG_PEERKEY
1173 if (!wpa_auth->conf.peerkey) {
1174 wpa_printf(MSG_DEBUG, "RSN: SMK M1/M3/Error, but "
1175 "PeerKey use disabled - ignoring message");
1178 if (!sm->PTK_valid) {
1179 wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
1180 "received EAPOL-Key msg SMK in "
1181 "invalid state - dropped");
1185 #else /* CONFIG_PEERKEY */
1189 return; /* STSL disabled - ignore SMK messages */
1190 #endif /* CONFIG_PEERKEY */
1195 wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG,
1196 "received EAPOL-Key frame (%s)", msgtxt);
1198 if (key_info & WPA_KEY_INFO_ACK) {
1199 wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
1200 "received invalid EAPOL-Key: Key Ack set");
1204 if (!(key_info & WPA_KEY_INFO_MIC)) {
1205 wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
1206 "received invalid EAPOL-Key: Key MIC not set");
1210 sm->MICVerified = FALSE;
1211 if (sm->PTK_valid && !sm->update_snonce) {
1212 if (wpa_verify_key_mic(sm->wpa_key_mgmt, &sm->PTK, data,
1214 (msg != PAIRWISE_4 || !sm->alt_snonce_valid ||
1215 wpa_try_alt_snonce(sm, data, data_len))) {
1216 wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
1217 "received EAPOL-Key with invalid MIC");
1220 sm->MICVerified = TRUE;
1221 eloop_cancel_timeout(wpa_send_eapol_timeout, wpa_auth, sm);
1222 sm->pending_1_of_4_timeout = 0;
1225 if (key_info & WPA_KEY_INFO_REQUEST) {
1226 if (sm->MICVerified) {
1227 sm->req_replay_counter_used = 1;
1228 os_memcpy(sm->req_replay_counter, key->replay_counter,
1229 WPA_REPLAY_COUNTER_LEN);
1231 wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
1232 "received EAPOL-Key request with "
1238 * TODO: should decrypt key data field if encryption was used;
1239 * even though MAC address KDE is not normally encrypted,
1240 * supplicant is allowed to encrypt it.
1242 if (msg == SMK_ERROR) {
1243 #ifdef CONFIG_PEERKEY
1244 wpa_smk_error(wpa_auth, sm, (const u8 *) (key + 1),
1246 #endif /* CONFIG_PEERKEY */
1248 } else if (key_info & WPA_KEY_INFO_ERROR) {
1249 if (wpa_receive_error_report(
1251 !(key_info & WPA_KEY_INFO_KEY_TYPE)) > 0)
1252 return; /* STA entry was removed */
1253 } else if (key_info & WPA_KEY_INFO_KEY_TYPE) {
1254 wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
1255 "received EAPOL-Key Request for new "
1257 wpa_request_new_ptk(sm);
1258 #ifdef CONFIG_PEERKEY
1259 } else if (msg == SMK_M1) {
1260 wpa_smk_m1(wpa_auth, sm, key, (const u8 *) (key + 1),
1262 #endif /* CONFIG_PEERKEY */
1263 } else if (key_data_length > 0 &&
1264 wpa_parse_kde_ies((const u8 *) (key + 1),
1265 key_data_length, &kde) == 0 &&
1268 wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
1269 "received EAPOL-Key Request for GTK "
1271 eloop_cancel_timeout(wpa_rekey_gtk, wpa_auth, NULL);
1272 wpa_rekey_gtk(wpa_auth, NULL);
1275 /* Do not allow the same key replay counter to be reused. */
1276 wpa_replay_counter_mark_invalid(sm->key_replay,
1277 key->replay_counter);
1279 if (msg == PAIRWISE_2) {
1281 * Maintain a copy of the pending EAPOL-Key frames in
1282 * case the EAPOL-Key frame was retransmitted. This is
1283 * needed to allow EAPOL-Key msg 2/4 reply to another
1284 * pending msg 1/4 to update the SNonce to work around
1285 * unexpected supplicant behavior.
1287 os_memcpy(sm->prev_key_replay, sm->key_replay,
1288 sizeof(sm->key_replay));
1290 os_memset(sm->prev_key_replay, 0,
1291 sizeof(sm->prev_key_replay));
1295 * Make sure old valid counters are not accepted anymore and
1296 * do not get copied again.
1298 wpa_replay_counter_mark_invalid(sm->key_replay, NULL);
1301 #ifdef CONFIG_PEERKEY
1302 if (msg == SMK_M3) {
1303 wpa_smk_m3(wpa_auth, sm, key, (const u8 *) (key + 1),
1307 #endif /* CONFIG_PEERKEY */
1309 os_free(sm->last_rx_eapol_key);
1310 sm->last_rx_eapol_key = os_malloc(data_len);
1311 if (sm->last_rx_eapol_key == NULL)
1313 os_memcpy(sm->last_rx_eapol_key, data, data_len);
1314 sm->last_rx_eapol_key_len = data_len;
1316 sm->rx_eapol_key_secure = !!(key_info & WPA_KEY_INFO_SECURE);
1317 sm->EAPOLKeyReceived = TRUE;
1318 sm->EAPOLKeyPairwise = !!(key_info & WPA_KEY_INFO_KEY_TYPE);
1319 sm->EAPOLKeyRequest = !!(key_info & WPA_KEY_INFO_REQUEST);
1320 os_memcpy(sm->SNonce, key->key_nonce, WPA_NONCE_LEN);
1325 static int wpa_gmk_to_gtk(const u8 *gmk, const char *label, const u8 *addr,
1326 const u8 *gnonce, u8 *gtk, size_t gtk_len)
1328 u8 data[ETH_ALEN + WPA_NONCE_LEN + 8 + 16];
1332 /* GTK = PRF-X(GMK, "Group key expansion",
1333 * AA || GNonce || Time || random data)
1334 * The example described in the IEEE 802.11 standard uses only AA and
1335 * GNonce as inputs here. Add some more entropy since this derivation
1336 * is done only at the Authenticator and as such, does not need to be
1339 os_memcpy(data, addr, ETH_ALEN);
1340 os_memcpy(data + ETH_ALEN, gnonce, WPA_NONCE_LEN);
1341 pos = data + ETH_ALEN + WPA_NONCE_LEN;
1342 wpa_get_ntp_timestamp(pos);
1344 if (random_get_bytes(pos, 16) < 0)
1347 #ifdef CONFIG_IEEE80211W
1348 sha256_prf(gmk, WPA_GMK_LEN, label, data, sizeof(data), gtk, gtk_len);
1349 #else /* CONFIG_IEEE80211W */
1350 if (sha1_prf(gmk, WPA_GMK_LEN, label, data, sizeof(data), gtk, gtk_len)
1353 #endif /* CONFIG_IEEE80211W */
1359 static void wpa_send_eapol_timeout(void *eloop_ctx, void *timeout_ctx)
1361 struct wpa_authenticator *wpa_auth = eloop_ctx;
1362 struct wpa_state_machine *sm = timeout_ctx;
1364 sm->pending_1_of_4_timeout = 0;
1365 wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG, "EAPOL-Key timeout");
1366 sm->TimeoutEvt = TRUE;
1371 void __wpa_send_eapol(struct wpa_authenticator *wpa_auth,
1372 struct wpa_state_machine *sm, int key_info,
1373 const u8 *key_rsc, const u8 *nonce,
1374 const u8 *kde, size_t kde_len,
1375 int keyidx, int encr, int force_version)
1377 struct ieee802_1x_hdr *hdr;
1378 struct wpa_eapol_key *key;
1381 int key_data_len, pad_len = 0;
1383 int version, pairwise;
1386 len = sizeof(struct ieee802_1x_hdr) + sizeof(struct wpa_eapol_key);
1389 version = force_version;
1390 else if (sm->wpa_key_mgmt == WPA_KEY_MGMT_OSEN ||
1391 wpa_key_mgmt_suite_b(sm->wpa_key_mgmt))
1392 version = WPA_KEY_INFO_TYPE_AKM_DEFINED;
1393 else if (wpa_use_aes_cmac(sm))
1394 version = WPA_KEY_INFO_TYPE_AES_128_CMAC;
1395 else if (sm->pairwise != WPA_CIPHER_TKIP)
1396 version = WPA_KEY_INFO_TYPE_HMAC_SHA1_AES;
1398 version = WPA_KEY_INFO_TYPE_HMAC_MD5_RC4;
1400 pairwise = !!(key_info & WPA_KEY_INFO_KEY_TYPE);
1402 wpa_printf(MSG_DEBUG, "WPA: Send EAPOL(version=%d secure=%d mic=%d "
1403 "ack=%d install=%d pairwise=%d kde_len=%lu keyidx=%d "
1406 (key_info & WPA_KEY_INFO_SECURE) ? 1 : 0,
1407 (key_info & WPA_KEY_INFO_MIC) ? 1 : 0,
1408 (key_info & WPA_KEY_INFO_ACK) ? 1 : 0,
1409 (key_info & WPA_KEY_INFO_INSTALL) ? 1 : 0,
1410 pairwise, (unsigned long) kde_len, keyidx, encr);
1412 key_data_len = kde_len;
1414 if ((version == WPA_KEY_INFO_TYPE_HMAC_SHA1_AES ||
1415 sm->wpa_key_mgmt == WPA_KEY_MGMT_OSEN ||
1416 wpa_key_mgmt_suite_b(sm->wpa_key_mgmt) ||
1417 version == WPA_KEY_INFO_TYPE_AES_128_CMAC) && encr) {
1418 pad_len = key_data_len % 8;
1420 pad_len = 8 - pad_len;
1421 key_data_len += pad_len + 8;
1424 len += key_data_len;
1426 hdr = os_zalloc(len);
1429 hdr->version = wpa_auth->conf.eapol_version;
1430 hdr->type = IEEE802_1X_TYPE_EAPOL_KEY;
1431 hdr->length = host_to_be16(len - sizeof(*hdr));
1432 key = (struct wpa_eapol_key *) (hdr + 1);
1434 key->type = sm->wpa == WPA_VERSION_WPA2 ?
1435 EAPOL_KEY_TYPE_RSN : EAPOL_KEY_TYPE_WPA;
1436 key_info |= version;
1437 if (encr && sm->wpa == WPA_VERSION_WPA2)
1438 key_info |= WPA_KEY_INFO_ENCR_KEY_DATA;
1439 if (sm->wpa != WPA_VERSION_WPA2)
1440 key_info |= keyidx << WPA_KEY_INFO_KEY_INDEX_SHIFT;
1441 WPA_PUT_BE16(key->key_info, key_info);
1443 alg = pairwise ? sm->pairwise : wpa_auth->conf.wpa_group;
1444 WPA_PUT_BE16(key->key_length, wpa_cipher_key_len(alg));
1445 if (key_info & WPA_KEY_INFO_SMK_MESSAGE)
1446 WPA_PUT_BE16(key->key_length, 0);
1448 /* FIX: STSL: what to use as key_replay_counter? */
1449 for (i = RSNA_MAX_EAPOL_RETRIES - 1; i > 0; i--) {
1450 sm->key_replay[i].valid = sm->key_replay[i - 1].valid;
1451 os_memcpy(sm->key_replay[i].counter,
1452 sm->key_replay[i - 1].counter,
1453 WPA_REPLAY_COUNTER_LEN);
1455 inc_byte_array(sm->key_replay[0].counter, WPA_REPLAY_COUNTER_LEN);
1456 os_memcpy(key->replay_counter, sm->key_replay[0].counter,
1457 WPA_REPLAY_COUNTER_LEN);
1458 wpa_hexdump(MSG_DEBUG, "WPA: Replay Counter",
1459 key->replay_counter, WPA_REPLAY_COUNTER_LEN);
1460 sm->key_replay[0].valid = TRUE;
1463 os_memcpy(key->key_nonce, nonce, WPA_NONCE_LEN);
1466 os_memcpy(key->key_rsc, key_rsc, WPA_KEY_RSC_LEN);
1469 os_memcpy(key + 1, kde, kde_len);
1470 WPA_PUT_BE16(key->key_data_length, kde_len);
1471 } else if (encr && kde) {
1472 buf = os_zalloc(key_data_len);
1478 os_memcpy(pos, kde, kde_len);
1484 wpa_hexdump_key(MSG_DEBUG, "Plaintext EAPOL-Key Key Data",
1486 if (version == WPA_KEY_INFO_TYPE_HMAC_SHA1_AES ||
1487 sm->wpa_key_mgmt == WPA_KEY_MGMT_OSEN ||
1488 wpa_key_mgmt_suite_b(sm->wpa_key_mgmt) ||
1489 version == WPA_KEY_INFO_TYPE_AES_128_CMAC) {
1490 if (aes_wrap(sm->PTK.kek, sm->PTK.kek_len,
1491 (key_data_len - 8) / 8, buf,
1492 (u8 *) (key + 1))) {
1497 WPA_PUT_BE16(key->key_data_length, key_data_len);
1498 } else if (sm->PTK.kek_len == 16) {
1500 os_memcpy(key->key_iv,
1501 sm->group->Counter + WPA_NONCE_LEN - 16, 16);
1502 inc_byte_array(sm->group->Counter, WPA_NONCE_LEN);
1503 os_memcpy(ek, key->key_iv, 16);
1504 os_memcpy(ek + 16, sm->PTK.kek, sm->PTK.kek_len);
1505 os_memcpy(key + 1, buf, key_data_len);
1506 rc4_skip(ek, 32, 256, (u8 *) (key + 1), key_data_len);
1507 WPA_PUT_BE16(key->key_data_length, key_data_len);
1516 if (key_info & WPA_KEY_INFO_MIC) {
1517 if (!sm->PTK_valid) {
1518 wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG,
1519 "PTK not valid when sending EAPOL-Key "
1524 wpa_eapol_key_mic(sm->PTK.kck, sm->PTK.kck_len,
1525 sm->wpa_key_mgmt, version,
1526 (u8 *) hdr, len, key->key_mic);
1527 #ifdef CONFIG_TESTING_OPTIONS
1529 wpa_auth->conf.corrupt_gtk_rekey_mic_probability > 0.0 &&
1531 wpa_auth->conf.corrupt_gtk_rekey_mic_probability) {
1532 wpa_auth_logger(wpa_auth, sm->addr, LOGGER_INFO,
1533 "Corrupting group EAPOL-Key Key MIC");
1536 #endif /* CONFIG_TESTING_OPTIONS */
1539 wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_inc_EapolFramesTx,
1541 wpa_auth_send_eapol(wpa_auth, sm->addr, (u8 *) hdr, len,
1547 static void wpa_send_eapol(struct wpa_authenticator *wpa_auth,
1548 struct wpa_state_machine *sm, int key_info,
1549 const u8 *key_rsc, const u8 *nonce,
1550 const u8 *kde, size_t kde_len,
1551 int keyidx, int encr)
1554 int pairwise = key_info & WPA_KEY_INFO_KEY_TYPE;
1560 __wpa_send_eapol(wpa_auth, sm, key_info, key_rsc, nonce, kde, kde_len,
1563 ctr = pairwise ? sm->TimeoutCtr : sm->GTimeoutCtr;
1564 if (ctr == 1 && wpa_auth->conf.tx_status)
1565 timeout_ms = pairwise ? eapol_key_timeout_first :
1566 eapol_key_timeout_first_group;
1568 timeout_ms = eapol_key_timeout_subseq;
1569 if (pairwise && ctr == 1 && !(key_info & WPA_KEY_INFO_MIC))
1570 sm->pending_1_of_4_timeout = 1;
1571 wpa_printf(MSG_DEBUG, "WPA: Use EAPOL-Key timeout of %u ms (retry "
1572 "counter %d)", timeout_ms, ctr);
1573 eloop_register_timeout(timeout_ms / 1000, (timeout_ms % 1000) * 1000,
1574 wpa_send_eapol_timeout, wpa_auth, sm);
1578 static int wpa_verify_key_mic(int akmp, struct wpa_ptk *PTK, u8 *data,
1581 struct ieee802_1x_hdr *hdr;
1582 struct wpa_eapol_key *key;
1585 u8 mic[WPA_EAPOL_KEY_MIC_MAX_LEN];
1586 size_t mic_len = 16;
1588 if (data_len < sizeof(*hdr) + sizeof(*key))
1591 hdr = (struct ieee802_1x_hdr *) data;
1592 key = (struct wpa_eapol_key *) (hdr + 1);
1593 key_info = WPA_GET_BE16(key->key_info);
1594 os_memcpy(mic, key->key_mic, mic_len);
1595 os_memset(key->key_mic, 0, mic_len);
1596 if (wpa_eapol_key_mic(PTK->kck, PTK->kck_len, akmp,
1597 key_info & WPA_KEY_INFO_TYPE_MASK,
1598 data, data_len, key->key_mic) ||
1599 os_memcmp_const(mic, key->key_mic, mic_len) != 0)
1601 os_memcpy(key->key_mic, mic, mic_len);
1606 void wpa_remove_ptk(struct wpa_state_machine *sm)
1608 sm->PTK_valid = FALSE;
1609 os_memset(&sm->PTK, 0, sizeof(sm->PTK));
1610 wpa_auth_set_key(sm->wpa_auth, 0, WPA_ALG_NONE, sm->addr, 0, NULL, 0);
1611 sm->pairwise_set = FALSE;
1612 eloop_cancel_timeout(wpa_rekey_ptk, sm->wpa_auth, sm);
1616 int wpa_auth_sm_event(struct wpa_state_machine *sm, wpa_event event)
1623 wpa_auth_vlogger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
1624 "event %d notification", event);
1629 /* PTKs are derived through AMPE */
1630 if (wpa_auth_start_ampe(sm->wpa_auth, sm->addr)) {
1635 #endif /* CONFIG_MESH */
1640 sm->DeauthenticationRequest = TRUE;
1643 case WPA_REAUTH_EAPOL:
1646 * When using WPS, we may end up here if the STA
1647 * manages to re-associate without the previous STA
1648 * entry getting removed. Consequently, we need to make
1649 * sure that the WPA state machines gets initialized
1650 * properly at this point.
1652 wpa_printf(MSG_DEBUG, "WPA state machine had not been "
1653 "started - initialize now");
1656 if (wpa_sm_step(sm) == 1)
1657 return 1; /* should not really happen */
1659 sm->AuthenticationRequest = TRUE;
1662 if (sm->GUpdateStationKeys) {
1664 * Reauthentication cancels the pending group key
1665 * update for this STA.
1667 sm->group->GKeyDoneStations--;
1668 sm->GUpdateStationKeys = FALSE;
1669 sm->PtkGroupInit = TRUE;
1671 sm->ReAuthenticationRequest = TRUE;
1674 #ifdef CONFIG_IEEE80211R
1675 wpa_printf(MSG_DEBUG, "FT: Retry PTK configuration "
1676 "after association");
1677 wpa_ft_install_ptk(sm);
1679 /* Using FT protocol, not WPA auth state machine */
1680 sm->ft_completed = 1;
1682 #else /* CONFIG_IEEE80211R */
1684 #endif /* CONFIG_IEEE80211R */
1687 #ifdef CONFIG_IEEE80211R
1688 sm->ft_completed = 0;
1689 #endif /* CONFIG_IEEE80211R */
1691 #ifdef CONFIG_IEEE80211W
1692 if (sm->mgmt_frame_prot && event == WPA_AUTH)
1694 #endif /* CONFIG_IEEE80211W */
1697 sm->PTK_valid = FALSE;
1698 os_memset(&sm->PTK, 0, sizeof(sm->PTK));
1700 if (event != WPA_REAUTH_EAPOL)
1704 return wpa_sm_step(sm);
1708 SM_STATE(WPA_PTK, INITIALIZE)
1710 SM_ENTRY_MA(WPA_PTK, INITIALIZE, wpa_ptk);
1712 /* Init flag is not cleared here, so avoid busy
1713 * loop by claiming nothing changed. */
1714 sm->changed = FALSE;
1718 if (sm->GUpdateStationKeys)
1719 sm->group->GKeyDoneStations--;
1720 sm->GUpdateStationKeys = FALSE;
1721 if (sm->wpa == WPA_VERSION_WPA)
1722 sm->PInitAKeys = FALSE;
1723 if (1 /* Unicast cipher supported AND (ESS OR ((IBSS or WDS) and
1724 * Local AA > Remote AA)) */) {
1727 wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_portEnabled, 0);
1729 wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_portValid, 0);
1731 if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt)) {
1732 wpa_auth_set_eapol(sm->wpa_auth, sm->addr,
1733 WPA_EAPOL_authorized, 0);
1738 SM_STATE(WPA_PTK, DISCONNECT)
1740 SM_ENTRY_MA(WPA_PTK, DISCONNECT, wpa_ptk);
1741 sm->Disconnect = FALSE;
1742 wpa_sta_disconnect(sm->wpa_auth, sm->addr);
1746 SM_STATE(WPA_PTK, DISCONNECTED)
1748 SM_ENTRY_MA(WPA_PTK, DISCONNECTED, wpa_ptk);
1749 sm->DeauthenticationRequest = FALSE;
1753 SM_STATE(WPA_PTK, AUTHENTICATION)
1755 SM_ENTRY_MA(WPA_PTK, AUTHENTICATION, wpa_ptk);
1756 os_memset(&sm->PTK, 0, sizeof(sm->PTK));
1757 sm->PTK_valid = FALSE;
1758 wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_portControl_Auto,
1760 wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_portEnabled, 1);
1761 sm->AuthenticationRequest = FALSE;
1765 static void wpa_group_ensure_init(struct wpa_authenticator *wpa_auth,
1766 struct wpa_group *group)
1768 if (group->first_sta_seen)
1771 * System has run bit further than at the time hostapd was started
1772 * potentially very early during boot up. This provides better chances
1773 * of collecting more randomness on embedded systems. Re-initialize the
1774 * GMK and Counter here to improve their strength if there was not
1775 * enough entropy available immediately after system startup.
1777 wpa_printf(MSG_DEBUG, "WPA: Re-initialize GMK/Counter on first "
1779 if (random_pool_ready() != 1) {
1780 wpa_printf(MSG_INFO, "WPA: Not enough entropy in random pool "
1781 "to proceed - reject first 4-way handshake");
1782 group->reject_4way_hs_for_entropy = TRUE;
1784 group->first_sta_seen = TRUE;
1785 group->reject_4way_hs_for_entropy = FALSE;
1788 wpa_group_init_gmk_and_counter(wpa_auth, group);
1789 wpa_gtk_update(wpa_auth, group);
1790 wpa_group_config_group_keys(wpa_auth, group);
1794 SM_STATE(WPA_PTK, AUTHENTICATION2)
1796 SM_ENTRY_MA(WPA_PTK, AUTHENTICATION2, wpa_ptk);
1798 wpa_group_ensure_init(sm->wpa_auth, sm->group);
1799 sm->ReAuthenticationRequest = FALSE;
1802 * Definition of ANonce selection in IEEE Std 802.11i-2004 is somewhat
1803 * ambiguous. The Authenticator state machine uses a counter that is
1804 * incremented by one for each 4-way handshake. However, the security
1805 * analysis of 4-way handshake points out that unpredictable nonces
1806 * help in preventing precomputation attacks. Instead of the state
1807 * machine definition, use an unpredictable nonce value here to provide
1808 * stronger protection against potential precomputation attacks.
1810 if (random_get_bytes(sm->ANonce, WPA_NONCE_LEN)) {
1811 wpa_printf(MSG_ERROR, "WPA: Failed to get random data for "
1813 sm->Disconnect = TRUE;
1816 wpa_hexdump(MSG_DEBUG, "WPA: Assign ANonce", sm->ANonce,
1818 /* IEEE 802.11i does not clear TimeoutCtr here, but this is more
1819 * logical place than INITIALIZE since AUTHENTICATION2 can be
1820 * re-entered on ReAuthenticationRequest without going through
1826 SM_STATE(WPA_PTK, INITPMK)
1828 u8 msk[2 * PMK_LEN];
1829 size_t len = 2 * PMK_LEN;
1831 SM_ENTRY_MA(WPA_PTK, INITPMK, wpa_ptk);
1832 #ifdef CONFIG_IEEE80211R
1834 #endif /* CONFIG_IEEE80211R */
1836 wpa_printf(MSG_DEBUG, "WPA: PMK from PMKSA cache");
1837 os_memcpy(sm->PMK, sm->pmksa->pmk, PMK_LEN);
1838 } else if (wpa_auth_get_msk(sm->wpa_auth, sm->addr, msk, &len) == 0) {
1839 wpa_printf(MSG_DEBUG, "WPA: PMK from EAPOL state machine "
1840 "(len=%lu)", (unsigned long) len);
1841 os_memcpy(sm->PMK, msk, PMK_LEN);
1842 #ifdef CONFIG_IEEE80211R
1843 if (len >= 2 * PMK_LEN) {
1844 os_memcpy(sm->xxkey, msk + PMK_LEN, PMK_LEN);
1845 sm->xxkey_len = PMK_LEN;
1847 #endif /* CONFIG_IEEE80211R */
1849 wpa_printf(MSG_DEBUG, "WPA: Could not get PMK, get_msk: %p",
1850 sm->wpa_auth->cb.get_msk);
1853 sm->req_replay_counter_used = 0;
1854 /* IEEE 802.11i does not set keyRun to FALSE, but not doing this
1855 * will break reauthentication since EAPOL state machines may not be
1856 * get into AUTHENTICATING state that clears keyRun before WPA state
1857 * machine enters AUTHENTICATION2 state and goes immediately to INITPMK
1858 * state and takes PMK from the previously used AAA Key. This will
1859 * eventually fail in 4-Way Handshake because Supplicant uses PMK
1860 * derived from the new AAA Key. Setting keyRun = FALSE here seems to
1861 * be good workaround for this issue. */
1862 wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_keyRun, 0);
1866 SM_STATE(WPA_PTK, INITPSK)
1869 SM_ENTRY_MA(WPA_PTK, INITPSK, wpa_ptk);
1870 psk = wpa_auth_get_psk(sm->wpa_auth, sm->addr, sm->p2p_dev_addr, NULL);
1872 os_memcpy(sm->PMK, psk, PMK_LEN);
1873 #ifdef CONFIG_IEEE80211R
1874 os_memcpy(sm->xxkey, psk, PMK_LEN);
1875 sm->xxkey_len = PMK_LEN;
1876 #endif /* CONFIG_IEEE80211R */
1878 sm->req_replay_counter_used = 0;
1882 SM_STATE(WPA_PTK, PTKSTART)
1884 u8 buf[2 + RSN_SELECTOR_LEN + PMKID_LEN], *pmkid = NULL;
1885 size_t pmkid_len = 0;
1887 SM_ENTRY_MA(WPA_PTK, PTKSTART, wpa_ptk);
1888 sm->PTKRequest = FALSE;
1889 sm->TimeoutEvt = FALSE;
1890 sm->alt_snonce_valid = FALSE;
1893 if (sm->TimeoutCtr > (int) dot11RSNAConfigPairwiseUpdateCount) {
1894 /* No point in sending the EAPOL-Key - we will disconnect
1895 * immediately following this. */
1899 wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
1900 "sending 1/4 msg of 4-Way Handshake");
1902 * TODO: Could add PMKID even with WPA2-PSK, but only if there is only
1903 * one possible PSK for this STA.
1905 if (sm->wpa == WPA_VERSION_WPA2 &&
1906 wpa_key_mgmt_wpa_ieee8021x(sm->wpa_key_mgmt) &&
1907 sm->wpa_key_mgmt != WPA_KEY_MGMT_OSEN) {
1909 pmkid_len = 2 + RSN_SELECTOR_LEN + PMKID_LEN;
1910 pmkid[0] = WLAN_EID_VENDOR_SPECIFIC;
1911 pmkid[1] = RSN_SELECTOR_LEN + PMKID_LEN;
1912 RSN_SELECTOR_PUT(&pmkid[2], RSN_KEY_DATA_PMKID);
1914 os_memcpy(&pmkid[2 + RSN_SELECTOR_LEN],
1915 sm->pmksa->pmkid, PMKID_LEN);
1916 } else if (wpa_key_mgmt_suite_b(sm->wpa_key_mgmt)) {
1917 /* No KCK available to derive PMKID */
1921 * Calculate PMKID since no PMKSA cache entry was
1922 * available with pre-calculated PMKID.
1924 rsn_pmkid(sm->PMK, PMK_LEN, sm->wpa_auth->addr,
1925 sm->addr, &pmkid[2 + RSN_SELECTOR_LEN],
1926 wpa_key_mgmt_sha256(sm->wpa_key_mgmt));
1929 wpa_send_eapol(sm->wpa_auth, sm,
1930 WPA_KEY_INFO_ACK | WPA_KEY_INFO_KEY_TYPE, NULL,
1931 sm->ANonce, pmkid, pmkid_len, 0, 0);
1935 static int wpa_derive_ptk(struct wpa_state_machine *sm, const u8 *snonce,
1936 const u8 *pmk, struct wpa_ptk *ptk)
1938 #ifdef CONFIG_IEEE80211R
1939 if (wpa_key_mgmt_ft(sm->wpa_key_mgmt))
1940 return wpa_auth_derive_ptk_ft(sm, pmk, ptk);
1941 #endif /* CONFIG_IEEE80211R */
1943 return wpa_pmk_to_ptk(pmk, PMK_LEN, "Pairwise key expansion",
1944 sm->wpa_auth->addr, sm->addr, sm->ANonce, snonce,
1945 ptk, sm->wpa_key_mgmt, sm->pairwise);
1949 SM_STATE(WPA_PTK, PTKCALCNEGOTIATING)
1953 const u8 *pmk = NULL;
1955 SM_ENTRY_MA(WPA_PTK, PTKCALCNEGOTIATING, wpa_ptk);
1956 sm->EAPOLKeyReceived = FALSE;
1957 sm->update_snonce = FALSE;
1959 /* WPA with IEEE 802.1X: use the derived PMK from EAP
1960 * WPA-PSK: iterate through possible PSKs and select the one matching
1963 if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt)) {
1964 pmk = wpa_auth_get_psk(sm->wpa_auth, sm->addr,
1965 sm->p2p_dev_addr, pmk);
1971 wpa_derive_ptk(sm, sm->SNonce, pmk, &PTK);
1973 if (wpa_verify_key_mic(sm->wpa_key_mgmt, &PTK,
1974 sm->last_rx_eapol_key,
1975 sm->last_rx_eapol_key_len) == 0) {
1980 if (!wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt))
1985 wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
1986 "invalid MIC in msg 2/4 of 4-Way Handshake");
1990 #ifdef CONFIG_IEEE80211R
1991 if (sm->wpa == WPA_VERSION_WPA2 && wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
1993 * Verify that PMKR1Name from EAPOL-Key message 2/4 matches
1994 * with the value we derived.
1996 if (os_memcmp_const(sm->sup_pmk_r1_name, sm->pmk_r1_name,
1997 WPA_PMK_NAME_LEN) != 0) {
1998 wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
1999 "PMKR1Name mismatch in FT 4-way "
2001 wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name from "
2003 sm->sup_pmk_r1_name, WPA_PMK_NAME_LEN);
2004 wpa_hexdump(MSG_DEBUG, "FT: Derived PMKR1Name",
2005 sm->pmk_r1_name, WPA_PMK_NAME_LEN);
2009 #endif /* CONFIG_IEEE80211R */
2011 sm->pending_1_of_4_timeout = 0;
2012 eloop_cancel_timeout(wpa_send_eapol_timeout, sm->wpa_auth, sm);
2014 if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt)) {
2015 /* PSK may have changed from the previous choice, so update
2016 * state machine data based on whatever PSK was selected here.
2018 os_memcpy(sm->PMK, pmk, PMK_LEN);
2021 sm->MICVerified = TRUE;
2023 os_memcpy(&sm->PTK, &PTK, sizeof(PTK));
2024 sm->PTK_valid = TRUE;
2028 SM_STATE(WPA_PTK, PTKCALCNEGOTIATING2)
2030 SM_ENTRY_MA(WPA_PTK, PTKCALCNEGOTIATING2, wpa_ptk);
2035 #ifdef CONFIG_IEEE80211W
2037 static int ieee80211w_kde_len(struct wpa_state_machine *sm)
2039 if (sm->mgmt_frame_prot) {
2041 len = wpa_cipher_key_len(sm->wpa_auth->conf.group_mgmt_cipher);
2042 return 2 + RSN_SELECTOR_LEN + WPA_IGTK_KDE_PREFIX_LEN + len;
2049 static u8 * ieee80211w_kde_add(struct wpa_state_machine *sm, u8 *pos)
2051 struct wpa_igtk_kde igtk;
2052 struct wpa_group *gsm = sm->group;
2053 u8 rsc[WPA_KEY_RSC_LEN];
2054 size_t len = wpa_cipher_key_len(sm->wpa_auth->conf.group_mgmt_cipher);
2056 if (!sm->mgmt_frame_prot)
2059 igtk.keyid[0] = gsm->GN_igtk;
2061 if (gsm->wpa_group_state != WPA_GROUP_SETKEYSDONE ||
2062 wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN_igtk, rsc) < 0)
2063 os_memset(igtk.pn, 0, sizeof(igtk.pn));
2065 os_memcpy(igtk.pn, rsc, sizeof(igtk.pn));
2066 os_memcpy(igtk.igtk, gsm->IGTK[gsm->GN_igtk - 4], len);
2067 if (sm->wpa_auth->conf.disable_gtk) {
2069 * Provide unique random IGTK to each STA to prevent use of
2072 if (random_get_bytes(igtk.igtk, len) < 0)
2075 pos = wpa_add_kde(pos, RSN_KEY_DATA_IGTK,
2076 (const u8 *) &igtk, WPA_IGTK_KDE_PREFIX_LEN + len,
2082 #else /* CONFIG_IEEE80211W */
2084 static int ieee80211w_kde_len(struct wpa_state_machine *sm)
2090 static u8 * ieee80211w_kde_add(struct wpa_state_machine *sm, u8 *pos)
2095 #endif /* CONFIG_IEEE80211W */
2098 SM_STATE(WPA_PTK, PTKINITNEGOTIATING)
2100 u8 rsc[WPA_KEY_RSC_LEN], *_rsc, *gtk, *kde, *pos, dummy_gtk[32];
2101 size_t gtk_len, kde_len;
2102 struct wpa_group *gsm = sm->group;
2104 int wpa_ie_len, secure, keyidx, encr = 0;
2106 SM_ENTRY_MA(WPA_PTK, PTKINITNEGOTIATING, wpa_ptk);
2107 sm->TimeoutEvt = FALSE;
2110 if (sm->TimeoutCtr > (int) dot11RSNAConfigPairwiseUpdateCount) {
2111 /* No point in sending the EAPOL-Key - we will disconnect
2112 * immediately following this. */
2116 /* Send EAPOL(1, 1, 1, Pair, P, RSC, ANonce, MIC(PTK), RSNIE, [MDIE],
2117 GTK[GN], IGTK, [FTIE], [TIE * 2])
2119 os_memset(rsc, 0, WPA_KEY_RSC_LEN);
2120 wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN, rsc);
2121 /* If FT is used, wpa_auth->wpa_ie includes both RSNIE and MDIE */
2122 wpa_ie = sm->wpa_auth->wpa_ie;
2123 wpa_ie_len = sm->wpa_auth->wpa_ie_len;
2124 if (sm->wpa == WPA_VERSION_WPA &&
2125 (sm->wpa_auth->conf.wpa & WPA_PROTO_RSN) &&
2126 wpa_ie_len > wpa_ie[1] + 2 && wpa_ie[0] == WLAN_EID_RSN) {
2127 /* WPA-only STA, remove RSN IE and possible MDIE */
2128 wpa_ie = wpa_ie + wpa_ie[1] + 2;
2129 if (wpa_ie[0] == WLAN_EID_MOBILITY_DOMAIN)
2130 wpa_ie = wpa_ie + wpa_ie[1] + 2;
2131 wpa_ie_len = wpa_ie[1] + 2;
2133 wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
2134 "sending 3/4 msg of 4-Way Handshake");
2135 if (sm->wpa == WPA_VERSION_WPA2) {
2136 /* WPA2 send GTK in the 4-way handshake */
2138 gtk = gsm->GTK[gsm->GN - 1];
2139 gtk_len = gsm->GTK_len;
2140 if (sm->wpa_auth->conf.disable_gtk) {
2142 * Provide unique random GTK to each STA to prevent use
2143 * of GTK in the BSS.
2145 if (random_get_bytes(dummy_gtk, gtk_len) < 0)
2153 /* WPA does not include GTK in msg 3/4 */
2159 if (sm->rx_eapol_key_secure) {
2161 * It looks like Windows 7 supplicant tries to use
2162 * Secure bit in msg 2/4 after having reported Michael
2163 * MIC failure and it then rejects the 4-way handshake
2164 * if msg 3/4 does not set Secure bit. Work around this
2165 * by setting the Secure bit here even in the case of
2166 * WPA if the supplicant used it first.
2168 wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
2169 "STA used Secure bit in WPA msg 2/4 - "
2170 "set Secure for 3/4 as workaround");
2175 kde_len = wpa_ie_len + ieee80211w_kde_len(sm);
2177 kde_len += 2 + RSN_SELECTOR_LEN + 2 + gtk_len;
2178 #ifdef CONFIG_IEEE80211R
2179 if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
2180 kde_len += 2 + PMKID_LEN; /* PMKR1Name into RSN IE */
2181 kde_len += 300; /* FTIE + 2 * TIE */
2183 #endif /* CONFIG_IEEE80211R */
2185 if (WPA_GET_BE32(sm->ip_addr) > 0)
2186 kde_len += 2 + RSN_SELECTOR_LEN + 3 * 4;
2187 #endif /* CONFIG_P2P */
2188 kde = os_malloc(kde_len);
2193 os_memcpy(pos, wpa_ie, wpa_ie_len);
2195 #ifdef CONFIG_IEEE80211R
2196 if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
2197 int res = wpa_insert_pmkid(kde, pos - kde, sm->pmk_r1_name);
2199 wpa_printf(MSG_ERROR, "FT: Failed to insert "
2200 "PMKR1Name into RSN IE in EAPOL-Key data");
2206 #endif /* CONFIG_IEEE80211R */
2209 hdr[0] = keyidx & 0x03;
2211 pos = wpa_add_kde(pos, RSN_KEY_DATA_GROUPKEY, hdr, 2,
2214 pos = ieee80211w_kde_add(sm, pos);
2216 #ifdef CONFIG_IEEE80211R
2217 if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
2219 struct wpa_auth_config *conf;
2221 conf = &sm->wpa_auth->conf;
2222 res = wpa_write_ftie(conf, conf->r0_key_holder,
2223 conf->r0_key_holder_len,
2224 NULL, NULL, pos, kde + kde_len - pos,
2227 wpa_printf(MSG_ERROR, "FT: Failed to insert FTIE "
2228 "into EAPOL-Key Key Data");
2234 /* TIE[ReassociationDeadline] (TU) */
2235 *pos++ = WLAN_EID_TIMEOUT_INTERVAL;
2237 *pos++ = WLAN_TIMEOUT_REASSOC_DEADLINE;
2238 WPA_PUT_LE32(pos, conf->reassociation_deadline);
2241 /* TIE[KeyLifetime] (seconds) */
2242 *pos++ = WLAN_EID_TIMEOUT_INTERVAL;
2244 *pos++ = WLAN_TIMEOUT_KEY_LIFETIME;
2245 WPA_PUT_LE32(pos, conf->r0_key_lifetime * 60);
2248 #endif /* CONFIG_IEEE80211R */
2250 if (WPA_GET_BE32(sm->ip_addr) > 0) {
2252 os_memcpy(addr, sm->ip_addr, 4);
2253 os_memcpy(addr + 4, sm->wpa_auth->conf.ip_addr_mask, 4);
2254 os_memcpy(addr + 8, sm->wpa_auth->conf.ip_addr_go, 4);
2255 pos = wpa_add_kde(pos, WFA_KEY_DATA_IP_ADDR_ALLOC,
2256 addr, sizeof(addr), NULL, 0);
2258 #endif /* CONFIG_P2P */
2260 wpa_send_eapol(sm->wpa_auth, sm,
2261 (secure ? WPA_KEY_INFO_SECURE : 0) | WPA_KEY_INFO_MIC |
2262 WPA_KEY_INFO_ACK | WPA_KEY_INFO_INSTALL |
2263 WPA_KEY_INFO_KEY_TYPE,
2264 _rsc, sm->ANonce, kde, pos - kde, keyidx, encr);
2269 SM_STATE(WPA_PTK, PTKINITDONE)
2271 SM_ENTRY_MA(WPA_PTK, PTKINITDONE, wpa_ptk);
2272 sm->EAPOLKeyReceived = FALSE;
2274 enum wpa_alg alg = wpa_cipher_to_alg(sm->pairwise);
2275 int klen = wpa_cipher_key_len(sm->pairwise);
2276 if (wpa_auth_set_key(sm->wpa_auth, 0, alg, sm->addr, 0,
2277 sm->PTK.tk, klen)) {
2278 wpa_sta_disconnect(sm->wpa_auth, sm->addr);
2281 /* FIX: MLME-SetProtection.Request(TA, Tx_Rx) */
2282 sm->pairwise_set = TRUE;
2284 if (sm->wpa_auth->conf.wpa_ptk_rekey) {
2285 eloop_cancel_timeout(wpa_rekey_ptk, sm->wpa_auth, sm);
2286 eloop_register_timeout(sm->wpa_auth->conf.
2287 wpa_ptk_rekey, 0, wpa_rekey_ptk,
2291 if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt)) {
2292 wpa_auth_set_eapol(sm->wpa_auth, sm->addr,
2293 WPA_EAPOL_authorized, 1);
2297 if (0 /* IBSS == TRUE */) {
2299 if (sm->keycount == 2) {
2300 wpa_auth_set_eapol(sm->wpa_auth, sm->addr,
2301 WPA_EAPOL_portValid, 1);
2304 wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_portValid,
2307 wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_keyAvailable, 0);
2308 wpa_auth_set_eapol(sm->wpa_auth, sm->addr, WPA_EAPOL_keyDone, 1);
2309 if (sm->wpa == WPA_VERSION_WPA)
2310 sm->PInitAKeys = TRUE;
2313 wpa_auth_vlogger(sm->wpa_auth, sm->addr, LOGGER_INFO,
2314 "pairwise key handshake completed (%s)",
2315 sm->wpa == WPA_VERSION_WPA ? "WPA" : "RSN");
2317 #ifdef CONFIG_IEEE80211R
2318 wpa_ft_push_pmk_r1(sm->wpa_auth, sm->addr);
2319 #endif /* CONFIG_IEEE80211R */
2325 struct wpa_authenticator *wpa_auth = sm->wpa_auth;
2328 SM_ENTER(WPA_PTK, INITIALIZE);
2329 else if (sm->Disconnect
2330 /* || FIX: dot11RSNAConfigSALifetime timeout */) {
2331 wpa_auth_logger(wpa_auth, sm->addr, LOGGER_DEBUG,
2332 "WPA_PTK: sm->Disconnect");
2333 SM_ENTER(WPA_PTK, DISCONNECT);
2335 else if (sm->DeauthenticationRequest)
2336 SM_ENTER(WPA_PTK, DISCONNECTED);
2337 else if (sm->AuthenticationRequest)
2338 SM_ENTER(WPA_PTK, AUTHENTICATION);
2339 else if (sm->ReAuthenticationRequest)
2340 SM_ENTER(WPA_PTK, AUTHENTICATION2);
2341 else if (sm->PTKRequest)
2342 SM_ENTER(WPA_PTK, PTKSTART);
2343 else switch (sm->wpa_ptk_state) {
2344 case WPA_PTK_INITIALIZE:
2346 case WPA_PTK_DISCONNECT:
2347 SM_ENTER(WPA_PTK, DISCONNECTED);
2349 case WPA_PTK_DISCONNECTED:
2350 SM_ENTER(WPA_PTK, INITIALIZE);
2352 case WPA_PTK_AUTHENTICATION:
2353 SM_ENTER(WPA_PTK, AUTHENTICATION2);
2355 case WPA_PTK_AUTHENTICATION2:
2356 if (wpa_key_mgmt_wpa_ieee8021x(sm->wpa_key_mgmt) &&
2357 wpa_auth_get_eapol(sm->wpa_auth, sm->addr,
2358 WPA_EAPOL_keyRun) > 0)
2359 SM_ENTER(WPA_PTK, INITPMK);
2360 else if (wpa_key_mgmt_wpa_psk(sm->wpa_key_mgmt)
2361 /* FIX: && 802.1X::keyRun */)
2362 SM_ENTER(WPA_PTK, INITPSK);
2364 case WPA_PTK_INITPMK:
2365 if (wpa_auth_get_eapol(sm->wpa_auth, sm->addr,
2366 WPA_EAPOL_keyAvailable) > 0)
2367 SM_ENTER(WPA_PTK, PTKSTART);
2369 wpa_auth->dot11RSNA4WayHandshakeFailures++;
2370 wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_INFO,
2371 "INITPMK - keyAvailable = false");
2372 SM_ENTER(WPA_PTK, DISCONNECT);
2375 case WPA_PTK_INITPSK:
2376 if (wpa_auth_get_psk(sm->wpa_auth, sm->addr, sm->p2p_dev_addr,
2378 SM_ENTER(WPA_PTK, PTKSTART);
2380 wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_INFO,
2381 "no PSK configured for the STA");
2382 wpa_auth->dot11RSNA4WayHandshakeFailures++;
2383 SM_ENTER(WPA_PTK, DISCONNECT);
2386 case WPA_PTK_PTKSTART:
2387 if (sm->EAPOLKeyReceived && !sm->EAPOLKeyRequest &&
2388 sm->EAPOLKeyPairwise)
2389 SM_ENTER(WPA_PTK, PTKCALCNEGOTIATING);
2390 else if (sm->TimeoutCtr >
2391 (int) dot11RSNAConfigPairwiseUpdateCount) {
2392 wpa_auth->dot11RSNA4WayHandshakeFailures++;
2393 wpa_auth_vlogger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
2394 "PTKSTART: Retry limit %d reached",
2395 dot11RSNAConfigPairwiseUpdateCount);
2396 SM_ENTER(WPA_PTK, DISCONNECT);
2397 } else if (sm->TimeoutEvt)
2398 SM_ENTER(WPA_PTK, PTKSTART);
2400 case WPA_PTK_PTKCALCNEGOTIATING:
2401 if (sm->MICVerified)
2402 SM_ENTER(WPA_PTK, PTKCALCNEGOTIATING2);
2403 else if (sm->EAPOLKeyReceived && !sm->EAPOLKeyRequest &&
2404 sm->EAPOLKeyPairwise)
2405 SM_ENTER(WPA_PTK, PTKCALCNEGOTIATING);
2406 else if (sm->TimeoutEvt)
2407 SM_ENTER(WPA_PTK, PTKSTART);
2409 case WPA_PTK_PTKCALCNEGOTIATING2:
2410 SM_ENTER(WPA_PTK, PTKINITNEGOTIATING);
2412 case WPA_PTK_PTKINITNEGOTIATING:
2413 if (sm->update_snonce)
2414 SM_ENTER(WPA_PTK, PTKCALCNEGOTIATING);
2415 else if (sm->EAPOLKeyReceived && !sm->EAPOLKeyRequest &&
2416 sm->EAPOLKeyPairwise && sm->MICVerified)
2417 SM_ENTER(WPA_PTK, PTKINITDONE);
2418 else if (sm->TimeoutCtr >
2419 (int) dot11RSNAConfigPairwiseUpdateCount) {
2420 wpa_auth->dot11RSNA4WayHandshakeFailures++;
2421 wpa_auth_vlogger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
2422 "PTKINITNEGOTIATING: Retry limit %d "
2424 dot11RSNAConfigPairwiseUpdateCount);
2425 SM_ENTER(WPA_PTK, DISCONNECT);
2426 } else if (sm->TimeoutEvt)
2427 SM_ENTER(WPA_PTK, PTKINITNEGOTIATING);
2429 case WPA_PTK_PTKINITDONE:
2435 SM_STATE(WPA_PTK_GROUP, IDLE)
2437 SM_ENTRY_MA(WPA_PTK_GROUP, IDLE, wpa_ptk_group);
2439 /* Init flag is not cleared here, so avoid busy
2440 * loop by claiming nothing changed. */
2441 sm->changed = FALSE;
2443 sm->GTimeoutCtr = 0;
2447 SM_STATE(WPA_PTK_GROUP, REKEYNEGOTIATING)
2449 u8 rsc[WPA_KEY_RSC_LEN];
2450 struct wpa_group *gsm = sm->group;
2452 u8 *kde_buf = NULL, *pos, hdr[2];
2454 u8 *gtk, dummy_gtk[32];
2456 SM_ENTRY_MA(WPA_PTK_GROUP, REKEYNEGOTIATING, wpa_ptk_group);
2459 if (sm->GTimeoutCtr > (int) dot11RSNAConfigGroupUpdateCount) {
2460 /* No point in sending the EAPOL-Key - we will disconnect
2461 * immediately following this. */
2465 if (sm->wpa == WPA_VERSION_WPA)
2466 sm->PInitAKeys = FALSE;
2467 sm->TimeoutEvt = FALSE;
2468 /* Send EAPOL(1, 1, 1, !Pair, G, RSC, GNonce, MIC(PTK), GTK[GN]) */
2469 os_memset(rsc, 0, WPA_KEY_RSC_LEN);
2470 if (gsm->wpa_group_state == WPA_GROUP_SETKEYSDONE)
2471 wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN, rsc);
2472 wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
2473 "sending 1/2 msg of Group Key Handshake");
2475 gtk = gsm->GTK[gsm->GN - 1];
2476 if (sm->wpa_auth->conf.disable_gtk) {
2478 * Provide unique random GTK to each STA to prevent use
2479 * of GTK in the BSS.
2481 if (random_get_bytes(dummy_gtk, gsm->GTK_len) < 0)
2485 if (sm->wpa == WPA_VERSION_WPA2) {
2486 kde_len = 2 + RSN_SELECTOR_LEN + 2 + gsm->GTK_len +
2487 ieee80211w_kde_len(sm);
2488 kde_buf = os_malloc(kde_len);
2489 if (kde_buf == NULL)
2492 kde = pos = kde_buf;
2493 hdr[0] = gsm->GN & 0x03;
2495 pos = wpa_add_kde(pos, RSN_KEY_DATA_GROUPKEY, hdr, 2,
2497 pos = ieee80211w_kde_add(sm, pos);
2498 kde_len = pos - kde;
2501 kde_len = gsm->GTK_len;
2504 wpa_send_eapol(sm->wpa_auth, sm,
2505 WPA_KEY_INFO_SECURE | WPA_KEY_INFO_MIC |
2507 (!sm->Pair ? WPA_KEY_INFO_INSTALL : 0),
2508 rsc, gsm->GNonce, kde, kde_len, gsm->GN, 1);
2514 SM_STATE(WPA_PTK_GROUP, REKEYESTABLISHED)
2516 SM_ENTRY_MA(WPA_PTK_GROUP, REKEYESTABLISHED, wpa_ptk_group);
2517 sm->EAPOLKeyReceived = FALSE;
2518 if (sm->GUpdateStationKeys)
2519 sm->group->GKeyDoneStations--;
2520 sm->GUpdateStationKeys = FALSE;
2521 sm->GTimeoutCtr = 0;
2522 /* FIX: MLME.SetProtection.Request(TA, Tx_Rx) */
2523 wpa_auth_vlogger(sm->wpa_auth, sm->addr, LOGGER_INFO,
2524 "group key handshake completed (%s)",
2525 sm->wpa == WPA_VERSION_WPA ? "WPA" : "RSN");
2530 SM_STATE(WPA_PTK_GROUP, KEYERROR)
2532 SM_ENTRY_MA(WPA_PTK_GROUP, KEYERROR, wpa_ptk_group);
2533 if (sm->GUpdateStationKeys)
2534 sm->group->GKeyDoneStations--;
2535 sm->GUpdateStationKeys = FALSE;
2536 sm->Disconnect = TRUE;
2540 SM_STEP(WPA_PTK_GROUP)
2542 if (sm->Init || sm->PtkGroupInit) {
2543 SM_ENTER(WPA_PTK_GROUP, IDLE);
2544 sm->PtkGroupInit = FALSE;
2545 } else switch (sm->wpa_ptk_group_state) {
2546 case WPA_PTK_GROUP_IDLE:
2547 if (sm->GUpdateStationKeys ||
2548 (sm->wpa == WPA_VERSION_WPA && sm->PInitAKeys))
2549 SM_ENTER(WPA_PTK_GROUP, REKEYNEGOTIATING);
2551 case WPA_PTK_GROUP_REKEYNEGOTIATING:
2552 if (sm->EAPOLKeyReceived && !sm->EAPOLKeyRequest &&
2553 !sm->EAPOLKeyPairwise && sm->MICVerified)
2554 SM_ENTER(WPA_PTK_GROUP, REKEYESTABLISHED);
2555 else if (sm->GTimeoutCtr >
2556 (int) dot11RSNAConfigGroupUpdateCount)
2557 SM_ENTER(WPA_PTK_GROUP, KEYERROR);
2558 else if (sm->TimeoutEvt)
2559 SM_ENTER(WPA_PTK_GROUP, REKEYNEGOTIATING);
2561 case WPA_PTK_GROUP_KEYERROR:
2562 SM_ENTER(WPA_PTK_GROUP, IDLE);
2564 case WPA_PTK_GROUP_REKEYESTABLISHED:
2565 SM_ENTER(WPA_PTK_GROUP, IDLE);
2571 static int wpa_gtk_update(struct wpa_authenticator *wpa_auth,
2572 struct wpa_group *group)
2576 os_memcpy(group->GNonce, group->Counter, WPA_NONCE_LEN);
2577 inc_byte_array(group->Counter, WPA_NONCE_LEN);
2578 if (wpa_gmk_to_gtk(group->GMK, "Group key expansion",
2579 wpa_auth->addr, group->GNonce,
2580 group->GTK[group->GN - 1], group->GTK_len) < 0)
2582 wpa_hexdump_key(MSG_DEBUG, "GTK",
2583 group->GTK[group->GN - 1], group->GTK_len);
2585 #ifdef CONFIG_IEEE80211W
2586 if (wpa_auth->conf.ieee80211w != NO_MGMT_FRAME_PROTECTION) {
2588 len = wpa_cipher_key_len(wpa_auth->conf.group_mgmt_cipher);
2589 os_memcpy(group->GNonce, group->Counter, WPA_NONCE_LEN);
2590 inc_byte_array(group->Counter, WPA_NONCE_LEN);
2591 if (wpa_gmk_to_gtk(group->GMK, "IGTK key expansion",
2592 wpa_auth->addr, group->GNonce,
2593 group->IGTK[group->GN_igtk - 4], len) < 0)
2595 wpa_hexdump_key(MSG_DEBUG, "IGTK",
2596 group->IGTK[group->GN_igtk - 4], len);
2598 #endif /* CONFIG_IEEE80211W */
2604 static void wpa_group_gtk_init(struct wpa_authenticator *wpa_auth,
2605 struct wpa_group *group)
2607 wpa_printf(MSG_DEBUG, "WPA: group state machine entering state "
2608 "GTK_INIT (VLAN-ID %d)", group->vlan_id);
2609 group->changed = FALSE; /* GInit is not cleared here; avoid loop */
2610 group->wpa_group_state = WPA_GROUP_GTK_INIT;
2613 os_memset(group->GTK, 0, sizeof(group->GTK));
2616 #ifdef CONFIG_IEEE80211W
2619 #endif /* CONFIG_IEEE80211W */
2620 /* GTK[GN] = CalcGTK() */
2621 wpa_gtk_update(wpa_auth, group);
2625 static int wpa_group_update_sta(struct wpa_state_machine *sm, void *ctx)
2627 if (ctx != NULL && ctx != sm->group)
2630 if (sm->wpa_ptk_state != WPA_PTK_PTKINITDONE) {
2631 wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
2632 "Not in PTKINITDONE; skip Group Key update");
2633 sm->GUpdateStationKeys = FALSE;
2636 if (sm->GUpdateStationKeys) {
2638 * This should not really happen, so add a debug log entry.
2639 * Since we clear the GKeyDoneStations before the loop, the
2640 * station needs to be counted here anyway.
2642 wpa_auth_logger(sm->wpa_auth, sm->addr, LOGGER_DEBUG,
2643 "GUpdateStationKeys was already set when "
2644 "marking station for GTK rekeying");
2647 /* Do not rekey GTK/IGTK when STA is in WNM-Sleep Mode */
2648 if (sm->is_wnmsleep)
2651 sm->group->GKeyDoneStations++;
2652 sm->GUpdateStationKeys = TRUE;
2660 /* update GTK when exiting WNM-Sleep Mode */
2661 void wpa_wnmsleep_rekey_gtk(struct wpa_state_machine *sm)
2663 if (sm == NULL || sm->is_wnmsleep)
2666 wpa_group_update_sta(sm, NULL);
2670 void wpa_set_wnmsleep(struct wpa_state_machine *sm, int flag)
2673 sm->is_wnmsleep = !!flag;
2677 int wpa_wnmsleep_gtk_subelem(struct wpa_state_machine *sm, u8 *pos)
2679 struct wpa_group *gsm = sm->group;
2684 * Sub-elem ID[1] | Length[1] | Key Info[2] | Key Length[1] | RSC[8] |
2687 *pos++ = WNM_SLEEP_SUBELEM_GTK;
2688 *pos++ = 11 + gsm->GTK_len;
2689 /* Key ID in B0-B1 of Key Info */
2690 WPA_PUT_LE16(pos, gsm->GN & 0x03);
2692 *pos++ = gsm->GTK_len;
2693 if (wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN, pos) != 0)
2696 os_memcpy(pos, gsm->GTK[gsm->GN - 1], gsm->GTK_len);
2697 pos += gsm->GTK_len;
2699 wpa_printf(MSG_DEBUG, "WNM: GTK Key ID %u in WNM-Sleep Mode exit",
2701 wpa_hexdump_key(MSG_DEBUG, "WNM: GTK in WNM-Sleep Mode exit",
2702 gsm->GTK[gsm->GN - 1], gsm->GTK_len);
2708 #ifdef CONFIG_IEEE80211W
2709 int wpa_wnmsleep_igtk_subelem(struct wpa_state_machine *sm, u8 *pos)
2711 struct wpa_group *gsm = sm->group;
2713 size_t len = wpa_cipher_key_len(sm->wpa_auth->conf.group_mgmt_cipher);
2717 * Sub-elem ID[1] | Length[1] | KeyID[2] | PN[6] | Key[16]
2719 *pos++ = WNM_SLEEP_SUBELEM_IGTK;
2720 *pos++ = 2 + 6 + len;
2721 WPA_PUT_LE16(pos, gsm->GN_igtk);
2723 if (wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN_igtk, pos) != 0)
2727 os_memcpy(pos, gsm->IGTK[gsm->GN_igtk - 4], len);
2730 wpa_printf(MSG_DEBUG, "WNM: IGTK Key ID %u in WNM-Sleep Mode exit",
2732 wpa_hexdump_key(MSG_DEBUG, "WNM: IGTK in WNM-Sleep Mode exit",
2733 gsm->IGTK[gsm->GN_igtk - 4], len);
2737 #endif /* CONFIG_IEEE80211W */
2738 #endif /* CONFIG_WNM */
2741 static void wpa_group_setkeys(struct wpa_authenticator *wpa_auth,
2742 struct wpa_group *group)
2746 wpa_printf(MSG_DEBUG, "WPA: group state machine entering state "
2747 "SETKEYS (VLAN-ID %d)", group->vlan_id);
2748 group->changed = TRUE;
2749 group->wpa_group_state = WPA_GROUP_SETKEYS;
2750 group->GTKReKey = FALSE;
2752 group->GM = group->GN;
2754 #ifdef CONFIG_IEEE80211W
2755 tmp = group->GM_igtk;
2756 group->GM_igtk = group->GN_igtk;
2757 group->GN_igtk = tmp;
2758 #endif /* CONFIG_IEEE80211W */
2759 /* "GKeyDoneStations = GNoStations" is done in more robust way by
2760 * counting the STAs that are marked with GUpdateStationKeys instead of
2761 * including all STAs that could be in not-yet-completed state. */
2762 wpa_gtk_update(wpa_auth, group);
2764 if (group->GKeyDoneStations) {
2765 wpa_printf(MSG_DEBUG, "wpa_group_setkeys: Unexpected "
2766 "GKeyDoneStations=%d when starting new GTK rekey",
2767 group->GKeyDoneStations);
2768 group->GKeyDoneStations = 0;
2770 wpa_auth_for_each_sta(wpa_auth, wpa_group_update_sta, group);
2771 wpa_printf(MSG_DEBUG, "wpa_group_setkeys: GKeyDoneStations=%d",
2772 group->GKeyDoneStations);
2776 static int wpa_group_config_group_keys(struct wpa_authenticator *wpa_auth,
2777 struct wpa_group *group)
2781 if (wpa_auth_set_key(wpa_auth, group->vlan_id,
2782 wpa_cipher_to_alg(wpa_auth->conf.wpa_group),
2783 broadcast_ether_addr, group->GN,
2784 group->GTK[group->GN - 1], group->GTK_len) < 0)
2787 #ifdef CONFIG_IEEE80211W
2788 if (wpa_auth->conf.ieee80211w != NO_MGMT_FRAME_PROTECTION) {
2792 alg = wpa_cipher_to_alg(wpa_auth->conf.group_mgmt_cipher);
2793 len = wpa_cipher_key_len(wpa_auth->conf.group_mgmt_cipher);
2796 wpa_auth_set_key(wpa_auth, group->vlan_id, alg,
2797 broadcast_ether_addr, group->GN_igtk,
2798 group->IGTK[group->GN_igtk - 4], len) < 0)
2801 #endif /* CONFIG_IEEE80211W */
2807 static int wpa_group_disconnect_cb(struct wpa_state_machine *sm, void *ctx)
2809 if (sm->group == ctx) {
2810 wpa_printf(MSG_DEBUG, "WPA: Mark STA " MACSTR
2811 " for discconnection due to fatal failure",
2813 sm->Disconnect = TRUE;
2820 static void wpa_group_fatal_failure(struct wpa_authenticator *wpa_auth,
2821 struct wpa_group *group)
2823 wpa_printf(MSG_DEBUG, "WPA: group state machine entering state FATAL_FAILURE");
2824 group->changed = TRUE;
2825 group->wpa_group_state = WPA_GROUP_FATAL_FAILURE;
2826 wpa_auth_for_each_sta(wpa_auth, wpa_group_disconnect_cb, group);
2830 static int wpa_group_setkeysdone(struct wpa_authenticator *wpa_auth,
2831 struct wpa_group *group)
2833 wpa_printf(MSG_DEBUG, "WPA: group state machine entering state "
2834 "SETKEYSDONE (VLAN-ID %d)", group->vlan_id);
2835 group->changed = TRUE;
2836 group->wpa_group_state = WPA_GROUP_SETKEYSDONE;
2838 if (wpa_group_config_group_keys(wpa_auth, group) < 0) {
2839 wpa_group_fatal_failure(wpa_auth, group);
2847 static void wpa_group_sm_step(struct wpa_authenticator *wpa_auth,
2848 struct wpa_group *group)
2851 wpa_group_gtk_init(wpa_auth, group);
2852 } else if (group->wpa_group_state == WPA_GROUP_FATAL_FAILURE) {
2853 /* Do not allow group operations */
2854 } else if (group->wpa_group_state == WPA_GROUP_GTK_INIT &&
2855 group->GTKAuthenticator) {
2856 wpa_group_setkeysdone(wpa_auth, group);
2857 } else if (group->wpa_group_state == WPA_GROUP_SETKEYSDONE &&
2859 wpa_group_setkeys(wpa_auth, group);
2860 } else if (group->wpa_group_state == WPA_GROUP_SETKEYS) {
2861 if (group->GKeyDoneStations == 0)
2862 wpa_group_setkeysdone(wpa_auth, group);
2863 else if (group->GTKReKey)
2864 wpa_group_setkeys(wpa_auth, group);
2869 static int wpa_sm_step(struct wpa_state_machine *sm)
2874 if (sm->in_step_loop) {
2875 /* This should not happen, but if it does, make sure we do not
2876 * end up freeing the state machine too early by exiting the
2877 * recursive call. */
2878 wpa_printf(MSG_ERROR, "WPA: wpa_sm_step() called recursively");
2882 sm->in_step_loop = 1;
2884 if (sm->pending_deinit)
2887 sm->changed = FALSE;
2888 sm->wpa_auth->group->changed = FALSE;
2890 SM_STEP_RUN(WPA_PTK);
2891 if (sm->pending_deinit)
2893 SM_STEP_RUN(WPA_PTK_GROUP);
2894 if (sm->pending_deinit)
2896 wpa_group_sm_step(sm->wpa_auth, sm->group);
2897 } while (sm->changed || sm->wpa_auth->group->changed);
2898 sm->in_step_loop = 0;
2900 if (sm->pending_deinit) {
2901 wpa_printf(MSG_DEBUG, "WPA: Completing pending STA state "
2902 "machine deinit for " MACSTR, MAC2STR(sm->addr));
2903 wpa_free_sta_sm(sm);
2910 static void wpa_sm_call_step(void *eloop_ctx, void *timeout_ctx)
2912 struct wpa_state_machine *sm = eloop_ctx;
2917 void wpa_auth_sm_notify(struct wpa_state_machine *sm)
2921 eloop_register_timeout(0, 0, wpa_sm_call_step, sm, NULL);
2925 void wpa_gtk_rekey(struct wpa_authenticator *wpa_auth)
2928 struct wpa_group *group;
2930 if (wpa_auth == NULL)
2933 group = wpa_auth->group;
2935 for (i = 0; i < 2; i++) {
2937 group->GM = group->GN;
2939 #ifdef CONFIG_IEEE80211W
2940 tmp = group->GM_igtk;
2941 group->GM_igtk = group->GN_igtk;
2942 group->GN_igtk = tmp;
2943 #endif /* CONFIG_IEEE80211W */
2944 wpa_gtk_update(wpa_auth, group);
2945 wpa_group_config_group_keys(wpa_auth, group);
2950 static const char * wpa_bool_txt(int bool)
2952 return bool ? "TRUE" : "FALSE";
2956 #define RSN_SUITE "%02x-%02x-%02x-%d"
2957 #define RSN_SUITE_ARG(s) \
2958 ((s) >> 24) & 0xff, ((s) >> 16) & 0xff, ((s) >> 8) & 0xff, (s) & 0xff
2960 int wpa_get_mib(struct wpa_authenticator *wpa_auth, char *buf, size_t buflen)
2963 char pmkid_txt[PMKID_LEN * 2 + 1];
2964 #ifdef CONFIG_RSN_PREAUTH
2965 const int preauth = 1;
2966 #else /* CONFIG_RSN_PREAUTH */
2967 const int preauth = 0;
2968 #endif /* CONFIG_RSN_PREAUTH */
2970 if (wpa_auth == NULL)
2973 ret = os_snprintf(buf + len, buflen - len,
2974 "dot11RSNAOptionImplemented=TRUE\n"
2975 "dot11RSNAPreauthenticationImplemented=%s\n"
2976 "dot11RSNAEnabled=%s\n"
2977 "dot11RSNAPreauthenticationEnabled=%s\n",
2978 wpa_bool_txt(preauth),
2979 wpa_bool_txt(wpa_auth->conf.wpa & WPA_PROTO_RSN),
2980 wpa_bool_txt(wpa_auth->conf.rsn_preauth));
2981 if (os_snprintf_error(buflen - len, ret))
2985 wpa_snprintf_hex(pmkid_txt, sizeof(pmkid_txt),
2986 wpa_auth->dot11RSNAPMKIDUsed, PMKID_LEN);
2989 buf + len, buflen - len,
2990 "dot11RSNAConfigVersion=%u\n"
2991 "dot11RSNAConfigPairwiseKeysSupported=9999\n"
2992 /* FIX: dot11RSNAConfigGroupCipher */
2993 /* FIX: dot11RSNAConfigGroupRekeyMethod */
2994 /* FIX: dot11RSNAConfigGroupRekeyTime */
2995 /* FIX: dot11RSNAConfigGroupRekeyPackets */
2996 "dot11RSNAConfigGroupRekeyStrict=%u\n"
2997 "dot11RSNAConfigGroupUpdateCount=%u\n"
2998 "dot11RSNAConfigPairwiseUpdateCount=%u\n"
2999 "dot11RSNAConfigGroupCipherSize=%u\n"
3000 "dot11RSNAConfigPMKLifetime=%u\n"
3001 "dot11RSNAConfigPMKReauthThreshold=%u\n"
3002 "dot11RSNAConfigNumberOfPTKSAReplayCounters=0\n"
3003 "dot11RSNAConfigSATimeout=%u\n"
3004 "dot11RSNAAuthenticationSuiteSelected=" RSN_SUITE "\n"
3005 "dot11RSNAPairwiseCipherSelected=" RSN_SUITE "\n"
3006 "dot11RSNAGroupCipherSelected=" RSN_SUITE "\n"
3007 "dot11RSNAPMKIDUsed=%s\n"
3008 "dot11RSNAAuthenticationSuiteRequested=" RSN_SUITE "\n"
3009 "dot11RSNAPairwiseCipherRequested=" RSN_SUITE "\n"
3010 "dot11RSNAGroupCipherRequested=" RSN_SUITE "\n"
3011 "dot11RSNATKIPCounterMeasuresInvoked=%u\n"
3012 "dot11RSNA4WayHandshakeFailures=%u\n"
3013 "dot11RSNAConfigNumberOfGTKSAReplayCounters=0\n",
3015 !!wpa_auth->conf.wpa_strict_rekey,
3016 dot11RSNAConfigGroupUpdateCount,
3017 dot11RSNAConfigPairwiseUpdateCount,
3018 wpa_cipher_key_len(wpa_auth->conf.wpa_group) * 8,
3019 dot11RSNAConfigPMKLifetime,
3020 dot11RSNAConfigPMKReauthThreshold,
3021 dot11RSNAConfigSATimeout,
3022 RSN_SUITE_ARG(wpa_auth->dot11RSNAAuthenticationSuiteSelected),
3023 RSN_SUITE_ARG(wpa_auth->dot11RSNAPairwiseCipherSelected),
3024 RSN_SUITE_ARG(wpa_auth->dot11RSNAGroupCipherSelected),
3026 RSN_SUITE_ARG(wpa_auth->dot11RSNAAuthenticationSuiteRequested),
3027 RSN_SUITE_ARG(wpa_auth->dot11RSNAPairwiseCipherRequested),
3028 RSN_SUITE_ARG(wpa_auth->dot11RSNAGroupCipherRequested),
3029 wpa_auth->dot11RSNATKIPCounterMeasuresInvoked,
3030 wpa_auth->dot11RSNA4WayHandshakeFailures);
3031 if (os_snprintf_error(buflen - len, ret))
3035 /* TODO: dot11RSNAConfigPairwiseCiphersTable */
3036 /* TODO: dot11RSNAConfigAuthenticationSuitesTable */
3039 ret = os_snprintf(buf + len, buflen - len, "hostapdWPAGroupState=%d\n",
3040 wpa_auth->group->wpa_group_state);
3041 if (os_snprintf_error(buflen - len, ret))
3049 int wpa_get_mib_sta(struct wpa_state_machine *sm, char *buf, size_t buflen)
3057 /* TODO: FF-FF-FF-FF-FF-FF entry for broadcast/multicast stats */
3059 /* dot11RSNAStatsEntry */
3061 pairwise = wpa_cipher_to_suite(sm->wpa == WPA_VERSION_WPA2 ?
3062 WPA_PROTO_RSN : WPA_PROTO_WPA,
3068 buf + len, buflen - len,
3069 /* TODO: dot11RSNAStatsIndex */
3070 "dot11RSNAStatsSTAAddress=" MACSTR "\n"
3071 "dot11RSNAStatsVersion=1\n"
3072 "dot11RSNAStatsSelectedPairwiseCipher=" RSN_SUITE "\n"
3073 /* TODO: dot11RSNAStatsTKIPICVErrors */
3074 "dot11RSNAStatsTKIPLocalMICFailures=%u\n"
3075 "dot11RSNAStatsTKIPRemoteMICFailures=%u\n"
3076 /* TODO: dot11RSNAStatsCCMPReplays */
3077 /* TODO: dot11RSNAStatsCCMPDecryptErrors */
3078 /* TODO: dot11RSNAStatsTKIPReplays */,
3080 RSN_SUITE_ARG(pairwise),
3081 sm->dot11RSNAStatsTKIPLocalMICFailures,
3082 sm->dot11RSNAStatsTKIPRemoteMICFailures);
3083 if (os_snprintf_error(buflen - len, ret))
3088 ret = os_snprintf(buf + len, buflen - len,
3089 "hostapdWPAPTKState=%d\n"
3090 "hostapdWPAPTKGroupState=%d\n",
3092 sm->wpa_ptk_group_state);
3093 if (os_snprintf_error(buflen - len, ret))
3101 void wpa_auth_countermeasures_start(struct wpa_authenticator *wpa_auth)
3104 wpa_auth->dot11RSNATKIPCounterMeasuresInvoked++;
3108 int wpa_auth_pairwise_set(struct wpa_state_machine *sm)
3110 return sm && sm->pairwise_set;
3114 int wpa_auth_get_pairwise(struct wpa_state_machine *sm)
3116 return sm->pairwise;
3120 int wpa_auth_sta_key_mgmt(struct wpa_state_machine *sm)
3124 return sm->wpa_key_mgmt;
3128 int wpa_auth_sta_wpa_version(struct wpa_state_machine *sm)
3136 int wpa_auth_sta_clear_pmksa(struct wpa_state_machine *sm,
3137 struct rsn_pmksa_cache_entry *entry)
3139 if (sm == NULL || sm->pmksa != entry)
3146 struct rsn_pmksa_cache_entry *
3147 wpa_auth_sta_get_pmksa(struct wpa_state_machine *sm)
3149 return sm ? sm->pmksa : NULL;
3153 void wpa_auth_sta_local_mic_failure_report(struct wpa_state_machine *sm)
3156 sm->dot11RSNAStatsTKIPLocalMICFailures++;
3160 const u8 * wpa_auth_get_wpa_ie(struct wpa_authenticator *wpa_auth, size_t *len)
3162 if (wpa_auth == NULL)
3164 *len = wpa_auth->wpa_ie_len;
3165 return wpa_auth->wpa_ie;
3169 int wpa_auth_pmksa_add(struct wpa_state_machine *sm, const u8 *pmk,
3170 int session_timeout, struct eapol_state_machine *eapol)
3172 if (sm == NULL || sm->wpa != WPA_VERSION_WPA2 ||
3173 sm->wpa_auth->conf.disable_pmksa_caching)
3176 if (pmksa_cache_auth_add(sm->wpa_auth->pmksa, pmk, PMK_LEN,
3177 sm->PTK.kck, sm->PTK.kck_len,
3178 sm->wpa_auth->addr, sm->addr, session_timeout,
3179 eapol, sm->wpa_key_mgmt))
3186 int wpa_auth_pmksa_add_preauth(struct wpa_authenticator *wpa_auth,
3187 const u8 *pmk, size_t len, const u8 *sta_addr,
3188 int session_timeout,
3189 struct eapol_state_machine *eapol)
3191 if (wpa_auth == NULL)
3194 if (pmksa_cache_auth_add(wpa_auth->pmksa, pmk, len,
3197 sta_addr, session_timeout, eapol,
3198 WPA_KEY_MGMT_IEEE8021X))
3205 int wpa_auth_pmksa_add_sae(struct wpa_authenticator *wpa_auth, const u8 *addr,
3208 if (wpa_auth->conf.disable_pmksa_caching)
3211 if (pmksa_cache_auth_add(wpa_auth->pmksa, pmk, PMK_LEN,
3213 wpa_auth->addr, addr, 0, NULL,
3221 void wpa_auth_pmksa_remove(struct wpa_authenticator *wpa_auth,
3224 struct rsn_pmksa_cache_entry *pmksa;
3226 if (wpa_auth == NULL || wpa_auth->pmksa == NULL)
3228 pmksa = pmksa_cache_auth_get(wpa_auth->pmksa, sta_addr, NULL);
3230 wpa_printf(MSG_DEBUG, "WPA: Remove PMKSA cache entry for "
3231 MACSTR " based on request", MAC2STR(sta_addr));
3232 pmksa_cache_free_entry(wpa_auth->pmksa, pmksa);
3237 static struct wpa_group *
3238 wpa_auth_add_group(struct wpa_authenticator *wpa_auth, int vlan_id)
3240 struct wpa_group *group;
3242 if (wpa_auth == NULL || wpa_auth->group == NULL)
3245 wpa_printf(MSG_DEBUG, "WPA: Add group state machine for VLAN-ID %d",
3247 group = wpa_group_init(wpa_auth, vlan_id, 0);
3251 group->next = wpa_auth->group->next;
3252 wpa_auth->group->next = group;
3258 int wpa_auth_sta_set_vlan(struct wpa_state_machine *sm, int vlan_id)
3260 struct wpa_group *group;
3262 if (sm == NULL || sm->wpa_auth == NULL)
3265 group = sm->wpa_auth->group;
3267 if (group->vlan_id == vlan_id)
3269 group = group->next;
3272 if (group == NULL) {
3273 group = wpa_auth_add_group(sm->wpa_auth, vlan_id);
3278 if (sm->group == group)
3281 if (group->wpa_group_state == WPA_GROUP_FATAL_FAILURE)
3284 wpa_printf(MSG_DEBUG, "WPA: Moving STA " MACSTR " to use group state "
3285 "machine for VLAN ID %d", MAC2STR(sm->addr), vlan_id);
3292 void wpa_auth_eapol_key_tx_status(struct wpa_authenticator *wpa_auth,
3293 struct wpa_state_machine *sm, int ack)
3295 if (wpa_auth == NULL || sm == NULL)
3297 wpa_printf(MSG_DEBUG, "WPA: EAPOL-Key TX status for STA " MACSTR
3298 " ack=%d", MAC2STR(sm->addr), ack);
3299 if (sm->pending_1_of_4_timeout && ack) {
3301 * Some deployed supplicant implementations update their SNonce
3302 * for each EAPOL-Key 2/4 message even within the same 4-way
3303 * handshake and then fail to use the first SNonce when
3304 * deriving the PTK. This results in unsuccessful 4-way
3305 * handshake whenever the relatively short initial timeout is
3306 * reached and EAPOL-Key 1/4 is retransmitted. Try to work
3307 * around this by increasing the timeout now that we know that
3308 * the station has received the frame.
3310 int timeout_ms = eapol_key_timeout_subseq;
3311 wpa_printf(MSG_DEBUG, "WPA: Increase initial EAPOL-Key 1/4 "
3312 "timeout by %u ms because of acknowledged frame",
3314 eloop_cancel_timeout(wpa_send_eapol_timeout, wpa_auth, sm);
3315 eloop_register_timeout(timeout_ms / 1000,
3316 (timeout_ms % 1000) * 1000,
3317 wpa_send_eapol_timeout, wpa_auth, sm);
3322 int wpa_auth_uses_sae(struct wpa_state_machine *sm)
3326 return wpa_key_mgmt_sae(sm->wpa_key_mgmt);
3330 int wpa_auth_uses_ft_sae(struct wpa_state_machine *sm)
3334 return sm->wpa_key_mgmt == WPA_KEY_MGMT_FT_SAE;
3339 int wpa_auth_get_ip_addr(struct wpa_state_machine *sm, u8 *addr)
3341 if (sm == NULL || WPA_GET_BE32(sm->ip_addr) == 0)
3343 os_memcpy(addr, sm->ip_addr, 4);
3346 #endif /* CONFIG_P2P */
3349 int wpa_auth_radius_das_disconnect_pmksa(struct wpa_authenticator *wpa_auth,
3350 struct radius_das_attrs *attr)
3352 return pmksa_cache_auth_radius_das_disconnect(wpa_auth->pmksa, attr);