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 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, sm->pmk_r1_name);
49 wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R1", sm->pmk_r1, PMK_LEN);
50 wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name", sm->pmk_r1_name,
52 wpa_pmk_r1_to_ptk(sm->pmk_r1, sm->snonce, anonce, sm->own_addr,
53 sm->bssid, sm->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 + 1 octet)
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);
80 sm->mdie_ft_capab = mobility_domain[MOBILITY_DOMAIN_ID_LEN];
81 wpa_printf(MSG_DEBUG, "FT: Capability and Policy: 0x%02x",
84 os_memset(sm->mobility_domain, 0, MOBILITY_DOMAIN_ID_LEN);
87 if (r0kh_id_len > FT_R0KH_ID_MAX_LEN)
89 wpa_hexdump(MSG_DEBUG, "FT: R0KH-ID", r0kh_id, r0kh_id_len);
90 os_memcpy(sm->r0kh_id, r0kh_id, r0kh_id_len);
91 sm->r0kh_id_len = r0kh_id_len;
93 /* FIX: When should R0KH-ID be cleared? We need to keep the
94 * old R0KH-ID in order to be able to use this during FT. */
96 * os_memset(sm->r0kh_id, 0, FT_R0KH_ID_LEN);
97 * sm->r0kh_id_len = 0;
102 wpa_hexdump(MSG_DEBUG, "FT: R1KH-ID", r1kh_id, FT_R1KH_ID_LEN);
103 os_memcpy(sm->r1kh_id, r1kh_id, FT_R1KH_ID_LEN);
105 os_memset(sm->r1kh_id, 0, FT_R1KH_ID_LEN);
112 * wpa_ft_gen_req_ies - Generate FT (IEEE 802.11r) IEs for Auth/ReAssoc Request
113 * @sm: Pointer to WPA state machine data from wpa_sm_init()
114 * @len: Buffer for returning the length of the IEs
115 * @anonce: ANonce or %NULL if not yet available
116 * @pmk_name: PMKR0Name or PMKR1Name to be added into the RSN IE PMKID List
117 * @kck: 128-bit KCK for MIC or %NULL if no MIC is used
118 * @target_ap: Target AP address
119 * @ric_ies: Optional IE(s), e.g., WMM TSPEC(s), for RIC-Request or %NULL
120 * @ric_ies_len: Length of ric_ies buffer in octets
121 * @ap_mdie: Mobility Domain IE from the target AP
122 * Returns: Pointer to buffer with IEs or %NULL on failure
124 * Caller is responsible for freeing the returned buffer with os_free();
126 static u8 * wpa_ft_gen_req_ies(struct wpa_sm *sm, size_t *len,
127 const u8 *anonce, const u8 *pmk_name,
128 const u8 *kck, const u8 *target_ap,
129 const u8 *ric_ies, size_t ric_ies_len,
133 u8 *buf, *pos, *ftie_len, *ftie_pos;
134 struct rsn_mdie *mdie;
135 struct rsn_ftie *ftie;
136 struct rsn_ie_hdr *rsnie;
139 sm->ft_completed = 0;
141 buf_len = 2 + sizeof(struct rsn_mdie) + 2 + sizeof(struct rsn_ftie) +
142 2 + sm->r0kh_id_len + ric_ies_len + 100;
143 buf = os_zalloc(buf_len);
148 /* RSNIE[PMKR0Name/PMKR1Name] */
149 rsnie = (struct rsn_ie_hdr *) pos;
150 rsnie->elem_id = WLAN_EID_RSN;
151 WPA_PUT_LE16(rsnie->version, RSN_VERSION);
152 pos = (u8 *) (rsnie + 1);
154 /* Group Suite Selector */
155 if (sm->group_cipher == WPA_CIPHER_CCMP)
156 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_CCMP);
157 else if (sm->group_cipher == WPA_CIPHER_TKIP)
158 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_TKIP);
160 wpa_printf(MSG_WARNING, "FT: Invalid group cipher (%d)",
165 pos += RSN_SELECTOR_LEN;
167 /* Pairwise Suite Count */
168 WPA_PUT_LE16(pos, 1);
171 /* Pairwise Suite List */
172 if (sm->pairwise_cipher == WPA_CIPHER_CCMP)
173 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_CCMP);
174 else if (sm->pairwise_cipher == WPA_CIPHER_TKIP)
175 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_TKIP);
177 wpa_printf(MSG_WARNING, "FT: Invalid pairwise cipher (%d)",
178 sm->pairwise_cipher);
182 pos += RSN_SELECTOR_LEN;
184 /* Authenticated Key Management Suite Count */
185 WPA_PUT_LE16(pos, 1);
188 /* Authenticated Key Management Suite List */
189 if (sm->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X)
190 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FT_802_1X);
191 else if (sm->key_mgmt == WPA_KEY_MGMT_FT_PSK)
192 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FT_PSK);
194 wpa_printf(MSG_WARNING, "FT: Invalid key management type (%d)",
199 pos += RSN_SELECTOR_LEN;
201 /* RSN Capabilities */
203 #ifdef CONFIG_IEEE80211W
204 if (sm->mgmt_group_cipher == WPA_CIPHER_AES_128_CMAC)
205 capab |= WPA_CAPABILITY_MFPC;
206 #endif /* CONFIG_IEEE80211W */
207 WPA_PUT_LE16(pos, capab);
211 WPA_PUT_LE16(pos, 1);
214 /* PMKID List [PMKR0Name/PMKR1Name] */
215 os_memcpy(pos, pmk_name, WPA_PMK_NAME_LEN);
216 pos += WPA_PMK_NAME_LEN;
218 #ifdef CONFIG_IEEE80211W
219 if (sm->mgmt_group_cipher == WPA_CIPHER_AES_128_CMAC) {
220 /* Management Group Cipher Suite */
221 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_AES_128_CMAC);
222 pos += RSN_SELECTOR_LEN;
224 #endif /* CONFIG_IEEE80211W */
226 rsnie->len = (pos - (u8 *) rsnie) - 2;
229 *pos++ = WLAN_EID_MOBILITY_DOMAIN;
230 *pos++ = sizeof(*mdie);
231 mdie = (struct rsn_mdie *) pos;
232 pos += sizeof(*mdie);
233 os_memcpy(mdie->mobility_domain, sm->mobility_domain,
234 MOBILITY_DOMAIN_ID_LEN);
235 mdie->ft_capab = ap_mdie && ap_mdie[1] >= 3 ? ap_mdie[4] :
238 /* FTIE[SNonce, [R1KH-ID,] R0KH-ID ] */
240 *pos++ = WLAN_EID_FAST_BSS_TRANSITION;
242 ftie = (struct rsn_ftie *) pos;
243 pos += sizeof(*ftie);
244 os_memcpy(ftie->snonce, sm->snonce, WPA_NONCE_LEN);
246 os_memcpy(ftie->anonce, anonce, WPA_NONCE_LEN);
248 /* R1KH-ID sub-element in third FT message */
249 *pos++ = FTIE_SUBELEM_R1KH_ID;
250 *pos++ = FT_R1KH_ID_LEN;
251 os_memcpy(pos, sm->r1kh_id, FT_R1KH_ID_LEN);
252 pos += FT_R1KH_ID_LEN;
254 /* R0KH-ID sub-element */
255 *pos++ = FTIE_SUBELEM_R0KH_ID;
256 *pos++ = sm->r0kh_id_len;
257 os_memcpy(pos, sm->r0kh_id, sm->r0kh_id_len);
258 pos += sm->r0kh_id_len;
259 *ftie_len = pos - ftie_len - 1;
263 os_memcpy(pos, ric_ies, ric_ies_len);
269 * IEEE Std 802.11r-2008, 11A.8.4
270 * MIC shall be calculated over:
271 * non-AP STA MAC address
272 * Target AP MAC address
273 * Transaction seq number (5 for ReassocReq, 3 otherwise)
276 * FTIE (with MIC field set to 0)
277 * RIC-Request (if present)
279 /* Information element count */
280 ftie->mic_control[1] = 3 + ieee802_11_ie_count(ric_ies,
282 if (wpa_ft_mic(kck, sm->own_addr, target_ap, 5,
283 ((u8 *) mdie) - 2, 2 + sizeof(*mdie),
284 ftie_pos, 2 + *ftie_len,
285 (u8 *) rsnie, 2 + rsnie->len, ric_ies,
286 ric_ies_len, ftie->mic) < 0) {
287 wpa_printf(MSG_INFO, "FT: Failed to calculate MIC");
321 static int wpa_ft_parse_ftie(const u8 *ie, size_t ie_len,
322 struct wpa_ft_ies *parse)
327 parse->ftie_len = ie_len;
329 pos = ie + sizeof(struct rsn_ftie);
332 while (pos + 2 <= end && pos + 2 + pos[1] <= end) {
334 case FTIE_SUBELEM_R1KH_ID:
335 if (pos[1] != FT_R1KH_ID_LEN) {
336 wpa_printf(MSG_DEBUG, "FT: Invalid R1KH-ID "
337 "length in FTIE: %d", pos[1]);
340 parse->r1kh_id = pos + 2;
342 case FTIE_SUBELEM_GTK:
343 parse->gtk = pos + 2;
344 parse->gtk_len = pos[1];
346 case FTIE_SUBELEM_R0KH_ID:
347 if (pos[1] < 1 || pos[1] > FT_R0KH_ID_MAX_LEN) {
348 wpa_printf(MSG_DEBUG, "FT: Invalid R0KH-ID "
349 "length in FTIE: %d", pos[1]);
352 parse->r0kh_id = pos + 2;
353 parse->r0kh_id_len = pos[1];
355 #ifdef CONFIG_IEEE80211W
356 case FTIE_SUBELEM_IGTK:
357 parse->igtk = pos + 2;
358 parse->igtk_len = pos[1];
360 #endif /* CONFIG_IEEE80211W */
370 static int wpa_ft_parse_ies(const u8 *ies, size_t ies_len,
371 struct wpa_ft_ies *parse)
374 struct wpa_ie_data data;
376 const struct rsn_ftie *ftie;
377 int prot_ie_count = 0;
379 os_memset(parse, 0, sizeof(*parse));
385 while (pos + 2 <= end && pos + 2 + pos[1] <= end) {
388 parse->rsn = pos + 2;
389 parse->rsn_len = pos[1];
390 ret = wpa_parse_wpa_ie_rsn(parse->rsn - 2,
394 wpa_printf(MSG_DEBUG, "FT: Failed to parse "
398 if (data.num_pmkid == 1 && data.pmkid)
399 parse->rsn_pmkid = data.pmkid;
401 case WLAN_EID_MOBILITY_DOMAIN:
402 parse->mdie = pos + 2;
403 parse->mdie_len = pos[1];
405 case WLAN_EID_FAST_BSS_TRANSITION:
406 if (pos[1] < sizeof(*ftie))
408 ftie = (const struct rsn_ftie *) (pos + 2);
409 prot_ie_count = ftie->mic_control[1];
410 if (wpa_ft_parse_ftie(pos + 2, pos[1], parse) < 0)
413 case WLAN_EID_TIMEOUT_INTERVAL:
414 parse->tie = pos + 2;
415 parse->tie_len = pos[1];
417 case WLAN_EID_RIC_DATA:
418 if (parse->ric == NULL)
425 if (prot_ie_count == 0)
426 return 0; /* no MIC */
429 * Check that the protected IE count matches with IEs included in the
440 if (prot_ie_count < 0) {
441 wpa_printf(MSG_DEBUG, "FT: Some required IEs not included in "
442 "the protected IE count");
446 if (prot_ie_count == 0 && parse->ric) {
447 wpa_printf(MSG_DEBUG, "FT: RIC IE(s) in the frame, but not "
448 "included in protected IE count");
452 /* Determine the end of the RIC IE(s) */
454 while (pos && pos + 2 <= end && pos + 2 + pos[1] <= end &&
459 parse->ric_len = pos - parse->ric;
461 wpa_printf(MSG_DEBUG, "FT: %d protected IEs missing from "
462 "frame", (int) prot_ie_count);
470 static int wpa_ft_install_ptk(struct wpa_sm *sm, const u8 *bssid)
474 u8 null_rsc[6] = { 0, 0, 0, 0, 0, 0 };
476 wpa_printf(MSG_DEBUG, "FT: Installing PTK to the driver.");
478 switch (sm->pairwise_cipher) {
479 case WPA_CIPHER_CCMP:
483 case WPA_CIPHER_TKIP:
488 wpa_printf(MSG_WARNING, "FT: Unsupported pairwise cipher %d",
489 sm->pairwise_cipher);
493 if (wpa_sm_set_key(sm, alg, bssid, 0, 1, null_rsc,
494 sizeof(null_rsc), (u8 *) sm->ptk.tk1, keylen) < 0) {
495 wpa_printf(MSG_WARNING, "FT: Failed to set PTK to the driver");
504 * wpa_ft_prepare_auth_request - Generate over-the-air auth request
505 * @sm: Pointer to WPA state machine data from wpa_sm_init()
506 * @mdie: Target AP MDIE
507 * Returns: 0 on success, -1 on failure
509 int wpa_ft_prepare_auth_request(struct wpa_sm *sm, const u8 *mdie)
514 /* Generate a new SNonce */
515 if (os_get_random(sm->snonce, WPA_NONCE_LEN)) {
516 wpa_printf(MSG_INFO, "FT: Failed to generate a new SNonce");
520 ft_ies = wpa_ft_gen_req_ies(sm, &ft_ies_len, NULL, sm->pmk_r0_name,
521 NULL, sm->bssid, NULL, 0, mdie);
523 wpa_sm_update_ft_ies(sm, sm->mobility_domain,
532 int wpa_ft_process_response(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
533 int ft_action, const u8 *target_ap,
534 const u8 *ric_ies, size_t ric_ies_len)
537 size_t ft_ies_len, ptk_len;
538 struct wpa_ft_ies parse;
539 struct rsn_mdie *mdie;
540 struct rsn_ftie *ftie;
541 u8 ptk_name[WPA_PMK_NAME_LEN];
545 wpa_hexdump(MSG_DEBUG, "FT: Response IEs", ies, ies_len);
546 wpa_hexdump(MSG_DEBUG, "FT: RIC IEs", ric_ies, ric_ies_len);
549 if (!sm->over_the_ds_in_progress) {
550 wpa_printf(MSG_DEBUG, "FT: No over-the-DS in progress "
551 "- drop FT Action Response");
555 if (os_memcmp(target_ap, sm->target_ap, ETH_ALEN) != 0) {
556 wpa_printf(MSG_DEBUG, "FT: No over-the-DS in progress "
557 "with this Target AP - drop FT Action "
563 if (sm->key_mgmt != WPA_KEY_MGMT_FT_IEEE8021X &&
564 sm->key_mgmt != WPA_KEY_MGMT_FT_PSK) {
565 wpa_printf(MSG_DEBUG, "FT: Reject FT IEs since FT is not "
566 "enabled for this connection");
570 if (wpa_ft_parse_ies(ies, ies_len, &parse) < 0) {
571 wpa_printf(MSG_DEBUG, "FT: Failed to parse IEs");
575 mdie = (struct rsn_mdie *) parse.mdie;
576 if (mdie == NULL || parse.mdie_len < sizeof(*mdie) ||
577 os_memcmp(mdie->mobility_domain, sm->mobility_domain,
578 MOBILITY_DOMAIN_ID_LEN) != 0) {
579 wpa_printf(MSG_DEBUG, "FT: Invalid MDIE");
583 ftie = (struct rsn_ftie *) parse.ftie;
584 if (ftie == NULL || parse.ftie_len < sizeof(*ftie)) {
585 wpa_printf(MSG_DEBUG, "FT: Invalid FTIE");
589 if (os_memcmp(ftie->snonce, sm->snonce, WPA_NONCE_LEN) != 0) {
590 wpa_printf(MSG_DEBUG, "FT: SNonce mismatch in FTIE");
591 wpa_hexdump(MSG_DEBUG, "FT: Received SNonce",
592 ftie->snonce, WPA_NONCE_LEN);
593 wpa_hexdump(MSG_DEBUG, "FT: Expected SNonce",
594 sm->snonce, WPA_NONCE_LEN);
598 if (parse.r0kh_id == NULL) {
599 wpa_printf(MSG_DEBUG, "FT: No R0KH-ID subelem in FTIE");
603 if (parse.r0kh_id_len != sm->r0kh_id_len ||
604 os_memcmp(parse.r0kh_id, sm->r0kh_id, parse.r0kh_id_len) != 0) {
605 wpa_printf(MSG_DEBUG, "FT: R0KH-ID in FTIE did not match with "
606 "the current R0KH-ID");
607 wpa_hexdump(MSG_DEBUG, "FT: R0KH-ID in FTIE",
608 parse.r0kh_id, parse.r0kh_id_len);
609 wpa_hexdump(MSG_DEBUG, "FT: The current R0KH-ID",
610 sm->r0kh_id, sm->r0kh_id_len);
614 if (parse.r1kh_id == NULL) {
615 wpa_printf(MSG_DEBUG, "FT: No R1KH-ID subelem in FTIE");
619 if (parse.rsn_pmkid == NULL ||
620 os_memcmp(parse.rsn_pmkid, sm->pmk_r0_name, WPA_PMK_NAME_LEN)) {
621 wpa_printf(MSG_DEBUG, "FT: No matching PMKR0Name (PMKID) in "
626 os_memcpy(sm->r1kh_id, parse.r1kh_id, FT_R1KH_ID_LEN);
627 wpa_hexdump(MSG_DEBUG, "FT: R1KH-ID", sm->r1kh_id, FT_R1KH_ID_LEN);
628 wpa_hexdump(MSG_DEBUG, "FT: SNonce", sm->snonce, WPA_NONCE_LEN);
629 wpa_hexdump(MSG_DEBUG, "FT: ANonce", ftie->anonce, WPA_NONCE_LEN);
630 os_memcpy(sm->anonce, ftie->anonce, WPA_NONCE_LEN);
631 wpa_derive_pmk_r1(sm->pmk_r0, sm->pmk_r0_name, sm->r1kh_id,
632 sm->own_addr, sm->pmk_r1, sm->pmk_r1_name);
633 wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R1", sm->pmk_r1, PMK_LEN);
634 wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name",
635 sm->pmk_r1_name, WPA_PMK_NAME_LEN);
638 ptk_len = sm->pairwise_cipher == WPA_CIPHER_CCMP ? 48 : 64;
639 wpa_pmk_r1_to_ptk(sm->pmk_r1, sm->snonce, ftie->anonce, sm->own_addr,
640 bssid, sm->pmk_r1_name,
641 (u8 *) &sm->ptk, ptk_len, ptk_name);
642 wpa_hexdump_key(MSG_DEBUG, "FT: PTK",
643 (u8 *) &sm->ptk, ptk_len);
644 wpa_hexdump(MSG_DEBUG, "FT: PTKName", ptk_name, WPA_PMK_NAME_LEN);
646 ft_ies = wpa_ft_gen_req_ies(sm, &ft_ies_len, ftie->anonce,
647 sm->pmk_r1_name, sm->ptk.kck, bssid,
648 ric_ies, ric_ies_len,
649 parse.mdie ? parse.mdie - 2 : NULL);
651 wpa_sm_update_ft_ies(sm, sm->mobility_domain,
656 wpa_sm_mark_authenticated(sm, bssid);
657 ret = wpa_ft_install_ptk(sm, bssid);
660 * Some drivers do not support key configuration when we are
661 * not associated with the target AP. Work around this by
662 * trying again after the following reassociation gets
665 wpa_printf(MSG_DEBUG, "FT: Failed to set PTK prior to "
666 "association - try again after reassociation");
667 sm->set_ptk_after_assoc = 1;
669 sm->set_ptk_after_assoc = 0;
671 sm->ft_completed = 1;
674 * The caller is expected trigger re-association with the
677 os_memcpy(sm->bssid, target_ap, ETH_ALEN);
684 int wpa_ft_is_completed(struct wpa_sm *sm)
689 if (sm->key_mgmt != WPA_KEY_MGMT_FT_IEEE8021X &&
690 sm->key_mgmt != WPA_KEY_MGMT_FT_PSK)
693 return sm->ft_completed;
697 static int wpa_ft_process_gtk_subelem(struct wpa_sm *sm, const u8 *gtk_elem,
703 size_t gtk_len, keylen, rsc_len;
705 if (gtk_elem == NULL) {
706 wpa_printf(MSG_DEBUG, "FT: No GTK included in FTIE");
710 wpa_hexdump_key(MSG_DEBUG, "FT: Received GTK in Reassoc Resp",
711 gtk_elem, gtk_elem_len);
713 if (gtk_elem_len < 11 + 24 || (gtk_elem_len - 11) % 8 ||
714 gtk_elem_len - 19 > sizeof(gtk)) {
715 wpa_printf(MSG_DEBUG, "FT: Invalid GTK sub-elem "
716 "length %lu", (unsigned long) gtk_elem_len);
719 gtk_len = gtk_elem_len - 19;
720 if (aes_unwrap(sm->ptk.kek, gtk_len / 8, gtk_elem + 11, gtk)) {
721 wpa_printf(MSG_WARNING, "FT: AES unwrap failed - could not "
726 switch (sm->group_cipher) {
727 case WPA_CIPHER_CCMP:
732 case WPA_CIPHER_TKIP:
737 case WPA_CIPHER_WEP104:
742 case WPA_CIPHER_WEP40:
748 wpa_printf(MSG_WARNING, "WPA: Unsupported Group Cipher %d",
753 if (gtk_len < keylen) {
754 wpa_printf(MSG_DEBUG, "FT: Too short GTK in FTIE");
758 /* Key Info[2] | Key Length[1] | RSC[8] | Key[5..32]. */
760 keyidx = WPA_GET_LE16(gtk_elem) & 0x03;
762 if (gtk_elem[2] != keylen) {
763 wpa_printf(MSG_DEBUG, "FT: GTK length mismatch: received %d "
765 gtk_elem[2], (unsigned long) keylen);
769 wpa_hexdump_key(MSG_DEBUG, "FT: GTK from Reassoc Resp", gtk, keylen);
770 if (wpa_sm_set_key(sm, alg, (u8 *) "\xff\xff\xff\xff\xff\xff",
771 keyidx, 0, gtk_elem + 3, rsc_len, gtk, keylen) <
773 wpa_printf(MSG_WARNING, "WPA: Failed to set GTK to the "
782 #ifdef CONFIG_IEEE80211W
783 static int wpa_ft_process_igtk_subelem(struct wpa_sm *sm, const u8 *igtk_elem,
784 size_t igtk_elem_len)
786 u8 igtk[WPA_IGTK_LEN];
789 if (sm->mgmt_group_cipher != WPA_CIPHER_AES_128_CMAC)
792 if (igtk_elem == NULL) {
793 wpa_printf(MSG_DEBUG, "FT: No IGTK included in FTIE");
797 wpa_hexdump_key(MSG_DEBUG, "FT: Received IGTK in Reassoc Resp",
798 igtk_elem, igtk_elem_len);
800 if (igtk_elem_len != 2 + 6 + 1 + WPA_IGTK_LEN + 8) {
801 wpa_printf(MSG_DEBUG, "FT: Invalid IGTK sub-elem "
802 "length %lu", (unsigned long) igtk_elem_len);
805 if (igtk_elem[8] != WPA_IGTK_LEN) {
806 wpa_printf(MSG_DEBUG, "FT: Invalid IGTK sub-elem Key Length "
811 if (aes_unwrap(sm->ptk.kek, WPA_IGTK_LEN / 8, igtk_elem + 9, igtk)) {
812 wpa_printf(MSG_WARNING, "FT: AES unwrap failed - could not "
817 /* KeyID[2] | IPN[6] | Key Length[1] | Key[16+8] */
819 keyidx = WPA_GET_LE16(igtk_elem);
821 wpa_hexdump_key(MSG_DEBUG, "FT: IGTK from Reassoc Resp", igtk,
823 if (wpa_sm_set_key(sm, WPA_ALG_IGTK, (u8 *) "\xff\xff\xff\xff\xff\xff",
824 keyidx, 0, igtk_elem + 2, 6, igtk, WPA_IGTK_LEN) <
826 wpa_printf(MSG_WARNING, "WPA: Failed to set IGTK to the "
833 #endif /* CONFIG_IEEE80211W */
836 int wpa_ft_validate_reassoc_resp(struct wpa_sm *sm, const u8 *ies,
837 size_t ies_len, const u8 *src_addr)
839 struct wpa_ft_ies parse;
840 struct rsn_mdie *mdie;
841 struct rsn_ftie *ftie;
845 wpa_hexdump(MSG_DEBUG, "FT: Response IEs", ies, ies_len);
847 if (sm->key_mgmt != WPA_KEY_MGMT_FT_IEEE8021X &&
848 sm->key_mgmt != WPA_KEY_MGMT_FT_PSK) {
849 wpa_printf(MSG_DEBUG, "FT: Reject FT IEs since FT is not "
850 "enabled for this connection");
854 if (wpa_ft_parse_ies(ies, ies_len, &parse) < 0) {
855 wpa_printf(MSG_DEBUG, "FT: Failed to parse IEs");
859 mdie = (struct rsn_mdie *) parse.mdie;
860 if (mdie == NULL || parse.mdie_len < sizeof(*mdie) ||
861 os_memcmp(mdie->mobility_domain, sm->mobility_domain,
862 MOBILITY_DOMAIN_ID_LEN) != 0) {
863 wpa_printf(MSG_DEBUG, "FT: Invalid MDIE");
867 ftie = (struct rsn_ftie *) parse.ftie;
868 if (ftie == NULL || parse.ftie_len < sizeof(*ftie)) {
869 wpa_printf(MSG_DEBUG, "FT: Invalid FTIE");
873 if (os_memcmp(ftie->snonce, sm->snonce, WPA_NONCE_LEN) != 0) {
874 wpa_printf(MSG_DEBUG, "FT: SNonce mismatch in FTIE");
875 wpa_hexdump(MSG_DEBUG, "FT: Received SNonce",
876 ftie->snonce, WPA_NONCE_LEN);
877 wpa_hexdump(MSG_DEBUG, "FT: Expected SNonce",
878 sm->snonce, WPA_NONCE_LEN);
882 if (os_memcmp(ftie->anonce, sm->anonce, WPA_NONCE_LEN) != 0) {
883 wpa_printf(MSG_DEBUG, "FT: ANonce mismatch in FTIE");
884 wpa_hexdump(MSG_DEBUG, "FT: Received ANonce",
885 ftie->anonce, WPA_NONCE_LEN);
886 wpa_hexdump(MSG_DEBUG, "FT: Expected ANonce",
887 sm->anonce, WPA_NONCE_LEN);
891 if (parse.r0kh_id == NULL) {
892 wpa_printf(MSG_DEBUG, "FT: No R0KH-ID subelem in FTIE");
896 if (parse.r0kh_id_len != sm->r0kh_id_len ||
897 os_memcmp(parse.r0kh_id, sm->r0kh_id, parse.r0kh_id_len) != 0) {
898 wpa_printf(MSG_DEBUG, "FT: R0KH-ID in FTIE did not match with "
899 "the current R0KH-ID");
900 wpa_hexdump(MSG_DEBUG, "FT: R0KH-ID in FTIE",
901 parse.r0kh_id, parse.r0kh_id_len);
902 wpa_hexdump(MSG_DEBUG, "FT: The current R0KH-ID",
903 sm->r0kh_id, sm->r0kh_id_len);
907 if (parse.r1kh_id == NULL) {
908 wpa_printf(MSG_DEBUG, "FT: No R1KH-ID subelem in FTIE");
912 if (os_memcmp(parse.r1kh_id, sm->r1kh_id, FT_R1KH_ID_LEN) != 0) {
913 wpa_printf(MSG_DEBUG, "FT: Unknown R1KH-ID used in "
918 if (parse.rsn_pmkid == NULL ||
919 os_memcmp(parse.rsn_pmkid, sm->pmk_r1_name, WPA_PMK_NAME_LEN)) {
920 wpa_printf(MSG_DEBUG, "FT: No matching PMKR1Name (PMKID) in "
921 "RSNIE (pmkid=%d)", !!parse.rsn_pmkid);
929 if (wpa_ft_mic(sm->ptk.kck, sm->own_addr, src_addr, 6,
930 parse.mdie - 2, parse.mdie_len + 2,
931 parse.ftie - 2, parse.ftie_len + 2,
932 parse.rsn - 2, parse.rsn_len + 2,
933 parse.ric, parse.ric_len,
935 wpa_printf(MSG_DEBUG, "FT: Failed to calculate MIC");
939 if (os_memcmp(mic, ftie->mic, 16) != 0) {
940 wpa_printf(MSG_DEBUG, "FT: Invalid MIC in FTIE");
941 wpa_hexdump(MSG_MSGDUMP, "FT: Received MIC", ftie->mic, 16);
942 wpa_hexdump(MSG_MSGDUMP, "FT: Calculated MIC", mic, 16);
946 if (wpa_ft_process_gtk_subelem(sm, parse.gtk, parse.gtk_len) < 0)
949 #ifdef CONFIG_IEEE80211W
950 if (wpa_ft_process_igtk_subelem(sm, parse.igtk, parse.igtk_len) < 0)
952 #endif /* CONFIG_IEEE80211W */
954 if (sm->set_ptk_after_assoc) {
955 wpa_printf(MSG_DEBUG, "FT: Try to set PTK again now that we "
957 if (wpa_ft_install_ptk(sm, src_addr) < 0)
959 sm->set_ptk_after_assoc = 0;
963 wpa_hexdump(MSG_MSGDUMP, "FT: RIC Response",
964 parse.ric, parse.ric_len);
965 /* TODO: parse response and inform driver about results */
973 * wpa_ft_start_over_ds - Generate over-the-DS auth request
974 * @sm: Pointer to WPA state machine data from wpa_sm_init()
975 * @target_ap: Target AP Address
976 * @mdie: Mobility Domain IE from the target AP
977 * Returns: 0 on success, -1 on failure
979 int wpa_ft_start_over_ds(struct wpa_sm *sm, const u8 *target_ap,
985 wpa_printf(MSG_DEBUG, "FT: Request over-the-DS with " MACSTR,
988 /* Generate a new SNonce */
989 if (os_get_random(sm->snonce, WPA_NONCE_LEN)) {
990 wpa_printf(MSG_INFO, "FT: Failed to generate a new SNonce");
994 ft_ies = wpa_ft_gen_req_ies(sm, &ft_ies_len, NULL, sm->pmk_r0_name,
995 NULL, target_ap, NULL, 0, mdie);
997 sm->over_the_ds_in_progress = 1;
998 os_memcpy(sm->target_ap, target_ap, ETH_ALEN);
999 wpa_sm_send_ft_action(sm, 1, target_ap, ft_ies, ft_ies_len);
1006 #endif /* CONFIG_IEEE80211R */