2 * WPA Supplicant - IEEE 802.11r - Fast BSS Transition
3 * Copyright (c) 2006-2007, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "crypto/aes_wrap.h"
13 #include "crypto/random.h"
14 #include "common/ieee802_11_defs.h"
15 #include "common/ieee802_11_common.h"
19 #ifdef CONFIG_IEEE80211R
21 int wpa_derive_ptk_ft(struct wpa_sm *sm, const unsigned char *src_addr,
22 const struct wpa_eapol_key *key,
23 struct wpa_ptk *ptk, size_t ptk_len)
25 u8 ptk_name[WPA_PMK_NAME_LEN];
26 const u8 *anonce = key->key_nonce;
28 if (sm->xxkey_len == 0) {
29 wpa_printf(MSG_DEBUG, "FT: XXKey not available for key "
34 wpa_derive_pmk_r0(sm->xxkey, sm->xxkey_len, sm->ssid,
35 sm->ssid_len, sm->mobility_domain,
36 sm->r0kh_id, sm->r0kh_id_len, sm->own_addr,
37 sm->pmk_r0, sm->pmk_r0_name);
38 wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R0", sm->pmk_r0, PMK_LEN);
39 wpa_hexdump(MSG_DEBUG, "FT: PMKR0Name",
40 sm->pmk_r0_name, WPA_PMK_NAME_LEN);
41 wpa_derive_pmk_r1(sm->pmk_r0, sm->pmk_r0_name, sm->r1kh_id,
42 sm->own_addr, sm->pmk_r1, sm->pmk_r1_name);
43 wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R1", sm->pmk_r1, PMK_LEN);
44 wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name", sm->pmk_r1_name,
46 wpa_pmk_r1_to_ptk(sm->pmk_r1, sm->snonce, anonce, sm->own_addr,
47 sm->bssid, sm->pmk_r1_name,
48 (u8 *) ptk, ptk_len, ptk_name);
49 wpa_hexdump_key(MSG_DEBUG, "FT: PTK", (u8 *) ptk, ptk_len);
50 wpa_hexdump(MSG_DEBUG, "FT: PTKName", ptk_name, WPA_PMK_NAME_LEN);
57 * wpa_sm_set_ft_params - Set FT (IEEE 802.11r) parameters
58 * @sm: Pointer to WPA state machine data from wpa_sm_init()
59 * @ies: Association Response IEs or %NULL to clear FT parameters
60 * @ies_len: Length of ies buffer in octets
61 * Returns: 0 on success, -1 on failure
63 int wpa_sm_set_ft_params(struct wpa_sm *sm, const u8 *ies, size_t ies_len)
70 if (wpa_ft_parse_ies(ies, ies_len, &ft) < 0)
73 if (ft.mdie && ft.mdie_len < MOBILITY_DOMAIN_ID_LEN + 1)
77 wpa_hexdump(MSG_DEBUG, "FT: Mobility domain",
78 ft.mdie, MOBILITY_DOMAIN_ID_LEN);
79 os_memcpy(sm->mobility_domain, ft.mdie,
80 MOBILITY_DOMAIN_ID_LEN);
81 sm->mdie_ft_capab = ft.mdie[MOBILITY_DOMAIN_ID_LEN];
82 wpa_printf(MSG_DEBUG, "FT: Capability and Policy: 0x%02x",
85 os_memset(sm->mobility_domain, 0, MOBILITY_DOMAIN_ID_LEN);
88 wpa_hexdump(MSG_DEBUG, "FT: R0KH-ID",
89 ft.r0kh_id, ft.r0kh_id_len);
90 os_memcpy(sm->r0kh_id, ft.r0kh_id, ft.r0kh_id_len);
91 sm->r0kh_id_len = ft.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",
103 ft.r1kh_id, FT_R1KH_ID_LEN);
104 os_memcpy(sm->r1kh_id, ft.r1kh_id, FT_R1KH_ID_LEN);
106 os_memset(sm->r1kh_id, 0, FT_R1KH_ID_LEN);
108 os_free(sm->assoc_resp_ies);
109 sm->assoc_resp_ies = os_malloc(ft.mdie_len + 2 + ft.ftie_len + 2);
110 if (sm->assoc_resp_ies) {
111 u8 *pos = sm->assoc_resp_ies;
113 os_memcpy(pos, ft.mdie - 2, ft.mdie_len + 2);
114 pos += ft.mdie_len + 2;
117 os_memcpy(pos, ft.ftie - 2, ft.ftie_len + 2);
118 pos += ft.ftie_len + 2;
120 sm->assoc_resp_ies_len = pos - sm->assoc_resp_ies;
121 wpa_hexdump(MSG_DEBUG, "FT: Stored MDIE and FTIE from "
122 "(Re)Association Response",
123 sm->assoc_resp_ies, sm->assoc_resp_ies_len);
131 * wpa_ft_gen_req_ies - Generate FT (IEEE 802.11r) IEs for Auth/ReAssoc Request
132 * @sm: Pointer to WPA state machine data from wpa_sm_init()
133 * @len: Buffer for returning the length of the IEs
134 * @anonce: ANonce or %NULL if not yet available
135 * @pmk_name: PMKR0Name or PMKR1Name to be added into the RSN IE PMKID List
136 * @kck: 128-bit KCK for MIC or %NULL if no MIC is used
137 * @target_ap: Target AP address
138 * @ric_ies: Optional IE(s), e.g., WMM TSPEC(s), for RIC-Request or %NULL
139 * @ric_ies_len: Length of ric_ies buffer in octets
140 * @ap_mdie: Mobility Domain IE from the target AP
141 * Returns: Pointer to buffer with IEs or %NULL on failure
143 * Caller is responsible for freeing the returned buffer with os_free();
145 static u8 * wpa_ft_gen_req_ies(struct wpa_sm *sm, size_t *len,
146 const u8 *anonce, const u8 *pmk_name,
147 const u8 *kck, const u8 *target_ap,
148 const u8 *ric_ies, size_t ric_ies_len,
152 u8 *buf, *pos, *ftie_len, *ftie_pos;
153 struct rsn_mdie *mdie;
154 struct rsn_ftie *ftie;
155 struct rsn_ie_hdr *rsnie;
158 sm->ft_completed = 0;
159 sm->ft_reassoc_completed = 0;
161 buf_len = 2 + sizeof(struct rsn_mdie) + 2 + sizeof(struct rsn_ftie) +
162 2 + sm->r0kh_id_len + ric_ies_len + 100;
163 buf = os_zalloc(buf_len);
168 /* RSNIE[PMKR0Name/PMKR1Name] */
169 rsnie = (struct rsn_ie_hdr *) pos;
170 rsnie->elem_id = WLAN_EID_RSN;
171 WPA_PUT_LE16(rsnie->version, RSN_VERSION);
172 pos = (u8 *) (rsnie + 1);
174 /* Group Suite Selector */
175 if (sm->group_cipher != WPA_CIPHER_CCMP &&
176 sm->group_cipher != WPA_CIPHER_GCMP &&
177 sm->group_cipher != WPA_CIPHER_TKIP) {
178 wpa_printf(MSG_WARNING, "FT: Invalid group cipher (%d)",
183 RSN_SELECTOR_PUT(pos, wpa_cipher_to_suite(WPA_PROTO_RSN,
185 pos += RSN_SELECTOR_LEN;
187 /* Pairwise Suite Count */
188 WPA_PUT_LE16(pos, 1);
191 /* Pairwise Suite List */
192 if (!wpa_cipher_valid_pairwise(sm->pairwise_cipher)) {
193 wpa_printf(MSG_WARNING, "FT: Invalid pairwise cipher (%d)",
194 sm->pairwise_cipher);
198 RSN_SELECTOR_PUT(pos, wpa_cipher_to_suite(WPA_PROTO_RSN,
199 sm->pairwise_cipher));
200 pos += RSN_SELECTOR_LEN;
202 /* Authenticated Key Management Suite Count */
203 WPA_PUT_LE16(pos, 1);
206 /* Authenticated Key Management Suite List */
207 if (sm->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X)
208 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FT_802_1X);
209 else if (sm->key_mgmt == WPA_KEY_MGMT_FT_PSK)
210 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FT_PSK);
212 wpa_printf(MSG_WARNING, "FT: Invalid key management type (%d)",
217 pos += RSN_SELECTOR_LEN;
219 /* RSN Capabilities */
221 #ifdef CONFIG_IEEE80211W
222 if (sm->mgmt_group_cipher == WPA_CIPHER_AES_128_CMAC)
223 capab |= WPA_CAPABILITY_MFPC;
224 #endif /* CONFIG_IEEE80211W */
225 WPA_PUT_LE16(pos, capab);
229 WPA_PUT_LE16(pos, 1);
232 /* PMKID List [PMKR0Name/PMKR1Name] */
233 os_memcpy(pos, pmk_name, WPA_PMK_NAME_LEN);
234 pos += WPA_PMK_NAME_LEN;
236 #ifdef CONFIG_IEEE80211W
237 if (sm->mgmt_group_cipher == WPA_CIPHER_AES_128_CMAC) {
238 /* Management Group Cipher Suite */
239 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_AES_128_CMAC);
240 pos += RSN_SELECTOR_LEN;
242 #endif /* CONFIG_IEEE80211W */
244 rsnie->len = (pos - (u8 *) rsnie) - 2;
247 *pos++ = WLAN_EID_MOBILITY_DOMAIN;
248 *pos++ = sizeof(*mdie);
249 mdie = (struct rsn_mdie *) pos;
250 pos += sizeof(*mdie);
251 os_memcpy(mdie->mobility_domain, sm->mobility_domain,
252 MOBILITY_DOMAIN_ID_LEN);
253 mdie->ft_capab = ap_mdie && ap_mdie[1] >= 3 ? ap_mdie[4] :
256 /* FTIE[SNonce, [R1KH-ID,] R0KH-ID ] */
258 *pos++ = WLAN_EID_FAST_BSS_TRANSITION;
260 ftie = (struct rsn_ftie *) pos;
261 pos += sizeof(*ftie);
262 os_memcpy(ftie->snonce, sm->snonce, WPA_NONCE_LEN);
264 os_memcpy(ftie->anonce, anonce, WPA_NONCE_LEN);
266 /* R1KH-ID sub-element in third FT message */
267 *pos++ = FTIE_SUBELEM_R1KH_ID;
268 *pos++ = FT_R1KH_ID_LEN;
269 os_memcpy(pos, sm->r1kh_id, FT_R1KH_ID_LEN);
270 pos += FT_R1KH_ID_LEN;
272 /* R0KH-ID sub-element */
273 *pos++ = FTIE_SUBELEM_R0KH_ID;
274 *pos++ = sm->r0kh_id_len;
275 os_memcpy(pos, sm->r0kh_id, sm->r0kh_id_len);
276 pos += sm->r0kh_id_len;
277 *ftie_len = pos - ftie_len - 1;
281 os_memcpy(pos, ric_ies, ric_ies_len);
287 * IEEE Std 802.11r-2008, 11A.8.4
288 * MIC shall be calculated over:
289 * non-AP STA MAC address
290 * Target AP MAC address
291 * Transaction seq number (5 for ReassocReq, 3 otherwise)
294 * FTIE (with MIC field set to 0)
295 * RIC-Request (if present)
297 /* Information element count */
298 ftie->mic_control[1] = 3 + ieee802_11_ie_count(ric_ies,
300 if (wpa_ft_mic(kck, sm->own_addr, target_ap, 5,
301 ((u8 *) mdie) - 2, 2 + sizeof(*mdie),
302 ftie_pos, 2 + *ftie_len,
303 (u8 *) rsnie, 2 + rsnie->len, ric_ies,
304 ric_ies_len, ftie->mic) < 0) {
305 wpa_printf(MSG_INFO, "FT: Failed to calculate MIC");
317 static int wpa_ft_install_ptk(struct wpa_sm *sm, const u8 *bssid)
321 u8 null_rsc[6] = { 0, 0, 0, 0, 0, 0 };
323 wpa_printf(MSG_DEBUG, "FT: Installing PTK to the driver.");
325 if (!wpa_cipher_valid_pairwise(sm->pairwise_cipher)) {
326 wpa_printf(MSG_WARNING, "FT: Unsupported pairwise cipher %d",
327 sm->pairwise_cipher);
331 alg = wpa_cipher_to_alg(sm->pairwise_cipher);
332 keylen = wpa_cipher_key_len(sm->pairwise_cipher);
334 if (wpa_sm_set_key(sm, alg, bssid, 0, 1, null_rsc,
335 sizeof(null_rsc), (u8 *) sm->ptk.tk1, keylen) < 0) {
336 wpa_printf(MSG_WARNING, "FT: Failed to set PTK to the driver");
345 * wpa_ft_prepare_auth_request - Generate over-the-air auth request
346 * @sm: Pointer to WPA state machine data from wpa_sm_init()
347 * @mdie: Target AP MDIE
348 * Returns: 0 on success, -1 on failure
350 int wpa_ft_prepare_auth_request(struct wpa_sm *sm, const u8 *mdie)
355 /* Generate a new SNonce */
356 if (random_get_bytes(sm->snonce, WPA_NONCE_LEN)) {
357 wpa_printf(MSG_INFO, "FT: Failed to generate a new SNonce");
361 ft_ies = wpa_ft_gen_req_ies(sm, &ft_ies_len, NULL, sm->pmk_r0_name,
362 NULL, sm->bssid, NULL, 0, mdie);
364 wpa_sm_update_ft_ies(sm, sm->mobility_domain,
373 int wpa_ft_process_response(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
374 int ft_action, const u8 *target_ap,
375 const u8 *ric_ies, size_t ric_ies_len)
378 size_t ft_ies_len, ptk_len;
379 struct wpa_ft_ies parse;
380 struct rsn_mdie *mdie;
381 struct rsn_ftie *ftie;
382 u8 ptk_name[WPA_PMK_NAME_LEN];
386 wpa_hexdump(MSG_DEBUG, "FT: Response IEs", ies, ies_len);
387 wpa_hexdump(MSG_DEBUG, "FT: RIC IEs", ric_ies, ric_ies_len);
390 if (!sm->over_the_ds_in_progress) {
391 wpa_printf(MSG_DEBUG, "FT: No over-the-DS in progress "
392 "- drop FT Action Response");
396 if (os_memcmp(target_ap, sm->target_ap, ETH_ALEN) != 0) {
397 wpa_printf(MSG_DEBUG, "FT: No over-the-DS in progress "
398 "with this Target AP - drop FT Action "
404 if (sm->key_mgmt != WPA_KEY_MGMT_FT_IEEE8021X &&
405 sm->key_mgmt != WPA_KEY_MGMT_FT_PSK) {
406 wpa_printf(MSG_DEBUG, "FT: Reject FT IEs since FT is not "
407 "enabled for this connection");
411 if (wpa_ft_parse_ies(ies, ies_len, &parse) < 0) {
412 wpa_printf(MSG_DEBUG, "FT: Failed to parse IEs");
416 mdie = (struct rsn_mdie *) parse.mdie;
417 if (mdie == NULL || parse.mdie_len < sizeof(*mdie) ||
418 os_memcmp(mdie->mobility_domain, sm->mobility_domain,
419 MOBILITY_DOMAIN_ID_LEN) != 0) {
420 wpa_printf(MSG_DEBUG, "FT: Invalid MDIE");
424 ftie = (struct rsn_ftie *) parse.ftie;
425 if (ftie == NULL || parse.ftie_len < sizeof(*ftie)) {
426 wpa_printf(MSG_DEBUG, "FT: Invalid FTIE");
430 if (os_memcmp(ftie->snonce, sm->snonce, WPA_NONCE_LEN) != 0) {
431 wpa_printf(MSG_DEBUG, "FT: SNonce mismatch in FTIE");
432 wpa_hexdump(MSG_DEBUG, "FT: Received SNonce",
433 ftie->snonce, WPA_NONCE_LEN);
434 wpa_hexdump(MSG_DEBUG, "FT: Expected SNonce",
435 sm->snonce, WPA_NONCE_LEN);
439 if (parse.r0kh_id == NULL) {
440 wpa_printf(MSG_DEBUG, "FT: No R0KH-ID subelem in FTIE");
444 if (parse.r0kh_id_len != sm->r0kh_id_len ||
445 os_memcmp(parse.r0kh_id, sm->r0kh_id, parse.r0kh_id_len) != 0) {
446 wpa_printf(MSG_DEBUG, "FT: R0KH-ID in FTIE did not match with "
447 "the current R0KH-ID");
448 wpa_hexdump(MSG_DEBUG, "FT: R0KH-ID in FTIE",
449 parse.r0kh_id, parse.r0kh_id_len);
450 wpa_hexdump(MSG_DEBUG, "FT: The current R0KH-ID",
451 sm->r0kh_id, sm->r0kh_id_len);
455 if (parse.r1kh_id == NULL) {
456 wpa_printf(MSG_DEBUG, "FT: No R1KH-ID subelem in FTIE");
460 if (parse.rsn_pmkid == NULL ||
461 os_memcmp(parse.rsn_pmkid, sm->pmk_r0_name, WPA_PMK_NAME_LEN)) {
462 wpa_printf(MSG_DEBUG, "FT: No matching PMKR0Name (PMKID) in "
467 os_memcpy(sm->r1kh_id, parse.r1kh_id, FT_R1KH_ID_LEN);
468 wpa_hexdump(MSG_DEBUG, "FT: R1KH-ID", sm->r1kh_id, FT_R1KH_ID_LEN);
469 wpa_hexdump(MSG_DEBUG, "FT: SNonce", sm->snonce, WPA_NONCE_LEN);
470 wpa_hexdump(MSG_DEBUG, "FT: ANonce", ftie->anonce, WPA_NONCE_LEN);
471 os_memcpy(sm->anonce, ftie->anonce, WPA_NONCE_LEN);
472 wpa_derive_pmk_r1(sm->pmk_r0, sm->pmk_r0_name, sm->r1kh_id,
473 sm->own_addr, sm->pmk_r1, sm->pmk_r1_name);
474 wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R1", sm->pmk_r1, PMK_LEN);
475 wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name",
476 sm->pmk_r1_name, WPA_PMK_NAME_LEN);
479 ptk_len = sm->pairwise_cipher != WPA_CIPHER_TKIP ? 48 : 64;
480 wpa_pmk_r1_to_ptk(sm->pmk_r1, sm->snonce, ftie->anonce, sm->own_addr,
481 bssid, sm->pmk_r1_name,
482 (u8 *) &sm->ptk, ptk_len, ptk_name);
483 wpa_hexdump_key(MSG_DEBUG, "FT: PTK",
484 (u8 *) &sm->ptk, ptk_len);
485 wpa_hexdump(MSG_DEBUG, "FT: PTKName", ptk_name, WPA_PMK_NAME_LEN);
487 ft_ies = wpa_ft_gen_req_ies(sm, &ft_ies_len, ftie->anonce,
488 sm->pmk_r1_name, sm->ptk.kck, bssid,
489 ric_ies, ric_ies_len,
490 parse.mdie ? parse.mdie - 2 : NULL);
492 wpa_sm_update_ft_ies(sm, sm->mobility_domain,
497 wpa_sm_mark_authenticated(sm, bssid);
498 ret = wpa_ft_install_ptk(sm, bssid);
501 * Some drivers do not support key configuration when we are
502 * not associated with the target AP. Work around this by
503 * trying again after the following reassociation gets
506 wpa_printf(MSG_DEBUG, "FT: Failed to set PTK prior to "
507 "association - try again after reassociation");
508 sm->set_ptk_after_assoc = 1;
510 sm->set_ptk_after_assoc = 0;
512 sm->ft_completed = 1;
515 * The caller is expected trigger re-association with the
518 os_memcpy(sm->bssid, target_ap, ETH_ALEN);
525 int wpa_ft_is_completed(struct wpa_sm *sm)
530 if (sm->key_mgmt != WPA_KEY_MGMT_FT_IEEE8021X &&
531 sm->key_mgmt != WPA_KEY_MGMT_FT_PSK)
534 return sm->ft_completed;
538 static int wpa_ft_process_gtk_subelem(struct wpa_sm *sm, const u8 *gtk_elem,
544 size_t gtk_len, keylen, rsc_len;
546 if (gtk_elem == NULL) {
547 wpa_printf(MSG_DEBUG, "FT: No GTK included in FTIE");
551 wpa_hexdump_key(MSG_DEBUG, "FT: Received GTK in Reassoc Resp",
552 gtk_elem, gtk_elem_len);
554 if (gtk_elem_len < 11 + 24 || (gtk_elem_len - 11) % 8 ||
555 gtk_elem_len - 19 > sizeof(gtk)) {
556 wpa_printf(MSG_DEBUG, "FT: Invalid GTK sub-elem "
557 "length %lu", (unsigned long) gtk_elem_len);
560 gtk_len = gtk_elem_len - 19;
561 if (aes_unwrap(sm->ptk.kek, gtk_len / 8, gtk_elem + 11, gtk)) {
562 wpa_printf(MSG_WARNING, "FT: AES unwrap failed - could not "
567 keylen = wpa_cipher_key_len(sm->group_cipher);
568 rsc_len = wpa_cipher_rsc_len(sm->group_cipher);
569 alg = wpa_cipher_to_alg(sm->group_cipher);
570 if (alg == WPA_ALG_NONE) {
571 wpa_printf(MSG_WARNING, "WPA: Unsupported Group Cipher %d",
576 if (gtk_len < keylen) {
577 wpa_printf(MSG_DEBUG, "FT: Too short GTK in FTIE");
581 /* Key Info[2] | Key Length[1] | RSC[8] | Key[5..32]. */
583 keyidx = WPA_GET_LE16(gtk_elem) & 0x03;
585 if (gtk_elem[2] != keylen) {
586 wpa_printf(MSG_DEBUG, "FT: GTK length mismatch: received %d "
588 gtk_elem[2], (unsigned long) keylen);
592 wpa_hexdump_key(MSG_DEBUG, "FT: GTK from Reassoc Resp", gtk, keylen);
593 if (wpa_sm_set_key(sm, alg, broadcast_ether_addr, keyidx, 0,
594 gtk_elem + 3, rsc_len, gtk, keylen) < 0) {
595 wpa_printf(MSG_WARNING, "WPA: Failed to set GTK to the "
604 #ifdef CONFIG_IEEE80211W
605 static int wpa_ft_process_igtk_subelem(struct wpa_sm *sm, const u8 *igtk_elem,
606 size_t igtk_elem_len)
608 u8 igtk[WPA_IGTK_LEN];
611 if (sm->mgmt_group_cipher != WPA_CIPHER_AES_128_CMAC)
614 if (igtk_elem == NULL) {
615 wpa_printf(MSG_DEBUG, "FT: No IGTK included in FTIE");
619 wpa_hexdump_key(MSG_DEBUG, "FT: Received IGTK in Reassoc Resp",
620 igtk_elem, igtk_elem_len);
622 if (igtk_elem_len != 2 + 6 + 1 + WPA_IGTK_LEN + 8) {
623 wpa_printf(MSG_DEBUG, "FT: Invalid IGTK sub-elem "
624 "length %lu", (unsigned long) igtk_elem_len);
627 if (igtk_elem[8] != WPA_IGTK_LEN) {
628 wpa_printf(MSG_DEBUG, "FT: Invalid IGTK sub-elem Key Length "
633 if (aes_unwrap(sm->ptk.kek, WPA_IGTK_LEN / 8, igtk_elem + 9, igtk)) {
634 wpa_printf(MSG_WARNING, "FT: AES unwrap failed - could not "
639 /* KeyID[2] | IPN[6] | Key Length[1] | Key[16+8] */
641 keyidx = WPA_GET_LE16(igtk_elem);
643 wpa_hexdump_key(MSG_DEBUG, "FT: IGTK from Reassoc Resp", igtk,
645 if (wpa_sm_set_key(sm, WPA_ALG_IGTK, broadcast_ether_addr, keyidx, 0,
646 igtk_elem + 2, 6, igtk, WPA_IGTK_LEN) < 0) {
647 wpa_printf(MSG_WARNING, "WPA: Failed to set IGTK to the "
654 #endif /* CONFIG_IEEE80211W */
657 int wpa_ft_validate_reassoc_resp(struct wpa_sm *sm, const u8 *ies,
658 size_t ies_len, const u8 *src_addr)
660 struct wpa_ft_ies parse;
661 struct rsn_mdie *mdie;
662 struct rsn_ftie *ftie;
666 wpa_hexdump(MSG_DEBUG, "FT: Response IEs", ies, ies_len);
668 if (sm->key_mgmt != WPA_KEY_MGMT_FT_IEEE8021X &&
669 sm->key_mgmt != WPA_KEY_MGMT_FT_PSK) {
670 wpa_printf(MSG_DEBUG, "FT: Reject FT IEs since FT is not "
671 "enabled for this connection");
675 if (sm->ft_reassoc_completed) {
676 wpa_printf(MSG_DEBUG, "FT: Reassociation has already been completed for this FT protocol instance - ignore unexpected retransmission");
680 if (wpa_ft_parse_ies(ies, ies_len, &parse) < 0) {
681 wpa_printf(MSG_DEBUG, "FT: Failed to parse IEs");
685 mdie = (struct rsn_mdie *) parse.mdie;
686 if (mdie == NULL || parse.mdie_len < sizeof(*mdie) ||
687 os_memcmp(mdie->mobility_domain, sm->mobility_domain,
688 MOBILITY_DOMAIN_ID_LEN) != 0) {
689 wpa_printf(MSG_DEBUG, "FT: Invalid MDIE");
693 ftie = (struct rsn_ftie *) parse.ftie;
694 if (ftie == NULL || parse.ftie_len < sizeof(*ftie)) {
695 wpa_printf(MSG_DEBUG, "FT: Invalid FTIE");
699 if (os_memcmp(ftie->snonce, sm->snonce, WPA_NONCE_LEN) != 0) {
700 wpa_printf(MSG_DEBUG, "FT: SNonce mismatch in FTIE");
701 wpa_hexdump(MSG_DEBUG, "FT: Received SNonce",
702 ftie->snonce, WPA_NONCE_LEN);
703 wpa_hexdump(MSG_DEBUG, "FT: Expected SNonce",
704 sm->snonce, WPA_NONCE_LEN);
708 if (os_memcmp(ftie->anonce, sm->anonce, WPA_NONCE_LEN) != 0) {
709 wpa_printf(MSG_DEBUG, "FT: ANonce mismatch in FTIE");
710 wpa_hexdump(MSG_DEBUG, "FT: Received ANonce",
711 ftie->anonce, WPA_NONCE_LEN);
712 wpa_hexdump(MSG_DEBUG, "FT: Expected ANonce",
713 sm->anonce, WPA_NONCE_LEN);
717 if (parse.r0kh_id == NULL) {
718 wpa_printf(MSG_DEBUG, "FT: No R0KH-ID subelem in FTIE");
722 if (parse.r0kh_id_len != sm->r0kh_id_len ||
723 os_memcmp(parse.r0kh_id, sm->r0kh_id, parse.r0kh_id_len) != 0) {
724 wpa_printf(MSG_DEBUG, "FT: R0KH-ID in FTIE did not match with "
725 "the current R0KH-ID");
726 wpa_hexdump(MSG_DEBUG, "FT: R0KH-ID in FTIE",
727 parse.r0kh_id, parse.r0kh_id_len);
728 wpa_hexdump(MSG_DEBUG, "FT: The current R0KH-ID",
729 sm->r0kh_id, sm->r0kh_id_len);
733 if (parse.r1kh_id == NULL) {
734 wpa_printf(MSG_DEBUG, "FT: No R1KH-ID subelem in FTIE");
738 if (os_memcmp(parse.r1kh_id, sm->r1kh_id, FT_R1KH_ID_LEN) != 0) {
739 wpa_printf(MSG_DEBUG, "FT: Unknown R1KH-ID used in "
744 if (parse.rsn_pmkid == NULL ||
745 os_memcmp(parse.rsn_pmkid, sm->pmk_r1_name, WPA_PMK_NAME_LEN)) {
746 wpa_printf(MSG_DEBUG, "FT: No matching PMKR1Name (PMKID) in "
747 "RSNIE (pmkid=%d)", !!parse.rsn_pmkid);
753 count += ieee802_11_ie_count(parse.ric, parse.ric_len);
754 if (ftie->mic_control[1] != count) {
755 wpa_printf(MSG_DEBUG, "FT: Unexpected IE count in MIC "
756 "Control: received %u expected %u",
757 ftie->mic_control[1], count);
761 if (wpa_ft_mic(sm->ptk.kck, sm->own_addr, src_addr, 6,
762 parse.mdie - 2, parse.mdie_len + 2,
763 parse.ftie - 2, parse.ftie_len + 2,
764 parse.rsn - 2, parse.rsn_len + 2,
765 parse.ric, parse.ric_len,
767 wpa_printf(MSG_DEBUG, "FT: Failed to calculate MIC");
771 if (os_memcmp(mic, ftie->mic, 16) != 0) {
772 wpa_printf(MSG_DEBUG, "FT: Invalid MIC in FTIE");
773 wpa_hexdump(MSG_MSGDUMP, "FT: Received MIC", ftie->mic, 16);
774 wpa_hexdump(MSG_MSGDUMP, "FT: Calculated MIC", mic, 16);
778 sm->ft_reassoc_completed = 1;
780 if (wpa_ft_process_gtk_subelem(sm, parse.gtk, parse.gtk_len) < 0)
783 #ifdef CONFIG_IEEE80211W
784 if (wpa_ft_process_igtk_subelem(sm, parse.igtk, parse.igtk_len) < 0)
786 #endif /* CONFIG_IEEE80211W */
788 if (sm->set_ptk_after_assoc) {
789 wpa_printf(MSG_DEBUG, "FT: Try to set PTK again now that we "
791 if (wpa_ft_install_ptk(sm, src_addr) < 0)
793 sm->set_ptk_after_assoc = 0;
797 wpa_hexdump(MSG_MSGDUMP, "FT: RIC Response",
798 parse.ric, parse.ric_len);
799 /* TODO: parse response and inform driver about results */
807 * wpa_ft_start_over_ds - Generate over-the-DS auth request
808 * @sm: Pointer to WPA state machine data from wpa_sm_init()
809 * @target_ap: Target AP Address
810 * @mdie: Mobility Domain IE from the target AP
811 * Returns: 0 on success, -1 on failure
813 int wpa_ft_start_over_ds(struct wpa_sm *sm, const u8 *target_ap,
819 wpa_printf(MSG_DEBUG, "FT: Request over-the-DS with " MACSTR,
822 /* Generate a new SNonce */
823 if (random_get_bytes(sm->snonce, WPA_NONCE_LEN)) {
824 wpa_printf(MSG_INFO, "FT: Failed to generate a new SNonce");
828 ft_ies = wpa_ft_gen_req_ies(sm, &ft_ies_len, NULL, sm->pmk_r0_name,
829 NULL, target_ap, NULL, 0, mdie);
831 sm->over_the_ds_in_progress = 1;
832 os_memcpy(sm->target_ap, target_ap, ETH_ALEN);
833 wpa_sm_send_ft_action(sm, 1, target_ap, ft_ies, ft_ies_len);
840 #endif /* CONFIG_IEEE80211R */