1 /*
2 * hostapd / WPA authenticator glue code
3 * Copyright (c) 2002-2022, 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/sae.h"
16 #include "common/wpa_ctrl.h"
17 #include "common/ptksa_cache.h"
18 #include "crypto/sha1.h"
19 #include "eapol_auth/eapol_auth_sm.h"
20 #include "eapol_auth/eapol_auth_sm_i.h"
21 #include "eap_server/eap.h"
22 #include "l2_packet/l2_packet.h"
23 #include "eth_p_oui.h"
24 #include "hostapd.h"
25 #include "ieee802_1x.h"
26 #include "preauth_auth.h"
27 #include "sta_info.h"
28 #include "tkip_countermeasures.h"
29 #include "ap_drv_ops.h"
30 #include "ap_config.h"
31 #include "ieee802_11.h"
32 #include "ieee802_11_auth.h"
33 #include "pmksa_cache_auth.h"
34 #include "wpa_auth.h"
35 #include "wpa_auth_glue.h"
36
37
hostapd_wpa_auth_conf(struct hostapd_bss_config * conf,struct hostapd_config * iconf,struct wpa_auth_config * wconf)38 static void hostapd_wpa_auth_conf(struct hostapd_bss_config *conf,
39 struct hostapd_config *iconf,
40 struct wpa_auth_config *wconf)
41 {
42 int sae_pw_id;
43
44 os_memset(wconf, 0, sizeof(*wconf));
45 wconf->wpa = conf->wpa;
46 wconf->extended_key_id = conf->extended_key_id;
47 wconf->wpa_key_mgmt = conf->wpa_key_mgmt;
48 wconf->wpa_pairwise = conf->wpa_pairwise;
49 wconf->wpa_group = conf->wpa_group;
50 wconf->wpa_group_rekey = conf->wpa_group_rekey;
51 wconf->wpa_strict_rekey = conf->wpa_strict_rekey;
52 wconf->wpa_gmk_rekey = conf->wpa_gmk_rekey;
53 wconf->wpa_ptk_rekey = conf->wpa_ptk_rekey;
54 wconf->wpa_group_update_count = conf->wpa_group_update_count;
55 wconf->wpa_disable_eapol_key_retries =
56 conf->wpa_disable_eapol_key_retries;
57 wconf->wpa_pairwise_update_count = conf->wpa_pairwise_update_count;
58 wconf->rsn_pairwise = conf->rsn_pairwise;
59 wconf->rsn_preauth = conf->rsn_preauth;
60 wconf->eapol_version = conf->eapol_version;
61 #ifdef CONFIG_MACSEC
62 if (wconf->eapol_version > 2)
63 wconf->eapol_version = 2;
64 #endif /* CONFIG_MACSEC */
65 wconf->wmm_enabled = conf->wmm_enabled;
66 wconf->wmm_uapsd = conf->wmm_uapsd;
67 wconf->disable_pmksa_caching = conf->disable_pmksa_caching;
68 #ifdef CONFIG_OCV
69 wconf->ocv = conf->ocv;
70 #endif /* CONFIG_OCV */
71 wconf->okc = conf->okc;
72 wconf->ieee80211w = conf->ieee80211w;
73 wconf->beacon_prot = conf->beacon_prot;
74 wconf->group_mgmt_cipher = conf->group_mgmt_cipher;
75 wconf->sae_require_mfp = conf->sae_require_mfp;
76 #ifdef CONFIG_IEEE80211R_AP
77 wconf->ssid_len = conf->ssid.ssid_len;
78 if (wconf->ssid_len > SSID_MAX_LEN)
79 wconf->ssid_len = SSID_MAX_LEN;
80 os_memcpy(wconf->ssid, conf->ssid.ssid, wconf->ssid_len);
81 os_memcpy(wconf->mobility_domain, conf->mobility_domain,
82 MOBILITY_DOMAIN_ID_LEN);
83 if (conf->nas_identifier &&
84 os_strlen(conf->nas_identifier) <= FT_R0KH_ID_MAX_LEN) {
85 wconf->r0_key_holder_len = os_strlen(conf->nas_identifier);
86 os_memcpy(wconf->r0_key_holder, conf->nas_identifier,
87 wconf->r0_key_holder_len);
88 }
89 os_memcpy(wconf->r1_key_holder, conf->r1_key_holder, FT_R1KH_ID_LEN);
90 wconf->r0_key_lifetime = conf->r0_key_lifetime;
91 wconf->r1_max_key_lifetime = conf->r1_max_key_lifetime;
92 wconf->reassociation_deadline = conf->reassociation_deadline;
93 wconf->rkh_pos_timeout = conf->rkh_pos_timeout;
94 wconf->rkh_neg_timeout = conf->rkh_neg_timeout;
95 wconf->rkh_pull_timeout = conf->rkh_pull_timeout;
96 wconf->rkh_pull_retries = conf->rkh_pull_retries;
97 wconf->r0kh_list = &conf->r0kh_list;
98 wconf->r1kh_list = &conf->r1kh_list;
99 wconf->pmk_r1_push = conf->pmk_r1_push;
100 wconf->ft_over_ds = conf->ft_over_ds;
101 wconf->ft_psk_generate_local = conf->ft_psk_generate_local;
102 #endif /* CONFIG_IEEE80211R_AP */
103 #ifdef CONFIG_HS20
104 wconf->disable_gtk = conf->disable_dgaf;
105 if (conf->osen) {
106 wconf->disable_gtk = 1;
107 wconf->wpa = WPA_PROTO_OSEN;
108 wconf->wpa_key_mgmt = WPA_KEY_MGMT_OSEN;
109 wconf->wpa_pairwise = 0;
110 wconf->wpa_group = WPA_CIPHER_CCMP;
111 wconf->rsn_pairwise = WPA_CIPHER_CCMP;
112 wconf->rsn_preauth = 0;
113 wconf->disable_pmksa_caching = 1;
114 wconf->ieee80211w = 1;
115 }
116 #endif /* CONFIG_HS20 */
117 #ifdef CONFIG_TESTING_OPTIONS
118 wconf->corrupt_gtk_rekey_mic_probability =
119 iconf->corrupt_gtk_rekey_mic_probability;
120 if (conf->own_ie_override &&
121 wpabuf_len(conf->own_ie_override) <= MAX_OWN_IE_OVERRIDE) {
122 wconf->own_ie_override_len = wpabuf_len(conf->own_ie_override);
123 os_memcpy(wconf->own_ie_override,
124 wpabuf_head(conf->own_ie_override),
125 wconf->own_ie_override_len);
126 }
127 if (conf->rsne_override_eapol &&
128 wpabuf_len(conf->rsne_override_eapol) <= MAX_OWN_IE_OVERRIDE) {
129 wconf->rsne_override_eapol_set = 1;
130 wconf->rsne_override_eapol_len =
131 wpabuf_len(conf->rsne_override_eapol);
132 os_memcpy(wconf->rsne_override_eapol,
133 wpabuf_head(conf->rsne_override_eapol),
134 wconf->rsne_override_eapol_len);
135 }
136 if (conf->rsnxe_override_eapol &&
137 wpabuf_len(conf->rsnxe_override_eapol) <= MAX_OWN_IE_OVERRIDE) {
138 wconf->rsnxe_override_eapol_set = 1;
139 wconf->rsnxe_override_eapol_len =
140 wpabuf_len(conf->rsnxe_override_eapol);
141 os_memcpy(wconf->rsnxe_override_eapol,
142 wpabuf_head(conf->rsnxe_override_eapol),
143 wconf->rsnxe_override_eapol_len);
144 }
145 if (conf->rsne_override_ft &&
146 wpabuf_len(conf->rsne_override_ft) <= MAX_OWN_IE_OVERRIDE) {
147 wconf->rsne_override_ft_set = 1;
148 wconf->rsne_override_ft_len =
149 wpabuf_len(conf->rsne_override_ft);
150 os_memcpy(wconf->rsne_override_ft,
151 wpabuf_head(conf->rsne_override_ft),
152 wconf->rsne_override_ft_len);
153 }
154 if (conf->rsnxe_override_ft &&
155 wpabuf_len(conf->rsnxe_override_ft) <= MAX_OWN_IE_OVERRIDE) {
156 wconf->rsnxe_override_ft_set = 1;
157 wconf->rsnxe_override_ft_len =
158 wpabuf_len(conf->rsnxe_override_ft);
159 os_memcpy(wconf->rsnxe_override_ft,
160 wpabuf_head(conf->rsnxe_override_ft),
161 wconf->rsnxe_override_ft_len);
162 }
163 if (conf->gtk_rsc_override &&
164 wpabuf_len(conf->gtk_rsc_override) > 0 &&
165 wpabuf_len(conf->gtk_rsc_override) <= WPA_KEY_RSC_LEN) {
166 os_memcpy(wconf->gtk_rsc_override,
167 wpabuf_head(conf->gtk_rsc_override),
168 wpabuf_len(conf->gtk_rsc_override));
169 wconf->gtk_rsc_override_set = 1;
170 }
171 if (conf->igtk_rsc_override &&
172 wpabuf_len(conf->igtk_rsc_override) > 0 &&
173 wpabuf_len(conf->igtk_rsc_override) <= WPA_KEY_RSC_LEN) {
174 os_memcpy(wconf->igtk_rsc_override,
175 wpabuf_head(conf->igtk_rsc_override),
176 wpabuf_len(conf->igtk_rsc_override));
177 wconf->igtk_rsc_override_set = 1;
178 }
179 wconf->ft_rsnxe_used = conf->ft_rsnxe_used;
180 wconf->oci_freq_override_eapol_m3 = conf->oci_freq_override_eapol_m3;
181 wconf->oci_freq_override_eapol_g1 = conf->oci_freq_override_eapol_g1;
182 wconf->oci_freq_override_ft_assoc = conf->oci_freq_override_ft_assoc;
183 wconf->oci_freq_override_fils_assoc =
184 conf->oci_freq_override_fils_assoc;
185 wconf->skip_send_eapol = iconf->skip_send_eapol;
186 wconf->enable_eapol_large_timeout = iconf->enable_eapol_large_timeout;
187 #endif /* CONFIG_TESTING_OPTIONS */
188 #ifdef CONFIG_P2P
189 os_memcpy(wconf->ip_addr_go, conf->ip_addr_go, 4);
190 os_memcpy(wconf->ip_addr_mask, conf->ip_addr_mask, 4);
191 os_memcpy(wconf->ip_addr_start, conf->ip_addr_start, 4);
192 os_memcpy(wconf->ip_addr_end, conf->ip_addr_end, 4);
193 #endif /* CONFIG_P2P */
194 #ifdef CONFIG_FILS
195 wconf->fils_cache_id_set = conf->fils_cache_id_set;
196 os_memcpy(wconf->fils_cache_id, conf->fils_cache_id,
197 FILS_CACHE_ID_LEN);
198 #endif /* CONFIG_FILS */
199 wconf->sae_pwe = conf->sae_pwe;
200 sae_pw_id = hostapd_sae_pw_id_in_use(conf);
201 if (sae_pw_id == 2 && wconf->sae_pwe != 3)
202 wconf->sae_pwe = 1;
203 else if (sae_pw_id == 1 && wconf->sae_pwe == 0)
204 wconf->sae_pwe = 2;
205 #ifdef CONFIG_SAE_PK
206 wconf->sae_pk = hostapd_sae_pk_in_use(conf);
207 #endif /* CONFIG_SAE_PK */
208 #ifdef CONFIG_OWE
209 wconf->owe_ptk_workaround = conf->owe_ptk_workaround;
210 #endif /* CONFIG_OWE */
211 wconf->transition_disable = conf->transition_disable;
212 #ifdef CONFIG_DPP2
213 wconf->dpp_pfs = conf->dpp_pfs;
214 #endif /* CONFIG_DPP2 */
215 #ifdef CONFIG_PASN
216 #ifdef CONFIG_TESTING_OPTIONS
217 wconf->force_kdk_derivation = conf->force_kdk_derivation;
218 #endif /* CONFIG_TESTING_OPTIONS */
219 #endif /* CONFIG_PASN */
220
221 wconf->radius_psk = conf->wpa_psk_radius == PSK_RADIUS_DURING_4WAY_HS;
222 }
223
224
hostapd_wpa_auth_logger(void * ctx,const u8 * addr,logger_level level,const char * txt)225 static void hostapd_wpa_auth_logger(void *ctx, const u8 *addr,
226 logger_level level, const char *txt)
227 {
228 #ifndef CONFIG_NO_HOSTAPD_LOGGER
229 struct hostapd_data *hapd = ctx;
230 int hlevel;
231
232 switch (level) {
233 case LOGGER_WARNING:
234 hlevel = HOSTAPD_LEVEL_WARNING;
235 break;
236 case LOGGER_INFO:
237 hlevel = HOSTAPD_LEVEL_INFO;
238 break;
239 case LOGGER_DEBUG:
240 default:
241 hlevel = HOSTAPD_LEVEL_DEBUG;
242 break;
243 }
244
245 hostapd_logger(hapd, addr, HOSTAPD_MODULE_WPA, hlevel, "%s", txt);
246 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
247 }
248
249
hostapd_wpa_auth_disconnect(void * ctx,const u8 * addr,u16 reason)250 static void hostapd_wpa_auth_disconnect(void *ctx, const u8 *addr,
251 u16 reason)
252 {
253 struct hostapd_data *hapd = ctx;
254 wpa_printf(MSG_DEBUG, "%s: WPA authenticator requests disconnect: "
255 "STA " MACSTR " reason %d",
256 __func__, MAC2STR(addr), reason);
257 ap_sta_disconnect(hapd, NULL, addr, reason);
258 }
259
260
hostapd_wpa_auth_mic_failure_report(void * ctx,const u8 * addr)261 static int hostapd_wpa_auth_mic_failure_report(void *ctx, const u8 *addr)
262 {
263 struct hostapd_data *hapd = ctx;
264 return michael_mic_failure(hapd, addr, 0);
265 }
266
267
hostapd_wpa_auth_psk_failure_report(void * ctx,const u8 * addr)268 static void hostapd_wpa_auth_psk_failure_report(void *ctx, const u8 *addr)
269 {
270 struct hostapd_data *hapd = ctx;
271 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR,
272 MAC2STR(addr));
273 }
274
275
hostapd_wpa_auth_set_eapol(void * ctx,const u8 * addr,wpa_eapol_variable var,int value)276 static void hostapd_wpa_auth_set_eapol(void *ctx, const u8 *addr,
277 wpa_eapol_variable var, int value)
278 {
279 struct hostapd_data *hapd = ctx;
280 struct sta_info *sta = ap_get_sta(hapd, addr);
281 if (sta == NULL)
282 return;
283 switch (var) {
284 case WPA_EAPOL_portEnabled:
285 ieee802_1x_notify_port_enabled(sta->eapol_sm, value);
286 break;
287 case WPA_EAPOL_portValid:
288 ieee802_1x_notify_port_valid(sta->eapol_sm, value);
289 break;
290 case WPA_EAPOL_authorized:
291 ieee802_1x_set_sta_authorized(hapd, sta, value);
292 break;
293 case WPA_EAPOL_portControl_Auto:
294 if (sta->eapol_sm)
295 sta->eapol_sm->portControl = Auto;
296 break;
297 case WPA_EAPOL_keyRun:
298 if (sta->eapol_sm)
299 sta->eapol_sm->keyRun = value;
300 break;
301 case WPA_EAPOL_keyAvailable:
302 if (sta->eapol_sm)
303 sta->eapol_sm->eap_if->eapKeyAvailable = value;
304 break;
305 case WPA_EAPOL_keyDone:
306 if (sta->eapol_sm)
307 sta->eapol_sm->keyDone = value;
308 break;
309 case WPA_EAPOL_inc_EapolFramesTx:
310 if (sta->eapol_sm)
311 sta->eapol_sm->dot1xAuthEapolFramesTx++;
312 break;
313 }
314 }
315
316
hostapd_wpa_auth_get_eapol(void * ctx,const u8 * addr,wpa_eapol_variable var)317 static int hostapd_wpa_auth_get_eapol(void *ctx, const u8 *addr,
318 wpa_eapol_variable var)
319 {
320 struct hostapd_data *hapd = ctx;
321 struct sta_info *sta = ap_get_sta(hapd, addr);
322 if (sta == NULL || sta->eapol_sm == NULL)
323 return -1;
324 switch (var) {
325 case WPA_EAPOL_keyRun:
326 return sta->eapol_sm->keyRun;
327 case WPA_EAPOL_keyAvailable:
328 return sta->eapol_sm->eap_if->eapKeyAvailable;
329 default:
330 return -1;
331 }
332 }
333
334
hostapd_wpa_auth_get_psk(void * ctx,const u8 * addr,const u8 * p2p_dev_addr,const u8 * prev_psk,size_t * psk_len,int * vlan_id)335 static const u8 * hostapd_wpa_auth_get_psk(void *ctx, const u8 *addr,
336 const u8 *p2p_dev_addr,
337 const u8 *prev_psk, size_t *psk_len,
338 int *vlan_id)
339 {
340 struct hostapd_data *hapd = ctx;
341 struct sta_info *sta = ap_get_sta(hapd, addr);
342 const u8 *psk;
343
344 if (vlan_id)
345 *vlan_id = 0;
346 if (psk_len)
347 *psk_len = PMK_LEN;
348
349 #ifdef CONFIG_SAE
350 if (sta && sta->auth_alg == WLAN_AUTH_SAE) {
351 if (!sta->sae || prev_psk)
352 return NULL;
353 return sta->sae->pmk;
354 }
355 if (sta && wpa_auth_uses_sae(sta->wpa_sm)) {
356 wpa_printf(MSG_DEBUG,
357 "No PSK for STA trying to use SAE with PMKSA caching");
358 return NULL;
359 }
360 #endif /* CONFIG_SAE */
361
362 #ifdef CONFIG_OWE
363 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
364 sta && sta->owe_pmk) {
365 if (psk_len)
366 *psk_len = sta->owe_pmk_len;
367 return sta->owe_pmk;
368 }
369 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) && sta) {
370 struct rsn_pmksa_cache_entry *sa;
371
372 sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
373 if (sa && sa->akmp == WPA_KEY_MGMT_OWE) {
374 if (psk_len)
375 *psk_len = sa->pmk_len;
376 return sa->pmk;
377 }
378 }
379 #endif /* CONFIG_OWE */
380
381 psk = hostapd_get_psk(hapd->conf, addr, p2p_dev_addr, prev_psk,
382 vlan_id);
383 /*
384 * This is about to iterate over all psks, prev_psk gives the last
385 * returned psk which should not be returned again.
386 * logic list (all hostapd_get_psk; all sta->psk)
387 */
388 if (sta && sta->psk && !psk) {
389 struct hostapd_sta_wpa_psk_short *pos;
390
391 if (vlan_id)
392 *vlan_id = 0;
393 psk = sta->psk->psk;
394 for (pos = sta->psk; pos; pos = pos->next) {
395 if (pos->is_passphrase) {
396 if (pbkdf2_sha1(pos->passphrase,
397 hapd->conf->ssid.ssid,
398 hapd->conf->ssid.ssid_len, 4096,
399 pos->psk, PMK_LEN) != 0) {
400 wpa_printf(MSG_WARNING,
401 "Error in pbkdf2_sha1()");
402 continue;
403 }
404 pos->is_passphrase = 0;
405 }
406 if (pos->psk == prev_psk) {
407 psk = pos->next ? pos->next->psk : NULL;
408 break;
409 }
410 }
411 }
412 return psk;
413 }
414
415
hostapd_wpa_auth_get_msk(void * ctx,const u8 * addr,u8 * msk,size_t * len)416 static int hostapd_wpa_auth_get_msk(void *ctx, const u8 *addr, u8 *msk,
417 size_t *len)
418 {
419 struct hostapd_data *hapd = ctx;
420 const u8 *key;
421 size_t keylen;
422 struct sta_info *sta;
423
424 sta = ap_get_sta(hapd, addr);
425 if (sta == NULL) {
426 wpa_printf(MSG_DEBUG, "AUTH_GET_MSK: Cannot find STA");
427 return -1;
428 }
429
430 key = ieee802_1x_get_key(sta->eapol_sm, &keylen);
431 if (key == NULL) {
432 wpa_printf(MSG_DEBUG, "AUTH_GET_MSK: Key is null, eapol_sm: %p",
433 sta->eapol_sm);
434 return -1;
435 }
436
437 if (keylen > *len)
438 keylen = *len;
439 os_memcpy(msk, key, keylen);
440 *len = keylen;
441
442 return 0;
443 }
444
445
hostapd_wpa_auth_set_key(void * ctx,int vlan_id,enum wpa_alg alg,const u8 * addr,int idx,u8 * key,size_t key_len,enum key_flag key_flag)446 static int hostapd_wpa_auth_set_key(void *ctx, int vlan_id, enum wpa_alg alg,
447 const u8 *addr, int idx, u8 *key,
448 size_t key_len, enum key_flag key_flag)
449 {
450 struct hostapd_data *hapd = ctx;
451 const char *ifname = hapd->conf->iface;
452
453 if (vlan_id > 0) {
454 ifname = hostapd_get_vlan_id_ifname(hapd->conf->vlan, vlan_id);
455 if (!ifname) {
456 if (!(hapd->iface->drv_flags &
457 WPA_DRIVER_FLAGS_VLAN_OFFLOAD))
458 return -1;
459 ifname = hapd->conf->iface;
460 }
461 }
462
463 #ifdef CONFIG_TESTING_OPTIONS
464 if (key_flag & KEY_FLAG_MODIFY) {
465 /* We are updating an already installed key. Don't overwrite
466 * the already stored key information with zeros.
467 */
468 } else if (addr && !is_broadcast_ether_addr(addr)) {
469 struct sta_info *sta;
470
471 sta = ap_get_sta(hapd, addr);
472 if (sta) {
473 sta->last_tk_alg = alg;
474 sta->last_tk_key_idx = idx;
475 if (key)
476 os_memcpy(sta->last_tk, key, key_len);
477 sta->last_tk_len = key_len;
478 }
479 } else if (alg == WPA_ALG_BIP_CMAC_128 ||
480 alg == WPA_ALG_BIP_GMAC_128 ||
481 alg == WPA_ALG_BIP_GMAC_256 ||
482 alg == WPA_ALG_BIP_CMAC_256) {
483 if (idx == 4 || idx == 5) {
484 hapd->last_igtk_alg = alg;
485 hapd->last_igtk_key_idx = idx;
486 if (key)
487 os_memcpy(hapd->last_igtk, key, key_len);
488 hapd->last_igtk_len = key_len;
489 } else if (idx == 6 || idx == 7) {
490 hapd->last_bigtk_alg = alg;
491 hapd->last_bigtk_key_idx = idx;
492 if (key)
493 os_memcpy(hapd->last_bigtk, key, key_len);
494 hapd->last_bigtk_len = key_len;
495 }
496 } else {
497 hapd->last_gtk_alg = alg;
498 hapd->last_gtk_key_idx = idx;
499 if (key)
500 os_memcpy(hapd->last_gtk, key, key_len);
501 hapd->last_gtk_len = key_len;
502 }
503 #endif /* CONFIG_TESTING_OPTIONS */
504 return hostapd_drv_set_key(ifname, hapd, alg, addr, idx, vlan_id, 1,
505 NULL, 0, key, key_len, key_flag);
506 }
507
508
hostapd_wpa_auth_get_seqnum(void * ctx,const u8 * addr,int idx,u8 * seq)509 static int hostapd_wpa_auth_get_seqnum(void *ctx, const u8 *addr, int idx,
510 u8 *seq)
511 {
512 struct hostapd_data *hapd = ctx;
513 return hostapd_get_seqnum(hapd->conf->iface, hapd, addr, idx, seq);
514 }
515
516
hostapd_wpa_auth_send_eapol(void * ctx,const u8 * addr,const u8 * data,size_t data_len,int encrypt)517 int hostapd_wpa_auth_send_eapol(void *ctx, const u8 *addr,
518 const u8 *data, size_t data_len,
519 int encrypt)
520 {
521 struct hostapd_data *hapd = ctx;
522 struct sta_info *sta;
523 u32 flags = 0;
524
525 #ifdef CONFIG_TESTING_OPTIONS
526 if (hapd->ext_eapol_frame_io) {
527 size_t hex_len = 2 * data_len + 1;
528 char *hex = os_malloc(hex_len);
529
530 if (hex == NULL)
531 return -1;
532 wpa_snprintf_hex(hex, hex_len, data, data_len);
533 wpa_msg(hapd->msg_ctx, MSG_INFO, "EAPOL-TX " MACSTR " %s",
534 MAC2STR(addr), hex);
535 os_free(hex);
536 return 0;
537 }
538 #endif /* CONFIG_TESTING_OPTIONS */
539
540 sta = ap_get_sta(hapd, addr);
541 if (sta)
542 flags = hostapd_sta_flags_to_drv(sta->flags);
543
544 return hostapd_drv_hapd_send_eapol(hapd, addr, data, data_len,
545 encrypt, flags);
546 }
547
548
hostapd_wpa_auth_for_each_sta(void * ctx,int (* cb)(struct wpa_state_machine * sm,void * ctx),void * cb_ctx)549 static int hostapd_wpa_auth_for_each_sta(
550 void *ctx, int (*cb)(struct wpa_state_machine *sm, void *ctx),
551 void *cb_ctx)
552 {
553 struct hostapd_data *hapd = ctx;
554 struct sta_info *sta;
555
556 for (sta = hapd->sta_list; sta; sta = sta->next) {
557 if (sta->wpa_sm && cb(sta->wpa_sm, cb_ctx))
558 return 1;
559 }
560 return 0;
561 }
562
563
564 struct wpa_auth_iface_iter_data {
565 int (*cb)(struct wpa_authenticator *sm, void *ctx);
566 void *cb_ctx;
567 };
568
wpa_auth_iface_iter(struct hostapd_iface * iface,void * ctx)569 static int wpa_auth_iface_iter(struct hostapd_iface *iface, void *ctx)
570 {
571 struct wpa_auth_iface_iter_data *data = ctx;
572 size_t i;
573 for (i = 0; i < iface->num_bss; i++) {
574 if (iface->bss[i]->wpa_auth &&
575 data->cb(iface->bss[i]->wpa_auth, data->cb_ctx))
576 return 1;
577 }
578 return 0;
579 }
580
581
hostapd_wpa_auth_for_each_auth(void * ctx,int (* cb)(struct wpa_authenticator * sm,void * ctx),void * cb_ctx)582 static int hostapd_wpa_auth_for_each_auth(
583 void *ctx, int (*cb)(struct wpa_authenticator *sm, void *ctx),
584 void *cb_ctx)
585 {
586 struct hostapd_data *hapd = ctx;
587 struct wpa_auth_iface_iter_data data;
588 if (hapd->iface->interfaces == NULL ||
589 hapd->iface->interfaces->for_each_interface == NULL)
590 return -1;
591 data.cb = cb;
592 data.cb_ctx = cb_ctx;
593 return hapd->iface->interfaces->for_each_interface(
594 hapd->iface->interfaces, wpa_auth_iface_iter, &data);
595 }
596
597
598 #ifdef CONFIG_IEEE80211R_AP
599
600 struct wpa_ft_rrb_rx_later_data {
601 struct dl_list list;
602 u8 addr[ETH_ALEN];
603 size_t data_len;
604 /* followed by data_len octets of data */
605 };
606
hostapd_wpa_ft_rrb_rx_later(void * eloop_ctx,void * timeout_ctx)607 static void hostapd_wpa_ft_rrb_rx_later(void *eloop_ctx, void *timeout_ctx)
608 {
609 struct hostapd_data *hapd = eloop_ctx;
610 struct wpa_ft_rrb_rx_later_data *data, *n;
611
612 dl_list_for_each_safe(data, n, &hapd->l2_queue,
613 struct wpa_ft_rrb_rx_later_data, list) {
614 if (hapd->wpa_auth) {
615 wpa_ft_rrb_rx(hapd->wpa_auth, data->addr,
616 (const u8 *) (data + 1),
617 data->data_len);
618 }
619 dl_list_del(&data->list);
620 os_free(data);
621 }
622 }
623
624
625 struct wpa_auth_ft_iface_iter_data {
626 struct hostapd_data *src_hapd;
627 const u8 *dst;
628 const u8 *data;
629 size_t data_len;
630 };
631
632
hostapd_wpa_auth_ft_iter(struct hostapd_iface * iface,void * ctx)633 static int hostapd_wpa_auth_ft_iter(struct hostapd_iface *iface, void *ctx)
634 {
635 struct wpa_auth_ft_iface_iter_data *idata = ctx;
636 struct wpa_ft_rrb_rx_later_data *data;
637 struct hostapd_data *hapd;
638 size_t j;
639
640 for (j = 0; j < iface->num_bss; j++) {
641 hapd = iface->bss[j];
642 if (hapd == idata->src_hapd ||
643 !hapd->wpa_auth ||
644 os_memcmp(hapd->own_addr, idata->dst, ETH_ALEN) != 0)
645 continue;
646
647 wpa_printf(MSG_DEBUG,
648 "FT: Send RRB data directly to locally managed BSS "
649 MACSTR "@%s -> " MACSTR "@%s",
650 MAC2STR(idata->src_hapd->own_addr),
651 idata->src_hapd->conf->iface,
652 MAC2STR(hapd->own_addr), hapd->conf->iface);
653
654 /* Defer wpa_ft_rrb_rx() until next eloop step as this is
655 * when it would be triggered when reading from a socket.
656 * This avoids
657 * hapd0:send -> hapd1:recv -> hapd1:send -> hapd0:recv,
658 * that is calling hapd0:recv handler from within
659 * hapd0:send directly.
660 */
661 data = os_zalloc(sizeof(*data) + idata->data_len);
662 if (!data)
663 return 1;
664
665 os_memcpy(data->addr, idata->src_hapd->own_addr, ETH_ALEN);
666 os_memcpy(data + 1, idata->data, idata->data_len);
667 data->data_len = idata->data_len;
668
669 dl_list_add(&hapd->l2_queue, &data->list);
670
671 if (!eloop_is_timeout_registered(hostapd_wpa_ft_rrb_rx_later,
672 hapd, NULL))
673 eloop_register_timeout(0, 0,
674 hostapd_wpa_ft_rrb_rx_later,
675 hapd, NULL);
676
677 return 1;
678 }
679
680 return 0;
681 }
682
683 #endif /* CONFIG_IEEE80211R_AP */
684
685
hostapd_wpa_auth_send_ether(void * ctx,const u8 * dst,u16 proto,const u8 * data,size_t data_len)686 static int hostapd_wpa_auth_send_ether(void *ctx, const u8 *dst, u16 proto,
687 const u8 *data, size_t data_len)
688 {
689 struct hostapd_data *hapd = ctx;
690 struct l2_ethhdr *buf;
691 int ret;
692
693 #ifdef CONFIG_TESTING_OPTIONS
694 if (hapd->ext_eapol_frame_io && proto == ETH_P_EAPOL) {
695 size_t hex_len = 2 * data_len + 1;
696 char *hex = os_malloc(hex_len);
697
698 if (hex == NULL)
699 return -1;
700 wpa_snprintf_hex(hex, hex_len, data, data_len);
701 wpa_msg(hapd->msg_ctx, MSG_INFO, "EAPOL-TX " MACSTR " %s",
702 MAC2STR(dst), hex);
703 os_free(hex);
704 return 0;
705 }
706 #endif /* CONFIG_TESTING_OPTIONS */
707
708 #ifdef CONFIG_IEEE80211R_AP
709 if (proto == ETH_P_RRB && hapd->iface->interfaces &&
710 hapd->iface->interfaces->for_each_interface) {
711 int res;
712 struct wpa_auth_ft_iface_iter_data idata;
713 idata.src_hapd = hapd;
714 idata.dst = dst;
715 idata.data = data;
716 idata.data_len = data_len;
717 res = hapd->iface->interfaces->for_each_interface(
718 hapd->iface->interfaces, hostapd_wpa_auth_ft_iter,
719 &idata);
720 if (res == 1)
721 return data_len;
722 }
723 #endif /* CONFIG_IEEE80211R_AP */
724
725 if (hapd->l2 == NULL)
726 return -1;
727
728 buf = os_malloc(sizeof(*buf) + data_len);
729 if (buf == NULL)
730 return -1;
731 os_memcpy(buf->h_dest, dst, ETH_ALEN);
732 os_memcpy(buf->h_source, hapd->own_addr, ETH_ALEN);
733 buf->h_proto = host_to_be16(proto);
734 os_memcpy(buf + 1, data, data_len);
735 ret = l2_packet_send(hapd->l2, dst, proto, (u8 *) buf,
736 sizeof(*buf) + data_len);
737 os_free(buf);
738 return ret;
739 }
740
741
742 #ifdef CONFIG_ETH_P_OUI
hostapd_wpa_get_oui(struct hostapd_data * hapd,u8 oui_suffix)743 static struct eth_p_oui_ctx * hostapd_wpa_get_oui(struct hostapd_data *hapd,
744 u8 oui_suffix)
745 {
746 switch (oui_suffix) {
747 #ifdef CONFIG_IEEE80211R_AP
748 case FT_PACKET_R0KH_R1KH_PULL:
749 return hapd->oui_pull;
750 case FT_PACKET_R0KH_R1KH_RESP:
751 return hapd->oui_resp;
752 case FT_PACKET_R0KH_R1KH_PUSH:
753 return hapd->oui_push;
754 case FT_PACKET_R0KH_R1KH_SEQ_REQ:
755 return hapd->oui_sreq;
756 case FT_PACKET_R0KH_R1KH_SEQ_RESP:
757 return hapd->oui_sresp;
758 #endif /* CONFIG_IEEE80211R_AP */
759 default:
760 return NULL;
761 }
762 }
763 #endif /* CONFIG_ETH_P_OUI */
764
765
766 #ifdef CONFIG_IEEE80211R_AP
767
768 struct oui_deliver_later_data {
769 struct dl_list list;
770 u8 src_addr[ETH_ALEN];
771 u8 dst_addr[ETH_ALEN];
772 size_t data_len;
773 u8 oui_suffix;
774 /* followed by data_len octets of data */
775 };
776
hostapd_oui_deliver_later(void * eloop_ctx,void * timeout_ctx)777 static void hostapd_oui_deliver_later(void *eloop_ctx, void *timeout_ctx)
778 {
779 struct hostapd_data *hapd = eloop_ctx;
780 struct oui_deliver_later_data *data, *n;
781 struct eth_p_oui_ctx *oui_ctx;
782
783 dl_list_for_each_safe(data, n, &hapd->l2_oui_queue,
784 struct oui_deliver_later_data, list) {
785 oui_ctx = hostapd_wpa_get_oui(hapd, data->oui_suffix);
786 wpa_printf(MSG_DEBUG, "RRB(%s): %s src=" MACSTR " dst=" MACSTR
787 " oui_suffix=%u data_len=%u data=%p",
788 hapd->conf->iface, __func__,
789 MAC2STR(data->src_addr), MAC2STR(data->dst_addr),
790 data->oui_suffix, (unsigned int) data->data_len,
791 data);
792 if (hapd->wpa_auth && oui_ctx) {
793 eth_p_oui_deliver(oui_ctx, data->src_addr,
794 data->dst_addr,
795 (const u8 *) (data + 1),
796 data->data_len);
797 }
798 dl_list_del(&data->list);
799 os_free(data);
800 }
801 }
802
803
804 struct wpa_auth_oui_iface_iter_data {
805 struct hostapd_data *src_hapd;
806 const u8 *dst_addr;
807 const u8 *data;
808 size_t data_len;
809 u8 oui_suffix;
810 };
811
hostapd_wpa_auth_oui_iter(struct hostapd_iface * iface,void * ctx)812 static int hostapd_wpa_auth_oui_iter(struct hostapd_iface *iface, void *ctx)
813 {
814 struct wpa_auth_oui_iface_iter_data *idata = ctx;
815 struct oui_deliver_later_data *data;
816 struct hostapd_data *hapd, *src_hapd = idata->src_hapd;
817 size_t j;
818
819 for (j = 0; j < iface->num_bss; j++) {
820 hapd = iface->bss[j];
821 if (hapd == src_hapd)
822 continue; /* don't deliver back to same interface */
823 if (!wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) ||
824 hapd->conf->ssid.ssid_len !=
825 src_hapd->conf->ssid.ssid_len ||
826 os_memcmp(hapd->conf->ssid.ssid,
827 src_hapd->conf->ssid.ssid,
828 hapd->conf->ssid.ssid_len) != 0 ||
829 os_memcmp(hapd->conf->mobility_domain,
830 src_hapd->conf->mobility_domain,
831 MOBILITY_DOMAIN_ID_LEN) != 0)
832 continue; /* no matching FT SSID/mobility domain */
833 if (!is_multicast_ether_addr(idata->dst_addr) &&
834 os_memcmp(hapd->own_addr, idata->dst_addr, ETH_ALEN) != 0)
835 continue; /* destination address does not match */
836
837 /* defer eth_p_oui_deliver until next eloop step as this is
838 * when it would be triggerd from reading from sock
839 * This avoids
840 * hapd0:send -> hapd1:recv -> hapd1:send -> hapd0:recv,
841 * that is calling hapd0:recv handler from within
842 * hapd0:send directly.
843 */
844 data = os_zalloc(sizeof(*data) + idata->data_len);
845 if (!data)
846 return 1;
847 wpa_printf(MSG_DEBUG,
848 "RRB(%s): local delivery to %s dst=" MACSTR
849 " oui_suffix=%u data_len=%u data=%p",
850 src_hapd->conf->iface, hapd->conf->iface,
851 MAC2STR(idata->dst_addr), idata->oui_suffix,
852 (unsigned int) idata->data_len, data);
853
854 os_memcpy(data->src_addr, src_hapd->own_addr, ETH_ALEN);
855 os_memcpy(data->dst_addr, idata->dst_addr, ETH_ALEN);
856 os_memcpy(data + 1, idata->data, idata->data_len);
857 data->data_len = idata->data_len;
858 data->oui_suffix = idata->oui_suffix;
859
860 dl_list_add_tail(&hapd->l2_oui_queue, &data->list);
861
862 if (!eloop_is_timeout_registered(hostapd_oui_deliver_later,
863 hapd, NULL))
864 eloop_register_timeout(0, 0,
865 hostapd_oui_deliver_later,
866 hapd, NULL);
867
868 /* If dst_addr is a multicast address, do not return any
869 * non-zero value here. Otherwise, the iteration of
870 * for_each_interface() will be stopped. */
871 if (!is_multicast_ether_addr(idata->dst_addr))
872 return 1;
873 }
874
875 return 0;
876 }
877
878 #endif /* CONFIG_IEEE80211R_AP */
879
880
hostapd_wpa_auth_send_oui(void * ctx,const u8 * dst,u8 oui_suffix,const u8 * data,size_t data_len)881 static int hostapd_wpa_auth_send_oui(void *ctx, const u8 *dst, u8 oui_suffix,
882 const u8 *data, size_t data_len)
883 {
884 #ifdef CONFIG_ETH_P_OUI
885 struct hostapd_data *hapd = ctx;
886 struct eth_p_oui_ctx *oui_ctx;
887
888 wpa_printf(MSG_DEBUG, "RRB(%s): send to dst=" MACSTR
889 " oui_suffix=%u data_len=%u",
890 hapd->conf->iface, MAC2STR(dst), oui_suffix,
891 (unsigned int) data_len);
892 #ifdef CONFIG_IEEE80211R_AP
893 if (hapd->iface->interfaces &&
894 hapd->iface->interfaces->for_each_interface) {
895 struct wpa_auth_oui_iface_iter_data idata;
896 int res;
897
898 idata.src_hapd = hapd;
899 idata.dst_addr = dst;
900 idata.data = data;
901 idata.data_len = data_len;
902 idata.oui_suffix = oui_suffix;
903 res = hapd->iface->interfaces->for_each_interface(
904 hapd->iface->interfaces, hostapd_wpa_auth_oui_iter,
905 &idata);
906 if (res == 1)
907 return data_len;
908 }
909 #endif /* CONFIG_IEEE80211R_AP */
910
911 oui_ctx = hostapd_wpa_get_oui(hapd, oui_suffix);
912 if (!oui_ctx)
913 return -1;
914
915 return eth_p_oui_send(oui_ctx, hapd->own_addr, dst, data, data_len);
916 #else /* CONFIG_ETH_P_OUI */
917 return -1;
918 #endif /* CONFIG_ETH_P_OUI */
919 }
920
921
hostapd_channel_info(void * ctx,struct wpa_channel_info * ci)922 static int hostapd_channel_info(void *ctx, struct wpa_channel_info *ci)
923 {
924 struct hostapd_data *hapd = ctx;
925
926 return hostapd_drv_channel_info(hapd, ci);
927 }
928
929
930 #ifdef CONFIG_PASN
931
hostapd_store_ptksa(void * ctx,const u8 * addr,int cipher,u32 life_time,const struct wpa_ptk * ptk)932 static void hostapd_store_ptksa(void *ctx, const u8 *addr,int cipher,
933 u32 life_time, const struct wpa_ptk *ptk)
934 {
935 struct hostapd_data *hapd = ctx;
936
937 ptksa_cache_add(hapd->ptksa, addr, cipher, life_time, ptk);
938 }
939
940
hostapd_clear_ptksa(void * ctx,const u8 * addr,int cipher)941 static void hostapd_clear_ptksa(void *ctx, const u8 *addr, int cipher)
942 {
943 struct hostapd_data *hapd = ctx;
944
945 ptksa_cache_flush(hapd->ptksa, addr, cipher);
946 }
947
948 #endif /* CONFIG_PASN */
949
950
hostapd_wpa_auth_update_vlan(void * ctx,const u8 * addr,int vlan_id)951 static int hostapd_wpa_auth_update_vlan(void *ctx, const u8 *addr, int vlan_id)
952 {
953 #ifndef CONFIG_NO_VLAN
954 struct hostapd_data *hapd = ctx;
955 struct sta_info *sta;
956
957 sta = ap_get_sta(hapd, addr);
958 if (!sta)
959 return -1;
960
961 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) {
962 struct vlan_description vlan_desc;
963
964 os_memset(&vlan_desc, 0, sizeof(vlan_desc));
965 vlan_desc.notempty = 1;
966 vlan_desc.untagged = vlan_id;
967 if (!hostapd_vlan_valid(hapd->conf->vlan, &vlan_desc)) {
968 wpa_printf(MSG_INFO,
969 "Invalid VLAN ID %d in wpa_psk_file",
970 vlan_id);
971 return -1;
972 }
973
974 if (ap_sta_set_vlan(hapd, sta, &vlan_desc) < 0) {
975 wpa_printf(MSG_INFO,
976 "Failed to assign VLAN ID %d from wpa_psk_file to "
977 MACSTR, vlan_id, MAC2STR(sta->addr));
978 return -1;
979 }
980 } else {
981 sta->vlan_id = vlan_id;
982 }
983
984 wpa_printf(MSG_INFO,
985 "Assigned VLAN ID %d from wpa_psk_file to " MACSTR,
986 vlan_id, MAC2STR(sta->addr));
987 if ((sta->flags & WLAN_STA_ASSOC) &&
988 ap_sta_bind_vlan(hapd, sta) < 0)
989 return -1;
990 #endif /* CONFIG_NO_VLAN */
991
992 return 0;
993 }
994
995
996 #ifdef CONFIG_OCV
hostapd_get_sta_tx_params(void * ctx,const u8 * addr,int ap_max_chanwidth,int ap_seg1_idx,int * bandwidth,int * seg1_idx)997 static int hostapd_get_sta_tx_params(void *ctx, const u8 *addr,
998 int ap_max_chanwidth, int ap_seg1_idx,
999 int *bandwidth, int *seg1_idx)
1000 {
1001 struct hostapd_data *hapd = ctx;
1002 struct sta_info *sta;
1003
1004 sta = ap_get_sta(hapd, addr);
1005 if (!sta) {
1006 hostapd_wpa_auth_logger(hapd, addr, LOGGER_INFO,
1007 "Failed to get STA info to validate received OCI");
1008 return -1;
1009 }
1010
1011 return get_tx_parameters(sta, ap_max_chanwidth, ap_seg1_idx, bandwidth,
1012 seg1_idx);
1013 }
1014 #endif /* CONFIG_OCV */
1015
1016
1017 #ifdef CONFIG_IEEE80211R_AP
1018
hostapd_wpa_auth_send_ft_action(void * ctx,const u8 * dst,const u8 * data,size_t data_len)1019 static int hostapd_wpa_auth_send_ft_action(void *ctx, const u8 *dst,
1020 const u8 *data, size_t data_len)
1021 {
1022 struct hostapd_data *hapd = ctx;
1023 int res;
1024 struct ieee80211_mgmt *m;
1025 size_t mlen;
1026 struct sta_info *sta;
1027
1028 sta = ap_get_sta(hapd, dst);
1029 if (sta == NULL || sta->wpa_sm == NULL)
1030 return -1;
1031
1032 m = os_zalloc(sizeof(*m) + data_len);
1033 if (m == NULL)
1034 return -1;
1035 mlen = ((u8 *) &m->u - (u8 *) m) + data_len;
1036 m->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1037 WLAN_FC_STYPE_ACTION);
1038 os_memcpy(m->da, dst, ETH_ALEN);
1039 os_memcpy(m->sa, hapd->own_addr, ETH_ALEN);
1040 os_memcpy(m->bssid, hapd->own_addr, ETH_ALEN);
1041 os_memcpy(&m->u, data, data_len);
1042
1043 res = hostapd_drv_send_mlme(hapd, (u8 *) m, mlen, 0, NULL, 0, 0);
1044 os_free(m);
1045 return res;
1046 }
1047
1048
1049 static struct wpa_state_machine *
hostapd_wpa_auth_add_sta(void * ctx,const u8 * sta_addr)1050 hostapd_wpa_auth_add_sta(void *ctx, const u8 *sta_addr)
1051 {
1052 struct hostapd_data *hapd = ctx;
1053 struct sta_info *sta;
1054 int ret;
1055
1056 wpa_printf(MSG_DEBUG, "Add station entry for " MACSTR
1057 " based on WPA authenticator callback",
1058 MAC2STR(sta_addr));
1059 ret = hostapd_add_sta_node(hapd, sta_addr, WLAN_AUTH_FT);
1060
1061 /*
1062 * The expected return values from hostapd_add_sta_node() are
1063 * 0: successfully added STA entry
1064 * -EOPNOTSUPP: driver or driver wrapper does not support/need this
1065 * operations
1066 * any other negative value: error in adding the STA entry */
1067 if (ret < 0 && ret != -EOPNOTSUPP)
1068 return NULL;
1069
1070 sta = ap_sta_add(hapd, sta_addr);
1071 if (sta == NULL)
1072 return NULL;
1073 if (ret == 0)
1074 sta->added_unassoc = 1;
1075
1076 sta->ft_over_ds = 1;
1077 if (sta->wpa_sm) {
1078 sta->auth_alg = WLAN_AUTH_FT;
1079 return sta->wpa_sm;
1080 }
1081
1082 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, sta->addr, NULL);
1083 if (sta->wpa_sm == NULL) {
1084 ap_free_sta(hapd, sta);
1085 return NULL;
1086 }
1087 sta->auth_alg = WLAN_AUTH_FT;
1088
1089 return sta->wpa_sm;
1090 }
1091
1092
hostapd_wpa_auth_add_sta_ft(void * ctx,const u8 * sta_addr)1093 static int hostapd_wpa_auth_add_sta_ft(void *ctx, const u8 *sta_addr)
1094 {
1095 struct hostapd_data *hapd = ctx;
1096 struct sta_info *sta;
1097
1098 sta = ap_get_sta(hapd, sta_addr);
1099 if (!sta)
1100 return -1;
1101
1102 if (FULL_AP_CLIENT_STATE_SUPP(hapd->iface->drv_flags) &&
1103 (sta->flags & WLAN_STA_MFP) && ap_sta_is_authorized(sta) &&
1104 !(hapd->conf->mesh & MESH_ENABLED) && !(sta->added_unassoc)) {
1105 /* We could not do this in handle_auth() since there was a
1106 * PMF-enabled association for the STA and the new
1107 * authentication attempt was not yet fully processed. Now that
1108 * we are ready to configure the TK to the driver,
1109 * authentication has succeeded and we can clean up the driver
1110 * STA entry to avoid issues with any maintained state from the
1111 * previous association. */
1112 wpa_printf(MSG_DEBUG,
1113 "FT: Remove and re-add driver STA entry after successful FT authentication");
1114 return ap_sta_re_add(hapd, sta);
1115 }
1116
1117 return 0;
1118 }
1119
1120
hostapd_wpa_auth_set_vlan(void * ctx,const u8 * sta_addr,struct vlan_description * vlan)1121 static int hostapd_wpa_auth_set_vlan(void *ctx, const u8 *sta_addr,
1122 struct vlan_description *vlan)
1123 {
1124 struct hostapd_data *hapd = ctx;
1125 struct sta_info *sta;
1126
1127 sta = ap_get_sta(hapd, sta_addr);
1128 if (!sta || !sta->wpa_sm)
1129 return -1;
1130
1131 if (vlan->notempty &&
1132 !hostapd_vlan_valid(hapd->conf->vlan, vlan)) {
1133 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1134 HOSTAPD_LEVEL_INFO,
1135 "Invalid VLAN %d%s received from FT",
1136 vlan->untagged, vlan->tagged[0] ? "+" : "");
1137 return -1;
1138 }
1139
1140 if (ap_sta_set_vlan(hapd, sta, vlan) < 0)
1141 return -1;
1142 /* Configure wpa_group for GTK but ignore error due to driver not
1143 * knowing this STA. */
1144 ap_sta_bind_vlan(hapd, sta);
1145
1146 if (sta->vlan_id)
1147 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1148 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
1149
1150 return 0;
1151 }
1152
1153
hostapd_wpa_auth_get_vlan(void * ctx,const u8 * sta_addr,struct vlan_description * vlan)1154 static int hostapd_wpa_auth_get_vlan(void *ctx, const u8 *sta_addr,
1155 struct vlan_description *vlan)
1156 {
1157 struct hostapd_data *hapd = ctx;
1158 struct sta_info *sta;
1159
1160 sta = ap_get_sta(hapd, sta_addr);
1161 if (!sta)
1162 return -1;
1163
1164 if (sta->vlan_desc)
1165 *vlan = *sta->vlan_desc;
1166 else
1167 os_memset(vlan, 0, sizeof(*vlan));
1168
1169 return 0;
1170 }
1171
1172
1173 static int
hostapd_wpa_auth_set_identity(void * ctx,const u8 * sta_addr,const u8 * identity,size_t identity_len)1174 hostapd_wpa_auth_set_identity(void *ctx, const u8 *sta_addr,
1175 const u8 *identity, size_t identity_len)
1176 {
1177 struct hostapd_data *hapd = ctx;
1178 struct sta_info *sta;
1179
1180 sta = ap_get_sta(hapd, sta_addr);
1181 if (!sta)
1182 return -1;
1183
1184 os_free(sta->identity);
1185 sta->identity = NULL;
1186
1187 if (sta->eapol_sm) {
1188 os_free(sta->eapol_sm->identity);
1189 sta->eapol_sm->identity = NULL;
1190 sta->eapol_sm->identity_len = 0;
1191 }
1192
1193 if (!identity_len)
1194 return 0;
1195
1196 /* sta->identity is NULL terminated */
1197 sta->identity = os_zalloc(identity_len + 1);
1198 if (!sta->identity)
1199 return -1;
1200 os_memcpy(sta->identity, identity, identity_len);
1201
1202 if (sta->eapol_sm) {
1203 sta->eapol_sm->identity = os_zalloc(identity_len);
1204 if (!sta->eapol_sm->identity)
1205 return -1;
1206 os_memcpy(sta->eapol_sm->identity, identity, identity_len);
1207 sta->eapol_sm->identity_len = identity_len;
1208 }
1209
1210 return 0;
1211 }
1212
1213
1214 static size_t
hostapd_wpa_auth_get_identity(void * ctx,const u8 * sta_addr,const u8 ** buf)1215 hostapd_wpa_auth_get_identity(void *ctx, const u8 *sta_addr, const u8 **buf)
1216 {
1217 struct hostapd_data *hapd = ctx;
1218 struct sta_info *sta;
1219 size_t len;
1220 char *identity;
1221
1222 sta = ap_get_sta(hapd, sta_addr);
1223 if (!sta)
1224 return 0;
1225
1226 *buf = ieee802_1x_get_identity(sta->eapol_sm, &len);
1227 if (*buf && len)
1228 return len;
1229
1230 if (!sta->identity) {
1231 *buf = NULL;
1232 return 0;
1233 }
1234
1235 identity = sta->identity;
1236 len = os_strlen(identity);
1237 *buf = (u8 *) identity;
1238
1239 return len;
1240 }
1241
1242
1243 static int
hostapd_wpa_auth_set_radius_cui(void * ctx,const u8 * sta_addr,const u8 * radius_cui,size_t radius_cui_len)1244 hostapd_wpa_auth_set_radius_cui(void *ctx, const u8 *sta_addr,
1245 const u8 *radius_cui, size_t radius_cui_len)
1246 {
1247 struct hostapd_data *hapd = ctx;
1248 struct sta_info *sta;
1249
1250 sta = ap_get_sta(hapd, sta_addr);
1251 if (!sta)
1252 return -1;
1253
1254 os_free(sta->radius_cui);
1255 sta->radius_cui = NULL;
1256
1257 if (sta->eapol_sm) {
1258 wpabuf_free(sta->eapol_sm->radius_cui);
1259 sta->eapol_sm->radius_cui = NULL;
1260 }
1261
1262 if (!radius_cui)
1263 return 0;
1264
1265 /* sta->radius_cui is NULL terminated */
1266 sta->radius_cui = os_zalloc(radius_cui_len + 1);
1267 if (!sta->radius_cui)
1268 return -1;
1269 os_memcpy(sta->radius_cui, radius_cui, radius_cui_len);
1270
1271 if (sta->eapol_sm) {
1272 sta->eapol_sm->radius_cui = wpabuf_alloc_copy(radius_cui,
1273 radius_cui_len);
1274 if (!sta->eapol_sm->radius_cui)
1275 return -1;
1276 }
1277
1278 return 0;
1279 }
1280
1281
1282 static size_t
hostapd_wpa_auth_get_radius_cui(void * ctx,const u8 * sta_addr,const u8 ** buf)1283 hostapd_wpa_auth_get_radius_cui(void *ctx, const u8 *sta_addr, const u8 **buf)
1284 {
1285 struct hostapd_data *hapd = ctx;
1286 struct sta_info *sta;
1287 struct wpabuf *b;
1288 size_t len;
1289 char *radius_cui;
1290
1291 sta = ap_get_sta(hapd, sta_addr);
1292 if (!sta)
1293 return 0;
1294
1295 b = ieee802_1x_get_radius_cui(sta->eapol_sm);
1296 if (b) {
1297 len = wpabuf_len(b);
1298 *buf = wpabuf_head(b);
1299 return len;
1300 }
1301
1302 if (!sta->radius_cui) {
1303 *buf = NULL;
1304 return 0;
1305 }
1306
1307 radius_cui = sta->radius_cui;
1308 len = os_strlen(radius_cui);
1309 *buf = (u8 *) radius_cui;
1310
1311 return len;
1312 }
1313
1314
hostapd_wpa_auth_set_session_timeout(void * ctx,const u8 * sta_addr,int session_timeout)1315 static void hostapd_wpa_auth_set_session_timeout(void *ctx, const u8 *sta_addr,
1316 int session_timeout)
1317 {
1318 struct hostapd_data *hapd = ctx;
1319 struct sta_info *sta;
1320
1321 sta = ap_get_sta(hapd, sta_addr);
1322 if (!sta)
1323 return;
1324
1325 if (session_timeout) {
1326 os_get_reltime(&sta->session_timeout);
1327 sta->session_timeout.sec += session_timeout;
1328 sta->session_timeout_set = 1;
1329 ap_sta_session_timeout(hapd, sta, session_timeout);
1330 } else {
1331 sta->session_timeout_set = 0;
1332 ap_sta_no_session_timeout(hapd, sta);
1333 }
1334 }
1335
1336
hostapd_wpa_auth_get_session_timeout(void * ctx,const u8 * sta_addr)1337 static int hostapd_wpa_auth_get_session_timeout(void *ctx, const u8 *sta_addr)
1338 {
1339 struct hostapd_data *hapd = ctx;
1340 struct sta_info *sta;
1341 struct os_reltime now, remaining;
1342
1343 sta = ap_get_sta(hapd, sta_addr);
1344 if (!sta || !sta->session_timeout_set)
1345 return 0;
1346
1347 os_get_reltime(&now);
1348 if (os_reltime_before(&sta->session_timeout, &now)) {
1349 /* already expired, return >0 as timeout was set */
1350 return 1;
1351 }
1352
1353 os_reltime_sub(&sta->session_timeout, &now, &remaining);
1354
1355 return (remaining.sec > 0) ? remaining.sec : 1;
1356 }
1357
1358
hostapd_rrb_receive(void * ctx,const u8 * src_addr,const u8 * buf,size_t len)1359 static void hostapd_rrb_receive(void *ctx, const u8 *src_addr, const u8 *buf,
1360 size_t len)
1361 {
1362 struct hostapd_data *hapd = ctx;
1363 struct l2_ethhdr *ethhdr;
1364 if (len < sizeof(*ethhdr))
1365 return;
1366 ethhdr = (struct l2_ethhdr *) buf;
1367 wpa_printf(MSG_DEBUG, "FT: RRB received packet " MACSTR " -> "
1368 MACSTR, MAC2STR(ethhdr->h_source), MAC2STR(ethhdr->h_dest));
1369 if (!is_multicast_ether_addr(ethhdr->h_dest) &&
1370 os_memcmp(hapd->own_addr, ethhdr->h_dest, ETH_ALEN) != 0)
1371 return;
1372 wpa_ft_rrb_rx(hapd->wpa_auth, ethhdr->h_source, buf + sizeof(*ethhdr),
1373 len - sizeof(*ethhdr));
1374 }
1375
1376
hostapd_rrb_oui_receive(void * ctx,const u8 * src_addr,const u8 * dst_addr,u8 oui_suffix,const u8 * buf,size_t len)1377 static void hostapd_rrb_oui_receive(void *ctx, const u8 *src_addr,
1378 const u8 *dst_addr, u8 oui_suffix,
1379 const u8 *buf, size_t len)
1380 {
1381 struct hostapd_data *hapd = ctx;
1382
1383 wpa_printf(MSG_DEBUG, "FT: RRB received packet " MACSTR " -> "
1384 MACSTR, MAC2STR(src_addr), MAC2STR(dst_addr));
1385 if (!is_multicast_ether_addr(dst_addr) &&
1386 os_memcmp(hapd->own_addr, dst_addr, ETH_ALEN) != 0)
1387 return;
1388 wpa_ft_rrb_oui_rx(hapd->wpa_auth, src_addr, dst_addr, oui_suffix, buf,
1389 len);
1390 }
1391
1392
hostapd_wpa_auth_add_tspec(void * ctx,const u8 * sta_addr,u8 * tspec_ie,size_t tspec_ielen)1393 static int hostapd_wpa_auth_add_tspec(void *ctx, const u8 *sta_addr,
1394 u8 *tspec_ie, size_t tspec_ielen)
1395 {
1396 struct hostapd_data *hapd = ctx;
1397 return hostapd_add_tspec(hapd, sta_addr, tspec_ie, tspec_ielen);
1398 }
1399
1400
1401
hostapd_wpa_register_ft_oui(struct hostapd_data * hapd,const char * ft_iface)1402 static int hostapd_wpa_register_ft_oui(struct hostapd_data *hapd,
1403 const char *ft_iface)
1404 {
1405 hapd->oui_pull = eth_p_oui_register(hapd, ft_iface,
1406 FT_PACKET_R0KH_R1KH_PULL,
1407 hostapd_rrb_oui_receive, hapd);
1408 if (!hapd->oui_pull)
1409 return -1;
1410
1411 hapd->oui_resp = eth_p_oui_register(hapd, ft_iface,
1412 FT_PACKET_R0KH_R1KH_RESP,
1413 hostapd_rrb_oui_receive, hapd);
1414 if (!hapd->oui_resp)
1415 return -1;
1416
1417 hapd->oui_push = eth_p_oui_register(hapd, ft_iface,
1418 FT_PACKET_R0KH_R1KH_PUSH,
1419 hostapd_rrb_oui_receive, hapd);
1420 if (!hapd->oui_push)
1421 return -1;
1422
1423 hapd->oui_sreq = eth_p_oui_register(hapd, ft_iface,
1424 FT_PACKET_R0KH_R1KH_SEQ_REQ,
1425 hostapd_rrb_oui_receive, hapd);
1426 if (!hapd->oui_sreq)
1427 return -1;
1428
1429 hapd->oui_sresp = eth_p_oui_register(hapd, ft_iface,
1430 FT_PACKET_R0KH_R1KH_SEQ_RESP,
1431 hostapd_rrb_oui_receive, hapd);
1432 if (!hapd->oui_sresp)
1433 return -1;
1434
1435 return 0;
1436 }
1437
1438
hostapd_wpa_unregister_ft_oui(struct hostapd_data * hapd)1439 static void hostapd_wpa_unregister_ft_oui(struct hostapd_data *hapd)
1440 {
1441 eth_p_oui_unregister(hapd->oui_pull);
1442 hapd->oui_pull = NULL;
1443 eth_p_oui_unregister(hapd->oui_resp);
1444 hapd->oui_resp = NULL;
1445 eth_p_oui_unregister(hapd->oui_push);
1446 hapd->oui_push = NULL;
1447 eth_p_oui_unregister(hapd->oui_sreq);
1448 hapd->oui_sreq = NULL;
1449 eth_p_oui_unregister(hapd->oui_sresp);
1450 hapd->oui_sresp = NULL;
1451 }
1452 #endif /* CONFIG_IEEE80211R_AP */
1453
1454
1455 #ifndef CONFIG_NO_RADIUS
hostapd_request_radius_psk(void * ctx,const u8 * addr,int key_mgmt,const u8 * anonce,const u8 * eapol,size_t eapol_len)1456 static void hostapd_request_radius_psk(void *ctx, const u8 *addr, int key_mgmt,
1457 const u8 *anonce,
1458 const u8 *eapol, size_t eapol_len)
1459 {
1460 struct hostapd_data *hapd = ctx;
1461
1462 wpa_printf(MSG_DEBUG, "RADIUS PSK request for " MACSTR " key_mgmt=0x%x",
1463 MAC2STR(addr), key_mgmt);
1464 wpa_hexdump(MSG_DEBUG, "ANonce", anonce, WPA_NONCE_LEN);
1465 wpa_hexdump(MSG_DEBUG, "EAPOL", eapol, eapol_len);
1466 hostapd_acl_req_radius_psk(hapd, addr, key_mgmt, anonce, eapol,
1467 eapol_len);
1468 }
1469 #endif /* CONFIG_NO_RADIUS */
1470
1471
hostapd_setup_wpa(struct hostapd_data * hapd)1472 int hostapd_setup_wpa(struct hostapd_data *hapd)
1473 {
1474 struct wpa_auth_config _conf;
1475 static const struct wpa_auth_callbacks cb = {
1476 .logger = hostapd_wpa_auth_logger,
1477 .disconnect = hostapd_wpa_auth_disconnect,
1478 .mic_failure_report = hostapd_wpa_auth_mic_failure_report,
1479 .psk_failure_report = hostapd_wpa_auth_psk_failure_report,
1480 .set_eapol = hostapd_wpa_auth_set_eapol,
1481 .get_eapol = hostapd_wpa_auth_get_eapol,
1482 .get_psk = hostapd_wpa_auth_get_psk,
1483 .get_msk = hostapd_wpa_auth_get_msk,
1484 .set_key = hostapd_wpa_auth_set_key,
1485 .get_seqnum = hostapd_wpa_auth_get_seqnum,
1486 .send_eapol = hostapd_wpa_auth_send_eapol,
1487 .for_each_sta = hostapd_wpa_auth_for_each_sta,
1488 .for_each_auth = hostapd_wpa_auth_for_each_auth,
1489 .send_ether = hostapd_wpa_auth_send_ether,
1490 .send_oui = hostapd_wpa_auth_send_oui,
1491 .channel_info = hostapd_channel_info,
1492 .update_vlan = hostapd_wpa_auth_update_vlan,
1493 #ifdef CONFIG_PASN
1494 .store_ptksa = hostapd_store_ptksa,
1495 .clear_ptksa = hostapd_clear_ptksa,
1496 #endif /* CONFIG_PASN */
1497
1498 #ifdef CONFIG_OCV
1499 .get_sta_tx_params = hostapd_get_sta_tx_params,
1500 #endif /* CONFIG_OCV */
1501 #ifdef CONFIG_IEEE80211R_AP
1502 .send_ft_action = hostapd_wpa_auth_send_ft_action,
1503 .add_sta = hostapd_wpa_auth_add_sta,
1504 .add_sta_ft = hostapd_wpa_auth_add_sta_ft,
1505 .add_tspec = hostapd_wpa_auth_add_tspec,
1506 .set_vlan = hostapd_wpa_auth_set_vlan,
1507 .get_vlan = hostapd_wpa_auth_get_vlan,
1508 .set_identity = hostapd_wpa_auth_set_identity,
1509 .get_identity = hostapd_wpa_auth_get_identity,
1510 .set_radius_cui = hostapd_wpa_auth_set_radius_cui,
1511 .get_radius_cui = hostapd_wpa_auth_get_radius_cui,
1512 .set_session_timeout = hostapd_wpa_auth_set_session_timeout,
1513 .get_session_timeout = hostapd_wpa_auth_get_session_timeout,
1514 #endif /* CONFIG_IEEE80211R_AP */
1515 #ifndef CONFIG_NO_RADIUS
1516 .request_radius_psk = hostapd_request_radius_psk,
1517 #endif /* CONFIG_NO_RADIUS */
1518 };
1519 const u8 *wpa_ie;
1520 size_t wpa_ie_len;
1521
1522 hostapd_wpa_auth_conf(hapd->conf, hapd->iconf, &_conf);
1523 _conf.msg_ctx = hapd->msg_ctx;
1524 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_EAPOL_TX_STATUS)
1525 _conf.tx_status = 1;
1526 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_MLME)
1527 _conf.ap_mlme = 1;
1528
1529 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_WIRED) &&
1530 (hapd->conf->wpa_deny_ptk0_rekey == PTK0_REKEY_ALLOW_NEVER ||
1531 (hapd->conf->wpa_deny_ptk0_rekey == PTK0_REKEY_ALLOW_LOCAL_OK &&
1532 !(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_SAFE_PTK0_REKEYS)))) {
1533 wpa_msg(hapd->msg_ctx, MSG_INFO,
1534 "Disable PTK0 rekey support - replaced with disconnect");
1535 _conf.wpa_deny_ptk0_rekey = 1;
1536 }
1537
1538 if (_conf.extended_key_id &&
1539 (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_EXTENDED_KEY_ID))
1540 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Extended Key ID supported");
1541 else
1542 _conf.extended_key_id = 0;
1543
1544 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_BEACON_PROTECTION))
1545 _conf.beacon_prot = 0;
1546
1547 #ifdef CONFIG_OCV
1548 if (!(hapd->iface->drv_flags2 &
1549 (WPA_DRIVER_FLAGS2_AP_SME | WPA_DRIVER_FLAGS2_OCV)))
1550 _conf.ocv = 0;
1551 #endif /* CONFIG_OCV */
1552
1553 _conf.secure_ltf =
1554 !!(hapd->iface->drv_flags2 & WPA_DRIVER_FLAGS2_SEC_LTF);
1555 _conf.secure_rtt =
1556 !!(hapd->iface->drv_flags2 & WPA_DRIVER_FLAGS2_SEC_RTT);
1557 _conf.prot_range_neg =
1558 !!(hapd->iface->drv_flags2 & WPA_DRIVER_FLAGS2_PROT_RANGE_NEG);
1559
1560 hapd->wpa_auth = wpa_init(hapd->own_addr, &_conf, &cb, hapd);
1561 if (hapd->wpa_auth == NULL) {
1562 wpa_printf(MSG_ERROR, "WPA initialization failed.");
1563 return -1;
1564 }
1565
1566 if (hostapd_set_privacy(hapd, 1)) {
1567 wpa_printf(MSG_ERROR, "Could not set PrivacyInvoked "
1568 "for interface %s", hapd->conf->iface);
1569 return -1;
1570 }
1571
1572 wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len);
1573 if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len)) {
1574 wpa_printf(MSG_ERROR, "Failed to configure WPA IE for "
1575 "the kernel driver.");
1576 return -1;
1577 }
1578
1579 if (rsn_preauth_iface_init(hapd)) {
1580 wpa_printf(MSG_ERROR, "Initialization of RSN "
1581 "pre-authentication failed.");
1582 return -1;
1583 }
1584
1585 if (!hapd->ptksa)
1586 hapd->ptksa = ptksa_cache_init();
1587 if (!hapd->ptksa) {
1588 wpa_printf(MSG_ERROR, "Failed to allocate PTKSA cache");
1589 return -1;
1590 }
1591
1592 #ifdef CONFIG_IEEE80211R_AP
1593 if (!hostapd_drv_none(hapd) &&
1594 wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt)) {
1595 const char *ft_iface;
1596
1597 ft_iface = hapd->conf->bridge[0] ? hapd->conf->bridge :
1598 hapd->conf->iface;
1599 hapd->l2 = l2_packet_init(ft_iface, NULL, ETH_P_RRB,
1600 hostapd_rrb_receive, hapd, 1);
1601 if (!hapd->l2) {
1602 wpa_printf(MSG_ERROR, "Failed to open l2_packet "
1603 "interface");
1604 return -1;
1605 }
1606
1607 if (hostapd_wpa_register_ft_oui(hapd, ft_iface)) {
1608 wpa_printf(MSG_ERROR,
1609 "Failed to open ETH_P_OUI interface");
1610 return -1;
1611 }
1612 }
1613 #endif /* CONFIG_IEEE80211R_AP */
1614
1615 return 0;
1616
1617 }
1618
1619
hostapd_reconfig_wpa(struct hostapd_data * hapd)1620 void hostapd_reconfig_wpa(struct hostapd_data *hapd)
1621 {
1622 struct wpa_auth_config wpa_auth_conf;
1623 hostapd_wpa_auth_conf(hapd->conf, hapd->iconf, &wpa_auth_conf);
1624 wpa_reconfig(hapd->wpa_auth, &wpa_auth_conf);
1625 }
1626
1627
hostapd_deinit_wpa(struct hostapd_data * hapd)1628 void hostapd_deinit_wpa(struct hostapd_data *hapd)
1629 {
1630 ieee80211_tkip_countermeasures_deinit(hapd);
1631 ptksa_cache_deinit(hapd->ptksa);
1632 hapd->ptksa = NULL;
1633
1634 rsn_preauth_iface_deinit(hapd);
1635 if (hapd->wpa_auth) {
1636 wpa_deinit(hapd->wpa_auth);
1637 hapd->wpa_auth = NULL;
1638
1639 if (hapd->drv_priv && hostapd_set_privacy(hapd, 0)) {
1640 wpa_printf(MSG_DEBUG, "Could not disable "
1641 "PrivacyInvoked for interface %s",
1642 hapd->conf->iface);
1643 }
1644
1645 if (hapd->drv_priv &&
1646 hostapd_set_generic_elem(hapd, (u8 *) "", 0)) {
1647 wpa_printf(MSG_DEBUG, "Could not remove generic "
1648 "information element from interface %s",
1649 hapd->conf->iface);
1650 }
1651 }
1652 ieee802_1x_deinit(hapd);
1653
1654 #ifdef CONFIG_IEEE80211R_AP
1655 eloop_cancel_timeout(hostapd_wpa_ft_rrb_rx_later, hapd, ELOOP_ALL_CTX);
1656 hostapd_wpa_ft_rrb_rx_later(hapd, NULL); /* flush without delivering */
1657 eloop_cancel_timeout(hostapd_oui_deliver_later, hapd, ELOOP_ALL_CTX);
1658 hostapd_oui_deliver_later(hapd, NULL); /* flush without delivering */
1659 l2_packet_deinit(hapd->l2);
1660 hapd->l2 = NULL;
1661 hostapd_wpa_unregister_ft_oui(hapd);
1662 #endif /* CONFIG_IEEE80211R_AP */
1663
1664 #ifdef CONFIG_TESTING_OPTIONS
1665 forced_memzero(hapd->last_gtk, WPA_GTK_MAX_LEN);
1666 forced_memzero(hapd->last_igtk, WPA_IGTK_MAX_LEN);
1667 forced_memzero(hapd->last_bigtk, WPA_BIGTK_MAX_LEN);
1668 #endif /* CONFIG_TESTING_OPTIONS */
1669 }
1670