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 "crypto/random.h"
20 #include "common/ieee802_11_defs.h"
21 #include "common/ieee802_11_common.h"
26 #ifdef CONFIG_IEEE80211R
28 int wpa_derive_ptk_ft(struct wpa_sm *sm, const unsigned char *src_addr,
29 const struct wpa_eapol_key *key,
30 struct wpa_ptk *ptk, size_t ptk_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, sm->pmk_r1_name);
50 wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R1", sm->pmk_r1, PMK_LEN);
51 wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name", sm->pmk_r1_name,
53 wpa_pmk_r1_to_ptk(sm->pmk_r1, sm->snonce, anonce, sm->own_addr,
54 sm->bssid, sm->pmk_r1_name,
55 (u8 *) ptk, ptk_len, ptk_name);
56 wpa_hexdump_key(MSG_DEBUG, "FT: PTK", (u8 *) ptk, ptk_len);
57 wpa_hexdump(MSG_DEBUG, "FT: PTKName", ptk_name, WPA_PMK_NAME_LEN);
64 * wpa_sm_set_ft_params - Set FT (IEEE 802.11r) parameters
65 * @sm: Pointer to WPA state machine data from wpa_sm_init()
66 * @ies: Association Response IEs or %NULL to clear FT parameters
67 * @ies_len: Length of ies buffer in octets
68 * Returns: 0 on success, -1 on failure
70 int wpa_sm_set_ft_params(struct wpa_sm *sm, const u8 *ies, size_t ies_len)
77 if (wpa_ft_parse_ies(ies, ies_len, &ft) < 0)
80 if (ft.mdie && ft.mdie_len < MOBILITY_DOMAIN_ID_LEN + 1)
84 wpa_hexdump(MSG_DEBUG, "FT: Mobility domain",
85 ft.mdie, MOBILITY_DOMAIN_ID_LEN);
86 os_memcpy(sm->mobility_domain, ft.mdie,
87 MOBILITY_DOMAIN_ID_LEN);
88 sm->mdie_ft_capab = ft.mdie[MOBILITY_DOMAIN_ID_LEN];
89 wpa_printf(MSG_DEBUG, "FT: Capability and Policy: 0x%02x",
92 os_memset(sm->mobility_domain, 0, MOBILITY_DOMAIN_ID_LEN);
95 wpa_hexdump(MSG_DEBUG, "FT: R0KH-ID",
96 ft.r0kh_id, ft.r0kh_id_len);
97 os_memcpy(sm->r0kh_id, ft.r0kh_id, ft.r0kh_id_len);
98 sm->r0kh_id_len = ft.r0kh_id_len;
100 /* FIX: When should R0KH-ID be cleared? We need to keep the
101 * old R0KH-ID in order to be able to use this during FT. */
103 * os_memset(sm->r0kh_id, 0, FT_R0KH_ID_LEN);
104 * sm->r0kh_id_len = 0;
109 wpa_hexdump(MSG_DEBUG, "FT: R1KH-ID",
110 ft.r1kh_id, FT_R1KH_ID_LEN);
111 os_memcpy(sm->r1kh_id, ft.r1kh_id, FT_R1KH_ID_LEN);
113 os_memset(sm->r1kh_id, 0, FT_R1KH_ID_LEN);
115 os_free(sm->assoc_resp_ies);
116 sm->assoc_resp_ies = os_malloc(ft.mdie_len + 2 + ft.ftie_len + 2);
117 if (sm->assoc_resp_ies) {
118 u8 *pos = sm->assoc_resp_ies;
120 os_memcpy(pos, ft.mdie - 2, ft.mdie_len + 2);
121 pos += ft.mdie_len + 2;
124 os_memcpy(pos, ft.ftie - 2, ft.ftie_len + 2);
125 pos += ft.ftie_len + 2;
127 sm->assoc_resp_ies_len = pos - sm->assoc_resp_ies;
128 wpa_hexdump(MSG_DEBUG, "FT: Stored MDIE and FTIE from "
129 "(Re)Association Response",
130 sm->assoc_resp_ies, sm->assoc_resp_ies_len);
138 * wpa_ft_gen_req_ies - Generate FT (IEEE 802.11r) IEs for Auth/ReAssoc Request
139 * @sm: Pointer to WPA state machine data from wpa_sm_init()
140 * @len: Buffer for returning the length of the IEs
141 * @anonce: ANonce or %NULL if not yet available
142 * @pmk_name: PMKR0Name or PMKR1Name to be added into the RSN IE PMKID List
143 * @kck: 128-bit KCK for MIC or %NULL if no MIC is used
144 * @target_ap: Target AP address
145 * @ric_ies: Optional IE(s), e.g., WMM TSPEC(s), for RIC-Request or %NULL
146 * @ric_ies_len: Length of ric_ies buffer in octets
147 * @ap_mdie: Mobility Domain IE from the target AP
148 * Returns: Pointer to buffer with IEs or %NULL on failure
150 * Caller is responsible for freeing the returned buffer with os_free();
152 static u8 * wpa_ft_gen_req_ies(struct wpa_sm *sm, size_t *len,
153 const u8 *anonce, const u8 *pmk_name,
154 const u8 *kck, const u8 *target_ap,
155 const u8 *ric_ies, size_t ric_ies_len,
159 u8 *buf, *pos, *ftie_len, *ftie_pos;
160 struct rsn_mdie *mdie;
161 struct rsn_ftie *ftie;
162 struct rsn_ie_hdr *rsnie;
165 sm->ft_completed = 0;
167 buf_len = 2 + sizeof(struct rsn_mdie) + 2 + sizeof(struct rsn_ftie) +
168 2 + sm->r0kh_id_len + ric_ies_len + 100;
169 buf = os_zalloc(buf_len);
174 /* RSNIE[PMKR0Name/PMKR1Name] */
175 rsnie = (struct rsn_ie_hdr *) pos;
176 rsnie->elem_id = WLAN_EID_RSN;
177 WPA_PUT_LE16(rsnie->version, RSN_VERSION);
178 pos = (u8 *) (rsnie + 1);
180 /* Group Suite Selector */
181 if (sm->group_cipher == WPA_CIPHER_CCMP)
182 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_CCMP);
183 else if (sm->group_cipher == WPA_CIPHER_TKIP)
184 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_TKIP);
186 wpa_printf(MSG_WARNING, "FT: Invalid group cipher (%d)",
191 pos += RSN_SELECTOR_LEN;
193 /* Pairwise Suite Count */
194 WPA_PUT_LE16(pos, 1);
197 /* Pairwise Suite List */
198 if (sm->pairwise_cipher == WPA_CIPHER_CCMP)
199 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_CCMP);
200 else if (sm->pairwise_cipher == WPA_CIPHER_TKIP)
201 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_TKIP);
203 wpa_printf(MSG_WARNING, "FT: Invalid pairwise cipher (%d)",
204 sm->pairwise_cipher);
208 pos += RSN_SELECTOR_LEN;
210 /* Authenticated Key Management Suite Count */
211 WPA_PUT_LE16(pos, 1);
214 /* Authenticated Key Management Suite List */
215 if (sm->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X)
216 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FT_802_1X);
217 else if (sm->key_mgmt == WPA_KEY_MGMT_FT_PSK)
218 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FT_PSK);
220 wpa_printf(MSG_WARNING, "FT: Invalid key management type (%d)",
225 pos += RSN_SELECTOR_LEN;
227 /* RSN Capabilities */
229 #ifdef CONFIG_IEEE80211W
230 if (sm->mgmt_group_cipher == WPA_CIPHER_AES_128_CMAC)
231 capab |= WPA_CAPABILITY_MFPC;
232 #endif /* CONFIG_IEEE80211W */
233 WPA_PUT_LE16(pos, capab);
237 WPA_PUT_LE16(pos, 1);
240 /* PMKID List [PMKR0Name/PMKR1Name] */
241 os_memcpy(pos, pmk_name, WPA_PMK_NAME_LEN);
242 pos += WPA_PMK_NAME_LEN;
244 #ifdef CONFIG_IEEE80211W
245 if (sm->mgmt_group_cipher == WPA_CIPHER_AES_128_CMAC) {
246 /* Management Group Cipher Suite */
247 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_AES_128_CMAC);
248 pos += RSN_SELECTOR_LEN;
250 #endif /* CONFIG_IEEE80211W */
252 rsnie->len = (pos - (u8 *) rsnie) - 2;
255 *pos++ = WLAN_EID_MOBILITY_DOMAIN;
256 *pos++ = sizeof(*mdie);
257 mdie = (struct rsn_mdie *) pos;
258 pos += sizeof(*mdie);
259 os_memcpy(mdie->mobility_domain, sm->mobility_domain,
260 MOBILITY_DOMAIN_ID_LEN);
261 mdie->ft_capab = ap_mdie && ap_mdie[1] >= 3 ? ap_mdie[4] :
264 /* FTIE[SNonce, [R1KH-ID,] R0KH-ID ] */
266 *pos++ = WLAN_EID_FAST_BSS_TRANSITION;
268 ftie = (struct rsn_ftie *) pos;
269 pos += sizeof(*ftie);
270 os_memcpy(ftie->snonce, sm->snonce, WPA_NONCE_LEN);
272 os_memcpy(ftie->anonce, anonce, WPA_NONCE_LEN);
274 /* R1KH-ID sub-element in third FT message */
275 *pos++ = FTIE_SUBELEM_R1KH_ID;
276 *pos++ = FT_R1KH_ID_LEN;
277 os_memcpy(pos, sm->r1kh_id, FT_R1KH_ID_LEN);
278 pos += FT_R1KH_ID_LEN;
280 /* R0KH-ID sub-element */
281 *pos++ = FTIE_SUBELEM_R0KH_ID;
282 *pos++ = sm->r0kh_id_len;
283 os_memcpy(pos, sm->r0kh_id, sm->r0kh_id_len);
284 pos += sm->r0kh_id_len;
285 *ftie_len = pos - ftie_len - 1;
289 os_memcpy(pos, ric_ies, ric_ies_len);
295 * IEEE Std 802.11r-2008, 11A.8.4
296 * MIC shall be calculated over:
297 * non-AP STA MAC address
298 * Target AP MAC address
299 * Transaction seq number (5 for ReassocReq, 3 otherwise)
302 * FTIE (with MIC field set to 0)
303 * RIC-Request (if present)
305 /* Information element count */
306 ftie->mic_control[1] = 3 + ieee802_11_ie_count(ric_ies,
308 if (wpa_ft_mic(kck, sm->own_addr, target_ap, 5,
309 ((u8 *) mdie) - 2, 2 + sizeof(*mdie),
310 ftie_pos, 2 + *ftie_len,
311 (u8 *) rsnie, 2 + rsnie->len, ric_ies,
312 ric_ies_len, ftie->mic) < 0) {
313 wpa_printf(MSG_INFO, "FT: Failed to calculate MIC");
325 static int wpa_ft_install_ptk(struct wpa_sm *sm, const u8 *bssid)
329 u8 null_rsc[6] = { 0, 0, 0, 0, 0, 0 };
331 wpa_printf(MSG_DEBUG, "FT: Installing PTK to the driver.");
333 switch (sm->pairwise_cipher) {
334 case WPA_CIPHER_CCMP:
338 case WPA_CIPHER_TKIP:
343 wpa_printf(MSG_WARNING, "FT: Unsupported pairwise cipher %d",
344 sm->pairwise_cipher);
348 if (wpa_sm_set_key(sm, alg, bssid, 0, 1, null_rsc,
349 sizeof(null_rsc), (u8 *) sm->ptk.tk1, keylen) < 0) {
350 wpa_printf(MSG_WARNING, "FT: Failed to set PTK to the driver");
359 * wpa_ft_prepare_auth_request - Generate over-the-air auth request
360 * @sm: Pointer to WPA state machine data from wpa_sm_init()
361 * @mdie: Target AP MDIE
362 * Returns: 0 on success, -1 on failure
364 int wpa_ft_prepare_auth_request(struct wpa_sm *sm, const u8 *mdie)
369 /* Generate a new SNonce */
370 if (random_get_bytes(sm->snonce, WPA_NONCE_LEN)) {
371 wpa_printf(MSG_INFO, "FT: Failed to generate a new SNonce");
375 ft_ies = wpa_ft_gen_req_ies(sm, &ft_ies_len, NULL, sm->pmk_r0_name,
376 NULL, sm->bssid, NULL, 0, mdie);
378 wpa_sm_update_ft_ies(sm, sm->mobility_domain,
387 int wpa_ft_process_response(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
388 int ft_action, const u8 *target_ap,
389 const u8 *ric_ies, size_t ric_ies_len)
392 size_t ft_ies_len, ptk_len;
393 struct wpa_ft_ies parse;
394 struct rsn_mdie *mdie;
395 struct rsn_ftie *ftie;
396 u8 ptk_name[WPA_PMK_NAME_LEN];
400 wpa_hexdump(MSG_DEBUG, "FT: Response IEs", ies, ies_len);
401 wpa_hexdump(MSG_DEBUG, "FT: RIC IEs", ric_ies, ric_ies_len);
404 if (!sm->over_the_ds_in_progress) {
405 wpa_printf(MSG_DEBUG, "FT: No over-the-DS in progress "
406 "- drop FT Action Response");
410 if (os_memcmp(target_ap, sm->target_ap, ETH_ALEN) != 0) {
411 wpa_printf(MSG_DEBUG, "FT: No over-the-DS in progress "
412 "with this Target AP - drop FT Action "
418 if (sm->key_mgmt != WPA_KEY_MGMT_FT_IEEE8021X &&
419 sm->key_mgmt != WPA_KEY_MGMT_FT_PSK) {
420 wpa_printf(MSG_DEBUG, "FT: Reject FT IEs since FT is not "
421 "enabled for this connection");
425 if (wpa_ft_parse_ies(ies, ies_len, &parse) < 0) {
426 wpa_printf(MSG_DEBUG, "FT: Failed to parse IEs");
430 mdie = (struct rsn_mdie *) parse.mdie;
431 if (mdie == NULL || parse.mdie_len < sizeof(*mdie) ||
432 os_memcmp(mdie->mobility_domain, sm->mobility_domain,
433 MOBILITY_DOMAIN_ID_LEN) != 0) {
434 wpa_printf(MSG_DEBUG, "FT: Invalid MDIE");
438 ftie = (struct rsn_ftie *) parse.ftie;
439 if (ftie == NULL || parse.ftie_len < sizeof(*ftie)) {
440 wpa_printf(MSG_DEBUG, "FT: Invalid FTIE");
444 if (os_memcmp(ftie->snonce, sm->snonce, WPA_NONCE_LEN) != 0) {
445 wpa_printf(MSG_DEBUG, "FT: SNonce mismatch in FTIE");
446 wpa_hexdump(MSG_DEBUG, "FT: Received SNonce",
447 ftie->snonce, WPA_NONCE_LEN);
448 wpa_hexdump(MSG_DEBUG, "FT: Expected SNonce",
449 sm->snonce, WPA_NONCE_LEN);
453 if (parse.r0kh_id == NULL) {
454 wpa_printf(MSG_DEBUG, "FT: No R0KH-ID subelem in FTIE");
458 if (parse.r0kh_id_len != sm->r0kh_id_len ||
459 os_memcmp(parse.r0kh_id, sm->r0kh_id, parse.r0kh_id_len) != 0) {
460 wpa_printf(MSG_DEBUG, "FT: R0KH-ID in FTIE did not match with "
461 "the current R0KH-ID");
462 wpa_hexdump(MSG_DEBUG, "FT: R0KH-ID in FTIE",
463 parse.r0kh_id, parse.r0kh_id_len);
464 wpa_hexdump(MSG_DEBUG, "FT: The current R0KH-ID",
465 sm->r0kh_id, sm->r0kh_id_len);
469 if (parse.r1kh_id == NULL) {
470 wpa_printf(MSG_DEBUG, "FT: No R1KH-ID subelem in FTIE");
474 if (parse.rsn_pmkid == NULL ||
475 os_memcmp(parse.rsn_pmkid, sm->pmk_r0_name, WPA_PMK_NAME_LEN)) {
476 wpa_printf(MSG_DEBUG, "FT: No matching PMKR0Name (PMKID) in "
481 os_memcpy(sm->r1kh_id, parse.r1kh_id, FT_R1KH_ID_LEN);
482 wpa_hexdump(MSG_DEBUG, "FT: R1KH-ID", sm->r1kh_id, FT_R1KH_ID_LEN);
483 wpa_hexdump(MSG_DEBUG, "FT: SNonce", sm->snonce, WPA_NONCE_LEN);
484 wpa_hexdump(MSG_DEBUG, "FT: ANonce", ftie->anonce, WPA_NONCE_LEN);
485 os_memcpy(sm->anonce, ftie->anonce, WPA_NONCE_LEN);
486 wpa_derive_pmk_r1(sm->pmk_r0, sm->pmk_r0_name, sm->r1kh_id,
487 sm->own_addr, sm->pmk_r1, sm->pmk_r1_name);
488 wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R1", sm->pmk_r1, PMK_LEN);
489 wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name",
490 sm->pmk_r1_name, WPA_PMK_NAME_LEN);
493 ptk_len = sm->pairwise_cipher == WPA_CIPHER_CCMP ? 48 : 64;
494 wpa_pmk_r1_to_ptk(sm->pmk_r1, sm->snonce, ftie->anonce, sm->own_addr,
495 bssid, sm->pmk_r1_name,
496 (u8 *) &sm->ptk, ptk_len, ptk_name);
497 wpa_hexdump_key(MSG_DEBUG, "FT: PTK",
498 (u8 *) &sm->ptk, ptk_len);
499 wpa_hexdump(MSG_DEBUG, "FT: PTKName", ptk_name, WPA_PMK_NAME_LEN);
501 ft_ies = wpa_ft_gen_req_ies(sm, &ft_ies_len, ftie->anonce,
502 sm->pmk_r1_name, sm->ptk.kck, bssid,
503 ric_ies, ric_ies_len,
504 parse.mdie ? parse.mdie - 2 : NULL);
506 wpa_sm_update_ft_ies(sm, sm->mobility_domain,
511 wpa_sm_mark_authenticated(sm, bssid);
512 ret = wpa_ft_install_ptk(sm, bssid);
515 * Some drivers do not support key configuration when we are
516 * not associated with the target AP. Work around this by
517 * trying again after the following reassociation gets
520 wpa_printf(MSG_DEBUG, "FT: Failed to set PTK prior to "
521 "association - try again after reassociation");
522 sm->set_ptk_after_assoc = 1;
524 sm->set_ptk_after_assoc = 0;
526 sm->ft_completed = 1;
529 * The caller is expected trigger re-association with the
532 os_memcpy(sm->bssid, target_ap, ETH_ALEN);
539 int wpa_ft_is_completed(struct wpa_sm *sm)
544 if (sm->key_mgmt != WPA_KEY_MGMT_FT_IEEE8021X &&
545 sm->key_mgmt != WPA_KEY_MGMT_FT_PSK)
548 return sm->ft_completed;
552 static int wpa_ft_process_gtk_subelem(struct wpa_sm *sm, const u8 *gtk_elem,
558 size_t gtk_len, keylen, rsc_len;
560 if (gtk_elem == NULL) {
561 wpa_printf(MSG_DEBUG, "FT: No GTK included in FTIE");
565 wpa_hexdump_key(MSG_DEBUG, "FT: Received GTK in Reassoc Resp",
566 gtk_elem, gtk_elem_len);
568 if (gtk_elem_len < 11 + 24 || (gtk_elem_len - 11) % 8 ||
569 gtk_elem_len - 19 > sizeof(gtk)) {
570 wpa_printf(MSG_DEBUG, "FT: Invalid GTK sub-elem "
571 "length %lu", (unsigned long) gtk_elem_len);
574 gtk_len = gtk_elem_len - 19;
575 if (aes_unwrap(sm->ptk.kek, gtk_len / 8, gtk_elem + 11, gtk)) {
576 wpa_printf(MSG_WARNING, "FT: AES unwrap failed - could not "
581 switch (sm->group_cipher) {
582 case WPA_CIPHER_CCMP:
587 case WPA_CIPHER_TKIP:
592 case WPA_CIPHER_WEP104:
597 case WPA_CIPHER_WEP40:
603 wpa_printf(MSG_WARNING, "WPA: Unsupported Group Cipher %d",
608 if (gtk_len < keylen) {
609 wpa_printf(MSG_DEBUG, "FT: Too short GTK in FTIE");
613 /* Key Info[2] | Key Length[1] | RSC[8] | Key[5..32]. */
615 keyidx = WPA_GET_LE16(gtk_elem) & 0x03;
617 if (gtk_elem[2] != keylen) {
618 wpa_printf(MSG_DEBUG, "FT: GTK length mismatch: received %d "
620 gtk_elem[2], (unsigned long) keylen);
624 wpa_hexdump_key(MSG_DEBUG, "FT: GTK from Reassoc Resp", gtk, keylen);
625 if (wpa_sm_set_key(sm, alg, broadcast_ether_addr, keyidx, 0,
626 gtk_elem + 3, rsc_len, gtk, keylen) < 0) {
627 wpa_printf(MSG_WARNING, "WPA: Failed to set GTK to the "
636 #ifdef CONFIG_IEEE80211W
637 static int wpa_ft_process_igtk_subelem(struct wpa_sm *sm, const u8 *igtk_elem,
638 size_t igtk_elem_len)
640 u8 igtk[WPA_IGTK_LEN];
643 if (sm->mgmt_group_cipher != WPA_CIPHER_AES_128_CMAC)
646 if (igtk_elem == NULL) {
647 wpa_printf(MSG_DEBUG, "FT: No IGTK included in FTIE");
651 wpa_hexdump_key(MSG_DEBUG, "FT: Received IGTK in Reassoc Resp",
652 igtk_elem, igtk_elem_len);
654 if (igtk_elem_len != 2 + 6 + 1 + WPA_IGTK_LEN + 8) {
655 wpa_printf(MSG_DEBUG, "FT: Invalid IGTK sub-elem "
656 "length %lu", (unsigned long) igtk_elem_len);
659 if (igtk_elem[8] != WPA_IGTK_LEN) {
660 wpa_printf(MSG_DEBUG, "FT: Invalid IGTK sub-elem Key Length "
665 if (aes_unwrap(sm->ptk.kek, WPA_IGTK_LEN / 8, igtk_elem + 9, igtk)) {
666 wpa_printf(MSG_WARNING, "FT: AES unwrap failed - could not "
671 /* KeyID[2] | IPN[6] | Key Length[1] | Key[16+8] */
673 keyidx = WPA_GET_LE16(igtk_elem);
675 wpa_hexdump_key(MSG_DEBUG, "FT: IGTK from Reassoc Resp", igtk,
677 if (wpa_sm_set_key(sm, WPA_ALG_IGTK, broadcast_ether_addr, keyidx, 0,
678 igtk_elem + 2, 6, igtk, WPA_IGTK_LEN) < 0) {
679 wpa_printf(MSG_WARNING, "WPA: Failed to set IGTK to the "
686 #endif /* CONFIG_IEEE80211W */
689 int wpa_ft_validate_reassoc_resp(struct wpa_sm *sm, const u8 *ies,
690 size_t ies_len, const u8 *src_addr)
692 struct wpa_ft_ies parse;
693 struct rsn_mdie *mdie;
694 struct rsn_ftie *ftie;
698 wpa_hexdump(MSG_DEBUG, "FT: Response IEs", ies, ies_len);
700 if (sm->key_mgmt != WPA_KEY_MGMT_FT_IEEE8021X &&
701 sm->key_mgmt != WPA_KEY_MGMT_FT_PSK) {
702 wpa_printf(MSG_DEBUG, "FT: Reject FT IEs since FT is not "
703 "enabled for this connection");
707 if (wpa_ft_parse_ies(ies, ies_len, &parse) < 0) {
708 wpa_printf(MSG_DEBUG, "FT: Failed to parse IEs");
712 mdie = (struct rsn_mdie *) parse.mdie;
713 if (mdie == NULL || parse.mdie_len < sizeof(*mdie) ||
714 os_memcmp(mdie->mobility_domain, sm->mobility_domain,
715 MOBILITY_DOMAIN_ID_LEN) != 0) {
716 wpa_printf(MSG_DEBUG, "FT: Invalid MDIE");
720 ftie = (struct rsn_ftie *) parse.ftie;
721 if (ftie == NULL || parse.ftie_len < sizeof(*ftie)) {
722 wpa_printf(MSG_DEBUG, "FT: Invalid FTIE");
726 if (os_memcmp(ftie->snonce, sm->snonce, WPA_NONCE_LEN) != 0) {
727 wpa_printf(MSG_DEBUG, "FT: SNonce mismatch in FTIE");
728 wpa_hexdump(MSG_DEBUG, "FT: Received SNonce",
729 ftie->snonce, WPA_NONCE_LEN);
730 wpa_hexdump(MSG_DEBUG, "FT: Expected SNonce",
731 sm->snonce, WPA_NONCE_LEN);
735 if (os_memcmp(ftie->anonce, sm->anonce, WPA_NONCE_LEN) != 0) {
736 wpa_printf(MSG_DEBUG, "FT: ANonce mismatch in FTIE");
737 wpa_hexdump(MSG_DEBUG, "FT: Received ANonce",
738 ftie->anonce, WPA_NONCE_LEN);
739 wpa_hexdump(MSG_DEBUG, "FT: Expected ANonce",
740 sm->anonce, WPA_NONCE_LEN);
744 if (parse.r0kh_id == NULL) {
745 wpa_printf(MSG_DEBUG, "FT: No R0KH-ID subelem in FTIE");
749 if (parse.r0kh_id_len != sm->r0kh_id_len ||
750 os_memcmp(parse.r0kh_id, sm->r0kh_id, parse.r0kh_id_len) != 0) {
751 wpa_printf(MSG_DEBUG, "FT: R0KH-ID in FTIE did not match with "
752 "the current R0KH-ID");
753 wpa_hexdump(MSG_DEBUG, "FT: R0KH-ID in FTIE",
754 parse.r0kh_id, parse.r0kh_id_len);
755 wpa_hexdump(MSG_DEBUG, "FT: The current R0KH-ID",
756 sm->r0kh_id, sm->r0kh_id_len);
760 if (parse.r1kh_id == NULL) {
761 wpa_printf(MSG_DEBUG, "FT: No R1KH-ID subelem in FTIE");
765 if (os_memcmp(parse.r1kh_id, sm->r1kh_id, FT_R1KH_ID_LEN) != 0) {
766 wpa_printf(MSG_DEBUG, "FT: Unknown R1KH-ID used in "
771 if (parse.rsn_pmkid == NULL ||
772 os_memcmp(parse.rsn_pmkid, sm->pmk_r1_name, WPA_PMK_NAME_LEN)) {
773 wpa_printf(MSG_DEBUG, "FT: No matching PMKR1Name (PMKID) in "
774 "RSNIE (pmkid=%d)", !!parse.rsn_pmkid);
780 count += ieee802_11_ie_count(parse.ric, parse.ric_len);
781 if (ftie->mic_control[1] != count) {
782 wpa_printf(MSG_DEBUG, "FT: Unexpected IE count in MIC "
783 "Control: received %u expected %u",
784 ftie->mic_control[1], count);
788 if (wpa_ft_mic(sm->ptk.kck, sm->own_addr, src_addr, 6,
789 parse.mdie - 2, parse.mdie_len + 2,
790 parse.ftie - 2, parse.ftie_len + 2,
791 parse.rsn - 2, parse.rsn_len + 2,
792 parse.ric, parse.ric_len,
794 wpa_printf(MSG_DEBUG, "FT: Failed to calculate MIC");
798 if (os_memcmp(mic, ftie->mic, 16) != 0) {
799 wpa_printf(MSG_DEBUG, "FT: Invalid MIC in FTIE");
800 wpa_hexdump(MSG_MSGDUMP, "FT: Received MIC", ftie->mic, 16);
801 wpa_hexdump(MSG_MSGDUMP, "FT: Calculated MIC", mic, 16);
805 if (wpa_ft_process_gtk_subelem(sm, parse.gtk, parse.gtk_len) < 0)
808 #ifdef CONFIG_IEEE80211W
809 if (wpa_ft_process_igtk_subelem(sm, parse.igtk, parse.igtk_len) < 0)
811 #endif /* CONFIG_IEEE80211W */
813 if (sm->set_ptk_after_assoc) {
814 wpa_printf(MSG_DEBUG, "FT: Try to set PTK again now that we "
816 if (wpa_ft_install_ptk(sm, src_addr) < 0)
818 sm->set_ptk_after_assoc = 0;
822 wpa_hexdump(MSG_MSGDUMP, "FT: RIC Response",
823 parse.ric, parse.ric_len);
824 /* TODO: parse response and inform driver about results */
832 * wpa_ft_start_over_ds - Generate over-the-DS auth request
833 * @sm: Pointer to WPA state machine data from wpa_sm_init()
834 * @target_ap: Target AP Address
835 * @mdie: Mobility Domain IE from the target AP
836 * Returns: 0 on success, -1 on failure
838 int wpa_ft_start_over_ds(struct wpa_sm *sm, const u8 *target_ap,
844 wpa_printf(MSG_DEBUG, "FT: Request over-the-DS with " MACSTR,
847 /* Generate a new SNonce */
848 if (random_get_bytes(sm->snonce, WPA_NONCE_LEN)) {
849 wpa_printf(MSG_INFO, "FT: Failed to generate a new SNonce");
853 ft_ies = wpa_ft_gen_req_ies(sm, &ft_ies_len, NULL, sm->pmk_r0_name,
854 NULL, target_ap, NULL, 0, mdie);
856 sm->over_the_ds_in_progress = 1;
857 os_memcpy(sm->target_ap, target_ap, ETH_ALEN);
858 wpa_sm_send_ft_action(sm, 1, target_ap, ft_ies, ft_ies_len);
865 #endif /* CONFIG_IEEE80211R */