2 * WPA Supplicant - IEEE 802.11r - Fast BSS Transition
3 * Copyright (c) 2006-2007, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
18 #include "crypto/aes_wrap.h"
19 #include "common/ieee802_11_defs.h"
20 #include "common/ieee802_11_common.h"
25 #ifdef CONFIG_IEEE80211R
27 int wpa_derive_ptk_ft(struct wpa_sm
*sm
, const unsigned char *src_addr
,
28 const struct wpa_eapol_key
*key
,
29 struct wpa_ptk
*ptk
, size_t ptk_len
)
31 u8 pmk_r1_name
[WPA_PMK_NAME_LEN
];
32 u8 ptk_name
[WPA_PMK_NAME_LEN
];
33 const u8
*anonce
= key
->key_nonce
;
35 if (sm
->xxkey_len
== 0) {
36 wpa_printf(MSG_DEBUG
, "FT: XXKey not available for key "
41 wpa_derive_pmk_r0(sm
->xxkey
, sm
->xxkey_len
, sm
->ssid
,
42 sm
->ssid_len
, sm
->mobility_domain
,
43 sm
->r0kh_id
, sm
->r0kh_id_len
, sm
->own_addr
,
44 sm
->pmk_r0
, sm
->pmk_r0_name
);
45 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R0", sm
->pmk_r0
, PMK_LEN
);
46 wpa_hexdump(MSG_DEBUG
, "FT: PMKR0Name",
47 sm
->pmk_r0_name
, WPA_PMK_NAME_LEN
);
48 wpa_derive_pmk_r1(sm
->pmk_r0
, sm
->pmk_r0_name
, sm
->r1kh_id
,
49 sm
->own_addr
, sm
->pmk_r1
, pmk_r1_name
);
50 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1", sm
->pmk_r1
, PMK_LEN
);
51 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name", pmk_r1_name
, WPA_PMK_NAME_LEN
);
52 wpa_pmk_r1_to_ptk(sm
->pmk_r1
, sm
->snonce
, anonce
, sm
->own_addr
,
53 sm
->bssid
, pmk_r1_name
,
54 (u8
*) ptk
, ptk_len
, ptk_name
);
55 wpa_hexdump_key(MSG_DEBUG
, "FT: PTK", (u8
*) ptk
, ptk_len
);
56 wpa_hexdump(MSG_DEBUG
, "FT: PTKName", ptk_name
, WPA_PMK_NAME_LEN
);
63 * wpa_sm_set_ft_params - Set FT (IEEE 802.11r) parameters
64 * @sm: Pointer to WPA state machine data from wpa_sm_init()
65 * @mobility_domain: Mobility domain identifier (2 octets)
66 * @r0kh_id: PMK-R0 key holder identity (1-48 octets)
67 * @r0kh_id_len: R0KH-ID length (1-48)
68 * @r1kh_id: PMK-R1 key holder identity (16 octets)
69 * Returns: 0 on success, -1 on failure
71 int wpa_sm_set_ft_params(struct wpa_sm
*sm
, const u8
*mobility_domain
,
72 const u8
*r0kh_id
, size_t r0kh_id_len
,
75 if (sm
&& mobility_domain
) {
76 wpa_hexdump(MSG_DEBUG
, "FT: Mobility domain",
77 mobility_domain
, MOBILITY_DOMAIN_ID_LEN
);
78 os_memcpy(sm
->mobility_domain
, mobility_domain
,
79 MOBILITY_DOMAIN_ID_LEN
);
81 os_memset(sm
->mobility_domain
, 0, MOBILITY_DOMAIN_ID_LEN
);
84 if (r0kh_id_len
> FT_R0KH_ID_MAX_LEN
)
86 wpa_hexdump(MSG_DEBUG
, "FT: R0KH-ID", r0kh_id
, r0kh_id_len
);
87 os_memcpy(sm
->r0kh_id
, r0kh_id
, r0kh_id_len
);
88 sm
->r0kh_id_len
= r0kh_id_len
;
90 /* FIX: When should R0KH-ID be cleared? We need to keep the
91 * old R0KH-ID in order to be able to use this during FT. */
93 * os_memset(sm->r0kh_id, 0, FT_R0KH_ID_LEN);
94 * sm->r0kh_id_len = 0;
99 wpa_hexdump(MSG_DEBUG
, "FT: R1KH-ID", r1kh_id
, FT_R1KH_ID_LEN
);
100 os_memcpy(sm
->r1kh_id
, r1kh_id
, FT_R1KH_ID_LEN
);
102 os_memset(sm
->r1kh_id
, 0, FT_R1KH_ID_LEN
);
109 * wpa_ft_gen_req_ies - Generate FT (IEEE 802.11r) IEs for Auth/ReAssoc Request
110 * @sm: Pointer to WPA state machine data from wpa_sm_init()
111 * @len: Buffer for returning the length of the IEs
112 * @anonce: ANonce or %NULL if not yet available
113 * @pmk_name: PMKR0Name or PMKR1Name to be added into the RSN IE PMKID List
114 * @kck: 128-bit KCK for MIC or %NULL if no MIC is used
115 * @target_ap: Target AP address
116 * @ric_ies: Optional IE(s), e.g., WMM TSPEC(s), for RIC-Request or %NULL
117 * @ric_ies_len: Length of ric_ies buffer in octets
118 * Returns: Pointer to buffer with IEs or %NULL on failure
120 * Caller is responsible for freeing the returned buffer with os_free();
122 static u8
* wpa_ft_gen_req_ies(struct wpa_sm
*sm
, size_t *len
,
123 const u8
*anonce
, const u8
*pmk_name
,
124 const u8
*kck
, const u8
*target_ap
,
125 const u8
*ric_ies
, size_t ric_ies_len
)
128 u8
*buf
, *pos
, *ftie_len
, *ftie_pos
;
129 struct rsn_mdie
*mdie
;
130 struct rsn_ftie
*ftie
;
131 struct rsn_ie_hdr
*rsnie
;
134 sm
->ft_completed
= 0;
136 buf_len
= 2 + sizeof(struct rsn_mdie
) + 2 + sizeof(struct rsn_ftie
) +
137 2 + sm
->r0kh_id_len
+ ric_ies_len
+ 100;
138 buf
= os_zalloc(buf_len
);
143 /* RSNIE[PMKR0Name/PMKR1Name] */
144 rsnie
= (struct rsn_ie_hdr
*) pos
;
145 rsnie
->elem_id
= WLAN_EID_RSN
;
146 WPA_PUT_LE16(rsnie
->version
, RSN_VERSION
);
147 pos
= (u8
*) (rsnie
+ 1);
149 /* Group Suite Selector */
150 if (sm
->group_cipher
== WPA_CIPHER_CCMP
)
151 RSN_SELECTOR_PUT(pos
, RSN_CIPHER_SUITE_CCMP
);
152 else if (sm
->group_cipher
== WPA_CIPHER_TKIP
)
153 RSN_SELECTOR_PUT(pos
, RSN_CIPHER_SUITE_TKIP
);
155 wpa_printf(MSG_WARNING
, "FT: Invalid group cipher (%d)",
160 pos
+= RSN_SELECTOR_LEN
;
162 /* Pairwise Suite Count */
163 WPA_PUT_LE16(pos
, 1);
166 /* Pairwise Suite List */
167 if (sm
->pairwise_cipher
== WPA_CIPHER_CCMP
)
168 RSN_SELECTOR_PUT(pos
, RSN_CIPHER_SUITE_CCMP
);
169 else if (sm
->pairwise_cipher
== WPA_CIPHER_TKIP
)
170 RSN_SELECTOR_PUT(pos
, RSN_CIPHER_SUITE_TKIP
);
172 wpa_printf(MSG_WARNING
, "FT: Invalid pairwise cipher (%d)",
173 sm
->pairwise_cipher
);
177 pos
+= RSN_SELECTOR_LEN
;
179 /* Authenticated Key Management Suite Count */
180 WPA_PUT_LE16(pos
, 1);
183 /* Authenticated Key Management Suite List */
184 if (sm
->key_mgmt
== WPA_KEY_MGMT_FT_IEEE8021X
)
185 RSN_SELECTOR_PUT(pos
, RSN_AUTH_KEY_MGMT_FT_802_1X
);
186 else if (sm
->key_mgmt
== WPA_KEY_MGMT_FT_PSK
)
187 RSN_SELECTOR_PUT(pos
, RSN_AUTH_KEY_MGMT_FT_PSK
);
189 wpa_printf(MSG_WARNING
, "FT: Invalid key management type (%d)",
194 pos
+= RSN_SELECTOR_LEN
;
196 /* RSN Capabilities */
198 #ifdef CONFIG_IEEE80211W
199 if (sm
->mgmt_group_cipher
== WPA_CIPHER_AES_128_CMAC
)
200 capab
|= WPA_CAPABILITY_MFPC
;
201 #endif /* CONFIG_IEEE80211W */
202 WPA_PUT_LE16(pos
, capab
);
206 WPA_PUT_LE16(pos
, 1);
209 /* PMKID List [PMKR0Name/PMKR1Name] */
210 os_memcpy(pos
, pmk_name
, WPA_PMK_NAME_LEN
);
211 pos
+= WPA_PMK_NAME_LEN
;
213 #ifdef CONFIG_IEEE80211W
214 if (sm
->mgmt_group_cipher
== WPA_CIPHER_AES_128_CMAC
) {
215 /* Management Group Cipher Suite */
216 RSN_SELECTOR_PUT(pos
, RSN_CIPHER_SUITE_AES_128_CMAC
);
217 pos
+= RSN_SELECTOR_LEN
;
219 #endif /* CONFIG_IEEE80211W */
221 rsnie
->len
= (pos
- (u8
*) rsnie
) - 2;
224 *pos
++ = WLAN_EID_MOBILITY_DOMAIN
;
225 *pos
++ = sizeof(*mdie
);
226 mdie
= (struct rsn_mdie
*) pos
;
227 pos
+= sizeof(*mdie
);
228 os_memcpy(mdie
->mobility_domain
, sm
->mobility_domain
,
229 MOBILITY_DOMAIN_ID_LEN
);
230 mdie
->ft_capab
= 0; /* FIX: copy from the target AP's MDIE */
232 /* FTIE[SNonce, R0KH-ID] */
234 *pos
++ = WLAN_EID_FAST_BSS_TRANSITION
;
236 ftie
= (struct rsn_ftie
*) pos
;
237 pos
+= sizeof(*ftie
);
238 os_memcpy(ftie
->snonce
, sm
->snonce
, WPA_NONCE_LEN
);
240 os_memcpy(ftie
->anonce
, anonce
, WPA_NONCE_LEN
);
241 /* R0KH-ID sub-element */
242 *pos
++ = FTIE_SUBELEM_R0KH_ID
;
243 *pos
++ = sm
->r0kh_id_len
;
244 os_memcpy(pos
, sm
->r0kh_id
, sm
->r0kh_id_len
);
245 pos
+= sm
->r0kh_id_len
;
246 *ftie_len
= pos
- ftie_len
- 1;
250 os_memcpy(pos
, ric_ies
, ric_ies_len
);
256 * IEEE Std 802.11r-2008, 11A.8.4
257 * MIC shall be calculated over:
258 * non-AP STA MAC address
259 * Target AP MAC address
260 * Transaction seq number (5 for ReassocReq, 3 otherwise)
263 * FTIE (with MIC field set to 0)
264 * RIC-Request (if present)
266 /* Information element count */
267 ftie
->mic_control
[1] = 3 + ieee802_11_ie_count(ric_ies
,
269 if (wpa_ft_mic(kck
, sm
->own_addr
, target_ap
, 5,
270 ((u8
*) mdie
) - 2, 2 + sizeof(*mdie
),
271 ftie_pos
, 2 + *ftie_len
,
272 (u8
*) rsnie
, 2 + rsnie
->len
, ric_ies
,
273 ric_ies_len
, ftie
->mic
) < 0) {
274 wpa_printf(MSG_INFO
, "FT: Failed to calculate MIC");
308 static int wpa_ft_parse_ftie(const u8
*ie
, size_t ie_len
,
309 struct wpa_ft_ies
*parse
)
314 parse
->ftie_len
= ie_len
;
316 pos
= ie
+ sizeof(struct rsn_ftie
);
319 while (pos
+ 2 <= end
&& pos
+ 2 + pos
[1] <= end
) {
321 case FTIE_SUBELEM_R1KH_ID
:
322 if (pos
[1] != FT_R1KH_ID_LEN
) {
323 wpa_printf(MSG_DEBUG
, "FT: Invalid R1KH-ID "
324 "length in FTIE: %d", pos
[1]);
327 parse
->r1kh_id
= pos
+ 2;
329 case FTIE_SUBELEM_GTK
:
330 parse
->gtk
= pos
+ 2;
331 parse
->gtk_len
= pos
[1];
333 case FTIE_SUBELEM_R0KH_ID
:
334 if (pos
[1] < 1 || pos
[1] > FT_R0KH_ID_MAX_LEN
) {
335 wpa_printf(MSG_DEBUG
, "FT: Invalid R0KH-ID "
336 "length in FTIE: %d", pos
[1]);
339 parse
->r0kh_id
= pos
+ 2;
340 parse
->r0kh_id_len
= pos
[1];
342 #ifdef CONFIG_IEEE80211W
343 case FTIE_SUBELEM_IGTK
:
344 parse
->igtk
= pos
+ 2;
345 parse
->igtk_len
= pos
[1];
347 #endif /* CONFIG_IEEE80211W */
357 static int wpa_ft_parse_ies(const u8
*ies
, size_t ies_len
,
358 struct wpa_ft_ies
*parse
)
361 struct wpa_ie_data data
;
363 const struct rsn_ftie
*ftie
;
364 int prot_ie_count
= 0;
366 os_memset(parse
, 0, sizeof(*parse
));
372 while (pos
+ 2 <= end
&& pos
+ 2 + pos
[1] <= end
) {
375 parse
->rsn
= pos
+ 2;
376 parse
->rsn_len
= pos
[1];
377 ret
= wpa_parse_wpa_ie_rsn(parse
->rsn
- 2,
381 wpa_printf(MSG_DEBUG
, "FT: Failed to parse "
385 if (data
.num_pmkid
== 1 && data
.pmkid
)
386 parse
->rsn_pmkid
= data
.pmkid
;
388 case WLAN_EID_MOBILITY_DOMAIN
:
389 parse
->mdie
= pos
+ 2;
390 parse
->mdie_len
= pos
[1];
392 case WLAN_EID_FAST_BSS_TRANSITION
:
393 if (pos
[1] < sizeof(*ftie
))
395 ftie
= (const struct rsn_ftie
*) (pos
+ 2);
396 prot_ie_count
= ftie
->mic_control
[1];
397 if (wpa_ft_parse_ftie(pos
+ 2, pos
[1], parse
) < 0)
400 case WLAN_EID_TIMEOUT_INTERVAL
:
401 parse
->tie
= pos
+ 2;
402 parse
->tie_len
= pos
[1];
404 case WLAN_EID_RIC_DATA
:
405 if (parse
->ric
== NULL
)
412 if (prot_ie_count
== 0)
413 return 0; /* no MIC */
416 * Check that the protected IE count matches with IEs included in the
427 if (prot_ie_count
< 0) {
428 wpa_printf(MSG_DEBUG
, "FT: Some required IEs not included in "
429 "the protected IE count");
433 if (prot_ie_count
== 0 && parse
->ric
) {
434 wpa_printf(MSG_DEBUG
, "FT: RIC IE(s) in the frame, but not "
435 "included in protected IE count");
439 /* Determine the end of the RIC IE(s) */
441 while (pos
&& pos
+ 2 <= end
&& pos
+ 2 + pos
[1] <= end
&&
446 parse
->ric_len
= pos
- parse
->ric
;
448 wpa_printf(MSG_DEBUG
, "FT: %d protected IEs missing from "
449 "frame", (int) prot_ie_count
);
457 static int wpa_ft_install_ptk(struct wpa_sm
*sm
, const u8
*bssid
)
461 u8 null_rsc
[6] = { 0, 0, 0, 0, 0, 0 };
463 wpa_printf(MSG_DEBUG
, "FT: Installing PTK to the driver.");
465 switch (sm
->pairwise_cipher
) {
466 case WPA_CIPHER_CCMP
:
470 case WPA_CIPHER_TKIP
:
475 wpa_printf(MSG_WARNING
, "FT: Unsupported pairwise cipher %d",
476 sm
->pairwise_cipher
);
480 if (wpa_sm_set_key(sm
, alg
, bssid
, 0, 1, null_rsc
,
481 sizeof(null_rsc
), (u8
*) sm
->ptk
.tk1
, keylen
) < 0) {
482 wpa_printf(MSG_WARNING
, "FT: Failed to set PTK to the driver");
491 * wpa_ft_prepare_auth_request - Generate over-the-air auth request
492 * @sm: Pointer to WPA state machine data from wpa_sm_init()
493 * Returns: 0 on success, -1 on failure
495 int wpa_ft_prepare_auth_request(struct wpa_sm
*sm
)
500 /* Generate a new SNonce */
501 if (os_get_random(sm
->snonce
, WPA_NONCE_LEN
)) {
502 wpa_printf(MSG_INFO
, "FT: Failed to generate a new SNonce");
506 ft_ies
= wpa_ft_gen_req_ies(sm
, &ft_ies_len
, NULL
, sm
->pmk_r0_name
,
507 NULL
, sm
->bssid
, NULL
, 0);
509 wpa_sm_update_ft_ies(sm
, sm
->mobility_domain
,
518 int wpa_ft_process_response(struct wpa_sm
*sm
, const u8
*ies
, size_t ies_len
,
519 int ft_action
, const u8
*target_ap
,
520 const u8
*ric_ies
, size_t ric_ies_len
)
523 size_t ft_ies_len
, ptk_len
;
524 struct wpa_ft_ies parse
;
525 struct rsn_mdie
*mdie
;
526 struct rsn_ftie
*ftie
;
527 u8 ptk_name
[WPA_PMK_NAME_LEN
];
531 wpa_hexdump(MSG_DEBUG
, "FT: Response IEs", ies
, ies_len
);
532 wpa_hexdump(MSG_DEBUG
, "FT: RIC IEs", ric_ies
, ric_ies_len
);
535 if (!sm
->over_the_ds_in_progress
) {
536 wpa_printf(MSG_DEBUG
, "FT: No over-the-DS in progress "
537 "- drop FT Action Response");
541 if (os_memcmp(target_ap
, sm
->target_ap
, ETH_ALEN
) != 0) {
542 wpa_printf(MSG_DEBUG
, "FT: No over-the-DS in progress "
543 "with this Target AP - drop FT Action "
549 if (sm
->key_mgmt
!= WPA_KEY_MGMT_FT_IEEE8021X
&&
550 sm
->key_mgmt
!= WPA_KEY_MGMT_FT_PSK
) {
551 wpa_printf(MSG_DEBUG
, "FT: Reject FT IEs since FT is not "
552 "enabled for this connection");
556 if (wpa_ft_parse_ies(ies
, ies_len
, &parse
) < 0) {
557 wpa_printf(MSG_DEBUG
, "FT: Failed to parse IEs");
561 mdie
= (struct rsn_mdie
*) parse
.mdie
;
562 if (mdie
== NULL
|| parse
.mdie_len
< sizeof(*mdie
) ||
563 os_memcmp(mdie
->mobility_domain
, sm
->mobility_domain
,
564 MOBILITY_DOMAIN_ID_LEN
) != 0) {
565 wpa_printf(MSG_DEBUG
, "FT: Invalid MDIE");
569 ftie
= (struct rsn_ftie
*) parse
.ftie
;
570 if (ftie
== NULL
|| parse
.ftie_len
< sizeof(*ftie
)) {
571 wpa_printf(MSG_DEBUG
, "FT: Invalid FTIE");
575 if (parse
.r0kh_id
== NULL
) {
576 wpa_printf(MSG_DEBUG
, "FT: No R0KH-ID subelem in FTIE");
580 if (parse
.r0kh_id_len
!= sm
->r0kh_id_len
||
581 os_memcmp(parse
.r0kh_id
, sm
->r0kh_id
, parse
.r0kh_id_len
) != 0) {
582 wpa_printf(MSG_DEBUG
, "FT: R0KH-ID in FTIE did not match with "
583 "the current R0KH-ID");
584 wpa_hexdump(MSG_DEBUG
, "FT: R0KH-ID in FTIE",
585 parse
.r0kh_id
, parse
.r0kh_id_len
);
586 wpa_hexdump(MSG_DEBUG
, "FT: The current R0KH-ID",
587 sm
->r0kh_id
, sm
->r0kh_id_len
);
591 if (parse
.r1kh_id
== NULL
) {
592 wpa_printf(MSG_DEBUG
, "FT: No R1KH-ID subelem in FTIE");
596 if (parse
.rsn_pmkid
== NULL
||
597 os_memcmp(parse
.rsn_pmkid
, sm
->pmk_r0_name
, WPA_PMK_NAME_LEN
)) {
598 wpa_printf(MSG_DEBUG
, "FT: No matching PMKR0Name (PMKID) in "
603 os_memcpy(sm
->r1kh_id
, parse
.r1kh_id
, FT_R1KH_ID_LEN
);
604 wpa_hexdump(MSG_DEBUG
, "FT: R1KH-ID", sm
->r1kh_id
, FT_R1KH_ID_LEN
);
605 wpa_hexdump(MSG_DEBUG
, "FT: SNonce", sm
->snonce
, WPA_NONCE_LEN
);
606 wpa_hexdump(MSG_DEBUG
, "FT: ANonce", ftie
->anonce
, WPA_NONCE_LEN
);
607 wpa_derive_pmk_r1(sm
->pmk_r0
, sm
->pmk_r0_name
, sm
->r1kh_id
,
608 sm
->own_addr
, sm
->pmk_r1
, sm
->pmk_r1_name
);
609 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1", sm
->pmk_r1
, PMK_LEN
);
610 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name",
611 sm
->pmk_r1_name
, WPA_PMK_NAME_LEN
);
614 ptk_len
= sm
->pairwise_cipher
== WPA_CIPHER_CCMP
? 48 : 64;
615 wpa_pmk_r1_to_ptk(sm
->pmk_r1
, sm
->snonce
, ftie
->anonce
, sm
->own_addr
,
616 bssid
, sm
->pmk_r1_name
,
617 (u8
*) &sm
->ptk
, ptk_len
, ptk_name
);
618 wpa_hexdump_key(MSG_DEBUG
, "FT: PTK",
619 (u8
*) &sm
->ptk
, ptk_len
);
620 wpa_hexdump(MSG_DEBUG
, "FT: PTKName", ptk_name
, WPA_PMK_NAME_LEN
);
622 ft_ies
= wpa_ft_gen_req_ies(sm
, &ft_ies_len
, ftie
->anonce
,
623 sm
->pmk_r1_name
, sm
->ptk
.kck
, bssid
,
624 ric_ies
, ric_ies_len
);
626 wpa_sm_update_ft_ies(sm
, sm
->mobility_domain
,
631 ret
= wpa_ft_install_ptk(sm
, bssid
);
634 sm
->ft_completed
= 1;
636 /* TODO: trigger re-association to the Target AP;
637 * MLME is now doing this automatically, but it should
638 * really be done only if we get here successfully. */
639 os_memcpy(sm
->bssid
, target_ap
, ETH_ALEN
);
647 int wpa_ft_is_completed(struct wpa_sm
*sm
)
652 if (sm
->key_mgmt
!= WPA_KEY_MGMT_FT_IEEE8021X
&&
653 sm
->key_mgmt
!= WPA_KEY_MGMT_FT_PSK
)
656 return sm
->ft_completed
;
660 static int wpa_ft_process_gtk_subelem(struct wpa_sm
*sm
, const u8
*gtk_elem
,
666 size_t gtk_len
, keylen
, rsc_len
;
668 if (gtk_elem
== NULL
) {
669 wpa_printf(MSG_DEBUG
, "FT: No GTK included in FTIE");
673 wpa_hexdump_key(MSG_DEBUG
, "FT: Received GTK in Reassoc Resp",
674 gtk_elem
, gtk_elem_len
);
676 if (gtk_elem_len
< 10 + 24 || (gtk_elem_len
- 10) % 8 ||
677 gtk_elem_len
- 18 > sizeof(gtk
)) {
678 wpa_printf(MSG_DEBUG
, "FT: Invalid GTK sub-elem "
679 "length %lu", (unsigned long) gtk_elem_len
);
682 gtk_len
= gtk_elem_len
- 18;
683 if (aes_unwrap(sm
->ptk
.kek
, gtk_len
/ 8, gtk_elem
+ 10, gtk
)) {
684 wpa_printf(MSG_WARNING
, "FT: AES unwrap failed - could not "
689 switch (sm
->group_cipher
) {
690 case WPA_CIPHER_CCMP
:
695 case WPA_CIPHER_TKIP
:
700 case WPA_CIPHER_WEP104
:
705 case WPA_CIPHER_WEP40
:
711 wpa_printf(MSG_WARNING
, "WPA: Unsupported Group Cipher %d",
716 if (gtk_len
< keylen
) {
717 wpa_printf(MSG_DEBUG
, "FT: Too short GTK in FTIE");
721 /* Key Info[1] | Key Length[1] | RSC[8] | Key[5..32]. */
723 keyidx
= gtk_elem
[0] & 0x03;
725 if (gtk_elem
[1] != keylen
) {
726 wpa_printf(MSG_DEBUG
, "FT: GTK length mismatch: received %d "
728 gtk_elem
[1], (unsigned long) keylen
);
732 wpa_hexdump_key(MSG_DEBUG
, "FT: GTK from Reassoc Resp", gtk
, keylen
);
733 if (wpa_sm_set_key(sm
, alg
, (u8
*) "\xff\xff\xff\xff\xff\xff",
734 keyidx
, 0, gtk_elem
+ 2, rsc_len
, gtk
, keylen
) <
736 wpa_printf(MSG_WARNING
, "WPA: Failed to set GTK to the "
745 #ifdef CONFIG_IEEE80211W
746 static int wpa_ft_process_igtk_subelem(struct wpa_sm
*sm
, const u8
*igtk_elem
,
747 size_t igtk_elem_len
)
749 u8 igtk
[WPA_IGTK_LEN
];
752 if (sm
->mgmt_group_cipher
!= WPA_CIPHER_AES_128_CMAC
)
755 if (igtk_elem
== NULL
) {
756 wpa_printf(MSG_DEBUG
, "FT: No IGTK included in FTIE");
760 wpa_hexdump_key(MSG_DEBUG
, "FT: Received IGTK in Reassoc Resp",
761 igtk_elem
, igtk_elem_len
);
763 if (igtk_elem_len
!= 2 + 6 + 1 + WPA_IGTK_LEN
+ 8) {
764 wpa_printf(MSG_DEBUG
, "FT: Invalid IGTK sub-elem "
765 "length %lu", (unsigned long) igtk_elem_len
);
768 if (igtk_elem
[8] != WPA_IGTK_LEN
) {
769 wpa_printf(MSG_DEBUG
, "FT: Invalid IGTK sub-elem Key Length "
774 if (aes_unwrap(sm
->ptk
.kek
, WPA_IGTK_LEN
/ 8, igtk_elem
+ 9, igtk
)) {
775 wpa_printf(MSG_WARNING
, "FT: AES unwrap failed - could not "
780 /* KeyID[2] | IPN[6] | Key Length[1] | Key[16+8] */
782 keyidx
= WPA_GET_LE16(igtk_elem
);
784 wpa_hexdump_key(MSG_DEBUG
, "FT: IGTK from Reassoc Resp", igtk
,
786 if (wpa_sm_set_key(sm
, WPA_ALG_IGTK
, (u8
*) "\xff\xff\xff\xff\xff\xff",
787 keyidx
, 0, igtk_elem
+ 2, 6, igtk
, WPA_IGTK_LEN
) <
789 wpa_printf(MSG_WARNING
, "WPA: Failed to set IGTK to the "
796 #endif /* CONFIG_IEEE80211W */
799 int wpa_ft_validate_reassoc_resp(struct wpa_sm
*sm
, const u8
*ies
,
800 size_t ies_len
, const u8
*src_addr
)
802 struct wpa_ft_ies parse
;
803 struct rsn_mdie
*mdie
;
804 struct rsn_ftie
*ftie
;
808 wpa_hexdump(MSG_DEBUG
, "FT: Response IEs", ies
, ies_len
);
810 if (sm
->key_mgmt
!= WPA_KEY_MGMT_FT_IEEE8021X
&&
811 sm
->key_mgmt
!= WPA_KEY_MGMT_FT_PSK
) {
812 wpa_printf(MSG_DEBUG
, "FT: Reject FT IEs since FT is not "
813 "enabled for this connection");
817 if (wpa_ft_parse_ies(ies
, ies_len
, &parse
) < 0) {
818 wpa_printf(MSG_DEBUG
, "FT: Failed to parse IEs");
822 mdie
= (struct rsn_mdie
*) parse
.mdie
;
823 if (mdie
== NULL
|| parse
.mdie_len
< sizeof(*mdie
) ||
824 os_memcmp(mdie
->mobility_domain
, sm
->mobility_domain
,
825 MOBILITY_DOMAIN_ID_LEN
) != 0) {
826 wpa_printf(MSG_DEBUG
, "FT: Invalid MDIE");
830 ftie
= (struct rsn_ftie
*) parse
.ftie
;
831 if (ftie
== NULL
|| parse
.ftie_len
< sizeof(*ftie
)) {
832 wpa_printf(MSG_DEBUG
, "FT: Invalid FTIE");
836 if (parse
.r0kh_id
== NULL
) {
837 wpa_printf(MSG_DEBUG
, "FT: No R0KH-ID subelem in FTIE");
841 if (parse
.r0kh_id_len
!= sm
->r0kh_id_len
||
842 os_memcmp(parse
.r0kh_id
, sm
->r0kh_id
, parse
.r0kh_id_len
) != 0) {
843 wpa_printf(MSG_DEBUG
, "FT: R0KH-ID in FTIE did not match with "
844 "the current R0KH-ID");
845 wpa_hexdump(MSG_DEBUG
, "FT: R0KH-ID in FTIE",
846 parse
.r0kh_id
, parse
.r0kh_id_len
);
847 wpa_hexdump(MSG_DEBUG
, "FT: The current R0KH-ID",
848 sm
->r0kh_id
, sm
->r0kh_id_len
);
852 if (parse
.r1kh_id
== NULL
) {
853 wpa_printf(MSG_DEBUG
, "FT: No R1KH-ID subelem in FTIE");
857 if (os_memcmp(parse
.r1kh_id
, sm
->r1kh_id
, FT_R1KH_ID_LEN
) != 0) {
858 wpa_printf(MSG_DEBUG
, "FT: Unknown R1KH-ID used in "
863 if (parse
.rsn_pmkid
== NULL
||
864 os_memcmp(parse
.rsn_pmkid
, sm
->pmk_r1_name
, WPA_PMK_NAME_LEN
)) {
865 wpa_printf(MSG_DEBUG
, "FT: No matching PMKR1Name (PMKID) in "
866 "RSNIE (pmkid=%d)", !!parse
.rsn_pmkid
);
874 if (wpa_ft_mic(sm
->ptk
.kck
, sm
->own_addr
, src_addr
, 6,
875 parse
.mdie
- 2, parse
.mdie_len
+ 2,
876 parse
.ftie
- 2, parse
.ftie_len
+ 2,
877 parse
.rsn
- 2, parse
.rsn_len
+ 2,
878 parse
.ric
, parse
.ric_len
,
880 wpa_printf(MSG_DEBUG
, "FT: Failed to calculate MIC");
884 if (os_memcmp(mic
, ftie
->mic
, 16) != 0) {
885 wpa_printf(MSG_DEBUG
, "FT: Invalid MIC in FTIE");
886 wpa_hexdump(MSG_MSGDUMP
, "FT: Received MIC", ftie
->mic
, 16);
887 wpa_hexdump(MSG_MSGDUMP
, "FT: Calculated MIC", mic
, 16);
891 if (wpa_ft_process_gtk_subelem(sm
, parse
.gtk
, parse
.gtk_len
) < 0)
894 #ifdef CONFIG_IEEE80211W
895 if (wpa_ft_process_igtk_subelem(sm
, parse
.igtk
, parse
.igtk_len
) < 0)
897 #endif /* CONFIG_IEEE80211W */
900 wpa_hexdump(MSG_MSGDUMP
, "FT: RIC Response",
901 parse
.ric
, parse
.ric_len
);
902 /* TODO: parse response and inform driver about results */
910 * wpa_ft_start_over_ds - Generate over-the-DS auth request
911 * @sm: Pointer to WPA state machine data from wpa_sm_init()
912 * Returns: 0 on success, -1 on failure
914 int wpa_ft_start_over_ds(struct wpa_sm
*sm
, const u8
*target_ap
)
919 wpa_printf(MSG_DEBUG
, "FT: Request over-the-DS with " MACSTR
,
922 /* Generate a new SNonce */
923 if (os_get_random(sm
->snonce
, WPA_NONCE_LEN
)) {
924 wpa_printf(MSG_INFO
, "FT: Failed to generate a new SNonce");
928 ft_ies
= wpa_ft_gen_req_ies(sm
, &ft_ies_len
, NULL
, sm
->pmk_r0_name
,
929 NULL
, target_ap
, NULL
, 0);
931 sm
->over_the_ds_in_progress
= 1;
932 os_memcpy(sm
->target_ap
, target_ap
, ETH_ALEN
);
933 wpa_sm_send_ft_action(sm
, 1, target_ap
, ft_ies
, ft_ies_len
);
940 #endif /* CONFIG_IEEE80211R */