3 * Copyright (c) 2003-2014, 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.
16 #include "crypto/random.h"
17 #include "crypto/sha1.h"
18 #include "eapol_supp/eapol_supp_sm.h"
19 #include "eap_peer/eap.h"
20 #include "eap_peer/eap_proxy.h"
21 #include "eap_server/eap_methods.h"
22 #include "rsn_supp/wpa.h"
25 #include "utils/ext_password.h"
26 #include "l2_packet/l2_packet.h"
27 #include "wpa_supplicant_i.h"
29 #include "ctrl_iface.h"
30 #include "pcsc_funcs.h"
31 #include "common/version.h"
32 #include "rsn_supp/preauth.h"
33 #include "rsn_supp/pmksa_cache.h"
34 #include "common/wpa_ctrl.h"
35 #include "common/ieee802_11_defs.h"
37 #include "blacklist.h"
38 #include "wpas_glue.h"
39 #include "wps_supplicant.h"
42 #include "gas_query.h"
44 #include "p2p_supplicant.h"
45 #include "wifi_display.h"
51 #include "offchannel.h"
52 #include "hs20_supplicant.h"
57 const char *wpa_supplicant_version
=
58 "wpa_supplicant v" VERSION_STR
"\n"
59 "Copyright (c) 2003-2014, Jouni Malinen <j@w1.fi> and contributors";
61 const char *wpa_supplicant_license
=
62 "This software may be distributed under the terms of the BSD license.\n"
63 "See README for more details.\n"
64 #ifdef EAP_TLS_OPENSSL
65 "\nThis product includes software developed by the OpenSSL Project\n"
66 "for use in the OpenSSL Toolkit (http://www.openssl.org/)\n"
67 #endif /* EAP_TLS_OPENSSL */
70 #ifndef CONFIG_NO_STDOUT_DEBUG
71 /* Long text divided into parts in order to fit in C89 strings size limits. */
72 const char *wpa_supplicant_full_license1
=
74 const char *wpa_supplicant_full_license2
=
75 "This software may be distributed under the terms of the BSD license.\n"
77 "Redistribution and use in source and binary forms, with or without\n"
78 "modification, are permitted provided that the following conditions are\n"
81 const char *wpa_supplicant_full_license3
=
82 "1. Redistributions of source code must retain the above copyright\n"
83 " notice, this list of conditions and the following disclaimer.\n"
85 "2. Redistributions in binary form must reproduce the above copyright\n"
86 " notice, this list of conditions and the following disclaimer in the\n"
87 " documentation and/or other materials provided with the distribution.\n"
89 const char *wpa_supplicant_full_license4
=
90 "3. Neither the name(s) of the above-listed copyright holder(s) nor the\n"
91 " names of its contributors may be used to endorse or promote products\n"
92 " derived from this software without specific prior written permission.\n"
94 "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n"
95 "\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n"
96 "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n"
97 "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n";
98 const char *wpa_supplicant_full_license5
=
99 "OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n"
100 "SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n"
101 "LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n"
102 "DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n"
103 "THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n"
104 "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n"
105 "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
107 #endif /* CONFIG_NO_STDOUT_DEBUG */
109 /* Configure default/group WEP keys for static WEP */
110 int wpa_set_wep_keys(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
)
114 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
115 if (ssid
->wep_key_len
[i
] == 0)
119 wpa_drv_set_key(wpa_s
, WPA_ALG_WEP
, NULL
,
120 i
, i
== ssid
->wep_tx_keyidx
, NULL
, 0,
121 ssid
->wep_key
[i
], ssid
->wep_key_len
[i
]);
128 int wpa_supplicant_set_wpa_none_key(struct wpa_supplicant
*wpa_s
,
129 struct wpa_ssid
*ssid
)
136 /* IBSS/WPA-None uses only one key (Group) for both receiving and
137 * sending unicast and multicast packets. */
139 if (ssid
->mode
!= WPAS_MODE_IBSS
) {
140 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Invalid mode %d (not "
141 "IBSS/ad-hoc) for WPA-None", ssid
->mode
);
145 if (!ssid
->psk_set
) {
146 wpa_msg(wpa_s
, MSG_INFO
, "WPA: No PSK configured for "
151 switch (wpa_s
->group_cipher
) {
152 case WPA_CIPHER_CCMP
:
153 os_memcpy(key
, ssid
->psk
, 16);
157 case WPA_CIPHER_GCMP
:
158 os_memcpy(key
, ssid
->psk
, 16);
162 case WPA_CIPHER_TKIP
:
163 /* WPA-None uses the same Michael MIC key for both TX and RX */
164 os_memcpy(key
, ssid
->psk
, 16 + 8);
165 os_memcpy(key
+ 16 + 8, ssid
->psk
+ 16, 8);
170 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Invalid group cipher %d for "
171 "WPA-None", wpa_s
->group_cipher
);
175 /* TODO: should actually remember the previously used seq#, both for TX
176 * and RX from each STA.. */
178 return wpa_drv_set_key(wpa_s
, alg
, NULL
, 0, 1, seq
, 6, key
, keylen
);
182 static void wpa_supplicant_timeout(void *eloop_ctx
, void *timeout_ctx
)
184 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
185 const u8
*bssid
= wpa_s
->bssid
;
186 if (is_zero_ether_addr(bssid
))
187 bssid
= wpa_s
->pending_bssid
;
188 wpa_msg(wpa_s
, MSG_INFO
, "Authentication with " MACSTR
" timed out.",
190 wpa_blacklist_add(wpa_s
, bssid
);
191 wpa_sm_notify_disassoc(wpa_s
->wpa
);
192 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
193 wpa_s
->reassociate
= 1;
196 * If we timed out, the AP or the local radio may be busy.
197 * So, wait a second until scanning again.
199 wpa_supplicant_req_scan(wpa_s
, 1, 0);
204 * wpa_supplicant_req_auth_timeout - Schedule a timeout for authentication
205 * @wpa_s: Pointer to wpa_supplicant data
206 * @sec: Number of seconds after which to time out authentication
207 * @usec: Number of microseconds after which to time out authentication
209 * This function is used to schedule a timeout for the current authentication
212 void wpa_supplicant_req_auth_timeout(struct wpa_supplicant
*wpa_s
,
215 if (wpa_s
->conf
->ap_scan
== 0 &&
216 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
))
219 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setting authentication timeout: %d sec "
220 "%d usec", sec
, usec
);
221 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
222 eloop_register_timeout(sec
, usec
, wpa_supplicant_timeout
, wpa_s
, NULL
);
227 * wpa_supplicant_cancel_auth_timeout - Cancel authentication timeout
228 * @wpa_s: Pointer to wpa_supplicant data
230 * This function is used to cancel authentication timeout scheduled with
231 * wpa_supplicant_req_auth_timeout() and it is called when authentication has
234 void wpa_supplicant_cancel_auth_timeout(struct wpa_supplicant
*wpa_s
)
236 wpa_dbg(wpa_s
, MSG_DEBUG
, "Cancelling authentication timeout");
237 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
238 wpa_blacklist_del(wpa_s
, wpa_s
->bssid
);
243 * wpa_supplicant_initiate_eapol - Configure EAPOL state machine
244 * @wpa_s: Pointer to wpa_supplicant data
246 * This function is used to configure EAPOL state machine based on the selected
247 * authentication mode.
249 void wpa_supplicant_initiate_eapol(struct wpa_supplicant
*wpa_s
)
251 #ifdef IEEE8021X_EAPOL
252 struct eapol_config eapol_conf
;
253 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
255 #ifdef CONFIG_IBSS_RSN
256 if (ssid
->mode
== WPAS_MODE_IBSS
&&
257 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
258 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
) {
260 * RSN IBSS authentication is per-STA and we can disable the
261 * per-BSSID EAPOL authentication.
263 eapol_sm_notify_portControl(wpa_s
->eapol
, ForceAuthorized
);
264 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
265 eapol_sm_notify_eap_fail(wpa_s
->eapol
, FALSE
);
268 #endif /* CONFIG_IBSS_RSN */
270 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
271 eapol_sm_notify_eap_fail(wpa_s
->eapol
, FALSE
);
273 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
274 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
275 eapol_sm_notify_portControl(wpa_s
->eapol
, ForceAuthorized
);
277 eapol_sm_notify_portControl(wpa_s
->eapol
, Auto
);
279 os_memset(&eapol_conf
, 0, sizeof(eapol_conf
));
280 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
281 eapol_conf
.accept_802_1x_keys
= 1;
282 eapol_conf
.required_keys
= 0;
283 if (ssid
->eapol_flags
& EAPOL_FLAG_REQUIRE_KEY_UNICAST
) {
284 eapol_conf
.required_keys
|= EAPOL_REQUIRE_KEY_UNICAST
;
286 if (ssid
->eapol_flags
& EAPOL_FLAG_REQUIRE_KEY_BROADCAST
) {
287 eapol_conf
.required_keys
|=
288 EAPOL_REQUIRE_KEY_BROADCAST
;
291 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
)
292 eapol_conf
.required_keys
= 0;
294 eapol_conf
.fast_reauth
= wpa_s
->conf
->fast_reauth
;
295 eapol_conf
.workaround
= ssid
->eap_workaround
;
296 eapol_conf
.eap_disabled
=
297 !wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) &&
298 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
299 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPS
;
300 eapol_conf
.external_sim
= wpa_s
->conf
->external_sim
;
303 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
) {
304 eapol_conf
.wps
|= EAPOL_LOCAL_WPS_IN_USE
;
305 if (wpa_s
->current_bss
) {
307 ie
= wpa_bss_get_vendor_ie_multi(wpa_s
->current_bss
,
312 EAPOL_PEER_IS_WPS20_AP
;
317 #endif /* CONFIG_WPS */
319 eapol_sm_notify_config(wpa_s
->eapol
, &ssid
->eap
, &eapol_conf
);
321 ieee802_1x_alloc_kay_sm(wpa_s
, ssid
);
322 #endif /* IEEE8021X_EAPOL */
327 * wpa_supplicant_set_non_wpa_policy - Set WPA parameters to non-WPA mode
328 * @wpa_s: Pointer to wpa_supplicant data
329 * @ssid: Configuration data for the network
331 * This function is used to configure WPA state machine and related parameters
332 * to a mode where WPA is not enabled. This is called as part of the
333 * authentication configuration when the selected network does not use WPA.
335 void wpa_supplicant_set_non_wpa_policy(struct wpa_supplicant
*wpa_s
,
336 struct wpa_ssid
*ssid
)
340 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
341 wpa_s
->key_mgmt
= WPA_KEY_MGMT_WPS
;
342 else if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)
343 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X_NO_WPA
;
345 wpa_s
->key_mgmt
= WPA_KEY_MGMT_NONE
;
346 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
347 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
348 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
349 wpa_s
->pairwise_cipher
= WPA_CIPHER_NONE
;
350 wpa_s
->group_cipher
= WPA_CIPHER_NONE
;
351 wpa_s
->mgmt_group_cipher
= 0;
353 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
354 if (ssid
->wep_key_len
[i
] > 5) {
355 wpa_s
->pairwise_cipher
= WPA_CIPHER_WEP104
;
356 wpa_s
->group_cipher
= WPA_CIPHER_WEP104
;
358 } else if (ssid
->wep_key_len
[i
] > 0) {
359 wpa_s
->pairwise_cipher
= WPA_CIPHER_WEP40
;
360 wpa_s
->group_cipher
= WPA_CIPHER_WEP40
;
365 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_RSN_ENABLED
, 0);
366 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_KEY_MGMT
, wpa_s
->key_mgmt
);
367 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PAIRWISE
,
368 wpa_s
->pairwise_cipher
);
369 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_GROUP
, wpa_s
->group_cipher
);
370 #ifdef CONFIG_IEEE80211W
371 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MGMT_GROUP
,
372 wpa_s
->mgmt_group_cipher
);
373 #endif /* CONFIG_IEEE80211W */
375 pmksa_cache_clear_current(wpa_s
->wpa
);
379 void free_hw_features(struct wpa_supplicant
*wpa_s
)
382 if (wpa_s
->hw
.modes
== NULL
)
385 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
386 os_free(wpa_s
->hw
.modes
[i
].channels
);
387 os_free(wpa_s
->hw
.modes
[i
].rates
);
390 os_free(wpa_s
->hw
.modes
);
391 wpa_s
->hw
.modes
= NULL
;
395 static void wpa_supplicant_cleanup(struct wpa_supplicant
*wpa_s
)
399 bgscan_deinit(wpa_s
);
400 autoscan_deinit(wpa_s
);
401 scard_deinit(wpa_s
->scard
);
403 wpa_sm_set_scard_ctx(wpa_s
->wpa
, NULL
);
404 eapol_sm_register_scard_ctx(wpa_s
->eapol
, NULL
);
405 l2_packet_deinit(wpa_s
->l2
);
408 l2_packet_deinit(wpa_s
->l2_br
);
411 #ifdef CONFIG_TESTING_OPTIONS
412 l2_packet_deinit(wpa_s
->l2_test
);
413 wpa_s
->l2_test
= NULL
;
414 #endif /* CONFIG_TESTING_OPTIONS */
416 if (wpa_s
->conf
!= NULL
) {
417 struct wpa_ssid
*ssid
;
418 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
)
419 wpas_notify_network_removed(wpa_s
, ssid
);
422 os_free(wpa_s
->confname
);
423 wpa_s
->confname
= NULL
;
425 os_free(wpa_s
->confanother
);
426 wpa_s
->confanother
= NULL
;
428 wpa_sm_set_eapol(wpa_s
->wpa
, NULL
);
429 eapol_sm_deinit(wpa_s
->eapol
);
432 rsn_preauth_deinit(wpa_s
->wpa
);
435 wpa_tdls_deinit(wpa_s
->wpa
);
436 #endif /* CONFIG_TDLS */
438 pmksa_candidate_free(wpa_s
->wpa
);
439 wpa_sm_deinit(wpa_s
->wpa
);
441 wpa_blacklist_clear(wpa_s
);
443 wpa_bss_deinit(wpa_s
);
445 wpa_supplicant_cancel_delayed_sched_scan(wpa_s
);
446 wpa_supplicant_cancel_scan(wpa_s
);
447 wpa_supplicant_cancel_auth_timeout(wpa_s
);
448 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
449 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
450 eloop_cancel_timeout(wpa_supplicant_delayed_mic_error_report
,
452 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
454 wpas_wps_deinit(wpa_s
);
456 wpabuf_free(wpa_s
->pending_eapol_rx
);
457 wpa_s
->pending_eapol_rx
= NULL
;
459 #ifdef CONFIG_IBSS_RSN
460 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
461 wpa_s
->ibss_rsn
= NULL
;
462 #endif /* CONFIG_IBSS_RSN */
467 wpa_supplicant_ap_deinit(wpa_s
);
468 #endif /* CONFIG_AP */
470 wpas_p2p_deinit(wpa_s
);
472 #ifdef CONFIG_OFFCHANNEL
473 offchannel_deinit(wpa_s
);
474 #endif /* CONFIG_OFFCHANNEL */
476 wpa_supplicant_cancel_sched_scan(wpa_s
);
478 os_free(wpa_s
->next_scan_freqs
);
479 wpa_s
->next_scan_freqs
= NULL
;
481 os_free(wpa_s
->manual_scan_freqs
);
482 wpa_s
->manual_scan_freqs
= NULL
;
484 os_free(wpa_s
->manual_sched_scan_freqs
);
485 wpa_s
->manual_sched_scan_freqs
= NULL
;
487 gas_query_deinit(wpa_s
->gas
);
490 free_hw_features(wpa_s
);
492 ieee802_1x_dealloc_kay_sm(wpa_s
);
494 os_free(wpa_s
->bssid_filter
);
495 wpa_s
->bssid_filter
= NULL
;
497 os_free(wpa_s
->disallow_aps_bssid
);
498 wpa_s
->disallow_aps_bssid
= NULL
;
499 os_free(wpa_s
->disallow_aps_ssid
);
500 wpa_s
->disallow_aps_ssid
= NULL
;
502 wnm_bss_keep_alive_deinit(wpa_s
);
504 wnm_deallocate_memory(wpa_s
);
505 #endif /* CONFIG_WNM */
507 ext_password_deinit(wpa_s
->ext_pw
);
508 wpa_s
->ext_pw
= NULL
;
510 wpabuf_free(wpa_s
->last_gas_resp
);
511 wpa_s
->last_gas_resp
= NULL
;
512 wpabuf_free(wpa_s
->prev_gas_resp
);
513 wpa_s
->prev_gas_resp
= NULL
;
515 os_free(wpa_s
->last_scan_res
);
516 wpa_s
->last_scan_res
= NULL
;
520 #endif /* CONFIG_HS20 */
522 for (i
= 0; i
< NUM_VENDOR_ELEM_FRAMES
; i
++) {
523 wpabuf_free(wpa_s
->vendor_elem
[i
]);
524 wpa_s
->vendor_elem
[i
] = NULL
;
527 wmm_ac_notify_disassoc(wpa_s
);
532 * wpa_clear_keys - Clear keys configured for the driver
533 * @wpa_s: Pointer to wpa_supplicant data
534 * @addr: Previously used BSSID or %NULL if not available
536 * This function clears the encryption keys that has been previously configured
539 void wpa_clear_keys(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
543 #ifdef CONFIG_IEEE80211W
545 #else /* CONFIG_IEEE80211W */
547 #endif /* CONFIG_IEEE80211W */
549 /* MLME-DELETEKEYS.request */
550 for (i
= 0; i
< max
; i
++) {
551 if (wpa_s
->keys_cleared
& BIT(i
))
553 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, i
, 0, NULL
, 0,
556 if (!(wpa_s
->keys_cleared
& BIT(0)) && addr
&&
557 !is_zero_ether_addr(addr
)) {
558 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, addr
, 0, 0, NULL
, 0, NULL
,
560 /* MLME-SETPROTECTION.request(None) */
561 wpa_drv_mlme_setprotection(
563 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
564 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
566 wpa_s
->keys_cleared
= (u32
) -1;
571 * wpa_supplicant_state_txt - Get the connection state name as a text string
572 * @state: State (wpa_state; WPA_*)
573 * Returns: The state name as a printable text string
575 const char * wpa_supplicant_state_txt(enum wpa_states state
)
578 case WPA_DISCONNECTED
:
579 return "DISCONNECTED";
582 case WPA_INTERFACE_DISABLED
:
583 return "INTERFACE_DISABLED";
586 case WPA_AUTHENTICATING
:
587 return "AUTHENTICATING";
588 case WPA_ASSOCIATING
:
589 return "ASSOCIATING";
592 case WPA_4WAY_HANDSHAKE
:
593 return "4WAY_HANDSHAKE";
594 case WPA_GROUP_HANDSHAKE
:
595 return "GROUP_HANDSHAKE";
606 static void wpa_supplicant_start_bgscan(struct wpa_supplicant
*wpa_s
)
610 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->bgscan
)
611 name
= wpa_s
->current_ssid
->bgscan
;
613 name
= wpa_s
->conf
->bgscan
;
614 if (name
== NULL
|| name
[0] == '\0')
616 if (wpas_driver_bss_selection(wpa_s
))
618 if (wpa_s
->current_ssid
== wpa_s
->bgscan_ssid
)
621 if (wpa_s
->p2p_group_interface
!= NOT_P2P_GROUP_INTERFACE
)
623 #endif /* CONFIG_P2P */
625 bgscan_deinit(wpa_s
);
626 if (wpa_s
->current_ssid
) {
627 if (bgscan_init(wpa_s
, wpa_s
->current_ssid
, name
)) {
628 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to initialize "
631 * Live without bgscan; it is only used as a roaming
632 * optimization, so the initial connection is not
636 struct wpa_scan_results
*scan_res
;
637 wpa_s
->bgscan_ssid
= wpa_s
->current_ssid
;
638 scan_res
= wpa_supplicant_get_scan_results(wpa_s
, NULL
,
641 bgscan_notify_scan(wpa_s
, scan_res
);
642 wpa_scan_results_free(scan_res
);
646 wpa_s
->bgscan_ssid
= NULL
;
650 static void wpa_supplicant_stop_bgscan(struct wpa_supplicant
*wpa_s
)
652 if (wpa_s
->bgscan_ssid
!= NULL
) {
653 bgscan_deinit(wpa_s
);
654 wpa_s
->bgscan_ssid
= NULL
;
658 #endif /* CONFIG_BGSCAN */
661 static void wpa_supplicant_start_autoscan(struct wpa_supplicant
*wpa_s
)
663 if (autoscan_init(wpa_s
, 0))
664 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to initialize autoscan");
668 static void wpa_supplicant_stop_autoscan(struct wpa_supplicant
*wpa_s
)
670 autoscan_deinit(wpa_s
);
674 void wpa_supplicant_reinit_autoscan(struct wpa_supplicant
*wpa_s
)
676 if (wpa_s
->wpa_state
== WPA_DISCONNECTED
||
677 wpa_s
->wpa_state
== WPA_SCANNING
) {
678 autoscan_deinit(wpa_s
);
679 wpa_supplicant_start_autoscan(wpa_s
);
685 * wpa_supplicant_set_state - Set current connection state
686 * @wpa_s: Pointer to wpa_supplicant data
687 * @state: The new connection state
689 * This function is called whenever the connection state changes, e.g.,
690 * association is completed for WPA/WPA2 4-Way Handshake is started.
692 void wpa_supplicant_set_state(struct wpa_supplicant
*wpa_s
,
693 enum wpa_states state
)
695 enum wpa_states old_state
= wpa_s
->wpa_state
;
697 wpa_dbg(wpa_s
, MSG_DEBUG
, "State: %s -> %s",
698 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
699 wpa_supplicant_state_txt(state
));
701 if (state
== WPA_INTERFACE_DISABLED
) {
702 /* Assure normal scan when interface is restored */
703 wpa_s
->normal_scans
= 0;
706 if (state
== WPA_COMPLETED
) {
707 wpas_connect_work_done(wpa_s
);
708 /* Reinitialize normal_scan counter */
709 wpa_s
->normal_scans
= 0;
712 if (state
!= WPA_SCANNING
)
713 wpa_supplicant_notify_scanning(wpa_s
, 0);
715 if (state
== WPA_COMPLETED
&& wpa_s
->new_connection
) {
716 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
717 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
718 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
"- Connection to "
719 MACSTR
" completed [id=%d id_str=%s]",
720 MAC2STR(wpa_s
->bssid
),
721 ssid
? ssid
->id
: -1,
722 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
723 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
724 wpas_clear_temp_disabled(wpa_s
, ssid
, 1);
725 wpa_s
->extra_blacklist_count
= 0;
726 wpa_s
->new_connection
= 0;
727 wpa_drv_set_operstate(wpa_s
, 1);
728 #ifndef IEEE8021X_EAPOL
729 wpa_drv_set_supp_port(wpa_s
, 1);
730 #endif /* IEEE8021X_EAPOL */
731 wpa_s
->after_wps
= 0;
732 wpa_s
->known_wps_freq
= 0;
733 wpas_p2p_completed(wpa_s
);
735 sme_sched_obss_scan(wpa_s
, 1);
736 } else if (state
== WPA_DISCONNECTED
|| state
== WPA_ASSOCIATING
||
737 state
== WPA_ASSOCIATED
) {
738 wpa_s
->new_connection
= 1;
739 wpa_drv_set_operstate(wpa_s
, 0);
740 #ifndef IEEE8021X_EAPOL
741 wpa_drv_set_supp_port(wpa_s
, 0);
742 #endif /* IEEE8021X_EAPOL */
743 sme_sched_obss_scan(wpa_s
, 0);
745 wpa_s
->wpa_state
= state
;
748 if (state
== WPA_COMPLETED
)
749 wpa_supplicant_start_bgscan(wpa_s
);
750 else if (state
< WPA_ASSOCIATED
)
751 wpa_supplicant_stop_bgscan(wpa_s
);
752 #endif /* CONFIG_BGSCAN */
754 if (state
== WPA_AUTHENTICATING
)
755 wpa_supplicant_stop_autoscan(wpa_s
);
757 if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
758 wpa_supplicant_start_autoscan(wpa_s
);
760 if (wpa_s
->wpa_state
!= old_state
) {
761 wpas_notify_state_changed(wpa_s
, wpa_s
->wpa_state
, old_state
);
764 * Notify the P2P Device interface about a state change in one
767 wpas_p2p_indicate_state_change(wpa_s
);
769 if (wpa_s
->wpa_state
== WPA_COMPLETED
||
770 old_state
== WPA_COMPLETED
)
771 wpas_notify_auth_changed(wpa_s
);
776 void wpa_supplicant_terminate_proc(struct wpa_global
*global
)
780 struct wpa_supplicant
*wpa_s
= global
->ifaces
;
782 struct wpa_supplicant
*next
= wpa_s
->next
;
783 if (wpas_wps_terminate_pending(wpa_s
) == 1)
786 if (wpa_s
->p2p_group_interface
!= NOT_P2P_GROUP_INTERFACE
||
787 (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->p2p_group
))
788 wpas_p2p_disconnect(wpa_s
);
789 #endif /* CONFIG_P2P */
792 #endif /* CONFIG_WPS */
799 static void wpa_supplicant_terminate(int sig
, void *signal_ctx
)
801 struct wpa_global
*global
= signal_ctx
;
802 wpa_supplicant_terminate_proc(global
);
806 void wpa_supplicant_clear_status(struct wpa_supplicant
*wpa_s
)
808 enum wpa_states old_state
= wpa_s
->wpa_state
;
810 wpa_s
->pairwise_cipher
= 0;
811 wpa_s
->group_cipher
= 0;
812 wpa_s
->mgmt_group_cipher
= 0;
814 if (wpa_s
->wpa_state
!= WPA_INTERFACE_DISABLED
)
815 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
817 if (wpa_s
->wpa_state
!= old_state
)
818 wpas_notify_state_changed(wpa_s
, wpa_s
->wpa_state
, old_state
);
823 * wpa_supplicant_reload_configuration - Reload configuration data
824 * @wpa_s: Pointer to wpa_supplicant data
825 * Returns: 0 on success or -1 if configuration parsing failed
827 * This function can be used to request that the configuration data is reloaded
828 * (e.g., after configuration file change). This function is reloading
829 * configuration only for one interface, so this may need to be called multiple
830 * times if %wpa_supplicant is controlling multiple interfaces and all
831 * interfaces need reconfiguration.
833 int wpa_supplicant_reload_configuration(struct wpa_supplicant
*wpa_s
)
835 struct wpa_config
*conf
;
839 if (wpa_s
->confname
== NULL
)
841 conf
= wpa_config_read(wpa_s
->confname
, NULL
);
843 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to parse the configuration "
844 "file '%s' - exiting", wpa_s
->confname
);
847 wpa_config_read(wpa_s
->confanother
, conf
);
849 conf
->changed_parameters
= (unsigned int) -1;
851 reconf_ctrl
= !!conf
->ctrl_interface
!= !!wpa_s
->conf
->ctrl_interface
852 || (conf
->ctrl_interface
&& wpa_s
->conf
->ctrl_interface
&&
853 os_strcmp(conf
->ctrl_interface
,
854 wpa_s
->conf
->ctrl_interface
) != 0);
856 if (reconf_ctrl
&& wpa_s
->ctrl_iface
) {
857 wpa_supplicant_ctrl_iface_deinit(wpa_s
->ctrl_iface
);
858 wpa_s
->ctrl_iface
= NULL
;
861 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
862 if (wpa_s
->current_ssid
) {
863 wpa_supplicant_deauthenticate(wpa_s
,
864 WLAN_REASON_DEAUTH_LEAVING
);
868 * TODO: should notify EAPOL SM about changes in opensc_engine_path,
869 * pkcs11_engine_path, pkcs11_module_path, openssl_ciphers.
871 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
873 * Clear forced success to clear EAP state for next
876 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
878 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
879 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
880 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
881 wpa_sm_set_fast_reauth(wpa_s
->wpa
, wpa_s
->conf
->fast_reauth
);
882 rsn_preauth_deinit(wpa_s
->wpa
);
884 old_ap_scan
= wpa_s
->conf
->ap_scan
;
885 wpa_config_free(wpa_s
->conf
);
887 if (old_ap_scan
!= wpa_s
->conf
->ap_scan
)
888 wpas_notify_ap_scan_changed(wpa_s
);
891 wpa_s
->ctrl_iface
= wpa_supplicant_ctrl_iface_init(wpa_s
);
893 wpa_supplicant_update_config(wpa_s
);
895 wpa_supplicant_clear_status(wpa_s
);
896 if (wpa_supplicant_enabled_networks(wpa_s
)) {
897 wpa_s
->reassociate
= 1;
898 wpa_supplicant_req_scan(wpa_s
, 0, 0);
900 wpa_dbg(wpa_s
, MSG_DEBUG
, "Reconfiguration completed");
905 static void wpa_supplicant_reconfig(int sig
, void *signal_ctx
)
907 struct wpa_global
*global
= signal_ctx
;
908 struct wpa_supplicant
*wpa_s
;
909 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
910 wpa_dbg(wpa_s
, MSG_DEBUG
, "Signal %d received - reconfiguring",
912 if (wpa_supplicant_reload_configuration(wpa_s
) < 0) {
913 wpa_supplicant_terminate_proc(global
);
919 static int wpa_supplicant_suites_from_ai(struct wpa_supplicant
*wpa_s
,
920 struct wpa_ssid
*ssid
,
921 struct wpa_ie_data
*ie
)
923 int ret
= wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, ie
);
926 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Failed to parse WPA IE "
927 "from association info");
932 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Using WPA IE from AssocReq to set "
934 if (!(ie
->group_cipher
& ssid
->group_cipher
)) {
935 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled group "
936 "cipher 0x%x (mask 0x%x) - reject",
937 ie
->group_cipher
, ssid
->group_cipher
);
940 if (!(ie
->pairwise_cipher
& ssid
->pairwise_cipher
)) {
941 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled pairwise "
942 "cipher 0x%x (mask 0x%x) - reject",
943 ie
->pairwise_cipher
, ssid
->pairwise_cipher
);
946 if (!(ie
->key_mgmt
& ssid
->key_mgmt
)) {
947 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled key "
948 "management 0x%x (mask 0x%x) - reject",
949 ie
->key_mgmt
, ssid
->key_mgmt
);
953 #ifdef CONFIG_IEEE80211W
954 if (!(ie
->capabilities
& WPA_CAPABILITY_MFPC
) &&
955 (ssid
->ieee80211w
== MGMT_FRAME_PROTECTION_DEFAULT
?
956 wpa_s
->conf
->pmf
: ssid
->ieee80211w
) ==
957 MGMT_FRAME_PROTECTION_REQUIRED
) {
958 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver associated with an AP "
959 "that does not support management frame protection - "
963 #endif /* CONFIG_IEEE80211W */
970 * wpa_supplicant_set_suites - Set authentication and encryption parameters
971 * @wpa_s: Pointer to wpa_supplicant data
972 * @bss: Scan results for the selected BSS, or %NULL if not available
973 * @ssid: Configuration data for the selected network
974 * @wpa_ie: Buffer for the WPA/RSN IE
975 * @wpa_ie_len: Maximum wpa_ie buffer size on input. This is changed to be the
976 * used buffer length in case the functions returns success.
977 * Returns: 0 on success or -1 on failure
979 * This function is used to configure authentication and encryption parameters
980 * based on the network configuration and scan result for the selected BSS (if
983 int wpa_supplicant_set_suites(struct wpa_supplicant
*wpa_s
,
984 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
,
985 u8
*wpa_ie
, size_t *wpa_ie_len
)
987 struct wpa_ie_data ie
;
989 const u8
*bss_wpa
, *bss_rsn
, *bss_osen
;
992 bss_wpa
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
993 bss_rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
994 bss_osen
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
996 bss_wpa
= bss_rsn
= bss_osen
= NULL
;
998 if (bss_rsn
&& (ssid
->proto
& WPA_PROTO_RSN
) &&
999 wpa_parse_wpa_ie(bss_rsn
, 2 + bss_rsn
[1], &ie
) == 0 &&
1000 (ie
.group_cipher
& ssid
->group_cipher
) &&
1001 (ie
.pairwise_cipher
& ssid
->pairwise_cipher
) &&
1002 (ie
.key_mgmt
& ssid
->key_mgmt
)) {
1003 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: using IEEE 802.11i/D9.0");
1004 proto
= WPA_PROTO_RSN
;
1005 } else if (bss_wpa
&& (ssid
->proto
& WPA_PROTO_WPA
) &&
1006 wpa_parse_wpa_ie(bss_wpa
, 2 +bss_wpa
[1], &ie
) == 0 &&
1007 (ie
.group_cipher
& ssid
->group_cipher
) &&
1008 (ie
.pairwise_cipher
& ssid
->pairwise_cipher
) &&
1009 (ie
.key_mgmt
& ssid
->key_mgmt
)) {
1010 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using IEEE 802.11i/D3.0");
1011 proto
= WPA_PROTO_WPA
;
1013 } else if (bss_osen
&& (ssid
->proto
& WPA_PROTO_OSEN
)) {
1014 wpa_dbg(wpa_s
, MSG_DEBUG
, "HS 2.0: using OSEN");
1015 /* TODO: parse OSEN element */
1016 os_memset(&ie
, 0, sizeof(ie
));
1017 ie
.group_cipher
= WPA_CIPHER_CCMP
;
1018 ie
.pairwise_cipher
= WPA_CIPHER_CCMP
;
1019 ie
.key_mgmt
= WPA_KEY_MGMT_OSEN
;
1020 proto
= WPA_PROTO_OSEN
;
1021 #endif /* CONFIG_HS20 */
1023 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select WPA/RSN");
1026 if (ssid
->proto
& WPA_PROTO_OSEN
)
1027 proto
= WPA_PROTO_OSEN
;
1028 else if (ssid
->proto
& WPA_PROTO_RSN
)
1029 proto
= WPA_PROTO_RSN
;
1031 proto
= WPA_PROTO_WPA
;
1032 if (wpa_supplicant_suites_from_ai(wpa_s
, ssid
, &ie
) < 0) {
1033 os_memset(&ie
, 0, sizeof(ie
));
1034 ie
.group_cipher
= ssid
->group_cipher
;
1035 ie
.pairwise_cipher
= ssid
->pairwise_cipher
;
1036 ie
.key_mgmt
= ssid
->key_mgmt
;
1037 #ifdef CONFIG_IEEE80211W
1038 ie
.mgmt_group_cipher
=
1039 ssid
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
?
1040 WPA_CIPHER_AES_128_CMAC
: 0;
1041 #endif /* CONFIG_IEEE80211W */
1042 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Set cipher suites "
1043 "based on configuration");
1048 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Selected cipher suites: group %d "
1049 "pairwise %d key_mgmt %d proto %d",
1050 ie
.group_cipher
, ie
.pairwise_cipher
, ie
.key_mgmt
, proto
);
1051 #ifdef CONFIG_IEEE80211W
1052 if (ssid
->ieee80211w
) {
1053 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Selected mgmt group cipher %d",
1054 ie
.mgmt_group_cipher
);
1056 #endif /* CONFIG_IEEE80211W */
1058 wpa_s
->wpa_proto
= proto
;
1059 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PROTO
, proto
);
1060 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_RSN_ENABLED
,
1061 !!(ssid
->proto
& (WPA_PROTO_RSN
| WPA_PROTO_OSEN
)));
1063 if (bss
|| !wpa_s
->ap_ies_from_associnfo
) {
1064 if (wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, bss_wpa
,
1065 bss_wpa
? 2 + bss_wpa
[1] : 0) ||
1066 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, bss_rsn
,
1067 bss_rsn
? 2 + bss_rsn
[1] : 0))
1071 sel
= ie
.group_cipher
& ssid
->group_cipher
;
1072 wpa_s
->group_cipher
= wpa_pick_group_cipher(sel
);
1073 if (wpa_s
->group_cipher
< 0) {
1074 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select group "
1078 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using GTK %s",
1079 wpa_cipher_txt(wpa_s
->group_cipher
));
1081 sel
= ie
.pairwise_cipher
& ssid
->pairwise_cipher
;
1082 wpa_s
->pairwise_cipher
= wpa_pick_pairwise_cipher(sel
, 1);
1083 if (wpa_s
->pairwise_cipher
< 0) {
1084 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select pairwise "
1088 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using PTK %s",
1089 wpa_cipher_txt(wpa_s
->pairwise_cipher
));
1091 sel
= ie
.key_mgmt
& ssid
->key_mgmt
;
1093 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
))
1094 sel
&= ~(WPA_KEY_MGMT_SAE
| WPA_KEY_MGMT_FT_SAE
);
1095 #endif /* CONFIG_SAE */
1097 } else if (sel
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
1098 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X_SUITE_B
;
1099 wpa_dbg(wpa_s
, MSG_DEBUG
,
1100 "WPA: using KEY_MGMT 802.1X with Suite B");
1101 #ifdef CONFIG_IEEE80211R
1102 } else if (sel
& WPA_KEY_MGMT_FT_IEEE8021X
) {
1103 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_IEEE8021X
;
1104 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FT/802.1X");
1105 } else if (sel
& WPA_KEY_MGMT_FT_PSK
) {
1106 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_PSK
;
1107 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FT/PSK");
1108 #endif /* CONFIG_IEEE80211R */
1110 } else if (sel
& WPA_KEY_MGMT_SAE
) {
1111 wpa_s
->key_mgmt
= WPA_KEY_MGMT_SAE
;
1112 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: using KEY_MGMT SAE");
1113 } else if (sel
& WPA_KEY_MGMT_FT_SAE
) {
1114 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_SAE
;
1115 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: using KEY_MGMT FT/SAE");
1116 #endif /* CONFIG_SAE */
1117 #ifdef CONFIG_IEEE80211W
1118 } else if (sel
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
1119 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X_SHA256
;
1120 wpa_dbg(wpa_s
, MSG_DEBUG
,
1121 "WPA: using KEY_MGMT 802.1X with SHA256");
1122 } else if (sel
& WPA_KEY_MGMT_PSK_SHA256
) {
1123 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK_SHA256
;
1124 wpa_dbg(wpa_s
, MSG_DEBUG
,
1125 "WPA: using KEY_MGMT PSK with SHA256");
1126 #endif /* CONFIG_IEEE80211W */
1127 } else if (sel
& WPA_KEY_MGMT_IEEE8021X
) {
1128 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X
;
1129 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT 802.1X");
1130 } else if (sel
& WPA_KEY_MGMT_PSK
) {
1131 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK
;
1132 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT WPA-PSK");
1133 } else if (sel
& WPA_KEY_MGMT_WPA_NONE
) {
1134 wpa_s
->key_mgmt
= WPA_KEY_MGMT_WPA_NONE
;
1135 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT WPA-NONE");
1137 } else if (sel
& WPA_KEY_MGMT_OSEN
) {
1138 wpa_s
->key_mgmt
= WPA_KEY_MGMT_OSEN
;
1139 wpa_dbg(wpa_s
, MSG_DEBUG
, "HS 2.0: using KEY_MGMT OSEN");
1140 #endif /* CONFIG_HS20 */
1142 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select "
1143 "authenticated key management type");
1147 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_KEY_MGMT
, wpa_s
->key_mgmt
);
1148 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PAIRWISE
,
1149 wpa_s
->pairwise_cipher
);
1150 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_GROUP
, wpa_s
->group_cipher
);
1152 #ifdef CONFIG_IEEE80211W
1153 sel
= ie
.mgmt_group_cipher
;
1154 if ((ssid
->ieee80211w
== MGMT_FRAME_PROTECTION_DEFAULT
?
1155 wpa_s
->conf
->pmf
: ssid
->ieee80211w
) == NO_MGMT_FRAME_PROTECTION
||
1156 !(ie
.capabilities
& WPA_CAPABILITY_MFPC
))
1158 if (sel
& WPA_CIPHER_AES_128_CMAC
) {
1159 wpa_s
->mgmt_group_cipher
= WPA_CIPHER_AES_128_CMAC
;
1160 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using MGMT group cipher "
1162 } else if (sel
& WPA_CIPHER_BIP_GMAC_128
) {
1163 wpa_s
->mgmt_group_cipher
= WPA_CIPHER_BIP_GMAC_128
;
1164 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using MGMT group cipher "
1166 } else if (sel
& WPA_CIPHER_BIP_GMAC_256
) {
1167 wpa_s
->mgmt_group_cipher
= WPA_CIPHER_BIP_GMAC_256
;
1168 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using MGMT group cipher "
1170 } else if (sel
& WPA_CIPHER_BIP_CMAC_256
) {
1171 wpa_s
->mgmt_group_cipher
= WPA_CIPHER_BIP_CMAC_256
;
1172 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using MGMT group cipher "
1175 wpa_s
->mgmt_group_cipher
= 0;
1176 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: not using MGMT group cipher");
1178 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MGMT_GROUP
,
1179 wpa_s
->mgmt_group_cipher
);
1180 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MFP
,
1181 (ssid
->ieee80211w
== MGMT_FRAME_PROTECTION_DEFAULT
?
1182 wpa_s
->conf
->pmf
: ssid
->ieee80211w
));
1183 #endif /* CONFIG_IEEE80211W */
1185 if (wpa_sm_set_assoc_wpa_ie_default(wpa_s
->wpa
, wpa_ie
, wpa_ie_len
)) {
1186 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to generate WPA IE");
1190 if (wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
)) {
1191 wpa_sm_set_pmk(wpa_s
->wpa
, ssid
->psk
, PMK_LEN
, NULL
);
1192 #ifndef CONFIG_NO_PBKDF2
1193 if (bss
&& ssid
->bssid_set
&& ssid
->ssid_len
== 0 &&
1196 pbkdf2_sha1(ssid
->passphrase
, bss
->ssid
, bss
->ssid_len
,
1197 4096, psk
, PMK_LEN
);
1198 wpa_hexdump_key(MSG_MSGDUMP
, "PSK (from passphrase)",
1200 wpa_sm_set_pmk(wpa_s
->wpa
, psk
, PMK_LEN
, NULL
);
1202 #endif /* CONFIG_NO_PBKDF2 */
1203 #ifdef CONFIG_EXT_PASSWORD
1204 if (ssid
->ext_psk
) {
1205 struct wpabuf
*pw
= ext_password_get(wpa_s
->ext_pw
,
1207 char pw_str
[64 + 1];
1211 wpa_msg(wpa_s
, MSG_INFO
, "EXT PW: No PSK "
1212 "found from external storage");
1216 if (wpabuf_len(pw
) < 8 || wpabuf_len(pw
) > 64) {
1217 wpa_msg(wpa_s
, MSG_INFO
, "EXT PW: Unexpected "
1218 "PSK length %d in external storage",
1219 (int) wpabuf_len(pw
));
1220 ext_password_free(pw
);
1224 os_memcpy(pw_str
, wpabuf_head(pw
), wpabuf_len(pw
));
1225 pw_str
[wpabuf_len(pw
)] = '\0';
1227 #ifndef CONFIG_NO_PBKDF2
1228 if (wpabuf_len(pw
) >= 8 && wpabuf_len(pw
) < 64 && bss
)
1230 pbkdf2_sha1(pw_str
, bss
->ssid
, bss
->ssid_len
,
1231 4096, psk
, PMK_LEN
);
1232 os_memset(pw_str
, 0, sizeof(pw_str
));
1233 wpa_hexdump_key(MSG_MSGDUMP
, "PSK (from "
1234 "external passphrase)",
1236 wpa_sm_set_pmk(wpa_s
->wpa
, psk
, PMK_LEN
, NULL
);
1238 #endif /* CONFIG_NO_PBKDF2 */
1239 if (wpabuf_len(pw
) == 2 * PMK_LEN
) {
1240 if (hexstr2bin(pw_str
, psk
, PMK_LEN
) < 0) {
1241 wpa_msg(wpa_s
, MSG_INFO
, "EXT PW: "
1242 "Invalid PSK hex string");
1243 os_memset(pw_str
, 0, sizeof(pw_str
));
1244 ext_password_free(pw
);
1247 wpa_sm_set_pmk(wpa_s
->wpa
, psk
, PMK_LEN
, NULL
);
1249 wpa_msg(wpa_s
, MSG_INFO
, "EXT PW: No suitable "
1251 os_memset(pw_str
, 0, sizeof(pw_str
));
1252 ext_password_free(pw
);
1256 os_memset(pw_str
, 0, sizeof(pw_str
));
1257 ext_password_free(pw
);
1259 #endif /* CONFIG_EXT_PASSWORD */
1261 wpa_sm_set_pmk_from_pmksa(wpa_s
->wpa
);
1267 static void wpas_ext_capab_byte(struct wpa_supplicant
*wpa_s
, u8
*pos
, int idx
)
1272 case 0: /* Bits 0-7 */
1274 case 1: /* Bits 8-15 */
1276 case 2: /* Bits 16-23 */
1278 *pos
|= 0x02; /* Bit 17 - WNM-Sleep Mode */
1279 *pos
|= 0x08; /* Bit 19 - BSS Transition */
1280 #endif /* CONFIG_WNM */
1282 case 3: /* Bits 24-31 */
1284 *pos
|= 0x02; /* Bit 25 - SSID List */
1285 #endif /* CONFIG_WNM */
1286 #ifdef CONFIG_INTERWORKING
1287 if (wpa_s
->conf
->interworking
)
1288 *pos
|= 0x80; /* Bit 31 - Interworking */
1289 #endif /* CONFIG_INTERWORKING */
1291 case 4: /* Bits 32-39 */
1292 #ifdef CONFIG_INTERWORKING
1293 if (wpa_s
->drv_flags
/ WPA_DRIVER_FLAGS_QOS_MAPPING
)
1294 *pos
|= 0x01; /* Bit 32 - QoS Map */
1295 #endif /* CONFIG_INTERWORKING */
1297 case 5: /* Bits 40-47 */
1299 if (wpa_s
->conf
->hs20
)
1300 *pos
|= 0x40; /* Bit 46 - WNM-Notification */
1301 #endif /* CONFIG_HS20 */
1303 case 6: /* Bits 48-55 */
1309 int wpas_build_ext_capab(struct wpa_supplicant
*wpa_s
, u8
*buf
, size_t buflen
)
1314 if (len
< wpa_s
->extended_capa_len
)
1315 len
= wpa_s
->extended_capa_len
;
1316 if (buflen
< (size_t) len
+ 2) {
1317 wpa_printf(MSG_INFO
,
1318 "Not enough room for building extended capabilities element");
1322 *pos
++ = WLAN_EID_EXT_CAPAB
;
1324 for (i
= 0; i
< len
; i
++, pos
++) {
1325 wpas_ext_capab_byte(wpa_s
, pos
, i
);
1327 if (i
< wpa_s
->extended_capa_len
) {
1328 *pos
&= ~wpa_s
->extended_capa_mask
[i
];
1329 *pos
|= wpa_s
->extended_capa
[i
];
1333 while (len
> 0 && buf
[1 + len
] == 0) {
1344 static int wpas_valid_bss(struct wpa_supplicant
*wpa_s
,
1345 struct wpa_bss
*test_bss
)
1347 struct wpa_bss
*bss
;
1349 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
1350 if (bss
== test_bss
)
1358 static int wpas_valid_ssid(struct wpa_supplicant
*wpa_s
,
1359 struct wpa_ssid
*test_ssid
)
1361 struct wpa_ssid
*ssid
;
1363 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
1364 if (ssid
== test_ssid
)
1372 int wpas_valid_bss_ssid(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*test_bss
,
1373 struct wpa_ssid
*test_ssid
)
1375 if (test_bss
&& !wpas_valid_bss(wpa_s
, test_bss
))
1378 return test_ssid
== NULL
|| wpas_valid_ssid(wpa_s
, test_ssid
);
1382 void wpas_connect_work_free(struct wpa_connect_work
*cwork
)
1390 void wpas_connect_work_done(struct wpa_supplicant
*wpa_s
)
1392 struct wpa_connect_work
*cwork
;
1393 struct wpa_radio_work
*work
= wpa_s
->connect_work
;
1398 wpa_s
->connect_work
= NULL
;
1401 wpas_connect_work_free(cwork
);
1402 radio_work_done(work
);
1406 int wpas_update_random_addr(struct wpa_supplicant
*wpa_s
, int style
)
1408 struct os_reltime now
;
1411 os_get_reltime(&now
);
1412 if (wpa_s
->last_mac_addr_style
== style
&&
1413 wpa_s
->last_mac_addr_change
.sec
!= 0 &&
1414 !os_reltime_expired(&now
, &wpa_s
->last_mac_addr_change
,
1415 wpa_s
->conf
->rand_addr_lifetime
)) {
1416 wpa_msg(wpa_s
, MSG_DEBUG
,
1417 "Previously selected random MAC address has not yet expired");
1423 if (random_mac_addr(addr
) < 0)
1427 os_memcpy(addr
, wpa_s
->perm_addr
, ETH_ALEN
);
1428 if (random_mac_addr_keep_oui(addr
) < 0)
1435 if (wpa_drv_set_mac_addr(wpa_s
, addr
) < 0) {
1436 wpa_msg(wpa_s
, MSG_INFO
,
1437 "Failed to set random MAC address");
1441 os_get_reltime(&wpa_s
->last_mac_addr_change
);
1442 wpa_s
->mac_addr_changed
= 1;
1443 wpa_s
->last_mac_addr_style
= style
;
1445 if (wpa_supplicant_update_mac_addr(wpa_s
) < 0) {
1446 wpa_msg(wpa_s
, MSG_INFO
,
1447 "Could not update MAC address information");
1451 wpa_msg(wpa_s
, MSG_DEBUG
, "Using random MAC address " MACSTR
,
1458 int wpas_update_random_addr_disassoc(struct wpa_supplicant
*wpa_s
)
1460 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
||
1461 !wpa_s
->conf
->preassoc_mac_addr
)
1464 return wpas_update_random_addr(wpa_s
, wpa_s
->conf
->preassoc_mac_addr
);
1468 static void wpas_start_assoc_cb(struct wpa_radio_work
*work
, int deinit
);
1471 * wpa_supplicant_associate - Request association
1472 * @wpa_s: Pointer to wpa_supplicant data
1473 * @bss: Scan results for the selected BSS, or %NULL if not available
1474 * @ssid: Configuration data for the selected network
1476 * This function is used to request %wpa_supplicant to associate with a BSS.
1478 void wpa_supplicant_associate(struct wpa_supplicant
*wpa_s
,
1479 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
)
1481 struct wpa_connect_work
*cwork
;
1484 if (ssid
->mac_addr
== -1)
1485 rand_style
= wpa_s
->conf
->mac_addr
;
1487 rand_style
= ssid
->mac_addr
;
1489 if (wpa_s
->last_ssid
== ssid
) {
1490 wpa_dbg(wpa_s
, MSG_DEBUG
, "Re-association to the same ESS");
1491 } else if (rand_style
> 0) {
1492 if (wpas_update_random_addr(wpa_s
, rand_style
) < 0)
1494 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
1495 } else if (wpa_s
->mac_addr_changed
) {
1496 if (wpa_drv_set_mac_addr(wpa_s
, NULL
) < 0) {
1497 wpa_msg(wpa_s
, MSG_INFO
,
1498 "Could not restore permanent MAC address");
1501 wpa_s
->mac_addr_changed
= 0;
1502 if (wpa_supplicant_update_mac_addr(wpa_s
) < 0) {
1503 wpa_msg(wpa_s
, MSG_INFO
,
1504 "Could not update MAC address information");
1507 wpa_msg(wpa_s
, MSG_DEBUG
, "Using permanent MAC address");
1509 wpa_s
->last_ssid
= ssid
;
1511 #ifdef CONFIG_IBSS_RSN
1512 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
1513 wpa_s
->ibss_rsn
= NULL
;
1514 #endif /* CONFIG_IBSS_RSN */
1516 if (ssid
->mode
== WPAS_MODE_AP
|| ssid
->mode
== WPAS_MODE_P2P_GO
||
1517 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
) {
1519 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_AP
)) {
1520 wpa_msg(wpa_s
, MSG_INFO
, "Driver does not support AP "
1524 if (wpa_supplicant_create_ap(wpa_s
, ssid
) < 0) {
1525 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1526 if (ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)
1527 wpas_p2p_ap_setup_failed(wpa_s
);
1530 wpa_s
->current_bss
= bss
;
1531 #else /* CONFIG_AP */
1532 wpa_msg(wpa_s
, MSG_ERROR
, "AP mode support not included in "
1534 #endif /* CONFIG_AP */
1538 if (ssid
->mode
== WPAS_MODE_MESH
) {
1540 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_MESH
)) {
1541 wpa_msg(wpa_s
, MSG_INFO
,
1542 "Driver does not support mesh mode");
1546 ssid
->frequency
= bss
->freq
;
1547 if (wpa_supplicant_join_mesh(wpa_s
, ssid
) < 0) {
1548 wpa_msg(wpa_s
, MSG_ERROR
, "Could not join mesh");
1551 wpa_s
->current_bss
= bss
;
1552 wpa_msg_ctrl(wpa_s
, MSG_INFO
, MESH_GROUP_STARTED
1553 "ssid=\"%s\" id=%d",
1554 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
),
1556 #else /* CONFIG_MESH */
1557 wpa_msg(wpa_s
, MSG_ERROR
,
1558 "mesh mode support not included in the build");
1559 #endif /* CONFIG_MESH */
1565 wpa_tdls_ap_ies(wpa_s
->wpa
, (const u8
*) (bss
+ 1),
1567 #endif /* CONFIG_TDLS */
1569 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
1570 ssid
->mode
== IEEE80211_MODE_INFRA
) {
1571 sme_authenticate(wpa_s
, bss
, ssid
);
1575 if (wpa_s
->connect_work
) {
1576 wpa_dbg(wpa_s
, MSG_DEBUG
, "Reject wpa_supplicant_associate() call since connect_work exist");
1580 if (radio_work_pending(wpa_s
, "connect")) {
1581 wpa_dbg(wpa_s
, MSG_DEBUG
, "Reject wpa_supplicant_associate() call since pending work exist");
1585 cwork
= os_zalloc(sizeof(*cwork
));
1592 if (radio_add_work(wpa_s
, bss
? bss
->freq
: 0, "connect", 1,
1593 wpas_start_assoc_cb
, cwork
) < 0) {
1599 static void wpas_start_assoc_cb(struct wpa_radio_work
*work
, int deinit
)
1601 struct wpa_connect_work
*cwork
= work
->ctx
;
1602 struct wpa_bss
*bss
= cwork
->bss
;
1603 struct wpa_ssid
*ssid
= cwork
->ssid
;
1604 struct wpa_supplicant
*wpa_s
= work
->wpa_s
;
1607 int use_crypt
, ret
, i
, bssid_changed
;
1608 int algs
= WPA_AUTH_ALG_OPEN
;
1609 unsigned int cipher_pairwise
, cipher_group
;
1610 struct wpa_driver_associate_params params
;
1611 int wep_keys_set
= 0;
1612 int assoc_failed
= 0;
1613 struct wpa_ssid
*old_ssid
;
1614 #ifdef CONFIG_HT_OVERRIDES
1615 struct ieee80211_ht_capabilities htcaps
;
1616 struct ieee80211_ht_capabilities htcaps_mask
;
1617 #endif /* CONFIG_HT_OVERRIDES */
1618 #ifdef CONFIG_VHT_OVERRIDES
1619 struct ieee80211_vht_capabilities vhtcaps
;
1620 struct ieee80211_vht_capabilities vhtcaps_mask
;
1621 #endif /* CONFIG_VHT_OVERRIDES */
1624 if (work
->started
) {
1625 wpa_s
->connect_work
= NULL
;
1627 /* cancel possible auth. timeout */
1628 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
,
1631 wpas_connect_work_free(cwork
);
1635 wpa_s
->connect_work
= work
;
1637 if (cwork
->bss_removed
|| !wpas_valid_bss_ssid(wpa_s
, bss
, ssid
)) {
1638 wpa_dbg(wpa_s
, MSG_DEBUG
, "BSS/SSID entry for association not valid anymore - drop connection attempt");
1639 wpas_connect_work_done(wpa_s
);
1643 os_memset(¶ms
, 0, sizeof(params
));
1644 wpa_s
->reassociate
= 0;
1645 wpa_s
->eap_expected_failure
= 0;
1647 (!wpas_driver_bss_selection(wpa_s
) || wpas_wps_searching(wpa_s
))) {
1648 #ifdef CONFIG_IEEE80211R
1649 const u8
*ie
, *md
= NULL
;
1650 #endif /* CONFIG_IEEE80211R */
1651 wpa_msg(wpa_s
, MSG_INFO
, "Trying to associate with " MACSTR
1652 " (SSID='%s' freq=%d MHz)", MAC2STR(bss
->bssid
),
1653 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
), bss
->freq
);
1654 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
1655 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
1656 os_memcpy(wpa_s
->pending_bssid
, bss
->bssid
, ETH_ALEN
);
1658 wpas_notify_bssid_changed(wpa_s
);
1659 #ifdef CONFIG_IEEE80211R
1660 ie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
1661 if (ie
&& ie
[1] >= MOBILITY_DOMAIN_ID_LEN
)
1663 wpa_sm_set_ft_params(wpa_s
->wpa
, ie
, ie
? 2 + ie
[1] : 0);
1665 /* Prepare for the next transition */
1666 wpa_ft_prepare_auth_request(wpa_s
->wpa
, ie
);
1668 #endif /* CONFIG_IEEE80211R */
1670 } else if ((ssid
->ssid
== NULL
|| ssid
->ssid_len
== 0) &&
1671 wpa_s
->conf
->ap_scan
== 2 &&
1672 (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
1673 /* Use ap_scan==1 style network selection to find the network
1675 wpas_connect_work_done(wpa_s
);
1676 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
1677 wpa_s
->reassociate
= 1;
1678 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1680 #endif /* CONFIG_WPS */
1682 wpa_msg(wpa_s
, MSG_INFO
, "Trying to associate with SSID '%s'",
1683 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
1684 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1686 wpa_supplicant_cancel_sched_scan(wpa_s
);
1687 wpa_supplicant_cancel_scan(wpa_s
);
1689 /* Starting new association, so clear the possibly used WPA IE from the
1690 * previous association. */
1691 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1693 #ifdef IEEE8021X_EAPOL
1694 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1696 if (ssid
->non_leap
== 0)
1697 algs
= WPA_AUTH_ALG_LEAP
;
1699 algs
|= WPA_AUTH_ALG_LEAP
;
1702 #endif /* IEEE8021X_EAPOL */
1703 wpa_dbg(wpa_s
, MSG_DEBUG
, "Automatic auth_alg selection: 0x%x", algs
);
1704 if (ssid
->auth_alg
) {
1705 algs
= ssid
->auth_alg
;
1706 wpa_dbg(wpa_s
, MSG_DEBUG
, "Overriding auth_alg selection: "
1710 if (bss
&& (wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
) ||
1711 wpa_bss_get_ie(bss
, WLAN_EID_RSN
)) &&
1712 wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
1713 int try_opportunistic
;
1714 try_opportunistic
= (ssid
->proactive_key_caching
< 0 ?
1716 ssid
->proactive_key_caching
) &&
1717 (ssid
->proto
& WPA_PROTO_RSN
);
1718 if (pmksa_cache_set_current(wpa_s
->wpa
, NULL
, bss
->bssid
,
1719 ssid
, try_opportunistic
) == 0)
1720 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
, 1);
1721 wpa_ie_len
= sizeof(wpa_ie
);
1722 if (wpa_supplicant_set_suites(wpa_s
, bss
, ssid
,
1723 wpa_ie
, &wpa_ie_len
)) {
1724 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to set WPA "
1725 "key management and encryption suites");
1726 wpas_connect_work_done(wpa_s
);
1729 } else if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) && bss
&&
1730 wpa_key_mgmt_wpa_ieee8021x(ssid
->key_mgmt
)) {
1732 * Both WPA and non-WPA IEEE 802.1X enabled in configuration -
1733 * use non-WPA since the scan results did not indicate that the
1734 * AP is using WPA or WPA2.
1736 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
1738 wpa_s
->wpa_proto
= 0;
1739 } else if (wpa_key_mgmt_wpa_any(ssid
->key_mgmt
)) {
1740 wpa_ie_len
= sizeof(wpa_ie
);
1741 if (wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
1742 wpa_ie
, &wpa_ie_len
)) {
1743 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to set WPA "
1744 "key management and encryption suites (no "
1746 wpas_connect_work_done(wpa_s
);
1750 } else if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
1751 struct wpabuf
*wps_ie
;
1752 wps_ie
= wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid
));
1753 if (wps_ie
&& wpabuf_len(wps_ie
) <= sizeof(wpa_ie
)) {
1754 wpa_ie_len
= wpabuf_len(wps_ie
);
1755 os_memcpy(wpa_ie
, wpabuf_head(wps_ie
), wpa_ie_len
);
1758 wpabuf_free(wps_ie
);
1759 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
1760 if (!bss
|| (bss
->caps
& IEEE80211_CAP_PRIVACY
))
1761 params
.wps
= WPS_MODE_PRIVACY
;
1763 params
.wps
= WPS_MODE_OPEN
;
1764 wpa_s
->wpa_proto
= 0;
1765 #endif /* CONFIG_WPS */
1767 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
1769 wpa_s
->wpa_proto
= 0;
1773 if (wpa_s
->global
->p2p
) {
1777 pos
= wpa_ie
+ wpa_ie_len
;
1778 len
= sizeof(wpa_ie
) - wpa_ie_len
;
1779 res
= wpas_p2p_assoc_req_ie(wpa_s
, bss
, pos
, len
,
1785 wpa_s
->cross_connect_disallowed
= 0;
1788 p2p
= wpa_bss_get_vendor_ie_multi(bss
, P2P_IE_VENDOR_TYPE
);
1790 wpa_s
->cross_connect_disallowed
=
1791 p2p_get_cross_connect_disallowed(p2p
);
1793 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: WLAN AP %s cross "
1795 wpa_s
->cross_connect_disallowed
?
1796 "disallows" : "allows");
1800 os_memset(wpa_s
->p2p_ip_addr_info
, 0, sizeof(wpa_s
->p2p_ip_addr_info
));
1801 #endif /* CONFIG_P2P */
1804 if (is_hs20_network(wpa_s
, ssid
, bss
)) {
1805 struct wpabuf
*hs20
;
1806 hs20
= wpabuf_alloc(20);
1808 int pps_mo_id
= hs20_get_pps_mo_id(wpa_s
, ssid
);
1811 wpas_hs20_add_indication(hs20
, pps_mo_id
);
1812 len
= sizeof(wpa_ie
) - wpa_ie_len
;
1813 if (wpabuf_len(hs20
) <= len
) {
1814 os_memcpy(wpa_ie
+ wpa_ie_len
,
1815 wpabuf_head(hs20
), wpabuf_len(hs20
));
1816 wpa_ie_len
+= wpabuf_len(hs20
);
1821 #endif /* CONFIG_HS20 */
1824 * Workaround: Add Extended Capabilities element only if the AP
1825 * included this element in Beacon/Probe Response frames. Some older
1826 * APs seem to have interoperability issues if this element is
1827 * included, so while the standard may require us to include the
1828 * element in all cases, it is justifiable to skip it to avoid
1829 * interoperability issues.
1831 if (!bss
|| wpa_bss_get_ie(bss
, WLAN_EID_EXT_CAPAB
)) {
1834 ext_capab_len
= wpas_build_ext_capab(wpa_s
, ext_capab
,
1836 if (ext_capab_len
> 0) {
1838 if (wpa_ie_len
> 0 && pos
[0] == WLAN_EID_RSN
)
1840 os_memmove(pos
+ ext_capab_len
, pos
,
1841 wpa_ie_len
- (pos
- wpa_ie
));
1842 wpa_ie_len
+= ext_capab_len
;
1843 os_memcpy(pos
, ext_capab
, ext_capab_len
);
1847 wpa_clear_keys(wpa_s
, bss
? bss
->bssid
: NULL
);
1849 cipher_pairwise
= wpa_s
->pairwise_cipher
;
1850 cipher_group
= wpa_s
->group_cipher
;
1851 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1852 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1853 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
)
1855 if (wpa_set_wep_keys(wpa_s
, ssid
)) {
1860 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
)
1863 #ifdef IEEE8021X_EAPOL
1864 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1865 if ((ssid
->eapol_flags
&
1866 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
1867 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
)) == 0 &&
1871 /* Assume that dynamic WEP-104 keys will be used and
1872 * set cipher suites in order for drivers to expect
1874 cipher_pairwise
= cipher_group
= WPA_CIPHER_WEP104
;
1877 #endif /* IEEE8021X_EAPOL */
1879 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1880 /* Set the key before (and later after) association */
1881 wpa_supplicant_set_wpa_none_key(wpa_s
, ssid
);
1884 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATING
);
1886 params
.ssid
= bss
->ssid
;
1887 params
.ssid_len
= bss
->ssid_len
;
1888 if (!wpas_driver_bss_selection(wpa_s
) || ssid
->bssid_set
) {
1889 wpa_printf(MSG_DEBUG
, "Limit connection to BSSID "
1890 MACSTR
" freq=%u MHz based on scan results "
1892 MAC2STR(bss
->bssid
), bss
->freq
,
1894 params
.bssid
= bss
->bssid
;
1895 params
.freq
.freq
= bss
->freq
;
1897 params
.bssid_hint
= bss
->bssid
;
1898 params
.freq_hint
= bss
->freq
;
1900 params
.ssid
= ssid
->ssid
;
1901 params
.ssid_len
= ssid
->ssid_len
;
1904 if (ssid
->mode
== WPAS_MODE_IBSS
&& ssid
->bssid_set
&&
1905 wpa_s
->conf
->ap_scan
== 2) {
1906 params
.bssid
= ssid
->bssid
;
1907 params
.fixed_bssid
= 1;
1910 /* Initial frequency for IBSS/mesh */
1911 if ((ssid
->mode
== WPAS_MODE_IBSS
|| ssid
->mode
== WPAS_MODE_MESH
) &&
1912 ssid
->frequency
> 0 && params
.freq
.freq
== 0) {
1913 enum hostapd_hw_mode hw_mode
;
1916 params
.freq
.freq
= ssid
->frequency
;
1918 hw_mode
= ieee80211_freq_to_chan(ssid
->frequency
, &channel
);
1919 for (i
= 0; wpa_s
->hw
.modes
&& i
< wpa_s
->hw
.num_modes
; i
++) {
1920 if (wpa_s
->hw
.modes
[i
].mode
== hw_mode
) {
1921 struct hostapd_hw_modes
*mode
;
1923 mode
= &wpa_s
->hw
.modes
[i
];
1924 params
.freq
.ht_enabled
= ht_supported(mode
);
1930 if (ssid
->mode
== WPAS_MODE_IBSS
) {
1931 if (ssid
->beacon_int
)
1932 params
.beacon_int
= ssid
->beacon_int
;
1934 params
.beacon_int
= wpa_s
->conf
->beacon_int
;
1937 params
.wpa_ie
= wpa_ie
;
1938 params
.wpa_ie_len
= wpa_ie_len
;
1939 params
.pairwise_suite
= cipher_pairwise
;
1940 params
.group_suite
= cipher_group
;
1941 params
.key_mgmt_suite
= wpa_s
->key_mgmt
;
1942 params
.wpa_proto
= wpa_s
->wpa_proto
;
1943 params
.auth_alg
= algs
;
1944 params
.mode
= ssid
->mode
;
1945 params
.bg_scan_period
= ssid
->bg_scan_period
;
1946 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
1947 if (ssid
->wep_key_len
[i
])
1948 params
.wep_key
[i
] = ssid
->wep_key
[i
];
1949 params
.wep_key_len
[i
] = ssid
->wep_key_len
[i
];
1951 params
.wep_tx_keyidx
= ssid
->wep_tx_keyidx
;
1953 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1954 (params
.key_mgmt_suite
== WPA_KEY_MGMT_PSK
||
1955 params
.key_mgmt_suite
== WPA_KEY_MGMT_FT_PSK
)) {
1956 params
.passphrase
= ssid
->passphrase
;
1958 params
.psk
= ssid
->psk
;
1961 if (wpa_s
->conf
->key_mgmt_offload
) {
1962 if (params
.key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X
||
1963 params
.key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SHA256
||
1964 params
.key_mgmt_suite
== WPA_KEY_MGMT_IEEE8021X_SUITE_B
)
1965 params
.req_key_mgmt_offload
=
1966 ssid
->proactive_key_caching
< 0 ?
1967 wpa_s
->conf
->okc
: ssid
->proactive_key_caching
;
1969 params
.req_key_mgmt_offload
= 1;
1971 if ((params
.key_mgmt_suite
== WPA_KEY_MGMT_PSK
||
1972 params
.key_mgmt_suite
== WPA_KEY_MGMT_PSK_SHA256
||
1973 params
.key_mgmt_suite
== WPA_KEY_MGMT_FT_PSK
) &&
1975 params
.psk
= ssid
->psk
;
1978 params
.drop_unencrypted
= use_crypt
;
1980 #ifdef CONFIG_IEEE80211W
1981 params
.mgmt_frame_protection
=
1982 ssid
->ieee80211w
== MGMT_FRAME_PROTECTION_DEFAULT
?
1983 wpa_s
->conf
->pmf
: ssid
->ieee80211w
;
1984 if (params
.mgmt_frame_protection
!= NO_MGMT_FRAME_PROTECTION
&& bss
) {
1985 const u8
*rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1986 struct wpa_ie_data ie
;
1987 if (rsn
&& wpa_parse_wpa_ie(rsn
, 2 + rsn
[1], &ie
) == 0 &&
1989 (WPA_CAPABILITY_MFPC
| WPA_CAPABILITY_MFPR
)) {
1990 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Selected AP supports "
1991 "MFP: require MFP");
1992 params
.mgmt_frame_protection
=
1993 MGMT_FRAME_PROTECTION_REQUIRED
;
1996 #endif /* CONFIG_IEEE80211W */
1998 params
.p2p
= ssid
->p2p_group
;
2000 if (wpa_s
->parent
->set_sta_uapsd
)
2001 params
.uapsd
= wpa_s
->parent
->sta_uapsd
;
2005 #ifdef CONFIG_HT_OVERRIDES
2006 os_memset(&htcaps
, 0, sizeof(htcaps
));
2007 os_memset(&htcaps_mask
, 0, sizeof(htcaps_mask
));
2008 params
.htcaps
= (u8
*) &htcaps
;
2009 params
.htcaps_mask
= (u8
*) &htcaps_mask
;
2010 wpa_supplicant_apply_ht_overrides(wpa_s
, ssid
, ¶ms
);
2011 #endif /* CONFIG_HT_OVERRIDES */
2012 #ifdef CONFIG_VHT_OVERRIDES
2013 os_memset(&vhtcaps
, 0, sizeof(vhtcaps
));
2014 os_memset(&vhtcaps_mask
, 0, sizeof(vhtcaps_mask
));
2015 params
.vhtcaps
= &vhtcaps
;
2016 params
.vhtcaps_mask
= &vhtcaps_mask
;
2017 wpa_supplicant_apply_vht_overrides(wpa_s
, wpa_s
->current_ssid
, ¶ms
);
2018 #endif /* CONFIG_VHT_OVERRIDES */
2022 * If multi-channel concurrency is not supported, check for any
2023 * frequency conflict. In case of any frequency conflict, remove the
2024 * least prioritized connection.
2026 if (wpa_s
->num_multichan_concurrent
< 2) {
2028 num
= get_shared_radio_freqs(wpa_s
, &freq
, 1);
2029 if (num
> 0 && freq
> 0 && freq
!= params
.freq
.freq
) {
2030 wpa_printf(MSG_DEBUG
,
2031 "Assoc conflicting freq found (%d != %d)",
2032 freq
, params
.freq
.freq
);
2033 if (wpas_p2p_handle_frequency_conflicts(
2034 wpa_s
, params
.freq
.freq
, ssid
) < 0) {
2035 wpas_connect_work_done(wpa_s
);
2040 #endif /* CONFIG_P2P */
2042 ret
= wpa_drv_associate(wpa_s
, ¶ms
);
2044 wpa_msg(wpa_s
, MSG_INFO
, "Association request to the driver "
2046 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SANE_ERROR_CODES
) {
2048 * The driver is known to mean what is saying, so we
2049 * can stop right here; the association will not
2052 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
2053 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
2054 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
2057 /* try to continue anyway; new association will be tried again
2062 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
2063 /* Set the key after the association just in case association
2064 * cleared the previously configured key. */
2065 wpa_supplicant_set_wpa_none_key(wpa_s
, ssid
);
2066 /* No need to timeout authentication since there is no key
2068 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2069 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
2070 #ifdef CONFIG_IBSS_RSN
2071 } else if (ssid
->mode
== WPAS_MODE_IBSS
&&
2072 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2073 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
) {
2075 * RSN IBSS authentication is per-STA and we can disable the
2076 * per-BSSID authentication.
2078 wpa_supplicant_cancel_auth_timeout(wpa_s
);
2079 #endif /* CONFIG_IBSS_RSN */
2081 /* Timeout for IEEE 802.11 authentication and association */
2085 /* give IBSS a bit more time */
2086 timeout
= ssid
->mode
== WPAS_MODE_IBSS
? 10 : 5;
2087 } else if (wpa_s
->conf
->ap_scan
== 1) {
2088 /* give IBSS a bit more time */
2089 timeout
= ssid
->mode
== WPAS_MODE_IBSS
? 20 : 10;
2091 wpa_supplicant_req_auth_timeout(wpa_s
, timeout
, 0);
2095 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC
)) {
2096 /* Set static WEP keys again */
2097 wpa_set_wep_keys(wpa_s
, ssid
);
2100 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
) {
2102 * Do not allow EAP session resumption between different
2103 * network configurations.
2105 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2107 old_ssid
= wpa_s
->current_ssid
;
2108 wpa_s
->current_ssid
= ssid
;
2109 wpa_s
->current_bss
= bss
;
2110 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
2111 wpa_supplicant_initiate_eapol(wpa_s
);
2112 if (old_ssid
!= wpa_s
->current_ssid
)
2113 wpas_notify_network_changed(wpa_s
);
2117 static void wpa_supplicant_clear_connection(struct wpa_supplicant
*wpa_s
,
2120 struct wpa_ssid
*old_ssid
;
2122 wpas_connect_work_done(wpa_s
);
2123 wpa_clear_keys(wpa_s
, addr
);
2124 old_ssid
= wpa_s
->current_ssid
;
2125 wpa_supplicant_mark_disassoc(wpa_s
);
2126 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
2127 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
2128 if (old_ssid
!= wpa_s
->current_ssid
)
2129 wpas_notify_network_changed(wpa_s
);
2130 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
2135 * wpa_supplicant_deauthenticate - Deauthenticate the current connection
2136 * @wpa_s: Pointer to wpa_supplicant data
2137 * @reason_code: IEEE 802.11 reason code for the deauthenticate frame
2139 * This function is used to request %wpa_supplicant to deauthenticate from the
2142 void wpa_supplicant_deauthenticate(struct wpa_supplicant
*wpa_s
,
2146 union wpa_event_data event
;
2149 wpa_dbg(wpa_s
, MSG_DEBUG
, "Request to deauthenticate - bssid=" MACSTR
2150 " pending_bssid=" MACSTR
" reason=%d state=%s",
2151 MAC2STR(wpa_s
->bssid
), MAC2STR(wpa_s
->pending_bssid
),
2152 reason_code
, wpa_supplicant_state_txt(wpa_s
->wpa_state
));
2154 if (!is_zero_ether_addr(wpa_s
->bssid
))
2155 addr
= wpa_s
->bssid
;
2156 else if (!is_zero_ether_addr(wpa_s
->pending_bssid
) &&
2157 (wpa_s
->wpa_state
== WPA_AUTHENTICATING
||
2158 wpa_s
->wpa_state
== WPA_ASSOCIATING
))
2159 addr
= wpa_s
->pending_bssid
;
2160 else if (wpa_s
->wpa_state
== WPA_ASSOCIATING
) {
2162 * When using driver-based BSS selection, we may not know the
2163 * BSSID with which we are currently trying to associate. We
2164 * need to notify the driver of this disconnection even in such
2165 * a case, so use the all zeros address here.
2167 addr
= wpa_s
->bssid
;
2172 wpa_tdls_teardown_peers(wpa_s
->wpa
);
2173 #endif /* CONFIG_TDLS */
2177 wpa_msg_ctrl(wpa_s
, MSG_INFO
, MESH_GROUP_REMOVED
"%s",
2179 wpa_supplicant_leave_mesh(wpa_s
);
2181 #endif /* CONFIG_MESH */
2184 wpa_drv_deauthenticate(wpa_s
, addr
, reason_code
);
2185 os_memset(&event
, 0, sizeof(event
));
2186 event
.deauth_info
.reason_code
= (u16
) reason_code
;
2187 event
.deauth_info
.locally_generated
= 1;
2188 wpa_supplicant_event(wpa_s
, EVENT_DEAUTH
, &event
);
2193 wpa_supplicant_clear_connection(wpa_s
, addr
);
2196 static void wpa_supplicant_enable_one_network(struct wpa_supplicant
*wpa_s
,
2197 struct wpa_ssid
*ssid
)
2199 if (!ssid
|| !ssid
->disabled
|| ssid
->disabled
== 2)
2203 wpas_clear_temp_disabled(wpa_s
, ssid
, 1);
2204 wpas_notify_network_enabled_changed(wpa_s
, ssid
);
2207 * Try to reassociate since there is no current configuration and a new
2208 * network was made available.
2210 if (!wpa_s
->current_ssid
&& !wpa_s
->disconnected
)
2211 wpa_s
->reassociate
= 1;
2216 * wpa_supplicant_enable_network - Mark a configured network as enabled
2217 * @wpa_s: wpa_supplicant structure for a network interface
2218 * @ssid: wpa_ssid structure for a configured network or %NULL
2220 * Enables the specified network or all networks if no network specified.
2222 void wpa_supplicant_enable_network(struct wpa_supplicant
*wpa_s
,
2223 struct wpa_ssid
*ssid
)
2226 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
)
2227 wpa_supplicant_enable_one_network(wpa_s
, ssid
);
2229 wpa_supplicant_enable_one_network(wpa_s
, ssid
);
2231 if (wpa_s
->reassociate
&& !wpa_s
->disconnected
) {
2232 if (wpa_s
->sched_scanning
) {
2233 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to add "
2234 "new network to scan filters");
2235 wpa_supplicant_cancel_sched_scan(wpa_s
);
2238 if (wpa_supplicant_fast_associate(wpa_s
) != 1)
2239 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2245 * wpa_supplicant_disable_network - Mark a configured network as disabled
2246 * @wpa_s: wpa_supplicant structure for a network interface
2247 * @ssid: wpa_ssid structure for a configured network or %NULL
2249 * Disables the specified network or all networks if no network specified.
2251 void wpa_supplicant_disable_network(struct wpa_supplicant
*wpa_s
,
2252 struct wpa_ssid
*ssid
)
2254 struct wpa_ssid
*other_ssid
;
2258 if (wpa_s
->sched_scanning
)
2259 wpa_supplicant_cancel_sched_scan(wpa_s
);
2261 for (other_ssid
= wpa_s
->conf
->ssid
; other_ssid
;
2262 other_ssid
= other_ssid
->next
) {
2263 was_disabled
= other_ssid
->disabled
;
2264 if (was_disabled
== 2)
2265 continue; /* do not change persistent P2P group
2268 other_ssid
->disabled
= 1;
2270 if (was_disabled
!= other_ssid
->disabled
)
2271 wpas_notify_network_enabled_changed(
2274 if (wpa_s
->current_ssid
)
2275 wpa_supplicant_deauthenticate(
2276 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2277 } else if (ssid
->disabled
!= 2) {
2278 if (ssid
== wpa_s
->current_ssid
)
2279 wpa_supplicant_deauthenticate(
2280 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2282 was_disabled
= ssid
->disabled
;
2286 if (was_disabled
!= ssid
->disabled
) {
2287 wpas_notify_network_enabled_changed(wpa_s
, ssid
);
2288 if (wpa_s
->sched_scanning
) {
2289 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan "
2290 "to remove network from filters");
2291 wpa_supplicant_cancel_sched_scan(wpa_s
);
2292 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2300 * wpa_supplicant_select_network - Attempt association with a network
2301 * @wpa_s: wpa_supplicant structure for a network interface
2302 * @ssid: wpa_ssid structure for a configured network or %NULL for any network
2304 void wpa_supplicant_select_network(struct wpa_supplicant
*wpa_s
,
2305 struct wpa_ssid
*ssid
)
2308 struct wpa_ssid
*other_ssid
;
2309 int disconnected
= 0;
2311 if (ssid
&& ssid
!= wpa_s
->current_ssid
&& wpa_s
->current_ssid
) {
2312 wpa_supplicant_deauthenticate(
2313 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2318 wpas_clear_temp_disabled(wpa_s
, ssid
, 1);
2321 * Mark all other networks disabled or mark all networks enabled if no
2322 * network specified.
2324 for (other_ssid
= wpa_s
->conf
->ssid
; other_ssid
;
2325 other_ssid
= other_ssid
->next
) {
2326 int was_disabled
= other_ssid
->disabled
;
2327 if (was_disabled
== 2)
2328 continue; /* do not change persistent P2P group data */
2330 other_ssid
->disabled
= ssid
? (ssid
->id
!= other_ssid
->id
) : 0;
2331 if (was_disabled
&& !other_ssid
->disabled
)
2332 wpas_clear_temp_disabled(wpa_s
, other_ssid
, 0);
2334 if (was_disabled
!= other_ssid
->disabled
)
2335 wpas_notify_network_enabled_changed(wpa_s
, other_ssid
);
2338 if (ssid
&& ssid
== wpa_s
->current_ssid
&& wpa_s
->current_ssid
) {
2339 /* We are already associated with the selected network */
2340 wpa_printf(MSG_DEBUG
, "Already associated with the "
2341 "selected network - do nothing");
2346 wpa_s
->current_ssid
= ssid
;
2347 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
2348 wpa_s
->connect_without_scan
=
2349 (ssid
->mode
== WPAS_MODE_MESH
) ? ssid
: NULL
;
2351 wpa_s
->connect_without_scan
= NULL
;
2354 wpa_s
->disconnected
= 0;
2355 wpa_s
->reassociate
= 1;
2357 if (wpa_s
->connect_without_scan
||
2358 wpa_supplicant_fast_associate(wpa_s
) != 1)
2359 wpa_supplicant_req_scan(wpa_s
, 0, disconnected
? 100000 : 0);
2362 wpas_notify_network_selected(wpa_s
, ssid
);
2367 * wpas_set_pkcs11_engine_and_module_path - Set PKCS #11 engine and module path
2368 * @wpa_s: wpa_supplicant structure for a network interface
2369 * @pkcs11_engine_path: PKCS #11 engine path or NULL
2370 * @pkcs11_module_path: PKCS #11 module path or NULL
2371 * Returns: 0 on success; -1 on failure
2373 * Sets the PKCS #11 engine and module path. Both have to be NULL or a valid
2374 * path. If resetting the EAPOL state machine with the new PKCS #11 engine and
2375 * module path fails the paths will be reset to the default value (NULL).
2377 int wpas_set_pkcs11_engine_and_module_path(struct wpa_supplicant
*wpa_s
,
2378 const char *pkcs11_engine_path
,
2379 const char *pkcs11_module_path
)
2381 char *pkcs11_engine_path_copy
= NULL
;
2382 char *pkcs11_module_path_copy
= NULL
;
2384 if (pkcs11_engine_path
!= NULL
) {
2385 pkcs11_engine_path_copy
= os_strdup(pkcs11_engine_path
);
2386 if (pkcs11_engine_path_copy
== NULL
)
2389 if (pkcs11_module_path
!= NULL
) {
2390 pkcs11_module_path_copy
= os_strdup(pkcs11_module_path
);
2391 if (pkcs11_module_path_copy
== NULL
) {
2392 os_free(pkcs11_engine_path_copy
);
2397 os_free(wpa_s
->conf
->pkcs11_engine_path
);
2398 os_free(wpa_s
->conf
->pkcs11_module_path
);
2399 wpa_s
->conf
->pkcs11_engine_path
= pkcs11_engine_path_copy
;
2400 wpa_s
->conf
->pkcs11_module_path
= pkcs11_module_path_copy
;
2402 wpa_sm_set_eapol(wpa_s
->wpa
, NULL
);
2403 eapol_sm_deinit(wpa_s
->eapol
);
2404 wpa_s
->eapol
= NULL
;
2405 if (wpa_supplicant_init_eapol(wpa_s
)) {
2406 /* Error -> Reset paths to the default value (NULL) once. */
2407 if (pkcs11_engine_path
!= NULL
&& pkcs11_module_path
!= NULL
)
2408 wpas_set_pkcs11_engine_and_module_path(wpa_s
, NULL
,
2413 wpa_sm_set_eapol(wpa_s
->wpa
, wpa_s
->eapol
);
2420 * wpa_supplicant_set_ap_scan - Set AP scan mode for interface
2421 * @wpa_s: wpa_supplicant structure for a network interface
2422 * @ap_scan: AP scan mode
2423 * Returns: 0 if succeed or -1 if ap_scan has an invalid value
2426 int wpa_supplicant_set_ap_scan(struct wpa_supplicant
*wpa_s
, int ap_scan
)
2431 if (ap_scan
< 0 || ap_scan
> 2)
2435 if (ap_scan
== 2 && ap_scan
!= wpa_s
->conf
->ap_scan
&&
2436 wpa_s
->wpa_state
>= WPA_ASSOCIATING
&&
2437 wpa_s
->wpa_state
< WPA_COMPLETED
) {
2438 wpa_printf(MSG_ERROR
, "ap_scan = %d (%d) rejected while "
2439 "associating", wpa_s
->conf
->ap_scan
, ap_scan
);
2442 #endif /* ANDROID */
2444 old_ap_scan
= wpa_s
->conf
->ap_scan
;
2445 wpa_s
->conf
->ap_scan
= ap_scan
;
2447 if (old_ap_scan
!= wpa_s
->conf
->ap_scan
)
2448 wpas_notify_ap_scan_changed(wpa_s
);
2455 * wpa_supplicant_set_bss_expiration_age - Set BSS entry expiration age
2456 * @wpa_s: wpa_supplicant structure for a network interface
2457 * @expire_age: Expiration age in seconds
2458 * Returns: 0 if succeed or -1 if expire_age has an invalid value
2461 int wpa_supplicant_set_bss_expiration_age(struct wpa_supplicant
*wpa_s
,
2462 unsigned int bss_expire_age
)
2464 if (bss_expire_age
< 10) {
2465 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid bss expiration age %u",
2469 wpa_msg(wpa_s
, MSG_DEBUG
, "Setting bss expiration age: %d sec",
2471 wpa_s
->conf
->bss_expiration_age
= bss_expire_age
;
2478 * wpa_supplicant_set_bss_expiration_count - Set BSS entry expiration scan count
2479 * @wpa_s: wpa_supplicant structure for a network interface
2480 * @expire_count: number of scans after which an unseen BSS is reclaimed
2481 * Returns: 0 if succeed or -1 if expire_count has an invalid value
2484 int wpa_supplicant_set_bss_expiration_count(struct wpa_supplicant
*wpa_s
,
2485 unsigned int bss_expire_count
)
2487 if (bss_expire_count
< 1) {
2488 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid bss expiration count %u",
2492 wpa_msg(wpa_s
, MSG_DEBUG
, "Setting bss expiration scan count: %u",
2494 wpa_s
->conf
->bss_expiration_scan_count
= bss_expire_count
;
2501 * wpa_supplicant_set_scan_interval - Set scan interval
2502 * @wpa_s: wpa_supplicant structure for a network interface
2503 * @scan_interval: scan interval in seconds
2504 * Returns: 0 if succeed or -1 if scan_interval has an invalid value
2507 int wpa_supplicant_set_scan_interval(struct wpa_supplicant
*wpa_s
,
2510 if (scan_interval
< 0) {
2511 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid scan interval %d",
2515 wpa_msg(wpa_s
, MSG_DEBUG
, "Setting scan interval: %d sec",
2517 wpa_supplicant_update_scan_int(wpa_s
, scan_interval
);
2524 * wpa_supplicant_set_debug_params - Set global debug params
2525 * @global: wpa_global structure
2526 * @debug_level: debug level
2527 * @debug_timestamp: determines if show timestamp in debug data
2528 * @debug_show_keys: determines if show keys in debug data
2529 * Returns: 0 if succeed or -1 if debug_level has wrong value
2531 int wpa_supplicant_set_debug_params(struct wpa_global
*global
, int debug_level
,
2532 int debug_timestamp
, int debug_show_keys
)
2535 int old_level
, old_timestamp
, old_show_keys
;
2537 /* check for allowed debuglevels */
2538 if (debug_level
!= MSG_EXCESSIVE
&&
2539 debug_level
!= MSG_MSGDUMP
&&
2540 debug_level
!= MSG_DEBUG
&&
2541 debug_level
!= MSG_INFO
&&
2542 debug_level
!= MSG_WARNING
&&
2543 debug_level
!= MSG_ERROR
)
2546 old_level
= wpa_debug_level
;
2547 old_timestamp
= wpa_debug_timestamp
;
2548 old_show_keys
= wpa_debug_show_keys
;
2550 wpa_debug_level
= debug_level
;
2551 wpa_debug_timestamp
= debug_timestamp
? 1 : 0;
2552 wpa_debug_show_keys
= debug_show_keys
? 1 : 0;
2554 if (wpa_debug_level
!= old_level
)
2555 wpas_notify_debug_level_changed(global
);
2556 if (wpa_debug_timestamp
!= old_timestamp
)
2557 wpas_notify_debug_timestamp_changed(global
);
2558 if (wpa_debug_show_keys
!= old_show_keys
)
2559 wpas_notify_debug_show_keys_changed(global
);
2566 * wpa_supplicant_get_ssid - Get a pointer to the current network structure
2567 * @wpa_s: Pointer to wpa_supplicant data
2568 * Returns: A pointer to the current network structure or %NULL on failure
2570 struct wpa_ssid
* wpa_supplicant_get_ssid(struct wpa_supplicant
*wpa_s
)
2572 struct wpa_ssid
*entry
;
2573 u8 ssid
[MAX_SSID_LEN
];
2579 res
= wpa_drv_get_ssid(wpa_s
, ssid
);
2581 wpa_msg(wpa_s
, MSG_WARNING
, "Could not read SSID from "
2587 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0) {
2588 wpa_msg(wpa_s
, MSG_WARNING
, "Could not read BSSID from "
2593 wired
= wpa_s
->conf
->ap_scan
== 0 &&
2594 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
);
2596 entry
= wpa_s
->conf
->ssid
;
2598 if (!wpas_network_disabled(wpa_s
, entry
) &&
2599 ((ssid_len
== entry
->ssid_len
&&
2600 os_memcmp(ssid
, entry
->ssid
, ssid_len
) == 0) || wired
) &&
2601 (!entry
->bssid_set
||
2602 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0))
2605 if (!wpas_network_disabled(wpa_s
, entry
) &&
2606 (entry
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
2607 (entry
->ssid
== NULL
|| entry
->ssid_len
== 0) &&
2608 (!entry
->bssid_set
||
2609 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0))
2611 #endif /* CONFIG_WPS */
2613 if (!wpas_network_disabled(wpa_s
, entry
) && entry
->bssid_set
&&
2614 entry
->ssid_len
== 0 &&
2615 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0)
2618 entry
= entry
->next
;
2625 static int select_driver(struct wpa_supplicant
*wpa_s
, int i
)
2627 struct wpa_global
*global
= wpa_s
->global
;
2629 if (wpa_drivers
[i
]->global_init
&& global
->drv_priv
[i
] == NULL
) {
2630 global
->drv_priv
[i
] = wpa_drivers
[i
]->global_init();
2631 if (global
->drv_priv
[i
] == NULL
) {
2632 wpa_printf(MSG_ERROR
, "Failed to initialize driver "
2633 "'%s'", wpa_drivers
[i
]->name
);
2638 wpa_s
->driver
= wpa_drivers
[i
];
2639 wpa_s
->global_drv_priv
= global
->drv_priv
[i
];
2645 static int wpa_supplicant_set_driver(struct wpa_supplicant
*wpa_s
,
2650 const char *pos
, *driver
= name
;
2655 if (wpa_drivers
[0] == NULL
) {
2656 wpa_msg(wpa_s
, MSG_ERROR
, "No driver interfaces build into "
2662 /* default to first driver in the list */
2663 return select_driver(wpa_s
, 0);
2667 pos
= os_strchr(driver
, ',');
2671 len
= os_strlen(driver
);
2673 for (i
= 0; wpa_drivers
[i
]; i
++) {
2674 if (os_strlen(wpa_drivers
[i
]->name
) == len
&&
2675 os_strncmp(driver
, wpa_drivers
[i
]->name
, len
) ==
2677 /* First driver that succeeds wins */
2678 if (select_driver(wpa_s
, i
) == 0)
2686 wpa_msg(wpa_s
, MSG_ERROR
, "Unsupported driver '%s'", name
);
2692 * wpa_supplicant_rx_eapol - Deliver a received EAPOL frame to wpa_supplicant
2693 * @ctx: Context pointer (wpa_s); this is the ctx variable registered
2694 * with struct wpa_driver_ops::init()
2695 * @src_addr: Source address of the EAPOL frame
2696 * @buf: EAPOL data starting from the EAPOL header (i.e., no Ethernet header)
2697 * @len: Length of the EAPOL data
2699 * This function is called for each received EAPOL frame. Most driver
2700 * interfaces rely on more generic OS mechanism for receiving frames through
2701 * l2_packet, but if such a mechanism is not available, the driver wrapper may
2702 * take care of received EAPOL frames and deliver them to the core supplicant
2703 * code by calling this function.
2705 void wpa_supplicant_rx_eapol(void *ctx
, const u8
*src_addr
,
2706 const u8
*buf
, size_t len
)
2708 struct wpa_supplicant
*wpa_s
= ctx
;
2710 wpa_dbg(wpa_s
, MSG_DEBUG
, "RX EAPOL from " MACSTR
, MAC2STR(src_addr
));
2711 wpa_hexdump(MSG_MSGDUMP
, "RX EAPOL", buf
, len
);
2713 #ifdef CONFIG_PEERKEY
2714 if (wpa_s
->wpa_state
> WPA_ASSOCIATED
&& wpa_s
->current_ssid
&&
2715 wpa_s
->current_ssid
->peerkey
&&
2716 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
2717 wpa_sm_rx_eapol_peerkey(wpa_s
->wpa
, src_addr
, buf
, len
) == 1) {
2718 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: Processed PeerKey EAPOL-Key");
2721 #endif /* CONFIG_PEERKEY */
2723 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
||
2724 (wpa_s
->last_eapol_matches_bssid
&&
2727 #endif /* CONFIG_AP */
2728 os_memcmp(src_addr
, wpa_s
->bssid
, ETH_ALEN
) != 0)) {
2730 * There is possible race condition between receiving the
2731 * association event and the EAPOL frame since they are coming
2732 * through different paths from the driver. In order to avoid
2733 * issues in trying to process the EAPOL frame before receiving
2734 * association information, lets queue it for processing until
2735 * the association event is received. This may also be needed in
2736 * driver-based roaming case, so also use src_addr != BSSID as a
2737 * trigger if we have previously confirmed that the
2738 * Authenticator uses BSSID as the src_addr (which is not the
2739 * case with wired IEEE 802.1X).
2741 wpa_dbg(wpa_s
, MSG_DEBUG
, "Not associated - Delay processing "
2742 "of received EAPOL frame (state=%s bssid=" MACSTR
")",
2743 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
2744 MAC2STR(wpa_s
->bssid
));
2745 wpabuf_free(wpa_s
->pending_eapol_rx
);
2746 wpa_s
->pending_eapol_rx
= wpabuf_alloc_copy(buf
, len
);
2747 if (wpa_s
->pending_eapol_rx
) {
2748 os_get_reltime(&wpa_s
->pending_eapol_rx_time
);
2749 os_memcpy(wpa_s
->pending_eapol_rx_src
, src_addr
,
2755 wpa_s
->last_eapol_matches_bssid
=
2756 os_memcmp(src_addr
, wpa_s
->bssid
, ETH_ALEN
) == 0;
2759 if (wpa_s
->ap_iface
) {
2760 wpa_supplicant_ap_rx_eapol(wpa_s
, src_addr
, buf
, len
);
2763 #endif /* CONFIG_AP */
2765 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
) {
2766 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignored received EAPOL frame since "
2767 "no key management is configured");
2771 if (wpa_s
->eapol_received
== 0 &&
2772 (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) ||
2773 !wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
2774 wpa_s
->wpa_state
!= WPA_COMPLETED
) &&
2775 (wpa_s
->current_ssid
== NULL
||
2776 wpa_s
->current_ssid
->mode
!= IEEE80211_MODE_IBSS
)) {
2777 /* Timeout for completing IEEE 802.1X and WPA authentication */
2778 wpa_supplicant_req_auth_timeout(
2780 (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
2781 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
||
2782 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
) ?
2785 wpa_s
->eapol_received
++;
2787 if (wpa_s
->countermeasures
) {
2788 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Countermeasures - dropped "
2793 #ifdef CONFIG_IBSS_RSN
2794 if (wpa_s
->current_ssid
&&
2795 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
) {
2796 ibss_rsn_rx_eapol(wpa_s
->ibss_rsn
, src_addr
, buf
, len
);
2799 #endif /* CONFIG_IBSS_RSN */
2801 /* Source address of the incoming EAPOL frame could be compared to the
2802 * current BSSID. However, it is possible that a centralized
2803 * Authenticator could be using another MAC address than the BSSID of
2804 * an AP, so just allow any address to be used for now. The replies are
2805 * still sent to the current BSSID (if available), though. */
2807 os_memcpy(wpa_s
->last_eapol_src
, src_addr
, ETH_ALEN
);
2808 if (!wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) &&
2809 eapol_sm_rx_eapol(wpa_s
->eapol
, src_addr
, buf
, len
) > 0)
2811 wpa_drv_poll(wpa_s
);
2812 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
))
2813 wpa_sm_rx_eapol(wpa_s
->wpa
, src_addr
, buf
, len
);
2814 else if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2816 * Set portValid = TRUE here since we are going to skip 4-way
2817 * handshake processing which would normally set portValid. We
2818 * need this to allow the EAPOL state machines to be completed
2819 * without going through EAPOL-Key handshake.
2821 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2826 int wpa_supplicant_update_mac_addr(struct wpa_supplicant
*wpa_s
)
2828 if ((!wpa_s
->p2p_mgmt
||
2829 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
)) &&
2830 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE
)) {
2831 l2_packet_deinit(wpa_s
->l2
);
2832 wpa_s
->l2
= l2_packet_init(wpa_s
->ifname
,
2833 wpa_drv_get_mac_addr(wpa_s
),
2835 wpa_supplicant_rx_eapol
, wpa_s
, 0);
2836 if (wpa_s
->l2
== NULL
)
2839 const u8
*addr
= wpa_drv_get_mac_addr(wpa_s
);
2841 os_memcpy(wpa_s
->own_addr
, addr
, ETH_ALEN
);
2844 if (wpa_s
->l2
&& l2_packet_get_own_addr(wpa_s
->l2
, wpa_s
->own_addr
)) {
2845 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to get own L2 address");
2849 wpa_sm_set_own_addr(wpa_s
->wpa
, wpa_s
->own_addr
);
2855 static void wpa_supplicant_rx_eapol_bridge(void *ctx
, const u8
*src_addr
,
2856 const u8
*buf
, size_t len
)
2858 struct wpa_supplicant
*wpa_s
= ctx
;
2859 const struct l2_ethhdr
*eth
;
2861 if (len
< sizeof(*eth
))
2863 eth
= (const struct l2_ethhdr
*) buf
;
2865 if (os_memcmp(eth
->h_dest
, wpa_s
->own_addr
, ETH_ALEN
) != 0 &&
2866 !(eth
->h_dest
[0] & 0x01)) {
2867 wpa_dbg(wpa_s
, MSG_DEBUG
, "RX EAPOL from " MACSTR
" to " MACSTR
2868 " (bridge - not for this interface - ignore)",
2869 MAC2STR(src_addr
), MAC2STR(eth
->h_dest
));
2873 wpa_dbg(wpa_s
, MSG_DEBUG
, "RX EAPOL from " MACSTR
" to " MACSTR
2874 " (bridge)", MAC2STR(src_addr
), MAC2STR(eth
->h_dest
));
2875 wpa_supplicant_rx_eapol(wpa_s
, src_addr
, buf
+ sizeof(*eth
),
2876 len
- sizeof(*eth
));
2881 * wpa_supplicant_driver_init - Initialize driver interface parameters
2882 * @wpa_s: Pointer to wpa_supplicant data
2883 * Returns: 0 on success, -1 on failure
2885 * This function is called to initialize driver interface parameters.
2886 * wpa_drv_init() must have been called before this function to initialize the
2889 int wpa_supplicant_driver_init(struct wpa_supplicant
*wpa_s
)
2891 static int interface_count
= 0;
2893 if (wpa_supplicant_update_mac_addr(wpa_s
) < 0)
2896 wpa_dbg(wpa_s
, MSG_DEBUG
, "Own MAC address: " MACSTR
,
2897 MAC2STR(wpa_s
->own_addr
));
2898 os_memcpy(wpa_s
->perm_addr
, wpa_s
->own_addr
, ETH_ALEN
);
2899 wpa_sm_set_own_addr(wpa_s
->wpa
, wpa_s
->own_addr
);
2901 if (wpa_s
->bridge_ifname
[0]) {
2902 wpa_dbg(wpa_s
, MSG_DEBUG
, "Receiving packets from bridge "
2903 "interface '%s'", wpa_s
->bridge_ifname
);
2904 wpa_s
->l2_br
= l2_packet_init(wpa_s
->bridge_ifname
,
2907 wpa_supplicant_rx_eapol_bridge
,
2909 if (wpa_s
->l2_br
== NULL
) {
2910 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to open l2_packet "
2911 "connection for the bridge interface '%s'",
2912 wpa_s
->bridge_ifname
);
2917 wpa_clear_keys(wpa_s
, NULL
);
2919 /* Make sure that TKIP countermeasures are not left enabled (could
2920 * happen if wpa_supplicant is killed during countermeasures. */
2921 wpa_drv_set_countermeasures(wpa_s
, 0);
2923 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: flushing PMKID list in the driver");
2924 wpa_drv_flush_pmkid(wpa_s
);
2926 wpa_s
->prev_scan_ssid
= WILDCARD_SSID_SCAN
;
2927 wpa_s
->prev_scan_wildcard
= 0;
2929 if (wpa_supplicant_enabled_networks(wpa_s
)) {
2930 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
2931 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
2932 interface_count
= 0;
2935 if (!wpa_s
->p2p_mgmt
&&
2936 wpa_supplicant_delayed_sched_scan(wpa_s
,
2937 interface_count
% 3,
2939 wpa_supplicant_req_scan(wpa_s
, interface_count
% 3,
2941 #endif /* ANDROID */
2944 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
2950 static int wpa_supplicant_daemon(const char *pid_file
)
2952 wpa_printf(MSG_DEBUG
, "Daemonize..");
2953 return os_daemonize(pid_file
);
2957 static struct wpa_supplicant
* wpa_supplicant_alloc(void)
2959 struct wpa_supplicant
*wpa_s
;
2961 wpa_s
= os_zalloc(sizeof(*wpa_s
));
2964 wpa_s
->scan_req
= INITIAL_SCAN_REQ
;
2965 wpa_s
->scan_interval
= 5;
2966 wpa_s
->new_connection
= 1;
2967 wpa_s
->parent
= wpa_s
;
2968 wpa_s
->sched_scanning
= 0;
2974 #ifdef CONFIG_HT_OVERRIDES
2976 static int wpa_set_htcap_mcs(struct wpa_supplicant
*wpa_s
,
2977 struct ieee80211_ht_capabilities
*htcaps
,
2978 struct ieee80211_ht_capabilities
*htcaps_mask
,
2981 /* parse ht_mcs into hex array */
2983 const char *tmp
= ht_mcs
;
2986 /* If ht_mcs is null, do not set anything */
2990 /* This is what we are setting in the kernel */
2991 os_memset(&htcaps
->supported_mcs_set
, 0, IEEE80211_HT_MCS_MASK_LEN
);
2993 wpa_msg(wpa_s
, MSG_DEBUG
, "set_htcap, ht_mcs -:%s:-", ht_mcs
);
2995 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++) {
2997 long v
= strtol(tmp
, &end
, 16);
2999 wpa_msg(wpa_s
, MSG_DEBUG
,
3000 "htcap value[%i]: %ld end: %p tmp: %p",
3005 htcaps
->supported_mcs_set
[i
] = v
;
3008 wpa_msg(wpa_s
, MSG_ERROR
,
3009 "Failed to parse ht-mcs: %s, error: %s\n",
3010 ht_mcs
, strerror(errno
));
3016 * If we were able to parse any values, then set mask for the MCS set.
3019 os_memset(&htcaps_mask
->supported_mcs_set
, 0xff,
3020 IEEE80211_HT_MCS_MASK_LEN
- 1);
3021 /* skip the 3 reserved bits */
3022 htcaps_mask
->supported_mcs_set
[IEEE80211_HT_MCS_MASK_LEN
- 1] =
3030 static int wpa_disable_max_amsdu(struct wpa_supplicant
*wpa_s
,
3031 struct ieee80211_ht_capabilities
*htcaps
,
3032 struct ieee80211_ht_capabilities
*htcaps_mask
,
3037 wpa_msg(wpa_s
, MSG_DEBUG
, "set_disable_max_amsdu: %d", disabled
);
3042 msk
= host_to_le16(HT_CAP_INFO_MAX_AMSDU_SIZE
);
3043 htcaps_mask
->ht_capabilities_info
|= msk
;
3045 htcaps
->ht_capabilities_info
&= msk
;
3047 htcaps
->ht_capabilities_info
|= msk
;
3053 static int wpa_set_ampdu_factor(struct wpa_supplicant
*wpa_s
,
3054 struct ieee80211_ht_capabilities
*htcaps
,
3055 struct ieee80211_ht_capabilities
*htcaps_mask
,
3058 wpa_msg(wpa_s
, MSG_DEBUG
, "set_ampdu_factor: %d", factor
);
3063 if (factor
< 0 || factor
> 3) {
3064 wpa_msg(wpa_s
, MSG_ERROR
, "ampdu_factor: %d out of range. "
3065 "Must be 0-3 or -1", factor
);
3069 htcaps_mask
->a_mpdu_params
|= 0x3; /* 2 bits for factor */
3070 htcaps
->a_mpdu_params
&= ~0x3;
3071 htcaps
->a_mpdu_params
|= factor
& 0x3;
3077 static int wpa_set_ampdu_density(struct wpa_supplicant
*wpa_s
,
3078 struct ieee80211_ht_capabilities
*htcaps
,
3079 struct ieee80211_ht_capabilities
*htcaps_mask
,
3082 wpa_msg(wpa_s
, MSG_DEBUG
, "set_ampdu_density: %d", density
);
3087 if (density
< 0 || density
> 7) {
3088 wpa_msg(wpa_s
, MSG_ERROR
,
3089 "ampdu_density: %d out of range. Must be 0-7 or -1.",
3094 htcaps_mask
->a_mpdu_params
|= 0x1C;
3095 htcaps
->a_mpdu_params
&= ~(0x1C);
3096 htcaps
->a_mpdu_params
|= (density
<< 2) & 0x1C;
3102 static int wpa_set_disable_ht40(struct wpa_supplicant
*wpa_s
,
3103 struct ieee80211_ht_capabilities
*htcaps
,
3104 struct ieee80211_ht_capabilities
*htcaps_mask
,
3107 /* Masking these out disables HT40 */
3108 le16 msk
= host_to_le16(HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
|
3109 HT_CAP_INFO_SHORT_GI40MHZ
);
3111 wpa_msg(wpa_s
, MSG_DEBUG
, "set_disable_ht40: %d", disabled
);
3114 htcaps
->ht_capabilities_info
&= ~msk
;
3116 htcaps
->ht_capabilities_info
|= msk
;
3118 htcaps_mask
->ht_capabilities_info
|= msk
;
3124 static int wpa_set_disable_sgi(struct wpa_supplicant
*wpa_s
,
3125 struct ieee80211_ht_capabilities
*htcaps
,
3126 struct ieee80211_ht_capabilities
*htcaps_mask
,
3129 /* Masking these out disables SGI */
3130 le16 msk
= host_to_le16(HT_CAP_INFO_SHORT_GI20MHZ
|
3131 HT_CAP_INFO_SHORT_GI40MHZ
);
3133 wpa_msg(wpa_s
, MSG_DEBUG
, "set_disable_sgi: %d", disabled
);
3136 htcaps
->ht_capabilities_info
&= ~msk
;
3138 htcaps
->ht_capabilities_info
|= msk
;
3140 htcaps_mask
->ht_capabilities_info
|= msk
;
3146 static int wpa_set_disable_ldpc(struct wpa_supplicant
*wpa_s
,
3147 struct ieee80211_ht_capabilities
*htcaps
,
3148 struct ieee80211_ht_capabilities
*htcaps_mask
,
3151 /* Masking these out disables LDPC */
3152 le16 msk
= host_to_le16(HT_CAP_INFO_LDPC_CODING_CAP
);
3154 wpa_msg(wpa_s
, MSG_DEBUG
, "set_disable_ldpc: %d", disabled
);
3157 htcaps
->ht_capabilities_info
&= ~msk
;
3159 htcaps
->ht_capabilities_info
|= msk
;
3161 htcaps_mask
->ht_capabilities_info
|= msk
;
3167 void wpa_supplicant_apply_ht_overrides(
3168 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
3169 struct wpa_driver_associate_params
*params
)
3171 struct ieee80211_ht_capabilities
*htcaps
;
3172 struct ieee80211_ht_capabilities
*htcaps_mask
;
3177 params
->disable_ht
= ssid
->disable_ht
;
3178 if (!params
->htcaps
|| !params
->htcaps_mask
)
3181 htcaps
= (struct ieee80211_ht_capabilities
*) params
->htcaps
;
3182 htcaps_mask
= (struct ieee80211_ht_capabilities
*) params
->htcaps_mask
;
3183 wpa_set_htcap_mcs(wpa_s
, htcaps
, htcaps_mask
, ssid
->ht_mcs
);
3184 wpa_disable_max_amsdu(wpa_s
, htcaps
, htcaps_mask
,
3185 ssid
->disable_max_amsdu
);
3186 wpa_set_ampdu_factor(wpa_s
, htcaps
, htcaps_mask
, ssid
->ampdu_factor
);
3187 wpa_set_ampdu_density(wpa_s
, htcaps
, htcaps_mask
, ssid
->ampdu_density
);
3188 wpa_set_disable_ht40(wpa_s
, htcaps
, htcaps_mask
, ssid
->disable_ht40
);
3189 wpa_set_disable_sgi(wpa_s
, htcaps
, htcaps_mask
, ssid
->disable_sgi
);
3190 wpa_set_disable_ldpc(wpa_s
, htcaps
, htcaps_mask
, ssid
->disable_ldpc
);
3192 if (ssid
->ht40_intolerant
) {
3193 le16 bit
= host_to_le16(HT_CAP_INFO_40MHZ_INTOLERANT
);
3194 htcaps
->ht_capabilities_info
|= bit
;
3195 htcaps_mask
->ht_capabilities_info
|= bit
;
3199 #endif /* CONFIG_HT_OVERRIDES */
3202 #ifdef CONFIG_VHT_OVERRIDES
3203 void wpa_supplicant_apply_vht_overrides(
3204 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
3205 struct wpa_driver_associate_params
*params
)
3207 struct ieee80211_vht_capabilities
*vhtcaps
;
3208 struct ieee80211_vht_capabilities
*vhtcaps_mask
;
3213 params
->disable_vht
= ssid
->disable_vht
;
3215 vhtcaps
= (void *) params
->vhtcaps
;
3216 vhtcaps_mask
= (void *) params
->vhtcaps_mask
;
3218 if (!vhtcaps
|| !vhtcaps_mask
)
3221 vhtcaps
->vht_capabilities_info
= ssid
->vht_capa
;
3222 vhtcaps_mask
->vht_capabilities_info
= ssid
->vht_capa_mask
;
3224 #ifdef CONFIG_HT_OVERRIDES
3225 /* if max ampdu is <= 3, we have to make the HT cap the same */
3226 if (ssid
->vht_capa_mask
& VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX
) {
3229 max_ampdu
= (ssid
->vht_capa
&
3230 VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX
) >>
3231 VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX_SHIFT
;
3233 max_ampdu
= max_ampdu
< 3 ? max_ampdu
: 3;
3234 wpa_set_ampdu_factor(wpa_s
,
3235 (void *) params
->htcaps
,
3236 (void *) params
->htcaps_mask
,
3239 #endif /* CONFIG_HT_OVERRIDES */
3241 #define OVERRIDE_MCS(i) \
3242 if (ssid->vht_tx_mcs_nss_ ##i >= 0) { \
3243 vhtcaps_mask->vht_supported_mcs_set.tx_map |= \
3245 vhtcaps->vht_supported_mcs_set.tx_map |= \
3246 ssid->vht_tx_mcs_nss_ ##i << 2 * (i - 1); \
3248 if (ssid->vht_rx_mcs_nss_ ##i >= 0) { \
3249 vhtcaps_mask->vht_supported_mcs_set.rx_map |= \
3251 vhtcaps->vht_supported_mcs_set.rx_map |= \
3252 ssid->vht_rx_mcs_nss_ ##i << 2 * (i - 1); \
3264 #endif /* CONFIG_VHT_OVERRIDES */
3267 static int pcsc_reader_init(struct wpa_supplicant
*wpa_s
)
3272 if (!wpa_s
->conf
->pcsc_reader
)
3275 wpa_s
->scard
= scard_init(wpa_s
->conf
->pcsc_reader
);
3279 if (wpa_s
->conf
->pcsc_pin
&&
3280 scard_set_pin(wpa_s
->scard
, wpa_s
->conf
->pcsc_pin
) < 0) {
3281 scard_deinit(wpa_s
->scard
);
3282 wpa_s
->scard
= NULL
;
3283 wpa_msg(wpa_s
, MSG_ERROR
, "PC/SC PIN validation failed");
3287 len
= sizeof(wpa_s
->imsi
) - 1;
3288 if (scard_get_imsi(wpa_s
->scard
, wpa_s
->imsi
, &len
)) {
3289 scard_deinit(wpa_s
->scard
);
3290 wpa_s
->scard
= NULL
;
3291 wpa_msg(wpa_s
, MSG_ERROR
, "Could not read IMSI");
3294 wpa_s
->imsi
[len
] = '\0';
3296 wpa_s
->mnc_len
= scard_get_mnc_len(wpa_s
->scard
);
3298 wpa_printf(MSG_DEBUG
, "SCARD: IMSI %s (MNC length %d)",
3299 wpa_s
->imsi
, wpa_s
->mnc_len
);
3301 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
3302 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
3303 #endif /* PCSC_FUNCS */
3309 int wpas_init_ext_pw(struct wpa_supplicant
*wpa_s
)
3313 ext_password_deinit(wpa_s
->ext_pw
);
3314 wpa_s
->ext_pw
= NULL
;
3315 eapol_sm_set_ext_pw_ctx(wpa_s
->eapol
, NULL
);
3317 if (!wpa_s
->conf
->ext_password_backend
)
3320 val
= os_strdup(wpa_s
->conf
->ext_password_backend
);
3323 pos
= os_strchr(val
, ':');
3327 wpa_printf(MSG_DEBUG
, "EXT PW: Initialize backend '%s'", val
);
3329 wpa_s
->ext_pw
= ext_password_init(val
, pos
);
3331 if (wpa_s
->ext_pw
== NULL
) {
3332 wpa_printf(MSG_DEBUG
, "EXT PW: Failed to initialize backend");
3335 eapol_sm_set_ext_pw_ctx(wpa_s
->eapol
, wpa_s
->ext_pw
);
3341 static int wpas_set_wowlan_triggers(struct wpa_supplicant
*wpa_s
,
3342 const struct wpa_driver_capa
*capa
)
3344 struct wowlan_triggers
*triggers
;
3347 if (!wpa_s
->conf
->wowlan_triggers
)
3350 triggers
= wpa_get_wowlan_triggers(wpa_s
->conf
->wowlan_triggers
, capa
);
3352 ret
= wpa_drv_wowlan(wpa_s
, triggers
);
3359 static struct wpa_radio
* radio_add_interface(struct wpa_supplicant
*wpa_s
,
3362 struct wpa_supplicant
*iface
= wpa_s
->global
->ifaces
;
3363 struct wpa_radio
*radio
;
3365 while (rn
&& iface
) {
3366 radio
= iface
->radio
;
3367 if (radio
&& os_strcmp(rn
, radio
->name
) == 0) {
3368 wpa_printf(MSG_DEBUG
, "Add interface %s to existing radio %s",
3370 dl_list_add(&radio
->ifaces
, &wpa_s
->radio_list
);
3374 iface
= iface
->next
;
3377 wpa_printf(MSG_DEBUG
, "Add interface %s to a new radio %s",
3378 wpa_s
->ifname
, rn
? rn
: "N/A");
3379 radio
= os_zalloc(sizeof(*radio
));
3384 os_strlcpy(radio
->name
, rn
, sizeof(radio
->name
));
3385 dl_list_init(&radio
->ifaces
);
3386 dl_list_init(&radio
->work
);
3387 dl_list_add(&radio
->ifaces
, &wpa_s
->radio_list
);
3393 static void radio_work_free(struct wpa_radio_work
*work
)
3395 if (work
->wpa_s
->scan_work
== work
) {
3396 /* This should not really happen. */
3397 wpa_dbg(work
->wpa_s
, MSG_INFO
, "Freeing radio work '%s'@%p (started=%d) that is marked as scan_work",
3398 work
->type
, work
, work
->started
);
3399 work
->wpa_s
->scan_work
= NULL
;
3403 if (work
->wpa_s
->p2p_scan_work
== work
) {
3404 /* This should not really happen. */
3405 wpa_dbg(work
->wpa_s
, MSG_INFO
, "Freeing radio work '%s'@%p (started=%d) that is marked as p2p_scan_work",
3406 work
->type
, work
, work
->started
);
3407 work
->wpa_s
->p2p_scan_work
= NULL
;
3409 #endif /* CONFIG_P2P */
3411 dl_list_del(&work
->list
);
3416 static void radio_start_next_work(void *eloop_ctx
, void *timeout_ctx
)
3418 struct wpa_radio
*radio
= eloop_ctx
;
3419 struct wpa_radio_work
*work
;
3420 struct os_reltime now
, diff
;
3421 struct wpa_supplicant
*wpa_s
;
3423 work
= dl_list_first(&radio
->work
, struct wpa_radio_work
, list
);
3428 return; /* already started and still in progress */
3430 wpa_s
= dl_list_first(&radio
->ifaces
, struct wpa_supplicant
,
3432 if (wpa_s
&& wpa_s
->external_scan_running
) {
3433 wpa_printf(MSG_DEBUG
, "Delay radio work start until externally triggered scan completes");
3437 os_get_reltime(&now
);
3438 os_reltime_sub(&now
, &work
->time
, &diff
);
3439 wpa_dbg(work
->wpa_s
, MSG_DEBUG
, "Starting radio work '%s'@%p after %ld.%06ld second wait",
3440 work
->type
, work
, diff
.sec
, diff
.usec
);
3448 * This function removes both started and pending radio works running on
3449 * the provided interface's radio.
3450 * Prior to the removal of the radio work, its callback (cb) is called with
3451 * deinit set to be 1. Each work's callback is responsible for clearing its
3452 * internal data and restoring to a correct state.
3453 * @wpa_s: wpa_supplicant data
3454 * @type: type of works to be removed
3455 * @remove_all: 1 to remove all the works on this radio, 0 to remove only
3456 * this interface's works.
3458 void radio_remove_works(struct wpa_supplicant
*wpa_s
,
3459 const char *type
, int remove_all
)
3461 struct wpa_radio_work
*work
, *tmp
;
3462 struct wpa_radio
*radio
= wpa_s
->radio
;
3464 dl_list_for_each_safe(work
, tmp
, &radio
->work
, struct wpa_radio_work
,
3466 if (type
&& os_strcmp(type
, work
->type
) != 0)
3469 /* skip other ifaces' works */
3470 if (!remove_all
&& work
->wpa_s
!= wpa_s
)
3473 wpa_dbg(wpa_s
, MSG_DEBUG
, "Remove radio work '%s'@%p%s",
3474 work
->type
, work
, work
->started
? " (started)" : "");
3476 radio_work_free(work
);
3479 /* in case we removed the started work */
3480 radio_work_check_next(wpa_s
);
3484 static void radio_remove_interface(struct wpa_supplicant
*wpa_s
)
3486 struct wpa_radio
*radio
= wpa_s
->radio
;
3491 wpa_printf(MSG_DEBUG
, "Remove interface %s from radio %s",
3492 wpa_s
->ifname
, radio
->name
);
3493 dl_list_del(&wpa_s
->radio_list
);
3494 radio_remove_works(wpa_s
, NULL
, 0);
3495 wpa_s
->radio
= NULL
;
3496 if (!dl_list_empty(&radio
->ifaces
))
3497 return; /* Interfaces remain for this radio */
3499 wpa_printf(MSG_DEBUG
, "Remove radio %s", radio
->name
);
3500 eloop_cancel_timeout(radio_start_next_work
, radio
, NULL
);
3505 void radio_work_check_next(struct wpa_supplicant
*wpa_s
)
3507 struct wpa_radio
*radio
= wpa_s
->radio
;
3509 if (dl_list_empty(&radio
->work
))
3511 if (wpa_s
->ext_work_in_progress
) {
3512 wpa_printf(MSG_DEBUG
,
3513 "External radio work in progress - delay start of pending item");
3516 eloop_cancel_timeout(radio_start_next_work
, radio
, NULL
);
3517 eloop_register_timeout(0, 0, radio_start_next_work
, radio
, NULL
);
3522 * radio_add_work - Add a radio work item
3523 * @wpa_s: Pointer to wpa_supplicant data
3524 * @freq: Frequency of the offchannel operation in MHz or 0
3525 * @type: Unique identifier for each type of work
3526 * @next: Force as the next work to be executed
3527 * @cb: Callback function for indicating when radio is available
3528 * @ctx: Context pointer for the work (work->ctx in cb())
3529 * Returns: 0 on success, -1 on failure
3531 * This function is used to request time for an operation that requires
3532 * exclusive radio control. Once the radio is available, the registered callback
3533 * function will be called. radio_work_done() must be called once the exclusive
3534 * radio operation has been completed, so that the radio is freed for other
3535 * operations. The special case of deinit=1 is used to free the context data
3536 * during interface removal. That does not allow the callback function to start
3537 * the radio operation, i.e., it must free any resources allocated for the radio
3540 * The @freq parameter can be used to indicate a single channel on which the
3541 * offchannel operation will occur. This may allow multiple radio work
3542 * operations to be performed in parallel if they apply for the same channel.
3543 * Setting this to 0 indicates that the work item may use multiple channels or
3544 * requires exclusive control of the radio.
3546 int radio_add_work(struct wpa_supplicant
*wpa_s
, unsigned int freq
,
3547 const char *type
, int next
,
3548 void (*cb
)(struct wpa_radio_work
*work
, int deinit
),
3551 struct wpa_radio_work
*work
;
3554 work
= os_zalloc(sizeof(*work
));
3557 wpa_dbg(wpa_s
, MSG_DEBUG
, "Add radio work '%s'@%p", type
, work
);
3558 os_get_reltime(&work
->time
);
3561 work
->wpa_s
= wpa_s
;
3565 was_empty
= dl_list_empty(&wpa_s
->radio
->work
);
3567 dl_list_add(&wpa_s
->radio
->work
, &work
->list
);
3569 dl_list_add_tail(&wpa_s
->radio
->work
, &work
->list
);
3571 wpa_dbg(wpa_s
, MSG_DEBUG
, "First radio work item in the queue - schedule start immediately");
3572 radio_work_check_next(wpa_s
);
3580 * radio_work_done - Indicate that a radio work item has been completed
3581 * @work: Completed work
3583 * This function is called once the callback function registered with
3584 * radio_add_work() has completed its work.
3586 void radio_work_done(struct wpa_radio_work
*work
)
3588 struct wpa_supplicant
*wpa_s
= work
->wpa_s
;
3589 struct os_reltime now
, diff
;
3590 unsigned int started
= work
->started
;
3592 os_get_reltime(&now
);
3593 os_reltime_sub(&now
, &work
->time
, &diff
);
3594 wpa_dbg(wpa_s
, MSG_DEBUG
, "Radio work '%s'@%p %s in %ld.%06ld seconds",
3595 work
->type
, work
, started
? "done" : "canceled",
3596 diff
.sec
, diff
.usec
);
3597 radio_work_free(work
);
3599 radio_work_check_next(wpa_s
);
3603 struct wpa_radio_work
*
3604 radio_work_pending(struct wpa_supplicant
*wpa_s
, const char *type
)
3606 struct wpa_radio_work
*work
;
3607 struct wpa_radio
*radio
= wpa_s
->radio
;
3609 dl_list_for_each(work
, &radio
->work
, struct wpa_radio_work
, list
) {
3610 if (work
->wpa_s
== wpa_s
&& os_strcmp(work
->type
, type
) == 0)
3618 static int wpas_init_driver(struct wpa_supplicant
*wpa_s
,
3619 struct wpa_interface
*iface
)
3621 const char *ifname
, *driver
, *rn
;
3623 driver
= iface
->driver
;
3625 if (wpa_supplicant_set_driver(wpa_s
, driver
) < 0)
3628 wpa_s
->drv_priv
= wpa_drv_init(wpa_s
, wpa_s
->ifname
);
3629 if (wpa_s
->drv_priv
== NULL
) {
3631 pos
= driver
? os_strchr(driver
, ',') : NULL
;
3633 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to initialize "
3634 "driver interface - try next driver wrapper");
3638 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to initialize driver "
3642 if (wpa_drv_set_param(wpa_s
, wpa_s
->conf
->driver_param
) < 0) {
3643 wpa_msg(wpa_s
, MSG_ERROR
, "Driver interface rejected "
3644 "driver_param '%s'", wpa_s
->conf
->driver_param
);
3648 ifname
= wpa_drv_get_ifname(wpa_s
);
3649 if (ifname
&& os_strcmp(ifname
, wpa_s
->ifname
) != 0) {
3650 wpa_dbg(wpa_s
, MSG_DEBUG
, "Driver interface replaced "
3651 "interface name with '%s'", ifname
);
3652 os_strlcpy(wpa_s
->ifname
, ifname
, sizeof(wpa_s
->ifname
));
3655 rn
= wpa_driver_get_radio_name(wpa_s
);
3656 if (rn
&& rn
[0] == '\0')
3659 wpa_s
->radio
= radio_add_interface(wpa_s
, rn
);
3660 if (wpa_s
->radio
== NULL
)
3667 static int wpa_supplicant_init_iface(struct wpa_supplicant
*wpa_s
,
3668 struct wpa_interface
*iface
)
3670 struct wpa_driver_capa capa
;
3673 wpa_printf(MSG_DEBUG
, "Initializing interface '%s' conf '%s' driver "
3674 "'%s' ctrl_interface '%s' bridge '%s'", iface
->ifname
,
3675 iface
->confname
? iface
->confname
: "N/A",
3676 iface
->driver
? iface
->driver
: "default",
3677 iface
->ctrl_interface
? iface
->ctrl_interface
: "N/A",
3678 iface
->bridge_ifname
? iface
->bridge_ifname
: "N/A");
3680 if (iface
->confname
) {
3681 #ifdef CONFIG_BACKEND_FILE
3682 wpa_s
->confname
= os_rel2abs_path(iface
->confname
);
3683 if (wpa_s
->confname
== NULL
) {
3684 wpa_printf(MSG_ERROR
, "Failed to get absolute path "
3685 "for configuration file '%s'.",
3689 wpa_printf(MSG_DEBUG
, "Configuration file '%s' -> '%s'",
3690 iface
->confname
, wpa_s
->confname
);
3691 #else /* CONFIG_BACKEND_FILE */
3692 wpa_s
->confname
= os_strdup(iface
->confname
);
3693 #endif /* CONFIG_BACKEND_FILE */
3694 wpa_s
->conf
= wpa_config_read(wpa_s
->confname
, NULL
);
3695 if (wpa_s
->conf
== NULL
) {
3696 wpa_printf(MSG_ERROR
, "Failed to read or parse "
3697 "configuration '%s'.", wpa_s
->confname
);
3700 wpa_s
->confanother
= os_rel2abs_path(iface
->confanother
);
3701 wpa_config_read(wpa_s
->confanother
, wpa_s
->conf
);
3704 * Override ctrl_interface and driver_param if set on command
3707 if (iface
->ctrl_interface
) {
3708 os_free(wpa_s
->conf
->ctrl_interface
);
3709 wpa_s
->conf
->ctrl_interface
=
3710 os_strdup(iface
->ctrl_interface
);
3713 if (iface
->driver_param
) {
3714 os_free(wpa_s
->conf
->driver_param
);
3715 wpa_s
->conf
->driver_param
=
3716 os_strdup(iface
->driver_param
);
3719 if (iface
->p2p_mgmt
&& !iface
->ctrl_interface
) {
3720 os_free(wpa_s
->conf
->ctrl_interface
);
3721 wpa_s
->conf
->ctrl_interface
= NULL
;
3724 wpa_s
->conf
= wpa_config_alloc_empty(iface
->ctrl_interface
,
3725 iface
->driver_param
);
3727 if (wpa_s
->conf
== NULL
) {
3728 wpa_printf(MSG_ERROR
, "\nNo configuration found.");
3732 if (iface
->ifname
== NULL
) {
3733 wpa_printf(MSG_ERROR
, "\nInterface name is required.");
3736 if (os_strlen(iface
->ifname
) >= sizeof(wpa_s
->ifname
)) {
3737 wpa_printf(MSG_ERROR
, "\nToo long interface name '%s'.",
3741 os_strlcpy(wpa_s
->ifname
, iface
->ifname
, sizeof(wpa_s
->ifname
));
3743 if (iface
->bridge_ifname
) {
3744 if (os_strlen(iface
->bridge_ifname
) >=
3745 sizeof(wpa_s
->bridge_ifname
)) {
3746 wpa_printf(MSG_ERROR
, "\nToo long bridge interface "
3747 "name '%s'.", iface
->bridge_ifname
);
3750 os_strlcpy(wpa_s
->bridge_ifname
, iface
->bridge_ifname
,
3751 sizeof(wpa_s
->bridge_ifname
));
3754 /* RSNA Supplicant Key Management - INITIALIZE */
3755 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
3756 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
3758 /* Initialize driver interface and register driver event handler before
3759 * L2 receive handler so that association events are processed before
3760 * EAPOL-Key packets if both become available for the same select()
3762 if (wpas_init_driver(wpa_s
, iface
) < 0)
3765 if (wpa_supplicant_init_wpa(wpa_s
) < 0)
3768 wpa_sm_set_ifname(wpa_s
->wpa
, wpa_s
->ifname
,
3769 wpa_s
->bridge_ifname
[0] ? wpa_s
->bridge_ifname
:
3771 wpa_sm_set_fast_reauth(wpa_s
->wpa
, wpa_s
->conf
->fast_reauth
);
3773 if (wpa_s
->conf
->dot11RSNAConfigPMKLifetime
&&
3774 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
3775 wpa_s
->conf
->dot11RSNAConfigPMKLifetime
)) {
3776 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid WPA parameter value for "
3777 "dot11RSNAConfigPMKLifetime");
3781 if (wpa_s
->conf
->dot11RSNAConfigPMKReauthThreshold
&&
3782 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
3783 wpa_s
->conf
->dot11RSNAConfigPMKReauthThreshold
)) {
3784 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid WPA parameter value for "
3785 "dot11RSNAConfigPMKReauthThreshold");
3789 if (wpa_s
->conf
->dot11RSNAConfigSATimeout
&&
3790 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
,
3791 wpa_s
->conf
->dot11RSNAConfigSATimeout
)) {
3792 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid WPA parameter value for "
3793 "dot11RSNAConfigSATimeout");
3797 wpa_s
->hw
.modes
= wpa_drv_get_hw_feature_data(wpa_s
,
3798 &wpa_s
->hw
.num_modes
,
3801 capa_res
= wpa_drv_get_capa(wpa_s
, &capa
);
3802 if (capa_res
== 0) {
3803 wpa_s
->drv_capa_known
= 1;
3804 wpa_s
->drv_flags
= capa
.flags
;
3805 wpa_s
->drv_enc
= capa
.enc
;
3806 wpa_s
->drv_smps_modes
= capa
.smps_modes
;
3807 wpa_s
->drv_rrm_flags
= capa
.rrm_flags
;
3808 wpa_s
->probe_resp_offloads
= capa
.probe_resp_offloads
;
3809 wpa_s
->max_scan_ssids
= capa
.max_scan_ssids
;
3810 wpa_s
->max_sched_scan_ssids
= capa
.max_sched_scan_ssids
;
3811 wpa_s
->sched_scan_supported
= capa
.sched_scan_supported
;
3812 wpa_s
->max_match_sets
= capa
.max_match_sets
;
3813 wpa_s
->max_remain_on_chan
= capa
.max_remain_on_chan
;
3814 wpa_s
->max_stations
= capa
.max_stations
;
3815 wpa_s
->extended_capa
= capa
.extended_capa
;
3816 wpa_s
->extended_capa_mask
= capa
.extended_capa_mask
;
3817 wpa_s
->extended_capa_len
= capa
.extended_capa_len
;
3818 wpa_s
->num_multichan_concurrent
=
3819 capa
.num_multichan_concurrent
;
3820 wpa_s
->wmm_ac_supported
= capa
.wmm_ac_supported
;
3822 if (wpa_s
->max_remain_on_chan
== 0)
3823 wpa_s
->max_remain_on_chan
= 1000;
3826 * Only take p2p_mgmt parameters when P2P Device is supported.
3827 * Doing it here as it determines whether l2_packet_init() will be done
3828 * during wpa_supplicant_driver_init().
3830 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
)
3831 wpa_s
->p2p_mgmt
= iface
->p2p_mgmt
;
3833 iface
->p2p_mgmt
= 1;
3835 if (wpa_s
->num_multichan_concurrent
== 0)
3836 wpa_s
->num_multichan_concurrent
= 1;
3838 if (wpa_supplicant_driver_init(wpa_s
) < 0)
3842 if ((!iface
->p2p_mgmt
||
3843 !(wpa_s
->drv_flags
&
3844 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
)) &&
3845 wpa_tdls_init(wpa_s
->wpa
))
3847 #endif /* CONFIG_TDLS */
3849 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1] &&
3850 wpa_drv_set_country(wpa_s
, wpa_s
->conf
->country
)) {
3851 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to set country");
3855 if (wpas_wps_init(wpa_s
))
3858 if (wpa_supplicant_init_eapol(wpa_s
) < 0)
3860 wpa_sm_set_eapol(wpa_s
->wpa
, wpa_s
->eapol
);
3862 wpa_s
->ctrl_iface
= wpa_supplicant_ctrl_iface_init(wpa_s
);
3863 if (wpa_s
->ctrl_iface
== NULL
) {
3864 wpa_printf(MSG_ERROR
,
3865 "Failed to initialize control interface '%s'.\n"
3866 "You may have another wpa_supplicant process "
3867 "already running or the file was\n"
3868 "left by an unclean termination of wpa_supplicant "
3869 "in which case you will need\n"
3870 "to manually remove this file before starting "
3871 "wpa_supplicant again.\n",
3872 wpa_s
->conf
->ctrl_interface
);
3876 wpa_s
->gas
= gas_query_init(wpa_s
);
3877 if (wpa_s
->gas
== NULL
) {
3878 wpa_printf(MSG_ERROR
, "Failed to initialize GAS query");
3882 if (iface
->p2p_mgmt
&& wpas_p2p_init(wpa_s
->global
, wpa_s
) < 0) {
3883 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to init P2P");
3887 if (wpa_bss_init(wpa_s
) < 0)
3891 * Set Wake-on-WLAN triggers, if configured.
3892 * Note: We don't restore/remove the triggers on shutdown (it doesn't
3893 * have effect anyway when the interface is down).
3895 if (capa_res
== 0 && wpas_set_wowlan_triggers(wpa_s
, &capa
) < 0)
3898 #ifdef CONFIG_EAP_PROXY
3901 wpa_s
->mnc_len
= eapol_sm_get_eap_proxy_imsi(wpa_s
->eapol
, wpa_s
->imsi
,
3903 if (wpa_s
->mnc_len
> 0) {
3904 wpa_s
->imsi
[len
] = '\0';
3905 wpa_printf(MSG_DEBUG
, "eap_proxy: IMSI %s (MNC length %d)",
3906 wpa_s
->imsi
, wpa_s
->mnc_len
);
3908 wpa_printf(MSG_DEBUG
, "eap_proxy: IMSI not available");
3911 #endif /* CONFIG_EAP_PROXY */
3913 if (pcsc_reader_init(wpa_s
) < 0)
3916 if (wpas_init_ext_pw(wpa_s
) < 0)
3919 wpas_rrm_reset(wpa_s
);
3925 static void wpa_supplicant_deinit_iface(struct wpa_supplicant
*wpa_s
,
3926 int notify
, int terminate
)
3928 struct wpa_global
*global
= wpa_s
->global
;
3929 struct wpa_supplicant
*iface
, *prev
;
3931 if (wpa_s
== wpa_s
->parent
)
3932 wpas_p2p_group_remove(wpa_s
, "*");
3934 iface
= global
->ifaces
;
3936 if (iface
== wpa_s
|| iface
->parent
!= wpa_s
) {
3937 iface
= iface
->next
;
3940 wpa_printf(MSG_DEBUG
,
3941 "Remove remaining child interface %s from parent %s",
3942 iface
->ifname
, wpa_s
->ifname
);
3944 iface
= iface
->next
;
3945 wpa_supplicant_remove_iface(global
, prev
, terminate
);
3948 wpa_s
->disconnected
= 1;
3949 if (wpa_s
->drv_priv
) {
3950 wpa_supplicant_deauthenticate(wpa_s
,
3951 WLAN_REASON_DEAUTH_LEAVING
);
3953 wpa_drv_set_countermeasures(wpa_s
, 0);
3954 wpa_clear_keys(wpa_s
, NULL
);
3957 wpa_supplicant_cleanup(wpa_s
);
3958 wpas_p2p_deinit_iface(wpa_s
);
3960 wpas_ctrl_radio_work_flush(wpa_s
);
3961 radio_remove_interface(wpa_s
);
3963 if (wpa_s
->drv_priv
)
3964 wpa_drv_deinit(wpa_s
);
3967 wpas_notify_iface_removed(wpa_s
);
3970 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_TERMINATING
);
3972 if (wpa_s
->ctrl_iface
) {
3973 wpa_supplicant_ctrl_iface_deinit(wpa_s
->ctrl_iface
);
3974 wpa_s
->ctrl_iface
= NULL
;
3979 wpa_supplicant_mesh_iface_deinit(wpa_s
, wpa_s
->ifmsh
);
3980 wpa_s
->ifmsh
= NULL
;
3982 #endif /* CONFIG_MESH */
3984 if (wpa_s
->conf
!= NULL
) {
3985 wpa_config_free(wpa_s
->conf
);
3994 * wpa_supplicant_add_iface - Add a new network interface
3995 * @global: Pointer to global data from wpa_supplicant_init()
3996 * @iface: Interface configuration options
3997 * Returns: Pointer to the created interface or %NULL on failure
3999 * This function is used to add new network interfaces for %wpa_supplicant.
4000 * This can be called before wpa_supplicant_run() to add interfaces before the
4001 * main event loop has been started. In addition, new interfaces can be added
4002 * dynamically while %wpa_supplicant is already running. This could happen,
4003 * e.g., when a hotplug network adapter is inserted.
4005 struct wpa_supplicant
* wpa_supplicant_add_iface(struct wpa_global
*global
,
4006 struct wpa_interface
*iface
)
4008 struct wpa_supplicant
*wpa_s
;
4009 struct wpa_interface t_iface
;
4010 struct wpa_ssid
*ssid
;
4012 if (global
== NULL
|| iface
== NULL
)
4015 wpa_s
= wpa_supplicant_alloc();
4019 wpa_s
->global
= global
;
4022 if (global
->params
.override_driver
) {
4023 wpa_printf(MSG_DEBUG
, "Override interface parameter: driver "
4025 iface
->driver
, global
->params
.override_driver
);
4026 t_iface
.driver
= global
->params
.override_driver
;
4028 if (global
->params
.override_ctrl_interface
) {
4029 wpa_printf(MSG_DEBUG
, "Override interface parameter: "
4030 "ctrl_interface ('%s' -> '%s')",
4031 iface
->ctrl_interface
,
4032 global
->params
.override_ctrl_interface
);
4033 t_iface
.ctrl_interface
=
4034 global
->params
.override_ctrl_interface
;
4036 if (wpa_supplicant_init_iface(wpa_s
, &t_iface
)) {
4037 wpa_printf(MSG_DEBUG
, "Failed to add interface %s",
4039 wpa_supplicant_deinit_iface(wpa_s
, 0, 0);
4043 if (iface
->p2p_mgmt
== 0) {
4044 /* Notify the control interfaces about new iface */
4045 if (wpas_notify_iface_added(wpa_s
)) {
4046 wpa_supplicant_deinit_iface(wpa_s
, 1, 0);
4050 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
)
4051 wpas_notify_network_added(wpa_s
, ssid
);
4054 wpa_s
->next
= global
->ifaces
;
4055 global
->ifaces
= wpa_s
;
4057 wpa_dbg(wpa_s
, MSG_DEBUG
, "Added interface %s", wpa_s
->ifname
);
4058 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
4061 if (wpa_s
->global
->p2p
== NULL
&&
4062 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
) &&
4063 wpas_p2p_add_p2pdev_interface(wpa_s
, iface
->conf_p2p_dev
) < 0) {
4064 wpa_printf(MSG_INFO
,
4065 "P2P: Failed to enable P2P Device interface");
4066 /* Try to continue without. P2P will be disabled. */
4068 #endif /* CONFIG_P2P */
4075 * wpa_supplicant_remove_iface - Remove a network interface
4076 * @global: Pointer to global data from wpa_supplicant_init()
4077 * @wpa_s: Pointer to the network interface to be removed
4078 * Returns: 0 if interface was removed, -1 if interface was not found
4080 * This function can be used to dynamically remove network interfaces from
4081 * %wpa_supplicant, e.g., when a hotplug network adapter is ejected. In
4082 * addition, this function is used to remove all remaining interfaces when
4083 * %wpa_supplicant is terminated.
4085 int wpa_supplicant_remove_iface(struct wpa_global
*global
,
4086 struct wpa_supplicant
*wpa_s
,
4089 struct wpa_supplicant
*prev
;
4091 unsigned int mesh_if_created
= wpa_s
->mesh_if_created
;
4092 char *ifname
= NULL
;
4093 #endif /* CONFIG_MESH */
4095 /* Remove interface from the global list of interfaces */
4096 prev
= global
->ifaces
;
4097 if (prev
== wpa_s
) {
4098 global
->ifaces
= wpa_s
->next
;
4100 while (prev
&& prev
->next
!= wpa_s
)
4104 prev
->next
= wpa_s
->next
;
4107 wpa_dbg(wpa_s
, MSG_DEBUG
, "Removing interface %s", wpa_s
->ifname
);
4110 if (mesh_if_created
) {
4111 ifname
= os_strdup(wpa_s
->ifname
);
4112 if (ifname
== NULL
) {
4113 wpa_dbg(wpa_s
, MSG_ERROR
,
4114 "mesh: Failed to malloc ifname");
4118 #endif /* CONFIG_MESH */
4120 if (global
->p2p_group_formation
== wpa_s
)
4121 global
->p2p_group_formation
= NULL
;
4122 if (global
->p2p_invite_group
== wpa_s
)
4123 global
->p2p_invite_group
= NULL
;
4124 wpa_supplicant_deinit_iface(wpa_s
, 1, terminate
);
4127 if (mesh_if_created
) {
4128 wpa_drv_if_remove(global
->ifaces
, WPA_IF_MESH
, ifname
);
4131 #endif /* CONFIG_MESH */
4138 * wpa_supplicant_get_eap_mode - Get the current EAP mode
4139 * @wpa_s: Pointer to the network interface
4140 * Returns: Pointer to the eap mode or the string "UNKNOWN" if not found
4142 const char * wpa_supplicant_get_eap_mode(struct wpa_supplicant
*wpa_s
)
4144 const char *eapol_method
;
4146 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) == 0 &&
4147 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
4151 eapol_method
= eapol_sm_get_method_name(wpa_s
->eapol
);
4152 if (eapol_method
== NULL
)
4153 return "UNKNOWN-EAP";
4155 return eapol_method
;
4160 * wpa_supplicant_get_iface - Get a new network interface
4161 * @global: Pointer to global data from wpa_supplicant_init()
4162 * @ifname: Interface name
4163 * Returns: Pointer to the interface or %NULL if not found
4165 struct wpa_supplicant
* wpa_supplicant_get_iface(struct wpa_global
*global
,
4168 struct wpa_supplicant
*wpa_s
;
4170 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
4171 if (os_strcmp(wpa_s
->ifname
, ifname
) == 0)
4178 #ifndef CONFIG_NO_WPA_MSG
4179 static const char * wpa_supplicant_msg_ifname_cb(void *ctx
)
4181 struct wpa_supplicant
*wpa_s
= ctx
;
4184 return wpa_s
->ifname
;
4186 #endif /* CONFIG_NO_WPA_MSG */
4190 * wpa_supplicant_init - Initialize %wpa_supplicant
4191 * @params: Parameters for %wpa_supplicant
4192 * Returns: Pointer to global %wpa_supplicant data, or %NULL on failure
4194 * This function is used to initialize %wpa_supplicant. After successful
4195 * initialization, the returned data pointer can be used to add and remove
4196 * network interfaces, and eventually, to deinitialize %wpa_supplicant.
4198 struct wpa_global
* wpa_supplicant_init(struct wpa_params
*params
)
4200 struct wpa_global
*global
;
4206 #ifdef CONFIG_DRIVER_NDIS
4208 void driver_ndis_init_ops(void);
4209 driver_ndis_init_ops();
4211 #endif /* CONFIG_DRIVER_NDIS */
4213 #ifndef CONFIG_NO_WPA_MSG
4214 wpa_msg_register_ifname_cb(wpa_supplicant_msg_ifname_cb
);
4215 #endif /* CONFIG_NO_WPA_MSG */
4217 wpa_debug_open_file(params
->wpa_debug_file_path
);
4218 if (params
->wpa_debug_syslog
)
4219 wpa_debug_open_syslog();
4220 if (params
->wpa_debug_tracing
) {
4221 ret
= wpa_debug_open_linux_tracing();
4223 wpa_printf(MSG_ERROR
,
4224 "Failed to enable trace logging");
4229 ret
= eap_register_methods();
4231 wpa_printf(MSG_ERROR
, "Failed to register EAP methods");
4233 wpa_printf(MSG_ERROR
, "Two or more EAP methods used "
4234 "the same EAP type.");
4238 global
= os_zalloc(sizeof(*global
));
4241 dl_list_init(&global
->p2p_srv_bonjour
);
4242 dl_list_init(&global
->p2p_srv_upnp
);
4243 global
->params
.daemonize
= params
->daemonize
;
4244 global
->params
.wait_for_monitor
= params
->wait_for_monitor
;
4245 global
->params
.dbus_ctrl_interface
= params
->dbus_ctrl_interface
;
4246 if (params
->pid_file
)
4247 global
->params
.pid_file
= os_strdup(params
->pid_file
);
4248 if (params
->ctrl_interface
)
4249 global
->params
.ctrl_interface
=
4250 os_strdup(params
->ctrl_interface
);
4251 if (params
->ctrl_interface_group
)
4252 global
->params
.ctrl_interface_group
=
4253 os_strdup(params
->ctrl_interface_group
);
4254 if (params
->override_driver
)
4255 global
->params
.override_driver
=
4256 os_strdup(params
->override_driver
);
4257 if (params
->override_ctrl_interface
)
4258 global
->params
.override_ctrl_interface
=
4259 os_strdup(params
->override_ctrl_interface
);
4260 wpa_debug_level
= global
->params
.wpa_debug_level
=
4261 params
->wpa_debug_level
;
4262 wpa_debug_show_keys
= global
->params
.wpa_debug_show_keys
=
4263 params
->wpa_debug_show_keys
;
4264 wpa_debug_timestamp
= global
->params
.wpa_debug_timestamp
=
4265 params
->wpa_debug_timestamp
;
4267 wpa_printf(MSG_DEBUG
, "wpa_supplicant v" VERSION_STR
);
4270 wpa_printf(MSG_ERROR
, "Failed to initialize event loop");
4271 wpa_supplicant_deinit(global
);
4275 random_init(params
->entropy_file
);
4277 global
->ctrl_iface
= wpa_supplicant_global_ctrl_iface_init(global
);
4278 if (global
->ctrl_iface
== NULL
) {
4279 wpa_supplicant_deinit(global
);
4283 if (wpas_notify_supplicant_initialized(global
)) {
4284 wpa_supplicant_deinit(global
);
4288 for (i
= 0; wpa_drivers
[i
]; i
++)
4289 global
->drv_count
++;
4290 if (global
->drv_count
== 0) {
4291 wpa_printf(MSG_ERROR
, "No drivers enabled");
4292 wpa_supplicant_deinit(global
);
4295 global
->drv_priv
= os_calloc(global
->drv_count
, sizeof(void *));
4296 if (global
->drv_priv
== NULL
) {
4297 wpa_supplicant_deinit(global
);
4301 #ifdef CONFIG_WIFI_DISPLAY
4302 if (wifi_display_init(global
) < 0) {
4303 wpa_printf(MSG_ERROR
, "Failed to initialize Wi-Fi Display");
4304 wpa_supplicant_deinit(global
);
4307 #endif /* CONFIG_WIFI_DISPLAY */
4314 * wpa_supplicant_run - Run the %wpa_supplicant main event loop
4315 * @global: Pointer to global data from wpa_supplicant_init()
4316 * Returns: 0 after successful event loop run, -1 on failure
4318 * This function starts the main event loop and continues running as long as
4319 * there are any remaining events. In most cases, this function is running as
4320 * long as the %wpa_supplicant process in still in use.
4322 int wpa_supplicant_run(struct wpa_global
*global
)
4324 struct wpa_supplicant
*wpa_s
;
4326 if (global
->params
.daemonize
&&
4327 wpa_supplicant_daemon(global
->params
.pid_file
))
4330 if (global
->params
.wait_for_monitor
) {
4331 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
)
4332 if (wpa_s
->ctrl_iface
)
4333 wpa_supplicant_ctrl_iface_wait(
4337 eloop_register_signal_terminate(wpa_supplicant_terminate
, global
);
4338 eloop_register_signal_reconfig(wpa_supplicant_reconfig
, global
);
4347 * wpa_supplicant_deinit - Deinitialize %wpa_supplicant
4348 * @global: Pointer to global data from wpa_supplicant_init()
4350 * This function is called to deinitialize %wpa_supplicant and to free all
4351 * allocated resources. Remaining network interfaces will also be removed.
4353 void wpa_supplicant_deinit(struct wpa_global
*global
)
4360 #ifdef CONFIG_WIFI_DISPLAY
4361 wifi_display_deinit(global
);
4362 #endif /* CONFIG_WIFI_DISPLAY */
4364 while (global
->ifaces
)
4365 wpa_supplicant_remove_iface(global
, global
->ifaces
, 1);
4367 if (global
->ctrl_iface
)
4368 wpa_supplicant_global_ctrl_iface_deinit(global
->ctrl_iface
);
4370 wpas_notify_supplicant_deinitialized(global
);
4372 eap_peer_unregister_methods();
4374 eap_server_unregister_methods();
4375 #endif /* CONFIG_AP */
4377 for (i
= 0; wpa_drivers
[i
] && global
->drv_priv
; i
++) {
4378 if (!global
->drv_priv
[i
])
4380 wpa_drivers
[i
]->global_deinit(global
->drv_priv
[i
]);
4382 os_free(global
->drv_priv
);
4388 if (global
->params
.pid_file
) {
4389 os_daemonize_terminate(global
->params
.pid_file
);
4390 os_free(global
->params
.pid_file
);
4392 os_free(global
->params
.ctrl_interface
);
4393 os_free(global
->params
.ctrl_interface_group
);
4394 os_free(global
->params
.override_driver
);
4395 os_free(global
->params
.override_ctrl_interface
);
4397 os_free(global
->p2p_disallow_freq
.range
);
4398 os_free(global
->p2p_go_avoid_freq
.range
);
4399 os_free(global
->add_psk
);
4402 wpa_debug_close_syslog();
4403 wpa_debug_close_file();
4404 wpa_debug_close_linux_tracing();
4408 void wpa_supplicant_update_config(struct wpa_supplicant
*wpa_s
)
4410 if ((wpa_s
->conf
->changed_parameters
& CFG_CHANGED_COUNTRY
) &&
4411 wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1]) {
4413 country
[0] = wpa_s
->conf
->country
[0];
4414 country
[1] = wpa_s
->conf
->country
[1];
4416 if (wpa_drv_set_country(wpa_s
, country
) < 0) {
4417 wpa_printf(MSG_ERROR
, "Failed to set country code "
4422 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_EXT_PW_BACKEND
)
4423 wpas_init_ext_pw(wpa_s
);
4426 wpas_wps_update_config(wpa_s
);
4427 #endif /* CONFIG_WPS */
4428 wpas_p2p_update_config(wpa_s
);
4429 wpa_s
->conf
->changed_parameters
= 0;
4433 void add_freq(int *freqs
, int *num_freqs
, int freq
)
4437 for (i
= 0; i
< *num_freqs
; i
++) {
4438 if (freqs
[i
] == freq
)
4442 freqs
[*num_freqs
] = freq
;
4447 static int * get_bss_freqs_in_ess(struct wpa_supplicant
*wpa_s
)
4449 struct wpa_bss
*bss
, *cbss
;
4450 const int max_freqs
= 10;
4454 freqs
= os_calloc(max_freqs
+ 1, sizeof(int));
4458 cbss
= wpa_s
->current_bss
;
4460 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
4463 if (bss
->ssid_len
== cbss
->ssid_len
&&
4464 os_memcmp(bss
->ssid
, cbss
->ssid
, bss
->ssid_len
) == 0 &&
4465 wpa_blacklist_get(wpa_s
, bss
->bssid
) == NULL
) {
4466 add_freq(freqs
, &num_freqs
, bss
->freq
);
4467 if (num_freqs
== max_freqs
)
4472 if (num_freqs
== 0) {
4481 void wpas_connection_failed(struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
4487 wpas_connect_work_done(wpa_s
);
4490 * Remove possible authentication timeout since the connection failed.
4492 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
4494 if (wpa_s
->disconnected
) {
4496 * There is no point in blacklisting the AP if this event is
4497 * generated based on local request to disconnect.
4499 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignore connection failure "
4500 "indication since interface has been put into "
4501 "disconnected state");
4506 * Add the failed BSSID into the blacklist and speed up next scan
4507 * attempt if there could be other APs that could accept association.
4508 * The current blacklist count indicates how many times we have tried
4509 * connecting to this AP and multiple attempts mean that other APs are
4510 * either not available or has already been tried, so that we can start
4511 * increasing the delay here to avoid constant scanning.
4513 count
= wpa_blacklist_add(wpa_s
, bssid
);
4514 if (count
== 1 && wpa_s
->current_bss
) {
4516 * This BSS was not in the blacklist before. If there is
4517 * another BSS available for the same ESS, we should try that
4518 * next. Otherwise, we may as well try this one once more
4519 * before allowing other, likely worse, ESSes to be considered.
4521 freqs
= get_bss_freqs_in_ess(wpa_s
);
4523 wpa_dbg(wpa_s
, MSG_DEBUG
, "Another BSS in this ESS "
4524 "has been seen; try it next");
4525 wpa_blacklist_add(wpa_s
, bssid
);
4527 * On the next scan, go through only the known channels
4528 * used in this ESS based on previous scans to speed up
4529 * common load balancing use case.
4531 os_free(wpa_s
->next_scan_freqs
);
4532 wpa_s
->next_scan_freqs
= freqs
;
4537 * Add previous failure count in case the temporary blacklist was
4538 * cleared due to no other BSSes being available.
4540 count
+= wpa_s
->extra_blacklist_count
;
4542 if (count
> 3 && wpa_s
->current_ssid
) {
4543 wpa_printf(MSG_DEBUG
, "Continuous association failures - "
4544 "consider temporary network disabling");
4545 wpas_auth_failed(wpa_s
, "CONN_FAILED");
4566 wpa_dbg(wpa_s
, MSG_DEBUG
, "Blacklist count %d --> request scan in %d "
4567 "ms", count
, timeout
);
4570 * TODO: if more than one possible AP is available in scan results,
4571 * could try the other ones before requesting a new scan.
4573 wpa_supplicant_req_scan(wpa_s
, timeout
/ 1000,
4574 1000 * (timeout
% 1000));
4578 int wpas_driver_bss_selection(struct wpa_supplicant
*wpa_s
)
4580 return wpa_s
->conf
->ap_scan
== 2 ||
4581 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_BSS_SELECTION
);
4585 #if defined(CONFIG_CTRL_IFACE) || defined(CONFIG_CTRL_IFACE_DBUS_NEW)
4586 int wpa_supplicant_ctrl_iface_ctrl_rsp_handle(struct wpa_supplicant
*wpa_s
,
4587 struct wpa_ssid
*ssid
,
4591 #ifdef IEEE8021X_EAPOL
4592 struct eap_peer_config
*eap
= &ssid
->eap
;
4594 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: response handle field=%s", field
);
4595 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: response value",
4596 (const u8
*) value
, os_strlen(value
));
4598 switch (wpa_supplicant_ctrl_req_from_string(field
)) {
4599 case WPA_CTRL_REQ_EAP_IDENTITY
:
4600 os_free(eap
->identity
);
4601 eap
->identity
= (u8
*) os_strdup(value
);
4602 eap
->identity_len
= os_strlen(value
);
4603 eap
->pending_req_identity
= 0;
4604 if (ssid
== wpa_s
->current_ssid
)
4605 wpa_s
->reassociate
= 1;
4607 case WPA_CTRL_REQ_EAP_PASSWORD
:
4608 bin_clear_free(eap
->password
, eap
->password_len
);
4609 eap
->password
= (u8
*) os_strdup(value
);
4610 eap
->password_len
= os_strlen(value
);
4611 eap
->pending_req_password
= 0;
4612 if (ssid
== wpa_s
->current_ssid
)
4613 wpa_s
->reassociate
= 1;
4615 case WPA_CTRL_REQ_EAP_NEW_PASSWORD
:
4616 bin_clear_free(eap
->new_password
, eap
->new_password_len
);
4617 eap
->new_password
= (u8
*) os_strdup(value
);
4618 eap
->new_password_len
= os_strlen(value
);
4619 eap
->pending_req_new_password
= 0;
4620 if (ssid
== wpa_s
->current_ssid
)
4621 wpa_s
->reassociate
= 1;
4623 case WPA_CTRL_REQ_EAP_PIN
:
4624 str_clear_free(eap
->pin
);
4625 eap
->pin
= os_strdup(value
);
4626 eap
->pending_req_pin
= 0;
4627 if (ssid
== wpa_s
->current_ssid
)
4628 wpa_s
->reassociate
= 1;
4630 case WPA_CTRL_REQ_EAP_OTP
:
4631 bin_clear_free(eap
->otp
, eap
->otp_len
);
4632 eap
->otp
= (u8
*) os_strdup(value
);
4633 eap
->otp_len
= os_strlen(value
);
4634 os_free(eap
->pending_req_otp
);
4635 eap
->pending_req_otp
= NULL
;
4636 eap
->pending_req_otp_len
= 0;
4638 case WPA_CTRL_REQ_EAP_PASSPHRASE
:
4639 str_clear_free(eap
->private_key_passwd
);
4640 eap
->private_key_passwd
= os_strdup(value
);
4641 eap
->pending_req_passphrase
= 0;
4642 if (ssid
== wpa_s
->current_ssid
)
4643 wpa_s
->reassociate
= 1;
4645 case WPA_CTRL_REQ_SIM
:
4646 str_clear_free(eap
->external_sim_resp
);
4647 eap
->external_sim_resp
= os_strdup(value
);
4650 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown field '%s'", field
);
4655 #else /* IEEE8021X_EAPOL */
4656 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: IEEE 802.1X not included");
4658 #endif /* IEEE8021X_EAPOL */
4660 #endif /* CONFIG_CTRL_IFACE || CONFIG_CTRL_IFACE_DBUS_NEW */
4663 int wpas_network_disabled(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
)
4666 unsigned int drv_enc
;
4674 if (wpa_s
&& wpa_s
->drv_capa_known
)
4675 drv_enc
= wpa_s
->drv_enc
;
4677 drv_enc
= (unsigned int) -1;
4679 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
4680 size_t len
= ssid
->wep_key_len
[i
];
4683 if (len
== 5 && (drv_enc
& WPA_DRIVER_CAPA_ENC_WEP40
))
4685 if (len
== 13 && (drv_enc
& WPA_DRIVER_CAPA_ENC_WEP104
))
4687 if (len
== 16 && (drv_enc
& WPA_DRIVER_CAPA_ENC_WEP128
))
4689 return 1; /* invalid WEP key */
4692 if (wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) && !ssid
->psk_set
&&
4693 (!ssid
->passphrase
|| ssid
->ssid_len
!= 0) && !ssid
->ext_psk
)
4700 int wpas_is_p2p_prioritized(struct wpa_supplicant
*wpa_s
)
4702 if (wpa_s
->global
->conc_pref
== WPA_CONC_PREF_P2P
)
4704 if (wpa_s
->global
->conc_pref
== WPA_CONC_PREF_STA
)
4710 void wpas_auth_failed(struct wpa_supplicant
*wpa_s
, char *reason
)
4712 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
4714 struct os_reltime now
;
4717 wpa_printf(MSG_DEBUG
, "Authentication failure but no known "
4722 if (ssid
->key_mgmt
== WPA_KEY_MGMT_WPS
)
4725 ssid
->auth_failures
++;
4728 if (ssid
->p2p_group
&&
4729 (wpa_s
->p2p_in_provisioning
|| wpa_s
->show_group_started
)) {
4731 * Skip the wait time since there is a short timeout on the
4732 * connection to a P2P group.
4736 #endif /* CONFIG_P2P */
4738 if (ssid
->auth_failures
> 50)
4740 else if (ssid
->auth_failures
> 10)
4742 else if (ssid
->auth_failures
> 5)
4744 else if (ssid
->auth_failures
> 3)
4746 else if (ssid
->auth_failures
> 2)
4748 else if (ssid
->auth_failures
> 1)
4753 if (ssid
->auth_failures
> 1 &&
4754 wpa_key_mgmt_wpa_ieee8021x(ssid
->key_mgmt
))
4755 dur
+= os_random() % (ssid
->auth_failures
* 10);
4757 os_get_reltime(&now
);
4758 if (now
.sec
+ dur
<= ssid
->disabled_until
.sec
)
4761 ssid
->disabled_until
.sec
= now
.sec
+ dur
;
4763 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_TEMP_DISABLED
4764 "id=%d ssid=\"%s\" auth_failures=%u duration=%d reason=%s",
4765 ssid
->id
, wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
),
4766 ssid
->auth_failures
, dur
, reason
);
4770 void wpas_clear_temp_disabled(struct wpa_supplicant
*wpa_s
,
4771 struct wpa_ssid
*ssid
, int clear_failures
)
4776 if (ssid
->disabled_until
.sec
) {
4777 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_REENABLED
4778 "id=%d ssid=\"%s\"",
4779 ssid
->id
, wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
4781 ssid
->disabled_until
.sec
= 0;
4782 ssid
->disabled_until
.usec
= 0;
4784 ssid
->auth_failures
= 0;
4788 int disallowed_bssid(struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
4792 if (wpa_s
->disallow_aps_bssid
== NULL
)
4795 for (i
= 0; i
< wpa_s
->disallow_aps_bssid_count
; i
++) {
4796 if (os_memcmp(wpa_s
->disallow_aps_bssid
+ i
* ETH_ALEN
,
4797 bssid
, ETH_ALEN
) == 0)
4805 int disallowed_ssid(struct wpa_supplicant
*wpa_s
, const u8
*ssid
,
4810 if (wpa_s
->disallow_aps_ssid
== NULL
|| ssid
== NULL
)
4813 for (i
= 0; i
< wpa_s
->disallow_aps_ssid_count
; i
++) {
4814 struct wpa_ssid_value
*s
= &wpa_s
->disallow_aps_ssid
[i
];
4815 if (ssid_len
== s
->ssid_len
&&
4816 os_memcmp(ssid
, s
->ssid
, ssid_len
) == 0)
4825 * wpas_request_connection - Request a new connection
4826 * @wpa_s: Pointer to the network interface
4828 * This function is used to request a new connection to be found. It will mark
4829 * the interface to allow reassociation and request a new scan to find a
4830 * suitable network to connect to.
4832 void wpas_request_connection(struct wpa_supplicant
*wpa_s
)
4834 wpa_s
->normal_scans
= 0;
4835 wpa_s
->scan_req
= NORMAL_SCAN_REQ
;
4836 wpa_supplicant_reinit_autoscan(wpa_s
);
4837 wpa_s
->extra_blacklist_count
= 0;
4838 wpa_s
->disconnected
= 0;
4839 wpa_s
->reassociate
= 1;
4841 if (wpa_supplicant_fast_associate(wpa_s
) != 1)
4842 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4846 void dump_freq_data(struct wpa_supplicant
*wpa_s
, const char *title
,
4847 struct wpa_used_freq_data
*freqs_data
,
4852 wpa_dbg(wpa_s
, MSG_DEBUG
, "Shared frequencies (len=%u): %s",
4854 for (i
= 0; i
< len
; i
++) {
4855 struct wpa_used_freq_data
*cur
= &freqs_data
[i
];
4856 wpa_dbg(wpa_s
, MSG_DEBUG
, "freq[%u]: %d, flags=0x%X",
4857 i
, cur
->freq
, cur
->flags
);
4863 * Find the operating frequencies of any of the virtual interfaces that
4864 * are using the same radio as the current interface, and in addition, get
4865 * information about the interface types that are using the frequency.
4867 int get_shared_radio_freqs_data(struct wpa_supplicant
*wpa_s
,
4868 struct wpa_used_freq_data
*freqs_data
,
4871 struct wpa_supplicant
*ifs
;
4874 unsigned int idx
= 0, i
;
4876 wpa_dbg(wpa_s
, MSG_DEBUG
,
4877 "Determining shared radio frequencies (max len %u)", len
);
4878 os_memset(freqs_data
, 0, sizeof(struct wpa_used_freq_data
) * len
);
4880 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
4885 if (ifs
->current_ssid
== NULL
|| ifs
->assoc_freq
== 0)
4888 if (ifs
->current_ssid
->mode
== WPAS_MODE_AP
||
4889 ifs
->current_ssid
->mode
== WPAS_MODE_P2P_GO
)
4890 freq
= ifs
->current_ssid
->frequency
;
4891 else if (wpa_drv_get_bssid(ifs
, bssid
) == 0)
4892 freq
= ifs
->assoc_freq
;
4896 /* Hold only distinct freqs */
4897 for (i
= 0; i
< idx
; i
++)
4898 if (freqs_data
[i
].freq
== freq
)
4902 freqs_data
[idx
++].freq
= freq
;
4904 if (ifs
->current_ssid
->mode
== WPAS_MODE_INFRA
) {
4905 freqs_data
[i
].flags
= ifs
->current_ssid
->p2p_group
?
4906 WPA_FREQ_USED_BY_P2P_CLIENT
:
4907 WPA_FREQ_USED_BY_INFRA_STATION
;
4911 dump_freq_data(wpa_s
, "completed iteration", freqs_data
, idx
);
4917 * Find the operating frequencies of any of the virtual interfaces that
4918 * are using the same radio as the current interface.
4920 int get_shared_radio_freqs(struct wpa_supplicant
*wpa_s
,
4921 int *freq_array
, unsigned int len
)
4923 struct wpa_used_freq_data
*freqs_data
;
4926 os_memset(freq_array
, 0, sizeof(int) * len
);
4928 freqs_data
= os_calloc(len
, sizeof(struct wpa_used_freq_data
));
4932 num
= get_shared_radio_freqs_data(wpa_s
, freqs_data
, len
);
4933 for (i
= 0; i
< num
; i
++)
4934 freq_array
[i
] = freqs_data
[i
].freq
;
4936 os_free(freqs_data
);
4942 static void wpas_rrm_neighbor_rep_timeout_handler(void *data
, void *user_ctx
)
4944 struct rrm_data
*rrm
= data
;
4946 if (!rrm
->notify_neighbor_rep
) {
4947 wpa_printf(MSG_ERROR
,
4948 "RRM: Unexpected neighbor report timeout");
4952 wpa_printf(MSG_DEBUG
, "RRM: Notifying neighbor report - NONE");
4953 rrm
->notify_neighbor_rep(rrm
->neighbor_rep_cb_ctx
, NULL
);
4955 rrm
->notify_neighbor_rep
= NULL
;
4956 rrm
->neighbor_rep_cb_ctx
= NULL
;
4961 * wpas_rrm_reset - Clear and reset all RRM data in wpa_supplicant
4962 * @wpa_s: Pointer to wpa_supplicant
4964 void wpas_rrm_reset(struct wpa_supplicant
*wpa_s
)
4966 wpa_s
->rrm
.rrm_used
= 0;
4968 eloop_cancel_timeout(wpas_rrm_neighbor_rep_timeout_handler
, &wpa_s
->rrm
,
4970 if (wpa_s
->rrm
.notify_neighbor_rep
)
4971 wpas_rrm_neighbor_rep_timeout_handler(&wpa_s
->rrm
, NULL
);
4972 wpa_s
->rrm
.next_neighbor_rep_token
= 1;
4977 * wpas_rrm_process_neighbor_rep - Handle incoming neighbor report
4978 * @wpa_s: Pointer to wpa_supplicant
4979 * @report: Neighbor report buffer, prefixed by a 1-byte dialog token
4980 * @report_len: Length of neighbor report buffer
4982 void wpas_rrm_process_neighbor_rep(struct wpa_supplicant
*wpa_s
,
4983 const u8
*report
, size_t report_len
)
4985 struct wpabuf
*neighbor_rep
;
4987 wpa_hexdump(MSG_DEBUG
, "RRM: New Neighbor Report", report
, report_len
);
4991 if (report
[0] != wpa_s
->rrm
.next_neighbor_rep_token
- 1) {
4992 wpa_printf(MSG_DEBUG
,
4993 "RRM: Discarding neighbor report with token %d (expected %d)",
4994 report
[0], wpa_s
->rrm
.next_neighbor_rep_token
- 1);
4998 eloop_cancel_timeout(wpas_rrm_neighbor_rep_timeout_handler
, &wpa_s
->rrm
,
5001 if (!wpa_s
->rrm
.notify_neighbor_rep
) {
5002 wpa_printf(MSG_ERROR
, "RRM: Unexpected neighbor report");
5006 /* skipping the first byte, which is only an id (dialog token) */
5007 neighbor_rep
= wpabuf_alloc(report_len
- 1);
5008 if (neighbor_rep
== NULL
)
5010 wpabuf_put_data(neighbor_rep
, report
+ 1, report_len
- 1);
5011 wpa_printf(MSG_DEBUG
, "RRM: Notifying neighbor report (token = %d)",
5013 wpa_s
->rrm
.notify_neighbor_rep(wpa_s
->rrm
.neighbor_rep_cb_ctx
,
5015 wpa_s
->rrm
.notify_neighbor_rep
= NULL
;
5016 wpa_s
->rrm
.neighbor_rep_cb_ctx
= NULL
;
5021 * wpas_rrm_send_neighbor_rep_request - Request a neighbor report from our AP
5022 * @wpa_s: Pointer to wpa_supplicant
5023 * @ssid: if not null, this is sent in the request. Otherwise, no SSID IE
5024 * is sent in the request.
5025 * @cb: Callback function to be called once the requested report arrives, or
5026 * timed out after RRM_NEIGHBOR_REPORT_TIMEOUT seconds.
5027 * In the former case, 'neighbor_rep' is a newly allocated wpabuf, and it's
5028 * the requester's responsibility to free it.
5029 * In the latter case NULL will be sent in 'neighbor_rep'.
5030 * @cb_ctx: Context value to send the callback function
5031 * Returns: 0 in case of success, negative error code otherwise
5033 * In case there is a previous request which has not been answered yet, the
5034 * new request fails. The caller may retry after RRM_NEIGHBOR_REPORT_TIMEOUT.
5035 * Request must contain a callback function.
5037 int wpas_rrm_send_neighbor_rep_request(struct wpa_supplicant
*wpa_s
,
5038 const struct wpa_ssid
*ssid
,
5039 void (*cb
)(void *ctx
,
5040 struct wpabuf
*neighbor_rep
),
5046 if (wpa_s
->wpa_state
!= WPA_COMPLETED
|| wpa_s
->current_ssid
== NULL
) {
5047 wpa_printf(MSG_DEBUG
, "RRM: No connection, no RRM.");
5051 if (!wpa_s
->rrm
.rrm_used
) {
5052 wpa_printf(MSG_DEBUG
, "RRM: No RRM in current connection.");
5056 rrm_ie
= wpa_bss_get_ie(wpa_s
->current_bss
,
5057 WLAN_EID_RRM_ENABLED_CAPABILITIES
);
5058 if (!rrm_ie
|| !(wpa_s
->current_bss
->caps
& IEEE80211_CAP_RRM
) ||
5059 !(rrm_ie
[2] & WLAN_RRM_CAPS_NEIGHBOR_REPORT
)) {
5060 wpa_printf(MSG_DEBUG
,
5061 "RRM: No network support for Neighbor Report.");
5066 wpa_printf(MSG_DEBUG
,
5067 "RRM: Neighbor Report request must provide a callback.");
5071 /* Refuse if there's a live request */
5072 if (wpa_s
->rrm
.notify_neighbor_rep
) {
5073 wpa_printf(MSG_DEBUG
,
5074 "RRM: Currently handling previous Neighbor Report.");
5078 /* 3 = action category + action code + dialog token */
5079 buf
= wpabuf_alloc(3 + (ssid
? 2 + ssid
->ssid_len
: 0));
5081 wpa_printf(MSG_DEBUG
,
5082 "RRM: Failed to allocate Neighbor Report Request");
5086 wpa_printf(MSG_DEBUG
, "RRM: Neighbor report request (for %s), token=%d",
5087 (ssid
? wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
) : ""),
5088 wpa_s
->rrm
.next_neighbor_rep_token
);
5090 wpabuf_put_u8(buf
, WLAN_ACTION_RADIO_MEASUREMENT
);
5091 wpabuf_put_u8(buf
, WLAN_RRM_NEIGHBOR_REPORT_REQUEST
);
5092 wpabuf_put_u8(buf
, wpa_s
->rrm
.next_neighbor_rep_token
);
5094 wpabuf_put_u8(buf
, WLAN_EID_SSID
);
5095 wpabuf_put_u8(buf
, ssid
->ssid_len
);
5096 wpabuf_put_data(buf
, ssid
->ssid
, ssid
->ssid_len
);
5099 wpa_s
->rrm
.next_neighbor_rep_token
++;
5101 if (wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
5102 wpa_s
->own_addr
, wpa_s
->bssid
,
5103 wpabuf_head(buf
), wpabuf_len(buf
), 0) < 0) {
5104 wpa_printf(MSG_DEBUG
,
5105 "RRM: Failed to send Neighbor Report Request");
5110 wpa_s
->rrm
.neighbor_rep_cb_ctx
= cb_ctx
;
5111 wpa_s
->rrm
.notify_neighbor_rep
= cb
;
5112 eloop_register_timeout(RRM_NEIGHBOR_REPORT_TIMEOUT
, 0,
5113 wpas_rrm_neighbor_rep_timeout_handler
,
5121 void wpas_rrm_handle_link_measurement_request(struct wpa_supplicant
*wpa_s
,
5123 const u8
*frame
, size_t len
,
5127 const struct rrm_link_measurement_request
*req
;
5128 struct rrm_link_measurement_report report
;
5130 if (wpa_s
->wpa_state
!= WPA_COMPLETED
) {
5131 wpa_printf(MSG_INFO
,
5132 "RRM: Ignoring link measurement request. Not associated");
5136 if (!wpa_s
->rrm
.rrm_used
) {
5137 wpa_printf(MSG_INFO
,
5138 "RRM: Ignoring link measurement request. Not RRM network");
5142 if (!(wpa_s
->drv_rrm_flags
& WPA_DRIVER_FLAGS_TX_POWER_INSERTION
)) {
5143 wpa_printf(MSG_INFO
,
5144 "RRM: Measurement report failed. TX power insertion not supported");
5148 req
= (const struct rrm_link_measurement_request
*) frame
;
5149 if (len
< sizeof(*req
)) {
5150 wpa_printf(MSG_INFO
,
5151 "RRM: Link measurement report failed. Request too short");
5155 os_memset(&report
, 0, sizeof(report
));
5156 report
.tpc
.eid
= WLAN_EID_TPC_REPORT
;
5158 report
.rsni
= 255; /* 255 indicates that RSNI is not available */
5159 report
.dialog_token
= req
->dialog_token
;
5162 * It's possible to estimate RCPI based on RSSI in dBm. This
5163 * calculation will not reflect the correct value for high rates,
5164 * but it's good enough for Action frames which are transmitted
5165 * with up to 24 Mbps rates.
5168 report
.rcpi
= 255; /* not available */
5169 else if (rssi
< -110)
5174 report
.rcpi
= (rssi
+ 110) * 2;
5176 /* action_category + action_code */
5177 buf
= wpabuf_alloc(2 + sizeof(report
));
5179 wpa_printf(MSG_ERROR
,
5180 "RRM: Link measurement report failed. Buffer allocation failed");
5184 wpabuf_put_u8(buf
, WLAN_ACTION_RADIO_MEASUREMENT
);
5185 wpabuf_put_u8(buf
, WLAN_RRM_LINK_MEASUREMENT_REPORT
);
5186 wpabuf_put_data(buf
, &report
, sizeof(report
));
5187 wpa_hexdump(MSG_DEBUG
, "RRM: Link measurement report:",
5188 wpabuf_head(buf
), wpabuf_len(buf
));
5190 if (wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, src
,
5191 wpa_s
->own_addr
, wpa_s
->bssid
,
5192 wpabuf_head(buf
), wpabuf_len(buf
), 0)) {
5193 wpa_printf(MSG_ERROR
,
5194 "RRM: Link measurement report failed. Send action failed");