2 * hostapd - IEEE 802.11r - Fast BSS Transition
3 * Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
18 #include "crypto/aes_wrap.h"
21 #include "ieee802_11.h"
23 #include "wpa_auth_i.h"
24 #include "wpa_auth_ie.h"
27 #ifdef CONFIG_IEEE80211R
47 static int wpa_ft_parse_ies(const u8
*ies
, size_t ies_len
,
48 struct wpa_ft_ies
*parse
);
51 static int wpa_ft_rrb_send(struct wpa_authenticator
*wpa_auth
, const u8
*dst
,
52 const u8
*data
, size_t data_len
)
54 if (wpa_auth
->cb
.send_ether
== NULL
)
56 return wpa_auth
->cb
.send_ether(wpa_auth
->cb
.ctx
, dst
, ETH_P_RRB
,
61 static int wpa_ft_action_send(struct wpa_authenticator
*wpa_auth
,
62 const u8
*dst
, const u8
*data
, size_t data_len
)
64 if (wpa_auth
->cb
.send_ft_action
== NULL
)
66 return wpa_auth
->cb
.send_ft_action(wpa_auth
->cb
.ctx
, dst
,
71 static struct wpa_state_machine
*
72 wpa_ft_add_sta(struct wpa_authenticator
*wpa_auth
, const u8
*sta_addr
)
74 if (wpa_auth
->cb
.add_sta
== NULL
)
76 return wpa_auth
->cb
.add_sta(wpa_auth
->cb
.ctx
, sta_addr
);
80 int wpa_write_mdie(struct wpa_auth_config
*conf
, u8
*buf
, size_t len
)
84 if (len
< 2 + sizeof(struct rsn_mdie
))
87 *pos
++ = WLAN_EID_MOBILITY_DOMAIN
;
88 *pos
++ = MOBILITY_DOMAIN_ID_LEN
+ 1;
89 os_memcpy(pos
, conf
->mobility_domain
, MOBILITY_DOMAIN_ID_LEN
);
90 pos
+= MOBILITY_DOMAIN_ID_LEN
;
91 capab
= RSN_FT_CAPAB_FT_OVER_DS
;
98 static int wpa_write_ftie(struct wpa_auth_config
*conf
, const u8
*r0kh_id
,
100 const u8
*anonce
, const u8
*snonce
,
101 u8
*buf
, size_t len
, const u8
*subelem
,
104 u8
*pos
= buf
, *ielen
;
105 struct rsn_ftie
*hdr
;
107 if (len
< 2 + sizeof(*hdr
) + 2 + FT_R1KH_ID_LEN
+ 2 + r0kh_id_len
+
111 *pos
++ = WLAN_EID_FAST_BSS_TRANSITION
;
114 hdr
= (struct rsn_ftie
*) pos
;
115 os_memset(hdr
, 0, sizeof(*hdr
));
117 WPA_PUT_LE16(hdr
->mic_control
, 0);
119 os_memcpy(hdr
->anonce
, anonce
, WPA_NONCE_LEN
);
121 os_memcpy(hdr
->snonce
, snonce
, WPA_NONCE_LEN
);
123 /* Optional Parameters */
124 *pos
++ = FTIE_SUBELEM_R1KH_ID
;
125 *pos
++ = FT_R1KH_ID_LEN
;
126 os_memcpy(pos
, conf
->r1_key_holder
, FT_R1KH_ID_LEN
);
127 pos
+= FT_R1KH_ID_LEN
;
130 *pos
++ = FTIE_SUBELEM_R0KH_ID
;
131 *pos
++ = r0kh_id_len
;
132 os_memcpy(pos
, r0kh_id
, r0kh_id_len
);
137 os_memcpy(pos
, subelem
, subelem_len
);
141 *ielen
= pos
- buf
- 2;
147 struct wpa_ft_pmk_r0_sa
{
148 struct wpa_ft_pmk_r0_sa
*next
;
150 u8 pmk_r0_name
[WPA_PMK_NAME_LEN
];
152 /* TODO: expiration, identity, radius_class, EAP type, VLAN ID */
156 struct wpa_ft_pmk_r1_sa
{
157 struct wpa_ft_pmk_r1_sa
*next
;
159 u8 pmk_r1_name
[WPA_PMK_NAME_LEN
];
161 /* TODO: expiration, identity, radius_class, EAP type, VLAN ID */
164 struct wpa_ft_pmk_cache
{
165 struct wpa_ft_pmk_r0_sa
*pmk_r0
;
166 struct wpa_ft_pmk_r1_sa
*pmk_r1
;
169 struct wpa_ft_pmk_cache
* wpa_ft_pmk_cache_init(void)
171 struct wpa_ft_pmk_cache
*cache
;
173 cache
= os_zalloc(sizeof(*cache
));
179 void wpa_ft_pmk_cache_deinit(struct wpa_ft_pmk_cache
*cache
)
181 struct wpa_ft_pmk_r0_sa
*r0
, *r0prev
;
182 struct wpa_ft_pmk_r1_sa
*r1
, *r1prev
;
188 os_memset(r0prev
->pmk_r0
, 0, PMK_LEN
);
196 os_memset(r1prev
->pmk_r1
, 0, PMK_LEN
);
204 static int wpa_ft_store_pmk_r0(struct wpa_authenticator
*wpa_auth
,
205 const u8
*spa
, const u8
*pmk_r0
,
206 const u8
*pmk_r0_name
)
208 struct wpa_ft_pmk_cache
*cache
= wpa_auth
->ft_pmk_cache
;
209 struct wpa_ft_pmk_r0_sa
*r0
;
211 /* TODO: add expiration and limit on number of entries in cache */
213 r0
= os_zalloc(sizeof(*r0
));
217 os_memcpy(r0
->pmk_r0
, pmk_r0
, PMK_LEN
);
218 os_memcpy(r0
->pmk_r0_name
, pmk_r0_name
, WPA_PMK_NAME_LEN
);
219 os_memcpy(r0
->spa
, spa
, ETH_ALEN
);
221 r0
->next
= cache
->pmk_r0
;
228 static int wpa_ft_fetch_pmk_r0(struct wpa_authenticator
*wpa_auth
,
229 const u8
*spa
, const u8
*pmk_r0_name
,
232 struct wpa_ft_pmk_cache
*cache
= wpa_auth
->ft_pmk_cache
;
233 struct wpa_ft_pmk_r0_sa
*r0
;
237 if (os_memcmp(r0
->spa
, spa
, ETH_ALEN
) == 0 &&
238 os_memcmp(r0
->pmk_r0_name
, pmk_r0_name
, WPA_PMK_NAME_LEN
)
240 os_memcpy(pmk_r0
, r0
->pmk_r0
, PMK_LEN
);
251 static int wpa_ft_store_pmk_r1(struct wpa_authenticator
*wpa_auth
,
252 const u8
*spa
, const u8
*pmk_r1
,
253 const u8
*pmk_r1_name
)
255 struct wpa_ft_pmk_cache
*cache
= wpa_auth
->ft_pmk_cache
;
256 struct wpa_ft_pmk_r1_sa
*r1
;
258 /* TODO: add expiration and limit on number of entries in cache */
260 r1
= os_zalloc(sizeof(*r1
));
264 os_memcpy(r1
->pmk_r1
, pmk_r1
, PMK_LEN
);
265 os_memcpy(r1
->pmk_r1_name
, pmk_r1_name
, WPA_PMK_NAME_LEN
);
266 os_memcpy(r1
->spa
, spa
, ETH_ALEN
);
268 r1
->next
= cache
->pmk_r1
;
275 static int wpa_ft_fetch_pmk_r1(struct wpa_authenticator
*wpa_auth
,
276 const u8
*spa
, const u8
*pmk_r1_name
,
279 struct wpa_ft_pmk_cache
*cache
= wpa_auth
->ft_pmk_cache
;
280 struct wpa_ft_pmk_r1_sa
*r1
;
284 if (os_memcmp(r1
->spa
, spa
, ETH_ALEN
) == 0 &&
285 os_memcmp(r1
->pmk_r1_name
, pmk_r1_name
, WPA_PMK_NAME_LEN
)
287 os_memcpy(pmk_r1
, r1
->pmk_r1
, PMK_LEN
);
298 static int wpa_ft_pull_pmk_r1(struct wpa_authenticator
*wpa_auth
,
299 const u8
*s1kh_id
, const u8
*r0kh_id
,
300 size_t r0kh_id_len
, const u8
*pmk_r0_name
)
302 struct ft_remote_r0kh
*r0kh
;
303 struct ft_r0kh_r1kh_pull_frame frame
, f
;
305 r0kh
= wpa_auth
->conf
.r0kh_list
;
307 if (r0kh
->id_len
== r0kh_id_len
&&
308 os_memcmp(r0kh
->id
, r0kh_id
, r0kh_id_len
) == 0)
315 wpa_printf(MSG_DEBUG
, "FT: Send PMK-R1 pull request to remote R0KH "
316 "address " MACSTR
, MAC2STR(r0kh
->addr
));
318 os_memset(&frame
, 0, sizeof(frame
));
319 frame
.frame_type
= RSN_REMOTE_FRAME_TYPE_FT_RRB
;
320 frame
.packet_type
= FT_PACKET_R0KH_R1KH_PULL
;
321 frame
.data_length
= host_to_le16(FT_R0KH_R1KH_PULL_DATA_LEN
);
322 os_memcpy(frame
.ap_address
, wpa_auth
->addr
, ETH_ALEN
);
324 /* aes_wrap() does not support inplace encryption, so use a temporary
325 * buffer for the data. */
326 if (os_get_random(f
.nonce
, sizeof(f
.nonce
))) {
327 wpa_printf(MSG_DEBUG
, "FT: Failed to get random data for "
331 os_memcpy(f
.pmk_r0_name
, pmk_r0_name
, WPA_PMK_NAME_LEN
);
332 os_memcpy(f
.r1kh_id
, wpa_auth
->conf
.r1_key_holder
, FT_R1KH_ID_LEN
);
333 os_memcpy(f
.s1kh_id
, s1kh_id
, ETH_ALEN
);
335 if (aes_wrap(r0kh
->key
, (FT_R0KH_R1KH_PULL_DATA_LEN
+ 7) / 8,
336 f
.nonce
, frame
.nonce
) < 0)
339 wpa_ft_rrb_send(wpa_auth
, r0kh
->addr
, (u8
*) &frame
, sizeof(frame
));
345 int wpa_auth_derive_ptk_ft(struct wpa_state_machine
*sm
, const u8
*pmk
,
346 struct wpa_ptk
*ptk
, size_t ptk_len
)
348 u8 pmk_r0
[PMK_LEN
], pmk_r0_name
[WPA_PMK_NAME_LEN
];
349 u8 pmk_r1
[PMK_LEN
], pmk_r1_name
[WPA_PMK_NAME_LEN
];
350 u8 ptk_name
[WPA_PMK_NAME_LEN
];
351 const u8
*mdid
= sm
->wpa_auth
->conf
.mobility_domain
;
352 const u8
*r0kh
= sm
->wpa_auth
->conf
.r0_key_holder
;
353 size_t r0kh_len
= sm
->wpa_auth
->conf
.r0_key_holder_len
;
354 const u8
*r1kh
= sm
->wpa_auth
->conf
.r1_key_holder
;
355 const u8
*ssid
= sm
->wpa_auth
->conf
.ssid
;
356 size_t ssid_len
= sm
->wpa_auth
->conf
.ssid_len
;
359 if (sm
->xxkey_len
== 0) {
360 wpa_printf(MSG_DEBUG
, "FT: XXKey not available for key "
365 wpa_derive_pmk_r0(sm
->xxkey
, sm
->xxkey_len
, ssid
, ssid_len
, mdid
,
366 r0kh
, r0kh_len
, sm
->addr
, pmk_r0
, pmk_r0_name
);
367 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R0", pmk_r0
, PMK_LEN
);
368 wpa_hexdump(MSG_DEBUG
, "FT: PMKR0Name", pmk_r0_name
, WPA_PMK_NAME_LEN
);
369 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
, pmk_r1_name
);
373 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1", pmk_r1
, PMK_LEN
);
374 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name", pmk_r1_name
, WPA_PMK_NAME_LEN
);
375 wpa_ft_store_pmk_r1(sm
->wpa_auth
, sm
->addr
, pmk_r1
, pmk_r1_name
);
377 wpa_pmk_r1_to_ptk(pmk_r1
, sm
->SNonce
, sm
->ANonce
, sm
->addr
,
378 sm
->wpa_auth
->addr
, pmk_r1_name
,
379 (u8
*) ptk
, ptk_len
, ptk_name
);
380 wpa_hexdump_key(MSG_DEBUG
, "FT: PTK", (u8
*) ptk
, ptk_len
);
381 wpa_hexdump(MSG_DEBUG
, "FT: PTKName", ptk_name
, WPA_PMK_NAME_LEN
);
387 static inline int wpa_auth_get_seqnum(struct wpa_authenticator
*wpa_auth
,
388 const u8
*addr
, int idx
, u8
*seq
)
390 if (wpa_auth
->cb
.get_seqnum
== NULL
)
392 return wpa_auth
->cb
.get_seqnum(wpa_auth
->cb
.ctx
, addr
, idx
, seq
);
396 static u8
* wpa_ft_gtk_subelem(struct wpa_state_machine
*sm
, size_t *len
)
399 struct wpa_group
*gsm
= sm
->group
;
400 size_t subelem_len
, pad_len
;
405 key_len
= gsm
->GTK_len
;
406 if (key_len
> sizeof(keybuf
))
410 * Pad key for AES Key Wrap if it is not multiple of 8 bytes or is less
413 pad_len
= key_len
% 8;
415 pad_len
= 8 - pad_len
;
416 if (key_len
+ pad_len
< 16)
419 os_memcpy(keybuf
, gsm
->GTK
[gsm
->GN
- 1], key_len
);
420 os_memset(keybuf
+ key_len
, 0, pad_len
);
421 keybuf
[key_len
] = 0xdd;
425 key
= gsm
->GTK
[gsm
->GN
- 1];
428 * Sub-elem ID[1] | Length[1] | Key Info[1] | Key Length[1] | RSC[8] |
431 subelem_len
= 12 + key_len
+ 8;
432 subelem
= os_zalloc(subelem_len
);
436 subelem
[0] = FTIE_SUBELEM_GTK
;
437 subelem
[1] = 10 + key_len
+ 8;
438 subelem
[2] = gsm
->GN
& 0x03; /* Key ID in B0-B1 of Key Info */
439 subelem
[3] = gsm
->GTK_len
;
440 wpa_auth_get_seqnum(sm
->wpa_auth
, NULL
, gsm
->GN
, subelem
+ 4);
441 if (aes_wrap(sm
->PTK
.kek
, key_len
/ 8, key
, subelem
+ 12)) {
451 #ifdef CONFIG_IEEE80211W
452 static u8
* wpa_ft_igtk_subelem(struct wpa_state_machine
*sm
, size_t *len
)
455 struct wpa_group
*gsm
= sm
->group
;
458 /* Sub-elem ID[1] | Length[1] | KeyID[2] | IPN[6] | Key Length[1] |
460 subelem_len
= 1 + 1 + 2 + 6 + 1 + WPA_IGTK_LEN
+ 8;
461 subelem
= os_zalloc(subelem_len
);
466 *pos
++ = FTIE_SUBELEM_IGTK
;
467 *pos
++ = subelem_len
- 2;
468 WPA_PUT_LE16(pos
, gsm
->GN_igtk
);
470 wpa_auth_get_seqnum(sm
->wpa_auth
, NULL
, gsm
->GN_igtk
, pos
);
472 *pos
++ = WPA_IGTK_LEN
;
473 if (aes_wrap(sm
->PTK
.kek
, WPA_IGTK_LEN
/ 8,
474 gsm
->IGTK
[gsm
->GN_igtk
- 4], pos
)) {
482 #endif /* CONFIG_IEEE80211W */
485 static u8
* wpa_ft_process_rdie(u8
*pos
, u8
*end
, u8 id
, u8 descr_count
,
486 const u8
*ies
, size_t ies_len
)
488 struct ieee802_11_elems parse
;
489 struct rsn_rdie
*rdie
;
491 wpa_printf(MSG_DEBUG
, "FT: Resource Request: id=%d descr_count=%d",
493 wpa_hexdump(MSG_MSGDUMP
, "FT: Resource descriptor IE(s)",
496 if (end
- pos
< (int) sizeof(*rdie
)) {
497 wpa_printf(MSG_ERROR
, "FT: Not enough room for response RDIE");
501 *pos
++ = WLAN_EID_RIC_DATA
;
502 *pos
++ = sizeof(*rdie
);
503 rdie
= (struct rsn_rdie
*) pos
;
505 rdie
->descr_count
= 0;
506 rdie
->status_code
= host_to_le16(WLAN_STATUS_SUCCESS
);
507 pos
+= sizeof(*rdie
);
509 if (ieee802_11_parse_elems((u8
*) ies
, ies_len
, &parse
, 1) ==
511 wpa_printf(MSG_DEBUG
, "FT: Failed to parse request IEs");
513 host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE
);
518 if (parse
.wmm_tspec
) {
519 struct wmm_tspec_element
*tspec
;
522 if (parse
.wmm_tspec_len
+ 2 < (int) sizeof(*tspec
)) {
523 wpa_printf(MSG_DEBUG
, "FT: Too short WMM TSPEC IE "
524 "(%d)", (int) parse
.wmm_tspec_len
);
526 host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE
);
529 if (end
- pos
< (int) sizeof(*tspec
)) {
530 wpa_printf(MSG_ERROR
, "FT: Not enough room for "
533 host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE
);
536 tspec
= (struct wmm_tspec_element
*) pos
;
537 os_memcpy(tspec
, parse
.wmm_tspec
- 2, sizeof(*tspec
));
538 res
= wmm_process_tspec(tspec
);
539 wpa_printf(MSG_DEBUG
, "FT: ADDTS processing result: %d", res
);
540 if (res
== WMM_ADDTS_STATUS_INVALID_PARAMETERS
)
542 host_to_le16(WLAN_STATUS_INVALID_PARAMETERS
);
543 else if (res
== WMM_ADDTS_STATUS_REFUSED
)
545 host_to_le16(WLAN_STATUS_REQUEST_DECLINED
);
547 /* TSPEC accepted; include updated TSPEC in response */
548 rdie
->descr_count
= 1;
549 pos
+= sizeof(*tspec
);
553 #endif /* NEED_AP_MLME */
555 wpa_printf(MSG_DEBUG
, "FT: No supported resource requested");
556 rdie
->status_code
= host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE
);
561 static u8
* wpa_ft_process_ric(u8
*pos
, u8
*end
, const u8
*ric
, size_t ric_len
)
563 const u8
*rpos
, *start
;
564 const struct rsn_rdie
*rdie
;
566 wpa_hexdump(MSG_MSGDUMP
, "FT: RIC Request", ric
, ric_len
);
569 while (rpos
+ sizeof(*rdie
) < ric
+ ric_len
) {
570 if (rpos
[0] != WLAN_EID_RIC_DATA
|| rpos
[1] < sizeof(*rdie
) ||
571 rpos
+ 2 + rpos
[1] > ric
+ ric_len
)
573 rdie
= (const struct rsn_rdie
*) (rpos
+ 2);
577 while (rpos
+ 2 <= ric
+ ric_len
&&
578 rpos
+ 2 + rpos
[1] <= ric
+ ric_len
) {
579 if (rpos
[0] == WLAN_EID_RIC_DATA
)
583 pos
= wpa_ft_process_rdie(pos
, end
, rdie
->id
,
585 start
, rpos
- start
);
592 u8
* wpa_sm_write_assoc_resp_ies(struct wpa_state_machine
*sm
, u8
*pos
,
593 size_t max_len
, int auth_alg
,
594 const u8
*req_ies
, size_t req_ies_len
)
596 u8
*end
, *mdie
, *ftie
, *rsnie
, *r0kh_id
, *subelem
= NULL
;
597 size_t mdie_len
, ftie_len
, rsnie_len
, r0kh_id_len
, subelem_len
= 0;
599 struct wpa_auth_config
*conf
;
600 struct rsn_ftie
*_ftie
;
601 struct wpa_ft_ies parse
;
607 conf
= &sm
->wpa_auth
->conf
;
609 if (sm
->wpa_key_mgmt
!= WPA_KEY_MGMT_FT_IEEE8021X
&&
610 sm
->wpa_key_mgmt
!= WPA_KEY_MGMT_FT_PSK
)
616 res
= wpa_write_rsn_ie(conf
, pos
, end
- pos
, sm
->pmk_r1_name
);
623 /* Mobility Domain Information */
624 res
= wpa_write_mdie(conf
, pos
, end
- pos
);
631 /* Fast BSS Transition Information */
632 if (auth_alg
== WLAN_AUTH_FT
) {
633 subelem
= wpa_ft_gtk_subelem(sm
, &subelem_len
);
634 r0kh_id
= sm
->r0kh_id
;
635 r0kh_id_len
= sm
->r0kh_id_len
;
636 #ifdef CONFIG_IEEE80211W
637 if (sm
->mgmt_frame_prot
) {
641 igtk
= wpa_ft_igtk_subelem(sm
, &igtk_len
);
646 nbuf
= os_realloc(subelem
, subelem_len
+ igtk_len
);
653 os_memcpy(subelem
+ subelem_len
, igtk
, igtk_len
);
654 subelem_len
+= igtk_len
;
657 #endif /* CONFIG_IEEE80211W */
659 r0kh_id
= conf
->r0_key_holder
;
660 r0kh_id_len
= conf
->r0_key_holder_len
;
662 res
= wpa_write_ftie(conf
, r0kh_id
, r0kh_id_len
, NULL
, NULL
, pos
,
663 end
- pos
, subelem
, subelem_len
);
671 _ftie
= (struct rsn_ftie
*) (ftie
+ 2);
672 _ftie
->mic_control
[1] = 3; /* Information element count */
675 if (wpa_ft_parse_ies(req_ies
, req_ies_len
, &parse
) == 0 && parse
.ric
) {
676 pos
= wpa_ft_process_ric(pos
, end
, parse
.ric
, parse
.ric_len
);
677 _ftie
->mic_control
[1] += ieee802_11_ie_count(ric_start
,
680 if (ric_start
== pos
)
683 if (wpa_ft_mic(sm
->PTK
.kck
, sm
->addr
, sm
->wpa_auth
->addr
, 6,
684 mdie
, mdie_len
, ftie
, ftie_len
,
686 ric_start
, ric_start
? pos
- ric_start
: 0,
688 wpa_printf(MSG_DEBUG
, "FT: Failed to calculate MIC");
694 static int wpa_ft_parse_ftie(const u8
*ie
, size_t ie_len
,
695 struct wpa_ft_ies
*parse
)
700 parse
->ftie_len
= ie_len
;
702 pos
= ie
+ sizeof(struct rsn_ftie
);
705 while (pos
+ 2 <= end
&& pos
+ 2 + pos
[1] <= end
) {
707 case FTIE_SUBELEM_R1KH_ID
:
708 if (pos
[1] != FT_R1KH_ID_LEN
) {
709 wpa_printf(MSG_DEBUG
, "FT: Invalid R1KH-ID "
710 "length in FTIE: %d", pos
[1]);
713 parse
->r1kh_id
= pos
+ 2;
715 case FTIE_SUBELEM_GTK
:
716 parse
->gtk
= pos
+ 2;
717 parse
->gtk_len
= pos
[1];
719 case FTIE_SUBELEM_R0KH_ID
:
720 if (pos
[1] < 1 || pos
[1] > FT_R0KH_ID_MAX_LEN
) {
721 wpa_printf(MSG_DEBUG
, "FT: Invalid R0KH-ID "
722 "length in FTIE: %d", pos
[1]);
725 parse
->r0kh_id
= pos
+ 2;
726 parse
->r0kh_id_len
= pos
[1];
737 static int wpa_ft_parse_ies(const u8
*ies
, size_t ies_len
,
738 struct wpa_ft_ies
*parse
)
741 struct wpa_ie_data data
;
743 const struct rsn_ftie
*ftie
;
744 int prot_ie_count
= 0;
746 os_memset(parse
, 0, sizeof(*parse
));
752 while (pos
+ 2 <= end
&& pos
+ 2 + pos
[1] <= end
) {
755 parse
->rsn
= pos
+ 2;
756 parse
->rsn_len
= pos
[1];
757 ret
= wpa_parse_wpa_ie_rsn(parse
->rsn
- 2,
761 wpa_printf(MSG_DEBUG
, "FT: Failed to parse "
765 if (data
.num_pmkid
== 1 && data
.pmkid
)
766 parse
->rsn_pmkid
= data
.pmkid
;
768 case WLAN_EID_MOBILITY_DOMAIN
:
769 parse
->mdie
= pos
+ 2;
770 parse
->mdie_len
= pos
[1];
772 case WLAN_EID_FAST_BSS_TRANSITION
:
773 if (pos
[1] < sizeof(*ftie
))
775 ftie
= (const struct rsn_ftie
*) (pos
+ 2);
776 prot_ie_count
= ftie
->mic_control
[1];
777 if (wpa_ft_parse_ftie(pos
+ 2, pos
[1], parse
) < 0)
780 case WLAN_EID_RIC_DATA
:
781 if (parse
->ric
== NULL
)
788 if (prot_ie_count
== 0)
789 return 0; /* no MIC */
792 * Check that the protected IE count matches with IEs included in the
801 if (prot_ie_count
< 0) {
802 wpa_printf(MSG_DEBUG
, "FT: Some required IEs not included in "
803 "the protected IE count");
807 if (prot_ie_count
== 0 && parse
->ric
) {
808 wpa_printf(MSG_DEBUG
, "FT: RIC IE(s) in the frame, but not "
809 "included in protected IE count");
813 /* Determine the end of the RIC IE(s) */
815 while (pos
&& pos
+ 2 <= end
&& pos
+ 2 + pos
[1] <= end
&&
820 parse
->ric_len
= pos
- parse
->ric
;
822 wpa_printf(MSG_DEBUG
, "FT: %d protected IEs missing from "
823 "frame", (int) prot_ie_count
);
831 static inline int wpa_auth_set_key(struct wpa_authenticator
*wpa_auth
,
833 wpa_alg alg
, const u8
*addr
, int idx
,
834 u8
*key
, size_t key_len
)
836 if (wpa_auth
->cb
.set_key
== NULL
)
838 return wpa_auth
->cb
.set_key(wpa_auth
->cb
.ctx
, vlan_id
, alg
, addr
, idx
,
843 static void wpa_ft_install_ptk(struct wpa_state_machine
*sm
)
848 /* MLME-SETKEYS.request(PTK) */
849 if (sm
->pairwise
== WPA_CIPHER_TKIP
) {
852 } else if (sm
->pairwise
== WPA_CIPHER_CCMP
) {
858 /* FIX: add STA entry to kernel/driver here? The set_key will fail
859 * most likely without this.. At the moment, STA entry is added only
860 * after association has been completed. Alternatively, could
861 * re-configure PTK at that point(?).
863 if (wpa_auth_set_key(sm
->wpa_auth
, 0, alg
, sm
->addr
, 0,
867 /* FIX: MLME-SetProtection.Request(TA, Tx_Rx) */
868 sm
->pairwise_set
= TRUE
;
872 static u16
wpa_ft_process_auth_req(struct wpa_state_machine
*sm
,
873 const u8
*ies
, size_t ies_len
,
874 u8
**resp_ies
, size_t *resp_ies_len
)
876 struct rsn_mdie
*mdie
;
877 struct rsn_ftie
*ftie
;
878 u8 pmk_r1
[PMK_LEN
], pmk_r1_name
[WPA_PMK_NAME_LEN
];
879 u8 ptk_name
[WPA_PMK_NAME_LEN
];
880 struct wpa_auth_config
*conf
;
881 struct wpa_ft_ies parse
;
882 size_t buflen
, ptk_len
;
889 sm
->pmk_r1_name_valid
= 0;
890 conf
= &sm
->wpa_auth
->conf
;
892 wpa_hexdump(MSG_DEBUG
, "FT: Received authentication frame IEs",
895 if (wpa_ft_parse_ies(ies
, ies_len
, &parse
) < 0) {
896 wpa_printf(MSG_DEBUG
, "FT: Failed to parse FT IEs");
897 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
900 mdie
= (struct rsn_mdie
*) parse
.mdie
;
901 if (mdie
== NULL
|| parse
.mdie_len
< sizeof(*mdie
) ||
902 os_memcmp(mdie
->mobility_domain
,
903 sm
->wpa_auth
->conf
.mobility_domain
,
904 MOBILITY_DOMAIN_ID_LEN
) != 0) {
905 wpa_printf(MSG_DEBUG
, "FT: Invalid MDIE");
906 return WLAN_STATUS_INVALID_MDIE
;
909 ftie
= (struct rsn_ftie
*) parse
.ftie
;
910 if (ftie
== NULL
|| parse
.ftie_len
< sizeof(*ftie
)) {
911 wpa_printf(MSG_DEBUG
, "FT: Invalid FTIE");
912 return WLAN_STATUS_INVALID_FTIE
;
915 os_memcpy(sm
->SNonce
, ftie
->snonce
, WPA_NONCE_LEN
);
917 if (parse
.r0kh_id
== NULL
) {
918 wpa_printf(MSG_DEBUG
, "FT: Invalid FTIE - no R0KH-ID");
919 return WLAN_STATUS_INVALID_FTIE
;
922 wpa_hexdump(MSG_DEBUG
, "FT: STA R0KH-ID",
923 parse
.r0kh_id
, parse
.r0kh_id_len
);
924 os_memcpy(sm
->r0kh_id
, parse
.r0kh_id
, parse
.r0kh_id_len
);
925 sm
->r0kh_id_len
= parse
.r0kh_id_len
;
927 if (parse
.rsn_pmkid
== NULL
) {
928 wpa_printf(MSG_DEBUG
, "FT: No PMKID in RSNIE");
929 return WLAN_STATUS_INVALID_PMKID
;
932 wpa_hexdump(MSG_DEBUG
, "FT: Requested PMKR0Name",
933 parse
.rsn_pmkid
, WPA_PMK_NAME_LEN
);
934 wpa_derive_pmk_r1_name(parse
.rsn_pmkid
,
935 sm
->wpa_auth
->conf
.r1_key_holder
, sm
->addr
,
937 wpa_hexdump(MSG_DEBUG
, "FT: Derived requested PMKR1Name",
938 pmk_r1_name
, WPA_PMK_NAME_LEN
);
940 if (wpa_ft_fetch_pmk_r1(sm
->wpa_auth
, sm
->addr
, pmk_r1_name
, pmk_r1
) <
942 if (wpa_ft_pull_pmk_r1(sm
->wpa_auth
, sm
->addr
, sm
->r0kh_id
,
943 sm
->r0kh_id_len
, parse
.rsn_pmkid
) < 0) {
944 wpa_printf(MSG_DEBUG
, "FT: Did not have matching "
945 "PMK-R1 and unknown R0KH-ID");
946 return WLAN_STATUS_INVALID_PMKID
;
950 * TODO: Should return "status pending" (and the caller should
951 * not send out response now). The real response will be sent
952 * once the response from R0KH is received.
954 return WLAN_STATUS_INVALID_PMKID
;
957 wpa_hexdump_key(MSG_DEBUG
, "FT: Selected PMK-R1", pmk_r1
, PMK_LEN
);
958 sm
->pmk_r1_name_valid
= 1;
959 os_memcpy(sm
->pmk_r1_name
, pmk_r1_name
, WPA_PMK_NAME_LEN
);
961 if (os_get_random(sm
->ANonce
, WPA_NONCE_LEN
)) {
962 wpa_printf(MSG_DEBUG
, "FT: Failed to get random data for "
964 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
967 wpa_hexdump(MSG_DEBUG
, "FT: Received SNonce",
968 sm
->SNonce
, WPA_NONCE_LEN
);
969 wpa_hexdump(MSG_DEBUG
, "FT: Generated ANonce",
970 sm
->ANonce
, WPA_NONCE_LEN
);
972 ptk_len
= sm
->pairwise
== WPA_CIPHER_CCMP
? 48 : 64;
973 wpa_pmk_r1_to_ptk(pmk_r1
, sm
->SNonce
, sm
->ANonce
, sm
->addr
,
974 sm
->wpa_auth
->addr
, pmk_r1_name
,
975 (u8
*) &sm
->PTK
, ptk_len
, ptk_name
);
976 wpa_hexdump_key(MSG_DEBUG
, "FT: PTK",
977 (u8
*) &sm
->PTK
, ptk_len
);
978 wpa_hexdump(MSG_DEBUG
, "FT: PTKName", ptk_name
, WPA_PMK_NAME_LEN
);
980 wpa_ft_install_ptk(sm
);
982 buflen
= 2 + sizeof(struct rsn_mdie
) + 2 + sizeof(struct rsn_ftie
) +
983 2 + FT_R1KH_ID_LEN
+ 200;
984 *resp_ies
= os_zalloc(buflen
);
985 if (*resp_ies
== NULL
) {
986 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
990 end
= *resp_ies
+ buflen
;
992 ret
= wpa_write_rsn_ie(conf
, pos
, end
- pos
, parse
.rsn_pmkid
);
996 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
1000 ret
= wpa_write_mdie(conf
, pos
, end
- pos
);
1004 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
1008 ret
= wpa_write_ftie(conf
, parse
.r0kh_id
, parse
.r0kh_id_len
,
1009 sm
->ANonce
, sm
->SNonce
, pos
, end
- pos
, NULL
, 0);
1013 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
1017 *resp_ies_len
= pos
- *resp_ies
;
1019 return WLAN_STATUS_SUCCESS
;
1023 void wpa_ft_process_auth(struct wpa_state_machine
*sm
, const u8
*bssid
,
1024 u16 auth_transaction
, const u8
*ies
, size_t ies_len
,
1025 void (*cb
)(void *ctx
, const u8
*dst
, const u8
*bssid
,
1026 u16 auth_transaction
, u16 status
,
1027 const u8
*ies
, size_t ies_len
),
1032 size_t resp_ies_len
;
1035 wpa_printf(MSG_DEBUG
, "FT: Received authentication frame, but "
1036 "WPA SM not available");
1040 wpa_printf(MSG_DEBUG
, "FT: Received authentication frame: STA=" MACSTR
1041 " BSSID=" MACSTR
" transaction=%d",
1042 MAC2STR(sm
->addr
), MAC2STR(bssid
), auth_transaction
);
1043 status
= wpa_ft_process_auth_req(sm
, ies
, ies_len
, &resp_ies
,
1046 wpa_printf(MSG_DEBUG
, "FT: FT authentication response: dst=" MACSTR
1047 " auth_transaction=%d status=%d",
1048 MAC2STR(sm
->addr
), auth_transaction
+ 1, status
);
1049 wpa_hexdump(MSG_DEBUG
, "FT: Response IEs", resp_ies
, resp_ies_len
);
1050 cb(ctx
, sm
->addr
, bssid
, auth_transaction
+ 1, status
,
1051 resp_ies
, resp_ies_len
);
1056 u16
wpa_ft_validate_reassoc(struct wpa_state_machine
*sm
, const u8
*ies
,
1059 struct wpa_ft_ies parse
;
1060 struct rsn_mdie
*mdie
;
1061 struct rsn_ftie
*ftie
;
1065 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
1067 wpa_hexdump(MSG_DEBUG
, "FT: Reassoc Req IEs", ies
, ies_len
);
1069 if (wpa_ft_parse_ies(ies
, ies_len
, &parse
) < 0) {
1070 wpa_printf(MSG_DEBUG
, "FT: Failed to parse FT IEs");
1071 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
1074 if (parse
.rsn
== NULL
) {
1075 wpa_printf(MSG_DEBUG
, "FT: No RSNIE in Reassoc Req");
1076 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
1079 if (parse
.rsn_pmkid
== NULL
) {
1080 wpa_printf(MSG_DEBUG
, "FT: No PMKID in RSNIE");
1081 return WLAN_STATUS_INVALID_PMKID
;
1084 if (os_memcmp(parse
.rsn_pmkid
, sm
->pmk_r1_name
, WPA_PMK_NAME_LEN
) != 0)
1086 wpa_printf(MSG_DEBUG
, "FT: PMKID in Reassoc Req did not match "
1087 "with the PMKR1Name derived from auth request");
1088 return WLAN_STATUS_INVALID_PMKID
;
1091 mdie
= (struct rsn_mdie
*) parse
.mdie
;
1092 if (mdie
== NULL
|| parse
.mdie_len
< sizeof(*mdie
) ||
1093 os_memcmp(mdie
->mobility_domain
,
1094 sm
->wpa_auth
->conf
.mobility_domain
,
1095 MOBILITY_DOMAIN_ID_LEN
) != 0) {
1096 wpa_printf(MSG_DEBUG
, "FT: Invalid MDIE");
1097 return WLAN_STATUS_INVALID_MDIE
;
1100 ftie
= (struct rsn_ftie
*) parse
.ftie
;
1101 if (ftie
== NULL
|| parse
.ftie_len
< sizeof(*ftie
)) {
1102 wpa_printf(MSG_DEBUG
, "FT: Invalid FTIE");
1103 return WLAN_STATUS_INVALID_FTIE
;
1106 if (wpa_ft_mic(sm
->PTK
.kck
, sm
->addr
, sm
->wpa_auth
->addr
, 5,
1107 parse
.mdie
- 2, parse
.mdie_len
+ 2,
1108 parse
.ftie
- 2, parse
.ftie_len
+ 2,
1109 parse
.rsn
- 2, parse
.rsn_len
+ 2,
1110 parse
.ric
, parse
.ric_len
,
1112 wpa_printf(MSG_DEBUG
, "FT: Failed to calculate MIC");
1113 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
1116 if (os_memcmp(mic
, ftie
->mic
, 16) != 0) {
1117 wpa_printf(MSG_DEBUG
, "FT: Invalid MIC in FTIE");
1118 wpa_hexdump(MSG_MSGDUMP
, "FT: Received MIC", ftie
->mic
, 16);
1119 wpa_hexdump(MSG_MSGDUMP
, "FT: Calculated MIC", mic
, 16);
1120 return WLAN_STATUS_INVALID_FTIE
;
1123 return WLAN_STATUS_SUCCESS
;
1127 int wpa_ft_action_rx(struct wpa_state_machine
*sm
, const u8
*data
, size_t len
)
1129 const u8
*sta_addr
, *target_ap
;
1133 struct ft_rrb_frame
*frame
;
1139 * data: Category[1] Action[1] STA_Address[6] Target_AP_Address[6]
1140 * FT Request action frame body[variable]
1144 wpa_printf(MSG_DEBUG
, "FT: Too short FT Action frame "
1145 "(len=%lu)", (unsigned long) len
);
1150 sta_addr
= data
+ 2;
1151 target_ap
= data
+ 8;
1155 wpa_printf(MSG_DEBUG
, "FT: Received FT Action frame (STA=" MACSTR
1156 " Target AP=" MACSTR
" Action=%d)",
1157 MAC2STR(sta_addr
), MAC2STR(target_ap
), action
);
1159 if (os_memcmp(sta_addr
, sm
->addr
, ETH_ALEN
) != 0) {
1160 wpa_printf(MSG_DEBUG
, "FT: Mismatch in FT Action STA address: "
1161 "STA=" MACSTR
" STA-Address=" MACSTR
,
1162 MAC2STR(sm
->addr
), MAC2STR(sta_addr
));
1167 * Do some sanity checking on the target AP address (not own and not
1168 * broadcast. This could be extended to filter based on a list of known
1169 * APs in the MD (if such a list were configured).
1171 if ((target_ap
[0] & 0x01) ||
1172 os_memcmp(target_ap
, sm
->wpa_auth
->addr
, ETH_ALEN
) == 0) {
1173 wpa_printf(MSG_DEBUG
, "FT: Invalid Target AP in FT Action "
1178 wpa_hexdump(MSG_MSGDUMP
, "FT: Action frame body", ies
, ies_len
);
1180 /* RRB - Forward action frame to the target AP */
1181 frame
= os_malloc(sizeof(*frame
) + len
);
1182 frame
->frame_type
= RSN_REMOTE_FRAME_TYPE_FT_RRB
;
1183 frame
->packet_type
= FT_PACKET_REQUEST
;
1184 frame
->action_length
= host_to_le16(len
);
1185 os_memcpy(frame
->ap_address
, sm
->wpa_auth
->addr
, ETH_ALEN
);
1186 os_memcpy(frame
+ 1, data
, len
);
1188 wpa_ft_rrb_send(sm
->wpa_auth
, target_ap
, (u8
*) frame
,
1189 sizeof(*frame
) + len
);
1196 static int wpa_ft_rrb_rx_request(struct wpa_authenticator
*wpa_auth
,
1197 const u8
*current_ap
, const u8
*sta_addr
,
1198 const u8
*body
, size_t len
)
1200 struct wpa_state_machine
*sm
;
1203 size_t resp_ies_len
, rlen
;
1204 struct ft_rrb_frame
*frame
;
1206 sm
= wpa_ft_add_sta(wpa_auth
, sta_addr
);
1208 wpa_printf(MSG_DEBUG
, "FT: Failed to add new STA based on "
1213 wpa_hexdump(MSG_MSGDUMP
, "FT: RRB Request Frame body", body
, len
);
1215 status
= wpa_ft_process_auth_req(sm
, body
, len
, &resp_ies
,
1218 wpa_printf(MSG_DEBUG
, "FT: RRB authentication response: STA=" MACSTR
1219 " CurrentAP=" MACSTR
" status=%d",
1220 MAC2STR(sm
->addr
), MAC2STR(current_ap
), status
);
1221 wpa_hexdump(MSG_DEBUG
, "FT: Response IEs", resp_ies
, resp_ies_len
);
1223 /* RRB - Forward action frame response to the Current AP */
1226 * data: Category[1] Action[1] STA_Address[6] Target_AP_Address[6]
1227 * Status_Code[2] FT Request action frame body[variable]
1229 rlen
= 2 + 2 * ETH_ALEN
+ 2 + resp_ies_len
;
1231 frame
= os_malloc(sizeof(*frame
) + rlen
);
1232 frame
->frame_type
= RSN_REMOTE_FRAME_TYPE_FT_RRB
;
1233 frame
->packet_type
= FT_PACKET_RESPONSE
;
1234 frame
->action_length
= host_to_le16(rlen
);
1235 os_memcpy(frame
->ap_address
, wpa_auth
->addr
, ETH_ALEN
);
1236 pos
= (u8
*) (frame
+ 1);
1237 *pos
++ = WLAN_ACTION_FT
;
1238 *pos
++ = 2; /* Action: Response */
1239 os_memcpy(pos
, sta_addr
, ETH_ALEN
);
1241 os_memcpy(pos
, wpa_auth
->addr
, ETH_ALEN
);
1243 WPA_PUT_LE16(pos
, status
);
1246 os_memcpy(pos
, resp_ies
, resp_ies_len
);
1250 wpa_ft_rrb_send(wpa_auth
, current_ap
, (u8
*) frame
,
1251 sizeof(*frame
) + rlen
);
1258 static int wpa_ft_rrb_rx_pull(struct wpa_authenticator
*wpa_auth
,
1260 const u8
*data
, size_t data_len
)
1262 struct ft_r0kh_r1kh_pull_frame
*frame
, f
;
1263 struct ft_remote_r1kh
*r1kh
;
1264 struct ft_r0kh_r1kh_resp_frame resp
, r
;
1267 wpa_printf(MSG_DEBUG
, "FT: Received PMK-R1 pull");
1269 if (data_len
< sizeof(*frame
))
1272 r1kh
= wpa_auth
->conf
.r1kh_list
;
1274 if (os_memcmp(r1kh
->addr
, src_addr
, ETH_ALEN
) == 0)
1279 wpa_printf(MSG_DEBUG
, "FT: No matching R1KH address found for "
1280 "PMK-R1 pull source address " MACSTR
,
1285 frame
= (struct ft_r0kh_r1kh_pull_frame
*) data
;
1286 /* aes_unwrap() does not support inplace decryption, so use a temporary
1287 * buffer for the data. */
1288 if (aes_unwrap(r1kh
->key
, (FT_R0KH_R1KH_PULL_DATA_LEN
+ 7) / 8,
1289 frame
->nonce
, f
.nonce
) < 0) {
1290 wpa_printf(MSG_DEBUG
, "FT: Failed to decrypt PMK-R1 pull "
1291 "request from " MACSTR
, MAC2STR(src_addr
));
1295 wpa_hexdump(MSG_DEBUG
, "FT: PMK-R1 pull - nonce",
1296 f
.nonce
, sizeof(f
.nonce
));
1297 wpa_hexdump(MSG_DEBUG
, "FT: PMK-R1 pull - PMKR0Name",
1298 f
.pmk_r0_name
, WPA_PMK_NAME_LEN
);
1299 wpa_printf(MSG_DEBUG
, "FT: PMK-R1 pull - R1KH-ID=" MACSTR
"S1KH-ID="
1300 MACSTR
, MAC2STR(f
.r1kh_id
), MAC2STR(f
.s1kh_id
));
1302 os_memset(&resp
, 0, sizeof(resp
));
1303 resp
.frame_type
= RSN_REMOTE_FRAME_TYPE_FT_RRB
;
1304 resp
.packet_type
= FT_PACKET_R0KH_R1KH_RESP
;
1305 resp
.data_length
= host_to_le16(FT_R0KH_R1KH_RESP_DATA_LEN
);
1306 os_memcpy(resp
.ap_address
, wpa_auth
->addr
, ETH_ALEN
);
1308 /* aes_wrap() does not support inplace encryption, so use a temporary
1309 * buffer for the data. */
1310 os_memcpy(r
.nonce
, f
.nonce
, sizeof(f
.nonce
));
1311 os_memcpy(r
.r1kh_id
, f
.r1kh_id
, FT_R1KH_ID_LEN
);
1312 os_memcpy(r
.s1kh_id
, f
.s1kh_id
, ETH_ALEN
);
1313 if (wpa_ft_fetch_pmk_r0(wpa_auth
, f
.s1kh_id
, f
.pmk_r0_name
, pmk_r0
) <
1315 wpa_printf(MSG_DEBUG
, "FT: No matching PMKR0Name found for "
1320 wpa_derive_pmk_r1(pmk_r0
, f
.pmk_r0_name
, f
.r1kh_id
, f
.s1kh_id
,
1321 r
.pmk_r1
, r
.pmk_r1_name
);
1322 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1", r
.pmk_r1
, PMK_LEN
);
1323 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name", r
.pmk_r1_name
,
1326 if (aes_wrap(r1kh
->key
, (FT_R0KH_R1KH_RESP_DATA_LEN
+ 7) / 8,
1327 r
.nonce
, resp
.nonce
) < 0) {
1328 os_memset(pmk_r0
, 0, PMK_LEN
);
1332 os_memset(pmk_r0
, 0, PMK_LEN
);
1334 wpa_ft_rrb_send(wpa_auth
, src_addr
, (u8
*) &resp
, sizeof(resp
));
1340 static int wpa_ft_rrb_rx_resp(struct wpa_authenticator
*wpa_auth
,
1342 const u8
*data
, size_t data_len
)
1344 struct ft_r0kh_r1kh_resp_frame
*frame
, f
;
1345 struct ft_remote_r0kh
*r0kh
;
1347 wpa_printf(MSG_DEBUG
, "FT: Received PMK-R1 pull response");
1349 if (data_len
< sizeof(*frame
))
1352 r0kh
= wpa_auth
->conf
.r0kh_list
;
1354 if (os_memcmp(r0kh
->addr
, src_addr
, ETH_ALEN
) == 0)
1359 wpa_printf(MSG_DEBUG
, "FT: No matching R0KH address found for "
1360 "PMK-R0 pull response source address " MACSTR
,
1365 frame
= (struct ft_r0kh_r1kh_resp_frame
*) data
;
1366 /* aes_unwrap() does not support inplace decryption, so use a temporary
1367 * buffer for the data. */
1368 if (aes_unwrap(r0kh
->key
, (FT_R0KH_R1KH_RESP_DATA_LEN
+ 7) / 8,
1369 frame
->nonce
, f
.nonce
) < 0) {
1370 wpa_printf(MSG_DEBUG
, "FT: Failed to decrypt PMK-R1 pull "
1371 "response from " MACSTR
, MAC2STR(src_addr
));
1375 if (os_memcmp(f
.r1kh_id
, wpa_auth
->conf
.r1_key_holder
, FT_R1KH_ID_LEN
)
1377 wpa_printf(MSG_DEBUG
, "FT: PMK-R1 pull response did not use a "
1378 "matching R1KH-ID");
1382 /* TODO: verify that <nonce,s1kh_id> matches with a pending request
1383 * and call this requests callback function to finish request
1386 wpa_hexdump(MSG_DEBUG
, "FT: PMK-R1 pull - nonce",
1387 f
.nonce
, sizeof(f
.nonce
));
1388 wpa_printf(MSG_DEBUG
, "FT: PMK-R1 pull - R1KH-ID=" MACSTR
"S1KH-ID="
1389 MACSTR
, MAC2STR(f
.r1kh_id
), MAC2STR(f
.s1kh_id
));
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
);
1396 os_memset(f
.pmk_r1
, 0, PMK_LEN
);
1402 static int wpa_ft_rrb_rx_push(struct wpa_authenticator
*wpa_auth
,
1404 const u8
*data
, size_t data_len
)
1406 struct ft_r0kh_r1kh_push_frame
*frame
, f
;
1407 struct ft_remote_r0kh
*r0kh
;
1411 wpa_printf(MSG_DEBUG
, "FT: Received PMK-R1 push");
1413 if (data_len
< sizeof(*frame
))
1416 r0kh
= wpa_auth
->conf
.r0kh_list
;
1418 if (os_memcmp(r0kh
->addr
, src_addr
, ETH_ALEN
) == 0)
1423 wpa_printf(MSG_DEBUG
, "FT: No matching R0KH address found for "
1424 "PMK-R0 push source address " MACSTR
,
1429 frame
= (struct ft_r0kh_r1kh_push_frame
*) data
;
1430 /* aes_unwrap() does not support inplace decryption, so use a temporary
1431 * buffer for the data. */
1432 if (aes_unwrap(r0kh
->key
, (FT_R0KH_R1KH_PUSH_DATA_LEN
+ 7) / 8,
1433 frame
->timestamp
, f
.timestamp
) < 0) {
1434 wpa_printf(MSG_DEBUG
, "FT: Failed to decrypt PMK-R1 push from "
1435 MACSTR
, MAC2STR(src_addr
));
1440 tsend
= WPA_GET_LE32(f
.timestamp
);
1441 if ((now
.sec
> tsend
&& now
.sec
- tsend
> 60) ||
1442 (now
.sec
< tsend
&& tsend
- now
.sec
> 60)) {
1443 wpa_printf(MSG_DEBUG
, "FT: PMK-R1 push did not have a valid "
1444 "timestamp: sender time %d own time %d\n",
1445 (int) tsend
, (int) now
.sec
);
1449 if (os_memcmp(f
.r1kh_id
, wpa_auth
->conf
.r1_key_holder
, FT_R1KH_ID_LEN
)
1451 wpa_printf(MSG_DEBUG
, "FT: PMK-R1 push did not use a matching "
1452 "R1KH-ID (received " MACSTR
" own " MACSTR
")",
1454 MAC2STR(wpa_auth
->conf
.r1_key_holder
));
1458 wpa_printf(MSG_DEBUG
, "FT: PMK-R1 push - R1KH-ID=" MACSTR
" S1KH-ID="
1459 MACSTR
, MAC2STR(f
.r1kh_id
), MAC2STR(f
.s1kh_id
));
1460 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1 push - PMK-R1",
1462 wpa_hexdump(MSG_DEBUG
, "FT: PMK-R1 push - PMKR1Name",
1463 f
.pmk_r1_name
, WPA_PMK_NAME_LEN
);
1465 wpa_ft_store_pmk_r1(wpa_auth
, f
.s1kh_id
, f
.pmk_r1
, f
.pmk_r1_name
);
1466 os_memset(f
.pmk_r1
, 0, PMK_LEN
);
1472 int wpa_ft_rrb_rx(struct wpa_authenticator
*wpa_auth
, const u8
*src_addr
,
1473 const u8
*data
, size_t data_len
)
1475 struct ft_rrb_frame
*frame
;
1477 const u8
*pos
, *end
, *start
;
1479 const u8
*sta_addr
, *target_ap_addr
;
1481 wpa_printf(MSG_DEBUG
, "FT: RRB received frame from remote AP " MACSTR
,
1484 if (data_len
< sizeof(*frame
)) {
1485 wpa_printf(MSG_DEBUG
, "FT: Too short RRB frame (data_len=%lu)",
1486 (unsigned long) data_len
);
1491 frame
= (struct ft_rrb_frame
*) pos
;
1492 pos
+= sizeof(*frame
);
1494 alen
= le_to_host16(frame
->action_length
);
1495 wpa_printf(MSG_DEBUG
, "FT: RRB frame - frame_type=%d packet_type=%d "
1496 "action_length=%d ap_address=" MACSTR
,
1497 frame
->frame_type
, frame
->packet_type
, alen
,
1498 MAC2STR(frame
->ap_address
));
1500 if (frame
->frame_type
!= RSN_REMOTE_FRAME_TYPE_FT_RRB
) {
1501 /* Discard frame per IEEE Std 802.11r-2008, 11A.10.3 */
1502 wpa_printf(MSG_DEBUG
, "FT: RRB discarded frame with "
1503 "unrecognized type %d", frame
->frame_type
);
1507 if (alen
> data_len
- sizeof(*frame
)) {
1508 wpa_printf(MSG_DEBUG
, "FT: RRB frame too short for action "
1513 if (frame
->packet_type
== FT_PACKET_R0KH_R1KH_PULL
)
1514 return wpa_ft_rrb_rx_pull(wpa_auth
, src_addr
, data
, data_len
);
1515 if (frame
->packet_type
== FT_PACKET_R0KH_R1KH_RESP
)
1516 return wpa_ft_rrb_rx_resp(wpa_auth
, src_addr
, data
, data_len
);
1517 if (frame
->packet_type
== FT_PACKET_R0KH_R1KH_PUSH
)
1518 return wpa_ft_rrb_rx_push(wpa_auth
, src_addr
, data
, data_len
);
1520 wpa_hexdump(MSG_MSGDUMP
, "FT: RRB - FT Action frame", pos
, alen
);
1522 if (alen
< 1 + 1 + 2 * ETH_ALEN
) {
1523 wpa_printf(MSG_DEBUG
, "FT: Too short RRB frame (not enough "
1524 "room for Action Frame body); alen=%lu",
1525 (unsigned long) alen
);
1531 if (*pos
!= WLAN_ACTION_FT
) {
1532 wpa_printf(MSG_DEBUG
, "FT: Unexpected Action frame category "
1541 target_ap_addr
= pos
;
1543 wpa_printf(MSG_DEBUG
, "FT: RRB Action Frame: action=%d sta_addr="
1544 MACSTR
" target_ap_addr=" MACSTR
,
1545 action
, MAC2STR(sta_addr
), MAC2STR(target_ap_addr
));
1547 if (frame
->packet_type
== FT_PACKET_REQUEST
) {
1548 wpa_printf(MSG_DEBUG
, "FT: FT Packet Type - Request");
1551 wpa_printf(MSG_DEBUG
, "FT: Unexpected Action %d in "
1552 "RRB Request", action
);
1556 if (os_memcmp(target_ap_addr
, wpa_auth
->addr
, ETH_ALEN
) != 0) {
1557 wpa_printf(MSG_DEBUG
, "FT: Target AP address in the "
1558 "RRB Request does not match with own "
1563 if (wpa_ft_rrb_rx_request(wpa_auth
, frame
->ap_address
,
1564 sta_addr
, pos
, end
- pos
) < 0)
1566 } else if (frame
->packet_type
== FT_PACKET_RESPONSE
) {
1569 if (end
- pos
< 2) {
1570 wpa_printf(MSG_DEBUG
, "FT: Not enough room for status "
1571 "code in RRB Response");
1574 status_code
= WPA_GET_LE16(pos
);
1577 wpa_printf(MSG_DEBUG
, "FT: FT Packet Type - Response "
1578 "(status_code=%d)", status_code
);
1580 if (wpa_ft_action_send(wpa_auth
, sta_addr
, start
, alen
) < 0)
1583 wpa_printf(MSG_DEBUG
, "FT: RRB discarded frame with unknown "
1584 "packet_type %d", frame
->packet_type
);
1592 static void wpa_ft_generate_pmk_r1(struct wpa_authenticator
*wpa_auth
,
1593 struct wpa_ft_pmk_r0_sa
*pmk_r0
,
1594 struct ft_remote_r1kh
*r1kh
,
1597 struct ft_r0kh_r1kh_push_frame frame
, f
;
1600 os_memset(&frame
, 0, sizeof(frame
));
1601 frame
.frame_type
= RSN_REMOTE_FRAME_TYPE_FT_RRB
;
1602 frame
.packet_type
= FT_PACKET_R0KH_R1KH_PUSH
;
1603 frame
.data_length
= host_to_le16(FT_R0KH_R1KH_PUSH_DATA_LEN
);
1604 os_memcpy(frame
.ap_address
, wpa_auth
->addr
, ETH_ALEN
);
1606 /* aes_wrap() does not support inplace encryption, so use a temporary
1607 * buffer for the data. */
1608 os_memcpy(f
.r1kh_id
, r1kh
->id
, FT_R1KH_ID_LEN
);
1609 os_memcpy(f
.s1kh_id
, s1kh_id
, ETH_ALEN
);
1610 os_memcpy(f
.pmk_r0_name
, pmk_r0
->pmk_r0_name
, WPA_PMK_NAME_LEN
);
1611 wpa_derive_pmk_r1(pmk_r0
->pmk_r0
, pmk_r0
->pmk_r0_name
, r1kh
->id
,
1612 s1kh_id
, f
.pmk_r1
, f
.pmk_r1_name
);
1613 wpa_printf(MSG_DEBUG
, "FT: R1KH-ID " MACSTR
, MAC2STR(r1kh
->id
));
1614 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1", f
.pmk_r1
, PMK_LEN
);
1615 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name", f
.pmk_r1_name
,
1618 WPA_PUT_LE32(f
.timestamp
, now
.sec
);
1619 if (aes_wrap(r1kh
->key
, (FT_R0KH_R1KH_PUSH_DATA_LEN
+ 7) / 8,
1620 f
.timestamp
, frame
.timestamp
) < 0)
1623 wpa_ft_rrb_send(wpa_auth
, r1kh
->addr
, (u8
*) &frame
, sizeof(frame
));
1627 void wpa_ft_push_pmk_r1(struct wpa_authenticator
*wpa_auth
, const u8
*addr
)
1629 struct wpa_ft_pmk_r0_sa
*r0
;
1630 struct ft_remote_r1kh
*r1kh
;
1632 if (!wpa_auth
->conf
.pmk_r1_push
)
1635 r0
= wpa_auth
->ft_pmk_cache
->pmk_r0
;
1637 if (os_memcmp(r0
->spa
, addr
, ETH_ALEN
) == 0)
1642 if (r0
== NULL
|| r0
->pmk_r1_pushed
)
1644 r0
->pmk_r1_pushed
= 1;
1646 wpa_printf(MSG_DEBUG
, "FT: Deriving and pushing PMK-R1 keys to R1KHs "
1647 "for STA " MACSTR
, MAC2STR(addr
));
1649 r1kh
= wpa_auth
->conf
.r1kh_list
;
1651 wpa_ft_generate_pmk_r1(wpa_auth
, r0
, r1kh
, addr
);
1656 #endif /* CONFIG_IEEE80211R */