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