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.
21 #include "ieee802_11.h"
24 #include "wpa_auth_i.h"
25 #include "wpa_auth_ie.h"
28 #ifdef CONFIG_IEEE80211R
48 static int wpa_ft_parse_ies(const u8 *ies, size_t ies_len,
49 struct wpa_ft_ies *parse);
52 static int wpa_ft_rrb_send(struct wpa_authenticator *wpa_auth, const u8 *dst,
53 const u8 *data, size_t data_len)
55 if (wpa_auth->cb.send_ether == NULL)
57 return wpa_auth->cb.send_ether(wpa_auth->cb.ctx, dst, ETH_P_RRB,
62 static int wpa_ft_action_send(struct wpa_authenticator *wpa_auth,
63 const u8 *dst, const u8 *data, size_t data_len)
65 if (wpa_auth->cb.send_ft_action == NULL)
67 return wpa_auth->cb.send_ft_action(wpa_auth->cb.ctx, dst,
72 static struct wpa_state_machine *
73 wpa_ft_add_sta(struct wpa_authenticator *wpa_auth, const u8 *sta_addr)
75 if (wpa_auth->cb.add_sta == NULL)
77 return wpa_auth->cb.add_sta(wpa_auth->cb.ctx, sta_addr);
81 int wpa_write_mdie(struct wpa_auth_config *conf, u8 *buf, size_t len)
85 if (len < 2 + sizeof(struct rsn_mdie))
88 *pos++ = WLAN_EID_MOBILITY_DOMAIN;
89 *pos++ = MOBILITY_DOMAIN_ID_LEN + 1;
90 os_memcpy(pos, conf->mobility_domain, MOBILITY_DOMAIN_ID_LEN);
91 pos += MOBILITY_DOMAIN_ID_LEN;
92 capab = RSN_FT_CAPAB_FT_OVER_DS;
99 static int wpa_write_ftie(struct wpa_auth_config *conf, const u8 *r0kh_id,
101 const u8 *anonce, const u8 *snonce,
102 u8 *buf, size_t len, const u8 *subelem,
105 u8 *pos = buf, *ielen;
106 struct rsn_ftie *hdr;
108 if (len < 2 + sizeof(*hdr) + 2 + FT_R1KH_ID_LEN + 2 + r0kh_id_len +
112 *pos++ = WLAN_EID_FAST_BSS_TRANSITION;
115 hdr = (struct rsn_ftie *) pos;
116 os_memset(hdr, 0, sizeof(*hdr));
118 WPA_PUT_LE16(hdr->mic_control, 0);
120 os_memcpy(hdr->anonce, anonce, WPA_NONCE_LEN);
122 os_memcpy(hdr->snonce, snonce, WPA_NONCE_LEN);
124 /* Optional Parameters */
125 *pos++ = FTIE_SUBELEM_R1KH_ID;
126 *pos++ = FT_R1KH_ID_LEN;
127 os_memcpy(pos, conf->r1_key_holder, FT_R1KH_ID_LEN);
128 pos += FT_R1KH_ID_LEN;
131 *pos++ = FTIE_SUBELEM_R0KH_ID;
132 *pos++ = r0kh_id_len;
133 os_memcpy(pos, r0kh_id, r0kh_id_len);
138 os_memcpy(pos, subelem, subelem_len);
142 *ielen = pos - buf - 2;
148 struct wpa_ft_pmk_r0_sa {
149 struct wpa_ft_pmk_r0_sa *next;
151 u8 pmk_r0_name[WPA_PMK_NAME_LEN];
153 /* TODO: expiration, identity, radius_class, EAP type, VLAN ID */
157 struct wpa_ft_pmk_r1_sa {
158 struct wpa_ft_pmk_r1_sa *next;
160 u8 pmk_r1_name[WPA_PMK_NAME_LEN];
162 /* TODO: expiration, identity, radius_class, EAP type, VLAN ID */
165 struct wpa_ft_pmk_cache {
166 struct wpa_ft_pmk_r0_sa *pmk_r0;
167 struct wpa_ft_pmk_r1_sa *pmk_r1;
170 struct wpa_ft_pmk_cache * wpa_ft_pmk_cache_init(void)
172 struct wpa_ft_pmk_cache *cache;
174 cache = os_zalloc(sizeof(*cache));
180 void wpa_ft_pmk_cache_deinit(struct wpa_ft_pmk_cache *cache)
182 struct wpa_ft_pmk_r0_sa *r0, *r0prev;
183 struct wpa_ft_pmk_r1_sa *r1, *r1prev;
189 os_memset(r0prev->pmk_r0, 0, PMK_LEN);
197 os_memset(r1prev->pmk_r1, 0, PMK_LEN);
205 static int wpa_ft_store_pmk_r0(struct wpa_authenticator *wpa_auth,
206 const u8 *spa, const u8 *pmk_r0,
207 const u8 *pmk_r0_name)
209 struct wpa_ft_pmk_cache *cache = wpa_auth->ft_pmk_cache;
210 struct wpa_ft_pmk_r0_sa *r0;
212 /* TODO: add expiration and limit on number of entries in cache */
214 r0 = os_zalloc(sizeof(*r0));
218 os_memcpy(r0->pmk_r0, pmk_r0, PMK_LEN);
219 os_memcpy(r0->pmk_r0_name, pmk_r0_name, WPA_PMK_NAME_LEN);
220 os_memcpy(r0->spa, spa, ETH_ALEN);
222 r0->next = cache->pmk_r0;
229 static int wpa_ft_fetch_pmk_r0(struct wpa_authenticator *wpa_auth,
230 const u8 *spa, const u8 *pmk_r0_name,
233 struct wpa_ft_pmk_cache *cache = wpa_auth->ft_pmk_cache;
234 struct wpa_ft_pmk_r0_sa *r0;
238 if (os_memcmp(r0->spa, spa, ETH_ALEN) == 0 &&
239 os_memcmp(r0->pmk_r0_name, pmk_r0_name, WPA_PMK_NAME_LEN)
241 os_memcpy(pmk_r0, r0->pmk_r0, PMK_LEN);
252 static int wpa_ft_store_pmk_r1(struct wpa_authenticator *wpa_auth,
253 const u8 *spa, const u8 *pmk_r1,
254 const u8 *pmk_r1_name)
256 struct wpa_ft_pmk_cache *cache = wpa_auth->ft_pmk_cache;
257 struct wpa_ft_pmk_r1_sa *r1;
259 /* TODO: add expiration and limit on number of entries in cache */
261 r1 = os_zalloc(sizeof(*r1));
265 os_memcpy(r1->pmk_r1, pmk_r1, PMK_LEN);
266 os_memcpy(r1->pmk_r1_name, pmk_r1_name, WPA_PMK_NAME_LEN);
267 os_memcpy(r1->spa, spa, ETH_ALEN);
269 r1->next = cache->pmk_r1;
276 static int wpa_ft_fetch_pmk_r1(struct wpa_authenticator *wpa_auth,
277 const u8 *spa, const u8 *pmk_r1_name,
280 struct wpa_ft_pmk_cache *cache = wpa_auth->ft_pmk_cache;
281 struct wpa_ft_pmk_r1_sa *r1;
285 if (os_memcmp(r1->spa, spa, ETH_ALEN) == 0 &&
286 os_memcmp(r1->pmk_r1_name, pmk_r1_name, WPA_PMK_NAME_LEN)
288 os_memcpy(pmk_r1, r1->pmk_r1, PMK_LEN);
299 static int wpa_ft_pull_pmk_r1(struct wpa_authenticator *wpa_auth,
300 const u8 *s1kh_id, const u8 *r0kh_id,
301 size_t r0kh_id_len, const u8 *pmk_r0_name)
303 struct ft_remote_r0kh *r0kh;
304 struct ft_r0kh_r1kh_pull_frame frame, f;
306 r0kh = wpa_auth->conf.r0kh_list;
308 if (r0kh->id_len == r0kh_id_len &&
309 os_memcmp(r0kh->id, r0kh_id, r0kh_id_len) == 0)
316 wpa_printf(MSG_DEBUG, "FT: Send PMK-R1 pull request to remote R0KH "
317 "address " MACSTR, MAC2STR(r0kh->addr));
319 os_memset(&frame, 0, sizeof(frame));
320 frame.frame_type = RSN_REMOTE_FRAME_TYPE_FT_RRB;
321 frame.packet_type = FT_PACKET_R0KH_R1KH_PULL;
322 frame.data_length = host_to_le16(FT_R0KH_R1KH_PULL_DATA_LEN);
323 os_memcpy(frame.ap_address, wpa_auth->addr, ETH_ALEN);
325 /* aes_wrap() does not support inplace encryption, so use a temporary
326 * buffer for the data. */
327 if (os_get_random(f.nonce, sizeof(f.nonce))) {
328 wpa_printf(MSG_DEBUG, "FT: Failed to get random data for "
332 os_memcpy(f.pmk_r0_name, pmk_r0_name, WPA_PMK_NAME_LEN);
333 os_memcpy(f.r1kh_id, wpa_auth->conf.r1_key_holder, FT_R1KH_ID_LEN);
334 os_memcpy(f.s1kh_id, s1kh_id, ETH_ALEN);
336 if (aes_wrap(r0kh->key, (FT_R0KH_R1KH_PULL_DATA_LEN + 7) / 8,
337 f.nonce, frame.nonce) < 0)
340 wpa_ft_rrb_send(wpa_auth, r0kh->addr, (u8 *) &frame, sizeof(frame));
346 int wpa_auth_derive_ptk_ft(struct wpa_state_machine *sm, const u8 *pmk,
347 struct wpa_ptk *ptk, size_t ptk_len)
349 u8 pmk_r0[PMK_LEN], pmk_r0_name[WPA_PMK_NAME_LEN];
350 u8 pmk_r1[PMK_LEN], pmk_r1_name[WPA_PMK_NAME_LEN];
351 u8 ptk_name[WPA_PMK_NAME_LEN];
352 const u8 *mdid = sm->wpa_auth->conf.mobility_domain;
353 const u8 *r0kh = sm->wpa_auth->conf.r0_key_holder;
354 size_t r0kh_len = sm->wpa_auth->conf.r0_key_holder_len;
355 const u8 *r1kh = sm->wpa_auth->conf.r1_key_holder;
356 const u8 *ssid = sm->wpa_auth->conf.ssid;
357 size_t ssid_len = sm->wpa_auth->conf.ssid_len;
360 if (sm->xxkey_len == 0) {
361 wpa_printf(MSG_DEBUG, "FT: XXKey not available for key "
366 wpa_derive_pmk_r0(sm->xxkey, sm->xxkey_len, ssid, ssid_len, mdid,
367 r0kh, r0kh_len, sm->addr, pmk_r0, pmk_r0_name);
368 wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R0", pmk_r0, PMK_LEN);
369 wpa_hexdump(MSG_DEBUG, "FT: PMKR0Name", pmk_r0_name, WPA_PMK_NAME_LEN);
370 wpa_ft_store_pmk_r0(sm->wpa_auth, sm->addr, pmk_r0, pmk_r0_name);
372 wpa_derive_pmk_r1(pmk_r0, pmk_r0_name, r1kh, sm->addr,
373 pmk_r1, pmk_r1_name);
374 wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R1", pmk_r1, PMK_LEN);
375 wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name", pmk_r1_name, WPA_PMK_NAME_LEN);
376 wpa_ft_store_pmk_r1(sm->wpa_auth, sm->addr, pmk_r1, pmk_r1_name);
378 wpa_pmk_r1_to_ptk(pmk_r1, sm->SNonce, sm->ANonce, sm->addr,
379 sm->wpa_auth->addr, pmk_r1_name,
380 (u8 *) ptk, ptk_len, ptk_name);
381 wpa_hexdump_key(MSG_DEBUG, "FT: PTK", (u8 *) ptk, ptk_len);
382 wpa_hexdump(MSG_DEBUG, "FT: PTKName", ptk_name, WPA_PMK_NAME_LEN);
388 static inline int wpa_auth_get_seqnum(struct wpa_authenticator *wpa_auth,
389 const u8 *addr, int idx, u8 *seq)
391 if (wpa_auth->cb.get_seqnum == NULL)
393 return wpa_auth->cb.get_seqnum(wpa_auth->cb.ctx, addr, idx, seq);
397 #ifdef CONFIG_IEEE80211W
398 static inline int wpa_auth_get_seqnum_igtk(struct wpa_authenticator *wpa_auth,
399 const u8 *addr, int idx, u8 *seq)
401 if (wpa_auth->cb.get_seqnum_igtk == NULL)
403 return wpa_auth->cb.get_seqnum_igtk(wpa_auth->cb.ctx, addr, idx, seq);
405 #endif /* CONFIG_IEEE80211W */
408 static u8 * wpa_ft_gtk_subelem(struct wpa_state_machine *sm, size_t *len)
411 struct wpa_group *gsm = sm->group;
412 size_t subelem_len, pad_len;
417 key_len = gsm->GTK_len;
418 if (key_len > sizeof(keybuf))
422 * Pad key for AES Key Wrap if it is not multiple of 8 bytes or is less
425 pad_len = key_len % 8;
427 pad_len = 8 - pad_len;
428 if (key_len + pad_len < 16)
431 os_memcpy(keybuf, gsm->GTK[gsm->GN - 1], key_len);
432 os_memset(keybuf + key_len, 0, pad_len);
433 keybuf[key_len] = 0xdd;
437 key = gsm->GTK[gsm->GN - 1];
440 * Sub-elem ID[1] | Length[1] | Key Info[1] | Key Length[1] | RSC[8] |
443 subelem_len = 12 + key_len + 8;
444 subelem = os_zalloc(subelem_len);
448 subelem[0] = FTIE_SUBELEM_GTK;
449 subelem[1] = 10 + key_len + 8;
450 subelem[2] = gsm->GN & 0x03; /* Key ID in B0-B1 of Key Info */
451 subelem[3] = gsm->GTK_len;
452 wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN, subelem + 4);
453 if (aes_wrap(sm->PTK.kek, key_len / 8, key, subelem + 12)) {
463 #ifdef CONFIG_IEEE80211W
464 static u8 * wpa_ft_igtk_subelem(struct wpa_state_machine *sm, size_t *len)
467 struct wpa_group *gsm = sm->group;
470 /* Sub-elem ID[1] | Length[1] | KeyID[2] | IPN[6] | Key Length[1] |
472 subelem_len = 1 + 1 + 2 + 6 + 1 + WPA_IGTK_LEN + 8;
473 subelem = os_zalloc(subelem_len);
478 *pos++ = FTIE_SUBELEM_IGTK;
479 *pos++ = subelem_len - 2;
480 WPA_PUT_LE16(pos, gsm->GN_igtk);
482 wpa_auth_get_seqnum_igtk(sm->wpa_auth, NULL, gsm->GN_igtk, pos);
484 *pos++ = WPA_IGTK_LEN;
485 if (aes_wrap(sm->PTK.kek, WPA_IGTK_LEN / 8,
486 gsm->IGTK[gsm->GN_igtk - 4], pos)) {
494 #endif /* CONFIG_IEEE80211W */
497 static u8 * wpa_ft_process_rdie(u8 *pos, u8 *end, u8 id, u8 descr_count,
498 const u8 *ies, size_t ies_len)
500 struct ieee802_11_elems parse;
501 struct rsn_rdie *rdie;
503 wpa_printf(MSG_DEBUG, "FT: Resource Request: id=%d descr_count=%d",
505 wpa_hexdump(MSG_MSGDUMP, "FT: Resource descriptor IE(s)",
508 if (end - pos < (int) sizeof(*rdie)) {
509 wpa_printf(MSG_ERROR, "FT: Not enough room for response RDIE");
513 *pos++ = WLAN_EID_RIC_DATA;
514 *pos++ = sizeof(*rdie);
515 rdie = (struct rsn_rdie *) pos;
517 rdie->descr_count = 0;
518 rdie->status_code = host_to_le16(WLAN_STATUS_SUCCESS);
519 pos += sizeof(*rdie);
521 if (ieee802_11_parse_elems((u8 *) ies, ies_len, &parse, 1) ==
523 wpa_printf(MSG_DEBUG, "FT: Failed to parse request IEs");
525 host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE);
529 if (parse.wmm_tspec) {
530 struct wmm_tspec_element *tspec;
533 if (parse.wmm_tspec_len + 2 < (int) sizeof(*tspec)) {
534 wpa_printf(MSG_DEBUG, "FT: Too short WMM TSPEC IE "
535 "(%d)", (int) parse.wmm_tspec_len);
537 host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE);
540 if (end - pos < (int) sizeof(*tspec)) {
541 wpa_printf(MSG_ERROR, "FT: Not enough room for "
544 host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE);
547 tspec = (struct wmm_tspec_element *) pos;
548 os_memcpy(tspec, parse.wmm_tspec - 2, sizeof(*tspec));
549 res = wmm_process_tspec(tspec);
550 wpa_printf(MSG_DEBUG, "FT: ADDTS processing result: %d", res);
551 if (res == WMM_ADDTS_STATUS_INVALID_PARAMETERS)
553 host_to_le16(WLAN_STATUS_INVALID_PARAMETERS);
554 else if (res == WMM_ADDTS_STATUS_REFUSED)
556 host_to_le16(WLAN_STATUS_REQUEST_DECLINED);
558 /* TSPEC accepted; include updated TSPEC in response */
559 rdie->descr_count = 1;
560 pos += sizeof(*tspec);
565 wpa_printf(MSG_DEBUG, "FT: No supported resource requested");
566 rdie->status_code = host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE);
571 static u8 * wpa_ft_process_ric(u8 *pos, u8 *end, const u8 *ric, size_t ric_len)
573 const u8 *rpos, *start;
574 const struct rsn_rdie *rdie;
576 wpa_hexdump(MSG_MSGDUMP, "FT: RIC Request", ric, ric_len);
579 while (rpos + sizeof(*rdie) < ric + ric_len) {
580 if (rpos[0] != WLAN_EID_RIC_DATA || rpos[1] < sizeof(*rdie) ||
581 rpos + 2 + rpos[1] > ric + ric_len)
583 rdie = (const struct rsn_rdie *) (rpos + 2);
587 while (rpos + 2 <= ric + ric_len &&
588 rpos + 2 + rpos[1] <= ric + ric_len) {
589 if (rpos[0] == WLAN_EID_RIC_DATA)
593 pos = wpa_ft_process_rdie(pos, end, rdie->id,
595 start, rpos - start);
602 u8 * wpa_sm_write_assoc_resp_ies(struct wpa_state_machine *sm, u8 *pos,
603 size_t max_len, int auth_alg,
604 const u8 *req_ies, size_t req_ies_len)
606 u8 *end, *mdie, *ftie, *rsnie, *r0kh_id, *subelem = NULL;
607 size_t mdie_len, ftie_len, rsnie_len, r0kh_id_len, subelem_len = 0;
609 struct wpa_auth_config *conf;
610 struct rsn_ftie *_ftie;
611 struct wpa_ft_ies parse;
617 conf = &sm->wpa_auth->conf;
619 if (sm->wpa_key_mgmt != WPA_KEY_MGMT_FT_IEEE8021X &&
620 sm->wpa_key_mgmt != WPA_KEY_MGMT_FT_PSK)
626 res = wpa_write_rsn_ie(conf, pos, end - pos, sm->pmk_r1_name);
633 /* Mobility Domain Information */
634 res = wpa_write_mdie(conf, pos, end - pos);
641 /* Fast BSS Transition Information */
642 if (auth_alg == WLAN_AUTH_FT) {
643 subelem = wpa_ft_gtk_subelem(sm, &subelem_len);
644 r0kh_id = sm->r0kh_id;
645 r0kh_id_len = sm->r0kh_id_len;
646 #ifdef CONFIG_IEEE80211W
647 if (sm->mgmt_frame_prot) {
651 igtk = wpa_ft_igtk_subelem(sm, &igtk_len);
656 nbuf = os_realloc(subelem, subelem_len + igtk_len);
663 os_memcpy(subelem + subelem_len, igtk, igtk_len);
664 subelem_len += igtk_len;
667 #endif /* CONFIG_IEEE80211W */
669 r0kh_id = conf->r0_key_holder;
670 r0kh_id_len = conf->r0_key_holder_len;
672 res = wpa_write_ftie(conf, r0kh_id, r0kh_id_len, NULL, NULL, pos,
673 end - pos, subelem, subelem_len);
681 _ftie = (struct rsn_ftie *) (ftie + 2);
682 _ftie->mic_control[1] = 3; /* Information element count */
685 if (wpa_ft_parse_ies(req_ies, req_ies_len, &parse) == 0 && parse.ric) {
686 pos = wpa_ft_process_ric(pos, end, parse.ric, parse.ric_len);
687 _ftie->mic_control[1] += ieee802_11_ie_count(ric_start,
690 if (ric_start == pos)
693 if (wpa_ft_mic(sm->PTK.kck, sm->addr, sm->wpa_auth->addr, 6,
694 mdie, mdie_len, ftie, ftie_len,
696 ric_start, ric_start ? pos - ric_start : 0,
698 wpa_printf(MSG_DEBUG, "FT: Failed to calculate MIC");
704 static int wpa_ft_parse_ftie(const u8 *ie, size_t ie_len,
705 struct wpa_ft_ies *parse)
710 parse->ftie_len = ie_len;
712 pos = ie + sizeof(struct rsn_ftie);
715 while (pos + 2 <= end && pos + 2 + pos[1] <= end) {
717 case FTIE_SUBELEM_R1KH_ID:
718 if (pos[1] != FT_R1KH_ID_LEN) {
719 wpa_printf(MSG_DEBUG, "FT: Invalid R1KH-ID "
720 "length in FTIE: %d", pos[1]);
723 parse->r1kh_id = pos + 2;
725 case FTIE_SUBELEM_GTK:
726 parse->gtk = pos + 2;
727 parse->gtk_len = pos[1];
729 case FTIE_SUBELEM_R0KH_ID:
730 if (pos[1] < 1 || pos[1] > FT_R0KH_ID_MAX_LEN) {
731 wpa_printf(MSG_DEBUG, "FT: Invalid R0KH-ID "
732 "length in FTIE: %d", pos[1]);
735 parse->r0kh_id = pos + 2;
736 parse->r0kh_id_len = pos[1];
747 static int wpa_ft_parse_ies(const u8 *ies, size_t ies_len,
748 struct wpa_ft_ies *parse)
751 struct wpa_ie_data data;
753 const struct rsn_ftie *ftie;
754 int prot_ie_count = 0;
756 os_memset(parse, 0, sizeof(*parse));
762 while (pos + 2 <= end && pos + 2 + pos[1] <= end) {
765 parse->rsn = pos + 2;
766 parse->rsn_len = pos[1];
767 ret = wpa_parse_wpa_ie_rsn(parse->rsn - 2,
771 wpa_printf(MSG_DEBUG, "FT: Failed to parse "
775 if (data.num_pmkid == 1 && data.pmkid)
776 parse->rsn_pmkid = data.pmkid;
778 case WLAN_EID_MOBILITY_DOMAIN:
779 parse->mdie = pos + 2;
780 parse->mdie_len = pos[1];
782 case WLAN_EID_FAST_BSS_TRANSITION:
783 if (pos[1] < sizeof(*ftie))
785 ftie = (const struct rsn_ftie *) (pos + 2);
786 prot_ie_count = ftie->mic_control[1];
787 if (wpa_ft_parse_ftie(pos + 2, pos[1], parse) < 0)
790 case WLAN_EID_RIC_DATA:
791 if (parse->ric == NULL)
798 if (prot_ie_count == 0)
799 return 0; /* no MIC */
802 * Check that the protected IE count matches with IEs included in the
811 if (prot_ie_count < 0) {
812 wpa_printf(MSG_DEBUG, "FT: Some required IEs not included in "
813 "the protected IE count");
817 if (prot_ie_count == 0 && parse->ric) {
818 wpa_printf(MSG_DEBUG, "FT: RIC IE(s) in the frame, but not "
819 "included in protected IE count");
823 /* Determine the end of the RIC IE(s) */
825 while (pos && pos + 2 <= end && pos + 2 + pos[1] <= end &&
830 parse->ric_len = pos - parse->ric;
832 wpa_printf(MSG_DEBUG, "FT: %d protected IEs missing from "
833 "frame", (int) prot_ie_count);
841 static inline int wpa_auth_set_key(struct wpa_authenticator *wpa_auth,
843 wpa_alg alg, const u8 *addr, int idx,
844 u8 *key, size_t key_len)
846 if (wpa_auth->cb.set_key == NULL)
848 return wpa_auth->cb.set_key(wpa_auth->cb.ctx, vlan_id, alg, addr, idx,
853 static void wpa_ft_install_ptk(struct wpa_state_machine *sm)
858 /* MLME-SETKEYS.request(PTK) */
859 if (sm->pairwise == WPA_CIPHER_TKIP) {
862 } else if (sm->pairwise == WPA_CIPHER_CCMP) {
868 /* FIX: add STA entry to kernel/driver here? The set_key will fail
869 * most likely without this.. At the moment, STA entry is added only
870 * after association has been completed. Alternatively, could
871 * re-configure PTK at that point(?).
873 if (wpa_auth_set_key(sm->wpa_auth, 0, alg, sm->addr, 0,
877 /* FIX: MLME-SetProtection.Request(TA, Tx_Rx) */
878 sm->pairwise_set = TRUE;
882 static u16 wpa_ft_process_auth_req(struct wpa_state_machine *sm,
883 const u8 *ies, size_t ies_len,
884 u8 **resp_ies, size_t *resp_ies_len)
886 struct rsn_mdie *mdie;
887 struct rsn_ftie *ftie;
888 u8 pmk_r1[PMK_LEN], pmk_r1_name[WPA_PMK_NAME_LEN];
889 u8 ptk_name[WPA_PMK_NAME_LEN];
890 struct wpa_auth_config *conf;
891 struct wpa_ft_ies parse;
892 size_t buflen, ptk_len;
899 sm->pmk_r1_name_valid = 0;
900 conf = &sm->wpa_auth->conf;
902 wpa_hexdump(MSG_DEBUG, "FT: Received authentication frame IEs",
905 if (wpa_ft_parse_ies(ies, ies_len, &parse) < 0) {
906 wpa_printf(MSG_DEBUG, "FT: Failed to parse FT IEs");
907 return WLAN_STATUS_UNSPECIFIED_FAILURE;
910 mdie = (struct rsn_mdie *) parse.mdie;
911 if (mdie == NULL || parse.mdie_len < sizeof(*mdie) ||
912 os_memcmp(mdie->mobility_domain,
913 sm->wpa_auth->conf.mobility_domain,
914 MOBILITY_DOMAIN_ID_LEN) != 0) {
915 wpa_printf(MSG_DEBUG, "FT: Invalid MDIE");
916 return WLAN_STATUS_INVALID_MDIE;
919 ftie = (struct rsn_ftie *) parse.ftie;
920 if (ftie == NULL || parse.ftie_len < sizeof(*ftie)) {
921 wpa_printf(MSG_DEBUG, "FT: Invalid FTIE");
922 return WLAN_STATUS_INVALID_FTIE;
925 os_memcpy(sm->SNonce, ftie->snonce, WPA_NONCE_LEN);
927 if (parse.r0kh_id == NULL) {
928 wpa_printf(MSG_DEBUG, "FT: Invalid FTIE - no R0KH-ID");
929 return WLAN_STATUS_INVALID_FTIE;
932 wpa_hexdump(MSG_DEBUG, "FT: STA R0KH-ID",
933 parse.r0kh_id, parse.r0kh_id_len);
934 os_memcpy(sm->r0kh_id, parse.r0kh_id, parse.r0kh_id_len);
935 sm->r0kh_id_len = parse.r0kh_id_len;
937 if (parse.rsn_pmkid == NULL) {
938 wpa_printf(MSG_DEBUG, "FT: No PMKID in RSNIE");
939 return WLAN_STATUS_INVALID_PMKID;
942 wpa_hexdump(MSG_DEBUG, "FT: Requested PMKR0Name",
943 parse.rsn_pmkid, WPA_PMK_NAME_LEN);
944 wpa_derive_pmk_r1_name(parse.rsn_pmkid,
945 sm->wpa_auth->conf.r1_key_holder, sm->addr,
947 wpa_hexdump(MSG_DEBUG, "FT: Derived requested PMKR1Name",
948 pmk_r1_name, WPA_PMK_NAME_LEN);
950 if (wpa_ft_fetch_pmk_r1(sm->wpa_auth, sm->addr, pmk_r1_name, pmk_r1) <
952 if (wpa_ft_pull_pmk_r1(sm->wpa_auth, sm->addr, sm->r0kh_id,
953 sm->r0kh_id_len, parse.rsn_pmkid) < 0) {
954 wpa_printf(MSG_DEBUG, "FT: Did not have matching "
955 "PMK-R1 and unknown R0KH-ID");
956 return WLAN_STATUS_INVALID_PMKID;
960 * TODO: Should return "status pending" (and the caller should
961 * not send out response now). The real response will be sent
962 * once the response from R0KH is received.
964 return WLAN_STATUS_INVALID_PMKID;
967 wpa_hexdump_key(MSG_DEBUG, "FT: Selected PMK-R1", pmk_r1, PMK_LEN);
968 sm->pmk_r1_name_valid = 1;
969 os_memcpy(sm->pmk_r1_name, pmk_r1_name, WPA_PMK_NAME_LEN);
971 if (os_get_random(sm->ANonce, WPA_NONCE_LEN)) {
972 wpa_printf(MSG_DEBUG, "FT: Failed to get random data for "
974 return WLAN_STATUS_UNSPECIFIED_FAILURE;
977 wpa_hexdump(MSG_DEBUG, "FT: Received SNonce",
978 sm->SNonce, WPA_NONCE_LEN);
979 wpa_hexdump(MSG_DEBUG, "FT: Generated ANonce",
980 sm->ANonce, WPA_NONCE_LEN);
982 ptk_len = sm->pairwise == WPA_CIPHER_CCMP ? 48 : 64;
983 wpa_pmk_r1_to_ptk(pmk_r1, sm->SNonce, sm->ANonce, sm->addr,
984 sm->wpa_auth->addr, pmk_r1_name,
985 (u8 *) &sm->PTK, ptk_len, ptk_name);
986 wpa_hexdump_key(MSG_DEBUG, "FT: PTK",
987 (u8 *) &sm->PTK, ptk_len);
988 wpa_hexdump(MSG_DEBUG, "FT: PTKName", ptk_name, WPA_PMK_NAME_LEN);
990 wpa_ft_install_ptk(sm);
992 buflen = 2 + sizeof(struct rsn_mdie) + 2 + sizeof(struct rsn_ftie) +
993 2 + FT_R1KH_ID_LEN + 200;
994 *resp_ies = os_zalloc(buflen);
995 if (*resp_ies == NULL) {
996 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1000 end = *resp_ies + buflen;
1002 ret = wpa_write_rsn_ie(conf, pos, end - pos, parse.rsn_pmkid);
1006 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1010 ret = wpa_write_mdie(conf, pos, end - pos);
1014 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1018 ret = wpa_write_ftie(conf, parse.r0kh_id, parse.r0kh_id_len,
1019 sm->ANonce, sm->SNonce, pos, end - pos, NULL, 0);
1023 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1027 *resp_ies_len = pos - *resp_ies;
1029 return WLAN_STATUS_SUCCESS;
1033 void wpa_ft_process_auth(struct wpa_state_machine *sm, const u8 *bssid,
1034 u16 auth_transaction, const u8 *ies, size_t ies_len,
1035 void (*cb)(void *ctx, const u8 *dst, const u8 *bssid,
1036 u16 auth_transaction, u16 status,
1037 const u8 *ies, size_t ies_len),
1042 size_t resp_ies_len;
1045 wpa_printf(MSG_DEBUG, "FT: Received authentication frame, but "
1046 "WPA SM not available");
1050 wpa_printf(MSG_DEBUG, "FT: Received authentication frame: STA=" MACSTR
1051 " BSSID=" MACSTR " transaction=%d",
1052 MAC2STR(sm->addr), MAC2STR(bssid), auth_transaction);
1053 status = wpa_ft_process_auth_req(sm, ies, ies_len, &resp_ies,
1056 wpa_printf(MSG_DEBUG, "FT: FT authentication response: dst=" MACSTR
1057 " auth_transaction=%d status=%d",
1058 MAC2STR(sm->addr), auth_transaction + 1, status);
1059 wpa_hexdump(MSG_DEBUG, "FT: Response IEs", resp_ies, resp_ies_len);
1060 cb(ctx, sm->addr, bssid, auth_transaction + 1, status,
1061 resp_ies, resp_ies_len);
1066 u16 wpa_ft_validate_reassoc(struct wpa_state_machine *sm, const u8 *ies,
1069 struct wpa_ft_ies parse;
1070 struct rsn_mdie *mdie;
1071 struct rsn_ftie *ftie;
1075 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1077 wpa_hexdump(MSG_DEBUG, "FT: Reassoc Req IEs", ies, ies_len);
1079 if (wpa_ft_parse_ies(ies, ies_len, &parse) < 0) {
1080 wpa_printf(MSG_DEBUG, "FT: Failed to parse FT IEs");
1081 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1084 if (parse.rsn == NULL) {
1085 wpa_printf(MSG_DEBUG, "FT: No RSNIE in Reassoc Req");
1086 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1089 if (parse.rsn_pmkid == NULL) {
1090 wpa_printf(MSG_DEBUG, "FT: No PMKID in RSNIE");
1091 return WLAN_STATUS_INVALID_PMKID;
1094 if (os_memcmp(parse.rsn_pmkid, sm->pmk_r1_name, WPA_PMK_NAME_LEN) != 0)
1096 wpa_printf(MSG_DEBUG, "FT: PMKID in Reassoc Req did not match "
1097 "with the PMKR1Name derived from auth request");
1098 return WLAN_STATUS_INVALID_PMKID;
1101 mdie = (struct rsn_mdie *) parse.mdie;
1102 if (mdie == NULL || parse.mdie_len < sizeof(*mdie) ||
1103 os_memcmp(mdie->mobility_domain,
1104 sm->wpa_auth->conf.mobility_domain,
1105 MOBILITY_DOMAIN_ID_LEN) != 0) {
1106 wpa_printf(MSG_DEBUG, "FT: Invalid MDIE");
1107 return WLAN_STATUS_INVALID_MDIE;
1110 ftie = (struct rsn_ftie *) parse.ftie;
1111 if (ftie == NULL || parse.ftie_len < sizeof(*ftie)) {
1112 wpa_printf(MSG_DEBUG, "FT: Invalid FTIE");
1113 return WLAN_STATUS_INVALID_FTIE;
1116 if (wpa_ft_mic(sm->PTK.kck, sm->addr, sm->wpa_auth->addr, 5,
1117 parse.mdie - 2, parse.mdie_len + 2,
1118 parse.ftie - 2, parse.ftie_len + 2,
1119 parse.rsn - 2, parse.rsn_len + 2,
1120 parse.ric, parse.ric_len,
1122 wpa_printf(MSG_DEBUG, "FT: Failed to calculate MIC");
1123 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1126 if (os_memcmp(mic, ftie->mic, 16) != 0) {
1127 wpa_printf(MSG_DEBUG, "FT: Invalid MIC in FTIE");
1128 wpa_hexdump(MSG_MSGDUMP, "FT: Received MIC", ftie->mic, 16);
1129 wpa_hexdump(MSG_MSGDUMP, "FT: Calculated MIC", mic, 16);
1130 return WLAN_STATUS_INVALID_FTIE;
1133 return WLAN_STATUS_SUCCESS;
1137 int wpa_ft_action_rx(struct wpa_state_machine *sm, const u8 *data, size_t len)
1139 const u8 *sta_addr, *target_ap;
1143 struct ft_rrb_frame *frame;
1149 * data: Category[1] Action[1] STA_Address[6] Target_AP_Address[6]
1150 * FT Request action frame body[variable]
1154 wpa_printf(MSG_DEBUG, "FT: Too short FT Action frame "
1155 "(len=%lu)", (unsigned long) len);
1160 sta_addr = data + 2;
1161 target_ap = data + 8;
1165 wpa_printf(MSG_DEBUG, "FT: Received FT Action frame (STA=" MACSTR
1166 " Target AP=" MACSTR " Action=%d)",
1167 MAC2STR(sta_addr), MAC2STR(target_ap), action);
1169 if (os_memcmp(sta_addr, sm->addr, ETH_ALEN) != 0) {
1170 wpa_printf(MSG_DEBUG, "FT: Mismatch in FT Action STA address: "
1171 "STA=" MACSTR " STA-Address=" MACSTR,
1172 MAC2STR(sm->addr), MAC2STR(sta_addr));
1177 * Do some sanity checking on the target AP address (not own and not
1178 * broadcast. This could be extended to filter based on a list of known
1179 * APs in the MD (if such a list were configured).
1181 if ((target_ap[0] & 0x01) ||
1182 os_memcmp(target_ap, sm->wpa_auth->addr, ETH_ALEN) == 0) {
1183 wpa_printf(MSG_DEBUG, "FT: Invalid Target AP in FT Action "
1188 wpa_hexdump(MSG_MSGDUMP, "FT: Action frame body", ies, ies_len);
1190 /* RRB - Forward action frame to the target AP */
1191 frame = os_malloc(sizeof(*frame) + len);
1192 frame->frame_type = RSN_REMOTE_FRAME_TYPE_FT_RRB;
1193 frame->packet_type = FT_PACKET_REQUEST;
1194 frame->action_length = host_to_le16(len);
1195 os_memcpy(frame->ap_address, sm->wpa_auth->addr, ETH_ALEN);
1196 os_memcpy(frame + 1, data, len);
1198 wpa_ft_rrb_send(sm->wpa_auth, target_ap, (u8 *) frame,
1199 sizeof(*frame) + len);
1206 static int wpa_ft_rrb_rx_request(struct wpa_authenticator *wpa_auth,
1207 const u8 *current_ap, const u8 *sta_addr,
1208 const u8 *body, size_t len)
1210 struct wpa_state_machine *sm;
1213 size_t resp_ies_len, rlen;
1214 struct ft_rrb_frame *frame;
1216 sm = wpa_ft_add_sta(wpa_auth, sta_addr);
1218 wpa_printf(MSG_DEBUG, "FT: Failed to add new STA based on "
1223 wpa_hexdump(MSG_MSGDUMP, "FT: RRB Request Frame body", body, len);
1225 status = wpa_ft_process_auth_req(sm, body, len, &resp_ies,
1228 wpa_printf(MSG_DEBUG, "FT: RRB authentication response: STA=" MACSTR
1229 " CurrentAP=" MACSTR " status=%d",
1230 MAC2STR(sm->addr), MAC2STR(current_ap), status);
1231 wpa_hexdump(MSG_DEBUG, "FT: Response IEs", resp_ies, resp_ies_len);
1233 /* RRB - Forward action frame response to the Current AP */
1236 * data: Category[1] Action[1] STA_Address[6] Target_AP_Address[6]
1237 * Status_Code[2] FT Request action frame body[variable]
1239 rlen = 2 + 2 * ETH_ALEN + 2 + resp_ies_len;
1241 frame = os_malloc(sizeof(*frame) + rlen);
1242 frame->frame_type = RSN_REMOTE_FRAME_TYPE_FT_RRB;
1243 frame->packet_type = FT_PACKET_RESPONSE;
1244 frame->action_length = host_to_le16(rlen);
1245 os_memcpy(frame->ap_address, wpa_auth->addr, ETH_ALEN);
1246 pos = (u8 *) (frame + 1);
1247 *pos++ = WLAN_ACTION_FT;
1248 *pos++ = 2; /* Action: Response */
1249 os_memcpy(pos, sta_addr, ETH_ALEN);
1251 os_memcpy(pos, wpa_auth->addr, ETH_ALEN);
1253 WPA_PUT_LE16(pos, status);
1256 os_memcpy(pos, resp_ies, resp_ies_len);
1260 wpa_ft_rrb_send(wpa_auth, current_ap, (u8 *) frame,
1261 sizeof(*frame) + rlen);
1268 static int wpa_ft_rrb_rx_pull(struct wpa_authenticator *wpa_auth,
1270 const u8 *data, size_t data_len)
1272 struct ft_r0kh_r1kh_pull_frame *frame, f;
1273 struct ft_remote_r1kh *r1kh;
1274 struct ft_r0kh_r1kh_resp_frame resp, r;
1277 wpa_printf(MSG_DEBUG, "FT: Received PMK-R1 pull");
1279 if (data_len < sizeof(*frame))
1282 r1kh = wpa_auth->conf.r1kh_list;
1284 if (os_memcmp(r1kh->addr, src_addr, ETH_ALEN) == 0)
1289 wpa_printf(MSG_DEBUG, "FT: No matching R1KH address found for "
1290 "PMK-R1 pull source address " MACSTR,
1295 frame = (struct ft_r0kh_r1kh_pull_frame *) data;
1296 /* aes_unwrap() does not support inplace decryption, so use a temporary
1297 * buffer for the data. */
1298 if (aes_unwrap(r1kh->key, (FT_R0KH_R1KH_PULL_DATA_LEN + 7) / 8,
1299 frame->nonce, f.nonce) < 0) {
1300 wpa_printf(MSG_DEBUG, "FT: Failed to decrypt PMK-R1 pull "
1301 "request from " MACSTR, MAC2STR(src_addr));
1305 wpa_hexdump(MSG_DEBUG, "FT: PMK-R1 pull - nonce",
1306 f.nonce, sizeof(f.nonce));
1307 wpa_hexdump(MSG_DEBUG, "FT: PMK-R1 pull - PMKR0Name",
1308 f.pmk_r0_name, WPA_PMK_NAME_LEN);
1309 wpa_printf(MSG_DEBUG, "FT: PMK-R1 pull - R1KH-ID=" MACSTR "S1KH-ID="
1310 MACSTR, MAC2STR(f.r1kh_id), MAC2STR(f.s1kh_id));
1312 os_memset(&resp, 0, sizeof(resp));
1313 resp.frame_type = RSN_REMOTE_FRAME_TYPE_FT_RRB;
1314 resp.packet_type = FT_PACKET_R0KH_R1KH_RESP;
1315 resp.data_length = host_to_le16(FT_R0KH_R1KH_RESP_DATA_LEN);
1316 os_memcpy(resp.ap_address, wpa_auth->addr, ETH_ALEN);
1318 /* aes_wrap() does not support inplace encryption, so use a temporary
1319 * buffer for the data. */
1320 os_memcpy(r.nonce, f.nonce, sizeof(f.nonce));
1321 os_memcpy(r.r1kh_id, f.r1kh_id, FT_R1KH_ID_LEN);
1322 os_memcpy(r.s1kh_id, f.s1kh_id, ETH_ALEN);
1323 if (wpa_ft_fetch_pmk_r0(wpa_auth, f.s1kh_id, f.pmk_r0_name, pmk_r0) <
1325 wpa_printf(MSG_DEBUG, "FT: No matching PMKR0Name found for "
1330 wpa_derive_pmk_r1(pmk_r0, f.pmk_r0_name, f.r1kh_id, f.s1kh_id,
1331 r.pmk_r1, r.pmk_r1_name);
1332 wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R1", r.pmk_r1, PMK_LEN);
1333 wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name", r.pmk_r1_name,
1336 if (aes_wrap(r1kh->key, (FT_R0KH_R1KH_RESP_DATA_LEN + 7) / 8,
1337 r.nonce, resp.nonce) < 0) {
1338 os_memset(pmk_r0, 0, PMK_LEN);
1342 os_memset(pmk_r0, 0, PMK_LEN);
1344 wpa_ft_rrb_send(wpa_auth, src_addr, (u8 *) &resp, sizeof(resp));
1350 static int wpa_ft_rrb_rx_resp(struct wpa_authenticator *wpa_auth,
1352 const u8 *data, size_t data_len)
1354 struct ft_r0kh_r1kh_resp_frame *frame, f;
1355 struct ft_remote_r0kh *r0kh;
1357 wpa_printf(MSG_DEBUG, "FT: Received PMK-R1 pull response");
1359 if (data_len < sizeof(*frame))
1362 r0kh = wpa_auth->conf.r0kh_list;
1364 if (os_memcmp(r0kh->addr, src_addr, ETH_ALEN) == 0)
1369 wpa_printf(MSG_DEBUG, "FT: No matching R0KH address found for "
1370 "PMK-R0 pull response source address " MACSTR,
1375 frame = (struct ft_r0kh_r1kh_resp_frame *) data;
1376 /* aes_unwrap() does not support inplace decryption, so use a temporary
1377 * buffer for the data. */
1378 if (aes_unwrap(r0kh->key, (FT_R0KH_R1KH_RESP_DATA_LEN + 7) / 8,
1379 frame->nonce, f.nonce) < 0) {
1380 wpa_printf(MSG_DEBUG, "FT: Failed to decrypt PMK-R1 pull "
1381 "response from " MACSTR, MAC2STR(src_addr));
1385 if (os_memcmp(f.r1kh_id, wpa_auth->conf.r1_key_holder, FT_R1KH_ID_LEN)
1387 wpa_printf(MSG_DEBUG, "FT: PMK-R1 pull response did not use a "
1388 "matching R1KH-ID");
1392 /* TODO: verify that <nonce,s1kh_id> matches with a pending request
1393 * and call this requests callback function to finish request
1396 wpa_hexdump(MSG_DEBUG, "FT: PMK-R1 pull - nonce",
1397 f.nonce, sizeof(f.nonce));
1398 wpa_printf(MSG_DEBUG, "FT: PMK-R1 pull - R1KH-ID=" MACSTR "S1KH-ID="
1399 MACSTR, MAC2STR(f.r1kh_id), MAC2STR(f.s1kh_id));
1400 wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R1 pull - PMK-R1",
1402 wpa_hexdump(MSG_DEBUG, "FT: PMK-R1 pull - PMKR1Name",
1403 f.pmk_r1_name, WPA_PMK_NAME_LEN);
1405 wpa_ft_store_pmk_r1(wpa_auth, f.s1kh_id, f.pmk_r1, f.pmk_r1_name);
1406 os_memset(f.pmk_r1, 0, PMK_LEN);
1412 static int wpa_ft_rrb_rx_push(struct wpa_authenticator *wpa_auth,
1414 const u8 *data, size_t data_len)
1416 struct ft_r0kh_r1kh_push_frame *frame, f;
1417 struct ft_remote_r0kh *r0kh;
1421 wpa_printf(MSG_DEBUG, "FT: Received PMK-R1 push");
1423 if (data_len < sizeof(*frame))
1426 r0kh = wpa_auth->conf.r0kh_list;
1428 if (os_memcmp(r0kh->addr, src_addr, ETH_ALEN) == 0)
1433 wpa_printf(MSG_DEBUG, "FT: No matching R0KH address found for "
1434 "PMK-R0 push source address " MACSTR,
1439 frame = (struct ft_r0kh_r1kh_push_frame *) data;
1440 /* aes_unwrap() does not support inplace decryption, so use a temporary
1441 * buffer for the data. */
1442 if (aes_unwrap(r0kh->key, (FT_R0KH_R1KH_PUSH_DATA_LEN + 7) / 8,
1443 frame->timestamp, f.timestamp) < 0) {
1444 wpa_printf(MSG_DEBUG, "FT: Failed to decrypt PMK-R1 push from "
1445 MACSTR, MAC2STR(src_addr));
1450 tsend = WPA_GET_LE32(f.timestamp);
1451 if ((now.sec > tsend && now.sec - tsend > 60) ||
1452 (now.sec < tsend && tsend - now.sec > 60)) {
1453 wpa_printf(MSG_DEBUG, "FT: PMK-R1 push did not have a valid "
1454 "timestamp: sender time %d own time %d\n",
1455 (int) tsend, (int) now.sec);
1459 if (os_memcmp(f.r1kh_id, wpa_auth->conf.r1_key_holder, FT_R1KH_ID_LEN)
1461 wpa_printf(MSG_DEBUG, "FT: PMK-R1 push did not use a matching "
1462 "R1KH-ID (received " MACSTR " own " MACSTR ")",
1464 MAC2STR(wpa_auth->conf.r1_key_holder));
1468 wpa_printf(MSG_DEBUG, "FT: PMK-R1 push - R1KH-ID=" MACSTR " S1KH-ID="
1469 MACSTR, MAC2STR(f.r1kh_id), MAC2STR(f.s1kh_id));
1470 wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R1 push - PMK-R1",
1472 wpa_hexdump(MSG_DEBUG, "FT: PMK-R1 push - PMKR1Name",
1473 f.pmk_r1_name, WPA_PMK_NAME_LEN);
1475 wpa_ft_store_pmk_r1(wpa_auth, f.s1kh_id, f.pmk_r1, f.pmk_r1_name);
1476 os_memset(f.pmk_r1, 0, PMK_LEN);
1482 int wpa_ft_rrb_rx(struct wpa_authenticator *wpa_auth, const u8 *src_addr,
1483 const u8 *data, size_t data_len)
1485 struct ft_rrb_frame *frame;
1487 const u8 *pos, *end, *start;
1489 const u8 *sta_addr, *target_ap_addr;
1491 wpa_printf(MSG_DEBUG, "FT: RRB received frame from remote AP " MACSTR,
1494 if (data_len < sizeof(*frame)) {
1495 wpa_printf(MSG_DEBUG, "FT: Too short RRB frame (data_len=%lu)",
1496 (unsigned long) data_len);
1501 frame = (struct ft_rrb_frame *) pos;
1502 pos += sizeof(*frame);
1504 alen = le_to_host16(frame->action_length);
1505 wpa_printf(MSG_DEBUG, "FT: RRB frame - frame_type=%d packet_type=%d "
1506 "action_length=%d ap_address=" MACSTR,
1507 frame->frame_type, frame->packet_type, alen,
1508 MAC2STR(frame->ap_address));
1510 if (frame->frame_type != RSN_REMOTE_FRAME_TYPE_FT_RRB) {
1511 /* Discard frame per IEEE Std 802.11r-2008, 11A.10.3 */
1512 wpa_printf(MSG_DEBUG, "FT: RRB discarded frame with "
1513 "unrecognized type %d", frame->frame_type);
1517 if (alen > data_len - sizeof(*frame)) {
1518 wpa_printf(MSG_DEBUG, "FT: RRB frame too short for action "
1523 if (frame->packet_type == FT_PACKET_R0KH_R1KH_PULL)
1524 return wpa_ft_rrb_rx_pull(wpa_auth, src_addr, data, data_len);
1525 if (frame->packet_type == FT_PACKET_R0KH_R1KH_RESP)
1526 return wpa_ft_rrb_rx_resp(wpa_auth, src_addr, data, data_len);
1527 if (frame->packet_type == FT_PACKET_R0KH_R1KH_PUSH)
1528 return wpa_ft_rrb_rx_push(wpa_auth, src_addr, data, data_len);
1530 wpa_hexdump(MSG_MSGDUMP, "FT: RRB - FT Action frame", pos, alen);
1532 if (alen < 1 + 1 + 2 * ETH_ALEN) {
1533 wpa_printf(MSG_DEBUG, "FT: Too short RRB frame (not enough "
1534 "room for Action Frame body); alen=%lu",
1535 (unsigned long) alen);
1541 if (*pos != WLAN_ACTION_FT) {
1542 wpa_printf(MSG_DEBUG, "FT: Unexpected Action frame category "
1551 target_ap_addr = pos;
1553 wpa_printf(MSG_DEBUG, "FT: RRB Action Frame: action=%d sta_addr="
1554 MACSTR " target_ap_addr=" MACSTR,
1555 action, MAC2STR(sta_addr), MAC2STR(target_ap_addr));
1557 if (frame->packet_type == FT_PACKET_REQUEST) {
1558 wpa_printf(MSG_DEBUG, "FT: FT Packet Type - Request");
1561 wpa_printf(MSG_DEBUG, "FT: Unexpected Action %d in "
1562 "RRB Request", action);
1566 if (os_memcmp(target_ap_addr, wpa_auth->addr, ETH_ALEN) != 0) {
1567 wpa_printf(MSG_DEBUG, "FT: Target AP address in the "
1568 "RRB Request does not match with own "
1573 if (wpa_ft_rrb_rx_request(wpa_auth, frame->ap_address,
1574 sta_addr, pos, end - pos) < 0)
1576 } else if (frame->packet_type == FT_PACKET_RESPONSE) {
1579 if (end - pos < 2) {
1580 wpa_printf(MSG_DEBUG, "FT: Not enough room for status "
1581 "code in RRB Response");
1584 status_code = WPA_GET_LE16(pos);
1587 wpa_printf(MSG_DEBUG, "FT: FT Packet Type - Response "
1588 "(status_code=%d)", status_code);
1590 if (wpa_ft_action_send(wpa_auth, sta_addr, start, alen) < 0)
1593 wpa_printf(MSG_DEBUG, "FT: RRB discarded frame with unknown "
1594 "packet_type %d", frame->packet_type);
1602 static void wpa_ft_generate_pmk_r1(struct wpa_authenticator *wpa_auth,
1603 struct wpa_ft_pmk_r0_sa *pmk_r0,
1604 struct ft_remote_r1kh *r1kh,
1607 struct ft_r0kh_r1kh_push_frame frame, f;
1610 os_memset(&frame, 0, sizeof(frame));
1611 frame.frame_type = RSN_REMOTE_FRAME_TYPE_FT_RRB;
1612 frame.packet_type = FT_PACKET_R0KH_R1KH_PUSH;
1613 frame.data_length = host_to_le16(FT_R0KH_R1KH_PUSH_DATA_LEN);
1614 os_memcpy(frame.ap_address, wpa_auth->addr, ETH_ALEN);
1616 /* aes_wrap() does not support inplace encryption, so use a temporary
1617 * buffer for the data. */
1618 os_memcpy(f.r1kh_id, r1kh->id, FT_R1KH_ID_LEN);
1619 os_memcpy(f.s1kh_id, s1kh_id, ETH_ALEN);
1620 os_memcpy(f.pmk_r0_name, pmk_r0->pmk_r0_name, WPA_PMK_NAME_LEN);
1621 wpa_derive_pmk_r1(pmk_r0->pmk_r0, pmk_r0->pmk_r0_name, r1kh->id,
1622 s1kh_id, f.pmk_r1, f.pmk_r1_name);
1623 wpa_printf(MSG_DEBUG, "FT: R1KH-ID " MACSTR, MAC2STR(r1kh->id));
1624 wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R1", f.pmk_r1, PMK_LEN);
1625 wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name", f.pmk_r1_name,
1628 WPA_PUT_LE32(f.timestamp, now.sec);
1629 if (aes_wrap(r1kh->key, (FT_R0KH_R1KH_PUSH_DATA_LEN + 7) / 8,
1630 f.timestamp, frame.timestamp) < 0)
1633 wpa_ft_rrb_send(wpa_auth, r1kh->addr, (u8 *) &frame, sizeof(frame));
1637 void wpa_ft_push_pmk_r1(struct wpa_authenticator *wpa_auth, const u8 *addr)
1639 struct wpa_ft_pmk_r0_sa *r0;
1640 struct ft_remote_r1kh *r1kh;
1642 if (!wpa_auth->conf.pmk_r1_push)
1645 r0 = wpa_auth->ft_pmk_cache->pmk_r0;
1647 if (os_memcmp(r0->spa, addr, ETH_ALEN) == 0)
1652 if (r0 == NULL || r0->pmk_r1_pushed)
1654 r0->pmk_r1_pushed = 1;
1656 wpa_printf(MSG_DEBUG, "FT: Deriving and pushing PMK-R1 keys to R1KHs "
1657 "for STA " MACSTR, MAC2STR(addr));
1659 r1kh = wpa_auth->conf.r1kh_list;
1661 wpa_ft_generate_pmk_r1(wpa_auth, r0, r1kh, addr);
1666 #endif /* CONFIG_IEEE80211R */