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.
22 #include "ieee802_11_defs.h"
24 #ifdef CONFIG_IEEE80211R
26 int wpa_derive_ptk_ft(struct wpa_sm
*sm
, const unsigned char *src_addr
,
27 const struct wpa_eapol_key
*key
,
30 u8 pmk_r1_name
[WPA_PMK_NAME_LEN
];
31 u8 ptk_name
[WPA_PMK_NAME_LEN
];
32 const u8
*anonce
= key
->key_nonce
;
34 if (sm
->xxkey_len
== 0) {
35 wpa_printf(MSG_DEBUG
, "FT: XXKey not available for key "
40 wpa_derive_pmk_r0(sm
->xxkey
, sm
->xxkey_len
, sm
->ssid
,
41 sm
->ssid_len
, sm
->mobility_domain
,
42 sm
->r0kh_id
, sm
->r0kh_id_len
, sm
->own_addr
,
43 sm
->pmk_r0
, sm
->pmk_r0_name
);
44 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R0", sm
->pmk_r0
, PMK_LEN
);
45 wpa_hexdump(MSG_DEBUG
, "FT: PMKR0Name",
46 sm
->pmk_r0_name
, WPA_PMK_NAME_LEN
);
47 wpa_derive_pmk_r1(sm
->pmk_r0
, sm
->pmk_r0_name
, sm
->r1kh_id
,
48 sm
->own_addr
, sm
->pmk_r1
, pmk_r1_name
);
49 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1", sm
->pmk_r1
, PMK_LEN
);
50 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name", pmk_r1_name
, WPA_PMK_NAME_LEN
);
51 wpa_pmk_r1_to_ptk(sm
->pmk_r1
, sm
->snonce
, anonce
, sm
->own_addr
,
52 sm
->bssid
, pmk_r1_name
,
53 (u8
*) ptk
, sizeof(*ptk
), ptk_name
);
54 wpa_hexdump_key(MSG_DEBUG
, "FT: PTK", (u8
*) ptk
, sizeof(*ptk
));
55 wpa_hexdump(MSG_DEBUG
, "FT: PTKName", ptk_name
, WPA_PMK_NAME_LEN
);
62 * wpa_sm_set_ft_params - Set FT (IEEE 802.11r) parameters
63 * @sm: Pointer to WPA state machine data from wpa_sm_init()
64 * @mobility_domain: Mobility domain identifier (2 octets)
65 * @r0kh_id: PMK-R0 key holder identity (1-48 octets)
66 * @r0kh_id_len: R0KH-ID length (1-48)
67 * @r1kh_id: PMK-R1 key holder identity (16 octets)
68 * Returns: 0 on success, -1 on failure
70 int wpa_sm_set_ft_params(struct wpa_sm
*sm
, const u8
*mobility_domain
,
71 const u8
*r0kh_id
, size_t r0kh_id_len
,
74 if (sm
&& mobility_domain
) {
75 wpa_hexdump(MSG_DEBUG
, "FT: Mobility domain",
76 mobility_domain
, MOBILITY_DOMAIN_ID_LEN
);
77 os_memcpy(sm
->mobility_domain
, mobility_domain
,
78 MOBILITY_DOMAIN_ID_LEN
);
80 os_memset(sm
->mobility_domain
, 0, MOBILITY_DOMAIN_ID_LEN
);
83 if (r0kh_id_len
> FT_R0KH_ID_MAX_LEN
)
85 wpa_hexdump(MSG_DEBUG
, "FT: R0KH-ID", r0kh_id
, r0kh_id_len
);
86 os_memcpy(sm
->r0kh_id
, r0kh_id
, r0kh_id_len
);
87 sm
->r0kh_id_len
= r0kh_id_len
;
89 /* FIX: When should R0KH-ID be cleared? We need to keep the
90 * old R0KH-ID in order to be able to use this during FT. */
92 * os_memset(sm->r0kh_id, 0, FT_R0KH_ID_LEN);
93 * sm->r0kh_id_len = 0;
98 wpa_hexdump(MSG_DEBUG
, "FT: R1KH-ID", r1kh_id
, FT_R1KH_ID_LEN
);
99 os_memcpy(sm
->r1kh_id
, r1kh_id
, FT_R1KH_ID_LEN
);
101 os_memset(sm
->r1kh_id
, 0, FT_R1KH_ID_LEN
);
108 * wpa_ft_gen_req_ies - Generate FT (IEEE 802.11r) IEs for Auth Request
109 * @sm: Pointer to WPA state machine data from wpa_sm_init()
110 * @len: Buffer for returning the length of the IEs
111 * @anonce: ANonce or %NULL if not yet available
112 * @pmk_name: PMKR0Name or PMKR1Name to be added into the RSN IE PMKID List
113 * @kck: 128-bit KCK for MIC or %NULL if no MIC is used
114 * @target_ap: Target AP address
115 * Returns: Pointer to buffer with IEs or %NULL on failure
117 * Caller is responsible for freeing the returned buffer with os_free();
119 static u8
* wpa_ft_gen_req_ies(struct wpa_sm
*sm
, size_t *len
,
120 const u8
*anonce
, const u8
*pmk_name
,
121 const u8
*kck
, const u8
*target_ap
)
124 u8
*buf
, *pos
, *ftie_len
, *ftie_pos
;
125 struct rsn_mdie
*mdie
;
126 struct rsn_ftie
*ftie
;
127 struct rsn_ie_hdr
*rsnie
;
130 sm
->ft_completed
= 0;
132 buf_len
= 2 + sizeof(struct rsn_mdie
) + 2 + sizeof(struct rsn_ftie
) +
133 2 + sm
->r0kh_id_len
+ 100;
134 buf
= os_zalloc(buf_len
);
139 /* RSNIE[PMKR0Name] */
140 rsnie
= (struct rsn_ie_hdr
*) pos
;
141 rsnie
->elem_id
= WLAN_EID_RSN
;
142 WPA_PUT_LE16(rsnie
->version
, RSN_VERSION
);
143 pos
= (u8
*) (rsnie
+ 1);
145 /* Group Suite Selector */
146 if (sm
->group_cipher
== WPA_CIPHER_CCMP
)
147 RSN_SELECTOR_PUT(pos
, RSN_CIPHER_SUITE_CCMP
);
148 else if (sm
->group_cipher
== WPA_CIPHER_TKIP
)
149 RSN_SELECTOR_PUT(pos
, RSN_CIPHER_SUITE_TKIP
);
151 wpa_printf(MSG_WARNING
, "FT: Invalid group cipher (%d)",
156 pos
+= RSN_SELECTOR_LEN
;
158 /* Pairwise Suite Count */
159 WPA_PUT_LE16(pos
, 1);
162 /* Pairwise Suite List */
163 if (sm
->pairwise_cipher
== WPA_CIPHER_CCMP
)
164 RSN_SELECTOR_PUT(pos
, RSN_CIPHER_SUITE_CCMP
);
165 else if (sm
->pairwise_cipher
== WPA_CIPHER_TKIP
)
166 RSN_SELECTOR_PUT(pos
, RSN_CIPHER_SUITE_TKIP
);
168 wpa_printf(MSG_WARNING
, "FT: Invalid pairwise cipher (%d)",
169 sm
->pairwise_cipher
);
173 pos
+= RSN_SELECTOR_LEN
;
175 /* Authenticated Key Management Suite Count */
176 WPA_PUT_LE16(pos
, 1);
179 /* Authenticated Key Management Suite List */
180 if (sm
->key_mgmt
== WPA_KEY_MGMT_FT_IEEE8021X
)
181 RSN_SELECTOR_PUT(pos
, RSN_AUTH_KEY_MGMT_FT_802_1X
);
182 else if (sm
->key_mgmt
== WPA_KEY_MGMT_FT_PSK
)
183 RSN_SELECTOR_PUT(pos
, RSN_AUTH_KEY_MGMT_FT_PSK
);
185 wpa_printf(MSG_WARNING
, "FT: Invalid key management type (%d)",
190 pos
+= RSN_SELECTOR_LEN
;
192 /* RSN Capabilities */
194 #ifdef CONFIG_IEEE80211W
195 if (sm
->mgmt_group_cipher
== WPA_CIPHER_AES_128_CMAC
)
196 capab
|= WPA_CAPABILITY_MGMT_FRAME_PROTECTION
;
197 #endif /* CONFIG_IEEE80211W */
198 WPA_PUT_LE16(pos
, capab
);
202 WPA_PUT_LE16(pos
, 1);
205 /* PMKID List [PMKR0Name/PMKR1Name] */
206 os_memcpy(pos
, pmk_name
, WPA_PMK_NAME_LEN
);
207 pos
+= WPA_PMK_NAME_LEN
;
209 #ifdef CONFIG_IEEE80211W
210 if (sm
->mgmt_group_cipher
== WPA_CIPHER_AES_128_CMAC
) {
211 /* Management Group Cipher Suite */
212 RSN_SELECTOR_PUT(pos
, RSN_CIPHER_SUITE_AES_128_CMAC
);
213 pos
+= RSN_SELECTOR_LEN
;
215 #endif /* CONFIG_IEEE80211W */
217 rsnie
->len
= (pos
- (u8
*) rsnie
) - 2;
220 *pos
++ = WLAN_EID_MOBILITY_DOMAIN
;
221 *pos
++ = sizeof(*mdie
);
222 mdie
= (struct rsn_mdie
*) pos
;
223 pos
+= sizeof(*mdie
);
224 os_memcpy(mdie
->mobility_domain
, sm
->mobility_domain
,
225 MOBILITY_DOMAIN_ID_LEN
);
226 mdie
->ft_capab
= 0; /* FIX: copy from the target AP's MDIE */
228 /* FTIE[SNonce, R0KH-ID] */
230 *pos
++ = WLAN_EID_FAST_BSS_TRANSITION
;
232 ftie
= (struct rsn_ftie
*) pos
;
233 pos
+= sizeof(*ftie
);
234 os_memcpy(ftie
->snonce
, sm
->snonce
, WPA_NONCE_LEN
);
236 os_memcpy(ftie
->anonce
, anonce
, WPA_NONCE_LEN
);
237 /* R0KH-ID sub-element */
238 *pos
++ = FTIE_SUBELEM_R0KH_ID
;
239 *pos
++ = sm
->r0kh_id_len
;
240 os_memcpy(pos
, sm
->r0kh_id
, sm
->r0kh_id_len
);
241 pos
+= sm
->r0kh_id_len
;
242 *ftie_len
= pos
- ftie_len
- 1;
246 * IEEE 802.11r/D9.0, 11A.8.4
247 * MIC shall be calculated over:
248 * non-AP STA MAC address
249 * Target AP MAC address
250 * Transaction seq number (5 for ReassocReq, 3 otherwise)
253 * FTIE (with MIC field set to 0)
254 * RIC-Request (if present)
256 ftie
->mic_control
[1] = 3; /* Information element count */
257 if (wpa_ft_mic(kck
, sm
->own_addr
, target_ap
, 5,
258 ((u8
*) mdie
) - 2, 2 + sizeof(*mdie
),
259 ftie_pos
, 2 + *ftie_len
,
260 (u8
*) rsnie
, 2 + rsnie
->len
, NULL
, 0,
262 wpa_printf(MSG_INFO
, "FT: Failed to calculate MIC");
292 static int wpa_ft_parse_ftie(const u8
*ie
, size_t ie_len
,
293 struct wpa_ft_ies
*parse
)
298 parse
->ftie_len
= ie_len
;
300 pos
= ie
+ sizeof(struct rsn_ftie
);
303 while (pos
+ 2 <= end
&& pos
+ 2 + pos
[1] <= end
) {
305 case FTIE_SUBELEM_R1KH_ID
:
306 if (pos
[1] != FT_R1KH_ID_LEN
) {
307 wpa_printf(MSG_DEBUG
, "FT: Invalid R1KH-ID "
308 "length in FTIE: %d", pos
[1]);
311 parse
->r1kh_id
= pos
+ 2;
313 case FTIE_SUBELEM_GTK
:
314 parse
->gtk
= pos
+ 2;
315 parse
->gtk_len
= pos
[1];
317 case FTIE_SUBELEM_R0KH_ID
:
318 if (pos
[1] < 1 || pos
[1] > FT_R0KH_ID_MAX_LEN
) {
319 wpa_printf(MSG_DEBUG
, "FT: Invalid R0KH-ID "
320 "length in FTIE: %d", pos
[1]);
323 parse
->r0kh_id
= pos
+ 2;
324 parse
->r0kh_id_len
= pos
[1];
335 static int wpa_ft_parse_ies(const u8
*ies
, size_t ies_len
,
336 struct wpa_ft_ies
*parse
)
339 struct wpa_ie_data data
;
342 os_memset(parse
, 0, sizeof(*parse
));
348 while (pos
+ 2 <= end
&& pos
+ 2 + pos
[1] <= end
) {
351 parse
->rsn
= pos
+ 2;
352 parse
->rsn_len
= pos
[1];
353 ret
= wpa_parse_wpa_ie_rsn(parse
->rsn
- 2,
357 wpa_printf(MSG_DEBUG
, "FT: Failed to parse "
361 if (data
.num_pmkid
== 1 && data
.pmkid
)
362 parse
->rsn_pmkid
= data
.pmkid
;
364 case WLAN_EID_MOBILITY_DOMAIN
:
365 parse
->mdie
= pos
+ 2;
366 parse
->mdie_len
= pos
[1];
368 case WLAN_EID_FAST_BSS_TRANSITION
:
369 if (wpa_ft_parse_ftie(pos
+ 2, pos
[1], parse
) < 0)
372 case WLAN_EID_TIMEOUT_INTERVAL
:
373 parse
->tie
= pos
+ 2;
374 parse
->tie_len
= pos
[1];
385 static int wpa_ft_install_ptk(struct wpa_sm
*sm
, const u8
*bssid
)
389 u8 null_rsc
[6] = { 0, 0, 0, 0, 0, 0 };
391 wpa_printf(MSG_DEBUG
, "FT: Installing PTK to the driver.");
393 switch (sm
->pairwise_cipher
) {
394 case WPA_CIPHER_CCMP
:
398 case WPA_CIPHER_TKIP
:
403 wpa_printf(MSG_WARNING
, "FT: Unsupported pairwise cipher %d",
404 sm
->pairwise_cipher
);
408 if (wpa_sm_set_key(sm
, alg
, bssid
, 0, 1, null_rsc
,
409 sizeof(null_rsc
), (u8
*) sm
->ptk
.tk1
, keylen
) < 0) {
410 wpa_printf(MSG_WARNING
, "FT: Failed to set PTK to the driver");
419 * wpa_ft_prepare_auth_request - Generate over-the-air auth request
420 * @sm: Pointer to WPA state machine data from wpa_sm_init()
421 * Returns: 0 on success, -1 on failure
423 int wpa_ft_prepare_auth_request(struct wpa_sm
*sm
)
428 /* Generate a new SNonce */
429 if (os_get_random(sm
->snonce
, WPA_NONCE_LEN
)) {
430 wpa_printf(MSG_INFO
, "FT: Failed to generate a new SNonce");
434 ft_ies
= wpa_ft_gen_req_ies(sm
, &ft_ies_len
, NULL
, sm
->pmk_r0_name
,
437 wpa_sm_update_ft_ies(sm
, sm
->mobility_domain
,
446 int wpa_ft_process_response(struct wpa_sm
*sm
, const u8
*ies
, size_t ies_len
,
447 int ft_action
, const u8
*target_ap
)
451 struct wpa_ft_ies parse
;
452 struct rsn_mdie
*mdie
;
453 struct rsn_ftie
*ftie
;
454 u8 ptk_name
[WPA_PMK_NAME_LEN
];
458 wpa_hexdump(MSG_DEBUG
, "FT: Response IEs", ies
, ies_len
);
461 if (!sm
->over_the_ds_in_progress
) {
462 wpa_printf(MSG_DEBUG
, "FT: No over-the-DS in progress "
463 "- drop FT Action Response");
467 if (os_memcmp(target_ap
, sm
->target_ap
, ETH_ALEN
) != 0) {
468 wpa_printf(MSG_DEBUG
, "FT: No over-the-DS in progress "
469 "with this Target AP - drop FT Action "
475 if (sm
->key_mgmt
!= WPA_KEY_MGMT_FT_IEEE8021X
&&
476 sm
->key_mgmt
!= WPA_KEY_MGMT_FT_PSK
) {
477 wpa_printf(MSG_DEBUG
, "FT: Reject FT IEs since FT is not "
478 "enabled for this connection");
482 if (wpa_ft_parse_ies(ies
, ies_len
, &parse
) < 0) {
483 wpa_printf(MSG_DEBUG
, "FT: Failed to parse IEs");
487 mdie
= (struct rsn_mdie
*) parse
.mdie
;
488 if (mdie
== NULL
|| parse
.mdie_len
< sizeof(*mdie
) ||
489 os_memcmp(mdie
->mobility_domain
, sm
->mobility_domain
,
490 MOBILITY_DOMAIN_ID_LEN
) != 0) {
491 wpa_printf(MSG_DEBUG
, "FT: Invalid MDIE");
495 ftie
= (struct rsn_ftie
*) parse
.ftie
;
496 if (ftie
== NULL
|| parse
.ftie_len
< sizeof(*ftie
)) {
497 wpa_printf(MSG_DEBUG
, "FT: Invalid FTIE");
501 if (parse
.r0kh_id
== NULL
) {
502 wpa_printf(MSG_DEBUG
, "FT: No R0KH-ID subelem in FTIE");
506 if (parse
.r0kh_id_len
!= sm
->r0kh_id_len
||
507 os_memcmp(parse
.r0kh_id
, sm
->r0kh_id
, parse
.r0kh_id_len
) != 0) {
508 wpa_printf(MSG_DEBUG
, "FT: R0KH-ID in FTIE did not match with "
509 "the current R0KH-ID");
510 wpa_hexdump(MSG_DEBUG
, "FT: R0KH-ID in FTIE",
511 parse
.r0kh_id
, parse
.r0kh_id_len
);
512 wpa_hexdump(MSG_DEBUG
, "FT: The current R0KH-ID",
513 sm
->r0kh_id
, sm
->r0kh_id_len
);
517 if (parse
.r1kh_id
== NULL
) {
518 wpa_printf(MSG_DEBUG
, "FT: No R1KH-ID subelem in FTIE");
522 if (parse
.rsn_pmkid
== NULL
||
523 os_memcmp(parse
.rsn_pmkid
, sm
->pmk_r0_name
, WPA_PMK_NAME_LEN
)) {
524 wpa_printf(MSG_DEBUG
, "FT: No matching PMKR0Name (PMKID) in "
529 os_memcpy(sm
->r1kh_id
, parse
.r1kh_id
, FT_R1KH_ID_LEN
);
530 wpa_hexdump(MSG_DEBUG
, "FT: R1KH-ID", sm
->r1kh_id
, FT_R1KH_ID_LEN
);
531 wpa_hexdump(MSG_DEBUG
, "FT: SNonce", sm
->snonce
, WPA_NONCE_LEN
);
532 wpa_hexdump(MSG_DEBUG
, "FT: ANonce", ftie
->anonce
, WPA_NONCE_LEN
);
533 wpa_derive_pmk_r1(sm
->pmk_r0
, sm
->pmk_r0_name
, sm
->r1kh_id
,
534 sm
->own_addr
, sm
->pmk_r1
, sm
->pmk_r1_name
);
535 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1", sm
->pmk_r1
, PMK_LEN
);
536 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name",
537 sm
->pmk_r1_name
, WPA_PMK_NAME_LEN
);
540 wpa_pmk_r1_to_ptk(sm
->pmk_r1
, sm
->snonce
, ftie
->anonce
, sm
->own_addr
,
541 bssid
, sm
->pmk_r1_name
,
542 (u8
*) &sm
->ptk
, sizeof(sm
->ptk
), ptk_name
);
543 wpa_hexdump_key(MSG_DEBUG
, "FT: PTK",
544 (u8
*) &sm
->ptk
, sizeof(sm
->ptk
));
545 wpa_hexdump(MSG_DEBUG
, "FT: PTKName", ptk_name
, WPA_PMK_NAME_LEN
);
547 ft_ies
= wpa_ft_gen_req_ies(sm
, &ft_ies_len
, ftie
->anonce
,
548 sm
->pmk_r1_name
, sm
->ptk
.kck
, bssid
);
550 wpa_sm_update_ft_ies(sm
, sm
->mobility_domain
,
555 ret
= wpa_ft_install_ptk(sm
, bssid
);
558 sm
->ft_completed
= 1;
560 /* TODO: trigger re-association to the Target AP;
561 * MLME is now doing this automatically, but it should
562 * really be done only if we get here successfully. */
563 os_memcpy(sm
->bssid
, target_ap
, ETH_ALEN
);
571 int wpa_ft_is_completed(struct wpa_sm
*sm
)
576 if (sm
->key_mgmt
!= WPA_KEY_MGMT_FT_IEEE8021X
&&
577 sm
->key_mgmt
!= WPA_KEY_MGMT_FT_PSK
)
580 return sm
->ft_completed
;
584 int wpa_ft_validate_reassoc_resp(struct wpa_sm
*sm
, const u8
*ies
,
585 size_t ies_len
, const u8
*src_addr
)
587 struct wpa_ft_ies parse
;
588 struct rsn_mdie
*mdie
;
589 struct rsn_ftie
*ftie
;
590 size_t count
, gtk_len
, keylen
, rsc_len
;
596 wpa_hexdump(MSG_DEBUG
, "FT: Response IEs", ies
, ies_len
);
598 if (sm
->key_mgmt
!= WPA_KEY_MGMT_FT_IEEE8021X
&&
599 sm
->key_mgmt
!= WPA_KEY_MGMT_FT_PSK
) {
600 wpa_printf(MSG_DEBUG
, "FT: Reject FT IEs since FT is not "
601 "enabled for this connection");
605 if (wpa_ft_parse_ies(ies
, ies_len
, &parse
) < 0) {
606 wpa_printf(MSG_DEBUG
, "FT: Failed to parse IEs");
610 mdie
= (struct rsn_mdie
*) parse
.mdie
;
611 if (mdie
== NULL
|| parse
.mdie_len
< sizeof(*mdie
) ||
612 os_memcmp(mdie
->mobility_domain
, sm
->mobility_domain
,
613 MOBILITY_DOMAIN_ID_LEN
) != 0) {
614 wpa_printf(MSG_DEBUG
, "FT: Invalid MDIE");
618 ftie
= (struct rsn_ftie
*) parse
.ftie
;
619 if (ftie
== NULL
|| parse
.ftie_len
< sizeof(*ftie
)) {
620 wpa_printf(MSG_DEBUG
, "FT: Invalid FTIE");
624 if (parse
.r0kh_id
== NULL
) {
625 wpa_printf(MSG_DEBUG
, "FT: No R0KH-ID subelem in FTIE");
629 if (parse
.r0kh_id_len
!= sm
->r0kh_id_len
||
630 os_memcmp(parse
.r0kh_id
, sm
->r0kh_id
, parse
.r0kh_id_len
) != 0) {
631 wpa_printf(MSG_DEBUG
, "FT: R0KH-ID in FTIE did not match with "
632 "the current R0KH-ID");
633 wpa_hexdump(MSG_DEBUG
, "FT: R0KH-ID in FTIE",
634 parse
.r0kh_id
, parse
.r0kh_id_len
);
635 wpa_hexdump(MSG_DEBUG
, "FT: The current R0KH-ID",
636 sm
->r0kh_id
, sm
->r0kh_id_len
);
640 if (parse
.r1kh_id
== NULL
) {
641 wpa_printf(MSG_DEBUG
, "FT: No R1KH-ID subelem in FTIE");
645 if (os_memcmp(parse
.r1kh_id
, sm
->r1kh_id
, FT_R1KH_ID_LEN
) != 0) {
646 wpa_printf(MSG_DEBUG
, "FT: Unknown R1KH-ID used in "
651 if (parse
.rsn_pmkid
== NULL
||
652 os_memcmp(parse
.rsn_pmkid
, sm
->pmk_r1_name
, WPA_PMK_NAME_LEN
)) {
653 wpa_printf(MSG_DEBUG
, "FT: No matching PMKR1Name (PMKID) in "
654 "RSNIE (pmkid=%d)", !!parse
.rsn_pmkid
);
662 if (ftie
->mic_control
[1] != count
) {
663 wpa_printf(MSG_DEBUG
, "FT: Unexpected IE count in FTIE (%d)",
664 ftie
->mic_control
[1]);
668 if (wpa_ft_mic(sm
->ptk
.kck
, sm
->own_addr
, src_addr
, 6,
669 parse
.mdie
- 2, parse
.mdie_len
+ 2,
670 parse
.ftie
- 2, parse
.ftie_len
+ 2,
671 parse
.rsn
- 2, parse
.rsn_len
+ 2, NULL
, 0,
673 wpa_printf(MSG_DEBUG
, "FT: Failed to calculate MIC");
677 if (os_memcmp(mic
, ftie
->mic
, 16) != 0) {
678 wpa_printf(MSG_DEBUG
, "FT: Invalid MIC in FTIE");
679 wpa_hexdump(MSG_MSGDUMP
, "FT: Received MIC", ftie
->mic
, 16);
680 wpa_hexdump(MSG_MSGDUMP
, "FT: Calculated MIC", mic
, 16);
684 if (parse
.gtk
== NULL
) {
685 wpa_printf(MSG_DEBUG
, "FT: No GTK included in FTIE");
689 wpa_hexdump_key(MSG_DEBUG
, "FT: Received GTK in Reassoc Resp",
690 parse
.gtk
, parse
.gtk_len
);
692 if (parse
.gtk_len
< 10 + 24 || (parse
.gtk_len
- 10) % 8 ||
693 parse
.gtk_len
- 18 > sizeof(gtk
)) {
694 wpa_printf(MSG_DEBUG
, "FT: Invalid GTK sub-elem "
695 "length %lu", (unsigned long) parse
.gtk_len
);
698 gtk_len
= parse
.gtk_len
- 18;
699 if (aes_unwrap(sm
->ptk
.kek
, gtk_len
/ 8, parse
.gtk
+ 10, gtk
)) {
700 wpa_printf(MSG_WARNING
, "FT: AES unwrap failed - could not "
705 switch (sm
->group_cipher
) {
706 case WPA_CIPHER_CCMP
:
711 case WPA_CIPHER_TKIP
:
716 case WPA_CIPHER_WEP104
:
721 case WPA_CIPHER_WEP40
:
727 wpa_printf(MSG_WARNING
, "WPA: Unsupported Group Cipher %d",
732 if (gtk_len
< keylen
) {
733 wpa_printf(MSG_DEBUG
, "FT: Too short GTK in FTIE");
737 /* Key Info[1] | Key Length[1] | RSC[8] | Key[5..32]. */
739 keyidx
= parse
.gtk
[0] & 0x03;
741 if (parse
.gtk
[1] != keylen
) {
742 wpa_printf(MSG_DEBUG
, "FT: GTK length mismatch: received %d "
744 parse
.gtk
[1], (unsigned long) keylen
);
748 wpa_hexdump_key(MSG_DEBUG
, "FT: GTK from Reassoc Resp", gtk
, keylen
);
749 if (wpa_sm_set_key(sm
, alg
, (u8
*) "\xff\xff\xff\xff\xff\xff",
750 keyidx
, 0, parse
.gtk
+ 2, rsc_len
, gtk
, keylen
) < 0)
752 wpa_printf(MSG_WARNING
, "WPA: Failed to set GTK to the "
762 * wpa_ft_start_over_ds - Generate over-the-DS auth request
763 * @sm: Pointer to WPA state machine data from wpa_sm_init()
764 * Returns: 0 on success, -1 on failure
766 int wpa_ft_start_over_ds(struct wpa_sm
*sm
, const u8
*target_ap
)
771 wpa_printf(MSG_DEBUG
, "FT: Request over-the-DS with " MACSTR
,
774 /* Generate a new SNonce */
775 if (os_get_random(sm
->snonce
, WPA_NONCE_LEN
)) {
776 wpa_printf(MSG_INFO
, "FT: Failed to generate a new SNonce");
780 ft_ies
= wpa_ft_gen_req_ies(sm
, &ft_ies_len
, NULL
, sm
->pmk_r0_name
,
783 sm
->over_the_ds_in_progress
= 1;
784 os_memcpy(sm
->target_ap
, target_ap
, ETH_ALEN
);
785 wpa_sm_send_ft_action(sm
, 1, target_ap
, ft_ies
, ft_ies_len
);
792 #endif /* CONFIG_IEEE80211R */