• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * hostapd / Callback functions for driver wrappers
3  * Copyright (c) 2002-2013, 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 "radius/radius.h"
14 #include "drivers/driver.h"
15 #include "common/ieee802_11_defs.h"
16 #include "common/ieee802_11_common.h"
17 #include "common/wpa_ctrl.h"
18 #include "common/dpp.h"
19 #include "common/sae.h"
20 #include "common/hw_features_common.h"
21 #include "crypto/random.h"
22 #include "p2p/p2p.h"
23 #include "wps/wps.h"
24 #include "fst/fst.h"
25 #include "wnm_ap.h"
26 #include "hostapd.h"
27 #include "ieee802_11.h"
28 #include "ieee802_11_auth.h"
29 #include "sta_info.h"
30 #include "accounting.h"
31 #include "tkip_countermeasures.h"
32 #include "ieee802_1x.h"
33 #include "wpa_auth.h"
34 #include "wps_hostapd.h"
35 #include "ap_drv_ops.h"
36 #include "ap_config.h"
37 #include "ap_mlme.h"
38 #include "hw_features.h"
39 #include "dfs.h"
40 #include "beacon.h"
41 #include "mbo_ap.h"
42 #include "dpp_hostapd.h"
43 #include "fils_hlp.h"
44 #include "neighbor_db.h"
45 
46 
47 #ifdef CONFIG_FILS
hostapd_notify_assoc_fils_finish(struct hostapd_data * hapd,struct sta_info * sta)48 void hostapd_notify_assoc_fils_finish(struct hostapd_data *hapd,
49 				      struct sta_info *sta)
50 {
51 	u16 reply_res = WLAN_STATUS_SUCCESS;
52 	struct ieee802_11_elems elems;
53 	u8 buf[IEEE80211_MAX_MMPDU_SIZE], *p = buf;
54 	int new_assoc;
55 
56 	wpa_printf(MSG_DEBUG, "%s FILS: Finish association with " MACSTR,
57 		   __func__, MAC2STR(sta->addr));
58 	eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
59 	if (!sta->fils_pending_assoc_req)
60 		return;
61 
62 	ieee802_11_parse_elems(sta->fils_pending_assoc_req,
63 			       sta->fils_pending_assoc_req_len, &elems, 0);
64 	if (!elems.fils_session) {
65 		wpa_printf(MSG_DEBUG, "%s failed to find FILS Session element",
66 			   __func__);
67 		return;
68 	}
69 
70 	p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
71 					   elems.fils_session,
72 					   sta->fils_hlp_resp);
73 
74 	reply_res = hostapd_sta_assoc(hapd, sta->addr,
75 				      sta->fils_pending_assoc_is_reassoc,
76 				      WLAN_STATUS_SUCCESS,
77 				      buf, p - buf);
78 	ap_sta_set_authorized(hapd, sta, 1);
79 	new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
80 	sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
81 	sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
82 	hostapd_set_sta_flags(hapd, sta);
83 	wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
84 	ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
85 	hostapd_new_assoc_sta(hapd, sta, !new_assoc);
86 	os_free(sta->fils_pending_assoc_req);
87 	sta->fils_pending_assoc_req = NULL;
88 	sta->fils_pending_assoc_req_len = 0;
89 	wpabuf_free(sta->fils_hlp_resp);
90 	sta->fils_hlp_resp = NULL;
91 	wpabuf_free(sta->hlp_dhcp_discover);
92 	sta->hlp_dhcp_discover = NULL;
93 	fils_hlp_deinit(hapd);
94 
95 	/*
96 	 * Remove the station in case transmission of a success response fails
97 	 * (the STA was added associated to the driver) or if the station was
98 	 * previously added unassociated.
99 	 */
100 	if (reply_res != WLAN_STATUS_SUCCESS || sta->added_unassoc) {
101 		hostapd_drv_sta_remove(hapd, sta->addr);
102 		sta->added_unassoc = 0;
103 	}
104 }
105 #endif /* CONFIG_FILS */
106 
107 
check_sa_query_need(struct hostapd_data * hapd,struct sta_info * sta)108 static bool check_sa_query_need(struct hostapd_data *hapd, struct sta_info *sta)
109 {
110 	if ((sta->flags &
111 	     (WLAN_STA_ASSOC | WLAN_STA_MFP | WLAN_STA_AUTHORIZED)) !=
112 	    (WLAN_STA_ASSOC | WLAN_STA_MFP | WLAN_STA_AUTHORIZED))
113 		return false;
114 
115 	if (!sta->sa_query_timed_out && sta->sa_query_count > 0)
116 		ap_check_sa_query_timeout(hapd, sta);
117 
118 	if (!sta->sa_query_timed_out && (sta->auth_alg != WLAN_AUTH_FT)) {
119 		/*
120 		 * STA has already been associated with MFP and SA Query timeout
121 		 * has not been reached. Reject the association attempt
122 		 * temporarily and start SA Query, if one is not pending.
123 		 */
124 		if (sta->sa_query_count == 0)
125 			ap_sta_start_sa_query(hapd, sta);
126 
127 		return true;
128 	}
129 
130 	return false;
131 }
132 
133 
hostapd_notif_assoc(struct hostapd_data * hapd,const u8 * addr,const u8 * req_ies,size_t req_ies_len,int reassoc)134 int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
135 			const u8 *req_ies, size_t req_ies_len, int reassoc)
136 {
137 	struct sta_info *sta;
138 	int new_assoc;
139 	enum wpa_validate_result res;
140 	struct ieee802_11_elems elems;
141 	const u8 *ie;
142 	size_t ielen;
143 	u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
144 	u8 *p = buf;
145 	u16 reason = WLAN_REASON_UNSPECIFIED;
146 	int status = WLAN_STATUS_SUCCESS;
147 	const u8 *p2p_dev_addr = NULL;
148 
149 	if (addr == NULL) {
150 		/*
151 		 * This could potentially happen with unexpected event from the
152 		 * driver wrapper. This was seen at least in one case where the
153 		 * driver ended up being set to station mode while hostapd was
154 		 * running, so better make sure we stop processing such an
155 		 * event here.
156 		 */
157 		wpa_printf(MSG_DEBUG,
158 			   "hostapd_notif_assoc: Skip event with no address");
159 		return -1;
160 	}
161 
162 	if (is_multicast_ether_addr(addr) ||
163 	    is_zero_ether_addr(addr) ||
164 	    os_memcmp(addr, hapd->own_addr, ETH_ALEN) == 0) {
165 		/* Do not process any frames with unexpected/invalid SA so that
166 		 * we do not add any state for unexpected STA addresses or end
167 		 * up sending out frames to unexpected destination. */
168 		wpa_printf(MSG_DEBUG, "%s: Invalid SA=" MACSTR
169 			   " in received indication - ignore this indication silently",
170 			   __func__, MAC2STR(addr));
171 		return 0;
172 	}
173 
174 	random_add_randomness(addr, ETH_ALEN);
175 
176 	hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
177 		       HOSTAPD_LEVEL_INFO, "associated");
178 
179 	ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0);
180 	if (elems.wps_ie) {
181 		ie = elems.wps_ie - 2;
182 		ielen = elems.wps_ie_len + 2;
183 		wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq");
184 	} else if (elems.rsn_ie) {
185 		ie = elems.rsn_ie - 2;
186 		ielen = elems.rsn_ie_len + 2;
187 		wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq");
188 	} else if (elems.wpa_ie) {
189 		ie = elems.wpa_ie - 2;
190 		ielen = elems.wpa_ie_len + 2;
191 		wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq");
192 #ifdef CONFIG_HS20
193 	} else if (elems.osen) {
194 		ie = elems.osen - 2;
195 		ielen = elems.osen_len + 2;
196 		wpa_printf(MSG_DEBUG, "STA included OSEN IE in (Re)AssocReq");
197 #endif /* CONFIG_HS20 */
198 	} else {
199 		ie = NULL;
200 		ielen = 0;
201 		wpa_printf(MSG_DEBUG,
202 			   "STA did not include WPS/RSN/WPA IE in (Re)AssocReq");
203 	}
204 
205 	sta = ap_get_sta(hapd, addr);
206 	if (sta) {
207 		ap_sta_no_session_timeout(hapd, sta);
208 		accounting_sta_stop(hapd, sta);
209 
210 		/*
211 		 * Make sure that the previously registered inactivity timer
212 		 * will not remove the STA immediately.
213 		 */
214 		sta->timeout_next = STA_NULLFUNC;
215 	} else {
216 		sta = ap_sta_add(hapd, addr);
217 		if (sta == NULL) {
218 			hostapd_drv_sta_disassoc(hapd, addr,
219 						 WLAN_REASON_DISASSOC_AP_BUSY);
220 			return -1;
221 		}
222 	}
223 	sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
224 
225 	/*
226 	 * ACL configurations to the drivers (implementing AP SME and ACL
227 	 * offload) without hostapd's knowledge, can result in a disconnection
228 	 * though the driver accepts the connection. Skip the hostapd check for
229 	 * ACL if the driver supports ACL offload to avoid potentially
230 	 * conflicting ACL rules.
231 	 */
232 	if (hapd->iface->drv_max_acl_mac_addrs == 0 &&
233 	    hostapd_check_acl(hapd, addr, NULL) != HOSTAPD_ACL_ACCEPT) {
234 		wpa_printf(MSG_INFO, "STA " MACSTR " not allowed to connect",
235 			   MAC2STR(addr));
236 		reason = WLAN_REASON_UNSPECIFIED;
237 		goto fail;
238 	}
239 
240 #ifdef CONFIG_P2P
241 	if (elems.p2p) {
242 		wpabuf_free(sta->p2p_ie);
243 		sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
244 							  P2P_IE_VENDOR_TYPE);
245 		if (sta->p2p_ie)
246 			p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
247 	}
248 #endif /* CONFIG_P2P */
249 
250 #ifdef NEED_AP_MLME
251 	if (elems.ht_capabilities &&
252 	    (hapd->iface->conf->ht_capab &
253 	     HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
254 		struct ieee80211_ht_capabilities *ht_cap =
255 			(struct ieee80211_ht_capabilities *)
256 			elems.ht_capabilities;
257 
258 		if (le_to_host16(ht_cap->ht_capabilities_info) &
259 		    HT_CAP_INFO_40MHZ_INTOLERANT)
260 			ht40_intolerant_add(hapd->iface, sta);
261 	}
262 #endif /* NEED_AP_MLME */
263 
264 	check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
265 
266 #ifdef CONFIG_HS20
267 	wpabuf_free(sta->hs20_ie);
268 	if (elems.hs20 && elems.hs20_len > 4) {
269 		sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
270 						 elems.hs20_len - 4);
271 	} else
272 		sta->hs20_ie = NULL;
273 
274 	wpabuf_free(sta->roaming_consortium);
275 	if (elems.roaming_cons_sel)
276 		sta->roaming_consortium = wpabuf_alloc_copy(
277 			elems.roaming_cons_sel + 4,
278 			elems.roaming_cons_sel_len - 4);
279 	else
280 		sta->roaming_consortium = NULL;
281 #endif /* CONFIG_HS20 */
282 
283 #ifdef CONFIG_FST
284 	wpabuf_free(sta->mb_ies);
285 	if (hapd->iface->fst)
286 		sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
287 	else
288 		sta->mb_ies = NULL;
289 #endif /* CONFIG_FST */
290 
291 	mbo_ap_check_sta_assoc(hapd, sta, &elems);
292 
293 	ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
294 				    elems.supp_op_classes_len);
295 
296 	if (hapd->conf->wpa) {
297 		if (ie == NULL || ielen == 0) {
298 #ifdef CONFIG_WPS
299 			if (hapd->conf->wps_state) {
300 				wpa_printf(MSG_DEBUG,
301 					   "STA did not include WPA/RSN IE in (Re)Association Request - possible WPS use");
302 				sta->flags |= WLAN_STA_MAYBE_WPS;
303 				goto skip_wpa_check;
304 			}
305 #endif /* CONFIG_WPS */
306 
307 			wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA");
308 			reason = WLAN_REASON_INVALID_IE;
309 			status = WLAN_STATUS_INVALID_IE;
310 			goto fail;
311 		}
312 #ifdef CONFIG_WPS
313 		if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 &&
314 		    os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
315 			struct wpabuf *wps;
316 
317 			if (check_sa_query_need(hapd, sta)) {
318 				status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
319 
320 				p = hostapd_eid_assoc_comeback_time(hapd, sta,
321 								    p);
322 
323 				hostapd_sta_assoc(hapd, addr, reassoc, status,
324 						  buf, p - buf);
325 				return 0;
326 			}
327 
328 			sta->flags |= WLAN_STA_WPS;
329 			wps = ieee802_11_vendor_ie_concat(ie, ielen,
330 							  WPS_IE_VENDOR_TYPE);
331 			if (wps) {
332 				if (wps_is_20(wps)) {
333 					wpa_printf(MSG_DEBUG,
334 						   "WPS: STA supports WPS 2.0");
335 					sta->flags |= WLAN_STA_WPS2;
336 				}
337 				wpabuf_free(wps);
338 			}
339 			goto skip_wpa_check;
340 		}
341 #endif /* CONFIG_WPS */
342 
343 		if (sta->wpa_sm == NULL)
344 			sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
345 							sta->addr,
346 							p2p_dev_addr);
347 		if (sta->wpa_sm == NULL) {
348 			wpa_printf(MSG_ERROR,
349 				   "Failed to initialize WPA state machine");
350 			return -1;
351 		}
352 		res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
353 					  hapd->iface->freq,
354 					  ie, ielen,
355 					  elems.rsnxe ? elems.rsnxe - 2 : NULL,
356 					  elems.rsnxe ? elems.rsnxe_len + 2 : 0,
357 					  elems.mdie, elems.mdie_len,
358 					  elems.owe_dh, elems.owe_dh_len);
359 		reason = WLAN_REASON_INVALID_IE;
360 		status = WLAN_STATUS_INVALID_IE;
361 		switch (res) {
362 		case WPA_IE_OK:
363 			reason = WLAN_REASON_UNSPECIFIED;
364 			status = WLAN_STATUS_SUCCESS;
365 			break;
366 		case WPA_INVALID_IE:
367 			reason = WLAN_REASON_INVALID_IE;
368 			status = WLAN_STATUS_INVALID_IE;
369 			break;
370 		case WPA_INVALID_GROUP:
371 			reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
372 			status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
373 			break;
374 		case WPA_INVALID_PAIRWISE:
375 			reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID;
376 			status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
377 			break;
378 		case WPA_INVALID_AKMP:
379 			reason = WLAN_REASON_AKMP_NOT_VALID;
380 			status = WLAN_STATUS_AKMP_NOT_VALID;
381 			break;
382 		case WPA_NOT_ENABLED:
383 			reason = WLAN_REASON_INVALID_IE;
384 			status = WLAN_STATUS_INVALID_IE;
385 			break;
386 		case WPA_ALLOC_FAIL:
387 			reason = WLAN_REASON_UNSPECIFIED;
388 			status = WLAN_STATUS_UNSPECIFIED_FAILURE;
389 			break;
390 		case WPA_MGMT_FRAME_PROTECTION_VIOLATION:
391 			reason = WLAN_REASON_INVALID_IE;
392 			status = WLAN_STATUS_INVALID_IE;
393 			break;
394 		case WPA_INVALID_MGMT_GROUP_CIPHER:
395 			reason = WLAN_REASON_CIPHER_SUITE_REJECTED;
396 			status = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
397 			break;
398 		case WPA_INVALID_MDIE:
399 			reason = WLAN_REASON_INVALID_MDE;
400 			status = WLAN_STATUS_INVALID_MDIE;
401 			break;
402 		case WPA_INVALID_PROTO:
403 			reason = WLAN_REASON_INVALID_IE;
404 			status = WLAN_STATUS_INVALID_IE;
405 			break;
406 		case WPA_INVALID_PMKID:
407 			reason = WLAN_REASON_INVALID_PMKID;
408 			status = WLAN_STATUS_INVALID_PMKID;
409 			break;
410 		case WPA_DENIED_OTHER_REASON:
411 			reason = WLAN_REASON_UNSPECIFIED;
412 			status = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
413 			break;
414 		}
415 		if (status != WLAN_STATUS_SUCCESS) {
416 			wpa_printf(MSG_DEBUG,
417 				   "WPA/RSN information element rejected? (res %u)",
418 				   res);
419 			wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
420 			goto fail;
421 		}
422 
423 		if (check_sa_query_need(hapd, sta)) {
424 			status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
425 
426 			p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
427 
428 			hostapd_sta_assoc(hapd, addr, reassoc, status, buf,
429 					  p - buf);
430 			return 0;
431 		}
432 
433 		if (wpa_auth_uses_mfp(sta->wpa_sm))
434 			sta->flags |= WLAN_STA_MFP;
435 		else
436 			sta->flags &= ~WLAN_STA_MFP;
437 
438 #ifdef CONFIG_IEEE80211R_AP
439 		if (sta->auth_alg == WLAN_AUTH_FT) {
440 			status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies,
441 							 req_ies_len);
442 			if (status != WLAN_STATUS_SUCCESS) {
443 				if (status == WLAN_STATUS_INVALID_PMKID)
444 					reason = WLAN_REASON_INVALID_IE;
445 				if (status == WLAN_STATUS_INVALID_MDIE)
446 					reason = WLAN_REASON_INVALID_IE;
447 				if (status == WLAN_STATUS_INVALID_FTIE)
448 					reason = WLAN_REASON_INVALID_IE;
449 				goto fail;
450 			}
451 		}
452 #endif /* CONFIG_IEEE80211R_AP */
453 #ifdef CONFIG_SAE
454 		if (hapd->conf->sae_pwe == 2 &&
455 		    sta->auth_alg == WLAN_AUTH_SAE &&
456 		    sta->sae && !sta->sae->h2e &&
457 		    ieee802_11_rsnx_capab_len(elems.rsnxe, elems.rsnxe_len,
458 					      WLAN_RSNX_CAPAB_SAE_H2E)) {
459 			wpa_printf(MSG_INFO, "SAE: " MACSTR
460 				   " indicates support for SAE H2E, but did not use it",
461 				   MAC2STR(sta->addr));
462 			status = WLAN_STATUS_UNSPECIFIED_FAILURE;
463 			reason = WLAN_REASON_UNSPECIFIED;
464 			goto fail;
465 		}
466 #endif /* CONFIG_SAE */
467 	} else if (hapd->conf->wps_state) {
468 #ifdef CONFIG_WPS
469 		struct wpabuf *wps;
470 
471 		if (req_ies)
472 			wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
473 							  WPS_IE_VENDOR_TYPE);
474 		else
475 			wps = NULL;
476 #ifdef CONFIG_WPS_STRICT
477 		if (wps && wps_validate_assoc_req(wps) < 0) {
478 			reason = WLAN_REASON_INVALID_IE;
479 			status = WLAN_STATUS_INVALID_IE;
480 			wpabuf_free(wps);
481 			goto fail;
482 		}
483 #endif /* CONFIG_WPS_STRICT */
484 		if (wps) {
485 			sta->flags |= WLAN_STA_WPS;
486 			if (wps_is_20(wps)) {
487 				wpa_printf(MSG_DEBUG,
488 					   "WPS: STA supports WPS 2.0");
489 				sta->flags |= WLAN_STA_WPS2;
490 			}
491 		} else
492 			sta->flags |= WLAN_STA_MAYBE_WPS;
493 		wpabuf_free(wps);
494 #endif /* CONFIG_WPS */
495 #ifdef CONFIG_HS20
496 	} else if (hapd->conf->osen) {
497 		if (elems.osen == NULL) {
498 			hostapd_logger(
499 				hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
500 				HOSTAPD_LEVEL_INFO,
501 				"No HS 2.0 OSEN element in association request");
502 			return WLAN_STATUS_INVALID_IE;
503 		}
504 
505 		wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
506 		if (sta->wpa_sm == NULL)
507 			sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
508 							sta->addr, NULL);
509 		if (sta->wpa_sm == NULL) {
510 			wpa_printf(MSG_WARNING,
511 				   "Failed to initialize WPA state machine");
512 			return WLAN_STATUS_UNSPECIFIED_FAILURE;
513 		}
514 		if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
515 				      elems.osen - 2, elems.osen_len + 2) < 0)
516 			return WLAN_STATUS_INVALID_IE;
517 #endif /* CONFIG_HS20 */
518 	}
519 #ifdef CONFIG_WPS
520 skip_wpa_check:
521 #endif /* CONFIG_WPS */
522 
523 #ifdef CONFIG_MBO
524 	if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
525 	    elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
526 	    hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
527 		wpa_printf(MSG_INFO,
528 			   "MBO: Reject WPA2 association without PMF");
529 		return WLAN_STATUS_UNSPECIFIED_FAILURE;
530 	}
531 #endif /* CONFIG_MBO */
532 
533 #ifdef CONFIG_IEEE80211R_AP
534 	p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf),
535 					sta->auth_alg, req_ies, req_ies_len,
536 					!elems.rsnxe);
537 	if (!p) {
538 		wpa_printf(MSG_DEBUG, "FT: Failed to write AssocResp IEs");
539 		return WLAN_STATUS_UNSPECIFIED_FAILURE;
540 	}
541 #endif /* CONFIG_IEEE80211R_AP */
542 
543 #ifdef CONFIG_FILS
544 	if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
545 	    sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
546 	    sta->auth_alg == WLAN_AUTH_FILS_PK) {
547 		int delay_assoc = 0;
548 
549 		if (!req_ies)
550 			return WLAN_STATUS_UNSPECIFIED_FAILURE;
551 
552 		if (!wpa_fils_validate_fils_session(sta->wpa_sm, req_ies,
553 						    req_ies_len,
554 						    sta->fils_session)) {
555 			wpa_printf(MSG_DEBUG,
556 				   "FILS: Session validation failed");
557 			return WLAN_STATUS_UNSPECIFIED_FAILURE;
558 		}
559 
560 		res = wpa_fils_validate_key_confirm(sta->wpa_sm, req_ies,
561 						    req_ies_len);
562 		if (res < 0) {
563 			wpa_printf(MSG_DEBUG,
564 				   "FILS: Key Confirm validation failed");
565 			return WLAN_STATUS_UNSPECIFIED_FAILURE;
566 		}
567 
568 		if (fils_process_hlp(hapd, sta, req_ies, req_ies_len) > 0) {
569 			wpa_printf(MSG_DEBUG,
570 				   "FILS: Delaying Assoc Response (HLP)");
571 			delay_assoc = 1;
572 		} else {
573 			wpa_printf(MSG_DEBUG,
574 				   "FILS: Going ahead with Assoc Response (no HLP)");
575 		}
576 
577 		if (sta) {
578 			wpa_printf(MSG_DEBUG, "FILS: HLP callback cleanup");
579 			eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
580 			os_free(sta->fils_pending_assoc_req);
581 			sta->fils_pending_assoc_req = NULL;
582 			sta->fils_pending_assoc_req_len = 0;
583 			wpabuf_free(sta->fils_hlp_resp);
584 			sta->fils_hlp_resp = NULL;
585 			sta->fils_drv_assoc_finish = 0;
586 		}
587 
588 		if (sta && delay_assoc && status == WLAN_STATUS_SUCCESS) {
589 			u8 *req_tmp;
590 
591 			req_tmp = os_malloc(req_ies_len);
592 			if (!req_tmp) {
593 				wpa_printf(MSG_DEBUG,
594 					   "FILS: buffer allocation failed for assoc req");
595 				goto fail;
596 			}
597 			os_memcpy(req_tmp, req_ies, req_ies_len);
598 			sta->fils_pending_assoc_req = req_tmp;
599 			sta->fils_pending_assoc_req_len = req_ies_len;
600 			sta->fils_pending_assoc_is_reassoc = reassoc;
601 			sta->fils_drv_assoc_finish = 1;
602 			wpa_printf(MSG_DEBUG,
603 				   "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
604 				   MACSTR, MAC2STR(sta->addr));
605 			eloop_register_timeout(
606 				0, hapd->conf->fils_hlp_wait_time * 1024,
607 				fils_hlp_timeout, hapd, sta);
608 			return 0;
609 		}
610 		p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
611 						   elems.fils_session,
612 						   sta->fils_hlp_resp);
613 		wpa_hexdump(MSG_DEBUG, "FILS Assoc Resp BUF (IEs)",
614 			    buf, p - buf);
615 	}
616 #endif /* CONFIG_FILS */
617 
618 #ifdef CONFIG_OWE
619 	if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
620 	    wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE &&
621 	    elems.owe_dh) {
622 		u8 *npos;
623 		u16 ret_status;
624 
625 		npos = owe_assoc_req_process(hapd, sta,
626 					     elems.owe_dh, elems.owe_dh_len,
627 					     p, sizeof(buf) - (p - buf),
628 					     &ret_status);
629 		status = ret_status;
630 		if (npos)
631 			p = npos;
632 
633 		if (!npos &&
634 		    status == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) {
635 			hostapd_sta_assoc(hapd, addr, reassoc, ret_status, buf,
636 					  p - buf);
637 			return 0;
638 		}
639 
640 		if (!npos || status != WLAN_STATUS_SUCCESS)
641 			goto fail;
642 	}
643 #endif /* CONFIG_OWE */
644 
645 #ifdef CONFIG_DPP2
646 		dpp_pfs_free(sta->dpp_pfs);
647 		sta->dpp_pfs = NULL;
648 
649 		if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) &&
650 		    hapd->conf->dpp_netaccesskey && sta->wpa_sm &&
651 		    wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_DPP &&
652 		    elems.owe_dh) {
653 			sta->dpp_pfs = dpp_pfs_init(
654 				wpabuf_head(hapd->conf->dpp_netaccesskey),
655 				wpabuf_len(hapd->conf->dpp_netaccesskey));
656 			if (!sta->dpp_pfs) {
657 				wpa_printf(MSG_DEBUG,
658 					   "DPP: Could not initialize PFS");
659 				/* Try to continue without PFS */
660 				goto pfs_fail;
661 			}
662 
663 			if (dpp_pfs_process(sta->dpp_pfs, elems.owe_dh,
664 					    elems.owe_dh_len) < 0) {
665 				dpp_pfs_free(sta->dpp_pfs);
666 				sta->dpp_pfs = NULL;
667 				reason = WLAN_REASON_UNSPECIFIED;
668 				goto fail;
669 			}
670 		}
671 
672 		wpa_auth_set_dpp_z(sta->wpa_sm, sta->dpp_pfs ?
673 				   sta->dpp_pfs->secret : NULL);
674 	pfs_fail:
675 #endif /* CONFIG_DPP2 */
676 
677 	if (elems.rrm_enabled &&
678 	    elems.rrm_enabled_len >= sizeof(sta->rrm_enabled_capa))
679 	    os_memcpy(sta->rrm_enabled_capa, elems.rrm_enabled,
680 		      sizeof(sta->rrm_enabled_capa));
681 
682 #if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_FILS) || defined(CONFIG_OWE)
683 	hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
684 
685 	if (sta->auth_alg == WLAN_AUTH_FT ||
686 	    sta->auth_alg == WLAN_AUTH_FILS_SK ||
687 	    sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
688 	    sta->auth_alg == WLAN_AUTH_FILS_PK)
689 		ap_sta_set_authorized(hapd, sta, 1);
690 #else /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
691 	/* Keep compiler silent about unused variables */
692 	if (status) {
693 	}
694 #endif /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
695 
696 	new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
697 	sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
698 	sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
699 
700 	hostapd_set_sta_flags(hapd, sta);
701 
702 	if (reassoc && (sta->auth_alg == WLAN_AUTH_FT))
703 		wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
704 #ifdef CONFIG_FILS
705 	else if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
706 		 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
707 		 sta->auth_alg == WLAN_AUTH_FILS_PK)
708 		wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
709 #endif /* CONFIG_FILS */
710 	else
711 		wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
712 
713 	hostapd_new_assoc_sta(hapd, sta, !new_assoc);
714 
715 	ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
716 
717 #ifdef CONFIG_P2P
718 	if (req_ies) {
719 		p2p_group_notif_assoc(hapd->p2p_group, sta->addr,
720 				      req_ies, req_ies_len);
721 	}
722 #endif /* CONFIG_P2P */
723 
724 	return 0;
725 
726 fail:
727 #ifdef CONFIG_IEEE80211R_AP
728 	if (status >= 0)
729 		hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
730 #endif /* CONFIG_IEEE80211R_AP */
731 	hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
732 	ap_free_sta(hapd, sta);
733 	return -1;
734 }
735 
736 
hostapd_notif_disassoc(struct hostapd_data * hapd,const u8 * addr)737 void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr)
738 {
739 	struct sta_info *sta;
740 
741 	if (addr == NULL) {
742 		/*
743 		 * This could potentially happen with unexpected event from the
744 		 * driver wrapper. This was seen at least in one case where the
745 		 * driver ended up reporting a station mode event while hostapd
746 		 * was running, so better make sure we stop processing such an
747 		 * event here.
748 		 */
749 		wpa_printf(MSG_DEBUG,
750 			   "hostapd_notif_disassoc: Skip event with no address");
751 		return;
752 	}
753 
754 	hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
755 		       HOSTAPD_LEVEL_INFO, "disassociated");
756 
757 	sta = ap_get_sta(hapd, addr);
758 	if (sta == NULL) {
759 		wpa_printf(MSG_DEBUG,
760 			   "Disassociation notification for unknown STA "
761 			   MACSTR, MAC2STR(addr));
762 		return;
763 	}
764 
765 	ap_sta_set_authorized(hapd, sta, 0);
766 	sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
767 	hostapd_set_sta_flags(hapd, sta);
768 	wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
769 	sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
770 	ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
771 	ap_free_sta(hapd, sta);
772 }
773 
774 
hostapd_event_sta_low_ack(struct hostapd_data * hapd,const u8 * addr)775 void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr)
776 {
777 	struct sta_info *sta = ap_get_sta(hapd, addr);
778 
779 	if (!sta || !hapd->conf->disassoc_low_ack || sta->agreed_to_steer)
780 		return;
781 
782 	hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
783 		       HOSTAPD_LEVEL_INFO,
784 		       "disconnected due to excessive missing ACKs");
785 	hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK);
786 	ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK);
787 }
788 
789 
hostapd_event_sta_opmode_changed(struct hostapd_data * hapd,const u8 * addr,enum smps_mode smps_mode,enum chan_width chan_width,u8 rx_nss)790 void hostapd_event_sta_opmode_changed(struct hostapd_data *hapd, const u8 *addr,
791 				      enum smps_mode smps_mode,
792 				      enum chan_width chan_width, u8 rx_nss)
793 {
794 	struct sta_info *sta = ap_get_sta(hapd, addr);
795 	const char *txt;
796 
797 	if (!sta)
798 		return;
799 
800 	switch (smps_mode) {
801 	case SMPS_AUTOMATIC:
802 		txt = "automatic";
803 		break;
804 	case SMPS_OFF:
805 		txt = "off";
806 		break;
807 	case SMPS_DYNAMIC:
808 		txt = "dynamic";
809 		break;
810 	case SMPS_STATIC:
811 		txt = "static";
812 		break;
813 	default:
814 		txt = NULL;
815 		break;
816 	}
817 	if (txt) {
818 		wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_SMPS_MODE_CHANGED
819 			MACSTR " %s", MAC2STR(addr), txt);
820 	}
821 
822 	switch (chan_width) {
823 	case CHAN_WIDTH_20_NOHT:
824 		txt = "20(no-HT)";
825 		break;
826 	case CHAN_WIDTH_20:
827 		txt = "20";
828 		break;
829 	case CHAN_WIDTH_40:
830 		txt = "40";
831 		break;
832 	case CHAN_WIDTH_80:
833 		txt = "80";
834 		break;
835 	case CHAN_WIDTH_80P80:
836 		txt = "80+80";
837 		break;
838 	case CHAN_WIDTH_160:
839 		txt = "160";
840 		break;
841 	default:
842 		txt = NULL;
843 		break;
844 	}
845 	if (txt) {
846 		wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_MAX_BW_CHANGED
847 			MACSTR " %s", MAC2STR(addr), txt);
848 	}
849 
850 	if (rx_nss != 0xff) {
851 		wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_N_SS_CHANGED
852 			MACSTR " %d", MAC2STR(addr), rx_nss);
853 	}
854 }
855 
856 
hostapd_event_ch_switch(struct hostapd_data * hapd,int freq,int ht,int offset,int width,int cf1,int cf2,int finished)857 void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
858 			     int offset, int width, int cf1, int cf2,
859 			     int finished)
860 {
861 #ifdef NEED_AP_MLME
862 	int channel, chwidth, is_dfs;
863 	u8 seg0_idx = 0, seg1_idx = 0;
864 	size_t i;
865 
866 	hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
867 		       HOSTAPD_LEVEL_INFO,
868 		       "driver %s channel switch: freq=%d, ht=%d, vht_ch=0x%x, he_ch=0x%x, eht_ch=0x%x, offset=%d, width=%d (%s), cf1=%d, cf2=%d",
869 		       finished ? "had" : "starting",
870 		       freq, ht, hapd->iconf->ch_switch_vht_config,
871 		       hapd->iconf->ch_switch_he_config,
872 		       hapd->iconf->ch_switch_eht_config, offset,
873 		       width, channel_width_to_string(width), cf1, cf2);
874 
875 	if (!hapd->iface->current_mode) {
876 		hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
877 			       HOSTAPD_LEVEL_WARNING,
878 			       "ignore channel switch since the interface is not yet ready");
879 		return;
880 	}
881 
882 	hapd->iface->freq = freq;
883 
884 	channel = hostapd_hw_get_channel(hapd, freq);
885 	if (!channel) {
886 		hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
887 			       HOSTAPD_LEVEL_WARNING,
888 			       "driver switched to bad channel!");
889 		return;
890 	}
891 
892 	switch (width) {
893 	case CHAN_WIDTH_80:
894 		chwidth = CHANWIDTH_80MHZ;
895 		break;
896 	case CHAN_WIDTH_80P80:
897 		chwidth = CHANWIDTH_80P80MHZ;
898 		break;
899 	case CHAN_WIDTH_160:
900 		chwidth = CHANWIDTH_160MHZ;
901 		break;
902 	case CHAN_WIDTH_20_NOHT:
903 	case CHAN_WIDTH_20:
904 	case CHAN_WIDTH_40:
905 	default:
906 		chwidth = CHANWIDTH_USE_HT;
907 		break;
908 	}
909 
910 	switch (hapd->iface->current_mode->mode) {
911 	case HOSTAPD_MODE_IEEE80211A:
912 		if (cf1 == 5935)
913 			seg0_idx = (cf1 - 5925) / 5;
914 		else if (cf1 > 5950)
915 			seg0_idx = (cf1 - 5950) / 5;
916 		else if (cf1 > 5000)
917 			seg0_idx = (cf1 - 5000) / 5;
918 
919 		if (cf2 == 5935)
920 			seg1_idx = (cf2 - 5925) / 5;
921 		else if (cf2 > 5950)
922 			seg1_idx = (cf2 - 5950) / 5;
923 		else if (cf2 > 5000)
924 			seg1_idx = (cf2 - 5000) / 5;
925 		break;
926 	default:
927 		ieee80211_freq_to_chan(cf1, &seg0_idx);
928 		ieee80211_freq_to_chan(cf2, &seg1_idx);
929 		break;
930 	}
931 
932 	hapd->iconf->channel = channel;
933 	hapd->iconf->ieee80211n = ht;
934 	if (!ht) {
935 		hapd->iconf->ieee80211ac = 0;
936 	} else if (hapd->iconf->ch_switch_vht_config) {
937 		/* CHAN_SWITCH VHT config */
938 		if (hapd->iconf->ch_switch_vht_config &
939 		    CH_SWITCH_VHT_ENABLED)
940 			hapd->iconf->ieee80211ac = 1;
941 		else if (hapd->iconf->ch_switch_vht_config &
942 			 CH_SWITCH_VHT_DISABLED)
943 			hapd->iconf->ieee80211ac = 0;
944 	} else if (hapd->iconf->ch_switch_he_config) {
945 		/* CHAN_SWITCH HE config */
946 		if (hapd->iconf->ch_switch_he_config &
947 		    CH_SWITCH_HE_ENABLED)
948 			hapd->iconf->ieee80211ax = 1;
949 		else if (hapd->iconf->ch_switch_he_config &
950 			 CH_SWITCH_HE_DISABLED)
951 			hapd->iconf->ieee80211ax = 0;
952 #ifdef CONFIG_IEEE80211BE
953 	} else if (hapd->iconf->ch_switch_eht_config) {
954 		/* CHAN_SWITCH EHT config */
955 		if (hapd->iconf->ch_switch_eht_config &
956 		    CH_SWITCH_EHT_ENABLED) {
957 			hapd->iconf->ieee80211be = 1;
958 			hapd->iconf->ieee80211ax = 1;
959 			if (!is_6ghz_freq(hapd->iface->freq))
960 				hapd->iconf->ieee80211ac = 1;
961 		} else if (hapd->iconf->ch_switch_eht_config &
962 			   CH_SWITCH_EHT_DISABLED)
963 			hapd->iconf->ieee80211be = 0;
964 #endif /* CONFIG_IEEE80211BE */
965 	}
966 	hapd->iconf->ch_switch_vht_config = 0;
967 	hapd->iconf->ch_switch_he_config = 0;
968 	hapd->iconf->ch_switch_eht_config = 0;
969 
970 	if (width == CHAN_WIDTH_40 || width == CHAN_WIDTH_80 ||
971 	    width == CHAN_WIDTH_80P80 || width == CHAN_WIDTH_160)
972 		hapd->iconf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
973 	else if (width == CHAN_WIDTH_20 || width == CHAN_WIDTH_20_NOHT)
974 		hapd->iconf->ht_capab &= ~HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
975 
976 	hapd->iconf->secondary_channel = offset;
977 	hostapd_set_oper_chwidth(hapd->iconf, chwidth);
978 	hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, seg0_idx);
979 	hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, seg1_idx);
980 	if (hapd->iconf->ieee80211ac) {
981 		hapd->iconf->vht_capab &= ~VHT_CAP_SUPP_CHAN_WIDTH_MASK;
982 		if (chwidth == CHANWIDTH_160MHZ)
983 			hapd->iconf->vht_capab |=
984 				VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
985 		else if (chwidth == CHANWIDTH_80P80MHZ)
986 			hapd->iconf->vht_capab |=
987 				VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
988 	}
989 
990 	is_dfs = ieee80211_is_dfs(freq, hapd->iface->hw_features,
991 				  hapd->iface->num_hw_features);
992 
993 	wpa_msg(hapd->msg_ctx, MSG_INFO,
994 		"%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d dfs=%d",
995 		finished ? WPA_EVENT_CHANNEL_SWITCH :
996 		WPA_EVENT_CHANNEL_SWITCH_STARTED,
997 		freq, ht, offset, channel_width_to_string(width),
998 		cf1, cf2, is_dfs);
999 	if (!finished)
1000 		return;
1001 
1002 	if (hapd->csa_in_progress &&
1003 	    freq == hapd->cs_freq_params.freq) {
1004 		hostapd_cleanup_cs_params(hapd);
1005 		ieee802_11_set_beacon(hapd);
1006 
1007 		wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
1008 			"freq=%d dfs=%d", freq, is_dfs);
1009 	} else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) {
1010 		wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
1011 			"freq=%d dfs=%d", freq, is_dfs);
1012 	} else if (is_dfs &&
1013 		   hostapd_is_dfs_required(hapd->iface) &&
1014 		   !hostapd_is_dfs_chan_available(hapd->iface) &&
1015 		   !hapd->iface->cac_started) {
1016 		hostapd_disable_iface(hapd->iface);
1017 		hostapd_enable_iface(hapd->iface);
1018 	}
1019 
1020 	for (i = 0; i < hapd->iface->num_bss; i++)
1021 		hostapd_neighbor_set_own_report(hapd->iface->bss[i]);
1022 
1023 #ifdef CONFIG_OCV
1024 	if (hapd->conf->ocv &&
1025 	    !(hapd->iface->drv_flags2 &
1026 	      WPA_DRIVER_FLAGS2_SA_QUERY_OFFLOAD_AP)) {
1027 		struct sta_info *sta;
1028 		bool check_sa_query = false;
1029 
1030 		for (sta = hapd->sta_list; sta; sta = sta->next) {
1031 			if (wpa_auth_uses_ocv(sta->wpa_sm) &&
1032 			    !(sta->flags & WLAN_STA_WNM_SLEEP_MODE)) {
1033 				sta->post_csa_sa_query = 1;
1034 				check_sa_query = true;
1035 			}
1036 		}
1037 
1038 		if (check_sa_query) {
1039 			wpa_printf(MSG_DEBUG,
1040 				   "OCV: Check post-CSA SA Query initiation in 15 seconds");
1041 			eloop_register_timeout(15, 0,
1042 					       hostapd_ocv_check_csa_sa_query,
1043 					       hapd, NULL);
1044 		}
1045 	}
1046 #endif /* CONFIG_OCV */
1047 #endif /* NEED_AP_MLME */
1048 }
1049 
1050 
hostapd_event_connect_failed_reason(struct hostapd_data * hapd,const u8 * addr,int reason_code)1051 void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
1052 					 const u8 *addr, int reason_code)
1053 {
1054 	switch (reason_code) {
1055 	case MAX_CLIENT_REACHED:
1056 		wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR,
1057 			MAC2STR(addr));
1058 		break;
1059 	case BLOCKED_CLIENT:
1060 		wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR,
1061 			MAC2STR(addr));
1062 		break;
1063 	}
1064 }
1065 
1066 
1067 #ifdef CONFIG_ACS
hostapd_acs_channel_selected(struct hostapd_data * hapd,struct acs_selected_channels * acs_res)1068 void hostapd_acs_channel_selected(struct hostapd_data *hapd,
1069 				  struct acs_selected_channels *acs_res)
1070 {
1071 	int ret, i;
1072 	int err = 0;
1073 	struct hostapd_channel_data *pri_chan;
1074 
1075 	if (hapd->iconf->channel) {
1076 		wpa_printf(MSG_INFO, "ACS: Channel was already set to %d",
1077 			   hapd->iconf->channel);
1078 		return;
1079 	}
1080 
1081 	hapd->iface->freq = acs_res->pri_freq;
1082 
1083 	if (!hapd->iface->current_mode) {
1084 		for (i = 0; i < hapd->iface->num_hw_features; i++) {
1085 			struct hostapd_hw_modes *mode =
1086 				&hapd->iface->hw_features[i];
1087 
1088 			if (mode->mode == acs_res->hw_mode) {
1089 				if (hapd->iface->freq > 0 &&
1090 				    !hw_get_chan(mode->mode,
1091 						 hapd->iface->freq,
1092 						 hapd->iface->hw_features,
1093 						 hapd->iface->num_hw_features))
1094 					continue;
1095 				hapd->iface->current_mode = mode;
1096 				break;
1097 			}
1098 		}
1099 		if (!hapd->iface->current_mode) {
1100 			hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1101 				       HOSTAPD_LEVEL_WARNING,
1102 				       "driver selected to bad hw_mode");
1103 			err = 1;
1104 			goto out;
1105 		}
1106 	}
1107 
1108 	if (!acs_res->pri_freq) {
1109 		hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1110 			       HOSTAPD_LEVEL_WARNING,
1111 			       "driver switched to bad channel");
1112 		err = 1;
1113 		goto out;
1114 	}
1115 	pri_chan = hw_get_channel_freq(hapd->iface->current_mode->mode,
1116 				       acs_res->pri_freq, NULL,
1117 				       hapd->iface->hw_features,
1118 				       hapd->iface->num_hw_features);
1119 	if (!pri_chan) {
1120 		wpa_printf(MSG_ERROR,
1121 			   "ACS: Could not determine primary channel number from pri_freq %u",
1122 			   acs_res->pri_freq);
1123 		err = 1;
1124 		goto out;
1125 	}
1126 
1127 	hapd->iconf->channel = pri_chan->chan;
1128 	hapd->iconf->acs = 1;
1129 
1130 	if (acs_res->sec_freq == 0)
1131 		hapd->iconf->secondary_channel = 0;
1132 	else if (acs_res->sec_freq < acs_res->pri_freq)
1133 		hapd->iconf->secondary_channel = -1;
1134 	else if (acs_res->sec_freq > acs_res->pri_freq)
1135 		hapd->iconf->secondary_channel = 1;
1136 	else {
1137 		wpa_printf(MSG_ERROR, "Invalid secondary channel!");
1138 		err = 1;
1139 		goto out;
1140 	}
1141 
1142 	hapd->iconf->edmg_channel = acs_res->edmg_channel;
1143 
1144 	if (hapd->iface->conf->ieee80211ac || hapd->iface->conf->ieee80211ax) {
1145 		/* set defaults for backwards compatibility */
1146 		hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, 0);
1147 		hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, 0);
1148 		hostapd_set_oper_chwidth(hapd->iconf, CHANWIDTH_USE_HT);
1149 		if (acs_res->ch_width == 40) {
1150 			if (is_6ghz_freq(acs_res->pri_freq))
1151 				hostapd_set_oper_centr_freq_seg0_idx(
1152 					hapd->iconf,
1153 					acs_res->vht_seg0_center_ch);
1154 		} else if (acs_res->ch_width == 80) {
1155 			hostapd_set_oper_centr_freq_seg0_idx(
1156 				hapd->iconf, acs_res->vht_seg0_center_ch);
1157 			if (acs_res->vht_seg1_center_ch == 0) {
1158 				hostapd_set_oper_chwidth(hapd->iconf,
1159 							 CHANWIDTH_80MHZ);
1160 			} else {
1161 				hostapd_set_oper_chwidth(hapd->iconf,
1162 							 CHANWIDTH_80P80MHZ);
1163 				hostapd_set_oper_centr_freq_seg1_idx(
1164 					hapd->iconf,
1165 					acs_res->vht_seg1_center_ch);
1166 			}
1167 		} else if (acs_res->ch_width == 160) {
1168 			hostapd_set_oper_chwidth(hapd->iconf, CHANWIDTH_160MHZ);
1169 			hostapd_set_oper_centr_freq_seg0_idx(
1170 				hapd->iconf, acs_res->vht_seg1_center_ch);
1171 		}
1172 	}
1173 
1174 out:
1175 	ret = hostapd_acs_completed(hapd->iface, err);
1176 	if (ret) {
1177 		wpa_printf(MSG_ERROR,
1178 			   "ACS: Possibly channel configuration is invalid");
1179 	}
1180 }
1181 #endif /* CONFIG_ACS */
1182 
1183 
hostapd_probe_req_rx(struct hostapd_data * hapd,const u8 * sa,const u8 * da,const u8 * bssid,const u8 * ie,size_t ie_len,int ssi_signal)1184 int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
1185 			 const u8 *bssid, const u8 *ie, size_t ie_len,
1186 			 int ssi_signal)
1187 {
1188 	size_t i;
1189 	int ret = 0;
1190 
1191 	if (sa == NULL || ie == NULL)
1192 		return -1;
1193 
1194 	random_add_randomness(sa, ETH_ALEN);
1195 	for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) {
1196 		if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
1197 					    sa, da, bssid, ie, ie_len,
1198 					    ssi_signal) > 0) {
1199 			ret = 1;
1200 			break;
1201 		}
1202 	}
1203 	return ret;
1204 }
1205 
1206 
1207 #ifdef HOSTAPD
1208 
1209 #ifdef CONFIG_IEEE80211R_AP
hostapd_notify_auth_ft_finish(void * ctx,const u8 * dst,const u8 * bssid,u16 auth_transaction,u16 status,const u8 * ies,size_t ies_len)1210 static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst,
1211 					  const u8 *bssid,
1212 					  u16 auth_transaction, u16 status,
1213 					  const u8 *ies, size_t ies_len)
1214 {
1215 	struct hostapd_data *hapd = ctx;
1216 	struct sta_info *sta;
1217 
1218 	sta = ap_get_sta(hapd, dst);
1219 	if (sta == NULL)
1220 		return;
1221 
1222 	hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
1223 		       HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
1224 	sta->flags |= WLAN_STA_AUTH;
1225 
1226 	hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len);
1227 }
1228 #endif /* CONFIG_IEEE80211R_AP */
1229 
1230 
1231 #ifdef CONFIG_FILS
hostapd_notify_auth_fils_finish(struct hostapd_data * hapd,struct sta_info * sta,u16 resp,struct wpabuf * data,int pub)1232 static void hostapd_notify_auth_fils_finish(struct hostapd_data *hapd,
1233 					    struct sta_info *sta, u16 resp,
1234 					    struct wpabuf *data, int pub)
1235 {
1236 	if (resp == WLAN_STATUS_SUCCESS) {
1237 		hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1238 			       HOSTAPD_LEVEL_DEBUG, "authentication OK (FILS)");
1239 		sta->flags |= WLAN_STA_AUTH;
1240 		wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1241 		sta->auth_alg = WLAN_AUTH_FILS_SK;
1242 		mlme_authenticate_indication(hapd, sta);
1243 	} else {
1244 		hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1245 			       HOSTAPD_LEVEL_DEBUG,
1246 			       "authentication failed (FILS)");
1247 	}
1248 
1249 	hostapd_sta_auth(hapd, sta->addr, 2, resp,
1250 			 data ? wpabuf_head(data) : NULL,
1251 			 data ? wpabuf_len(data) : 0);
1252 	wpabuf_free(data);
1253 }
1254 #endif /* CONFIG_FILS */
1255 
1256 
hostapd_notif_auth(struct hostapd_data * hapd,struct auth_info * rx_auth)1257 static void hostapd_notif_auth(struct hostapd_data *hapd,
1258 			       struct auth_info *rx_auth)
1259 {
1260 	struct sta_info *sta;
1261 	u16 status = WLAN_STATUS_SUCCESS;
1262 	u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
1263 	size_t resp_ies_len = 0;
1264 
1265 	sta = ap_get_sta(hapd, rx_auth->peer);
1266 	if (!sta) {
1267 		sta = ap_sta_add(hapd, rx_auth->peer);
1268 		if (sta == NULL) {
1269 			status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1270 			goto fail;
1271 		}
1272 	}
1273 	sta->flags &= ~WLAN_STA_PREAUTH;
1274 	ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
1275 #ifdef CONFIG_IEEE80211R_AP
1276 	if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) {
1277 		sta->auth_alg = WLAN_AUTH_FT;
1278 		if (sta->wpa_sm == NULL)
1279 			sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1280 							sta->addr, NULL);
1281 		if (sta->wpa_sm == NULL) {
1282 			wpa_printf(MSG_DEBUG,
1283 				   "FT: Failed to initialize WPA state machine");
1284 			status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1285 			goto fail;
1286 		}
1287 		wpa_ft_process_auth(sta->wpa_sm, rx_auth->bssid,
1288 				    rx_auth->auth_transaction, rx_auth->ies,
1289 				    rx_auth->ies_len,
1290 				    hostapd_notify_auth_ft_finish, hapd);
1291 		return;
1292 	}
1293 #endif /* CONFIG_IEEE80211R_AP */
1294 
1295 #ifdef CONFIG_FILS
1296 	if (rx_auth->auth_type == WLAN_AUTH_FILS_SK) {
1297 		sta->auth_alg = WLAN_AUTH_FILS_SK;
1298 		handle_auth_fils(hapd, sta, rx_auth->ies, rx_auth->ies_len,
1299 				 rx_auth->auth_type, rx_auth->auth_transaction,
1300 				 rx_auth->status_code,
1301 				 hostapd_notify_auth_fils_finish);
1302 		return;
1303 	}
1304 #endif /* CONFIG_FILS */
1305 
1306 fail:
1307 	hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1,
1308 			 status, resp_ies, resp_ies_len);
1309 }
1310 
1311 
1312 #ifndef NEED_AP_MLME
hostapd_action_rx(struct hostapd_data * hapd,struct rx_mgmt * drv_mgmt)1313 static void hostapd_action_rx(struct hostapd_data *hapd,
1314 			      struct rx_mgmt *drv_mgmt)
1315 {
1316 	struct ieee80211_mgmt *mgmt;
1317 	struct sta_info *sta;
1318 	size_t plen __maybe_unused;
1319 	u16 fc;
1320 	u8 *action __maybe_unused;
1321 
1322 	if (drv_mgmt->frame_len < IEEE80211_HDRLEN + 2 + 1)
1323 		return;
1324 
1325 	plen = drv_mgmt->frame_len - IEEE80211_HDRLEN;
1326 
1327 	mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame;
1328 	fc = le_to_host16(mgmt->frame_control);
1329 	if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION)
1330 		return; /* handled by the driver */
1331 
1332 	action = (u8 *) &mgmt->u.action.u;
1333 	wpa_printf(MSG_DEBUG, "RX_ACTION category %u action %u sa " MACSTR
1334 		   " da " MACSTR " plen %d",
1335 		   mgmt->u.action.category, *action,
1336 		   MAC2STR(mgmt->sa), MAC2STR(mgmt->da), (int) plen);
1337 
1338 	sta = ap_get_sta(hapd, mgmt->sa);
1339 	if (sta == NULL) {
1340 		wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
1341 		return;
1342 	}
1343 #ifdef CONFIG_IEEE80211R_AP
1344 	if (mgmt->u.action.category == WLAN_ACTION_FT) {
1345 		wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action, plen);
1346 		return;
1347 	}
1348 #endif /* CONFIG_IEEE80211R_AP */
1349 	if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY) {
1350 		ieee802_11_sa_query_action(hapd, mgmt, drv_mgmt->frame_len);
1351 		return;
1352 	}
1353 #ifdef CONFIG_WNM_AP
1354 	if (mgmt->u.action.category == WLAN_ACTION_WNM) {
1355 		ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len);
1356 		return;
1357 	}
1358 #endif /* CONFIG_WNM_AP */
1359 #ifdef CONFIG_FST
1360 	if (mgmt->u.action.category == WLAN_ACTION_FST && hapd->iface->fst) {
1361 		fst_rx_action(hapd->iface->fst, mgmt, drv_mgmt->frame_len);
1362 		return;
1363 	}
1364 #endif /* CONFIG_FST */
1365 #ifdef CONFIG_DPP
1366 	if (plen >= 2 + 4 &&
1367 	    mgmt->u.action.u.vs_public_action.action ==
1368 	    WLAN_PA_VENDOR_SPECIFIC &&
1369 	    WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
1370 	    OUI_WFA &&
1371 	    mgmt->u.action.u.vs_public_action.variable[0] ==
1372 	    DPP_OUI_TYPE) {
1373 		const u8 *pos, *end;
1374 
1375 		pos = mgmt->u.action.u.vs_public_action.oui;
1376 		end = drv_mgmt->frame + drv_mgmt->frame_len;
1377 		hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos,
1378 				      drv_mgmt->freq);
1379 		return;
1380 	}
1381 #endif /* CONFIG_DPP */
1382 }
1383 #endif /* NEED_AP_MLME */
1384 
1385 
1386 #ifdef NEED_AP_MLME
1387 
1388 #define HAPD_BROADCAST ((struct hostapd_data *) -1)
1389 
get_hapd_bssid(struct hostapd_iface * iface,const u8 * bssid)1390 static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface,
1391 					    const u8 *bssid)
1392 {
1393 	size_t i;
1394 
1395 	if (bssid == NULL)
1396 		return NULL;
1397 	if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff &&
1398 	    bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff)
1399 		return HAPD_BROADCAST;
1400 
1401 	for (i = 0; i < iface->num_bss; i++) {
1402 		if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0)
1403 			return iface->bss[i];
1404 	}
1405 
1406 	return NULL;
1407 }
1408 
1409 
hostapd_rx_from_unknown_sta(struct hostapd_data * hapd,const u8 * bssid,const u8 * addr,int wds)1410 static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd,
1411 					const u8 *bssid, const u8 *addr,
1412 					int wds)
1413 {
1414 	hapd = get_hapd_bssid(hapd->iface, bssid);
1415 	if (hapd == NULL || hapd == HAPD_BROADCAST)
1416 		return;
1417 
1418 	ieee802_11_rx_from_unknown(hapd, addr, wds);
1419 }
1420 
1421 
hostapd_mgmt_rx(struct hostapd_data * hapd,struct rx_mgmt * rx_mgmt)1422 static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt)
1423 {
1424 	struct hostapd_iface *iface = hapd->iface;
1425 	const struct ieee80211_hdr *hdr;
1426 	const u8 *bssid;
1427 	struct hostapd_frame_info fi;
1428 	int ret;
1429 
1430 #ifdef CONFIG_TESTING_OPTIONS
1431 	if (hapd->ext_mgmt_frame_handling) {
1432 		size_t hex_len = 2 * rx_mgmt->frame_len + 1;
1433 		char *hex = os_malloc(hex_len);
1434 
1435 		if (hex) {
1436 			wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame,
1437 					 rx_mgmt->frame_len);
1438 			wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex);
1439 			os_free(hex);
1440 		}
1441 		return 1;
1442 	}
1443 #endif /* CONFIG_TESTING_OPTIONS */
1444 
1445 	hdr = (const struct ieee80211_hdr *) rx_mgmt->frame;
1446 	bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len);
1447 	if (bssid == NULL)
1448 		return 0;
1449 
1450 	hapd = get_hapd_bssid(iface, bssid);
1451 	if (hapd == NULL) {
1452 		u16 fc = le_to_host16(hdr->frame_control);
1453 
1454 		/*
1455 		 * Drop frames to unknown BSSIDs except for Beacon frames which
1456 		 * could be used to update neighbor information.
1457 		 */
1458 		if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1459 		    WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1460 			hapd = iface->bss[0];
1461 		else
1462 			return 0;
1463 	}
1464 
1465 	os_memset(&fi, 0, sizeof(fi));
1466 	fi.freq = rx_mgmt->freq;
1467 	fi.datarate = rx_mgmt->datarate;
1468 	fi.ssi_signal = rx_mgmt->ssi_signal;
1469 
1470 	if (hapd == HAPD_BROADCAST) {
1471 		size_t i;
1472 
1473 		ret = 0;
1474 		for (i = 0; i < iface->num_bss; i++) {
1475 			/* if bss is set, driver will call this function for
1476 			 * each bss individually. */
1477 			if (rx_mgmt->drv_priv &&
1478 			    (iface->bss[i]->drv_priv != rx_mgmt->drv_priv))
1479 				continue;
1480 
1481 			if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame,
1482 					    rx_mgmt->frame_len, &fi) > 0)
1483 				ret = 1;
1484 		}
1485 	} else
1486 		ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len,
1487 				      &fi);
1488 
1489 	random_add_randomness(&fi, sizeof(fi));
1490 
1491 	return ret;
1492 }
1493 
1494 
hostapd_mgmt_tx_cb(struct hostapd_data * hapd,const u8 * buf,size_t len,u16 stype,int ok)1495 static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf,
1496 			       size_t len, u16 stype, int ok)
1497 {
1498 	struct ieee80211_hdr *hdr;
1499 	struct hostapd_data *orig_hapd = hapd;
1500 
1501 	hdr = (struct ieee80211_hdr *) buf;
1502 	hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len));
1503 	if (!hapd)
1504 		return;
1505 	if (hapd == HAPD_BROADCAST) {
1506 		if (stype != WLAN_FC_STYPE_ACTION || len <= 25 ||
1507 		    buf[24] != WLAN_ACTION_PUBLIC)
1508 			return;
1509 		hapd = get_hapd_bssid(orig_hapd->iface, hdr->addr2);
1510 		if (!hapd || hapd == HAPD_BROADCAST)
1511 			return;
1512 		/*
1513 		 * Allow processing of TX status for a Public Action frame that
1514 		 * used wildcard BBSID.
1515 		 */
1516 	}
1517 	ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
1518 }
1519 
1520 #endif /* NEED_AP_MLME */
1521 
1522 
hostapd_event_new_sta(struct hostapd_data * hapd,const u8 * addr)1523 static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr)
1524 {
1525 	struct sta_info *sta = ap_get_sta(hapd, addr);
1526 
1527 	if (sta)
1528 		return 0;
1529 
1530 	wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
1531 		   " - adding a new STA", MAC2STR(addr));
1532 	sta = ap_sta_add(hapd, addr);
1533 	if (sta) {
1534 		hostapd_new_assoc_sta(hapd, sta, 0);
1535 	} else {
1536 		wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
1537 			   MAC2STR(addr));
1538 		return -1;
1539 	}
1540 
1541 	return 0;
1542 }
1543 
1544 
hostapd_event_eapol_rx(struct hostapd_data * hapd,const u8 * src,const u8 * data,size_t data_len)1545 static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src,
1546 				   const u8 *data, size_t data_len)
1547 {
1548 	struct hostapd_iface *iface = hapd->iface;
1549 	struct sta_info *sta;
1550 	size_t j;
1551 
1552 	for (j = 0; j < iface->num_bss; j++) {
1553 		sta = ap_get_sta(iface->bss[j], src);
1554 		if (sta && sta->flags & WLAN_STA_ASSOC) {
1555 			hapd = iface->bss[j];
1556 			break;
1557 		}
1558 	}
1559 
1560 	ieee802_1x_receive(hapd, src, data, data_len);
1561 }
1562 
1563 #endif /* HOSTAPD */
1564 
1565 
1566 static struct hostapd_channel_data *
hostapd_get_mode_chan(struct hostapd_hw_modes * mode,unsigned int freq)1567 hostapd_get_mode_chan(struct hostapd_hw_modes *mode, unsigned int freq)
1568 {
1569 	int i;
1570 	struct hostapd_channel_data *chan;
1571 
1572 	for (i = 0; i < mode->num_channels; i++) {
1573 		chan = &mode->channels[i];
1574 		if ((unsigned int) chan->freq == freq)
1575 			return chan;
1576 	}
1577 
1578 	return NULL;
1579 }
1580 
1581 
hostapd_get_mode_channel(struct hostapd_iface * iface,unsigned int freq)1582 static struct hostapd_channel_data * hostapd_get_mode_channel(
1583 	struct hostapd_iface *iface, unsigned int freq)
1584 {
1585 	int i;
1586 	struct hostapd_channel_data *chan;
1587 
1588 	for (i = 0; i < iface->num_hw_features; i++) {
1589 		if (hostapd_hw_skip_mode(iface, &iface->hw_features[i]))
1590 			continue;
1591 		chan = hostapd_get_mode_chan(&iface->hw_features[i], freq);
1592 		if (chan)
1593 			return chan;
1594 	}
1595 
1596 	return NULL;
1597 }
1598 
1599 
hostapd_update_nf(struct hostapd_iface * iface,struct hostapd_channel_data * chan,struct freq_survey * survey)1600 static void hostapd_update_nf(struct hostapd_iface *iface,
1601 			      struct hostapd_channel_data *chan,
1602 			      struct freq_survey *survey)
1603 {
1604 	if (!iface->chans_surveyed) {
1605 		chan->min_nf = survey->nf;
1606 		iface->lowest_nf = survey->nf;
1607 	} else {
1608 		if (dl_list_empty(&chan->survey_list))
1609 			chan->min_nf = survey->nf;
1610 		else if (survey->nf < chan->min_nf)
1611 			chan->min_nf = survey->nf;
1612 		if (survey->nf < iface->lowest_nf)
1613 			iface->lowest_nf = survey->nf;
1614 	}
1615 }
1616 
1617 
hostapd_single_channel_get_survey(struct hostapd_iface * iface,struct survey_results * survey_res)1618 static void hostapd_single_channel_get_survey(struct hostapd_iface *iface,
1619 					      struct survey_results *survey_res)
1620 {
1621 	struct hostapd_channel_data *chan;
1622 	struct freq_survey *survey;
1623 	u64 divisor, dividend;
1624 
1625 	survey = dl_list_first(&survey_res->survey_list, struct freq_survey,
1626 			       list);
1627 	if (!survey || !survey->freq)
1628 		return;
1629 
1630 	chan = hostapd_get_mode_channel(iface, survey->freq);
1631 	if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED)
1632 		return;
1633 
1634 	wpa_printf(MSG_DEBUG,
1635 		   "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)",
1636 		   survey->freq,
1637 		   (unsigned long int) survey->channel_time,
1638 		   (unsigned long int) survey->channel_time_busy);
1639 
1640 	if (survey->channel_time > iface->last_channel_time &&
1641 	    survey->channel_time > survey->channel_time_busy) {
1642 		dividend = survey->channel_time_busy -
1643 			iface->last_channel_time_busy;
1644 		divisor = survey->channel_time - iface->last_channel_time;
1645 
1646 		iface->channel_utilization = dividend * 255 / divisor;
1647 		wpa_printf(MSG_DEBUG, "Channel Utilization: %d",
1648 			   iface->channel_utilization);
1649 	}
1650 	iface->last_channel_time = survey->channel_time;
1651 	iface->last_channel_time_busy = survey->channel_time_busy;
1652 }
1653 
1654 
hostapd_event_get_survey(struct hostapd_iface * iface,struct survey_results * survey_results)1655 void hostapd_event_get_survey(struct hostapd_iface *iface,
1656 			      struct survey_results *survey_results)
1657 {
1658 	struct freq_survey *survey, *tmp;
1659 	struct hostapd_channel_data *chan;
1660 
1661 	if (dl_list_empty(&survey_results->survey_list)) {
1662 		wpa_printf(MSG_DEBUG, "No survey data received");
1663 		return;
1664 	}
1665 
1666 	if (survey_results->freq_filter) {
1667 		hostapd_single_channel_get_survey(iface, survey_results);
1668 		return;
1669 	}
1670 
1671 	dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
1672 			      struct freq_survey, list) {
1673 		chan = hostapd_get_mode_channel(iface, survey->freq);
1674 		if (!chan)
1675 			continue;
1676 		if (chan->flag & HOSTAPD_CHAN_DISABLED)
1677 			continue;
1678 
1679 		dl_list_del(&survey->list);
1680 		dl_list_add_tail(&chan->survey_list, &survey->list);
1681 
1682 		hostapd_update_nf(iface, chan, survey);
1683 
1684 		iface->chans_surveyed++;
1685 	}
1686 }
1687 
1688 
1689 #ifdef HOSTAPD
1690 #ifdef NEED_AP_MLME
1691 
hostapd_event_iface_unavailable(struct hostapd_data * hapd)1692 static void hostapd_event_iface_unavailable(struct hostapd_data *hapd)
1693 {
1694 	wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped",
1695 		   hapd->conf->iface);
1696 
1697 	if (hapd->csa_in_progress) {
1698 		wpa_printf(MSG_INFO, "CSA failed (%s was stopped)",
1699 			   hapd->conf->iface);
1700 		hostapd_switch_channel_fallback(hapd->iface,
1701 						&hapd->cs_freq_params);
1702 	}
1703 
1704 	// inform framework that interface is unavailable
1705 	hostapd_disable_iface(hapd->iface);
1706 }
1707 
1708 
hostapd_event_dfs_radar_detected(struct hostapd_data * hapd,struct dfs_event * radar)1709 static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd,
1710 					     struct dfs_event *radar)
1711 {
1712 	wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
1713 	hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled,
1714 				   radar->chan_offset, radar->chan_width,
1715 				   radar->cf1, radar->cf2);
1716 }
1717 
1718 
hostapd_event_dfs_pre_cac_expired(struct hostapd_data * hapd,struct dfs_event * radar)1719 static void hostapd_event_dfs_pre_cac_expired(struct hostapd_data *hapd,
1720 					      struct dfs_event *radar)
1721 {
1722 	wpa_printf(MSG_DEBUG, "DFS Pre-CAC expired on %d MHz", radar->freq);
1723 	hostapd_dfs_pre_cac_expired(hapd->iface, radar->freq, radar->ht_enabled,
1724 				    radar->chan_offset, radar->chan_width,
1725 				    radar->cf1, radar->cf2);
1726 }
1727 
1728 
hostapd_event_dfs_cac_finished(struct hostapd_data * hapd,struct dfs_event * radar)1729 static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd,
1730 					   struct dfs_event *radar)
1731 {
1732 	wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
1733 	hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled,
1734 				 radar->chan_offset, radar->chan_width,
1735 				 radar->cf1, radar->cf2);
1736 }
1737 
1738 
hostapd_event_dfs_cac_aborted(struct hostapd_data * hapd,struct dfs_event * radar)1739 static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd,
1740 					  struct dfs_event *radar)
1741 {
1742 	wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
1743 	hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled,
1744 				 radar->chan_offset, radar->chan_width,
1745 				 radar->cf1, radar->cf2);
1746 }
1747 
1748 
hostapd_event_dfs_nop_finished(struct hostapd_data * hapd,struct dfs_event * radar)1749 static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd,
1750 					   struct dfs_event *radar)
1751 {
1752 	wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
1753 	hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled,
1754 				 radar->chan_offset, radar->chan_width,
1755 				 radar->cf1, radar->cf2);
1756 }
1757 
1758 
hostapd_event_dfs_cac_started(struct hostapd_data * hapd,struct dfs_event * radar)1759 static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd,
1760 					  struct dfs_event *radar)
1761 {
1762 	wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq);
1763 	hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled,
1764 			      radar->chan_offset, radar->chan_width,
1765 			      radar->cf1, radar->cf2);
1766 }
1767 
1768 #endif /* NEED_AP_MLME */
1769 
1770 
hostapd_event_wds_sta_interface_status(struct hostapd_data * hapd,int istatus,const char * ifname,const u8 * addr)1771 static void hostapd_event_wds_sta_interface_status(struct hostapd_data *hapd,
1772 						   int istatus,
1773 						   const char *ifname,
1774 						   const u8 *addr)
1775 {
1776 	struct sta_info *sta = ap_get_sta(hapd, addr);
1777 
1778 	if (sta) {
1779 		os_free(sta->ifname_wds);
1780 		if (istatus == INTERFACE_ADDED)
1781 			sta->ifname_wds = os_strdup(ifname);
1782 		else
1783 			sta->ifname_wds = NULL;
1784 	}
1785 
1786 	wpa_msg(hapd->msg_ctx, MSG_INFO, "%sifname=%s sta_addr=" MACSTR,
1787 		istatus == INTERFACE_ADDED ?
1788 		WDS_STA_INTERFACE_ADDED : WDS_STA_INTERFACE_REMOVED,
1789 		ifname, MAC2STR(addr));
1790 }
1791 
1792 
1793 #ifdef CONFIG_OWE
hostapd_notif_update_dh_ie(struct hostapd_data * hapd,const u8 * peer,const u8 * ie,size_t ie_len)1794 static int hostapd_notif_update_dh_ie(struct hostapd_data *hapd,
1795 				      const u8 *peer, const u8 *ie,
1796 				      size_t ie_len)
1797 {
1798 	u16 status;
1799 	struct sta_info *sta;
1800 	struct ieee802_11_elems elems;
1801 
1802 	if (!hapd || !hapd->wpa_auth) {
1803 		wpa_printf(MSG_DEBUG, "OWE: Invalid hapd context");
1804 		return -1;
1805 	}
1806 	if (!peer) {
1807 		wpa_printf(MSG_DEBUG, "OWE: Peer unknown");
1808 		return -1;
1809 	}
1810 	if (!(hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE)) {
1811 		wpa_printf(MSG_DEBUG, "OWE: No OWE AKM configured");
1812 		status = WLAN_STATUS_AKMP_NOT_VALID;
1813 		goto err;
1814 	}
1815 	if (ieee802_11_parse_elems(ie, ie_len, &elems, 1) == ParseFailed) {
1816 		wpa_printf(MSG_DEBUG, "OWE: Failed to parse OWE IE for "
1817 			   MACSTR, MAC2STR(peer));
1818 		status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1819 		goto err;
1820 	}
1821 	status = owe_validate_request(hapd, peer, elems.rsn_ie,
1822 				      elems.rsn_ie_len,
1823 				      elems.owe_dh, elems.owe_dh_len);
1824 	if (status != WLAN_STATUS_SUCCESS)
1825 		goto err;
1826 
1827 	sta = ap_get_sta(hapd, peer);
1828 	if (sta) {
1829 		ap_sta_no_session_timeout(hapd, sta);
1830 		accounting_sta_stop(hapd, sta);
1831 
1832 		/*
1833 		 * Make sure that the previously registered inactivity timer
1834 		 * will not remove the STA immediately.
1835 		 */
1836 		sta->timeout_next = STA_NULLFUNC;
1837 	} else {
1838 		sta = ap_sta_add(hapd, peer);
1839 		if (!sta) {
1840 			status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1841 			goto err;
1842 		}
1843 	}
1844 	sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
1845 
1846 	status = owe_process_rsn_ie(hapd, sta, elems.rsn_ie,
1847 				    elems.rsn_ie_len, elems.owe_dh,
1848 				    elems.owe_dh_len);
1849 	if (status != WLAN_STATUS_SUCCESS)
1850 		ap_free_sta(hapd, sta);
1851 
1852 	return 0;
1853 err:
1854 	hostapd_drv_update_dh_ie(hapd, peer, status, NULL, 0);
1855 	return 0;
1856 }
1857 #endif /* CONFIG_OWE */
1858 
1859 
wpa_supplicant_event(void * ctx,enum wpa_event_type event,union wpa_event_data * data)1860 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
1861 			  union wpa_event_data *data)
1862 {
1863 	struct hostapd_data *hapd = ctx;
1864 #ifndef CONFIG_NO_STDOUT_DEBUG
1865 	int level = MSG_DEBUG;
1866 
1867 	if (event == EVENT_RX_MGMT && data->rx_mgmt.frame &&
1868 	    data->rx_mgmt.frame_len >= 24) {
1869 		const struct ieee80211_hdr *hdr;
1870 		u16 fc;
1871 
1872 		hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
1873 		fc = le_to_host16(hdr->frame_control);
1874 		if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1875 		    WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1876 			level = MSG_EXCESSIVE;
1877 		if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1878 		    WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ)
1879 			level = MSG_EXCESSIVE;
1880 	}
1881 
1882 	wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received",
1883 		event_to_string(event), event);
1884 #endif /* CONFIG_NO_STDOUT_DEBUG */
1885 
1886 	switch (event) {
1887 	case EVENT_MICHAEL_MIC_FAILURE:
1888 		michael_mic_failure(hapd, data->michael_mic_failure.src, 1);
1889 		break;
1890 	case EVENT_SCAN_RESULTS:
1891 		if (hapd->iface->scan_cb)
1892 			hapd->iface->scan_cb(hapd->iface);
1893 		break;
1894 	case EVENT_WPS_BUTTON_PUSHED:
1895 		hostapd_wps_button_pushed(hapd, NULL);
1896 		break;
1897 #ifdef NEED_AP_MLME
1898 	case EVENT_TX_STATUS:
1899 		switch (data->tx_status.type) {
1900 		case WLAN_FC_TYPE_MGMT:
1901 			hostapd_mgmt_tx_cb(hapd, data->tx_status.data,
1902 					   data->tx_status.data_len,
1903 					   data->tx_status.stype,
1904 					   data->tx_status.ack);
1905 			break;
1906 		case WLAN_FC_TYPE_DATA:
1907 			hostapd_tx_status(hapd, data->tx_status.dst,
1908 					  data->tx_status.data,
1909 					  data->tx_status.data_len,
1910 					  data->tx_status.ack);
1911 			break;
1912 		}
1913 		break;
1914 	case EVENT_EAPOL_TX_STATUS:
1915 		hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst,
1916 					data->eapol_tx_status.data,
1917 					data->eapol_tx_status.data_len,
1918 					data->eapol_tx_status.ack);
1919 		break;
1920 	case EVENT_DRIVER_CLIENT_POLL_OK:
1921 		hostapd_client_poll_ok(hapd, data->client_poll.addr);
1922 		break;
1923 	case EVENT_RX_FROM_UNKNOWN:
1924 		hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid,
1925 					    data->rx_from_unknown.addr,
1926 					    data->rx_from_unknown.wds);
1927 		break;
1928 #endif /* NEED_AP_MLME */
1929 	case EVENT_RX_MGMT:
1930 		if (!data->rx_mgmt.frame)
1931 			break;
1932 #ifdef NEED_AP_MLME
1933 		hostapd_mgmt_rx(hapd, &data->rx_mgmt);
1934 #else /* NEED_AP_MLME */
1935 		hostapd_action_rx(hapd, &data->rx_mgmt);
1936 #endif /* NEED_AP_MLME */
1937 		break;
1938 	case EVENT_RX_PROBE_REQ:
1939 		if (data->rx_probe_req.sa == NULL ||
1940 		    data->rx_probe_req.ie == NULL)
1941 			break;
1942 		hostapd_probe_req_rx(hapd, data->rx_probe_req.sa,
1943 				     data->rx_probe_req.da,
1944 				     data->rx_probe_req.bssid,
1945 				     data->rx_probe_req.ie,
1946 				     data->rx_probe_req.ie_len,
1947 				     data->rx_probe_req.ssi_signal);
1948 		break;
1949 	case EVENT_NEW_STA:
1950 		hostapd_event_new_sta(hapd, data->new_sta.addr);
1951 		break;
1952 	case EVENT_EAPOL_RX:
1953 		hostapd_event_eapol_rx(hapd, data->eapol_rx.src,
1954 				       data->eapol_rx.data,
1955 				       data->eapol_rx.data_len);
1956 		break;
1957 	case EVENT_ASSOC:
1958 		if (!data)
1959 			return;
1960 		hostapd_notif_assoc(hapd, data->assoc_info.addr,
1961 				    data->assoc_info.req_ies,
1962 				    data->assoc_info.req_ies_len,
1963 				    data->assoc_info.reassoc);
1964 		break;
1965 #ifdef CONFIG_OWE
1966 	case EVENT_UPDATE_DH:
1967 		if (!data)
1968 			return;
1969 		hostapd_notif_update_dh_ie(hapd, data->update_dh.peer,
1970 					   data->update_dh.ie,
1971 					   data->update_dh.ie_len);
1972 		break;
1973 #endif /* CONFIG_OWE */
1974 	case EVENT_DISASSOC:
1975 		if (data)
1976 			hostapd_notif_disassoc(hapd, data->disassoc_info.addr);
1977 		break;
1978 	case EVENT_DEAUTH:
1979 		if (data)
1980 			hostapd_notif_disassoc(hapd, data->deauth_info.addr);
1981 		break;
1982 	case EVENT_STATION_LOW_ACK:
1983 		if (!data)
1984 			break;
1985 		hostapd_event_sta_low_ack(hapd, data->low_ack.addr);
1986 		break;
1987 	case EVENT_AUTH:
1988 		hostapd_notif_auth(hapd, &data->auth);
1989 		break;
1990 	case EVENT_CH_SWITCH_STARTED:
1991 	case EVENT_CH_SWITCH:
1992 		if (!data)
1993 			break;
1994 		hostapd_event_ch_switch(hapd, data->ch_switch.freq,
1995 					data->ch_switch.ht_enabled,
1996 					data->ch_switch.ch_offset,
1997 					data->ch_switch.ch_width,
1998 					data->ch_switch.cf1,
1999 					data->ch_switch.cf2,
2000 					event == EVENT_CH_SWITCH);
2001 		break;
2002 	case EVENT_CONNECT_FAILED_REASON:
2003 		if (!data)
2004 			break;
2005 		hostapd_event_connect_failed_reason(
2006 			hapd, data->connect_failed_reason.addr,
2007 			data->connect_failed_reason.code);
2008 		break;
2009 	case EVENT_SURVEY:
2010 		hostapd_event_get_survey(hapd->iface, &data->survey_results);
2011 		break;
2012 #ifdef NEED_AP_MLME
2013 	case EVENT_INTERFACE_UNAVAILABLE:
2014 		hostapd_event_iface_unavailable(hapd);
2015 		break;
2016 	case EVENT_DFS_RADAR_DETECTED:
2017 		if (!data)
2018 			break;
2019 		hostapd_event_dfs_radar_detected(hapd, &data->dfs_event);
2020 		break;
2021 	case EVENT_DFS_PRE_CAC_EXPIRED:
2022 		if (!data)
2023 			break;
2024 		hostapd_event_dfs_pre_cac_expired(hapd, &data->dfs_event);
2025 		break;
2026 	case EVENT_DFS_CAC_FINISHED:
2027 		if (!data)
2028 			break;
2029 		hostapd_event_dfs_cac_finished(hapd, &data->dfs_event);
2030 		break;
2031 	case EVENT_DFS_CAC_ABORTED:
2032 		if (!data)
2033 			break;
2034 		hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event);
2035 		break;
2036 	case EVENT_DFS_NOP_FINISHED:
2037 		if (!data)
2038 			break;
2039 		hostapd_event_dfs_nop_finished(hapd, &data->dfs_event);
2040 		break;
2041 	case EVENT_CHANNEL_LIST_CHANGED:
2042 		/* channel list changed (regulatory?), update channel list */
2043 		/* TODO: check this. hostapd_get_hw_features() initializes
2044 		 * too much stuff. */
2045 		/* hostapd_get_hw_features(hapd->iface); */
2046 		hostapd_channel_list_updated(
2047 			hapd->iface, data->channel_list_changed.initiator);
2048 		break;
2049 	case EVENT_DFS_CAC_STARTED:
2050 		if (!data)
2051 			break;
2052 		hostapd_event_dfs_cac_started(hapd, &data->dfs_event);
2053 		break;
2054 #endif /* NEED_AP_MLME */
2055 	case EVENT_INTERFACE_ENABLED:
2056 		wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED);
2057 		if (hapd->disabled && hapd->started) {
2058 			hapd->disabled = 0;
2059 			/*
2060 			 * Try to re-enable interface if the driver stopped it
2061 			 * when the interface got disabled.
2062 			 */
2063 			if (hapd->wpa_auth)
2064 				wpa_auth_reconfig_group_keys(hapd->wpa_auth);
2065 			else
2066 				hostapd_reconfig_encryption(hapd);
2067 			hapd->reenable_beacon = 1;
2068 			ieee802_11_set_beacon(hapd);
2069 #ifdef NEED_AP_MLME
2070 		} else if (hapd->disabled && hapd->iface->cac_started) {
2071 			wpa_printf(MSG_DEBUG, "DFS: restarting pending CAC");
2072 			hostapd_handle_dfs(hapd->iface);
2073 #endif /* NEED_AP_MLME */
2074 		}
2075 		break;
2076 	case EVENT_INTERFACE_DISABLED:
2077 		hostapd_free_stas(hapd);
2078 		wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED);
2079 		hapd->disabled = 1;
2080 		break;
2081 #ifdef CONFIG_ACS
2082 	case EVENT_ACS_CHANNEL_SELECTED:
2083 		hostapd_acs_channel_selected(hapd,
2084 					     &data->acs_selected_channels);
2085 		break;
2086 #endif /* CONFIG_ACS */
2087 	case EVENT_STATION_OPMODE_CHANGED:
2088 		hostapd_event_sta_opmode_changed(hapd, data->sta_opmode.addr,
2089 						 data->sta_opmode.smps_mode,
2090 						 data->sta_opmode.chan_width,
2091 						 data->sta_opmode.rx_nss);
2092 		break;
2093 	case EVENT_WDS_STA_INTERFACE_STATUS:
2094 		hostapd_event_wds_sta_interface_status(
2095 			hapd, data->wds_sta_interface.istatus,
2096 			data->wds_sta_interface.ifname,
2097 			data->wds_sta_interface.sta_addr);
2098 		break;
2099 #ifdef CONFIG_IEEE80211AX
2100 	case EVENT_BSS_COLOR_COLLISION:
2101 		/* The BSS color is shared amongst all BBSs on a specific phy.
2102 		 * Therefore we always start the color change on the primary
2103 		 * BSS. */
2104 		wpa_printf(MSG_DEBUG, "BSS color collision on %s",
2105 			   hapd->conf->iface);
2106 		hostapd_switch_color(hapd->iface->bss[0],
2107 				     data->bss_color_collision.bitmap);
2108 		break;
2109 	case EVENT_CCA_STARTED_NOTIFY:
2110 		wpa_printf(MSG_DEBUG, "CCA started on on %s",
2111 			   hapd->conf->iface);
2112 		break;
2113 	case EVENT_CCA_ABORTED_NOTIFY:
2114 		wpa_printf(MSG_DEBUG, "CCA aborted on on %s",
2115 			   hapd->conf->iface);
2116 		hostapd_cleanup_cca_params(hapd);
2117 		break;
2118 	case EVENT_CCA_NOTIFY:
2119 		wpa_printf(MSG_DEBUG, "CCA finished on on %s",
2120 			   hapd->conf->iface);
2121 		hapd->iface->conf->he_op.he_bss_color = hapd->cca_color;
2122 		hostapd_cleanup_cca_params(hapd);
2123 		break;
2124 #endif /* CONFIG_IEEE80211AX */
2125 	default:
2126 		wpa_printf(MSG_DEBUG, "Unknown event %d", event);
2127 		break;
2128 	}
2129 }
2130 
2131 
wpa_supplicant_event_global(void * ctx,enum wpa_event_type event,union wpa_event_data * data)2132 void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
2133 				 union wpa_event_data *data)
2134 {
2135 	struct hapd_interfaces *interfaces = ctx;
2136 	struct hostapd_data *hapd;
2137 
2138 	if (event != EVENT_INTERFACE_STATUS)
2139 		return;
2140 
2141 	hapd = hostapd_get_iface(interfaces, data->interface_status.ifname);
2142 	if (hapd && hapd->driver && hapd->driver->get_ifindex &&
2143 	    hapd->drv_priv) {
2144 		unsigned int ifindex;
2145 
2146 		ifindex = hapd->driver->get_ifindex(hapd->drv_priv);
2147 		if (ifindex != data->interface_status.ifindex) {
2148 			wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
2149 				"interface status ifindex %d mismatch (%d)",
2150 				ifindex, data->interface_status.ifindex);
2151 			return;
2152 		}
2153 	}
2154 	if (hapd)
2155 		wpa_supplicant_event(hapd, event, data);
2156 }
2157 
2158 #endif /* HOSTAPD */
2159