3 * Copyright (c) 2003-2017, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
8 * This file implements functions for registering and unregistering
9 * %wpa_supplicant interfaces. In addition, this file contains number of
10 * functions for managing network connections.
14 #ifdef CONFIG_MATCH_IFACE
17 #endif /* CONFIG_MATCH_IFACE */
20 #include "crypto/random.h"
21 #include "crypto/sha1.h"
22 #include "eapol_supp/eapol_supp_sm.h"
23 #include "eap_peer/eap.h"
24 #include "eap_peer/eap_proxy.h"
25 #include "eap_server/eap_methods.h"
26 #include "rsn_supp/wpa.h"
29 #include "utils/ext_password.h"
30 #include "l2_packet/l2_packet.h"
31 #include "wpa_supplicant_i.h"
33 #include "ctrl_iface.h"
34 #include "pcsc_funcs.h"
35 #include "common/version.h"
36 #include "rsn_supp/preauth.h"
37 #include "rsn_supp/pmksa_cache.h"
38 #include "common/wpa_ctrl.h"
39 #include "common/ieee802_11_defs.h"
40 #include "common/hw_features_common.h"
43 #include "blacklist.h"
44 #include "wpas_glue.h"
45 #include "wps_supplicant.h"
48 #include "gas_query.h"
50 #include "p2p_supplicant.h"
51 #include "wifi_display.h"
57 #include "offchannel.h"
58 #include "hs20_supplicant.h"
63 const char *const wpa_supplicant_version
=
64 "wpa_supplicant v" VERSION_STR
"\n"
65 "Copyright (c) 2003-2017, Jouni Malinen <j@w1.fi> and contributors";
67 const char *const wpa_supplicant_license
=
68 "This software may be distributed under the terms of the BSD license.\n"
69 "See README for more details.\n"
70 #ifdef EAP_TLS_OPENSSL
71 "\nThis product includes software developed by the OpenSSL Project\n"
72 "for use in the OpenSSL Toolkit (http://www.openssl.org/)\n"
73 #endif /* EAP_TLS_OPENSSL */
76 #ifndef CONFIG_NO_STDOUT_DEBUG
77 /* Long text divided into parts in order to fit in C89 strings size limits. */
78 const char *const wpa_supplicant_full_license1
=
80 const char *const wpa_supplicant_full_license2
=
81 "This software may be distributed under the terms of the BSD license.\n"
83 "Redistribution and use in source and binary forms, with or without\n"
84 "modification, are permitted provided that the following conditions are\n"
87 const char *const wpa_supplicant_full_license3
=
88 "1. Redistributions of source code must retain the above copyright\n"
89 " notice, this list of conditions and the following disclaimer.\n"
91 "2. Redistributions in binary form must reproduce the above copyright\n"
92 " notice, this list of conditions and the following disclaimer in the\n"
93 " documentation and/or other materials provided with the distribution.\n"
95 const char *const wpa_supplicant_full_license4
=
96 "3. Neither the name(s) of the above-listed copyright holder(s) nor the\n"
97 " names of its contributors may be used to endorse or promote products\n"
98 " derived from this software without specific prior written permission.\n"
100 "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n"
101 "\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n"
102 "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n"
103 "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n";
104 const char *const wpa_supplicant_full_license5
=
105 "OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n"
106 "SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n"
107 "LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n"
108 "DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n"
109 "THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n"
110 "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n"
111 "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
113 #endif /* CONFIG_NO_STDOUT_DEBUG */
115 /* Configure default/group WEP keys for static WEP */
116 int wpa_set_wep_keys(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
)
120 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
121 if (ssid
->wep_key_len
[i
] == 0)
125 wpa_drv_set_key(wpa_s
, WPA_ALG_WEP
, NULL
,
126 i
, i
== ssid
->wep_tx_keyidx
, NULL
, 0,
127 ssid
->wep_key
[i
], ssid
->wep_key_len
[i
]);
134 int wpa_supplicant_set_wpa_none_key(struct wpa_supplicant
*wpa_s
,
135 struct wpa_ssid
*ssid
)
143 /* IBSS/WPA-None uses only one key (Group) for both receiving and
144 * sending unicast and multicast packets. */
146 if (ssid
->mode
!= WPAS_MODE_IBSS
) {
147 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Invalid mode %d (not "
148 "IBSS/ad-hoc) for WPA-None", ssid
->mode
);
152 if (!ssid
->psk_set
) {
153 wpa_msg(wpa_s
, MSG_INFO
, "WPA: No PSK configured for "
158 switch (wpa_s
->group_cipher
) {
159 case WPA_CIPHER_CCMP
:
160 os_memcpy(key
, ssid
->psk
, 16);
164 case WPA_CIPHER_GCMP
:
165 os_memcpy(key
, ssid
->psk
, 16);
169 case WPA_CIPHER_TKIP
:
170 /* WPA-None uses the same Michael MIC key for both TX and RX */
171 os_memcpy(key
, ssid
->psk
, 16 + 8);
172 os_memcpy(key
+ 16 + 8, ssid
->psk
+ 16, 8);
177 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Invalid group cipher %d for "
178 "WPA-None", wpa_s
->group_cipher
);
182 /* TODO: should actually remember the previously used seq#, both for TX
183 * and RX from each STA.. */
185 ret
= wpa_drv_set_key(wpa_s
, alg
, NULL
, 0, 1, seq
, 6, key
, keylen
);
186 os_memset(key
, 0, sizeof(key
));
191 static void wpa_supplicant_timeout(void *eloop_ctx
, void *timeout_ctx
)
193 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
194 const u8
*bssid
= wpa_s
->bssid
;
195 if (!is_zero_ether_addr(wpa_s
->pending_bssid
) &&
196 (wpa_s
->wpa_state
== WPA_AUTHENTICATING
||
197 wpa_s
->wpa_state
== WPA_ASSOCIATING
))
198 bssid
= wpa_s
->pending_bssid
;
199 wpa_msg(wpa_s
, MSG_INFO
, "Authentication with " MACSTR
" timed out.",
201 wpa_blacklist_add(wpa_s
, bssid
);
202 wpa_sm_notify_disassoc(wpa_s
->wpa
);
203 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
204 wpa_s
->reassociate
= 1;
207 * If we timed out, the AP or the local radio may be busy.
208 * So, wait a second until scanning again.
210 wpa_supplicant_req_scan(wpa_s
, 1, 0);
215 * wpa_supplicant_req_auth_timeout - Schedule a timeout for authentication
216 * @wpa_s: Pointer to wpa_supplicant data
217 * @sec: Number of seconds after which to time out authentication
218 * @usec: Number of microseconds after which to time out authentication
220 * This function is used to schedule a timeout for the current authentication
223 void wpa_supplicant_req_auth_timeout(struct wpa_supplicant
*wpa_s
,
226 if (wpa_s
->conf
->ap_scan
== 0 &&
227 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
))
230 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setting authentication timeout: %d sec "
231 "%d usec", sec
, usec
);
232 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
233 eloop_register_timeout(sec
, usec
, wpa_supplicant_timeout
, wpa_s
, NULL
);
238 * wpa_supplicant_cancel_auth_timeout - Cancel authentication timeout
239 * @wpa_s: Pointer to wpa_supplicant data
241 * This function is used to cancel authentication timeout scheduled with
242 * wpa_supplicant_req_auth_timeout() and it is called when authentication has
245 void wpa_supplicant_cancel_auth_timeout(struct wpa_supplicant
*wpa_s
)
247 wpa_dbg(wpa_s
, MSG_DEBUG
, "Cancelling authentication timeout");
248 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
249 wpa_blacklist_del(wpa_s
, wpa_s
->bssid
);
254 * wpa_supplicant_initiate_eapol - Configure EAPOL state machine
255 * @wpa_s: Pointer to wpa_supplicant data
257 * This function is used to configure EAPOL state machine based on the selected
258 * authentication mode.
260 void wpa_supplicant_initiate_eapol(struct wpa_supplicant
*wpa_s
)
262 #ifdef IEEE8021X_EAPOL
263 struct eapol_config eapol_conf
;
264 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
266 #ifdef CONFIG_IBSS_RSN
267 if (ssid
->mode
== WPAS_MODE_IBSS
&&
268 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
269 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
) {
271 * RSN IBSS authentication is per-STA and we can disable the
272 * per-BSSID EAPOL authentication.
274 eapol_sm_notify_portControl(wpa_s
->eapol
, ForceAuthorized
);
275 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
276 eapol_sm_notify_eap_fail(wpa_s
->eapol
, FALSE
);
279 #endif /* CONFIG_IBSS_RSN */
281 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
282 eapol_sm_notify_eap_fail(wpa_s
->eapol
, FALSE
);
284 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
285 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
286 eapol_sm_notify_portControl(wpa_s
->eapol
, ForceAuthorized
);
288 eapol_sm_notify_portControl(wpa_s
->eapol
, Auto
);
290 os_memset(&eapol_conf
, 0, sizeof(eapol_conf
));
291 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
292 eapol_conf
.accept_802_1x_keys
= 1;
293 eapol_conf
.required_keys
= 0;
294 if (ssid
->eapol_flags
& EAPOL_FLAG_REQUIRE_KEY_UNICAST
) {
295 eapol_conf
.required_keys
|= EAPOL_REQUIRE_KEY_UNICAST
;
297 if (ssid
->eapol_flags
& EAPOL_FLAG_REQUIRE_KEY_BROADCAST
) {
298 eapol_conf
.required_keys
|=
299 EAPOL_REQUIRE_KEY_BROADCAST
;
302 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
)
303 eapol_conf
.required_keys
= 0;
305 eapol_conf
.fast_reauth
= wpa_s
->conf
->fast_reauth
;
306 eapol_conf
.workaround
= ssid
->eap_workaround
;
307 eapol_conf
.eap_disabled
=
308 !wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) &&
309 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
310 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPS
;
311 eapol_conf
.external_sim
= wpa_s
->conf
->external_sim
;
314 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
315 eapol_conf
.wps
|= EAPOL_LOCAL_WPS_IN_USE
;
316 if (wpa_s
->current_bss
) {
318 ie
= wpa_bss_get_vendor_ie_multi(wpa_s
->current_bss
,
323 EAPOL_PEER_IS_WPS20_AP
;
328 #endif /* CONFIG_WPS */
330 eapol_sm_notify_config(wpa_s
->eapol
, &ssid
->eap
, &eapol_conf
);
333 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
&& ssid
->mka_psk_set
)
334 ieee802_1x_create_preshared_mka(wpa_s
, ssid
);
336 ieee802_1x_alloc_kay_sm(wpa_s
, ssid
);
337 #endif /* CONFIG_MACSEC */
338 #endif /* IEEE8021X_EAPOL */
343 * wpa_supplicant_set_non_wpa_policy - Set WPA parameters to non-WPA mode
344 * @wpa_s: Pointer to wpa_supplicant data
345 * @ssid: Configuration data for the network
347 * This function is used to configure WPA state machine and related parameters
348 * to a mode where WPA is not enabled. This is called as part of the
349 * authentication configuration when the selected network does not use WPA.
351 void wpa_supplicant_set_non_wpa_policy(struct wpa_supplicant
*wpa_s
,
352 struct wpa_ssid
*ssid
)
356 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
357 wpa_s
->key_mgmt
= WPA_KEY_MGMT_WPS
;
358 else if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)
359 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X_NO_WPA
;
361 wpa_s
->key_mgmt
= WPA_KEY_MGMT_NONE
;
362 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
363 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
364 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
365 wpa_s
->pairwise_cipher
= WPA_CIPHER_NONE
;
366 wpa_s
->group_cipher
= WPA_CIPHER_NONE
;
367 wpa_s
->mgmt_group_cipher
= 0;
369 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
370 if (ssid
->wep_key_len
[i
] > 5) {
371 wpa_s
->pairwise_cipher
= WPA_CIPHER_WEP104
;
372 wpa_s
->group_cipher
= WPA_CIPHER_WEP104
;
374 } else if (ssid
->wep_key_len
[i
] > 0) {
375 wpa_s
->pairwise_cipher
= WPA_CIPHER_WEP40
;
376 wpa_s
->group_cipher
= WPA_CIPHER_WEP40
;
381 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_RSN_ENABLED
, 0);
382 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_KEY_MGMT
, wpa_s
->key_mgmt
);
383 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PAIRWISE
,
384 wpa_s
->pairwise_cipher
);
385 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_GROUP
, wpa_s
->group_cipher
);
386 #ifdef CONFIG_IEEE80211W
387 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MGMT_GROUP
,
388 wpa_s
->mgmt_group_cipher
);
389 #endif /* CONFIG_IEEE80211W */
391 pmksa_cache_clear_current(wpa_s
->wpa
);
395 void free_hw_features(struct wpa_supplicant
*wpa_s
)
398 if (wpa_s
->hw
.modes
== NULL
)
401 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
402 os_free(wpa_s
->hw
.modes
[i
].channels
);
403 os_free(wpa_s
->hw
.modes
[i
].rates
);
406 os_free(wpa_s
->hw
.modes
);
407 wpa_s
->hw
.modes
= NULL
;
411 static void free_bss_tmp_disallowed(struct wpa_supplicant
*wpa_s
)
413 struct wpa_bss_tmp_disallowed
*bss
, *prev
;
415 dl_list_for_each_safe(bss
, prev
, &wpa_s
->bss_tmp_disallowed
,
416 struct wpa_bss_tmp_disallowed
, list
) {
417 dl_list_del(&bss
->list
);
423 void wpas_flush_fils_hlp_req(struct wpa_supplicant
*wpa_s
)
425 struct fils_hlp_req
*req
;
427 while ((req
= dl_list_first(&wpa_s
->fils_hlp_req
, struct fils_hlp_req
,
429 dl_list_del(&req
->list
);
430 wpabuf_free(req
->pkt
);
436 static void wpa_supplicant_cleanup(struct wpa_supplicant
*wpa_s
)
440 bgscan_deinit(wpa_s
);
441 autoscan_deinit(wpa_s
);
442 scard_deinit(wpa_s
->scard
);
444 wpa_sm_set_scard_ctx(wpa_s
->wpa
, NULL
);
445 eapol_sm_register_scard_ctx(wpa_s
->eapol
, NULL
);
446 l2_packet_deinit(wpa_s
->l2
);
449 l2_packet_deinit(wpa_s
->l2_br
);
452 #ifdef CONFIG_TESTING_OPTIONS
453 l2_packet_deinit(wpa_s
->l2_test
);
454 wpa_s
->l2_test
= NULL
;
455 #endif /* CONFIG_TESTING_OPTIONS */
457 if (wpa_s
->conf
!= NULL
) {
458 struct wpa_ssid
*ssid
;
459 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
)
460 wpas_notify_network_removed(wpa_s
, ssid
);
463 os_free(wpa_s
->confname
);
464 wpa_s
->confname
= NULL
;
466 os_free(wpa_s
->confanother
);
467 wpa_s
->confanother
= NULL
;
469 wpa_sm_set_eapol(wpa_s
->wpa
, NULL
);
470 eapol_sm_deinit(wpa_s
->eapol
);
473 rsn_preauth_deinit(wpa_s
->wpa
);
476 wpa_tdls_deinit(wpa_s
->wpa
);
477 #endif /* CONFIG_TDLS */
479 wmm_ac_clear_saved_tspecs(wpa_s
);
480 pmksa_candidate_free(wpa_s
->wpa
);
481 wpa_sm_deinit(wpa_s
->wpa
);
483 wpa_blacklist_clear(wpa_s
);
485 wpa_bss_deinit(wpa_s
);
487 wpa_supplicant_cancel_delayed_sched_scan(wpa_s
);
488 wpa_supplicant_cancel_scan(wpa_s
);
489 wpa_supplicant_cancel_auth_timeout(wpa_s
);
490 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
491 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
492 eloop_cancel_timeout(wpa_supplicant_delayed_mic_error_report
,
494 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
496 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
498 wpas_wps_deinit(wpa_s
);
500 wpabuf_free(wpa_s
->pending_eapol_rx
);
501 wpa_s
->pending_eapol_rx
= NULL
;
503 #ifdef CONFIG_IBSS_RSN
504 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
505 wpa_s
->ibss_rsn
= NULL
;
506 #endif /* CONFIG_IBSS_RSN */
511 wpa_supplicant_ap_deinit(wpa_s
);
512 #endif /* CONFIG_AP */
514 wpas_p2p_deinit(wpa_s
);
516 #ifdef CONFIG_OFFCHANNEL
517 offchannel_deinit(wpa_s
);
518 #endif /* CONFIG_OFFCHANNEL */
520 wpa_supplicant_cancel_sched_scan(wpa_s
);
522 os_free(wpa_s
->next_scan_freqs
);
523 wpa_s
->next_scan_freqs
= NULL
;
525 os_free(wpa_s
->manual_scan_freqs
);
526 wpa_s
->manual_scan_freqs
= NULL
;
528 os_free(wpa_s
->manual_sched_scan_freqs
);
529 wpa_s
->manual_sched_scan_freqs
= NULL
;
531 wpas_mac_addr_rand_scan_clear(wpa_s
, MAC_ADDR_RAND_ALL
);
534 * Need to remove any pending gas-query radio work before the
535 * gas_query_deinit() call because gas_query::work has not yet been set
536 * for works that have not been started. gas_query_free() will be unable
537 * to cancel such pending radio works and once the pending gas-query
538 * radio work eventually gets removed, the deinit notification call to
539 * gas_query_start_cb() would result in dereferencing freed memory.
542 radio_remove_works(wpa_s
, "gas-query", 0);
543 gas_query_deinit(wpa_s
->gas
);
546 free_hw_features(wpa_s
);
548 ieee802_1x_dealloc_kay_sm(wpa_s
);
550 os_free(wpa_s
->bssid_filter
);
551 wpa_s
->bssid_filter
= NULL
;
553 os_free(wpa_s
->disallow_aps_bssid
);
554 wpa_s
->disallow_aps_bssid
= NULL
;
555 os_free(wpa_s
->disallow_aps_ssid
);
556 wpa_s
->disallow_aps_ssid
= NULL
;
558 wnm_bss_keep_alive_deinit(wpa_s
);
560 wnm_deallocate_memory(wpa_s
);
561 #endif /* CONFIG_WNM */
563 ext_password_deinit(wpa_s
->ext_pw
);
564 wpa_s
->ext_pw
= NULL
;
566 wpabuf_free(wpa_s
->last_gas_resp
);
567 wpa_s
->last_gas_resp
= NULL
;
568 wpabuf_free(wpa_s
->prev_gas_resp
);
569 wpa_s
->prev_gas_resp
= NULL
;
571 os_free(wpa_s
->last_scan_res
);
572 wpa_s
->last_scan_res
= NULL
;
576 wpa_drv_configure_frame_filters(wpa_s
, 0);
578 #endif /* CONFIG_HS20 */
580 for (i
= 0; i
< NUM_VENDOR_ELEM_FRAMES
; i
++) {
581 wpabuf_free(wpa_s
->vendor_elem
[i
]);
582 wpa_s
->vendor_elem
[i
] = NULL
;
585 wmm_ac_notify_disassoc(wpa_s
);
587 wpa_s
->sched_scan_plans_num
= 0;
588 os_free(wpa_s
->sched_scan_plans
);
589 wpa_s
->sched_scan_plans
= NULL
;
592 wpa_s
->non_pref_chan_num
= 0;
593 os_free(wpa_s
->non_pref_chan
);
594 wpa_s
->non_pref_chan
= NULL
;
595 #endif /* CONFIG_MBO */
597 free_bss_tmp_disallowed(wpa_s
);
599 wpabuf_free(wpa_s
->lci
);
601 wpas_clear_beacon_rep_data(wpa_s
);
603 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
606 struct external_pmksa_cache
*entry
;
608 while ((entry
= dl_list_last(&wpa_s
->mesh_external_pmksa_cache
,
609 struct external_pmksa_cache
,
611 dl_list_del(&entry
->list
);
612 os_free(entry
->pmksa_cache
);
616 #endif /* CONFIG_MESH */
617 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
619 wpas_flush_fils_hlp_req(wpa_s
);
624 * wpa_clear_keys - Clear keys configured for the driver
625 * @wpa_s: Pointer to wpa_supplicant data
626 * @addr: Previously used BSSID or %NULL if not available
628 * This function clears the encryption keys that has been previously configured
631 void wpa_clear_keys(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
635 #ifdef CONFIG_IEEE80211W
637 #else /* CONFIG_IEEE80211W */
639 #endif /* CONFIG_IEEE80211W */
641 /* MLME-DELETEKEYS.request */
642 for (i
= 0; i
< max
; i
++) {
643 if (wpa_s
->keys_cleared
& BIT(i
))
645 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, i
, 0, NULL
, 0,
648 if (!(wpa_s
->keys_cleared
& BIT(0)) && addr
&&
649 !is_zero_ether_addr(addr
)) {
650 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, addr
, 0, 0, NULL
, 0, NULL
,
652 /* MLME-SETPROTECTION.request(None) */
653 wpa_drv_mlme_setprotection(
655 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
656 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
658 wpa_s
->keys_cleared
= (u32
) -1;
663 * wpa_supplicant_state_txt - Get the connection state name as a text string
664 * @state: State (wpa_state; WPA_*)
665 * Returns: The state name as a printable text string
667 const char * wpa_supplicant_state_txt(enum wpa_states state
)
670 case WPA_DISCONNECTED
:
671 return "DISCONNECTED";
674 case WPA_INTERFACE_DISABLED
:
675 return "INTERFACE_DISABLED";
678 case WPA_AUTHENTICATING
:
679 return "AUTHENTICATING";
680 case WPA_ASSOCIATING
:
681 return "ASSOCIATING";
684 case WPA_4WAY_HANDSHAKE
:
685 return "4WAY_HANDSHAKE";
686 case WPA_GROUP_HANDSHAKE
:
687 return "GROUP_HANDSHAKE";
698 static void wpa_supplicant_start_bgscan(struct wpa_supplicant
*wpa_s
)
702 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->bgscan
)
703 name
= wpa_s
->current_ssid
->bgscan
;
705 name
= wpa_s
->conf
->bgscan
;
706 if (name
== NULL
|| name
[0] == '\0')
708 if (wpas_driver_bss_selection(wpa_s
))
710 if (wpa_s
->current_ssid
== wpa_s
->bgscan_ssid
)
713 if (wpa_s
->p2p_group_interface
!= NOT_P2P_GROUP_INTERFACE
)
715 #endif /* CONFIG_P2P */
717 bgscan_deinit(wpa_s
);
718 if (wpa_s
->current_ssid
) {
719 if (bgscan_init(wpa_s
, wpa_s
->current_ssid
, name
)) {
720 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to initialize "
723 * Live without bgscan; it is only used as a roaming
724 * optimization, so the initial connection is not
728 struct wpa_scan_results
*scan_res
;
729 wpa_s
->bgscan_ssid
= wpa_s
->current_ssid
;
730 scan_res
= wpa_supplicant_get_scan_results(wpa_s
, NULL
,
733 bgscan_notify_scan(wpa_s
, scan_res
);
734 wpa_scan_results_free(scan_res
);
738 wpa_s
->bgscan_ssid
= NULL
;
742 static void wpa_supplicant_stop_bgscan(struct wpa_supplicant
*wpa_s
)
744 if (wpa_s
->bgscan_ssid
!= NULL
) {
745 bgscan_deinit(wpa_s
);
746 wpa_s
->bgscan_ssid
= NULL
;
750 #endif /* CONFIG_BGSCAN */
753 static void wpa_supplicant_start_autoscan(struct wpa_supplicant
*wpa_s
)
755 if (autoscan_init(wpa_s
, 0))
756 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to initialize autoscan");
760 static void wpa_supplicant_stop_autoscan(struct wpa_supplicant
*wpa_s
)
762 autoscan_deinit(wpa_s
);
766 void wpa_supplicant_reinit_autoscan(struct wpa_supplicant
*wpa_s
)
768 if (wpa_s
->wpa_state
== WPA_DISCONNECTED
||
769 wpa_s
->wpa_state
== WPA_SCANNING
) {
770 autoscan_deinit(wpa_s
);
771 wpa_supplicant_start_autoscan(wpa_s
);
777 * wpa_supplicant_set_state - Set current connection state
778 * @wpa_s: Pointer to wpa_supplicant data
779 * @state: The new connection state
781 * This function is called whenever the connection state changes, e.g.,
782 * association is completed for WPA/WPA2 4-Way Handshake is started.
784 void wpa_supplicant_set_state(struct wpa_supplicant
*wpa_s
,
785 enum wpa_states state
)
787 enum wpa_states old_state
= wpa_s
->wpa_state
;
789 wpa_dbg(wpa_s
, MSG_DEBUG
, "State: %s -> %s",
790 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
791 wpa_supplicant_state_txt(state
));
793 if (state
== WPA_INTERFACE_DISABLED
) {
794 /* Assure normal scan when interface is restored */
795 wpa_s
->normal_scans
= 0;
798 if (state
== WPA_COMPLETED
) {
799 wpas_connect_work_done(wpa_s
);
800 /* Reinitialize normal_scan counter */
801 wpa_s
->normal_scans
= 0;
806 * P2PS client has to reply to Probe Request frames received on the
807 * group operating channel. Enable Probe Request frame reporting for
808 * P2P connected client in case p2p_cli_probe configuration property is
811 if (wpa_s
->conf
->p2p_cli_probe
&& wpa_s
->current_ssid
&&
812 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
&&
813 wpa_s
->current_ssid
->p2p_group
) {
814 if (state
== WPA_COMPLETED
&& !wpa_s
->p2p_cli_probe
) {
815 wpa_dbg(wpa_s
, MSG_DEBUG
,
816 "P2P: Enable CLI Probe Request RX reporting");
817 wpa_s
->p2p_cli_probe
=
818 wpa_drv_probe_req_report(wpa_s
, 1) >= 0;
819 } else if (state
!= WPA_COMPLETED
&& wpa_s
->p2p_cli_probe
) {
820 wpa_dbg(wpa_s
, MSG_DEBUG
,
821 "P2P: Disable CLI Probe Request RX reporting");
822 wpa_s
->p2p_cli_probe
= 0;
823 wpa_drv_probe_req_report(wpa_s
, 0);
826 #endif /* CONFIG_P2P */
828 if (state
!= WPA_SCANNING
)
829 wpa_supplicant_notify_scanning(wpa_s
, 0);
831 if (state
== WPA_COMPLETED
&& wpa_s
->new_connection
) {
832 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
833 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
834 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
"- Connection to "
835 MACSTR
" completed [id=%d id_str=%s]",
836 MAC2STR(wpa_s
->bssid
),
837 ssid
? ssid
->id
: -1,
838 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
839 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
840 wpas_clear_temp_disabled(wpa_s
, ssid
, 1);
841 wpa_blacklist_clear(wpa_s
);
842 wpa_s
->extra_blacklist_count
= 0;
843 wpa_s
->new_connection
= 0;
844 wpa_drv_set_operstate(wpa_s
, 1);
845 #ifndef IEEE8021X_EAPOL
846 wpa_drv_set_supp_port(wpa_s
, 1);
847 #endif /* IEEE8021X_EAPOL */
848 wpa_s
->after_wps
= 0;
849 wpa_s
->known_wps_freq
= 0;
850 wpas_p2p_completed(wpa_s
);
852 sme_sched_obss_scan(wpa_s
, 1);
853 } else if (state
== WPA_DISCONNECTED
|| state
== WPA_ASSOCIATING
||
854 state
== WPA_ASSOCIATED
) {
855 wpa_s
->new_connection
= 1;
856 wpa_drv_set_operstate(wpa_s
, 0);
857 #ifndef IEEE8021X_EAPOL
858 wpa_drv_set_supp_port(wpa_s
, 0);
859 #endif /* IEEE8021X_EAPOL */
860 sme_sched_obss_scan(wpa_s
, 0);
862 wpa_s
->wpa_state
= state
;
865 if (state
== WPA_COMPLETED
)
866 wpa_supplicant_start_bgscan(wpa_s
);
867 else if (state
< WPA_ASSOCIATED
)
868 wpa_supplicant_stop_bgscan(wpa_s
);
869 #endif /* CONFIG_BGSCAN */
871 if (state
== WPA_AUTHENTICATING
)
872 wpa_supplicant_stop_autoscan(wpa_s
);
874 if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
875 wpa_supplicant_start_autoscan(wpa_s
);
877 if (old_state
>= WPA_ASSOCIATED
&& wpa_s
->wpa_state
< WPA_ASSOCIATED
)
878 wmm_ac_notify_disassoc(wpa_s
);
880 if (wpa_s
->wpa_state
!= old_state
) {
881 wpas_notify_state_changed(wpa_s
, wpa_s
->wpa_state
, old_state
);
884 * Notify the P2P Device interface about a state change in one
887 wpas_p2p_indicate_state_change(wpa_s
);
889 if (wpa_s
->wpa_state
== WPA_COMPLETED
||
890 old_state
== WPA_COMPLETED
)
891 wpas_notify_auth_changed(wpa_s
);
896 void wpa_supplicant_terminate_proc(struct wpa_global
*global
)
900 struct wpa_supplicant
*wpa_s
= global
->ifaces
;
902 struct wpa_supplicant
*next
= wpa_s
->next
;
903 if (wpas_wps_terminate_pending(wpa_s
) == 1)
906 if (wpa_s
->p2p_group_interface
!= NOT_P2P_GROUP_INTERFACE
||
907 (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->p2p_group
))
908 wpas_p2p_disconnect(wpa_s
);
909 #endif /* CONFIG_P2P */
912 #endif /* CONFIG_WPS */
919 static void wpa_supplicant_terminate(int sig
, void *signal_ctx
)
921 struct wpa_global
*global
= signal_ctx
;
922 wpa_supplicant_terminate_proc(global
);
926 void wpa_supplicant_clear_status(struct wpa_supplicant
*wpa_s
)
928 enum wpa_states old_state
= wpa_s
->wpa_state
;
930 wpa_s
->pairwise_cipher
= 0;
931 wpa_s
->group_cipher
= 0;
932 wpa_s
->mgmt_group_cipher
= 0;
934 if (wpa_s
->wpa_state
!= WPA_INTERFACE_DISABLED
)
935 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
937 if (wpa_s
->wpa_state
!= old_state
)
938 wpas_notify_state_changed(wpa_s
, wpa_s
->wpa_state
, old_state
);
943 * wpa_supplicant_reload_configuration - Reload configuration data
944 * @wpa_s: Pointer to wpa_supplicant data
945 * Returns: 0 on success or -1 if configuration parsing failed
947 * This function can be used to request that the configuration data is reloaded
948 * (e.g., after configuration file change). This function is reloading
949 * configuration only for one interface, so this may need to be called multiple
950 * times if %wpa_supplicant is controlling multiple interfaces and all
951 * interfaces need reconfiguration.
953 int wpa_supplicant_reload_configuration(struct wpa_supplicant
*wpa_s
)
955 struct wpa_config
*conf
;
959 if (wpa_s
->confname
== NULL
)
961 conf
= wpa_config_read(wpa_s
->confname
, NULL
);
963 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to parse the configuration "
964 "file '%s' - exiting", wpa_s
->confname
);
967 wpa_config_read(wpa_s
->confanother
, conf
);
969 conf
->changed_parameters
= (unsigned int) -1;
971 reconf_ctrl
= !!conf
->ctrl_interface
!= !!wpa_s
->conf
->ctrl_interface
972 || (conf
->ctrl_interface
&& wpa_s
->conf
->ctrl_interface
&&
973 os_strcmp(conf
->ctrl_interface
,
974 wpa_s
->conf
->ctrl_interface
) != 0);
976 if (reconf_ctrl
&& wpa_s
->ctrl_iface
) {
977 wpa_supplicant_ctrl_iface_deinit(wpa_s
->ctrl_iface
);
978 wpa_s
->ctrl_iface
= NULL
;
981 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
982 if (wpa_s
->current_ssid
) {
983 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
984 wpa_s
->own_disconnect_req
= 1;
985 wpa_supplicant_deauthenticate(wpa_s
,
986 WLAN_REASON_DEAUTH_LEAVING
);
990 * TODO: should notify EAPOL SM about changes in opensc_engine_path,
991 * pkcs11_engine_path, pkcs11_module_path, openssl_ciphers.
993 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
995 * Clear forced success to clear EAP state for next
998 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
1000 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
1001 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
1002 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
1003 wpa_sm_set_fast_reauth(wpa_s
->wpa
, wpa_s
->conf
->fast_reauth
);
1004 rsn_preauth_deinit(wpa_s
->wpa
);
1006 old_ap_scan
= wpa_s
->conf
->ap_scan
;
1007 wpa_config_free(wpa_s
->conf
);
1009 if (old_ap_scan
!= wpa_s
->conf
->ap_scan
)
1010 wpas_notify_ap_scan_changed(wpa_s
);
1013 wpa_s
->ctrl_iface
= wpa_supplicant_ctrl_iface_init(wpa_s
);
1015 wpa_supplicant_update_config(wpa_s
);
1017 wpa_supplicant_clear_status(wpa_s
);
1018 if (wpa_supplicant_enabled_networks(wpa_s
)) {
1019 wpa_s
->reassociate
= 1;
1020 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1022 wpa_dbg(wpa_s
, MSG_DEBUG
, "Reconfiguration completed");
1027 static void wpa_supplicant_reconfig(int sig
, void *signal_ctx
)
1029 struct wpa_global
*global
= signal_ctx
;
1030 struct wpa_supplicant
*wpa_s
;
1031 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
1032 wpa_dbg(wpa_s
, MSG_DEBUG
, "Signal %d received - reconfiguring",
1034 if (wpa_supplicant_reload_configuration(wpa_s
) < 0) {
1035 wpa_supplicant_terminate_proc(global
);
1039 if (wpa_debug_reopen_file() < 0) {
1040 /* Ignore errors since we cannot really do much to fix this */
1041 wpa_printf(MSG_DEBUG
, "Could not reopen debug log file");
1046 static int wpa_supplicant_suites_from_ai(struct wpa_supplicant
*wpa_s
,
1047 struct wpa_ssid
*ssid
,
1048 struct wpa_ie_data
*ie
)
1050 int ret
= wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, ie
);
1053 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Failed to parse WPA IE "
1054 "from association info");
1059 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Using WPA IE from AssocReq to set "
1061 if (!(ie
->group_cipher
& ssid
->group_cipher
)) {
1062 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled group "
1063 "cipher 0x%x (mask 0x%x) - reject",
1064 ie
->group_cipher
, ssid
->group_cipher
);
1067 if (!(ie
->pairwise_cipher
& ssid
->pairwise_cipher
)) {
1068 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled pairwise "
1069 "cipher 0x%x (mask 0x%x) - reject",
1070 ie
->pairwise_cipher
, ssid
->pairwise_cipher
);
1073 if (!(ie
->key_mgmt
& ssid
->key_mgmt
)) {
1074 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled key "
1075 "management 0x%x (mask 0x%x) - reject",
1076 ie
->key_mgmt
, ssid
->key_mgmt
);
1080 #ifdef CONFIG_IEEE80211W
1081 if (!(ie
->capabilities
& WPA_CAPABILITY_MFPC
) &&
1082 wpas_get_ssid_pmf(wpa_s
, ssid
) == MGMT_FRAME_PROTECTION_REQUIRED
) {
1083 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver associated with an AP "
1084 "that does not support management frame protection - "
1088 #endif /* CONFIG_IEEE80211W */
1095 * wpa_supplicant_set_suites - Set authentication and encryption parameters
1096 * @wpa_s: Pointer to wpa_supplicant data
1097 * @bss: Scan results for the selected BSS, or %NULL if not available
1098 * @ssid: Configuration data for the selected network
1099 * @wpa_ie: Buffer for the WPA/RSN IE
1100 * @wpa_ie_len: Maximum wpa_ie buffer size on input. This is changed to be the
1101 * used buffer length in case the functions returns success.
1102 * Returns: 0 on success or -1 on failure
1104 * This function is used to configure authentication and encryption parameters
1105 * based on the network configuration and scan result for the selected BSS (if
1108 int wpa_supplicant_set_suites(struct wpa_supplicant
*wpa_s
,
1109 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
,
1110 u8
*wpa_ie
, size_t *wpa_ie_len
)
1112 struct wpa_ie_data ie
;
1114 const u8
*bss_wpa
, *bss_rsn
, *bss_osen
;
1117 bss_wpa
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
1118 bss_rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1119 bss_osen
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
1121 bss_wpa
= bss_rsn
= bss_osen
= NULL
;
1123 if (bss_rsn
&& (ssid
->proto
& WPA_PROTO_RSN
) &&
1124 wpa_parse_wpa_ie(bss_rsn
, 2 + bss_rsn
[1], &ie
) == 0 &&
1125 (ie
.group_cipher
& ssid
->group_cipher
) &&
1126 (ie
.pairwise_cipher
& ssid
->pairwise_cipher
) &&
1127 (ie
.key_mgmt
& ssid
->key_mgmt
)) {
1128 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: using IEEE 802.11i/D9.0");
1129 proto
= WPA_PROTO_RSN
;
1130 } else if (bss_wpa
&& (ssid
->proto
& WPA_PROTO_WPA
) &&
1131 wpa_parse_wpa_ie(bss_wpa
, 2 + bss_wpa
[1], &ie
) == 0 &&
1132 (ie
.group_cipher
& ssid
->group_cipher
) &&
1133 (ie
.pairwise_cipher
& ssid
->pairwise_cipher
) &&
1134 (ie
.key_mgmt
& ssid
->key_mgmt
)) {
1135 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using IEEE 802.11i/D3.0");
1136 proto
= WPA_PROTO_WPA
;
1138 } else if (bss_osen
&& (ssid
->proto
& WPA_PROTO_OSEN
)) {
1139 wpa_dbg(wpa_s
, MSG_DEBUG
, "HS 2.0: using OSEN");
1140 /* TODO: parse OSEN element */
1141 os_memset(&ie
, 0, sizeof(ie
));
1142 ie
.group_cipher
= WPA_CIPHER_CCMP
;
1143 ie
.pairwise_cipher
= WPA_CIPHER_CCMP
;
1144 ie
.key_mgmt
= WPA_KEY_MGMT_OSEN
;
1145 proto
= WPA_PROTO_OSEN
;
1146 #endif /* CONFIG_HS20 */
1148 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select WPA/RSN");
1149 wpa_dbg(wpa_s
, MSG_DEBUG
,
1150 "WPA: ssid proto=0x%x pairwise_cipher=0x%x group_cipher=0x%x key_mgmt=0x%x",
1151 ssid
->proto
, ssid
->pairwise_cipher
, ssid
->group_cipher
,
1153 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: BSS " MACSTR
" ssid='%s'%s%s%s",
1154 MAC2STR(bss
->bssid
),
1155 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
),
1156 bss_wpa
? " WPA" : "",
1157 bss_rsn
? " RSN" : "",
1158 bss_osen
? " OSEN" : "");
1160 wpa_hexdump(MSG_DEBUG
, "RSN", bss_rsn
, 2 + bss_rsn
[1]);
1161 if (wpa_parse_wpa_ie(bss_rsn
, 2 + bss_rsn
[1], &ie
)) {
1162 wpa_dbg(wpa_s
, MSG_DEBUG
,
1163 "Could not parse RSN element");
1165 wpa_dbg(wpa_s
, MSG_DEBUG
,
1166 "RSN: pairwise_cipher=0x%x group_cipher=0x%x key_mgmt=0x%x",
1167 ie
.pairwise_cipher
, ie
.group_cipher
,
1172 wpa_hexdump(MSG_DEBUG
, "WPA", bss_wpa
, 2 + bss_wpa
[1]);
1173 if (wpa_parse_wpa_ie(bss_wpa
, 2 + bss_wpa
[1], &ie
)) {
1174 wpa_dbg(wpa_s
, MSG_DEBUG
,
1175 "Could not parse WPA element");
1177 wpa_dbg(wpa_s
, MSG_DEBUG
,
1178 "WPA: pairwise_cipher=0x%x group_cipher=0x%x key_mgmt=0x%x",
1179 ie
.pairwise_cipher
, ie
.group_cipher
,
1185 if (ssid
->proto
& WPA_PROTO_OSEN
)
1186 proto
= WPA_PROTO_OSEN
;
1187 else if (ssid
->proto
& WPA_PROTO_RSN
)
1188 proto
= WPA_PROTO_RSN
;
1190 proto
= WPA_PROTO_WPA
;
1191 if (wpa_supplicant_suites_from_ai(wpa_s
, ssid
, &ie
) < 0) {
1192 os_memset(&ie
, 0, sizeof(ie
));
1193 ie
.group_cipher
= ssid
->group_cipher
;
1194 ie
.pairwise_cipher
= ssid
->pairwise_cipher
;
1195 ie
.key_mgmt
= ssid
->key_mgmt
;
1196 #ifdef CONFIG_IEEE80211W
1197 ie
.mgmt_group_cipher
=
1198 ssid
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
?
1199 WPA_CIPHER_AES_128_CMAC
: 0;
1200 #endif /* CONFIG_IEEE80211W */
1201 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Set cipher suites "
1202 "based on configuration");
1207 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Selected cipher suites: group %d "
1208 "pairwise %d key_mgmt %d proto %d",
1209 ie
.group_cipher
, ie
.pairwise_cipher
, ie
.key_mgmt
, proto
);
1210 #ifdef CONFIG_IEEE80211W
1211 if (ssid
->ieee80211w
) {
1212 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Selected mgmt group cipher %d",
1213 ie
.mgmt_group_cipher
);
1215 #endif /* CONFIG_IEEE80211W */
1217 wpa_s
->wpa_proto
= proto
;
1218 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PROTO
, proto
);
1219 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_RSN_ENABLED
,
1220 !!(ssid
->proto
& (WPA_PROTO_RSN
| WPA_PROTO_OSEN
)));
1222 if (bss
|| !wpa_s
->ap_ies_from_associnfo
) {
1223 if (wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, bss_wpa
,
1224 bss_wpa
? 2 + bss_wpa
[1] : 0) ||
1225 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, bss_rsn
,
1226 bss_rsn
? 2 + bss_rsn
[1] : 0))
1230 #ifdef CONFIG_NO_WPA
1231 wpa_s
->group_cipher
= WPA_CIPHER_NONE
;
1232 wpa_s
->pairwise_cipher
= WPA_CIPHER_NONE
;
1233 #else /* CONFIG_NO_WPA */
1234 sel
= ie
.group_cipher
& ssid
->group_cipher
;
1235 wpa_s
->group_cipher
= wpa_pick_group_cipher(sel
);
1236 if (wpa_s
->group_cipher
< 0) {
1237 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select group "
1241 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using GTK %s",
1242 wpa_cipher_txt(wpa_s
->group_cipher
));
1244 sel
= ie
.pairwise_cipher
& ssid
->pairwise_cipher
;
1245 wpa_s
->pairwise_cipher
= wpa_pick_pairwise_cipher(sel
, 1);
1246 if (wpa_s
->pairwise_cipher
< 0) {
1247 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select pairwise "
1251 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using PTK %s",
1252 wpa_cipher_txt(wpa_s
->pairwise_cipher
));
1253 #endif /* CONFIG_NO_WPA */
1255 sel
= ie
.key_mgmt
& ssid
->key_mgmt
;
1257 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
))
1258 sel
&= ~(WPA_KEY_MGMT_SAE
| WPA_KEY_MGMT_FT_SAE
);
1259 #endif /* CONFIG_SAE */
1261 #ifdef CONFIG_SUITEB192
1262 } else if (sel
& WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
1263 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
;
1264 wpa_dbg(wpa_s
, MSG_DEBUG
,
1265 "WPA: using KEY_MGMT 802.1X with Suite B (192-bit)");
1266 #endif /* CONFIG_SUITEB192 */
1267 #ifdef CONFIG_SUITEB
1268 } else if (sel
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
1269 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X_SUITE_B
;
1270 wpa_dbg(wpa_s
, MSG_DEBUG
,
1271 "WPA: using KEY_MGMT 802.1X with Suite B");
1272 #endif /* CONFIG_SUITEB */
1274 #ifdef CONFIG_IEEE80211R
1275 } else if (sel
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
1276 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_FILS_SHA384
;
1277 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FT-FILS-SHA384");
1278 } else if (sel
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
1279 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_FILS_SHA256
;
1280 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FT-FILS-SHA256");
1281 #endif /* CONFIG_IEEE80211R */
1282 } else if (sel
& WPA_KEY_MGMT_FILS_SHA384
) {
1283 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FILS_SHA384
;
1284 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FILS-SHA384");
1285 } else if (sel
& WPA_KEY_MGMT_FILS_SHA256
) {
1286 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FILS_SHA256
;
1287 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FILS-SHA256");
1288 #endif /* CONFIG_FILS */
1289 #ifdef CONFIG_IEEE80211R
1290 } else if (sel
& WPA_KEY_MGMT_FT_IEEE8021X
) {
1291 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_IEEE8021X
;
1292 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FT/802.1X");
1293 } else if (sel
& WPA_KEY_MGMT_FT_PSK
) {
1294 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_PSK
;
1295 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FT/PSK");
1296 #endif /* CONFIG_IEEE80211R */
1298 } else if (sel
& WPA_KEY_MGMT_SAE
) {
1299 wpa_s
->key_mgmt
= WPA_KEY_MGMT_SAE
;
1300 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: using KEY_MGMT SAE");
1301 } else if (sel
& WPA_KEY_MGMT_FT_SAE
) {
1302 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_SAE
;
1303 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: using KEY_MGMT FT/SAE");
1304 #endif /* CONFIG_SAE */
1305 #ifdef CONFIG_IEEE80211W
1306 } else if (sel
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
1307 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X_SHA256
;
1308 wpa_dbg(wpa_s
, MSG_DEBUG
,
1309 "WPA: using KEY_MGMT 802.1X with SHA256");
1310 } else if (sel
& WPA_KEY_MGMT_PSK_SHA256
) {
1311 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK_SHA256
;
1312 wpa_dbg(wpa_s
, MSG_DEBUG
,
1313 "WPA: using KEY_MGMT PSK with SHA256");
1314 #endif /* CONFIG_IEEE80211W */
1315 } else if (sel
& WPA_KEY_MGMT_IEEE8021X
) {
1316 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X
;
1317 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT 802.1X");
1318 } else if (sel
& WPA_KEY_MGMT_PSK
) {
1319 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK
;
1320 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT WPA-PSK");
1321 } else if (sel
& WPA_KEY_MGMT_WPA_NONE
) {
1322 wpa_s
->key_mgmt
= WPA_KEY_MGMT_WPA_NONE
;
1323 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT WPA-NONE");
1325 } else if (sel
& WPA_KEY_MGMT_OSEN
) {
1326 wpa_s
->key_mgmt
= WPA_KEY_MGMT_OSEN
;
1327 wpa_dbg(wpa_s
, MSG_DEBUG
, "HS 2.0: using KEY_MGMT OSEN");
1328 #endif /* CONFIG_HS20 */
1330 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select "
1331 "authenticated key management type");
1335 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_KEY_MGMT
, wpa_s
->key_mgmt
);
1336 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PAIRWISE
,
1337 wpa_s
->pairwise_cipher
);
1338 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_GROUP
, wpa_s
->group_cipher
);
1340 #ifdef CONFIG_IEEE80211W
1341 sel
= ie
.mgmt_group_cipher
;
1342 if (wpas_get_ssid_pmf(wpa_s
, ssid
) == NO_MGMT_FRAME_PROTECTION
||
1343 !(ie
.capabilities
& WPA_CAPABILITY_MFPC
))
1345 if (sel
& WPA_CIPHER_AES_128_CMAC
) {
1346 wpa_s
->mgmt_group_cipher
= WPA_CIPHER_AES_128_CMAC
;
1347 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using MGMT group cipher "
1349 } else if (sel
& WPA_CIPHER_BIP_GMAC_128
) {
1350 wpa_s
->mgmt_group_cipher
= WPA_CIPHER_BIP_GMAC_128
;
1351 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using MGMT group cipher "
1353 } else if (sel
& WPA_CIPHER_BIP_GMAC_256
) {
1354 wpa_s
->mgmt_group_cipher
= WPA_CIPHER_BIP_GMAC_256
;
1355 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using MGMT group cipher "
1357 } else if (sel
& WPA_CIPHER_BIP_CMAC_256
) {
1358 wpa_s
->mgmt_group_cipher
= WPA_CIPHER_BIP_CMAC_256
;
1359 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using MGMT group cipher "
1362 wpa_s
->mgmt_group_cipher
= 0;
1363 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: not using MGMT group cipher");
1365 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MGMT_GROUP
,
1366 wpa_s
->mgmt_group_cipher
);
1367 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MFP
,
1368 wpas_get_ssid_pmf(wpa_s
, ssid
));
1369 #endif /* CONFIG_IEEE80211W */
1371 if (wpa_sm_set_assoc_wpa_ie_default(wpa_s
->wpa
, wpa_ie
, wpa_ie_len
)) {
1372 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to generate WPA IE");
1376 if (wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
)) {
1379 if (ssid
->psk_set
) {
1380 wpa_sm_set_pmk(wpa_s
->wpa
, ssid
->psk
, PMK_LEN
, NULL
,
1384 #ifndef CONFIG_NO_PBKDF2
1385 if (bss
&& ssid
->bssid_set
&& ssid
->ssid_len
== 0 &&
1388 pbkdf2_sha1(ssid
->passphrase
, bss
->ssid
, bss
->ssid_len
,
1389 4096, psk
, PMK_LEN
);
1390 wpa_hexdump_key(MSG_MSGDUMP
, "PSK (from passphrase)",
1392 wpa_sm_set_pmk(wpa_s
->wpa
, psk
, PMK_LEN
, NULL
, NULL
);
1394 os_memset(psk
, 0, sizeof(psk
));
1396 #endif /* CONFIG_NO_PBKDF2 */
1397 #ifdef CONFIG_EXT_PASSWORD
1398 if (ssid
->ext_psk
) {
1399 struct wpabuf
*pw
= ext_password_get(wpa_s
->ext_pw
,
1401 char pw_str
[64 + 1];
1405 wpa_msg(wpa_s
, MSG_INFO
, "EXT PW: No PSK "
1406 "found from external storage");
1410 if (wpabuf_len(pw
) < 8 || wpabuf_len(pw
) > 64) {
1411 wpa_msg(wpa_s
, MSG_INFO
, "EXT PW: Unexpected "
1412 "PSK length %d in external storage",
1413 (int) wpabuf_len(pw
));
1414 ext_password_free(pw
);
1418 os_memcpy(pw_str
, wpabuf_head(pw
), wpabuf_len(pw
));
1419 pw_str
[wpabuf_len(pw
)] = '\0';
1421 #ifndef CONFIG_NO_PBKDF2
1422 if (wpabuf_len(pw
) >= 8 && wpabuf_len(pw
) < 64 && bss
)
1424 pbkdf2_sha1(pw_str
, bss
->ssid
, bss
->ssid_len
,
1425 4096, psk
, PMK_LEN
);
1426 os_memset(pw_str
, 0, sizeof(pw_str
));
1427 wpa_hexdump_key(MSG_MSGDUMP
, "PSK (from "
1428 "external passphrase)",
1430 wpa_sm_set_pmk(wpa_s
->wpa
, psk
, PMK_LEN
, NULL
,
1433 os_memset(psk
, 0, sizeof(psk
));
1435 #endif /* CONFIG_NO_PBKDF2 */
1436 if (wpabuf_len(pw
) == 2 * PMK_LEN
) {
1437 if (hexstr2bin(pw_str
, psk
, PMK_LEN
) < 0) {
1438 wpa_msg(wpa_s
, MSG_INFO
, "EXT PW: "
1439 "Invalid PSK hex string");
1440 os_memset(pw_str
, 0, sizeof(pw_str
));
1441 ext_password_free(pw
);
1444 wpa_sm_set_pmk(wpa_s
->wpa
, psk
, PMK_LEN
, NULL
,
1447 os_memset(psk
, 0, sizeof(psk
));
1449 wpa_msg(wpa_s
, MSG_INFO
, "EXT PW: No suitable "
1451 os_memset(pw_str
, 0, sizeof(pw_str
));
1452 ext_password_free(pw
);
1456 os_memset(pw_str
, 0, sizeof(pw_str
));
1457 ext_password_free(pw
);
1459 #endif /* CONFIG_EXT_PASSWORD */
1462 wpa_msg(wpa_s
, MSG_INFO
,
1463 "No PSK available for association");
1467 wpa_sm_set_pmk_from_pmksa(wpa_s
->wpa
);
1473 static void wpas_ext_capab_byte(struct wpa_supplicant
*wpa_s
, u8
*pos
, int idx
)
1478 case 0: /* Bits 0-7 */
1480 case 1: /* Bits 8-15 */
1482 case 2: /* Bits 16-23 */
1484 *pos
|= 0x02; /* Bit 17 - WNM-Sleep Mode */
1485 *pos
|= 0x08; /* Bit 19 - BSS Transition */
1486 #endif /* CONFIG_WNM */
1488 case 3: /* Bits 24-31 */
1490 *pos
|= 0x02; /* Bit 25 - SSID List */
1491 #endif /* CONFIG_WNM */
1492 #ifdef CONFIG_INTERWORKING
1493 if (wpa_s
->conf
->interworking
)
1494 *pos
|= 0x80; /* Bit 31 - Interworking */
1495 #endif /* CONFIG_INTERWORKING */
1497 case 4: /* Bits 32-39 */
1498 #ifdef CONFIG_INTERWORKING
1499 if (wpa_s
->drv_flags
/ WPA_DRIVER_FLAGS_QOS_MAPPING
)
1500 *pos
|= 0x01; /* Bit 32 - QoS Map */
1501 #endif /* CONFIG_INTERWORKING */
1503 case 5: /* Bits 40-47 */
1505 if (wpa_s
->conf
->hs20
)
1506 *pos
|= 0x40; /* Bit 46 - WNM-Notification */
1507 #endif /* CONFIG_HS20 */
1509 *pos
|= 0x40; /* Bit 46 - WNM-Notification */
1510 #endif /* CONFIG_MBO */
1512 case 6: /* Bits 48-55 */
1514 case 7: /* Bits 56-63 */
1516 case 8: /* Bits 64-71 */
1517 if (wpa_s
->conf
->ftm_responder
)
1518 *pos
|= 0x40; /* Bit 70 - FTM responder */
1519 if (wpa_s
->conf
->ftm_initiator
)
1520 *pos
|= 0x80; /* Bit 71 - FTM initiator */
1522 case 9: /* Bits 72-79 */
1525 #endif /* CONFIG_FILS */
1531 int wpas_build_ext_capab(struct wpa_supplicant
*wpa_s
, u8
*buf
, size_t buflen
)
1536 if (len
< wpa_s
->extended_capa_len
)
1537 len
= wpa_s
->extended_capa_len
;
1538 if (buflen
< (size_t) len
+ 2) {
1539 wpa_printf(MSG_INFO
,
1540 "Not enough room for building extended capabilities element");
1544 *pos
++ = WLAN_EID_EXT_CAPAB
;
1546 for (i
= 0; i
< len
; i
++, pos
++) {
1547 wpas_ext_capab_byte(wpa_s
, pos
, i
);
1549 if (i
< wpa_s
->extended_capa_len
) {
1550 *pos
&= ~wpa_s
->extended_capa_mask
[i
];
1551 *pos
|= wpa_s
->extended_capa
[i
];
1555 while (len
> 0 && buf
[1 + len
] == 0) {
1566 static int wpas_valid_bss(struct wpa_supplicant
*wpa_s
,
1567 struct wpa_bss
*test_bss
)
1569 struct wpa_bss
*bss
;
1571 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
1572 if (bss
== test_bss
)
1580 static int wpas_valid_ssid(struct wpa_supplicant
*wpa_s
,
1581 struct wpa_ssid
*test_ssid
)
1583 struct wpa_ssid
*ssid
;
1585 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
1586 if (ssid
== test_ssid
)
1594 int wpas_valid_bss_ssid(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*test_bss
,
1595 struct wpa_ssid
*test_ssid
)
1597 if (test_bss
&& !wpas_valid_bss(wpa_s
, test_bss
))
1600 return test_ssid
== NULL
|| wpas_valid_ssid(wpa_s
, test_ssid
);
1604 void wpas_connect_work_free(struct wpa_connect_work
*cwork
)
1612 void wpas_connect_work_done(struct wpa_supplicant
*wpa_s
)
1614 struct wpa_connect_work
*cwork
;
1615 struct wpa_radio_work
*work
= wpa_s
->connect_work
;
1620 wpa_s
->connect_work
= NULL
;
1623 wpas_connect_work_free(cwork
);
1624 radio_work_done(work
);
1628 int wpas_update_random_addr(struct wpa_supplicant
*wpa_s
, int style
)
1630 struct os_reltime now
;
1633 os_get_reltime(&now
);
1634 if (wpa_s
->last_mac_addr_style
== style
&&
1635 wpa_s
->last_mac_addr_change
.sec
!= 0 &&
1636 !os_reltime_expired(&now
, &wpa_s
->last_mac_addr_change
,
1637 wpa_s
->conf
->rand_addr_lifetime
)) {
1638 wpa_msg(wpa_s
, MSG_DEBUG
,
1639 "Previously selected random MAC address has not yet expired");
1645 if (random_mac_addr(addr
) < 0)
1649 os_memcpy(addr
, wpa_s
->perm_addr
, ETH_ALEN
);
1650 if (random_mac_addr_keep_oui(addr
) < 0)
1657 if (wpa_drv_set_mac_addr(wpa_s
, addr
) < 0) {
1658 wpa_msg(wpa_s
, MSG_INFO
,
1659 "Failed to set random MAC address");
1663 os_get_reltime(&wpa_s
->last_mac_addr_change
);
1664 wpa_s
->mac_addr_changed
= 1;
1665 wpa_s
->last_mac_addr_style
= style
;
1667 if (wpa_supplicant_update_mac_addr(wpa_s
) < 0) {
1668 wpa_msg(wpa_s
, MSG_INFO
,
1669 "Could not update MAC address information");
1673 wpa_msg(wpa_s
, MSG_DEBUG
, "Using random MAC address " MACSTR
,
1680 int wpas_update_random_addr_disassoc(struct wpa_supplicant
*wpa_s
)
1682 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
||
1683 !wpa_s
->conf
->preassoc_mac_addr
)
1686 return wpas_update_random_addr(wpa_s
, wpa_s
->conf
->preassoc_mac_addr
);
1690 static void wpas_start_assoc_cb(struct wpa_radio_work
*work
, int deinit
);
1693 * wpa_supplicant_associate - Request association
1694 * @wpa_s: Pointer to wpa_supplicant data
1695 * @bss: Scan results for the selected BSS, or %NULL if not available
1696 * @ssid: Configuration data for the selected network
1698 * This function is used to request %wpa_supplicant to associate with a BSS.
1700 void wpa_supplicant_associate(struct wpa_supplicant
*wpa_s
,
1701 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
)
1703 struct wpa_connect_work
*cwork
;
1706 wpa_s
->own_disconnect_req
= 0;
1709 * If we are starting a new connection, any previously pending EAPOL
1710 * RX cannot be valid anymore.
1712 wpabuf_free(wpa_s
->pending_eapol_rx
);
1713 wpa_s
->pending_eapol_rx
= NULL
;
1715 if (ssid
->mac_addr
== -1)
1716 rand_style
= wpa_s
->conf
->mac_addr
;
1718 rand_style
= ssid
->mac_addr
;
1720 wmm_ac_clear_saved_tspecs(wpa_s
);
1721 wpa_s
->reassoc_same_bss
= 0;
1722 wpa_s
->reassoc_same_ess
= 0;
1724 if (wpa_s
->last_ssid
== ssid
) {
1725 wpa_dbg(wpa_s
, MSG_DEBUG
, "Re-association to the same ESS");
1726 wpa_s
->reassoc_same_ess
= 1;
1727 if (wpa_s
->current_bss
&& wpa_s
->current_bss
== bss
) {
1728 wmm_ac_save_tspecs(wpa_s
);
1729 wpa_s
->reassoc_same_bss
= 1;
1733 if (rand_style
> 0 && !wpa_s
->reassoc_same_ess
) {
1734 if (wpas_update_random_addr(wpa_s
, rand_style
) < 0)
1736 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
1737 } else if (rand_style
== 0 && wpa_s
->mac_addr_changed
) {
1738 if (wpa_drv_set_mac_addr(wpa_s
, NULL
) < 0) {
1739 wpa_msg(wpa_s
, MSG_INFO
,
1740 "Could not restore permanent MAC address");
1743 wpa_s
->mac_addr_changed
= 0;
1744 if (wpa_supplicant_update_mac_addr(wpa_s
) < 0) {
1745 wpa_msg(wpa_s
, MSG_INFO
,
1746 "Could not update MAC address information");
1749 wpa_msg(wpa_s
, MSG_DEBUG
, "Using permanent MAC address");
1751 wpa_s
->last_ssid
= ssid
;
1753 #ifdef CONFIG_IBSS_RSN
1754 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
1755 wpa_s
->ibss_rsn
= NULL
;
1756 #else /* CONFIG_IBSS_RSN */
1757 if (ssid
->mode
== WPAS_MODE_IBSS
&&
1758 !(ssid
->key_mgmt
& (WPA_KEY_MGMT_NONE
| WPA_KEY_MGMT_WPA_NONE
))) {
1759 wpa_msg(wpa_s
, MSG_INFO
,
1760 "IBSS RSN not supported in the build");
1763 #endif /* CONFIG_IBSS_RSN */
1765 if (ssid
->mode
== WPAS_MODE_AP
|| ssid
->mode
== WPAS_MODE_P2P_GO
||
1766 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
) {
1768 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_AP
)) {
1769 wpa_msg(wpa_s
, MSG_INFO
, "Driver does not support AP "
1773 if (wpa_supplicant_create_ap(wpa_s
, ssid
) < 0) {
1774 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1775 if (ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)
1776 wpas_p2p_ap_setup_failed(wpa_s
);
1779 wpa_s
->current_bss
= bss
;
1780 #else /* CONFIG_AP */
1781 wpa_msg(wpa_s
, MSG_ERROR
, "AP mode support not included in "
1783 #endif /* CONFIG_AP */
1787 if (ssid
->mode
== WPAS_MODE_MESH
) {
1789 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_MESH
)) {
1790 wpa_msg(wpa_s
, MSG_INFO
,
1791 "Driver does not support mesh mode");
1795 ssid
->frequency
= bss
->freq
;
1796 if (wpa_supplicant_join_mesh(wpa_s
, ssid
) < 0) {
1797 wpa_msg(wpa_s
, MSG_ERROR
, "Could not join mesh");
1800 wpa_s
->current_bss
= bss
;
1801 wpa_msg(wpa_s
, MSG_INFO
, MESH_GROUP_STARTED
"ssid=\"%s\" id=%d",
1802 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
),
1804 #else /* CONFIG_MESH */
1805 wpa_msg(wpa_s
, MSG_ERROR
,
1806 "mesh mode support not included in the build");
1807 #endif /* CONFIG_MESH */
1813 wpa_tdls_ap_ies(wpa_s
->wpa
, (const u8
*) (bss
+ 1),
1815 #endif /* CONFIG_TDLS */
1817 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
1818 ssid
->mode
== IEEE80211_MODE_INFRA
) {
1819 sme_authenticate(wpa_s
, bss
, ssid
);
1823 if (wpa_s
->connect_work
) {
1824 wpa_dbg(wpa_s
, MSG_DEBUG
, "Reject wpa_supplicant_associate() call since connect_work exist");
1828 if (radio_work_pending(wpa_s
, "connect")) {
1829 wpa_dbg(wpa_s
, MSG_DEBUG
, "Reject wpa_supplicant_associate() call since pending work exist");
1834 if (ssid
->mode
== WPAS_MODE_IBSS
|| ssid
->mode
== WPAS_MODE_MESH
) {
1835 /* Clear possibly set auth_alg, if any, from last attempt. */
1836 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_OPEN
;
1838 #endif /* CONFIG_SME */
1840 wpas_abort_ongoing_scan(wpa_s
);
1842 cwork
= os_zalloc(sizeof(*cwork
));
1849 if (radio_add_work(wpa_s
, bss
? bss
->freq
: 0, "connect", 1,
1850 wpas_start_assoc_cb
, cwork
) < 0) {
1856 static int bss_is_ibss(struct wpa_bss
*bss
)
1858 return (bss
->caps
& (IEEE80211_CAP_ESS
| IEEE80211_CAP_IBSS
)) ==
1863 static int drv_supports_vht(struct wpa_supplicant
*wpa_s
,
1864 const struct wpa_ssid
*ssid
)
1866 enum hostapd_hw_mode hw_mode
;
1867 struct hostapd_hw_modes
*mode
= NULL
;
1871 #ifdef CONFIG_HT_OVERRIDES
1872 if (ssid
->disable_ht
)
1874 #endif /* CONFIG_HT_OVERRIDES */
1876 hw_mode
= ieee80211_freq_to_chan(ssid
->frequency
, &channel
);
1877 if (hw_mode
== NUM_HOSTAPD_MODES
)
1879 for (i
= 0; wpa_s
->hw
.modes
&& i
< wpa_s
->hw
.num_modes
; i
++) {
1880 if (wpa_s
->hw
.modes
[i
].mode
== hw_mode
) {
1881 mode
= &wpa_s
->hw
.modes
[i
];
1889 return mode
->vht_capab
!= 0;
1893 void ibss_mesh_setup_freq(struct wpa_supplicant
*wpa_s
,
1894 const struct wpa_ssid
*ssid
,
1895 struct hostapd_freq_params
*freq
)
1897 enum hostapd_hw_mode hw_mode
;
1898 struct hostapd_hw_modes
*mode
= NULL
;
1899 int ht40plus
[] = { 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157,
1901 int vht80
[] = { 36, 52, 100, 116, 132, 149 };
1902 struct hostapd_channel_data
*pri_chan
= NULL
, *sec_chan
= NULL
;
1904 int i
, chan_idx
, ht40
= -1, res
, obss_scan
= 1;
1906 struct hostapd_freq_params vht_freq
;
1907 int chwidth
, seg0
, seg1
;
1910 freq
->freq
= ssid
->frequency
;
1912 for (j
= 0; j
< wpa_s
->last_scan_res_used
; j
++) {
1913 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[j
];
1915 if (ssid
->mode
!= WPAS_MODE_IBSS
)
1918 /* Don't adjust control freq in case of fixed_freq */
1919 if (ssid
->fixed_freq
)
1922 if (!bss_is_ibss(bss
))
1925 if (ssid
->ssid_len
== bss
->ssid_len
&&
1926 os_memcmp(ssid
->ssid
, bss
->ssid
, bss
->ssid_len
) == 0) {
1927 wpa_printf(MSG_DEBUG
,
1928 "IBSS already found in scan results, adjust control freq: %d",
1930 freq
->freq
= bss
->freq
;
1936 /* For IBSS check HT_IBSS flag */
1937 if (ssid
->mode
== WPAS_MODE_IBSS
&&
1938 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_HT_IBSS
))
1941 if (wpa_s
->group_cipher
== WPA_CIPHER_WEP40
||
1942 wpa_s
->group_cipher
== WPA_CIPHER_WEP104
||
1943 wpa_s
->pairwise_cipher
== WPA_CIPHER_TKIP
) {
1944 wpa_printf(MSG_DEBUG
,
1945 "IBSS: WEP/TKIP detected, do not try to enable HT");
1949 hw_mode
= ieee80211_freq_to_chan(freq
->freq
, &channel
);
1950 for (i
= 0; wpa_s
->hw
.modes
&& i
< wpa_s
->hw
.num_modes
; i
++) {
1951 if (wpa_s
->hw
.modes
[i
].mode
== hw_mode
) {
1952 mode
= &wpa_s
->hw
.modes
[i
];
1960 #ifdef CONFIG_HT_OVERRIDES
1961 if (ssid
->disable_ht
) {
1962 freq
->ht_enabled
= 0;
1965 #endif /* CONFIG_HT_OVERRIDES */
1967 freq
->ht_enabled
= ht_supported(mode
);
1968 if (!freq
->ht_enabled
)
1971 /* Setup higher BW only for 5 GHz */
1972 if (mode
->mode
!= HOSTAPD_MODE_IEEE80211A
)
1975 for (chan_idx
= 0; chan_idx
< mode
->num_channels
; chan_idx
++) {
1976 pri_chan
= &mode
->channels
[chan_idx
];
1977 if (pri_chan
->chan
== channel
)
1984 /* Check primary channel flags */
1985 if (pri_chan
->flag
& (HOSTAPD_CHAN_DISABLED
| HOSTAPD_CHAN_NO_IR
))
1988 #ifdef CONFIG_HT_OVERRIDES
1989 if (ssid
->disable_ht40
)
1991 #endif /* CONFIG_HT_OVERRIDES */
1993 /* Check/setup HT40+/HT40- */
1994 for (j
= 0; j
< ARRAY_SIZE(ht40plus
); j
++) {
1995 if (ht40plus
[j
] == channel
) {
2001 /* Find secondary channel */
2002 for (i
= 0; i
< mode
->num_channels
; i
++) {
2003 sec_chan
= &mode
->channels
[i
];
2004 if (sec_chan
->chan
== channel
+ ht40
* 4)
2011 /* Check secondary channel flags */
2012 if (sec_chan
->flag
& (HOSTAPD_CHAN_DISABLED
| HOSTAPD_CHAN_NO_IR
))
2015 freq
->channel
= pri_chan
->chan
;
2018 if (!(pri_chan
->flag
& HOSTAPD_CHAN_HT40MINUS
))
2021 if (!(pri_chan
->flag
& HOSTAPD_CHAN_HT40PLUS
))
2024 freq
->sec_channel_offset
= ht40
;
2027 struct wpa_scan_results
*scan_res
;
2029 scan_res
= wpa_supplicant_get_scan_results(wpa_s
, NULL
, 0);
2030 if (scan_res
== NULL
) {
2032 freq
->sec_channel_offset
= 0;
2036 res
= check_40mhz_5g(mode
, scan_res
, pri_chan
->chan
,
2041 freq
->sec_channel_offset
= 0;
2044 /* Configuration allowed */
2047 /* Switch pri/sec channels */
2048 freq
->freq
= hw_get_freq(mode
, sec_chan
->chan
);
2049 freq
->sec_channel_offset
= -freq
->sec_channel_offset
;
2050 freq
->channel
= sec_chan
->chan
;
2053 freq
->sec_channel_offset
= 0;
2057 wpa_scan_results_free(scan_res
);
2060 wpa_printf(MSG_DEBUG
,
2061 "IBSS/mesh: setup freq channel %d, sec_channel_offset %d",
2062 freq
->channel
, freq
->sec_channel_offset
);
2064 if (!drv_supports_vht(wpa_s
, ssid
))
2067 /* For IBSS check VHT_IBSS flag */
2068 if (ssid
->mode
== WPAS_MODE_IBSS
&&
2069 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_VHT_IBSS
))
2074 #ifdef CONFIG_VHT_OVERRIDES
2075 if (ssid
->disable_vht
) {
2076 freq
->vht_enabled
= 0;
2079 #endif /* CONFIG_VHT_OVERRIDES */
2081 vht_freq
.vht_enabled
= vht_supported(mode
);
2082 if (!vht_freq
.vht_enabled
)
2085 /* setup center_freq1, bandwidth */
2086 for (j
= 0; j
< ARRAY_SIZE(vht80
); j
++) {
2087 if (freq
->channel
>= vht80
[j
] &&
2088 freq
->channel
< vht80
[j
] + 16)
2092 if (j
== ARRAY_SIZE(vht80
))
2095 for (i
= vht80
[j
]; i
< vht80
[j
] + 16; i
+= 4) {
2096 struct hostapd_channel_data
*chan
;
2098 chan
= hw_get_channel_chan(mode
, i
, NULL
);
2102 /* Back to HT configuration if channel not usable */
2103 if (chan
->flag
& (HOSTAPD_CHAN_DISABLED
| HOSTAPD_CHAN_NO_IR
))
2107 chwidth
= VHT_CHANWIDTH_80MHZ
;
2108 seg0
= vht80
[j
] + 6;
2111 if (ssid
->max_oper_chwidth
== VHT_CHANWIDTH_80P80MHZ
) {
2112 /* setup center_freq2, bandwidth */
2113 for (k
= 0; k
< ARRAY_SIZE(vht80
); k
++) {
2114 /* Only accept 80 MHz segments separated by a gap */
2115 if (j
== k
|| abs(vht80
[j
] - vht80
[k
]) == 16)
2117 for (i
= vht80
[k
]; i
< vht80
[k
] + 16; i
+= 4) {
2118 struct hostapd_channel_data
*chan
;
2120 chan
= hw_get_channel_chan(mode
, i
, NULL
);
2124 if (chan
->flag
& (HOSTAPD_CHAN_DISABLED
|
2125 HOSTAPD_CHAN_NO_IR
|
2126 HOSTAPD_CHAN_RADAR
))
2129 /* Found a suitable second segment for 80+80 */
2130 chwidth
= VHT_CHANWIDTH_80P80MHZ
;
2132 VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ
;
2133 seg1
= vht80
[k
] + 6;
2136 if (chwidth
== VHT_CHANWIDTH_80P80MHZ
)
2139 } else if (ssid
->max_oper_chwidth
== VHT_CHANWIDTH_160MHZ
) {
2140 if (freq
->freq
== 5180) {
2141 chwidth
= VHT_CHANWIDTH_160MHZ
;
2142 vht_caps
|= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
;
2144 } else if (freq
->freq
== 5520) {
2145 chwidth
= VHT_CHANWIDTH_160MHZ
;
2146 vht_caps
|= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
;
2151 if (hostapd_set_freq_params(&vht_freq
, mode
->mode
, freq
->freq
,
2152 freq
->channel
, freq
->ht_enabled
,
2153 vht_freq
.vht_enabled
,
2154 freq
->sec_channel_offset
,
2155 chwidth
, seg0
, seg1
, vht_caps
) != 0)
2160 wpa_printf(MSG_DEBUG
, "IBSS: VHT setup freq cf1 %d, cf2 %d, bw %d",
2161 freq
->center_freq1
, freq
->center_freq2
, freq
->bandwidth
);
2165 static void wpas_start_assoc_cb(struct wpa_radio_work
*work
, int deinit
)
2167 struct wpa_connect_work
*cwork
= work
->ctx
;
2168 struct wpa_bss
*bss
= cwork
->bss
;
2169 struct wpa_ssid
*ssid
= cwork
->ssid
;
2170 struct wpa_supplicant
*wpa_s
= work
->wpa_s
;
2173 int use_crypt
, ret
, i
, bssid_changed
;
2174 int algs
= WPA_AUTH_ALG_OPEN
;
2175 unsigned int cipher_pairwise
, cipher_group
;
2176 struct wpa_driver_associate_params params
;
2177 int wep_keys_set
= 0;
2178 int assoc_failed
= 0;
2179 struct wpa_ssid
*old_ssid
;
2180 u8 prev_bssid
[ETH_ALEN
];
2181 #ifdef CONFIG_HT_OVERRIDES
2182 struct ieee80211_ht_capabilities htcaps
;
2183 struct ieee80211_ht_capabilities htcaps_mask
;
2184 #endif /* CONFIG_HT_OVERRIDES */
2185 #ifdef CONFIG_VHT_OVERRIDES
2186 struct ieee80211_vht_capabilities vhtcaps
;
2187 struct ieee80211_vht_capabilities vhtcaps_mask
;
2188 #endif /* CONFIG_VHT_OVERRIDES */
2191 if (work
->started
) {
2192 wpa_s
->connect_work
= NULL
;
2194 /* cancel possible auth. timeout */
2195 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
,
2198 wpas_connect_work_free(cwork
);
2202 wpa_s
->connect_work
= work
;
2204 if (cwork
->bss_removed
|| !wpas_valid_bss_ssid(wpa_s
, bss
, ssid
) ||
2205 wpas_network_disabled(wpa_s
, ssid
)) {
2206 wpa_dbg(wpa_s
, MSG_DEBUG
, "BSS/SSID entry for association not valid anymore - drop connection attempt");
2207 wpas_connect_work_done(wpa_s
);
2211 os_memcpy(prev_bssid
, wpa_s
->bssid
, ETH_ALEN
);
2212 os_memset(¶ms
, 0, sizeof(params
));
2213 wpa_s
->reassociate
= 0;
2214 wpa_s
->eap_expected_failure
= 0;
2216 (!wpas_driver_bss_selection(wpa_s
) || wpas_wps_searching(wpa_s
))) {
2217 #ifdef CONFIG_IEEE80211R
2218 const u8
*ie
, *md
= NULL
;
2219 #endif /* CONFIG_IEEE80211R */
2220 wpa_msg(wpa_s
, MSG_INFO
, "Trying to associate with " MACSTR
2221 " (SSID='%s' freq=%d MHz)", MAC2STR(bss
->bssid
),
2222 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
), bss
->freq
);
2223 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
2224 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
2225 os_memcpy(wpa_s
->pending_bssid
, bss
->bssid
, ETH_ALEN
);
2227 wpas_notify_bssid_changed(wpa_s
);
2228 #ifdef CONFIG_IEEE80211R
2229 ie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
2230 if (ie
&& ie
[1] >= MOBILITY_DOMAIN_ID_LEN
)
2232 wpa_sm_set_ft_params(wpa_s
->wpa
, ie
, ie
? 2 + ie
[1] : 0);
2234 /* Prepare for the next transition */
2235 wpa_ft_prepare_auth_request(wpa_s
->wpa
, ie
);
2237 #endif /* CONFIG_IEEE80211R */
2239 } else if ((ssid
->ssid
== NULL
|| ssid
->ssid_len
== 0) &&
2240 wpa_s
->conf
->ap_scan
== 2 &&
2241 (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
2242 /* Use ap_scan==1 style network selection to find the network
2244 wpas_connect_work_done(wpa_s
);
2245 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
2246 wpa_s
->reassociate
= 1;
2247 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2249 #endif /* CONFIG_WPS */
2251 wpa_msg(wpa_s
, MSG_INFO
, "Trying to associate with SSID '%s'",
2252 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
2254 os_memcpy(wpa_s
->pending_bssid
, bss
->bssid
, ETH_ALEN
);
2256 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
2259 wpa_supplicant_cancel_sched_scan(wpa_s
);
2261 wpa_supplicant_cancel_scan(wpa_s
);
2263 /* Starting new association, so clear the possibly used WPA IE from the
2264 * previous association. */
2265 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2267 #ifdef IEEE8021X_EAPOL
2268 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
2270 if (ssid
->non_leap
== 0)
2271 algs
= WPA_AUTH_ALG_LEAP
;
2273 algs
|= WPA_AUTH_ALG_LEAP
;
2276 #endif /* IEEE8021X_EAPOL */
2277 wpa_dbg(wpa_s
, MSG_DEBUG
, "Automatic auth_alg selection: 0x%x", algs
);
2278 if (ssid
->auth_alg
) {
2279 algs
= ssid
->auth_alg
;
2280 wpa_dbg(wpa_s
, MSG_DEBUG
, "Overriding auth_alg selection: "
2284 if (bss
&& (wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
) ||
2285 wpa_bss_get_ie(bss
, WLAN_EID_RSN
)) &&
2286 wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
2287 int try_opportunistic
;
2288 try_opportunistic
= (ssid
->proactive_key_caching
< 0 ?
2290 ssid
->proactive_key_caching
) &&
2291 (ssid
->proto
& WPA_PROTO_RSN
);
2292 if (pmksa_cache_set_current(wpa_s
->wpa
, NULL
, bss
->bssid
,
2293 ssid
, try_opportunistic
) == 0)
2294 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
);
2295 wpa_ie_len
= sizeof(wpa_ie
);
2296 if (wpa_supplicant_set_suites(wpa_s
, bss
, ssid
,
2297 wpa_ie
, &wpa_ie_len
)) {
2298 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to set WPA "
2299 "key management and encryption suites");
2300 wpas_connect_work_done(wpa_s
);
2303 } else if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) && bss
&&
2304 wpa_key_mgmt_wpa_ieee8021x(ssid
->key_mgmt
)) {
2306 * Both WPA and non-WPA IEEE 802.1X enabled in configuration -
2307 * use non-WPA since the scan results did not indicate that the
2308 * AP is using WPA or WPA2.
2310 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
2312 wpa_s
->wpa_proto
= 0;
2313 } else if (wpa_key_mgmt_wpa_any(ssid
->key_mgmt
)) {
2314 wpa_ie_len
= sizeof(wpa_ie
);
2315 if (wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
2316 wpa_ie
, &wpa_ie_len
)) {
2317 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to set WPA "
2318 "key management and encryption suites (no "
2320 wpas_connect_work_done(wpa_s
);
2324 } else if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
2325 struct wpabuf
*wps_ie
;
2326 wps_ie
= wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid
));
2327 if (wps_ie
&& wpabuf_len(wps_ie
) <= sizeof(wpa_ie
)) {
2328 wpa_ie_len
= wpabuf_len(wps_ie
);
2329 os_memcpy(wpa_ie
, wpabuf_head(wps_ie
), wpa_ie_len
);
2332 wpabuf_free(wps_ie
);
2333 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
2334 if (!bss
|| (bss
->caps
& IEEE80211_CAP_PRIVACY
))
2335 params
.wps
= WPS_MODE_PRIVACY
;
2337 params
.wps
= WPS_MODE_OPEN
;
2338 wpa_s
->wpa_proto
= 0;
2339 #endif /* CONFIG_WPS */
2341 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
2343 wpa_s
->wpa_proto
= 0;
2347 if (wpa_s
->global
->p2p
) {
2351 pos
= wpa_ie
+ wpa_ie_len
;
2352 len
= sizeof(wpa_ie
) - wpa_ie_len
;
2353 res
= wpas_p2p_assoc_req_ie(wpa_s
, bss
, pos
, len
,
2359 wpa_s
->cross_connect_disallowed
= 0;
2362 p2p
= wpa_bss_get_vendor_ie_multi(bss
, P2P_IE_VENDOR_TYPE
);
2364 wpa_s
->cross_connect_disallowed
=
2365 p2p_get_cross_connect_disallowed(p2p
);
2367 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: WLAN AP %s cross "
2369 wpa_s
->cross_connect_disallowed
?
2370 "disallows" : "allows");
2374 os_memset(wpa_s
->p2p_ip_addr_info
, 0, sizeof(wpa_s
->p2p_ip_addr_info
));
2375 #endif /* CONFIG_P2P */
2378 wpa_ie_len
+= wpas_supp_op_class_ie(wpa_s
, bss
->freq
,
2379 wpa_ie
+ wpa_ie_len
,
2385 * Workaround: Add Extended Capabilities element only if the AP
2386 * included this element in Beacon/Probe Response frames. Some older
2387 * APs seem to have interoperability issues if this element is
2388 * included, so while the standard may require us to include the
2389 * element in all cases, it is justifiable to skip it to avoid
2390 * interoperability issues.
2392 if (ssid
->p2p_group
)
2393 wpa_drv_get_ext_capa(wpa_s
, WPA_IF_P2P_CLIENT
);
2395 wpa_drv_get_ext_capa(wpa_s
, WPA_IF_STATION
);
2397 if (!bss
|| wpa_bss_get_ie(bss
, WLAN_EID_EXT_CAPAB
)) {
2400 ext_capab_len
= wpas_build_ext_capab(wpa_s
, ext_capab
,
2402 if (ext_capab_len
> 0) {
2404 if (wpa_ie_len
> 0 && pos
[0] == WLAN_EID_RSN
)
2406 os_memmove(pos
+ ext_capab_len
, pos
,
2407 wpa_ie_len
- (pos
- wpa_ie
));
2408 wpa_ie_len
+= ext_capab_len
;
2409 os_memcpy(pos
, ext_capab
, ext_capab_len
);
2414 if (is_hs20_network(wpa_s
, ssid
, bss
)) {
2415 struct wpabuf
*hs20
;
2417 hs20
= wpabuf_alloc(20);
2419 int pps_mo_id
= hs20_get_pps_mo_id(wpa_s
, ssid
);
2422 wpas_hs20_add_indication(hs20
, pps_mo_id
);
2423 len
= sizeof(wpa_ie
) - wpa_ie_len
;
2424 if (wpabuf_len(hs20
) <= len
) {
2425 os_memcpy(wpa_ie
+ wpa_ie_len
,
2426 wpabuf_head(hs20
), wpabuf_len(hs20
));
2427 wpa_ie_len
+= wpabuf_len(hs20
);
2431 hs20_configure_frame_filters(wpa_s
);
2434 #endif /* CONFIG_HS20 */
2436 if (wpa_s
->vendor_elem
[VENDOR_ELEM_ASSOC_REQ
]) {
2437 struct wpabuf
*buf
= wpa_s
->vendor_elem
[VENDOR_ELEM_ASSOC_REQ
];
2440 len
= sizeof(wpa_ie
) - wpa_ie_len
;
2441 if (wpabuf_len(buf
) <= len
) {
2442 os_memcpy(wpa_ie
+ wpa_ie_len
,
2443 wpabuf_head(buf
), wpabuf_len(buf
));
2444 wpa_ie_len
+= wpabuf_len(buf
);
2449 if (wpa_s
->fst_ies
) {
2450 int fst_ies_len
= wpabuf_len(wpa_s
->fst_ies
);
2452 if (wpa_ie_len
+ fst_ies_len
<= sizeof(wpa_ie
)) {
2453 os_memcpy(wpa_ie
+ wpa_ie_len
,
2454 wpabuf_head(wpa_s
->fst_ies
), fst_ies_len
);
2455 wpa_ie_len
+= fst_ies_len
;
2458 #endif /* CONFIG_FST */
2461 if (bss
&& wpa_bss_get_vendor_ie(bss
, MBO_IE_VENDOR_TYPE
)) {
2464 len
= wpas_mbo_ie(wpa_s
, wpa_ie
+ wpa_ie_len
,
2465 sizeof(wpa_ie
) - wpa_ie_len
);
2469 #endif /* CONFIG_MBO */
2471 wpa_clear_keys(wpa_s
, bss
? bss
->bssid
: NULL
);
2473 cipher_pairwise
= wpa_s
->pairwise_cipher
;
2474 cipher_group
= wpa_s
->group_cipher
;
2475 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2476 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
2477 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
)
2479 if (wpa_set_wep_keys(wpa_s
, ssid
)) {
2484 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
)
2487 #ifdef IEEE8021X_EAPOL
2488 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
2489 if ((ssid
->eapol_flags
&
2490 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
2491 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
)) == 0 &&
2495 /* Assume that dynamic WEP-104 keys will be used and
2496 * set cipher suites in order for drivers to expect
2498 cipher_pairwise
= cipher_group
= WPA_CIPHER_WEP104
;
2501 #endif /* IEEE8021X_EAPOL */
2503 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2504 /* Set the key before (and later after) association */
2505 wpa_supplicant_set_wpa_none_key(wpa_s
, ssid
);
2508 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATING
);
2510 params
.ssid
= bss
->ssid
;
2511 params
.ssid_len
= bss
->ssid_len
;
2512 if (!wpas_driver_bss_selection(wpa_s
) || ssid
->bssid_set
||
2513 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
2514 wpa_printf(MSG_DEBUG
, "Limit connection to BSSID "
2515 MACSTR
" freq=%u MHz based on scan results "
2516 "(bssid_set=%d wps=%d)",
2517 MAC2STR(bss
->bssid
), bss
->freq
,
2519 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
);
2520 params
.bssid
= bss
->bssid
;
2521 params
.freq
.freq
= bss
->freq
;
2523 params
.bssid_hint
= bss
->bssid
;
2524 params
.freq_hint
= bss
->freq
;
2525 params
.pbss
= bss_is_pbss(bss
);
2527 params
.ssid
= ssid
->ssid
;
2528 params
.ssid_len
= ssid
->ssid_len
;
2529 params
.pbss
= (ssid
->pbss
!= 2) ? ssid
->pbss
: 0;
2532 if (ssid
->mode
== WPAS_MODE_IBSS
&& ssid
->bssid_set
&&
2533 wpa_s
->conf
->ap_scan
== 2) {
2534 params
.bssid
= ssid
->bssid
;
2535 params
.fixed_bssid
= 1;
2538 /* Initial frequency for IBSS/mesh */
2539 if ((ssid
->mode
== WPAS_MODE_IBSS
|| ssid
->mode
== WPAS_MODE_MESH
) &&
2540 ssid
->frequency
> 0 && params
.freq
.freq
== 0)
2541 ibss_mesh_setup_freq(wpa_s
, ssid
, ¶ms
.freq
);
2543 if (ssid
->mode
== WPAS_MODE_IBSS
) {
2544 params
.fixed_freq
= ssid
->fixed_freq
;
2545 if (ssid
->beacon_int
)
2546 params
.beacon_int
= ssid
->beacon_int
;
2548 params
.beacon_int
= wpa_s
->conf
->beacon_int
;
2551 params
.wpa_ie
= wpa_ie
;
2552 params
.wpa_ie_len
= wpa_ie_len
;
2553 params
.pairwise_suite
= cipher_pairwise
;
2554 params
.group_suite
= cipher_group
;
2555 params
.key_mgmt_suite
= wpa_s
->key_mgmt
;
2556 params
.wpa_proto
= wpa_s
->wpa_proto
;
2557 params
.auth_alg
= algs
;
2558 params
.mode
= ssid
->mode
;
2559 params
.bg_scan_period
= ssid
->bg_scan_period
;
2560 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
2561 if (ssid
->wep_key_len
[i
])
2562 params
.wep_key
[i
] = ssid
->wep_key
[i
];
2563 params
.wep_key_len
[i
] = ssid
->wep_key_len
[i
];
2565 params
.wep_tx_keyidx
= ssid
->wep_tx_keyidx
;
2567 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
2568 (params
.key_mgmt_suite
== WPA_KEY_MGMT_PSK
||
2569 params
.key_mgmt_suite
== WPA_KEY_MGMT_FT_PSK
)) {
2570 params
.passphrase
= ssid
->passphrase
;
2572 params
.psk
= ssid
->psk
;
2575 if (wpa_s
->conf
->key_mgmt_offload
) {
2576 if (params
.key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X
||
2577 params
.key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SHA256
||
2578 params
.key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SUITE_B
||
2579 params
.key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
)
2580 params
.req_key_mgmt_offload
=
2581 ssid
->proactive_key_caching
< 0 ?
2582 wpa_s
->conf
->okc
: ssid
->proactive_key_caching
;
2584 params
.req_key_mgmt_offload
= 1;
2586 if ((params
.key_mgmt_suite
== WPA_KEY_MGMT_PSK
||
2587 params
.key_mgmt_suite
== WPA_KEY_MGMT_PSK_SHA256
||
2588 params
.key_mgmt_suite
== WPA_KEY_MGMT_FT_PSK
) &&
2590 params
.psk
= ssid
->psk
;
2593 params
.drop_unencrypted
= use_crypt
;
2595 #ifdef CONFIG_IEEE80211W
2596 params
.mgmt_frame_protection
= wpas_get_ssid_pmf(wpa_s
, ssid
);
2597 if (params
.mgmt_frame_protection
!= NO_MGMT_FRAME_PROTECTION
&& bss
) {
2598 const u8
*rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2599 struct wpa_ie_data ie
;
2600 if (rsn
&& wpa_parse_wpa_ie(rsn
, 2 + rsn
[1], &ie
) == 0 &&
2602 (WPA_CAPABILITY_MFPC
| WPA_CAPABILITY_MFPR
)) {
2603 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Selected AP supports "
2604 "MFP: require MFP");
2605 params
.mgmt_frame_protection
=
2606 MGMT_FRAME_PROTECTION_REQUIRED
;
2609 #endif /* CONFIG_IEEE80211W */
2611 params
.p2p
= ssid
->p2p_group
;
2613 if (wpa_s
->p2pdev
->set_sta_uapsd
)
2614 params
.uapsd
= wpa_s
->p2pdev
->sta_uapsd
;
2618 #ifdef CONFIG_HT_OVERRIDES
2619 os_memset(&htcaps
, 0, sizeof(htcaps
));
2620 os_memset(&htcaps_mask
, 0, sizeof(htcaps_mask
));
2621 params
.htcaps
= (u8
*) &htcaps
;
2622 params
.htcaps_mask
= (u8
*) &htcaps_mask
;
2623 wpa_supplicant_apply_ht_overrides(wpa_s
, ssid
, ¶ms
);
2624 #endif /* CONFIG_HT_OVERRIDES */
2625 #ifdef CONFIG_VHT_OVERRIDES
2626 os_memset(&vhtcaps
, 0, sizeof(vhtcaps
));
2627 os_memset(&vhtcaps_mask
, 0, sizeof(vhtcaps_mask
));
2628 params
.vhtcaps
= &vhtcaps
;
2629 params
.vhtcaps_mask
= &vhtcaps_mask
;
2630 wpa_supplicant_apply_vht_overrides(wpa_s
, ssid
, ¶ms
);
2631 #endif /* CONFIG_VHT_OVERRIDES */
2635 * If multi-channel concurrency is not supported, check for any
2636 * frequency conflict. In case of any frequency conflict, remove the
2637 * least prioritized connection.
2639 if (wpa_s
->num_multichan_concurrent
< 2) {
2641 num
= get_shared_radio_freqs(wpa_s
, &freq
, 1);
2642 if (num
> 0 && freq
> 0 && freq
!= params
.freq
.freq
) {
2643 wpa_printf(MSG_DEBUG
,
2644 "Assoc conflicting freq found (%d != %d)",
2645 freq
, params
.freq
.freq
);
2646 if (wpas_p2p_handle_frequency_conflicts(
2647 wpa_s
, params
.freq
.freq
, ssid
) < 0) {
2648 wpas_connect_work_done(wpa_s
);
2653 #endif /* CONFIG_P2P */
2655 if (wpa_s
->reassoc_same_ess
&& !is_zero_ether_addr(prev_bssid
) &&
2656 wpa_s
->current_ssid
)
2657 params
.prev_bssid
= prev_bssid
;
2659 ret
= wpa_drv_associate(wpa_s
, ¶ms
);
2661 wpa_msg(wpa_s
, MSG_INFO
, "Association request to the driver "
2663 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SANE_ERROR_CODES
) {
2665 * The driver is known to mean what is saying, so we
2666 * can stop right here; the association will not
2669 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
2670 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
2671 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
2674 /* try to continue anyway; new association will be tried again
2679 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2680 /* Set the key after the association just in case association
2681 * cleared the previously configured key. */
2682 wpa_supplicant_set_wpa_none_key(wpa_s
, ssid
);
2683 /* No need to timeout authentication since there is no key
2685 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2686 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2687 #ifdef CONFIG_IBSS_RSN
2688 } else if (ssid
->mode
== WPAS_MODE_IBSS
&&
2689 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2690 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
) {
2692 * RSN IBSS authentication is per-STA and we can disable the
2693 * per-BSSID authentication.
2695 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2696 #endif /* CONFIG_IBSS_RSN */
2698 /* Timeout for IEEE 802.11 authentication and association */
2702 /* give IBSS a bit more time */
2703 timeout
= ssid
->mode
== WPAS_MODE_IBSS
? 10 : 5;
2704 } else if (wpa_s
->conf
->ap_scan
== 1) {
2705 /* give IBSS a bit more time */
2706 timeout
= ssid
->mode
== WPAS_MODE_IBSS
? 20 : 10;
2708 wpa_supplicant_req_auth_timeout(wpa_s
, timeout
, 0);
2712 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC
)) {
2713 /* Set static WEP keys again */
2714 wpa_set_wep_keys(wpa_s
, ssid
);
2717 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
) {
2719 * Do not allow EAP session resumption between different
2720 * network configurations.
2722 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2724 old_ssid
= wpa_s
->current_ssid
;
2725 wpa_s
->current_ssid
= ssid
;
2727 if (!wpas_driver_bss_selection(wpa_s
) || ssid
->bssid_set
) {
2728 wpa_s
->current_bss
= bss
;
2730 hs20_configure_frame_filters(wpa_s
);
2731 #endif /* CONFIG_HS20 */
2734 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
2735 wpa_supplicant_initiate_eapol(wpa_s
);
2736 if (old_ssid
!= wpa_s
->current_ssid
)
2737 wpas_notify_network_changed(wpa_s
);
2741 static void wpa_supplicant_clear_connection(struct wpa_supplicant
*wpa_s
,
2744 struct wpa_ssid
*old_ssid
;
2746 wpas_connect_work_done(wpa_s
);
2747 wpa_clear_keys(wpa_s
, addr
);
2748 old_ssid
= wpa_s
->current_ssid
;
2749 wpa_supplicant_mark_disassoc(wpa_s
);
2750 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
2751 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
2752 if (old_ssid
!= wpa_s
->current_ssid
)
2753 wpas_notify_network_changed(wpa_s
);
2754 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
2759 * wpa_supplicant_deauthenticate - Deauthenticate the current connection
2760 * @wpa_s: Pointer to wpa_supplicant data
2761 * @reason_code: IEEE 802.11 reason code for the deauthenticate frame
2763 * This function is used to request %wpa_supplicant to deauthenticate from the
2766 void wpa_supplicant_deauthenticate(struct wpa_supplicant
*wpa_s
,
2770 union wpa_event_data event
;
2773 wpa_dbg(wpa_s
, MSG_DEBUG
, "Request to deauthenticate - bssid=" MACSTR
2774 " pending_bssid=" MACSTR
" reason=%d state=%s",
2775 MAC2STR(wpa_s
->bssid
), MAC2STR(wpa_s
->pending_bssid
),
2776 reason_code
, wpa_supplicant_state_txt(wpa_s
->wpa_state
));
2778 if (!is_zero_ether_addr(wpa_s
->pending_bssid
) &&
2779 (wpa_s
->wpa_state
== WPA_AUTHENTICATING
||
2780 wpa_s
->wpa_state
== WPA_ASSOCIATING
))
2781 addr
= wpa_s
->pending_bssid
;
2782 else if (!is_zero_ether_addr(wpa_s
->bssid
))
2783 addr
= wpa_s
->bssid
;
2784 else if (wpa_s
->wpa_state
== WPA_ASSOCIATING
) {
2786 * When using driver-based BSS selection, we may not know the
2787 * BSSID with which we are currently trying to associate. We
2788 * need to notify the driver of this disconnection even in such
2789 * a case, so use the all zeros address here.
2791 addr
= wpa_s
->bssid
;
2796 wpa_tdls_teardown_peers(wpa_s
->wpa
);
2797 #endif /* CONFIG_TDLS */
2801 wpa_msg(wpa_s
, MSG_INFO
, MESH_GROUP_REMOVED
"%s",
2803 wpa_supplicant_leave_mesh(wpa_s
);
2805 #endif /* CONFIG_MESH */
2808 wpa_drv_deauthenticate(wpa_s
, addr
, reason_code
);
2809 os_memset(&event
, 0, sizeof(event
));
2810 event
.deauth_info
.reason_code
= (u16
) reason_code
;
2811 event
.deauth_info
.locally_generated
= 1;
2812 wpa_supplicant_event(wpa_s
, EVENT_DEAUTH
, &event
);
2817 wpa_supplicant_clear_connection(wpa_s
, addr
);
2820 static void wpa_supplicant_enable_one_network(struct wpa_supplicant
*wpa_s
,
2821 struct wpa_ssid
*ssid
)
2823 if (!ssid
|| !ssid
->disabled
|| ssid
->disabled
== 2)
2827 wpas_clear_temp_disabled(wpa_s
, ssid
, 1);
2828 wpas_notify_network_enabled_changed(wpa_s
, ssid
);
2831 * Try to reassociate since there is no current configuration and a new
2832 * network was made available.
2834 if (!wpa_s
->current_ssid
&& !wpa_s
->disconnected
)
2835 wpa_s
->reassociate
= 1;
2840 * wpa_supplicant_add_network - Add a new network
2841 * @wpa_s: wpa_supplicant structure for a network interface
2842 * Returns: The new network configuration or %NULL if operation failed
2844 * This function performs the following operations:
2845 * 1. Adds a new network.
2846 * 2. Send network addition notification.
2847 * 3. Marks the network disabled.
2848 * 4. Set network default parameters.
2850 struct wpa_ssid
* wpa_supplicant_add_network(struct wpa_supplicant
*wpa_s
)
2852 struct wpa_ssid
*ssid
;
2854 ssid
= wpa_config_add_network(wpa_s
->conf
);
2857 wpas_notify_network_added(wpa_s
, ssid
);
2859 wpa_config_set_network_defaults(ssid
);
2866 * wpa_supplicant_remove_network - Remove a configured network based on id
2867 * @wpa_s: wpa_supplicant structure for a network interface
2868 * @id: Unique network id to search for
2869 * Returns: 0 on success, or -1 if the network was not found, -2 if the network
2870 * could not be removed
2872 * This function performs the following operations:
2873 * 1. Removes the network.
2874 * 2. Send network removal notification.
2875 * 3. Update internal state machines.
2876 * 4. Stop any running sched scans.
2878 int wpa_supplicant_remove_network(struct wpa_supplicant
*wpa_s
, int id
)
2880 struct wpa_ssid
*ssid
;
2883 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2886 wpas_notify_network_removed(wpa_s
, ssid
);
2888 if (wpa_s
->last_ssid
== ssid
)
2889 wpa_s
->last_ssid
= NULL
;
2891 if (ssid
== wpa_s
->current_ssid
|| !wpa_s
->current_ssid
) {
2893 wpa_s
->sme
.prev_bssid_set
= 0;
2894 #endif /* CONFIG_SME */
2896 * Invalidate the EAP session cache if the current or
2897 * previously used network is removed.
2899 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2902 if (ssid
== wpa_s
->current_ssid
) {
2903 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
2904 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
2906 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
2907 wpa_s
->own_disconnect_req
= 1;
2908 wpa_supplicant_deauthenticate(wpa_s
,
2909 WLAN_REASON_DEAUTH_LEAVING
);
2912 was_disabled
= ssid
->disabled
;
2914 if (wpa_config_remove_network(wpa_s
->conf
, id
) < 0)
2917 if (!was_disabled
&& wpa_s
->sched_scanning
) {
2918 wpa_printf(MSG_DEBUG
,
2919 "Stop ongoing sched_scan to remove network from filters");
2920 wpa_supplicant_cancel_sched_scan(wpa_s
);
2921 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2929 * wpa_supplicant_enable_network - Mark a configured network as enabled
2930 * @wpa_s: wpa_supplicant structure for a network interface
2931 * @ssid: wpa_ssid structure for a configured network or %NULL
2933 * Enables the specified network or all networks if no network specified.
2935 void wpa_supplicant_enable_network(struct wpa_supplicant
*wpa_s
,
2936 struct wpa_ssid
*ssid
)
2939 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
)
2940 wpa_supplicant_enable_one_network(wpa_s
, ssid
);
2942 wpa_supplicant_enable_one_network(wpa_s
, ssid
);
2944 if (wpa_s
->reassociate
&& !wpa_s
->disconnected
&&
2945 (!wpa_s
->current_ssid
||
2946 wpa_s
->wpa_state
== WPA_DISCONNECTED
||
2947 wpa_s
->wpa_state
== WPA_SCANNING
)) {
2948 if (wpa_s
->sched_scanning
) {
2949 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to add "
2950 "new network to scan filters");
2951 wpa_supplicant_cancel_sched_scan(wpa_s
);
2954 if (wpa_supplicant_fast_associate(wpa_s
) != 1) {
2955 wpa_s
->scan_req
= NORMAL_SCAN_REQ
;
2956 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2963 * wpa_supplicant_disable_network - Mark a configured network as disabled
2964 * @wpa_s: wpa_supplicant structure for a network interface
2965 * @ssid: wpa_ssid structure for a configured network or %NULL
2967 * Disables the specified network or all networks if no network specified.
2969 void wpa_supplicant_disable_network(struct wpa_supplicant
*wpa_s
,
2970 struct wpa_ssid
*ssid
)
2972 struct wpa_ssid
*other_ssid
;
2976 if (wpa_s
->sched_scanning
)
2977 wpa_supplicant_cancel_sched_scan(wpa_s
);
2979 for (other_ssid
= wpa_s
->conf
->ssid
; other_ssid
;
2980 other_ssid
= other_ssid
->next
) {
2981 was_disabled
= other_ssid
->disabled
;
2982 if (was_disabled
== 2)
2983 continue; /* do not change persistent P2P group
2986 other_ssid
->disabled
= 1;
2988 if (was_disabled
!= other_ssid
->disabled
)
2989 wpas_notify_network_enabled_changed(
2992 if (wpa_s
->current_ssid
)
2993 wpa_supplicant_deauthenticate(
2994 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2995 } else if (ssid
->disabled
!= 2) {
2996 if (ssid
== wpa_s
->current_ssid
)
2997 wpa_supplicant_deauthenticate(
2998 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3000 was_disabled
= ssid
->disabled
;
3004 if (was_disabled
!= ssid
->disabled
) {
3005 wpas_notify_network_enabled_changed(wpa_s
, ssid
);
3006 if (wpa_s
->sched_scanning
) {
3007 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan "
3008 "to remove network from filters");
3009 wpa_supplicant_cancel_sched_scan(wpa_s
);
3010 wpa_supplicant_req_scan(wpa_s
, 0, 0);
3018 * wpa_supplicant_select_network - Attempt association with a network
3019 * @wpa_s: wpa_supplicant structure for a network interface
3020 * @ssid: wpa_ssid structure for a configured network or %NULL for any network
3022 void wpa_supplicant_select_network(struct wpa_supplicant
*wpa_s
,
3023 struct wpa_ssid
*ssid
)
3026 struct wpa_ssid
*other_ssid
;
3027 int disconnected
= 0;
3029 if (ssid
&& ssid
!= wpa_s
->current_ssid
&& wpa_s
->current_ssid
) {
3030 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
3031 wpa_s
->own_disconnect_req
= 1;
3032 wpa_supplicant_deauthenticate(
3033 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3038 wpas_clear_temp_disabled(wpa_s
, ssid
, 1);
3041 * Mark all other networks disabled or mark all networks enabled if no
3042 * network specified.
3044 for (other_ssid
= wpa_s
->conf
->ssid
; other_ssid
;
3045 other_ssid
= other_ssid
->next
) {
3046 int was_disabled
= other_ssid
->disabled
;
3047 if (was_disabled
== 2)
3048 continue; /* do not change persistent P2P group data */
3050 other_ssid
->disabled
= ssid
? (ssid
->id
!= other_ssid
->id
) : 0;
3051 if (was_disabled
&& !other_ssid
->disabled
)
3052 wpas_clear_temp_disabled(wpa_s
, other_ssid
, 0);
3054 if (was_disabled
!= other_ssid
->disabled
)
3055 wpas_notify_network_enabled_changed(wpa_s
, other_ssid
);
3058 if (ssid
&& ssid
== wpa_s
->current_ssid
&& wpa_s
->current_ssid
&&
3059 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
3060 /* We are already associated with the selected network */
3061 wpa_printf(MSG_DEBUG
, "Already associated with the "
3062 "selected network - do nothing");
3067 wpa_s
->current_ssid
= ssid
;
3068 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
3069 wpa_s
->connect_without_scan
=
3070 (ssid
->mode
== WPAS_MODE_MESH
) ? ssid
: NULL
;
3073 * Don't optimize next scan freqs since a new ESS has been
3076 os_free(wpa_s
->next_scan_freqs
);
3077 wpa_s
->next_scan_freqs
= NULL
;
3079 wpa_s
->connect_without_scan
= NULL
;
3082 wpa_s
->disconnected
= 0;
3083 wpa_s
->reassociate
= 1;
3085 if (wpa_s
->connect_without_scan
||
3086 wpa_supplicant_fast_associate(wpa_s
) != 1) {
3087 wpa_s
->scan_req
= NORMAL_SCAN_REQ
;
3088 wpas_scan_reset_sched_scan(wpa_s
);
3089 wpa_supplicant_req_scan(wpa_s
, 0, disconnected
? 100000 : 0);
3093 wpas_notify_network_selected(wpa_s
, ssid
);
3098 * wpas_set_pkcs11_engine_and_module_path - Set PKCS #11 engine and module path
3099 * @wpa_s: wpa_supplicant structure for a network interface
3100 * @pkcs11_engine_path: PKCS #11 engine path or NULL
3101 * @pkcs11_module_path: PKCS #11 module path or NULL
3102 * Returns: 0 on success; -1 on failure
3104 * Sets the PKCS #11 engine and module path. Both have to be NULL or a valid
3105 * path. If resetting the EAPOL state machine with the new PKCS #11 engine and
3106 * module path fails the paths will be reset to the default value (NULL).
3108 int wpas_set_pkcs11_engine_and_module_path(struct wpa_supplicant
*wpa_s
,
3109 const char *pkcs11_engine_path
,
3110 const char *pkcs11_module_path
)
3112 char *pkcs11_engine_path_copy
= NULL
;
3113 char *pkcs11_module_path_copy
= NULL
;
3115 if (pkcs11_engine_path
!= NULL
) {
3116 pkcs11_engine_path_copy
= os_strdup(pkcs11_engine_path
);
3117 if (pkcs11_engine_path_copy
== NULL
)
3120 if (pkcs11_module_path
!= NULL
) {
3121 pkcs11_module_path_copy
= os_strdup(pkcs11_module_path
);
3122 if (pkcs11_module_path_copy
== NULL
) {
3123 os_free(pkcs11_engine_path_copy
);
3128 os_free(wpa_s
->conf
->pkcs11_engine_path
);
3129 os_free(wpa_s
->conf
->pkcs11_module_path
);
3130 wpa_s
->conf
->pkcs11_engine_path
= pkcs11_engine_path_copy
;
3131 wpa_s
->conf
->pkcs11_module_path
= pkcs11_module_path_copy
;
3133 wpa_sm_set_eapol(wpa_s
->wpa
, NULL
);
3134 eapol_sm_deinit(wpa_s
->eapol
);
3135 wpa_s
->eapol
= NULL
;
3136 if (wpa_supplicant_init_eapol(wpa_s
)) {
3137 /* Error -> Reset paths to the default value (NULL) once. */
3138 if (pkcs11_engine_path
!= NULL
&& pkcs11_module_path
!= NULL
)
3139 wpas_set_pkcs11_engine_and_module_path(wpa_s
, NULL
,
3144 wpa_sm_set_eapol(wpa_s
->wpa
, wpa_s
->eapol
);
3151 * wpa_supplicant_set_ap_scan - Set AP scan mode for interface
3152 * @wpa_s: wpa_supplicant structure for a network interface
3153 * @ap_scan: AP scan mode
3154 * Returns: 0 if succeed or -1 if ap_scan has an invalid value
3157 int wpa_supplicant_set_ap_scan(struct wpa_supplicant
*wpa_s
, int ap_scan
)
3162 if (ap_scan
< 0 || ap_scan
> 2)
3165 if (ap_scan
== 2 && os_strcmp(wpa_s
->driver
->name
, "nl80211") == 0) {
3166 wpa_printf(MSG_INFO
,
3167 "Note: nl80211 driver interface is not designed to be used with ap_scan=2; this can result in connection failures");
3171 if (ap_scan
== 2 && ap_scan
!= wpa_s
->conf
->ap_scan
&&
3172 wpa_s
->wpa_state
>= WPA_ASSOCIATING
&&
3173 wpa_s
->wpa_state
< WPA_COMPLETED
) {
3174 wpa_printf(MSG_ERROR
, "ap_scan = %d (%d) rejected while "
3175 "associating", wpa_s
->conf
->ap_scan
, ap_scan
);
3178 #endif /* ANDROID */
3180 old_ap_scan
= wpa_s
->conf
->ap_scan
;
3181 wpa_s
->conf
->ap_scan
= ap_scan
;
3183 if (old_ap_scan
!= wpa_s
->conf
->ap_scan
)
3184 wpas_notify_ap_scan_changed(wpa_s
);
3191 * wpa_supplicant_set_bss_expiration_age - Set BSS entry expiration age
3192 * @wpa_s: wpa_supplicant structure for a network interface
3193 * @expire_age: Expiration age in seconds
3194 * Returns: 0 if succeed or -1 if expire_age has an invalid value
3197 int wpa_supplicant_set_bss_expiration_age(struct wpa_supplicant
*wpa_s
,
3198 unsigned int bss_expire_age
)
3200 if (bss_expire_age
< 10) {
3201 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid bss expiration age %u",
3205 wpa_msg(wpa_s
, MSG_DEBUG
, "Setting bss expiration age: %d sec",
3207 wpa_s
->conf
->bss_expiration_age
= bss_expire_age
;
3214 * wpa_supplicant_set_bss_expiration_count - Set BSS entry expiration scan count
3215 * @wpa_s: wpa_supplicant structure for a network interface
3216 * @expire_count: number of scans after which an unseen BSS is reclaimed
3217 * Returns: 0 if succeed or -1 if expire_count has an invalid value
3220 int wpa_supplicant_set_bss_expiration_count(struct wpa_supplicant
*wpa_s
,
3221 unsigned int bss_expire_count
)
3223 if (bss_expire_count
< 1) {
3224 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid bss expiration count %u",
3228 wpa_msg(wpa_s
, MSG_DEBUG
, "Setting bss expiration scan count: %u",
3230 wpa_s
->conf
->bss_expiration_scan_count
= bss_expire_count
;
3237 * wpa_supplicant_set_scan_interval - Set scan interval
3238 * @wpa_s: wpa_supplicant structure for a network interface
3239 * @scan_interval: scan interval in seconds
3240 * Returns: 0 if succeed or -1 if scan_interval has an invalid value
3243 int wpa_supplicant_set_scan_interval(struct wpa_supplicant
*wpa_s
,
3246 if (scan_interval
< 0) {
3247 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid scan interval %d",
3251 wpa_msg(wpa_s
, MSG_DEBUG
, "Setting scan interval: %d sec",
3253 wpa_supplicant_update_scan_int(wpa_s
, scan_interval
);
3260 * wpa_supplicant_set_debug_params - Set global debug params
3261 * @global: wpa_global structure
3262 * @debug_level: debug level
3263 * @debug_timestamp: determines if show timestamp in debug data
3264 * @debug_show_keys: determines if show keys in debug data
3265 * Returns: 0 if succeed or -1 if debug_level has wrong value
3267 int wpa_supplicant_set_debug_params(struct wpa_global
*global
, int debug_level
,
3268 int debug_timestamp
, int debug_show_keys
)
3271 int old_level
, old_timestamp
, old_show_keys
;
3273 /* check for allowed debuglevels */
3274 if (debug_level
!= MSG_EXCESSIVE
&&
3275 debug_level
!= MSG_MSGDUMP
&&
3276 debug_level
!= MSG_DEBUG
&&
3277 debug_level
!= MSG_INFO
&&
3278 debug_level
!= MSG_WARNING
&&
3279 debug_level
!= MSG_ERROR
)
3282 old_level
= wpa_debug_level
;
3283 old_timestamp
= wpa_debug_timestamp
;
3284 old_show_keys
= wpa_debug_show_keys
;
3286 wpa_debug_level
= debug_level
;
3287 wpa_debug_timestamp
= debug_timestamp
? 1 : 0;
3288 wpa_debug_show_keys
= debug_show_keys
? 1 : 0;
3290 if (wpa_debug_level
!= old_level
)
3291 wpas_notify_debug_level_changed(global
);
3292 if (wpa_debug_timestamp
!= old_timestamp
)
3293 wpas_notify_debug_timestamp_changed(global
);
3294 if (wpa_debug_show_keys
!= old_show_keys
)
3295 wpas_notify_debug_show_keys_changed(global
);
3302 * wpa_supplicant_get_ssid - Get a pointer to the current network structure
3303 * @wpa_s: Pointer to wpa_supplicant data
3304 * Returns: A pointer to the current network structure or %NULL on failure
3306 struct wpa_ssid
* wpa_supplicant_get_ssid(struct wpa_supplicant
*wpa_s
)
3308 struct wpa_ssid
*entry
;
3309 u8 ssid
[SSID_MAX_LEN
];
3315 res
= wpa_drv_get_ssid(wpa_s
, ssid
);
3317 wpa_msg(wpa_s
, MSG_WARNING
, "Could not read SSID from "
3323 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0) {
3324 wpa_msg(wpa_s
, MSG_WARNING
, "Could not read BSSID from "
3329 wired
= wpa_s
->conf
->ap_scan
== 0 &&
3330 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
);
3332 entry
= wpa_s
->conf
->ssid
;
3334 if (!wpas_network_disabled(wpa_s
, entry
) &&
3335 ((ssid_len
== entry
->ssid_len
&&
3336 os_memcmp(ssid
, entry
->ssid
, ssid_len
) == 0) || wired
) &&
3337 (!entry
->bssid_set
||
3338 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0))
3341 if (!wpas_network_disabled(wpa_s
, entry
) &&
3342 (entry
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
3343 (entry
->ssid
== NULL
|| entry
->ssid_len
== 0) &&
3344 (!entry
->bssid_set
||
3345 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0))
3347 #endif /* CONFIG_WPS */
3349 if (!wpas_network_disabled(wpa_s
, entry
) && entry
->bssid_set
&&
3350 entry
->ssid_len
== 0 &&
3351 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0)
3354 entry
= entry
->next
;
3361 static int select_driver(struct wpa_supplicant
*wpa_s
, int i
)
3363 struct wpa_global
*global
= wpa_s
->global
;
3365 if (wpa_drivers
[i
]->global_init
&& global
->drv_priv
[i
] == NULL
) {
3366 global
->drv_priv
[i
] = wpa_drivers
[i
]->global_init(global
);
3367 if (global
->drv_priv
[i
] == NULL
) {
3368 wpa_printf(MSG_ERROR
, "Failed to initialize driver "
3369 "'%s'", wpa_drivers
[i
]->name
);
3374 wpa_s
->driver
= wpa_drivers
[i
];
3375 wpa_s
->global_drv_priv
= global
->drv_priv
[i
];
3381 static int wpa_supplicant_set_driver(struct wpa_supplicant
*wpa_s
,
3386 const char *pos
, *driver
= name
;
3391 if (wpa_drivers
[0] == NULL
) {
3392 wpa_msg(wpa_s
, MSG_ERROR
, "No driver interfaces build into "
3398 /* default to first driver in the list */
3399 return select_driver(wpa_s
, 0);
3403 pos
= os_strchr(driver
, ',');
3407 len
= os_strlen(driver
);
3409 for (i
= 0; wpa_drivers
[i
]; i
++) {
3410 if (os_strlen(wpa_drivers
[i
]->name
) == len
&&
3411 os_strncmp(driver
, wpa_drivers
[i
]->name
, len
) ==
3413 /* First driver that succeeds wins */
3414 if (select_driver(wpa_s
, i
) == 0)
3422 wpa_msg(wpa_s
, MSG_ERROR
, "Unsupported driver '%s'", name
);
3428 * wpa_supplicant_rx_eapol - Deliver a received EAPOL frame to wpa_supplicant
3429 * @ctx: Context pointer (wpa_s); this is the ctx variable registered
3430 * with struct wpa_driver_ops::init()
3431 * @src_addr: Source address of the EAPOL frame
3432 * @buf: EAPOL data starting from the EAPOL header (i.e., no Ethernet header)
3433 * @len: Length of the EAPOL data
3435 * This function is called for each received EAPOL frame. Most driver
3436 * interfaces rely on more generic OS mechanism for receiving frames through
3437 * l2_packet, but if such a mechanism is not available, the driver wrapper may
3438 * take care of received EAPOL frames and deliver them to the core supplicant
3439 * code by calling this function.
3441 void wpa_supplicant_rx_eapol(void *ctx
, const u8
*src_addr
,
3442 const u8
*buf
, size_t len
)
3444 struct wpa_supplicant
*wpa_s
= ctx
;
3446 wpa_dbg(wpa_s
, MSG_DEBUG
, "RX EAPOL from " MACSTR
, MAC2STR(src_addr
));
3447 wpa_hexdump(MSG_MSGDUMP
, "RX EAPOL", buf
, len
);
3449 #ifdef CONFIG_TESTING_OPTIONS
3450 if (wpa_s
->ignore_auth_resp
) {
3451 wpa_printf(MSG_INFO
, "RX EAPOL - ignore_auth_resp active!");
3454 #endif /* CONFIG_TESTING_OPTIONS */
3456 #ifdef CONFIG_PEERKEY
3457 if (wpa_s
->wpa_state
> WPA_ASSOCIATED
&& wpa_s
->current_ssid
&&
3458 wpa_s
->current_ssid
->peerkey
&&
3459 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
3460 wpa_sm_rx_eapol_peerkey(wpa_s
->wpa
, src_addr
, buf
, len
) == 1) {
3461 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: Processed PeerKey EAPOL-Key");
3464 #endif /* CONFIG_PEERKEY */
3466 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
||
3467 (wpa_s
->last_eapol_matches_bssid
&&
3470 #endif /* CONFIG_AP */
3471 os_memcmp(src_addr
, wpa_s
->bssid
, ETH_ALEN
) != 0)) {
3473 * There is possible race condition between receiving the
3474 * association event and the EAPOL frame since they are coming
3475 * through different paths from the driver. In order to avoid
3476 * issues in trying to process the EAPOL frame before receiving
3477 * association information, lets queue it for processing until
3478 * the association event is received. This may also be needed in
3479 * driver-based roaming case, so also use src_addr != BSSID as a
3480 * trigger if we have previously confirmed that the
3481 * Authenticator uses BSSID as the src_addr (which is not the
3482 * case with wired IEEE 802.1X).
3484 wpa_dbg(wpa_s
, MSG_DEBUG
, "Not associated - Delay processing "
3485 "of received EAPOL frame (state=%s bssid=" MACSTR
")",
3486 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
3487 MAC2STR(wpa_s
->bssid
));
3488 wpabuf_free(wpa_s
->pending_eapol_rx
);
3489 wpa_s
->pending_eapol_rx
= wpabuf_alloc_copy(buf
, len
);
3490 if (wpa_s
->pending_eapol_rx
) {
3491 os_get_reltime(&wpa_s
->pending_eapol_rx_time
);
3492 os_memcpy(wpa_s
->pending_eapol_rx_src
, src_addr
,
3498 wpa_s
->last_eapol_matches_bssid
=
3499 os_memcmp(src_addr
, wpa_s
->bssid
, ETH_ALEN
) == 0;
3502 if (wpa_s
->ap_iface
) {
3503 wpa_supplicant_ap_rx_eapol(wpa_s
, src_addr
, buf
, len
);
3506 #endif /* CONFIG_AP */
3508 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
) {
3509 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignored received EAPOL frame since "
3510 "no key management is configured");
3514 if (wpa_s
->eapol_received
== 0 &&
3515 (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) ||
3516 !wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
3517 wpa_s
->wpa_state
!= WPA_COMPLETED
) &&
3518 (wpa_s
->current_ssid
== NULL
||
3519 wpa_s
->current_ssid
->mode
!= IEEE80211_MODE_IBSS
)) {
3520 /* Timeout for completing IEEE 802.1X and WPA authentication */
3523 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
3524 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
||
3525 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
3526 /* Use longer timeout for IEEE 802.1X/EAP */
3531 if (wpa_s
->current_ssid
&& wpa_s
->current_bss
&&
3532 (wpa_s
->current_ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
3533 eap_is_wps_pin_enrollee(&wpa_s
->current_ssid
->eap
)) {
3535 * Use shorter timeout if going through WPS AP iteration
3536 * for PIN config method with an AP that does not
3537 * advertise Selected Registrar.
3539 struct wpabuf
*wps_ie
;
3541 wps_ie
= wpa_bss_get_vendor_ie_multi(
3542 wpa_s
->current_bss
, WPS_IE_VENDOR_TYPE
);
3544 !wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 1))
3546 wpabuf_free(wps_ie
);
3548 #endif /* CONFIG_WPS */
3550 wpa_supplicant_req_auth_timeout(wpa_s
, timeout
, 0);
3552 wpa_s
->eapol_received
++;
3554 if (wpa_s
->countermeasures
) {
3555 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Countermeasures - dropped "
3560 #ifdef CONFIG_IBSS_RSN
3561 if (wpa_s
->current_ssid
&&
3562 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
) {
3563 ibss_rsn_rx_eapol(wpa_s
->ibss_rsn
, src_addr
, buf
, len
);
3566 #endif /* CONFIG_IBSS_RSN */
3568 /* Source address of the incoming EAPOL frame could be compared to the
3569 * current BSSID. However, it is possible that a centralized
3570 * Authenticator could be using another MAC address than the BSSID of
3571 * an AP, so just allow any address to be used for now. The replies are
3572 * still sent to the current BSSID (if available), though. */
3574 os_memcpy(wpa_s
->last_eapol_src
, src_addr
, ETH_ALEN
);
3575 if (!wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) &&
3576 eapol_sm_rx_eapol(wpa_s
->eapol
, src_addr
, buf
, len
) > 0)
3578 wpa_drv_poll(wpa_s
);
3579 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
))
3580 wpa_sm_rx_eapol(wpa_s
->wpa
, src_addr
, buf
, len
);
3581 else if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
3583 * Set portValid = TRUE here since we are going to skip 4-way
3584 * handshake processing which would normally set portValid. We
3585 * need this to allow the EAPOL state machines to be completed
3586 * without going through EAPOL-Key handshake.
3588 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
3593 int wpa_supplicant_update_mac_addr(struct wpa_supplicant
*wpa_s
)
3595 if ((!wpa_s
->p2p_mgmt
||
3596 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
)) &&
3597 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE
)) {
3598 l2_packet_deinit(wpa_s
->l2
);
3599 wpa_s
->l2
= l2_packet_init(wpa_s
->ifname
,
3600 wpa_drv_get_mac_addr(wpa_s
),
3602 wpa_supplicant_rx_eapol
, wpa_s
, 0);
3603 if (wpa_s
->l2
== NULL
)
3606 const u8
*addr
= wpa_drv_get_mac_addr(wpa_s
);
3608 os_memcpy(wpa_s
->own_addr
, addr
, ETH_ALEN
);
3611 if (wpa_s
->l2
&& l2_packet_get_own_addr(wpa_s
->l2
, wpa_s
->own_addr
)) {
3612 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to get own L2 address");
3616 wpa_sm_set_own_addr(wpa_s
->wpa
, wpa_s
->own_addr
);
3622 static void wpa_supplicant_rx_eapol_bridge(void *ctx
, const u8
*src_addr
,
3623 const u8
*buf
, size_t len
)
3625 struct wpa_supplicant
*wpa_s
= ctx
;
3626 const struct l2_ethhdr
*eth
;
3628 if (len
< sizeof(*eth
))
3630 eth
= (const struct l2_ethhdr
*) buf
;
3632 if (os_memcmp(eth
->h_dest
, wpa_s
->own_addr
, ETH_ALEN
) != 0 &&
3633 !(eth
->h_dest
[0] & 0x01)) {
3634 wpa_dbg(wpa_s
, MSG_DEBUG
, "RX EAPOL from " MACSTR
" to " MACSTR
3635 " (bridge - not for this interface - ignore)",
3636 MAC2STR(src_addr
), MAC2STR(eth
->h_dest
));
3640 wpa_dbg(wpa_s
, MSG_DEBUG
, "RX EAPOL from " MACSTR
" to " MACSTR
3641 " (bridge)", MAC2STR(src_addr
), MAC2STR(eth
->h_dest
));
3642 wpa_supplicant_rx_eapol(wpa_s
, src_addr
, buf
+ sizeof(*eth
),
3643 len
- sizeof(*eth
));
3648 * wpa_supplicant_driver_init - Initialize driver interface parameters
3649 * @wpa_s: Pointer to wpa_supplicant data
3650 * Returns: 0 on success, -1 on failure
3652 * This function is called to initialize driver interface parameters.
3653 * wpa_drv_init() must have been called before this function to initialize the
3656 int wpa_supplicant_driver_init(struct wpa_supplicant
*wpa_s
)
3658 static int interface_count
= 0;
3660 if (wpa_supplicant_update_mac_addr(wpa_s
) < 0)
3663 wpa_dbg(wpa_s
, MSG_DEBUG
, "Own MAC address: " MACSTR
,
3664 MAC2STR(wpa_s
->own_addr
));
3665 os_memcpy(wpa_s
->perm_addr
, wpa_s
->own_addr
, ETH_ALEN
);
3666 wpa_sm_set_own_addr(wpa_s
->wpa
, wpa_s
->own_addr
);
3668 if (wpa_s
->bridge_ifname
[0]) {
3669 wpa_dbg(wpa_s
, MSG_DEBUG
, "Receiving packets from bridge "
3670 "interface '%s'", wpa_s
->bridge_ifname
);
3671 wpa_s
->l2_br
= l2_packet_init_bridge(
3672 wpa_s
->bridge_ifname
, wpa_s
->ifname
, wpa_s
->own_addr
,
3673 ETH_P_EAPOL
, wpa_supplicant_rx_eapol_bridge
, wpa_s
, 1);
3674 if (wpa_s
->l2_br
== NULL
) {
3675 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to open l2_packet "
3676 "connection for the bridge interface '%s'",
3677 wpa_s
->bridge_ifname
);
3682 if (wpa_s
->conf
->ap_scan
== 2 &&
3683 os_strcmp(wpa_s
->driver
->name
, "nl80211") == 0) {
3684 wpa_printf(MSG_INFO
,
3685 "Note: nl80211 driver interface is not designed to be used with ap_scan=2; this can result in connection failures");
3688 wpa_clear_keys(wpa_s
, NULL
);
3690 /* Make sure that TKIP countermeasures are not left enabled (could
3691 * happen if wpa_supplicant is killed during countermeasures. */
3692 wpa_drv_set_countermeasures(wpa_s
, 0);
3694 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: flushing PMKID list in the driver");
3695 wpa_drv_flush_pmkid(wpa_s
);
3697 wpa_s
->prev_scan_ssid
= WILDCARD_SSID_SCAN
;
3698 wpa_s
->prev_scan_wildcard
= 0;
3700 if (wpa_supplicant_enabled_networks(wpa_s
)) {
3701 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
3702 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
3703 interface_count
= 0;
3706 if (!wpa_s
->p2p_mgmt
&&
3707 wpa_supplicant_delayed_sched_scan(wpa_s
,
3708 interface_count
% 3,
3710 wpa_supplicant_req_scan(wpa_s
, interface_count
% 3,
3712 #endif /* ANDROID */
3715 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
3721 static int wpa_supplicant_daemon(const char *pid_file
)
3723 wpa_printf(MSG_DEBUG
, "Daemonize..");
3724 return os_daemonize(pid_file
);
3728 static struct wpa_supplicant
*
3729 wpa_supplicant_alloc(struct wpa_supplicant
*parent
)
3731 struct wpa_supplicant
*wpa_s
;
3733 wpa_s
= os_zalloc(sizeof(*wpa_s
));
3736 wpa_s
->scan_req
= INITIAL_SCAN_REQ
;
3737 wpa_s
->scan_interval
= 5;
3738 wpa_s
->new_connection
= 1;
3739 wpa_s
->parent
= parent
? parent
: wpa_s
;
3740 wpa_s
->p2pdev
= wpa_s
->parent
;
3741 wpa_s
->sched_scanning
= 0;
3743 dl_list_init(&wpa_s
->bss_tmp_disallowed
);
3744 dl_list_init(&wpa_s
->fils_hlp_req
);
3750 #ifdef CONFIG_HT_OVERRIDES
3752 static int wpa_set_htcap_mcs(struct wpa_supplicant
*wpa_s
,
3753 struct ieee80211_ht_capabilities
*htcaps
,
3754 struct ieee80211_ht_capabilities
*htcaps_mask
,
3757 /* parse ht_mcs into hex array */
3759 const char *tmp
= ht_mcs
;
3762 /* If ht_mcs is null, do not set anything */
3766 /* This is what we are setting in the kernel */
3767 os_memset(&htcaps
->supported_mcs_set
, 0, IEEE80211_HT_MCS_MASK_LEN
);
3769 wpa_msg(wpa_s
, MSG_DEBUG
, "set_htcap, ht_mcs -:%s:-", ht_mcs
);
3771 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++) {
3775 v
= strtol(tmp
, &end
, 16);
3778 wpa_msg(wpa_s
, MSG_DEBUG
,
3779 "htcap value[%i]: %ld end: %p tmp: %p",
3784 htcaps
->supported_mcs_set
[i
] = v
;
3787 wpa_msg(wpa_s
, MSG_ERROR
,
3788 "Failed to parse ht-mcs: %s, error: %s\n",
3789 ht_mcs
, strerror(errno
));
3795 * If we were able to parse any values, then set mask for the MCS set.
3798 os_memset(&htcaps_mask
->supported_mcs_set
, 0xff,
3799 IEEE80211_HT_MCS_MASK_LEN
- 1);
3800 /* skip the 3 reserved bits */
3801 htcaps_mask
->supported_mcs_set
[IEEE80211_HT_MCS_MASK_LEN
- 1] =
3809 static int wpa_disable_max_amsdu(struct wpa_supplicant
*wpa_s
,
3810 struct ieee80211_ht_capabilities
*htcaps
,
3811 struct ieee80211_ht_capabilities
*htcaps_mask
,
3816 wpa_msg(wpa_s
, MSG_DEBUG
, "set_disable_max_amsdu: %d", disabled
);
3821 msk
= host_to_le16(HT_CAP_INFO_MAX_AMSDU_SIZE
);
3822 htcaps_mask
->ht_capabilities_info
|= msk
;
3824 htcaps
->ht_capabilities_info
&= msk
;
3826 htcaps
->ht_capabilities_info
|= msk
;
3832 static int wpa_set_ampdu_factor(struct wpa_supplicant
*wpa_s
,
3833 struct ieee80211_ht_capabilities
*htcaps
,
3834 struct ieee80211_ht_capabilities
*htcaps_mask
,
3837 wpa_msg(wpa_s
, MSG_DEBUG
, "set_ampdu_factor: %d", factor
);
3842 if (factor
< 0 || factor
> 3) {
3843 wpa_msg(wpa_s
, MSG_ERROR
, "ampdu_factor: %d out of range. "
3844 "Must be 0-3 or -1", factor
);
3848 htcaps_mask
->a_mpdu_params
|= 0x3; /* 2 bits for factor */
3849 htcaps
->a_mpdu_params
&= ~0x3;
3850 htcaps
->a_mpdu_params
|= factor
& 0x3;
3856 static int wpa_set_ampdu_density(struct wpa_supplicant
*wpa_s
,
3857 struct ieee80211_ht_capabilities
*htcaps
,
3858 struct ieee80211_ht_capabilities
*htcaps_mask
,
3861 wpa_msg(wpa_s
, MSG_DEBUG
, "set_ampdu_density: %d", density
);
3866 if (density
< 0 || density
> 7) {
3867 wpa_msg(wpa_s
, MSG_ERROR
,
3868 "ampdu_density: %d out of range. Must be 0-7 or -1.",
3873 htcaps_mask
->a_mpdu_params
|= 0x1C;
3874 htcaps
->a_mpdu_params
&= ~(0x1C);
3875 htcaps
->a_mpdu_params
|= (density
<< 2) & 0x1C;
3881 static int wpa_set_disable_ht40(struct wpa_supplicant
*wpa_s
,
3882 struct ieee80211_ht_capabilities
*htcaps
,
3883 struct ieee80211_ht_capabilities
*htcaps_mask
,
3886 wpa_msg(wpa_s
, MSG_DEBUG
, "set_disable_ht40: %d", disabled
);
3888 set_disable_ht40(htcaps
, disabled
);
3889 set_disable_ht40(htcaps_mask
, 0);
3895 static int wpa_set_disable_sgi(struct wpa_supplicant
*wpa_s
,
3896 struct ieee80211_ht_capabilities
*htcaps
,
3897 struct ieee80211_ht_capabilities
*htcaps_mask
,
3900 /* Masking these out disables SGI */
3901 le16 msk
= host_to_le16(HT_CAP_INFO_SHORT_GI20MHZ
|
3902 HT_CAP_INFO_SHORT_GI40MHZ
);
3904 wpa_msg(wpa_s
, MSG_DEBUG
, "set_disable_sgi: %d", disabled
);
3907 htcaps
->ht_capabilities_info
&= ~msk
;
3909 htcaps
->ht_capabilities_info
|= msk
;
3911 htcaps_mask
->ht_capabilities_info
|= msk
;
3917 static int wpa_set_disable_ldpc(struct wpa_supplicant
*wpa_s
,
3918 struct ieee80211_ht_capabilities
*htcaps
,
3919 struct ieee80211_ht_capabilities
*htcaps_mask
,
3922 /* Masking these out disables LDPC */
3923 le16 msk
= host_to_le16(HT_CAP_INFO_LDPC_CODING_CAP
);
3925 wpa_msg(wpa_s
, MSG_DEBUG
, "set_disable_ldpc: %d", disabled
);
3928 htcaps
->ht_capabilities_info
&= ~msk
;
3930 htcaps
->ht_capabilities_info
|= msk
;
3932 htcaps_mask
->ht_capabilities_info
|= msk
;
3938 void wpa_supplicant_apply_ht_overrides(
3939 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
3940 struct wpa_driver_associate_params
*params
)
3942 struct ieee80211_ht_capabilities
*htcaps
;
3943 struct ieee80211_ht_capabilities
*htcaps_mask
;
3948 params
->disable_ht
= ssid
->disable_ht
;
3949 if (!params
->htcaps
|| !params
->htcaps_mask
)
3952 htcaps
= (struct ieee80211_ht_capabilities
*) params
->htcaps
;
3953 htcaps_mask
= (struct ieee80211_ht_capabilities
*) params
->htcaps_mask
;
3954 wpa_set_htcap_mcs(wpa_s
, htcaps
, htcaps_mask
, ssid
->ht_mcs
);
3955 wpa_disable_max_amsdu(wpa_s
, htcaps
, htcaps_mask
,
3956 ssid
->disable_max_amsdu
);
3957 wpa_set_ampdu_factor(wpa_s
, htcaps
, htcaps_mask
, ssid
->ampdu_factor
);
3958 wpa_set_ampdu_density(wpa_s
, htcaps
, htcaps_mask
, ssid
->ampdu_density
);
3959 wpa_set_disable_ht40(wpa_s
, htcaps
, htcaps_mask
, ssid
->disable_ht40
);
3960 wpa_set_disable_sgi(wpa_s
, htcaps
, htcaps_mask
, ssid
->disable_sgi
);
3961 wpa_set_disable_ldpc(wpa_s
, htcaps
, htcaps_mask
, ssid
->disable_ldpc
);
3963 if (ssid
->ht40_intolerant
) {
3964 le16 bit
= host_to_le16(HT_CAP_INFO_40MHZ_INTOLERANT
);
3965 htcaps
->ht_capabilities_info
|= bit
;
3966 htcaps_mask
->ht_capabilities_info
|= bit
;
3970 #endif /* CONFIG_HT_OVERRIDES */
3973 #ifdef CONFIG_VHT_OVERRIDES
3974 void wpa_supplicant_apply_vht_overrides(
3975 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
3976 struct wpa_driver_associate_params
*params
)
3978 struct ieee80211_vht_capabilities
*vhtcaps
;
3979 struct ieee80211_vht_capabilities
*vhtcaps_mask
;
3984 params
->disable_vht
= ssid
->disable_vht
;
3986 vhtcaps
= (void *) params
->vhtcaps
;
3987 vhtcaps_mask
= (void *) params
->vhtcaps_mask
;
3989 if (!vhtcaps
|| !vhtcaps_mask
)
3992 vhtcaps
->vht_capabilities_info
= host_to_le32(ssid
->vht_capa
);
3993 vhtcaps_mask
->vht_capabilities_info
= host_to_le32(ssid
->vht_capa_mask
);
3995 #ifdef CONFIG_HT_OVERRIDES
3996 /* if max ampdu is <= 3, we have to make the HT cap the same */
3997 if (ssid
->vht_capa_mask
& VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX
) {
4000 max_ampdu
= (ssid
->vht_capa
&
4001 VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX
) >>
4002 VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX_SHIFT
;
4004 max_ampdu
= max_ampdu
< 3 ? max_ampdu
: 3;
4005 wpa_set_ampdu_factor(wpa_s
,
4006 (void *) params
->htcaps
,
4007 (void *) params
->htcaps_mask
,
4010 #endif /* CONFIG_HT_OVERRIDES */
4012 #define OVERRIDE_MCS(i) \
4013 if (ssid->vht_tx_mcs_nss_ ##i >= 0) { \
4014 vhtcaps_mask->vht_supported_mcs_set.tx_map |= \
4015 host_to_le16(3 << 2 * (i - 1)); \
4016 vhtcaps->vht_supported_mcs_set.tx_map |= \
4017 host_to_le16(ssid->vht_tx_mcs_nss_ ##i << \
4020 if (ssid->vht_rx_mcs_nss_ ##i >= 0) { \
4021 vhtcaps_mask->vht_supported_mcs_set.rx_map |= \
4022 host_to_le16(3 << 2 * (i - 1)); \
4023 vhtcaps->vht_supported_mcs_set.rx_map |= \
4024 host_to_le16(ssid->vht_rx_mcs_nss_ ##i << \
4037 #endif /* CONFIG_VHT_OVERRIDES */
4040 static int pcsc_reader_init(struct wpa_supplicant
*wpa_s
)
4045 if (!wpa_s
->conf
->pcsc_reader
)
4048 wpa_s
->scard
= scard_init(wpa_s
->conf
->pcsc_reader
);
4052 if (wpa_s
->conf
->pcsc_pin
&&
4053 scard_set_pin(wpa_s
->scard
, wpa_s
->conf
->pcsc_pin
) < 0) {
4054 scard_deinit(wpa_s
->scard
);
4055 wpa_s
->scard
= NULL
;
4056 wpa_msg(wpa_s
, MSG_ERROR
, "PC/SC PIN validation failed");
4060 len
= sizeof(wpa_s
->imsi
) - 1;
4061 if (scard_get_imsi(wpa_s
->scard
, wpa_s
->imsi
, &len
)) {
4062 scard_deinit(wpa_s
->scard
);
4063 wpa_s
->scard
= NULL
;
4064 wpa_msg(wpa_s
, MSG_ERROR
, "Could not read IMSI");
4067 wpa_s
->imsi
[len
] = '\0';
4069 wpa_s
->mnc_len
= scard_get_mnc_len(wpa_s
->scard
);
4071 wpa_printf(MSG_DEBUG
, "SCARD: IMSI %s (MNC length %d)",
4072 wpa_s
->imsi
, wpa_s
->mnc_len
);
4074 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
4075 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
4076 #endif /* PCSC_FUNCS */
4082 int wpas_init_ext_pw(struct wpa_supplicant
*wpa_s
)
4086 ext_password_deinit(wpa_s
->ext_pw
);
4087 wpa_s
->ext_pw
= NULL
;
4088 eapol_sm_set_ext_pw_ctx(wpa_s
->eapol
, NULL
);
4090 if (!wpa_s
->conf
->ext_password_backend
)
4093 val
= os_strdup(wpa_s
->conf
->ext_password_backend
);
4096 pos
= os_strchr(val
, ':');
4100 wpa_printf(MSG_DEBUG
, "EXT PW: Initialize backend '%s'", val
);
4102 wpa_s
->ext_pw
= ext_password_init(val
, pos
);
4104 if (wpa_s
->ext_pw
== NULL
) {
4105 wpa_printf(MSG_DEBUG
, "EXT PW: Failed to initialize backend");
4108 eapol_sm_set_ext_pw_ctx(wpa_s
->eapol
, wpa_s
->ext_pw
);
4116 static const u8
* wpas_fst_get_bssid_cb(void *ctx
)
4118 struct wpa_supplicant
*wpa_s
= ctx
;
4120 return (is_zero_ether_addr(wpa_s
->bssid
) ||
4121 wpa_s
->wpa_state
!= WPA_COMPLETED
) ? NULL
: wpa_s
->bssid
;
4125 static void wpas_fst_get_channel_info_cb(void *ctx
,
4126 enum hostapd_hw_mode
*hw_mode
,
4129 struct wpa_supplicant
*wpa_s
= ctx
;
4131 if (wpa_s
->current_bss
) {
4132 *hw_mode
= ieee80211_freq_to_chan(wpa_s
->current_bss
->freq
,
4134 } else if (wpa_s
->hw
.num_modes
) {
4135 *hw_mode
= wpa_s
->hw
.modes
[0].mode
;
4143 static int wpas_fst_get_hw_modes(void *ctx
, struct hostapd_hw_modes
**modes
)
4145 struct wpa_supplicant
*wpa_s
= ctx
;
4147 *modes
= wpa_s
->hw
.modes
;
4148 return wpa_s
->hw
.num_modes
;
4152 static void wpas_fst_set_ies_cb(void *ctx
, const struct wpabuf
*fst_ies
)
4154 struct wpa_supplicant
*wpa_s
= ctx
;
4156 wpa_hexdump_buf(MSG_DEBUG
, "FST: Set IEs", fst_ies
);
4157 wpa_s
->fst_ies
= fst_ies
;
4161 static int wpas_fst_send_action_cb(void *ctx
, const u8
*da
, struct wpabuf
*data
)
4163 struct wpa_supplicant
*wpa_s
= ctx
;
4165 if (os_memcmp(wpa_s
->bssid
, da
, ETH_ALEN
) != 0) {
4166 wpa_printf(MSG_INFO
, "FST:%s:bssid=" MACSTR
" != da=" MACSTR
,
4167 __func__
, MAC2STR(wpa_s
->bssid
), MAC2STR(da
));
4170 return wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
4171 wpa_s
->own_addr
, wpa_s
->bssid
,
4172 wpabuf_head(data
), wpabuf_len(data
),
4177 static const struct wpabuf
* wpas_fst_get_mb_ie_cb(void *ctx
, const u8
*addr
)
4179 struct wpa_supplicant
*wpa_s
= ctx
;
4181 WPA_ASSERT(os_memcmp(wpa_s
->bssid
, addr
, ETH_ALEN
) == 0);
4182 return wpa_s
->received_mb_ies
;
4186 static void wpas_fst_update_mb_ie_cb(void *ctx
, const u8
*addr
,
4187 const u8
*buf
, size_t size
)
4189 struct wpa_supplicant
*wpa_s
= ctx
;
4190 struct mb_ies_info info
;
4192 WPA_ASSERT(os_memcmp(wpa_s
->bssid
, addr
, ETH_ALEN
) == 0);
4194 if (!mb_ies_info_by_ies(&info
, buf
, size
)) {
4195 wpabuf_free(wpa_s
->received_mb_ies
);
4196 wpa_s
->received_mb_ies
= mb_ies_by_info(&info
);
4201 static const u8
* wpas_fst_get_peer_first(void *ctx
,
4202 struct fst_get_peer_ctx
**get_ctx
,
4205 struct wpa_supplicant
*wpa_s
= ctx
;
4208 if (!is_zero_ether_addr(wpa_s
->bssid
))
4209 return (wpa_s
->received_mb_ies
|| !mb_only
) ?
4210 wpa_s
->bssid
: NULL
;
4215 static const u8
* wpas_fst_get_peer_next(void *ctx
,
4216 struct fst_get_peer_ctx
**get_ctx
,
4222 void fst_wpa_supplicant_fill_iface_obj(struct wpa_supplicant
*wpa_s
,
4223 struct fst_wpa_obj
*iface_obj
)
4225 iface_obj
->ctx
= wpa_s
;
4226 iface_obj
->get_bssid
= wpas_fst_get_bssid_cb
;
4227 iface_obj
->get_channel_info
= wpas_fst_get_channel_info_cb
;
4228 iface_obj
->get_hw_modes
= wpas_fst_get_hw_modes
;
4229 iface_obj
->set_ies
= wpas_fst_set_ies_cb
;
4230 iface_obj
->send_action
= wpas_fst_send_action_cb
;
4231 iface_obj
->get_mb_ie
= wpas_fst_get_mb_ie_cb
;
4232 iface_obj
->update_mb_ie
= wpas_fst_update_mb_ie_cb
;
4233 iface_obj
->get_peer_first
= wpas_fst_get_peer_first
;
4234 iface_obj
->get_peer_next
= wpas_fst_get_peer_next
;
4236 #endif /* CONFIG_FST */
4238 static int wpas_set_wowlan_triggers(struct wpa_supplicant
*wpa_s
,
4239 const struct wpa_driver_capa
*capa
)
4241 struct wowlan_triggers
*triggers
;
4244 if (!wpa_s
->conf
->wowlan_triggers
)
4247 triggers
= wpa_get_wowlan_triggers(wpa_s
->conf
->wowlan_triggers
, capa
);
4249 ret
= wpa_drv_wowlan(wpa_s
, triggers
);
4256 enum wpa_radio_work_band
wpas_freq_to_band(int freq
)
4259 return BAND_2_4_GHZ
;
4266 unsigned int wpas_get_bands(struct wpa_supplicant
*wpa_s
, const int *freqs
)
4269 unsigned int band
= 0;
4272 /* freqs are specified for the radio work */
4273 for (i
= 0; freqs
[i
]; i
++)
4274 band
|= wpas_freq_to_band(freqs
[i
]);
4277 * freqs are not specified, implies all
4278 * the supported freqs by HW
4280 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
4281 if (wpa_s
->hw
.modes
[i
].num_channels
!= 0) {
4282 if (wpa_s
->hw
.modes
[i
].mode
==
4283 HOSTAPD_MODE_IEEE80211B
||
4284 wpa_s
->hw
.modes
[i
].mode
==
4285 HOSTAPD_MODE_IEEE80211G
)
4286 band
|= BAND_2_4_GHZ
;
4287 else if (wpa_s
->hw
.modes
[i
].mode
==
4288 HOSTAPD_MODE_IEEE80211A
)
4290 else if (wpa_s
->hw
.modes
[i
].mode
==
4291 HOSTAPD_MODE_IEEE80211AD
)
4292 band
|= BAND_60_GHZ
;
4293 else if (wpa_s
->hw
.modes
[i
].mode
==
4294 HOSTAPD_MODE_IEEE80211ANY
)
4295 band
= BAND_2_4_GHZ
| BAND_5_GHZ
|
4305 static struct wpa_radio
* radio_add_interface(struct wpa_supplicant
*wpa_s
,
4308 struct wpa_supplicant
*iface
= wpa_s
->global
->ifaces
;
4309 struct wpa_radio
*radio
;
4311 while (rn
&& iface
) {
4312 radio
= iface
->radio
;
4313 if (radio
&& os_strcmp(rn
, radio
->name
) == 0) {
4314 wpa_printf(MSG_DEBUG
, "Add interface %s to existing radio %s",
4316 dl_list_add(&radio
->ifaces
, &wpa_s
->radio_list
);
4320 iface
= iface
->next
;
4323 wpa_printf(MSG_DEBUG
, "Add interface %s to a new radio %s",
4324 wpa_s
->ifname
, rn
? rn
: "N/A");
4325 radio
= os_zalloc(sizeof(*radio
));
4330 os_strlcpy(radio
->name
, rn
, sizeof(radio
->name
));
4331 dl_list_init(&radio
->ifaces
);
4332 dl_list_init(&radio
->work
);
4333 dl_list_add(&radio
->ifaces
, &wpa_s
->radio_list
);
4339 static void radio_work_free(struct wpa_radio_work
*work
)
4341 if (work
->wpa_s
->scan_work
== work
) {
4342 /* This should not really happen. */
4343 wpa_dbg(work
->wpa_s
, MSG_INFO
, "Freeing radio work '%s'@%p (started=%d) that is marked as scan_work",
4344 work
->type
, work
, work
->started
);
4345 work
->wpa_s
->scan_work
= NULL
;
4349 if (work
->wpa_s
->p2p_scan_work
== work
) {
4350 /* This should not really happen. */
4351 wpa_dbg(work
->wpa_s
, MSG_INFO
, "Freeing radio work '%s'@%p (started=%d) that is marked as p2p_scan_work",
4352 work
->type
, work
, work
->started
);
4353 work
->wpa_s
->p2p_scan_work
= NULL
;
4355 #endif /* CONFIG_P2P */
4357 if (work
->started
) {
4358 work
->wpa_s
->radio
->num_active_works
--;
4359 wpa_dbg(work
->wpa_s
, MSG_DEBUG
,
4360 "radio_work_free('%s'@%p: num_active_works --> %u",
4362 work
->wpa_s
->radio
->num_active_works
);
4365 dl_list_del(&work
->list
);
4370 static int radio_work_is_connect(struct wpa_radio_work
*work
)
4372 return os_strcmp(work
->type
, "sme-connect") == 0 ||
4373 os_strcmp(work
->type
, "connect") == 0;
4377 static int radio_work_is_scan(struct wpa_radio_work
*work
)
4379 return os_strcmp(work
->type
, "scan") == 0 ||
4380 os_strcmp(work
->type
, "p2p-scan") == 0;
4384 static struct wpa_radio_work
* radio_work_get_next_work(struct wpa_radio
*radio
)
4386 struct wpa_radio_work
*active_work
= NULL
;
4387 struct wpa_radio_work
*tmp
;
4389 /* Get the active work to know the type and band. */
4390 dl_list_for_each(tmp
, &radio
->work
, struct wpa_radio_work
, list
) {
4398 /* No active work, start one */
4399 radio
->num_active_works
= 0;
4400 dl_list_for_each(tmp
, &radio
->work
, struct wpa_radio_work
,
4402 if (os_strcmp(tmp
->type
, "scan") == 0 &&
4403 radio
->external_scan_running
&&
4404 (((struct wpa_driver_scan_params
*)
4405 tmp
->ctx
)->only_new_results
||
4406 tmp
->wpa_s
->clear_driver_scan_cache
))
4413 if (radio_work_is_connect(active_work
)) {
4415 * If the active work is either connect or sme-connect,
4416 * do not parallelize them with other radio works.
4418 wpa_dbg(active_work
->wpa_s
, MSG_DEBUG
,
4419 "Do not parallelize radio work with %s",
4424 dl_list_for_each(tmp
, &radio
->work
, struct wpa_radio_work
, list
) {
4429 * If connect or sme-connect are enqueued, parallelize only
4430 * those operations ahead of them in the queue.
4432 if (radio_work_is_connect(tmp
))
4435 /* Serialize parallel scan and p2p_scan operations on the same
4436 * interface since the driver_nl80211 mechanism for tracking
4437 * scan cookies does not yet have support for this. */
4438 if (active_work
->wpa_s
== tmp
->wpa_s
&&
4439 radio_work_is_scan(active_work
) &&
4440 radio_work_is_scan(tmp
)) {
4441 wpa_dbg(active_work
->wpa_s
, MSG_DEBUG
,
4442 "Do not start work '%s' when another work '%s' is already scheduled",
4443 tmp
->type
, active_work
->type
);
4447 * Check that the radio works are distinct and
4448 * on different bands.
4450 if (os_strcmp(active_work
->type
, tmp
->type
) != 0 &&
4451 (active_work
->bands
!= tmp
->bands
)) {
4453 * If a scan has to be scheduled through nl80211 scan
4454 * interface and if an external scan is already running,
4455 * do not schedule the scan since it is likely to get
4456 * rejected by kernel.
4458 if (os_strcmp(tmp
->type
, "scan") == 0 &&
4459 radio
->external_scan_running
&&
4460 (((struct wpa_driver_scan_params
*)
4461 tmp
->ctx
)->only_new_results
||
4462 tmp
->wpa_s
->clear_driver_scan_cache
))
4465 wpa_dbg(active_work
->wpa_s
, MSG_DEBUG
,
4466 "active_work:%s new_work:%s",
4467 active_work
->type
, tmp
->type
);
4472 /* Did not find a radio work to schedule in parallel. */
4477 static void radio_start_next_work(void *eloop_ctx
, void *timeout_ctx
)
4479 struct wpa_radio
*radio
= eloop_ctx
;
4480 struct wpa_radio_work
*work
;
4481 struct os_reltime now
, diff
;
4482 struct wpa_supplicant
*wpa_s
;
4484 work
= dl_list_first(&radio
->work
, struct wpa_radio_work
, list
);
4486 radio
->num_active_works
= 0;
4490 wpa_s
= dl_list_first(&radio
->ifaces
, struct wpa_supplicant
,
4494 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS
)) {
4496 return; /* already started and still in progress */
4498 if (wpa_s
&& wpa_s
->radio
->external_scan_running
) {
4499 wpa_printf(MSG_DEBUG
, "Delay radio work start until externally triggered scan completes");
4504 if (radio
->num_active_works
< MAX_ACTIVE_WORKS
) {
4505 /* get the work to schedule next */
4506 work
= radio_work_get_next_work(radio
);
4512 wpa_s
= work
->wpa_s
;
4513 os_get_reltime(&now
);
4514 os_reltime_sub(&now
, &work
->time
, &diff
);
4515 wpa_dbg(wpa_s
, MSG_DEBUG
,
4516 "Starting radio work '%s'@%p after %ld.%06ld second wait",
4517 work
->type
, work
, diff
.sec
, diff
.usec
);
4520 radio
->num_active_works
++;
4524 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS
) &&
4525 radio
->num_active_works
< MAX_ACTIVE_WORKS
)
4526 radio_work_check_next(wpa_s
);
4531 * This function removes both started and pending radio works running on
4532 * the provided interface's radio.
4533 * Prior to the removal of the radio work, its callback (cb) is called with
4534 * deinit set to be 1. Each work's callback is responsible for clearing its
4535 * internal data and restoring to a correct state.
4536 * @wpa_s: wpa_supplicant data
4537 * @type: type of works to be removed
4538 * @remove_all: 1 to remove all the works on this radio, 0 to remove only
4539 * this interface's works.
4541 void radio_remove_works(struct wpa_supplicant
*wpa_s
,
4542 const char *type
, int remove_all
)
4544 struct wpa_radio_work
*work
, *tmp
;
4545 struct wpa_radio
*radio
= wpa_s
->radio
;
4547 dl_list_for_each_safe(work
, tmp
, &radio
->work
, struct wpa_radio_work
,
4549 if (type
&& os_strcmp(type
, work
->type
) != 0)
4552 /* skip other ifaces' works */
4553 if (!remove_all
&& work
->wpa_s
!= wpa_s
)
4556 wpa_dbg(wpa_s
, MSG_DEBUG
, "Remove radio work '%s'@%p%s",
4557 work
->type
, work
, work
->started
? " (started)" : "");
4559 radio_work_free(work
);
4562 /* in case we removed the started work */
4563 radio_work_check_next(wpa_s
);
4567 static void radio_remove_interface(struct wpa_supplicant
*wpa_s
)
4569 struct wpa_radio
*radio
= wpa_s
->radio
;
4574 wpa_printf(MSG_DEBUG
, "Remove interface %s from radio %s",
4575 wpa_s
->ifname
, radio
->name
);
4576 dl_list_del(&wpa_s
->radio_list
);
4577 radio_remove_works(wpa_s
, NULL
, 0);
4578 wpa_s
->radio
= NULL
;
4579 if (!dl_list_empty(&radio
->ifaces
))
4580 return; /* Interfaces remain for this radio */
4582 wpa_printf(MSG_DEBUG
, "Remove radio %s", radio
->name
);
4583 eloop_cancel_timeout(radio_start_next_work
, radio
, NULL
);
4588 void radio_work_check_next(struct wpa_supplicant
*wpa_s
)
4590 struct wpa_radio
*radio
= wpa_s
->radio
;
4592 if (dl_list_empty(&radio
->work
))
4594 if (wpa_s
->ext_work_in_progress
) {
4595 wpa_printf(MSG_DEBUG
,
4596 "External radio work in progress - delay start of pending item");
4599 eloop_cancel_timeout(radio_start_next_work
, radio
, NULL
);
4600 eloop_register_timeout(0, 0, radio_start_next_work
, radio
, NULL
);
4605 * radio_add_work - Add a radio work item
4606 * @wpa_s: Pointer to wpa_supplicant data
4607 * @freq: Frequency of the offchannel operation in MHz or 0
4608 * @type: Unique identifier for each type of work
4609 * @next: Force as the next work to be executed
4610 * @cb: Callback function for indicating when radio is available
4611 * @ctx: Context pointer for the work (work->ctx in cb())
4612 * Returns: 0 on success, -1 on failure
4614 * This function is used to request time for an operation that requires
4615 * exclusive radio control. Once the radio is available, the registered callback
4616 * function will be called. radio_work_done() must be called once the exclusive
4617 * radio operation has been completed, so that the radio is freed for other
4618 * operations. The special case of deinit=1 is used to free the context data
4619 * during interface removal. That does not allow the callback function to start
4620 * the radio operation, i.e., it must free any resources allocated for the radio
4623 * The @freq parameter can be used to indicate a single channel on which the
4624 * offchannel operation will occur. This may allow multiple radio work
4625 * operations to be performed in parallel if they apply for the same channel.
4626 * Setting this to 0 indicates that the work item may use multiple channels or
4627 * requires exclusive control of the radio.
4629 int radio_add_work(struct wpa_supplicant
*wpa_s
, unsigned int freq
,
4630 const char *type
, int next
,
4631 void (*cb
)(struct wpa_radio_work
*work
, int deinit
),
4634 struct wpa_radio
*radio
= wpa_s
->radio
;
4635 struct wpa_radio_work
*work
;
4638 work
= os_zalloc(sizeof(*work
));
4641 wpa_dbg(wpa_s
, MSG_DEBUG
, "Add radio work '%s'@%p", type
, work
);
4642 os_get_reltime(&work
->time
);
4645 work
->wpa_s
= wpa_s
;
4650 work
->bands
= wpas_freq_to_band(freq
);
4651 else if (os_strcmp(type
, "scan") == 0 ||
4652 os_strcmp(type
, "p2p-scan") == 0)
4653 work
->bands
= wpas_get_bands(wpa_s
,
4654 ((struct wpa_driver_scan_params
*)
4657 work
->bands
= wpas_get_bands(wpa_s
, NULL
);
4659 was_empty
= dl_list_empty(&wpa_s
->radio
->work
);
4661 dl_list_add(&wpa_s
->radio
->work
, &work
->list
);
4663 dl_list_add_tail(&wpa_s
->radio
->work
, &work
->list
);
4665 wpa_dbg(wpa_s
, MSG_DEBUG
, "First radio work item in the queue - schedule start immediately");
4666 radio_work_check_next(wpa_s
);
4667 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS
)
4668 && radio
->num_active_works
< MAX_ACTIVE_WORKS
) {
4669 wpa_dbg(wpa_s
, MSG_DEBUG
,
4670 "Try to schedule a radio work (num_active_works=%u)",
4671 radio
->num_active_works
);
4672 radio_work_check_next(wpa_s
);
4680 * radio_work_done - Indicate that a radio work item has been completed
4681 * @work: Completed work
4683 * This function is called once the callback function registered with
4684 * radio_add_work() has completed its work.
4686 void radio_work_done(struct wpa_radio_work
*work
)
4688 struct wpa_supplicant
*wpa_s
= work
->wpa_s
;
4689 struct os_reltime now
, diff
;
4690 unsigned int started
= work
->started
;
4692 os_get_reltime(&now
);
4693 os_reltime_sub(&now
, &work
->time
, &diff
);
4694 wpa_dbg(wpa_s
, MSG_DEBUG
, "Radio work '%s'@%p %s in %ld.%06ld seconds",
4695 work
->type
, work
, started
? "done" : "canceled",
4696 diff
.sec
, diff
.usec
);
4697 radio_work_free(work
);
4699 radio_work_check_next(wpa_s
);
4703 struct wpa_radio_work
*
4704 radio_work_pending(struct wpa_supplicant
*wpa_s
, const char *type
)
4706 struct wpa_radio_work
*work
;
4707 struct wpa_radio
*radio
= wpa_s
->radio
;
4709 dl_list_for_each(work
, &radio
->work
, struct wpa_radio_work
, list
) {
4710 if (work
->wpa_s
== wpa_s
&& os_strcmp(work
->type
, type
) == 0)
4718 static int wpas_init_driver(struct wpa_supplicant
*wpa_s
,
4719 struct wpa_interface
*iface
)
4721 const char *ifname
, *driver
, *rn
;
4723 driver
= iface
->driver
;
4725 if (wpa_supplicant_set_driver(wpa_s
, driver
) < 0)
4728 wpa_s
->drv_priv
= wpa_drv_init(wpa_s
, wpa_s
->ifname
);
4729 if (wpa_s
->drv_priv
== NULL
) {
4731 pos
= driver
? os_strchr(driver
, ',') : NULL
;
4733 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to initialize "
4734 "driver interface - try next driver wrapper");
4738 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to initialize driver "
4742 if (wpa_drv_set_param(wpa_s
, wpa_s
->conf
->driver_param
) < 0) {
4743 wpa_msg(wpa_s
, MSG_ERROR
, "Driver interface rejected "
4744 "driver_param '%s'", wpa_s
->conf
->driver_param
);
4748 ifname
= wpa_drv_get_ifname(wpa_s
);
4749 if (ifname
&& os_strcmp(ifname
, wpa_s
->ifname
) != 0) {
4750 wpa_dbg(wpa_s
, MSG_DEBUG
, "Driver interface replaced "
4751 "interface name with '%s'", ifname
);
4752 os_strlcpy(wpa_s
->ifname
, ifname
, sizeof(wpa_s
->ifname
));
4755 rn
= wpa_driver_get_radio_name(wpa_s
);
4756 if (rn
&& rn
[0] == '\0')
4759 wpa_s
->radio
= radio_add_interface(wpa_s
, rn
);
4760 if (wpa_s
->radio
== NULL
)
4767 static int wpa_supplicant_init_iface(struct wpa_supplicant
*wpa_s
,
4768 struct wpa_interface
*iface
)
4770 struct wpa_driver_capa capa
;
4773 wpa_printf(MSG_DEBUG
, "Initializing interface '%s' conf '%s' driver "
4774 "'%s' ctrl_interface '%s' bridge '%s'", iface
->ifname
,
4775 iface
->confname
? iface
->confname
: "N/A",
4776 iface
->driver
? iface
->driver
: "default",
4777 iface
->ctrl_interface
? iface
->ctrl_interface
: "N/A",
4778 iface
->bridge_ifname
? iface
->bridge_ifname
: "N/A");
4780 if (iface
->confname
) {
4781 #ifdef CONFIG_BACKEND_FILE
4782 wpa_s
->confname
= os_rel2abs_path(iface
->confname
);
4783 if (wpa_s
->confname
== NULL
) {
4784 wpa_printf(MSG_ERROR
, "Failed to get absolute path "
4785 "for configuration file '%s'.",
4789 wpa_printf(MSG_DEBUG
, "Configuration file '%s' -> '%s'",
4790 iface
->confname
, wpa_s
->confname
);
4791 #else /* CONFIG_BACKEND_FILE */
4792 wpa_s
->confname
= os_strdup(iface
->confname
);
4793 #endif /* CONFIG_BACKEND_FILE */
4794 wpa_s
->conf
= wpa_config_read(wpa_s
->confname
, NULL
);
4795 if (wpa_s
->conf
== NULL
) {
4796 wpa_printf(MSG_ERROR
, "Failed to read or parse "
4797 "configuration '%s'.", wpa_s
->confname
);
4800 wpa_s
->confanother
= os_rel2abs_path(iface
->confanother
);
4801 wpa_config_read(wpa_s
->confanother
, wpa_s
->conf
);
4804 * Override ctrl_interface and driver_param if set on command
4807 if (iface
->ctrl_interface
) {
4808 os_free(wpa_s
->conf
->ctrl_interface
);
4809 wpa_s
->conf
->ctrl_interface
=
4810 os_strdup(iface
->ctrl_interface
);
4813 if (iface
->driver_param
) {
4814 os_free(wpa_s
->conf
->driver_param
);
4815 wpa_s
->conf
->driver_param
=
4816 os_strdup(iface
->driver_param
);
4819 if (iface
->p2p_mgmt
&& !iface
->ctrl_interface
) {
4820 os_free(wpa_s
->conf
->ctrl_interface
);
4821 wpa_s
->conf
->ctrl_interface
= NULL
;
4824 wpa_s
->conf
= wpa_config_alloc_empty(iface
->ctrl_interface
,
4825 iface
->driver_param
);
4827 if (wpa_s
->conf
== NULL
) {
4828 wpa_printf(MSG_ERROR
, "\nNo configuration found.");
4832 if (iface
->ifname
== NULL
) {
4833 wpa_printf(MSG_ERROR
, "\nInterface name is required.");
4836 if (os_strlen(iface
->ifname
) >= sizeof(wpa_s
->ifname
)) {
4837 wpa_printf(MSG_ERROR
, "\nToo long interface name '%s'.",
4841 os_strlcpy(wpa_s
->ifname
, iface
->ifname
, sizeof(wpa_s
->ifname
));
4843 if (iface
->bridge_ifname
) {
4844 if (os_strlen(iface
->bridge_ifname
) >=
4845 sizeof(wpa_s
->bridge_ifname
)) {
4846 wpa_printf(MSG_ERROR
, "\nToo long bridge interface "
4847 "name '%s'.", iface
->bridge_ifname
);
4850 os_strlcpy(wpa_s
->bridge_ifname
, iface
->bridge_ifname
,
4851 sizeof(wpa_s
->bridge_ifname
));
4854 /* RSNA Supplicant Key Management - INITIALIZE */
4855 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
4856 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
4858 /* Initialize driver interface and register driver event handler before
4859 * L2 receive handler so that association events are processed before
4860 * EAPOL-Key packets if both become available for the same select()
4862 if (wpas_init_driver(wpa_s
, iface
) < 0)
4865 if (wpa_supplicant_init_wpa(wpa_s
) < 0)
4868 wpa_sm_set_ifname(wpa_s
->wpa
, wpa_s
->ifname
,
4869 wpa_s
->bridge_ifname
[0] ? wpa_s
->bridge_ifname
:
4871 wpa_sm_set_fast_reauth(wpa_s
->wpa
, wpa_s
->conf
->fast_reauth
);
4873 if (wpa_s
->conf
->dot11RSNAConfigPMKLifetime
&&
4874 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
4875 wpa_s
->conf
->dot11RSNAConfigPMKLifetime
)) {
4876 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid WPA parameter value for "
4877 "dot11RSNAConfigPMKLifetime");
4881 if (wpa_s
->conf
->dot11RSNAConfigPMKReauthThreshold
&&
4882 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
4883 wpa_s
->conf
->dot11RSNAConfigPMKReauthThreshold
)) {
4884 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid WPA parameter value for "
4885 "dot11RSNAConfigPMKReauthThreshold");
4889 if (wpa_s
->conf
->dot11RSNAConfigSATimeout
&&
4890 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
,
4891 wpa_s
->conf
->dot11RSNAConfigSATimeout
)) {
4892 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid WPA parameter value for "
4893 "dot11RSNAConfigSATimeout");
4897 wpa_s
->hw
.modes
= wpa_drv_get_hw_feature_data(wpa_s
,
4898 &wpa_s
->hw
.num_modes
,
4900 if (wpa_s
->hw
.modes
) {
4903 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
4904 if (wpa_s
->hw
.modes
[i
].vht_capab
) {
4905 wpa_s
->hw_capab
= CAPAB_VHT
;
4909 if (wpa_s
->hw
.modes
[i
].ht_capab
&
4910 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
)
4911 wpa_s
->hw_capab
= CAPAB_HT40
;
4912 else if (wpa_s
->hw
.modes
[i
].ht_capab
&&
4913 wpa_s
->hw_capab
== CAPAB_NO_HT_VHT
)
4914 wpa_s
->hw_capab
= CAPAB_HT
;
4918 capa_res
= wpa_drv_get_capa(wpa_s
, &capa
);
4919 if (capa_res
== 0) {
4920 wpa_s
->drv_capa_known
= 1;
4921 wpa_s
->drv_flags
= capa
.flags
;
4922 wpa_s
->drv_enc
= capa
.enc
;
4923 wpa_s
->drv_smps_modes
= capa
.smps_modes
;
4924 wpa_s
->drv_rrm_flags
= capa
.rrm_flags
;
4925 wpa_s
->probe_resp_offloads
= capa
.probe_resp_offloads
;
4926 wpa_s
->max_scan_ssids
= capa
.max_scan_ssids
;
4927 wpa_s
->max_sched_scan_ssids
= capa
.max_sched_scan_ssids
;
4928 wpa_s
->max_sched_scan_plans
= capa
.max_sched_scan_plans
;
4929 wpa_s
->max_sched_scan_plan_interval
=
4930 capa
.max_sched_scan_plan_interval
;
4931 wpa_s
->max_sched_scan_plan_iterations
=
4932 capa
.max_sched_scan_plan_iterations
;
4933 wpa_s
->sched_scan_supported
= capa
.sched_scan_supported
;
4934 wpa_s
->max_match_sets
= capa
.max_match_sets
;
4935 wpa_s
->max_remain_on_chan
= capa
.max_remain_on_chan
;
4936 wpa_s
->max_stations
= capa
.max_stations
;
4937 wpa_s
->extended_capa
= capa
.extended_capa
;
4938 wpa_s
->extended_capa_mask
= capa
.extended_capa_mask
;
4939 wpa_s
->extended_capa_len
= capa
.extended_capa_len
;
4940 wpa_s
->num_multichan_concurrent
=
4941 capa
.num_multichan_concurrent
;
4942 wpa_s
->wmm_ac_supported
= capa
.wmm_ac_supported
;
4944 if (capa
.mac_addr_rand_scan_supported
)
4945 wpa_s
->mac_addr_rand_supported
|= MAC_ADDR_RAND_SCAN
;
4946 if (wpa_s
->sched_scan_supported
&&
4947 capa
.mac_addr_rand_sched_scan_supported
)
4948 wpa_s
->mac_addr_rand_supported
|=
4949 (MAC_ADDR_RAND_SCHED_SCAN
| MAC_ADDR_RAND_PNO
);
4951 if (wpa_s
->max_remain_on_chan
== 0)
4952 wpa_s
->max_remain_on_chan
= 1000;
4955 * Only take p2p_mgmt parameters when P2P Device is supported.
4956 * Doing it here as it determines whether l2_packet_init() will be done
4957 * during wpa_supplicant_driver_init().
4959 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
)
4960 wpa_s
->p2p_mgmt
= iface
->p2p_mgmt
;
4962 iface
->p2p_mgmt
= 1;
4964 if (wpa_s
->num_multichan_concurrent
== 0)
4965 wpa_s
->num_multichan_concurrent
= 1;
4967 if (wpa_supplicant_driver_init(wpa_s
) < 0)
4971 if ((!iface
->p2p_mgmt
||
4972 !(wpa_s
->drv_flags
&
4973 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
)) &&
4974 wpa_tdls_init(wpa_s
->wpa
))
4976 #endif /* CONFIG_TDLS */
4978 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1] &&
4979 wpa_drv_set_country(wpa_s
, wpa_s
->conf
->country
)) {
4980 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to set country");
4985 if (wpa_s
->conf
->fst_group_id
) {
4986 struct fst_iface_cfg cfg
;
4987 struct fst_wpa_obj iface_obj
;
4989 fst_wpa_supplicant_fill_iface_obj(wpa_s
, &iface_obj
);
4990 os_strlcpy(cfg
.group_id
, wpa_s
->conf
->fst_group_id
,
4991 sizeof(cfg
.group_id
));
4992 cfg
.priority
= wpa_s
->conf
->fst_priority
;
4993 cfg
.llt
= wpa_s
->conf
->fst_llt
;
4995 wpa_s
->fst
= fst_attach(wpa_s
->ifname
, wpa_s
->own_addr
,
4998 wpa_msg(wpa_s
, MSG_ERROR
,
4999 "FST: Cannot attach iface %s to group %s",
5000 wpa_s
->ifname
, cfg
.group_id
);
5004 #endif /* CONFIG_FST */
5006 if (wpas_wps_init(wpa_s
))
5009 if (wpa_supplicant_init_eapol(wpa_s
) < 0)
5011 wpa_sm_set_eapol(wpa_s
->wpa
, wpa_s
->eapol
);
5013 wpa_s
->ctrl_iface
= wpa_supplicant_ctrl_iface_init(wpa_s
);
5014 if (wpa_s
->ctrl_iface
== NULL
) {
5015 wpa_printf(MSG_ERROR
,
5016 "Failed to initialize control interface '%s'.\n"
5017 "You may have another wpa_supplicant process "
5018 "already running or the file was\n"
5019 "left by an unclean termination of wpa_supplicant "
5020 "in which case you will need\n"
5021 "to manually remove this file before starting "
5022 "wpa_supplicant again.\n",
5023 wpa_s
->conf
->ctrl_interface
);
5027 wpa_s
->gas
= gas_query_init(wpa_s
);
5028 if (wpa_s
->gas
== NULL
) {
5029 wpa_printf(MSG_ERROR
, "Failed to initialize GAS query");
5033 if (iface
->p2p_mgmt
&& wpas_p2p_init(wpa_s
->global
, wpa_s
) < 0) {
5034 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to init P2P");
5038 if (wpa_bss_init(wpa_s
) < 0)
5041 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
5043 dl_list_init(&wpa_s
->mesh_external_pmksa_cache
);
5044 #endif /* CONFIG_MESH */
5045 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
5048 * Set Wake-on-WLAN triggers, if configured.
5049 * Note: We don't restore/remove the triggers on shutdown (it doesn't
5050 * have effect anyway when the interface is down).
5052 if (capa_res
== 0 && wpas_set_wowlan_triggers(wpa_s
, &capa
) < 0)
5055 #ifdef CONFIG_EAP_PROXY
5058 wpa_s
->mnc_len
= eapol_sm_get_eap_proxy_imsi(wpa_s
->eapol
, wpa_s
->imsi
,
5060 if (wpa_s
->mnc_len
> 0) {
5061 wpa_s
->imsi
[len
] = '\0';
5062 wpa_printf(MSG_DEBUG
, "eap_proxy: IMSI %s (MNC length %d)",
5063 wpa_s
->imsi
, wpa_s
->mnc_len
);
5065 wpa_printf(MSG_DEBUG
, "eap_proxy: IMSI not available");
5068 #endif /* CONFIG_EAP_PROXY */
5070 if (pcsc_reader_init(wpa_s
) < 0)
5073 if (wpas_init_ext_pw(wpa_s
) < 0)
5076 wpas_rrm_reset(wpa_s
);
5078 wpas_sched_scan_plans_set(wpa_s
, wpa_s
->conf
->sched_scan_plans
);
5082 #endif /* CONFIG_HS20 */
5084 wpas_mbo_update_non_pref_chan(wpa_s
, wpa_s
->conf
->non_pref_chan
);
5085 #endif /* CONFIG_MBO */
5087 wpa_supplicant_set_default_scan_ies(wpa_s
);
5093 static void wpa_supplicant_deinit_iface(struct wpa_supplicant
*wpa_s
,
5094 int notify
, int terminate
)
5096 struct wpa_global
*global
= wpa_s
->global
;
5097 struct wpa_supplicant
*iface
, *prev
;
5099 if (wpa_s
== wpa_s
->parent
)
5100 wpas_p2p_group_remove(wpa_s
, "*");
5102 iface
= global
->ifaces
;
5104 if (iface
->p2pdev
== wpa_s
)
5105 iface
->p2pdev
= iface
->parent
;
5106 if (iface
== wpa_s
|| iface
->parent
!= wpa_s
) {
5107 iface
= iface
->next
;
5110 wpa_printf(MSG_DEBUG
,
5111 "Remove remaining child interface %s from parent %s",
5112 iface
->ifname
, wpa_s
->ifname
);
5114 iface
= iface
->next
;
5115 wpa_supplicant_remove_iface(global
, prev
, terminate
);
5118 wpa_s
->disconnected
= 1;
5119 if (wpa_s
->drv_priv
) {
5120 wpa_supplicant_deauthenticate(wpa_s
,
5121 WLAN_REASON_DEAUTH_LEAVING
);
5123 wpa_drv_set_countermeasures(wpa_s
, 0);
5124 wpa_clear_keys(wpa_s
, NULL
);
5127 wpa_supplicant_cleanup(wpa_s
);
5128 wpas_p2p_deinit_iface(wpa_s
);
5130 wpas_ctrl_radio_work_flush(wpa_s
);
5131 radio_remove_interface(wpa_s
);
5135 fst_detach(wpa_s
->fst
);
5138 if (wpa_s
->received_mb_ies
) {
5139 wpabuf_free(wpa_s
->received_mb_ies
);
5140 wpa_s
->received_mb_ies
= NULL
;
5142 #endif /* CONFIG_FST */
5144 if (wpa_s
->drv_priv
)
5145 wpa_drv_deinit(wpa_s
);
5148 wpas_notify_iface_removed(wpa_s
);
5151 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_TERMINATING
);
5153 if (wpa_s
->ctrl_iface
) {
5154 wpa_supplicant_ctrl_iface_deinit(wpa_s
->ctrl_iface
);
5155 wpa_s
->ctrl_iface
= NULL
;
5160 wpa_supplicant_mesh_iface_deinit(wpa_s
, wpa_s
->ifmsh
);
5161 wpa_s
->ifmsh
= NULL
;
5163 #endif /* CONFIG_MESH */
5165 if (wpa_s
->conf
!= NULL
) {
5166 wpa_config_free(wpa_s
->conf
);
5170 os_free(wpa_s
->ssids_from_scan_req
);
5176 #ifdef CONFIG_MATCH_IFACE
5179 * wpa_supplicant_match_iface - Match an interface description to a name
5180 * @global: Pointer to global data from wpa_supplicant_init()
5181 * @ifname: Name of the interface to match
5182 * Returns: Pointer to the created interface description or %NULL on failure
5184 struct wpa_interface
* wpa_supplicant_match_iface(struct wpa_global
*global
,
5188 struct wpa_interface
*iface
, *miface
;
5190 for (i
= 0; i
< global
->params
.match_iface_count
; i
++) {
5191 miface
= &global
->params
.match_ifaces
[i
];
5192 if (!miface
->ifname
||
5193 fnmatch(miface
->ifname
, ifname
, 0) == 0) {
5194 iface
= os_zalloc(sizeof(*iface
));
5198 iface
->ifname
= ifname
;
5208 * wpa_supplicant_match_existing - Match existing interfaces
5209 * @global: Pointer to global data from wpa_supplicant_init()
5210 * Returns: 0 on success, -1 on failure
5212 static int wpa_supplicant_match_existing(struct wpa_global
*global
)
5214 struct if_nameindex
*ifi
, *ifp
;
5215 struct wpa_supplicant
*wpa_s
;
5216 struct wpa_interface
*iface
;
5218 ifp
= if_nameindex();
5220 wpa_printf(MSG_ERROR
, "if_nameindex: %s", strerror(errno
));
5224 for (ifi
= ifp
; ifi
->if_name
; ifi
++) {
5225 wpa_s
= wpa_supplicant_get_iface(global
, ifi
->if_name
);
5228 iface
= wpa_supplicant_match_iface(global
, ifi
->if_name
);
5230 wpa_s
= wpa_supplicant_add_iface(global
, iface
, NULL
);
5237 if_freenameindex(ifp
);
5241 #endif /* CONFIG_MATCH_IFACE */
5245 * wpa_supplicant_add_iface - Add a new network interface
5246 * @global: Pointer to global data from wpa_supplicant_init()
5247 * @iface: Interface configuration options
5248 * @parent: Parent interface or %NULL to assign new interface as parent
5249 * Returns: Pointer to the created interface or %NULL on failure
5251 * This function is used to add new network interfaces for %wpa_supplicant.
5252 * This can be called before wpa_supplicant_run() to add interfaces before the
5253 * main event loop has been started. In addition, new interfaces can be added
5254 * dynamically while %wpa_supplicant is already running. This could happen,
5255 * e.g., when a hotplug network adapter is inserted.
5257 struct wpa_supplicant
* wpa_supplicant_add_iface(struct wpa_global
*global
,
5258 struct wpa_interface
*iface
,
5259 struct wpa_supplicant
*parent
)
5261 struct wpa_supplicant
*wpa_s
;
5262 struct wpa_interface t_iface
;
5263 struct wpa_ssid
*ssid
;
5265 if (global
== NULL
|| iface
== NULL
)
5268 wpa_s
= wpa_supplicant_alloc(parent
);
5272 wpa_s
->global
= global
;
5275 if (global
->params
.override_driver
) {
5276 wpa_printf(MSG_DEBUG
, "Override interface parameter: driver "
5278 iface
->driver
, global
->params
.override_driver
);
5279 t_iface
.driver
= global
->params
.override_driver
;
5281 if (global
->params
.override_ctrl_interface
) {
5282 wpa_printf(MSG_DEBUG
, "Override interface parameter: "
5283 "ctrl_interface ('%s' -> '%s')",
5284 iface
->ctrl_interface
,
5285 global
->params
.override_ctrl_interface
);
5286 t_iface
.ctrl_interface
=
5287 global
->params
.override_ctrl_interface
;
5289 if (wpa_supplicant_init_iface(wpa_s
, &t_iface
)) {
5290 wpa_printf(MSG_DEBUG
, "Failed to add interface %s",
5292 wpa_supplicant_deinit_iface(wpa_s
, 0, 0);
5296 if (iface
->p2p_mgmt
== 0) {
5297 /* Notify the control interfaces about new iface */
5298 if (wpas_notify_iface_added(wpa_s
)) {
5299 wpa_supplicant_deinit_iface(wpa_s
, 1, 0);
5303 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
)
5304 wpas_notify_network_added(wpa_s
, ssid
);
5307 wpa_s
->next
= global
->ifaces
;
5308 global
->ifaces
= wpa_s
;
5310 wpa_dbg(wpa_s
, MSG_DEBUG
, "Added interface %s", wpa_s
->ifname
);
5311 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
5314 if (wpa_s
->global
->p2p
== NULL
&&
5315 !wpa_s
->global
->p2p_disabled
&& !wpa_s
->conf
->p2p_disabled
&&
5316 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
) &&
5317 wpas_p2p_add_p2pdev_interface(
5318 wpa_s
, wpa_s
->global
->params
.conf_p2p_dev
) < 0) {
5319 wpa_printf(MSG_INFO
,
5320 "P2P: Failed to enable P2P Device interface");
5321 /* Try to continue without. P2P will be disabled. */
5323 #endif /* CONFIG_P2P */
5330 * wpa_supplicant_remove_iface - Remove a network interface
5331 * @global: Pointer to global data from wpa_supplicant_init()
5332 * @wpa_s: Pointer to the network interface to be removed
5333 * Returns: 0 if interface was removed, -1 if interface was not found
5335 * This function can be used to dynamically remove network interfaces from
5336 * %wpa_supplicant, e.g., when a hotplug network adapter is ejected. In
5337 * addition, this function is used to remove all remaining interfaces when
5338 * %wpa_supplicant is terminated.
5340 int wpa_supplicant_remove_iface(struct wpa_global
*global
,
5341 struct wpa_supplicant
*wpa_s
,
5344 struct wpa_supplicant
*prev
;
5346 unsigned int mesh_if_created
= wpa_s
->mesh_if_created
;
5347 char *ifname
= NULL
;
5348 struct wpa_supplicant
*parent
= wpa_s
->parent
;
5349 #endif /* CONFIG_MESH */
5351 /* Remove interface from the global list of interfaces */
5352 prev
= global
->ifaces
;
5353 if (prev
== wpa_s
) {
5354 global
->ifaces
= wpa_s
->next
;
5356 while (prev
&& prev
->next
!= wpa_s
)
5360 prev
->next
= wpa_s
->next
;
5363 wpa_dbg(wpa_s
, MSG_DEBUG
, "Removing interface %s", wpa_s
->ifname
);
5366 if (mesh_if_created
) {
5367 ifname
= os_strdup(wpa_s
->ifname
);
5368 if (ifname
== NULL
) {
5369 wpa_dbg(wpa_s
, MSG_ERROR
,
5370 "mesh: Failed to malloc ifname");
5374 #endif /* CONFIG_MESH */
5376 if (global
->p2p_group_formation
== wpa_s
)
5377 global
->p2p_group_formation
= NULL
;
5378 if (global
->p2p_invite_group
== wpa_s
)
5379 global
->p2p_invite_group
= NULL
;
5380 wpa_supplicant_deinit_iface(wpa_s
, 1, terminate
);
5383 if (mesh_if_created
) {
5384 wpa_drv_if_remove(parent
, WPA_IF_MESH
, ifname
);
5387 #endif /* CONFIG_MESH */
5394 * wpa_supplicant_get_eap_mode - Get the current EAP mode
5395 * @wpa_s: Pointer to the network interface
5396 * Returns: Pointer to the eap mode or the string "UNKNOWN" if not found
5398 const char * wpa_supplicant_get_eap_mode(struct wpa_supplicant
*wpa_s
)
5400 const char *eapol_method
;
5402 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) == 0 &&
5403 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
5407 eapol_method
= eapol_sm_get_method_name(wpa_s
->eapol
);
5408 if (eapol_method
== NULL
)
5409 return "UNKNOWN-EAP";
5411 return eapol_method
;
5416 * wpa_supplicant_get_iface - Get a new network interface
5417 * @global: Pointer to global data from wpa_supplicant_init()
5418 * @ifname: Interface name
5419 * Returns: Pointer to the interface or %NULL if not found
5421 struct wpa_supplicant
* wpa_supplicant_get_iface(struct wpa_global
*global
,
5424 struct wpa_supplicant
*wpa_s
;
5426 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
5427 if (os_strcmp(wpa_s
->ifname
, ifname
) == 0)
5434 #ifndef CONFIG_NO_WPA_MSG
5435 static const char * wpa_supplicant_msg_ifname_cb(void *ctx
)
5437 struct wpa_supplicant
*wpa_s
= ctx
;
5440 return wpa_s
->ifname
;
5442 #endif /* CONFIG_NO_WPA_MSG */
5445 #ifndef WPA_SUPPLICANT_CLEANUP_INTERVAL
5446 #define WPA_SUPPLICANT_CLEANUP_INTERVAL 10
5447 #endif /* WPA_SUPPLICANT_CLEANUP_INTERVAL */
5449 /* Periodic cleanup tasks */
5450 static void wpas_periodic(void *eloop_ctx
, void *timeout_ctx
)
5452 struct wpa_global
*global
= eloop_ctx
;
5453 struct wpa_supplicant
*wpa_s
;
5455 eloop_register_timeout(WPA_SUPPLICANT_CLEANUP_INTERVAL
, 0,
5456 wpas_periodic
, global
, NULL
);
5460 p2p_expire_peers(global
->p2p
);
5461 #endif /* CONFIG_P2P */
5463 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
5464 wpa_bss_flush_by_age(wpa_s
, wpa_s
->conf
->bss_expiration_age
);
5467 #endif /* CONFIG_AP */
5473 * wpa_supplicant_init - Initialize %wpa_supplicant
5474 * @params: Parameters for %wpa_supplicant
5475 * Returns: Pointer to global %wpa_supplicant data, or %NULL on failure
5477 * This function is used to initialize %wpa_supplicant. After successful
5478 * initialization, the returned data pointer can be used to add and remove
5479 * network interfaces, and eventually, to deinitialize %wpa_supplicant.
5481 struct wpa_global
* wpa_supplicant_init(struct wpa_params
*params
)
5483 struct wpa_global
*global
;
5489 #ifdef CONFIG_DRIVER_NDIS
5491 void driver_ndis_init_ops(void);
5492 driver_ndis_init_ops();
5494 #endif /* CONFIG_DRIVER_NDIS */
5496 #ifndef CONFIG_NO_WPA_MSG
5497 wpa_msg_register_ifname_cb(wpa_supplicant_msg_ifname_cb
);
5498 #endif /* CONFIG_NO_WPA_MSG */
5500 if (params
->wpa_debug_file_path
)
5501 wpa_debug_open_file(params
->wpa_debug_file_path
);
5503 wpa_debug_setup_stdout();
5504 if (params
->wpa_debug_syslog
)
5505 wpa_debug_open_syslog();
5506 if (params
->wpa_debug_tracing
) {
5507 ret
= wpa_debug_open_linux_tracing();
5509 wpa_printf(MSG_ERROR
,
5510 "Failed to enable trace logging");
5515 ret
= eap_register_methods();
5517 wpa_printf(MSG_ERROR
, "Failed to register EAP methods");
5519 wpa_printf(MSG_ERROR
, "Two or more EAP methods used "
5520 "the same EAP type.");
5524 global
= os_zalloc(sizeof(*global
));
5527 dl_list_init(&global
->p2p_srv_bonjour
);
5528 dl_list_init(&global
->p2p_srv_upnp
);
5529 global
->params
.daemonize
= params
->daemonize
;
5530 global
->params
.wait_for_monitor
= params
->wait_for_monitor
;
5531 global
->params
.dbus_ctrl_interface
= params
->dbus_ctrl_interface
;
5532 if (params
->pid_file
)
5533 global
->params
.pid_file
= os_strdup(params
->pid_file
);
5534 if (params
->ctrl_interface
)
5535 global
->params
.ctrl_interface
=
5536 os_strdup(params
->ctrl_interface
);
5537 if (params
->ctrl_interface_group
)
5538 global
->params
.ctrl_interface_group
=
5539 os_strdup(params
->ctrl_interface_group
);
5540 if (params
->override_driver
)
5541 global
->params
.override_driver
=
5542 os_strdup(params
->override_driver
);
5543 if (params
->override_ctrl_interface
)
5544 global
->params
.override_ctrl_interface
=
5545 os_strdup(params
->override_ctrl_interface
);
5546 #ifdef CONFIG_MATCH_IFACE
5547 global
->params
.match_iface_count
= params
->match_iface_count
;
5548 if (params
->match_iface_count
) {
5549 global
->params
.match_ifaces
=
5550 os_calloc(params
->match_iface_count
,
5551 sizeof(struct wpa_interface
));
5552 os_memcpy(global
->params
.match_ifaces
,
5553 params
->match_ifaces
,
5554 params
->match_iface_count
*
5555 sizeof(struct wpa_interface
));
5557 #endif /* CONFIG_MATCH_IFACE */
5559 if (params
->conf_p2p_dev
)
5560 global
->params
.conf_p2p_dev
=
5561 os_strdup(params
->conf_p2p_dev
);
5562 #endif /* CONFIG_P2P */
5563 wpa_debug_level
= global
->params
.wpa_debug_level
=
5564 params
->wpa_debug_level
;
5565 wpa_debug_show_keys
= global
->params
.wpa_debug_show_keys
=
5566 params
->wpa_debug_show_keys
;
5567 wpa_debug_timestamp
= global
->params
.wpa_debug_timestamp
=
5568 params
->wpa_debug_timestamp
;
5570 wpa_printf(MSG_DEBUG
, "wpa_supplicant v" VERSION_STR
);
5573 wpa_printf(MSG_ERROR
, "Failed to initialize event loop");
5574 wpa_supplicant_deinit(global
);
5578 random_init(params
->entropy_file
);
5580 global
->ctrl_iface
= wpa_supplicant_global_ctrl_iface_init(global
);
5581 if (global
->ctrl_iface
== NULL
) {
5582 wpa_supplicant_deinit(global
);
5586 if (wpas_notify_supplicant_initialized(global
)) {
5587 wpa_supplicant_deinit(global
);
5591 for (i
= 0; wpa_drivers
[i
]; i
++)
5592 global
->drv_count
++;
5593 if (global
->drv_count
== 0) {
5594 wpa_printf(MSG_ERROR
, "No drivers enabled");
5595 wpa_supplicant_deinit(global
);
5598 global
->drv_priv
= os_calloc(global
->drv_count
, sizeof(void *));
5599 if (global
->drv_priv
== NULL
) {
5600 wpa_supplicant_deinit(global
);
5604 #ifdef CONFIG_WIFI_DISPLAY
5605 if (wifi_display_init(global
) < 0) {
5606 wpa_printf(MSG_ERROR
, "Failed to initialize Wi-Fi Display");
5607 wpa_supplicant_deinit(global
);
5610 #endif /* CONFIG_WIFI_DISPLAY */
5612 eloop_register_timeout(WPA_SUPPLICANT_CLEANUP_INTERVAL
, 0,
5613 wpas_periodic
, global
, NULL
);
5620 * wpa_supplicant_run - Run the %wpa_supplicant main event loop
5621 * @global: Pointer to global data from wpa_supplicant_init()
5622 * Returns: 0 after successful event loop run, -1 on failure
5624 * This function starts the main event loop and continues running as long as
5625 * there are any remaining events. In most cases, this function is running as
5626 * long as the %wpa_supplicant process in still in use.
5628 int wpa_supplicant_run(struct wpa_global
*global
)
5630 struct wpa_supplicant
*wpa_s
;
5632 if (global
->params
.daemonize
&&
5633 (wpa_supplicant_daemon(global
->params
.pid_file
) ||
5634 eloop_sock_requeue()))
5637 #ifdef CONFIG_MATCH_IFACE
5638 if (wpa_supplicant_match_existing(global
))
5642 if (global
->params
.wait_for_monitor
) {
5643 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
)
5644 if (wpa_s
->ctrl_iface
&& !wpa_s
->p2p_mgmt
)
5645 wpa_supplicant_ctrl_iface_wait(
5649 eloop_register_signal_terminate(wpa_supplicant_terminate
, global
);
5650 eloop_register_signal_reconfig(wpa_supplicant_reconfig
, global
);
5659 * wpa_supplicant_deinit - Deinitialize %wpa_supplicant
5660 * @global: Pointer to global data from wpa_supplicant_init()
5662 * This function is called to deinitialize %wpa_supplicant and to free all
5663 * allocated resources. Remaining network interfaces will also be removed.
5665 void wpa_supplicant_deinit(struct wpa_global
*global
)
5672 eloop_cancel_timeout(wpas_periodic
, global
, NULL
);
5674 #ifdef CONFIG_WIFI_DISPLAY
5675 wifi_display_deinit(global
);
5676 #endif /* CONFIG_WIFI_DISPLAY */
5678 while (global
->ifaces
)
5679 wpa_supplicant_remove_iface(global
, global
->ifaces
, 1);
5681 if (global
->ctrl_iface
)
5682 wpa_supplicant_global_ctrl_iface_deinit(global
->ctrl_iface
);
5684 wpas_notify_supplicant_deinitialized(global
);
5686 eap_peer_unregister_methods();
5688 eap_server_unregister_methods();
5689 #endif /* CONFIG_AP */
5691 for (i
= 0; wpa_drivers
[i
] && global
->drv_priv
; i
++) {
5692 if (!global
->drv_priv
[i
])
5694 wpa_drivers
[i
]->global_deinit(global
->drv_priv
[i
]);
5696 os_free(global
->drv_priv
);
5702 if (global
->params
.pid_file
) {
5703 os_daemonize_terminate(global
->params
.pid_file
);
5704 os_free(global
->params
.pid_file
);
5706 os_free(global
->params
.ctrl_interface
);
5707 os_free(global
->params
.ctrl_interface_group
);
5708 os_free(global
->params
.override_driver
);
5709 os_free(global
->params
.override_ctrl_interface
);
5710 #ifdef CONFIG_MATCH_IFACE
5711 os_free(global
->params
.match_ifaces
);
5712 #endif /* CONFIG_MATCH_IFACE */
5714 os_free(global
->params
.conf_p2p_dev
);
5715 #endif /* CONFIG_P2P */
5717 os_free(global
->p2p_disallow_freq
.range
);
5718 os_free(global
->p2p_go_avoid_freq
.range
);
5719 os_free(global
->add_psk
);
5722 wpa_debug_close_syslog();
5723 wpa_debug_close_file();
5724 wpa_debug_close_linux_tracing();
5728 void wpa_supplicant_update_config(struct wpa_supplicant
*wpa_s
)
5730 if ((wpa_s
->conf
->changed_parameters
& CFG_CHANGED_COUNTRY
) &&
5731 wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1]) {
5733 country
[0] = wpa_s
->conf
->country
[0];
5734 country
[1] = wpa_s
->conf
->country
[1];
5736 if (wpa_drv_set_country(wpa_s
, country
) < 0) {
5737 wpa_printf(MSG_ERROR
, "Failed to set country code "
5742 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_EXT_PW_BACKEND
)
5743 wpas_init_ext_pw(wpa_s
);
5745 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_SCHED_SCAN_PLANS
)
5746 wpas_sched_scan_plans_set(wpa_s
, wpa_s
->conf
->sched_scan_plans
);
5749 wpas_wps_update_config(wpa_s
);
5750 #endif /* CONFIG_WPS */
5751 wpas_p2p_update_config(wpa_s
);
5752 wpa_s
->conf
->changed_parameters
= 0;
5756 void add_freq(int *freqs
, int *num_freqs
, int freq
)
5760 for (i
= 0; i
< *num_freqs
; i
++) {
5761 if (freqs
[i
] == freq
)
5765 freqs
[*num_freqs
] = freq
;
5770 static int * get_bss_freqs_in_ess(struct wpa_supplicant
*wpa_s
)
5772 struct wpa_bss
*bss
, *cbss
;
5773 const int max_freqs
= 10;
5777 freqs
= os_calloc(max_freqs
+ 1, sizeof(int));
5781 cbss
= wpa_s
->current_bss
;
5783 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
5786 if (bss
->ssid_len
== cbss
->ssid_len
&&
5787 os_memcmp(bss
->ssid
, cbss
->ssid
, bss
->ssid_len
) == 0 &&
5788 wpa_blacklist_get(wpa_s
, bss
->bssid
) == NULL
) {
5789 add_freq(freqs
, &num_freqs
, bss
->freq
);
5790 if (num_freqs
== max_freqs
)
5795 if (num_freqs
== 0) {
5804 void wpas_connection_failed(struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
5810 wpas_connect_work_done(wpa_s
);
5813 * Remove possible authentication timeout since the connection failed.
5815 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
5818 * There is no point in blacklisting the AP if this event is
5819 * generated based on local request to disconnect.
5821 if (wpa_s
->own_disconnect_req
) {
5822 wpa_s
->own_disconnect_req
= 0;
5823 wpa_dbg(wpa_s
, MSG_DEBUG
,
5824 "Ignore connection failure due to local request to disconnect");
5827 if (wpa_s
->disconnected
) {
5828 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore connection failure "
5829 "indication since interface has been put into "
5830 "disconnected state");
5835 * Add the failed BSSID into the blacklist and speed up next scan
5836 * attempt if there could be other APs that could accept association.
5837 * The current blacklist count indicates how many times we have tried
5838 * connecting to this AP and multiple attempts mean that other APs are
5839 * either not available or has already been tried, so that we can start
5840 * increasing the delay here to avoid constant scanning.
5842 count
= wpa_blacklist_add(wpa_s
, bssid
);
5843 if (count
== 1 && wpa_s
->current_bss
) {
5845 * This BSS was not in the blacklist before. If there is
5846 * another BSS available for the same ESS, we should try that
5847 * next. Otherwise, we may as well try this one once more
5848 * before allowing other, likely worse, ESSes to be considered.
5850 freqs
= get_bss_freqs_in_ess(wpa_s
);
5852 wpa_dbg(wpa_s
, MSG_DEBUG
, "Another BSS in this ESS "
5853 "has been seen; try it next");
5854 wpa_blacklist_add(wpa_s
, bssid
);
5856 * On the next scan, go through only the known channels
5857 * used in this ESS based on previous scans to speed up
5858 * common load balancing use case.
5860 os_free(wpa_s
->next_scan_freqs
);
5861 wpa_s
->next_scan_freqs
= freqs
;
5866 * Add previous failure count in case the temporary blacklist was
5867 * cleared due to no other BSSes being available.
5869 count
+= wpa_s
->extra_blacklist_count
;
5871 if (count
> 3 && wpa_s
->current_ssid
) {
5872 wpa_printf(MSG_DEBUG
, "Continuous association failures - "
5873 "consider temporary network disabling");
5874 wpas_auth_failed(wpa_s
, "CONN_FAILED");
5895 wpa_dbg(wpa_s
, MSG_DEBUG
, "Blacklist count %d --> request scan in %d "
5896 "ms", count
, timeout
);
5899 * TODO: if more than one possible AP is available in scan results,
5900 * could try the other ones before requesting a new scan.
5902 wpa_supplicant_req_scan(wpa_s
, timeout
/ 1000,
5903 1000 * (timeout
% 1000));
5907 int wpas_driver_bss_selection(struct wpa_supplicant
*wpa_s
)
5909 return wpa_s
->conf
->ap_scan
== 2 ||
5910 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_BSS_SELECTION
);
5914 #if defined(CONFIG_CTRL_IFACE) || defined(CONFIG_CTRL_IFACE_DBUS_NEW)
5915 int wpa_supplicant_ctrl_iface_ctrl_rsp_handle(struct wpa_supplicant
*wpa_s
,
5916 struct wpa_ssid
*ssid
,
5920 #ifdef IEEE8021X_EAPOL
5921 struct eap_peer_config
*eap
= &ssid
->eap
;
5923 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: response handle field=%s", field
);
5924 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: response value",
5925 (const u8
*) value
, os_strlen(value
));
5927 switch (wpa_supplicant_ctrl_req_from_string(field
)) {
5928 case WPA_CTRL_REQ_EAP_IDENTITY
:
5929 os_free(eap
->identity
);
5930 eap
->identity
= (u8
*) os_strdup(value
);
5931 eap
->identity_len
= os_strlen(value
);
5932 eap
->pending_req_identity
= 0;
5933 if (ssid
== wpa_s
->current_ssid
)
5934 wpa_s
->reassociate
= 1;
5936 case WPA_CTRL_REQ_EAP_PASSWORD
:
5937 bin_clear_free(eap
->password
, eap
->password_len
);
5938 eap
->password
= (u8
*) os_strdup(value
);
5939 eap
->password_len
= os_strlen(value
);
5940 eap
->pending_req_password
= 0;
5941 if (ssid
== wpa_s
->current_ssid
)
5942 wpa_s
->reassociate
= 1;
5944 case WPA_CTRL_REQ_EAP_NEW_PASSWORD
:
5945 bin_clear_free(eap
->new_password
, eap
->new_password_len
);
5946 eap
->new_password
= (u8
*) os_strdup(value
);
5947 eap
->new_password_len
= os_strlen(value
);
5948 eap
->pending_req_new_password
= 0;
5949 if (ssid
== wpa_s
->current_ssid
)
5950 wpa_s
->reassociate
= 1;
5952 case WPA_CTRL_REQ_EAP_PIN
:
5953 str_clear_free(eap
->pin
);
5954 eap
->pin
= os_strdup(value
);
5955 eap
->pending_req_pin
= 0;
5956 if (ssid
== wpa_s
->current_ssid
)
5957 wpa_s
->reassociate
= 1;
5959 case WPA_CTRL_REQ_EAP_OTP
:
5960 bin_clear_free(eap
->otp
, eap
->otp_len
);
5961 eap
->otp
= (u8
*) os_strdup(value
);
5962 eap
->otp_len
= os_strlen(value
);
5963 os_free(eap
->pending_req_otp
);
5964 eap
->pending_req_otp
= NULL
;
5965 eap
->pending_req_otp_len
= 0;
5967 case WPA_CTRL_REQ_EAP_PASSPHRASE
:
5968 str_clear_free(eap
->private_key_passwd
);
5969 eap
->private_key_passwd
= os_strdup(value
);
5970 eap
->pending_req_passphrase
= 0;
5971 if (ssid
== wpa_s
->current_ssid
)
5972 wpa_s
->reassociate
= 1;
5974 case WPA_CTRL_REQ_SIM
:
5975 str_clear_free(eap
->external_sim_resp
);
5976 eap
->external_sim_resp
= os_strdup(value
);
5977 eap
->pending_req_sim
= 0;
5979 case WPA_CTRL_REQ_PSK_PASSPHRASE
:
5980 if (wpa_config_set(ssid
, "psk", value
, 0) < 0)
5982 ssid
->mem_only_psk
= 1;
5983 if (ssid
->passphrase
)
5984 wpa_config_update_psk(ssid
);
5985 if (wpa_s
->wpa_state
== WPA_SCANNING
&& !wpa_s
->scanning
)
5986 wpa_supplicant_req_scan(wpa_s
, 0, 0);
5988 case WPA_CTRL_REQ_EXT_CERT_CHECK
:
5989 if (eap
->pending_ext_cert_check
!= PENDING_CHECK
)
5991 if (os_strcmp(value
, "good") == 0)
5992 eap
->pending_ext_cert_check
= EXT_CERT_CHECK_GOOD
;
5993 else if (os_strcmp(value
, "bad") == 0)
5994 eap
->pending_ext_cert_check
= EXT_CERT_CHECK_BAD
;
5999 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown field '%s'", field
);
6004 #else /* IEEE8021X_EAPOL */
6005 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: IEEE 802.1X not included");
6007 #endif /* IEEE8021X_EAPOL */
6009 #endif /* CONFIG_CTRL_IFACE || CONFIG_CTRL_IFACE_DBUS_NEW */
6012 int wpas_network_disabled(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
)
6015 unsigned int drv_enc
;
6017 if (wpa_s
->p2p_mgmt
)
6018 return 1; /* no normal network profiles on p2p_mgmt interface */
6026 if (wpa_s
->drv_capa_known
)
6027 drv_enc
= wpa_s
->drv_enc
;
6029 drv_enc
= (unsigned int) -1;
6031 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
6032 size_t len
= ssid
->wep_key_len
[i
];
6035 if (len
== 5 && (drv_enc
& WPA_DRIVER_CAPA_ENC_WEP40
))
6037 if (len
== 13 && (drv_enc
& WPA_DRIVER_CAPA_ENC_WEP104
))
6039 if (len
== 16 && (drv_enc
& WPA_DRIVER_CAPA_ENC_WEP128
))
6041 return 1; /* invalid WEP key */
6044 if (wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) && !ssid
->psk_set
&&
6045 (!ssid
->passphrase
|| ssid
->ssid_len
!= 0) && !ssid
->ext_psk
&&
6046 !ssid
->mem_only_psk
)
6053 int wpas_get_ssid_pmf(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
)
6055 #ifdef CONFIG_IEEE80211W
6056 if (ssid
== NULL
|| ssid
->ieee80211w
== MGMT_FRAME_PROTECTION_DEFAULT
) {
6057 if (wpa_s
->conf
->pmf
== MGMT_FRAME_PROTECTION_OPTIONAL
&&
6058 !(wpa_s
->drv_enc
& WPA_DRIVER_CAPA_ENC_BIP
)) {
6060 * Driver does not support BIP -- ignore pmf=1 default
6061 * since the connection with PMF would fail and the
6062 * configuration does not require PMF to be enabled.
6064 return NO_MGMT_FRAME_PROTECTION
;
6069 ~(WPA_KEY_MGMT_NONE
| WPA_KEY_MGMT_WPS
|
6070 WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) == 0) {
6072 * Do not use the default PMF value for non-RSN networks
6073 * since PMF is available only with RSN and pmf=2
6074 * configuration would otherwise prevent connections to
6075 * all open networks.
6077 return NO_MGMT_FRAME_PROTECTION
;
6080 return wpa_s
->conf
->pmf
;
6083 return ssid
->ieee80211w
;
6084 #else /* CONFIG_IEEE80211W */
6085 return NO_MGMT_FRAME_PROTECTION
;
6086 #endif /* CONFIG_IEEE80211W */
6090 int wpas_is_p2p_prioritized(struct wpa_supplicant
*wpa_s
)
6092 if (wpa_s
->global
->conc_pref
== WPA_CONC_PREF_P2P
)
6094 if (wpa_s
->global
->conc_pref
== WPA_CONC_PREF_STA
)
6100 void wpas_auth_failed(struct wpa_supplicant
*wpa_s
, char *reason
)
6102 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
6104 struct os_reltime now
;
6107 wpa_printf(MSG_DEBUG
, "Authentication failure but no known "
6112 if (ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
)
6115 ssid
->auth_failures
++;
6118 if (ssid
->p2p_group
&&
6119 (wpa_s
->p2p_in_provisioning
|| wpa_s
->show_group_started
)) {
6121 * Skip the wait time since there is a short timeout on the
6122 * connection to a P2P group.
6126 #endif /* CONFIG_P2P */
6128 if (ssid
->auth_failures
> 50)
6130 else if (ssid
->auth_failures
> 10)
6132 else if (ssid
->auth_failures
> 5)
6134 else if (ssid
->auth_failures
> 3)
6136 else if (ssid
->auth_failures
> 2)
6138 else if (ssid
->auth_failures
> 1)
6143 if (ssid
->auth_failures
> 1 &&
6144 wpa_key_mgmt_wpa_ieee8021x(ssid
->key_mgmt
))
6145 dur
+= os_random() % (ssid
->auth_failures
* 10);
6147 os_get_reltime(&now
);
6148 if (now
.sec
+ dur
<= ssid
->disabled_until
.sec
)
6151 ssid
->disabled_until
.sec
= now
.sec
+ dur
;
6153 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_TEMP_DISABLED
6154 "id=%d ssid=\"%s\" auth_failures=%u duration=%d reason=%s",
6155 ssid
->id
, wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
),
6156 ssid
->auth_failures
, dur
, reason
);
6160 void wpas_clear_temp_disabled(struct wpa_supplicant
*wpa_s
,
6161 struct wpa_ssid
*ssid
, int clear_failures
)
6166 if (ssid
->disabled_until
.sec
) {
6167 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_REENABLED
6168 "id=%d ssid=\"%s\"",
6169 ssid
->id
, wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
6171 ssid
->disabled_until
.sec
= 0;
6172 ssid
->disabled_until
.usec
= 0;
6174 ssid
->auth_failures
= 0;
6178 int disallowed_bssid(struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
6182 if (wpa_s
->disallow_aps_bssid
== NULL
)
6185 for (i
= 0; i
< wpa_s
->disallow_aps_bssid_count
; i
++) {
6186 if (os_memcmp(wpa_s
->disallow_aps_bssid
+ i
* ETH_ALEN
,
6187 bssid
, ETH_ALEN
) == 0)
6195 int disallowed_ssid(struct wpa_supplicant
*wpa_s
, const u8
*ssid
,
6200 if (wpa_s
->disallow_aps_ssid
== NULL
|| ssid
== NULL
)
6203 for (i
= 0; i
< wpa_s
->disallow_aps_ssid_count
; i
++) {
6204 struct wpa_ssid_value
*s
= &wpa_s
->disallow_aps_ssid
[i
];
6205 if (ssid_len
== s
->ssid_len
&&
6206 os_memcmp(ssid
, s
->ssid
, ssid_len
) == 0)
6215 * wpas_request_connection - Request a new connection
6216 * @wpa_s: Pointer to the network interface
6218 * This function is used to request a new connection to be found. It will mark
6219 * the interface to allow reassociation and request a new scan to find a
6220 * suitable network to connect to.
6222 void wpas_request_connection(struct wpa_supplicant
*wpa_s
)
6224 wpa_s
->normal_scans
= 0;
6225 wpa_s
->scan_req
= NORMAL_SCAN_REQ
;
6226 wpa_supplicant_reinit_autoscan(wpa_s
);
6227 wpa_s
->extra_blacklist_count
= 0;
6228 wpa_s
->disconnected
= 0;
6229 wpa_s
->reassociate
= 1;
6231 if (wpa_supplicant_fast_associate(wpa_s
) != 1)
6232 wpa_supplicant_req_scan(wpa_s
, 0, 0);
6234 wpa_s
->reattach
= 0;
6239 * wpas_request_disconnection - Request disconnection
6240 * @wpa_s: Pointer to the network interface
6242 * This function is used to request disconnection from the currently connected
6243 * network. This will stop any ongoing scans and initiate deauthentication.
6245 void wpas_request_disconnection(struct wpa_supplicant
*wpa_s
)
6248 wpa_s
->sme
.prev_bssid_set
= 0;
6249 #endif /* CONFIG_SME */
6250 wpa_s
->reassociate
= 0;
6251 wpa_s
->disconnected
= 1;
6252 wpa_supplicant_cancel_sched_scan(wpa_s
);
6253 wpa_supplicant_cancel_scan(wpa_s
);
6254 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
6255 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
6259 void dump_freq_data(struct wpa_supplicant
*wpa_s
, const char *title
,
6260 struct wpa_used_freq_data
*freqs_data
,
6265 wpa_dbg(wpa_s
, MSG_DEBUG
, "Shared frequencies (len=%u): %s",
6267 for (i
= 0; i
< len
; i
++) {
6268 struct wpa_used_freq_data
*cur
= &freqs_data
[i
];
6269 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq[%u]: %d, flags=0x%X",
6270 i
, cur
->freq
, cur
->flags
);
6276 * Find the operating frequencies of any of the virtual interfaces that
6277 * are using the same radio as the current interface, and in addition, get
6278 * information about the interface types that are using the frequency.
6280 int get_shared_radio_freqs_data(struct wpa_supplicant
*wpa_s
,
6281 struct wpa_used_freq_data
*freqs_data
,
6284 struct wpa_supplicant
*ifs
;
6287 unsigned int idx
= 0, i
;
6289 wpa_dbg(wpa_s
, MSG_DEBUG
,
6290 "Determining shared radio frequencies (max len %u)", len
);
6291 os_memset(freqs_data
, 0, sizeof(struct wpa_used_freq_data
) * len
);
6293 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
6298 if (ifs
->current_ssid
== NULL
|| ifs
->assoc_freq
== 0)
6301 if (ifs
->current_ssid
->mode
== WPAS_MODE_AP
||
6302 ifs
->current_ssid
->mode
== WPAS_MODE_P2P_GO
||
6303 ifs
->current_ssid
->mode
== WPAS_MODE_MESH
)
6304 freq
= ifs
->current_ssid
->frequency
;
6305 else if (wpa_drv_get_bssid(ifs
, bssid
) == 0)
6306 freq
= ifs
->assoc_freq
;
6310 /* Hold only distinct freqs */
6311 for (i
= 0; i
< idx
; i
++)
6312 if (freqs_data
[i
].freq
== freq
)
6316 freqs_data
[idx
++].freq
= freq
;
6318 if (ifs
->current_ssid
->mode
== WPAS_MODE_INFRA
) {
6319 freqs_data
[i
].flags
|= ifs
->current_ssid
->p2p_group
?
6320 WPA_FREQ_USED_BY_P2P_CLIENT
:
6321 WPA_FREQ_USED_BY_INFRA_STATION
;
6325 dump_freq_data(wpa_s
, "completed iteration", freqs_data
, idx
);
6331 * Find the operating frequencies of any of the virtual interfaces that
6332 * are using the same radio as the current interface.
6334 int get_shared_radio_freqs(struct wpa_supplicant
*wpa_s
,
6335 int *freq_array
, unsigned int len
)
6337 struct wpa_used_freq_data
*freqs_data
;
6340 os_memset(freq_array
, 0, sizeof(int) * len
);
6342 freqs_data
= os_calloc(len
, sizeof(struct wpa_used_freq_data
));
6346 num
= get_shared_radio_freqs_data(wpa_s
, freqs_data
, len
);
6347 for (i
= 0; i
< num
; i
++)
6348 freq_array
[i
] = freqs_data
[i
].freq
;
6350 os_free(freqs_data
);
6356 struct wpa_supplicant
*
6357 wpas_vendor_elem(struct wpa_supplicant
*wpa_s
, enum wpa_vendor_elem_frame frame
)
6361 case VENDOR_ELEM_PROBE_REQ_P2P
:
6362 case VENDOR_ELEM_PROBE_RESP_P2P
:
6363 case VENDOR_ELEM_PROBE_RESP_P2P_GO
:
6364 case VENDOR_ELEM_BEACON_P2P_GO
:
6365 case VENDOR_ELEM_P2P_PD_REQ
:
6366 case VENDOR_ELEM_P2P_PD_RESP
:
6367 case VENDOR_ELEM_P2P_GO_NEG_REQ
:
6368 case VENDOR_ELEM_P2P_GO_NEG_RESP
:
6369 case VENDOR_ELEM_P2P_GO_NEG_CONF
:
6370 case VENDOR_ELEM_P2P_INV_REQ
:
6371 case VENDOR_ELEM_P2P_INV_RESP
:
6372 case VENDOR_ELEM_P2P_ASSOC_REQ
:
6373 case VENDOR_ELEM_P2P_ASSOC_RESP
:
6374 return wpa_s
->p2pdev
;
6375 #endif /* CONFIG_P2P */
6382 void wpas_vendor_elem_update(struct wpa_supplicant
*wpa_s
)
6387 wpa_printf(MSG_DEBUG
, "Update vendor elements");
6389 for (i
= 0; i
< NUM_VENDOR_ELEM_FRAMES
; i
++) {
6390 if (wpa_s
->vendor_elem
[i
]) {
6393 res
= os_snprintf(buf
, sizeof(buf
), "frame[%u]", i
);
6394 if (!os_snprintf_error(sizeof(buf
), res
)) {
6395 wpa_hexdump_buf(MSG_DEBUG
, buf
,
6396 wpa_s
->vendor_elem
[i
]);
6402 if (wpa_s
->parent
== wpa_s
&&
6403 wpa_s
->global
->p2p
&&
6404 !wpa_s
->global
->p2p_disabled
)
6405 p2p_set_vendor_elems(wpa_s
->global
->p2p
, wpa_s
->vendor_elem
);
6406 #endif /* CONFIG_P2P */
6410 int wpas_vendor_elem_remove(struct wpa_supplicant
*wpa_s
, int frame
,
6411 const u8
*elem
, size_t len
)
6415 ie
= wpabuf_mhead_u8(wpa_s
->vendor_elem
[frame
]);
6416 end
= ie
+ wpabuf_len(wpa_s
->vendor_elem
[frame
]);
6418 for (; ie
+ 1 < end
; ie
+= 2 + ie
[1]) {
6421 if (os_memcmp(ie
, elem
, len
) != 0)
6424 if (wpabuf_len(wpa_s
->vendor_elem
[frame
]) == len
) {
6425 wpabuf_free(wpa_s
->vendor_elem
[frame
]);
6426 wpa_s
->vendor_elem
[frame
] = NULL
;
6428 os_memmove(ie
, ie
+ len
, end
- (ie
+ len
));
6429 wpa_s
->vendor_elem
[frame
]->used
-= len
;
6431 wpas_vendor_elem_update(wpa_s
);
6439 struct hostapd_hw_modes
* get_mode(struct hostapd_hw_modes
*modes
,
6440 u16 num_modes
, enum hostapd_hw_mode mode
)
6444 for (i
= 0; i
< num_modes
; i
++) {
6445 if (modes
[i
].mode
== mode
)
6454 wpa_bss_tmp_disallowed
* wpas_get_disallowed_bss(struct wpa_supplicant
*wpa_s
,
6457 struct wpa_bss_tmp_disallowed
*bss
;
6459 dl_list_for_each(bss
, &wpa_s
->bss_tmp_disallowed
,
6460 struct wpa_bss_tmp_disallowed
, list
) {
6461 if (os_memcmp(bssid
, bss
->bssid
, ETH_ALEN
) == 0)
6469 void wpa_bss_tmp_disallow(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
6472 struct wpa_bss_tmp_disallowed
*bss
;
6473 struct os_reltime until
;
6475 os_get_reltime(&until
);
6478 bss
= wpas_get_disallowed_bss(wpa_s
, bssid
);
6480 bss
->disallowed_until
= until
;
6484 bss
= os_malloc(sizeof(*bss
));
6486 wpa_printf(MSG_DEBUG
,
6487 "Failed to allocate memory for temp disallow BSS");
6491 bss
->disallowed_until
= until
;
6492 os_memcpy(bss
->bssid
, bssid
, ETH_ALEN
);
6493 dl_list_add(&wpa_s
->bss_tmp_disallowed
, &bss
->list
);
6497 int wpa_is_bss_tmp_disallowed(struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
6499 struct wpa_bss_tmp_disallowed
*bss
= NULL
, *tmp
, *prev
;
6500 struct os_reltime now
, age
;
6502 os_get_reltime(&now
);
6504 dl_list_for_each_safe(tmp
, prev
, &wpa_s
->bss_tmp_disallowed
,
6505 struct wpa_bss_tmp_disallowed
, list
) {
6506 if (!os_reltime_before(&now
, &tmp
->disallowed_until
)) {
6507 /* This BSS is not disallowed anymore */
6508 dl_list_del(&tmp
->list
);
6512 if (os_memcmp(bssid
, tmp
->bssid
, ETH_ALEN
) == 0) {
6520 os_reltime_sub(&bss
->disallowed_until
, &now
, &age
);
6521 wpa_printf(MSG_DEBUG
,
6522 "BSS " MACSTR
" disabled for %ld.%0ld seconds",
6523 MAC2STR(bss
->bssid
), age
.sec
, age
.usec
);