2 * IEEE 802.11 RSN / WPA Authenticator
3 * Copyright (c) 2004-2018, 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 "common/ocv.h"
17 #include "crypto/aes.h"
18 #include "crypto/aes_wrap.h"
19 #include "crypto/aes_siv.h"
20 #include "crypto/crypto.h"
21 #include "crypto/sha1.h"
22 #include "crypto/sha256.h"
23 #include "crypto/sha384.h"
24 #include "crypto/random.h"
25 #include "eapol_auth/eapol_auth_sm.h"
26 #include "drivers/driver.h"
27 #include "ap_config.h"
28 #include "ieee802_11.h"
30 #include "pmksa_cache_auth.h"
31 #include "wpa_auth_i.h"
32 #include "wpa_auth_ie.h"
34 #define STATE_MACHINE_DATA struct wpa_state_machine
35 #define STATE_MACHINE_DEBUG_PREFIX "WPA"
36 #define STATE_MACHINE_ADDR sm->addr
39 static void wpa_send_eapol_timeout(void *eloop_ctx
, void *timeout_ctx
);
40 static int wpa_sm_step(struct wpa_state_machine
*sm
);
41 static int wpa_verify_key_mic(int akmp
, size_t pmk_len
, struct wpa_ptk
*PTK
,
42 u8
*data
, size_t data_len
);
44 static int wpa_aead_decrypt(struct wpa_state_machine
*sm
, struct wpa_ptk
*ptk
,
45 u8
*buf
, size_t buf_len
, u16
*_key_data_len
);
46 static struct wpabuf
* fils_prepare_plainbuf(struct wpa_state_machine
*sm
,
47 const struct wpabuf
*hlp
);
48 #endif /* CONFIG_FILS */
49 static void wpa_sm_call_step(void *eloop_ctx
, void *timeout_ctx
);
50 static void wpa_group_sm_step(struct wpa_authenticator
*wpa_auth
,
51 struct wpa_group
*group
);
52 static void wpa_request_new_ptk(struct wpa_state_machine
*sm
);
53 static int wpa_gtk_update(struct wpa_authenticator
*wpa_auth
,
54 struct wpa_group
*group
);
55 static int wpa_group_config_group_keys(struct wpa_authenticator
*wpa_auth
,
56 struct wpa_group
*group
);
57 static int wpa_derive_ptk(struct wpa_state_machine
*sm
, const u8
*snonce
,
58 const u8
*pmk
, unsigned int pmk_len
,
60 static void wpa_group_free(struct wpa_authenticator
*wpa_auth
,
61 struct wpa_group
*group
);
62 static void wpa_group_get(struct wpa_authenticator
*wpa_auth
,
63 struct wpa_group
*group
);
64 static void wpa_group_put(struct wpa_authenticator
*wpa_auth
,
65 struct wpa_group
*group
);
66 static u8
* ieee80211w_kde_add(struct wpa_state_machine
*sm
, u8
*pos
);
68 static const u32 eapol_key_timeout_first
= 100; /* ms */
69 static const u32 eapol_key_timeout_subseq
= 1000; /* ms */
70 static const u32 eapol_key_timeout_first_group
= 500; /* ms */
71 static const u32 eapol_key_timeout_no_retrans
= 4000; /* ms */
73 /* TODO: make these configurable */
74 static const int dot11RSNAConfigPMKLifetime
= 43200;
75 static const int dot11RSNAConfigPMKReauthThreshold
= 70;
76 static const int dot11RSNAConfigSATimeout
= 60;
79 static inline int wpa_auth_mic_failure_report(
80 struct wpa_authenticator
*wpa_auth
, const u8
*addr
)
82 if (wpa_auth
->cb
->mic_failure_report
)
83 return wpa_auth
->cb
->mic_failure_report(wpa_auth
->cb_ctx
, addr
);
88 static inline void wpa_auth_psk_failure_report(
89 struct wpa_authenticator
*wpa_auth
, const u8
*addr
)
91 if (wpa_auth
->cb
->psk_failure_report
)
92 wpa_auth
->cb
->psk_failure_report(wpa_auth
->cb_ctx
, addr
);
96 static inline void wpa_auth_set_eapol(struct wpa_authenticator
*wpa_auth
,
97 const u8
*addr
, wpa_eapol_variable var
,
100 if (wpa_auth
->cb
->set_eapol
)
101 wpa_auth
->cb
->set_eapol(wpa_auth
->cb_ctx
, addr
, var
, value
);
105 static inline int wpa_auth_get_eapol(struct wpa_authenticator
*wpa_auth
,
106 const u8
*addr
, wpa_eapol_variable var
)
108 if (wpa_auth
->cb
->get_eapol
== NULL
)
110 return wpa_auth
->cb
->get_eapol(wpa_auth
->cb_ctx
, addr
, var
);
114 static inline const u8
* wpa_auth_get_psk(struct wpa_authenticator
*wpa_auth
,
116 const u8
*p2p_dev_addr
,
117 const u8
*prev_psk
, size_t *psk_len
)
119 if (wpa_auth
->cb
->get_psk
== NULL
)
121 return wpa_auth
->cb
->get_psk(wpa_auth
->cb_ctx
, addr
, p2p_dev_addr
,
126 static inline int wpa_auth_get_msk(struct wpa_authenticator
*wpa_auth
,
127 const u8
*addr
, u8
*msk
, size_t *len
)
129 if (wpa_auth
->cb
->get_msk
== NULL
)
131 return wpa_auth
->cb
->get_msk(wpa_auth
->cb_ctx
, addr
, msk
, len
);
135 static inline int wpa_auth_set_key(struct wpa_authenticator
*wpa_auth
,
137 enum wpa_alg alg
, const u8
*addr
, int idx
,
138 u8
*key
, size_t key_len
)
140 if (wpa_auth
->cb
->set_key
== NULL
)
142 return wpa_auth
->cb
->set_key(wpa_auth
->cb_ctx
, vlan_id
, alg
, addr
, idx
,
147 static inline int wpa_auth_get_seqnum(struct wpa_authenticator
*wpa_auth
,
148 const u8
*addr
, int idx
, u8
*seq
)
150 if (wpa_auth
->cb
->get_seqnum
== NULL
)
152 return wpa_auth
->cb
->get_seqnum(wpa_auth
->cb_ctx
, addr
, idx
, seq
);
157 wpa_auth_send_eapol(struct wpa_authenticator
*wpa_auth
, const u8
*addr
,
158 const u8
*data
, size_t data_len
, int encrypt
)
160 if (wpa_auth
->cb
->send_eapol
== NULL
)
162 return wpa_auth
->cb
->send_eapol(wpa_auth
->cb_ctx
, addr
, data
, data_len
,
168 static inline int wpa_auth_start_ampe(struct wpa_authenticator
*wpa_auth
,
171 if (wpa_auth
->cb
->start_ampe
== NULL
)
173 return wpa_auth
->cb
->start_ampe(wpa_auth
->cb_ctx
, addr
);
175 #endif /* CONFIG_MESH */
178 int wpa_auth_for_each_sta(struct wpa_authenticator
*wpa_auth
,
179 int (*cb
)(struct wpa_state_machine
*sm
, void *ctx
),
182 if (wpa_auth
->cb
->for_each_sta
== NULL
)
184 return wpa_auth
->cb
->for_each_sta(wpa_auth
->cb_ctx
, cb
, cb_ctx
);
188 int wpa_auth_for_each_auth(struct wpa_authenticator
*wpa_auth
,
189 int (*cb
)(struct wpa_authenticator
*a
, void *ctx
),
192 if (wpa_auth
->cb
->for_each_auth
== NULL
)
194 return wpa_auth
->cb
->for_each_auth(wpa_auth
->cb_ctx
, cb
, cb_ctx
);
198 void wpa_auth_logger(struct wpa_authenticator
*wpa_auth
, const u8
*addr
,
199 logger_level level
, const char *txt
)
201 if (wpa_auth
->cb
->logger
== NULL
)
203 wpa_auth
->cb
->logger(wpa_auth
->cb_ctx
, addr
, level
, txt
);
207 void wpa_auth_vlogger(struct wpa_authenticator
*wpa_auth
, const u8
*addr
,
208 logger_level level
, const char *fmt
, ...)
214 if (wpa_auth
->cb
->logger
== NULL
)
217 maxlen
= os_strlen(fmt
) + 100;
218 format
= os_malloc(maxlen
);
223 vsnprintf(format
, maxlen
, fmt
, ap
);
226 wpa_auth_logger(wpa_auth
, addr
, level
, format
);
232 static void wpa_sta_disconnect(struct wpa_authenticator
*wpa_auth
,
233 const u8
*addr
, u16 reason
)
235 if (wpa_auth
->cb
->disconnect
== NULL
)
237 wpa_printf(MSG_DEBUG
, "wpa_sta_disconnect STA " MACSTR
" (reason %u)",
238 MAC2STR(addr
), reason
);
239 wpa_auth
->cb
->disconnect(wpa_auth
->cb_ctx
, addr
, reason
);
244 static int wpa_channel_info(struct wpa_authenticator
*wpa_auth
,
245 struct wpa_channel_info
*ci
)
247 if (!wpa_auth
->cb
->channel_info
)
249 return wpa_auth
->cb
->channel_info(wpa_auth
->cb_ctx
, ci
);
251 #endif /* CONFIG_OCV */
254 static void wpa_rekey_gmk(void *eloop_ctx
, void *timeout_ctx
)
256 struct wpa_authenticator
*wpa_auth
= eloop_ctx
;
258 if (random_get_bytes(wpa_auth
->group
->GMK
, WPA_GMK_LEN
)) {
259 wpa_printf(MSG_ERROR
, "Failed to get random data for WPA "
262 wpa_auth_logger(wpa_auth
, NULL
, LOGGER_DEBUG
, "GMK rekeyd");
263 wpa_hexdump_key(MSG_DEBUG
, "GMK",
264 wpa_auth
->group
->GMK
, WPA_GMK_LEN
);
267 if (wpa_auth
->conf
.wpa_gmk_rekey
) {
268 eloop_register_timeout(wpa_auth
->conf
.wpa_gmk_rekey
, 0,
269 wpa_rekey_gmk
, wpa_auth
, NULL
);
274 static void wpa_rekey_gtk(void *eloop_ctx
, void *timeout_ctx
)
276 struct wpa_authenticator
*wpa_auth
= eloop_ctx
;
277 struct wpa_group
*group
, *next
;
279 wpa_auth_logger(wpa_auth
, NULL
, LOGGER_DEBUG
, "rekeying GTK");
280 group
= wpa_auth
->group
;
282 wpa_group_get(wpa_auth
, group
);
284 group
->GTKReKey
= TRUE
;
286 group
->changed
= FALSE
;
287 wpa_group_sm_step(wpa_auth
, group
);
288 } while (group
->changed
);
291 wpa_group_put(wpa_auth
, group
);
295 if (wpa_auth
->conf
.wpa_group_rekey
) {
296 eloop_register_timeout(wpa_auth
->conf
.wpa_group_rekey
,
297 0, wpa_rekey_gtk
, wpa_auth
, NULL
);
302 static void wpa_rekey_ptk(void *eloop_ctx
, void *timeout_ctx
)
304 struct wpa_authenticator
*wpa_auth
= eloop_ctx
;
305 struct wpa_state_machine
*sm
= timeout_ctx
;
307 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
, "rekeying PTK");
308 wpa_request_new_ptk(sm
);
313 static int wpa_auth_pmksa_clear_cb(struct wpa_state_machine
*sm
, void *ctx
)
315 if (sm
->pmksa
== ctx
)
321 static void wpa_auth_pmksa_free_cb(struct rsn_pmksa_cache_entry
*entry
,
324 struct wpa_authenticator
*wpa_auth
= ctx
;
325 wpa_auth_for_each_sta(wpa_auth
, wpa_auth_pmksa_clear_cb
, entry
);
329 static int wpa_group_init_gmk_and_counter(struct wpa_authenticator
*wpa_auth
,
330 struct wpa_group
*group
)
332 u8 buf
[ETH_ALEN
+ 8 + sizeof(unsigned long)];
336 if (random_get_bytes(group
->GMK
, WPA_GMK_LEN
) < 0)
338 wpa_hexdump_key(MSG_DEBUG
, "GMK", group
->GMK
, WPA_GMK_LEN
);
341 * Counter = PRF-256(Random number, "Init Counter",
342 * Local MAC Address || Time)
344 os_memcpy(buf
, wpa_auth
->addr
, ETH_ALEN
);
345 wpa_get_ntp_timestamp(buf
+ ETH_ALEN
);
346 ptr
= (unsigned long) group
;
347 os_memcpy(buf
+ ETH_ALEN
+ 8, &ptr
, sizeof(ptr
));
348 if (random_get_bytes(rkey
, sizeof(rkey
)) < 0)
351 if (sha1_prf(rkey
, sizeof(rkey
), "Init Counter", buf
, sizeof(buf
),
352 group
->Counter
, WPA_NONCE_LEN
) < 0)
354 wpa_hexdump_key(MSG_DEBUG
, "Key Counter",
355 group
->Counter
, WPA_NONCE_LEN
);
361 static struct wpa_group
* wpa_group_init(struct wpa_authenticator
*wpa_auth
,
362 int vlan_id
, int delay_init
)
364 struct wpa_group
*group
;
366 group
= os_zalloc(sizeof(struct wpa_group
));
370 group
->GTKAuthenticator
= TRUE
;
371 group
->vlan_id
= vlan_id
;
372 group
->GTK_len
= wpa_cipher_key_len(wpa_auth
->conf
.wpa_group
);
374 if (random_pool_ready() != 1) {
375 wpa_printf(MSG_INFO
, "WPA: Not enough entropy in random pool "
376 "for secure operations - update keys later when "
377 "the first station connects");
381 * Set initial GMK/Counter value here. The actual values that will be
382 * used in negotiations will be set once the first station tries to
383 * connect. This allows more time for collecting additional randomness
384 * on embedded devices.
386 if (wpa_group_init_gmk_and_counter(wpa_auth
, group
) < 0) {
387 wpa_printf(MSG_ERROR
, "Failed to get random data for WPA "
395 wpa_printf(MSG_DEBUG
, "WPA: Delay group state machine start "
396 "until Beacon frames have been configured");
397 /* Initialization is completed in wpa_init_keys(). */
399 wpa_group_sm_step(wpa_auth
, group
);
400 group
->GInit
= FALSE
;
401 wpa_group_sm_step(wpa_auth
, group
);
409 * wpa_init - Initialize WPA authenticator
410 * @addr: Authenticator address
411 * @conf: Configuration for WPA authenticator
412 * @cb: Callback functions for WPA authenticator
413 * Returns: Pointer to WPA authenticator data or %NULL on failure
415 struct wpa_authenticator
* wpa_init(const u8
*addr
,
416 struct wpa_auth_config
*conf
,
417 const struct wpa_auth_callbacks
*cb
,
420 struct wpa_authenticator
*wpa_auth
;
422 wpa_auth
= os_zalloc(sizeof(struct wpa_authenticator
));
423 if (wpa_auth
== NULL
)
425 os_memcpy(wpa_auth
->addr
, addr
, ETH_ALEN
);
426 os_memcpy(&wpa_auth
->conf
, conf
, sizeof(*conf
));
428 wpa_auth
->cb_ctx
= cb_ctx
;
430 if (wpa_auth_gen_wpa_ie(wpa_auth
)) {
431 wpa_printf(MSG_ERROR
, "Could not generate WPA IE.");
436 wpa_auth
->group
= wpa_group_init(wpa_auth
, 0, 1);
437 if (wpa_auth
->group
== NULL
) {
438 os_free(wpa_auth
->wpa_ie
);
443 wpa_auth
->pmksa
= pmksa_cache_auth_init(wpa_auth_pmksa_free_cb
,
445 if (wpa_auth
->pmksa
== NULL
) {
446 wpa_printf(MSG_ERROR
, "PMKSA cache initialization failed.");
447 os_free(wpa_auth
->group
);
448 os_free(wpa_auth
->wpa_ie
);
453 #ifdef CONFIG_IEEE80211R_AP
454 wpa_auth
->ft_pmk_cache
= wpa_ft_pmk_cache_init();
455 if (wpa_auth
->ft_pmk_cache
== NULL
) {
456 wpa_printf(MSG_ERROR
, "FT PMK cache initialization failed.");
457 os_free(wpa_auth
->group
);
458 os_free(wpa_auth
->wpa_ie
);
459 pmksa_cache_auth_deinit(wpa_auth
->pmksa
);
463 #endif /* CONFIG_IEEE80211R_AP */
465 if (wpa_auth
->conf
.wpa_gmk_rekey
) {
466 eloop_register_timeout(wpa_auth
->conf
.wpa_gmk_rekey
, 0,
467 wpa_rekey_gmk
, wpa_auth
, NULL
);
470 if (wpa_auth
->conf
.wpa_group_rekey
) {
471 eloop_register_timeout(wpa_auth
->conf
.wpa_group_rekey
, 0,
472 wpa_rekey_gtk
, wpa_auth
, NULL
);
476 if (WPA_GET_BE32(conf
->ip_addr_start
)) {
477 int count
= WPA_GET_BE32(conf
->ip_addr_end
) -
478 WPA_GET_BE32(conf
->ip_addr_start
) + 1;
482 wpa_auth
->ip_pool
= bitfield_alloc(count
);
484 #endif /* CONFIG_P2P */
490 int wpa_init_keys(struct wpa_authenticator
*wpa_auth
)
492 struct wpa_group
*group
= wpa_auth
->group
;
494 wpa_printf(MSG_DEBUG
, "WPA: Start group state machine to set initial "
496 wpa_group_sm_step(wpa_auth
, group
);
497 group
->GInit
= FALSE
;
498 wpa_group_sm_step(wpa_auth
, group
);
499 if (group
->wpa_group_state
== WPA_GROUP_FATAL_FAILURE
)
506 * wpa_deinit - Deinitialize WPA authenticator
507 * @wpa_auth: Pointer to WPA authenticator data from wpa_init()
509 void wpa_deinit(struct wpa_authenticator
*wpa_auth
)
511 struct wpa_group
*group
, *prev
;
513 eloop_cancel_timeout(wpa_rekey_gmk
, wpa_auth
, NULL
);
514 eloop_cancel_timeout(wpa_rekey_gtk
, wpa_auth
, NULL
);
516 pmksa_cache_auth_deinit(wpa_auth
->pmksa
);
518 #ifdef CONFIG_IEEE80211R_AP
519 wpa_ft_pmk_cache_deinit(wpa_auth
->ft_pmk_cache
);
520 wpa_auth
->ft_pmk_cache
= NULL
;
521 wpa_ft_deinit(wpa_auth
);
522 #endif /* CONFIG_IEEE80211R_AP */
525 bitfield_free(wpa_auth
->ip_pool
);
526 #endif /* CONFIG_P2P */
529 os_free(wpa_auth
->wpa_ie
);
531 group
= wpa_auth
->group
;
543 * wpa_reconfig - Update WPA authenticator configuration
544 * @wpa_auth: Pointer to WPA authenticator data from wpa_init()
545 * @conf: Configuration for WPA authenticator
547 int wpa_reconfig(struct wpa_authenticator
*wpa_auth
,
548 struct wpa_auth_config
*conf
)
550 struct wpa_group
*group
;
551 if (wpa_auth
== NULL
)
554 os_memcpy(&wpa_auth
->conf
, conf
, sizeof(*conf
));
555 if (wpa_auth_gen_wpa_ie(wpa_auth
)) {
556 wpa_printf(MSG_ERROR
, "Could not generate WPA IE.");
561 * Reinitialize GTK to make sure it is suitable for the new
564 group
= wpa_auth
->group
;
565 group
->GTK_len
= wpa_cipher_key_len(wpa_auth
->conf
.wpa_group
);
567 wpa_group_sm_step(wpa_auth
, group
);
568 group
->GInit
= FALSE
;
569 wpa_group_sm_step(wpa_auth
, group
);
575 struct wpa_state_machine
*
576 wpa_auth_sta_init(struct wpa_authenticator
*wpa_auth
, const u8
*addr
,
577 const u8
*p2p_dev_addr
)
579 struct wpa_state_machine
*sm
;
581 if (wpa_auth
->group
->wpa_group_state
== WPA_GROUP_FATAL_FAILURE
)
584 sm
= os_zalloc(sizeof(struct wpa_state_machine
));
587 os_memcpy(sm
->addr
, addr
, ETH_ALEN
);
589 os_memcpy(sm
->p2p_dev_addr
, p2p_dev_addr
, ETH_ALEN
);
591 sm
->wpa_auth
= wpa_auth
;
592 sm
->group
= wpa_auth
->group
;
593 wpa_group_get(sm
->wpa_auth
, sm
->group
);
599 int wpa_auth_sta_associated(struct wpa_authenticator
*wpa_auth
,
600 struct wpa_state_machine
*sm
)
602 if (wpa_auth
== NULL
|| !wpa_auth
->conf
.wpa
|| sm
== NULL
)
605 #ifdef CONFIG_IEEE80211R_AP
606 if (sm
->ft_completed
) {
607 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
608 "FT authentication already completed - do not "
609 "start 4-way handshake");
610 /* Go to PTKINITDONE state to allow GTK rekeying */
611 sm
->wpa_ptk_state
= WPA_PTK_PTKINITDONE
;
615 #endif /* CONFIG_IEEE80211R_AP */
618 if (sm
->fils_completed
) {
619 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
620 "FILS authentication already completed - do not start 4-way handshake");
621 /* Go to PTKINITDONE state to allow GTK rekeying */
622 sm
->wpa_ptk_state
= WPA_PTK_PTKINITDONE
;
626 #endif /* CONFIG_FILS */
629 os_memset(&sm
->key_replay
, 0, sizeof(sm
->key_replay
));
630 sm
->ReAuthenticationRequest
= TRUE
;
631 return wpa_sm_step(sm
);
634 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
635 "start authentication");
639 if (wpa_sm_step(sm
) == 1)
640 return 1; /* should not really happen */
642 sm
->AuthenticationRequest
= TRUE
;
643 return wpa_sm_step(sm
);
647 void wpa_auth_sta_no_wpa(struct wpa_state_machine
*sm
)
649 /* WPA/RSN was not used - clear WPA state. This is needed if the STA
650 * reassociates back to the same AP while the previous entry for the
651 * STA has not yet been removed. */
655 sm
->wpa_key_mgmt
= 0;
659 static void wpa_free_sta_sm(struct wpa_state_machine
*sm
)
662 if (WPA_GET_BE32(sm
->ip_addr
)) {
664 wpa_printf(MSG_DEBUG
, "P2P: Free assigned IP "
665 "address %u.%u.%u.%u from " MACSTR
,
666 sm
->ip_addr
[0], sm
->ip_addr
[1],
667 sm
->ip_addr
[2], sm
->ip_addr
[3],
669 start
= WPA_GET_BE32(sm
->wpa_auth
->conf
.ip_addr_start
);
670 bitfield_clear(sm
->wpa_auth
->ip_pool
,
671 WPA_GET_BE32(sm
->ip_addr
) - start
);
673 #endif /* CONFIG_P2P */
674 if (sm
->GUpdateStationKeys
) {
675 sm
->group
->GKeyDoneStations
--;
676 sm
->GUpdateStationKeys
= FALSE
;
678 #ifdef CONFIG_IEEE80211R_AP
679 os_free(sm
->assoc_resp_ftie
);
680 wpabuf_free(sm
->ft_pending_req_ies
);
681 #endif /* CONFIG_IEEE80211R_AP */
682 os_free(sm
->last_rx_eapol_key
);
684 wpa_group_put(sm
->wpa_auth
, sm
->group
);
689 void wpa_auth_sta_deinit(struct wpa_state_machine
*sm
)
694 if (sm
->wpa_auth
->conf
.wpa_strict_rekey
&& sm
->has_GTK
) {
695 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
696 "strict rekeying - force GTK rekey since STA "
698 if (eloop_deplete_timeout(0, 500000, wpa_rekey_gtk
,
699 sm
->wpa_auth
, NULL
) == -1)
700 eloop_register_timeout(0, 500000, wpa_rekey_gtk
, sm
->wpa_auth
,
704 eloop_cancel_timeout(wpa_send_eapol_timeout
, sm
->wpa_auth
, sm
);
705 sm
->pending_1_of_4_timeout
= 0;
706 eloop_cancel_timeout(wpa_sm_call_step
, sm
, NULL
);
707 eloop_cancel_timeout(wpa_rekey_ptk
, sm
->wpa_auth
, sm
);
708 #ifdef CONFIG_IEEE80211R_AP
709 wpa_ft_sta_deinit(sm
);
710 #endif /* CONFIG_IEEE80211R_AP */
711 if (sm
->in_step_loop
) {
712 /* Must not free state machine while wpa_sm_step() is running.
713 * Freeing will be completed in the end of wpa_sm_step(). */
714 wpa_printf(MSG_DEBUG
, "WPA: Registering pending STA state "
715 "machine deinit for " MACSTR
, MAC2STR(sm
->addr
));
716 sm
->pending_deinit
= 1;
722 static void wpa_request_new_ptk(struct wpa_state_machine
*sm
)
727 sm
->PTKRequest
= TRUE
;
732 static int wpa_replay_counter_valid(struct wpa_key_replay_counter
*ctr
,
733 const u8
*replay_counter
)
736 for (i
= 0; i
< RSNA_MAX_EAPOL_RETRIES
; i
++) {
739 if (os_memcmp(replay_counter
, ctr
[i
].counter
,
740 WPA_REPLAY_COUNTER_LEN
) == 0)
747 static void wpa_replay_counter_mark_invalid(struct wpa_key_replay_counter
*ctr
,
748 const u8
*replay_counter
)
751 for (i
= 0; i
< RSNA_MAX_EAPOL_RETRIES
; i
++) {
753 (replay_counter
== NULL
||
754 os_memcmp(replay_counter
, ctr
[i
].counter
,
755 WPA_REPLAY_COUNTER_LEN
) == 0))
756 ctr
[i
].valid
= FALSE
;
761 #ifdef CONFIG_IEEE80211R_AP
762 static int ft_check_msg_2_of_4(struct wpa_authenticator
*wpa_auth
,
763 struct wpa_state_machine
*sm
,
764 struct wpa_eapol_ie_parse
*kde
)
766 struct wpa_ie_data ie
;
767 struct rsn_mdie
*mdie
;
769 if (wpa_parse_wpa_ie_rsn(kde
->rsn_ie
, kde
->rsn_ie_len
, &ie
) < 0 ||
770 ie
.num_pmkid
!= 1 || ie
.pmkid
== NULL
) {
771 wpa_printf(MSG_DEBUG
, "FT: No PMKR1Name in "
772 "FT 4-way handshake message 2/4");
776 os_memcpy(sm
->sup_pmk_r1_name
, ie
.pmkid
, PMKID_LEN
);
777 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name from Supplicant",
778 sm
->sup_pmk_r1_name
, PMKID_LEN
);
780 if (!kde
->mdie
|| !kde
->ftie
) {
781 wpa_printf(MSG_DEBUG
, "FT: No %s in FT 4-way handshake "
782 "message 2/4", kde
->mdie
? "FTIE" : "MDIE");
786 mdie
= (struct rsn_mdie
*) (kde
->mdie
+ 2);
787 if (kde
->mdie
[1] < sizeof(struct rsn_mdie
) ||
788 os_memcmp(wpa_auth
->conf
.mobility_domain
, mdie
->mobility_domain
,
789 MOBILITY_DOMAIN_ID_LEN
) != 0) {
790 wpa_printf(MSG_DEBUG
, "FT: MDIE mismatch");
794 if (sm
->assoc_resp_ftie
&&
795 (kde
->ftie
[1] != sm
->assoc_resp_ftie
[1] ||
796 os_memcmp(kde
->ftie
, sm
->assoc_resp_ftie
,
797 2 + sm
->assoc_resp_ftie
[1]) != 0)) {
798 wpa_printf(MSG_DEBUG
, "FT: FTIE mismatch");
799 wpa_hexdump(MSG_DEBUG
, "FT: FTIE in EAPOL-Key msg 2/4",
800 kde
->ftie
, kde
->ftie_len
);
801 wpa_hexdump(MSG_DEBUG
, "FT: FTIE in (Re)AssocResp",
802 sm
->assoc_resp_ftie
, 2 + sm
->assoc_resp_ftie
[1]);
808 #endif /* CONFIG_IEEE80211R_AP */
811 static int wpa_receive_error_report(struct wpa_authenticator
*wpa_auth
,
812 struct wpa_state_machine
*sm
, int group
)
814 /* Supplicant reported a Michael MIC error */
815 wpa_auth_vlogger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
816 "received EAPOL-Key Error Request "
817 "(STA detected Michael MIC failure (group=%d))",
820 if (group
&& wpa_auth
->conf
.wpa_group
!= WPA_CIPHER_TKIP
) {
821 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
822 "ignore Michael MIC failure report since "
823 "group cipher is not TKIP");
824 } else if (!group
&& sm
->pairwise
!= WPA_CIPHER_TKIP
) {
825 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
826 "ignore Michael MIC failure report since "
827 "pairwise cipher is not TKIP");
829 if (wpa_auth_mic_failure_report(wpa_auth
, sm
->addr
) > 0)
830 return 1; /* STA entry was removed */
831 sm
->dot11RSNAStatsTKIPRemoteMICFailures
++;
832 wpa_auth
->dot11RSNAStatsTKIPRemoteMICFailures
++;
836 * Error report is not a request for a new key handshake, but since
837 * Authenticator may do it, let's change the keys now anyway.
839 wpa_request_new_ptk(sm
);
844 static int wpa_try_alt_snonce(struct wpa_state_machine
*sm
, u8
*data
,
849 const u8
*pmk
= NULL
;
852 os_memset(&PTK
, 0, sizeof(PTK
));
854 if (wpa_key_mgmt_wpa_psk(sm
->wpa_key_mgmt
) &&
855 !wpa_key_mgmt_sae(sm
->wpa_key_mgmt
)) {
856 pmk
= wpa_auth_get_psk(sm
->wpa_auth
, sm
->addr
,
857 sm
->p2p_dev_addr
, pmk
, &pmk_len
);
860 #ifdef CONFIG_IEEE80211R_AP
861 if (wpa_key_mgmt_ft_psk(sm
->wpa_key_mgmt
)) {
862 os_memcpy(sm
->xxkey
, pmk
, pmk_len
);
863 sm
->xxkey_len
= pmk_len
;
865 #endif /* CONFIG_IEEE80211R_AP */
868 pmk_len
= sm
->pmk_len
;
871 if (wpa_derive_ptk(sm
, sm
->alt_SNonce
, pmk
, pmk_len
, &PTK
) < 0)
874 if (wpa_verify_key_mic(sm
->wpa_key_mgmt
, pmk_len
, &PTK
,
875 data
, data_len
) == 0) {
880 if (!wpa_key_mgmt_wpa_psk(sm
->wpa_key_mgmt
) ||
881 wpa_key_mgmt_sae(sm
->wpa_key_mgmt
))
886 wpa_printf(MSG_DEBUG
,
887 "WPA: Earlier SNonce did not result in matching MIC");
891 wpa_printf(MSG_DEBUG
,
892 "WPA: Earlier SNonce resulted in matching MIC");
893 sm
->alt_snonce_valid
= 0;
894 os_memcpy(sm
->SNonce
, sm
->alt_SNonce
, WPA_NONCE_LEN
);
895 os_memcpy(&sm
->PTK
, &PTK
, sizeof(PTK
));
896 sm
->PTK_valid
= TRUE
;
902 void wpa_receive(struct wpa_authenticator
*wpa_auth
,
903 struct wpa_state_machine
*sm
,
904 u8
*data
, size_t data_len
)
906 struct ieee802_1x_hdr
*hdr
;
907 struct wpa_eapol_key
*key
;
908 u16 key_info
, key_data_length
;
909 enum { PAIRWISE_2
, PAIRWISE_4
, GROUP_2
, REQUEST
} msg
;
911 struct wpa_eapol_ie_parse kde
;
913 size_t keyhdrlen
, mic_len
;
916 if (wpa_auth
== NULL
|| !wpa_auth
->conf
.wpa
|| sm
== NULL
)
918 wpa_hexdump(MSG_MSGDUMP
, "WPA: RX EAPOL data", data
, data_len
);
920 mic_len
= wpa_mic_len(sm
->wpa_key_mgmt
, sm
->pmk_len
);
921 keyhdrlen
= sizeof(*key
) + mic_len
+ 2;
923 if (data_len
< sizeof(*hdr
) + keyhdrlen
) {
924 wpa_printf(MSG_DEBUG
, "WPA: Ignore too short EAPOL-Key frame");
928 hdr
= (struct ieee802_1x_hdr
*) data
;
929 key
= (struct wpa_eapol_key
*) (hdr
+ 1);
930 mic
= (u8
*) (key
+ 1);
931 key_info
= WPA_GET_BE16(key
->key_info
);
932 key_data
= mic
+ mic_len
+ 2;
933 key_data_length
= WPA_GET_BE16(mic
+ mic_len
);
934 wpa_printf(MSG_DEBUG
, "WPA: Received EAPOL-Key from " MACSTR
935 " key_info=0x%x type=%u mic_len=%u key_data_length=%u",
936 MAC2STR(sm
->addr
), key_info
, key
->type
,
937 (unsigned int) mic_len
, key_data_length
);
938 wpa_hexdump(MSG_MSGDUMP
,
939 "WPA: EAPOL-Key header (ending before Key MIC)",
941 wpa_hexdump(MSG_MSGDUMP
, "WPA: EAPOL-Key Key MIC",
943 if (key_data_length
> data_len
- sizeof(*hdr
) - keyhdrlen
) {
944 wpa_printf(MSG_INFO
, "WPA: Invalid EAPOL-Key frame - "
945 "key_data overflow (%d > %lu)",
947 (unsigned long) (data_len
- sizeof(*hdr
) -
952 if (sm
->wpa
== WPA_VERSION_WPA2
) {
953 if (key
->type
== EAPOL_KEY_TYPE_WPA
) {
955 * Some deployed station implementations seem to send
956 * msg 4/4 with incorrect type value in WPA2 mode.
958 wpa_printf(MSG_DEBUG
, "Workaround: Allow EAPOL-Key "
959 "with unexpected WPA type in RSN mode");
960 } else if (key
->type
!= EAPOL_KEY_TYPE_RSN
) {
961 wpa_printf(MSG_DEBUG
, "Ignore EAPOL-Key with "
962 "unexpected type %d in RSN mode",
967 if (key
->type
!= EAPOL_KEY_TYPE_WPA
) {
968 wpa_printf(MSG_DEBUG
, "Ignore EAPOL-Key with "
969 "unexpected type %d in WPA mode",
975 wpa_hexdump(MSG_DEBUG
, "WPA: Received Key Nonce", key
->key_nonce
,
977 wpa_hexdump(MSG_DEBUG
, "WPA: Received Replay Counter",
978 key
->replay_counter
, WPA_REPLAY_COUNTER_LEN
);
980 /* FIX: verify that the EAPOL-Key frame was encrypted if pairwise keys
983 if (key_info
& WPA_KEY_INFO_SMK_MESSAGE
) {
984 wpa_printf(MSG_DEBUG
, "WPA: Ignore SMK message");
988 if (key_info
& WPA_KEY_INFO_REQUEST
) {
991 } else if (!(key_info
& WPA_KEY_INFO_KEY_TYPE
)) {
993 msgtxt
= "2/2 Group";
994 } else if (key_data_length
== 0 ||
995 (mic_len
== 0 && (key_info
& WPA_KEY_INFO_ENCR_KEY_DATA
) &&
996 key_data_length
== AES_BLOCK_SIZE
)) {
998 msgtxt
= "4/4 Pairwise";
1001 msgtxt
= "2/4 Pairwise";
1004 if (msg
== REQUEST
|| msg
== PAIRWISE_2
|| msg
== PAIRWISE_4
||
1006 u16 ver
= key_info
& WPA_KEY_INFO_TYPE_MASK
;
1007 if (sm
->pairwise
== WPA_CIPHER_CCMP
||
1008 sm
->pairwise
== WPA_CIPHER_GCMP
) {
1009 if (wpa_use_cmac(sm
->wpa_key_mgmt
) &&
1010 !wpa_use_akm_defined(sm
->wpa_key_mgmt
) &&
1011 ver
!= WPA_KEY_INFO_TYPE_AES_128_CMAC
) {
1012 wpa_auth_logger(wpa_auth
, sm
->addr
,
1014 "advertised support for "
1015 "AES-128-CMAC, but did not "
1020 if (!wpa_use_cmac(sm
->wpa_key_mgmt
) &&
1021 !wpa_use_akm_defined(sm
->wpa_key_mgmt
) &&
1022 ver
!= WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
) {
1023 wpa_auth_logger(wpa_auth
, sm
->addr
,
1025 "did not use HMAC-SHA1-AES "
1031 if (wpa_use_akm_defined(sm
->wpa_key_mgmt
) &&
1032 ver
!= WPA_KEY_INFO_TYPE_AKM_DEFINED
) {
1033 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_WARNING
,
1034 "did not use EAPOL-Key descriptor version 0 as required for AKM-defined cases");
1039 if (key_info
& WPA_KEY_INFO_REQUEST
) {
1040 if (sm
->req_replay_counter_used
&&
1041 os_memcmp(key
->replay_counter
, sm
->req_replay_counter
,
1042 WPA_REPLAY_COUNTER_LEN
) <= 0) {
1043 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_WARNING
,
1044 "received EAPOL-Key request with "
1045 "replayed counter");
1050 if (!(key_info
& WPA_KEY_INFO_REQUEST
) &&
1051 !wpa_replay_counter_valid(sm
->key_replay
, key
->replay_counter
)) {
1054 if (msg
== PAIRWISE_2
&&
1055 wpa_replay_counter_valid(sm
->prev_key_replay
,
1056 key
->replay_counter
) &&
1057 sm
->wpa_ptk_state
== WPA_PTK_PTKINITNEGOTIATING
&&
1058 os_memcmp(sm
->SNonce
, key
->key_nonce
, WPA_NONCE_LEN
) != 0)
1061 * Some supplicant implementations (e.g., Windows XP
1062 * WZC) update SNonce for each EAPOL-Key 2/4. This
1063 * breaks the workaround on accepting any of the
1064 * pending requests, so allow the SNonce to be updated
1065 * even if we have already sent out EAPOL-Key 3/4.
1067 wpa_auth_vlogger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
1068 "Process SNonce update from STA "
1069 "based on retransmitted EAPOL-Key "
1071 sm
->update_snonce
= 1;
1072 os_memcpy(sm
->alt_SNonce
, sm
->SNonce
, WPA_NONCE_LEN
);
1073 sm
->alt_snonce_valid
= TRUE
;
1074 os_memcpy(sm
->alt_replay_counter
,
1075 sm
->key_replay
[0].counter
,
1076 WPA_REPLAY_COUNTER_LEN
);
1077 goto continue_processing
;
1080 if (msg
== PAIRWISE_4
&& sm
->alt_snonce_valid
&&
1081 sm
->wpa_ptk_state
== WPA_PTK_PTKINITNEGOTIATING
&&
1082 os_memcmp(key
->replay_counter
, sm
->alt_replay_counter
,
1083 WPA_REPLAY_COUNTER_LEN
) == 0) {
1085 * Supplicant may still be using the old SNonce since
1086 * there was two EAPOL-Key 2/4 messages and they had
1087 * different SNonce values.
1089 wpa_auth_vlogger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
1090 "Try to process received EAPOL-Key 4/4 based on old Replay Counter and SNonce from an earlier EAPOL-Key 1/4");
1091 goto continue_processing
;
1094 if (msg
== PAIRWISE_2
&&
1095 wpa_replay_counter_valid(sm
->prev_key_replay
,
1096 key
->replay_counter
) &&
1097 sm
->wpa_ptk_state
== WPA_PTK_PTKINITNEGOTIATING
) {
1098 wpa_auth_vlogger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
1099 "ignore retransmitted EAPOL-Key %s - "
1100 "SNonce did not change", msgtxt
);
1102 wpa_auth_vlogger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
1103 "received EAPOL-Key %s with "
1104 "unexpected replay counter", msgtxt
);
1106 for (i
= 0; i
< RSNA_MAX_EAPOL_RETRIES
; i
++) {
1107 if (!sm
->key_replay
[i
].valid
)
1109 wpa_hexdump(MSG_DEBUG
, "pending replay counter",
1110 sm
->key_replay
[i
].counter
,
1111 WPA_REPLAY_COUNTER_LEN
);
1113 wpa_hexdump(MSG_DEBUG
, "received replay counter",
1114 key
->replay_counter
, WPA_REPLAY_COUNTER_LEN
);
1118 continue_processing
:
1120 if (sm
->wpa
== WPA_VERSION_WPA2
&& mic_len
== 0 &&
1121 !(key_info
& WPA_KEY_INFO_ENCR_KEY_DATA
)) {
1122 wpa_auth_vlogger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
1123 "WPA: Encr Key Data bit not set even though AEAD cipher is supposed to be used - drop frame");
1126 #endif /* CONFIG_FILS */
1130 if (sm
->wpa_ptk_state
!= WPA_PTK_PTKSTART
&&
1131 sm
->wpa_ptk_state
!= WPA_PTK_PTKCALCNEGOTIATING
&&
1132 (!sm
->update_snonce
||
1133 sm
->wpa_ptk_state
!= WPA_PTK_PTKINITNEGOTIATING
)) {
1134 wpa_auth_vlogger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1135 "received EAPOL-Key msg 2/4 in "
1136 "invalid state (%d) - dropped",
1140 random_add_randomness(key
->key_nonce
, WPA_NONCE_LEN
);
1141 if (sm
->group
->reject_4way_hs_for_entropy
) {
1143 * The system did not have enough entropy to generate
1144 * strong random numbers. Reject the first 4-way
1145 * handshake(s) and collect some entropy based on the
1146 * information from it. Once enough entropy is
1147 * available, the next atempt will trigger GMK/Key
1148 * Counter update and the station will be allowed to
1151 wpa_printf(MSG_DEBUG
, "WPA: Reject 4-way handshake to "
1152 "collect more entropy for random number "
1154 random_mark_pool_ready();
1155 wpa_sta_disconnect(wpa_auth
, sm
->addr
,
1156 WLAN_REASON_PREV_AUTH_NOT_VALID
);
1161 if (sm
->wpa_ptk_state
!= WPA_PTK_PTKINITNEGOTIATING
||
1163 wpa_auth_vlogger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1164 "received EAPOL-Key msg 4/4 in "
1165 "invalid state (%d) - dropped",
1171 if (sm
->wpa_ptk_group_state
!= WPA_PTK_GROUP_REKEYNEGOTIATING
1172 || !sm
->PTK_valid
) {
1173 wpa_auth_vlogger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1174 "received EAPOL-Key msg 2/2 in "
1175 "invalid state (%d) - dropped",
1176 sm
->wpa_ptk_group_state
);
1184 wpa_auth_vlogger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
1185 "received EAPOL-Key frame (%s)", msgtxt
);
1187 if (key_info
& WPA_KEY_INFO_ACK
) {
1188 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1189 "received invalid EAPOL-Key: Key Ack set");
1193 if (!wpa_key_mgmt_fils(sm
->wpa_key_mgmt
) &&
1194 !(key_info
& WPA_KEY_INFO_MIC
)) {
1195 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1196 "received invalid EAPOL-Key: Key MIC not set");
1201 if (wpa_key_mgmt_fils(sm
->wpa_key_mgmt
) &&
1202 (key_info
& WPA_KEY_INFO_MIC
)) {
1203 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1204 "received invalid EAPOL-Key: Key MIC set");
1207 #endif /* CONFIG_FILS */
1209 sm
->MICVerified
= FALSE
;
1210 if (sm
->PTK_valid
&& !sm
->update_snonce
) {
1212 wpa_verify_key_mic(sm
->wpa_key_mgmt
, sm
->pmk_len
, &sm
->PTK
,
1214 (msg
!= PAIRWISE_4
|| !sm
->alt_snonce_valid
||
1215 wpa_try_alt_snonce(sm
, data
, data_len
))) {
1216 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1217 "received EAPOL-Key with invalid MIC");
1222 wpa_aead_decrypt(sm
, &sm
->PTK
, data
, data_len
,
1223 &key_data_length
) < 0) {
1224 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1225 "received EAPOL-Key with invalid MIC");
1228 #endif /* CONFIG_FILS */
1229 sm
->MICVerified
= TRUE
;
1230 eloop_cancel_timeout(wpa_send_eapol_timeout
, wpa_auth
, sm
);
1231 sm
->pending_1_of_4_timeout
= 0;
1234 if (key_info
& WPA_KEY_INFO_REQUEST
) {
1235 if (sm
->MICVerified
) {
1236 sm
->req_replay_counter_used
= 1;
1237 os_memcpy(sm
->req_replay_counter
, key
->replay_counter
,
1238 WPA_REPLAY_COUNTER_LEN
);
1240 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1241 "received EAPOL-Key request with "
1247 * TODO: should decrypt key data field if encryption was used;
1248 * even though MAC address KDE is not normally encrypted,
1249 * supplicant is allowed to encrypt it.
1251 if (key_info
& WPA_KEY_INFO_ERROR
) {
1252 if (wpa_receive_error_report(
1254 !(key_info
& WPA_KEY_INFO_KEY_TYPE
)) > 0)
1255 return; /* STA entry was removed */
1256 } else if (key_info
& WPA_KEY_INFO_KEY_TYPE
) {
1257 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1258 "received EAPOL-Key Request for new "
1260 wpa_request_new_ptk(sm
);
1261 } else if (key_data_length
> 0 &&
1262 wpa_parse_kde_ies(key_data
, key_data_length
,
1266 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1267 "received EAPOL-Key Request for GTK "
1269 eloop_cancel_timeout(wpa_rekey_gtk
, wpa_auth
, NULL
);
1270 wpa_rekey_gtk(wpa_auth
, NULL
);
1273 /* Do not allow the same key replay counter to be reused. */
1274 wpa_replay_counter_mark_invalid(sm
->key_replay
,
1275 key
->replay_counter
);
1277 if (msg
== PAIRWISE_2
) {
1279 * Maintain a copy of the pending EAPOL-Key frames in
1280 * case the EAPOL-Key frame was retransmitted. This is
1281 * needed to allow EAPOL-Key msg 2/4 reply to another
1282 * pending msg 1/4 to update the SNonce to work around
1283 * unexpected supplicant behavior.
1285 os_memcpy(sm
->prev_key_replay
, sm
->key_replay
,
1286 sizeof(sm
->key_replay
));
1288 os_memset(sm
->prev_key_replay
, 0,
1289 sizeof(sm
->prev_key_replay
));
1293 * Make sure old valid counters are not accepted anymore and
1294 * do not get copied again.
1296 wpa_replay_counter_mark_invalid(sm
->key_replay
, NULL
);
1299 os_free(sm
->last_rx_eapol_key
);
1300 sm
->last_rx_eapol_key
= os_memdup(data
, data_len
);
1301 if (sm
->last_rx_eapol_key
== NULL
)
1303 sm
->last_rx_eapol_key_len
= data_len
;
1305 sm
->rx_eapol_key_secure
= !!(key_info
& WPA_KEY_INFO_SECURE
);
1306 sm
->EAPOLKeyReceived
= TRUE
;
1307 sm
->EAPOLKeyPairwise
= !!(key_info
& WPA_KEY_INFO_KEY_TYPE
);
1308 sm
->EAPOLKeyRequest
= !!(key_info
& WPA_KEY_INFO_REQUEST
);
1309 os_memcpy(sm
->SNonce
, key
->key_nonce
, WPA_NONCE_LEN
);
1314 static int wpa_gmk_to_gtk(const u8
*gmk
, const char *label
, const u8
*addr
,
1315 const u8
*gnonce
, u8
*gtk
, size_t gtk_len
)
1317 u8 data
[ETH_ALEN
+ WPA_NONCE_LEN
+ 8 + WPA_GTK_MAX_LEN
];
1321 /* GTK = PRF-X(GMK, "Group key expansion",
1322 * AA || GNonce || Time || random data)
1323 * The example described in the IEEE 802.11 standard uses only AA and
1324 * GNonce as inputs here. Add some more entropy since this derivation
1325 * is done only at the Authenticator and as such, does not need to be
1328 os_memset(data
, 0, sizeof(data
));
1329 os_memcpy(data
, addr
, ETH_ALEN
);
1330 os_memcpy(data
+ ETH_ALEN
, gnonce
, WPA_NONCE_LEN
);
1331 pos
= data
+ ETH_ALEN
+ WPA_NONCE_LEN
;
1332 wpa_get_ntp_timestamp(pos
);
1334 if (random_get_bytes(pos
, gtk_len
) < 0)
1337 #ifdef CONFIG_SHA384
1338 if (sha384_prf(gmk
, WPA_GMK_LEN
, label
, data
, sizeof(data
),
1341 #else /* CONFIG_SHA384 */
1342 #ifdef CONFIG_SHA256
1343 if (sha256_prf(gmk
, WPA_GMK_LEN
, label
, data
, sizeof(data
),
1346 #else /* CONFIG_SHA256 */
1347 if (sha1_prf(gmk
, WPA_GMK_LEN
, label
, data
, sizeof(data
),
1350 #endif /* CONFIG_SHA256 */
1351 #endif /* CONFIG_SHA384 */
1357 static void wpa_send_eapol_timeout(void *eloop_ctx
, void *timeout_ctx
)
1359 struct wpa_authenticator
*wpa_auth
= eloop_ctx
;
1360 struct wpa_state_machine
*sm
= timeout_ctx
;
1362 sm
->pending_1_of_4_timeout
= 0;
1363 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
, "EAPOL-Key timeout");
1364 sm
->TimeoutEvt
= TRUE
;
1369 void __wpa_send_eapol(struct wpa_authenticator
*wpa_auth
,
1370 struct wpa_state_machine
*sm
, int key_info
,
1371 const u8
*key_rsc
, const u8
*nonce
,
1372 const u8
*kde
, size_t kde_len
,
1373 int keyidx
, int encr
, int force_version
)
1375 struct ieee802_1x_hdr
*hdr
;
1376 struct wpa_eapol_key
*key
;
1377 size_t len
, mic_len
, keyhdrlen
;
1379 int key_data_len
, pad_len
= 0;
1381 int version
, pairwise
;
1383 u8
*key_mic
, *key_data
;
1385 mic_len
= wpa_mic_len(sm
->wpa_key_mgmt
, sm
->pmk_len
);
1386 keyhdrlen
= sizeof(*key
) + mic_len
+ 2;
1388 len
= sizeof(struct ieee802_1x_hdr
) + keyhdrlen
;
1391 version
= force_version
;
1392 else if (wpa_use_akm_defined(sm
->wpa_key_mgmt
))
1393 version
= WPA_KEY_INFO_TYPE_AKM_DEFINED
;
1394 else if (wpa_use_cmac(sm
->wpa_key_mgmt
))
1395 version
= WPA_KEY_INFO_TYPE_AES_128_CMAC
;
1396 else if (sm
->pairwise
!= WPA_CIPHER_TKIP
)
1397 version
= WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
;
1399 version
= WPA_KEY_INFO_TYPE_HMAC_MD5_RC4
;
1401 pairwise
= !!(key_info
& WPA_KEY_INFO_KEY_TYPE
);
1403 wpa_printf(MSG_DEBUG
, "WPA: Send EAPOL(version=%d secure=%d mic=%d "
1404 "ack=%d install=%d pairwise=%d kde_len=%lu keyidx=%d "
1407 (key_info
& WPA_KEY_INFO_SECURE
) ? 1 : 0,
1408 (key_info
& WPA_KEY_INFO_MIC
) ? 1 : 0,
1409 (key_info
& WPA_KEY_INFO_ACK
) ? 1 : 0,
1410 (key_info
& WPA_KEY_INFO_INSTALL
) ? 1 : 0,
1411 pairwise
, (unsigned long) kde_len
, keyidx
, encr
);
1413 key_data_len
= kde_len
;
1415 if ((version
== WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
||
1416 wpa_use_aes_key_wrap(sm
->wpa_key_mgmt
) ||
1417 version
== WPA_KEY_INFO_TYPE_AES_128_CMAC
) && encr
) {
1418 pad_len
= key_data_len
% 8;
1420 pad_len
= 8 - pad_len
;
1421 key_data_len
+= pad_len
+ 8;
1424 len
+= key_data_len
;
1425 if (!mic_len
&& encr
)
1426 len
+= AES_BLOCK_SIZE
;
1428 hdr
= os_zalloc(len
);
1431 hdr
->version
= wpa_auth
->conf
.eapol_version
;
1432 hdr
->type
= IEEE802_1X_TYPE_EAPOL_KEY
;
1433 hdr
->length
= host_to_be16(len
- sizeof(*hdr
));
1434 key
= (struct wpa_eapol_key
*) (hdr
+ 1);
1435 key_mic
= (u8
*) (key
+ 1);
1436 key_data
= ((u8
*) (hdr
+ 1)) + keyhdrlen
;
1438 key
->type
= sm
->wpa
== WPA_VERSION_WPA2
?
1439 EAPOL_KEY_TYPE_RSN
: EAPOL_KEY_TYPE_WPA
;
1440 key_info
|= version
;
1441 if (encr
&& sm
->wpa
== WPA_VERSION_WPA2
)
1442 key_info
|= WPA_KEY_INFO_ENCR_KEY_DATA
;
1443 if (sm
->wpa
!= WPA_VERSION_WPA2
)
1444 key_info
|= keyidx
<< WPA_KEY_INFO_KEY_INDEX_SHIFT
;
1445 WPA_PUT_BE16(key
->key_info
, key_info
);
1447 alg
= pairwise
? sm
->pairwise
: wpa_auth
->conf
.wpa_group
;
1448 if (sm
->wpa
== WPA_VERSION_WPA2
&& !pairwise
)
1449 WPA_PUT_BE16(key
->key_length
, 0);
1451 WPA_PUT_BE16(key
->key_length
, wpa_cipher_key_len(alg
));
1453 for (i
= RSNA_MAX_EAPOL_RETRIES
- 1; i
> 0; i
--) {
1454 sm
->key_replay
[i
].valid
= sm
->key_replay
[i
- 1].valid
;
1455 os_memcpy(sm
->key_replay
[i
].counter
,
1456 sm
->key_replay
[i
- 1].counter
,
1457 WPA_REPLAY_COUNTER_LEN
);
1459 inc_byte_array(sm
->key_replay
[0].counter
, WPA_REPLAY_COUNTER_LEN
);
1460 os_memcpy(key
->replay_counter
, sm
->key_replay
[0].counter
,
1461 WPA_REPLAY_COUNTER_LEN
);
1462 wpa_hexdump(MSG_DEBUG
, "WPA: Replay Counter",
1463 key
->replay_counter
, WPA_REPLAY_COUNTER_LEN
);
1464 sm
->key_replay
[0].valid
= TRUE
;
1467 os_memcpy(key
->key_nonce
, nonce
, WPA_NONCE_LEN
);
1470 os_memcpy(key
->key_rsc
, key_rsc
, WPA_KEY_RSC_LEN
);
1473 os_memcpy(key_data
, kde
, kde_len
);
1474 WPA_PUT_BE16(key_mic
+ mic_len
, kde_len
);
1476 } else if (!mic_len
&& kde
) {
1480 WPA_PUT_BE16(key_mic
, AES_BLOCK_SIZE
+ kde_len
);
1481 wpa_hexdump_key(MSG_DEBUG
, "Plaintext EAPOL-Key Key Data",
1484 wpa_hexdump_key(MSG_DEBUG
, "WPA: KEK",
1485 sm
->PTK
.kek
, sm
->PTK
.kek_len
);
1486 /* AES-SIV AAD from EAPOL protocol version field (inclusive) to
1487 * to Key Data (exclusive). */
1488 aad
[0] = (u8
*) hdr
;
1489 aad_len
[0] = key_mic
+ 2 - (u8
*) hdr
;
1490 if (aes_siv_encrypt(sm
->PTK
.kek
, sm
->PTK
.kek_len
, kde
, kde_len
,
1491 1, aad
, aad_len
, key_mic
+ 2) < 0) {
1492 wpa_printf(MSG_DEBUG
, "WPA: AES-SIV encryption failed");
1496 wpa_hexdump(MSG_DEBUG
, "WPA: Encrypted Key Data from SIV",
1497 key_mic
+ 2, AES_BLOCK_SIZE
+ kde_len
);
1498 #endif /* CONFIG_FILS */
1499 } else if (encr
&& kde
) {
1500 buf
= os_zalloc(key_data_len
);
1506 os_memcpy(pos
, kde
, kde_len
);
1512 wpa_hexdump_key(MSG_DEBUG
, "Plaintext EAPOL-Key Key Data",
1514 if (version
== WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
||
1515 wpa_use_aes_key_wrap(sm
->wpa_key_mgmt
) ||
1516 version
== WPA_KEY_INFO_TYPE_AES_128_CMAC
) {
1517 wpa_printf(MSG_DEBUG
,
1518 "WPA: Encrypt Key Data using AES-WRAP (KEK length %u)",
1519 (unsigned int) sm
->PTK
.kek_len
);
1520 if (aes_wrap(sm
->PTK
.kek
, sm
->PTK
.kek_len
,
1521 (key_data_len
- 8) / 8, buf
, key_data
)) {
1526 WPA_PUT_BE16(key_mic
+ mic_len
, key_data_len
);
1527 #ifndef CONFIG_NO_RC4
1528 } else if (sm
->PTK
.kek_len
== 16) {
1531 wpa_printf(MSG_DEBUG
,
1532 "WPA: Encrypt Key Data using RC4");
1533 os_memcpy(key
->key_iv
,
1534 sm
->group
->Counter
+ WPA_NONCE_LEN
- 16, 16);
1535 inc_byte_array(sm
->group
->Counter
, WPA_NONCE_LEN
);
1536 os_memcpy(ek
, key
->key_iv
, 16);
1537 os_memcpy(ek
+ 16, sm
->PTK
.kek
, sm
->PTK
.kek_len
);
1538 os_memcpy(key_data
, buf
, key_data_len
);
1539 rc4_skip(ek
, 32, 256, key_data
, key_data_len
);
1540 WPA_PUT_BE16(key_mic
+ mic_len
, key_data_len
);
1541 #endif /* CONFIG_NO_RC4 */
1550 if (key_info
& WPA_KEY_INFO_MIC
) {
1551 if (!sm
->PTK_valid
|| !mic_len
) {
1552 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
1553 "PTK not valid when sending EAPOL-Key "
1559 if (wpa_eapol_key_mic(sm
->PTK
.kck
, sm
->PTK
.kck_len
,
1560 sm
->wpa_key_mgmt
, version
,
1561 (u8
*) hdr
, len
, key_mic
) < 0) {
1565 #ifdef CONFIG_TESTING_OPTIONS
1567 wpa_auth
->conf
.corrupt_gtk_rekey_mic_probability
> 0.0 &&
1569 wpa_auth
->conf
.corrupt_gtk_rekey_mic_probability
) {
1570 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
1571 "Corrupting group EAPOL-Key Key MIC");
1574 #endif /* CONFIG_TESTING_OPTIONS */
1577 wpa_auth_set_eapol(sm
->wpa_auth
, sm
->addr
, WPA_EAPOL_inc_EapolFramesTx
,
1579 wpa_auth_send_eapol(wpa_auth
, sm
->addr
, (u8
*) hdr
, len
,
1585 static void wpa_send_eapol(struct wpa_authenticator
*wpa_auth
,
1586 struct wpa_state_machine
*sm
, int key_info
,
1587 const u8
*key_rsc
, const u8
*nonce
,
1588 const u8
*kde
, size_t kde_len
,
1589 int keyidx
, int encr
)
1592 int pairwise
= key_info
& WPA_KEY_INFO_KEY_TYPE
;
1598 __wpa_send_eapol(wpa_auth
, sm
, key_info
, key_rsc
, nonce
, kde
, kde_len
,
1601 ctr
= pairwise
? sm
->TimeoutCtr
: sm
->GTimeoutCtr
;
1602 if (ctr
== 1 && wpa_auth
->conf
.tx_status
)
1603 timeout_ms
= pairwise
? eapol_key_timeout_first
:
1604 eapol_key_timeout_first_group
;
1606 timeout_ms
= eapol_key_timeout_subseq
;
1607 if (wpa_auth
->conf
.wpa_disable_eapol_key_retries
&&
1608 (!pairwise
|| (key_info
& WPA_KEY_INFO_MIC
)))
1609 timeout_ms
= eapol_key_timeout_no_retrans
;
1610 if (pairwise
&& ctr
== 1 && !(key_info
& WPA_KEY_INFO_MIC
))
1611 sm
->pending_1_of_4_timeout
= 1;
1612 wpa_printf(MSG_DEBUG
, "WPA: Use EAPOL-Key timeout of %u ms (retry "
1613 "counter %u)", timeout_ms
, ctr
);
1614 eloop_register_timeout(timeout_ms
/ 1000, (timeout_ms
% 1000) * 1000,
1615 wpa_send_eapol_timeout
, wpa_auth
, sm
);
1619 static int wpa_verify_key_mic(int akmp
, size_t pmk_len
, struct wpa_ptk
*PTK
,
1620 u8
*data
, size_t data_len
)
1622 struct ieee802_1x_hdr
*hdr
;
1623 struct wpa_eapol_key
*key
;
1626 u8 mic
[WPA_EAPOL_KEY_MIC_MAX_LEN
], *mic_pos
;
1627 size_t mic_len
= wpa_mic_len(akmp
, pmk_len
);
1629 if (data_len
< sizeof(*hdr
) + sizeof(*key
))
1632 hdr
= (struct ieee802_1x_hdr
*) data
;
1633 key
= (struct wpa_eapol_key
*) (hdr
+ 1);
1634 mic_pos
= (u8
*) (key
+ 1);
1635 key_info
= WPA_GET_BE16(key
->key_info
);
1636 os_memcpy(mic
, mic_pos
, mic_len
);
1637 os_memset(mic_pos
, 0, mic_len
);
1638 if (wpa_eapol_key_mic(PTK
->kck
, PTK
->kck_len
, akmp
,
1639 key_info
& WPA_KEY_INFO_TYPE_MASK
,
1640 data
, data_len
, mic_pos
) ||
1641 os_memcmp_const(mic
, mic_pos
, mic_len
) != 0)
1643 os_memcpy(mic_pos
, mic
, mic_len
);
1648 void wpa_remove_ptk(struct wpa_state_machine
*sm
)
1650 sm
->PTK_valid
= FALSE
;
1651 os_memset(&sm
->PTK
, 0, sizeof(sm
->PTK
));
1652 if (wpa_auth_set_key(sm
->wpa_auth
, 0, WPA_ALG_NONE
, sm
->addr
, 0, NULL
,
1654 wpa_printf(MSG_DEBUG
,
1655 "RSN: PTK removal from the driver failed");
1656 sm
->pairwise_set
= FALSE
;
1657 eloop_cancel_timeout(wpa_rekey_ptk
, sm
->wpa_auth
, sm
);
1661 int wpa_auth_sm_event(struct wpa_state_machine
*sm
, enum wpa_event event
)
1668 wpa_auth_vlogger(sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
1669 "event %d notification", event
);
1674 /* PTKs are derived through AMPE */
1675 if (wpa_auth_start_ampe(sm
->wpa_auth
, sm
->addr
)) {
1680 #endif /* CONFIG_MESH */
1685 sm
->DeauthenticationRequest
= TRUE
;
1688 case WPA_REAUTH_EAPOL
:
1691 * When using WPS, we may end up here if the STA
1692 * manages to re-associate without the previous STA
1693 * entry getting removed. Consequently, we need to make
1694 * sure that the WPA state machines gets initialized
1695 * properly at this point.
1697 wpa_printf(MSG_DEBUG
, "WPA state machine had not been "
1698 "started - initialize now");
1701 if (wpa_sm_step(sm
) == 1)
1702 return 1; /* should not really happen */
1704 sm
->AuthenticationRequest
= TRUE
;
1707 if (sm
->GUpdateStationKeys
) {
1709 * Reauthentication cancels the pending group key
1710 * update for this STA.
1712 sm
->group
->GKeyDoneStations
--;
1713 sm
->GUpdateStationKeys
= FALSE
;
1714 sm
->PtkGroupInit
= TRUE
;
1716 sm
->ReAuthenticationRequest
= TRUE
;
1719 #ifdef CONFIG_IEEE80211R_AP
1720 wpa_printf(MSG_DEBUG
, "FT: Retry PTK configuration "
1721 "after association");
1722 wpa_ft_install_ptk(sm
);
1724 /* Using FT protocol, not WPA auth state machine */
1725 sm
->ft_completed
= 1;
1727 #else /* CONFIG_IEEE80211R_AP */
1729 #endif /* CONFIG_IEEE80211R_AP */
1730 case WPA_ASSOC_FILS
:
1732 wpa_printf(MSG_DEBUG
,
1733 "FILS: TK configuration after association");
1735 sm
->fils_completed
= 1;
1737 #else /* CONFIG_FILS */
1739 #endif /* CONFIG_FILS */
1740 case WPA_DRV_STA_REMOVED
:
1741 sm
->tk_already_set
= FALSE
;
1745 #ifdef CONFIG_IEEE80211R_AP
1746 sm
->ft_completed
= 0;
1747 #endif /* CONFIG_IEEE80211R_AP */
1749 #ifdef CONFIG_IEEE80211W
1750 if (sm
->mgmt_frame_prot
&& event
== WPA_AUTH
)
1752 #endif /* CONFIG_IEEE80211W */
1754 if (wpa_key_mgmt_fils(sm
->wpa_key_mgmt
) &&
1755 (event
== WPA_AUTH
|| event
== WPA_ASSOC
))
1757 #endif /* CONFIG_FILS */
1760 sm
->PTK_valid
= FALSE
;
1761 os_memset(&sm
->PTK
, 0, sizeof(sm
->PTK
));
1763 if (event
!= WPA_REAUTH_EAPOL
)
1767 if (sm
->in_step_loop
) {
1769 * wpa_sm_step() is already running - avoid recursive call to
1770 * it by making the existing loop process the new update.
1775 return wpa_sm_step(sm
);
1779 SM_STATE(WPA_PTK
, INITIALIZE
)
1781 SM_ENTRY_MA(WPA_PTK
, INITIALIZE
, wpa_ptk
);
1783 /* Init flag is not cleared here, so avoid busy
1784 * loop by claiming nothing changed. */
1785 sm
->changed
= FALSE
;
1789 if (sm
->GUpdateStationKeys
)
1790 sm
->group
->GKeyDoneStations
--;
1791 sm
->GUpdateStationKeys
= FALSE
;
1792 if (sm
->wpa
== WPA_VERSION_WPA
)
1793 sm
->PInitAKeys
= FALSE
;
1794 if (1 /* Unicast cipher supported AND (ESS OR ((IBSS or WDS) and
1795 * Local AA > Remote AA)) */) {
1798 wpa_auth_set_eapol(sm
->wpa_auth
, sm
->addr
, WPA_EAPOL_portEnabled
, 0);
1800 wpa_auth_set_eapol(sm
->wpa_auth
, sm
->addr
, WPA_EAPOL_portValid
, 0);
1802 if (wpa_key_mgmt_wpa_psk(sm
->wpa_key_mgmt
) ||
1803 sm
->wpa_key_mgmt
== WPA_KEY_MGMT_DPP
||
1804 sm
->wpa_key_mgmt
== WPA_KEY_MGMT_OWE
) {
1805 wpa_auth_set_eapol(sm
->wpa_auth
, sm
->addr
,
1806 WPA_EAPOL_authorized
, 0);
1811 SM_STATE(WPA_PTK
, DISCONNECT
)
1813 u16 reason
= sm
->disconnect_reason
;
1815 SM_ENTRY_MA(WPA_PTK
, DISCONNECT
, wpa_ptk
);
1816 sm
->Disconnect
= FALSE
;
1817 sm
->disconnect_reason
= 0;
1819 reason
= WLAN_REASON_PREV_AUTH_NOT_VALID
;
1820 wpa_sta_disconnect(sm
->wpa_auth
, sm
->addr
, reason
);
1824 SM_STATE(WPA_PTK
, DISCONNECTED
)
1826 SM_ENTRY_MA(WPA_PTK
, DISCONNECTED
, wpa_ptk
);
1827 sm
->DeauthenticationRequest
= FALSE
;
1831 SM_STATE(WPA_PTK
, AUTHENTICATION
)
1833 SM_ENTRY_MA(WPA_PTK
, AUTHENTICATION
, wpa_ptk
);
1834 os_memset(&sm
->PTK
, 0, sizeof(sm
->PTK
));
1835 sm
->PTK_valid
= FALSE
;
1836 wpa_auth_set_eapol(sm
->wpa_auth
, sm
->addr
, WPA_EAPOL_portControl_Auto
,
1838 wpa_auth_set_eapol(sm
->wpa_auth
, sm
->addr
, WPA_EAPOL_portEnabled
, 1);
1839 sm
->AuthenticationRequest
= FALSE
;
1843 static void wpa_group_ensure_init(struct wpa_authenticator
*wpa_auth
,
1844 struct wpa_group
*group
)
1846 if (group
->first_sta_seen
)
1849 * System has run bit further than at the time hostapd was started
1850 * potentially very early during boot up. This provides better chances
1851 * of collecting more randomness on embedded systems. Re-initialize the
1852 * GMK and Counter here to improve their strength if there was not
1853 * enough entropy available immediately after system startup.
1855 wpa_printf(MSG_DEBUG
, "WPA: Re-initialize GMK/Counter on first "
1857 if (random_pool_ready() != 1) {
1858 wpa_printf(MSG_INFO
, "WPA: Not enough entropy in random pool "
1859 "to proceed - reject first 4-way handshake");
1860 group
->reject_4way_hs_for_entropy
= TRUE
;
1862 group
->first_sta_seen
= TRUE
;
1863 group
->reject_4way_hs_for_entropy
= FALSE
;
1866 if (wpa_group_init_gmk_and_counter(wpa_auth
, group
) < 0 ||
1867 wpa_gtk_update(wpa_auth
, group
) < 0 ||
1868 wpa_group_config_group_keys(wpa_auth
, group
) < 0) {
1869 wpa_printf(MSG_INFO
, "WPA: GMK/GTK setup failed");
1870 group
->first_sta_seen
= FALSE
;
1871 group
->reject_4way_hs_for_entropy
= TRUE
;
1876 SM_STATE(WPA_PTK
, AUTHENTICATION2
)
1878 SM_ENTRY_MA(WPA_PTK
, AUTHENTICATION2
, wpa_ptk
);
1880 wpa_group_ensure_init(sm
->wpa_auth
, sm
->group
);
1881 sm
->ReAuthenticationRequest
= FALSE
;
1884 * Definition of ANonce selection in IEEE Std 802.11i-2004 is somewhat
1885 * ambiguous. The Authenticator state machine uses a counter that is
1886 * incremented by one for each 4-way handshake. However, the security
1887 * analysis of 4-way handshake points out that unpredictable nonces
1888 * help in preventing precomputation attacks. Instead of the state
1889 * machine definition, use an unpredictable nonce value here to provide
1890 * stronger protection against potential precomputation attacks.
1892 if (random_get_bytes(sm
->ANonce
, WPA_NONCE_LEN
)) {
1893 wpa_printf(MSG_ERROR
, "WPA: Failed to get random data for "
1895 sm
->Disconnect
= TRUE
;
1898 wpa_hexdump(MSG_DEBUG
, "WPA: Assign ANonce", sm
->ANonce
,
1900 /* IEEE 802.11i does not clear TimeoutCtr here, but this is more
1901 * logical place than INITIALIZE since AUTHENTICATION2 can be
1902 * re-entered on ReAuthenticationRequest without going through
1908 static int wpa_auth_sm_ptk_update(struct wpa_state_machine
*sm
)
1910 if (random_get_bytes(sm
->ANonce
, WPA_NONCE_LEN
)) {
1911 wpa_printf(MSG_ERROR
,
1912 "WPA: Failed to get random data for ANonce");
1913 sm
->Disconnect
= TRUE
;
1916 wpa_hexdump(MSG_DEBUG
, "WPA: Assign new ANonce", sm
->ANonce
,
1923 SM_STATE(WPA_PTK
, INITPMK
)
1925 u8 msk
[2 * PMK_LEN
];
1926 size_t len
= 2 * PMK_LEN
;
1928 SM_ENTRY_MA(WPA_PTK
, INITPMK
, wpa_ptk
);
1929 #ifdef CONFIG_IEEE80211R_AP
1931 #endif /* CONFIG_IEEE80211R_AP */
1933 wpa_printf(MSG_DEBUG
, "WPA: PMK from PMKSA cache");
1934 os_memcpy(sm
->PMK
, sm
->pmksa
->pmk
, sm
->pmksa
->pmk_len
);
1935 sm
->pmk_len
= sm
->pmksa
->pmk_len
;
1937 } else if (sm
->wpa_key_mgmt
== WPA_KEY_MGMT_DPP
) {
1938 wpa_printf(MSG_DEBUG
,
1939 "DPP: No PMKSA cache entry for STA - reject connection");
1940 sm
->Disconnect
= TRUE
;
1941 sm
->disconnect_reason
= WLAN_REASON_INVALID_PMKID
;
1943 #endif /* CONFIG_DPP */
1944 } else if (wpa_auth_get_msk(sm
->wpa_auth
, sm
->addr
, msk
, &len
) == 0) {
1945 unsigned int pmk_len
;
1947 if (wpa_key_mgmt_sha384(sm
->wpa_key_mgmt
))
1948 pmk_len
= PMK_LEN_SUITE_B_192
;
1951 wpa_printf(MSG_DEBUG
, "WPA: PMK from EAPOL state machine "
1952 "(MSK len=%lu PMK len=%u)", (unsigned long) len
,
1954 if (len
< pmk_len
) {
1955 wpa_printf(MSG_DEBUG
,
1956 "WPA: MSK not long enough (%u) to create PMK (%u)",
1957 (unsigned int) len
, (unsigned int) pmk_len
);
1958 sm
->Disconnect
= TRUE
;
1961 os_memcpy(sm
->PMK
, msk
, pmk_len
);
1962 sm
->pmk_len
= pmk_len
;
1963 #ifdef CONFIG_IEEE80211R_AP
1964 if (len
>= 2 * PMK_LEN
) {
1965 if (wpa_key_mgmt_sha384(sm
->wpa_key_mgmt
)) {
1966 os_memcpy(sm
->xxkey
, msk
, SHA384_MAC_LEN
);
1967 sm
->xxkey_len
= SHA384_MAC_LEN
;
1969 os_memcpy(sm
->xxkey
, msk
+ PMK_LEN
, PMK_LEN
);
1970 sm
->xxkey_len
= PMK_LEN
;
1973 #endif /* CONFIG_IEEE80211R_AP */
1975 wpa_printf(MSG_DEBUG
, "WPA: Could not get PMK, get_msk: %p",
1976 sm
->wpa_auth
->cb
->get_msk
);
1977 sm
->Disconnect
= TRUE
;
1980 os_memset(msk
, 0, sizeof(msk
));
1982 sm
->req_replay_counter_used
= 0;
1983 /* IEEE 802.11i does not set keyRun to FALSE, but not doing this
1984 * will break reauthentication since EAPOL state machines may not be
1985 * get into AUTHENTICATING state that clears keyRun before WPA state
1986 * machine enters AUTHENTICATION2 state and goes immediately to INITPMK
1987 * state and takes PMK from the previously used AAA Key. This will
1988 * eventually fail in 4-Way Handshake because Supplicant uses PMK
1989 * derived from the new AAA Key. Setting keyRun = FALSE here seems to
1990 * be good workaround for this issue. */
1991 wpa_auth_set_eapol(sm
->wpa_auth
, sm
->addr
, WPA_EAPOL_keyRun
, 0);
1995 SM_STATE(WPA_PTK
, INITPSK
)
2000 SM_ENTRY_MA(WPA_PTK
, INITPSK
, wpa_ptk
);
2001 psk
= wpa_auth_get_psk(sm
->wpa_auth
, sm
->addr
, sm
->p2p_dev_addr
, NULL
,
2004 os_memcpy(sm
->PMK
, psk
, psk_len
);
2005 sm
->pmk_len
= psk_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 */
2012 if (wpa_auth_uses_sae(sm
) && sm
->pmksa
) {
2013 wpa_printf(MSG_DEBUG
, "SAE: PMK from PMKSA cache");
2014 os_memcpy(sm
->PMK
, sm
->pmksa
->pmk
, sm
->pmksa
->pmk_len
);
2015 sm
->pmk_len
= sm
->pmksa
->pmk_len
;
2017 #endif /* CONFIG_SAE */
2018 sm
->req_replay_counter_used
= 0;
2022 SM_STATE(WPA_PTK
, PTKSTART
)
2024 u8 buf
[2 + RSN_SELECTOR_LEN
+ PMKID_LEN
], *pmkid
= NULL
;
2025 size_t pmkid_len
= 0;
2027 SM_ENTRY_MA(WPA_PTK
, PTKSTART
, wpa_ptk
);
2028 sm
->PTKRequest
= FALSE
;
2029 sm
->TimeoutEvt
= FALSE
;
2030 sm
->alt_snonce_valid
= FALSE
;
2033 if (sm
->TimeoutCtr
> sm
->wpa_auth
->conf
.wpa_pairwise_update_count
) {
2034 /* No point in sending the EAPOL-Key - we will disconnect
2035 * immediately following this. */
2039 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
2040 "sending 1/4 msg of 4-Way Handshake");
2042 * For infrastructure BSS cases, it is better for the AP not to include
2043 * the PMKID KDE in EAPOL-Key msg 1/4 since it could be used to initiate
2044 * offline search for the passphrase/PSK without having to be able to
2045 * capture a 4-way handshake from a STA that has access to the network.
2047 * For IBSS cases, addition of PMKID KDE could be considered even with
2048 * WPA2-PSK cases that use multiple PSKs, but only if there is a single
2049 * possible PSK for this STA. However, this should not be done unless
2050 * there is support for using that information on the supplicant side.
2051 * The concern about exposing PMKID unnecessarily in infrastructure BSS
2052 * cases would also apply here, but at least in the IBSS case, this
2053 * would cover a potential real use case.
2055 if (sm
->wpa
== WPA_VERSION_WPA2
&&
2056 (wpa_key_mgmt_wpa_ieee8021x(sm
->wpa_key_mgmt
) ||
2057 (sm
->wpa_key_mgmt
== WPA_KEY_MGMT_OWE
&& sm
->pmksa
) ||
2058 wpa_key_mgmt_sae(sm
->wpa_key_mgmt
)) &&
2059 sm
->wpa_key_mgmt
!= WPA_KEY_MGMT_OSEN
) {
2061 pmkid_len
= 2 + RSN_SELECTOR_LEN
+ PMKID_LEN
;
2062 pmkid
[0] = WLAN_EID_VENDOR_SPECIFIC
;
2063 pmkid
[1] = RSN_SELECTOR_LEN
+ PMKID_LEN
;
2064 RSN_SELECTOR_PUT(&pmkid
[2], RSN_KEY_DATA_PMKID
);
2066 wpa_hexdump(MSG_DEBUG
,
2067 "RSN: Message 1/4 PMKID from PMKSA entry",
2068 sm
->pmksa
->pmkid
, PMKID_LEN
);
2069 os_memcpy(&pmkid
[2 + RSN_SELECTOR_LEN
],
2070 sm
->pmksa
->pmkid
, PMKID_LEN
);
2071 } else if (wpa_key_mgmt_suite_b(sm
->wpa_key_mgmt
)) {
2072 /* No KCK available to derive PMKID */
2073 wpa_printf(MSG_DEBUG
,
2074 "RSN: No KCK available to derive PMKID for message 1/4");
2077 } else if (wpa_key_mgmt_sae(sm
->wpa_key_mgmt
)) {
2078 if (sm
->pmkid_set
) {
2079 wpa_hexdump(MSG_DEBUG
,
2080 "RSN: Message 1/4 PMKID from SAE",
2081 sm
->pmkid
, PMKID_LEN
);
2082 os_memcpy(&pmkid
[2 + RSN_SELECTOR_LEN
],
2083 sm
->pmkid
, PMKID_LEN
);
2085 /* No PMKID available */
2086 wpa_printf(MSG_DEBUG
,
2087 "RSN: No SAE PMKID available for message 1/4");
2090 #endif /* CONFIG_SAE */
2093 * Calculate PMKID since no PMKSA cache entry was
2094 * available with pre-calculated PMKID.
2096 rsn_pmkid(sm
->PMK
, sm
->pmk_len
, sm
->wpa_auth
->addr
,
2097 sm
->addr
, &pmkid
[2 + RSN_SELECTOR_LEN
],
2099 wpa_hexdump(MSG_DEBUG
,
2100 "RSN: Message 1/4 PMKID derived from PMK",
2101 &pmkid
[2 + RSN_SELECTOR_LEN
], PMKID_LEN
);
2104 wpa_send_eapol(sm
->wpa_auth
, sm
,
2105 WPA_KEY_INFO_ACK
| WPA_KEY_INFO_KEY_TYPE
, NULL
,
2106 sm
->ANonce
, pmkid
, pmkid_len
, 0, 0);
2110 static int wpa_derive_ptk(struct wpa_state_machine
*sm
, const u8
*snonce
,
2111 const u8
*pmk
, unsigned int pmk_len
,
2112 struct wpa_ptk
*ptk
)
2114 #ifdef CONFIG_IEEE80211R_AP
2115 if (wpa_key_mgmt_ft(sm
->wpa_key_mgmt
))
2116 return wpa_auth_derive_ptk_ft(sm
, pmk
, ptk
);
2117 #endif /* CONFIG_IEEE80211R_AP */
2119 return wpa_pmk_to_ptk(pmk
, pmk_len
, "Pairwise key expansion",
2120 sm
->wpa_auth
->addr
, sm
->addr
, sm
->ANonce
, snonce
,
2121 ptk
, sm
->wpa_key_mgmt
, sm
->pairwise
);
2127 int fils_auth_pmk_to_ptk(struct wpa_state_machine
*sm
, const u8
*pmk
,
2128 size_t pmk_len
, const u8
*snonce
, const u8
*anonce
,
2129 const u8
*dhss
, size_t dhss_len
,
2130 struct wpabuf
*g_sta
, struct wpabuf
*g_ap
)
2132 u8 ick
[FILS_ICK_MAX_LEN
];
2135 u8 fils_ft
[FILS_FT_MAX_LEN
];
2136 size_t fils_ft_len
= 0;
2138 res
= fils_pmk_to_ptk(pmk
, pmk_len
, sm
->addr
, sm
->wpa_auth
->addr
,
2139 snonce
, anonce
, dhss
, dhss_len
,
2140 &sm
->PTK
, ick
, &ick_len
,
2141 sm
->wpa_key_mgmt
, sm
->pairwise
,
2142 fils_ft
, &fils_ft_len
);
2145 sm
->PTK_valid
= TRUE
;
2146 sm
->tk_already_set
= FALSE
;
2148 #ifdef CONFIG_IEEE80211R_AP
2150 struct wpa_authenticator
*wpa_auth
= sm
->wpa_auth
;
2151 struct wpa_auth_config
*conf
= &wpa_auth
->conf
;
2152 u8 pmk_r0
[PMK_LEN_MAX
], pmk_r0_name
[WPA_PMK_NAME_LEN
];
2153 int use_sha384
= wpa_key_mgmt_sha384(sm
->wpa_key_mgmt
);
2154 size_t pmk_r0_len
= use_sha384
? SHA384_MAC_LEN
: PMK_LEN
;
2156 if (wpa_derive_pmk_r0(fils_ft
, fils_ft_len
,
2157 conf
->ssid
, conf
->ssid_len
,
2158 conf
->mobility_domain
,
2159 conf
->r0_key_holder
,
2160 conf
->r0_key_holder_len
,
2161 sm
->addr
, pmk_r0
, pmk_r0_name
,
2165 wpa_hexdump_key(MSG_DEBUG
, "FILS+FT: PMK-R0",
2166 pmk_r0
, pmk_r0_len
);
2167 wpa_hexdump(MSG_DEBUG
, "FILS+FT: PMKR0Name",
2168 pmk_r0_name
, WPA_PMK_NAME_LEN
);
2169 wpa_ft_store_pmk_fils(sm
, pmk_r0
, pmk_r0_name
);
2170 os_memset(fils_ft
, 0, sizeof(fils_ft
));
2172 #endif /* CONFIG_IEEE80211R_AP */
2174 res
= fils_key_auth_sk(ick
, ick_len
, snonce
, anonce
,
2175 sm
->addr
, sm
->wpa_auth
->addr
,
2176 g_sta
? wpabuf_head(g_sta
) : NULL
,
2177 g_sta
? wpabuf_len(g_sta
) : 0,
2178 g_ap
? wpabuf_head(g_ap
) : NULL
,
2179 g_ap
? wpabuf_len(g_ap
) : 0,
2180 sm
->wpa_key_mgmt
, sm
->fils_key_auth_sta
,
2181 sm
->fils_key_auth_ap
,
2182 &sm
->fils_key_auth_len
);
2183 os_memset(ick
, 0, sizeof(ick
));
2185 /* Store nonces for (Re)Association Request/Response frame processing */
2186 os_memcpy(sm
->SNonce
, snonce
, FILS_NONCE_LEN
);
2187 os_memcpy(sm
->ANonce
, anonce
, FILS_NONCE_LEN
);
2193 static int wpa_aead_decrypt(struct wpa_state_machine
*sm
, struct wpa_ptk
*ptk
,
2194 u8
*buf
, size_t buf_len
, u16
*_key_data_len
)
2196 struct ieee802_1x_hdr
*hdr
;
2197 struct wpa_eapol_key
*key
;
2204 hdr
= (struct ieee802_1x_hdr
*) buf
;
2205 key
= (struct wpa_eapol_key
*) (hdr
+ 1);
2206 pos
= (u8
*) (key
+ 1);
2207 key_data_len
= WPA_GET_BE16(pos
);
2208 if (key_data_len
< AES_BLOCK_SIZE
||
2209 key_data_len
> buf_len
- sizeof(*hdr
) - sizeof(*key
) - 2) {
2210 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_INFO
,
2211 "No room for AES-SIV data in the frame");
2214 pos
+= 2; /* Pointing at the Encrypted Key Data field */
2216 tmp
= os_malloc(key_data_len
);
2220 /* AES-SIV AAD from EAPOL protocol version field (inclusive) to
2221 * to Key Data (exclusive). */
2223 aad_len
[0] = pos
- buf
;
2224 if (aes_siv_decrypt(ptk
->kek
, ptk
->kek_len
, pos
, key_data_len
,
2225 1, aad
, aad_len
, tmp
) < 0) {
2226 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_INFO
,
2227 "Invalid AES-SIV data in the frame");
2228 bin_clear_free(tmp
, key_data_len
);
2232 /* AEAD decryption and validation completed successfully */
2233 key_data_len
-= AES_BLOCK_SIZE
;
2234 wpa_hexdump_key(MSG_DEBUG
, "WPA: Decrypted Key Data",
2237 /* Replace Key Data field with the decrypted version */
2238 os_memcpy(pos
, tmp
, key_data_len
);
2239 pos
-= 2; /* Key Data Length field */
2240 WPA_PUT_BE16(pos
, key_data_len
);
2241 bin_clear_free(tmp
, key_data_len
);
2243 *_key_data_len
= key_data_len
;
2248 const u8
* wpa_fils_validate_fils_session(struct wpa_state_machine
*sm
,
2249 const u8
*ies
, size_t ies_len
,
2250 const u8
*fils_session
)
2253 const u8
*session
= NULL
;
2255 if (!wpa_key_mgmt_fils(sm
->wpa_key_mgmt
)) {
2256 wpa_printf(MSG_DEBUG
,
2257 "FILS: Not a FILS AKM - reject association");
2261 /* Verify Session element */
2263 end
= ((const u8
*) ie
) + ies_len
;
2264 while (ie
+ 1 < end
) {
2265 if (ie
+ 2 + ie
[1] > end
)
2267 if (ie
[0] == WLAN_EID_EXTENSION
&&
2268 ie
[1] >= 1 + FILS_SESSION_LEN
&&
2269 ie
[2] == WLAN_EID_EXT_FILS_SESSION
) {
2277 wpa_printf(MSG_DEBUG
,
2278 "FILS: %s: Could not find FILS Session element in Assoc Req - reject",
2283 if (!fils_session
) {
2284 wpa_printf(MSG_DEBUG
,
2285 "FILS: %s: Could not find FILS Session element in STA entry - reject",
2290 if (os_memcmp(fils_session
, session
+ 3, FILS_SESSION_LEN
) != 0) {
2291 wpa_printf(MSG_DEBUG
, "FILS: Session mismatch");
2292 wpa_hexdump(MSG_DEBUG
, "FILS: Expected FILS Session",
2293 fils_session
, FILS_SESSION_LEN
);
2294 wpa_hexdump(MSG_DEBUG
, "FILS: Received FILS Session",
2295 session
+ 3, FILS_SESSION_LEN
);
2302 int wpa_fils_validate_key_confirm(struct wpa_state_machine
*sm
, const u8
*ies
,
2305 struct ieee802_11_elems elems
;
2307 if (ieee802_11_parse_elems(ies
, ies_len
, &elems
, 1) == ParseFailed
) {
2308 wpa_printf(MSG_DEBUG
,
2309 "FILS: Failed to parse decrypted elements");
2313 if (!elems
.fils_session
) {
2314 wpa_printf(MSG_DEBUG
, "FILS: No FILS Session element");
2318 if (!elems
.fils_key_confirm
) {
2319 wpa_printf(MSG_DEBUG
, "FILS: No FILS Key Confirm element");
2323 if (elems
.fils_key_confirm_len
!= sm
->fils_key_auth_len
) {
2324 wpa_printf(MSG_DEBUG
,
2325 "FILS: Unexpected Key-Auth length %d (expected %d)",
2326 elems
.fils_key_confirm_len
,
2327 (int) sm
->fils_key_auth_len
);
2331 if (os_memcmp(elems
.fils_key_confirm
, sm
->fils_key_auth_sta
,
2332 sm
->fils_key_auth_len
) != 0) {
2333 wpa_printf(MSG_DEBUG
, "FILS: Key-Auth mismatch");
2334 wpa_hexdump(MSG_DEBUG
, "FILS: Received Key-Auth",
2335 elems
.fils_key_confirm
, elems
.fils_key_confirm_len
);
2336 wpa_hexdump(MSG_DEBUG
, "FILS: Expected Key-Auth",
2337 sm
->fils_key_auth_sta
, sm
->fils_key_auth_len
);
2345 int fils_decrypt_assoc(struct wpa_state_machine
*sm
, const u8
*fils_session
,
2346 const struct ieee80211_mgmt
*mgmt
, size_t frame_len
,
2347 u8
*pos
, size_t left
)
2350 const u8
*end
, *ie_start
, *ie
, *session
, *crypt
;
2354 if (!sm
|| !sm
->PTK_valid
) {
2355 wpa_printf(MSG_DEBUG
,
2356 "FILS: No KEK to decrypt Assocication Request frame");
2360 if (!wpa_key_mgmt_fils(sm
->wpa_key_mgmt
)) {
2361 wpa_printf(MSG_DEBUG
,
2362 "FILS: Not a FILS AKM - reject association");
2366 end
= ((const u8
*) mgmt
) + frame_len
;
2367 fc
= le_to_host16(mgmt
->frame_control
);
2368 stype
= WLAN_FC_GET_STYPE(fc
);
2369 if (stype
== WLAN_FC_STYPE_REASSOC_REQ
)
2370 ie_start
= mgmt
->u
.reassoc_req
.variable
;
2372 ie_start
= mgmt
->u
.assoc_req
.variable
;
2376 * Find FILS Session element which is the last unencrypted element in
2379 session
= wpa_fils_validate_fils_session(sm
, ie
, end
- ie
,
2382 wpa_printf(MSG_DEBUG
, "FILS: Session validation failed");
2386 crypt
= session
+ 2 + session
[1];
2388 if (end
- crypt
< AES_BLOCK_SIZE
) {
2389 wpa_printf(MSG_DEBUG
,
2390 "FILS: Too short frame to include AES-SIV data");
2394 /* AES-SIV AAD vectors */
2396 /* The STA's MAC address */
2398 aad_len
[0] = ETH_ALEN
;
2399 /* The AP's BSSID */
2401 aad_len
[1] = ETH_ALEN
;
2402 /* The STA's nonce */
2403 aad
[2] = sm
->SNonce
;
2404 aad_len
[2] = FILS_NONCE_LEN
;
2405 /* The AP's nonce */
2406 aad
[3] = sm
->ANonce
;
2407 aad_len
[3] = FILS_NONCE_LEN
;
2409 * The (Re)Association Request frame from the Capability Information
2410 * field to the FILS Session element (both inclusive).
2412 aad
[4] = (const u8
*) &mgmt
->u
.assoc_req
.capab_info
;
2413 aad_len
[4] = crypt
- aad
[4];
2415 if (aes_siv_decrypt(sm
->PTK
.kek
, sm
->PTK
.kek_len
, crypt
, end
- crypt
,
2416 5, aad
, aad_len
, pos
+ (crypt
- ie_start
)) < 0) {
2417 wpa_printf(MSG_DEBUG
,
2418 "FILS: Invalid AES-SIV data in the frame");
2421 wpa_hexdump(MSG_DEBUG
, "FILS: Decrypted Association Request elements",
2422 pos
, left
- AES_BLOCK_SIZE
);
2424 if (wpa_fils_validate_key_confirm(sm
, pos
, left
- AES_BLOCK_SIZE
) < 0) {
2425 wpa_printf(MSG_DEBUG
, "FILS: Key Confirm validation failed");
2429 return left
- AES_BLOCK_SIZE
;
2433 int fils_encrypt_assoc(struct wpa_state_machine
*sm
, u8
*buf
,
2434 size_t current_len
, size_t max_len
,
2435 const struct wpabuf
*hlp
)
2437 u8
*end
= buf
+ max_len
;
2438 u8
*pos
= buf
+ current_len
;
2439 struct ieee80211_mgmt
*mgmt
;
2440 struct wpabuf
*plain
;
2444 if (!sm
|| !sm
->PTK_valid
)
2447 wpa_hexdump(MSG_DEBUG
,
2448 "FILS: Association Response frame before FILS processing",
2451 mgmt
= (struct ieee80211_mgmt
*) buf
;
2453 /* AES-SIV AAD vectors */
2455 /* The AP's BSSID */
2457 aad_len
[0] = ETH_ALEN
;
2458 /* The STA's MAC address */
2460 aad_len
[1] = ETH_ALEN
;
2461 /* The AP's nonce */
2462 aad
[2] = sm
->ANonce
;
2463 aad_len
[2] = FILS_NONCE_LEN
;
2464 /* The STA's nonce */
2465 aad
[3] = sm
->SNonce
;
2466 aad_len
[3] = FILS_NONCE_LEN
;
2468 * The (Re)Association Response frame from the Capability Information
2469 * field (the same offset in both Association and Reassociation
2470 * Response frames) to the FILS Session element (both inclusive).
2472 aad
[4] = (const u8
*) &mgmt
->u
.assoc_resp
.capab_info
;
2473 aad_len
[4] = pos
- aad
[4];
2475 /* The following elements will be encrypted with AES-SIV */
2476 plain
= fils_prepare_plainbuf(sm
, hlp
);
2478 wpa_printf(MSG_DEBUG
, "FILS: Plain buffer prep failed");
2482 if (pos
+ wpabuf_len(plain
) + AES_BLOCK_SIZE
> end
) {
2483 wpa_printf(MSG_DEBUG
,
2484 "FILS: Not enough room for FILS elements");
2489 wpa_hexdump_buf_key(MSG_DEBUG
, "FILS: Association Response plaintext",
2492 if (aes_siv_encrypt(sm
->PTK
.kek
, sm
->PTK
.kek_len
,
2493 wpabuf_head(plain
), wpabuf_len(plain
),
2494 5, aad
, aad_len
, pos
) < 0) {
2499 wpa_hexdump(MSG_DEBUG
,
2500 "FILS: Encrypted Association Response elements",
2501 pos
, AES_BLOCK_SIZE
+ wpabuf_len(plain
));
2502 current_len
+= wpabuf_len(plain
) + AES_BLOCK_SIZE
;
2505 sm
->fils_completed
= 1;
2511 static struct wpabuf
* fils_prepare_plainbuf(struct wpa_state_machine
*sm
,
2512 const struct wpabuf
*hlp
)
2514 struct wpabuf
*plain
;
2515 u8
*len
, *tmp
, *tmp2
;
2517 u8
*gtk
, dummy_gtk
[32];
2519 struct wpa_group
*gsm
;
2521 plain
= wpabuf_alloc(1000);
2525 /* TODO: FILS Public Key */
2527 /* FILS Key Confirmation */
2528 wpabuf_put_u8(plain
, WLAN_EID_EXTENSION
); /* Element ID */
2529 wpabuf_put_u8(plain
, 1 + sm
->fils_key_auth_len
); /* Length */
2530 /* Element ID Extension */
2531 wpabuf_put_u8(plain
, WLAN_EID_EXT_FILS_KEY_CONFIRM
);
2532 wpabuf_put_data(plain
, sm
->fils_key_auth_ap
, sm
->fils_key_auth_len
);
2534 /* FILS HLP Container */
2536 wpabuf_put_buf(plain
, hlp
);
2538 /* TODO: FILS IP Address Assignment */
2542 wpabuf_put_u8(plain
, WLAN_EID_EXTENSION
); /* Element ID */
2543 len
= wpabuf_put(plain
, 1);
2544 wpabuf_put_u8(plain
, WLAN_EID_EXT_KEY_DELIVERY
);
2545 wpa_auth_get_seqnum(sm
->wpa_auth
, NULL
, gsm
->GN
,
2546 wpabuf_put(plain
, WPA_KEY_RSC_LEN
));
2548 gtk
= gsm
->GTK
[gsm
->GN
- 1];
2549 gtk_len
= gsm
->GTK_len
;
2550 if (sm
->wpa_auth
->conf
.disable_gtk
||
2551 sm
->wpa_key_mgmt
== WPA_KEY_MGMT_OSEN
) {
2553 * Provide unique random GTK to each STA to prevent use
2554 * of GTK in the BSS.
2556 if (random_get_bytes(dummy_gtk
, gtk_len
) < 0) {
2562 hdr
[0] = gsm
->GN
& 0x03;
2564 tmp
= wpabuf_put(plain
, 0);
2565 tmp2
= wpa_add_kde(tmp
, RSN_KEY_DATA_GROUPKEY
, hdr
, 2,
2567 wpabuf_put(plain
, tmp2
- tmp
);
2570 tmp
= wpabuf_put(plain
, 0);
2571 tmp2
= ieee80211w_kde_add(sm
, tmp
);
2572 wpabuf_put(plain
, tmp2
- tmp
);
2574 *len
= (u8
*) wpabuf_put(plain
, 0) - len
- 1;
2579 int fils_set_tk(struct wpa_state_machine
*sm
)
2584 if (!sm
|| !sm
->PTK_valid
) {
2585 wpa_printf(MSG_DEBUG
, "FILS: No valid PTK available to set TK");
2588 if (sm
->tk_already_set
) {
2589 wpa_printf(MSG_DEBUG
, "FILS: TK already set to the driver");
2593 alg
= wpa_cipher_to_alg(sm
->pairwise
);
2594 klen
= wpa_cipher_key_len(sm
->pairwise
);
2596 wpa_printf(MSG_DEBUG
, "FILS: Configure TK to the driver");
2597 if (wpa_auth_set_key(sm
->wpa_auth
, 0, alg
, sm
->addr
, 0,
2598 sm
->PTK
.tk
, klen
)) {
2599 wpa_printf(MSG_DEBUG
, "FILS: Failed to set TK to the driver");
2602 sm
->tk_already_set
= TRUE
;
2608 u8
* hostapd_eid_assoc_fils_session(struct wpa_state_machine
*sm
, u8
*buf
,
2609 const u8
*fils_session
, struct wpabuf
*hlp
)
2611 struct wpabuf
*plain
;
2615 *pos
++ = WLAN_EID_EXTENSION
; /* Element ID */
2616 *pos
++ = 1 + FILS_SESSION_LEN
; /* Length */
2617 *pos
++ = WLAN_EID_EXT_FILS_SESSION
; /* Element ID Extension */
2618 os_memcpy(pos
, fils_session
, FILS_SESSION_LEN
);
2619 pos
+= FILS_SESSION_LEN
;
2621 plain
= fils_prepare_plainbuf(sm
, hlp
);
2623 wpa_printf(MSG_DEBUG
, "FILS: Plain buffer prep failed");
2627 os_memcpy(pos
, wpabuf_head(plain
), wpabuf_len(plain
));
2628 pos
+= wpabuf_len(plain
);
2630 wpa_printf(MSG_DEBUG
, "%s: plain buf_len: %u", __func__
,
2631 (unsigned int) wpabuf_len(plain
));
2633 sm
->fils_completed
= 1;
2637 #endif /* CONFIG_FILS */
2641 int get_sta_tx_parameters(struct wpa_state_machine
*sm
, int ap_max_chanwidth
,
2642 int ap_seg1_idx
, int *bandwidth
, int *seg1_idx
)
2644 struct wpa_authenticator
*wpa_auth
= sm
->wpa_auth
;
2646 if (!wpa_auth
->cb
->get_sta_tx_params
)
2648 return wpa_auth
->cb
->get_sta_tx_params(wpa_auth
->cb_ctx
, sm
->addr
,
2649 ap_max_chanwidth
, ap_seg1_idx
,
2650 bandwidth
, seg1_idx
);
2652 #endif /* CONFIG_OCV */
2655 SM_STATE(WPA_PTK
, PTKCALCNEGOTIATING
)
2657 struct wpa_authenticator
*wpa_auth
= sm
->wpa_auth
;
2659 int ok
= 0, psk_found
= 0;
2660 const u8
*pmk
= NULL
;
2663 const u8
*eapol_key_ie
, *key_data
, *mic
;
2664 u16 key_data_length
;
2665 size_t mic_len
, eapol_key_ie_len
;
2666 struct ieee802_1x_hdr
*hdr
;
2667 struct wpa_eapol_key
*key
;
2668 struct wpa_eapol_ie_parse kde
;
2670 SM_ENTRY_MA(WPA_PTK
, PTKCALCNEGOTIATING
, wpa_ptk
);
2671 sm
->EAPOLKeyReceived
= FALSE
;
2672 sm
->update_snonce
= FALSE
;
2673 os_memset(&PTK
, 0, sizeof(PTK
));
2675 mic_len
= wpa_mic_len(sm
->wpa_key_mgmt
, sm
->pmk_len
);
2677 /* WPA with IEEE 802.1X: use the derived PMK from EAP
2678 * WPA-PSK: iterate through possible PSKs and select the one matching
2681 if (wpa_key_mgmt_wpa_psk(sm
->wpa_key_mgmt
) &&
2682 !wpa_key_mgmt_sae(sm
->wpa_key_mgmt
)) {
2683 pmk
= wpa_auth_get_psk(sm
->wpa_auth
, sm
->addr
,
2684 sm
->p2p_dev_addr
, pmk
, &pmk_len
);
2688 #ifdef CONFIG_IEEE80211R_AP
2689 if (wpa_key_mgmt_ft_psk(sm
->wpa_key_mgmt
)) {
2690 os_memcpy(sm
->xxkey
, pmk
, pmk_len
);
2691 sm
->xxkey_len
= pmk_len
;
2693 #endif /* CONFIG_IEEE80211R_AP */
2696 pmk_len
= sm
->pmk_len
;
2699 if (wpa_derive_ptk(sm
, sm
->SNonce
, pmk
, pmk_len
, &PTK
) < 0)
2703 wpa_verify_key_mic(sm
->wpa_key_mgmt
, pmk_len
, &PTK
,
2704 sm
->last_rx_eapol_key
,
2705 sm
->last_rx_eapol_key_len
) == 0) {
2712 wpa_aead_decrypt(sm
, &PTK
, sm
->last_rx_eapol_key
,
2713 sm
->last_rx_eapol_key_len
, NULL
) == 0) {
2717 #endif /* CONFIG_FILS */
2719 if (!wpa_key_mgmt_wpa_psk(sm
->wpa_key_mgmt
) ||
2720 wpa_key_mgmt_sae(sm
->wpa_key_mgmt
))
2725 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
2726 "invalid MIC in msg 2/4 of 4-Way Handshake");
2728 wpa_auth_psk_failure_report(sm
->wpa_auth
, sm
->addr
);
2733 * Note: last_rx_eapol_key length fields have already been validated in
2736 hdr
= (struct ieee802_1x_hdr
*) sm
->last_rx_eapol_key
;
2737 key
= (struct wpa_eapol_key
*) (hdr
+ 1);
2738 mic
= (u8
*) (key
+ 1);
2739 key_data
= mic
+ mic_len
+ 2;
2740 key_data_length
= WPA_GET_BE16(mic
+ mic_len
);
2741 if (key_data_length
> sm
->last_rx_eapol_key_len
- sizeof(*hdr
) -
2742 sizeof(*key
) - mic_len
- 2)
2745 if (wpa_parse_kde_ies(key_data
, key_data_length
, &kde
) < 0) {
2746 wpa_auth_vlogger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
2747 "received EAPOL-Key msg 2/4 with invalid Key Data contents");
2751 eapol_key_ie
= kde
.rsn_ie
;
2752 eapol_key_ie_len
= kde
.rsn_ie_len
;
2753 } else if (kde
.osen
) {
2754 eapol_key_ie
= kde
.osen
;
2755 eapol_key_ie_len
= kde
.osen_len
;
2757 eapol_key_ie
= kde
.wpa_ie
;
2758 eapol_key_ie_len
= kde
.wpa_ie_len
;
2760 ft
= sm
->wpa
== WPA_VERSION_WPA2
&& wpa_key_mgmt_ft(sm
->wpa_key_mgmt
);
2761 if (sm
->wpa_ie
== NULL
||
2762 wpa_compare_rsn_ie(ft
, sm
->wpa_ie
, sm
->wpa_ie_len
,
2763 eapol_key_ie
, eapol_key_ie_len
)) {
2764 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
2765 "WPA IE from (Re)AssocReq did not match with msg 2/4");
2767 wpa_hexdump(MSG_DEBUG
, "WPA IE in AssocReq",
2768 sm
->wpa_ie
, sm
->wpa_ie_len
);
2770 wpa_hexdump(MSG_DEBUG
, "WPA IE in msg 2/4",
2771 eapol_key_ie
, eapol_key_ie_len
);
2772 /* MLME-DEAUTHENTICATE.request */
2773 wpa_sta_disconnect(wpa_auth
, sm
->addr
,
2774 WLAN_REASON_PREV_AUTH_NOT_VALID
);
2778 if (wpa_auth_uses_ocv(sm
)) {
2779 struct wpa_channel_info ci
;
2783 if (wpa_channel_info(wpa_auth
, &ci
) != 0) {
2784 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
2785 "Failed to get channel info to validate received OCI in EAPOL-Key 2/4");
2789 if (get_sta_tx_parameters(sm
,
2790 channel_width_to_int(ci
.chanwidth
),
2791 ci
.seg1_idx
, &tx_chanwidth
,
2795 if (ocv_verify_tx_params(kde
.oci
, kde
.oci_len
, &ci
,
2796 tx_chanwidth
, tx_seg1_idx
) != 0) {
2797 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
2802 #endif /* CONFIG_OCV */
2803 #ifdef CONFIG_IEEE80211R_AP
2804 if (ft
&& ft_check_msg_2_of_4(wpa_auth
, sm
, &kde
) < 0) {
2805 wpa_sta_disconnect(wpa_auth
, sm
->addr
,
2806 WLAN_REASON_PREV_AUTH_NOT_VALID
);
2809 #endif /* CONFIG_IEEE80211R_AP */
2811 if (kde
.ip_addr_req
&& kde
.ip_addr_req
[0] &&
2812 wpa_auth
->ip_pool
&& WPA_GET_BE32(sm
->ip_addr
) == 0) {
2814 wpa_printf(MSG_DEBUG
,
2815 "P2P: IP address requested in EAPOL-Key exchange");
2816 idx
= bitfield_get_first_zero(wpa_auth
->ip_pool
);
2818 u32 start
= WPA_GET_BE32(wpa_auth
->conf
.ip_addr_start
);
2819 bitfield_set(wpa_auth
->ip_pool
, idx
);
2820 WPA_PUT_BE32(sm
->ip_addr
, start
+ idx
);
2821 wpa_printf(MSG_DEBUG
,
2822 "P2P: Assigned IP address %u.%u.%u.%u to "
2823 MACSTR
, sm
->ip_addr
[0], sm
->ip_addr
[1],
2824 sm
->ip_addr
[2], sm
->ip_addr
[3],
2828 #endif /* CONFIG_P2P */
2830 #ifdef CONFIG_IEEE80211R_AP
2831 if (sm
->wpa
== WPA_VERSION_WPA2
&& wpa_key_mgmt_ft(sm
->wpa_key_mgmt
)) {
2833 * Verify that PMKR1Name from EAPOL-Key message 2/4 matches
2834 * with the value we derived.
2836 if (os_memcmp_const(sm
->sup_pmk_r1_name
, sm
->pmk_r1_name
,
2837 WPA_PMK_NAME_LEN
) != 0) {
2838 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
2839 "PMKR1Name mismatch in FT 4-way "
2841 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name from "
2843 sm
->sup_pmk_r1_name
, WPA_PMK_NAME_LEN
);
2844 wpa_hexdump(MSG_DEBUG
, "FT: Derived PMKR1Name",
2845 sm
->pmk_r1_name
, WPA_PMK_NAME_LEN
);
2849 #endif /* CONFIG_IEEE80211R_AP */
2851 sm
->pending_1_of_4_timeout
= 0;
2852 eloop_cancel_timeout(wpa_send_eapol_timeout
, sm
->wpa_auth
, sm
);
2854 if (wpa_key_mgmt_wpa_psk(sm
->wpa_key_mgmt
)) {
2855 /* PSK may have changed from the previous choice, so update
2856 * state machine data based on whatever PSK was selected here.
2858 os_memcpy(sm
->PMK
, pmk
, PMK_LEN
);
2859 sm
->pmk_len
= PMK_LEN
;
2862 sm
->MICVerified
= TRUE
;
2864 os_memcpy(&sm
->PTK
, &PTK
, sizeof(PTK
));
2865 sm
->PTK_valid
= TRUE
;
2869 SM_STATE(WPA_PTK
, PTKCALCNEGOTIATING2
)
2871 SM_ENTRY_MA(WPA_PTK
, PTKCALCNEGOTIATING2
, wpa_ptk
);
2876 #ifdef CONFIG_IEEE80211W
2878 static int ieee80211w_kde_len(struct wpa_state_machine
*sm
)
2880 if (sm
->mgmt_frame_prot
) {
2882 len
= wpa_cipher_key_len(sm
->wpa_auth
->conf
.group_mgmt_cipher
);
2883 return 2 + RSN_SELECTOR_LEN
+ WPA_IGTK_KDE_PREFIX_LEN
+ len
;
2890 static u8
* ieee80211w_kde_add(struct wpa_state_machine
*sm
, u8
*pos
)
2892 struct wpa_igtk_kde igtk
;
2893 struct wpa_group
*gsm
= sm
->group
;
2894 u8 rsc
[WPA_KEY_RSC_LEN
];
2895 size_t len
= wpa_cipher_key_len(sm
->wpa_auth
->conf
.group_mgmt_cipher
);
2897 if (!sm
->mgmt_frame_prot
)
2900 igtk
.keyid
[0] = gsm
->GN_igtk
;
2902 if (gsm
->wpa_group_state
!= WPA_GROUP_SETKEYSDONE
||
2903 wpa_auth_get_seqnum(sm
->wpa_auth
, NULL
, gsm
->GN_igtk
, rsc
) < 0)
2904 os_memset(igtk
.pn
, 0, sizeof(igtk
.pn
));
2906 os_memcpy(igtk
.pn
, rsc
, sizeof(igtk
.pn
));
2907 os_memcpy(igtk
.igtk
, gsm
->IGTK
[gsm
->GN_igtk
- 4], len
);
2908 if (sm
->wpa_auth
->conf
.disable_gtk
||
2909 sm
->wpa_key_mgmt
== WPA_KEY_MGMT_OSEN
) {
2911 * Provide unique random IGTK to each STA to prevent use of
2914 if (random_get_bytes(igtk
.igtk
, len
) < 0)
2917 pos
= wpa_add_kde(pos
, RSN_KEY_DATA_IGTK
,
2918 (const u8
*) &igtk
, WPA_IGTK_KDE_PREFIX_LEN
+ len
,
2924 #else /* CONFIG_IEEE80211W */
2926 static int ieee80211w_kde_len(struct wpa_state_machine
*sm
)
2932 static u8
* ieee80211w_kde_add(struct wpa_state_machine
*sm
, u8
*pos
)
2937 #endif /* CONFIG_IEEE80211W */
2940 static int ocv_oci_len(struct wpa_state_machine
*sm
)
2943 if (wpa_auth_uses_ocv(sm
))
2944 return OCV_OCI_KDE_LEN
;
2945 #endif /* CONFIG_OCV */
2949 static int ocv_oci_add(struct wpa_state_machine
*sm
, u8
**argpos
)
2952 struct wpa_channel_info ci
;
2954 if (!wpa_auth_uses_ocv(sm
))
2957 if (wpa_channel_info(sm
->wpa_auth
, &ci
) != 0) {
2958 wpa_printf(MSG_WARNING
,
2959 "Failed to get channel info for OCI element");
2963 return ocv_insert_oci_kde(&ci
, argpos
);
2964 #else /* CONFIG_OCV */
2966 #endif /* CONFIG_OCV */
2970 SM_STATE(WPA_PTK
, PTKINITNEGOTIATING
)
2972 u8 rsc
[WPA_KEY_RSC_LEN
], *_rsc
, *gtk
, *kde
, *pos
, dummy_gtk
[32];
2973 size_t gtk_len
, kde_len
;
2974 struct wpa_group
*gsm
= sm
->group
;
2976 int wpa_ie_len
, secure
, keyidx
, encr
= 0;
2978 SM_ENTRY_MA(WPA_PTK
, PTKINITNEGOTIATING
, wpa_ptk
);
2979 sm
->TimeoutEvt
= FALSE
;
2982 if (sm
->wpa_auth
->conf
.wpa_disable_eapol_key_retries
&&
2983 sm
->TimeoutCtr
> 1) {
2984 /* Do not allow retransmission of EAPOL-Key msg 3/4 */
2987 if (sm
->TimeoutCtr
> sm
->wpa_auth
->conf
.wpa_pairwise_update_count
) {
2988 /* No point in sending the EAPOL-Key - we will disconnect
2989 * immediately following this. */
2993 /* Send EAPOL(1, 1, 1, Pair, P, RSC, ANonce, MIC(PTK), RSNIE, [MDIE],
2994 GTK[GN], IGTK, [FTIE], [TIE * 2])
2996 os_memset(rsc
, 0, WPA_KEY_RSC_LEN
);
2997 wpa_auth_get_seqnum(sm
->wpa_auth
, NULL
, gsm
->GN
, rsc
);
2998 /* If FT is used, wpa_auth->wpa_ie includes both RSNIE and MDIE */
2999 wpa_ie
= sm
->wpa_auth
->wpa_ie
;
3000 wpa_ie_len
= sm
->wpa_auth
->wpa_ie_len
;
3001 if (sm
->wpa
== WPA_VERSION_WPA
&&
3002 (sm
->wpa_auth
->conf
.wpa
& WPA_PROTO_RSN
) &&
3003 wpa_ie_len
> wpa_ie
[1] + 2 && wpa_ie
[0] == WLAN_EID_RSN
) {
3004 /* WPA-only STA, remove RSN IE and possible MDIE */
3005 wpa_ie
= wpa_ie
+ wpa_ie
[1] + 2;
3006 if (wpa_ie
[0] == WLAN_EID_MOBILITY_DOMAIN
)
3007 wpa_ie
= wpa_ie
+ wpa_ie
[1] + 2;
3008 wpa_ie_len
= wpa_ie
[1] + 2;
3010 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
3011 "sending 3/4 msg of 4-Way Handshake");
3012 if (sm
->wpa
== WPA_VERSION_WPA2
) {
3013 /* WPA2 send GTK in the 4-way handshake */
3015 gtk
= gsm
->GTK
[gsm
->GN
- 1];
3016 gtk_len
= gsm
->GTK_len
;
3017 if (sm
->wpa_auth
->conf
.disable_gtk
||
3018 sm
->wpa_key_mgmt
== WPA_KEY_MGMT_OSEN
) {
3020 * Provide unique random GTK to each STA to prevent use
3021 * of GTK in the BSS.
3023 if (random_get_bytes(dummy_gtk
, gtk_len
) < 0)
3031 /* WPA does not include GTK in msg 3/4 */
3037 if (sm
->rx_eapol_key_secure
) {
3039 * It looks like Windows 7 supplicant tries to use
3040 * Secure bit in msg 2/4 after having reported Michael
3041 * MIC failure and it then rejects the 4-way handshake
3042 * if msg 3/4 does not set Secure bit. Work around this
3043 * by setting the Secure bit here even in the case of
3044 * WPA if the supplicant used it first.
3046 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
3047 "STA used Secure bit in WPA msg 2/4 - "
3048 "set Secure for 3/4 as workaround");
3053 kde_len
= wpa_ie_len
+ ieee80211w_kde_len(sm
) + ocv_oci_len(sm
);
3055 kde_len
+= 2 + RSN_SELECTOR_LEN
+ 2 + gtk_len
;
3056 #ifdef CONFIG_IEEE80211R_AP
3057 if (wpa_key_mgmt_ft(sm
->wpa_key_mgmt
)) {
3058 kde_len
+= 2 + PMKID_LEN
; /* PMKR1Name into RSN IE */
3059 kde_len
+= 300; /* FTIE + 2 * TIE */
3061 #endif /* CONFIG_IEEE80211R_AP */
3063 if (WPA_GET_BE32(sm
->ip_addr
) > 0)
3064 kde_len
+= 2 + RSN_SELECTOR_LEN
+ 3 * 4;
3065 #endif /* CONFIG_P2P */
3066 kde
= os_malloc(kde_len
);
3071 os_memcpy(pos
, wpa_ie
, wpa_ie_len
);
3073 #ifdef CONFIG_IEEE80211R_AP
3074 if (wpa_key_mgmt_ft(sm
->wpa_key_mgmt
)) {
3079 res
= wpa_insert_pmkid(kde
, &elen
, sm
->pmk_r1_name
);
3081 wpa_printf(MSG_ERROR
, "FT: Failed to insert "
3082 "PMKR1Name into RSN IE in EAPOL-Key data");
3089 #endif /* CONFIG_IEEE80211R_AP */
3092 hdr
[0] = keyidx
& 0x03;
3094 pos
= wpa_add_kde(pos
, RSN_KEY_DATA_GROUPKEY
, hdr
, 2,
3097 pos
= ieee80211w_kde_add(sm
, pos
);
3098 if (ocv_oci_add(sm
, &pos
) < 0) {
3103 #ifdef CONFIG_IEEE80211R_AP
3104 if (wpa_key_mgmt_ft(sm
->wpa_key_mgmt
)) {
3106 struct wpa_auth_config
*conf
;
3108 conf
= &sm
->wpa_auth
->conf
;
3109 if (sm
->assoc_resp_ftie
&&
3110 kde
+ kde_len
- pos
>= 2 + sm
->assoc_resp_ftie
[1]) {
3111 os_memcpy(pos
, sm
->assoc_resp_ftie
,
3112 2 + sm
->assoc_resp_ftie
[1]);
3113 res
= 2 + sm
->assoc_resp_ftie
[1];
3115 int use_sha384
= wpa_key_mgmt_sha384(sm
->wpa_key_mgmt
);
3117 res
= wpa_write_ftie(conf
, use_sha384
,
3118 conf
->r0_key_holder
,
3119 conf
->r0_key_holder_len
,
3121 kde
+ kde_len
- pos
,
3125 wpa_printf(MSG_ERROR
, "FT: Failed to insert FTIE "
3126 "into EAPOL-Key Key Data");
3132 /* TIE[ReassociationDeadline] (TU) */
3133 *pos
++ = WLAN_EID_TIMEOUT_INTERVAL
;
3135 *pos
++ = WLAN_TIMEOUT_REASSOC_DEADLINE
;
3136 WPA_PUT_LE32(pos
, conf
->reassociation_deadline
);
3139 /* TIE[KeyLifetime] (seconds) */
3140 *pos
++ = WLAN_EID_TIMEOUT_INTERVAL
;
3142 *pos
++ = WLAN_TIMEOUT_KEY_LIFETIME
;
3143 WPA_PUT_LE32(pos
, conf
->r0_key_lifetime
);
3146 #endif /* CONFIG_IEEE80211R_AP */
3148 if (WPA_GET_BE32(sm
->ip_addr
) > 0) {
3150 os_memcpy(addr
, sm
->ip_addr
, 4);
3151 os_memcpy(addr
+ 4, sm
->wpa_auth
->conf
.ip_addr_mask
, 4);
3152 os_memcpy(addr
+ 8, sm
->wpa_auth
->conf
.ip_addr_go
, 4);
3153 pos
= wpa_add_kde(pos
, WFA_KEY_DATA_IP_ADDR_ALLOC
,
3154 addr
, sizeof(addr
), NULL
, 0);
3156 #endif /* CONFIG_P2P */
3158 wpa_send_eapol(sm
->wpa_auth
, sm
,
3159 (secure
? WPA_KEY_INFO_SECURE
: 0) |
3160 (wpa_mic_len(sm
->wpa_key_mgmt
, sm
->pmk_len
) ?
3161 WPA_KEY_INFO_MIC
: 0) |
3162 WPA_KEY_INFO_ACK
| WPA_KEY_INFO_INSTALL
|
3163 WPA_KEY_INFO_KEY_TYPE
,
3164 _rsc
, sm
->ANonce
, kde
, pos
- kde
, keyidx
, encr
);
3169 SM_STATE(WPA_PTK
, PTKINITDONE
)
3171 SM_ENTRY_MA(WPA_PTK
, PTKINITDONE
, wpa_ptk
);
3172 sm
->EAPOLKeyReceived
= FALSE
;
3174 enum wpa_alg alg
= wpa_cipher_to_alg(sm
->pairwise
);
3175 int klen
= wpa_cipher_key_len(sm
->pairwise
);
3176 if (wpa_auth_set_key(sm
->wpa_auth
, 0, alg
, sm
->addr
, 0,
3177 sm
->PTK
.tk
, klen
)) {
3178 wpa_sta_disconnect(sm
->wpa_auth
, sm
->addr
,
3179 WLAN_REASON_PREV_AUTH_NOT_VALID
);
3182 /* FIX: MLME-SetProtection.Request(TA, Tx_Rx) */
3183 sm
->pairwise_set
= TRUE
;
3185 if (sm
->wpa_auth
->conf
.wpa_ptk_rekey
) {
3186 eloop_cancel_timeout(wpa_rekey_ptk
, sm
->wpa_auth
, sm
);
3187 eloop_register_timeout(sm
->wpa_auth
->conf
.
3188 wpa_ptk_rekey
, 0, wpa_rekey_ptk
,
3192 if (wpa_key_mgmt_wpa_psk(sm
->wpa_key_mgmt
) ||
3193 sm
->wpa_key_mgmt
== WPA_KEY_MGMT_DPP
||
3194 sm
->wpa_key_mgmt
== WPA_KEY_MGMT_OWE
) {
3195 wpa_auth_set_eapol(sm
->wpa_auth
, sm
->addr
,
3196 WPA_EAPOL_authorized
, 1);
3200 if (0 /* IBSS == TRUE */) {
3202 if (sm
->keycount
== 2) {
3203 wpa_auth_set_eapol(sm
->wpa_auth
, sm
->addr
,
3204 WPA_EAPOL_portValid
, 1);
3207 wpa_auth_set_eapol(sm
->wpa_auth
, sm
->addr
, WPA_EAPOL_portValid
,
3210 wpa_auth_set_eapol(sm
->wpa_auth
, sm
->addr
, WPA_EAPOL_keyAvailable
, 0);
3211 wpa_auth_set_eapol(sm
->wpa_auth
, sm
->addr
, WPA_EAPOL_keyDone
, 1);
3212 if (sm
->wpa
== WPA_VERSION_WPA
)
3213 sm
->PInitAKeys
= TRUE
;
3216 wpa_auth_vlogger(sm
->wpa_auth
, sm
->addr
, LOGGER_INFO
,
3217 "pairwise key handshake completed (%s)",
3218 sm
->wpa
== WPA_VERSION_WPA
? "WPA" : "RSN");
3220 #ifdef CONFIG_IEEE80211R_AP
3221 wpa_ft_push_pmk_r1(sm
->wpa_auth
, sm
->addr
);
3222 #endif /* CONFIG_IEEE80211R_AP */
3228 struct wpa_authenticator
*wpa_auth
= sm
->wpa_auth
;
3231 SM_ENTER(WPA_PTK
, INITIALIZE
);
3232 else if (sm
->Disconnect
3233 /* || FIX: dot11RSNAConfigSALifetime timeout */) {
3234 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
3235 "WPA_PTK: sm->Disconnect");
3236 SM_ENTER(WPA_PTK
, DISCONNECT
);
3238 else if (sm
->DeauthenticationRequest
)
3239 SM_ENTER(WPA_PTK
, DISCONNECTED
);
3240 else if (sm
->AuthenticationRequest
)
3241 SM_ENTER(WPA_PTK
, AUTHENTICATION
);
3242 else if (sm
->ReAuthenticationRequest
)
3243 SM_ENTER(WPA_PTK
, AUTHENTICATION2
);
3244 else if (sm
->PTKRequest
) {
3245 if (wpa_auth_sm_ptk_update(sm
) < 0)
3246 SM_ENTER(WPA_PTK
, DISCONNECTED
);
3248 SM_ENTER(WPA_PTK
, PTKSTART
);
3249 } else switch (sm
->wpa_ptk_state
) {
3250 case WPA_PTK_INITIALIZE
:
3252 case WPA_PTK_DISCONNECT
:
3253 SM_ENTER(WPA_PTK
, DISCONNECTED
);
3255 case WPA_PTK_DISCONNECTED
:
3256 SM_ENTER(WPA_PTK
, INITIALIZE
);
3258 case WPA_PTK_AUTHENTICATION
:
3259 SM_ENTER(WPA_PTK
, AUTHENTICATION2
);
3261 case WPA_PTK_AUTHENTICATION2
:
3262 if (wpa_key_mgmt_wpa_ieee8021x(sm
->wpa_key_mgmt
) &&
3263 wpa_auth_get_eapol(sm
->wpa_auth
, sm
->addr
,
3264 WPA_EAPOL_keyRun
) > 0)
3265 SM_ENTER(WPA_PTK
, INITPMK
);
3266 else if (wpa_key_mgmt_wpa_psk(sm
->wpa_key_mgmt
) ||
3267 sm
->wpa_key_mgmt
== WPA_KEY_MGMT_OWE
3268 /* FIX: && 802.1X::keyRun */)
3269 SM_ENTER(WPA_PTK
, INITPSK
);
3270 else if (sm
->wpa_key_mgmt
== WPA_KEY_MGMT_DPP
)
3271 SM_ENTER(WPA_PTK
, INITPMK
);
3273 case WPA_PTK_INITPMK
:
3274 if (wpa_auth_get_eapol(sm
->wpa_auth
, sm
->addr
,
3275 WPA_EAPOL_keyAvailable
) > 0) {
3276 SM_ENTER(WPA_PTK
, PTKSTART
);
3278 } else if (sm
->wpa_key_mgmt
== WPA_KEY_MGMT_DPP
&& sm
->pmksa
) {
3279 SM_ENTER(WPA_PTK
, PTKSTART
);
3280 #endif /* CONFIG_DPP */
3282 wpa_auth
->dot11RSNA4WayHandshakeFailures
++;
3283 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_INFO
,
3284 "INITPMK - keyAvailable = false");
3285 SM_ENTER(WPA_PTK
, DISCONNECT
);
3288 case WPA_PTK_INITPSK
:
3289 if (wpa_auth_get_psk(sm
->wpa_auth
, sm
->addr
, sm
->p2p_dev_addr
,
3291 SM_ENTER(WPA_PTK
, PTKSTART
);
3293 } else if (wpa_auth_uses_sae(sm
) && sm
->pmksa
) {
3294 SM_ENTER(WPA_PTK
, PTKSTART
);
3295 #endif /* CONFIG_SAE */
3297 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_INFO
,
3298 "no PSK configured for the STA");
3299 wpa_auth
->dot11RSNA4WayHandshakeFailures
++;
3300 SM_ENTER(WPA_PTK
, DISCONNECT
);
3303 case WPA_PTK_PTKSTART
:
3304 if (sm
->EAPOLKeyReceived
&& !sm
->EAPOLKeyRequest
&&
3305 sm
->EAPOLKeyPairwise
)
3306 SM_ENTER(WPA_PTK
, PTKCALCNEGOTIATING
);
3307 else if (sm
->TimeoutCtr
>
3308 sm
->wpa_auth
->conf
.wpa_pairwise_update_count
) {
3309 wpa_auth
->dot11RSNA4WayHandshakeFailures
++;
3311 sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
3312 "PTKSTART: Retry limit %u reached",
3313 sm
->wpa_auth
->conf
.wpa_pairwise_update_count
);
3314 SM_ENTER(WPA_PTK
, DISCONNECT
);
3315 } else if (sm
->TimeoutEvt
)
3316 SM_ENTER(WPA_PTK
, PTKSTART
);
3318 case WPA_PTK_PTKCALCNEGOTIATING
:
3319 if (sm
->MICVerified
)
3320 SM_ENTER(WPA_PTK
, PTKCALCNEGOTIATING2
);
3321 else if (sm
->EAPOLKeyReceived
&& !sm
->EAPOLKeyRequest
&&
3322 sm
->EAPOLKeyPairwise
)
3323 SM_ENTER(WPA_PTK
, PTKCALCNEGOTIATING
);
3324 else if (sm
->TimeoutEvt
)
3325 SM_ENTER(WPA_PTK
, PTKSTART
);
3327 case WPA_PTK_PTKCALCNEGOTIATING2
:
3328 SM_ENTER(WPA_PTK
, PTKINITNEGOTIATING
);
3330 case WPA_PTK_PTKINITNEGOTIATING
:
3331 if (sm
->update_snonce
)
3332 SM_ENTER(WPA_PTK
, PTKCALCNEGOTIATING
);
3333 else if (sm
->EAPOLKeyReceived
&& !sm
->EAPOLKeyRequest
&&
3334 sm
->EAPOLKeyPairwise
&& sm
->MICVerified
)
3335 SM_ENTER(WPA_PTK
, PTKINITDONE
);
3336 else if (sm
->TimeoutCtr
>
3337 sm
->wpa_auth
->conf
.wpa_pairwise_update_count
||
3338 (sm
->wpa_auth
->conf
.wpa_disable_eapol_key_retries
&&
3339 sm
->TimeoutCtr
> 1)) {
3340 wpa_auth
->dot11RSNA4WayHandshakeFailures
++;
3342 sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
3343 "PTKINITNEGOTIATING: Retry limit %u reached",
3344 sm
->wpa_auth
->conf
.wpa_pairwise_update_count
);
3345 SM_ENTER(WPA_PTK
, DISCONNECT
);
3346 } else if (sm
->TimeoutEvt
)
3347 SM_ENTER(WPA_PTK
, PTKINITNEGOTIATING
);
3349 case WPA_PTK_PTKINITDONE
:
3355 SM_STATE(WPA_PTK_GROUP
, IDLE
)
3357 SM_ENTRY_MA(WPA_PTK_GROUP
, IDLE
, wpa_ptk_group
);
3359 /* Init flag is not cleared here, so avoid busy
3360 * loop by claiming nothing changed. */
3361 sm
->changed
= FALSE
;
3363 sm
->GTimeoutCtr
= 0;
3367 SM_STATE(WPA_PTK_GROUP
, REKEYNEGOTIATING
)
3369 u8 rsc
[WPA_KEY_RSC_LEN
];
3370 struct wpa_group
*gsm
= sm
->group
;
3372 u8
*kde_buf
= NULL
, *pos
, hdr
[2];
3374 u8
*gtk
, dummy_gtk
[32];
3376 SM_ENTRY_MA(WPA_PTK_GROUP
, REKEYNEGOTIATING
, wpa_ptk_group
);
3379 if (sm
->wpa_auth
->conf
.wpa_disable_eapol_key_retries
&&
3380 sm
->GTimeoutCtr
> 1) {
3381 /* Do not allow retransmission of EAPOL-Key group msg 1/2 */
3384 if (sm
->GTimeoutCtr
> sm
->wpa_auth
->conf
.wpa_group_update_count
) {
3385 /* No point in sending the EAPOL-Key - we will disconnect
3386 * immediately following this. */
3390 if (sm
->wpa
== WPA_VERSION_WPA
)
3391 sm
->PInitAKeys
= FALSE
;
3392 sm
->TimeoutEvt
= FALSE
;
3393 /* Send EAPOL(1, 1, 1, !Pair, G, RSC, GNonce, MIC(PTK), GTK[GN]) */
3394 os_memset(rsc
, 0, WPA_KEY_RSC_LEN
);
3395 if (gsm
->wpa_group_state
== WPA_GROUP_SETKEYSDONE
)
3396 wpa_auth_get_seqnum(sm
->wpa_auth
, NULL
, gsm
->GN
, rsc
);
3397 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
3398 "sending 1/2 msg of Group Key Handshake");
3400 gtk
= gsm
->GTK
[gsm
->GN
- 1];
3401 if (sm
->wpa_auth
->conf
.disable_gtk
||
3402 sm
->wpa_key_mgmt
== WPA_KEY_MGMT_OSEN
) {
3404 * Provide unique random GTK to each STA to prevent use
3405 * of GTK in the BSS.
3407 if (random_get_bytes(dummy_gtk
, gsm
->GTK_len
) < 0)
3411 if (sm
->wpa
== WPA_VERSION_WPA2
) {
3412 kde_len
= 2 + RSN_SELECTOR_LEN
+ 2 + gsm
->GTK_len
+
3413 ieee80211w_kde_len(sm
) + ocv_oci_len(sm
);
3414 kde_buf
= os_malloc(kde_len
);
3415 if (kde_buf
== NULL
)
3418 kde
= pos
= kde_buf
;
3419 hdr
[0] = gsm
->GN
& 0x03;
3421 pos
= wpa_add_kde(pos
, RSN_KEY_DATA_GROUPKEY
, hdr
, 2,
3423 pos
= ieee80211w_kde_add(sm
, pos
);
3424 if (ocv_oci_add(sm
, &pos
) < 0) {
3428 kde_len
= pos
- kde
;
3431 kde_len
= gsm
->GTK_len
;
3434 wpa_send_eapol(sm
->wpa_auth
, sm
,
3435 WPA_KEY_INFO_SECURE
|
3436 (wpa_mic_len(sm
->wpa_key_mgmt
, sm
->pmk_len
) ?
3437 WPA_KEY_INFO_MIC
: 0) |
3439 (!sm
->Pair
? WPA_KEY_INFO_INSTALL
: 0),
3440 rsc
, NULL
, kde
, kde_len
, gsm
->GN
, 1);
3446 SM_STATE(WPA_PTK_GROUP
, REKEYESTABLISHED
)
3449 struct wpa_authenticator
*wpa_auth
= sm
->wpa_auth
;
3450 const u8
*key_data
, *mic
;
3451 struct ieee802_1x_hdr
*hdr
;
3452 struct wpa_eapol_key
*key
;
3453 struct wpa_eapol_ie_parse kde
;
3455 u16 key_data_length
;
3456 #endif /* CONFIG_OCV */
3458 SM_ENTRY_MA(WPA_PTK_GROUP
, REKEYESTABLISHED
, wpa_ptk_group
);
3459 sm
->EAPOLKeyReceived
= FALSE
;
3462 mic_len
= wpa_mic_len(sm
->wpa_key_mgmt
, sm
->pmk_len
);
3465 * Note: last_rx_eapol_key length fields have already been validated in
3468 hdr
= (struct ieee802_1x_hdr
*) sm
->last_rx_eapol_key
;
3469 key
= (struct wpa_eapol_key
*) (hdr
+ 1);
3470 mic
= (u8
*) (key
+ 1);
3471 key_data
= mic
+ mic_len
+ 2;
3472 key_data_length
= WPA_GET_BE16(mic
+ mic_len
);
3473 if (key_data_length
> sm
->last_rx_eapol_key_len
- sizeof(*hdr
) -
3474 sizeof(*key
) - mic_len
- 2)
3477 if (wpa_parse_kde_ies(key_data
, key_data_length
, &kde
) < 0) {
3478 wpa_auth_vlogger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
3479 "received EAPOL-Key group msg 2/2 with invalid Key Data contents");
3483 if (wpa_auth_uses_ocv(sm
)) {
3484 struct wpa_channel_info ci
;
3488 if (wpa_channel_info(wpa_auth
, &ci
) != 0) {
3489 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
3490 "Failed to get channel info to validate received OCI in EAPOL-Key group 1/2");
3494 if (get_sta_tx_parameters(sm
,
3495 channel_width_to_int(ci
.chanwidth
),
3496 ci
.seg1_idx
, &tx_chanwidth
,
3500 if (ocv_verify_tx_params(kde
.oci
, kde
.oci_len
, &ci
,
3501 tx_chanwidth
, tx_seg1_idx
) != 0) {
3502 wpa_auth_logger(wpa_auth
, sm
->addr
, LOGGER_INFO
,
3507 #endif /* CONFIG_OCV */
3509 if (sm
->GUpdateStationKeys
)
3510 sm
->group
->GKeyDoneStations
--;
3511 sm
->GUpdateStationKeys
= FALSE
;
3512 sm
->GTimeoutCtr
= 0;
3513 /* FIX: MLME.SetProtection.Request(TA, Tx_Rx) */
3514 wpa_auth_vlogger(sm
->wpa_auth
, sm
->addr
, LOGGER_INFO
,
3515 "group key handshake completed (%s)",
3516 sm
->wpa
== WPA_VERSION_WPA
? "WPA" : "RSN");
3521 SM_STATE(WPA_PTK_GROUP
, KEYERROR
)
3523 SM_ENTRY_MA(WPA_PTK_GROUP
, KEYERROR
, wpa_ptk_group
);
3524 if (sm
->GUpdateStationKeys
)
3525 sm
->group
->GKeyDoneStations
--;
3526 sm
->GUpdateStationKeys
= FALSE
;
3527 sm
->Disconnect
= TRUE
;
3528 wpa_auth_vlogger(sm
->wpa_auth
, sm
->addr
, LOGGER_INFO
,
3529 "group key handshake failed (%s) after %u tries",
3530 sm
->wpa
== WPA_VERSION_WPA
? "WPA" : "RSN",
3531 sm
->wpa_auth
->conf
.wpa_group_update_count
);
3535 SM_STEP(WPA_PTK_GROUP
)
3537 if (sm
->Init
|| sm
->PtkGroupInit
) {
3538 SM_ENTER(WPA_PTK_GROUP
, IDLE
);
3539 sm
->PtkGroupInit
= FALSE
;
3540 } else switch (sm
->wpa_ptk_group_state
) {
3541 case WPA_PTK_GROUP_IDLE
:
3542 if (sm
->GUpdateStationKeys
||
3543 (sm
->wpa
== WPA_VERSION_WPA
&& sm
->PInitAKeys
))
3544 SM_ENTER(WPA_PTK_GROUP
, REKEYNEGOTIATING
);
3546 case WPA_PTK_GROUP_REKEYNEGOTIATING
:
3547 if (sm
->EAPOLKeyReceived
&& !sm
->EAPOLKeyRequest
&&
3548 !sm
->EAPOLKeyPairwise
&& sm
->MICVerified
)
3549 SM_ENTER(WPA_PTK_GROUP
, REKEYESTABLISHED
);
3550 else if (sm
->GTimeoutCtr
>
3551 sm
->wpa_auth
->conf
.wpa_group_update_count
||
3552 (sm
->wpa_auth
->conf
.wpa_disable_eapol_key_retries
&&
3553 sm
->GTimeoutCtr
> 1))
3554 SM_ENTER(WPA_PTK_GROUP
, KEYERROR
);
3555 else if (sm
->TimeoutEvt
)
3556 SM_ENTER(WPA_PTK_GROUP
, REKEYNEGOTIATING
);
3558 case WPA_PTK_GROUP_KEYERROR
:
3559 SM_ENTER(WPA_PTK_GROUP
, IDLE
);
3561 case WPA_PTK_GROUP_REKEYESTABLISHED
:
3562 SM_ENTER(WPA_PTK_GROUP
, IDLE
);
3568 static int wpa_gtk_update(struct wpa_authenticator
*wpa_auth
,
3569 struct wpa_group
*group
)
3573 os_memcpy(group
->GNonce
, group
->Counter
, WPA_NONCE_LEN
);
3574 inc_byte_array(group
->Counter
, WPA_NONCE_LEN
);
3575 if (wpa_gmk_to_gtk(group
->GMK
, "Group key expansion",
3576 wpa_auth
->addr
, group
->GNonce
,
3577 group
->GTK
[group
->GN
- 1], group
->GTK_len
) < 0)
3579 wpa_hexdump_key(MSG_DEBUG
, "GTK",
3580 group
->GTK
[group
->GN
- 1], group
->GTK_len
);
3582 #ifdef CONFIG_IEEE80211W
3583 if (wpa_auth
->conf
.ieee80211w
!= NO_MGMT_FRAME_PROTECTION
) {
3585 len
= wpa_cipher_key_len(wpa_auth
->conf
.group_mgmt_cipher
);
3586 os_memcpy(group
->GNonce
, group
->Counter
, WPA_NONCE_LEN
);
3587 inc_byte_array(group
->Counter
, WPA_NONCE_LEN
);
3588 if (wpa_gmk_to_gtk(group
->GMK
, "IGTK key expansion",
3589 wpa_auth
->addr
, group
->GNonce
,
3590 group
->IGTK
[group
->GN_igtk
- 4], len
) < 0)
3592 wpa_hexdump_key(MSG_DEBUG
, "IGTK",
3593 group
->IGTK
[group
->GN_igtk
- 4], len
);
3595 #endif /* CONFIG_IEEE80211W */
3601 static void wpa_group_gtk_init(struct wpa_authenticator
*wpa_auth
,
3602 struct wpa_group
*group
)
3604 wpa_printf(MSG_DEBUG
, "WPA: group state machine entering state "
3605 "GTK_INIT (VLAN-ID %d)", group
->vlan_id
);
3606 group
->changed
= FALSE
; /* GInit is not cleared here; avoid loop */
3607 group
->wpa_group_state
= WPA_GROUP_GTK_INIT
;
3610 os_memset(group
->GTK
, 0, sizeof(group
->GTK
));
3613 #ifdef CONFIG_IEEE80211W
3616 #endif /* CONFIG_IEEE80211W */
3617 /* GTK[GN] = CalcGTK() */
3618 wpa_gtk_update(wpa_auth
, group
);
3622 static int wpa_group_update_sta(struct wpa_state_machine
*sm
, void *ctx
)
3624 if (ctx
!= NULL
&& ctx
!= sm
->group
)
3627 if (sm
->wpa_ptk_state
!= WPA_PTK_PTKINITDONE
) {
3628 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
3629 "Not in PTKINITDONE; skip Group Key update");
3630 sm
->GUpdateStationKeys
= FALSE
;
3633 if (sm
->GUpdateStationKeys
) {
3635 * This should not really happen, so add a debug log entry.
3636 * Since we clear the GKeyDoneStations before the loop, the
3637 * station needs to be counted here anyway.
3639 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
3640 "GUpdateStationKeys was already set when "
3641 "marking station for GTK rekeying");
3644 /* Do not rekey GTK/IGTK when STA is in WNM-Sleep Mode */
3645 if (sm
->is_wnmsleep
)
3648 sm
->group
->GKeyDoneStations
++;
3649 sm
->GUpdateStationKeys
= TRUE
;
3656 #ifdef CONFIG_WNM_AP
3657 /* update GTK when exiting WNM-Sleep Mode */
3658 void wpa_wnmsleep_rekey_gtk(struct wpa_state_machine
*sm
)
3660 if (sm
== NULL
|| sm
->is_wnmsleep
)
3663 wpa_group_update_sta(sm
, NULL
);
3667 void wpa_set_wnmsleep(struct wpa_state_machine
*sm
, int flag
)
3670 sm
->is_wnmsleep
= !!flag
;
3674 int wpa_wnmsleep_gtk_subelem(struct wpa_state_machine
*sm
, u8
*pos
)
3676 struct wpa_group
*gsm
= sm
->group
;
3681 * Sub-elem ID[1] | Length[1] | Key Info[2] | Key Length[1] | RSC[8] |
3684 *pos
++ = WNM_SLEEP_SUBELEM_GTK
;
3685 *pos
++ = 11 + gsm
->GTK_len
;
3686 /* Key ID in B0-B1 of Key Info */
3687 WPA_PUT_LE16(pos
, gsm
->GN
& 0x03);
3689 *pos
++ = gsm
->GTK_len
;
3690 if (wpa_auth_get_seqnum(sm
->wpa_auth
, NULL
, gsm
->GN
, pos
) != 0)
3693 os_memcpy(pos
, gsm
->GTK
[gsm
->GN
- 1], gsm
->GTK_len
);
3694 pos
+= gsm
->GTK_len
;
3696 wpa_printf(MSG_DEBUG
, "WNM: GTK Key ID %u in WNM-Sleep Mode exit",
3698 wpa_hexdump_key(MSG_DEBUG
, "WNM: GTK in WNM-Sleep Mode exit",
3699 gsm
->GTK
[gsm
->GN
- 1], gsm
->GTK_len
);
3705 #ifdef CONFIG_IEEE80211W
3706 int wpa_wnmsleep_igtk_subelem(struct wpa_state_machine
*sm
, u8
*pos
)
3708 struct wpa_group
*gsm
= sm
->group
;
3710 size_t len
= wpa_cipher_key_len(sm
->wpa_auth
->conf
.group_mgmt_cipher
);
3714 * Sub-elem ID[1] | Length[1] | KeyID[2] | PN[6] | Key[16]
3716 *pos
++ = WNM_SLEEP_SUBELEM_IGTK
;
3717 *pos
++ = 2 + 6 + len
;
3718 WPA_PUT_LE16(pos
, gsm
->GN_igtk
);
3720 if (wpa_auth_get_seqnum(sm
->wpa_auth
, NULL
, gsm
->GN_igtk
, pos
) != 0)
3724 os_memcpy(pos
, gsm
->IGTK
[gsm
->GN_igtk
- 4], len
);
3727 wpa_printf(MSG_DEBUG
, "WNM: IGTK Key ID %u in WNM-Sleep Mode exit",
3729 wpa_hexdump_key(MSG_DEBUG
, "WNM: IGTK in WNM-Sleep Mode exit",
3730 gsm
->IGTK
[gsm
->GN_igtk
- 4], len
);
3734 #endif /* CONFIG_IEEE80211W */
3735 #endif /* CONFIG_WNM_AP */
3738 static void wpa_group_setkeys(struct wpa_authenticator
*wpa_auth
,
3739 struct wpa_group
*group
)
3743 wpa_printf(MSG_DEBUG
, "WPA: group state machine entering state "
3744 "SETKEYS (VLAN-ID %d)", group
->vlan_id
);
3745 group
->changed
= TRUE
;
3746 group
->wpa_group_state
= WPA_GROUP_SETKEYS
;
3747 group
->GTKReKey
= FALSE
;
3749 group
->GM
= group
->GN
;
3751 #ifdef CONFIG_IEEE80211W
3752 tmp
= group
->GM_igtk
;
3753 group
->GM_igtk
= group
->GN_igtk
;
3754 group
->GN_igtk
= tmp
;
3755 #endif /* CONFIG_IEEE80211W */
3756 /* "GKeyDoneStations = GNoStations" is done in more robust way by
3757 * counting the STAs that are marked with GUpdateStationKeys instead of
3758 * including all STAs that could be in not-yet-completed state. */
3759 wpa_gtk_update(wpa_auth
, group
);
3761 if (group
->GKeyDoneStations
) {
3762 wpa_printf(MSG_DEBUG
, "wpa_group_setkeys: Unexpected "
3763 "GKeyDoneStations=%d when starting new GTK rekey",
3764 group
->GKeyDoneStations
);
3765 group
->GKeyDoneStations
= 0;
3767 wpa_auth_for_each_sta(wpa_auth
, wpa_group_update_sta
, group
);
3768 wpa_printf(MSG_DEBUG
, "wpa_group_setkeys: GKeyDoneStations=%d",
3769 group
->GKeyDoneStations
);
3773 static int wpa_group_config_group_keys(struct wpa_authenticator
*wpa_auth
,
3774 struct wpa_group
*group
)
3778 if (wpa_auth_set_key(wpa_auth
, group
->vlan_id
,
3779 wpa_cipher_to_alg(wpa_auth
->conf
.wpa_group
),
3780 broadcast_ether_addr
, group
->GN
,
3781 group
->GTK
[group
->GN
- 1], group
->GTK_len
) < 0)
3784 #ifdef CONFIG_IEEE80211W
3785 if (wpa_auth
->conf
.ieee80211w
!= NO_MGMT_FRAME_PROTECTION
) {
3789 alg
= wpa_cipher_to_alg(wpa_auth
->conf
.group_mgmt_cipher
);
3790 len
= wpa_cipher_key_len(wpa_auth
->conf
.group_mgmt_cipher
);
3793 wpa_auth_set_key(wpa_auth
, group
->vlan_id
, alg
,
3794 broadcast_ether_addr
, group
->GN_igtk
,
3795 group
->IGTK
[group
->GN_igtk
- 4], len
) < 0)
3798 #endif /* CONFIG_IEEE80211W */
3804 static int wpa_group_disconnect_cb(struct wpa_state_machine
*sm
, void *ctx
)
3806 if (sm
->group
== ctx
) {
3807 wpa_printf(MSG_DEBUG
, "WPA: Mark STA " MACSTR
3808 " for discconnection due to fatal failure",
3810 sm
->Disconnect
= TRUE
;
3817 static void wpa_group_fatal_failure(struct wpa_authenticator
*wpa_auth
,
3818 struct wpa_group
*group
)
3820 wpa_printf(MSG_DEBUG
, "WPA: group state machine entering state FATAL_FAILURE");
3821 group
->changed
= TRUE
;
3822 group
->wpa_group_state
= WPA_GROUP_FATAL_FAILURE
;
3823 wpa_auth_for_each_sta(wpa_auth
, wpa_group_disconnect_cb
, group
);
3827 static int wpa_group_setkeysdone(struct wpa_authenticator
*wpa_auth
,
3828 struct wpa_group
*group
)
3830 wpa_printf(MSG_DEBUG
, "WPA: group state machine entering state "
3831 "SETKEYSDONE (VLAN-ID %d)", group
->vlan_id
);
3832 group
->changed
= TRUE
;
3833 group
->wpa_group_state
= WPA_GROUP_SETKEYSDONE
;
3835 if (wpa_group_config_group_keys(wpa_auth
, group
) < 0) {
3836 wpa_group_fatal_failure(wpa_auth
, group
);
3844 static void wpa_group_sm_step(struct wpa_authenticator
*wpa_auth
,
3845 struct wpa_group
*group
)
3848 wpa_group_gtk_init(wpa_auth
, group
);
3849 } else if (group
->wpa_group_state
== WPA_GROUP_FATAL_FAILURE
) {
3850 /* Do not allow group operations */
3851 } else if (group
->wpa_group_state
== WPA_GROUP_GTK_INIT
&&
3852 group
->GTKAuthenticator
) {
3853 wpa_group_setkeysdone(wpa_auth
, group
);
3854 } else if (group
->wpa_group_state
== WPA_GROUP_SETKEYSDONE
&&
3856 wpa_group_setkeys(wpa_auth
, group
);
3857 } else if (group
->wpa_group_state
== WPA_GROUP_SETKEYS
) {
3858 if (group
->GKeyDoneStations
== 0)
3859 wpa_group_setkeysdone(wpa_auth
, group
);
3860 else if (group
->GTKReKey
)
3861 wpa_group_setkeys(wpa_auth
, group
);
3866 static int wpa_sm_step(struct wpa_state_machine
*sm
)
3871 if (sm
->in_step_loop
) {
3872 /* This should not happen, but if it does, make sure we do not
3873 * end up freeing the state machine too early by exiting the
3874 * recursive call. */
3875 wpa_printf(MSG_ERROR
, "WPA: wpa_sm_step() called recursively");
3879 sm
->in_step_loop
= 1;
3881 if (sm
->pending_deinit
)
3884 sm
->changed
= FALSE
;
3885 sm
->wpa_auth
->group
->changed
= FALSE
;
3887 SM_STEP_RUN(WPA_PTK
);
3888 if (sm
->pending_deinit
)
3890 SM_STEP_RUN(WPA_PTK_GROUP
);
3891 if (sm
->pending_deinit
)
3893 wpa_group_sm_step(sm
->wpa_auth
, sm
->group
);
3894 } while (sm
->changed
|| sm
->wpa_auth
->group
->changed
);
3895 sm
->in_step_loop
= 0;
3897 if (sm
->pending_deinit
) {
3898 wpa_printf(MSG_DEBUG
, "WPA: Completing pending STA state "
3899 "machine deinit for " MACSTR
, MAC2STR(sm
->addr
));
3900 wpa_free_sta_sm(sm
);
3907 static void wpa_sm_call_step(void *eloop_ctx
, void *timeout_ctx
)
3909 struct wpa_state_machine
*sm
= eloop_ctx
;
3914 void wpa_auth_sm_notify(struct wpa_state_machine
*sm
)
3918 eloop_register_timeout(0, 0, wpa_sm_call_step
, sm
, NULL
);
3922 void wpa_gtk_rekey(struct wpa_authenticator
*wpa_auth
)
3925 struct wpa_group
*group
;
3927 if (wpa_auth
== NULL
)
3930 group
= wpa_auth
->group
;
3932 for (i
= 0; i
< 2; i
++) {
3934 group
->GM
= group
->GN
;
3936 #ifdef CONFIG_IEEE80211W
3937 tmp
= group
->GM_igtk
;
3938 group
->GM_igtk
= group
->GN_igtk
;
3939 group
->GN_igtk
= tmp
;
3940 #endif /* CONFIG_IEEE80211W */
3941 wpa_gtk_update(wpa_auth
, group
);
3942 wpa_group_config_group_keys(wpa_auth
, group
);
3947 static const char * wpa_bool_txt(int val
)
3949 return val
? "TRUE" : "FALSE";
3953 #define RSN_SUITE "%02x-%02x-%02x-%d"
3954 #define RSN_SUITE_ARG(s) \
3955 ((s) >> 24) & 0xff, ((s) >> 16) & 0xff, ((s) >> 8) & 0xff, (s) & 0xff
3957 int wpa_get_mib(struct wpa_authenticator
*wpa_auth
, char *buf
, size_t buflen
)
3960 char pmkid_txt
[PMKID_LEN
* 2 + 1];
3961 #ifdef CONFIG_RSN_PREAUTH
3962 const int preauth
= 1;
3963 #else /* CONFIG_RSN_PREAUTH */
3964 const int preauth
= 0;
3965 #endif /* CONFIG_RSN_PREAUTH */
3967 if (wpa_auth
== NULL
)
3970 ret
= os_snprintf(buf
+ len
, buflen
- len
,
3971 "dot11RSNAOptionImplemented=TRUE\n"
3972 "dot11RSNAPreauthenticationImplemented=%s\n"
3973 "dot11RSNAEnabled=%s\n"
3974 "dot11RSNAPreauthenticationEnabled=%s\n",
3975 wpa_bool_txt(preauth
),
3976 wpa_bool_txt(wpa_auth
->conf
.wpa
& WPA_PROTO_RSN
),
3977 wpa_bool_txt(wpa_auth
->conf
.rsn_preauth
));
3978 if (os_snprintf_error(buflen
- len
, ret
))
3982 wpa_snprintf_hex(pmkid_txt
, sizeof(pmkid_txt
),
3983 wpa_auth
->dot11RSNAPMKIDUsed
, PMKID_LEN
);
3986 buf
+ len
, buflen
- len
,
3987 "dot11RSNAConfigVersion=%u\n"
3988 "dot11RSNAConfigPairwiseKeysSupported=9999\n"
3989 /* FIX: dot11RSNAConfigGroupCipher */
3990 /* FIX: dot11RSNAConfigGroupRekeyMethod */
3991 /* FIX: dot11RSNAConfigGroupRekeyTime */
3992 /* FIX: dot11RSNAConfigGroupRekeyPackets */
3993 "dot11RSNAConfigGroupRekeyStrict=%u\n"
3994 "dot11RSNAConfigGroupUpdateCount=%u\n"
3995 "dot11RSNAConfigPairwiseUpdateCount=%u\n"
3996 "dot11RSNAConfigGroupCipherSize=%u\n"
3997 "dot11RSNAConfigPMKLifetime=%u\n"
3998 "dot11RSNAConfigPMKReauthThreshold=%u\n"
3999 "dot11RSNAConfigNumberOfPTKSAReplayCounters=0\n"
4000 "dot11RSNAConfigSATimeout=%u\n"
4001 "dot11RSNAAuthenticationSuiteSelected=" RSN_SUITE
"\n"
4002 "dot11RSNAPairwiseCipherSelected=" RSN_SUITE
"\n"
4003 "dot11RSNAGroupCipherSelected=" RSN_SUITE
"\n"
4004 "dot11RSNAPMKIDUsed=%s\n"
4005 "dot11RSNAAuthenticationSuiteRequested=" RSN_SUITE
"\n"
4006 "dot11RSNAPairwiseCipherRequested=" RSN_SUITE
"\n"
4007 "dot11RSNAGroupCipherRequested=" RSN_SUITE
"\n"
4008 "dot11RSNATKIPCounterMeasuresInvoked=%u\n"
4009 "dot11RSNA4WayHandshakeFailures=%u\n"
4010 "dot11RSNAConfigNumberOfGTKSAReplayCounters=0\n",
4012 !!wpa_auth
->conf
.wpa_strict_rekey
,
4013 wpa_auth
->conf
.wpa_group_update_count
,
4014 wpa_auth
->conf
.wpa_pairwise_update_count
,
4015 wpa_cipher_key_len(wpa_auth
->conf
.wpa_group
) * 8,
4016 dot11RSNAConfigPMKLifetime
,
4017 dot11RSNAConfigPMKReauthThreshold
,
4018 dot11RSNAConfigSATimeout
,
4019 RSN_SUITE_ARG(wpa_auth
->dot11RSNAAuthenticationSuiteSelected
),
4020 RSN_SUITE_ARG(wpa_auth
->dot11RSNAPairwiseCipherSelected
),
4021 RSN_SUITE_ARG(wpa_auth
->dot11RSNAGroupCipherSelected
),
4023 RSN_SUITE_ARG(wpa_auth
->dot11RSNAAuthenticationSuiteRequested
),
4024 RSN_SUITE_ARG(wpa_auth
->dot11RSNAPairwiseCipherRequested
),
4025 RSN_SUITE_ARG(wpa_auth
->dot11RSNAGroupCipherRequested
),
4026 wpa_auth
->dot11RSNATKIPCounterMeasuresInvoked
,
4027 wpa_auth
->dot11RSNA4WayHandshakeFailures
);
4028 if (os_snprintf_error(buflen
- len
, ret
))
4032 /* TODO: dot11RSNAConfigPairwiseCiphersTable */
4033 /* TODO: dot11RSNAConfigAuthenticationSuitesTable */
4036 ret
= os_snprintf(buf
+ len
, buflen
- len
, "hostapdWPAGroupState=%d\n",
4037 wpa_auth
->group
->wpa_group_state
);
4038 if (os_snprintf_error(buflen
- len
, ret
))
4046 int wpa_get_mib_sta(struct wpa_state_machine
*sm
, char *buf
, size_t buflen
)
4054 /* TODO: FF-FF-FF-FF-FF-FF entry for broadcast/multicast stats */
4056 /* dot11RSNAStatsEntry */
4058 pairwise
= wpa_cipher_to_suite(sm
->wpa
== WPA_VERSION_WPA2
?
4059 WPA_PROTO_RSN
: WPA_PROTO_WPA
,
4065 buf
+ len
, buflen
- len
,
4066 /* TODO: dot11RSNAStatsIndex */
4067 "dot11RSNAStatsSTAAddress=" MACSTR
"\n"
4068 "dot11RSNAStatsVersion=1\n"
4069 "dot11RSNAStatsSelectedPairwiseCipher=" RSN_SUITE
"\n"
4070 /* TODO: dot11RSNAStatsTKIPICVErrors */
4071 "dot11RSNAStatsTKIPLocalMICFailures=%u\n"
4072 "dot11RSNAStatsTKIPRemoteMICFailures=%u\n"
4073 /* TODO: dot11RSNAStatsCCMPReplays */
4074 /* TODO: dot11RSNAStatsCCMPDecryptErrors */
4075 /* TODO: dot11RSNAStatsTKIPReplays */,
4077 RSN_SUITE_ARG(pairwise
),
4078 sm
->dot11RSNAStatsTKIPLocalMICFailures
,
4079 sm
->dot11RSNAStatsTKIPRemoteMICFailures
);
4080 if (os_snprintf_error(buflen
- len
, ret
))
4085 ret
= os_snprintf(buf
+ len
, buflen
- len
,
4086 "hostapdWPAPTKState=%d\n"
4087 "hostapdWPAPTKGroupState=%d\n",
4089 sm
->wpa_ptk_group_state
);
4090 if (os_snprintf_error(buflen
- len
, ret
))
4098 void wpa_auth_countermeasures_start(struct wpa_authenticator
*wpa_auth
)
4101 wpa_auth
->dot11RSNATKIPCounterMeasuresInvoked
++;
4105 int wpa_auth_pairwise_set(struct wpa_state_machine
*sm
)
4107 return sm
&& sm
->pairwise_set
;
4111 int wpa_auth_get_pairwise(struct wpa_state_machine
*sm
)
4113 return sm
->pairwise
;
4117 int wpa_auth_sta_key_mgmt(struct wpa_state_machine
*sm
)
4121 return sm
->wpa_key_mgmt
;
4125 int wpa_auth_sta_wpa_version(struct wpa_state_machine
*sm
)
4133 int wpa_auth_sta_ft_tk_already_set(struct wpa_state_machine
*sm
)
4135 if (!sm
|| !wpa_key_mgmt_ft(sm
->wpa_key_mgmt
))
4137 return sm
->tk_already_set
;
4141 int wpa_auth_sta_fils_tk_already_set(struct wpa_state_machine
*sm
)
4143 if (!sm
|| !wpa_key_mgmt_fils(sm
->wpa_key_mgmt
))
4145 return sm
->tk_already_set
;
4149 int wpa_auth_sta_clear_pmksa(struct wpa_state_machine
*sm
,
4150 struct rsn_pmksa_cache_entry
*entry
)
4152 if (sm
== NULL
|| sm
->pmksa
!= entry
)
4159 struct rsn_pmksa_cache_entry
*
4160 wpa_auth_sta_get_pmksa(struct wpa_state_machine
*sm
)
4162 return sm
? sm
->pmksa
: NULL
;
4166 void wpa_auth_sta_local_mic_failure_report(struct wpa_state_machine
*sm
)
4169 sm
->dot11RSNAStatsTKIPLocalMICFailures
++;
4173 const u8
* wpa_auth_get_wpa_ie(struct wpa_authenticator
*wpa_auth
, size_t *len
)
4175 if (wpa_auth
== NULL
)
4177 *len
= wpa_auth
->wpa_ie_len
;
4178 return wpa_auth
->wpa_ie
;
4182 int wpa_auth_pmksa_add(struct wpa_state_machine
*sm
, const u8
*pmk
,
4183 unsigned int pmk_len
,
4184 int session_timeout
, struct eapol_state_machine
*eapol
)
4186 if (sm
== NULL
|| sm
->wpa
!= WPA_VERSION_WPA2
||
4187 sm
->wpa_auth
->conf
.disable_pmksa_caching
)
4190 if (wpa_key_mgmt_sha384(sm
->wpa_key_mgmt
)) {
4191 if (pmk_len
> PMK_LEN_SUITE_B_192
)
4192 pmk_len
= PMK_LEN_SUITE_B_192
;
4193 } else if (pmk_len
> PMK_LEN
) {
4197 if (pmksa_cache_auth_add(sm
->wpa_auth
->pmksa
, pmk
, pmk_len
, NULL
,
4198 sm
->PTK
.kck
, sm
->PTK
.kck_len
,
4199 sm
->wpa_auth
->addr
, sm
->addr
, session_timeout
,
4200 eapol
, sm
->wpa_key_mgmt
))
4207 int wpa_auth_pmksa_add_preauth(struct wpa_authenticator
*wpa_auth
,
4208 const u8
*pmk
, size_t len
, const u8
*sta_addr
,
4209 int session_timeout
,
4210 struct eapol_state_machine
*eapol
)
4212 if (wpa_auth
== NULL
)
4215 if (pmksa_cache_auth_add(wpa_auth
->pmksa
, pmk
, len
, NULL
,
4218 sta_addr
, session_timeout
, eapol
,
4219 WPA_KEY_MGMT_IEEE8021X
))
4226 int wpa_auth_pmksa_add_sae(struct wpa_authenticator
*wpa_auth
, const u8
*addr
,
4227 const u8
*pmk
, const u8
*pmkid
)
4229 if (wpa_auth
->conf
.disable_pmksa_caching
)
4232 if (pmksa_cache_auth_add(wpa_auth
->pmksa
, pmk
, PMK_LEN
, pmkid
,
4234 wpa_auth
->addr
, addr
, 0, NULL
,
4242 void wpa_auth_add_sae_pmkid(struct wpa_state_machine
*sm
, const u8
*pmkid
)
4244 os_memcpy(sm
->pmkid
, pmkid
, PMKID_LEN
);
4249 int wpa_auth_pmksa_add2(struct wpa_authenticator
*wpa_auth
, const u8
*addr
,
4250 const u8
*pmk
, size_t pmk_len
, const u8
*pmkid
,
4251 int session_timeout
, int akmp
)
4253 if (wpa_auth
->conf
.disable_pmksa_caching
)
4256 if (pmksa_cache_auth_add(wpa_auth
->pmksa
, pmk
, pmk_len
, pmkid
,
4257 NULL
, 0, wpa_auth
->addr
, addr
, session_timeout
,
4265 void wpa_auth_pmksa_remove(struct wpa_authenticator
*wpa_auth
,
4268 struct rsn_pmksa_cache_entry
*pmksa
;
4270 if (wpa_auth
== NULL
|| wpa_auth
->pmksa
== NULL
)
4272 pmksa
= pmksa_cache_auth_get(wpa_auth
->pmksa
, sta_addr
, NULL
);
4274 wpa_printf(MSG_DEBUG
, "WPA: Remove PMKSA cache entry for "
4275 MACSTR
" based on request", MAC2STR(sta_addr
));
4276 pmksa_cache_free_entry(wpa_auth
->pmksa
, pmksa
);
4281 int wpa_auth_pmksa_list(struct wpa_authenticator
*wpa_auth
, char *buf
,
4284 if (!wpa_auth
|| !wpa_auth
->pmksa
)
4286 return pmksa_cache_auth_list(wpa_auth
->pmksa
, buf
, len
);
4290 void wpa_auth_pmksa_flush(struct wpa_authenticator
*wpa_auth
)
4292 if (wpa_auth
&& wpa_auth
->pmksa
)
4293 pmksa_cache_auth_flush(wpa_auth
->pmksa
);
4297 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
4300 int wpa_auth_pmksa_list_mesh(struct wpa_authenticator
*wpa_auth
, const u8
*addr
,
4301 char *buf
, size_t len
)
4303 if (!wpa_auth
|| !wpa_auth
->pmksa
)
4306 return pmksa_cache_auth_list_mesh(wpa_auth
->pmksa
, addr
, buf
, len
);
4310 struct rsn_pmksa_cache_entry
*
4311 wpa_auth_pmksa_create_entry(const u8
*aa
, const u8
*spa
, const u8
*pmk
,
4312 const u8
*pmkid
, int expiration
)
4314 struct rsn_pmksa_cache_entry
*entry
;
4315 struct os_reltime now
;
4317 entry
= pmksa_cache_auth_create_entry(pmk
, PMK_LEN
, pmkid
, NULL
, 0, aa
,
4318 spa
, 0, NULL
, WPA_KEY_MGMT_SAE
);
4322 os_get_reltime(&now
);
4323 entry
->expiration
= now
.sec
+ expiration
;
4328 int wpa_auth_pmksa_add_entry(struct wpa_authenticator
*wpa_auth
,
4329 struct rsn_pmksa_cache_entry
*entry
)
4333 if (!wpa_auth
|| !wpa_auth
->pmksa
)
4336 ret
= pmksa_cache_auth_add_entry(wpa_auth
->pmksa
, entry
);
4338 wpa_printf(MSG_DEBUG
,
4339 "RSN: Failed to store external PMKSA cache for "
4340 MACSTR
, MAC2STR(entry
->spa
));
4345 #endif /* CONFIG_MESH */
4346 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
4349 struct rsn_pmksa_cache_entry
*
4350 wpa_auth_pmksa_get(struct wpa_authenticator
*wpa_auth
, const u8
*sta_addr
,
4353 if (!wpa_auth
|| !wpa_auth
->pmksa
)
4355 return pmksa_cache_auth_get(wpa_auth
->pmksa
, sta_addr
, pmkid
);
4359 void wpa_auth_pmksa_set_to_sm(struct rsn_pmksa_cache_entry
*pmksa
,
4360 struct wpa_state_machine
*sm
,
4361 struct wpa_authenticator
*wpa_auth
,
4368 os_memcpy(pmk
, pmksa
->pmk
, PMK_LEN
);
4369 os_memcpy(pmkid
, pmksa
->pmkid
, PMKID_LEN
);
4370 os_memcpy(wpa_auth
->dot11RSNAPMKIDUsed
, pmksa
->pmkid
, PMKID_LEN
);
4375 * Remove and free the group from wpa_authenticator. This is triggered by a
4376 * callback to make sure nobody is currently iterating the group list while it
4379 static void wpa_group_free(struct wpa_authenticator
*wpa_auth
,
4380 struct wpa_group
*group
)
4382 struct wpa_group
*prev
= wpa_auth
->group
;
4384 wpa_printf(MSG_DEBUG
, "WPA: Remove group state machine for VLAN-ID %d",
4388 if (prev
->next
== group
) {
4389 /* This never frees the special first group as needed */
4390 prev
->next
= group
->next
;
4400 /* Increase the reference counter for group */
4401 static void wpa_group_get(struct wpa_authenticator
*wpa_auth
,
4402 struct wpa_group
*group
)
4404 /* Skip the special first group */
4405 if (wpa_auth
->group
== group
)
4408 group
->references
++;
4412 /* Decrease the reference counter and maybe free the group */
4413 static void wpa_group_put(struct wpa_authenticator
*wpa_auth
,
4414 struct wpa_group
*group
)
4416 /* Skip the special first group */
4417 if (wpa_auth
->group
== group
)
4420 group
->references
--;
4421 if (group
->references
)
4423 wpa_group_free(wpa_auth
, group
);
4428 * Add a group that has its references counter set to zero. Caller needs to
4429 * call wpa_group_get() on the return value to mark the entry in use.
4431 static struct wpa_group
*
4432 wpa_auth_add_group(struct wpa_authenticator
*wpa_auth
, int vlan_id
)
4434 struct wpa_group
*group
;
4436 if (wpa_auth
== NULL
|| wpa_auth
->group
== NULL
)
4439 wpa_printf(MSG_DEBUG
, "WPA: Add group state machine for VLAN-ID %d",
4441 group
= wpa_group_init(wpa_auth
, vlan_id
, 0);
4445 group
->next
= wpa_auth
->group
->next
;
4446 wpa_auth
->group
->next
= group
;
4453 * Enforce that the group state machine for the VLAN is running, increase
4454 * reference counter as interface is up. References might have been increased
4455 * even if a negative value is returned.
4456 * Returns: -1 on error (group missing, group already failed); otherwise, 0
4458 int wpa_auth_ensure_group(struct wpa_authenticator
*wpa_auth
, int vlan_id
)
4460 struct wpa_group
*group
;
4462 if (wpa_auth
== NULL
)
4465 group
= wpa_auth
->group
;
4467 if (group
->vlan_id
== vlan_id
)
4469 group
= group
->next
;
4472 if (group
== NULL
) {
4473 group
= wpa_auth_add_group(wpa_auth
, vlan_id
);
4478 wpa_printf(MSG_DEBUG
,
4479 "WPA: Ensure group state machine running for VLAN ID %d",
4482 wpa_group_get(wpa_auth
, group
);
4483 group
->num_setup_iface
++;
4485 if (group
->wpa_group_state
== WPA_GROUP_FATAL_FAILURE
)
4493 * Decrease reference counter, expected to be zero afterwards.
4494 * returns: -1 on error (group not found, group in fail state)
4495 * -2 if wpa_group is still referenced
4498 int wpa_auth_release_group(struct wpa_authenticator
*wpa_auth
, int vlan_id
)
4500 struct wpa_group
*group
;
4503 if (wpa_auth
== NULL
)
4506 group
= wpa_auth
->group
;
4508 if (group
->vlan_id
== vlan_id
)
4510 group
= group
->next
;
4516 wpa_printf(MSG_DEBUG
,
4517 "WPA: Try stopping group state machine for VLAN ID %d",
4520 if (group
->num_setup_iface
<= 0) {
4521 wpa_printf(MSG_ERROR
,
4522 "WPA: wpa_auth_release_group called more often than wpa_auth_ensure_group for VLAN ID %d, skipping.",
4526 group
->num_setup_iface
--;
4528 if (group
->wpa_group_state
== WPA_GROUP_FATAL_FAILURE
)
4531 if (group
->references
> 1) {
4532 wpa_printf(MSG_DEBUG
,
4533 "WPA: Cannot stop group state machine for VLAN ID %d as references are still hold",
4538 wpa_group_put(wpa_auth
, group
);
4544 int wpa_auth_sta_set_vlan(struct wpa_state_machine
*sm
, int vlan_id
)
4546 struct wpa_group
*group
;
4548 if (sm
== NULL
|| sm
->wpa_auth
== NULL
)
4551 group
= sm
->wpa_auth
->group
;
4553 if (group
->vlan_id
== vlan_id
)
4555 group
= group
->next
;
4558 if (group
== NULL
) {
4559 group
= wpa_auth_add_group(sm
->wpa_auth
, vlan_id
);
4564 if (sm
->group
== group
)
4567 if (group
->wpa_group_state
== WPA_GROUP_FATAL_FAILURE
)
4570 wpa_printf(MSG_DEBUG
, "WPA: Moving STA " MACSTR
" to use group state "
4571 "machine for VLAN ID %d", MAC2STR(sm
->addr
), vlan_id
);
4573 wpa_group_get(sm
->wpa_auth
, group
);
4574 wpa_group_put(sm
->wpa_auth
, sm
->group
);
4581 void wpa_auth_eapol_key_tx_status(struct wpa_authenticator
*wpa_auth
,
4582 struct wpa_state_machine
*sm
, int ack
)
4584 if (wpa_auth
== NULL
|| sm
== NULL
)
4586 wpa_printf(MSG_DEBUG
, "WPA: EAPOL-Key TX status for STA " MACSTR
4587 " ack=%d", MAC2STR(sm
->addr
), ack
);
4588 if (sm
->pending_1_of_4_timeout
&& ack
) {
4590 * Some deployed supplicant implementations update their SNonce
4591 * for each EAPOL-Key 2/4 message even within the same 4-way
4592 * handshake and then fail to use the first SNonce when
4593 * deriving the PTK. This results in unsuccessful 4-way
4594 * handshake whenever the relatively short initial timeout is
4595 * reached and EAPOL-Key 1/4 is retransmitted. Try to work
4596 * around this by increasing the timeout now that we know that
4597 * the station has received the frame.
4599 int timeout_ms
= eapol_key_timeout_subseq
;
4600 wpa_printf(MSG_DEBUG
, "WPA: Increase initial EAPOL-Key 1/4 "
4601 "timeout by %u ms because of acknowledged frame",
4603 eloop_cancel_timeout(wpa_send_eapol_timeout
, wpa_auth
, sm
);
4604 eloop_register_timeout(timeout_ms
/ 1000,
4605 (timeout_ms
% 1000) * 1000,
4606 wpa_send_eapol_timeout
, wpa_auth
, sm
);
4609 #ifdef CONFIG_TESTING_OPTIONS
4610 if (sm
->eapol_status_cb
) {
4611 sm
->eapol_status_cb(sm
->eapol_status_cb_ctx1
,
4612 sm
->eapol_status_cb_ctx2
);
4613 sm
->eapol_status_cb
= NULL
;
4615 #endif /* CONFIG_TESTING_OPTIONS */
4619 int wpa_auth_uses_sae(struct wpa_state_machine
*sm
)
4623 return wpa_key_mgmt_sae(sm
->wpa_key_mgmt
);
4627 int wpa_auth_uses_ft_sae(struct wpa_state_machine
*sm
)
4631 return sm
->wpa_key_mgmt
== WPA_KEY_MGMT_FT_SAE
;
4636 int wpa_auth_get_ip_addr(struct wpa_state_machine
*sm
, u8
*addr
)
4638 if (sm
== NULL
|| WPA_GET_BE32(sm
->ip_addr
) == 0)
4640 os_memcpy(addr
, sm
->ip_addr
, 4);
4643 #endif /* CONFIG_P2P */
4646 int wpa_auth_radius_das_disconnect_pmksa(struct wpa_authenticator
*wpa_auth
,
4647 struct radius_das_attrs
*attr
)
4649 return pmksa_cache_auth_radius_das_disconnect(wpa_auth
->pmksa
, attr
);
4653 void wpa_auth_reconfig_group_keys(struct wpa_authenticator
*wpa_auth
)
4655 struct wpa_group
*group
;
4659 for (group
= wpa_auth
->group
; group
; group
= group
->next
)
4660 wpa_group_config_group_keys(wpa_auth
, group
);
4666 struct wpa_auth_fils_iter_data
{
4667 struct wpa_authenticator
*auth
;
4669 struct rsn_pmksa_cache_entry
*pmksa
;
4675 static int wpa_auth_fils_iter(struct wpa_authenticator
*a
, void *ctx
)
4677 struct wpa_auth_fils_iter_data
*data
= ctx
;
4679 if (a
== data
->auth
|| !a
->conf
.fils_cache_id_set
||
4680 os_memcmp(a
->conf
.fils_cache_id
, data
->cache_id
,
4681 FILS_CACHE_ID_LEN
) != 0)
4683 data
->pmksa
= pmksa_cache_auth_get(a
->pmksa
, data
->spa
, data
->pmkid
);
4684 return data
->pmksa
!= NULL
;
4688 struct rsn_pmksa_cache_entry
*
4689 wpa_auth_pmksa_get_fils_cache_id(struct wpa_authenticator
*wpa_auth
,
4690 const u8
*sta_addr
, const u8
*pmkid
)
4692 struct wpa_auth_fils_iter_data idata
;
4694 if (!wpa_auth
->conf
.fils_cache_id_set
)
4696 idata
.auth
= wpa_auth
;
4697 idata
.cache_id
= wpa_auth
->conf
.fils_cache_id
;
4699 idata
.spa
= sta_addr
;
4700 idata
.pmkid
= pmkid
;
4701 wpa_auth_for_each_auth(wpa_auth
, wpa_auth_fils_iter
, &idata
);
4706 #ifdef CONFIG_IEEE80211R_AP
4707 int wpa_auth_write_fte(struct wpa_authenticator
*wpa_auth
, int use_sha384
,
4708 u8
*buf
, size_t len
)
4710 struct wpa_auth_config
*conf
= &wpa_auth
->conf
;
4712 return wpa_write_ftie(conf
, use_sha384
, conf
->r0_key_holder
,
4713 conf
->r0_key_holder_len
,
4714 NULL
, NULL
, buf
, len
, NULL
, 0);
4716 #endif /* CONFIG_IEEE80211R_AP */
4719 void wpa_auth_get_fils_aead_params(struct wpa_state_machine
*sm
,
4720 u8
*fils_anonce
, u8
*fils_snonce
,
4721 u8
*fils_kek
, size_t *fils_kek_len
)
4723 os_memcpy(fils_anonce
, sm
->ANonce
, WPA_NONCE_LEN
);
4724 os_memcpy(fils_snonce
, sm
->SNonce
, WPA_NONCE_LEN
);
4725 os_memcpy(fils_kek
, sm
->PTK
.kek
, WPA_KEK_MAX_LEN
);
4726 *fils_kek_len
= sm
->PTK
.kek_len
;
4729 #endif /* CONFIG_FILS */
4732 #ifdef CONFIG_TESTING_OPTIONS
4734 int wpa_auth_resend_m1(struct wpa_state_machine
*sm
, int change_anonce
,
4735 void (*cb
)(void *ctx1
, void *ctx2
),
4736 void *ctx1
, void *ctx2
)
4738 const u8
*anonce
= sm
->ANonce
;
4739 u8 anonce_buf
[WPA_NONCE_LEN
];
4741 if (change_anonce
) {
4742 if (random_get_bytes(anonce_buf
, WPA_NONCE_LEN
))
4744 anonce
= anonce_buf
;
4747 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
4748 "sending 1/4 msg of 4-Way Handshake (TESTING)");
4749 wpa_send_eapol(sm
->wpa_auth
, sm
,
4750 WPA_KEY_INFO_ACK
| WPA_KEY_INFO_KEY_TYPE
, NULL
,
4751 anonce
, NULL
, 0, 0, 0);
4756 int wpa_auth_resend_m3(struct wpa_state_machine
*sm
,
4757 void (*cb
)(void *ctx1
, void *ctx2
),
4758 void *ctx1
, void *ctx2
)
4760 u8 rsc
[WPA_KEY_RSC_LEN
], *_rsc
, *gtk
, *kde
, *pos
;
4761 #ifdef CONFIG_IEEE80211W
4763 #endif /* CONFIG_IEEE80211W */
4764 size_t gtk_len
, kde_len
;
4765 struct wpa_group
*gsm
= sm
->group
;
4767 int wpa_ie_len
, secure
, keyidx
, encr
= 0;
4769 /* Send EAPOL(1, 1, 1, Pair, P, RSC, ANonce, MIC(PTK), RSNIE, [MDIE],
4770 GTK[GN], IGTK, [FTIE], [TIE * 2])
4774 os_memset(rsc
, 0, WPA_KEY_RSC_LEN
);
4775 /* If FT is used, wpa_auth->wpa_ie includes both RSNIE and MDIE */
4776 wpa_ie
= sm
->wpa_auth
->wpa_ie
;
4777 wpa_ie_len
= sm
->wpa_auth
->wpa_ie_len
;
4778 if (sm
->wpa
== WPA_VERSION_WPA
&&
4779 (sm
->wpa_auth
->conf
.wpa
& WPA_PROTO_RSN
) &&
4780 wpa_ie_len
> wpa_ie
[1] + 2 && wpa_ie
[0] == WLAN_EID_RSN
) {
4781 /* WPA-only STA, remove RSN IE and possible MDIE */
4782 wpa_ie
= wpa_ie
+ wpa_ie
[1] + 2;
4783 if (wpa_ie
[0] == WLAN_EID_MOBILITY_DOMAIN
)
4784 wpa_ie
= wpa_ie
+ wpa_ie
[1] + 2;
4785 wpa_ie_len
= wpa_ie
[1] + 2;
4787 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
4788 "sending 3/4 msg of 4-Way Handshake (TESTING)");
4789 if (sm
->wpa
== WPA_VERSION_WPA2
) {
4790 /* WPA2 send GTK in the 4-way handshake */
4792 gtk
= gsm
->GTK
[gsm
->GN
- 1];
4793 gtk_len
= gsm
->GTK_len
;
4798 /* WPA does not include GTK in msg 3/4 */
4804 if (sm
->rx_eapol_key_secure
) {
4806 * It looks like Windows 7 supplicant tries to use
4807 * Secure bit in msg 2/4 after having reported Michael
4808 * MIC failure and it then rejects the 4-way handshake
4809 * if msg 3/4 does not set Secure bit. Work around this
4810 * by setting the Secure bit here even in the case of
4811 * WPA if the supplicant used it first.
4813 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
4814 "STA used Secure bit in WPA msg 2/4 - "
4815 "set Secure for 3/4 as workaround");
4820 kde_len
= wpa_ie_len
+ ieee80211w_kde_len(sm
) + ocv_oci_len(sm
);
4822 kde_len
+= 2 + RSN_SELECTOR_LEN
+ 2 + gtk_len
;
4823 #ifdef CONFIG_IEEE80211R_AP
4824 if (wpa_key_mgmt_ft(sm
->wpa_key_mgmt
)) {
4825 kde_len
+= 2 + PMKID_LEN
; /* PMKR1Name into RSN IE */
4826 kde_len
+= 300; /* FTIE + 2 * TIE */
4828 #endif /* CONFIG_IEEE80211R_AP */
4829 kde
= os_malloc(kde_len
);
4834 os_memcpy(pos
, wpa_ie
, wpa_ie_len
);
4836 #ifdef CONFIG_IEEE80211R_AP
4837 if (wpa_key_mgmt_ft(sm
->wpa_key_mgmt
)) {
4842 res
= wpa_insert_pmkid(kde
, &elen
, sm
->pmk_r1_name
);
4844 wpa_printf(MSG_ERROR
, "FT: Failed to insert "
4845 "PMKR1Name into RSN IE in EAPOL-Key data");
4852 #endif /* CONFIG_IEEE80211R_AP */
4855 hdr
[0] = keyidx
& 0x03;
4857 pos
= wpa_add_kde(pos
, RSN_KEY_DATA_GROUPKEY
, hdr
, 2,
4860 #ifdef CONFIG_IEEE80211W
4862 pos
= ieee80211w_kde_add(sm
, pos
);
4863 if (pos
- opos
>= 2 + RSN_SELECTOR_LEN
+ WPA_IGTK_KDE_PREFIX_LEN
) {
4864 /* skip KDE header and keyid */
4865 opos
+= 2 + RSN_SELECTOR_LEN
+ 2;
4866 os_memset(opos
, 0, 6); /* clear PN */
4868 #endif /* CONFIG_IEEE80211W */
4869 if (ocv_oci_add(sm
, &pos
) < 0) {
4874 #ifdef CONFIG_IEEE80211R_AP
4875 if (wpa_key_mgmt_ft(sm
->wpa_key_mgmt
)) {
4877 struct wpa_auth_config
*conf
;
4879 conf
= &sm
->wpa_auth
->conf
;
4880 if (sm
->assoc_resp_ftie
&&
4881 kde
+ kde_len
- pos
>= 2 + sm
->assoc_resp_ftie
[1]) {
4882 os_memcpy(pos
, sm
->assoc_resp_ftie
,
4883 2 + sm
->assoc_resp_ftie
[1]);
4884 res
= 2 + sm
->assoc_resp_ftie
[1];
4886 int use_sha384
= wpa_key_mgmt_sha384(sm
->wpa_key_mgmt
);
4888 res
= wpa_write_ftie(conf
, use_sha384
,
4889 conf
->r0_key_holder
,
4890 conf
->r0_key_holder_len
,
4892 kde
+ kde_len
- pos
,
4896 wpa_printf(MSG_ERROR
, "FT: Failed to insert FTIE "
4897 "into EAPOL-Key Key Data");
4903 /* TIE[ReassociationDeadline] (TU) */
4904 *pos
++ = WLAN_EID_TIMEOUT_INTERVAL
;
4906 *pos
++ = WLAN_TIMEOUT_REASSOC_DEADLINE
;
4907 WPA_PUT_LE32(pos
, conf
->reassociation_deadline
);
4910 /* TIE[KeyLifetime] (seconds) */
4911 *pos
++ = WLAN_EID_TIMEOUT_INTERVAL
;
4913 *pos
++ = WLAN_TIMEOUT_KEY_LIFETIME
;
4914 WPA_PUT_LE32(pos
, conf
->r0_key_lifetime
);
4917 #endif /* CONFIG_IEEE80211R_AP */
4919 wpa_send_eapol(sm
->wpa_auth
, sm
,
4920 (secure
? WPA_KEY_INFO_SECURE
: 0) |
4921 (wpa_mic_len(sm
->wpa_key_mgmt
, sm
->pmk_len
) ?
4922 WPA_KEY_INFO_MIC
: 0) |
4923 WPA_KEY_INFO_ACK
| WPA_KEY_INFO_INSTALL
|
4924 WPA_KEY_INFO_KEY_TYPE
,
4925 _rsc
, sm
->ANonce
, kde
, pos
- kde
, keyidx
, encr
);
4931 int wpa_auth_resend_group_m1(struct wpa_state_machine
*sm
,
4932 void (*cb
)(void *ctx1
, void *ctx2
),
4933 void *ctx1
, void *ctx2
)
4935 u8 rsc
[WPA_KEY_RSC_LEN
];
4936 struct wpa_group
*gsm
= sm
->group
;
4938 u8
*kde_buf
= NULL
, *pos
, hdr
[2];
4939 #ifdef CONFIG_IEEE80211W
4941 #endif /* CONFIG_IEEE80211W */
4945 /* Send EAPOL(1, 1, 1, !Pair, G, RSC, GNonce, MIC(PTK), GTK[GN]) */
4946 os_memset(rsc
, 0, WPA_KEY_RSC_LEN
);
4948 wpa_auth_logger(sm
->wpa_auth
, sm
->addr
, LOGGER_DEBUG
,
4949 "sending 1/2 msg of Group Key Handshake (TESTING)");
4951 gtk
= gsm
->GTK
[gsm
->GN
- 1];
4952 if (sm
->wpa
== WPA_VERSION_WPA2
) {
4953 kde_len
= 2 + RSN_SELECTOR_LEN
+ 2 + gsm
->GTK_len
+
4954 ieee80211w_kde_len(sm
) + ocv_oci_len(sm
);
4955 kde_buf
= os_malloc(kde_len
);
4956 if (kde_buf
== NULL
)
4959 kde
= pos
= kde_buf
;
4960 hdr
[0] = gsm
->GN
& 0x03;
4962 pos
= wpa_add_kde(pos
, RSN_KEY_DATA_GROUPKEY
, hdr
, 2,
4964 #ifdef CONFIG_IEEE80211W
4966 pos
= ieee80211w_kde_add(sm
, pos
);
4968 2 + RSN_SELECTOR_LEN
+ WPA_IGTK_KDE_PREFIX_LEN
) {
4969 /* skip KDE header and keyid */
4970 opos
+= 2 + RSN_SELECTOR_LEN
+ 2;
4971 os_memset(opos
, 0, 6); /* clear PN */
4973 #endif /* CONFIG_IEEE80211W */
4974 if (ocv_oci_add(sm
, &pos
) < 0) {
4978 kde_len
= pos
- kde
;
4981 kde_len
= gsm
->GTK_len
;
4984 sm
->eapol_status_cb
= cb
;
4985 sm
->eapol_status_cb_ctx1
= ctx1
;
4986 sm
->eapol_status_cb_ctx2
= ctx2
;
4988 wpa_send_eapol(sm
->wpa_auth
, sm
,
4989 WPA_KEY_INFO_SECURE
|
4990 (wpa_mic_len(sm
->wpa_key_mgmt
, sm
->pmk_len
) ?
4991 WPA_KEY_INFO_MIC
: 0) |
4993 (!sm
->Pair
? WPA_KEY_INFO_INSTALL
: 0),
4994 rsc
, NULL
, kde
, kde_len
, gsm
->GN
, 1);
5001 int wpa_auth_rekey_gtk(struct wpa_authenticator
*wpa_auth
)
5005 eloop_cancel_timeout(wpa_rekey_gtk
, wpa_auth
, NULL
);
5006 return eloop_register_timeout(0, 0, wpa_rekey_gtk
, wpa_auth
, NULL
);
5009 #endif /* CONFIG_TESTING_OPTIONS */