2 * hostapd - IEEE 802.11r - Fast BSS Transition
3 * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "common/ieee802_11_defs.h"
13 #include "common/ieee802_11_common.h"
14 #include "crypto/aes_wrap.h"
15 #include "crypto/random.h"
16 #include "ap_config.h"
17 #include "ieee802_11.h"
20 #include "wpa_auth_i.h"
23 #ifdef CONFIG_IEEE80211R
25 static int wpa_ft_rrb_send(struct wpa_authenticator
*wpa_auth
, const u8
*dst
,
26 const u8
*data
, size_t data_len
)
28 if (wpa_auth
->cb
.send_ether
== NULL
)
30 wpa_printf(MSG_DEBUG
, "FT: RRB send to " MACSTR
, MAC2STR(dst
));
31 return wpa_auth
->cb
.send_ether(wpa_auth
->cb
.ctx
, dst
, ETH_P_RRB
,
36 static int wpa_ft_action_send(struct wpa_authenticator
*wpa_auth
,
37 const u8
*dst
, const u8
*data
, size_t data_len
)
39 if (wpa_auth
->cb
.send_ft_action
== NULL
)
41 return wpa_auth
->cb
.send_ft_action(wpa_auth
->cb
.ctx
, dst
,
46 static struct wpa_state_machine
*
47 wpa_ft_add_sta(struct wpa_authenticator
*wpa_auth
, const u8
*sta_addr
)
49 if (wpa_auth
->cb
.add_sta
== NULL
)
51 return wpa_auth
->cb
.add_sta(wpa_auth
->cb
.ctx
, sta_addr
);
55 static int wpa_ft_add_tspec(struct wpa_authenticator
*wpa_auth
,
57 u8
*tspec_ie
, size_t tspec_ielen
)
59 if (wpa_auth
->cb
.add_tspec
== NULL
) {
60 wpa_printf(MSG_DEBUG
, "FT: add_tspec is not initialized");
63 return wpa_auth
->cb
.add_tspec(wpa_auth
->cb
.ctx
, sta_addr
, tspec_ie
,
68 int wpa_write_mdie(struct wpa_auth_config
*conf
, u8
*buf
, size_t len
)
72 if (len
< 2 + sizeof(struct rsn_mdie
))
75 *pos
++ = WLAN_EID_MOBILITY_DOMAIN
;
76 *pos
++ = MOBILITY_DOMAIN_ID_LEN
+ 1;
77 os_memcpy(pos
, conf
->mobility_domain
, MOBILITY_DOMAIN_ID_LEN
);
78 pos
+= MOBILITY_DOMAIN_ID_LEN
;
81 capab
|= RSN_FT_CAPAB_FT_OVER_DS
;
88 int wpa_write_ftie(struct wpa_auth_config
*conf
, const u8
*r0kh_id
,
90 const u8
*anonce
, const u8
*snonce
,
91 u8
*buf
, size_t len
, const u8
*subelem
,
94 u8
*pos
= buf
, *ielen
;
97 if (len
< 2 + sizeof(*hdr
) + 2 + FT_R1KH_ID_LEN
+ 2 + r0kh_id_len
+
101 *pos
++ = WLAN_EID_FAST_BSS_TRANSITION
;
104 hdr
= (struct rsn_ftie
*) pos
;
105 os_memset(hdr
, 0, sizeof(*hdr
));
107 WPA_PUT_LE16(hdr
->mic_control
, 0);
109 os_memcpy(hdr
->anonce
, anonce
, WPA_NONCE_LEN
);
111 os_memcpy(hdr
->snonce
, snonce
, WPA_NONCE_LEN
);
113 /* Optional Parameters */
114 *pos
++ = FTIE_SUBELEM_R1KH_ID
;
115 *pos
++ = FT_R1KH_ID_LEN
;
116 os_memcpy(pos
, conf
->r1_key_holder
, FT_R1KH_ID_LEN
);
117 pos
+= FT_R1KH_ID_LEN
;
120 *pos
++ = FTIE_SUBELEM_R0KH_ID
;
121 *pos
++ = r0kh_id_len
;
122 os_memcpy(pos
, r0kh_id
, r0kh_id_len
);
127 os_memcpy(pos
, subelem
, subelem_len
);
131 *ielen
= pos
- buf
- 2;
137 struct wpa_ft_pmk_r0_sa
{
138 struct wpa_ft_pmk_r0_sa
*next
;
140 u8 pmk_r0_name
[WPA_PMK_NAME_LEN
];
142 int pairwise
; /* Pairwise cipher suite, WPA_CIPHER_* */
143 /* TODO: expiration, identity, radius_class, EAP type, VLAN ID */
147 struct wpa_ft_pmk_r1_sa
{
148 struct wpa_ft_pmk_r1_sa
*next
;
150 u8 pmk_r1_name
[WPA_PMK_NAME_LEN
];
152 int pairwise
; /* Pairwise cipher suite, WPA_CIPHER_* */
153 /* TODO: expiration, identity, radius_class, EAP type, VLAN ID */
156 struct wpa_ft_pmk_cache
{
157 struct wpa_ft_pmk_r0_sa
*pmk_r0
;
158 struct wpa_ft_pmk_r1_sa
*pmk_r1
;
161 struct wpa_ft_pmk_cache
* wpa_ft_pmk_cache_init(void)
163 struct wpa_ft_pmk_cache
*cache
;
165 cache
= os_zalloc(sizeof(*cache
));
171 void wpa_ft_pmk_cache_deinit(struct wpa_ft_pmk_cache
*cache
)
173 struct wpa_ft_pmk_r0_sa
*r0
, *r0prev
;
174 struct wpa_ft_pmk_r1_sa
*r1
, *r1prev
;
180 os_memset(r0prev
->pmk_r0
, 0, PMK_LEN
);
188 os_memset(r1prev
->pmk_r1
, 0, PMK_LEN
);
196 static int wpa_ft_store_pmk_r0(struct wpa_authenticator
*wpa_auth
,
197 const u8
*spa
, const u8
*pmk_r0
,
198 const u8
*pmk_r0_name
, int pairwise
)
200 struct wpa_ft_pmk_cache
*cache
= wpa_auth
->ft_pmk_cache
;
201 struct wpa_ft_pmk_r0_sa
*r0
;
203 /* TODO: add expiration and limit on number of entries in cache */
205 r0
= os_zalloc(sizeof(*r0
));
209 os_memcpy(r0
->pmk_r0
, pmk_r0
, PMK_LEN
);
210 os_memcpy(r0
->pmk_r0_name
, pmk_r0_name
, WPA_PMK_NAME_LEN
);
211 os_memcpy(r0
->spa
, spa
, ETH_ALEN
);
212 r0
->pairwise
= pairwise
;
214 r0
->next
= cache
->pmk_r0
;
221 static int wpa_ft_fetch_pmk_r0(struct wpa_authenticator
*wpa_auth
,
222 const u8
*spa
, const u8
*pmk_r0_name
,
223 u8
*pmk_r0
, int *pairwise
)
225 struct wpa_ft_pmk_cache
*cache
= wpa_auth
->ft_pmk_cache
;
226 struct wpa_ft_pmk_r0_sa
*r0
;
230 if (os_memcmp(r0
->spa
, spa
, ETH_ALEN
) == 0 &&
231 os_memcmp(r0
->pmk_r0_name
, pmk_r0_name
, WPA_PMK_NAME_LEN
)
233 os_memcpy(pmk_r0
, r0
->pmk_r0
, PMK_LEN
);
235 *pairwise
= r0
->pairwise
;
246 static int wpa_ft_store_pmk_r1(struct wpa_authenticator
*wpa_auth
,
247 const u8
*spa
, const u8
*pmk_r1
,
248 const u8
*pmk_r1_name
, int pairwise
)
250 struct wpa_ft_pmk_cache
*cache
= wpa_auth
->ft_pmk_cache
;
251 struct wpa_ft_pmk_r1_sa
*r1
;
253 /* TODO: add expiration and limit on number of entries in cache */
255 r1
= os_zalloc(sizeof(*r1
));
259 os_memcpy(r1
->pmk_r1
, pmk_r1
, PMK_LEN
);
260 os_memcpy(r1
->pmk_r1_name
, pmk_r1_name
, WPA_PMK_NAME_LEN
);
261 os_memcpy(r1
->spa
, spa
, ETH_ALEN
);
262 r1
->pairwise
= pairwise
;
264 r1
->next
= cache
->pmk_r1
;
271 static int wpa_ft_fetch_pmk_r1(struct wpa_authenticator
*wpa_auth
,
272 const u8
*spa
, const u8
*pmk_r1_name
,
273 u8
*pmk_r1
, int *pairwise
)
275 struct wpa_ft_pmk_cache
*cache
= wpa_auth
->ft_pmk_cache
;
276 struct wpa_ft_pmk_r1_sa
*r1
;
280 if (os_memcmp(r1
->spa
, spa
, ETH_ALEN
) == 0 &&
281 os_memcmp(r1
->pmk_r1_name
, pmk_r1_name
, WPA_PMK_NAME_LEN
)
283 os_memcpy(pmk_r1
, r1
->pmk_r1
, PMK_LEN
);
285 *pairwise
= r1
->pairwise
;
296 static int wpa_ft_pull_pmk_r1(struct wpa_authenticator
*wpa_auth
,
297 const u8
*s1kh_id
, const u8
*r0kh_id
,
298 size_t r0kh_id_len
, const u8
*pmk_r0_name
)
300 struct ft_remote_r0kh
*r0kh
;
301 struct ft_r0kh_r1kh_pull_frame frame
, f
;
303 r0kh
= wpa_auth
->conf
.r0kh_list
;
305 if (r0kh
->id_len
== r0kh_id_len
&&
306 os_memcmp(r0kh
->id
, r0kh_id
, r0kh_id_len
) == 0)
313 wpa_printf(MSG_DEBUG
, "FT: Send PMK-R1 pull request to remote R0KH "
314 "address " MACSTR
, MAC2STR(r0kh
->addr
));
316 os_memset(&frame
, 0, sizeof(frame
));
317 frame
.frame_type
= RSN_REMOTE_FRAME_TYPE_FT_RRB
;
318 frame
.packet_type
= FT_PACKET_R0KH_R1KH_PULL
;
319 frame
.data_length
= host_to_le16(FT_R0KH_R1KH_PULL_DATA_LEN
);
320 os_memcpy(frame
.ap_address
, wpa_auth
->addr
, ETH_ALEN
);
322 /* aes_wrap() does not support inplace encryption, so use a temporary
323 * buffer for the data. */
324 if (random_get_bytes(f
.nonce
, sizeof(f
.nonce
))) {
325 wpa_printf(MSG_DEBUG
, "FT: Failed to get random data for "
329 os_memcpy(f
.pmk_r0_name
, pmk_r0_name
, WPA_PMK_NAME_LEN
);
330 os_memcpy(f
.r1kh_id
, wpa_auth
->conf
.r1_key_holder
, FT_R1KH_ID_LEN
);
331 os_memcpy(f
.s1kh_id
, s1kh_id
, ETH_ALEN
);
332 os_memset(f
.pad
, 0, sizeof(f
.pad
));
334 if (aes_wrap(r0kh
->key
, (FT_R0KH_R1KH_PULL_DATA_LEN
+ 7) / 8,
335 f
.nonce
, frame
.nonce
) < 0)
338 wpa_ft_rrb_send(wpa_auth
, r0kh
->addr
, (u8
*) &frame
, sizeof(frame
));
344 int wpa_auth_derive_ptk_ft(struct wpa_state_machine
*sm
, const u8
*pmk
,
345 struct wpa_ptk
*ptk
, size_t ptk_len
)
347 u8 pmk_r0
[PMK_LEN
], pmk_r0_name
[WPA_PMK_NAME_LEN
];
349 u8 ptk_name
[WPA_PMK_NAME_LEN
];
350 const u8
*mdid
= sm
->wpa_auth
->conf
.mobility_domain
;
351 const u8
*r0kh
= sm
->wpa_auth
->conf
.r0_key_holder
;
352 size_t r0kh_len
= sm
->wpa_auth
->conf
.r0_key_holder_len
;
353 const u8
*r1kh
= sm
->wpa_auth
->conf
.r1_key_holder
;
354 const u8
*ssid
= sm
->wpa_auth
->conf
.ssid
;
355 size_t ssid_len
= sm
->wpa_auth
->conf
.ssid_len
;
358 if (sm
->xxkey_len
== 0) {
359 wpa_printf(MSG_DEBUG
, "FT: XXKey not available for key "
364 wpa_derive_pmk_r0(sm
->xxkey
, sm
->xxkey_len
, ssid
, ssid_len
, mdid
,
365 r0kh
, r0kh_len
, sm
->addr
, pmk_r0
, pmk_r0_name
);
366 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R0", pmk_r0
, PMK_LEN
);
367 wpa_hexdump(MSG_DEBUG
, "FT: PMKR0Name", pmk_r0_name
, WPA_PMK_NAME_LEN
);
368 wpa_ft_store_pmk_r0(sm
->wpa_auth
, sm
->addr
, pmk_r0
, pmk_r0_name
,
371 wpa_derive_pmk_r1(pmk_r0
, pmk_r0_name
, r1kh
, sm
->addr
,
372 pmk_r1
, sm
->pmk_r1_name
);
373 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1", pmk_r1
, PMK_LEN
);
374 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name", sm
->pmk_r1_name
,
376 wpa_ft_store_pmk_r1(sm
->wpa_auth
, sm
->addr
, pmk_r1
, sm
->pmk_r1_name
,
379 wpa_pmk_r1_to_ptk(pmk_r1
, sm
->SNonce
, sm
->ANonce
, sm
->addr
,
380 sm
->wpa_auth
->addr
, sm
->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)
420 if (pad_len
&& key_len
< sizeof(keybuf
)) {
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[2] | Key Length[1] | RSC[8] |
433 subelem_len
= 13 + key_len
+ 8;
434 subelem
= os_zalloc(subelem_len
);
438 subelem
[0] = FTIE_SUBELEM_GTK
;
439 subelem
[1] = 11 + key_len
+ 8;
440 /* Key ID in B0-B1 of Key Info */
441 WPA_PUT_LE16(&subelem
[2], gsm
->GN
& 0x03);
442 subelem
[4] = gsm
->GTK_len
;
443 wpa_auth_get_seqnum(sm
->wpa_auth
, NULL
, gsm
->GN
, subelem
+ 5);
444 if (aes_wrap(sm
->PTK
.kek
, key_len
/ 8, key
, subelem
+ 13)) {
454 #ifdef CONFIG_IEEE80211W
455 static u8
* wpa_ft_igtk_subelem(struct wpa_state_machine
*sm
, size_t *len
)
458 struct wpa_group
*gsm
= sm
->group
;
461 /* Sub-elem ID[1] | Length[1] | KeyID[2] | IPN[6] | Key Length[1] |
463 subelem_len
= 1 + 1 + 2 + 6 + 1 + WPA_IGTK_LEN
+ 8;
464 subelem
= os_zalloc(subelem_len
);
469 *pos
++ = FTIE_SUBELEM_IGTK
;
470 *pos
++ = subelem_len
- 2;
471 WPA_PUT_LE16(pos
, gsm
->GN_igtk
);
473 wpa_auth_get_seqnum(sm
->wpa_auth
, NULL
, gsm
->GN_igtk
, pos
);
475 *pos
++ = WPA_IGTK_LEN
;
476 if (aes_wrap(sm
->PTK
.kek
, WPA_IGTK_LEN
/ 8,
477 gsm
->IGTK
[gsm
->GN_igtk
- 4], pos
)) {
485 #endif /* CONFIG_IEEE80211W */
488 static u8
* wpa_ft_process_rdie(struct wpa_state_machine
*sm
,
489 u8
*pos
, u8
*end
, u8 id
, u8 descr_count
,
490 const u8
*ies
, size_t ies_len
)
492 struct ieee802_11_elems parse
;
493 struct rsn_rdie
*rdie
;
495 wpa_printf(MSG_DEBUG
, "FT: Resource Request: id=%d descr_count=%d",
497 wpa_hexdump(MSG_MSGDUMP
, "FT: Resource descriptor IE(s)",
500 if (end
- pos
< (int) sizeof(*rdie
)) {
501 wpa_printf(MSG_ERROR
, "FT: Not enough room for response RDIE");
505 *pos
++ = WLAN_EID_RIC_DATA
;
506 *pos
++ = sizeof(*rdie
);
507 rdie
= (struct rsn_rdie
*) pos
;
509 rdie
->descr_count
= 0;
510 rdie
->status_code
= host_to_le16(WLAN_STATUS_SUCCESS
);
511 pos
+= sizeof(*rdie
);
513 if (ieee802_11_parse_elems((u8
*) ies
, ies_len
, &parse
, 1) ==
515 wpa_printf(MSG_DEBUG
, "FT: Failed to parse request IEs");
517 host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE
);
522 if (parse
.wmm_tspec
&& sm
->wpa_auth
->conf
.ap_mlme
) {
523 struct wmm_tspec_element
*tspec
;
526 if (parse
.wmm_tspec_len
+ 2 < (int) sizeof(*tspec
)) {
527 wpa_printf(MSG_DEBUG
, "FT: Too short WMM TSPEC IE "
528 "(%d)", (int) parse
.wmm_tspec_len
);
530 host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE
);
533 if (end
- pos
< (int) sizeof(*tspec
)) {
534 wpa_printf(MSG_ERROR
, "FT: Not enough room for "
537 host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE
);
540 tspec
= (struct wmm_tspec_element
*) pos
;
541 os_memcpy(tspec
, parse
.wmm_tspec
- 2, sizeof(*tspec
));
542 res
= wmm_process_tspec(tspec
);
543 wpa_printf(MSG_DEBUG
, "FT: ADDTS processing result: %d", res
);
544 if (res
== WMM_ADDTS_STATUS_INVALID_PARAMETERS
)
546 host_to_le16(WLAN_STATUS_INVALID_PARAMETERS
);
547 else if (res
== WMM_ADDTS_STATUS_REFUSED
)
549 host_to_le16(WLAN_STATUS_REQUEST_DECLINED
);
551 /* TSPEC accepted; include updated TSPEC in response */
552 rdie
->descr_count
= 1;
553 pos
+= sizeof(*tspec
);
557 #endif /* NEED_AP_MLME */
559 if (parse
.wmm_tspec
&& !sm
->wpa_auth
->conf
.ap_mlme
) {
560 struct wmm_tspec_element
*tspec
;
563 tspec
= (struct wmm_tspec_element
*) pos
;
564 os_memcpy(tspec
, parse
.wmm_tspec
- 2, sizeof(*tspec
));
565 res
= wpa_ft_add_tspec(sm
->wpa_auth
, sm
->addr
, pos
,
569 rdie
->status_code
= host_to_le16(res
);
571 /* TSPEC accepted; include updated TSPEC in
573 rdie
->descr_count
= 1;
574 pos
+= sizeof(*tspec
);
580 wpa_printf(MSG_DEBUG
, "FT: No supported resource requested");
581 rdie
->status_code
= host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE
);
586 static u8
* wpa_ft_process_ric(struct wpa_state_machine
*sm
, u8
*pos
, u8
*end
,
587 const u8
*ric
, size_t ric_len
)
589 const u8
*rpos
, *start
;
590 const struct rsn_rdie
*rdie
;
592 wpa_hexdump(MSG_MSGDUMP
, "FT: RIC Request", ric
, ric_len
);
595 while (rpos
+ sizeof(*rdie
) < ric
+ ric_len
) {
596 if (rpos
[0] != WLAN_EID_RIC_DATA
|| rpos
[1] < sizeof(*rdie
) ||
597 rpos
+ 2 + rpos
[1] > ric
+ ric_len
)
599 rdie
= (const struct rsn_rdie
*) (rpos
+ 2);
603 while (rpos
+ 2 <= ric
+ ric_len
&&
604 rpos
+ 2 + rpos
[1] <= ric
+ ric_len
) {
605 if (rpos
[0] == WLAN_EID_RIC_DATA
)
609 pos
= wpa_ft_process_rdie(sm
, pos
, end
, rdie
->id
,
611 start
, rpos
- start
);
618 u8
* wpa_sm_write_assoc_resp_ies(struct wpa_state_machine
*sm
, u8
*pos
,
619 size_t max_len
, int auth_alg
,
620 const u8
*req_ies
, size_t req_ies_len
)
622 u8
*end
, *mdie
, *ftie
, *rsnie
= NULL
, *r0kh_id
, *subelem
= NULL
;
623 size_t mdie_len
, ftie_len
, rsnie_len
= 0, r0kh_id_len
, subelem_len
= 0;
625 struct wpa_auth_config
*conf
;
626 struct rsn_ftie
*_ftie
;
627 struct wpa_ft_ies parse
;
634 conf
= &sm
->wpa_auth
->conf
;
636 if (sm
->wpa_key_mgmt
!= WPA_KEY_MGMT_FT_IEEE8021X
&&
637 sm
->wpa_key_mgmt
!= WPA_KEY_MGMT_FT_PSK
)
642 if (auth_alg
== WLAN_AUTH_FT
) {
644 * RSN (only present if this is a Reassociation Response and
645 * part of a fast BSS transition)
647 res
= wpa_write_rsn_ie(conf
, pos
, end
- pos
, sm
->pmk_r1_name
);
655 /* Mobility Domain Information */
656 res
= wpa_write_mdie(conf
, pos
, end
- pos
);
663 /* Fast BSS Transition Information */
664 if (auth_alg
== WLAN_AUTH_FT
) {
665 subelem
= wpa_ft_gtk_subelem(sm
, &subelem_len
);
666 r0kh_id
= sm
->r0kh_id
;
667 r0kh_id_len
= sm
->r0kh_id_len
;
670 #ifdef CONFIG_IEEE80211W
671 if (sm
->mgmt_frame_prot
) {
675 igtk
= wpa_ft_igtk_subelem(sm
, &igtk_len
);
680 nbuf
= os_realloc(subelem
, subelem_len
+ igtk_len
);
687 os_memcpy(subelem
+ subelem_len
, igtk
, igtk_len
);
688 subelem_len
+= igtk_len
;
691 #endif /* CONFIG_IEEE80211W */
693 r0kh_id
= conf
->r0_key_holder
;
694 r0kh_id_len
= conf
->r0_key_holder_len
;
698 res
= wpa_write_ftie(conf
, r0kh_id
, r0kh_id_len
, anonce
, snonce
, pos
,
699 end
- pos
, subelem
, subelem_len
);
707 os_free(sm
->assoc_resp_ftie
);
708 sm
->assoc_resp_ftie
= os_malloc(ftie_len
);
709 if (sm
->assoc_resp_ftie
)
710 os_memcpy(sm
->assoc_resp_ftie
, ftie
, ftie_len
);
712 _ftie
= (struct rsn_ftie
*) (ftie
+ 2);
713 if (auth_alg
== WLAN_AUTH_FT
)
714 _ftie
->mic_control
[1] = 3; /* Information element count */
717 if (wpa_ft_parse_ies(req_ies
, req_ies_len
, &parse
) == 0 && parse
.ric
) {
718 pos
= wpa_ft_process_ric(sm
, pos
, end
, parse
.ric
,
720 if (auth_alg
== WLAN_AUTH_FT
)
721 _ftie
->mic_control
[1] +=
722 ieee802_11_ie_count(ric_start
,
725 if (ric_start
== pos
)
728 if (auth_alg
== WLAN_AUTH_FT
&&
729 wpa_ft_mic(sm
->PTK
.kck
, sm
->addr
, sm
->wpa_auth
->addr
, 6,
730 mdie
, mdie_len
, ftie
, ftie_len
,
732 ric_start
, ric_start
? pos
- ric_start
: 0,
734 wpa_printf(MSG_DEBUG
, "FT: Failed to calculate MIC");
740 static inline int wpa_auth_set_key(struct wpa_authenticator
*wpa_auth
,
742 enum wpa_alg alg
, const u8
*addr
, int idx
,
743 u8
*key
, size_t key_len
)
745 if (wpa_auth
->cb
.set_key
== NULL
)
747 return wpa_auth
->cb
.set_key(wpa_auth
->cb
.ctx
, vlan_id
, alg
, addr
, idx
,
752 void wpa_ft_install_ptk(struct wpa_state_machine
*sm
)
757 /* MLME-SETKEYS.request(PTK) */
758 alg
= wpa_cipher_to_alg(sm
->pairwise
);
759 klen
= wpa_cipher_key_len(sm
->pairwise
);
760 if (!wpa_cipher_valid_pairwise(sm
->pairwise
)) {
761 wpa_printf(MSG_DEBUG
, "FT: Unknown pairwise alg 0x%x - skip "
762 "PTK configuration", sm
->pairwise
);
766 /* FIX: add STA entry to kernel/driver here? The set_key will fail
767 * most likely without this.. At the moment, STA entry is added only
768 * after association has been completed. This function will be called
769 * again after association to get the PTK configured, but that could be
770 * optimized by adding the STA entry earlier.
772 if (wpa_auth_set_key(sm
->wpa_auth
, 0, alg
, sm
->addr
, 0,
776 /* FIX: MLME-SetProtection.Request(TA, Tx_Rx) */
777 sm
->pairwise_set
= TRUE
;
781 static u16
wpa_ft_process_auth_req(struct wpa_state_machine
*sm
,
782 const u8
*ies
, size_t ies_len
,
783 u8
**resp_ies
, size_t *resp_ies_len
)
785 struct rsn_mdie
*mdie
;
786 struct rsn_ftie
*ftie
;
787 u8 pmk_r1
[PMK_LEN
], pmk_r1_name
[WPA_PMK_NAME_LEN
];
788 u8 ptk_name
[WPA_PMK_NAME_LEN
];
789 struct wpa_auth_config
*conf
;
790 struct wpa_ft_ies parse
;
791 size_t buflen
, ptk_len
;
799 sm
->pmk_r1_name_valid
= 0;
800 conf
= &sm
->wpa_auth
->conf
;
802 wpa_hexdump(MSG_DEBUG
, "FT: Received authentication frame IEs",
805 if (wpa_ft_parse_ies(ies
, ies_len
, &parse
) < 0) {
806 wpa_printf(MSG_DEBUG
, "FT: Failed to parse FT IEs");
807 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
810 mdie
= (struct rsn_mdie
*) parse
.mdie
;
811 if (mdie
== NULL
|| parse
.mdie_len
< sizeof(*mdie
) ||
812 os_memcmp(mdie
->mobility_domain
,
813 sm
->wpa_auth
->conf
.mobility_domain
,
814 MOBILITY_DOMAIN_ID_LEN
) != 0) {
815 wpa_printf(MSG_DEBUG
, "FT: Invalid MDIE");
816 return WLAN_STATUS_INVALID_MDIE
;
819 ftie
= (struct rsn_ftie
*) parse
.ftie
;
820 if (ftie
== NULL
|| parse
.ftie_len
< sizeof(*ftie
)) {
821 wpa_printf(MSG_DEBUG
, "FT: Invalid FTIE");
822 return WLAN_STATUS_INVALID_FTIE
;
825 os_memcpy(sm
->SNonce
, ftie
->snonce
, WPA_NONCE_LEN
);
827 if (parse
.r0kh_id
== NULL
) {
828 wpa_printf(MSG_DEBUG
, "FT: Invalid FTIE - no R0KH-ID");
829 return WLAN_STATUS_INVALID_FTIE
;
832 wpa_hexdump(MSG_DEBUG
, "FT: STA R0KH-ID",
833 parse
.r0kh_id
, parse
.r0kh_id_len
);
834 os_memcpy(sm
->r0kh_id
, parse
.r0kh_id
, parse
.r0kh_id_len
);
835 sm
->r0kh_id_len
= parse
.r0kh_id_len
;
837 if (parse
.rsn_pmkid
== NULL
) {
838 wpa_printf(MSG_DEBUG
, "FT: No PMKID in RSNIE");
839 return WLAN_STATUS_INVALID_PMKID
;
842 wpa_hexdump(MSG_DEBUG
, "FT: Requested PMKR0Name",
843 parse
.rsn_pmkid
, WPA_PMK_NAME_LEN
);
844 wpa_derive_pmk_r1_name(parse
.rsn_pmkid
,
845 sm
->wpa_auth
->conf
.r1_key_holder
, sm
->addr
,
847 wpa_hexdump(MSG_DEBUG
, "FT: Derived requested PMKR1Name",
848 pmk_r1_name
, WPA_PMK_NAME_LEN
);
850 if (wpa_ft_fetch_pmk_r1(sm
->wpa_auth
, sm
->addr
, pmk_r1_name
, pmk_r1
,
852 if (wpa_ft_pull_pmk_r1(sm
->wpa_auth
, sm
->addr
, sm
->r0kh_id
,
853 sm
->r0kh_id_len
, parse
.rsn_pmkid
) < 0) {
854 wpa_printf(MSG_DEBUG
, "FT: Did not have matching "
855 "PMK-R1 and unknown R0KH-ID");
856 return WLAN_STATUS_INVALID_PMKID
;
860 * TODO: Should return "status pending" (and the caller should
861 * not send out response now). The real response will be sent
862 * once the response from R0KH is received.
864 return WLAN_STATUS_INVALID_PMKID
;
867 wpa_hexdump_key(MSG_DEBUG
, "FT: Selected PMK-R1", pmk_r1
, PMK_LEN
);
868 sm
->pmk_r1_name_valid
= 1;
869 os_memcpy(sm
->pmk_r1_name
, pmk_r1_name
, WPA_PMK_NAME_LEN
);
871 if (random_get_bytes(sm
->ANonce
, WPA_NONCE_LEN
)) {
872 wpa_printf(MSG_DEBUG
, "FT: Failed to get random data for "
874 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
877 wpa_hexdump(MSG_DEBUG
, "FT: Received SNonce",
878 sm
->SNonce
, WPA_NONCE_LEN
);
879 wpa_hexdump(MSG_DEBUG
, "FT: Generated ANonce",
880 sm
->ANonce
, WPA_NONCE_LEN
);
882 ptk_len
= pairwise
== WPA_CIPHER_TKIP
? 64 : 48;
883 wpa_pmk_r1_to_ptk(pmk_r1
, sm
->SNonce
, sm
->ANonce
, sm
->addr
,
884 sm
->wpa_auth
->addr
, pmk_r1_name
,
885 (u8
*) &sm
->PTK
, ptk_len
, ptk_name
);
886 wpa_hexdump_key(MSG_DEBUG
, "FT: PTK",
887 (u8
*) &sm
->PTK
, ptk_len
);
888 wpa_hexdump(MSG_DEBUG
, "FT: PTKName", ptk_name
, WPA_PMK_NAME_LEN
);
890 sm
->pairwise
= pairwise
;
891 wpa_ft_install_ptk(sm
);
893 buflen
= 2 + sizeof(struct rsn_mdie
) + 2 + sizeof(struct rsn_ftie
) +
894 2 + FT_R1KH_ID_LEN
+ 200;
895 *resp_ies
= os_zalloc(buflen
);
896 if (*resp_ies
== NULL
) {
897 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
901 end
= *resp_ies
+ buflen
;
903 ret
= wpa_write_rsn_ie(conf
, pos
, end
- pos
, parse
.rsn_pmkid
);
907 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
911 ret
= wpa_write_mdie(conf
, pos
, end
- pos
);
915 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
919 ret
= wpa_write_ftie(conf
, parse
.r0kh_id
, parse
.r0kh_id_len
,
920 sm
->ANonce
, sm
->SNonce
, pos
, end
- pos
, NULL
, 0);
924 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
928 *resp_ies_len
= pos
- *resp_ies
;
930 return WLAN_STATUS_SUCCESS
;
934 void wpa_ft_process_auth(struct wpa_state_machine
*sm
, const u8
*bssid
,
935 u16 auth_transaction
, const u8
*ies
, size_t ies_len
,
936 void (*cb
)(void *ctx
, const u8
*dst
, const u8
*bssid
,
937 u16 auth_transaction
, u16 status
,
938 const u8
*ies
, size_t ies_len
),
946 wpa_printf(MSG_DEBUG
, "FT: Received authentication frame, but "
947 "WPA SM not available");
951 wpa_printf(MSG_DEBUG
, "FT: Received authentication frame: STA=" MACSTR
952 " BSSID=" MACSTR
" transaction=%d",
953 MAC2STR(sm
->addr
), MAC2STR(bssid
), auth_transaction
);
954 status
= wpa_ft_process_auth_req(sm
, ies
, ies_len
, &resp_ies
,
957 wpa_printf(MSG_DEBUG
, "FT: FT authentication response: dst=" MACSTR
958 " auth_transaction=%d status=%d",
959 MAC2STR(sm
->addr
), auth_transaction
+ 1, status
);
960 wpa_hexdump(MSG_DEBUG
, "FT: Response IEs", resp_ies
, resp_ies_len
);
961 cb(ctx
, sm
->addr
, bssid
, auth_transaction
+ 1, status
,
962 resp_ies
, resp_ies_len
);
967 u16
wpa_ft_validate_reassoc(struct wpa_state_machine
*sm
, const u8
*ies
,
970 struct wpa_ft_ies parse
;
971 struct rsn_mdie
*mdie
;
972 struct rsn_ftie
*ftie
;
977 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
979 wpa_hexdump(MSG_DEBUG
, "FT: Reassoc Req IEs", ies
, ies_len
);
981 if (wpa_ft_parse_ies(ies
, ies_len
, &parse
) < 0) {
982 wpa_printf(MSG_DEBUG
, "FT: Failed to parse FT IEs");
983 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
986 if (parse
.rsn
== NULL
) {
987 wpa_printf(MSG_DEBUG
, "FT: No RSNIE in Reassoc Req");
988 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
991 if (parse
.rsn_pmkid
== NULL
) {
992 wpa_printf(MSG_DEBUG
, "FT: No PMKID in RSNIE");
993 return WLAN_STATUS_INVALID_PMKID
;
996 if (os_memcmp(parse
.rsn_pmkid
, sm
->pmk_r1_name
, WPA_PMK_NAME_LEN
) != 0)
998 wpa_printf(MSG_DEBUG
, "FT: PMKID in Reassoc Req did not match "
999 "with the PMKR1Name derived from auth request");
1000 return WLAN_STATUS_INVALID_PMKID
;
1003 mdie
= (struct rsn_mdie
*) parse
.mdie
;
1004 if (mdie
== NULL
|| parse
.mdie_len
< sizeof(*mdie
) ||
1005 os_memcmp(mdie
->mobility_domain
,
1006 sm
->wpa_auth
->conf
.mobility_domain
,
1007 MOBILITY_DOMAIN_ID_LEN
) != 0) {
1008 wpa_printf(MSG_DEBUG
, "FT: Invalid MDIE");
1009 return WLAN_STATUS_INVALID_MDIE
;
1012 ftie
= (struct rsn_ftie
*) parse
.ftie
;
1013 if (ftie
== NULL
|| parse
.ftie_len
< sizeof(*ftie
)) {
1014 wpa_printf(MSG_DEBUG
, "FT: Invalid FTIE");
1015 return WLAN_STATUS_INVALID_FTIE
;
1018 if (os_memcmp(ftie
->snonce
, sm
->SNonce
, WPA_NONCE_LEN
) != 0) {
1019 wpa_printf(MSG_DEBUG
, "FT: SNonce mismatch in FTIE");
1020 wpa_hexdump(MSG_DEBUG
, "FT: Received SNonce",
1021 ftie
->snonce
, WPA_NONCE_LEN
);
1022 wpa_hexdump(MSG_DEBUG
, "FT: Expected SNonce",
1023 sm
->SNonce
, WPA_NONCE_LEN
);
1027 if (os_memcmp(ftie
->anonce
, sm
->ANonce
, WPA_NONCE_LEN
) != 0) {
1028 wpa_printf(MSG_DEBUG
, "FT: ANonce mismatch in FTIE");
1029 wpa_hexdump(MSG_DEBUG
, "FT: Received ANonce",
1030 ftie
->anonce
, WPA_NONCE_LEN
);
1031 wpa_hexdump(MSG_DEBUG
, "FT: Expected ANonce",
1032 sm
->ANonce
, WPA_NONCE_LEN
);
1037 if (parse
.r0kh_id
== NULL
) {
1038 wpa_printf(MSG_DEBUG
, "FT: No R0KH-ID subelem in FTIE");
1042 if (parse
.r0kh_id_len
!= sm
->r0kh_id_len
||
1043 os_memcmp(parse
.r0kh_id
, sm
->r0kh_id
, parse
.r0kh_id_len
) != 0) {
1044 wpa_printf(MSG_DEBUG
, "FT: R0KH-ID in FTIE did not match with "
1045 "the current R0KH-ID");
1046 wpa_hexdump(MSG_DEBUG
, "FT: R0KH-ID in FTIE",
1047 parse
.r0kh_id
, parse
.r0kh_id_len
);
1048 wpa_hexdump(MSG_DEBUG
, "FT: The current R0KH-ID",
1049 sm
->r0kh_id
, sm
->r0kh_id_len
);
1053 if (parse
.r1kh_id
== NULL
) {
1054 wpa_printf(MSG_DEBUG
, "FT: No R1KH-ID subelem in FTIE");
1058 if (os_memcmp(parse
.r1kh_id
, sm
->wpa_auth
->conf
.r1_key_holder
,
1059 FT_R1KH_ID_LEN
) != 0) {
1060 wpa_printf(MSG_DEBUG
, "FT: Unknown R1KH-ID used in "
1062 wpa_hexdump(MSG_DEBUG
, "FT: R1KH-ID in FTIE",
1063 parse
.r1kh_id
, FT_R1KH_ID_LEN
);
1064 wpa_hexdump(MSG_DEBUG
, "FT: Expected R1KH-ID",
1065 sm
->wpa_auth
->conf
.r1_key_holder
, FT_R1KH_ID_LEN
);
1069 if (parse
.rsn_pmkid
== NULL
||
1070 os_memcmp(parse
.rsn_pmkid
, sm
->pmk_r1_name
, WPA_PMK_NAME_LEN
)) {
1071 wpa_printf(MSG_DEBUG
, "FT: No matching PMKR1Name (PMKID) in "
1072 "RSNIE (pmkid=%d)", !!parse
.rsn_pmkid
);
1078 count
+= ieee802_11_ie_count(parse
.ric
, parse
.ric_len
);
1079 if (ftie
->mic_control
[1] != count
) {
1080 wpa_printf(MSG_DEBUG
, "FT: Unexpected IE count in MIC "
1081 "Control: received %u expected %u",
1082 ftie
->mic_control
[1], count
);
1086 if (wpa_ft_mic(sm
->PTK
.kck
, sm
->addr
, sm
->wpa_auth
->addr
, 5,
1087 parse
.mdie
- 2, parse
.mdie_len
+ 2,
1088 parse
.ftie
- 2, parse
.ftie_len
+ 2,
1089 parse
.rsn
- 2, parse
.rsn_len
+ 2,
1090 parse
.ric
, parse
.ric_len
,
1092 wpa_printf(MSG_DEBUG
, "FT: Failed to calculate MIC");
1093 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
1096 if (os_memcmp(mic
, ftie
->mic
, 16) != 0) {
1097 wpa_printf(MSG_DEBUG
, "FT: Invalid MIC in FTIE");
1098 wpa_printf(MSG_DEBUG
, "FT: addr=" MACSTR
" auth_addr=" MACSTR
,
1099 MAC2STR(sm
->addr
), MAC2STR(sm
->wpa_auth
->addr
));
1100 wpa_hexdump(MSG_MSGDUMP
, "FT: Received MIC", ftie
->mic
, 16);
1101 wpa_hexdump(MSG_MSGDUMP
, "FT: Calculated MIC", mic
, 16);
1102 wpa_hexdump(MSG_MSGDUMP
, "FT: MDIE",
1103 parse
.mdie
- 2, parse
.mdie_len
+ 2);
1104 wpa_hexdump(MSG_MSGDUMP
, "FT: FTIE",
1105 parse
.ftie
- 2, parse
.ftie_len
+ 2);
1106 wpa_hexdump(MSG_MSGDUMP
, "FT: RSN",
1107 parse
.rsn
- 2, parse
.rsn_len
+ 2);
1108 return WLAN_STATUS_INVALID_FTIE
;
1111 return WLAN_STATUS_SUCCESS
;
1115 int wpa_ft_action_rx(struct wpa_state_machine
*sm
, const u8
*data
, size_t len
)
1117 const u8
*sta_addr
, *target_ap
;
1121 struct ft_rrb_frame
*frame
;
1127 * data: Category[1] Action[1] STA_Address[6] Target_AP_Address[6]
1128 * FT Request action frame body[variable]
1132 wpa_printf(MSG_DEBUG
, "FT: Too short FT Action frame "
1133 "(len=%lu)", (unsigned long) len
);
1138 sta_addr
= data
+ 2;
1139 target_ap
= data
+ 8;
1143 wpa_printf(MSG_DEBUG
, "FT: Received FT Action frame (STA=" MACSTR
1144 " Target AP=" MACSTR
" Action=%d)",
1145 MAC2STR(sta_addr
), MAC2STR(target_ap
), action
);
1147 if (os_memcmp(sta_addr
, sm
->addr
, ETH_ALEN
) != 0) {
1148 wpa_printf(MSG_DEBUG
, "FT: Mismatch in FT Action STA address: "
1149 "STA=" MACSTR
" STA-Address=" MACSTR
,
1150 MAC2STR(sm
->addr
), MAC2STR(sta_addr
));
1155 * Do some sanity checking on the target AP address (not own and not
1156 * broadcast. This could be extended to filter based on a list of known
1157 * APs in the MD (if such a list were configured).
1159 if ((target_ap
[0] & 0x01) ||
1160 os_memcmp(target_ap
, sm
->wpa_auth
->addr
, ETH_ALEN
) == 0) {
1161 wpa_printf(MSG_DEBUG
, "FT: Invalid Target AP in FT Action "
1166 wpa_hexdump(MSG_MSGDUMP
, "FT: Action frame body", ies
, ies_len
);
1168 /* RRB - Forward action frame to the target AP */
1169 frame
= os_malloc(sizeof(*frame
) + len
);
1172 frame
->frame_type
= RSN_REMOTE_FRAME_TYPE_FT_RRB
;
1173 frame
->packet_type
= FT_PACKET_REQUEST
;
1174 frame
->action_length
= host_to_le16(len
);
1175 os_memcpy(frame
->ap_address
, sm
->wpa_auth
->addr
, ETH_ALEN
);
1176 os_memcpy(frame
+ 1, data
, len
);
1178 wpa_ft_rrb_send(sm
->wpa_auth
, target_ap
, (u8
*) frame
,
1179 sizeof(*frame
) + len
);
1186 static int wpa_ft_rrb_rx_request(struct wpa_authenticator
*wpa_auth
,
1187 const u8
*current_ap
, const u8
*sta_addr
,
1188 const u8
*body
, size_t len
)
1190 struct wpa_state_machine
*sm
;
1193 size_t resp_ies_len
, rlen
;
1194 struct ft_rrb_frame
*frame
;
1196 sm
= wpa_ft_add_sta(wpa_auth
, sta_addr
);
1198 wpa_printf(MSG_DEBUG
, "FT: Failed to add new STA based on "
1203 wpa_hexdump(MSG_MSGDUMP
, "FT: RRB Request Frame body", body
, len
);
1205 status
= wpa_ft_process_auth_req(sm
, body
, len
, &resp_ies
,
1208 wpa_printf(MSG_DEBUG
, "FT: RRB authentication response: STA=" MACSTR
1209 " CurrentAP=" MACSTR
" status=%d",
1210 MAC2STR(sm
->addr
), MAC2STR(current_ap
), status
);
1211 wpa_hexdump(MSG_DEBUG
, "FT: Response IEs", resp_ies
, resp_ies_len
);
1213 /* RRB - Forward action frame response to the Current AP */
1216 * data: Category[1] Action[1] STA_Address[6] Target_AP_Address[6]
1217 * Status_Code[2] FT Request action frame body[variable]
1219 rlen
= 2 + 2 * ETH_ALEN
+ 2 + resp_ies_len
;
1221 frame
= os_malloc(sizeof(*frame
) + rlen
);
1222 if (frame
== NULL
) {
1226 frame
->frame_type
= RSN_REMOTE_FRAME_TYPE_FT_RRB
;
1227 frame
->packet_type
= FT_PACKET_RESPONSE
;
1228 frame
->action_length
= host_to_le16(rlen
);
1229 os_memcpy(frame
->ap_address
, wpa_auth
->addr
, ETH_ALEN
);
1230 pos
= (u8
*) (frame
+ 1);
1231 *pos
++ = WLAN_ACTION_FT
;
1232 *pos
++ = 2; /* Action: Response */
1233 os_memcpy(pos
, sta_addr
, ETH_ALEN
);
1235 os_memcpy(pos
, wpa_auth
->addr
, ETH_ALEN
);
1237 WPA_PUT_LE16(pos
, status
);
1240 os_memcpy(pos
, resp_ies
, resp_ies_len
);
1244 wpa_ft_rrb_send(wpa_auth
, current_ap
, (u8
*) frame
,
1245 sizeof(*frame
) + rlen
);
1252 static int wpa_ft_rrb_rx_pull(struct wpa_authenticator
*wpa_auth
,
1254 const u8
*data
, size_t data_len
)
1256 struct ft_r0kh_r1kh_pull_frame
*frame
, f
;
1257 struct ft_remote_r1kh
*r1kh
;
1258 struct ft_r0kh_r1kh_resp_frame resp
, r
;
1262 wpa_printf(MSG_DEBUG
, "FT: Received PMK-R1 pull");
1264 if (data_len
< sizeof(*frame
))
1267 r1kh
= wpa_auth
->conf
.r1kh_list
;
1269 if (os_memcmp(r1kh
->addr
, src_addr
, ETH_ALEN
) == 0)
1274 wpa_printf(MSG_DEBUG
, "FT: No matching R1KH address found for "
1275 "PMK-R1 pull source address " MACSTR
,
1280 frame
= (struct ft_r0kh_r1kh_pull_frame
*) data
;
1281 /* aes_unwrap() does not support inplace decryption, so use a temporary
1282 * buffer for the data. */
1283 if (aes_unwrap(r1kh
->key
, (FT_R0KH_R1KH_PULL_DATA_LEN
+ 7) / 8,
1284 frame
->nonce
, f
.nonce
) < 0) {
1285 wpa_printf(MSG_DEBUG
, "FT: Failed to decrypt PMK-R1 pull "
1286 "request from " MACSTR
, MAC2STR(src_addr
));
1290 wpa_hexdump(MSG_DEBUG
, "FT: PMK-R1 pull - nonce",
1291 f
.nonce
, sizeof(f
.nonce
));
1292 wpa_hexdump(MSG_DEBUG
, "FT: PMK-R1 pull - PMKR0Name",
1293 f
.pmk_r0_name
, WPA_PMK_NAME_LEN
);
1294 wpa_printf(MSG_DEBUG
, "FT: PMK-R1 pull - R1KH-ID=" MACSTR
"S1KH-ID="
1295 MACSTR
, MAC2STR(f
.r1kh_id
), MAC2STR(f
.s1kh_id
));
1297 os_memset(&resp
, 0, sizeof(resp
));
1298 resp
.frame_type
= RSN_REMOTE_FRAME_TYPE_FT_RRB
;
1299 resp
.packet_type
= FT_PACKET_R0KH_R1KH_RESP
;
1300 resp
.data_length
= host_to_le16(FT_R0KH_R1KH_RESP_DATA_LEN
);
1301 os_memcpy(resp
.ap_address
, wpa_auth
->addr
, ETH_ALEN
);
1303 /* aes_wrap() does not support inplace encryption, so use a temporary
1304 * buffer for the data. */
1305 os_memcpy(r
.nonce
, f
.nonce
, sizeof(f
.nonce
));
1306 os_memcpy(r
.r1kh_id
, f
.r1kh_id
, FT_R1KH_ID_LEN
);
1307 os_memcpy(r
.s1kh_id
, f
.s1kh_id
, ETH_ALEN
);
1308 if (wpa_ft_fetch_pmk_r0(wpa_auth
, f
.s1kh_id
, f
.pmk_r0_name
, pmk_r0
,
1310 wpa_printf(MSG_DEBUG
, "FT: No matching PMKR0Name found for "
1315 wpa_derive_pmk_r1(pmk_r0
, f
.pmk_r0_name
, f
.r1kh_id
, f
.s1kh_id
,
1316 r
.pmk_r1
, r
.pmk_r1_name
);
1317 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1", r
.pmk_r1
, PMK_LEN
);
1318 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name", r
.pmk_r1_name
,
1320 r
.pairwise
= host_to_le16(pairwise
);
1321 os_memset(r
.pad
, 0, sizeof(r
.pad
));
1323 if (aes_wrap(r1kh
->key
, (FT_R0KH_R1KH_RESP_DATA_LEN
+ 7) / 8,
1324 r
.nonce
, resp
.nonce
) < 0) {
1325 os_memset(pmk_r0
, 0, PMK_LEN
);
1329 os_memset(pmk_r0
, 0, PMK_LEN
);
1331 wpa_ft_rrb_send(wpa_auth
, src_addr
, (u8
*) &resp
, sizeof(resp
));
1337 static int wpa_ft_rrb_rx_resp(struct wpa_authenticator
*wpa_auth
,
1339 const u8
*data
, size_t data_len
)
1341 struct ft_r0kh_r1kh_resp_frame
*frame
, f
;
1342 struct ft_remote_r0kh
*r0kh
;
1345 wpa_printf(MSG_DEBUG
, "FT: Received PMK-R1 pull response");
1347 if (data_len
< sizeof(*frame
))
1350 r0kh
= wpa_auth
->conf
.r0kh_list
;
1352 if (os_memcmp(r0kh
->addr
, src_addr
, ETH_ALEN
) == 0)
1357 wpa_printf(MSG_DEBUG
, "FT: No matching R0KH address found for "
1358 "PMK-R0 pull response source address " MACSTR
,
1363 frame
= (struct ft_r0kh_r1kh_resp_frame
*) data
;
1364 /* aes_unwrap() does not support inplace decryption, so use a temporary
1365 * buffer for the data. */
1366 if (aes_unwrap(r0kh
->key
, (FT_R0KH_R1KH_RESP_DATA_LEN
+ 7) / 8,
1367 frame
->nonce
, f
.nonce
) < 0) {
1368 wpa_printf(MSG_DEBUG
, "FT: Failed to decrypt PMK-R1 pull "
1369 "response from " MACSTR
, MAC2STR(src_addr
));
1373 if (os_memcmp(f
.r1kh_id
, wpa_auth
->conf
.r1_key_holder
, FT_R1KH_ID_LEN
)
1375 wpa_printf(MSG_DEBUG
, "FT: PMK-R1 pull response did not use a "
1376 "matching R1KH-ID");
1380 /* TODO: verify that <nonce,s1kh_id> matches with a pending request
1381 * and call this requests callback function to finish request
1384 pairwise
= le_to_host16(f
.pairwise
);
1385 wpa_hexdump(MSG_DEBUG
, "FT: PMK-R1 pull - nonce",
1386 f
.nonce
, sizeof(f
.nonce
));
1387 wpa_printf(MSG_DEBUG
, "FT: PMK-R1 pull - R1KH-ID=" MACSTR
"S1KH-ID="
1388 MACSTR
" pairwise=0x%x",
1389 MAC2STR(f
.r1kh_id
), MAC2STR(f
.s1kh_id
), pairwise
);
1390 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1 pull - PMK-R1",
1392 wpa_hexdump(MSG_DEBUG
, "FT: PMK-R1 pull - PMKR1Name",
1393 f
.pmk_r1_name
, WPA_PMK_NAME_LEN
);
1395 wpa_ft_store_pmk_r1(wpa_auth
, f
.s1kh_id
, f
.pmk_r1
, f
.pmk_r1_name
,
1397 os_memset(f
.pmk_r1
, 0, PMK_LEN
);
1403 static int wpa_ft_rrb_rx_push(struct wpa_authenticator
*wpa_auth
,
1405 const u8
*data
, size_t data_len
)
1407 struct ft_r0kh_r1kh_push_frame
*frame
, f
;
1408 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 pairwise
= le_to_host16(f
.pairwise
);
1461 wpa_printf(MSG_DEBUG
, "FT: PMK-R1 push - R1KH-ID=" MACSTR
" S1KH-ID="
1462 MACSTR
" pairwise=0x%x",
1463 MAC2STR(f
.r1kh_id
), MAC2STR(f
.s1kh_id
), pairwise
);
1464 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1 push - PMK-R1",
1466 wpa_hexdump(MSG_DEBUG
, "FT: PMK-R1 push - PMKR1Name",
1467 f
.pmk_r1_name
, WPA_PMK_NAME_LEN
);
1469 wpa_ft_store_pmk_r1(wpa_auth
, f
.s1kh_id
, f
.pmk_r1
, f
.pmk_r1_name
,
1471 os_memset(f
.pmk_r1
, 0, PMK_LEN
);
1477 int wpa_ft_rrb_rx(struct wpa_authenticator
*wpa_auth
, const u8
*src_addr
,
1478 const u8
*data
, size_t data_len
)
1480 struct ft_rrb_frame
*frame
;
1482 const u8
*pos
, *end
, *start
;
1484 const u8
*sta_addr
, *target_ap_addr
;
1486 wpa_printf(MSG_DEBUG
, "FT: RRB received frame from remote AP " MACSTR
,
1489 if (data_len
< sizeof(*frame
)) {
1490 wpa_printf(MSG_DEBUG
, "FT: Too short RRB frame (data_len=%lu)",
1491 (unsigned long) data_len
);
1496 frame
= (struct ft_rrb_frame
*) pos
;
1497 pos
+= sizeof(*frame
);
1499 alen
= le_to_host16(frame
->action_length
);
1500 wpa_printf(MSG_DEBUG
, "FT: RRB frame - frame_type=%d packet_type=%d "
1501 "action_length=%d ap_address=" MACSTR
,
1502 frame
->frame_type
, frame
->packet_type
, alen
,
1503 MAC2STR(frame
->ap_address
));
1505 if (frame
->frame_type
!= RSN_REMOTE_FRAME_TYPE_FT_RRB
) {
1506 /* Discard frame per IEEE Std 802.11r-2008, 11A.10.3 */
1507 wpa_printf(MSG_DEBUG
, "FT: RRB discarded frame with "
1508 "unrecognized type %d", frame
->frame_type
);
1512 if (alen
> data_len
- sizeof(*frame
)) {
1513 wpa_printf(MSG_DEBUG
, "FT: RRB frame too short for action "
1518 if (frame
->packet_type
== FT_PACKET_R0KH_R1KH_PULL
)
1519 return wpa_ft_rrb_rx_pull(wpa_auth
, src_addr
, data
, data_len
);
1520 if (frame
->packet_type
== FT_PACKET_R0KH_R1KH_RESP
)
1521 return wpa_ft_rrb_rx_resp(wpa_auth
, src_addr
, data
, data_len
);
1522 if (frame
->packet_type
== FT_PACKET_R0KH_R1KH_PUSH
)
1523 return wpa_ft_rrb_rx_push(wpa_auth
, src_addr
, data
, data_len
);
1525 wpa_hexdump(MSG_MSGDUMP
, "FT: RRB - FT Action frame", pos
, alen
);
1527 if (alen
< 1 + 1 + 2 * ETH_ALEN
) {
1528 wpa_printf(MSG_DEBUG
, "FT: Too short RRB frame (not enough "
1529 "room for Action Frame body); alen=%lu",
1530 (unsigned long) alen
);
1536 if (*pos
!= WLAN_ACTION_FT
) {
1537 wpa_printf(MSG_DEBUG
, "FT: Unexpected Action frame category "
1546 target_ap_addr
= pos
;
1548 wpa_printf(MSG_DEBUG
, "FT: RRB Action Frame: action=%d sta_addr="
1549 MACSTR
" target_ap_addr=" MACSTR
,
1550 action
, MAC2STR(sta_addr
), MAC2STR(target_ap_addr
));
1552 if (frame
->packet_type
== FT_PACKET_REQUEST
) {
1553 wpa_printf(MSG_DEBUG
, "FT: FT Packet Type - Request");
1556 wpa_printf(MSG_DEBUG
, "FT: Unexpected Action %d in "
1557 "RRB Request", action
);
1561 if (os_memcmp(target_ap_addr
, wpa_auth
->addr
, ETH_ALEN
) != 0) {
1562 wpa_printf(MSG_DEBUG
, "FT: Target AP address in the "
1563 "RRB Request does not match with own "
1568 if (wpa_ft_rrb_rx_request(wpa_auth
, frame
->ap_address
,
1569 sta_addr
, pos
, end
- pos
) < 0)
1571 } else if (frame
->packet_type
== FT_PACKET_RESPONSE
) {
1574 if (end
- pos
< 2) {
1575 wpa_printf(MSG_DEBUG
, "FT: Not enough room for status "
1576 "code in RRB Response");
1579 status_code
= WPA_GET_LE16(pos
);
1582 wpa_printf(MSG_DEBUG
, "FT: FT Packet Type - Response "
1583 "(status_code=%d)", status_code
);
1585 if (wpa_ft_action_send(wpa_auth
, sta_addr
, start
, alen
) < 0)
1588 wpa_printf(MSG_DEBUG
, "FT: RRB discarded frame with unknown "
1589 "packet_type %d", frame
->packet_type
);
1597 static void wpa_ft_generate_pmk_r1(struct wpa_authenticator
*wpa_auth
,
1598 struct wpa_ft_pmk_r0_sa
*pmk_r0
,
1599 struct ft_remote_r1kh
*r1kh
,
1600 const u8
*s1kh_id
, int pairwise
)
1602 struct ft_r0kh_r1kh_push_frame frame
, f
;
1605 os_memset(&frame
, 0, sizeof(frame
));
1606 frame
.frame_type
= RSN_REMOTE_FRAME_TYPE_FT_RRB
;
1607 frame
.packet_type
= FT_PACKET_R0KH_R1KH_PUSH
;
1608 frame
.data_length
= host_to_le16(FT_R0KH_R1KH_PUSH_DATA_LEN
);
1609 os_memcpy(frame
.ap_address
, wpa_auth
->addr
, ETH_ALEN
);
1611 /* aes_wrap() does not support inplace encryption, so use a temporary
1612 * buffer for the data. */
1613 os_memcpy(f
.r1kh_id
, r1kh
->id
, FT_R1KH_ID_LEN
);
1614 os_memcpy(f
.s1kh_id
, s1kh_id
, ETH_ALEN
);
1615 os_memcpy(f
.pmk_r0_name
, pmk_r0
->pmk_r0_name
, WPA_PMK_NAME_LEN
);
1616 wpa_derive_pmk_r1(pmk_r0
->pmk_r0
, pmk_r0
->pmk_r0_name
, r1kh
->id
,
1617 s1kh_id
, f
.pmk_r1
, f
.pmk_r1_name
);
1618 wpa_printf(MSG_DEBUG
, "FT: R1KH-ID " MACSTR
, MAC2STR(r1kh
->id
));
1619 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1", f
.pmk_r1
, PMK_LEN
);
1620 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name", f
.pmk_r1_name
,
1623 WPA_PUT_LE32(f
.timestamp
, now
.sec
);
1624 f
.pairwise
= host_to_le16(pairwise
);
1625 os_memset(f
.pad
, 0, sizeof(f
.pad
));
1626 if (aes_wrap(r1kh
->key
, (FT_R0KH_R1KH_PUSH_DATA_LEN
+ 7) / 8,
1627 f
.timestamp
, frame
.timestamp
) < 0)
1630 wpa_ft_rrb_send(wpa_auth
, r1kh
->addr
, (u8
*) &frame
, sizeof(frame
));
1634 void wpa_ft_push_pmk_r1(struct wpa_authenticator
*wpa_auth
, const u8
*addr
)
1636 struct wpa_ft_pmk_r0_sa
*r0
;
1637 struct ft_remote_r1kh
*r1kh
;
1639 if (!wpa_auth
->conf
.pmk_r1_push
)
1642 r0
= wpa_auth
->ft_pmk_cache
->pmk_r0
;
1644 if (os_memcmp(r0
->spa
, addr
, ETH_ALEN
) == 0)
1649 if (r0
== NULL
|| r0
->pmk_r1_pushed
)
1651 r0
->pmk_r1_pushed
= 1;
1653 wpa_printf(MSG_DEBUG
, "FT: Deriving and pushing PMK-R1 keys to R1KHs "
1654 "for STA " MACSTR
, MAC2STR(addr
));
1656 r1kh
= wpa_auth
->conf
.r1kh_list
;
1658 wpa_ft_generate_pmk_r1(wpa_auth
, r0
, r1kh
, addr
, r0
->pairwise
);
1663 #endif /* CONFIG_IEEE80211R */