5d085c69eeeca771e5bd0f6fd2c02fc1265e000e
[libeap.git] / src / ap / wpa_auth_ft.c
1 /*
2  * hostapd - IEEE 802.11r - Fast BSS Transition
3  * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
4  *
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.
8  *
9  * Alternatively, this software may be distributed under the terms of BSD
10  * license.
11  *
12  * See README and COPYING for more details.
13  */
14
15 #include "utils/includes.h"
16
17 #include "utils/common.h"
18 #include "common/ieee802_11_defs.h"
19 #include "common/ieee802_11_common.h"
20 #include "crypto/aes_wrap.h"
21 #include "ap_config.h"
22 #include "ieee802_11.h"
23 #include "wmm.h"
24 #include "wpa_auth.h"
25 #include "wpa_auth_i.h"
26 #include "wpa_auth_ie.h"
27
28
29 #ifdef CONFIG_IEEE80211R
30
31 struct wpa_ft_ies {
32         const u8 *mdie;
33         size_t mdie_len;
34         const u8 *ftie;
35         size_t ftie_len;
36         const u8 *r1kh_id;
37         const u8 *gtk;
38         size_t gtk_len;
39         const u8 *r0kh_id;
40         size_t r0kh_id_len;
41         const u8 *rsn;
42         size_t rsn_len;
43         const u8 *rsn_pmkid;
44         const u8 *ric;
45         size_t ric_len;
46 };
47
48
49 static int wpa_ft_parse_ies(const u8 *ies, size_t ies_len,
50                             struct wpa_ft_ies *parse);
51
52
53 static int wpa_ft_rrb_send(struct wpa_authenticator *wpa_auth, const u8 *dst,
54                            const u8 *data, size_t data_len)
55 {
56         if (wpa_auth->cb.send_ether == NULL)
57                 return -1;
58         return wpa_auth->cb.send_ether(wpa_auth->cb.ctx, dst, ETH_P_RRB,
59                                        data, data_len);
60 }
61
62
63 static int wpa_ft_action_send(struct wpa_authenticator *wpa_auth,
64                               const u8 *dst, const u8 *data, size_t data_len)
65 {
66         if (wpa_auth->cb.send_ft_action == NULL)
67                 return -1;
68         return wpa_auth->cb.send_ft_action(wpa_auth->cb.ctx, dst,
69                                            data, data_len);
70 }
71
72
73 static struct wpa_state_machine *
74 wpa_ft_add_sta(struct wpa_authenticator *wpa_auth, const u8 *sta_addr)
75 {
76         if (wpa_auth->cb.add_sta == NULL)
77                 return NULL;
78         return wpa_auth->cb.add_sta(wpa_auth->cb.ctx, sta_addr);
79 }
80
81
82 int wpa_write_mdie(struct wpa_auth_config *conf, u8 *buf, size_t len)
83 {
84         u8 *pos = buf;
85         u8 capab;
86         if (len < 2 + sizeof(struct rsn_mdie))
87                 return -1;
88
89         *pos++ = WLAN_EID_MOBILITY_DOMAIN;
90         *pos++ = MOBILITY_DOMAIN_ID_LEN + 1;
91         os_memcpy(pos, conf->mobility_domain, MOBILITY_DOMAIN_ID_LEN);
92         pos += MOBILITY_DOMAIN_ID_LEN;
93         capab = RSN_FT_CAPAB_FT_OVER_DS;
94         *pos++ = capab;
95
96         return pos - buf;
97 }
98
99
100 static int wpa_write_ftie(struct wpa_auth_config *conf, const u8 *r0kh_id,
101                           size_t r0kh_id_len,
102                           const u8 *anonce, const u8 *snonce,
103                           u8 *buf, size_t len, const u8 *subelem,
104                           size_t subelem_len)
105 {
106         u8 *pos = buf, *ielen;
107         struct rsn_ftie *hdr;
108
109         if (len < 2 + sizeof(*hdr) + 2 + FT_R1KH_ID_LEN + 2 + r0kh_id_len +
110             subelem_len)
111                 return -1;
112
113         *pos++ = WLAN_EID_FAST_BSS_TRANSITION;
114         ielen = pos++;
115
116         hdr = (struct rsn_ftie *) pos;
117         os_memset(hdr, 0, sizeof(*hdr));
118         pos += sizeof(*hdr);
119         WPA_PUT_LE16(hdr->mic_control, 0);
120         if (anonce)
121                 os_memcpy(hdr->anonce, anonce, WPA_NONCE_LEN);
122         if (snonce)
123                 os_memcpy(hdr->snonce, snonce, WPA_NONCE_LEN);
124
125         /* Optional Parameters */
126         *pos++ = FTIE_SUBELEM_R1KH_ID;
127         *pos++ = FT_R1KH_ID_LEN;
128         os_memcpy(pos, conf->r1_key_holder, FT_R1KH_ID_LEN);
129         pos += FT_R1KH_ID_LEN;
130
131         if (r0kh_id) {
132                 *pos++ = FTIE_SUBELEM_R0KH_ID;
133                 *pos++ = r0kh_id_len;
134                 os_memcpy(pos, r0kh_id, r0kh_id_len);
135                 pos += r0kh_id_len;
136         }
137
138         if (subelem) {
139                 os_memcpy(pos, subelem, subelem_len);
140                 pos += subelem_len;
141         }
142
143         *ielen = pos - buf - 2;
144
145         return pos - buf;
146 }
147
148
149 struct wpa_ft_pmk_r0_sa {
150         struct wpa_ft_pmk_r0_sa *next;
151         u8 pmk_r0[PMK_LEN];
152         u8 pmk_r0_name[WPA_PMK_NAME_LEN];
153         u8 spa[ETH_ALEN];
154         int pairwise; /* Pairwise cipher suite, WPA_CIPHER_* */
155         /* TODO: expiration, identity, radius_class, EAP type, VLAN ID */
156         int pmk_r1_pushed;
157 };
158
159 struct wpa_ft_pmk_r1_sa {
160         struct wpa_ft_pmk_r1_sa *next;
161         u8 pmk_r1[PMK_LEN];
162         u8 pmk_r1_name[WPA_PMK_NAME_LEN];
163         u8 spa[ETH_ALEN];
164         int pairwise; /* Pairwise cipher suite, WPA_CIPHER_* */
165         /* TODO: expiration, identity, radius_class, EAP type, VLAN ID */
166 };
167
168 struct wpa_ft_pmk_cache {
169         struct wpa_ft_pmk_r0_sa *pmk_r0;
170         struct wpa_ft_pmk_r1_sa *pmk_r1;
171 };
172
173 struct wpa_ft_pmk_cache * wpa_ft_pmk_cache_init(void)
174 {
175         struct wpa_ft_pmk_cache *cache;
176
177         cache = os_zalloc(sizeof(*cache));
178
179         return cache;
180 }
181
182
183 void wpa_ft_pmk_cache_deinit(struct wpa_ft_pmk_cache *cache)
184 {
185         struct wpa_ft_pmk_r0_sa *r0, *r0prev;
186         struct wpa_ft_pmk_r1_sa *r1, *r1prev;
187
188         r0 = cache->pmk_r0;
189         while (r0) {
190                 r0prev = r0;
191                 r0 = r0->next;
192                 os_memset(r0prev->pmk_r0, 0, PMK_LEN);
193                 os_free(r0prev);
194         }
195
196         r1 = cache->pmk_r1;
197         while (r1) {
198                 r1prev = r1;
199                 r1 = r1->next;
200                 os_memset(r1prev->pmk_r1, 0, PMK_LEN);
201                 os_free(r1prev);
202         }
203
204         os_free(cache);
205 }
206
207
208 static int wpa_ft_store_pmk_r0(struct wpa_authenticator *wpa_auth,
209                                const u8 *spa, const u8 *pmk_r0,
210                                const u8 *pmk_r0_name, int pairwise)
211 {
212         struct wpa_ft_pmk_cache *cache = wpa_auth->ft_pmk_cache;
213         struct wpa_ft_pmk_r0_sa *r0;
214
215         /* TODO: add expiration and limit on number of entries in cache */
216
217         r0 = os_zalloc(sizeof(*r0));
218         if (r0 == NULL)
219                 return -1;
220
221         os_memcpy(r0->pmk_r0, pmk_r0, PMK_LEN);
222         os_memcpy(r0->pmk_r0_name, pmk_r0_name, WPA_PMK_NAME_LEN);
223         os_memcpy(r0->spa, spa, ETH_ALEN);
224         r0->pairwise = pairwise;
225
226         r0->next = cache->pmk_r0;
227         cache->pmk_r0 = r0;
228
229         return 0;
230 }
231
232
233 static int wpa_ft_fetch_pmk_r0(struct wpa_authenticator *wpa_auth,
234                                const u8 *spa, const u8 *pmk_r0_name,
235                                u8 *pmk_r0, int *pairwise)
236 {
237         struct wpa_ft_pmk_cache *cache = wpa_auth->ft_pmk_cache;
238         struct wpa_ft_pmk_r0_sa *r0;
239
240         r0 = cache->pmk_r0;
241         while (r0) {
242                 if (os_memcmp(r0->spa, spa, ETH_ALEN) == 0 &&
243                     os_memcmp(r0->pmk_r0_name, pmk_r0_name, WPA_PMK_NAME_LEN)
244                     == 0) {
245                         os_memcpy(pmk_r0, r0->pmk_r0, PMK_LEN);
246                         if (pairwise)
247                                 *pairwise = r0->pairwise;
248                         return 0;
249                 }
250
251                 r0 = r0->next;
252         }
253
254         return -1;
255 }
256
257
258 static int wpa_ft_store_pmk_r1(struct wpa_authenticator *wpa_auth,
259                                const u8 *spa, const u8 *pmk_r1,
260                                const u8 *pmk_r1_name, int pairwise)
261 {
262         struct wpa_ft_pmk_cache *cache = wpa_auth->ft_pmk_cache;
263         struct wpa_ft_pmk_r1_sa *r1;
264
265         /* TODO: add expiration and limit on number of entries in cache */
266
267         r1 = os_zalloc(sizeof(*r1));
268         if (r1 == NULL)
269                 return -1;
270
271         os_memcpy(r1->pmk_r1, pmk_r1, PMK_LEN);
272         os_memcpy(r1->pmk_r1_name, pmk_r1_name, WPA_PMK_NAME_LEN);
273         os_memcpy(r1->spa, spa, ETH_ALEN);
274         r1->pairwise = pairwise;
275
276         r1->next = cache->pmk_r1;
277         cache->pmk_r1 = r1;
278
279         return 0;
280 }
281
282
283 static int wpa_ft_fetch_pmk_r1(struct wpa_authenticator *wpa_auth,
284                                const u8 *spa, const u8 *pmk_r1_name,
285                                u8 *pmk_r1, int *pairwise)
286 {
287         struct wpa_ft_pmk_cache *cache = wpa_auth->ft_pmk_cache;
288         struct wpa_ft_pmk_r1_sa *r1;
289
290         r1 = cache->pmk_r1;
291         while (r1) {
292                 if (os_memcmp(r1->spa, spa, ETH_ALEN) == 0 &&
293                     os_memcmp(r1->pmk_r1_name, pmk_r1_name, WPA_PMK_NAME_LEN)
294                     == 0) {
295                         os_memcpy(pmk_r1, r1->pmk_r1, PMK_LEN);
296                         if (pairwise)
297                                 *pairwise = r1->pairwise;
298                         return 0;
299                 }
300
301                 r1 = r1->next;
302         }
303
304         return -1;
305 }
306
307
308 static int wpa_ft_pull_pmk_r1(struct wpa_authenticator *wpa_auth,
309                               const u8 *s1kh_id, const u8 *r0kh_id,
310                               size_t r0kh_id_len, const u8 *pmk_r0_name)
311 {
312         struct ft_remote_r0kh *r0kh;
313         struct ft_r0kh_r1kh_pull_frame frame, f;
314
315         r0kh = wpa_auth->conf.r0kh_list;
316         while (r0kh) {
317                 if (r0kh->id_len == r0kh_id_len &&
318                     os_memcmp(r0kh->id, r0kh_id, r0kh_id_len) == 0)
319                         break;
320                 r0kh = r0kh->next;
321         }
322         if (r0kh == NULL)
323                 return -1;
324
325         wpa_printf(MSG_DEBUG, "FT: Send PMK-R1 pull request to remote R0KH "
326                    "address " MACSTR, MAC2STR(r0kh->addr));
327
328         os_memset(&frame, 0, sizeof(frame));
329         frame.frame_type = RSN_REMOTE_FRAME_TYPE_FT_RRB;
330         frame.packet_type = FT_PACKET_R0KH_R1KH_PULL;
331         frame.data_length = host_to_le16(FT_R0KH_R1KH_PULL_DATA_LEN);
332         os_memcpy(frame.ap_address, wpa_auth->addr, ETH_ALEN);
333
334         /* aes_wrap() does not support inplace encryption, so use a temporary
335          * buffer for the data. */
336         if (os_get_random(f.nonce, sizeof(f.nonce))) {
337                 wpa_printf(MSG_DEBUG, "FT: Failed to get random data for "
338                            "nonce");
339                 return -1;
340         }
341         os_memcpy(f.pmk_r0_name, pmk_r0_name, WPA_PMK_NAME_LEN);
342         os_memcpy(f.r1kh_id, wpa_auth->conf.r1_key_holder, FT_R1KH_ID_LEN);
343         os_memcpy(f.s1kh_id, s1kh_id, ETH_ALEN);
344
345         if (aes_wrap(r0kh->key, (FT_R0KH_R1KH_PULL_DATA_LEN + 7) / 8,
346                      f.nonce, frame.nonce) < 0)
347                 return -1;
348
349         wpa_ft_rrb_send(wpa_auth, r0kh->addr, (u8 *) &frame, sizeof(frame));
350
351         return 0;
352 }
353
354
355 int wpa_auth_derive_ptk_ft(struct wpa_state_machine *sm, const u8 *pmk,
356                            struct wpa_ptk *ptk, size_t ptk_len)
357 {
358         u8 pmk_r0[PMK_LEN], pmk_r0_name[WPA_PMK_NAME_LEN];
359         u8 pmk_r1[PMK_LEN];
360         u8 ptk_name[WPA_PMK_NAME_LEN];
361         const u8 *mdid = sm->wpa_auth->conf.mobility_domain;
362         const u8 *r0kh = sm->wpa_auth->conf.r0_key_holder;
363         size_t r0kh_len = sm->wpa_auth->conf.r0_key_holder_len;
364         const u8 *r1kh = sm->wpa_auth->conf.r1_key_holder;
365         const u8 *ssid = sm->wpa_auth->conf.ssid;
366         size_t ssid_len = sm->wpa_auth->conf.ssid_len;
367
368
369         if (sm->xxkey_len == 0) {
370                 wpa_printf(MSG_DEBUG, "FT: XXKey not available for key "
371                            "derivation");
372                 return -1;
373         }
374
375         wpa_derive_pmk_r0(sm->xxkey, sm->xxkey_len, ssid, ssid_len, mdid,
376                           r0kh, r0kh_len, sm->addr, pmk_r0, pmk_r0_name);
377         wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R0", pmk_r0, PMK_LEN);
378         wpa_hexdump(MSG_DEBUG, "FT: PMKR0Name", pmk_r0_name, WPA_PMK_NAME_LEN);
379         wpa_ft_store_pmk_r0(sm->wpa_auth, sm->addr, pmk_r0, pmk_r0_name,
380                             sm->pairwise);
381
382         wpa_derive_pmk_r1(pmk_r0, pmk_r0_name, r1kh, sm->addr,
383                           pmk_r1, sm->pmk_r1_name);
384         wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R1", pmk_r1, PMK_LEN);
385         wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name", sm->pmk_r1_name,
386                     WPA_PMK_NAME_LEN);
387         wpa_ft_store_pmk_r1(sm->wpa_auth, sm->addr, pmk_r1, sm->pmk_r1_name,
388                             sm->pairwise);
389
390         wpa_pmk_r1_to_ptk(pmk_r1, sm->SNonce, sm->ANonce, sm->addr,
391                           sm->wpa_auth->addr, sm->pmk_r1_name,
392                           (u8 *) ptk, ptk_len, ptk_name);
393         wpa_hexdump_key(MSG_DEBUG, "FT: PTK", (u8 *) ptk, ptk_len);
394         wpa_hexdump(MSG_DEBUG, "FT: PTKName", ptk_name, WPA_PMK_NAME_LEN);
395
396         return 0;
397 }
398
399
400 static inline int wpa_auth_get_seqnum(struct wpa_authenticator *wpa_auth,
401                                       const u8 *addr, int idx, u8 *seq)
402 {
403         if (wpa_auth->cb.get_seqnum == NULL)
404                 return -1;
405         return wpa_auth->cb.get_seqnum(wpa_auth->cb.ctx, addr, idx, seq);
406 }
407
408
409 static u8 * wpa_ft_gtk_subelem(struct wpa_state_machine *sm, size_t *len)
410 {
411         u8 *subelem;
412         struct wpa_group *gsm = sm->group;
413         size_t subelem_len, pad_len;
414         const u8 *key;
415         size_t key_len;
416         u8 keybuf[32];
417
418         key_len = gsm->GTK_len;
419         if (key_len > sizeof(keybuf))
420                 return NULL;
421
422         /*
423          * Pad key for AES Key Wrap if it is not multiple of 8 bytes or is less
424          * than 16 bytes.
425          */
426         pad_len = key_len % 8;
427         if (pad_len)
428                 pad_len = 8 - pad_len;
429         if (key_len + pad_len < 16)
430                 pad_len += 8;
431         if (pad_len) {
432                 os_memcpy(keybuf, gsm->GTK[gsm->GN - 1], key_len);
433                 os_memset(keybuf + key_len, 0, pad_len);
434                 keybuf[key_len] = 0xdd;
435                 key_len += pad_len;
436                 key = keybuf;
437         } else
438                 key = gsm->GTK[gsm->GN - 1];
439
440         /*
441          * Sub-elem ID[1] | Length[1] | Key Info[1] | Key Length[1] | RSC[8] |
442          * Key[5..32].
443          */
444         subelem_len = 12 + key_len + 8;
445         subelem = os_zalloc(subelem_len);
446         if (subelem == NULL)
447                 return NULL;
448
449         subelem[0] = FTIE_SUBELEM_GTK;
450         subelem[1] = 10 + key_len + 8;
451         subelem[2] = gsm->GN & 0x03; /* Key ID in B0-B1 of Key Info */
452         subelem[3] = gsm->GTK_len;
453         wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN, subelem + 4);
454         if (aes_wrap(sm->PTK.kek, key_len / 8, key, subelem + 12)) {
455                 os_free(subelem);
456                 return NULL;
457         }
458
459         *len = subelem_len;
460         return subelem;
461 }
462
463
464 #ifdef CONFIG_IEEE80211W
465 static u8 * wpa_ft_igtk_subelem(struct wpa_state_machine *sm, size_t *len)
466 {
467         u8 *subelem, *pos;
468         struct wpa_group *gsm = sm->group;
469         size_t subelem_len;
470
471         /* Sub-elem ID[1] | Length[1] | KeyID[2] | IPN[6] | Key Length[1] |
472          * Key[16+8] */
473         subelem_len = 1 + 1 + 2 + 6 + 1 + WPA_IGTK_LEN + 8;
474         subelem = os_zalloc(subelem_len);
475         if (subelem == NULL)
476                 return NULL;
477
478         pos = subelem;
479         *pos++ = FTIE_SUBELEM_IGTK;
480         *pos++ = subelem_len - 2;
481         WPA_PUT_LE16(pos, gsm->GN_igtk);
482         pos += 2;
483         wpa_auth_get_seqnum(sm->wpa_auth, NULL, gsm->GN_igtk, pos);
484         pos += 6;
485         *pos++ = WPA_IGTK_LEN;
486         if (aes_wrap(sm->PTK.kek, WPA_IGTK_LEN / 8,
487                      gsm->IGTK[gsm->GN_igtk - 4], pos)) {
488                 os_free(subelem);
489                 return NULL;
490         }
491
492         *len = subelem_len;
493         return subelem;
494 }
495 #endif /* CONFIG_IEEE80211W */
496
497
498 static u8 * wpa_ft_process_rdie(u8 *pos, u8 *end, u8 id, u8 descr_count,
499                                 const u8 *ies, size_t ies_len)
500 {
501         struct ieee802_11_elems parse;
502         struct rsn_rdie *rdie;
503
504         wpa_printf(MSG_DEBUG, "FT: Resource Request: id=%d descr_count=%d",
505                    id, descr_count);
506         wpa_hexdump(MSG_MSGDUMP, "FT: Resource descriptor IE(s)",
507                     ies, ies_len);
508
509         if (end - pos < (int) sizeof(*rdie)) {
510                 wpa_printf(MSG_ERROR, "FT: Not enough room for response RDIE");
511                 return pos;
512         }
513
514         *pos++ = WLAN_EID_RIC_DATA;
515         *pos++ = sizeof(*rdie);
516         rdie = (struct rsn_rdie *) pos;
517         rdie->id = id;
518         rdie->descr_count = 0;
519         rdie->status_code = host_to_le16(WLAN_STATUS_SUCCESS);
520         pos += sizeof(*rdie);
521
522         if (ieee802_11_parse_elems((u8 *) ies, ies_len, &parse, 1) ==
523             ParseFailed) {
524                 wpa_printf(MSG_DEBUG, "FT: Failed to parse request IEs");
525                 rdie->status_code =
526                         host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE);
527                 return pos;
528         }
529
530 #ifdef NEED_AP_MLME
531         if (parse.wmm_tspec) {
532                 struct wmm_tspec_element *tspec;
533                 int res;
534
535                 if (parse.wmm_tspec_len + 2 < (int) sizeof(*tspec)) {
536                         wpa_printf(MSG_DEBUG, "FT: Too short WMM TSPEC IE "
537                                    "(%d)", (int) parse.wmm_tspec_len);
538                         rdie->status_code =
539                                 host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE);
540                         return pos;
541                 }
542                 if (end - pos < (int) sizeof(*tspec)) {
543                         wpa_printf(MSG_ERROR, "FT: Not enough room for "
544                                    "response TSPEC");
545                         rdie->status_code =
546                                 host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE);
547                         return pos;
548                 }
549                 tspec = (struct wmm_tspec_element *) pos;
550                 os_memcpy(tspec, parse.wmm_tspec - 2, sizeof(*tspec));
551                 res = wmm_process_tspec(tspec);
552                 wpa_printf(MSG_DEBUG, "FT: ADDTS processing result: %d", res);
553                 if (res == WMM_ADDTS_STATUS_INVALID_PARAMETERS)
554                         rdie->status_code =
555                                 host_to_le16(WLAN_STATUS_INVALID_PARAMETERS);
556                 else if (res == WMM_ADDTS_STATUS_REFUSED)
557                         rdie->status_code =
558                                 host_to_le16(WLAN_STATUS_REQUEST_DECLINED);
559                 else {
560                         /* TSPEC accepted; include updated TSPEC in response */
561                         rdie->descr_count = 1;
562                         pos += sizeof(*tspec);
563                 }
564                 return pos;
565         }
566 #endif /* NEED_AP_MLME */
567
568         wpa_printf(MSG_DEBUG, "FT: No supported resource requested");
569         rdie->status_code = host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE);
570         return pos;
571 }
572
573
574 static u8 * wpa_ft_process_ric(u8 *pos, u8 *end, const u8 *ric, size_t ric_len)
575 {
576         const u8 *rpos, *start;
577         const struct rsn_rdie *rdie;
578
579         wpa_hexdump(MSG_MSGDUMP, "FT: RIC Request", ric, ric_len);
580
581         rpos = ric;
582         while (rpos + sizeof(*rdie) < ric + ric_len) {
583                 if (rpos[0] != WLAN_EID_RIC_DATA || rpos[1] < sizeof(*rdie) ||
584                     rpos + 2 + rpos[1] > ric + ric_len)
585                         break;
586                 rdie = (const struct rsn_rdie *) (rpos + 2);
587                 rpos += 2 + rpos[1];
588                 start = rpos;
589
590                 while (rpos + 2 <= ric + ric_len &&
591                        rpos + 2 + rpos[1] <= ric + ric_len) {
592                         if (rpos[0] == WLAN_EID_RIC_DATA)
593                                 break;
594                         rpos += 2 + rpos[1];
595                 }
596                 pos = wpa_ft_process_rdie(pos, end, rdie->id,
597                                           rdie->descr_count,
598                                           start, rpos - start);
599         }
600
601         return pos;
602 }
603
604
605 u8 * wpa_sm_write_assoc_resp_ies(struct wpa_state_machine *sm, u8 *pos,
606                                  size_t max_len, int auth_alg,
607                                  const u8 *req_ies, size_t req_ies_len)
608 {
609         u8 *end, *mdie, *ftie, *rsnie = NULL, *r0kh_id, *subelem = NULL;
610         size_t mdie_len, ftie_len, rsnie_len = 0, r0kh_id_len, subelem_len = 0;
611         int res;
612         struct wpa_auth_config *conf;
613         struct rsn_ftie *_ftie;
614         struct wpa_ft_ies parse;
615         u8 *ric_start;
616
617         if (sm == NULL)
618                 return pos;
619
620         conf = &sm->wpa_auth->conf;
621
622         if (sm->wpa_key_mgmt != WPA_KEY_MGMT_FT_IEEE8021X &&
623             sm->wpa_key_mgmt != WPA_KEY_MGMT_FT_PSK)
624                 return pos;
625
626         end = pos + max_len;
627
628         if (auth_alg == WLAN_AUTH_FT) {
629                 /*
630                  * RSN (only present if this is a Reassociation Response and
631                  * part of a fast BSS transition)
632                  */
633                 res = wpa_write_rsn_ie(conf, pos, end - pos, sm->pmk_r1_name);
634                 if (res < 0)
635                         return pos;
636                 rsnie = pos;
637                 rsnie_len = res;
638                 pos += res;
639         }
640
641         /* Mobility Domain Information */
642         res = wpa_write_mdie(conf, pos, end - pos);
643         if (res < 0)
644                 return pos;
645         mdie = pos;
646         mdie_len = res;
647         pos += res;
648
649         /* Fast BSS Transition Information */
650         if (auth_alg == WLAN_AUTH_FT) {
651                 subelem = wpa_ft_gtk_subelem(sm, &subelem_len);
652                 r0kh_id = sm->r0kh_id;
653                 r0kh_id_len = sm->r0kh_id_len;
654 #ifdef CONFIG_IEEE80211W
655                 if (sm->mgmt_frame_prot) {
656                         u8 *igtk;
657                         size_t igtk_len;
658                         u8 *nbuf;
659                         igtk = wpa_ft_igtk_subelem(sm, &igtk_len);
660                         if (igtk == NULL) {
661                                 os_free(subelem);
662                                 return pos;
663                         }
664                         nbuf = os_realloc(subelem, subelem_len + igtk_len);
665                         if (nbuf == NULL) {
666                                 os_free(subelem);
667                                 os_free(igtk);
668                                 return pos;
669                         }
670                         subelem = nbuf;
671                         os_memcpy(subelem + subelem_len, igtk, igtk_len);
672                         subelem_len += igtk_len;
673                         os_free(igtk);
674                 }
675 #endif /* CONFIG_IEEE80211W */
676         } else {
677                 r0kh_id = conf->r0_key_holder;
678                 r0kh_id_len = conf->r0_key_holder_len;
679         }
680         res = wpa_write_ftie(conf, r0kh_id, r0kh_id_len, NULL, NULL, pos,
681                              end - pos, subelem, subelem_len);
682         os_free(subelem);
683         if (res < 0)
684                 return pos;
685         ftie = pos;
686         ftie_len = res;
687         pos += res;
688
689         _ftie = (struct rsn_ftie *) (ftie + 2);
690         _ftie->mic_control[1] = 3; /* Information element count */
691
692         ric_start = pos;
693         if (wpa_ft_parse_ies(req_ies, req_ies_len, &parse) == 0 && parse.ric) {
694                 pos = wpa_ft_process_ric(pos, end, parse.ric, parse.ric_len);
695                 _ftie->mic_control[1] += ieee802_11_ie_count(ric_start,
696                                                              pos - ric_start);
697         }
698         if (ric_start == pos)
699                 ric_start = NULL;
700
701         if (wpa_ft_mic(sm->PTK.kck, sm->addr, sm->wpa_auth->addr, 6,
702                        mdie, mdie_len, ftie, ftie_len,
703                        rsnie, rsnie_len,
704                        ric_start, ric_start ? pos - ric_start : 0,
705                        _ftie->mic) < 0)
706                 wpa_printf(MSG_DEBUG, "FT: Failed to calculate MIC");
707
708         return pos;
709 }
710
711
712 static int wpa_ft_parse_ftie(const u8 *ie, size_t ie_len,
713                              struct wpa_ft_ies *parse)
714 {
715         const u8 *end, *pos;
716
717         parse->ftie = ie;
718         parse->ftie_len = ie_len;
719
720         pos = ie + sizeof(struct rsn_ftie);
721         end = ie + ie_len;
722
723         while (pos + 2 <= end && pos + 2 + pos[1] <= end) {
724                 switch (pos[0]) {
725                 case FTIE_SUBELEM_R1KH_ID:
726                         if (pos[1] != FT_R1KH_ID_LEN) {
727                                 wpa_printf(MSG_DEBUG, "FT: Invalid R1KH-ID "
728                                            "length in FTIE: %d", pos[1]);
729                                 return -1;
730                         }
731                         parse->r1kh_id = pos + 2;
732                         break;
733                 case FTIE_SUBELEM_GTK:
734                         parse->gtk = pos + 2;
735                         parse->gtk_len = pos[1];
736                         break;
737                 case FTIE_SUBELEM_R0KH_ID:
738                         if (pos[1] < 1 || pos[1] > FT_R0KH_ID_MAX_LEN) {
739                                 wpa_printf(MSG_DEBUG, "FT: Invalid R0KH-ID "
740                                            "length in FTIE: %d", pos[1]);
741                                 return -1;
742                         }
743                         parse->r0kh_id = pos + 2;
744                         parse->r0kh_id_len = pos[1];
745                         break;
746                 }
747
748                 pos += 2 + pos[1];
749         }
750
751         return 0;
752 }
753
754
755 static int wpa_ft_parse_ies(const u8 *ies, size_t ies_len,
756                             struct wpa_ft_ies *parse)
757 {
758         const u8 *end, *pos;
759         struct wpa_ie_data data;
760         int ret;
761         const struct rsn_ftie *ftie;
762         int prot_ie_count = 0;
763
764         os_memset(parse, 0, sizeof(*parse));
765         if (ies == NULL)
766                 return 0;
767
768         pos = ies;
769         end = ies + ies_len;
770         while (pos + 2 <= end && pos + 2 + pos[1] <= end) {
771                 switch (pos[0]) {
772                 case WLAN_EID_RSN:
773                         parse->rsn = pos + 2;
774                         parse->rsn_len = pos[1];
775                         ret = wpa_parse_wpa_ie_rsn(parse->rsn - 2,
776                                                    parse->rsn_len + 2,
777                                                    &data);
778                         if (ret < 0) {
779                                 wpa_printf(MSG_DEBUG, "FT: Failed to parse "
780                                            "RSN IE: %d", ret);
781                                 return -1;
782                         }
783                         if (data.num_pmkid == 1 && data.pmkid)
784                                 parse->rsn_pmkid = data.pmkid;
785                         break;
786                 case WLAN_EID_MOBILITY_DOMAIN:
787                         parse->mdie = pos + 2;
788                         parse->mdie_len = pos[1];
789                         break;
790                 case WLAN_EID_FAST_BSS_TRANSITION:
791                         if (pos[1] < sizeof(*ftie))
792                                 return -1;
793                         ftie = (const struct rsn_ftie *) (pos + 2);
794                         prot_ie_count = ftie->mic_control[1];
795                         if (wpa_ft_parse_ftie(pos + 2, pos[1], parse) < 0)
796                                 return -1;
797                         break;
798                 case WLAN_EID_RIC_DATA:
799                         if (parse->ric == NULL)
800                                 parse->ric = pos;
801                 }
802
803                 pos += 2 + pos[1];
804         }
805
806         if (prot_ie_count == 0)
807                 return 0; /* no MIC */
808
809         /*
810          * Check that the protected IE count matches with IEs included in the
811          * frame.
812          */
813         if (parse->rsn)
814                 prot_ie_count--;
815         if (parse->mdie)
816                 prot_ie_count--;
817         if (parse->ftie)
818                 prot_ie_count--;
819         if (prot_ie_count < 0) {
820                 wpa_printf(MSG_DEBUG, "FT: Some required IEs not included in "
821                            "the protected IE count");
822                 return -1;
823         }
824
825         if (prot_ie_count == 0 && parse->ric) {
826                 wpa_printf(MSG_DEBUG, "FT: RIC IE(s) in the frame, but not "
827                            "included in protected IE count");
828                 return -1;
829         }
830
831         /* Determine the end of the RIC IE(s) */
832         pos = parse->ric;
833         while (pos && pos + 2 <= end && pos + 2 + pos[1] <= end &&
834                prot_ie_count) {
835                 prot_ie_count--;
836                 pos += 2 + pos[1];
837         }
838         parse->ric_len = pos - parse->ric;
839         if (prot_ie_count) {
840                 wpa_printf(MSG_DEBUG, "FT: %d protected IEs missing from "
841                            "frame", (int) prot_ie_count);
842                 return -1;
843         }
844
845         return 0;
846 }
847
848
849 static inline int wpa_auth_set_key(struct wpa_authenticator *wpa_auth,
850                                    int vlan_id,
851                                    enum wpa_alg alg, const u8 *addr, int idx,
852                                    u8 *key, size_t key_len)
853 {
854         if (wpa_auth->cb.set_key == NULL)
855                 return -1;
856         return wpa_auth->cb.set_key(wpa_auth->cb.ctx, vlan_id, alg, addr, idx,
857                                     key, key_len);
858 }
859
860
861 void wpa_ft_install_ptk(struct wpa_state_machine *sm)
862 {
863         enum wpa_alg alg;
864         int klen;
865
866         /* MLME-SETKEYS.request(PTK) */
867         if (sm->pairwise == WPA_CIPHER_TKIP) {
868                 alg = WPA_ALG_TKIP;
869                 klen = 32;
870         } else if (sm->pairwise == WPA_CIPHER_CCMP) {
871                 alg = WPA_ALG_CCMP;
872                 klen = 16;
873         } else {
874                 wpa_printf(MSG_DEBUG, "FT: Unknown pairwise alg 0x%x - skip "
875                            "PTK configuration", sm->pairwise);
876                 return;
877         }
878
879         /* FIX: add STA entry to kernel/driver here? The set_key will fail
880          * most likely without this.. At the moment, STA entry is added only
881          * after association has been completed. This function will be called
882          * again after association to get the PTK configured, but that could be
883          * optimized by adding the STA entry earlier.
884          */
885         if (wpa_auth_set_key(sm->wpa_auth, 0, alg, sm->addr, 0,
886                              sm->PTK.tk1, klen))
887                 return;
888
889         /* FIX: MLME-SetProtection.Request(TA, Tx_Rx) */
890         sm->pairwise_set = TRUE;
891 }
892
893
894 static u16 wpa_ft_process_auth_req(struct wpa_state_machine *sm,
895                                    const u8 *ies, size_t ies_len,
896                                    u8 **resp_ies, size_t *resp_ies_len)
897 {
898         struct rsn_mdie *mdie;
899         struct rsn_ftie *ftie;
900         u8 pmk_r1[PMK_LEN], pmk_r1_name[WPA_PMK_NAME_LEN];
901         u8 ptk_name[WPA_PMK_NAME_LEN];
902         struct wpa_auth_config *conf;
903         struct wpa_ft_ies parse;
904         size_t buflen, ptk_len;
905         int ret;
906         u8 *pos, *end;
907         int pairwise;
908
909         *resp_ies = NULL;
910         *resp_ies_len = 0;
911
912         sm->pmk_r1_name_valid = 0;
913         conf = &sm->wpa_auth->conf;
914
915         wpa_hexdump(MSG_DEBUG, "FT: Received authentication frame IEs",
916                     ies, ies_len);
917
918         if (wpa_ft_parse_ies(ies, ies_len, &parse) < 0) {
919                 wpa_printf(MSG_DEBUG, "FT: Failed to parse FT IEs");
920                 return WLAN_STATUS_UNSPECIFIED_FAILURE;
921         }
922
923         mdie = (struct rsn_mdie *) parse.mdie;
924         if (mdie == NULL || parse.mdie_len < sizeof(*mdie) ||
925             os_memcmp(mdie->mobility_domain,
926                       sm->wpa_auth->conf.mobility_domain,
927                       MOBILITY_DOMAIN_ID_LEN) != 0) {
928                 wpa_printf(MSG_DEBUG, "FT: Invalid MDIE");
929                 return WLAN_STATUS_INVALID_MDIE;
930         }
931
932         ftie = (struct rsn_ftie *) parse.ftie;
933         if (ftie == NULL || parse.ftie_len < sizeof(*ftie)) {
934                 wpa_printf(MSG_DEBUG, "FT: Invalid FTIE");
935                 return WLAN_STATUS_INVALID_FTIE;
936         }
937
938         os_memcpy(sm->SNonce, ftie->snonce, WPA_NONCE_LEN);
939
940         if (parse.r0kh_id == NULL) {
941                 wpa_printf(MSG_DEBUG, "FT: Invalid FTIE - no R0KH-ID");
942                 return WLAN_STATUS_INVALID_FTIE;
943         }
944
945         wpa_hexdump(MSG_DEBUG, "FT: STA R0KH-ID",
946                     parse.r0kh_id, parse.r0kh_id_len);
947         os_memcpy(sm->r0kh_id, parse.r0kh_id, parse.r0kh_id_len);
948         sm->r0kh_id_len = parse.r0kh_id_len;
949
950         if (parse.rsn_pmkid == NULL) {
951                 wpa_printf(MSG_DEBUG, "FT: No PMKID in RSNIE");
952                 return WLAN_STATUS_INVALID_PMKID;
953         }
954
955         wpa_hexdump(MSG_DEBUG, "FT: Requested PMKR0Name",
956                     parse.rsn_pmkid, WPA_PMK_NAME_LEN);
957         wpa_derive_pmk_r1_name(parse.rsn_pmkid,
958                                sm->wpa_auth->conf.r1_key_holder, sm->addr,
959                                pmk_r1_name);
960         wpa_hexdump(MSG_DEBUG, "FT: Derived requested PMKR1Name",
961                     pmk_r1_name, WPA_PMK_NAME_LEN);
962
963         if (wpa_ft_fetch_pmk_r1(sm->wpa_auth, sm->addr, pmk_r1_name, pmk_r1,
964                     &pairwise) < 0) {
965                 if (wpa_ft_pull_pmk_r1(sm->wpa_auth, sm->addr, sm->r0kh_id,
966                                        sm->r0kh_id_len, parse.rsn_pmkid) < 0) {
967                         wpa_printf(MSG_DEBUG, "FT: Did not have matching "
968                                    "PMK-R1 and unknown R0KH-ID");
969                         return WLAN_STATUS_INVALID_PMKID;
970                 }
971
972                 /*
973                  * TODO: Should return "status pending" (and the caller should
974                  * not send out response now). The real response will be sent
975                  * once the response from R0KH is received.
976                  */
977                 return WLAN_STATUS_INVALID_PMKID;
978         }
979
980         wpa_hexdump_key(MSG_DEBUG, "FT: Selected PMK-R1", pmk_r1, PMK_LEN);
981         sm->pmk_r1_name_valid = 1;
982         os_memcpy(sm->pmk_r1_name, pmk_r1_name, WPA_PMK_NAME_LEN);
983
984         if (os_get_random(sm->ANonce, WPA_NONCE_LEN)) {
985                 wpa_printf(MSG_DEBUG, "FT: Failed to get random data for "
986                            "ANonce");
987                 return WLAN_STATUS_UNSPECIFIED_FAILURE;
988         }
989
990         wpa_hexdump(MSG_DEBUG, "FT: Received SNonce",
991                     sm->SNonce, WPA_NONCE_LEN);
992         wpa_hexdump(MSG_DEBUG, "FT: Generated ANonce",
993                     sm->ANonce, WPA_NONCE_LEN);
994
995         ptk_len = pairwise != WPA_CIPHER_CCMP ? 64 : 48;
996         wpa_pmk_r1_to_ptk(pmk_r1, sm->SNonce, sm->ANonce, sm->addr,
997                           sm->wpa_auth->addr, pmk_r1_name,
998                           (u8 *) &sm->PTK, ptk_len, ptk_name);
999         wpa_hexdump_key(MSG_DEBUG, "FT: PTK",
1000                         (u8 *) &sm->PTK, ptk_len);
1001         wpa_hexdump(MSG_DEBUG, "FT: PTKName", ptk_name, WPA_PMK_NAME_LEN);
1002
1003         sm->pairwise = pairwise;
1004         wpa_ft_install_ptk(sm);
1005
1006         buflen = 2 + sizeof(struct rsn_mdie) + 2 + sizeof(struct rsn_ftie) +
1007                 2 + FT_R1KH_ID_LEN + 200;
1008         *resp_ies = os_zalloc(buflen);
1009         if (*resp_ies == NULL) {
1010                 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1011         }
1012
1013         pos = *resp_ies;
1014         end = *resp_ies + buflen;
1015
1016         ret = wpa_write_rsn_ie(conf, pos, end - pos, parse.rsn_pmkid);
1017         if (ret < 0) {
1018                 os_free(*resp_ies);
1019                 *resp_ies = NULL;
1020                 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1021         }
1022         pos += ret;
1023
1024         ret = wpa_write_mdie(conf, pos, end - pos);
1025         if (ret < 0) {
1026                 os_free(*resp_ies);
1027                 *resp_ies = NULL;
1028                 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1029         }
1030         pos += ret;
1031
1032         ret = wpa_write_ftie(conf, parse.r0kh_id, parse.r0kh_id_len,
1033                              sm->ANonce, sm->SNonce, pos, end - pos, NULL, 0);
1034         if (ret < 0) {
1035                 os_free(*resp_ies);
1036                 *resp_ies = NULL;
1037                 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1038         }
1039         pos += ret;
1040
1041         *resp_ies_len = pos - *resp_ies;
1042
1043         return WLAN_STATUS_SUCCESS;
1044 }
1045
1046
1047 void wpa_ft_process_auth(struct wpa_state_machine *sm, const u8 *bssid,
1048                          u16 auth_transaction, const u8 *ies, size_t ies_len,
1049                          void (*cb)(void *ctx, const u8 *dst, const u8 *bssid,
1050                                     u16 auth_transaction, u16 status,
1051                                     const u8 *ies, size_t ies_len),
1052                          void *ctx)
1053 {
1054         u16 status;
1055         u8 *resp_ies;
1056         size_t resp_ies_len;
1057
1058         if (sm == NULL) {
1059                 wpa_printf(MSG_DEBUG, "FT: Received authentication frame, but "
1060                            "WPA SM not available");
1061                 return;
1062         }
1063
1064         wpa_printf(MSG_DEBUG, "FT: Received authentication frame: STA=" MACSTR
1065                    " BSSID=" MACSTR " transaction=%d",
1066                    MAC2STR(sm->addr), MAC2STR(bssid), auth_transaction);
1067         status = wpa_ft_process_auth_req(sm, ies, ies_len, &resp_ies,
1068                                          &resp_ies_len);
1069
1070         wpa_printf(MSG_DEBUG, "FT: FT authentication response: dst=" MACSTR
1071                    " auth_transaction=%d status=%d",
1072                    MAC2STR(sm->addr), auth_transaction + 1, status);
1073         wpa_hexdump(MSG_DEBUG, "FT: Response IEs", resp_ies, resp_ies_len);
1074         cb(ctx, sm->addr, bssid, auth_transaction + 1, status,
1075            resp_ies, resp_ies_len);
1076         os_free(resp_ies);
1077 }
1078
1079
1080 u16 wpa_ft_validate_reassoc(struct wpa_state_machine *sm, const u8 *ies,
1081                             size_t ies_len)
1082 {
1083         struct wpa_ft_ies parse;
1084         struct rsn_mdie *mdie;
1085         struct rsn_ftie *ftie;
1086         u8 mic[16];
1087
1088         if (sm == NULL)
1089                 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1090
1091         wpa_hexdump(MSG_DEBUG, "FT: Reassoc Req IEs", ies, ies_len);
1092
1093         if (wpa_ft_parse_ies(ies, ies_len, &parse) < 0) {
1094                 wpa_printf(MSG_DEBUG, "FT: Failed to parse FT IEs");
1095                 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1096         }
1097
1098         if (parse.rsn == NULL) {
1099                 wpa_printf(MSG_DEBUG, "FT: No RSNIE in Reassoc Req");
1100                 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1101         }
1102
1103         if (parse.rsn_pmkid == NULL) {
1104                 wpa_printf(MSG_DEBUG, "FT: No PMKID in RSNIE");
1105                 return WLAN_STATUS_INVALID_PMKID;
1106         }
1107
1108         if (os_memcmp(parse.rsn_pmkid, sm->pmk_r1_name, WPA_PMK_NAME_LEN) != 0)
1109         {
1110                 wpa_printf(MSG_DEBUG, "FT: PMKID in Reassoc Req did not match "
1111                            "with the PMKR1Name derived from auth request");
1112                 return WLAN_STATUS_INVALID_PMKID;
1113         }
1114
1115         mdie = (struct rsn_mdie *) parse.mdie;
1116         if (mdie == NULL || parse.mdie_len < sizeof(*mdie) ||
1117             os_memcmp(mdie->mobility_domain,
1118                       sm->wpa_auth->conf.mobility_domain,
1119                       MOBILITY_DOMAIN_ID_LEN) != 0) {
1120                 wpa_printf(MSG_DEBUG, "FT: Invalid MDIE");
1121                 return WLAN_STATUS_INVALID_MDIE;
1122         }
1123
1124         ftie = (struct rsn_ftie *) parse.ftie;
1125         if (ftie == NULL || parse.ftie_len < sizeof(*ftie)) {
1126                 wpa_printf(MSG_DEBUG, "FT: Invalid FTIE");
1127                 return WLAN_STATUS_INVALID_FTIE;
1128         }
1129
1130         if (wpa_ft_mic(sm->PTK.kck, sm->addr, sm->wpa_auth->addr, 5,
1131                        parse.mdie - 2, parse.mdie_len + 2,
1132                        parse.ftie - 2, parse.ftie_len + 2,
1133                        parse.rsn - 2, parse.rsn_len + 2,
1134                        parse.ric, parse.ric_len,
1135                        mic) < 0) {
1136                 wpa_printf(MSG_DEBUG, "FT: Failed to calculate MIC");
1137                 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1138         }
1139
1140         if (os_memcmp(mic, ftie->mic, 16) != 0) {
1141                 wpa_printf(MSG_DEBUG, "FT: Invalid MIC in FTIE");
1142                 wpa_hexdump(MSG_MSGDUMP, "FT: Received MIC", ftie->mic, 16);
1143                 wpa_hexdump(MSG_MSGDUMP, "FT: Calculated MIC", mic, 16);
1144                 return WLAN_STATUS_INVALID_FTIE;
1145         }
1146
1147         return WLAN_STATUS_SUCCESS;
1148 }
1149
1150
1151 int wpa_ft_action_rx(struct wpa_state_machine *sm, const u8 *data, size_t len)
1152 {
1153         const u8 *sta_addr, *target_ap;
1154         const u8 *ies;
1155         size_t ies_len;
1156         u8 action;
1157         struct ft_rrb_frame *frame;
1158
1159         if (sm == NULL)
1160                 return -1;
1161
1162         /*
1163          * data: Category[1] Action[1] STA_Address[6] Target_AP_Address[6]
1164          * FT Request action frame body[variable]
1165          */
1166
1167         if (len < 14) {
1168                 wpa_printf(MSG_DEBUG, "FT: Too short FT Action frame "
1169                            "(len=%lu)", (unsigned long) len);
1170                 return -1;
1171         }
1172
1173         action = data[1];
1174         sta_addr = data + 2;
1175         target_ap = data + 8;
1176         ies = data + 14;
1177         ies_len = len - 14;
1178
1179         wpa_printf(MSG_DEBUG, "FT: Received FT Action frame (STA=" MACSTR
1180                    " Target AP=" MACSTR " Action=%d)",
1181                    MAC2STR(sta_addr), MAC2STR(target_ap), action);
1182
1183         if (os_memcmp(sta_addr, sm->addr, ETH_ALEN) != 0) {
1184                 wpa_printf(MSG_DEBUG, "FT: Mismatch in FT Action STA address: "
1185                            "STA=" MACSTR " STA-Address=" MACSTR,
1186                            MAC2STR(sm->addr), MAC2STR(sta_addr));
1187                 return -1;
1188         }
1189
1190         /*
1191          * Do some sanity checking on the target AP address (not own and not
1192          * broadcast. This could be extended to filter based on a list of known
1193          * APs in the MD (if such a list were configured).
1194          */
1195         if ((target_ap[0] & 0x01) ||
1196             os_memcmp(target_ap, sm->wpa_auth->addr, ETH_ALEN) == 0) {
1197                 wpa_printf(MSG_DEBUG, "FT: Invalid Target AP in FT Action "
1198                            "frame");
1199                 return -1;
1200         }
1201
1202         wpa_hexdump(MSG_MSGDUMP, "FT: Action frame body", ies, ies_len);
1203
1204         /* RRB - Forward action frame to the target AP */
1205         frame = os_malloc(sizeof(*frame) + len);
1206         frame->frame_type = RSN_REMOTE_FRAME_TYPE_FT_RRB;
1207         frame->packet_type = FT_PACKET_REQUEST;
1208         frame->action_length = host_to_le16(len);
1209         os_memcpy(frame->ap_address, sm->wpa_auth->addr, ETH_ALEN);
1210         os_memcpy(frame + 1, data, len);
1211
1212         wpa_ft_rrb_send(sm->wpa_auth, target_ap, (u8 *) frame,
1213                         sizeof(*frame) + len);
1214         os_free(frame);
1215
1216         return 0;
1217 }
1218
1219
1220 static int wpa_ft_rrb_rx_request(struct wpa_authenticator *wpa_auth,
1221                                  const u8 *current_ap, const u8 *sta_addr,
1222                                  const u8 *body, size_t len)
1223 {
1224         struct wpa_state_machine *sm;
1225         u16 status;
1226         u8 *resp_ies, *pos;
1227         size_t resp_ies_len, rlen;
1228         struct ft_rrb_frame *frame;
1229
1230         sm = wpa_ft_add_sta(wpa_auth, sta_addr);
1231         if (sm == NULL) {
1232                 wpa_printf(MSG_DEBUG, "FT: Failed to add new STA based on "
1233                            "RRB Request");
1234                 return -1;
1235         }
1236
1237         wpa_hexdump(MSG_MSGDUMP, "FT: RRB Request Frame body", body, len);
1238
1239         status = wpa_ft_process_auth_req(sm, body, len, &resp_ies,
1240                                          &resp_ies_len);
1241
1242         wpa_printf(MSG_DEBUG, "FT: RRB authentication response: STA=" MACSTR
1243                    " CurrentAP=" MACSTR " status=%d",
1244                    MAC2STR(sm->addr), MAC2STR(current_ap), status);
1245         wpa_hexdump(MSG_DEBUG, "FT: Response IEs", resp_ies, resp_ies_len);
1246
1247         /* RRB - Forward action frame response to the Current AP */
1248
1249         /*
1250          * data: Category[1] Action[1] STA_Address[6] Target_AP_Address[6]
1251          * Status_Code[2] FT Request action frame body[variable]
1252          */
1253         rlen = 2 + 2 * ETH_ALEN + 2 + resp_ies_len;
1254
1255         frame = os_malloc(sizeof(*frame) + rlen);
1256         frame->frame_type = RSN_REMOTE_FRAME_TYPE_FT_RRB;
1257         frame->packet_type = FT_PACKET_RESPONSE;
1258         frame->action_length = host_to_le16(rlen);
1259         os_memcpy(frame->ap_address, wpa_auth->addr, ETH_ALEN);
1260         pos = (u8 *) (frame + 1);
1261         *pos++ = WLAN_ACTION_FT;
1262         *pos++ = 2; /* Action: Response */
1263         os_memcpy(pos, sta_addr, ETH_ALEN);
1264         pos += ETH_ALEN;
1265         os_memcpy(pos, wpa_auth->addr, ETH_ALEN);
1266         pos += ETH_ALEN;
1267         WPA_PUT_LE16(pos, status);
1268         pos += 2;
1269         if (resp_ies) {
1270                 os_memcpy(pos, resp_ies, resp_ies_len);
1271                 os_free(resp_ies);
1272         }
1273
1274         wpa_ft_rrb_send(wpa_auth, current_ap, (u8 *) frame,
1275                         sizeof(*frame) + rlen);
1276         os_free(frame);
1277
1278         return 0;
1279 }
1280
1281
1282 static int wpa_ft_rrb_rx_pull(struct wpa_authenticator *wpa_auth,
1283                               const u8 *src_addr,
1284                               const u8 *data, size_t data_len)
1285 {
1286         struct ft_r0kh_r1kh_pull_frame *frame, f;
1287         struct ft_remote_r1kh *r1kh;
1288         struct ft_r0kh_r1kh_resp_frame resp, r;
1289         u8 pmk_r0[PMK_LEN];
1290         int pairwise;
1291
1292         wpa_printf(MSG_DEBUG, "FT: Received PMK-R1 pull");
1293
1294         if (data_len < sizeof(*frame))
1295                 return -1;
1296
1297         r1kh = wpa_auth->conf.r1kh_list;
1298         while (r1kh) {
1299                 if (os_memcmp(r1kh->addr, src_addr, ETH_ALEN) == 0)
1300                         break;
1301                 r1kh = r1kh->next;
1302         }
1303         if (r1kh == NULL) {
1304                 wpa_printf(MSG_DEBUG, "FT: No matching R1KH address found for "
1305                            "PMK-R1 pull source address " MACSTR,
1306                            MAC2STR(src_addr));
1307                 return -1;
1308         }
1309
1310         frame = (struct ft_r0kh_r1kh_pull_frame *) data;
1311         /* aes_unwrap() does not support inplace decryption, so use a temporary
1312          * buffer for the data. */
1313         if (aes_unwrap(r1kh->key, (FT_R0KH_R1KH_PULL_DATA_LEN + 7) / 8,
1314                        frame->nonce, f.nonce) < 0) {
1315                 wpa_printf(MSG_DEBUG, "FT: Failed to decrypt PMK-R1 pull "
1316                            "request from " MACSTR, MAC2STR(src_addr));
1317                 return -1;
1318         }
1319
1320         wpa_hexdump(MSG_DEBUG, "FT: PMK-R1 pull - nonce",
1321                     f.nonce, sizeof(f.nonce));
1322         wpa_hexdump(MSG_DEBUG, "FT: PMK-R1 pull - PMKR0Name",
1323                     f.pmk_r0_name, WPA_PMK_NAME_LEN);
1324         wpa_printf(MSG_DEBUG, "FT: PMK-R1 pull - R1KH-ID=" MACSTR "S1KH-ID="
1325                    MACSTR, MAC2STR(f.r1kh_id), MAC2STR(f.s1kh_id));
1326
1327         os_memset(&resp, 0, sizeof(resp));
1328         resp.frame_type = RSN_REMOTE_FRAME_TYPE_FT_RRB;
1329         resp.packet_type = FT_PACKET_R0KH_R1KH_RESP;
1330         resp.data_length = host_to_le16(FT_R0KH_R1KH_RESP_DATA_LEN);
1331         os_memcpy(resp.ap_address, wpa_auth->addr, ETH_ALEN);
1332
1333         /* aes_wrap() does not support inplace encryption, so use a temporary
1334          * buffer for the data. */
1335         os_memcpy(r.nonce, f.nonce, sizeof(f.nonce));
1336         os_memcpy(r.r1kh_id, f.r1kh_id, FT_R1KH_ID_LEN);
1337         os_memcpy(r.s1kh_id, f.s1kh_id, ETH_ALEN);
1338         if (wpa_ft_fetch_pmk_r0(wpa_auth, f.s1kh_id, f.pmk_r0_name, pmk_r0,
1339                                 &pairwise) < 0) {
1340                 wpa_printf(MSG_DEBUG, "FT: No matching PMKR0Name found for "
1341                            "PMK-R1 pull");
1342                 return -1;
1343         }
1344
1345         wpa_derive_pmk_r1(pmk_r0, f.pmk_r0_name, f.r1kh_id, f.s1kh_id,
1346                           r.pmk_r1, r.pmk_r1_name);
1347         wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R1", r.pmk_r1, PMK_LEN);
1348         wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name", r.pmk_r1_name,
1349                     WPA_PMK_NAME_LEN);
1350         r.pairwise = pairwise;
1351
1352         if (aes_wrap(r1kh->key, (FT_R0KH_R1KH_RESP_DATA_LEN + 7) / 8,
1353                      r.nonce, resp.nonce) < 0) {
1354                 os_memset(pmk_r0, 0, PMK_LEN);
1355                 return -1;
1356         }
1357
1358         os_memset(pmk_r0, 0, PMK_LEN);
1359
1360         wpa_ft_rrb_send(wpa_auth, src_addr, (u8 *) &resp, sizeof(resp));
1361
1362         return 0;
1363 }
1364
1365
1366 static int wpa_ft_rrb_rx_resp(struct wpa_authenticator *wpa_auth,
1367                               const u8 *src_addr,
1368                               const u8 *data, size_t data_len)
1369 {
1370         struct ft_r0kh_r1kh_resp_frame *frame, f;
1371         struct ft_remote_r0kh *r0kh;
1372         int pairwise;
1373
1374         wpa_printf(MSG_DEBUG, "FT: Received PMK-R1 pull response");
1375
1376         if (data_len < sizeof(*frame))
1377                 return -1;
1378
1379         r0kh = wpa_auth->conf.r0kh_list;
1380         while (r0kh) {
1381                 if (os_memcmp(r0kh->addr, src_addr, ETH_ALEN) == 0)
1382                         break;
1383                 r0kh = r0kh->next;
1384         }
1385         if (r0kh == NULL) {
1386                 wpa_printf(MSG_DEBUG, "FT: No matching R0KH address found for "
1387                            "PMK-R0 pull response source address " MACSTR,
1388                            MAC2STR(src_addr));
1389                 return -1;
1390         }
1391
1392         frame = (struct ft_r0kh_r1kh_resp_frame *) data;
1393         /* aes_unwrap() does not support inplace decryption, so use a temporary
1394          * buffer for the data. */
1395         if (aes_unwrap(r0kh->key, (FT_R0KH_R1KH_RESP_DATA_LEN + 7) / 8,
1396                        frame->nonce, f.nonce) < 0) {
1397                 wpa_printf(MSG_DEBUG, "FT: Failed to decrypt PMK-R1 pull "
1398                            "response from " MACSTR, MAC2STR(src_addr));
1399                 return -1;
1400         }
1401
1402         if (os_memcmp(f.r1kh_id, wpa_auth->conf.r1_key_holder, FT_R1KH_ID_LEN)
1403             != 0) {
1404                 wpa_printf(MSG_DEBUG, "FT: PMK-R1 pull response did not use a "
1405                            "matching R1KH-ID");
1406                 return -1;
1407         }
1408
1409         /* TODO: verify that <nonce,s1kh_id> matches with a pending request
1410          * and call this requests callback function to finish request
1411          * processing */
1412
1413         pairwise = le_to_host16(f.pairwise);
1414         wpa_hexdump(MSG_DEBUG, "FT: PMK-R1 pull - nonce",
1415                     f.nonce, sizeof(f.nonce));
1416         wpa_printf(MSG_DEBUG, "FT: PMK-R1 pull - R1KH-ID=" MACSTR "S1KH-ID="
1417                    MACSTR " pairwise=0x%x",
1418                    MAC2STR(f.r1kh_id), MAC2STR(f.s1kh_id), pairwise);
1419         wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R1 pull - PMK-R1",
1420                         f.pmk_r1, PMK_LEN);
1421         wpa_hexdump(MSG_DEBUG, "FT: PMK-R1 pull - PMKR1Name",
1422                         f.pmk_r1_name, WPA_PMK_NAME_LEN);
1423
1424         wpa_ft_store_pmk_r1(wpa_auth, f.s1kh_id, f.pmk_r1, f.pmk_r1_name,
1425                             pairwise);
1426         os_memset(f.pmk_r1, 0, PMK_LEN);
1427
1428         return 0;
1429 }
1430
1431
1432 static int wpa_ft_rrb_rx_push(struct wpa_authenticator *wpa_auth,
1433                               const u8 *src_addr,
1434                               const u8 *data, size_t data_len)
1435 {
1436         struct ft_r0kh_r1kh_push_frame *frame, f;
1437         struct ft_remote_r0kh *r0kh;
1438         struct os_time now;
1439         os_time_t tsend;
1440         int pairwise;
1441
1442         wpa_printf(MSG_DEBUG, "FT: Received PMK-R1 push");
1443
1444         if (data_len < sizeof(*frame))
1445                 return -1;
1446
1447         r0kh = wpa_auth->conf.r0kh_list;
1448         while (r0kh) {
1449                 if (os_memcmp(r0kh->addr, src_addr, ETH_ALEN) == 0)
1450                         break;
1451                 r0kh = r0kh->next;
1452         }
1453         if (r0kh == NULL) {
1454                 wpa_printf(MSG_DEBUG, "FT: No matching R0KH address found for "
1455                            "PMK-R0 push source address " MACSTR,
1456                            MAC2STR(src_addr));
1457                 return -1;
1458         }
1459
1460         frame = (struct ft_r0kh_r1kh_push_frame *) data;
1461         /* aes_unwrap() does not support inplace decryption, so use a temporary
1462          * buffer for the data. */
1463         if (aes_unwrap(r0kh->key, (FT_R0KH_R1KH_PUSH_DATA_LEN + 7) / 8,
1464                        frame->timestamp, f.timestamp) < 0) {
1465                 wpa_printf(MSG_DEBUG, "FT: Failed to decrypt PMK-R1 push from "
1466                            MACSTR, MAC2STR(src_addr));
1467                 return -1;
1468         }
1469
1470         os_get_time(&now);
1471         tsend = WPA_GET_LE32(f.timestamp);
1472         if ((now.sec > tsend && now.sec - tsend > 60) ||
1473             (now.sec < tsend && tsend - now.sec > 60)) {
1474                 wpa_printf(MSG_DEBUG, "FT: PMK-R1 push did not have a valid "
1475                            "timestamp: sender time %d own time %d\n",
1476                            (int) tsend, (int) now.sec);
1477                 return -1;
1478         }
1479
1480         if (os_memcmp(f.r1kh_id, wpa_auth->conf.r1_key_holder, FT_R1KH_ID_LEN)
1481             != 0) {
1482                 wpa_printf(MSG_DEBUG, "FT: PMK-R1 push did not use a matching "
1483                            "R1KH-ID (received " MACSTR " own " MACSTR ")",
1484                            MAC2STR(f.r1kh_id),
1485                            MAC2STR(wpa_auth->conf.r1_key_holder));
1486                 return -1;
1487         }
1488
1489         pairwise = le_to_host16(f.pairwise);
1490         wpa_printf(MSG_DEBUG, "FT: PMK-R1 push - R1KH-ID=" MACSTR " S1KH-ID="
1491                    MACSTR " pairwise=0x%x",
1492                    MAC2STR(f.r1kh_id), MAC2STR(f.s1kh_id), pairwise);
1493         wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R1 push - PMK-R1",
1494                         f.pmk_r1, PMK_LEN);
1495         wpa_hexdump(MSG_DEBUG, "FT: PMK-R1 push - PMKR1Name",
1496                         f.pmk_r1_name, WPA_PMK_NAME_LEN);
1497
1498         wpa_ft_store_pmk_r1(wpa_auth, f.s1kh_id, f.pmk_r1, f.pmk_r1_name,
1499                             pairwise);
1500         os_memset(f.pmk_r1, 0, PMK_LEN);
1501
1502         return 0;
1503 }
1504
1505
1506 int wpa_ft_rrb_rx(struct wpa_authenticator *wpa_auth, const u8 *src_addr,
1507                   const u8 *data, size_t data_len)
1508 {
1509         struct ft_rrb_frame *frame;
1510         u16 alen;
1511         const u8 *pos, *end, *start;
1512         u8 action;
1513         const u8 *sta_addr, *target_ap_addr;
1514
1515         wpa_printf(MSG_DEBUG, "FT: RRB received frame from remote AP " MACSTR,
1516                    MAC2STR(src_addr));
1517
1518         if (data_len < sizeof(*frame)) {
1519                 wpa_printf(MSG_DEBUG, "FT: Too short RRB frame (data_len=%lu)",
1520                            (unsigned long) data_len);
1521                 return -1;
1522         }
1523
1524         pos = data;
1525         frame = (struct ft_rrb_frame *) pos;
1526         pos += sizeof(*frame);
1527
1528         alen = le_to_host16(frame->action_length);
1529         wpa_printf(MSG_DEBUG, "FT: RRB frame - frame_type=%d packet_type=%d "
1530                    "action_length=%d ap_address=" MACSTR,
1531                    frame->frame_type, frame->packet_type, alen,
1532                    MAC2STR(frame->ap_address));
1533
1534         if (frame->frame_type != RSN_REMOTE_FRAME_TYPE_FT_RRB) {
1535                 /* Discard frame per IEEE Std 802.11r-2008, 11A.10.3 */
1536                 wpa_printf(MSG_DEBUG, "FT: RRB discarded frame with "
1537                            "unrecognized type %d", frame->frame_type);
1538                 return -1;
1539         }
1540
1541         if (alen > data_len - sizeof(*frame)) {
1542                 wpa_printf(MSG_DEBUG, "FT: RRB frame too short for action "
1543                            "frame");
1544                 return -1;
1545         }
1546
1547         if (frame->packet_type == FT_PACKET_R0KH_R1KH_PULL)
1548                 return wpa_ft_rrb_rx_pull(wpa_auth, src_addr, data, data_len);
1549         if (frame->packet_type == FT_PACKET_R0KH_R1KH_RESP)
1550                 return wpa_ft_rrb_rx_resp(wpa_auth, src_addr, data, data_len);
1551         if (frame->packet_type == FT_PACKET_R0KH_R1KH_PUSH)
1552                 return wpa_ft_rrb_rx_push(wpa_auth, src_addr, data, data_len);
1553
1554         wpa_hexdump(MSG_MSGDUMP, "FT: RRB - FT Action frame", pos, alen);
1555
1556         if (alen < 1 + 1 + 2 * ETH_ALEN) {
1557                 wpa_printf(MSG_DEBUG, "FT: Too short RRB frame (not enough "
1558                            "room for Action Frame body); alen=%lu",
1559                            (unsigned long) alen);
1560                 return -1;
1561         }
1562         start = pos;
1563         end = pos + alen;
1564
1565         if (*pos != WLAN_ACTION_FT) {
1566                 wpa_printf(MSG_DEBUG, "FT: Unexpected Action frame category "
1567                            "%d", *pos);
1568                 return -1;
1569         }
1570
1571         pos++;
1572         action = *pos++;
1573         sta_addr = pos;
1574         pos += ETH_ALEN;
1575         target_ap_addr = pos;
1576         pos += ETH_ALEN;
1577         wpa_printf(MSG_DEBUG, "FT: RRB Action Frame: action=%d sta_addr="
1578                    MACSTR " target_ap_addr=" MACSTR,
1579                    action, MAC2STR(sta_addr), MAC2STR(target_ap_addr));
1580
1581         if (frame->packet_type == FT_PACKET_REQUEST) {
1582                 wpa_printf(MSG_DEBUG, "FT: FT Packet Type - Request");
1583
1584                 if (action != 1) {
1585                         wpa_printf(MSG_DEBUG, "FT: Unexpected Action %d in "
1586                                    "RRB Request", action);
1587                         return -1;
1588                 }
1589
1590                 if (os_memcmp(target_ap_addr, wpa_auth->addr, ETH_ALEN) != 0) {
1591                         wpa_printf(MSG_DEBUG, "FT: Target AP address in the "
1592                                    "RRB Request does not match with own "
1593                                    "address");
1594                         return -1;
1595                 }
1596
1597                 if (wpa_ft_rrb_rx_request(wpa_auth, frame->ap_address,
1598                                           sta_addr, pos, end - pos) < 0)
1599                         return -1;
1600         } else if (frame->packet_type == FT_PACKET_RESPONSE) {
1601                 u16 status_code;
1602
1603                 if (end - pos < 2) {
1604                         wpa_printf(MSG_DEBUG, "FT: Not enough room for status "
1605                                    "code in RRB Response");
1606                         return -1;
1607                 }
1608                 status_code = WPA_GET_LE16(pos);
1609                 pos += 2;
1610
1611                 wpa_printf(MSG_DEBUG, "FT: FT Packet Type - Response "
1612                            "(status_code=%d)", status_code);
1613
1614                 if (wpa_ft_action_send(wpa_auth, sta_addr, start, alen) < 0)
1615                         return -1;
1616         } else {
1617                 wpa_printf(MSG_DEBUG, "FT: RRB discarded frame with unknown "
1618                            "packet_type %d", frame->packet_type);
1619                 return -1;
1620         }
1621
1622         return 0;
1623 }
1624
1625
1626 static void wpa_ft_generate_pmk_r1(struct wpa_authenticator *wpa_auth,
1627                                    struct wpa_ft_pmk_r0_sa *pmk_r0,
1628                                    struct ft_remote_r1kh *r1kh,
1629                                    const u8 *s1kh_id, int pairwise)
1630 {
1631         struct ft_r0kh_r1kh_push_frame frame, f;
1632         struct os_time now;
1633
1634         os_memset(&frame, 0, sizeof(frame));
1635         frame.frame_type = RSN_REMOTE_FRAME_TYPE_FT_RRB;
1636         frame.packet_type = FT_PACKET_R0KH_R1KH_PUSH;
1637         frame.data_length = host_to_le16(FT_R0KH_R1KH_PUSH_DATA_LEN);
1638         os_memcpy(frame.ap_address, wpa_auth->addr, ETH_ALEN);
1639
1640         /* aes_wrap() does not support inplace encryption, so use a temporary
1641          * buffer for the data. */
1642         os_memcpy(f.r1kh_id, r1kh->id, FT_R1KH_ID_LEN);
1643         os_memcpy(f.s1kh_id, s1kh_id, ETH_ALEN);
1644         os_memcpy(f.pmk_r0_name, pmk_r0->pmk_r0_name, WPA_PMK_NAME_LEN);
1645         wpa_derive_pmk_r1(pmk_r0->pmk_r0, pmk_r0->pmk_r0_name, r1kh->id,
1646                           s1kh_id, f.pmk_r1, f.pmk_r1_name);
1647         wpa_printf(MSG_DEBUG, "FT: R1KH-ID " MACSTR, MAC2STR(r1kh->id));
1648         wpa_hexdump_key(MSG_DEBUG, "FT: PMK-R1", f.pmk_r1, PMK_LEN);
1649         wpa_hexdump(MSG_DEBUG, "FT: PMKR1Name", f.pmk_r1_name,
1650                     WPA_PMK_NAME_LEN);
1651         os_get_time(&now);
1652         WPA_PUT_LE32(f.timestamp, now.sec);
1653         f.pairwise = pairwise;
1654         if (aes_wrap(r1kh->key, (FT_R0KH_R1KH_PUSH_DATA_LEN + 7) / 8,
1655                      f.timestamp, frame.timestamp) < 0)
1656                 return;
1657
1658         wpa_ft_rrb_send(wpa_auth, r1kh->addr, (u8 *) &frame, sizeof(frame));
1659 }
1660
1661
1662 void wpa_ft_push_pmk_r1(struct wpa_authenticator *wpa_auth, const u8 *addr)
1663 {
1664         struct wpa_ft_pmk_r0_sa *r0;
1665         struct ft_remote_r1kh *r1kh;
1666
1667         if (!wpa_auth->conf.pmk_r1_push)
1668                 return;
1669
1670         r0 = wpa_auth->ft_pmk_cache->pmk_r0;
1671         while (r0) {
1672                 if (os_memcmp(r0->spa, addr, ETH_ALEN) == 0)
1673                         break;
1674                 r0 = r0->next;
1675         }
1676
1677         if (r0 == NULL || r0->pmk_r1_pushed)
1678                 return;
1679         r0->pmk_r1_pushed = 1;
1680
1681         wpa_printf(MSG_DEBUG, "FT: Deriving and pushing PMK-R1 keys to R1KHs "
1682                    "for STA " MACSTR, MAC2STR(addr));
1683
1684         r1kh = wpa_auth->conf.r1kh_list;
1685         while (r1kh) {
1686                 wpa_ft_generate_pmk_r1(wpa_auth, r0, r1kh, addr, r0->pairwise);
1687                 r1kh = r1kh->next;
1688         }
1689 }
1690
1691 #endif /* CONFIG_IEEE80211R */