2 * hostapd - IEEE 802.11r - Fast BSS Transition
3 * Copyright (c) 2004-2009, 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.
15 #include "utils/includes.h"
17 #include "utils/common.h"
18 #include "common/ieee802_11_defs.h"
19 #include "common/ieee802_11_common.h"
20 #include "crypto/aes_wrap.h"
21 #include "ap_config.h"
22 #include "ieee802_11.h"
25 #include "wpa_auth_i.h"
26 #include "wpa_auth_ie.h"
29 #ifdef CONFIG_IEEE80211R
49 static int wpa_ft_parse_ies(const u8
*ies
, size_t ies_len
,
50 struct wpa_ft_ies
*parse
);
53 static int wpa_ft_rrb_send(struct wpa_authenticator
*wpa_auth
, const u8
*dst
,
54 const u8
*data
, size_t data_len
)
56 if (wpa_auth
->cb
.send_ether
== NULL
)
58 return wpa_auth
->cb
.send_ether(wpa_auth
->cb
.ctx
, dst
, ETH_P_RRB
,
63 static int wpa_ft_action_send(struct wpa_authenticator
*wpa_auth
,
64 const u8
*dst
, const u8
*data
, size_t data_len
)
66 if (wpa_auth
->cb
.send_ft_action
== NULL
)
68 return wpa_auth
->cb
.send_ft_action(wpa_auth
->cb
.ctx
, dst
,
73 static struct wpa_state_machine
*
74 wpa_ft_add_sta(struct wpa_authenticator
*wpa_auth
, const u8
*sta_addr
)
76 if (wpa_auth
->cb
.add_sta
== NULL
)
78 return wpa_auth
->cb
.add_sta(wpa_auth
->cb
.ctx
, sta_addr
);
82 int wpa_write_mdie(struct wpa_auth_config
*conf
, u8
*buf
, size_t len
)
86 if (len
< 2 + sizeof(struct rsn_mdie
))
89 *pos
++ = WLAN_EID_MOBILITY_DOMAIN
;
90 *pos
++ = MOBILITY_DOMAIN_ID_LEN
+ 1;
91 os_memcpy(pos
, conf
->mobility_domain
, MOBILITY_DOMAIN_ID_LEN
);
92 pos
+= MOBILITY_DOMAIN_ID_LEN
;
93 capab
= RSN_FT_CAPAB_FT_OVER_DS
;
100 static int wpa_write_ftie(struct wpa_auth_config
*conf
, const u8
*r0kh_id
,
102 const u8
*anonce
, const u8
*snonce
,
103 u8
*buf
, size_t len
, const u8
*subelem
,
106 u8
*pos
= buf
, *ielen
;
107 struct rsn_ftie
*hdr
;
109 if (len
< 2 + sizeof(*hdr
) + 2 + FT_R1KH_ID_LEN
+ 2 + r0kh_id_len
+
113 *pos
++ = WLAN_EID_FAST_BSS_TRANSITION
;
116 hdr
= (struct rsn_ftie
*) pos
;
117 os_memset(hdr
, 0, sizeof(*hdr
));
119 WPA_PUT_LE16(hdr
->mic_control
, 0);
121 os_memcpy(hdr
->anonce
, anonce
, WPA_NONCE_LEN
);
123 os_memcpy(hdr
->snonce
, snonce
, WPA_NONCE_LEN
);
125 /* Optional Parameters */
126 *pos
++ = FTIE_SUBELEM_R1KH_ID
;
127 *pos
++ = FT_R1KH_ID_LEN
;
128 os_memcpy(pos
, conf
->r1_key_holder
, FT_R1KH_ID_LEN
);
129 pos
+= FT_R1KH_ID_LEN
;
132 *pos
++ = FTIE_SUBELEM_R0KH_ID
;
133 *pos
++ = r0kh_id_len
;
134 os_memcpy(pos
, r0kh_id
, r0kh_id_len
);
139 os_memcpy(pos
, subelem
, subelem_len
);
143 *ielen
= pos
- buf
- 2;
149 struct wpa_ft_pmk_r0_sa
{
150 struct wpa_ft_pmk_r0_sa
*next
;
152 u8 pmk_r0_name
[WPA_PMK_NAME_LEN
];
154 /* TODO: expiration, identity, radius_class, EAP type, VLAN ID */
158 struct wpa_ft_pmk_r1_sa
{
159 struct wpa_ft_pmk_r1_sa
*next
;
161 u8 pmk_r1_name
[WPA_PMK_NAME_LEN
];
163 /* TODO: expiration, identity, radius_class, EAP type, VLAN ID */
166 struct wpa_ft_pmk_cache
{
167 struct wpa_ft_pmk_r0_sa
*pmk_r0
;
168 struct wpa_ft_pmk_r1_sa
*pmk_r1
;
171 struct wpa_ft_pmk_cache
* wpa_ft_pmk_cache_init(void)
173 struct wpa_ft_pmk_cache
*cache
;
175 cache
= os_zalloc(sizeof(*cache
));
181 void wpa_ft_pmk_cache_deinit(struct wpa_ft_pmk_cache
*cache
)
183 struct wpa_ft_pmk_r0_sa
*r0
, *r0prev
;
184 struct wpa_ft_pmk_r1_sa
*r1
, *r1prev
;
190 os_memset(r0prev
->pmk_r0
, 0, PMK_LEN
);
198 os_memset(r1prev
->pmk_r1
, 0, PMK_LEN
);
206 static int wpa_ft_store_pmk_r0(struct wpa_authenticator
*wpa_auth
,
207 const u8
*spa
, const u8
*pmk_r0
,
208 const u8
*pmk_r0_name
)
210 struct wpa_ft_pmk_cache
*cache
= wpa_auth
->ft_pmk_cache
;
211 struct wpa_ft_pmk_r0_sa
*r0
;
213 /* TODO: add expiration and limit on number of entries in cache */
215 r0
= os_zalloc(sizeof(*r0
));
219 os_memcpy(r0
->pmk_r0
, pmk_r0
, PMK_LEN
);
220 os_memcpy(r0
->pmk_r0_name
, pmk_r0_name
, WPA_PMK_NAME_LEN
);
221 os_memcpy(r0
->spa
, spa
, ETH_ALEN
);
223 r0
->next
= cache
->pmk_r0
;
230 static int wpa_ft_fetch_pmk_r0(struct wpa_authenticator
*wpa_auth
,
231 const u8
*spa
, const u8
*pmk_r0_name
,
234 struct wpa_ft_pmk_cache
*cache
= wpa_auth
->ft_pmk_cache
;
235 struct wpa_ft_pmk_r0_sa
*r0
;
239 if (os_memcmp(r0
->spa
, spa
, ETH_ALEN
) == 0 &&
240 os_memcmp(r0
->pmk_r0_name
, pmk_r0_name
, WPA_PMK_NAME_LEN
)
242 os_memcpy(pmk_r0
, r0
->pmk_r0
, PMK_LEN
);
253 static int wpa_ft_store_pmk_r1(struct wpa_authenticator
*wpa_auth
,
254 const u8
*spa
, const u8
*pmk_r1
,
255 const u8
*pmk_r1_name
)
257 struct wpa_ft_pmk_cache
*cache
= wpa_auth
->ft_pmk_cache
;
258 struct wpa_ft_pmk_r1_sa
*r1
;
260 /* TODO: add expiration and limit on number of entries in cache */
262 r1
= os_zalloc(sizeof(*r1
));
266 os_memcpy(r1
->pmk_r1
, pmk_r1
, PMK_LEN
);
267 os_memcpy(r1
->pmk_r1_name
, pmk_r1_name
, WPA_PMK_NAME_LEN
);
268 os_memcpy(r1
->spa
, spa
, ETH_ALEN
);
270 r1
->next
= cache
->pmk_r1
;
277 static int wpa_ft_fetch_pmk_r1(struct wpa_authenticator
*wpa_auth
,
278 const u8
*spa
, const u8
*pmk_r1_name
,
281 struct wpa_ft_pmk_cache
*cache
= wpa_auth
->ft_pmk_cache
;
282 struct wpa_ft_pmk_r1_sa
*r1
;
286 if (os_memcmp(r1
->spa
, spa
, ETH_ALEN
) == 0 &&
287 os_memcmp(r1
->pmk_r1_name
, pmk_r1_name
, WPA_PMK_NAME_LEN
)
289 os_memcpy(pmk_r1
, r1
->pmk_r1
, PMK_LEN
);
300 static int wpa_ft_pull_pmk_r1(struct wpa_authenticator
*wpa_auth
,
301 const u8
*s1kh_id
, const u8
*r0kh_id
,
302 size_t r0kh_id_len
, const u8
*pmk_r0_name
)
304 struct ft_remote_r0kh
*r0kh
;
305 struct ft_r0kh_r1kh_pull_frame frame
, f
;
307 r0kh
= wpa_auth
->conf
.r0kh_list
;
309 if (r0kh
->id_len
== r0kh_id_len
&&
310 os_memcmp(r0kh
->id
, r0kh_id
, r0kh_id_len
) == 0)
317 wpa_printf(MSG_DEBUG
, "FT: Send PMK-R1 pull request to remote R0KH "
318 "address " MACSTR
, MAC2STR(r0kh
->addr
));
320 os_memset(&frame
, 0, sizeof(frame
));
321 frame
.frame_type
= RSN_REMOTE_FRAME_TYPE_FT_RRB
;
322 frame
.packet_type
= FT_PACKET_R0KH_R1KH_PULL
;
323 frame
.data_length
= host_to_le16(FT_R0KH_R1KH_PULL_DATA_LEN
);
324 os_memcpy(frame
.ap_address
, wpa_auth
->addr
, ETH_ALEN
);
326 /* aes_wrap() does not support inplace encryption, so use a temporary
327 * buffer for the data. */
328 if (os_get_random(f
.nonce
, sizeof(f
.nonce
))) {
329 wpa_printf(MSG_DEBUG
, "FT: Failed to get random data for "
333 os_memcpy(f
.pmk_r0_name
, pmk_r0_name
, WPA_PMK_NAME_LEN
);
334 os_memcpy(f
.r1kh_id
, wpa_auth
->conf
.r1_key_holder
, FT_R1KH_ID_LEN
);
335 os_memcpy(f
.s1kh_id
, s1kh_id
, ETH_ALEN
);
337 if (aes_wrap(r0kh
->key
, (FT_R0KH_R1KH_PULL_DATA_LEN
+ 7) / 8,
338 f
.nonce
, frame
.nonce
) < 0)
341 wpa_ft_rrb_send(wpa_auth
, r0kh
->addr
, (u8
*) &frame
, sizeof(frame
));
347 int wpa_auth_derive_ptk_ft(struct wpa_state_machine
*sm
, const u8
*pmk
,
348 struct wpa_ptk
*ptk
, size_t ptk_len
)
350 u8 pmk_r0
[PMK_LEN
], pmk_r0_name
[WPA_PMK_NAME_LEN
];
351 u8 pmk_r1
[PMK_LEN
], pmk_r1_name
[WPA_PMK_NAME_LEN
];
352 u8 ptk_name
[WPA_PMK_NAME_LEN
];
353 const u8
*mdid
= sm
->wpa_auth
->conf
.mobility_domain
;
354 const u8
*r0kh
= sm
->wpa_auth
->conf
.r0_key_holder
;
355 size_t r0kh_len
= sm
->wpa_auth
->conf
.r0_key_holder_len
;
356 const u8
*r1kh
= sm
->wpa_auth
->conf
.r1_key_holder
;
357 const u8
*ssid
= sm
->wpa_auth
->conf
.ssid
;
358 size_t ssid_len
= sm
->wpa_auth
->conf
.ssid_len
;
361 if (sm
->xxkey_len
== 0) {
362 wpa_printf(MSG_DEBUG
, "FT: XXKey not available for key "
367 wpa_derive_pmk_r0(sm
->xxkey
, sm
->xxkey_len
, ssid
, ssid_len
, mdid
,
368 r0kh
, r0kh_len
, sm
->addr
, pmk_r0
, pmk_r0_name
);
369 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R0", pmk_r0
, PMK_LEN
);
370 wpa_hexdump(MSG_DEBUG
, "FT: PMKR0Name", pmk_r0_name
, WPA_PMK_NAME_LEN
);
371 wpa_ft_store_pmk_r0(sm
->wpa_auth
, sm
->addr
, pmk_r0
, pmk_r0_name
);
373 wpa_derive_pmk_r1(pmk_r0
, pmk_r0_name
, r1kh
, sm
->addr
,
374 pmk_r1
, pmk_r1_name
);
375 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1", pmk_r1
, PMK_LEN
);
376 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name", pmk_r1_name
, WPA_PMK_NAME_LEN
);
377 wpa_ft_store_pmk_r1(sm
->wpa_auth
, sm
->addr
, pmk_r1
, pmk_r1_name
);
379 wpa_pmk_r1_to_ptk(pmk_r1
, sm
->SNonce
, sm
->ANonce
, sm
->addr
,
380 sm
->wpa_auth
->addr
, pmk_r1_name
,
381 (u8
*) ptk
, ptk_len
, ptk_name
);
382 wpa_hexdump_key(MSG_DEBUG
, "FT: PTK", (u8
*) ptk
, ptk_len
);
383 wpa_hexdump(MSG_DEBUG
, "FT: PTKName", ptk_name
, WPA_PMK_NAME_LEN
);
389 static inline int wpa_auth_get_seqnum(struct wpa_authenticator
*wpa_auth
,
390 const u8
*addr
, int idx
, u8
*seq
)
392 if (wpa_auth
->cb
.get_seqnum
== NULL
)
394 return wpa_auth
->cb
.get_seqnum(wpa_auth
->cb
.ctx
, addr
, idx
, seq
);
398 static u8
* wpa_ft_gtk_subelem(struct wpa_state_machine
*sm
, size_t *len
)
401 struct wpa_group
*gsm
= sm
->group
;
402 size_t subelem_len
, pad_len
;
407 key_len
= gsm
->GTK_len
;
408 if (key_len
> sizeof(keybuf
))
412 * Pad key for AES Key Wrap if it is not multiple of 8 bytes or is less
415 pad_len
= key_len
% 8;
417 pad_len
= 8 - pad_len
;
418 if (key_len
+ pad_len
< 16)
421 os_memcpy(keybuf
, gsm
->GTK
[gsm
->GN
- 1], key_len
);
422 os_memset(keybuf
+ key_len
, 0, pad_len
);
423 keybuf
[key_len
] = 0xdd;
427 key
= gsm
->GTK
[gsm
->GN
- 1];
430 * Sub-elem ID[1] | Length[1] | Key Info[1] | Key Length[1] | RSC[8] |
433 subelem_len
= 12 + key_len
+ 8;
434 subelem
= os_zalloc(subelem_len
);
438 subelem
[0] = FTIE_SUBELEM_GTK
;
439 subelem
[1] = 10 + key_len
+ 8;
440 subelem
[2] = gsm
->GN
& 0x03; /* Key ID in B0-B1 of Key Info */
441 subelem
[3] = gsm
->GTK_len
;
442 wpa_auth_get_seqnum(sm
->wpa_auth
, NULL
, gsm
->GN
, subelem
+ 4);
443 if (aes_wrap(sm
->PTK
.kek
, key_len
/ 8, key
, subelem
+ 12)) {
453 #ifdef CONFIG_IEEE80211W
454 static u8
* wpa_ft_igtk_subelem(struct wpa_state_machine
*sm
, size_t *len
)
457 struct wpa_group
*gsm
= sm
->group
;
460 /* Sub-elem ID[1] | Length[1] | KeyID[2] | IPN[6] | Key Length[1] |
462 subelem_len
= 1 + 1 + 2 + 6 + 1 + WPA_IGTK_LEN
+ 8;
463 subelem
= os_zalloc(subelem_len
);
468 *pos
++ = FTIE_SUBELEM_IGTK
;
469 *pos
++ = subelem_len
- 2;
470 WPA_PUT_LE16(pos
, gsm
->GN_igtk
);
472 wpa_auth_get_seqnum(sm
->wpa_auth
, NULL
, gsm
->GN_igtk
, pos
);
474 *pos
++ = WPA_IGTK_LEN
;
475 if (aes_wrap(sm
->PTK
.kek
, WPA_IGTK_LEN
/ 8,
476 gsm
->IGTK
[gsm
->GN_igtk
- 4], pos
)) {
484 #endif /* CONFIG_IEEE80211W */
487 static u8
* wpa_ft_process_rdie(u8
*pos
, u8
*end
, u8 id
, u8 descr_count
,
488 const u8
*ies
, size_t ies_len
)
490 struct ieee802_11_elems parse
;
491 struct rsn_rdie
*rdie
;
493 wpa_printf(MSG_DEBUG
, "FT: Resource Request: id=%d descr_count=%d",
495 wpa_hexdump(MSG_MSGDUMP
, "FT: Resource descriptor IE(s)",
498 if (end
- pos
< (int) sizeof(*rdie
)) {
499 wpa_printf(MSG_ERROR
, "FT: Not enough room for response RDIE");
503 *pos
++ = WLAN_EID_RIC_DATA
;
504 *pos
++ = sizeof(*rdie
);
505 rdie
= (struct rsn_rdie
*) pos
;
507 rdie
->descr_count
= 0;
508 rdie
->status_code
= host_to_le16(WLAN_STATUS_SUCCESS
);
509 pos
+= sizeof(*rdie
);
511 if (ieee802_11_parse_elems((u8
*) ies
, ies_len
, &parse
, 1) ==
513 wpa_printf(MSG_DEBUG
, "FT: Failed to parse request IEs");
515 host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE
);
520 if (parse
.wmm_tspec
) {
521 struct wmm_tspec_element
*tspec
;
524 if (parse
.wmm_tspec_len
+ 2 < (int) sizeof(*tspec
)) {
525 wpa_printf(MSG_DEBUG
, "FT: Too short WMM TSPEC IE "
526 "(%d)", (int) parse
.wmm_tspec_len
);
528 host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE
);
531 if (end
- pos
< (int) sizeof(*tspec
)) {
532 wpa_printf(MSG_ERROR
, "FT: Not enough room for "
535 host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE
);
538 tspec
= (struct wmm_tspec_element
*) pos
;
539 os_memcpy(tspec
, parse
.wmm_tspec
- 2, sizeof(*tspec
));
540 res
= wmm_process_tspec(tspec
);
541 wpa_printf(MSG_DEBUG
, "FT: ADDTS processing result: %d", res
);
542 if (res
== WMM_ADDTS_STATUS_INVALID_PARAMETERS
)
544 host_to_le16(WLAN_STATUS_INVALID_PARAMETERS
);
545 else if (res
== WMM_ADDTS_STATUS_REFUSED
)
547 host_to_le16(WLAN_STATUS_REQUEST_DECLINED
);
549 /* TSPEC accepted; include updated TSPEC in response */
550 rdie
->descr_count
= 1;
551 pos
+= sizeof(*tspec
);
555 #endif /* NEED_AP_MLME */
557 wpa_printf(MSG_DEBUG
, "FT: No supported resource requested");
558 rdie
->status_code
= host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE
);
563 static u8
* wpa_ft_process_ric(u8
*pos
, u8
*end
, const u8
*ric
, size_t ric_len
)
565 const u8
*rpos
, *start
;
566 const struct rsn_rdie
*rdie
;
568 wpa_hexdump(MSG_MSGDUMP
, "FT: RIC Request", ric
, ric_len
);
571 while (rpos
+ sizeof(*rdie
) < ric
+ ric_len
) {
572 if (rpos
[0] != WLAN_EID_RIC_DATA
|| rpos
[1] < sizeof(*rdie
) ||
573 rpos
+ 2 + rpos
[1] > ric
+ ric_len
)
575 rdie
= (const struct rsn_rdie
*) (rpos
+ 2);
579 while (rpos
+ 2 <= ric
+ ric_len
&&
580 rpos
+ 2 + rpos
[1] <= ric
+ ric_len
) {
581 if (rpos
[0] == WLAN_EID_RIC_DATA
)
585 pos
= wpa_ft_process_rdie(pos
, end
, rdie
->id
,
587 start
, rpos
- start
);
594 u8
* wpa_sm_write_assoc_resp_ies(struct wpa_state_machine
*sm
, u8
*pos
,
595 size_t max_len
, int auth_alg
,
596 const u8
*req_ies
, size_t req_ies_len
)
598 u8
*end
, *mdie
, *ftie
, *rsnie
, *r0kh_id
, *subelem
= NULL
;
599 size_t mdie_len
, ftie_len
, rsnie_len
, r0kh_id_len
, subelem_len
= 0;
601 struct wpa_auth_config
*conf
;
602 struct rsn_ftie
*_ftie
;
603 struct wpa_ft_ies parse
;
609 conf
= &sm
->wpa_auth
->conf
;
611 if (sm
->wpa_key_mgmt
!= WPA_KEY_MGMT_FT_IEEE8021X
&&
612 sm
->wpa_key_mgmt
!= WPA_KEY_MGMT_FT_PSK
)
618 res
= wpa_write_rsn_ie(conf
, pos
, end
- pos
, sm
->pmk_r1_name
);
625 /* Mobility Domain Information */
626 res
= wpa_write_mdie(conf
, pos
, end
- pos
);
633 /* Fast BSS Transition Information */
634 if (auth_alg
== WLAN_AUTH_FT
) {
635 subelem
= wpa_ft_gtk_subelem(sm
, &subelem_len
);
636 r0kh_id
= sm
->r0kh_id
;
637 r0kh_id_len
= sm
->r0kh_id_len
;
638 #ifdef CONFIG_IEEE80211W
639 if (sm
->mgmt_frame_prot
) {
643 igtk
= wpa_ft_igtk_subelem(sm
, &igtk_len
);
648 nbuf
= os_realloc(subelem
, subelem_len
+ igtk_len
);
655 os_memcpy(subelem
+ subelem_len
, igtk
, igtk_len
);
656 subelem_len
+= igtk_len
;
659 #endif /* CONFIG_IEEE80211W */
661 r0kh_id
= conf
->r0_key_holder
;
662 r0kh_id_len
= conf
->r0_key_holder_len
;
664 res
= wpa_write_ftie(conf
, r0kh_id
, r0kh_id_len
, NULL
, NULL
, pos
,
665 end
- pos
, subelem
, subelem_len
);
673 _ftie
= (struct rsn_ftie
*) (ftie
+ 2);
674 _ftie
->mic_control
[1] = 3; /* Information element count */
677 if (wpa_ft_parse_ies(req_ies
, req_ies_len
, &parse
) == 0 && parse
.ric
) {
678 pos
= wpa_ft_process_ric(pos
, end
, parse
.ric
, parse
.ric_len
);
679 _ftie
->mic_control
[1] += ieee802_11_ie_count(ric_start
,
682 if (ric_start
== pos
)
685 if (wpa_ft_mic(sm
->PTK
.kck
, sm
->addr
, sm
->wpa_auth
->addr
, 6,
686 mdie
, mdie_len
, ftie
, ftie_len
,
688 ric_start
, ric_start
? pos
- ric_start
: 0,
690 wpa_printf(MSG_DEBUG
, "FT: Failed to calculate MIC");
696 static int wpa_ft_parse_ftie(const u8
*ie
, size_t ie_len
,
697 struct wpa_ft_ies
*parse
)
702 parse
->ftie_len
= ie_len
;
704 pos
= ie
+ sizeof(struct rsn_ftie
);
707 while (pos
+ 2 <= end
&& pos
+ 2 + pos
[1] <= end
) {
709 case FTIE_SUBELEM_R1KH_ID
:
710 if (pos
[1] != FT_R1KH_ID_LEN
) {
711 wpa_printf(MSG_DEBUG
, "FT: Invalid R1KH-ID "
712 "length in FTIE: %d", pos
[1]);
715 parse
->r1kh_id
= pos
+ 2;
717 case FTIE_SUBELEM_GTK
:
718 parse
->gtk
= pos
+ 2;
719 parse
->gtk_len
= pos
[1];
721 case FTIE_SUBELEM_R0KH_ID
:
722 if (pos
[1] < 1 || pos
[1] > FT_R0KH_ID_MAX_LEN
) {
723 wpa_printf(MSG_DEBUG
, "FT: Invalid R0KH-ID "
724 "length in FTIE: %d", pos
[1]);
727 parse
->r0kh_id
= pos
+ 2;
728 parse
->r0kh_id_len
= pos
[1];
739 static int wpa_ft_parse_ies(const u8
*ies
, size_t ies_len
,
740 struct wpa_ft_ies
*parse
)
743 struct wpa_ie_data data
;
745 const struct rsn_ftie
*ftie
;
746 int prot_ie_count
= 0;
748 os_memset(parse
, 0, sizeof(*parse
));
754 while (pos
+ 2 <= end
&& pos
+ 2 + pos
[1] <= end
) {
757 parse
->rsn
= pos
+ 2;
758 parse
->rsn_len
= pos
[1];
759 ret
= wpa_parse_wpa_ie_rsn(parse
->rsn
- 2,
763 wpa_printf(MSG_DEBUG
, "FT: Failed to parse "
767 if (data
.num_pmkid
== 1 && data
.pmkid
)
768 parse
->rsn_pmkid
= data
.pmkid
;
770 case WLAN_EID_MOBILITY_DOMAIN
:
771 parse
->mdie
= pos
+ 2;
772 parse
->mdie_len
= pos
[1];
774 case WLAN_EID_FAST_BSS_TRANSITION
:
775 if (pos
[1] < sizeof(*ftie
))
777 ftie
= (const struct rsn_ftie
*) (pos
+ 2);
778 prot_ie_count
= ftie
->mic_control
[1];
779 if (wpa_ft_parse_ftie(pos
+ 2, pos
[1], parse
) < 0)
782 case WLAN_EID_RIC_DATA
:
783 if (parse
->ric
== NULL
)
790 if (prot_ie_count
== 0)
791 return 0; /* no MIC */
794 * Check that the protected IE count matches with IEs included in the
803 if (prot_ie_count
< 0) {
804 wpa_printf(MSG_DEBUG
, "FT: Some required IEs not included in "
805 "the protected IE count");
809 if (prot_ie_count
== 0 && parse
->ric
) {
810 wpa_printf(MSG_DEBUG
, "FT: RIC IE(s) in the frame, but not "
811 "included in protected IE count");
815 /* Determine the end of the RIC IE(s) */
817 while (pos
&& pos
+ 2 <= end
&& pos
+ 2 + pos
[1] <= end
&&
822 parse
->ric_len
= pos
- parse
->ric
;
824 wpa_printf(MSG_DEBUG
, "FT: %d protected IEs missing from "
825 "frame", (int) prot_ie_count
);
833 static inline int wpa_auth_set_key(struct wpa_authenticator
*wpa_auth
,
835 enum wpa_alg alg
, const u8
*addr
, int idx
,
836 u8
*key
, size_t key_len
)
838 if (wpa_auth
->cb
.set_key
== NULL
)
840 return wpa_auth
->cb
.set_key(wpa_auth
->cb
.ctx
, vlan_id
, alg
, addr
, idx
,
845 static void wpa_ft_install_ptk(struct wpa_state_machine
*sm
)
850 /* MLME-SETKEYS.request(PTK) */
851 if (sm
->pairwise
== WPA_CIPHER_TKIP
) {
854 } else if (sm
->pairwise
== WPA_CIPHER_CCMP
) {
860 /* FIX: add STA entry to kernel/driver here? The set_key will fail
861 * most likely without this.. At the moment, STA entry is added only
862 * after association has been completed. Alternatively, could
863 * re-configure PTK at that point(?).
865 if (wpa_auth_set_key(sm
->wpa_auth
, 0, alg
, sm
->addr
, 0,
869 /* FIX: MLME-SetProtection.Request(TA, Tx_Rx) */
870 sm
->pairwise_set
= TRUE
;
874 static u16
wpa_ft_process_auth_req(struct wpa_state_machine
*sm
,
875 const u8
*ies
, size_t ies_len
,
876 u8
**resp_ies
, size_t *resp_ies_len
)
878 struct rsn_mdie
*mdie
;
879 struct rsn_ftie
*ftie
;
880 u8 pmk_r1
[PMK_LEN
], pmk_r1_name
[WPA_PMK_NAME_LEN
];
881 u8 ptk_name
[WPA_PMK_NAME_LEN
];
882 struct wpa_auth_config
*conf
;
883 struct wpa_ft_ies parse
;
884 size_t buflen
, ptk_len
;
891 sm
->pmk_r1_name_valid
= 0;
892 conf
= &sm
->wpa_auth
->conf
;
894 wpa_hexdump(MSG_DEBUG
, "FT: Received authentication frame IEs",
897 if (wpa_ft_parse_ies(ies
, ies_len
, &parse
) < 0) {
898 wpa_printf(MSG_DEBUG
, "FT: Failed to parse FT IEs");
899 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
902 mdie
= (struct rsn_mdie
*) parse
.mdie
;
903 if (mdie
== NULL
|| parse
.mdie_len
< sizeof(*mdie
) ||
904 os_memcmp(mdie
->mobility_domain
,
905 sm
->wpa_auth
->conf
.mobility_domain
,
906 MOBILITY_DOMAIN_ID_LEN
) != 0) {
907 wpa_printf(MSG_DEBUG
, "FT: Invalid MDIE");
908 return WLAN_STATUS_INVALID_MDIE
;
911 ftie
= (struct rsn_ftie
*) parse
.ftie
;
912 if (ftie
== NULL
|| parse
.ftie_len
< sizeof(*ftie
)) {
913 wpa_printf(MSG_DEBUG
, "FT: Invalid FTIE");
914 return WLAN_STATUS_INVALID_FTIE
;
917 os_memcpy(sm
->SNonce
, ftie
->snonce
, WPA_NONCE_LEN
);
919 if (parse
.r0kh_id
== NULL
) {
920 wpa_printf(MSG_DEBUG
, "FT: Invalid FTIE - no R0KH-ID");
921 return WLAN_STATUS_INVALID_FTIE
;
924 wpa_hexdump(MSG_DEBUG
, "FT: STA R0KH-ID",
925 parse
.r0kh_id
, parse
.r0kh_id_len
);
926 os_memcpy(sm
->r0kh_id
, parse
.r0kh_id
, parse
.r0kh_id_len
);
927 sm
->r0kh_id_len
= parse
.r0kh_id_len
;
929 if (parse
.rsn_pmkid
== NULL
) {
930 wpa_printf(MSG_DEBUG
, "FT: No PMKID in RSNIE");
931 return WLAN_STATUS_INVALID_PMKID
;
934 wpa_hexdump(MSG_DEBUG
, "FT: Requested PMKR0Name",
935 parse
.rsn_pmkid
, WPA_PMK_NAME_LEN
);
936 wpa_derive_pmk_r1_name(parse
.rsn_pmkid
,
937 sm
->wpa_auth
->conf
.r1_key_holder
, sm
->addr
,
939 wpa_hexdump(MSG_DEBUG
, "FT: Derived requested PMKR1Name",
940 pmk_r1_name
, WPA_PMK_NAME_LEN
);
942 if (wpa_ft_fetch_pmk_r1(sm
->wpa_auth
, sm
->addr
, pmk_r1_name
, pmk_r1
) <
944 if (wpa_ft_pull_pmk_r1(sm
->wpa_auth
, sm
->addr
, sm
->r0kh_id
,
945 sm
->r0kh_id_len
, parse
.rsn_pmkid
) < 0) {
946 wpa_printf(MSG_DEBUG
, "FT: Did not have matching "
947 "PMK-R1 and unknown R0KH-ID");
948 return WLAN_STATUS_INVALID_PMKID
;
952 * TODO: Should return "status pending" (and the caller should
953 * not send out response now). The real response will be sent
954 * once the response from R0KH is received.
956 return WLAN_STATUS_INVALID_PMKID
;
959 wpa_hexdump_key(MSG_DEBUG
, "FT: Selected PMK-R1", pmk_r1
, PMK_LEN
);
960 sm
->pmk_r1_name_valid
= 1;
961 os_memcpy(sm
->pmk_r1_name
, pmk_r1_name
, WPA_PMK_NAME_LEN
);
963 if (os_get_random(sm
->ANonce
, WPA_NONCE_LEN
)) {
964 wpa_printf(MSG_DEBUG
, "FT: Failed to get random data for "
966 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
969 wpa_hexdump(MSG_DEBUG
, "FT: Received SNonce",
970 sm
->SNonce
, WPA_NONCE_LEN
);
971 wpa_hexdump(MSG_DEBUG
, "FT: Generated ANonce",
972 sm
->ANonce
, WPA_NONCE_LEN
);
974 ptk_len
= sm
->pairwise
== WPA_CIPHER_CCMP
? 48 : 64;
975 wpa_pmk_r1_to_ptk(pmk_r1
, sm
->SNonce
, sm
->ANonce
, sm
->addr
,
976 sm
->wpa_auth
->addr
, pmk_r1_name
,
977 (u8
*) &sm
->PTK
, ptk_len
, ptk_name
);
978 wpa_hexdump_key(MSG_DEBUG
, "FT: PTK",
979 (u8
*) &sm
->PTK
, ptk_len
);
980 wpa_hexdump(MSG_DEBUG
, "FT: PTKName", ptk_name
, WPA_PMK_NAME_LEN
);
982 wpa_ft_install_ptk(sm
);
984 buflen
= 2 + sizeof(struct rsn_mdie
) + 2 + sizeof(struct rsn_ftie
) +
985 2 + FT_R1KH_ID_LEN
+ 200;
986 *resp_ies
= os_zalloc(buflen
);
987 if (*resp_ies
== NULL
) {
988 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
992 end
= *resp_ies
+ buflen
;
994 ret
= wpa_write_rsn_ie(conf
, pos
, end
- pos
, parse
.rsn_pmkid
);
998 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
1002 ret
= wpa_write_mdie(conf
, pos
, end
- pos
);
1006 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
1010 ret
= wpa_write_ftie(conf
, parse
.r0kh_id
, parse
.r0kh_id_len
,
1011 sm
->ANonce
, sm
->SNonce
, pos
, end
- pos
, NULL
, 0);
1015 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
1019 *resp_ies_len
= pos
- *resp_ies
;
1021 return WLAN_STATUS_SUCCESS
;
1025 void wpa_ft_process_auth(struct wpa_state_machine
*sm
, const u8
*bssid
,
1026 u16 auth_transaction
, const u8
*ies
, size_t ies_len
,
1027 void (*cb
)(void *ctx
, const u8
*dst
, const u8
*bssid
,
1028 u16 auth_transaction
, u16 status
,
1029 const u8
*ies
, size_t ies_len
),
1034 size_t resp_ies_len
;
1037 wpa_printf(MSG_DEBUG
, "FT: Received authentication frame, but "
1038 "WPA SM not available");
1042 wpa_printf(MSG_DEBUG
, "FT: Received authentication frame: STA=" MACSTR
1043 " BSSID=" MACSTR
" transaction=%d",
1044 MAC2STR(sm
->addr
), MAC2STR(bssid
), auth_transaction
);
1045 status
= wpa_ft_process_auth_req(sm
, ies
, ies_len
, &resp_ies
,
1048 wpa_printf(MSG_DEBUG
, "FT: FT authentication response: dst=" MACSTR
1049 " auth_transaction=%d status=%d",
1050 MAC2STR(sm
->addr
), auth_transaction
+ 1, status
);
1051 wpa_hexdump(MSG_DEBUG
, "FT: Response IEs", resp_ies
, resp_ies_len
);
1052 cb(ctx
, sm
->addr
, bssid
, auth_transaction
+ 1, status
,
1053 resp_ies
, resp_ies_len
);
1058 u16
wpa_ft_validate_reassoc(struct wpa_state_machine
*sm
, const u8
*ies
,
1061 struct wpa_ft_ies parse
;
1062 struct rsn_mdie
*mdie
;
1063 struct rsn_ftie
*ftie
;
1067 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
1069 wpa_hexdump(MSG_DEBUG
, "FT: Reassoc Req IEs", ies
, ies_len
);
1071 if (wpa_ft_parse_ies(ies
, ies_len
, &parse
) < 0) {
1072 wpa_printf(MSG_DEBUG
, "FT: Failed to parse FT IEs");
1073 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
1076 if (parse
.rsn
== NULL
) {
1077 wpa_printf(MSG_DEBUG
, "FT: No RSNIE in Reassoc Req");
1078 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
1081 if (parse
.rsn_pmkid
== NULL
) {
1082 wpa_printf(MSG_DEBUG
, "FT: No PMKID in RSNIE");
1083 return WLAN_STATUS_INVALID_PMKID
;
1086 if (os_memcmp(parse
.rsn_pmkid
, sm
->pmk_r1_name
, WPA_PMK_NAME_LEN
) != 0)
1088 wpa_printf(MSG_DEBUG
, "FT: PMKID in Reassoc Req did not match "
1089 "with the PMKR1Name derived from auth request");
1090 return WLAN_STATUS_INVALID_PMKID
;
1093 mdie
= (struct rsn_mdie
*) parse
.mdie
;
1094 if (mdie
== NULL
|| parse
.mdie_len
< sizeof(*mdie
) ||
1095 os_memcmp(mdie
->mobility_domain
,
1096 sm
->wpa_auth
->conf
.mobility_domain
,
1097 MOBILITY_DOMAIN_ID_LEN
) != 0) {
1098 wpa_printf(MSG_DEBUG
, "FT: Invalid MDIE");
1099 return WLAN_STATUS_INVALID_MDIE
;
1102 ftie
= (struct rsn_ftie
*) parse
.ftie
;
1103 if (ftie
== NULL
|| parse
.ftie_len
< sizeof(*ftie
)) {
1104 wpa_printf(MSG_DEBUG
, "FT: Invalid FTIE");
1105 return WLAN_STATUS_INVALID_FTIE
;
1108 if (wpa_ft_mic(sm
->PTK
.kck
, sm
->addr
, sm
->wpa_auth
->addr
, 5,
1109 parse
.mdie
- 2, parse
.mdie_len
+ 2,
1110 parse
.ftie
- 2, parse
.ftie_len
+ 2,
1111 parse
.rsn
- 2, parse
.rsn_len
+ 2,
1112 parse
.ric
, parse
.ric_len
,
1114 wpa_printf(MSG_DEBUG
, "FT: Failed to calculate MIC");
1115 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
1118 if (os_memcmp(mic
, ftie
->mic
, 16) != 0) {
1119 wpa_printf(MSG_DEBUG
, "FT: Invalid MIC in FTIE");
1120 wpa_hexdump(MSG_MSGDUMP
, "FT: Received MIC", ftie
->mic
, 16);
1121 wpa_hexdump(MSG_MSGDUMP
, "FT: Calculated MIC", mic
, 16);
1122 return WLAN_STATUS_INVALID_FTIE
;
1125 return WLAN_STATUS_SUCCESS
;
1129 int wpa_ft_action_rx(struct wpa_state_machine
*sm
, const u8
*data
, size_t len
)
1131 const u8
*sta_addr
, *target_ap
;
1135 struct ft_rrb_frame
*frame
;
1141 * data: Category[1] Action[1] STA_Address[6] Target_AP_Address[6]
1142 * FT Request action frame body[variable]
1146 wpa_printf(MSG_DEBUG
, "FT: Too short FT Action frame "
1147 "(len=%lu)", (unsigned long) len
);
1152 sta_addr
= data
+ 2;
1153 target_ap
= data
+ 8;
1157 wpa_printf(MSG_DEBUG
, "FT: Received FT Action frame (STA=" MACSTR
1158 " Target AP=" MACSTR
" Action=%d)",
1159 MAC2STR(sta_addr
), MAC2STR(target_ap
), action
);
1161 if (os_memcmp(sta_addr
, sm
->addr
, ETH_ALEN
) != 0) {
1162 wpa_printf(MSG_DEBUG
, "FT: Mismatch in FT Action STA address: "
1163 "STA=" MACSTR
" STA-Address=" MACSTR
,
1164 MAC2STR(sm
->addr
), MAC2STR(sta_addr
));
1169 * Do some sanity checking on the target AP address (not own and not
1170 * broadcast. This could be extended to filter based on a list of known
1171 * APs in the MD (if such a list were configured).
1173 if ((target_ap
[0] & 0x01) ||
1174 os_memcmp(target_ap
, sm
->wpa_auth
->addr
, ETH_ALEN
) == 0) {
1175 wpa_printf(MSG_DEBUG
, "FT: Invalid Target AP in FT Action "
1180 wpa_hexdump(MSG_MSGDUMP
, "FT: Action frame body", ies
, ies_len
);
1182 /* RRB - Forward action frame to the target AP */
1183 frame
= os_malloc(sizeof(*frame
) + len
);
1184 frame
->frame_type
= RSN_REMOTE_FRAME_TYPE_FT_RRB
;
1185 frame
->packet_type
= FT_PACKET_REQUEST
;
1186 frame
->action_length
= host_to_le16(len
);
1187 os_memcpy(frame
->ap_address
, sm
->wpa_auth
->addr
, ETH_ALEN
);
1188 os_memcpy(frame
+ 1, data
, len
);
1190 wpa_ft_rrb_send(sm
->wpa_auth
, target_ap
, (u8
*) frame
,
1191 sizeof(*frame
) + len
);
1198 static int wpa_ft_rrb_rx_request(struct wpa_authenticator
*wpa_auth
,
1199 const u8
*current_ap
, const u8
*sta_addr
,
1200 const u8
*body
, size_t len
)
1202 struct wpa_state_machine
*sm
;
1205 size_t resp_ies_len
, rlen
;
1206 struct ft_rrb_frame
*frame
;
1208 sm
= wpa_ft_add_sta(wpa_auth
, sta_addr
);
1210 wpa_printf(MSG_DEBUG
, "FT: Failed to add new STA based on "
1215 wpa_hexdump(MSG_MSGDUMP
, "FT: RRB Request Frame body", body
, len
);
1217 status
= wpa_ft_process_auth_req(sm
, body
, len
, &resp_ies
,
1220 wpa_printf(MSG_DEBUG
, "FT: RRB authentication response: STA=" MACSTR
1221 " CurrentAP=" MACSTR
" status=%d",
1222 MAC2STR(sm
->addr
), MAC2STR(current_ap
), status
);
1223 wpa_hexdump(MSG_DEBUG
, "FT: Response IEs", resp_ies
, resp_ies_len
);
1225 /* RRB - Forward action frame response to the Current AP */
1228 * data: Category[1] Action[1] STA_Address[6] Target_AP_Address[6]
1229 * Status_Code[2] FT Request action frame body[variable]
1231 rlen
= 2 + 2 * ETH_ALEN
+ 2 + resp_ies_len
;
1233 frame
= os_malloc(sizeof(*frame
) + rlen
);
1234 frame
->frame_type
= RSN_REMOTE_FRAME_TYPE_FT_RRB
;
1235 frame
->packet_type
= FT_PACKET_RESPONSE
;
1236 frame
->action_length
= host_to_le16(rlen
);
1237 os_memcpy(frame
->ap_address
, wpa_auth
->addr
, ETH_ALEN
);
1238 pos
= (u8
*) (frame
+ 1);
1239 *pos
++ = WLAN_ACTION_FT
;
1240 *pos
++ = 2; /* Action: Response */
1241 os_memcpy(pos
, sta_addr
, ETH_ALEN
);
1243 os_memcpy(pos
, wpa_auth
->addr
, ETH_ALEN
);
1245 WPA_PUT_LE16(pos
, status
);
1248 os_memcpy(pos
, resp_ies
, resp_ies_len
);
1252 wpa_ft_rrb_send(wpa_auth
, current_ap
, (u8
*) frame
,
1253 sizeof(*frame
) + rlen
);
1260 static int wpa_ft_rrb_rx_pull(struct wpa_authenticator
*wpa_auth
,
1262 const u8
*data
, size_t data_len
)
1264 struct ft_r0kh_r1kh_pull_frame
*frame
, f
;
1265 struct ft_remote_r1kh
*r1kh
;
1266 struct ft_r0kh_r1kh_resp_frame resp
, r
;
1269 wpa_printf(MSG_DEBUG
, "FT: Received PMK-R1 pull");
1271 if (data_len
< sizeof(*frame
))
1274 r1kh
= wpa_auth
->conf
.r1kh_list
;
1276 if (os_memcmp(r1kh
->addr
, src_addr
, ETH_ALEN
) == 0)
1281 wpa_printf(MSG_DEBUG
, "FT: No matching R1KH address found for "
1282 "PMK-R1 pull source address " MACSTR
,
1287 frame
= (struct ft_r0kh_r1kh_pull_frame
*) data
;
1288 /* aes_unwrap() does not support inplace decryption, so use a temporary
1289 * buffer for the data. */
1290 if (aes_unwrap(r1kh
->key
, (FT_R0KH_R1KH_PULL_DATA_LEN
+ 7) / 8,
1291 frame
->nonce
, f
.nonce
) < 0) {
1292 wpa_printf(MSG_DEBUG
, "FT: Failed to decrypt PMK-R1 pull "
1293 "request from " MACSTR
, MAC2STR(src_addr
));
1297 wpa_hexdump(MSG_DEBUG
, "FT: PMK-R1 pull - nonce",
1298 f
.nonce
, sizeof(f
.nonce
));
1299 wpa_hexdump(MSG_DEBUG
, "FT: PMK-R1 pull - PMKR0Name",
1300 f
.pmk_r0_name
, WPA_PMK_NAME_LEN
);
1301 wpa_printf(MSG_DEBUG
, "FT: PMK-R1 pull - R1KH-ID=" MACSTR
"S1KH-ID="
1302 MACSTR
, MAC2STR(f
.r1kh_id
), MAC2STR(f
.s1kh_id
));
1304 os_memset(&resp
, 0, sizeof(resp
));
1305 resp
.frame_type
= RSN_REMOTE_FRAME_TYPE_FT_RRB
;
1306 resp
.packet_type
= FT_PACKET_R0KH_R1KH_RESP
;
1307 resp
.data_length
= host_to_le16(FT_R0KH_R1KH_RESP_DATA_LEN
);
1308 os_memcpy(resp
.ap_address
, wpa_auth
->addr
, ETH_ALEN
);
1310 /* aes_wrap() does not support inplace encryption, so use a temporary
1311 * buffer for the data. */
1312 os_memcpy(r
.nonce
, f
.nonce
, sizeof(f
.nonce
));
1313 os_memcpy(r
.r1kh_id
, f
.r1kh_id
, FT_R1KH_ID_LEN
);
1314 os_memcpy(r
.s1kh_id
, f
.s1kh_id
, ETH_ALEN
);
1315 if (wpa_ft_fetch_pmk_r0(wpa_auth
, f
.s1kh_id
, f
.pmk_r0_name
, pmk_r0
) <
1317 wpa_printf(MSG_DEBUG
, "FT: No matching PMKR0Name found for "
1322 wpa_derive_pmk_r1(pmk_r0
, f
.pmk_r0_name
, f
.r1kh_id
, f
.s1kh_id
,
1323 r
.pmk_r1
, r
.pmk_r1_name
);
1324 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1", r
.pmk_r1
, PMK_LEN
);
1325 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name", r
.pmk_r1_name
,
1328 if (aes_wrap(r1kh
->key
, (FT_R0KH_R1KH_RESP_DATA_LEN
+ 7) / 8,
1329 r
.nonce
, resp
.nonce
) < 0) {
1330 os_memset(pmk_r0
, 0, PMK_LEN
);
1334 os_memset(pmk_r0
, 0, PMK_LEN
);
1336 wpa_ft_rrb_send(wpa_auth
, src_addr
, (u8
*) &resp
, sizeof(resp
));
1342 static int wpa_ft_rrb_rx_resp(struct wpa_authenticator
*wpa_auth
,
1344 const u8
*data
, size_t data_len
)
1346 struct ft_r0kh_r1kh_resp_frame
*frame
, f
;
1347 struct ft_remote_r0kh
*r0kh
;
1349 wpa_printf(MSG_DEBUG
, "FT: Received PMK-R1 pull response");
1351 if (data_len
< sizeof(*frame
))
1354 r0kh
= wpa_auth
->conf
.r0kh_list
;
1356 if (os_memcmp(r0kh
->addr
, src_addr
, ETH_ALEN
) == 0)
1361 wpa_printf(MSG_DEBUG
, "FT: No matching R0KH address found for "
1362 "PMK-R0 pull response source address " MACSTR
,
1367 frame
= (struct ft_r0kh_r1kh_resp_frame
*) data
;
1368 /* aes_unwrap() does not support inplace decryption, so use a temporary
1369 * buffer for the data. */
1370 if (aes_unwrap(r0kh
->key
, (FT_R0KH_R1KH_RESP_DATA_LEN
+ 7) / 8,
1371 frame
->nonce
, f
.nonce
) < 0) {
1372 wpa_printf(MSG_DEBUG
, "FT: Failed to decrypt PMK-R1 pull "
1373 "response from " MACSTR
, MAC2STR(src_addr
));
1377 if (os_memcmp(f
.r1kh_id
, wpa_auth
->conf
.r1_key_holder
, FT_R1KH_ID_LEN
)
1379 wpa_printf(MSG_DEBUG
, "FT: PMK-R1 pull response did not use a "
1380 "matching R1KH-ID");
1384 /* TODO: verify that <nonce,s1kh_id> matches with a pending request
1385 * and call this requests callback function to finish request
1388 wpa_hexdump(MSG_DEBUG
, "FT: PMK-R1 pull - nonce",
1389 f
.nonce
, sizeof(f
.nonce
));
1390 wpa_printf(MSG_DEBUG
, "FT: PMK-R1 pull - R1KH-ID=" MACSTR
"S1KH-ID="
1391 MACSTR
, MAC2STR(f
.r1kh_id
), MAC2STR(f
.s1kh_id
));
1392 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1 pull - PMK-R1",
1394 wpa_hexdump(MSG_DEBUG
, "FT: PMK-R1 pull - PMKR1Name",
1395 f
.pmk_r1_name
, WPA_PMK_NAME_LEN
);
1397 wpa_ft_store_pmk_r1(wpa_auth
, f
.s1kh_id
, f
.pmk_r1
, f
.pmk_r1_name
);
1398 os_memset(f
.pmk_r1
, 0, PMK_LEN
);
1404 static int wpa_ft_rrb_rx_push(struct wpa_authenticator
*wpa_auth
,
1406 const u8
*data
, size_t data_len
)
1408 struct ft_r0kh_r1kh_push_frame
*frame
, f
;
1409 struct ft_remote_r0kh
*r0kh
;
1413 wpa_printf(MSG_DEBUG
, "FT: Received PMK-R1 push");
1415 if (data_len
< sizeof(*frame
))
1418 r0kh
= wpa_auth
->conf
.r0kh_list
;
1420 if (os_memcmp(r0kh
->addr
, src_addr
, ETH_ALEN
) == 0)
1425 wpa_printf(MSG_DEBUG
, "FT: No matching R0KH address found for "
1426 "PMK-R0 push source address " MACSTR
,
1431 frame
= (struct ft_r0kh_r1kh_push_frame
*) data
;
1432 /* aes_unwrap() does not support inplace decryption, so use a temporary
1433 * buffer for the data. */
1434 if (aes_unwrap(r0kh
->key
, (FT_R0KH_R1KH_PUSH_DATA_LEN
+ 7) / 8,
1435 frame
->timestamp
, f
.timestamp
) < 0) {
1436 wpa_printf(MSG_DEBUG
, "FT: Failed to decrypt PMK-R1 push from "
1437 MACSTR
, MAC2STR(src_addr
));
1442 tsend
= WPA_GET_LE32(f
.timestamp
);
1443 if ((now
.sec
> tsend
&& now
.sec
- tsend
> 60) ||
1444 (now
.sec
< tsend
&& tsend
- now
.sec
> 60)) {
1445 wpa_printf(MSG_DEBUG
, "FT: PMK-R1 push did not have a valid "
1446 "timestamp: sender time %d own time %d\n",
1447 (int) tsend
, (int) now
.sec
);
1451 if (os_memcmp(f
.r1kh_id
, wpa_auth
->conf
.r1_key_holder
, FT_R1KH_ID_LEN
)
1453 wpa_printf(MSG_DEBUG
, "FT: PMK-R1 push did not use a matching "
1454 "R1KH-ID (received " MACSTR
" own " MACSTR
")",
1456 MAC2STR(wpa_auth
->conf
.r1_key_holder
));
1460 wpa_printf(MSG_DEBUG
, "FT: PMK-R1 push - R1KH-ID=" MACSTR
" S1KH-ID="
1461 MACSTR
, MAC2STR(f
.r1kh_id
), MAC2STR(f
.s1kh_id
));
1462 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1 push - PMK-R1",
1464 wpa_hexdump(MSG_DEBUG
, "FT: PMK-R1 push - PMKR1Name",
1465 f
.pmk_r1_name
, WPA_PMK_NAME_LEN
);
1467 wpa_ft_store_pmk_r1(wpa_auth
, f
.s1kh_id
, f
.pmk_r1
, f
.pmk_r1_name
);
1468 os_memset(f
.pmk_r1
, 0, PMK_LEN
);
1474 int wpa_ft_rrb_rx(struct wpa_authenticator
*wpa_auth
, const u8
*src_addr
,
1475 const u8
*data
, size_t data_len
)
1477 struct ft_rrb_frame
*frame
;
1479 const u8
*pos
, *end
, *start
;
1481 const u8
*sta_addr
, *target_ap_addr
;
1483 wpa_printf(MSG_DEBUG
, "FT: RRB received frame from remote AP " MACSTR
,
1486 if (data_len
< sizeof(*frame
)) {
1487 wpa_printf(MSG_DEBUG
, "FT: Too short RRB frame (data_len=%lu)",
1488 (unsigned long) data_len
);
1493 frame
= (struct ft_rrb_frame
*) pos
;
1494 pos
+= sizeof(*frame
);
1496 alen
= le_to_host16(frame
->action_length
);
1497 wpa_printf(MSG_DEBUG
, "FT: RRB frame - frame_type=%d packet_type=%d "
1498 "action_length=%d ap_address=" MACSTR
,
1499 frame
->frame_type
, frame
->packet_type
, alen
,
1500 MAC2STR(frame
->ap_address
));
1502 if (frame
->frame_type
!= RSN_REMOTE_FRAME_TYPE_FT_RRB
) {
1503 /* Discard frame per IEEE Std 802.11r-2008, 11A.10.3 */
1504 wpa_printf(MSG_DEBUG
, "FT: RRB discarded frame with "
1505 "unrecognized type %d", frame
->frame_type
);
1509 if (alen
> data_len
- sizeof(*frame
)) {
1510 wpa_printf(MSG_DEBUG
, "FT: RRB frame too short for action "
1515 if (frame
->packet_type
== FT_PACKET_R0KH_R1KH_PULL
)
1516 return wpa_ft_rrb_rx_pull(wpa_auth
, src_addr
, data
, data_len
);
1517 if (frame
->packet_type
== FT_PACKET_R0KH_R1KH_RESP
)
1518 return wpa_ft_rrb_rx_resp(wpa_auth
, src_addr
, data
, data_len
);
1519 if (frame
->packet_type
== FT_PACKET_R0KH_R1KH_PUSH
)
1520 return wpa_ft_rrb_rx_push(wpa_auth
, src_addr
, data
, data_len
);
1522 wpa_hexdump(MSG_MSGDUMP
, "FT: RRB - FT Action frame", pos
, alen
);
1524 if (alen
< 1 + 1 + 2 * ETH_ALEN
) {
1525 wpa_printf(MSG_DEBUG
, "FT: Too short RRB frame (not enough "
1526 "room for Action Frame body); alen=%lu",
1527 (unsigned long) alen
);
1533 if (*pos
!= WLAN_ACTION_FT
) {
1534 wpa_printf(MSG_DEBUG
, "FT: Unexpected Action frame category "
1543 target_ap_addr
= pos
;
1545 wpa_printf(MSG_DEBUG
, "FT: RRB Action Frame: action=%d sta_addr="
1546 MACSTR
" target_ap_addr=" MACSTR
,
1547 action
, MAC2STR(sta_addr
), MAC2STR(target_ap_addr
));
1549 if (frame
->packet_type
== FT_PACKET_REQUEST
) {
1550 wpa_printf(MSG_DEBUG
, "FT: FT Packet Type - Request");
1553 wpa_printf(MSG_DEBUG
, "FT: Unexpected Action %d in "
1554 "RRB Request", action
);
1558 if (os_memcmp(target_ap_addr
, wpa_auth
->addr
, ETH_ALEN
) != 0) {
1559 wpa_printf(MSG_DEBUG
, "FT: Target AP address in the "
1560 "RRB Request does not match with own "
1565 if (wpa_ft_rrb_rx_request(wpa_auth
, frame
->ap_address
,
1566 sta_addr
, pos
, end
- pos
) < 0)
1568 } else if (frame
->packet_type
== FT_PACKET_RESPONSE
) {
1571 if (end
- pos
< 2) {
1572 wpa_printf(MSG_DEBUG
, "FT: Not enough room for status "
1573 "code in RRB Response");
1576 status_code
= WPA_GET_LE16(pos
);
1579 wpa_printf(MSG_DEBUG
, "FT: FT Packet Type - Response "
1580 "(status_code=%d)", status_code
);
1582 if (wpa_ft_action_send(wpa_auth
, sta_addr
, start
, alen
) < 0)
1585 wpa_printf(MSG_DEBUG
, "FT: RRB discarded frame with unknown "
1586 "packet_type %d", frame
->packet_type
);
1594 static void wpa_ft_generate_pmk_r1(struct wpa_authenticator
*wpa_auth
,
1595 struct wpa_ft_pmk_r0_sa
*pmk_r0
,
1596 struct ft_remote_r1kh
*r1kh
,
1599 struct ft_r0kh_r1kh_push_frame frame
, f
;
1602 os_memset(&frame
, 0, sizeof(frame
));
1603 frame
.frame_type
= RSN_REMOTE_FRAME_TYPE_FT_RRB
;
1604 frame
.packet_type
= FT_PACKET_R0KH_R1KH_PUSH
;
1605 frame
.data_length
= host_to_le16(FT_R0KH_R1KH_PUSH_DATA_LEN
);
1606 os_memcpy(frame
.ap_address
, wpa_auth
->addr
, ETH_ALEN
);
1608 /* aes_wrap() does not support inplace encryption, so use a temporary
1609 * buffer for the data. */
1610 os_memcpy(f
.r1kh_id
, r1kh
->id
, FT_R1KH_ID_LEN
);
1611 os_memcpy(f
.s1kh_id
, s1kh_id
, ETH_ALEN
);
1612 os_memcpy(f
.pmk_r0_name
, pmk_r0
->pmk_r0_name
, WPA_PMK_NAME_LEN
);
1613 wpa_derive_pmk_r1(pmk_r0
->pmk_r0
, pmk_r0
->pmk_r0_name
, r1kh
->id
,
1614 s1kh_id
, f
.pmk_r1
, f
.pmk_r1_name
);
1615 wpa_printf(MSG_DEBUG
, "FT: R1KH-ID " MACSTR
, MAC2STR(r1kh
->id
));
1616 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1", f
.pmk_r1
, PMK_LEN
);
1617 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name", f
.pmk_r1_name
,
1620 WPA_PUT_LE32(f
.timestamp
, now
.sec
);
1621 if (aes_wrap(r1kh
->key
, (FT_R0KH_R1KH_PUSH_DATA_LEN
+ 7) / 8,
1622 f
.timestamp
, frame
.timestamp
) < 0)
1625 wpa_ft_rrb_send(wpa_auth
, r1kh
->addr
, (u8
*) &frame
, sizeof(frame
));
1629 void wpa_ft_push_pmk_r1(struct wpa_authenticator
*wpa_auth
, const u8
*addr
)
1631 struct wpa_ft_pmk_r0_sa
*r0
;
1632 struct ft_remote_r1kh
*r1kh
;
1634 if (!wpa_auth
->conf
.pmk_r1_push
)
1637 r0
= wpa_auth
->ft_pmk_cache
->pmk_r0
;
1639 if (os_memcmp(r0
->spa
, addr
, ETH_ALEN
) == 0)
1644 if (r0
== NULL
|| r0
->pmk_r1_pushed
)
1646 r0
->pmk_r1_pushed
= 1;
1648 wpa_printf(MSG_DEBUG
, "FT: Deriving and pushing PMK-R1 keys to R1KHs "
1649 "for STA " MACSTR
, MAC2STR(addr
));
1651 r1kh
= wpa_auth
->conf
.r1kh_list
;
1653 wpa_ft_generate_pmk_r1(wpa_auth
, r0
, r1kh
, addr
);
1658 #endif /* CONFIG_IEEE80211R */