3 * Copyright (c) 2003-2018, 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"
41 #include "common/gas_server.h"
44 #include "blacklist.h"
45 #include "wpas_glue.h"
46 #include "wps_supplicant.h"
49 #include "gas_query.h"
51 #include "p2p_supplicant.h"
52 #include "wifi_display.h"
58 #include "offchannel.h"
59 #include "hs20_supplicant.h"
63 #include "dpp_supplicant.h"
65 #include "ap/ap_config.h"
66 #include "ap/hostapd.h"
67 #endif /* CONFIG_MESH */
69 const char *const wpa_supplicant_version
=
70 "wpa_supplicant v" VERSION_STR
"\n"
71 "Copyright (c) 2003-2017, Jouni Malinen <j@w1.fi> and contributors";
73 const char *const wpa_supplicant_license
=
74 "This software may be distributed under the terms of the BSD license.\n"
75 "See README for more details.\n"
76 #ifdef EAP_TLS_OPENSSL
77 "\nThis product includes software developed by the OpenSSL Project\n"
78 "for use in the OpenSSL Toolkit (http://www.openssl.org/)\n"
79 #endif /* EAP_TLS_OPENSSL */
82 #ifndef CONFIG_NO_STDOUT_DEBUG
83 /* Long text divided into parts in order to fit in C89 strings size limits. */
84 const char *const wpa_supplicant_full_license1
=
86 const char *const wpa_supplicant_full_license2
=
87 "This software may be distributed under the terms of the BSD license.\n"
89 "Redistribution and use in source and binary forms, with or without\n"
90 "modification, are permitted provided that the following conditions are\n"
93 const char *const wpa_supplicant_full_license3
=
94 "1. Redistributions of source code must retain the above copyright\n"
95 " notice, this list of conditions and the following disclaimer.\n"
97 "2. Redistributions in binary form must reproduce the above copyright\n"
98 " notice, this list of conditions and the following disclaimer in the\n"
99 " documentation and/or other materials provided with the distribution.\n"
101 const char *const wpa_supplicant_full_license4
=
102 "3. Neither the name(s) of the above-listed copyright holder(s) nor the\n"
103 " names of its contributors may be used to endorse or promote products\n"
104 " derived from this software without specific prior written permission.\n"
106 "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n"
107 "\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n"
108 "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n"
109 "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n";
110 const char *const wpa_supplicant_full_license5
=
111 "OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n"
112 "SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n"
113 "LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n"
114 "DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n"
115 "THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n"
116 "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n"
117 "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
119 #endif /* CONFIG_NO_STDOUT_DEBUG */
122 static void wpa_bss_tmp_disallow_timeout(void *eloop_ctx
, void *timeout_ctx
);
123 #if defined(CONFIG_FILS) && defined(IEEE8021X_EAPOL)
124 static void wpas_update_fils_connect_params(struct wpa_supplicant
*wpa_s
);
125 #endif /* CONFIG_FILS && IEEE8021X_EAPOL */
128 /* Configure default/group WEP keys for static WEP */
129 int wpa_set_wep_keys(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
)
133 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
134 if (ssid
->wep_key_len
[i
] == 0)
138 wpa_drv_set_key(wpa_s
, WPA_ALG_WEP
, NULL
,
139 i
, i
== ssid
->wep_tx_keyidx
, NULL
, 0,
140 ssid
->wep_key
[i
], ssid
->wep_key_len
[i
]);
147 int wpa_supplicant_set_wpa_none_key(struct wpa_supplicant
*wpa_s
,
148 struct wpa_ssid
*ssid
)
156 /* IBSS/WPA-None uses only one key (Group) for both receiving and
157 * sending unicast and multicast packets. */
159 if (ssid
->mode
!= WPAS_MODE_IBSS
) {
160 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Invalid mode %d (not "
161 "IBSS/ad-hoc) for WPA-None", ssid
->mode
);
165 if (!ssid
->psk_set
) {
166 wpa_msg(wpa_s
, MSG_INFO
, "WPA: No PSK configured for "
171 switch (wpa_s
->group_cipher
) {
172 case WPA_CIPHER_CCMP
:
173 os_memcpy(key
, ssid
->psk
, 16);
177 case WPA_CIPHER_GCMP
:
178 os_memcpy(key
, ssid
->psk
, 16);
182 case WPA_CIPHER_TKIP
:
183 /* WPA-None uses the same Michael MIC key for both TX and RX */
184 os_memcpy(key
, ssid
->psk
, 16 + 8);
185 os_memcpy(key
+ 16 + 8, ssid
->psk
+ 16, 8);
190 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Invalid group cipher %d for "
191 "WPA-None", wpa_s
->group_cipher
);
195 /* TODO: should actually remember the previously used seq#, both for TX
196 * and RX from each STA.. */
198 ret
= wpa_drv_set_key(wpa_s
, alg
, NULL
, 0, 1, seq
, 6, key
, keylen
);
199 os_memset(key
, 0, sizeof(key
));
204 static void wpa_supplicant_timeout(void *eloop_ctx
, void *timeout_ctx
)
206 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
207 const u8
*bssid
= wpa_s
->bssid
;
208 if (!is_zero_ether_addr(wpa_s
->pending_bssid
) &&
209 (wpa_s
->wpa_state
== WPA_AUTHENTICATING
||
210 wpa_s
->wpa_state
== WPA_ASSOCIATING
))
211 bssid
= wpa_s
->pending_bssid
;
212 wpa_msg(wpa_s
, MSG_INFO
, "Authentication with " MACSTR
" timed out.",
214 wpa_blacklist_add(wpa_s
, bssid
);
215 wpa_sm_notify_disassoc(wpa_s
->wpa
);
216 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
217 wpa_s
->reassociate
= 1;
220 * If we timed out, the AP or the local radio may be busy.
221 * So, wait a second until scanning again.
223 wpa_supplicant_req_scan(wpa_s
, 1, 0);
228 * wpa_supplicant_req_auth_timeout - Schedule a timeout for authentication
229 * @wpa_s: Pointer to wpa_supplicant data
230 * @sec: Number of seconds after which to time out authentication
231 * @usec: Number of microseconds after which to time out authentication
233 * This function is used to schedule a timeout for the current authentication
236 void wpa_supplicant_req_auth_timeout(struct wpa_supplicant
*wpa_s
,
239 if (wpa_s
->conf
->ap_scan
== 0 &&
240 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
))
243 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setting authentication timeout: %d sec "
244 "%d usec", sec
, usec
);
245 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
246 wpa_s
->last_auth_timeout_sec
= sec
;
247 eloop_register_timeout(sec
, usec
, wpa_supplicant_timeout
, wpa_s
, NULL
);
252 * wpas_auth_timeout_restart - Restart and change timeout for authentication
253 * @wpa_s: Pointer to wpa_supplicant data
254 * @sec_diff: difference in seconds applied to original timeout value
256 void wpas_auth_timeout_restart(struct wpa_supplicant
*wpa_s
, int sec_diff
)
258 int new_sec
= wpa_s
->last_auth_timeout_sec
+ sec_diff
;
260 if (eloop_is_timeout_registered(wpa_supplicant_timeout
, wpa_s
, NULL
)) {
261 wpa_dbg(wpa_s
, MSG_DEBUG
,
262 "Authentication timeout restart: %d sec", new_sec
);
263 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
264 eloop_register_timeout(new_sec
, 0, wpa_supplicant_timeout
,
271 * wpa_supplicant_cancel_auth_timeout - Cancel authentication timeout
272 * @wpa_s: Pointer to wpa_supplicant data
274 * This function is used to cancel authentication timeout scheduled with
275 * wpa_supplicant_req_auth_timeout() and it is called when authentication has
278 void wpa_supplicant_cancel_auth_timeout(struct wpa_supplicant
*wpa_s
)
280 wpa_dbg(wpa_s
, MSG_DEBUG
, "Cancelling authentication timeout");
281 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
282 wpa_blacklist_del(wpa_s
, wpa_s
->bssid
);
287 * wpa_supplicant_initiate_eapol - Configure EAPOL state machine
288 * @wpa_s: Pointer to wpa_supplicant data
290 * This function is used to configure EAPOL state machine based on the selected
291 * authentication mode.
293 void wpa_supplicant_initiate_eapol(struct wpa_supplicant
*wpa_s
)
295 #ifdef IEEE8021X_EAPOL
296 struct eapol_config eapol_conf
;
297 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
299 #ifdef CONFIG_IBSS_RSN
300 if (ssid
->mode
== WPAS_MODE_IBSS
&&
301 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
302 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
) {
304 * RSN IBSS authentication is per-STA and we can disable the
305 * per-BSSID EAPOL authentication.
307 eapol_sm_notify_portControl(wpa_s
->eapol
, ForceAuthorized
);
308 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
309 eapol_sm_notify_eap_fail(wpa_s
->eapol
, FALSE
);
312 #endif /* CONFIG_IBSS_RSN */
314 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
315 eapol_sm_notify_eap_fail(wpa_s
->eapol
, FALSE
);
317 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
318 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
319 eapol_sm_notify_portControl(wpa_s
->eapol
, ForceAuthorized
);
321 eapol_sm_notify_portControl(wpa_s
->eapol
, Auto
);
323 os_memset(&eapol_conf
, 0, sizeof(eapol_conf
));
324 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
325 eapol_conf
.accept_802_1x_keys
= 1;
326 eapol_conf
.required_keys
= 0;
327 if (ssid
->eapol_flags
& EAPOL_FLAG_REQUIRE_KEY_UNICAST
) {
328 eapol_conf
.required_keys
|= EAPOL_REQUIRE_KEY_UNICAST
;
330 if (ssid
->eapol_flags
& EAPOL_FLAG_REQUIRE_KEY_BROADCAST
) {
331 eapol_conf
.required_keys
|=
332 EAPOL_REQUIRE_KEY_BROADCAST
;
335 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
)
336 eapol_conf
.required_keys
= 0;
338 eapol_conf
.fast_reauth
= wpa_s
->conf
->fast_reauth
;
339 eapol_conf
.workaround
= ssid
->eap_workaround
;
340 eapol_conf
.eap_disabled
=
341 !wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) &&
342 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
343 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPS
;
344 eapol_conf
.external_sim
= wpa_s
->conf
->external_sim
;
347 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
348 eapol_conf
.wps
|= EAPOL_LOCAL_WPS_IN_USE
;
349 if (wpa_s
->current_bss
) {
351 ie
= wpa_bss_get_vendor_ie_multi(wpa_s
->current_bss
,
356 EAPOL_PEER_IS_WPS20_AP
;
361 #endif /* CONFIG_WPS */
363 eapol_sm_notify_config(wpa_s
->eapol
, &ssid
->eap
, &eapol_conf
);
366 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
&& ssid
->mka_psk_set
)
367 ieee802_1x_create_preshared_mka(wpa_s
, ssid
);
369 ieee802_1x_alloc_kay_sm(wpa_s
, ssid
);
370 #endif /* CONFIG_MACSEC */
371 #endif /* IEEE8021X_EAPOL */
376 * wpa_supplicant_set_non_wpa_policy - Set WPA parameters to non-WPA mode
377 * @wpa_s: Pointer to wpa_supplicant data
378 * @ssid: Configuration data for the network
380 * This function is used to configure WPA state machine and related parameters
381 * to a mode where WPA is not enabled. This is called as part of the
382 * authentication configuration when the selected network does not use WPA.
384 void wpa_supplicant_set_non_wpa_policy(struct wpa_supplicant
*wpa_s
,
385 struct wpa_ssid
*ssid
)
389 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
390 wpa_s
->key_mgmt
= WPA_KEY_MGMT_WPS
;
391 else if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)
392 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X_NO_WPA
;
394 wpa_s
->key_mgmt
= WPA_KEY_MGMT_NONE
;
395 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
396 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
397 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
398 wpa_s
->pairwise_cipher
= WPA_CIPHER_NONE
;
399 wpa_s
->group_cipher
= WPA_CIPHER_NONE
;
400 wpa_s
->mgmt_group_cipher
= 0;
402 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
403 if (ssid
->wep_key_len
[i
] > 5) {
404 wpa_s
->pairwise_cipher
= WPA_CIPHER_WEP104
;
405 wpa_s
->group_cipher
= WPA_CIPHER_WEP104
;
407 } else if (ssid
->wep_key_len
[i
] > 0) {
408 wpa_s
->pairwise_cipher
= WPA_CIPHER_WEP40
;
409 wpa_s
->group_cipher
= WPA_CIPHER_WEP40
;
414 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_RSN_ENABLED
, 0);
415 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_KEY_MGMT
, wpa_s
->key_mgmt
);
416 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PAIRWISE
,
417 wpa_s
->pairwise_cipher
);
418 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_GROUP
, wpa_s
->group_cipher
);
419 #ifdef CONFIG_IEEE80211W
420 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MGMT_GROUP
,
421 wpa_s
->mgmt_group_cipher
);
422 #endif /* CONFIG_IEEE80211W */
424 pmksa_cache_clear_current(wpa_s
->wpa
);
428 void free_hw_features(struct wpa_supplicant
*wpa_s
)
431 if (wpa_s
->hw
.modes
== NULL
)
434 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
435 os_free(wpa_s
->hw
.modes
[i
].channels
);
436 os_free(wpa_s
->hw
.modes
[i
].rates
);
439 os_free(wpa_s
->hw
.modes
);
440 wpa_s
->hw
.modes
= NULL
;
444 static void free_bss_tmp_disallowed(struct wpa_supplicant
*wpa_s
)
446 struct wpa_bss_tmp_disallowed
*bss
, *prev
;
448 dl_list_for_each_safe(bss
, prev
, &wpa_s
->bss_tmp_disallowed
,
449 struct wpa_bss_tmp_disallowed
, list
) {
450 eloop_cancel_timeout(wpa_bss_tmp_disallow_timeout
, wpa_s
, bss
);
451 dl_list_del(&bss
->list
);
457 void wpas_flush_fils_hlp_req(struct wpa_supplicant
*wpa_s
)
459 struct fils_hlp_req
*req
;
461 while ((req
= dl_list_first(&wpa_s
->fils_hlp_req
, struct fils_hlp_req
,
463 dl_list_del(&req
->list
);
464 wpabuf_free(req
->pkt
);
470 static void wpa_supplicant_cleanup(struct wpa_supplicant
*wpa_s
)
474 bgscan_deinit(wpa_s
);
475 autoscan_deinit(wpa_s
);
476 scard_deinit(wpa_s
->scard
);
478 wpa_sm_set_scard_ctx(wpa_s
->wpa
, NULL
);
479 eapol_sm_register_scard_ctx(wpa_s
->eapol
, NULL
);
480 l2_packet_deinit(wpa_s
->l2
);
483 l2_packet_deinit(wpa_s
->l2_br
);
486 #ifdef CONFIG_TESTING_OPTIONS
487 l2_packet_deinit(wpa_s
->l2_test
);
488 wpa_s
->l2_test
= NULL
;
489 os_free(wpa_s
->get_pref_freq_list_override
);
490 wpa_s
->get_pref_freq_list_override
= NULL
;
491 wpabuf_free(wpa_s
->last_assoc_req_wpa_ie
);
492 wpa_s
->last_assoc_req_wpa_ie
= NULL
;
493 #endif /* CONFIG_TESTING_OPTIONS */
495 if (wpa_s
->conf
!= NULL
) {
496 struct wpa_ssid
*ssid
;
497 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
)
498 wpas_notify_network_removed(wpa_s
, ssid
);
501 os_free(wpa_s
->confname
);
502 wpa_s
->confname
= NULL
;
504 os_free(wpa_s
->confanother
);
505 wpa_s
->confanother
= NULL
;
507 wpa_sm_set_eapol(wpa_s
->wpa
, NULL
);
508 eapol_sm_deinit(wpa_s
->eapol
);
511 rsn_preauth_deinit(wpa_s
->wpa
);
514 wpa_tdls_deinit(wpa_s
->wpa
);
515 #endif /* CONFIG_TDLS */
517 wmm_ac_clear_saved_tspecs(wpa_s
);
518 pmksa_candidate_free(wpa_s
->wpa
);
519 wpa_sm_deinit(wpa_s
->wpa
);
521 wpa_blacklist_clear(wpa_s
);
523 wpa_bss_deinit(wpa_s
);
525 wpa_supplicant_cancel_delayed_sched_scan(wpa_s
);
526 wpa_supplicant_cancel_scan(wpa_s
);
527 wpa_supplicant_cancel_auth_timeout(wpa_s
);
528 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
529 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
530 eloop_cancel_timeout(wpa_supplicant_delayed_mic_error_report
,
532 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
534 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
536 wpas_wps_deinit(wpa_s
);
538 wpabuf_free(wpa_s
->pending_eapol_rx
);
539 wpa_s
->pending_eapol_rx
= NULL
;
541 #ifdef CONFIG_IBSS_RSN
542 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
543 wpa_s
->ibss_rsn
= NULL
;
544 #endif /* CONFIG_IBSS_RSN */
549 wpa_supplicant_ap_deinit(wpa_s
);
550 #endif /* CONFIG_AP */
552 wpas_p2p_deinit(wpa_s
);
554 #ifdef CONFIG_OFFCHANNEL
555 offchannel_deinit(wpa_s
);
556 #endif /* CONFIG_OFFCHANNEL */
558 wpa_supplicant_cancel_sched_scan(wpa_s
);
560 os_free(wpa_s
->next_scan_freqs
);
561 wpa_s
->next_scan_freqs
= NULL
;
563 os_free(wpa_s
->manual_scan_freqs
);
564 wpa_s
->manual_scan_freqs
= NULL
;
565 os_free(wpa_s
->select_network_scan_freqs
);
566 wpa_s
->select_network_scan_freqs
= NULL
;
568 os_free(wpa_s
->manual_sched_scan_freqs
);
569 wpa_s
->manual_sched_scan_freqs
= NULL
;
571 wpas_mac_addr_rand_scan_clear(wpa_s
, MAC_ADDR_RAND_ALL
);
574 * Need to remove any pending gas-query radio work before the
575 * gas_query_deinit() call because gas_query::work has not yet been set
576 * for works that have not been started. gas_query_free() will be unable
577 * to cancel such pending radio works and once the pending gas-query
578 * radio work eventually gets removed, the deinit notification call to
579 * gas_query_start_cb() would result in dereferencing freed memory.
582 radio_remove_works(wpa_s
, "gas-query", 0);
583 gas_query_deinit(wpa_s
->gas
);
585 gas_server_deinit(wpa_s
->gas_server
);
586 wpa_s
->gas_server
= NULL
;
588 free_hw_features(wpa_s
);
590 ieee802_1x_dealloc_kay_sm(wpa_s
);
592 os_free(wpa_s
->bssid_filter
);
593 wpa_s
->bssid_filter
= NULL
;
595 os_free(wpa_s
->disallow_aps_bssid
);
596 wpa_s
->disallow_aps_bssid
= NULL
;
597 os_free(wpa_s
->disallow_aps_ssid
);
598 wpa_s
->disallow_aps_ssid
= NULL
;
600 wnm_bss_keep_alive_deinit(wpa_s
);
602 wnm_deallocate_memory(wpa_s
);
603 #endif /* CONFIG_WNM */
605 ext_password_deinit(wpa_s
->ext_pw
);
606 wpa_s
->ext_pw
= NULL
;
608 wpabuf_free(wpa_s
->last_gas_resp
);
609 wpa_s
->last_gas_resp
= NULL
;
610 wpabuf_free(wpa_s
->prev_gas_resp
);
611 wpa_s
->prev_gas_resp
= NULL
;
613 os_free(wpa_s
->last_scan_res
);
614 wpa_s
->last_scan_res
= NULL
;
618 wpa_drv_configure_frame_filters(wpa_s
, 0);
620 #endif /* CONFIG_HS20 */
622 for (i
= 0; i
< NUM_VENDOR_ELEM_FRAMES
; i
++) {
623 wpabuf_free(wpa_s
->vendor_elem
[i
]);
624 wpa_s
->vendor_elem
[i
] = NULL
;
627 wmm_ac_notify_disassoc(wpa_s
);
629 wpa_s
->sched_scan_plans_num
= 0;
630 os_free(wpa_s
->sched_scan_plans
);
631 wpa_s
->sched_scan_plans
= NULL
;
634 wpa_s
->non_pref_chan_num
= 0;
635 os_free(wpa_s
->non_pref_chan
);
636 wpa_s
->non_pref_chan
= NULL
;
637 #endif /* CONFIG_MBO */
639 free_bss_tmp_disallowed(wpa_s
);
641 wpabuf_free(wpa_s
->lci
);
643 wpas_clear_beacon_rep_data(wpa_s
);
645 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
648 struct external_pmksa_cache
*entry
;
650 while ((entry
= dl_list_last(&wpa_s
->mesh_external_pmksa_cache
,
651 struct external_pmksa_cache
,
653 dl_list_del(&entry
->list
);
654 os_free(entry
->pmksa_cache
);
658 #endif /* CONFIG_MESH */
659 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
661 wpas_flush_fils_hlp_req(wpa_s
);
663 wpabuf_free(wpa_s
->ric_ies
);
664 wpa_s
->ric_ies
= NULL
;
667 wpas_dpp_deinit(wpa_s
);
668 #endif /* CONFIG_DPP */
673 * wpa_clear_keys - Clear keys configured for the driver
674 * @wpa_s: Pointer to wpa_supplicant data
675 * @addr: Previously used BSSID or %NULL if not available
677 * This function clears the encryption keys that has been previously configured
680 void wpa_clear_keys(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
684 #ifdef CONFIG_IEEE80211W
686 #else /* CONFIG_IEEE80211W */
688 #endif /* CONFIG_IEEE80211W */
690 /* MLME-DELETEKEYS.request */
691 for (i
= 0; i
< max
; i
++) {
692 if (wpa_s
->keys_cleared
& BIT(i
))
694 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, i
, 0, NULL
, 0,
697 if (!(wpa_s
->keys_cleared
& BIT(0)) && addr
&&
698 !is_zero_ether_addr(addr
)) {
699 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, addr
, 0, 0, NULL
, 0, NULL
,
701 /* MLME-SETPROTECTION.request(None) */
702 wpa_drv_mlme_setprotection(
704 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
705 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
707 wpa_s
->keys_cleared
= (u32
) -1;
712 * wpa_supplicant_state_txt - Get the connection state name as a text string
713 * @state: State (wpa_state; WPA_*)
714 * Returns: The state name as a printable text string
716 const char * wpa_supplicant_state_txt(enum wpa_states state
)
719 case WPA_DISCONNECTED
:
720 return "DISCONNECTED";
723 case WPA_INTERFACE_DISABLED
:
724 return "INTERFACE_DISABLED";
727 case WPA_AUTHENTICATING
:
728 return "AUTHENTICATING";
729 case WPA_ASSOCIATING
:
730 return "ASSOCIATING";
733 case WPA_4WAY_HANDSHAKE
:
734 return "4WAY_HANDSHAKE";
735 case WPA_GROUP_HANDSHAKE
:
736 return "GROUP_HANDSHAKE";
747 static void wpa_supplicant_start_bgscan(struct wpa_supplicant
*wpa_s
)
751 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->bgscan
)
752 name
= wpa_s
->current_ssid
->bgscan
;
754 name
= wpa_s
->conf
->bgscan
;
755 if (name
== NULL
|| name
[0] == '\0')
757 if (wpas_driver_bss_selection(wpa_s
))
759 if (wpa_s
->current_ssid
== wpa_s
->bgscan_ssid
)
762 if (wpa_s
->p2p_group_interface
!= NOT_P2P_GROUP_INTERFACE
)
764 #endif /* CONFIG_P2P */
766 bgscan_deinit(wpa_s
);
767 if (wpa_s
->current_ssid
) {
768 if (bgscan_init(wpa_s
, wpa_s
->current_ssid
, name
)) {
769 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to initialize "
772 * Live without bgscan; it is only used as a roaming
773 * optimization, so the initial connection is not
777 struct wpa_scan_results
*scan_res
;
778 wpa_s
->bgscan_ssid
= wpa_s
->current_ssid
;
779 scan_res
= wpa_supplicant_get_scan_results(wpa_s
, NULL
,
782 bgscan_notify_scan(wpa_s
, scan_res
);
783 wpa_scan_results_free(scan_res
);
787 wpa_s
->bgscan_ssid
= NULL
;
791 static void wpa_supplicant_stop_bgscan(struct wpa_supplicant
*wpa_s
)
793 if (wpa_s
->bgscan_ssid
!= NULL
) {
794 bgscan_deinit(wpa_s
);
795 wpa_s
->bgscan_ssid
= NULL
;
799 #endif /* CONFIG_BGSCAN */
802 static void wpa_supplicant_start_autoscan(struct wpa_supplicant
*wpa_s
)
804 if (autoscan_init(wpa_s
, 0))
805 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to initialize autoscan");
809 static void wpa_supplicant_stop_autoscan(struct wpa_supplicant
*wpa_s
)
811 autoscan_deinit(wpa_s
);
815 void wpa_supplicant_reinit_autoscan(struct wpa_supplicant
*wpa_s
)
817 if (wpa_s
->wpa_state
== WPA_DISCONNECTED
||
818 wpa_s
->wpa_state
== WPA_SCANNING
) {
819 autoscan_deinit(wpa_s
);
820 wpa_supplicant_start_autoscan(wpa_s
);
826 * wpa_supplicant_set_state - Set current connection state
827 * @wpa_s: Pointer to wpa_supplicant data
828 * @state: The new connection state
830 * This function is called whenever the connection state changes, e.g.,
831 * association is completed for WPA/WPA2 4-Way Handshake is started.
833 void wpa_supplicant_set_state(struct wpa_supplicant
*wpa_s
,
834 enum wpa_states state
)
836 enum wpa_states old_state
= wpa_s
->wpa_state
;
838 wpa_dbg(wpa_s
, MSG_DEBUG
, "State: %s -> %s",
839 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
840 wpa_supplicant_state_txt(state
));
842 if (state
== WPA_INTERFACE_DISABLED
) {
843 /* Assure normal scan when interface is restored */
844 wpa_s
->normal_scans
= 0;
847 if (state
== WPA_COMPLETED
) {
848 wpas_connect_work_done(wpa_s
);
849 /* Reinitialize normal_scan counter */
850 wpa_s
->normal_scans
= 0;
855 * P2PS client has to reply to Probe Request frames received on the
856 * group operating channel. Enable Probe Request frame reporting for
857 * P2P connected client in case p2p_cli_probe configuration property is
860 if (wpa_s
->conf
->p2p_cli_probe
&& wpa_s
->current_ssid
&&
861 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
&&
862 wpa_s
->current_ssid
->p2p_group
) {
863 if (state
== WPA_COMPLETED
&& !wpa_s
->p2p_cli_probe
) {
864 wpa_dbg(wpa_s
, MSG_DEBUG
,
865 "P2P: Enable CLI Probe Request RX reporting");
866 wpa_s
->p2p_cli_probe
=
867 wpa_drv_probe_req_report(wpa_s
, 1) >= 0;
868 } else if (state
!= WPA_COMPLETED
&& wpa_s
->p2p_cli_probe
) {
869 wpa_dbg(wpa_s
, MSG_DEBUG
,
870 "P2P: Disable CLI Probe Request RX reporting");
871 wpa_s
->p2p_cli_probe
= 0;
872 wpa_drv_probe_req_report(wpa_s
, 0);
875 #endif /* CONFIG_P2P */
877 if (state
!= WPA_SCANNING
)
878 wpa_supplicant_notify_scanning(wpa_s
, 0);
880 if (state
== WPA_COMPLETED
&& wpa_s
->new_connection
) {
881 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
882 int fils_hlp_sent
= 0;
885 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
886 wpa_auth_alg_fils(wpa_s
->sme
.auth_alg
))
888 #endif /* CONFIG_SME */
889 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
890 wpa_auth_alg_fils(wpa_s
->auth_alg
))
893 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
894 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
"- Connection to "
895 MACSTR
" completed [id=%d id_str=%s%s]",
896 MAC2STR(wpa_s
->bssid
),
897 ssid
? ssid
->id
: -1,
898 ssid
&& ssid
->id_str
? ssid
->id_str
: "",
899 fils_hlp_sent
? " FILS_HLP_SENT" : "");
900 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
901 wpas_clear_temp_disabled(wpa_s
, ssid
, 1);
902 wpa_blacklist_clear(wpa_s
);
903 wpa_s
->extra_blacklist_count
= 0;
904 wpa_s
->new_connection
= 0;
905 wpa_drv_set_operstate(wpa_s
, 1);
906 #ifndef IEEE8021X_EAPOL
907 wpa_drv_set_supp_port(wpa_s
, 1);
908 #endif /* IEEE8021X_EAPOL */
909 wpa_s
->after_wps
= 0;
910 wpa_s
->known_wps_freq
= 0;
911 wpas_p2p_completed(wpa_s
);
913 sme_sched_obss_scan(wpa_s
, 1);
915 #if defined(CONFIG_FILS) && defined(IEEE8021X_EAPOL)
916 if (!fils_hlp_sent
&& ssid
&& ssid
->eap
.erp
)
917 wpas_update_fils_connect_params(wpa_s
);
918 #endif /* CONFIG_FILS && IEEE8021X_EAPOL */
919 } else if (state
== WPA_DISCONNECTED
|| state
== WPA_ASSOCIATING
||
920 state
== WPA_ASSOCIATED
) {
921 wpa_s
->new_connection
= 1;
922 wpa_drv_set_operstate(wpa_s
, 0);
923 #ifndef IEEE8021X_EAPOL
924 wpa_drv_set_supp_port(wpa_s
, 0);
925 #endif /* IEEE8021X_EAPOL */
926 sme_sched_obss_scan(wpa_s
, 0);
928 wpa_s
->wpa_state
= state
;
931 if (state
== WPA_COMPLETED
)
932 wpa_supplicant_start_bgscan(wpa_s
);
933 else if (state
< WPA_ASSOCIATED
)
934 wpa_supplicant_stop_bgscan(wpa_s
);
935 #endif /* CONFIG_BGSCAN */
937 if (state
== WPA_AUTHENTICATING
)
938 wpa_supplicant_stop_autoscan(wpa_s
);
940 if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
941 wpa_supplicant_start_autoscan(wpa_s
);
943 if (old_state
>= WPA_ASSOCIATED
&& wpa_s
->wpa_state
< WPA_ASSOCIATED
)
944 wmm_ac_notify_disassoc(wpa_s
);
946 if (wpa_s
->wpa_state
!= old_state
) {
947 wpas_notify_state_changed(wpa_s
, wpa_s
->wpa_state
, old_state
);
950 * Notify the P2P Device interface about a state change in one
953 wpas_p2p_indicate_state_change(wpa_s
);
955 if (wpa_s
->wpa_state
== WPA_COMPLETED
||
956 old_state
== WPA_COMPLETED
)
957 wpas_notify_auth_changed(wpa_s
);
962 void wpa_supplicant_terminate_proc(struct wpa_global
*global
)
966 struct wpa_supplicant
*wpa_s
= global
->ifaces
;
968 struct wpa_supplicant
*next
= wpa_s
->next
;
969 if (wpas_wps_terminate_pending(wpa_s
) == 1)
972 if (wpa_s
->p2p_group_interface
!= NOT_P2P_GROUP_INTERFACE
||
973 (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->p2p_group
))
974 wpas_p2p_disconnect(wpa_s
);
975 #endif /* CONFIG_P2P */
978 #endif /* CONFIG_WPS */
985 static void wpa_supplicant_terminate(int sig
, void *signal_ctx
)
987 struct wpa_global
*global
= signal_ctx
;
988 wpa_supplicant_terminate_proc(global
);
992 void wpa_supplicant_clear_status(struct wpa_supplicant
*wpa_s
)
994 enum wpa_states old_state
= wpa_s
->wpa_state
;
996 wpa_s
->pairwise_cipher
= 0;
997 wpa_s
->group_cipher
= 0;
998 wpa_s
->mgmt_group_cipher
= 0;
1000 if (wpa_s
->wpa_state
!= WPA_INTERFACE_DISABLED
)
1001 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1003 if (wpa_s
->wpa_state
!= old_state
)
1004 wpas_notify_state_changed(wpa_s
, wpa_s
->wpa_state
, old_state
);
1009 * wpa_supplicant_reload_configuration - Reload configuration data
1010 * @wpa_s: Pointer to wpa_supplicant data
1011 * Returns: 0 on success or -1 if configuration parsing failed
1013 * This function can be used to request that the configuration data is reloaded
1014 * (e.g., after configuration file change). This function is reloading
1015 * configuration only for one interface, so this may need to be called multiple
1016 * times if %wpa_supplicant is controlling multiple interfaces and all
1017 * interfaces need reconfiguration.
1019 int wpa_supplicant_reload_configuration(struct wpa_supplicant
*wpa_s
)
1021 struct wpa_config
*conf
;
1025 if (wpa_s
->confname
== NULL
)
1027 conf
= wpa_config_read(wpa_s
->confname
, NULL
);
1029 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to parse the configuration "
1030 "file '%s' - exiting", wpa_s
->confname
);
1033 if (wpa_s
->confanother
&&
1034 !wpa_config_read(wpa_s
->confanother
, conf
)) {
1035 wpa_msg(wpa_s
, MSG_ERROR
,
1036 "Failed to parse the configuration file '%s' - exiting",
1037 wpa_s
->confanother
);
1041 conf
->changed_parameters
= (unsigned int) -1;
1043 reconf_ctrl
= !!conf
->ctrl_interface
!= !!wpa_s
->conf
->ctrl_interface
1044 || (conf
->ctrl_interface
&& wpa_s
->conf
->ctrl_interface
&&
1045 os_strcmp(conf
->ctrl_interface
,
1046 wpa_s
->conf
->ctrl_interface
) != 0);
1048 if (reconf_ctrl
&& wpa_s
->ctrl_iface
) {
1049 wpa_supplicant_ctrl_iface_deinit(wpa_s
->ctrl_iface
);
1050 wpa_s
->ctrl_iface
= NULL
;
1053 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
1054 if (wpa_s
->current_ssid
) {
1055 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
1056 wpa_s
->own_disconnect_req
= 1;
1057 wpa_supplicant_deauthenticate(wpa_s
,
1058 WLAN_REASON_DEAUTH_LEAVING
);
1062 * TODO: should notify EAPOL SM about changes in opensc_engine_path,
1063 * pkcs11_engine_path, pkcs11_module_path, openssl_ciphers.
1065 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
1066 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
||
1067 wpa_s
->key_mgmt
== WPA_KEY_MGMT_DPP
) {
1069 * Clear forced success to clear EAP state for next
1072 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
1074 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
1075 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
1076 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
1077 wpa_sm_set_fast_reauth(wpa_s
->wpa
, wpa_s
->conf
->fast_reauth
);
1078 rsn_preauth_deinit(wpa_s
->wpa
);
1080 old_ap_scan
= wpa_s
->conf
->ap_scan
;
1081 wpa_config_free(wpa_s
->conf
);
1083 if (old_ap_scan
!= wpa_s
->conf
->ap_scan
)
1084 wpas_notify_ap_scan_changed(wpa_s
);
1087 wpa_s
->ctrl_iface
= wpa_supplicant_ctrl_iface_init(wpa_s
);
1089 wpa_supplicant_update_config(wpa_s
);
1091 wpa_supplicant_clear_status(wpa_s
);
1092 if (wpa_supplicant_enabled_networks(wpa_s
)) {
1093 wpa_s
->reassociate
= 1;
1094 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1096 wpa_dbg(wpa_s
, MSG_DEBUG
, "Reconfiguration completed");
1101 static void wpa_supplicant_reconfig(int sig
, void *signal_ctx
)
1103 struct wpa_global
*global
= signal_ctx
;
1104 struct wpa_supplicant
*wpa_s
;
1105 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
1106 wpa_dbg(wpa_s
, MSG_DEBUG
, "Signal %d received - reconfiguring",
1108 if (wpa_supplicant_reload_configuration(wpa_s
) < 0) {
1109 wpa_supplicant_terminate_proc(global
);
1113 if (wpa_debug_reopen_file() < 0) {
1114 /* Ignore errors since we cannot really do much to fix this */
1115 wpa_printf(MSG_DEBUG
, "Could not reopen debug log file");
1120 static int wpa_supplicant_suites_from_ai(struct wpa_supplicant
*wpa_s
,
1121 struct wpa_ssid
*ssid
,
1122 struct wpa_ie_data
*ie
)
1124 int ret
= wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, ie
);
1127 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Failed to parse WPA IE "
1128 "from association info");
1133 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Using WPA IE from AssocReq to set "
1135 if (!(ie
->group_cipher
& ssid
->group_cipher
)) {
1136 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled group "
1137 "cipher 0x%x (mask 0x%x) - reject",
1138 ie
->group_cipher
, ssid
->group_cipher
);
1141 if (!(ie
->pairwise_cipher
& ssid
->pairwise_cipher
)) {
1142 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled pairwise "
1143 "cipher 0x%x (mask 0x%x) - reject",
1144 ie
->pairwise_cipher
, ssid
->pairwise_cipher
);
1147 if (!(ie
->key_mgmt
& ssid
->key_mgmt
)) {
1148 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled key "
1149 "management 0x%x (mask 0x%x) - reject",
1150 ie
->key_mgmt
, ssid
->key_mgmt
);
1154 #ifdef CONFIG_IEEE80211W
1155 if (!(ie
->capabilities
& WPA_CAPABILITY_MFPC
) &&
1156 wpas_get_ssid_pmf(wpa_s
, ssid
) == MGMT_FRAME_PROTECTION_REQUIRED
) {
1157 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver associated with an AP "
1158 "that does not support management frame protection - "
1162 #endif /* CONFIG_IEEE80211W */
1169 * wpa_supplicant_set_suites - Set authentication and encryption parameters
1170 * @wpa_s: Pointer to wpa_supplicant data
1171 * @bss: Scan results for the selected BSS, or %NULL if not available
1172 * @ssid: Configuration data for the selected network
1173 * @wpa_ie: Buffer for the WPA/RSN IE
1174 * @wpa_ie_len: Maximum wpa_ie buffer size on input. This is changed to be the
1175 * used buffer length in case the functions returns success.
1176 * Returns: 0 on success or -1 on failure
1178 * This function is used to configure authentication and encryption parameters
1179 * based on the network configuration and scan result for the selected BSS (if
1182 int wpa_supplicant_set_suites(struct wpa_supplicant
*wpa_s
,
1183 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
,
1184 u8
*wpa_ie
, size_t *wpa_ie_len
)
1186 struct wpa_ie_data ie
;
1188 const u8
*bss_wpa
, *bss_rsn
, *bss_osen
;
1191 bss_wpa
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
1192 bss_rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1193 bss_osen
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
1195 bss_wpa
= bss_rsn
= bss_osen
= NULL
;
1197 if (bss_rsn
&& (ssid
->proto
& WPA_PROTO_RSN
) &&
1198 wpa_parse_wpa_ie(bss_rsn
, 2 + bss_rsn
[1], &ie
) == 0 &&
1199 (ie
.group_cipher
& ssid
->group_cipher
) &&
1200 (ie
.pairwise_cipher
& ssid
->pairwise_cipher
) &&
1201 (ie
.key_mgmt
& ssid
->key_mgmt
)) {
1202 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: using IEEE 802.11i/D9.0");
1203 proto
= WPA_PROTO_RSN
;
1204 } else if (bss_wpa
&& (ssid
->proto
& WPA_PROTO_WPA
) &&
1205 wpa_parse_wpa_ie(bss_wpa
, 2 + bss_wpa
[1], &ie
) == 0 &&
1206 (ie
.group_cipher
& ssid
->group_cipher
) &&
1207 (ie
.pairwise_cipher
& ssid
->pairwise_cipher
) &&
1208 (ie
.key_mgmt
& ssid
->key_mgmt
)) {
1209 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using IEEE 802.11i/D3.0");
1210 proto
= WPA_PROTO_WPA
;
1212 } else if (bss_osen
&& (ssid
->proto
& WPA_PROTO_OSEN
)) {
1213 wpa_dbg(wpa_s
, MSG_DEBUG
, "HS 2.0: using OSEN");
1214 /* TODO: parse OSEN element */
1215 os_memset(&ie
, 0, sizeof(ie
));
1216 ie
.group_cipher
= WPA_CIPHER_CCMP
;
1217 ie
.pairwise_cipher
= WPA_CIPHER_CCMP
;
1218 ie
.key_mgmt
= WPA_KEY_MGMT_OSEN
;
1219 proto
= WPA_PROTO_OSEN
;
1220 } else if (bss_rsn
&& (ssid
->proto
& WPA_PROTO_OSEN
) &&
1221 wpa_parse_wpa_ie(bss_rsn
, 2 + bss_rsn
[1], &ie
) == 0 &&
1222 (ie
.group_cipher
& ssid
->group_cipher
) &&
1223 (ie
.pairwise_cipher
& ssid
->pairwise_cipher
) &&
1224 (ie
.key_mgmt
& ssid
->key_mgmt
)) {
1225 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: using OSEN (within RSN)");
1226 proto
= WPA_PROTO_RSN
;
1227 #endif /* CONFIG_HS20 */
1229 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select WPA/RSN");
1230 wpa_dbg(wpa_s
, MSG_DEBUG
,
1231 "WPA: ssid proto=0x%x pairwise_cipher=0x%x group_cipher=0x%x key_mgmt=0x%x",
1232 ssid
->proto
, ssid
->pairwise_cipher
, ssid
->group_cipher
,
1234 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: BSS " MACSTR
" ssid='%s'%s%s%s",
1235 MAC2STR(bss
->bssid
),
1236 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
),
1237 bss_wpa
? " WPA" : "",
1238 bss_rsn
? " RSN" : "",
1239 bss_osen
? " OSEN" : "");
1241 wpa_hexdump(MSG_DEBUG
, "RSN", bss_rsn
, 2 + bss_rsn
[1]);
1242 if (wpa_parse_wpa_ie(bss_rsn
, 2 + bss_rsn
[1], &ie
)) {
1243 wpa_dbg(wpa_s
, MSG_DEBUG
,
1244 "Could not parse RSN element");
1246 wpa_dbg(wpa_s
, MSG_DEBUG
,
1247 "RSN: pairwise_cipher=0x%x group_cipher=0x%x key_mgmt=0x%x",
1248 ie
.pairwise_cipher
, ie
.group_cipher
,
1253 wpa_hexdump(MSG_DEBUG
, "WPA", bss_wpa
, 2 + bss_wpa
[1]);
1254 if (wpa_parse_wpa_ie(bss_wpa
, 2 + bss_wpa
[1], &ie
)) {
1255 wpa_dbg(wpa_s
, MSG_DEBUG
,
1256 "Could not parse WPA element");
1258 wpa_dbg(wpa_s
, MSG_DEBUG
,
1259 "WPA: pairwise_cipher=0x%x group_cipher=0x%x key_mgmt=0x%x",
1260 ie
.pairwise_cipher
, ie
.group_cipher
,
1266 if (ssid
->proto
& WPA_PROTO_OSEN
)
1267 proto
= WPA_PROTO_OSEN
;
1268 else if (ssid
->proto
& WPA_PROTO_RSN
)
1269 proto
= WPA_PROTO_RSN
;
1271 proto
= WPA_PROTO_WPA
;
1272 if (wpa_supplicant_suites_from_ai(wpa_s
, ssid
, &ie
) < 0) {
1273 os_memset(&ie
, 0, sizeof(ie
));
1274 ie
.group_cipher
= ssid
->group_cipher
;
1275 ie
.pairwise_cipher
= ssid
->pairwise_cipher
;
1276 ie
.key_mgmt
= ssid
->key_mgmt
;
1277 #ifdef CONFIG_IEEE80211W
1278 ie
.mgmt_group_cipher
= 0;
1279 if (ssid
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
) {
1280 if (ssid
->group_mgmt_cipher
&
1281 WPA_CIPHER_BIP_GMAC_256
)
1282 ie
.mgmt_group_cipher
=
1283 WPA_CIPHER_BIP_GMAC_256
;
1284 else if (ssid
->group_mgmt_cipher
&
1285 WPA_CIPHER_BIP_CMAC_256
)
1286 ie
.mgmt_group_cipher
=
1287 WPA_CIPHER_BIP_CMAC_256
;
1288 else if (ssid
->group_mgmt_cipher
&
1289 WPA_CIPHER_BIP_GMAC_128
)
1290 ie
.mgmt_group_cipher
=
1291 WPA_CIPHER_BIP_GMAC_128
;
1293 ie
.mgmt_group_cipher
=
1294 WPA_CIPHER_AES_128_CMAC
;
1296 #endif /* CONFIG_IEEE80211W */
1298 if ((ssid
->key_mgmt
& WPA_KEY_MGMT_OWE
) &&
1300 !bss_wpa
&& !bss_rsn
&& !bss_osen
) {
1301 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
1302 wpa_s
->wpa_proto
= 0;
1306 #endif /* CONFIG_OWE */
1307 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Set cipher suites "
1308 "based on configuration");
1313 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Selected cipher suites: group %d "
1314 "pairwise %d key_mgmt %d proto %d",
1315 ie
.group_cipher
, ie
.pairwise_cipher
, ie
.key_mgmt
, proto
);
1316 #ifdef CONFIG_IEEE80211W
1317 if (ssid
->ieee80211w
) {
1318 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Selected mgmt group cipher %d",
1319 ie
.mgmt_group_cipher
);
1321 #endif /* CONFIG_IEEE80211W */
1323 wpa_s
->wpa_proto
= proto
;
1324 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PROTO
, proto
);
1325 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_RSN_ENABLED
,
1326 !!(ssid
->proto
& (WPA_PROTO_RSN
| WPA_PROTO_OSEN
)));
1328 if (bss
|| !wpa_s
->ap_ies_from_associnfo
) {
1329 if (wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, bss_wpa
,
1330 bss_wpa
? 2 + bss_wpa
[1] : 0) ||
1331 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, bss_rsn
,
1332 bss_rsn
? 2 + bss_rsn
[1] : 0))
1336 #ifdef CONFIG_NO_WPA
1337 wpa_s
->group_cipher
= WPA_CIPHER_NONE
;
1338 wpa_s
->pairwise_cipher
= WPA_CIPHER_NONE
;
1339 #else /* CONFIG_NO_WPA */
1340 sel
= ie
.group_cipher
& ssid
->group_cipher
;
1341 wpa_s
->group_cipher
= wpa_pick_group_cipher(sel
);
1342 if (wpa_s
->group_cipher
< 0) {
1343 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select group "
1347 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using GTK %s",
1348 wpa_cipher_txt(wpa_s
->group_cipher
));
1350 sel
= ie
.pairwise_cipher
& ssid
->pairwise_cipher
;
1351 wpa_s
->pairwise_cipher
= wpa_pick_pairwise_cipher(sel
, 1);
1352 if (wpa_s
->pairwise_cipher
< 0) {
1353 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select pairwise "
1357 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using PTK %s",
1358 wpa_cipher_txt(wpa_s
->pairwise_cipher
));
1359 #endif /* CONFIG_NO_WPA */
1361 sel
= ie
.key_mgmt
& ssid
->key_mgmt
;
1363 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
))
1364 sel
&= ~(WPA_KEY_MGMT_SAE
| WPA_KEY_MGMT_FT_SAE
);
1365 #endif /* CONFIG_SAE */
1367 #ifdef CONFIG_SUITEB192
1368 } else if (sel
& WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
1369 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
;
1370 wpa_dbg(wpa_s
, MSG_DEBUG
,
1371 "WPA: using KEY_MGMT 802.1X with Suite B (192-bit)");
1372 #endif /* CONFIG_SUITEB192 */
1373 #ifdef CONFIG_SUITEB
1374 } else if (sel
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
1375 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X_SUITE_B
;
1376 wpa_dbg(wpa_s
, MSG_DEBUG
,
1377 "WPA: using KEY_MGMT 802.1X with Suite B");
1378 #endif /* CONFIG_SUITEB */
1380 #ifdef CONFIG_IEEE80211R
1381 } else if (sel
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
1382 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_FILS_SHA384
;
1383 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FT-FILS-SHA384");
1384 } else if (sel
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
1385 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_FILS_SHA256
;
1386 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FT-FILS-SHA256");
1387 #endif /* CONFIG_IEEE80211R */
1388 } else if (sel
& WPA_KEY_MGMT_FILS_SHA384
) {
1389 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FILS_SHA384
;
1390 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FILS-SHA384");
1391 } else if (sel
& WPA_KEY_MGMT_FILS_SHA256
) {
1392 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FILS_SHA256
;
1393 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FILS-SHA256");
1394 #endif /* CONFIG_FILS */
1395 #ifdef CONFIG_IEEE80211R
1396 #ifdef CONFIG_SHA384
1397 } else if (sel
& WPA_KEY_MGMT_FT_IEEE8021X_SHA384
) {
1398 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_IEEE8021X_SHA384
;
1399 wpa_dbg(wpa_s
, MSG_DEBUG
,
1400 "WPA: using KEY_MGMT FT/802.1X-SHA384");
1401 if (pmksa_cache_get_current(wpa_s
->wpa
)) {
1402 /* PMKSA caching with FT is not fully functional, so
1403 * disable the case for now. */
1404 wpa_dbg(wpa_s
, MSG_DEBUG
,
1405 "WPA: Disable PMKSA caching for FT/802.1X connection");
1406 pmksa_cache_clear_current(wpa_s
->wpa
);
1408 #endif /* CONFIG_SHA384 */
1409 } else if (sel
& WPA_KEY_MGMT_FT_IEEE8021X
) {
1410 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_IEEE8021X
;
1411 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FT/802.1X");
1412 if (pmksa_cache_get_current(wpa_s
->wpa
)) {
1413 /* PMKSA caching with FT is not fully functional, so
1414 * disable the case for now. */
1415 wpa_dbg(wpa_s
, MSG_DEBUG
,
1416 "WPA: Disable PMKSA caching for FT/802.1X connection");
1417 pmksa_cache_clear_current(wpa_s
->wpa
);
1419 } else if (sel
& WPA_KEY_MGMT_FT_PSK
) {
1420 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_PSK
;
1421 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FT/PSK");
1422 #endif /* CONFIG_IEEE80211R */
1424 } else if (sel
& WPA_KEY_MGMT_SAE
) {
1425 wpa_s
->key_mgmt
= WPA_KEY_MGMT_SAE
;
1426 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: using KEY_MGMT SAE");
1427 } else if (sel
& WPA_KEY_MGMT_FT_SAE
) {
1428 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_SAE
;
1429 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: using KEY_MGMT FT/SAE");
1430 #endif /* CONFIG_SAE */
1431 #ifdef CONFIG_IEEE80211W
1432 } else if (sel
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
1433 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X_SHA256
;
1434 wpa_dbg(wpa_s
, MSG_DEBUG
,
1435 "WPA: using KEY_MGMT 802.1X with SHA256");
1436 } else if (sel
& WPA_KEY_MGMT_PSK_SHA256
) {
1437 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK_SHA256
;
1438 wpa_dbg(wpa_s
, MSG_DEBUG
,
1439 "WPA: using KEY_MGMT PSK with SHA256");
1440 #endif /* CONFIG_IEEE80211W */
1441 } else if (sel
& WPA_KEY_MGMT_IEEE8021X
) {
1442 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X
;
1443 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT 802.1X");
1444 } else if (sel
& WPA_KEY_MGMT_PSK
) {
1445 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK
;
1446 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT WPA-PSK");
1447 } else if (sel
& WPA_KEY_MGMT_WPA_NONE
) {
1448 wpa_s
->key_mgmt
= WPA_KEY_MGMT_WPA_NONE
;
1449 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT WPA-NONE");
1451 } else if (sel
& WPA_KEY_MGMT_OSEN
) {
1452 wpa_s
->key_mgmt
= WPA_KEY_MGMT_OSEN
;
1453 wpa_dbg(wpa_s
, MSG_DEBUG
, "HS 2.0: using KEY_MGMT OSEN");
1454 #endif /* CONFIG_HS20 */
1456 } else if (sel
& WPA_KEY_MGMT_OWE
) {
1457 wpa_s
->key_mgmt
= WPA_KEY_MGMT_OWE
;
1458 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: using KEY_MGMT OWE");
1459 #endif /* CONFIG_OWE */
1461 } else if (sel
& WPA_KEY_MGMT_DPP
) {
1462 wpa_s
->key_mgmt
= WPA_KEY_MGMT_DPP
;
1463 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: using KEY_MGMT DPP");
1464 #endif /* CONFIG_DPP */
1466 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select "
1467 "authenticated key management type");
1471 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_KEY_MGMT
, wpa_s
->key_mgmt
);
1472 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PAIRWISE
,
1473 wpa_s
->pairwise_cipher
);
1474 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_GROUP
, wpa_s
->group_cipher
);
1476 #ifdef CONFIG_IEEE80211W
1477 sel
= ie
.mgmt_group_cipher
;
1478 if (ssid
->group_mgmt_cipher
)
1479 sel
&= ssid
->group_mgmt_cipher
;
1480 if (wpas_get_ssid_pmf(wpa_s
, ssid
) == NO_MGMT_FRAME_PROTECTION
||
1481 !(ie
.capabilities
& WPA_CAPABILITY_MFPC
))
1483 if (sel
& WPA_CIPHER_AES_128_CMAC
) {
1484 wpa_s
->mgmt_group_cipher
= WPA_CIPHER_AES_128_CMAC
;
1485 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using MGMT group cipher "
1487 } else if (sel
& WPA_CIPHER_BIP_GMAC_128
) {
1488 wpa_s
->mgmt_group_cipher
= WPA_CIPHER_BIP_GMAC_128
;
1489 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using MGMT group cipher "
1491 } else if (sel
& WPA_CIPHER_BIP_GMAC_256
) {
1492 wpa_s
->mgmt_group_cipher
= WPA_CIPHER_BIP_GMAC_256
;
1493 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using MGMT group cipher "
1495 } else if (sel
& WPA_CIPHER_BIP_CMAC_256
) {
1496 wpa_s
->mgmt_group_cipher
= WPA_CIPHER_BIP_CMAC_256
;
1497 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using MGMT group cipher "
1500 wpa_s
->mgmt_group_cipher
= 0;
1501 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: not using MGMT group cipher");
1503 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MGMT_GROUP
,
1504 wpa_s
->mgmt_group_cipher
);
1505 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MFP
,
1506 wpas_get_ssid_pmf(wpa_s
, ssid
));
1507 #endif /* CONFIG_IEEE80211W */
1509 if (wpa_sm_set_assoc_wpa_ie_default(wpa_s
->wpa
, wpa_ie
, wpa_ie_len
)) {
1510 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to generate WPA IE");
1514 if (wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
)) {
1518 sae_only
= (ssid
->key_mgmt
& (WPA_KEY_MGMT_PSK
|
1519 WPA_KEY_MGMT_FT_PSK
|
1520 WPA_KEY_MGMT_PSK_SHA256
)) == 0;
1522 if (ssid
->psk_set
&& !sae_only
) {
1523 wpa_hexdump_key(MSG_MSGDUMP
, "PSK (set in config)",
1524 ssid
->psk
, PMK_LEN
);
1525 wpa_sm_set_pmk(wpa_s
->wpa
, ssid
->psk
, PMK_LEN
, NULL
,
1530 if (wpa_key_mgmt_sae(ssid
->key_mgmt
) &&
1531 (ssid
->sae_password
|| ssid
->passphrase
))
1534 #ifndef CONFIG_NO_PBKDF2
1535 if (bss
&& ssid
->bssid_set
&& ssid
->ssid_len
== 0 &&
1536 ssid
->passphrase
&& !sae_only
) {
1538 pbkdf2_sha1(ssid
->passphrase
, bss
->ssid
, bss
->ssid_len
,
1539 4096, psk
, PMK_LEN
);
1540 wpa_hexdump_key(MSG_MSGDUMP
, "PSK (from passphrase)",
1542 wpa_sm_set_pmk(wpa_s
->wpa
, psk
, PMK_LEN
, NULL
, NULL
);
1544 os_memset(psk
, 0, sizeof(psk
));
1546 #endif /* CONFIG_NO_PBKDF2 */
1547 #ifdef CONFIG_EXT_PASSWORD
1548 if (ssid
->ext_psk
&& !sae_only
) {
1549 struct wpabuf
*pw
= ext_password_get(wpa_s
->ext_pw
,
1551 char pw_str
[64 + 1];
1555 wpa_msg(wpa_s
, MSG_INFO
, "EXT PW: No PSK "
1556 "found from external storage");
1560 if (wpabuf_len(pw
) < 8 || wpabuf_len(pw
) > 64) {
1561 wpa_msg(wpa_s
, MSG_INFO
, "EXT PW: Unexpected "
1562 "PSK length %d in external storage",
1563 (int) wpabuf_len(pw
));
1564 ext_password_free(pw
);
1568 os_memcpy(pw_str
, wpabuf_head(pw
), wpabuf_len(pw
));
1569 pw_str
[wpabuf_len(pw
)] = '\0';
1571 #ifndef CONFIG_NO_PBKDF2
1572 if (wpabuf_len(pw
) >= 8 && wpabuf_len(pw
) < 64 && bss
)
1574 pbkdf2_sha1(pw_str
, bss
->ssid
, bss
->ssid_len
,
1575 4096, psk
, PMK_LEN
);
1576 os_memset(pw_str
, 0, sizeof(pw_str
));
1577 wpa_hexdump_key(MSG_MSGDUMP
, "PSK (from "
1578 "external passphrase)",
1580 wpa_sm_set_pmk(wpa_s
->wpa
, psk
, PMK_LEN
, NULL
,
1583 os_memset(psk
, 0, sizeof(psk
));
1585 #endif /* CONFIG_NO_PBKDF2 */
1586 if (wpabuf_len(pw
) == 2 * PMK_LEN
) {
1587 if (hexstr2bin(pw_str
, psk
, PMK_LEN
) < 0) {
1588 wpa_msg(wpa_s
, MSG_INFO
, "EXT PW: "
1589 "Invalid PSK hex string");
1590 os_memset(pw_str
, 0, sizeof(pw_str
));
1591 ext_password_free(pw
);
1594 wpa_hexdump_key(MSG_MSGDUMP
,
1595 "PSK (from external PSK)",
1597 wpa_sm_set_pmk(wpa_s
->wpa
, psk
, PMK_LEN
, NULL
,
1600 os_memset(psk
, 0, sizeof(psk
));
1602 wpa_msg(wpa_s
, MSG_INFO
, "EXT PW: No suitable "
1604 os_memset(pw_str
, 0, sizeof(pw_str
));
1605 ext_password_free(pw
);
1609 os_memset(pw_str
, 0, sizeof(pw_str
));
1610 ext_password_free(pw
);
1612 #endif /* CONFIG_EXT_PASSWORD */
1615 wpa_msg(wpa_s
, MSG_INFO
,
1616 "No PSK available for association");
1617 wpas_auth_failed(wpa_s
, "NO_PSK_AVAILABLE");
1621 } else if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
) {
1622 /* OWE Diffie-Hellman exchange in (Re)Association
1623 * Request/Response frames set the PMK, so do not override it
1625 #endif /* CONFIG_OWE */
1627 wpa_sm_set_pmk_from_pmksa(wpa_s
->wpa
);
1633 static void wpas_ext_capab_byte(struct wpa_supplicant
*wpa_s
, u8
*pos
, int idx
)
1638 case 0: /* Bits 0-7 */
1640 case 1: /* Bits 8-15 */
1642 case 2: /* Bits 16-23 */
1644 *pos
|= 0x02; /* Bit 17 - WNM-Sleep Mode */
1645 *pos
|= 0x08; /* Bit 19 - BSS Transition */
1646 #endif /* CONFIG_WNM */
1648 case 3: /* Bits 24-31 */
1650 *pos
|= 0x02; /* Bit 25 - SSID List */
1651 #endif /* CONFIG_WNM */
1652 #ifdef CONFIG_INTERWORKING
1653 if (wpa_s
->conf
->interworking
)
1654 *pos
|= 0x80; /* Bit 31 - Interworking */
1655 #endif /* CONFIG_INTERWORKING */
1657 case 4: /* Bits 32-39 */
1658 #ifdef CONFIG_INTERWORKING
1659 if (wpa_s
->drv_flags
/ WPA_DRIVER_FLAGS_QOS_MAPPING
)
1660 *pos
|= 0x01; /* Bit 32 - QoS Map */
1661 #endif /* CONFIG_INTERWORKING */
1663 case 5: /* Bits 40-47 */
1665 if (wpa_s
->conf
->hs20
)
1666 *pos
|= 0x40; /* Bit 46 - WNM-Notification */
1667 #endif /* CONFIG_HS20 */
1669 *pos
|= 0x40; /* Bit 46 - WNM-Notification */
1670 #endif /* CONFIG_MBO */
1672 case 6: /* Bits 48-55 */
1674 case 7: /* Bits 56-63 */
1676 case 8: /* Bits 64-71 */
1677 if (wpa_s
->conf
->ftm_responder
)
1678 *pos
|= 0x40; /* Bit 70 - FTM responder */
1679 if (wpa_s
->conf
->ftm_initiator
)
1680 *pos
|= 0x80; /* Bit 71 - FTM initiator */
1682 case 9: /* Bits 72-79 */
1684 if (!wpa_s
->disable_fils
)
1686 #endif /* CONFIG_FILS */
1692 int wpas_build_ext_capab(struct wpa_supplicant
*wpa_s
, u8
*buf
, size_t buflen
)
1697 if (len
< wpa_s
->extended_capa_len
)
1698 len
= wpa_s
->extended_capa_len
;
1699 if (buflen
< (size_t) len
+ 2) {
1700 wpa_printf(MSG_INFO
,
1701 "Not enough room for building extended capabilities element");
1705 *pos
++ = WLAN_EID_EXT_CAPAB
;
1707 for (i
= 0; i
< len
; i
++, pos
++) {
1708 wpas_ext_capab_byte(wpa_s
, pos
, i
);
1710 if (i
< wpa_s
->extended_capa_len
) {
1711 *pos
&= ~wpa_s
->extended_capa_mask
[i
];
1712 *pos
|= wpa_s
->extended_capa
[i
];
1716 while (len
> 0 && buf
[1 + len
] == 0) {
1727 static int wpas_valid_bss(struct wpa_supplicant
*wpa_s
,
1728 struct wpa_bss
*test_bss
)
1730 struct wpa_bss
*bss
;
1732 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
1733 if (bss
== test_bss
)
1741 static int wpas_valid_ssid(struct wpa_supplicant
*wpa_s
,
1742 struct wpa_ssid
*test_ssid
)
1744 struct wpa_ssid
*ssid
;
1746 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
1747 if (ssid
== test_ssid
)
1755 int wpas_valid_bss_ssid(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*test_bss
,
1756 struct wpa_ssid
*test_ssid
)
1758 if (test_bss
&& !wpas_valid_bss(wpa_s
, test_bss
))
1761 return test_ssid
== NULL
|| wpas_valid_ssid(wpa_s
, test_ssid
);
1765 void wpas_connect_work_free(struct wpa_connect_work
*cwork
)
1773 void wpas_connect_work_done(struct wpa_supplicant
*wpa_s
)
1775 struct wpa_connect_work
*cwork
;
1776 struct wpa_radio_work
*work
= wpa_s
->connect_work
;
1781 wpa_s
->connect_work
= NULL
;
1784 wpas_connect_work_free(cwork
);
1785 radio_work_done(work
);
1789 int wpas_update_random_addr(struct wpa_supplicant
*wpa_s
, int style
)
1791 struct os_reltime now
;
1794 os_get_reltime(&now
);
1795 if (wpa_s
->last_mac_addr_style
== style
&&
1796 wpa_s
->last_mac_addr_change
.sec
!= 0 &&
1797 !os_reltime_expired(&now
, &wpa_s
->last_mac_addr_change
,
1798 wpa_s
->conf
->rand_addr_lifetime
)) {
1799 wpa_msg(wpa_s
, MSG_DEBUG
,
1800 "Previously selected random MAC address has not yet expired");
1806 if (random_mac_addr(addr
) < 0)
1810 os_memcpy(addr
, wpa_s
->perm_addr
, ETH_ALEN
);
1811 if (random_mac_addr_keep_oui(addr
) < 0)
1818 if (wpa_drv_set_mac_addr(wpa_s
, addr
) < 0) {
1819 wpa_msg(wpa_s
, MSG_INFO
,
1820 "Failed to set random MAC address");
1824 os_get_reltime(&wpa_s
->last_mac_addr_change
);
1825 wpa_s
->mac_addr_changed
= 1;
1826 wpa_s
->last_mac_addr_style
= style
;
1828 if (wpa_supplicant_update_mac_addr(wpa_s
) < 0) {
1829 wpa_msg(wpa_s
, MSG_INFO
,
1830 "Could not update MAC address information");
1834 wpa_msg(wpa_s
, MSG_DEBUG
, "Using random MAC address " MACSTR
,
1841 int wpas_update_random_addr_disassoc(struct wpa_supplicant
*wpa_s
)
1843 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
||
1844 !wpa_s
->conf
->preassoc_mac_addr
)
1847 return wpas_update_random_addr(wpa_s
, wpa_s
->conf
->preassoc_mac_addr
);
1851 static void wpas_start_assoc_cb(struct wpa_radio_work
*work
, int deinit
);
1854 * wpa_supplicant_associate - Request association
1855 * @wpa_s: Pointer to wpa_supplicant data
1856 * @bss: Scan results for the selected BSS, or %NULL if not available
1857 * @ssid: Configuration data for the selected network
1859 * This function is used to request %wpa_supplicant to associate with a BSS.
1861 void wpa_supplicant_associate(struct wpa_supplicant
*wpa_s
,
1862 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
)
1864 struct wpa_connect_work
*cwork
;
1867 wpa_s
->own_disconnect_req
= 0;
1870 * If we are starting a new connection, any previously pending EAPOL
1871 * RX cannot be valid anymore.
1873 wpabuf_free(wpa_s
->pending_eapol_rx
);
1874 wpa_s
->pending_eapol_rx
= NULL
;
1876 if (ssid
->mac_addr
== -1)
1877 rand_style
= wpa_s
->conf
->mac_addr
;
1879 rand_style
= ssid
->mac_addr
;
1881 wmm_ac_clear_saved_tspecs(wpa_s
);
1882 wpa_s
->reassoc_same_bss
= 0;
1883 wpa_s
->reassoc_same_ess
= 0;
1884 #ifdef CONFIG_TESTING_OPTIONS
1885 wpa_s
->testing_resend_assoc
= 0;
1886 #endif /* CONFIG_TESTING_OPTIONS */
1888 if (wpa_s
->last_ssid
== ssid
) {
1889 wpa_dbg(wpa_s
, MSG_DEBUG
, "Re-association to the same ESS");
1890 wpa_s
->reassoc_same_ess
= 1;
1891 if (wpa_s
->current_bss
&& wpa_s
->current_bss
== bss
) {
1892 wmm_ac_save_tspecs(wpa_s
);
1893 wpa_s
->reassoc_same_bss
= 1;
1897 if (rand_style
> 0 && !wpa_s
->reassoc_same_ess
) {
1898 if (wpas_update_random_addr(wpa_s
, rand_style
) < 0)
1900 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
1901 } else if (rand_style
== 0 && wpa_s
->mac_addr_changed
) {
1902 if (wpa_drv_set_mac_addr(wpa_s
, NULL
) < 0) {
1903 wpa_msg(wpa_s
, MSG_INFO
,
1904 "Could not restore permanent MAC address");
1907 wpa_s
->mac_addr_changed
= 0;
1908 if (wpa_supplicant_update_mac_addr(wpa_s
) < 0) {
1909 wpa_msg(wpa_s
, MSG_INFO
,
1910 "Could not update MAC address information");
1913 wpa_msg(wpa_s
, MSG_DEBUG
, "Using permanent MAC address");
1915 wpa_s
->last_ssid
= ssid
;
1917 #ifdef CONFIG_IBSS_RSN
1918 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
1919 wpa_s
->ibss_rsn
= NULL
;
1920 #else /* CONFIG_IBSS_RSN */
1921 if (ssid
->mode
== WPAS_MODE_IBSS
&&
1922 !(ssid
->key_mgmt
& (WPA_KEY_MGMT_NONE
| WPA_KEY_MGMT_WPA_NONE
))) {
1923 wpa_msg(wpa_s
, MSG_INFO
,
1924 "IBSS RSN not supported in the build");
1927 #endif /* CONFIG_IBSS_RSN */
1929 if (ssid
->mode
== WPAS_MODE_AP
|| ssid
->mode
== WPAS_MODE_P2P_GO
||
1930 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
) {
1932 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_AP
)) {
1933 wpa_msg(wpa_s
, MSG_INFO
, "Driver does not support AP "
1937 if (wpa_supplicant_create_ap(wpa_s
, ssid
) < 0) {
1938 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1939 if (ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)
1940 wpas_p2p_ap_setup_failed(wpa_s
);
1943 wpa_s
->current_bss
= bss
;
1944 #else /* CONFIG_AP */
1945 wpa_msg(wpa_s
, MSG_ERROR
, "AP mode support not included in "
1947 #endif /* CONFIG_AP */
1951 if (ssid
->mode
== WPAS_MODE_MESH
) {
1953 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_MESH
)) {
1954 wpa_msg(wpa_s
, MSG_INFO
,
1955 "Driver does not support mesh mode");
1959 ssid
->frequency
= bss
->freq
;
1960 if (wpa_supplicant_join_mesh(wpa_s
, ssid
) < 0) {
1961 wpa_msg(wpa_s
, MSG_ERROR
, "Could not join mesh");
1964 wpa_s
->current_bss
= bss
;
1965 wpa_msg(wpa_s
, MSG_INFO
, MESH_GROUP_STARTED
"ssid=\"%s\" id=%d",
1966 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
),
1968 wpas_notify_mesh_group_started(wpa_s
, ssid
);
1969 #else /* CONFIG_MESH */
1970 wpa_msg(wpa_s
, MSG_ERROR
,
1971 "mesh mode support not included in the build");
1972 #endif /* CONFIG_MESH */
1977 * Set WPA state machine configuration to match the selected network now
1978 * so that the information is available before wpas_start_assoc_cb()
1979 * gets called. This is needed at least for RSN pre-authentication where
1980 * candidate APs are added to a list based on scan result processing
1981 * before completion of the first association.
1983 wpa_supplicant_rsn_supp_set_config(wpa_s
, ssid
);
1986 if (wpas_dpp_check_connect(wpa_s
, ssid
, bss
) != 0)
1988 #endif /* CONFIG_DPP */
1992 wpa_tdls_ap_ies(wpa_s
->wpa
, (const u8
*) (bss
+ 1),
1994 #endif /* CONFIG_TDLS */
1996 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
1997 ssid
->mode
== IEEE80211_MODE_INFRA
) {
1998 sme_authenticate(wpa_s
, bss
, ssid
);
2002 if (wpa_s
->connect_work
) {
2003 wpa_dbg(wpa_s
, MSG_DEBUG
, "Reject wpa_supplicant_associate() call since connect_work exist");
2007 if (radio_work_pending(wpa_s
, "connect")) {
2008 wpa_dbg(wpa_s
, MSG_DEBUG
, "Reject wpa_supplicant_associate() call since pending work exist");
2013 if (ssid
->mode
== WPAS_MODE_IBSS
|| ssid
->mode
== WPAS_MODE_MESH
) {
2014 /* Clear possibly set auth_alg, if any, from last attempt. */
2015 wpa_s
->sme
.auth_alg
= WPA_AUTH_ALG_OPEN
;
2017 #endif /* CONFIG_SME */
2019 wpas_abort_ongoing_scan(wpa_s
);
2021 cwork
= os_zalloc(sizeof(*cwork
));
2028 if (radio_add_work(wpa_s
, bss
? bss
->freq
: 0, "connect", 1,
2029 wpas_start_assoc_cb
, cwork
) < 0) {
2035 static int bss_is_ibss(struct wpa_bss
*bss
)
2037 return (bss
->caps
& (IEEE80211_CAP_ESS
| IEEE80211_CAP_IBSS
)) ==
2042 static int drv_supports_vht(struct wpa_supplicant
*wpa_s
,
2043 const struct wpa_ssid
*ssid
)
2045 enum hostapd_hw_mode hw_mode
;
2046 struct hostapd_hw_modes
*mode
= NULL
;
2050 hw_mode
= ieee80211_freq_to_chan(ssid
->frequency
, &channel
);
2051 if (hw_mode
== NUM_HOSTAPD_MODES
)
2053 for (i
= 0; wpa_s
->hw
.modes
&& i
< wpa_s
->hw
.num_modes
; i
++) {
2054 if (wpa_s
->hw
.modes
[i
].mode
== hw_mode
) {
2055 mode
= &wpa_s
->hw
.modes
[i
];
2063 return mode
->vht_capab
!= 0;
2067 void ibss_mesh_setup_freq(struct wpa_supplicant
*wpa_s
,
2068 const struct wpa_ssid
*ssid
,
2069 struct hostapd_freq_params
*freq
)
2071 enum hostapd_hw_mode hw_mode
;
2072 struct hostapd_hw_modes
*mode
= NULL
;
2073 int ht40plus
[] = { 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157,
2075 int vht80
[] = { 36, 52, 100, 116, 132, 149 };
2076 struct hostapd_channel_data
*pri_chan
= NULL
, *sec_chan
= NULL
;
2078 int i
, chan_idx
, ht40
= -1, res
, obss_scan
= 1;
2080 struct hostapd_freq_params vht_freq
;
2081 int chwidth
, seg0
, seg1
;
2084 freq
->freq
= ssid
->frequency
;
2086 for (j
= 0; j
< wpa_s
->last_scan_res_used
; j
++) {
2087 struct wpa_bss
*bss
= wpa_s
->last_scan_res
[j
];
2089 if (ssid
->mode
!= WPAS_MODE_IBSS
)
2092 /* Don't adjust control freq in case of fixed_freq */
2093 if (ssid
->fixed_freq
)
2096 if (!bss_is_ibss(bss
))
2099 if (ssid
->ssid_len
== bss
->ssid_len
&&
2100 os_memcmp(ssid
->ssid
, bss
->ssid
, bss
->ssid_len
) == 0) {
2101 wpa_printf(MSG_DEBUG
,
2102 "IBSS already found in scan results, adjust control freq: %d",
2104 freq
->freq
= bss
->freq
;
2110 /* For IBSS check HT_IBSS flag */
2111 if (ssid
->mode
== WPAS_MODE_IBSS
&&
2112 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_HT_IBSS
))
2115 if (wpa_s
->group_cipher
== WPA_CIPHER_WEP40
||
2116 wpa_s
->group_cipher
== WPA_CIPHER_WEP104
||
2117 wpa_s
->pairwise_cipher
== WPA_CIPHER_TKIP
) {
2118 wpa_printf(MSG_DEBUG
,
2119 "IBSS: WEP/TKIP detected, do not try to enable HT");
2123 hw_mode
= ieee80211_freq_to_chan(freq
->freq
, &channel
);
2124 for (i
= 0; wpa_s
->hw
.modes
&& i
< wpa_s
->hw
.num_modes
; i
++) {
2125 if (wpa_s
->hw
.modes
[i
].mode
== hw_mode
) {
2126 mode
= &wpa_s
->hw
.modes
[i
];
2134 #ifdef CONFIG_HT_OVERRIDES
2135 if (ssid
->disable_ht
) {
2136 freq
->ht_enabled
= 0;
2139 #endif /* CONFIG_HT_OVERRIDES */
2141 freq
->ht_enabled
= ht_supported(mode
);
2142 if (!freq
->ht_enabled
)
2145 /* Setup higher BW only for 5 GHz */
2146 if (mode
->mode
!= HOSTAPD_MODE_IEEE80211A
)
2149 for (chan_idx
= 0; chan_idx
< mode
->num_channels
; chan_idx
++) {
2150 pri_chan
= &mode
->channels
[chan_idx
];
2151 if (pri_chan
->chan
== channel
)
2158 /* Check primary channel flags */
2159 if (pri_chan
->flag
& (HOSTAPD_CHAN_DISABLED
| HOSTAPD_CHAN_NO_IR
))
2162 #ifdef CONFIG_HT_OVERRIDES
2163 if (ssid
->disable_ht40
)
2165 #endif /* CONFIG_HT_OVERRIDES */
2167 /* Check/setup HT40+/HT40- */
2168 for (j
= 0; j
< ARRAY_SIZE(ht40plus
); j
++) {
2169 if (ht40plus
[j
] == channel
) {
2175 /* Find secondary channel */
2176 for (i
= 0; i
< mode
->num_channels
; i
++) {
2177 sec_chan
= &mode
->channels
[i
];
2178 if (sec_chan
->chan
== channel
+ ht40
* 4)
2185 /* Check secondary channel flags */
2186 if (sec_chan
->flag
& (HOSTAPD_CHAN_DISABLED
| HOSTAPD_CHAN_NO_IR
))
2189 freq
->channel
= pri_chan
->chan
;
2192 if (!(pri_chan
->flag
& HOSTAPD_CHAN_HT40MINUS
))
2195 if (!(pri_chan
->flag
& HOSTAPD_CHAN_HT40PLUS
))
2198 freq
->sec_channel_offset
= ht40
;
2201 struct wpa_scan_results
*scan_res
;
2203 scan_res
= wpa_supplicant_get_scan_results(wpa_s
, NULL
, 0);
2204 if (scan_res
== NULL
) {
2206 freq
->sec_channel_offset
= 0;
2210 res
= check_40mhz_5g(mode
, scan_res
, pri_chan
->chan
,
2215 freq
->sec_channel_offset
= 0;
2218 /* Configuration allowed */
2221 /* Switch pri/sec channels */
2222 freq
->freq
= hw_get_freq(mode
, sec_chan
->chan
);
2223 freq
->sec_channel_offset
= -freq
->sec_channel_offset
;
2224 freq
->channel
= sec_chan
->chan
;
2227 freq
->sec_channel_offset
= 0;
2231 wpa_scan_results_free(scan_res
);
2234 wpa_printf(MSG_DEBUG
,
2235 "IBSS/mesh: setup freq channel %d, sec_channel_offset %d",
2236 freq
->channel
, freq
->sec_channel_offset
);
2238 if (!drv_supports_vht(wpa_s
, ssid
))
2241 /* For IBSS check VHT_IBSS flag */
2242 if (ssid
->mode
== WPAS_MODE_IBSS
&&
2243 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_VHT_IBSS
))
2248 #ifdef CONFIG_VHT_OVERRIDES
2249 if (ssid
->disable_vht
) {
2250 freq
->vht_enabled
= 0;
2253 #endif /* CONFIG_VHT_OVERRIDES */
2255 vht_freq
.vht_enabled
= vht_supported(mode
);
2256 if (!vht_freq
.vht_enabled
)
2259 /* setup center_freq1, bandwidth */
2260 for (j
= 0; j
< ARRAY_SIZE(vht80
); j
++) {
2261 if (freq
->channel
>= vht80
[j
] &&
2262 freq
->channel
< vht80
[j
] + 16)
2266 if (j
== ARRAY_SIZE(vht80
))
2269 for (i
= vht80
[j
]; i
< vht80
[j
] + 16; i
+= 4) {
2270 struct hostapd_channel_data
*chan
;
2272 chan
= hw_get_channel_chan(mode
, i
, NULL
);
2276 /* Back to HT configuration if channel not usable */
2277 if (chan
->flag
& (HOSTAPD_CHAN_DISABLED
| HOSTAPD_CHAN_NO_IR
))
2281 chwidth
= VHT_CHANWIDTH_80MHZ
;
2282 seg0
= vht80
[j
] + 6;
2285 if (ssid
->max_oper_chwidth
== VHT_CHANWIDTH_80P80MHZ
) {
2286 /* setup center_freq2, bandwidth */
2287 for (k
= 0; k
< ARRAY_SIZE(vht80
); k
++) {
2288 /* Only accept 80 MHz segments separated by a gap */
2289 if (j
== k
|| abs(vht80
[j
] - vht80
[k
]) == 16)
2291 for (i
= vht80
[k
]; i
< vht80
[k
] + 16; i
+= 4) {
2292 struct hostapd_channel_data
*chan
;
2294 chan
= hw_get_channel_chan(mode
, i
, NULL
);
2298 if (chan
->flag
& (HOSTAPD_CHAN_DISABLED
|
2299 HOSTAPD_CHAN_NO_IR
|
2300 HOSTAPD_CHAN_RADAR
))
2303 /* Found a suitable second segment for 80+80 */
2304 chwidth
= VHT_CHANWIDTH_80P80MHZ
;
2306 VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ
;
2307 seg1
= vht80
[k
] + 6;
2310 if (chwidth
== VHT_CHANWIDTH_80P80MHZ
)
2313 } else if (ssid
->max_oper_chwidth
== VHT_CHANWIDTH_160MHZ
) {
2314 if (freq
->freq
== 5180) {
2315 chwidth
= VHT_CHANWIDTH_160MHZ
;
2316 vht_caps
|= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
;
2318 } else if (freq
->freq
== 5520) {
2319 chwidth
= VHT_CHANWIDTH_160MHZ
;
2320 vht_caps
|= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
;
2325 if (hostapd_set_freq_params(&vht_freq
, mode
->mode
, freq
->freq
,
2326 freq
->channel
, freq
->ht_enabled
,
2327 vht_freq
.vht_enabled
,
2328 freq
->sec_channel_offset
,
2329 chwidth
, seg0
, seg1
, vht_caps
) != 0)
2334 wpa_printf(MSG_DEBUG
, "IBSS: VHT setup freq cf1 %d, cf2 %d, bw %d",
2335 freq
->center_freq1
, freq
->center_freq2
, freq
->bandwidth
);
2340 static size_t wpas_add_fils_hlp_req(struct wpa_supplicant
*wpa_s
, u8
*ie_buf
,
2343 struct fils_hlp_req
*req
;
2344 size_t rem_len
, hdr_len
, hlp_len
, len
, ie_len
= 0;
2348 dl_list_for_each(req
, &wpa_s
->fils_hlp_req
, struct fils_hlp_req
,
2350 rem_len
= ie_buf_len
- ie_len
;
2351 pos
= wpabuf_head(req
->pkt
);
2352 hdr_len
= 1 + 2 * ETH_ALEN
+ 6;
2353 hlp_len
= wpabuf_len(req
->pkt
);
2355 if (rem_len
< 2 + hdr_len
+ hlp_len
) {
2356 wpa_printf(MSG_ERROR
,
2357 "FILS: Cannot fit HLP - rem_len=%lu to_fill=%lu",
2358 (unsigned long) rem_len
,
2359 (unsigned long) (2 + hdr_len
+ hlp_len
));
2363 len
= (hdr_len
+ hlp_len
) > 255 ? 255 : hdr_len
+ hlp_len
;
2365 *buf
++ = WLAN_EID_EXTENSION
;
2368 /* Element ID Extension */
2369 *buf
++ = WLAN_EID_EXT_FILS_HLP_CONTAINER
;
2370 /* Destination MAC address */
2371 os_memcpy(buf
, req
->dst
, ETH_ALEN
);
2373 /* Source MAC address */
2374 os_memcpy(buf
, wpa_s
->own_addr
, ETH_ALEN
);
2376 /* LLC/SNAP Header */
2377 os_memcpy(buf
, "\xaa\xaa\x03\x00\x00\x00", 6);
2380 os_memcpy(buf
, pos
, len
- hdr_len
);
2381 buf
+= len
- hdr_len
;
2382 pos
+= len
- hdr_len
;
2384 hlp_len
-= len
- hdr_len
;
2389 len
= (hlp_len
> 255) ? 255 : hlp_len
;
2390 if (rem_len
< 2 + len
)
2392 *buf
++ = WLAN_EID_FRAGMENT
;
2394 os_memcpy(buf
, pos
, len
);
2408 int wpa_is_fils_supported(struct wpa_supplicant
*wpa_s
)
2410 return (((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
2411 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SUPPORT_FILS
)) ||
2412 (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
2413 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD
)));
2417 int wpa_is_fils_sk_pfs_supported(struct wpa_supplicant
*wpa_s
)
2419 #ifdef CONFIG_FILS_SK_PFS
2420 return (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
2421 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SUPPORT_FILS
);
2422 #else /* CONFIG_FILS_SK_PFS */
2424 #endif /* CONFIG_FILS_SK_PFS */
2427 #endif /* CONFIG_FILS */
2430 static u8
* wpas_populate_assoc_ies(
2431 struct wpa_supplicant
*wpa_s
,
2432 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
,
2433 struct wpa_driver_associate_params
*params
,
2434 enum wpa_drv_update_connect_params_mask
*mask
)
2437 size_t max_wpa_ie_len
= 500;
2439 int algs
= WPA_AUTH_ALG_OPEN
;
2441 const u8
*realm
, *username
, *rrk
;
2442 size_t realm_len
, username_len
, rrk_len
;
2444 struct fils_hlp_req
*req
;
2446 dl_list_for_each(req
, &wpa_s
->fils_hlp_req
, struct fils_hlp_req
,
2448 max_wpa_ie_len
+= 3 + 2 * ETH_ALEN
+ 6 + wpabuf_len(req
->pkt
) +
2449 2 + 2 * wpabuf_len(req
->pkt
) / 255;
2451 #endif /* CONFIG_FILS */
2453 wpa_ie
= os_malloc(max_wpa_ie_len
);
2455 wpa_printf(MSG_ERROR
,
2456 "Failed to allocate connect IE buffer for %lu bytes",
2457 (unsigned long) max_wpa_ie_len
);
2461 if (bss
&& (wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
) ||
2462 wpa_bss_get_ie(bss
, WLAN_EID_RSN
)) &&
2463 wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
2464 int try_opportunistic
;
2465 const u8
*cache_id
= NULL
;
2467 try_opportunistic
= (ssid
->proactive_key_caching
< 0 ?
2469 ssid
->proactive_key_caching
) &&
2470 (ssid
->proto
& WPA_PROTO_RSN
);
2472 if (wpa_key_mgmt_fils(ssid
->key_mgmt
))
2473 cache_id
= wpa_bss_get_fils_cache_id(bss
);
2474 #endif /* CONFIG_FILS */
2475 if (pmksa_cache_set_current(wpa_s
->wpa
, NULL
, bss
->bssid
,
2476 ssid
, try_opportunistic
,
2478 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
);
2479 wpa_ie_len
= max_wpa_ie_len
;
2480 if (wpa_supplicant_set_suites(wpa_s
, bss
, ssid
,
2481 wpa_ie
, &wpa_ie_len
)) {
2482 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to set WPA "
2483 "key management and encryption suites");
2487 } else if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) && bss
&&
2488 wpa_key_mgmt_wpa_ieee8021x(ssid
->key_mgmt
)) {
2490 * Both WPA and non-WPA IEEE 802.1X enabled in configuration -
2491 * use non-WPA since the scan results did not indicate that the
2492 * AP is using WPA or WPA2.
2494 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
2496 wpa_s
->wpa_proto
= 0;
2497 } else if (wpa_key_mgmt_wpa_any(ssid
->key_mgmt
)) {
2498 wpa_ie_len
= max_wpa_ie_len
;
2499 if (wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
2500 wpa_ie
, &wpa_ie_len
)) {
2501 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to set WPA "
2502 "key management and encryption suites (no "
2508 } else if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
2509 struct wpabuf
*wps_ie
;
2510 wps_ie
= wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid
));
2511 if (wps_ie
&& wpabuf_len(wps_ie
) <= max_wpa_ie_len
) {
2512 wpa_ie_len
= wpabuf_len(wps_ie
);
2513 os_memcpy(wpa_ie
, wpabuf_head(wps_ie
), wpa_ie_len
);
2516 wpabuf_free(wps_ie
);
2517 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
2518 if (!bss
|| (bss
->caps
& IEEE80211_CAP_PRIVACY
))
2519 params
->wps
= WPS_MODE_PRIVACY
;
2521 params
->wps
= WPS_MODE_OPEN
;
2522 wpa_s
->wpa_proto
= 0;
2523 #endif /* CONFIG_WPS */
2525 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
2527 wpa_s
->wpa_proto
= 0;
2530 #ifdef IEEE8021X_EAPOL
2531 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
2533 if (ssid
->non_leap
== 0)
2534 algs
= WPA_AUTH_ALG_LEAP
;
2536 algs
|= WPA_AUTH_ALG_LEAP
;
2541 /* Clear FILS association */
2542 wpa_sm_set_reset_fils_completed(wpa_s
->wpa
, 0);
2544 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD
) &&
2545 ssid
->eap
.erp
&& wpa_key_mgmt_fils(wpa_s
->key_mgmt
) &&
2546 eapol_sm_get_erp_info(wpa_s
->eapol
, &ssid
->eap
, &username
,
2547 &username_len
, &realm
, &realm_len
,
2548 &next_seq_num
, &rrk
, &rrk_len
) == 0) {
2549 algs
= WPA_AUTH_ALG_FILS
;
2550 params
->fils_erp_username
= username
;
2551 params
->fils_erp_username_len
= username_len
;
2552 params
->fils_erp_realm
= realm
;
2553 params
->fils_erp_realm_len
= realm_len
;
2554 params
->fils_erp_next_seq_num
= next_seq_num
;
2555 params
->fils_erp_rrk
= rrk
;
2556 params
->fils_erp_rrk_len
= rrk_len
;
2559 *mask
|= WPA_DRV_UPDATE_FILS_ERP_INFO
;
2561 #endif /* CONFIG_FILS */
2562 #endif /* IEEE8021X_EAPOL */
2564 if (wpa_s
->key_mgmt
& (WPA_KEY_MGMT_SAE
| WPA_KEY_MGMT_FT_SAE
))
2565 algs
= WPA_AUTH_ALG_SAE
;
2566 #endif /* CONFIG_SAE */
2568 wpa_dbg(wpa_s
, MSG_DEBUG
, "Automatic auth_alg selection: 0x%x", algs
);
2569 if (ssid
->auth_alg
) {
2570 algs
= ssid
->auth_alg
;
2571 wpa_dbg(wpa_s
, MSG_DEBUG
,
2572 "Overriding auth_alg selection: 0x%x", algs
);
2576 if (wpa_s
->global
->p2p
) {
2580 pos
= wpa_ie
+ wpa_ie_len
;
2581 len
= max_wpa_ie_len
- wpa_ie_len
;
2582 res
= wpas_p2p_assoc_req_ie(wpa_s
, bss
, pos
, len
,
2588 wpa_s
->cross_connect_disallowed
= 0;
2591 p2p
= wpa_bss_get_vendor_ie_multi(bss
, P2P_IE_VENDOR_TYPE
);
2593 wpa_s
->cross_connect_disallowed
=
2594 p2p_get_cross_connect_disallowed(p2p
);
2596 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: WLAN AP %s cross "
2598 wpa_s
->cross_connect_disallowed
?
2599 "disallows" : "allows");
2603 os_memset(wpa_s
->p2p_ip_addr_info
, 0, sizeof(wpa_s
->p2p_ip_addr_info
));
2604 #endif /* CONFIG_P2P */
2607 wpa_ie_len
+= wpas_supp_op_class_ie(wpa_s
, bss
->freq
,
2608 wpa_ie
+ wpa_ie_len
,
2614 * Workaround: Add Extended Capabilities element only if the AP
2615 * included this element in Beacon/Probe Response frames. Some older
2616 * APs seem to have interoperability issues if this element is
2617 * included, so while the standard may require us to include the
2618 * element in all cases, it is justifiable to skip it to avoid
2619 * interoperability issues.
2621 if (ssid
->p2p_group
)
2622 wpa_drv_get_ext_capa(wpa_s
, WPA_IF_P2P_CLIENT
);
2624 wpa_drv_get_ext_capa(wpa_s
, WPA_IF_STATION
);
2626 if (!bss
|| wpa_bss_get_ie(bss
, WLAN_EID_EXT_CAPAB
)) {
2629 ext_capab_len
= wpas_build_ext_capab(wpa_s
, ext_capab
,
2631 if (ext_capab_len
> 0 &&
2632 wpa_ie_len
+ ext_capab_len
<= max_wpa_ie_len
) {
2634 if (wpa_ie_len
> 0 && pos
[0] == WLAN_EID_RSN
)
2636 os_memmove(pos
+ ext_capab_len
, pos
,
2637 wpa_ie_len
- (pos
- wpa_ie
));
2638 wpa_ie_len
+= ext_capab_len
;
2639 os_memcpy(pos
, ext_capab
, ext_capab_len
);
2644 if (is_hs20_network(wpa_s
, ssid
, bss
)) {
2645 struct wpabuf
*hs20
;
2647 hs20
= wpabuf_alloc(20 + MAX_ROAMING_CONS_OI_LEN
);
2649 int pps_mo_id
= hs20_get_pps_mo_id(wpa_s
, ssid
);
2652 wpas_hs20_add_indication(hs20
, pps_mo_id
);
2653 wpas_hs20_add_roam_cons_sel(hs20
, ssid
);
2654 len
= max_wpa_ie_len
- wpa_ie_len
;
2655 if (wpabuf_len(hs20
) <= len
) {
2656 os_memcpy(wpa_ie
+ wpa_ie_len
,
2657 wpabuf_head(hs20
), wpabuf_len(hs20
));
2658 wpa_ie_len
+= wpabuf_len(hs20
);
2662 hs20_configure_frame_filters(wpa_s
);
2665 #endif /* CONFIG_HS20 */
2667 if (wpa_s
->vendor_elem
[VENDOR_ELEM_ASSOC_REQ
]) {
2668 struct wpabuf
*buf
= wpa_s
->vendor_elem
[VENDOR_ELEM_ASSOC_REQ
];
2671 len
= max_wpa_ie_len
- wpa_ie_len
;
2672 if (wpabuf_len(buf
) <= len
) {
2673 os_memcpy(wpa_ie
+ wpa_ie_len
,
2674 wpabuf_head(buf
), wpabuf_len(buf
));
2675 wpa_ie_len
+= wpabuf_len(buf
);
2680 if (wpa_s
->fst_ies
) {
2681 int fst_ies_len
= wpabuf_len(wpa_s
->fst_ies
);
2683 if (wpa_ie_len
+ fst_ies_len
<= max_wpa_ie_len
) {
2684 os_memcpy(wpa_ie
+ wpa_ie_len
,
2685 wpabuf_head(wpa_s
->fst_ies
), fst_ies_len
);
2686 wpa_ie_len
+= fst_ies_len
;
2689 #endif /* CONFIG_FST */
2692 if (bss
&& wpa_bss_get_vendor_ie(bss
, MBO_IE_VENDOR_TYPE
)) {
2695 len
= wpas_mbo_ie(wpa_s
, wpa_ie
+ wpa_ie_len
,
2696 max_wpa_ie_len
- wpa_ie_len
);
2700 #endif /* CONFIG_MBO */
2703 if (algs
== WPA_AUTH_ALG_FILS
) {
2706 len
= wpas_add_fils_hlp_req(wpa_s
, wpa_ie
+ wpa_ie_len
,
2707 max_wpa_ie_len
- wpa_ie_len
);
2710 #endif /* CONFIG_FILS */
2713 #ifdef CONFIG_TESTING_OPTIONS
2714 if (get_ie_ext(wpa_ie
, wpa_ie_len
, WLAN_EID_EXT_OWE_DH_PARAM
)) {
2715 wpa_printf(MSG_INFO
, "TESTING: Override OWE DH element");
2717 #endif /* CONFIG_TESTING_OPTIONS */
2718 if (algs
== WPA_AUTH_ALG_OPEN
&&
2719 ssid
->key_mgmt
== WPA_KEY_MGMT_OWE
) {
2720 struct wpabuf
*owe_ie
;
2723 if (ssid
->owe_group
) {
2724 group
= ssid
->owe_group
;
2726 if (wpa_s
->last_owe_group
== 19)
2728 else if (wpa_s
->last_owe_group
== 20)
2731 group
= OWE_DH_GROUP
;
2733 wpa_s
->last_owe_group
= group
;
2734 wpa_printf(MSG_DEBUG
, "OWE: Try to use group %u", group
);
2735 owe_ie
= owe_build_assoc_req(wpa_s
->wpa
, group
);
2737 wpabuf_len(owe_ie
) <= max_wpa_ie_len
- wpa_ie_len
) {
2738 os_memcpy(wpa_ie
+ wpa_ie_len
,
2739 wpabuf_head(owe_ie
), wpabuf_len(owe_ie
));
2740 wpa_ie_len
+= wpabuf_len(owe_ie
);
2741 wpabuf_free(owe_ie
);
2744 #endif /* CONFIG_OWE */
2746 #ifdef CONFIG_IEEE80211R
2748 * Add MDIE under these conditions: the network profile allows FT,
2749 * the AP supports FT, and the mobility domain ID matches.
2751 if (wpa_key_mgmt_ft(wpa_sm_get_key_mgmt(wpa_s
->wpa
))) {
2752 const u8
*mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
2754 if (mdie
&& mdie
[1] >= MOBILITY_DOMAIN_ID_LEN
) {
2756 const u8
*md
= mdie
+ 2;
2757 const u8
*wpa_md
= wpa_sm_get_ft_md(wpa_s
->wpa
);
2759 if (os_memcmp(md
, wpa_md
,
2760 MOBILITY_DOMAIN_ID_LEN
) == 0) {
2761 /* Add mobility domain IE */
2762 len
= wpa_ft_add_mdie(
2763 wpa_s
->wpa
, wpa_ie
+ wpa_ie_len
,
2764 max_wpa_ie_len
- wpa_ie_len
, mdie
);
2768 if (len
> 0 && wpa_s
->sme
.ft_used
&&
2769 wpa_sm_has_ptk(wpa_s
->wpa
)) {
2770 wpa_dbg(wpa_s
, MSG_DEBUG
,
2771 "SME: Trying to use FT over-the-air");
2772 algs
|= WPA_AUTH_ALG_FT
;
2774 #endif /* CONFIG_SME */
2777 #endif /* CONFIG_IEEE80211R */
2779 params
->wpa_ie
= wpa_ie
;
2780 params
->wpa_ie_len
= wpa_ie_len
;
2781 params
->auth_alg
= algs
;
2783 *mask
|= WPA_DRV_UPDATE_ASSOC_IES
| WPA_DRV_UPDATE_AUTH_TYPE
;
2789 #if defined(CONFIG_FILS) && defined(IEEE8021X_EAPOL)
2790 static void wpas_update_fils_connect_params(struct wpa_supplicant
*wpa_s
)
2792 struct wpa_driver_associate_params params
;
2793 enum wpa_drv_update_connect_params_mask mask
= 0;
2796 if (wpa_s
->auth_alg
!= WPA_AUTH_ALG_OPEN
)
2797 return; /* nothing to do */
2799 os_memset(¶ms
, 0, sizeof(params
));
2800 wpa_ie
= wpas_populate_assoc_ies(wpa_s
, wpa_s
->current_bss
,
2801 wpa_s
->current_ssid
, ¶ms
, &mask
);
2805 if (params
.auth_alg
!= WPA_AUTH_ALG_FILS
) {
2810 wpa_s
->auth_alg
= params
.auth_alg
;
2811 wpa_drv_update_connect_params(wpa_s
, ¶ms
, mask
);
2814 #endif /* CONFIG_FILS && IEEE8021X_EAPOL */
2817 static void wpas_start_assoc_cb(struct wpa_radio_work
*work
, int deinit
)
2819 struct wpa_connect_work
*cwork
= work
->ctx
;
2820 struct wpa_bss
*bss
= cwork
->bss
;
2821 struct wpa_ssid
*ssid
= cwork
->ssid
;
2822 struct wpa_supplicant
*wpa_s
= work
->wpa_s
;
2824 int use_crypt
, ret
, i
, bssid_changed
;
2825 unsigned int cipher_pairwise
, cipher_group
, cipher_group_mgmt
;
2826 struct wpa_driver_associate_params params
;
2827 int wep_keys_set
= 0;
2828 int assoc_failed
= 0;
2829 struct wpa_ssid
*old_ssid
;
2830 u8 prev_bssid
[ETH_ALEN
];
2831 #ifdef CONFIG_HT_OVERRIDES
2832 struct ieee80211_ht_capabilities htcaps
;
2833 struct ieee80211_ht_capabilities htcaps_mask
;
2834 #endif /* CONFIG_HT_OVERRIDES */
2835 #ifdef CONFIG_VHT_OVERRIDES
2836 struct ieee80211_vht_capabilities vhtcaps
;
2837 struct ieee80211_vht_capabilities vhtcaps_mask
;
2838 #endif /* CONFIG_VHT_OVERRIDES */
2841 if (work
->started
) {
2842 wpa_s
->connect_work
= NULL
;
2844 /* cancel possible auth. timeout */
2845 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
,
2848 wpas_connect_work_free(cwork
);
2852 wpa_s
->connect_work
= work
;
2854 if (cwork
->bss_removed
|| !wpas_valid_bss_ssid(wpa_s
, bss
, ssid
) ||
2855 wpas_network_disabled(wpa_s
, ssid
)) {
2856 wpa_dbg(wpa_s
, MSG_DEBUG
, "BSS/SSID entry for association not valid anymore - drop connection attempt");
2857 wpas_connect_work_done(wpa_s
);
2861 os_memcpy(prev_bssid
, wpa_s
->bssid
, ETH_ALEN
);
2862 os_memset(¶ms
, 0, sizeof(params
));
2863 wpa_s
->reassociate
= 0;
2864 wpa_s
->eap_expected_failure
= 0;
2866 (!wpas_driver_bss_selection(wpa_s
) || wpas_wps_searching(wpa_s
))) {
2867 #ifdef CONFIG_IEEE80211R
2868 const u8
*ie
, *md
= NULL
;
2869 #endif /* CONFIG_IEEE80211R */
2870 wpa_msg(wpa_s
, MSG_INFO
, "Trying to associate with " MACSTR
2871 " (SSID='%s' freq=%d MHz)", MAC2STR(bss
->bssid
),
2872 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
), bss
->freq
);
2873 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
2874 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
2875 os_memcpy(wpa_s
->pending_bssid
, bss
->bssid
, ETH_ALEN
);
2877 wpas_notify_bssid_changed(wpa_s
);
2878 #ifdef CONFIG_IEEE80211R
2879 ie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
2880 if (ie
&& ie
[1] >= MOBILITY_DOMAIN_ID_LEN
)
2882 wpa_sm_set_ft_params(wpa_s
->wpa
, ie
, ie
? 2 + ie
[1] : 0);
2884 /* Prepare for the next transition */
2885 wpa_ft_prepare_auth_request(wpa_s
->wpa
, ie
);
2887 #endif /* CONFIG_IEEE80211R */
2889 } else if ((ssid
->ssid
== NULL
|| ssid
->ssid_len
== 0) &&
2890 wpa_s
->conf
->ap_scan
== 2 &&
2891 (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
2892 /* Use ap_scan==1 style network selection to find the network
2894 wpas_connect_work_done(wpa_s
);
2895 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
2896 wpa_s
->reassociate
= 1;
2897 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2899 #endif /* CONFIG_WPS */
2901 wpa_msg(wpa_s
, MSG_INFO
, "Trying to associate with SSID '%s'",
2902 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
2904 os_memcpy(wpa_s
->pending_bssid
, bss
->bssid
, ETH_ALEN
);
2906 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
2909 wpa_supplicant_cancel_sched_scan(wpa_s
);
2911 wpa_supplicant_cancel_scan(wpa_s
);
2913 /* Starting new association, so clear the possibly used WPA IE from the
2914 * previous association. */
2915 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
2917 wpa_ie
= wpas_populate_assoc_ies(wpa_s
, bss
, ssid
, ¶ms
, NULL
);
2919 wpas_connect_work_done(wpa_s
);
2923 wpa_clear_keys(wpa_s
, bss
? bss
->bssid
: NULL
);
2925 cipher_pairwise
= wpa_s
->pairwise_cipher
;
2926 cipher_group
= wpa_s
->group_cipher
;
2927 cipher_group_mgmt
= wpa_s
->mgmt_group_cipher
;
2928 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
2929 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
2930 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
)
2932 if (wpa_set_wep_keys(wpa_s
, ssid
)) {
2937 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
)
2940 #ifdef IEEE8021X_EAPOL
2941 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
2942 if ((ssid
->eapol_flags
&
2943 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
2944 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
)) == 0 &&
2948 /* Assume that dynamic WEP-104 keys will be used and
2949 * set cipher suites in order for drivers to expect
2951 cipher_pairwise
= cipher_group
= WPA_CIPHER_WEP104
;
2954 #endif /* IEEE8021X_EAPOL */
2956 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2957 /* Set the key before (and later after) association */
2958 wpa_supplicant_set_wpa_none_key(wpa_s
, ssid
);
2961 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATING
);
2963 params
.ssid
= bss
->ssid
;
2964 params
.ssid_len
= bss
->ssid_len
;
2965 if (!wpas_driver_bss_selection(wpa_s
) || ssid
->bssid_set
||
2966 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
2967 wpa_printf(MSG_DEBUG
, "Limit connection to BSSID "
2968 MACSTR
" freq=%u MHz based on scan results "
2969 "(bssid_set=%d wps=%d)",
2970 MAC2STR(bss
->bssid
), bss
->freq
,
2972 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
);
2973 params
.bssid
= bss
->bssid
;
2974 params
.freq
.freq
= bss
->freq
;
2976 params
.bssid_hint
= bss
->bssid
;
2977 params
.freq_hint
= bss
->freq
;
2978 params
.pbss
= bss_is_pbss(bss
);
2980 if (ssid
->bssid_hint_set
)
2981 params
.bssid_hint
= ssid
->bssid_hint
;
2983 params
.ssid
= ssid
->ssid
;
2984 params
.ssid_len
= ssid
->ssid_len
;
2985 params
.pbss
= (ssid
->pbss
!= 2) ? ssid
->pbss
: 0;
2988 if (ssid
->mode
== WPAS_MODE_IBSS
&& ssid
->bssid_set
&&
2989 wpa_s
->conf
->ap_scan
== 2) {
2990 params
.bssid
= ssid
->bssid
;
2991 params
.fixed_bssid
= 1;
2994 /* Initial frequency for IBSS/mesh */
2995 if ((ssid
->mode
== WPAS_MODE_IBSS
|| ssid
->mode
== WPAS_MODE_MESH
) &&
2996 ssid
->frequency
> 0 && params
.freq
.freq
== 0)
2997 ibss_mesh_setup_freq(wpa_s
, ssid
, ¶ms
.freq
);
2999 if (ssid
->mode
== WPAS_MODE_IBSS
) {
3000 params
.fixed_freq
= ssid
->fixed_freq
;
3001 if (ssid
->beacon_int
)
3002 params
.beacon_int
= ssid
->beacon_int
;
3004 params
.beacon_int
= wpa_s
->conf
->beacon_int
;
3007 params
.pairwise_suite
= cipher_pairwise
;
3008 params
.group_suite
= cipher_group
;
3009 params
.mgmt_group_suite
= cipher_group_mgmt
;
3010 params
.key_mgmt_suite
= wpa_s
->key_mgmt
;
3011 params
.wpa_proto
= wpa_s
->wpa_proto
;
3012 wpa_s
->auth_alg
= params
.auth_alg
;
3013 params
.mode
= ssid
->mode
;
3014 params
.bg_scan_period
= ssid
->bg_scan_period
;
3015 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
3016 if (ssid
->wep_key_len
[i
])
3017 params
.wep_key
[i
] = ssid
->wep_key
[i
];
3018 params
.wep_key_len
[i
] = ssid
->wep_key_len
[i
];
3020 params
.wep_tx_keyidx
= ssid
->wep_tx_keyidx
;
3022 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
3023 (params
.key_mgmt_suite
== WPA_KEY_MGMT_PSK
||
3024 params
.key_mgmt_suite
== WPA_KEY_MGMT_FT_PSK
)) {
3025 params
.passphrase
= ssid
->passphrase
;
3027 params
.psk
= ssid
->psk
;
3030 if (wpa_s
->conf
->key_mgmt_offload
) {
3031 if (params
.key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X
||
3032 params
.key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SHA256
||
3033 params
.key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SUITE_B
||
3034 params
.key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
)
3035 params
.req_key_mgmt_offload
=
3036 ssid
->proactive_key_caching
< 0 ?
3037 wpa_s
->conf
->okc
: ssid
->proactive_key_caching
;
3039 params
.req_key_mgmt_offload
= 1;
3041 if ((params
.key_mgmt_suite
== WPA_KEY_MGMT_PSK
||
3042 params
.key_mgmt_suite
== WPA_KEY_MGMT_PSK_SHA256
||
3043 params
.key_mgmt_suite
== WPA_KEY_MGMT_FT_PSK
) &&
3045 params
.psk
= ssid
->psk
;
3048 params
.drop_unencrypted
= use_crypt
;
3050 #ifdef CONFIG_IEEE80211W
3051 params
.mgmt_frame_protection
= wpas_get_ssid_pmf(wpa_s
, ssid
);
3052 if (params
.mgmt_frame_protection
!= NO_MGMT_FRAME_PROTECTION
&& bss
) {
3053 const u8
*rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
3054 struct wpa_ie_data ie
;
3055 if (rsn
&& wpa_parse_wpa_ie(rsn
, 2 + rsn
[1], &ie
) == 0 &&
3057 (WPA_CAPABILITY_MFPC
| WPA_CAPABILITY_MFPR
)) {
3058 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Selected AP supports "
3059 "MFP: require MFP");
3060 params
.mgmt_frame_protection
=
3061 MGMT_FRAME_PROTECTION_REQUIRED
;
3064 #endif /* CONFIG_IEEE80211W */
3066 params
.p2p
= ssid
->p2p_group
;
3068 if (wpa_s
->p2pdev
->set_sta_uapsd
)
3069 params
.uapsd
= wpa_s
->p2pdev
->sta_uapsd
;
3073 #ifdef CONFIG_HT_OVERRIDES
3074 os_memset(&htcaps
, 0, sizeof(htcaps
));
3075 os_memset(&htcaps_mask
, 0, sizeof(htcaps_mask
));
3076 params
.htcaps
= (u8
*) &htcaps
;
3077 params
.htcaps_mask
= (u8
*) &htcaps_mask
;
3078 wpa_supplicant_apply_ht_overrides(wpa_s
, ssid
, ¶ms
);
3079 #endif /* CONFIG_HT_OVERRIDES */
3080 #ifdef CONFIG_VHT_OVERRIDES
3081 os_memset(&vhtcaps
, 0, sizeof(vhtcaps
));
3082 os_memset(&vhtcaps_mask
, 0, sizeof(vhtcaps_mask
));
3083 params
.vhtcaps
= &vhtcaps
;
3084 params
.vhtcaps_mask
= &vhtcaps_mask
;
3085 wpa_supplicant_apply_vht_overrides(wpa_s
, ssid
, ¶ms
);
3086 #endif /* CONFIG_VHT_OVERRIDES */
3090 * If multi-channel concurrency is not supported, check for any
3091 * frequency conflict. In case of any frequency conflict, remove the
3092 * least prioritized connection.
3094 if (wpa_s
->num_multichan_concurrent
< 2) {
3096 num
= get_shared_radio_freqs(wpa_s
, &freq
, 1);
3097 if (num
> 0 && freq
> 0 && freq
!= params
.freq
.freq
) {
3098 wpa_printf(MSG_DEBUG
,
3099 "Assoc conflicting freq found (%d != %d)",
3100 freq
, params
.freq
.freq
);
3101 if (wpas_p2p_handle_frequency_conflicts(
3102 wpa_s
, params
.freq
.freq
, ssid
) < 0) {
3103 wpas_connect_work_done(wpa_s
);
3109 #endif /* CONFIG_P2P */
3111 if (wpa_s
->reassoc_same_ess
&& !is_zero_ether_addr(prev_bssid
) &&
3112 wpa_s
->current_ssid
)
3113 params
.prev_bssid
= prev_bssid
;
3115 ret
= wpa_drv_associate(wpa_s
, ¶ms
);
3118 wpa_msg(wpa_s
, MSG_INFO
, "Association request to the driver "
3120 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SANE_ERROR_CODES
) {
3122 * The driver is known to mean what is saying, so we
3123 * can stop right here; the association will not
3126 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
3127 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
3128 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
3131 /* try to continue anyway; new association will be tried again
3136 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
3137 /* Set the key after the association just in case association
3138 * cleared the previously configured key. */
3139 wpa_supplicant_set_wpa_none_key(wpa_s
, ssid
);
3140 /* No need to timeout authentication since there is no key
3142 wpa_supplicant_cancel_auth_timeout(wpa_s
);
3143 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
3144 #ifdef CONFIG_IBSS_RSN
3145 } else if (ssid
->mode
== WPAS_MODE_IBSS
&&
3146 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
3147 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
) {
3149 * RSN IBSS authentication is per-STA and we can disable the
3150 * per-BSSID authentication.
3152 wpa_supplicant_cancel_auth_timeout(wpa_s
);
3153 #endif /* CONFIG_IBSS_RSN */
3155 /* Timeout for IEEE 802.11 authentication and association */
3159 /* give IBSS a bit more time */
3160 timeout
= ssid
->mode
== WPAS_MODE_IBSS
? 10 : 5;
3161 } else if (wpa_s
->conf
->ap_scan
== 1) {
3162 /* give IBSS a bit more time */
3163 timeout
= ssid
->mode
== WPAS_MODE_IBSS
? 20 : 10;
3165 wpa_supplicant_req_auth_timeout(wpa_s
, timeout
, 0);
3169 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC
)) {
3170 /* Set static WEP keys again */
3171 wpa_set_wep_keys(wpa_s
, ssid
);
3174 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
) {
3176 * Do not allow EAP session resumption between different
3177 * network configurations.
3179 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3181 old_ssid
= wpa_s
->current_ssid
;
3182 wpa_s
->current_ssid
= ssid
;
3184 if (!wpas_driver_bss_selection(wpa_s
) || ssid
->bssid_set
) {
3185 wpa_s
->current_bss
= bss
;
3187 hs20_configure_frame_filters(wpa_s
);
3188 #endif /* CONFIG_HS20 */
3191 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
3192 wpa_supplicant_initiate_eapol(wpa_s
);
3193 if (old_ssid
!= wpa_s
->current_ssid
)
3194 wpas_notify_network_changed(wpa_s
);
3198 static void wpa_supplicant_clear_connection(struct wpa_supplicant
*wpa_s
,
3201 struct wpa_ssid
*old_ssid
;
3203 wpas_connect_work_done(wpa_s
);
3204 wpa_clear_keys(wpa_s
, addr
);
3205 old_ssid
= wpa_s
->current_ssid
;
3206 wpa_supplicant_mark_disassoc(wpa_s
);
3207 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
3208 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
3209 if (old_ssid
!= wpa_s
->current_ssid
)
3210 wpas_notify_network_changed(wpa_s
);
3211 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
3216 * wpa_supplicant_deauthenticate - Deauthenticate the current connection
3217 * @wpa_s: Pointer to wpa_supplicant data
3218 * @reason_code: IEEE 802.11 reason code for the deauthenticate frame
3220 * This function is used to request %wpa_supplicant to deauthenticate from the
3223 void wpa_supplicant_deauthenticate(struct wpa_supplicant
*wpa_s
,
3227 union wpa_event_data event
;
3230 wpa_dbg(wpa_s
, MSG_DEBUG
, "Request to deauthenticate - bssid=" MACSTR
3231 " pending_bssid=" MACSTR
" reason=%d state=%s",
3232 MAC2STR(wpa_s
->bssid
), MAC2STR(wpa_s
->pending_bssid
),
3233 reason_code
, wpa_supplicant_state_txt(wpa_s
->wpa_state
));
3235 if (!is_zero_ether_addr(wpa_s
->pending_bssid
) &&
3236 (wpa_s
->wpa_state
== WPA_AUTHENTICATING
||
3237 wpa_s
->wpa_state
== WPA_ASSOCIATING
))
3238 addr
= wpa_s
->pending_bssid
;
3239 else if (!is_zero_ether_addr(wpa_s
->bssid
))
3240 addr
= wpa_s
->bssid
;
3241 else if (wpa_s
->wpa_state
== WPA_ASSOCIATING
) {
3243 * When using driver-based BSS selection, we may not know the
3244 * BSSID with which we are currently trying to associate. We
3245 * need to notify the driver of this disconnection even in such
3246 * a case, so use the all zeros address here.
3248 addr
= wpa_s
->bssid
;
3253 wpa_tdls_teardown_peers(wpa_s
->wpa
);
3254 #endif /* CONFIG_TDLS */
3258 struct mesh_conf
*mconf
;
3260 mconf
= wpa_s
->ifmsh
->mconf
;
3261 wpa_msg(wpa_s
, MSG_INFO
, MESH_GROUP_REMOVED
"%s",
3263 wpas_notify_mesh_group_removed(wpa_s
, mconf
->meshid
,
3264 mconf
->meshid_len
, reason_code
);
3265 wpa_supplicant_leave_mesh(wpa_s
);
3267 #endif /* CONFIG_MESH */
3270 wpa_drv_deauthenticate(wpa_s
, addr
, reason_code
);
3271 os_memset(&event
, 0, sizeof(event
));
3272 event
.deauth_info
.reason_code
= (u16
) reason_code
;
3273 event
.deauth_info
.locally_generated
= 1;
3274 wpa_supplicant_event(wpa_s
, EVENT_DEAUTH
, &event
);
3279 wpa_supplicant_clear_connection(wpa_s
, addr
);
3282 static void wpa_supplicant_enable_one_network(struct wpa_supplicant
*wpa_s
,
3283 struct wpa_ssid
*ssid
)
3285 if (!ssid
|| !ssid
->disabled
|| ssid
->disabled
== 2)
3289 wpas_clear_temp_disabled(wpa_s
, ssid
, 1);
3290 wpas_notify_network_enabled_changed(wpa_s
, ssid
);
3293 * Try to reassociate since there is no current configuration and a new
3294 * network was made available.
3296 if (!wpa_s
->current_ssid
&& !wpa_s
->disconnected
)
3297 wpa_s
->reassociate
= 1;
3302 * wpa_supplicant_add_network - Add a new network
3303 * @wpa_s: wpa_supplicant structure for a network interface
3304 * Returns: The new network configuration or %NULL if operation failed
3306 * This function performs the following operations:
3307 * 1. Adds a new network.
3308 * 2. Send network addition notification.
3309 * 3. Marks the network disabled.
3310 * 4. Set network default parameters.
3312 struct wpa_ssid
* wpa_supplicant_add_network(struct wpa_supplicant
*wpa_s
)
3314 struct wpa_ssid
*ssid
;
3316 ssid
= wpa_config_add_network(wpa_s
->conf
);
3319 wpas_notify_network_added(wpa_s
, ssid
);
3321 wpa_config_set_network_defaults(ssid
);
3328 * wpa_supplicant_remove_network - Remove a configured network based on id
3329 * @wpa_s: wpa_supplicant structure for a network interface
3330 * @id: Unique network id to search for
3331 * Returns: 0 on success, or -1 if the network was not found, -2 if the network
3332 * could not be removed
3334 * This function performs the following operations:
3335 * 1. Removes the network.
3336 * 2. Send network removal notification.
3337 * 3. Update internal state machines.
3338 * 4. Stop any running sched scans.
3340 int wpa_supplicant_remove_network(struct wpa_supplicant
*wpa_s
, int id
)
3342 struct wpa_ssid
*ssid
;
3345 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3348 wpas_notify_network_removed(wpa_s
, ssid
);
3350 if (wpa_s
->last_ssid
== ssid
)
3351 wpa_s
->last_ssid
= NULL
;
3353 if (ssid
== wpa_s
->current_ssid
|| !wpa_s
->current_ssid
) {
3355 wpa_s
->sme
.prev_bssid_set
= 0;
3356 #endif /* CONFIG_SME */
3358 * Invalidate the EAP session cache if the current or
3359 * previously used network is removed.
3361 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3364 if (ssid
== wpa_s
->current_ssid
) {
3365 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
3366 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
3368 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
3369 wpa_s
->own_disconnect_req
= 1;
3370 wpa_supplicant_deauthenticate(wpa_s
,
3371 WLAN_REASON_DEAUTH_LEAVING
);
3374 was_disabled
= ssid
->disabled
;
3376 if (wpa_config_remove_network(wpa_s
->conf
, id
) < 0)
3379 if (!was_disabled
&& wpa_s
->sched_scanning
) {
3380 wpa_printf(MSG_DEBUG
,
3381 "Stop ongoing sched_scan to remove network from filters");
3382 wpa_supplicant_cancel_sched_scan(wpa_s
);
3383 wpa_supplicant_req_scan(wpa_s
, 0, 0);
3391 * wpa_supplicant_enable_network - Mark a configured network as enabled
3392 * @wpa_s: wpa_supplicant structure for a network interface
3393 * @ssid: wpa_ssid structure for a configured network or %NULL
3395 * Enables the specified network or all networks if no network specified.
3397 void wpa_supplicant_enable_network(struct wpa_supplicant
*wpa_s
,
3398 struct wpa_ssid
*ssid
)
3401 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
)
3402 wpa_supplicant_enable_one_network(wpa_s
, ssid
);
3404 wpa_supplicant_enable_one_network(wpa_s
, ssid
);
3406 if (wpa_s
->reassociate
&& !wpa_s
->disconnected
&&
3407 (!wpa_s
->current_ssid
||
3408 wpa_s
->wpa_state
== WPA_DISCONNECTED
||
3409 wpa_s
->wpa_state
== WPA_SCANNING
)) {
3410 if (wpa_s
->sched_scanning
) {
3411 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to add "
3412 "new network to scan filters");
3413 wpa_supplicant_cancel_sched_scan(wpa_s
);
3416 if (wpa_supplicant_fast_associate(wpa_s
) != 1) {
3417 wpa_s
->scan_req
= NORMAL_SCAN_REQ
;
3418 wpa_supplicant_req_scan(wpa_s
, 0, 0);
3425 * wpa_supplicant_disable_network - Mark a configured network as disabled
3426 * @wpa_s: wpa_supplicant structure for a network interface
3427 * @ssid: wpa_ssid structure for a configured network or %NULL
3429 * Disables the specified network or all networks if no network specified.
3431 void wpa_supplicant_disable_network(struct wpa_supplicant
*wpa_s
,
3432 struct wpa_ssid
*ssid
)
3434 struct wpa_ssid
*other_ssid
;
3438 if (wpa_s
->sched_scanning
)
3439 wpa_supplicant_cancel_sched_scan(wpa_s
);
3441 for (other_ssid
= wpa_s
->conf
->ssid
; other_ssid
;
3442 other_ssid
= other_ssid
->next
) {
3443 was_disabled
= other_ssid
->disabled
;
3444 if (was_disabled
== 2)
3445 continue; /* do not change persistent P2P group
3448 other_ssid
->disabled
= 1;
3450 if (was_disabled
!= other_ssid
->disabled
)
3451 wpas_notify_network_enabled_changed(
3454 if (wpa_s
->current_ssid
) {
3455 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
3456 wpa_s
->own_disconnect_req
= 1;
3457 wpa_supplicant_deauthenticate(
3458 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3460 } else if (ssid
->disabled
!= 2) {
3461 if (ssid
== wpa_s
->current_ssid
) {
3462 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
3463 wpa_s
->own_disconnect_req
= 1;
3464 wpa_supplicant_deauthenticate(
3465 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3468 was_disabled
= ssid
->disabled
;
3472 if (was_disabled
!= ssid
->disabled
) {
3473 wpas_notify_network_enabled_changed(wpa_s
, ssid
);
3474 if (wpa_s
->sched_scanning
) {
3475 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan "
3476 "to remove network from filters");
3477 wpa_supplicant_cancel_sched_scan(wpa_s
);
3478 wpa_supplicant_req_scan(wpa_s
, 0, 0);
3486 * wpa_supplicant_select_network - Attempt association with a network
3487 * @wpa_s: wpa_supplicant structure for a network interface
3488 * @ssid: wpa_ssid structure for a configured network or %NULL for any network
3490 void wpa_supplicant_select_network(struct wpa_supplicant
*wpa_s
,
3491 struct wpa_ssid
*ssid
)
3494 struct wpa_ssid
*other_ssid
;
3495 int disconnected
= 0;
3497 if (ssid
&& ssid
!= wpa_s
->current_ssid
&& wpa_s
->current_ssid
) {
3498 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
3499 wpa_s
->own_disconnect_req
= 1;
3500 wpa_supplicant_deauthenticate(
3501 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3506 wpas_clear_temp_disabled(wpa_s
, ssid
, 1);
3509 * Mark all other networks disabled or mark all networks enabled if no
3510 * network specified.
3512 for (other_ssid
= wpa_s
->conf
->ssid
; other_ssid
;
3513 other_ssid
= other_ssid
->next
) {
3514 int was_disabled
= other_ssid
->disabled
;
3515 if (was_disabled
== 2)
3516 continue; /* do not change persistent P2P group data */
3518 other_ssid
->disabled
= ssid
? (ssid
->id
!= other_ssid
->id
) : 0;
3519 if (was_disabled
&& !other_ssid
->disabled
)
3520 wpas_clear_temp_disabled(wpa_s
, other_ssid
, 0);
3522 if (was_disabled
!= other_ssid
->disabled
)
3523 wpas_notify_network_enabled_changed(wpa_s
, other_ssid
);
3526 if (ssid
&& ssid
== wpa_s
->current_ssid
&& wpa_s
->current_ssid
&&
3527 wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
3528 /* We are already associated with the selected network */
3529 wpa_printf(MSG_DEBUG
, "Already associated with the "
3530 "selected network - do nothing");
3535 wpa_s
->current_ssid
= ssid
;
3536 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
3537 wpa_s
->connect_without_scan
=
3538 (ssid
->mode
== WPAS_MODE_MESH
) ? ssid
: NULL
;
3541 * Don't optimize next scan freqs since a new ESS has been
3544 os_free(wpa_s
->next_scan_freqs
);
3545 wpa_s
->next_scan_freqs
= NULL
;
3547 wpa_s
->connect_without_scan
= NULL
;
3550 wpa_s
->disconnected
= 0;
3551 wpa_s
->reassociate
= 1;
3552 wpa_s
->last_owe_group
= 0;
3554 if (wpa_s
->connect_without_scan
||
3555 wpa_supplicant_fast_associate(wpa_s
) != 1) {
3556 wpa_s
->scan_req
= NORMAL_SCAN_REQ
;
3557 wpas_scan_reset_sched_scan(wpa_s
);
3558 wpa_supplicant_req_scan(wpa_s
, 0, disconnected
? 100000 : 0);
3562 wpas_notify_network_selected(wpa_s
, ssid
);
3567 * wpas_set_pkcs11_engine_and_module_path - Set PKCS #11 engine and module path
3568 * @wpa_s: wpa_supplicant structure for a network interface
3569 * @pkcs11_engine_path: PKCS #11 engine path or NULL
3570 * @pkcs11_module_path: PKCS #11 module path or NULL
3571 * Returns: 0 on success; -1 on failure
3573 * Sets the PKCS #11 engine and module path. Both have to be NULL or a valid
3574 * path. If resetting the EAPOL state machine with the new PKCS #11 engine and
3575 * module path fails the paths will be reset to the default value (NULL).
3577 int wpas_set_pkcs11_engine_and_module_path(struct wpa_supplicant
*wpa_s
,
3578 const char *pkcs11_engine_path
,
3579 const char *pkcs11_module_path
)
3581 char *pkcs11_engine_path_copy
= NULL
;
3582 char *pkcs11_module_path_copy
= NULL
;
3584 if (pkcs11_engine_path
!= NULL
) {
3585 pkcs11_engine_path_copy
= os_strdup(pkcs11_engine_path
);
3586 if (pkcs11_engine_path_copy
== NULL
)
3589 if (pkcs11_module_path
!= NULL
) {
3590 pkcs11_module_path_copy
= os_strdup(pkcs11_module_path
);
3591 if (pkcs11_module_path_copy
== NULL
) {
3592 os_free(pkcs11_engine_path_copy
);
3597 os_free(wpa_s
->conf
->pkcs11_engine_path
);
3598 os_free(wpa_s
->conf
->pkcs11_module_path
);
3599 wpa_s
->conf
->pkcs11_engine_path
= pkcs11_engine_path_copy
;
3600 wpa_s
->conf
->pkcs11_module_path
= pkcs11_module_path_copy
;
3602 wpa_sm_set_eapol(wpa_s
->wpa
, NULL
);
3603 eapol_sm_deinit(wpa_s
->eapol
);
3604 wpa_s
->eapol
= NULL
;
3605 if (wpa_supplicant_init_eapol(wpa_s
)) {
3606 /* Error -> Reset paths to the default value (NULL) once. */
3607 if (pkcs11_engine_path
!= NULL
&& pkcs11_module_path
!= NULL
)
3608 wpas_set_pkcs11_engine_and_module_path(wpa_s
, NULL
,
3613 wpa_sm_set_eapol(wpa_s
->wpa
, wpa_s
->eapol
);
3620 * wpa_supplicant_set_ap_scan - Set AP scan mode for interface
3621 * @wpa_s: wpa_supplicant structure for a network interface
3622 * @ap_scan: AP scan mode
3623 * Returns: 0 if succeed or -1 if ap_scan has an invalid value
3626 int wpa_supplicant_set_ap_scan(struct wpa_supplicant
*wpa_s
, int ap_scan
)
3631 if (ap_scan
< 0 || ap_scan
> 2)
3634 if (ap_scan
== 2 && os_strcmp(wpa_s
->driver
->name
, "nl80211") == 0) {
3635 wpa_printf(MSG_INFO
,
3636 "Note: nl80211 driver interface is not designed to be used with ap_scan=2; this can result in connection failures");
3640 if (ap_scan
== 2 && ap_scan
!= wpa_s
->conf
->ap_scan
&&
3641 wpa_s
->wpa_state
>= WPA_ASSOCIATING
&&
3642 wpa_s
->wpa_state
< WPA_COMPLETED
) {
3643 wpa_printf(MSG_ERROR
, "ap_scan = %d (%d) rejected while "
3644 "associating", wpa_s
->conf
->ap_scan
, ap_scan
);
3647 #endif /* ANDROID */
3649 old_ap_scan
= wpa_s
->conf
->ap_scan
;
3650 wpa_s
->conf
->ap_scan
= ap_scan
;
3652 if (old_ap_scan
!= wpa_s
->conf
->ap_scan
)
3653 wpas_notify_ap_scan_changed(wpa_s
);
3660 * wpa_supplicant_set_bss_expiration_age - Set BSS entry expiration age
3661 * @wpa_s: wpa_supplicant structure for a network interface
3662 * @expire_age: Expiration age in seconds
3663 * Returns: 0 if succeed or -1 if expire_age has an invalid value
3666 int wpa_supplicant_set_bss_expiration_age(struct wpa_supplicant
*wpa_s
,
3667 unsigned int bss_expire_age
)
3669 if (bss_expire_age
< 10) {
3670 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid bss expiration age %u",
3674 wpa_msg(wpa_s
, MSG_DEBUG
, "Setting bss expiration age: %d sec",
3676 wpa_s
->conf
->bss_expiration_age
= bss_expire_age
;
3683 * wpa_supplicant_set_bss_expiration_count - Set BSS entry expiration scan count
3684 * @wpa_s: wpa_supplicant structure for a network interface
3685 * @expire_count: number of scans after which an unseen BSS is reclaimed
3686 * Returns: 0 if succeed or -1 if expire_count has an invalid value
3689 int wpa_supplicant_set_bss_expiration_count(struct wpa_supplicant
*wpa_s
,
3690 unsigned int bss_expire_count
)
3692 if (bss_expire_count
< 1) {
3693 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid bss expiration count %u",
3697 wpa_msg(wpa_s
, MSG_DEBUG
, "Setting bss expiration scan count: %u",
3699 wpa_s
->conf
->bss_expiration_scan_count
= bss_expire_count
;
3706 * wpa_supplicant_set_scan_interval - Set scan interval
3707 * @wpa_s: wpa_supplicant structure for a network interface
3708 * @scan_interval: scan interval in seconds
3709 * Returns: 0 if succeed or -1 if scan_interval has an invalid value
3712 int wpa_supplicant_set_scan_interval(struct wpa_supplicant
*wpa_s
,
3715 if (scan_interval
< 0) {
3716 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid scan interval %d",
3720 wpa_msg(wpa_s
, MSG_DEBUG
, "Setting scan interval: %d sec",
3722 wpa_supplicant_update_scan_int(wpa_s
, scan_interval
);
3729 * wpa_supplicant_set_debug_params - Set global debug params
3730 * @global: wpa_global structure
3731 * @debug_level: debug level
3732 * @debug_timestamp: determines if show timestamp in debug data
3733 * @debug_show_keys: determines if show keys in debug data
3734 * Returns: 0 if succeed or -1 if debug_level has wrong value
3736 int wpa_supplicant_set_debug_params(struct wpa_global
*global
, int debug_level
,
3737 int debug_timestamp
, int debug_show_keys
)
3740 int old_level
, old_timestamp
, old_show_keys
;
3742 /* check for allowed debuglevels */
3743 if (debug_level
!= MSG_EXCESSIVE
&&
3744 debug_level
!= MSG_MSGDUMP
&&
3745 debug_level
!= MSG_DEBUG
&&
3746 debug_level
!= MSG_INFO
&&
3747 debug_level
!= MSG_WARNING
&&
3748 debug_level
!= MSG_ERROR
)
3751 old_level
= wpa_debug_level
;
3752 old_timestamp
= wpa_debug_timestamp
;
3753 old_show_keys
= wpa_debug_show_keys
;
3755 wpa_debug_level
= debug_level
;
3756 wpa_debug_timestamp
= debug_timestamp
? 1 : 0;
3757 wpa_debug_show_keys
= debug_show_keys
? 1 : 0;
3759 if (wpa_debug_level
!= old_level
)
3760 wpas_notify_debug_level_changed(global
);
3761 if (wpa_debug_timestamp
!= old_timestamp
)
3762 wpas_notify_debug_timestamp_changed(global
);
3763 if (wpa_debug_show_keys
!= old_show_keys
)
3764 wpas_notify_debug_show_keys_changed(global
);
3771 static int owe_trans_ssid_match(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
3772 const u8
*entry_ssid
, size_t entry_ssid_len
)
3774 const u8
*owe
, *pos
, *end
;
3776 struct wpa_bss
*bss
;
3778 /* Check network profile SSID aganst the SSID in the
3779 * OWE Transition Mode element. */
3781 bss
= wpa_bss_get_bssid_latest(wpa_s
, bssid
);
3785 owe
= wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
);
3790 end
= owe
+ 2 + owe
[1];
3792 if (end
- pos
< ETH_ALEN
+ 1)
3796 if (end
- pos
< ssid_len
|| ssid_len
> SSID_MAX_LEN
)
3799 return entry_ssid_len
== ssid_len
&&
3800 os_memcmp(pos
, entry_ssid
, ssid_len
) == 0;
3802 #endif /* CONFIG_OWE */
3806 * wpa_supplicant_get_ssid - Get a pointer to the current network structure
3807 * @wpa_s: Pointer to wpa_supplicant data
3808 * Returns: A pointer to the current network structure or %NULL on failure
3810 struct wpa_ssid
* wpa_supplicant_get_ssid(struct wpa_supplicant
*wpa_s
)
3812 struct wpa_ssid
*entry
;
3813 u8 ssid
[SSID_MAX_LEN
];
3819 res
= wpa_drv_get_ssid(wpa_s
, ssid
);
3821 wpa_msg(wpa_s
, MSG_WARNING
, "Could not read SSID from "
3827 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0) {
3828 wpa_msg(wpa_s
, MSG_WARNING
, "Could not read BSSID from "
3833 wired
= wpa_s
->conf
->ap_scan
== 0 &&
3834 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
);
3836 entry
= wpa_s
->conf
->ssid
;
3838 if (!wpas_network_disabled(wpa_s
, entry
) &&
3839 ((ssid_len
== entry
->ssid_len
&&
3840 os_memcmp(ssid
, entry
->ssid
, ssid_len
) == 0) || wired
) &&
3841 (!entry
->bssid_set
||
3842 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0))
3845 if (!wpas_network_disabled(wpa_s
, entry
) &&
3846 (entry
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
3847 (entry
->ssid
== NULL
|| entry
->ssid_len
== 0) &&
3848 (!entry
->bssid_set
||
3849 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0))
3851 #endif /* CONFIG_WPS */
3854 if (!wpas_network_disabled(wpa_s
, entry
) &&
3855 owe_trans_ssid_match(wpa_s
, bssid
, entry
->ssid
,
3857 (!entry
->bssid_set
||
3858 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0))
3860 #endif /* CONFIG_OWE */
3862 if (!wpas_network_disabled(wpa_s
, entry
) && entry
->bssid_set
&&
3863 entry
->ssid_len
== 0 &&
3864 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0)
3867 entry
= entry
->next
;
3874 static int select_driver(struct wpa_supplicant
*wpa_s
, int i
)
3876 struct wpa_global
*global
= wpa_s
->global
;
3878 if (wpa_drivers
[i
]->global_init
&& global
->drv_priv
[i
] == NULL
) {
3879 global
->drv_priv
[i
] = wpa_drivers
[i
]->global_init(global
);
3880 if (global
->drv_priv
[i
] == NULL
) {
3881 wpa_printf(MSG_ERROR
, "Failed to initialize driver "
3882 "'%s'", wpa_drivers
[i
]->name
);
3887 wpa_s
->driver
= wpa_drivers
[i
];
3888 wpa_s
->global_drv_priv
= global
->drv_priv
[i
];
3894 static int wpa_supplicant_set_driver(struct wpa_supplicant
*wpa_s
,
3899 const char *pos
, *driver
= name
;
3904 if (wpa_drivers
[0] == NULL
) {
3905 wpa_msg(wpa_s
, MSG_ERROR
, "No driver interfaces build into "
3911 /* default to first driver in the list */
3912 return select_driver(wpa_s
, 0);
3916 pos
= os_strchr(driver
, ',');
3920 len
= os_strlen(driver
);
3922 for (i
= 0; wpa_drivers
[i
]; i
++) {
3923 if (os_strlen(wpa_drivers
[i
]->name
) == len
&&
3924 os_strncmp(driver
, wpa_drivers
[i
]->name
, len
) ==
3926 /* First driver that succeeds wins */
3927 if (select_driver(wpa_s
, i
) == 0)
3935 wpa_msg(wpa_s
, MSG_ERROR
, "Unsupported driver '%s'", name
);
3941 * wpa_supplicant_rx_eapol - Deliver a received EAPOL frame to wpa_supplicant
3942 * @ctx: Context pointer (wpa_s); this is the ctx variable registered
3943 * with struct wpa_driver_ops::init()
3944 * @src_addr: Source address of the EAPOL frame
3945 * @buf: EAPOL data starting from the EAPOL header (i.e., no Ethernet header)
3946 * @len: Length of the EAPOL data
3948 * This function is called for each received EAPOL frame. Most driver
3949 * interfaces rely on more generic OS mechanism for receiving frames through
3950 * l2_packet, but if such a mechanism is not available, the driver wrapper may
3951 * take care of received EAPOL frames and deliver them to the core supplicant
3952 * code by calling this function.
3954 void wpa_supplicant_rx_eapol(void *ctx
, const u8
*src_addr
,
3955 const u8
*buf
, size_t len
)
3957 struct wpa_supplicant
*wpa_s
= ctx
;
3959 wpa_dbg(wpa_s
, MSG_DEBUG
, "RX EAPOL from " MACSTR
, MAC2STR(src_addr
));
3960 wpa_hexdump(MSG_MSGDUMP
, "RX EAPOL", buf
, len
);
3962 #ifdef CONFIG_TESTING_OPTIONS
3963 if (wpa_s
->ignore_auth_resp
) {
3964 wpa_printf(MSG_INFO
, "RX EAPOL - ignore_auth_resp active!");
3967 #endif /* CONFIG_TESTING_OPTIONS */
3969 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
||
3970 (wpa_s
->last_eapol_matches_bssid
&&
3973 #endif /* CONFIG_AP */
3974 os_memcmp(src_addr
, wpa_s
->bssid
, ETH_ALEN
) != 0)) {
3976 * There is possible race condition between receiving the
3977 * association event and the EAPOL frame since they are coming
3978 * through different paths from the driver. In order to avoid
3979 * issues in trying to process the EAPOL frame before receiving
3980 * association information, lets queue it for processing until
3981 * the association event is received. This may also be needed in
3982 * driver-based roaming case, so also use src_addr != BSSID as a
3983 * trigger if we have previously confirmed that the
3984 * Authenticator uses BSSID as the src_addr (which is not the
3985 * case with wired IEEE 802.1X).
3987 wpa_dbg(wpa_s
, MSG_DEBUG
, "Not associated - Delay processing "
3988 "of received EAPOL frame (state=%s bssid=" MACSTR
")",
3989 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
3990 MAC2STR(wpa_s
->bssid
));
3991 wpabuf_free(wpa_s
->pending_eapol_rx
);
3992 wpa_s
->pending_eapol_rx
= wpabuf_alloc_copy(buf
, len
);
3993 if (wpa_s
->pending_eapol_rx
) {
3994 os_get_reltime(&wpa_s
->pending_eapol_rx_time
);
3995 os_memcpy(wpa_s
->pending_eapol_rx_src
, src_addr
,
4001 wpa_s
->last_eapol_matches_bssid
=
4002 os_memcmp(src_addr
, wpa_s
->bssid
, ETH_ALEN
) == 0;
4005 if (wpa_s
->ap_iface
) {
4006 wpa_supplicant_ap_rx_eapol(wpa_s
, src_addr
, buf
, len
);
4009 #endif /* CONFIG_AP */
4011 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
) {
4012 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignored received EAPOL frame since "
4013 "no key management is configured");
4017 if (wpa_s
->eapol_received
== 0 &&
4018 (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) ||
4019 !wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
4020 wpa_s
->wpa_state
!= WPA_COMPLETED
) &&
4021 (wpa_s
->current_ssid
== NULL
||
4022 wpa_s
->current_ssid
->mode
!= IEEE80211_MODE_IBSS
)) {
4023 /* Timeout for completing IEEE 802.1X and WPA authentication */
4026 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
4027 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
||
4028 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
4029 /* Use longer timeout for IEEE 802.1X/EAP */
4034 if (wpa_s
->current_ssid
&& wpa_s
->current_bss
&&
4035 (wpa_s
->current_ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
4036 eap_is_wps_pin_enrollee(&wpa_s
->current_ssid
->eap
)) {
4038 * Use shorter timeout if going through WPS AP iteration
4039 * for PIN config method with an AP that does not
4040 * advertise Selected Registrar.
4042 struct wpabuf
*wps_ie
;
4044 wps_ie
= wpa_bss_get_vendor_ie_multi(
4045 wpa_s
->current_bss
, WPS_IE_VENDOR_TYPE
);
4047 !wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 1))
4049 wpabuf_free(wps_ie
);
4051 #endif /* CONFIG_WPS */
4053 wpa_supplicant_req_auth_timeout(wpa_s
, timeout
, 0);
4055 wpa_s
->eapol_received
++;
4057 if (wpa_s
->countermeasures
) {
4058 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Countermeasures - dropped "
4063 #ifdef CONFIG_IBSS_RSN
4064 if (wpa_s
->current_ssid
&&
4065 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
) {
4066 ibss_rsn_rx_eapol(wpa_s
->ibss_rsn
, src_addr
, buf
, len
);
4069 #endif /* CONFIG_IBSS_RSN */
4071 /* Source address of the incoming EAPOL frame could be compared to the
4072 * current BSSID. However, it is possible that a centralized
4073 * Authenticator could be using another MAC address than the BSSID of
4074 * an AP, so just allow any address to be used for now. The replies are
4075 * still sent to the current BSSID (if available), though. */
4077 os_memcpy(wpa_s
->last_eapol_src
, src_addr
, ETH_ALEN
);
4078 if (!wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) &&
4079 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_OWE
&&
4080 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_DPP
&&
4081 eapol_sm_rx_eapol(wpa_s
->eapol
, src_addr
, buf
, len
) > 0)
4083 wpa_drv_poll(wpa_s
);
4084 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
))
4085 wpa_sm_rx_eapol(wpa_s
->wpa
, src_addr
, buf
, len
);
4086 else if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
4088 * Set portValid = TRUE here since we are going to skip 4-way
4089 * handshake processing which would normally set portValid. We
4090 * need this to allow the EAPOL state machines to be completed
4091 * without going through EAPOL-Key handshake.
4093 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
4098 int wpa_supplicant_update_mac_addr(struct wpa_supplicant
*wpa_s
)
4100 if ((!wpa_s
->p2p_mgmt
||
4101 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
)) &&
4102 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE
)) {
4103 l2_packet_deinit(wpa_s
->l2
);
4104 wpa_s
->l2
= l2_packet_init(wpa_s
->ifname
,
4105 wpa_drv_get_mac_addr(wpa_s
),
4107 wpa_supplicant_rx_eapol
, wpa_s
, 0);
4108 if (wpa_s
->l2
== NULL
)
4111 if (l2_packet_set_packet_filter(wpa_s
->l2
,
4112 L2_PACKET_FILTER_PKTTYPE
))
4113 wpa_dbg(wpa_s
, MSG_DEBUG
,
4114 "Failed to attach pkt_type filter");
4116 const u8
*addr
= wpa_drv_get_mac_addr(wpa_s
);
4118 os_memcpy(wpa_s
->own_addr
, addr
, ETH_ALEN
);
4121 if (wpa_s
->l2
&& l2_packet_get_own_addr(wpa_s
->l2
, wpa_s
->own_addr
)) {
4122 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to get own L2 address");
4126 wpa_sm_set_own_addr(wpa_s
->wpa
, wpa_s
->own_addr
);
4132 static void wpa_supplicant_rx_eapol_bridge(void *ctx
, const u8
*src_addr
,
4133 const u8
*buf
, size_t len
)
4135 struct wpa_supplicant
*wpa_s
= ctx
;
4136 const struct l2_ethhdr
*eth
;
4138 if (len
< sizeof(*eth
))
4140 eth
= (const struct l2_ethhdr
*) buf
;
4142 if (os_memcmp(eth
->h_dest
, wpa_s
->own_addr
, ETH_ALEN
) != 0 &&
4143 !(eth
->h_dest
[0] & 0x01)) {
4144 wpa_dbg(wpa_s
, MSG_DEBUG
, "RX EAPOL from " MACSTR
" to " MACSTR
4145 " (bridge - not for this interface - ignore)",
4146 MAC2STR(src_addr
), MAC2STR(eth
->h_dest
));
4150 wpa_dbg(wpa_s
, MSG_DEBUG
, "RX EAPOL from " MACSTR
" to " MACSTR
4151 " (bridge)", MAC2STR(src_addr
), MAC2STR(eth
->h_dest
));
4152 wpa_supplicant_rx_eapol(wpa_s
, src_addr
, buf
+ sizeof(*eth
),
4153 len
- sizeof(*eth
));
4158 * wpa_supplicant_driver_init - Initialize driver interface parameters
4159 * @wpa_s: Pointer to wpa_supplicant data
4160 * Returns: 0 on success, -1 on failure
4162 * This function is called to initialize driver interface parameters.
4163 * wpa_drv_init() must have been called before this function to initialize the
4166 int wpa_supplicant_driver_init(struct wpa_supplicant
*wpa_s
)
4168 static int interface_count
= 0;
4170 if (wpa_supplicant_update_mac_addr(wpa_s
) < 0)
4173 wpa_dbg(wpa_s
, MSG_DEBUG
, "Own MAC address: " MACSTR
,
4174 MAC2STR(wpa_s
->own_addr
));
4175 os_memcpy(wpa_s
->perm_addr
, wpa_s
->own_addr
, ETH_ALEN
);
4176 wpa_sm_set_own_addr(wpa_s
->wpa
, wpa_s
->own_addr
);
4178 if (wpa_s
->bridge_ifname
[0]) {
4179 wpa_dbg(wpa_s
, MSG_DEBUG
, "Receiving packets from bridge "
4180 "interface '%s'", wpa_s
->bridge_ifname
);
4181 wpa_s
->l2_br
= l2_packet_init_bridge(
4182 wpa_s
->bridge_ifname
, wpa_s
->ifname
, wpa_s
->own_addr
,
4183 ETH_P_EAPOL
, wpa_supplicant_rx_eapol_bridge
, wpa_s
, 1);
4184 if (wpa_s
->l2_br
== NULL
) {
4185 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to open l2_packet "
4186 "connection for the bridge interface '%s'",
4187 wpa_s
->bridge_ifname
);
4192 if (wpa_s
->conf
->ap_scan
== 2 &&
4193 os_strcmp(wpa_s
->driver
->name
, "nl80211") == 0) {
4194 wpa_printf(MSG_INFO
,
4195 "Note: nl80211 driver interface is not designed to be used with ap_scan=2; this can result in connection failures");
4198 wpa_clear_keys(wpa_s
, NULL
);
4200 /* Make sure that TKIP countermeasures are not left enabled (could
4201 * happen if wpa_supplicant is killed during countermeasures. */
4202 wpa_drv_set_countermeasures(wpa_s
, 0);
4204 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: flushing PMKID list in the driver");
4205 wpa_drv_flush_pmkid(wpa_s
);
4207 wpa_s
->prev_scan_ssid
= WILDCARD_SSID_SCAN
;
4208 wpa_s
->prev_scan_wildcard
= 0;
4210 if (wpa_supplicant_enabled_networks(wpa_s
)) {
4211 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4212 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
4213 interface_count
= 0;
4216 if (!wpa_s
->p2p_mgmt
&&
4217 wpa_supplicant_delayed_sched_scan(wpa_s
,
4218 interface_count
% 3,
4220 wpa_supplicant_req_scan(wpa_s
, interface_count
% 3,
4222 #endif /* ANDROID */
4225 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
4231 static int wpa_supplicant_daemon(const char *pid_file
)
4233 wpa_printf(MSG_DEBUG
, "Daemonize..");
4234 return os_daemonize(pid_file
);
4238 static struct wpa_supplicant
*
4239 wpa_supplicant_alloc(struct wpa_supplicant
*parent
)
4241 struct wpa_supplicant
*wpa_s
;
4243 wpa_s
= os_zalloc(sizeof(*wpa_s
));
4246 wpa_s
->scan_req
= INITIAL_SCAN_REQ
;
4247 wpa_s
->scan_interval
= 5;
4248 wpa_s
->new_connection
= 1;
4249 wpa_s
->parent
= parent
? parent
: wpa_s
;
4250 wpa_s
->p2pdev
= wpa_s
->parent
;
4251 wpa_s
->sched_scanning
= 0;
4253 dl_list_init(&wpa_s
->bss_tmp_disallowed
);
4254 dl_list_init(&wpa_s
->fils_hlp_req
);
4260 #ifdef CONFIG_HT_OVERRIDES
4262 static int wpa_set_htcap_mcs(struct wpa_supplicant
*wpa_s
,
4263 struct ieee80211_ht_capabilities
*htcaps
,
4264 struct ieee80211_ht_capabilities
*htcaps_mask
,
4267 /* parse ht_mcs into hex array */
4269 const char *tmp
= ht_mcs
;
4272 /* If ht_mcs is null, do not set anything */
4276 /* This is what we are setting in the kernel */
4277 os_memset(&htcaps
->supported_mcs_set
, 0, IEEE80211_HT_MCS_MASK_LEN
);
4279 wpa_msg(wpa_s
, MSG_DEBUG
, "set_htcap, ht_mcs -:%s:-", ht_mcs
);
4281 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++) {
4285 v
= strtol(tmp
, &end
, 16);
4288 wpa_msg(wpa_s
, MSG_DEBUG
,
4289 "htcap value[%i]: %ld end: %p tmp: %p",
4294 htcaps
->supported_mcs_set
[i
] = v
;
4297 wpa_msg(wpa_s
, MSG_ERROR
,
4298 "Failed to parse ht-mcs: %s, error: %s\n",
4299 ht_mcs
, strerror(errno
));
4305 * If we were able to parse any values, then set mask for the MCS set.
4308 os_memset(&htcaps_mask
->supported_mcs_set
, 0xff,
4309 IEEE80211_HT_MCS_MASK_LEN
- 1);
4310 /* skip the 3 reserved bits */
4311 htcaps_mask
->supported_mcs_set
[IEEE80211_HT_MCS_MASK_LEN
- 1] =
4319 static int wpa_disable_max_amsdu(struct wpa_supplicant
*wpa_s
,
4320 struct ieee80211_ht_capabilities
*htcaps
,
4321 struct ieee80211_ht_capabilities
*htcaps_mask
,
4326 wpa_msg(wpa_s
, MSG_DEBUG
, "set_disable_max_amsdu: %d", disabled
);
4331 msk
= host_to_le16(HT_CAP_INFO_MAX_AMSDU_SIZE
);
4332 htcaps_mask
->ht_capabilities_info
|= msk
;
4334 htcaps
->ht_capabilities_info
&= msk
;
4336 htcaps
->ht_capabilities_info
|= msk
;
4342 static int wpa_set_ampdu_factor(struct wpa_supplicant
*wpa_s
,
4343 struct ieee80211_ht_capabilities
*htcaps
,
4344 struct ieee80211_ht_capabilities
*htcaps_mask
,
4347 wpa_msg(wpa_s
, MSG_DEBUG
, "set_ampdu_factor: %d", factor
);
4352 if (factor
< 0 || factor
> 3) {
4353 wpa_msg(wpa_s
, MSG_ERROR
, "ampdu_factor: %d out of range. "
4354 "Must be 0-3 or -1", factor
);
4358 htcaps_mask
->a_mpdu_params
|= 0x3; /* 2 bits for factor */
4359 htcaps
->a_mpdu_params
&= ~0x3;
4360 htcaps
->a_mpdu_params
|= factor
& 0x3;
4366 static int wpa_set_ampdu_density(struct wpa_supplicant
*wpa_s
,
4367 struct ieee80211_ht_capabilities
*htcaps
,
4368 struct ieee80211_ht_capabilities
*htcaps_mask
,
4371 wpa_msg(wpa_s
, MSG_DEBUG
, "set_ampdu_density: %d", density
);
4376 if (density
< 0 || density
> 7) {
4377 wpa_msg(wpa_s
, MSG_ERROR
,
4378 "ampdu_density: %d out of range. Must be 0-7 or -1.",
4383 htcaps_mask
->a_mpdu_params
|= 0x1C;
4384 htcaps
->a_mpdu_params
&= ~(0x1C);
4385 htcaps
->a_mpdu_params
|= (density
<< 2) & 0x1C;
4391 static int wpa_set_disable_ht40(struct wpa_supplicant
*wpa_s
,
4392 struct ieee80211_ht_capabilities
*htcaps
,
4393 struct ieee80211_ht_capabilities
*htcaps_mask
,
4396 wpa_msg(wpa_s
, MSG_DEBUG
, "set_disable_ht40: %d", disabled
);
4398 set_disable_ht40(htcaps
, disabled
);
4399 set_disable_ht40(htcaps_mask
, 0);
4405 static int wpa_set_disable_sgi(struct wpa_supplicant
*wpa_s
,
4406 struct ieee80211_ht_capabilities
*htcaps
,
4407 struct ieee80211_ht_capabilities
*htcaps_mask
,
4410 /* Masking these out disables SGI */
4411 le16 msk
= host_to_le16(HT_CAP_INFO_SHORT_GI20MHZ
|
4412 HT_CAP_INFO_SHORT_GI40MHZ
);
4414 wpa_msg(wpa_s
, MSG_DEBUG
, "set_disable_sgi: %d", disabled
);
4417 htcaps
->ht_capabilities_info
&= ~msk
;
4419 htcaps
->ht_capabilities_info
|= msk
;
4421 htcaps_mask
->ht_capabilities_info
|= msk
;
4427 static int wpa_set_disable_ldpc(struct wpa_supplicant
*wpa_s
,
4428 struct ieee80211_ht_capabilities
*htcaps
,
4429 struct ieee80211_ht_capabilities
*htcaps_mask
,
4432 /* Masking these out disables LDPC */
4433 le16 msk
= host_to_le16(HT_CAP_INFO_LDPC_CODING_CAP
);
4435 wpa_msg(wpa_s
, MSG_DEBUG
, "set_disable_ldpc: %d", disabled
);
4438 htcaps
->ht_capabilities_info
&= ~msk
;
4440 htcaps
->ht_capabilities_info
|= msk
;
4442 htcaps_mask
->ht_capabilities_info
|= msk
;
4448 void wpa_supplicant_apply_ht_overrides(
4449 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
4450 struct wpa_driver_associate_params
*params
)
4452 struct ieee80211_ht_capabilities
*htcaps
;
4453 struct ieee80211_ht_capabilities
*htcaps_mask
;
4458 params
->disable_ht
= ssid
->disable_ht
;
4459 if (!params
->htcaps
|| !params
->htcaps_mask
)
4462 htcaps
= (struct ieee80211_ht_capabilities
*) params
->htcaps
;
4463 htcaps_mask
= (struct ieee80211_ht_capabilities
*) params
->htcaps_mask
;
4464 wpa_set_htcap_mcs(wpa_s
, htcaps
, htcaps_mask
, ssid
->ht_mcs
);
4465 wpa_disable_max_amsdu(wpa_s
, htcaps
, htcaps_mask
,
4466 ssid
->disable_max_amsdu
);
4467 wpa_set_ampdu_factor(wpa_s
, htcaps
, htcaps_mask
, ssid
->ampdu_factor
);
4468 wpa_set_ampdu_density(wpa_s
, htcaps
, htcaps_mask
, ssid
->ampdu_density
);
4469 wpa_set_disable_ht40(wpa_s
, htcaps
, htcaps_mask
, ssid
->disable_ht40
);
4470 wpa_set_disable_sgi(wpa_s
, htcaps
, htcaps_mask
, ssid
->disable_sgi
);
4471 wpa_set_disable_ldpc(wpa_s
, htcaps
, htcaps_mask
, ssid
->disable_ldpc
);
4473 if (ssid
->ht40_intolerant
) {
4474 le16 bit
= host_to_le16(HT_CAP_INFO_40MHZ_INTOLERANT
);
4475 htcaps
->ht_capabilities_info
|= bit
;
4476 htcaps_mask
->ht_capabilities_info
|= bit
;
4480 #endif /* CONFIG_HT_OVERRIDES */
4483 #ifdef CONFIG_VHT_OVERRIDES
4484 void wpa_supplicant_apply_vht_overrides(
4485 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
4486 struct wpa_driver_associate_params
*params
)
4488 struct ieee80211_vht_capabilities
*vhtcaps
;
4489 struct ieee80211_vht_capabilities
*vhtcaps_mask
;
4494 params
->disable_vht
= ssid
->disable_vht
;
4496 vhtcaps
= (void *) params
->vhtcaps
;
4497 vhtcaps_mask
= (void *) params
->vhtcaps_mask
;
4499 if (!vhtcaps
|| !vhtcaps_mask
)
4502 vhtcaps
->vht_capabilities_info
= host_to_le32(ssid
->vht_capa
);
4503 vhtcaps_mask
->vht_capabilities_info
= host_to_le32(ssid
->vht_capa_mask
);
4505 #ifdef CONFIG_HT_OVERRIDES
4506 /* if max ampdu is <= 3, we have to make the HT cap the same */
4507 if (ssid
->vht_capa_mask
& VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX
) {
4510 max_ampdu
= (ssid
->vht_capa
&
4511 VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX
) >>
4512 VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX_SHIFT
;
4514 max_ampdu
= max_ampdu
< 3 ? max_ampdu
: 3;
4515 wpa_set_ampdu_factor(wpa_s
,
4516 (void *) params
->htcaps
,
4517 (void *) params
->htcaps_mask
,
4520 #endif /* CONFIG_HT_OVERRIDES */
4522 #define OVERRIDE_MCS(i) \
4523 if (ssid->vht_tx_mcs_nss_ ##i >= 0) { \
4524 vhtcaps_mask->vht_supported_mcs_set.tx_map |= \
4525 host_to_le16(3 << 2 * (i - 1)); \
4526 vhtcaps->vht_supported_mcs_set.tx_map |= \
4527 host_to_le16(ssid->vht_tx_mcs_nss_ ##i << \
4530 if (ssid->vht_rx_mcs_nss_ ##i >= 0) { \
4531 vhtcaps_mask->vht_supported_mcs_set.rx_map |= \
4532 host_to_le16(3 << 2 * (i - 1)); \
4533 vhtcaps->vht_supported_mcs_set.rx_map |= \
4534 host_to_le16(ssid->vht_rx_mcs_nss_ ##i << \
4547 #endif /* CONFIG_VHT_OVERRIDES */
4550 static int pcsc_reader_init(struct wpa_supplicant
*wpa_s
)
4555 if (!wpa_s
->conf
->pcsc_reader
)
4558 wpa_s
->scard
= scard_init(wpa_s
->conf
->pcsc_reader
);
4562 if (wpa_s
->conf
->pcsc_pin
&&
4563 scard_set_pin(wpa_s
->scard
, wpa_s
->conf
->pcsc_pin
) < 0) {
4564 scard_deinit(wpa_s
->scard
);
4565 wpa_s
->scard
= NULL
;
4566 wpa_msg(wpa_s
, MSG_ERROR
, "PC/SC PIN validation failed");
4570 len
= sizeof(wpa_s
->imsi
) - 1;
4571 if (scard_get_imsi(wpa_s
->scard
, wpa_s
->imsi
, &len
)) {
4572 scard_deinit(wpa_s
->scard
);
4573 wpa_s
->scard
= NULL
;
4574 wpa_msg(wpa_s
, MSG_ERROR
, "Could not read IMSI");
4577 wpa_s
->imsi
[len
] = '\0';
4579 wpa_s
->mnc_len
= scard_get_mnc_len(wpa_s
->scard
);
4581 wpa_printf(MSG_DEBUG
, "SCARD: IMSI %s (MNC length %d)",
4582 wpa_s
->imsi
, wpa_s
->mnc_len
);
4584 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
4585 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
4586 #endif /* PCSC_FUNCS */
4592 int wpas_init_ext_pw(struct wpa_supplicant
*wpa_s
)
4596 ext_password_deinit(wpa_s
->ext_pw
);
4597 wpa_s
->ext_pw
= NULL
;
4598 eapol_sm_set_ext_pw_ctx(wpa_s
->eapol
, NULL
);
4600 if (!wpa_s
->conf
->ext_password_backend
)
4603 val
= os_strdup(wpa_s
->conf
->ext_password_backend
);
4606 pos
= os_strchr(val
, ':');
4610 wpa_printf(MSG_DEBUG
, "EXT PW: Initialize backend '%s'", val
);
4612 wpa_s
->ext_pw
= ext_password_init(val
, pos
);
4614 if (wpa_s
->ext_pw
== NULL
) {
4615 wpa_printf(MSG_DEBUG
, "EXT PW: Failed to initialize backend");
4618 eapol_sm_set_ext_pw_ctx(wpa_s
->eapol
, wpa_s
->ext_pw
);
4626 static const u8
* wpas_fst_get_bssid_cb(void *ctx
)
4628 struct wpa_supplicant
*wpa_s
= ctx
;
4630 return (is_zero_ether_addr(wpa_s
->bssid
) ||
4631 wpa_s
->wpa_state
!= WPA_COMPLETED
) ? NULL
: wpa_s
->bssid
;
4635 static void wpas_fst_get_channel_info_cb(void *ctx
,
4636 enum hostapd_hw_mode
*hw_mode
,
4639 struct wpa_supplicant
*wpa_s
= ctx
;
4641 if (wpa_s
->current_bss
) {
4642 *hw_mode
= ieee80211_freq_to_chan(wpa_s
->current_bss
->freq
,
4644 } else if (wpa_s
->hw
.num_modes
) {
4645 *hw_mode
= wpa_s
->hw
.modes
[0].mode
;
4653 static int wpas_fst_get_hw_modes(void *ctx
, struct hostapd_hw_modes
**modes
)
4655 struct wpa_supplicant
*wpa_s
= ctx
;
4657 *modes
= wpa_s
->hw
.modes
;
4658 return wpa_s
->hw
.num_modes
;
4662 static void wpas_fst_set_ies_cb(void *ctx
, const struct wpabuf
*fst_ies
)
4664 struct wpa_supplicant
*wpa_s
= ctx
;
4666 wpa_hexdump_buf(MSG_DEBUG
, "FST: Set IEs", fst_ies
);
4667 wpa_s
->fst_ies
= fst_ies
;
4671 static int wpas_fst_send_action_cb(void *ctx
, const u8
*da
, struct wpabuf
*data
)
4673 struct wpa_supplicant
*wpa_s
= ctx
;
4675 if (os_memcmp(wpa_s
->bssid
, da
, ETH_ALEN
) != 0) {
4676 wpa_printf(MSG_INFO
, "FST:%s:bssid=" MACSTR
" != da=" MACSTR
,
4677 __func__
, MAC2STR(wpa_s
->bssid
), MAC2STR(da
));
4680 return wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
4681 wpa_s
->own_addr
, wpa_s
->bssid
,
4682 wpabuf_head(data
), wpabuf_len(data
),
4687 static const struct wpabuf
* wpas_fst_get_mb_ie_cb(void *ctx
, const u8
*addr
)
4689 struct wpa_supplicant
*wpa_s
= ctx
;
4691 WPA_ASSERT(os_memcmp(wpa_s
->bssid
, addr
, ETH_ALEN
) == 0);
4692 return wpa_s
->received_mb_ies
;
4696 static void wpas_fst_update_mb_ie_cb(void *ctx
, const u8
*addr
,
4697 const u8
*buf
, size_t size
)
4699 struct wpa_supplicant
*wpa_s
= ctx
;
4700 struct mb_ies_info info
;
4702 WPA_ASSERT(os_memcmp(wpa_s
->bssid
, addr
, ETH_ALEN
) == 0);
4704 if (!mb_ies_info_by_ies(&info
, buf
, size
)) {
4705 wpabuf_free(wpa_s
->received_mb_ies
);
4706 wpa_s
->received_mb_ies
= mb_ies_by_info(&info
);
4711 static const u8
* wpas_fst_get_peer_first(void *ctx
,
4712 struct fst_get_peer_ctx
**get_ctx
,
4715 struct wpa_supplicant
*wpa_s
= ctx
;
4718 if (!is_zero_ether_addr(wpa_s
->bssid
))
4719 return (wpa_s
->received_mb_ies
|| !mb_only
) ?
4720 wpa_s
->bssid
: NULL
;
4725 static const u8
* wpas_fst_get_peer_next(void *ctx
,
4726 struct fst_get_peer_ctx
**get_ctx
,
4732 void fst_wpa_supplicant_fill_iface_obj(struct wpa_supplicant
*wpa_s
,
4733 struct fst_wpa_obj
*iface_obj
)
4735 iface_obj
->ctx
= wpa_s
;
4736 iface_obj
->get_bssid
= wpas_fst_get_bssid_cb
;
4737 iface_obj
->get_channel_info
= wpas_fst_get_channel_info_cb
;
4738 iface_obj
->get_hw_modes
= wpas_fst_get_hw_modes
;
4739 iface_obj
->set_ies
= wpas_fst_set_ies_cb
;
4740 iface_obj
->send_action
= wpas_fst_send_action_cb
;
4741 iface_obj
->get_mb_ie
= wpas_fst_get_mb_ie_cb
;
4742 iface_obj
->update_mb_ie
= wpas_fst_update_mb_ie_cb
;
4743 iface_obj
->get_peer_first
= wpas_fst_get_peer_first
;
4744 iface_obj
->get_peer_next
= wpas_fst_get_peer_next
;
4746 #endif /* CONFIG_FST */
4748 static int wpas_set_wowlan_triggers(struct wpa_supplicant
*wpa_s
,
4749 const struct wpa_driver_capa
*capa
)
4751 struct wowlan_triggers
*triggers
;
4754 if (!wpa_s
->conf
->wowlan_triggers
)
4757 triggers
= wpa_get_wowlan_triggers(wpa_s
->conf
->wowlan_triggers
, capa
);
4759 ret
= wpa_drv_wowlan(wpa_s
, triggers
);
4766 enum wpa_radio_work_band
wpas_freq_to_band(int freq
)
4769 return BAND_2_4_GHZ
;
4776 unsigned int wpas_get_bands(struct wpa_supplicant
*wpa_s
, const int *freqs
)
4779 unsigned int band
= 0;
4782 /* freqs are specified for the radio work */
4783 for (i
= 0; freqs
[i
]; i
++)
4784 band
|= wpas_freq_to_band(freqs
[i
]);
4787 * freqs are not specified, implies all
4788 * the supported freqs by HW
4790 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
4791 if (wpa_s
->hw
.modes
[i
].num_channels
!= 0) {
4792 if (wpa_s
->hw
.modes
[i
].mode
==
4793 HOSTAPD_MODE_IEEE80211B
||
4794 wpa_s
->hw
.modes
[i
].mode
==
4795 HOSTAPD_MODE_IEEE80211G
)
4796 band
|= BAND_2_4_GHZ
;
4797 else if (wpa_s
->hw
.modes
[i
].mode
==
4798 HOSTAPD_MODE_IEEE80211A
)
4800 else if (wpa_s
->hw
.modes
[i
].mode
==
4801 HOSTAPD_MODE_IEEE80211AD
)
4802 band
|= BAND_60_GHZ
;
4803 else if (wpa_s
->hw
.modes
[i
].mode
==
4804 HOSTAPD_MODE_IEEE80211ANY
)
4805 band
= BAND_2_4_GHZ
| BAND_5_GHZ
|
4815 static struct wpa_radio
* radio_add_interface(struct wpa_supplicant
*wpa_s
,
4818 struct wpa_supplicant
*iface
= wpa_s
->global
->ifaces
;
4819 struct wpa_radio
*radio
;
4821 while (rn
&& iface
) {
4822 radio
= iface
->radio
;
4823 if (radio
&& os_strcmp(rn
, radio
->name
) == 0) {
4824 wpa_printf(MSG_DEBUG
, "Add interface %s to existing radio %s",
4826 dl_list_add(&radio
->ifaces
, &wpa_s
->radio_list
);
4830 iface
= iface
->next
;
4833 wpa_printf(MSG_DEBUG
, "Add interface %s to a new radio %s",
4834 wpa_s
->ifname
, rn
? rn
: "N/A");
4835 radio
= os_zalloc(sizeof(*radio
));
4840 os_strlcpy(radio
->name
, rn
, sizeof(radio
->name
));
4841 dl_list_init(&radio
->ifaces
);
4842 dl_list_init(&radio
->work
);
4843 dl_list_add(&radio
->ifaces
, &wpa_s
->radio_list
);
4849 static void radio_work_free(struct wpa_radio_work
*work
)
4851 if (work
->wpa_s
->scan_work
== work
) {
4852 /* This should not really happen. */
4853 wpa_dbg(work
->wpa_s
, MSG_INFO
, "Freeing radio work '%s'@%p (started=%d) that is marked as scan_work",
4854 work
->type
, work
, work
->started
);
4855 work
->wpa_s
->scan_work
= NULL
;
4859 if (work
->wpa_s
->p2p_scan_work
== work
) {
4860 /* This should not really happen. */
4861 wpa_dbg(work
->wpa_s
, MSG_INFO
, "Freeing radio work '%s'@%p (started=%d) that is marked as p2p_scan_work",
4862 work
->type
, work
, work
->started
);
4863 work
->wpa_s
->p2p_scan_work
= NULL
;
4865 #endif /* CONFIG_P2P */
4867 if (work
->started
) {
4868 work
->wpa_s
->radio
->num_active_works
--;
4869 wpa_dbg(work
->wpa_s
, MSG_DEBUG
,
4870 "radio_work_free('%s'@%p): num_active_works --> %u",
4872 work
->wpa_s
->radio
->num_active_works
);
4875 dl_list_del(&work
->list
);
4880 static int radio_work_is_connect(struct wpa_radio_work
*work
)
4882 return os_strcmp(work
->type
, "sme-connect") == 0 ||
4883 os_strcmp(work
->type
, "connect") == 0;
4887 static int radio_work_is_scan(struct wpa_radio_work
*work
)
4889 return os_strcmp(work
->type
, "scan") == 0 ||
4890 os_strcmp(work
->type
, "p2p-scan") == 0;
4894 static struct wpa_radio_work
* radio_work_get_next_work(struct wpa_radio
*radio
)
4896 struct wpa_radio_work
*active_work
= NULL
;
4897 struct wpa_radio_work
*tmp
;
4899 /* Get the active work to know the type and band. */
4900 dl_list_for_each(tmp
, &radio
->work
, struct wpa_radio_work
, list
) {
4908 /* No active work, start one */
4909 radio
->num_active_works
= 0;
4910 dl_list_for_each(tmp
, &radio
->work
, struct wpa_radio_work
,
4912 if (os_strcmp(tmp
->type
, "scan") == 0 &&
4913 radio
->external_scan_running
&&
4914 (((struct wpa_driver_scan_params
*)
4915 tmp
->ctx
)->only_new_results
||
4916 tmp
->wpa_s
->clear_driver_scan_cache
))
4923 if (radio_work_is_connect(active_work
)) {
4925 * If the active work is either connect or sme-connect,
4926 * do not parallelize them with other radio works.
4928 wpa_dbg(active_work
->wpa_s
, MSG_DEBUG
,
4929 "Do not parallelize radio work with %s",
4934 dl_list_for_each(tmp
, &radio
->work
, struct wpa_radio_work
, list
) {
4939 * If connect or sme-connect are enqueued, parallelize only
4940 * those operations ahead of them in the queue.
4942 if (radio_work_is_connect(tmp
))
4945 /* Serialize parallel scan and p2p_scan operations on the same
4946 * interface since the driver_nl80211 mechanism for tracking
4947 * scan cookies does not yet have support for this. */
4948 if (active_work
->wpa_s
== tmp
->wpa_s
&&
4949 radio_work_is_scan(active_work
) &&
4950 radio_work_is_scan(tmp
)) {
4951 wpa_dbg(active_work
->wpa_s
, MSG_DEBUG
,
4952 "Do not start work '%s' when another work '%s' is already scheduled",
4953 tmp
->type
, active_work
->type
);
4957 * Check that the radio works are distinct and
4958 * on different bands.
4960 if (os_strcmp(active_work
->type
, tmp
->type
) != 0 &&
4961 (active_work
->bands
!= tmp
->bands
)) {
4963 * If a scan has to be scheduled through nl80211 scan
4964 * interface and if an external scan is already running,
4965 * do not schedule the scan since it is likely to get
4966 * rejected by kernel.
4968 if (os_strcmp(tmp
->type
, "scan") == 0 &&
4969 radio
->external_scan_running
&&
4970 (((struct wpa_driver_scan_params
*)
4971 tmp
->ctx
)->only_new_results
||
4972 tmp
->wpa_s
->clear_driver_scan_cache
))
4975 wpa_dbg(active_work
->wpa_s
, MSG_DEBUG
,
4976 "active_work:%s new_work:%s",
4977 active_work
->type
, tmp
->type
);
4982 /* Did not find a radio work to schedule in parallel. */
4987 static void radio_start_next_work(void *eloop_ctx
, void *timeout_ctx
)
4989 struct wpa_radio
*radio
= eloop_ctx
;
4990 struct wpa_radio_work
*work
;
4991 struct os_reltime now
, diff
;
4992 struct wpa_supplicant
*wpa_s
;
4994 work
= dl_list_first(&radio
->work
, struct wpa_radio_work
, list
);
4996 radio
->num_active_works
= 0;
5000 wpa_s
= dl_list_first(&radio
->ifaces
, struct wpa_supplicant
,
5004 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS
)) {
5006 return; /* already started and still in progress */
5008 if (wpa_s
&& wpa_s
->radio
->external_scan_running
) {
5009 wpa_printf(MSG_DEBUG
, "Delay radio work start until externally triggered scan completes");
5014 if (radio
->num_active_works
< MAX_ACTIVE_WORKS
) {
5015 /* get the work to schedule next */
5016 work
= radio_work_get_next_work(radio
);
5022 wpa_s
= work
->wpa_s
;
5023 os_get_reltime(&now
);
5024 os_reltime_sub(&now
, &work
->time
, &diff
);
5025 wpa_dbg(wpa_s
, MSG_DEBUG
,
5026 "Starting radio work '%s'@%p after %ld.%06ld second wait",
5027 work
->type
, work
, diff
.sec
, diff
.usec
);
5030 radio
->num_active_works
++;
5034 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS
) &&
5035 radio
->num_active_works
< MAX_ACTIVE_WORKS
)
5036 radio_work_check_next(wpa_s
);
5041 * This function removes both started and pending radio works running on
5042 * the provided interface's radio.
5043 * Prior to the removal of the radio work, its callback (cb) is called with
5044 * deinit set to be 1. Each work's callback is responsible for clearing its
5045 * internal data and restoring to a correct state.
5046 * @wpa_s: wpa_supplicant data
5047 * @type: type of works to be removed
5048 * @remove_all: 1 to remove all the works on this radio, 0 to remove only
5049 * this interface's works.
5051 void radio_remove_works(struct wpa_supplicant
*wpa_s
,
5052 const char *type
, int remove_all
)
5054 struct wpa_radio_work
*work
, *tmp
;
5055 struct wpa_radio
*radio
= wpa_s
->radio
;
5057 dl_list_for_each_safe(work
, tmp
, &radio
->work
, struct wpa_radio_work
,
5059 if (type
&& os_strcmp(type
, work
->type
) != 0)
5062 /* skip other ifaces' works */
5063 if (!remove_all
&& work
->wpa_s
!= wpa_s
)
5066 wpa_dbg(wpa_s
, MSG_DEBUG
, "Remove radio work '%s'@%p%s",
5067 work
->type
, work
, work
->started
? " (started)" : "");
5069 radio_work_free(work
);
5072 /* in case we removed the started work */
5073 radio_work_check_next(wpa_s
);
5077 void radio_remove_pending_work(struct wpa_supplicant
*wpa_s
, void *ctx
)
5079 struct wpa_radio_work
*work
;
5080 struct wpa_radio
*radio
= wpa_s
->radio
;
5082 dl_list_for_each(work
, &radio
->work
, struct wpa_radio_work
, list
) {
5083 if (work
->ctx
!= ctx
)
5085 wpa_dbg(wpa_s
, MSG_DEBUG
, "Free pending radio work '%s'@%p%s",
5086 work
->type
, work
, work
->started
? " (started)" : "");
5087 radio_work_free(work
);
5093 static void radio_remove_interface(struct wpa_supplicant
*wpa_s
)
5095 struct wpa_radio
*radio
= wpa_s
->radio
;
5100 wpa_printf(MSG_DEBUG
, "Remove interface %s from radio %s",
5101 wpa_s
->ifname
, radio
->name
);
5102 dl_list_del(&wpa_s
->radio_list
);
5103 radio_remove_works(wpa_s
, NULL
, 0);
5104 wpa_s
->radio
= NULL
;
5105 if (!dl_list_empty(&radio
->ifaces
))
5106 return; /* Interfaces remain for this radio */
5108 wpa_printf(MSG_DEBUG
, "Remove radio %s", radio
->name
);
5109 eloop_cancel_timeout(radio_start_next_work
, radio
, NULL
);
5114 void radio_work_check_next(struct wpa_supplicant
*wpa_s
)
5116 struct wpa_radio
*radio
= wpa_s
->radio
;
5118 if (dl_list_empty(&radio
->work
))
5120 if (wpa_s
->ext_work_in_progress
) {
5121 wpa_printf(MSG_DEBUG
,
5122 "External radio work in progress - delay start of pending item");
5125 eloop_cancel_timeout(radio_start_next_work
, radio
, NULL
);
5126 eloop_register_timeout(0, 0, radio_start_next_work
, radio
, NULL
);
5131 * radio_add_work - Add a radio work item
5132 * @wpa_s: Pointer to wpa_supplicant data
5133 * @freq: Frequency of the offchannel operation in MHz or 0
5134 * @type: Unique identifier for each type of work
5135 * @next: Force as the next work to be executed
5136 * @cb: Callback function for indicating when radio is available
5137 * @ctx: Context pointer for the work (work->ctx in cb())
5138 * Returns: 0 on success, -1 on failure
5140 * This function is used to request time for an operation that requires
5141 * exclusive radio control. Once the radio is available, the registered callback
5142 * function will be called. radio_work_done() must be called once the exclusive
5143 * radio operation has been completed, so that the radio is freed for other
5144 * operations. The special case of deinit=1 is used to free the context data
5145 * during interface removal. That does not allow the callback function to start
5146 * the radio operation, i.e., it must free any resources allocated for the radio
5149 * The @freq parameter can be used to indicate a single channel on which the
5150 * offchannel operation will occur. This may allow multiple radio work
5151 * operations to be performed in parallel if they apply for the same channel.
5152 * Setting this to 0 indicates that the work item may use multiple channels or
5153 * requires exclusive control of the radio.
5155 int radio_add_work(struct wpa_supplicant
*wpa_s
, unsigned int freq
,
5156 const char *type
, int next
,
5157 void (*cb
)(struct wpa_radio_work
*work
, int deinit
),
5160 struct wpa_radio
*radio
= wpa_s
->radio
;
5161 struct wpa_radio_work
*work
;
5164 work
= os_zalloc(sizeof(*work
));
5167 wpa_dbg(wpa_s
, MSG_DEBUG
, "Add radio work '%s'@%p", type
, work
);
5168 os_get_reltime(&work
->time
);
5171 work
->wpa_s
= wpa_s
;
5176 work
->bands
= wpas_freq_to_band(freq
);
5177 else if (os_strcmp(type
, "scan") == 0 ||
5178 os_strcmp(type
, "p2p-scan") == 0)
5179 work
->bands
= wpas_get_bands(wpa_s
,
5180 ((struct wpa_driver_scan_params
*)
5183 work
->bands
= wpas_get_bands(wpa_s
, NULL
);
5185 was_empty
= dl_list_empty(&wpa_s
->radio
->work
);
5187 dl_list_add(&wpa_s
->radio
->work
, &work
->list
);
5189 dl_list_add_tail(&wpa_s
->radio
->work
, &work
->list
);
5191 wpa_dbg(wpa_s
, MSG_DEBUG
, "First radio work item in the queue - schedule start immediately");
5192 radio_work_check_next(wpa_s
);
5193 } else if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS
)
5194 && radio
->num_active_works
< MAX_ACTIVE_WORKS
) {
5195 wpa_dbg(wpa_s
, MSG_DEBUG
,
5196 "Try to schedule a radio work (num_active_works=%u)",
5197 radio
->num_active_works
);
5198 radio_work_check_next(wpa_s
);
5206 * radio_work_done - Indicate that a radio work item has been completed
5207 * @work: Completed work
5209 * This function is called once the callback function registered with
5210 * radio_add_work() has completed its work.
5212 void radio_work_done(struct wpa_radio_work
*work
)
5214 struct wpa_supplicant
*wpa_s
= work
->wpa_s
;
5215 struct os_reltime now
, diff
;
5216 unsigned int started
= work
->started
;
5218 os_get_reltime(&now
);
5219 os_reltime_sub(&now
, &work
->time
, &diff
);
5220 wpa_dbg(wpa_s
, MSG_DEBUG
, "Radio work '%s'@%p %s in %ld.%06ld seconds",
5221 work
->type
, work
, started
? "done" : "canceled",
5222 diff
.sec
, diff
.usec
);
5223 radio_work_free(work
);
5225 radio_work_check_next(wpa_s
);
5229 struct wpa_radio_work
*
5230 radio_work_pending(struct wpa_supplicant
*wpa_s
, const char *type
)
5232 struct wpa_radio_work
*work
;
5233 struct wpa_radio
*radio
= wpa_s
->radio
;
5235 dl_list_for_each(work
, &radio
->work
, struct wpa_radio_work
, list
) {
5236 if (work
->wpa_s
== wpa_s
&& os_strcmp(work
->type
, type
) == 0)
5244 static int wpas_init_driver(struct wpa_supplicant
*wpa_s
,
5245 const struct wpa_interface
*iface
)
5247 const char *ifname
, *driver
, *rn
;
5249 driver
= iface
->driver
;
5251 if (wpa_supplicant_set_driver(wpa_s
, driver
) < 0)
5254 wpa_s
->drv_priv
= wpa_drv_init(wpa_s
, wpa_s
->ifname
);
5255 if (wpa_s
->drv_priv
== NULL
) {
5257 pos
= driver
? os_strchr(driver
, ',') : NULL
;
5259 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to initialize "
5260 "driver interface - try next driver wrapper");
5264 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to initialize driver "
5268 if (wpa_drv_set_param(wpa_s
, wpa_s
->conf
->driver_param
) < 0) {
5269 wpa_msg(wpa_s
, MSG_ERROR
, "Driver interface rejected "
5270 "driver_param '%s'", wpa_s
->conf
->driver_param
);
5274 ifname
= wpa_drv_get_ifname(wpa_s
);
5275 if (ifname
&& os_strcmp(ifname
, wpa_s
->ifname
) != 0) {
5276 wpa_dbg(wpa_s
, MSG_DEBUG
, "Driver interface replaced "
5277 "interface name with '%s'", ifname
);
5278 os_strlcpy(wpa_s
->ifname
, ifname
, sizeof(wpa_s
->ifname
));
5281 rn
= wpa_driver_get_radio_name(wpa_s
);
5282 if (rn
&& rn
[0] == '\0')
5285 wpa_s
->radio
= radio_add_interface(wpa_s
, rn
);
5286 if (wpa_s
->radio
== NULL
)
5293 #ifdef CONFIG_GAS_SERVER
5295 static void wpas_gas_server_tx_status(struct wpa_supplicant
*wpa_s
,
5296 unsigned int freq
, const u8
*dst
,
5297 const u8
*src
, const u8
*bssid
,
5298 const u8
*data
, size_t data_len
,
5299 enum offchannel_send_action_result result
)
5301 wpa_printf(MSG_DEBUG
, "GAS: TX status: freq=%u dst=" MACSTR
5304 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
? "SUCCESS" :
5305 (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
? "no-ACK" :
5307 gas_server_tx_status(wpa_s
->gas_server
, dst
, data
, data_len
,
5308 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
);
5312 static void wpas_gas_server_tx(void *ctx
, int freq
, const u8
*da
,
5313 struct wpabuf
*buf
, unsigned int wait_time
)
5315 struct wpa_supplicant
*wpa_s
= ctx
;
5316 const u8 broadcast
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
5318 if (wait_time
> wpa_s
->max_remain_on_chan
)
5319 wait_time
= wpa_s
->max_remain_on_chan
;
5321 offchannel_send_action(wpa_s
, freq
, da
, wpa_s
->own_addr
, broadcast
,
5322 wpabuf_head(buf
), wpabuf_len(buf
),
5323 wait_time
, wpas_gas_server_tx_status
, 0);
5326 #endif /* CONFIG_GAS_SERVER */
5328 static int wpa_supplicant_init_iface(struct wpa_supplicant
*wpa_s
,
5329 const struct wpa_interface
*iface
)
5331 struct wpa_driver_capa capa
;
5335 wpa_printf(MSG_DEBUG
, "Initializing interface '%s' conf '%s' driver "
5336 "'%s' ctrl_interface '%s' bridge '%s'", iface
->ifname
,
5337 iface
->confname
? iface
->confname
: "N/A",
5338 iface
->driver
? iface
->driver
: "default",
5339 iface
->ctrl_interface
? iface
->ctrl_interface
: "N/A",
5340 iface
->bridge_ifname
? iface
->bridge_ifname
: "N/A");
5342 if (iface
->confname
) {
5343 #ifdef CONFIG_BACKEND_FILE
5344 wpa_s
->confname
= os_rel2abs_path(iface
->confname
);
5345 if (wpa_s
->confname
== NULL
) {
5346 wpa_printf(MSG_ERROR
, "Failed to get absolute path "
5347 "for configuration file '%s'.",
5351 wpa_printf(MSG_DEBUG
, "Configuration file '%s' -> '%s'",
5352 iface
->confname
, wpa_s
->confname
);
5353 #else /* CONFIG_BACKEND_FILE */
5354 wpa_s
->confname
= os_strdup(iface
->confname
);
5355 #endif /* CONFIG_BACKEND_FILE */
5356 wpa_s
->conf
= wpa_config_read(wpa_s
->confname
, NULL
);
5357 if (wpa_s
->conf
== NULL
) {
5358 wpa_printf(MSG_ERROR
, "Failed to read or parse "
5359 "configuration '%s'.", wpa_s
->confname
);
5362 wpa_s
->confanother
= os_rel2abs_path(iface
->confanother
);
5363 if (wpa_s
->confanother
&&
5364 !wpa_config_read(wpa_s
->confanother
, wpa_s
->conf
)) {
5365 wpa_printf(MSG_ERROR
,
5366 "Failed to read or parse configuration '%s'.",
5367 wpa_s
->confanother
);
5372 * Override ctrl_interface and driver_param if set on command
5375 if (iface
->ctrl_interface
) {
5376 os_free(wpa_s
->conf
->ctrl_interface
);
5377 wpa_s
->conf
->ctrl_interface
=
5378 os_strdup(iface
->ctrl_interface
);
5381 if (iface
->driver_param
) {
5382 os_free(wpa_s
->conf
->driver_param
);
5383 wpa_s
->conf
->driver_param
=
5384 os_strdup(iface
->driver_param
);
5387 if (iface
->p2p_mgmt
&& !iface
->ctrl_interface
) {
5388 os_free(wpa_s
->conf
->ctrl_interface
);
5389 wpa_s
->conf
->ctrl_interface
= NULL
;
5392 wpa_s
->conf
= wpa_config_alloc_empty(iface
->ctrl_interface
,
5393 iface
->driver_param
);
5395 if (wpa_s
->conf
== NULL
) {
5396 wpa_printf(MSG_ERROR
, "\nNo configuration found.");
5400 if (iface
->ifname
== NULL
) {
5401 wpa_printf(MSG_ERROR
, "\nInterface name is required.");
5404 if (os_strlen(iface
->ifname
) >= sizeof(wpa_s
->ifname
)) {
5405 wpa_printf(MSG_ERROR
, "\nToo long interface name '%s'.",
5409 os_strlcpy(wpa_s
->ifname
, iface
->ifname
, sizeof(wpa_s
->ifname
));
5411 if (iface
->bridge_ifname
) {
5412 if (os_strlen(iface
->bridge_ifname
) >=
5413 sizeof(wpa_s
->bridge_ifname
)) {
5414 wpa_printf(MSG_ERROR
, "\nToo long bridge interface "
5415 "name '%s'.", iface
->bridge_ifname
);
5418 os_strlcpy(wpa_s
->bridge_ifname
, iface
->bridge_ifname
,
5419 sizeof(wpa_s
->bridge_ifname
));
5422 /* RSNA Supplicant Key Management - INITIALIZE */
5423 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
5424 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
5426 /* Initialize driver interface and register driver event handler before
5427 * L2 receive handler so that association events are processed before
5428 * EAPOL-Key packets if both become available for the same select()
5430 if (wpas_init_driver(wpa_s
, iface
) < 0)
5433 if (wpa_supplicant_init_wpa(wpa_s
) < 0)
5436 wpa_sm_set_ifname(wpa_s
->wpa
, wpa_s
->ifname
,
5437 wpa_s
->bridge_ifname
[0] ? wpa_s
->bridge_ifname
:
5439 wpa_sm_set_fast_reauth(wpa_s
->wpa
, wpa_s
->conf
->fast_reauth
);
5441 if (wpa_s
->conf
->dot11RSNAConfigPMKLifetime
&&
5442 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
5443 wpa_s
->conf
->dot11RSNAConfigPMKLifetime
)) {
5444 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid WPA parameter value for "
5445 "dot11RSNAConfigPMKLifetime");
5449 if (wpa_s
->conf
->dot11RSNAConfigPMKReauthThreshold
&&
5450 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
5451 wpa_s
->conf
->dot11RSNAConfigPMKReauthThreshold
)) {
5452 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid WPA parameter value for "
5453 "dot11RSNAConfigPMKReauthThreshold");
5457 if (wpa_s
->conf
->dot11RSNAConfigSATimeout
&&
5458 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
,
5459 wpa_s
->conf
->dot11RSNAConfigSATimeout
)) {
5460 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid WPA parameter value for "
5461 "dot11RSNAConfigSATimeout");
5465 wpa_s
->hw
.modes
= wpa_drv_get_hw_feature_data(wpa_s
,
5466 &wpa_s
->hw
.num_modes
,
5469 if (wpa_s
->hw
.modes
) {
5472 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
5473 if (wpa_s
->hw
.modes
[i
].vht_capab
) {
5474 wpa_s
->hw_capab
= CAPAB_VHT
;
5478 if (wpa_s
->hw
.modes
[i
].ht_capab
&
5479 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
)
5480 wpa_s
->hw_capab
= CAPAB_HT40
;
5481 else if (wpa_s
->hw
.modes
[i
].ht_capab
&&
5482 wpa_s
->hw_capab
== CAPAB_NO_HT_VHT
)
5483 wpa_s
->hw_capab
= CAPAB_HT
;
5487 capa_res
= wpa_drv_get_capa(wpa_s
, &capa
);
5488 if (capa_res
== 0) {
5489 wpa_s
->drv_capa_known
= 1;
5490 wpa_s
->drv_flags
= capa
.flags
;
5491 wpa_s
->drv_enc
= capa
.enc
;
5492 wpa_s
->drv_smps_modes
= capa
.smps_modes
;
5493 wpa_s
->drv_rrm_flags
= capa
.rrm_flags
;
5494 wpa_s
->probe_resp_offloads
= capa
.probe_resp_offloads
;
5495 wpa_s
->max_scan_ssids
= capa
.max_scan_ssids
;
5496 wpa_s
->max_sched_scan_ssids
= capa
.max_sched_scan_ssids
;
5497 wpa_s
->max_sched_scan_plans
= capa
.max_sched_scan_plans
;
5498 wpa_s
->max_sched_scan_plan_interval
=
5499 capa
.max_sched_scan_plan_interval
;
5500 wpa_s
->max_sched_scan_plan_iterations
=
5501 capa
.max_sched_scan_plan_iterations
;
5502 wpa_s
->sched_scan_supported
= capa
.sched_scan_supported
;
5503 wpa_s
->max_match_sets
= capa
.max_match_sets
;
5504 wpa_s
->max_remain_on_chan
= capa
.max_remain_on_chan
;
5505 wpa_s
->max_stations
= capa
.max_stations
;
5506 wpa_s
->extended_capa
= capa
.extended_capa
;
5507 wpa_s
->extended_capa_mask
= capa
.extended_capa_mask
;
5508 wpa_s
->extended_capa_len
= capa
.extended_capa_len
;
5509 wpa_s
->num_multichan_concurrent
=
5510 capa
.num_multichan_concurrent
;
5511 wpa_s
->wmm_ac_supported
= capa
.wmm_ac_supported
;
5513 if (capa
.mac_addr_rand_scan_supported
)
5514 wpa_s
->mac_addr_rand_supported
|= MAC_ADDR_RAND_SCAN
;
5515 if (wpa_s
->sched_scan_supported
&&
5516 capa
.mac_addr_rand_sched_scan_supported
)
5517 wpa_s
->mac_addr_rand_supported
|=
5518 (MAC_ADDR_RAND_SCHED_SCAN
| MAC_ADDR_RAND_PNO
);
5520 if (wpa_s
->max_remain_on_chan
== 0)
5521 wpa_s
->max_remain_on_chan
= 1000;
5524 * Only take p2p_mgmt parameters when P2P Device is supported.
5525 * Doing it here as it determines whether l2_packet_init() will be done
5526 * during wpa_supplicant_driver_init().
5528 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
)
5529 wpa_s
->p2p_mgmt
= iface
->p2p_mgmt
;
5531 if (wpa_s
->num_multichan_concurrent
== 0)
5532 wpa_s
->num_multichan_concurrent
= 1;
5534 if (wpa_supplicant_driver_init(wpa_s
) < 0)
5538 if (!iface
->p2p_mgmt
&& wpa_tdls_init(wpa_s
->wpa
))
5540 #endif /* CONFIG_TDLS */
5542 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1] &&
5543 wpa_drv_set_country(wpa_s
, wpa_s
->conf
->country
)) {
5544 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to set country");
5549 if (wpa_s
->conf
->fst_group_id
) {
5550 struct fst_iface_cfg cfg
;
5551 struct fst_wpa_obj iface_obj
;
5553 fst_wpa_supplicant_fill_iface_obj(wpa_s
, &iface_obj
);
5554 os_strlcpy(cfg
.group_id
, wpa_s
->conf
->fst_group_id
,
5555 sizeof(cfg
.group_id
));
5556 cfg
.priority
= wpa_s
->conf
->fst_priority
;
5557 cfg
.llt
= wpa_s
->conf
->fst_llt
;
5559 wpa_s
->fst
= fst_attach(wpa_s
->ifname
, wpa_s
->own_addr
,
5562 wpa_msg(wpa_s
, MSG_ERROR
,
5563 "FST: Cannot attach iface %s to group %s",
5564 wpa_s
->ifname
, cfg
.group_id
);
5568 #endif /* CONFIG_FST */
5570 if (wpas_wps_init(wpa_s
))
5573 #ifdef CONFIG_GAS_SERVER
5574 wpa_s
->gas_server
= gas_server_init(wpa_s
, wpas_gas_server_tx
);
5575 if (!wpa_s
->gas_server
) {
5576 wpa_printf(MSG_ERROR
, "Failed to initialize GAS server");
5579 #endif /* CONFIG_GAS_SERVER */
5582 if (wpas_dpp_init(wpa_s
) < 0)
5584 #endif /* CONFIG_DPP */
5586 if (wpa_supplicant_init_eapol(wpa_s
) < 0)
5588 wpa_sm_set_eapol(wpa_s
->wpa
, wpa_s
->eapol
);
5590 wpa_s
->ctrl_iface
= wpa_supplicant_ctrl_iface_init(wpa_s
);
5591 if (wpa_s
->ctrl_iface
== NULL
) {
5592 wpa_printf(MSG_ERROR
,
5593 "Failed to initialize control interface '%s'.\n"
5594 "You may have another wpa_supplicant process "
5595 "already running or the file was\n"
5596 "left by an unclean termination of wpa_supplicant "
5597 "in which case you will need\n"
5598 "to manually remove this file before starting "
5599 "wpa_supplicant again.\n",
5600 wpa_s
->conf
->ctrl_interface
);
5604 wpa_s
->gas
= gas_query_init(wpa_s
);
5605 if (wpa_s
->gas
== NULL
) {
5606 wpa_printf(MSG_ERROR
, "Failed to initialize GAS query");
5610 if ((!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
) ||
5612 wpas_p2p_init(wpa_s
->global
, wpa_s
) < 0) {
5613 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to init P2P");
5617 if (wpa_bss_init(wpa_s
) < 0)
5620 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
5622 dl_list_init(&wpa_s
->mesh_external_pmksa_cache
);
5623 #endif /* CONFIG_MESH */
5624 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
5627 * Set Wake-on-WLAN triggers, if configured.
5628 * Note: We don't restore/remove the triggers on shutdown (it doesn't
5629 * have effect anyway when the interface is down).
5631 if (capa_res
== 0 && wpas_set_wowlan_triggers(wpa_s
, &capa
) < 0)
5634 #ifdef CONFIG_EAP_PROXY
5637 wpa_s
->mnc_len
= eapol_sm_get_eap_proxy_imsi(wpa_s
->eapol
, -1,
5639 if (wpa_s
->mnc_len
> 0) {
5640 wpa_s
->imsi
[len
] = '\0';
5641 wpa_printf(MSG_DEBUG
, "eap_proxy: IMSI %s (MNC length %d)",
5642 wpa_s
->imsi
, wpa_s
->mnc_len
);
5644 wpa_printf(MSG_DEBUG
, "eap_proxy: IMSI not available");
5647 #endif /* CONFIG_EAP_PROXY */
5649 if (pcsc_reader_init(wpa_s
) < 0)
5652 if (wpas_init_ext_pw(wpa_s
) < 0)
5655 wpas_rrm_reset(wpa_s
);
5657 wpas_sched_scan_plans_set(wpa_s
, wpa_s
->conf
->sched_scan_plans
);
5661 #endif /* CONFIG_HS20 */
5663 if (wpa_s
->conf
->oce
) {
5664 if ((wpa_s
->conf
->oce
& OCE_STA
) &&
5665 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OCE_STA
))
5666 wpa_s
->enable_oce
= OCE_STA
;
5667 if ((wpa_s
->conf
->oce
& OCE_STA_CFON
) &&
5668 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OCE_STA_CFON
)) {
5669 /* TODO: Need to add STA-CFON support */
5670 wpa_printf(MSG_ERROR
,
5671 "OCE STA-CFON feature is not yet supported");
5674 wpas_mbo_update_non_pref_chan(wpa_s
, wpa_s
->conf
->non_pref_chan
);
5675 #endif /* CONFIG_MBO */
5677 wpa_supplicant_set_default_scan_ies(wpa_s
);
5683 static void wpa_supplicant_deinit_iface(struct wpa_supplicant
*wpa_s
,
5684 int notify
, int terminate
)
5686 struct wpa_global
*global
= wpa_s
->global
;
5687 struct wpa_supplicant
*iface
, *prev
;
5689 if (wpa_s
== wpa_s
->parent
)
5690 wpas_p2p_group_remove(wpa_s
, "*");
5692 iface
= global
->ifaces
;
5694 if (iface
->p2pdev
== wpa_s
)
5695 iface
->p2pdev
= iface
->parent
;
5696 if (iface
== wpa_s
|| iface
->parent
!= wpa_s
) {
5697 iface
= iface
->next
;
5700 wpa_printf(MSG_DEBUG
,
5701 "Remove remaining child interface %s from parent %s",
5702 iface
->ifname
, wpa_s
->ifname
);
5704 iface
= iface
->next
;
5705 wpa_supplicant_remove_iface(global
, prev
, terminate
);
5708 wpa_s
->disconnected
= 1;
5709 if (wpa_s
->drv_priv
) {
5710 wpa_supplicant_deauthenticate(wpa_s
,
5711 WLAN_REASON_DEAUTH_LEAVING
);
5713 wpa_drv_set_countermeasures(wpa_s
, 0);
5714 wpa_clear_keys(wpa_s
, NULL
);
5717 wpa_supplicant_cleanup(wpa_s
);
5718 wpas_p2p_deinit_iface(wpa_s
);
5720 wpas_ctrl_radio_work_flush(wpa_s
);
5721 radio_remove_interface(wpa_s
);
5725 fst_detach(wpa_s
->fst
);
5728 if (wpa_s
->received_mb_ies
) {
5729 wpabuf_free(wpa_s
->received_mb_ies
);
5730 wpa_s
->received_mb_ies
= NULL
;
5732 #endif /* CONFIG_FST */
5734 if (wpa_s
->drv_priv
)
5735 wpa_drv_deinit(wpa_s
);
5738 wpas_notify_iface_removed(wpa_s
);
5741 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_TERMINATING
);
5743 if (wpa_s
->ctrl_iface
) {
5744 wpa_supplicant_ctrl_iface_deinit(wpa_s
->ctrl_iface
);
5745 wpa_s
->ctrl_iface
= NULL
;
5750 wpa_supplicant_mesh_iface_deinit(wpa_s
, wpa_s
->ifmsh
);
5751 wpa_s
->ifmsh
= NULL
;
5753 #endif /* CONFIG_MESH */
5755 if (wpa_s
->conf
!= NULL
) {
5756 wpa_config_free(wpa_s
->conf
);
5760 os_free(wpa_s
->ssids_from_scan_req
);
5766 #ifdef CONFIG_MATCH_IFACE
5769 * wpa_supplicant_match_iface - Match an interface description to a name
5770 * @global: Pointer to global data from wpa_supplicant_init()
5771 * @ifname: Name of the interface to match
5772 * Returns: Pointer to the created interface description or %NULL on failure
5774 struct wpa_interface
* wpa_supplicant_match_iface(struct wpa_global
*global
,
5778 struct wpa_interface
*iface
, *miface
;
5780 for (i
= 0; i
< global
->params
.match_iface_count
; i
++) {
5781 miface
= &global
->params
.match_ifaces
[i
];
5782 if (!miface
->ifname
||
5783 fnmatch(miface
->ifname
, ifname
, 0) == 0) {
5784 iface
= os_zalloc(sizeof(*iface
));
5788 iface
->ifname
= ifname
;
5798 * wpa_supplicant_match_existing - Match existing interfaces
5799 * @global: Pointer to global data from wpa_supplicant_init()
5800 * Returns: 0 on success, -1 on failure
5802 static int wpa_supplicant_match_existing(struct wpa_global
*global
)
5804 struct if_nameindex
*ifi
, *ifp
;
5805 struct wpa_supplicant
*wpa_s
;
5806 struct wpa_interface
*iface
;
5808 ifp
= if_nameindex();
5810 wpa_printf(MSG_ERROR
, "if_nameindex: %s", strerror(errno
));
5814 for (ifi
= ifp
; ifi
->if_name
; ifi
++) {
5815 wpa_s
= wpa_supplicant_get_iface(global
, ifi
->if_name
);
5818 iface
= wpa_supplicant_match_iface(global
, ifi
->if_name
);
5820 wpa_s
= wpa_supplicant_add_iface(global
, iface
, NULL
);
5827 if_freenameindex(ifp
);
5831 #endif /* CONFIG_MATCH_IFACE */
5835 * wpa_supplicant_add_iface - Add a new network interface
5836 * @global: Pointer to global data from wpa_supplicant_init()
5837 * @iface: Interface configuration options
5838 * @parent: Parent interface or %NULL to assign new interface as parent
5839 * Returns: Pointer to the created interface or %NULL on failure
5841 * This function is used to add new network interfaces for %wpa_supplicant.
5842 * This can be called before wpa_supplicant_run() to add interfaces before the
5843 * main event loop has been started. In addition, new interfaces can be added
5844 * dynamically while %wpa_supplicant is already running. This could happen,
5845 * e.g., when a hotplug network adapter is inserted.
5847 struct wpa_supplicant
* wpa_supplicant_add_iface(struct wpa_global
*global
,
5848 struct wpa_interface
*iface
,
5849 struct wpa_supplicant
*parent
)
5851 struct wpa_supplicant
*wpa_s
;
5852 struct wpa_interface t_iface
;
5853 struct wpa_ssid
*ssid
;
5855 if (global
== NULL
|| iface
== NULL
)
5858 wpa_s
= wpa_supplicant_alloc(parent
);
5862 wpa_s
->global
= global
;
5865 if (global
->params
.override_driver
) {
5866 wpa_printf(MSG_DEBUG
, "Override interface parameter: driver "
5868 iface
->driver
, global
->params
.override_driver
);
5869 t_iface
.driver
= global
->params
.override_driver
;
5871 if (global
->params
.override_ctrl_interface
) {
5872 wpa_printf(MSG_DEBUG
, "Override interface parameter: "
5873 "ctrl_interface ('%s' -> '%s')",
5874 iface
->ctrl_interface
,
5875 global
->params
.override_ctrl_interface
);
5876 t_iface
.ctrl_interface
=
5877 global
->params
.override_ctrl_interface
;
5879 if (wpa_supplicant_init_iface(wpa_s
, &t_iface
)) {
5880 wpa_printf(MSG_DEBUG
, "Failed to add interface %s",
5882 wpa_supplicant_deinit_iface(wpa_s
, 0, 0);
5886 if (iface
->p2p_mgmt
== 0) {
5887 /* Notify the control interfaces about new iface */
5888 if (wpas_notify_iface_added(wpa_s
)) {
5889 wpa_supplicant_deinit_iface(wpa_s
, 1, 0);
5893 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
)
5894 wpas_notify_network_added(wpa_s
, ssid
);
5897 wpa_s
->next
= global
->ifaces
;
5898 global
->ifaces
= wpa_s
;
5900 wpa_dbg(wpa_s
, MSG_DEBUG
, "Added interface %s", wpa_s
->ifname
);
5901 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
5904 if (wpa_s
->global
->p2p
== NULL
&&
5905 !wpa_s
->global
->p2p_disabled
&& !wpa_s
->conf
->p2p_disabled
&&
5906 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
) &&
5907 wpas_p2p_add_p2pdev_interface(
5908 wpa_s
, wpa_s
->global
->params
.conf_p2p_dev
) < 0) {
5909 wpa_printf(MSG_INFO
,
5910 "P2P: Failed to enable P2P Device interface");
5911 /* Try to continue without. P2P will be disabled. */
5913 #endif /* CONFIG_P2P */
5920 * wpa_supplicant_remove_iface - Remove a network interface
5921 * @global: Pointer to global data from wpa_supplicant_init()
5922 * @wpa_s: Pointer to the network interface to be removed
5923 * Returns: 0 if interface was removed, -1 if interface was not found
5925 * This function can be used to dynamically remove network interfaces from
5926 * %wpa_supplicant, e.g., when a hotplug network adapter is ejected. In
5927 * addition, this function is used to remove all remaining interfaces when
5928 * %wpa_supplicant is terminated.
5930 int wpa_supplicant_remove_iface(struct wpa_global
*global
,
5931 struct wpa_supplicant
*wpa_s
,
5934 struct wpa_supplicant
*prev
;
5936 unsigned int mesh_if_created
= wpa_s
->mesh_if_created
;
5937 char *ifname
= NULL
;
5938 struct wpa_supplicant
*parent
= wpa_s
->parent
;
5939 #endif /* CONFIG_MESH */
5941 /* Remove interface from the global list of interfaces */
5942 prev
= global
->ifaces
;
5943 if (prev
== wpa_s
) {
5944 global
->ifaces
= wpa_s
->next
;
5946 while (prev
&& prev
->next
!= wpa_s
)
5950 prev
->next
= wpa_s
->next
;
5953 wpa_dbg(wpa_s
, MSG_DEBUG
, "Removing interface %s", wpa_s
->ifname
);
5956 if (mesh_if_created
) {
5957 ifname
= os_strdup(wpa_s
->ifname
);
5958 if (ifname
== NULL
) {
5959 wpa_dbg(wpa_s
, MSG_ERROR
,
5960 "mesh: Failed to malloc ifname");
5964 #endif /* CONFIG_MESH */
5966 if (global
->p2p_group_formation
== wpa_s
)
5967 global
->p2p_group_formation
= NULL
;
5968 if (global
->p2p_invite_group
== wpa_s
)
5969 global
->p2p_invite_group
= NULL
;
5970 wpa_supplicant_deinit_iface(wpa_s
, 1, terminate
);
5973 if (mesh_if_created
) {
5974 wpa_drv_if_remove(parent
, WPA_IF_MESH
, ifname
);
5977 #endif /* CONFIG_MESH */
5984 * wpa_supplicant_get_eap_mode - Get the current EAP mode
5985 * @wpa_s: Pointer to the network interface
5986 * Returns: Pointer to the eap mode or the string "UNKNOWN" if not found
5988 const char * wpa_supplicant_get_eap_mode(struct wpa_supplicant
*wpa_s
)
5990 const char *eapol_method
;
5992 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) == 0 &&
5993 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
5997 eapol_method
= eapol_sm_get_method_name(wpa_s
->eapol
);
5998 if (eapol_method
== NULL
)
5999 return "UNKNOWN-EAP";
6001 return eapol_method
;
6006 * wpa_supplicant_get_iface - Get a new network interface
6007 * @global: Pointer to global data from wpa_supplicant_init()
6008 * @ifname: Interface name
6009 * Returns: Pointer to the interface or %NULL if not found
6011 struct wpa_supplicant
* wpa_supplicant_get_iface(struct wpa_global
*global
,
6014 struct wpa_supplicant
*wpa_s
;
6016 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6017 if (os_strcmp(wpa_s
->ifname
, ifname
) == 0)
6024 #ifndef CONFIG_NO_WPA_MSG
6025 static const char * wpa_supplicant_msg_ifname_cb(void *ctx
)
6027 struct wpa_supplicant
*wpa_s
= ctx
;
6030 return wpa_s
->ifname
;
6032 #endif /* CONFIG_NO_WPA_MSG */
6035 #ifndef WPA_SUPPLICANT_CLEANUP_INTERVAL
6036 #define WPA_SUPPLICANT_CLEANUP_INTERVAL 10
6037 #endif /* WPA_SUPPLICANT_CLEANUP_INTERVAL */
6039 /* Periodic cleanup tasks */
6040 static void wpas_periodic(void *eloop_ctx
, void *timeout_ctx
)
6042 struct wpa_global
*global
= eloop_ctx
;
6043 struct wpa_supplicant
*wpa_s
;
6045 eloop_register_timeout(WPA_SUPPLICANT_CLEANUP_INTERVAL
, 0,
6046 wpas_periodic
, global
, NULL
);
6050 p2p_expire_peers(global
->p2p
);
6051 #endif /* CONFIG_P2P */
6053 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6054 wpa_bss_flush_by_age(wpa_s
, wpa_s
->conf
->bss_expiration_age
);
6057 #endif /* CONFIG_AP */
6063 * wpa_supplicant_init - Initialize %wpa_supplicant
6064 * @params: Parameters for %wpa_supplicant
6065 * Returns: Pointer to global %wpa_supplicant data, or %NULL on failure
6067 * This function is used to initialize %wpa_supplicant. After successful
6068 * initialization, the returned data pointer can be used to add and remove
6069 * network interfaces, and eventually, to deinitialize %wpa_supplicant.
6071 struct wpa_global
* wpa_supplicant_init(struct wpa_params
*params
)
6073 struct wpa_global
*global
;
6079 #ifdef CONFIG_DRIVER_NDIS
6081 void driver_ndis_init_ops(void);
6082 driver_ndis_init_ops();
6084 #endif /* CONFIG_DRIVER_NDIS */
6086 #ifndef CONFIG_NO_WPA_MSG
6087 wpa_msg_register_ifname_cb(wpa_supplicant_msg_ifname_cb
);
6088 #endif /* CONFIG_NO_WPA_MSG */
6090 if (params
->wpa_debug_file_path
)
6091 wpa_debug_open_file(params
->wpa_debug_file_path
);
6093 wpa_debug_setup_stdout();
6094 if (params
->wpa_debug_syslog
)
6095 wpa_debug_open_syslog();
6096 if (params
->wpa_debug_tracing
) {
6097 ret
= wpa_debug_open_linux_tracing();
6099 wpa_printf(MSG_ERROR
,
6100 "Failed to enable trace logging");
6105 ret
= eap_register_methods();
6107 wpa_printf(MSG_ERROR
, "Failed to register EAP methods");
6109 wpa_printf(MSG_ERROR
, "Two or more EAP methods used "
6110 "the same EAP type.");
6114 global
= os_zalloc(sizeof(*global
));
6117 dl_list_init(&global
->p2p_srv_bonjour
);
6118 dl_list_init(&global
->p2p_srv_upnp
);
6119 global
->params
.daemonize
= params
->daemonize
;
6120 global
->params
.wait_for_monitor
= params
->wait_for_monitor
;
6121 global
->params
.dbus_ctrl_interface
= params
->dbus_ctrl_interface
;
6122 if (params
->pid_file
)
6123 global
->params
.pid_file
= os_strdup(params
->pid_file
);
6124 if (params
->ctrl_interface
)
6125 global
->params
.ctrl_interface
=
6126 os_strdup(params
->ctrl_interface
);
6127 if (params
->ctrl_interface_group
)
6128 global
->params
.ctrl_interface_group
=
6129 os_strdup(params
->ctrl_interface_group
);
6130 if (params
->override_driver
)
6131 global
->params
.override_driver
=
6132 os_strdup(params
->override_driver
);
6133 if (params
->override_ctrl_interface
)
6134 global
->params
.override_ctrl_interface
=
6135 os_strdup(params
->override_ctrl_interface
);
6136 #ifdef CONFIG_MATCH_IFACE
6137 global
->params
.match_iface_count
= params
->match_iface_count
;
6138 if (params
->match_iface_count
) {
6139 global
->params
.match_ifaces
=
6140 os_calloc(params
->match_iface_count
,
6141 sizeof(struct wpa_interface
));
6142 os_memcpy(global
->params
.match_ifaces
,
6143 params
->match_ifaces
,
6144 params
->match_iface_count
*
6145 sizeof(struct wpa_interface
));
6147 #endif /* CONFIG_MATCH_IFACE */
6149 if (params
->conf_p2p_dev
)
6150 global
->params
.conf_p2p_dev
=
6151 os_strdup(params
->conf_p2p_dev
);
6152 #endif /* CONFIG_P2P */
6153 wpa_debug_level
= global
->params
.wpa_debug_level
=
6154 params
->wpa_debug_level
;
6155 wpa_debug_show_keys
= global
->params
.wpa_debug_show_keys
=
6156 params
->wpa_debug_show_keys
;
6157 wpa_debug_timestamp
= global
->params
.wpa_debug_timestamp
=
6158 params
->wpa_debug_timestamp
;
6160 wpa_printf(MSG_DEBUG
, "wpa_supplicant v" VERSION_STR
);
6163 wpa_printf(MSG_ERROR
, "Failed to initialize event loop");
6164 wpa_supplicant_deinit(global
);
6168 random_init(params
->entropy_file
);
6170 global
->ctrl_iface
= wpa_supplicant_global_ctrl_iface_init(global
);
6171 if (global
->ctrl_iface
== NULL
) {
6172 wpa_supplicant_deinit(global
);
6176 if (wpas_notify_supplicant_initialized(global
)) {
6177 wpa_supplicant_deinit(global
);
6181 for (i
= 0; wpa_drivers
[i
]; i
++)
6182 global
->drv_count
++;
6183 if (global
->drv_count
== 0) {
6184 wpa_printf(MSG_ERROR
, "No drivers enabled");
6185 wpa_supplicant_deinit(global
);
6188 global
->drv_priv
= os_calloc(global
->drv_count
, sizeof(void *));
6189 if (global
->drv_priv
== NULL
) {
6190 wpa_supplicant_deinit(global
);
6194 #ifdef CONFIG_WIFI_DISPLAY
6195 if (wifi_display_init(global
) < 0) {
6196 wpa_printf(MSG_ERROR
, "Failed to initialize Wi-Fi Display");
6197 wpa_supplicant_deinit(global
);
6200 #endif /* CONFIG_WIFI_DISPLAY */
6202 eloop_register_timeout(WPA_SUPPLICANT_CLEANUP_INTERVAL
, 0,
6203 wpas_periodic
, global
, NULL
);
6210 * wpa_supplicant_run - Run the %wpa_supplicant main event loop
6211 * @global: Pointer to global data from wpa_supplicant_init()
6212 * Returns: 0 after successful event loop run, -1 on failure
6214 * This function starts the main event loop and continues running as long as
6215 * there are any remaining events. In most cases, this function is running as
6216 * long as the %wpa_supplicant process in still in use.
6218 int wpa_supplicant_run(struct wpa_global
*global
)
6220 struct wpa_supplicant
*wpa_s
;
6222 if (global
->params
.daemonize
&&
6223 (wpa_supplicant_daemon(global
->params
.pid_file
) ||
6224 eloop_sock_requeue()))
6227 #ifdef CONFIG_MATCH_IFACE
6228 if (wpa_supplicant_match_existing(global
))
6232 if (global
->params
.wait_for_monitor
) {
6233 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
)
6234 if (wpa_s
->ctrl_iface
&& !wpa_s
->p2p_mgmt
)
6235 wpa_supplicant_ctrl_iface_wait(
6239 eloop_register_signal_terminate(wpa_supplicant_terminate
, global
);
6240 eloop_register_signal_reconfig(wpa_supplicant_reconfig
, global
);
6249 * wpa_supplicant_deinit - Deinitialize %wpa_supplicant
6250 * @global: Pointer to global data from wpa_supplicant_init()
6252 * This function is called to deinitialize %wpa_supplicant and to free all
6253 * allocated resources. Remaining network interfaces will also be removed.
6255 void wpa_supplicant_deinit(struct wpa_global
*global
)
6262 eloop_cancel_timeout(wpas_periodic
, global
, NULL
);
6264 #ifdef CONFIG_WIFI_DISPLAY
6265 wifi_display_deinit(global
);
6266 #endif /* CONFIG_WIFI_DISPLAY */
6268 while (global
->ifaces
)
6269 wpa_supplicant_remove_iface(global
, global
->ifaces
, 1);
6271 if (global
->ctrl_iface
)
6272 wpa_supplicant_global_ctrl_iface_deinit(global
->ctrl_iface
);
6274 wpas_notify_supplicant_deinitialized(global
);
6276 eap_peer_unregister_methods();
6278 eap_server_unregister_methods();
6279 #endif /* CONFIG_AP */
6281 for (i
= 0; wpa_drivers
[i
] && global
->drv_priv
; i
++) {
6282 if (!global
->drv_priv
[i
])
6284 wpa_drivers
[i
]->global_deinit(global
->drv_priv
[i
]);
6286 os_free(global
->drv_priv
);
6292 if (global
->params
.pid_file
) {
6293 os_daemonize_terminate(global
->params
.pid_file
);
6294 os_free(global
->params
.pid_file
);
6296 os_free(global
->params
.ctrl_interface
);
6297 os_free(global
->params
.ctrl_interface_group
);
6298 os_free(global
->params
.override_driver
);
6299 os_free(global
->params
.override_ctrl_interface
);
6300 #ifdef CONFIG_MATCH_IFACE
6301 os_free(global
->params
.match_ifaces
);
6302 #endif /* CONFIG_MATCH_IFACE */
6304 os_free(global
->params
.conf_p2p_dev
);
6305 #endif /* CONFIG_P2P */
6307 os_free(global
->p2p_disallow_freq
.range
);
6308 os_free(global
->p2p_go_avoid_freq
.range
);
6309 os_free(global
->add_psk
);
6312 wpa_debug_close_syslog();
6313 wpa_debug_close_file();
6314 wpa_debug_close_linux_tracing();
6318 void wpa_supplicant_update_config(struct wpa_supplicant
*wpa_s
)
6320 if ((wpa_s
->conf
->changed_parameters
& CFG_CHANGED_COUNTRY
) &&
6321 wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1]) {
6323 country
[0] = wpa_s
->conf
->country
[0];
6324 country
[1] = wpa_s
->conf
->country
[1];
6326 if (wpa_drv_set_country(wpa_s
, country
) < 0) {
6327 wpa_printf(MSG_ERROR
, "Failed to set country code "
6332 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_EXT_PW_BACKEND
)
6333 wpas_init_ext_pw(wpa_s
);
6335 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_SCHED_SCAN_PLANS
)
6336 wpas_sched_scan_plans_set(wpa_s
, wpa_s
->conf
->sched_scan_plans
);
6338 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_WOWLAN_TRIGGERS
) {
6339 struct wpa_driver_capa capa
;
6340 int res
= wpa_drv_get_capa(wpa_s
, &capa
);
6342 if (res
== 0 && wpas_set_wowlan_triggers(wpa_s
, &capa
) < 0)
6343 wpa_printf(MSG_ERROR
,
6344 "Failed to update wowlan_triggers to '%s'",
6345 wpa_s
->conf
->wowlan_triggers
);
6349 wpas_wps_update_config(wpa_s
);
6350 #endif /* CONFIG_WPS */
6351 wpas_p2p_update_config(wpa_s
);
6352 wpa_s
->conf
->changed_parameters
= 0;
6356 void add_freq(int *freqs
, int *num_freqs
, int freq
)
6360 for (i
= 0; i
< *num_freqs
; i
++) {
6361 if (freqs
[i
] == freq
)
6365 freqs
[*num_freqs
] = freq
;
6370 static int * get_bss_freqs_in_ess(struct wpa_supplicant
*wpa_s
)
6372 struct wpa_bss
*bss
, *cbss
;
6373 const int max_freqs
= 10;
6377 freqs
= os_calloc(max_freqs
+ 1, sizeof(int));
6381 cbss
= wpa_s
->current_bss
;
6383 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
6386 if (bss
->ssid_len
== cbss
->ssid_len
&&
6387 os_memcmp(bss
->ssid
, cbss
->ssid
, bss
->ssid_len
) == 0 &&
6388 wpa_blacklist_get(wpa_s
, bss
->bssid
) == NULL
) {
6389 add_freq(freqs
, &num_freqs
, bss
->freq
);
6390 if (num_freqs
== max_freqs
)
6395 if (num_freqs
== 0) {
6404 void wpas_connection_failed(struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
6410 wpas_connect_work_done(wpa_s
);
6413 * Remove possible authentication timeout since the connection failed.
6415 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
6418 * There is no point in blacklisting the AP if this event is
6419 * generated based on local request to disconnect.
6421 if (wpa_s
->own_disconnect_req
) {
6422 wpa_s
->own_disconnect_req
= 0;
6423 wpa_dbg(wpa_s
, MSG_DEBUG
,
6424 "Ignore connection failure due to local request to disconnect");
6427 if (wpa_s
->disconnected
) {
6428 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore connection failure "
6429 "indication since interface has been put into "
6430 "disconnected state");
6435 * Add the failed BSSID into the blacklist and speed up next scan
6436 * attempt if there could be other APs that could accept association.
6437 * The current blacklist count indicates how many times we have tried
6438 * connecting to this AP and multiple attempts mean that other APs are
6439 * either not available or has already been tried, so that we can start
6440 * increasing the delay here to avoid constant scanning.
6442 count
= wpa_blacklist_add(wpa_s
, bssid
);
6443 if (count
== 1 && wpa_s
->current_bss
) {
6445 * This BSS was not in the blacklist before. If there is
6446 * another BSS available for the same ESS, we should try that
6447 * next. Otherwise, we may as well try this one once more
6448 * before allowing other, likely worse, ESSes to be considered.
6450 freqs
= get_bss_freqs_in_ess(wpa_s
);
6452 wpa_dbg(wpa_s
, MSG_DEBUG
, "Another BSS in this ESS "
6453 "has been seen; try it next");
6454 wpa_blacklist_add(wpa_s
, bssid
);
6456 * On the next scan, go through only the known channels
6457 * used in this ESS based on previous scans to speed up
6458 * common load balancing use case.
6460 os_free(wpa_s
->next_scan_freqs
);
6461 wpa_s
->next_scan_freqs
= freqs
;
6466 * Add previous failure count in case the temporary blacklist was
6467 * cleared due to no other BSSes being available.
6469 count
+= wpa_s
->extra_blacklist_count
;
6471 if (count
> 3 && wpa_s
->current_ssid
) {
6472 wpa_printf(MSG_DEBUG
, "Continuous association failures - "
6473 "consider temporary network disabling");
6474 wpas_auth_failed(wpa_s
, "CONN_FAILED");
6495 wpa_dbg(wpa_s
, MSG_DEBUG
, "Blacklist count %d --> request scan in %d "
6496 "ms", count
, timeout
);
6499 * TODO: if more than one possible AP is available in scan results,
6500 * could try the other ones before requesting a new scan.
6502 wpa_supplicant_req_scan(wpa_s
, timeout
/ 1000,
6503 1000 * (timeout
% 1000));
6507 int wpas_driver_bss_selection(struct wpa_supplicant
*wpa_s
)
6509 return wpa_s
->conf
->ap_scan
== 2 ||
6510 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_BSS_SELECTION
);
6514 #if defined(CONFIG_CTRL_IFACE) || defined(CONFIG_CTRL_IFACE_DBUS_NEW)
6515 int wpa_supplicant_ctrl_iface_ctrl_rsp_handle(struct wpa_supplicant
*wpa_s
,
6516 struct wpa_ssid
*ssid
,
6520 #ifdef IEEE8021X_EAPOL
6521 struct eap_peer_config
*eap
= &ssid
->eap
;
6523 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: response handle field=%s", field
);
6524 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: response value",
6525 (const u8
*) value
, os_strlen(value
));
6527 switch (wpa_supplicant_ctrl_req_from_string(field
)) {
6528 case WPA_CTRL_REQ_EAP_IDENTITY
:
6529 os_free(eap
->identity
);
6530 eap
->identity
= (u8
*) os_strdup(value
);
6531 eap
->identity_len
= os_strlen(value
);
6532 eap
->pending_req_identity
= 0;
6533 if (ssid
== wpa_s
->current_ssid
)
6534 wpa_s
->reassociate
= 1;
6536 case WPA_CTRL_REQ_EAP_PASSWORD
:
6537 bin_clear_free(eap
->password
, eap
->password_len
);
6538 eap
->password
= (u8
*) os_strdup(value
);
6539 eap
->password_len
= os_strlen(value
);
6540 eap
->pending_req_password
= 0;
6541 if (ssid
== wpa_s
->current_ssid
)
6542 wpa_s
->reassociate
= 1;
6544 case WPA_CTRL_REQ_EAP_NEW_PASSWORD
:
6545 bin_clear_free(eap
->new_password
, eap
->new_password_len
);
6546 eap
->new_password
= (u8
*) os_strdup(value
);
6547 eap
->new_password_len
= os_strlen(value
);
6548 eap
->pending_req_new_password
= 0;
6549 if (ssid
== wpa_s
->current_ssid
)
6550 wpa_s
->reassociate
= 1;
6552 case WPA_CTRL_REQ_EAP_PIN
:
6553 str_clear_free(eap
->pin
);
6554 eap
->pin
= os_strdup(value
);
6555 eap
->pending_req_pin
= 0;
6556 if (ssid
== wpa_s
->current_ssid
)
6557 wpa_s
->reassociate
= 1;
6559 case WPA_CTRL_REQ_EAP_OTP
:
6560 bin_clear_free(eap
->otp
, eap
->otp_len
);
6561 eap
->otp
= (u8
*) os_strdup(value
);
6562 eap
->otp_len
= os_strlen(value
);
6563 os_free(eap
->pending_req_otp
);
6564 eap
->pending_req_otp
= NULL
;
6565 eap
->pending_req_otp_len
= 0;
6567 case WPA_CTRL_REQ_EAP_PASSPHRASE
:
6568 str_clear_free(eap
->private_key_passwd
);
6569 eap
->private_key_passwd
= os_strdup(value
);
6570 eap
->pending_req_passphrase
= 0;
6571 if (ssid
== wpa_s
->current_ssid
)
6572 wpa_s
->reassociate
= 1;
6574 case WPA_CTRL_REQ_SIM
:
6575 str_clear_free(eap
->external_sim_resp
);
6576 eap
->external_sim_resp
= os_strdup(value
);
6577 eap
->pending_req_sim
= 0;
6579 case WPA_CTRL_REQ_PSK_PASSPHRASE
:
6580 if (wpa_config_set(ssid
, "psk", value
, 0) < 0)
6582 ssid
->mem_only_psk
= 1;
6583 if (ssid
->passphrase
)
6584 wpa_config_update_psk(ssid
);
6585 if (wpa_s
->wpa_state
== WPA_SCANNING
&& !wpa_s
->scanning
)
6586 wpa_supplicant_req_scan(wpa_s
, 0, 0);
6588 case WPA_CTRL_REQ_EXT_CERT_CHECK
:
6589 if (eap
->pending_ext_cert_check
!= PENDING_CHECK
)
6591 if (os_strcmp(value
, "good") == 0)
6592 eap
->pending_ext_cert_check
= EXT_CERT_CHECK_GOOD
;
6593 else if (os_strcmp(value
, "bad") == 0)
6594 eap
->pending_ext_cert_check
= EXT_CERT_CHECK_BAD
;
6599 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown field '%s'", field
);
6604 #else /* IEEE8021X_EAPOL */
6605 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: IEEE 802.1X not included");
6607 #endif /* IEEE8021X_EAPOL */
6609 #endif /* CONFIG_CTRL_IFACE || CONFIG_CTRL_IFACE_DBUS_NEW */
6612 int wpas_network_disabled(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
)
6615 unsigned int drv_enc
;
6617 if (wpa_s
->p2p_mgmt
)
6618 return 1; /* no normal network profiles on p2p_mgmt interface */
6626 if (wpa_s
->drv_capa_known
)
6627 drv_enc
= wpa_s
->drv_enc
;
6629 drv_enc
= (unsigned int) -1;
6631 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
6632 size_t len
= ssid
->wep_key_len
[i
];
6635 if (len
== 5 && (drv_enc
& WPA_DRIVER_CAPA_ENC_WEP40
))
6637 if (len
== 13 && (drv_enc
& WPA_DRIVER_CAPA_ENC_WEP104
))
6639 if (len
== 16 && (drv_enc
& WPA_DRIVER_CAPA_ENC_WEP128
))
6641 return 1; /* invalid WEP key */
6644 if (wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) && !ssid
->psk_set
&&
6645 (!ssid
->passphrase
|| ssid
->ssid_len
!= 0) && !ssid
->ext_psk
&&
6646 !(wpa_key_mgmt_sae(ssid
->key_mgmt
) && ssid
->sae_password
) &&
6647 !ssid
->mem_only_psk
)
6654 int wpas_get_ssid_pmf(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
)
6656 #ifdef CONFIG_IEEE80211W
6657 if (ssid
== NULL
|| ssid
->ieee80211w
== MGMT_FRAME_PROTECTION_DEFAULT
) {
6658 if (wpa_s
->conf
->pmf
== MGMT_FRAME_PROTECTION_OPTIONAL
&&
6659 !(wpa_s
->drv_enc
& WPA_DRIVER_CAPA_ENC_BIP
)) {
6661 * Driver does not support BIP -- ignore pmf=1 default
6662 * since the connection with PMF would fail and the
6663 * configuration does not require PMF to be enabled.
6665 return NO_MGMT_FRAME_PROTECTION
;
6670 ~(WPA_KEY_MGMT_NONE
| WPA_KEY_MGMT_WPS
|
6671 WPA_KEY_MGMT_IEEE8021X_NO_WPA
)) == 0) {
6673 * Do not use the default PMF value for non-RSN networks
6674 * since PMF is available only with RSN and pmf=2
6675 * configuration would otherwise prevent connections to
6676 * all open networks.
6678 return NO_MGMT_FRAME_PROTECTION
;
6681 return wpa_s
->conf
->pmf
;
6684 return ssid
->ieee80211w
;
6685 #else /* CONFIG_IEEE80211W */
6686 return NO_MGMT_FRAME_PROTECTION
;
6687 #endif /* CONFIG_IEEE80211W */
6691 int wpas_is_p2p_prioritized(struct wpa_supplicant
*wpa_s
)
6693 if (wpa_s
->global
->conc_pref
== WPA_CONC_PREF_P2P
)
6695 if (wpa_s
->global
->conc_pref
== WPA_CONC_PREF_STA
)
6701 void wpas_auth_failed(struct wpa_supplicant
*wpa_s
, char *reason
)
6703 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
6705 struct os_reltime now
;
6708 wpa_printf(MSG_DEBUG
, "Authentication failure but no known "
6713 if (ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
)
6716 ssid
->auth_failures
++;
6719 if (ssid
->p2p_group
&&
6720 (wpa_s
->p2p_in_provisioning
|| wpa_s
->show_group_started
)) {
6722 * Skip the wait time since there is a short timeout on the
6723 * connection to a P2P group.
6727 #endif /* CONFIG_P2P */
6729 if (ssid
->auth_failures
> 50)
6731 else if (ssid
->auth_failures
> 10)
6733 else if (ssid
->auth_failures
> 5)
6735 else if (ssid
->auth_failures
> 3)
6737 else if (ssid
->auth_failures
> 2)
6739 else if (ssid
->auth_failures
> 1)
6744 if (ssid
->auth_failures
> 1 &&
6745 wpa_key_mgmt_wpa_ieee8021x(ssid
->key_mgmt
))
6746 dur
+= os_random() % (ssid
->auth_failures
* 10);
6748 os_get_reltime(&now
);
6749 if (now
.sec
+ dur
<= ssid
->disabled_until
.sec
)
6752 ssid
->disabled_until
.sec
= now
.sec
+ dur
;
6754 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_TEMP_DISABLED
6755 "id=%d ssid=\"%s\" auth_failures=%u duration=%d reason=%s",
6756 ssid
->id
, wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
),
6757 ssid
->auth_failures
, dur
, reason
);
6761 void wpas_clear_temp_disabled(struct wpa_supplicant
*wpa_s
,
6762 struct wpa_ssid
*ssid
, int clear_failures
)
6767 if (ssid
->disabled_until
.sec
) {
6768 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_REENABLED
6769 "id=%d ssid=\"%s\"",
6770 ssid
->id
, wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
6772 ssid
->disabled_until
.sec
= 0;
6773 ssid
->disabled_until
.usec
= 0;
6775 ssid
->auth_failures
= 0;
6779 int disallowed_bssid(struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
6783 if (wpa_s
->disallow_aps_bssid
== NULL
)
6786 for (i
= 0; i
< wpa_s
->disallow_aps_bssid_count
; i
++) {
6787 if (os_memcmp(wpa_s
->disallow_aps_bssid
+ i
* ETH_ALEN
,
6788 bssid
, ETH_ALEN
) == 0)
6796 int disallowed_ssid(struct wpa_supplicant
*wpa_s
, const u8
*ssid
,
6801 if (wpa_s
->disallow_aps_ssid
== NULL
|| ssid
== NULL
)
6804 for (i
= 0; i
< wpa_s
->disallow_aps_ssid_count
; i
++) {
6805 struct wpa_ssid_value
*s
= &wpa_s
->disallow_aps_ssid
[i
];
6806 if (ssid_len
== s
->ssid_len
&&
6807 os_memcmp(ssid
, s
->ssid
, ssid_len
) == 0)
6816 * wpas_request_connection - Request a new connection
6817 * @wpa_s: Pointer to the network interface
6819 * This function is used to request a new connection to be found. It will mark
6820 * the interface to allow reassociation and request a new scan to find a
6821 * suitable network to connect to.
6823 void wpas_request_connection(struct wpa_supplicant
*wpa_s
)
6825 wpa_s
->normal_scans
= 0;
6826 wpa_s
->scan_req
= NORMAL_SCAN_REQ
;
6827 wpa_supplicant_reinit_autoscan(wpa_s
);
6828 wpa_s
->extra_blacklist_count
= 0;
6829 wpa_s
->disconnected
= 0;
6830 wpa_s
->reassociate
= 1;
6831 wpa_s
->last_owe_group
= 0;
6833 if (wpa_supplicant_fast_associate(wpa_s
) != 1)
6834 wpa_supplicant_req_scan(wpa_s
, 0, 0);
6836 wpa_s
->reattach
= 0;
6841 * wpas_request_disconnection - Request disconnection
6842 * @wpa_s: Pointer to the network interface
6844 * This function is used to request disconnection from the currently connected
6845 * network. This will stop any ongoing scans and initiate deauthentication.
6847 void wpas_request_disconnection(struct wpa_supplicant
*wpa_s
)
6850 wpa_s
->sme
.prev_bssid_set
= 0;
6851 #endif /* CONFIG_SME */
6852 wpa_s
->reassociate
= 0;
6853 wpa_s
->disconnected
= 1;
6854 wpa_supplicant_cancel_sched_scan(wpa_s
);
6855 wpa_supplicant_cancel_scan(wpa_s
);
6856 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
6857 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
6861 void dump_freq_data(struct wpa_supplicant
*wpa_s
, const char *title
,
6862 struct wpa_used_freq_data
*freqs_data
,
6867 wpa_dbg(wpa_s
, MSG_DEBUG
, "Shared frequencies (len=%u): %s",
6869 for (i
= 0; i
< len
; i
++) {
6870 struct wpa_used_freq_data
*cur
= &freqs_data
[i
];
6871 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq[%u]: %d, flags=0x%X",
6872 i
, cur
->freq
, cur
->flags
);
6878 * Find the operating frequencies of any of the virtual interfaces that
6879 * are using the same radio as the current interface, and in addition, get
6880 * information about the interface types that are using the frequency.
6882 int get_shared_radio_freqs_data(struct wpa_supplicant
*wpa_s
,
6883 struct wpa_used_freq_data
*freqs_data
,
6886 struct wpa_supplicant
*ifs
;
6889 unsigned int idx
= 0, i
;
6891 wpa_dbg(wpa_s
, MSG_DEBUG
,
6892 "Determining shared radio frequencies (max len %u)", len
);
6893 os_memset(freqs_data
, 0, sizeof(struct wpa_used_freq_data
) * len
);
6895 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
6900 if (ifs
->current_ssid
== NULL
|| ifs
->assoc_freq
== 0)
6903 if (ifs
->current_ssid
->mode
== WPAS_MODE_AP
||
6904 ifs
->current_ssid
->mode
== WPAS_MODE_P2P_GO
||
6905 ifs
->current_ssid
->mode
== WPAS_MODE_MESH
)
6906 freq
= ifs
->current_ssid
->frequency
;
6907 else if (wpa_drv_get_bssid(ifs
, bssid
) == 0)
6908 freq
= ifs
->assoc_freq
;
6912 /* Hold only distinct freqs */
6913 for (i
= 0; i
< idx
; i
++)
6914 if (freqs_data
[i
].freq
== freq
)
6918 freqs_data
[idx
++].freq
= freq
;
6920 if (ifs
->current_ssid
->mode
== WPAS_MODE_INFRA
) {
6921 freqs_data
[i
].flags
|= ifs
->current_ssid
->p2p_group
?
6922 WPA_FREQ_USED_BY_P2P_CLIENT
:
6923 WPA_FREQ_USED_BY_INFRA_STATION
;
6927 dump_freq_data(wpa_s
, "completed iteration", freqs_data
, idx
);
6933 * Find the operating frequencies of any of the virtual interfaces that
6934 * are using the same radio as the current interface.
6936 int get_shared_radio_freqs(struct wpa_supplicant
*wpa_s
,
6937 int *freq_array
, unsigned int len
)
6939 struct wpa_used_freq_data
*freqs_data
;
6942 os_memset(freq_array
, 0, sizeof(int) * len
);
6944 freqs_data
= os_calloc(len
, sizeof(struct wpa_used_freq_data
));
6948 num
= get_shared_radio_freqs_data(wpa_s
, freqs_data
, len
);
6949 for (i
= 0; i
< num
; i
++)
6950 freq_array
[i
] = freqs_data
[i
].freq
;
6952 os_free(freqs_data
);
6958 struct wpa_supplicant
*
6959 wpas_vendor_elem(struct wpa_supplicant
*wpa_s
, enum wpa_vendor_elem_frame frame
)
6963 case VENDOR_ELEM_PROBE_REQ_P2P
:
6964 case VENDOR_ELEM_PROBE_RESP_P2P
:
6965 case VENDOR_ELEM_PROBE_RESP_P2P_GO
:
6966 case VENDOR_ELEM_BEACON_P2P_GO
:
6967 case VENDOR_ELEM_P2P_PD_REQ
:
6968 case VENDOR_ELEM_P2P_PD_RESP
:
6969 case VENDOR_ELEM_P2P_GO_NEG_REQ
:
6970 case VENDOR_ELEM_P2P_GO_NEG_RESP
:
6971 case VENDOR_ELEM_P2P_GO_NEG_CONF
:
6972 case VENDOR_ELEM_P2P_INV_REQ
:
6973 case VENDOR_ELEM_P2P_INV_RESP
:
6974 case VENDOR_ELEM_P2P_ASSOC_REQ
:
6975 case VENDOR_ELEM_P2P_ASSOC_RESP
:
6976 return wpa_s
->p2pdev
;
6977 #endif /* CONFIG_P2P */
6984 void wpas_vendor_elem_update(struct wpa_supplicant
*wpa_s
)
6989 wpa_printf(MSG_DEBUG
, "Update vendor elements");
6991 for (i
= 0; i
< NUM_VENDOR_ELEM_FRAMES
; i
++) {
6992 if (wpa_s
->vendor_elem
[i
]) {
6995 res
= os_snprintf(buf
, sizeof(buf
), "frame[%u]", i
);
6996 if (!os_snprintf_error(sizeof(buf
), res
)) {
6997 wpa_hexdump_buf(MSG_DEBUG
, buf
,
6998 wpa_s
->vendor_elem
[i
]);
7004 if (wpa_s
->parent
== wpa_s
&&
7005 wpa_s
->global
->p2p
&&
7006 !wpa_s
->global
->p2p_disabled
)
7007 p2p_set_vendor_elems(wpa_s
->global
->p2p
, wpa_s
->vendor_elem
);
7008 #endif /* CONFIG_P2P */
7012 int wpas_vendor_elem_remove(struct wpa_supplicant
*wpa_s
, int frame
,
7013 const u8
*elem
, size_t len
)
7017 ie
= wpabuf_mhead_u8(wpa_s
->vendor_elem
[frame
]);
7018 end
= ie
+ wpabuf_len(wpa_s
->vendor_elem
[frame
]);
7020 for (; ie
+ 1 < end
; ie
+= 2 + ie
[1]) {
7023 if (os_memcmp(ie
, elem
, len
) != 0)
7026 if (wpabuf_len(wpa_s
->vendor_elem
[frame
]) == len
) {
7027 wpabuf_free(wpa_s
->vendor_elem
[frame
]);
7028 wpa_s
->vendor_elem
[frame
] = NULL
;
7030 os_memmove(ie
, ie
+ len
, end
- (ie
+ len
));
7031 wpa_s
->vendor_elem
[frame
]->used
-= len
;
7033 wpas_vendor_elem_update(wpa_s
);
7041 struct hostapd_hw_modes
* get_mode(struct hostapd_hw_modes
*modes
,
7042 u16 num_modes
, enum hostapd_hw_mode mode
)
7046 for (i
= 0; i
< num_modes
; i
++) {
7047 if (modes
[i
].mode
== mode
)
7056 wpa_bss_tmp_disallowed
* wpas_get_disallowed_bss(struct wpa_supplicant
*wpa_s
,
7059 struct wpa_bss_tmp_disallowed
*bss
;
7061 dl_list_for_each(bss
, &wpa_s
->bss_tmp_disallowed
,
7062 struct wpa_bss_tmp_disallowed
, list
) {
7063 if (os_memcmp(bssid
, bss
->bssid
, ETH_ALEN
) == 0)
7071 static int wpa_set_driver_tmp_disallow_list(struct wpa_supplicant
*wpa_s
)
7073 struct wpa_bss_tmp_disallowed
*tmp
;
7074 unsigned int num_bssid
= 0;
7078 bssids
= os_malloc(dl_list_len(&wpa_s
->bss_tmp_disallowed
) * ETH_ALEN
);
7081 dl_list_for_each(tmp
, &wpa_s
->bss_tmp_disallowed
,
7082 struct wpa_bss_tmp_disallowed
, list
) {
7083 os_memcpy(&bssids
[num_bssid
* ETH_ALEN
], tmp
->bssid
,
7087 ret
= wpa_drv_set_bssid_blacklist(wpa_s
, num_bssid
, bssids
);
7093 static void wpa_bss_tmp_disallow_timeout(void *eloop_ctx
, void *timeout_ctx
)
7095 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
7096 struct wpa_bss_tmp_disallowed
*tmp
, *bss
= timeout_ctx
;
7098 /* Make sure the bss is not already freed */
7099 dl_list_for_each(tmp
, &wpa_s
->bss_tmp_disallowed
,
7100 struct wpa_bss_tmp_disallowed
, list
) {
7102 dl_list_del(&tmp
->list
);
7104 wpa_set_driver_tmp_disallow_list(wpa_s
);
7111 void wpa_bss_tmp_disallow(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
7114 struct wpa_bss_tmp_disallowed
*bss
;
7116 bss
= wpas_get_disallowed_bss(wpa_s
, bssid
);
7118 eloop_cancel_timeout(wpa_bss_tmp_disallow_timeout
, wpa_s
, bss
);
7119 eloop_register_timeout(sec
, 0, wpa_bss_tmp_disallow_timeout
,
7124 bss
= os_malloc(sizeof(*bss
));
7126 wpa_printf(MSG_DEBUG
,
7127 "Failed to allocate memory for temp disallow BSS");
7131 os_memcpy(bss
->bssid
, bssid
, ETH_ALEN
);
7132 dl_list_add(&wpa_s
->bss_tmp_disallowed
, &bss
->list
);
7133 wpa_set_driver_tmp_disallow_list(wpa_s
);
7134 eloop_register_timeout(sec
, 0, wpa_bss_tmp_disallow_timeout
,
7139 int wpa_is_bss_tmp_disallowed(struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
7141 struct wpa_bss_tmp_disallowed
*bss
= NULL
, *tmp
, *prev
;
7143 dl_list_for_each_safe(tmp
, prev
, &wpa_s
->bss_tmp_disallowed
,
7144 struct wpa_bss_tmp_disallowed
, list
) {
7145 if (os_memcmp(bssid
, tmp
->bssid
, ETH_ALEN
) == 0) {