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