]>
Commit | Line | Data |
---|---|---|
6fc6879b JM |
1 | /* |
2 | * WPA Supplicant - Driver event processing | |
e3b5bd81 | 3 | * Copyright (c) 2003-2019, Jouni Malinen <j@w1.fi> |
6fc6879b | 4 | * |
0f3d578e JM |
5 | * This software may be distributed under the terms of the BSD license. |
6 | * See README for more details. | |
6fc6879b JM |
7 | */ |
8 | ||
9 | #include "includes.h" | |
10 | ||
11 | #include "common.h" | |
12 | #include "eapol_supp/eapol_supp_sm.h" | |
3acb5005 | 13 | #include "rsn_supp/wpa.h" |
6fc6879b | 14 | #include "eloop.h" |
6fc6879b JM |
15 | #include "config.h" |
16 | #include "l2_packet/l2_packet.h" | |
17 | #include "wpa_supplicant_i.h" | |
2d5b792d | 18 | #include "driver_i.h" |
6fc6879b | 19 | #include "pcsc_funcs.h" |
3acb5005 JM |
20 | #include "rsn_supp/preauth.h" |
21 | #include "rsn_supp/pmksa_cache.h" | |
90973fb2 | 22 | #include "common/wpa_ctrl.h" |
6fc6879b | 23 | #include "eap_peer/eap.h" |
1d041bec | 24 | #include "ap/hostapd.h" |
93b7ddd0 | 25 | #include "p2p/p2p.h" |
9fbfd1b0 | 26 | #include "fst/fst.h" |
75cad1a0 | 27 | #include "wnm_sta.h" |
8bac466b | 28 | #include "notify.h" |
90973fb2 | 29 | #include "common/ieee802_11_defs.h" |
54f489be | 30 | #include "common/ieee802_11_common.h" |
461d39af | 31 | #include "common/gas_server.h" |
10ec6a5f | 32 | #include "common/dpp.h" |
bbb921da | 33 | #include "crypto/random.h" |
6fc6879b JM |
34 | #include "blacklist.h" |
35 | #include "wpas_glue.h" | |
351f09a2 | 36 | #include "wps_supplicant.h" |
11ef8d35 | 37 | #include "ibss_rsn.h" |
c2a04078 | 38 | #include "sme.h" |
04ea7b79 | 39 | #include "gas_query.h" |
9bae1be0 | 40 | #include "p2p_supplicant.h" |
60b94c98 | 41 | #include "bgscan.h" |
7c865c68 | 42 | #include "autoscan.h" |
f8b1f695 | 43 | #include "ap.h" |
6fa81a3b | 44 | #include "bss.h" |
9ba9fa07 | 45 | #include "scan.h" |
24f6497c | 46 | #include "offchannel.h" |
4d5bda5f | 47 | #include "interworking.h" |
8319e312 | 48 | #include "mesh.h" |
5f92659d | 49 | #include "mesh_mpm.h" |
a0413b17 | 50 | #include "wmm_ac.h" |
30d27b04 | 51 | #include "dpp_supplicant.h" |
6fc6879b JM |
52 | |
53 | ||
91073cca SD |
54 | #define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5 |
55 | ||
56 | ||
5d5c4ee5 | 57 | #ifndef CONFIG_NO_SCAN_PROCESSING |
06b7f58d | 58 | static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s, |
cc4952ad | 59 | int new_scan, int own_request); |
5d5c4ee5 | 60 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
d6bbcce4 JM |
61 | |
62 | ||
3d5f0e91 | 63 | int wpas_temp_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid) |
00e5e3d5 | 64 | { |
4e1eae1d | 65 | struct os_reltime now; |
00e5e3d5 JM |
66 | |
67 | if (ssid == NULL || ssid->disabled_until.sec == 0) | |
68 | return 0; | |
69 | ||
4e1eae1d | 70 | os_get_reltime(&now); |
00e5e3d5 JM |
71 | if (ssid->disabled_until.sec > now.sec) |
72 | return ssid->disabled_until.sec - now.sec; | |
73 | ||
74 | wpas_clear_temp_disabled(wpa_s, ssid, 0); | |
75 | ||
76 | return 0; | |
77 | } | |
78 | ||
79 | ||
eb926f12 | 80 | #ifndef CONFIG_NO_SCAN_PROCESSING |
9bd566a3 AS |
81 | /** |
82 | * wpas_reenabled_network_time - Time until first network is re-enabled | |
83 | * @wpa_s: Pointer to wpa_supplicant data | |
84 | * Returns: If all enabled networks are temporarily disabled, returns the time | |
85 | * (in sec) until the first network is re-enabled. Otherwise returns 0. | |
86 | * | |
87 | * This function is used in case all enabled networks are temporarily disabled, | |
88 | * in which case it returns the time (in sec) that the first network will be | |
89 | * re-enabled. The function assumes that at least one network is enabled. | |
90 | */ | |
91 | static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s) | |
92 | { | |
93 | struct wpa_ssid *ssid; | |
94 | int disabled_for, res = 0; | |
95 | ||
96 | #ifdef CONFIG_INTERWORKING | |
97 | if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking && | |
98 | wpa_s->conf->cred) | |
99 | return 0; | |
100 | #endif /* CONFIG_INTERWORKING */ | |
101 | ||
102 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { | |
103 | if (ssid->disabled) | |
104 | continue; | |
105 | ||
106 | disabled_for = wpas_temp_disabled(wpa_s, ssid); | |
107 | if (!disabled_for) | |
108 | return 0; | |
109 | ||
110 | if (!res || disabled_for < res) | |
111 | res = disabled_for; | |
112 | } | |
113 | ||
114 | return res; | |
115 | } | |
eb926f12 | 116 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
9bd566a3 AS |
117 | |
118 | ||
119 | void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx) | |
120 | { | |
121 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
122 | ||
123 | if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING) | |
124 | return; | |
125 | ||
126 | wpa_dbg(wpa_s, MSG_DEBUG, | |
127 | "Try to associate due to network getting re-enabled"); | |
128 | if (wpa_supplicant_fast_associate(wpa_s) != 1) { | |
129 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
130 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
131 | } | |
132 | } | |
133 | ||
134 | ||
5cd47405 JM |
135 | static struct wpa_bss * wpa_supplicant_get_new_bss( |
136 | struct wpa_supplicant *wpa_s, const u8 *bssid) | |
137 | { | |
138 | struct wpa_bss *bss = NULL; | |
139 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
140 | ||
141 | if (ssid->ssid_len > 0) | |
142 | bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len); | |
143 | if (!bss) | |
144 | bss = wpa_bss_get_bssid(wpa_s, bssid); | |
145 | ||
146 | return bss; | |
147 | } | |
148 | ||
149 | ||
068e3877 JM |
150 | static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s) |
151 | { | |
152 | struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid); | |
153 | ||
154 | if (!bss) { | |
155 | wpa_supplicant_update_scan_results(wpa_s); | |
156 | ||
157 | /* Get the BSS from the new scan results */ | |
158 | bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid); | |
159 | } | |
160 | ||
161 | if (bss) | |
162 | wpa_s->current_bss = bss; | |
163 | } | |
164 | ||
165 | ||
6fc6879b JM |
166 | static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s) |
167 | { | |
8bac466b | 168 | struct wpa_ssid *ssid, *old_ssid; |
eaa8eefe | 169 | u8 drv_ssid[SSID_MAX_LEN]; |
c41d0840 | 170 | size_t drv_ssid_len; |
00e5e3d5 | 171 | int res; |
6fc6879b | 172 | |
068e3877 JM |
173 | if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) { |
174 | wpa_supplicant_update_current_bss(wpa_s); | |
c41d0840 KV |
175 | |
176 | if (wpa_s->current_ssid->ssid_len == 0) | |
177 | return 0; /* current profile still in use */ | |
178 | res = wpa_drv_get_ssid(wpa_s, drv_ssid); | |
179 | if (res < 0) { | |
180 | wpa_msg(wpa_s, MSG_INFO, | |
181 | "Failed to read SSID from driver"); | |
182 | return 0; /* try to use current profile */ | |
183 | } | |
184 | drv_ssid_len = res; | |
185 | ||
186 | if (drv_ssid_len == wpa_s->current_ssid->ssid_len && | |
187 | os_memcmp(drv_ssid, wpa_s->current_ssid->ssid, | |
188 | drv_ssid_len) == 0) | |
189 | return 0; /* current profile still in use */ | |
190 | ||
191 | wpa_msg(wpa_s, MSG_DEBUG, | |
192 | "Driver-initiated BSS selection changed the SSID to %s", | |
193 | wpa_ssid_txt(drv_ssid, drv_ssid_len)); | |
194 | /* continue selecting a new network profile */ | |
068e3877 | 195 | } |
6fc6879b | 196 | |
f049052b BG |
197 | wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association " |
198 | "information"); | |
6fc6879b JM |
199 | ssid = wpa_supplicant_get_ssid(wpa_s); |
200 | if (ssid == NULL) { | |
f049052b BG |
201 | wpa_msg(wpa_s, MSG_INFO, |
202 | "No network configuration found for the current AP"); | |
6fc6879b JM |
203 | return -1; |
204 | } | |
205 | ||
349493bd | 206 | if (wpas_network_disabled(wpa_s, ssid)) { |
f049052b | 207 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled"); |
6fc6879b JM |
208 | return -1; |
209 | } | |
210 | ||
6407f413 JM |
211 | if (disallowed_bssid(wpa_s, wpa_s->bssid) || |
212 | disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) { | |
213 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed"); | |
214 | return -1; | |
215 | } | |
216 | ||
00e5e3d5 JM |
217 | res = wpas_temp_disabled(wpa_s, ssid); |
218 | if (res > 0) { | |
219 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily " | |
220 | "disabled for %d second(s)", res); | |
221 | return -1; | |
222 | } | |
223 | ||
f049052b BG |
224 | wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the " |
225 | "current AP"); | |
0bf927a0 | 226 | if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) { |
6fc6879b JM |
227 | u8 wpa_ie[80]; |
228 | size_t wpa_ie_len = sizeof(wpa_ie); | |
cbf61176 JM |
229 | if (wpa_supplicant_set_suites(wpa_s, NULL, ssid, |
230 | wpa_ie, &wpa_ie_len) < 0) | |
231 | wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites"); | |
6fc6879b JM |
232 | } else { |
233 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); | |
234 | } | |
235 | ||
236 | if (wpa_s->current_ssid && wpa_s->current_ssid != ssid) | |
237 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | |
8bac466b | 238 | old_ssid = wpa_s->current_ssid; |
6fc6879b | 239 | wpa_s->current_ssid = ssid; |
5cd47405 | 240 | |
068e3877 | 241 | wpa_supplicant_update_current_bss(wpa_s); |
5cd47405 | 242 | |
6fc6879b JM |
243 | wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid); |
244 | wpa_supplicant_initiate_eapol(wpa_s); | |
8bac466b JM |
245 | if (old_ssid != wpa_s->current_ssid) |
246 | wpas_notify_network_changed(wpa_s); | |
6fc6879b JM |
247 | |
248 | return 0; | |
249 | } | |
250 | ||
251 | ||
01a17491 | 252 | void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx) |
6fc6879b JM |
253 | { |
254 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
255 | ||
256 | if (wpa_s->countermeasures) { | |
257 | wpa_s->countermeasures = 0; | |
258 | wpa_drv_set_countermeasures(wpa_s, 0); | |
259 | wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped"); | |
f1609f11 IP |
260 | |
261 | /* | |
262 | * It is possible that the device is sched scanning, which means | |
263 | * that a connection attempt will be done only when we receive | |
264 | * scan results. However, in this case, it would be preferable | |
265 | * to scan and connect immediately, so cancel the sched_scan and | |
266 | * issue a regular scan flow. | |
267 | */ | |
268 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
6fc6879b JM |
269 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
270 | } | |
271 | } | |
272 | ||
273 | ||
274 | void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s) | |
275 | { | |
8bac466b JM |
276 | int bssid_changed; |
277 | ||
b6668734 JM |
278 | wnm_bss_keep_alive_deinit(wpa_s); |
279 | ||
78177a00 JM |
280 | #ifdef CONFIG_IBSS_RSN |
281 | ibss_rsn_deinit(wpa_s->ibss_rsn); | |
282 | wpa_s->ibss_rsn = NULL; | |
283 | #endif /* CONFIG_IBSS_RSN */ | |
284 | ||
ca62e114 JM |
285 | #ifdef CONFIG_AP |
286 | wpa_supplicant_ap_deinit(wpa_s); | |
287 | #endif /* CONFIG_AP */ | |
288 | ||
ece4ac5f MG |
289 | #ifdef CONFIG_HS20 |
290 | /* Clear possibly configured frame filters */ | |
291 | wpa_drv_configure_frame_filters(wpa_s, 0); | |
292 | #endif /* CONFIG_HS20 */ | |
293 | ||
8401a6b0 JM |
294 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
295 | return; | |
296 | ||
2bbad1c7 MW |
297 | if (os_reltime_initialized(&wpa_s->session_start)) { |
298 | os_reltime_age(&wpa_s->session_start, &wpa_s->session_length); | |
299 | wpa_s->session_start.sec = 0; | |
300 | wpa_s->session_start.usec = 0; | |
301 | wpas_notify_session_length(wpa_s); | |
302 | } | |
303 | ||
6fc6879b | 304 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
8bac466b | 305 | bssid_changed = !is_zero_ether_addr(wpa_s->bssid); |
6fc6879b JM |
306 | os_memset(wpa_s->bssid, 0, ETH_ALEN); |
307 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); | |
4e70bbf1 | 308 | sme_clear_on_disassoc(wpa_s); |
be8be671 | 309 | wpa_s->current_bss = NULL; |
3c85f144 | 310 | wpa_s->assoc_freq = 0; |
8fd0f0f3 | 311 | |
8bac466b JM |
312 | if (bssid_changed) |
313 | wpas_notify_bssid_changed(wpa_s); | |
314 | ||
6fc6879b JM |
315 | eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); |
316 | eapol_sm_notify_portValid(wpa_s->eapol, FALSE); | |
a1ea1b45 | 317 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || |
567da5bb | 318 | wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || |
b0b25c5b | 319 | wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || wpa_s->drv_authorized_port) |
6fc6879b | 320 | eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); |
b0b25c5b | 321 | wpa_s->drv_authorized_port = 0; |
6fc6879b | 322 | wpa_s->ap_ies_from_associnfo = 0; |
0d30cc24 | 323 | wpa_s->current_ssid = NULL; |
25a8f9e3 | 324 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
0d30cc24 | 325 | wpa_s->key_mgmt = 0; |
b361d580 AK |
326 | |
327 | wpas_rrm_reset(wpa_s); | |
03ed0a52 | 328 | wpa_s->wnmsleep_used = 0; |
d514b502 | 329 | wnm_clear_coloc_intf_reporting(wpa_s); |
2e06cef8 | 330 | wpa_s->disable_mbo_oce = 0; |
16579769 JM |
331 | |
332 | #ifdef CONFIG_TESTING_OPTIONS | |
333 | wpa_s->last_tk_alg = WPA_ALG_NONE; | |
334 | os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk)); | |
335 | #endif /* CONFIG_TESTING_OPTIONS */ | |
d7f038de | 336 | wpa_s->ieee80211ac = 0; |
5abc7823 VN |
337 | |
338 | if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0) | |
339 | wpa_s->enabled_4addr_mode = 0; | |
6fc6879b JM |
340 | } |
341 | ||
342 | ||
343 | static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s) | |
344 | { | |
345 | struct wpa_ie_data ie; | |
346 | int pmksa_set = -1; | |
347 | size_t i; | |
348 | ||
349 | if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 || | |
350 | ie.pmkid == NULL) | |
351 | return; | |
352 | ||
353 | for (i = 0; i < ie.num_pmkid; i++) { | |
354 | pmksa_set = pmksa_cache_set_current(wpa_s->wpa, | |
355 | ie.pmkid + i * PMKID_LEN, | |
852b2f27 | 356 | NULL, NULL, 0, NULL, 0); |
6fc6879b | 357 | if (pmksa_set == 0) { |
ba422613 | 358 | eapol_sm_notify_pmkid_attempt(wpa_s->eapol); |
6fc6879b JM |
359 | break; |
360 | } | |
361 | } | |
362 | ||
f049052b BG |
363 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from " |
364 | "PMKSA cache", pmksa_set == 0 ? "" : "not "); | |
6fc6879b JM |
365 | } |
366 | ||
367 | ||
368 | static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s, | |
369 | union wpa_event_data *data) | |
370 | { | |
371 | if (data == NULL) { | |
f049052b BG |
372 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate " |
373 | "event"); | |
6fc6879b JM |
374 | return; |
375 | } | |
f049052b BG |
376 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR |
377 | " index=%d preauth=%d", | |
378 | MAC2STR(data->pmkid_candidate.bssid), | |
379 | data->pmkid_candidate.index, | |
380 | data->pmkid_candidate.preauth); | |
6fc6879b JM |
381 | |
382 | pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid, | |
383 | data->pmkid_candidate.index, | |
384 | data->pmkid_candidate.preauth); | |
385 | } | |
386 | ||
387 | ||
388 | static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s) | |
389 | { | |
390 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || | |
391 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) | |
392 | return 0; | |
393 | ||
394 | #ifdef IEEE8021X_EAPOL | |
395 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA && | |
396 | wpa_s->current_ssid && | |
397 | !(wpa_s->current_ssid->eapol_flags & | |
398 | (EAPOL_FLAG_REQUIRE_KEY_UNICAST | | |
399 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) { | |
400 | /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either | |
401 | * plaintext or static WEP keys). */ | |
402 | return 0; | |
403 | } | |
404 | #endif /* IEEE8021X_EAPOL */ | |
405 | ||
406 | return 1; | |
407 | } | |
408 | ||
409 | ||
410 | /** | |
411 | * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC | |
412 | * @wpa_s: pointer to wpa_supplicant data | |
413 | * @ssid: Configuration data for the network | |
414 | * Returns: 0 on success, -1 on failure | |
415 | * | |
416 | * This function is called when starting authentication with a network that is | |
417 | * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA). | |
418 | */ | |
419 | int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s, | |
420 | struct wpa_ssid *ssid) | |
421 | { | |
422 | #ifdef IEEE8021X_EAPOL | |
b832d34c | 423 | #ifdef PCSC_FUNCS |
eb324600 | 424 | int aka = 0, sim = 0; |
6fc6879b | 425 | |
62f736dd JT |
426 | if ((ssid != NULL && ssid->eap.pcsc == NULL) || |
427 | wpa_s->scard != NULL || wpa_s->conf->external_sim) | |
6fc6879b JM |
428 | return 0; |
429 | ||
62f736dd | 430 | if (ssid == NULL || ssid->eap.eap_methods == NULL) { |
6fc6879b JM |
431 | sim = 1; |
432 | aka = 1; | |
433 | } else { | |
434 | struct eap_method_type *eap = ssid->eap.eap_methods; | |
435 | while (eap->vendor != EAP_VENDOR_IETF || | |
436 | eap->method != EAP_TYPE_NONE) { | |
437 | if (eap->vendor == EAP_VENDOR_IETF) { | |
438 | if (eap->method == EAP_TYPE_SIM) | |
439 | sim = 1; | |
3d332fe7 JM |
440 | else if (eap->method == EAP_TYPE_AKA || |
441 | eap->method == EAP_TYPE_AKA_PRIME) | |
6fc6879b JM |
442 | aka = 1; |
443 | } | |
444 | eap++; | |
445 | } | |
446 | } | |
447 | ||
448 | if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL) | |
449 | sim = 0; | |
3d332fe7 JM |
450 | if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL && |
451 | eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) == | |
452 | NULL) | |
6fc6879b JM |
453 | aka = 0; |
454 | ||
455 | if (!sim && !aka) { | |
f049052b BG |
456 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to " |
457 | "use SIM, but neither EAP-SIM nor EAP-AKA are " | |
458 | "enabled"); | |
6fc6879b JM |
459 | return 0; |
460 | } | |
461 | ||
f049052b BG |
462 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM " |
463 | "(sim=%d aka=%d) - initialize PCSC", sim, aka); | |
eb324600 | 464 | |
5a620604 | 465 | wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader); |
6fc6879b | 466 | if (wpa_s->scard == NULL) { |
f049052b BG |
467 | wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM " |
468 | "(pcsc-lite)"); | |
6fc6879b JM |
469 | return -1; |
470 | } | |
471 | wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard); | |
472 | eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard); | |
b832d34c | 473 | #endif /* PCSC_FUNCS */ |
6fc6879b JM |
474 | #endif /* IEEE8021X_EAPOL */ |
475 | ||
476 | return 0; | |
477 | } | |
478 | ||
479 | ||
480 | #ifndef CONFIG_NO_SCAN_PROCESSING | |
86bd1410 JM |
481 | |
482 | static int has_wep_key(struct wpa_ssid *ssid) | |
483 | { | |
484 | int i; | |
485 | ||
486 | for (i = 0; i < NUM_WEP_KEYS; i++) { | |
487 | if (ssid->wep_key_len[i]) | |
488 | return 1; | |
489 | } | |
490 | ||
491 | return 0; | |
492 | } | |
493 | ||
494 | ||
620c7837 | 495 | static int wpa_supplicant_match_privacy(struct wpa_bss *bss, |
6fc6879b JM |
496 | struct wpa_ssid *ssid) |
497 | { | |
86bd1410 | 498 | int privacy = 0; |
6fc6879b JM |
499 | |
500 | if (ssid->mixed_cell) | |
501 | return 1; | |
502 | ||
0632542b AT |
503 | #ifdef CONFIG_WPS |
504 | if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) | |
505 | return 1; | |
506 | #endif /* CONFIG_WPS */ | |
507 | ||
c1790a5f JM |
508 | #ifdef CONFIG_OWE |
509 | if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only) | |
510 | return 1; | |
511 | #endif /* CONFIG_OWE */ | |
512 | ||
86bd1410 JM |
513 | if (has_wep_key(ssid)) |
514 | privacy = 1; | |
515 | ||
6fc6879b JM |
516 | #ifdef IEEE8021X_EAPOL |
517 | if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && | |
518 | ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST | | |
519 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST)) | |
520 | privacy = 1; | |
521 | #endif /* IEEE8021X_EAPOL */ | |
522 | ||
29fbc522 JM |
523 | if (wpa_key_mgmt_wpa(ssid->key_mgmt)) |
524 | privacy = 1; | |
525 | ||
df0f01d9 JM |
526 | if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN) |
527 | privacy = 1; | |
528 | ||
6fc6879b JM |
529 | if (bss->caps & IEEE80211_CAP_PRIVACY) |
530 | return privacy; | |
531 | return !privacy; | |
532 | } | |
533 | ||
534 | ||
a6099152 JM |
535 | static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s, |
536 | struct wpa_ssid *ssid, | |
e65a87b3 | 537 | struct wpa_bss *bss, int debug_print) |
6fc6879b JM |
538 | { |
539 | struct wpa_ie_data ie; | |
540 | int proto_match = 0; | |
541 | const u8 *rsn_ie, *wpa_ie; | |
351f09a2 | 542 | int ret; |
43882f1e | 543 | int wep_ok; |
6fc6879b | 544 | |
a6099152 | 545 | ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss); |
351f09a2 JM |
546 | if (ret >= 0) |
547 | return ret; | |
ad08c363 | 548 | |
43882f1e JM |
549 | /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */ |
550 | wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) && | |
551 | (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) && | |
552 | ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) || | |
553 | (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)); | |
554 | ||
620c7837 | 555 | rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
f5a60216 | 556 | while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) { |
6fc6879b JM |
557 | proto_match++; |
558 | ||
559 | if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) { | |
e65a87b3 JM |
560 | if (debug_print) |
561 | wpa_dbg(wpa_s, MSG_DEBUG, | |
562 | " skip RSN IE - parse failed"); | |
6fc6879b JM |
563 | break; |
564 | } | |
2c129a1b LD |
565 | if (!ie.has_pairwise) |
566 | ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq); | |
567 | if (!ie.has_group) | |
568 | ie.group_cipher = wpa_default_rsn_cipher(bss->freq); | |
43882f1e JM |
569 | |
570 | if (wep_ok && | |
571 | (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104))) | |
572 | { | |
e65a87b3 JM |
573 | if (debug_print) |
574 | wpa_dbg(wpa_s, MSG_DEBUG, | |
575 | " selected based on TSN in RSN IE"); | |
43882f1e JM |
576 | return 1; |
577 | } | |
578 | ||
f5a60216 JM |
579 | if (!(ie.proto & ssid->proto) && |
580 | !(ssid->proto & WPA_PROTO_OSEN)) { | |
e65a87b3 JM |
581 | if (debug_print) |
582 | wpa_dbg(wpa_s, MSG_DEBUG, | |
583 | " skip RSN IE - proto mismatch"); | |
6fc6879b JM |
584 | break; |
585 | } | |
586 | ||
587 | if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { | |
e65a87b3 JM |
588 | if (debug_print) |
589 | wpa_dbg(wpa_s, MSG_DEBUG, | |
590 | " skip RSN IE - PTK cipher mismatch"); | |
6fc6879b JM |
591 | break; |
592 | } | |
593 | ||
594 | if (!(ie.group_cipher & ssid->group_cipher)) { | |
e65a87b3 JM |
595 | if (debug_print) |
596 | wpa_dbg(wpa_s, MSG_DEBUG, | |
597 | " skip RSN IE - GTK cipher mismatch"); | |
6fc6879b JM |
598 | break; |
599 | } | |
600 | ||
61a56c14 JM |
601 | if (ssid->group_mgmt_cipher && |
602 | !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) { | |
603 | if (debug_print) | |
604 | wpa_dbg(wpa_s, MSG_DEBUG, | |
605 | " skip RSN IE - group mgmt cipher mismatch"); | |
606 | break; | |
607 | } | |
608 | ||
6fc6879b | 609 | if (!(ie.key_mgmt & ssid->key_mgmt)) { |
e65a87b3 JM |
610 | if (debug_print) |
611 | wpa_dbg(wpa_s, MSG_DEBUG, | |
612 | " skip RSN IE - key mgmt mismatch"); | |
6fc6879b JM |
613 | break; |
614 | } | |
615 | ||
0b60b0aa | 616 | if (!(ie.capabilities & WPA_CAPABILITY_MFPC) && |
3f56a2b7 | 617 | wpas_get_ssid_pmf(wpa_s, ssid) == |
62d49803 | 618 | MGMT_FRAME_PROTECTION_REQUIRED) { |
e65a87b3 JM |
619 | if (debug_print) |
620 | wpa_dbg(wpa_s, MSG_DEBUG, | |
621 | " skip RSN IE - no mgmt frame protection"); | |
6fc6879b JM |
622 | break; |
623 | } | |
fa464267 JM |
624 | if ((ie.capabilities & WPA_CAPABILITY_MFPR) && |
625 | wpas_get_ssid_pmf(wpa_s, ssid) == | |
626 | NO_MGMT_FRAME_PROTECTION) { | |
e65a87b3 JM |
627 | if (debug_print) |
628 | wpa_dbg(wpa_s, MSG_DEBUG, | |
629 | " skip RSN IE - no mgmt frame protection enabled but AP requires it"); | |
fa464267 JM |
630 | break; |
631 | } | |
6fc6879b | 632 | |
e65a87b3 JM |
633 | if (debug_print) |
634 | wpa_dbg(wpa_s, MSG_DEBUG, | |
635 | " selected based on RSN IE"); | |
6fc6879b JM |
636 | return 1; |
637 | } | |
638 | ||
c1790a5f JM |
639 | if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED && |
640 | (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) { | |
e65a87b3 JM |
641 | if (debug_print) |
642 | wpa_dbg(wpa_s, MSG_DEBUG, | |
643 | " skip - MFP Required but network not MFP Capable"); | |
03626e91 SD |
644 | return 0; |
645 | } | |
03626e91 | 646 | |
620c7837 | 647 | wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
6fc6879b JM |
648 | while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) { |
649 | proto_match++; | |
650 | ||
651 | if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) { | |
e65a87b3 JM |
652 | if (debug_print) |
653 | wpa_dbg(wpa_s, MSG_DEBUG, | |
654 | " skip WPA IE - parse failed"); | |
6fc6879b JM |
655 | break; |
656 | } | |
43882f1e JM |
657 | |
658 | if (wep_ok && | |
659 | (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104))) | |
660 | { | |
e65a87b3 JM |
661 | if (debug_print) |
662 | wpa_dbg(wpa_s, MSG_DEBUG, | |
663 | " selected based on TSN in WPA IE"); | |
43882f1e JM |
664 | return 1; |
665 | } | |
666 | ||
6fc6879b | 667 | if (!(ie.proto & ssid->proto)) { |
e65a87b3 JM |
668 | if (debug_print) |
669 | wpa_dbg(wpa_s, MSG_DEBUG, | |
670 | " skip WPA IE - proto mismatch"); | |
6fc6879b JM |
671 | break; |
672 | } | |
673 | ||
674 | if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { | |
e65a87b3 JM |
675 | if (debug_print) |
676 | wpa_dbg(wpa_s, MSG_DEBUG, | |
677 | " skip WPA IE - PTK cipher mismatch"); | |
6fc6879b JM |
678 | break; |
679 | } | |
680 | ||
681 | if (!(ie.group_cipher & ssid->group_cipher)) { | |
e65a87b3 JM |
682 | if (debug_print) |
683 | wpa_dbg(wpa_s, MSG_DEBUG, | |
684 | " skip WPA IE - GTK cipher mismatch"); | |
6fc6879b JM |
685 | break; |
686 | } | |
687 | ||
688 | if (!(ie.key_mgmt & ssid->key_mgmt)) { | |
e65a87b3 JM |
689 | if (debug_print) |
690 | wpa_dbg(wpa_s, MSG_DEBUG, | |
691 | " skip WPA IE - key mgmt mismatch"); | |
6fc6879b JM |
692 | break; |
693 | } | |
694 | ||
e65a87b3 JM |
695 | if (debug_print) |
696 | wpa_dbg(wpa_s, MSG_DEBUG, | |
697 | " selected based on WPA IE"); | |
6fc6879b JM |
698 | return 1; |
699 | } | |
700 | ||
a3f7e518 JM |
701 | if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie && |
702 | !rsn_ie) { | |
e65a87b3 JM |
703 | if (debug_print) |
704 | wpa_dbg(wpa_s, MSG_DEBUG, | |
705 | " allow for non-WPA IEEE 802.1X"); | |
a3f7e518 JM |
706 | return 1; |
707 | } | |
708 | ||
c1790a5f JM |
709 | #ifdef CONFIG_OWE |
710 | if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only && | |
711 | !wpa_ie && !rsn_ie) { | |
91073cca SD |
712 | if (wpa_s->owe_transition_select && |
713 | wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) && | |
714 | ssid->owe_transition_bss_select_count + 1 <= | |
715 | MAX_OWE_TRANSITION_BSS_SELECT_COUNT) { | |
716 | ssid->owe_transition_bss_select_count++; | |
717 | if (debug_print) | |
718 | wpa_dbg(wpa_s, MSG_DEBUG, | |
719 | " skip OWE transition BSS (selection count %d does not exceed %d)", | |
720 | ssid->owe_transition_bss_select_count, | |
721 | MAX_OWE_TRANSITION_BSS_SELECT_COUNT); | |
a5e6270f | 722 | wpa_s->owe_transition_search = 1; |
91073cca SD |
723 | return 0; |
724 | } | |
c1790a5f JM |
725 | if (debug_print) |
726 | wpa_dbg(wpa_s, MSG_DEBUG, | |
727 | " allow in OWE transition mode"); | |
728 | return 1; | |
729 | } | |
730 | #endif /* CONFIG_OWE */ | |
731 | ||
cc5e390d | 732 | if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) && |
df83fb7d | 733 | wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) { |
e65a87b3 JM |
734 | if (debug_print) |
735 | wpa_dbg(wpa_s, MSG_DEBUG, | |
736 | " skip - no WPA/RSN proto match"); | |
cc5e390d JM |
737 | return 0; |
738 | } | |
6fc6879b | 739 | |
df0f01d9 JM |
740 | if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && |
741 | wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) { | |
e65a87b3 JM |
742 | if (debug_print) |
743 | wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN"); | |
df0f01d9 JM |
744 | return 1; |
745 | } | |
746 | ||
c2f1fe41 | 747 | if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) { |
e65a87b3 JM |
748 | if (debug_print) |
749 | wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2"); | |
c2f1fe41 JM |
750 | return 1; |
751 | } | |
752 | ||
e65a87b3 JM |
753 | if (debug_print) |
754 | wpa_dbg(wpa_s, MSG_DEBUG, | |
755 | " reject due to mismatch with WPA/WPA2"); | |
c2f1fe41 JM |
756 | |
757 | return 0; | |
6fc6879b JM |
758 | } |
759 | ||
760 | ||
b766a9a2 JM |
761 | static int freq_allowed(int *freqs, int freq) |
762 | { | |
763 | int i; | |
764 | ||
765 | if (freqs == NULL) | |
766 | return 1; | |
767 | ||
768 | for (i = 0; freqs[i]; i++) | |
769 | if (freqs[i] == freq) | |
770 | return 1; | |
771 | return 0; | |
772 | } | |
773 | ||
774 | ||
e65a87b3 JM |
775 | static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
776 | int debug_print) | |
e1e8cae3 CL |
777 | { |
778 | const struct hostapd_hw_modes *mode = NULL, *modes; | |
779 | const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES }; | |
780 | const u8 *rate_ie; | |
781 | int i, j, k; | |
782 | ||
a6d94e1b JM |
783 | if (bss->freq == 0) |
784 | return 1; /* Cannot do matching without knowing band */ | |
785 | ||
e1e8cae3 CL |
786 | modes = wpa_s->hw.modes; |
787 | if (modes == NULL) { | |
788 | /* | |
789 | * The driver does not provide any additional information | |
790 | * about the utilized hardware, so allow the connection attempt | |
791 | * to continue. | |
792 | */ | |
793 | return 1; | |
794 | } | |
795 | ||
796 | for (i = 0; i < wpa_s->hw.num_modes; i++) { | |
797 | for (j = 0; j < modes[i].num_channels; j++) { | |
798 | int freq = modes[i].channels[j].freq; | |
799 | if (freq == bss->freq) { | |
800 | if (mode && | |
801 | mode->mode == HOSTAPD_MODE_IEEE80211G) | |
802 | break; /* do not allow 802.11b replace | |
803 | * 802.11g */ | |
804 | mode = &modes[i]; | |
805 | break; | |
806 | } | |
807 | } | |
808 | } | |
809 | ||
810 | if (mode == NULL) | |
811 | return 0; | |
812 | ||
813 | for (i = 0; i < (int) sizeof(scan_ie); i++) { | |
620c7837 | 814 | rate_ie = wpa_bss_get_ie(bss, scan_ie[i]); |
e1e8cae3 CL |
815 | if (rate_ie == NULL) |
816 | continue; | |
817 | ||
818 | for (j = 2; j < rate_ie[1] + 2; j++) { | |
819 | int flagged = !!(rate_ie[j] & 0x80); | |
820 | int r = (rate_ie[j] & 0x7f) * 5; | |
821 | ||
822 | /* | |
823 | * IEEE Std 802.11n-2009 7.3.2.2: | |
824 | * The new BSS Membership selector value is encoded | |
825 | * like a legacy basic rate, but it is not a rate and | |
826 | * only indicates if the BSS members are required to | |
827 | * support the mandatory features of Clause 20 [HT PHY] | |
828 | * in order to join the BSS. | |
829 | */ | |
830 | if (flagged && ((rate_ie[j] & 0x7f) == | |
831 | BSS_MEMBERSHIP_SELECTOR_HT_PHY)) { | |
832 | if (!ht_supported(mode)) { | |
e65a87b3 JM |
833 | if (debug_print) |
834 | wpa_dbg(wpa_s, MSG_DEBUG, | |
835 | " hardware does not support HT PHY"); | |
e1e8cae3 CL |
836 | return 0; |
837 | } | |
838 | continue; | |
839 | } | |
840 | ||
c8ebeda4 MK |
841 | /* There's also a VHT selector for 802.11ac */ |
842 | if (flagged && ((rate_ie[j] & 0x7f) == | |
843 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) { | |
844 | if (!vht_supported(mode)) { | |
e65a87b3 JM |
845 | if (debug_print) |
846 | wpa_dbg(wpa_s, MSG_DEBUG, | |
847 | " hardware does not support VHT PHY"); | |
c8ebeda4 MK |
848 | return 0; |
849 | } | |
850 | continue; | |
851 | } | |
852 | ||
e1e8cae3 CL |
853 | if (!flagged) |
854 | continue; | |
855 | ||
856 | /* check for legacy basic rates */ | |
857 | for (k = 0; k < mode->num_rates; k++) { | |
858 | if (mode->rates[k] == r) | |
859 | break; | |
860 | } | |
861 | if (k == mode->num_rates) { | |
862 | /* | |
863 | * IEEE Std 802.11-2007 7.3.2.2 demands that in | |
864 | * order to join a BSS all required rates | |
865 | * have to be supported by the hardware. | |
866 | */ | |
e65a87b3 JM |
867 | if (debug_print) |
868 | wpa_dbg(wpa_s, MSG_DEBUG, | |
869 | " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)", | |
870 | r / 10, r % 10, | |
871 | bss->freq, mode->mode, mode->num_rates); | |
e1e8cae3 CL |
872 | return 0; |
873 | } | |
874 | } | |
875 | } | |
876 | ||
877 | return 1; | |
878 | } | |
879 | ||
880 | ||
ff3ad3c5 VK |
881 | /* |
882 | * Test whether BSS is in an ESS. | |
883 | * This is done differently in DMG (60 GHz) and non-DMG bands | |
884 | */ | |
885 | static int bss_is_ess(struct wpa_bss *bss) | |
886 | { | |
887 | if (bss_is_dmg(bss)) { | |
888 | return (bss->caps & IEEE80211_CAP_DMG_MASK) == | |
889 | IEEE80211_CAP_DMG_AP; | |
890 | } | |
891 | ||
892 | return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) == | |
893 | IEEE80211_CAP_ESS); | |
894 | } | |
895 | ||
896 | ||
79cd993a ST |
897 | static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask) |
898 | { | |
899 | size_t i; | |
900 | ||
901 | for (i = 0; i < ETH_ALEN; i++) { | |
902 | if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i])) | |
903 | return 0; | |
904 | } | |
905 | return 1; | |
906 | } | |
907 | ||
908 | ||
b83e4554 ST |
909 | static int addr_in_list(const u8 *addr, const u8 *list, size_t num) |
910 | { | |
911 | size_t i; | |
912 | ||
913 | for (i = 0; i < num; i++) { | |
79cd993a ST |
914 | const u8 *a = list + i * ETH_ALEN * 2; |
915 | const u8 *m = a + ETH_ALEN; | |
b83e4554 | 916 | |
79cd993a | 917 | if (match_mac_mask(a, addr, m)) |
b83e4554 ST |
918 | return 1; |
919 | } | |
920 | return 0; | |
921 | } | |
922 | ||
923 | ||
e8b96490 JM |
924 | static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
925 | const u8 **ret_ssid, size_t *ret_ssid_len) | |
926 | { | |
927 | #ifdef CONFIG_OWE | |
928 | const u8 *owe, *pos, *end, *bssid; | |
929 | u8 ssid_len; | |
930 | struct wpa_bss *open_bss; | |
931 | ||
932 | owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE); | |
933 | if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN)) | |
934 | return; | |
935 | ||
936 | pos = owe + 6; | |
937 | end = owe + 2 + owe[1]; | |
938 | ||
939 | if (end - pos < ETH_ALEN + 1) | |
940 | return; | |
941 | bssid = pos; | |
942 | pos += ETH_ALEN; | |
943 | ssid_len = *pos++; | |
944 | if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN) | |
945 | return; | |
946 | ||
947 | /* Match the profile SSID against the OWE transition mode SSID on the | |
948 | * open network. */ | |
949 | wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR | |
950 | " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len)); | |
951 | *ret_ssid = pos; | |
952 | *ret_ssid_len = ssid_len; | |
953 | ||
954 | if (bss->ssid_len > 0) | |
955 | return; | |
956 | ||
957 | open_bss = wpa_bss_get_bssid_latest(wpa_s, bssid); | |
958 | if (!open_bss) | |
959 | return; | |
960 | if (ssid_len != open_bss->ssid_len || | |
961 | os_memcmp(pos, open_bss->ssid, ssid_len) != 0) { | |
962 | wpa_dbg(wpa_s, MSG_DEBUG, | |
963 | "OWE: transition mode SSID mismatch: %s", | |
964 | wpa_ssid_txt(open_bss->ssid, open_bss->ssid_len)); | |
965 | return; | |
966 | } | |
967 | ||
968 | owe = wpa_bss_get_vendor_ie(open_bss, OWE_IE_VENDOR_TYPE); | |
969 | if (!owe || wpa_bss_get_ie(open_bss, WLAN_EID_RSN)) { | |
970 | wpa_dbg(wpa_s, MSG_DEBUG, | |
971 | "OWE: transition mode open BSS unexpected info"); | |
972 | return; | |
973 | } | |
974 | ||
975 | pos = owe + 6; | |
976 | end = owe + 2 + owe[1]; | |
977 | ||
978 | if (end - pos < ETH_ALEN + 1) | |
979 | return; | |
980 | if (os_memcmp(pos, bss->bssid, ETH_ALEN) != 0) { | |
981 | wpa_dbg(wpa_s, MSG_DEBUG, | |
982 | "OWE: transition mode BSSID mismatch: " MACSTR, | |
983 | MAC2STR(pos)); | |
984 | return; | |
985 | } | |
986 | pos += ETH_ALEN; | |
987 | ssid_len = *pos++; | |
988 | if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN) | |
989 | return; | |
990 | wpa_dbg(wpa_s, MSG_DEBUG, "OWE: learned transition mode OWE SSID: %s", | |
991 | wpa_ssid_txt(pos, ssid_len)); | |
992 | os_memcpy(bss->ssid, pos, ssid_len); | |
993 | bss->ssid_len = ssid_len; | |
994 | #endif /* CONFIG_OWE */ | |
995 | } | |
996 | ||
997 | ||
84d1c0fd AS |
998 | struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s, |
999 | int i, struct wpa_bss *bss, | |
1000 | struct wpa_ssid *group, | |
e65a87b3 | 1001 | int only_first_ssid, int debug_print) |
6fc6879b | 1002 | { |
620c7837 | 1003 | u8 wpa_ie_len, rsn_ie_len; |
d8d940b7 | 1004 | int wpa; |
6fc6879b JM |
1005 | struct wpa_blacklist *e; |
1006 | const u8 *ie; | |
d8d940b7 | 1007 | struct wpa_ssid *ssid; |
f5a60216 | 1008 | int osen, rsn_osen = 0; |
cb06cf34 DS |
1009 | #ifdef CONFIG_MBO |
1010 | const u8 *assoc_disallow; | |
1011 | #endif /* CONFIG_MBO */ | |
e8b96490 JM |
1012 | const u8 *match_ssid; |
1013 | size_t match_ssid_len; | |
f5a60216 | 1014 | struct wpa_ie_data data; |
6fc6879b | 1015 | |
620c7837 | 1016 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
d8d940b7 | 1017 | wpa_ie_len = ie ? ie[1] : 0; |
6fc6879b | 1018 | |
620c7837 | 1019 | ie = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
d8d940b7 | 1020 | rsn_ie_len = ie ? ie[1] : 0; |
f5a60216 JM |
1021 | if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 && |
1022 | (data.key_mgmt & WPA_KEY_MGMT_OSEN)) | |
1023 | rsn_osen = 1; | |
6fc6879b | 1024 | |
df0f01d9 JM |
1025 | ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); |
1026 | osen = ie != NULL; | |
1027 | ||
e65a87b3 JM |
1028 | if (debug_print) { |
1029 | wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR | |
1030 | " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s", | |
1031 | i, MAC2STR(bss->bssid), | |
1032 | wpa_ssid_txt(bss->ssid, bss->ssid_len), | |
1033 | wpa_ie_len, rsn_ie_len, bss->caps, bss->level, | |
1034 | bss->freq, | |
1035 | wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? | |
1036 | " wps" : "", | |
1037 | (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) || | |
1038 | wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) | |
1039 | ? " p2p" : "", | |
1040 | osen ? " osen=1" : ""); | |
1041 | } | |
9cf32261 | 1042 | |
d8d940b7 | 1043 | e = wpa_blacklist_get(wpa_s, bss->bssid); |
5471c343 JM |
1044 | if (e) { |
1045 | int limit = 1; | |
349493bd | 1046 | if (wpa_supplicant_enabled_networks(wpa_s) == 1) { |
5471c343 JM |
1047 | /* |
1048 | * When only a single network is enabled, we can | |
1049 | * trigger blacklisting on the first failure. This | |
1050 | * should not be done with multiple enabled networks to | |
1051 | * avoid getting forced to move into a worse ESS on | |
1052 | * single error if there are no other BSSes of the | |
1053 | * current ESS. | |
1054 | */ | |
1055 | limit = 0; | |
1056 | } | |
1057 | if (e->count > limit) { | |
e65a87b3 JM |
1058 | if (debug_print) { |
1059 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1060 | " skip - blacklisted (count=%d limit=%d)", | |
1061 | e->count, limit); | |
1062 | } | |
c2197bc9 | 1063 | return NULL; |
5471c343 | 1064 | } |
d8d940b7 | 1065 | } |
6fc6879b | 1066 | |
e8b96490 JM |
1067 | match_ssid = bss->ssid; |
1068 | match_ssid_len = bss->ssid_len; | |
1069 | owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len); | |
1070 | ||
1071 | if (match_ssid_len == 0) { | |
e65a87b3 JM |
1072 | if (debug_print) |
1073 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known"); | |
c2197bc9 | 1074 | return NULL; |
d8d940b7 | 1075 | } |
e81634cd | 1076 | |
6407f413 | 1077 | if (disallowed_bssid(wpa_s, bss->bssid)) { |
e65a87b3 JM |
1078 | if (debug_print) |
1079 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed"); | |
6407f413 JM |
1080 | return NULL; |
1081 | } | |
1082 | ||
e8b96490 | 1083 | if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) { |
e65a87b3 JM |
1084 | if (debug_print) |
1085 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed"); | |
6407f413 JM |
1086 | return NULL; |
1087 | } | |
1088 | ||
d8d940b7 | 1089 | wpa = wpa_ie_len > 0 || rsn_ie_len > 0; |
6fc6879b | 1090 | |
3d910ef4 | 1091 | for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) { |
d8d940b7 | 1092 | int check_ssid = wpa ? 1 : (ssid->ssid_len != 0); |
00e5e3d5 | 1093 | int res; |
ad08c363 | 1094 | |
349493bd | 1095 | if (wpas_network_disabled(wpa_s, ssid)) { |
e65a87b3 JM |
1096 | if (debug_print) |
1097 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled"); | |
0c703df3 | 1098 | continue; |
d8d940b7 | 1099 | } |
9cf32261 | 1100 | |
00e5e3d5 JM |
1101 | res = wpas_temp_disabled(wpa_s, ssid); |
1102 | if (res > 0) { | |
e65a87b3 JM |
1103 | if (debug_print) |
1104 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1105 | " skip - disabled temporarily for %d second(s)", | |
1106 | res); | |
00e5e3d5 JM |
1107 | continue; |
1108 | } | |
1109 | ||
ad08c363 | 1110 | #ifdef CONFIG_WPS |
f648bc7d | 1111 | if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) { |
e65a87b3 JM |
1112 | if (debug_print) |
1113 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1114 | " skip - blacklisted (WPS)"); | |
f648bc7d JM |
1115 | continue; |
1116 | } | |
1117 | ||
d8d940b7 JM |
1118 | if (wpa && ssid->ssid_len == 0 && |
1119 | wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss)) | |
1120 | check_ssid = 0; | |
1121 | ||
1122 | if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) { | |
1123 | /* Only allow wildcard SSID match if an AP | |
1124 | * advertises active WPS operation that matches | |
1125 | * with our mode. */ | |
1126 | check_ssid = 1; | |
ad08c363 | 1127 | if (ssid->ssid_len == 0 && |
a6099152 | 1128 | wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss)) |
ad08c363 | 1129 | check_ssid = 0; |
d8d940b7 | 1130 | } |
ad08c363 JM |
1131 | #endif /* CONFIG_WPS */ |
1132 | ||
7d232e23 ZC |
1133 | if (ssid->bssid_set && ssid->ssid_len == 0 && |
1134 | os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0) | |
1135 | check_ssid = 0; | |
1136 | ||
d8d940b7 | 1137 | if (check_ssid && |
e8b96490 JM |
1138 | (match_ssid_len != ssid->ssid_len || |
1139 | os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) { | |
e65a87b3 JM |
1140 | if (debug_print) |
1141 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1142 | " skip - SSID mismatch"); | |
0c703df3 | 1143 | continue; |
6fc6879b | 1144 | } |
6fc6879b | 1145 | |
d8d940b7 JM |
1146 | if (ssid->bssid_set && |
1147 | os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) { | |
e65a87b3 JM |
1148 | if (debug_print) |
1149 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1150 | " skip - BSSID mismatch"); | |
0c703df3 | 1151 | continue; |
d8d940b7 | 1152 | } |
6fc6879b | 1153 | |
b83e4554 ST |
1154 | /* check blacklist */ |
1155 | if (ssid->num_bssid_blacklist && | |
1156 | addr_in_list(bss->bssid, ssid->bssid_blacklist, | |
1157 | ssid->num_bssid_blacklist)) { | |
e65a87b3 JM |
1158 | if (debug_print) |
1159 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1160 | " skip - BSSID blacklisted"); | |
b83e4554 ST |
1161 | continue; |
1162 | } | |
1163 | ||
1164 | /* if there is a whitelist, only accept those APs */ | |
1165 | if (ssid->num_bssid_whitelist && | |
1166 | !addr_in_list(bss->bssid, ssid->bssid_whitelist, | |
1167 | ssid->num_bssid_whitelist)) { | |
e65a87b3 JM |
1168 | if (debug_print) |
1169 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1170 | " skip - BSSID not in whitelist"); | |
b83e4554 ST |
1171 | continue; |
1172 | } | |
1173 | ||
e65a87b3 JM |
1174 | if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss, |
1175 | debug_print)) | |
0c703df3 | 1176 | continue; |
9cf32261 | 1177 | |
df0f01d9 | 1178 | if (!osen && !wpa && |
d8d940b7 JM |
1179 | !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) && |
1180 | !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) && | |
c1790a5f | 1181 | !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) && |
d8d940b7 | 1182 | !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) { |
e65a87b3 JM |
1183 | if (debug_print) |
1184 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1185 | " skip - non-WPA network not allowed"); | |
0c703df3 | 1186 | continue; |
6fc6879b | 1187 | } |
9cf32261 | 1188 | |
86bd1410 JM |
1189 | if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && |
1190 | has_wep_key(ssid)) { | |
e65a87b3 JM |
1191 | if (debug_print) |
1192 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1193 | " skip - ignore WPA/WPA2 AP for WEP network block"); | |
86bd1410 JM |
1194 | continue; |
1195 | } | |
1196 | ||
f5a60216 JM |
1197 | if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen && |
1198 | !rsn_osen) { | |
e65a87b3 JM |
1199 | if (debug_print) |
1200 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1201 | " skip - non-OSEN network not allowed"); | |
df0f01d9 JM |
1202 | continue; |
1203 | } | |
1204 | ||
29fbc522 | 1205 | if (!wpa_supplicant_match_privacy(bss, ssid)) { |
e65a87b3 JM |
1206 | if (debug_print) |
1207 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1208 | " skip - privacy mismatch"); | |
0c703df3 | 1209 | continue; |
e81634cd JM |
1210 | } |
1211 | ||
f74618cb | 1212 | if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) && |
70351623 | 1213 | !bss_is_pbss(bss)) { |
e65a87b3 JM |
1214 | if (debug_print) |
1215 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1216 | " skip - not ESS, PBSS, or MBSS"); | |
b9074912 LD |
1217 | continue; |
1218 | } | |
1219 | ||
90f14962 | 1220 | if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) { |
e65a87b3 JM |
1221 | if (debug_print) |
1222 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1223 | " skip - PBSS mismatch (ssid %d bss %d)", | |
1224 | ssid->pbss, bss_is_pbss(bss)); | |
0c703df3 | 1225 | continue; |
d8d940b7 | 1226 | } |
b766a9a2 | 1227 | |
d8d940b7 | 1228 | if (!freq_allowed(ssid->freq_list, bss->freq)) { |
e65a87b3 JM |
1229 | if (debug_print) |
1230 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1231 | " skip - frequency not allowed"); | |
0c703df3 | 1232 | continue; |
6fc6879b | 1233 | } |
d8d940b7 | 1234 | |
fac72f93 | 1235 | #ifdef CONFIG_MESH |
f74618cb | 1236 | if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 && |
fac72f93 | 1237 | ssid->frequency != bss->freq) { |
e65a87b3 JM |
1238 | if (debug_print) |
1239 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1240 | " skip - frequency not allowed (mesh)"); | |
fac72f93 MH |
1241 | continue; |
1242 | } | |
1243 | #endif /* CONFIG_MESH */ | |
1244 | ||
e65a87b3 JM |
1245 | if (!rate_match(wpa_s, bss, debug_print)) { |
1246 | if (debug_print) | |
1247 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1248 | " skip - rate sets do not match"); | |
e1e8cae3 CL |
1249 | continue; |
1250 | } | |
1251 | ||
81a10a94 JM |
1252 | #ifndef CONFIG_IBSS_RSN |
1253 | if (ssid->mode == WPAS_MODE_IBSS && | |
1254 | !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | | |
1255 | WPA_KEY_MGMT_WPA_NONE))) { | |
e65a87b3 JM |
1256 | if (debug_print) |
1257 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1258 | " skip - IBSS RSN not supported in the build"); | |
81a10a94 JM |
1259 | continue; |
1260 | } | |
1261 | #endif /* !CONFIG_IBSS_RSN */ | |
1262 | ||
73e49269 | 1263 | #ifdef CONFIG_P2P |
b72e14e5 JM |
1264 | if (ssid->p2p_group && |
1265 | !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) && | |
1266 | !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) { | |
e65a87b3 JM |
1267 | if (debug_print) |
1268 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1269 | " skip - no P2P IE seen"); | |
b72e14e5 JM |
1270 | continue; |
1271 | } | |
1272 | ||
9ec87666 JM |
1273 | if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) { |
1274 | struct wpabuf *p2p_ie; | |
1275 | u8 dev_addr[ETH_ALEN]; | |
1276 | ||
1277 | ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE); | |
1278 | if (ie == NULL) { | |
e65a87b3 JM |
1279 | if (debug_print) |
1280 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1281 | " skip - no P2P element"); | |
9ec87666 JM |
1282 | continue; |
1283 | } | |
1284 | p2p_ie = wpa_bss_get_vendor_ie_multi( | |
1285 | bss, P2P_IE_VENDOR_TYPE); | |
1286 | if (p2p_ie == NULL) { | |
e65a87b3 JM |
1287 | if (debug_print) |
1288 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1289 | " skip - could not fetch P2P element"); | |
9ec87666 JM |
1290 | continue; |
1291 | } | |
1292 | ||
1293 | if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 | |
1294 | || os_memcmp(dev_addr, ssid->go_p2p_dev_addr, | |
1295 | ETH_ALEN) != 0) { | |
e65a87b3 JM |
1296 | if (debug_print) |
1297 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1298 | " skip - no matching GO P2P Device Address in P2P element"); | |
9ec87666 JM |
1299 | wpabuf_free(p2p_ie); |
1300 | continue; | |
1301 | } | |
1302 | wpabuf_free(p2p_ie); | |
1303 | } | |
1304 | ||
73e49269 JM |
1305 | /* |
1306 | * TODO: skip the AP if its P2P IE has Group Formation | |
1307 | * bit set in the P2P Group Capability Bitmap and we | |
1308 | * are not in Group Formation with that device. | |
1309 | */ | |
1310 | #endif /* CONFIG_P2P */ | |
1311 | ||
dfaf11d6 JM |
1312 | if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) |
1313 | { | |
1314 | struct os_reltime diff; | |
1315 | ||
1316 | os_reltime_sub(&wpa_s->scan_min_time, | |
1317 | &bss->last_update, &diff); | |
e65a87b3 JM |
1318 | if (debug_print) |
1319 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1320 | " skip - scan result not recent enough (%u.%06u seconds too old)", | |
dfaf11d6 JM |
1321 | (unsigned int) diff.sec, |
1322 | (unsigned int) diff.usec); | |
1323 | continue; | |
1324 | } | |
cb06cf34 | 1325 | #ifdef CONFIG_MBO |
6ad37d73 | 1326 | #ifdef CONFIG_TESTING_OPTIONS |
1327 | if (wpa_s->ignore_assoc_disallow) | |
1328 | goto skip_assoc_disallow; | |
1329 | #endif /* CONFIG_TESTING_OPTIONS */ | |
cb06cf34 DS |
1330 | assoc_disallow = wpas_mbo_get_bss_attr( |
1331 | bss, MBO_ATTR_ID_ASSOC_DISALLOW); | |
1332 | if (assoc_disallow && assoc_disallow[1] >= 1) { | |
e65a87b3 JM |
1333 | if (debug_print) |
1334 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1335 | " skip - MBO association disallowed (reason %u)", | |
cb06cf34 DS |
1336 | assoc_disallow[2]); |
1337 | continue; | |
1338 | } | |
dd599908 | 1339 | |
19677b77 | 1340 | if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) { |
e65a87b3 JM |
1341 | if (debug_print) |
1342 | wpa_dbg(wpa_s, MSG_DEBUG, | |
19677b77 | 1343 | " skip - AP temporarily disallowed"); |
dd599908 AS |
1344 | continue; |
1345 | } | |
6ad37d73 | 1346 | #ifdef CONFIG_TESTING_OPTIONS |
1347 | skip_assoc_disallow: | |
1348 | #endif /* CONFIG_TESTING_OPTIONS */ | |
cb06cf34 | 1349 | #endif /* CONFIG_MBO */ |
dfaf11d6 | 1350 | |
567da5bb JM |
1351 | #ifdef CONFIG_DPP |
1352 | if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) && | |
a0d5c56f JM |
1353 | !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, ssid) && |
1354 | (!ssid->dpp_connector || | |
1355 | !ssid->dpp_netaccesskey || | |
1356 | !ssid->dpp_csign)) { | |
567da5bb JM |
1357 | if (debug_print) |
1358 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1359 | " skip - no PMKSA entry for DPP"); | |
1360 | continue; | |
1361 | } | |
1362 | #endif /* CONFIG_DPP */ | |
1363 | ||
d8d940b7 JM |
1364 | /* Matching configuration found */ |
1365 | return ssid; | |
6fc6879b JM |
1366 | } |
1367 | ||
d8d940b7 | 1368 | /* No matching configuration found */ |
c2197bc9 | 1369 | return NULL; |
9cf32261 JM |
1370 | } |
1371 | ||
1372 | ||
6fa81a3b | 1373 | static struct wpa_bss * |
a1fd2ce5 | 1374 | wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s, |
a1fd2ce5 | 1375 | struct wpa_ssid *group, |
3d910ef4 JM |
1376 | struct wpa_ssid **selected_ssid, |
1377 | int only_first_ssid) | |
9cf32261 | 1378 | { |
620c7837 | 1379 | unsigned int i; |
9cf32261 | 1380 | |
e65a87b3 JM |
1381 | if (wpa_s->current_ssid) { |
1382 | struct wpa_ssid *ssid; | |
1383 | ||
1384 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1385 | "Scan results matching the currently selected network"); | |
1386 | for (i = 0; i < wpa_s->last_scan_res_used; i++) { | |
1387 | struct wpa_bss *bss = wpa_s->last_scan_res[i]; | |
1388 | ||
1389 | ssid = wpa_scan_res_match(wpa_s, i, bss, group, | |
1390 | only_first_ssid, 0); | |
1391 | if (ssid != wpa_s->current_ssid) | |
1392 | continue; | |
1393 | wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR | |
1394 | " freq=%d level=%d snr=%d est_throughput=%u", | |
1395 | i, MAC2STR(bss->bssid), bss->freq, bss->level, | |
1396 | bss->snr, bss->est_throughput); | |
1397 | } | |
1398 | } | |
1399 | ||
3d910ef4 JM |
1400 | if (only_first_ssid) |
1401 | wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d", | |
1402 | group->id); | |
1403 | else | |
1404 | wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d", | |
1405 | group->priority); | |
9cf32261 | 1406 | |
620c7837 JM |
1407 | for (i = 0; i < wpa_s->last_scan_res_used; i++) { |
1408 | struct wpa_bss *bss = wpa_s->last_scan_res[i]; | |
91073cca SD |
1409 | |
1410 | wpa_s->owe_transition_select = 1; | |
3d910ef4 | 1411 | *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group, |
e65a87b3 | 1412 | only_first_ssid, 1); |
91073cca | 1413 | wpa_s->owe_transition_select = 0; |
d8d940b7 JM |
1414 | if (!*selected_ssid) |
1415 | continue; | |
f049052b BG |
1416 | wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR |
1417 | " ssid='%s'", | |
620c7837 JM |
1418 | MAC2STR(bss->bssid), |
1419 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); | |
1420 | return bss; | |
d8d940b7 JM |
1421 | } |
1422 | ||
1423 | return NULL; | |
6fc6879b JM |
1424 | } |
1425 | ||
1426 | ||
97236cee MH |
1427 | struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s, |
1428 | struct wpa_ssid **selected_ssid) | |
6fc6879b | 1429 | { |
6fa81a3b | 1430 | struct wpa_bss *selected = NULL; |
09b9df4e | 1431 | int prio; |
7c373ac2 | 1432 | struct wpa_ssid *next_ssid = NULL; |
a52410c2 | 1433 | struct wpa_ssid *ssid; |
09b9df4e | 1434 | |
620c7837 JM |
1435 | if (wpa_s->last_scan_res == NULL || |
1436 | wpa_s->last_scan_res_used == 0) | |
1437 | return NULL; /* no scan results from last update */ | |
1438 | ||
7c373ac2 | 1439 | if (wpa_s->next_ssid) { |
7c373ac2 JM |
1440 | /* check that next_ssid is still valid */ |
1441 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { | |
1442 | if (ssid == wpa_s->next_ssid) | |
1443 | break; | |
1444 | } | |
1445 | next_ssid = ssid; | |
1446 | wpa_s->next_ssid = NULL; | |
1447 | } | |
3d910ef4 | 1448 | |
7c373ac2 JM |
1449 | while (selected == NULL) { |
1450 | for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { | |
1451 | if (next_ssid && next_ssid->priority == | |
1452 | wpa_s->conf->pssid[prio]->priority) { | |
3d910ef4 | 1453 | selected = wpa_supplicant_select_bss( |
7c373ac2 | 1454 | wpa_s, next_ssid, selected_ssid, 1); |
3d910ef4 JM |
1455 | if (selected) |
1456 | break; | |
1457 | } | |
09b9df4e | 1458 | selected = wpa_supplicant_select_bss( |
620c7837 | 1459 | wpa_s, wpa_s->conf->pssid[prio], |
3d910ef4 | 1460 | selected_ssid, 0); |
09b9df4e JM |
1461 | if (selected) |
1462 | break; | |
1463 | } | |
1464 | ||
8945cc45 BM |
1465 | if (selected == NULL && wpa_s->blacklist && |
1466 | !wpa_s->countermeasures) { | |
f049052b BG |
1467 | wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear " |
1468 | "blacklist and try again"); | |
09b9df4e JM |
1469 | wpa_blacklist_clear(wpa_s); |
1470 | wpa_s->blacklist_cleared++; | |
1471 | } else if (selected == NULL) | |
1472 | break; | |
1473 | } | |
1474 | ||
a52410c2 JM |
1475 | ssid = *selected_ssid; |
1476 | if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set && | |
1477 | !ssid->passphrase && !ssid->ext_psk) { | |
1478 | const char *field_name, *txt = NULL; | |
1479 | ||
1480 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1481 | "PSK/passphrase not yet available for the selected network"); | |
1482 | ||
1483 | wpas_notify_network_request(wpa_s, ssid, | |
1484 | WPA_CTRL_REQ_PSK_PASSPHRASE, NULL); | |
1485 | ||
1486 | field_name = wpa_supplicant_ctrl_req_to_string( | |
1487 | WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt); | |
1488 | if (field_name == NULL) | |
1489 | return NULL; | |
1490 | ||
1491 | wpas_send_ctrl_req(wpa_s, ssid, field_name, txt); | |
1492 | ||
1493 | selected = NULL; | |
1494 | } | |
1495 | ||
09b9df4e JM |
1496 | return selected; |
1497 | } | |
1498 | ||
1499 | ||
1500 | static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s, | |
977b1174 | 1501 | int timeout_sec, int timeout_usec) |
09b9df4e | 1502 | { |
349493bd | 1503 | if (!wpa_supplicant_enabled_networks(wpa_s)) { |
4f34d51a SL |
1504 | /* |
1505 | * No networks are enabled; short-circuit request so | |
1506 | * we don't wait timeout seconds before transitioning | |
1507 | * to INACTIVE state. | |
1508 | */ | |
ac06fb12 JM |
1509 | wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request " |
1510 | "since there are no enabled networks"); | |
4f34d51a SL |
1511 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); |
1512 | return; | |
09b9df4e | 1513 | } |
5cc70322 JM |
1514 | |
1515 | wpa_s->scan_for_connection = 1; | |
977b1174 | 1516 | wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec); |
09b9df4e JM |
1517 | } |
1518 | ||
1519 | ||
5cbd88d9 JJ |
1520 | int wpa_supplicant_connect(struct wpa_supplicant *wpa_s, |
1521 | struct wpa_bss *selected, | |
1522 | struct wpa_ssid *ssid) | |
09b9df4e JM |
1523 | { |
1524 | if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) { | |
1525 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP | |
1526 | "PBC session overlap"); | |
1a2f7ca1 | 1527 | wpas_notify_wps_event_pbc_overlap(wpa_s); |
b73bf0a7 | 1528 | #ifdef CONFIG_P2P |
ace0fbdb AS |
1529 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT || |
1530 | wpa_s->p2p_in_provisioning) { | |
1531 | eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb, | |
1532 | wpa_s, NULL); | |
5cbd88d9 | 1533 | return -1; |
ace0fbdb | 1534 | } |
b73bf0a7 | 1535 | #endif /* CONFIG_P2P */ |
199716ad BG |
1536 | |
1537 | #ifdef CONFIG_WPS | |
0a7b2a02 | 1538 | wpas_wps_pbc_overlap(wpa_s); |
7736f18b | 1539 | wpas_wps_cancel(wpa_s); |
199716ad | 1540 | #endif /* CONFIG_WPS */ |
5cbd88d9 | 1541 | return -1; |
09b9df4e JM |
1542 | } |
1543 | ||
b0680017 JM |
1544 | wpa_msg(wpa_s, MSG_DEBUG, |
1545 | "Considering connect request: reassociate: %d selected: " | |
1546 | MACSTR " bssid: " MACSTR " pending: " MACSTR | |
1547 | " wpa_state: %s ssid=%p current_ssid=%p", | |
1548 | wpa_s->reassociate, MAC2STR(selected->bssid), | |
1549 | MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid), | |
1550 | wpa_supplicant_state_txt(wpa_s->wpa_state), | |
1551 | ssid, wpa_s->current_ssid); | |
1552 | ||
09b9df4e JM |
1553 | /* |
1554 | * Do not trigger new association unless the BSSID has changed or if | |
1555 | * reassociation is requested. If we are in process of associating with | |
1556 | * the selected BSSID, do not trigger new attempt. | |
1557 | */ | |
1558 | if (wpa_s->reassociate || | |
1559 | (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 && | |
e29853bb BG |
1560 | ((wpa_s->wpa_state != WPA_ASSOCIATING && |
1561 | wpa_s->wpa_state != WPA_AUTHENTICATING) || | |
b0680017 JM |
1562 | (!is_zero_ether_addr(wpa_s->pending_bssid) && |
1563 | os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) != | |
1564 | 0) || | |
1565 | (is_zero_ether_addr(wpa_s->pending_bssid) && | |
1566 | ssid != wpa_s->current_ssid)))) { | |
09b9df4e | 1567 | if (wpa_supplicant_scard_init(wpa_s, ssid)) { |
977b1174 | 1568 | wpa_supplicant_req_new_scan(wpa_s, 10, 0); |
5cbd88d9 | 1569 | return 0; |
09b9df4e | 1570 | } |
b0680017 JM |
1571 | wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR, |
1572 | MAC2STR(selected->bssid)); | |
09b9df4e JM |
1573 | wpa_supplicant_associate(wpa_s, selected, ssid); |
1574 | } else { | |
b0680017 JM |
1575 | wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to " |
1576 | "connect with the selected AP"); | |
09b9df4e | 1577 | } |
5cbd88d9 JJ |
1578 | |
1579 | return 0; | |
09b9df4e JM |
1580 | } |
1581 | ||
1582 | ||
b55aaa5f JM |
1583 | static struct wpa_ssid * |
1584 | wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s) | |
1585 | { | |
1586 | int prio; | |
1587 | struct wpa_ssid *ssid; | |
1588 | ||
1589 | for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { | |
1590 | for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext) | |
1591 | { | |
349493bd | 1592 | if (wpas_network_disabled(wpa_s, ssid)) |
b55aaa5f | 1593 | continue; |
81a10a94 JM |
1594 | #ifndef CONFIG_IBSS_RSN |
1595 | if (ssid->mode == WPAS_MODE_IBSS && | |
1596 | !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | | |
1597 | WPA_KEY_MGMT_WPA_NONE))) { | |
1598 | wpa_msg(wpa_s, MSG_INFO, | |
1599 | "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'", | |
1600 | wpa_ssid_txt(ssid->ssid, | |
1601 | ssid->ssid_len)); | |
1602 | continue; | |
1603 | } | |
1604 | #endif /* !CONFIG_IBSS_RSN */ | |
f74618cb SE |
1605 | if (ssid->mode == WPAS_MODE_IBSS || |
1606 | ssid->mode == WPAS_MODE_AP || | |
1607 | ssid->mode == WPAS_MODE_MESH) | |
b55aaa5f JM |
1608 | return ssid; |
1609 | } | |
1610 | } | |
1611 | return NULL; | |
1612 | } | |
1613 | ||
1614 | ||
a1fd2ce5 JM |
1615 | /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based |
1616 | * on BSS added and BSS changed events */ | |
6ae93185 | 1617 | static void wpa_supplicant_rsn_preauth_scan_results( |
6d28fb96 | 1618 | struct wpa_supplicant *wpa_s) |
6ae93185 | 1619 | { |
6d28fb96 | 1620 | struct wpa_bss *bss; |
6ae93185 JM |
1621 | |
1622 | if (rsn_preauth_scan_results(wpa_s->wpa) < 0) | |
1623 | return; | |
1624 | ||
6d28fb96 | 1625 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
6ae93185 | 1626 | const u8 *ssid, *rsn; |
6ae93185 | 1627 | |
6d28fb96 | 1628 | ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID); |
6ae93185 JM |
1629 | if (ssid == NULL) |
1630 | continue; | |
1631 | ||
6d28fb96 | 1632 | rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
6ae93185 JM |
1633 | if (rsn == NULL) |
1634 | continue; | |
1635 | ||
6d28fb96 | 1636 | rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn); |
6ae93185 JM |
1637 | } |
1638 | ||
1639 | } | |
1640 | ||
1641 | ||
48563d86 JM |
1642 | static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s, |
1643 | struct wpa_bss *selected, | |
20ed5e40 | 1644 | struct wpa_ssid *ssid) |
48563d86 | 1645 | { |
20ed5e40 | 1646 | struct wpa_bss *current_bss = NULL; |
ce18c107 | 1647 | #ifndef CONFIG_NO_ROAMING |
8d1e6931 | 1648 | int min_diff, diff; |
954e10e4 | 1649 | int to_5ghz; |
8d1e6931 | 1650 | int cur_est, sel_est; |
ce18c107 | 1651 | #endif /* CONFIG_NO_ROAMING */ |
48563d86 JM |
1652 | |
1653 | if (wpa_s->reassociate) | |
1654 | return 1; /* explicit request to reassociate */ | |
1655 | if (wpa_s->wpa_state < WPA_ASSOCIATED) | |
1656 | return 1; /* we are not associated; continue */ | |
1657 | if (wpa_s->current_ssid == NULL) | |
1658 | return 1; /* unknown current SSID */ | |
1659 | if (wpa_s->current_ssid != ssid) | |
1660 | return 1; /* different network block */ | |
1661 | ||
22628eca JM |
1662 | if (wpas_driver_bss_selection(wpa_s)) |
1663 | return 0; /* Driver-based roaming */ | |
1664 | ||
20ed5e40 JM |
1665 | if (wpa_s->current_ssid->ssid) |
1666 | current_bss = wpa_bss_get(wpa_s, wpa_s->bssid, | |
1667 | wpa_s->current_ssid->ssid, | |
1668 | wpa_s->current_ssid->ssid_len); | |
1669 | if (!current_bss) | |
1670 | current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid); | |
48563d86 JM |
1671 | |
1672 | if (!current_bss) | |
1673 | return 1; /* current BSS not seen in scan results */ | |
1674 | ||
20ed5e40 JM |
1675 | if (current_bss == selected) |
1676 | return 0; | |
1677 | ||
1678 | if (selected->last_update_idx > current_bss->last_update_idx) | |
1679 | return 1; /* current BSS not seen in the last scan */ | |
1680 | ||
e9af53ad | 1681 | #ifndef CONFIG_NO_ROAMING |
f049052b | 1682 | wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation"); |
0d2030ee | 1683 | wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR |
8d1e6931 JM |
1684 | " freq=%d level=%d snr=%d est_throughput=%u", |
1685 | MAC2STR(current_bss->bssid), | |
1686 | current_bss->freq, current_bss->level, | |
0d2030ee JM |
1687 | current_bss->snr, current_bss->est_throughput); |
1688 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR | |
8d1e6931 JM |
1689 | " freq=%d level=%d snr=%d est_throughput=%u", |
1690 | MAC2STR(selected->bssid), selected->freq, selected->level, | |
0d2030ee | 1691 | selected->snr, selected->est_throughput); |
48563d86 | 1692 | |
ac26ebd8 JM |
1693 | if (wpa_s->current_ssid->bssid_set && |
1694 | os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) == | |
1695 | 0) { | |
f049052b BG |
1696 | wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS " |
1697 | "has preferred BSSID"); | |
ac26ebd8 JM |
1698 | return 1; |
1699 | } | |
1700 | ||
0d2030ee JM |
1701 | if (selected->est_throughput > current_bss->est_throughput + 5000) { |
1702 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1703 | "Allow reassociation - selected BSS has better estimated throughput"); | |
1704 | return 1; | |
1705 | } | |
1706 | ||
954e10e4 JM |
1707 | to_5ghz = selected->freq > 4000 && current_bss->freq < 4000; |
1708 | ||
1709 | if (current_bss->level < 0 && | |
1710 | current_bss->level > selected->level + to_5ghz * 2) { | |
bff954e9 RS |
1711 | wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better " |
1712 | "signal level"); | |
1713 | return 0; | |
1714 | } | |
1715 | ||
8d1e6931 JM |
1716 | if (current_bss->est_throughput > selected->est_throughput + 5000) { |
1717 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1718 | "Skip roam - Current BSS has better estimated throughput"); | |
bcf66493 | 1719 | return 0; |
8d1e6931 JM |
1720 | } |
1721 | ||
1722 | cur_est = current_bss->est_throughput; | |
1723 | sel_est = selected->est_throughput; | |
48563d86 JM |
1724 | min_diff = 2; |
1725 | if (current_bss->level < 0) { | |
1726 | if (current_bss->level < -85) | |
1727 | min_diff = 1; | |
1728 | else if (current_bss->level < -80) | |
1729 | min_diff = 2; | |
1730 | else if (current_bss->level < -75) | |
1731 | min_diff = 3; | |
1732 | else if (current_bss->level < -70) | |
1733 | min_diff = 4; | |
1734 | else | |
1735 | min_diff = 5; | |
8d1e6931 JM |
1736 | if (cur_est > sel_est * 1.5) |
1737 | min_diff += 10; | |
1738 | else if (cur_est > sel_est * 1.2) | |
1739 | min_diff += 5; | |
1740 | else if (cur_est > sel_est * 1.1) | |
1741 | min_diff += 2; | |
1742 | else if (cur_est > sel_est) | |
1743 | min_diff++; | |
48563d86 | 1744 | } |
954e10e4 | 1745 | if (to_5ghz) { |
8d1e6931 JM |
1746 | int reduce = 2; |
1747 | ||
954e10e4 | 1748 | /* Make it easier to move to 5 GHz band */ |
8d1e6931 JM |
1749 | if (sel_est > cur_est * 1.5) |
1750 | reduce = 5; | |
1751 | else if (sel_est > cur_est * 1.2) | |
1752 | reduce = 4; | |
1753 | else if (sel_est > cur_est * 1.1) | |
1754 | reduce = 3; | |
1755 | ||
1756 | if (min_diff > reduce) | |
1757 | min_diff -= reduce; | |
954e10e4 JM |
1758 | else |
1759 | min_diff = 0; | |
1760 | } | |
8d1e6931 JM |
1761 | diff = abs(current_bss->level - selected->level); |
1762 | if (diff < min_diff) { | |
1763 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1764 | "Skip roam - too small difference in signal level (%d < %d)", | |
1765 | diff, min_diff); | |
48563d86 JM |
1766 | return 0; |
1767 | } | |
1768 | ||
8d1e6931 JM |
1769 | wpa_dbg(wpa_s, MSG_DEBUG, |
1770 | "Allow reassociation due to difference in signal level (%d >= %d)", | |
1771 | diff, min_diff); | |
48563d86 | 1772 | return 1; |
e9af53ad DS |
1773 | #else /* CONFIG_NO_ROAMING */ |
1774 | return 0; | |
1775 | #endif /* CONFIG_NO_ROAMING */ | |
48563d86 JM |
1776 | } |
1777 | ||
cd2f4ddf | 1778 | |
e3e2fe3a AS |
1779 | /* |
1780 | * Return a negative value if no scan results could be fetched or if scan | |
1781 | * results should not be shared with other virtual interfaces. | |
1782 | * Return 0 if scan results were fetched and may be shared with other | |
1783 | * interfaces. | |
1784 | * Return 1 if scan results may be shared with other virtual interfaces but may | |
1785 | * not trigger any operations. | |
1786 | * Return 2 if the interface was removed and cannot be used. | |
1787 | */ | |
e1504976 | 1788 | static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, |
cfd31b50 | 1789 | union wpa_event_data *data, |
e3e2fe3a | 1790 | int own_request, int update_only) |
09b9df4e | 1791 | { |
d12a51b5 JM |
1792 | struct wpa_scan_results *scan_res = NULL; |
1793 | int ret = 0; | |
5bc0cdb7 | 1794 | int ap = 0; |
7b1aa4fe JM |
1795 | #ifndef CONFIG_NO_RANDOM_POOL |
1796 | size_t i, num; | |
1797 | #endif /* CONFIG_NO_RANDOM_POOL */ | |
5bc0cdb7 JM |
1798 | |
1799 | #ifdef CONFIG_AP | |
1800 | if (wpa_s->ap_iface) | |
1801 | ap = 1; | |
1802 | #endif /* CONFIG_AP */ | |
6fc6879b | 1803 | |
cb8564b1 DW |
1804 | wpa_supplicant_notify_scanning(wpa_s, 0); |
1805 | ||
a1fd2ce5 JM |
1806 | scan_res = wpa_supplicant_get_scan_results(wpa_s, |
1807 | data ? &data->scan_info : | |
1808 | NULL, 1); | |
1809 | if (scan_res == NULL) { | |
66fe0f70 DS |
1810 | if (wpa_s->conf->ap_scan == 2 || ap || |
1811 | wpa_s->scan_res_handler == scan_only_handler) | |
e1504976 | 1812 | return -1; |
cfd31b50 JM |
1813 | if (!own_request) |
1814 | return -1; | |
adcd7c4b KV |
1815 | if (data && data->scan_info.external_scan) |
1816 | return -1; | |
f049052b BG |
1817 | wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try " |
1818 | "scanning again"); | |
977b1174 | 1819 | wpa_supplicant_req_new_scan(wpa_s, 1, 0); |
d12a51b5 JM |
1820 | ret = -1; |
1821 | goto scan_work_done; | |
6fc6879b JM |
1822 | } |
1823 | ||
bbb921da | 1824 | #ifndef CONFIG_NO_RANDOM_POOL |
bbb921da JM |
1825 | num = scan_res->num; |
1826 | if (num > 10) | |
1827 | num = 10; | |
1828 | for (i = 0; i < num; i++) { | |
1829 | u8 buf[5]; | |
1830 | struct wpa_scan_res *res = scan_res->res[i]; | |
1831 | buf[0] = res->bssid[5]; | |
1832 | buf[1] = res->qual & 0xff; | |
1833 | buf[2] = res->noise & 0xff; | |
1834 | buf[3] = res->level & 0xff; | |
1835 | buf[4] = res->tsf & 0xff; | |
1836 | random_add_randomness(buf, sizeof(buf)); | |
1837 | } | |
1838 | #endif /* CONFIG_NO_RANDOM_POOL */ | |
1839 | ||
e3e2fe3a AS |
1840 | if (update_only) { |
1841 | ret = 1; | |
1842 | goto scan_work_done; | |
1843 | } | |
1844 | ||
06f9acce | 1845 | if (own_request && wpa_s->scan_res_handler && |
adcd7c4b | 1846 | !(data && data->scan_info.external_scan)) { |
860fddbb JB |
1847 | void (*scan_res_handler)(struct wpa_supplicant *wpa_s, |
1848 | struct wpa_scan_results *scan_res); | |
1849 | ||
1850 | scan_res_handler = wpa_s->scan_res_handler; | |
64e58f51 | 1851 | wpa_s->scan_res_handler = NULL; |
860fddbb | 1852 | scan_res_handler(wpa_s, scan_res); |
e3e2fe3a | 1853 | ret = 1; |
d12a51b5 | 1854 | goto scan_work_done; |
64e58f51 JM |
1855 | } |
1856 | ||
5bc0cdb7 | 1857 | if (ap) { |
f049052b | 1858 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode"); |
c202f19c JB |
1859 | #ifdef CONFIG_AP |
1860 | if (wpa_s->ap_iface->scan_cb) | |
1861 | wpa_s->ap_iface->scan_cb(wpa_s->ap_iface); | |
1862 | #endif /* CONFIG_AP */ | |
d12a51b5 | 1863 | goto scan_work_done; |
5bc0cdb7 JM |
1864 | } |
1865 | ||
a5f40eff | 1866 | wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)", |
adcd7c4b KV |
1867 | wpa_s->own_scan_running, |
1868 | data ? data->scan_info.external_scan : 0); | |
d81c73be | 1869 | if (wpa_s->last_scan_req == MANUAL_SCAN_REQ && |
adcd7c4b KV |
1870 | wpa_s->manual_scan_use_id && wpa_s->own_scan_running && |
1871 | own_request && !(data && data->scan_info.external_scan)) { | |
d81c73be JM |
1872 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u", |
1873 | wpa_s->manual_scan_id); | |
1874 | wpa_s->manual_scan_use_id = 0; | |
1875 | } else { | |
1876 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS); | |
1877 | } | |
24f76940 | 1878 | wpas_notify_scan_results(wpa_s); |
6fc6879b | 1879 | |
8bac466b JM |
1880 | wpas_notify_scan_done(wpa_s, 1); |
1881 | ||
adcd7c4b | 1882 | if (data && data->scan_info.external_scan) { |
015af91f JM |
1883 | wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection"); |
1884 | wpa_scan_results_free(scan_res); | |
1885 | return 0; | |
1886 | } | |
1887 | ||
75d65857 | 1888 | if (wnm_scan_process(wpa_s, 1) > 0) |
d0b9ab69 JM |
1889 | goto scan_work_done; |
1890 | ||
d12a51b5 JM |
1891 | if (sme_proc_obss_scan(wpa_s) > 0) |
1892 | goto scan_work_done; | |
c3701c66 | 1893 | |
e3b5bd81 | 1894 | if (own_request && data && |
76196ddb AS |
1895 | wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0) |
1896 | goto scan_work_done; | |
1897 | ||
d12a51b5 JM |
1898 | if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) |
1899 | goto scan_work_done; | |
6fc6879b | 1900 | |
d12a51b5 JM |
1901 | if (autoscan_notify_scan(wpa_s, scan_res)) |
1902 | goto scan_work_done; | |
7c865c68 | 1903 | |
3180d7a2 SO |
1904 | if (wpa_s->disconnected) { |
1905 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | |
d12a51b5 | 1906 | goto scan_work_done; |
3180d7a2 SO |
1907 | } |
1908 | ||
22628eca | 1909 | if (!wpas_driver_bss_selection(wpa_s) && |
d12a51b5 JM |
1910 | bgscan_notify_scan(wpa_s, scan_res) == 1) |
1911 | goto scan_work_done; | |
a1fd2ce5 | 1912 | |
f9f0526b JM |
1913 | wpas_wps_update_ap_info(wpa_s, scan_res); |
1914 | ||
706e11a4 AN |
1915 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING && |
1916 | wpa_s->wpa_state < WPA_COMPLETED) | |
1917 | goto scan_work_done; | |
1918 | ||
20ed5e40 JM |
1919 | wpa_scan_results_free(scan_res); |
1920 | ||
adcd7c4b | 1921 | if (own_request && wpa_s->scan_work) { |
d12a51b5 JM |
1922 | struct wpa_radio_work *work = wpa_s->scan_work; |
1923 | wpa_s->scan_work = NULL; | |
1924 | radio_work_done(work); | |
1925 | } | |
1926 | ||
16ef233b JM |
1927 | os_free(wpa_s->last_scan_freqs); |
1928 | wpa_s->last_scan_freqs = NULL; | |
1929 | wpa_s->num_last_scan_freqs = 0; | |
1930 | if (own_request && data && | |
1931 | data->scan_info.freqs && data->scan_info.num_freqs) { | |
1932 | wpa_s->last_scan_freqs = os_malloc(sizeof(int) * | |
1933 | data->scan_info.num_freqs); | |
1934 | if (wpa_s->last_scan_freqs) { | |
1935 | os_memcpy(wpa_s->last_scan_freqs, | |
1936 | data->scan_info.freqs, | |
1937 | sizeof(int) * data->scan_info.num_freqs); | |
1938 | wpa_s->num_last_scan_freqs = data->scan_info.num_freqs; | |
1939 | } | |
1940 | } | |
1941 | ||
cc4952ad | 1942 | return wpas_select_network_from_last_scan(wpa_s, 1, own_request); |
d12a51b5 JM |
1943 | |
1944 | scan_work_done: | |
1945 | wpa_scan_results_free(scan_res); | |
adcd7c4b | 1946 | if (own_request && wpa_s->scan_work) { |
d12a51b5 JM |
1947 | struct wpa_radio_work *work = wpa_s->scan_work; |
1948 | wpa_s->scan_work = NULL; | |
1949 | radio_work_done(work); | |
1950 | } | |
1951 | return ret; | |
a594e2a9 JM |
1952 | } |
1953 | ||
1954 | ||
06b7f58d | 1955 | static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s, |
cc4952ad | 1956 | int new_scan, int own_request) |
a594e2a9 JM |
1957 | { |
1958 | struct wpa_bss *selected; | |
1959 | struct wpa_ssid *ssid = NULL; | |
9bd566a3 AS |
1960 | int time_to_reenable = wpas_reenabled_network_time(wpa_s); |
1961 | ||
1962 | if (time_to_reenable > 0) { | |
1963 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1964 | "Postpone network selection by %d seconds since all networks are disabled", | |
1965 | time_to_reenable); | |
1966 | eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL); | |
1967 | eloop_register_timeout(time_to_reenable, 0, | |
1968 | wpas_network_reenabled, wpa_s, NULL); | |
1969 | return 0; | |
1970 | } | |
a594e2a9 | 1971 | |
44b9ea5b JM |
1972 | if (wpa_s->p2p_mgmt) |
1973 | return 0; /* no normal connection on p2p_mgmt interface */ | |
1974 | ||
a5e6270f | 1975 | wpa_s->owe_transition_search = 0; |
620c7837 JM |
1976 | selected = wpa_supplicant_pick_network(wpa_s, &ssid); |
1977 | ||
70351623 MH |
1978 | #ifdef CONFIG_MESH |
1979 | if (wpa_s->ifmsh) { | |
1980 | wpa_msg(wpa_s, MSG_INFO, | |
1981 | "Avoiding join because we already joined a mesh group"); | |
1982 | return 0; | |
1983 | } | |
1984 | #endif /* CONFIG_MESH */ | |
1985 | ||
6fc6879b | 1986 | if (selected) { |
48563d86 | 1987 | int skip; |
20ed5e40 | 1988 | skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid); |
1bbff09e | 1989 | if (skip) { |
06b7f58d JM |
1990 | if (new_scan) |
1991 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); | |
e1504976 | 1992 | return 0; |
1bbff09e | 1993 | } |
5cbd88d9 | 1994 | |
16ef233b JM |
1995 | wpa_s->suitable_network++; |
1996 | ||
0e6a2cf2 AB |
1997 | if (ssid != wpa_s->current_ssid && |
1998 | wpa_s->wpa_state >= WPA_AUTHENTICATING) { | |
1999 | wpa_s->own_disconnect_req = 1; | |
2000 | wpa_supplicant_deauthenticate( | |
2001 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
2002 | } | |
2003 | ||
5cbd88d9 JJ |
2004 | if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) { |
2005 | wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed"); | |
2006 | return -1; | |
2007 | } | |
06b7f58d JM |
2008 | if (new_scan) |
2009 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); | |
0dd54313 | 2010 | /* |
e3e2fe3a AS |
2011 | * Do not allow other virtual radios to trigger operations based |
2012 | * on these scan results since we do not want them to start | |
2013 | * other associations at the same time. | |
0dd54313 JM |
2014 | */ |
2015 | return 1; | |
6fc6879b | 2016 | } else { |
16ef233b | 2017 | wpa_s->no_suitable_network++; |
f049052b | 2018 | wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found"); |
b55aaa5f JM |
2019 | ssid = wpa_supplicant_pick_new_network(wpa_s); |
2020 | if (ssid) { | |
f049052b | 2021 | wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network"); |
b55aaa5f | 2022 | wpa_supplicant_associate(wpa_s, NULL, ssid); |
06b7f58d JM |
2023 | if (new_scan) |
2024 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); | |
cc4952ad JJ |
2025 | } else if (own_request) { |
2026 | /* | |
2027 | * No SSID found. If SCAN results are as a result of | |
2028 | * own scan request and not due to a scan request on | |
2029 | * another shared interface, try another scan. | |
2030 | */ | |
67b9bd08 | 2031 | int timeout_sec = wpa_s->scan_interval; |
977b1174 | 2032 | int timeout_usec = 0; |
0817de90 | 2033 | #ifdef CONFIG_P2P |
b0e669be JM |
2034 | int res; |
2035 | ||
2036 | res = wpas_p2p_scan_no_go_seen(wpa_s); | |
2037 | if (res == 2) | |
2038 | return 2; | |
2039 | if (res == 1) | |
aa9bb764 JM |
2040 | return 0; |
2041 | ||
6fc48481 | 2042 | if (wpa_s->p2p_in_provisioning || |
41d5ce9e RR |
2043 | wpa_s->show_group_started || |
2044 | wpa_s->p2p_in_invitation) { | |
0817de90 JM |
2045 | /* |
2046 | * Use shorter wait during P2P Provisioning | |
6fc48481 RR |
2047 | * state and during P2P join-a-group operation |
2048 | * to speed up group formation. | |
0817de90 JM |
2049 | */ |
2050 | timeout_sec = 0; | |
2051 | timeout_usec = 250000; | |
a4cba8f1 LC |
2052 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, |
2053 | timeout_usec); | |
2054 | return 0; | |
0817de90 JM |
2055 | } |
2056 | #endif /* CONFIG_P2P */ | |
4d5bda5f JM |
2057 | #ifdef CONFIG_INTERWORKING |
2058 | if (wpa_s->conf->auto_interworking && | |
2059 | wpa_s->conf->interworking && | |
2060 | wpa_s->conf->cred) { | |
2061 | wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: " | |
2062 | "start ANQP fetch since no matching " | |
2063 | "networks found"); | |
2064 | wpa_s->network_select = 1; | |
2065 | wpa_s->auto_network_select = 1; | |
2066 | interworking_start_fetch_anqp(wpa_s); | |
0dd54313 | 2067 | return 1; |
4d5bda5f JM |
2068 | } |
2069 | #endif /* CONFIG_INTERWORKING */ | |
662b40b1 | 2070 | #ifdef CONFIG_WPS |
538d6f4b | 2071 | if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) { |
662b40b1 JM |
2072 | wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing"); |
2073 | timeout_sec = 0; | |
2074 | timeout_usec = 500000; | |
2075 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, | |
2076 | timeout_usec); | |
2077 | return 0; | |
2078 | } | |
2079 | #endif /* CONFIG_WPS */ | |
a5e6270f JM |
2080 | #ifdef CONFIG_OWE |
2081 | if (wpa_s->owe_transition_search) { | |
2082 | wpa_dbg(wpa_s, MSG_DEBUG, | |
2083 | "OWE: Use shorter wait during transition mode search"); | |
2084 | timeout_sec = 0; | |
2085 | timeout_usec = 500000; | |
2086 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, | |
2087 | timeout_usec); | |
2088 | return 0; | |
2089 | } | |
2090 | #endif /* CONFIG_OWE */ | |
a4cba8f1 LC |
2091 | if (wpa_supplicant_req_sched_scan(wpa_s)) |
2092 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, | |
2093 | timeout_usec); | |
4f39908b DS |
2094 | |
2095 | wpa_msg_ctrl(wpa_s, MSG_INFO, | |
2096 | WPA_EVENT_NETWORK_NOT_FOUND); | |
977b1174 | 2097 | } |
6fc6879b | 2098 | } |
e1504976 | 2099 | return 0; |
6fc6879b | 2100 | } |
6859f1cb BG |
2101 | |
2102 | ||
b0e669be JM |
2103 | static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, |
2104 | union wpa_event_data *data) | |
6859f1cb | 2105 | { |
6859f1cb | 2106 | struct wpa_supplicant *ifs; |
b0e669be | 2107 | int res; |
6859f1cb | 2108 | |
e3e2fe3a | 2109 | res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0); |
b0e669be JM |
2110 | if (res == 2) { |
2111 | /* | |
2112 | * Interface may have been removed, so must not dereference | |
2113 | * wpa_s after this. | |
2114 | */ | |
2115 | return 1; | |
2116 | } | |
e3e2fe3a AS |
2117 | |
2118 | if (res < 0) { | |
e1504976 BG |
2119 | /* |
2120 | * If no scan results could be fetched, then no need to | |
2121 | * notify those interfaces that did not actually request | |
0dd54313 JM |
2122 | * this scan. Similarly, if scan results started a new operation on this |
2123 | * interface, do not notify other interfaces to avoid concurrent | |
2124 | * operations during a connection attempt. | |
e1504976 | 2125 | */ |
b0e669be | 2126 | return 0; |
e1504976 | 2127 | } |
6859f1cb BG |
2128 | |
2129 | /* | |
f88f19b4 | 2130 | * Check other interfaces to see if they share the same radio. If |
6859f1cb BG |
2131 | * so, they get updated with this same scan info. |
2132 | */ | |
f88f19b4 JM |
2133 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
2134 | radio_list) { | |
2135 | if (ifs != wpa_s) { | |
6859f1cb BG |
2136 | wpa_printf(MSG_DEBUG, "%s: Updating scan results from " |
2137 | "sibling", ifs->ifname); | |
e3e2fe3a AS |
2138 | res = _wpa_supplicant_event_scan_results(ifs, data, 0, |
2139 | res > 0); | |
2140 | if (res < 0) | |
2141 | return 0; | |
6859f1cb BG |
2142 | } |
2143 | } | |
b0e669be JM |
2144 | |
2145 | return 0; | |
6859f1cb BG |
2146 | } |
2147 | ||
6fc6879b JM |
2148 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
2149 | ||
2150 | ||
cecdddc1 PS |
2151 | int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s) |
2152 | { | |
2153 | #ifdef CONFIG_NO_SCAN_PROCESSING | |
2154 | return -1; | |
2155 | #else /* CONFIG_NO_SCAN_PROCESSING */ | |
a12d3454 | 2156 | struct os_reltime now; |
cecdddc1 | 2157 | |
6e374bd4 JM |
2158 | wpa_s->ignore_post_flush_scan_res = 0; |
2159 | ||
c1a14ef4 | 2160 | if (wpa_s->last_scan_res_used == 0) |
cecdddc1 PS |
2161 | return -1; |
2162 | ||
a12d3454 JB |
2163 | os_get_reltime(&now); |
2164 | if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) { | |
cecdddc1 PS |
2165 | wpa_printf(MSG_DEBUG, "Fast associate: Old scan results"); |
2166 | return -1; | |
2167 | } | |
2168 | ||
cc4952ad | 2169 | return wpas_select_network_from_last_scan(wpa_s, 0, 1); |
cecdddc1 PS |
2170 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
2171 | } | |
2172 | ||
b6668734 JM |
2173 | #ifdef CONFIG_WNM |
2174 | ||
2175 | static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx) | |
2176 | { | |
2177 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
2178 | ||
2179 | if (wpa_s->wpa_state < WPA_ASSOCIATED) | |
2180 | return; | |
2181 | ||
2ec535fd JM |
2182 | if (!wpa_s->no_keep_alive) { |
2183 | wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR, | |
2184 | MAC2STR(wpa_s->bssid)); | |
2185 | /* TODO: could skip this if normal data traffic has been sent */ | |
2186 | /* TODO: Consider using some more appropriate data frame for | |
2187 | * this */ | |
2188 | if (wpa_s->l2) | |
2189 | l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800, | |
2190 | (u8 *) "", 0); | |
2191 | } | |
b6668734 | 2192 | |
597c7a8d | 2193 | #ifdef CONFIG_SME |
b6668734 JM |
2194 | if (wpa_s->sme.bss_max_idle_period) { |
2195 | unsigned int msec; | |
2196 | msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */ | |
2197 | if (msec > 100) | |
2198 | msec -= 100; | |
2199 | eloop_register_timeout(msec / 1000, msec % 1000 * 1000, | |
2200 | wnm_bss_keep_alive, wpa_s, NULL); | |
2201 | } | |
597c7a8d | 2202 | #endif /* CONFIG_SME */ |
b6668734 JM |
2203 | } |
2204 | ||
2205 | ||
2206 | static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s, | |
2207 | const u8 *ies, size_t ies_len) | |
2208 | { | |
2209 | struct ieee802_11_elems elems; | |
2210 | ||
2211 | if (ies == NULL) | |
2212 | return; | |
2213 | ||
2214 | if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) | |
2215 | return; | |
2216 | ||
2217 | #ifdef CONFIG_SME | |
2218 | if (elems.bss_max_idle_period) { | |
2219 | unsigned int msec; | |
2220 | wpa_s->sme.bss_max_idle_period = | |
2221 | WPA_GET_LE16(elems.bss_max_idle_period); | |
2222 | wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 " | |
2223 | "TU)%s", wpa_s->sme.bss_max_idle_period, | |
2224 | (elems.bss_max_idle_period[2] & 0x01) ? | |
2225 | " (protected keep-live required)" : ""); | |
2226 | if (wpa_s->sme.bss_max_idle_period == 0) | |
2227 | wpa_s->sme.bss_max_idle_period = 1; | |
2228 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) { | |
2229 | eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL); | |
2230 | /* msec times 1000 */ | |
2231 | msec = wpa_s->sme.bss_max_idle_period * 1024; | |
2232 | if (msec > 100) | |
2233 | msec -= 100; | |
2234 | eloop_register_timeout(msec / 1000, msec % 1000 * 1000, | |
2235 | wnm_bss_keep_alive, wpa_s, | |
2236 | NULL); | |
2237 | } | |
2238 | } | |
2239 | #endif /* CONFIG_SME */ | |
2240 | } | |
2241 | ||
2242 | #endif /* CONFIG_WNM */ | |
2243 | ||
2244 | ||
2245 | void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s) | |
2246 | { | |
2247 | #ifdef CONFIG_WNM | |
2248 | eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL); | |
2249 | #endif /* CONFIG_WNM */ | |
2250 | } | |
2251 | ||
2252 | ||
56f5af48 JM |
2253 | #ifdef CONFIG_INTERWORKING |
2254 | ||
2255 | static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map, | |
2256 | size_t len) | |
2257 | { | |
2258 | int res; | |
2259 | ||
2260 | wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len); | |
2261 | res = wpa_drv_set_qos_map(wpa_s, qos_map, len); | |
2262 | if (res) { | |
2263 | wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver"); | |
2264 | } | |
2265 | ||
2266 | return res; | |
2267 | } | |
2268 | ||
2269 | ||
2270 | static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s, | |
2271 | const u8 *ies, size_t ies_len) | |
2272 | { | |
2273 | struct ieee802_11_elems elems; | |
2274 | ||
2275 | if (ies == NULL) | |
2276 | return; | |
2277 | ||
2278 | if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) | |
2279 | return; | |
2280 | ||
2281 | if (elems.qos_map_set) { | |
2282 | wpas_qos_map_set(wpa_s, elems.qos_map_set, | |
2283 | elems.qos_map_set_len); | |
2284 | } | |
2285 | } | |
2286 | ||
2287 | #endif /* CONFIG_INTERWORKING */ | |
2288 | ||
2289 | ||
5abc7823 VN |
2290 | static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s, |
2291 | const u8 *ies, size_t ies_len) | |
2292 | { | |
2293 | struct ieee802_11_elems elems; | |
2294 | const u8 *map_sub_elem, *pos; | |
2295 | size_t len; | |
2296 | ||
2297 | if (!wpa_s->current_ssid || | |
2298 | !wpa_s->current_ssid->multi_ap_backhaul_sta || | |
2299 | !ies || | |
2300 | ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) | |
2301 | return; | |
2302 | ||
2303 | if (!elems.multi_ap || elems.multi_ap_len < 7) { | |
2304 | wpa_printf(MSG_INFO, "AP doesn't support Multi-AP protocol"); | |
2305 | goto fail; | |
2306 | } | |
2307 | ||
2308 | pos = elems.multi_ap + 4; | |
2309 | len = elems.multi_ap_len - 4; | |
2310 | ||
2311 | map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE); | |
2312 | if (!map_sub_elem || map_sub_elem[1] < 1) { | |
2313 | wpa_printf(MSG_INFO, "invalid Multi-AP sub elem type"); | |
2314 | goto fail; | |
2315 | } | |
2316 | ||
2317 | if (!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS)) { | |
83ebf558 DL |
2318 | if ((map_sub_elem[2] & MULTI_AP_FRONTHAUL_BSS) && |
2319 | wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) { | |
2320 | wpa_printf(MSG_INFO, | |
2321 | "WPS active, accepting fronthaul-only BSS"); | |
2322 | /* Don't set 4addr mode in this case, so just return */ | |
2323 | return; | |
2324 | } | |
5abc7823 VN |
2325 | wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS"); |
2326 | goto fail; | |
2327 | } | |
2328 | ||
2329 | if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) { | |
2330 | wpa_printf(MSG_ERROR, "Failed to set 4addr mode"); | |
2331 | goto fail; | |
2332 | } | |
2333 | wpa_s->enabled_4addr_mode = 1; | |
2334 | return; | |
2335 | ||
2336 | fail: | |
2337 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
2338 | } | |
2339 | ||
2340 | ||
ea708118 DL |
2341 | #ifdef CONFIG_FST |
2342 | static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s, | |
2343 | const u8 *ie, size_t ie_len) | |
2344 | { | |
2345 | struct mb_ies_info mb_ies; | |
2346 | ||
2347 | if (!ie || !ie_len || !wpa_s->fst) | |
2348 | return -ENOENT; | |
2349 | ||
2350 | os_memset(&mb_ies, 0, sizeof(mb_ies)); | |
2351 | ||
2352 | while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) { | |
2353 | size_t len; | |
2354 | ||
2355 | len = 2 + ie[1]; | |
2356 | if (len > ie_len) { | |
2357 | wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found", | |
2358 | ie, ie_len); | |
2359 | break; | |
2360 | } | |
2361 | ||
2362 | if (ie[0] == WLAN_EID_MULTI_BAND) { | |
2363 | wpa_printf(MSG_DEBUG, "MB IE of %u bytes found", | |
2364 | (unsigned int) len); | |
2365 | mb_ies.ies[mb_ies.nof_ies].ie = ie + 2; | |
2366 | mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2; | |
2367 | mb_ies.nof_ies++; | |
2368 | } | |
2369 | ||
2370 | ie_len -= len; | |
2371 | ie += len; | |
2372 | } | |
2373 | ||
2374 | if (mb_ies.nof_ies > 0) { | |
2375 | wpabuf_free(wpa_s->received_mb_ies); | |
2376 | wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies); | |
2377 | return 0; | |
2378 | } | |
2379 | ||
2380 | return -ENOENT; | |
2381 | } | |
2382 | #endif /* CONFIG_FST */ | |
2383 | ||
2384 | ||
579ce771 JM |
2385 | static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s, |
2386 | union wpa_event_data *data) | |
6fc6879b JM |
2387 | { |
2388 | int l, len, found = 0, wpa_found, rsn_found; | |
c2a04078 | 2389 | const u8 *p; |
64624f31 | 2390 | #if defined(CONFIG_IEEE80211R) || defined(CONFIG_OWE) |
6a1ce395 | 2391 | u8 bssid[ETH_ALEN]; |
64624f31 | 2392 | #endif /* CONFIG_IEEE80211R || CONFIG_OWE */ |
6fc6879b | 2393 | |
f049052b | 2394 | wpa_dbg(wpa_s, MSG_DEBUG, "Association info event"); |
6fc6879b JM |
2395 | if (data->assoc_info.req_ies) |
2396 | wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies, | |
2397 | data->assoc_info.req_ies_len); | |
52c9e6f3 | 2398 | if (data->assoc_info.resp_ies) { |
6fc6879b JM |
2399 | wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies, |
2400 | data->assoc_info.resp_ies_len); | |
52c9e6f3 JM |
2401 | #ifdef CONFIG_TDLS |
2402 | wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies, | |
2403 | data->assoc_info.resp_ies_len); | |
2404 | #endif /* CONFIG_TDLS */ | |
b6668734 JM |
2405 | #ifdef CONFIG_WNM |
2406 | wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies, | |
2407 | data->assoc_info.resp_ies_len); | |
2408 | #endif /* CONFIG_WNM */ | |
56f5af48 JM |
2409 | #ifdef CONFIG_INTERWORKING |
2410 | interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies, | |
2411 | data->assoc_info.resp_ies_len); | |
2412 | #endif /* CONFIG_INTERWORKING */ | |
d7f038de BP |
2413 | if (wpa_s->hw_capab == CAPAB_VHT && |
2414 | get_ie(data->assoc_info.resp_ies, | |
2415 | data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP)) | |
2416 | wpa_s->ieee80211ac = 1; | |
5abc7823 VN |
2417 | |
2418 | multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies, | |
2419 | data->assoc_info.resp_ies_len); | |
52c9e6f3 | 2420 | } |
6fc6879b JM |
2421 | if (data->assoc_info.beacon_ies) |
2422 | wpa_hexdump(MSG_DEBUG, "beacon_ies", | |
2423 | data->assoc_info.beacon_ies, | |
2424 | data->assoc_info.beacon_ies_len); | |
4832ecd7 | 2425 | if (data->assoc_info.freq) |
f049052b BG |
2426 | wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz", |
2427 | data->assoc_info.freq); | |
6fc6879b | 2428 | |
3f8ceff5 JM |
2429 | wpa_s->connection_set = 0; |
2430 | if (data->assoc_info.req_ies && data->assoc_info.resp_ies) { | |
2431 | struct ieee802_11_elems req_elems, resp_elems; | |
2432 | ||
2433 | if (ieee802_11_parse_elems(data->assoc_info.req_ies, | |
2434 | data->assoc_info.req_ies_len, | |
2435 | &req_elems, 0) != ParseFailed && | |
2436 | ieee802_11_parse_elems(data->assoc_info.resp_ies, | |
2437 | data->assoc_info.resp_ies_len, | |
2438 | &resp_elems, 0) != ParseFailed) { | |
2439 | wpa_s->connection_set = 1; | |
2440 | wpa_s->connection_ht = req_elems.ht_capabilities && | |
2441 | resp_elems.ht_capabilities; | |
2442 | wpa_s->connection_vht = req_elems.vht_capabilities && | |
2443 | resp_elems.vht_capabilities; | |
2444 | wpa_s->connection_he = req_elems.he_capabilities && | |
2445 | resp_elems.he_capabilities; | |
2446 | } | |
2447 | } | |
2448 | ||
6fc6879b JM |
2449 | p = data->assoc_info.req_ies; |
2450 | l = data->assoc_info.req_ies_len; | |
2451 | ||
2452 | /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */ | |
2453 | while (p && l >= 2) { | |
2454 | len = p[1] + 2; | |
2455 | if (len > l) { | |
2456 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", | |
2457 | p, l); | |
2458 | break; | |
2459 | } | |
2460 | if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && | |
2461 | (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) || | |
192964dd DN |
2462 | (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 && |
2463 | (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) || | |
6fc6879b JM |
2464 | (p[0] == WLAN_EID_RSN && p[1] >= 2)) { |
2465 | if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len)) | |
2466 | break; | |
2467 | found = 1; | |
2468 | wpa_find_assoc_pmkid(wpa_s); | |
2469 | break; | |
2470 | } | |
2471 | l -= len; | |
2472 | p += len; | |
2473 | } | |
2474 | if (!found && data->assoc_info.req_ies) | |
2475 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); | |
2476 | ||
706df429 JM |
2477 | #ifdef CONFIG_FILS |
2478 | #ifdef CONFIG_SME | |
76e20f4f JM |
2479 | if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS || |
2480 | wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) && | |
706df429 JM |
2481 | (!data->assoc_info.resp_frame || |
2482 | fils_process_assoc_resp(wpa_s->wpa, | |
2483 | data->assoc_info.resp_frame, | |
2484 | data->assoc_info.resp_frame_len) < 0)) { | |
2485 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED); | |
2486 | return -1; | |
2487 | } | |
2488 | #endif /* CONFIG_SME */ | |
5538fc93 VK |
2489 | |
2490 | /* Additional processing for FILS when SME is in driver */ | |
2491 | if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS && | |
2492 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) | |
2493 | wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1); | |
706df429 JM |
2494 | #endif /* CONFIG_FILS */ |
2495 | ||
0a614799 JM |
2496 | #ifdef CONFIG_OWE |
2497 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE && | |
5a78c361 JM |
2498 | (wpa_drv_get_bssid(wpa_s, bssid) < 0 || |
2499 | owe_process_assoc_resp(wpa_s->wpa, bssid, | |
2500 | data->assoc_info.resp_ies, | |
2501 | data->assoc_info.resp_ies_len) < 0)) { | |
0a614799 JM |
2502 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED); |
2503 | return -1; | |
2504 | } | |
2505 | #endif /* CONFIG_OWE */ | |
2506 | ||
10ec6a5f JM |
2507 | #ifdef CONFIG_DPP2 |
2508 | wpa_sm_set_dpp_z(wpa_s->wpa, NULL); | |
2509 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_DPP && wpa_s->dpp_pfs) { | |
2510 | struct ieee802_11_elems elems; | |
2511 | ||
2512 | if (ieee802_11_parse_elems(data->assoc_info.resp_ies, | |
2513 | data->assoc_info.resp_ies_len, | |
2514 | &elems, 0) == ParseFailed || | |
2515 | !elems.owe_dh) | |
2516 | goto no_pfs; | |
2517 | if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh, | |
2518 | elems.owe_dh_len) < 0) { | |
2519 | wpa_supplicant_deauthenticate(wpa_s, | |
2520 | WLAN_REASON_UNSPECIFIED); | |
2521 | return -1; | |
2522 | } | |
2523 | ||
2524 | wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret); | |
2525 | } | |
2526 | no_pfs: | |
2527 | #endif /* CONFIG_DPP2 */ | |
2528 | ||
c2a04078 | 2529 | #ifdef CONFIG_IEEE80211R |
62c72d72 JM |
2530 | #ifdef CONFIG_SME |
2531 | if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) { | |
62c72d72 JM |
2532 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0 || |
2533 | wpa_ft_validate_reassoc_resp(wpa_s->wpa, | |
2534 | data->assoc_info.resp_ies, | |
2535 | data->assoc_info.resp_ies_len, | |
2536 | bssid) < 0) { | |
f049052b BG |
2537 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of " |
2538 | "Reassociation Response failed"); | |
579ce771 JM |
2539 | wpa_supplicant_deauthenticate( |
2540 | wpa_s, WLAN_REASON_INVALID_IE); | |
2541 | return -1; | |
62c72d72 JM |
2542 | } |
2543 | } | |
62c72d72 | 2544 | |
c2a04078 JM |
2545 | p = data->assoc_info.resp_ies; |
2546 | l = data->assoc_info.resp_ies_len; | |
2547 | ||
54f489be | 2548 | #ifdef CONFIG_WPS_STRICT |
5dac11e0 | 2549 | if (p && wpa_s->current_ssid && |
54f489be JM |
2550 | wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) { |
2551 | struct wpabuf *wps; | |
2552 | wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE); | |
2553 | if (wps == NULL) { | |
f049052b BG |
2554 | wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not " |
2555 | "include WPS IE in (Re)Association Response"); | |
54f489be JM |
2556 | return -1; |
2557 | } | |
2558 | ||
2559 | if (wps_validate_assoc_resp(wps) < 0) { | |
2560 | wpabuf_free(wps); | |
2561 | wpa_supplicant_deauthenticate( | |
2562 | wpa_s, WLAN_REASON_INVALID_IE); | |
2563 | return -1; | |
2564 | } | |
2565 | wpabuf_free(wps); | |
2566 | } | |
2567 | #endif /* CONFIG_WPS_STRICT */ | |
2568 | ||
e7846b68 | 2569 | /* Go through the IEs and make a copy of the MDIE, if present. */ |
c2a04078 JM |
2570 | while (p && l >= 2) { |
2571 | len = p[1] + 2; | |
2572 | if (len > l) { | |
2573 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", | |
2574 | p, l); | |
2575 | break; | |
2576 | } | |
e7846b68 JM |
2577 | if (p[0] == WLAN_EID_MOBILITY_DOMAIN && |
2578 | p[1] >= MOBILITY_DOMAIN_ID_LEN) { | |
2579 | wpa_s->sme.ft_used = 1; | |
2580 | os_memcpy(wpa_s->sme.mobility_domain, p + 2, | |
2581 | MOBILITY_DOMAIN_ID_LEN); | |
2582 | break; | |
2583 | } | |
c2a04078 JM |
2584 | l -= len; |
2585 | p += len; | |
2586 | } | |
e7846b68 | 2587 | #endif /* CONFIG_SME */ |
c2a04078 | 2588 | |
6a1ce395 DG |
2589 | /* Process FT when SME is in the driver */ |
2590 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && | |
2591 | wpa_ft_is_completed(wpa_s->wpa)) { | |
2592 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0 || | |
2593 | wpa_ft_validate_reassoc_resp(wpa_s->wpa, | |
2594 | data->assoc_info.resp_ies, | |
2595 | data->assoc_info.resp_ies_len, | |
2596 | bssid) < 0) { | |
2597 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of " | |
2598 | "Reassociation Response failed"); | |
2599 | wpa_supplicant_deauthenticate( | |
2600 | wpa_s, WLAN_REASON_INVALID_IE); | |
2601 | return -1; | |
2602 | } | |
2603 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done"); | |
2604 | } | |
2605 | ||
e7846b68 JM |
2606 | wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies, |
2607 | data->assoc_info.resp_ies_len); | |
c2a04078 JM |
2608 | #endif /* CONFIG_IEEE80211R */ |
2609 | ||
6fc6879b JM |
2610 | /* WPA/RSN IE from Beacon/ProbeResp */ |
2611 | p = data->assoc_info.beacon_ies; | |
2612 | l = data->assoc_info.beacon_ies_len; | |
2613 | ||
2614 | /* Go through the IEs and make a copy of the WPA/RSN IEs, if present. | |
2615 | */ | |
2616 | wpa_found = rsn_found = 0; | |
2617 | while (p && l >= 2) { | |
2618 | len = p[1] + 2; | |
2619 | if (len > l) { | |
2620 | wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies", | |
2621 | p, l); | |
2622 | break; | |
2623 | } | |
2624 | if (!wpa_found && | |
2625 | p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && | |
2626 | os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) { | |
2627 | wpa_found = 1; | |
2628 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len); | |
2629 | } | |
2630 | ||
2631 | if (!rsn_found && | |
2632 | p[0] == WLAN_EID_RSN && p[1] >= 2) { | |
2633 | rsn_found = 1; | |
2634 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len); | |
2635 | } | |
2636 | ||
2637 | l -= len; | |
2638 | p += len; | |
2639 | } | |
2640 | ||
2641 | if (!wpa_found && data->assoc_info.beacon_ies) | |
2642 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0); | |
2643 | if (!rsn_found && data->assoc_info.beacon_ies) | |
2644 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0); | |
2645 | if (wpa_found || rsn_found) | |
2646 | wpa_s->ap_ies_from_associnfo = 1; | |
4832ecd7 | 2647 | |
117e812d JM |
2648 | if (wpa_s->assoc_freq && data->assoc_info.freq && |
2649 | wpa_s->assoc_freq != data->assoc_info.freq) { | |
2650 | wpa_printf(MSG_DEBUG, "Operating frequency changed from " | |
2651 | "%u to %u MHz", | |
2652 | wpa_s->assoc_freq, data->assoc_info.freq); | |
2653 | wpa_supplicant_update_scan_results(wpa_s); | |
2654 | } | |
2655 | ||
4832ecd7 | 2656 | wpa_s->assoc_freq = data->assoc_info.freq; |
579ce771 JM |
2657 | |
2658 | return 0; | |
6fc6879b JM |
2659 | } |
2660 | ||
2661 | ||
ad9ee4d4 JM |
2662 | static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s) |
2663 | { | |
2664 | const u8 *bss_wpa = NULL, *bss_rsn = NULL; | |
2665 | ||
2666 | if (!wpa_s->current_bss || !wpa_s->current_ssid) | |
2667 | return -1; | |
2668 | ||
2669 | if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt)) | |
2670 | return 0; | |
2671 | ||
2672 | bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss, | |
2673 | WPA_IE_VENDOR_TYPE); | |
2674 | bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN); | |
2675 | ||
2676 | if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa, | |
2677 | bss_wpa ? 2 + bss_wpa[1] : 0) || | |
2678 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn, | |
2679 | bss_rsn ? 2 + bss_rsn[1] : 0)) | |
2680 | return -1; | |
2681 | ||
2682 | return 0; | |
2683 | } | |
2684 | ||
2685 | ||
ea708118 DL |
2686 | static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s, |
2687 | union wpa_event_data *data) | |
2688 | { | |
2689 | #ifdef CONFIG_FST | |
2690 | struct assoc_info *ai = data ? &data->assoc_info : NULL; | |
2691 | struct wpa_bss *bss = wpa_s->current_bss; | |
2692 | const u8 *ieprb, *iebcn; | |
2693 | ||
2694 | wpabuf_free(wpa_s->received_mb_ies); | |
2695 | wpa_s->received_mb_ies = NULL; | |
2696 | ||
2697 | if (ai && | |
2698 | !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) { | |
2699 | wpa_printf(MSG_DEBUG, | |
2700 | "FST: MB IEs updated from Association Response frame"); | |
2701 | return; | |
2702 | } | |
2703 | ||
2704 | if (ai && | |
2705 | !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) { | |
2706 | wpa_printf(MSG_DEBUG, | |
2707 | "FST: MB IEs updated from association event Beacon IEs"); | |
2708 | return; | |
2709 | } | |
2710 | ||
2711 | if (!bss) | |
2712 | return; | |
2713 | ||
2714 | ieprb = (const u8 *) (bss + 1); | |
2715 | iebcn = ieprb + bss->ie_len; | |
2716 | ||
2717 | if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len)) | |
2718 | wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE"); | |
2719 | else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len)) | |
2720 | wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE"); | |
2721 | #endif /* CONFIG_FST */ | |
2722 | } | |
2723 | ||
2724 | ||
6fc6879b JM |
2725 | static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s, |
2726 | union wpa_event_data *data) | |
2727 | { | |
2728 | u8 bssid[ETH_ALEN]; | |
e07adb7f | 2729 | int ft_completed, already_authorized; |
ce7d0eb1 | 2730 | int new_bss = 0; |
6fc6879b | 2731 | |
1d041bec JM |
2732 | #ifdef CONFIG_AP |
2733 | if (wpa_s->ap_iface) { | |
a01acc50 JM |
2734 | if (!data) |
2735 | return; | |
1d041bec JM |
2736 | hostapd_notif_assoc(wpa_s->ap_iface->bss[0], |
2737 | data->assoc_info.addr, | |
2738 | data->assoc_info.req_ies, | |
39b08b5f SP |
2739 | data->assoc_info.req_ies_len, |
2740 | data->assoc_info.reassoc); | |
1d041bec JM |
2741 | return; |
2742 | } | |
2743 | #endif /* CONFIG_AP */ | |
2744 | ||
9bd566a3 AS |
2745 | eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL); |
2746 | ||
1d041bec | 2747 | ft_completed = wpa_ft_is_completed(wpa_s->wpa); |
579ce771 JM |
2748 | if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0) |
2749 | return; | |
706df429 JM |
2750 | /* |
2751 | * FILS authentication can share the same mechanism to mark the | |
2752 | * connection fully authenticated, so set ft_completed also based on | |
2753 | * FILS result. | |
2754 | */ | |
2755 | if (!ft_completed) | |
2756 | ft_completed = wpa_fils_is_completed(wpa_s->wpa); | |
6fc6879b | 2757 | |
0a0c38f6 MH |
2758 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0) { |
2759 | wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID"); | |
07783eaa | 2760 | wpa_supplicant_deauthenticate( |
0a0c38f6 MH |
2761 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
2762 | return; | |
2763 | } | |
2764 | ||
6fc6879b | 2765 | wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED); |
0a0c38f6 | 2766 | if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) { |
2bbad1c7 MW |
2767 | if (os_reltime_initialized(&wpa_s->session_start)) { |
2768 | os_reltime_age(&wpa_s->session_start, | |
2769 | &wpa_s->session_length); | |
2770 | wpa_s->session_start.sec = 0; | |
2771 | wpa_s->session_start.usec = 0; | |
2772 | wpas_notify_session_length(wpa_s); | |
2773 | } else { | |
2774 | wpas_notify_auth_changed(wpa_s); | |
2775 | os_get_reltime(&wpa_s->session_start); | |
2776 | } | |
f049052b | 2777 | wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID=" |
6fc6879b | 2778 | MACSTR, MAC2STR(bssid)); |
ce7d0eb1 | 2779 | new_bss = 1; |
bbb921da | 2780 | random_add_randomness(bssid, ETH_ALEN); |
6fc6879b JM |
2781 | os_memcpy(wpa_s->bssid, bssid, ETH_ALEN); |
2782 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); | |
e485286c | 2783 | wpas_notify_bssid_changed(wpa_s); |
8bac466b | 2784 | |
6fc6879b JM |
2785 | if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) { |
2786 | wpa_clear_keys(wpa_s, bssid); | |
2787 | } | |
2788 | if (wpa_supplicant_select_config(wpa_s) < 0) { | |
07783eaa | 2789 | wpa_supplicant_deauthenticate( |
6fc6879b JM |
2790 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
2791 | return; | |
2792 | } | |
ce7d0eb1 | 2793 | } |
cd2f4ddf | 2794 | |
ce7d0eb1 SD |
2795 | if (wpa_s->conf->ap_scan == 1 && |
2796 | wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) { | |
2797 | if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss) | |
2798 | wpa_msg(wpa_s, MSG_WARNING, | |
2799 | "WPA/RSN IEs not updated"); | |
6fc6879b JM |
2800 | } |
2801 | ||
ea708118 DL |
2802 | wpas_fst_update_mb_assoc(wpa_s, data); |
2803 | ||
62fa124c JM |
2804 | #ifdef CONFIG_SME |
2805 | os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN); | |
2806 | wpa_s->sme.prev_bssid_set = 1; | |
3302b7c2 | 2807 | wpa_s->sme.last_unprot_disconnect.sec = 0; |
62fa124c JM |
2808 | #endif /* CONFIG_SME */ |
2809 | ||
6fc6879b JM |
2810 | wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid)); |
2811 | if (wpa_s->current_ssid) { | |
2812 | /* When using scanning (ap_scan=1), SIM PC/SC interface can be | |
2813 | * initialized before association, but for other modes, | |
2814 | * initialize PC/SC here, if the current configuration needs | |
2815 | * smartcard or SIM/USIM. */ | |
2816 | wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid); | |
2817 | } | |
2818 | wpa_sm_notify_assoc(wpa_s->wpa, bssid); | |
3f967fe0 JM |
2819 | if (wpa_s->l2) |
2820 | l2_packet_notify_auth_start(wpa_s->l2); | |
6fc6879b | 2821 | |
e07adb7f JM |
2822 | already_authorized = data && data->assoc_info.authorized; |
2823 | ||
6fc6879b JM |
2824 | /* |
2825 | * Set portEnabled first to FALSE in order to get EAP state machine out | |
2826 | * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE | |
2827 | * state machine may transit to AUTHENTICATING state based on obsolete | |
2828 | * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to | |
2829 | * AUTHENTICATED without ever giving chance to EAP state machine to | |
2830 | * reset the state. | |
2831 | */ | |
e07adb7f | 2832 | if (!ft_completed && !already_authorized) { |
6fc6879b JM |
2833 | eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); |
2834 | eapol_sm_notify_portValid(wpa_s->eapol, FALSE); | |
2835 | } | |
a1ea1b45 | 2836 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || |
567da5bb | 2837 | wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || |
a1ea1b45 | 2838 | wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed || |
b0b25c5b | 2839 | already_authorized || wpa_s->drv_authorized_port) |
6fc6879b JM |
2840 | eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); |
2841 | /* 802.1X::portControl = Auto */ | |
2842 | eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE); | |
2843 | wpa_s->eapol_received = 0; | |
2844 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || | |
9c972abb JM |
2845 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE || |
2846 | (wpa_s->current_ssid && | |
f74618cb | 2847 | wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) { |
fb958ea7 JM |
2848 | if (wpa_s->current_ssid && |
2849 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE && | |
6ea1f413 JM |
2850 | (wpa_s->drv_flags & |
2851 | WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) { | |
2852 | /* | |
2853 | * Set the key after having received joined-IBSS event | |
2854 | * from the driver. | |
2855 | */ | |
2856 | wpa_supplicant_set_wpa_none_key(wpa_s, | |
2857 | wpa_s->current_ssid); | |
2858 | } | |
6fc6879b JM |
2859 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
2860 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
2861 | } else if (!ft_completed) { | |
2862 | /* Timeout for receiving the first EAPOL packet */ | |
2863 | wpa_supplicant_req_auth_timeout(wpa_s, 10, 0); | |
2864 | } | |
2865 | wpa_supplicant_cancel_scan(wpa_s); | |
2866 | ||
fe01cd00 AS |
2867 | if (ft_completed) { |
2868 | /* | |
2869 | * FT protocol completed - make sure EAPOL state machine ends | |
2870 | * up in authenticated. | |
2871 | */ | |
2872 | wpa_supplicant_cancel_auth_timeout(wpa_s); | |
2873 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
2874 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
2875 | eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); | |
2876 | } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) && | |
2877 | wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) { | |
6fc6879b JM |
2878 | /* |
2879 | * We are done; the driver will take care of RSN 4-way | |
2880 | * handshake. | |
2881 | */ | |
2882 | wpa_supplicant_cancel_auth_timeout(wpa_s); | |
2883 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
2884 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
2885 | eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); | |
436ee2fd | 2886 | } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) && |
98ea9431 JM |
2887 | wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { |
2888 | /* | |
2889 | * The driver will take care of RSN 4-way handshake, so we need | |
2890 | * to allow EAPOL supplicant to complete its work without | |
2891 | * waiting for WPA supplicant. | |
2892 | */ | |
2893 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
6fc6879b | 2894 | } |
1ff73338 | 2895 | |
3ab35a66 JM |
2896 | wpa_s->last_eapol_matches_bssid = 0; |
2897 | ||
1ff73338 | 2898 | if (wpa_s->pending_eapol_rx) { |
c2be937c JB |
2899 | struct os_reltime now, age; |
2900 | os_get_reltime(&now); | |
2901 | os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age); | |
6a5425fd | 2902 | if (age.sec == 0 && age.usec < 200000 && |
1ff73338 JM |
2903 | os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) == |
2904 | 0) { | |
f049052b BG |
2905 | wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL " |
2906 | "frame that was received just before " | |
2907 | "association notification"); | |
1ff73338 JM |
2908 | wpa_supplicant_rx_eapol( |
2909 | wpa_s, wpa_s->pending_eapol_rx_src, | |
2910 | wpabuf_head(wpa_s->pending_eapol_rx), | |
2911 | wpabuf_len(wpa_s->pending_eapol_rx)); | |
2912 | } | |
2913 | wpabuf_free(wpa_s->pending_eapol_rx); | |
2914 | wpa_s->pending_eapol_rx = NULL; | |
2915 | } | |
60b94c98 | 2916 | |
0194fedb JB |
2917 | if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || |
2918 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) && | |
66562e9c JM |
2919 | wpa_s->current_ssid && |
2920 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) { | |
0194fedb JB |
2921 | /* Set static WEP keys again */ |
2922 | wpa_set_wep_keys(wpa_s, wpa_s->current_ssid); | |
2923 | } | |
50b05780 JM |
2924 | |
2925 | #ifdef CONFIG_IBSS_RSN | |
2926 | if (wpa_s->current_ssid && | |
2927 | wpa_s->current_ssid->mode == WPAS_MODE_IBSS && | |
2928 | wpa_s->key_mgmt != WPA_KEY_MGMT_NONE && | |
78177a00 JM |
2929 | wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE && |
2930 | wpa_s->ibss_rsn == NULL) { | |
6c33ca9f | 2931 | wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid); |
78177a00 JM |
2932 | if (!wpa_s->ibss_rsn) { |
2933 | wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN"); | |
2934 | wpa_supplicant_deauthenticate( | |
2935 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
2936 | return; | |
2937 | } | |
2938 | ||
2939 | ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk); | |
2940 | } | |
50b05780 | 2941 | #endif /* CONFIG_IBSS_RSN */ |
f9f0526b JM |
2942 | |
2943 | wpas_wps_notify_assoc(wpa_s, bssid); | |
a0413b17 MB |
2944 | |
2945 | if (data) { | |
2946 | wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies, | |
2947 | data->assoc_info.resp_ies_len, | |
2948 | &data->assoc_info.wmm_params); | |
8c42b369 EP |
2949 | |
2950 | if (wpa_s->reassoc_same_bss) | |
2951 | wmm_ac_restore_tspecs(wpa_s); | |
a0413b17 | 2952 | } |
bbe7969d VK |
2953 | |
2954 | #ifdef CONFIG_FILS | |
2955 | if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) { | |
2956 | struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, bssid); | |
2957 | const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss); | |
2958 | ||
2959 | if (fils_cache_id) | |
2960 | wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id); | |
2961 | } | |
2962 | #endif /* CONFIG_FILS */ | |
6fc6879b JM |
2963 | } |
2964 | ||
2965 | ||
d00821e9 JM |
2966 | static int disconnect_reason_recoverable(u16 reason_code) |
2967 | { | |
2968 | return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY || | |
2969 | reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA || | |
2970 | reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA; | |
2971 | } | |
2972 | ||
2973 | ||
0544b242 | 2974 | static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s, |
3d9975d5 JM |
2975 | u16 reason_code, |
2976 | int locally_generated) | |
6fc6879b JM |
2977 | { |
2978 | const u8 *bssid; | |
0aadd568 JM |
2979 | |
2980 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { | |
2981 | /* | |
2982 | * At least Host AP driver and a Prism3 card seemed to be | |
2983 | * generating streams of disconnected events when configuring | |
2984 | * IBSS for WPA-None. Ignore them for now. | |
2985 | */ | |
2986 | return; | |
2987 | } | |
2988 | ||
2989 | bssid = wpa_s->bssid; | |
2990 | if (is_zero_ether_addr(bssid)) | |
2991 | bssid = wpa_s->pending_bssid; | |
2992 | ||
2993 | if (!is_zero_ether_addr(bssid) || | |
2994 | wpa_s->wpa_state >= WPA_AUTHENTICATING) { | |
2995 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR | |
2996 | " reason=%d%s", | |
2997 | MAC2STR(bssid), reason_code, | |
2998 | locally_generated ? " locally_generated=1" : ""); | |
2999 | } | |
3000 | } | |
3001 | ||
3002 | ||
c9a82218 JM |
3003 | static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code, |
3004 | int locally_generated) | |
3005 | { | |
3006 | if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE || | |
3007 | !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) | |
3008 | return 0; /* Not in 4-way handshake with PSK */ | |
3009 | ||
3010 | /* | |
3011 | * It looks like connection was lost while trying to go through PSK | |
3012 | * 4-way handshake. Filter out known disconnection cases that are caused | |
3013 | * by something else than PSK mismatch to avoid confusing reports. | |
3014 | */ | |
3015 | ||
3016 | if (locally_generated) { | |
3017 | if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS) | |
3018 | return 0; | |
3019 | } | |
3020 | ||
3021 | return 1; | |
3022 | } | |
3023 | ||
3024 | ||
0aadd568 JM |
3025 | static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s, |
3026 | u16 reason_code, | |
3027 | int locally_generated) | |
3028 | { | |
3029 | const u8 *bssid; | |
6d6f4bb8 JM |
3030 | int authenticating; |
3031 | u8 prev_pending_bssid[ETH_ALEN]; | |
d00821e9 JM |
3032 | struct wpa_bss *fast_reconnect = NULL; |
3033 | struct wpa_ssid *fast_reconnect_ssid = NULL; | |
bcdf2096 | 3034 | struct wpa_ssid *last_ssid; |
1ac38863 | 3035 | struct wpa_bss *curr = NULL; |
6d6f4bb8 JM |
3036 | |
3037 | authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING; | |
3038 | os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN); | |
6fc6879b JM |
3039 | |
3040 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { | |
3041 | /* | |
3042 | * At least Host AP driver and a Prism3 card seemed to be | |
3043 | * generating streams of disconnected events when configuring | |
3044 | * IBSS for WPA-None. Ignore them for now. | |
3045 | */ | |
f049052b BG |
3046 | wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in " |
3047 | "IBSS/WPA-None mode"); | |
6fc6879b JM |
3048 | return; |
3049 | } | |
3050 | ||
1ac38863 DS |
3051 | if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING && |
3052 | reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY && | |
3053 | locally_generated) | |
3054 | /* | |
3055 | * Remove the inactive AP (which is probably out of range) from | |
3056 | * the BSS list after marking disassociation. In particular | |
3057 | * mac80211-based drivers use the | |
3058 | * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in | |
3059 | * locally generated disconnection events for cases where the | |
3060 | * AP does not reply anymore. | |
3061 | */ | |
3062 | curr = wpa_s->current_bss; | |
3063 | ||
c9a82218 | 3064 | if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) { |
6fc6879b JM |
3065 | wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - " |
3066 | "pre-shared key may be incorrect"); | |
5bf9a6c8 JM |
3067 | if (wpas_p2p_4way_hs_failed(wpa_s) > 0) |
3068 | return; /* P2P group removed */ | |
b19c098e | 3069 | wpas_auth_failed(wpa_s, "WRONG_KEY"); |
16ef233b JM |
3070 | #ifdef CONFIG_DPP2 |
3071 | wpas_dpp_send_conn_status_result(wpa_s, | |
3072 | DPP_STATUS_AUTH_FAILURE); | |
3073 | #endif /* CONFIG_DPP2 */ | |
6fc6879b | 3074 | } |
3636b891 JM |
3075 | if (!wpa_s->disconnected && |
3076 | (!wpa_s->auto_reconnect_disabled || | |
6e252b0d | 3077 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS || |
5e238cc6 SD |
3078 | wpas_wps_searching(wpa_s) || |
3079 | wpas_wps_reenable_networks_pending(wpa_s))) { | |
d00821e9 | 3080 | wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to " |
6e252b0d | 3081 | "reconnect (wps=%d/%d wpa_state=%d)", |
f7da5a9e | 3082 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS, |
6e252b0d | 3083 | wpas_wps_searching(wpa_s), |
f7da5a9e | 3084 | wpa_s->wpa_state); |
d00821e9 JM |
3085 | if (wpa_s->wpa_state == WPA_COMPLETED && |
3086 | wpa_s->current_ssid && | |
3087 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA && | |
3d9975d5 | 3088 | !locally_generated && |
d00821e9 JM |
3089 | disconnect_reason_recoverable(reason_code)) { |
3090 | /* | |
3091 | * It looks like the AP has dropped association with | |
3092 | * us, but could allow us to get back in. Try to | |
3093 | * reconnect to the same BSS without full scan to save | |
3094 | * time for some common cases. | |
3095 | */ | |
3096 | fast_reconnect = wpa_s->current_bss; | |
3097 | fast_reconnect_ssid = wpa_s->current_ssid; | |
3098 | } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) | |
0d0a8ca1 | 3099 | wpa_supplicant_req_scan(wpa_s, 0, 100000); |
f7da5a9e JM |
3100 | else |
3101 | wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new " | |
3102 | "immediate scan"); | |
0d0a8ca1 | 3103 | } else { |
d00821e9 | 3104 | wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not " |
f049052b | 3105 | "try to re-connect"); |
0d0a8ca1 AC |
3106 | wpa_s->reassociate = 0; |
3107 | wpa_s->disconnected = 1; | |
0d0f7ecb MS |
3108 | if (!wpa_s->pno) |
3109 | wpa_supplicant_cancel_sched_scan(wpa_s); | |
0d0a8ca1 | 3110 | } |
6fc6879b | 3111 | bssid = wpa_s->bssid; |
a8e16edc | 3112 | if (is_zero_ether_addr(bssid)) |
6fc6879b | 3113 | bssid = wpa_s->pending_bssid; |
56d24b4e JM |
3114 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
3115 | wpas_connection_failed(wpa_s, bssid); | |
6fc6879b | 3116 | wpa_sm_notify_disassoc(wpa_s->wpa); |
0bb1e425 GM |
3117 | if (locally_generated) |
3118 | wpa_s->disconnect_reason = -reason_code; | |
3119 | else | |
3120 | wpa_s->disconnect_reason = reason_code; | |
3121 | wpas_notify_disconnect_reason(wpa_s); | |
6fc6879b | 3122 | if (wpa_supplicant_dynamic_keys(wpa_s)) { |
f049052b | 3123 | wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys"); |
6fc6879b JM |
3124 | wpa_clear_keys(wpa_s, wpa_s->bssid); |
3125 | } | |
bcdf2096 | 3126 | last_ssid = wpa_s->current_ssid; |
6fc6879b | 3127 | wpa_supplicant_mark_disassoc(wpa_s); |
e29853bb | 3128 | |
1ac38863 DS |
3129 | if (curr) |
3130 | wpa_bss_remove(wpa_s, curr, "Connection to AP lost"); | |
3131 | ||
bcdf2096 | 3132 | if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) { |
e29853bb | 3133 | sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid); |
bcdf2096 JM |
3134 | wpa_s->current_ssid = last_ssid; |
3135 | } | |
d00821e9 | 3136 | |
eef7235d JM |
3137 | if (fast_reconnect && |
3138 | !wpas_network_disabled(wpa_s, fast_reconnect_ssid) && | |
3139 | !disallowed_bssid(wpa_s, fast_reconnect->bssid) && | |
3140 | !disallowed_ssid(wpa_s, fast_reconnect->ssid, | |
3141 | fast_reconnect->ssid_len) && | |
dd599908 | 3142 | !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) && |
19677b77 | 3143 | !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) { |
5928411e | 3144 | #ifndef CONFIG_NO_SCAN_PROCESSING |
d00821e9 JM |
3145 | wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS"); |
3146 | if (wpa_supplicant_connect(wpa_s, fast_reconnect, | |
3147 | fast_reconnect_ssid) < 0) { | |
3148 | /* Recover through full scan */ | |
3149 | wpa_supplicant_req_scan(wpa_s, 0, 100000); | |
3150 | } | |
5928411e | 3151 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
eef7235d JM |
3152 | } else if (fast_reconnect) { |
3153 | /* | |
3154 | * Could not reconnect to the same BSS due to network being | |
3155 | * disabled. Use a new scan to match the alternative behavior | |
3156 | * above, i.e., to continue automatic reconnection attempt in a | |
3157 | * way that enforces disabled network rules. | |
3158 | */ | |
3159 | wpa_supplicant_req_scan(wpa_s, 0, 100000); | |
d00821e9 | 3160 | } |
6fc6879b JM |
3161 | } |
3162 | ||
3163 | ||
46690a3b | 3164 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT |
01a17491 | 3165 | void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx) |
46690a3b JM |
3166 | { |
3167 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
3168 | ||
3169 | if (!wpa_s->pending_mic_error_report) | |
3170 | return; | |
3171 | ||
f049052b | 3172 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report"); |
46690a3b JM |
3173 | wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise); |
3174 | wpa_s->pending_mic_error_report = 0; | |
3175 | } | |
3176 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
3177 | ||
3178 | ||
6fc6879b JM |
3179 | static void |
3180 | wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s, | |
3181 | union wpa_event_data *data) | |
3182 | { | |
3183 | int pairwise; | |
6473e5c8 | 3184 | struct os_reltime t; |
6fc6879b JM |
3185 | |
3186 | wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected"); | |
3187 | pairwise = (data && data->michael_mic_failure.unicast); | |
6473e5c8 JB |
3188 | os_get_reltime(&t); |
3189 | if ((wpa_s->last_michael_mic_error.sec && | |
3190 | !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) || | |
46690a3b JM |
3191 | wpa_s->pending_mic_error_report) { |
3192 | if (wpa_s->pending_mic_error_report) { | |
3193 | /* | |
3194 | * Send the pending MIC error report immediately since | |
3195 | * we are going to start countermeasures and AP better | |
3196 | * do the same. | |
3197 | */ | |
3198 | wpa_sm_key_request(wpa_s->wpa, 1, | |
3199 | wpa_s->pending_mic_error_pairwise); | |
3200 | } | |
3201 | ||
3202 | /* Send the new MIC error report immediately since we are going | |
3203 | * to start countermeasures and AP better do the same. | |
3204 | */ | |
3205 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
3206 | ||
6fc6879b JM |
3207 | /* initialize countermeasures */ |
3208 | wpa_s->countermeasures = 1; | |
8945cc45 BM |
3209 | |
3210 | wpa_blacklist_add(wpa_s, wpa_s->bssid); | |
3211 | ||
6fc6879b JM |
3212 | wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started"); |
3213 | ||
3214 | /* | |
3215 | * Need to wait for completion of request frame. We do not get | |
3216 | * any callback for the message completion, so just wait a | |
3217 | * short while and hope for the best. */ | |
3218 | os_sleep(0, 10000); | |
3219 | ||
3220 | wpa_drv_set_countermeasures(wpa_s, 1); | |
3221 | wpa_supplicant_deauthenticate(wpa_s, | |
3222 | WLAN_REASON_MICHAEL_MIC_FAILURE); | |
3223 | eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, | |
3224 | wpa_s, NULL); | |
3225 | eloop_register_timeout(60, 0, | |
3226 | wpa_supplicant_stop_countermeasures, | |
3227 | wpa_s, NULL); | |
3228 | /* TODO: mark the AP rejected for 60 second. STA is | |
3229 | * allowed to associate with another AP.. */ | |
46690a3b JM |
3230 | } else { |
3231 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT | |
3232 | if (wpa_s->mic_errors_seen) { | |
3233 | /* | |
3234 | * Reduce the effectiveness of Michael MIC error | |
3235 | * reports as a means for attacking against TKIP if | |
3236 | * more than one MIC failure is noticed with the same | |
3237 | * PTK. We delay the transmission of the reports by a | |
3238 | * random time between 0 and 60 seconds in order to | |
3239 | * force the attacker wait 60 seconds before getting | |
3240 | * the information on whether a frame resulted in a MIC | |
3241 | * failure. | |
3242 | */ | |
3243 | u8 rval[4]; | |
3244 | int sec; | |
3245 | ||
3246 | if (os_get_random(rval, sizeof(rval)) < 0) | |
3247 | sec = os_random() % 60; | |
3248 | else | |
3249 | sec = WPA_GET_BE32(rval) % 60; | |
f049052b BG |
3250 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error " |
3251 | "report %d seconds", sec); | |
46690a3b JM |
3252 | wpa_s->pending_mic_error_report = 1; |
3253 | wpa_s->pending_mic_error_pairwise = pairwise; | |
3254 | eloop_cancel_timeout( | |
3255 | wpa_supplicant_delayed_mic_error_report, | |
3256 | wpa_s, NULL); | |
3257 | eloop_register_timeout( | |
3258 | sec, os_random() % 1000000, | |
3259 | wpa_supplicant_delayed_mic_error_report, | |
3260 | wpa_s, NULL); | |
3261 | } else { | |
3262 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
3263 | } | |
3264 | #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
3265 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
3266 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
6fc6879b | 3267 | } |
6473e5c8 | 3268 | wpa_s->last_michael_mic_error = t; |
46690a3b | 3269 | wpa_s->mic_errors_seen++; |
6fc6879b JM |
3270 | } |
3271 | ||
3272 | ||
a83d9c96 SL |
3273 | #ifdef CONFIG_TERMINATE_ONLASTIF |
3274 | static int any_interfaces(struct wpa_supplicant *head) | |
3275 | { | |
3276 | struct wpa_supplicant *wpa_s; | |
3277 | ||
3278 | for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next) | |
3279 | if (!wpa_s->interface_removed) | |
3280 | return 1; | |
3281 | return 0; | |
3282 | } | |
3283 | #endif /* CONFIG_TERMINATE_ONLASTIF */ | |
3284 | ||
3285 | ||
6fc6879b JM |
3286 | static void |
3287 | wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s, | |
3288 | union wpa_event_data *data) | |
3289 | { | |
3290 | if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0) | |
3291 | return; | |
3292 | ||
3293 | switch (data->interface_status.ievent) { | |
3294 | case EVENT_INTERFACE_ADDED: | |
3295 | if (!wpa_s->interface_removed) | |
3296 | break; | |
3297 | wpa_s->interface_removed = 0; | |
f049052b | 3298 | wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added"); |
6fc6879b | 3299 | if (wpa_supplicant_driver_init(wpa_s) < 0) { |
f049052b BG |
3300 | wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the " |
3301 | "driver after interface was added"); | |
6fc6879b | 3302 | } |
f43c1ae7 IP |
3303 | |
3304 | #ifdef CONFIG_P2P | |
3305 | if (!wpa_s->global->p2p && | |
3306 | !wpa_s->global->p2p_disabled && | |
3307 | !wpa_s->conf->p2p_disabled && | |
3308 | (wpa_s->drv_flags & | |
3309 | WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) && | |
3310 | wpas_p2p_add_p2pdev_interface( | |
3311 | wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) { | |
3312 | wpa_printf(MSG_INFO, | |
3313 | "P2P: Failed to enable P2P Device interface"); | |
3314 | /* Try to continue without. P2P will be disabled. */ | |
3315 | } | |
3316 | #endif /* CONFIG_P2P */ | |
3317 | ||
6fc6879b JM |
3318 | break; |
3319 | case EVENT_INTERFACE_REMOVED: | |
f049052b | 3320 | wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed"); |
6fc6879b JM |
3321 | wpa_s->interface_removed = 1; |
3322 | wpa_supplicant_mark_disassoc(wpa_s); | |
cb6710a4 | 3323 | wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); |
6fc6879b JM |
3324 | l2_packet_deinit(wpa_s->l2); |
3325 | wpa_s->l2 = NULL; | |
f43c1ae7 IP |
3326 | |
3327 | #ifdef CONFIG_P2P | |
3328 | if (wpa_s->global->p2p && | |
3329 | wpa_s->global->p2p_init_wpa_s->parent == wpa_s && | |
3330 | (wpa_s->drv_flags & | |
3331 | WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) { | |
3332 | wpa_dbg(wpa_s, MSG_DEBUG, | |
3333 | "Removing P2P Device interface"); | |
3334 | wpa_supplicant_remove_iface( | |
3335 | wpa_s->global, wpa_s->global->p2p_init_wpa_s, | |
3336 | 0); | |
3337 | wpa_s->global->p2p_init_wpa_s = NULL; | |
3338 | } | |
3339 | #endif /* CONFIG_P2P */ | |
3340 | ||
2e997eec RM |
3341 | #ifdef CONFIG_MATCH_IFACE |
3342 | if (wpa_s->matched) { | |
3343 | wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0); | |
3344 | break; | |
3345 | } | |
3346 | #endif /* CONFIG_MATCH_IFACE */ | |
3347 | ||
a83d9c96 SL |
3348 | #ifdef CONFIG_TERMINATE_ONLASTIF |
3349 | /* check if last interface */ | |
3350 | if (!any_interfaces(wpa_s->global->ifaces)) | |
3351 | eloop_terminate(); | |
3352 | #endif /* CONFIG_TERMINATE_ONLASTIF */ | |
6fc6879b JM |
3353 | break; |
3354 | } | |
3355 | } | |
3356 | ||
3357 | ||
281ff0aa GP |
3358 | #ifdef CONFIG_TDLS |
3359 | static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s, | |
3360 | union wpa_event_data *data) | |
3361 | { | |
3362 | if (data == NULL) | |
3363 | return; | |
3364 | switch (data->tdls.oper) { | |
3365 | case TDLS_REQUEST_SETUP: | |
3887878e SD |
3366 | wpa_tdls_remove(wpa_s->wpa, data->tdls.peer); |
3367 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) | |
3368 | wpa_tdls_start(wpa_s->wpa, data->tdls.peer); | |
3369 | else | |
3370 | wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer); | |
281ff0aa GP |
3371 | break; |
3372 | case TDLS_REQUEST_TEARDOWN: | |
f130b105 SD |
3373 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
3374 | wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer, | |
3375 | data->tdls.reason_code); | |
3376 | else | |
3377 | wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, | |
3378 | data->tdls.peer); | |
281ff0aa | 3379 | break; |
c10ca2a6 SD |
3380 | case TDLS_REQUEST_DISCOVER: |
3381 | wpa_tdls_send_discovery_request(wpa_s->wpa, | |
3382 | data->tdls.peer); | |
3383 | break; | |
281ff0aa GP |
3384 | } |
3385 | } | |
3386 | #endif /* CONFIG_TDLS */ | |
3387 | ||
3388 | ||
ad3872a3 | 3389 | #ifdef CONFIG_WNM |
75cad1a0 XC |
3390 | static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s, |
3391 | union wpa_event_data *data) | |
3392 | { | |
3393 | if (data == NULL) | |
3394 | return; | |
3395 | switch (data->wnm.oper) { | |
3396 | case WNM_OPER_SLEEP: | |
3397 | wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request " | |
3398 | "(action=%d, intval=%d)", | |
3399 | data->wnm.sleep_action, data->wnm.sleep_intval); | |
3400 | ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action, | |
cd0ef657 | 3401 | data->wnm.sleep_intval, NULL); |
75cad1a0 XC |
3402 | break; |
3403 | } | |
3404 | } | |
ad3872a3 | 3405 | #endif /* CONFIG_WNM */ |
75cad1a0 XC |
3406 | |
3407 | ||
6fc6879b JM |
3408 | #ifdef CONFIG_IEEE80211R |
3409 | static void | |
3410 | wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s, | |
3411 | union wpa_event_data *data) | |
3412 | { | |
3413 | if (data == NULL) | |
3414 | return; | |
3415 | ||
3416 | if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies, | |
3417 | data->ft_ies.ies_len, | |
3418 | data->ft_ies.ft_action, | |
babfbf15 JM |
3419 | data->ft_ies.target_ap, |
3420 | data->ft_ies.ric_ies, | |
3421 | data->ft_ies.ric_ies_len) < 0) { | |
6fc6879b JM |
3422 | /* TODO: prevent MLME/driver from trying to associate? */ |
3423 | } | |
3424 | } | |
3425 | #endif /* CONFIG_IEEE80211R */ | |
3426 | ||
3427 | ||
11ef8d35 JM |
3428 | #ifdef CONFIG_IBSS_RSN |
3429 | static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s, | |
3430 | union wpa_event_data *data) | |
3431 | { | |
df4bc509 | 3432 | struct wpa_ssid *ssid; |
df418245 XC |
3433 | if (wpa_s->wpa_state < WPA_ASSOCIATED) |
3434 | return; | |
11ef8d35 JM |
3435 | if (data == NULL) |
3436 | return; | |
df4bc509 JM |
3437 | ssid = wpa_s->current_ssid; |
3438 | if (ssid == NULL) | |
3439 | return; | |
3440 | if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt)) | |
3441 | return; | |
3442 | ||
11ef8d35 JM |
3443 | ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer); |
3444 | } | |
13adc57b AQ |
3445 | |
3446 | ||
3447 | static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s, | |
3448 | union wpa_event_data *data) | |
3449 | { | |
3450 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
3451 | ||
3452 | if (ssid == NULL) | |
3453 | return; | |
3454 | ||
3455 | /* check if the ssid is correctly configured as IBSS/RSN */ | |
3456 | if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt)) | |
3457 | return; | |
3458 | ||
3459 | ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame, | |
3460 | data->rx_mgmt.frame_len); | |
3461 | } | |
11ef8d35 JM |
3462 | #endif /* CONFIG_IBSS_RSN */ |
3463 | ||
3464 | ||
036f7c4a JM |
3465 | #ifdef CONFIG_IEEE80211R |
3466 | static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data, | |
3467 | size_t len) | |
3468 | { | |
3469 | const u8 *sta_addr, *target_ap_addr; | |
3470 | u16 status; | |
3471 | ||
3472 | wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len); | |
3473 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) | |
3474 | return; /* only SME case supported for now */ | |
3475 | if (len < 1 + 2 * ETH_ALEN + 2) | |
3476 | return; | |
3477 | if (data[0] != 2) | |
3478 | return; /* Only FT Action Response is supported for now */ | |
3479 | sta_addr = data + 1; | |
3480 | target_ap_addr = data + 1 + ETH_ALEN; | |
3481 | status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN); | |
f049052b BG |
3482 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA " |
3483 | MACSTR " TargetAP " MACSTR " status %u", | |
3484 | MAC2STR(sta_addr), MAC2STR(target_ap_addr), status); | |
036f7c4a JM |
3485 | |
3486 | if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) { | |
f049052b BG |
3487 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR |
3488 | " in FT Action Response", MAC2STR(sta_addr)); | |
036f7c4a JM |
3489 | return; |
3490 | } | |
3491 | ||
3492 | if (status) { | |
f049052b BG |
3493 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates " |
3494 | "failure (status code %d)", status); | |
036f7c4a JM |
3495 | /* TODO: report error to FT code(?) */ |
3496 | return; | |
3497 | } | |
3498 | ||
3499 | if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2, | |
3500 | len - (1 + 2 * ETH_ALEN + 2), 1, | |
3501 | target_ap_addr, NULL, 0) < 0) | |
3502 | return; | |
3503 | ||
fe191985 JM |
3504 | #ifdef CONFIG_SME |
3505 | { | |
3506 | struct wpa_bss *bss; | |
3507 | bss = wpa_bss_get_bssid(wpa_s, target_ap_addr); | |
3508 | if (bss) | |
3509 | wpa_s->sme.freq = bss->freq; | |
62c72d72 | 3510 | wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT; |
fe191985 JM |
3511 | sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr, |
3512 | WLAN_AUTH_FT); | |
3513 | } | |
3514 | #endif /* CONFIG_SME */ | |
036f7c4a JM |
3515 | } |
3516 | #endif /* CONFIG_IEEE80211R */ | |
3517 | ||
3518 | ||
7d878ca7 JM |
3519 | static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s, |
3520 | struct unprot_deauth *e) | |
3521 | { | |
7d878ca7 JM |
3522 | wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame " |
3523 | "dropped: " MACSTR " -> " MACSTR | |
3524 | " (reason code %u)", | |
3525 | MAC2STR(e->sa), MAC2STR(e->da), e->reason_code); | |
3526 | sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code); | |
7d878ca7 JM |
3527 | } |
3528 | ||
3529 | ||
3530 | static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s, | |
3531 | struct unprot_disassoc *e) | |
3532 | { | |
7d878ca7 JM |
3533 | wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame " |
3534 | "dropped: " MACSTR " -> " MACSTR | |
3535 | " (reason code %u)", | |
3536 | MAC2STR(e->sa), MAC2STR(e->da), e->reason_code); | |
3537 | sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code); | |
7d878ca7 JM |
3538 | } |
3539 | ||
3540 | ||
d7df0fa7 JM |
3541 | static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr, |
3542 | u16 reason_code, int locally_generated, | |
3543 | const u8 *ie, size_t ie_len, int deauth) | |
3544 | { | |
3545 | #ifdef CONFIG_AP | |
3546 | if (wpa_s->ap_iface && addr) { | |
3547 | hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr); | |
3548 | return; | |
3549 | } | |
3550 | ||
3551 | if (wpa_s->ap_iface) { | |
3552 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode"); | |
3553 | return; | |
3554 | } | |
3555 | #endif /* CONFIG_AP */ | |
3556 | ||
c2805909 JM |
3557 | if (!locally_generated) |
3558 | wpa_s->own_disconnect_req = 0; | |
3559 | ||
d7df0fa7 JM |
3560 | wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated); |
3561 | ||
c60ba9f7 JM |
3562 | if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED || |
3563 | ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) || | |
3564 | (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) && | |
3565 | eapol_sm_failed(wpa_s->eapol))) && | |
3566 | !wpa_s->eap_expected_failure)) | |
b19c098e | 3567 | wpas_auth_failed(wpa_s, "AUTH_FAILED"); |
d7df0fa7 JM |
3568 | |
3569 | #ifdef CONFIG_P2P | |
43ee4704 | 3570 | if (deauth && reason_code > 0) { |
d7df0fa7 JM |
3571 | if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len, |
3572 | locally_generated) > 0) { | |
3573 | /* | |
3574 | * The interface was removed, so cannot continue | |
3575 | * processing any additional operations after this. | |
3576 | */ | |
3577 | return; | |
3578 | } | |
3579 | } | |
3580 | #endif /* CONFIG_P2P */ | |
3581 | ||
3582 | wpa_supplicant_event_disassoc_finish(wpa_s, reason_code, | |
3583 | locally_generated); | |
3584 | } | |
3585 | ||
3586 | ||
3587 | static void wpas_event_disassoc(struct wpa_supplicant *wpa_s, | |
3588 | struct disassoc_info *info) | |
3589 | { | |
3590 | u16 reason_code = 0; | |
3591 | int locally_generated = 0; | |
3592 | const u8 *addr = NULL; | |
3593 | const u8 *ie = NULL; | |
3594 | size_t ie_len = 0; | |
3595 | ||
3596 | wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification"); | |
3597 | ||
3598 | if (info) { | |
3599 | addr = info->addr; | |
3600 | ie = info->ie; | |
3601 | ie_len = info->ie_len; | |
3602 | reason_code = info->reason_code; | |
3603 | locally_generated = info->locally_generated; | |
cfde99a8 AK |
3604 | wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code, |
3605 | reason2str(reason_code), | |
3606 | locally_generated ? " locally_generated=1" : ""); | |
d7df0fa7 JM |
3607 | if (addr) |
3608 | wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR, | |
3609 | MAC2STR(addr)); | |
3610 | wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)", | |
3611 | ie, ie_len); | |
3612 | } | |
3613 | ||
3614 | #ifdef CONFIG_AP | |
3615 | if (wpa_s->ap_iface && info && info->addr) { | |
3616 | hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr); | |
3617 | return; | |
3618 | } | |
3619 | ||
3620 | if (wpa_s->ap_iface) { | |
3621 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode"); | |
3622 | return; | |
3623 | } | |
3624 | #endif /* CONFIG_AP */ | |
3625 | ||
3626 | #ifdef CONFIG_P2P | |
3627 | if (info) { | |
3628 | wpas_p2p_disassoc_notif( | |
3629 | wpa_s, info->addr, reason_code, info->ie, info->ie_len, | |
3630 | locally_generated); | |
3631 | } | |
3632 | #endif /* CONFIG_P2P */ | |
3633 | ||
3634 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) | |
3635 | sme_event_disassoc(wpa_s, info); | |
3636 | ||
3637 | wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated, | |
3638 | ie, ie_len, 0); | |
3639 | } | |
3640 | ||
3641 | ||
3642 | static void wpas_event_deauth(struct wpa_supplicant *wpa_s, | |
3643 | struct deauth_info *info) | |
3644 | { | |
3645 | u16 reason_code = 0; | |
3646 | int locally_generated = 0; | |
3647 | const u8 *addr = NULL; | |
3648 | const u8 *ie = NULL; | |
3649 | size_t ie_len = 0; | |
3650 | ||
3651 | wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification"); | |
3652 | ||
3653 | if (info) { | |
3654 | addr = info->addr; | |
3655 | ie = info->ie; | |
3656 | ie_len = info->ie_len; | |
3657 | reason_code = info->reason_code; | |
3658 | locally_generated = info->locally_generated; | |
cfde99a8 AK |
3659 | wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", |
3660 | reason_code, reason2str(reason_code), | |
3661 | locally_generated ? " locally_generated=1" : ""); | |
d7df0fa7 JM |
3662 | if (addr) { |
3663 | wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR, | |
3664 | MAC2STR(addr)); | |
3665 | } | |
3666 | wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)", | |
3667 | ie, ie_len); | |
3668 | } | |
3669 | ||
3670 | wpa_reset_ft_completed(wpa_s->wpa); | |
3671 | ||
3672 | wpas_event_disconnect(wpa_s, addr, reason_code, | |
3673 | locally_generated, ie, ie_len, 1); | |
3674 | } | |
3675 | ||
3676 | ||
142817b2 JM |
3677 | static const char * reg_init_str(enum reg_change_initiator init) |
3678 | { | |
3679 | switch (init) { | |
3680 | case REGDOM_SET_BY_CORE: | |
3681 | return "CORE"; | |
3682 | case REGDOM_SET_BY_USER: | |
3683 | return "USER"; | |
3684 | case REGDOM_SET_BY_DRIVER: | |
3685 | return "DRIVER"; | |
3686 | case REGDOM_SET_BY_COUNTRY_IE: | |
3687 | return "COUNTRY_IE"; | |
3688 | case REGDOM_BEACON_HINT: | |
3689 | return "BEACON_HINT"; | |
3690 | } | |
3691 | return "?"; | |
3692 | } | |
3693 | ||
3694 | ||
3695 | static const char * reg_type_str(enum reg_type type) | |
3696 | { | |
3697 | switch (type) { | |
3698 | case REGDOM_TYPE_UNKNOWN: | |
3699 | return "UNKNOWN"; | |
3700 | case REGDOM_TYPE_COUNTRY: | |
3701 | return "COUNTRY"; | |
3702 | case REGDOM_TYPE_WORLD: | |
3703 | return "WORLD"; | |
3704 | case REGDOM_TYPE_CUSTOM_WORLD: | |
3705 | return "CUSTOM_WORLD"; | |
3706 | case REGDOM_TYPE_INTERSECTION: | |
3707 | return "INTERSECTION"; | |
3708 | } | |
3709 | return "?"; | |
3710 | } | |
3711 | ||
3712 | ||
32bb47fa JM |
3713 | void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s, |
3714 | struct channel_list_changed *info) | |
731ca636 | 3715 | { |
731ca636 | 3716 | struct wpa_supplicant *ifs; |
aa56e36d | 3717 | u8 dfs_domain; |
731ca636 | 3718 | |
3b11ad34 IP |
3719 | /* |
3720 | * To allow backwards compatibility with higher level layers that | |
3721 | * assumed the REGDOM_CHANGE event is sent over the initially added | |
3722 | * interface. Find the highest parent of this interface and use it to | |
3723 | * send the event. | |
3724 | */ | |
3725 | for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent) | |
3726 | ; | |
3727 | ||
32bb47fa JM |
3728 | if (info) { |
3729 | wpa_msg(ifs, MSG_INFO, | |
3730 | WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s", | |
3731 | reg_init_str(info->initiator), reg_type_str(info->type), | |
3732 | info->alpha2[0] ? " alpha2=" : "", | |
3733 | info->alpha2[0] ? info->alpha2 : ""); | |
3734 | } | |
142817b2 | 3735 | |
731ca636 VKE |
3736 | if (wpa_s->drv_priv == NULL) |
3737 | return; /* Ignore event during drv initialization */ | |
3738 | ||
c67e7e2a JM |
3739 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
3740 | radio_list) { | |
0f4bccdb AN |
3741 | wpa_printf(MSG_DEBUG, "%s: Updating hw mode", |
3742 | ifs->ifname); | |
3743 | free_hw_features(ifs); | |
3744 | ifs->hw.modes = wpa_drv_get_hw_feature_data( | |
aa56e36d | 3745 | ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain); |
6ceea4c3 | 3746 | |
ebf59eb5 AN |
3747 | /* Restart PNO/sched_scan with updated channel list */ |
3748 | if (ifs->pno) { | |
3749 | wpas_stop_pno(ifs); | |
3750 | wpas_start_pno(ifs); | |
3751 | } else if (ifs->sched_scanning && !ifs->pno_sched_pending) { | |
3752 | wpa_dbg(ifs, MSG_DEBUG, | |
3753 | "Channel list changed - restart sched_scan"); | |
3754 | wpas_scan_restart_sched_scan(ifs); | |
3755 | } | |
6ceea4c3 | 3756 | } |
0f4bccdb | 3757 | |
3a8f008a | 3758 | wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER); |
731ca636 VKE |
3759 | } |
3760 | ||
3761 | ||
dbfb8e82 | 3762 | static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s, |
70d1e728 AO |
3763 | const u8 *frame, size_t len, int freq, |
3764 | int rssi) | |
dbfb8e82 | 3765 | { |
70d95373 | 3766 | const struct ieee80211_mgmt *mgmt; |
dbfb8e82 JM |
3767 | const u8 *payload; |
3768 | size_t plen; | |
3769 | u8 category; | |
3770 | ||
3771 | if (len < IEEE80211_HDRLEN + 2) | |
3772 | return; | |
3773 | ||
70d95373 JM |
3774 | mgmt = (const struct ieee80211_mgmt *) frame; |
3775 | payload = frame + IEEE80211_HDRLEN; | |
dbfb8e82 | 3776 | category = *payload++; |
70d95373 | 3777 | plen = len - IEEE80211_HDRLEN - 1; |
dbfb8e82 JM |
3778 | |
3779 | wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR | |
3780 | " Category=%u DataLen=%d freq=%d MHz", | |
3781 | MAC2STR(mgmt->sa), category, (int) plen, freq); | |
3782 | ||
d1f88001 MB |
3783 | if (category == WLAN_ACTION_WMM) { |
3784 | wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen); | |
3785 | return; | |
3786 | } | |
3787 | ||
dbfb8e82 JM |
3788 | #ifdef CONFIG_IEEE80211R |
3789 | if (category == WLAN_ACTION_FT) { | |
3790 | ft_rx_action(wpa_s, payload, plen); | |
3791 | return; | |
3792 | } | |
3793 | #endif /* CONFIG_IEEE80211R */ | |
3794 | ||
dbfb8e82 JM |
3795 | #ifdef CONFIG_SME |
3796 | if (category == WLAN_ACTION_SA_QUERY) { | |
3797 | sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen); | |
3798 | return; | |
3799 | } | |
3800 | #endif /* CONFIG_SME */ | |
dbfb8e82 JM |
3801 | |
3802 | #ifdef CONFIG_WNM | |
3803 | if (mgmt->u.action.category == WLAN_ACTION_WNM) { | |
3804 | ieee802_11_rx_wnm_action(wpa_s, mgmt, len); | |
3805 | return; | |
3806 | } | |
3807 | #endif /* CONFIG_WNM */ | |
3808 | ||
3809 | #ifdef CONFIG_GAS | |
c5a64e2d JM |
3810 | if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC || |
3811 | mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) && | |
dbfb8e82 | 3812 | gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid, |
c5a64e2d | 3813 | mgmt->u.action.category, |
dbfb8e82 JM |
3814 | payload, plen, freq) == 0) |
3815 | return; | |
3816 | #endif /* CONFIG_GAS */ | |
3817 | ||
461d39af JM |
3818 | #ifdef CONFIG_GAS_SERVER |
3819 | if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC || | |
3820 | mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) && | |
3821 | gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid, | |
3822 | mgmt->u.action.category, | |
3823 | payload, plen, freq) == 0) | |
3824 | return; | |
3825 | #endif /* CONFIG_GAS_SERVER */ | |
3826 | ||
dbfb8e82 JM |
3827 | #ifdef CONFIG_TDLS |
3828 | if (category == WLAN_ACTION_PUBLIC && plen >= 4 && | |
3829 | payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) { | |
3830 | wpa_dbg(wpa_s, MSG_DEBUG, | |
3831 | "TDLS: Received Discovery Response from " MACSTR, | |
3832 | MAC2STR(mgmt->sa)); | |
3833 | return; | |
3834 | } | |
3835 | #endif /* CONFIG_TDLS */ | |
3836 | ||
3837 | #ifdef CONFIG_INTERWORKING | |
3838 | if (category == WLAN_ACTION_QOS && plen >= 1 && | |
3839 | payload[0] == QOS_QOS_MAP_CONFIG) { | |
3840 | const u8 *pos = payload + 1; | |
3841 | size_t qlen = plen - 1; | |
3842 | wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from " | |
3843 | MACSTR, MAC2STR(mgmt->sa)); | |
3844 | if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 && | |
3845 | qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET && | |
3846 | pos[1] <= qlen - 2 && pos[1] >= 16) | |
3847 | wpas_qos_map_set(wpa_s, pos + 2, pos[1]); | |
3848 | return; | |
3849 | } | |
3850 | #endif /* CONFIG_INTERWORKING */ | |
3851 | ||
4a742011 DS |
3852 | if (category == WLAN_ACTION_RADIO_MEASUREMENT && |
3853 | payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) { | |
3854 | wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa, | |
b3c148e9 | 3855 | mgmt->da, |
4a742011 DS |
3856 | payload + 1, |
3857 | plen - 1); | |
3858 | return; | |
3859 | } | |
3860 | ||
d89c0701 AK |
3861 | if (category == WLAN_ACTION_RADIO_MEASUREMENT && |
3862 | payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) { | |
3863 | wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1); | |
3864 | return; | |
3865 | } | |
3866 | ||
70d1e728 AO |
3867 | if (category == WLAN_ACTION_RADIO_MEASUREMENT && |
3868 | payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) { | |
3869 | wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa, | |
3870 | payload + 1, plen - 1, | |
3871 | rssi); | |
3872 | return; | |
3873 | } | |
3874 | ||
9fbfd1b0 AN |
3875 | #ifdef CONFIG_FST |
3876 | if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) { | |
3877 | fst_rx_action(wpa_s->fst, mgmt, len); | |
3878 | return; | |
3879 | } | |
3880 | #endif /* CONFIG_FST */ | |
3881 | ||
30d27b04 JM |
3882 | #ifdef CONFIG_DPP |
3883 | if (category == WLAN_ACTION_PUBLIC && plen >= 5 && | |
3884 | payload[0] == WLAN_PA_VENDOR_SPECIFIC && | |
3885 | WPA_GET_BE24(&payload[1]) == OUI_WFA && | |
3886 | payload[4] == DPP_OUI_TYPE) { | |
dc4d271c JM |
3887 | payload++; |
3888 | plen--; | |
30d27b04 JM |
3889 | wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq); |
3890 | return; | |
3891 | } | |
3892 | #endif /* CONFIG_DPP */ | |
3893 | ||
dbfb8e82 JM |
3894 | wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid, |
3895 | category, payload, plen, freq); | |
5f92659d BC |
3896 | if (wpa_s->ifmsh) |
3897 | mesh_mpm_action_rx(wpa_s, mgmt, len); | |
dbfb8e82 JM |
3898 | } |
3899 | ||
3900 | ||
253f2e37 AH |
3901 | static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s, |
3902 | union wpa_event_data *event) | |
3903 | { | |
253f2e37 AH |
3904 | struct wpa_freq_range_list *list; |
3905 | char *str = NULL; | |
3906 | ||
3907 | list = &event->freq_range; | |
3908 | ||
3909 | if (list->num) | |
3910 | str = freq_range_list_str(list); | |
3911 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s", | |
3912 | str ? str : ""); | |
3913 | ||
3914 | #ifdef CONFIG_P2P | |
3915 | if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) { | |
3916 | wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range", | |
3917 | __func__); | |
3918 | } else { | |
3919 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event"); | |
253f2e37 | 3920 | |
a7160f7e IP |
3921 | /* |
3922 | * The update channel flow will also take care of moving a GO | |
3923 | * from the unsafe frequency if needed. | |
3924 | */ | |
3a8f008a IP |
3925 | wpas_p2p_update_channel_list(wpa_s, |
3926 | WPAS_P2P_CHANNEL_UPDATE_AVOID); | |
253f2e37 AH |
3927 | } |
3928 | #endif /* CONFIG_P2P */ | |
3929 | ||
3930 | os_free(str); | |
3931 | } | |
3932 | ||
3933 | ||
b8e88d35 | 3934 | static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s) |
b41f2684 | 3935 | { |
b41f2684 CL |
3936 | if (wpa_s->wpa_state == WPA_ASSOCIATED) { |
3937 | wpa_supplicant_cancel_auth_timeout(wpa_s); | |
3938 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
3939 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
3940 | eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); | |
b0b25c5b | 3941 | wpa_s->drv_authorized_port = 1; |
b41f2684 | 3942 | } |
b8e88d35 AS |
3943 | } |
3944 | ||
3945 | ||
37547ad6 DL |
3946 | static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s, |
3947 | int freq) | |
3948 | { | |
3949 | size_t i; | |
3950 | int j; | |
3951 | ||
3952 | for (i = 0; i < wpa_s->hw.num_modes; i++) { | |
3953 | const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i]; | |
3954 | ||
3955 | for (j = 0; j < mode->num_channels; j++) { | |
3956 | const struct hostapd_channel_data *chan; | |
3957 | ||
3958 | chan = &mode->channels[j]; | |
3959 | if (chan->freq == freq) | |
3960 | return chan->dfs_cac_ms; | |
3961 | } | |
3962 | } | |
3963 | ||
3964 | return 0; | |
3965 | } | |
3966 | ||
3967 | ||
3968 | static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s, | |
3969 | struct dfs_event *radar) | |
3970 | { | |
3971 | #if defined(NEED_AP_MLME) && defined(CONFIG_AP) | |
0332c27e | 3972 | if (wpa_s->ap_iface || wpa_s->ifmsh) { |
37547ad6 DL |
3973 | wpas_ap_event_dfs_cac_started(wpa_s, radar); |
3974 | } else | |
3975 | #endif /* NEED_AP_MLME && CONFIG_AP */ | |
3976 | { | |
3977 | unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq); | |
3978 | ||
3979 | cac_time /= 1000; /* convert from ms to sec */ | |
3980 | if (!cac_time) | |
3981 | cac_time = 10 * 60; /* max timeout: 10 minutes */ | |
3982 | ||
3983 | /* Restart auth timeout: CAC time added to initial timeout */ | |
3984 | wpas_auth_timeout_restart(wpa_s, cac_time); | |
3985 | } | |
3986 | } | |
3987 | ||
3988 | ||
3989 | static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s, | |
3990 | struct dfs_event *radar) | |
3991 | { | |
3992 | #if defined(NEED_AP_MLME) && defined(CONFIG_AP) | |
0332c27e | 3993 | if (wpa_s->ap_iface || wpa_s->ifmsh) { |
37547ad6 DL |
3994 | wpas_ap_event_dfs_cac_finished(wpa_s, radar); |
3995 | } else | |
3996 | #endif /* NEED_AP_MLME && CONFIG_AP */ | |
3997 | { | |
3998 | /* Restart auth timeout with original value after CAC is | |
3999 | * finished */ | |
4000 | wpas_auth_timeout_restart(wpa_s, 0); | |
4001 | } | |
4002 | } | |
4003 | ||
4004 | ||
4005 | static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s, | |
4006 | struct dfs_event *radar) | |
4007 | { | |
4008 | #if defined(NEED_AP_MLME) && defined(CONFIG_AP) | |
0332c27e | 4009 | if (wpa_s->ap_iface || wpa_s->ifmsh) { |
37547ad6 DL |
4010 | wpas_ap_event_dfs_cac_aborted(wpa_s, radar); |
4011 | } else | |
4012 | #endif /* NEED_AP_MLME && CONFIG_AP */ | |
4013 | { | |
4014 | /* Restart auth timeout with original value after CAC is | |
4015 | * aborted */ | |
4016 | wpas_auth_timeout_restart(wpa_s, 0); | |
4017 | } | |
4018 | } | |
4019 | ||
4020 | ||
b8e88d35 AS |
4021 | static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s, |
4022 | union wpa_event_data *data) | |
4023 | { | |
4024 | wpa_dbg(wpa_s, MSG_DEBUG, | |
4025 | "Connection authorized by device, previous state %d", | |
4026 | wpa_s->wpa_state); | |
4027 | ||
4028 | wpa_supplicant_event_port_authorized(wpa_s); | |
4029 | ||
b0a21e22 | 4030 | wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr); |
b41f2684 | 4031 | wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck, |
98cd3d1c JM |
4032 | data->assoc_info.ptk_kck_len, |
4033 | data->assoc_info.ptk_kek, | |
4034 | data->assoc_info.ptk_kek_len); | |
01ef320f VK |
4035 | #ifdef CONFIG_FILS |
4036 | if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) { | |
f705f41b VK |
4037 | struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid); |
4038 | const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss); | |
4039 | ||
01ef320f VK |
4040 | /* Update ERP next sequence number */ |
4041 | eapol_sm_update_erp_next_seq_num( | |
4042 | wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num); | |
f705f41b VK |
4043 | |
4044 | if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) { | |
4045 | /* Add the new PMK and PMKID to the PMKSA cache */ | |
4046 | wpa_sm_pmksa_cache_add(wpa_s->wpa, | |
4047 | data->assoc_info.fils_pmk, | |
4048 | data->assoc_info.fils_pmk_len, | |
4049 | data->assoc_info.fils_pmkid, | |
4050 | wpa_s->bssid, fils_cache_id); | |
4051 | } else if (data->assoc_info.fils_pmkid) { | |
4052 | /* Update the current PMKSA used for this connection */ | |
4053 | pmksa_cache_set_current(wpa_s->wpa, | |
4054 | data->assoc_info.fils_pmkid, | |
852b2f27 | 4055 | NULL, NULL, 0, NULL, 0); |
f705f41b | 4056 | } |
01ef320f | 4057 | } |
01ef320f | 4058 | #endif /* CONFIG_FILS */ |
b41f2684 CL |
4059 | } |
4060 | ||
4061 | ||
0cc41ee6 JM |
4062 | static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s, |
4063 | union wpa_event_data *data) | |
4064 | { | |
4065 | const u8 *bssid = data->assoc_reject.bssid; | |
a8391db7 AB |
4066 | #ifdef CONFIG_MBO |
4067 | struct wpa_bss *reject_bss; | |
4068 | #endif /* CONFIG_MBO */ | |
0cc41ee6 JM |
4069 | |
4070 | if (!bssid || is_zero_ether_addr(bssid)) | |
4071 | bssid = wpa_s->pending_bssid; | |
a8391db7 AB |
4072 | #ifdef CONFIG_MBO |
4073 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) | |
4074 | reject_bss = wpa_s->current_bss; | |
4075 | else | |
4076 | reject_bss = wpa_bss_get_bssid(wpa_s, bssid); | |
4077 | #endif /* CONFIG_MBO */ | |
0cc41ee6 JM |
4078 | |
4079 | if (data->assoc_reject.bssid) | |
4080 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT | |
4081 | "bssid=" MACSTR " status_code=%u%s%s%s", | |
4082 | MAC2STR(data->assoc_reject.bssid), | |
4083 | data->assoc_reject.status_code, | |
4084 | data->assoc_reject.timed_out ? " timeout" : "", | |
4085 | data->assoc_reject.timeout_reason ? "=" : "", | |
4086 | data->assoc_reject.timeout_reason ? | |
4087 | data->assoc_reject.timeout_reason : ""); | |
4088 | else | |
4089 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT | |
4090 | "status_code=%u%s%s%s", | |
4091 | data->assoc_reject.status_code, | |
4092 | data->assoc_reject.timed_out ? " timeout" : "", | |
4093 | data->assoc_reject.timeout_reason ? "=" : "", | |
4094 | data->assoc_reject.timeout_reason ? | |
4095 | data->assoc_reject.timeout_reason : ""); | |
4096 | wpa_s->assoc_status_code = data->assoc_reject.status_code; | |
4097 | wpas_notify_assoc_status_code(wpa_s); | |
4098 | ||
4099 | #ifdef CONFIG_OWE | |
4100 | if (data->assoc_reject.status_code == | |
4101 | WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED && | |
4102 | wpa_s->key_mgmt == WPA_KEY_MGMT_OWE && | |
4103 | wpa_s->current_ssid && | |
4104 | wpa_s->current_ssid->owe_group == 0 && | |
4105 | wpa_s->last_owe_group != 21) { | |
4106 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
4107 | struct wpa_bss *bss = wpa_s->current_bss; | |
4108 | ||
4109 | if (!bss) { | |
4110 | bss = wpa_supplicant_get_new_bss(wpa_s, bssid); | |
ffff7f70 JM |
4111 | if (!bss) { |
4112 | wpas_connection_failed(wpa_s, bssid); | |
4113 | wpa_supplicant_mark_disassoc(wpa_s); | |
0cc41ee6 | 4114 | return; |
ffff7f70 | 4115 | } |
0cc41ee6 JM |
4116 | } |
4117 | wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group"); | |
4118 | wpas_connect_work_done(wpa_s); | |
4119 | wpa_supplicant_mark_disassoc(wpa_s); | |
4120 | wpa_supplicant_connect(wpa_s, bss, ssid); | |
4121 | return; | |
4122 | } | |
4123 | #endif /* CONFIG_OWE */ | |
4124 | ||
19677b77 BL |
4125 | #ifdef CONFIG_MBO |
4126 | if (data->assoc_reject.status_code == | |
4127 | WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS && | |
a8391db7 | 4128 | reject_bss && data->assoc_reject.resp_ies) { |
19677b77 BL |
4129 | const u8 *rssi_rej; |
4130 | ||
4131 | rssi_rej = mbo_get_attr_from_ies( | |
4132 | data->assoc_reject.resp_ies, | |
4133 | data->assoc_reject.resp_ies_len, | |
4134 | OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT); | |
4135 | if (rssi_rej && rssi_rej[1] == 2) { | |
4136 | wpa_printf(MSG_DEBUG, | |
4137 | "OCE: RSSI-based association rejection from " | |
4138 | MACSTR " (Delta RSSI: %u, Retry Delay: %u)", | |
a8391db7 | 4139 | MAC2STR(reject_bss->bssid), |
19677b77 BL |
4140 | rssi_rej[2], rssi_rej[3]); |
4141 | wpa_bss_tmp_disallow(wpa_s, | |
a8391db7 | 4142 | reject_bss->bssid, |
19677b77 | 4143 | rssi_rej[3], |
a8391db7 | 4144 | rssi_rej[2] + reject_bss->level); |
19677b77 BL |
4145 | } |
4146 | } | |
4147 | #endif /* CONFIG_MBO */ | |
4148 | ||
0cc41ee6 JM |
4149 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) { |
4150 | sme_event_assoc_reject(wpa_s, data); | |
4151 | return; | |
4152 | } | |
4153 | ||
4154 | /* Driver-based SME cases */ | |
4155 | ||
4156 | #ifdef CONFIG_SAE | |
4157 | if (wpa_s->current_ssid && | |
4158 | wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) && | |
4159 | !data->assoc_reject.timed_out) { | |
4160 | wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry"); | |
4161 | wpa_sm_aborted_cached(wpa_s->wpa); | |
4162 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid); | |
4163 | } | |
4164 | #endif /* CONFIG_SAE */ | |
4165 | ||
50b77f50 SD |
4166 | #ifdef CONFIG_DPP |
4167 | if (wpa_s->current_ssid && | |
4168 | wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP && | |
4169 | !data->assoc_reject.timed_out) { | |
4170 | wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry"); | |
4171 | wpa_sm_aborted_cached(wpa_s->wpa); | |
4172 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid); | |
4173 | } | |
4174 | #endif /* CONFIG_DPP */ | |
4175 | ||
0cc41ee6 JM |
4176 | #ifdef CONFIG_FILS |
4177 | /* Update ERP next sequence number */ | |
af835d75 | 4178 | if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) { |
0cc41ee6 JM |
4179 | eapol_sm_update_erp_next_seq_num( |
4180 | wpa_s->eapol, | |
4181 | data->assoc_reject.fils_erp_next_seq_num); | |
af835d75 AB |
4182 | fils_connection_failure(wpa_s); |
4183 | } | |
0cc41ee6 JM |
4184 | #endif /* CONFIG_FILS */ |
4185 | ||
4186 | wpas_connection_failed(wpa_s, bssid); | |
4187 | wpa_supplicant_mark_disassoc(wpa_s); | |
4188 | } | |
4189 | ||
4190 | ||
9646a8ab | 4191 | void wpa_supplicant_event(void *ctx, enum wpa_event_type event, |
6fc6879b JM |
4192 | union wpa_event_data *data) |
4193 | { | |
4194 | struct wpa_supplicant *wpa_s = ctx; | |
02e122a9 | 4195 | int resched; |
3d1d4691 JM |
4196 | #ifndef CONFIG_NO_STDOUT_DEBUG |
4197 | int level = MSG_DEBUG; | |
4198 | #endif /* CONFIG_NO_STDOUT_DEBUG */ | |
6fc6879b | 4199 | |
8401a6b0 JM |
4200 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED && |
4201 | event != EVENT_INTERFACE_ENABLED && | |
9b6f44cb | 4202 | event != EVENT_INTERFACE_STATUS && |
1446afc8 | 4203 | event != EVENT_SCAN_RESULTS && |
9b6f44cb | 4204 | event != EVENT_SCHED_SCAN_STOPPED) { |
6c3771d7 BG |
4205 | wpa_dbg(wpa_s, MSG_DEBUG, |
4206 | "Ignore event %s (%d) while interface is disabled", | |
4207 | event_to_string(event), event); | |
8401a6b0 JM |
4208 | return; |
4209 | } | |
4210 | ||
74781dfc | 4211 | #ifndef CONFIG_NO_STDOUT_DEBUG |
eab6f5e0 | 4212 | if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) { |
74781dfc JM |
4213 | const struct ieee80211_hdr *hdr; |
4214 | u16 fc; | |
4215 | hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame; | |
4216 | fc = le_to_host16(hdr->frame_control); | |
4217 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | |
4218 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) | |
4219 | level = MSG_EXCESSIVE; | |
4220 | } | |
4221 | ||
4222 | wpa_dbg(wpa_s, level, "Event %s (%d) received", | |
6c3771d7 | 4223 | event_to_string(event), event); |
74781dfc | 4224 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
9b7124b2 | 4225 | |
6fc6879b | 4226 | switch (event) { |
c2a04078 | 4227 | case EVENT_AUTH: |
ea708118 | 4228 | #ifdef CONFIG_FST |
58059e6c JM |
4229 | if (!wpas_fst_update_mbie(wpa_s, data->auth.ies, |
4230 | data->auth.ies_len)) | |
4231 | wpa_printf(MSG_DEBUG, | |
4232 | "FST: MB IEs updated from auth IE"); | |
ea708118 | 4233 | #endif /* CONFIG_FST */ |
c2a04078 | 4234 | sme_event_auth(wpa_s, data); |
38b405c8 AK |
4235 | wpa_s->auth_status_code = data->auth.status_code; |
4236 | wpas_notify_auth_status_code(wpa_s); | |
c2a04078 | 4237 | break; |
6fc6879b | 4238 | case EVENT_ASSOC: |
02adead5 MK |
4239 | #ifdef CONFIG_TESTING_OPTIONS |
4240 | if (wpa_s->ignore_auth_resp) { | |
4241 | wpa_printf(MSG_INFO, | |
4242 | "EVENT_ASSOC - ignore_auth_resp active!"); | |
4243 | break; | |
4244 | } | |
daa40960 JM |
4245 | if (wpa_s->testing_resend_assoc) { |
4246 | wpa_printf(MSG_INFO, | |
4247 | "EVENT_DEAUTH - testing_resend_assoc"); | |
4248 | break; | |
4249 | } | |
02adead5 | 4250 | #endif /* CONFIG_TESTING_OPTIONS */ |
6fc6879b | 4251 | wpa_supplicant_event_assoc(wpa_s, data); |
698c9e20 | 4252 | wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS; |
da143f7f JM |
4253 | if (data && |
4254 | (data->assoc_info.authorized || | |
4255 | (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && | |
4256 | wpa_fils_is_completed(wpa_s->wpa)))) | |
b41f2684 | 4257 | wpa_supplicant_event_assoc_auth(wpa_s, data); |
f32227ed RJ |
4258 | if (data) { |
4259 | wpa_msg(wpa_s, MSG_INFO, | |
4260 | WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u", | |
4261 | data->assoc_info.subnet_status); | |
4262 | } | |
6fc6879b JM |
4263 | break; |
4264 | case EVENT_DISASSOC: | |
d7df0fa7 JM |
4265 | wpas_event_disassoc(wpa_s, |
4266 | data ? &data->disassoc_info : NULL); | |
4267 | break; | |
a84ed99e | 4268 | case EVENT_DEAUTH: |
02adead5 MK |
4269 | #ifdef CONFIG_TESTING_OPTIONS |
4270 | if (wpa_s->ignore_auth_resp) { | |
4271 | wpa_printf(MSG_INFO, | |
4272 | "EVENT_DEAUTH - ignore_auth_resp active!"); | |
4273 | break; | |
4274 | } | |
daa40960 JM |
4275 | if (wpa_s->testing_resend_assoc) { |
4276 | wpa_printf(MSG_INFO, | |
4277 | "EVENT_DEAUTH - testing_resend_assoc"); | |
4278 | break; | |
4279 | } | |
02adead5 | 4280 | #endif /* CONFIG_TESTING_OPTIONS */ |
d7df0fa7 JM |
4281 | wpas_event_deauth(wpa_s, |
4282 | data ? &data->deauth_info : NULL); | |
6fc6879b JM |
4283 | break; |
4284 | case EVENT_MICHAEL_MIC_FAILURE: | |
4285 | wpa_supplicant_event_michael_mic_failure(wpa_s, data); | |
4286 | break; | |
4287 | #ifndef CONFIG_NO_SCAN_PROCESSING | |
a5f40eff | 4288 | case EVENT_SCAN_STARTED: |
adcd7c4b KV |
4289 | if (wpa_s->own_scan_requested || |
4290 | (data && !data->scan_info.external_scan)) { | |
dc3906cb JM |
4291 | struct os_reltime diff; |
4292 | ||
adcd7c4b | 4293 | os_get_reltime(&wpa_s->scan_start_time); |
dc3906cb JM |
4294 | os_reltime_sub(&wpa_s->scan_start_time, |
4295 | &wpa_s->scan_trigger_time, &diff); | |
4296 | wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds", | |
4297 | diff.sec, diff.usec); | |
a5f40eff JM |
4298 | wpa_s->own_scan_requested = 0; |
4299 | wpa_s->own_scan_running = 1; | |
d81c73be JM |
4300 | if (wpa_s->last_scan_req == MANUAL_SCAN_REQ && |
4301 | wpa_s->manual_scan_use_id) { | |
abc05534 DS |
4302 | wpa_msg_ctrl(wpa_s, MSG_INFO, |
4303 | WPA_EVENT_SCAN_STARTED "id=%u", | |
4304 | wpa_s->manual_scan_id); | |
d81c73be | 4305 | } else { |
abc05534 DS |
4306 | wpa_msg_ctrl(wpa_s, MSG_INFO, |
4307 | WPA_EVENT_SCAN_STARTED); | |
d81c73be | 4308 | } |
a5f40eff JM |
4309 | } else { |
4310 | wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan"); | |
d90bfa97 | 4311 | wpa_s->radio->external_scan_running = 1; |
abc05534 | 4312 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED); |
a5f40eff JM |
4313 | } |
4314 | break; | |
6fc6879b | 4315 | case EVENT_SCAN_RESULTS: |
1446afc8 IP |
4316 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
4317 | wpa_s->scan_res_handler = NULL; | |
4318 | wpa_s->own_scan_running = 0; | |
4319 | wpa_s->radio->external_scan_running = 0; | |
4320 | wpa_s->last_scan_req = NORMAL_SCAN_REQ; | |
4321 | break; | |
4322 | } | |
4323 | ||
adcd7c4b KV |
4324 | if (!(data && data->scan_info.external_scan) && |
4325 | os_reltime_initialized(&wpa_s->scan_start_time)) { | |
dc3906cb JM |
4326 | struct os_reltime now, diff; |
4327 | os_get_reltime(&now); | |
4328 | os_reltime_sub(&now, &wpa_s->scan_start_time, &diff); | |
4329 | wpa_s->scan_start_time.sec = 0; | |
4330 | wpa_s->scan_start_time.usec = 0; | |
4331 | wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds", | |
4332 | diff.sec, diff.usec); | |
4333 | } | |
b0e669be JM |
4334 | if (wpa_supplicant_event_scan_results(wpa_s, data)) |
4335 | break; /* interface may have been removed */ | |
adcd7c4b KV |
4336 | if (!(data && data->scan_info.external_scan)) |
4337 | wpa_s->own_scan_running = 0; | |
4338 | if (data && data->scan_info.nl_scan_event) | |
4339 | wpa_s->radio->external_scan_running = 0; | |
6428d0a7 | 4340 | radio_work_check_next(wpa_s); |
6fc6879b JM |
4341 | break; |
4342 | #endif /* CONFIG_NO_SCAN_PROCESSING */ | |
4343 | case EVENT_ASSOCINFO: | |
4344 | wpa_supplicant_event_associnfo(wpa_s, data); | |
4345 | break; | |
4346 | case EVENT_INTERFACE_STATUS: | |
4347 | wpa_supplicant_event_interface_status(wpa_s, data); | |
4348 | break; | |
4349 | case EVENT_PMKID_CANDIDATE: | |
4350 | wpa_supplicant_event_pmkid_candidate(wpa_s, data); | |
4351 | break; | |
281ff0aa GP |
4352 | #ifdef CONFIG_TDLS |
4353 | case EVENT_TDLS: | |
4354 | wpa_supplicant_event_tdls(wpa_s, data); | |
4355 | break; | |
4356 | #endif /* CONFIG_TDLS */ | |
ad3872a3 | 4357 | #ifdef CONFIG_WNM |
75cad1a0 XC |
4358 | case EVENT_WNM: |
4359 | wpa_supplicant_event_wnm(wpa_s, data); | |
4360 | break; | |
ad3872a3 | 4361 | #endif /* CONFIG_WNM */ |
6fc6879b JM |
4362 | #ifdef CONFIG_IEEE80211R |
4363 | case EVENT_FT_RESPONSE: | |
4364 | wpa_supplicant_event_ft_response(wpa_s, data); | |
4365 | break; | |
4366 | #endif /* CONFIG_IEEE80211R */ | |
11ef8d35 JM |
4367 | #ifdef CONFIG_IBSS_RSN |
4368 | case EVENT_IBSS_RSN_START: | |
4369 | wpa_supplicant_event_ibss_rsn_start(wpa_s, data); | |
4370 | break; | |
4371 | #endif /* CONFIG_IBSS_RSN */ | |
efa46078 | 4372 | case EVENT_ASSOC_REJECT: |
0cc41ee6 | 4373 | wpas_event_assoc_reject(wpa_s, data); |
efa46078 | 4374 | break; |
da1fb17c | 4375 | case EVENT_AUTH_TIMED_OUT: |
9a700ff9 JM |
4376 | /* It is possible to get this event from earlier connection */ |
4377 | if (wpa_s->current_ssid && | |
4378 | wpa_s->current_ssid->mode == WPAS_MODE_MESH) { | |
4379 | wpa_dbg(wpa_s, MSG_DEBUG, | |
4380 | "Ignore AUTH_TIMED_OUT in mesh configuration"); | |
4381 | break; | |
4382 | } | |
ea78c315 JM |
4383 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
4384 | sme_event_auth_timed_out(wpa_s, data); | |
da1fb17c JM |
4385 | break; |
4386 | case EVENT_ASSOC_TIMED_OUT: | |
9a700ff9 JM |
4387 | /* It is possible to get this event from earlier connection */ |
4388 | if (wpa_s->current_ssid && | |
4389 | wpa_s->current_ssid->mode == WPAS_MODE_MESH) { | |
4390 | wpa_dbg(wpa_s, MSG_DEBUG, | |
4391 | "Ignore ASSOC_TIMED_OUT in mesh configuration"); | |
4392 | break; | |
4393 | } | |
ea78c315 JM |
4394 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
4395 | sme_event_assoc_timed_out(wpa_s, data); | |
da1fb17c | 4396 | break; |
f8b1f695 | 4397 | case EVENT_TX_STATUS: |
f049052b BG |
4398 | wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR |
4399 | " type=%d stype=%d", | |
4400 | MAC2STR(data->tx_status.dst), | |
4401 | data->tx_status.type, data->tx_status.stype); | |
24f6497c | 4402 | #ifdef CONFIG_AP |
9bae1be0 | 4403 | if (wpa_s->ap_iface == NULL) { |
24f6497c | 4404 | #ifdef CONFIG_OFFCHANNEL |
9bae1be0 JM |
4405 | if (data->tx_status.type == WLAN_FC_TYPE_MGMT && |
4406 | data->tx_status.stype == WLAN_FC_STYPE_ACTION) | |
24f6497c | 4407 | offchannel_send_action_tx_status( |
9bae1be0 JM |
4408 | wpa_s, data->tx_status.dst, |
4409 | data->tx_status.data, | |
4410 | data->tx_status.data_len, | |
93b7ddd0 | 4411 | data->tx_status.ack ? |
24f6497c JM |
4412 | OFFCHANNEL_SEND_ACTION_SUCCESS : |
4413 | OFFCHANNEL_SEND_ACTION_NO_ACK); | |
4414 | #endif /* CONFIG_OFFCHANNEL */ | |
9bae1be0 JM |
4415 | break; |
4416 | } | |
24f6497c JM |
4417 | #endif /* CONFIG_AP */ |
4418 | #ifdef CONFIG_OFFCHANNEL | |
f049052b | 4419 | wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst=" |
a26c9c2e | 4420 | MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst)); |
9bae1be0 JM |
4421 | /* |
4422 | * Catch TX status events for Action frames we sent via group | |
a26c9c2e LD |
4423 | * interface in GO mode, or via standalone AP interface. |
4424 | * Note, wpa_s->p2pdev will be the same as wpa_s->parent, | |
4425 | * except when the primary interface is used as a GO interface | |
4426 | * (for drivers which do not have group interface concurrency) | |
9bae1be0 JM |
4427 | */ |
4428 | if (data->tx_status.type == WLAN_FC_TYPE_MGMT && | |
4429 | data->tx_status.stype == WLAN_FC_STYPE_ACTION && | |
a26c9c2e | 4430 | os_memcmp(wpa_s->p2pdev->pending_action_dst, |
9bae1be0 | 4431 | data->tx_status.dst, ETH_ALEN) == 0) { |
24f6497c | 4432 | offchannel_send_action_tx_status( |
a26c9c2e | 4433 | wpa_s->p2pdev, data->tx_status.dst, |
9bae1be0 JM |
4434 | data->tx_status.data, |
4435 | data->tx_status.data_len, | |
1d39378a | 4436 | data->tx_status.ack ? |
24f6497c JM |
4437 | OFFCHANNEL_SEND_ACTION_SUCCESS : |
4438 | OFFCHANNEL_SEND_ACTION_NO_ACK); | |
f8b1f695 | 4439 | break; |
9bae1be0 | 4440 | } |
24f6497c JM |
4441 | #endif /* CONFIG_OFFCHANNEL */ |
4442 | #ifdef CONFIG_AP | |
f8b1f695 JM |
4443 | switch (data->tx_status.type) { |
4444 | case WLAN_FC_TYPE_MGMT: | |
4445 | ap_mgmt_tx_cb(wpa_s, data->tx_status.data, | |
4446 | data->tx_status.data_len, | |
4447 | data->tx_status.stype, | |
4448 | data->tx_status.ack); | |
4449 | break; | |
4450 | case WLAN_FC_TYPE_DATA: | |
4451 | ap_tx_status(wpa_s, data->tx_status.dst, | |
4452 | data->tx_status.data, | |
4453 | data->tx_status.data_len, | |
4454 | data->tx_status.ack); | |
4455 | break; | |
4456 | } | |
24f6497c | 4457 | #endif /* CONFIG_AP */ |
f8b1f695 | 4458 | break; |
24f6497c | 4459 | #ifdef CONFIG_AP |
dd840f79 JB |
4460 | case EVENT_EAPOL_TX_STATUS: |
4461 | ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst, | |
4462 | data->eapol_tx_status.data, | |
4463 | data->eapol_tx_status.data_len, | |
4464 | data->eapol_tx_status.ack); | |
4465 | break; | |
bcf24348 JB |
4466 | case EVENT_DRIVER_CLIENT_POLL_OK: |
4467 | ap_client_poll_ok(wpa_s, data->client_poll.addr); | |
4468 | break; | |
f8b1f695 JM |
4469 | case EVENT_RX_FROM_UNKNOWN: |
4470 | if (wpa_s->ap_iface == NULL) | |
4471 | break; | |
9b90955e JB |
4472 | ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr, |
4473 | data->rx_from_unknown.wds); | |
f8b1f695 | 4474 | break; |
d57e0617 | 4475 | #endif /* CONFIG_AP */ |
95f556f3 OD |
4476 | |
4477 | case EVENT_CH_SWITCH_STARTED: | |
1b487b8b | 4478 | case EVENT_CH_SWITCH: |
61f121d9 | 4479 | if (!data || !wpa_s->current_ssid) |
1b487b8b | 4480 | break; |
1b487b8b | 4481 | |
95f556f3 OD |
4482 | wpa_msg(wpa_s, MSG_INFO, |
4483 | "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d", | |
4484 | event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH : | |
4485 | WPA_EVENT_CHANNEL_SWITCH_STARTED, | |
37fd0be2 JM |
4486 | data->ch_switch.freq, |
4487 | data->ch_switch.ht_enabled, | |
4488 | data->ch_switch.ch_offset, | |
4489 | channel_width_to_string(data->ch_switch.ch_width), | |
4490 | data->ch_switch.cf1, | |
4491 | data->ch_switch.cf2); | |
95f556f3 OD |
4492 | if (event == EVENT_CH_SWITCH_STARTED) |
4493 | break; | |
37fd0be2 | 4494 | |
61f121d9 IP |
4495 | wpa_s->assoc_freq = data->ch_switch.freq; |
4496 | wpa_s->current_ssid->frequency = data->ch_switch.freq; | |
4497 | ||
d57e0617 | 4498 | #ifdef CONFIG_AP |
61f121d9 IP |
4499 | if (wpa_s->current_ssid->mode == WPAS_MODE_AP || |
4500 | wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO || | |
0332c27e | 4501 | wpa_s->current_ssid->mode == WPAS_MODE_MESH || |
61f121d9 IP |
4502 | wpa_s->current_ssid->mode == |
4503 | WPAS_MODE_P2P_GROUP_FORMATION) { | |
4504 | wpas_ap_ch_switch(wpa_s, data->ch_switch.freq, | |
4505 | data->ch_switch.ht_enabled, | |
4506 | data->ch_switch.ch_offset, | |
4507 | data->ch_switch.ch_width, | |
4508 | data->ch_switch.cf1, | |
95f556f3 OD |
4509 | data->ch_switch.cf2, |
4510 | 1); | |
61f121d9 | 4511 | } |
d57e0617 | 4512 | #endif /* CONFIG_AP */ |
3bafb0d8 | 4513 | |
f91e68e9 | 4514 | sme_event_ch_switch(wpa_s); |
3bafb0d8 | 4515 | wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS); |
d514b502 | 4516 | wnm_clear_coloc_intf_reporting(wpa_s); |
1b487b8b | 4517 | break; |
d57e0617 | 4518 | #ifdef CONFIG_AP |
bd0f68c4 AK |
4519 | #ifdef NEED_AP_MLME |
4520 | case EVENT_DFS_RADAR_DETECTED: | |
4521 | if (data) | |
2dd5fbbf DL |
4522 | wpas_ap_event_dfs_radar_detected(wpa_s, |
4523 | &data->dfs_event); | |
bd0f68c4 | 4524 | break; |
37547ad6 DL |
4525 | case EVENT_DFS_NOP_FINISHED: |
4526 | if (data) | |
4527 | wpas_ap_event_dfs_cac_nop_finished(wpa_s, | |
4528 | &data->dfs_event); | |
4529 | break; | |
4530 | #endif /* NEED_AP_MLME */ | |
4531 | #endif /* CONFIG_AP */ | |
bd0f68c4 AK |
4532 | case EVENT_DFS_CAC_STARTED: |
4533 | if (data) | |
37547ad6 | 4534 | wpas_event_dfs_cac_started(wpa_s, &data->dfs_event); |
bd0f68c4 AK |
4535 | break; |
4536 | case EVENT_DFS_CAC_FINISHED: | |
4537 | if (data) | |
37547ad6 | 4538 | wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event); |
bd0f68c4 AK |
4539 | break; |
4540 | case EVENT_DFS_CAC_ABORTED: | |
4541 | if (data) | |
37547ad6 | 4542 | wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event); |
bd0f68c4 | 4543 | break; |
2d43d37f JB |
4544 | case EVENT_RX_MGMT: { |
4545 | u16 fc, stype; | |
4546 | const struct ieee80211_mgmt *mgmt; | |
4547 | ||
60b893df JM |
4548 | #ifdef CONFIG_TESTING_OPTIONS |
4549 | if (wpa_s->ext_mgmt_frame_handling) { | |
4550 | struct rx_mgmt *rx = &data->rx_mgmt; | |
4551 | size_t hex_len = 2 * rx->frame_len + 1; | |
4552 | char *hex = os_malloc(hex_len); | |
4553 | if (hex) { | |
4554 | wpa_snprintf_hex(hex, hex_len, | |
4555 | rx->frame, rx->frame_len); | |
4556 | wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s", | |
4557 | rx->freq, rx->datarate, rx->ssi_signal, | |
4558 | hex); | |
4559 | os_free(hex); | |
4560 | } | |
4561 | break; | |
4562 | } | |
4563 | #endif /* CONFIG_TESTING_OPTIONS */ | |
4564 | ||
2d43d37f JB |
4565 | mgmt = (const struct ieee80211_mgmt *) |
4566 | data->rx_mgmt.frame; | |
4567 | fc = le_to_host16(mgmt->frame_control); | |
4568 | stype = WLAN_FC_GET_STYPE(fc); | |
4569 | ||
13adc57b | 4570 | #ifdef CONFIG_AP |
9bae1be0 | 4571 | if (wpa_s->ap_iface == NULL) { |
13adc57b | 4572 | #endif /* CONFIG_AP */ |
9bae1be0 | 4573 | #ifdef CONFIG_P2P |
9bae1be0 | 4574 | if (stype == WLAN_FC_STYPE_PROBE_REQ && |
c01120a0 | 4575 | data->rx_mgmt.frame_len > IEEE80211_HDRLEN) { |
9bae1be0 | 4576 | const u8 *src = mgmt->sa; |
c01120a0 JM |
4577 | const u8 *ie; |
4578 | size_t ie_len; | |
4579 | ||
4580 | ie = data->rx_mgmt.frame + IEEE80211_HDRLEN; | |
4581 | ie_len = data->rx_mgmt.frame_len - | |
4582 | IEEE80211_HDRLEN; | |
baf513d6 JB |
4583 | wpas_p2p_probe_req_rx( |
4584 | wpa_s, src, mgmt->da, | |
4585 | mgmt->bssid, ie, ie_len, | |
734ddf61 | 4586 | data->rx_mgmt.freq, |
baf513d6 | 4587 | data->rx_mgmt.ssi_signal); |
9bae1be0 JM |
4588 | break; |
4589 | } | |
4590 | #endif /* CONFIG_P2P */ | |
13adc57b | 4591 | #ifdef CONFIG_IBSS_RSN |
5f92659d BC |
4592 | if (wpa_s->current_ssid && |
4593 | wpa_s->current_ssid->mode == WPAS_MODE_IBSS && | |
4594 | stype == WLAN_FC_STYPE_AUTH && | |
13adc57b AQ |
4595 | data->rx_mgmt.frame_len >= 30) { |
4596 | wpa_supplicant_event_ibss_auth(wpa_s, data); | |
4597 | break; | |
4598 | } | |
4599 | #endif /* CONFIG_IBSS_RSN */ | |
dbfb8e82 JM |
4600 | |
4601 | if (stype == WLAN_FC_STYPE_ACTION) { | |
4602 | wpas_event_rx_mgmt_action( | |
70d95373 JM |
4603 | wpa_s, data->rx_mgmt.frame, |
4604 | data->rx_mgmt.frame_len, | |
70d1e728 AO |
4605 | data->rx_mgmt.freq, |
4606 | data->rx_mgmt.ssi_signal); | |
dbfb8e82 JM |
4607 | break; |
4608 | } | |
4609 | ||
5f92659d BC |
4610 | if (wpa_s->ifmsh) { |
4611 | mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt); | |
4612 | break; | |
4613 | } | |
4614 | ||
5ff39c13 SD |
4615 | #ifdef CONFIG_SAE |
4616 | if (stype == WLAN_FC_STYPE_AUTH && | |
4617 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && | |
4618 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) { | |
4619 | sme_external_auth_mgmt_rx( | |
4620 | wpa_s, data->rx_mgmt.frame, | |
4621 | data->rx_mgmt.frame_len); | |
4622 | break; | |
4623 | } | |
4624 | #endif /* CONFIG_SAE */ | |
f049052b BG |
4625 | wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received " |
4626 | "management frame in non-AP mode"); | |
f8b1f695 | 4627 | break; |
13adc57b | 4628 | #ifdef CONFIG_AP |
9bae1be0 | 4629 | } |
2d43d37f JB |
4630 | |
4631 | if (stype == WLAN_FC_STYPE_PROBE_REQ && | |
c01120a0 JM |
4632 | data->rx_mgmt.frame_len > IEEE80211_HDRLEN) { |
4633 | const u8 *ie; | |
4634 | size_t ie_len; | |
4635 | ||
4636 | ie = data->rx_mgmt.frame + IEEE80211_HDRLEN; | |
4637 | ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN; | |
2d43d37f JB |
4638 | |
4639 | wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da, | |
4640 | mgmt->bssid, ie, ie_len, | |
4641 | data->rx_mgmt.ssi_signal); | |
2d43d37f JB |
4642 | } |
4643 | ||
2a8b7416 | 4644 | ap_mgmt_rx(wpa_s, &data->rx_mgmt); |
13adc57b | 4645 | #endif /* CONFIG_AP */ |
f8b1f695 | 4646 | break; |
2d43d37f | 4647 | } |
e67b55fb | 4648 | case EVENT_RX_PROBE_REQ: |
b211f3eb JM |
4649 | if (data->rx_probe_req.sa == NULL || |
4650 | data->rx_probe_req.ie == NULL) | |
4651 | break; | |
e67b55fb JM |
4652 | #ifdef CONFIG_AP |
4653 | if (wpa_s->ap_iface) { | |
4654 | hostapd_probe_req_rx(wpa_s->ap_iface->bss[0], | |
4655 | data->rx_probe_req.sa, | |
04a85e44 JM |
4656 | data->rx_probe_req.da, |
4657 | data->rx_probe_req.bssid, | |
e67b55fb | 4658 | data->rx_probe_req.ie, |
baf513d6 JB |
4659 | data->rx_probe_req.ie_len, |
4660 | data->rx_probe_req.ssi_signal); | |
e67b55fb JM |
4661 | break; |
4662 | } | |
4663 | #endif /* CONFIG_AP */ | |
e67b55fb | 4664 | wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa, |
04a85e44 JM |
4665 | data->rx_probe_req.da, |
4666 | data->rx_probe_req.bssid, | |
e67b55fb | 4667 | data->rx_probe_req.ie, |
baf513d6 | 4668 | data->rx_probe_req.ie_len, |
734ddf61 | 4669 | 0, |
baf513d6 | 4670 | data->rx_probe_req.ssi_signal); |
036f7c4a | 4671 | break; |
9bae1be0 | 4672 | case EVENT_REMAIN_ON_CHANNEL: |
24f6497c JM |
4673 | #ifdef CONFIG_OFFCHANNEL |
4674 | offchannel_remain_on_channel_cb( | |
4675 | wpa_s, data->remain_on_channel.freq, | |
4676 | data->remain_on_channel.duration); | |
4677 | #endif /* CONFIG_OFFCHANNEL */ | |
9bae1be0 JM |
4678 | wpas_p2p_remain_on_channel_cb( |
4679 | wpa_s, data->remain_on_channel.freq, | |
4680 | data->remain_on_channel.duration); | |
4681 | break; | |
4682 | case EVENT_CANCEL_REMAIN_ON_CHANNEL: | |
24f6497c JM |
4683 | #ifdef CONFIG_OFFCHANNEL |
4684 | offchannel_cancel_remain_on_channel_cb( | |
4685 | wpa_s, data->remain_on_channel.freq); | |
4686 | #endif /* CONFIG_OFFCHANNEL */ | |
9bae1be0 JM |
4687 | wpas_p2p_cancel_remain_on_channel_cb( |
4688 | wpa_s, data->remain_on_channel.freq); | |
30d27b04 JM |
4689 | #ifdef CONFIG_DPP |
4690 | wpas_dpp_cancel_remain_on_channel_cb( | |
4691 | wpa_s, data->remain_on_channel.freq); | |
4692 | #endif /* CONFIG_DPP */ | |
9bae1be0 | 4693 | break; |
a8e0505b JM |
4694 | case EVENT_EAPOL_RX: |
4695 | wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src, | |
4696 | data->eapol_rx.data, | |
4697 | data->eapol_rx.data_len); | |
4698 | break; | |
e2f74005 | 4699 | case EVENT_SIGNAL_CHANGE: |
0cd86028 JM |
4700 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE |
4701 | "above=%d signal=%d noise=%d txrate=%d", | |
4702 | data->signal_change.above_threshold, | |
4703 | data->signal_change.current_signal, | |
4704 | data->signal_change.current_noise, | |
4705 | data->signal_change.current_txrate); | |
71d77adb MM |
4706 | wpa_bss_update_level(wpa_s->current_bss, |
4707 | data->signal_change.current_signal); | |
e2f74005 | 4708 | bgscan_notify_signal_change( |
60a972a6 | 4709 | wpa_s, data->signal_change.above_threshold, |
174fa789 PS |
4710 | data->signal_change.current_signal, |
4711 | data->signal_change.current_noise, | |
4712 | data->signal_change.current_txrate); | |
e2f74005 | 4713 | break; |
77a020a1 BG |
4714 | case EVENT_INTERFACE_MAC_CHANGED: |
4715 | wpa_supplicant_update_mac_addr(wpa_s); | |
4716 | break; | |
8401a6b0 | 4717 | case EVENT_INTERFACE_ENABLED: |
f049052b | 4718 | wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled"); |
8401a6b0 | 4719 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
bfba8deb | 4720 | wpa_supplicant_update_mac_addr(wpa_s); |
3263fca2 | 4721 | wpa_supplicant_set_default_scan_ies(wpa_s); |
782e2f78 IP |
4722 | if (wpa_s->p2p_mgmt) { |
4723 | wpa_supplicant_set_state(wpa_s, | |
4724 | WPA_DISCONNECTED); | |
4725 | break; | |
4726 | } | |
4727 | ||
199716ad | 4728 | #ifdef CONFIG_AP |
9919f7a2 JB |
4729 | if (!wpa_s->ap_iface) { |
4730 | wpa_supplicant_set_state(wpa_s, | |
4731 | WPA_DISCONNECTED); | |
635874b5 | 4732 | wpa_s->scan_req = NORMAL_SCAN_REQ; |
9919f7a2 JB |
4733 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
4734 | } else | |
4735 | wpa_supplicant_set_state(wpa_s, | |
4736 | WPA_COMPLETED); | |
199716ad BG |
4737 | #else /* CONFIG_AP */ |
4738 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | |
4739 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
4740 | #endif /* CONFIG_AP */ | |
8401a6b0 JM |
4741 | } |
4742 | break; | |
4743 | case EVENT_INTERFACE_DISABLED: | |
f049052b | 4744 | wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled"); |
6f72577f IP |
4745 | #ifdef CONFIG_P2P |
4746 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO || | |
4747 | (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group && | |
4748 | wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) { | |
635874b5 JM |
4749 | /* |
4750 | * Mark interface disabled if this happens to end up not | |
4751 | * being removed as a separate P2P group interface. | |
4752 | */ | |
4753 | wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); | |
6f72577f IP |
4754 | /* |
4755 | * The interface was externally disabled. Remove | |
4756 | * it assuming an external entity will start a | |
4757 | * new session if needed. | |
4758 | */ | |
8f2cf379 JM |
4759 | if (wpa_s->current_ssid && |
4760 | wpa_s->current_ssid->p2p_group) | |
4761 | wpas_p2p_interface_unavailable(wpa_s); | |
4762 | else | |
4763 | wpas_p2p_disconnect(wpa_s); | |
635874b5 JM |
4764 | /* |
4765 | * wpa_s instance may have been freed, so must not use | |
4766 | * it here anymore. | |
4767 | */ | |
6f72577f IP |
4768 | break; |
4769 | } | |
c71c2416 JM |
4770 | if (wpa_s->p2p_scan_work && wpa_s->global->p2p && |
4771 | p2p_in_progress(wpa_s->global->p2p) > 1) { | |
4772 | /* This radio work will be cancelled, so clear P2P | |
4773 | * state as well. | |
4774 | */ | |
4775 | p2p_stop_find(wpa_s->global->p2p); | |
4776 | } | |
6f72577f IP |
4777 | #endif /* CONFIG_P2P */ |
4778 | ||
b7a6702f JM |
4779 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) { |
4780 | /* | |
4781 | * Indicate disconnection to keep ctrl_iface events | |
4782 | * consistent. | |
4783 | */ | |
4784 | wpa_supplicant_event_disassoc( | |
4785 | wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1); | |
4786 | } | |
8401a6b0 | 4787 | wpa_supplicant_mark_disassoc(wpa_s); |
14220fe6 | 4788 | wpa_bss_flush(wpa_s); |
b3253ebb AO |
4789 | radio_remove_works(wpa_s, NULL, 0); |
4790 | ||
8401a6b0 JM |
4791 | wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); |
4792 | break; | |
b5c9da8d | 4793 | case EVENT_CHANNEL_LIST_CHANGED: |
142817b2 JM |
4794 | wpa_supplicant_update_channel_list( |
4795 | wpa_s, &data->channel_list_changed); | |
c973f386 JM |
4796 | break; |
4797 | case EVENT_INTERFACE_UNAVAILABLE: | |
c973f386 | 4798 | wpas_p2p_interface_unavailable(wpa_s); |
7cfc4ac3 AGS |
4799 | break; |
4800 | case EVENT_BEST_CHANNEL: | |
f049052b BG |
4801 | wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received " |
4802 | "(%d %d %d)", | |
4803 | data->best_chan.freq_24, data->best_chan.freq_5, | |
4804 | data->best_chan.freq_overall); | |
7cfc4ac3 AGS |
4805 | wpa_s->best_24_freq = data->best_chan.freq_24; |
4806 | wpa_s->best_5_freq = data->best_chan.freq_5; | |
4807 | wpa_s->best_overall_freq = data->best_chan.freq_overall; | |
7cfc4ac3 AGS |
4808 | wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24, |
4809 | data->best_chan.freq_5, | |
4810 | data->best_chan.freq_overall); | |
b5c9da8d | 4811 | break; |
7d878ca7 JM |
4812 | case EVENT_UNPROT_DEAUTH: |
4813 | wpa_supplicant_event_unprot_deauth(wpa_s, | |
4814 | &data->unprot_deauth); | |
4815 | break; | |
4816 | case EVENT_UNPROT_DISASSOC: | |
4817 | wpa_supplicant_event_unprot_disassoc(wpa_s, | |
4818 | &data->unprot_disassoc); | |
4819 | break; | |
0d7e5a3a JB |
4820 | case EVENT_STATION_LOW_ACK: |
4821 | #ifdef CONFIG_AP | |
4822 | if (wpa_s->ap_iface && data) | |
4823 | hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0], | |
4824 | data->low_ack.addr); | |
4825 | #endif /* CONFIG_AP */ | |
8f15f711 AN |
4826 | #ifdef CONFIG_TDLS |
4827 | if (data) | |
947f900f AN |
4828 | wpa_tdls_disable_unreachable_link(wpa_s->wpa, |
4829 | data->low_ack.addr); | |
8f15f711 | 4830 | #endif /* CONFIG_TDLS */ |
0d7e5a3a | 4831 | break; |
ea244d21 XC |
4832 | case EVENT_IBSS_PEER_LOST: |
4833 | #ifdef CONFIG_IBSS_RSN | |
4834 | ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer); | |
4835 | #endif /* CONFIG_IBSS_RSN */ | |
4836 | break; | |
b14a210c JB |
4837 | case EVENT_DRIVER_GTK_REKEY: |
4838 | if (os_memcmp(data->driver_gtk_rekey.bssid, | |
4839 | wpa_s->bssid, ETH_ALEN)) | |
4840 | break; | |
4841 | if (!wpa_s->wpa) | |
4842 | break; | |
4843 | wpa_sm_update_replay_ctr(wpa_s->wpa, | |
4844 | data->driver_gtk_rekey.replay_ctr); | |
4845 | break; | |
cbdf3507 LC |
4846 | case EVENT_SCHED_SCAN_STOPPED: |
4847 | wpa_s->sched_scanning = 0; | |
bef5e9a8 | 4848 | resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s); |
cbdf3507 LC |
4849 | wpa_supplicant_notify_scanning(wpa_s, 0); |
4850 | ||
9b6f44cb JM |
4851 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
4852 | break; | |
4853 | ||
14f34a73 AS |
4854 | /* |
4855 | * If the driver stopped scanning without being requested to, | |
4856 | * request a new scan to continue scanning for networks. | |
4857 | */ | |
4858 | if (!wpa_s->sched_scan_stop_req && | |
4859 | wpa_s->wpa_state == WPA_SCANNING) { | |
4860 | wpa_dbg(wpa_s, MSG_DEBUG, | |
4861 | "Restart scanning after unexpected sched_scan stop event"); | |
4862 | wpa_supplicant_req_scan(wpa_s, 1, 0); | |
4863 | break; | |
4864 | } | |
4865 | ||
4866 | wpa_s->sched_scan_stop_req = 0; | |
4867 | ||
cbdf3507 | 4868 | /* |
cf70d298 RM |
4869 | * Start a new sched scan to continue searching for more SSIDs |
4870 | * either if timed out or PNO schedule scan is pending. | |
cbdf3507 | 4871 | */ |
5e3ddf4d AB |
4872 | if (wpa_s->sched_scan_timed_out) { |
4873 | wpa_supplicant_req_sched_scan(wpa_s); | |
4874 | } else if (wpa_s->pno_sched_pending) { | |
4875 | wpa_s->pno_sched_pending = 0; | |
4876 | wpas_start_pno(wpa_s); | |
02e122a9 DS |
4877 | } else if (resched) { |
4878 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
cf70d298 RM |
4879 | } |
4880 | ||
cbdf3507 | 4881 | break; |
783fcb7d GG |
4882 | case EVENT_WPS_BUTTON_PUSHED: |
4883 | #ifdef CONFIG_WPS | |
83ebf558 | 4884 | wpas_wps_start_pbc(wpa_s, NULL, 0, 0); |
783fcb7d GG |
4885 | #endif /* CONFIG_WPS */ |
4886 | break; | |
253f2e37 AH |
4887 | case EVENT_AVOID_FREQUENCIES: |
4888 | wpa_supplicant_notify_avoid_freq(wpa_s, data); | |
4889 | break; | |
3140803b RM |
4890 | case EVENT_CONNECT_FAILED_REASON: |
4891 | #ifdef CONFIG_AP | |
4892 | if (!wpa_s->ap_iface || !data) | |
4893 | break; | |
4894 | hostapd_event_connect_failed_reason( | |
4895 | wpa_s->ap_iface->bss[0], | |
4896 | data->connect_failed_reason.addr, | |
4897 | data->connect_failed_reason.code); | |
4898 | #endif /* CONFIG_AP */ | |
4899 | break; | |
8319e312 | 4900 | case EVENT_NEW_PEER_CANDIDATE: |
eac02316 MH |
4901 | #ifdef CONFIG_MESH |
4902 | if (!wpa_s->ifmsh || !data) | |
4903 | break; | |
8319e312 TP |
4904 | wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer, |
4905 | data->mesh_peer.ies, | |
4906 | data->mesh_peer.ie_len); | |
eac02316 | 4907 | #endif /* CONFIG_MESH */ |
8319e312 | 4908 | break; |
96bc5086 TB |
4909 | case EVENT_SURVEY: |
4910 | #ifdef CONFIG_AP | |
4911 | if (!wpa_s->ap_iface) | |
4912 | break; | |
4913 | hostapd_event_get_survey(wpa_s->ap_iface, | |
4914 | &data->survey_results); | |
4915 | #endif /* CONFIG_AP */ | |
4916 | break; | |
d9909717 | 4917 | case EVENT_ACS_CHANNEL_SELECTED: |
34e8bfd7 | 4918 | #ifdef CONFIG_AP |
d9909717 TB |
4919 | #ifdef CONFIG_ACS |
4920 | if (!wpa_s->ap_iface) | |
4921 | break; | |
4922 | hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0], | |
4923 | &data->acs_selected_channels); | |
4924 | #endif /* CONFIG_ACS */ | |
34e8bfd7 | 4925 | #endif /* CONFIG_AP */ |
d9909717 | 4926 | break; |
a6f5b193 PX |
4927 | case EVENT_P2P_LO_STOP: |
4928 | #ifdef CONFIG_P2P | |
4929 | wpa_s->p2p_lo_started = 0; | |
4930 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP | |
4931 | P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d", | |
4932 | data->p2p_lo_stop.reason_code); | |
4933 | #endif /* CONFIG_P2P */ | |
4934 | break; | |
0f9b4a0f JM |
4935 | case EVENT_BEACON_LOSS: |
4936 | if (!wpa_s->current_bss || !wpa_s->current_ssid) | |
4937 | break; | |
4938 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS); | |
4939 | bgscan_notify_beacon_loss(wpa_s); | |
4940 | break; | |
5ff39c13 SD |
4941 | case EVENT_EXTERNAL_AUTH: |
4942 | #ifdef CONFIG_SAE | |
4943 | if (!wpa_s->current_ssid) { | |
4944 | wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL"); | |
4945 | break; | |
4946 | } | |
4947 | sme_external_auth_trigger(wpa_s, data); | |
4948 | #endif /* CONFIG_SAE */ | |
4949 | break; | |
b8e88d35 AS |
4950 | case EVENT_PORT_AUTHORIZED: |
4951 | wpa_supplicant_event_port_authorized(wpa_s); | |
4952 | break; | |
ec2b5173 T |
4953 | case EVENT_STATION_OPMODE_CHANGED: |
4954 | #ifdef CONFIG_AP | |
4955 | if (!wpa_s->ap_iface || !data) | |
4956 | break; | |
4957 | ||
4958 | hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0], | |
4959 | data->sta_opmode.addr, | |
4960 | data->sta_opmode.smps_mode, | |
4961 | data->sta_opmode.chan_width, | |
4962 | data->sta_opmode.rx_nss); | |
4963 | #endif /* CONFIG_AP */ | |
4964 | break; | |
6fc6879b | 4965 | default: |
f049052b | 4966 | wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event); |
6fc6879b JM |
4967 | break; |
4968 | } | |
4969 | } | |
45e3fc72 RM |
4970 | |
4971 | ||
4972 | void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event, | |
4973 | union wpa_event_data *data) | |
4974 | { | |
4975 | struct wpa_supplicant *wpa_s; | |
4976 | ||
4977 | if (event != EVENT_INTERFACE_STATUS) | |
4978 | return; | |
4979 | ||
4980 | wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname); | |
4981 | if (wpa_s && wpa_s->driver->get_ifindex) { | |
4982 | unsigned int ifindex; | |
4983 | ||
4984 | ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv); | |
4985 | if (ifindex != data->interface_status.ifindex) { | |
4986 | wpa_dbg(wpa_s, MSG_DEBUG, | |
4987 | "interface status ifindex %d mismatch (%d)", | |
4988 | ifindex, data->interface_status.ifindex); | |
4989 | return; | |
4990 | } | |
4991 | } | |
2e997eec RM |
4992 | #ifdef CONFIG_MATCH_IFACE |
4993 | else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) { | |
4994 | struct wpa_interface *wpa_i; | |
4995 | ||
4996 | wpa_i = wpa_supplicant_match_iface( | |
4997 | ctx, data->interface_status.ifname); | |
4998 | if (!wpa_i) | |
4999 | return; | |
5000 | wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL); | |
5001 | os_free(wpa_i); | |
5002 | if (wpa_s) | |
5003 | wpa_s->matched = 1; | |
5004 | } | |
5005 | #endif /* CONFIG_MATCH_IFACE */ | |
45e3fc72 RM |
5006 | |
5007 | if (wpa_s) | |
5008 | wpa_supplicant_event(wpa_s, event, data); | |
5009 | } |