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