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.h"
17 #include "crypto/aes_wrap.h"
18 #include "crypto/aes_siv.h"
19 #include "crypto/crypto.h"
20 #include "crypto/sha1.h"
21 #include "crypto/sha256.h"
22 #include "crypto/random.h"
23 #include "eapol_auth/eapol_auth_sm.h"
24 #include "ap_config.h"
25 #include "ieee802_11.h"
27 #include "pmksa_cache_auth.h"
28 #include "wpa_auth_i.h"
29 #include "wpa_auth_ie.h"
31 #define STATE_MACHINE_DATA struct wpa_state_machine
32 #define STATE_MACHINE_DEBUG_PREFIX "WPA"
33 #define STATE_MACHINE_ADDR sm->addr
36 static void wpa_send_eapol_timeout(void *eloop_ctx
, void *timeout_ctx
);
37 static int wpa_sm_step(struct wpa_state_machine
*sm
);
38 static int wpa_verify_key_mic(int akmp
, struct wpa_ptk
*PTK
, u8
*data
,
41 static int wpa_aead_decrypt(struct wpa_state_machine
*sm
, struct wpa_ptk
*ptk
,
42 u8
*buf
, size_t buf_len
, u16
*_key_data_len
);
43 static struct wpabuf
* fils_prepare_plainbuf(struct wpa_state_machine
*sm
,
44 const struct wpabuf
*hlp
);
45 #endif /* CONFIG_FILS */
46 static void wpa_sm_call_step(void *eloop_ctx
, void *timeout_ctx
);
47 static void wpa_group_sm_step(struct wpa_authenticator
*wpa_auth
,
48 struct wpa_group
*group
);
49 static void wpa_request_new_ptk(struct wpa_state_machine
*sm
);
50 static int wpa_gtk_update(struct wpa_authenticator
*wpa_auth
,
51 struct wpa_group
*group
);
52 static int wpa_group_config_group_keys(struct wpa_authenticator
*wpa_auth
,
53 struct wpa_group
*group
);
54 static int wpa_derive_ptk(struct wpa_state_machine
*sm
, const u8
*snonce
,
55 const u8
*pmk
, unsigned int pmk_len
,
57 static void wpa_group_free(struct wpa_authenticator
*wpa_auth
,
58 struct wpa_group
*group
);
59 static void wpa_group_get(struct wpa_authenticator
*wpa_auth
,
60 struct wpa_group
*group
);
61 static void wpa_group_put(struct wpa_authenticator
*wpa_auth
,
62 struct wpa_group
*group
);
63 static u8
* ieee80211w_kde_add(struct wpa_state_machine
*sm
, u8
*pos
);
65 static const u32 eapol_key_timeout_first
= 100; /* ms */
66 static const u32 eapol_key_timeout_subseq
= 1000; /* ms */
67 static const u32 eapol_key_timeout_first_group
= 500; /* ms */
69 /* TODO: make these configurable */
70 static const int dot11RSNAConfigPMKLifetime
= 43200;
71 static const int dot11RSNAConfigPMKReauthThreshold
= 70;
72 static const int dot11RSNAConfigSATimeout
= 60;
75 static inline int wpa_auth_mic_failure_report(
76 struct wpa_authenticator
*wpa_auth
, const u8
*addr
)
78 if (wpa_auth
->cb
->mic_failure_report
)
79 return wpa_auth
->cb
->mic_failure_report(wpa_auth
->cb_ctx
, addr
);
84 static inline void wpa_auth_psk_failure_report(
85 struct wpa_authenticator
*wpa_auth
, const u8
*addr
)
87 if (wpa_auth
->cb
->psk_failure_report
)
88 wpa_auth
->cb
->psk_failure_report(wpa_auth
->cb_ctx
, addr
);
92 static inline void wpa_auth_set_eapol(struct wpa_authenticator
*wpa_auth
,
93 const u8
*addr
, wpa_eapol_variable var
,
96 if (wpa_auth
->cb
->set_eapol
)
97 wpa_auth
->cb
->set_eapol(wpa_auth
->cb_ctx
, addr
, var
, value
);
101 static inline int wpa_auth_get_eapol(struct wpa_authenticator
*wpa_auth
,
102 const u8
*addr
, wpa_eapol_variable var
)
104 if (wpa_auth
->cb
->get_eapol
== NULL
)
106 return wpa_auth
->cb
->get_eapol(wpa_auth
->cb_ctx
, addr
, var
);
110 static inline const u8
* wpa_auth_get_psk(struct wpa_authenticator
*wpa_auth
,
112 const u8
*p2p_dev_addr
,
115 if (wpa_auth
->cb
->get_psk
== NULL
)
117 return wpa_auth
->cb
->get_psk(wpa_auth
->cb_ctx
, addr
, p2p_dev_addr
,
122 static inline int wpa_auth_get_msk(struct wpa_authenticator
*wpa_auth
,
123 const u8
*addr
, u8
*msk
, size_t *len
)
125 if (wpa_auth
->cb
->get_msk
== NULL
)
127 return wpa_auth
->cb
->get_msk(wpa_auth
->cb_ctx
, addr
, msk
, len
);
131 static inline int wpa_auth_set_key(struct wpa_authenticator
*wpa_auth
,
133 enum wpa_alg alg
, const u8
*addr
, int idx
,
134 u8
*key
, size_t key_len
)
136 if (wpa_auth
->cb
->set_key
== NULL
)
138 return wpa_auth
->cb
->set_key(wpa_auth
->cb_ctx
, vlan_id
, alg
, addr
, idx
,
143 static inline int wpa_auth_get_seqnum(struct wpa_authenticator
*wpa_auth
,
144 const u8
*addr
, int idx
, u8
*seq
)
146 if (wpa_auth
->cb
->get_seqnum
== NULL
)
148 return wpa_auth
->cb
->get_seqnum(wpa_auth
->cb_ctx
, addr
, idx
, seq
);
153 wpa_auth_send_eapol(struct wpa_authenticator
*wpa_auth
, const u8
*addr
,
154 const u8
*data
, size_t data_len
, int encrypt
)
156 if (wpa_auth
->cb
->send_eapol
== NULL
)
158 return wpa_auth
->cb
->send_eapol(wpa_auth
->cb_ctx
, addr
, data
, data_len
,
164 static inline int wpa_auth_start_ampe(struct wpa_authenticator
*wpa_auth
,
167 if (wpa_auth
->cb
->start_ampe
== NULL
)
169 return wpa_auth
->cb
->start_ampe(wpa_auth
->cb_ctx
, addr
);
171 #endif /* CONFIG_MESH */
174 int wpa_auth_for_each_sta(struct wpa_authenticator
*wpa_auth
,
175 int (*cb
)(struct wpa_state_machine
*sm
, void *ctx
),
178 if (wpa_auth
->cb
->for_each_sta
== NULL
)
180 return wpa_auth
->cb
->for_each_sta(wpa_auth
->cb_ctx
, cb
, cb_ctx
);
184 int wpa_auth_for_each_auth(struct wpa_authenticator
*wpa_auth
,
185 int (*cb
)(struct wpa_authenticator
*a
, void *ctx
),
188 if (wpa_auth
->cb
->for_each_auth
== NULL
)
190 return wpa_auth
->cb
->for_each_auth(wpa_auth
->cb_ctx
, cb
, cb_ctx
);
194 void wpa_auth_logger(struct wpa_authenticator
*wpa_auth
, const u8
*addr
,
195 logger_level level
, const char *txt
)
197 if (wpa_auth
->cb
->logger
== NULL
)
199 wpa_auth
->cb
->logger(wpa_auth
->cb_ctx
, addr
, level
, txt
);
203 void wpa_auth_vlogger(struct wpa_authenticator
*wpa_auth
, const u8
*addr
,
204 logger_level level
, const char *fmt
, ...)
210 if (wpa_auth
->cb
->logger
== NULL
)
213 maxlen
= os_strlen(fmt
) + 100;
214 format
= os_malloc(maxlen
);
219 vsnprintf(format
, maxlen
, fmt
, ap
);
222 wpa_auth_logger(wpa_auth
, addr
, level
, format
);
228 static void wpa_sta_disconnect(struct wpa_authenticator
*wpa_auth
,
231 if (wpa_auth
->cb
->disconnect
== NULL
)
233 wpa_printf(MSG_DEBUG
, "wpa_sta_disconnect STA " MACSTR
, MAC2STR(addr
));
234 wpa_auth
->cb
->disconnect(wpa_auth
->cb_ctx
, addr
,
235 WLAN_REASON_PREV_AUTH_NOT_VALID
);
239 static int wpa_use_aes_cmac(struct wpa_state_machine
*sm
)
242 #ifdef CONFIG_IEEE80211R_AP
243 if (wpa_key_mgmt_ft(sm
->wpa_key_mgmt
))
245 #endif /* CONFIG_IEEE80211R_AP */
246 #ifdef CONFIG_IEEE80211W
247 if (wpa_key_mgmt_sha256(sm
->wpa_key_mgmt
))
249 #endif /* CONFIG_IEEE80211W */
250 if (sm
->wpa_key_mgmt
== WPA_KEY_MGMT_OSEN
)
256 static void wpa_rekey_gmk(void *eloop_ctx
, void *timeout_ctx
)
258 struct wpa_authenticator
*wpa_auth
= eloop_ctx
;
260 if (random_get_bytes(wpa_auth
->group
->GMK
, WPA_GMK_LEN
)) {
261 wpa_printf(MSG_ERROR
, "Failed to get random data for WPA "
264 wpa_auth_logger(wpa_auth
, NULL
, LOGGER_DEBUG
, "GMK rekeyd");
265 wpa_hexdump_key(MSG_DEBUG
, "GMK",
266 wpa_auth
->group
->GMK
, WPA_GMK_LEN
);
269 if (wpa_auth
->conf
.wpa_gmk_rekey
) {
270 eloop_register_timeout(wpa_auth
->conf
.wpa_gmk_rekey
, 0,
271 wpa_rekey_gmk
, wpa_auth
, NULL
);
276 static void wpa_rekey_gtk(void *eloop_ctx
, void *timeout_ctx
)
278 struct wpa_authenticator
*wpa_auth
= eloop_ctx
;
279 struct wpa_group
*group
, *next
;
281 wpa_auth_logger(wpa_auth
, NULL
, LOGGER_DEBUG
, "rekeying GTK");
282 group
= wpa_auth
->group
;
284 wpa_group_get(wpa_auth
, group
);
286 group
->GTKReKey
= TRUE
;
288 group
->changed
= FALSE
;
289 wpa_group_sm_step(wpa_auth
, group
);
290 } while (group
->changed
);
293 wpa_group_put(wpa_auth
, group
);
297 if (wpa_auth
->conf
.wpa_group_rekey
) {
298 eloop_register_timeout(wpa_auth
->conf
.wpa_group_rekey
,
299 0, wpa_rekey_gtk
, wpa_auth
, NULL
);
304 static void wpa_rekey_ptk(void *eloop_ctx
, void *timeout_ctx
)
306 struct wpa_authenticator
*wpa_auth
= eloop_ctx
;
307 struct wpa_state_machine
*sm
= timeout_ctx
;
309 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
, "rekeying PTK");
310 wpa_request_new_ptk(sm
);
315 static int wpa_auth_pmksa_clear_cb(struct wpa_state_machine
*sm
, void *ctx
)
317 if (sm
->pmksa
== ctx
)
323 static void wpa_auth_pmksa_free_cb(struct rsn_pmksa_cache_entry
*entry
,
326 struct wpa_authenticator
*wpa_auth
= ctx
;
327 wpa_auth_for_each_sta(wpa_auth
, wpa_auth_pmksa_clear_cb
, entry
);
331 static int wpa_group_init_gmk_and_counter(struct wpa_authenticator
*wpa_auth
,
332 struct wpa_group
*group
)
334 u8 buf
[ETH_ALEN
+ 8 + sizeof(unsigned long)];
338 if (random_get_bytes(group
->GMK
, WPA_GMK_LEN
) < 0)
340 wpa_hexdump_key(MSG_DEBUG
, "GMK", group
->GMK
, WPA_GMK_LEN
);
343 * Counter = PRF-256(Random number, "Init Counter",
344 * Local MAC Address || Time)
346 os_memcpy(buf
, wpa_auth
->addr
, ETH_ALEN
);
347 wpa_get_ntp_timestamp(buf
+ ETH_ALEN
);
348 ptr
= (unsigned long) group
;
349 os_memcpy(buf
+ ETH_ALEN
+ 8, &ptr
, sizeof(ptr
));
350 if (random_get_bytes(rkey
, sizeof(rkey
)) < 0)
353 if (sha1_prf(rkey
, sizeof(rkey
), "Init Counter", buf
, sizeof(buf
),
354 group
->Counter
, WPA_NONCE_LEN
) < 0)
356 wpa_hexdump_key(MSG_DEBUG
, "Key Counter",
357 group
->Counter
, WPA_NONCE_LEN
);
363 static struct wpa_group
* wpa_group_init(struct wpa_authenticator
*wpa_auth
,
364 int vlan_id
, int delay_init
)
366 struct wpa_group
*group
;
368 group
= os_zalloc(sizeof(struct wpa_group
));
372 group
->GTKAuthenticator
= TRUE
;
373 group
->vlan_id
= vlan_id
;
374 group
->GTK_len
= wpa_cipher_key_len(wpa_auth
->conf
.wpa_group
);
376 if (random_pool_ready() != 1) {
377 wpa_printf(MSG_INFO
, "WPA: Not enough entropy in random pool "
378 "for secure operations - update keys later when "
379 "the first station connects");
383 * Set initial GMK/Counter value here. The actual values that will be
384 * used in negotiations will be set once the first station tries to
385 * connect. This allows more time for collecting additional randomness
386 * on embedded devices.
388 if (wpa_group_init_gmk_and_counter(wpa_auth
, group
) < 0) {
389 wpa_printf(MSG_ERROR
, "Failed to get random data for WPA "
397 wpa_printf(MSG_DEBUG
, "WPA: Delay group state machine start "
398 "until Beacon frames have been configured");
399 /* Initialization is completed in wpa_init_keys(). */
401 wpa_group_sm_step(wpa_auth
, group
);
402 group
->GInit
= FALSE
;
403 wpa_group_sm_step(wpa_auth
, group
);
411 * wpa_init - Initialize WPA authenticator
412 * @addr: Authenticator address
413 * @conf: Configuration for WPA authenticator
414 * @cb: Callback functions for WPA authenticator
415 * Returns: Pointer to WPA authenticator data or %NULL on failure
417 struct wpa_authenticator
* wpa_init(const u8
*addr
,
418 struct wpa_auth_config
*conf
,
419 const struct wpa_auth_callbacks
*cb
,
422 struct wpa_authenticator
*wpa_auth
;
424 wpa_auth
= os_zalloc(sizeof(struct wpa_authenticator
));
425 if (wpa_auth
== NULL
)
427 os_memcpy(wpa_auth
->addr
, addr
, ETH_ALEN
);
428 os_memcpy(&wpa_auth
->conf
, conf
, sizeof(*conf
));
430 wpa_auth
->cb_ctx
= cb_ctx
;
432 if (wpa_auth_gen_wpa_ie(wpa_auth
)) {
433 wpa_printf(MSG_ERROR
, "Could not generate WPA IE.");
438 wpa_auth
->group
= wpa_group_init(wpa_auth
, 0, 1);
439 if (wpa_auth
->group
== NULL
) {
440 os_free(wpa_auth
->wpa_ie
);
445 wpa_auth
->pmksa
= pmksa_cache_auth_init(wpa_auth_pmksa_free_cb
,
447 if (wpa_auth
->pmksa
== NULL
) {
448 wpa_printf(MSG_ERROR
, "PMKSA cache initialization failed.");
449 os_free(wpa_auth
->group
);
450 os_free(wpa_auth
->wpa_ie
);
455 #ifdef CONFIG_IEEE80211R_AP
456 wpa_auth
->ft_pmk_cache
= wpa_ft_pmk_cache_init();
457 if (wpa_auth
->ft_pmk_cache
== NULL
) {
458 wpa_printf(MSG_ERROR
, "FT PMK cache initialization failed.");
459 os_free(wpa_auth
->group
);
460 os_free(wpa_auth
->wpa_ie
);
461 pmksa_cache_auth_deinit(wpa_auth
->pmksa
);
465 #endif /* CONFIG_IEEE80211R_AP */
467 if (wpa_auth
->conf
.wpa_gmk_rekey
) {
468 eloop_register_timeout(wpa_auth
->conf
.wpa_gmk_rekey
, 0,
469 wpa_rekey_gmk
, wpa_auth
, NULL
);
472 if (wpa_auth
->conf
.wpa_group_rekey
) {
473 eloop_register_timeout(wpa_auth
->conf
.wpa_group_rekey
, 0,
474 wpa_rekey_gtk
, wpa_auth
, NULL
);
478 if (WPA_GET_BE32(conf
->ip_addr_start
)) {
479 int count
= WPA_GET_BE32(conf
->ip_addr_end
) -
480 WPA_GET_BE32(conf
->ip_addr_start
) + 1;
484 wpa_auth
->ip_pool
= bitfield_alloc(count
);
486 #endif /* CONFIG_P2P */
492 int wpa_init_keys(struct wpa_authenticator
*wpa_auth
)
494 struct wpa_group
*group
= wpa_auth
->group
;
496 wpa_printf(MSG_DEBUG
, "WPA: Start group state machine to set initial "
498 wpa_group_sm_step(wpa_auth
, group
);
499 group
->GInit
= FALSE
;
500 wpa_group_sm_step(wpa_auth
, group
);
501 if (group
->wpa_group_state
== WPA_GROUP_FATAL_FAILURE
)
508 * wpa_deinit - Deinitialize WPA authenticator
509 * @wpa_auth: Pointer to WPA authenticator data from wpa_init()
511 void wpa_deinit(struct wpa_authenticator
*wpa_auth
)
513 struct wpa_group
*group
, *prev
;
515 eloop_cancel_timeout(wpa_rekey_gmk
, wpa_auth
, NULL
);
516 eloop_cancel_timeout(wpa_rekey_gtk
, wpa_auth
, NULL
);
518 pmksa_cache_auth_deinit(wpa_auth
->pmksa
);
520 #ifdef CONFIG_IEEE80211R_AP
521 wpa_ft_pmk_cache_deinit(wpa_auth
->ft_pmk_cache
);
522 wpa_auth
->ft_pmk_cache
= NULL
;
523 wpa_ft_deinit(wpa_auth
);
524 #endif /* CONFIG_IEEE80211R_AP */
527 bitfield_free(wpa_auth
->ip_pool
);
528 #endif /* CONFIG_P2P */
531 os_free(wpa_auth
->wpa_ie
);
533 group
= wpa_auth
->group
;
545 * wpa_reconfig - Update WPA authenticator configuration
546 * @wpa_auth: Pointer to WPA authenticator data from wpa_init()
547 * @conf: Configuration for WPA authenticator
549 int wpa_reconfig(struct wpa_authenticator
*wpa_auth
,
550 struct wpa_auth_config
*conf
)
552 struct wpa_group
*group
;
553 if (wpa_auth
== NULL
)
556 os_memcpy(&wpa_auth
->conf
, conf
, sizeof(*conf
));
557 if (wpa_auth_gen_wpa_ie(wpa_auth
)) {
558 wpa_printf(MSG_ERROR
, "Could not generate WPA IE.");
563 * Reinitialize GTK to make sure it is suitable for the new
566 group
= wpa_auth
->group
;
567 group
->GTK_len
= wpa_cipher_key_len(wpa_auth
->conf
.wpa_group
);
569 wpa_group_sm_step(wpa_auth
, group
);
570 group
->GInit
= FALSE
;
571 wpa_group_sm_step(wpa_auth
, group
);
577 struct wpa_state_machine
*
578 wpa_auth_sta_init(struct wpa_authenticator
*wpa_auth
, const u8
*addr
,
579 const u8
*p2p_dev_addr
)
581 struct wpa_state_machine
*sm
;
583 if (wpa_auth
->group
->wpa_group_state
== WPA_GROUP_FATAL_FAILURE
)
586 sm
= os_zalloc(sizeof(struct wpa_state_machine
));
589 os_memcpy(sm
->addr
, addr
, ETH_ALEN
);
591 os_memcpy(sm
->p2p_dev_addr
, p2p_dev_addr
, ETH_ALEN
);
593 sm
->wpa_auth
= wpa_auth
;
594 sm
->group
= wpa_auth
->group
;
595 wpa_group_get(sm
->wpa_auth
, sm
->group
);
601 int wpa_auth_sta_associated(struct wpa_authenticator
*wpa_auth
,
602 struct wpa_state_machine
*sm
)
604 if (wpa_auth
== NULL
|| !wpa_auth
->conf
.wpa
|| sm
== NULL
)
607 #ifdef CONFIG_IEEE80211R_AP
608 if (sm
->ft_completed
) {
609 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
610 "FT authentication already completed - do not "
611 "start 4-way handshake");
612 /* Go to PTKINITDONE state to allow GTK rekeying */
613 sm
->wpa_ptk_state
= WPA_PTK_PTKINITDONE
;
617 #endif /* CONFIG_IEEE80211R_AP */
620 if (sm
->fils_completed
) {
621 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
622 "FILS authentication already completed - do not start 4-way handshake");
623 /* Go to PTKINITDONE state to allow GTK rekeying */
624 sm
->wpa_ptk_state
= WPA_PTK_PTKINITDONE
;
628 #endif /* CONFIG_FILS */
631 os_memset(&sm
->key_replay
, 0, sizeof(sm
->key_replay
));
632 sm
->ReAuthenticationRequest
= TRUE
;
633 return wpa_sm_step(sm
);
636 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
637 "start authentication");
641 if (wpa_sm_step(sm
) == 1)
642 return 1; /* should not really happen */
644 sm
->AuthenticationRequest
= TRUE
;
645 return wpa_sm_step(sm
);
649 void wpa_auth_sta_no_wpa(struct wpa_state_machine
*sm
)
651 /* WPA/RSN was not used - clear WPA state. This is needed if the STA
652 * reassociates back to the same AP while the previous entry for the
653 * STA has not yet been removed. */
657 sm
->wpa_key_mgmt
= 0;
661 static void wpa_free_sta_sm(struct wpa_state_machine
*sm
)
664 if (WPA_GET_BE32(sm
->ip_addr
)) {
666 wpa_printf(MSG_DEBUG
, "P2P: Free assigned IP "
667 "address %u.%u.%u.%u from " MACSTR
,
668 sm
->ip_addr
[0], sm
->ip_addr
[1],
669 sm
->ip_addr
[2], sm
->ip_addr
[3],
671 start
= WPA_GET_BE32(sm
->wpa_auth
->conf
.ip_addr_start
);
672 bitfield_clear(sm
->wpa_auth
->ip_pool
,
673 WPA_GET_BE32(sm
->ip_addr
) - start
);
675 #endif /* CONFIG_P2P */
676 if (sm
->GUpdateStationKeys
) {
677 sm
->group
->GKeyDoneStations
--;
678 sm
->GUpdateStationKeys
= FALSE
;
680 #ifdef CONFIG_IEEE80211R_AP
681 os_free(sm
->assoc_resp_ftie
);
682 wpabuf_free(sm
->ft_pending_req_ies
);
683 #endif /* CONFIG_IEEE80211R_AP */
684 os_free(sm
->last_rx_eapol_key
);
686 wpa_group_put(sm
->wpa_auth
, sm
->group
);
691 void wpa_auth_sta_deinit(struct wpa_state_machine
*sm
)
696 if (sm
->wpa_auth
->conf
.wpa_strict_rekey
&& sm
->has_GTK
) {
697 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
698 "strict rekeying - force GTK rekey since STA "
700 eloop_cancel_timeout(wpa_rekey_gtk
, sm
->wpa_auth
, NULL
);
701 eloop_register_timeout(0, 500000, wpa_rekey_gtk
, sm
->wpa_auth
,
705 eloop_cancel_timeout(wpa_send_eapol_timeout
, sm
->wpa_auth
, sm
);
706 sm
->pending_1_of_4_timeout
= 0;
707 eloop_cancel_timeout(wpa_sm_call_step
, sm
, NULL
);
708 eloop_cancel_timeout(wpa_rekey_ptk
, sm
->wpa_auth
, sm
);
709 #ifdef CONFIG_IEEE80211R_AP
710 wpa_ft_sta_deinit(sm
);
711 #endif /* CONFIG_IEEE80211R_AP */
712 if (sm
->in_step_loop
) {
713 /* Must not free state machine while wpa_sm_step() is running.
714 * Freeing will be completed in the end of wpa_sm_step(). */
715 wpa_printf(MSG_DEBUG
, "WPA: Registering pending STA state "
716 "machine deinit for " MACSTR
, MAC2STR(sm
->addr
));
717 sm
->pending_deinit
= 1;
723 static void wpa_request_new_ptk(struct wpa_state_machine
*sm
)
728 sm
->PTKRequest
= TRUE
;
733 static int wpa_replay_counter_valid(struct wpa_key_replay_counter
*ctr
,
734 const u8
*replay_counter
)
737 for (i
= 0; i
< RSNA_MAX_EAPOL_RETRIES
; i
++) {
740 if (os_memcmp(replay_counter
, ctr
[i
].counter
,
741 WPA_REPLAY_COUNTER_LEN
) == 0)
748 static void wpa_replay_counter_mark_invalid(struct wpa_key_replay_counter
*ctr
,
749 const u8
*replay_counter
)
752 for (i
= 0; i
< RSNA_MAX_EAPOL_RETRIES
; i
++) {
754 (replay_counter
== NULL
||
755 os_memcmp(replay_counter
, ctr
[i
].counter
,
756 WPA_REPLAY_COUNTER_LEN
) == 0))
757 ctr
[i
].valid
= FALSE
;
762 #ifdef CONFIG_IEEE80211R_AP
763 static int ft_check_msg_2_of_4(struct wpa_authenticator
*wpa_auth
,
764 struct wpa_state_machine
*sm
,
765 struct wpa_eapol_ie_parse
*kde
)
767 struct wpa_ie_data ie
;
768 struct rsn_mdie
*mdie
;
770 if (wpa_parse_wpa_ie_rsn(kde
->rsn_ie
, kde
->rsn_ie_len
, &ie
) < 0 ||
771 ie
.num_pmkid
!= 1 || ie
.pmkid
== NULL
) {
772 wpa_printf(MSG_DEBUG
, "FT: No PMKR1Name in "
773 "FT 4-way handshake message 2/4");
777 os_memcpy(sm
->sup_pmk_r1_name
, ie
.pmkid
, PMKID_LEN
);
778 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name from Supplicant",
779 sm
->sup_pmk_r1_name
, PMKID_LEN
);
781 if (!kde
->mdie
|| !kde
->ftie
) {
782 wpa_printf(MSG_DEBUG
, "FT: No %s in FT 4-way handshake "
783 "message 2/4", kde
->mdie
? "FTIE" : "MDIE");
787 mdie
= (struct rsn_mdie
*) (kde
->mdie
+ 2);
788 if (kde
->mdie
[1] < sizeof(struct rsn_mdie
) ||
789 os_memcmp(wpa_auth
->conf
.mobility_domain
, mdie
->mobility_domain
,
790 MOBILITY_DOMAIN_ID_LEN
) != 0) {
791 wpa_printf(MSG_DEBUG
, "FT: MDIE mismatch");
795 if (sm
->assoc_resp_ftie
&&
796 (kde
->ftie
[1] != sm
->assoc_resp_ftie
[1] ||
797 os_memcmp(kde
->ftie
, sm
->assoc_resp_ftie
,
798 2 + sm
->assoc_resp_ftie
[1]) != 0)) {
799 wpa_printf(MSG_DEBUG
, "FT: FTIE mismatch");
800 wpa_hexdump(MSG_DEBUG
, "FT: FTIE in EAPOL-Key msg 2/4",
801 kde
->ftie
, kde
->ftie_len
);
802 wpa_hexdump(MSG_DEBUG
, "FT: FTIE in (Re)AssocResp",
803 sm
->assoc_resp_ftie
, 2 + sm
->assoc_resp_ftie
[1]);
809 #endif /* CONFIG_IEEE80211R_AP */
812 static int wpa_receive_error_report(struct wpa_authenticator
*wpa_auth
,
813 struct wpa_state_machine
*sm
, int group
)
815 /* Supplicant reported a Michael MIC error */
816 wpa_auth_vlogger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
817 "received EAPOL-Key Error Request "
818 "(STA detected Michael MIC failure (group=%d))",
821 if (group
&& wpa_auth
->conf
.wpa_group
!= WPA_CIPHER_TKIP
) {
822 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
823 "ignore Michael MIC failure report since "
824 "group cipher is not TKIP");
825 } else if (!group
&& sm
->pairwise
!= WPA_CIPHER_TKIP
) {
826 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
827 "ignore Michael MIC failure report since "
828 "pairwise cipher is not TKIP");
830 if (wpa_auth_mic_failure_report(wpa_auth
, sm
->addr
) > 0)
831 return 1; /* STA entry was removed */
832 sm
->dot11RSNAStatsTKIPRemoteMICFailures
++;
833 wpa_auth
->dot11RSNAStatsTKIPRemoteMICFailures
++;
837 * Error report is not a request for a new key handshake, but since
838 * Authenticator may do it, let's change the keys now anyway.
840 wpa_request_new_ptk(sm
);
845 static int wpa_try_alt_snonce(struct wpa_state_machine
*sm
, u8
*data
,
850 const u8
*pmk
= NULL
;
851 unsigned int pmk_len
;
853 os_memset(&PTK
, 0, sizeof(PTK
));
855 if (wpa_key_mgmt_wpa_psk(sm
->wpa_key_mgmt
)) {
856 pmk
= wpa_auth_get_psk(sm
->wpa_auth
, sm
->addr
,
857 sm
->p2p_dev_addr
, pmk
);
863 pmk_len
= sm
->pmk_len
;
866 if (wpa_derive_ptk(sm
, sm
->alt_SNonce
, pmk
, pmk_len
, &PTK
) < 0)
869 if (wpa_verify_key_mic(sm
->wpa_key_mgmt
, &PTK
, data
, data_len
)
875 if (!wpa_key_mgmt_wpa_psk(sm
->wpa_key_mgmt
))
880 wpa_printf(MSG_DEBUG
,
881 "WPA: Earlier SNonce did not result in matching MIC");
885 wpa_printf(MSG_DEBUG
,
886 "WPA: Earlier SNonce resulted in matching MIC");
887 sm
->alt_snonce_valid
= 0;
888 os_memcpy(sm
->SNonce
, sm
->alt_SNonce
, WPA_NONCE_LEN
);
889 os_memcpy(&sm
->PTK
, &PTK
, sizeof(PTK
));
890 sm
->PTK_valid
= TRUE
;
896 void wpa_receive(struct wpa_authenticator
*wpa_auth
,
897 struct wpa_state_machine
*sm
,
898 u8
*data
, size_t data_len
)
900 struct ieee802_1x_hdr
*hdr
;
901 struct wpa_eapol_key
*key
;
902 u16 key_info
, key_data_length
;
903 enum { PAIRWISE_2
, PAIRWISE_4
, GROUP_2
, REQUEST
,
904 SMK_M1
, SMK_M3
, SMK_ERROR
} msg
;
906 struct wpa_eapol_ie_parse kde
;
908 size_t keyhdrlen
, mic_len
;
911 if (wpa_auth
== NULL
|| !wpa_auth
->conf
.wpa
|| sm
== NULL
)
913 wpa_hexdump(MSG_MSGDUMP
, "WPA: RX EAPOL data", data
, data_len
);
915 mic_len
= wpa_mic_len(sm
->wpa_key_mgmt
);
916 keyhdrlen
= sizeof(*key
) + mic_len
+ 2;
918 if (data_len
< sizeof(*hdr
) + keyhdrlen
) {
919 wpa_printf(MSG_DEBUG
, "WPA: Ignore too short EAPOL-Key frame");
923 hdr
= (struct ieee802_1x_hdr
*) data
;
924 key
= (struct wpa_eapol_key
*) (hdr
+ 1);
925 mic
= (u8
*) (key
+ 1);
926 key_info
= WPA_GET_BE16(key
->key_info
);
927 key_data
= mic
+ mic_len
+ 2;
928 key_data_length
= WPA_GET_BE16(mic
+ mic_len
);
929 wpa_printf(MSG_DEBUG
, "WPA: Received EAPOL-Key from " MACSTR
930 " key_info=0x%x type=%u mic_len=%u key_data_length=%u",
931 MAC2STR(sm
->addr
), key_info
, key
->type
,
932 (unsigned int) mic_len
, key_data_length
);
933 wpa_hexdump(MSG_MSGDUMP
,
934 "WPA: EAPOL-Key header (ending before Key MIC)",
936 wpa_hexdump(MSG_MSGDUMP
, "WPA: EAPOL-Key Key MIC",
938 if (key_data_length
> data_len
- sizeof(*hdr
) - keyhdrlen
) {
939 wpa_printf(MSG_INFO
, "WPA: Invalid EAPOL-Key frame - "
940 "key_data overflow (%d > %lu)",
942 (unsigned long) (data_len
- sizeof(*hdr
) -
947 if (sm
->wpa
== WPA_VERSION_WPA2
) {
948 if (key
->type
== EAPOL_KEY_TYPE_WPA
) {
950 * Some deployed station implementations seem to send
951 * msg 4/4 with incorrect type value in WPA2 mode.
953 wpa_printf(MSG_DEBUG
, "Workaround: Allow EAPOL-Key "
954 "with unexpected WPA type in RSN mode");
955 } else if (key
->type
!= EAPOL_KEY_TYPE_RSN
) {
956 wpa_printf(MSG_DEBUG
, "Ignore EAPOL-Key with "
957 "unexpected type %d in RSN mode",
962 if (key
->type
!= EAPOL_KEY_TYPE_WPA
) {
963 wpa_printf(MSG_DEBUG
, "Ignore EAPOL-Key with "
964 "unexpected type %d in WPA mode",
970 wpa_hexdump(MSG_DEBUG
, "WPA: Received Key Nonce", key
->key_nonce
,
972 wpa_hexdump(MSG_DEBUG
, "WPA: Received Replay Counter",
973 key
->replay_counter
, WPA_REPLAY_COUNTER_LEN
);
975 /* FIX: verify that the EAPOL-Key frame was encrypted if pairwise keys
978 if ((key_info
& (WPA_KEY_INFO_SMK_MESSAGE
| WPA_KEY_INFO_REQUEST
)) ==
979 (WPA_KEY_INFO_SMK_MESSAGE
| WPA_KEY_INFO_REQUEST
)) {
980 if (key_info
& WPA_KEY_INFO_ERROR
) {
982 msgtxt
= "SMK Error";
987 } else if (key_info
& WPA_KEY_INFO_SMK_MESSAGE
) {
990 } else if (key_info
& WPA_KEY_INFO_REQUEST
) {
993 } else if (!(key_info
& WPA_KEY_INFO_KEY_TYPE
)) {
995 msgtxt
= "2/2 Group";
996 } else if (key_data_length
== 0 ||
997 (mic_len
== 0 && (key_info
& WPA_KEY_INFO_ENCR_KEY_DATA
) &&
998 key_data_length
== AES_BLOCK_SIZE
)) {
1000 msgtxt
= "4/4 Pairwise";
1003 msgtxt
= "2/4 Pairwise";
1006 /* TODO: key_info type validation for PeerKey */
1007 if (msg
== REQUEST
|| msg
== PAIRWISE_2
|| msg
== PAIRWISE_4
||
1009 u16 ver
= key_info
& WPA_KEY_INFO_TYPE_MASK
;
1010 if (sm
->pairwise
== WPA_CIPHER_CCMP
||
1011 sm
->pairwise
== WPA_CIPHER_GCMP
) {
1012 if (wpa_use_aes_cmac(sm
) &&
1013 sm
->wpa_key_mgmt
!= WPA_KEY_MGMT_OSEN
&&
1014 !wpa_key_mgmt_suite_b(sm
->wpa_key_mgmt
) &&
1015 !wpa_key_mgmt_fils(sm
->wpa_key_mgmt
) &&
1016 ver
!= WPA_KEY_INFO_TYPE_AES_128_CMAC
) {
1017 wpa_auth_logger(wpa_auth
, sm
->addr
,
1019 "advertised support for "
1020 "AES-128-CMAC, but did not "
1025 if (!wpa_use_aes_cmac(sm
) &&
1026 !wpa_key_mgmt_fils(sm
->wpa_key_mgmt
) &&
1027 sm
->wpa_key_mgmt
!= WPA_KEY_MGMT_OWE
&&
1028 ver
!= WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
) {
1029 wpa_auth_logger(wpa_auth
, sm
->addr
,
1031 "did not use HMAC-SHA1-AES "
1037 if ((wpa_key_mgmt_suite_b(sm
->wpa_key_mgmt
) ||
1038 wpa_key_mgmt_fils(sm
->wpa_key_mgmt
) ||
1039 sm
->wpa_key_mgmt
== WPA_KEY_MGMT_OWE
) &&
1040 ver
!= WPA_KEY_INFO_TYPE_AKM_DEFINED
) {
1041 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_WARNING
,
1042 "did not use EAPOL-Key descriptor version 0 as required for AKM-defined cases");
1047 if (key_info
& WPA_KEY_INFO_REQUEST
) {
1048 if (sm
->req_replay_counter_used
&&
1049 os_memcmp(key
->replay_counter
, sm
->req_replay_counter
,
1050 WPA_REPLAY_COUNTER_LEN
) <= 0) {
1051 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_WARNING
,
1052 "received EAPOL-Key request with "
1053 "replayed counter");
1058 if (!(key_info
& WPA_KEY_INFO_REQUEST
) &&
1059 !wpa_replay_counter_valid(sm
->key_replay
, key
->replay_counter
)) {
1062 if (msg
== PAIRWISE_2
&&
1063 wpa_replay_counter_valid(sm
->prev_key_replay
,
1064 key
->replay_counter
) &&
1065 sm
->wpa_ptk_state
== WPA_PTK_PTKINITNEGOTIATING
&&
1066 os_memcmp(sm
->SNonce
, key
->key_nonce
, WPA_NONCE_LEN
) != 0)
1069 * Some supplicant implementations (e.g., Windows XP
1070 * WZC) update SNonce for each EAPOL-Key 2/4. This
1071 * breaks the workaround on accepting any of the
1072 * pending requests, so allow the SNonce to be updated
1073 * even if we have already sent out EAPOL-Key 3/4.
1075 wpa_auth_vlogger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
1076 "Process SNonce update from STA "
1077 "based on retransmitted EAPOL-Key "
1079 sm
->update_snonce
= 1;
1080 os_memcpy(sm
->alt_SNonce
, sm
->SNonce
, WPA_NONCE_LEN
);
1081 sm
->alt_snonce_valid
= TRUE
;
1082 os_memcpy(sm
->alt_replay_counter
,
1083 sm
->key_replay
[0].counter
,
1084 WPA_REPLAY_COUNTER_LEN
);
1085 goto continue_processing
;
1088 if (msg
== PAIRWISE_4
&& sm
->alt_snonce_valid
&&
1089 sm
->wpa_ptk_state
== WPA_PTK_PTKINITNEGOTIATING
&&
1090 os_memcmp(key
->replay_counter
, sm
->alt_replay_counter
,
1091 WPA_REPLAY_COUNTER_LEN
) == 0) {
1093 * Supplicant may still be using the old SNonce since
1094 * there was two EAPOL-Key 2/4 messages and they had
1095 * different SNonce values.
1097 wpa_auth_vlogger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
1098 "Try to process received EAPOL-Key 4/4 based on old Replay Counter and SNonce from an earlier EAPOL-Key 1/4");
1099 goto continue_processing
;
1102 if (msg
== PAIRWISE_2
&&
1103 wpa_replay_counter_valid(sm
->prev_key_replay
,
1104 key
->replay_counter
) &&
1105 sm
->wpa_ptk_state
== WPA_PTK_PTKINITNEGOTIATING
) {
1106 wpa_auth_vlogger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
1107 "ignore retransmitted EAPOL-Key %s - "
1108 "SNonce did not change", msgtxt
);
1110 wpa_auth_vlogger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
1111 "received EAPOL-Key %s with "
1112 "unexpected replay counter", msgtxt
);
1114 for (i
= 0; i
< RSNA_MAX_EAPOL_RETRIES
; i
++) {
1115 if (!sm
->key_replay
[i
].valid
)
1117 wpa_hexdump(MSG_DEBUG
, "pending replay counter",
1118 sm
->key_replay
[i
].counter
,
1119 WPA_REPLAY_COUNTER_LEN
);
1121 wpa_hexdump(MSG_DEBUG
, "received replay counter",
1122 key
->replay_counter
, WPA_REPLAY_COUNTER_LEN
);
1126 continue_processing
:
1128 if (sm
->wpa
== WPA_VERSION_WPA2
&& mic_len
== 0 &&
1129 !(key_info
& WPA_KEY_INFO_ENCR_KEY_DATA
)) {
1130 wpa_auth_vlogger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
1131 "WPA: Encr Key Data bit not set even though AEAD cipher is supposed to be used - drop frame");
1134 #endif /* CONFIG_FILS */
1138 if (sm
->wpa_ptk_state
!= WPA_PTK_PTKSTART
&&
1139 sm
->wpa_ptk_state
!= WPA_PTK_PTKCALCNEGOTIATING
&&
1140 (!sm
->update_snonce
||
1141 sm
->wpa_ptk_state
!= WPA_PTK_PTKINITNEGOTIATING
)) {
1142 wpa_auth_vlogger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1143 "received EAPOL-Key msg 2/4 in "
1144 "invalid state (%d) - dropped",
1148 random_add_randomness(key
->key_nonce
, WPA_NONCE_LEN
);
1149 if (sm
->group
->reject_4way_hs_for_entropy
) {
1151 * The system did not have enough entropy to generate
1152 * strong random numbers. Reject the first 4-way
1153 * handshake(s) and collect some entropy based on the
1154 * information from it. Once enough entropy is
1155 * available, the next atempt will trigger GMK/Key
1156 * Counter update and the station will be allowed to
1159 wpa_printf(MSG_DEBUG
, "WPA: Reject 4-way handshake to "
1160 "collect more entropy for random number "
1162 random_mark_pool_ready();
1163 wpa_sta_disconnect(wpa_auth
, sm
->addr
);
1168 if (sm
->wpa_ptk_state
!= WPA_PTK_PTKINITNEGOTIATING
||
1170 wpa_auth_vlogger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1171 "received EAPOL-Key msg 4/4 in "
1172 "invalid state (%d) - dropped",
1178 if (sm
->wpa_ptk_group_state
!= WPA_PTK_GROUP_REKEYNEGOTIATING
1179 || !sm
->PTK_valid
) {
1180 wpa_auth_vlogger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1181 "received EAPOL-Key msg 2/2 in "
1182 "invalid state (%d) - dropped",
1183 sm
->wpa_ptk_group_state
);
1187 #ifdef CONFIG_PEERKEY
1191 if (!wpa_auth
->conf
.peerkey
) {
1192 wpa_printf(MSG_DEBUG
, "RSN: SMK M1/M3/Error, but "
1193 "PeerKey use disabled - ignoring message");
1196 if (!sm
->PTK_valid
) {
1197 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1198 "received EAPOL-Key msg SMK in "
1199 "invalid state - dropped");
1203 #else /* CONFIG_PEERKEY */
1207 return; /* STSL disabled - ignore SMK messages */
1208 #endif /* CONFIG_PEERKEY */
1213 wpa_auth_vlogger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
1214 "received EAPOL-Key frame (%s)", msgtxt
);
1216 if (key_info
& WPA_KEY_INFO_ACK
) {
1217 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1218 "received invalid EAPOL-Key: Key Ack set");
1222 if (!wpa_key_mgmt_fils(sm
->wpa_key_mgmt
) &&
1223 !(key_info
& WPA_KEY_INFO_MIC
)) {
1224 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1225 "received invalid EAPOL-Key: Key MIC not set");
1230 if (wpa_key_mgmt_fils(sm
->wpa_key_mgmt
) &&
1231 (key_info
& WPA_KEY_INFO_MIC
)) {
1232 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1233 "received invalid EAPOL-Key: Key MIC set");
1236 #endif /* CONFIG_FILS */
1238 sm
->MICVerified
= FALSE
;
1239 if (sm
->PTK_valid
&& !sm
->update_snonce
) {
1241 wpa_verify_key_mic(sm
->wpa_key_mgmt
, &sm
->PTK
, data
,
1243 (msg
!= PAIRWISE_4
|| !sm
->alt_snonce_valid
||
1244 wpa_try_alt_snonce(sm
, data
, data_len
))) {
1245 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1246 "received EAPOL-Key with invalid MIC");
1251 wpa_aead_decrypt(sm
, &sm
->PTK
, data
, data_len
,
1252 &key_data_length
) < 0) {
1253 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1254 "received EAPOL-Key with invalid MIC");
1257 #endif /* CONFIG_FILS */
1258 sm
->MICVerified
= TRUE
;
1259 eloop_cancel_timeout(wpa_send_eapol_timeout
, wpa_auth
, sm
);
1260 sm
->pending_1_of_4_timeout
= 0;
1263 if (key_info
& WPA_KEY_INFO_REQUEST
) {
1264 if (sm
->MICVerified
) {
1265 sm
->req_replay_counter_used
= 1;
1266 os_memcpy(sm
->req_replay_counter
, key
->replay_counter
,
1267 WPA_REPLAY_COUNTER_LEN
);
1269 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1270 "received EAPOL-Key request with "
1276 * TODO: should decrypt key data field if encryption was used;
1277 * even though MAC address KDE is not normally encrypted,
1278 * supplicant is allowed to encrypt it.
1280 if (msg
== SMK_ERROR
) {
1281 #ifdef CONFIG_PEERKEY
1282 wpa_smk_error(wpa_auth
, sm
, key_data
, key_data_length
);
1283 #endif /* CONFIG_PEERKEY */
1285 } else if (key_info
& WPA_KEY_INFO_ERROR
) {
1286 if (wpa_receive_error_report(
1288 !(key_info
& WPA_KEY_INFO_KEY_TYPE
)) > 0)
1289 return; /* STA entry was removed */
1290 } else if (key_info
& WPA_KEY_INFO_KEY_TYPE
) {
1291 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1292 "received EAPOL-Key Request for new "
1294 wpa_request_new_ptk(sm
);
1295 #ifdef CONFIG_PEERKEY
1296 } else if (msg
== SMK_M1
) {
1297 wpa_smk_m1(wpa_auth
, sm
, key
, key_data
,
1299 #endif /* CONFIG_PEERKEY */
1300 } else if (key_data_length
> 0 &&
1301 wpa_parse_kde_ies(key_data
, key_data_length
,
1305 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1306 "received EAPOL-Key Request for GTK "
1308 eloop_cancel_timeout(wpa_rekey_gtk
, wpa_auth
, NULL
);
1309 wpa_rekey_gtk(wpa_auth
, NULL
);
1312 /* Do not allow the same key replay counter to be reused. */
1313 wpa_replay_counter_mark_invalid(sm
->key_replay
,
1314 key
->replay_counter
);
1316 if (msg
== PAIRWISE_2
) {
1318 * Maintain a copy of the pending EAPOL-Key frames in
1319 * case the EAPOL-Key frame was retransmitted. This is
1320 * needed to allow EAPOL-Key msg 2/4 reply to another
1321 * pending msg 1/4 to update the SNonce to work around
1322 * unexpected supplicant behavior.
1324 os_memcpy(sm
->prev_key_replay
, sm
->key_replay
,
1325 sizeof(sm
->key_replay
));
1327 os_memset(sm
->prev_key_replay
, 0,
1328 sizeof(sm
->prev_key_replay
));
1332 * Make sure old valid counters are not accepted anymore and
1333 * do not get copied again.
1335 wpa_replay_counter_mark_invalid(sm
->key_replay
, NULL
);
1338 #ifdef CONFIG_PEERKEY
1339 if (msg
== SMK_M3
) {
1340 wpa_smk_m3(wpa_auth
, sm
, key
, key_data
, key_data_length
);
1343 #endif /* CONFIG_PEERKEY */
1345 os_free(sm
->last_rx_eapol_key
);
1346 sm
->last_rx_eapol_key
= os_memdup(data
, data_len
);
1347 if (sm
->last_rx_eapol_key
== NULL
)
1349 sm
->last_rx_eapol_key_len
= data_len
;
1351 sm
->rx_eapol_key_secure
= !!(key_info
& WPA_KEY_INFO_SECURE
);
1352 sm
->EAPOLKeyReceived
= TRUE
;
1353 sm
->EAPOLKeyPairwise
= !!(key_info
& WPA_KEY_INFO_KEY_TYPE
);
1354 sm
->EAPOLKeyRequest
= !!(key_info
& WPA_KEY_INFO_REQUEST
);
1355 os_memcpy(sm
->SNonce
, key
->key_nonce
, WPA_NONCE_LEN
);
1360 static int wpa_gmk_to_gtk(const u8
*gmk
, const char *label
, const u8
*addr
,
1361 const u8
*gnonce
, u8
*gtk
, size_t gtk_len
)
1363 u8 data
[ETH_ALEN
+ WPA_NONCE_LEN
+ 8 + 16];
1367 /* GTK = PRF-X(GMK, "Group key expansion",
1368 * AA || GNonce || Time || random data)
1369 * The example described in the IEEE 802.11 standard uses only AA and
1370 * GNonce as inputs here. Add some more entropy since this derivation
1371 * is done only at the Authenticator and as such, does not need to be
1374 os_memcpy(data
, addr
, ETH_ALEN
);
1375 os_memcpy(data
+ ETH_ALEN
, gnonce
, WPA_NONCE_LEN
);
1376 pos
= data
+ ETH_ALEN
+ WPA_NONCE_LEN
;
1377 wpa_get_ntp_timestamp(pos
);
1379 if (random_get_bytes(pos
, 16) < 0)
1382 #ifdef CONFIG_IEEE80211W
1383 sha256_prf(gmk
, WPA_GMK_LEN
, label
, data
, sizeof(data
), gtk
, gtk_len
);
1384 #else /* CONFIG_IEEE80211W */
1385 if (sha1_prf(gmk
, WPA_GMK_LEN
, label
, data
, sizeof(data
), gtk
, gtk_len
)
1388 #endif /* CONFIG_IEEE80211W */
1394 static void wpa_send_eapol_timeout(void *eloop_ctx
, void *timeout_ctx
)
1396 struct wpa_authenticator
*wpa_auth
= eloop_ctx
;
1397 struct wpa_state_machine
*sm
= timeout_ctx
;
1399 sm
->pending_1_of_4_timeout
= 0;
1400 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
, "EAPOL-Key timeout");
1401 sm
->TimeoutEvt
= TRUE
;
1406 void __wpa_send_eapol(struct wpa_authenticator
*wpa_auth
,
1407 struct wpa_state_machine
*sm
, int key_info
,
1408 const u8
*key_rsc
, const u8
*nonce
,
1409 const u8
*kde
, size_t kde_len
,
1410 int keyidx
, int encr
, int force_version
)
1412 struct ieee802_1x_hdr
*hdr
;
1413 struct wpa_eapol_key
*key
;
1414 size_t len
, mic_len
, keyhdrlen
;
1416 int key_data_len
, pad_len
= 0;
1418 int version
, pairwise
;
1420 u8
*key_mic
, *key_data
;
1422 mic_len
= wpa_mic_len(sm
->wpa_key_mgmt
);
1423 keyhdrlen
= sizeof(*key
) + mic_len
+ 2;
1425 len
= sizeof(struct ieee802_1x_hdr
) + keyhdrlen
;
1428 version
= force_version
;
1429 else if (sm
->wpa_key_mgmt
== WPA_KEY_MGMT_OSEN
||
1430 sm
->wpa_key_mgmt
== WPA_KEY_MGMT_OWE
||
1431 wpa_key_mgmt_suite_b(sm
->wpa_key_mgmt
) ||
1432 wpa_key_mgmt_fils(sm
->wpa_key_mgmt
))
1433 version
= WPA_KEY_INFO_TYPE_AKM_DEFINED
;
1434 else if (wpa_use_aes_cmac(sm
))
1435 version
= WPA_KEY_INFO_TYPE_AES_128_CMAC
;
1436 else if (sm
->pairwise
!= WPA_CIPHER_TKIP
)
1437 version
= WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
;
1439 version
= WPA_KEY_INFO_TYPE_HMAC_MD5_RC4
;
1441 pairwise
= !!(key_info
& WPA_KEY_INFO_KEY_TYPE
);
1443 wpa_printf(MSG_DEBUG
, "WPA: Send EAPOL(version=%d secure=%d mic=%d "
1444 "ack=%d install=%d pairwise=%d kde_len=%lu keyidx=%d "
1447 (key_info
& WPA_KEY_INFO_SECURE
) ? 1 : 0,
1448 (key_info
& WPA_KEY_INFO_MIC
) ? 1 : 0,
1449 (key_info
& WPA_KEY_INFO_ACK
) ? 1 : 0,
1450 (key_info
& WPA_KEY_INFO_INSTALL
) ? 1 : 0,
1451 pairwise
, (unsigned long) kde_len
, keyidx
, encr
);
1453 key_data_len
= kde_len
;
1455 if ((version
== WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
||
1456 sm
->wpa_key_mgmt
== WPA_KEY_MGMT_OWE
||
1457 sm
->wpa_key_mgmt
== WPA_KEY_MGMT_OSEN
||
1458 wpa_key_mgmt_suite_b(sm
->wpa_key_mgmt
) ||
1459 version
== WPA_KEY_INFO_TYPE_AES_128_CMAC
) && encr
) {
1460 pad_len
= key_data_len
% 8;
1462 pad_len
= 8 - pad_len
;
1463 key_data_len
+= pad_len
+ 8;
1466 len
+= key_data_len
;
1467 if (!mic_len
&& encr
)
1468 len
+= AES_BLOCK_SIZE
;
1470 hdr
= os_zalloc(len
);
1473 hdr
->version
= wpa_auth
->conf
.eapol_version
;
1474 hdr
->type
= IEEE802_1X_TYPE_EAPOL_KEY
;
1475 hdr
->length
= host_to_be16(len
- sizeof(*hdr
));
1476 key
= (struct wpa_eapol_key
*) (hdr
+ 1);
1477 key_mic
= (u8
*) (key
+ 1);
1478 key_data
= ((u8
*) (hdr
+ 1)) + keyhdrlen
;
1480 key
->type
= sm
->wpa
== WPA_VERSION_WPA2
?
1481 EAPOL_KEY_TYPE_RSN
: EAPOL_KEY_TYPE_WPA
;
1482 key_info
|= version
;
1483 if (encr
&& sm
->wpa
== WPA_VERSION_WPA2
)
1484 key_info
|= WPA_KEY_INFO_ENCR_KEY_DATA
;
1485 if (sm
->wpa
!= WPA_VERSION_WPA2
)
1486 key_info
|= keyidx
<< WPA_KEY_INFO_KEY_INDEX_SHIFT
;
1487 WPA_PUT_BE16(key
->key_info
, key_info
);
1489 alg
= pairwise
? sm
->pairwise
: wpa_auth
->conf
.wpa_group
;
1490 if ((key_info
& WPA_KEY_INFO_SMK_MESSAGE
) ||
1491 (sm
->wpa
== WPA_VERSION_WPA2
&& !pairwise
))
1492 WPA_PUT_BE16(key
->key_length
, 0);
1494 WPA_PUT_BE16(key
->key_length
, wpa_cipher_key_len(alg
));
1496 /* FIX: STSL: what to use as key_replay_counter? */
1497 for (i
= RSNA_MAX_EAPOL_RETRIES
- 1; i
> 0; i
--) {
1498 sm
->key_replay
[i
].valid
= sm
->key_replay
[i
- 1].valid
;
1499 os_memcpy(sm
->key_replay
[i
].counter
,
1500 sm
->key_replay
[i
- 1].counter
,
1501 WPA_REPLAY_COUNTER_LEN
);
1503 inc_byte_array(sm
->key_replay
[0].counter
, WPA_REPLAY_COUNTER_LEN
);
1504 os_memcpy(key
->replay_counter
, sm
->key_replay
[0].counter
,
1505 WPA_REPLAY_COUNTER_LEN
);
1506 wpa_hexdump(MSG_DEBUG
, "WPA: Replay Counter",
1507 key
->replay_counter
, WPA_REPLAY_COUNTER_LEN
);
1508 sm
->key_replay
[0].valid
= TRUE
;
1511 os_memcpy(key
->key_nonce
, nonce
, WPA_NONCE_LEN
);
1514 os_memcpy(key
->key_rsc
, key_rsc
, WPA_KEY_RSC_LEN
);
1517 os_memcpy(key_data
, kde
, kde_len
);
1518 WPA_PUT_BE16(key_mic
+ mic_len
, kde_len
);
1520 } else if (!mic_len
) {
1524 WPA_PUT_BE16(key_mic
, AES_BLOCK_SIZE
+ kde_len
);
1525 wpa_hexdump_key(MSG_DEBUG
, "Plaintext EAPOL-Key Key Data",
1528 wpa_hexdump_key(MSG_DEBUG
, "WPA: KEK",
1529 sm
->PTK
.kek
, sm
->PTK
.kek_len
);
1530 /* AES-SIV AAD from EAPOL protocol version field (inclusive) to
1531 * to Key Data (exclusive). */
1532 aad
[0] = (u8
*) hdr
;
1533 aad_len
[0] = key_mic
+ 2 - (u8
*) hdr
;
1534 if (aes_siv_encrypt(sm
->PTK
.kek
, sm
->PTK
.kek_len
, kde
, kde_len
,
1535 1, aad
, aad_len
, key_mic
+ 2) < 0) {
1536 wpa_printf(MSG_DEBUG
, "WPA: AES-SIV encryption failed");
1540 wpa_hexdump(MSG_DEBUG
, "WPA: Encrypted Key Data from SIV",
1541 key_mic
+ 2, AES_BLOCK_SIZE
+ kde_len
);
1542 #endif /* CONFIG_FILS */
1543 } else if (encr
&& kde
) {
1544 buf
= os_zalloc(key_data_len
);
1550 os_memcpy(pos
, kde
, kde_len
);
1556 wpa_hexdump_key(MSG_DEBUG
, "Plaintext EAPOL-Key Key Data",
1558 if (version
== WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
||
1559 sm
->wpa_key_mgmt
== WPA_KEY_MGMT_OWE
||
1560 sm
->wpa_key_mgmt
== WPA_KEY_MGMT_OSEN
||
1561 wpa_key_mgmt_suite_b(sm
->wpa_key_mgmt
) ||
1562 version
== WPA_KEY_INFO_TYPE_AES_128_CMAC
) {
1563 wpa_printf(MSG_DEBUG
,
1564 "WPA: Encrypt Key Data using AES-WRAP (KEK length %u)",
1565 (unsigned int) sm
->PTK
.kek_len
);
1566 if (aes_wrap(sm
->PTK
.kek
, sm
->PTK
.kek_len
,
1567 (key_data_len
- 8) / 8, buf
, key_data
)) {
1572 WPA_PUT_BE16(key_mic
+ mic_len
, key_data_len
);
1573 #ifndef CONFIG_NO_RC4
1574 } else if (sm
->PTK
.kek_len
== 16) {
1577 wpa_printf(MSG_DEBUG
,
1578 "WPA: Encrypt Key Data using RC4");
1579 os_memcpy(key
->key_iv
,
1580 sm
->group
->Counter
+ WPA_NONCE_LEN
- 16, 16);
1581 inc_byte_array(sm
->group
->Counter
, WPA_NONCE_LEN
);
1582 os_memcpy(ek
, key
->key_iv
, 16);
1583 os_memcpy(ek
+ 16, sm
->PTK
.kek
, sm
->PTK
.kek_len
);
1584 os_memcpy(key_data
, buf
, key_data_len
);
1585 rc4_skip(ek
, 32, 256, key_data
, key_data_len
);
1586 WPA_PUT_BE16(key_mic
+ mic_len
, key_data_len
);
1587 #endif /* CONFIG_NO_RC4 */
1596 if (key_info
& WPA_KEY_INFO_MIC
) {
1597 if (!sm
->PTK_valid
|| !mic_len
) {
1598 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
1599 "PTK not valid when sending EAPOL-Key "
1605 wpa_eapol_key_mic(sm
->PTK
.kck
, sm
->PTK
.kck_len
,
1606 sm
->wpa_key_mgmt
, version
,
1607 (u8
*) hdr
, len
, key_mic
);
1608 #ifdef CONFIG_TESTING_OPTIONS
1610 wpa_auth
->conf
.corrupt_gtk_rekey_mic_probability
> 0.0 &&
1612 wpa_auth
->conf
.corrupt_gtk_rekey_mic_probability
) {
1613 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1614 "Corrupting group EAPOL-Key Key MIC");
1617 #endif /* CONFIG_TESTING_OPTIONS */
1620 wpa_auth_set_eapol(sm
->wpa_auth
, sm
->addr
, WPA_EAPOL_inc_EapolFramesTx
,
1622 wpa_auth_send_eapol(wpa_auth
, sm
->addr
, (u8
*) hdr
, len
,
1628 static void wpa_send_eapol(struct wpa_authenticator
*wpa_auth
,
1629 struct wpa_state_machine
*sm
, int key_info
,
1630 const u8
*key_rsc
, const u8
*nonce
,
1631 const u8
*kde
, size_t kde_len
,
1632 int keyidx
, int encr
)
1635 int pairwise
= key_info
& WPA_KEY_INFO_KEY_TYPE
;
1641 __wpa_send_eapol(wpa_auth
, sm
, key_info
, key_rsc
, nonce
, kde
, kde_len
,
1644 ctr
= pairwise
? sm
->TimeoutCtr
: sm
->GTimeoutCtr
;
1645 if (ctr
== 1 && wpa_auth
->conf
.tx_status
)
1646 timeout_ms
= pairwise
? eapol_key_timeout_first
:
1647 eapol_key_timeout_first_group
;
1649 timeout_ms
= eapol_key_timeout_subseq
;
1650 if (pairwise
&& ctr
== 1 && !(key_info
& WPA_KEY_INFO_MIC
))
1651 sm
->pending_1_of_4_timeout
= 1;
1652 wpa_printf(MSG_DEBUG
, "WPA: Use EAPOL-Key timeout of %u ms (retry "
1653 "counter %u)", timeout_ms
, ctr
);
1654 eloop_register_timeout(timeout_ms
/ 1000, (timeout_ms
% 1000) * 1000,
1655 wpa_send_eapol_timeout
, wpa_auth
, sm
);
1659 static int wpa_verify_key_mic(int akmp
, struct wpa_ptk
*PTK
, u8
*data
,
1662 struct ieee802_1x_hdr
*hdr
;
1663 struct wpa_eapol_key
*key
;
1666 u8 mic
[WPA_EAPOL_KEY_MIC_MAX_LEN
], *mic_pos
;
1667 size_t mic_len
= wpa_mic_len(akmp
);
1669 if (data_len
< sizeof(*hdr
) + sizeof(*key
))
1672 hdr
= (struct ieee802_1x_hdr
*) data
;
1673 key
= (struct wpa_eapol_key
*) (hdr
+ 1);
1674 mic_pos
= (u8
*) (key
+ 1);
1675 key_info
= WPA_GET_BE16(key
->key_info
);
1676 os_memcpy(mic
, mic_pos
, mic_len
);
1677 os_memset(mic_pos
, 0, mic_len
);
1678 if (wpa_eapol_key_mic(PTK
->kck
, PTK
->kck_len
, akmp
,
1679 key_info
& WPA_KEY_INFO_TYPE_MASK
,
1680 data
, data_len
, mic_pos
) ||
1681 os_memcmp_const(mic
, mic_pos
, mic_len
) != 0)
1683 os_memcpy(mic_pos
, mic
, mic_len
);
1688 void wpa_remove_ptk(struct wpa_state_machine
*sm
)
1690 sm
->PTK_valid
= FALSE
;
1691 os_memset(&sm
->PTK
, 0, sizeof(sm
->PTK
));
1692 if (wpa_auth_set_key(sm
->wpa_auth
, 0, WPA_ALG_NONE
, sm
->addr
, 0, NULL
,
1694 wpa_printf(MSG_DEBUG
,
1695 "RSN: PTK removal from the driver failed");
1696 sm
->pairwise_set
= FALSE
;
1697 eloop_cancel_timeout(wpa_rekey_ptk
, sm
->wpa_auth
, sm
);
1701 int wpa_auth_sm_event(struct wpa_state_machine
*sm
, enum wpa_event event
)
1708 wpa_auth_vlogger(sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
1709 "event %d notification", event
);
1714 /* PTKs are derived through AMPE */
1715 if (wpa_auth_start_ampe(sm
->wpa_auth
, sm
->addr
)) {
1720 #endif /* CONFIG_MESH */
1725 sm
->DeauthenticationRequest
= TRUE
;
1728 case WPA_REAUTH_EAPOL
:
1731 * When using WPS, we may end up here if the STA
1732 * manages to re-associate without the previous STA
1733 * entry getting removed. Consequently, we need to make
1734 * sure that the WPA state machines gets initialized
1735 * properly at this point.
1737 wpa_printf(MSG_DEBUG
, "WPA state machine had not been "
1738 "started - initialize now");
1741 if (wpa_sm_step(sm
) == 1)
1742 return 1; /* should not really happen */
1744 sm
->AuthenticationRequest
= TRUE
;
1747 if (sm
->GUpdateStationKeys
) {
1749 * Reauthentication cancels the pending group key
1750 * update for this STA.
1752 sm
->group
->GKeyDoneStations
--;
1753 sm
->GUpdateStationKeys
= FALSE
;
1754 sm
->PtkGroupInit
= TRUE
;
1756 sm
->ReAuthenticationRequest
= TRUE
;
1759 #ifdef CONFIG_IEEE80211R_AP
1760 wpa_printf(MSG_DEBUG
, "FT: Retry PTK configuration "
1761 "after association");
1762 wpa_ft_install_ptk(sm
);
1764 /* Using FT protocol, not WPA auth state machine */
1765 sm
->ft_completed
= 1;
1767 #else /* CONFIG_IEEE80211R_AP */
1769 #endif /* CONFIG_IEEE80211R_AP */
1770 case WPA_ASSOC_FILS
:
1772 wpa_printf(MSG_DEBUG
,
1773 "FILS: TK configuration after association");
1775 sm
->fils_completed
= 1;
1777 #else /* CONFIG_FILS */
1779 #endif /* CONFIG_FILS */
1782 #ifdef CONFIG_IEEE80211R_AP
1783 sm
->ft_completed
= 0;
1784 #endif /* CONFIG_IEEE80211R_AP */
1786 #ifdef CONFIG_IEEE80211W
1787 if (sm
->mgmt_frame_prot
&& event
== WPA_AUTH
)
1789 #endif /* CONFIG_IEEE80211W */
1791 if (wpa_key_mgmt_fils(sm
->wpa_key_mgmt
) &&
1792 (event
== WPA_AUTH
|| event
== WPA_ASSOC
))
1794 #endif /* CONFIG_FILS */
1797 sm
->PTK_valid
= FALSE
;
1798 os_memset(&sm
->PTK
, 0, sizeof(sm
->PTK
));
1800 if (event
!= WPA_REAUTH_EAPOL
)
1804 if (sm
->in_step_loop
) {
1806 * wpa_sm_step() is already running - avoid recursive call to
1807 * it by making the existing loop process the new update.
1812 return wpa_sm_step(sm
);
1816 SM_STATE(WPA_PTK
, INITIALIZE
)
1818 SM_ENTRY_MA(WPA_PTK
, INITIALIZE
, wpa_ptk
);
1820 /* Init flag is not cleared here, so avoid busy
1821 * loop by claiming nothing changed. */
1822 sm
->changed
= FALSE
;
1826 if (sm
->GUpdateStationKeys
)
1827 sm
->group
->GKeyDoneStations
--;
1828 sm
->GUpdateStationKeys
= FALSE
;
1829 if (sm
->wpa
== WPA_VERSION_WPA
)
1830 sm
->PInitAKeys
= FALSE
;
1831 if (1 /* Unicast cipher supported AND (ESS OR ((IBSS or WDS) and
1832 * Local AA > Remote AA)) */) {
1835 wpa_auth_set_eapol(sm
->wpa_auth
, sm
->addr
, WPA_EAPOL_portEnabled
, 0);
1837 wpa_auth_set_eapol(sm
->wpa_auth
, sm
->addr
, WPA_EAPOL_portValid
, 0);
1839 if (wpa_key_mgmt_wpa_psk(sm
->wpa_key_mgmt
) ||
1840 sm
->wpa_key_mgmt
== WPA_KEY_MGMT_OWE
) {
1841 wpa_auth_set_eapol(sm
->wpa_auth
, sm
->addr
,
1842 WPA_EAPOL_authorized
, 0);
1847 SM_STATE(WPA_PTK
, DISCONNECT
)
1849 SM_ENTRY_MA(WPA_PTK
, DISCONNECT
, wpa_ptk
);
1850 sm
->Disconnect
= FALSE
;
1851 wpa_sta_disconnect(sm
->wpa_auth
, sm
->addr
);
1855 SM_STATE(WPA_PTK
, DISCONNECTED
)
1857 SM_ENTRY_MA(WPA_PTK
, DISCONNECTED
, wpa_ptk
);
1858 sm
->DeauthenticationRequest
= FALSE
;
1862 SM_STATE(WPA_PTK
, AUTHENTICATION
)
1864 SM_ENTRY_MA(WPA_PTK
, AUTHENTICATION
, wpa_ptk
);
1865 os_memset(&sm
->PTK
, 0, sizeof(sm
->PTK
));
1866 sm
->PTK_valid
= FALSE
;
1867 wpa_auth_set_eapol(sm
->wpa_auth
, sm
->addr
, WPA_EAPOL_portControl_Auto
,
1869 wpa_auth_set_eapol(sm
->wpa_auth
, sm
->addr
, WPA_EAPOL_portEnabled
, 1);
1870 sm
->AuthenticationRequest
= FALSE
;
1874 static void wpa_group_ensure_init(struct wpa_authenticator
*wpa_auth
,
1875 struct wpa_group
*group
)
1877 if (group
->first_sta_seen
)
1880 * System has run bit further than at the time hostapd was started
1881 * potentially very early during boot up. This provides better chances
1882 * of collecting more randomness on embedded systems. Re-initialize the
1883 * GMK and Counter here to improve their strength if there was not
1884 * enough entropy available immediately after system startup.
1886 wpa_printf(MSG_DEBUG
, "WPA: Re-initialize GMK/Counter on first "
1888 if (random_pool_ready() != 1) {
1889 wpa_printf(MSG_INFO
, "WPA: Not enough entropy in random pool "
1890 "to proceed - reject first 4-way handshake");
1891 group
->reject_4way_hs_for_entropy
= TRUE
;
1893 group
->first_sta_seen
= TRUE
;
1894 group
->reject_4way_hs_for_entropy
= FALSE
;
1897 if (wpa_group_init_gmk_and_counter(wpa_auth
, group
) < 0 ||
1898 wpa_gtk_update(wpa_auth
, group
) < 0 ||
1899 wpa_group_config_group_keys(wpa_auth
, group
) < 0) {
1900 wpa_printf(MSG_INFO
, "WPA: GMK/GTK setup failed");
1901 group
->first_sta_seen
= FALSE
;
1902 group
->reject_4way_hs_for_entropy
= TRUE
;
1907 SM_STATE(WPA_PTK
, AUTHENTICATION2
)
1909 SM_ENTRY_MA(WPA_PTK
, AUTHENTICATION2
, wpa_ptk
);
1911 wpa_group_ensure_init(sm
->wpa_auth
, sm
->group
);
1912 sm
->ReAuthenticationRequest
= FALSE
;
1915 * Definition of ANonce selection in IEEE Std 802.11i-2004 is somewhat
1916 * ambiguous. The Authenticator state machine uses a counter that is
1917 * incremented by one for each 4-way handshake. However, the security
1918 * analysis of 4-way handshake points out that unpredictable nonces
1919 * help in preventing precomputation attacks. Instead of the state
1920 * machine definition, use an unpredictable nonce value here to provide
1921 * stronger protection against potential precomputation attacks.
1923 if (random_get_bytes(sm
->ANonce
, WPA_NONCE_LEN
)) {
1924 wpa_printf(MSG_ERROR
, "WPA: Failed to get random data for "
1926 sm
->Disconnect
= TRUE
;
1929 wpa_hexdump(MSG_DEBUG
, "WPA: Assign ANonce", sm
->ANonce
,
1931 /* IEEE 802.11i does not clear TimeoutCtr here, but this is more
1932 * logical place than INITIALIZE since AUTHENTICATION2 can be
1933 * re-entered on ReAuthenticationRequest without going through
1939 SM_STATE(WPA_PTK
, INITPMK
)
1941 u8 msk
[2 * PMK_LEN
];
1942 size_t len
= 2 * PMK_LEN
;
1944 SM_ENTRY_MA(WPA_PTK
, INITPMK
, wpa_ptk
);
1945 #ifdef CONFIG_IEEE80211R_AP
1947 #endif /* CONFIG_IEEE80211R_AP */
1949 wpa_printf(MSG_DEBUG
, "WPA: PMK from PMKSA cache");
1950 os_memcpy(sm
->PMK
, sm
->pmksa
->pmk
, sm
->pmksa
->pmk_len
);
1951 sm
->pmk_len
= sm
->pmksa
->pmk_len
;
1952 } else if (wpa_auth_get_msk(sm
->wpa_auth
, sm
->addr
, msk
, &len
) == 0) {
1953 unsigned int pmk_len
;
1955 if (wpa_key_mgmt_sha384(sm
->wpa_key_mgmt
))
1956 pmk_len
= PMK_LEN_SUITE_B_192
;
1959 wpa_printf(MSG_DEBUG
, "WPA: PMK from EAPOL state machine "
1960 "(MSK len=%lu PMK len=%u)", (unsigned long) len
,
1962 if (len
< pmk_len
) {
1963 wpa_printf(MSG_DEBUG
,
1964 "WPA: MSK not long enough (%u) to create PMK (%u)",
1965 (unsigned int) len
, (unsigned int) pmk_len
);
1966 sm
->Disconnect
= TRUE
;
1969 os_memcpy(sm
->PMK
, msk
, pmk_len
);
1970 sm
->pmk_len
= pmk_len
;
1971 #ifdef CONFIG_IEEE80211R_AP
1972 if (len
>= 2 * PMK_LEN
) {
1973 os_memcpy(sm
->xxkey
, msk
+ PMK_LEN
, PMK_LEN
);
1974 sm
->xxkey_len
= PMK_LEN
;
1976 #endif /* CONFIG_IEEE80211R_AP */
1978 wpa_printf(MSG_DEBUG
, "WPA: Could not get PMK, get_msk: %p",
1979 sm
->wpa_auth
->cb
->get_msk
);
1980 sm
->Disconnect
= TRUE
;
1983 os_memset(msk
, 0, sizeof(msk
));
1985 sm
->req_replay_counter_used
= 0;
1986 /* IEEE 802.11i does not set keyRun to FALSE, but not doing this
1987 * will break reauthentication since EAPOL state machines may not be
1988 * get into AUTHENTICATING state that clears keyRun before WPA state
1989 * machine enters AUTHENTICATION2 state and goes immediately to INITPMK
1990 * state and takes PMK from the previously used AAA Key. This will
1991 * eventually fail in 4-Way Handshake because Supplicant uses PMK
1992 * derived from the new AAA Key. Setting keyRun = FALSE here seems to
1993 * be good workaround for this issue. */
1994 wpa_auth_set_eapol(sm
->wpa_auth
, sm
->addr
, WPA_EAPOL_keyRun
, 0);
1998 SM_STATE(WPA_PTK
, INITPSK
)
2001 SM_ENTRY_MA(WPA_PTK
, INITPSK
, wpa_ptk
);
2002 psk
= wpa_auth_get_psk(sm
->wpa_auth
, sm
->addr
, sm
->p2p_dev_addr
, NULL
);
2004 os_memcpy(sm
->PMK
, psk
, PMK_LEN
);
2005 sm
->pmk_len
= PMK_LEN
;
2006 #ifdef CONFIG_IEEE80211R_AP
2007 os_memcpy(sm
->xxkey
, psk
, PMK_LEN
);
2008 sm
->xxkey_len
= PMK_LEN
;
2009 #endif /* CONFIG_IEEE80211R_AP */
2011 sm
->req_replay_counter_used
= 0;
2015 SM_STATE(WPA_PTK
, PTKSTART
)
2017 u8 buf
[2 + RSN_SELECTOR_LEN
+ PMKID_LEN
], *pmkid
= NULL
;
2018 size_t pmkid_len
= 0;
2020 SM_ENTRY_MA(WPA_PTK
, PTKSTART
, wpa_ptk
);
2021 sm
->PTKRequest
= FALSE
;
2022 sm
->TimeoutEvt
= FALSE
;
2023 sm
->alt_snonce_valid
= FALSE
;
2026 if (sm
->TimeoutCtr
> sm
->wpa_auth
->conf
.wpa_pairwise_update_count
) {
2027 /* No point in sending the EAPOL-Key - we will disconnect
2028 * immediately following this. */
2032 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
2033 "sending 1/4 msg of 4-Way Handshake");
2035 * TODO: Could add PMKID even with WPA2-PSK, but only if there is only
2036 * one possible PSK for this STA.
2038 if (sm
->wpa
== WPA_VERSION_WPA2
&&
2039 wpa_key_mgmt_wpa_ieee8021x(sm
->wpa_key_mgmt
) &&
2040 sm
->wpa_key_mgmt
!= WPA_KEY_MGMT_OSEN
) {
2042 pmkid_len
= 2 + RSN_SELECTOR_LEN
+ PMKID_LEN
;
2043 pmkid
[0] = WLAN_EID_VENDOR_SPECIFIC
;
2044 pmkid
[1] = RSN_SELECTOR_LEN
+ PMKID_LEN
;
2045 RSN_SELECTOR_PUT(&pmkid
[2], RSN_KEY_DATA_PMKID
);
2047 os_memcpy(&pmkid
[2 + RSN_SELECTOR_LEN
],
2048 sm
->pmksa
->pmkid
, PMKID_LEN
);
2049 } else if (wpa_key_mgmt_suite_b(sm
->wpa_key_mgmt
)) {
2050 /* No KCK available to derive PMKID */
2054 * Calculate PMKID since no PMKSA cache entry was
2055 * available with pre-calculated PMKID.
2057 rsn_pmkid(sm
->PMK
, sm
->pmk_len
, sm
->wpa_auth
->addr
,
2058 sm
->addr
, &pmkid
[2 + RSN_SELECTOR_LEN
],
2059 wpa_key_mgmt_sha256(sm
->wpa_key_mgmt
));
2062 wpa_send_eapol(sm
->wpa_auth
, sm
,
2063 WPA_KEY_INFO_ACK
| WPA_KEY_INFO_KEY_TYPE
, NULL
,
2064 sm
->ANonce
, pmkid
, pmkid_len
, 0, 0);
2068 static int wpa_derive_ptk(struct wpa_state_machine
*sm
, const u8
*snonce
,
2069 const u8
*pmk
, unsigned int pmk_len
,
2070 struct wpa_ptk
*ptk
)
2072 #ifdef CONFIG_IEEE80211R_AP
2073 if (wpa_key_mgmt_ft(sm
->wpa_key_mgmt
))
2074 return wpa_auth_derive_ptk_ft(sm
, pmk
, ptk
);
2075 #endif /* CONFIG_IEEE80211R_AP */
2077 return wpa_pmk_to_ptk(pmk
, pmk_len
, "Pairwise key expansion",
2078 sm
->wpa_auth
->addr
, sm
->addr
, sm
->ANonce
, snonce
,
2079 ptk
, sm
->wpa_key_mgmt
, sm
->pairwise
);
2085 int fils_auth_pmk_to_ptk(struct wpa_state_machine
*sm
, const u8
*pmk
,
2086 size_t pmk_len
, const u8
*snonce
, const u8
*anonce
,
2087 struct wpabuf
*g_sta
, struct wpabuf
*g_ap
)
2089 u8 ick
[FILS_ICK_MAX_LEN
];
2092 u8 fils_ft
[FILS_FT_MAX_LEN
];
2093 size_t fils_ft_len
= 0;
2095 res
= fils_pmk_to_ptk(pmk
, pmk_len
, sm
->addr
, sm
->wpa_auth
->addr
,
2096 snonce
, anonce
, &sm
->PTK
, ick
, &ick_len
,
2097 sm
->wpa_key_mgmt
, sm
->pairwise
,
2098 fils_ft
, &fils_ft_len
);
2101 sm
->PTK_valid
= TRUE
;
2103 #ifdef CONFIG_IEEE80211R_AP
2105 struct wpa_authenticator
*wpa_auth
= sm
->wpa_auth
;
2106 struct wpa_auth_config
*conf
= &wpa_auth
->conf
;
2107 u8 pmk_r0
[PMK_LEN
], pmk_r0_name
[WPA_PMK_NAME_LEN
];
2109 if (wpa_derive_pmk_r0(fils_ft
, fils_ft_len
,
2110 conf
->ssid
, conf
->ssid_len
,
2111 conf
->mobility_domain
,
2112 conf
->r0_key_holder
,
2113 conf
->r0_key_holder_len
,
2114 sm
->addr
, pmk_r0
, pmk_r0_name
) < 0)
2117 wpa_hexdump_key(MSG_DEBUG
, "FILS+FT: PMK-R0", pmk_r0
, PMK_LEN
);
2118 wpa_hexdump(MSG_DEBUG
, "FILS+FT: PMKR0Name",
2119 pmk_r0_name
, WPA_PMK_NAME_LEN
);
2120 wpa_ft_store_pmk_r0(wpa_auth
, sm
->addr
, pmk_r0
, pmk_r0_name
,
2122 os_memset(fils_ft
, 0, sizeof(fils_ft
));
2124 #endif /* CONFIG_IEEE80211R_AP */
2126 res
= fils_key_auth_sk(ick
, ick_len
, snonce
, anonce
,
2127 sm
->addr
, sm
->wpa_auth
->addr
,
2128 g_sta
? wpabuf_head(g_sta
) : NULL
,
2129 g_sta
? wpabuf_len(g_sta
) : 0,
2130 g_ap
? wpabuf_head(g_ap
) : NULL
,
2131 g_ap
? wpabuf_len(g_ap
) : 0,
2132 sm
->wpa_key_mgmt
, sm
->fils_key_auth_sta
,
2133 sm
->fils_key_auth_ap
,
2134 &sm
->fils_key_auth_len
);
2135 os_memset(ick
, 0, sizeof(ick
));
2137 /* Store nonces for (Re)Association Request/Response frame processing */
2138 os_memcpy(sm
->SNonce
, snonce
, FILS_NONCE_LEN
);
2139 os_memcpy(sm
->ANonce
, anonce
, FILS_NONCE_LEN
);
2145 static int wpa_aead_decrypt(struct wpa_state_machine
*sm
, struct wpa_ptk
*ptk
,
2146 u8
*buf
, size_t buf_len
, u16
*_key_data_len
)
2148 struct ieee802_1x_hdr
*hdr
;
2149 struct wpa_eapol_key
*key
;
2156 hdr
= (struct ieee802_1x_hdr
*) buf
;
2157 key
= (struct wpa_eapol_key
*) (hdr
+ 1);
2158 pos
= (u8
*) (key
+ 1);
2159 key_data_len
= WPA_GET_BE16(pos
);
2160 if (key_data_len
< AES_BLOCK_SIZE
||
2161 key_data_len
> buf_len
- sizeof(*hdr
) - sizeof(*key
) - 2) {
2162 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_INFO
,
2163 "No room for AES-SIV data in the frame");
2166 pos
+= 2; /* Pointing at the Encrypted Key Data field */
2168 tmp
= os_malloc(key_data_len
);
2172 /* AES-SIV AAD from EAPOL protocol version field (inclusive) to
2173 * to Key Data (exclusive). */
2175 aad_len
[0] = pos
- buf
;
2176 if (aes_siv_decrypt(ptk
->kek
, ptk
->kek_len
, pos
, key_data_len
,
2177 1, aad
, aad_len
, tmp
) < 0) {
2178 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_INFO
,
2179 "Invalid AES-SIV data in the frame");
2180 bin_clear_free(tmp
, key_data_len
);
2184 /* AEAD decryption and validation completed successfully */
2185 key_data_len
-= AES_BLOCK_SIZE
;
2186 wpa_hexdump_key(MSG_DEBUG
, "WPA: Decrypted Key Data",
2189 /* Replace Key Data field with the decrypted version */
2190 os_memcpy(pos
, tmp
, key_data_len
);
2191 pos
-= 2; /* Key Data Length field */
2192 WPA_PUT_BE16(pos
, key_data_len
);
2193 bin_clear_free(tmp
, key_data_len
);
2195 *_key_data_len
= key_data_len
;
2200 const u8
* wpa_fils_validate_fils_session(struct wpa_state_machine
*sm
,
2201 const u8
*ies
, size_t ies_len
,
2202 const u8
*fils_session
)
2205 const u8
*session
= NULL
;
2207 if (!wpa_key_mgmt_fils(sm
->wpa_key_mgmt
)) {
2208 wpa_printf(MSG_DEBUG
,
2209 "FILS: Not a FILS AKM - reject association");
2213 /* Verify Session element */
2215 end
= ((const u8
*) ie
) + ies_len
;
2216 while (ie
+ 1 < end
) {
2217 if (ie
+ 2 + ie
[1] > end
)
2219 if (ie
[0] == WLAN_EID_EXTENSION
&&
2220 ie
[1] >= 1 + FILS_SESSION_LEN
&&
2221 ie
[2] == WLAN_EID_EXT_FILS_SESSION
) {
2229 wpa_printf(MSG_DEBUG
,
2230 "FILS: %s: Could not find FILS Session element in Assoc Req - reject",
2235 if (!fils_session
) {
2236 wpa_printf(MSG_DEBUG
,
2237 "FILS: %s: Could not find FILS Session element in STA entry - reject",
2242 if (os_memcmp(fils_session
, session
+ 3, FILS_SESSION_LEN
) != 0) {
2243 wpa_printf(MSG_DEBUG
, "FILS: Session mismatch");
2244 wpa_hexdump(MSG_DEBUG
, "FILS: Expected FILS Session",
2245 fils_session
, FILS_SESSION_LEN
);
2246 wpa_hexdump(MSG_DEBUG
, "FILS: Received FILS Session",
2247 session
+ 3, FILS_SESSION_LEN
);
2254 int wpa_fils_validate_key_confirm(struct wpa_state_machine
*sm
, const u8
*ies
,
2257 struct ieee802_11_elems elems
;
2259 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
) {
2260 wpa_printf(MSG_DEBUG
,
2261 "FILS: Failed to parse decrypted elements");
2265 if (!elems
.fils_key_confirm
) {
2266 wpa_printf(MSG_DEBUG
, "FILS: No FILS Key Confirm element");
2270 if (elems
.fils_key_confirm_len
!= sm
->fils_key_auth_len
) {
2271 wpa_printf(MSG_DEBUG
,
2272 "FILS: Unexpected Key-Auth length %d (expected %d)",
2273 elems
.fils_key_confirm_len
,
2274 (int) sm
->fils_key_auth_len
);
2278 if (os_memcmp(elems
.fils_key_confirm
, sm
->fils_key_auth_sta
,
2279 sm
->fils_key_auth_len
) != 0) {
2280 wpa_printf(MSG_DEBUG
, "FILS: Key-Auth mismatch");
2281 wpa_hexdump(MSG_DEBUG
, "FILS: Received Key-Auth",
2282 elems
.fils_key_confirm
, elems
.fils_key_confirm_len
);
2283 wpa_hexdump(MSG_DEBUG
, "FILS: Expected Key-Auth",
2284 sm
->fils_key_auth_sta
, sm
->fils_key_auth_len
);
2292 int fils_decrypt_assoc(struct wpa_state_machine
*sm
, const u8
*fils_session
,
2293 const struct ieee80211_mgmt
*mgmt
, size_t frame_len
,
2294 u8
*pos
, size_t left
)
2297 const u8
*end
, *ie_start
, *ie
, *session
, *crypt
;
2301 if (!sm
|| !sm
->PTK_valid
) {
2302 wpa_printf(MSG_DEBUG
,
2303 "FILS: No KEK to decrypt Assocication Request frame");
2307 if (!wpa_key_mgmt_fils(sm
->wpa_key_mgmt
)) {
2308 wpa_printf(MSG_DEBUG
,
2309 "FILS: Not a FILS AKM - reject association");
2313 end
= ((const u8
*) mgmt
) + frame_len
;
2314 fc
= le_to_host16(mgmt
->frame_control
);
2315 stype
= WLAN_FC_GET_STYPE(fc
);
2316 if (stype
== WLAN_FC_STYPE_REASSOC_REQ
)
2317 ie_start
= mgmt
->u
.reassoc_req
.variable
;
2319 ie_start
= mgmt
->u
.assoc_req
.variable
;
2323 * Find FILS Session element which is the last unencrypted element in
2326 session
= wpa_fils_validate_fils_session(sm
, ie
, end
- ie
,
2329 wpa_printf(MSG_DEBUG
, "FILS: Session validation failed");
2333 crypt
= session
+ 2 + session
[1];
2335 if (end
- crypt
< AES_BLOCK_SIZE
) {
2336 wpa_printf(MSG_DEBUG
,
2337 "FILS: Too short frame to include AES-SIV data");
2341 /* AES-SIV AAD vectors */
2343 /* The STA's MAC address */
2345 aad_len
[0] = ETH_ALEN
;
2346 /* The AP's BSSID */
2348 aad_len
[1] = ETH_ALEN
;
2349 /* The STA's nonce */
2350 aad
[2] = sm
->SNonce
;
2351 aad_len
[2] = FILS_NONCE_LEN
;
2352 /* The AP's nonce */
2353 aad
[3] = sm
->ANonce
;
2354 aad_len
[3] = FILS_NONCE_LEN
;
2356 * The (Re)Association Request frame from the Capability Information
2357 * field to the FILS Session element (both inclusive).
2359 aad
[4] = (const u8
*) &mgmt
->u
.assoc_req
.capab_info
;
2360 aad_len
[4] = crypt
- aad
[4];
2362 if (aes_siv_decrypt(sm
->PTK
.kek
, sm
->PTK
.kek_len
, crypt
, end
- crypt
,
2363 5, aad
, aad_len
, pos
+ (crypt
- ie_start
)) < 0) {
2364 wpa_printf(MSG_DEBUG
,
2365 "FILS: Invalid AES-SIV data in the frame");
2368 wpa_hexdump(MSG_DEBUG
, "FILS: Decrypted Association Request elements",
2369 pos
, left
- AES_BLOCK_SIZE
);
2371 if (wpa_fils_validate_key_confirm(sm
, pos
, left
- AES_BLOCK_SIZE
) < 0) {
2372 wpa_printf(MSG_DEBUG
, "FILS: Key Confirm validation failed");
2376 return left
- AES_BLOCK_SIZE
;
2380 int fils_encrypt_assoc(struct wpa_state_machine
*sm
, u8
*buf
,
2381 size_t current_len
, size_t max_len
,
2382 const struct wpabuf
*hlp
)
2384 u8
*end
= buf
+ max_len
;
2385 u8
*pos
= buf
+ current_len
;
2386 struct ieee80211_mgmt
*mgmt
;
2387 struct wpabuf
*plain
;
2391 if (!sm
|| !sm
->PTK_valid
)
2394 wpa_hexdump(MSG_DEBUG
,
2395 "FILS: Association Response frame before FILS processing",
2398 mgmt
= (struct ieee80211_mgmt
*) buf
;
2400 /* AES-SIV AAD vectors */
2402 /* The AP's BSSID */
2404 aad_len
[0] = ETH_ALEN
;
2405 /* The STA's MAC address */
2407 aad_len
[1] = ETH_ALEN
;
2408 /* The AP's nonce */
2409 aad
[2] = sm
->ANonce
;
2410 aad_len
[2] = FILS_NONCE_LEN
;
2411 /* The STA's nonce */
2412 aad
[3] = sm
->SNonce
;
2413 aad_len
[3] = FILS_NONCE_LEN
;
2415 * The (Re)Association Response frame from the Capability Information
2416 * field (the same offset in both Association and Reassociation
2417 * Response frames) to the FILS Session element (both inclusive).
2419 aad
[4] = (const u8
*) &mgmt
->u
.assoc_resp
.capab_info
;
2420 aad_len
[4] = pos
- aad
[4];
2422 /* The following elements will be encrypted with AES-SIV */
2423 plain
= fils_prepare_plainbuf(sm
, hlp
);
2425 wpa_printf(MSG_DEBUG
, "FILS: Plain buffer prep failed");
2429 if (pos
+ wpabuf_len(plain
) + AES_BLOCK_SIZE
> end
) {
2430 wpa_printf(MSG_DEBUG
,
2431 "FILS: Not enough room for FILS elements");
2436 wpa_hexdump_buf_key(MSG_DEBUG
, "FILS: Association Response plaintext",
2439 if (aes_siv_encrypt(sm
->PTK
.kek
, sm
->PTK
.kek_len
,
2440 wpabuf_head(plain
), wpabuf_len(plain
),
2441 5, aad
, aad_len
, pos
) < 0) {
2446 wpa_hexdump(MSG_DEBUG
,
2447 "FILS: Encrypted Association Response elements",
2448 pos
, AES_BLOCK_SIZE
+ wpabuf_len(plain
));
2449 current_len
+= wpabuf_len(plain
) + AES_BLOCK_SIZE
;
2452 sm
->fils_completed
= 1;
2458 static struct wpabuf
* fils_prepare_plainbuf(struct wpa_state_machine
*sm
,
2459 const struct wpabuf
*hlp
)
2461 struct wpabuf
*plain
;
2462 u8
*len
, *tmp
, *tmp2
;
2464 u8
*gtk
, dummy_gtk
[32];
2466 struct wpa_group
*gsm
;
2468 plain
= wpabuf_alloc(1000);
2472 /* TODO: FILS Public Key */
2474 /* FILS Key Confirmation */
2475 wpabuf_put_u8(plain
, WLAN_EID_EXTENSION
); /* Element ID */
2476 wpabuf_put_u8(plain
, 1 + sm
->fils_key_auth_len
); /* Length */
2477 /* Element ID Extension */
2478 wpabuf_put_u8(plain
, WLAN_EID_EXT_FILS_KEY_CONFIRM
);
2479 wpabuf_put_data(plain
, sm
->fils_key_auth_ap
, sm
->fils_key_auth_len
);
2481 /* FILS HLP Container */
2483 wpabuf_put_buf(plain
, hlp
);
2485 /* TODO: FILS IP Address Assignment */
2489 wpabuf_put_u8(plain
, WLAN_EID_EXTENSION
); /* Element ID */
2490 len
= wpabuf_put(plain
, 1);
2491 wpabuf_put_u8(plain
, WLAN_EID_EXT_KEY_DELIVERY
);
2492 wpa_auth_get_seqnum(sm
->wpa_auth
, NULL
, gsm
->GN
,
2493 wpabuf_put(plain
, WPA_KEY_RSC_LEN
));
2495 gtk
= gsm
->GTK
[gsm
->GN
- 1];
2496 gtk_len
= gsm
->GTK_len
;
2497 if (sm
->wpa_auth
->conf
.disable_gtk
) {
2499 * Provide unique random GTK to each STA to prevent use
2500 * of GTK in the BSS.
2502 if (random_get_bytes(dummy_gtk
, gtk_len
) < 0) {
2508 hdr
[0] = gsm
->GN
& 0x03;
2510 tmp
= wpabuf_put(plain
, 0);
2511 tmp2
= wpa_add_kde(tmp
, RSN_KEY_DATA_GROUPKEY
, hdr
, 2,
2513 wpabuf_put(plain
, tmp2
- tmp
);
2516 tmp
= wpabuf_put(plain
, 0);
2517 tmp2
= ieee80211w_kde_add(sm
, tmp
);
2518 wpabuf_put(plain
, tmp2
- tmp
);
2520 *len
= (u8
*) wpabuf_put(plain
, 0) - len
- 1;
2525 int fils_set_tk(struct wpa_state_machine
*sm
)
2530 if (!sm
|| !sm
->PTK_valid
)
2533 alg
= wpa_cipher_to_alg(sm
->pairwise
);
2534 klen
= wpa_cipher_key_len(sm
->pairwise
);
2536 wpa_printf(MSG_DEBUG
, "FILS: Configure TK to the driver");
2537 if (wpa_auth_set_key(sm
->wpa_auth
, 0, alg
, sm
->addr
, 0,
2538 sm
->PTK
.tk
, klen
)) {
2539 wpa_printf(MSG_DEBUG
, "FILS: Failed to set TK to the driver");
2547 u8
* hostapd_eid_assoc_fils_session(struct wpa_state_machine
*sm
, u8
*buf
,
2548 const u8
*fils_session
)
2550 struct wpabuf
*plain
;
2554 *pos
++ = WLAN_EID_EXTENSION
; /* Element ID */
2555 *pos
++ = 1 + FILS_SESSION_LEN
; /* Length */
2556 *pos
++ = WLAN_EID_EXT_FILS_SESSION
; /* Element ID Extension */
2557 os_memcpy(pos
, fils_session
, FILS_SESSION_LEN
);
2558 pos
+= FILS_SESSION_LEN
;
2560 plain
= fils_prepare_plainbuf(sm
, NULL
);
2562 wpa_printf(MSG_DEBUG
, "FILS: Plain buffer prep failed");
2566 os_memcpy(pos
, wpabuf_head(plain
), wpabuf_len(plain
));
2567 pos
+= wpabuf_len(plain
);
2569 wpa_printf(MSG_DEBUG
, "%s: plain buf_len: %u", __func__
,
2570 (unsigned int) wpabuf_len(plain
));
2572 sm
->fils_completed
= 1;
2576 #endif /* CONFIG_FILS */
2579 SM_STATE(WPA_PTK
, PTKCALCNEGOTIATING
)
2581 struct wpa_authenticator
*wpa_auth
= sm
->wpa_auth
;
2583 int ok
= 0, psk_found
= 0;
2584 const u8
*pmk
= NULL
;
2585 unsigned int pmk_len
;
2587 const u8
*eapol_key_ie
, *key_data
, *mic
;
2588 u16 key_data_length
;
2589 size_t mic_len
, eapol_key_ie_len
;
2590 struct ieee802_1x_hdr
*hdr
;
2591 struct wpa_eapol_key
*key
;
2592 struct wpa_eapol_ie_parse kde
;
2594 SM_ENTRY_MA(WPA_PTK
, PTKCALCNEGOTIATING
, wpa_ptk
);
2595 sm
->EAPOLKeyReceived
= FALSE
;
2596 sm
->update_snonce
= FALSE
;
2597 os_memset(&PTK
, 0, sizeof(PTK
));
2599 mic_len
= wpa_mic_len(sm
->wpa_key_mgmt
);
2601 /* WPA with IEEE 802.1X: use the derived PMK from EAP
2602 * WPA-PSK: iterate through possible PSKs and select the one matching
2605 if (wpa_key_mgmt_wpa_psk(sm
->wpa_key_mgmt
)) {
2606 pmk
= wpa_auth_get_psk(sm
->wpa_auth
, sm
->addr
,
2607 sm
->p2p_dev_addr
, pmk
);
2614 pmk_len
= sm
->pmk_len
;
2617 if (wpa_derive_ptk(sm
, sm
->SNonce
, pmk
, pmk_len
, &PTK
) < 0)
2621 wpa_verify_key_mic(sm
->wpa_key_mgmt
, &PTK
,
2622 sm
->last_rx_eapol_key
,
2623 sm
->last_rx_eapol_key_len
) == 0) {
2630 wpa_aead_decrypt(sm
, &PTK
, sm
->last_rx_eapol_key
,
2631 sm
->last_rx_eapol_key_len
, NULL
) == 0) {
2635 #endif /* CONFIG_FILS */
2637 if (!wpa_key_mgmt_wpa_psk(sm
->wpa_key_mgmt
))
2642 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
2643 "invalid MIC in msg 2/4 of 4-Way Handshake");
2645 wpa_auth_psk_failure_report(sm
->wpa_auth
, sm
->addr
);
2650 * Note: last_rx_eapol_key length fields have already been validated in
2653 hdr
= (struct ieee802_1x_hdr
*) sm
->last_rx_eapol_key
;
2654 key
= (struct wpa_eapol_key
*) (hdr
+ 1);
2655 mic
= (u8
*) (key
+ 1);
2656 key_data
= mic
+ mic_len
+ 2;
2657 key_data_length
= WPA_GET_BE16(mic
+ mic_len
);
2658 if (key_data_length
> sm
->last_rx_eapol_key_len
- sizeof(*hdr
) -
2659 sizeof(*key
) - mic_len
- 2)
2662 if (wpa_parse_kde_ies(key_data
, key_data_length
, &kde
) < 0) {
2663 wpa_auth_vlogger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
2664 "received EAPOL-Key msg 2/4 with invalid Key Data contents");
2668 eapol_key_ie
= kde
.rsn_ie
;
2669 eapol_key_ie_len
= kde
.rsn_ie_len
;
2670 } else if (kde
.osen
) {
2671 eapol_key_ie
= kde
.osen
;
2672 eapol_key_ie_len
= kde
.osen_len
;
2674 eapol_key_ie
= kde
.wpa_ie
;
2675 eapol_key_ie_len
= kde
.wpa_ie_len
;
2677 ft
= sm
->wpa
== WPA_VERSION_WPA2
&& wpa_key_mgmt_ft(sm
->wpa_key_mgmt
);
2678 if (sm
->wpa_ie
== NULL
||
2679 wpa_compare_rsn_ie(ft
, sm
->wpa_ie
, sm
->wpa_ie_len
,
2680 eapol_key_ie
, eapol_key_ie_len
)) {
2681 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
2682 "WPA IE from (Re)AssocReq did not match with msg 2/4");
2684 wpa_hexdump(MSG_DEBUG
, "WPA IE in AssocReq",
2685 sm
->wpa_ie
, sm
->wpa_ie_len
);
2687 wpa_hexdump(MSG_DEBUG
, "WPA IE in msg 2/4",
2688 eapol_key_ie
, eapol_key_ie_len
);
2689 /* MLME-DEAUTHENTICATE.request */
2690 wpa_sta_disconnect(wpa_auth
, sm
->addr
);
2693 #ifdef CONFIG_IEEE80211R_AP
2694 if (ft
&& ft_check_msg_2_of_4(wpa_auth
, sm
, &kde
) < 0) {
2695 wpa_sta_disconnect(wpa_auth
, sm
->addr
);
2698 #endif /* CONFIG_IEEE80211R_AP */
2700 if (kde
.ip_addr_req
&& kde
.ip_addr_req
[0] &&
2701 wpa_auth
->ip_pool
&& WPA_GET_BE32(sm
->ip_addr
) == 0) {
2703 wpa_printf(MSG_DEBUG
,
2704 "P2P: IP address requested in EAPOL-Key exchange");
2705 idx
= bitfield_get_first_zero(wpa_auth
->ip_pool
);
2707 u32 start
= WPA_GET_BE32(wpa_auth
->conf
.ip_addr_start
);
2708 bitfield_set(wpa_auth
->ip_pool
, idx
);
2709 WPA_PUT_BE32(sm
->ip_addr
, start
+ idx
);
2710 wpa_printf(MSG_DEBUG
,
2711 "P2P: Assigned IP address %u.%u.%u.%u to "
2712 MACSTR
, sm
->ip_addr
[0], sm
->ip_addr
[1],
2713 sm
->ip_addr
[2], sm
->ip_addr
[3],
2717 #endif /* CONFIG_P2P */
2719 #ifdef CONFIG_IEEE80211R_AP
2720 if (sm
->wpa
== WPA_VERSION_WPA2
&& wpa_key_mgmt_ft(sm
->wpa_key_mgmt
)) {
2722 * Verify that PMKR1Name from EAPOL-Key message 2/4 matches
2723 * with the value we derived.
2725 if (os_memcmp_const(sm
->sup_pmk_r1_name
, sm
->pmk_r1_name
,
2726 WPA_PMK_NAME_LEN
) != 0) {
2727 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
2728 "PMKR1Name mismatch in FT 4-way "
2730 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name from "
2732 sm
->sup_pmk_r1_name
, WPA_PMK_NAME_LEN
);
2733 wpa_hexdump(MSG_DEBUG
, "FT: Derived PMKR1Name",
2734 sm
->pmk_r1_name
, WPA_PMK_NAME_LEN
);
2738 #endif /* CONFIG_IEEE80211R_AP */
2740 sm
->pending_1_of_4_timeout
= 0;
2741 eloop_cancel_timeout(wpa_send_eapol_timeout
, sm
->wpa_auth
, sm
);
2743 if (wpa_key_mgmt_wpa_psk(sm
->wpa_key_mgmt
)) {
2744 /* PSK may have changed from the previous choice, so update
2745 * state machine data based on whatever PSK was selected here.
2747 os_memcpy(sm
->PMK
, pmk
, PMK_LEN
);
2748 sm
->pmk_len
= PMK_LEN
;
2751 sm
->MICVerified
= TRUE
;
2753 os_memcpy(&sm
->PTK
, &PTK
, sizeof(PTK
));
2754 sm
->PTK_valid
= TRUE
;
2758 SM_STATE(WPA_PTK
, PTKCALCNEGOTIATING2
)
2760 SM_ENTRY_MA(WPA_PTK
, PTKCALCNEGOTIATING2
, wpa_ptk
);
2765 #ifdef CONFIG_IEEE80211W
2767 static int ieee80211w_kde_len(struct wpa_state_machine
*sm
)
2769 if (sm
->mgmt_frame_prot
) {
2771 len
= wpa_cipher_key_len(sm
->wpa_auth
->conf
.group_mgmt_cipher
);
2772 return 2 + RSN_SELECTOR_LEN
+ WPA_IGTK_KDE_PREFIX_LEN
+ len
;
2779 static u8
* ieee80211w_kde_add(struct wpa_state_machine
*sm
, u8
*pos
)
2781 struct wpa_igtk_kde igtk
;
2782 struct wpa_group
*gsm
= sm
->group
;
2783 u8 rsc
[WPA_KEY_RSC_LEN
];
2784 size_t len
= wpa_cipher_key_len(sm
->wpa_auth
->conf
.group_mgmt_cipher
);
2786 if (!sm
->mgmt_frame_prot
)
2789 igtk
.keyid
[0] = gsm
->GN_igtk
;
2791 if (gsm
->wpa_group_state
!= WPA_GROUP_SETKEYSDONE
||
2792 wpa_auth_get_seqnum(sm
->wpa_auth
, NULL
, gsm
->GN_igtk
, rsc
) < 0)
2793 os_memset(igtk
.pn
, 0, sizeof(igtk
.pn
));
2795 os_memcpy(igtk
.pn
, rsc
, sizeof(igtk
.pn
));
2796 os_memcpy(igtk
.igtk
, gsm
->IGTK
[gsm
->GN_igtk
- 4], len
);
2797 if (sm
->wpa_auth
->conf
.disable_gtk
) {
2799 * Provide unique random IGTK to each STA to prevent use of
2802 if (random_get_bytes(igtk
.igtk
, len
) < 0)
2805 pos
= wpa_add_kde(pos
, RSN_KEY_DATA_IGTK
,
2806 (const u8
*) &igtk
, WPA_IGTK_KDE_PREFIX_LEN
+ len
,
2812 #else /* CONFIG_IEEE80211W */
2814 static int ieee80211w_kde_len(struct wpa_state_machine
*sm
)
2820 static u8
* ieee80211w_kde_add(struct wpa_state_machine
*sm
, u8
*pos
)
2825 #endif /* CONFIG_IEEE80211W */
2828 SM_STATE(WPA_PTK
, PTKINITNEGOTIATING
)
2830 u8 rsc
[WPA_KEY_RSC_LEN
], *_rsc
, *gtk
, *kde
, *pos
, dummy_gtk
[32];
2831 size_t gtk_len
, kde_len
;
2832 struct wpa_group
*gsm
= sm
->group
;
2834 int wpa_ie_len
, secure
, keyidx
, encr
= 0;
2836 SM_ENTRY_MA(WPA_PTK
, PTKINITNEGOTIATING
, wpa_ptk
);
2837 sm
->TimeoutEvt
= FALSE
;
2840 if (sm
->TimeoutCtr
> sm
->wpa_auth
->conf
.wpa_pairwise_update_count
) {
2841 /* No point in sending the EAPOL-Key - we will disconnect
2842 * immediately following this. */
2846 /* Send EAPOL(1, 1, 1, Pair, P, RSC, ANonce, MIC(PTK), RSNIE, [MDIE],
2847 GTK[GN], IGTK, [FTIE], [TIE * 2])
2849 os_memset(rsc
, 0, WPA_KEY_RSC_LEN
);
2850 wpa_auth_get_seqnum(sm
->wpa_auth
, NULL
, gsm
->GN
, rsc
);
2851 /* If FT is used, wpa_auth->wpa_ie includes both RSNIE and MDIE */
2852 wpa_ie
= sm
->wpa_auth
->wpa_ie
;
2853 wpa_ie_len
= sm
->wpa_auth
->wpa_ie_len
;
2854 if (sm
->wpa
== WPA_VERSION_WPA
&&
2855 (sm
->wpa_auth
->conf
.wpa
& WPA_PROTO_RSN
) &&
2856 wpa_ie_len
> wpa_ie
[1] + 2 && wpa_ie
[0] == WLAN_EID_RSN
) {
2857 /* WPA-only STA, remove RSN IE and possible MDIE */
2858 wpa_ie
= wpa_ie
+ wpa_ie
[1] + 2;
2859 if (wpa_ie
[0] == WLAN_EID_MOBILITY_DOMAIN
)
2860 wpa_ie
= wpa_ie
+ wpa_ie
[1] + 2;
2861 wpa_ie_len
= wpa_ie
[1] + 2;
2863 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
2864 "sending 3/4 msg of 4-Way Handshake");
2865 if (sm
->wpa
== WPA_VERSION_WPA2
) {
2866 /* WPA2 send GTK in the 4-way handshake */
2868 gtk
= gsm
->GTK
[gsm
->GN
- 1];
2869 gtk_len
= gsm
->GTK_len
;
2870 if (sm
->wpa_auth
->conf
.disable_gtk
) {
2872 * Provide unique random GTK to each STA to prevent use
2873 * of GTK in the BSS.
2875 if (random_get_bytes(dummy_gtk
, gtk_len
) < 0)
2883 /* WPA does not include GTK in msg 3/4 */
2889 if (sm
->rx_eapol_key_secure
) {
2891 * It looks like Windows 7 supplicant tries to use
2892 * Secure bit in msg 2/4 after having reported Michael
2893 * MIC failure and it then rejects the 4-way handshake
2894 * if msg 3/4 does not set Secure bit. Work around this
2895 * by setting the Secure bit here even in the case of
2896 * WPA if the supplicant used it first.
2898 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
2899 "STA used Secure bit in WPA msg 2/4 - "
2900 "set Secure for 3/4 as workaround");
2905 kde_len
= wpa_ie_len
+ ieee80211w_kde_len(sm
);
2907 kde_len
+= 2 + RSN_SELECTOR_LEN
+ 2 + gtk_len
;
2908 #ifdef CONFIG_IEEE80211R_AP
2909 if (wpa_key_mgmt_ft(sm
->wpa_key_mgmt
)) {
2910 kde_len
+= 2 + PMKID_LEN
; /* PMKR1Name into RSN IE */
2911 kde_len
+= 300; /* FTIE + 2 * TIE */
2913 #endif /* CONFIG_IEEE80211R_AP */
2915 if (WPA_GET_BE32(sm
->ip_addr
) > 0)
2916 kde_len
+= 2 + RSN_SELECTOR_LEN
+ 3 * 4;
2917 #endif /* CONFIG_P2P */
2918 kde
= os_malloc(kde_len
);
2923 os_memcpy(pos
, wpa_ie
, wpa_ie_len
);
2925 #ifdef CONFIG_IEEE80211R_AP
2926 if (wpa_key_mgmt_ft(sm
->wpa_key_mgmt
)) {
2931 res
= wpa_insert_pmkid(kde
, &elen
, sm
->pmk_r1_name
);
2933 wpa_printf(MSG_ERROR
, "FT: Failed to insert "
2934 "PMKR1Name into RSN IE in EAPOL-Key data");
2941 #endif /* CONFIG_IEEE80211R_AP */
2944 hdr
[0] = keyidx
& 0x03;
2946 pos
= wpa_add_kde(pos
, RSN_KEY_DATA_GROUPKEY
, hdr
, 2,
2949 pos
= ieee80211w_kde_add(sm
, pos
);
2951 #ifdef CONFIG_IEEE80211R_AP
2952 if (wpa_key_mgmt_ft(sm
->wpa_key_mgmt
)) {
2954 struct wpa_auth_config
*conf
;
2956 conf
= &sm
->wpa_auth
->conf
;
2957 if (sm
->assoc_resp_ftie
&&
2958 kde
+ kde_len
- pos
>= 2 + sm
->assoc_resp_ftie
[1]) {
2959 os_memcpy(pos
, sm
->assoc_resp_ftie
,
2960 2 + sm
->assoc_resp_ftie
[1]);
2961 res
= 2 + sm
->assoc_resp_ftie
[1];
2963 res
= wpa_write_ftie(conf
, conf
->r0_key_holder
,
2964 conf
->r0_key_holder_len
,
2966 kde
+ kde_len
- pos
,
2970 wpa_printf(MSG_ERROR
, "FT: Failed to insert FTIE "
2971 "into EAPOL-Key Key Data");
2977 /* TIE[ReassociationDeadline] (TU) */
2978 *pos
++ = WLAN_EID_TIMEOUT_INTERVAL
;
2980 *pos
++ = WLAN_TIMEOUT_REASSOC_DEADLINE
;
2981 WPA_PUT_LE32(pos
, conf
->reassociation_deadline
);
2984 /* TIE[KeyLifetime] (seconds) */
2985 *pos
++ = WLAN_EID_TIMEOUT_INTERVAL
;
2987 *pos
++ = WLAN_TIMEOUT_KEY_LIFETIME
;
2988 WPA_PUT_LE32(pos
, conf
->r0_key_lifetime
* 60);
2991 #endif /* CONFIG_IEEE80211R_AP */
2993 if (WPA_GET_BE32(sm
->ip_addr
) > 0) {
2995 os_memcpy(addr
, sm
->ip_addr
, 4);
2996 os_memcpy(addr
+ 4, sm
->wpa_auth
->conf
.ip_addr_mask
, 4);
2997 os_memcpy(addr
+ 8, sm
->wpa_auth
->conf
.ip_addr_go
, 4);
2998 pos
= wpa_add_kde(pos
, WFA_KEY_DATA_IP_ADDR_ALLOC
,
2999 addr
, sizeof(addr
), NULL
, 0);
3001 #endif /* CONFIG_P2P */
3003 wpa_send_eapol(sm
->wpa_auth
, sm
,
3004 (secure
? WPA_KEY_INFO_SECURE
: 0) |
3005 (wpa_mic_len(sm
->wpa_key_mgmt
) ? WPA_KEY_INFO_MIC
: 0) |
3006 WPA_KEY_INFO_ACK
| WPA_KEY_INFO_INSTALL
|
3007 WPA_KEY_INFO_KEY_TYPE
,
3008 _rsc
, sm
->ANonce
, kde
, pos
- kde
, keyidx
, encr
);
3013 SM_STATE(WPA_PTK
, PTKINITDONE
)
3015 SM_ENTRY_MA(WPA_PTK
, PTKINITDONE
, wpa_ptk
);
3016 sm
->EAPOLKeyReceived
= FALSE
;
3018 enum wpa_alg alg
= wpa_cipher_to_alg(sm
->pairwise
);
3019 int klen
= wpa_cipher_key_len(sm
->pairwise
);
3020 if (wpa_auth_set_key(sm
->wpa_auth
, 0, alg
, sm
->addr
, 0,
3021 sm
->PTK
.tk
, klen
)) {
3022 wpa_sta_disconnect(sm
->wpa_auth
, sm
->addr
);
3025 /* FIX: MLME-SetProtection.Request(TA, Tx_Rx) */
3026 sm
->pairwise_set
= TRUE
;
3028 if (sm
->wpa_auth
->conf
.wpa_ptk_rekey
) {
3029 eloop_cancel_timeout(wpa_rekey_ptk
, sm
->wpa_auth
, sm
);
3030 eloop_register_timeout(sm
->wpa_auth
->conf
.
3031 wpa_ptk_rekey
, 0, wpa_rekey_ptk
,
3035 if (wpa_key_mgmt_wpa_psk(sm
->wpa_key_mgmt
) ||
3036 sm
->wpa_key_mgmt
== WPA_KEY_MGMT_OWE
) {
3037 wpa_auth_set_eapol(sm
->wpa_auth
, sm
->addr
,
3038 WPA_EAPOL_authorized
, 1);
3042 if (0 /* IBSS == TRUE */) {
3044 if (sm
->keycount
== 2) {
3045 wpa_auth_set_eapol(sm
->wpa_auth
, sm
->addr
,
3046 WPA_EAPOL_portValid
, 1);
3049 wpa_auth_set_eapol(sm
->wpa_auth
, sm
->addr
, WPA_EAPOL_portValid
,
3052 wpa_auth_set_eapol(sm
->wpa_auth
, sm
->addr
, WPA_EAPOL_keyAvailable
, 0);
3053 wpa_auth_set_eapol(sm
->wpa_auth
, sm
->addr
, WPA_EAPOL_keyDone
, 1);
3054 if (sm
->wpa
== WPA_VERSION_WPA
)
3055 sm
->PInitAKeys
= TRUE
;
3058 wpa_auth_vlogger(sm
->wpa_auth
, sm
->addr
, LOGGER_INFO
,
3059 "pairwise key handshake completed (%s)",
3060 sm
->wpa
== WPA_VERSION_WPA
? "WPA" : "RSN");
3062 #ifdef CONFIG_IEEE80211R_AP
3063 wpa_ft_push_pmk_r1(sm
->wpa_auth
, sm
->addr
);
3064 #endif /* CONFIG_IEEE80211R_AP */
3070 struct wpa_authenticator
*wpa_auth
= sm
->wpa_auth
;
3073 SM_ENTER(WPA_PTK
, INITIALIZE
);
3074 else if (sm
->Disconnect
3075 /* || FIX: dot11RSNAConfigSALifetime timeout */) {
3076 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
3077 "WPA_PTK: sm->Disconnect");
3078 SM_ENTER(WPA_PTK
, DISCONNECT
);
3080 else if (sm
->DeauthenticationRequest
)
3081 SM_ENTER(WPA_PTK
, DISCONNECTED
);
3082 else if (sm
->AuthenticationRequest
)
3083 SM_ENTER(WPA_PTK
, AUTHENTICATION
);
3084 else if (sm
->ReAuthenticationRequest
)
3085 SM_ENTER(WPA_PTK
, AUTHENTICATION2
);
3086 else if (sm
->PTKRequest
)
3087 SM_ENTER(WPA_PTK
, PTKSTART
);
3088 else switch (sm
->wpa_ptk_state
) {
3089 case WPA_PTK_INITIALIZE
:
3091 case WPA_PTK_DISCONNECT
:
3092 SM_ENTER(WPA_PTK
, DISCONNECTED
);
3094 case WPA_PTK_DISCONNECTED
:
3095 SM_ENTER(WPA_PTK
, INITIALIZE
);
3097 case WPA_PTK_AUTHENTICATION
:
3098 SM_ENTER(WPA_PTK
, AUTHENTICATION2
);
3100 case WPA_PTK_AUTHENTICATION2
:
3101 if (wpa_key_mgmt_wpa_ieee8021x(sm
->wpa_key_mgmt
) &&
3102 wpa_auth_get_eapol(sm
->wpa_auth
, sm
->addr
,
3103 WPA_EAPOL_keyRun
) > 0)
3104 SM_ENTER(WPA_PTK
, INITPMK
);
3105 else if (wpa_key_mgmt_wpa_psk(sm
->wpa_key_mgmt
) ||
3106 sm
->wpa_key_mgmt
== WPA_KEY_MGMT_OWE
3107 /* FIX: && 802.1X::keyRun */)
3108 SM_ENTER(WPA_PTK
, INITPSK
);
3110 case WPA_PTK_INITPMK
:
3111 if (wpa_auth_get_eapol(sm
->wpa_auth
, sm
->addr
,
3112 WPA_EAPOL_keyAvailable
) > 0)
3113 SM_ENTER(WPA_PTK
, PTKSTART
);
3115 wpa_auth
->dot11RSNA4WayHandshakeFailures
++;
3116 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_INFO
,
3117 "INITPMK - keyAvailable = false");
3118 SM_ENTER(WPA_PTK
, DISCONNECT
);
3121 case WPA_PTK_INITPSK
:
3122 if (wpa_auth_get_psk(sm
->wpa_auth
, sm
->addr
, sm
->p2p_dev_addr
,
3124 SM_ENTER(WPA_PTK
, PTKSTART
);
3126 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_INFO
,
3127 "no PSK configured for the STA");
3128 wpa_auth
->dot11RSNA4WayHandshakeFailures
++;
3129 SM_ENTER(WPA_PTK
, DISCONNECT
);
3132 case WPA_PTK_PTKSTART
:
3133 if (sm
->EAPOLKeyReceived
&& !sm
->EAPOLKeyRequest
&&
3134 sm
->EAPOLKeyPairwise
)
3135 SM_ENTER(WPA_PTK
, PTKCALCNEGOTIATING
);
3136 else if (sm
->TimeoutCtr
>
3137 sm
->wpa_auth
->conf
.wpa_pairwise_update_count
) {
3138 wpa_auth
->dot11RSNA4WayHandshakeFailures
++;
3140 sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
3141 "PTKSTART: Retry limit %u reached",
3142 sm
->wpa_auth
->conf
.wpa_pairwise_update_count
);
3143 SM_ENTER(WPA_PTK
, DISCONNECT
);
3144 } else if (sm
->TimeoutEvt
)
3145 SM_ENTER(WPA_PTK
, PTKSTART
);
3147 case WPA_PTK_PTKCALCNEGOTIATING
:
3148 if (sm
->MICVerified
)
3149 SM_ENTER(WPA_PTK
, PTKCALCNEGOTIATING2
);
3150 else if (sm
->EAPOLKeyReceived
&& !sm
->EAPOLKeyRequest
&&
3151 sm
->EAPOLKeyPairwise
)
3152 SM_ENTER(WPA_PTK
, PTKCALCNEGOTIATING
);
3153 else if (sm
->TimeoutEvt
)
3154 SM_ENTER(WPA_PTK
, PTKSTART
);
3156 case WPA_PTK_PTKCALCNEGOTIATING2
:
3157 SM_ENTER(WPA_PTK
, PTKINITNEGOTIATING
);
3159 case WPA_PTK_PTKINITNEGOTIATING
:
3160 if (sm
->update_snonce
)
3161 SM_ENTER(WPA_PTK
, PTKCALCNEGOTIATING
);
3162 else if (sm
->EAPOLKeyReceived
&& !sm
->EAPOLKeyRequest
&&
3163 sm
->EAPOLKeyPairwise
&& sm
->MICVerified
)
3164 SM_ENTER(WPA_PTK
, PTKINITDONE
);
3165 else if (sm
->TimeoutCtr
>
3166 sm
->wpa_auth
->conf
.wpa_pairwise_update_count
) {
3167 wpa_auth
->dot11RSNA4WayHandshakeFailures
++;
3169 sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
3170 "PTKINITNEGOTIATING: Retry limit %u reached",
3171 sm
->wpa_auth
->conf
.wpa_pairwise_update_count
);
3172 SM_ENTER(WPA_PTK
, DISCONNECT
);
3173 } else if (sm
->TimeoutEvt
)
3174 SM_ENTER(WPA_PTK
, PTKINITNEGOTIATING
);
3176 case WPA_PTK_PTKINITDONE
:
3182 SM_STATE(WPA_PTK_GROUP
, IDLE
)
3184 SM_ENTRY_MA(WPA_PTK_GROUP
, IDLE
, wpa_ptk_group
);
3186 /* Init flag is not cleared here, so avoid busy
3187 * loop by claiming nothing changed. */
3188 sm
->changed
= FALSE
;
3190 sm
->GTimeoutCtr
= 0;
3194 SM_STATE(WPA_PTK_GROUP
, REKEYNEGOTIATING
)
3196 u8 rsc
[WPA_KEY_RSC_LEN
];
3197 struct wpa_group
*gsm
= sm
->group
;
3199 u8
*kde_buf
= NULL
, *pos
, hdr
[2];
3201 u8
*gtk
, dummy_gtk
[32];
3203 SM_ENTRY_MA(WPA_PTK_GROUP
, REKEYNEGOTIATING
, wpa_ptk_group
);
3206 if (sm
->GTimeoutCtr
> sm
->wpa_auth
->conf
.wpa_group_update_count
) {
3207 /* No point in sending the EAPOL-Key - we will disconnect
3208 * immediately following this. */
3212 if (sm
->wpa
== WPA_VERSION_WPA
)
3213 sm
->PInitAKeys
= FALSE
;
3214 sm
->TimeoutEvt
= FALSE
;
3215 /* Send EAPOL(1, 1, 1, !Pair, G, RSC, GNonce, MIC(PTK), GTK[GN]) */
3216 os_memset(rsc
, 0, WPA_KEY_RSC_LEN
);
3217 if (gsm
->wpa_group_state
== WPA_GROUP_SETKEYSDONE
)
3218 wpa_auth_get_seqnum(sm
->wpa_auth
, NULL
, gsm
->GN
, rsc
);
3219 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
3220 "sending 1/2 msg of Group Key Handshake");
3222 gtk
= gsm
->GTK
[gsm
->GN
- 1];
3223 if (sm
->wpa_auth
->conf
.disable_gtk
) {
3225 * Provide unique random GTK to each STA to prevent use
3226 * of GTK in the BSS.
3228 if (random_get_bytes(dummy_gtk
, gsm
->GTK_len
) < 0)
3232 if (sm
->wpa
== WPA_VERSION_WPA2
) {
3233 kde_len
= 2 + RSN_SELECTOR_LEN
+ 2 + gsm
->GTK_len
+
3234 ieee80211w_kde_len(sm
);
3235 kde_buf
= os_malloc(kde_len
);
3236 if (kde_buf
== NULL
)
3239 kde
= pos
= kde_buf
;
3240 hdr
[0] = gsm
->GN
& 0x03;
3242 pos
= wpa_add_kde(pos
, RSN_KEY_DATA_GROUPKEY
, hdr
, 2,
3244 pos
= ieee80211w_kde_add(sm
, pos
);
3245 kde_len
= pos
- kde
;
3248 kde_len
= gsm
->GTK_len
;
3251 wpa_send_eapol(sm
->wpa_auth
, sm
,
3252 WPA_KEY_INFO_SECURE
|
3253 (wpa_mic_len(sm
->wpa_key_mgmt
) ? WPA_KEY_INFO_MIC
: 0) |
3255 (!sm
->Pair
? WPA_KEY_INFO_INSTALL
: 0),
3256 rsc
, NULL
, kde
, kde_len
, gsm
->GN
, 1);
3262 SM_STATE(WPA_PTK_GROUP
, REKEYESTABLISHED
)
3264 SM_ENTRY_MA(WPA_PTK_GROUP
, REKEYESTABLISHED
, wpa_ptk_group
);
3265 sm
->EAPOLKeyReceived
= FALSE
;
3266 if (sm
->GUpdateStationKeys
)
3267 sm
->group
->GKeyDoneStations
--;
3268 sm
->GUpdateStationKeys
= FALSE
;
3269 sm
->GTimeoutCtr
= 0;
3270 /* FIX: MLME.SetProtection.Request(TA, Tx_Rx) */
3271 wpa_auth_vlogger(sm
->wpa_auth
, sm
->addr
, LOGGER_INFO
,
3272 "group key handshake completed (%s)",
3273 sm
->wpa
== WPA_VERSION_WPA
? "WPA" : "RSN");
3278 SM_STATE(WPA_PTK_GROUP
, KEYERROR
)
3280 SM_ENTRY_MA(WPA_PTK_GROUP
, KEYERROR
, wpa_ptk_group
);
3281 if (sm
->GUpdateStationKeys
)
3282 sm
->group
->GKeyDoneStations
--;
3283 sm
->GUpdateStationKeys
= FALSE
;
3284 sm
->Disconnect
= TRUE
;
3285 wpa_auth_vlogger(sm
->wpa_auth
, sm
->addr
, LOGGER_INFO
,
3286 "group key handshake failed (%s) after %u tries",
3287 sm
->wpa
== WPA_VERSION_WPA
? "WPA" : "RSN",
3288 sm
->wpa_auth
->conf
.wpa_group_update_count
);
3292 SM_STEP(WPA_PTK_GROUP
)
3294 if (sm
->Init
|| sm
->PtkGroupInit
) {
3295 SM_ENTER(WPA_PTK_GROUP
, IDLE
);
3296 sm
->PtkGroupInit
= FALSE
;
3297 } else switch (sm
->wpa_ptk_group_state
) {
3298 case WPA_PTK_GROUP_IDLE
:
3299 if (sm
->GUpdateStationKeys
||
3300 (sm
->wpa
== WPA_VERSION_WPA
&& sm
->PInitAKeys
))
3301 SM_ENTER(WPA_PTK_GROUP
, REKEYNEGOTIATING
);
3303 case WPA_PTK_GROUP_REKEYNEGOTIATING
:
3304 if (sm
->EAPOLKeyReceived
&& !sm
->EAPOLKeyRequest
&&
3305 !sm
->EAPOLKeyPairwise
&& sm
->MICVerified
)
3306 SM_ENTER(WPA_PTK_GROUP
, REKEYESTABLISHED
);
3307 else if (sm
->GTimeoutCtr
>
3308 sm
->wpa_auth
->conf
.wpa_group_update_count
)
3309 SM_ENTER(WPA_PTK_GROUP
, KEYERROR
);
3310 else if (sm
->TimeoutEvt
)
3311 SM_ENTER(WPA_PTK_GROUP
, REKEYNEGOTIATING
);
3313 case WPA_PTK_GROUP_KEYERROR
:
3314 SM_ENTER(WPA_PTK_GROUP
, IDLE
);
3316 case WPA_PTK_GROUP_REKEYESTABLISHED
:
3317 SM_ENTER(WPA_PTK_GROUP
, IDLE
);
3323 static int wpa_gtk_update(struct wpa_authenticator
*wpa_auth
,
3324 struct wpa_group
*group
)
3328 os_memcpy(group
->GNonce
, group
->Counter
, WPA_NONCE_LEN
);
3329 inc_byte_array(group
->Counter
, WPA_NONCE_LEN
);
3330 if (wpa_gmk_to_gtk(group
->GMK
, "Group key expansion",
3331 wpa_auth
->addr
, group
->GNonce
,
3332 group
->GTK
[group
->GN
- 1], group
->GTK_len
) < 0)
3334 wpa_hexdump_key(MSG_DEBUG
, "GTK",
3335 group
->GTK
[group
->GN
- 1], group
->GTK_len
);
3337 #ifdef CONFIG_IEEE80211W
3338 if (wpa_auth
->conf
.ieee80211w
!= NO_MGMT_FRAME_PROTECTION
) {
3340 len
= wpa_cipher_key_len(wpa_auth
->conf
.group_mgmt_cipher
);
3341 os_memcpy(group
->GNonce
, group
->Counter
, WPA_NONCE_LEN
);
3342 inc_byte_array(group
->Counter
, WPA_NONCE_LEN
);
3343 if (wpa_gmk_to_gtk(group
->GMK
, "IGTK key expansion",
3344 wpa_auth
->addr
, group
->GNonce
,
3345 group
->IGTK
[group
->GN_igtk
- 4], len
) < 0)
3347 wpa_hexdump_key(MSG_DEBUG
, "IGTK",
3348 group
->IGTK
[group
->GN_igtk
- 4], len
);
3350 #endif /* CONFIG_IEEE80211W */
3356 static void wpa_group_gtk_init(struct wpa_authenticator
*wpa_auth
,
3357 struct wpa_group
*group
)
3359 wpa_printf(MSG_DEBUG
, "WPA: group state machine entering state "
3360 "GTK_INIT (VLAN-ID %d)", group
->vlan_id
);
3361 group
->changed
= FALSE
; /* GInit is not cleared here; avoid loop */
3362 group
->wpa_group_state
= WPA_GROUP_GTK_INIT
;
3365 os_memset(group
->GTK
, 0, sizeof(group
->GTK
));
3368 #ifdef CONFIG_IEEE80211W
3371 #endif /* CONFIG_IEEE80211W */
3372 /* GTK[GN] = CalcGTK() */
3373 wpa_gtk_update(wpa_auth
, group
);
3377 static int wpa_group_update_sta(struct wpa_state_machine
*sm
, void *ctx
)
3379 if (ctx
!= NULL
&& ctx
!= sm
->group
)
3382 if (sm
->wpa_ptk_state
!= WPA_PTK_PTKINITDONE
) {
3383 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
3384 "Not in PTKINITDONE; skip Group Key update");
3385 sm
->GUpdateStationKeys
= FALSE
;
3388 if (sm
->GUpdateStationKeys
) {
3390 * This should not really happen, so add a debug log entry.
3391 * Since we clear the GKeyDoneStations before the loop, the
3392 * station needs to be counted here anyway.
3394 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
3395 "GUpdateStationKeys was already set when "
3396 "marking station for GTK rekeying");
3399 /* Do not rekey GTK/IGTK when STA is in WNM-Sleep Mode */
3400 if (sm
->is_wnmsleep
)
3403 sm
->group
->GKeyDoneStations
++;
3404 sm
->GUpdateStationKeys
= TRUE
;
3412 /* update GTK when exiting WNM-Sleep Mode */
3413 void wpa_wnmsleep_rekey_gtk(struct wpa_state_machine
*sm
)
3415 if (sm
== NULL
|| sm
->is_wnmsleep
)
3418 wpa_group_update_sta(sm
, NULL
);
3422 void wpa_set_wnmsleep(struct wpa_state_machine
*sm
, int flag
)
3425 sm
->is_wnmsleep
= !!flag
;
3429 int wpa_wnmsleep_gtk_subelem(struct wpa_state_machine
*sm
, u8
*pos
)
3431 struct wpa_group
*gsm
= sm
->group
;
3436 * Sub-elem ID[1] | Length[1] | Key Info[2] | Key Length[1] | RSC[8] |
3439 *pos
++ = WNM_SLEEP_SUBELEM_GTK
;
3440 *pos
++ = 11 + gsm
->GTK_len
;
3441 /* Key ID in B0-B1 of Key Info */
3442 WPA_PUT_LE16(pos
, gsm
->GN
& 0x03);
3444 *pos
++ = gsm
->GTK_len
;
3445 if (wpa_auth_get_seqnum(sm
->wpa_auth
, NULL
, gsm
->GN
, pos
) != 0)
3448 os_memcpy(pos
, gsm
->GTK
[gsm
->GN
- 1], gsm
->GTK_len
);
3449 pos
+= gsm
->GTK_len
;
3451 wpa_printf(MSG_DEBUG
, "WNM: GTK Key ID %u in WNM-Sleep Mode exit",
3453 wpa_hexdump_key(MSG_DEBUG
, "WNM: GTK in WNM-Sleep Mode exit",
3454 gsm
->GTK
[gsm
->GN
- 1], gsm
->GTK_len
);
3460 #ifdef CONFIG_IEEE80211W
3461 int wpa_wnmsleep_igtk_subelem(struct wpa_state_machine
*sm
, u8
*pos
)
3463 struct wpa_group
*gsm
= sm
->group
;
3465 size_t len
= wpa_cipher_key_len(sm
->wpa_auth
->conf
.group_mgmt_cipher
);
3469 * Sub-elem ID[1] | Length[1] | KeyID[2] | PN[6] | Key[16]
3471 *pos
++ = WNM_SLEEP_SUBELEM_IGTK
;
3472 *pos
++ = 2 + 6 + len
;
3473 WPA_PUT_LE16(pos
, gsm
->GN_igtk
);
3475 if (wpa_auth_get_seqnum(sm
->wpa_auth
, NULL
, gsm
->GN_igtk
, pos
) != 0)
3479 os_memcpy(pos
, gsm
->IGTK
[gsm
->GN_igtk
- 4], len
);
3482 wpa_printf(MSG_DEBUG
, "WNM: IGTK Key ID %u in WNM-Sleep Mode exit",
3484 wpa_hexdump_key(MSG_DEBUG
, "WNM: IGTK in WNM-Sleep Mode exit",
3485 gsm
->IGTK
[gsm
->GN_igtk
- 4], len
);
3489 #endif /* CONFIG_IEEE80211W */
3490 #endif /* CONFIG_WNM */
3493 static void wpa_group_setkeys(struct wpa_authenticator
*wpa_auth
,
3494 struct wpa_group
*group
)
3498 wpa_printf(MSG_DEBUG
, "WPA: group state machine entering state "
3499 "SETKEYS (VLAN-ID %d)", group
->vlan_id
);
3500 group
->changed
= TRUE
;
3501 group
->wpa_group_state
= WPA_GROUP_SETKEYS
;
3502 group
->GTKReKey
= FALSE
;
3504 group
->GM
= group
->GN
;
3506 #ifdef CONFIG_IEEE80211W
3507 tmp
= group
->GM_igtk
;
3508 group
->GM_igtk
= group
->GN_igtk
;
3509 group
->GN_igtk
= tmp
;
3510 #endif /* CONFIG_IEEE80211W */
3511 /* "GKeyDoneStations = GNoStations" is done in more robust way by
3512 * counting the STAs that are marked with GUpdateStationKeys instead of
3513 * including all STAs that could be in not-yet-completed state. */
3514 wpa_gtk_update(wpa_auth
, group
);
3516 if (group
->GKeyDoneStations
) {
3517 wpa_printf(MSG_DEBUG
, "wpa_group_setkeys: Unexpected "
3518 "GKeyDoneStations=%d when starting new GTK rekey",
3519 group
->GKeyDoneStations
);
3520 group
->GKeyDoneStations
= 0;
3522 wpa_auth_for_each_sta(wpa_auth
, wpa_group_update_sta
, group
);
3523 wpa_printf(MSG_DEBUG
, "wpa_group_setkeys: GKeyDoneStations=%d",
3524 group
->GKeyDoneStations
);
3528 static int wpa_group_config_group_keys(struct wpa_authenticator
*wpa_auth
,
3529 struct wpa_group
*group
)
3533 if (wpa_auth_set_key(wpa_auth
, group
->vlan_id
,
3534 wpa_cipher_to_alg(wpa_auth
->conf
.wpa_group
),
3535 broadcast_ether_addr
, group
->GN
,
3536 group
->GTK
[group
->GN
- 1], group
->GTK_len
) < 0)
3539 #ifdef CONFIG_IEEE80211W
3540 if (wpa_auth
->conf
.ieee80211w
!= NO_MGMT_FRAME_PROTECTION
) {
3544 alg
= wpa_cipher_to_alg(wpa_auth
->conf
.group_mgmt_cipher
);
3545 len
= wpa_cipher_key_len(wpa_auth
->conf
.group_mgmt_cipher
);
3548 wpa_auth_set_key(wpa_auth
, group
->vlan_id
, alg
,
3549 broadcast_ether_addr
, group
->GN_igtk
,
3550 group
->IGTK
[group
->GN_igtk
- 4], len
) < 0)
3553 #endif /* CONFIG_IEEE80211W */
3559 static int wpa_group_disconnect_cb(struct wpa_state_machine
*sm
, void *ctx
)
3561 if (sm
->group
== ctx
) {
3562 wpa_printf(MSG_DEBUG
, "WPA: Mark STA " MACSTR
3563 " for discconnection due to fatal failure",
3565 sm
->Disconnect
= TRUE
;
3572 static void wpa_group_fatal_failure(struct wpa_authenticator
*wpa_auth
,
3573 struct wpa_group
*group
)
3575 wpa_printf(MSG_DEBUG
, "WPA: group state machine entering state FATAL_FAILURE");
3576 group
->changed
= TRUE
;
3577 group
->wpa_group_state
= WPA_GROUP_FATAL_FAILURE
;
3578 wpa_auth_for_each_sta(wpa_auth
, wpa_group_disconnect_cb
, group
);
3582 static int wpa_group_setkeysdone(struct wpa_authenticator
*wpa_auth
,
3583 struct wpa_group
*group
)
3585 wpa_printf(MSG_DEBUG
, "WPA: group state machine entering state "
3586 "SETKEYSDONE (VLAN-ID %d)", group
->vlan_id
);
3587 group
->changed
= TRUE
;
3588 group
->wpa_group_state
= WPA_GROUP_SETKEYSDONE
;
3590 if (wpa_group_config_group_keys(wpa_auth
, group
) < 0) {
3591 wpa_group_fatal_failure(wpa_auth
, group
);
3599 static void wpa_group_sm_step(struct wpa_authenticator
*wpa_auth
,
3600 struct wpa_group
*group
)
3603 wpa_group_gtk_init(wpa_auth
, group
);
3604 } else if (group
->wpa_group_state
== WPA_GROUP_FATAL_FAILURE
) {
3605 /* Do not allow group operations */
3606 } else if (group
->wpa_group_state
== WPA_GROUP_GTK_INIT
&&
3607 group
->GTKAuthenticator
) {
3608 wpa_group_setkeysdone(wpa_auth
, group
);
3609 } else if (group
->wpa_group_state
== WPA_GROUP_SETKEYSDONE
&&
3611 wpa_group_setkeys(wpa_auth
, group
);
3612 } else if (group
->wpa_group_state
== WPA_GROUP_SETKEYS
) {
3613 if (group
->GKeyDoneStations
== 0)
3614 wpa_group_setkeysdone(wpa_auth
, group
);
3615 else if (group
->GTKReKey
)
3616 wpa_group_setkeys(wpa_auth
, group
);
3621 static int wpa_sm_step(struct wpa_state_machine
*sm
)
3626 if (sm
->in_step_loop
) {
3627 /* This should not happen, but if it does, make sure we do not
3628 * end up freeing the state machine too early by exiting the
3629 * recursive call. */
3630 wpa_printf(MSG_ERROR
, "WPA: wpa_sm_step() called recursively");
3634 sm
->in_step_loop
= 1;
3636 if (sm
->pending_deinit
)
3639 sm
->changed
= FALSE
;
3640 sm
->wpa_auth
->group
->changed
= FALSE
;
3642 SM_STEP_RUN(WPA_PTK
);
3643 if (sm
->pending_deinit
)
3645 SM_STEP_RUN(WPA_PTK_GROUP
);
3646 if (sm
->pending_deinit
)
3648 wpa_group_sm_step(sm
->wpa_auth
, sm
->group
);
3649 } while (sm
->changed
|| sm
->wpa_auth
->group
->changed
);
3650 sm
->in_step_loop
= 0;
3652 if (sm
->pending_deinit
) {
3653 wpa_printf(MSG_DEBUG
, "WPA: Completing pending STA state "
3654 "machine deinit for " MACSTR
, MAC2STR(sm
->addr
));
3655 wpa_free_sta_sm(sm
);
3662 static void wpa_sm_call_step(void *eloop_ctx
, void *timeout_ctx
)
3664 struct wpa_state_machine
*sm
= eloop_ctx
;
3669 void wpa_auth_sm_notify(struct wpa_state_machine
*sm
)
3673 eloop_register_timeout(0, 0, wpa_sm_call_step
, sm
, NULL
);
3677 void wpa_gtk_rekey(struct wpa_authenticator
*wpa_auth
)
3680 struct wpa_group
*group
;
3682 if (wpa_auth
== NULL
)
3685 group
= wpa_auth
->group
;
3687 for (i
= 0; i
< 2; i
++) {
3689 group
->GM
= group
->GN
;
3691 #ifdef CONFIG_IEEE80211W
3692 tmp
= group
->GM_igtk
;
3693 group
->GM_igtk
= group
->GN_igtk
;
3694 group
->GN_igtk
= tmp
;
3695 #endif /* CONFIG_IEEE80211W */
3696 wpa_gtk_update(wpa_auth
, group
);
3697 wpa_group_config_group_keys(wpa_auth
, group
);
3702 static const char * wpa_bool_txt(int val
)
3704 return val
? "TRUE" : "FALSE";
3708 #define RSN_SUITE "%02x-%02x-%02x-%d"
3709 #define RSN_SUITE_ARG(s) \
3710 ((s) >> 24) & 0xff, ((s) >> 16) & 0xff, ((s) >> 8) & 0xff, (s) & 0xff
3712 int wpa_get_mib(struct wpa_authenticator
*wpa_auth
, char *buf
, size_t buflen
)
3715 char pmkid_txt
[PMKID_LEN
* 2 + 1];
3716 #ifdef CONFIG_RSN_PREAUTH
3717 const int preauth
= 1;
3718 #else /* CONFIG_RSN_PREAUTH */
3719 const int preauth
= 0;
3720 #endif /* CONFIG_RSN_PREAUTH */
3722 if (wpa_auth
== NULL
)
3725 ret
= os_snprintf(buf
+ len
, buflen
- len
,
3726 "dot11RSNAOptionImplemented=TRUE\n"
3727 "dot11RSNAPreauthenticationImplemented=%s\n"
3728 "dot11RSNAEnabled=%s\n"
3729 "dot11RSNAPreauthenticationEnabled=%s\n",
3730 wpa_bool_txt(preauth
),
3731 wpa_bool_txt(wpa_auth
->conf
.wpa
& WPA_PROTO_RSN
),
3732 wpa_bool_txt(wpa_auth
->conf
.rsn_preauth
));
3733 if (os_snprintf_error(buflen
- len
, ret
))
3737 wpa_snprintf_hex(pmkid_txt
, sizeof(pmkid_txt
),
3738 wpa_auth
->dot11RSNAPMKIDUsed
, PMKID_LEN
);
3741 buf
+ len
, buflen
- len
,
3742 "dot11RSNAConfigVersion=%u\n"
3743 "dot11RSNAConfigPairwiseKeysSupported=9999\n"
3744 /* FIX: dot11RSNAConfigGroupCipher */
3745 /* FIX: dot11RSNAConfigGroupRekeyMethod */
3746 /* FIX: dot11RSNAConfigGroupRekeyTime */
3747 /* FIX: dot11RSNAConfigGroupRekeyPackets */
3748 "dot11RSNAConfigGroupRekeyStrict=%u\n"
3749 "dot11RSNAConfigGroupUpdateCount=%u\n"
3750 "dot11RSNAConfigPairwiseUpdateCount=%u\n"
3751 "dot11RSNAConfigGroupCipherSize=%u\n"
3752 "dot11RSNAConfigPMKLifetime=%u\n"
3753 "dot11RSNAConfigPMKReauthThreshold=%u\n"
3754 "dot11RSNAConfigNumberOfPTKSAReplayCounters=0\n"
3755 "dot11RSNAConfigSATimeout=%u\n"
3756 "dot11RSNAAuthenticationSuiteSelected=" RSN_SUITE
"\n"
3757 "dot11RSNAPairwiseCipherSelected=" RSN_SUITE
"\n"
3758 "dot11RSNAGroupCipherSelected=" RSN_SUITE
"\n"
3759 "dot11RSNAPMKIDUsed=%s\n"
3760 "dot11RSNAAuthenticationSuiteRequested=" RSN_SUITE
"\n"
3761 "dot11RSNAPairwiseCipherRequested=" RSN_SUITE
"\n"
3762 "dot11RSNAGroupCipherRequested=" RSN_SUITE
"\n"
3763 "dot11RSNATKIPCounterMeasuresInvoked=%u\n"
3764 "dot11RSNA4WayHandshakeFailures=%u\n"
3765 "dot11RSNAConfigNumberOfGTKSAReplayCounters=0\n",
3767 !!wpa_auth
->conf
.wpa_strict_rekey
,
3768 wpa_auth
->conf
.wpa_group_update_count
,
3769 wpa_auth
->conf
.wpa_pairwise_update_count
,
3770 wpa_cipher_key_len(wpa_auth
->conf
.wpa_group
) * 8,
3771 dot11RSNAConfigPMKLifetime
,
3772 dot11RSNAConfigPMKReauthThreshold
,
3773 dot11RSNAConfigSATimeout
,
3774 RSN_SUITE_ARG(wpa_auth
->dot11RSNAAuthenticationSuiteSelected
),
3775 RSN_SUITE_ARG(wpa_auth
->dot11RSNAPairwiseCipherSelected
),
3776 RSN_SUITE_ARG(wpa_auth
->dot11RSNAGroupCipherSelected
),
3778 RSN_SUITE_ARG(wpa_auth
->dot11RSNAAuthenticationSuiteRequested
),
3779 RSN_SUITE_ARG(wpa_auth
->dot11RSNAPairwiseCipherRequested
),
3780 RSN_SUITE_ARG(wpa_auth
->dot11RSNAGroupCipherRequested
),
3781 wpa_auth
->dot11RSNATKIPCounterMeasuresInvoked
,
3782 wpa_auth
->dot11RSNA4WayHandshakeFailures
);
3783 if (os_snprintf_error(buflen
- len
, ret
))
3787 /* TODO: dot11RSNAConfigPairwiseCiphersTable */
3788 /* TODO: dot11RSNAConfigAuthenticationSuitesTable */
3791 ret
= os_snprintf(buf
+ len
, buflen
- len
, "hostapdWPAGroupState=%d\n",
3792 wpa_auth
->group
->wpa_group_state
);
3793 if (os_snprintf_error(buflen
- len
, ret
))
3801 int wpa_get_mib_sta(struct wpa_state_machine
*sm
, char *buf
, size_t buflen
)
3809 /* TODO: FF-FF-FF-FF-FF-FF entry for broadcast/multicast stats */
3811 /* dot11RSNAStatsEntry */
3813 pairwise
= wpa_cipher_to_suite(sm
->wpa
== WPA_VERSION_WPA2
?
3814 WPA_PROTO_RSN
: WPA_PROTO_WPA
,
3820 buf
+ len
, buflen
- len
,
3821 /* TODO: dot11RSNAStatsIndex */
3822 "dot11RSNAStatsSTAAddress=" MACSTR
"\n"
3823 "dot11RSNAStatsVersion=1\n"
3824 "dot11RSNAStatsSelectedPairwiseCipher=" RSN_SUITE
"\n"
3825 /* TODO: dot11RSNAStatsTKIPICVErrors */
3826 "dot11RSNAStatsTKIPLocalMICFailures=%u\n"
3827 "dot11RSNAStatsTKIPRemoteMICFailures=%u\n"
3828 /* TODO: dot11RSNAStatsCCMPReplays */
3829 /* TODO: dot11RSNAStatsCCMPDecryptErrors */
3830 /* TODO: dot11RSNAStatsTKIPReplays */,
3832 RSN_SUITE_ARG(pairwise
),
3833 sm
->dot11RSNAStatsTKIPLocalMICFailures
,
3834 sm
->dot11RSNAStatsTKIPRemoteMICFailures
);
3835 if (os_snprintf_error(buflen
- len
, ret
))
3840 ret
= os_snprintf(buf
+ len
, buflen
- len
,
3841 "hostapdWPAPTKState=%d\n"
3842 "hostapdWPAPTKGroupState=%d\n",
3844 sm
->wpa_ptk_group_state
);
3845 if (os_snprintf_error(buflen
- len
, ret
))
3853 void wpa_auth_countermeasures_start(struct wpa_authenticator
*wpa_auth
)
3856 wpa_auth
->dot11RSNATKIPCounterMeasuresInvoked
++;
3860 int wpa_auth_pairwise_set(struct wpa_state_machine
*sm
)
3862 return sm
&& sm
->pairwise_set
;
3866 int wpa_auth_get_pairwise(struct wpa_state_machine
*sm
)
3868 return sm
->pairwise
;
3872 int wpa_auth_sta_key_mgmt(struct wpa_state_machine
*sm
)
3876 return sm
->wpa_key_mgmt
;
3880 int wpa_auth_sta_wpa_version(struct wpa_state_machine
*sm
)
3888 int wpa_auth_sta_clear_pmksa(struct wpa_state_machine
*sm
,
3889 struct rsn_pmksa_cache_entry
*entry
)
3891 if (sm
== NULL
|| sm
->pmksa
!= entry
)
3898 struct rsn_pmksa_cache_entry
*
3899 wpa_auth_sta_get_pmksa(struct wpa_state_machine
*sm
)
3901 return sm
? sm
->pmksa
: NULL
;
3905 void wpa_auth_sta_local_mic_failure_report(struct wpa_state_machine
*sm
)
3908 sm
->dot11RSNAStatsTKIPLocalMICFailures
++;
3912 const u8
* wpa_auth_get_wpa_ie(struct wpa_authenticator
*wpa_auth
, size_t *len
)
3914 if (wpa_auth
== NULL
)
3916 *len
= wpa_auth
->wpa_ie_len
;
3917 return wpa_auth
->wpa_ie
;
3921 int wpa_auth_pmksa_add(struct wpa_state_machine
*sm
, const u8
*pmk
,
3922 unsigned int pmk_len
,
3923 int session_timeout
, struct eapol_state_machine
*eapol
)
3925 if (sm
== NULL
|| sm
->wpa
!= WPA_VERSION_WPA2
||
3926 sm
->wpa_auth
->conf
.disable_pmksa_caching
)
3929 if (wpa_key_mgmt_sha384(sm
->wpa_key_mgmt
)) {
3930 if (pmk_len
> PMK_LEN_SUITE_B_192
)
3931 pmk_len
= PMK_LEN_SUITE_B_192
;
3932 } else if (pmk_len
> PMK_LEN
) {
3936 if (pmksa_cache_auth_add(sm
->wpa_auth
->pmksa
, pmk
, pmk_len
, NULL
,
3937 sm
->PTK
.kck
, sm
->PTK
.kck_len
,
3938 sm
->wpa_auth
->addr
, sm
->addr
, session_timeout
,
3939 eapol
, sm
->wpa_key_mgmt
))
3946 int wpa_auth_pmksa_add_preauth(struct wpa_authenticator
*wpa_auth
,
3947 const u8
*pmk
, size_t len
, const u8
*sta_addr
,
3948 int session_timeout
,
3949 struct eapol_state_machine
*eapol
)
3951 if (wpa_auth
== NULL
)
3954 if (pmksa_cache_auth_add(wpa_auth
->pmksa
, pmk
, len
, NULL
,
3957 sta_addr
, session_timeout
, eapol
,
3958 WPA_KEY_MGMT_IEEE8021X
))
3965 int wpa_auth_pmksa_add_sae(struct wpa_authenticator
*wpa_auth
, const u8
*addr
,
3966 const u8
*pmk
, const u8
*pmkid
)
3968 if (wpa_auth
->conf
.disable_pmksa_caching
)
3971 if (pmksa_cache_auth_add(wpa_auth
->pmksa
, pmk
, PMK_LEN
, pmkid
,
3973 wpa_auth
->addr
, addr
, 0, NULL
,
3981 void wpa_auth_pmksa_remove(struct wpa_authenticator
*wpa_auth
,
3984 struct rsn_pmksa_cache_entry
*pmksa
;
3986 if (wpa_auth
== NULL
|| wpa_auth
->pmksa
== NULL
)
3988 pmksa
= pmksa_cache_auth_get(wpa_auth
->pmksa
, sta_addr
, NULL
);
3990 wpa_printf(MSG_DEBUG
, "WPA: Remove PMKSA cache entry for "
3991 MACSTR
" based on request", MAC2STR(sta_addr
));
3992 pmksa_cache_free_entry(wpa_auth
->pmksa
, pmksa
);
3997 int wpa_auth_pmksa_list(struct wpa_authenticator
*wpa_auth
, char *buf
,
4000 if (!wpa_auth
|| !wpa_auth
->pmksa
)
4002 return pmksa_cache_auth_list(wpa_auth
->pmksa
, buf
, len
);
4006 void wpa_auth_pmksa_flush(struct wpa_authenticator
*wpa_auth
)
4008 if (wpa_auth
&& wpa_auth
->pmksa
)
4009 pmksa_cache_auth_flush(wpa_auth
->pmksa
);
4013 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
4016 int wpa_auth_pmksa_list_mesh(struct wpa_authenticator
*wpa_auth
, const u8
*addr
,
4017 char *buf
, size_t len
)
4019 if (!wpa_auth
|| !wpa_auth
->pmksa
)
4022 return pmksa_cache_auth_list_mesh(wpa_auth
->pmksa
, addr
, buf
, len
);
4026 struct rsn_pmksa_cache_entry
*
4027 wpa_auth_pmksa_create_entry(const u8
*aa
, const u8
*spa
, const u8
*pmk
,
4028 const u8
*pmkid
, int expiration
)
4030 struct rsn_pmksa_cache_entry
*entry
;
4031 struct os_reltime now
;
4033 entry
= pmksa_cache_auth_create_entry(pmk
, PMK_LEN
, pmkid
, NULL
, 0, aa
,
4034 spa
, 0, NULL
, WPA_KEY_MGMT_SAE
);
4038 os_get_reltime(&now
);
4039 entry
->expiration
= now
.sec
+ expiration
;
4044 int wpa_auth_pmksa_add_entry(struct wpa_authenticator
*wpa_auth
,
4045 struct rsn_pmksa_cache_entry
*entry
)
4049 if (!wpa_auth
|| !wpa_auth
->pmksa
)
4052 ret
= pmksa_cache_auth_add_entry(wpa_auth
->pmksa
, entry
);
4054 wpa_printf(MSG_DEBUG
,
4055 "RSN: Failed to store external PMKSA cache for "
4056 MACSTR
, MAC2STR(entry
->spa
));
4061 #endif /* CONFIG_MESH */
4062 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
4065 struct rsn_pmksa_cache_entry
*
4066 wpa_auth_pmksa_get(struct wpa_authenticator
*wpa_auth
, const u8
*sta_addr
,
4069 if (!wpa_auth
|| !wpa_auth
->pmksa
)
4071 return pmksa_cache_auth_get(wpa_auth
->pmksa
, sta_addr
, pmkid
);
4075 void wpa_auth_pmksa_set_to_sm(struct rsn_pmksa_cache_entry
*pmksa
,
4076 struct wpa_state_machine
*sm
,
4077 struct wpa_authenticator
*wpa_auth
,
4084 os_memcpy(pmk
, pmksa
->pmk
, PMK_LEN
);
4085 os_memcpy(pmkid
, pmksa
->pmkid
, PMKID_LEN
);
4086 os_memcpy(wpa_auth
->dot11RSNAPMKIDUsed
, pmksa
->pmkid
, PMKID_LEN
);
4091 * Remove and free the group from wpa_authenticator. This is triggered by a
4092 * callback to make sure nobody is currently iterating the group list while it
4095 static void wpa_group_free(struct wpa_authenticator
*wpa_auth
,
4096 struct wpa_group
*group
)
4098 struct wpa_group
*prev
= wpa_auth
->group
;
4100 wpa_printf(MSG_DEBUG
, "WPA: Remove group state machine for VLAN-ID %d",
4104 if (prev
->next
== group
) {
4105 /* This never frees the special first group as needed */
4106 prev
->next
= group
->next
;
4116 /* Increase the reference counter for group */
4117 static void wpa_group_get(struct wpa_authenticator
*wpa_auth
,
4118 struct wpa_group
*group
)
4120 /* Skip the special first group */
4121 if (wpa_auth
->group
== group
)
4124 group
->references
++;
4128 /* Decrease the reference counter and maybe free the group */
4129 static void wpa_group_put(struct wpa_authenticator
*wpa_auth
,
4130 struct wpa_group
*group
)
4132 /* Skip the special first group */
4133 if (wpa_auth
->group
== group
)
4136 group
->references
--;
4137 if (group
->references
)
4139 wpa_group_free(wpa_auth
, group
);
4144 * Add a group that has its references counter set to zero. Caller needs to
4145 * call wpa_group_get() on the return value to mark the entry in use.
4147 static struct wpa_group
*
4148 wpa_auth_add_group(struct wpa_authenticator
*wpa_auth
, int vlan_id
)
4150 struct wpa_group
*group
;
4152 if (wpa_auth
== NULL
|| wpa_auth
->group
== NULL
)
4155 wpa_printf(MSG_DEBUG
, "WPA: Add group state machine for VLAN-ID %d",
4157 group
= wpa_group_init(wpa_auth
, vlan_id
, 0);
4161 group
->next
= wpa_auth
->group
->next
;
4162 wpa_auth
->group
->next
= group
;
4169 * Enforce that the group state machine for the VLAN is running, increase
4170 * reference counter as interface is up. References might have been increased
4171 * even if a negative value is returned.
4172 * Returns: -1 on error (group missing, group already failed); otherwise, 0
4174 int wpa_auth_ensure_group(struct wpa_authenticator
*wpa_auth
, int vlan_id
)
4176 struct wpa_group
*group
;
4178 if (wpa_auth
== NULL
)
4181 group
= wpa_auth
->group
;
4183 if (group
->vlan_id
== vlan_id
)
4185 group
= group
->next
;
4188 if (group
== NULL
) {
4189 group
= wpa_auth_add_group(wpa_auth
, vlan_id
);
4194 wpa_printf(MSG_DEBUG
,
4195 "WPA: Ensure group state machine running for VLAN ID %d",
4198 wpa_group_get(wpa_auth
, group
);
4199 group
->num_setup_iface
++;
4201 if (group
->wpa_group_state
== WPA_GROUP_FATAL_FAILURE
)
4209 * Decrease reference counter, expected to be zero afterwards.
4210 * returns: -1 on error (group not found, group in fail state)
4211 * -2 if wpa_group is still referenced
4214 int wpa_auth_release_group(struct wpa_authenticator
*wpa_auth
, int vlan_id
)
4216 struct wpa_group
*group
;
4219 if (wpa_auth
== NULL
)
4222 group
= wpa_auth
->group
;
4224 if (group
->vlan_id
== vlan_id
)
4226 group
= group
->next
;
4232 wpa_printf(MSG_DEBUG
,
4233 "WPA: Try stopping group state machine for VLAN ID %d",
4236 if (group
->num_setup_iface
<= 0) {
4237 wpa_printf(MSG_ERROR
,
4238 "WPA: wpa_auth_release_group called more often than wpa_auth_ensure_group for VLAN ID %d, skipping.",
4242 group
->num_setup_iface
--;
4244 if (group
->wpa_group_state
== WPA_GROUP_FATAL_FAILURE
)
4247 if (group
->references
> 1) {
4248 wpa_printf(MSG_DEBUG
,
4249 "WPA: Cannot stop group state machine for VLAN ID %d as references are still hold",
4254 wpa_group_put(wpa_auth
, group
);
4260 int wpa_auth_sta_set_vlan(struct wpa_state_machine
*sm
, int vlan_id
)
4262 struct wpa_group
*group
;
4264 if (sm
== NULL
|| sm
->wpa_auth
== NULL
)
4267 group
= sm
->wpa_auth
->group
;
4269 if (group
->vlan_id
== vlan_id
)
4271 group
= group
->next
;
4274 if (group
== NULL
) {
4275 group
= wpa_auth_add_group(sm
->wpa_auth
, vlan_id
);
4280 if (sm
->group
== group
)
4283 if (group
->wpa_group_state
== WPA_GROUP_FATAL_FAILURE
)
4286 wpa_printf(MSG_DEBUG
, "WPA: Moving STA " MACSTR
" to use group state "
4287 "machine for VLAN ID %d", MAC2STR(sm
->addr
), vlan_id
);
4289 wpa_group_get(sm
->wpa_auth
, group
);
4290 wpa_group_put(sm
->wpa_auth
, sm
->group
);
4297 void wpa_auth_eapol_key_tx_status(struct wpa_authenticator
*wpa_auth
,
4298 struct wpa_state_machine
*sm
, int ack
)
4300 if (wpa_auth
== NULL
|| sm
== NULL
)
4302 wpa_printf(MSG_DEBUG
, "WPA: EAPOL-Key TX status for STA " MACSTR
4303 " ack=%d", MAC2STR(sm
->addr
), ack
);
4304 if (sm
->pending_1_of_4_timeout
&& ack
) {
4306 * Some deployed supplicant implementations update their SNonce
4307 * for each EAPOL-Key 2/4 message even within the same 4-way
4308 * handshake and then fail to use the first SNonce when
4309 * deriving the PTK. This results in unsuccessful 4-way
4310 * handshake whenever the relatively short initial timeout is
4311 * reached and EAPOL-Key 1/4 is retransmitted. Try to work
4312 * around this by increasing the timeout now that we know that
4313 * the station has received the frame.
4315 int timeout_ms
= eapol_key_timeout_subseq
;
4316 wpa_printf(MSG_DEBUG
, "WPA: Increase initial EAPOL-Key 1/4 "
4317 "timeout by %u ms because of acknowledged frame",
4319 eloop_cancel_timeout(wpa_send_eapol_timeout
, wpa_auth
, sm
);
4320 eloop_register_timeout(timeout_ms
/ 1000,
4321 (timeout_ms
% 1000) * 1000,
4322 wpa_send_eapol_timeout
, wpa_auth
, sm
);
4327 int wpa_auth_uses_sae(struct wpa_state_machine
*sm
)
4331 return wpa_key_mgmt_sae(sm
->wpa_key_mgmt
);
4335 int wpa_auth_uses_ft_sae(struct wpa_state_machine
*sm
)
4339 return sm
->wpa_key_mgmt
== WPA_KEY_MGMT_FT_SAE
;
4344 int wpa_auth_get_ip_addr(struct wpa_state_machine
*sm
, u8
*addr
)
4346 if (sm
== NULL
|| WPA_GET_BE32(sm
->ip_addr
) == 0)
4348 os_memcpy(addr
, sm
->ip_addr
, 4);
4351 #endif /* CONFIG_P2P */
4354 int wpa_auth_radius_das_disconnect_pmksa(struct wpa_authenticator
*wpa_auth
,
4355 struct radius_das_attrs
*attr
)
4357 return pmksa_cache_auth_radius_das_disconnect(wpa_auth
->pmksa
, attr
);
4361 void wpa_auth_reconfig_group_keys(struct wpa_authenticator
*wpa_auth
)
4363 struct wpa_group
*group
;
4367 for (group
= wpa_auth
->group
; group
; group
= group
->next
)
4368 wpa_group_config_group_keys(wpa_auth
, group
);
4374 struct wpa_auth_fils_iter_data
{
4375 struct wpa_authenticator
*auth
;
4377 struct rsn_pmksa_cache_entry
*pmksa
;
4383 static int wpa_auth_fils_iter(struct wpa_authenticator
*a
, void *ctx
)
4385 struct wpa_auth_fils_iter_data
*data
= ctx
;
4387 if (a
== data
->auth
|| !a
->conf
.fils_cache_id_set
||
4388 os_memcmp(a
->conf
.fils_cache_id
, data
->cache_id
,
4389 FILS_CACHE_ID_LEN
) != 0)
4391 data
->pmksa
= pmksa_cache_auth_get(a
->pmksa
, data
->spa
, data
->pmkid
);
4392 return data
->pmksa
!= NULL
;
4396 struct rsn_pmksa_cache_entry
*
4397 wpa_auth_pmksa_get_fils_cache_id(struct wpa_authenticator
*wpa_auth
,
4398 const u8
*sta_addr
, const u8
*pmkid
)
4400 struct wpa_auth_fils_iter_data idata
;
4402 if (!wpa_auth
->conf
.fils_cache_id_set
)
4404 idata
.auth
= wpa_auth
;
4405 idata
.cache_id
= wpa_auth
->conf
.fils_cache_id
;
4407 idata
.spa
= sta_addr
;
4408 idata
.pmkid
= pmkid
;
4409 wpa_auth_for_each_auth(wpa_auth
, wpa_auth_fils_iter
, &idata
);
4414 #ifdef CONFIG_IEEE80211R_AP
4415 int wpa_auth_write_fte(struct wpa_authenticator
*wpa_auth
, u8
*buf
, size_t len
)
4417 struct wpa_auth_config
*conf
= &wpa_auth
->conf
;
4419 return wpa_write_ftie(conf
, conf
->r0_key_holder
,
4420 conf
->r0_key_holder_len
,
4421 NULL
, NULL
, buf
, len
, NULL
, 0);
4423 #endif /* CONFIG_IEEE80211R_AP */
4426 void wpa_auth_get_fils_aead_params(struct wpa_state_machine
*sm
,
4427 u8
*fils_anonce
, u8
*fils_snonce
,
4428 u8
*fils_kek
, size_t *fils_kek_len
)
4430 os_memcpy(fils_anonce
, sm
->ANonce
, WPA_NONCE_LEN
);
4431 os_memcpy(fils_snonce
, sm
->SNonce
, WPA_NONCE_LEN
);
4432 os_memcpy(fils_kek
, sm
->PTK
.kek
, WPA_KEK_MAX_LEN
);
4433 *fils_kek_len
= sm
->PTK
.kek_len
;
4436 #endif /* CONFIG_FILS */