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