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