xref: /freebsd/contrib/wpa/wpa_supplicant/events.c (revision a90b9d0159070121c221b966469c3e36d912bf82)
139beb93cSSam Leffler /*
239beb93cSSam Leffler  * WPA Supplicant - Driver event processing
34bc52338SCy Schubert  * Copyright (c) 2003-2019, Jouni Malinen <j@w1.fi>
439beb93cSSam Leffler  *
5f05cddf9SRui Paulo  * This software may be distributed under the terms of the BSD license.
6f05cddf9SRui Paulo  * See README for more details.
739beb93cSSam Leffler  */
839beb93cSSam Leffler 
939beb93cSSam Leffler #include "includes.h"
1039beb93cSSam Leffler 
1139beb93cSSam Leffler #include "common.h"
1239beb93cSSam Leffler #include "eapol_supp/eapol_supp_sm.h"
13e28a4053SRui Paulo #include "rsn_supp/wpa.h"
1439beb93cSSam Leffler #include "eloop.h"
1539beb93cSSam Leffler #include "config.h"
1639beb93cSSam Leffler #include "l2_packet/l2_packet.h"
1739beb93cSSam Leffler #include "wpa_supplicant_i.h"
18e28a4053SRui Paulo #include "driver_i.h"
1939beb93cSSam Leffler #include "pcsc_funcs.h"
20e28a4053SRui Paulo #include "rsn_supp/preauth.h"
21e28a4053SRui Paulo #include "rsn_supp/pmksa_cache.h"
22e28a4053SRui Paulo #include "common/wpa_ctrl.h"
2339beb93cSSam Leffler #include "eap_peer/eap.h"
24e28a4053SRui Paulo #include "ap/hostapd.h"
25*a90b9d01SCy Schubert #include "ap/sta_info.h"
26f05cddf9SRui Paulo #include "p2p/p2p.h"
27325151a3SRui Paulo #include "fst/fst.h"
28f05cddf9SRui Paulo #include "wnm_sta.h"
29e28a4053SRui Paulo #include "notify.h"
30e28a4053SRui Paulo #include "common/ieee802_11_defs.h"
31f05cddf9SRui Paulo #include "common/ieee802_11_common.h"
3285732ac8SCy Schubert #include "common/gas_server.h"
334bc52338SCy Schubert #include "common/dpp.h"
34c1d255d3SCy Schubert #include "common/ptksa_cache.h"
35f05cddf9SRui Paulo #include "crypto/random.h"
36c1d255d3SCy Schubert #include "bssid_ignore.h"
3739beb93cSSam Leffler #include "wpas_glue.h"
3839beb93cSSam Leffler #include "wps_supplicant.h"
39e28a4053SRui Paulo #include "ibss_rsn.h"
40e28a4053SRui Paulo #include "sme.h"
41f05cddf9SRui Paulo #include "gas_query.h"
42f05cddf9SRui Paulo #include "p2p_supplicant.h"
43e28a4053SRui Paulo #include "bgscan.h"
44f05cddf9SRui Paulo #include "autoscan.h"
45e28a4053SRui Paulo #include "ap.h"
46e28a4053SRui Paulo #include "bss.h"
47e28a4053SRui Paulo #include "scan.h"
48f05cddf9SRui Paulo #include "offchannel.h"
49f05cddf9SRui Paulo #include "interworking.h"
505b9c547cSRui Paulo #include "mesh.h"
515b9c547cSRui Paulo #include "mesh_mpm.h"
525b9c547cSRui Paulo #include "wmm_ac.h"
53*a90b9d01SCy Schubert #include "nan_usd.h"
5485732ac8SCy Schubert #include "dpp_supplicant.h"
5585732ac8SCy Schubert 
5685732ac8SCy Schubert 
5785732ac8SCy Schubert #define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5
585b9c547cSRui Paulo 
595b9c547cSRui Paulo 
605b9c547cSRui Paulo #ifndef CONFIG_NO_SCAN_PROCESSING
615b9c547cSRui Paulo static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
62*a90b9d01SCy Schubert 					      int new_scan, int own_request,
63*a90b9d01SCy Schubert 					      bool trigger_6ghz_scan,
64*a90b9d01SCy Schubert 					      union wpa_event_data *data);
655b9c547cSRui Paulo #endif /* CONFIG_NO_SCAN_PROCESSING */
66f05cddf9SRui Paulo 
67f05cddf9SRui Paulo 
wpas_temp_disabled(struct wpa_supplicant * wpa_s,struct wpa_ssid * ssid)6885732ac8SCy Schubert int wpas_temp_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
69f05cddf9SRui Paulo {
705b9c547cSRui Paulo 	struct os_reltime now;
71f05cddf9SRui Paulo 
72f05cddf9SRui Paulo 	if (ssid == NULL || ssid->disabled_until.sec == 0)
73f05cddf9SRui Paulo 		return 0;
74f05cddf9SRui Paulo 
755b9c547cSRui Paulo 	os_get_reltime(&now);
76f05cddf9SRui Paulo 	if (ssid->disabled_until.sec > now.sec)
77f05cddf9SRui Paulo 		return ssid->disabled_until.sec - now.sec;
78f05cddf9SRui Paulo 
79f05cddf9SRui Paulo 	wpas_clear_temp_disabled(wpa_s, ssid, 0);
80f05cddf9SRui Paulo 
81f05cddf9SRui Paulo 	return 0;
82f05cddf9SRui Paulo }
8339beb93cSSam Leffler 
8439beb93cSSam Leffler 
85780fb4a2SCy Schubert #ifndef CONFIG_NO_SCAN_PROCESSING
86325151a3SRui Paulo /**
87325151a3SRui Paulo  * wpas_reenabled_network_time - Time until first network is re-enabled
88325151a3SRui Paulo  * @wpa_s: Pointer to wpa_supplicant data
89325151a3SRui Paulo  * Returns: If all enabled networks are temporarily disabled, returns the time
90325151a3SRui Paulo  *	(in sec) until the first network is re-enabled. Otherwise returns 0.
91325151a3SRui Paulo  *
92325151a3SRui Paulo  * This function is used in case all enabled networks are temporarily disabled,
93325151a3SRui Paulo  * in which case it returns the time (in sec) that the first network will be
94325151a3SRui Paulo  * re-enabled. The function assumes that at least one network is enabled.
95325151a3SRui Paulo  */
wpas_reenabled_network_time(struct wpa_supplicant * wpa_s)96325151a3SRui Paulo static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
97325151a3SRui Paulo {
98325151a3SRui Paulo 	struct wpa_ssid *ssid;
99325151a3SRui Paulo 	int disabled_for, res = 0;
100325151a3SRui Paulo 
101325151a3SRui Paulo #ifdef CONFIG_INTERWORKING
102325151a3SRui Paulo 	if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
103325151a3SRui Paulo 	    wpa_s->conf->cred)
104325151a3SRui Paulo 		return 0;
105325151a3SRui Paulo #endif /* CONFIG_INTERWORKING */
106325151a3SRui Paulo 
107325151a3SRui Paulo 	for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
108325151a3SRui Paulo 		if (ssid->disabled)
109325151a3SRui Paulo 			continue;
110325151a3SRui Paulo 
111325151a3SRui Paulo 		disabled_for = wpas_temp_disabled(wpa_s, ssid);
112325151a3SRui Paulo 		if (!disabled_for)
113325151a3SRui Paulo 			return 0;
114325151a3SRui Paulo 
115325151a3SRui Paulo 		if (!res || disabled_for < res)
116325151a3SRui Paulo 			res = disabled_for;
117325151a3SRui Paulo 	}
118325151a3SRui Paulo 
119325151a3SRui Paulo 	return res;
120325151a3SRui Paulo }
121780fb4a2SCy Schubert #endif /* CONFIG_NO_SCAN_PROCESSING */
122325151a3SRui Paulo 
123325151a3SRui Paulo 
wpas_network_reenabled(void * eloop_ctx,void * timeout_ctx)124325151a3SRui Paulo void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
125325151a3SRui Paulo {
126325151a3SRui Paulo 	struct wpa_supplicant *wpa_s = eloop_ctx;
127325151a3SRui Paulo 
128325151a3SRui Paulo 	if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
129325151a3SRui Paulo 		return;
130325151a3SRui Paulo 
131325151a3SRui Paulo 	wpa_dbg(wpa_s, MSG_DEBUG,
132325151a3SRui Paulo 		"Try to associate due to network getting re-enabled");
133325151a3SRui Paulo 	if (wpa_supplicant_fast_associate(wpa_s) != 1) {
134325151a3SRui Paulo 		wpa_supplicant_cancel_sched_scan(wpa_s);
135325151a3SRui Paulo 		wpa_supplicant_req_scan(wpa_s, 0, 0);
136325151a3SRui Paulo 	}
137325151a3SRui Paulo }
138325151a3SRui Paulo 
139325151a3SRui Paulo 
__wpa_supplicant_get_new_bss(struct wpa_supplicant * wpa_s,const u8 * bssid,const u8 * ssid,size_t ssid_len)140*a90b9d01SCy Schubert static struct wpa_bss * __wpa_supplicant_get_new_bss(
141*a90b9d01SCy Schubert 	struct wpa_supplicant *wpa_s, const u8 *bssid, const u8 *ssid,
142*a90b9d01SCy Schubert 	size_t ssid_len)
143*a90b9d01SCy Schubert {
144*a90b9d01SCy Schubert 	if (ssid && ssid_len > 0)
145*a90b9d01SCy Schubert 		return wpa_bss_get(wpa_s, bssid, ssid, ssid_len);
146*a90b9d01SCy Schubert 	else
147*a90b9d01SCy Schubert 		return wpa_bss_get_bssid(wpa_s, bssid);
148*a90b9d01SCy Schubert }
149*a90b9d01SCy Schubert 
150*a90b9d01SCy Schubert 
_wpa_supplicant_get_new_bss(struct wpa_supplicant * wpa_s,const u8 * bssid,const u8 * ssid,size_t ssid_len,bool try_update_scan_results)151*a90b9d01SCy Schubert static struct wpa_bss * _wpa_supplicant_get_new_bss(
152*a90b9d01SCy Schubert 	struct wpa_supplicant *wpa_s, const u8 *bssid, const u8 *ssid,
153*a90b9d01SCy Schubert 	size_t ssid_len, bool try_update_scan_results)
154*a90b9d01SCy Schubert {
155*a90b9d01SCy Schubert 	struct wpa_bss *bss = __wpa_supplicant_get_new_bss(wpa_s, bssid, ssid,
156*a90b9d01SCy Schubert 							   ssid_len);
157*a90b9d01SCy Schubert 
158*a90b9d01SCy Schubert 	if (bss || !try_update_scan_results)
159*a90b9d01SCy Schubert 		return bss;
160*a90b9d01SCy Schubert 
161*a90b9d01SCy Schubert 	wpa_supplicant_update_scan_results(wpa_s, bssid);
162*a90b9d01SCy Schubert 
163*a90b9d01SCy Schubert 	return __wpa_supplicant_get_new_bss(wpa_s, bssid, ssid, ssid_len);
164*a90b9d01SCy Schubert }
165*a90b9d01SCy Schubert 
166*a90b9d01SCy Schubert 
wpa_supplicant_get_new_bss(struct wpa_supplicant * wpa_s,const u8 * bssid)1675b9c547cSRui Paulo static struct wpa_bss * wpa_supplicant_get_new_bss(
1685b9c547cSRui Paulo 	struct wpa_supplicant *wpa_s, const u8 *bssid)
1695b9c547cSRui Paulo {
1705b9c547cSRui Paulo 	struct wpa_bss *bss = NULL;
1715b9c547cSRui Paulo 	struct wpa_ssid *ssid = wpa_s->current_ssid;
172*a90b9d01SCy Schubert 	u8 drv_ssid[SSID_MAX_LEN];
173*a90b9d01SCy Schubert 	int res;
174*a90b9d01SCy Schubert 	bool try_update_scan_results = true;
1755b9c547cSRui Paulo 
176*a90b9d01SCy Schubert 	res = wpa_drv_get_ssid(wpa_s, drv_ssid);
177*a90b9d01SCy Schubert 	if (res > 0) {
178*a90b9d01SCy Schubert 		bss = _wpa_supplicant_get_new_bss(wpa_s, bssid, drv_ssid, res,
179*a90b9d01SCy Schubert 						  try_update_scan_results);
180*a90b9d01SCy Schubert 		try_update_scan_results = false;
181*a90b9d01SCy Schubert 	}
182*a90b9d01SCy Schubert 	if (!bss && ssid && ssid->ssid_len > 0) {
183*a90b9d01SCy Schubert 		bss = _wpa_supplicant_get_new_bss(wpa_s, bssid, ssid->ssid,
184*a90b9d01SCy Schubert 						  ssid->ssid_len,
185*a90b9d01SCy Schubert 						  try_update_scan_results);
186*a90b9d01SCy Schubert 		try_update_scan_results = false;
187*a90b9d01SCy Schubert 	}
1885b9c547cSRui Paulo 	if (!bss)
189*a90b9d01SCy Schubert 		bss = _wpa_supplicant_get_new_bss(wpa_s, bssid, NULL, 0,
190*a90b9d01SCy Schubert 						  try_update_scan_results);
1915b9c547cSRui Paulo 
1925b9c547cSRui Paulo 	return bss;
1935b9c547cSRui Paulo }
1945b9c547cSRui Paulo 
1955b9c547cSRui Paulo 
196*a90b9d01SCy Schubert static struct wpa_bss *
wpa_supplicant_update_current_bss(struct wpa_supplicant * wpa_s,const u8 * bssid)197*a90b9d01SCy Schubert wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s, const u8 *bssid)
1985b9c547cSRui Paulo {
199*a90b9d01SCy Schubert 	struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
2005b9c547cSRui Paulo 
2015b9c547cSRui Paulo 	if (bss)
2025b9c547cSRui Paulo 		wpa_s->current_bss = bss;
203*a90b9d01SCy Schubert 
204*a90b9d01SCy Schubert 	return bss;
2055b9c547cSRui Paulo }
2065b9c547cSRui Paulo 
2075b9c547cSRui Paulo 
wpa_supplicant_update_link_bss(struct wpa_supplicant * wpa_s,u8 link_id,const u8 * bssid)208*a90b9d01SCy Schubert static void wpa_supplicant_update_link_bss(struct wpa_supplicant *wpa_s,
209*a90b9d01SCy Schubert 					   u8 link_id, const u8 *bssid)
210*a90b9d01SCy Schubert {
211*a90b9d01SCy Schubert 	struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
212*a90b9d01SCy Schubert 
213*a90b9d01SCy Schubert 	if (bss)
214*a90b9d01SCy Schubert 		wpa_s->links[link_id].bss = bss;
215*a90b9d01SCy Schubert }
216*a90b9d01SCy Schubert 
217*a90b9d01SCy Schubert 
wpa_supplicant_select_config(struct wpa_supplicant * wpa_s,union wpa_event_data * data)218*a90b9d01SCy Schubert static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s,
219*a90b9d01SCy Schubert 					union wpa_event_data *data)
22039beb93cSSam Leffler {
221e28a4053SRui Paulo 	struct wpa_ssid *ssid, *old_ssid;
222*a90b9d01SCy Schubert 	struct wpa_bss *bss;
223325151a3SRui Paulo 	u8 drv_ssid[SSID_MAX_LEN];
224325151a3SRui Paulo 	size_t drv_ssid_len;
225f05cddf9SRui Paulo 	int res;
22639beb93cSSam Leffler 
2275b9c547cSRui Paulo 	if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
228*a90b9d01SCy Schubert 		wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
229325151a3SRui Paulo 
230325151a3SRui Paulo 		if (wpa_s->current_ssid->ssid_len == 0)
231325151a3SRui Paulo 			return 0; /* current profile still in use */
232325151a3SRui Paulo 		res = wpa_drv_get_ssid(wpa_s, drv_ssid);
233325151a3SRui Paulo 		if (res < 0) {
234325151a3SRui Paulo 			wpa_msg(wpa_s, MSG_INFO,
235325151a3SRui Paulo 				"Failed to read SSID from driver");
236325151a3SRui Paulo 			return 0; /* try to use current profile */
237325151a3SRui Paulo 		}
238325151a3SRui Paulo 		drv_ssid_len = res;
239325151a3SRui Paulo 
240325151a3SRui Paulo 		if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
241325151a3SRui Paulo 		    os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
242325151a3SRui Paulo 			      drv_ssid_len) == 0)
243325151a3SRui Paulo 			return 0; /* current profile still in use */
244325151a3SRui Paulo 
245c1d255d3SCy Schubert #ifdef CONFIG_OWE
246c1d255d3SCy Schubert 		if ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
247c1d255d3SCy Schubert 		    wpa_s->current_bss &&
248c1d255d3SCy Schubert 		    (wpa_s->current_bss->flags & WPA_BSS_OWE_TRANSITION) &&
249c1d255d3SCy Schubert 		    drv_ssid_len == wpa_s->current_bss->ssid_len &&
250c1d255d3SCy Schubert 		    os_memcmp(drv_ssid, wpa_s->current_bss->ssid,
251c1d255d3SCy Schubert 			      drv_ssid_len) == 0)
252c1d255d3SCy Schubert 			return 0; /* current profile still in use */
253c1d255d3SCy Schubert #endif /* CONFIG_OWE */
254c1d255d3SCy Schubert 
255325151a3SRui Paulo 		wpa_msg(wpa_s, MSG_DEBUG,
256325151a3SRui Paulo 			"Driver-initiated BSS selection changed the SSID to %s",
257325151a3SRui Paulo 			wpa_ssid_txt(drv_ssid, drv_ssid_len));
258325151a3SRui Paulo 		/* continue selecting a new network profile */
2595b9c547cSRui Paulo 	}
26039beb93cSSam Leffler 
261f05cddf9SRui Paulo 	wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
26239beb93cSSam Leffler 		"information");
26339beb93cSSam Leffler 	ssid = wpa_supplicant_get_ssid(wpa_s);
26439beb93cSSam Leffler 	if (ssid == NULL) {
265f05cddf9SRui Paulo 		wpa_msg(wpa_s, MSG_INFO,
266f05cddf9SRui Paulo 			"No network configuration found for the current AP");
267f05cddf9SRui Paulo 		return -1;
268f05cddf9SRui Paulo 	}
269f05cddf9SRui Paulo 
270f05cddf9SRui Paulo 	if (wpas_network_disabled(wpa_s, ssid)) {
271f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
272f05cddf9SRui Paulo 		return -1;
273f05cddf9SRui Paulo 	}
274f05cddf9SRui Paulo 
275f05cddf9SRui Paulo 	if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
276f05cddf9SRui Paulo 	    disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
277f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
278f05cddf9SRui Paulo 		return -1;
279f05cddf9SRui Paulo 	}
280f05cddf9SRui Paulo 
281f05cddf9SRui Paulo 	res = wpas_temp_disabled(wpa_s, ssid);
282f05cddf9SRui Paulo 	if (res > 0) {
283f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
284f05cddf9SRui Paulo 			"disabled for %d second(s)", res);
285f05cddf9SRui Paulo 		return -1;
286f05cddf9SRui Paulo 	}
287f05cddf9SRui Paulo 
288f05cddf9SRui Paulo 	wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
28939beb93cSSam Leffler 		"current AP");
290*a90b9d01SCy Schubert 	bss = wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
291f05cddf9SRui Paulo 	if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
29239beb93cSSam Leffler 		u8 wpa_ie[80];
29339beb93cSSam Leffler 		size_t wpa_ie_len = sizeof(wpa_ie);
294*a90b9d01SCy Schubert 		bool skip_default_rsne;
295*a90b9d01SCy Schubert 
296*a90b9d01SCy Schubert 		/* Do not override RSNE/RSNXE with the default values if the
297*a90b9d01SCy Schubert 		 * driver indicated the actual values used in the
298*a90b9d01SCy Schubert 		 * (Re)Association Request frame. */
299*a90b9d01SCy Schubert 		skip_default_rsne = data && data->assoc_info.req_ies;
300*a90b9d01SCy Schubert 		if (wpa_supplicant_set_suites(wpa_s, bss, ssid,
301*a90b9d01SCy Schubert 					      wpa_ie, &wpa_ie_len,
302*a90b9d01SCy Schubert 					      skip_default_rsne) < 0)
3035b9c547cSRui Paulo 			wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
30439beb93cSSam Leffler 	} else {
30539beb93cSSam Leffler 		wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
30639beb93cSSam Leffler 	}
30739beb93cSSam Leffler 
30839beb93cSSam Leffler 	if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
30939beb93cSSam Leffler 		eapol_sm_invalidate_cached_session(wpa_s->eapol);
310e28a4053SRui Paulo 	old_ssid = wpa_s->current_ssid;
31139beb93cSSam Leffler 	wpa_s->current_ssid = ssid;
3125b9c547cSRui Paulo 
31339beb93cSSam Leffler 	wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
31439beb93cSSam Leffler 	wpa_supplicant_initiate_eapol(wpa_s);
315e28a4053SRui Paulo 	if (old_ssid != wpa_s->current_ssid)
316e28a4053SRui Paulo 		wpas_notify_network_changed(wpa_s);
31739beb93cSSam Leffler 
31839beb93cSSam Leffler 	return 0;
31939beb93cSSam Leffler }
32039beb93cSSam Leffler 
32139beb93cSSam Leffler 
wpa_supplicant_stop_countermeasures(void * eloop_ctx,void * sock_ctx)322f05cddf9SRui Paulo void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
32339beb93cSSam Leffler {
32439beb93cSSam Leffler 	struct wpa_supplicant *wpa_s = eloop_ctx;
32539beb93cSSam Leffler 
32639beb93cSSam Leffler 	if (wpa_s->countermeasures) {
32739beb93cSSam Leffler 		wpa_s->countermeasures = 0;
32839beb93cSSam Leffler 		wpa_drv_set_countermeasures(wpa_s, 0);
32939beb93cSSam Leffler 		wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
3305b9c547cSRui Paulo 
3315b9c547cSRui Paulo 		/*
3325b9c547cSRui Paulo 		 * It is possible that the device is sched scanning, which means
3335b9c547cSRui Paulo 		 * that a connection attempt will be done only when we receive
3345b9c547cSRui Paulo 		 * scan results. However, in this case, it would be preferable
3355b9c547cSRui Paulo 		 * to scan and connect immediately, so cancel the sched_scan and
3365b9c547cSRui Paulo 		 * issue a regular scan flow.
3375b9c547cSRui Paulo 		 */
3385b9c547cSRui Paulo 		wpa_supplicant_cancel_sched_scan(wpa_s);
33939beb93cSSam Leffler 		wpa_supplicant_req_scan(wpa_s, 0, 0);
34039beb93cSSam Leffler 	}
34139beb93cSSam Leffler }
34239beb93cSSam Leffler 
34339beb93cSSam Leffler 
wpas_reset_mlo_info(struct wpa_supplicant * wpa_s)344*a90b9d01SCy Schubert void wpas_reset_mlo_info(struct wpa_supplicant *wpa_s)
345*a90b9d01SCy Schubert {
346*a90b9d01SCy Schubert 	if (!wpa_s->valid_links)
347*a90b9d01SCy Schubert 		return;
348*a90b9d01SCy Schubert 
349*a90b9d01SCy Schubert 	wpa_s->valid_links = 0;
350*a90b9d01SCy Schubert 	wpa_s->mlo_assoc_link_id = 0;
351*a90b9d01SCy Schubert 	os_memset(wpa_s->ap_mld_addr, 0, ETH_ALEN);
352*a90b9d01SCy Schubert 	os_memset(wpa_s->links, 0, sizeof(wpa_s->links));
353*a90b9d01SCy Schubert }
354*a90b9d01SCy Schubert 
355*a90b9d01SCy Schubert 
wpa_supplicant_mark_disassoc(struct wpa_supplicant * wpa_s)35639beb93cSSam Leffler void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
35739beb93cSSam Leffler {
358e28a4053SRui Paulo 	int bssid_changed;
359e28a4053SRui Paulo 
360f05cddf9SRui Paulo 	wnm_bss_keep_alive_deinit(wpa_s);
361f05cddf9SRui Paulo 
362f05cddf9SRui Paulo #ifdef CONFIG_IBSS_RSN
363f05cddf9SRui Paulo 	ibss_rsn_deinit(wpa_s->ibss_rsn);
364f05cddf9SRui Paulo 	wpa_s->ibss_rsn = NULL;
365f05cddf9SRui Paulo #endif /* CONFIG_IBSS_RSN */
366f05cddf9SRui Paulo 
367f05cddf9SRui Paulo #ifdef CONFIG_AP
368f05cddf9SRui Paulo 	wpa_supplicant_ap_deinit(wpa_s);
369f05cddf9SRui Paulo #endif /* CONFIG_AP */
370f05cddf9SRui Paulo 
371780fb4a2SCy Schubert #ifdef CONFIG_HS20
372780fb4a2SCy Schubert 	/* Clear possibly configured frame filters */
373780fb4a2SCy Schubert 	wpa_drv_configure_frame_filters(wpa_s, 0);
374780fb4a2SCy Schubert #endif /* CONFIG_HS20 */
375780fb4a2SCy Schubert 
376f05cddf9SRui Paulo 	if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
377f05cddf9SRui Paulo 		return;
378f05cddf9SRui Paulo 
3794bc52338SCy Schubert 	if (os_reltime_initialized(&wpa_s->session_start)) {
3804bc52338SCy Schubert 		os_reltime_age(&wpa_s->session_start, &wpa_s->session_length);
3814bc52338SCy Schubert 		wpa_s->session_start.sec = 0;
3824bc52338SCy Schubert 		wpa_s->session_start.usec = 0;
3834bc52338SCy Schubert 		wpas_notify_session_length(wpa_s);
3844bc52338SCy Schubert 	}
3854bc52338SCy Schubert 
38639beb93cSSam Leffler 	wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
387e28a4053SRui Paulo 	bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
38839beb93cSSam Leffler 	os_memset(wpa_s->bssid, 0, ETH_ALEN);
38939beb93cSSam Leffler 	os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
3905b9c547cSRui Paulo 	sme_clear_on_disassoc(wpa_s);
391e28a4053SRui Paulo 	wpa_s->current_bss = NULL;
392f05cddf9SRui Paulo 	wpa_s->assoc_freq = 0;
393f05cddf9SRui Paulo 
394e28a4053SRui Paulo 	if (bssid_changed)
395e28a4053SRui Paulo 		wpas_notify_bssid_changed(wpa_s);
396e28a4053SRui Paulo 
397c1d255d3SCy Schubert 	eapol_sm_notify_portEnabled(wpa_s->eapol, false);
398c1d255d3SCy Schubert 	eapol_sm_notify_portValid(wpa_s->eapol, false);
39985732ac8SCy Schubert 	if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
40085732ac8SCy Schubert 	    wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
401c1d255d3SCy Schubert 	    wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || wpa_s->drv_authorized_port)
402c1d255d3SCy Schubert 		eapol_sm_notify_eap_success(wpa_s->eapol, false);
403c1d255d3SCy Schubert 	wpa_s->drv_authorized_port = 0;
40439beb93cSSam Leffler 	wpa_s->ap_ies_from_associnfo = 0;
405f05cddf9SRui Paulo 	wpa_s->current_ssid = NULL;
4065b9c547cSRui Paulo 	eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
407f05cddf9SRui Paulo 	wpa_s->key_mgmt = 0;
408*a90b9d01SCy Schubert 	wpa_s->allowed_key_mgmts = 0;
4095b9c547cSRui Paulo 
410*a90b9d01SCy Schubert #ifndef CONFIG_NO_RRM
4115b9c547cSRui Paulo 	wpas_rrm_reset(wpa_s);
412*a90b9d01SCy Schubert #endif /* CONFIG_NO_RRM */
413a2063804SGordon Tetlow 	wpa_s->wnmsleep_used = 0;
414*a90b9d01SCy Schubert #ifdef CONFIG_WNM
415*a90b9d01SCy Schubert 	wpa_s->wnm_mode = 0;
416*a90b9d01SCy Schubert #endif /* CONFIG_WNM */
41785732ac8SCy Schubert 	wnm_clear_coloc_intf_reporting(wpa_s);
418c1d255d3SCy Schubert 	wpa_s->disable_mbo_oce = 0;
41985732ac8SCy Schubert 
42085732ac8SCy Schubert #ifdef CONFIG_TESTING_OPTIONS
42185732ac8SCy Schubert 	wpa_s->last_tk_alg = WPA_ALG_NONE;
42285732ac8SCy Schubert 	os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk));
42385732ac8SCy Schubert #endif /* CONFIG_TESTING_OPTIONS */
42485732ac8SCy Schubert 	wpa_s->ieee80211ac = 0;
4254bc52338SCy Schubert 
4264bc52338SCy Schubert 	if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
4274bc52338SCy Schubert 		wpa_s->enabled_4addr_mode = 0;
428*a90b9d01SCy Schubert 
429*a90b9d01SCy Schubert 	wpa_s->wps_scan_done = false;
430*a90b9d01SCy Schubert 	wpas_reset_mlo_info(wpa_s);
431*a90b9d01SCy Schubert 
432*a90b9d01SCy Schubert #ifdef CONFIG_SME
433*a90b9d01SCy Schubert 	wpa_s->sme.bss_max_idle_period = 0;
434*a90b9d01SCy Schubert #endif /* CONFIG_SME */
435*a90b9d01SCy Schubert 
436*a90b9d01SCy Schubert 	wpa_s->ssid_verified = false;
437*a90b9d01SCy Schubert 	wpa_s->bigtk_set = false;
43839beb93cSSam Leffler }
43939beb93cSSam Leffler 
44039beb93cSSam Leffler 
wpa_find_assoc_pmkid(struct wpa_supplicant * wpa_s,bool authorized)441*a90b9d01SCy Schubert static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s, bool authorized)
44239beb93cSSam Leffler {
44339beb93cSSam Leffler 	struct wpa_ie_data ie;
44439beb93cSSam Leffler 	int pmksa_set = -1;
44539beb93cSSam Leffler 	size_t i;
4464b72b91aSCy Schubert 	struct rsn_pmksa_cache_entry *cur_pmksa;
44739beb93cSSam Leffler 
4484b72b91aSCy Schubert 	/* Start with assumption of no PMKSA cache entry match for cases other
4494b72b91aSCy Schubert 	 * than SAE. In particular, this is needed to generate the PMKSA cache
4504b72b91aSCy Schubert 	 * entries for Suite B cases with driver-based roaming indication. */
4514b72b91aSCy Schubert 	cur_pmksa = pmksa_cache_get_current(wpa_s->wpa);
4524b72b91aSCy Schubert 	if (cur_pmksa && !wpa_key_mgmt_sae(cur_pmksa->akmp))
453c1d255d3SCy Schubert 		pmksa_cache_clear_current(wpa_s->wpa);
454c1d255d3SCy Schubert 
45539beb93cSSam Leffler 	if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
45639beb93cSSam Leffler 	    ie.pmkid == NULL)
45739beb93cSSam Leffler 		return;
45839beb93cSSam Leffler 
45939beb93cSSam Leffler 	for (i = 0; i < ie.num_pmkid; i++) {
46039beb93cSSam Leffler 		pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
46139beb93cSSam Leffler 						    ie.pmkid + i * PMKID_LEN,
462*a90b9d01SCy Schubert 						    NULL, NULL, 0, NULL, 0,
463*a90b9d01SCy Schubert 						    true);
46439beb93cSSam Leffler 		if (pmksa_set == 0) {
4655b9c547cSRui Paulo 			eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
466*a90b9d01SCy Schubert 			if (authorized)
467*a90b9d01SCy Schubert 				wpa_sm_set_pmk_from_pmksa(wpa_s->wpa);
46839beb93cSSam Leffler 			break;
46939beb93cSSam Leffler 		}
47039beb93cSSam Leffler 	}
47139beb93cSSam Leffler 
472f05cddf9SRui Paulo 	wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
473f05cddf9SRui Paulo 		"PMKSA cache", pmksa_set == 0 ? "" : "not ");
47439beb93cSSam Leffler }
47539beb93cSSam Leffler 
47639beb93cSSam Leffler 
wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant * wpa_s,union wpa_event_data * data)47739beb93cSSam Leffler static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
47839beb93cSSam Leffler 						 union wpa_event_data *data)
47939beb93cSSam Leffler {
48039beb93cSSam Leffler 	if (data == NULL) {
481f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
482f05cddf9SRui Paulo 			"event");
48339beb93cSSam Leffler 		return;
48439beb93cSSam Leffler 	}
485f05cddf9SRui Paulo 	wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
48639beb93cSSam Leffler 		" index=%d preauth=%d",
48739beb93cSSam Leffler 		MAC2STR(data->pmkid_candidate.bssid),
48839beb93cSSam Leffler 		data->pmkid_candidate.index,
48939beb93cSSam Leffler 		data->pmkid_candidate.preauth);
49039beb93cSSam Leffler 
49139beb93cSSam Leffler 	pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
49239beb93cSSam Leffler 			    data->pmkid_candidate.index,
49339beb93cSSam Leffler 			    data->pmkid_candidate.preauth);
49439beb93cSSam Leffler }
49539beb93cSSam Leffler 
49639beb93cSSam Leffler 
wpa_supplicant_dynamic_keys(struct wpa_supplicant * wpa_s)49739beb93cSSam Leffler static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
49839beb93cSSam Leffler {
49939beb93cSSam Leffler 	if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
50039beb93cSSam Leffler 	    wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
50139beb93cSSam Leffler 		return 0;
50239beb93cSSam Leffler 
50339beb93cSSam Leffler #ifdef IEEE8021X_EAPOL
50439beb93cSSam Leffler 	if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
50539beb93cSSam Leffler 	    wpa_s->current_ssid &&
50639beb93cSSam Leffler 	    !(wpa_s->current_ssid->eapol_flags &
50739beb93cSSam Leffler 	      (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
50839beb93cSSam Leffler 	       EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
50939beb93cSSam Leffler 		/* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
51039beb93cSSam Leffler 		 * plaintext or static WEP keys). */
51139beb93cSSam Leffler 		return 0;
51239beb93cSSam Leffler 	}
51339beb93cSSam Leffler #endif /* IEEE8021X_EAPOL */
51439beb93cSSam Leffler 
51539beb93cSSam Leffler 	return 1;
51639beb93cSSam Leffler }
51739beb93cSSam Leffler 
51839beb93cSSam Leffler 
51939beb93cSSam Leffler /**
52039beb93cSSam Leffler  * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
52139beb93cSSam Leffler  * @wpa_s: pointer to wpa_supplicant data
52239beb93cSSam Leffler  * @ssid: Configuration data for the network
52339beb93cSSam Leffler  * Returns: 0 on success, -1 on failure
52439beb93cSSam Leffler  *
52539beb93cSSam Leffler  * This function is called when starting authentication with a network that is
52639beb93cSSam Leffler  * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
52739beb93cSSam Leffler  */
wpa_supplicant_scard_init(struct wpa_supplicant * wpa_s,struct wpa_ssid * ssid)52839beb93cSSam Leffler int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
52939beb93cSSam Leffler 			      struct wpa_ssid *ssid)
53039beb93cSSam Leffler {
53139beb93cSSam Leffler #ifdef IEEE8021X_EAPOL
532f05cddf9SRui Paulo #ifdef PCSC_FUNCS
5335b9c547cSRui Paulo 	int aka = 0, sim = 0;
53439beb93cSSam Leffler 
5355b9c547cSRui Paulo 	if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
5365b9c547cSRui Paulo 	    wpa_s->scard != NULL || wpa_s->conf->external_sim)
53739beb93cSSam Leffler 		return 0;
53839beb93cSSam Leffler 
5395b9c547cSRui Paulo 	if (ssid == NULL || ssid->eap.eap_methods == NULL) {
54039beb93cSSam Leffler 		sim = 1;
54139beb93cSSam Leffler 		aka = 1;
54239beb93cSSam Leffler 	} else {
54339beb93cSSam Leffler 		struct eap_method_type *eap = ssid->eap.eap_methods;
54439beb93cSSam Leffler 		while (eap->vendor != EAP_VENDOR_IETF ||
54539beb93cSSam Leffler 		       eap->method != EAP_TYPE_NONE) {
54639beb93cSSam Leffler 			if (eap->vendor == EAP_VENDOR_IETF) {
54739beb93cSSam Leffler 				if (eap->method == EAP_TYPE_SIM)
54839beb93cSSam Leffler 					sim = 1;
549f05cddf9SRui Paulo 				else if (eap->method == EAP_TYPE_AKA ||
550f05cddf9SRui Paulo 					 eap->method == EAP_TYPE_AKA_PRIME)
55139beb93cSSam Leffler 					aka = 1;
55239beb93cSSam Leffler 			}
55339beb93cSSam Leffler 			eap++;
55439beb93cSSam Leffler 		}
55539beb93cSSam Leffler 	}
55639beb93cSSam Leffler 
55739beb93cSSam Leffler 	if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
55839beb93cSSam Leffler 		sim = 0;
559f05cddf9SRui Paulo 	if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
560f05cddf9SRui Paulo 	    eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
561f05cddf9SRui Paulo 	    NULL)
56239beb93cSSam Leffler 		aka = 0;
56339beb93cSSam Leffler 
56439beb93cSSam Leffler 	if (!sim && !aka) {
565f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
566f05cddf9SRui Paulo 			"use SIM, but neither EAP-SIM nor EAP-AKA are "
567f05cddf9SRui Paulo 			"enabled");
56839beb93cSSam Leffler 		return 0;
56939beb93cSSam Leffler 	}
57039beb93cSSam Leffler 
571f05cddf9SRui Paulo 	wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
57239beb93cSSam Leffler 		"(sim=%d aka=%d) - initialize PCSC", sim, aka);
57339beb93cSSam Leffler 
5745b9c547cSRui Paulo 	wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
57539beb93cSSam Leffler 	if (wpa_s->scard == NULL) {
576f05cddf9SRui Paulo 		wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
57739beb93cSSam Leffler 			"(pcsc-lite)");
57839beb93cSSam Leffler 		return -1;
57939beb93cSSam Leffler 	}
58039beb93cSSam Leffler 	wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
58139beb93cSSam Leffler 	eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
582f05cddf9SRui Paulo #endif /* PCSC_FUNCS */
58339beb93cSSam Leffler #endif /* IEEE8021X_EAPOL */
58439beb93cSSam Leffler 
58539beb93cSSam Leffler 	return 0;
58639beb93cSSam Leffler }
58739beb93cSSam Leffler 
58839beb93cSSam Leffler 
58939beb93cSSam Leffler #ifndef CONFIG_NO_SCAN_PROCESSING
5905b9c547cSRui Paulo 
591c1d255d3SCy Schubert #ifdef CONFIG_WEP
has_wep_key(struct wpa_ssid * ssid)5925b9c547cSRui Paulo static int has_wep_key(struct wpa_ssid *ssid)
5935b9c547cSRui Paulo {
5945b9c547cSRui Paulo 	int i;
5955b9c547cSRui Paulo 
5965b9c547cSRui Paulo 	for (i = 0; i < NUM_WEP_KEYS; i++) {
5975b9c547cSRui Paulo 		if (ssid->wep_key_len[i])
5985b9c547cSRui Paulo 			return 1;
5995b9c547cSRui Paulo 	}
6005b9c547cSRui Paulo 
6015b9c547cSRui Paulo 	return 0;
6025b9c547cSRui Paulo }
603c1d255d3SCy Schubert #endif /* CONFIG_WEP */
6045b9c547cSRui Paulo 
6055b9c547cSRui Paulo 
wpa_supplicant_match_privacy(struct wpa_bss * bss,struct wpa_ssid * ssid)606f05cddf9SRui Paulo static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
60739beb93cSSam Leffler 					struct wpa_ssid *ssid)
60839beb93cSSam Leffler {
6095b9c547cSRui Paulo 	int privacy = 0;
61039beb93cSSam Leffler 
61139beb93cSSam Leffler 	if (ssid->mixed_cell)
61239beb93cSSam Leffler 		return 1;
61339beb93cSSam Leffler 
6143157ba21SRui Paulo #ifdef CONFIG_WPS
6153157ba21SRui Paulo 	if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
6163157ba21SRui Paulo 		return 1;
6173157ba21SRui Paulo #endif /* CONFIG_WPS */
6183157ba21SRui Paulo 
61985732ac8SCy Schubert #ifdef CONFIG_OWE
62085732ac8SCy Schubert 	if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
62185732ac8SCy Schubert 		return 1;
62285732ac8SCy Schubert #endif /* CONFIG_OWE */
62385732ac8SCy Schubert 
624c1d255d3SCy Schubert #ifdef CONFIG_WEP
6255b9c547cSRui Paulo 	if (has_wep_key(ssid))
62639beb93cSSam Leffler 		privacy = 1;
627c1d255d3SCy Schubert #endif /* CONFIG_WEP */
6285b9c547cSRui Paulo 
62939beb93cSSam Leffler #ifdef IEEE8021X_EAPOL
63039beb93cSSam Leffler 	if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
63139beb93cSSam Leffler 	    ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
63239beb93cSSam Leffler 				 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
63339beb93cSSam Leffler 		privacy = 1;
63439beb93cSSam Leffler #endif /* IEEE8021X_EAPOL */
63539beb93cSSam Leffler 
636f05cddf9SRui Paulo 	if (wpa_key_mgmt_wpa(ssid->key_mgmt))
637f05cddf9SRui Paulo 		privacy = 1;
638f05cddf9SRui Paulo 
6395b9c547cSRui Paulo 	if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
6405b9c547cSRui Paulo 		privacy = 1;
6415b9c547cSRui Paulo 
64239beb93cSSam Leffler 	if (bss->caps & IEEE80211_CAP_PRIVACY)
64339beb93cSSam Leffler 		return privacy;
64439beb93cSSam Leffler 	return !privacy;
64539beb93cSSam Leffler }
64639beb93cSSam Leffler 
64739beb93cSSam Leffler 
wpa_supplicant_ssid_bss_match(struct wpa_supplicant * wpa_s,struct wpa_ssid * ssid,struct wpa_bss * bss,int debug_print)64839beb93cSSam Leffler static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
64939beb93cSSam Leffler 					 struct wpa_ssid *ssid,
65085732ac8SCy Schubert 					 struct wpa_bss *bss, int debug_print)
65139beb93cSSam Leffler {
65239beb93cSSam Leffler 	struct wpa_ie_data ie;
65339beb93cSSam Leffler 	int proto_match = 0;
65439beb93cSSam Leffler 	const u8 *rsn_ie, *wpa_ie;
65539beb93cSSam Leffler 	int ret;
656c1d255d3SCy Schubert #ifdef CONFIG_WEP
657f05cddf9SRui Paulo 	int wep_ok;
658c1d255d3SCy Schubert #endif /* CONFIG_WEP */
659*a90b9d01SCy Schubert 	bool is_6ghz_bss = is_6ghz_freq(bss->freq);
66039beb93cSSam Leffler 
66139beb93cSSam Leffler 	ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
66239beb93cSSam Leffler 	if (ret >= 0)
66339beb93cSSam Leffler 		return ret;
66439beb93cSSam Leffler 
665c1d255d3SCy Schubert #ifdef CONFIG_WEP
666f05cddf9SRui Paulo 	/* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
667f05cddf9SRui Paulo 	wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
668f05cddf9SRui Paulo 		(((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
669f05cddf9SRui Paulo 		  ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
670f05cddf9SRui Paulo 		 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
671c1d255d3SCy Schubert #endif /* CONFIG_WEP */
672f05cddf9SRui Paulo 
673f05cddf9SRui Paulo 	rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
674*a90b9d01SCy Schubert 	if (is_6ghz_bss && !rsn_ie) {
675*a90b9d01SCy Schubert 		if (debug_print)
676*a90b9d01SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
677*a90b9d01SCy Schubert 				"   skip - 6 GHz BSS without RSNE");
678*a90b9d01SCy Schubert 		return 0;
679*a90b9d01SCy Schubert 	}
680*a90b9d01SCy Schubert 
68185732ac8SCy Schubert 	while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) {
68239beb93cSSam Leffler 		proto_match++;
68339beb93cSSam Leffler 
68439beb93cSSam Leffler 		if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
68585732ac8SCy Schubert 			if (debug_print)
68685732ac8SCy Schubert 				wpa_dbg(wpa_s, MSG_DEBUG,
68785732ac8SCy Schubert 					"   skip RSN IE - parse failed");
68839beb93cSSam Leffler 			break;
68939beb93cSSam Leffler 		}
6904bc52338SCy Schubert 		if (!ie.has_pairwise)
6914bc52338SCy Schubert 			ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
6924bc52338SCy Schubert 		if (!ie.has_group)
6934bc52338SCy Schubert 			ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
694f05cddf9SRui Paulo 
695*a90b9d01SCy Schubert 		if (is_6ghz_bss || !is_zero_ether_addr(bss->mld_addr)) {
696*a90b9d01SCy Schubert 			/* WEP and TKIP are not allowed on 6 GHz/MLD */
697*a90b9d01SCy Schubert 			ie.pairwise_cipher &= ~(WPA_CIPHER_WEP40 |
698*a90b9d01SCy Schubert 						WPA_CIPHER_WEP104 |
699*a90b9d01SCy Schubert 						WPA_CIPHER_TKIP);
700*a90b9d01SCy Schubert 			ie.group_cipher &= ~(WPA_CIPHER_WEP40 |
701*a90b9d01SCy Schubert 					     WPA_CIPHER_WEP104 |
702*a90b9d01SCy Schubert 					     WPA_CIPHER_TKIP);
703*a90b9d01SCy Schubert 		}
704*a90b9d01SCy Schubert 
705c1d255d3SCy Schubert #ifdef CONFIG_WEP
706f05cddf9SRui Paulo 		if (wep_ok &&
707f05cddf9SRui Paulo 		    (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
708f05cddf9SRui Paulo 		{
70985732ac8SCy Schubert 			if (debug_print)
71085732ac8SCy Schubert 				wpa_dbg(wpa_s, MSG_DEBUG,
71185732ac8SCy Schubert 					"   selected based on TSN in RSN IE");
712f05cddf9SRui Paulo 			return 1;
713f05cddf9SRui Paulo 		}
714c1d255d3SCy Schubert #endif /* CONFIG_WEP */
715f05cddf9SRui Paulo 
71685732ac8SCy Schubert 		if (!(ie.proto & ssid->proto) &&
71785732ac8SCy Schubert 		    !(ssid->proto & WPA_PROTO_OSEN)) {
71885732ac8SCy Schubert 			if (debug_print)
71985732ac8SCy Schubert 				wpa_dbg(wpa_s, MSG_DEBUG,
72085732ac8SCy Schubert 					"   skip RSN IE - proto mismatch");
72139beb93cSSam Leffler 			break;
72239beb93cSSam Leffler 		}
72339beb93cSSam Leffler 
72439beb93cSSam Leffler 		if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
72585732ac8SCy Schubert 			if (debug_print)
72685732ac8SCy Schubert 				wpa_dbg(wpa_s, MSG_DEBUG,
72785732ac8SCy Schubert 					"   skip RSN IE - PTK cipher mismatch");
72839beb93cSSam Leffler 			break;
72939beb93cSSam Leffler 		}
73039beb93cSSam Leffler 
73139beb93cSSam Leffler 		if (!(ie.group_cipher & ssid->group_cipher)) {
73285732ac8SCy Schubert 			if (debug_print)
73385732ac8SCy Schubert 				wpa_dbg(wpa_s, MSG_DEBUG,
73485732ac8SCy Schubert 					"   skip RSN IE - GTK cipher mismatch");
73585732ac8SCy Schubert 			break;
73685732ac8SCy Schubert 		}
73785732ac8SCy Schubert 
73885732ac8SCy Schubert 		if (ssid->group_mgmt_cipher &&
73985732ac8SCy Schubert 		    !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
74085732ac8SCy Schubert 			if (debug_print)
74185732ac8SCy Schubert 				wpa_dbg(wpa_s, MSG_DEBUG,
74285732ac8SCy Schubert 					"   skip RSN IE - group mgmt cipher mismatch");
74339beb93cSSam Leffler 			break;
74439beb93cSSam Leffler 		}
74539beb93cSSam Leffler 
746*a90b9d01SCy Schubert 		if (is_6ghz_bss) {
747*a90b9d01SCy Schubert 			/* MFPC must be supported on 6 GHz */
748*a90b9d01SCy Schubert 			if (!(ie.capabilities & WPA_CAPABILITY_MFPC)) {
749*a90b9d01SCy Schubert 				if (debug_print)
750*a90b9d01SCy Schubert 					wpa_dbg(wpa_s, MSG_DEBUG,
751*a90b9d01SCy Schubert 						"   skip RSNE - 6 GHz without MFPC");
752*a90b9d01SCy Schubert 				break;
753*a90b9d01SCy Schubert 			}
754*a90b9d01SCy Schubert 
755*a90b9d01SCy Schubert 			/* WPA PSK is not allowed on the 6 GHz band */
756*a90b9d01SCy Schubert 			ie.key_mgmt &= ~(WPA_KEY_MGMT_PSK |
757*a90b9d01SCy Schubert 					 WPA_KEY_MGMT_FT_PSK |
758*a90b9d01SCy Schubert 					 WPA_KEY_MGMT_PSK_SHA256);
759*a90b9d01SCy Schubert 		}
760*a90b9d01SCy Schubert 
76139beb93cSSam Leffler 		if (!(ie.key_mgmt & ssid->key_mgmt)) {
76285732ac8SCy Schubert 			if (debug_print)
76385732ac8SCy Schubert 				wpa_dbg(wpa_s, MSG_DEBUG,
76485732ac8SCy Schubert 					"   skip RSN IE - key mgmt mismatch");
76539beb93cSSam Leffler 			break;
76639beb93cSSam Leffler 		}
76739beb93cSSam Leffler 
76839beb93cSSam Leffler 		if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
7695b9c547cSRui Paulo 		    wpas_get_ssid_pmf(wpa_s, ssid) ==
770f05cddf9SRui Paulo 		    MGMT_FRAME_PROTECTION_REQUIRED) {
77185732ac8SCy Schubert 			if (debug_print)
77285732ac8SCy Schubert 				wpa_dbg(wpa_s, MSG_DEBUG,
77385732ac8SCy Schubert 					"   skip RSN IE - no mgmt frame protection");
77439beb93cSSam Leffler 			break;
77539beb93cSSam Leffler 		}
776780fb4a2SCy Schubert 		if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
777780fb4a2SCy Schubert 		    wpas_get_ssid_pmf(wpa_s, ssid) ==
778780fb4a2SCy Schubert 		    NO_MGMT_FRAME_PROTECTION) {
77985732ac8SCy Schubert 			if (debug_print)
780780fb4a2SCy Schubert 				wpa_dbg(wpa_s, MSG_DEBUG,
781780fb4a2SCy Schubert 					"   skip RSN IE - no mgmt frame protection enabled but AP requires it");
782780fb4a2SCy Schubert 			break;
783780fb4a2SCy Schubert 		}
78439beb93cSSam Leffler 
78585732ac8SCy Schubert 		if (debug_print)
78685732ac8SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
78785732ac8SCy Schubert 				"   selected based on RSN IE");
78839beb93cSSam Leffler 		return 1;
78939beb93cSSam Leffler 	}
79039beb93cSSam Leffler 
791*a90b9d01SCy Schubert 	if (is_6ghz_bss) {
792*a90b9d01SCy Schubert 		if (debug_print)
793*a90b9d01SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
794*a90b9d01SCy Schubert 				"   skip - 6 GHz BSS without matching RSNE");
795*a90b9d01SCy Schubert 		return 0;
796*a90b9d01SCy Schubert 	}
797*a90b9d01SCy Schubert 
798*a90b9d01SCy Schubert 	wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
799*a90b9d01SCy Schubert 
80085732ac8SCy Schubert 	if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
80185732ac8SCy Schubert 	    (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
802*a90b9d01SCy Schubert #ifdef CONFIG_OWE
803*a90b9d01SCy Schubert 		if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && ssid->owe_only &&
804*a90b9d01SCy Schubert 		    !wpa_ie && !rsn_ie &&
805*a90b9d01SCy Schubert 		    wpa_s->owe_transition_select &&
806*a90b9d01SCy Schubert 		    wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
807*a90b9d01SCy Schubert 		    ssid->owe_transition_bss_select_count + 1 <=
808*a90b9d01SCy Schubert 		    MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
809*a90b9d01SCy Schubert 			ssid->owe_transition_bss_select_count++;
810*a90b9d01SCy Schubert 			if (debug_print)
811*a90b9d01SCy Schubert 				wpa_dbg(wpa_s, MSG_DEBUG,
812*a90b9d01SCy Schubert 					"   skip OWE open BSS (selection count %d does not exceed %d)",
813*a90b9d01SCy Schubert 					ssid->owe_transition_bss_select_count,
814*a90b9d01SCy Schubert 					MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
815*a90b9d01SCy Schubert 			wpa_s->owe_transition_search = 1;
816*a90b9d01SCy Schubert 			return 0;
817*a90b9d01SCy Schubert 		}
818*a90b9d01SCy Schubert #endif /* CONFIG_OWE */
81985732ac8SCy Schubert 		if (debug_print)
820780fb4a2SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
821780fb4a2SCy Schubert 				"   skip - MFP Required but network not MFP Capable");
822780fb4a2SCy Schubert 		return 0;
823780fb4a2SCy Schubert 	}
824780fb4a2SCy Schubert 
82539beb93cSSam Leffler 	while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
82639beb93cSSam Leffler 		proto_match++;
82739beb93cSSam Leffler 
82839beb93cSSam Leffler 		if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
82985732ac8SCy Schubert 			if (debug_print)
83085732ac8SCy Schubert 				wpa_dbg(wpa_s, MSG_DEBUG,
83185732ac8SCy Schubert 					"   skip WPA IE - parse failed");
83239beb93cSSam Leffler 			break;
83339beb93cSSam Leffler 		}
834f05cddf9SRui Paulo 
835c1d255d3SCy Schubert #ifdef CONFIG_WEP
836f05cddf9SRui Paulo 		if (wep_ok &&
837f05cddf9SRui Paulo 		    (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
838f05cddf9SRui Paulo 		{
83985732ac8SCy Schubert 			if (debug_print)
84085732ac8SCy Schubert 				wpa_dbg(wpa_s, MSG_DEBUG,
84185732ac8SCy Schubert 					"   selected based on TSN in WPA IE");
842f05cddf9SRui Paulo 			return 1;
843f05cddf9SRui Paulo 		}
844c1d255d3SCy Schubert #endif /* CONFIG_WEP */
845f05cddf9SRui Paulo 
84639beb93cSSam Leffler 		if (!(ie.proto & ssid->proto)) {
84785732ac8SCy Schubert 			if (debug_print)
84885732ac8SCy Schubert 				wpa_dbg(wpa_s, MSG_DEBUG,
84985732ac8SCy Schubert 					"   skip WPA IE - proto mismatch");
85039beb93cSSam Leffler 			break;
85139beb93cSSam Leffler 		}
85239beb93cSSam Leffler 
85339beb93cSSam Leffler 		if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
85485732ac8SCy Schubert 			if (debug_print)
85585732ac8SCy Schubert 				wpa_dbg(wpa_s, MSG_DEBUG,
85685732ac8SCy Schubert 					"   skip WPA IE - PTK cipher mismatch");
85739beb93cSSam Leffler 			break;
85839beb93cSSam Leffler 		}
85939beb93cSSam Leffler 
86039beb93cSSam Leffler 		if (!(ie.group_cipher & ssid->group_cipher)) {
86185732ac8SCy Schubert 			if (debug_print)
86285732ac8SCy Schubert 				wpa_dbg(wpa_s, MSG_DEBUG,
86385732ac8SCy Schubert 					"   skip WPA IE - GTK cipher mismatch");
86439beb93cSSam Leffler 			break;
86539beb93cSSam Leffler 		}
86639beb93cSSam Leffler 
86739beb93cSSam Leffler 		if (!(ie.key_mgmt & ssid->key_mgmt)) {
86885732ac8SCy Schubert 			if (debug_print)
86985732ac8SCy Schubert 				wpa_dbg(wpa_s, MSG_DEBUG,
87085732ac8SCy Schubert 					"   skip WPA IE - key mgmt mismatch");
87139beb93cSSam Leffler 			break;
87239beb93cSSam Leffler 		}
87339beb93cSSam Leffler 
87485732ac8SCy Schubert 		if (debug_print)
87585732ac8SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
87685732ac8SCy Schubert 				"   selected based on WPA IE");
87739beb93cSSam Leffler 		return 1;
87839beb93cSSam Leffler 	}
87939beb93cSSam Leffler 
880f05cddf9SRui Paulo 	if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
881f05cddf9SRui Paulo 	    !rsn_ie) {
88285732ac8SCy Schubert 		if (debug_print)
88385732ac8SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
88485732ac8SCy Schubert 				"   allow for non-WPA IEEE 802.1X");
885f05cddf9SRui Paulo 		return 1;
886f05cddf9SRui Paulo 	}
887f05cddf9SRui Paulo 
88885732ac8SCy Schubert #ifdef CONFIG_OWE
88985732ac8SCy Schubert 	if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
89085732ac8SCy Schubert 	    !wpa_ie && !rsn_ie) {
89185732ac8SCy Schubert 		if (wpa_s->owe_transition_select &&
89285732ac8SCy Schubert 		    wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
89385732ac8SCy Schubert 		    ssid->owe_transition_bss_select_count + 1 <=
89485732ac8SCy Schubert 		    MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
89585732ac8SCy Schubert 			ssid->owe_transition_bss_select_count++;
89685732ac8SCy Schubert 			if (debug_print)
89785732ac8SCy Schubert 				wpa_dbg(wpa_s, MSG_DEBUG,
89885732ac8SCy Schubert 					"   skip OWE transition BSS (selection count %d does not exceed %d)",
89985732ac8SCy Schubert 					ssid->owe_transition_bss_select_count,
90085732ac8SCy Schubert 					MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
90185732ac8SCy Schubert 			wpa_s->owe_transition_search = 1;
90285732ac8SCy Schubert 			return 0;
90385732ac8SCy Schubert 		}
90485732ac8SCy Schubert 		if (debug_print)
90585732ac8SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
90685732ac8SCy Schubert 				"   allow in OWE transition mode");
90785732ac8SCy Schubert 		return 1;
90885732ac8SCy Schubert 	}
90985732ac8SCy Schubert #endif /* CONFIG_OWE */
91085732ac8SCy Schubert 
911f05cddf9SRui Paulo 	if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
912f05cddf9SRui Paulo 	    wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
91385732ac8SCy Schubert 		if (debug_print)
91485732ac8SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
91585732ac8SCy Schubert 				"   skip - no WPA/RSN proto match");
916f05cddf9SRui Paulo 		return 0;
917f05cddf9SRui Paulo 	}
918f05cddf9SRui Paulo 
9195b9c547cSRui Paulo 	if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
9205b9c547cSRui Paulo 	    wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
92185732ac8SCy Schubert 		if (debug_print)
9225b9c547cSRui Paulo 			wpa_dbg(wpa_s, MSG_DEBUG, "   allow in OSEN");
9235b9c547cSRui Paulo 		return 1;
9245b9c547cSRui Paulo 	}
9255b9c547cSRui Paulo 
926f05cddf9SRui Paulo 	if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
92785732ac8SCy Schubert 		if (debug_print)
928f05cddf9SRui Paulo 			wpa_dbg(wpa_s, MSG_DEBUG, "   allow in non-WPA/WPA2");
929f05cddf9SRui Paulo 		return 1;
930f05cddf9SRui Paulo 	}
931f05cddf9SRui Paulo 
93285732ac8SCy Schubert 	if (debug_print)
93385732ac8SCy Schubert 		wpa_dbg(wpa_s, MSG_DEBUG,
93485732ac8SCy Schubert 			"   reject due to mismatch with WPA/WPA2");
93539beb93cSSam Leffler 
93639beb93cSSam Leffler 	return 0;
93739beb93cSSam Leffler }
93839beb93cSSam Leffler 
93939beb93cSSam Leffler 
freq_allowed(int * freqs,int freq)940e28a4053SRui Paulo static int freq_allowed(int *freqs, int freq)
941e28a4053SRui Paulo {
942e28a4053SRui Paulo 	int i;
943e28a4053SRui Paulo 
944e28a4053SRui Paulo 	if (freqs == NULL)
945e28a4053SRui Paulo 		return 1;
946e28a4053SRui Paulo 
947e28a4053SRui Paulo 	for (i = 0; freqs[i]; i++)
948e28a4053SRui Paulo 		if (freqs[i] == freq)
949e28a4053SRui Paulo 			return 1;
950e28a4053SRui Paulo 	return 0;
951e28a4053SRui Paulo }
952e28a4053SRui Paulo 
953e28a4053SRui Paulo 
rate_match(struct wpa_supplicant * wpa_s,struct wpa_ssid * ssid,struct wpa_bss * bss,int debug_print)954c1d255d3SCy Schubert static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
955c1d255d3SCy Schubert 		      struct wpa_bss *bss, int debug_print)
956f05cddf9SRui Paulo {
957f05cddf9SRui Paulo 	const struct hostapd_hw_modes *mode = NULL, *modes;
958f05cddf9SRui Paulo 	const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
959f05cddf9SRui Paulo 	const u8 *rate_ie;
960f05cddf9SRui Paulo 	int i, j, k;
961f05cddf9SRui Paulo 
962f05cddf9SRui Paulo 	if (bss->freq == 0)
963f05cddf9SRui Paulo 		return 1; /* Cannot do matching without knowing band */
964f05cddf9SRui Paulo 
965f05cddf9SRui Paulo 	modes = wpa_s->hw.modes;
966f05cddf9SRui Paulo 	if (modes == NULL) {
967f05cddf9SRui Paulo 		/*
968f05cddf9SRui Paulo 		 * The driver does not provide any additional information
969f05cddf9SRui Paulo 		 * about the utilized hardware, so allow the connection attempt
970f05cddf9SRui Paulo 		 * to continue.
971f05cddf9SRui Paulo 		 */
972f05cddf9SRui Paulo 		return 1;
973f05cddf9SRui Paulo 	}
974f05cddf9SRui Paulo 
975f05cddf9SRui Paulo 	for (i = 0; i < wpa_s->hw.num_modes; i++) {
976f05cddf9SRui Paulo 		for (j = 0; j < modes[i].num_channels; j++) {
977f05cddf9SRui Paulo 			int freq = modes[i].channels[j].freq;
978f05cddf9SRui Paulo 			if (freq == bss->freq) {
979f05cddf9SRui Paulo 				if (mode &&
980f05cddf9SRui Paulo 				    mode->mode == HOSTAPD_MODE_IEEE80211G)
981f05cddf9SRui Paulo 					break; /* do not allow 802.11b replace
982f05cddf9SRui Paulo 						* 802.11g */
983f05cddf9SRui Paulo 				mode = &modes[i];
984f05cddf9SRui Paulo 				break;
985f05cddf9SRui Paulo 			}
986f05cddf9SRui Paulo 		}
987f05cddf9SRui Paulo 	}
988f05cddf9SRui Paulo 
989f05cddf9SRui Paulo 	if (mode == NULL)
990f05cddf9SRui Paulo 		return 0;
991f05cddf9SRui Paulo 
992f05cddf9SRui Paulo 	for (i = 0; i < (int) sizeof(scan_ie); i++) {
993f05cddf9SRui Paulo 		rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
994f05cddf9SRui Paulo 		if (rate_ie == NULL)
995f05cddf9SRui Paulo 			continue;
996f05cddf9SRui Paulo 
997f05cddf9SRui Paulo 		for (j = 2; j < rate_ie[1] + 2; j++) {
998f05cddf9SRui Paulo 			int flagged = !!(rate_ie[j] & 0x80);
999f05cddf9SRui Paulo 			int r = (rate_ie[j] & 0x7f) * 5;
1000f05cddf9SRui Paulo 
1001f05cddf9SRui Paulo 			/*
1002f05cddf9SRui Paulo 			 * IEEE Std 802.11n-2009 7.3.2.2:
1003f05cddf9SRui Paulo 			 * The new BSS Membership selector value is encoded
1004f05cddf9SRui Paulo 			 * like a legacy basic rate, but it is not a rate and
1005f05cddf9SRui Paulo 			 * only indicates if the BSS members are required to
1006f05cddf9SRui Paulo 			 * support the mandatory features of Clause 20 [HT PHY]
1007f05cddf9SRui Paulo 			 * in order to join the BSS.
1008f05cddf9SRui Paulo 			 */
1009f05cddf9SRui Paulo 			if (flagged && ((rate_ie[j] & 0x7f) ==
1010f05cddf9SRui Paulo 					BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
1011f05cddf9SRui Paulo 				if (!ht_supported(mode)) {
101285732ac8SCy Schubert 					if (debug_print)
1013f05cddf9SRui Paulo 						wpa_dbg(wpa_s, MSG_DEBUG,
101485732ac8SCy Schubert 							"   hardware does not support HT PHY");
1015f05cddf9SRui Paulo 					return 0;
1016f05cddf9SRui Paulo 				}
1017f05cddf9SRui Paulo 				continue;
1018f05cddf9SRui Paulo 			}
1019f05cddf9SRui Paulo 
10205b9c547cSRui Paulo 			/* There's also a VHT selector for 802.11ac */
10215b9c547cSRui Paulo 			if (flagged && ((rate_ie[j] & 0x7f) ==
10225b9c547cSRui Paulo 					BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
10235b9c547cSRui Paulo 				if (!vht_supported(mode)) {
102485732ac8SCy Schubert 					if (debug_print)
10255b9c547cSRui Paulo 						wpa_dbg(wpa_s, MSG_DEBUG,
102685732ac8SCy Schubert 							"   hardware does not support VHT PHY");
10275b9c547cSRui Paulo 					return 0;
10285b9c547cSRui Paulo 				}
10295b9c547cSRui Paulo 				continue;
10305b9c547cSRui Paulo 			}
10315b9c547cSRui Paulo 
1032*a90b9d01SCy Schubert 			if (flagged && ((rate_ie[j] & 0x7f) ==
1033*a90b9d01SCy Schubert 					BSS_MEMBERSHIP_SELECTOR_HE_PHY)) {
1034*a90b9d01SCy Schubert 				if (!he_supported(mode, IEEE80211_MODE_INFRA)) {
1035*a90b9d01SCy Schubert 					if (debug_print)
1036*a90b9d01SCy Schubert 						wpa_dbg(wpa_s, MSG_DEBUG,
1037*a90b9d01SCy Schubert 							"   hardware does not support HE PHY");
1038*a90b9d01SCy Schubert 					return 0;
1039*a90b9d01SCy Schubert 				}
1040*a90b9d01SCy Schubert 				continue;
1041*a90b9d01SCy Schubert 			}
1042*a90b9d01SCy Schubert 
1043c1d255d3SCy Schubert #ifdef CONFIG_SAE
1044c1d255d3SCy Schubert 			if (flagged && ((rate_ie[j] & 0x7f) ==
1045c1d255d3SCy Schubert 					BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY)) {
1046*a90b9d01SCy Schubert 				if (wpa_s->conf->sae_pwe ==
1047*a90b9d01SCy Schubert 				    SAE_PWE_HUNT_AND_PECK &&
1048c1d255d3SCy Schubert 				    !ssid->sae_password_id &&
1049*a90b9d01SCy Schubert 				    !is_6ghz_freq(bss->freq) &&
1050c1d255d3SCy Schubert 				    wpa_key_mgmt_sae(ssid->key_mgmt)) {
1051c1d255d3SCy Schubert 					if (debug_print)
1052c1d255d3SCy Schubert 						wpa_dbg(wpa_s, MSG_DEBUG,
1053c1d255d3SCy Schubert 							"   SAE H2E disabled");
1054c1d255d3SCy Schubert #ifdef CONFIG_TESTING_OPTIONS
1055c1d255d3SCy Schubert 					if (wpa_s->ignore_sae_h2e_only) {
1056c1d255d3SCy Schubert 						wpa_dbg(wpa_s, MSG_DEBUG,
1057c1d255d3SCy Schubert 							"TESTING: Ignore SAE H2E requirement mismatch");
1058c1d255d3SCy Schubert 						continue;
1059c1d255d3SCy Schubert 					}
1060c1d255d3SCy Schubert #endif /* CONFIG_TESTING_OPTIONS */
1061c1d255d3SCy Schubert 					return 0;
1062c1d255d3SCy Schubert 				}
1063c1d255d3SCy Schubert 				continue;
1064c1d255d3SCy Schubert 			}
1065c1d255d3SCy Schubert #endif /* CONFIG_SAE */
1066c1d255d3SCy Schubert 
1067f05cddf9SRui Paulo 			if (!flagged)
1068f05cddf9SRui Paulo 				continue;
1069f05cddf9SRui Paulo 
1070f05cddf9SRui Paulo 			/* check for legacy basic rates */
1071f05cddf9SRui Paulo 			for (k = 0; k < mode->num_rates; k++) {
1072f05cddf9SRui Paulo 				if (mode->rates[k] == r)
1073f05cddf9SRui Paulo 					break;
1074f05cddf9SRui Paulo 			}
1075f05cddf9SRui Paulo 			if (k == mode->num_rates) {
1076f05cddf9SRui Paulo 				/*
1077f05cddf9SRui Paulo 				 * IEEE Std 802.11-2007 7.3.2.2 demands that in
1078f05cddf9SRui Paulo 				 * order to join a BSS all required rates
1079f05cddf9SRui Paulo 				 * have to be supported by the hardware.
1080f05cddf9SRui Paulo 				 */
108185732ac8SCy Schubert 				if (debug_print)
10825b9c547cSRui Paulo 					wpa_dbg(wpa_s, MSG_DEBUG,
10835b9c547cSRui Paulo 						"   hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
10845b9c547cSRui Paulo 						r / 10, r % 10,
10855b9c547cSRui Paulo 						bss->freq, mode->mode, mode->num_rates);
1086f05cddf9SRui Paulo 				return 0;
1087f05cddf9SRui Paulo 			}
1088f05cddf9SRui Paulo 		}
1089f05cddf9SRui Paulo 	}
1090f05cddf9SRui Paulo 
1091f05cddf9SRui Paulo 	return 1;
1092f05cddf9SRui Paulo }
1093f05cddf9SRui Paulo 
1094f05cddf9SRui Paulo 
10955b9c547cSRui Paulo /*
10965b9c547cSRui Paulo  * Test whether BSS is in an ESS.
10975b9c547cSRui Paulo  * This is done differently in DMG (60 GHz) and non-DMG bands
10985b9c547cSRui Paulo  */
bss_is_ess(struct wpa_bss * bss)10995b9c547cSRui Paulo static int bss_is_ess(struct wpa_bss *bss)
11005b9c547cSRui Paulo {
11015b9c547cSRui Paulo 	if (bss_is_dmg(bss)) {
11025b9c547cSRui Paulo 		return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
11035b9c547cSRui Paulo 			IEEE80211_CAP_DMG_AP;
11045b9c547cSRui Paulo 	}
11055b9c547cSRui Paulo 
11065b9c547cSRui Paulo 	return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
11075b9c547cSRui Paulo 		IEEE80211_CAP_ESS);
11085b9c547cSRui Paulo }
11095b9c547cSRui Paulo 
11105b9c547cSRui Paulo 
match_mac_mask(const u8 * addr_a,const u8 * addr_b,const u8 * mask)11115b9c547cSRui Paulo static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
11125b9c547cSRui Paulo {
11135b9c547cSRui Paulo 	size_t i;
11145b9c547cSRui Paulo 
11155b9c547cSRui Paulo 	for (i = 0; i < ETH_ALEN; i++) {
11165b9c547cSRui Paulo 		if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
11175b9c547cSRui Paulo 			return 0;
11185b9c547cSRui Paulo 	}
11195b9c547cSRui Paulo 	return 1;
11205b9c547cSRui Paulo }
11215b9c547cSRui Paulo 
11225b9c547cSRui Paulo 
addr_in_list(const u8 * addr,const u8 * list,size_t num)11235b9c547cSRui Paulo static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
11245b9c547cSRui Paulo {
11255b9c547cSRui Paulo 	size_t i;
11265b9c547cSRui Paulo 
11275b9c547cSRui Paulo 	for (i = 0; i < num; i++) {
11285b9c547cSRui Paulo 		const u8 *a = list + i * ETH_ALEN * 2;
11295b9c547cSRui Paulo 		const u8 *m = a + ETH_ALEN;
11305b9c547cSRui Paulo 
11315b9c547cSRui Paulo 		if (match_mac_mask(a, addr, m))
11325b9c547cSRui Paulo 			return 1;
11335b9c547cSRui Paulo 	}
11345b9c547cSRui Paulo 	return 0;
11355b9c547cSRui Paulo }
11365b9c547cSRui Paulo 
11375b9c547cSRui Paulo 
owe_trans_ssid(struct wpa_supplicant * wpa_s,struct wpa_bss * bss,const u8 ** ret_ssid,size_t * ret_ssid_len)113885732ac8SCy Schubert static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
113985732ac8SCy Schubert 			   const u8 **ret_ssid, size_t *ret_ssid_len)
114085732ac8SCy Schubert {
114185732ac8SCy Schubert #ifdef CONFIG_OWE
114285732ac8SCy Schubert 	const u8 *owe, *pos, *end, *bssid;
114385732ac8SCy Schubert 	u8 ssid_len;
114485732ac8SCy Schubert 
114585732ac8SCy Schubert 	owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
114685732ac8SCy Schubert 	if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN))
114785732ac8SCy Schubert 		return;
114885732ac8SCy Schubert 
114985732ac8SCy Schubert 	pos = owe + 6;
115085732ac8SCy Schubert 	end = owe + 2 + owe[1];
115185732ac8SCy Schubert 
115285732ac8SCy Schubert 	if (end - pos < ETH_ALEN + 1)
115385732ac8SCy Schubert 		return;
115485732ac8SCy Schubert 	bssid = pos;
115585732ac8SCy Schubert 	pos += ETH_ALEN;
115685732ac8SCy Schubert 	ssid_len = *pos++;
115785732ac8SCy Schubert 	if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN)
115885732ac8SCy Schubert 		return;
115985732ac8SCy Schubert 
116085732ac8SCy Schubert 	/* Match the profile SSID against the OWE transition mode SSID on the
116185732ac8SCy Schubert 	 * open network. */
116285732ac8SCy Schubert 	wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
116385732ac8SCy Schubert 		" SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len));
116485732ac8SCy Schubert 	*ret_ssid = pos;
116585732ac8SCy Schubert 	*ret_ssid_len = ssid_len;
116685732ac8SCy Schubert 
1167c1d255d3SCy Schubert 	if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) {
1168c1d255d3SCy Schubert 		struct wpa_ssid *ssid;
1169c1d255d3SCy Schubert 
1170c1d255d3SCy Schubert 		for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1171c1d255d3SCy Schubert 			if (wpas_network_disabled(wpa_s, ssid))
1172c1d255d3SCy Schubert 				continue;
1173c1d255d3SCy Schubert 			if (ssid->ssid_len == ssid_len &&
1174c1d255d3SCy Schubert 			    os_memcmp(ssid->ssid, pos, ssid_len) == 0) {
1175c1d255d3SCy Schubert 				/* OWE BSS in transition mode for a currently
1176c1d255d3SCy Schubert 				 * enabled OWE network. */
1177c1d255d3SCy Schubert 				wpa_dbg(wpa_s, MSG_DEBUG,
1178c1d255d3SCy Schubert 					"OWE: transition mode OWE SSID for active OWE profile");
1179c1d255d3SCy Schubert 				bss->flags |= WPA_BSS_OWE_TRANSITION;
1180c1d255d3SCy Schubert 				break;
1181c1d255d3SCy Schubert 			}
1182c1d255d3SCy Schubert 		}
1183c1d255d3SCy Schubert 	}
118485732ac8SCy Schubert #endif /* CONFIG_OWE */
118585732ac8SCy Schubert }
118685732ac8SCy Schubert 
118785732ac8SCy Schubert 
wpas_valid_ml_bss(struct wpa_supplicant * wpa_s,struct wpa_bss * bss)1188*a90b9d01SCy Schubert static bool wpas_valid_ml_bss(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
1189*a90b9d01SCy Schubert {
1190*a90b9d01SCy Schubert 	u16 removed_links;
1191*a90b9d01SCy Schubert 
1192*a90b9d01SCy Schubert 	if (wpa_bss_parse_basic_ml_element(wpa_s, bss, NULL, NULL, NULL, NULL))
1193*a90b9d01SCy Schubert 		return true;
1194*a90b9d01SCy Schubert 
1195*a90b9d01SCy Schubert 	if (!bss->valid_links)
1196*a90b9d01SCy Schubert 		return true;
1197*a90b9d01SCy Schubert 
1198*a90b9d01SCy Schubert 	/* Check if the current BSS is going to be removed */
1199*a90b9d01SCy Schubert 	removed_links = wpa_bss_parse_reconf_ml_element(wpa_s, bss);
1200*a90b9d01SCy Schubert 	if (BIT(bss->mld_link_id) & removed_links)
1201*a90b9d01SCy Schubert 		return false;
1202*a90b9d01SCy Schubert 
1203*a90b9d01SCy Schubert 	return true;
1204*a90b9d01SCy Schubert }
1205*a90b9d01SCy Schubert 
1206*a90b9d01SCy Schubert 
disabled_freq(struct wpa_supplicant * wpa_s,int freq)1207*a90b9d01SCy Schubert int disabled_freq(struct wpa_supplicant *wpa_s, int freq)
1208c1d255d3SCy Schubert {
1209c1d255d3SCy Schubert 	int i, j;
1210c1d255d3SCy Schubert 
1211c1d255d3SCy Schubert 	if (!wpa_s->hw.modes || !wpa_s->hw.num_modes)
1212c1d255d3SCy Schubert 		return 0;
1213c1d255d3SCy Schubert 
1214c1d255d3SCy Schubert 	for (j = 0; j < wpa_s->hw.num_modes; j++) {
1215c1d255d3SCy Schubert 		struct hostapd_hw_modes *mode = &wpa_s->hw.modes[j];
1216c1d255d3SCy Schubert 
1217c1d255d3SCy Schubert 		for (i = 0; i < mode->num_channels; i++) {
1218c1d255d3SCy Schubert 			struct hostapd_channel_data *chan = &mode->channels[i];
1219c1d255d3SCy Schubert 
1220c1d255d3SCy Schubert 			if (chan->freq == freq)
1221c1d255d3SCy Schubert 				return !!(chan->flag & HOSTAPD_CHAN_DISABLED);
1222c1d255d3SCy Schubert 		}
1223c1d255d3SCy Schubert 	}
1224c1d255d3SCy Schubert 
1225c1d255d3SCy Schubert 	return 1;
1226c1d255d3SCy Schubert }
1227c1d255d3SCy Schubert 
1228c1d255d3SCy Schubert 
1229c1d255d3SCy Schubert static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1230c1d255d3SCy Schubert 			    const u8 *match_ssid, size_t match_ssid_len,
1231c1d255d3SCy Schubert 			    struct wpa_bss *bss, int bssid_ignore_count,
1232c1d255d3SCy Schubert 			    bool debug_print);
1233c1d255d3SCy Schubert 
1234c1d255d3SCy Schubert 
1235c1d255d3SCy Schubert #ifdef CONFIG_SAE_PK
sae_pk_acceptable_bss_with_pk(struct wpa_supplicant * wpa_s,struct wpa_bss * orig_bss,struct wpa_ssid * ssid,const u8 * match_ssid,size_t match_ssid_len)1236c1d255d3SCy Schubert static bool sae_pk_acceptable_bss_with_pk(struct wpa_supplicant *wpa_s,
1237c1d255d3SCy Schubert 					  struct wpa_bss *orig_bss,
1238c1d255d3SCy Schubert 					  struct wpa_ssid *ssid,
1239c1d255d3SCy Schubert 					  const u8 *match_ssid,
1240c1d255d3SCy Schubert 					  size_t match_ssid_len)
1241c1d255d3SCy Schubert {
1242c1d255d3SCy Schubert 	struct wpa_bss *bss;
1243c1d255d3SCy Schubert 
1244c1d255d3SCy Schubert 	dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1245c1d255d3SCy Schubert 		int count;
1246c1d255d3SCy Schubert 		const u8 *ie;
1247c1d255d3SCy Schubert 
1248c1d255d3SCy Schubert 		if (bss == orig_bss)
1249c1d255d3SCy Schubert 			continue;
1250c1d255d3SCy Schubert 		ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
1251c1d255d3SCy Schubert 		if (!(ieee802_11_rsnx_capab(ie, WLAN_RSNX_CAPAB_SAE_PK)))
1252c1d255d3SCy Schubert 			continue;
1253c1d255d3SCy Schubert 
1254c1d255d3SCy Schubert 		/* TODO: Could be more thorough in checking what kind of
1255c1d255d3SCy Schubert 		 * signal strength or throughput estimate would be acceptable
1256c1d255d3SCy Schubert 		 * compared to the originally selected BSS. */
1257c1d255d3SCy Schubert 		if (bss->est_throughput < 2000)
1258c1d255d3SCy Schubert 			return false;
1259c1d255d3SCy Schubert 
1260c1d255d3SCy Schubert 		count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
1261c1d255d3SCy Schubert 		if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1262c1d255d3SCy Schubert 				    bss, count, 0))
1263c1d255d3SCy Schubert 			return true;
1264c1d255d3SCy Schubert 	}
1265c1d255d3SCy Schubert 
1266c1d255d3SCy Schubert 	return false;
1267c1d255d3SCy Schubert }
1268c1d255d3SCy Schubert #endif /* CONFIG_SAE_PK */
1269c1d255d3SCy Schubert 
1270c1d255d3SCy Schubert 
wpa_scan_res_ok(struct wpa_supplicant * wpa_s,struct wpa_ssid * ssid,const u8 * match_ssid,size_t match_ssid_len,struct wpa_bss * bss,int bssid_ignore_count,bool debug_print)1271c1d255d3SCy Schubert static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1272c1d255d3SCy Schubert 			    const u8 *match_ssid, size_t match_ssid_len,
1273c1d255d3SCy Schubert 			    struct wpa_bss *bss, int bssid_ignore_count,
1274c1d255d3SCy Schubert 			    bool debug_print)
1275c1d255d3SCy Schubert {
1276c1d255d3SCy Schubert 	int res;
1277c1d255d3SCy Schubert 	bool wpa, check_ssid, osen, rsn_osen = false;
1278c1d255d3SCy Schubert 	struct wpa_ie_data data;
1279c1d255d3SCy Schubert #ifdef CONFIG_MBO
1280c1d255d3SCy Schubert 	const u8 *assoc_disallow;
1281c1d255d3SCy Schubert #endif /* CONFIG_MBO */
1282c1d255d3SCy Schubert #ifdef CONFIG_SAE
1283c1d255d3SCy Schubert 	u8 rsnxe_capa = 0;
1284c1d255d3SCy Schubert #endif /* CONFIG_SAE */
1285c1d255d3SCy Schubert 	const u8 *ie;
1286c1d255d3SCy Schubert 
1287c1d255d3SCy Schubert 	ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1288c1d255d3SCy Schubert 	wpa = ie && ie[1];
1289c1d255d3SCy Schubert 	ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1290c1d255d3SCy Schubert 	wpa |= ie && ie[1];
1291c1d255d3SCy Schubert 	if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 &&
1292c1d255d3SCy Schubert 	    (data.key_mgmt & WPA_KEY_MGMT_OSEN))
1293c1d255d3SCy Schubert 		rsn_osen = true;
1294c1d255d3SCy Schubert 	ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
1295c1d255d3SCy Schubert 	osen = ie != NULL;
1296c1d255d3SCy Schubert 
1297c1d255d3SCy Schubert #ifdef CONFIG_SAE
1298c1d255d3SCy Schubert 	ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
1299c1d255d3SCy Schubert 	if (ie && ie[1] >= 1)
1300c1d255d3SCy Schubert 		rsnxe_capa = ie[2];
1301c1d255d3SCy Schubert #endif /* CONFIG_SAE */
1302c1d255d3SCy Schubert 
1303c1d255d3SCy Schubert 	check_ssid = wpa || ssid->ssid_len > 0;
1304c1d255d3SCy Schubert 
1305c1d255d3SCy Schubert 	if (wpas_network_disabled(wpa_s, ssid)) {
1306c1d255d3SCy Schubert 		if (debug_print)
1307c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG, "   skip - disabled");
1308c1d255d3SCy Schubert 		return false;
1309c1d255d3SCy Schubert 	}
1310c1d255d3SCy Schubert 
1311c1d255d3SCy Schubert 	res = wpas_temp_disabled(wpa_s, ssid);
1312c1d255d3SCy Schubert 	if (res > 0) {
1313c1d255d3SCy Schubert 		if (debug_print)
1314c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
1315c1d255d3SCy Schubert 				"   skip - disabled temporarily for %d second(s)",
1316c1d255d3SCy Schubert 				res);
1317c1d255d3SCy Schubert 		return false;
1318c1d255d3SCy Schubert 	}
1319c1d255d3SCy Schubert 
1320c1d255d3SCy Schubert #ifdef CONFIG_WPS
1321c1d255d3SCy Schubert 	if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && bssid_ignore_count) {
1322c1d255d3SCy Schubert 		if (debug_print)
1323c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
1324c1d255d3SCy Schubert 				"   skip - BSSID ignored (WPS)");
1325c1d255d3SCy Schubert 		return false;
1326c1d255d3SCy Schubert 	}
1327c1d255d3SCy Schubert 
1328c1d255d3SCy Schubert 	if (wpa && ssid->ssid_len == 0 &&
1329c1d255d3SCy Schubert 	    wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1330c1d255d3SCy Schubert 		check_ssid = false;
1331c1d255d3SCy Schubert 
1332c1d255d3SCy Schubert 	if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1333c1d255d3SCy Schubert 		/* Only allow wildcard SSID match if an AP advertises active
1334c1d255d3SCy Schubert 		 * WPS operation that matches our mode. */
1335c1d255d3SCy Schubert 		check_ssid = ssid->ssid_len > 0 ||
1336c1d255d3SCy Schubert 			!wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss);
1337c1d255d3SCy Schubert 	}
1338c1d255d3SCy Schubert #endif /* CONFIG_WPS */
1339c1d255d3SCy Schubert 
1340c1d255d3SCy Schubert 	if (ssid->bssid_set && ssid->ssid_len == 0 &&
1341*a90b9d01SCy Schubert 	    ether_addr_equal(bss->bssid, ssid->bssid))
1342c1d255d3SCy Schubert 		check_ssid = false;
1343c1d255d3SCy Schubert 
1344c1d255d3SCy Schubert 	if (check_ssid &&
1345c1d255d3SCy Schubert 	    (match_ssid_len != ssid->ssid_len ||
1346c1d255d3SCy Schubert 	     os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
1347c1d255d3SCy Schubert 		if (debug_print)
1348c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG, "   skip - SSID mismatch");
1349c1d255d3SCy Schubert 		return false;
1350c1d255d3SCy Schubert 	}
1351c1d255d3SCy Schubert 
1352c1d255d3SCy Schubert 	if (ssid->bssid_set &&
1353*a90b9d01SCy Schubert 	    !ether_addr_equal(bss->bssid, ssid->bssid)) {
1354c1d255d3SCy Schubert 		if (debug_print)
1355c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG, "   skip - BSSID mismatch");
1356c1d255d3SCy Schubert 		return false;
1357c1d255d3SCy Schubert 	}
1358c1d255d3SCy Schubert 
1359c1d255d3SCy Schubert 	/* check the list of BSSIDs to ignore */
1360c1d255d3SCy Schubert 	if (ssid->num_bssid_ignore &&
1361c1d255d3SCy Schubert 	    addr_in_list(bss->bssid, ssid->bssid_ignore,
1362c1d255d3SCy Schubert 			 ssid->num_bssid_ignore)) {
1363c1d255d3SCy Schubert 		if (debug_print)
1364c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
1365c1d255d3SCy Schubert 				"   skip - BSSID configured to be ignored");
1366c1d255d3SCy Schubert 		return false;
1367c1d255d3SCy Schubert 	}
1368c1d255d3SCy Schubert 
1369c1d255d3SCy Schubert 	/* if there is a list of accepted BSSIDs, only accept those APs */
1370c1d255d3SCy Schubert 	if (ssid->num_bssid_accept &&
1371c1d255d3SCy Schubert 	    !addr_in_list(bss->bssid, ssid->bssid_accept,
1372c1d255d3SCy Schubert 			  ssid->num_bssid_accept)) {
1373c1d255d3SCy Schubert 		if (debug_print)
1374c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
1375c1d255d3SCy Schubert 				"   skip - BSSID not in list of accepted values");
1376c1d255d3SCy Schubert 		return false;
1377c1d255d3SCy Schubert 	}
1378c1d255d3SCy Schubert 
1379c1d255d3SCy Schubert 	if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss, debug_print))
1380c1d255d3SCy Schubert 		return false;
1381c1d255d3SCy Schubert 
1382c1d255d3SCy Schubert 	if (!osen && !wpa &&
1383c1d255d3SCy Schubert 	    !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1384c1d255d3SCy Schubert 	    !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
1385c1d255d3SCy Schubert 	    !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1386c1d255d3SCy Schubert 	    !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
1387c1d255d3SCy Schubert 		if (debug_print)
1388c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
1389c1d255d3SCy Schubert 				"   skip - non-WPA network not allowed");
1390c1d255d3SCy Schubert 		return false;
1391c1d255d3SCy Schubert 	}
1392c1d255d3SCy Schubert 
1393c1d255d3SCy Schubert #ifdef CONFIG_WEP
1394c1d255d3SCy Schubert 	if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && has_wep_key(ssid)) {
1395c1d255d3SCy Schubert 		if (debug_print)
1396c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
1397c1d255d3SCy Schubert 				"   skip - ignore WPA/WPA2 AP for WEP network block");
1398c1d255d3SCy Schubert 		return false;
1399c1d255d3SCy Schubert 	}
1400c1d255d3SCy Schubert #endif /* CONFIG_WEP */
1401c1d255d3SCy Schubert 
1402c1d255d3SCy Schubert 	if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen && !rsn_osen) {
1403c1d255d3SCy Schubert 		if (debug_print)
1404c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
1405c1d255d3SCy Schubert 				"   skip - non-OSEN network not allowed");
1406c1d255d3SCy Schubert 		return false;
1407c1d255d3SCy Schubert 	}
1408c1d255d3SCy Schubert 
1409c1d255d3SCy Schubert 	if (!wpa_supplicant_match_privacy(bss, ssid)) {
1410c1d255d3SCy Schubert 		if (debug_print)
1411c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG, "   skip - privacy mismatch");
1412c1d255d3SCy Schubert 		return false;
1413c1d255d3SCy Schubert 	}
1414c1d255d3SCy Schubert 
1415c1d255d3SCy Schubert 	if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
1416c1d255d3SCy Schubert 	    !bss_is_pbss(bss)) {
1417c1d255d3SCy Schubert 		if (debug_print)
1418c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
1419c1d255d3SCy Schubert 				"   skip - not ESS, PBSS, or MBSS");
1420c1d255d3SCy Schubert 		return false;
1421c1d255d3SCy Schubert 	}
1422c1d255d3SCy Schubert 
1423c1d255d3SCy Schubert 	if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1424c1d255d3SCy Schubert 		if (debug_print)
1425c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
1426c1d255d3SCy Schubert 				"   skip - PBSS mismatch (ssid %d bss %d)",
1427c1d255d3SCy Schubert 				ssid->pbss, bss_is_pbss(bss));
1428c1d255d3SCy Schubert 		return false;
1429c1d255d3SCy Schubert 	}
1430c1d255d3SCy Schubert 
1431c1d255d3SCy Schubert 	if (!freq_allowed(ssid->freq_list, bss->freq)) {
1432c1d255d3SCy Schubert 		if (debug_print)
1433c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
1434c1d255d3SCy Schubert 				"   skip - frequency not allowed");
1435c1d255d3SCy Schubert 		return false;
1436c1d255d3SCy Schubert 	}
1437c1d255d3SCy Schubert 
1438c1d255d3SCy Schubert #ifdef CONFIG_MESH
1439c1d255d3SCy Schubert 	if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
1440c1d255d3SCy Schubert 	    ssid->frequency != bss->freq) {
1441c1d255d3SCy Schubert 		if (debug_print)
1442c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
1443c1d255d3SCy Schubert 				"   skip - frequency not allowed (mesh)");
1444c1d255d3SCy Schubert 		return false;
1445c1d255d3SCy Schubert 	}
1446c1d255d3SCy Schubert #endif /* CONFIG_MESH */
1447c1d255d3SCy Schubert 
1448c1d255d3SCy Schubert 	if (!rate_match(wpa_s, ssid, bss, debug_print)) {
1449c1d255d3SCy Schubert 		if (debug_print)
1450c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
1451c1d255d3SCy Schubert 				"   skip - rate sets do not match");
1452c1d255d3SCy Schubert 		return false;
1453c1d255d3SCy Schubert 	}
1454c1d255d3SCy Schubert 
1455c1d255d3SCy Schubert #ifdef CONFIG_SAE
1456*a90b9d01SCy Schubert 	/* When using SAE Password Identifier and when operationg on the 6 GHz
1457*a90b9d01SCy Schubert 	 * band, only H2E is allowed. */
1458*a90b9d01SCy Schubert 	if ((wpa_s->conf->sae_pwe == SAE_PWE_HASH_TO_ELEMENT ||
1459*a90b9d01SCy Schubert 	     is_6ghz_freq(bss->freq) || ssid->sae_password_id) &&
1460*a90b9d01SCy Schubert 	    wpa_s->conf->sae_pwe != SAE_PWE_FORCE_HUNT_AND_PECK &&
1461*a90b9d01SCy Schubert 	    wpa_key_mgmt_sae(ssid->key_mgmt) &&
1462c1d255d3SCy Schubert 	    !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
1463c1d255d3SCy Schubert 		if (debug_print)
1464c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
1465c1d255d3SCy Schubert 				"   skip - SAE H2E required, but not supported by the AP");
1466c1d255d3SCy Schubert 		return false;
1467c1d255d3SCy Schubert 	}
1468c1d255d3SCy Schubert #endif /* CONFIG_SAE */
1469c1d255d3SCy Schubert 
1470c1d255d3SCy Schubert #ifdef CONFIG_SAE_PK
1471c1d255d3SCy Schubert 	if (ssid->sae_pk == SAE_PK_MODE_ONLY &&
1472c1d255d3SCy Schubert 	    !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK))) {
1473c1d255d3SCy Schubert 		if (debug_print)
1474c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
1475c1d255d3SCy Schubert 				"   skip - SAE-PK required, but not supported by the AP");
1476c1d255d3SCy Schubert 		return false;
1477c1d255d3SCy Schubert 	}
1478c1d255d3SCy Schubert #endif /* CONFIG_SAE_PK */
1479c1d255d3SCy Schubert 
1480c1d255d3SCy Schubert #ifndef CONFIG_IBSS_RSN
1481c1d255d3SCy Schubert 	if (ssid->mode == WPAS_MODE_IBSS &&
1482c1d255d3SCy Schubert 	    !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) {
1483c1d255d3SCy Schubert 		if (debug_print)
1484c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
1485c1d255d3SCy Schubert 				"   skip - IBSS RSN not supported in the build");
1486c1d255d3SCy Schubert 		return false;
1487c1d255d3SCy Schubert 	}
1488c1d255d3SCy Schubert #endif /* !CONFIG_IBSS_RSN */
1489c1d255d3SCy Schubert 
1490c1d255d3SCy Schubert #ifdef CONFIG_P2P
1491c1d255d3SCy Schubert 	if (ssid->p2p_group &&
1492c1d255d3SCy Schubert 	    !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1493c1d255d3SCy Schubert 	    !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1494c1d255d3SCy Schubert 		if (debug_print)
1495c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG, "   skip - no P2P IE seen");
1496c1d255d3SCy Schubert 		return false;
1497c1d255d3SCy Schubert 	}
1498c1d255d3SCy Schubert 
1499c1d255d3SCy Schubert 	if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1500c1d255d3SCy Schubert 		struct wpabuf *p2p_ie;
1501c1d255d3SCy Schubert 		u8 dev_addr[ETH_ALEN];
1502c1d255d3SCy Schubert 
1503c1d255d3SCy Schubert 		ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1504c1d255d3SCy Schubert 		if (!ie) {
1505c1d255d3SCy Schubert 			if (debug_print)
1506c1d255d3SCy Schubert 				wpa_dbg(wpa_s, MSG_DEBUG,
1507c1d255d3SCy Schubert 					"   skip - no P2P element");
1508c1d255d3SCy Schubert 			return false;
1509c1d255d3SCy Schubert 		}
1510c1d255d3SCy Schubert 		p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
1511c1d255d3SCy Schubert 		if (!p2p_ie) {
1512c1d255d3SCy Schubert 			if (debug_print)
1513c1d255d3SCy Schubert 				wpa_dbg(wpa_s, MSG_DEBUG,
1514c1d255d3SCy Schubert 					"   skip - could not fetch P2P element");
1515c1d255d3SCy Schubert 			return false;
1516c1d255d3SCy Schubert 		}
1517c1d255d3SCy Schubert 
1518c1d255d3SCy Schubert 		if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 ||
1519*a90b9d01SCy Schubert 		    !ether_addr_equal(dev_addr, ssid->go_p2p_dev_addr)) {
1520c1d255d3SCy Schubert 			if (debug_print)
1521c1d255d3SCy Schubert 				wpa_dbg(wpa_s, MSG_DEBUG,
1522c1d255d3SCy Schubert 					"   skip - no matching GO P2P Device Address in P2P element");
1523c1d255d3SCy Schubert 			wpabuf_free(p2p_ie);
1524c1d255d3SCy Schubert 			return false;
1525c1d255d3SCy Schubert 		}
1526c1d255d3SCy Schubert 		wpabuf_free(p2p_ie);
1527c1d255d3SCy Schubert 	}
1528c1d255d3SCy Schubert 
1529c1d255d3SCy Schubert 	/*
1530c1d255d3SCy Schubert 	 * TODO: skip the AP if its P2P IE has Group Formation bit set in the
1531c1d255d3SCy Schubert 	 * P2P Group Capability Bitmap and we are not in Group Formation with
1532c1d255d3SCy Schubert 	 * that device.
1533c1d255d3SCy Schubert 	 */
1534c1d255d3SCy Schubert #endif /* CONFIG_P2P */
1535c1d255d3SCy Schubert 
1536c1d255d3SCy Schubert 	if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) {
1537c1d255d3SCy Schubert 		struct os_reltime diff;
1538c1d255d3SCy Schubert 
1539c1d255d3SCy Schubert 		os_reltime_sub(&wpa_s->scan_min_time, &bss->last_update, &diff);
1540c1d255d3SCy Schubert 		if (debug_print)
1541c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
1542c1d255d3SCy Schubert 				"   skip - scan result not recent enough (%u.%06u seconds too old)",
1543c1d255d3SCy Schubert 				(unsigned int) diff.sec,
1544c1d255d3SCy Schubert 				(unsigned int) diff.usec);
1545c1d255d3SCy Schubert 		return false;
1546c1d255d3SCy Schubert 	}
1547c1d255d3SCy Schubert #ifdef CONFIG_MBO
1548c1d255d3SCy Schubert #ifdef CONFIG_TESTING_OPTIONS
1549c1d255d3SCy Schubert 	if (wpa_s->ignore_assoc_disallow)
1550c1d255d3SCy Schubert 		goto skip_assoc_disallow;
1551c1d255d3SCy Schubert #endif /* CONFIG_TESTING_OPTIONS */
1552*a90b9d01SCy Schubert 	assoc_disallow = wpas_mbo_check_assoc_disallow(bss);
1553c1d255d3SCy Schubert 	if (assoc_disallow && assoc_disallow[1] >= 1) {
1554c1d255d3SCy Schubert 		if (debug_print)
1555c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
1556c1d255d3SCy Schubert 				"   skip - MBO association disallowed (reason %u)",
1557c1d255d3SCy Schubert 				assoc_disallow[2]);
1558c1d255d3SCy Schubert 		return false;
1559c1d255d3SCy Schubert 	}
1560c1d255d3SCy Schubert 
1561c1d255d3SCy Schubert 	if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
1562c1d255d3SCy Schubert 		if (debug_print)
1563c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
1564c1d255d3SCy Schubert 				"   skip - AP temporarily disallowed");
1565c1d255d3SCy Schubert 		return false;
1566c1d255d3SCy Schubert 	}
1567c1d255d3SCy Schubert #ifdef CONFIG_TESTING_OPTIONS
1568c1d255d3SCy Schubert skip_assoc_disallow:
1569c1d255d3SCy Schubert #endif /* CONFIG_TESTING_OPTIONS */
1570c1d255d3SCy Schubert #endif /* CONFIG_MBO */
1571c1d255d3SCy Schubert 
1572c1d255d3SCy Schubert #ifdef CONFIG_DPP
1573c1d255d3SCy Schubert 	if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
1574*a90b9d01SCy Schubert 	    !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, wpa_s->own_addr,
1575*a90b9d01SCy Schubert 				 ssid) &&
1576c1d255d3SCy Schubert 	    (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1577c1d255d3SCy Schubert 	     !ssid->dpp_csign)) {
1578c1d255d3SCy Schubert 		if (debug_print)
1579c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
1580c1d255d3SCy Schubert 				"   skip - no PMKSA entry for DPP");
1581c1d255d3SCy Schubert 		return false;
1582c1d255d3SCy Schubert 	}
1583c1d255d3SCy Schubert #endif /* CONFIG_DPP */
1584c1d255d3SCy Schubert 
1585c1d255d3SCy Schubert #ifdef CONFIG_SAE_PK
1586c1d255d3SCy Schubert 	if (ssid->sae_pk == SAE_PK_MODE_AUTOMATIC &&
1587c1d255d3SCy Schubert 	    wpa_key_mgmt_sae(ssid->key_mgmt) &&
1588c1d255d3SCy Schubert 	    ((ssid->sae_password &&
1589c1d255d3SCy Schubert 	      sae_pk_valid_password(ssid->sae_password)) ||
1590c1d255d3SCy Schubert 	     (!ssid->sae_password && ssid->passphrase &&
1591c1d255d3SCy Schubert 	      sae_pk_valid_password(ssid->passphrase))) &&
1592c1d255d3SCy Schubert 	    !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) &&
1593c1d255d3SCy Schubert 	    sae_pk_acceptable_bss_with_pk(wpa_s, bss, ssid, match_ssid,
1594c1d255d3SCy Schubert 					  match_ssid_len)) {
1595c1d255d3SCy Schubert 		if (debug_print)
1596c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
1597c1d255d3SCy Schubert 				"   skip - another acceptable BSS with SAE-PK in the same ESS");
1598c1d255d3SCy Schubert 		return false;
1599c1d255d3SCy Schubert 	}
1600c1d255d3SCy Schubert #endif /* CONFIG_SAE_PK */
1601c1d255d3SCy Schubert 
1602c1d255d3SCy Schubert 	if (bss->ssid_len == 0) {
1603*a90b9d01SCy Schubert #ifdef CONFIG_OWE
1604*a90b9d01SCy Schubert 		const u8 *owe_ssid = NULL;
1605*a90b9d01SCy Schubert 		size_t owe_ssid_len = 0;
1606*a90b9d01SCy Schubert 
1607*a90b9d01SCy Schubert 		owe_trans_ssid(wpa_s, bss, &owe_ssid, &owe_ssid_len);
1608*a90b9d01SCy Schubert 		if (owe_ssid && owe_ssid_len &&
1609*a90b9d01SCy Schubert 		    owe_ssid_len == ssid->ssid_len &&
1610*a90b9d01SCy Schubert 		    os_memcmp(owe_ssid, ssid->ssid, owe_ssid_len) == 0) {
1611*a90b9d01SCy Schubert 			if (debug_print)
1612*a90b9d01SCy Schubert 				wpa_dbg(wpa_s, MSG_DEBUG,
1613*a90b9d01SCy Schubert 					"   skip - no SSID in BSS entry for a possible OWE transition mode BSS");
1614*a90b9d01SCy Schubert 			int_array_add_unique(&wpa_s->owe_trans_scan_freq,
1615*a90b9d01SCy Schubert 					     bss->freq);
1616*a90b9d01SCy Schubert 			return false;
1617*a90b9d01SCy Schubert 		}
1618*a90b9d01SCy Schubert #endif /* CONFIG_OWE */
1619c1d255d3SCy Schubert 		if (debug_print)
1620c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
1621c1d255d3SCy Schubert 				"   skip - no SSID known for the BSS");
1622c1d255d3SCy Schubert 		return false;
1623c1d255d3SCy Schubert 	}
1624c1d255d3SCy Schubert 
1625*a90b9d01SCy Schubert 	if (!wpas_valid_ml_bss(wpa_s, bss)) {
1626*a90b9d01SCy Schubert 		if (debug_print)
1627*a90b9d01SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
1628*a90b9d01SCy Schubert 				"   skip - ML BSS going to be removed");
1629*a90b9d01SCy Schubert 		return false;
1630*a90b9d01SCy Schubert 	}
1631*a90b9d01SCy Schubert 
1632c1d255d3SCy Schubert 	/* Matching configuration found */
1633c1d255d3SCy Schubert 	return true;
1634c1d255d3SCy Schubert }
1635c1d255d3SCy Schubert 
1636c1d255d3SCy Schubert 
wpa_scan_res_match(struct wpa_supplicant * wpa_s,int i,struct wpa_bss * bss,struct wpa_ssid * group,int only_first_ssid,int debug_print)1637780fb4a2SCy Schubert struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1638f05cddf9SRui Paulo 				     int i, struct wpa_bss *bss,
16395b9c547cSRui Paulo 				     struct wpa_ssid *group,
164085732ac8SCy Schubert 				     int only_first_ssid, int debug_print)
1641f05cddf9SRui Paulo {
1642f05cddf9SRui Paulo 	u8 wpa_ie_len, rsn_ie_len;
164339beb93cSSam Leffler 	const u8 *ie;
1644f05cddf9SRui Paulo 	struct wpa_ssid *ssid;
1645c1d255d3SCy Schubert 	int osen;
164685732ac8SCy Schubert 	const u8 *match_ssid;
164785732ac8SCy Schubert 	size_t match_ssid_len;
1648c1d255d3SCy Schubert 	int bssid_ignore_count;
164939beb93cSSam Leffler 
1650f05cddf9SRui Paulo 	ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
165139beb93cSSam Leffler 	wpa_ie_len = ie ? ie[1] : 0;
165239beb93cSSam Leffler 
1653f05cddf9SRui Paulo 	ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
165439beb93cSSam Leffler 	rsn_ie_len = ie ? ie[1] : 0;
165539beb93cSSam Leffler 
16565b9c547cSRui Paulo 	ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
16575b9c547cSRui Paulo 	osen = ie != NULL;
16585b9c547cSRui Paulo 
165985732ac8SCy Schubert 	if (debug_print) {
166085732ac8SCy Schubert 		wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
166185732ac8SCy Schubert 			" ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
166285732ac8SCy Schubert 			i, MAC2STR(bss->bssid),
166385732ac8SCy Schubert 			wpa_ssid_txt(bss->ssid, bss->ssid_len),
166485732ac8SCy Schubert 			wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
166585732ac8SCy Schubert 			bss->freq,
166685732ac8SCy Schubert 			wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
166785732ac8SCy Schubert 			" wps" : "",
16685b9c547cSRui Paulo 			(wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
166985732ac8SCy Schubert 			 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
167085732ac8SCy Schubert 			? " p2p" : "",
16715b9c547cSRui Paulo 			osen ? " osen=1" : "");
167285732ac8SCy Schubert 	}
167339beb93cSSam Leffler 
1674c1d255d3SCy Schubert 	bssid_ignore_count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
1675c1d255d3SCy Schubert 	if (bssid_ignore_count) {
1676f05cddf9SRui Paulo 		int limit = 1;
1677f05cddf9SRui Paulo 		if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
1678f05cddf9SRui Paulo 			/*
1679f05cddf9SRui Paulo 			 * When only a single network is enabled, we can
1680c1d255d3SCy Schubert 			 * trigger BSSID ignoring on the first failure. This
1681f05cddf9SRui Paulo 			 * should not be done with multiple enabled networks to
1682f05cddf9SRui Paulo 			 * avoid getting forced to move into a worse ESS on
1683f05cddf9SRui Paulo 			 * single error if there are no other BSSes of the
1684f05cddf9SRui Paulo 			 * current ESS.
1685f05cddf9SRui Paulo 			 */
1686f05cddf9SRui Paulo 			limit = 0;
1687f05cddf9SRui Paulo 		}
1688c1d255d3SCy Schubert 		if (bssid_ignore_count > limit) {
168985732ac8SCy Schubert 			if (debug_print) {
169085732ac8SCy Schubert 				wpa_dbg(wpa_s, MSG_DEBUG,
1691c1d255d3SCy Schubert 					"   skip - BSSID ignored (count=%d limit=%d)",
1692c1d255d3SCy Schubert 					bssid_ignore_count, limit);
169385732ac8SCy Schubert 			}
1694f05cddf9SRui Paulo 			return NULL;
1695f05cddf9SRui Paulo 		}
169639beb93cSSam Leffler 	}
169739beb93cSSam Leffler 
169885732ac8SCy Schubert 	match_ssid = bss->ssid;
169985732ac8SCy Schubert 	match_ssid_len = bss->ssid_len;
170085732ac8SCy Schubert 	owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
170185732ac8SCy Schubert 
170285732ac8SCy Schubert 	if (match_ssid_len == 0) {
170385732ac8SCy Schubert 		if (debug_print)
1704f05cddf9SRui Paulo 			wpa_dbg(wpa_s, MSG_DEBUG, "   skip - SSID not known");
1705f05cddf9SRui Paulo 		return NULL;
17063157ba21SRui Paulo 	}
17073157ba21SRui Paulo 
1708f05cddf9SRui Paulo 	if (disallowed_bssid(wpa_s, bss->bssid)) {
170985732ac8SCy Schubert 		if (debug_print)
1710f05cddf9SRui Paulo 			wpa_dbg(wpa_s, MSG_DEBUG, "   skip - BSSID disallowed");
1711f05cddf9SRui Paulo 		return NULL;
171239beb93cSSam Leffler 	}
171339beb93cSSam Leffler 
171485732ac8SCy Schubert 	if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
171585732ac8SCy Schubert 		if (debug_print)
1716f05cddf9SRui Paulo 			wpa_dbg(wpa_s, MSG_DEBUG, "   skip - SSID disallowed");
1717f05cddf9SRui Paulo 		return NULL;
1718f05cddf9SRui Paulo 	}
1719f05cddf9SRui Paulo 
1720c1d255d3SCy Schubert 	if (disabled_freq(wpa_s, bss->freq)) {
1721c1d255d3SCy Schubert 		if (debug_print)
1722c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG, "   skip - channel disabled");
1723c1d255d3SCy Schubert 		return NULL;
1724c1d255d3SCy Schubert 	}
1725f05cddf9SRui Paulo 
1726*a90b9d01SCy Schubert 	if (wnm_is_bss_excluded(wpa_s, bss)) {
1727*a90b9d01SCy Schubert 		if (debug_print)
1728*a90b9d01SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG, "   skip - BSSID excluded");
1729*a90b9d01SCy Schubert 		return NULL;
1730*a90b9d01SCy Schubert 	}
1731*a90b9d01SCy Schubert 
17325b9c547cSRui Paulo 	for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
1733c1d255d3SCy Schubert 		if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1734c1d255d3SCy Schubert 				    bss, bssid_ignore_count, debug_print))
1735f05cddf9SRui Paulo 			return ssid;
1736f05cddf9SRui Paulo 	}
1737f05cddf9SRui Paulo 
1738f05cddf9SRui Paulo 	/* No matching configuration found */
173939beb93cSSam Leffler 	return NULL;
174039beb93cSSam Leffler }
174139beb93cSSam Leffler 
174239beb93cSSam Leffler 
1743e28a4053SRui Paulo static struct wpa_bss *
wpa_supplicant_select_bss(struct wpa_supplicant * wpa_s,struct wpa_ssid * group,struct wpa_ssid ** selected_ssid,int only_first_ssid)1744e28a4053SRui Paulo wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
1745e28a4053SRui Paulo 			  struct wpa_ssid *group,
17465b9c547cSRui Paulo 			  struct wpa_ssid **selected_ssid,
17475b9c547cSRui Paulo 			  int only_first_ssid)
174839beb93cSSam Leffler {
1749f05cddf9SRui Paulo 	unsigned int i;
175039beb93cSSam Leffler 
175185732ac8SCy Schubert 	if (wpa_s->current_ssid) {
175285732ac8SCy Schubert 		struct wpa_ssid *ssid;
175385732ac8SCy Schubert 
175485732ac8SCy Schubert 		wpa_dbg(wpa_s, MSG_DEBUG,
175585732ac8SCy Schubert 			"Scan results matching the currently selected network");
175685732ac8SCy Schubert 		for (i = 0; i < wpa_s->last_scan_res_used; i++) {
175785732ac8SCy Schubert 			struct wpa_bss *bss = wpa_s->last_scan_res[i];
175885732ac8SCy Schubert 
175985732ac8SCy Schubert 			ssid = wpa_scan_res_match(wpa_s, i, bss, group,
176085732ac8SCy Schubert 						  only_first_ssid, 0);
176185732ac8SCy Schubert 			if (ssid != wpa_s->current_ssid)
176285732ac8SCy Schubert 				continue;
176385732ac8SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
176485732ac8SCy Schubert 				" freq=%d level=%d snr=%d est_throughput=%u",
176585732ac8SCy Schubert 				i, MAC2STR(bss->bssid), bss->freq, bss->level,
176685732ac8SCy Schubert 				bss->snr, bss->est_throughput);
176785732ac8SCy Schubert 		}
176885732ac8SCy Schubert 	}
176985732ac8SCy Schubert 
17705b9c547cSRui Paulo 	if (only_first_ssid)
17715b9c547cSRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
17725b9c547cSRui Paulo 			group->id);
17735b9c547cSRui Paulo 	else
1774f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
177539beb93cSSam Leffler 			group->priority);
177639beb93cSSam Leffler 
1777f05cddf9SRui Paulo 	for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1778f05cddf9SRui Paulo 		struct wpa_bss *bss = wpa_s->last_scan_res[i];
177985732ac8SCy Schubert 
178085732ac8SCy Schubert 		wpa_s->owe_transition_select = 1;
17815b9c547cSRui Paulo 		*selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
178285732ac8SCy Schubert 						    only_first_ssid, 1);
178385732ac8SCy Schubert 		wpa_s->owe_transition_select = 0;
1784f05cddf9SRui Paulo 		if (!*selected_ssid)
1785f05cddf9SRui Paulo 			continue;
1786c1d255d3SCy Schubert 		wpa_dbg(wpa_s, MSG_DEBUG, "   selected %sBSS " MACSTR
1787f05cddf9SRui Paulo 			" ssid='%s'",
1788c1d255d3SCy Schubert 			bss == wpa_s->current_bss ? "current ": "",
1789f05cddf9SRui Paulo 			MAC2STR(bss->bssid),
1790f05cddf9SRui Paulo 			wpa_ssid_txt(bss->ssid, bss->ssid_len));
1791f05cddf9SRui Paulo 		return bss;
1792f05cddf9SRui Paulo 	}
179339beb93cSSam Leffler 
1794f05cddf9SRui Paulo 	return NULL;
179539beb93cSSam Leffler }
179639beb93cSSam Leffler 
179739beb93cSSam Leffler 
wpa_supplicant_pick_network(struct wpa_supplicant * wpa_s,struct wpa_ssid ** selected_ssid)17985b9c547cSRui Paulo struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1799e28a4053SRui Paulo 					     struct wpa_ssid **selected_ssid)
180039beb93cSSam Leffler {
1801e28a4053SRui Paulo 	struct wpa_bss *selected = NULL;
1802c1d255d3SCy Schubert 	size_t prio;
18035b9c547cSRui Paulo 	struct wpa_ssid *next_ssid = NULL;
1804325151a3SRui Paulo 	struct wpa_ssid *ssid;
18053157ba21SRui Paulo 
1806f05cddf9SRui Paulo 	if (wpa_s->last_scan_res == NULL ||
1807f05cddf9SRui Paulo 	    wpa_s->last_scan_res_used == 0)
1808f05cddf9SRui Paulo 		return NULL; /* no scan results from last update */
1809f05cddf9SRui Paulo 
18105b9c547cSRui Paulo 	if (wpa_s->next_ssid) {
18115b9c547cSRui Paulo 		/* check that next_ssid is still valid */
18125b9c547cSRui Paulo 		for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
18135b9c547cSRui Paulo 			if (ssid == wpa_s->next_ssid)
18145b9c547cSRui Paulo 				break;
18155b9c547cSRui Paulo 		}
18165b9c547cSRui Paulo 		next_ssid = ssid;
18175b9c547cSRui Paulo 		wpa_s->next_ssid = NULL;
18185b9c547cSRui Paulo 	}
18195b9c547cSRui Paulo 
182039beb93cSSam Leffler 	while (selected == NULL) {
182139beb93cSSam Leffler 		for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
18225b9c547cSRui Paulo 			if (next_ssid && next_ssid->priority ==
18235b9c547cSRui Paulo 			    wpa_s->conf->pssid[prio]->priority) {
18245b9c547cSRui Paulo 				selected = wpa_supplicant_select_bss(
18255b9c547cSRui Paulo 					wpa_s, next_ssid, selected_ssid, 1);
18265b9c547cSRui Paulo 				if (selected)
18275b9c547cSRui Paulo 					break;
18285b9c547cSRui Paulo 			}
182939beb93cSSam Leffler 			selected = wpa_supplicant_select_bss(
1830f05cddf9SRui Paulo 				wpa_s, wpa_s->conf->pssid[prio],
18315b9c547cSRui Paulo 				selected_ssid, 0);
183239beb93cSSam Leffler 			if (selected)
183339beb93cSSam Leffler 				break;
183439beb93cSSam Leffler 		}
183539beb93cSSam Leffler 
1836*a90b9d01SCy Schubert 		if (!selected &&
1837*a90b9d01SCy Schubert 		    (wpa_s->bssid_ignore || wnm_active_bss_trans_mgmt(wpa_s)) &&
1838f05cddf9SRui Paulo 		    !wpa_s->countermeasures) {
1839c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
1840c1d255d3SCy Schubert 				"No APs found - clear BSSID ignore list and try again");
1841*a90b9d01SCy Schubert 			wnm_btm_reset(wpa_s);
1842c1d255d3SCy Schubert 			wpa_bssid_ignore_clear(wpa_s);
1843c1d255d3SCy Schubert 			wpa_s->bssid_ignore_cleared = true;
1844e28a4053SRui Paulo 		} else if (selected == NULL)
184539beb93cSSam Leffler 			break;
184639beb93cSSam Leffler 	}
1847e28a4053SRui Paulo 
1848325151a3SRui Paulo 	ssid = *selected_ssid;
1849325151a3SRui Paulo 	if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1850325151a3SRui Paulo 	    !ssid->passphrase && !ssid->ext_psk) {
1851325151a3SRui Paulo 		const char *field_name, *txt = NULL;
1852325151a3SRui Paulo 
1853325151a3SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG,
1854325151a3SRui Paulo 			"PSK/passphrase not yet available for the selected network");
1855325151a3SRui Paulo 
1856325151a3SRui Paulo 		wpas_notify_network_request(wpa_s, ssid,
1857325151a3SRui Paulo 					    WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1858325151a3SRui Paulo 
1859325151a3SRui Paulo 		field_name = wpa_supplicant_ctrl_req_to_string(
1860325151a3SRui Paulo 			WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1861325151a3SRui Paulo 		if (field_name == NULL)
1862325151a3SRui Paulo 			return NULL;
1863325151a3SRui Paulo 
1864325151a3SRui Paulo 		wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1865325151a3SRui Paulo 
1866325151a3SRui Paulo 		selected = NULL;
1867325151a3SRui Paulo 	}
1868325151a3SRui Paulo 
1869e28a4053SRui Paulo 	return selected;
187039beb93cSSam Leffler }
187139beb93cSSam Leffler 
187239beb93cSSam Leffler 
wpa_supplicant_req_new_scan(struct wpa_supplicant * wpa_s,int timeout_sec,int timeout_usec)1873e28a4053SRui Paulo static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1874e28a4053SRui Paulo 					int timeout_sec, int timeout_usec)
1875e28a4053SRui Paulo {
1876f05cddf9SRui Paulo 	if (!wpa_supplicant_enabled_networks(wpa_s)) {
18773157ba21SRui Paulo 		/*
18783157ba21SRui Paulo 		 * No networks are enabled; short-circuit request so
18793157ba21SRui Paulo 		 * we don't wait timeout seconds before transitioning
18803157ba21SRui Paulo 		 * to INACTIVE state.
18813157ba21SRui Paulo 		 */
1882f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1883f05cddf9SRui Paulo 			"since there are no enabled networks");
18843157ba21SRui Paulo 		wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
18853157ba21SRui Paulo 		return;
188639beb93cSSam Leffler 	}
1887f05cddf9SRui Paulo 
1888f05cddf9SRui Paulo 	wpa_s->scan_for_connection = 1;
1889e28a4053SRui Paulo 	wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1890e28a4053SRui Paulo }
1891e28a4053SRui Paulo 
1892e28a4053SRui Paulo 
ml_link_probe_scan(struct wpa_supplicant * wpa_s)1893*a90b9d01SCy Schubert static bool ml_link_probe_scan(struct wpa_supplicant *wpa_s)
1894*a90b9d01SCy Schubert {
1895*a90b9d01SCy Schubert 	if (!wpa_s->ml_connect_probe_ssid || !wpa_s->ml_connect_probe_bss)
1896*a90b9d01SCy Schubert 		return false;
1897*a90b9d01SCy Schubert 
1898*a90b9d01SCy Schubert 	wpa_msg(wpa_s, MSG_DEBUG,
1899*a90b9d01SCy Schubert 		"Request association with " MACSTR " after ML probe",
1900*a90b9d01SCy Schubert 		MAC2STR(wpa_s->ml_connect_probe_bss->bssid));
1901*a90b9d01SCy Schubert 
1902*a90b9d01SCy Schubert 	wpa_supplicant_associate(wpa_s, wpa_s->ml_connect_probe_bss,
1903*a90b9d01SCy Schubert 				 wpa_s->ml_connect_probe_ssid);
1904*a90b9d01SCy Schubert 
1905*a90b9d01SCy Schubert 	wpa_s->ml_connect_probe_ssid = NULL;
1906*a90b9d01SCy Schubert 	wpa_s->ml_connect_probe_bss = NULL;
1907*a90b9d01SCy Schubert 
1908*a90b9d01SCy Schubert 	return true;
1909*a90b9d01SCy Schubert }
1910*a90b9d01SCy Schubert 
1911*a90b9d01SCy Schubert 
wpa_supplicant_connect_ml_missing(struct wpa_supplicant * wpa_s,struct wpa_bss * selected,struct wpa_ssid * ssid)1912*a90b9d01SCy Schubert static int wpa_supplicant_connect_ml_missing(struct wpa_supplicant *wpa_s,
1913*a90b9d01SCy Schubert 					     struct wpa_bss *selected,
1914*a90b9d01SCy Schubert 					     struct wpa_ssid *ssid)
1915*a90b9d01SCy Schubert {
1916*a90b9d01SCy Schubert 	int *freqs;
1917*a90b9d01SCy Schubert 	u16 missing_links = 0, removed_links;
1918*a90b9d01SCy Schubert 	u8 ap_mld_id;
1919*a90b9d01SCy Schubert 
1920*a90b9d01SCy Schubert 	if (!((wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_MLO) &&
1921*a90b9d01SCy Schubert 	      (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)))
1922*a90b9d01SCy Schubert 		return 0;
1923*a90b9d01SCy Schubert 
1924*a90b9d01SCy Schubert 	if (wpa_bss_parse_basic_ml_element(wpa_s, selected, NULL,
1925*a90b9d01SCy Schubert 					   &missing_links, ssid,
1926*a90b9d01SCy Schubert 					   &ap_mld_id) ||
1927*a90b9d01SCy Schubert 	    !missing_links)
1928*a90b9d01SCy Schubert 		return 0;
1929*a90b9d01SCy Schubert 
1930*a90b9d01SCy Schubert 	removed_links = wpa_bss_parse_reconf_ml_element(wpa_s, selected);
1931*a90b9d01SCy Schubert 	missing_links &= ~removed_links;
1932*a90b9d01SCy Schubert 
1933*a90b9d01SCy Schubert 	if (!missing_links)
1934*a90b9d01SCy Schubert 		return 0;
1935*a90b9d01SCy Schubert 
1936*a90b9d01SCy Schubert 	wpa_dbg(wpa_s, MSG_DEBUG,
1937*a90b9d01SCy Schubert 		"MLD: Doing an ML probe for missing links 0x%04x",
1938*a90b9d01SCy Schubert 		missing_links);
1939*a90b9d01SCy Schubert 
1940*a90b9d01SCy Schubert 	freqs = os_malloc(sizeof(int) * 2);
1941*a90b9d01SCy Schubert 	if (!freqs)
1942*a90b9d01SCy Schubert 		return 0;
1943*a90b9d01SCy Schubert 
1944*a90b9d01SCy Schubert 	wpa_s->ml_connect_probe_ssid = ssid;
1945*a90b9d01SCy Schubert 	wpa_s->ml_connect_probe_bss = selected;
1946*a90b9d01SCy Schubert 
1947*a90b9d01SCy Schubert 	freqs[0] = selected->freq;
1948*a90b9d01SCy Schubert 	freqs[1] = 0;
1949*a90b9d01SCy Schubert 
1950*a90b9d01SCy Schubert 	wpa_s->manual_scan_passive = 0;
1951*a90b9d01SCy Schubert 	wpa_s->manual_scan_use_id = 0;
1952*a90b9d01SCy Schubert 	wpa_s->manual_scan_only_new = 0;
1953*a90b9d01SCy Schubert 	wpa_s->scan_id_count = 0;
1954*a90b9d01SCy Schubert 	os_free(wpa_s->manual_scan_freqs);
1955*a90b9d01SCy Schubert 	wpa_s->manual_scan_freqs = freqs;
1956*a90b9d01SCy Schubert 
1957*a90b9d01SCy Schubert 	os_memcpy(wpa_s->ml_probe_bssid, selected->bssid, ETH_ALEN);
1958*a90b9d01SCy Schubert 
1959*a90b9d01SCy Schubert 	/*
1960*a90b9d01SCy Schubert 	 * In case the ML probe request is intended to retrieve information from
1961*a90b9d01SCy Schubert 	 * the transmitted BSS, the AP MLD ID should be included and should be
1962*a90b9d01SCy Schubert 	 * set to zero.
1963*a90b9d01SCy Schubert 	 * In case the ML probe requested is intended to retrieve information
1964*a90b9d01SCy Schubert 	 * from a non-transmitted BSS, the AP MLD ID should not be included.
1965*a90b9d01SCy Schubert 	 */
1966*a90b9d01SCy Schubert 	if (ap_mld_id)
1967*a90b9d01SCy Schubert 		wpa_s->ml_probe_mld_id = -1;
1968*a90b9d01SCy Schubert 	else
1969*a90b9d01SCy Schubert 		wpa_s->ml_probe_mld_id = 0;
1970*a90b9d01SCy Schubert 
1971*a90b9d01SCy Schubert 	if (ssid && ssid->ssid_len) {
1972*a90b9d01SCy Schubert 		os_free(wpa_s->ssids_from_scan_req);
1973*a90b9d01SCy Schubert 		wpa_s->num_ssids_from_scan_req = 0;
1974*a90b9d01SCy Schubert 
1975*a90b9d01SCy Schubert 		wpa_s->ssids_from_scan_req =
1976*a90b9d01SCy Schubert 			os_zalloc(sizeof(struct wpa_ssid_value));
1977*a90b9d01SCy Schubert 		if (wpa_s->ssids_from_scan_req) {
1978*a90b9d01SCy Schubert 			wpa_printf(MSG_DEBUG,
1979*a90b9d01SCy Schubert 				   "MLD: ML probe: With direct SSID");
1980*a90b9d01SCy Schubert 
1981*a90b9d01SCy Schubert 			wpa_s->num_ssids_from_scan_req = 1;
1982*a90b9d01SCy Schubert 			wpa_s->ssids_from_scan_req[0].ssid_len = ssid->ssid_len;
1983*a90b9d01SCy Schubert 			os_memcpy(wpa_s->ssids_from_scan_req[0].ssid,
1984*a90b9d01SCy Schubert 				  ssid->ssid, ssid->ssid_len);
1985*a90b9d01SCy Schubert 		}
1986*a90b9d01SCy Schubert 	}
1987*a90b9d01SCy Schubert 
1988*a90b9d01SCy Schubert 	wpa_s->ml_probe_links = missing_links;
1989*a90b9d01SCy Schubert 
1990*a90b9d01SCy Schubert 	wpa_s->normal_scans = 0;
1991*a90b9d01SCy Schubert 	wpa_s->scan_req = MANUAL_SCAN_REQ;
1992*a90b9d01SCy Schubert 	wpa_s->after_wps = 0;
1993*a90b9d01SCy Schubert 	wpa_s->known_wps_freq = 0;
1994*a90b9d01SCy Schubert 	wpa_supplicant_req_scan(wpa_s, 0, 0);
1995*a90b9d01SCy Schubert 
1996*a90b9d01SCy Schubert 	return 1;
1997*a90b9d01SCy Schubert }
1998*a90b9d01SCy Schubert 
1999*a90b9d01SCy Schubert 
wpa_supplicant_connect(struct wpa_supplicant * wpa_s,struct wpa_bss * selected,struct wpa_ssid * ssid)2000f05cddf9SRui Paulo int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
2001e28a4053SRui Paulo 			   struct wpa_bss *selected,
2002e28a4053SRui Paulo 			   struct wpa_ssid *ssid)
2003e28a4053SRui Paulo {
2004*a90b9d01SCy Schubert #ifdef IEEE8021X_EAPOL
2005*a90b9d01SCy Schubert 	if ((eap_is_wps_pbc_enrollee(&ssid->eap) &&
2006*a90b9d01SCy Schubert 	     wpas_wps_partner_link_overlap_detect(wpa_s)) ||
2007*a90b9d01SCy Schubert 	    wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
2008e28a4053SRui Paulo 		wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
2009e28a4053SRui Paulo 			"PBC session overlap");
2010325151a3SRui Paulo 		wpas_notify_wps_event_pbc_overlap(wpa_s);
2011*a90b9d01SCy Schubert 		wpa_s->wps_overlap = true;
2012f05cddf9SRui Paulo #ifdef CONFIG_P2P
20135b9c547cSRui Paulo 		if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
20145b9c547cSRui Paulo 		    wpa_s->p2p_in_provisioning) {
20155b9c547cSRui Paulo 			eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
20165b9c547cSRui Paulo 					       wpa_s, NULL);
2017f05cddf9SRui Paulo 			return -1;
20185b9c547cSRui Paulo 		}
2019f05cddf9SRui Paulo #endif /* CONFIG_P2P */
2020f05cddf9SRui Paulo 
2021f05cddf9SRui Paulo #ifdef CONFIG_WPS
2022325151a3SRui Paulo 		wpas_wps_pbc_overlap(wpa_s);
2023f05cddf9SRui Paulo 		wpas_wps_cancel(wpa_s);
2024f05cddf9SRui Paulo #endif /* CONFIG_WPS */
2025f05cddf9SRui Paulo 		return -1;
2026e28a4053SRui Paulo 	}
2027*a90b9d01SCy Schubert #endif /* IEEE8021X_EAPOL */
2028e28a4053SRui Paulo 
20295b9c547cSRui Paulo 	wpa_msg(wpa_s, MSG_DEBUG,
20305b9c547cSRui Paulo 		"Considering connect request: reassociate: %d  selected: "
20315b9c547cSRui Paulo 		MACSTR "  bssid: " MACSTR "  pending: " MACSTR
20325b9c547cSRui Paulo 		"  wpa_state: %s  ssid=%p  current_ssid=%p",
20335b9c547cSRui Paulo 		wpa_s->reassociate, MAC2STR(selected->bssid),
20345b9c547cSRui Paulo 		MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
20355b9c547cSRui Paulo 		wpa_supplicant_state_txt(wpa_s->wpa_state),
20365b9c547cSRui Paulo 		ssid, wpa_s->current_ssid);
20375b9c547cSRui Paulo 
2038e28a4053SRui Paulo 	/*
2039e28a4053SRui Paulo 	 * Do not trigger new association unless the BSSID has changed or if
2040e28a4053SRui Paulo 	 * reassociation is requested. If we are in process of associating with
2041e28a4053SRui Paulo 	 * the selected BSSID, do not trigger new attempt.
2042e28a4053SRui Paulo 	 */
2043e28a4053SRui Paulo 	if (wpa_s->reassociate ||
2044*a90b9d01SCy Schubert 	    (!ether_addr_equal(selected->bssid, wpa_s->bssid) &&
2045f05cddf9SRui Paulo 	     ((wpa_s->wpa_state != WPA_ASSOCIATING &&
2046f05cddf9SRui Paulo 	       wpa_s->wpa_state != WPA_AUTHENTICATING) ||
20475b9c547cSRui Paulo 	      (!is_zero_ether_addr(wpa_s->pending_bssid) &&
2048*a90b9d01SCy Schubert 	       !ether_addr_equal(selected->bssid, wpa_s->pending_bssid)) ||
20495b9c547cSRui Paulo 	      (is_zero_ether_addr(wpa_s->pending_bssid) &&
20505b9c547cSRui Paulo 	       ssid != wpa_s->current_ssid)))) {
2051e28a4053SRui Paulo 		if (wpa_supplicant_scard_init(wpa_s, ssid)) {
2052e28a4053SRui Paulo 			wpa_supplicant_req_new_scan(wpa_s, 10, 0);
2053f05cddf9SRui Paulo 			return 0;
2054e28a4053SRui Paulo 		}
2055*a90b9d01SCy Schubert 
2056*a90b9d01SCy Schubert 		if (wpa_supplicant_connect_ml_missing(wpa_s, selected, ssid))
2057*a90b9d01SCy Schubert 			return 0;
2058*a90b9d01SCy Schubert 
20595b9c547cSRui Paulo 		wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
20605b9c547cSRui Paulo 			MAC2STR(selected->bssid));
2061e28a4053SRui Paulo 		wpa_supplicant_associate(wpa_s, selected, ssid);
2062e28a4053SRui Paulo 	} else {
20635b9c547cSRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
20645b9c547cSRui Paulo 			"connect with the selected AP");
2065e28a4053SRui Paulo 	}
2066f05cddf9SRui Paulo 
2067f05cddf9SRui Paulo 	return 0;
2068e28a4053SRui Paulo }
2069e28a4053SRui Paulo 
2070e28a4053SRui Paulo 
2071e28a4053SRui Paulo static struct wpa_ssid *
wpa_supplicant_pick_new_network(struct wpa_supplicant * wpa_s)2072e28a4053SRui Paulo wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
2073e28a4053SRui Paulo {
2074c1d255d3SCy Schubert 	size_t prio;
2075e28a4053SRui Paulo 	struct wpa_ssid *ssid;
2076e28a4053SRui Paulo 
2077e28a4053SRui Paulo 	for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
2078e28a4053SRui Paulo 		for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
2079e28a4053SRui Paulo 		{
2080f05cddf9SRui Paulo 			if (wpas_network_disabled(wpa_s, ssid))
2081e28a4053SRui Paulo 				continue;
208285732ac8SCy Schubert #ifndef CONFIG_IBSS_RSN
208385732ac8SCy Schubert 			if (ssid->mode == WPAS_MODE_IBSS &&
208485732ac8SCy Schubert 			    !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
208585732ac8SCy Schubert 						WPA_KEY_MGMT_WPA_NONE))) {
208685732ac8SCy Schubert 				wpa_msg(wpa_s, MSG_INFO,
208785732ac8SCy Schubert 					"IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
208885732ac8SCy Schubert 					wpa_ssid_txt(ssid->ssid,
208985732ac8SCy Schubert 						     ssid->ssid_len));
209085732ac8SCy Schubert 				continue;
209185732ac8SCy Schubert 			}
209285732ac8SCy Schubert #endif /* !CONFIG_IBSS_RSN */
2093206b73d0SCy Schubert 			if (ssid->mode == WPAS_MODE_IBSS ||
2094206b73d0SCy Schubert 			    ssid->mode == WPAS_MODE_AP ||
2095206b73d0SCy Schubert 			    ssid->mode == WPAS_MODE_MESH)
2096e28a4053SRui Paulo 				return ssid;
2097e28a4053SRui Paulo 		}
2098e28a4053SRui Paulo 	}
2099e28a4053SRui Paulo 	return NULL;
2100e28a4053SRui Paulo }
2101e28a4053SRui Paulo 
2102e28a4053SRui Paulo 
2103e28a4053SRui Paulo /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
2104e28a4053SRui Paulo  * on BSS added and BSS changed events */
wpa_supplicant_rsn_preauth_scan_results(struct wpa_supplicant * wpa_s)2105e28a4053SRui Paulo static void wpa_supplicant_rsn_preauth_scan_results(
2106f05cddf9SRui Paulo 	struct wpa_supplicant *wpa_s)
2107e28a4053SRui Paulo {
2108f05cddf9SRui Paulo 	struct wpa_bss *bss;
2109e28a4053SRui Paulo 
2110e28a4053SRui Paulo 	if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
2111e28a4053SRui Paulo 		return;
2112e28a4053SRui Paulo 
2113f05cddf9SRui Paulo 	dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
2114e28a4053SRui Paulo 		const u8 *ssid, *rsn;
2115e28a4053SRui Paulo 
2116f05cddf9SRui Paulo 		ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
2117e28a4053SRui Paulo 		if (ssid == NULL)
2118e28a4053SRui Paulo 			continue;
2119e28a4053SRui Paulo 
2120f05cddf9SRui Paulo 		rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2121e28a4053SRui Paulo 		if (rsn == NULL)
2122e28a4053SRui Paulo 			continue;
2123e28a4053SRui Paulo 
2124f05cddf9SRui Paulo 		rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
2125e28a4053SRui Paulo 	}
2126e28a4053SRui Paulo 
2127e28a4053SRui Paulo }
2128e28a4053SRui Paulo 
2129e28a4053SRui Paulo 
2130c1d255d3SCy Schubert #ifndef CONFIG_NO_ROAMING
2131c1d255d3SCy Schubert 
wpas_get_snr_signal_info(u32 frequency,int avg_signal,int noise)2132c1d255d3SCy Schubert static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise)
2133c1d255d3SCy Schubert {
2134*a90b9d01SCy Schubert 	if (noise == WPA_INVALID_NOISE) {
2135*a90b9d01SCy Schubert 		if (IS_5GHZ(frequency)) {
2136*a90b9d01SCy Schubert 			noise = DEFAULT_NOISE_FLOOR_5GHZ;
2137*a90b9d01SCy Schubert 		} else if (is_6ghz_freq(frequency)) {
2138*a90b9d01SCy Schubert 			noise = DEFAULT_NOISE_FLOOR_6GHZ;
2139*a90b9d01SCy Schubert 		} else {
2140*a90b9d01SCy Schubert 			noise = DEFAULT_NOISE_FLOOR_2GHZ;
2141*a90b9d01SCy Schubert 		}
2142*a90b9d01SCy Schubert 	}
2143c1d255d3SCy Schubert 	return avg_signal - noise;
2144c1d255d3SCy Schubert }
2145c1d255d3SCy Schubert 
2146c1d255d3SCy Schubert 
2147c1d255d3SCy Schubert static unsigned int
wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant * wpa_s,const struct wpa_bss * bss,int snr)2148c1d255d3SCy Schubert wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
2149c1d255d3SCy Schubert 				     const struct wpa_bss *bss, int snr)
2150c1d255d3SCy Schubert {
2151c1d255d3SCy Schubert 	int rate = wpa_bss_get_max_rate(bss);
2152c1d255d3SCy Schubert 	const u8 *ies = wpa_bss_ie_ptr(bss);
2153c1d255d3SCy Schubert 	size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
2154*a90b9d01SCy Schubert 	enum chan_width max_cw = CHAN_WIDTH_UNKNOWN;
2155c1d255d3SCy Schubert 
2156*a90b9d01SCy Schubert 	return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr, bss->freq,
2157*a90b9d01SCy Schubert 				&max_cw);
2158*a90b9d01SCy Schubert }
2159*a90b9d01SCy Schubert 
2160*a90b9d01SCy Schubert 
wpas_evaluate_band_score(int frequency)2161*a90b9d01SCy Schubert static int wpas_evaluate_band_score(int frequency)
2162*a90b9d01SCy Schubert {
2163*a90b9d01SCy Schubert 	if (is_6ghz_freq(frequency))
2164*a90b9d01SCy Schubert 		return 2;
2165*a90b9d01SCy Schubert 	if (IS_5GHZ(frequency))
2166*a90b9d01SCy Schubert 		return 1;
2167*a90b9d01SCy Schubert 	return 0;
2168c1d255d3SCy Schubert }
2169c1d255d3SCy Schubert 
2170c1d255d3SCy Schubert 
wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant * wpa_s,struct wpa_bss * current_bss,struct wpa_bss * selected)2171c1d255d3SCy Schubert int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s,
2172c1d255d3SCy Schubert 					   struct wpa_bss *current_bss,
2173c1d255d3SCy Schubert 					   struct wpa_bss *selected)
2174c1d255d3SCy Schubert {
2175c1d255d3SCy Schubert 	int min_diff, diff;
2176*a90b9d01SCy Schubert 	int cur_band_score, sel_band_score;
2177*a90b9d01SCy Schubert 	int to_5ghz, to_6ghz;
2178*a90b9d01SCy Schubert 	int cur_level, sel_level;
2179c1d255d3SCy Schubert 	unsigned int cur_est, sel_est;
2180c1d255d3SCy Schubert 	struct wpa_signal_info si;
2181c1d255d3SCy Schubert 	int cur_snr = 0;
2182c1d255d3SCy Schubert 	int ret = 0;
2183*a90b9d01SCy Schubert 	const u8 *cur_ies = wpa_bss_ie_ptr(current_bss);
2184*a90b9d01SCy Schubert 	const u8 *sel_ies = wpa_bss_ie_ptr(selected);
2185*a90b9d01SCy Schubert 	size_t cur_ie_len = current_bss->ie_len ? current_bss->ie_len :
2186*a90b9d01SCy Schubert 		current_bss->beacon_ie_len;
2187*a90b9d01SCy Schubert 	size_t sel_ie_len = selected->ie_len ? selected->ie_len :
2188*a90b9d01SCy Schubert 		selected->beacon_ie_len;
2189c1d255d3SCy Schubert 
2190c1d255d3SCy Schubert 	wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
2191c1d255d3SCy Schubert 	wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
2192c1d255d3SCy Schubert 		" freq=%d level=%d snr=%d est_throughput=%u",
2193c1d255d3SCy Schubert 		MAC2STR(current_bss->bssid),
2194c1d255d3SCy Schubert 		current_bss->freq, current_bss->level,
2195c1d255d3SCy Schubert 		current_bss->snr, current_bss->est_throughput);
2196c1d255d3SCy Schubert 	wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
2197c1d255d3SCy Schubert 		" freq=%d level=%d snr=%d est_throughput=%u",
2198c1d255d3SCy Schubert 		MAC2STR(selected->bssid), selected->freq, selected->level,
2199c1d255d3SCy Schubert 		selected->snr, selected->est_throughput);
2200c1d255d3SCy Schubert 
2201*a90b9d01SCy Schubert 	if (wpas_ap_link_address(wpa_s, selected->bssid)) {
2202*a90b9d01SCy Schubert 		wpa_dbg(wpa_s, MSG_DEBUG, "MLD: associated to selected BSS");
2203*a90b9d01SCy Schubert 		return 0;
2204*a90b9d01SCy Schubert 	}
2205*a90b9d01SCy Schubert 
2206c1d255d3SCy Schubert 	if (wpa_s->current_ssid->bssid_set &&
2207*a90b9d01SCy Schubert 	    ether_addr_equal(selected->bssid, wpa_s->current_ssid->bssid)) {
2208c1d255d3SCy Schubert 		wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
2209c1d255d3SCy Schubert 			"has preferred BSSID");
2210c1d255d3SCy Schubert 		return 1;
2211c1d255d3SCy Schubert 	}
2212c1d255d3SCy Schubert 
2213c1d255d3SCy Schubert 	/*
2214c1d255d3SCy Schubert 	 * Try to poll the signal from the driver since this will allow to get
2215c1d255d3SCy Schubert 	 * more accurate values. In some cases, there can be big differences
2216c1d255d3SCy Schubert 	 * between the RSSI of the Probe Response frames of the AP we are
2217c1d255d3SCy Schubert 	 * associated with and the Beacon frames we hear from the same AP after
2218c1d255d3SCy Schubert 	 * association. This can happen, e.g., when there are two antennas that
2219c1d255d3SCy Schubert 	 * hear the AP very differently. If the driver chooses to hear the
2220c1d255d3SCy Schubert 	 * Probe Response frames during the scan on the "bad" antenna because
2221c1d255d3SCy Schubert 	 * it wants to save power, but knows to choose the other antenna after
2222c1d255d3SCy Schubert 	 * association, we will hear our AP with a low RSSI as part of the
2223c1d255d3SCy Schubert 	 * scan even when we can hear it decently on the other antenna. To cope
2224c1d255d3SCy Schubert 	 * with this, ask the driver to teach us how it hears the AP. Also, the
2225c1d255d3SCy Schubert 	 * scan results may be a bit old, since we can very quickly get fresh
2226c1d255d3SCy Schubert 	 * information about our currently associated AP.
2227c1d255d3SCy Schubert 	 */
2228c1d255d3SCy Schubert 	if (wpa_drv_signal_poll(wpa_s, &si) == 0 &&
2229*a90b9d01SCy Schubert 	    (si.data.avg_beacon_signal || si.data.avg_signal)) {
2230*a90b9d01SCy Schubert 		/*
2231*a90b9d01SCy Schubert 		 * Normalize avg_signal to the RSSI over 20 MHz, as the
2232*a90b9d01SCy Schubert 		 * throughput is estimated based on the RSSI over 20 MHz
2233*a90b9d01SCy Schubert 		 */
2234*a90b9d01SCy Schubert 		cur_level = si.data.avg_beacon_signal ?
2235*a90b9d01SCy Schubert 			si.data.avg_beacon_signal :
2236*a90b9d01SCy Schubert 			(si.data.avg_signal -
2237*a90b9d01SCy Schubert 			 wpas_channel_width_rssi_bump(cur_ies, cur_ie_len,
2238*a90b9d01SCy Schubert 						      si.chanwidth));
2239c1d255d3SCy Schubert 		cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level,
2240c1d255d3SCy Schubert 						   si.current_noise);
2241c1d255d3SCy Schubert 
2242c1d255d3SCy Schubert 		cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s,
2243c1d255d3SCy Schubert 							       current_bss,
2244c1d255d3SCy Schubert 							       cur_snr);
2245c1d255d3SCy Schubert 		wpa_dbg(wpa_s, MSG_DEBUG,
2246c1d255d3SCy Schubert 			"Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u",
2247c1d255d3SCy Schubert 			cur_level, cur_snr, cur_est);
2248*a90b9d01SCy Schubert 	} else {
2249*a90b9d01SCy Schubert 		/* Level and SNR are measured over 20 MHz channel */
2250*a90b9d01SCy Schubert 		cur_level = current_bss->level;
2251*a90b9d01SCy Schubert 		cur_snr = current_bss->snr;
2252*a90b9d01SCy Schubert 		cur_est = current_bss->est_throughput;
2253c1d255d3SCy Schubert 	}
2254c1d255d3SCy Schubert 
2255*a90b9d01SCy Schubert 	/* Adjust the SNR of BSSes based on the channel width. */
2256*a90b9d01SCy Schubert 	cur_level += wpas_channel_width_rssi_bump(cur_ies, cur_ie_len,
2257*a90b9d01SCy Schubert 						  current_bss->max_cw);
2258*a90b9d01SCy Schubert 	cur_snr = wpas_adjust_snr_by_chanwidth(cur_ies, cur_ie_len,
2259*a90b9d01SCy Schubert 					       current_bss->max_cw, cur_snr);
2260*a90b9d01SCy Schubert 
2261*a90b9d01SCy Schubert 	sel_est = selected->est_throughput;
2262*a90b9d01SCy Schubert 	sel_level = selected->level +
2263*a90b9d01SCy Schubert 		wpas_channel_width_rssi_bump(sel_ies, sel_ie_len,
2264*a90b9d01SCy Schubert 					     selected->max_cw);
2265*a90b9d01SCy Schubert 
2266c1d255d3SCy Schubert 	if (sel_est > cur_est + 5000) {
2267c1d255d3SCy Schubert 		wpa_dbg(wpa_s, MSG_DEBUG,
2268c1d255d3SCy Schubert 			"Allow reassociation - selected BSS has better estimated throughput");
2269c1d255d3SCy Schubert 		return 1;
2270c1d255d3SCy Schubert 	}
2271c1d255d3SCy Schubert 
2272c1d255d3SCy Schubert 	to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
2273*a90b9d01SCy Schubert 	to_6ghz = is_6ghz_freq(selected->freq) &&
2274*a90b9d01SCy Schubert 		!is_6ghz_freq(current_bss->freq);
2275c1d255d3SCy Schubert 
2276*a90b9d01SCy Schubert 	if (cur_level < 0 &&
2277*a90b9d01SCy Schubert 	    cur_level > sel_level + to_5ghz * 2 + to_6ghz * 2 &&
2278c1d255d3SCy Schubert 	    sel_est < cur_est * 1.2) {
2279c1d255d3SCy Schubert 		wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
2280c1d255d3SCy Schubert 			"signal level");
2281c1d255d3SCy Schubert 		return 0;
2282c1d255d3SCy Schubert 	}
2283c1d255d3SCy Schubert 
2284c1d255d3SCy Schubert 	if (cur_est > sel_est + 5000) {
2285c1d255d3SCy Schubert 		wpa_dbg(wpa_s, MSG_DEBUG,
2286c1d255d3SCy Schubert 			"Skip roam - Current BSS has better estimated throughput");
2287c1d255d3SCy Schubert 		return 0;
2288c1d255d3SCy Schubert 	}
2289c1d255d3SCy Schubert 
2290c1d255d3SCy Schubert 	if (cur_snr > GREAT_SNR) {
2291c1d255d3SCy Schubert 		wpa_dbg(wpa_s, MSG_DEBUG,
2292c1d255d3SCy Schubert 			"Skip roam - Current BSS has good SNR (%u > %u)",
2293c1d255d3SCy Schubert 			cur_snr, GREAT_SNR);
2294c1d255d3SCy Schubert 		return 0;
2295c1d255d3SCy Schubert 	}
2296c1d255d3SCy Schubert 
2297c1d255d3SCy Schubert 	if (cur_level < -85) /* ..-86 dBm */
2298c1d255d3SCy Schubert 		min_diff = 1;
2299c1d255d3SCy Schubert 	else if (cur_level < -80) /* -85..-81 dBm */
2300c1d255d3SCy Schubert 		min_diff = 2;
2301c1d255d3SCy Schubert 	else if (cur_level < -75) /* -80..-76 dBm */
2302c1d255d3SCy Schubert 		min_diff = 3;
2303c1d255d3SCy Schubert 	else if (cur_level < -70) /* -75..-71 dBm */
2304c1d255d3SCy Schubert 		min_diff = 4;
2305c1d255d3SCy Schubert 	else if (cur_level < 0) /* -70..-1 dBm */
2306c1d255d3SCy Schubert 		min_diff = 5;
2307c1d255d3SCy Schubert 	else /* unspecified units (not in dBm) */
2308c1d255d3SCy Schubert 		min_diff = 2;
2309c1d255d3SCy Schubert 
2310c1d255d3SCy Schubert 	if (cur_est > sel_est * 1.5)
2311c1d255d3SCy Schubert 		min_diff += 10;
2312c1d255d3SCy Schubert 	else if (cur_est > sel_est * 1.2)
2313c1d255d3SCy Schubert 		min_diff += 5;
2314c1d255d3SCy Schubert 	else if (cur_est > sel_est * 1.1)
2315c1d255d3SCy Schubert 		min_diff += 2;
2316c1d255d3SCy Schubert 	else if (cur_est > sel_est)
2317c1d255d3SCy Schubert 		min_diff++;
2318c1d255d3SCy Schubert 	else if (sel_est > cur_est * 1.5)
2319c1d255d3SCy Schubert 		min_diff -= 10;
2320c1d255d3SCy Schubert 	else if (sel_est > cur_est * 1.2)
2321c1d255d3SCy Schubert 		min_diff -= 5;
2322c1d255d3SCy Schubert 	else if (sel_est > cur_est * 1.1)
2323c1d255d3SCy Schubert 		min_diff -= 2;
2324c1d255d3SCy Schubert 	else if (sel_est > cur_est)
2325c1d255d3SCy Schubert 		min_diff--;
2326c1d255d3SCy Schubert 
2327*a90b9d01SCy Schubert 	cur_band_score = wpas_evaluate_band_score(current_bss->freq);
2328*a90b9d01SCy Schubert 	sel_band_score = wpas_evaluate_band_score(selected->freq);
2329*a90b9d01SCy Schubert 	min_diff += (cur_band_score - sel_band_score) * 2;
2330*a90b9d01SCy Schubert 	if (wpa_s->signal_threshold && cur_level <= wpa_s->signal_threshold &&
2331*a90b9d01SCy Schubert 	    sel_level > wpa_s->signal_threshold)
2332c1d255d3SCy Schubert 		min_diff -= 2;
2333*a90b9d01SCy Schubert 	diff = sel_level - cur_level;
2334c1d255d3SCy Schubert 	if (diff < min_diff) {
2335c1d255d3SCy Schubert 		wpa_dbg(wpa_s, MSG_DEBUG,
2336c1d255d3SCy Schubert 			"Skip roam - too small difference in signal level (%d < %d)",
2337c1d255d3SCy Schubert 			diff, min_diff);
2338c1d255d3SCy Schubert 		ret = 0;
2339c1d255d3SCy Schubert 	} else {
2340c1d255d3SCy Schubert 		wpa_dbg(wpa_s, MSG_DEBUG,
2341c1d255d3SCy Schubert 			"Allow reassociation due to difference in signal level (%d >= %d)",
2342c1d255d3SCy Schubert 			diff, min_diff);
2343c1d255d3SCy Schubert 		ret = 1;
2344c1d255d3SCy Schubert 	}
2345c1d255d3SCy Schubert 	wpa_msg_ctrl(wpa_s, MSG_INFO, "%scur_bssid=" MACSTR
2346c1d255d3SCy Schubert 		     " cur_freq=%d cur_level=%d cur_est=%d sel_bssid=" MACSTR
2347c1d255d3SCy Schubert 		     " sel_freq=%d sel_level=%d sel_est=%d",
2348c1d255d3SCy Schubert 		     ret ? WPA_EVENT_DO_ROAM : WPA_EVENT_SKIP_ROAM,
2349c1d255d3SCy Schubert 		     MAC2STR(current_bss->bssid),
2350c1d255d3SCy Schubert 		     current_bss->freq, cur_level, cur_est,
2351c1d255d3SCy Schubert 		     MAC2STR(selected->bssid),
2352*a90b9d01SCy Schubert 		     selected->freq, sel_level, sel_est);
2353c1d255d3SCy Schubert 	return ret;
2354c1d255d3SCy Schubert }
2355c1d255d3SCy Schubert 
2356c1d255d3SCy Schubert #endif /* CONFIG_NO_ROAMING */
2357c1d255d3SCy Schubert 
2358c1d255d3SCy Schubert 
wpa_supplicant_need_to_roam(struct wpa_supplicant * wpa_s,struct wpa_bss * selected,struct wpa_ssid * ssid)2359e28a4053SRui Paulo static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
2360e28a4053SRui Paulo 				       struct wpa_bss *selected,
2361f05cddf9SRui Paulo 				       struct wpa_ssid *ssid)
2362e28a4053SRui Paulo {
2363f05cddf9SRui Paulo 	struct wpa_bss *current_bss = NULL;
2364*a90b9d01SCy Schubert 	const u8 *bssid;
2365e28a4053SRui Paulo 
2366e28a4053SRui Paulo 	if (wpa_s->reassociate)
2367e28a4053SRui Paulo 		return 1; /* explicit request to reassociate */
2368e28a4053SRui Paulo 	if (wpa_s->wpa_state < WPA_ASSOCIATED)
2369e28a4053SRui Paulo 		return 1; /* we are not associated; continue */
2370e28a4053SRui Paulo 	if (wpa_s->current_ssid == NULL)
2371e28a4053SRui Paulo 		return 1; /* unknown current SSID */
2372e28a4053SRui Paulo 	if (wpa_s->current_ssid != ssid)
2373e28a4053SRui Paulo 		return 1; /* different network block */
2374e28a4053SRui Paulo 
2375f05cddf9SRui Paulo 	if (wpas_driver_bss_selection(wpa_s))
2376f05cddf9SRui Paulo 		return 0; /* Driver-based roaming */
2377e28a4053SRui Paulo 
2378*a90b9d01SCy Schubert 	if (wpa_s->valid_links)
2379*a90b9d01SCy Schubert 		bssid = wpa_s->links[wpa_s->mlo_assoc_link_id].bssid;
2380*a90b9d01SCy Schubert 	else
2381*a90b9d01SCy Schubert 		bssid = wpa_s->bssid;
2382*a90b9d01SCy Schubert 
2383f05cddf9SRui Paulo 	if (wpa_s->current_ssid->ssid)
2384*a90b9d01SCy Schubert 		current_bss = wpa_bss_get(wpa_s, bssid,
2385f05cddf9SRui Paulo 					  wpa_s->current_ssid->ssid,
2386f05cddf9SRui Paulo 					  wpa_s->current_ssid->ssid_len);
2387f05cddf9SRui Paulo 	if (!current_bss)
2388*a90b9d01SCy Schubert 		current_bss = wpa_bss_get_bssid(wpa_s, bssid);
2389e28a4053SRui Paulo 
2390e28a4053SRui Paulo 	if (!current_bss)
2391e28a4053SRui Paulo 		return 1; /* current BSS not seen in scan results */
2392e28a4053SRui Paulo 
2393f05cddf9SRui Paulo 	if (current_bss == selected)
2394f05cddf9SRui Paulo 		return 0;
2395f05cddf9SRui Paulo 
2396f05cddf9SRui Paulo 	if (selected->last_update_idx > current_bss->last_update_idx)
2397f05cddf9SRui Paulo 		return 1; /* current BSS not seen in the last scan */
2398f05cddf9SRui Paulo 
2399f05cddf9SRui Paulo #ifndef CONFIG_NO_ROAMING
2400c1d255d3SCy Schubert 	return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss,
2401c1d255d3SCy Schubert 						      selected);
2402f05cddf9SRui Paulo #else /* CONFIG_NO_ROAMING */
2403f05cddf9SRui Paulo 	return 0;
2404f05cddf9SRui Paulo #endif /* CONFIG_NO_ROAMING */
2405e28a4053SRui Paulo }
2406e28a4053SRui Paulo 
2407e28a4053SRui Paulo 
240885732ac8SCy Schubert /*
240985732ac8SCy Schubert  * Return a negative value if no scan results could be fetched or if scan
241085732ac8SCy Schubert  * results should not be shared with other virtual interfaces.
241185732ac8SCy Schubert  * Return 0 if scan results were fetched and may be shared with other
241285732ac8SCy Schubert  * interfaces.
241385732ac8SCy Schubert  * Return 1 if scan results may be shared with other virtual interfaces but may
241485732ac8SCy Schubert  * not trigger any operations.
241585732ac8SCy Schubert  * Return 2 if the interface was removed and cannot be used.
241685732ac8SCy Schubert  */
_wpa_supplicant_event_scan_results(struct wpa_supplicant * wpa_s,union wpa_event_data * data,int own_request,int update_only)2417f05cddf9SRui Paulo static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
24185b9c547cSRui Paulo 					      union wpa_event_data *data,
241985732ac8SCy Schubert 					      int own_request, int update_only)
2420e28a4053SRui Paulo {
24215b9c547cSRui Paulo 	struct wpa_scan_results *scan_res = NULL;
24225b9c547cSRui Paulo 	int ret = 0;
2423e28a4053SRui Paulo 	int ap = 0;
2424*a90b9d01SCy Schubert 	bool trigger_6ghz_scan;
2425f05cddf9SRui Paulo #ifndef CONFIG_NO_RANDOM_POOL
2426f05cddf9SRui Paulo 	size_t i, num;
2427f05cddf9SRui Paulo #endif /* CONFIG_NO_RANDOM_POOL */
2428e28a4053SRui Paulo 
2429e28a4053SRui Paulo #ifdef CONFIG_AP
2430e28a4053SRui Paulo 	if (wpa_s->ap_iface)
2431e28a4053SRui Paulo 		ap = 1;
2432e28a4053SRui Paulo #endif /* CONFIG_AP */
2433e28a4053SRui Paulo 
2434*a90b9d01SCy Schubert 	trigger_6ghz_scan = wpa_s->crossed_6ghz_dom &&
2435*a90b9d01SCy Schubert 		wpa_s->last_scan_all_chan;
2436*a90b9d01SCy Schubert 	wpa_s->crossed_6ghz_dom = false;
2437*a90b9d01SCy Schubert 	wpa_s->last_scan_all_chan = false;
2438*a90b9d01SCy Schubert 
2439e28a4053SRui Paulo 	wpa_supplicant_notify_scanning(wpa_s, 0);
2440e28a4053SRui Paulo 
2441e28a4053SRui Paulo 	scan_res = wpa_supplicant_get_scan_results(wpa_s,
2442e28a4053SRui Paulo 						   data ? &data->scan_info :
2443*a90b9d01SCy Schubert 						   NULL, 1, NULL);
2444e28a4053SRui Paulo 	if (scan_res == NULL) {
24455b9c547cSRui Paulo 		if (wpa_s->conf->ap_scan == 2 || ap ||
24465b9c547cSRui Paulo 		    wpa_s->scan_res_handler == scan_only_handler)
24475b9c547cSRui Paulo 			return -1;
24485b9c547cSRui Paulo 		if (!own_request)
2449f05cddf9SRui Paulo 			return -1;
2450780fb4a2SCy Schubert 		if (data && data->scan_info.external_scan)
2451780fb4a2SCy Schubert 			return -1;
2452c1d255d3SCy Schubert 		if (wpa_s->scan_res_fail_handler) {
2453c1d255d3SCy Schubert 			void (*handler)(struct wpa_supplicant *wpa_s);
2454c1d255d3SCy Schubert 
2455c1d255d3SCy Schubert 			handler = wpa_s->scan_res_fail_handler;
2456c1d255d3SCy Schubert 			wpa_s->scan_res_fail_handler = NULL;
2457c1d255d3SCy Schubert 			handler(wpa_s);
2458c1d255d3SCy Schubert 		} else {
2459c1d255d3SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
2460c1d255d3SCy Schubert 				"Failed to get scan results - try scanning again");
2461e28a4053SRui Paulo 			wpa_supplicant_req_new_scan(wpa_s, 1, 0);
2462c1d255d3SCy Schubert 		}
2463c1d255d3SCy Schubert 
24645b9c547cSRui Paulo 		ret = -1;
24655b9c547cSRui Paulo 		goto scan_work_done;
2466e28a4053SRui Paulo 	}
2467e28a4053SRui Paulo 
2468f05cddf9SRui Paulo #ifndef CONFIG_NO_RANDOM_POOL
2469f05cddf9SRui Paulo 	num = scan_res->num;
2470f05cddf9SRui Paulo 	if (num > 10)
2471f05cddf9SRui Paulo 		num = 10;
2472f05cddf9SRui Paulo 	for (i = 0; i < num; i++) {
2473f05cddf9SRui Paulo 		u8 buf[5];
2474f05cddf9SRui Paulo 		struct wpa_scan_res *res = scan_res->res[i];
2475f05cddf9SRui Paulo 		buf[0] = res->bssid[5];
2476f05cddf9SRui Paulo 		buf[1] = res->qual & 0xff;
2477f05cddf9SRui Paulo 		buf[2] = res->noise & 0xff;
2478f05cddf9SRui Paulo 		buf[3] = res->level & 0xff;
2479f05cddf9SRui Paulo 		buf[4] = res->tsf & 0xff;
2480f05cddf9SRui Paulo 		random_add_randomness(buf, sizeof(buf));
2481f05cddf9SRui Paulo 	}
2482f05cddf9SRui Paulo #endif /* CONFIG_NO_RANDOM_POOL */
2483f05cddf9SRui Paulo 
248485732ac8SCy Schubert 	if (update_only) {
248585732ac8SCy Schubert 		ret = 1;
248685732ac8SCy Schubert 		goto scan_work_done;
248785732ac8SCy Schubert 	}
248885732ac8SCy Schubert 
24895b9c547cSRui Paulo 	if (own_request && wpa_s->scan_res_handler &&
2490780fb4a2SCy Schubert 	    !(data && data->scan_info.external_scan)) {
2491f05cddf9SRui Paulo 		void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
2492f05cddf9SRui Paulo 					 struct wpa_scan_results *scan_res);
2493f05cddf9SRui Paulo 
2494f05cddf9SRui Paulo 		scan_res_handler = wpa_s->scan_res_handler;
2495e28a4053SRui Paulo 		wpa_s->scan_res_handler = NULL;
2496f05cddf9SRui Paulo 		scan_res_handler(wpa_s, scan_res);
249785732ac8SCy Schubert 		ret = 1;
24985b9c547cSRui Paulo 		goto scan_work_done;
2499e28a4053SRui Paulo 	}
2500e28a4053SRui Paulo 
25015b9c547cSRui Paulo 	wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
2502780fb4a2SCy Schubert 		wpa_s->own_scan_running,
2503780fb4a2SCy Schubert 		data ? data->scan_info.external_scan : 0);
25045b9c547cSRui Paulo 	if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
2505780fb4a2SCy Schubert 	    wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
2506780fb4a2SCy Schubert 	    own_request && !(data && data->scan_info.external_scan)) {
25075b9c547cSRui Paulo 		wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
25085b9c547cSRui Paulo 			     wpa_s->manual_scan_id);
25095b9c547cSRui Paulo 		wpa_s->manual_scan_use_id = 0;
25105b9c547cSRui Paulo 	} else {
2511e28a4053SRui Paulo 		wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
25125b9c547cSRui Paulo 	}
2513e28a4053SRui Paulo 	wpas_notify_scan_results(wpa_s);
2514e28a4053SRui Paulo 
2515e28a4053SRui Paulo 	wpas_notify_scan_done(wpa_s, 1);
2516e28a4053SRui Paulo 
2517c1d255d3SCy Schubert 	if (ap) {
2518c1d255d3SCy Schubert 		wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
2519c1d255d3SCy Schubert #ifdef CONFIG_AP
2520c1d255d3SCy Schubert 		if (wpa_s->ap_iface->scan_cb)
2521c1d255d3SCy Schubert 			wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
2522c1d255d3SCy Schubert #endif /* CONFIG_AP */
2523c1d255d3SCy Schubert 		goto scan_work_done;
2524c1d255d3SCy Schubert 	}
2525c1d255d3SCy Schubert 
2526780fb4a2SCy Schubert 	if (data && data->scan_info.external_scan) {
25275b9c547cSRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
2528f05cddf9SRui Paulo 		wpa_scan_results_free(scan_res);
2529f05cddf9SRui Paulo 		return 0;
2530f05cddf9SRui Paulo 	}
2531f05cddf9SRui Paulo 
2532*a90b9d01SCy Schubert 	if (wnm_scan_process(wpa_s, false) > 0)
25335b9c547cSRui Paulo 		goto scan_work_done;
2534f05cddf9SRui Paulo 
253532a95656SCy Schubert 	if (sme_proc_obss_scan(wpa_s) > 0)
25365b9c547cSRui Paulo 		goto scan_work_done;
25375b9c547cSRui Paulo 
2538*a90b9d01SCy Schubert #ifndef CONFIG_NO_RRM
25394bc52338SCy Schubert 	if (own_request && data &&
254085732ac8SCy Schubert 	    wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
254185732ac8SCy Schubert 		goto scan_work_done;
2542*a90b9d01SCy Schubert #endif /* CONFIG_NO_RRM */
2543*a90b9d01SCy Schubert 
2544*a90b9d01SCy Schubert 	if (ml_link_probe_scan(wpa_s))
2545*a90b9d01SCy Schubert 		goto scan_work_done;
254685732ac8SCy Schubert 
25475b9c547cSRui Paulo 	if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
25485b9c547cSRui Paulo 		goto scan_work_done;
25495b9c547cSRui Paulo 
25505b9c547cSRui Paulo 	if (autoscan_notify_scan(wpa_s, scan_res))
25515b9c547cSRui Paulo 		goto scan_work_done;
2552e28a4053SRui Paulo 
2553e28a4053SRui Paulo 	if (wpa_s->disconnected) {
2554e28a4053SRui Paulo 		wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
25555b9c547cSRui Paulo 		goto scan_work_done;
2556e28a4053SRui Paulo 	}
2557e28a4053SRui Paulo 
2558f05cddf9SRui Paulo 	if (!wpas_driver_bss_selection(wpa_s) &&
25595b9c547cSRui Paulo 	    bgscan_notify_scan(wpa_s, scan_res) == 1)
25605b9c547cSRui Paulo 		goto scan_work_done;
2561e28a4053SRui Paulo 
2562f05cddf9SRui Paulo 	wpas_wps_update_ap_info(wpa_s, scan_res);
2563e28a4053SRui Paulo 
2564780fb4a2SCy Schubert 	if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2565780fb4a2SCy Schubert 	    wpa_s->wpa_state < WPA_COMPLETED)
2566780fb4a2SCy Schubert 		goto scan_work_done;
2567780fb4a2SCy Schubert 
2568f05cddf9SRui Paulo 	wpa_scan_results_free(scan_res);
2569f05cddf9SRui Paulo 
2570780fb4a2SCy Schubert 	if (own_request && wpa_s->scan_work) {
25715b9c547cSRui Paulo 		struct wpa_radio_work *work = wpa_s->scan_work;
25725b9c547cSRui Paulo 		wpa_s->scan_work = NULL;
25735b9c547cSRui Paulo 		radio_work_done(work);
25745b9c547cSRui Paulo 	}
25755b9c547cSRui Paulo 
2576c1d255d3SCy Schubert 	os_free(wpa_s->last_scan_freqs);
2577c1d255d3SCy Schubert 	wpa_s->last_scan_freqs = NULL;
2578c1d255d3SCy Schubert 	wpa_s->num_last_scan_freqs = 0;
2579c1d255d3SCy Schubert 	if (own_request && data &&
2580c1d255d3SCy Schubert 	    data->scan_info.freqs && data->scan_info.num_freqs) {
2581c1d255d3SCy Schubert 		wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
2582c1d255d3SCy Schubert 						   data->scan_info.num_freqs);
2583c1d255d3SCy Schubert 		if (wpa_s->last_scan_freqs) {
2584c1d255d3SCy Schubert 			os_memcpy(wpa_s->last_scan_freqs,
2585c1d255d3SCy Schubert 				  data->scan_info.freqs,
2586c1d255d3SCy Schubert 				  sizeof(int) * data->scan_info.num_freqs);
2587c1d255d3SCy Schubert 			wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
2588c1d255d3SCy Schubert 		}
2589c1d255d3SCy Schubert 	}
2590c1d255d3SCy Schubert 
2591*a90b9d01SCy Schubert 	if (wpa_s->supp_pbc_active && !wpas_wps_partner_link_scan_done(wpa_s))
2592*a90b9d01SCy Schubert 		return ret;
2593*a90b9d01SCy Schubert 
2594*a90b9d01SCy Schubert 	return wpas_select_network_from_last_scan(wpa_s, 1, own_request,
2595*a90b9d01SCy Schubert 						  trigger_6ghz_scan, data);
25965b9c547cSRui Paulo 
25975b9c547cSRui Paulo scan_work_done:
25985b9c547cSRui Paulo 	wpa_scan_results_free(scan_res);
2599780fb4a2SCy Schubert 	if (own_request && wpa_s->scan_work) {
26005b9c547cSRui Paulo 		struct wpa_radio_work *work = wpa_s->scan_work;
26015b9c547cSRui Paulo 		wpa_s->scan_work = NULL;
26025b9c547cSRui Paulo 		radio_work_done(work);
26035b9c547cSRui Paulo 	}
26045b9c547cSRui Paulo 	return ret;
2605f05cddf9SRui Paulo }
2606f05cddf9SRui Paulo 
2607f05cddf9SRui Paulo 
wpas_trigger_6ghz_scan(struct wpa_supplicant * wpa_s,union wpa_event_data * data)2608*a90b9d01SCy Schubert static int wpas_trigger_6ghz_scan(struct wpa_supplicant *wpa_s,
2609*a90b9d01SCy Schubert 				  union wpa_event_data *data)
2610*a90b9d01SCy Schubert {
2611*a90b9d01SCy Schubert 	struct wpa_driver_scan_params params;
2612*a90b9d01SCy Schubert 	unsigned int j;
2613*a90b9d01SCy Schubert 
2614*a90b9d01SCy Schubert 	wpa_dbg(wpa_s, MSG_INFO, "Triggering 6GHz-only scan");
2615*a90b9d01SCy Schubert 	os_memset(&params, 0, sizeof(params));
2616*a90b9d01SCy Schubert 	params.non_coloc_6ghz = wpa_s->last_scan_non_coloc_6ghz;
2617*a90b9d01SCy Schubert 	for (j = 0; j < data->scan_info.num_ssids; j++)
2618*a90b9d01SCy Schubert 		params.ssids[j] = data->scan_info.ssids[j];
2619*a90b9d01SCy Schubert 	params.num_ssids = data->scan_info.num_ssids;
2620*a90b9d01SCy Schubert 	wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, &params,
2621*a90b9d01SCy Schubert 				true, !wpa_s->last_scan_non_coloc_6ghz, false);
2622*a90b9d01SCy Schubert 	if (!wpa_supplicant_trigger_scan(wpa_s, &params, true, true)) {
2623*a90b9d01SCy Schubert 		os_free(params.freqs);
2624*a90b9d01SCy Schubert 		return 1;
2625*a90b9d01SCy Schubert 	}
2626*a90b9d01SCy Schubert 	wpa_dbg(wpa_s, MSG_INFO, "Failed to trigger 6GHz-only scan");
2627*a90b9d01SCy Schubert 	os_free(params.freqs);
2628*a90b9d01SCy Schubert 	return 0;
2629*a90b9d01SCy Schubert }
2630*a90b9d01SCy Schubert 
2631*a90b9d01SCy Schubert 
2632*a90b9d01SCy Schubert /**
2633*a90b9d01SCy Schubert  * Select a network from the last scan
2634*a90b9d01SCy Schubert  * @wpa_s: Pointer to wpa_supplicant data
2635*a90b9d01SCy Schubert  * @new_scan: Whether this function was called right after a scan has finished
2636*a90b9d01SCy Schubert  * @own_request: Whether the scan was requested by this interface
2637*a90b9d01SCy Schubert  * @trigger_6ghz_scan: Whether to trigger a 6ghz-only scan when applicable
2638*a90b9d01SCy Schubert  * @data: Scan data from scan that finished if applicable
2639*a90b9d01SCy Schubert  *
2640*a90b9d01SCy Schubert  * See _wpa_supplicant_event_scan_results() for return values.
2641*a90b9d01SCy Schubert  */
wpas_select_network_from_last_scan(struct wpa_supplicant * wpa_s,int new_scan,int own_request,bool trigger_6ghz_scan,union wpa_event_data * data)26425b9c547cSRui Paulo static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
2643*a90b9d01SCy Schubert 					      int new_scan, int own_request,
2644*a90b9d01SCy Schubert 					      bool trigger_6ghz_scan,
2645*a90b9d01SCy Schubert 					      union wpa_event_data *data)
2646f05cddf9SRui Paulo {
2647f05cddf9SRui Paulo 	struct wpa_bss *selected;
2648f05cddf9SRui Paulo 	struct wpa_ssid *ssid = NULL;
2649325151a3SRui Paulo 	int time_to_reenable = wpas_reenabled_network_time(wpa_s);
2650325151a3SRui Paulo 
2651325151a3SRui Paulo 	if (time_to_reenable > 0) {
2652325151a3SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG,
2653325151a3SRui Paulo 			"Postpone network selection by %d seconds since all networks are disabled",
2654325151a3SRui Paulo 			time_to_reenable);
2655325151a3SRui Paulo 		eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2656325151a3SRui Paulo 		eloop_register_timeout(time_to_reenable, 0,
2657325151a3SRui Paulo 				       wpas_network_reenabled, wpa_s, NULL);
2658325151a3SRui Paulo 		return 0;
2659325151a3SRui Paulo 	}
2660f05cddf9SRui Paulo 
26615b9c547cSRui Paulo 	if (wpa_s->p2p_mgmt)
26625b9c547cSRui Paulo 		return 0; /* no normal connection on p2p_mgmt interface */
26635b9c547cSRui Paulo 
266485732ac8SCy Schubert 	wpa_s->owe_transition_search = 0;
2665*a90b9d01SCy Schubert #ifdef CONFIG_OWE
2666*a90b9d01SCy Schubert 	os_free(wpa_s->owe_trans_scan_freq);
2667*a90b9d01SCy Schubert 	wpa_s->owe_trans_scan_freq = NULL;
2668*a90b9d01SCy Schubert #endif /* CONFIG_OWE */
2669f05cddf9SRui Paulo 	selected = wpa_supplicant_pick_network(wpa_s, &ssid);
2670e28a4053SRui Paulo 
2671780fb4a2SCy Schubert #ifdef CONFIG_MESH
2672780fb4a2SCy Schubert 	if (wpa_s->ifmsh) {
2673780fb4a2SCy Schubert 		wpa_msg(wpa_s, MSG_INFO,
2674780fb4a2SCy Schubert 			"Avoiding join because we already joined a mesh group");
2675780fb4a2SCy Schubert 		return 0;
2676780fb4a2SCy Schubert 	}
2677780fb4a2SCy Schubert #endif /* CONFIG_MESH */
2678780fb4a2SCy Schubert 
2679e28a4053SRui Paulo 	if (selected) {
2680e28a4053SRui Paulo 		int skip;
2681f05cddf9SRui Paulo 		skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
2682f05cddf9SRui Paulo 		if (skip) {
26835b9c547cSRui Paulo 			if (new_scan)
2684f05cddf9SRui Paulo 				wpa_supplicant_rsn_preauth_scan_results(wpa_s);
2685f05cddf9SRui Paulo 			return 0;
2686f05cddf9SRui Paulo 		}
2687f05cddf9SRui Paulo 
2688c1d255d3SCy Schubert 		wpa_s->suitable_network++;
2689c1d255d3SCy Schubert 
2690780fb4a2SCy Schubert 		if (ssid != wpa_s->current_ssid &&
2691780fb4a2SCy Schubert 		    wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2692780fb4a2SCy Schubert 			wpa_s->own_disconnect_req = 1;
2693780fb4a2SCy Schubert 			wpa_supplicant_deauthenticate(
2694780fb4a2SCy Schubert 				wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2695780fb4a2SCy Schubert 		}
2696780fb4a2SCy Schubert 
2697f05cddf9SRui Paulo 		if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
2698f05cddf9SRui Paulo 			wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
2699f05cddf9SRui Paulo 			return -1;
2700f05cddf9SRui Paulo 		}
2701*a90b9d01SCy Schubert 		wpa_s->supp_pbc_active = false;
2702*a90b9d01SCy Schubert 
27035b9c547cSRui Paulo 		if (new_scan)
2704f05cddf9SRui Paulo 			wpa_supplicant_rsn_preauth_scan_results(wpa_s);
2705f05cddf9SRui Paulo 		/*
270685732ac8SCy Schubert 		 * Do not allow other virtual radios to trigger operations based
270785732ac8SCy Schubert 		 * on these scan results since we do not want them to start
270885732ac8SCy Schubert 		 * other associations at the same time.
2709f05cddf9SRui Paulo 		 */
2710f05cddf9SRui Paulo 		return 1;
2711e28a4053SRui Paulo 	} else {
2712c1d255d3SCy Schubert 		wpa_s->no_suitable_network++;
2713f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2714e28a4053SRui Paulo 		ssid = wpa_supplicant_pick_new_network(wpa_s);
2715e28a4053SRui Paulo 		if (ssid) {
2716f05cddf9SRui Paulo 			wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2717e28a4053SRui Paulo 			wpa_supplicant_associate(wpa_s, NULL, ssid);
27185b9c547cSRui Paulo 			if (new_scan)
2719f05cddf9SRui Paulo 				wpa_supplicant_rsn_preauth_scan_results(wpa_s);
27205b9c547cSRui Paulo 		} else if (own_request) {
2721*a90b9d01SCy Schubert 			if (wpa_s->support_6ghz && trigger_6ghz_scan && data &&
2722*a90b9d01SCy Schubert 			    wpas_trigger_6ghz_scan(wpa_s, data) < 0)
2723*a90b9d01SCy Schubert 				return 1;
2724*a90b9d01SCy Schubert 
27255b9c547cSRui Paulo 			/*
27265b9c547cSRui Paulo 			 * No SSID found. If SCAN results are as a result of
27275b9c547cSRui Paulo 			 * own scan request and not due to a scan request on
27285b9c547cSRui Paulo 			 * another shared interface, try another scan.
27295b9c547cSRui Paulo 			 */
2730f05cddf9SRui Paulo 			int timeout_sec = wpa_s->scan_interval;
2731e28a4053SRui Paulo 			int timeout_usec = 0;
2732f05cddf9SRui Paulo #ifdef CONFIG_P2P
27335b9c547cSRui Paulo 			int res;
27345b9c547cSRui Paulo 
27355b9c547cSRui Paulo 			res = wpas_p2p_scan_no_go_seen(wpa_s);
27365b9c547cSRui Paulo 			if (res == 2)
27375b9c547cSRui Paulo 				return 2;
27385b9c547cSRui Paulo 			if (res == 1)
2739f05cddf9SRui Paulo 				return 0;
2740f05cddf9SRui Paulo 
2741*a90b9d01SCy Schubert 			if (wpas_p2p_retry_limit_exceeded(wpa_s))
2742*a90b9d01SCy Schubert 				return 0;
2743*a90b9d01SCy Schubert 
27445b9c547cSRui Paulo 			if (wpa_s->p2p_in_provisioning ||
27455b9c547cSRui Paulo 			    wpa_s->show_group_started ||
27465b9c547cSRui Paulo 			    wpa_s->p2p_in_invitation) {
2747f05cddf9SRui Paulo 				/*
2748f05cddf9SRui Paulo 				 * Use shorter wait during P2P Provisioning
27495b9c547cSRui Paulo 				 * state and during P2P join-a-group operation
27505b9c547cSRui Paulo 				 * to speed up group formation.
2751f05cddf9SRui Paulo 				 */
2752f05cddf9SRui Paulo 				timeout_sec = 0;
2753f05cddf9SRui Paulo 				timeout_usec = 250000;
2754f05cddf9SRui Paulo 				wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2755f05cddf9SRui Paulo 							    timeout_usec);
2756f05cddf9SRui Paulo 				return 0;
2757f05cddf9SRui Paulo 			}
2758f05cddf9SRui Paulo #endif /* CONFIG_P2P */
2759f05cddf9SRui Paulo #ifdef CONFIG_INTERWORKING
2760f05cddf9SRui Paulo 			if (wpa_s->conf->auto_interworking &&
2761f05cddf9SRui Paulo 			    wpa_s->conf->interworking &&
2762f05cddf9SRui Paulo 			    wpa_s->conf->cred) {
2763f05cddf9SRui Paulo 				wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2764f05cddf9SRui Paulo 					"start ANQP fetch since no matching "
2765f05cddf9SRui Paulo 					"networks found");
2766f05cddf9SRui Paulo 				wpa_s->network_select = 1;
2767f05cddf9SRui Paulo 				wpa_s->auto_network_select = 1;
2768f05cddf9SRui Paulo 				interworking_start_fetch_anqp(wpa_s);
2769f05cddf9SRui Paulo 				return 1;
2770f05cddf9SRui Paulo 			}
2771f05cddf9SRui Paulo #endif /* CONFIG_INTERWORKING */
27725b9c547cSRui Paulo #ifdef CONFIG_WPS
27735b9c547cSRui Paulo 			if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
27745b9c547cSRui Paulo 				wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
27755b9c547cSRui Paulo 				timeout_sec = 0;
27765b9c547cSRui Paulo 				timeout_usec = 500000;
27775b9c547cSRui Paulo 				wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
27785b9c547cSRui Paulo 							    timeout_usec);
27795b9c547cSRui Paulo 				return 0;
27805b9c547cSRui Paulo 			}
27815b9c547cSRui Paulo #endif /* CONFIG_WPS */
278285732ac8SCy Schubert #ifdef CONFIG_OWE
278385732ac8SCy Schubert 			if (wpa_s->owe_transition_search) {
278485732ac8SCy Schubert 				wpa_dbg(wpa_s, MSG_DEBUG,
278585732ac8SCy Schubert 					"OWE: Use shorter wait during transition mode search");
278685732ac8SCy Schubert 				timeout_sec = 0;
278785732ac8SCy Schubert 				timeout_usec = 500000;
2788*a90b9d01SCy Schubert 				if (wpa_s->owe_trans_scan_freq) {
2789*a90b9d01SCy Schubert 					os_free(wpa_s->next_scan_freqs);
2790*a90b9d01SCy Schubert 					wpa_s->next_scan_freqs =
2791*a90b9d01SCy Schubert 						wpa_s->owe_trans_scan_freq;
2792*a90b9d01SCy Schubert 					wpa_s->owe_trans_scan_freq = NULL;
2793*a90b9d01SCy Schubert 					timeout_usec = 100000;
2794*a90b9d01SCy Schubert 				}
279585732ac8SCy Schubert 				wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
279685732ac8SCy Schubert 							    timeout_usec);
279785732ac8SCy Schubert 				return 0;
279885732ac8SCy Schubert 			}
279985732ac8SCy Schubert #endif /* CONFIG_OWE */
2800f05cddf9SRui Paulo 			if (wpa_supplicant_req_sched_scan(wpa_s))
2801e28a4053SRui Paulo 				wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2802e28a4053SRui Paulo 							    timeout_usec);
2803325151a3SRui Paulo 
2804325151a3SRui Paulo 			wpa_msg_ctrl(wpa_s, MSG_INFO,
2805325151a3SRui Paulo 				     WPA_EVENT_NETWORK_NOT_FOUND);
2806e28a4053SRui Paulo 		}
2807e28a4053SRui Paulo 	}
2808f05cddf9SRui Paulo 	return 0;
280939beb93cSSam Leffler }
2810f05cddf9SRui Paulo 
2811f05cddf9SRui Paulo 
wpa_supplicant_event_scan_results(struct wpa_supplicant * wpa_s,union wpa_event_data * data)28125b9c547cSRui Paulo static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2813f05cddf9SRui Paulo 					     union wpa_event_data *data)
2814f05cddf9SRui Paulo {
2815f05cddf9SRui Paulo 	struct wpa_supplicant *ifs;
28165b9c547cSRui Paulo 	int res;
2817f05cddf9SRui Paulo 
281885732ac8SCy Schubert 	res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
28195b9c547cSRui Paulo 	if (res == 2) {
28205b9c547cSRui Paulo 		/*
28215b9c547cSRui Paulo 		 * Interface may have been removed, so must not dereference
28225b9c547cSRui Paulo 		 * wpa_s after this.
28235b9c547cSRui Paulo 		 */
28245b9c547cSRui Paulo 		return 1;
28255b9c547cSRui Paulo 	}
282685732ac8SCy Schubert 
282785732ac8SCy Schubert 	if (res < 0) {
2828f05cddf9SRui Paulo 		/*
2829f05cddf9SRui Paulo 		 * If no scan results could be fetched, then no need to
2830f05cddf9SRui Paulo 		 * notify those interfaces that did not actually request
2831f05cddf9SRui Paulo 		 * this scan. Similarly, if scan results started a new operation on this
2832f05cddf9SRui Paulo 		 * interface, do not notify other interfaces to avoid concurrent
2833f05cddf9SRui Paulo 		 * operations during a connection attempt.
2834f05cddf9SRui Paulo 		 */
28355b9c547cSRui Paulo 		return 0;
2836f05cddf9SRui Paulo 	}
2837f05cddf9SRui Paulo 
2838f05cddf9SRui Paulo 	/*
28395b9c547cSRui Paulo 	 * Check other interfaces to see if they share the same radio. If
2840f05cddf9SRui Paulo 	 * so, they get updated with this same scan info.
2841f05cddf9SRui Paulo 	 */
28425b9c547cSRui Paulo 	dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
28435b9c547cSRui Paulo 			 radio_list) {
28445b9c547cSRui Paulo 		if (ifs != wpa_s) {
2845f05cddf9SRui Paulo 			wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2846f05cddf9SRui Paulo 				   "sibling", ifs->ifname);
284785732ac8SCy Schubert 			res = _wpa_supplicant_event_scan_results(ifs, data, 0,
284885732ac8SCy Schubert 								 res > 0);
284985732ac8SCy Schubert 			if (res < 0)
285085732ac8SCy Schubert 				return 0;
2851f05cddf9SRui Paulo 		}
2852f05cddf9SRui Paulo 	}
28535b9c547cSRui Paulo 
28545b9c547cSRui Paulo 	return 0;
2855f05cddf9SRui Paulo }
2856f05cddf9SRui Paulo 
285739beb93cSSam Leffler #endif /* CONFIG_NO_SCAN_PROCESSING */
285839beb93cSSam Leffler 
285939beb93cSSam Leffler 
wpa_supplicant_fast_associate(struct wpa_supplicant * wpa_s)28605b9c547cSRui Paulo int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
28615b9c547cSRui Paulo {
28625b9c547cSRui Paulo #ifdef CONFIG_NO_SCAN_PROCESSING
28635b9c547cSRui Paulo 	return -1;
28645b9c547cSRui Paulo #else /* CONFIG_NO_SCAN_PROCESSING */
28655b9c547cSRui Paulo 	struct os_reltime now;
28665b9c547cSRui Paulo 
286785732ac8SCy Schubert 	wpa_s->ignore_post_flush_scan_res = 0;
286885732ac8SCy Schubert 
2869325151a3SRui Paulo 	if (wpa_s->last_scan_res_used == 0)
28705b9c547cSRui Paulo 		return -1;
28715b9c547cSRui Paulo 
28725b9c547cSRui Paulo 	os_get_reltime(&now);
2873c1d255d3SCy Schubert 	if (os_reltime_expired(&now, &wpa_s->last_scan,
2874c1d255d3SCy Schubert 			       wpa_s->conf->scan_res_valid_for_connect)) {
28755b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
28765b9c547cSRui Paulo 		return -1;
2877*a90b9d01SCy Schubert 	} else if (wpa_s->crossed_6ghz_dom) {
2878*a90b9d01SCy Schubert 		wpa_printf(MSG_DEBUG, "Fast associate: Crossed 6 GHz domain");
2879*a90b9d01SCy Schubert 		return -1;
28805b9c547cSRui Paulo 	}
28815b9c547cSRui Paulo 
2882*a90b9d01SCy Schubert 	return wpas_select_network_from_last_scan(wpa_s, 0, 1, false, NULL);
28835b9c547cSRui Paulo #endif /* CONFIG_NO_SCAN_PROCESSING */
28845b9c547cSRui Paulo }
28855b9c547cSRui Paulo 
2886*a90b9d01SCy Schubert 
wpa_wps_supplicant_fast_associate(struct wpa_supplicant * wpa_s)2887*a90b9d01SCy Schubert int wpa_wps_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2888*a90b9d01SCy Schubert {
2889*a90b9d01SCy Schubert #ifdef CONFIG_NO_SCAN_PROCESSING
2890*a90b9d01SCy Schubert 	return -1;
2891*a90b9d01SCy Schubert #else /* CONFIG_NO_SCAN_PROCESSING */
2892*a90b9d01SCy Schubert 	return wpas_select_network_from_last_scan(wpa_s, 1, 1, false, NULL);
2893*a90b9d01SCy Schubert #endif /* CONFIG_NO_SCAN_PROCESSING */
2894*a90b9d01SCy Schubert }
2895*a90b9d01SCy Schubert 
2896*a90b9d01SCy Schubert 
2897f05cddf9SRui Paulo #ifdef CONFIG_WNM
2898f05cddf9SRui Paulo 
wnm_bss_keep_alive(void * eloop_ctx,void * sock_ctx)2899f05cddf9SRui Paulo static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2900f05cddf9SRui Paulo {
2901f05cddf9SRui Paulo 	struct wpa_supplicant *wpa_s = eloop_ctx;
2902f05cddf9SRui Paulo 
2903f05cddf9SRui Paulo 	if (wpa_s->wpa_state < WPA_ASSOCIATED)
2904f05cddf9SRui Paulo 		return;
2905f05cddf9SRui Paulo 
2906f05cddf9SRui Paulo 	if (!wpa_s->no_keep_alive) {
2907f05cddf9SRui Paulo 		wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2908f05cddf9SRui Paulo 			   MAC2STR(wpa_s->bssid));
2909f05cddf9SRui Paulo 		/* TODO: could skip this if normal data traffic has been sent */
2910f05cddf9SRui Paulo 		/* TODO: Consider using some more appropriate data frame for
2911f05cddf9SRui Paulo 		 * this */
2912f05cddf9SRui Paulo 		if (wpa_s->l2)
2913f05cddf9SRui Paulo 			l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2914f05cddf9SRui Paulo 				       (u8 *) "", 0);
2915f05cddf9SRui Paulo 	}
2916f05cddf9SRui Paulo 
2917f05cddf9SRui Paulo #ifdef CONFIG_SME
2918f05cddf9SRui Paulo 	if (wpa_s->sme.bss_max_idle_period) {
2919f05cddf9SRui Paulo 		unsigned int msec;
2920f05cddf9SRui Paulo 		msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
2921f05cddf9SRui Paulo 		if (msec > 100)
2922f05cddf9SRui Paulo 			msec -= 100;
2923f05cddf9SRui Paulo 		eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2924f05cddf9SRui Paulo 				       wnm_bss_keep_alive, wpa_s, NULL);
2925f05cddf9SRui Paulo 	}
2926f05cddf9SRui Paulo #endif /* CONFIG_SME */
2927f05cddf9SRui Paulo }
2928f05cddf9SRui Paulo 
2929f05cddf9SRui Paulo 
wnm_process_assoc_resp(struct wpa_supplicant * wpa_s,const u8 * ies,size_t ies_len)2930f05cddf9SRui Paulo static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
2931f05cddf9SRui Paulo 				   const u8 *ies, size_t ies_len)
2932f05cddf9SRui Paulo {
2933f05cddf9SRui Paulo 	struct ieee802_11_elems elems;
2934f05cddf9SRui Paulo 
2935f05cddf9SRui Paulo 	if (ies == NULL)
2936f05cddf9SRui Paulo 		return;
2937f05cddf9SRui Paulo 
2938f05cddf9SRui Paulo 	if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
2939f05cddf9SRui Paulo 		return;
2940f05cddf9SRui Paulo 
2941f05cddf9SRui Paulo #ifdef CONFIG_SME
2942f05cddf9SRui Paulo 	if (elems.bss_max_idle_period) {
2943f05cddf9SRui Paulo 		unsigned int msec;
2944f05cddf9SRui Paulo 		wpa_s->sme.bss_max_idle_period =
2945f05cddf9SRui Paulo 			WPA_GET_LE16(elems.bss_max_idle_period);
2946f05cddf9SRui Paulo 		wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
2947f05cddf9SRui Paulo 			   "TU)%s", wpa_s->sme.bss_max_idle_period,
2948f05cddf9SRui Paulo 			   (elems.bss_max_idle_period[2] & 0x01) ?
2949f05cddf9SRui Paulo 			   " (protected keep-live required)" : "");
2950f05cddf9SRui Paulo 		if (wpa_s->sme.bss_max_idle_period == 0)
2951f05cddf9SRui Paulo 			wpa_s->sme.bss_max_idle_period = 1;
2952f05cddf9SRui Paulo 		if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
2953f05cddf9SRui Paulo 			eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2954f05cddf9SRui Paulo 			 /* msec times 1000 */
2955f05cddf9SRui Paulo 			msec = wpa_s->sme.bss_max_idle_period * 1024;
2956f05cddf9SRui Paulo 			if (msec > 100)
2957f05cddf9SRui Paulo 				msec -= 100;
2958f05cddf9SRui Paulo 			eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
2959f05cddf9SRui Paulo 					       wnm_bss_keep_alive, wpa_s,
2960f05cddf9SRui Paulo 					       NULL);
2961f05cddf9SRui Paulo 		}
2962*a90b9d01SCy Schubert 	} else {
2963*a90b9d01SCy Schubert 		wpa_s->sme.bss_max_idle_period = 0;
2964f05cddf9SRui Paulo 	}
2965f05cddf9SRui Paulo #endif /* CONFIG_SME */
2966f05cddf9SRui Paulo }
2967f05cddf9SRui Paulo 
2968f05cddf9SRui Paulo #endif /* CONFIG_WNM */
2969f05cddf9SRui Paulo 
2970f05cddf9SRui Paulo 
wnm_bss_keep_alive_deinit(struct wpa_supplicant * wpa_s)2971f05cddf9SRui Paulo void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
2972f05cddf9SRui Paulo {
2973f05cddf9SRui Paulo #ifdef CONFIG_WNM
2974f05cddf9SRui Paulo 	eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
2975f05cddf9SRui Paulo #endif /* CONFIG_WNM */
2976f05cddf9SRui Paulo }
2977f05cddf9SRui Paulo 
2978f05cddf9SRui Paulo 
wpas_qos_map_set(struct wpa_supplicant * wpa_s,const u8 * qos_map,size_t len)29795b9c547cSRui Paulo static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
29805b9c547cSRui Paulo 			    size_t len)
29815b9c547cSRui Paulo {
29825b9c547cSRui Paulo 	int res;
29835b9c547cSRui Paulo 
29845b9c547cSRui Paulo 	wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
29855b9c547cSRui Paulo 	res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
29865b9c547cSRui Paulo 	if (res) {
29875b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
29885b9c547cSRui Paulo 	}
29895b9c547cSRui Paulo 
29905b9c547cSRui Paulo 	return res;
29915b9c547cSRui Paulo }
29925b9c547cSRui Paulo 
29935b9c547cSRui Paulo 
interworking_process_assoc_resp(struct wpa_supplicant * wpa_s,const u8 * ies,size_t ies_len)29945b9c547cSRui Paulo static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
29955b9c547cSRui Paulo 					    const u8 *ies, size_t ies_len)
29965b9c547cSRui Paulo {
29975b9c547cSRui Paulo 	struct ieee802_11_elems elems;
29985b9c547cSRui Paulo 
29995b9c547cSRui Paulo 	if (ies == NULL)
30005b9c547cSRui Paulo 		return;
30015b9c547cSRui Paulo 
30025b9c547cSRui Paulo 	if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
30035b9c547cSRui Paulo 		return;
30045b9c547cSRui Paulo 
30055b9c547cSRui Paulo 	if (elems.qos_map_set) {
30065b9c547cSRui Paulo 		wpas_qos_map_set(wpa_s, elems.qos_map_set,
30075b9c547cSRui Paulo 				 elems.qos_map_set_len);
30085b9c547cSRui Paulo 	}
30095b9c547cSRui Paulo }
30105b9c547cSRui Paulo 
3011*a90b9d01SCy Schubert 
wpa_supplicant_set_4addr_mode(struct wpa_supplicant * wpa_s)3012*a90b9d01SCy Schubert static void wpa_supplicant_set_4addr_mode(struct wpa_supplicant *wpa_s)
3013*a90b9d01SCy Schubert {
3014*a90b9d01SCy Schubert 	if (wpa_s->enabled_4addr_mode) {
3015*a90b9d01SCy Schubert 		wpa_printf(MSG_DEBUG, "4addr mode already set");
3016*a90b9d01SCy Schubert 		return;
3017*a90b9d01SCy Schubert 	}
3018*a90b9d01SCy Schubert 
3019*a90b9d01SCy Schubert 	if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
3020*a90b9d01SCy Schubert 		wpa_msg(wpa_s, MSG_ERROR, "Failed to set 4addr mode");
3021*a90b9d01SCy Schubert 		goto fail;
3022*a90b9d01SCy Schubert 	}
3023*a90b9d01SCy Schubert 	wpa_s->enabled_4addr_mode = 1;
3024*a90b9d01SCy Schubert 	wpa_msg(wpa_s, MSG_INFO, "Successfully set 4addr mode");
3025*a90b9d01SCy Schubert 	return;
3026*a90b9d01SCy Schubert 
3027*a90b9d01SCy Schubert fail:
3028*a90b9d01SCy Schubert 	wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3029*a90b9d01SCy Schubert }
30305b9c547cSRui Paulo 
30315b9c547cSRui Paulo 
multi_ap_process_assoc_resp(struct wpa_supplicant * wpa_s,const u8 * ies,size_t ies_len)30324bc52338SCy Schubert static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
30334bc52338SCy Schubert 					const u8 *ies, size_t ies_len)
30344bc52338SCy Schubert {
30354bc52338SCy Schubert 	struct ieee802_11_elems elems;
3036*a90b9d01SCy Schubert 	struct multi_ap_params multi_ap;
3037*a90b9d01SCy Schubert 	u16 status;
30384bc52338SCy Schubert 
3039c1d255d3SCy Schubert 	wpa_s->multi_ap_ie = 0;
30404bc52338SCy Schubert 
3041c1d255d3SCy Schubert 	if (!ies ||
3042c1d255d3SCy Schubert 	    ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
3043*a90b9d01SCy Schubert 	    !elems.multi_ap)
3044c1d255d3SCy Schubert 		return;
30454bc52338SCy Schubert 
3046*a90b9d01SCy Schubert 	status = check_multi_ap_ie(elems.multi_ap + 4, elems.multi_ap_len - 4,
3047*a90b9d01SCy Schubert 				   &multi_ap);
3048*a90b9d01SCy Schubert 	if (status != WLAN_STATUS_SUCCESS)
3049c1d255d3SCy Schubert 		return;
3050c1d255d3SCy Schubert 
3051*a90b9d01SCy Schubert 	wpa_s->multi_ap_backhaul = !!(multi_ap.capability &
3052*a90b9d01SCy Schubert 				      MULTI_AP_BACKHAUL_BSS);
3053*a90b9d01SCy Schubert 	wpa_s->multi_ap_fronthaul = !!(multi_ap.capability &
3054c1d255d3SCy Schubert 				       MULTI_AP_FRONTHAUL_BSS);
3055c1d255d3SCy Schubert 	wpa_s->multi_ap_ie = 1;
3056c1d255d3SCy Schubert }
3057c1d255d3SCy Schubert 
3058c1d255d3SCy Schubert 
multi_ap_set_4addr_mode(struct wpa_supplicant * wpa_s)3059c1d255d3SCy Schubert static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
3060c1d255d3SCy Schubert {
3061c1d255d3SCy Schubert 	if (!wpa_s->current_ssid ||
3062c1d255d3SCy Schubert 	    !wpa_s->current_ssid->multi_ap_backhaul_sta)
3063c1d255d3SCy Schubert 		return;
3064c1d255d3SCy Schubert 
3065c1d255d3SCy Schubert 	if (!wpa_s->multi_ap_ie) {
3066c1d255d3SCy Schubert 		wpa_printf(MSG_INFO,
3067c1d255d3SCy Schubert 			   "AP does not include valid Multi-AP element");
30684bc52338SCy Schubert 		goto fail;
30694bc52338SCy Schubert 	}
30704bc52338SCy Schubert 
3071c1d255d3SCy Schubert 	if (!wpa_s->multi_ap_backhaul) {
3072c1d255d3SCy Schubert 		if (wpa_s->multi_ap_fronthaul &&
30734bc52338SCy Schubert 		    wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
30744bc52338SCy Schubert 			wpa_printf(MSG_INFO,
30754bc52338SCy Schubert 				   "WPS active, accepting fronthaul-only BSS");
30764bc52338SCy Schubert 			/* Don't set 4addr mode in this case, so just return */
30774bc52338SCy Schubert 			return;
30784bc52338SCy Schubert 		}
30794bc52338SCy Schubert 		wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
30804bc52338SCy Schubert 		goto fail;
30814bc52338SCy Schubert 	}
30824bc52338SCy Schubert 
3083*a90b9d01SCy Schubert 	wpa_supplicant_set_4addr_mode(wpa_s);
30844bc52338SCy Schubert 	return;
30854bc52338SCy Schubert 
30864bc52338SCy Schubert fail:
30874bc52338SCy Schubert 	wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
30884bc52338SCy Schubert }
30894bc52338SCy Schubert 
30904bc52338SCy Schubert 
3091780fb4a2SCy Schubert #ifdef CONFIG_FST
wpas_fst_update_mbie(struct wpa_supplicant * wpa_s,const u8 * ie,size_t ie_len)3092780fb4a2SCy Schubert static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
3093780fb4a2SCy Schubert 				const u8 *ie, size_t ie_len)
3094780fb4a2SCy Schubert {
3095780fb4a2SCy Schubert 	struct mb_ies_info mb_ies;
3096780fb4a2SCy Schubert 
3097780fb4a2SCy Schubert 	if (!ie || !ie_len || !wpa_s->fst)
3098780fb4a2SCy Schubert 	    return -ENOENT;
3099780fb4a2SCy Schubert 
3100780fb4a2SCy Schubert 	os_memset(&mb_ies, 0, sizeof(mb_ies));
3101780fb4a2SCy Schubert 
3102780fb4a2SCy Schubert 	while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
3103780fb4a2SCy Schubert 		size_t len;
3104780fb4a2SCy Schubert 
3105780fb4a2SCy Schubert 		len = 2 + ie[1];
3106780fb4a2SCy Schubert 		if (len > ie_len) {
3107780fb4a2SCy Schubert 			wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
3108780fb4a2SCy Schubert 				    ie, ie_len);
3109780fb4a2SCy Schubert 			break;
3110780fb4a2SCy Schubert 		}
3111780fb4a2SCy Schubert 
3112780fb4a2SCy Schubert 		if (ie[0] == WLAN_EID_MULTI_BAND) {
3113780fb4a2SCy Schubert 			wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
3114780fb4a2SCy Schubert 				   (unsigned int) len);
3115780fb4a2SCy Schubert 			mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
3116780fb4a2SCy Schubert 			mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
3117780fb4a2SCy Schubert 			mb_ies.nof_ies++;
3118780fb4a2SCy Schubert 		}
3119780fb4a2SCy Schubert 
3120780fb4a2SCy Schubert 		ie_len -= len;
3121780fb4a2SCy Schubert 		ie += len;
3122780fb4a2SCy Schubert 	}
3123780fb4a2SCy Schubert 
3124780fb4a2SCy Schubert 	if (mb_ies.nof_ies > 0) {
3125780fb4a2SCy Schubert 		wpabuf_free(wpa_s->received_mb_ies);
3126780fb4a2SCy Schubert 		wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
3127780fb4a2SCy Schubert 		return 0;
3128780fb4a2SCy Schubert 	}
3129780fb4a2SCy Schubert 
3130780fb4a2SCy Schubert 	return -ENOENT;
3131780fb4a2SCy Schubert }
3132780fb4a2SCy Schubert #endif /* CONFIG_FST */
3133780fb4a2SCy Schubert 
3134780fb4a2SCy Schubert 
wpa_supplicant_use_own_rsne_params(struct wpa_supplicant * wpa_s,union wpa_event_data * data)31354b72b91aSCy Schubert static int wpa_supplicant_use_own_rsne_params(struct wpa_supplicant *wpa_s,
31364b72b91aSCy Schubert 					      union wpa_event_data *data)
31374b72b91aSCy Schubert {
31384b72b91aSCy Schubert 	int sel;
31394b72b91aSCy Schubert 	const u8 *p;
31404b72b91aSCy Schubert 	int l, len;
31414b72b91aSCy Schubert 	bool found = false;
31424b72b91aSCy Schubert 	struct wpa_ie_data ie;
31434b72b91aSCy Schubert 	struct wpa_ssid *ssid = wpa_s->current_ssid;
31444b72b91aSCy Schubert 	struct wpa_bss *bss = wpa_s->current_bss;
31454b72b91aSCy Schubert 	int pmf;
31464b72b91aSCy Schubert 
31474b72b91aSCy Schubert 	if (!ssid)
31484b72b91aSCy Schubert 		return 0;
31494b72b91aSCy Schubert 
31504b72b91aSCy Schubert 	p = data->assoc_info.req_ies;
31514b72b91aSCy Schubert 	l = data->assoc_info.req_ies_len;
31524b72b91aSCy Schubert 
31534b72b91aSCy Schubert 	while (p && l >= 2) {
31544b72b91aSCy Schubert 		len = p[1] + 2;
31554b72b91aSCy Schubert 		if (len > l) {
31564b72b91aSCy Schubert 			wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
31574b72b91aSCy Schubert 				    p, l);
31584b72b91aSCy Schubert 			break;
31594b72b91aSCy Schubert 		}
31604b72b91aSCy Schubert 		if (((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
31614b72b91aSCy Schubert 		      (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
31624b72b91aSCy Schubert 		     (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
31634b72b91aSCy Schubert 		      (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
31644b72b91aSCy Schubert 		     (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
31654b72b91aSCy Schubert 			found = true;
31664b72b91aSCy Schubert 			break;
31674b72b91aSCy Schubert 		}
31684b72b91aSCy Schubert 		l -= len;
31694b72b91aSCy Schubert 		p += len;
31704b72b91aSCy Schubert 	}
31714b72b91aSCy Schubert 
3172*a90b9d01SCy Schubert 	if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0) {
3173*a90b9d01SCy Schubert 		wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV, 0);
31744b72b91aSCy Schubert 		return 0;
3175*a90b9d01SCy Schubert 	}
31764b72b91aSCy Schubert 
31774b72b91aSCy Schubert 	wpa_hexdump(MSG_DEBUG,
31784b72b91aSCy Schubert 		    "WPA: Update cipher suite selection based on IEs in driver-generated WPA/RSNE in AssocReq",
31794b72b91aSCy Schubert 		    p, l);
31804b72b91aSCy Schubert 
31814b72b91aSCy Schubert 	/* Update proto from (Re)Association Request frame info */
31824b72b91aSCy Schubert 	wpa_s->wpa_proto = ie.proto;
31834b72b91aSCy Schubert 	wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, wpa_s->wpa_proto);
31844b72b91aSCy Schubert 	wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
31854b72b91aSCy Schubert 			 !!(wpa_s->wpa_proto &
31864b72b91aSCy Schubert 			    (WPA_PROTO_RSN | WPA_PROTO_OSEN)));
31874b72b91aSCy Schubert 
31884b72b91aSCy Schubert 	/* Update AKMP suite from (Re)Association Request frame info */
31894b72b91aSCy Schubert 	sel = ie.key_mgmt;
31904b72b91aSCy Schubert 	if (ssid->key_mgmt)
31914b72b91aSCy Schubert 		sel &= ssid->key_mgmt;
31924b72b91aSCy Schubert 
31934b72b91aSCy Schubert 	wpa_dbg(wpa_s, MSG_DEBUG,
31944b72b91aSCy Schubert 		"WPA: AP key_mgmt 0x%x network key_mgmt 0x%x; available key_mgmt 0x%x",
31954b72b91aSCy Schubert 		ie.key_mgmt, ssid->key_mgmt, sel);
31964b72b91aSCy Schubert 	if (ie.key_mgmt && !sel) {
31974b72b91aSCy Schubert 		wpa_supplicant_deauthenticate(
31984b72b91aSCy Schubert 			wpa_s, WLAN_REASON_AKMP_NOT_VALID);
31994b72b91aSCy Schubert 		return -1;
32004b72b91aSCy Schubert 	}
32014b72b91aSCy Schubert 
3202*a90b9d01SCy Schubert #ifdef CONFIG_OCV
3203*a90b9d01SCy Schubert 	if (((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) ||
3204*a90b9d01SCy Schubert 	     (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV)) && ssid->ocv)
3205*a90b9d01SCy Schubert 		wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV,
3206*a90b9d01SCy Schubert 				 !!(ie.capabilities & WPA_CAPABILITY_OCVC));
3207*a90b9d01SCy Schubert #endif /* CONFIG_OCV */
3208*a90b9d01SCy Schubert 
3209*a90b9d01SCy Schubert 	/*
3210*a90b9d01SCy Schubert 	 * Update PMK in wpa_sm and the driver if roamed to WPA/WPA2 PSK from a
3211*a90b9d01SCy Schubert 	 * different AKM.
3212*a90b9d01SCy Schubert 	 */
3213*a90b9d01SCy Schubert 	if (wpa_s->key_mgmt != ie.key_mgmt &&
3214*a90b9d01SCy Schubert 	    wpa_key_mgmt_wpa_psk_no_sae(ie.key_mgmt)) {
3215*a90b9d01SCy Schubert 		if (!ssid->psk_set) {
3216*a90b9d01SCy Schubert 			wpa_dbg(wpa_s, MSG_INFO,
3217*a90b9d01SCy Schubert 				"No PSK available for association");
3218*a90b9d01SCy Schubert 			wpas_auth_failed(wpa_s, "NO_PSK_AVAILABLE", NULL);
3219*a90b9d01SCy Schubert 			return -1;
3220*a90b9d01SCy Schubert 		}
3221*a90b9d01SCy Schubert 
3222*a90b9d01SCy Schubert 		wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN, NULL, NULL);
3223*a90b9d01SCy Schubert 		if (wpa_s->conf->key_mgmt_offload &&
3224*a90b9d01SCy Schubert 		    (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD) &&
3225*a90b9d01SCy Schubert 		    wpa_drv_set_key(wpa_s, -1, 0, NULL, 0, 0, NULL, 0,
3226*a90b9d01SCy Schubert 				    ssid->psk, PMK_LEN, KEY_FLAG_PMK))
3227*a90b9d01SCy Schubert 			wpa_dbg(wpa_s, MSG_ERROR,
3228*a90b9d01SCy Schubert 				"WPA: Cannot set PMK for key management offload");
3229*a90b9d01SCy Schubert 	}
3230*a90b9d01SCy Schubert 
32314b72b91aSCy Schubert 	wpa_s->key_mgmt = ie.key_mgmt;
32324b72b91aSCy Schubert 	wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
32334b72b91aSCy Schubert 	wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT %s and proto %d",
32344b72b91aSCy Schubert 		wpa_key_mgmt_txt(wpa_s->key_mgmt, wpa_s->wpa_proto),
32354b72b91aSCy Schubert 		wpa_s->wpa_proto);
32364b72b91aSCy Schubert 
32374b72b91aSCy Schubert 	/* Update pairwise cipher from (Re)Association Request frame info */
32384b72b91aSCy Schubert 	sel = ie.pairwise_cipher;
32394b72b91aSCy Schubert 	if (ssid->pairwise_cipher)
32404b72b91aSCy Schubert 		sel &= ssid->pairwise_cipher;
32414b72b91aSCy Schubert 
32424b72b91aSCy Schubert 	wpa_dbg(wpa_s, MSG_DEBUG,
32434b72b91aSCy Schubert 		"WPA: AP pairwise cipher 0x%x network pairwise cipher 0x%x; available pairwise cipher 0x%x",
32444b72b91aSCy Schubert 		ie.pairwise_cipher, ssid->pairwise_cipher, sel);
32454b72b91aSCy Schubert 	if (ie.pairwise_cipher && !sel) {
32464b72b91aSCy Schubert 		wpa_supplicant_deauthenticate(
32474b72b91aSCy Schubert 			wpa_s, WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID);
32484b72b91aSCy Schubert 		return -1;
32494b72b91aSCy Schubert 	}
32504b72b91aSCy Schubert 
32514b72b91aSCy Schubert 	wpa_s->pairwise_cipher = ie.pairwise_cipher;
32524b72b91aSCy Schubert 	wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
32534b72b91aSCy Schubert 			 wpa_s->pairwise_cipher);
32544b72b91aSCy Schubert 	wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s",
32554b72b91aSCy Schubert 		wpa_cipher_txt(wpa_s->pairwise_cipher));
32564b72b91aSCy Schubert 
32574b72b91aSCy Schubert 	/* Update other parameters based on AP's WPA IE/RSNE, if available */
32584b72b91aSCy Schubert 	if (!bss) {
32594b72b91aSCy Schubert 		wpa_dbg(wpa_s, MSG_DEBUG,
32604b72b91aSCy Schubert 			"WPA: current_bss == NULL - skip AP IE check");
32614b72b91aSCy Schubert 		return 0;
32624b72b91aSCy Schubert 	}
32634b72b91aSCy Schubert 
32644b72b91aSCy Schubert 	/* Update GTK and IGTK from AP's RSNE */
32654b72b91aSCy Schubert 	found = false;
32664b72b91aSCy Schubert 
32674b72b91aSCy Schubert 	if (wpa_s->wpa_proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) {
32684b72b91aSCy Schubert 		const u8 *bss_rsn;
32694b72b91aSCy Schubert 
32704b72b91aSCy Schubert 		bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
32714b72b91aSCy Schubert 		if (bss_rsn) {
32724b72b91aSCy Schubert 			p = bss_rsn;
32734b72b91aSCy Schubert 			len = 2 + bss_rsn[1];
32744b72b91aSCy Schubert 			found = true;
32754b72b91aSCy Schubert 		}
32764b72b91aSCy Schubert 	} else if (wpa_s->wpa_proto & WPA_PROTO_WPA) {
32774b72b91aSCy Schubert 		const u8 *bss_wpa;
32784b72b91aSCy Schubert 
32794b72b91aSCy Schubert 		bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
32804b72b91aSCy Schubert 		if (bss_wpa) {
32814b72b91aSCy Schubert 			p = bss_wpa;
32824b72b91aSCy Schubert 			len = 2 + bss_wpa[1];
32834b72b91aSCy Schubert 			found = true;
32844b72b91aSCy Schubert 		}
32854b72b91aSCy Schubert 	}
32864b72b91aSCy Schubert 
32874b72b91aSCy Schubert 	if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
32884b72b91aSCy Schubert 		return 0;
32894b72b91aSCy Schubert 
32904b72b91aSCy Schubert 	pmf = wpas_get_ssid_pmf(wpa_s, ssid);
32914b72b91aSCy Schubert 	if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
32924b72b91aSCy Schubert 	    pmf == MGMT_FRAME_PROTECTION_REQUIRED) {
32934b72b91aSCy Schubert 		/* AP does not support MFP, local configuration requires it */
32944b72b91aSCy Schubert 		wpa_supplicant_deauthenticate(
32954b72b91aSCy Schubert 			wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
32964b72b91aSCy Schubert 		return -1;
32974b72b91aSCy Schubert 	}
32984b72b91aSCy Schubert 	if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
32994b72b91aSCy Schubert 	    pmf == NO_MGMT_FRAME_PROTECTION) {
33004b72b91aSCy Schubert 		/* AP requires MFP, local configuration disables it */
33014b72b91aSCy Schubert 		wpa_supplicant_deauthenticate(
33024b72b91aSCy Schubert 			wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
33034b72b91aSCy Schubert 		return -1;
33044b72b91aSCy Schubert 	}
33054b72b91aSCy Schubert 
33064b72b91aSCy Schubert 	/* Update PMF from local configuration now that MFP validation was done
33074b72b91aSCy Schubert 	 * above */
33084b72b91aSCy Schubert 	wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, pmf);
33094b72b91aSCy Schubert 
33104b72b91aSCy Schubert 	/* Update GTK from AP's RSNE */
33114b72b91aSCy Schubert 	sel = ie.group_cipher;
33124b72b91aSCy Schubert 	if (ssid->group_cipher)
33134b72b91aSCy Schubert 		sel &= ssid->group_cipher;
33144b72b91aSCy Schubert 
33154b72b91aSCy Schubert 	wpa_dbg(wpa_s, MSG_DEBUG,
33164b72b91aSCy Schubert 		"WPA: AP group cipher 0x%x network group cipher 0x%x; available group cipher 0x%x",
33174b72b91aSCy Schubert 		ie.group_cipher, ssid->group_cipher, sel);
33184b72b91aSCy Schubert 	if (ie.group_cipher && !sel) {
33194b72b91aSCy Schubert 		wpa_supplicant_deauthenticate(
33204b72b91aSCy Schubert 			wpa_s, WLAN_REASON_GROUP_CIPHER_NOT_VALID);
33214b72b91aSCy Schubert 		return -1;
33224b72b91aSCy Schubert 	}
33234b72b91aSCy Schubert 
33244b72b91aSCy Schubert 	wpa_s->group_cipher = ie.group_cipher;
33254b72b91aSCy Schubert 	wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
33264b72b91aSCy Schubert 	wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s",
33274b72b91aSCy Schubert 		wpa_cipher_txt(wpa_s->group_cipher));
33284b72b91aSCy Schubert 
33294b72b91aSCy Schubert 	/* Update IGTK from AP RSN IE */
33304b72b91aSCy Schubert 	sel = ie.mgmt_group_cipher;
33314b72b91aSCy Schubert 	if (ssid->group_mgmt_cipher)
33324b72b91aSCy Schubert 		sel &= ssid->group_mgmt_cipher;
33334b72b91aSCy Schubert 
33344b72b91aSCy Schubert 	wpa_dbg(wpa_s, MSG_DEBUG,
33354b72b91aSCy Schubert 		"WPA: AP mgmt_group_cipher 0x%x network mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x",
33364b72b91aSCy Schubert 		ie.mgmt_group_cipher, ssid->group_mgmt_cipher, sel);
33374b72b91aSCy Schubert 
33384b72b91aSCy Schubert 	if (pmf == NO_MGMT_FRAME_PROTECTION ||
33394b72b91aSCy Schubert 	    !(ie.capabilities & WPA_CAPABILITY_MFPC)) {
33404b72b91aSCy Schubert 		wpa_dbg(wpa_s, MSG_DEBUG,
33414b72b91aSCy Schubert 			"WPA: STA/AP is not MFP capable; AP RSNE caps 0x%x",
33424b72b91aSCy Schubert 			ie.capabilities);
33434b72b91aSCy Schubert 		ie.mgmt_group_cipher = 0;
33444b72b91aSCy Schubert 	}
33454b72b91aSCy Schubert 
33464b72b91aSCy Schubert 	if (ie.mgmt_group_cipher && !sel) {
33474b72b91aSCy Schubert 		wpa_supplicant_deauthenticate(
33484b72b91aSCy Schubert 			wpa_s, WLAN_REASON_CIPHER_SUITE_REJECTED);
33494b72b91aSCy Schubert 		return -1;
33504b72b91aSCy Schubert 	}
33514b72b91aSCy Schubert 
33524b72b91aSCy Schubert 	wpa_s->mgmt_group_cipher = ie.mgmt_group_cipher;
33534b72b91aSCy Schubert 	wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
33544b72b91aSCy Schubert 			 wpa_s->mgmt_group_cipher);
33554b72b91aSCy Schubert 	if (wpa_s->mgmt_group_cipher)
33564b72b91aSCy Schubert 		wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher %s",
33574b72b91aSCy Schubert 			wpa_cipher_txt(wpa_s->mgmt_group_cipher));
33584b72b91aSCy Schubert 	else
33594b72b91aSCy Schubert 		wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
33604b72b91aSCy Schubert 
33614b72b91aSCy Schubert 	return 0;
33624b72b91aSCy Schubert }
33634b72b91aSCy Schubert 
33644b72b91aSCy Schubert 
wpa_supplicant_event_associnfo(struct wpa_supplicant * wpa_s,union wpa_event_data * data)3365e28a4053SRui Paulo static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
336639beb93cSSam Leffler 					  union wpa_event_data *data)
336739beb93cSSam Leffler {
3368c1d255d3SCy Schubert 	int l, len, found = 0, found_x = 0, wpa_found, rsn_found;
3369e28a4053SRui Paulo 	const u8 *p;
33705b9c547cSRui Paulo 	u8 bssid[ETH_ALEN];
3371c1d255d3SCy Schubert 	bool bssid_known;
337239beb93cSSam Leffler 
3373f05cddf9SRui Paulo 	wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
3374*a90b9d01SCy Schubert 	wpa_s->ssid_verified = false;
3375*a90b9d01SCy Schubert 	wpa_s->bigtk_set = false;
3376*a90b9d01SCy Schubert #ifdef CONFIG_SAE
3377*a90b9d01SCy Schubert #ifdef CONFIG_SME
3378*a90b9d01SCy Schubert 	/* SAE H2E binds the SSID into PT and that verifies the SSID
3379*a90b9d01SCy Schubert 	 * implicitly. */
3380*a90b9d01SCy Schubert 	if (wpa_s->sme.sae.state == SAE_ACCEPTED && wpa_s->sme.sae.h2e)
3381*a90b9d01SCy Schubert 		wpa_s->ssid_verified = true;
3382*a90b9d01SCy Schubert #endif /* CONFIG_SME */
3383*a90b9d01SCy Schubert #endif /* CONFIG_SAE */
3384c1d255d3SCy Schubert 	bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0;
338539beb93cSSam Leffler 	if (data->assoc_info.req_ies)
338639beb93cSSam Leffler 		wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
338739beb93cSSam Leffler 			    data->assoc_info.req_ies_len);
3388f05cddf9SRui Paulo 	if (data->assoc_info.resp_ies) {
338939beb93cSSam Leffler 		wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
339039beb93cSSam Leffler 			    data->assoc_info.resp_ies_len);
3391f05cddf9SRui Paulo #ifdef CONFIG_TDLS
3392f05cddf9SRui Paulo 		wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
3393f05cddf9SRui Paulo 					data->assoc_info.resp_ies_len);
3394f05cddf9SRui Paulo #endif /* CONFIG_TDLS */
3395f05cddf9SRui Paulo #ifdef CONFIG_WNM
3396f05cddf9SRui Paulo 		wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3397f05cddf9SRui Paulo 				       data->assoc_info.resp_ies_len);
3398f05cddf9SRui Paulo #endif /* CONFIG_WNM */
33995b9c547cSRui Paulo 		interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
34005b9c547cSRui Paulo 						data->assoc_info.resp_ies_len);
340185732ac8SCy Schubert 		if (wpa_s->hw_capab == CAPAB_VHT &&
340285732ac8SCy Schubert 		    get_ie(data->assoc_info.resp_ies,
340385732ac8SCy Schubert 			   data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
340485732ac8SCy Schubert 			wpa_s->ieee80211ac = 1;
34054bc52338SCy Schubert 
34064bc52338SCy Schubert 		multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
34074bc52338SCy Schubert 					    data->assoc_info.resp_ies_len);
3408f05cddf9SRui Paulo 	}
340939beb93cSSam Leffler 	if (data->assoc_info.beacon_ies)
341039beb93cSSam Leffler 		wpa_hexdump(MSG_DEBUG, "beacon_ies",
341139beb93cSSam Leffler 			    data->assoc_info.beacon_ies,
341239beb93cSSam Leffler 			    data->assoc_info.beacon_ies_len);
3413e28a4053SRui Paulo 	if (data->assoc_info.freq)
3414f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
3415f05cddf9SRui Paulo 			data->assoc_info.freq);
341639beb93cSSam Leffler 
34174bc52338SCy Schubert 	wpa_s->connection_set = 0;
34184bc52338SCy Schubert 	if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
34194bc52338SCy Schubert 		struct ieee802_11_elems req_elems, resp_elems;
34204bc52338SCy Schubert 
34214bc52338SCy Schubert 		if (ieee802_11_parse_elems(data->assoc_info.req_ies,
34224bc52338SCy Schubert 					   data->assoc_info.req_ies_len,
34234bc52338SCy Schubert 					   &req_elems, 0) != ParseFailed &&
34244bc52338SCy Schubert 		    ieee802_11_parse_elems(data->assoc_info.resp_ies,
34254bc52338SCy Schubert 					   data->assoc_info.resp_ies_len,
34264bc52338SCy Schubert 					   &resp_elems, 0) != ParseFailed) {
34274bc52338SCy Schubert 			wpa_s->connection_set = 1;
34284bc52338SCy Schubert 			wpa_s->connection_ht = req_elems.ht_capabilities &&
34294bc52338SCy Schubert 				resp_elems.ht_capabilities;
3430c1d255d3SCy Schubert 			/* Do not include subset of VHT on 2.4 GHz vendor
3431c1d255d3SCy Schubert 			 * extension in consideration for reporting VHT
3432c1d255d3SCy Schubert 			 * association. */
34334bc52338SCy Schubert 			wpa_s->connection_vht = req_elems.vht_capabilities &&
3434c1d255d3SCy Schubert 				resp_elems.vht_capabilities &&
3435c1d255d3SCy Schubert 				(!data->assoc_info.freq ||
3436c1d255d3SCy Schubert 				 wpas_freq_to_band(data->assoc_info.freq) !=
3437c1d255d3SCy Schubert 				 BAND_2_4_GHZ);
34384bc52338SCy Schubert 			wpa_s->connection_he = req_elems.he_capabilities &&
34394bc52338SCy Schubert 				resp_elems.he_capabilities;
3440*a90b9d01SCy Schubert 			wpa_s->connection_eht = req_elems.eht_capabilities &&
3441*a90b9d01SCy Schubert 				resp_elems.eht_capabilities;
3442*a90b9d01SCy Schubert 			if (req_elems.rrm_enabled)
3443*a90b9d01SCy Schubert 				wpa_s->rrm.rrm_used = 1;
34444bc52338SCy Schubert 		}
34454bc52338SCy Schubert 	}
34464bc52338SCy Schubert 
344739beb93cSSam Leffler 	p = data->assoc_info.req_ies;
344839beb93cSSam Leffler 	l = data->assoc_info.req_ies_len;
344939beb93cSSam Leffler 
345039beb93cSSam Leffler 	/* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
345139beb93cSSam Leffler 	while (p && l >= 2) {
345239beb93cSSam Leffler 		len = p[1] + 2;
345339beb93cSSam Leffler 		if (len > l) {
345439beb93cSSam Leffler 			wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
345539beb93cSSam Leffler 				    p, l);
345639beb93cSSam Leffler 			break;
345739beb93cSSam Leffler 		}
3458c1d255d3SCy Schubert 		if (!found &&
3459c1d255d3SCy Schubert 		    ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
346039beb93cSSam Leffler 		      (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3461780fb4a2SCy Schubert 		     (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3462780fb4a2SCy Schubert 		      (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3463c1d255d3SCy Schubert 		     (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
346439beb93cSSam Leffler 			if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
346539beb93cSSam Leffler 				break;
346639beb93cSSam Leffler 			found = 1;
3467*a90b9d01SCy Schubert 			wpa_find_assoc_pmkid(wpa_s,
3468*a90b9d01SCy Schubert 					     data->assoc_info.authorized);
3469c1d255d3SCy Schubert 		}
3470c1d255d3SCy Schubert 		if (!found_x && p[0] == WLAN_EID_RSNX) {
3471c1d255d3SCy Schubert 			if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
347239beb93cSSam Leffler 				break;
3473c1d255d3SCy Schubert 			found_x = 1;
347439beb93cSSam Leffler 		}
347539beb93cSSam Leffler 		l -= len;
347639beb93cSSam Leffler 		p += len;
347739beb93cSSam Leffler 	}
347839beb93cSSam Leffler 	if (!found && data->assoc_info.req_ies)
347939beb93cSSam Leffler 		wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
3480c1d255d3SCy Schubert 	if (!found_x && data->assoc_info.req_ies)
3481c1d255d3SCy Schubert 		wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
348239beb93cSSam Leffler 
348385732ac8SCy Schubert #ifdef CONFIG_FILS
348485732ac8SCy Schubert #ifdef CONFIG_SME
3485*a90b9d01SCy Schubert 	if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
3486*a90b9d01SCy Schubert 	    wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) {
3487*a90b9d01SCy Schubert 		if (!data->assoc_info.resp_frame ||
348885732ac8SCy Schubert 		    fils_process_assoc_resp(wpa_s->wpa,
348985732ac8SCy Schubert 					    data->assoc_info.resp_frame,
3490*a90b9d01SCy Schubert 					    data->assoc_info.resp_frame_len) <
3491*a90b9d01SCy Schubert 		    0) {
3492*a90b9d01SCy Schubert 			wpa_supplicant_deauthenticate(wpa_s,
3493*a90b9d01SCy Schubert 						      WLAN_REASON_UNSPECIFIED);
349485732ac8SCy Schubert 			return -1;
349585732ac8SCy Schubert 		}
3496*a90b9d01SCy Schubert 
3497*a90b9d01SCy Schubert 		/* FILS use of an AEAD cipher include the SSID element in
3498*a90b9d01SCy Schubert 		 * (Re)Association Request frame in the AAD and since the AP
3499*a90b9d01SCy Schubert 		 * accepted that, the SSID was verified. */
3500*a90b9d01SCy Schubert 		wpa_s->ssid_verified = true;
3501*a90b9d01SCy Schubert 	}
350285732ac8SCy Schubert #endif /* CONFIG_SME */
350385732ac8SCy Schubert 
350485732ac8SCy Schubert 	/* Additional processing for FILS when SME is in driver */
350585732ac8SCy Schubert 	if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
350685732ac8SCy Schubert 	    !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
350785732ac8SCy Schubert 		wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
350885732ac8SCy Schubert #endif /* CONFIG_FILS */
350985732ac8SCy Schubert 
351085732ac8SCy Schubert #ifdef CONFIG_OWE
351185732ac8SCy Schubert 	if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
3512*a90b9d01SCy Schubert 	    !(wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OWE_OFFLOAD_STA) &&
3513c1d255d3SCy Schubert 	    (!bssid_known ||
3514*a90b9d01SCy Schubert 	     owe_process_assoc_resp(wpa_s->wpa,
3515*a90b9d01SCy Schubert 				    wpa_s->valid_links ?
3516*a90b9d01SCy Schubert 				    wpa_s->ap_mld_addr : bssid,
351785732ac8SCy Schubert 				    data->assoc_info.resp_ies,
351885732ac8SCy Schubert 				    data->assoc_info.resp_ies_len) < 0)) {
351985732ac8SCy Schubert 		wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
352085732ac8SCy Schubert 		return -1;
352185732ac8SCy Schubert 	}
352285732ac8SCy Schubert #endif /* CONFIG_OWE */
352385732ac8SCy Schubert 
35244bc52338SCy Schubert #ifdef CONFIG_DPP2
35254bc52338SCy Schubert 	wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
3526c1d255d3SCy Schubert 	if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
3527c1d255d3SCy Schubert 	    wpa_s->dpp_pfs) {
35284bc52338SCy Schubert 		struct ieee802_11_elems elems;
35294bc52338SCy Schubert 
35304bc52338SCy Schubert 		if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
35314bc52338SCy Schubert 					   data->assoc_info.resp_ies_len,
35324bc52338SCy Schubert 					   &elems, 0) == ParseFailed ||
35334bc52338SCy Schubert 		    !elems.owe_dh)
35344bc52338SCy Schubert 			goto no_pfs;
35354bc52338SCy Schubert 		if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
35364bc52338SCy Schubert 				    elems.owe_dh_len) < 0) {
35374bc52338SCy Schubert 			wpa_supplicant_deauthenticate(wpa_s,
35384bc52338SCy Schubert 						      WLAN_REASON_UNSPECIFIED);
35394bc52338SCy Schubert 			return -1;
35404bc52338SCy Schubert 		}
35414bc52338SCy Schubert 
35424bc52338SCy Schubert 		wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
35434bc52338SCy Schubert 	}
35444bc52338SCy Schubert no_pfs:
35454bc52338SCy Schubert #endif /* CONFIG_DPP2 */
35464bc52338SCy Schubert 
3547e28a4053SRui Paulo #ifdef CONFIG_IEEE80211R
3548e28a4053SRui Paulo #ifdef CONFIG_SME
3549e28a4053SRui Paulo 	if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
3550c1d255d3SCy Schubert 		if (!bssid_known ||
3551e28a4053SRui Paulo 		    wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3552e28a4053SRui Paulo 						 data->assoc_info.resp_ies,
3553e28a4053SRui Paulo 						 data->assoc_info.resp_ies_len,
3554e28a4053SRui Paulo 						 bssid) < 0) {
3555f05cddf9SRui Paulo 			wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3556e28a4053SRui Paulo 				"Reassociation Response failed");
3557e28a4053SRui Paulo 			wpa_supplicant_deauthenticate(
3558e28a4053SRui Paulo 				wpa_s, WLAN_REASON_INVALID_IE);
3559e28a4053SRui Paulo 			return -1;
3560e28a4053SRui Paulo 		}
3561*a90b9d01SCy Schubert 		/* SSID is included in PMK-R0 derivation, so it is verified
3562*a90b9d01SCy Schubert 		 * implicitly. */
3563*a90b9d01SCy Schubert 		wpa_s->ssid_verified = true;
3564e28a4053SRui Paulo 	}
3565e28a4053SRui Paulo 
3566e28a4053SRui Paulo 	p = data->assoc_info.resp_ies;
3567e28a4053SRui Paulo 	l = data->assoc_info.resp_ies_len;
3568e28a4053SRui Paulo 
3569f05cddf9SRui Paulo #ifdef CONFIG_WPS_STRICT
3570f05cddf9SRui Paulo 	if (p && wpa_s->current_ssid &&
3571f05cddf9SRui Paulo 	    wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
3572f05cddf9SRui Paulo 		struct wpabuf *wps;
3573f05cddf9SRui Paulo 		wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
3574f05cddf9SRui Paulo 		if (wps == NULL) {
3575f05cddf9SRui Paulo 			wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
3576f05cddf9SRui Paulo 				"include WPS IE in (Re)Association Response");
3577f05cddf9SRui Paulo 			return -1;
3578f05cddf9SRui Paulo 		}
3579f05cddf9SRui Paulo 
3580f05cddf9SRui Paulo 		if (wps_validate_assoc_resp(wps) < 0) {
3581f05cddf9SRui Paulo 			wpabuf_free(wps);
3582f05cddf9SRui Paulo 			wpa_supplicant_deauthenticate(
3583f05cddf9SRui Paulo 				wpa_s, WLAN_REASON_INVALID_IE);
3584f05cddf9SRui Paulo 			return -1;
3585f05cddf9SRui Paulo 		}
3586f05cddf9SRui Paulo 		wpabuf_free(wps);
3587f05cddf9SRui Paulo 	}
3588f05cddf9SRui Paulo #endif /* CONFIG_WPS_STRICT */
3589f05cddf9SRui Paulo 
3590e28a4053SRui Paulo 	/* Go through the IEs and make a copy of the MDIE, if present. */
3591e28a4053SRui Paulo 	while (p && l >= 2) {
3592e28a4053SRui Paulo 		len = p[1] + 2;
3593e28a4053SRui Paulo 		if (len > l) {
3594e28a4053SRui Paulo 			wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3595e28a4053SRui Paulo 				    p, l);
3596e28a4053SRui Paulo 			break;
3597e28a4053SRui Paulo 		}
3598e28a4053SRui Paulo 		if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
3599e28a4053SRui Paulo 		    p[1] >= MOBILITY_DOMAIN_ID_LEN) {
3600e28a4053SRui Paulo 			wpa_s->sme.ft_used = 1;
3601e28a4053SRui Paulo 			os_memcpy(wpa_s->sme.mobility_domain, p + 2,
3602e28a4053SRui Paulo 				  MOBILITY_DOMAIN_ID_LEN);
3603e28a4053SRui Paulo 			break;
3604e28a4053SRui Paulo 		}
3605e28a4053SRui Paulo 		l -= len;
3606e28a4053SRui Paulo 		p += len;
3607e28a4053SRui Paulo 	}
3608e28a4053SRui Paulo #endif /* CONFIG_SME */
3609e28a4053SRui Paulo 
36105b9c547cSRui Paulo 	/* Process FT when SME is in the driver */
36115b9c547cSRui Paulo 	if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
36125b9c547cSRui Paulo 	    wpa_ft_is_completed(wpa_s->wpa)) {
3613c1d255d3SCy Schubert 		if (!bssid_known ||
36145b9c547cSRui Paulo 		    wpa_ft_validate_reassoc_resp(wpa_s->wpa,
36155b9c547cSRui Paulo 						 data->assoc_info.resp_ies,
36165b9c547cSRui Paulo 						 data->assoc_info.resp_ies_len,
36175b9c547cSRui Paulo 						 bssid) < 0) {
36185b9c547cSRui Paulo 			wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
36195b9c547cSRui Paulo 				"Reassociation Response failed");
36205b9c547cSRui Paulo 			wpa_supplicant_deauthenticate(
36215b9c547cSRui Paulo 				wpa_s, WLAN_REASON_INVALID_IE);
36225b9c547cSRui Paulo 			return -1;
36235b9c547cSRui Paulo 		}
36245b9c547cSRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
3625*a90b9d01SCy Schubert 		/* SSID is included in PMK-R0 derivation, so it is verified
3626*a90b9d01SCy Schubert 		 * implicitly. */
3627*a90b9d01SCy Schubert 		wpa_s->ssid_verified = true;
36285b9c547cSRui Paulo 	}
36295b9c547cSRui Paulo 
3630e28a4053SRui Paulo 	wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
3631e28a4053SRui Paulo 			     data->assoc_info.resp_ies_len);
3632e28a4053SRui Paulo #endif /* CONFIG_IEEE80211R */
3633e28a4053SRui Paulo 
3634*a90b9d01SCy Schubert #ifndef CONFIG_NO_ROBUST_AV
3635c1d255d3SCy Schubert 	if (bssid_known)
3636c1d255d3SCy Schubert 		wpas_handle_assoc_resp_mscs(wpa_s, bssid,
3637c1d255d3SCy Schubert 					    data->assoc_info.resp_ies,
3638c1d255d3SCy Schubert 					    data->assoc_info.resp_ies_len);
3639*a90b9d01SCy Schubert #endif /* CONFIG_NO_ROBUST_AV */
3640c1d255d3SCy Schubert 
364139beb93cSSam Leffler 	/* WPA/RSN IE from Beacon/ProbeResp */
364239beb93cSSam Leffler 	p = data->assoc_info.beacon_ies;
364339beb93cSSam Leffler 	l = data->assoc_info.beacon_ies_len;
364439beb93cSSam Leffler 
364539beb93cSSam Leffler 	/* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
364639beb93cSSam Leffler 	 */
364739beb93cSSam Leffler 	wpa_found = rsn_found = 0;
364839beb93cSSam Leffler 	while (p && l >= 2) {
364939beb93cSSam Leffler 		len = p[1] + 2;
365039beb93cSSam Leffler 		if (len > l) {
365139beb93cSSam Leffler 			wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
365239beb93cSSam Leffler 				    p, l);
365339beb93cSSam Leffler 			break;
365439beb93cSSam Leffler 		}
365539beb93cSSam Leffler 		if (!wpa_found &&
365639beb93cSSam Leffler 		    p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
365739beb93cSSam Leffler 		    os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
365839beb93cSSam Leffler 			wpa_found = 1;
365939beb93cSSam Leffler 			wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
366039beb93cSSam Leffler 		}
366139beb93cSSam Leffler 
366239beb93cSSam Leffler 		if (!rsn_found &&
366339beb93cSSam Leffler 		    p[0] == WLAN_EID_RSN && p[1] >= 2) {
366439beb93cSSam Leffler 			rsn_found = 1;
366539beb93cSSam Leffler 			wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
366639beb93cSSam Leffler 		}
366739beb93cSSam Leffler 
3668c1d255d3SCy Schubert 		if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
3669c1d255d3SCy Schubert 			wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
3670c1d255d3SCy Schubert 
367139beb93cSSam Leffler 		l -= len;
367239beb93cSSam Leffler 		p += len;
367339beb93cSSam Leffler 	}
367439beb93cSSam Leffler 
367539beb93cSSam Leffler 	if (!wpa_found && data->assoc_info.beacon_ies)
367639beb93cSSam Leffler 		wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
3677c1d255d3SCy Schubert 	if (!rsn_found && data->assoc_info.beacon_ies) {
367839beb93cSSam Leffler 		wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
3679c1d255d3SCy Schubert 		wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
3680c1d255d3SCy Schubert 	}
368139beb93cSSam Leffler 	if (wpa_found || rsn_found)
368239beb93cSSam Leffler 		wpa_s->ap_ies_from_associnfo = 1;
3683e28a4053SRui Paulo 
3684*a90b9d01SCy Schubert 	if (wpa_s->assoc_freq && data->assoc_info.freq) {
3685*a90b9d01SCy Schubert 		struct wpa_bss *bss;
3686*a90b9d01SCy Schubert 		unsigned int freq = 0;
3687*a90b9d01SCy Schubert 
3688*a90b9d01SCy Schubert 		if (bssid_known) {
3689*a90b9d01SCy Schubert 			bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
3690*a90b9d01SCy Schubert 			if (bss)
3691*a90b9d01SCy Schubert 				freq = bss->freq;
3692*a90b9d01SCy Schubert 		}
3693*a90b9d01SCy Schubert 		if (freq != data->assoc_info.freq) {
3694*a90b9d01SCy Schubert 			wpa_printf(MSG_DEBUG,
3695*a90b9d01SCy Schubert 				   "Operating frequency changed from %u to %u MHz",
3696f05cddf9SRui Paulo 				   wpa_s->assoc_freq, data->assoc_info.freq);
3697*a90b9d01SCy Schubert 			wpa_supplicant_update_scan_results(wpa_s, bssid);
3698*a90b9d01SCy Schubert 		}
3699f05cddf9SRui Paulo 	}
3700f05cddf9SRui Paulo 
3701e28a4053SRui Paulo 	wpa_s->assoc_freq = data->assoc_info.freq;
3702e28a4053SRui Paulo 
3703*a90b9d01SCy Schubert #ifndef CONFIG_NO_ROBUST_AV
37044b72b91aSCy Schubert 	wpas_handle_assoc_resp_qos_mgmt(wpa_s, data->assoc_info.resp_ies,
37054b72b91aSCy Schubert 					data->assoc_info.resp_ies_len);
3706*a90b9d01SCy Schubert #endif /* CONFIG_NO_ROBUST_AV */
37074b72b91aSCy Schubert 
3708e28a4053SRui Paulo 	return 0;
370939beb93cSSam Leffler }
371039beb93cSSam Leffler 
371139beb93cSSam Leffler 
wpa_supplicant_assoc_update_ie(struct wpa_supplicant * wpa_s)3712f05cddf9SRui Paulo static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3713f05cddf9SRui Paulo {
3714c1d255d3SCy Schubert 	const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
3715f05cddf9SRui Paulo 
3716f05cddf9SRui Paulo 	if (!wpa_s->current_bss || !wpa_s->current_ssid)
3717f05cddf9SRui Paulo 		return -1;
3718f05cddf9SRui Paulo 
3719f05cddf9SRui Paulo 	if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3720f05cddf9SRui Paulo 		return 0;
3721f05cddf9SRui Paulo 
3722f05cddf9SRui Paulo 	bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3723f05cddf9SRui Paulo 					WPA_IE_VENDOR_TYPE);
3724f05cddf9SRui Paulo 	bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
3725c1d255d3SCy Schubert 	bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
3726f05cddf9SRui Paulo 
3727f05cddf9SRui Paulo 	if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3728f05cddf9SRui Paulo 				 bss_wpa ? 2 + bss_wpa[1] : 0) ||
3729f05cddf9SRui Paulo 	    wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
3730c1d255d3SCy Schubert 				 bss_rsn ? 2 + bss_rsn[1] : 0) ||
3731c1d255d3SCy Schubert 	    wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
3732c1d255d3SCy Schubert 				 bss_rsnx ? 2 + bss_rsnx[1] : 0))
3733f05cddf9SRui Paulo 		return -1;
3734f05cddf9SRui Paulo 
3735f05cddf9SRui Paulo 	return 0;
3736f05cddf9SRui Paulo }
3737f05cddf9SRui Paulo 
3738f05cddf9SRui Paulo 
wpas_fst_update_mb_assoc(struct wpa_supplicant * wpa_s,union wpa_event_data * data)3739780fb4a2SCy Schubert static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3740780fb4a2SCy Schubert 				     union wpa_event_data *data)
3741780fb4a2SCy Schubert {
3742780fb4a2SCy Schubert #ifdef CONFIG_FST
3743780fb4a2SCy Schubert 	struct assoc_info *ai = data ? &data->assoc_info : NULL;
3744780fb4a2SCy Schubert 	struct wpa_bss *bss = wpa_s->current_bss;
3745780fb4a2SCy Schubert 	const u8 *ieprb, *iebcn;
3746780fb4a2SCy Schubert 
3747780fb4a2SCy Schubert 	wpabuf_free(wpa_s->received_mb_ies);
3748780fb4a2SCy Schubert 	wpa_s->received_mb_ies = NULL;
3749780fb4a2SCy Schubert 
3750780fb4a2SCy Schubert 	if (ai &&
3751780fb4a2SCy Schubert 	    !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3752780fb4a2SCy Schubert 		wpa_printf(MSG_DEBUG,
3753780fb4a2SCy Schubert 			   "FST: MB IEs updated from Association Response frame");
3754780fb4a2SCy Schubert 		return;
3755780fb4a2SCy Schubert 	}
3756780fb4a2SCy Schubert 
3757780fb4a2SCy Schubert 	if (ai &&
3758780fb4a2SCy Schubert 	    !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3759780fb4a2SCy Schubert 		wpa_printf(MSG_DEBUG,
3760780fb4a2SCy Schubert 			   "FST: MB IEs updated from association event Beacon IEs");
3761780fb4a2SCy Schubert 		return;
3762780fb4a2SCy Schubert 	}
3763780fb4a2SCy Schubert 
3764780fb4a2SCy Schubert 	if (!bss)
3765780fb4a2SCy Schubert 		return;
3766780fb4a2SCy Schubert 
3767c1d255d3SCy Schubert 	ieprb = wpa_bss_ie_ptr(bss);
3768780fb4a2SCy Schubert 	iebcn = ieprb + bss->ie_len;
3769780fb4a2SCy Schubert 
3770780fb4a2SCy Schubert 	if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3771780fb4a2SCy Schubert 		wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3772780fb4a2SCy Schubert 	else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3773780fb4a2SCy Schubert 		wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3774780fb4a2SCy Schubert #endif /* CONFIG_FST */
3775780fb4a2SCy Schubert }
3776780fb4a2SCy Schubert 
3777780fb4a2SCy Schubert 
wpas_ml_parse_assoc(struct wpa_supplicant * wpa_s,struct ieee802_11_elems * elems,struct ml_sta_link_info * ml_info)3778*a90b9d01SCy Schubert static unsigned int wpas_ml_parse_assoc(struct wpa_supplicant *wpa_s,
3779*a90b9d01SCy Schubert 					struct ieee802_11_elems *elems,
3780*a90b9d01SCy Schubert 					struct ml_sta_link_info *ml_info)
3781*a90b9d01SCy Schubert {
3782*a90b9d01SCy Schubert 	struct wpabuf *mlbuf;
3783*a90b9d01SCy Schubert 	struct ieee80211_eht_ml *ml;
3784*a90b9d01SCy Schubert 	size_t ml_len;
3785*a90b9d01SCy Schubert 	struct eht_ml_basic_common_info *common_info;
3786*a90b9d01SCy Schubert 	const u8 *pos;
3787*a90b9d01SCy Schubert 	u16 eml_capa = 0, mld_capa = 0;
3788*a90b9d01SCy Schubert 	const u16 control =
3789*a90b9d01SCy Schubert 		host_to_le16(MULTI_LINK_CONTROL_TYPE_BASIC |
3790*a90b9d01SCy Schubert 			     BASIC_MULTI_LINK_CTRL_PRES_LINK_ID |
3791*a90b9d01SCy Schubert 			     BASIC_MULTI_LINK_CTRL_PRES_BSS_PARAM_CH_COUNT);
3792*a90b9d01SCy Schubert 	u8 expected_common_info_len = 9;
3793*a90b9d01SCy Schubert 	unsigned int i = 0;
3794*a90b9d01SCy Schubert 	u16 ml_control;
3795*a90b9d01SCy Schubert 
3796*a90b9d01SCy Schubert 	if (!wpa_s->valid_links || !elems->basic_mle || !elems->basic_mle_len)
3797*a90b9d01SCy Schubert 		return 0;
3798*a90b9d01SCy Schubert 
3799*a90b9d01SCy Schubert 	mlbuf = ieee802_11_defrag(elems->basic_mle, elems->basic_mle_len, true);
3800*a90b9d01SCy Schubert 	if (!mlbuf)
3801*a90b9d01SCy Schubert 		return 0;
3802*a90b9d01SCy Schubert 
3803*a90b9d01SCy Schubert 	ml = (struct ieee80211_eht_ml *) wpabuf_head(mlbuf);
3804*a90b9d01SCy Schubert 	ml_len = wpabuf_len(mlbuf);
3805*a90b9d01SCy Schubert 	if (ml_len < sizeof(*ml))
3806*a90b9d01SCy Schubert 		goto out;
3807*a90b9d01SCy Schubert 
3808*a90b9d01SCy Schubert 	os_memset(ml_info, 0, sizeof(*ml_info) * MAX_NUM_MLD_LINKS);
3809*a90b9d01SCy Schubert 
3810*a90b9d01SCy Schubert 	ml_control = le_to_host16(ml->ml_control);
3811*a90b9d01SCy Schubert 
3812*a90b9d01SCy Schubert 	if ((ml_control & control) != control) {
3813*a90b9d01SCy Schubert 		wpa_printf(MSG_DEBUG, "MLD: Invalid presence BM=0x%x",
3814*a90b9d01SCy Schubert 			   ml_control);
3815*a90b9d01SCy Schubert 		goto out;
3816*a90b9d01SCy Schubert 	}
3817*a90b9d01SCy Schubert 
3818*a90b9d01SCy Schubert 	if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) {
3819*a90b9d01SCy Schubert 		wpa_printf(MSG_DEBUG, "MLD: EML capabilities included");
3820*a90b9d01SCy Schubert 		expected_common_info_len += 2;
3821*a90b9d01SCy Schubert 	}
3822*a90b9d01SCy Schubert 
3823*a90b9d01SCy Schubert 	if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA) {
3824*a90b9d01SCy Schubert 		wpa_printf(MSG_DEBUG, "MLD: MLD capabilities included");
3825*a90b9d01SCy Schubert 		expected_common_info_len += 2;
3826*a90b9d01SCy Schubert 	}
3827*a90b9d01SCy Schubert 
3828*a90b9d01SCy Schubert 	if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO) {
3829*a90b9d01SCy Schubert 		wpa_printf(MSG_DEBUG,
3830*a90b9d01SCy Schubert 			   "MLD: Unexpected: medium sync delay info present");
3831*a90b9d01SCy Schubert 		expected_common_info_len += 2;
3832*a90b9d01SCy Schubert 	}
3833*a90b9d01SCy Schubert 
3834*a90b9d01SCy Schubert 	if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_AP_MLD_ID) {
3835*a90b9d01SCy Schubert 		wpa_printf(MSG_DEBUG,
3836*a90b9d01SCy Schubert 			   "MLD: Unexpected: MLD ID present");
3837*a90b9d01SCy Schubert 		expected_common_info_len++;
3838*a90b9d01SCy Schubert 	}
3839*a90b9d01SCy Schubert 
3840*a90b9d01SCy Schubert 	if (sizeof(*ml) + expected_common_info_len > ml_len) {
3841*a90b9d01SCy Schubert 		wpa_printf(MSG_DEBUG,
3842*a90b9d01SCy Schubert 			   "MLD: Not enough bytes for common info. ml_len=%zu",
3843*a90b9d01SCy Schubert 			   ml_len);
3844*a90b9d01SCy Schubert 		goto out;
3845*a90b9d01SCy Schubert 	}
3846*a90b9d01SCy Schubert 
3847*a90b9d01SCy Schubert 	common_info = (struct eht_ml_basic_common_info *) ml->variable;
3848*a90b9d01SCy Schubert 	if (common_info->len != expected_common_info_len) {
3849*a90b9d01SCy Schubert 		wpa_printf(MSG_DEBUG,
3850*a90b9d01SCy Schubert 			   "MLD: Invalid common info len=%u. expected=%u",
3851*a90b9d01SCy Schubert 			   common_info->len, expected_common_info_len);
3852*a90b9d01SCy Schubert 		goto out;
3853*a90b9d01SCy Schubert 	}
3854*a90b9d01SCy Schubert 
3855*a90b9d01SCy Schubert 	wpa_printf(MSG_DEBUG, "MLD: address: " MACSTR,
3856*a90b9d01SCy Schubert 		   MAC2STR(common_info->mld_addr));
3857*a90b9d01SCy Schubert 
3858*a90b9d01SCy Schubert 	if (!ether_addr_equal(wpa_s->ap_mld_addr, common_info->mld_addr)) {
3859*a90b9d01SCy Schubert 		wpa_printf(MSG_DEBUG, "MLD: Mismatching MLD address (expected "
3860*a90b9d01SCy Schubert 			   MACSTR ")", MAC2STR(wpa_s->ap_mld_addr));
3861*a90b9d01SCy Schubert 		goto out;
3862*a90b9d01SCy Schubert 	}
3863*a90b9d01SCy Schubert 
3864*a90b9d01SCy Schubert 	pos = common_info->variable;
3865*a90b9d01SCy Schubert 
3866*a90b9d01SCy Schubert 	/* Store the information for the association link */
3867*a90b9d01SCy Schubert 	ml_info[i].link_id = *pos;
3868*a90b9d01SCy Schubert 	pos++;
3869*a90b9d01SCy Schubert 
3870*a90b9d01SCy Schubert 	/* Skip the BSS Parameters Change Count */
3871*a90b9d01SCy Schubert 	pos++;
3872*a90b9d01SCy Schubert 
3873*a90b9d01SCy Schubert 	/* Skip the Medium Synchronization Delay Information if present  */
3874*a90b9d01SCy Schubert 	if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO)
3875*a90b9d01SCy Schubert 		pos += 2;
3876*a90b9d01SCy Schubert 
3877*a90b9d01SCy Schubert 	if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) {
3878*a90b9d01SCy Schubert 		eml_capa = WPA_GET_LE16(pos);
3879*a90b9d01SCy Schubert 		pos += 2;
3880*a90b9d01SCy Schubert 	}
3881*a90b9d01SCy Schubert 
3882*a90b9d01SCy Schubert 	if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA) {
3883*a90b9d01SCy Schubert 		mld_capa = WPA_GET_LE16(pos);
3884*a90b9d01SCy Schubert 		pos += 2;
3885*a90b9d01SCy Schubert 	}
3886*a90b9d01SCy Schubert 
3887*a90b9d01SCy Schubert 	wpa_printf(MSG_DEBUG,
3888*a90b9d01SCy Schubert 		   "MLD: link_id=%u, eml=0x%x, mld=0x%x",
3889*a90b9d01SCy Schubert 		   ml_info[i].link_id, eml_capa, mld_capa);
3890*a90b9d01SCy Schubert 
3891*a90b9d01SCy Schubert 	i++;
3892*a90b9d01SCy Schubert 
3893*a90b9d01SCy Schubert 	pos = ((u8 *) common_info) + common_info->len;
3894*a90b9d01SCy Schubert 	ml_len -= sizeof(*ml) + common_info->len;
3895*a90b9d01SCy Schubert 	while (ml_len > 2 && i < MAX_NUM_MLD_LINKS) {
3896*a90b9d01SCy Schubert 		u8 sub_elem_len = pos[1];
3897*a90b9d01SCy Schubert 		u8 sta_info_len;
3898*a90b9d01SCy Schubert 		u8 nstr_bitmap_len = 0;
3899*a90b9d01SCy Schubert 		u16 ctrl;
3900*a90b9d01SCy Schubert 		const u8 *end;
3901*a90b9d01SCy Schubert 
3902*a90b9d01SCy Schubert 		wpa_printf(MSG_DEBUG, "MLD: Subelement len=%u", sub_elem_len);
3903*a90b9d01SCy Schubert 
3904*a90b9d01SCy Schubert 		if (sub_elem_len > ml_len - 2) {
3905*a90b9d01SCy Schubert 			wpa_printf(MSG_DEBUG,
3906*a90b9d01SCy Schubert 				   "MLD: Invalid link info len: %u > %zu",
3907*a90b9d01SCy Schubert 				   2 + sub_elem_len, ml_len);
3908*a90b9d01SCy Schubert 			goto out;
3909*a90b9d01SCy Schubert 		}
3910*a90b9d01SCy Schubert 
3911*a90b9d01SCy Schubert 		switch (*pos) {
3912*a90b9d01SCy Schubert 		case EHT_ML_SUB_ELEM_PER_STA_PROFILE:
3913*a90b9d01SCy Schubert 			break;
3914*a90b9d01SCy Schubert 		case EHT_ML_SUB_ELEM_FRAGMENT:
3915*a90b9d01SCy Schubert 		case EHT_ML_SUB_ELEM_VENDOR:
3916*a90b9d01SCy Schubert 			wpa_printf(MSG_DEBUG,
3917*a90b9d01SCy Schubert 				   "MLD: Skip subelement id=%u, len=%u",
3918*a90b9d01SCy Schubert 				   *pos, sub_elem_len);
3919*a90b9d01SCy Schubert 			pos += 2 + sub_elem_len;
3920*a90b9d01SCy Schubert 			ml_len -= 2 + sub_elem_len;
3921*a90b9d01SCy Schubert 			continue;
3922*a90b9d01SCy Schubert 		default:
3923*a90b9d01SCy Schubert 			wpa_printf(MSG_DEBUG, "MLD: Unknown subelement ID=%u",
3924*a90b9d01SCy Schubert 				   *pos);
3925*a90b9d01SCy Schubert 			goto out;
3926*a90b9d01SCy Schubert 		}
3927*a90b9d01SCy Schubert 
3928*a90b9d01SCy Schubert 		end = pos + 2 + sub_elem_len;
3929*a90b9d01SCy Schubert 
3930*a90b9d01SCy Schubert 		/* Skip the subelement ID and the length */
3931*a90b9d01SCy Schubert 		pos += 2;
3932*a90b9d01SCy Schubert 		ml_len -= 2;
3933*a90b9d01SCy Schubert 
3934*a90b9d01SCy Schubert 		if (end - pos < 2)
3935*a90b9d01SCy Schubert 			goto out;
3936*a90b9d01SCy Schubert 
3937*a90b9d01SCy Schubert 		/* Get the station control field */
3938*a90b9d01SCy Schubert 		ctrl = WPA_GET_LE16(pos);
3939*a90b9d01SCy Schubert 
3940*a90b9d01SCy Schubert 		pos += 2;
3941*a90b9d01SCy Schubert 		ml_len -= 2;
3942*a90b9d01SCy Schubert 
3943*a90b9d01SCy Schubert 		if (!(ctrl & EHT_PER_STA_CTRL_COMPLETE_PROFILE_MSK)) {
3944*a90b9d01SCy Schubert 			wpa_printf(MSG_DEBUG,
3945*a90b9d01SCy Schubert 				   "MLD: Per STA complete profile expected");
3946*a90b9d01SCy Schubert 			goto out;
3947*a90b9d01SCy Schubert 		}
3948*a90b9d01SCy Schubert 
3949*a90b9d01SCy Schubert 		if (!(ctrl & EHT_PER_STA_CTRL_MAC_ADDR_PRESENT_MSK)) {
3950*a90b9d01SCy Schubert 			wpa_printf(MSG_DEBUG,
3951*a90b9d01SCy Schubert 				   "MLD: Per STA MAC address not present");
3952*a90b9d01SCy Schubert 			goto out;
3953*a90b9d01SCy Schubert 		}
3954*a90b9d01SCy Schubert 
3955*a90b9d01SCy Schubert 		if (!(ctrl & EHT_PER_STA_CTRL_TSF_OFFSET_PRESENT_MSK)) {
3956*a90b9d01SCy Schubert 			wpa_printf(MSG_DEBUG,
3957*a90b9d01SCy Schubert 				   "MLD: Per STA TSF offset not present");
3958*a90b9d01SCy Schubert 			goto out;
3959*a90b9d01SCy Schubert 		}
3960*a90b9d01SCy Schubert 
3961*a90b9d01SCy Schubert 		if (!(ctrl & EHT_PER_STA_CTRL_BEACON_INTERVAL_PRESENT_MSK)) {
3962*a90b9d01SCy Schubert 			wpa_printf(MSG_DEBUG,
3963*a90b9d01SCy Schubert 				   "MLD: Beacon interval not present");
3964*a90b9d01SCy Schubert 			goto out;
3965*a90b9d01SCy Schubert 		}
3966*a90b9d01SCy Schubert 
3967*a90b9d01SCy Schubert 		if (!(ctrl & EHT_PER_STA_CTRL_DTIM_INFO_PRESENT_MSK)) {
3968*a90b9d01SCy Schubert 			wpa_printf(MSG_DEBUG,
3969*a90b9d01SCy Schubert 				   "MLD:  DTIM information not present");
3970*a90b9d01SCy Schubert 			goto out;
3971*a90b9d01SCy Schubert 		}
3972*a90b9d01SCy Schubert 
3973*a90b9d01SCy Schubert 		if (ctrl & EHT_PER_STA_CTRL_NSTR_LINK_PAIR_PRESENT_MSK) {
3974*a90b9d01SCy Schubert 			if (ctrl & EHT_PER_STA_CTRL_NSTR_BM_SIZE_MSK)
3975*a90b9d01SCy Schubert 				nstr_bitmap_len = 2;
3976*a90b9d01SCy Schubert 			else
3977*a90b9d01SCy Schubert 				nstr_bitmap_len = 1;
3978*a90b9d01SCy Schubert 		}
3979*a90b9d01SCy Schubert 
3980*a90b9d01SCy Schubert 		if (!(ctrl & EHT_PER_STA_CTRL_BSS_PARAM_CNT_PRESENT_MSK)) {
3981*a90b9d01SCy Schubert 			wpa_printf(MSG_DEBUG,
3982*a90b9d01SCy Schubert 				   "MLD:  BSS params change count not present");
3983*a90b9d01SCy Schubert 			goto out;
3984*a90b9d01SCy Schubert 		}
3985*a90b9d01SCy Schubert 
3986*a90b9d01SCy Schubert 		sta_info_len = 1 + ETH_ALEN + 8 + 2 + 2 + 1 + nstr_bitmap_len;
3987*a90b9d01SCy Schubert 		if (sta_info_len > ml_len || sta_info_len > end - pos ||
3988*a90b9d01SCy Schubert 		    sta_info_len + 2 > sub_elem_len ||
3989*a90b9d01SCy Schubert 		    sta_info_len != *pos) {
3990*a90b9d01SCy Schubert 			wpa_printf(MSG_DEBUG,
3991*a90b9d01SCy Schubert 				   "MLD: Invalid STA info len=%u, len=%u",
3992*a90b9d01SCy Schubert 				   sta_info_len, *pos);
3993*a90b9d01SCy Schubert 			goto out;
3994*a90b9d01SCy Schubert 		}
3995*a90b9d01SCy Schubert 
3996*a90b9d01SCy Schubert 		/* Get the link address */
3997*a90b9d01SCy Schubert 		wpa_printf(MSG_DEBUG,
3998*a90b9d01SCy Schubert 			   "MLD: link addr: " MACSTR " nstr BM len=%u",
3999*a90b9d01SCy Schubert 			   MAC2STR(pos + 1), nstr_bitmap_len);
4000*a90b9d01SCy Schubert 
4001*a90b9d01SCy Schubert 		ml_info[i].link_id = ctrl & EHT_PER_STA_CTRL_LINK_ID_MSK;
4002*a90b9d01SCy Schubert 		os_memcpy(ml_info[i].bssid, pos + 1, ETH_ALEN);
4003*a90b9d01SCy Schubert 
4004*a90b9d01SCy Schubert 		pos += sta_info_len;
4005*a90b9d01SCy Schubert 		ml_len -= sta_info_len;
4006*a90b9d01SCy Schubert 
4007*a90b9d01SCy Schubert 		wpa_printf(MSG_DEBUG, "MLD: sub_elem_len=%u, sta_info_len=%u",
4008*a90b9d01SCy Schubert 			   sub_elem_len, sta_info_len);
4009*a90b9d01SCy Schubert 
4010*a90b9d01SCy Schubert 		sub_elem_len -= sta_info_len + 2;
4011*a90b9d01SCy Schubert 		if (sub_elem_len < 4) {
4012*a90b9d01SCy Schubert 			wpa_printf(MSG_DEBUG, "MLD: Per STA profile too short");
4013*a90b9d01SCy Schubert 			goto out;
4014*a90b9d01SCy Schubert 		}
4015*a90b9d01SCy Schubert 
4016*a90b9d01SCy Schubert 		wpa_hexdump(MSG_MSGDUMP, "MLD: STA profile", pos, sub_elem_len);
4017*a90b9d01SCy Schubert 		ml_info[i].status = WPA_GET_LE16(pos + 2);
4018*a90b9d01SCy Schubert 
4019*a90b9d01SCy Schubert 		pos += sub_elem_len;
4020*a90b9d01SCy Schubert 		ml_len -= sub_elem_len;
4021*a90b9d01SCy Schubert 
4022*a90b9d01SCy Schubert 		i++;
4023*a90b9d01SCy Schubert 	}
4024*a90b9d01SCy Schubert 
4025*a90b9d01SCy Schubert 	wpabuf_free(mlbuf);
4026*a90b9d01SCy Schubert 	return i;
4027*a90b9d01SCy Schubert out:
4028*a90b9d01SCy Schubert 	wpabuf_free(mlbuf);
4029*a90b9d01SCy Schubert 	return 0;
4030*a90b9d01SCy Schubert }
4031*a90b9d01SCy Schubert 
4032*a90b9d01SCy Schubert 
wpa_drv_get_mlo_info(struct wpa_supplicant * wpa_s)4033*a90b9d01SCy Schubert static int wpa_drv_get_mlo_info(struct wpa_supplicant *wpa_s)
4034*a90b9d01SCy Schubert {
4035*a90b9d01SCy Schubert 	struct driver_sta_mlo_info mlo;
4036*a90b9d01SCy Schubert 	int i;
4037*a90b9d01SCy Schubert 
4038*a90b9d01SCy Schubert 	os_memset(&mlo, 0, sizeof(mlo));
4039*a90b9d01SCy Schubert 	if (wpas_drv_get_sta_mlo_info(wpa_s, &mlo)) {
4040*a90b9d01SCy Schubert 		wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO link info");
4041*a90b9d01SCy Schubert 		wpa_supplicant_deauthenticate(wpa_s,
4042*a90b9d01SCy Schubert 					      WLAN_REASON_DEAUTH_LEAVING);
4043*a90b9d01SCy Schubert 		return -1;
4044*a90b9d01SCy Schubert 	}
4045*a90b9d01SCy Schubert 
4046*a90b9d01SCy Schubert 	if (wpa_s->valid_links == mlo.valid_links) {
4047*a90b9d01SCy Schubert 		bool match = true;
4048*a90b9d01SCy Schubert 
4049*a90b9d01SCy Schubert 		if (!mlo.valid_links)
4050*a90b9d01SCy Schubert 			return 0;
4051*a90b9d01SCy Schubert 
4052*a90b9d01SCy Schubert 		for_each_link(mlo.valid_links, i) {
4053*a90b9d01SCy Schubert 			if (!ether_addr_equal(wpa_s->links[i].addr,
4054*a90b9d01SCy Schubert 					      mlo.links[i].addr) ||
4055*a90b9d01SCy Schubert 			    !ether_addr_equal(wpa_s->links[i].bssid,
4056*a90b9d01SCy Schubert 					      mlo.links[i].bssid)) {
4057*a90b9d01SCy Schubert 				match = false;
4058*a90b9d01SCy Schubert 				break;
4059*a90b9d01SCy Schubert 			}
4060*a90b9d01SCy Schubert 		}
4061*a90b9d01SCy Schubert 
4062*a90b9d01SCy Schubert 		if (match && wpa_s->mlo_assoc_link_id == mlo.assoc_link_id &&
4063*a90b9d01SCy Schubert 		    ether_addr_equal(wpa_s->ap_mld_addr, mlo.ap_mld_addr))
4064*a90b9d01SCy Schubert 			return 0;
4065*a90b9d01SCy Schubert 	}
4066*a90b9d01SCy Schubert 
4067*a90b9d01SCy Schubert 	wpa_s->valid_links = mlo.valid_links;
4068*a90b9d01SCy Schubert 	wpa_s->mlo_assoc_link_id = mlo.assoc_link_id;
4069*a90b9d01SCy Schubert 	os_memcpy(wpa_s->ap_mld_addr, mlo.ap_mld_addr, ETH_ALEN);
4070*a90b9d01SCy Schubert 	for_each_link(wpa_s->valid_links, i) {
4071*a90b9d01SCy Schubert 		os_memcpy(wpa_s->links[i].addr, mlo.links[i].addr, ETH_ALEN);
4072*a90b9d01SCy Schubert 		os_memcpy(wpa_s->links[i].bssid, mlo.links[i].bssid, ETH_ALEN);
4073*a90b9d01SCy Schubert 		wpa_s->links[i].freq = mlo.links[i].freq;
4074*a90b9d01SCy Schubert 		wpa_supplicant_update_link_bss(wpa_s, i, mlo.links[i].bssid);
4075*a90b9d01SCy Schubert 	}
4076*a90b9d01SCy Schubert 
4077*a90b9d01SCy Schubert 	return 0;
4078*a90b9d01SCy Schubert }
4079*a90b9d01SCy Schubert 
4080*a90b9d01SCy Schubert 
wpa_sm_set_ml_info(struct wpa_supplicant * wpa_s)4081*a90b9d01SCy Schubert static int wpa_sm_set_ml_info(struct wpa_supplicant *wpa_s)
4082*a90b9d01SCy Schubert {
4083*a90b9d01SCy Schubert 	struct driver_sta_mlo_info drv_mlo;
4084*a90b9d01SCy Schubert 	struct wpa_sm_mlo wpa_mlo;
4085*a90b9d01SCy Schubert 	const u8 *bss_rsn = NULL, *bss_rsnx = NULL;
4086*a90b9d01SCy Schubert 	int i;
4087*a90b9d01SCy Schubert 
4088*a90b9d01SCy Schubert 	os_memset(&drv_mlo, 0, sizeof(drv_mlo));
4089*a90b9d01SCy Schubert 	if (wpas_drv_get_sta_mlo_info(wpa_s, &drv_mlo)) {
4090*a90b9d01SCy Schubert 		wpa_dbg(wpa_s, MSG_INFO, "Failed to get MLO link info");
4091*a90b9d01SCy Schubert 		return -1;
4092*a90b9d01SCy Schubert 	}
4093*a90b9d01SCy Schubert 
4094*a90b9d01SCy Schubert 	os_memset(&wpa_mlo, 0, sizeof(wpa_mlo));
4095*a90b9d01SCy Schubert 	if (!drv_mlo.valid_links)
4096*a90b9d01SCy Schubert 		goto out;
4097*a90b9d01SCy Schubert 
4098*a90b9d01SCy Schubert 	os_memcpy(wpa_mlo.ap_mld_addr, drv_mlo.ap_mld_addr, ETH_ALEN);
4099*a90b9d01SCy Schubert 	wpa_mlo.assoc_link_id = drv_mlo.assoc_link_id;
4100*a90b9d01SCy Schubert 	wpa_mlo.valid_links = drv_mlo.valid_links;
4101*a90b9d01SCy Schubert 	wpa_mlo.req_links = drv_mlo.req_links;
4102*a90b9d01SCy Schubert 
4103*a90b9d01SCy Schubert 	for_each_link(drv_mlo.req_links, i) {
4104*a90b9d01SCy Schubert 		struct wpa_bss *bss;
4105*a90b9d01SCy Schubert 
4106*a90b9d01SCy Schubert 		bss = wpa_supplicant_get_new_bss(wpa_s, drv_mlo.links[i].bssid);
4107*a90b9d01SCy Schubert 		if (!bss) {
4108*a90b9d01SCy Schubert 			wpa_dbg(wpa_s, MSG_INFO,
4109*a90b9d01SCy Schubert 				"Failed to get MLO link %d BSS", i);
4110*a90b9d01SCy Schubert 			return -1;
4111*a90b9d01SCy Schubert 		}
4112*a90b9d01SCy Schubert 
4113*a90b9d01SCy Schubert 		bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
4114*a90b9d01SCy Schubert 		bss_rsnx = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
4115*a90b9d01SCy Schubert 
4116*a90b9d01SCy Schubert 		wpa_mlo.links[i].ap_rsne = bss_rsn ? (u8 *) bss_rsn : NULL;
4117*a90b9d01SCy Schubert 		wpa_mlo.links[i].ap_rsne_len = bss_rsn ? 2 + bss_rsn[1] : 0;
4118*a90b9d01SCy Schubert 		wpa_mlo.links[i].ap_rsnxe = bss_rsnx ? (u8 *) bss_rsnx : NULL;
4119*a90b9d01SCy Schubert 		wpa_mlo.links[i].ap_rsnxe_len = bss_rsnx ? 2 + bss_rsnx[1] : 0;
4120*a90b9d01SCy Schubert 
4121*a90b9d01SCy Schubert 		os_memcpy(wpa_mlo.links[i].bssid, drv_mlo.links[i].bssid,
4122*a90b9d01SCy Schubert 			  ETH_ALEN);
4123*a90b9d01SCy Schubert 		os_memcpy(wpa_mlo.links[i].addr, drv_mlo.links[i].addr,
4124*a90b9d01SCy Schubert 			  ETH_ALEN);
4125*a90b9d01SCy Schubert 	}
4126*a90b9d01SCy Schubert 
4127*a90b9d01SCy Schubert out:
4128*a90b9d01SCy Schubert 	return wpa_sm_set_mlo_params(wpa_s->wpa, &wpa_mlo);
4129*a90b9d01SCy Schubert }
4130*a90b9d01SCy Schubert 
4131*a90b9d01SCy Schubert 
wpa_supplicant_event_assoc(struct wpa_supplicant * wpa_s,union wpa_event_data * data)413239beb93cSSam Leffler static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
413339beb93cSSam Leffler 				       union wpa_event_data *data)
413439beb93cSSam Leffler {
413539beb93cSSam Leffler 	u8 bssid[ETH_ALEN];
4136780fb4a2SCy Schubert 	int ft_completed, already_authorized;
4137325151a3SRui Paulo 	int new_bss = 0;
4138c1d255d3SCy Schubert #if defined(CONFIG_FILS) || defined(CONFIG_MBO)
4139c1d255d3SCy Schubert 	struct wpa_bss *bss;
4140c1d255d3SCy Schubert #endif /* CONFIG_FILS || CONFIG_MBO */
414139beb93cSSam Leffler 
4142e28a4053SRui Paulo #ifdef CONFIG_AP
4143e28a4053SRui Paulo 	if (wpa_s->ap_iface) {
41445b9c547cSRui Paulo 		if (!data)
41455b9c547cSRui Paulo 			return;
4146e28a4053SRui Paulo 		hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
4147e28a4053SRui Paulo 				    data->assoc_info.addr,
4148e28a4053SRui Paulo 				    data->assoc_info.req_ies,
4149*a90b9d01SCy Schubert 				    data->assoc_info.req_ies_len, NULL, 0,
4150*a90b9d01SCy Schubert 				    NULL, data->assoc_info.reassoc);
4151e28a4053SRui Paulo 		return;
4152e28a4053SRui Paulo 	}
4153e28a4053SRui Paulo #endif /* CONFIG_AP */
4154e28a4053SRui Paulo 
4155325151a3SRui Paulo 	eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
4156c1d255d3SCy Schubert 	wpa_s->own_reconnect_req = 0;
4157325151a3SRui Paulo 
4158e28a4053SRui Paulo 	ft_completed = wpa_ft_is_completed(wpa_s->wpa);
4159*a90b9d01SCy Schubert 
4160*a90b9d01SCy Schubert 	if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
4161*a90b9d01SCy Schubert 		wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
4162*a90b9d01SCy Schubert 		wpa_supplicant_deauthenticate(
4163*a90b9d01SCy Schubert 			wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4164*a90b9d01SCy Schubert 		return;
4165*a90b9d01SCy Schubert 	}
4166*a90b9d01SCy Schubert 
4167*a90b9d01SCy Schubert 	if (wpa_drv_get_mlo_info(wpa_s) < 0) {
4168*a90b9d01SCy Schubert 		wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO connection info");
4169*a90b9d01SCy Schubert 		wpa_supplicant_deauthenticate(wpa_s,
4170*a90b9d01SCy Schubert 					      WLAN_REASON_DEAUTH_LEAVING);
4171*a90b9d01SCy Schubert 		return;
4172*a90b9d01SCy Schubert 	}
4173*a90b9d01SCy Schubert 
4174*a90b9d01SCy Schubert 	if (ft_completed &&
4175*a90b9d01SCy Schubert 	    (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION)) {
4176*a90b9d01SCy Schubert 		wpa_msg(wpa_s, MSG_INFO, "Attempt to roam to " MACSTR,
4177*a90b9d01SCy Schubert 			MAC2STR(bssid));
4178*a90b9d01SCy Schubert 		if (!wpa_supplicant_update_current_bss(wpa_s, bssid)) {
4179*a90b9d01SCy Schubert 			wpa_printf(MSG_ERROR,
4180*a90b9d01SCy Schubert 				   "Can't find target AP's information!");
4181*a90b9d01SCy Schubert 			return;
4182*a90b9d01SCy Schubert 		}
4183*a90b9d01SCy Schubert 		wpa_supplicant_assoc_update_ie(wpa_s);
4184*a90b9d01SCy Schubert 	}
4185*a90b9d01SCy Schubert 
4186e28a4053SRui Paulo 	if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
4187e28a4053SRui Paulo 		return;
418885732ac8SCy Schubert 	/*
418985732ac8SCy Schubert 	 * FILS authentication can share the same mechanism to mark the
419085732ac8SCy Schubert 	 * connection fully authenticated, so set ft_completed also based on
419185732ac8SCy Schubert 	 * FILS result.
419285732ac8SCy Schubert 	 */
419385732ac8SCy Schubert 	if (!ft_completed)
419485732ac8SCy Schubert 		ft_completed = wpa_fils_is_completed(wpa_s->wpa);
419539beb93cSSam Leffler 
419639beb93cSSam Leffler 	wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
4197*a90b9d01SCy Schubert 	if (!ether_addr_equal(bssid, wpa_s->bssid)) {
41984bc52338SCy Schubert 		if (os_reltime_initialized(&wpa_s->session_start)) {
41994bc52338SCy Schubert 			os_reltime_age(&wpa_s->session_start,
42004bc52338SCy Schubert 				       &wpa_s->session_length);
42014bc52338SCy Schubert 			wpa_s->session_start.sec = 0;
42024bc52338SCy Schubert 			wpa_s->session_start.usec = 0;
42034bc52338SCy Schubert 			wpas_notify_session_length(wpa_s);
42044bc52338SCy Schubert 		} else {
42054bc52338SCy Schubert 			wpas_notify_auth_changed(wpa_s);
42064bc52338SCy Schubert 			os_get_reltime(&wpa_s->session_start);
42074bc52338SCy Schubert 		}
4208f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
420939beb93cSSam Leffler 			MACSTR, MAC2STR(bssid));
4210325151a3SRui Paulo 		new_bss = 1;
4211f05cddf9SRui Paulo 		random_add_randomness(bssid, ETH_ALEN);
421239beb93cSSam Leffler 		os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
421339beb93cSSam Leffler 		os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
4214e28a4053SRui Paulo 		wpas_notify_bssid_changed(wpa_s);
4215e28a4053SRui Paulo 
421639beb93cSSam Leffler 		if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
421739beb93cSSam Leffler 			wpa_clear_keys(wpa_s, bssid);
421839beb93cSSam Leffler 		}
4219*a90b9d01SCy Schubert 		if (wpa_supplicant_select_config(wpa_s, data) < 0) {
4220f05cddf9SRui Paulo 			wpa_supplicant_deauthenticate(
422139beb93cSSam Leffler 				wpa_s, WLAN_REASON_DEAUTH_LEAVING);
422239beb93cSSam Leffler 			return;
422339beb93cSSam Leffler 		}
4224325151a3SRui Paulo 	}
4225f05cddf9SRui Paulo 
42264b72b91aSCy Schubert 	if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
42274b72b91aSCy Schubert 	    data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0)
42284b72b91aSCy Schubert 		return;
42294b72b91aSCy Schubert 
4230c1d255d3SCy Schubert 	multi_ap_set_4addr_mode(wpa_s);
4231c1d255d3SCy Schubert 
4232f05cddf9SRui Paulo 	if (wpa_s->conf->ap_scan == 1 &&
4233f05cddf9SRui Paulo 	    wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
4234325151a3SRui Paulo 		if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
4235f05cddf9SRui Paulo 			wpa_msg(wpa_s, MSG_WARNING,
4236f05cddf9SRui Paulo 				"WPA/RSN IEs not updated");
4237f05cddf9SRui Paulo 	}
4238e28a4053SRui Paulo 
4239780fb4a2SCy Schubert 	wpas_fst_update_mb_assoc(wpa_s, data);
4240780fb4a2SCy Schubert 
4241e28a4053SRui Paulo #ifdef CONFIG_SME
4242*a90b9d01SCy Schubert 	/*
4243*a90b9d01SCy Schubert 	 * Cache the current AP's BSSID (for non-MLO connection) or MLD address
4244*a90b9d01SCy Schubert 	 * (for MLO connection) as the previous BSSID for subsequent
4245*a90b9d01SCy Schubert 	 * reassociation requests handled by SME-in-wpa_supplicant.
4246*a90b9d01SCy Schubert 	 */
4247*a90b9d01SCy Schubert 	os_memcpy(wpa_s->sme.prev_bssid,
4248*a90b9d01SCy Schubert 		  wpa_s->valid_links ? wpa_s->ap_mld_addr : bssid, ETH_ALEN);
4249e28a4053SRui Paulo 	wpa_s->sme.prev_bssid_set = 1;
42505b9c547cSRui Paulo 	wpa_s->sme.last_unprot_disconnect.sec = 0;
4251e28a4053SRui Paulo #endif /* CONFIG_SME */
425239beb93cSSam Leffler 
425339beb93cSSam Leffler 	wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
425439beb93cSSam Leffler 	if (wpa_s->current_ssid) {
425539beb93cSSam Leffler 		/* When using scanning (ap_scan=1), SIM PC/SC interface can be
425639beb93cSSam Leffler 		 * initialized before association, but for other modes,
425739beb93cSSam Leffler 		 * initialize PC/SC here, if the current configuration needs
425839beb93cSSam Leffler 		 * smartcard or SIM/USIM. */
425939beb93cSSam Leffler 		wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
426039beb93cSSam Leffler 	}
426139beb93cSSam Leffler 	wpa_sm_notify_assoc(wpa_s->wpa, bssid);
4262*a90b9d01SCy Schubert 
4263*a90b9d01SCy Schubert 	if (wpa_sm_set_ml_info(wpa_s)) {
4264*a90b9d01SCy Schubert 		wpa_dbg(wpa_s, MSG_INFO,
4265*a90b9d01SCy Schubert 			"Failed to set MLO connection info to wpa_sm");
4266*a90b9d01SCy Schubert 		wpa_supplicant_deauthenticate(wpa_s,
4267*a90b9d01SCy Schubert 					      WLAN_REASON_DEAUTH_LEAVING);
4268*a90b9d01SCy Schubert 		return;
4269*a90b9d01SCy Schubert 	}
4270*a90b9d01SCy Schubert 
4271e28a4053SRui Paulo 	if (wpa_s->l2)
427239beb93cSSam Leffler 		l2_packet_notify_auth_start(wpa_s->l2);
427339beb93cSSam Leffler 
4274780fb4a2SCy Schubert 	already_authorized = data && data->assoc_info.authorized;
4275780fb4a2SCy Schubert 
427639beb93cSSam Leffler 	/*
4277c1d255d3SCy Schubert 	 * Set portEnabled first to false in order to get EAP state machine out
427839beb93cSSam Leffler 	 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
427939beb93cSSam Leffler 	 * state machine may transit to AUTHENTICATING state based on obsolete
428039beb93cSSam Leffler 	 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
428139beb93cSSam Leffler 	 * AUTHENTICATED without ever giving chance to EAP state machine to
428239beb93cSSam Leffler 	 * reset the state.
428339beb93cSSam Leffler 	 */
4284780fb4a2SCy Schubert 	if (!ft_completed && !already_authorized) {
4285c1d255d3SCy Schubert 		eapol_sm_notify_portEnabled(wpa_s->eapol, false);
4286c1d255d3SCy Schubert 		eapol_sm_notify_portValid(wpa_s->eapol, false);
428739beb93cSSam Leffler 	}
428885732ac8SCy Schubert 	if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
428985732ac8SCy Schubert 	    wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
429085732ac8SCy Schubert 	    wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
4291c1d255d3SCy Schubert 	    already_authorized || wpa_s->drv_authorized_port)
4292c1d255d3SCy Schubert 		eapol_sm_notify_eap_success(wpa_s->eapol, false);
429339beb93cSSam Leffler 	/* 802.1X::portControl = Auto */
4294c1d255d3SCy Schubert 	eapol_sm_notify_portEnabled(wpa_s->eapol, true);
429539beb93cSSam Leffler 	wpa_s->eapol_received = 0;
429639beb93cSSam Leffler 	if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
4297e28a4053SRui Paulo 	    wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
4298e28a4053SRui Paulo 	    (wpa_s->current_ssid &&
4299206b73d0SCy Schubert 	     wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
43005b9c547cSRui Paulo 		if (wpa_s->current_ssid &&
43015b9c547cSRui Paulo 		    wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
43025b9c547cSRui Paulo 		    (wpa_s->drv_flags &
43035b9c547cSRui Paulo 		     WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
43045b9c547cSRui Paulo 			/*
43055b9c547cSRui Paulo 			 * Set the key after having received joined-IBSS event
43065b9c547cSRui Paulo 			 * from the driver.
43075b9c547cSRui Paulo 			 */
43085b9c547cSRui Paulo 			wpa_supplicant_set_wpa_none_key(wpa_s,
43095b9c547cSRui Paulo 							wpa_s->current_ssid);
43105b9c547cSRui Paulo 		}
431139beb93cSSam Leffler 		wpa_supplicant_cancel_auth_timeout(wpa_s);
431239beb93cSSam Leffler 		wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
431339beb93cSSam Leffler 	} else if (!ft_completed) {
431439beb93cSSam Leffler 		/* Timeout for receiving the first EAPOL packet */
431539beb93cSSam Leffler 		wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
431639beb93cSSam Leffler 	}
431739beb93cSSam Leffler 	wpa_supplicant_cancel_scan(wpa_s);
431839beb93cSSam Leffler 
43194bc52338SCy Schubert 	if (ft_completed) {
43204bc52338SCy Schubert 		/*
43214bc52338SCy Schubert 		 * FT protocol completed - make sure EAPOL state machine ends
43224bc52338SCy Schubert 		 * up in authenticated.
43234bc52338SCy Schubert 		 */
43244bc52338SCy Schubert 		wpa_supplicant_cancel_auth_timeout(wpa_s);
43254bc52338SCy Schubert 		wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
4326c1d255d3SCy Schubert 		eapol_sm_notify_portValid(wpa_s->eapol, true);
4327c1d255d3SCy Schubert 		eapol_sm_notify_eap_success(wpa_s->eapol, true);
43284bc52338SCy Schubert 	} else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
432939beb93cSSam Leffler 		   wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
4330*a90b9d01SCy Schubert 		if (already_authorized) {
433139beb93cSSam Leffler 			/*
433239beb93cSSam Leffler 			 * We are done; the driver will take care of RSN 4-way
433339beb93cSSam Leffler 			 * handshake.
433439beb93cSSam Leffler 			 */
433539beb93cSSam Leffler 			wpa_supplicant_cancel_auth_timeout(wpa_s);
433639beb93cSSam Leffler 			wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
4337c1d255d3SCy Schubert 			eapol_sm_notify_portValid(wpa_s->eapol, true);
4338c1d255d3SCy Schubert 			eapol_sm_notify_eap_success(wpa_s->eapol, true);
4339*a90b9d01SCy Schubert 		} else {
4340*a90b9d01SCy Schubert 			/* Update port, WPA_COMPLETED state from the
4341*a90b9d01SCy Schubert 			 * EVENT_PORT_AUTHORIZED handler when the driver is done
4342*a90b9d01SCy Schubert 			 * with the 4-way handshake.
4343*a90b9d01SCy Schubert 			 */
4344*a90b9d01SCy Schubert 			wpa_msg(wpa_s, MSG_DEBUG,
4345*a90b9d01SCy Schubert 				"ASSOC INFO: wait for driver port authorized indication");
4346*a90b9d01SCy Schubert 		}
43474bc52338SCy Schubert 	} else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
4348f05cddf9SRui Paulo 		   wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
4349f05cddf9SRui Paulo 		/*
4350f05cddf9SRui Paulo 		 * The driver will take care of RSN 4-way handshake, so we need
4351f05cddf9SRui Paulo 		 * to allow EAPOL supplicant to complete its work without
4352f05cddf9SRui Paulo 		 * waiting for WPA supplicant.
4353f05cddf9SRui Paulo 		 */
4354c1d255d3SCy Schubert 		eapol_sm_notify_portValid(wpa_s->eapol, true);
435539beb93cSSam Leffler 	}
43563157ba21SRui Paulo 
4357f05cddf9SRui Paulo 	wpa_s->last_eapol_matches_bssid = 0;
4358f05cddf9SRui Paulo 
4359c1d255d3SCy Schubert #ifdef CONFIG_TESTING_OPTIONS
4360c1d255d3SCy Schubert 	if (wpa_s->rsne_override_eapol) {
4361c1d255d3SCy Schubert 		wpa_printf(MSG_DEBUG,
4362c1d255d3SCy Schubert 			   "TESTING: RSNE EAPOL-Key msg 2/4 override");
4363c1d255d3SCy Schubert 		wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
4364c1d255d3SCy Schubert 					wpabuf_head(wpa_s->rsne_override_eapol),
4365c1d255d3SCy Schubert 					wpabuf_len(wpa_s->rsne_override_eapol));
4366c1d255d3SCy Schubert 	}
4367c1d255d3SCy Schubert 	if (wpa_s->rsnxe_override_eapol) {
4368c1d255d3SCy Schubert 		wpa_printf(MSG_DEBUG,
4369c1d255d3SCy Schubert 			   "TESTING: RSNXE EAPOL-Key msg 2/4 override");
4370c1d255d3SCy Schubert 		wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
4371c1d255d3SCy Schubert 				       wpabuf_head(wpa_s->rsnxe_override_eapol),
4372c1d255d3SCy Schubert 				       wpabuf_len(wpa_s->rsnxe_override_eapol));
4373c1d255d3SCy Schubert 	}
4374c1d255d3SCy Schubert #endif /* CONFIG_TESTING_OPTIONS */
4375c1d255d3SCy Schubert 
43763157ba21SRui Paulo 	if (wpa_s->pending_eapol_rx) {
43775b9c547cSRui Paulo 		struct os_reltime now, age;
43785b9c547cSRui Paulo 		os_get_reltime(&now);
43795b9c547cSRui Paulo 		os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
438085732ac8SCy Schubert 		if (age.sec == 0 && age.usec < 200000 &&
4381*a90b9d01SCy Schubert 		    ether_addr_equal(wpa_s->pending_eapol_rx_src,
4382*a90b9d01SCy Schubert 				     wpa_s->valid_links ? wpa_s->ap_mld_addr :
4383*a90b9d01SCy Schubert 				     bssid)) {
4384f05cddf9SRui Paulo 			wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
4385f05cddf9SRui Paulo 				"frame that was received just before "
4386f05cddf9SRui Paulo 				"association notification");
43873157ba21SRui Paulo 			wpa_supplicant_rx_eapol(
43883157ba21SRui Paulo 				wpa_s, wpa_s->pending_eapol_rx_src,
43893157ba21SRui Paulo 				wpabuf_head(wpa_s->pending_eapol_rx),
4390*a90b9d01SCy Schubert 				wpabuf_len(wpa_s->pending_eapol_rx),
4391*a90b9d01SCy Schubert 				wpa_s->pending_eapol_encrypted);
43923157ba21SRui Paulo 		}
43933157ba21SRui Paulo 		wpabuf_free(wpa_s->pending_eapol_rx);
43943157ba21SRui Paulo 		wpa_s->pending_eapol_rx = NULL;
43953157ba21SRui Paulo 	}
4396e28a4053SRui Paulo 
4397c1d255d3SCy Schubert #ifdef CONFIG_WEP
4398e28a4053SRui Paulo 	if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
4399e28a4053SRui Paulo 	     wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
44005b9c547cSRui Paulo 	    wpa_s->current_ssid &&
44015b9c547cSRui Paulo 	    (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
4402e28a4053SRui Paulo 		/* Set static WEP keys again */
4403e28a4053SRui Paulo 		wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
4404e28a4053SRui Paulo 	}
4405c1d255d3SCy Schubert #endif /* CONFIG_WEP */
4406f05cddf9SRui Paulo 
4407f05cddf9SRui Paulo #ifdef CONFIG_IBSS_RSN
4408f05cddf9SRui Paulo 	if (wpa_s->current_ssid &&
4409f05cddf9SRui Paulo 	    wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
4410f05cddf9SRui Paulo 	    wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
4411f05cddf9SRui Paulo 	    wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
4412f05cddf9SRui Paulo 	    wpa_s->ibss_rsn == NULL) {
4413780fb4a2SCy Schubert 		wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
4414f05cddf9SRui Paulo 		if (!wpa_s->ibss_rsn) {
4415f05cddf9SRui Paulo 			wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
4416f05cddf9SRui Paulo 			wpa_supplicant_deauthenticate(
4417f05cddf9SRui Paulo 				wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4418f05cddf9SRui Paulo 			return;
4419f05cddf9SRui Paulo 		}
4420f05cddf9SRui Paulo 
4421f05cddf9SRui Paulo 		ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
4422f05cddf9SRui Paulo 	}
4423f05cddf9SRui Paulo #endif /* CONFIG_IBSS_RSN */
4424f05cddf9SRui Paulo 
4425f05cddf9SRui Paulo 	wpas_wps_notify_assoc(wpa_s, bssid);
44265b9c547cSRui Paulo 
4427*a90b9d01SCy Schubert #ifndef CONFIG_NO_WMM_AC
44285b9c547cSRui Paulo 	if (data) {
44295b9c547cSRui Paulo 		wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
44305b9c547cSRui Paulo 				    data->assoc_info.resp_ies_len,
44315b9c547cSRui Paulo 				    &data->assoc_info.wmm_params);
44325b9c547cSRui Paulo 
44335b9c547cSRui Paulo 		if (wpa_s->reassoc_same_bss)
44345b9c547cSRui Paulo 			wmm_ac_restore_tspecs(wpa_s);
44355b9c547cSRui Paulo 	}
4436*a90b9d01SCy Schubert #endif /* CONFIG_NO_WMM_AC */
443785732ac8SCy Schubert 
4438c1d255d3SCy Schubert #if defined(CONFIG_FILS) || defined(CONFIG_MBO)
4439c1d255d3SCy Schubert 	bss = wpa_bss_get_bssid(wpa_s, bssid);
4440c1d255d3SCy Schubert #endif /* CONFIG_FILS || CONFIG_MBO */
444185732ac8SCy Schubert #ifdef CONFIG_FILS
444285732ac8SCy Schubert 	if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
444385732ac8SCy Schubert 		const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
444485732ac8SCy Schubert 
444585732ac8SCy Schubert 		if (fils_cache_id)
444685732ac8SCy Schubert 			wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
444785732ac8SCy Schubert 	}
444885732ac8SCy Schubert #endif /* CONFIG_FILS */
4449c1d255d3SCy Schubert 
4450c1d255d3SCy Schubert #ifdef CONFIG_MBO
4451c1d255d3SCy Schubert 	wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
4452c1d255d3SCy Schubert #endif /* CONFIG_MBO */
4453c1d255d3SCy Schubert 
4454c1d255d3SCy Schubert #ifdef CONFIG_DPP2
4455c1d255d3SCy Schubert 	wpa_s->dpp_pfs_fallback = 0;
4456c1d255d3SCy Schubert #endif /* CONFIG_DPP2 */
4457*a90b9d01SCy Schubert 
4458*a90b9d01SCy Schubert 	if (wpa_s->current_ssid && wpa_s->current_ssid->enable_4addr_mode)
4459*a90b9d01SCy Schubert 		wpa_supplicant_set_4addr_mode(wpa_s);
4460f05cddf9SRui Paulo }
4461f05cddf9SRui Paulo 
4462f05cddf9SRui Paulo 
disconnect_reason_recoverable(u16 reason_code)4463f05cddf9SRui Paulo static int disconnect_reason_recoverable(u16 reason_code)
4464f05cddf9SRui Paulo {
4465f05cddf9SRui Paulo 	return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
4466f05cddf9SRui Paulo 		reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
4467f05cddf9SRui Paulo 		reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
446839beb93cSSam Leffler }
446939beb93cSSam Leffler 
447039beb93cSSam Leffler 
wpa_supplicant_event_disassoc(struct wpa_supplicant * wpa_s,u16 reason_code,int locally_generated)4471e28a4053SRui Paulo static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
4472f05cddf9SRui Paulo 					  u16 reason_code,
4473f05cddf9SRui Paulo 					  int locally_generated)
447439beb93cSSam Leffler {
447539beb93cSSam Leffler 	const u8 *bssid;
447639beb93cSSam Leffler 
447739beb93cSSam Leffler 	if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
447839beb93cSSam Leffler 		/*
447939beb93cSSam Leffler 		 * At least Host AP driver and a Prism3 card seemed to be
448039beb93cSSam Leffler 		 * generating streams of disconnected events when configuring
448139beb93cSSam Leffler 		 * IBSS for WPA-None. Ignore them for now.
448239beb93cSSam Leffler 		 */
4483f05cddf9SRui Paulo 		return;
4484f05cddf9SRui Paulo 	}
4485f05cddf9SRui Paulo 
4486f05cddf9SRui Paulo 	bssid = wpa_s->bssid;
4487f05cddf9SRui Paulo 	if (is_zero_ether_addr(bssid))
4488f05cddf9SRui Paulo 		bssid = wpa_s->pending_bssid;
4489f05cddf9SRui Paulo 
4490f05cddf9SRui Paulo 	if (!is_zero_ether_addr(bssid) ||
4491f05cddf9SRui Paulo 	    wpa_s->wpa_state >= WPA_AUTHENTICATING) {
4492f05cddf9SRui Paulo 		wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
4493f05cddf9SRui Paulo 			" reason=%d%s",
4494f05cddf9SRui Paulo 			MAC2STR(bssid), reason_code,
4495f05cddf9SRui Paulo 			locally_generated ? " locally_generated=1" : "");
4496f05cddf9SRui Paulo 	}
4497f05cddf9SRui Paulo }
4498f05cddf9SRui Paulo 
4499f05cddf9SRui Paulo 
could_be_psk_mismatch(struct wpa_supplicant * wpa_s,u16 reason_code,int locally_generated)4500f05cddf9SRui Paulo static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
4501f05cddf9SRui Paulo 				 int locally_generated)
4502f05cddf9SRui Paulo {
4503f05cddf9SRui Paulo 	if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
4504c1d255d3SCy Schubert 	    !wpa_s->new_connection ||
4505c1d255d3SCy Schubert 	    !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
4506c1d255d3SCy Schubert 	    wpa_key_mgmt_sae(wpa_s->key_mgmt))
4507c1d255d3SCy Schubert 		return 0; /* Not in initial 4-way handshake with PSK */
4508f05cddf9SRui Paulo 
4509f05cddf9SRui Paulo 	/*
4510f05cddf9SRui Paulo 	 * It looks like connection was lost while trying to go through PSK
4511f05cddf9SRui Paulo 	 * 4-way handshake. Filter out known disconnection cases that are caused
4512f05cddf9SRui Paulo 	 * by something else than PSK mismatch to avoid confusing reports.
4513f05cddf9SRui Paulo 	 */
4514f05cddf9SRui Paulo 
4515f05cddf9SRui Paulo 	if (locally_generated) {
4516f05cddf9SRui Paulo 		if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
4517f05cddf9SRui Paulo 			return 0;
4518f05cddf9SRui Paulo 	}
4519f05cddf9SRui Paulo 
4520f05cddf9SRui Paulo 	return 1;
4521f05cddf9SRui Paulo }
4522f05cddf9SRui Paulo 
4523f05cddf9SRui Paulo 
wpa_supplicant_event_disassoc_finish(struct wpa_supplicant * wpa_s,u16 reason_code,int locally_generated)4524f05cddf9SRui Paulo static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
4525f05cddf9SRui Paulo 						 u16 reason_code,
4526f05cddf9SRui Paulo 						 int locally_generated)
4527f05cddf9SRui Paulo {
4528f05cddf9SRui Paulo 	const u8 *bssid;
4529f05cddf9SRui Paulo 	struct wpa_bss *fast_reconnect = NULL;
4530f05cddf9SRui Paulo 	struct wpa_ssid *fast_reconnect_ssid = NULL;
4531780fb4a2SCy Schubert 	struct wpa_bss *curr = NULL;
4532f05cddf9SRui Paulo 
4533f05cddf9SRui Paulo 	if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
4534f05cddf9SRui Paulo 		/*
4535f05cddf9SRui Paulo 		 * At least Host AP driver and a Prism3 card seemed to be
4536f05cddf9SRui Paulo 		 * generating streams of disconnected events when configuring
4537f05cddf9SRui Paulo 		 * IBSS for WPA-None. Ignore them for now.
4538f05cddf9SRui Paulo 		 */
4539f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
454039beb93cSSam Leffler 			"IBSS/WPA-None mode");
454139beb93cSSam Leffler 		return;
454239beb93cSSam Leffler 	}
454339beb93cSSam Leffler 
4544780fb4a2SCy Schubert 	if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
4545780fb4a2SCy Schubert 	    reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
4546780fb4a2SCy Schubert 	    locally_generated)
4547780fb4a2SCy Schubert 		/*
4548780fb4a2SCy Schubert 		 * Remove the inactive AP (which is probably out of range) from
4549780fb4a2SCy Schubert 		 * the BSS list after marking disassociation. In particular
4550780fb4a2SCy Schubert 		 * mac80211-based drivers use the
4551780fb4a2SCy Schubert 		 * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
4552780fb4a2SCy Schubert 		 * locally generated disconnection events for cases where the
4553780fb4a2SCy Schubert 		 * AP does not reply anymore.
4554780fb4a2SCy Schubert 		 */
4555780fb4a2SCy Schubert 		curr = wpa_s->current_bss;
4556780fb4a2SCy Schubert 
4557f05cddf9SRui Paulo 	if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
455839beb93cSSam Leffler 		wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
455939beb93cSSam Leffler 			"pre-shared key may be incorrect");
45605b9c547cSRui Paulo 		if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
45615b9c547cSRui Paulo 			return; /* P2P group removed */
4562*a90b9d01SCy Schubert 		wpas_auth_failed(wpa_s, "WRONG_KEY", wpa_s->pending_bssid);
4563*a90b9d01SCy Schubert 		wpas_notify_psk_mismatch(wpa_s);
4564c1d255d3SCy Schubert #ifdef CONFIG_DPP2
4565c1d255d3SCy Schubert 		wpas_dpp_send_conn_status_result(wpa_s,
4566c1d255d3SCy Schubert 						 DPP_STATUS_AUTH_FAILURE);
4567c1d255d3SCy Schubert #endif /* CONFIG_DPP2 */
456839beb93cSSam Leffler 	}
45695b9c547cSRui Paulo 	if (!wpa_s->disconnected &&
45705b9c547cSRui Paulo 	    (!wpa_s->auto_reconnect_disabled ||
45715b9c547cSRui Paulo 	     wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
4572780fb4a2SCy Schubert 	     wpas_wps_searching(wpa_s) ||
4573780fb4a2SCy Schubert 	     wpas_wps_reenable_networks_pending(wpa_s))) {
4574f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
45755b9c547cSRui Paulo 			"reconnect (wps=%d/%d wpa_state=%d)",
4576f05cddf9SRui Paulo 			wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
45775b9c547cSRui Paulo 			wpas_wps_searching(wpa_s),
4578f05cddf9SRui Paulo 			wpa_s->wpa_state);
4579f05cddf9SRui Paulo 		if (wpa_s->wpa_state == WPA_COMPLETED &&
4580f05cddf9SRui Paulo 		    wpa_s->current_ssid &&
4581f05cddf9SRui Paulo 		    wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
4582c1d255d3SCy Schubert 		    (wpa_s->own_reconnect_req ||
4583c1d255d3SCy Schubert 		     (!locally_generated &&
4584c1d255d3SCy Schubert 		      disconnect_reason_recoverable(reason_code)))) {
4585f05cddf9SRui Paulo 			/*
4586f05cddf9SRui Paulo 			 * It looks like the AP has dropped association with
4587c1d255d3SCy Schubert 			 * us, but could allow us to get back in. This is also
4588c1d255d3SCy Schubert 			 * triggered for cases where local reconnection request
4589c1d255d3SCy Schubert 			 * is used to force reassociation with the same BSS.
4590c1d255d3SCy Schubert 			 * Try to reconnect to the same BSS without a full scan
4591c1d255d3SCy Schubert 			 * to save time for some common cases.
4592f05cddf9SRui Paulo 			 */
4593f05cddf9SRui Paulo 			fast_reconnect = wpa_s->current_bss;
4594f05cddf9SRui Paulo 			fast_reconnect_ssid = wpa_s->current_ssid;
4595c1d255d3SCy Schubert 		} else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
459639beb93cSSam Leffler 			wpa_supplicant_req_scan(wpa_s, 0, 100000);
4597c1d255d3SCy Schubert 		} else {
4598f05cddf9SRui Paulo 			wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
4599f05cddf9SRui Paulo 				"immediate scan");
4600c1d255d3SCy Schubert 		}
4601f05cddf9SRui Paulo 	} else {
4602f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
4603f05cddf9SRui Paulo 			"try to re-connect");
4604f05cddf9SRui Paulo 		wpa_s->reassociate = 0;
4605f05cddf9SRui Paulo 		wpa_s->disconnected = 1;
4606325151a3SRui Paulo 		if (!wpa_s->pno)
4607f05cddf9SRui Paulo 			wpa_supplicant_cancel_sched_scan(wpa_s);
4608f05cddf9SRui Paulo 	}
460939beb93cSSam Leffler 	bssid = wpa_s->bssid;
461039beb93cSSam Leffler 	if (is_zero_ether_addr(bssid))
461139beb93cSSam Leffler 		bssid = wpa_s->pending_bssid;
4612f05cddf9SRui Paulo 	if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
4613*a90b9d01SCy Schubert 		wpas_connection_failed(wpa_s, bssid, NULL);
461439beb93cSSam Leffler 	wpa_sm_notify_disassoc(wpa_s->wpa);
4615c1d255d3SCy Schubert 	ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
4616c1d255d3SCy Schubert 
4617f05cddf9SRui Paulo 	if (locally_generated)
4618f05cddf9SRui Paulo 		wpa_s->disconnect_reason = -reason_code;
4619f05cddf9SRui Paulo 	else
4620f05cddf9SRui Paulo 		wpa_s->disconnect_reason = reason_code;
4621f05cddf9SRui Paulo 	wpas_notify_disconnect_reason(wpa_s);
462239beb93cSSam Leffler 	if (wpa_supplicant_dynamic_keys(wpa_s)) {
4623f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
462439beb93cSSam Leffler 		wpa_clear_keys(wpa_s, wpa_s->bssid);
462539beb93cSSam Leffler 	}
462639beb93cSSam Leffler 	wpa_supplicant_mark_disassoc(wpa_s);
4627f05cddf9SRui Paulo 
4628780fb4a2SCy Schubert 	if (curr)
4629780fb4a2SCy Schubert 		wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
4630780fb4a2SCy Schubert 
46315b9c547cSRui Paulo 	if (fast_reconnect &&
46325b9c547cSRui Paulo 	    !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
46335b9c547cSRui Paulo 	    !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
46345b9c547cSRui Paulo 	    !disallowed_ssid(wpa_s, fast_reconnect->ssid,
46355b9c547cSRui Paulo 			     fast_reconnect->ssid_len) &&
4636780fb4a2SCy Schubert 	    !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
46374bc52338SCy Schubert 	    !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
4638f05cddf9SRui Paulo #ifndef CONFIG_NO_SCAN_PROCESSING
4639f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
4640f05cddf9SRui Paulo 		if (wpa_supplicant_connect(wpa_s, fast_reconnect,
4641f05cddf9SRui Paulo 					   fast_reconnect_ssid) < 0) {
4642f05cddf9SRui Paulo 			/* Recover through full scan */
4643f05cddf9SRui Paulo 			wpa_supplicant_req_scan(wpa_s, 0, 100000);
4644f05cddf9SRui Paulo 		}
4645f05cddf9SRui Paulo #endif /* CONFIG_NO_SCAN_PROCESSING */
46465b9c547cSRui Paulo 	} else if (fast_reconnect) {
46475b9c547cSRui Paulo 		/*
46485b9c547cSRui Paulo 		 * Could not reconnect to the same BSS due to network being
46495b9c547cSRui Paulo 		 * disabled. Use a new scan to match the alternative behavior
46505b9c547cSRui Paulo 		 * above, i.e., to continue automatic reconnection attempt in a
46515b9c547cSRui Paulo 		 * way that enforces disabled network rules.
46525b9c547cSRui Paulo 		 */
46535b9c547cSRui Paulo 		wpa_supplicant_req_scan(wpa_s, 0, 100000);
4654f05cddf9SRui Paulo 	}
465539beb93cSSam Leffler }
465639beb93cSSam Leffler 
465739beb93cSSam Leffler 
465839beb93cSSam Leffler #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
wpa_supplicant_delayed_mic_error_report(void * eloop_ctx,void * sock_ctx)4659f05cddf9SRui Paulo void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
466039beb93cSSam Leffler {
466139beb93cSSam Leffler 	struct wpa_supplicant *wpa_s = eloop_ctx;
466239beb93cSSam Leffler 
466339beb93cSSam Leffler 	if (!wpa_s->pending_mic_error_report)
466439beb93cSSam Leffler 		return;
466539beb93cSSam Leffler 
4666f05cddf9SRui Paulo 	wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
466739beb93cSSam Leffler 	wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
466839beb93cSSam Leffler 	wpa_s->pending_mic_error_report = 0;
466939beb93cSSam Leffler }
467039beb93cSSam Leffler #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
467139beb93cSSam Leffler 
467239beb93cSSam Leffler 
467339beb93cSSam Leffler static void
wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant * wpa_s,union wpa_event_data * data)467439beb93cSSam Leffler wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
467539beb93cSSam Leffler 					 union wpa_event_data *data)
467639beb93cSSam Leffler {
467739beb93cSSam Leffler 	int pairwise;
46785b9c547cSRui Paulo 	struct os_reltime t;
467939beb93cSSam Leffler 
468039beb93cSSam Leffler 	wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
468139beb93cSSam Leffler 	pairwise = (data && data->michael_mic_failure.unicast);
46825b9c547cSRui Paulo 	os_get_reltime(&t);
4683*a90b9d01SCy Schubert 	if ((os_reltime_initialized(&wpa_s->last_michael_mic_error) &&
46845b9c547cSRui Paulo 	     !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
468539beb93cSSam Leffler 	    wpa_s->pending_mic_error_report) {
468639beb93cSSam Leffler 		if (wpa_s->pending_mic_error_report) {
468739beb93cSSam Leffler 			/*
468839beb93cSSam Leffler 			 * Send the pending MIC error report immediately since
468939beb93cSSam Leffler 			 * we are going to start countermeasures and AP better
469039beb93cSSam Leffler 			 * do the same.
469139beb93cSSam Leffler 			 */
469239beb93cSSam Leffler 			wpa_sm_key_request(wpa_s->wpa, 1,
469339beb93cSSam Leffler 					   wpa_s->pending_mic_error_pairwise);
469439beb93cSSam Leffler 		}
469539beb93cSSam Leffler 
469639beb93cSSam Leffler 		/* Send the new MIC error report immediately since we are going
469739beb93cSSam Leffler 		 * to start countermeasures and AP better do the same.
469839beb93cSSam Leffler 		 */
469939beb93cSSam Leffler 		wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
470039beb93cSSam Leffler 
470139beb93cSSam Leffler 		/* initialize countermeasures */
470239beb93cSSam Leffler 		wpa_s->countermeasures = 1;
4703f05cddf9SRui Paulo 
4704c1d255d3SCy Schubert 		wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
4705f05cddf9SRui Paulo 
470639beb93cSSam Leffler 		wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
470739beb93cSSam Leffler 
470839beb93cSSam Leffler 		/*
470939beb93cSSam Leffler 		 * Need to wait for completion of request frame. We do not get
471039beb93cSSam Leffler 		 * any callback for the message completion, so just wait a
471139beb93cSSam Leffler 		 * short while and hope for the best. */
471239beb93cSSam Leffler 		os_sleep(0, 10000);
471339beb93cSSam Leffler 
471439beb93cSSam Leffler 		wpa_drv_set_countermeasures(wpa_s, 1);
471539beb93cSSam Leffler 		wpa_supplicant_deauthenticate(wpa_s,
471639beb93cSSam Leffler 					      WLAN_REASON_MICHAEL_MIC_FAILURE);
471739beb93cSSam Leffler 		eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
471839beb93cSSam Leffler 				     wpa_s, NULL);
471939beb93cSSam Leffler 		eloop_register_timeout(60, 0,
472039beb93cSSam Leffler 				       wpa_supplicant_stop_countermeasures,
472139beb93cSSam Leffler 				       wpa_s, NULL);
472239beb93cSSam Leffler 		/* TODO: mark the AP rejected for 60 second. STA is
472339beb93cSSam Leffler 		 * allowed to associate with another AP.. */
472439beb93cSSam Leffler 	} else {
472539beb93cSSam Leffler #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
472639beb93cSSam Leffler 		if (wpa_s->mic_errors_seen) {
472739beb93cSSam Leffler 			/*
472839beb93cSSam Leffler 			 * Reduce the effectiveness of Michael MIC error
472939beb93cSSam Leffler 			 * reports as a means for attacking against TKIP if
473039beb93cSSam Leffler 			 * more than one MIC failure is noticed with the same
473139beb93cSSam Leffler 			 * PTK. We delay the transmission of the reports by a
473239beb93cSSam Leffler 			 * random time between 0 and 60 seconds in order to
473339beb93cSSam Leffler 			 * force the attacker wait 60 seconds before getting
473439beb93cSSam Leffler 			 * the information on whether a frame resulted in a MIC
473539beb93cSSam Leffler 			 * failure.
473639beb93cSSam Leffler 			 */
473739beb93cSSam Leffler 			u8 rval[4];
473839beb93cSSam Leffler 			int sec;
473939beb93cSSam Leffler 
474039beb93cSSam Leffler 			if (os_get_random(rval, sizeof(rval)) < 0)
474139beb93cSSam Leffler 				sec = os_random() % 60;
474239beb93cSSam Leffler 			else
474339beb93cSSam Leffler 				sec = WPA_GET_BE32(rval) % 60;
4744f05cddf9SRui Paulo 			wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
4745f05cddf9SRui Paulo 				"report %d seconds", sec);
474639beb93cSSam Leffler 			wpa_s->pending_mic_error_report = 1;
474739beb93cSSam Leffler 			wpa_s->pending_mic_error_pairwise = pairwise;
474839beb93cSSam Leffler 			eloop_cancel_timeout(
474939beb93cSSam Leffler 				wpa_supplicant_delayed_mic_error_report,
475039beb93cSSam Leffler 				wpa_s, NULL);
475139beb93cSSam Leffler 			eloop_register_timeout(
475239beb93cSSam Leffler 				sec, os_random() % 1000000,
475339beb93cSSam Leffler 				wpa_supplicant_delayed_mic_error_report,
475439beb93cSSam Leffler 				wpa_s, NULL);
475539beb93cSSam Leffler 		} else {
475639beb93cSSam Leffler 			wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
475739beb93cSSam Leffler 		}
475839beb93cSSam Leffler #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
475939beb93cSSam Leffler 		wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
476039beb93cSSam Leffler #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
476139beb93cSSam Leffler 	}
47625b9c547cSRui Paulo 	wpa_s->last_michael_mic_error = t;
476339beb93cSSam Leffler 	wpa_s->mic_errors_seen++;
476439beb93cSSam Leffler }
476539beb93cSSam Leffler 
476639beb93cSSam Leffler 
47672aef0ff7SSam Leffler #ifdef CONFIG_TERMINATE_ONLASTIF
any_interfaces(struct wpa_supplicant * head)47682aef0ff7SSam Leffler static int any_interfaces(struct wpa_supplicant *head)
47692aef0ff7SSam Leffler {
47702aef0ff7SSam Leffler 	struct wpa_supplicant *wpa_s;
47712aef0ff7SSam Leffler 
47722aef0ff7SSam Leffler 	for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
47732aef0ff7SSam Leffler 		if (!wpa_s->interface_removed)
47742aef0ff7SSam Leffler 			return 1;
47752aef0ff7SSam Leffler 	return 0;
47762aef0ff7SSam Leffler }
47772aef0ff7SSam Leffler #endif /* CONFIG_TERMINATE_ONLASTIF */
47782aef0ff7SSam Leffler 
4779e28a4053SRui Paulo 
478039beb93cSSam Leffler static void
wpa_supplicant_event_interface_status(struct wpa_supplicant * wpa_s,union wpa_event_data * data)478139beb93cSSam Leffler wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
478239beb93cSSam Leffler 				      union wpa_event_data *data)
478339beb93cSSam Leffler {
478439beb93cSSam Leffler 	if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
478539beb93cSSam Leffler 		return;
478639beb93cSSam Leffler 
478739beb93cSSam Leffler 	switch (data->interface_status.ievent) {
478839beb93cSSam Leffler 	case EVENT_INTERFACE_ADDED:
478939beb93cSSam Leffler 		if (!wpa_s->interface_removed)
479039beb93cSSam Leffler 			break;
479139beb93cSSam Leffler 		wpa_s->interface_removed = 0;
4792f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
479339beb93cSSam Leffler 		if (wpa_supplicant_driver_init(wpa_s) < 0) {
4794f05cddf9SRui Paulo 			wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
4795f05cddf9SRui Paulo 				"driver after interface was added");
479639beb93cSSam Leffler 		}
4797325151a3SRui Paulo 
4798325151a3SRui Paulo #ifdef CONFIG_P2P
4799325151a3SRui Paulo 		if (!wpa_s->global->p2p &&
4800325151a3SRui Paulo 		    !wpa_s->global->p2p_disabled &&
4801325151a3SRui Paulo 		    !wpa_s->conf->p2p_disabled &&
4802325151a3SRui Paulo 		    (wpa_s->drv_flags &
4803325151a3SRui Paulo 		     WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
4804325151a3SRui Paulo 		    wpas_p2p_add_p2pdev_interface(
4805325151a3SRui Paulo 			    wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
4806325151a3SRui Paulo 			wpa_printf(MSG_INFO,
4807325151a3SRui Paulo 				   "P2P: Failed to enable P2P Device interface");
4808325151a3SRui Paulo 			/* Try to continue without. P2P will be disabled. */
4809325151a3SRui Paulo 		}
4810325151a3SRui Paulo #endif /* CONFIG_P2P */
4811325151a3SRui Paulo 
481239beb93cSSam Leffler 		break;
481339beb93cSSam Leffler 	case EVENT_INTERFACE_REMOVED:
4814f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
481539beb93cSSam Leffler 		wpa_s->interface_removed = 1;
481639beb93cSSam Leffler 		wpa_supplicant_mark_disassoc(wpa_s);
4817f05cddf9SRui Paulo 		wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
481839beb93cSSam Leffler 		l2_packet_deinit(wpa_s->l2);
481939beb93cSSam Leffler 		wpa_s->l2 = NULL;
4820325151a3SRui Paulo 
4821325151a3SRui Paulo #ifdef CONFIG_P2P
4822325151a3SRui Paulo 		if (wpa_s->global->p2p &&
4823325151a3SRui Paulo 		    wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
4824325151a3SRui Paulo 		    (wpa_s->drv_flags &
4825325151a3SRui Paulo 		     WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
4826325151a3SRui Paulo 			wpa_dbg(wpa_s, MSG_DEBUG,
4827325151a3SRui Paulo 				"Removing P2P Device interface");
4828325151a3SRui Paulo 			wpa_supplicant_remove_iface(
4829325151a3SRui Paulo 				wpa_s->global, wpa_s->global->p2p_init_wpa_s,
4830325151a3SRui Paulo 				0);
4831325151a3SRui Paulo 			wpa_s->global->p2p_init_wpa_s = NULL;
4832325151a3SRui Paulo 		}
4833325151a3SRui Paulo #endif /* CONFIG_P2P */
4834325151a3SRui Paulo 
4835780fb4a2SCy Schubert #ifdef CONFIG_MATCH_IFACE
4836780fb4a2SCy Schubert 		if (wpa_s->matched) {
4837780fb4a2SCy Schubert 			wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
4838780fb4a2SCy Schubert 			break;
4839780fb4a2SCy Schubert 		}
4840780fb4a2SCy Schubert #endif /* CONFIG_MATCH_IFACE */
4841780fb4a2SCy Schubert 
48422aef0ff7SSam Leffler #ifdef CONFIG_TERMINATE_ONLASTIF
48432aef0ff7SSam Leffler 		/* check if last interface */
48442aef0ff7SSam Leffler 		if (!any_interfaces(wpa_s->global->ifaces))
48452aef0ff7SSam Leffler 			eloop_terminate();
48462aef0ff7SSam Leffler #endif /* CONFIG_TERMINATE_ONLASTIF */
484739beb93cSSam Leffler 		break;
484839beb93cSSam Leffler 	}
484939beb93cSSam Leffler }
485039beb93cSSam Leffler 
485139beb93cSSam Leffler 
4852f05cddf9SRui Paulo #ifdef CONFIG_TDLS
wpa_supplicant_event_tdls(struct wpa_supplicant * wpa_s,union wpa_event_data * data)4853f05cddf9SRui Paulo static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
4854f05cddf9SRui Paulo 				      union wpa_event_data *data)
4855f05cddf9SRui Paulo {
4856f05cddf9SRui Paulo 	if (data == NULL)
4857f05cddf9SRui Paulo 		return;
4858f05cddf9SRui Paulo 	switch (data->tdls.oper) {
4859f05cddf9SRui Paulo 	case TDLS_REQUEST_SETUP:
48605b9c547cSRui Paulo 		wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
48615b9c547cSRui Paulo 		if (wpa_tdls_is_external_setup(wpa_s->wpa))
4862f05cddf9SRui Paulo 			wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
48635b9c547cSRui Paulo 		else
48645b9c547cSRui Paulo 			wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
4865f05cddf9SRui Paulo 		break;
4866f05cddf9SRui Paulo 	case TDLS_REQUEST_TEARDOWN:
48675b9c547cSRui Paulo 		if (wpa_tdls_is_external_setup(wpa_s->wpa))
48685b9c547cSRui Paulo 			wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
4869f05cddf9SRui Paulo 					       data->tdls.reason_code);
48705b9c547cSRui Paulo 		else
48715b9c547cSRui Paulo 			wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
48725b9c547cSRui Paulo 					  data->tdls.peer);
48735b9c547cSRui Paulo 		break;
48745b9c547cSRui Paulo 	case TDLS_REQUEST_DISCOVER:
48755b9c547cSRui Paulo 			wpa_tdls_send_discovery_request(wpa_s->wpa,
48765b9c547cSRui Paulo 							data->tdls.peer);
4877f05cddf9SRui Paulo 		break;
4878f05cddf9SRui Paulo 	}
4879f05cddf9SRui Paulo }
4880f05cddf9SRui Paulo #endif /* CONFIG_TDLS */
4881f05cddf9SRui Paulo 
4882f05cddf9SRui Paulo 
4883f05cddf9SRui Paulo #ifdef CONFIG_WNM
wpa_supplicant_event_wnm(struct wpa_supplicant * wpa_s,union wpa_event_data * data)4884f05cddf9SRui Paulo static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
4885f05cddf9SRui Paulo 				     union wpa_event_data *data)
4886f05cddf9SRui Paulo {
4887f05cddf9SRui Paulo 	if (data == NULL)
4888f05cddf9SRui Paulo 		return;
4889f05cddf9SRui Paulo 	switch (data->wnm.oper) {
4890f05cddf9SRui Paulo 	case WNM_OPER_SLEEP:
4891f05cddf9SRui Paulo 		wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
4892f05cddf9SRui Paulo 			   "(action=%d, intval=%d)",
4893f05cddf9SRui Paulo 			   data->wnm.sleep_action, data->wnm.sleep_intval);
4894f05cddf9SRui Paulo 		ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
4895f05cddf9SRui Paulo 					     data->wnm.sleep_intval, NULL);
4896f05cddf9SRui Paulo 		break;
4897f05cddf9SRui Paulo 	}
4898f05cddf9SRui Paulo }
4899f05cddf9SRui Paulo #endif /* CONFIG_WNM */
4900f05cddf9SRui Paulo 
4901f05cddf9SRui Paulo 
490239beb93cSSam Leffler #ifdef CONFIG_IEEE80211R
490339beb93cSSam Leffler static void
wpa_supplicant_event_ft_response(struct wpa_supplicant * wpa_s,union wpa_event_data * data)490439beb93cSSam Leffler wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
490539beb93cSSam Leffler 				 union wpa_event_data *data)
490639beb93cSSam Leffler {
490739beb93cSSam Leffler 	if (data == NULL)
490839beb93cSSam Leffler 		return;
490939beb93cSSam Leffler 
491039beb93cSSam Leffler 	if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
491139beb93cSSam Leffler 				    data->ft_ies.ies_len,
491239beb93cSSam Leffler 				    data->ft_ies.ft_action,
4913e28a4053SRui Paulo 				    data->ft_ies.target_ap,
4914e28a4053SRui Paulo 				    data->ft_ies.ric_ies,
4915e28a4053SRui Paulo 				    data->ft_ies.ric_ies_len) < 0) {
491639beb93cSSam Leffler 		/* TODO: prevent MLME/driver from trying to associate? */
491739beb93cSSam Leffler 	}
491839beb93cSSam Leffler }
491939beb93cSSam Leffler #endif /* CONFIG_IEEE80211R */
492039beb93cSSam Leffler 
492139beb93cSSam Leffler 
4922e28a4053SRui Paulo #ifdef CONFIG_IBSS_RSN
wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant * wpa_s,union wpa_event_data * data)4923e28a4053SRui Paulo static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
4924e28a4053SRui Paulo 						union wpa_event_data *data)
4925e28a4053SRui Paulo {
4926f05cddf9SRui Paulo 	struct wpa_ssid *ssid;
4927f05cddf9SRui Paulo 	if (wpa_s->wpa_state < WPA_ASSOCIATED)
4928f05cddf9SRui Paulo 		return;
4929e28a4053SRui Paulo 	if (data == NULL)
4930e28a4053SRui Paulo 		return;
4931f05cddf9SRui Paulo 	ssid = wpa_s->current_ssid;
4932f05cddf9SRui Paulo 	if (ssid == NULL)
4933f05cddf9SRui Paulo 		return;
4934f05cddf9SRui Paulo 	if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
4935f05cddf9SRui Paulo 		return;
4936f05cddf9SRui Paulo 
4937e28a4053SRui Paulo 	ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
4938e28a4053SRui Paulo }
49395b9c547cSRui Paulo 
49405b9c547cSRui Paulo 
wpa_supplicant_event_ibss_auth(struct wpa_supplicant * wpa_s,union wpa_event_data * data)49415b9c547cSRui Paulo static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
49425b9c547cSRui Paulo 					   union wpa_event_data *data)
49435b9c547cSRui Paulo {
49445b9c547cSRui Paulo 	struct wpa_ssid *ssid = wpa_s->current_ssid;
49455b9c547cSRui Paulo 
49465b9c547cSRui Paulo 	if (ssid == NULL)
49475b9c547cSRui Paulo 		return;
49485b9c547cSRui Paulo 
49495b9c547cSRui Paulo 	/* check if the ssid is correctly configured as IBSS/RSN */
49505b9c547cSRui Paulo 	if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
49515b9c547cSRui Paulo 		return;
49525b9c547cSRui Paulo 
49535b9c547cSRui Paulo 	ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
49545b9c547cSRui Paulo 			     data->rx_mgmt.frame_len);
49555b9c547cSRui Paulo }
4956e28a4053SRui Paulo #endif /* CONFIG_IBSS_RSN */
4957e28a4053SRui Paulo 
4958e28a4053SRui Paulo 
4959e28a4053SRui Paulo #ifdef CONFIG_IEEE80211R
ft_rx_action(struct wpa_supplicant * wpa_s,const u8 * data,size_t len)4960e28a4053SRui Paulo static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
4961e28a4053SRui Paulo 			 size_t len)
4962e28a4053SRui Paulo {
4963e28a4053SRui Paulo 	const u8 *sta_addr, *target_ap_addr;
4964e28a4053SRui Paulo 	u16 status;
4965e28a4053SRui Paulo 
4966e28a4053SRui Paulo 	wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
4967e28a4053SRui Paulo 	if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
4968e28a4053SRui Paulo 		return; /* only SME case supported for now */
4969e28a4053SRui Paulo 	if (len < 1 + 2 * ETH_ALEN + 2)
4970e28a4053SRui Paulo 		return;
4971e28a4053SRui Paulo 	if (data[0] != 2)
4972e28a4053SRui Paulo 		return; /* Only FT Action Response is supported for now */
4973e28a4053SRui Paulo 	sta_addr = data + 1;
4974e28a4053SRui Paulo 	target_ap_addr = data + 1 + ETH_ALEN;
4975e28a4053SRui Paulo 	status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
4976f05cddf9SRui Paulo 	wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
4977f05cddf9SRui Paulo 		MACSTR " TargetAP " MACSTR " status %u",
4978e28a4053SRui Paulo 		MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
4979e28a4053SRui Paulo 
4980*a90b9d01SCy Schubert 	if (!ether_addr_equal(sta_addr, wpa_s->own_addr)) {
4981f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
4982e28a4053SRui Paulo 			" in FT Action Response", MAC2STR(sta_addr));
4983e28a4053SRui Paulo 		return;
4984e28a4053SRui Paulo 	}
4985e28a4053SRui Paulo 
4986e28a4053SRui Paulo 	if (status) {
4987f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
4988e28a4053SRui Paulo 			"failure (status code %d)", status);
4989e28a4053SRui Paulo 		/* TODO: report error to FT code(?) */
4990e28a4053SRui Paulo 		return;
4991e28a4053SRui Paulo 	}
4992e28a4053SRui Paulo 
4993e28a4053SRui Paulo 	if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
4994e28a4053SRui Paulo 				    len - (1 + 2 * ETH_ALEN + 2), 1,
4995e28a4053SRui Paulo 				    target_ap_addr, NULL, 0) < 0)
4996e28a4053SRui Paulo 		return;
4997e28a4053SRui Paulo 
4998e28a4053SRui Paulo #ifdef CONFIG_SME
4999e28a4053SRui Paulo 	{
5000e28a4053SRui Paulo 		struct wpa_bss *bss;
5001e28a4053SRui Paulo 		bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
5002e28a4053SRui Paulo 		if (bss)
5003e28a4053SRui Paulo 			wpa_s->sme.freq = bss->freq;
5004e28a4053SRui Paulo 		wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
5005e28a4053SRui Paulo 		sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
5006e28a4053SRui Paulo 			      WLAN_AUTH_FT);
5007e28a4053SRui Paulo 	}
5008e28a4053SRui Paulo #endif /* CONFIG_SME */
5009e28a4053SRui Paulo }
5010e28a4053SRui Paulo #endif /* CONFIG_IEEE80211R */
5011e28a4053SRui Paulo 
5012e28a4053SRui Paulo 
wpa_supplicant_event_unprot_deauth(struct wpa_supplicant * wpa_s,struct unprot_deauth * e)5013f05cddf9SRui Paulo static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
5014f05cddf9SRui Paulo 					       struct unprot_deauth *e)
5015f05cddf9SRui Paulo {
5016f05cddf9SRui Paulo 	wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
5017f05cddf9SRui Paulo 		   "dropped: " MACSTR " -> " MACSTR
5018f05cddf9SRui Paulo 		   " (reason code %u)",
5019f05cddf9SRui Paulo 		   MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
5020f05cddf9SRui Paulo 	sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
5021f05cddf9SRui Paulo }
5022f05cddf9SRui Paulo 
5023f05cddf9SRui Paulo 
wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant * wpa_s,struct unprot_disassoc * e)5024f05cddf9SRui Paulo static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
5025f05cddf9SRui Paulo 						 struct unprot_disassoc *e)
5026f05cddf9SRui Paulo {
5027f05cddf9SRui Paulo 	wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
5028f05cddf9SRui Paulo 		   "dropped: " MACSTR " -> " MACSTR
5029f05cddf9SRui Paulo 		   " (reason code %u)",
5030f05cddf9SRui Paulo 		   MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
5031f05cddf9SRui Paulo 	sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
5032f05cddf9SRui Paulo }
5033f05cddf9SRui Paulo 
5034f05cddf9SRui Paulo 
wpas_event_disconnect(struct wpa_supplicant * wpa_s,const u8 * addr,u16 reason_code,int locally_generated,const u8 * ie,size_t ie_len,int deauth)50355b9c547cSRui Paulo static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
50365b9c547cSRui Paulo 				  u16 reason_code, int locally_generated,
50375b9c547cSRui Paulo 				  const u8 *ie, size_t ie_len, int deauth)
50385b9c547cSRui Paulo {
50395b9c547cSRui Paulo #ifdef CONFIG_AP
50405b9c547cSRui Paulo 	if (wpa_s->ap_iface && addr) {
50415b9c547cSRui Paulo 		hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
50425b9c547cSRui Paulo 		return;
50435b9c547cSRui Paulo 	}
50445b9c547cSRui Paulo 
50455b9c547cSRui Paulo 	if (wpa_s->ap_iface) {
50465b9c547cSRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
50475b9c547cSRui Paulo 		return;
50485b9c547cSRui Paulo 	}
50495b9c547cSRui Paulo #endif /* CONFIG_AP */
50505b9c547cSRui Paulo 
50515b9c547cSRui Paulo 	if (!locally_generated)
50525b9c547cSRui Paulo 		wpa_s->own_disconnect_req = 0;
50535b9c547cSRui Paulo 
50545b9c547cSRui Paulo 	wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
50555b9c547cSRui Paulo 
50565b9c547cSRui Paulo 	if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
50575b9c547cSRui Paulo 	      ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
50585b9c547cSRui Paulo 		(wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
50595b9c547cSRui Paulo 	       eapol_sm_failed(wpa_s->eapol))) &&
50605b9c547cSRui Paulo 	     !wpa_s->eap_expected_failure))
5061*a90b9d01SCy Schubert 		wpas_auth_failed(wpa_s, "AUTH_FAILED", addr);
50625b9c547cSRui Paulo 
50635b9c547cSRui Paulo #ifdef CONFIG_P2P
50645b9c547cSRui Paulo 	if (deauth && reason_code > 0) {
50655b9c547cSRui Paulo 		if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
50665b9c547cSRui Paulo 					  locally_generated) > 0) {
50675b9c547cSRui Paulo 			/*
50685b9c547cSRui Paulo 			 * The interface was removed, so cannot continue
50695b9c547cSRui Paulo 			 * processing any additional operations after this.
50705b9c547cSRui Paulo 			 */
50715b9c547cSRui Paulo 			return;
50725b9c547cSRui Paulo 		}
50735b9c547cSRui Paulo 	}
50745b9c547cSRui Paulo #endif /* CONFIG_P2P */
50755b9c547cSRui Paulo 
50765b9c547cSRui Paulo 	wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
50775b9c547cSRui Paulo 					     locally_generated);
50785b9c547cSRui Paulo }
50795b9c547cSRui Paulo 
50805b9c547cSRui Paulo 
wpas_event_disassoc(struct wpa_supplicant * wpa_s,struct disassoc_info * info)50815b9c547cSRui Paulo static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
50825b9c547cSRui Paulo 				struct disassoc_info *info)
50835b9c547cSRui Paulo {
50845b9c547cSRui Paulo 	u16 reason_code = 0;
50855b9c547cSRui Paulo 	int locally_generated = 0;
50865b9c547cSRui Paulo 	const u8 *addr = NULL;
50875b9c547cSRui Paulo 	const u8 *ie = NULL;
50885b9c547cSRui Paulo 	size_t ie_len = 0;
50895b9c547cSRui Paulo 
50905b9c547cSRui Paulo 	wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
50915b9c547cSRui Paulo 
50925b9c547cSRui Paulo 	if (info) {
50935b9c547cSRui Paulo 		addr = info->addr;
50945b9c547cSRui Paulo 		ie = info->ie;
50955b9c547cSRui Paulo 		ie_len = info->ie_len;
50965b9c547cSRui Paulo 		reason_code = info->reason_code;
50975b9c547cSRui Paulo 		locally_generated = info->locally_generated;
5098206b73d0SCy Schubert 		wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
5099206b73d0SCy Schubert 			reason2str(reason_code),
5100206b73d0SCy Schubert 			locally_generated ? " locally_generated=1" : "");
51015b9c547cSRui Paulo 		if (addr)
51025b9c547cSRui Paulo 			wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
51035b9c547cSRui Paulo 				MAC2STR(addr));
51045b9c547cSRui Paulo 		wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
51055b9c547cSRui Paulo 			    ie, ie_len);
51065b9c547cSRui Paulo 	}
51075b9c547cSRui Paulo 
51085b9c547cSRui Paulo #ifdef CONFIG_AP
51095b9c547cSRui Paulo 	if (wpa_s->ap_iface && info && info->addr) {
51105b9c547cSRui Paulo 		hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
51115b9c547cSRui Paulo 		return;
51125b9c547cSRui Paulo 	}
51135b9c547cSRui Paulo 
51145b9c547cSRui Paulo 	if (wpa_s->ap_iface) {
51155b9c547cSRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
51165b9c547cSRui Paulo 		return;
51175b9c547cSRui Paulo 	}
51185b9c547cSRui Paulo #endif /* CONFIG_AP */
51195b9c547cSRui Paulo 
51205b9c547cSRui Paulo #ifdef CONFIG_P2P
51215b9c547cSRui Paulo 	if (info) {
51225b9c547cSRui Paulo 		wpas_p2p_disassoc_notif(
51235b9c547cSRui Paulo 			wpa_s, info->addr, reason_code, info->ie, info->ie_len,
51245b9c547cSRui Paulo 			locally_generated);
51255b9c547cSRui Paulo 	}
51265b9c547cSRui Paulo #endif /* CONFIG_P2P */
51275b9c547cSRui Paulo 
51285b9c547cSRui Paulo 	if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
51295b9c547cSRui Paulo 		sme_event_disassoc(wpa_s, info);
51305b9c547cSRui Paulo 
51315b9c547cSRui Paulo 	wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
51325b9c547cSRui Paulo 			      ie, ie_len, 0);
51335b9c547cSRui Paulo }
51345b9c547cSRui Paulo 
51355b9c547cSRui Paulo 
wpas_event_deauth(struct wpa_supplicant * wpa_s,struct deauth_info * info)51365b9c547cSRui Paulo static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
51375b9c547cSRui Paulo 			      struct deauth_info *info)
51385b9c547cSRui Paulo {
51395b9c547cSRui Paulo 	u16 reason_code = 0;
51405b9c547cSRui Paulo 	int locally_generated = 0;
51415b9c547cSRui Paulo 	const u8 *addr = NULL;
51425b9c547cSRui Paulo 	const u8 *ie = NULL;
51435b9c547cSRui Paulo 	size_t ie_len = 0;
51445b9c547cSRui Paulo 
51455b9c547cSRui Paulo 	wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
51465b9c547cSRui Paulo 
51475b9c547cSRui Paulo 	if (info) {
51485b9c547cSRui Paulo 		addr = info->addr;
51495b9c547cSRui Paulo 		ie = info->ie;
51505b9c547cSRui Paulo 		ie_len = info->ie_len;
51515b9c547cSRui Paulo 		reason_code = info->reason_code;
51525b9c547cSRui Paulo 		locally_generated = info->locally_generated;
5153206b73d0SCy Schubert 		wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
5154206b73d0SCy Schubert 			reason_code, reason2str(reason_code),
5155206b73d0SCy Schubert 			locally_generated ? " locally_generated=1" : "");
51565b9c547cSRui Paulo 		if (addr) {
51575b9c547cSRui Paulo 			wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
51585b9c547cSRui Paulo 				MAC2STR(addr));
51595b9c547cSRui Paulo 		}
51605b9c547cSRui Paulo 		wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
51615b9c547cSRui Paulo 			    ie, ie_len);
51625b9c547cSRui Paulo 	}
51635b9c547cSRui Paulo 
51645b9c547cSRui Paulo 	wpa_reset_ft_completed(wpa_s->wpa);
51655b9c547cSRui Paulo 
51665b9c547cSRui Paulo 	wpas_event_disconnect(wpa_s, addr, reason_code,
51675b9c547cSRui Paulo 			      locally_generated, ie, ie_len, 1);
51685b9c547cSRui Paulo }
51695b9c547cSRui Paulo 
51705b9c547cSRui Paulo 
reg_init_str(enum reg_change_initiator init)51715b9c547cSRui Paulo static const char * reg_init_str(enum reg_change_initiator init)
51725b9c547cSRui Paulo {
51735b9c547cSRui Paulo 	switch (init) {
51745b9c547cSRui Paulo 	case REGDOM_SET_BY_CORE:
51755b9c547cSRui Paulo 		return "CORE";
51765b9c547cSRui Paulo 	case REGDOM_SET_BY_USER:
51775b9c547cSRui Paulo 		return "USER";
51785b9c547cSRui Paulo 	case REGDOM_SET_BY_DRIVER:
51795b9c547cSRui Paulo 		return "DRIVER";
51805b9c547cSRui Paulo 	case REGDOM_SET_BY_COUNTRY_IE:
51815b9c547cSRui Paulo 		return "COUNTRY_IE";
51825b9c547cSRui Paulo 	case REGDOM_BEACON_HINT:
51835b9c547cSRui Paulo 		return "BEACON_HINT";
51845b9c547cSRui Paulo 	}
51855b9c547cSRui Paulo 	return "?";
51865b9c547cSRui Paulo }
51875b9c547cSRui Paulo 
51885b9c547cSRui Paulo 
reg_type_str(enum reg_type type)51895b9c547cSRui Paulo static const char * reg_type_str(enum reg_type type)
51905b9c547cSRui Paulo {
51915b9c547cSRui Paulo 	switch (type) {
51925b9c547cSRui Paulo 	case REGDOM_TYPE_UNKNOWN:
51935b9c547cSRui Paulo 		return "UNKNOWN";
51945b9c547cSRui Paulo 	case REGDOM_TYPE_COUNTRY:
51955b9c547cSRui Paulo 		return "COUNTRY";
51965b9c547cSRui Paulo 	case REGDOM_TYPE_WORLD:
51975b9c547cSRui Paulo 		return "WORLD";
51985b9c547cSRui Paulo 	case REGDOM_TYPE_CUSTOM_WORLD:
51995b9c547cSRui Paulo 		return "CUSTOM_WORLD";
52005b9c547cSRui Paulo 	case REGDOM_TYPE_INTERSECTION:
52015b9c547cSRui Paulo 		return "INTERSECTION";
52025b9c547cSRui Paulo 	}
52035b9c547cSRui Paulo 	return "?";
52045b9c547cSRui Paulo }
52055b9c547cSRui Paulo 
52065b9c547cSRui Paulo 
wpas_beacon_hint(struct wpa_supplicant * wpa_s,const char * title,struct frequency_attrs * attrs)5207*a90b9d01SCy Schubert static void wpas_beacon_hint(struct wpa_supplicant *wpa_s, const char *title,
5208*a90b9d01SCy Schubert 			     struct frequency_attrs *attrs)
5209*a90b9d01SCy Schubert {
5210*a90b9d01SCy Schubert 	if (!attrs->freq)
5211*a90b9d01SCy Schubert 		return;
5212*a90b9d01SCy Schubert 	wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_BEACON_HINT
5213*a90b9d01SCy Schubert 		"%s freq=%u max_tx_power=%u%s%s%s",
5214*a90b9d01SCy Schubert 		title, attrs->freq, attrs->max_tx_power,
5215*a90b9d01SCy Schubert 		attrs->disabled ? " disabled=1" : "",
5216*a90b9d01SCy Schubert 		attrs->no_ir ? " no_ir=1" : "",
5217*a90b9d01SCy Schubert 		attrs->radar ? " radar=1" : "");
5218*a90b9d01SCy Schubert }
5219*a90b9d01SCy Schubert 
5220*a90b9d01SCy Schubert 
wpa_supplicant_update_channel_list(struct wpa_supplicant * wpa_s,struct channel_list_changed * info)52214bc52338SCy Schubert void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
52224bc52338SCy Schubert 					struct channel_list_changed *info)
52235b9c547cSRui Paulo {
52245b9c547cSRui Paulo 	struct wpa_supplicant *ifs;
522585732ac8SCy Schubert 	u8 dfs_domain;
52265b9c547cSRui Paulo 
5227780fb4a2SCy Schubert 	/*
5228780fb4a2SCy Schubert 	 * To allow backwards compatibility with higher level layers that
5229780fb4a2SCy Schubert 	 * assumed the REGDOM_CHANGE event is sent over the initially added
5230780fb4a2SCy Schubert 	 * interface. Find the highest parent of this interface and use it to
5231780fb4a2SCy Schubert 	 * send the event.
5232780fb4a2SCy Schubert 	 */
5233780fb4a2SCy Schubert 	for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
5234780fb4a2SCy Schubert 		;
5235780fb4a2SCy Schubert 
52364bc52338SCy Schubert 	if (info) {
52374bc52338SCy Schubert 		wpa_msg(ifs, MSG_INFO,
52384bc52338SCy Schubert 			WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
52395b9c547cSRui Paulo 			reg_init_str(info->initiator), reg_type_str(info->type),
52405b9c547cSRui Paulo 			info->alpha2[0] ? " alpha2=" : "",
52415b9c547cSRui Paulo 			info->alpha2[0] ? info->alpha2 : "");
5242*a90b9d01SCy Schubert 
5243*a90b9d01SCy Schubert 		if (info->initiator == REGDOM_BEACON_HINT) {
5244*a90b9d01SCy Schubert 			wpas_beacon_hint(ifs, "before",
5245*a90b9d01SCy Schubert 					 &info->beacon_hint_before);
5246*a90b9d01SCy Schubert 			wpas_beacon_hint(ifs, "after",
5247*a90b9d01SCy Schubert 					 &info->beacon_hint_after);
5248*a90b9d01SCy Schubert 		}
52494bc52338SCy Schubert 	}
52505b9c547cSRui Paulo 
52515b9c547cSRui Paulo 	if (wpa_s->drv_priv == NULL)
52525b9c547cSRui Paulo 		return; /* Ignore event during drv initialization */
52535b9c547cSRui Paulo 
52545b9c547cSRui Paulo 	dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
52555b9c547cSRui Paulo 			 radio_list) {
5256*a90b9d01SCy Schubert 		bool was_6ghz_enabled;
5257*a90b9d01SCy Schubert 
52585b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
52595b9c547cSRui Paulo 			   ifs->ifname);
52605b9c547cSRui Paulo 		free_hw_features(ifs);
52615b9c547cSRui Paulo 		ifs->hw.modes = wpa_drv_get_hw_feature_data(
526285732ac8SCy Schubert 			ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
5263325151a3SRui Paulo 
5264*a90b9d01SCy Schubert 		was_6ghz_enabled = ifs->is_6ghz_enabled;
5265*a90b9d01SCy Schubert 		ifs->is_6ghz_enabled = wpas_is_6ghz_supported(ifs, true);
5266*a90b9d01SCy Schubert 
5267780fb4a2SCy Schubert 		/* Restart PNO/sched_scan with updated channel list */
5268780fb4a2SCy Schubert 		if (ifs->pno) {
5269780fb4a2SCy Schubert 			wpas_stop_pno(ifs);
5270780fb4a2SCy Schubert 			wpas_start_pno(ifs);
5271780fb4a2SCy Schubert 		} else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
5272780fb4a2SCy Schubert 			wpa_dbg(ifs, MSG_DEBUG,
5273780fb4a2SCy Schubert 				"Channel list changed - restart sched_scan");
5274780fb4a2SCy Schubert 			wpas_scan_restart_sched_scan(ifs);
5275*a90b9d01SCy Schubert 		} else if (!was_6ghz_enabled && ifs->is_6ghz_enabled) {
5276*a90b9d01SCy Schubert 			wpa_dbg(ifs, MSG_INFO,
5277*a90b9d01SCy Schubert 				"Channel list changed: 6 GHz was enabled");
5278*a90b9d01SCy Schubert 
5279*a90b9d01SCy Schubert 			ifs->crossed_6ghz_dom = true;
5280780fb4a2SCy Schubert 		}
52815b9c547cSRui Paulo 	}
5282325151a3SRui Paulo 
5283325151a3SRui Paulo 	wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
52845b9c547cSRui Paulo }
52855b9c547cSRui Paulo 
52865b9c547cSRui Paulo 
wpas_event_rx_mgmt_action(struct wpa_supplicant * wpa_s,const u8 * frame,size_t len,int freq,int rssi)52875b9c547cSRui Paulo static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
52885b9c547cSRui Paulo 				      const u8 *frame, size_t len, int freq,
52895b9c547cSRui Paulo 				      int rssi)
52905b9c547cSRui Paulo {
52915b9c547cSRui Paulo 	const struct ieee80211_mgmt *mgmt;
52925b9c547cSRui Paulo 	const u8 *payload;
52935b9c547cSRui Paulo 	size_t plen;
52945b9c547cSRui Paulo 	u8 category;
52955b9c547cSRui Paulo 
52965b9c547cSRui Paulo 	if (len < IEEE80211_HDRLEN + 2)
52975b9c547cSRui Paulo 		return;
52985b9c547cSRui Paulo 
52995b9c547cSRui Paulo 	mgmt = (const struct ieee80211_mgmt *) frame;
53005b9c547cSRui Paulo 	payload = frame + IEEE80211_HDRLEN;
53015b9c547cSRui Paulo 	category = *payload++;
53025b9c547cSRui Paulo 	plen = len - IEEE80211_HDRLEN - 1;
53035b9c547cSRui Paulo 
53045b9c547cSRui Paulo 	wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
53055b9c547cSRui Paulo 		" Category=%u DataLen=%d freq=%d MHz",
53065b9c547cSRui Paulo 		MAC2STR(mgmt->sa), category, (int) plen, freq);
53075b9c547cSRui Paulo 
5308*a90b9d01SCy Schubert #ifndef CONFIG_NO_WMM_AC
53095b9c547cSRui Paulo 	if (category == WLAN_ACTION_WMM) {
53105b9c547cSRui Paulo 		wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
53115b9c547cSRui Paulo 		return;
53125b9c547cSRui Paulo 	}
5313*a90b9d01SCy Schubert #endif /* CONFIG_NO_WMM_AC */
53145b9c547cSRui Paulo 
53155b9c547cSRui Paulo #ifdef CONFIG_IEEE80211R
53165b9c547cSRui Paulo 	if (category == WLAN_ACTION_FT) {
53175b9c547cSRui Paulo 		ft_rx_action(wpa_s, payload, plen);
53185b9c547cSRui Paulo 		return;
53195b9c547cSRui Paulo 	}
53205b9c547cSRui Paulo #endif /* CONFIG_IEEE80211R */
53215b9c547cSRui Paulo 
53225b9c547cSRui Paulo #ifdef CONFIG_SME
53235b9c547cSRui Paulo 	if (category == WLAN_ACTION_SA_QUERY) {
5324c1d255d3SCy Schubert 		sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen);
53255b9c547cSRui Paulo 		return;
53265b9c547cSRui Paulo 	}
53275b9c547cSRui Paulo #endif /* CONFIG_SME */
53285b9c547cSRui Paulo 
53295b9c547cSRui Paulo #ifdef CONFIG_WNM
53305b9c547cSRui Paulo 	if (mgmt->u.action.category == WLAN_ACTION_WNM) {
53315b9c547cSRui Paulo 		ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
53325b9c547cSRui Paulo 		return;
53335b9c547cSRui Paulo 	}
53345b9c547cSRui Paulo #endif /* CONFIG_WNM */
53355b9c547cSRui Paulo 
53365b9c547cSRui Paulo #ifdef CONFIG_GAS
53375b9c547cSRui Paulo 	if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
53385b9c547cSRui Paulo 	     mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
53395b9c547cSRui Paulo 	    gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
53405b9c547cSRui Paulo 			 mgmt->u.action.category,
53415b9c547cSRui Paulo 			 payload, plen, freq) == 0)
53425b9c547cSRui Paulo 		return;
53435b9c547cSRui Paulo #endif /* CONFIG_GAS */
53445b9c547cSRui Paulo 
534585732ac8SCy Schubert #ifdef CONFIG_GAS_SERVER
534685732ac8SCy Schubert 	if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
534785732ac8SCy Schubert 	     mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
534885732ac8SCy Schubert 	    gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
534985732ac8SCy Schubert 			  mgmt->u.action.category,
535085732ac8SCy Schubert 			  payload, plen, freq) == 0)
535185732ac8SCy Schubert 		return;
535285732ac8SCy Schubert #endif /* CONFIG_GAS_SERVER */
535385732ac8SCy Schubert 
53545b9c547cSRui Paulo #ifdef CONFIG_TDLS
53555b9c547cSRui Paulo 	if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
53565b9c547cSRui Paulo 	    payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
53575b9c547cSRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG,
53585b9c547cSRui Paulo 			"TDLS: Received Discovery Response from " MACSTR,
53595b9c547cSRui Paulo 			MAC2STR(mgmt->sa));
5360*a90b9d01SCy Schubert 		if (wpa_s->valid_links &&
5361*a90b9d01SCy Schubert 		    wpa_tdls_process_discovery_response(wpa_s->wpa, mgmt->sa,
5362*a90b9d01SCy Schubert 							&payload[1], plen - 1))
5363*a90b9d01SCy Schubert 			wpa_dbg(wpa_s, MSG_ERROR,
5364*a90b9d01SCy Schubert 				"TDLS: Discovery Response process failed for "
5365*a90b9d01SCy Schubert 				MACSTR, MAC2STR(mgmt->sa));
53665b9c547cSRui Paulo 		return;
53675b9c547cSRui Paulo 	}
53685b9c547cSRui Paulo #endif /* CONFIG_TDLS */
53695b9c547cSRui Paulo 
53705b9c547cSRui Paulo #ifdef CONFIG_INTERWORKING
53715b9c547cSRui Paulo 	if (category == WLAN_ACTION_QOS && plen >= 1 &&
53725b9c547cSRui Paulo 	    payload[0] == QOS_QOS_MAP_CONFIG) {
53735b9c547cSRui Paulo 		const u8 *pos = payload + 1;
53745b9c547cSRui Paulo 		size_t qlen = plen - 1;
53755b9c547cSRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
53765b9c547cSRui Paulo 			MACSTR, MAC2STR(mgmt->sa));
5377*a90b9d01SCy Schubert 		if (ether_addr_equal(mgmt->sa, wpa_s->bssid) &&
53785b9c547cSRui Paulo 		    qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
53795b9c547cSRui Paulo 		    pos[1] <= qlen - 2 && pos[1] >= 16)
53805b9c547cSRui Paulo 			wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
53815b9c547cSRui Paulo 		return;
53825b9c547cSRui Paulo 	}
53835b9c547cSRui Paulo #endif /* CONFIG_INTERWORKING */
53845b9c547cSRui Paulo 
5385*a90b9d01SCy Schubert #ifndef CONFIG_NO_RRM
53865b9c547cSRui Paulo 	if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
5387780fb4a2SCy Schubert 	    payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
5388780fb4a2SCy Schubert 		wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
538985732ac8SCy Schubert 							  mgmt->da,
5390780fb4a2SCy Schubert 							  payload + 1,
5391780fb4a2SCy Schubert 							  plen - 1);
5392780fb4a2SCy Schubert 		return;
5393780fb4a2SCy Schubert 	}
5394780fb4a2SCy Schubert 
5395780fb4a2SCy Schubert 	if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
53965b9c547cSRui Paulo 	    payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
53975b9c547cSRui Paulo 		wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
53985b9c547cSRui Paulo 		return;
53995b9c547cSRui Paulo 	}
54005b9c547cSRui Paulo 
54015b9c547cSRui Paulo 	if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
54025b9c547cSRui Paulo 	    payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
54035b9c547cSRui Paulo 		wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
54045b9c547cSRui Paulo 							 payload + 1, plen - 1,
54055b9c547cSRui Paulo 							 rssi);
54065b9c547cSRui Paulo 		return;
54075b9c547cSRui Paulo 	}
5408*a90b9d01SCy Schubert #endif /* CONFIG_NO_RRM */
54095b9c547cSRui Paulo 
5410325151a3SRui Paulo #ifdef CONFIG_FST
5411325151a3SRui Paulo 	if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
5412325151a3SRui Paulo 		fst_rx_action(wpa_s->fst, mgmt, len);
5413325151a3SRui Paulo 		return;
5414325151a3SRui Paulo 	}
5415325151a3SRui Paulo #endif /* CONFIG_FST */
5416325151a3SRui Paulo 
5417*a90b9d01SCy Schubert #ifdef CONFIG_NAN_USD
5418*a90b9d01SCy Schubert 	if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
5419*a90b9d01SCy Schubert 	    payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
5420*a90b9d01SCy Schubert 	    WPA_GET_BE32(&payload[1]) == NAN_SDF_VENDOR_TYPE) {
5421*a90b9d01SCy Schubert 		payload += 5;
5422*a90b9d01SCy Schubert 		plen -= 5;
5423*a90b9d01SCy Schubert 		wpas_nan_usd_rx_sdf(wpa_s, mgmt->sa, freq, payload, plen);
5424*a90b9d01SCy Schubert 		return;
5425*a90b9d01SCy Schubert 	}
5426*a90b9d01SCy Schubert #endif /* CONFIG_NAN_USD */
5427*a90b9d01SCy Schubert 
542885732ac8SCy Schubert #ifdef CONFIG_DPP
542985732ac8SCy Schubert 	if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
543085732ac8SCy Schubert 	    payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
543185732ac8SCy Schubert 	    WPA_GET_BE24(&payload[1]) == OUI_WFA &&
543285732ac8SCy Schubert 	    payload[4] == DPP_OUI_TYPE) {
543385732ac8SCy Schubert 		payload++;
543485732ac8SCy Schubert 		plen--;
543585732ac8SCy Schubert 		wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
543685732ac8SCy Schubert 		return;
543785732ac8SCy Schubert 	}
543885732ac8SCy Schubert #endif /* CONFIG_DPP */
543985732ac8SCy Schubert 
5440*a90b9d01SCy Schubert #ifndef CONFIG_NO_ROBUST_AV
5441c1d255d3SCy Schubert 	if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
54424b72b91aSCy Schubert 	    payload[0] == ROBUST_AV_SCS_RESP) {
54434b72b91aSCy Schubert 		wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa,
54444b72b91aSCy Schubert 						      payload + 1, plen - 1);
54454b72b91aSCy Schubert 		return;
54464b72b91aSCy Schubert 	}
54474b72b91aSCy Schubert 
54484b72b91aSCy Schubert 	if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
5449c1d255d3SCy Schubert 	    payload[0] == ROBUST_AV_MSCS_RESP) {
5450c1d255d3SCy Schubert 		wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
5451c1d255d3SCy Schubert 						  payload + 1, plen - 1);
5452c1d255d3SCy Schubert 		return;
5453c1d255d3SCy Schubert 	}
5454c1d255d3SCy Schubert 
54554b72b91aSCy Schubert 	if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 &&
54564b72b91aSCy Schubert 	    WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) {
54574b72b91aSCy Schubert 		wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa,
54584b72b91aSCy Schubert 						 payload + 4, plen - 4);
54594b72b91aSCy Schubert 		return;
54604b72b91aSCy Schubert 	}
5461*a90b9d01SCy Schubert #endif /* CONFIG_NO_ROBUST_AV */
54624b72b91aSCy Schubert 
54635b9c547cSRui Paulo 	wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
54645b9c547cSRui Paulo 			   category, payload, plen, freq);
54655b9c547cSRui Paulo 	if (wpa_s->ifmsh)
54665b9c547cSRui Paulo 		mesh_mpm_action_rx(wpa_s, mgmt, len);
54675b9c547cSRui Paulo }
54685b9c547cSRui Paulo 
54695b9c547cSRui Paulo 
wpa_supplicant_notify_avoid_freq(struct wpa_supplicant * wpa_s,union wpa_event_data * event)54705b9c547cSRui Paulo static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
54715b9c547cSRui Paulo 					     union wpa_event_data *event)
54725b9c547cSRui Paulo {
54735b9c547cSRui Paulo 	struct wpa_freq_range_list *list;
54745b9c547cSRui Paulo 	char *str = NULL;
54755b9c547cSRui Paulo 
54765b9c547cSRui Paulo 	list = &event->freq_range;
54775b9c547cSRui Paulo 
54785b9c547cSRui Paulo 	if (list->num)
54795b9c547cSRui Paulo 		str = freq_range_list_str(list);
54805b9c547cSRui Paulo 	wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
54815b9c547cSRui Paulo 		str ? str : "");
54825b9c547cSRui Paulo 
54835b9c547cSRui Paulo #ifdef CONFIG_P2P
54845b9c547cSRui Paulo 	if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
54855b9c547cSRui Paulo 		wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
54865b9c547cSRui Paulo 			__func__);
54875b9c547cSRui Paulo 	} else {
54885b9c547cSRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
54895b9c547cSRui Paulo 
5490325151a3SRui Paulo 		/*
5491325151a3SRui Paulo 		 * The update channel flow will also take care of moving a GO
5492325151a3SRui Paulo 		 * from the unsafe frequency if needed.
5493325151a3SRui Paulo 		 */
5494325151a3SRui Paulo 		wpas_p2p_update_channel_list(wpa_s,
5495325151a3SRui Paulo 					     WPAS_P2P_CHANNEL_UPDATE_AVOID);
54965b9c547cSRui Paulo 	}
54975b9c547cSRui Paulo #endif /* CONFIG_P2P */
54985b9c547cSRui Paulo 
54995b9c547cSRui Paulo 	os_free(str);
55005b9c547cSRui Paulo }
55015b9c547cSRui Paulo 
55025b9c547cSRui Paulo 
wpa_supplicant_event_port_authorized(struct wpa_supplicant * wpa_s)550385732ac8SCy Schubert static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
55045b9c547cSRui Paulo {
55055b9c547cSRui Paulo 	if (wpa_s->wpa_state == WPA_ASSOCIATED) {
55065b9c547cSRui Paulo 		wpa_supplicant_cancel_auth_timeout(wpa_s);
55075b9c547cSRui Paulo 		wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
5508c1d255d3SCy Schubert 		eapol_sm_notify_portValid(wpa_s->eapol, true);
5509c1d255d3SCy Schubert 		eapol_sm_notify_eap_success(wpa_s->eapol, true);
5510c1d255d3SCy Schubert 		wpa_s->drv_authorized_port = 1;
55115b9c547cSRui Paulo 	}
551285732ac8SCy Schubert }
551385732ac8SCy Schubert 
551485732ac8SCy Schubert 
wpas_event_cac_ms(const struct wpa_supplicant * wpa_s,int freq)551585732ac8SCy Schubert static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
551685732ac8SCy Schubert 				      int freq)
551785732ac8SCy Schubert {
551885732ac8SCy Schubert 	size_t i;
551985732ac8SCy Schubert 	int j;
552085732ac8SCy Schubert 
552185732ac8SCy Schubert 	for (i = 0; i < wpa_s->hw.num_modes; i++) {
552285732ac8SCy Schubert 		const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
552385732ac8SCy Schubert 
552485732ac8SCy Schubert 		for (j = 0; j < mode->num_channels; j++) {
552585732ac8SCy Schubert 			const struct hostapd_channel_data *chan;
552685732ac8SCy Schubert 
552785732ac8SCy Schubert 			chan = &mode->channels[j];
552885732ac8SCy Schubert 			if (chan->freq == freq)
552985732ac8SCy Schubert 				return chan->dfs_cac_ms;
553085732ac8SCy Schubert 		}
553185732ac8SCy Schubert 	}
553285732ac8SCy Schubert 
553385732ac8SCy Schubert 	return 0;
553485732ac8SCy Schubert }
553585732ac8SCy Schubert 
553685732ac8SCy Schubert 
wpas_event_dfs_cac_started(struct wpa_supplicant * wpa_s,struct dfs_event * radar)553785732ac8SCy Schubert static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
553885732ac8SCy Schubert 				       struct dfs_event *radar)
553985732ac8SCy Schubert {
554085732ac8SCy Schubert #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
55414bc52338SCy Schubert 	if (wpa_s->ap_iface || wpa_s->ifmsh) {
554285732ac8SCy Schubert 		wpas_ap_event_dfs_cac_started(wpa_s, radar);
554385732ac8SCy Schubert 	} else
554485732ac8SCy Schubert #endif /* NEED_AP_MLME && CONFIG_AP */
554585732ac8SCy Schubert 	{
554685732ac8SCy Schubert 		unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
554785732ac8SCy Schubert 
554885732ac8SCy Schubert 		cac_time /= 1000; /* convert from ms to sec */
554985732ac8SCy Schubert 		if (!cac_time)
555085732ac8SCy Schubert 			cac_time = 10 * 60; /* max timeout: 10 minutes */
555185732ac8SCy Schubert 
555285732ac8SCy Schubert 		/* Restart auth timeout: CAC time added to initial timeout */
555385732ac8SCy Schubert 		wpas_auth_timeout_restart(wpa_s, cac_time);
555485732ac8SCy Schubert 	}
555585732ac8SCy Schubert }
555685732ac8SCy Schubert 
555785732ac8SCy Schubert 
wpas_event_dfs_cac_finished(struct wpa_supplicant * wpa_s,struct dfs_event * radar)555885732ac8SCy Schubert static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
555985732ac8SCy Schubert 					struct dfs_event *radar)
556085732ac8SCy Schubert {
556185732ac8SCy Schubert #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
55624bc52338SCy Schubert 	if (wpa_s->ap_iface || wpa_s->ifmsh) {
556385732ac8SCy Schubert 		wpas_ap_event_dfs_cac_finished(wpa_s, radar);
556485732ac8SCy Schubert 	} else
556585732ac8SCy Schubert #endif /* NEED_AP_MLME && CONFIG_AP */
556685732ac8SCy Schubert 	{
556785732ac8SCy Schubert 		/* Restart auth timeout with original value after CAC is
556885732ac8SCy Schubert 		 * finished */
556985732ac8SCy Schubert 		wpas_auth_timeout_restart(wpa_s, 0);
557085732ac8SCy Schubert 	}
557185732ac8SCy Schubert }
557285732ac8SCy Schubert 
557385732ac8SCy Schubert 
wpas_event_dfs_cac_aborted(struct wpa_supplicant * wpa_s,struct dfs_event * radar)557485732ac8SCy Schubert static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
557585732ac8SCy Schubert 				       struct dfs_event *radar)
557685732ac8SCy Schubert {
557785732ac8SCy Schubert #if defined(NEED_AP_MLME) && defined(CONFIG_AP)
55784bc52338SCy Schubert 	if (wpa_s->ap_iface || wpa_s->ifmsh) {
557985732ac8SCy Schubert 		wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
558085732ac8SCy Schubert 	} else
558185732ac8SCy Schubert #endif /* NEED_AP_MLME && CONFIG_AP */
558285732ac8SCy Schubert 	{
558385732ac8SCy Schubert 		/* Restart auth timeout with original value after CAC is
558485732ac8SCy Schubert 		 * aborted */
558585732ac8SCy Schubert 		wpas_auth_timeout_restart(wpa_s, 0);
558685732ac8SCy Schubert 	}
558785732ac8SCy Schubert }
558885732ac8SCy Schubert 
558985732ac8SCy Schubert 
wpa_supplicant_event_assoc_auth(struct wpa_supplicant * wpa_s,union wpa_event_data * data)559085732ac8SCy Schubert static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
559185732ac8SCy Schubert 					    union wpa_event_data *data)
559285732ac8SCy Schubert {
559385732ac8SCy Schubert 	wpa_dbg(wpa_s, MSG_DEBUG,
559485732ac8SCy Schubert 		"Connection authorized by device, previous state %d",
559585732ac8SCy Schubert 		wpa_s->wpa_state);
559685732ac8SCy Schubert 
559785732ac8SCy Schubert 	wpa_supplicant_event_port_authorized(wpa_s);
559885732ac8SCy Schubert 
5599c1d255d3SCy Schubert 	wpa_s->last_eapol_matches_bssid = 1;
5600c1d255d3SCy Schubert 
56015b9c547cSRui Paulo 	wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
56025b9c547cSRui Paulo 	wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
56035b9c547cSRui Paulo 			       data->assoc_info.ptk_kck_len,
56045b9c547cSRui Paulo 			       data->assoc_info.ptk_kek,
56055b9c547cSRui Paulo 			       data->assoc_info.ptk_kek_len);
560685732ac8SCy Schubert #ifdef CONFIG_FILS
560785732ac8SCy Schubert 	if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
560885732ac8SCy Schubert 		struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
560985732ac8SCy Schubert 		const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
561085732ac8SCy Schubert 
561185732ac8SCy Schubert 		/* Update ERP next sequence number */
561285732ac8SCy Schubert 		eapol_sm_update_erp_next_seq_num(
561385732ac8SCy Schubert 			wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
561485732ac8SCy Schubert 
561585732ac8SCy Schubert 		if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
561685732ac8SCy Schubert 			/* Add the new PMK and PMKID to the PMKSA cache */
561785732ac8SCy Schubert 			wpa_sm_pmksa_cache_add(wpa_s->wpa,
561885732ac8SCy Schubert 					       data->assoc_info.fils_pmk,
561985732ac8SCy Schubert 					       data->assoc_info.fils_pmk_len,
562085732ac8SCy Schubert 					       data->assoc_info.fils_pmkid,
5621*a90b9d01SCy Schubert 					       wpa_s->valid_links ?
5622*a90b9d01SCy Schubert 					       wpa_s->ap_mld_addr :
5623*a90b9d01SCy Schubert 					       wpa_s->bssid,
5624*a90b9d01SCy Schubert 					       fils_cache_id);
562585732ac8SCy Schubert 		} else if (data->assoc_info.fils_pmkid) {
562685732ac8SCy Schubert 			/* Update the current PMKSA used for this connection */
562785732ac8SCy Schubert 			pmksa_cache_set_current(wpa_s->wpa,
562885732ac8SCy Schubert 						data->assoc_info.fils_pmkid,
5629*a90b9d01SCy Schubert 						NULL, NULL, 0, NULL, 0, true);
563085732ac8SCy Schubert 		}
563185732ac8SCy Schubert 	}
563285732ac8SCy Schubert #endif /* CONFIG_FILS */
563385732ac8SCy Schubert }
563485732ac8SCy Schubert 
563585732ac8SCy Schubert 
connect_fail_reason(enum sta_connect_fail_reason_codes code)5636c1d255d3SCy Schubert static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
5637c1d255d3SCy Schubert {
5638c1d255d3SCy Schubert 	switch (code) {
5639c1d255d3SCy Schubert 	case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
5640c1d255d3SCy Schubert 		return "";
5641c1d255d3SCy Schubert 	case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
5642c1d255d3SCy Schubert 		return "no_bss_found";
5643c1d255d3SCy Schubert 	case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
5644c1d255d3SCy Schubert 		return "auth_tx_fail";
5645c1d255d3SCy Schubert 	case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
5646c1d255d3SCy Schubert 		return "auth_no_ack_received";
5647c1d255d3SCy Schubert 	case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
5648c1d255d3SCy Schubert 		return "auth_no_resp_received";
5649c1d255d3SCy Schubert 	case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
5650c1d255d3SCy Schubert 		return "assoc_req_tx_fail";
5651c1d255d3SCy Schubert 	case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
5652c1d255d3SCy Schubert 		return "assoc_no_ack_received";
5653c1d255d3SCy Schubert 	case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
5654c1d255d3SCy Schubert 		return "assoc_no_resp_received";
5655c1d255d3SCy Schubert 	default:
5656c1d255d3SCy Schubert 		return "unknown_reason";
5657c1d255d3SCy Schubert 	}
5658c1d255d3SCy Schubert }
5659c1d255d3SCy Schubert 
5660c1d255d3SCy Schubert 
wpas_event_assoc_reject(struct wpa_supplicant * wpa_s,union wpa_event_data * data)566185732ac8SCy Schubert static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
566285732ac8SCy Schubert 				    union wpa_event_data *data)
566385732ac8SCy Schubert {
566485732ac8SCy Schubert 	const u8 *bssid = data->assoc_reject.bssid;
5665*a90b9d01SCy Schubert 	struct ieee802_11_elems elems;
5666*a90b9d01SCy Schubert 	struct ml_sta_link_info ml_info[MAX_NUM_MLD_LINKS];
5667*a90b9d01SCy Schubert 	const u8 *link_bssids[MAX_NUM_MLD_LINKS + 1];
5668206b73d0SCy Schubert #ifdef CONFIG_MBO
5669206b73d0SCy Schubert 	struct wpa_bss *reject_bss;
5670206b73d0SCy Schubert #endif /* CONFIG_MBO */
567185732ac8SCy Schubert 
567285732ac8SCy Schubert 	if (!bssid || is_zero_ether_addr(bssid))
567385732ac8SCy Schubert 		bssid = wpa_s->pending_bssid;
5674206b73d0SCy Schubert #ifdef CONFIG_MBO
5675206b73d0SCy Schubert 	if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5676206b73d0SCy Schubert 		reject_bss = wpa_s->current_bss;
5677206b73d0SCy Schubert 	else
5678206b73d0SCy Schubert 		reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
5679206b73d0SCy Schubert #endif /* CONFIG_MBO */
568085732ac8SCy Schubert 
568185732ac8SCy Schubert 	if (data->assoc_reject.bssid)
568285732ac8SCy Schubert 		wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
5683c1d255d3SCy Schubert 			"bssid=" MACSTR	" status_code=%u%s%s%s%s%s",
568485732ac8SCy Schubert 			MAC2STR(data->assoc_reject.bssid),
568585732ac8SCy Schubert 			data->assoc_reject.status_code,
568685732ac8SCy Schubert 			data->assoc_reject.timed_out ? " timeout" : "",
568785732ac8SCy Schubert 			data->assoc_reject.timeout_reason ? "=" : "",
568885732ac8SCy Schubert 			data->assoc_reject.timeout_reason ?
5689c1d255d3SCy Schubert 			data->assoc_reject.timeout_reason : "",
5690c1d255d3SCy Schubert 			data->assoc_reject.reason_code !=
5691c1d255d3SCy Schubert 			STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5692c1d255d3SCy Schubert 			" qca_driver_reason=" : "",
5693c1d255d3SCy Schubert 			connect_fail_reason(data->assoc_reject.reason_code));
569485732ac8SCy Schubert 	else
569585732ac8SCy Schubert 		wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
5696c1d255d3SCy Schubert 			"status_code=%u%s%s%s%s%s",
569785732ac8SCy Schubert 			data->assoc_reject.status_code,
569885732ac8SCy Schubert 			data->assoc_reject.timed_out ? " timeout" : "",
569985732ac8SCy Schubert 			data->assoc_reject.timeout_reason ? "=" : "",
570085732ac8SCy Schubert 			data->assoc_reject.timeout_reason ?
5701c1d255d3SCy Schubert 			data->assoc_reject.timeout_reason : "",
5702c1d255d3SCy Schubert 			data->assoc_reject.reason_code !=
5703c1d255d3SCy Schubert 			STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5704c1d255d3SCy Schubert 			" qca_driver_reason=" : "",
5705c1d255d3SCy Schubert 			connect_fail_reason(data->assoc_reject.reason_code));
570685732ac8SCy Schubert 	wpa_s->assoc_status_code = data->assoc_reject.status_code;
570785732ac8SCy Schubert 	wpas_notify_assoc_status_code(wpa_s);
570885732ac8SCy Schubert 
570985732ac8SCy Schubert #ifdef CONFIG_OWE
571085732ac8SCy Schubert 	if (data->assoc_reject.status_code ==
571185732ac8SCy Schubert 	    WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
571285732ac8SCy Schubert 	    wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
571385732ac8SCy Schubert 	    wpa_s->current_ssid &&
571485732ac8SCy Schubert 	    wpa_s->current_ssid->owe_group == 0 &&
571585732ac8SCy Schubert 	    wpa_s->last_owe_group != 21) {
571685732ac8SCy Schubert 		struct wpa_ssid *ssid = wpa_s->current_ssid;
571785732ac8SCy Schubert 		struct wpa_bss *bss = wpa_s->current_bss;
571885732ac8SCy Schubert 
571985732ac8SCy Schubert 		if (!bss) {
572085732ac8SCy Schubert 			bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
572185732ac8SCy Schubert 			if (!bss) {
5722*a90b9d01SCy Schubert 				wpas_connection_failed(wpa_s, bssid, NULL);
572385732ac8SCy Schubert 				wpa_supplicant_mark_disassoc(wpa_s);
572485732ac8SCy Schubert 				return;
572585732ac8SCy Schubert 			}
572685732ac8SCy Schubert 		}
572785732ac8SCy Schubert 		wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
572885732ac8SCy Schubert 		wpas_connect_work_done(wpa_s);
572985732ac8SCy Schubert 		wpa_supplicant_mark_disassoc(wpa_s);
573085732ac8SCy Schubert 		wpa_supplicant_connect(wpa_s, bss, ssid);
573185732ac8SCy Schubert 		return;
573285732ac8SCy Schubert 	}
573385732ac8SCy Schubert #endif /* CONFIG_OWE */
573485732ac8SCy Schubert 
5735c1d255d3SCy Schubert #ifdef CONFIG_DPP2
5736c1d255d3SCy Schubert 	/* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
5737c1d255d3SCy Schubert 	 * the status code defined in the DPP R2 tech spec.
5738c1d255d3SCy Schubert 	 * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
5739c1d255d3SCy Schubert 	 * interoperability workaround with older hostapd implementation. */
5740c1d255d3SCy Schubert 	if (DPP_VERSION > 1 && wpa_s->current_ssid &&
5741c1d255d3SCy Schubert 	    (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
5742c1d255d3SCy Schubert 	     ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
5743c1d255d3SCy Schubert 	      wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
5744c1d255d3SCy Schubert 	    wpa_s->current_ssid->dpp_pfs == 0 &&
5745c1d255d3SCy Schubert 	    (data->assoc_reject.status_code ==
5746c1d255d3SCy Schubert 	     WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
5747c1d255d3SCy Schubert 	     data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
5748c1d255d3SCy Schubert 		struct wpa_ssid *ssid = wpa_s->current_ssid;
5749c1d255d3SCy Schubert 		struct wpa_bss *bss = wpa_s->current_bss;
5750c1d255d3SCy Schubert 
5751c1d255d3SCy Schubert 		wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
5752c1d255d3SCy Schubert 		if (!bss)
5753c1d255d3SCy Schubert 			bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5754c1d255d3SCy Schubert 		if (!bss || wpa_s->dpp_pfs_fallback) {
5755c1d255d3SCy Schubert 			wpa_printf(MSG_DEBUG,
5756c1d255d3SCy Schubert 				   "DPP: Updated PFS policy for next try");
5757*a90b9d01SCy Schubert 			wpas_connection_failed(wpa_s, bssid, NULL);
5758c1d255d3SCy Schubert 			wpa_supplicant_mark_disassoc(wpa_s);
5759c1d255d3SCy Schubert 			return;
5760c1d255d3SCy Schubert 		}
5761c1d255d3SCy Schubert 		wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
5762c1d255d3SCy Schubert 		wpa_s->dpp_pfs_fallback = 1;
5763c1d255d3SCy Schubert 		wpas_connect_work_done(wpa_s);
5764c1d255d3SCy Schubert 		wpa_supplicant_mark_disassoc(wpa_s);
5765c1d255d3SCy Schubert 		wpa_supplicant_connect(wpa_s, bss, ssid);
5766c1d255d3SCy Schubert 		return;
5767c1d255d3SCy Schubert 	}
5768c1d255d3SCy Schubert #endif /* CONFIG_DPP2 */
5769c1d255d3SCy Schubert 
57704bc52338SCy Schubert #ifdef CONFIG_MBO
57714bc52338SCy Schubert 	if (data->assoc_reject.status_code ==
57724bc52338SCy Schubert 	    WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
5773206b73d0SCy Schubert 	    reject_bss && data->assoc_reject.resp_ies) {
57744bc52338SCy Schubert 		const u8 *rssi_rej;
57754bc52338SCy Schubert 
57764bc52338SCy Schubert 		rssi_rej = mbo_get_attr_from_ies(
57774bc52338SCy Schubert 			data->assoc_reject.resp_ies,
57784bc52338SCy Schubert 			data->assoc_reject.resp_ies_len,
57794bc52338SCy Schubert 			OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
57804bc52338SCy Schubert 		if (rssi_rej && rssi_rej[1] == 2) {
57814bc52338SCy Schubert 			wpa_printf(MSG_DEBUG,
57824bc52338SCy Schubert 				   "OCE: RSSI-based association rejection from "
57834bc52338SCy Schubert 				   MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
5784206b73d0SCy Schubert 				   MAC2STR(reject_bss->bssid),
57854bc52338SCy Schubert 				   rssi_rej[2], rssi_rej[3]);
57864bc52338SCy Schubert 			wpa_bss_tmp_disallow(wpa_s,
5787206b73d0SCy Schubert 					     reject_bss->bssid,
57884bc52338SCy Schubert 					     rssi_rej[3],
5789206b73d0SCy Schubert 					     rssi_rej[2] + reject_bss->level);
57904bc52338SCy Schubert 		}
57914bc52338SCy Schubert 	}
57924bc52338SCy Schubert #endif /* CONFIG_MBO */
57934bc52338SCy Schubert 
5794*a90b9d01SCy Schubert 	/* Check for other failed links in the response */
5795*a90b9d01SCy Schubert 	os_memset(link_bssids, 0, sizeof(link_bssids));
5796*a90b9d01SCy Schubert 	if (ieee802_11_parse_elems(data->assoc_reject.resp_ies,
5797*a90b9d01SCy Schubert 				   data->assoc_reject.resp_ies_len,
5798*a90b9d01SCy Schubert 				   &elems, 1) != ParseFailed) {
5799*a90b9d01SCy Schubert 		unsigned int n_links, i, idx;
5800*a90b9d01SCy Schubert 
5801*a90b9d01SCy Schubert 		idx = 0;
5802*a90b9d01SCy Schubert 		n_links = wpas_ml_parse_assoc(wpa_s, &elems, ml_info);
5803*a90b9d01SCy Schubert 
5804*a90b9d01SCy Schubert 		for (i = 1; i < n_links; i++) {
5805*a90b9d01SCy Schubert 			/* The status cannot be success here.
5806*a90b9d01SCy Schubert 			 * Add the link to the failed list if it is reporting
5807*a90b9d01SCy Schubert 			 * an error. The only valid "non-error" status is
5808*a90b9d01SCy Schubert 			 * TX_LINK_NOT_ACCEPTED as that means this link may
5809*a90b9d01SCy Schubert 			 * still accept an association from us.
5810*a90b9d01SCy Schubert 			 */
5811*a90b9d01SCy Schubert 			if (ml_info[i].status !=
5812*a90b9d01SCy Schubert 			    WLAN_STATUS_DENIED_TX_LINK_NOT_ACCEPTED) {
5813*a90b9d01SCy Schubert 				link_bssids[idx] = ml_info[i].bssid;
5814*a90b9d01SCy Schubert 				idx++;
5815*a90b9d01SCy Schubert 			}
5816*a90b9d01SCy Schubert 		}
5817*a90b9d01SCy Schubert 	}
5818*a90b9d01SCy Schubert 
581985732ac8SCy Schubert 	if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
5820*a90b9d01SCy Schubert 		sme_event_assoc_reject(wpa_s, data, link_bssids);
582185732ac8SCy Schubert 		return;
582285732ac8SCy Schubert 	}
582385732ac8SCy Schubert 
582485732ac8SCy Schubert 	/* Driver-based SME cases */
582585732ac8SCy Schubert 
582685732ac8SCy Schubert #ifdef CONFIG_SAE
582785732ac8SCy Schubert 	if (wpa_s->current_ssid &&
582885732ac8SCy Schubert 	    wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
582985732ac8SCy Schubert 	    !data->assoc_reject.timed_out) {
583085732ac8SCy Schubert 		wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
583185732ac8SCy Schubert 		wpa_sm_aborted_cached(wpa_s->wpa);
583285732ac8SCy Schubert 		wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
583385732ac8SCy Schubert 	}
583485732ac8SCy Schubert #endif /* CONFIG_SAE */
583585732ac8SCy Schubert 
583685732ac8SCy Schubert #ifdef CONFIG_DPP
583785732ac8SCy Schubert 	if (wpa_s->current_ssid &&
583885732ac8SCy Schubert 	    wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
583985732ac8SCy Schubert 	    !data->assoc_reject.timed_out) {
584085732ac8SCy Schubert 		wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
584185732ac8SCy Schubert 		wpa_sm_aborted_cached(wpa_s->wpa);
584285732ac8SCy Schubert 		wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
584385732ac8SCy Schubert 	}
584485732ac8SCy Schubert #endif /* CONFIG_DPP */
584585732ac8SCy Schubert 
584685732ac8SCy Schubert #ifdef CONFIG_FILS
584785732ac8SCy Schubert 	/* Update ERP next sequence number */
584885732ac8SCy Schubert 	if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
5849c1d255d3SCy Schubert 		fils_pmksa_cache_flush(wpa_s);
585085732ac8SCy Schubert 		eapol_sm_update_erp_next_seq_num(
585185732ac8SCy Schubert 			wpa_s->eapol,
585285732ac8SCy Schubert 			data->assoc_reject.fils_erp_next_seq_num);
585385732ac8SCy Schubert 		fils_connection_failure(wpa_s);
585485732ac8SCy Schubert 	}
585585732ac8SCy Schubert #endif /* CONFIG_FILS */
585685732ac8SCy Schubert 
5857*a90b9d01SCy Schubert 	wpas_connection_failed(wpa_s, bssid, link_bssids);
585885732ac8SCy Schubert 	wpa_supplicant_mark_disassoc(wpa_s);
58595b9c547cSRui Paulo }
58605b9c547cSRui Paulo 
58615b9c547cSRui Paulo 
wpas_event_unprot_beacon(struct wpa_supplicant * wpa_s,struct unprot_beacon * data)5862c1d255d3SCy Schubert static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
5863c1d255d3SCy Schubert 				     struct unprot_beacon *data)
5864c1d255d3SCy Schubert {
5865c1d255d3SCy Schubert 	struct wpabuf *buf;
5866c1d255d3SCy Schubert 	int res;
5867c1d255d3SCy Schubert 
5868c1d255d3SCy Schubert 	if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
5869*a90b9d01SCy Schubert 	    !ether_addr_equal(data->sa, wpa_s->bssid))
5870c1d255d3SCy Schubert 		return;
5871c1d255d3SCy Schubert 	wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
5872c1d255d3SCy Schubert 		MAC2STR(data->sa));
5873c1d255d3SCy Schubert 
5874c1d255d3SCy Schubert 	buf = wpabuf_alloc(4);
5875c1d255d3SCy Schubert 	if (!buf)
5876c1d255d3SCy Schubert 		return;
5877c1d255d3SCy Schubert 
5878c1d255d3SCy Schubert 	wpabuf_put_u8(buf, WLAN_ACTION_WNM);
5879c1d255d3SCy Schubert 	wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
5880c1d255d3SCy Schubert 	wpabuf_put_u8(buf, 1); /* Dialog Token */
5881c1d255d3SCy Schubert 	wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
5882c1d255d3SCy Schubert 
5883c1d255d3SCy Schubert 	res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
5884c1d255d3SCy Schubert 				  wpa_s->own_addr, wpa_s->bssid,
5885c1d255d3SCy Schubert 				  wpabuf_head(buf), wpabuf_len(buf), 0);
5886c1d255d3SCy Schubert 	if (res < 0)
5887c1d255d3SCy Schubert 		wpa_printf(MSG_DEBUG,
5888c1d255d3SCy Schubert 			   "Failed to send WNM-Notification Request frame");
5889c1d255d3SCy Schubert 
5890c1d255d3SCy Schubert 	wpabuf_free(buf);
5891c1d255d3SCy Schubert }
5892c1d255d3SCy Schubert 
5893c1d255d3SCy Schubert 
bitmap_to_str(u8 value,char * buf)5894*a90b9d01SCy Schubert static const char * bitmap_to_str(u8 value, char *buf)
5895*a90b9d01SCy Schubert {
5896*a90b9d01SCy Schubert 	char *pos = buf;
5897*a90b9d01SCy Schubert 	int i, k = 0;
5898*a90b9d01SCy Schubert 
5899*a90b9d01SCy Schubert 	for (i = 7; i >= 0; i--)
5900*a90b9d01SCy Schubert 		pos[k++] = (value & BIT(i)) ? '1' : '0';
5901*a90b9d01SCy Schubert 
5902*a90b9d01SCy Schubert 	pos[8] = '\0';
5903*a90b9d01SCy Schubert 	return pos;
5904*a90b9d01SCy Schubert }
5905*a90b9d01SCy Schubert 
5906*a90b9d01SCy Schubert 
wpas_tid_link_map(struct wpa_supplicant * wpa_s,struct tid_link_map_info * info)5907*a90b9d01SCy Schubert static void wpas_tid_link_map(struct wpa_supplicant *wpa_s,
5908*a90b9d01SCy Schubert 			      struct tid_link_map_info *info)
5909*a90b9d01SCy Schubert {
5910*a90b9d01SCy Schubert 	char map_info[1000], *pos, *end;
5911*a90b9d01SCy Schubert 	int res, i;
5912*a90b9d01SCy Schubert 
5913*a90b9d01SCy Schubert 	pos = map_info;
5914*a90b9d01SCy Schubert 	end = pos + sizeof(map_info);
5915*a90b9d01SCy Schubert 	res = os_snprintf(map_info, sizeof(map_info), "default=%d",
5916*a90b9d01SCy Schubert 			  info->default_map);
5917*a90b9d01SCy Schubert 	if (os_snprintf_error(end - pos, res))
5918*a90b9d01SCy Schubert 		return;
5919*a90b9d01SCy Schubert 	pos += res;
5920*a90b9d01SCy Schubert 
5921*a90b9d01SCy Schubert 	if (!info->default_map) {
5922*a90b9d01SCy Schubert 		for_each_link(info->valid_links, i) {
5923*a90b9d01SCy Schubert 			char uplink_map_str[9];
5924*a90b9d01SCy Schubert 			char downlink_map_str[9];
5925*a90b9d01SCy Schubert 
5926*a90b9d01SCy Schubert 			bitmap_to_str(info->t2lmap[i].uplink, uplink_map_str);
5927*a90b9d01SCy Schubert 			bitmap_to_str(info->t2lmap[i].downlink,
5928*a90b9d01SCy Schubert 				      downlink_map_str);
5929*a90b9d01SCy Schubert 
5930*a90b9d01SCy Schubert 			res = os_snprintf(pos, end - pos,
5931*a90b9d01SCy Schubert 					  " link_id=%d up_link=%s down_link=%s",
5932*a90b9d01SCy Schubert 					  i, uplink_map_str,
5933*a90b9d01SCy Schubert 					  downlink_map_str);
5934*a90b9d01SCy Schubert 			if (os_snprintf_error(end - pos, res))
5935*a90b9d01SCy Schubert 				return;
5936*a90b9d01SCy Schubert 			pos += res;
5937*a90b9d01SCy Schubert 		}
5938*a90b9d01SCy Schubert 	}
5939*a90b9d01SCy Schubert 
5940*a90b9d01SCy Schubert 	wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_T2LM_UPDATE "%s", map_info);
5941*a90b9d01SCy Schubert }
5942*a90b9d01SCy Schubert 
5943*a90b9d01SCy Schubert 
wpas_link_reconfig(struct wpa_supplicant * wpa_s)5944*a90b9d01SCy Schubert static void wpas_link_reconfig(struct wpa_supplicant *wpa_s)
5945*a90b9d01SCy Schubert {
5946*a90b9d01SCy Schubert 	u8 bssid[ETH_ALEN];
5947*a90b9d01SCy Schubert 
5948*a90b9d01SCy Schubert 	if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
5949*a90b9d01SCy Schubert 		wpa_printf(MSG_ERROR, "LINK_RECONFIG: Failed to get BSSID");
5950*a90b9d01SCy Schubert 		wpa_supplicant_deauthenticate(wpa_s,
5951*a90b9d01SCy Schubert 					      WLAN_REASON_DEAUTH_LEAVING);
5952*a90b9d01SCy Schubert 		return;
5953*a90b9d01SCy Schubert 	}
5954*a90b9d01SCy Schubert 
5955*a90b9d01SCy Schubert 	if (!ether_addr_equal(bssid, wpa_s->bssid)) {
5956*a90b9d01SCy Schubert 		os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
5957*a90b9d01SCy Schubert 		wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
5958*a90b9d01SCy Schubert 		wpas_notify_bssid_changed(wpa_s);
5959*a90b9d01SCy Schubert 	}
5960*a90b9d01SCy Schubert 
5961*a90b9d01SCy Schubert 	if (wpa_drv_get_mlo_info(wpa_s) < 0) {
5962*a90b9d01SCy Schubert 		wpa_printf(MSG_ERROR,
5963*a90b9d01SCy Schubert 			   "LINK_RECONFIG: Failed to get MLO connection info");
5964*a90b9d01SCy Schubert 		wpa_supplicant_deauthenticate(wpa_s,
5965*a90b9d01SCy Schubert 					      WLAN_REASON_DEAUTH_LEAVING);
5966*a90b9d01SCy Schubert 		return;
5967*a90b9d01SCy Schubert 	}
5968*a90b9d01SCy Schubert 
5969*a90b9d01SCy Schubert 	if (wpa_sm_set_ml_info(wpa_s)) {
5970*a90b9d01SCy Schubert 		wpa_printf(MSG_ERROR,
5971*a90b9d01SCy Schubert 			   "LINK_RECONFIG: Failed to set MLO connection info to wpa_sm");
5972*a90b9d01SCy Schubert 		wpa_supplicant_deauthenticate(wpa_s,
5973*a90b9d01SCy Schubert 					      WLAN_REASON_DEAUTH_LEAVING);
5974*a90b9d01SCy Schubert 		return;
5975*a90b9d01SCy Schubert 	}
5976*a90b9d01SCy Schubert 
5977*a90b9d01SCy Schubert 	wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_LINK_RECONFIG "valid_links=0x%x",
5978*a90b9d01SCy Schubert 		wpa_s->valid_links);
5979*a90b9d01SCy Schubert }
5980*a90b9d01SCy Schubert 
5981*a90b9d01SCy Schubert 
wpa_supplicant_event(void * ctx,enum wpa_event_type event,union wpa_event_data * data)5982e28a4053SRui Paulo void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
598339beb93cSSam Leffler 			  union wpa_event_data *data)
598439beb93cSSam Leffler {
598539beb93cSSam Leffler 	struct wpa_supplicant *wpa_s = ctx;
5986325151a3SRui Paulo 	int resched;
5987c1d255d3SCy Schubert 	struct os_reltime age, clear_at;
598885732ac8SCy Schubert #ifndef CONFIG_NO_STDOUT_DEBUG
598985732ac8SCy Schubert 	int level = MSG_DEBUG;
599085732ac8SCy Schubert #endif /* CONFIG_NO_STDOUT_DEBUG */
5991f05cddf9SRui Paulo 
5992f05cddf9SRui Paulo 	if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
5993f05cddf9SRui Paulo 	    event != EVENT_INTERFACE_ENABLED &&
5994f05cddf9SRui Paulo 	    event != EVENT_INTERFACE_STATUS &&
5995780fb4a2SCy Schubert 	    event != EVENT_SCAN_RESULTS &&
5996f05cddf9SRui Paulo 	    event != EVENT_SCHED_SCAN_STOPPED) {
5997f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG,
5998f05cddf9SRui Paulo 			"Ignore event %s (%d) while interface is disabled",
5999f05cddf9SRui Paulo 			event_to_string(event), event);
6000f05cddf9SRui Paulo 		return;
6001f05cddf9SRui Paulo 	}
6002f05cddf9SRui Paulo 
6003f05cddf9SRui Paulo #ifndef CONFIG_NO_STDOUT_DEBUG
6004f05cddf9SRui Paulo 	if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
6005f05cddf9SRui Paulo 		const struct ieee80211_hdr *hdr;
6006f05cddf9SRui Paulo 		u16 fc;
6007f05cddf9SRui Paulo 		hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
6008f05cddf9SRui Paulo 		fc = le_to_host16(hdr->frame_control);
6009f05cddf9SRui Paulo 		if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
6010f05cddf9SRui Paulo 		    WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
6011f05cddf9SRui Paulo 			level = MSG_EXCESSIVE;
6012f05cddf9SRui Paulo 	}
6013f05cddf9SRui Paulo 
6014f05cddf9SRui Paulo 	wpa_dbg(wpa_s, level, "Event %s (%d) received",
6015f05cddf9SRui Paulo 		event_to_string(event), event);
6016f05cddf9SRui Paulo #endif /* CONFIG_NO_STDOUT_DEBUG */
601739beb93cSSam Leffler 
601839beb93cSSam Leffler 	switch (event) {
6019e28a4053SRui Paulo 	case EVENT_AUTH:
6020780fb4a2SCy Schubert #ifdef CONFIG_FST
6021780fb4a2SCy Schubert 		if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
6022780fb4a2SCy Schubert 					  data->auth.ies_len))
6023780fb4a2SCy Schubert 			wpa_printf(MSG_DEBUG,
6024780fb4a2SCy Schubert 				   "FST: MB IEs updated from auth IE");
6025780fb4a2SCy Schubert #endif /* CONFIG_FST */
6026e28a4053SRui Paulo 		sme_event_auth(wpa_s, data);
60274bc52338SCy Schubert 		wpa_s->auth_status_code = data->auth.status_code;
60284bc52338SCy Schubert 		wpas_notify_auth_status_code(wpa_s);
6029e28a4053SRui Paulo 		break;
603039beb93cSSam Leffler 	case EVENT_ASSOC:
6031780fb4a2SCy Schubert #ifdef CONFIG_TESTING_OPTIONS
6032780fb4a2SCy Schubert 		if (wpa_s->ignore_auth_resp) {
6033780fb4a2SCy Schubert 			wpa_printf(MSG_INFO,
6034780fb4a2SCy Schubert 				   "EVENT_ASSOC - ignore_auth_resp active!");
6035780fb4a2SCy Schubert 			break;
6036780fb4a2SCy Schubert 		}
603785732ac8SCy Schubert 		if (wpa_s->testing_resend_assoc) {
603885732ac8SCy Schubert 			wpa_printf(MSG_INFO,
603985732ac8SCy Schubert 				   "EVENT_DEAUTH - testing_resend_assoc");
604085732ac8SCy Schubert 			break;
604185732ac8SCy Schubert 		}
6042780fb4a2SCy Schubert #endif /* CONFIG_TESTING_OPTIONS */
6043c1d255d3SCy Schubert 		if (wpa_s->disconnected) {
6044c1d255d3SCy Schubert 			wpa_printf(MSG_INFO,
6045c1d255d3SCy Schubert 				   "Ignore unexpected EVENT_ASSOC in disconnected state");
6046c1d255d3SCy Schubert 			break;
6047c1d255d3SCy Schubert 		}
604839beb93cSSam Leffler 		wpa_supplicant_event_assoc(wpa_s, data);
604985732ac8SCy Schubert 		wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
605085732ac8SCy Schubert 		if (data &&
605185732ac8SCy Schubert 		    (data->assoc_info.authorized ||
605285732ac8SCy Schubert 		     (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
605385732ac8SCy Schubert 		      wpa_fils_is_completed(wpa_s->wpa))))
60545b9c547cSRui Paulo 			wpa_supplicant_event_assoc_auth(wpa_s, data);
6055780fb4a2SCy Schubert 		if (data) {
6056780fb4a2SCy Schubert 			wpa_msg(wpa_s, MSG_INFO,
6057780fb4a2SCy Schubert 				WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
6058780fb4a2SCy Schubert 				data->assoc_info.subnet_status);
6059780fb4a2SCy Schubert 		}
606039beb93cSSam Leffler 		break;
606139beb93cSSam Leffler 	case EVENT_DISASSOC:
60625b9c547cSRui Paulo 		wpas_event_disassoc(wpa_s,
60635b9c547cSRui Paulo 				    data ? &data->disassoc_info : NULL);
6064e28a4053SRui Paulo 		break;
6065e28a4053SRui Paulo 	case EVENT_DEAUTH:
6066780fb4a2SCy Schubert #ifdef CONFIG_TESTING_OPTIONS
6067780fb4a2SCy Schubert 		if (wpa_s->ignore_auth_resp) {
6068780fb4a2SCy Schubert 			wpa_printf(MSG_INFO,
6069780fb4a2SCy Schubert 				   "EVENT_DEAUTH - ignore_auth_resp active!");
6070780fb4a2SCy Schubert 			break;
6071780fb4a2SCy Schubert 		}
607285732ac8SCy Schubert 		if (wpa_s->testing_resend_assoc) {
607385732ac8SCy Schubert 			wpa_printf(MSG_INFO,
607485732ac8SCy Schubert 				   "EVENT_DEAUTH - testing_resend_assoc");
607585732ac8SCy Schubert 			break;
607685732ac8SCy Schubert 		}
6077780fb4a2SCy Schubert #endif /* CONFIG_TESTING_OPTIONS */
60785b9c547cSRui Paulo 		wpas_event_deauth(wpa_s,
60795b9c547cSRui Paulo 				  data ? &data->deauth_info : NULL);
608039beb93cSSam Leffler 		break;
6081*a90b9d01SCy Schubert 	case EVENT_LINK_RECONFIG:
6082*a90b9d01SCy Schubert 		wpas_link_reconfig(wpa_s);
6083*a90b9d01SCy Schubert 		break;
608439beb93cSSam Leffler 	case EVENT_MICHAEL_MIC_FAILURE:
608539beb93cSSam Leffler 		wpa_supplicant_event_michael_mic_failure(wpa_s, data);
608639beb93cSSam Leffler 		break;
608739beb93cSSam Leffler #ifndef CONFIG_NO_SCAN_PROCESSING
60885b9c547cSRui Paulo 	case EVENT_SCAN_STARTED:
6089780fb4a2SCy Schubert 		if (wpa_s->own_scan_requested ||
6090780fb4a2SCy Schubert 		    (data && !data->scan_info.external_scan)) {
60915b9c547cSRui Paulo 			struct os_reltime diff;
60925b9c547cSRui Paulo 
6093780fb4a2SCy Schubert 			os_get_reltime(&wpa_s->scan_start_time);
60945b9c547cSRui Paulo 			os_reltime_sub(&wpa_s->scan_start_time,
60955b9c547cSRui Paulo 				       &wpa_s->scan_trigger_time, &diff);
60965b9c547cSRui Paulo 			wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
60975b9c547cSRui Paulo 				diff.sec, diff.usec);
60985b9c547cSRui Paulo 			wpa_s->own_scan_requested = 0;
60995b9c547cSRui Paulo 			wpa_s->own_scan_running = 1;
61005b9c547cSRui Paulo 			if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
61015b9c547cSRui Paulo 			    wpa_s->manual_scan_use_id) {
61025b9c547cSRui Paulo 				wpa_msg_ctrl(wpa_s, MSG_INFO,
61035b9c547cSRui Paulo 					     WPA_EVENT_SCAN_STARTED "id=%u",
61045b9c547cSRui Paulo 					     wpa_s->manual_scan_id);
61055b9c547cSRui Paulo 			} else {
61065b9c547cSRui Paulo 				wpa_msg_ctrl(wpa_s, MSG_INFO,
61075b9c547cSRui Paulo 					     WPA_EVENT_SCAN_STARTED);
61085b9c547cSRui Paulo 			}
61095b9c547cSRui Paulo 		} else {
61105b9c547cSRui Paulo 			wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
6111c1d255d3SCy Schubert 			wpa_s->radio->external_scan_req_interface = wpa_s;
61125b9c547cSRui Paulo 			wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
61135b9c547cSRui Paulo 		}
61145b9c547cSRui Paulo 		break;
611539beb93cSSam Leffler 	case EVENT_SCAN_RESULTS:
6116780fb4a2SCy Schubert 		if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6117780fb4a2SCy Schubert 			wpa_s->scan_res_handler = NULL;
6118780fb4a2SCy Schubert 			wpa_s->own_scan_running = 0;
6119c1d255d3SCy Schubert 			wpa_s->radio->external_scan_req_interface = NULL;
6120780fb4a2SCy Schubert 			wpa_s->last_scan_req = NORMAL_SCAN_REQ;
6121780fb4a2SCy Schubert 			break;
6122780fb4a2SCy Schubert 		}
6123780fb4a2SCy Schubert 
6124780fb4a2SCy Schubert 		if (!(data && data->scan_info.external_scan) &&
6125780fb4a2SCy Schubert 		    os_reltime_initialized(&wpa_s->scan_start_time)) {
61265b9c547cSRui Paulo 			struct os_reltime now, diff;
61275b9c547cSRui Paulo 			os_get_reltime(&now);
61285b9c547cSRui Paulo 			os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
61295b9c547cSRui Paulo 			wpa_s->scan_start_time.sec = 0;
61305b9c547cSRui Paulo 			wpa_s->scan_start_time.usec = 0;
6131*a90b9d01SCy Schubert 			wpa_s->wps_scan_done = true;
61325b9c547cSRui Paulo 			wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
61335b9c547cSRui Paulo 				diff.sec, diff.usec);
6134f05cddf9SRui Paulo 		}
61355b9c547cSRui Paulo 		if (wpa_supplicant_event_scan_results(wpa_s, data))
61365b9c547cSRui Paulo 			break; /* interface may have been removed */
6137780fb4a2SCy Schubert 		if (!(data && data->scan_info.external_scan))
61385b9c547cSRui Paulo 			wpa_s->own_scan_running = 0;
6139780fb4a2SCy Schubert 		if (data && data->scan_info.nl_scan_event)
6140c1d255d3SCy Schubert 			wpa_s->radio->external_scan_req_interface = NULL;
61415b9c547cSRui Paulo 		radio_work_check_next(wpa_s);
614239beb93cSSam Leffler 		break;
614339beb93cSSam Leffler #endif /* CONFIG_NO_SCAN_PROCESSING */
614439beb93cSSam Leffler 	case EVENT_ASSOCINFO:
614539beb93cSSam Leffler 		wpa_supplicant_event_associnfo(wpa_s, data);
614639beb93cSSam Leffler 		break;
614739beb93cSSam Leffler 	case EVENT_INTERFACE_STATUS:
614839beb93cSSam Leffler 		wpa_supplicant_event_interface_status(wpa_s, data);
614939beb93cSSam Leffler 		break;
615039beb93cSSam Leffler 	case EVENT_PMKID_CANDIDATE:
615139beb93cSSam Leffler 		wpa_supplicant_event_pmkid_candidate(wpa_s, data);
615239beb93cSSam Leffler 		break;
6153f05cddf9SRui Paulo #ifdef CONFIG_TDLS
6154f05cddf9SRui Paulo 	case EVENT_TDLS:
6155f05cddf9SRui Paulo 		wpa_supplicant_event_tdls(wpa_s, data);
6156f05cddf9SRui Paulo 		break;
6157f05cddf9SRui Paulo #endif /* CONFIG_TDLS */
6158f05cddf9SRui Paulo #ifdef CONFIG_WNM
6159f05cddf9SRui Paulo 	case EVENT_WNM:
6160f05cddf9SRui Paulo 		wpa_supplicant_event_wnm(wpa_s, data);
6161f05cddf9SRui Paulo 		break;
6162f05cddf9SRui Paulo #endif /* CONFIG_WNM */
616339beb93cSSam Leffler #ifdef CONFIG_IEEE80211R
616439beb93cSSam Leffler 	case EVENT_FT_RESPONSE:
616539beb93cSSam Leffler 		wpa_supplicant_event_ft_response(wpa_s, data);
616639beb93cSSam Leffler 		break;
616739beb93cSSam Leffler #endif /* CONFIG_IEEE80211R */
6168e28a4053SRui Paulo #ifdef CONFIG_IBSS_RSN
6169e28a4053SRui Paulo 	case EVENT_IBSS_RSN_START:
6170e28a4053SRui Paulo 		wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
6171e28a4053SRui Paulo 		break;
6172e28a4053SRui Paulo #endif /* CONFIG_IBSS_RSN */
6173e28a4053SRui Paulo 	case EVENT_ASSOC_REJECT:
617485732ac8SCy Schubert 		wpas_event_assoc_reject(wpa_s, data);
6175e28a4053SRui Paulo 		break;
6176e28a4053SRui Paulo 	case EVENT_AUTH_TIMED_OUT:
61775b9c547cSRui Paulo 		/* It is possible to get this event from earlier connection */
61785b9c547cSRui Paulo 		if (wpa_s->current_ssid &&
61795b9c547cSRui Paulo 		    wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
61805b9c547cSRui Paulo 			wpa_dbg(wpa_s, MSG_DEBUG,
61815b9c547cSRui Paulo 				"Ignore AUTH_TIMED_OUT in mesh configuration");
61825b9c547cSRui Paulo 			break;
61835b9c547cSRui Paulo 		}
6184f05cddf9SRui Paulo 		if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6185e28a4053SRui Paulo 			sme_event_auth_timed_out(wpa_s, data);
6186e28a4053SRui Paulo 		break;
6187e28a4053SRui Paulo 	case EVENT_ASSOC_TIMED_OUT:
61885b9c547cSRui Paulo 		/* It is possible to get this event from earlier connection */
61895b9c547cSRui Paulo 		if (wpa_s->current_ssid &&
61905b9c547cSRui Paulo 		    wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
61915b9c547cSRui Paulo 			wpa_dbg(wpa_s, MSG_DEBUG,
61925b9c547cSRui Paulo 				"Ignore ASSOC_TIMED_OUT in mesh configuration");
61935b9c547cSRui Paulo 			break;
61945b9c547cSRui Paulo 		}
6195f05cddf9SRui Paulo 		if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6196e28a4053SRui Paulo 			sme_event_assoc_timed_out(wpa_s, data);
6197e28a4053SRui Paulo 		break;
6198e28a4053SRui Paulo 	case EVENT_TX_STATUS:
6199f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
6200f05cddf9SRui Paulo 			" type=%d stype=%d",
6201f05cddf9SRui Paulo 			MAC2STR(data->tx_status.dst),
6202f05cddf9SRui Paulo 			data->tx_status.type, data->tx_status.stype);
6203*a90b9d01SCy Schubert #ifdef CONFIG_WNM
6204*a90b9d01SCy Schubert 		if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6205*a90b9d01SCy Schubert 		    data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
6206*a90b9d01SCy Schubert 		    wnm_btm_resp_tx_status(wpa_s, data->tx_status.data,
6207*a90b9d01SCy Schubert 					   data->tx_status.data_len) == 0)
6208*a90b9d01SCy Schubert 			break;
6209*a90b9d01SCy Schubert #endif /* CONFIG_WNM */
6210c1d255d3SCy Schubert #ifdef CONFIG_PASN
6211c1d255d3SCy Schubert 		if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6212c1d255d3SCy Schubert 		    data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
6213c1d255d3SCy Schubert 		    wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
6214c1d255d3SCy Schubert 					     data->tx_status.data_len,
6215c1d255d3SCy Schubert 					     data->tx_status.ack) == 0)
6216c1d255d3SCy Schubert 			break;
6217c1d255d3SCy Schubert #endif /* CONFIG_PASN */
6218f05cddf9SRui Paulo #ifdef CONFIG_AP
6219f05cddf9SRui Paulo 		if (wpa_s->ap_iface == NULL) {
6220f05cddf9SRui Paulo #ifdef CONFIG_OFFCHANNEL
6221f05cddf9SRui Paulo 			if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6222f05cddf9SRui Paulo 			    data->tx_status.stype == WLAN_FC_STYPE_ACTION)
6223f05cddf9SRui Paulo 				offchannel_send_action_tx_status(
6224f05cddf9SRui Paulo 					wpa_s, data->tx_status.dst,
6225f05cddf9SRui Paulo 					data->tx_status.data,
6226f05cddf9SRui Paulo 					data->tx_status.data_len,
6227f05cddf9SRui Paulo 					data->tx_status.ack ?
6228f05cddf9SRui Paulo 					OFFCHANNEL_SEND_ACTION_SUCCESS :
6229f05cddf9SRui Paulo 					OFFCHANNEL_SEND_ACTION_NO_ACK);
6230f05cddf9SRui Paulo #endif /* CONFIG_OFFCHANNEL */
6231e28a4053SRui Paulo 			break;
6232f05cddf9SRui Paulo 		}
6233f05cddf9SRui Paulo #endif /* CONFIG_AP */
6234f05cddf9SRui Paulo #ifdef CONFIG_OFFCHANNEL
6235f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
6236780fb4a2SCy Schubert 			MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
6237f05cddf9SRui Paulo 		/*
6238f05cddf9SRui Paulo 		 * Catch TX status events for Action frames we sent via group
6239780fb4a2SCy Schubert 		 * interface in GO mode, or via standalone AP interface.
6240780fb4a2SCy Schubert 		 * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
6241780fb4a2SCy Schubert 		 * except when the primary interface is used as a GO interface
6242780fb4a2SCy Schubert 		 * (for drivers which do not have group interface concurrency)
6243f05cddf9SRui Paulo 		 */
6244f05cddf9SRui Paulo 		if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6245f05cddf9SRui Paulo 		    data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
6246*a90b9d01SCy Schubert 		    ether_addr_equal(wpa_s->p2pdev->pending_action_dst,
6247*a90b9d01SCy Schubert 				     data->tx_status.dst)) {
6248f05cddf9SRui Paulo 			offchannel_send_action_tx_status(
6249780fb4a2SCy Schubert 				wpa_s->p2pdev, data->tx_status.dst,
6250f05cddf9SRui Paulo 				data->tx_status.data,
6251f05cddf9SRui Paulo 				data->tx_status.data_len,
6252f05cddf9SRui Paulo 				data->tx_status.ack ?
6253f05cddf9SRui Paulo 				OFFCHANNEL_SEND_ACTION_SUCCESS :
6254f05cddf9SRui Paulo 				OFFCHANNEL_SEND_ACTION_NO_ACK);
6255f05cddf9SRui Paulo 			break;
6256f05cddf9SRui Paulo 		}
6257f05cddf9SRui Paulo #endif /* CONFIG_OFFCHANNEL */
6258f05cddf9SRui Paulo #ifdef CONFIG_AP
6259e28a4053SRui Paulo 		switch (data->tx_status.type) {
6260e28a4053SRui Paulo 		case WLAN_FC_TYPE_MGMT:
6261e28a4053SRui Paulo 			ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
6262e28a4053SRui Paulo 				      data->tx_status.data_len,
6263e28a4053SRui Paulo 				      data->tx_status.stype,
6264e28a4053SRui Paulo 				      data->tx_status.ack);
6265e28a4053SRui Paulo 			break;
6266e28a4053SRui Paulo 		case WLAN_FC_TYPE_DATA:
6267e28a4053SRui Paulo 			ap_tx_status(wpa_s, data->tx_status.dst,
6268e28a4053SRui Paulo 				     data->tx_status.data,
6269e28a4053SRui Paulo 				     data->tx_status.data_len,
6270e28a4053SRui Paulo 				     data->tx_status.ack);
6271e28a4053SRui Paulo 			break;
6272e28a4053SRui Paulo 		}
6273f05cddf9SRui Paulo #endif /* CONFIG_AP */
6274f05cddf9SRui Paulo 		break;
6275f05cddf9SRui Paulo #ifdef CONFIG_AP
6276f05cddf9SRui Paulo 	case EVENT_EAPOL_TX_STATUS:
6277f05cddf9SRui Paulo 		ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
6278f05cddf9SRui Paulo 				   data->eapol_tx_status.data,
6279f05cddf9SRui Paulo 				   data->eapol_tx_status.data_len,
6280f05cddf9SRui Paulo 				   data->eapol_tx_status.ack);
6281f05cddf9SRui Paulo 		break;
6282f05cddf9SRui Paulo 	case EVENT_DRIVER_CLIENT_POLL_OK:
6283f05cddf9SRui Paulo 		ap_client_poll_ok(wpa_s, data->client_poll.addr);
6284e28a4053SRui Paulo 		break;
6285e28a4053SRui Paulo 	case EVENT_RX_FROM_UNKNOWN:
6286e28a4053SRui Paulo 		if (wpa_s->ap_iface == NULL)
6287e28a4053SRui Paulo 			break;
6288f05cddf9SRui Paulo 		ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
6289f05cddf9SRui Paulo 				       data->rx_from_unknown.wds);
6290e28a4053SRui Paulo 		break;
629185732ac8SCy Schubert #endif /* CONFIG_AP */
6292206b73d0SCy Schubert 
6293*a90b9d01SCy Schubert 	case EVENT_LINK_CH_SWITCH_STARTED:
6294*a90b9d01SCy Schubert 	case EVENT_LINK_CH_SWITCH:
6295*a90b9d01SCy Schubert 		if (!data || !wpa_s->current_ssid ||
6296*a90b9d01SCy Schubert 		    !(wpa_s->valid_links & BIT(data->ch_switch.link_id)))
6297*a90b9d01SCy Schubert 			break;
6298*a90b9d01SCy Schubert 
6299*a90b9d01SCy Schubert 		wpa_msg(wpa_s, MSG_INFO,
6300*a90b9d01SCy Schubert 			"%sfreq=%d link_id=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
6301*a90b9d01SCy Schubert 			event == EVENT_LINK_CH_SWITCH ?
6302*a90b9d01SCy Schubert 			WPA_EVENT_LINK_CHANNEL_SWITCH :
6303*a90b9d01SCy Schubert 			WPA_EVENT_LINK_CHANNEL_SWITCH_STARTED,
6304*a90b9d01SCy Schubert 			data->ch_switch.freq,
6305*a90b9d01SCy Schubert 			data->ch_switch.link_id,
6306*a90b9d01SCy Schubert 			data->ch_switch.ht_enabled,
6307*a90b9d01SCy Schubert 			data->ch_switch.ch_offset,
6308*a90b9d01SCy Schubert 			channel_width_to_string(data->ch_switch.ch_width),
6309*a90b9d01SCy Schubert 			data->ch_switch.cf1,
6310*a90b9d01SCy Schubert 			data->ch_switch.cf2);
6311*a90b9d01SCy Schubert 		if (event == EVENT_LINK_CH_SWITCH_STARTED)
6312*a90b9d01SCy Schubert 			break;
6313*a90b9d01SCy Schubert 
6314*a90b9d01SCy Schubert 		wpa_s->links[data->ch_switch.link_id].freq =
6315*a90b9d01SCy Schubert 			data->ch_switch.freq;
6316*a90b9d01SCy Schubert 		if (wpa_s->links[data->ch_switch.link_id].bss &&
6317*a90b9d01SCy Schubert 		    wpa_s->links[data->ch_switch.link_id].bss->freq !=
6318*a90b9d01SCy Schubert 		    data->ch_switch.freq) {
6319*a90b9d01SCy Schubert 			wpa_s->links[data->ch_switch.link_id].bss->freq =
6320*a90b9d01SCy Schubert 				data->ch_switch.freq;
6321*a90b9d01SCy Schubert 			notify_bss_changes(
6322*a90b9d01SCy Schubert 				wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
6323*a90b9d01SCy Schubert 				wpa_s->links[data->ch_switch.link_id].bss);
6324*a90b9d01SCy Schubert 		}
6325*a90b9d01SCy Schubert 		break;
6326206b73d0SCy Schubert 	case EVENT_CH_SWITCH_STARTED:
6327f05cddf9SRui Paulo 	case EVENT_CH_SWITCH:
6328780fb4a2SCy Schubert 		if (!data || !wpa_s->current_ssid)
6329e28a4053SRui Paulo 			break;
6330f05cddf9SRui Paulo 
6331206b73d0SCy Schubert 		wpa_msg(wpa_s, MSG_INFO,
6332206b73d0SCy Schubert 			"%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
6333206b73d0SCy Schubert 			event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
6334206b73d0SCy Schubert 			WPA_EVENT_CHANNEL_SWITCH_STARTED,
6335780fb4a2SCy Schubert 			data->ch_switch.freq,
6336780fb4a2SCy Schubert 			data->ch_switch.ht_enabled,
6337780fb4a2SCy Schubert 			data->ch_switch.ch_offset,
6338780fb4a2SCy Schubert 			channel_width_to_string(data->ch_switch.ch_width),
6339780fb4a2SCy Schubert 			data->ch_switch.cf1,
6340780fb4a2SCy Schubert 			data->ch_switch.cf2);
6341206b73d0SCy Schubert 		if (event == EVENT_CH_SWITCH_STARTED)
6342206b73d0SCy Schubert 			break;
6343780fb4a2SCy Schubert 
6344780fb4a2SCy Schubert 		wpa_s->assoc_freq = data->ch_switch.freq;
6345780fb4a2SCy Schubert 		wpa_s->current_ssid->frequency = data->ch_switch.freq;
6346c1d255d3SCy Schubert 		if (wpa_s->current_bss &&
6347c1d255d3SCy Schubert 		    wpa_s->current_bss->freq != data->ch_switch.freq) {
6348c1d255d3SCy Schubert 			wpa_s->current_bss->freq = data->ch_switch.freq;
6349c1d255d3SCy Schubert 			notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
6350c1d255d3SCy Schubert 					   wpa_s->current_bss);
6351c1d255d3SCy Schubert 		}
6352c1d255d3SCy Schubert 
6353c1d255d3SCy Schubert #ifdef CONFIG_SME
6354c1d255d3SCy Schubert 		switch (data->ch_switch.ch_offset) {
6355c1d255d3SCy Schubert 		case 1:
6356c1d255d3SCy Schubert 			wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
6357c1d255d3SCy Schubert 			break;
6358c1d255d3SCy Schubert 		case -1:
6359c1d255d3SCy Schubert 			wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
6360c1d255d3SCy Schubert 			break;
6361c1d255d3SCy Schubert 		default:
6362c1d255d3SCy Schubert 			wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
6363c1d255d3SCy Schubert 			break;
6364c1d255d3SCy Schubert 		}
6365c1d255d3SCy Schubert #endif /* CONFIG_SME */
6366780fb4a2SCy Schubert 
636785732ac8SCy Schubert #ifdef CONFIG_AP
6368780fb4a2SCy Schubert 		if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
6369780fb4a2SCy Schubert 		    wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
63704bc52338SCy Schubert 		    wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
6371780fb4a2SCy Schubert 		    wpa_s->current_ssid->mode ==
6372780fb4a2SCy Schubert 		    WPAS_MODE_P2P_GROUP_FORMATION) {
6373f05cddf9SRui Paulo 			wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
6374f05cddf9SRui Paulo 					  data->ch_switch.ht_enabled,
63755b9c547cSRui Paulo 					  data->ch_switch.ch_offset,
63765b9c547cSRui Paulo 					  data->ch_switch.ch_width,
63775b9c547cSRui Paulo 					  data->ch_switch.cf1,
6378206b73d0SCy Schubert 					  data->ch_switch.cf2,
6379*a90b9d01SCy Schubert 					  data->ch_switch.punct_bitmap,
6380206b73d0SCy Schubert 					  1);
6381780fb4a2SCy Schubert 		}
638285732ac8SCy Schubert #endif /* CONFIG_AP */
6383780fb4a2SCy Schubert 
6384c1d255d3SCy Schubert 		if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
63854bc52338SCy Schubert 			sme_event_ch_switch(wpa_s);
6386c1d255d3SCy Schubert 
6387780fb4a2SCy Schubert 		wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
638885732ac8SCy Schubert 		wnm_clear_coloc_intf_reporting(wpa_s);
6389f05cddf9SRui Paulo 		break;
639085732ac8SCy Schubert #ifdef CONFIG_AP
63915b9c547cSRui Paulo #ifdef NEED_AP_MLME
63925b9c547cSRui Paulo 	case EVENT_DFS_RADAR_DETECTED:
63935b9c547cSRui Paulo 		if (data)
639485732ac8SCy Schubert 			wpas_ap_event_dfs_radar_detected(wpa_s,
639585732ac8SCy Schubert 							 &data->dfs_event);
63965b9c547cSRui Paulo 		break;
639785732ac8SCy Schubert 	case EVENT_DFS_NOP_FINISHED:
639885732ac8SCy Schubert 		if (data)
639985732ac8SCy Schubert 			wpas_ap_event_dfs_cac_nop_finished(wpa_s,
640085732ac8SCy Schubert 							   &data->dfs_event);
640185732ac8SCy Schubert 		break;
640285732ac8SCy Schubert #endif /* NEED_AP_MLME */
640385732ac8SCy Schubert #endif /* CONFIG_AP */
64045b9c547cSRui Paulo 	case EVENT_DFS_CAC_STARTED:
64055b9c547cSRui Paulo 		if (data)
64065b9c547cSRui Paulo 			wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
64075b9c547cSRui Paulo 		break;
64085b9c547cSRui Paulo 	case EVENT_DFS_CAC_FINISHED:
64095b9c547cSRui Paulo 		if (data)
64105b9c547cSRui Paulo 			wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
64115b9c547cSRui Paulo 		break;
64125b9c547cSRui Paulo 	case EVENT_DFS_CAC_ABORTED:
64135b9c547cSRui Paulo 		if (data)
64145b9c547cSRui Paulo 			wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
64155b9c547cSRui Paulo 		break;
6416f05cddf9SRui Paulo 	case EVENT_RX_MGMT: {
6417f05cddf9SRui Paulo 		u16 fc, stype;
6418f05cddf9SRui Paulo 		const struct ieee80211_mgmt *mgmt;
6419f05cddf9SRui Paulo 
64205b9c547cSRui Paulo #ifdef CONFIG_TESTING_OPTIONS
64215b9c547cSRui Paulo 		if (wpa_s->ext_mgmt_frame_handling) {
64225b9c547cSRui Paulo 			struct rx_mgmt *rx = &data->rx_mgmt;
64235b9c547cSRui Paulo 			size_t hex_len = 2 * rx->frame_len + 1;
64245b9c547cSRui Paulo 			char *hex = os_malloc(hex_len);
64255b9c547cSRui Paulo 			if (hex) {
64265b9c547cSRui Paulo 				wpa_snprintf_hex(hex, hex_len,
64275b9c547cSRui Paulo 						 rx->frame, rx->frame_len);
64285b9c547cSRui Paulo 				wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
64295b9c547cSRui Paulo 					rx->freq, rx->datarate, rx->ssi_signal,
64305b9c547cSRui Paulo 					hex);
64315b9c547cSRui Paulo 				os_free(hex);
64325b9c547cSRui Paulo 			}
64335b9c547cSRui Paulo 			break;
64345b9c547cSRui Paulo 		}
64355b9c547cSRui Paulo #endif /* CONFIG_TESTING_OPTIONS */
64365b9c547cSRui Paulo 
6437f05cddf9SRui Paulo 		mgmt = (const struct ieee80211_mgmt *)
6438f05cddf9SRui Paulo 			data->rx_mgmt.frame;
6439f05cddf9SRui Paulo 		fc = le_to_host16(mgmt->frame_control);
6440f05cddf9SRui Paulo 		stype = WLAN_FC_GET_STYPE(fc);
6441f05cddf9SRui Paulo 
64425b9c547cSRui Paulo #ifdef CONFIG_AP
6443f05cddf9SRui Paulo 		if (wpa_s->ap_iface == NULL) {
64445b9c547cSRui Paulo #endif /* CONFIG_AP */
6445f05cddf9SRui Paulo #ifdef CONFIG_P2P
6446f05cddf9SRui Paulo 			if (stype == WLAN_FC_STYPE_PROBE_REQ &&
6447780fb4a2SCy Schubert 			    data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
6448f05cddf9SRui Paulo 				const u8 *src = mgmt->sa;
6449780fb4a2SCy Schubert 				const u8 *ie;
6450780fb4a2SCy Schubert 				size_t ie_len;
6451780fb4a2SCy Schubert 
6452780fb4a2SCy Schubert 				ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
6453780fb4a2SCy Schubert 				ie_len = data->rx_mgmt.frame_len -
6454780fb4a2SCy Schubert 					IEEE80211_HDRLEN;
6455f05cddf9SRui Paulo 				wpas_p2p_probe_req_rx(
6456f05cddf9SRui Paulo 					wpa_s, src, mgmt->da,
6457f05cddf9SRui Paulo 					mgmt->bssid, ie, ie_len,
6458325151a3SRui Paulo 					data->rx_mgmt.freq,
6459f05cddf9SRui Paulo 					data->rx_mgmt.ssi_signal);
6460f05cddf9SRui Paulo 				break;
6461f05cddf9SRui Paulo 			}
6462f05cddf9SRui Paulo #endif /* CONFIG_P2P */
64635b9c547cSRui Paulo #ifdef CONFIG_IBSS_RSN
64645b9c547cSRui Paulo 			if (wpa_s->current_ssid &&
64655b9c547cSRui Paulo 			    wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
64665b9c547cSRui Paulo 			    stype == WLAN_FC_STYPE_AUTH &&
64675b9c547cSRui Paulo 			    data->rx_mgmt.frame_len >= 30) {
64685b9c547cSRui Paulo 				wpa_supplicant_event_ibss_auth(wpa_s, data);
64695b9c547cSRui Paulo 				break;
64705b9c547cSRui Paulo 			}
64715b9c547cSRui Paulo #endif /* CONFIG_IBSS_RSN */
64725b9c547cSRui Paulo 
64735b9c547cSRui Paulo 			if (stype == WLAN_FC_STYPE_ACTION) {
64745b9c547cSRui Paulo 				wpas_event_rx_mgmt_action(
64755b9c547cSRui Paulo 					wpa_s, data->rx_mgmt.frame,
64765b9c547cSRui Paulo 					data->rx_mgmt.frame_len,
64775b9c547cSRui Paulo 					data->rx_mgmt.freq,
64785b9c547cSRui Paulo 					data->rx_mgmt.ssi_signal);
64795b9c547cSRui Paulo 				break;
64805b9c547cSRui Paulo 			}
64815b9c547cSRui Paulo 
64825b9c547cSRui Paulo 			if (wpa_s->ifmsh) {
64835b9c547cSRui Paulo 				mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
64845b9c547cSRui Paulo 				break;
64855b9c547cSRui Paulo 			}
6486c1d255d3SCy Schubert #ifdef CONFIG_PASN
6487c1d255d3SCy Schubert 			if (stype == WLAN_FC_STYPE_AUTH &&
6488c1d255d3SCy Schubert 			    wpas_pasn_auth_rx(wpa_s, mgmt,
6489c1d255d3SCy Schubert 					      data->rx_mgmt.frame_len) != -2)
6490c1d255d3SCy Schubert 				break;
6491c1d255d3SCy Schubert #endif /* CONFIG_PASN */
64925b9c547cSRui Paulo 
649385732ac8SCy Schubert #ifdef CONFIG_SAE
649485732ac8SCy Schubert 			if (stype == WLAN_FC_STYPE_AUTH &&
649585732ac8SCy Schubert 			    !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
649685732ac8SCy Schubert 			    (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
649785732ac8SCy Schubert 				sme_external_auth_mgmt_rx(
649885732ac8SCy Schubert 					wpa_s, data->rx_mgmt.frame,
649985732ac8SCy Schubert 					data->rx_mgmt.frame_len);
650085732ac8SCy Schubert 				break;
650185732ac8SCy Schubert 			}
650285732ac8SCy Schubert #endif /* CONFIG_SAE */
6503f05cddf9SRui Paulo 			wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
6504f05cddf9SRui Paulo 				"management frame in non-AP mode");
6505f05cddf9SRui Paulo 			break;
65065b9c547cSRui Paulo #ifdef CONFIG_AP
6507f05cddf9SRui Paulo 		}
6508f05cddf9SRui Paulo 
6509f05cddf9SRui Paulo 		if (stype == WLAN_FC_STYPE_PROBE_REQ &&
6510780fb4a2SCy Schubert 		    data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
6511780fb4a2SCy Schubert 			const u8 *ie;
6512780fb4a2SCy Schubert 			size_t ie_len;
6513780fb4a2SCy Schubert 
6514780fb4a2SCy Schubert 			ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
6515780fb4a2SCy Schubert 			ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
6516f05cddf9SRui Paulo 
6517f05cddf9SRui Paulo 			wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
6518f05cddf9SRui Paulo 					 mgmt->bssid, ie, ie_len,
6519f05cddf9SRui Paulo 					 data->rx_mgmt.ssi_signal);
6520f05cddf9SRui Paulo 		}
6521f05cddf9SRui Paulo 
6522e28a4053SRui Paulo 		ap_mgmt_rx(wpa_s, &data->rx_mgmt);
6523e28a4053SRui Paulo #endif /* CONFIG_AP */
6524e28a4053SRui Paulo 		break;
6525e28a4053SRui Paulo 		}
6526f05cddf9SRui Paulo 	case EVENT_RX_PROBE_REQ:
6527f05cddf9SRui Paulo 		if (data->rx_probe_req.sa == NULL ||
6528f05cddf9SRui Paulo 		    data->rx_probe_req.ie == NULL)
6529f05cddf9SRui Paulo 			break;
6530f05cddf9SRui Paulo #ifdef CONFIG_AP
6531f05cddf9SRui Paulo 		if (wpa_s->ap_iface) {
6532f05cddf9SRui Paulo 			hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
6533f05cddf9SRui Paulo 					     data->rx_probe_req.sa,
6534f05cddf9SRui Paulo 					     data->rx_probe_req.da,
6535f05cddf9SRui Paulo 					     data->rx_probe_req.bssid,
6536f05cddf9SRui Paulo 					     data->rx_probe_req.ie,
6537f05cddf9SRui Paulo 					     data->rx_probe_req.ie_len,
6538f05cddf9SRui Paulo 					     data->rx_probe_req.ssi_signal);
6539f05cddf9SRui Paulo 			break;
6540f05cddf9SRui Paulo 		}
6541f05cddf9SRui Paulo #endif /* CONFIG_AP */
6542f05cddf9SRui Paulo 		wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
6543f05cddf9SRui Paulo 				      data->rx_probe_req.da,
6544f05cddf9SRui Paulo 				      data->rx_probe_req.bssid,
6545f05cddf9SRui Paulo 				      data->rx_probe_req.ie,
6546f05cddf9SRui Paulo 				      data->rx_probe_req.ie_len,
6547325151a3SRui Paulo 				      0,
6548f05cddf9SRui Paulo 				      data->rx_probe_req.ssi_signal);
6549f05cddf9SRui Paulo 		break;
6550f05cddf9SRui Paulo 	case EVENT_REMAIN_ON_CHANNEL:
6551f05cddf9SRui Paulo #ifdef CONFIG_OFFCHANNEL
6552f05cddf9SRui Paulo 		offchannel_remain_on_channel_cb(
6553f05cddf9SRui Paulo 			wpa_s, data->remain_on_channel.freq,
6554f05cddf9SRui Paulo 			data->remain_on_channel.duration);
6555f05cddf9SRui Paulo #endif /* CONFIG_OFFCHANNEL */
6556f05cddf9SRui Paulo 		wpas_p2p_remain_on_channel_cb(
6557f05cddf9SRui Paulo 			wpa_s, data->remain_on_channel.freq,
6558f05cddf9SRui Paulo 			data->remain_on_channel.duration);
6559c1d255d3SCy Schubert #ifdef CONFIG_DPP
6560c1d255d3SCy Schubert 		wpas_dpp_remain_on_channel_cb(
6561c1d255d3SCy Schubert 			wpa_s, data->remain_on_channel.freq,
6562c1d255d3SCy Schubert 			data->remain_on_channel.duration);
6563c1d255d3SCy Schubert #endif /* CONFIG_DPP */
6564*a90b9d01SCy Schubert #ifdef CONFIG_NAN_USD
6565*a90b9d01SCy Schubert 		wpas_nan_usd_remain_on_channel_cb(
6566*a90b9d01SCy Schubert 			wpa_s, data->remain_on_channel.freq,
6567*a90b9d01SCy Schubert 			data->remain_on_channel.duration);
6568*a90b9d01SCy Schubert #endif /* CONFIG_NAN_USD */
6569f05cddf9SRui Paulo 		break;
6570f05cddf9SRui Paulo 	case EVENT_CANCEL_REMAIN_ON_CHANNEL:
6571f05cddf9SRui Paulo #ifdef CONFIG_OFFCHANNEL
6572f05cddf9SRui Paulo 		offchannel_cancel_remain_on_channel_cb(
6573f05cddf9SRui Paulo 			wpa_s, data->remain_on_channel.freq);
6574f05cddf9SRui Paulo #endif /* CONFIG_OFFCHANNEL */
6575f05cddf9SRui Paulo 		wpas_p2p_cancel_remain_on_channel_cb(
6576f05cddf9SRui Paulo 			wpa_s, data->remain_on_channel.freq);
657785732ac8SCy Schubert #ifdef CONFIG_DPP
657885732ac8SCy Schubert 		wpas_dpp_cancel_remain_on_channel_cb(
657985732ac8SCy Schubert 			wpa_s, data->remain_on_channel.freq);
658085732ac8SCy Schubert #endif /* CONFIG_DPP */
6581*a90b9d01SCy Schubert #ifdef CONFIG_NAN_USD
6582*a90b9d01SCy Schubert 		wpas_nan_usd_cancel_remain_on_channel_cb(
6583*a90b9d01SCy Schubert 			wpa_s, data->remain_on_channel.freq);
6584*a90b9d01SCy Schubert #endif /* CONFIG_NAN_USD */
6585f05cddf9SRui Paulo 		break;
6586e28a4053SRui Paulo 	case EVENT_EAPOL_RX:
6587e28a4053SRui Paulo 		wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
6588e28a4053SRui Paulo 					data->eapol_rx.data,
6589*a90b9d01SCy Schubert 					data->eapol_rx.data_len,
6590*a90b9d01SCy Schubert 					data->eapol_rx.encrypted);
6591e28a4053SRui Paulo 		break;
6592e28a4053SRui Paulo 	case EVENT_SIGNAL_CHANGE:
65935b9c547cSRui Paulo 		wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
6594*a90b9d01SCy Schubert 			"above=%d signal=%d noise=%d txrate=%lu",
65955b9c547cSRui Paulo 			data->signal_change.above_threshold,
6596*a90b9d01SCy Schubert 			data->signal_change.data.signal,
65975b9c547cSRui Paulo 			data->signal_change.current_noise,
6598*a90b9d01SCy Schubert 			data->signal_change.data.current_tx_rate);
65995b9c547cSRui Paulo 		wpa_bss_update_level(wpa_s->current_bss,
6600*a90b9d01SCy Schubert 				     data->signal_change.data.signal);
6601e28a4053SRui Paulo 		bgscan_notify_signal_change(
6602f05cddf9SRui Paulo 			wpa_s, data->signal_change.above_threshold,
6603*a90b9d01SCy Schubert 			data->signal_change.data.signal,
6604f05cddf9SRui Paulo 			data->signal_change.current_noise,
6605*a90b9d01SCy Schubert 			data->signal_change.data.current_tx_rate);
6606*a90b9d01SCy Schubert 		os_memcpy(&wpa_s->last_signal_info, data,
6607*a90b9d01SCy Schubert 			  sizeof(struct wpa_signal_info));
6608*a90b9d01SCy Schubert 		wpas_notify_signal_change(wpa_s);
6609f05cddf9SRui Paulo 		break;
661085732ac8SCy Schubert 	case EVENT_INTERFACE_MAC_CHANGED:
661185732ac8SCy Schubert 		wpa_supplicant_update_mac_addr(wpa_s);
66124b72b91aSCy Schubert 		wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
661385732ac8SCy Schubert 		break;
6614f05cddf9SRui Paulo 	case EVENT_INTERFACE_ENABLED:
6615f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
6616f05cddf9SRui Paulo 		if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
66174b72b91aSCy Schubert 			u8 addr[ETH_ALEN];
66184b72b91aSCy Schubert 
6619c1d255d3SCy Schubert 			eloop_cancel_timeout(wpas_clear_disabled_interface,
6620c1d255d3SCy Schubert 					     wpa_s, NULL);
66214b72b91aSCy Schubert 			os_memcpy(addr, wpa_s->own_addr, ETH_ALEN);
6622f05cddf9SRui Paulo 			wpa_supplicant_update_mac_addr(wpa_s);
6623*a90b9d01SCy Schubert 			if (!ether_addr_equal(addr, wpa_s->own_addr))
66244b72b91aSCy Schubert 				wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
66254b72b91aSCy Schubert 			else
66264b72b91aSCy Schubert 				wpa_sm_pmksa_cache_reconfig(wpa_s->wpa);
6627206b73d0SCy Schubert 			wpa_supplicant_set_default_scan_ies(wpa_s);
66285b9c547cSRui Paulo 			if (wpa_s->p2p_mgmt) {
66295b9c547cSRui Paulo 				wpa_supplicant_set_state(wpa_s,
66305b9c547cSRui Paulo 							 WPA_DISCONNECTED);
66315b9c547cSRui Paulo 				break;
66325b9c547cSRui Paulo 			}
66335b9c547cSRui Paulo 
6634f05cddf9SRui Paulo #ifdef CONFIG_AP
6635f05cddf9SRui Paulo 			if (!wpa_s->ap_iface) {
6636f05cddf9SRui Paulo 				wpa_supplicant_set_state(wpa_s,
6637f05cddf9SRui Paulo 							 WPA_DISCONNECTED);
66385b9c547cSRui Paulo 				wpa_s->scan_req = NORMAL_SCAN_REQ;
6639f05cddf9SRui Paulo 				wpa_supplicant_req_scan(wpa_s, 0, 0);
6640f05cddf9SRui Paulo 			} else
6641f05cddf9SRui Paulo 				wpa_supplicant_set_state(wpa_s,
6642f05cddf9SRui Paulo 							 WPA_COMPLETED);
6643f05cddf9SRui Paulo #else /* CONFIG_AP */
6644f05cddf9SRui Paulo 			wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
6645f05cddf9SRui Paulo 			wpa_supplicant_req_scan(wpa_s, 0, 0);
6646f05cddf9SRui Paulo #endif /* CONFIG_AP */
6647f05cddf9SRui Paulo 		}
6648f05cddf9SRui Paulo 		break;
6649f05cddf9SRui Paulo 	case EVENT_INTERFACE_DISABLED:
6650f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
66515b9c547cSRui Paulo #ifdef CONFIG_P2P
66525b9c547cSRui Paulo 		if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
66535b9c547cSRui Paulo 		    (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
66545b9c547cSRui Paulo 		     wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
66555b9c547cSRui Paulo 			/*
66565b9c547cSRui Paulo 			 * Mark interface disabled if this happens to end up not
66575b9c547cSRui Paulo 			 * being removed as a separate P2P group interface.
66585b9c547cSRui Paulo 			 */
66595b9c547cSRui Paulo 			wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
66605b9c547cSRui Paulo 			/*
66615b9c547cSRui Paulo 			 * The interface was externally disabled. Remove
66625b9c547cSRui Paulo 			 * it assuming an external entity will start a
66635b9c547cSRui Paulo 			 * new session if needed.
66645b9c547cSRui Paulo 			 */
66655b9c547cSRui Paulo 			if (wpa_s->current_ssid &&
66665b9c547cSRui Paulo 			    wpa_s->current_ssid->p2p_group)
66675b9c547cSRui Paulo 				wpas_p2p_interface_unavailable(wpa_s);
66685b9c547cSRui Paulo 			else
66695b9c547cSRui Paulo 				wpas_p2p_disconnect(wpa_s);
66705b9c547cSRui Paulo 			/*
66715b9c547cSRui Paulo 			 * wpa_s instance may have been freed, so must not use
66725b9c547cSRui Paulo 			 * it here anymore.
66735b9c547cSRui Paulo 			 */
66745b9c547cSRui Paulo 			break;
66755b9c547cSRui Paulo 		}
66765b9c547cSRui Paulo 		if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
66775b9c547cSRui Paulo 		    p2p_in_progress(wpa_s->global->p2p) > 1) {
66785b9c547cSRui Paulo 			/* This radio work will be cancelled, so clear P2P
66795b9c547cSRui Paulo 			 * state as well.
66805b9c547cSRui Paulo 			 */
66815b9c547cSRui Paulo 			p2p_stop_find(wpa_s->global->p2p);
66825b9c547cSRui Paulo 		}
66835b9c547cSRui Paulo #endif /* CONFIG_P2P */
66845b9c547cSRui Paulo 
66855b9c547cSRui Paulo 		if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
66865b9c547cSRui Paulo 			/*
66875b9c547cSRui Paulo 			 * Indicate disconnection to keep ctrl_iface events
66885b9c547cSRui Paulo 			 * consistent.
66895b9c547cSRui Paulo 			 */
66905b9c547cSRui Paulo 			wpa_supplicant_event_disassoc(
66915b9c547cSRui Paulo 				wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
66925b9c547cSRui Paulo 		}
6693f05cddf9SRui Paulo 		wpa_supplicant_mark_disassoc(wpa_s);
6694c1d255d3SCy Schubert 		os_reltime_age(&wpa_s->last_scan, &age);
6695c1d255d3SCy Schubert 		if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
6696c1d255d3SCy Schubert 			clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
6697c1d255d3SCy Schubert 			clear_at.usec = 0;
6698c1d255d3SCy Schubert 		} else {
6699c1d255d3SCy Schubert 			struct os_reltime tmp;
6700c1d255d3SCy Schubert 
6701c1d255d3SCy Schubert 			tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
6702c1d255d3SCy Schubert 			tmp.usec = 0;
6703c1d255d3SCy Schubert 			os_reltime_sub(&tmp, &age, &clear_at);
6704c1d255d3SCy Schubert 		}
6705c1d255d3SCy Schubert 		eloop_register_timeout(clear_at.sec, clear_at.usec,
6706c1d255d3SCy Schubert 				       wpas_clear_disabled_interface,
6707c1d255d3SCy Schubert 				       wpa_s, NULL);
67085b9c547cSRui Paulo 		radio_remove_works(wpa_s, NULL, 0);
67095b9c547cSRui Paulo 
6710f05cddf9SRui Paulo 		wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
6711f05cddf9SRui Paulo 		break;
6712f05cddf9SRui Paulo 	case EVENT_CHANNEL_LIST_CHANGED:
67135b9c547cSRui Paulo 		wpa_supplicant_update_channel_list(
67145b9c547cSRui Paulo 			wpa_s, &data->channel_list_changed);
6715f05cddf9SRui Paulo 		break;
6716f05cddf9SRui Paulo 	case EVENT_INTERFACE_UNAVAILABLE:
6717f05cddf9SRui Paulo 		wpas_p2p_interface_unavailable(wpa_s);
6718f05cddf9SRui Paulo 		break;
6719f05cddf9SRui Paulo 	case EVENT_BEST_CHANNEL:
6720f05cddf9SRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
6721f05cddf9SRui Paulo 			"(%d %d %d)",
6722f05cddf9SRui Paulo 			data->best_chan.freq_24, data->best_chan.freq_5,
6723f05cddf9SRui Paulo 			data->best_chan.freq_overall);
6724f05cddf9SRui Paulo 		wpa_s->best_24_freq = data->best_chan.freq_24;
6725f05cddf9SRui Paulo 		wpa_s->best_5_freq = data->best_chan.freq_5;
6726f05cddf9SRui Paulo 		wpa_s->best_overall_freq = data->best_chan.freq_overall;
6727f05cddf9SRui Paulo 		wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
6728f05cddf9SRui Paulo 					      data->best_chan.freq_5,
6729f05cddf9SRui Paulo 					      data->best_chan.freq_overall);
6730f05cddf9SRui Paulo 		break;
6731f05cddf9SRui Paulo 	case EVENT_UNPROT_DEAUTH:
6732f05cddf9SRui Paulo 		wpa_supplicant_event_unprot_deauth(wpa_s,
6733f05cddf9SRui Paulo 						   &data->unprot_deauth);
6734f05cddf9SRui Paulo 		break;
6735f05cddf9SRui Paulo 	case EVENT_UNPROT_DISASSOC:
6736f05cddf9SRui Paulo 		wpa_supplicant_event_unprot_disassoc(wpa_s,
6737f05cddf9SRui Paulo 						     &data->unprot_disassoc);
6738f05cddf9SRui Paulo 		break;
6739f05cddf9SRui Paulo 	case EVENT_STATION_LOW_ACK:
6740f05cddf9SRui Paulo #ifdef CONFIG_AP
6741f05cddf9SRui Paulo 		if (wpa_s->ap_iface && data)
6742f05cddf9SRui Paulo 			hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
6743f05cddf9SRui Paulo 						  data->low_ack.addr);
6744f05cddf9SRui Paulo #endif /* CONFIG_AP */
6745f05cddf9SRui Paulo #ifdef CONFIG_TDLS
6746f05cddf9SRui Paulo 		if (data)
67475b9c547cSRui Paulo 			wpa_tdls_disable_unreachable_link(wpa_s->wpa,
67485b9c547cSRui Paulo 							  data->low_ack.addr);
6749f05cddf9SRui Paulo #endif /* CONFIG_TDLS */
6750f05cddf9SRui Paulo 		break;
6751f05cddf9SRui Paulo 	case EVENT_IBSS_PEER_LOST:
6752f05cddf9SRui Paulo #ifdef CONFIG_IBSS_RSN
6753f05cddf9SRui Paulo 		ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
6754f05cddf9SRui Paulo #endif /* CONFIG_IBSS_RSN */
6755f05cddf9SRui Paulo 		break;
6756f05cddf9SRui Paulo 	case EVENT_DRIVER_GTK_REKEY:
6757*a90b9d01SCy Schubert 		if (!ether_addr_equal(data->driver_gtk_rekey.bssid,
6758*a90b9d01SCy Schubert 				      wpa_s->bssid))
6759f05cddf9SRui Paulo 			break;
6760f05cddf9SRui Paulo 		if (!wpa_s->wpa)
6761f05cddf9SRui Paulo 			break;
6762f05cddf9SRui Paulo 		wpa_sm_update_replay_ctr(wpa_s->wpa,
6763f05cddf9SRui Paulo 					 data->driver_gtk_rekey.replay_ctr);
6764f05cddf9SRui Paulo 		break;
6765f05cddf9SRui Paulo 	case EVENT_SCHED_SCAN_STOPPED:
6766f05cddf9SRui Paulo 		wpa_s->sched_scanning = 0;
6767780fb4a2SCy Schubert 		resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
6768f05cddf9SRui Paulo 		wpa_supplicant_notify_scanning(wpa_s, 0);
6769f05cddf9SRui Paulo 
6770f05cddf9SRui Paulo 		if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6771f05cddf9SRui Paulo 			break;
6772f05cddf9SRui Paulo 
6773f05cddf9SRui Paulo 		/*
6774780fb4a2SCy Schubert 		 * If the driver stopped scanning without being requested to,
6775780fb4a2SCy Schubert 		 * request a new scan to continue scanning for networks.
6776780fb4a2SCy Schubert 		 */
6777780fb4a2SCy Schubert 		if (!wpa_s->sched_scan_stop_req &&
6778780fb4a2SCy Schubert 		    wpa_s->wpa_state == WPA_SCANNING) {
6779780fb4a2SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
6780780fb4a2SCy Schubert 				"Restart scanning after unexpected sched_scan stop event");
6781780fb4a2SCy Schubert 			wpa_supplicant_req_scan(wpa_s, 1, 0);
6782780fb4a2SCy Schubert 			break;
6783780fb4a2SCy Schubert 		}
6784780fb4a2SCy Schubert 
6785780fb4a2SCy Schubert 		wpa_s->sched_scan_stop_req = 0;
6786780fb4a2SCy Schubert 
6787780fb4a2SCy Schubert 		/*
67885b9c547cSRui Paulo 		 * Start a new sched scan to continue searching for more SSIDs
67895b9c547cSRui Paulo 		 * either if timed out or PNO schedule scan is pending.
6790f05cddf9SRui Paulo 		 */
67915b9c547cSRui Paulo 		if (wpa_s->sched_scan_timed_out) {
6792f05cddf9SRui Paulo 			wpa_supplicant_req_sched_scan(wpa_s);
67935b9c547cSRui Paulo 		} else if (wpa_s->pno_sched_pending) {
67945b9c547cSRui Paulo 			wpa_s->pno_sched_pending = 0;
67955b9c547cSRui Paulo 			wpas_start_pno(wpa_s);
6796325151a3SRui Paulo 		} else if (resched) {
6797325151a3SRui Paulo 			wpa_supplicant_req_scan(wpa_s, 0, 0);
67985b9c547cSRui Paulo 		}
67995b9c547cSRui Paulo 
6800f05cddf9SRui Paulo 		break;
6801f05cddf9SRui Paulo 	case EVENT_WPS_BUTTON_PUSHED:
6802f05cddf9SRui Paulo #ifdef CONFIG_WPS
68034bc52338SCy Schubert 		wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
6804f05cddf9SRui Paulo #endif /* CONFIG_WPS */
6805e28a4053SRui Paulo 		break;
68065b9c547cSRui Paulo 	case EVENT_AVOID_FREQUENCIES:
68075b9c547cSRui Paulo 		wpa_supplicant_notify_avoid_freq(wpa_s, data);
68085b9c547cSRui Paulo 		break;
68095b9c547cSRui Paulo 	case EVENT_CONNECT_FAILED_REASON:
68105b9c547cSRui Paulo #ifdef CONFIG_AP
68115b9c547cSRui Paulo 		if (!wpa_s->ap_iface || !data)
68125b9c547cSRui Paulo 			break;
68135b9c547cSRui Paulo 		hostapd_event_connect_failed_reason(
68145b9c547cSRui Paulo 			wpa_s->ap_iface->bss[0],
68155b9c547cSRui Paulo 			data->connect_failed_reason.addr,
68165b9c547cSRui Paulo 			data->connect_failed_reason.code);
68175b9c547cSRui Paulo #endif /* CONFIG_AP */
68185b9c547cSRui Paulo 		break;
68195b9c547cSRui Paulo 	case EVENT_NEW_PEER_CANDIDATE:
68205b9c547cSRui Paulo #ifdef CONFIG_MESH
68215b9c547cSRui Paulo 		if (!wpa_s->ifmsh || !data)
68225b9c547cSRui Paulo 			break;
68235b9c547cSRui Paulo 		wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
68245b9c547cSRui Paulo 				     data->mesh_peer.ies,
68255b9c547cSRui Paulo 				     data->mesh_peer.ie_len);
68265b9c547cSRui Paulo #endif /* CONFIG_MESH */
68275b9c547cSRui Paulo 		break;
6828780fb4a2SCy Schubert 	case EVENT_SURVEY:
6829780fb4a2SCy Schubert #ifdef CONFIG_AP
6830780fb4a2SCy Schubert 		if (!wpa_s->ap_iface)
6831780fb4a2SCy Schubert 			break;
6832780fb4a2SCy Schubert 		hostapd_event_get_survey(wpa_s->ap_iface,
6833780fb4a2SCy Schubert 					 &data->survey_results);
6834780fb4a2SCy Schubert #endif /* CONFIG_AP */
6835780fb4a2SCy Schubert 		break;
6836780fb4a2SCy Schubert 	case EVENT_ACS_CHANNEL_SELECTED:
683785732ac8SCy Schubert #ifdef CONFIG_AP
6838780fb4a2SCy Schubert #ifdef CONFIG_ACS
6839780fb4a2SCy Schubert 		if (!wpa_s->ap_iface)
6840780fb4a2SCy Schubert 			break;
6841780fb4a2SCy Schubert 		hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
6842780fb4a2SCy Schubert 					     &data->acs_selected_channels);
6843780fb4a2SCy Schubert #endif /* CONFIG_ACS */
684485732ac8SCy Schubert #endif /* CONFIG_AP */
6845780fb4a2SCy Schubert 		break;
6846780fb4a2SCy Schubert 	case EVENT_P2P_LO_STOP:
6847780fb4a2SCy Schubert #ifdef CONFIG_P2P
6848780fb4a2SCy Schubert 		wpa_s->p2p_lo_started = 0;
6849780fb4a2SCy Schubert 		wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
6850780fb4a2SCy Schubert 			P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
6851780fb4a2SCy Schubert 			data->p2p_lo_stop.reason_code);
6852780fb4a2SCy Schubert #endif /* CONFIG_P2P */
6853780fb4a2SCy Schubert 		break;
685485732ac8SCy Schubert 	case EVENT_BEACON_LOSS:
685585732ac8SCy Schubert 		if (!wpa_s->current_bss || !wpa_s->current_ssid)
685685732ac8SCy Schubert 			break;
685785732ac8SCy Schubert 		wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
685885732ac8SCy Schubert 		bgscan_notify_beacon_loss(wpa_s);
685985732ac8SCy Schubert 		break;
686085732ac8SCy Schubert 	case EVENT_EXTERNAL_AUTH:
686185732ac8SCy Schubert #ifdef CONFIG_SAE
686285732ac8SCy Schubert 		if (!wpa_s->current_ssid) {
686385732ac8SCy Schubert 			wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
686485732ac8SCy Schubert 			break;
686585732ac8SCy Schubert 		}
686685732ac8SCy Schubert 		sme_external_auth_trigger(wpa_s, data);
686785732ac8SCy Schubert #endif /* CONFIG_SAE */
686885732ac8SCy Schubert 		break;
6869*a90b9d01SCy Schubert #ifdef CONFIG_PASN
6870*a90b9d01SCy Schubert 	case EVENT_PASN_AUTH:
6871*a90b9d01SCy Schubert 		wpas_pasn_auth_trigger(wpa_s, &data->pasn_auth);
6872*a90b9d01SCy Schubert 		break;
6873*a90b9d01SCy Schubert #endif /* CONFIG_PASN */
687485732ac8SCy Schubert 	case EVENT_PORT_AUTHORIZED:
6875*a90b9d01SCy Schubert #ifdef CONFIG_AP
6876*a90b9d01SCy Schubert 		if (wpa_s->ap_iface && wpa_s->ap_iface->bss[0]) {
6877*a90b9d01SCy Schubert 			struct sta_info *sta;
6878*a90b9d01SCy Schubert 
6879*a90b9d01SCy Schubert 			sta = ap_get_sta(wpa_s->ap_iface->bss[0],
6880*a90b9d01SCy Schubert 					 data->port_authorized.sta_addr);
6881*a90b9d01SCy Schubert 			if (sta)
6882*a90b9d01SCy Schubert 				ap_sta_set_authorized(wpa_s->ap_iface->bss[0],
6883*a90b9d01SCy Schubert 						      sta, 1);
6884*a90b9d01SCy Schubert 			else
6885*a90b9d01SCy Schubert 				wpa_printf(MSG_DEBUG,
6886*a90b9d01SCy Schubert 					   "No STA info matching port authorized event found");
6887*a90b9d01SCy Schubert 			break;
6888*a90b9d01SCy Schubert 		}
6889*a90b9d01SCy Schubert #endif /* CONFIG_AP */
6890*a90b9d01SCy Schubert #ifndef CONFIG_NO_WPA
6891*a90b9d01SCy Schubert 		if (data->port_authorized.td_bitmap_len) {
6892*a90b9d01SCy Schubert 			wpa_printf(MSG_DEBUG,
6893*a90b9d01SCy Schubert 				   "WPA3: Transition Disable bitmap from the driver event: 0x%x",
6894*a90b9d01SCy Schubert 				   data->port_authorized.td_bitmap[0]);
6895*a90b9d01SCy Schubert 			wpas_transition_disable(
6896*a90b9d01SCy Schubert 				wpa_s, data->port_authorized.td_bitmap[0]);
6897*a90b9d01SCy Schubert 		}
6898*a90b9d01SCy Schubert #endif /* CONFIG_NO_WPA */
689985732ac8SCy Schubert 		wpa_supplicant_event_port_authorized(wpa_s);
690085732ac8SCy Schubert 		break;
690185732ac8SCy Schubert 	case EVENT_STATION_OPMODE_CHANGED:
690285732ac8SCy Schubert #ifdef CONFIG_AP
690385732ac8SCy Schubert 		if (!wpa_s->ap_iface || !data)
690485732ac8SCy Schubert 			break;
690585732ac8SCy Schubert 
690685732ac8SCy Schubert 		hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
690785732ac8SCy Schubert 						 data->sta_opmode.addr,
690885732ac8SCy Schubert 						 data->sta_opmode.smps_mode,
690985732ac8SCy Schubert 						 data->sta_opmode.chan_width,
691085732ac8SCy Schubert 						 data->sta_opmode.rx_nss);
691185732ac8SCy Schubert #endif /* CONFIG_AP */
691285732ac8SCy Schubert 		break;
6913c1d255d3SCy Schubert 	case EVENT_UNPROT_BEACON:
6914c1d255d3SCy Schubert 		wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
6915c1d255d3SCy Schubert 		break;
6916*a90b9d01SCy Schubert 	case EVENT_TX_WAIT_EXPIRE:
6917*a90b9d01SCy Schubert #ifdef CONFIG_DPP
6918*a90b9d01SCy Schubert 		wpas_dpp_tx_wait_expire(wpa_s);
6919*a90b9d01SCy Schubert #endif /* CONFIG_DPP */
6920*a90b9d01SCy Schubert #ifdef CONFIG_NAN_USD
6921*a90b9d01SCy Schubert 		wpas_nan_usd_tx_wait_expire(wpa_s);
6922*a90b9d01SCy Schubert #endif /* CONFIG_NAN_USD */
6923*a90b9d01SCy Schubert 		break;
6924*a90b9d01SCy Schubert 	case EVENT_TID_LINK_MAP:
6925*a90b9d01SCy Schubert 		if (data)
6926*a90b9d01SCy Schubert 			wpas_tid_link_map(wpa_s, &data->t2l_map_info);
6927*a90b9d01SCy Schubert 		break;
692839beb93cSSam Leffler 	default:
6929f05cddf9SRui Paulo 		wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
693039beb93cSSam Leffler 		break;
693139beb93cSSam Leffler 	}
693239beb93cSSam Leffler }
6933780fb4a2SCy Schubert 
6934780fb4a2SCy Schubert 
wpa_supplicant_event_global(void * ctx,enum wpa_event_type event,union wpa_event_data * data)6935780fb4a2SCy Schubert void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
6936780fb4a2SCy Schubert 				 union wpa_event_data *data)
6937780fb4a2SCy Schubert {
6938780fb4a2SCy Schubert 	struct wpa_supplicant *wpa_s;
6939780fb4a2SCy Schubert 
6940780fb4a2SCy Schubert 	if (event != EVENT_INTERFACE_STATUS)
6941780fb4a2SCy Schubert 		return;
6942780fb4a2SCy Schubert 
6943780fb4a2SCy Schubert 	wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
6944780fb4a2SCy Schubert 	if (wpa_s && wpa_s->driver->get_ifindex) {
6945780fb4a2SCy Schubert 		unsigned int ifindex;
6946780fb4a2SCy Schubert 
6947780fb4a2SCy Schubert 		ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
6948780fb4a2SCy Schubert 		if (ifindex != data->interface_status.ifindex) {
6949780fb4a2SCy Schubert 			wpa_dbg(wpa_s, MSG_DEBUG,
6950780fb4a2SCy Schubert 				"interface status ifindex %d mismatch (%d)",
6951780fb4a2SCy Schubert 				ifindex, data->interface_status.ifindex);
6952780fb4a2SCy Schubert 			return;
6953780fb4a2SCy Schubert 		}
6954780fb4a2SCy Schubert 	}
6955780fb4a2SCy Schubert #ifdef CONFIG_MATCH_IFACE
6956780fb4a2SCy Schubert 	else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
6957780fb4a2SCy Schubert 		struct wpa_interface *wpa_i;
6958780fb4a2SCy Schubert 
6959780fb4a2SCy Schubert 		wpa_i = wpa_supplicant_match_iface(
6960780fb4a2SCy Schubert 			ctx, data->interface_status.ifname);
6961780fb4a2SCy Schubert 		if (!wpa_i)
6962780fb4a2SCy Schubert 			return;
6963780fb4a2SCy Schubert 		wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
6964780fb4a2SCy Schubert 		os_free(wpa_i);
6965780fb4a2SCy Schubert 	}
6966780fb4a2SCy Schubert #endif /* CONFIG_MATCH_IFACE */
6967780fb4a2SCy Schubert 
6968780fb4a2SCy Schubert 	if (wpa_s)
6969780fb4a2SCy Schubert 		wpa_supplicant_event(wpa_s, event, data);
6970780fb4a2SCy Schubert }
6971