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