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