3 * Copyright (c) 2003-2012, 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_server/eap_methods.h"
21 #include "rsn_supp/wpa.h"
24 #include "utils/ext_password.h"
25 #include "l2_packet/l2_packet.h"
26 #include "wpa_supplicant_i.h"
28 #include "ctrl_iface.h"
29 #include "pcsc_funcs.h"
30 #include "common/version.h"
31 #include "rsn_supp/preauth.h"
32 #include "rsn_supp/pmksa_cache.h"
33 #include "common/wpa_ctrl.h"
34 #include "common/ieee802_11_defs.h"
36 #include "blacklist.h"
37 #include "wpas_glue.h"
38 #include "wps_supplicant.h"
41 #include "gas_query.h"
43 #include "p2p_supplicant.h"
49 #include "offchannel.h"
50 #include "hs20_supplicant.h"
52 const char *wpa_supplicant_version
=
53 "wpa_supplicant v" VERSION_STR
"\n"
54 "Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi> and contributors";
56 const char *wpa_supplicant_license
=
57 "This software may be distributed under the terms of the BSD license.\n"
58 "See README for more details.\n"
59 #ifdef EAP_TLS_OPENSSL
60 "\nThis product includes software developed by the OpenSSL Project\n"
61 "for use in the OpenSSL Toolkit (http://www.openssl.org/)\n"
62 #endif /* EAP_TLS_OPENSSL */
65 #ifndef CONFIG_NO_STDOUT_DEBUG
66 /* Long text divided into parts in order to fit in C89 strings size limits. */
67 const char *wpa_supplicant_full_license1
=
69 const char *wpa_supplicant_full_license2
=
70 "This software may be distributed under the terms of the BSD license.\n"
72 "Redistribution and use in source and binary forms, with or without\n"
73 "modification, are permitted provided that the following conditions are\n"
76 const char *wpa_supplicant_full_license3
=
77 "1. Redistributions of source code must retain the above copyright\n"
78 " notice, this list of conditions and the following disclaimer.\n"
80 "2. Redistributions in binary form must reproduce the above copyright\n"
81 " notice, this list of conditions and the following disclaimer in the\n"
82 " documentation and/or other materials provided with the distribution.\n"
84 const char *wpa_supplicant_full_license4
=
85 "3. Neither the name(s) of the above-listed copyright holder(s) nor the\n"
86 " names of its contributors may be used to endorse or promote products\n"
87 " derived from this software without specific prior written permission.\n"
89 "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n"
90 "\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n"
91 "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n"
92 "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n";
93 const char *wpa_supplicant_full_license5
=
94 "OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n"
95 "SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n"
96 "LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n"
97 "DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n"
98 "THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n"
99 "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n"
100 "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
102 #endif /* CONFIG_NO_STDOUT_DEBUG */
104 extern int wpa_debug_level
;
105 extern int wpa_debug_show_keys
;
106 extern int wpa_debug_timestamp
;
107 extern struct wpa_driver_ops
*wpa_drivers
[];
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 static 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_TKIP
:
158 /* WPA-None uses the same Michael MIC key for both TX and RX */
159 os_memcpy(key
, ssid
->psk
, 16 + 8);
160 os_memcpy(key
+ 16 + 8, ssid
->psk
+ 16, 8);
165 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Invalid group cipher %d for "
166 "WPA-None", wpa_s
->group_cipher
);
170 /* TODO: should actually remember the previously used seq#, both for TX
171 * and RX from each STA.. */
173 return wpa_drv_set_key(wpa_s
, alg
, NULL
, 0, 1, seq
, 6, key
, keylen
);
177 static void wpa_supplicant_timeout(void *eloop_ctx
, void *timeout_ctx
)
179 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
180 const u8
*bssid
= wpa_s
->bssid
;
181 if (is_zero_ether_addr(bssid
))
182 bssid
= wpa_s
->pending_bssid
;
183 wpa_msg(wpa_s
, MSG_INFO
, "Authentication with " MACSTR
" timed out.",
185 wpa_blacklist_add(wpa_s
, bssid
);
186 wpa_sm_notify_disassoc(wpa_s
->wpa
);
187 wpa_supplicant_disassociate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
188 wpa_s
->reassociate
= 1;
191 * If we timed out, the AP or the local radio may be busy.
192 * So, wait a second until scanning again.
194 wpa_supplicant_req_scan(wpa_s
, 1, 0);
199 * wpa_supplicant_req_auth_timeout - Schedule a timeout for authentication
200 * @wpa_s: Pointer to wpa_supplicant data
201 * @sec: Number of seconds after which to time out authentication
202 * @usec: Number of microseconds after which to time out authentication
204 * This function is used to schedule a timeout for the current authentication
207 void wpa_supplicant_req_auth_timeout(struct wpa_supplicant
*wpa_s
,
210 if (wpa_s
->conf
&& wpa_s
->conf
->ap_scan
== 0 &&
211 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
))
214 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setting authentication timeout: %d sec "
215 "%d usec", sec
, usec
);
216 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
217 eloop_register_timeout(sec
, usec
, wpa_supplicant_timeout
, wpa_s
, NULL
);
222 * wpa_supplicant_cancel_auth_timeout - Cancel authentication timeout
223 * @wpa_s: Pointer to wpa_supplicant data
225 * This function is used to cancel authentication timeout scheduled with
226 * wpa_supplicant_req_auth_timeout() and it is called when authentication has
229 void wpa_supplicant_cancel_auth_timeout(struct wpa_supplicant
*wpa_s
)
231 wpa_dbg(wpa_s
, MSG_DEBUG
, "Cancelling authentication timeout");
232 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
233 wpa_blacklist_del(wpa_s
, wpa_s
->bssid
);
238 * wpa_supplicant_initiate_eapol - Configure EAPOL state machine
239 * @wpa_s: Pointer to wpa_supplicant data
241 * This function is used to configure EAPOL state machine based on the selected
242 * authentication mode.
244 void wpa_supplicant_initiate_eapol(struct wpa_supplicant
*wpa_s
)
246 #ifdef IEEE8021X_EAPOL
247 struct eapol_config eapol_conf
;
248 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
250 #ifdef CONFIG_IBSS_RSN
251 if (ssid
->mode
== WPAS_MODE_IBSS
&&
252 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
253 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
) {
255 * RSN IBSS authentication is per-STA and we can disable the
256 * per-BSSID EAPOL authentication.
258 eapol_sm_notify_portControl(wpa_s
->eapol
, ForceAuthorized
);
259 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
260 eapol_sm_notify_eap_fail(wpa_s
->eapol
, FALSE
);
263 #endif /* CONFIG_IBSS_RSN */
265 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
266 eapol_sm_notify_eap_fail(wpa_s
->eapol
, FALSE
);
268 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
269 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
270 eapol_sm_notify_portControl(wpa_s
->eapol
, ForceAuthorized
);
272 eapol_sm_notify_portControl(wpa_s
->eapol
, Auto
);
274 os_memset(&eapol_conf
, 0, sizeof(eapol_conf
));
275 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
276 eapol_conf
.accept_802_1x_keys
= 1;
277 eapol_conf
.required_keys
= 0;
278 if (ssid
->eapol_flags
& EAPOL_FLAG_REQUIRE_KEY_UNICAST
) {
279 eapol_conf
.required_keys
|= EAPOL_REQUIRE_KEY_UNICAST
;
281 if (ssid
->eapol_flags
& EAPOL_FLAG_REQUIRE_KEY_BROADCAST
) {
282 eapol_conf
.required_keys
|=
283 EAPOL_REQUIRE_KEY_BROADCAST
;
286 if (wpa_s
->conf
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
))
287 eapol_conf
.required_keys
= 0;
290 eapol_conf
.fast_reauth
= wpa_s
->conf
->fast_reauth
;
291 eapol_conf
.workaround
= ssid
->eap_workaround
;
292 eapol_conf
.eap_disabled
=
293 !wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) &&
294 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
295 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPS
;
296 eapol_sm_notify_config(wpa_s
->eapol
, &ssid
->eap
, &eapol_conf
);
297 #endif /* IEEE8021X_EAPOL */
302 * wpa_supplicant_set_non_wpa_policy - Set WPA parameters to non-WPA mode
303 * @wpa_s: Pointer to wpa_supplicant data
304 * @ssid: Configuration data for the network
306 * This function is used to configure WPA state machine and related parameters
307 * to a mode where WPA is not enabled. This is called as part of the
308 * authentication configuration when the selected network does not use WPA.
310 void wpa_supplicant_set_non_wpa_policy(struct wpa_supplicant
*wpa_s
,
311 struct wpa_ssid
*ssid
)
315 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
316 wpa_s
->key_mgmt
= WPA_KEY_MGMT_WPS
;
317 else if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)
318 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X_NO_WPA
;
320 wpa_s
->key_mgmt
= WPA_KEY_MGMT_NONE
;
321 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
322 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
323 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
324 wpa_s
->pairwise_cipher
= WPA_CIPHER_NONE
;
325 wpa_s
->group_cipher
= WPA_CIPHER_NONE
;
326 wpa_s
->mgmt_group_cipher
= 0;
328 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
329 if (ssid
->wep_key_len
[i
] > 5) {
330 wpa_s
->pairwise_cipher
= WPA_CIPHER_WEP104
;
331 wpa_s
->group_cipher
= WPA_CIPHER_WEP104
;
333 } else if (ssid
->wep_key_len
[i
] > 0) {
334 wpa_s
->pairwise_cipher
= WPA_CIPHER_WEP40
;
335 wpa_s
->group_cipher
= WPA_CIPHER_WEP40
;
340 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_RSN_ENABLED
, 0);
341 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_KEY_MGMT
, wpa_s
->key_mgmt
);
342 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PAIRWISE
,
343 wpa_s
->pairwise_cipher
);
344 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_GROUP
, wpa_s
->group_cipher
);
345 #ifdef CONFIG_IEEE80211W
346 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MGMT_GROUP
,
347 wpa_s
->mgmt_group_cipher
);
348 #endif /* CONFIG_IEEE80211W */
350 pmksa_cache_clear_current(wpa_s
->wpa
);
354 void free_hw_features(struct wpa_supplicant
*wpa_s
)
357 if (wpa_s
->hw
.modes
== NULL
)
360 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
361 os_free(wpa_s
->hw
.modes
[i
].channels
);
362 os_free(wpa_s
->hw
.modes
[i
].rates
);
365 os_free(wpa_s
->hw
.modes
);
366 wpa_s
->hw
.modes
= NULL
;
370 static void wpa_supplicant_cleanup(struct wpa_supplicant
*wpa_s
)
372 bgscan_deinit(wpa_s
);
373 autoscan_deinit(wpa_s
);
374 scard_deinit(wpa_s
->scard
);
376 wpa_sm_set_scard_ctx(wpa_s
->wpa
, NULL
);
377 eapol_sm_register_scard_ctx(wpa_s
->eapol
, NULL
);
378 l2_packet_deinit(wpa_s
->l2
);
381 l2_packet_deinit(wpa_s
->l2_br
);
385 if (wpa_s
->conf
!= NULL
) {
386 struct wpa_ssid
*ssid
;
387 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
)
388 wpas_notify_network_removed(wpa_s
, ssid
);
391 os_free(wpa_s
->confname
);
392 wpa_s
->confname
= NULL
;
394 wpa_sm_set_eapol(wpa_s
->wpa
, NULL
);
395 eapol_sm_deinit(wpa_s
->eapol
);
398 rsn_preauth_deinit(wpa_s
->wpa
);
401 wpa_tdls_deinit(wpa_s
->wpa
);
402 #endif /* CONFIG_TDLS */
404 pmksa_candidate_free(wpa_s
->wpa
);
405 wpa_sm_deinit(wpa_s
->wpa
);
407 wpa_blacklist_clear(wpa_s
);
409 wpa_bss_deinit(wpa_s
);
411 wpa_supplicant_cancel_scan(wpa_s
);
412 wpa_supplicant_cancel_auth_timeout(wpa_s
);
413 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
414 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
415 eloop_cancel_timeout(wpa_supplicant_delayed_mic_error_report
,
417 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
419 wpas_wps_deinit(wpa_s
);
421 wpabuf_free(wpa_s
->pending_eapol_rx
);
422 wpa_s
->pending_eapol_rx
= NULL
;
424 #ifdef CONFIG_IBSS_RSN
425 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
426 wpa_s
->ibss_rsn
= NULL
;
427 #endif /* CONFIG_IBSS_RSN */
432 wpa_supplicant_ap_deinit(wpa_s
);
433 #endif /* CONFIG_AP */
436 wpas_p2p_deinit(wpa_s
);
437 #endif /* CONFIG_P2P */
439 #ifdef CONFIG_OFFCHANNEL
440 offchannel_deinit(wpa_s
);
441 #endif /* CONFIG_OFFCHANNEL */
443 wpa_supplicant_cancel_sched_scan(wpa_s
);
445 os_free(wpa_s
->next_scan_freqs
);
446 wpa_s
->next_scan_freqs
= NULL
;
448 gas_query_deinit(wpa_s
->gas
);
451 free_hw_features(wpa_s
);
453 os_free(wpa_s
->bssid_filter
);
454 wpa_s
->bssid_filter
= NULL
;
456 wnm_bss_keep_alive_deinit(wpa_s
);
458 ext_password_deinit(wpa_s
->ext_pw
);
459 wpa_s
->ext_pw
= NULL
;
464 * wpa_clear_keys - Clear keys configured for the driver
465 * @wpa_s: Pointer to wpa_supplicant data
466 * @addr: Previously used BSSID or %NULL if not available
468 * This function clears the encryption keys that has been previously configured
471 void wpa_clear_keys(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
473 if (wpa_s
->keys_cleared
) {
474 /* Some drivers (e.g., ndiswrapper & NDIS drivers) seem to have
475 * timing issues with keys being cleared just before new keys
476 * are set or just after association or something similar. This
477 * shows up in group key handshake failing often because of the
478 * client not receiving the first encrypted packets correctly.
479 * Skipping some of the extra key clearing steps seems to help
480 * in completing group key handshake more reliably. */
481 wpa_dbg(wpa_s
, MSG_DEBUG
, "No keys have been configured - "
482 "skip key clearing");
486 /* MLME-DELETEKEYS.request */
487 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
488 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
489 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
490 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
491 #ifdef CONFIG_IEEE80211W
492 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
493 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
494 #endif /* CONFIG_IEEE80211W */
496 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, addr
, 0, 0, NULL
, 0, NULL
,
498 /* MLME-SETPROTECTION.request(None) */
499 wpa_drv_mlme_setprotection(
501 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
502 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
504 wpa_s
->keys_cleared
= 1;
509 * wpa_supplicant_state_txt - Get the connection state name as a text string
510 * @state: State (wpa_state; WPA_*)
511 * Returns: The state name as a printable text string
513 const char * wpa_supplicant_state_txt(enum wpa_states state
)
516 case WPA_DISCONNECTED
:
517 return "DISCONNECTED";
520 case WPA_INTERFACE_DISABLED
:
521 return "INTERFACE_DISABLED";
524 case WPA_AUTHENTICATING
:
525 return "AUTHENTICATING";
526 case WPA_ASSOCIATING
:
527 return "ASSOCIATING";
530 case WPA_4WAY_HANDSHAKE
:
531 return "4WAY_HANDSHAKE";
532 case WPA_GROUP_HANDSHAKE
:
533 return "GROUP_HANDSHAKE";
544 static void wpa_supplicant_start_bgscan(struct wpa_supplicant
*wpa_s
)
546 if (wpas_driver_bss_selection(wpa_s
))
548 if (wpa_s
->current_ssid
== wpa_s
->bgscan_ssid
)
551 bgscan_deinit(wpa_s
);
552 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->bgscan
) {
553 if (bgscan_init(wpa_s
, wpa_s
->current_ssid
)) {
554 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to initialize "
557 * Live without bgscan; it is only used as a roaming
558 * optimization, so the initial connection is not
562 wpa_s
->bgscan_ssid
= wpa_s
->current_ssid
;
564 wpa_s
->bgscan_ssid
= NULL
;
568 static void wpa_supplicant_stop_bgscan(struct wpa_supplicant
*wpa_s
)
570 if (wpa_s
->bgscan_ssid
!= NULL
) {
571 bgscan_deinit(wpa_s
);
572 wpa_s
->bgscan_ssid
= NULL
;
576 #endif /* CONFIG_BGSCAN */
579 static void wpa_supplicant_start_autoscan(struct wpa_supplicant
*wpa_s
)
581 if (autoscan_init(wpa_s
, 0))
582 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to initialize autoscan");
586 static void wpa_supplicant_stop_autoscan(struct wpa_supplicant
*wpa_s
)
588 autoscan_deinit(wpa_s
);
592 void wpa_supplicant_reinit_autoscan(struct wpa_supplicant
*wpa_s
)
594 if (wpa_s
->wpa_state
== WPA_DISCONNECTED
||
595 wpa_s
->wpa_state
== WPA_SCANNING
) {
596 autoscan_deinit(wpa_s
);
597 wpa_supplicant_start_autoscan(wpa_s
);
603 * wpa_supplicant_set_state - Set current connection state
604 * @wpa_s: Pointer to wpa_supplicant data
605 * @state: The new connection state
607 * This function is called whenever the connection state changes, e.g.,
608 * association is completed for WPA/WPA2 4-Way Handshake is started.
610 void wpa_supplicant_set_state(struct wpa_supplicant
*wpa_s
,
611 enum wpa_states state
)
613 enum wpa_states old_state
= wpa_s
->wpa_state
;
615 wpa_dbg(wpa_s
, MSG_DEBUG
, "State: %s -> %s",
616 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
617 wpa_supplicant_state_txt(state
));
619 if (state
!= WPA_SCANNING
)
620 wpa_supplicant_notify_scanning(wpa_s
, 0);
622 if (state
== WPA_COMPLETED
&& wpa_s
->new_connection
) {
623 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
624 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
625 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
"- Connection to "
626 MACSTR
" completed %s [id=%d id_str=%s]",
627 MAC2STR(wpa_s
->bssid
), wpa_s
->reassociated_connection
?
628 "(reauth)" : "(auth)",
629 ssid
? ssid
->id
: -1,
630 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
631 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
632 wpa_s
->new_connection
= 0;
633 wpa_s
->reassociated_connection
= 1;
634 wpa_drv_set_operstate(wpa_s
, 1);
635 #ifndef IEEE8021X_EAPOL
636 wpa_drv_set_supp_port(wpa_s
, 1);
637 #endif /* IEEE8021X_EAPOL */
638 wpa_s
->after_wps
= 0;
640 wpas_p2p_completed(wpa_s
);
641 #endif /* CONFIG_P2P */
643 sme_sched_obss_scan(wpa_s
, 1);
644 } else if (state
== WPA_DISCONNECTED
|| state
== WPA_ASSOCIATING
||
645 state
== WPA_ASSOCIATED
) {
646 wpa_s
->new_connection
= 1;
647 wpa_drv_set_operstate(wpa_s
, 0);
648 #ifndef IEEE8021X_EAPOL
649 wpa_drv_set_supp_port(wpa_s
, 0);
650 #endif /* IEEE8021X_EAPOL */
651 sme_sched_obss_scan(wpa_s
, 0);
653 wpa_s
->wpa_state
= state
;
656 if (state
== WPA_COMPLETED
)
657 wpa_supplicant_start_bgscan(wpa_s
);
659 wpa_supplicant_stop_bgscan(wpa_s
);
660 #endif /* CONFIG_BGSCAN */
662 if (state
== WPA_AUTHENTICATING
)
663 wpa_supplicant_stop_autoscan(wpa_s
);
665 if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
666 wpa_supplicant_start_autoscan(wpa_s
);
668 if (wpa_s
->wpa_state
!= old_state
) {
669 wpas_notify_state_changed(wpa_s
, wpa_s
->wpa_state
, old_state
);
671 if (wpa_s
->wpa_state
== WPA_COMPLETED
||
672 old_state
== WPA_COMPLETED
)
673 wpas_notify_auth_changed(wpa_s
);
678 void wpa_supplicant_terminate_proc(struct wpa_global
*global
)
682 struct wpa_supplicant
*wpa_s
= global
->ifaces
;
684 if (wpas_wps_terminate_pending(wpa_s
) == 1)
688 #endif /* CONFIG_WPS */
695 static void wpa_supplicant_terminate(int sig
, void *signal_ctx
)
697 struct wpa_global
*global
= signal_ctx
;
698 wpa_supplicant_terminate_proc(global
);
702 void wpa_supplicant_clear_status(struct wpa_supplicant
*wpa_s
)
704 enum wpa_states old_state
= wpa_s
->wpa_state
;
706 wpa_s
->pairwise_cipher
= 0;
707 wpa_s
->group_cipher
= 0;
708 wpa_s
->mgmt_group_cipher
= 0;
710 if (wpa_s
->wpa_state
!= WPA_INTERFACE_DISABLED
)
711 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
713 if (wpa_s
->wpa_state
!= old_state
)
714 wpas_notify_state_changed(wpa_s
, wpa_s
->wpa_state
, old_state
);
719 * wpa_supplicant_reload_configuration - Reload configuration data
720 * @wpa_s: Pointer to wpa_supplicant data
721 * Returns: 0 on success or -1 if configuration parsing failed
723 * This function can be used to request that the configuration data is reloaded
724 * (e.g., after configuration file change). This function is reloading
725 * configuration only for one interface, so this may need to be called multiple
726 * times if %wpa_supplicant is controlling multiple interfaces and all
727 * interfaces need reconfiguration.
729 int wpa_supplicant_reload_configuration(struct wpa_supplicant
*wpa_s
)
731 struct wpa_config
*conf
;
735 if (wpa_s
->confname
== NULL
)
737 conf
= wpa_config_read(wpa_s
->confname
);
739 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to parse the configuration "
740 "file '%s' - exiting", wpa_s
->confname
);
743 conf
->changed_parameters
= (unsigned int) -1;
745 reconf_ctrl
= !!conf
->ctrl_interface
!= !!wpa_s
->conf
->ctrl_interface
746 || (conf
->ctrl_interface
&& wpa_s
->conf
->ctrl_interface
&&
747 os_strcmp(conf
->ctrl_interface
,
748 wpa_s
->conf
->ctrl_interface
) != 0);
750 if (reconf_ctrl
&& wpa_s
->ctrl_iface
) {
751 wpa_supplicant_ctrl_iface_deinit(wpa_s
->ctrl_iface
);
752 wpa_s
->ctrl_iface
= NULL
;
755 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
756 if (wpa_s
->current_ssid
) {
757 wpa_supplicant_deauthenticate(wpa_s
,
758 WLAN_REASON_DEAUTH_LEAVING
);
762 * TODO: should notify EAPOL SM about changes in opensc_engine_path,
763 * pkcs11_engine_path, pkcs11_module_path.
765 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
767 * Clear forced success to clear EAP state for next
770 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
772 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
773 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
774 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
775 wpa_sm_set_fast_reauth(wpa_s
->wpa
, wpa_s
->conf
->fast_reauth
);
776 rsn_preauth_deinit(wpa_s
->wpa
);
778 old_ap_scan
= wpa_s
->conf
->ap_scan
;
779 wpa_config_free(wpa_s
->conf
);
781 if (old_ap_scan
!= wpa_s
->conf
->ap_scan
)
782 wpas_notify_ap_scan_changed(wpa_s
);
785 wpa_s
->ctrl_iface
= wpa_supplicant_ctrl_iface_init(wpa_s
);
787 wpa_supplicant_update_config(wpa_s
);
789 wpa_supplicant_clear_status(wpa_s
);
790 if (wpa_supplicant_enabled_networks(wpa_s
)) {
791 wpa_s
->reassociate
= 1;
792 wpa_supplicant_req_scan(wpa_s
, 0, 0);
794 wpa_dbg(wpa_s
, MSG_DEBUG
, "Reconfiguration completed");
799 static void wpa_supplicant_reconfig(int sig
, void *signal_ctx
)
801 struct wpa_global
*global
= signal_ctx
;
802 struct wpa_supplicant
*wpa_s
;
803 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
804 wpa_dbg(wpa_s
, MSG_DEBUG
, "Signal %d received - reconfiguring",
806 if (wpa_supplicant_reload_configuration(wpa_s
) < 0) {
807 wpa_supplicant_terminate_proc(global
);
813 enum wpa_cipher
cipher_suite2driver(int cipher
)
816 case WPA_CIPHER_NONE
:
818 case WPA_CIPHER_WEP40
:
820 case WPA_CIPHER_WEP104
:
821 return CIPHER_WEP104
;
822 case WPA_CIPHER_CCMP
:
824 case WPA_CIPHER_TKIP
:
831 enum wpa_key_mgmt
key_mgmt2driver(int key_mgmt
)
834 case WPA_KEY_MGMT_NONE
:
835 return KEY_MGMT_NONE
;
836 case WPA_KEY_MGMT_IEEE8021X_NO_WPA
:
837 return KEY_MGMT_802_1X_NO_WPA
;
838 case WPA_KEY_MGMT_IEEE8021X
:
839 return KEY_MGMT_802_1X
;
840 case WPA_KEY_MGMT_WPA_NONE
:
841 return KEY_MGMT_WPA_NONE
;
842 case WPA_KEY_MGMT_FT_IEEE8021X
:
843 return KEY_MGMT_FT_802_1X
;
844 case WPA_KEY_MGMT_FT_PSK
:
845 return KEY_MGMT_FT_PSK
;
846 case WPA_KEY_MGMT_IEEE8021X_SHA256
:
847 return KEY_MGMT_802_1X_SHA256
;
848 case WPA_KEY_MGMT_PSK_SHA256
:
849 return KEY_MGMT_PSK_SHA256
;
850 case WPA_KEY_MGMT_WPS
:
852 case WPA_KEY_MGMT_PSK
:
859 static int wpa_supplicant_suites_from_ai(struct wpa_supplicant
*wpa_s
,
860 struct wpa_ssid
*ssid
,
861 struct wpa_ie_data
*ie
)
863 int ret
= wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, ie
);
866 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Failed to parse WPA IE "
867 "from association info");
872 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Using WPA IE from AssocReq to set "
874 if (!(ie
->group_cipher
& ssid
->group_cipher
)) {
875 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled group "
876 "cipher 0x%x (mask 0x%x) - reject",
877 ie
->group_cipher
, ssid
->group_cipher
);
880 if (!(ie
->pairwise_cipher
& ssid
->pairwise_cipher
)) {
881 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled pairwise "
882 "cipher 0x%x (mask 0x%x) - reject",
883 ie
->pairwise_cipher
, ssid
->pairwise_cipher
);
886 if (!(ie
->key_mgmt
& ssid
->key_mgmt
)) {
887 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled key "
888 "management 0x%x (mask 0x%x) - reject",
889 ie
->key_mgmt
, ssid
->key_mgmt
);
893 #ifdef CONFIG_IEEE80211W
894 if (!(ie
->capabilities
& WPA_CAPABILITY_MFPC
) &&
895 ssid
->ieee80211w
== MGMT_FRAME_PROTECTION_REQUIRED
) {
896 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver associated with an AP "
897 "that does not support management frame protection - "
901 #endif /* CONFIG_IEEE80211W */
908 * wpa_supplicant_set_suites - Set authentication and encryption parameters
909 * @wpa_s: Pointer to wpa_supplicant data
910 * @bss: Scan results for the selected BSS, or %NULL if not available
911 * @ssid: Configuration data for the selected network
912 * @wpa_ie: Buffer for the WPA/RSN IE
913 * @wpa_ie_len: Maximum wpa_ie buffer size on input. This is changed to be the
914 * used buffer length in case the functions returns success.
915 * Returns: 0 on success or -1 on failure
917 * This function is used to configure authentication and encryption parameters
918 * based on the network configuration and scan result for the selected BSS (if
921 int wpa_supplicant_set_suites(struct wpa_supplicant
*wpa_s
,
922 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
,
923 u8
*wpa_ie
, size_t *wpa_ie_len
)
925 struct wpa_ie_data ie
;
927 const u8
*bss_wpa
, *bss_rsn
;
930 bss_wpa
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
931 bss_rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
933 bss_wpa
= bss_rsn
= NULL
;
935 if (bss_rsn
&& (ssid
->proto
& WPA_PROTO_RSN
) &&
936 wpa_parse_wpa_ie(bss_rsn
, 2 + bss_rsn
[1], &ie
) == 0 &&
937 (ie
.group_cipher
& ssid
->group_cipher
) &&
938 (ie
.pairwise_cipher
& ssid
->pairwise_cipher
) &&
939 (ie
.key_mgmt
& ssid
->key_mgmt
)) {
940 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: using IEEE 802.11i/D9.0");
941 proto
= WPA_PROTO_RSN
;
942 } else if (bss_wpa
&& (ssid
->proto
& WPA_PROTO_WPA
) &&
943 wpa_parse_wpa_ie(bss_wpa
, 2 +bss_wpa
[1], &ie
) == 0 &&
944 (ie
.group_cipher
& ssid
->group_cipher
) &&
945 (ie
.pairwise_cipher
& ssid
->pairwise_cipher
) &&
946 (ie
.key_mgmt
& ssid
->key_mgmt
)) {
947 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using IEEE 802.11i/D3.0");
948 proto
= WPA_PROTO_WPA
;
950 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select WPA/RSN");
953 if (ssid
->proto
& WPA_PROTO_RSN
)
954 proto
= WPA_PROTO_RSN
;
956 proto
= WPA_PROTO_WPA
;
957 if (wpa_supplicant_suites_from_ai(wpa_s
, ssid
, &ie
) < 0) {
958 os_memset(&ie
, 0, sizeof(ie
));
959 ie
.group_cipher
= ssid
->group_cipher
;
960 ie
.pairwise_cipher
= ssid
->pairwise_cipher
;
961 ie
.key_mgmt
= ssid
->key_mgmt
;
962 #ifdef CONFIG_IEEE80211W
963 ie
.mgmt_group_cipher
=
964 ssid
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
?
965 WPA_CIPHER_AES_128_CMAC
: 0;
966 #endif /* CONFIG_IEEE80211W */
967 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Set cipher suites "
968 "based on configuration");
973 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Selected cipher suites: group %d "
974 "pairwise %d key_mgmt %d proto %d",
975 ie
.group_cipher
, ie
.pairwise_cipher
, ie
.key_mgmt
, proto
);
976 #ifdef CONFIG_IEEE80211W
977 if (ssid
->ieee80211w
) {
978 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Selected mgmt group cipher %d",
979 ie
.mgmt_group_cipher
);
981 #endif /* CONFIG_IEEE80211W */
983 wpa_s
->wpa_proto
= proto
;
984 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PROTO
, proto
);
985 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_RSN_ENABLED
,
986 !!(ssid
->proto
& WPA_PROTO_RSN
));
988 if (bss
|| !wpa_s
->ap_ies_from_associnfo
) {
989 if (wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, bss_wpa
,
990 bss_wpa
? 2 + bss_wpa
[1] : 0) ||
991 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, bss_rsn
,
992 bss_rsn
? 2 + bss_rsn
[1] : 0))
996 sel
= ie
.group_cipher
& ssid
->group_cipher
;
997 if (sel
& WPA_CIPHER_CCMP
) {
998 wpa_s
->group_cipher
= WPA_CIPHER_CCMP
;
999 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using GTK CCMP");
1000 } else if (sel
& WPA_CIPHER_TKIP
) {
1001 wpa_s
->group_cipher
= WPA_CIPHER_TKIP
;
1002 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using GTK TKIP");
1003 } else if (sel
& WPA_CIPHER_WEP104
) {
1004 wpa_s
->group_cipher
= WPA_CIPHER_WEP104
;
1005 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using GTK WEP104");
1006 } else if (sel
& WPA_CIPHER_WEP40
) {
1007 wpa_s
->group_cipher
= WPA_CIPHER_WEP40
;
1008 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using GTK WEP40");
1010 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select group "
1015 sel
= ie
.pairwise_cipher
& ssid
->pairwise_cipher
;
1016 if (sel
& WPA_CIPHER_CCMP
) {
1017 wpa_s
->pairwise_cipher
= WPA_CIPHER_CCMP
;
1018 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using PTK CCMP");
1019 } else if (sel
& WPA_CIPHER_TKIP
) {
1020 wpa_s
->pairwise_cipher
= WPA_CIPHER_TKIP
;
1021 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using PTK TKIP");
1022 } else if (sel
& WPA_CIPHER_NONE
) {
1023 wpa_s
->pairwise_cipher
= WPA_CIPHER_NONE
;
1024 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using PTK NONE");
1026 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select pairwise "
1031 sel
= ie
.key_mgmt
& ssid
->key_mgmt
;
1033 #ifdef CONFIG_IEEE80211R
1034 } else if (sel
& WPA_KEY_MGMT_FT_IEEE8021X
) {
1035 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_IEEE8021X
;
1036 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FT/802.1X");
1037 } else if (sel
& WPA_KEY_MGMT_FT_PSK
) {
1038 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_PSK
;
1039 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FT/PSK");
1040 #endif /* CONFIG_IEEE80211R */
1041 #ifdef CONFIG_IEEE80211W
1042 } else if (sel
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
1043 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X_SHA256
;
1044 wpa_dbg(wpa_s
, MSG_DEBUG
,
1045 "WPA: using KEY_MGMT 802.1X with SHA256");
1046 } else if (sel
& WPA_KEY_MGMT_PSK_SHA256
) {
1047 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK_SHA256
;
1048 wpa_dbg(wpa_s
, MSG_DEBUG
,
1049 "WPA: using KEY_MGMT PSK with SHA256");
1050 #endif /* CONFIG_IEEE80211W */
1051 } else if (sel
& WPA_KEY_MGMT_IEEE8021X
) {
1052 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X
;
1053 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT 802.1X");
1054 } else if (sel
& WPA_KEY_MGMT_PSK
) {
1055 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK
;
1056 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT WPA-PSK");
1057 } else if (sel
& WPA_KEY_MGMT_WPA_NONE
) {
1058 wpa_s
->key_mgmt
= WPA_KEY_MGMT_WPA_NONE
;
1059 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT WPA-NONE");
1061 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select "
1062 "authenticated key management type");
1066 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_KEY_MGMT
, wpa_s
->key_mgmt
);
1067 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PAIRWISE
,
1068 wpa_s
->pairwise_cipher
);
1069 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_GROUP
, wpa_s
->group_cipher
);
1071 #ifdef CONFIG_IEEE80211W
1072 sel
= ie
.mgmt_group_cipher
;
1073 if (ssid
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
||
1074 !(ie
.capabilities
& WPA_CAPABILITY_MFPC
))
1076 if (sel
& WPA_CIPHER_AES_128_CMAC
) {
1077 wpa_s
->mgmt_group_cipher
= WPA_CIPHER_AES_128_CMAC
;
1078 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using MGMT group cipher "
1081 wpa_s
->mgmt_group_cipher
= 0;
1082 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: not using MGMT group cipher");
1084 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MGMT_GROUP
,
1085 wpa_s
->mgmt_group_cipher
);
1086 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MFP
, ssid
->ieee80211w
);
1087 #endif /* CONFIG_IEEE80211W */
1089 if (wpa_sm_set_assoc_wpa_ie_default(wpa_s
->wpa
, wpa_ie
, wpa_ie_len
)) {
1090 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to generate WPA IE");
1094 if (wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
)) {
1095 wpa_sm_set_pmk(wpa_s
->wpa
, ssid
->psk
, PMK_LEN
);
1096 #ifndef CONFIG_NO_PBKDF2
1097 if (bss
&& ssid
->bssid_set
&& ssid
->ssid_len
== 0 &&
1100 pbkdf2_sha1(ssid
->passphrase
, (char *) bss
->ssid
,
1101 bss
->ssid_len
, 4096, psk
, PMK_LEN
);
1102 wpa_hexdump_key(MSG_MSGDUMP
, "PSK (from passphrase)",
1104 wpa_sm_set_pmk(wpa_s
->wpa
, psk
, PMK_LEN
);
1106 #endif /* CONFIG_NO_PBKDF2 */
1108 wpa_sm_set_pmk_from_pmksa(wpa_s
->wpa
);
1115 * wpa_supplicant_associate - Request association
1116 * @wpa_s: Pointer to wpa_supplicant data
1117 * @bss: Scan results for the selected BSS, or %NULL if not available
1118 * @ssid: Configuration data for the selected network
1120 * This function is used to request %wpa_supplicant to associate with a BSS.
1122 void wpa_supplicant_associate(struct wpa_supplicant
*wpa_s
,
1123 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
)
1127 int use_crypt
, ret
, i
, bssid_changed
;
1128 int algs
= WPA_AUTH_ALG_OPEN
;
1129 enum wpa_cipher cipher_pairwise
, cipher_group
;
1130 struct wpa_driver_associate_params params
;
1131 int wep_keys_set
= 0;
1132 struct wpa_driver_capa capa
;
1133 int assoc_failed
= 0;
1134 struct wpa_ssid
*old_ssid
;
1135 #ifdef CONFIG_HT_OVERRIDES
1136 struct ieee80211_ht_capabilities htcaps
;
1137 struct ieee80211_ht_capabilities htcaps_mask
;
1138 #endif /* CONFIG_HT_OVERRIDES */
1140 #ifdef CONFIG_IBSS_RSN
1141 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
1142 wpa_s
->ibss_rsn
= NULL
;
1143 #endif /* CONFIG_IBSS_RSN */
1145 if (ssid
->mode
== WPAS_MODE_AP
|| ssid
->mode
== WPAS_MODE_P2P_GO
||
1146 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
) {
1148 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_AP
)) {
1149 wpa_msg(wpa_s
, MSG_INFO
, "Driver does not support AP "
1153 wpa_supplicant_create_ap(wpa_s
, ssid
);
1154 wpa_s
->current_bss
= bss
;
1155 #else /* CONFIG_AP */
1156 wpa_msg(wpa_s
, MSG_ERROR
, "AP mode support not included in "
1158 #endif /* CONFIG_AP */
1164 wpa_tdls_ap_ies(wpa_s
->wpa
, (const u8
*) (bss
+ 1),
1166 #endif /* CONFIG_TDLS */
1168 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
1169 ssid
->mode
== IEEE80211_MODE_INFRA
) {
1170 sme_authenticate(wpa_s
, bss
, ssid
);
1174 os_memset(¶ms
, 0, sizeof(params
));
1175 wpa_s
->reassociate
= 0;
1176 if (bss
&& !wpas_driver_bss_selection(wpa_s
)) {
1177 #ifdef CONFIG_IEEE80211R
1178 const u8
*ie
, *md
= NULL
;
1179 #endif /* CONFIG_IEEE80211R */
1180 wpa_msg(wpa_s
, MSG_INFO
, "Trying to associate with " MACSTR
1181 " (SSID='%s' freq=%d MHz)", MAC2STR(bss
->bssid
),
1182 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
), bss
->freq
);
1183 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
1184 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
1185 os_memcpy(wpa_s
->pending_bssid
, bss
->bssid
, ETH_ALEN
);
1187 wpas_notify_bssid_changed(wpa_s
);
1188 #ifdef CONFIG_IEEE80211R
1189 ie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
1190 if (ie
&& ie
[1] >= MOBILITY_DOMAIN_ID_LEN
)
1192 wpa_sm_set_ft_params(wpa_s
->wpa
, ie
, ie
? 2 + ie
[1] : 0);
1194 /* Prepare for the next transition */
1195 wpa_ft_prepare_auth_request(wpa_s
->wpa
, ie
);
1197 #endif /* CONFIG_IEEE80211R */
1199 } else if ((ssid
->ssid
== NULL
|| ssid
->ssid_len
== 0) &&
1200 wpa_s
->conf
->ap_scan
== 2 &&
1201 (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
1202 /* Use ap_scan==1 style network selection to find the network
1204 wpa_s
->scan_req
= 2;
1205 wpa_s
->reassociate
= 1;
1206 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1208 #endif /* CONFIG_WPS */
1210 wpa_msg(wpa_s
, MSG_INFO
, "Trying to associate with SSID '%s'",
1211 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
1212 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1214 wpa_supplicant_cancel_sched_scan(wpa_s
);
1215 wpa_supplicant_cancel_scan(wpa_s
);
1217 /* Starting new association, so clear the possibly used WPA IE from the
1218 * previous association. */
1219 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1221 #ifdef IEEE8021X_EAPOL
1222 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1224 if (ssid
->non_leap
== 0)
1225 algs
= WPA_AUTH_ALG_LEAP
;
1227 algs
|= WPA_AUTH_ALG_LEAP
;
1230 #endif /* IEEE8021X_EAPOL */
1231 wpa_dbg(wpa_s
, MSG_DEBUG
, "Automatic auth_alg selection: 0x%x", algs
);
1232 if (ssid
->auth_alg
) {
1233 algs
= ssid
->auth_alg
;
1234 wpa_dbg(wpa_s
, MSG_DEBUG
, "Overriding auth_alg selection: "
1238 if (bss
&& (wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
) ||
1239 wpa_bss_get_ie(bss
, WLAN_EID_RSN
)) &&
1240 wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
1241 int try_opportunistic
;
1242 try_opportunistic
= ssid
->proactive_key_caching
&&
1243 (ssid
->proto
& WPA_PROTO_RSN
);
1244 if (pmksa_cache_set_current(wpa_s
->wpa
, NULL
, bss
->bssid
,
1245 wpa_s
->current_ssid
,
1246 try_opportunistic
) == 0)
1247 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
, 1);
1248 wpa_ie_len
= sizeof(wpa_ie
);
1249 if (wpa_supplicant_set_suites(wpa_s
, bss
, ssid
,
1250 wpa_ie
, &wpa_ie_len
)) {
1251 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to set WPA "
1252 "key management and encryption suites");
1255 } else if (wpa_key_mgmt_wpa_any(ssid
->key_mgmt
)) {
1256 wpa_ie_len
= sizeof(wpa_ie
);
1257 if (wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
1258 wpa_ie
, &wpa_ie_len
)) {
1259 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to set WPA "
1260 "key management and encryption suites (no "
1265 } else if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
1266 struct wpabuf
*wps_ie
;
1267 wps_ie
= wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid
));
1268 if (wps_ie
&& wpabuf_len(wps_ie
) <= sizeof(wpa_ie
)) {
1269 wpa_ie_len
= wpabuf_len(wps_ie
);
1270 os_memcpy(wpa_ie
, wpabuf_head(wps_ie
), wpa_ie_len
);
1273 wpabuf_free(wps_ie
);
1274 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
1275 if (!bss
|| (bss
->caps
& IEEE80211_CAP_PRIVACY
))
1276 params
.wps
= WPS_MODE_PRIVACY
;
1278 params
.wps
= WPS_MODE_OPEN
;
1279 wpa_s
->wpa_proto
= 0;
1280 #endif /* CONFIG_WPS */
1282 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
1284 wpa_s
->wpa_proto
= 0;
1288 if (wpa_s
->global
->p2p
) {
1292 pos
= wpa_ie
+ wpa_ie_len
;
1293 len
= sizeof(wpa_ie
) - wpa_ie_len
;
1294 res
= wpas_p2p_assoc_req_ie(wpa_s
, bss
, pos
, len
,
1300 wpa_s
->cross_connect_disallowed
= 0;
1303 p2p
= wpa_bss_get_vendor_ie_multi(bss
, P2P_IE_VENDOR_TYPE
);
1305 wpa_s
->cross_connect_disallowed
=
1306 p2p_get_cross_connect_disallowed(p2p
);
1308 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: WLAN AP %s cross "
1310 wpa_s
->cross_connect_disallowed
?
1311 "disallows" : "allows");
1314 #endif /* CONFIG_P2P */
1317 if (wpa_s
->conf
->hs20
) {
1318 struct wpabuf
*hs20
;
1319 hs20
= wpabuf_alloc(20);
1321 wpas_hs20_add_indication(hs20
);
1322 os_memcpy(wpa_ie
+ wpa_ie_len
, wpabuf_head(hs20
),
1324 wpa_ie_len
+= wpabuf_len(hs20
);
1328 #endif /* CONFIG_HS20 */
1330 #ifdef CONFIG_INTERWORKING
1331 if (wpa_s
->conf
->interworking
) {
1333 if (wpa_ie_len
> 0 && pos
[0] == WLAN_EID_RSN
)
1335 os_memmove(pos
+ 6, pos
, wpa_ie_len
- (pos
- wpa_ie
));
1337 *pos
++ = WLAN_EID_EXT_CAPAB
;
1342 *pos
++ = 0x80; /* Bit 31 - Interworking */
1344 #endif /* CONFIG_INTERWORKING */
1346 wpa_clear_keys(wpa_s
, bss
? bss
->bssid
: NULL
);
1348 cipher_pairwise
= cipher_suite2driver(wpa_s
->pairwise_cipher
);
1349 cipher_group
= cipher_suite2driver(wpa_s
->group_cipher
);
1350 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1351 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1352 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
)
1354 if (wpa_set_wep_keys(wpa_s
, ssid
)) {
1359 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
)
1362 #ifdef IEEE8021X_EAPOL
1363 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1364 if ((ssid
->eapol_flags
&
1365 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
1366 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
)) == 0 &&
1370 /* Assume that dynamic WEP-104 keys will be used and
1371 * set cipher suites in order for drivers to expect
1373 cipher_pairwise
= cipher_group
= CIPHER_WEP104
;
1376 #endif /* IEEE8021X_EAPOL */
1378 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1379 /* Set the key before (and later after) association */
1380 wpa_supplicant_set_wpa_none_key(wpa_s
, ssid
);
1383 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATING
);
1385 params
.ssid
= bss
->ssid
;
1386 params
.ssid_len
= bss
->ssid_len
;
1387 if (!wpas_driver_bss_selection(wpa_s
) || ssid
->bssid_set
) {
1388 wpa_printf(MSG_DEBUG
, "Limit connection to BSSID "
1389 MACSTR
" freq=%u MHz based on scan results "
1391 MAC2STR(bss
->bssid
), bss
->freq
,
1393 params
.bssid
= bss
->bssid
;
1394 params
.freq
= bss
->freq
;
1397 params
.ssid
= ssid
->ssid
;
1398 params
.ssid_len
= ssid
->ssid_len
;
1401 if (ssid
->mode
== WPAS_MODE_IBSS
&& ssid
->bssid_set
&&
1402 wpa_s
->conf
->ap_scan
== 2) {
1403 params
.bssid
= ssid
->bssid
;
1404 params
.fixed_bssid
= 1;
1407 if (ssid
->mode
== WPAS_MODE_IBSS
&& ssid
->frequency
> 0 &&
1409 params
.freq
= ssid
->frequency
; /* Initial channel for IBSS */
1410 params
.wpa_ie
= wpa_ie
;
1411 params
.wpa_ie_len
= wpa_ie_len
;
1412 params
.pairwise_suite
= cipher_pairwise
;
1413 params
.group_suite
= cipher_group
;
1414 params
.key_mgmt_suite
= key_mgmt2driver(wpa_s
->key_mgmt
);
1415 params
.wpa_proto
= wpa_s
->wpa_proto
;
1416 params
.auth_alg
= algs
;
1417 params
.mode
= ssid
->mode
;
1418 params
.bg_scan_period
= ssid
->bg_scan_period
;
1419 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
1420 if (ssid
->wep_key_len
[i
])
1421 params
.wep_key
[i
] = ssid
->wep_key
[i
];
1422 params
.wep_key_len
[i
] = ssid
->wep_key_len
[i
];
1424 params
.wep_tx_keyidx
= ssid
->wep_tx_keyidx
;
1426 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1427 (params
.key_mgmt_suite
== KEY_MGMT_PSK
||
1428 params
.key_mgmt_suite
== KEY_MGMT_FT_PSK
)) {
1429 params
.passphrase
= ssid
->passphrase
;
1431 params
.psk
= ssid
->psk
;
1434 params
.drop_unencrypted
= use_crypt
;
1436 #ifdef CONFIG_IEEE80211W
1437 params
.mgmt_frame_protection
= ssid
->ieee80211w
;
1438 if (ssid
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
&& bss
) {
1439 const u8
*rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1440 struct wpa_ie_data ie
;
1441 if (rsn
&& wpa_parse_wpa_ie(rsn
, 2 + rsn
[1], &ie
) == 0 &&
1443 (WPA_CAPABILITY_MFPC
| WPA_CAPABILITY_MFPR
)) {
1444 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Selected AP supports "
1445 "MFP: require MFP");
1446 params
.mgmt_frame_protection
=
1447 MGMT_FRAME_PROTECTION_REQUIRED
;
1450 #endif /* CONFIG_IEEE80211W */
1452 params
.p2p
= ssid
->p2p_group
;
1454 if (wpa_s
->parent
->set_sta_uapsd
)
1455 params
.uapsd
= wpa_s
->parent
->sta_uapsd
;
1459 #ifdef CONFIG_HT_OVERRIDES
1460 os_memset(&htcaps
, 0, sizeof(htcaps
));
1461 os_memset(&htcaps_mask
, 0, sizeof(htcaps_mask
));
1462 params
.htcaps
= (u8
*) &htcaps
;
1463 params
.htcaps_mask
= (u8
*) &htcaps_mask
;
1464 wpa_supplicant_apply_ht_overrides(wpa_s
, ssid
, ¶ms
);
1465 #endif /* CONFIG_HT_OVERRIDES */
1467 ret
= wpa_drv_associate(wpa_s
, ¶ms
);
1469 wpa_msg(wpa_s
, MSG_INFO
, "Association request to the driver "
1471 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SANE_ERROR_CODES
) {
1473 * The driver is known to mean what is saying, so we
1474 * can stop right here; the association will not
1477 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1478 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1479 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1482 /* try to continue anyway; new association will be tried again
1487 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1488 /* Set the key after the association just in case association
1489 * cleared the previously configured key. */
1490 wpa_supplicant_set_wpa_none_key(wpa_s
, ssid
);
1491 /* No need to timeout authentication since there is no key
1493 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1494 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1495 #ifdef CONFIG_IBSS_RSN
1496 } else if (ssid
->mode
== WPAS_MODE_IBSS
&&
1497 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
1498 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
) {
1500 * RSN IBSS authentication is per-STA and we can disable the
1501 * per-BSSID authentication.
1503 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1504 #endif /* CONFIG_IBSS_RSN */
1506 /* Timeout for IEEE 802.11 authentication and association */
1510 /* give IBSS a bit more time */
1511 timeout
= ssid
->mode
== WPAS_MODE_IBSS
? 10 : 5;
1512 } else if (wpa_s
->conf
->ap_scan
== 1) {
1513 /* give IBSS a bit more time */
1514 timeout
= ssid
->mode
== WPAS_MODE_IBSS
? 20 : 10;
1516 wpa_supplicant_req_auth_timeout(wpa_s
, timeout
, 0);
1519 if (wep_keys_set
&& wpa_drv_get_capa(wpa_s
, &capa
) == 0 &&
1520 capa
.flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC
) {
1521 /* Set static WEP keys again */
1522 wpa_set_wep_keys(wpa_s
, ssid
);
1525 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
) {
1527 * Do not allow EAP session resumption between different
1528 * network configurations.
1530 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
1532 old_ssid
= wpa_s
->current_ssid
;
1533 wpa_s
->current_ssid
= ssid
;
1534 wpa_s
->current_bss
= bss
;
1535 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
1536 wpa_supplicant_initiate_eapol(wpa_s
);
1537 if (old_ssid
!= wpa_s
->current_ssid
)
1538 wpas_notify_network_changed(wpa_s
);
1542 static void wpa_supplicant_clear_connection(struct wpa_supplicant
*wpa_s
,
1545 struct wpa_ssid
*old_ssid
;
1547 wpa_clear_keys(wpa_s
, addr
);
1548 wpa_supplicant_mark_disassoc(wpa_s
);
1549 old_ssid
= wpa_s
->current_ssid
;
1550 wpa_s
->current_ssid
= NULL
;
1551 wpa_s
->current_bss
= NULL
;
1552 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
1553 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
1554 if (old_ssid
!= wpa_s
->current_ssid
)
1555 wpas_notify_network_changed(wpa_s
);
1556 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
1561 * wpa_supplicant_disassociate - Disassociate the current connection
1562 * @wpa_s: Pointer to wpa_supplicant data
1563 * @reason_code: IEEE 802.11 reason code for the disassociate frame
1565 * This function is used to request %wpa_supplicant to disassociate with the
1568 void wpa_supplicant_disassociate(struct wpa_supplicant
*wpa_s
,
1572 union wpa_event_data event
;
1574 if (!is_zero_ether_addr(wpa_s
->bssid
)) {
1575 wpa_drv_disassociate(wpa_s
, wpa_s
->bssid
, reason_code
);
1576 addr
= wpa_s
->bssid
;
1577 os_memset(&event
, 0, sizeof(event
));
1578 event
.disassoc_info
.reason_code
= (u16
) reason_code
;
1579 event
.disassoc_info
.locally_generated
= 1;
1580 wpa_supplicant_event(wpa_s
, EVENT_DISASSOC
, &event
);
1583 wpa_supplicant_clear_connection(wpa_s
, addr
);
1588 * wpa_supplicant_deauthenticate - Deauthenticate the current connection
1589 * @wpa_s: Pointer to wpa_supplicant data
1590 * @reason_code: IEEE 802.11 reason code for the deauthenticate frame
1592 * This function is used to request %wpa_supplicant to deauthenticate from the
1595 void wpa_supplicant_deauthenticate(struct wpa_supplicant
*wpa_s
,
1599 union wpa_event_data event
;
1601 if (!is_zero_ether_addr(wpa_s
->bssid
)) {
1602 wpa_drv_deauthenticate(wpa_s
, wpa_s
->bssid
, reason_code
);
1603 addr
= wpa_s
->bssid
;
1604 os_memset(&event
, 0, sizeof(event
));
1605 event
.deauth_info
.reason_code
= (u16
) reason_code
;
1606 event
.deauth_info
.locally_generated
= 1;
1607 wpa_supplicant_event(wpa_s
, EVENT_DEAUTH
, &event
);
1610 wpa_supplicant_clear_connection(wpa_s
, addr
);
1615 * wpa_supplicant_enable_network - Mark a configured network as enabled
1616 * @wpa_s: wpa_supplicant structure for a network interface
1617 * @ssid: wpa_ssid structure for a configured network or %NULL
1619 * Enables the specified network or all networks if no network specified.
1621 void wpa_supplicant_enable_network(struct wpa_supplicant
*wpa_s
,
1622 struct wpa_ssid
*ssid
)
1624 struct wpa_ssid
*other_ssid
;
1628 for (other_ssid
= wpa_s
->conf
->ssid
; other_ssid
;
1629 other_ssid
= other_ssid
->next
) {
1630 if (other_ssid
->disabled
== 2)
1631 continue; /* do not change persistent P2P group
1633 if (other_ssid
== wpa_s
->current_ssid
&&
1634 other_ssid
->disabled
)
1635 wpa_s
->reassociate
= 1;
1637 was_disabled
= other_ssid
->disabled
;
1639 other_ssid
->disabled
= 0;
1641 if (was_disabled
!= other_ssid
->disabled
)
1642 wpas_notify_network_enabled_changed(
1645 if (wpa_s
->reassociate
)
1646 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1647 } else if (ssid
->disabled
&& ssid
->disabled
!= 2) {
1648 if (wpa_s
->current_ssid
== NULL
) {
1650 * Try to reassociate since there is no current
1651 * configuration and a new network was made available.
1653 wpa_s
->reassociate
= 1;
1654 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1657 was_disabled
= ssid
->disabled
;
1661 if (was_disabled
!= ssid
->disabled
)
1662 wpas_notify_network_enabled_changed(wpa_s
, ssid
);
1668 * wpa_supplicant_disable_network - Mark a configured network as disabled
1669 * @wpa_s: wpa_supplicant structure for a network interface
1670 * @ssid: wpa_ssid structure for a configured network or %NULL
1672 * Disables the specified network or all networks if no network specified.
1674 void wpa_supplicant_disable_network(struct wpa_supplicant
*wpa_s
,
1675 struct wpa_ssid
*ssid
)
1677 struct wpa_ssid
*other_ssid
;
1681 for (other_ssid
= wpa_s
->conf
->ssid
; other_ssid
;
1682 other_ssid
= other_ssid
->next
) {
1683 was_disabled
= other_ssid
->disabled
;
1684 if (was_disabled
== 2)
1685 continue; /* do not change persistent P2P group
1688 other_ssid
->disabled
= 1;
1690 if (was_disabled
!= other_ssid
->disabled
)
1691 wpas_notify_network_enabled_changed(
1694 if (wpa_s
->current_ssid
)
1695 wpa_supplicant_disassociate(
1696 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1697 } else if (ssid
->disabled
!= 2) {
1698 if (ssid
== wpa_s
->current_ssid
)
1699 wpa_supplicant_disassociate(
1700 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1702 was_disabled
= ssid
->disabled
;
1706 if (was_disabled
!= ssid
->disabled
)
1707 wpas_notify_network_enabled_changed(wpa_s
, ssid
);
1713 * wpa_supplicant_select_network - Attempt association with a network
1714 * @wpa_s: wpa_supplicant structure for a network interface
1715 * @ssid: wpa_ssid structure for a configured network or %NULL for any network
1717 void wpa_supplicant_select_network(struct wpa_supplicant
*wpa_s
,
1718 struct wpa_ssid
*ssid
)
1721 struct wpa_ssid
*other_ssid
;
1722 int disconnected
= 0;
1724 if (ssid
&& ssid
!= wpa_s
->current_ssid
&& wpa_s
->current_ssid
) {
1725 wpa_supplicant_disassociate(
1726 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1731 * Mark all other networks disabled or mark all networks enabled if no
1732 * network specified.
1734 for (other_ssid
= wpa_s
->conf
->ssid
; other_ssid
;
1735 other_ssid
= other_ssid
->next
) {
1736 int was_disabled
= other_ssid
->disabled
;
1737 if (was_disabled
== 2)
1738 continue; /* do not change persistent P2P group data */
1740 other_ssid
->disabled
= ssid
? (ssid
->id
!= other_ssid
->id
) : 0;
1742 if (was_disabled
!= other_ssid
->disabled
)
1743 wpas_notify_network_enabled_changed(wpa_s
, other_ssid
);
1746 if (ssid
&& ssid
== wpa_s
->current_ssid
&& wpa_s
->current_ssid
) {
1747 /* We are already associated with the selected network */
1748 wpa_printf(MSG_DEBUG
, "Already associated with the "
1749 "selected network - do nothing");
1754 wpa_s
->current_ssid
= ssid
;
1755 wpa_s
->connect_without_scan
= NULL
;
1756 wpa_s
->disconnected
= 0;
1757 wpa_s
->reassociate
= 1;
1758 wpa_supplicant_req_scan(wpa_s
, 0, disconnected
? 100000 : 0);
1761 wpas_notify_network_selected(wpa_s
, ssid
);
1766 * wpa_supplicant_set_ap_scan - Set AP scan mode for interface
1767 * @wpa_s: wpa_supplicant structure for a network interface
1768 * @ap_scan: AP scan mode
1769 * Returns: 0 if succeed or -1 if ap_scan has an invalid value
1772 int wpa_supplicant_set_ap_scan(struct wpa_supplicant
*wpa_s
, int ap_scan
)
1777 if (ap_scan
< 0 || ap_scan
> 2)
1781 if (ap_scan
== 2 && ap_scan
!= wpa_s
->conf
->ap_scan
&&
1782 wpa_s
->wpa_state
>= WPA_ASSOCIATING
&&
1783 wpa_s
->wpa_state
< WPA_COMPLETED
) {
1784 wpa_printf(MSG_ERROR
, "ap_scan = %d (%d) rejected while "
1785 "associating", wpa_s
->conf
->ap_scan
, ap_scan
);
1788 #endif /* ANDROID */
1790 old_ap_scan
= wpa_s
->conf
->ap_scan
;
1791 wpa_s
->conf
->ap_scan
= ap_scan
;
1793 if (old_ap_scan
!= wpa_s
->conf
->ap_scan
)
1794 wpas_notify_ap_scan_changed(wpa_s
);
1801 * wpa_supplicant_set_bss_expiration_age - Set BSS entry expiration age
1802 * @wpa_s: wpa_supplicant structure for a network interface
1803 * @expire_age: Expiration age in seconds
1804 * Returns: 0 if succeed or -1 if expire_age has an invalid value
1807 int wpa_supplicant_set_bss_expiration_age(struct wpa_supplicant
*wpa_s
,
1808 unsigned int bss_expire_age
)
1810 if (bss_expire_age
< 10) {
1811 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid bss expiration age %u",
1815 wpa_msg(wpa_s
, MSG_DEBUG
, "Setting bss expiration age: %d sec",
1817 wpa_s
->conf
->bss_expiration_age
= bss_expire_age
;
1824 * wpa_supplicant_set_bss_expiration_count - Set BSS entry expiration scan count
1825 * @wpa_s: wpa_supplicant structure for a network interface
1826 * @expire_count: number of scans after which an unseen BSS is reclaimed
1827 * Returns: 0 if succeed or -1 if expire_count has an invalid value
1830 int wpa_supplicant_set_bss_expiration_count(struct wpa_supplicant
*wpa_s
,
1831 unsigned int bss_expire_count
)
1833 if (bss_expire_count
< 1) {
1834 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid bss expiration count %u",
1838 wpa_msg(wpa_s
, MSG_DEBUG
, "Setting bss expiration scan count: %u",
1840 wpa_s
->conf
->bss_expiration_scan_count
= bss_expire_count
;
1847 * wpa_supplicant_set_scan_interval - Set scan interval
1848 * @wpa_s: wpa_supplicant structure for a network interface
1849 * @scan_interval: scan interval in seconds
1850 * Returns: 0 if succeed or -1 if scan_interval has an invalid value
1853 int wpa_supplicant_set_scan_interval(struct wpa_supplicant
*wpa_s
,
1856 if (scan_interval
< 0) {
1857 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid scan interval %d",
1861 wpa_msg(wpa_s
, MSG_DEBUG
, "Setting scan interval: %d sec",
1863 wpa_s
->scan_interval
= scan_interval
;
1870 * wpa_supplicant_set_debug_params - Set global debug params
1871 * @global: wpa_global structure
1872 * @debug_level: debug level
1873 * @debug_timestamp: determines if show timestamp in debug data
1874 * @debug_show_keys: determines if show keys in debug data
1875 * Returns: 0 if succeed or -1 if debug_level has wrong value
1877 int wpa_supplicant_set_debug_params(struct wpa_global
*global
, int debug_level
,
1878 int debug_timestamp
, int debug_show_keys
)
1881 int old_level
, old_timestamp
, old_show_keys
;
1883 /* check for allowed debuglevels */
1884 if (debug_level
!= MSG_EXCESSIVE
&&
1885 debug_level
!= MSG_MSGDUMP
&&
1886 debug_level
!= MSG_DEBUG
&&
1887 debug_level
!= MSG_INFO
&&
1888 debug_level
!= MSG_WARNING
&&
1889 debug_level
!= MSG_ERROR
)
1892 old_level
= wpa_debug_level
;
1893 old_timestamp
= wpa_debug_timestamp
;
1894 old_show_keys
= wpa_debug_show_keys
;
1896 wpa_debug_level
= debug_level
;
1897 wpa_debug_timestamp
= debug_timestamp
? 1 : 0;
1898 wpa_debug_show_keys
= debug_show_keys
? 1 : 0;
1900 if (wpa_debug_level
!= old_level
)
1901 wpas_notify_debug_level_changed(global
);
1902 if (wpa_debug_timestamp
!= old_timestamp
)
1903 wpas_notify_debug_timestamp_changed(global
);
1904 if (wpa_debug_show_keys
!= old_show_keys
)
1905 wpas_notify_debug_show_keys_changed(global
);
1912 * wpa_supplicant_get_ssid - Get a pointer to the current network structure
1913 * @wpa_s: Pointer to wpa_supplicant data
1914 * Returns: A pointer to the current network structure or %NULL on failure
1916 struct wpa_ssid
* wpa_supplicant_get_ssid(struct wpa_supplicant
*wpa_s
)
1918 struct wpa_ssid
*entry
;
1919 u8 ssid
[MAX_SSID_LEN
];
1925 res
= wpa_drv_get_ssid(wpa_s
, ssid
);
1927 wpa_msg(wpa_s
, MSG_WARNING
, "Could not read SSID from "
1933 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0) {
1934 wpa_msg(wpa_s
, MSG_WARNING
, "Could not read BSSID from "
1939 wired
= wpa_s
->conf
->ap_scan
== 0 &&
1940 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
);
1942 entry
= wpa_s
->conf
->ssid
;
1944 if (!wpas_network_disabled(wpa_s
, entry
) &&
1945 ((ssid_len
== entry
->ssid_len
&&
1946 os_memcmp(ssid
, entry
->ssid
, ssid_len
) == 0) || wired
) &&
1947 (!entry
->bssid_set
||
1948 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0))
1951 if (!wpas_network_disabled(wpa_s
, entry
) &&
1952 (entry
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
1953 (entry
->ssid
== NULL
|| entry
->ssid_len
== 0) &&
1954 (!entry
->bssid_set
||
1955 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0))
1957 #endif /* CONFIG_WPS */
1959 if (!wpas_network_disabled(wpa_s
, entry
) && entry
->bssid_set
&&
1960 entry
->ssid_len
== 0 &&
1961 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0)
1964 entry
= entry
->next
;
1971 static int select_driver(struct wpa_supplicant
*wpa_s
, int i
)
1973 struct wpa_global
*global
= wpa_s
->global
;
1975 if (wpa_drivers
[i
]->global_init
&& global
->drv_priv
[i
] == NULL
) {
1976 global
->drv_priv
[i
] = wpa_drivers
[i
]->global_init();
1977 if (global
->drv_priv
[i
] == NULL
) {
1978 wpa_printf(MSG_ERROR
, "Failed to initialize driver "
1979 "'%s'", wpa_drivers
[i
]->name
);
1984 wpa_s
->driver
= wpa_drivers
[i
];
1985 wpa_s
->global_drv_priv
= global
->drv_priv
[i
];
1991 static int wpa_supplicant_set_driver(struct wpa_supplicant
*wpa_s
,
1996 const char *pos
, *driver
= name
;
2001 if (wpa_drivers
[0] == NULL
) {
2002 wpa_msg(wpa_s
, MSG_ERROR
, "No driver interfaces build into "
2008 /* default to first driver in the list */
2009 return select_driver(wpa_s
, 0);
2013 pos
= os_strchr(driver
, ',');
2017 len
= os_strlen(driver
);
2019 for (i
= 0; wpa_drivers
[i
]; i
++) {
2020 if (os_strlen(wpa_drivers
[i
]->name
) == len
&&
2021 os_strncmp(driver
, wpa_drivers
[i
]->name
, len
) ==
2023 /* First driver that succeeds wins */
2024 if (select_driver(wpa_s
, i
) == 0)
2032 wpa_msg(wpa_s
, MSG_ERROR
, "Unsupported driver '%s'", name
);
2038 * wpa_supplicant_rx_eapol - Deliver a received EAPOL frame to wpa_supplicant
2039 * @ctx: Context pointer (wpa_s); this is the ctx variable registered
2040 * with struct wpa_driver_ops::init()
2041 * @src_addr: Source address of the EAPOL frame
2042 * @buf: EAPOL data starting from the EAPOL header (i.e., no Ethernet header)
2043 * @len: Length of the EAPOL data
2045 * This function is called for each received EAPOL frame. Most driver
2046 * interfaces rely on more generic OS mechanism for receiving frames through
2047 * l2_packet, but if such a mechanism is not available, the driver wrapper may
2048 * take care of received EAPOL frames and deliver them to the core supplicant
2049 * code by calling this function.
2051 void wpa_supplicant_rx_eapol(void *ctx
, const u8
*src_addr
,
2052 const u8
*buf
, size_t len
)
2054 struct wpa_supplicant
*wpa_s
= ctx
;
2056 wpa_dbg(wpa_s
, MSG_DEBUG
, "RX EAPOL from " MACSTR
, MAC2STR(src_addr
));
2057 wpa_hexdump(MSG_MSGDUMP
, "RX EAPOL", buf
, len
);
2059 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
) {
2061 * There is possible race condition between receiving the
2062 * association event and the EAPOL frame since they are coming
2063 * through different paths from the driver. In order to avoid
2064 * issues in trying to process the EAPOL frame before receiving
2065 * association information, lets queue it for processing until
2066 * the association event is received.
2068 wpa_dbg(wpa_s
, MSG_DEBUG
, "Not associated - Delay processing "
2069 "of received EAPOL frame");
2070 wpabuf_free(wpa_s
->pending_eapol_rx
);
2071 wpa_s
->pending_eapol_rx
= wpabuf_alloc_copy(buf
, len
);
2072 if (wpa_s
->pending_eapol_rx
) {
2073 os_get_time(&wpa_s
->pending_eapol_rx_time
);
2074 os_memcpy(wpa_s
->pending_eapol_rx_src
, src_addr
,
2081 if (wpa_s
->ap_iface
) {
2082 wpa_supplicant_ap_rx_eapol(wpa_s
, src_addr
, buf
, len
);
2085 #endif /* CONFIG_AP */
2087 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
) {
2088 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignored received EAPOL frame since "
2089 "no key management is configured");
2093 if (wpa_s
->eapol_received
== 0 &&
2094 (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) ||
2095 !wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
2096 wpa_s
->wpa_state
!= WPA_COMPLETED
) &&
2097 (wpa_s
->current_ssid
== NULL
||
2098 wpa_s
->current_ssid
->mode
!= IEEE80211_MODE_IBSS
)) {
2099 /* Timeout for completing IEEE 802.1X and WPA authentication */
2100 wpa_supplicant_req_auth_timeout(
2102 (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
2103 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
||
2104 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
) ?
2107 wpa_s
->eapol_received
++;
2109 if (wpa_s
->countermeasures
) {
2110 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Countermeasures - dropped "
2115 #ifdef CONFIG_IBSS_RSN
2116 if (wpa_s
->current_ssid
&&
2117 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
) {
2118 ibss_rsn_rx_eapol(wpa_s
->ibss_rsn
, src_addr
, buf
, len
);
2121 #endif /* CONFIG_IBSS_RSN */
2123 /* Source address of the incoming EAPOL frame could be compared to the
2124 * current BSSID. However, it is possible that a centralized
2125 * Authenticator could be using another MAC address than the BSSID of
2126 * an AP, so just allow any address to be used for now. The replies are
2127 * still sent to the current BSSID (if available), though. */
2129 os_memcpy(wpa_s
->last_eapol_src
, src_addr
, ETH_ALEN
);
2130 if (!wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) &&
2131 eapol_sm_rx_eapol(wpa_s
->eapol
, src_addr
, buf
, len
) > 0)
2133 wpa_drv_poll(wpa_s
);
2134 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
))
2135 wpa_sm_rx_eapol(wpa_s
->wpa
, src_addr
, buf
, len
);
2136 else if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2138 * Set portValid = TRUE here since we are going to skip 4-way
2139 * handshake processing which would normally set portValid. We
2140 * need this to allow the EAPOL state machines to be completed
2141 * without going through EAPOL-Key handshake.
2143 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2148 int wpa_supplicant_update_mac_addr(struct wpa_supplicant
*wpa_s
)
2150 if (wpa_s
->driver
->send_eapol
) {
2151 const u8
*addr
= wpa_drv_get_mac_addr(wpa_s
);
2153 os_memcpy(wpa_s
->own_addr
, addr
, ETH_ALEN
);
2154 } else if (!(wpa_s
->drv_flags
&
2155 WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE
)) {
2156 l2_packet_deinit(wpa_s
->l2
);
2157 wpa_s
->l2
= l2_packet_init(wpa_s
->ifname
,
2158 wpa_drv_get_mac_addr(wpa_s
),
2160 wpa_supplicant_rx_eapol
, wpa_s
, 0);
2161 if (wpa_s
->l2
== NULL
)
2164 const u8
*addr
= wpa_drv_get_mac_addr(wpa_s
);
2166 os_memcpy(wpa_s
->own_addr
, addr
, ETH_ALEN
);
2169 if (wpa_s
->l2
&& l2_packet_get_own_addr(wpa_s
->l2
, wpa_s
->own_addr
)) {
2170 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to get own L2 address");
2174 wpa_dbg(wpa_s
, MSG_DEBUG
, "Own MAC address: " MACSTR
,
2175 MAC2STR(wpa_s
->own_addr
));
2176 wpa_sm_set_own_addr(wpa_s
->wpa
, wpa_s
->own_addr
);
2182 static void wpa_supplicant_rx_eapol_bridge(void *ctx
, const u8
*src_addr
,
2183 const u8
*buf
, size_t len
)
2185 struct wpa_supplicant
*wpa_s
= ctx
;
2186 const struct l2_ethhdr
*eth
;
2188 if (len
< sizeof(*eth
))
2190 eth
= (const struct l2_ethhdr
*) buf
;
2192 if (os_memcmp(eth
->h_dest
, wpa_s
->own_addr
, ETH_ALEN
) != 0 &&
2193 !(eth
->h_dest
[0] & 0x01)) {
2194 wpa_dbg(wpa_s
, MSG_DEBUG
, "RX EAPOL from " MACSTR
" to " MACSTR
2195 " (bridge - not for this interface - ignore)",
2196 MAC2STR(src_addr
), MAC2STR(eth
->h_dest
));
2200 wpa_dbg(wpa_s
, MSG_DEBUG
, "RX EAPOL from " MACSTR
" to " MACSTR
2201 " (bridge)", MAC2STR(src_addr
), MAC2STR(eth
->h_dest
));
2202 wpa_supplicant_rx_eapol(wpa_s
, src_addr
, buf
+ sizeof(*eth
),
2203 len
- sizeof(*eth
));
2208 * wpa_supplicant_driver_init - Initialize driver interface parameters
2209 * @wpa_s: Pointer to wpa_supplicant data
2210 * Returns: 0 on success, -1 on failure
2212 * This function is called to initialize driver interface parameters.
2213 * wpa_drv_init() must have been called before this function to initialize the
2216 int wpa_supplicant_driver_init(struct wpa_supplicant
*wpa_s
)
2218 static int interface_count
= 0;
2220 if (wpa_supplicant_update_mac_addr(wpa_s
) < 0)
2223 if (wpa_s
->bridge_ifname
[0]) {
2224 wpa_dbg(wpa_s
, MSG_DEBUG
, "Receiving packets from bridge "
2225 "interface '%s'", wpa_s
->bridge_ifname
);
2226 wpa_s
->l2_br
= l2_packet_init(wpa_s
->bridge_ifname
,
2229 wpa_supplicant_rx_eapol_bridge
,
2231 if (wpa_s
->l2_br
== NULL
) {
2232 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to open l2_packet "
2233 "connection for the bridge interface '%s'",
2234 wpa_s
->bridge_ifname
);
2239 wpa_clear_keys(wpa_s
, NULL
);
2241 /* Make sure that TKIP countermeasures are not left enabled (could
2242 * happen if wpa_supplicant is killed during countermeasures. */
2243 wpa_drv_set_countermeasures(wpa_s
, 0);
2245 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: flushing PMKID list in the driver");
2246 wpa_drv_flush_pmkid(wpa_s
);
2248 wpa_s
->prev_scan_ssid
= WILDCARD_SSID_SCAN
;
2249 wpa_s
->prev_scan_wildcard
= 0;
2251 if (wpa_supplicant_enabled_networks(wpa_s
)) {
2252 if (wpa_supplicant_delayed_sched_scan(wpa_s
, interface_count
,
2254 wpa_supplicant_req_scan(wpa_s
, interface_count
,
2258 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
2264 static int wpa_supplicant_daemon(const char *pid_file
)
2266 wpa_printf(MSG_DEBUG
, "Daemonize..");
2267 return os_daemonize(pid_file
);
2271 static struct wpa_supplicant
* wpa_supplicant_alloc(void)
2273 struct wpa_supplicant
*wpa_s
;
2275 wpa_s
= os_zalloc(sizeof(*wpa_s
));
2278 wpa_s
->scan_req
= 1;
2279 wpa_s
->scan_interval
= 5;
2280 wpa_s
->new_connection
= 1;
2281 wpa_s
->parent
= wpa_s
;
2282 wpa_s
->sched_scanning
= 0;
2288 #ifdef CONFIG_HT_OVERRIDES
2290 static int wpa_set_htcap_mcs(struct wpa_supplicant
*wpa_s
,
2291 struct ieee80211_ht_capabilities
*htcaps
,
2292 struct ieee80211_ht_capabilities
*htcaps_mask
,
2295 /* parse ht_mcs into hex array */
2297 const char *tmp
= ht_mcs
;
2300 /* If ht_mcs is null, do not set anything */
2304 /* This is what we are setting in the kernel */
2305 os_memset(&htcaps
->supported_mcs_set
, 0, IEEE80211_HT_MCS_MASK_LEN
);
2307 wpa_msg(wpa_s
, MSG_DEBUG
, "set_htcap, ht_mcs -:%s:-", ht_mcs
);
2309 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++) {
2311 long v
= strtol(tmp
, &end
, 16);
2313 wpa_msg(wpa_s
, MSG_DEBUG
,
2314 "htcap value[%i]: %ld end: %p tmp: %p",
2319 htcaps
->supported_mcs_set
[i
] = v
;
2322 wpa_msg(wpa_s
, MSG_ERROR
,
2323 "Failed to parse ht-mcs: %s, error: %s\n",
2324 ht_mcs
, strerror(errno
));
2330 * If we were able to parse any values, then set mask for the MCS set.
2333 os_memset(&htcaps_mask
->supported_mcs_set
, 0xff,
2334 IEEE80211_HT_MCS_MASK_LEN
- 1);
2335 /* skip the 3 reserved bits */
2336 htcaps_mask
->supported_mcs_set
[IEEE80211_HT_MCS_MASK_LEN
- 1] =
2344 static int wpa_disable_max_amsdu(struct wpa_supplicant
*wpa_s
,
2345 struct ieee80211_ht_capabilities
*htcaps
,
2346 struct ieee80211_ht_capabilities
*htcaps_mask
,
2351 wpa_msg(wpa_s
, MSG_DEBUG
, "set_disable_max_amsdu: %d", disabled
);
2356 msk
= host_to_le16(HT_CAP_INFO_MAX_AMSDU_SIZE
);
2357 htcaps_mask
->ht_capabilities_info
|= msk
;
2359 htcaps
->ht_capabilities_info
&= msk
;
2361 htcaps
->ht_capabilities_info
|= msk
;
2367 static int wpa_set_ampdu_factor(struct wpa_supplicant
*wpa_s
,
2368 struct ieee80211_ht_capabilities
*htcaps
,
2369 struct ieee80211_ht_capabilities
*htcaps_mask
,
2372 wpa_msg(wpa_s
, MSG_DEBUG
, "set_ampdu_factor: %d", factor
);
2377 if (factor
< 0 || factor
> 3) {
2378 wpa_msg(wpa_s
, MSG_ERROR
, "ampdu_factor: %d out of range. "
2379 "Must be 0-3 or -1", factor
);
2383 htcaps_mask
->a_mpdu_params
|= 0x3; /* 2 bits for factor */
2384 htcaps
->a_mpdu_params
&= ~0x3;
2385 htcaps
->a_mpdu_params
|= factor
& 0x3;
2391 static int wpa_set_ampdu_density(struct wpa_supplicant
*wpa_s
,
2392 struct ieee80211_ht_capabilities
*htcaps
,
2393 struct ieee80211_ht_capabilities
*htcaps_mask
,
2396 wpa_msg(wpa_s
, MSG_DEBUG
, "set_ampdu_density: %d", density
);
2401 if (density
< 0 || density
> 7) {
2402 wpa_msg(wpa_s
, MSG_ERROR
,
2403 "ampdu_density: %d out of range. Must be 0-7 or -1.",
2408 htcaps_mask
->a_mpdu_params
|= 0x1C;
2409 htcaps
->a_mpdu_params
&= ~(0x1C);
2410 htcaps
->a_mpdu_params
|= (density
<< 2) & 0x1C;
2416 static int wpa_set_disable_ht40(struct wpa_supplicant
*wpa_s
,
2417 struct ieee80211_ht_capabilities
*htcaps
,
2418 struct ieee80211_ht_capabilities
*htcaps_mask
,
2421 /* Masking these out disables HT40 */
2422 u16 msk
= host_to_le16(HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
|
2423 HT_CAP_INFO_SHORT_GI40MHZ
);
2425 wpa_msg(wpa_s
, MSG_DEBUG
, "set_disable_ht40: %d", disabled
);
2428 htcaps
->ht_capabilities_info
&= ~msk
;
2430 htcaps
->ht_capabilities_info
|= msk
;
2432 htcaps_mask
->ht_capabilities_info
|= msk
;
2438 void wpa_supplicant_apply_ht_overrides(
2439 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
2440 struct wpa_driver_associate_params
*params
)
2442 struct ieee80211_ht_capabilities
*htcaps
;
2443 struct ieee80211_ht_capabilities
*htcaps_mask
;
2448 params
->disable_ht
= ssid
->disable_ht
;
2449 if (!params
->htcaps
|| !params
->htcaps_mask
)
2452 htcaps
= (struct ieee80211_ht_capabilities
*) params
->htcaps
;
2453 htcaps_mask
= (struct ieee80211_ht_capabilities
*) params
->htcaps_mask
;
2454 wpa_set_htcap_mcs(wpa_s
, htcaps
, htcaps_mask
, ssid
->ht_mcs
);
2455 wpa_disable_max_amsdu(wpa_s
, htcaps
, htcaps_mask
,
2456 ssid
->disable_max_amsdu
);
2457 wpa_set_ampdu_factor(wpa_s
, htcaps
, htcaps_mask
, ssid
->ampdu_factor
);
2458 wpa_set_ampdu_density(wpa_s
, htcaps
, htcaps_mask
, ssid
->ampdu_density
);
2459 wpa_set_disable_ht40(wpa_s
, htcaps
, htcaps_mask
, ssid
->disable_ht40
);
2462 #endif /* CONFIG_HT_OVERRIDES */
2465 static int pcsc_reader_init(struct wpa_supplicant
*wpa_s
)
2470 if (!wpa_s
->conf
->pcsc_reader
)
2473 wpa_s
->scard
= scard_init(SCARD_TRY_BOTH
, wpa_s
->conf
->pcsc_reader
);
2477 if (wpa_s
->conf
->pcsc_pin
&&
2478 scard_set_pin(wpa_s
->scard
, wpa_s
->conf
->pcsc_pin
) < 0) {
2479 scard_deinit(wpa_s
->scard
);
2480 wpa_s
->scard
= NULL
;
2481 wpa_msg(wpa_s
, MSG_ERROR
, "PC/SC PIN validation failed");
2485 len
= sizeof(wpa_s
->imsi
) - 1;
2486 if (scard_get_imsi(wpa_s
->scard
, wpa_s
->imsi
, &len
)) {
2487 scard_deinit(wpa_s
->scard
);
2488 wpa_s
->scard
= NULL
;
2489 wpa_msg(wpa_s
, MSG_ERROR
, "Could not read IMSI");
2492 wpa_s
->imsi
[len
] = '\0';
2494 wpa_s
->mnc_len
= scard_get_mnc_len(wpa_s
->scard
);
2496 wpa_printf(MSG_DEBUG
, "SCARD: IMSI %s (MNC length %d)",
2497 wpa_s
->imsi
, wpa_s
->mnc_len
);
2499 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
2500 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
2501 #endif /* PCSC_FUNCS */
2507 int wpas_init_ext_pw(struct wpa_supplicant
*wpa_s
)
2511 ext_password_deinit(wpa_s
->ext_pw
);
2512 wpa_s
->ext_pw
= NULL
;
2513 eapol_sm_set_ext_pw_ctx(wpa_s
->eapol
, NULL
);
2515 if (!wpa_s
->conf
->ext_password_backend
)
2518 val
= os_strdup(wpa_s
->conf
->ext_password_backend
);
2521 pos
= os_strchr(val
, ':');
2525 wpa_printf(MSG_DEBUG
, "EXT PW: Initialize backend '%s'", val
);
2527 wpa_s
->ext_pw
= ext_password_init(val
, pos
);
2529 if (wpa_s
->ext_pw
== NULL
) {
2530 wpa_printf(MSG_DEBUG
, "EXT PW: Failed to initialize backend");
2533 eapol_sm_set_ext_pw_ctx(wpa_s
->eapol
, wpa_s
->ext_pw
);
2539 static int wpa_supplicant_init_iface(struct wpa_supplicant
*wpa_s
,
2540 struct wpa_interface
*iface
)
2542 const char *ifname
, *driver
;
2543 struct wpa_driver_capa capa
;
2545 wpa_printf(MSG_DEBUG
, "Initializing interface '%s' conf '%s' driver "
2546 "'%s' ctrl_interface '%s' bridge '%s'", iface
->ifname
,
2547 iface
->confname
? iface
->confname
: "N/A",
2548 iface
->driver
? iface
->driver
: "default",
2549 iface
->ctrl_interface
? iface
->ctrl_interface
: "N/A",
2550 iface
->bridge_ifname
? iface
->bridge_ifname
: "N/A");
2552 if (iface
->confname
) {
2553 #ifdef CONFIG_BACKEND_FILE
2554 wpa_s
->confname
= os_rel2abs_path(iface
->confname
);
2555 if (wpa_s
->confname
== NULL
) {
2556 wpa_printf(MSG_ERROR
, "Failed to get absolute path "
2557 "for configuration file '%s'.",
2561 wpa_printf(MSG_DEBUG
, "Configuration file '%s' -> '%s'",
2562 iface
->confname
, wpa_s
->confname
);
2563 #else /* CONFIG_BACKEND_FILE */
2564 wpa_s
->confname
= os_strdup(iface
->confname
);
2565 #endif /* CONFIG_BACKEND_FILE */
2566 wpa_s
->conf
= wpa_config_read(wpa_s
->confname
);
2567 if (wpa_s
->conf
== NULL
) {
2568 wpa_printf(MSG_ERROR
, "Failed to read or parse "
2569 "configuration '%s'.", wpa_s
->confname
);
2574 * Override ctrl_interface and driver_param if set on command
2577 if (iface
->ctrl_interface
) {
2578 os_free(wpa_s
->conf
->ctrl_interface
);
2579 wpa_s
->conf
->ctrl_interface
=
2580 os_strdup(iface
->ctrl_interface
);
2583 if (iface
->driver_param
) {
2584 os_free(wpa_s
->conf
->driver_param
);
2585 wpa_s
->conf
->driver_param
=
2586 os_strdup(iface
->driver_param
);
2589 wpa_s
->conf
= wpa_config_alloc_empty(iface
->ctrl_interface
,
2590 iface
->driver_param
);
2592 if (wpa_s
->conf
== NULL
) {
2593 wpa_printf(MSG_ERROR
, "\nNo configuration found.");
2597 if (iface
->ifname
== NULL
) {
2598 wpa_printf(MSG_ERROR
, "\nInterface name is required.");
2601 if (os_strlen(iface
->ifname
) >= sizeof(wpa_s
->ifname
)) {
2602 wpa_printf(MSG_ERROR
, "\nToo long interface name '%s'.",
2606 os_strlcpy(wpa_s
->ifname
, iface
->ifname
, sizeof(wpa_s
->ifname
));
2608 if (iface
->bridge_ifname
) {
2609 if (os_strlen(iface
->bridge_ifname
) >=
2610 sizeof(wpa_s
->bridge_ifname
)) {
2611 wpa_printf(MSG_ERROR
, "\nToo long bridge interface "
2612 "name '%s'.", iface
->bridge_ifname
);
2615 os_strlcpy(wpa_s
->bridge_ifname
, iface
->bridge_ifname
,
2616 sizeof(wpa_s
->bridge_ifname
));
2619 /* RSNA Supplicant Key Management - INITIALIZE */
2620 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
2621 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
2623 /* Initialize driver interface and register driver event handler before
2624 * L2 receive handler so that association events are processed before
2625 * EAPOL-Key packets if both become available for the same select()
2627 driver
= iface
->driver
;
2629 if (wpa_supplicant_set_driver(wpa_s
, driver
) < 0)
2632 wpa_s
->drv_priv
= wpa_drv_init(wpa_s
, wpa_s
->ifname
);
2633 if (wpa_s
->drv_priv
== NULL
) {
2635 pos
= driver
? os_strchr(driver
, ',') : NULL
;
2637 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to initialize "
2638 "driver interface - try next driver wrapper");
2642 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to initialize driver "
2646 if (wpa_drv_set_param(wpa_s
, wpa_s
->conf
->driver_param
) < 0) {
2647 wpa_msg(wpa_s
, MSG_ERROR
, "Driver interface rejected "
2648 "driver_param '%s'", wpa_s
->conf
->driver_param
);
2652 ifname
= wpa_drv_get_ifname(wpa_s
);
2653 if (ifname
&& os_strcmp(ifname
, wpa_s
->ifname
) != 0) {
2654 wpa_dbg(wpa_s
, MSG_DEBUG
, "Driver interface replaced "
2655 "interface name with '%s'", ifname
);
2656 os_strlcpy(wpa_s
->ifname
, ifname
, sizeof(wpa_s
->ifname
));
2659 if (wpa_supplicant_init_wpa(wpa_s
) < 0)
2662 wpa_sm_set_ifname(wpa_s
->wpa
, wpa_s
->ifname
,
2663 wpa_s
->bridge_ifname
[0] ? wpa_s
->bridge_ifname
:
2665 wpa_sm_set_fast_reauth(wpa_s
->wpa
, wpa_s
->conf
->fast_reauth
);
2667 if (wpa_s
->conf
->dot11RSNAConfigPMKLifetime
&&
2668 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
2669 wpa_s
->conf
->dot11RSNAConfigPMKLifetime
)) {
2670 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid WPA parameter value for "
2671 "dot11RSNAConfigPMKLifetime");
2675 if (wpa_s
->conf
->dot11RSNAConfigPMKReauthThreshold
&&
2676 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
2677 wpa_s
->conf
->dot11RSNAConfigPMKReauthThreshold
)) {
2678 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid WPA parameter value for "
2679 "dot11RSNAConfigPMKReauthThreshold");
2683 if (wpa_s
->conf
->dot11RSNAConfigSATimeout
&&
2684 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
,
2685 wpa_s
->conf
->dot11RSNAConfigSATimeout
)) {
2686 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid WPA parameter value for "
2687 "dot11RSNAConfigSATimeout");
2691 wpa_s
->hw
.modes
= wpa_drv_get_hw_feature_data(wpa_s
,
2692 &wpa_s
->hw
.num_modes
,
2695 if (wpa_drv_get_capa(wpa_s
, &capa
) == 0) {
2696 wpa_s
->drv_capa_known
= 1;
2697 wpa_s
->drv_flags
= capa
.flags
;
2698 wpa_s
->drv_enc
= capa
.enc
;
2699 wpa_s
->probe_resp_offloads
= capa
.probe_resp_offloads
;
2700 wpa_s
->max_scan_ssids
= capa
.max_scan_ssids
;
2701 wpa_s
->max_sched_scan_ssids
= capa
.max_sched_scan_ssids
;
2702 wpa_s
->sched_scan_supported
= capa
.sched_scan_supported
;
2703 wpa_s
->max_match_sets
= capa
.max_match_sets
;
2704 wpa_s
->max_remain_on_chan
= capa
.max_remain_on_chan
;
2705 wpa_s
->max_stations
= capa
.max_stations
;
2707 if (wpa_s
->max_remain_on_chan
== 0)
2708 wpa_s
->max_remain_on_chan
= 1000;
2710 if (wpa_supplicant_driver_init(wpa_s
) < 0)
2714 if (wpa_tdls_init(wpa_s
->wpa
))
2716 #endif /* CONFIG_TDLS */
2718 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1] &&
2719 wpa_drv_set_country(wpa_s
, wpa_s
->conf
->country
)) {
2720 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to set country");
2724 if (wpas_wps_init(wpa_s
))
2727 if (wpa_supplicant_init_eapol(wpa_s
) < 0)
2729 wpa_sm_set_eapol(wpa_s
->wpa
, wpa_s
->eapol
);
2731 wpa_s
->ctrl_iface
= wpa_supplicant_ctrl_iface_init(wpa_s
);
2732 if (wpa_s
->ctrl_iface
== NULL
) {
2733 wpa_printf(MSG_ERROR
,
2734 "Failed to initialize control interface '%s'.\n"
2735 "You may have another wpa_supplicant process "
2736 "already running or the file was\n"
2737 "left by an unclean termination of wpa_supplicant "
2738 "in which case you will need\n"
2739 "to manually remove this file before starting "
2740 "wpa_supplicant again.\n",
2741 wpa_s
->conf
->ctrl_interface
);
2745 wpa_s
->gas
= gas_query_init(wpa_s
);
2746 if (wpa_s
->gas
== NULL
) {
2747 wpa_printf(MSG_ERROR
, "Failed to initialize GAS query");
2752 if (wpas_p2p_init(wpa_s
->global
, wpa_s
) < 0) {
2753 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to init P2P");
2756 #endif /* CONFIG_P2P */
2758 if (wpa_bss_init(wpa_s
) < 0)
2761 if (pcsc_reader_init(wpa_s
) < 0)
2764 if (wpas_init_ext_pw(wpa_s
) < 0)
2771 static void wpa_supplicant_deinit_iface(struct wpa_supplicant
*wpa_s
,
2772 int notify
, int terminate
)
2774 if (wpa_s
->drv_priv
) {
2775 wpa_supplicant_deauthenticate(wpa_s
,
2776 WLAN_REASON_DEAUTH_LEAVING
);
2778 wpa_drv_set_countermeasures(wpa_s
, 0);
2779 wpa_clear_keys(wpa_s
, NULL
);
2782 wpa_supplicant_cleanup(wpa_s
);
2785 if (wpa_s
== wpa_s
->global
->p2p_init_wpa_s
&& wpa_s
->global
->p2p
) {
2786 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Disable P2P since removing "
2787 "the management interface is being removed");
2788 wpas_p2p_deinit_global(wpa_s
->global
);
2790 #endif /* CONFIG_P2P */
2792 if (wpa_s
->drv_priv
)
2793 wpa_drv_deinit(wpa_s
);
2796 wpas_notify_iface_removed(wpa_s
);
2799 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_TERMINATING
);
2801 if (wpa_s
->ctrl_iface
) {
2802 wpa_supplicant_ctrl_iface_deinit(wpa_s
->ctrl_iface
);
2803 wpa_s
->ctrl_iface
= NULL
;
2806 if (wpa_s
->conf
!= NULL
) {
2807 wpa_config_free(wpa_s
->conf
);
2814 * wpa_supplicant_add_iface - Add a new network interface
2815 * @global: Pointer to global data from wpa_supplicant_init()
2816 * @iface: Interface configuration options
2817 * Returns: Pointer to the created interface or %NULL on failure
2819 * This function is used to add new network interfaces for %wpa_supplicant.
2820 * This can be called before wpa_supplicant_run() to add interfaces before the
2821 * main event loop has been started. In addition, new interfaces can be added
2822 * dynamically while %wpa_supplicant is already running. This could happen,
2823 * e.g., when a hotplug network adapter is inserted.
2825 struct wpa_supplicant
* wpa_supplicant_add_iface(struct wpa_global
*global
,
2826 struct wpa_interface
*iface
)
2828 struct wpa_supplicant
*wpa_s
;
2829 struct wpa_interface t_iface
;
2830 struct wpa_ssid
*ssid
;
2832 if (global
== NULL
|| iface
== NULL
)
2835 wpa_s
= wpa_supplicant_alloc();
2839 wpa_s
->global
= global
;
2842 if (global
->params
.override_driver
) {
2843 wpa_printf(MSG_DEBUG
, "Override interface parameter: driver "
2845 iface
->driver
, global
->params
.override_driver
);
2846 t_iface
.driver
= global
->params
.override_driver
;
2848 if (global
->params
.override_ctrl_interface
) {
2849 wpa_printf(MSG_DEBUG
, "Override interface parameter: "
2850 "ctrl_interface ('%s' -> '%s')",
2851 iface
->ctrl_interface
,
2852 global
->params
.override_ctrl_interface
);
2853 t_iface
.ctrl_interface
=
2854 global
->params
.override_ctrl_interface
;
2856 if (wpa_supplicant_init_iface(wpa_s
, &t_iface
)) {
2857 wpa_printf(MSG_DEBUG
, "Failed to add interface %s",
2859 wpa_supplicant_deinit_iface(wpa_s
, 0, 0);
2864 /* Notify the control interfaces about new iface */
2865 if (wpas_notify_iface_added(wpa_s
)) {
2866 wpa_supplicant_deinit_iface(wpa_s
, 1, 0);
2871 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
)
2872 wpas_notify_network_added(wpa_s
, ssid
);
2874 wpa_s
->next
= global
->ifaces
;
2875 global
->ifaces
= wpa_s
;
2877 wpa_dbg(wpa_s
, MSG_DEBUG
, "Added interface %s", wpa_s
->ifname
);
2878 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
2885 * wpa_supplicant_remove_iface - Remove a network interface
2886 * @global: Pointer to global data from wpa_supplicant_init()
2887 * @wpa_s: Pointer to the network interface to be removed
2888 * Returns: 0 if interface was removed, -1 if interface was not found
2890 * This function can be used to dynamically remove network interfaces from
2891 * %wpa_supplicant, e.g., when a hotplug network adapter is ejected. In
2892 * addition, this function is used to remove all remaining interfaces when
2893 * %wpa_supplicant is terminated.
2895 int wpa_supplicant_remove_iface(struct wpa_global
*global
,
2896 struct wpa_supplicant
*wpa_s
,
2899 struct wpa_supplicant
*prev
;
2901 /* Remove interface from the global list of interfaces */
2902 prev
= global
->ifaces
;
2903 if (prev
== wpa_s
) {
2904 global
->ifaces
= wpa_s
->next
;
2906 while (prev
&& prev
->next
!= wpa_s
)
2910 prev
->next
= wpa_s
->next
;
2913 wpa_dbg(wpa_s
, MSG_DEBUG
, "Removing interface %s", wpa_s
->ifname
);
2915 if (global
->p2p_group_formation
== wpa_s
)
2916 global
->p2p_group_formation
= NULL
;
2917 wpa_supplicant_deinit_iface(wpa_s
, 1, terminate
);
2925 * wpa_supplicant_get_eap_mode - Get the current EAP mode
2926 * @wpa_s: Pointer to the network interface
2927 * Returns: Pointer to the eap mode or the string "UNKNOWN" if not found
2929 const char * wpa_supplicant_get_eap_mode(struct wpa_supplicant
*wpa_s
)
2931 const char *eapol_method
;
2933 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) == 0 &&
2934 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
2938 eapol_method
= eapol_sm_get_method_name(wpa_s
->eapol
);
2939 if (eapol_method
== NULL
)
2940 return "UNKNOWN-EAP";
2942 return eapol_method
;
2947 * wpa_supplicant_get_iface - Get a new network interface
2948 * @global: Pointer to global data from wpa_supplicant_init()
2949 * @ifname: Interface name
2950 * Returns: Pointer to the interface or %NULL if not found
2952 struct wpa_supplicant
* wpa_supplicant_get_iface(struct wpa_global
*global
,
2955 struct wpa_supplicant
*wpa_s
;
2957 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2958 if (os_strcmp(wpa_s
->ifname
, ifname
) == 0)
2965 #ifndef CONFIG_NO_WPA_MSG
2966 static const char * wpa_supplicant_msg_ifname_cb(void *ctx
)
2968 struct wpa_supplicant
*wpa_s
= ctx
;
2971 return wpa_s
->ifname
;
2973 #endif /* CONFIG_NO_WPA_MSG */
2977 * wpa_supplicant_init - Initialize %wpa_supplicant
2978 * @params: Parameters for %wpa_supplicant
2979 * Returns: Pointer to global %wpa_supplicant data, or %NULL on failure
2981 * This function is used to initialize %wpa_supplicant. After successful
2982 * initialization, the returned data pointer can be used to add and remove
2983 * network interfaces, and eventually, to deinitialize %wpa_supplicant.
2985 struct wpa_global
* wpa_supplicant_init(struct wpa_params
*params
)
2987 struct wpa_global
*global
;
2993 #ifdef CONFIG_DRIVER_NDIS
2995 void driver_ndis_init_ops(void);
2996 driver_ndis_init_ops();
2998 #endif /* CONFIG_DRIVER_NDIS */
3000 #ifndef CONFIG_NO_WPA_MSG
3001 wpa_msg_register_ifname_cb(wpa_supplicant_msg_ifname_cb
);
3002 #endif /* CONFIG_NO_WPA_MSG */
3004 wpa_debug_open_file(params
->wpa_debug_file_path
);
3005 if (params
->wpa_debug_syslog
)
3006 wpa_debug_open_syslog();
3007 if (params
->wpa_debug_tracing
) {
3008 ret
= wpa_debug_open_linux_tracing();
3010 wpa_printf(MSG_ERROR
,
3011 "Failed to enable trace logging");
3016 ret
= eap_register_methods();
3018 wpa_printf(MSG_ERROR
, "Failed to register EAP methods");
3020 wpa_printf(MSG_ERROR
, "Two or more EAP methods used "
3021 "the same EAP type.");
3025 global
= os_zalloc(sizeof(*global
));
3028 dl_list_init(&global
->p2p_srv_bonjour
);
3029 dl_list_init(&global
->p2p_srv_upnp
);
3030 global
->params
.daemonize
= params
->daemonize
;
3031 global
->params
.wait_for_monitor
= params
->wait_for_monitor
;
3032 global
->params
.dbus_ctrl_interface
= params
->dbus_ctrl_interface
;
3033 if (params
->pid_file
)
3034 global
->params
.pid_file
= os_strdup(params
->pid_file
);
3035 if (params
->ctrl_interface
)
3036 global
->params
.ctrl_interface
=
3037 os_strdup(params
->ctrl_interface
);
3038 if (params
->override_driver
)
3039 global
->params
.override_driver
=
3040 os_strdup(params
->override_driver
);
3041 if (params
->override_ctrl_interface
)
3042 global
->params
.override_ctrl_interface
=
3043 os_strdup(params
->override_ctrl_interface
);
3044 wpa_debug_level
= global
->params
.wpa_debug_level
=
3045 params
->wpa_debug_level
;
3046 wpa_debug_show_keys
= global
->params
.wpa_debug_show_keys
=
3047 params
->wpa_debug_show_keys
;
3048 wpa_debug_timestamp
= global
->params
.wpa_debug_timestamp
=
3049 params
->wpa_debug_timestamp
;
3051 wpa_printf(MSG_DEBUG
, "wpa_supplicant v" VERSION_STR
);
3054 wpa_printf(MSG_ERROR
, "Failed to initialize event loop");
3055 wpa_supplicant_deinit(global
);
3059 random_init(params
->entropy_file
);
3061 global
->ctrl_iface
= wpa_supplicant_global_ctrl_iface_init(global
);
3062 if (global
->ctrl_iface
== NULL
) {
3063 wpa_supplicant_deinit(global
);
3067 if (wpas_notify_supplicant_initialized(global
)) {
3068 wpa_supplicant_deinit(global
);
3072 for (i
= 0; wpa_drivers
[i
]; i
++)
3073 global
->drv_count
++;
3074 if (global
->drv_count
== 0) {
3075 wpa_printf(MSG_ERROR
, "No drivers enabled");
3076 wpa_supplicant_deinit(global
);
3079 global
->drv_priv
= os_zalloc(global
->drv_count
* sizeof(void *));
3080 if (global
->drv_priv
== NULL
) {
3081 wpa_supplicant_deinit(global
);
3090 * wpa_supplicant_run - Run the %wpa_supplicant main event loop
3091 * @global: Pointer to global data from wpa_supplicant_init()
3092 * Returns: 0 after successful event loop run, -1 on failure
3094 * This function starts the main event loop and continues running as long as
3095 * there are any remaining events. In most cases, this function is running as
3096 * long as the %wpa_supplicant process in still in use.
3098 int wpa_supplicant_run(struct wpa_global
*global
)
3100 struct wpa_supplicant
*wpa_s
;
3102 if (global
->params
.daemonize
&&
3103 wpa_supplicant_daemon(global
->params
.pid_file
))
3106 if (global
->params
.wait_for_monitor
) {
3107 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
)
3108 if (wpa_s
->ctrl_iface
)
3109 wpa_supplicant_ctrl_iface_wait(
3113 eloop_register_signal_terminate(wpa_supplicant_terminate
, global
);
3114 eloop_register_signal_reconfig(wpa_supplicant_reconfig
, global
);
3123 * wpa_supplicant_deinit - Deinitialize %wpa_supplicant
3124 * @global: Pointer to global data from wpa_supplicant_init()
3126 * This function is called to deinitialize %wpa_supplicant and to free all
3127 * allocated resources. Remaining network interfaces will also be removed.
3129 void wpa_supplicant_deinit(struct wpa_global
*global
)
3137 wpas_p2p_deinit_global(global
);
3138 #endif /* CONFIG_P2P */
3140 while (global
->ifaces
)
3141 wpa_supplicant_remove_iface(global
, global
->ifaces
, 1);
3143 if (global
->ctrl_iface
)
3144 wpa_supplicant_global_ctrl_iface_deinit(global
->ctrl_iface
);
3146 wpas_notify_supplicant_deinitialized(global
);
3148 eap_peer_unregister_methods();
3150 eap_server_unregister_methods();
3151 #endif /* CONFIG_AP */
3153 for (i
= 0; wpa_drivers
[i
] && global
->drv_priv
; i
++) {
3154 if (!global
->drv_priv
[i
])
3156 wpa_drivers
[i
]->global_deinit(global
->drv_priv
[i
]);
3158 os_free(global
->drv_priv
);
3164 if (global
->params
.pid_file
) {
3165 os_daemonize_terminate(global
->params
.pid_file
);
3166 os_free(global
->params
.pid_file
);
3168 os_free(global
->params
.ctrl_interface
);
3169 os_free(global
->params
.override_driver
);
3170 os_free(global
->params
.override_ctrl_interface
);
3172 os_free(global
->p2p_disallow_freq
);
3175 wpa_debug_close_syslog();
3176 wpa_debug_close_file();
3177 wpa_debug_close_linux_tracing();
3181 void wpa_supplicant_update_config(struct wpa_supplicant
*wpa_s
)
3183 if ((wpa_s
->conf
->changed_parameters
& CFG_CHANGED_COUNTRY
) &&
3184 wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1]) {
3186 country
[0] = wpa_s
->conf
->country
[0];
3187 country
[1] = wpa_s
->conf
->country
[1];
3189 if (wpa_drv_set_country(wpa_s
, country
) < 0) {
3190 wpa_printf(MSG_ERROR
, "Failed to set country code "
3195 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_EXT_PW_BACKEND
)
3196 wpas_init_ext_pw(wpa_s
);
3199 wpas_wps_update_config(wpa_s
);
3200 #endif /* CONFIG_WPS */
3203 wpas_p2p_update_config(wpa_s
);
3204 #endif /* CONFIG_P2P */
3206 wpa_s
->conf
->changed_parameters
= 0;
3210 static void add_freq(int *freqs
, int *num_freqs
, int freq
)
3214 for (i
= 0; i
< *num_freqs
; i
++) {
3215 if (freqs
[i
] == freq
)
3219 freqs
[*num_freqs
] = freq
;
3224 static int * get_bss_freqs_in_ess(struct wpa_supplicant
*wpa_s
)
3226 struct wpa_bss
*bss
, *cbss
;
3227 const int max_freqs
= 10;
3231 freqs
= os_zalloc(sizeof(int) * (max_freqs
+ 1));
3235 cbss
= wpa_s
->current_bss
;
3237 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
3240 if (bss
->ssid_len
== cbss
->ssid_len
&&
3241 os_memcmp(bss
->ssid
, cbss
->ssid
, bss
->ssid_len
) == 0 &&
3242 wpa_blacklist_get(wpa_s
, bss
->bssid
) == NULL
) {
3243 add_freq(freqs
, &num_freqs
, bss
->freq
);
3244 if (num_freqs
== max_freqs
)
3249 if (num_freqs
== 0) {
3258 void wpas_connection_failed(struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
3265 * Remove possible authentication timeout since the connection failed.
3267 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
3270 * Add the failed BSSID into the blacklist and speed up next scan
3271 * attempt if there could be other APs that could accept association.
3272 * The current blacklist count indicates how many times we have tried
3273 * connecting to this AP and multiple attempts mean that other APs are
3274 * either not available or has already been tried, so that we can start
3275 * increasing the delay here to avoid constant scanning.
3277 count
= wpa_blacklist_add(wpa_s
, bssid
);
3278 if (count
== 1 && wpa_s
->current_bss
) {
3280 * This BSS was not in the blacklist before. If there is
3281 * another BSS available for the same ESS, we should try that
3282 * next. Otherwise, we may as well try this one once more
3283 * before allowing other, likely worse, ESSes to be considered.
3285 freqs
= get_bss_freqs_in_ess(wpa_s
);
3287 wpa_dbg(wpa_s
, MSG_DEBUG
, "Another BSS in this ESS "
3288 "has been seen; try it next");
3289 wpa_blacklist_add(wpa_s
, bssid
);
3291 * On the next scan, go through only the known channels
3292 * used in this ESS based on previous scans to speed up
3293 * common load balancing use case.
3295 os_free(wpa_s
->next_scan_freqs
);
3296 wpa_s
->next_scan_freqs
= freqs
;
3315 * TODO: if more than one possible AP is available in scan results,
3316 * could try the other ones before requesting a new scan.
3318 wpa_supplicant_req_scan(wpa_s
, timeout
/ 1000,
3319 1000 * (timeout
% 1000));
3323 int wpas_driver_bss_selection(struct wpa_supplicant
*wpa_s
)
3325 return wpa_s
->conf
->ap_scan
== 2 ||
3326 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_BSS_SELECTION
);
3330 #if defined(CONFIG_CTRL_IFACE) || defined(CONFIG_CTRL_IFACE_DBUS_NEW)
3331 int wpa_supplicant_ctrl_iface_ctrl_rsp_handle(struct wpa_supplicant
*wpa_s
,
3332 struct wpa_ssid
*ssid
,
3336 #ifdef IEEE8021X_EAPOL
3337 struct eap_peer_config
*eap
= &ssid
->eap
;
3339 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: response handle field=%s", field
);
3340 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: response value",
3341 (const u8
*) value
, os_strlen(value
));
3343 switch (wpa_supplicant_ctrl_req_from_string(field
)) {
3344 case WPA_CTRL_REQ_EAP_IDENTITY
:
3345 os_free(eap
->identity
);
3346 eap
->identity
= (u8
*) os_strdup(value
);
3347 eap
->identity_len
= os_strlen(value
);
3348 eap
->pending_req_identity
= 0;
3349 if (ssid
== wpa_s
->current_ssid
)
3350 wpa_s
->reassociate
= 1;
3352 case WPA_CTRL_REQ_EAP_PASSWORD
:
3353 os_free(eap
->password
);
3354 eap
->password
= (u8
*) os_strdup(value
);
3355 eap
->password_len
= os_strlen(value
);
3356 eap
->pending_req_password
= 0;
3357 if (ssid
== wpa_s
->current_ssid
)
3358 wpa_s
->reassociate
= 1;
3360 case WPA_CTRL_REQ_EAP_NEW_PASSWORD
:
3361 os_free(eap
->new_password
);
3362 eap
->new_password
= (u8
*) os_strdup(value
);
3363 eap
->new_password_len
= os_strlen(value
);
3364 eap
->pending_req_new_password
= 0;
3365 if (ssid
== wpa_s
->current_ssid
)
3366 wpa_s
->reassociate
= 1;
3368 case WPA_CTRL_REQ_EAP_PIN
:
3370 eap
->pin
= os_strdup(value
);
3371 eap
->pending_req_pin
= 0;
3372 if (ssid
== wpa_s
->current_ssid
)
3373 wpa_s
->reassociate
= 1;
3375 case WPA_CTRL_REQ_EAP_OTP
:
3377 eap
->otp
= (u8
*) os_strdup(value
);
3378 eap
->otp_len
= os_strlen(value
);
3379 os_free(eap
->pending_req_otp
);
3380 eap
->pending_req_otp
= NULL
;
3381 eap
->pending_req_otp_len
= 0;
3383 case WPA_CTRL_REQ_EAP_PASSPHRASE
:
3384 os_free(eap
->private_key_passwd
);
3385 eap
->private_key_passwd
= (u8
*) os_strdup(value
);
3386 eap
->pending_req_passphrase
= 0;
3387 if (ssid
== wpa_s
->current_ssid
)
3388 wpa_s
->reassociate
= 1;
3391 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown field '%s'", field
);
3396 #else /* IEEE8021X_EAPOL */
3397 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: IEEE 802.1X not included");
3399 #endif /* IEEE8021X_EAPOL */
3401 #endif /* CONFIG_CTRL_IFACE || CONFIG_CTRL_IFACE_DBUS_NEW */
3404 int wpas_network_disabled(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
)
3407 unsigned int drv_enc
;
3415 if (wpa_s
&& wpa_s
->drv_capa_known
)
3416 drv_enc
= wpa_s
->drv_enc
;
3418 drv_enc
= (unsigned int) -1;
3420 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
3421 size_t len
= ssid
->wep_key_len
[i
];
3424 if (len
== 5 && (drv_enc
& WPA_DRIVER_CAPA_ENC_WEP40
))
3426 if (len
== 13 && (drv_enc
& WPA_DRIVER_CAPA_ENC_WEP104
))
3428 if (len
== 16 && (drv_enc
& WPA_DRIVER_CAPA_ENC_WEP128
))
3430 return 1; /* invalid WEP key */
3433 if (wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) && !ssid
->psk_set
)
3440 int wpas_is_p2p_prioritized(struct wpa_supplicant
*wpa_s
)
3442 if (wpa_s
->global
->conc_pref
== WPA_CONC_PREF_P2P
)
3444 if (wpa_s
->global
->conc_pref
== WPA_CONC_PREF_STA
)