LCOV - code coverage report
Current view: top level - src/ap - wpa_auth_ft.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1422976643 Lines: 661 932 70.9 %
Date: 2015-02-03 Functions: 34 37 91.9 %

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

Generated by: LCOV version 1.10