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