• 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 "crypto/random.h"
19 #include "p2p/p2p.h"
20 #include "wps/wps.h"
21 #include "fst/fst.h"
22 #include "wnm_ap.h"
23 #include "hostapd.h"
24 #include "ieee802_11.h"
25 #include "ieee802_11_auth.h"
26 #include "sta_info.h"
27 #include "accounting.h"
28 #include "tkip_countermeasures.h"
29 #include "ieee802_1x.h"
30 #include "wpa_auth.h"
31 #include "wps_hostapd.h"
32 #include "ap_drv_ops.h"
33 #include "ap_config.h"
34 #include "ap_mlme.h"
35 #include "hw_features.h"
36 #include "dfs.h"
37 #include "beacon.h"
38 #include "mbo_ap.h"
39 #include "dpp_hostapd.h"
40 #include "fils_hlp.h"
41 
42 
43 #ifdef CONFIG_FILS
hostapd_notify_assoc_fils_finish(struct hostapd_data * hapd,struct sta_info * sta)44 void hostapd_notify_assoc_fils_finish(struct hostapd_data *hapd,
45 				      struct sta_info *sta)
46 {
47 	u16 reply_res = WLAN_STATUS_SUCCESS;
48 	struct ieee802_11_elems elems;
49 	u8 buf[IEEE80211_MAX_MMPDU_SIZE], *p = buf;
50 	int new_assoc;
51 
52 	wpa_printf(MSG_DEBUG, "%s FILS: Finish association with " MACSTR,
53 		   __func__, MAC2STR(sta->addr));
54 	eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
55 	if (!sta->fils_pending_assoc_req)
56 		return;
57 
58 	ieee802_11_parse_elems(sta->fils_pending_assoc_req,
59 			       sta->fils_pending_assoc_req_len, &elems, 0);
60 	if (!elems.fils_session) {
61 		wpa_printf(MSG_DEBUG, "%s failed to find FILS Session element",
62 			   __func__);
63 		return;
64 	}
65 
66 	p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
67 					   elems.fils_session,
68 					   sta->fils_hlp_resp);
69 
70 	reply_res = hostapd_sta_assoc(hapd, sta->addr,
71 				      sta->fils_pending_assoc_is_reassoc,
72 				      WLAN_STATUS_SUCCESS,
73 				      buf, p - buf);
74 	ap_sta_set_authorized(hapd, sta, 1);
75 	new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
76 	sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
77 	sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
78 	hostapd_set_sta_flags(hapd, sta);
79 	wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
80 	ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
81 	hostapd_new_assoc_sta(hapd, sta, !new_assoc);
82 	os_free(sta->fils_pending_assoc_req);
83 	sta->fils_pending_assoc_req = NULL;
84 	sta->fils_pending_assoc_req_len = 0;
85 	wpabuf_free(sta->fils_hlp_resp);
86 	sta->fils_hlp_resp = NULL;
87 	wpabuf_free(sta->hlp_dhcp_discover);
88 	sta->hlp_dhcp_discover = NULL;
89 	fils_hlp_deinit(hapd);
90 
91 	/*
92 	 * Remove the station in case transmission of a success response fails
93 	 * (the STA was added associated to the driver) or if the station was
94 	 * previously added unassociated.
95 	 */
96 	if (reply_res != WLAN_STATUS_SUCCESS || sta->added_unassoc) {
97 		hostapd_drv_sta_remove(hapd, sta->addr);
98 		sta->added_unassoc = 0;
99 	}
100 }
101 #endif /* CONFIG_FILS */
102 
103 
hostapd_notif_assoc(struct hostapd_data * hapd,const u8 * addr,const u8 * req_ies,size_t req_ies_len,int reassoc)104 int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
105 			const u8 *req_ies, size_t req_ies_len, int reassoc)
106 {
107 	struct sta_info *sta;
108 	int new_assoc, res;
109 	struct ieee802_11_elems elems;
110 	const u8 *ie;
111 	size_t ielen;
112 #if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_IEEE80211W) || defined(CONFIG_FILS)
113 	u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
114 	u8 *p = buf;
115 #endif /* CONFIG_IEEE80211R_AP || CONFIG_IEEE80211W || CONFIG_FILS */
116 	u16 reason = WLAN_REASON_UNSPECIFIED;
117 	u16 status = WLAN_STATUS_SUCCESS;
118 	const u8 *p2p_dev_addr = NULL;
119 
120 	if (addr == NULL) {
121 		/*
122 		 * This could potentially happen with unexpected event from the
123 		 * driver wrapper. This was seen at least in one case where the
124 		 * driver ended up being set to station mode while hostapd was
125 		 * running, so better make sure we stop processing such an
126 		 * event here.
127 		 */
128 		wpa_printf(MSG_DEBUG,
129 			   "hostapd_notif_assoc: Skip event with no address");
130 		return -1;
131 	}
132 	random_add_randomness(addr, ETH_ALEN);
133 
134 	hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
135 		       HOSTAPD_LEVEL_INFO, "associated");
136 
137 	ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0);
138 	if (elems.wps_ie) {
139 		ie = elems.wps_ie - 2;
140 		ielen = elems.wps_ie_len + 2;
141 		wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq");
142 	} else if (elems.rsn_ie) {
143 		ie = elems.rsn_ie - 2;
144 		ielen = elems.rsn_ie_len + 2;
145 		wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq");
146 	} else if (elems.wpa_ie) {
147 		ie = elems.wpa_ie - 2;
148 		ielen = elems.wpa_ie_len + 2;
149 		wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq");
150 #ifdef CONFIG_HS20
151 	} else if (elems.osen) {
152 		ie = elems.osen - 2;
153 		ielen = elems.osen_len + 2;
154 		wpa_printf(MSG_DEBUG, "STA included OSEN IE in (Re)AssocReq");
155 #endif /* CONFIG_HS20 */
156 	} else {
157 		ie = NULL;
158 		ielen = 0;
159 		wpa_printf(MSG_DEBUG,
160 			   "STA did not include WPS/RSN/WPA IE in (Re)AssocReq");
161 	}
162 
163 	sta = ap_get_sta(hapd, addr);
164 	if (sta) {
165 		ap_sta_no_session_timeout(hapd, sta);
166 		accounting_sta_stop(hapd, sta);
167 
168 		/*
169 		 * Make sure that the previously registered inactivity timer
170 		 * will not remove the STA immediately.
171 		 */
172 		sta->timeout_next = STA_NULLFUNC;
173 	} else {
174 		sta = ap_sta_add(hapd, addr);
175 		if (sta == NULL) {
176 			hostapd_drv_sta_disassoc(hapd, addr,
177 						 WLAN_REASON_DISASSOC_AP_BUSY);
178 			return -1;
179 		}
180 	}
181 	sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
182 
183 	/*
184 	 * ACL configurations to the drivers (implementing AP SME and ACL
185 	 * offload) without hostapd's knowledge, can result in a disconnection
186 	 * though the driver accepts the connection. Skip the hostapd check for
187 	 * ACL if the driver supports ACL offload to avoid potentially
188 	 * conflicting ACL rules.
189 	 */
190 	if (hapd->iface->drv_max_acl_mac_addrs == 0 &&
191 	    hostapd_check_acl(hapd, addr, NULL) != HOSTAPD_ACL_ACCEPT) {
192 		wpa_printf(MSG_INFO, "STA " MACSTR " not allowed to connect",
193 			   MAC2STR(addr));
194 		reason = WLAN_REASON_UNSPECIFIED;
195 		goto fail;
196 	}
197 
198 #ifdef CONFIG_P2P
199 	if (elems.p2p) {
200 		wpabuf_free(sta->p2p_ie);
201 		sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
202 							  P2P_IE_VENDOR_TYPE);
203 		if (sta->p2p_ie)
204 			p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
205 	}
206 #endif /* CONFIG_P2P */
207 
208 #ifdef CONFIG_IEEE80211N
209 #ifdef NEED_AP_MLME
210 	if (elems.ht_capabilities &&
211 	    (hapd->iface->conf->ht_capab &
212 	     HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
213 		struct ieee80211_ht_capabilities *ht_cap =
214 			(struct ieee80211_ht_capabilities *)
215 			elems.ht_capabilities;
216 
217 		if (le_to_host16(ht_cap->ht_capabilities_info) &
218 		    HT_CAP_INFO_40MHZ_INTOLERANT)
219 			ht40_intolerant_add(hapd->iface, sta);
220 	}
221 #endif /* NEED_AP_MLME */
222 #endif /* CONFIG_IEEE80211N */
223 
224 #ifdef CONFIG_INTERWORKING
225 	if (elems.ext_capab && elems.ext_capab_len > 4) {
226 		if (elems.ext_capab[4] & 0x01)
227 			sta->qos_map_enabled = 1;
228 	}
229 #endif /* CONFIG_INTERWORKING */
230 
231 #ifdef CONFIG_HS20
232 	wpabuf_free(sta->hs20_ie);
233 	if (elems.hs20 && elems.hs20_len > 4) {
234 		sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
235 						 elems.hs20_len - 4);
236 	} else
237 		sta->hs20_ie = NULL;
238 #endif /* CONFIG_HS20 */
239 
240 #ifdef CONFIG_FST
241 	wpabuf_free(sta->mb_ies);
242 	if (hapd->iface->fst)
243 		sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
244 	else
245 		sta->mb_ies = NULL;
246 #endif /* CONFIG_FST */
247 
248 	mbo_ap_check_sta_assoc(hapd, sta, &elems);
249 
250 	ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
251 				    elems.supp_op_classes_len);
252 
253 	if (hapd->conf->wpa) {
254 		if (ie == NULL || ielen == 0) {
255 #ifdef CONFIG_WPS
256 			if (hapd->conf->wps_state) {
257 				wpa_printf(MSG_DEBUG,
258 					   "STA did not include WPA/RSN IE in (Re)Association Request - possible WPS use");
259 				sta->flags |= WLAN_STA_MAYBE_WPS;
260 				goto skip_wpa_check;
261 			}
262 #endif /* CONFIG_WPS */
263 
264 			wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA");
265 			return -1;
266 		}
267 #ifdef CONFIG_WPS
268 		if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 &&
269 		    os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
270 			struct wpabuf *wps;
271 
272 			sta->flags |= WLAN_STA_WPS;
273 			wps = ieee802_11_vendor_ie_concat(ie, ielen,
274 							  WPS_IE_VENDOR_TYPE);
275 			if (wps) {
276 				if (wps_is_20(wps)) {
277 					wpa_printf(MSG_DEBUG,
278 						   "WPS: STA supports WPS 2.0");
279 					sta->flags |= WLAN_STA_WPS2;
280 				}
281 				wpabuf_free(wps);
282 			}
283 			goto skip_wpa_check;
284 		}
285 #endif /* CONFIG_WPS */
286 
287 		if (sta->wpa_sm == NULL)
288 			sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
289 							sta->addr,
290 							p2p_dev_addr);
291 		if (sta->wpa_sm == NULL) {
292 			wpa_printf(MSG_ERROR,
293 				   "Failed to initialize WPA state machine");
294 			return -1;
295 		}
296 		res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
297 					  ie, ielen,
298 					  elems.mdie, elems.mdie_len,
299 					  elems.owe_dh, elems.owe_dh_len);
300 		if (res != WPA_IE_OK) {
301 			wpa_printf(MSG_DEBUG,
302 				   "WPA/RSN information element rejected? (res %u)",
303 				   res);
304 			wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
305 			if (res == WPA_INVALID_GROUP) {
306 				reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
307 				status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
308 			} else if (res == WPA_INVALID_PAIRWISE) {
309 				reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID;
310 				status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
311 			} else if (res == WPA_INVALID_AKMP) {
312 				reason = WLAN_REASON_AKMP_NOT_VALID;
313 				status = WLAN_STATUS_AKMP_NOT_VALID;
314 			}
315 #ifdef CONFIG_IEEE80211W
316 			else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION) {
317 				reason = WLAN_REASON_INVALID_IE;
318 				status = WLAN_STATUS_INVALID_IE;
319 			} else if (res == WPA_INVALID_MGMT_GROUP_CIPHER) {
320 				reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
321 				status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
322 			}
323 #endif /* CONFIG_IEEE80211W */
324 			else {
325 				reason = WLAN_REASON_INVALID_IE;
326 				status = WLAN_STATUS_INVALID_IE;
327 			}
328 			goto fail;
329 		}
330 #ifdef CONFIG_IEEE80211W
331 		if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
332 		    sta->sa_query_count > 0)
333 			ap_check_sa_query_timeout(hapd, sta);
334 		if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
335 		    (sta->auth_alg != WLAN_AUTH_FT)) {
336 			/*
337 			 * STA has already been associated with MFP and SA
338 			 * Query timeout has not been reached. Reject the
339 			 * association attempt temporarily and start SA Query,
340 			 * if one is not pending.
341 			 */
342 
343 			if (sta->sa_query_count == 0)
344 				ap_sta_start_sa_query(hapd, sta);
345 
346 			status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
347 
348 			p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
349 
350 			hostapd_sta_assoc(hapd, addr, reassoc, status, buf,
351 					  p - buf);
352 			return 0;
353 		}
354 
355 		if (wpa_auth_uses_mfp(sta->wpa_sm))
356 			sta->flags |= WLAN_STA_MFP;
357 		else
358 			sta->flags &= ~WLAN_STA_MFP;
359 #endif /* CONFIG_IEEE80211W */
360 
361 #ifdef CONFIG_IEEE80211R_AP
362 		if (sta->auth_alg == WLAN_AUTH_FT) {
363 			status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies,
364 							 req_ies_len);
365 			if (status != WLAN_STATUS_SUCCESS) {
366 				if (status == WLAN_STATUS_INVALID_PMKID)
367 					reason = WLAN_REASON_INVALID_IE;
368 				if (status == WLAN_STATUS_INVALID_MDIE)
369 					reason = WLAN_REASON_INVALID_IE;
370 				if (status == WLAN_STATUS_INVALID_FTIE)
371 					reason = WLAN_REASON_INVALID_IE;
372 				goto fail;
373 			}
374 		}
375 #endif /* CONFIG_IEEE80211R_AP */
376 	} else if (hapd->conf->wps_state) {
377 #ifdef CONFIG_WPS
378 		struct wpabuf *wps;
379 
380 		if (req_ies)
381 			wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
382 							  WPS_IE_VENDOR_TYPE);
383 		else
384 			wps = NULL;
385 #ifdef CONFIG_WPS_STRICT
386 		if (wps && wps_validate_assoc_req(wps) < 0) {
387 			reason = WLAN_REASON_INVALID_IE;
388 			status = WLAN_STATUS_INVALID_IE;
389 			wpabuf_free(wps);
390 			goto fail;
391 		}
392 #endif /* CONFIG_WPS_STRICT */
393 		if (wps) {
394 			sta->flags |= WLAN_STA_WPS;
395 			if (wps_is_20(wps)) {
396 				wpa_printf(MSG_DEBUG,
397 					   "WPS: STA supports WPS 2.0");
398 				sta->flags |= WLAN_STA_WPS2;
399 			}
400 		} else
401 			sta->flags |= WLAN_STA_MAYBE_WPS;
402 		wpabuf_free(wps);
403 #endif /* CONFIG_WPS */
404 #ifdef CONFIG_HS20
405 	} else if (hapd->conf->osen) {
406 		if (elems.osen == NULL) {
407 			hostapd_logger(
408 				hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
409 				HOSTAPD_LEVEL_INFO,
410 				"No HS 2.0 OSEN element in association request");
411 			return WLAN_STATUS_INVALID_IE;
412 		}
413 
414 		wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
415 		if (sta->wpa_sm == NULL)
416 			sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
417 							sta->addr, NULL);
418 		if (sta->wpa_sm == NULL) {
419 			wpa_printf(MSG_WARNING,
420 				   "Failed to initialize WPA state machine");
421 			return WLAN_STATUS_UNSPECIFIED_FAILURE;
422 		}
423 		if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
424 				      elems.osen - 2, elems.osen_len + 2) < 0)
425 			return WLAN_STATUS_INVALID_IE;
426 #endif /* CONFIG_HS20 */
427 	}
428 
429 #ifdef CONFIG_MBO
430 	if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
431 	    elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
432 	    hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
433 		wpa_printf(MSG_INFO,
434 			   "MBO: Reject WPA2 association without PMF");
435 		return WLAN_STATUS_UNSPECIFIED_FAILURE;
436 	}
437 #endif /* CONFIG_MBO */
438 
439 #ifdef CONFIG_WPS
440 skip_wpa_check:
441 #endif /* CONFIG_WPS */
442 
443 #ifdef CONFIG_IEEE80211R_AP
444 	p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf),
445 					sta->auth_alg, req_ies, req_ies_len);
446 #endif /* CONFIG_IEEE80211R_AP */
447 
448 #ifdef CONFIG_FILS
449 	if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
450 	    sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
451 	    sta->auth_alg == WLAN_AUTH_FILS_PK) {
452 		int delay_assoc = 0;
453 
454 		if (!req_ies)
455 			return WLAN_STATUS_UNSPECIFIED_FAILURE;
456 
457 		if (!wpa_fils_validate_fils_session(sta->wpa_sm, req_ies,
458 						    req_ies_len,
459 						    sta->fils_session)) {
460 			wpa_printf(MSG_DEBUG,
461 				   "FILS: Session validation failed");
462 			return WLAN_STATUS_UNSPECIFIED_FAILURE;
463 		}
464 
465 		res = wpa_fils_validate_key_confirm(sta->wpa_sm, req_ies,
466 						    req_ies_len);
467 		if (res < 0) {
468 			wpa_printf(MSG_DEBUG,
469 				   "FILS: Key Confirm validation failed");
470 			return WLAN_STATUS_UNSPECIFIED_FAILURE;
471 		}
472 
473 		if (fils_process_hlp(hapd, sta, req_ies, req_ies_len) > 0) {
474 			wpa_printf(MSG_DEBUG,
475 				   "FILS: Delaying Assoc Response (HLP)");
476 			delay_assoc = 1;
477 		} else {
478 			wpa_printf(MSG_DEBUG,
479 				   "FILS: Going ahead with Assoc Response (no HLP)");
480 		}
481 
482 		if (sta) {
483 			wpa_printf(MSG_DEBUG, "FILS: HLP callback cleanup");
484 			eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
485 			os_free(sta->fils_pending_assoc_req);
486 			sta->fils_pending_assoc_req = NULL;
487 			sta->fils_pending_assoc_req_len = 0;
488 			wpabuf_free(sta->fils_hlp_resp);
489 			sta->fils_hlp_resp = NULL;
490 			sta->fils_drv_assoc_finish = 0;
491 		}
492 
493 		if (sta && delay_assoc && status == WLAN_STATUS_SUCCESS) {
494 			u8 *req_tmp;
495 
496 			req_tmp = os_malloc(req_ies_len);
497 			if (!req_tmp) {
498 				wpa_printf(MSG_DEBUG,
499 					   "FILS: buffer allocation failed for assoc req");
500 				goto fail;
501 			}
502 			os_memcpy(req_tmp, req_ies, req_ies_len);
503 			sta->fils_pending_assoc_req = req_tmp;
504 			sta->fils_pending_assoc_req_len = req_ies_len;
505 			sta->fils_pending_assoc_is_reassoc = reassoc;
506 			sta->fils_drv_assoc_finish = 1;
507 			wpa_printf(MSG_DEBUG,
508 				   "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
509 				   MACSTR, MAC2STR(sta->addr));
510 			eloop_register_timeout(
511 				0, hapd->conf->fils_hlp_wait_time * 1024,
512 				fils_hlp_timeout, hapd, sta);
513 			return 0;
514 		}
515 		p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
516 						   elems.fils_session,
517 						   sta->fils_hlp_resp);
518 		wpa_hexdump(MSG_DEBUG, "FILS Assoc Resp BUF (IEs)",
519 			    buf, p - buf);
520 	}
521 #endif /* CONFIG_FILS */
522 
523 #if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_FILS)
524 	hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
525 
526 	if (sta->auth_alg == WLAN_AUTH_FT ||
527 	    sta->auth_alg == WLAN_AUTH_FILS_SK ||
528 	    sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
529 	    sta->auth_alg == WLAN_AUTH_FILS_PK)
530 		ap_sta_set_authorized(hapd, sta, 1);
531 #else /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
532 	/* Keep compiler silent about unused variables */
533 	if (status) {
534 	}
535 #endif /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
536 
537 	new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
538 	sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
539 	sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
540 
541 	hostapd_set_sta_flags(hapd, sta);
542 
543 	if (reassoc && (sta->auth_alg == WLAN_AUTH_FT))
544 		wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
545 #ifdef CONFIG_FILS
546 	else if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
547 		 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
548 		 sta->auth_alg == WLAN_AUTH_FILS_PK)
549 		wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
550 #endif /* CONFIG_FILS */
551 	else
552 		wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
553 
554 	hostapd_new_assoc_sta(hapd, sta, !new_assoc);
555 
556 	ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
557 
558 #ifdef CONFIG_P2P
559 	if (req_ies) {
560 		p2p_group_notif_assoc(hapd->p2p_group, sta->addr,
561 				      req_ies, req_ies_len);
562 	}
563 #endif /* CONFIG_P2P */
564 
565 	return 0;
566 
567 fail:
568 #ifdef CONFIG_IEEE80211R_AP
569 	hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
570 #endif /* CONFIG_IEEE80211R_AP */
571 	hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
572 	ap_free_sta(hapd, sta);
573 	return -1;
574 }
575 
576 
hostapd_notif_disassoc(struct hostapd_data * hapd,const u8 * addr)577 void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr)
578 {
579 	struct sta_info *sta;
580 
581 	if (addr == NULL) {
582 		/*
583 		 * This could potentially happen with unexpected event from the
584 		 * driver wrapper. This was seen at least in one case where the
585 		 * driver ended up reporting a station mode event while hostapd
586 		 * was running, so better make sure we stop processing such an
587 		 * event here.
588 		 */
589 		wpa_printf(MSG_DEBUG,
590 			   "hostapd_notif_disassoc: Skip event with no address");
591 		return;
592 	}
593 
594 	hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
595 		       HOSTAPD_LEVEL_INFO, "disassociated");
596 
597 	sta = ap_get_sta(hapd, addr);
598 	if (sta == NULL) {
599 		wpa_printf(MSG_DEBUG,
600 			   "Disassociation notification for unknown STA "
601 			   MACSTR, MAC2STR(addr));
602 		return;
603 	}
604 
605 	ap_sta_set_authorized(hapd, sta, 0);
606 	sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
607 	wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
608 	sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
609 	ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
610 	ap_free_sta(hapd, sta);
611 }
612 
613 
hostapd_event_sta_low_ack(struct hostapd_data * hapd,const u8 * addr)614 void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr)
615 {
616 	struct sta_info *sta = ap_get_sta(hapd, addr);
617 
618 	if (!sta || !hapd->conf->disassoc_low_ack)
619 		return;
620 
621 	hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
622 		       HOSTAPD_LEVEL_INFO,
623 		       "disconnected due to excessive missing ACKs");
624 	hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK);
625 	ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK);
626 }
627 
628 
hostapd_event_ch_switch(struct hostapd_data * hapd,int freq,int ht,int offset,int width,int cf1,int cf2)629 void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
630 			     int offset, int width, int cf1, int cf2)
631 {
632 #ifdef NEED_AP_MLME
633 	int channel, chwidth, is_dfs;
634 	u8 seg0_idx = 0, seg1_idx = 0;
635 
636 	hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
637 		       HOSTAPD_LEVEL_INFO,
638 		       "driver had channel switch: freq=%d, ht=%d, offset=%d, width=%d (%s), cf1=%d, cf2=%d",
639 		       freq, ht, offset, width, channel_width_to_string(width),
640 		       cf1, cf2);
641 
642 	hapd->iface->freq = freq;
643 
644 	channel = hostapd_hw_get_channel(hapd, freq);
645 	if (!channel) {
646 		hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
647 			       HOSTAPD_LEVEL_WARNING,
648 			       "driver switched to bad channel!");
649 		return;
650 	}
651 
652 	switch (width) {
653 	case CHAN_WIDTH_80:
654 		chwidth = VHT_CHANWIDTH_80MHZ;
655 		break;
656 	case CHAN_WIDTH_80P80:
657 		chwidth = VHT_CHANWIDTH_80P80MHZ;
658 		break;
659 	case CHAN_WIDTH_160:
660 		chwidth = VHT_CHANWIDTH_160MHZ;
661 		break;
662 	case CHAN_WIDTH_20_NOHT:
663 	case CHAN_WIDTH_20:
664 	case CHAN_WIDTH_40:
665 	default:
666 		chwidth = VHT_CHANWIDTH_USE_HT;
667 		break;
668 	}
669 
670 	switch (hapd->iface->current_mode->mode) {
671 	case HOSTAPD_MODE_IEEE80211A:
672 		if (cf1 > 5000)
673 			seg0_idx = (cf1 - 5000) / 5;
674 		if (cf2 > 5000)
675 			seg1_idx = (cf2 - 5000) / 5;
676 		break;
677 	default:
678 		ieee80211_freq_to_chan(cf1, &seg0_idx);
679 		ieee80211_freq_to_chan(cf2, &seg1_idx);
680 		break;
681 	}
682 
683 	hapd->iconf->channel = channel;
684 	hapd->iconf->ieee80211n = ht;
685 	if (!ht)
686 		hapd->iconf->ieee80211ac = 0;
687 	hapd->iconf->secondary_channel = offset;
688 	hapd->iconf->vht_oper_chwidth = chwidth;
689 	hapd->iconf->vht_oper_centr_freq_seg0_idx = seg0_idx;
690 	hapd->iconf->vht_oper_centr_freq_seg1_idx = seg1_idx;
691 
692 	is_dfs = ieee80211_is_dfs(freq);
693 
694 	if (hapd->csa_in_progress &&
695 	    freq == hapd->cs_freq_params.freq) {
696 		hostapd_cleanup_cs_params(hapd);
697 		ieee802_11_set_beacon(hapd);
698 
699 		wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
700 			"freq=%d dfs=%d", freq, is_dfs);
701 	} else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) {
702 		wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
703 			"freq=%d dfs=%d", freq, is_dfs);
704 	}
705 #endif /* NEED_AP_MLME */
706 }
707 
708 
hostapd_event_connect_failed_reason(struct hostapd_data * hapd,const u8 * addr,int reason_code)709 void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
710 					 const u8 *addr, int reason_code)
711 {
712 	switch (reason_code) {
713 	case MAX_CLIENT_REACHED:
714 		wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR,
715 			MAC2STR(addr));
716 		break;
717 	case BLOCKED_CLIENT:
718 		wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR,
719 			MAC2STR(addr));
720 		break;
721 	}
722 }
723 
724 
725 #ifdef CONFIG_ACS
hostapd_acs_channel_selected(struct hostapd_data * hapd,struct acs_selected_channels * acs_res)726 void hostapd_acs_channel_selected(struct hostapd_data *hapd,
727 				  struct acs_selected_channels *acs_res)
728 {
729 	int ret, i;
730 	int err = 0;
731 
732 	if (hapd->iconf->channel) {
733 		wpa_printf(MSG_INFO, "ACS: Channel was already set to %d",
734 			   hapd->iconf->channel);
735 		return;
736 	}
737 
738 	if (!hapd->iface->current_mode) {
739 		for (i = 0; i < hapd->iface->num_hw_features; i++) {
740 			struct hostapd_hw_modes *mode =
741 				&hapd->iface->hw_features[i];
742 
743 			if (mode->mode == acs_res->hw_mode) {
744 				hapd->iface->current_mode = mode;
745 				break;
746 			}
747 		}
748 		if (!hapd->iface->current_mode) {
749 			hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
750 				       HOSTAPD_LEVEL_WARNING,
751 				       "driver selected to bad hw_mode");
752 			err = 1;
753 			goto out;
754 		}
755 	}
756 
757 	hapd->iface->freq = hostapd_hw_get_freq(hapd, acs_res->pri_channel);
758 
759 	if (!acs_res->pri_channel) {
760 		hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
761 			       HOSTAPD_LEVEL_WARNING,
762 			       "driver switched to bad channel");
763 		err = 1;
764 		goto out;
765 	}
766 
767 	hapd->iconf->channel = acs_res->pri_channel;
768 	hapd->iconf->acs = 1;
769 
770 	if (acs_res->sec_channel == 0)
771 		hapd->iconf->secondary_channel = 0;
772 	else if (acs_res->sec_channel < acs_res->pri_channel)
773 		hapd->iconf->secondary_channel = -1;
774 	else if (acs_res->sec_channel > acs_res->pri_channel)
775 		hapd->iconf->secondary_channel = 1;
776 	else {
777 		wpa_printf(MSG_ERROR, "Invalid secondary channel!");
778 		err = 1;
779 		goto out;
780 	}
781 
782 	if (hapd->iface->conf->ieee80211ac) {
783 		/* set defaults for backwards compatibility */
784 		hapd->iconf->vht_oper_centr_freq_seg1_idx = 0;
785 		hapd->iconf->vht_oper_centr_freq_seg0_idx = 0;
786 		hapd->iconf->vht_oper_chwidth = VHT_CHANWIDTH_USE_HT;
787 		if (acs_res->ch_width == 80) {
788 			hapd->iconf->vht_oper_centr_freq_seg0_idx =
789 				acs_res->vht_seg0_center_ch;
790 			hapd->iconf->vht_oper_chwidth = VHT_CHANWIDTH_80MHZ;
791 		} else if (acs_res->ch_width == 160) {
792 			if (acs_res->vht_seg1_center_ch == 0) {
793 				hapd->iconf->vht_oper_centr_freq_seg0_idx =
794 					acs_res->vht_seg0_center_ch;
795 				hapd->iconf->vht_oper_chwidth =
796 					VHT_CHANWIDTH_160MHZ;
797 			} else {
798 				hapd->iconf->vht_oper_centr_freq_seg0_idx =
799 					acs_res->vht_seg0_center_ch;
800 				hapd->iconf->vht_oper_centr_freq_seg1_idx =
801 					acs_res->vht_seg1_center_ch;
802 				hapd->iconf->vht_oper_chwidth =
803 					VHT_CHANWIDTH_80P80MHZ;
804 			}
805 		}
806 	}
807 
808 out:
809 	ret = hostapd_acs_completed(hapd->iface, err);
810 	if (ret) {
811 		wpa_printf(MSG_ERROR,
812 			   "ACS: Possibly channel configuration is invalid");
813 	}
814 }
815 #endif /* CONFIG_ACS */
816 
817 
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)818 int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
819 			 const u8 *bssid, const u8 *ie, size_t ie_len,
820 			 int ssi_signal)
821 {
822 	size_t i;
823 	int ret = 0;
824 
825 	if (sa == NULL || ie == NULL)
826 		return -1;
827 
828 	random_add_randomness(sa, ETH_ALEN);
829 	for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) {
830 		if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
831 					    sa, da, bssid, ie, ie_len,
832 					    ssi_signal) > 0) {
833 			ret = 1;
834 			break;
835 		}
836 	}
837 	return ret;
838 }
839 
840 
841 #ifdef HOSTAPD
842 
843 #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)844 static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst,
845 					  const u8 *bssid,
846 					  u16 auth_transaction, u16 status,
847 					  const u8 *ies, size_t ies_len)
848 {
849 	struct hostapd_data *hapd = ctx;
850 	struct sta_info *sta;
851 
852 	sta = ap_get_sta(hapd, dst);
853 	if (sta == NULL)
854 		return;
855 
856 	hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
857 		       HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
858 	sta->flags |= WLAN_STA_AUTH;
859 
860 	hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len);
861 }
862 #endif /* CONFIG_IEEE80211R_AP */
863 
864 
865 #ifdef CONFIG_FILS
hostapd_notify_auth_fils_finish(struct hostapd_data * hapd,struct sta_info * sta,u16 resp,struct wpabuf * data,int pub)866 static void hostapd_notify_auth_fils_finish(struct hostapd_data *hapd,
867 					    struct sta_info *sta, u16 resp,
868 					    struct wpabuf *data, int pub)
869 {
870 	if (resp == WLAN_STATUS_SUCCESS) {
871 		hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
872 			       HOSTAPD_LEVEL_DEBUG, "authentication OK (FILS)");
873 		sta->flags |= WLAN_STA_AUTH;
874 		wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
875 		sta->auth_alg = WLAN_AUTH_FILS_SK;
876 		mlme_authenticate_indication(hapd, sta);
877 	} else {
878 		hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
879 			       HOSTAPD_LEVEL_DEBUG,
880 			       "authentication failed (FILS)");
881 	}
882 
883 	hostapd_sta_auth(hapd, sta->addr, 2, resp,
884 			 data ? wpabuf_head(data) : NULL,
885 			 data ? wpabuf_len(data) : 0);
886 	wpabuf_free(data);
887 }
888 #endif /* CONFIG_FILS */
889 
890 
hostapd_notif_auth(struct hostapd_data * hapd,struct auth_info * rx_auth)891 static void hostapd_notif_auth(struct hostapd_data *hapd,
892 			       struct auth_info *rx_auth)
893 {
894 	struct sta_info *sta;
895 	u16 status = WLAN_STATUS_SUCCESS;
896 	u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
897 	size_t resp_ies_len = 0;
898 
899 	sta = ap_get_sta(hapd, rx_auth->peer);
900 	if (!sta) {
901 		sta = ap_sta_add(hapd, rx_auth->peer);
902 		if (sta == NULL) {
903 			status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
904 			goto fail;
905 		}
906 	}
907 	sta->flags &= ~WLAN_STA_PREAUTH;
908 	ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
909 #ifdef CONFIG_IEEE80211R_AP
910 	if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) {
911 		sta->auth_alg = WLAN_AUTH_FT;
912 		if (sta->wpa_sm == NULL)
913 			sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
914 							sta->addr, NULL);
915 		if (sta->wpa_sm == NULL) {
916 			wpa_printf(MSG_DEBUG,
917 				   "FT: Failed to initialize WPA state machine");
918 			status = WLAN_STATUS_UNSPECIFIED_FAILURE;
919 			goto fail;
920 		}
921 		wpa_ft_process_auth(sta->wpa_sm, rx_auth->bssid,
922 				    rx_auth->auth_transaction, rx_auth->ies,
923 				    rx_auth->ies_len,
924 				    hostapd_notify_auth_ft_finish, hapd);
925 		return;
926 	}
927 #endif /* CONFIG_IEEE80211R_AP */
928 
929 #ifdef CONFIG_FILS
930 	if (rx_auth->auth_type == WLAN_AUTH_FILS_SK) {
931 		sta->auth_alg = WLAN_AUTH_FILS_SK;
932 		handle_auth_fils(hapd, sta, rx_auth->ies, rx_auth->ies_len,
933 				 rx_auth->auth_type, rx_auth->auth_transaction,
934 				 rx_auth->status_code,
935 				 hostapd_notify_auth_fils_finish);
936 		return;
937 	}
938 #endif /* CONFIG_FILS */
939 
940 fail:
941 	hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1,
942 			 status, resp_ies, resp_ies_len);
943 }
944 
945 
hostapd_action_rx(struct hostapd_data * hapd,struct rx_mgmt * drv_mgmt)946 static void hostapd_action_rx(struct hostapd_data *hapd,
947 			      struct rx_mgmt *drv_mgmt)
948 {
949 	struct ieee80211_mgmt *mgmt;
950 	struct sta_info *sta;
951 	size_t plen __maybe_unused;
952 	u16 fc;
953 
954 	if (drv_mgmt->frame_len < 24 + 1)
955 		return;
956 
957 	plen = drv_mgmt->frame_len - 24 - 1;
958 
959 	mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame;
960 	fc = le_to_host16(mgmt->frame_control);
961 	if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION)
962 		return; /* handled by the driver */
963 
964 	wpa_printf(MSG_DEBUG, "RX_ACTION cat %d action plen %d",
965 		   mgmt->u.action.category, (int) plen);
966 
967 	sta = ap_get_sta(hapd, mgmt->sa);
968 	if (sta == NULL) {
969 		wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
970 		return;
971 	}
972 #ifdef CONFIG_IEEE80211R_AP
973 	if (mgmt->u.action.category == WLAN_ACTION_FT) {
974 		const u8 *payload = drv_mgmt->frame + 24 + 1;
975 
976 		wpa_ft_action_rx(sta->wpa_sm, payload, plen);
977 	}
978 #endif /* CONFIG_IEEE80211R_AP */
979 #ifdef CONFIG_IEEE80211W
980 	if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY && plen >= 4) {
981 		ieee802_11_sa_query_action(
982 			hapd, mgmt->sa,
983 			mgmt->u.action.u.sa_query_resp.action,
984 			mgmt->u.action.u.sa_query_resp.trans_id);
985 	}
986 #endif /* CONFIG_IEEE80211W */
987 #ifdef CONFIG_WNM_AP
988 	if (mgmt->u.action.category == WLAN_ACTION_WNM) {
989 		ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len);
990 	}
991 #endif /* CONFIG_WNM_AP */
992 #ifdef CONFIG_FST
993 	if (mgmt->u.action.category == WLAN_ACTION_FST && hapd->iface->fst) {
994 		fst_rx_action(hapd->iface->fst, mgmt, drv_mgmt->frame_len);
995 		return;
996 	}
997 #endif /* CONFIG_FST */
998 #ifdef CONFIG_DPP
999 	if (plen >= 1 + 4 &&
1000 	    mgmt->u.action.u.vs_public_action.action ==
1001 	    WLAN_PA_VENDOR_SPECIFIC &&
1002 	    WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
1003 	    OUI_WFA &&
1004 	    mgmt->u.action.u.vs_public_action.variable[0] ==
1005 	    DPP_OUI_TYPE) {
1006 		const u8 *pos, *end;
1007 
1008 		pos = mgmt->u.action.u.vs_public_action.oui;
1009 		end = drv_mgmt->frame + drv_mgmt->frame_len;
1010 		hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos,
1011 				      drv_mgmt->freq);
1012 		return;
1013 	}
1014 #endif /* CONFIG_DPP */
1015 }
1016 
1017 
1018 #ifdef NEED_AP_MLME
1019 
1020 #define HAPD_BROADCAST ((struct hostapd_data *) -1)
1021 
get_hapd_bssid(struct hostapd_iface * iface,const u8 * bssid)1022 static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface,
1023 					    const u8 *bssid)
1024 {
1025 	size_t i;
1026 
1027 	if (bssid == NULL)
1028 		return NULL;
1029 	if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff &&
1030 	    bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff)
1031 		return HAPD_BROADCAST;
1032 
1033 	for (i = 0; i < iface->num_bss; i++) {
1034 		if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0)
1035 			return iface->bss[i];
1036 	}
1037 
1038 	return NULL;
1039 }
1040 
1041 
hostapd_rx_from_unknown_sta(struct hostapd_data * hapd,const u8 * bssid,const u8 * addr,int wds)1042 static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd,
1043 					const u8 *bssid, const u8 *addr,
1044 					int wds)
1045 {
1046 	hapd = get_hapd_bssid(hapd->iface, bssid);
1047 	if (hapd == NULL || hapd == HAPD_BROADCAST)
1048 		return;
1049 
1050 	ieee802_11_rx_from_unknown(hapd, addr, wds);
1051 }
1052 
1053 
hostapd_mgmt_rx(struct hostapd_data * hapd,struct rx_mgmt * rx_mgmt)1054 static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt)
1055 {
1056 	struct hostapd_iface *iface = hapd->iface;
1057 	const struct ieee80211_hdr *hdr;
1058 	const u8 *bssid;
1059 	struct hostapd_frame_info fi;
1060 	int ret;
1061 
1062 #ifdef CONFIG_TESTING_OPTIONS
1063 	if (hapd->ext_mgmt_frame_handling) {
1064 		size_t hex_len = 2 * rx_mgmt->frame_len + 1;
1065 		char *hex = os_malloc(hex_len);
1066 
1067 		if (hex) {
1068 			wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame,
1069 					 rx_mgmt->frame_len);
1070 			wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex);
1071 			os_free(hex);
1072 		}
1073 		return 1;
1074 	}
1075 #endif /* CONFIG_TESTING_OPTIONS */
1076 
1077 	hdr = (const struct ieee80211_hdr *) rx_mgmt->frame;
1078 	bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len);
1079 	if (bssid == NULL)
1080 		return 0;
1081 
1082 	hapd = get_hapd_bssid(iface, bssid);
1083 	if (hapd == NULL) {
1084 		u16 fc = le_to_host16(hdr->frame_control);
1085 
1086 		/*
1087 		 * Drop frames to unknown BSSIDs except for Beacon frames which
1088 		 * could be used to update neighbor information.
1089 		 */
1090 		if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1091 		    WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1092 			hapd = iface->bss[0];
1093 		else
1094 			return 0;
1095 	}
1096 
1097 	os_memset(&fi, 0, sizeof(fi));
1098 	fi.datarate = rx_mgmt->datarate;
1099 	fi.ssi_signal = rx_mgmt->ssi_signal;
1100 
1101 	if (hapd == HAPD_BROADCAST) {
1102 		size_t i;
1103 
1104 		ret = 0;
1105 		for (i = 0; i < iface->num_bss; i++) {
1106 			/* if bss is set, driver will call this function for
1107 			 * each bss individually. */
1108 			if (rx_mgmt->drv_priv &&
1109 			    (iface->bss[i]->drv_priv != rx_mgmt->drv_priv))
1110 				continue;
1111 
1112 			if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame,
1113 					    rx_mgmt->frame_len, &fi) > 0)
1114 				ret = 1;
1115 		}
1116 	} else
1117 		ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len,
1118 				      &fi);
1119 
1120 	random_add_randomness(&fi, sizeof(fi));
1121 
1122 	return ret;
1123 }
1124 
1125 
hostapd_mgmt_tx_cb(struct hostapd_data * hapd,const u8 * buf,size_t len,u16 stype,int ok)1126 static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf,
1127 			       size_t len, u16 stype, int ok)
1128 {
1129 	struct ieee80211_hdr *hdr;
1130 	struct hostapd_data *orig_hapd = hapd;
1131 
1132 	hdr = (struct ieee80211_hdr *) buf;
1133 	hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len));
1134 	if (!hapd)
1135 		return;
1136 	if (hapd == HAPD_BROADCAST) {
1137 		if (stype != WLAN_FC_STYPE_ACTION || len <= 25 ||
1138 		    buf[24] != WLAN_ACTION_PUBLIC)
1139 			return;
1140 		hapd = get_hapd_bssid(orig_hapd->iface, hdr->addr2);
1141 		if (!hapd || hapd == HAPD_BROADCAST)
1142 			return;
1143 		/*
1144 		 * Allow processing of TX status for a Public Action frame that
1145 		 * used wildcard BBSID.
1146 		 */
1147 	}
1148 	ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
1149 }
1150 
1151 #endif /* NEED_AP_MLME */
1152 
1153 
hostapd_event_new_sta(struct hostapd_data * hapd,const u8 * addr)1154 static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr)
1155 {
1156 	struct sta_info *sta = ap_get_sta(hapd, addr);
1157 
1158 	if (sta)
1159 		return 0;
1160 
1161 	wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
1162 		   " - adding a new STA", MAC2STR(addr));
1163 	sta = ap_sta_add(hapd, addr);
1164 	if (sta) {
1165 		hostapd_new_assoc_sta(hapd, sta, 0);
1166 	} else {
1167 		wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
1168 			   MAC2STR(addr));
1169 		return -1;
1170 	}
1171 
1172 	return 0;
1173 }
1174 
1175 
hostapd_event_eapol_rx(struct hostapd_data * hapd,const u8 * src,const u8 * data,size_t data_len)1176 static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src,
1177 				   const u8 *data, size_t data_len)
1178 {
1179 	struct hostapd_iface *iface = hapd->iface;
1180 	struct sta_info *sta;
1181 	size_t j;
1182 
1183 	for (j = 0; j < iface->num_bss; j++) {
1184 		sta = ap_get_sta(iface->bss[j], src);
1185 		if (sta && sta->flags & WLAN_STA_ASSOC) {
1186 			hapd = iface->bss[j];
1187 			break;
1188 		}
1189 	}
1190 
1191 	ieee802_1x_receive(hapd, src, data, data_len);
1192 }
1193 
1194 #endif /* HOSTAPD */
1195 
1196 
hostapd_get_mode_channel(struct hostapd_iface * iface,unsigned int freq)1197 static struct hostapd_channel_data * hostapd_get_mode_channel(
1198 	struct hostapd_iface *iface, unsigned int freq)
1199 {
1200 	int i;
1201 	struct hostapd_channel_data *chan;
1202 
1203 	for (i = 0; i < iface->current_mode->num_channels; i++) {
1204 		chan = &iface->current_mode->channels[i];
1205 		if ((unsigned int) chan->freq == freq)
1206 			return chan;
1207 	}
1208 
1209 	return NULL;
1210 }
1211 
1212 
hostapd_update_nf(struct hostapd_iface * iface,struct hostapd_channel_data * chan,struct freq_survey * survey)1213 static void hostapd_update_nf(struct hostapd_iface *iface,
1214 			      struct hostapd_channel_data *chan,
1215 			      struct freq_survey *survey)
1216 {
1217 	if (!iface->chans_surveyed) {
1218 		chan->min_nf = survey->nf;
1219 		iface->lowest_nf = survey->nf;
1220 	} else {
1221 		if (dl_list_empty(&chan->survey_list))
1222 			chan->min_nf = survey->nf;
1223 		else if (survey->nf < chan->min_nf)
1224 			chan->min_nf = survey->nf;
1225 		if (survey->nf < iface->lowest_nf)
1226 			iface->lowest_nf = survey->nf;
1227 	}
1228 }
1229 
1230 
hostapd_single_channel_get_survey(struct hostapd_iface * iface,struct survey_results * survey_res)1231 static void hostapd_single_channel_get_survey(struct hostapd_iface *iface,
1232 					      struct survey_results *survey_res)
1233 {
1234 	struct hostapd_channel_data *chan;
1235 	struct freq_survey *survey;
1236 	u64 divisor, dividend;
1237 
1238 	survey = dl_list_first(&survey_res->survey_list, struct freq_survey,
1239 			       list);
1240 	if (!survey || !survey->freq)
1241 		return;
1242 
1243 	chan = hostapd_get_mode_channel(iface, survey->freq);
1244 	if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED)
1245 		return;
1246 
1247 	wpa_printf(MSG_DEBUG,
1248 		   "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)",
1249 		   survey->freq,
1250 		   (unsigned long int) survey->channel_time,
1251 		   (unsigned long int) survey->channel_time_busy);
1252 
1253 	if (survey->channel_time > iface->last_channel_time &&
1254 	    survey->channel_time > survey->channel_time_busy) {
1255 		dividend = survey->channel_time_busy -
1256 			iface->last_channel_time_busy;
1257 		divisor = survey->channel_time - iface->last_channel_time;
1258 
1259 		iface->channel_utilization = dividend * 255 / divisor;
1260 		wpa_printf(MSG_DEBUG, "Channel Utilization: %d",
1261 			   iface->channel_utilization);
1262 	}
1263 	iface->last_channel_time = survey->channel_time;
1264 	iface->last_channel_time_busy = survey->channel_time_busy;
1265 }
1266 
1267 
hostapd_event_get_survey(struct hostapd_iface * iface,struct survey_results * survey_results)1268 void hostapd_event_get_survey(struct hostapd_iface *iface,
1269 			      struct survey_results *survey_results)
1270 {
1271 	struct freq_survey *survey, *tmp;
1272 	struct hostapd_channel_data *chan;
1273 
1274 	if (dl_list_empty(&survey_results->survey_list)) {
1275 		wpa_printf(MSG_DEBUG, "No survey data received");
1276 		return;
1277 	}
1278 
1279 	if (survey_results->freq_filter) {
1280 		hostapd_single_channel_get_survey(iface, survey_results);
1281 		return;
1282 	}
1283 
1284 	dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
1285 			      struct freq_survey, list) {
1286 		chan = hostapd_get_mode_channel(iface, survey->freq);
1287 		if (!chan)
1288 			continue;
1289 		if (chan->flag & HOSTAPD_CHAN_DISABLED)
1290 			continue;
1291 
1292 		dl_list_del(&survey->list);
1293 		dl_list_add_tail(&chan->survey_list, &survey->list);
1294 
1295 		hostapd_update_nf(iface, chan, survey);
1296 
1297 		iface->chans_surveyed++;
1298 	}
1299 }
1300 
1301 
1302 #ifdef HOSTAPD
1303 #ifdef NEED_AP_MLME
1304 
hostapd_event_iface_unavailable(struct hostapd_data * hapd)1305 static void hostapd_event_iface_unavailable(struct hostapd_data *hapd)
1306 {
1307 	wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped",
1308 		   hapd->conf->iface);
1309 
1310 	if (hapd->csa_in_progress) {
1311 		wpa_printf(MSG_INFO, "CSA failed (%s was stopped)",
1312 			   hapd->conf->iface);
1313 		hostapd_switch_channel_fallback(hapd->iface,
1314 						&hapd->cs_freq_params);
1315 	}
1316 }
1317 
1318 
hostapd_event_dfs_radar_detected(struct hostapd_data * hapd,struct dfs_event * radar)1319 static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd,
1320 					     struct dfs_event *radar)
1321 {
1322 	wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
1323 	hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled,
1324 				   radar->chan_offset, radar->chan_width,
1325 				   radar->cf1, radar->cf2);
1326 }
1327 
1328 
hostapd_event_dfs_pre_cac_expired(struct hostapd_data * hapd,struct dfs_event * radar)1329 static void hostapd_event_dfs_pre_cac_expired(struct hostapd_data *hapd,
1330 					      struct dfs_event *radar)
1331 {
1332 	wpa_printf(MSG_DEBUG, "DFS Pre-CAC expired on %d MHz", radar->freq);
1333 	hostapd_dfs_pre_cac_expired(hapd->iface, radar->freq, radar->ht_enabled,
1334 				    radar->chan_offset, radar->chan_width,
1335 				    radar->cf1, radar->cf2);
1336 }
1337 
1338 
hostapd_event_dfs_cac_finished(struct hostapd_data * hapd,struct dfs_event * radar)1339 static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd,
1340 					   struct dfs_event *radar)
1341 {
1342 	wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
1343 	hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled,
1344 				 radar->chan_offset, radar->chan_width,
1345 				 radar->cf1, radar->cf2);
1346 }
1347 
1348 
hostapd_event_dfs_cac_aborted(struct hostapd_data * hapd,struct dfs_event * radar)1349 static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd,
1350 					  struct dfs_event *radar)
1351 {
1352 	wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
1353 	hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled,
1354 				 radar->chan_offset, radar->chan_width,
1355 				 radar->cf1, radar->cf2);
1356 }
1357 
1358 
hostapd_event_dfs_nop_finished(struct hostapd_data * hapd,struct dfs_event * radar)1359 static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd,
1360 					   struct dfs_event *radar)
1361 {
1362 	wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
1363 	hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled,
1364 				 radar->chan_offset, radar->chan_width,
1365 				 radar->cf1, radar->cf2);
1366 }
1367 
1368 
hostapd_event_dfs_cac_started(struct hostapd_data * hapd,struct dfs_event * radar)1369 static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd,
1370 					  struct dfs_event *radar)
1371 {
1372 	wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq);
1373 	hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled,
1374 			      radar->chan_offset, radar->chan_width,
1375 			      radar->cf1, radar->cf2);
1376 }
1377 
1378 #endif /* NEED_AP_MLME */
1379 
1380 
wpa_supplicant_event(void * ctx,enum wpa_event_type event,union wpa_event_data * data)1381 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
1382 			  union wpa_event_data *data)
1383 {
1384 	struct hostapd_data *hapd = ctx;
1385 #ifndef CONFIG_NO_STDOUT_DEBUG
1386 	int level = MSG_DEBUG;
1387 
1388 	if (event == EVENT_RX_MGMT && data->rx_mgmt.frame &&
1389 	    data->rx_mgmt.frame_len >= 24) {
1390 		const struct ieee80211_hdr *hdr;
1391 		u16 fc;
1392 
1393 		hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
1394 		fc = le_to_host16(hdr->frame_control);
1395 		if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1396 		    WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1397 			level = MSG_EXCESSIVE;
1398 		if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1399 		    WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ)
1400 			level = MSG_EXCESSIVE;
1401 	}
1402 
1403 	wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received",
1404 		event_to_string(event), event);
1405 #endif /* CONFIG_NO_STDOUT_DEBUG */
1406 
1407 	switch (event) {
1408 	case EVENT_MICHAEL_MIC_FAILURE:
1409 		michael_mic_failure(hapd, data->michael_mic_failure.src, 1);
1410 		break;
1411 	case EVENT_SCAN_RESULTS:
1412 		if (hapd->iface->scan_cb)
1413 			hapd->iface->scan_cb(hapd->iface);
1414 		break;
1415 	case EVENT_WPS_BUTTON_PUSHED:
1416 		hostapd_wps_button_pushed(hapd, NULL);
1417 		break;
1418 #ifdef NEED_AP_MLME
1419 	case EVENT_TX_STATUS:
1420 		switch (data->tx_status.type) {
1421 		case WLAN_FC_TYPE_MGMT:
1422 			hostapd_mgmt_tx_cb(hapd, data->tx_status.data,
1423 					   data->tx_status.data_len,
1424 					   data->tx_status.stype,
1425 					   data->tx_status.ack);
1426 			break;
1427 		case WLAN_FC_TYPE_DATA:
1428 			hostapd_tx_status(hapd, data->tx_status.dst,
1429 					  data->tx_status.data,
1430 					  data->tx_status.data_len,
1431 					  data->tx_status.ack);
1432 			break;
1433 		}
1434 		break;
1435 	case EVENT_EAPOL_TX_STATUS:
1436 		hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst,
1437 					data->eapol_tx_status.data,
1438 					data->eapol_tx_status.data_len,
1439 					data->eapol_tx_status.ack);
1440 		break;
1441 	case EVENT_DRIVER_CLIENT_POLL_OK:
1442 		hostapd_client_poll_ok(hapd, data->client_poll.addr);
1443 		break;
1444 	case EVENT_RX_FROM_UNKNOWN:
1445 		hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid,
1446 					    data->rx_from_unknown.addr,
1447 					    data->rx_from_unknown.wds);
1448 		break;
1449 #endif /* NEED_AP_MLME */
1450 	case EVENT_RX_MGMT:
1451 		if (!data->rx_mgmt.frame)
1452 			break;
1453 #ifdef NEED_AP_MLME
1454 		if (hostapd_mgmt_rx(hapd, &data->rx_mgmt) > 0)
1455 			break;
1456 #endif /* NEED_AP_MLME */
1457 		hostapd_action_rx(hapd, &data->rx_mgmt);
1458 		break;
1459 	case EVENT_RX_PROBE_REQ:
1460 		if (data->rx_probe_req.sa == NULL ||
1461 		    data->rx_probe_req.ie == NULL)
1462 			break;
1463 		hostapd_probe_req_rx(hapd, data->rx_probe_req.sa,
1464 				     data->rx_probe_req.da,
1465 				     data->rx_probe_req.bssid,
1466 				     data->rx_probe_req.ie,
1467 				     data->rx_probe_req.ie_len,
1468 				     data->rx_probe_req.ssi_signal);
1469 		break;
1470 	case EVENT_NEW_STA:
1471 		hostapd_event_new_sta(hapd, data->new_sta.addr);
1472 		break;
1473 	case EVENT_EAPOL_RX:
1474 		hostapd_event_eapol_rx(hapd, data->eapol_rx.src,
1475 				       data->eapol_rx.data,
1476 				       data->eapol_rx.data_len);
1477 		break;
1478 	case EVENT_ASSOC:
1479 		if (!data)
1480 			return;
1481 		hostapd_notif_assoc(hapd, data->assoc_info.addr,
1482 				    data->assoc_info.req_ies,
1483 				    data->assoc_info.req_ies_len,
1484 				    data->assoc_info.reassoc);
1485 		break;
1486 	case EVENT_DISASSOC:
1487 		if (data)
1488 			hostapd_notif_disassoc(hapd, data->disassoc_info.addr);
1489 		break;
1490 	case EVENT_DEAUTH:
1491 		if (data)
1492 			hostapd_notif_disassoc(hapd, data->deauth_info.addr);
1493 		break;
1494 	case EVENT_STATION_LOW_ACK:
1495 		if (!data)
1496 			break;
1497 		hostapd_event_sta_low_ack(hapd, data->low_ack.addr);
1498 		break;
1499 	case EVENT_AUTH:
1500 		hostapd_notif_auth(hapd, &data->auth);
1501 		break;
1502 	case EVENT_CH_SWITCH:
1503 		if (!data)
1504 			break;
1505 		hostapd_event_ch_switch(hapd, data->ch_switch.freq,
1506 					data->ch_switch.ht_enabled,
1507 					data->ch_switch.ch_offset,
1508 					data->ch_switch.ch_width,
1509 					data->ch_switch.cf1,
1510 					data->ch_switch.cf2);
1511 		break;
1512 	case EVENT_CONNECT_FAILED_REASON:
1513 		if (!data)
1514 			break;
1515 		hostapd_event_connect_failed_reason(
1516 			hapd, data->connect_failed_reason.addr,
1517 			data->connect_failed_reason.code);
1518 		break;
1519 	case EVENT_SURVEY:
1520 		hostapd_event_get_survey(hapd->iface, &data->survey_results);
1521 		break;
1522 #ifdef NEED_AP_MLME
1523 	case EVENT_INTERFACE_UNAVAILABLE:
1524 		hostapd_event_iface_unavailable(hapd);
1525 		break;
1526 	case EVENT_DFS_RADAR_DETECTED:
1527 		if (!data)
1528 			break;
1529 		hostapd_event_dfs_radar_detected(hapd, &data->dfs_event);
1530 		break;
1531 	case EVENT_DFS_PRE_CAC_EXPIRED:
1532 		if (!data)
1533 			break;
1534 		hostapd_event_dfs_pre_cac_expired(hapd, &data->dfs_event);
1535 		break;
1536 	case EVENT_DFS_CAC_FINISHED:
1537 		if (!data)
1538 			break;
1539 		hostapd_event_dfs_cac_finished(hapd, &data->dfs_event);
1540 		break;
1541 	case EVENT_DFS_CAC_ABORTED:
1542 		if (!data)
1543 			break;
1544 		hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event);
1545 		break;
1546 	case EVENT_DFS_NOP_FINISHED:
1547 		if (!data)
1548 			break;
1549 		hostapd_event_dfs_nop_finished(hapd, &data->dfs_event);
1550 		break;
1551 	case EVENT_CHANNEL_LIST_CHANGED:
1552 		/* channel list changed (regulatory?), update channel list */
1553 		/* TODO: check this. hostapd_get_hw_features() initializes
1554 		 * too much stuff. */
1555 		/* hostapd_get_hw_features(hapd->iface); */
1556 		hostapd_channel_list_updated(
1557 			hapd->iface, data->channel_list_changed.initiator);
1558 		break;
1559 	case EVENT_DFS_CAC_STARTED:
1560 		if (!data)
1561 			break;
1562 		hostapd_event_dfs_cac_started(hapd, &data->dfs_event);
1563 		break;
1564 #endif /* NEED_AP_MLME */
1565 	case EVENT_INTERFACE_ENABLED:
1566 		wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED);
1567 		if (hapd->disabled && hapd->started) {
1568 			hapd->disabled = 0;
1569 			/*
1570 			 * Try to re-enable interface if the driver stopped it
1571 			 * when the interface got disabled.
1572 			 */
1573 			wpa_auth_reconfig_group_keys(hapd->wpa_auth);
1574 			hapd->reenable_beacon = 1;
1575 			ieee802_11_set_beacon(hapd);
1576 		}
1577 		break;
1578 	case EVENT_INTERFACE_DISABLED:
1579 		hostapd_free_stas(hapd);
1580 		wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED);
1581 		hapd->disabled = 1;
1582 		break;
1583 #ifdef CONFIG_ACS
1584 	case EVENT_ACS_CHANNEL_SELECTED:
1585 		hostapd_acs_channel_selected(hapd,
1586 					     &data->acs_selected_channels);
1587 		break;
1588 #endif /* CONFIG_ACS */
1589 	default:
1590 		wpa_printf(MSG_DEBUG, "Unknown event %d", event);
1591 		break;
1592 	}
1593 }
1594 
1595 
wpa_supplicant_event_global(void * ctx,enum wpa_event_type event,union wpa_event_data * data)1596 void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
1597 				 union wpa_event_data *data)
1598 {
1599 	struct hapd_interfaces *interfaces = ctx;
1600 	struct hostapd_data *hapd;
1601 
1602 	if (event != EVENT_INTERFACE_STATUS)
1603 		return;
1604 
1605 	hapd = hostapd_get_iface(interfaces, data->interface_status.ifname);
1606 	if (hapd && hapd->driver && hapd->driver->get_ifindex &&
1607 	    hapd->drv_priv) {
1608 		unsigned int ifindex;
1609 
1610 		ifindex = hapd->driver->get_ifindex(hapd->drv_priv);
1611 		if (ifindex != data->interface_status.ifindex) {
1612 			wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1613 				"interface status ifindex %d mismatch (%d)",
1614 				ifindex, data->interface_status.ifindex);
1615 			return;
1616 		}
1617 	}
1618 	if (hapd)
1619 		wpa_supplicant_event(hapd, event, data);
1620 }
1621 
1622 #endif /* HOSTAPD */
1623