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