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