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