2 * hostapd - IEEE 802.11r - Fast BSS Transition
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/list.h"
14 #include "common/ieee802_11_defs.h"
15 #include "common/ieee802_11_common.h"
16 #include "common/ocv.h"
17 #include "drivers/driver.h"
18 #include "crypto/aes.h"
19 #include "crypto/aes_siv.h"
20 #include "crypto/aes_wrap.h"
21 #include "crypto/sha384.h"
22 #include "crypto/random.h"
23 #include "ap_config.h"
24 #include "ieee802_11.h"
27 #include "wpa_auth_i.h"
28 #include "pmksa_cache_auth.h"
31 #ifdef CONFIG_IEEE80211R_AP
33 const unsigned int ftRRBseqTimeout
= 10;
34 const unsigned int ftRRBmaxQueueLen
= 100;
37 static int wpa_ft_send_rrb_auth_resp(struct wpa_state_machine
*sm
,
38 const u8
*current_ap
, const u8
*sta_addr
,
39 u16 status
, const u8
*resp_ies
,
41 static void ft_finish_pull(struct wpa_state_machine
*sm
);
42 static void wpa_ft_expire_pull(void *eloop_ctx
, void *timeout_ctx
);
43 static void wpa_ft_rrb_seq_timeout(void *eloop_ctx
, void *timeout_ctx
);
53 * wpa_ft_rrb_decrypt - Decrypt FT RRB message
54 * @key: AES-SIV key for AEAD
55 * @key_len: Length of key in octets
56 * @enc: Pointer to encrypted TLVs
57 * @enc_len: Length of encrypted TLVs in octets
58 * @auth: Pointer to authenticated TLVs
59 * @auth_len: Length of authenticated TLVs in octets
60 * @src_addr: MAC address of the frame sender
61 * @type: Vendor-specific subtype of the RRB frame (FT_PACKET_*)
62 * @plain: Pointer to return the pointer to the allocated plaintext buffer;
63 * needs to be freed by the caller if not NULL;
64 * will only be returned on success
65 * @plain_len: Pointer to return the length of the allocated plaintext buffer
67 * Returns: 0 on success, -1 on error
69 static int wpa_ft_rrb_decrypt(const u8
*key
, const size_t key_len
,
70 const u8
*enc
, size_t enc_len
,
71 const u8
*auth
, const size_t auth_len
,
72 const u8
*src_addr
, u8 type
,
73 u8
**plain
, size_t *plain_size
)
75 const u8
*ad
[3] = { src_addr
, auth
, &type
};
76 size_t ad_len
[3] = { ETH_ALEN
, auth_len
, sizeof(type
) };
78 wpa_printf(MSG_DEBUG
, "FT(RRB): src_addr=" MACSTR
" type=%u",
79 MAC2STR(src_addr
), type
);
80 wpa_hexdump_key(MSG_DEBUG
, "FT(RRB): decrypt using key", key
, key_len
);
81 wpa_hexdump(MSG_DEBUG
, "FT(RRB): encrypted TLVs", enc
, enc_len
);
82 wpa_hexdump(MSG_DEBUG
, "FT(RRB): authenticated TLVs", auth
, auth_len
);
84 if (!key
) { /* skip decryption */
85 *plain
= os_memdup(enc
, enc_len
);
86 if (enc_len
> 0 && !*plain
)
89 *plain_size
= enc_len
;
97 if (enc_len
< AES_BLOCK_SIZE
)
100 *plain
= os_zalloc(enc_len
- AES_BLOCK_SIZE
);
104 if (aes_siv_decrypt(key
, key_len
, enc
, enc_len
, 3, ad
, ad_len
,
106 if (enc_len
< AES_BLOCK_SIZE
+ 2)
109 /* Try to work around Ethernet devices that add extra
110 * two octet padding even if the frame is longer than
111 * the minimum Ethernet frame. */
113 if (aes_siv_decrypt(key
, key_len
, enc
, enc_len
, 3, ad
, ad_len
,
118 *plain_size
= enc_len
- AES_BLOCK_SIZE
;
119 wpa_hexdump_key(MSG_DEBUG
, "FT(RRB): decrypted TLVs",
120 *plain
, *plain_size
);
127 wpa_printf(MSG_ERROR
, "FT(RRB): Failed to decrypt");
133 /* get first tlv record in packet matching type
134 * @data (decrypted) packet
135 * @return 0 on success else -1
137 static int wpa_ft_rrb_get_tlv(const u8
*plain
, size_t plain_len
,
138 u16 type
, size_t *tlv_len
, const u8
**tlv_data
)
140 const struct ft_rrb_tlv
*f
;
146 type16
= host_to_le16(type
);
148 while (left
>= sizeof(*f
)) {
149 f
= (const struct ft_rrb_tlv
*) plain
;
153 len
= le_to_host16(f
->len
);
156 wpa_printf(MSG_DEBUG
, "FT: RRB message truncated");
160 if (f
->type
== type16
) {
174 static void wpa_ft_rrb_dump(const u8
*plain
, const size_t plain_len
)
176 const struct ft_rrb_tlv
*f
;
182 wpa_printf(MSG_DEBUG
, "FT: RRB dump message");
183 while (left
>= sizeof(*f
)) {
184 f
= (const struct ft_rrb_tlv
*) plain
;
188 len
= le_to_host16(f
->len
);
190 wpa_printf(MSG_DEBUG
, "FT: RRB TLV type = %d, len = %zu",
191 le_to_host16(f
->type
), len
);
194 wpa_printf(MSG_DEBUG
,
195 "FT: RRB message truncated: left %zu bytes, need %zu",
200 wpa_hexdump(MSG_DEBUG
, "FT: RRB TLV data", plain
, len
);
207 wpa_hexdump(MSG_DEBUG
, "FT: RRB TLV padding", plain
, left
);
209 wpa_printf(MSG_DEBUG
, "FT: RRB dump message end");
213 static int cmp_int(const void *a
, const void *b
)
223 static int wpa_ft_rrb_get_tlv_vlan(const u8
*plain
, const size_t plain_len
,
224 struct vlan_description
*vlan
)
226 struct ft_rrb_tlv
*f
;
235 os_memset(vlan
, 0, sizeof(*vlan
));
237 while (left
>= sizeof(*f
)) {
238 f
= (struct ft_rrb_tlv
*) plain
;
243 len
= le_to_host16(f
->len
);
244 type
= le_to_host16(f
->type
);
247 wpa_printf(MSG_DEBUG
, "FT: RRB message truncated");
251 if (type
!= FT_RRB_VLAN_UNTAGGED
&& type
!= FT_RRB_VLAN_TAGGED
)
254 if (type
== FT_RRB_VLAN_UNTAGGED
&& len
!= sizeof(le16
)) {
255 wpa_printf(MSG_DEBUG
,
256 "FT: RRB VLAN_UNTAGGED invalid length");
260 if (type
== FT_RRB_VLAN_TAGGED
&& len
% sizeof(le16
) != 0) {
261 wpa_printf(MSG_DEBUG
,
262 "FT: RRB VLAN_TAGGED invalid length");
266 while (len
>= sizeof(le16
)) {
267 vlan_id
= WPA_GET_LE16(plain
);
268 plain
+= sizeof(le16
);
269 left
-= sizeof(le16
);
272 if (vlan_id
<= 0 || vlan_id
> MAX_VLAN_ID
) {
273 wpa_printf(MSG_DEBUG
,
274 "FT: RRB VLAN ID invalid %d",
279 if (type
== FT_RRB_VLAN_UNTAGGED
)
280 vlan
->untagged
= vlan_id
;
282 if (type
== FT_RRB_VLAN_TAGGED
&&
283 taggedidx
< MAX_NUM_TAGGED_VLAN
) {
284 vlan
->tagged
[taggedidx
] = vlan_id
;
286 } else if (type
== FT_RRB_VLAN_TAGGED
) {
287 wpa_printf(MSG_DEBUG
, "FT: RRB too many VLANs");
297 qsort(vlan
->tagged
, taggedidx
, sizeof(int), cmp_int
);
299 vlan
->notempty
= vlan
->untagged
|| vlan
->tagged
[0];
305 static size_t wpa_ft_tlv_len(const struct tlv_list
*tlvs
)
313 for (i
= 0; tlvs
[i
].type
!= FT_RRB_LAST_EMPTY
; i
++) {
314 tlv_len
+= sizeof(struct ft_rrb_tlv
);
315 tlv_len
+= tlvs
[i
].len
;
322 static size_t wpa_ft_tlv_lin(const struct tlv_list
*tlvs
, u8
*start
,
327 struct ft_rrb_tlv
*hdr
;
335 for (i
= 0; tlvs
[i
].type
!= FT_RRB_LAST_EMPTY
; i
++) {
336 if (tlv_len
+ sizeof(*hdr
) > (size_t) (endpos
- start
))
338 tlv_len
+= sizeof(*hdr
);
339 hdr
= (struct ft_rrb_tlv
*) pos
;
340 hdr
->type
= host_to_le16(tlvs
[i
].type
);
341 hdr
->len
= host_to_le16(tlvs
[i
].len
);
342 pos
= start
+ tlv_len
;
344 if (tlv_len
+ tlvs
[i
].len
> (size_t) (endpos
- start
))
346 if (tlvs
[i
].len
== 0)
348 tlv_len
+= tlvs
[i
].len
;
349 os_memcpy(pos
, tlvs
[i
].data
, tlvs
[i
].len
);
350 pos
= start
+ tlv_len
;
357 static size_t wpa_ft_vlan_len(const struct vlan_description
*vlan
)
362 if (!vlan
|| !vlan
->notempty
)
365 if (vlan
->untagged
) {
366 tlv_len
+= sizeof(struct ft_rrb_tlv
);
367 tlv_len
+= sizeof(le16
);
370 tlv_len
+= sizeof(struct ft_rrb_tlv
);
371 for (i
= 0; i
< MAX_NUM_TAGGED_VLAN
&& vlan
->tagged
[i
]; i
++)
372 tlv_len
+= sizeof(le16
);
378 static size_t wpa_ft_vlan_lin(const struct vlan_description
*vlan
,
379 u8
*start
, u8
*endpos
)
383 struct ft_rrb_tlv
*hdr
;
386 if (!vlan
|| !vlan
->notempty
)
390 if (vlan
->untagged
) {
391 tlv_len
+= sizeof(*hdr
);
392 if (start
+ tlv_len
> endpos
)
394 hdr
= (struct ft_rrb_tlv
*) pos
;
395 hdr
->type
= host_to_le16(FT_RRB_VLAN_UNTAGGED
);
396 hdr
->len
= host_to_le16(sizeof(le16
));
397 pos
= start
+ tlv_len
;
399 tlv_len
+= sizeof(le16
);
400 if (start
+ tlv_len
> endpos
)
402 WPA_PUT_LE16(pos
, vlan
->untagged
);
403 pos
= start
+ tlv_len
;
406 if (!vlan
->tagged
[0])
409 tlv_len
+= sizeof(*hdr
);
410 if (start
+ tlv_len
> endpos
)
412 hdr
= (struct ft_rrb_tlv
*) pos
;
413 hdr
->type
= host_to_le16(FT_RRB_VLAN_TAGGED
);
414 len
= 0; /* len is computed below */
415 pos
= start
+ tlv_len
;
417 for (i
= 0; i
< MAX_NUM_TAGGED_VLAN
&& vlan
->tagged
[i
]; i
++) {
418 tlv_len
+= sizeof(le16
);
419 if (start
+ tlv_len
> endpos
)
422 WPA_PUT_LE16(pos
, vlan
->tagged
[i
]);
423 pos
= start
+ tlv_len
;
426 hdr
->len
= host_to_le16(len
);
432 static int wpa_ft_rrb_lin(const struct tlv_list
*tlvs1
,
433 const struct tlv_list
*tlvs2
,
434 const struct vlan_description
*vlan
,
435 u8
**plain
, size_t *plain_len
)
440 tlv_len
= wpa_ft_tlv_len(tlvs1
);
441 tlv_len
+= wpa_ft_tlv_len(tlvs2
);
442 tlv_len
+= wpa_ft_vlan_len(vlan
);
444 *plain_len
= tlv_len
;
445 *plain
= os_zalloc(tlv_len
);
447 wpa_printf(MSG_ERROR
, "FT: Failed to allocate plaintext");
452 endpos
= *plain
+ tlv_len
;
453 pos
+= wpa_ft_tlv_lin(tlvs1
, pos
, endpos
);
454 pos
+= wpa_ft_tlv_lin(tlvs2
, pos
, endpos
);
455 pos
+= wpa_ft_vlan_lin(vlan
, pos
, endpos
);
459 wpa_printf(MSG_ERROR
, "FT: Length error building RRB");
473 static int wpa_ft_rrb_encrypt(const u8
*key
, const size_t key_len
,
474 const u8
*plain
, const size_t plain_len
,
475 const u8
*auth
, const size_t auth_len
,
476 const u8
*src_addr
, u8 type
, u8
*enc
)
478 const u8
*ad
[3] = { src_addr
, auth
, &type
};
479 size_t ad_len
[3] = { ETH_ALEN
, auth_len
, sizeof(type
) };
481 wpa_printf(MSG_DEBUG
, "FT(RRB): src_addr=" MACSTR
" type=%u",
482 MAC2STR(src_addr
), type
);
483 wpa_hexdump_key(MSG_DEBUG
, "FT(RRB): plaintext message",
485 wpa_hexdump_key(MSG_DEBUG
, "FT(RRB): encrypt using key", key
, key_len
);
486 wpa_hexdump(MSG_DEBUG
, "FT(RRB): authenticated TLVs", auth
, auth_len
);
489 /* encryption not needed, return plaintext as packet */
490 os_memcpy(enc
, plain
, plain_len
);
491 } else if (aes_siv_encrypt(key
, key_len
, plain
, plain_len
,
492 3, ad
, ad_len
, enc
) < 0) {
493 wpa_printf(MSG_ERROR
, "FT: Failed to encrypt RRB-OUI message");
496 wpa_hexdump(MSG_DEBUG
, "FT(RRB): encrypted TLVs",
497 enc
, plain_len
+ AES_BLOCK_SIZE
);
504 * wpa_ft_rrb_build - Build and encrypt an FT RRB message
505 * @key: AES-SIV key for AEAD
506 * @key_len: Length of key in octets
507 * @tlvs_enc0: First set of to-be-encrypted TLVs
508 * @tlvs_enc1: Second set of to-be-encrypted TLVs
509 * @tlvs_auth: Set of to-be-authenticated TLVs
510 * @src_addr: MAC address of the frame sender
511 * @type: Vendor-specific subtype of the RRB frame (FT_PACKET_*)
512 * @packet Pointer to return the pointer to the allocated packet buffer;
513 * needs to be freed by the caller if not null;
514 * will only be returned on success
515 * @packet_len: Pointer to return the length of the allocated buffer in octets
516 * Returns: 0 on success, -1 on error
518 static int wpa_ft_rrb_build(const u8
*key
, const size_t key_len
,
519 const struct tlv_list
*tlvs_enc0
,
520 const struct tlv_list
*tlvs_enc1
,
521 const struct tlv_list
*tlvs_auth
,
522 const struct vlan_description
*vlan
,
523 const u8
*src_addr
, u8 type
,
524 u8
**packet
, size_t *packet_len
)
526 u8
*plain
= NULL
, *auth
= NULL
, *pos
, *tmp
;
527 size_t plain_len
= 0, auth_len
= 0;
532 if (wpa_ft_rrb_lin(tlvs_enc0
, tlvs_enc1
, vlan
, &plain
, &plain_len
) < 0)
535 if (wpa_ft_rrb_lin(tlvs_auth
, NULL
, NULL
, &auth
, &auth_len
) < 0)
538 *packet_len
= sizeof(u16
) + auth_len
+ plain_len
;
540 *packet_len
+= AES_BLOCK_SIZE
;
541 #define RRB_MIN_MSG_LEN 64
542 if (*packet_len
< RRB_MIN_MSG_LEN
) {
543 pad_len
= RRB_MIN_MSG_LEN
- *packet_len
;
544 if (pad_len
< sizeof(struct ft_rrb_tlv
))
545 pad_len
= sizeof(struct ft_rrb_tlv
);
546 wpa_printf(MSG_DEBUG
,
547 "FT: Pad message to minimum Ethernet frame length (%d --> %d)",
548 (int) *packet_len
, (int) (*packet_len
+ pad_len
));
549 *packet_len
+= pad_len
;
550 tmp
= os_realloc(auth
, auth_len
+ pad_len
);
554 pos
= auth
+ auth_len
;
555 WPA_PUT_LE16(pos
, FT_RRB_LAST_EMPTY
);
557 WPA_PUT_LE16(pos
, pad_len
- sizeof(struct ft_rrb_tlv
));
559 os_memset(pos
, 0, pad_len
- sizeof(struct ft_rrb_tlv
));
563 *packet
= os_zalloc(*packet_len
);
568 WPA_PUT_LE16(pos
, auth_len
);
570 os_memcpy(pos
, auth
, auth_len
);
572 if (wpa_ft_rrb_encrypt(key
, key_len
, plain
, plain_len
, auth
,
573 auth_len
, src_addr
, type
, pos
) < 0)
575 wpa_hexdump(MSG_MSGDUMP
, "FT: RRB frame payload", *packet
, *packet_len
);
580 bin_clear_free(plain
, plain_len
);
584 wpa_printf(MSG_ERROR
, "FT: Failed to build RRB-OUI message");
594 #define RRB_GET_SRC(srcfield, type, field, txt, checklength) do { \
595 if (wpa_ft_rrb_get_tlv(srcfield, srcfield##_len, type, \
596 &f_##field##_len, &f_##field) < 0 || \
597 (checklength > 0 && ((size_t) checklength) != f_##field##_len)) { \
598 wpa_printf(MSG_INFO, "FT: Missing required " #field \
599 " in %s from " MACSTR, txt, MAC2STR(src_addr)); \
600 wpa_ft_rrb_dump(srcfield, srcfield##_len); \
605 #define RRB_GET(type, field, txt, checklength) \
606 RRB_GET_SRC(plain, type, field, txt, checklength)
607 #define RRB_GET_AUTH(type, field, txt, checklength) \
608 RRB_GET_SRC(auth, type, field, txt, checklength)
610 #define RRB_GET_OPTIONAL_SRC(srcfield, type, field, txt, checklength) do { \
611 if (wpa_ft_rrb_get_tlv(srcfield, srcfield##_len, type, \
612 &f_##field##_len, &f_##field) < 0 || \
613 (checklength > 0 && ((size_t) checklength) != f_##field##_len)) { \
614 wpa_printf(MSG_DEBUG, "FT: Missing optional " #field \
615 " in %s from " MACSTR, txt, MAC2STR(src_addr)); \
616 f_##field##_len = 0; \
621 #define RRB_GET_OPTIONAL(type, field, txt, checklength) \
622 RRB_GET_OPTIONAL_SRC(plain, type, field, txt, checklength)
623 #define RRB_GET_OPTIONAL_AUTH(type, field, txt, checklength) \
624 RRB_GET_OPTIONAL_SRC(auth, type, field, txt, checklength)
626 static int wpa_ft_rrb_send(struct wpa_authenticator
*wpa_auth
, const u8
*dst
,
627 const u8
*data
, size_t data_len
)
629 if (wpa_auth
->cb
->send_ether
== NULL
)
631 wpa_printf(MSG_DEBUG
, "FT: RRB send to " MACSTR
, MAC2STR(dst
));
632 return wpa_auth
->cb
->send_ether(wpa_auth
->cb_ctx
, dst
, ETH_P_RRB
,
637 static int wpa_ft_rrb_oui_send(struct wpa_authenticator
*wpa_auth
,
638 const u8
*dst
, u8 oui_suffix
,
639 const u8
*data
, size_t data_len
)
641 if (!wpa_auth
->cb
->send_oui
)
643 wpa_printf(MSG_DEBUG
, "FT: RRB-OUI type %u send to " MACSTR
" (len=%u)",
644 oui_suffix
, MAC2STR(dst
), (unsigned int) data_len
);
645 return wpa_auth
->cb
->send_oui(wpa_auth
->cb_ctx
, dst
, oui_suffix
, data
,
650 static int wpa_ft_action_send(struct wpa_authenticator
*wpa_auth
,
651 const u8
*dst
, const u8
*data
, size_t data_len
)
653 if (wpa_auth
->cb
->send_ft_action
== NULL
)
655 return wpa_auth
->cb
->send_ft_action(wpa_auth
->cb_ctx
, dst
,
660 static const u8
* wpa_ft_get_psk(struct wpa_authenticator
*wpa_auth
,
661 const u8
*addr
, const u8
*p2p_dev_addr
,
664 if (wpa_auth
->cb
->get_psk
== NULL
)
666 return wpa_auth
->cb
->get_psk(wpa_auth
->cb_ctx
, addr
, p2p_dev_addr
,
667 prev_psk
, NULL
, NULL
);
671 static struct wpa_state_machine
*
672 wpa_ft_add_sta(struct wpa_authenticator
*wpa_auth
, const u8
*sta_addr
)
674 if (wpa_auth
->cb
->add_sta
== NULL
)
676 return wpa_auth
->cb
->add_sta(wpa_auth
->cb_ctx
, sta_addr
);
680 static int wpa_ft_set_vlan(struct wpa_authenticator
*wpa_auth
,
681 const u8
*sta_addr
, struct vlan_description
*vlan
)
683 if (!wpa_auth
->cb
->set_vlan
)
685 return wpa_auth
->cb
->set_vlan(wpa_auth
->cb_ctx
, sta_addr
, vlan
);
689 static int wpa_ft_get_vlan(struct wpa_authenticator
*wpa_auth
,
690 const u8
*sta_addr
, struct vlan_description
*vlan
)
692 if (!wpa_auth
->cb
->get_vlan
)
694 return wpa_auth
->cb
->get_vlan(wpa_auth
->cb_ctx
, sta_addr
, vlan
);
699 wpa_ft_set_identity(struct wpa_authenticator
*wpa_auth
, const u8
*sta_addr
,
700 const u8
*identity
, size_t identity_len
)
702 if (!wpa_auth
->cb
->set_identity
)
704 return wpa_auth
->cb
->set_identity(wpa_auth
->cb_ctx
, sta_addr
, identity
,
710 wpa_ft_get_identity(struct wpa_authenticator
*wpa_auth
, const u8
*sta_addr
,
714 if (!wpa_auth
->cb
->get_identity
)
716 return wpa_auth
->cb
->get_identity(wpa_auth
->cb_ctx
, sta_addr
, buf
);
721 wpa_ft_set_radius_cui(struct wpa_authenticator
*wpa_auth
, const u8
*sta_addr
,
722 const u8
*radius_cui
, size_t radius_cui_len
)
724 if (!wpa_auth
->cb
->set_radius_cui
)
726 return wpa_auth
->cb
->set_radius_cui(wpa_auth
->cb_ctx
, sta_addr
,
727 radius_cui
, radius_cui_len
);
732 wpa_ft_get_radius_cui(struct wpa_authenticator
*wpa_auth
, const u8
*sta_addr
,
736 if (!wpa_auth
->cb
->get_radius_cui
)
738 return wpa_auth
->cb
->get_radius_cui(wpa_auth
->cb_ctx
, sta_addr
, buf
);
743 wpa_ft_set_session_timeout(struct wpa_authenticator
*wpa_auth
,
744 const u8
*sta_addr
, int session_timeout
)
746 if (!wpa_auth
->cb
->set_session_timeout
)
748 wpa_auth
->cb
->set_session_timeout(wpa_auth
->cb_ctx
, sta_addr
,
754 wpa_ft_get_session_timeout(struct wpa_authenticator
*wpa_auth
,
757 if (!wpa_auth
->cb
->get_session_timeout
)
759 return wpa_auth
->cb
->get_session_timeout(wpa_auth
->cb_ctx
, sta_addr
);
763 static int wpa_ft_add_tspec(struct wpa_authenticator
*wpa_auth
,
765 u8
*tspec_ie
, size_t tspec_ielen
)
767 if (wpa_auth
->cb
->add_tspec
== NULL
) {
768 wpa_printf(MSG_DEBUG
, "FT: add_tspec is not initialized");
771 return wpa_auth
->cb
->add_tspec(wpa_auth
->cb_ctx
, sta_addr
, tspec_ie
,
777 static int wpa_channel_info(struct wpa_authenticator
*wpa_auth
,
778 struct wpa_channel_info
*ci
)
780 if (!wpa_auth
->cb
->channel_info
)
782 return wpa_auth
->cb
->channel_info(wpa_auth
->cb_ctx
, ci
);
784 #endif /* CONFIG_OCV */
787 int wpa_write_mdie(struct wpa_auth_config
*conf
, u8
*buf
, size_t len
)
791 if (len
< 2 + sizeof(struct rsn_mdie
))
794 *pos
++ = WLAN_EID_MOBILITY_DOMAIN
;
795 *pos
++ = MOBILITY_DOMAIN_ID_LEN
+ 1;
796 os_memcpy(pos
, conf
->mobility_domain
, MOBILITY_DOMAIN_ID_LEN
);
797 pos
+= MOBILITY_DOMAIN_ID_LEN
;
799 if (conf
->ft_over_ds
)
800 capab
|= RSN_FT_CAPAB_FT_OVER_DS
;
807 int wpa_write_ftie(struct wpa_auth_config
*conf
, int use_sha384
,
808 const u8
*r0kh_id
, size_t r0kh_id_len
,
809 const u8
*anonce
, const u8
*snonce
,
810 u8
*buf
, size_t len
, const u8
*subelem
,
813 u8
*pos
= buf
, *ielen
;
814 size_t hdrlen
= use_sha384
? sizeof(struct rsn_ftie_sha384
) :
815 sizeof(struct rsn_ftie
);
817 if (len
< 2 + hdrlen
+ 2 + FT_R1KH_ID_LEN
+ 2 + r0kh_id_len
+
821 *pos
++ = WLAN_EID_FAST_BSS_TRANSITION
;
825 struct rsn_ftie_sha384
*hdr
= (struct rsn_ftie_sha384
*) pos
;
827 os_memset(hdr
, 0, sizeof(*hdr
));
829 WPA_PUT_LE16(hdr
->mic_control
, 0);
831 os_memcpy(hdr
->anonce
, anonce
, WPA_NONCE_LEN
);
833 os_memcpy(hdr
->snonce
, snonce
, WPA_NONCE_LEN
);
835 struct rsn_ftie
*hdr
= (struct rsn_ftie
*) pos
;
837 os_memset(hdr
, 0, sizeof(*hdr
));
839 WPA_PUT_LE16(hdr
->mic_control
, 0);
841 os_memcpy(hdr
->anonce
, anonce
, WPA_NONCE_LEN
);
843 os_memcpy(hdr
->snonce
, snonce
, WPA_NONCE_LEN
);
846 /* Optional Parameters */
847 *pos
++ = FTIE_SUBELEM_R1KH_ID
;
848 *pos
++ = FT_R1KH_ID_LEN
;
849 os_memcpy(pos
, conf
->r1_key_holder
, FT_R1KH_ID_LEN
);
850 pos
+= FT_R1KH_ID_LEN
;
853 *pos
++ = FTIE_SUBELEM_R0KH_ID
;
854 *pos
++ = r0kh_id_len
;
855 os_memcpy(pos
, r0kh_id
, r0kh_id_len
);
860 os_memcpy(pos
, subelem
, subelem_len
);
864 *ielen
= pos
- buf
- 2;
870 /* A packet to be handled after seq response */
871 struct ft_remote_item
{
874 u8 nonce
[FT_RRB_NONCE_LEN
];
875 struct os_reltime nonce_ts
;
877 u8 src_addr
[ETH_ALEN
];
882 int (*cb
)(struct wpa_authenticator
*wpa_auth
,
884 const u8
*enc
, size_t enc_len
,
885 const u8
*auth
, size_t auth_len
,
890 static void wpa_ft_rrb_seq_free(struct ft_remote_item
*item
)
892 eloop_cancel_timeout(wpa_ft_rrb_seq_timeout
, ELOOP_ALL_CTX
, item
);
893 dl_list_del(&item
->list
);
894 bin_clear_free(item
->enc
, item
->enc_len
);
900 static void wpa_ft_rrb_seq_flush(struct wpa_authenticator
*wpa_auth
,
901 struct ft_remote_seq
*rkh_seq
, int cb
)
903 struct ft_remote_item
*item
, *n
;
905 dl_list_for_each_safe(item
, n
, &rkh_seq
->rx
.queue
,
906 struct ft_remote_item
, list
) {
908 item
->cb(wpa_auth
, item
->src_addr
, item
->enc
,
909 item
->enc_len
, item
->auth
, item
->auth_len
, 1);
910 wpa_ft_rrb_seq_free(item
);
915 static void wpa_ft_rrb_seq_timeout(void *eloop_ctx
, void *timeout_ctx
)
917 struct ft_remote_item
*item
= timeout_ctx
;
919 wpa_ft_rrb_seq_free(item
);
924 wpa_ft_rrb_seq_req(struct wpa_authenticator
*wpa_auth
,
925 struct ft_remote_seq
*rkh_seq
, const u8
*src_addr
,
926 const u8
*f_r0kh_id
, size_t f_r0kh_id_len
,
927 const u8
*f_r1kh_id
, const u8
*key
, size_t key_len
,
928 const u8
*enc
, size_t enc_len
,
929 const u8
*auth
, size_t auth_len
,
930 int (*cb
)(struct wpa_authenticator
*wpa_auth
,
932 const u8
*enc
, size_t enc_len
,
933 const u8
*auth
, size_t auth_len
,
936 struct ft_remote_item
*item
= NULL
;
939 struct tlv_list seq_req_auth
[] = {
940 { .type
= FT_RRB_NONCE
, .len
= FT_RRB_NONCE_LEN
,
941 .data
= NULL
/* to be filled: item->nonce */ },
942 { .type
= FT_RRB_R0KH_ID
, .len
= f_r0kh_id_len
,
944 { .type
= FT_RRB_R1KH_ID
, .len
= FT_R1KH_ID_LEN
,
946 { .type
= FT_RRB_LAST_EMPTY
, .len
= 0, .data
= NULL
},
949 if (dl_list_len(&rkh_seq
->rx
.queue
) >= ftRRBmaxQueueLen
) {
950 wpa_printf(MSG_DEBUG
, "FT: Sequence number queue too long");
954 wpa_printf(MSG_DEBUG
, "FT: Send out sequence number request to " MACSTR
,
956 item
= os_zalloc(sizeof(*item
));
960 os_memcpy(item
->src_addr
, src_addr
, ETH_ALEN
);
963 if (random_get_bytes(item
->nonce
, FT_RRB_NONCE_LEN
) < 0) {
964 wpa_printf(MSG_DEBUG
, "FT: Seq num nonce: out of random bytes");
968 if (os_get_reltime(&item
->nonce_ts
) < 0)
971 if (enc
&& enc_len
> 0) {
972 item
->enc
= os_memdup(enc
, enc_len
);
973 item
->enc_len
= enc_len
;
978 if (auth
&& auth_len
> 0) {
979 item
->auth
= os_memdup(auth
, auth_len
);
980 item
->auth_len
= auth_len
;
985 eloop_register_timeout(ftRRBseqTimeout
, 0, wpa_ft_rrb_seq_timeout
,
988 seq_req_auth
[0].data
= item
->nonce
;
990 if (wpa_ft_rrb_build(key
, key_len
, NULL
, NULL
, seq_req_auth
, NULL
,
991 wpa_auth
->addr
, FT_PACKET_R0KH_R1KH_SEQ_REQ
,
992 &packet
, &packet_len
) < 0) {
993 item
= NULL
; /* some other seq resp might still accept this */
997 dl_list_add(&rkh_seq
->rx
.queue
, &item
->list
);
999 wpa_ft_rrb_oui_send(wpa_auth
, src_addr
, FT_PACKET_R0KH_R1KH_SEQ_REQ
,
1000 packet
, packet_len
);
1006 wpa_printf(MSG_DEBUG
, "FT: Failed to send sequence number request");
1008 os_free(item
->auth
);
1009 bin_clear_free(item
->enc
, item
->enc_len
);
1017 #define FT_RRB_SEQ_OK 0
1018 #define FT_RRB_SEQ_DROP 1
1019 #define FT_RRB_SEQ_DEFER 2
1022 wpa_ft_rrb_seq_chk(struct ft_remote_seq
*rkh_seq
, const u8
*src_addr
,
1023 const u8
*enc
, size_t enc_len
,
1024 const u8
*auth
, size_t auth_len
,
1025 const char *msgtype
, int no_defer
)
1029 const struct ft_rrb_seq
*msg_both
;
1030 u32 msg_seq
, msg_off
, rkh_off
;
1031 struct os_reltime now
;
1034 RRB_GET_AUTH(FT_RRB_SEQ
, seq
, msgtype
, sizeof(*msg_both
));
1035 wpa_hexdump(MSG_DEBUG
, "FT: sequence number", f_seq
, f_seq_len
);
1036 msg_both
= (const struct ft_rrb_seq
*) f_seq
;
1038 if (rkh_seq
->rx
.num_last
== 0) {
1039 /* first packet from remote */
1043 if (le_to_host32(msg_both
->dom
) != rkh_seq
->rx
.dom
) {
1044 /* remote might have rebooted */
1048 if (os_get_reltime(&now
) == 0) {
1049 u32 msg_ts_now_remote
, msg_ts_off
;
1050 struct os_reltime now_remote
;
1052 os_reltime_sub(&now
, &rkh_seq
->rx
.time_offset
, &now_remote
);
1053 msg_ts_now_remote
= now_remote
.sec
;
1054 msg_ts_off
= le_to_host32(msg_both
->ts
) -
1055 (msg_ts_now_remote
- ftRRBseqTimeout
);
1056 if (msg_ts_off
> 2 * ftRRBseqTimeout
)
1060 msg_seq
= le_to_host32(msg_both
->seq
);
1061 rkh_off
= rkh_seq
->rx
.last
[rkh_seq
->rx
.offsetidx
];
1062 msg_off
= msg_seq
- rkh_off
;
1063 if (msg_off
> 0xC0000000)
1064 goto out
; /* too old message, drop it */
1066 if (msg_off
<= 0x40000000) {
1067 for (i
= 0; i
< rkh_seq
->rx
.num_last
; i
++) {
1068 if (rkh_seq
->rx
.last
[i
] == msg_seq
)
1069 goto out
; /* duplicate message, drop it */
1072 return FT_RRB_SEQ_OK
;
1079 wpa_printf(MSG_DEBUG
, "FT: Possibly invalid sequence number in %s from "
1080 MACSTR
, msgtype
, MAC2STR(src_addr
));
1082 return FT_RRB_SEQ_DEFER
;
1084 wpa_printf(MSG_DEBUG
, "FT: Invalid sequence number in %s from " MACSTR
,
1085 msgtype
, MAC2STR(src_addr
));
1087 return FT_RRB_SEQ_DROP
;
1092 wpa_ft_rrb_seq_accept(struct wpa_authenticator
*wpa_auth
,
1093 struct ft_remote_seq
*rkh_seq
, const u8
*src_addr
,
1094 const u8
*auth
, size_t auth_len
,
1095 const char *msgtype
)
1099 const struct ft_rrb_seq
*msg_both
;
1100 u32 msg_seq
, msg_off
, min_off
, rkh_off
;
1104 RRB_GET_AUTH(FT_RRB_SEQ
, seq
, msgtype
, sizeof(*msg_both
));
1105 msg_both
= (const struct ft_rrb_seq
*) f_seq
;
1107 msg_seq
= le_to_host32(msg_both
->seq
);
1109 if (rkh_seq
->rx
.num_last
< FT_REMOTE_SEQ_BACKLOG
) {
1110 rkh_seq
->rx
.last
[rkh_seq
->rx
.num_last
] = msg_seq
;
1111 rkh_seq
->rx
.num_last
++;
1115 rkh_off
= rkh_seq
->rx
.last
[rkh_seq
->rx
.offsetidx
];
1116 for (i
= 0; i
< rkh_seq
->rx
.num_last
; i
++) {
1117 msg_off
= rkh_seq
->rx
.last
[i
] - rkh_off
;
1118 min_off
= rkh_seq
->rx
.last
[minidx
] - rkh_off
;
1119 if (msg_off
< min_off
&& i
!= rkh_seq
->rx
.offsetidx
)
1122 rkh_seq
->rx
.last
[rkh_seq
->rx
.offsetidx
] = msg_seq
;
1123 rkh_seq
->rx
.offsetidx
= minidx
;
1127 /* RRB_GET_AUTH should never fail here as
1128 * wpa_ft_rrb_seq_chk() verified FT_RRB_SEQ presence. */
1129 wpa_printf(MSG_ERROR
, "FT: %s() failed", __func__
);
1133 static int wpa_ft_new_seq(struct ft_remote_seq
*rkh_seq
,
1134 struct ft_rrb_seq
*f_seq
)
1136 struct os_reltime now
;
1138 if (os_get_reltime(&now
) < 0)
1141 if (!rkh_seq
->tx
.dom
) {
1142 if (random_get_bytes((u8
*) &rkh_seq
->tx
.seq
,
1143 sizeof(rkh_seq
->tx
.seq
))) {
1144 wpa_printf(MSG_ERROR
,
1145 "FT: Failed to get random data for sequence number initialization");
1146 rkh_seq
->tx
.seq
= now
.usec
;
1148 if (random_get_bytes((u8
*) &rkh_seq
->tx
.dom
,
1149 sizeof(rkh_seq
->tx
.dom
))) {
1150 wpa_printf(MSG_ERROR
,
1151 "FT: Failed to get random data for sequence number initialization");
1152 rkh_seq
->tx
.dom
= now
.usec
;
1154 rkh_seq
->tx
.dom
|= 1;
1157 f_seq
->dom
= host_to_le32(rkh_seq
->tx
.dom
);
1158 f_seq
->seq
= host_to_le32(rkh_seq
->tx
.seq
);
1159 f_seq
->ts
= host_to_le32(now
.sec
);
1167 struct wpa_ft_pmk_r0_sa
{
1168 struct dl_list list
;
1169 u8 pmk_r0
[PMK_LEN_MAX
];
1171 u8 pmk_r0_name
[WPA_PMK_NAME_LEN
];
1173 int pairwise
; /* Pairwise cipher suite, WPA_CIPHER_* */
1174 struct vlan_description
*vlan
;
1175 os_time_t expiration
; /* 0 for no expiration */
1177 size_t identity_len
;
1179 size_t radius_cui_len
;
1180 os_time_t session_timeout
; /* 0 for no expiration */
1181 /* TODO: radius_class, EAP type */
1185 struct wpa_ft_pmk_r1_sa
{
1186 struct dl_list list
;
1187 u8 pmk_r1
[PMK_LEN_MAX
];
1189 u8 pmk_r1_name
[WPA_PMK_NAME_LEN
];
1191 int pairwise
; /* Pairwise cipher suite, WPA_CIPHER_* */
1192 struct vlan_description
*vlan
;
1194 size_t identity_len
;
1196 size_t radius_cui_len
;
1197 os_time_t session_timeout
; /* 0 for no expiration */
1198 /* TODO: radius_class, EAP type */
1201 struct wpa_ft_pmk_cache
{
1202 struct dl_list pmk_r0
; /* struct wpa_ft_pmk_r0_sa */
1203 struct dl_list pmk_r1
; /* struct wpa_ft_pmk_r1_sa */
1207 static void wpa_ft_expire_pmk_r0(void *eloop_ctx
, void *timeout_ctx
);
1208 static void wpa_ft_expire_pmk_r1(void *eloop_ctx
, void *timeout_ctx
);
1211 static void wpa_ft_free_pmk_r0(struct wpa_ft_pmk_r0_sa
*r0
)
1216 dl_list_del(&r0
->list
);
1217 eloop_cancel_timeout(wpa_ft_expire_pmk_r0
, r0
, NULL
);
1219 os_memset(r0
->pmk_r0
, 0, PMK_LEN_MAX
);
1221 os_free(r0
->identity
);
1222 os_free(r0
->radius_cui
);
1227 static void wpa_ft_expire_pmk_r0(void *eloop_ctx
, void *timeout_ctx
)
1229 struct wpa_ft_pmk_r0_sa
*r0
= eloop_ctx
;
1230 struct os_reltime now
;
1232 int session_timeout
;
1234 os_get_reltime(&now
);
1239 expires_in
= r0
->expiration
- now
.sec
;
1240 session_timeout
= r0
->session_timeout
- now
.sec
;
1241 /* conditions to remove from cache:
1242 * a) r0->expiration is set and hit
1244 * b) r0->session_timeout is set and hit
1246 if ((!r0
->expiration
|| expires_in
> 0) &&
1247 (!r0
->session_timeout
|| session_timeout
> 0)) {
1248 wpa_printf(MSG_ERROR
,
1249 "FT: %s() called for non-expired entry %p",
1251 eloop_cancel_timeout(wpa_ft_expire_pmk_r0
, r0
, NULL
);
1252 if (r0
->expiration
&& expires_in
> 0)
1253 eloop_register_timeout(expires_in
+ 1, 0,
1254 wpa_ft_expire_pmk_r0
, r0
, NULL
);
1255 if (r0
->session_timeout
&& session_timeout
> 0)
1256 eloop_register_timeout(session_timeout
+ 1, 0,
1257 wpa_ft_expire_pmk_r0
, r0
, NULL
);
1261 wpa_ft_free_pmk_r0(r0
);
1265 static void wpa_ft_free_pmk_r1(struct wpa_ft_pmk_r1_sa
*r1
)
1270 dl_list_del(&r1
->list
);
1271 eloop_cancel_timeout(wpa_ft_expire_pmk_r1
, r1
, NULL
);
1273 os_memset(r1
->pmk_r1
, 0, PMK_LEN_MAX
);
1275 os_free(r1
->identity
);
1276 os_free(r1
->radius_cui
);
1281 static void wpa_ft_expire_pmk_r1(void *eloop_ctx
, void *timeout_ctx
)
1283 struct wpa_ft_pmk_r1_sa
*r1
= eloop_ctx
;
1285 wpa_ft_free_pmk_r1(r1
);
1289 struct wpa_ft_pmk_cache
* wpa_ft_pmk_cache_init(void)
1291 struct wpa_ft_pmk_cache
*cache
;
1293 cache
= os_zalloc(sizeof(*cache
));
1295 dl_list_init(&cache
->pmk_r0
);
1296 dl_list_init(&cache
->pmk_r1
);
1303 void wpa_ft_pmk_cache_deinit(struct wpa_ft_pmk_cache
*cache
)
1305 struct wpa_ft_pmk_r0_sa
*r0
, *r0prev
;
1306 struct wpa_ft_pmk_r1_sa
*r1
, *r1prev
;
1308 dl_list_for_each_safe(r0
, r0prev
, &cache
->pmk_r0
,
1309 struct wpa_ft_pmk_r0_sa
, list
)
1310 wpa_ft_free_pmk_r0(r0
);
1312 dl_list_for_each_safe(r1
, r1prev
, &cache
->pmk_r1
,
1313 struct wpa_ft_pmk_r1_sa
, list
)
1314 wpa_ft_free_pmk_r1(r1
);
1320 static int wpa_ft_store_pmk_r0(struct wpa_authenticator
*wpa_auth
,
1321 const u8
*spa
, const u8
*pmk_r0
,
1323 const u8
*pmk_r0_name
, int pairwise
,
1324 const struct vlan_description
*vlan
,
1325 int expires_in
, int session_timeout
,
1326 const u8
*identity
, size_t identity_len
,
1327 const u8
*radius_cui
, size_t radius_cui_len
)
1329 struct wpa_ft_pmk_cache
*cache
= wpa_auth
->ft_pmk_cache
;
1330 struct wpa_ft_pmk_r0_sa
*r0
;
1331 struct os_reltime now
;
1333 /* TODO: add limit on number of entries in cache */
1334 os_get_reltime(&now
);
1336 r0
= os_zalloc(sizeof(*r0
));
1340 os_memcpy(r0
->pmk_r0
, pmk_r0
, pmk_r0_len
);
1341 r0
->pmk_r0_len
= pmk_r0_len
;
1342 os_memcpy(r0
->pmk_r0_name
, pmk_r0_name
, WPA_PMK_NAME_LEN
);
1343 os_memcpy(r0
->spa
, spa
, ETH_ALEN
);
1344 r0
->pairwise
= pairwise
;
1346 r0
->expiration
= now
.sec
+ expires_in
;
1347 if (vlan
&& vlan
->notempty
) {
1348 r0
->vlan
= os_zalloc(sizeof(*vlan
));
1350 bin_clear_free(r0
, sizeof(*r0
));
1356 r0
->identity
= os_malloc(identity_len
);
1358 os_memcpy(r0
->identity
, identity
, identity_len
);
1359 r0
->identity_len
= identity_len
;
1363 r0
->radius_cui
= os_malloc(radius_cui_len
);
1364 if (r0
->radius_cui
) {
1365 os_memcpy(r0
->radius_cui
, radius_cui
, radius_cui_len
);
1366 r0
->radius_cui_len
= radius_cui_len
;
1369 if (session_timeout
> 0)
1370 r0
->session_timeout
= now
.sec
+ session_timeout
;
1372 dl_list_add(&cache
->pmk_r0
, &r0
->list
);
1374 eloop_register_timeout(expires_in
+ 1, 0, wpa_ft_expire_pmk_r0
,
1376 if (session_timeout
> 0)
1377 eloop_register_timeout(session_timeout
+ 1, 0,
1378 wpa_ft_expire_pmk_r0
, r0
, NULL
);
1384 static int wpa_ft_fetch_pmk_r0(struct wpa_authenticator
*wpa_auth
,
1385 const u8
*spa
, const u8
*pmk_r0_name
,
1386 const struct wpa_ft_pmk_r0_sa
**r0_out
)
1388 struct wpa_ft_pmk_cache
*cache
= wpa_auth
->ft_pmk_cache
;
1389 struct wpa_ft_pmk_r0_sa
*r0
;
1390 struct os_reltime now
;
1392 os_get_reltime(&now
);
1393 dl_list_for_each(r0
, &cache
->pmk_r0
, struct wpa_ft_pmk_r0_sa
, list
) {
1394 if (os_memcmp(r0
->spa
, spa
, ETH_ALEN
) == 0 &&
1395 os_memcmp_const(r0
->pmk_r0_name
, pmk_r0_name
,
1396 WPA_PMK_NAME_LEN
) == 0) {
1407 static int wpa_ft_store_pmk_r1(struct wpa_authenticator
*wpa_auth
,
1408 const u8
*spa
, const u8
*pmk_r1
,
1410 const u8
*pmk_r1_name
, int pairwise
,
1411 const struct vlan_description
*vlan
,
1412 int expires_in
, int session_timeout
,
1413 const u8
*identity
, size_t identity_len
,
1414 const u8
*radius_cui
, size_t radius_cui_len
)
1416 struct wpa_ft_pmk_cache
*cache
= wpa_auth
->ft_pmk_cache
;
1417 int max_expires_in
= wpa_auth
->conf
.r1_max_key_lifetime
;
1418 struct wpa_ft_pmk_r1_sa
*r1
;
1419 struct os_reltime now
;
1421 /* TODO: limit on number of entries in cache */
1422 os_get_reltime(&now
);
1424 if (max_expires_in
&& (max_expires_in
< expires_in
|| expires_in
== 0))
1425 expires_in
= max_expires_in
;
1427 r1
= os_zalloc(sizeof(*r1
));
1431 os_memcpy(r1
->pmk_r1
, pmk_r1
, pmk_r1_len
);
1432 r1
->pmk_r1_len
= pmk_r1_len
;
1433 os_memcpy(r1
->pmk_r1_name
, pmk_r1_name
, WPA_PMK_NAME_LEN
);
1434 os_memcpy(r1
->spa
, spa
, ETH_ALEN
);
1435 r1
->pairwise
= pairwise
;
1436 if (vlan
&& vlan
->notempty
) {
1437 r1
->vlan
= os_zalloc(sizeof(*vlan
));
1439 bin_clear_free(r1
, sizeof(*r1
));
1445 r1
->identity
= os_malloc(identity_len
);
1447 os_memcpy(r1
->identity
, identity
, identity_len
);
1448 r1
->identity_len
= identity_len
;
1452 r1
->radius_cui
= os_malloc(radius_cui_len
);
1453 if (r1
->radius_cui
) {
1454 os_memcpy(r1
->radius_cui
, radius_cui
, radius_cui_len
);
1455 r1
->radius_cui_len
= radius_cui_len
;
1458 if (session_timeout
> 0)
1459 r1
->session_timeout
= now
.sec
+ session_timeout
;
1461 dl_list_add(&cache
->pmk_r1
, &r1
->list
);
1464 eloop_register_timeout(expires_in
+ 1, 0, wpa_ft_expire_pmk_r1
,
1466 if (session_timeout
> 0)
1467 eloop_register_timeout(session_timeout
+ 1, 0,
1468 wpa_ft_expire_pmk_r1
, r1
, NULL
);
1474 static int wpa_ft_fetch_pmk_r1(struct wpa_authenticator
*wpa_auth
,
1475 const u8
*spa
, const u8
*pmk_r1_name
,
1476 u8
*pmk_r1
, size_t *pmk_r1_len
, int *pairwise
,
1477 struct vlan_description
*vlan
,
1478 const u8
**identity
, size_t *identity_len
,
1479 const u8
**radius_cui
, size_t *radius_cui_len
,
1480 int *session_timeout
)
1482 struct wpa_ft_pmk_cache
*cache
= wpa_auth
->ft_pmk_cache
;
1483 struct wpa_ft_pmk_r1_sa
*r1
;
1484 struct os_reltime now
;
1486 os_get_reltime(&now
);
1488 dl_list_for_each(r1
, &cache
->pmk_r1
, struct wpa_ft_pmk_r1_sa
, list
) {
1489 if (os_memcmp(r1
->spa
, spa
, ETH_ALEN
) == 0 &&
1490 os_memcmp_const(r1
->pmk_r1_name
, pmk_r1_name
,
1491 WPA_PMK_NAME_LEN
) == 0) {
1492 os_memcpy(pmk_r1
, r1
->pmk_r1
, r1
->pmk_r1_len
);
1493 *pmk_r1_len
= r1
->pmk_r1_len
;
1495 *pairwise
= r1
->pairwise
;
1496 if (vlan
&& r1
->vlan
)
1498 if (vlan
&& !r1
->vlan
)
1499 os_memset(vlan
, 0, sizeof(*vlan
));
1500 if (identity
&& identity_len
) {
1501 *identity
= r1
->identity
;
1502 *identity_len
= r1
->identity_len
;
1504 if (radius_cui
&& radius_cui_len
) {
1505 *radius_cui
= r1
->radius_cui
;
1506 *radius_cui_len
= r1
->radius_cui_len
;
1508 if (session_timeout
&& r1
->session_timeout
> now
.sec
)
1509 *session_timeout
= r1
->session_timeout
-
1511 else if (session_timeout
&& r1
->session_timeout
)
1512 *session_timeout
= 1;
1513 else if (session_timeout
)
1514 *session_timeout
= 0;
1523 static int wpa_ft_rrb_init_r0kh_seq(struct ft_remote_r0kh
*r0kh
)
1528 r0kh
->seq
= os_zalloc(sizeof(*r0kh
->seq
));
1530 wpa_printf(MSG_DEBUG
, "FT: Failed to allocate r0kh->seq");
1534 dl_list_init(&r0kh
->seq
->rx
.queue
);
1540 static void wpa_ft_rrb_lookup_r0kh(struct wpa_authenticator
*wpa_auth
,
1541 const u8
*f_r0kh_id
, size_t f_r0kh_id_len
,
1542 struct ft_remote_r0kh
**r0kh_out
,
1543 struct ft_remote_r0kh
**r0kh_wildcard
)
1545 struct ft_remote_r0kh
*r0kh
;
1547 *r0kh_wildcard
= NULL
;
1550 if (wpa_auth
->conf
.r0kh_list
)
1551 r0kh
= *wpa_auth
->conf
.r0kh_list
;
1554 for (; r0kh
; r0kh
= r0kh
->next
) {
1555 if (r0kh
->id_len
== 1 && r0kh
->id
[0] == '*')
1556 *r0kh_wildcard
= r0kh
;
1557 if (f_r0kh_id
&& r0kh
->id_len
== f_r0kh_id_len
&&
1558 os_memcmp_const(f_r0kh_id
, r0kh
->id
, f_r0kh_id_len
) == 0)
1562 if (!*r0kh_out
&& !*r0kh_wildcard
)
1563 wpa_printf(MSG_DEBUG
, "FT: No matching R0KH found");
1565 if (*r0kh_out
&& wpa_ft_rrb_init_r0kh_seq(*r0kh_out
) < 0)
1570 static int wpa_ft_rrb_init_r1kh_seq(struct ft_remote_r1kh
*r1kh
)
1575 r1kh
->seq
= os_zalloc(sizeof(*r1kh
->seq
));
1577 wpa_printf(MSG_DEBUG
, "FT: Failed to allocate r1kh->seq");
1581 dl_list_init(&r1kh
->seq
->rx
.queue
);
1587 static void wpa_ft_rrb_lookup_r1kh(struct wpa_authenticator
*wpa_auth
,
1588 const u8
*f_r1kh_id
,
1589 struct ft_remote_r1kh
**r1kh_out
,
1590 struct ft_remote_r1kh
**r1kh_wildcard
)
1592 struct ft_remote_r1kh
*r1kh
;
1594 *r1kh_wildcard
= NULL
;
1597 if (wpa_auth
->conf
.r1kh_list
)
1598 r1kh
= *wpa_auth
->conf
.r1kh_list
;
1601 for (; r1kh
; r1kh
= r1kh
->next
) {
1602 if (is_zero_ether_addr(r1kh
->addr
) &&
1603 is_zero_ether_addr(r1kh
->id
))
1604 *r1kh_wildcard
= r1kh
;
1606 os_memcmp_const(r1kh
->id
, f_r1kh_id
, FT_R1KH_ID_LEN
) == 0)
1610 if (!*r1kh_out
&& !*r1kh_wildcard
)
1611 wpa_printf(MSG_DEBUG
, "FT: No matching R1KH found");
1613 if (*r1kh_out
&& wpa_ft_rrb_init_r1kh_seq(*r1kh_out
) < 0)
1618 static int wpa_ft_rrb_check_r0kh(struct wpa_authenticator
*wpa_auth
,
1619 const u8
*f_r0kh_id
, size_t f_r0kh_id_len
)
1621 if (f_r0kh_id_len
!= wpa_auth
->conf
.r0_key_holder_len
||
1622 os_memcmp_const(f_r0kh_id
, wpa_auth
->conf
.r0_key_holder
,
1623 f_r0kh_id_len
) != 0)
1630 static int wpa_ft_rrb_check_r1kh(struct wpa_authenticator
*wpa_auth
,
1631 const u8
*f_r1kh_id
)
1633 if (os_memcmp_const(f_r1kh_id
, wpa_auth
->conf
.r1_key_holder
,
1634 FT_R1KH_ID_LEN
) != 0)
1641 static void wpa_ft_rrb_del_r0kh(void *eloop_ctx
, void *timeout_ctx
)
1643 struct wpa_authenticator
*wpa_auth
= eloop_ctx
;
1644 struct ft_remote_r0kh
*r0kh
, *prev
= NULL
;
1646 if (!wpa_auth
->conf
.r0kh_list
)
1649 for (r0kh
= *wpa_auth
->conf
.r0kh_list
; r0kh
; r0kh
= r0kh
->next
) {
1650 if (r0kh
== timeout_ctx
)
1657 prev
->next
= r0kh
->next
;
1659 *wpa_auth
->conf
.r0kh_list
= r0kh
->next
;
1661 wpa_ft_rrb_seq_flush(wpa_auth
, r0kh
->seq
, 0);
1667 static void wpa_ft_rrb_r0kh_replenish(struct wpa_authenticator
*wpa_auth
,
1668 struct ft_remote_r0kh
*r0kh
, int timeout
)
1671 eloop_replenish_timeout(timeout
, 0, wpa_ft_rrb_del_r0kh
,
1676 static void wpa_ft_rrb_r0kh_timeout(struct wpa_authenticator
*wpa_auth
,
1677 struct ft_remote_r0kh
*r0kh
, int timeout
)
1679 eloop_cancel_timeout(wpa_ft_rrb_del_r0kh
, wpa_auth
, r0kh
);
1682 eloop_register_timeout(timeout
, 0, wpa_ft_rrb_del_r0kh
,
1687 static struct ft_remote_r0kh
*
1688 wpa_ft_rrb_add_r0kh(struct wpa_authenticator
*wpa_auth
,
1689 struct ft_remote_r0kh
*r0kh_wildcard
,
1690 const u8
*src_addr
, const u8
*r0kh_id
, size_t id_len
,
1693 struct ft_remote_r0kh
*r0kh
;
1695 if (!wpa_auth
->conf
.r0kh_list
)
1698 r0kh
= os_zalloc(sizeof(*r0kh
));
1703 os_memcpy(r0kh
->addr
, src_addr
, sizeof(r0kh
->addr
));
1705 if (id_len
> FT_R0KH_ID_MAX_LEN
)
1706 id_len
= FT_R0KH_ID_MAX_LEN
;
1707 os_memcpy(r0kh
->id
, r0kh_id
, id_len
);
1708 r0kh
->id_len
= id_len
;
1710 os_memcpy(r0kh
->key
, r0kh_wildcard
->key
, sizeof(r0kh
->key
));
1712 r0kh
->next
= *wpa_auth
->conf
.r0kh_list
;
1713 *wpa_auth
->conf
.r0kh_list
= r0kh
;
1716 eloop_register_timeout(timeout
, 0, wpa_ft_rrb_del_r0kh
,
1719 if (wpa_ft_rrb_init_r0kh_seq(r0kh
) < 0)
1726 static void wpa_ft_rrb_del_r1kh(void *eloop_ctx
, void *timeout_ctx
)
1728 struct wpa_authenticator
*wpa_auth
= eloop_ctx
;
1729 struct ft_remote_r1kh
*r1kh
, *prev
= NULL
;
1731 if (!wpa_auth
->conf
.r1kh_list
)
1734 for (r1kh
= *wpa_auth
->conf
.r1kh_list
; r1kh
; r1kh
= r1kh
->next
) {
1735 if (r1kh
== timeout_ctx
)
1742 prev
->next
= r1kh
->next
;
1744 *wpa_auth
->conf
.r1kh_list
= r1kh
->next
;
1746 wpa_ft_rrb_seq_flush(wpa_auth
, r1kh
->seq
, 0);
1752 static void wpa_ft_rrb_r1kh_replenish(struct wpa_authenticator
*wpa_auth
,
1753 struct ft_remote_r1kh
*r1kh
, int timeout
)
1756 eloop_replenish_timeout(timeout
, 0, wpa_ft_rrb_del_r1kh
,
1761 static struct ft_remote_r1kh
*
1762 wpa_ft_rrb_add_r1kh(struct wpa_authenticator
*wpa_auth
,
1763 struct ft_remote_r1kh
*r1kh_wildcard
,
1764 const u8
*src_addr
, const u8
*r1kh_id
, int timeout
)
1766 struct ft_remote_r1kh
*r1kh
;
1768 if (!wpa_auth
->conf
.r1kh_list
)
1771 r1kh
= os_zalloc(sizeof(*r1kh
));
1775 os_memcpy(r1kh
->addr
, src_addr
, sizeof(r1kh
->addr
));
1776 os_memcpy(r1kh
->id
, r1kh_id
, sizeof(r1kh
->id
));
1777 os_memcpy(r1kh
->key
, r1kh_wildcard
->key
, sizeof(r1kh
->key
));
1778 r1kh
->next
= *wpa_auth
->conf
.r1kh_list
;
1779 *wpa_auth
->conf
.r1kh_list
= r1kh
;
1782 eloop_register_timeout(timeout
, 0, wpa_ft_rrb_del_r1kh
,
1785 if (wpa_ft_rrb_init_r1kh_seq(r1kh
) < 0)
1792 void wpa_ft_sta_deinit(struct wpa_state_machine
*sm
)
1794 eloop_cancel_timeout(wpa_ft_expire_pull
, sm
, NULL
);
1798 static void wpa_ft_deinit_seq(struct wpa_authenticator
*wpa_auth
)
1800 struct ft_remote_r0kh
*r0kh
;
1801 struct ft_remote_r1kh
*r1kh
;
1803 eloop_cancel_timeout(wpa_ft_rrb_seq_timeout
, wpa_auth
, ELOOP_ALL_CTX
);
1805 if (wpa_auth
->conf
.r0kh_list
)
1806 r0kh
= *wpa_auth
->conf
.r0kh_list
;
1809 for (; r0kh
; r0kh
= r0kh
->next
) {
1812 wpa_ft_rrb_seq_flush(wpa_auth
, r0kh
->seq
, 0);
1817 if (wpa_auth
->conf
.r1kh_list
)
1818 r1kh
= *wpa_auth
->conf
.r1kh_list
;
1821 for (; r1kh
; r1kh
= r1kh
->next
) {
1824 wpa_ft_rrb_seq_flush(wpa_auth
, r1kh
->seq
, 0);
1831 static void wpa_ft_deinit_rkh_tmp(struct wpa_authenticator
*wpa_auth
)
1833 struct ft_remote_r0kh
*r0kh
, *r0kh_next
, *r0kh_prev
= NULL
;
1834 struct ft_remote_r1kh
*r1kh
, *r1kh_next
, *r1kh_prev
= NULL
;
1836 if (wpa_auth
->conf
.r0kh_list
)
1837 r0kh
= *wpa_auth
->conf
.r0kh_list
;
1841 r0kh_next
= r0kh
->next
;
1842 if (eloop_cancel_timeout(wpa_ft_rrb_del_r0kh
, wpa_auth
,
1845 r0kh_prev
->next
= r0kh_next
;
1847 *wpa_auth
->conf
.r0kh_list
= r0kh_next
;
1855 if (wpa_auth
->conf
.r1kh_list
)
1856 r1kh
= *wpa_auth
->conf
.r1kh_list
;
1860 r1kh_next
= r1kh
->next
;
1861 if (eloop_cancel_timeout(wpa_ft_rrb_del_r1kh
, wpa_auth
,
1864 r1kh_prev
->next
= r1kh_next
;
1866 *wpa_auth
->conf
.r1kh_list
= r1kh_next
;
1876 void wpa_ft_deinit(struct wpa_authenticator
*wpa_auth
)
1878 wpa_ft_deinit_seq(wpa_auth
);
1879 wpa_ft_deinit_rkh_tmp(wpa_auth
);
1883 static void wpa_ft_block_r0kh(struct wpa_authenticator
*wpa_auth
,
1884 const u8
*f_r0kh_id
, size_t f_r0kh_id_len
)
1886 struct ft_remote_r0kh
*r0kh
, *r0kh_wildcard
;
1888 if (!wpa_auth
->conf
.rkh_neg_timeout
)
1891 wpa_ft_rrb_lookup_r0kh(wpa_auth
, f_r0kh_id
, f_r0kh_id_len
,
1892 &r0kh
, &r0kh_wildcard
);
1894 if (!r0kh_wildcard
) {
1895 /* r0kh removed after neg_timeout and might need re-adding */
1899 wpa_hexdump(MSG_DEBUG
, "FT: Blacklist R0KH-ID",
1900 f_r0kh_id
, f_r0kh_id_len
);
1903 wpa_ft_rrb_r0kh_timeout(wpa_auth
, r0kh
,
1904 wpa_auth
->conf
.rkh_neg_timeout
);
1905 os_memset(r0kh
->addr
, 0, ETH_ALEN
);
1907 wpa_ft_rrb_add_r0kh(wpa_auth
, r0kh_wildcard
, NULL
, f_r0kh_id
,
1909 wpa_auth
->conf
.rkh_neg_timeout
);
1913 static void wpa_ft_expire_pull(void *eloop_ctx
, void *timeout_ctx
)
1915 struct wpa_state_machine
*sm
= eloop_ctx
;
1917 wpa_printf(MSG_DEBUG
, "FT: Timeout pending pull request for " MACSTR
,
1919 if (sm
->ft_pending_pull_left_retries
<= 0)
1920 wpa_ft_block_r0kh(sm
->wpa_auth
, sm
->r0kh_id
, sm
->r0kh_id_len
);
1922 /* cancel multiple timeouts */
1923 eloop_cancel_timeout(wpa_ft_expire_pull
, sm
, NULL
);
1928 static int wpa_ft_pull_pmk_r1(struct wpa_state_machine
*sm
,
1929 const u8
*ies
, size_t ies_len
,
1930 const u8
*pmk_r0_name
)
1932 struct ft_remote_r0kh
*r0kh
, *r0kh_wildcard
;
1934 const u8
*key
, *f_r1kh_id
= sm
->wpa_auth
->conf
.r1_key_holder
;
1935 size_t packet_len
, key_len
;
1936 struct ft_rrb_seq f_seq
;
1937 int tsecs
, tusecs
, first
;
1938 struct wpabuf
*ft_pending_req_ies
;
1940 struct tlv_list req_enc
[] = {
1941 { .type
= FT_RRB_PMK_R0_NAME
, .len
= WPA_PMK_NAME_LEN
,
1942 .data
= pmk_r0_name
},
1943 { .type
= FT_RRB_S1KH_ID
, .len
= ETH_ALEN
,
1945 { .type
= FT_RRB_LAST_EMPTY
, .len
= 0, .data
= NULL
},
1947 struct tlv_list req_auth
[] = {
1948 { .type
= FT_RRB_NONCE
, .len
= FT_RRB_NONCE_LEN
,
1949 .data
= sm
->ft_pending_pull_nonce
},
1950 { .type
= FT_RRB_SEQ
, .len
= sizeof(f_seq
),
1951 .data
= (u8
*) &f_seq
},
1952 { .type
= FT_RRB_R0KH_ID
, .len
= sm
->r0kh_id_len
,
1953 .data
= sm
->r0kh_id
},
1954 { .type
= FT_RRB_R1KH_ID
, .len
= FT_R1KH_ID_LEN
,
1955 .data
= f_r1kh_id
},
1956 { .type
= FT_RRB_LAST_EMPTY
, .len
= 0, .data
= NULL
},
1959 if (sm
->ft_pending_pull_left_retries
<= 0)
1961 first
= sm
->ft_pending_pull_left_retries
==
1962 sm
->wpa_auth
->conf
.rkh_pull_retries
;
1963 sm
->ft_pending_pull_left_retries
--;
1965 wpa_ft_rrb_lookup_r0kh(sm
->wpa_auth
, sm
->r0kh_id
, sm
->r0kh_id_len
,
1966 &r0kh
, &r0kh_wildcard
);
1968 /* Keep r0kh sufficiently long in the list for seq num check */
1969 r0kh_timeout
= sm
->wpa_auth
->conf
.rkh_pull_timeout
/ 1000 +
1970 1 + ftRRBseqTimeout
;
1972 wpa_ft_rrb_r0kh_replenish(sm
->wpa_auth
, r0kh
, r0kh_timeout
);
1973 } else if (r0kh_wildcard
) {
1974 wpa_printf(MSG_DEBUG
, "FT: Using wildcard R0KH-ID");
1975 /* r0kh->addr: updated by SEQ_RESP and wpa_ft_expire_pull */
1976 r0kh
= wpa_ft_rrb_add_r0kh(sm
->wpa_auth
, r0kh_wildcard
,
1977 r0kh_wildcard
->addr
,
1978 sm
->r0kh_id
, sm
->r0kh_id_len
,
1982 wpa_hexdump(MSG_DEBUG
, "FT: Did not find R0KH-ID",
1983 sm
->r0kh_id
, sm
->r0kh_id_len
);
1986 if (is_zero_ether_addr(r0kh
->addr
)) {
1987 wpa_hexdump(MSG_DEBUG
, "FT: R0KH-ID is blacklisted",
1988 sm
->r0kh_id
, sm
->r0kh_id_len
);
1991 if (os_memcmp(r0kh
->addr
, sm
->wpa_auth
->addr
, ETH_ALEN
) == 0) {
1992 wpa_printf(MSG_DEBUG
,
1993 "FT: R0KH-ID points to self - no matching key available");
1998 key_len
= sizeof(r0kh
->key
);
2000 wpa_printf(MSG_DEBUG
, "FT: Send PMK-R1 pull request to remote R0KH "
2001 "address " MACSTR
, MAC2STR(r0kh
->addr
));
2003 if (r0kh
->seq
->rx
.num_last
== 0) {
2004 /* A sequence request will be sent out anyway when pull
2005 * response is received. Send it out now to avoid one RTT. */
2006 wpa_ft_rrb_seq_req(sm
->wpa_auth
, r0kh
->seq
, r0kh
->addr
,
2007 r0kh
->id
, r0kh
->id_len
, f_r1kh_id
, key
,
2008 key_len
, NULL
, 0, NULL
, 0, NULL
);
2012 random_get_bytes(sm
->ft_pending_pull_nonce
, FT_RRB_NONCE_LEN
) < 0) {
2013 wpa_printf(MSG_DEBUG
, "FT: Failed to get random data for "
2018 if (wpa_ft_new_seq(r0kh
->seq
, &f_seq
) < 0) {
2019 wpa_printf(MSG_DEBUG
, "FT: Failed to get seq num");
2023 if (wpa_ft_rrb_build(key
, key_len
, req_enc
, NULL
, req_auth
, NULL
,
2024 sm
->wpa_auth
->addr
, FT_PACKET_R0KH_R1KH_PULL
,
2025 &packet
, &packet_len
) < 0)
2028 ft_pending_req_ies
= wpabuf_alloc_copy(ies
, ies_len
);
2029 wpabuf_free(sm
->ft_pending_req_ies
);
2030 sm
->ft_pending_req_ies
= ft_pending_req_ies
;
2031 if (!sm
->ft_pending_req_ies
) {
2036 tsecs
= sm
->wpa_auth
->conf
.rkh_pull_timeout
/ 1000;
2037 tusecs
= (sm
->wpa_auth
->conf
.rkh_pull_timeout
% 1000) * 1000;
2038 eloop_register_timeout(tsecs
, tusecs
, wpa_ft_expire_pull
, sm
, NULL
);
2040 wpa_ft_rrb_oui_send(sm
->wpa_auth
, r0kh
->addr
, FT_PACKET_R0KH_R1KH_PULL
,
2041 packet
, packet_len
);
2049 int wpa_ft_store_pmk_fils(struct wpa_state_machine
*sm
,
2050 const u8
*pmk_r0
, const u8
*pmk_r0_name
)
2052 int expires_in
= sm
->wpa_auth
->conf
.r0_key_lifetime
;
2053 struct vlan_description vlan
;
2054 const u8
*identity
, *radius_cui
;
2055 size_t identity_len
, radius_cui_len
;
2056 int session_timeout
;
2057 size_t pmk_r0_len
= wpa_key_mgmt_sha384(sm
->wpa_key_mgmt
) ?
2058 SHA384_MAC_LEN
: PMK_LEN
;
2060 if (wpa_ft_get_vlan(sm
->wpa_auth
, sm
->addr
, &vlan
) < 0) {
2061 wpa_printf(MSG_DEBUG
, "FT: vlan not available for STA " MACSTR
,
2066 identity_len
= wpa_ft_get_identity(sm
->wpa_auth
, sm
->addr
, &identity
);
2067 radius_cui_len
= wpa_ft_get_radius_cui(sm
->wpa_auth
, sm
->addr
,
2069 session_timeout
= wpa_ft_get_session_timeout(sm
->wpa_auth
, sm
->addr
);
2071 return wpa_ft_store_pmk_r0(sm
->wpa_auth
, sm
->addr
, pmk_r0
, pmk_r0_len
,
2072 pmk_r0_name
, sm
->pairwise
, &vlan
, expires_in
,
2073 session_timeout
, identity
, identity_len
,
2074 radius_cui
, radius_cui_len
);
2078 int wpa_auth_derive_ptk_ft(struct wpa_state_machine
*sm
, struct wpa_ptk
*ptk
)
2080 u8 pmk_r0
[PMK_LEN_MAX
], pmk_r0_name
[WPA_PMK_NAME_LEN
];
2081 size_t pmk_r0_len
= wpa_key_mgmt_sha384(sm
->wpa_key_mgmt
) ?
2082 SHA384_MAC_LEN
: PMK_LEN
;
2083 size_t pmk_r1_len
= pmk_r0_len
;
2084 u8 pmk_r1
[PMK_LEN_MAX
];
2085 u8 ptk_name
[WPA_PMK_NAME_LEN
];
2086 const u8
*mdid
= sm
->wpa_auth
->conf
.mobility_domain
;
2087 const u8
*r0kh
= sm
->wpa_auth
->conf
.r0_key_holder
;
2088 size_t r0kh_len
= sm
->wpa_auth
->conf
.r0_key_holder_len
;
2089 const u8
*r1kh
= sm
->wpa_auth
->conf
.r1_key_holder
;
2090 const u8
*ssid
= sm
->wpa_auth
->conf
.ssid
;
2091 size_t ssid_len
= sm
->wpa_auth
->conf
.ssid_len
;
2092 int psk_local
= sm
->wpa_auth
->conf
.ft_psk_generate_local
;
2093 int expires_in
= sm
->wpa_auth
->conf
.r0_key_lifetime
;
2094 struct vlan_description vlan
;
2095 const u8
*identity
, *radius_cui
;
2096 size_t identity_len
, radius_cui_len
;
2097 int session_timeout
;
2101 if (sm
->xxkey_len
> 0) {
2103 mpmk_len
= sm
->xxkey_len
;
2104 } else if (sm
->pmksa
) {
2105 mpmk
= sm
->pmksa
->pmk
;
2106 mpmk_len
= sm
->pmksa
->pmk_len
;
2108 wpa_printf(MSG_DEBUG
, "FT: XXKey not available for key "
2113 if (wpa_ft_get_vlan(sm
->wpa_auth
, sm
->addr
, &vlan
) < 0) {
2114 wpa_printf(MSG_DEBUG
, "FT: vlan not available for STA " MACSTR
,
2119 identity_len
= wpa_ft_get_identity(sm
->wpa_auth
, sm
->addr
, &identity
);
2120 radius_cui_len
= wpa_ft_get_radius_cui(sm
->wpa_auth
, sm
->addr
,
2122 session_timeout
= wpa_ft_get_session_timeout(sm
->wpa_auth
, sm
->addr
);
2124 if (wpa_derive_pmk_r0(mpmk
, mpmk_len
, ssid
, ssid_len
, mdid
,
2125 r0kh
, r0kh_len
, sm
->addr
,
2126 pmk_r0
, pmk_r0_name
,
2127 wpa_key_mgmt_sha384(sm
->wpa_key_mgmt
)) < 0)
2129 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R0", pmk_r0
, pmk_r0_len
);
2130 wpa_hexdump(MSG_DEBUG
, "FT: PMKR0Name", pmk_r0_name
, WPA_PMK_NAME_LEN
);
2131 if (!psk_local
|| !wpa_key_mgmt_ft_psk(sm
->wpa_key_mgmt
))
2132 wpa_ft_store_pmk_r0(sm
->wpa_auth
, sm
->addr
, pmk_r0
, pmk_r0_len
,
2134 sm
->pairwise
, &vlan
, expires_in
,
2135 session_timeout
, identity
, identity_len
,
2136 radius_cui
, radius_cui_len
);
2138 if (wpa_derive_pmk_r1(pmk_r0
, pmk_r0_len
, pmk_r0_name
, r1kh
, sm
->addr
,
2139 pmk_r1
, sm
->pmk_r1_name
) < 0)
2141 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1", pmk_r1
, pmk_r1_len
);
2142 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name", sm
->pmk_r1_name
,
2144 if (!psk_local
|| !wpa_key_mgmt_ft_psk(sm
->wpa_key_mgmt
))
2145 wpa_ft_store_pmk_r1(sm
->wpa_auth
, sm
->addr
, pmk_r1
, pmk_r1_len
,
2146 sm
->pmk_r1_name
, sm
->pairwise
, &vlan
,
2147 expires_in
, session_timeout
, identity
,
2148 identity_len
, radius_cui
, radius_cui_len
);
2150 return wpa_pmk_r1_to_ptk(pmk_r1
, pmk_r1_len
, sm
->SNonce
, sm
->ANonce
,
2151 sm
->addr
, sm
->wpa_auth
->addr
, sm
->pmk_r1_name
,
2152 ptk
, ptk_name
, sm
->wpa_key_mgmt
, sm
->pairwise
);
2156 static inline int wpa_auth_get_seqnum(struct wpa_authenticator
*wpa_auth
,
2157 const u8
*addr
, int idx
, u8
*seq
)
2159 if (wpa_auth
->cb
->get_seqnum
== NULL
)
2161 return wpa_auth
->cb
->get_seqnum(wpa_auth
->cb_ctx
, addr
, idx
, seq
);
2165 static u8
* wpa_ft_gtk_subelem(struct wpa_state_machine
*sm
, size_t *len
)
2168 struct wpa_group
*gsm
= sm
->group
;
2169 size_t subelem_len
, pad_len
;
2176 if (wpa_key_mgmt_fils(sm
->wpa_key_mgmt
)) {
2178 kek_len
= sm
->PTK
.kek2_len
;
2181 kek_len
= sm
->PTK
.kek_len
;
2184 key_len
= gsm
->GTK_len
;
2185 if (key_len
> sizeof(keybuf
))
2189 * Pad key for AES Key Wrap if it is not multiple of 8 bytes or is less
2192 pad_len
= key_len
% 8;
2194 pad_len
= 8 - pad_len
;
2195 if (key_len
+ pad_len
< 16)
2197 if (pad_len
&& key_len
< sizeof(keybuf
)) {
2198 os_memcpy(keybuf
, gsm
->GTK
[gsm
->GN
- 1], key_len
);
2199 os_memset(keybuf
+ key_len
, 0, pad_len
);
2200 keybuf
[key_len
] = 0xdd;
2204 key
= gsm
->GTK
[gsm
->GN
- 1];
2207 * Sub-elem ID[1] | Length[1] | Key Info[2] | Key Length[1] | RSC[8] |
2210 subelem_len
= 13 + key_len
+ 8;
2211 subelem
= os_zalloc(subelem_len
);
2212 if (subelem
== NULL
)
2215 subelem
[0] = FTIE_SUBELEM_GTK
;
2216 subelem
[1] = 11 + key_len
+ 8;
2217 /* Key ID in B0-B1 of Key Info */
2218 WPA_PUT_LE16(&subelem
[2], gsm
->GN
& 0x03);
2219 subelem
[4] = gsm
->GTK_len
;
2220 wpa_auth_get_seqnum(sm
->wpa_auth
, NULL
, gsm
->GN
, subelem
+ 5);
2221 if (aes_wrap(kek
, kek_len
, key_len
/ 8, key
, subelem
+ 13)) {
2222 wpa_printf(MSG_DEBUG
,
2223 "FT: GTK subelem encryption failed: kek_len=%d",
2229 forced_memzero(keybuf
, sizeof(keybuf
));
2235 static u8
* wpa_ft_igtk_subelem(struct wpa_state_machine
*sm
, size_t *len
)
2238 struct wpa_group
*gsm
= sm
->group
;
2244 if (wpa_key_mgmt_fils(sm
->wpa_key_mgmt
)) {
2246 kek_len
= sm
->PTK
.kek2_len
;
2249 kek_len
= sm
->PTK
.kek_len
;
2252 igtk_len
= wpa_cipher_key_len(sm
->wpa_auth
->conf
.group_mgmt_cipher
);
2254 /* Sub-elem ID[1] | Length[1] | KeyID[2] | IPN[6] | Key Length[1] |
2256 subelem_len
= 1 + 1 + 2 + 6 + 1 + igtk_len
+ 8;
2257 subelem
= os_zalloc(subelem_len
);
2258 if (subelem
== NULL
)
2262 *pos
++ = FTIE_SUBELEM_IGTK
;
2263 *pos
++ = subelem_len
- 2;
2264 WPA_PUT_LE16(pos
, gsm
->GN_igtk
);
2266 wpa_auth_get_seqnum(sm
->wpa_auth
, NULL
, gsm
->GN_igtk
, pos
);
2269 if (aes_wrap(kek
, kek_len
, igtk_len
/ 8,
2270 gsm
->IGTK
[gsm
->GN_igtk
- 4], pos
)) {
2271 wpa_printf(MSG_DEBUG
,
2272 "FT: IGTK subelem encryption failed: kek_len=%d",
2283 static u8
* wpa_ft_process_rdie(struct wpa_state_machine
*sm
,
2284 u8
*pos
, u8
*end
, u8 id
, u8 descr_count
,
2285 const u8
*ies
, size_t ies_len
)
2287 struct ieee802_11_elems parse
;
2288 struct rsn_rdie
*rdie
;
2290 wpa_printf(MSG_DEBUG
, "FT: Resource Request: id=%d descr_count=%d",
2292 wpa_hexdump(MSG_MSGDUMP
, "FT: Resource descriptor IE(s)",
2295 if (end
- pos
< (int) sizeof(*rdie
)) {
2296 wpa_printf(MSG_ERROR
, "FT: Not enough room for response RDIE");
2300 *pos
++ = WLAN_EID_RIC_DATA
;
2301 *pos
++ = sizeof(*rdie
);
2302 rdie
= (struct rsn_rdie
*) pos
;
2304 rdie
->descr_count
= 0;
2305 rdie
->status_code
= host_to_le16(WLAN_STATUS_SUCCESS
);
2306 pos
+= sizeof(*rdie
);
2308 if (ieee802_11_parse_elems((u8
*) ies
, ies_len
, &parse
, 1) ==
2310 wpa_printf(MSG_DEBUG
, "FT: Failed to parse request IEs");
2312 host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE
);
2316 if (parse
.wmm_tspec
) {
2317 struct wmm_tspec_element
*tspec
;
2319 if (parse
.wmm_tspec_len
+ 2 < (int) sizeof(*tspec
)) {
2320 wpa_printf(MSG_DEBUG
, "FT: Too short WMM TSPEC IE "
2321 "(%d)", (int) parse
.wmm_tspec_len
);
2323 host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE
);
2326 if (end
- pos
< (int) sizeof(*tspec
)) {
2327 wpa_printf(MSG_ERROR
, "FT: Not enough room for "
2330 host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE
);
2333 tspec
= (struct wmm_tspec_element
*) pos
;
2334 os_memcpy(tspec
, parse
.wmm_tspec
- 2, sizeof(*tspec
));
2338 if (parse
.wmm_tspec
&& sm
->wpa_auth
->conf
.ap_mlme
) {
2341 res
= wmm_process_tspec((struct wmm_tspec_element
*) pos
);
2342 wpa_printf(MSG_DEBUG
, "FT: ADDTS processing result: %d", res
);
2343 if (res
== WMM_ADDTS_STATUS_INVALID_PARAMETERS
)
2345 host_to_le16(WLAN_STATUS_INVALID_PARAMETERS
);
2346 else if (res
== WMM_ADDTS_STATUS_REFUSED
)
2348 host_to_le16(WLAN_STATUS_REQUEST_DECLINED
);
2350 /* TSPEC accepted; include updated TSPEC in response */
2351 rdie
->descr_count
= 1;
2352 pos
+= sizeof(struct wmm_tspec_element
);
2356 #endif /* NEED_AP_MLME */
2358 if (parse
.wmm_tspec
&& !sm
->wpa_auth
->conf
.ap_mlme
) {
2361 res
= wpa_ft_add_tspec(sm
->wpa_auth
, sm
->addr
, pos
,
2362 sizeof(struct wmm_tspec_element
));
2365 rdie
->status_code
= host_to_le16(res
);
2367 /* TSPEC accepted; include updated TSPEC in
2369 rdie
->descr_count
= 1;
2370 pos
+= sizeof(struct wmm_tspec_element
);
2376 wpa_printf(MSG_DEBUG
, "FT: No supported resource requested");
2377 rdie
->status_code
= host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE
);
2382 static u8
* wpa_ft_process_ric(struct wpa_state_machine
*sm
, u8
*pos
, u8
*end
,
2383 const u8
*ric
, size_t ric_len
)
2385 const u8
*rpos
, *start
;
2386 const struct rsn_rdie
*rdie
;
2388 wpa_hexdump(MSG_MSGDUMP
, "FT: RIC Request", ric
, ric_len
);
2391 while (rpos
+ sizeof(*rdie
) < ric
+ ric_len
) {
2392 if (rpos
[0] != WLAN_EID_RIC_DATA
|| rpos
[1] < sizeof(*rdie
) ||
2393 rpos
+ 2 + rpos
[1] > ric
+ ric_len
)
2395 rdie
= (const struct rsn_rdie
*) (rpos
+ 2);
2396 rpos
+= 2 + rpos
[1];
2399 while (rpos
+ 2 <= ric
+ ric_len
&&
2400 rpos
+ 2 + rpos
[1] <= ric
+ ric_len
) {
2401 if (rpos
[0] == WLAN_EID_RIC_DATA
)
2403 rpos
+= 2 + rpos
[1];
2405 pos
= wpa_ft_process_rdie(sm
, pos
, end
, rdie
->id
,
2407 start
, rpos
- start
);
2414 u8
* wpa_sm_write_assoc_resp_ies(struct wpa_state_machine
*sm
, u8
*pos
,
2415 size_t max_len
, int auth_alg
,
2416 const u8
*req_ies
, size_t req_ies_len
)
2418 u8
*end
, *mdie
, *ftie
, *rsnie
= NULL
, *r0kh_id
, *subelem
= NULL
;
2419 u8
*fte_mic
, *elem_count
;
2420 size_t mdie_len
, ftie_len
, rsnie_len
= 0, r0kh_id_len
, subelem_len
= 0;
2424 struct wpa_auth_config
*conf
;
2425 struct wpa_ft_ies parse
;
2427 u8
*anonce
, *snonce
;
2435 use_sha384
= wpa_key_mgmt_sha384(sm
->wpa_key_mgmt
);
2436 conf
= &sm
->wpa_auth
->conf
;
2438 if (!wpa_key_mgmt_ft(sm
->wpa_key_mgmt
))
2441 end
= pos
+ max_len
;
2443 if (auth_alg
== WLAN_AUTH_FT
||
2444 ((auth_alg
== WLAN_AUTH_FILS_SK
||
2445 auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
2446 auth_alg
== WLAN_AUTH_FILS_PK
) &&
2447 (sm
->wpa_key_mgmt
& (WPA_KEY_MGMT_FT_FILS_SHA256
|
2448 WPA_KEY_MGMT_FT_FILS_SHA384
)))) {
2449 if (!sm
->pmk_r1_name_valid
) {
2450 wpa_printf(MSG_ERROR
,
2451 "FT: PMKR1Name is not valid for Assoc Resp RSNE");
2454 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name for Assoc Resp RSNE",
2455 sm
->pmk_r1_name
, WPA_PMK_NAME_LEN
);
2457 * RSN (only present if this is a Reassociation Response and
2458 * part of a fast BSS transition; or if this is a
2459 * (Re)Association Response frame during an FT initial mobility
2460 * domain association using FILS)
2462 res
= wpa_write_rsn_ie(conf
, pos
, end
- pos
, sm
->pmk_r1_name
);
2470 /* Mobility Domain Information */
2471 res
= wpa_write_mdie(conf
, pos
, end
- pos
);
2478 /* Fast BSS Transition Information */
2479 if (auth_alg
== WLAN_AUTH_FT
) {
2480 subelem
= wpa_ft_gtk_subelem(sm
, &subelem_len
);
2482 wpa_printf(MSG_DEBUG
,
2483 "FT: Failed to add GTK subelement");
2486 r0kh_id
= sm
->r0kh_id
;
2487 r0kh_id_len
= sm
->r0kh_id_len
;
2488 anonce
= sm
->ANonce
;
2489 snonce
= sm
->SNonce
;
2490 if (sm
->mgmt_frame_prot
) {
2494 igtk
= wpa_ft_igtk_subelem(sm
, &igtk_len
);
2496 wpa_printf(MSG_DEBUG
,
2497 "FT: Failed to add IGTK subelement");
2501 nbuf
= os_realloc(subelem
, subelem_len
+ igtk_len
);
2508 os_memcpy(subelem
+ subelem_len
, igtk
, igtk_len
);
2509 subelem_len
+= igtk_len
;
2513 if (wpa_auth_uses_ocv(sm
)) {
2514 struct wpa_channel_info ci
;
2517 if (wpa_channel_info(sm
->wpa_auth
, &ci
) != 0) {
2518 wpa_printf(MSG_WARNING
,
2519 "Failed to get channel info for OCI element");
2524 subelem_len
+= 2 + OCV_OCI_LEN
;
2525 nbuf
= os_realloc(subelem
, subelem_len
);
2532 ocipos
= subelem
+ subelem_len
- 2 - OCV_OCI_LEN
;
2533 *ocipos
++ = FTIE_SUBELEM_OCI
;
2534 *ocipos
++ = OCV_OCI_LEN
;
2535 if (ocv_insert_oci(&ci
, &ocipos
) < 0) {
2540 #endif /* CONFIG_OCV */
2542 r0kh_id
= conf
->r0_key_holder
;
2543 r0kh_id_len
= conf
->r0_key_holder_len
;
2547 res
= wpa_write_ftie(conf
, use_sha384
, r0kh_id
, r0kh_id_len
,
2548 anonce
, snonce
, pos
, end
- pos
,
2549 subelem
, subelem_len
);
2558 struct rsn_ftie_sha384
*_ftie
=
2559 (struct rsn_ftie_sha384
*) (ftie
+ 2);
2561 fte_mic
= _ftie
->mic
;
2562 elem_count
= &_ftie
->mic_control
[1];
2564 struct rsn_ftie
*_ftie
= (struct rsn_ftie
*) (ftie
+ 2);
2566 fte_mic
= _ftie
->mic
;
2567 elem_count
= &_ftie
->mic_control
[1];
2569 if (auth_alg
== WLAN_AUTH_FT
)
2570 *elem_count
= 3; /* Information element count */
2573 if (wpa_ft_parse_ies(req_ies
, req_ies_len
, &parse
, use_sha384
) == 0
2575 pos
= wpa_ft_process_ric(sm
, pos
, end
, parse
.ric
,
2577 if (auth_alg
== WLAN_AUTH_FT
)
2579 ieee802_11_ie_count(ric_start
,
2582 if (ric_start
== pos
)
2585 res
= wpa_write_rsnxe(&sm
->wpa_auth
->conf
, rsnxe
, sizeof(rsnxe
));
2589 if (auth_alg
== WLAN_AUTH_FT
&& rsnxe_len
)
2592 if (wpa_key_mgmt_fils(sm
->wpa_key_mgmt
)) {
2594 kck_len
= sm
->PTK
.kck2_len
;
2597 kck_len
= sm
->PTK
.kck_len
;
2599 if (auth_alg
== WLAN_AUTH_FT
&&
2600 wpa_ft_mic(kck
, kck_len
, sm
->addr
, sm
->wpa_auth
->addr
, 6,
2601 mdie
, mdie_len
, ftie
, ftie_len
,
2603 ric_start
, ric_start
? pos
- ric_start
: 0,
2604 rsnxe_len
? rsnxe
: NULL
, rsnxe_len
,
2606 wpa_printf(MSG_DEBUG
, "FT: Failed to calculate MIC");
2610 os_free(sm
->assoc_resp_ftie
);
2611 sm
->assoc_resp_ftie
= os_malloc(ftie_len
);
2612 if (!sm
->assoc_resp_ftie
)
2614 os_memcpy(sm
->assoc_resp_ftie
, ftie
, ftie_len
);
2620 static inline int wpa_auth_set_key(struct wpa_authenticator
*wpa_auth
,
2622 enum wpa_alg alg
, const u8
*addr
, int idx
,
2623 u8
*key
, size_t key_len
)
2625 if (wpa_auth
->cb
->set_key
== NULL
)
2627 return wpa_auth
->cb
->set_key(wpa_auth
->cb_ctx
, vlan_id
, alg
, addr
, idx
,
2632 void wpa_ft_install_ptk(struct wpa_state_machine
*sm
)
2637 /* MLME-SETKEYS.request(PTK) */
2638 alg
= wpa_cipher_to_alg(sm
->pairwise
);
2639 klen
= wpa_cipher_key_len(sm
->pairwise
);
2640 if (!wpa_cipher_valid_pairwise(sm
->pairwise
)) {
2641 wpa_printf(MSG_DEBUG
, "FT: Unknown pairwise alg 0x%x - skip "
2642 "PTK configuration", sm
->pairwise
);
2646 if (sm
->tk_already_set
) {
2647 /* Must avoid TK reconfiguration to prevent clearing of TX/RX
2648 * PN in the driver */
2649 wpa_printf(MSG_DEBUG
,
2650 "FT: Do not re-install same PTK to the driver");
2654 /* FIX: add STA entry to kernel/driver here? The set_key will fail
2655 * most likely without this.. At the moment, STA entry is added only
2656 * after association has been completed. This function will be called
2657 * again after association to get the PTK configured, but that could be
2658 * optimized by adding the STA entry earlier.
2660 if (wpa_auth_set_key(sm
->wpa_auth
, 0, alg
, sm
->addr
, 0,
2664 /* FIX: MLME-SetProtection.Request(TA, Tx_Rx) */
2665 sm
->pairwise_set
= TRUE
;
2666 sm
->tk_already_set
= TRUE
;
2670 /* Derive PMK-R1 from PSK, check all available PSK */
2671 static int wpa_ft_psk_pmk_r1(struct wpa_state_machine
*sm
,
2672 const u8
*req_pmk_r1_name
,
2673 u8
*out_pmk_r1
, int *out_pairwise
,
2674 struct vlan_description
*out_vlan
,
2675 const u8
**out_identity
, size_t *out_identity_len
,
2676 const u8
**out_radius_cui
,
2677 size_t *out_radius_cui_len
,
2678 int *out_session_timeout
)
2680 const u8
*pmk
= NULL
;
2681 u8 pmk_r0
[PMK_LEN
], pmk_r0_name
[WPA_PMK_NAME_LEN
];
2682 u8 pmk_r1
[PMK_LEN
], pmk_r1_name
[WPA_PMK_NAME_LEN
];
2683 struct wpa_authenticator
*wpa_auth
= sm
->wpa_auth
;
2684 const u8
*mdid
= wpa_auth
->conf
.mobility_domain
;
2685 const u8
*r0kh
= sm
->r0kh_id
;
2686 size_t r0kh_len
= sm
->r0kh_id_len
;
2687 const u8
*r1kh
= wpa_auth
->conf
.r1_key_holder
;
2688 const u8
*ssid
= wpa_auth
->conf
.ssid
;
2689 size_t ssid_len
= wpa_auth
->conf
.ssid_len
;
2692 pairwise
= sm
->pairwise
;
2695 pmk
= wpa_ft_get_psk(wpa_auth
, sm
->addr
, sm
->p2p_dev_addr
,
2700 if (wpa_derive_pmk_r0(pmk
, PMK_LEN
, ssid
, ssid_len
, mdid
, r0kh
,
2702 pmk_r0
, pmk_r0_name
, 0) < 0 ||
2703 wpa_derive_pmk_r1(pmk_r0
, PMK_LEN
, pmk_r0_name
, r1kh
,
2704 sm
->addr
, pmk_r1
, pmk_r1_name
) < 0 ||
2705 os_memcmp_const(pmk_r1_name
, req_pmk_r1_name
,
2706 WPA_PMK_NAME_LEN
) != 0)
2709 /* We found a PSK that matches the requested pmk_r1_name */
2710 wpa_printf(MSG_DEBUG
,
2711 "FT: Found PSK to generate PMK-R1 locally");
2712 os_memcpy(out_pmk_r1
, pmk_r1
, PMK_LEN
);
2714 *out_pairwise
= pairwise
;
2715 os_memcpy(sm
->PMK
, pmk
, PMK_LEN
);
2716 sm
->pmk_len
= PMK_LEN
;
2718 wpa_ft_get_vlan(sm
->wpa_auth
, sm
->addr
, out_vlan
) < 0) {
2719 wpa_printf(MSG_DEBUG
, "FT: vlan not available for STA "
2720 MACSTR
, MAC2STR(sm
->addr
));
2724 if (out_identity
&& out_identity_len
) {
2725 *out_identity_len
= wpa_ft_get_identity(
2726 sm
->wpa_auth
, sm
->addr
, out_identity
);
2729 if (out_radius_cui
&& out_radius_cui_len
) {
2730 *out_radius_cui_len
= wpa_ft_get_radius_cui(
2731 sm
->wpa_auth
, sm
->addr
, out_radius_cui
);
2734 if (out_session_timeout
) {
2735 *out_session_timeout
= wpa_ft_get_session_timeout(
2736 sm
->wpa_auth
, sm
->addr
);
2742 wpa_printf(MSG_DEBUG
,
2743 "FT: Did not find PSK to generate PMK-R1 locally");
2748 /* Detect the configuration the station asked for.
2749 * Required to detect FT-PSK and pairwise cipher.
2751 static int wpa_ft_set_key_mgmt(struct wpa_state_machine
*sm
,
2752 struct wpa_ft_ies
*parse
)
2754 int key_mgmt
, ciphers
;
2756 if (sm
->wpa_key_mgmt
)
2759 key_mgmt
= parse
->key_mgmt
& sm
->wpa_auth
->conf
.wpa_key_mgmt
;
2761 wpa_printf(MSG_DEBUG
, "FT: Invalid key mgmt (0x%x) from "
2762 MACSTR
, parse
->key_mgmt
, MAC2STR(sm
->addr
));
2765 if (key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
)
2766 sm
->wpa_key_mgmt
= WPA_KEY_MGMT_FT_IEEE8021X
;
2767 #ifdef CONFIG_SHA384
2768 else if (key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X_SHA384
)
2769 sm
->wpa_key_mgmt
= WPA_KEY_MGMT_FT_IEEE8021X_SHA384
;
2770 #endif /* CONFIG_SHA384 */
2771 else if (key_mgmt
& WPA_KEY_MGMT_FT_PSK
)
2772 sm
->wpa_key_mgmt
= WPA_KEY_MGMT_FT_PSK
;
2774 else if (key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
)
2775 sm
->wpa_key_mgmt
= WPA_KEY_MGMT_FT_FILS_SHA256
;
2776 else if (key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
)
2777 sm
->wpa_key_mgmt
= WPA_KEY_MGMT_FT_FILS_SHA384
;
2778 #endif /* CONFIG_FILS */
2779 ciphers
= parse
->pairwise_cipher
& sm
->wpa_auth
->conf
.rsn_pairwise
;
2781 wpa_printf(MSG_DEBUG
, "FT: Invalid pairwise cipher (0x%x) from "
2783 parse
->pairwise_cipher
, MAC2STR(sm
->addr
));
2786 sm
->pairwise
= wpa_pick_pairwise_cipher(ciphers
, 0);
2792 static int wpa_ft_local_derive_pmk_r1(struct wpa_authenticator
*wpa_auth
,
2793 struct wpa_state_machine
*sm
,
2794 const u8
*r0kh_id
, size_t r0kh_id_len
,
2795 const u8
*req_pmk_r0_name
,
2796 const u8
*req_pmk_r1_name
,
2797 u8
*out_pmk_r1
, int *out_pairwise
,
2798 struct vlan_description
*vlan
,
2799 const u8
**identity
, size_t *identity_len
,
2800 const u8
**radius_cui
,
2801 size_t *radius_cui_len
,
2802 int *out_session_timeout
)
2804 struct wpa_auth_config
*conf
= &wpa_auth
->conf
;
2805 const struct wpa_ft_pmk_r0_sa
*r0
;
2806 u8 pmk_r1_name
[WPA_PMK_NAME_LEN
];
2808 int session_timeout
= 0;
2809 struct os_reltime now
;
2811 if (conf
->r0_key_holder_len
!= r0kh_id_len
||
2812 os_memcmp(conf
->r0_key_holder
, r0kh_id
, conf
->r0_key_holder_len
) !=
2814 return -1; /* not our R0KH-ID */
2816 wpa_printf(MSG_DEBUG
, "FT: STA R0KH-ID matching local configuration");
2817 if (wpa_ft_fetch_pmk_r0(sm
->wpa_auth
, sm
->addr
, req_pmk_r0_name
, &r0
) <
2819 return -1; /* no matching PMKR0Name in local cache */
2821 wpa_printf(MSG_DEBUG
, "FT: Requested PMKR0Name found in local cache");
2823 if (wpa_derive_pmk_r1(r0
->pmk_r0
, r0
->pmk_r0_len
, r0
->pmk_r0_name
,
2824 conf
->r1_key_holder
,
2825 sm
->addr
, out_pmk_r1
, pmk_r1_name
) < 0)
2827 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1", out_pmk_r1
, r0
->pmk_r0_len
);
2828 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name", pmk_r1_name
, WPA_PMK_NAME_LEN
);
2830 os_get_reltime(&now
);
2832 expires_in
= r0
->expiration
- now
.sec
;
2834 if (r0
->session_timeout
)
2835 session_timeout
= r0
->session_timeout
- now
.sec
;
2837 wpa_ft_store_pmk_r1(wpa_auth
, sm
->addr
, out_pmk_r1
, r0
->pmk_r0_len
,
2839 sm
->pairwise
, r0
->vlan
, expires_in
, session_timeout
,
2840 r0
->identity
, r0
->identity_len
,
2841 r0
->radius_cui
, r0
->radius_cui_len
);
2843 *out_pairwise
= sm
->pairwise
;
2848 os_memset(vlan
, 0, sizeof(*vlan
));
2851 if (identity
&& identity_len
) {
2852 *identity
= r0
->identity
;
2853 *identity_len
= r0
->identity_len
;
2856 if (radius_cui
&& radius_cui_len
) {
2857 *radius_cui
= r0
->radius_cui
;
2858 *radius_cui_len
= r0
->radius_cui_len
;
2861 *out_session_timeout
= session_timeout
;
2867 static int wpa_ft_process_auth_req(struct wpa_state_machine
*sm
,
2868 const u8
*ies
, size_t ies_len
,
2869 u8
**resp_ies
, size_t *resp_ies_len
)
2871 struct rsn_mdie
*mdie
;
2872 u8 pmk_r1
[PMK_LEN_MAX
], pmk_r1_name
[WPA_PMK_NAME_LEN
];
2873 u8 ptk_name
[WPA_PMK_NAME_LEN
];
2874 struct wpa_auth_config
*conf
;
2875 struct wpa_ft_ies parse
;
2879 int pairwise
, session_timeout
= 0;
2880 struct vlan_description vlan
;
2881 const u8
*identity
, *radius_cui
;
2882 size_t identity_len
= 0, radius_cui_len
= 0;
2889 sm
->pmk_r1_name_valid
= 0;
2890 conf
= &sm
->wpa_auth
->conf
;
2892 wpa_hexdump(MSG_DEBUG
, "FT: Received authentication frame IEs",
2895 if (wpa_ft_parse_ies(ies
, ies_len
, &parse
, -1)) {
2896 wpa_printf(MSG_DEBUG
, "FT: Failed to parse FT IEs");
2897 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2899 use_sha384
= wpa_key_mgmt_sha384(parse
.key_mgmt
);
2900 pmk_r1_len
= use_sha384
? SHA384_MAC_LEN
: PMK_LEN
;
2902 mdie
= (struct rsn_mdie
*) parse
.mdie
;
2903 if (mdie
== NULL
|| parse
.mdie_len
< sizeof(*mdie
) ||
2904 os_memcmp(mdie
->mobility_domain
,
2905 sm
->wpa_auth
->conf
.mobility_domain
,
2906 MOBILITY_DOMAIN_ID_LEN
) != 0) {
2907 wpa_printf(MSG_DEBUG
, "FT: Invalid MDIE");
2908 return WLAN_STATUS_INVALID_MDIE
;
2912 struct rsn_ftie_sha384
*ftie
;
2914 ftie
= (struct rsn_ftie_sha384
*) parse
.ftie
;
2915 if (!ftie
|| parse
.ftie_len
< sizeof(*ftie
)) {
2916 wpa_printf(MSG_DEBUG
, "FT: Invalid FTIE");
2917 return WLAN_STATUS_INVALID_FTIE
;
2920 os_memcpy(sm
->SNonce
, ftie
->snonce
, WPA_NONCE_LEN
);
2922 struct rsn_ftie
*ftie
;
2924 ftie
= (struct rsn_ftie
*) parse
.ftie
;
2925 if (!ftie
|| parse
.ftie_len
< sizeof(*ftie
)) {
2926 wpa_printf(MSG_DEBUG
, "FT: Invalid FTIE");
2927 return WLAN_STATUS_INVALID_FTIE
;
2930 os_memcpy(sm
->SNonce
, ftie
->snonce
, WPA_NONCE_LEN
);
2933 if (parse
.r0kh_id
== NULL
) {
2934 wpa_printf(MSG_DEBUG
, "FT: Invalid FTIE - no R0KH-ID");
2935 return WLAN_STATUS_INVALID_FTIE
;
2938 wpa_hexdump(MSG_DEBUG
, "FT: STA R0KH-ID",
2939 parse
.r0kh_id
, parse
.r0kh_id_len
);
2940 os_memcpy(sm
->r0kh_id
, parse
.r0kh_id
, parse
.r0kh_id_len
);
2941 sm
->r0kh_id_len
= parse
.r0kh_id_len
;
2943 if (parse
.rsn_pmkid
== NULL
) {
2944 wpa_printf(MSG_DEBUG
, "FT: No PMKID in RSNIE");
2945 return WLAN_STATUS_INVALID_PMKID
;
2948 if (wpa_ft_set_key_mgmt(sm
, &parse
) < 0)
2949 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2951 wpa_hexdump(MSG_DEBUG
, "FT: Requested PMKR0Name",
2952 parse
.rsn_pmkid
, WPA_PMK_NAME_LEN
);
2953 if (wpa_derive_pmk_r1_name(parse
.rsn_pmkid
,
2954 sm
->wpa_auth
->conf
.r1_key_holder
, sm
->addr
,
2955 pmk_r1_name
, use_sha384
) < 0)
2956 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
2957 wpa_hexdump(MSG_DEBUG
, "FT: Derived requested PMKR1Name",
2958 pmk_r1_name
, WPA_PMK_NAME_LEN
);
2960 if (conf
->ft_psk_generate_local
&&
2961 wpa_key_mgmt_ft_psk(sm
->wpa_key_mgmt
)) {
2962 if (wpa_ft_psk_pmk_r1(sm
, pmk_r1_name
, pmk_r1
, &pairwise
,
2963 &vlan
, &identity
, &identity_len
,
2964 &radius_cui
, &radius_cui_len
,
2965 &session_timeout
) < 0)
2966 return WLAN_STATUS_INVALID_PMKID
;
2967 wpa_printf(MSG_DEBUG
,
2968 "FT: Generated PMK-R1 for FT-PSK locally");
2969 } else if (wpa_ft_fetch_pmk_r1(sm
->wpa_auth
, sm
->addr
, pmk_r1_name
,
2970 pmk_r1
, &pmk_r1_len
, &pairwise
, &vlan
,
2971 &identity
, &identity_len
, &radius_cui
,
2972 &radius_cui_len
, &session_timeout
) < 0) {
2973 wpa_printf(MSG_DEBUG
,
2974 "FT: No PMK-R1 available in local cache for the requested PMKR1Name");
2975 if (wpa_ft_local_derive_pmk_r1(sm
->wpa_auth
, sm
,
2976 parse
.r0kh_id
, parse
.r0kh_id_len
,
2978 pmk_r1_name
, pmk_r1
, &pairwise
,
2979 &vlan
, &identity
, &identity_len
,
2980 &radius_cui
, &radius_cui_len
,
2981 &session_timeout
) == 0) {
2982 wpa_printf(MSG_DEBUG
,
2983 "FT: Generated PMK-R1 based on local PMK-R0");
2984 goto pmk_r1_derived
;
2987 if (wpa_ft_pull_pmk_r1(sm
, ies
, ies_len
, parse
.rsn_pmkid
) < 0) {
2988 wpa_printf(MSG_DEBUG
,
2989 "FT: Did not have matching PMK-R1 and either unknown or blocked R0KH-ID or NAK from R0KH");
2990 return WLAN_STATUS_INVALID_PMKID
;
2993 return -1; /* Status pending */
2995 wpa_printf(MSG_DEBUG
, "FT: Found PMKR1Name from local cache");
2999 wpa_hexdump_key(MSG_DEBUG
, "FT: Selected PMK-R1", pmk_r1
, pmk_r1_len
);
3000 sm
->pmk_r1_name_valid
= 1;
3001 os_memcpy(sm
->pmk_r1_name
, pmk_r1_name
, WPA_PMK_NAME_LEN
);
3002 os_memcpy(sm
->pmk_r1
, pmk_r1
, pmk_r1_len
);
3003 sm
->pmk_r1_len
= pmk_r1_len
;
3005 if (random_get_bytes(sm
->ANonce
, WPA_NONCE_LEN
)) {
3006 wpa_printf(MSG_DEBUG
, "FT: Failed to get random data for "
3008 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3011 wpa_hexdump(MSG_DEBUG
, "FT: Received SNonce",
3012 sm
->SNonce
, WPA_NONCE_LEN
);
3013 wpa_hexdump(MSG_DEBUG
, "FT: Generated ANonce",
3014 sm
->ANonce
, WPA_NONCE_LEN
);
3016 if (wpa_pmk_r1_to_ptk(pmk_r1
, pmk_r1_len
, sm
->SNonce
, sm
->ANonce
,
3017 sm
->addr
, sm
->wpa_auth
->addr
, pmk_r1_name
,
3018 &sm
->PTK
, ptk_name
, sm
->wpa_key_mgmt
,
3020 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3022 sm
->pairwise
= pairwise
;
3023 sm
->PTK_valid
= TRUE
;
3024 sm
->tk_already_set
= FALSE
;
3025 wpa_ft_install_ptk(sm
);
3027 if (wpa_ft_set_vlan(sm
->wpa_auth
, sm
->addr
, &vlan
) < 0) {
3028 wpa_printf(MSG_DEBUG
, "FT: Failed to configure VLAN");
3029 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3031 if (wpa_ft_set_identity(sm
->wpa_auth
, sm
->addr
,
3032 identity
, identity_len
) < 0 ||
3033 wpa_ft_set_radius_cui(sm
->wpa_auth
, sm
->addr
,
3034 radius_cui
, radius_cui_len
) < 0) {
3035 wpa_printf(MSG_DEBUG
, "FT: Failed to configure identity/CUI");
3036 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3038 wpa_ft_set_session_timeout(sm
->wpa_auth
, sm
->addr
, session_timeout
);
3040 buflen
= 2 + sizeof(struct rsn_mdie
) + 2 + sizeof(struct rsn_ftie
) +
3041 2 + FT_R1KH_ID_LEN
+ 200;
3042 *resp_ies
= os_zalloc(buflen
);
3043 if (*resp_ies
== NULL
)
3047 end
= *resp_ies
+ buflen
;
3049 ret
= wpa_write_rsn_ie(conf
, pos
, end
- pos
, parse
.rsn_pmkid
);
3054 ret
= wpa_write_mdie(conf
, pos
, end
- pos
);
3059 ret
= wpa_write_ftie(conf
, use_sha384
, parse
.r0kh_id
, parse
.r0kh_id_len
,
3060 sm
->ANonce
, sm
->SNonce
, pos
, end
- pos
, NULL
, 0);
3065 *resp_ies_len
= pos
- *resp_ies
;
3067 return WLAN_STATUS_SUCCESS
;
3071 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3075 void wpa_ft_process_auth(struct wpa_state_machine
*sm
, const u8
*bssid
,
3076 u16 auth_transaction
, const u8
*ies
, size_t ies_len
,
3077 void (*cb
)(void *ctx
, const u8
*dst
, const u8
*bssid
,
3078 u16 auth_transaction
, u16 status
,
3079 const u8
*ies
, size_t ies_len
),
3084 size_t resp_ies_len
;
3088 wpa_printf(MSG_DEBUG
, "FT: Received authentication frame, but "
3089 "WPA SM not available");
3093 wpa_printf(MSG_DEBUG
, "FT: Received authentication frame: STA=" MACSTR
3094 " BSSID=" MACSTR
" transaction=%d",
3095 MAC2STR(sm
->addr
), MAC2STR(bssid
), auth_transaction
);
3096 sm
->ft_pending_cb
= cb
;
3097 sm
->ft_pending_cb_ctx
= ctx
;
3098 sm
->ft_pending_auth_transaction
= auth_transaction
;
3099 sm
->ft_pending_pull_left_retries
= sm
->wpa_auth
->conf
.rkh_pull_retries
;
3100 res
= wpa_ft_process_auth_req(sm
, ies
, ies_len
, &resp_ies
,
3103 wpa_printf(MSG_DEBUG
, "FT: Callback postponed until response is available");
3108 wpa_printf(MSG_DEBUG
, "FT: FT authentication response: dst=" MACSTR
3109 " auth_transaction=%d status=%u (%s)",
3110 MAC2STR(sm
->addr
), auth_transaction
+ 1, status
,
3111 status2str(status
));
3112 wpa_hexdump(MSG_DEBUG
, "FT: Response IEs", resp_ies
, resp_ies_len
);
3113 cb(ctx
, sm
->addr
, bssid
, auth_transaction
+ 1, status
,
3114 resp_ies
, resp_ies_len
);
3119 u16
wpa_ft_validate_reassoc(struct wpa_state_machine
*sm
, const u8
*ies
,
3122 struct wpa_ft_ies parse
;
3123 struct rsn_mdie
*mdie
;
3124 u8 mic
[WPA_EAPOL_KEY_MIC_MAX_LEN
];
3125 size_t mic_len
= 16;
3130 const u8
*anonce
, *snonce
, *fte_mic
;
3134 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3136 use_sha384
= wpa_key_mgmt_sha384(sm
->wpa_key_mgmt
);
3138 wpa_hexdump(MSG_DEBUG
, "FT: Reassoc Req IEs", ies
, ies_len
);
3140 if (wpa_ft_parse_ies(ies
, ies_len
, &parse
, use_sha384
) < 0) {
3141 wpa_printf(MSG_DEBUG
, "FT: Failed to parse FT IEs");
3142 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3145 if (parse
.rsn
== NULL
) {
3146 wpa_printf(MSG_DEBUG
, "FT: No RSNIE in Reassoc Req");
3147 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3150 if (parse
.rsn_pmkid
== NULL
) {
3151 wpa_printf(MSG_DEBUG
, "FT: No PMKID in RSNIE");
3152 return WLAN_STATUS_INVALID_PMKID
;
3155 if (os_memcmp_const(parse
.rsn_pmkid
, sm
->pmk_r1_name
, WPA_PMK_NAME_LEN
)
3157 wpa_printf(MSG_DEBUG
, "FT: PMKID in Reassoc Req did not match "
3158 "with the PMKR1Name derived from auth request");
3159 return WLAN_STATUS_INVALID_PMKID
;
3162 mdie
= (struct rsn_mdie
*) parse
.mdie
;
3163 if (mdie
== NULL
|| parse
.mdie_len
< sizeof(*mdie
) ||
3164 os_memcmp(mdie
->mobility_domain
,
3165 sm
->wpa_auth
->conf
.mobility_domain
,
3166 MOBILITY_DOMAIN_ID_LEN
) != 0) {
3167 wpa_printf(MSG_DEBUG
, "FT: Invalid MDIE");
3168 return WLAN_STATUS_INVALID_MDIE
;
3172 struct rsn_ftie_sha384
*ftie
;
3174 ftie
= (struct rsn_ftie_sha384
*) parse
.ftie
;
3175 if (ftie
== NULL
|| parse
.ftie_len
< sizeof(*ftie
)) {
3176 wpa_printf(MSG_DEBUG
, "FT: Invalid FTIE");
3177 return WLAN_STATUS_INVALID_FTIE
;
3180 anonce
= ftie
->anonce
;
3181 snonce
= ftie
->snonce
;
3182 fte_elem_count
= ftie
->mic_control
[1];
3183 fte_mic
= ftie
->mic
;
3185 struct rsn_ftie
*ftie
;
3187 ftie
= (struct rsn_ftie
*) parse
.ftie
;
3188 if (ftie
== NULL
|| parse
.ftie_len
< sizeof(*ftie
)) {
3189 wpa_printf(MSG_DEBUG
, "FT: Invalid FTIE");
3190 return WLAN_STATUS_INVALID_FTIE
;
3193 anonce
= ftie
->anonce
;
3194 snonce
= ftie
->snonce
;
3195 fte_elem_count
= ftie
->mic_control
[1];
3196 fte_mic
= ftie
->mic
;
3199 if (os_memcmp(snonce
, sm
->SNonce
, WPA_NONCE_LEN
) != 0) {
3200 wpa_printf(MSG_DEBUG
, "FT: SNonce mismatch in FTIE");
3201 wpa_hexdump(MSG_DEBUG
, "FT: Received SNonce",
3202 snonce
, WPA_NONCE_LEN
);
3203 wpa_hexdump(MSG_DEBUG
, "FT: Expected SNonce",
3204 sm
->SNonce
, WPA_NONCE_LEN
);
3205 return WLAN_STATUS_INVALID_FTIE
;
3208 if (os_memcmp(anonce
, sm
->ANonce
, WPA_NONCE_LEN
) != 0) {
3209 wpa_printf(MSG_DEBUG
, "FT: ANonce mismatch in FTIE");
3210 wpa_hexdump(MSG_DEBUG
, "FT: Received ANonce",
3211 anonce
, WPA_NONCE_LEN
);
3212 wpa_hexdump(MSG_DEBUG
, "FT: Expected ANonce",
3213 sm
->ANonce
, WPA_NONCE_LEN
);
3214 return WLAN_STATUS_INVALID_FTIE
;
3218 if (parse
.r0kh_id
== NULL
) {
3219 wpa_printf(MSG_DEBUG
, "FT: No R0KH-ID subelem in FTIE");
3220 return WLAN_STATUS_INVALID_FTIE
;
3223 if (parse
.r0kh_id_len
!= sm
->r0kh_id_len
||
3224 os_memcmp_const(parse
.r0kh_id
, sm
->r0kh_id
, parse
.r0kh_id_len
) != 0)
3226 wpa_printf(MSG_DEBUG
, "FT: R0KH-ID in FTIE did not match with "
3227 "the current R0KH-ID");
3228 wpa_hexdump(MSG_DEBUG
, "FT: R0KH-ID in FTIE",
3229 parse
.r0kh_id
, parse
.r0kh_id_len
);
3230 wpa_hexdump(MSG_DEBUG
, "FT: The current R0KH-ID",
3231 sm
->r0kh_id
, sm
->r0kh_id_len
);
3232 return WLAN_STATUS_INVALID_FTIE
;
3235 if (parse
.r1kh_id
== NULL
) {
3236 wpa_printf(MSG_DEBUG
, "FT: No R1KH-ID subelem in FTIE");
3237 return WLAN_STATUS_INVALID_FTIE
;
3240 if (os_memcmp_const(parse
.r1kh_id
, sm
->wpa_auth
->conf
.r1_key_holder
,
3241 FT_R1KH_ID_LEN
) != 0) {
3242 wpa_printf(MSG_DEBUG
, "FT: Unknown R1KH-ID used in "
3244 wpa_hexdump(MSG_DEBUG
, "FT: R1KH-ID in FTIE",
3245 parse
.r1kh_id
, FT_R1KH_ID_LEN
);
3246 wpa_hexdump(MSG_DEBUG
, "FT: Expected R1KH-ID",
3247 sm
->wpa_auth
->conf
.r1_key_holder
, FT_R1KH_ID_LEN
);
3248 return WLAN_STATUS_INVALID_FTIE
;
3251 if (parse
.rsn_pmkid
== NULL
||
3252 os_memcmp_const(parse
.rsn_pmkid
, sm
->pmk_r1_name
, WPA_PMK_NAME_LEN
))
3254 wpa_printf(MSG_DEBUG
, "FT: No matching PMKR1Name (PMKID) in "
3255 "RSNIE (pmkid=%d)", !!parse
.rsn_pmkid
);
3256 return WLAN_STATUS_INVALID_PMKID
;
3261 count
+= ieee802_11_ie_count(parse
.ric
, parse
.ric_len
);
3264 if (fte_elem_count
!= count
) {
3265 wpa_printf(MSG_DEBUG
, "FT: Unexpected IE count in MIC "
3266 "Control: received %u expected %u",
3267 fte_elem_count
, count
);
3268 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3271 if (wpa_key_mgmt_fils(sm
->wpa_key_mgmt
)) {
3273 kck_len
= sm
->PTK
.kck2_len
;
3276 kck_len
= sm
->PTK
.kck_len
;
3278 if (wpa_ft_mic(kck
, kck_len
, sm
->addr
, sm
->wpa_auth
->addr
, 5,
3279 parse
.mdie
- 2, parse
.mdie_len
+ 2,
3280 parse
.ftie
- 2, parse
.ftie_len
+ 2,
3281 parse
.rsn
- 2, parse
.rsn_len
+ 2,
3282 parse
.ric
, parse
.ric_len
,
3283 parse
.rsnxe
? parse
.rsnxe
- 2 : NULL
,
3284 parse
.rsnxe
? parse
.rsnxe_len
+ 2 : 0,
3286 wpa_printf(MSG_DEBUG
, "FT: Failed to calculate MIC");
3287 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3290 if (os_memcmp_const(mic
, fte_mic
, mic_len
) != 0) {
3291 wpa_printf(MSG_DEBUG
, "FT: Invalid MIC in FTIE");
3292 wpa_printf(MSG_DEBUG
, "FT: addr=" MACSTR
" auth_addr=" MACSTR
,
3293 MAC2STR(sm
->addr
), MAC2STR(sm
->wpa_auth
->addr
));
3294 wpa_hexdump(MSG_MSGDUMP
, "FT: Received MIC",
3296 wpa_hexdump(MSG_MSGDUMP
, "FT: Calculated MIC", mic
, mic_len
);
3297 wpa_hexdump(MSG_MSGDUMP
, "FT: MDIE",
3298 parse
.mdie
- 2, parse
.mdie_len
+ 2);
3299 wpa_hexdump(MSG_MSGDUMP
, "FT: FTIE",
3300 parse
.ftie
- 2, parse
.ftie_len
+ 2);
3301 wpa_hexdump(MSG_MSGDUMP
, "FT: RSN",
3302 parse
.rsn
- 2, parse
.rsn_len
+ 2);
3303 wpa_hexdump(MSG_MSGDUMP
, "FT: RSNXE",
3304 parse
.rsnxe
? parse
.rsnxe
- 2 : NULL
,
3305 parse
.rsnxe
? parse
.rsnxe_len
+ 2 : 0);
3306 return WLAN_STATUS_INVALID_FTIE
;
3310 if (wpa_auth_uses_ocv(sm
)) {
3311 struct wpa_channel_info ci
;
3315 if (wpa_channel_info(sm
->wpa_auth
, &ci
) != 0) {
3316 wpa_printf(MSG_WARNING
,
3317 "Failed to get channel info to validate received OCI in (Re)Assoc Request");
3318 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3321 if (get_sta_tx_parameters(sm
,
3322 channel_width_to_int(ci
.chanwidth
),
3323 ci
.seg1_idx
, &tx_chanwidth
,
3325 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3327 if (ocv_verify_tx_params(parse
.oci
, parse
.oci_len
, &ci
,
3328 tx_chanwidth
, tx_seg1_idx
) != 0) {
3329 wpa_printf(MSG_WARNING
, "%s", ocv_errorstr
);
3330 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
3333 #endif /* CONFIG_OCV */
3335 return WLAN_STATUS_SUCCESS
;
3339 int wpa_ft_action_rx(struct wpa_state_machine
*sm
, const u8
*data
, size_t len
)
3341 const u8
*sta_addr
, *target_ap
;
3345 struct ft_rrb_frame
*frame
;
3351 * data: Category[1] Action[1] STA_Address[6] Target_AP_Address[6]
3352 * FT Request action frame body[variable]
3356 wpa_printf(MSG_DEBUG
, "FT: Too short FT Action frame "
3357 "(len=%lu)", (unsigned long) len
);
3362 sta_addr
= data
+ 2;
3363 target_ap
= data
+ 8;
3367 wpa_printf(MSG_DEBUG
, "FT: Received FT Action frame (STA=" MACSTR
3368 " Target AP=" MACSTR
" Action=%d)",
3369 MAC2STR(sta_addr
), MAC2STR(target_ap
), action
);
3371 if (os_memcmp(sta_addr
, sm
->addr
, ETH_ALEN
) != 0) {
3372 wpa_printf(MSG_DEBUG
, "FT: Mismatch in FT Action STA address: "
3373 "STA=" MACSTR
" STA-Address=" MACSTR
,
3374 MAC2STR(sm
->addr
), MAC2STR(sta_addr
));
3379 * Do some sanity checking on the target AP address (not own and not
3380 * broadcast. This could be extended to filter based on a list of known
3381 * APs in the MD (if such a list were configured).
3383 if ((target_ap
[0] & 0x01) ||
3384 os_memcmp(target_ap
, sm
->wpa_auth
->addr
, ETH_ALEN
) == 0) {
3385 wpa_printf(MSG_DEBUG
, "FT: Invalid Target AP in FT Action "
3390 wpa_hexdump(MSG_MSGDUMP
, "FT: Action frame body", ies
, ies_len
);
3392 if (!sm
->wpa_auth
->conf
.ft_over_ds
) {
3393 wpa_printf(MSG_DEBUG
, "FT: Over-DS option disabled - reject");
3397 /* RRB - Forward action frame to the target AP */
3398 frame
= os_malloc(sizeof(*frame
) + len
);
3401 frame
->frame_type
= RSN_REMOTE_FRAME_TYPE_FT_RRB
;
3402 frame
->packet_type
= FT_PACKET_REQUEST
;
3403 frame
->action_length
= host_to_le16(len
);
3404 os_memcpy(frame
->ap_address
, sm
->wpa_auth
->addr
, ETH_ALEN
);
3405 os_memcpy(frame
+ 1, data
, len
);
3407 wpa_ft_rrb_send(sm
->wpa_auth
, target_ap
, (u8
*) frame
,
3408 sizeof(*frame
) + len
);
3415 static void wpa_ft_rrb_rx_request_cb(void *ctx
, const u8
*dst
, const u8
*bssid
,
3416 u16 auth_transaction
, u16 resp
,
3417 const u8
*ies
, size_t ies_len
)
3419 struct wpa_state_machine
*sm
= ctx
;
3420 wpa_printf(MSG_DEBUG
, "FT: Over-the-DS RX request cb for " MACSTR
,
3422 wpa_ft_send_rrb_auth_resp(sm
, sm
->ft_pending_current_ap
, sm
->addr
,
3423 WLAN_STATUS_SUCCESS
, ies
, ies_len
);
3427 static int wpa_ft_rrb_rx_request(struct wpa_authenticator
*wpa_auth
,
3428 const u8
*current_ap
, const u8
*sta_addr
,
3429 const u8
*body
, size_t len
)
3431 struct wpa_state_machine
*sm
;
3434 size_t resp_ies_len
;
3437 sm
= wpa_ft_add_sta(wpa_auth
, sta_addr
);
3439 wpa_printf(MSG_DEBUG
, "FT: Failed to add new STA based on "
3444 wpa_hexdump(MSG_MSGDUMP
, "FT: RRB Request Frame body", body
, len
);
3446 sm
->ft_pending_cb
= wpa_ft_rrb_rx_request_cb
;
3447 sm
->ft_pending_cb_ctx
= sm
;
3448 os_memcpy(sm
->ft_pending_current_ap
, current_ap
, ETH_ALEN
);
3449 sm
->ft_pending_pull_left_retries
= sm
->wpa_auth
->conf
.rkh_pull_retries
;
3450 res
= wpa_ft_process_auth_req(sm
, body
, len
, &resp_ies
,
3453 wpa_printf(MSG_DEBUG
, "FT: No immediate response available - wait for pull response");
3458 res
= wpa_ft_send_rrb_auth_resp(sm
, current_ap
, sta_addr
, status
,
3459 resp_ies
, resp_ies_len
);
3465 static int wpa_ft_send_rrb_auth_resp(struct wpa_state_machine
*sm
,
3466 const u8
*current_ap
, const u8
*sta_addr
,
3467 u16 status
, const u8
*resp_ies
,
3468 size_t resp_ies_len
)
3470 struct wpa_authenticator
*wpa_auth
= sm
->wpa_auth
;
3472 struct ft_rrb_frame
*frame
;
3475 wpa_printf(MSG_DEBUG
, "FT: RRB authentication response: STA=" MACSTR
3476 " CurrentAP=" MACSTR
" status=%u (%s)",
3477 MAC2STR(sm
->addr
), MAC2STR(current_ap
), status
,
3478 status2str(status
));
3479 wpa_hexdump(MSG_DEBUG
, "FT: Response IEs", resp_ies
, resp_ies_len
);
3481 /* RRB - Forward action frame response to the Current AP */
3484 * data: Category[1] Action[1] STA_Address[6] Target_AP_Address[6]
3485 * Status_Code[2] FT Request action frame body[variable]
3487 rlen
= 2 + 2 * ETH_ALEN
+ 2 + resp_ies_len
;
3489 frame
= os_malloc(sizeof(*frame
) + rlen
);
3492 frame
->frame_type
= RSN_REMOTE_FRAME_TYPE_FT_RRB
;
3493 frame
->packet_type
= FT_PACKET_RESPONSE
;
3494 frame
->action_length
= host_to_le16(rlen
);
3495 os_memcpy(frame
->ap_address
, wpa_auth
->addr
, ETH_ALEN
);
3496 pos
= (u8
*) (frame
+ 1);
3497 *pos
++ = WLAN_ACTION_FT
;
3498 *pos
++ = 2; /* Action: Response */
3499 os_memcpy(pos
, sta_addr
, ETH_ALEN
);
3501 os_memcpy(pos
, wpa_auth
->addr
, ETH_ALEN
);
3503 WPA_PUT_LE16(pos
, status
);
3506 os_memcpy(pos
, resp_ies
, resp_ies_len
);
3508 wpa_ft_rrb_send(wpa_auth
, current_ap
, (u8
*) frame
,
3509 sizeof(*frame
) + rlen
);
3516 static int wpa_ft_rrb_build_r0(const u8
*key
, const size_t key_len
,
3517 const struct tlv_list
*tlvs
,
3518 const struct wpa_ft_pmk_r0_sa
*pmk_r0
,
3519 const u8
*r1kh_id
, const u8
*s1kh_id
,
3520 const struct tlv_list
*tlv_auth
,
3521 const u8
*src_addr
, u8 type
,
3522 u8
**packet
, size_t *packet_len
)
3524 u8 pmk_r1
[PMK_LEN_MAX
];
3525 size_t pmk_r1_len
= pmk_r0
->pmk_r0_len
;
3526 u8 pmk_r1_name
[WPA_PMK_NAME_LEN
];
3527 u8 f_pairwise
[sizeof(le16
)];
3528 u8 f_expires_in
[sizeof(le16
)];
3529 u8 f_session_timeout
[sizeof(le32
)];
3531 int session_timeout
;
3532 struct os_reltime now
;
3534 struct tlv_list sess_tlv
[] = {
3535 { .type
= FT_RRB_PMK_R1
, .len
= pmk_r1_len
,
3537 { .type
= FT_RRB_PMK_R1_NAME
, .len
= sizeof(pmk_r1_name
),
3538 .data
= pmk_r1_name
},
3539 { .type
= FT_RRB_PAIRWISE
, .len
= sizeof(f_pairwise
),
3540 .data
= f_pairwise
},
3541 { .type
= FT_RRB_EXPIRES_IN
, .len
= sizeof(f_expires_in
),
3542 .data
= f_expires_in
},
3543 { .type
= FT_RRB_IDENTITY
, .len
= pmk_r0
->identity_len
,
3544 .data
= pmk_r0
->identity
},
3545 { .type
= FT_RRB_RADIUS_CUI
, .len
= pmk_r0
->radius_cui_len
,
3546 .data
= pmk_r0
->radius_cui
},
3547 { .type
= FT_RRB_SESSION_TIMEOUT
,
3548 .len
= sizeof(f_session_timeout
),
3549 .data
= f_session_timeout
},
3550 { .type
= FT_RRB_LAST_EMPTY
, .len
= 0, .data
= NULL
},
3553 if (wpa_derive_pmk_r1(pmk_r0
->pmk_r0
, pmk_r0
->pmk_r0_len
,
3554 pmk_r0
->pmk_r0_name
, r1kh_id
,
3555 s1kh_id
, pmk_r1
, pmk_r1_name
) < 0)
3557 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1 (for peer AP)",
3558 pmk_r1
, pmk_r1_len
);
3559 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name (for peer AP)",
3560 pmk_r1_name
, WPA_PMK_NAME_LEN
);
3561 WPA_PUT_LE16(f_pairwise
, pmk_r0
->pairwise
);
3563 os_get_reltime(&now
);
3564 if (pmk_r0
->expiration
> now
.sec
)
3565 expires_in
= pmk_r0
->expiration
- now
.sec
;
3566 else if (pmk_r0
->expiration
)
3570 WPA_PUT_LE16(f_expires_in
, expires_in
);
3572 if (pmk_r0
->session_timeout
> now
.sec
)
3573 session_timeout
= pmk_r0
->session_timeout
- now
.sec
;
3574 else if (pmk_r0
->session_timeout
)
3575 session_timeout
= 1;
3577 session_timeout
= 0;
3578 WPA_PUT_LE32(f_session_timeout
, session_timeout
);
3580 ret
= wpa_ft_rrb_build(key
, key_len
, tlvs
, sess_tlv
, tlv_auth
,
3581 pmk_r0
->vlan
, src_addr
, type
,
3582 packet
, packet_len
);
3584 forced_memzero(pmk_r1
, sizeof(pmk_r1
));
3590 static int wpa_ft_rrb_rx_pull(struct wpa_authenticator
*wpa_auth
,
3592 const u8
*enc
, size_t enc_len
,
3593 const u8
*auth
, size_t auth_len
,
3596 const char *msgtype
= "pull request";
3597 u8
*plain
= NULL
, *packet
= NULL
;
3598 size_t plain_len
= 0, packet_len
= 0;
3599 struct ft_remote_r1kh
*r1kh
, *r1kh_wildcard
;
3603 const u8
*f_nonce
, *f_r0kh_id
, *f_r1kh_id
, *f_s1kh_id
, *f_pmk_r0_name
;
3604 size_t f_nonce_len
, f_r0kh_id_len
, f_r1kh_id_len
, f_s1kh_id_len
;
3605 size_t f_pmk_r0_name_len
;
3606 const struct wpa_ft_pmk_r0_sa
*r0
;
3608 struct tlv_list resp
[2];
3609 struct tlv_list resp_auth
[5];
3610 struct ft_rrb_seq f_seq
;
3612 wpa_printf(MSG_DEBUG
, "FT: Received PMK-R1 pull");
3614 RRB_GET_AUTH(FT_RRB_R0KH_ID
, r0kh_id
, msgtype
, -1);
3615 wpa_hexdump(MSG_DEBUG
, "FT: R0KH-ID", f_r0kh_id
, f_r0kh_id_len
);
3617 if (wpa_ft_rrb_check_r0kh(wpa_auth
, f_r0kh_id
, f_r0kh_id_len
)) {
3618 wpa_printf(MSG_DEBUG
, "FT: R0KH-ID mismatch");
3622 RRB_GET_AUTH(FT_RRB_R1KH_ID
, r1kh_id
, msgtype
, FT_R1KH_ID_LEN
);
3623 wpa_printf(MSG_DEBUG
, "FT: R1KH-ID=" MACSTR
, MAC2STR(f_r1kh_id
));
3625 wpa_ft_rrb_lookup_r1kh(wpa_auth
, f_r1kh_id
, &r1kh
, &r1kh_wildcard
);
3628 key_len
= sizeof(r1kh
->key
);
3629 } else if (r1kh_wildcard
) {
3630 wpa_printf(MSG_DEBUG
, "FT: Using wildcard R1KH-ID");
3631 key
= r1kh_wildcard
->key
;
3632 key_len
= sizeof(r1kh_wildcard
->key
);
3637 RRB_GET_AUTH(FT_RRB_NONCE
, nonce
, "pull request", FT_RRB_NONCE_LEN
);
3638 wpa_hexdump(MSG_DEBUG
, "FT: nonce", f_nonce
, f_nonce_len
);
3640 seq_ret
= FT_RRB_SEQ_DROP
;
3642 seq_ret
= wpa_ft_rrb_seq_chk(r1kh
->seq
, src_addr
, enc
, enc_len
,
3643 auth
, auth_len
, msgtype
, no_defer
);
3644 if (!no_defer
&& r1kh_wildcard
&&
3645 (!r1kh
|| os_memcmp(r1kh
->addr
, src_addr
, ETH_ALEN
) != 0)) {
3646 /* wildcard: r1kh-id unknown or changed addr -> do a seq req */
3647 seq_ret
= FT_RRB_SEQ_DEFER
;
3650 if (seq_ret
== FT_RRB_SEQ_DROP
)
3653 if (wpa_ft_rrb_decrypt(key
, key_len
, enc
, enc_len
, auth
, auth_len
,
3654 src_addr
, FT_PACKET_R0KH_R1KH_PULL
,
3655 &plain
, &plain_len
) < 0)
3659 r1kh
= wpa_ft_rrb_add_r1kh(wpa_auth
, r1kh_wildcard
, src_addr
,
3661 wpa_auth
->conf
.rkh_pos_timeout
);
3665 if (seq_ret
== FT_RRB_SEQ_DEFER
) {
3666 wpa_ft_rrb_seq_req(wpa_auth
, r1kh
->seq
, src_addr
, f_r0kh_id
,
3667 f_r0kh_id_len
, f_r1kh_id
, key
, key_len
,
3668 enc
, enc_len
, auth
, auth_len
,
3669 &wpa_ft_rrb_rx_pull
);
3673 wpa_ft_rrb_seq_accept(wpa_auth
, r1kh
->seq
, src_addr
, auth
, auth_len
,
3675 wpa_ft_rrb_r1kh_replenish(wpa_auth
, r1kh
,
3676 wpa_auth
->conf
.rkh_pos_timeout
);
3678 RRB_GET(FT_RRB_PMK_R0_NAME
, pmk_r0_name
, msgtype
, WPA_PMK_NAME_LEN
);
3679 wpa_hexdump(MSG_DEBUG
, "FT: PMKR0Name", f_pmk_r0_name
,
3682 RRB_GET(FT_RRB_S1KH_ID
, s1kh_id
, msgtype
, ETH_ALEN
);
3683 wpa_printf(MSG_DEBUG
, "FT: S1KH-ID=" MACSTR
, MAC2STR(f_s1kh_id
));
3685 if (wpa_ft_new_seq(r1kh
->seq
, &f_seq
) < 0) {
3686 wpa_printf(MSG_DEBUG
, "FT: Failed to get seq num");
3690 resp
[0].type
= FT_RRB_S1KH_ID
;
3691 resp
[0].len
= f_s1kh_id_len
;
3692 resp
[0].data
= f_s1kh_id
;
3693 resp
[1].type
= FT_RRB_LAST_EMPTY
;
3695 resp
[1].data
= NULL
;
3697 resp_auth
[0].type
= FT_RRB_NONCE
;
3698 resp_auth
[0].len
= f_nonce_len
;
3699 resp_auth
[0].data
= f_nonce
;
3700 resp_auth
[1].type
= FT_RRB_SEQ
;
3701 resp_auth
[1].len
= sizeof(f_seq
);
3702 resp_auth
[1].data
= (u8
*) &f_seq
;
3703 resp_auth
[2].type
= FT_RRB_R0KH_ID
;
3704 resp_auth
[2].len
= f_r0kh_id_len
;
3705 resp_auth
[2].data
= f_r0kh_id
;
3706 resp_auth
[3].type
= FT_RRB_R1KH_ID
;
3707 resp_auth
[3].len
= f_r1kh_id_len
;
3708 resp_auth
[3].data
= f_r1kh_id
;
3709 resp_auth
[4].type
= FT_RRB_LAST_EMPTY
;
3710 resp_auth
[4].len
= 0;
3711 resp_auth
[4].data
= NULL
;
3713 if (wpa_ft_fetch_pmk_r0(wpa_auth
, f_s1kh_id
, f_pmk_r0_name
, &r0
) < 0) {
3714 wpa_printf(MSG_DEBUG
, "FT: No matching PMK-R0-Name found");
3715 ret
= wpa_ft_rrb_build(key
, key_len
, resp
, NULL
, resp_auth
,
3716 NULL
, wpa_auth
->addr
,
3717 FT_PACKET_R0KH_R1KH_RESP
,
3718 &packet
, &packet_len
);
3720 ret
= wpa_ft_rrb_build_r0(key
, key_len
, resp
, r0
, f_r1kh_id
,
3721 f_s1kh_id
, resp_auth
, wpa_auth
->addr
,
3722 FT_PACKET_R0KH_R1KH_RESP
,
3723 &packet
, &packet_len
);
3727 wpa_ft_rrb_oui_send(wpa_auth
, src_addr
,
3728 FT_PACKET_R0KH_R1KH_RESP
, packet
,
3739 /* @returns 0 on success
3741 * -2 if FR_RRB_PAIRWISE is missing
3743 static int wpa_ft_rrb_rx_r1(struct wpa_authenticator
*wpa_auth
,
3744 const u8
*src_addr
, u8 type
,
3745 const u8
*enc
, size_t enc_len
,
3746 const u8
*auth
, size_t auth_len
,
3747 const char *msgtype
, u8
*s1kh_id_out
,
3748 int (*cb
)(struct wpa_authenticator
*wpa_auth
,
3750 const u8
*enc
, size_t enc_len
,
3751 const u8
*auth
, size_t auth_len
,
3755 size_t plain_len
= 0;
3756 struct ft_remote_r0kh
*r0kh
, *r0kh_wildcard
;
3760 const u8
*f_r1kh_id
, *f_s1kh_id
, *f_r0kh_id
;
3761 const u8
*f_pmk_r1_name
, *f_pairwise
, *f_pmk_r1
;
3762 const u8
*f_expires_in
;
3763 size_t f_r1kh_id_len
, f_s1kh_id_len
, f_r0kh_id_len
;
3764 const u8
*f_identity
, *f_radius_cui
;
3765 const u8
*f_session_timeout
;
3766 size_t f_pmk_r1_name_len
, f_pairwise_len
, f_pmk_r1_len
;
3767 size_t f_expires_in_len
;
3768 size_t f_identity_len
, f_radius_cui_len
;
3769 size_t f_session_timeout_len
;
3773 int session_timeout
;
3774 struct vlan_description vlan
;
3777 RRB_GET_AUTH(FT_RRB_R0KH_ID
, r0kh_id
, msgtype
, -1);
3778 wpa_hexdump(MSG_DEBUG
, "FT: R0KH-ID", f_r0kh_id
, f_r0kh_id_len
);
3780 RRB_GET_AUTH(FT_RRB_R1KH_ID
, r1kh_id
, msgtype
, FT_R1KH_ID_LEN
);
3781 wpa_printf(MSG_DEBUG
, "FT: R1KH-ID=" MACSTR
, MAC2STR(f_r1kh_id
));
3783 if (wpa_ft_rrb_check_r1kh(wpa_auth
, f_r1kh_id
)) {
3784 wpa_printf(MSG_DEBUG
, "FT: R1KH-ID mismatch");
3788 wpa_ft_rrb_lookup_r0kh(wpa_auth
, f_r0kh_id
, f_r0kh_id_len
, &r0kh
,
3792 key_len
= sizeof(r0kh
->key
);
3793 } else if (r0kh_wildcard
) {
3794 wpa_printf(MSG_DEBUG
, "FT: Using wildcard R0KH-ID");
3795 key
= r0kh_wildcard
->key
;
3796 key_len
= sizeof(r0kh_wildcard
->key
);
3801 seq_ret
= FT_RRB_SEQ_DROP
;
3803 seq_ret
= wpa_ft_rrb_seq_chk(r0kh
->seq
, src_addr
, enc
, enc_len
,
3804 auth
, auth_len
, msgtype
,
3807 if (cb
&& r0kh_wildcard
&&
3808 (!r0kh
|| os_memcmp(r0kh
->addr
, src_addr
, ETH_ALEN
) != 0)) {
3809 /* wildcard: r0kh-id unknown or changed addr -> do a seq req */
3810 seq_ret
= FT_RRB_SEQ_DEFER
;
3813 if (seq_ret
== FT_RRB_SEQ_DROP
)
3816 if (wpa_ft_rrb_decrypt(key
, key_len
, enc
, enc_len
, auth
, auth_len
,
3817 src_addr
, type
, &plain
, &plain_len
) < 0)
3821 r0kh
= wpa_ft_rrb_add_r0kh(wpa_auth
, r0kh_wildcard
, src_addr
,
3822 f_r0kh_id
, f_r0kh_id_len
,
3823 wpa_auth
->conf
.rkh_pos_timeout
);
3827 if (seq_ret
== FT_RRB_SEQ_DEFER
) {
3828 wpa_ft_rrb_seq_req(wpa_auth
, r0kh
->seq
, src_addr
, f_r0kh_id
,
3829 f_r0kh_id_len
, f_r1kh_id
, key
, key_len
,
3830 enc
, enc_len
, auth
, auth_len
, cb
);
3834 wpa_ft_rrb_seq_accept(wpa_auth
, r0kh
->seq
, src_addr
, auth
, auth_len
,
3836 wpa_ft_rrb_r0kh_replenish(wpa_auth
, r0kh
,
3837 wpa_auth
->conf
.rkh_pos_timeout
);
3839 RRB_GET(FT_RRB_S1KH_ID
, s1kh_id
, msgtype
, ETH_ALEN
);
3840 wpa_printf(MSG_DEBUG
, "FT: S1KH-ID=" MACSTR
, MAC2STR(f_s1kh_id
));
3843 os_memcpy(s1kh_id_out
, f_s1kh_id
, ETH_ALEN
);
3846 RRB_GET(FT_RRB_PAIRWISE
, pairwise
, msgtype
, sizeof(le16
));
3847 wpa_hexdump(MSG_DEBUG
, "FT: pairwise", f_pairwise
, f_pairwise_len
);
3850 RRB_GET(FT_RRB_PMK_R1_NAME
, pmk_r1_name
, msgtype
, WPA_PMK_NAME_LEN
);
3851 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name",
3852 f_pmk_r1_name
, WPA_PMK_NAME_LEN
);
3854 pmk_r1_len
= PMK_LEN
;
3855 if (wpa_ft_rrb_get_tlv(plain
, plain_len
, FT_RRB_PMK_R1
, &f_pmk_r1_len
,
3857 (f_pmk_r1_len
== PMK_LEN
|| f_pmk_r1_len
== SHA384_MAC_LEN
))
3858 pmk_r1_len
= f_pmk_r1_len
;
3859 RRB_GET(FT_RRB_PMK_R1
, pmk_r1
, msgtype
, pmk_r1_len
);
3860 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1", f_pmk_r1
, pmk_r1_len
);
3862 pairwise
= WPA_GET_LE16(f_pairwise
);
3864 RRB_GET_OPTIONAL(FT_RRB_EXPIRES_IN
, expires_in
, msgtype
,
3867 expires_in
= WPA_GET_LE16(f_expires_in
);
3871 wpa_printf(MSG_DEBUG
, "FT: PMK-R1 %s - expires_in=%d", msgtype
,
3874 if (wpa_ft_rrb_get_tlv_vlan(plain
, plain_len
, &vlan
) < 0) {
3875 wpa_printf(MSG_DEBUG
, "FT: Cannot parse vlan");
3876 wpa_ft_rrb_dump(plain
, plain_len
);
3880 wpa_printf(MSG_DEBUG
, "FT: vlan %d%s",
3881 le_to_host16(vlan
.untagged
), vlan
.tagged
[0] ? "+" : "");
3883 RRB_GET_OPTIONAL(FT_RRB_IDENTITY
, identity
, msgtype
, -1);
3885 wpa_hexdump_ascii(MSG_DEBUG
, "FT: Identity", f_identity
,
3888 RRB_GET_OPTIONAL(FT_RRB_RADIUS_CUI
, radius_cui
, msgtype
, -1);
3890 wpa_hexdump_ascii(MSG_DEBUG
, "FT: CUI", f_radius_cui
,
3893 RRB_GET_OPTIONAL(FT_RRB_SESSION_TIMEOUT
, session_timeout
, msgtype
,
3895 if (f_session_timeout
)
3896 session_timeout
= WPA_GET_LE32(f_session_timeout
);
3898 session_timeout
= 0;
3899 wpa_printf(MSG_DEBUG
, "FT: session_timeout %d", session_timeout
);
3901 if (wpa_ft_store_pmk_r1(wpa_auth
, f_s1kh_id
, f_pmk_r1
, pmk_r1_len
,
3903 pairwise
, &vlan
, expires_in
, session_timeout
,
3904 f_identity
, f_identity_len
, f_radius_cui
,
3905 f_radius_cui_len
) < 0)
3910 bin_clear_free(plain
, plain_len
);
3917 static void ft_finish_pull(struct wpa_state_machine
*sm
)
3921 size_t resp_ies_len
;
3924 if (!sm
->ft_pending_cb
|| !sm
->ft_pending_req_ies
)
3927 res
= wpa_ft_process_auth_req(sm
, wpabuf_head(sm
->ft_pending_req_ies
),
3928 wpabuf_len(sm
->ft_pending_req_ies
),
3929 &resp_ies
, &resp_ies_len
);
3931 /* this loop is broken by ft_pending_pull_left_retries */
3932 wpa_printf(MSG_DEBUG
,
3933 "FT: Callback postponed until response is available");
3936 wpabuf_free(sm
->ft_pending_req_ies
);
3937 sm
->ft_pending_req_ies
= NULL
;
3939 wpa_printf(MSG_DEBUG
, "FT: Postponed auth callback result for " MACSTR
3940 " - status %u", MAC2STR(sm
->addr
), status
);
3942 sm
->ft_pending_cb(sm
->ft_pending_cb_ctx
, sm
->addr
, sm
->wpa_auth
->addr
,
3943 sm
->ft_pending_auth_transaction
+ 1, status
,
3944 resp_ies
, resp_ies_len
);
3949 struct ft_get_sta_ctx
{
3952 struct wpa_state_machine
*sm
;
3956 static int ft_get_sta_cb(struct wpa_state_machine
*sm
, void *ctx
)
3958 struct ft_get_sta_ctx
*info
= ctx
;
3960 if ((info
->s1kh_id
&&
3961 os_memcmp(info
->s1kh_id
, sm
->addr
, ETH_ALEN
) != 0) ||
3962 os_memcmp(info
->nonce
, sm
->ft_pending_pull_nonce
,
3963 FT_RRB_NONCE_LEN
) != 0 ||
3964 sm
->ft_pending_cb
== NULL
|| sm
->ft_pending_req_ies
== NULL
)
3973 static int wpa_ft_rrb_rx_resp(struct wpa_authenticator
*wpa_auth
,
3975 const u8
*enc
, size_t enc_len
,
3976 const u8
*auth
, size_t auth_len
,
3979 const char *msgtype
= "pull response";
3981 struct ft_get_sta_ctx ctx
;
3982 u8 s1kh_id
[ETH_ALEN
];
3986 wpa_printf(MSG_DEBUG
, "FT: Received PMK-R1 pull response");
3988 RRB_GET_AUTH(FT_RRB_NONCE
, nonce
, msgtype
, FT_RRB_NONCE_LEN
);
3989 wpa_hexdump(MSG_DEBUG
, "FT: nonce", f_nonce
, f_nonce_len
);
3991 os_memset(&ctx
, 0, sizeof(ctx
));
3992 ctx
.nonce
= f_nonce
;
3993 if (!wpa_auth_for_each_sta(wpa_auth
, ft_get_sta_cb
, &ctx
)) {
3994 /* nonce not found */
3995 wpa_printf(MSG_DEBUG
, "FT: Invalid nonce");
3999 ret
= wpa_ft_rrb_rx_r1(wpa_auth
, src_addr
, FT_PACKET_R0KH_R1KH_RESP
,
4000 enc
, enc_len
, auth
, auth_len
, msgtype
, s1kh_id
,
4001 no_defer
? NULL
: &wpa_ft_rrb_rx_resp
);
4011 ctx
.s1kh_id
= s1kh_id
;
4012 if (wpa_auth_for_each_sta(wpa_auth
, ft_get_sta_cb
, &ctx
)) {
4013 wpa_printf(MSG_DEBUG
,
4014 "FT: Response to a pending pull request for " MACSTR
,
4015 MAC2STR(ctx
.sm
->addr
));
4016 eloop_cancel_timeout(wpa_ft_expire_pull
, ctx
.sm
, NULL
);
4018 ctx
.sm
->ft_pending_pull_left_retries
= 0;
4019 ft_finish_pull(ctx
.sm
);
4027 static int wpa_ft_rrb_rx_push(struct wpa_authenticator
*wpa_auth
,
4029 const u8
*enc
, size_t enc_len
,
4030 const u8
*auth
, size_t auth_len
, int no_defer
)
4032 const char *msgtype
= "push";
4034 wpa_printf(MSG_DEBUG
, "FT: Received PMK-R1 push");
4036 if (wpa_ft_rrb_rx_r1(wpa_auth
, src_addr
, FT_PACKET_R0KH_R1KH_PUSH
,
4037 enc
, enc_len
, auth
, auth_len
, msgtype
, NULL
,
4038 no_defer
? NULL
: wpa_ft_rrb_rx_push
) < 0)
4045 static int wpa_ft_rrb_rx_seq(struct wpa_authenticator
*wpa_auth
,
4046 const u8
*src_addr
, int type
,
4047 const u8
*enc
, size_t enc_len
,
4048 const u8
*auth
, size_t auth_len
,
4049 struct ft_remote_seq
**rkh_seq
,
4050 u8
**key
, size_t *key_len
,
4051 struct ft_remote_r0kh
**r0kh_out
,
4052 struct ft_remote_r1kh
**r1kh_out
,
4053 struct ft_remote_r0kh
**r0kh_wildcard_out
,
4054 struct ft_remote_r1kh
**r1kh_wildcard_out
)
4056 struct ft_remote_r0kh
*r0kh
= NULL
;
4057 struct ft_remote_r1kh
*r1kh
= NULL
;
4058 const u8
*f_r0kh_id
, *f_r1kh_id
;
4059 size_t f_r0kh_id_len
, f_r1kh_id_len
;
4060 int to_r0kh
, to_r1kh
;
4062 size_t plain_len
= 0;
4063 struct ft_remote_r0kh
*r0kh_wildcard
;
4064 struct ft_remote_r1kh
*r1kh_wildcard
;
4066 RRB_GET_AUTH(FT_RRB_R0KH_ID
, r0kh_id
, "seq", -1);
4067 RRB_GET_AUTH(FT_RRB_R1KH_ID
, r1kh_id
, "seq", FT_R1KH_ID_LEN
);
4069 to_r0kh
= !wpa_ft_rrb_check_r0kh(wpa_auth
, f_r0kh_id
, f_r0kh_id_len
);
4070 to_r1kh
= !wpa_ft_rrb_check_r1kh(wpa_auth
, f_r1kh_id
);
4072 if (to_r0kh
&& to_r1kh
) {
4073 wpa_printf(MSG_DEBUG
, "FT: seq - local R0KH-ID and R1KH-ID");
4077 if (!to_r0kh
&& !to_r1kh
) {
4078 wpa_printf(MSG_DEBUG
, "FT: seq - remote R0KH-ID and R1KH-ID");
4083 wpa_ft_rrb_lookup_r0kh(wpa_auth
, f_r0kh_id
, f_r0kh_id_len
,
4084 &r0kh
, &r0kh_wildcard
);
4085 if (!r0kh_wildcard
&&
4086 (!r0kh
|| os_memcmp(r0kh
->addr
, src_addr
, ETH_ALEN
) != 0)) {
4087 wpa_hexdump(MSG_DEBUG
, "FT: Did not find R0KH-ID",
4088 f_r0kh_id
, f_r0kh_id_len
);
4093 *key_len
= sizeof(r0kh
->key
);
4095 *key
= r0kh_wildcard
->key
;
4096 *key_len
= sizeof(r0kh_wildcard
->key
);
4101 wpa_ft_rrb_lookup_r1kh(wpa_auth
, f_r1kh_id
, &r1kh
,
4103 if (!r1kh_wildcard
&&
4104 (!r1kh
|| os_memcmp(r1kh
->addr
, src_addr
, ETH_ALEN
) != 0)) {
4105 wpa_hexdump(MSG_DEBUG
, "FT: Did not find R1KH-ID",
4106 f_r1kh_id
, FT_R1KH_ID_LEN
);
4111 *key_len
= sizeof(r1kh
->key
);
4113 *key
= r1kh_wildcard
->key
;
4114 *key_len
= sizeof(r1kh_wildcard
->key
);
4118 if (wpa_ft_rrb_decrypt(*key
, *key_len
, enc
, enc_len
, auth
, auth_len
,
4119 src_addr
, type
, &plain
, &plain_len
) < 0)
4126 r0kh
= wpa_ft_rrb_add_r0kh(wpa_auth
, r0kh_wildcard
,
4127 src_addr
, f_r0kh_id
,
4133 wpa_ft_rrb_r0kh_replenish(wpa_auth
, r0kh
, ftRRBseqTimeout
);
4134 *rkh_seq
= r0kh
->seq
;
4137 if (r0kh_wildcard_out
)
4138 *r0kh_wildcard_out
= r0kh_wildcard
;
4143 r1kh
= wpa_ft_rrb_add_r1kh(wpa_auth
, r1kh_wildcard
,
4144 src_addr
, f_r1kh_id
,
4149 wpa_ft_rrb_r1kh_replenish(wpa_auth
, r1kh
, ftRRBseqTimeout
);
4150 *rkh_seq
= r1kh
->seq
;
4153 if (r1kh_wildcard_out
)
4154 *r1kh_wildcard_out
= r1kh_wildcard
;
4163 static int wpa_ft_rrb_rx_seq_req(struct wpa_authenticator
*wpa_auth
,
4165 const u8
*enc
, size_t enc_len
,
4166 const u8
*auth
, size_t auth_len
,
4170 struct ft_rrb_seq f_seq
;
4171 const u8
*f_nonce
, *f_r0kh_id
, *f_r1kh_id
;
4172 size_t f_nonce_len
, f_r0kh_id_len
, f_r1kh_id_len
;
4173 struct ft_remote_seq
*rkh_seq
= NULL
;
4174 u8
*packet
= NULL
, *key
= NULL
;
4175 size_t packet_len
= 0, key_len
= 0;
4176 struct tlv_list seq_resp_auth
[5];
4178 wpa_printf(MSG_DEBUG
, "FT: Received sequence number request");
4180 if (wpa_ft_rrb_rx_seq(wpa_auth
, src_addr
, FT_PACKET_R0KH_R1KH_SEQ_REQ
,
4181 enc
, enc_len
, auth
, auth_len
, &rkh_seq
, &key
,
4182 &key_len
, NULL
, NULL
, NULL
, NULL
) < 0)
4185 RRB_GET_AUTH(FT_RRB_NONCE
, nonce
, "seq request", FT_RRB_NONCE_LEN
);
4186 wpa_hexdump(MSG_DEBUG
, "FT: seq request - nonce", f_nonce
, f_nonce_len
);
4188 RRB_GET_AUTH(FT_RRB_R0KH_ID
, r0kh_id
, "seq", -1);
4189 RRB_GET_AUTH(FT_RRB_R1KH_ID
, r1kh_id
, "seq", FT_R1KH_ID_LEN
);
4191 if (wpa_ft_new_seq(rkh_seq
, &f_seq
) < 0) {
4192 wpa_printf(MSG_DEBUG
, "FT: Failed to get seq num");
4196 seq_resp_auth
[0].type
= FT_RRB_NONCE
;
4197 seq_resp_auth
[0].len
= f_nonce_len
;
4198 seq_resp_auth
[0].data
= f_nonce
;
4199 seq_resp_auth
[1].type
= FT_RRB_SEQ
;
4200 seq_resp_auth
[1].len
= sizeof(f_seq
);
4201 seq_resp_auth
[1].data
= (u8
*) &f_seq
;
4202 seq_resp_auth
[2].type
= FT_RRB_R0KH_ID
;
4203 seq_resp_auth
[2].len
= f_r0kh_id_len
;
4204 seq_resp_auth
[2].data
= f_r0kh_id
;
4205 seq_resp_auth
[3].type
= FT_RRB_R1KH_ID
;
4206 seq_resp_auth
[3].len
= FT_R1KH_ID_LEN
;
4207 seq_resp_auth
[3].data
= f_r1kh_id
;
4208 seq_resp_auth
[4].type
= FT_RRB_LAST_EMPTY
;
4209 seq_resp_auth
[4].len
= 0;
4210 seq_resp_auth
[4].data
= NULL
;
4212 if (wpa_ft_rrb_build(key
, key_len
, NULL
, NULL
, seq_resp_auth
, NULL
,
4213 wpa_auth
->addr
, FT_PACKET_R0KH_R1KH_SEQ_RESP
,
4214 &packet
, &packet_len
) < 0)
4217 wpa_ft_rrb_oui_send(wpa_auth
, src_addr
,
4218 FT_PACKET_R0KH_R1KH_SEQ_RESP
, packet
,
4228 static int wpa_ft_rrb_rx_seq_resp(struct wpa_authenticator
*wpa_auth
,
4230 const u8
*enc
, size_t enc_len
,
4231 const u8
*auth
, size_t auth_len
,
4236 struct ft_remote_r0kh
*r0kh
= NULL
, *r0kh_wildcard
= NULL
;
4237 struct ft_remote_r1kh
*r1kh
= NULL
, *r1kh_wildcard
= NULL
;
4238 const u8
*f_nonce
, *f_seq
;
4239 size_t f_nonce_len
, f_seq_len
;
4240 struct ft_remote_seq
*rkh_seq
= NULL
;
4241 struct ft_remote_item
*item
;
4242 struct os_reltime now
, now_remote
;
4244 const struct ft_rrb_seq
*msg_both
;
4245 u32 msg_dom
, msg_seq
;
4247 wpa_printf(MSG_DEBUG
, "FT: Received sequence number response");
4249 if (wpa_ft_rrb_rx_seq(wpa_auth
, src_addr
, FT_PACKET_R0KH_R1KH_SEQ_RESP
,
4250 enc
, enc_len
, auth
, auth_len
, &rkh_seq
, &key
,
4251 &key_len
, &r0kh
, &r1kh
, &r0kh_wildcard
,
4252 &r1kh_wildcard
) < 0)
4255 RRB_GET_AUTH(FT_RRB_NONCE
, nonce
, "seq response", FT_RRB_NONCE_LEN
);
4256 wpa_hexdump(MSG_DEBUG
, "FT: seq response - nonce", f_nonce
,
4260 dl_list_for_each(item
, &rkh_seq
->rx
.queue
, struct ft_remote_item
,
4262 if (os_memcmp_const(f_nonce
, item
->nonce
,
4263 FT_RRB_NONCE_LEN
) != 0 ||
4264 os_get_reltime(&now
) < 0 ||
4265 os_reltime_expired(&now
, &item
->nonce_ts
, ftRRBseqTimeout
))
4272 wpa_printf(MSG_DEBUG
, "FT: seq response - bad nonce");
4277 wpa_ft_rrb_r0kh_replenish(wpa_auth
, r0kh
,
4278 wpa_auth
->conf
.rkh_pos_timeout
);
4280 os_memcpy(r0kh
->addr
, src_addr
, ETH_ALEN
);
4284 wpa_ft_rrb_r1kh_replenish(wpa_auth
, r1kh
,
4285 wpa_auth
->conf
.rkh_pos_timeout
);
4287 os_memcpy(r1kh
->addr
, src_addr
, ETH_ALEN
);
4290 seq_ret
= wpa_ft_rrb_seq_chk(rkh_seq
, src_addr
, enc
, enc_len
, auth
,
4291 auth_len
, "seq response", 1);
4292 if (seq_ret
== FT_RRB_SEQ_OK
) {
4293 wpa_printf(MSG_DEBUG
, "FT: seq response - valid seq number");
4294 wpa_ft_rrb_seq_accept(wpa_auth
, rkh_seq
, src_addr
, auth
,
4295 auth_len
, "seq response");
4297 wpa_printf(MSG_DEBUG
, "FT: seq response - reset seq number");
4299 RRB_GET_AUTH(FT_RRB_SEQ
, seq
, "seq response",
4301 msg_both
= (const struct ft_rrb_seq
*) f_seq
;
4303 msg_dom
= le_to_host32(msg_both
->dom
);
4304 msg_seq
= le_to_host32(msg_both
->seq
);
4305 now_remote
.sec
= le_to_host32(msg_both
->ts
);
4306 now_remote
.usec
= 0;
4308 rkh_seq
->rx
.num_last
= 2;
4309 rkh_seq
->rx
.dom
= msg_dom
;
4310 rkh_seq
->rx
.offsetidx
= 0;
4311 /* Accept some older, possibly cached packets as well */
4312 rkh_seq
->rx
.last
[0] = msg_seq
- FT_REMOTE_SEQ_BACKLOG
-
4313 dl_list_len(&rkh_seq
->rx
.queue
);
4314 rkh_seq
->rx
.last
[1] = msg_seq
;
4316 /* local time - offset = remote time
4317 * <=> local time - remote time = offset */
4318 os_reltime_sub(&now
, &now_remote
, &rkh_seq
->rx
.time_offset
);
4321 wpa_ft_rrb_seq_flush(wpa_auth
, rkh_seq
, 1);
4329 int wpa_ft_rrb_rx(struct wpa_authenticator
*wpa_auth
, const u8
*src_addr
,
4330 const u8
*data
, size_t data_len
)
4332 struct ft_rrb_frame
*frame
;
4334 const u8
*pos
, *end
, *start
;
4336 const u8
*sta_addr
, *target_ap_addr
;
4338 wpa_printf(MSG_DEBUG
, "FT: RRB received frame from remote AP " MACSTR
,
4341 if (data_len
< sizeof(*frame
)) {
4342 wpa_printf(MSG_DEBUG
, "FT: Too short RRB frame (data_len=%lu)",
4343 (unsigned long) data_len
);
4348 frame
= (struct ft_rrb_frame
*) pos
;
4349 pos
+= sizeof(*frame
);
4351 alen
= le_to_host16(frame
->action_length
);
4352 wpa_printf(MSG_DEBUG
, "FT: RRB frame - frame_type=%d packet_type=%d "
4353 "action_length=%d ap_address=" MACSTR
,
4354 frame
->frame_type
, frame
->packet_type
, alen
,
4355 MAC2STR(frame
->ap_address
));
4357 if (frame
->frame_type
!= RSN_REMOTE_FRAME_TYPE_FT_RRB
) {
4358 /* Discard frame per IEEE Std 802.11r-2008, 11A.10.3 */
4359 wpa_printf(MSG_DEBUG
, "FT: RRB discarded frame with "
4360 "unrecognized type %d", frame
->frame_type
);
4364 if (alen
> data_len
- sizeof(*frame
)) {
4365 wpa_printf(MSG_DEBUG
, "FT: RRB frame too short for action "
4370 wpa_hexdump(MSG_MSGDUMP
, "FT: RRB - FT Action frame", pos
, alen
);
4372 if (alen
< 1 + 1 + 2 * ETH_ALEN
) {
4373 wpa_printf(MSG_DEBUG
, "FT: Too short RRB frame (not enough "
4374 "room for Action Frame body); alen=%lu",
4375 (unsigned long) alen
);
4381 if (*pos
!= WLAN_ACTION_FT
) {
4382 wpa_printf(MSG_DEBUG
, "FT: Unexpected Action frame category "
4391 target_ap_addr
= pos
;
4393 wpa_printf(MSG_DEBUG
, "FT: RRB Action Frame: action=%d sta_addr="
4394 MACSTR
" target_ap_addr=" MACSTR
,
4395 action
, MAC2STR(sta_addr
), MAC2STR(target_ap_addr
));
4397 if (frame
->packet_type
== FT_PACKET_REQUEST
) {
4398 wpa_printf(MSG_DEBUG
, "FT: FT Packet Type - Request");
4401 wpa_printf(MSG_DEBUG
, "FT: Unexpected Action %d in "
4402 "RRB Request", action
);
4406 if (os_memcmp(target_ap_addr
, wpa_auth
->addr
, ETH_ALEN
) != 0) {
4407 wpa_printf(MSG_DEBUG
, "FT: Target AP address in the "
4408 "RRB Request does not match with own "
4413 if (wpa_ft_rrb_rx_request(wpa_auth
, frame
->ap_address
,
4414 sta_addr
, pos
, end
- pos
) < 0)
4416 } else if (frame
->packet_type
== FT_PACKET_RESPONSE
) {
4419 if (end
- pos
< 2) {
4420 wpa_printf(MSG_DEBUG
, "FT: Not enough room for status "
4421 "code in RRB Response");
4424 status_code
= WPA_GET_LE16(pos
);
4427 wpa_printf(MSG_DEBUG
, "FT: FT Packet Type - Response "
4428 "(status_code=%d)", status_code
);
4430 if (wpa_ft_action_send(wpa_auth
, sta_addr
, start
, alen
) < 0)
4433 wpa_printf(MSG_DEBUG
, "FT: RRB discarded frame with unknown "
4434 "packet_type %d", frame
->packet_type
);
4439 wpa_hexdump(MSG_DEBUG
, "FT: Ignore extra data in end",
4447 void wpa_ft_rrb_oui_rx(struct wpa_authenticator
*wpa_auth
, const u8
*src_addr
,
4448 const u8
*dst_addr
, u8 oui_suffix
, const u8
*data
,
4451 const u8
*auth
, *enc
;
4455 wpa_printf(MSG_DEBUG
, "FT: RRB-OUI received frame from remote AP "
4456 MACSTR
, MAC2STR(src_addr
));
4457 wpa_printf(MSG_DEBUG
, "FT: RRB-OUI frame - oui_suffix=%d", oui_suffix
);
4458 wpa_hexdump(MSG_MSGDUMP
, "FT: RRB frame payload", data
, data_len
);
4460 if (is_multicast_ether_addr(src_addr
)) {
4461 wpa_printf(MSG_DEBUG
,
4462 "FT: RRB-OUI received frame from multicast address "
4463 MACSTR
, MAC2STR(src_addr
));
4467 if (is_multicast_ether_addr(dst_addr
)) {
4468 wpa_printf(MSG_DEBUG
,
4469 "FT: RRB-OUI received frame from remote AP " MACSTR
4470 " to multicast address " MACSTR
,
4471 MAC2STR(src_addr
), MAC2STR(dst_addr
));
4475 if (data_len
< sizeof(u16
)) {
4476 wpa_printf(MSG_DEBUG
, "FT: RRB-OUI frame too short");
4480 alen
= WPA_GET_LE16(data
);
4481 if (data_len
< sizeof(u16
) + alen
) {
4482 wpa_printf(MSG_DEBUG
, "FT: RRB-OUI frame too short");
4486 auth
= data
+ sizeof(u16
);
4487 wpa_hexdump(MSG_MSGDUMP
, "FT: Authenticated payload", auth
, alen
);
4488 enc
= data
+ sizeof(u16
) + alen
;
4489 elen
= data_len
- sizeof(u16
) - alen
;
4490 wpa_hexdump(MSG_MSGDUMP
, "FT: Encrypted payload", enc
, elen
);
4492 switch (oui_suffix
) {
4493 case FT_PACKET_R0KH_R1KH_PULL
:
4494 wpa_ft_rrb_rx_pull(wpa_auth
, src_addr
, enc
, elen
, auth
, alen
,
4497 case FT_PACKET_R0KH_R1KH_RESP
:
4498 wpa_ft_rrb_rx_resp(wpa_auth
, src_addr
, enc
, elen
, auth
, alen
,
4501 case FT_PACKET_R0KH_R1KH_PUSH
:
4502 wpa_ft_rrb_rx_push(wpa_auth
, src_addr
, enc
, elen
, auth
, alen
,
4505 case FT_PACKET_R0KH_R1KH_SEQ_REQ
:
4506 wpa_ft_rrb_rx_seq_req(wpa_auth
, src_addr
, enc
, elen
, auth
, alen
,
4509 case FT_PACKET_R0KH_R1KH_SEQ_RESP
:
4510 wpa_ft_rrb_rx_seq_resp(wpa_auth
, src_addr
, enc
, elen
, auth
,
4517 static int wpa_ft_generate_pmk_r1(struct wpa_authenticator
*wpa_auth
,
4518 struct wpa_ft_pmk_r0_sa
*pmk_r0
,
4519 struct ft_remote_r1kh
*r1kh
,
4524 struct ft_rrb_seq f_seq
;
4525 struct tlv_list push
[] = {
4526 { .type
= FT_RRB_S1KH_ID
, .len
= ETH_ALEN
,
4528 { .type
= FT_RRB_PMK_R0_NAME
, .len
= WPA_PMK_NAME_LEN
,
4529 .data
= pmk_r0
->pmk_r0_name
},
4530 { .type
= FT_RRB_LAST_EMPTY
, .len
= 0, .data
= NULL
},
4532 struct tlv_list push_auth
[] = {
4533 { .type
= FT_RRB_SEQ
, .len
= sizeof(f_seq
),
4534 .data
= (u8
*) &f_seq
},
4535 { .type
= FT_RRB_R0KH_ID
,
4536 .len
= wpa_auth
->conf
.r0_key_holder_len
,
4537 .data
= wpa_auth
->conf
.r0_key_holder
},
4538 { .type
= FT_RRB_R1KH_ID
, .len
= FT_R1KH_ID_LEN
,
4540 { .type
= FT_RRB_LAST_EMPTY
, .len
= 0, .data
= NULL
},
4543 if (wpa_ft_new_seq(r1kh
->seq
, &f_seq
) < 0) {
4544 wpa_printf(MSG_DEBUG
, "FT: Failed to get seq num");
4548 if (wpa_ft_rrb_build_r0(r1kh
->key
, sizeof(r1kh
->key
), push
, pmk_r0
,
4549 r1kh
->id
, s1kh_id
, push_auth
, wpa_auth
->addr
,
4550 FT_PACKET_R0KH_R1KH_PUSH
,
4551 &packet
, &packet_len
) < 0)
4554 wpa_ft_rrb_oui_send(wpa_auth
, r1kh
->addr
, FT_PACKET_R0KH_R1KH_PUSH
,
4555 packet
, packet_len
);
4562 void wpa_ft_push_pmk_r1(struct wpa_authenticator
*wpa_auth
, const u8
*addr
)
4564 struct wpa_ft_pmk_cache
*cache
= wpa_auth
->ft_pmk_cache
;
4565 struct wpa_ft_pmk_r0_sa
*r0
, *r0found
= NULL
;
4566 struct ft_remote_r1kh
*r1kh
;
4568 if (!wpa_auth
->conf
.pmk_r1_push
)
4570 if (!wpa_auth
->conf
.r1kh_list
)
4573 dl_list_for_each(r0
, &cache
->pmk_r0
, struct wpa_ft_pmk_r0_sa
, list
) {
4574 if (os_memcmp(r0
->spa
, addr
, ETH_ALEN
) == 0) {
4581 if (r0
== NULL
|| r0
->pmk_r1_pushed
)
4583 r0
->pmk_r1_pushed
= 1;
4585 wpa_printf(MSG_DEBUG
, "FT: Deriving and pushing PMK-R1 keys to R1KHs "
4586 "for STA " MACSTR
, MAC2STR(addr
));
4588 for (r1kh
= *wpa_auth
->conf
.r1kh_list
; r1kh
; r1kh
= r1kh
->next
) {
4589 if (is_zero_ether_addr(r1kh
->addr
) ||
4590 is_zero_ether_addr(r1kh
->id
))
4592 if (wpa_ft_rrb_init_r1kh_seq(r1kh
) < 0)
4594 wpa_ft_generate_pmk_r1(wpa_auth
, r0
, r1kh
, addr
);
4598 #endif /* CONFIG_IEEE80211R_AP */