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 "l2_packet/l2_packet.h"
25 #include "wpa_supplicant_i.h"
27 #include "ctrl_iface.h"
28 #include "pcsc_funcs.h"
29 #include "common/version.h"
30 #include "rsn_supp/preauth.h"
31 #include "rsn_supp/pmksa_cache.h"
32 #include "common/wpa_ctrl.h"
33 #include "common/ieee802_11_defs.h"
35 #include "blacklist.h"
36 #include "wpas_glue.h"
37 #include "wps_supplicant.h"
40 #include "gas_query.h"
42 #include "p2p_supplicant.h"
47 #include "offchannel.h"
48 #include "hs20_supplicant.h"
50 const char *wpa_supplicant_version
=
51 "wpa_supplicant v" VERSION_STR
"\n"
52 "Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi> and contributors";
54 const char *wpa_supplicant_license
=
55 "This software may be distributed under the terms of the BSD license.\n"
56 "See README for more details.\n"
57 #ifdef EAP_TLS_OPENSSL
58 "\nThis product includes software developed by the OpenSSL Project\n"
59 "for use in the OpenSSL Toolkit (http://www.openssl.org/)\n"
60 #endif /* EAP_TLS_OPENSSL */
63 #ifndef CONFIG_NO_STDOUT_DEBUG
64 /* Long text divided into parts in order to fit in C89 strings size limits. */
65 const char *wpa_supplicant_full_license1
=
67 const char *wpa_supplicant_full_license2
=
68 "This software may be distributed under the terms of the BSD license.\n"
70 "Redistribution and use in source and binary forms, with or without\n"
71 "modification, are permitted provided that the following conditions are\n"
74 const char *wpa_supplicant_full_license3
=
75 "1. Redistributions of source code must retain the above copyright\n"
76 " notice, this list of conditions and the following disclaimer.\n"
78 "2. Redistributions in binary form must reproduce the above copyright\n"
79 " notice, this list of conditions and the following disclaimer in the\n"
80 " documentation and/or other materials provided with the distribution.\n"
82 const char *wpa_supplicant_full_license4
=
83 "3. Neither the name(s) of the above-listed copyright holder(s) nor the\n"
84 " names of its contributors may be used to endorse or promote products\n"
85 " derived from this software without specific prior written permission.\n"
87 "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n"
88 "\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n"
89 "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n"
90 "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n";
91 const char *wpa_supplicant_full_license5
=
92 "OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n"
93 "SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n"
94 "LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n"
95 "DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n"
96 "THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n"
97 "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n"
98 "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
100 #endif /* CONFIG_NO_STDOUT_DEBUG */
102 extern int wpa_debug_level
;
103 extern int wpa_debug_show_keys
;
104 extern int wpa_debug_timestamp
;
105 extern struct wpa_driver_ops
*wpa_drivers
[];
107 /* Configure default/group WEP keys for static WEP */
108 int wpa_set_wep_keys(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
)
112 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
113 if (ssid
->wep_key_len
[i
] == 0)
117 wpa_drv_set_key(wpa_s
, WPA_ALG_WEP
, NULL
,
118 i
, i
== ssid
->wep_tx_keyidx
, NULL
, 0,
119 ssid
->wep_key
[i
], ssid
->wep_key_len
[i
]);
126 static int wpa_supplicant_set_wpa_none_key(struct wpa_supplicant
*wpa_s
,
127 struct wpa_ssid
*ssid
)
134 /* IBSS/WPA-None uses only one key (Group) for both receiving and
135 * sending unicast and multicast packets. */
137 if (ssid
->mode
!= WPAS_MODE_IBSS
) {
138 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Invalid mode %d (not "
139 "IBSS/ad-hoc) for WPA-None", ssid
->mode
);
143 if (!ssid
->psk_set
) {
144 wpa_msg(wpa_s
, MSG_INFO
, "WPA: No PSK configured for "
149 switch (wpa_s
->group_cipher
) {
150 case WPA_CIPHER_CCMP
:
151 os_memcpy(key
, ssid
->psk
, 16);
155 case WPA_CIPHER_TKIP
:
156 /* WPA-None uses the same Michael MIC key for both TX and RX */
157 os_memcpy(key
, ssid
->psk
, 16 + 8);
158 os_memcpy(key
+ 16 + 8, ssid
->psk
+ 16, 8);
163 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Invalid group cipher %d for "
164 "WPA-None", wpa_s
->group_cipher
);
168 /* TODO: should actually remember the previously used seq#, both for TX
169 * and RX from each STA.. */
171 return wpa_drv_set_key(wpa_s
, alg
, NULL
, 0, 1, seq
, 6, key
, keylen
);
175 static void wpa_supplicant_timeout(void *eloop_ctx
, void *timeout_ctx
)
177 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
178 const u8
*bssid
= wpa_s
->bssid
;
179 if (is_zero_ether_addr(bssid
))
180 bssid
= wpa_s
->pending_bssid
;
181 wpa_msg(wpa_s
, MSG_INFO
, "Authentication with " MACSTR
" timed out.",
183 wpa_blacklist_add(wpa_s
, bssid
);
184 wpa_sm_notify_disassoc(wpa_s
->wpa
);
185 wpa_supplicant_disassociate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
186 wpa_s
->reassociate
= 1;
189 * If we timed out, the AP or the local radio may be busy.
190 * So, wait a second until scanning again.
192 wpa_supplicant_req_scan(wpa_s
, 1, 0);
197 * wpa_supplicant_req_auth_timeout - Schedule a timeout for authentication
198 * @wpa_s: Pointer to wpa_supplicant data
199 * @sec: Number of seconds after which to time out authentication
200 * @usec: Number of microseconds after which to time out authentication
202 * This function is used to schedule a timeout for the current authentication
205 void wpa_supplicant_req_auth_timeout(struct wpa_supplicant
*wpa_s
,
208 if (wpa_s
->conf
&& wpa_s
->conf
->ap_scan
== 0 &&
209 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
))
212 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setting authentication timeout: %d sec "
213 "%d usec", sec
, usec
);
214 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
215 eloop_register_timeout(sec
, usec
, wpa_supplicant_timeout
, wpa_s
, NULL
);
220 * wpa_supplicant_cancel_auth_timeout - Cancel authentication timeout
221 * @wpa_s: Pointer to wpa_supplicant data
223 * This function is used to cancel authentication timeout scheduled with
224 * wpa_supplicant_req_auth_timeout() and it is called when authentication has
227 void wpa_supplicant_cancel_auth_timeout(struct wpa_supplicant
*wpa_s
)
229 wpa_dbg(wpa_s
, MSG_DEBUG
, "Cancelling authentication timeout");
230 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
231 wpa_blacklist_del(wpa_s
, wpa_s
->bssid
);
236 * wpa_supplicant_initiate_eapol - Configure EAPOL state machine
237 * @wpa_s: Pointer to wpa_supplicant data
239 * This function is used to configure EAPOL state machine based on the selected
240 * authentication mode.
242 void wpa_supplicant_initiate_eapol(struct wpa_supplicant
*wpa_s
)
244 #ifdef IEEE8021X_EAPOL
245 struct eapol_config eapol_conf
;
246 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
248 #ifdef CONFIG_IBSS_RSN
249 if (ssid
->mode
== WPAS_MODE_IBSS
&&
250 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
251 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
) {
253 * RSN IBSS authentication is per-STA and we can disable the
254 * per-BSSID EAPOL authentication.
256 eapol_sm_notify_portControl(wpa_s
->eapol
, ForceAuthorized
);
257 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
258 eapol_sm_notify_eap_fail(wpa_s
->eapol
, FALSE
);
261 #endif /* CONFIG_IBSS_RSN */
263 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
264 eapol_sm_notify_eap_fail(wpa_s
->eapol
, FALSE
);
266 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
267 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
268 eapol_sm_notify_portControl(wpa_s
->eapol
, ForceAuthorized
);
270 eapol_sm_notify_portControl(wpa_s
->eapol
, Auto
);
272 os_memset(&eapol_conf
, 0, sizeof(eapol_conf
));
273 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
274 eapol_conf
.accept_802_1x_keys
= 1;
275 eapol_conf
.required_keys
= 0;
276 if (ssid
->eapol_flags
& EAPOL_FLAG_REQUIRE_KEY_UNICAST
) {
277 eapol_conf
.required_keys
|= EAPOL_REQUIRE_KEY_UNICAST
;
279 if (ssid
->eapol_flags
& EAPOL_FLAG_REQUIRE_KEY_BROADCAST
) {
280 eapol_conf
.required_keys
|=
281 EAPOL_REQUIRE_KEY_BROADCAST
;
284 if (wpa_s
->conf
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
))
285 eapol_conf
.required_keys
= 0;
288 eapol_conf
.fast_reauth
= wpa_s
->conf
->fast_reauth
;
289 eapol_conf
.workaround
= ssid
->eap_workaround
;
290 eapol_conf
.eap_disabled
=
291 !wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) &&
292 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
293 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPS
;
294 eapol_sm_notify_config(wpa_s
->eapol
, &ssid
->eap
, &eapol_conf
);
295 #endif /* IEEE8021X_EAPOL */
300 * wpa_supplicant_set_non_wpa_policy - Set WPA parameters to non-WPA mode
301 * @wpa_s: Pointer to wpa_supplicant data
302 * @ssid: Configuration data for the network
304 * This function is used to configure WPA state machine and related parameters
305 * to a mode where WPA is not enabled. This is called as part of the
306 * authentication configuration when the selected network does not use WPA.
308 void wpa_supplicant_set_non_wpa_policy(struct wpa_supplicant
*wpa_s
,
309 struct wpa_ssid
*ssid
)
313 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
314 wpa_s
->key_mgmt
= WPA_KEY_MGMT_WPS
;
315 else if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)
316 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X_NO_WPA
;
318 wpa_s
->key_mgmt
= WPA_KEY_MGMT_NONE
;
319 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
320 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
321 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
322 wpa_s
->pairwise_cipher
= WPA_CIPHER_NONE
;
323 wpa_s
->group_cipher
= WPA_CIPHER_NONE
;
324 wpa_s
->mgmt_group_cipher
= 0;
326 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
327 if (ssid
->wep_key_len
[i
] > 5) {
328 wpa_s
->pairwise_cipher
= WPA_CIPHER_WEP104
;
329 wpa_s
->group_cipher
= WPA_CIPHER_WEP104
;
331 } else if (ssid
->wep_key_len
[i
] > 0) {
332 wpa_s
->pairwise_cipher
= WPA_CIPHER_WEP40
;
333 wpa_s
->group_cipher
= WPA_CIPHER_WEP40
;
338 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_RSN_ENABLED
, 0);
339 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_KEY_MGMT
, wpa_s
->key_mgmt
);
340 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PAIRWISE
,
341 wpa_s
->pairwise_cipher
);
342 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_GROUP
, wpa_s
->group_cipher
);
343 #ifdef CONFIG_IEEE80211W
344 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MGMT_GROUP
,
345 wpa_s
->mgmt_group_cipher
);
346 #endif /* CONFIG_IEEE80211W */
348 pmksa_cache_clear_current(wpa_s
->wpa
);
352 void free_hw_features(struct wpa_supplicant
*wpa_s
)
355 if (wpa_s
->hw
.modes
== NULL
)
358 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
359 os_free(wpa_s
->hw
.modes
[i
].channels
);
360 os_free(wpa_s
->hw
.modes
[i
].rates
);
363 os_free(wpa_s
->hw
.modes
);
364 wpa_s
->hw
.modes
= NULL
;
368 static void wpa_supplicant_cleanup(struct wpa_supplicant
*wpa_s
)
370 bgscan_deinit(wpa_s
);
371 scard_deinit(wpa_s
->scard
);
373 wpa_sm_set_scard_ctx(wpa_s
->wpa
, NULL
);
374 eapol_sm_register_scard_ctx(wpa_s
->eapol
, NULL
);
375 l2_packet_deinit(wpa_s
->l2
);
378 l2_packet_deinit(wpa_s
->l2_br
);
382 if (wpa_s
->conf
!= NULL
) {
383 struct wpa_ssid
*ssid
;
384 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
)
385 wpas_notify_network_removed(wpa_s
, ssid
);
388 os_free(wpa_s
->confname
);
389 wpa_s
->confname
= NULL
;
391 wpa_sm_set_eapol(wpa_s
->wpa
, NULL
);
392 eapol_sm_deinit(wpa_s
->eapol
);
395 rsn_preauth_deinit(wpa_s
->wpa
);
398 wpa_tdls_deinit(wpa_s
->wpa
);
399 #endif /* CONFIG_TDLS */
401 pmksa_candidate_free(wpa_s
->wpa
);
402 wpa_sm_deinit(wpa_s
->wpa
);
404 wpa_blacklist_clear(wpa_s
);
406 wpa_bss_deinit(wpa_s
);
408 wpa_supplicant_cancel_scan(wpa_s
);
409 wpa_supplicant_cancel_auth_timeout(wpa_s
);
410 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
411 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
412 eloop_cancel_timeout(wpa_supplicant_delayed_mic_error_report
,
414 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
416 wpas_wps_deinit(wpa_s
);
418 wpabuf_free(wpa_s
->pending_eapol_rx
);
419 wpa_s
->pending_eapol_rx
= NULL
;
421 #ifdef CONFIG_IBSS_RSN
422 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
423 wpa_s
->ibss_rsn
= NULL
;
424 #endif /* CONFIG_IBSS_RSN */
429 wpa_supplicant_ap_deinit(wpa_s
);
430 #endif /* CONFIG_AP */
433 wpas_p2p_deinit(wpa_s
);
434 #endif /* CONFIG_P2P */
436 #ifdef CONFIG_OFFCHANNEL
437 offchannel_deinit(wpa_s
);
438 #endif /* CONFIG_OFFCHANNEL */
440 wpa_supplicant_cancel_sched_scan(wpa_s
);
442 os_free(wpa_s
->next_scan_freqs
);
443 wpa_s
->next_scan_freqs
= NULL
;
445 gas_query_deinit(wpa_s
->gas
);
448 free_hw_features(wpa_s
);
450 os_free(wpa_s
->bssid_filter
);
451 wpa_s
->bssid_filter
= NULL
;
456 * wpa_clear_keys - Clear keys configured for the driver
457 * @wpa_s: Pointer to wpa_supplicant data
458 * @addr: Previously used BSSID or %NULL if not available
460 * This function clears the encryption keys that has been previously configured
463 void wpa_clear_keys(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
465 if (wpa_s
->keys_cleared
) {
466 /* Some drivers (e.g., ndiswrapper & NDIS drivers) seem to have
467 * timing issues with keys being cleared just before new keys
468 * are set or just after association or something similar. This
469 * shows up in group key handshake failing often because of the
470 * client not receiving the first encrypted packets correctly.
471 * Skipping some of the extra key clearing steps seems to help
472 * in completing group key handshake more reliably. */
473 wpa_dbg(wpa_s
, MSG_DEBUG
, "No keys have been configured - "
474 "skip key clearing");
478 /* MLME-DELETEKEYS.request */
479 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
480 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
481 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
482 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
483 #ifdef CONFIG_IEEE80211W
484 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
485 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
486 #endif /* CONFIG_IEEE80211W */
488 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, addr
, 0, 0, NULL
, 0, NULL
,
490 /* MLME-SETPROTECTION.request(None) */
491 wpa_drv_mlme_setprotection(
493 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
494 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
496 wpa_s
->keys_cleared
= 1;
501 * wpa_supplicant_state_txt - Get the connection state name as a text string
502 * @state: State (wpa_state; WPA_*)
503 * Returns: The state name as a printable text string
505 const char * wpa_supplicant_state_txt(enum wpa_states state
)
508 case WPA_DISCONNECTED
:
509 return "DISCONNECTED";
512 case WPA_INTERFACE_DISABLED
:
513 return "INTERFACE_DISABLED";
516 case WPA_AUTHENTICATING
:
517 return "AUTHENTICATING";
518 case WPA_ASSOCIATING
:
519 return "ASSOCIATING";
522 case WPA_4WAY_HANDSHAKE
:
523 return "4WAY_HANDSHAKE";
524 case WPA_GROUP_HANDSHAKE
:
525 return "GROUP_HANDSHAKE";
536 static void wpa_supplicant_start_bgscan(struct wpa_supplicant
*wpa_s
)
538 if (wpas_driver_bss_selection(wpa_s
))
540 if (wpa_s
->current_ssid
== wpa_s
->bgscan_ssid
)
543 bgscan_deinit(wpa_s
);
544 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->bgscan
) {
545 if (bgscan_init(wpa_s
, wpa_s
->current_ssid
)) {
546 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to initialize "
549 * Live without bgscan; it is only used as a roaming
550 * optimization, so the initial connection is not
554 wpa_s
->bgscan_ssid
= wpa_s
->current_ssid
;
556 wpa_s
->bgscan_ssid
= NULL
;
560 static void wpa_supplicant_stop_bgscan(struct wpa_supplicant
*wpa_s
)
562 if (wpa_s
->bgscan_ssid
!= NULL
) {
563 bgscan_deinit(wpa_s
);
564 wpa_s
->bgscan_ssid
= NULL
;
568 #endif /* CONFIG_BGSCAN */
572 * wpa_supplicant_set_state - Set current connection state
573 * @wpa_s: Pointer to wpa_supplicant data
574 * @state: The new connection state
576 * This function is called whenever the connection state changes, e.g.,
577 * association is completed for WPA/WPA2 4-Way Handshake is started.
579 void wpa_supplicant_set_state(struct wpa_supplicant
*wpa_s
,
580 enum wpa_states state
)
582 enum wpa_states old_state
= wpa_s
->wpa_state
;
584 wpa_dbg(wpa_s
, MSG_DEBUG
, "State: %s -> %s",
585 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
586 wpa_supplicant_state_txt(state
));
588 if (state
!= WPA_SCANNING
)
589 wpa_supplicant_notify_scanning(wpa_s
, 0);
591 if (state
== WPA_COMPLETED
&& wpa_s
->new_connection
) {
592 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
593 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
594 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
"- Connection to "
595 MACSTR
" completed %s [id=%d id_str=%s]",
596 MAC2STR(wpa_s
->bssid
), wpa_s
->reassociated_connection
?
597 "(reauth)" : "(auth)",
598 ssid
? ssid
->id
: -1,
599 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
600 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
601 wpa_s
->new_connection
= 0;
602 wpa_s
->reassociated_connection
= 1;
603 wpa_drv_set_operstate(wpa_s
, 1);
604 #ifndef IEEE8021X_EAPOL
605 wpa_drv_set_supp_port(wpa_s
, 1);
606 #endif /* IEEE8021X_EAPOL */
607 wpa_s
->after_wps
= 0;
609 wpas_p2p_completed(wpa_s
);
610 #endif /* CONFIG_P2P */
612 sme_sched_obss_scan(wpa_s
, 1);
613 } else if (state
== WPA_DISCONNECTED
|| state
== WPA_ASSOCIATING
||
614 state
== WPA_ASSOCIATED
) {
615 wpa_s
->new_connection
= 1;
616 wpa_drv_set_operstate(wpa_s
, 0);
617 #ifndef IEEE8021X_EAPOL
618 wpa_drv_set_supp_port(wpa_s
, 0);
619 #endif /* IEEE8021X_EAPOL */
620 sme_sched_obss_scan(wpa_s
, 0);
622 wpa_s
->wpa_state
= state
;
625 if (state
== WPA_COMPLETED
)
626 wpa_supplicant_start_bgscan(wpa_s
);
628 wpa_supplicant_stop_bgscan(wpa_s
);
629 #endif /* CONFIG_BGSCAN */
631 if (wpa_s
->wpa_state
!= old_state
) {
632 wpas_notify_state_changed(wpa_s
, wpa_s
->wpa_state
, old_state
);
634 if (wpa_s
->wpa_state
== WPA_COMPLETED
||
635 old_state
== WPA_COMPLETED
)
636 wpas_notify_auth_changed(wpa_s
);
641 void wpa_supplicant_terminate_proc(struct wpa_global
*global
)
645 struct wpa_supplicant
*wpa_s
= global
->ifaces
;
647 if (wpas_wps_terminate_pending(wpa_s
) == 1)
651 #endif /* CONFIG_WPS */
658 static void wpa_supplicant_terminate(int sig
, void *signal_ctx
)
660 struct wpa_global
*global
= signal_ctx
;
661 wpa_supplicant_terminate_proc(global
);
665 void wpa_supplicant_clear_status(struct wpa_supplicant
*wpa_s
)
667 enum wpa_states old_state
= wpa_s
->wpa_state
;
669 wpa_s
->pairwise_cipher
= 0;
670 wpa_s
->group_cipher
= 0;
671 wpa_s
->mgmt_group_cipher
= 0;
673 if (wpa_s
->wpa_state
!= WPA_INTERFACE_DISABLED
)
674 wpa_s
->wpa_state
= WPA_DISCONNECTED
;
676 if (wpa_s
->wpa_state
!= old_state
)
677 wpas_notify_state_changed(wpa_s
, wpa_s
->wpa_state
, old_state
);
682 * wpa_supplicant_reload_configuration - Reload configuration data
683 * @wpa_s: Pointer to wpa_supplicant data
684 * Returns: 0 on success or -1 if configuration parsing failed
686 * This function can be used to request that the configuration data is reloaded
687 * (e.g., after configuration file change). This function is reloading
688 * configuration only for one interface, so this may need to be called multiple
689 * times if %wpa_supplicant is controlling multiple interfaces and all
690 * interfaces need reconfiguration.
692 int wpa_supplicant_reload_configuration(struct wpa_supplicant
*wpa_s
)
694 struct wpa_config
*conf
;
698 if (wpa_s
->confname
== NULL
)
700 conf
= wpa_config_read(wpa_s
->confname
);
702 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to parse the configuration "
703 "file '%s' - exiting", wpa_s
->confname
);
706 conf
->changed_parameters
= (unsigned int) -1;
708 reconf_ctrl
= !!conf
->ctrl_interface
!= !!wpa_s
->conf
->ctrl_interface
709 || (conf
->ctrl_interface
&& wpa_s
->conf
->ctrl_interface
&&
710 os_strcmp(conf
->ctrl_interface
,
711 wpa_s
->conf
->ctrl_interface
) != 0);
713 if (reconf_ctrl
&& wpa_s
->ctrl_iface
) {
714 wpa_supplicant_ctrl_iface_deinit(wpa_s
->ctrl_iface
);
715 wpa_s
->ctrl_iface
= NULL
;
718 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
719 if (wpa_s
->current_ssid
) {
720 wpa_supplicant_deauthenticate(wpa_s
,
721 WLAN_REASON_DEAUTH_LEAVING
);
725 * TODO: should notify EAPOL SM about changes in opensc_engine_path,
726 * pkcs11_engine_path, pkcs11_module_path.
728 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
730 * Clear forced success to clear EAP state for next
733 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
735 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
736 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
737 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
738 wpa_sm_set_fast_reauth(wpa_s
->wpa
, wpa_s
->conf
->fast_reauth
);
739 rsn_preauth_deinit(wpa_s
->wpa
);
741 old_ap_scan
= wpa_s
->conf
->ap_scan
;
742 wpa_config_free(wpa_s
->conf
);
744 if (old_ap_scan
!= wpa_s
->conf
->ap_scan
)
745 wpas_notify_ap_scan_changed(wpa_s
);
748 wpa_s
->ctrl_iface
= wpa_supplicant_ctrl_iface_init(wpa_s
);
750 wpa_supplicant_update_config(wpa_s
);
752 wpa_supplicant_clear_status(wpa_s
);
753 if (wpa_supplicant_enabled_networks(wpa_s
->conf
)) {
754 wpa_s
->reassociate
= 1;
755 wpa_supplicant_req_scan(wpa_s
, 0, 0);
757 wpa_dbg(wpa_s
, MSG_DEBUG
, "Reconfiguration completed");
762 static void wpa_supplicant_reconfig(int sig
, void *signal_ctx
)
764 struct wpa_global
*global
= signal_ctx
;
765 struct wpa_supplicant
*wpa_s
;
766 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
767 wpa_dbg(wpa_s
, MSG_DEBUG
, "Signal %d received - reconfiguring",
769 if (wpa_supplicant_reload_configuration(wpa_s
) < 0) {
770 wpa_supplicant_terminate_proc(global
);
776 enum wpa_cipher
cipher_suite2driver(int cipher
)
779 case WPA_CIPHER_NONE
:
781 case WPA_CIPHER_WEP40
:
783 case WPA_CIPHER_WEP104
:
784 return CIPHER_WEP104
;
785 case WPA_CIPHER_CCMP
:
787 case WPA_CIPHER_TKIP
:
794 enum wpa_key_mgmt
key_mgmt2driver(int key_mgmt
)
797 case WPA_KEY_MGMT_NONE
:
798 return KEY_MGMT_NONE
;
799 case WPA_KEY_MGMT_IEEE8021X_NO_WPA
:
800 return KEY_MGMT_802_1X_NO_WPA
;
801 case WPA_KEY_MGMT_IEEE8021X
:
802 return KEY_MGMT_802_1X
;
803 case WPA_KEY_MGMT_WPA_NONE
:
804 return KEY_MGMT_WPA_NONE
;
805 case WPA_KEY_MGMT_FT_IEEE8021X
:
806 return KEY_MGMT_FT_802_1X
;
807 case WPA_KEY_MGMT_FT_PSK
:
808 return KEY_MGMT_FT_PSK
;
809 case WPA_KEY_MGMT_IEEE8021X_SHA256
:
810 return KEY_MGMT_802_1X_SHA256
;
811 case WPA_KEY_MGMT_PSK_SHA256
:
812 return KEY_MGMT_PSK_SHA256
;
813 case WPA_KEY_MGMT_WPS
:
815 case WPA_KEY_MGMT_PSK
:
822 static int wpa_supplicant_suites_from_ai(struct wpa_supplicant
*wpa_s
,
823 struct wpa_ssid
*ssid
,
824 struct wpa_ie_data
*ie
)
826 int ret
= wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, ie
);
829 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Failed to parse WPA IE "
830 "from association info");
835 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Using WPA IE from AssocReq to set "
837 if (!(ie
->group_cipher
& ssid
->group_cipher
)) {
838 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled group "
839 "cipher 0x%x (mask 0x%x) - reject",
840 ie
->group_cipher
, ssid
->group_cipher
);
843 if (!(ie
->pairwise_cipher
& ssid
->pairwise_cipher
)) {
844 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled pairwise "
845 "cipher 0x%x (mask 0x%x) - reject",
846 ie
->pairwise_cipher
, ssid
->pairwise_cipher
);
849 if (!(ie
->key_mgmt
& ssid
->key_mgmt
)) {
850 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled key "
851 "management 0x%x (mask 0x%x) - reject",
852 ie
->key_mgmt
, ssid
->key_mgmt
);
856 #ifdef CONFIG_IEEE80211W
857 if (!(ie
->capabilities
& WPA_CAPABILITY_MFPC
) &&
858 ssid
->ieee80211w
== MGMT_FRAME_PROTECTION_REQUIRED
) {
859 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver associated with an AP "
860 "that does not support management frame protection - "
864 #endif /* CONFIG_IEEE80211W */
871 * wpa_supplicant_set_suites - Set authentication and encryption parameters
872 * @wpa_s: Pointer to wpa_supplicant data
873 * @bss: Scan results for the selected BSS, or %NULL if not available
874 * @ssid: Configuration data for the selected network
875 * @wpa_ie: Buffer for the WPA/RSN IE
876 * @wpa_ie_len: Maximum wpa_ie buffer size on input. This is changed to be the
877 * used buffer length in case the functions returns success.
878 * Returns: 0 on success or -1 on failure
880 * This function is used to configure authentication and encryption parameters
881 * based on the network configuration and scan result for the selected BSS (if
884 int wpa_supplicant_set_suites(struct wpa_supplicant
*wpa_s
,
885 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
,
886 u8
*wpa_ie
, size_t *wpa_ie_len
)
888 struct wpa_ie_data ie
;
890 const u8
*bss_wpa
, *bss_rsn
;
893 bss_wpa
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
894 bss_rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
896 bss_wpa
= bss_rsn
= NULL
;
898 if (bss_rsn
&& (ssid
->proto
& WPA_PROTO_RSN
) &&
899 wpa_parse_wpa_ie(bss_rsn
, 2 + bss_rsn
[1], &ie
) == 0 &&
900 (ie
.group_cipher
& ssid
->group_cipher
) &&
901 (ie
.pairwise_cipher
& ssid
->pairwise_cipher
) &&
902 (ie
.key_mgmt
& ssid
->key_mgmt
)) {
903 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: using IEEE 802.11i/D9.0");
904 proto
= WPA_PROTO_RSN
;
905 } else if (bss_wpa
&& (ssid
->proto
& WPA_PROTO_WPA
) &&
906 wpa_parse_wpa_ie(bss_wpa
, 2 +bss_wpa
[1], &ie
) == 0 &&
907 (ie
.group_cipher
& ssid
->group_cipher
) &&
908 (ie
.pairwise_cipher
& ssid
->pairwise_cipher
) &&
909 (ie
.key_mgmt
& ssid
->key_mgmt
)) {
910 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using IEEE 802.11i/D3.0");
911 proto
= WPA_PROTO_WPA
;
913 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select WPA/RSN");
916 if (ssid
->proto
& WPA_PROTO_RSN
)
917 proto
= WPA_PROTO_RSN
;
919 proto
= WPA_PROTO_WPA
;
920 if (wpa_supplicant_suites_from_ai(wpa_s
, ssid
, &ie
) < 0) {
921 os_memset(&ie
, 0, sizeof(ie
));
922 ie
.group_cipher
= ssid
->group_cipher
;
923 ie
.pairwise_cipher
= ssid
->pairwise_cipher
;
924 ie
.key_mgmt
= ssid
->key_mgmt
;
925 #ifdef CONFIG_IEEE80211W
926 ie
.mgmt_group_cipher
=
927 ssid
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
?
928 WPA_CIPHER_AES_128_CMAC
: 0;
929 #endif /* CONFIG_IEEE80211W */
930 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Set cipher suites "
931 "based on configuration");
936 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Selected cipher suites: group %d "
937 "pairwise %d key_mgmt %d proto %d",
938 ie
.group_cipher
, ie
.pairwise_cipher
, ie
.key_mgmt
, proto
);
939 #ifdef CONFIG_IEEE80211W
940 if (ssid
->ieee80211w
) {
941 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Selected mgmt group cipher %d",
942 ie
.mgmt_group_cipher
);
944 #endif /* CONFIG_IEEE80211W */
946 wpa_s
->wpa_proto
= proto
;
947 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PROTO
, proto
);
948 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_RSN_ENABLED
,
949 !!(ssid
->proto
& WPA_PROTO_RSN
));
951 if (bss
|| !wpa_s
->ap_ies_from_associnfo
) {
952 if (wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, bss_wpa
,
953 bss_wpa
? 2 + bss_wpa
[1] : 0) ||
954 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, bss_rsn
,
955 bss_rsn
? 2 + bss_rsn
[1] : 0))
959 sel
= ie
.group_cipher
& ssid
->group_cipher
;
960 if (sel
& WPA_CIPHER_CCMP
) {
961 wpa_s
->group_cipher
= WPA_CIPHER_CCMP
;
962 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using GTK CCMP");
963 } else if (sel
& WPA_CIPHER_TKIP
) {
964 wpa_s
->group_cipher
= WPA_CIPHER_TKIP
;
965 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using GTK TKIP");
966 } else if (sel
& WPA_CIPHER_WEP104
) {
967 wpa_s
->group_cipher
= WPA_CIPHER_WEP104
;
968 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using GTK WEP104");
969 } else if (sel
& WPA_CIPHER_WEP40
) {
970 wpa_s
->group_cipher
= WPA_CIPHER_WEP40
;
971 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using GTK WEP40");
973 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select group "
978 sel
= ie
.pairwise_cipher
& ssid
->pairwise_cipher
;
979 if (sel
& WPA_CIPHER_CCMP
) {
980 wpa_s
->pairwise_cipher
= WPA_CIPHER_CCMP
;
981 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using PTK CCMP");
982 } else if (sel
& WPA_CIPHER_TKIP
) {
983 wpa_s
->pairwise_cipher
= WPA_CIPHER_TKIP
;
984 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using PTK TKIP");
985 } else if (sel
& WPA_CIPHER_NONE
) {
986 wpa_s
->pairwise_cipher
= WPA_CIPHER_NONE
;
987 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using PTK NONE");
989 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select pairwise "
994 sel
= ie
.key_mgmt
& ssid
->key_mgmt
;
996 #ifdef CONFIG_IEEE80211R
997 } else if (sel
& WPA_KEY_MGMT_FT_IEEE8021X
) {
998 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_IEEE8021X
;
999 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FT/802.1X");
1000 } else if (sel
& WPA_KEY_MGMT_FT_PSK
) {
1001 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_PSK
;
1002 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FT/PSK");
1003 #endif /* CONFIG_IEEE80211R */
1004 #ifdef CONFIG_IEEE80211W
1005 } else if (sel
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
1006 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X_SHA256
;
1007 wpa_dbg(wpa_s
, MSG_DEBUG
,
1008 "WPA: using KEY_MGMT 802.1X with SHA256");
1009 } else if (sel
& WPA_KEY_MGMT_PSK_SHA256
) {
1010 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK_SHA256
;
1011 wpa_dbg(wpa_s
, MSG_DEBUG
,
1012 "WPA: using KEY_MGMT PSK with SHA256");
1013 #endif /* CONFIG_IEEE80211W */
1014 } else if (sel
& WPA_KEY_MGMT_IEEE8021X
) {
1015 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X
;
1016 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT 802.1X");
1017 } else if (sel
& WPA_KEY_MGMT_PSK
) {
1018 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK
;
1019 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT WPA-PSK");
1020 } else if (sel
& WPA_KEY_MGMT_WPA_NONE
) {
1021 wpa_s
->key_mgmt
= WPA_KEY_MGMT_WPA_NONE
;
1022 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT WPA-NONE");
1024 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select "
1025 "authenticated key management type");
1029 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_KEY_MGMT
, wpa_s
->key_mgmt
);
1030 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PAIRWISE
,
1031 wpa_s
->pairwise_cipher
);
1032 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_GROUP
, wpa_s
->group_cipher
);
1034 #ifdef CONFIG_IEEE80211W
1035 sel
= ie
.mgmt_group_cipher
;
1036 if (ssid
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
||
1037 !(ie
.capabilities
& WPA_CAPABILITY_MFPC
))
1039 if (sel
& WPA_CIPHER_AES_128_CMAC
) {
1040 wpa_s
->mgmt_group_cipher
= WPA_CIPHER_AES_128_CMAC
;
1041 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using MGMT group cipher "
1044 wpa_s
->mgmt_group_cipher
= 0;
1045 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: not using MGMT group cipher");
1047 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MGMT_GROUP
,
1048 wpa_s
->mgmt_group_cipher
);
1049 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MFP
, ssid
->ieee80211w
);
1050 #endif /* CONFIG_IEEE80211W */
1052 if (wpa_sm_set_assoc_wpa_ie_default(wpa_s
->wpa
, wpa_ie
, wpa_ie_len
)) {
1053 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to generate WPA IE");
1057 if (wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
)) {
1058 wpa_sm_set_pmk(wpa_s
->wpa
, ssid
->psk
, PMK_LEN
);
1059 #ifndef CONFIG_NO_PBKDF2
1060 if (bss
&& ssid
->bssid_set
&& ssid
->ssid_len
== 0 &&
1063 pbkdf2_sha1(ssid
->passphrase
, (char *) bss
->ssid
,
1064 bss
->ssid_len
, 4096, psk
, PMK_LEN
);
1065 wpa_hexdump_key(MSG_MSGDUMP
, "PSK (from passphrase)",
1067 wpa_sm_set_pmk(wpa_s
->wpa
, psk
, PMK_LEN
);
1069 #endif /* CONFIG_NO_PBKDF2 */
1071 wpa_sm_set_pmk_from_pmksa(wpa_s
->wpa
);
1078 * wpa_supplicant_associate - Request association
1079 * @wpa_s: Pointer to wpa_supplicant data
1080 * @bss: Scan results for the selected BSS, or %NULL if not available
1081 * @ssid: Configuration data for the selected network
1083 * This function is used to request %wpa_supplicant to associate with a BSS.
1085 void wpa_supplicant_associate(struct wpa_supplicant
*wpa_s
,
1086 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
)
1090 int use_crypt
, ret
, i
, bssid_changed
;
1091 int algs
= WPA_AUTH_ALG_OPEN
;
1092 enum wpa_cipher cipher_pairwise
, cipher_group
;
1093 struct wpa_driver_associate_params params
;
1094 int wep_keys_set
= 0;
1095 struct wpa_driver_capa capa
;
1096 int assoc_failed
= 0;
1097 struct wpa_ssid
*old_ssid
;
1098 #ifdef CONFIG_HT_OVERRIDES
1099 struct ieee80211_ht_capabilities htcaps
;
1100 struct ieee80211_ht_capabilities htcaps_mask
;
1101 #endif /* CONFIG_HT_OVERRIDES */
1103 #ifdef CONFIG_IBSS_RSN
1104 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
1105 wpa_s
->ibss_rsn
= NULL
;
1106 #endif /* CONFIG_IBSS_RSN */
1108 if (ssid
->mode
== WPAS_MODE_AP
|| ssid
->mode
== WPAS_MODE_P2P_GO
||
1109 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
) {
1111 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_AP
)) {
1112 wpa_msg(wpa_s
, MSG_INFO
, "Driver does not support AP "
1116 wpa_supplicant_create_ap(wpa_s
, ssid
);
1117 wpa_s
->current_bss
= bss
;
1118 #else /* CONFIG_AP */
1119 wpa_msg(wpa_s
, MSG_ERROR
, "AP mode support not included in "
1121 #endif /* CONFIG_AP */
1127 wpa_tdls_ap_ies(wpa_s
->wpa
, (const u8
*) (bss
+ 1),
1129 #endif /* CONFIG_TDLS */
1131 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
1132 ssid
->mode
== IEEE80211_MODE_INFRA
) {
1133 sme_authenticate(wpa_s
, bss
, ssid
);
1137 os_memset(¶ms
, 0, sizeof(params
));
1138 wpa_s
->reassociate
= 0;
1139 if (bss
&& !wpas_driver_bss_selection(wpa_s
)) {
1140 #ifdef CONFIG_IEEE80211R
1141 const u8
*ie
, *md
= NULL
;
1142 #endif /* CONFIG_IEEE80211R */
1143 wpa_msg(wpa_s
, MSG_INFO
, "Trying to associate with " MACSTR
1144 " (SSID='%s' freq=%d MHz)", MAC2STR(bss
->bssid
),
1145 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
), bss
->freq
);
1146 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
1147 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
1148 os_memcpy(wpa_s
->pending_bssid
, bss
->bssid
, ETH_ALEN
);
1150 wpas_notify_bssid_changed(wpa_s
);
1151 #ifdef CONFIG_IEEE80211R
1152 ie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
1153 if (ie
&& ie
[1] >= MOBILITY_DOMAIN_ID_LEN
)
1155 wpa_sm_set_ft_params(wpa_s
->wpa
, ie
, ie
? 2 + ie
[1] : 0);
1157 /* Prepare for the next transition */
1158 wpa_ft_prepare_auth_request(wpa_s
->wpa
, ie
);
1160 #endif /* CONFIG_IEEE80211R */
1162 } else if ((ssid
->ssid
== NULL
|| ssid
->ssid_len
== 0) &&
1163 wpa_s
->conf
->ap_scan
== 2 &&
1164 (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
1165 /* Use ap_scan==1 style network selection to find the network
1167 wpa_s
->scan_req
= 2;
1168 wpa_s
->reassociate
= 1;
1169 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1171 #endif /* CONFIG_WPS */
1173 wpa_msg(wpa_s
, MSG_INFO
, "Trying to associate with SSID '%s'",
1174 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
1175 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1177 wpa_supplicant_cancel_sched_scan(wpa_s
);
1178 wpa_supplicant_cancel_scan(wpa_s
);
1180 /* Starting new association, so clear the possibly used WPA IE from the
1181 * previous association. */
1182 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1184 #ifdef IEEE8021X_EAPOL
1185 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1187 if (ssid
->non_leap
== 0)
1188 algs
= WPA_AUTH_ALG_LEAP
;
1190 algs
|= WPA_AUTH_ALG_LEAP
;
1193 #endif /* IEEE8021X_EAPOL */
1194 wpa_dbg(wpa_s
, MSG_DEBUG
, "Automatic auth_alg selection: 0x%x", algs
);
1195 if (ssid
->auth_alg
) {
1196 algs
= ssid
->auth_alg
;
1197 wpa_dbg(wpa_s
, MSG_DEBUG
, "Overriding auth_alg selection: "
1201 if (bss
&& (wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
) ||
1202 wpa_bss_get_ie(bss
, WLAN_EID_RSN
)) &&
1203 wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
1204 int try_opportunistic
;
1205 try_opportunistic
= ssid
->proactive_key_caching
&&
1206 (ssid
->proto
& WPA_PROTO_RSN
);
1207 if (pmksa_cache_set_current(wpa_s
->wpa
, NULL
, bss
->bssid
,
1208 wpa_s
->current_ssid
,
1209 try_opportunistic
) == 0)
1210 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
, 1);
1211 wpa_ie_len
= sizeof(wpa_ie
);
1212 if (wpa_supplicant_set_suites(wpa_s
, bss
, ssid
,
1213 wpa_ie
, &wpa_ie_len
)) {
1214 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to set WPA "
1215 "key management and encryption suites");
1218 } else if (wpa_key_mgmt_wpa_any(ssid
->key_mgmt
)) {
1219 wpa_ie_len
= sizeof(wpa_ie
);
1220 if (wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
1221 wpa_ie
, &wpa_ie_len
)) {
1222 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to set WPA "
1223 "key management and encryption suites (no "
1228 } else if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
1229 struct wpabuf
*wps_ie
;
1230 wps_ie
= wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid
));
1231 if (wps_ie
&& wpabuf_len(wps_ie
) <= sizeof(wpa_ie
)) {
1232 wpa_ie_len
= wpabuf_len(wps_ie
);
1233 os_memcpy(wpa_ie
, wpabuf_head(wps_ie
), wpa_ie_len
);
1236 wpabuf_free(wps_ie
);
1237 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
1238 if (!bss
|| (bss
->caps
& IEEE80211_CAP_PRIVACY
))
1239 params
.wps
= WPS_MODE_PRIVACY
;
1241 params
.wps
= WPS_MODE_OPEN
;
1242 wpa_s
->wpa_proto
= 0;
1243 #endif /* CONFIG_WPS */
1245 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
1247 wpa_s
->wpa_proto
= 0;
1251 if (wpa_s
->global
->p2p
) {
1255 pos
= wpa_ie
+ wpa_ie_len
;
1256 len
= sizeof(wpa_ie
) - wpa_ie_len
;
1257 res
= wpas_p2p_assoc_req_ie(wpa_s
, bss
, pos
, len
,
1263 wpa_s
->cross_connect_disallowed
= 0;
1266 p2p
= wpa_bss_get_vendor_ie_multi(bss
, P2P_IE_VENDOR_TYPE
);
1268 wpa_s
->cross_connect_disallowed
=
1269 p2p_get_cross_connect_disallowed(p2p
);
1271 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: WLAN AP %s cross "
1273 wpa_s
->cross_connect_disallowed
?
1274 "disallows" : "allows");
1277 #endif /* CONFIG_P2P */
1280 if (wpa_s
->conf
->hs20
) {
1281 struct wpabuf
*hs20
;
1282 hs20
= wpabuf_alloc(20);
1284 wpas_hs20_add_indication(hs20
);
1285 os_memcpy(wpa_ie
+ wpa_ie_len
, wpabuf_head(hs20
),
1287 wpa_ie_len
+= wpabuf_len(hs20
);
1291 #endif /* CONFIG_HS20 */
1293 #ifdef CONFIG_INTERWORKING
1294 if (wpa_s
->conf
->interworking
) {
1296 if (wpa_ie_len
> 0 && pos
[0] == WLAN_EID_RSN
)
1298 os_memmove(pos
+ 6, pos
, wpa_ie_len
- (pos
- wpa_ie
));
1300 *pos
++ = WLAN_EID_EXT_CAPAB
;
1305 *pos
++ = 0x80; /* Bit 31 - Interworking */
1307 #endif /* CONFIG_INTERWORKING */
1309 wpa_clear_keys(wpa_s
, bss
? bss
->bssid
: NULL
);
1311 cipher_pairwise
= cipher_suite2driver(wpa_s
->pairwise_cipher
);
1312 cipher_group
= cipher_suite2driver(wpa_s
->group_cipher
);
1313 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1314 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1315 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
)
1317 if (wpa_set_wep_keys(wpa_s
, ssid
)) {
1322 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
)
1325 #ifdef IEEE8021X_EAPOL
1326 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1327 if ((ssid
->eapol_flags
&
1328 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
1329 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
)) == 0 &&
1333 /* Assume that dynamic WEP-104 keys will be used and
1334 * set cipher suites in order for drivers to expect
1336 cipher_pairwise
= cipher_group
= CIPHER_WEP104
;
1339 #endif /* IEEE8021X_EAPOL */
1341 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1342 /* Set the key before (and later after) association */
1343 wpa_supplicant_set_wpa_none_key(wpa_s
, ssid
);
1346 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATING
);
1348 params
.ssid
= bss
->ssid
;
1349 params
.ssid_len
= bss
->ssid_len
;
1350 if (!wpas_driver_bss_selection(wpa_s
)) {
1351 params
.bssid
= bss
->bssid
;
1352 params
.freq
= bss
->freq
;
1355 params
.ssid
= ssid
->ssid
;
1356 params
.ssid_len
= ssid
->ssid_len
;
1359 if (ssid
->mode
== WPAS_MODE_IBSS
&& ssid
->bssid_set
&&
1360 wpa_s
->conf
->ap_scan
== 2) {
1361 params
.bssid
= ssid
->bssid
;
1362 params
.fixed_bssid
= 1;
1365 if (ssid
->mode
== WPAS_MODE_IBSS
&& ssid
->frequency
> 0 &&
1367 params
.freq
= ssid
->frequency
; /* Initial channel for IBSS */
1368 params
.wpa_ie
= wpa_ie
;
1369 params
.wpa_ie_len
= wpa_ie_len
;
1370 params
.pairwise_suite
= cipher_pairwise
;
1371 params
.group_suite
= cipher_group
;
1372 params
.key_mgmt_suite
= key_mgmt2driver(wpa_s
->key_mgmt
);
1373 params
.wpa_proto
= wpa_s
->wpa_proto
;
1374 params
.auth_alg
= algs
;
1375 params
.mode
= ssid
->mode
;
1376 params
.bg_scan_period
= ssid
->bg_scan_period
;
1377 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
1378 if (ssid
->wep_key_len
[i
])
1379 params
.wep_key
[i
] = ssid
->wep_key
[i
];
1380 params
.wep_key_len
[i
] = ssid
->wep_key_len
[i
];
1382 params
.wep_tx_keyidx
= ssid
->wep_tx_keyidx
;
1384 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1385 (params
.key_mgmt_suite
== KEY_MGMT_PSK
||
1386 params
.key_mgmt_suite
== KEY_MGMT_FT_PSK
)) {
1387 params
.passphrase
= ssid
->passphrase
;
1389 params
.psk
= ssid
->psk
;
1392 params
.drop_unencrypted
= use_crypt
;
1394 #ifdef CONFIG_IEEE80211W
1395 params
.mgmt_frame_protection
= ssid
->ieee80211w
;
1396 if (ssid
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
&& bss
) {
1397 const u8
*rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1398 struct wpa_ie_data ie
;
1399 if (rsn
&& wpa_parse_wpa_ie(rsn
, 2 + rsn
[1], &ie
) == 0 &&
1401 (WPA_CAPABILITY_MFPC
| WPA_CAPABILITY_MFPR
)) {
1402 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Selected AP supports "
1403 "MFP: require MFP");
1404 params
.mgmt_frame_protection
=
1405 MGMT_FRAME_PROTECTION_REQUIRED
;
1408 #endif /* CONFIG_IEEE80211W */
1410 params
.p2p
= ssid
->p2p_group
;
1412 if (wpa_s
->parent
->set_sta_uapsd
)
1413 params
.uapsd
= wpa_s
->parent
->sta_uapsd
;
1417 #ifdef CONFIG_HT_OVERRIDES
1418 os_memset(&htcaps
, 0, sizeof(htcaps
));
1419 os_memset(&htcaps_mask
, 0, sizeof(htcaps_mask
));
1420 params
.htcaps
= (u8
*) &htcaps
;
1421 params
.htcaps_mask
= (u8
*) &htcaps_mask
;
1422 wpa_supplicant_apply_ht_overrides(wpa_s
, ssid
, ¶ms
);
1423 #endif /* CONFIG_HT_OVERRIDES */
1425 ret
= wpa_drv_associate(wpa_s
, ¶ms
);
1427 wpa_msg(wpa_s
, MSG_INFO
, "Association request to the driver "
1429 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SANE_ERROR_CODES
) {
1431 * The driver is known to mean what is saying, so we
1432 * can stop right here; the association will not
1435 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1436 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1439 /* try to continue anyway; new association will be tried again
1444 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1445 /* Set the key after the association just in case association
1446 * cleared the previously configured key. */
1447 wpa_supplicant_set_wpa_none_key(wpa_s
, ssid
);
1448 /* No need to timeout authentication since there is no key
1450 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1451 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1452 #ifdef CONFIG_IBSS_RSN
1453 } else if (ssid
->mode
== WPAS_MODE_IBSS
&&
1454 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
1455 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
) {
1457 * RSN IBSS authentication is per-STA and we can disable the
1458 * per-BSSID authentication.
1460 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1461 #endif /* CONFIG_IBSS_RSN */
1463 /* Timeout for IEEE 802.11 authentication and association */
1467 /* give IBSS a bit more time */
1468 timeout
= ssid
->mode
== WPAS_MODE_IBSS
? 10 : 5;
1469 } else if (wpa_s
->conf
->ap_scan
== 1) {
1470 /* give IBSS a bit more time */
1471 timeout
= ssid
->mode
== WPAS_MODE_IBSS
? 20 : 10;
1473 wpa_supplicant_req_auth_timeout(wpa_s
, timeout
, 0);
1476 if (wep_keys_set
&& wpa_drv_get_capa(wpa_s
, &capa
) == 0 &&
1477 capa
.flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC
) {
1478 /* Set static WEP keys again */
1479 wpa_set_wep_keys(wpa_s
, ssid
);
1482 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
) {
1484 * Do not allow EAP session resumption between different
1485 * network configurations.
1487 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
1489 old_ssid
= wpa_s
->current_ssid
;
1490 wpa_s
->current_ssid
= ssid
;
1491 wpa_s
->current_bss
= bss
;
1492 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
1493 wpa_supplicant_initiate_eapol(wpa_s
);
1494 if (old_ssid
!= wpa_s
->current_ssid
)
1495 wpas_notify_network_changed(wpa_s
);
1499 static void wpa_supplicant_clear_connection(struct wpa_supplicant
*wpa_s
,
1502 struct wpa_ssid
*old_ssid
;
1504 wpa_clear_keys(wpa_s
, addr
);
1505 wpa_supplicant_mark_disassoc(wpa_s
);
1506 old_ssid
= wpa_s
->current_ssid
;
1507 wpa_s
->current_ssid
= NULL
;
1508 wpa_s
->current_bss
= NULL
;
1509 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
1510 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
1511 if (old_ssid
!= wpa_s
->current_ssid
)
1512 wpas_notify_network_changed(wpa_s
);
1513 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
1518 * wpa_supplicant_disassociate - Disassociate the current connection
1519 * @wpa_s: Pointer to wpa_supplicant data
1520 * @reason_code: IEEE 802.11 reason code for the disassociate frame
1522 * This function is used to request %wpa_supplicant to disassociate with the
1525 void wpa_supplicant_disassociate(struct wpa_supplicant
*wpa_s
,
1529 union wpa_event_data event
;
1531 if (!is_zero_ether_addr(wpa_s
->bssid
)) {
1532 wpa_drv_disassociate(wpa_s
, wpa_s
->bssid
, reason_code
);
1533 addr
= wpa_s
->bssid
;
1534 os_memset(&event
, 0, sizeof(event
));
1535 event
.disassoc_info
.reason_code
= (u16
) reason_code
;
1536 event
.disassoc_info
.locally_generated
= 1;
1537 wpa_supplicant_event(wpa_s
, EVENT_DISASSOC
, &event
);
1540 wpa_supplicant_clear_connection(wpa_s
, addr
);
1545 * wpa_supplicant_deauthenticate - Deauthenticate the current connection
1546 * @wpa_s: Pointer to wpa_supplicant data
1547 * @reason_code: IEEE 802.11 reason code for the deauthenticate frame
1549 * This function is used to request %wpa_supplicant to deauthenticate from the
1552 void wpa_supplicant_deauthenticate(struct wpa_supplicant
*wpa_s
,
1556 union wpa_event_data event
;
1558 if (!is_zero_ether_addr(wpa_s
->bssid
)) {
1559 wpa_drv_deauthenticate(wpa_s
, wpa_s
->bssid
, reason_code
);
1560 addr
= wpa_s
->bssid
;
1561 os_memset(&event
, 0, sizeof(event
));
1562 event
.deauth_info
.reason_code
= (u16
) reason_code
;
1563 event
.deauth_info
.locally_generated
= 1;
1564 wpa_supplicant_event(wpa_s
, EVENT_DEAUTH
, &event
);
1567 wpa_supplicant_clear_connection(wpa_s
, addr
);
1572 * wpa_supplicant_enable_network - Mark a configured network as enabled
1573 * @wpa_s: wpa_supplicant structure for a network interface
1574 * @ssid: wpa_ssid structure for a configured network or %NULL
1576 * Enables the specified network or all networks if no network specified.
1578 void wpa_supplicant_enable_network(struct wpa_supplicant
*wpa_s
,
1579 struct wpa_ssid
*ssid
)
1581 struct wpa_ssid
*other_ssid
;
1585 for (other_ssid
= wpa_s
->conf
->ssid
; other_ssid
;
1586 other_ssid
= other_ssid
->next
) {
1587 if (other_ssid
->disabled
== 2)
1588 continue; /* do not change persistent P2P group
1590 if (other_ssid
== wpa_s
->current_ssid
&&
1591 other_ssid
->disabled
)
1592 wpa_s
->reassociate
= 1;
1594 was_disabled
= other_ssid
->disabled
;
1596 other_ssid
->disabled
= 0;
1598 if (was_disabled
!= other_ssid
->disabled
)
1599 wpas_notify_network_enabled_changed(
1602 if (wpa_s
->reassociate
)
1603 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1604 } else if (ssid
->disabled
&& ssid
->disabled
!= 2) {
1605 if (wpa_s
->current_ssid
== NULL
) {
1607 * Try to reassociate since there is no current
1608 * configuration and a new network was made available.
1610 wpa_s
->reassociate
= 1;
1611 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1614 was_disabled
= ssid
->disabled
;
1618 if (was_disabled
!= ssid
->disabled
)
1619 wpas_notify_network_enabled_changed(wpa_s
, ssid
);
1625 * wpa_supplicant_disable_network - Mark a configured network as disabled
1626 * @wpa_s: wpa_supplicant structure for a network interface
1627 * @ssid: wpa_ssid structure for a configured network or %NULL
1629 * Disables the specified network or all networks if no network specified.
1631 void wpa_supplicant_disable_network(struct wpa_supplicant
*wpa_s
,
1632 struct wpa_ssid
*ssid
)
1634 struct wpa_ssid
*other_ssid
;
1638 for (other_ssid
= wpa_s
->conf
->ssid
; other_ssid
;
1639 other_ssid
= other_ssid
->next
) {
1640 was_disabled
= other_ssid
->disabled
;
1641 if (was_disabled
== 2)
1642 continue; /* do not change persistent P2P group
1645 other_ssid
->disabled
= 1;
1647 if (was_disabled
!= other_ssid
->disabled
)
1648 wpas_notify_network_enabled_changed(
1651 if (wpa_s
->current_ssid
)
1652 wpa_supplicant_disassociate(
1653 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1654 } else if (ssid
->disabled
!= 2) {
1655 if (ssid
== wpa_s
->current_ssid
)
1656 wpa_supplicant_disassociate(
1657 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1659 was_disabled
= ssid
->disabled
;
1663 if (was_disabled
!= ssid
->disabled
)
1664 wpas_notify_network_enabled_changed(wpa_s
, ssid
);
1670 * wpa_supplicant_select_network - Attempt association with a network
1671 * @wpa_s: wpa_supplicant structure for a network interface
1672 * @ssid: wpa_ssid structure for a configured network or %NULL for any network
1674 void wpa_supplicant_select_network(struct wpa_supplicant
*wpa_s
,
1675 struct wpa_ssid
*ssid
)
1678 struct wpa_ssid
*other_ssid
;
1679 int disconnected
= 0;
1681 if (ssid
&& ssid
!= wpa_s
->current_ssid
&& wpa_s
->current_ssid
) {
1682 wpa_supplicant_disassociate(
1683 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1688 * Mark all other networks disabled or mark all networks enabled if no
1689 * network specified.
1691 for (other_ssid
= wpa_s
->conf
->ssid
; other_ssid
;
1692 other_ssid
= other_ssid
->next
) {
1693 int was_disabled
= other_ssid
->disabled
;
1694 if (was_disabled
== 2)
1695 continue; /* do not change persistent P2P group data */
1697 other_ssid
->disabled
= ssid
? (ssid
->id
!= other_ssid
->id
) : 0;
1699 if (was_disabled
!= other_ssid
->disabled
)
1700 wpas_notify_network_enabled_changed(wpa_s
, other_ssid
);
1703 if (ssid
&& ssid
== wpa_s
->current_ssid
&& wpa_s
->current_ssid
) {
1704 /* We are already associated with the selected network */
1705 wpa_printf(MSG_DEBUG
, "Already associated with the "
1706 "selected network - do nothing");
1711 wpa_s
->current_ssid
= ssid
;
1712 wpa_s
->connect_without_scan
= NULL
;
1713 wpa_s
->disconnected
= 0;
1714 wpa_s
->reassociate
= 1;
1715 wpa_supplicant_req_scan(wpa_s
, 0, disconnected
? 100000 : 0);
1718 wpas_notify_network_selected(wpa_s
, ssid
);
1723 * wpa_supplicant_set_ap_scan - Set AP scan mode for interface
1724 * @wpa_s: wpa_supplicant structure for a network interface
1725 * @ap_scan: AP scan mode
1726 * Returns: 0 if succeed or -1 if ap_scan has an invalid value
1729 int wpa_supplicant_set_ap_scan(struct wpa_supplicant
*wpa_s
, int ap_scan
)
1734 if (ap_scan
< 0 || ap_scan
> 2)
1738 if (ap_scan
== 2 && ap_scan
!= wpa_s
->conf
->ap_scan
&&
1739 wpa_s
->wpa_state
>= WPA_ASSOCIATING
&&
1740 wpa_s
->wpa_state
< WPA_COMPLETED
) {
1741 wpa_printf(MSG_ERROR
, "ap_scan = %d (%d) rejected while "
1742 "associating", wpa_s
->conf
->ap_scan
, ap_scan
);
1745 #endif /* ANDROID */
1747 old_ap_scan
= wpa_s
->conf
->ap_scan
;
1748 wpa_s
->conf
->ap_scan
= ap_scan
;
1750 if (old_ap_scan
!= wpa_s
->conf
->ap_scan
)
1751 wpas_notify_ap_scan_changed(wpa_s
);
1758 * wpa_supplicant_set_bss_expiration_age - Set BSS entry expiration age
1759 * @wpa_s: wpa_supplicant structure for a network interface
1760 * @expire_age: Expiration age in seconds
1761 * Returns: 0 if succeed or -1 if expire_age has an invalid value
1764 int wpa_supplicant_set_bss_expiration_age(struct wpa_supplicant
*wpa_s
,
1765 unsigned int bss_expire_age
)
1767 if (bss_expire_age
< 10) {
1768 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid bss expiration age %u",
1772 wpa_msg(wpa_s
, MSG_DEBUG
, "Setting bss expiration age: %d sec",
1774 wpa_s
->conf
->bss_expiration_age
= bss_expire_age
;
1781 * wpa_supplicant_set_bss_expiration_count - Set BSS entry expiration scan count
1782 * @wpa_s: wpa_supplicant structure for a network interface
1783 * @expire_count: number of scans after which an unseen BSS is reclaimed
1784 * Returns: 0 if succeed or -1 if expire_count has an invalid value
1787 int wpa_supplicant_set_bss_expiration_count(struct wpa_supplicant
*wpa_s
,
1788 unsigned int bss_expire_count
)
1790 if (bss_expire_count
< 1) {
1791 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid bss expiration count %u",
1795 wpa_msg(wpa_s
, MSG_DEBUG
, "Setting bss expiration scan count: %u",
1797 wpa_s
->conf
->bss_expiration_scan_count
= bss_expire_count
;
1804 * wpa_supplicant_set_scan_interval - Set scan interval
1805 * @wpa_s: wpa_supplicant structure for a network interface
1806 * @scan_interval: scan interval in seconds
1807 * Returns: 0 if succeed or -1 if scan_interval has an invalid value
1810 int wpa_supplicant_set_scan_interval(struct wpa_supplicant
*wpa_s
,
1813 if (scan_interval
< 0) {
1814 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid scan interval %d",
1818 wpa_msg(wpa_s
, MSG_DEBUG
, "Setting scan interval: %d sec",
1820 wpa_s
->scan_interval
= scan_interval
;
1827 * wpa_supplicant_set_debug_params - Set global debug params
1828 * @global: wpa_global structure
1829 * @debug_level: debug level
1830 * @debug_timestamp: determines if show timestamp in debug data
1831 * @debug_show_keys: determines if show keys in debug data
1832 * Returns: 0 if succeed or -1 if debug_level has wrong value
1834 int wpa_supplicant_set_debug_params(struct wpa_global
*global
, int debug_level
,
1835 int debug_timestamp
, int debug_show_keys
)
1838 int old_level
, old_timestamp
, old_show_keys
;
1840 /* check for allowed debuglevels */
1841 if (debug_level
!= MSG_EXCESSIVE
&&
1842 debug_level
!= MSG_MSGDUMP
&&
1843 debug_level
!= MSG_DEBUG
&&
1844 debug_level
!= MSG_INFO
&&
1845 debug_level
!= MSG_WARNING
&&
1846 debug_level
!= MSG_ERROR
)
1849 old_level
= wpa_debug_level
;
1850 old_timestamp
= wpa_debug_timestamp
;
1851 old_show_keys
= wpa_debug_show_keys
;
1853 wpa_debug_level
= debug_level
;
1854 wpa_debug_timestamp
= debug_timestamp
? 1 : 0;
1855 wpa_debug_show_keys
= debug_show_keys
? 1 : 0;
1857 if (wpa_debug_level
!= old_level
)
1858 wpas_notify_debug_level_changed(global
);
1859 if (wpa_debug_timestamp
!= old_timestamp
)
1860 wpas_notify_debug_timestamp_changed(global
);
1861 if (wpa_debug_show_keys
!= old_show_keys
)
1862 wpas_notify_debug_show_keys_changed(global
);
1869 * wpa_supplicant_get_ssid - Get a pointer to the current network structure
1870 * @wpa_s: Pointer to wpa_supplicant data
1871 * Returns: A pointer to the current network structure or %NULL on failure
1873 struct wpa_ssid
* wpa_supplicant_get_ssid(struct wpa_supplicant
*wpa_s
)
1875 struct wpa_ssid
*entry
;
1876 u8 ssid
[MAX_SSID_LEN
];
1882 res
= wpa_drv_get_ssid(wpa_s
, ssid
);
1884 wpa_msg(wpa_s
, MSG_WARNING
, "Could not read SSID from "
1890 if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0) {
1891 wpa_msg(wpa_s
, MSG_WARNING
, "Could not read BSSID from "
1896 wired
= wpa_s
->conf
->ap_scan
== 0 &&
1897 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
);
1899 entry
= wpa_s
->conf
->ssid
;
1901 if (!wpas_network_disabled(entry
) &&
1902 ((ssid_len
== entry
->ssid_len
&&
1903 os_memcmp(ssid
, entry
->ssid
, ssid_len
) == 0) || wired
) &&
1904 (!entry
->bssid_set
||
1905 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0))
1908 if (!wpas_network_disabled(entry
) &&
1909 (entry
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
1910 (entry
->ssid
== NULL
|| entry
->ssid_len
== 0) &&
1911 (!entry
->bssid_set
||
1912 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0))
1914 #endif /* CONFIG_WPS */
1916 if (!wpas_network_disabled(entry
) && entry
->bssid_set
&&
1917 entry
->ssid_len
== 0 &&
1918 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0)
1921 entry
= entry
->next
;
1928 static int select_driver(struct wpa_supplicant
*wpa_s
, int i
)
1930 struct wpa_global
*global
= wpa_s
->global
;
1932 if (wpa_drivers
[i
]->global_init
&& global
->drv_priv
[i
] == NULL
) {
1933 global
->drv_priv
[i
] = wpa_drivers
[i
]->global_init();
1934 if (global
->drv_priv
[i
] == NULL
) {
1935 wpa_printf(MSG_ERROR
, "Failed to initialize driver "
1936 "'%s'", wpa_drivers
[i
]->name
);
1941 wpa_s
->driver
= wpa_drivers
[i
];
1942 wpa_s
->global_drv_priv
= global
->drv_priv
[i
];
1948 static int wpa_supplicant_set_driver(struct wpa_supplicant
*wpa_s
,
1953 const char *pos
, *driver
= name
;
1958 if (wpa_drivers
[0] == NULL
) {
1959 wpa_msg(wpa_s
, MSG_ERROR
, "No driver interfaces build into "
1965 /* default to first driver in the list */
1966 return select_driver(wpa_s
, 0);
1970 pos
= os_strchr(driver
, ',');
1974 len
= os_strlen(driver
);
1976 for (i
= 0; wpa_drivers
[i
]; i
++) {
1977 if (os_strlen(wpa_drivers
[i
]->name
) == len
&&
1978 os_strncmp(driver
, wpa_drivers
[i
]->name
, len
) ==
1980 /* First driver that succeeds wins */
1981 if (select_driver(wpa_s
, i
) == 0)
1989 wpa_msg(wpa_s
, MSG_ERROR
, "Unsupported driver '%s'", name
);
1995 * wpa_supplicant_rx_eapol - Deliver a received EAPOL frame to wpa_supplicant
1996 * @ctx: Context pointer (wpa_s); this is the ctx variable registered
1997 * with struct wpa_driver_ops::init()
1998 * @src_addr: Source address of the EAPOL frame
1999 * @buf: EAPOL data starting from the EAPOL header (i.e., no Ethernet header)
2000 * @len: Length of the EAPOL data
2002 * This function is called for each received EAPOL frame. Most driver
2003 * interfaces rely on more generic OS mechanism for receiving frames through
2004 * l2_packet, but if such a mechanism is not available, the driver wrapper may
2005 * take care of received EAPOL frames and deliver them to the core supplicant
2006 * code by calling this function.
2008 void wpa_supplicant_rx_eapol(void *ctx
, const u8
*src_addr
,
2009 const u8
*buf
, size_t len
)
2011 struct wpa_supplicant
*wpa_s
= ctx
;
2013 wpa_dbg(wpa_s
, MSG_DEBUG
, "RX EAPOL from " MACSTR
, MAC2STR(src_addr
));
2014 wpa_hexdump(MSG_MSGDUMP
, "RX EAPOL", buf
, len
);
2016 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
) {
2018 * There is possible race condition between receiving the
2019 * association event and the EAPOL frame since they are coming
2020 * through different paths from the driver. In order to avoid
2021 * issues in trying to process the EAPOL frame before receiving
2022 * association information, lets queue it for processing until
2023 * the association event is received.
2025 wpa_dbg(wpa_s
, MSG_DEBUG
, "Not associated - Delay processing "
2026 "of received EAPOL frame");
2027 wpabuf_free(wpa_s
->pending_eapol_rx
);
2028 wpa_s
->pending_eapol_rx
= wpabuf_alloc_copy(buf
, len
);
2029 if (wpa_s
->pending_eapol_rx
) {
2030 os_get_time(&wpa_s
->pending_eapol_rx_time
);
2031 os_memcpy(wpa_s
->pending_eapol_rx_src
, src_addr
,
2038 if (wpa_s
->ap_iface
) {
2039 wpa_supplicant_ap_rx_eapol(wpa_s
, src_addr
, buf
, len
);
2042 #endif /* CONFIG_AP */
2044 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
) {
2045 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignored received EAPOL frame since "
2046 "no key management is configured");
2050 if (wpa_s
->eapol_received
== 0 &&
2051 (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) ||
2052 !wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
2053 wpa_s
->wpa_state
!= WPA_COMPLETED
) &&
2054 (wpa_s
->current_ssid
== NULL
||
2055 wpa_s
->current_ssid
->mode
!= IEEE80211_MODE_IBSS
)) {
2056 /* Timeout for completing IEEE 802.1X and WPA authentication */
2057 wpa_supplicant_req_auth_timeout(
2059 (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
2060 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
||
2061 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
) ?
2064 wpa_s
->eapol_received
++;
2066 if (wpa_s
->countermeasures
) {
2067 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Countermeasures - dropped "
2072 #ifdef CONFIG_IBSS_RSN
2073 if (wpa_s
->current_ssid
&&
2074 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
) {
2075 ibss_rsn_rx_eapol(wpa_s
->ibss_rsn
, src_addr
, buf
, len
);
2078 #endif /* CONFIG_IBSS_RSN */
2080 /* Source address of the incoming EAPOL frame could be compared to the
2081 * current BSSID. However, it is possible that a centralized
2082 * Authenticator could be using another MAC address than the BSSID of
2083 * an AP, so just allow any address to be used for now. The replies are
2084 * still sent to the current BSSID (if available), though. */
2086 os_memcpy(wpa_s
->last_eapol_src
, src_addr
, ETH_ALEN
);
2087 if (!wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) &&
2088 eapol_sm_rx_eapol(wpa_s
->eapol
, src_addr
, buf
, len
) > 0)
2090 wpa_drv_poll(wpa_s
);
2091 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
))
2092 wpa_sm_rx_eapol(wpa_s
->wpa
, src_addr
, buf
, len
);
2093 else if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2095 * Set portValid = TRUE here since we are going to skip 4-way
2096 * handshake processing which would normally set portValid. We
2097 * need this to allow the EAPOL state machines to be completed
2098 * without going through EAPOL-Key handshake.
2100 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
2105 int wpa_supplicant_update_mac_addr(struct wpa_supplicant
*wpa_s
)
2107 if (wpa_s
->driver
->send_eapol
) {
2108 const u8
*addr
= wpa_drv_get_mac_addr(wpa_s
);
2110 os_memcpy(wpa_s
->own_addr
, addr
, ETH_ALEN
);
2111 } else if (!(wpa_s
->drv_flags
&
2112 WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE
)) {
2113 l2_packet_deinit(wpa_s
->l2
);
2114 wpa_s
->l2
= l2_packet_init(wpa_s
->ifname
,
2115 wpa_drv_get_mac_addr(wpa_s
),
2117 wpa_supplicant_rx_eapol
, wpa_s
, 0);
2118 if (wpa_s
->l2
== NULL
)
2121 const u8
*addr
= wpa_drv_get_mac_addr(wpa_s
);
2123 os_memcpy(wpa_s
->own_addr
, addr
, ETH_ALEN
);
2126 if (wpa_s
->l2
&& l2_packet_get_own_addr(wpa_s
->l2
, wpa_s
->own_addr
)) {
2127 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to get own L2 address");
2131 wpa_dbg(wpa_s
, MSG_DEBUG
, "Own MAC address: " MACSTR
,
2132 MAC2STR(wpa_s
->own_addr
));
2133 wpa_sm_set_own_addr(wpa_s
->wpa
, wpa_s
->own_addr
);
2139 static void wpa_supplicant_rx_eapol_bridge(void *ctx
, const u8
*src_addr
,
2140 const u8
*buf
, size_t len
)
2142 struct wpa_supplicant
*wpa_s
= ctx
;
2143 const struct l2_ethhdr
*eth
;
2145 if (len
< sizeof(*eth
))
2147 eth
= (const struct l2_ethhdr
*) buf
;
2149 if (os_memcmp(eth
->h_dest
, wpa_s
->own_addr
, ETH_ALEN
) != 0 &&
2150 !(eth
->h_dest
[0] & 0x01)) {
2151 wpa_dbg(wpa_s
, MSG_DEBUG
, "RX EAPOL from " MACSTR
" to " MACSTR
2152 " (bridge - not for this interface - ignore)",
2153 MAC2STR(src_addr
), MAC2STR(eth
->h_dest
));
2157 wpa_dbg(wpa_s
, MSG_DEBUG
, "RX EAPOL from " MACSTR
" to " MACSTR
2158 " (bridge)", MAC2STR(src_addr
), MAC2STR(eth
->h_dest
));
2159 wpa_supplicant_rx_eapol(wpa_s
, src_addr
, buf
+ sizeof(*eth
),
2160 len
- sizeof(*eth
));
2165 * wpa_supplicant_driver_init - Initialize driver interface parameters
2166 * @wpa_s: Pointer to wpa_supplicant data
2167 * Returns: 0 on success, -1 on failure
2169 * This function is called to initialize driver interface parameters.
2170 * wpa_drv_init() must have been called before this function to initialize the
2173 int wpa_supplicant_driver_init(struct wpa_supplicant
*wpa_s
)
2175 static int interface_count
= 0;
2177 if (wpa_supplicant_update_mac_addr(wpa_s
) < 0)
2180 if (wpa_s
->bridge_ifname
[0]) {
2181 wpa_dbg(wpa_s
, MSG_DEBUG
, "Receiving packets from bridge "
2182 "interface '%s'", wpa_s
->bridge_ifname
);
2183 wpa_s
->l2_br
= l2_packet_init(wpa_s
->bridge_ifname
,
2186 wpa_supplicant_rx_eapol_bridge
,
2188 if (wpa_s
->l2_br
== NULL
) {
2189 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to open l2_packet "
2190 "connection for the bridge interface '%s'",
2191 wpa_s
->bridge_ifname
);
2196 wpa_clear_keys(wpa_s
, NULL
);
2198 /* Make sure that TKIP countermeasures are not left enabled (could
2199 * happen if wpa_supplicant is killed during countermeasures. */
2200 wpa_drv_set_countermeasures(wpa_s
, 0);
2202 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: flushing PMKID list in the driver");
2203 wpa_drv_flush_pmkid(wpa_s
);
2205 wpa_s
->prev_scan_ssid
= WILDCARD_SSID_SCAN
;
2206 wpa_s
->prev_scan_wildcard
= 0;
2208 if (wpa_supplicant_enabled_networks(wpa_s
->conf
)) {
2209 if (wpa_supplicant_delayed_sched_scan(wpa_s
, interface_count
,
2211 wpa_supplicant_req_scan(wpa_s
, interface_count
,
2215 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
2221 static int wpa_supplicant_daemon(const char *pid_file
)
2223 wpa_printf(MSG_DEBUG
, "Daemonize..");
2224 return os_daemonize(pid_file
);
2228 static struct wpa_supplicant
* wpa_supplicant_alloc(void)
2230 struct wpa_supplicant
*wpa_s
;
2232 wpa_s
= os_zalloc(sizeof(*wpa_s
));
2235 wpa_s
->scan_req
= 1;
2236 wpa_s
->scan_interval
= 5;
2237 wpa_s
->new_connection
= 1;
2238 wpa_s
->parent
= wpa_s
;
2239 wpa_s
->sched_scanning
= 0;
2245 #ifdef CONFIG_HT_OVERRIDES
2247 static int wpa_set_htcap_mcs(struct wpa_supplicant
*wpa_s
,
2248 struct ieee80211_ht_capabilities
*htcaps
,
2249 struct ieee80211_ht_capabilities
*htcaps_mask
,
2252 /* parse ht_mcs into hex array */
2254 const char *tmp
= ht_mcs
;
2257 /* If ht_mcs is null, do not set anything */
2261 /* This is what we are setting in the kernel */
2262 os_memset(&htcaps
->supported_mcs_set
, 0, IEEE80211_HT_MCS_MASK_LEN
);
2264 wpa_msg(wpa_s
, MSG_DEBUG
, "set_htcap, ht_mcs -:%s:-", ht_mcs
);
2266 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++) {
2268 long v
= strtol(tmp
, &end
, 16);
2270 wpa_msg(wpa_s
, MSG_DEBUG
,
2271 "htcap value[%i]: %ld end: %p tmp: %p",
2276 htcaps
->supported_mcs_set
[i
] = v
;
2279 wpa_msg(wpa_s
, MSG_ERROR
,
2280 "Failed to parse ht-mcs: %s, error: %s\n",
2281 ht_mcs
, strerror(errno
));
2287 * If we were able to parse any values, then set mask for the MCS set.
2290 os_memset(&htcaps_mask
->supported_mcs_set
, 0xff,
2291 IEEE80211_HT_MCS_MASK_LEN
- 1);
2292 /* skip the 3 reserved bits */
2293 htcaps_mask
->supported_mcs_set
[IEEE80211_HT_MCS_MASK_LEN
- 1] =
2301 static int wpa_disable_max_amsdu(struct wpa_supplicant
*wpa_s
,
2302 struct ieee80211_ht_capabilities
*htcaps
,
2303 struct ieee80211_ht_capabilities
*htcaps_mask
,
2308 wpa_msg(wpa_s
, MSG_DEBUG
, "set_disable_max_amsdu: %d", disabled
);
2313 msk
= host_to_le16(HT_CAP_INFO_MAX_AMSDU_SIZE
);
2314 htcaps_mask
->ht_capabilities_info
|= msk
;
2316 htcaps
->ht_capabilities_info
&= msk
;
2318 htcaps
->ht_capabilities_info
|= msk
;
2324 static int wpa_set_ampdu_factor(struct wpa_supplicant
*wpa_s
,
2325 struct ieee80211_ht_capabilities
*htcaps
,
2326 struct ieee80211_ht_capabilities
*htcaps_mask
,
2329 wpa_msg(wpa_s
, MSG_DEBUG
, "set_ampdu_factor: %d", factor
);
2334 if (factor
< 0 || factor
> 3) {
2335 wpa_msg(wpa_s
, MSG_ERROR
, "ampdu_factor: %d out of range. "
2336 "Must be 0-3 or -1", factor
);
2340 htcaps_mask
->a_mpdu_params
|= 0x3; /* 2 bits for factor */
2341 htcaps
->a_mpdu_params
&= ~0x3;
2342 htcaps
->a_mpdu_params
|= factor
& 0x3;
2348 static int wpa_set_ampdu_density(struct wpa_supplicant
*wpa_s
,
2349 struct ieee80211_ht_capabilities
*htcaps
,
2350 struct ieee80211_ht_capabilities
*htcaps_mask
,
2353 wpa_msg(wpa_s
, MSG_DEBUG
, "set_ampdu_density: %d", density
);
2358 if (density
< 0 || density
> 7) {
2359 wpa_msg(wpa_s
, MSG_ERROR
,
2360 "ampdu_density: %d out of range. Must be 0-7 or -1.",
2365 htcaps_mask
->a_mpdu_params
|= 0x1C;
2366 htcaps
->a_mpdu_params
&= ~(0x1C);
2367 htcaps
->a_mpdu_params
|= (density
<< 2) & 0x1C;
2373 static int wpa_set_disable_ht40(struct wpa_supplicant
*wpa_s
,
2374 struct ieee80211_ht_capabilities
*htcaps
,
2375 struct ieee80211_ht_capabilities
*htcaps_mask
,
2378 /* Masking these out disables HT40 */
2379 u16 msk
= host_to_le16(HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
|
2380 HT_CAP_INFO_SHORT_GI40MHZ
);
2382 wpa_msg(wpa_s
, MSG_DEBUG
, "set_disable_ht40: %d", disabled
);
2385 htcaps
->ht_capabilities_info
&= ~msk
;
2387 htcaps
->ht_capabilities_info
|= msk
;
2389 htcaps_mask
->ht_capabilities_info
|= msk
;
2395 void wpa_supplicant_apply_ht_overrides(
2396 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
2397 struct wpa_driver_associate_params
*params
)
2399 struct ieee80211_ht_capabilities
*htcaps
;
2400 struct ieee80211_ht_capabilities
*htcaps_mask
;
2405 params
->disable_ht
= ssid
->disable_ht
;
2406 if (!params
->htcaps
|| !params
->htcaps_mask
)
2409 htcaps
= (struct ieee80211_ht_capabilities
*) params
->htcaps
;
2410 htcaps_mask
= (struct ieee80211_ht_capabilities
*) params
->htcaps_mask
;
2411 wpa_set_htcap_mcs(wpa_s
, htcaps
, htcaps_mask
, ssid
->ht_mcs
);
2412 wpa_disable_max_amsdu(wpa_s
, htcaps
, htcaps_mask
,
2413 ssid
->disable_max_amsdu
);
2414 wpa_set_ampdu_factor(wpa_s
, htcaps
, htcaps_mask
, ssid
->ampdu_factor
);
2415 wpa_set_ampdu_density(wpa_s
, htcaps
, htcaps_mask
, ssid
->ampdu_density
);
2416 wpa_set_disable_ht40(wpa_s
, htcaps
, htcaps_mask
, ssid
->disable_ht40
);
2419 #endif /* CONFIG_HT_OVERRIDES */
2422 static int pcsc_reader_init(struct wpa_supplicant
*wpa_s
)
2427 if (!wpa_s
->conf
->pcsc_reader
)
2430 wpa_s
->scard
= scard_init(SCARD_TRY_BOTH
, wpa_s
->conf
->pcsc_reader
);
2434 if (wpa_s
->conf
->pcsc_pin
&&
2435 scard_set_pin(wpa_s
->scard
, wpa_s
->conf
->pcsc_pin
) < 0) {
2436 scard_deinit(wpa_s
->scard
);
2437 wpa_s
->scard
= NULL
;
2438 wpa_msg(wpa_s
, MSG_ERROR
, "PC/SC PIN validation failed");
2442 len
= sizeof(wpa_s
->imsi
) - 1;
2443 if (scard_get_imsi(wpa_s
->scard
, wpa_s
->imsi
, &len
)) {
2444 scard_deinit(wpa_s
->scard
);
2445 wpa_s
->scard
= NULL
;
2446 wpa_msg(wpa_s
, MSG_ERROR
, "Could not read IMSI");
2449 wpa_s
->imsi
[len
] = '\0';
2451 wpa_s
->mnc_len
= scard_get_mnc_len(wpa_s
->scard
);
2453 wpa_printf(MSG_DEBUG
, "SCARD: IMSI %s (MNC length %d)",
2454 wpa_s
->imsi
, wpa_s
->mnc_len
);
2456 wpa_sm_set_scard_ctx(wpa_s
->wpa
, wpa_s
->scard
);
2457 eapol_sm_register_scard_ctx(wpa_s
->eapol
, wpa_s
->scard
);
2458 #endif /* PCSC_FUNCS */
2464 static int wpa_supplicant_init_iface(struct wpa_supplicant
*wpa_s
,
2465 struct wpa_interface
*iface
)
2467 const char *ifname
, *driver
;
2468 struct wpa_driver_capa capa
;
2470 wpa_printf(MSG_DEBUG
, "Initializing interface '%s' conf '%s' driver "
2471 "'%s' ctrl_interface '%s' bridge '%s'", iface
->ifname
,
2472 iface
->confname
? iface
->confname
: "N/A",
2473 iface
->driver
? iface
->driver
: "default",
2474 iface
->ctrl_interface
? iface
->ctrl_interface
: "N/A",
2475 iface
->bridge_ifname
? iface
->bridge_ifname
: "N/A");
2477 if (iface
->confname
) {
2478 #ifdef CONFIG_BACKEND_FILE
2479 wpa_s
->confname
= os_rel2abs_path(iface
->confname
);
2480 if (wpa_s
->confname
== NULL
) {
2481 wpa_printf(MSG_ERROR
, "Failed to get absolute path "
2482 "for configuration file '%s'.",
2486 wpa_printf(MSG_DEBUG
, "Configuration file '%s' -> '%s'",
2487 iface
->confname
, wpa_s
->confname
);
2488 #else /* CONFIG_BACKEND_FILE */
2489 wpa_s
->confname
= os_strdup(iface
->confname
);
2490 #endif /* CONFIG_BACKEND_FILE */
2491 wpa_s
->conf
= wpa_config_read(wpa_s
->confname
);
2492 if (wpa_s
->conf
== NULL
) {
2493 wpa_printf(MSG_ERROR
, "Failed to read or parse "
2494 "configuration '%s'.", wpa_s
->confname
);
2499 * Override ctrl_interface and driver_param if set on command
2502 if (iface
->ctrl_interface
) {
2503 os_free(wpa_s
->conf
->ctrl_interface
);
2504 wpa_s
->conf
->ctrl_interface
=
2505 os_strdup(iface
->ctrl_interface
);
2508 if (iface
->driver_param
) {
2509 os_free(wpa_s
->conf
->driver_param
);
2510 wpa_s
->conf
->driver_param
=
2511 os_strdup(iface
->driver_param
);
2514 wpa_s
->conf
= wpa_config_alloc_empty(iface
->ctrl_interface
,
2515 iface
->driver_param
);
2517 if (wpa_s
->conf
== NULL
) {
2518 wpa_printf(MSG_ERROR
, "\nNo configuration found.");
2522 if (iface
->ifname
== NULL
) {
2523 wpa_printf(MSG_ERROR
, "\nInterface name is required.");
2526 if (os_strlen(iface
->ifname
) >= sizeof(wpa_s
->ifname
)) {
2527 wpa_printf(MSG_ERROR
, "\nToo long interface name '%s'.",
2531 os_strlcpy(wpa_s
->ifname
, iface
->ifname
, sizeof(wpa_s
->ifname
));
2533 if (iface
->bridge_ifname
) {
2534 if (os_strlen(iface
->bridge_ifname
) >=
2535 sizeof(wpa_s
->bridge_ifname
)) {
2536 wpa_printf(MSG_ERROR
, "\nToo long bridge interface "
2537 "name '%s'.", iface
->bridge_ifname
);
2540 os_strlcpy(wpa_s
->bridge_ifname
, iface
->bridge_ifname
,
2541 sizeof(wpa_s
->bridge_ifname
));
2544 /* RSNA Supplicant Key Management - INITIALIZE */
2545 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
2546 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
2548 /* Initialize driver interface and register driver event handler before
2549 * L2 receive handler so that association events are processed before
2550 * EAPOL-Key packets if both become available for the same select()
2552 driver
= iface
->driver
;
2554 if (wpa_supplicant_set_driver(wpa_s
, driver
) < 0)
2557 wpa_s
->drv_priv
= wpa_drv_init(wpa_s
, wpa_s
->ifname
);
2558 if (wpa_s
->drv_priv
== NULL
) {
2560 pos
= driver
? os_strchr(driver
, ',') : NULL
;
2562 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to initialize "
2563 "driver interface - try next driver wrapper");
2567 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to initialize driver "
2571 if (wpa_drv_set_param(wpa_s
, wpa_s
->conf
->driver_param
) < 0) {
2572 wpa_msg(wpa_s
, MSG_ERROR
, "Driver interface rejected "
2573 "driver_param '%s'", wpa_s
->conf
->driver_param
);
2577 ifname
= wpa_drv_get_ifname(wpa_s
);
2578 if (ifname
&& os_strcmp(ifname
, wpa_s
->ifname
) != 0) {
2579 wpa_dbg(wpa_s
, MSG_DEBUG
, "Driver interface replaced "
2580 "interface name with '%s'", ifname
);
2581 os_strlcpy(wpa_s
->ifname
, ifname
, sizeof(wpa_s
->ifname
));
2584 if (wpa_supplicant_init_wpa(wpa_s
) < 0)
2587 wpa_sm_set_ifname(wpa_s
->wpa
, wpa_s
->ifname
,
2588 wpa_s
->bridge_ifname
[0] ? wpa_s
->bridge_ifname
:
2590 wpa_sm_set_fast_reauth(wpa_s
->wpa
, wpa_s
->conf
->fast_reauth
);
2592 if (wpa_s
->conf
->dot11RSNAConfigPMKLifetime
&&
2593 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
2594 wpa_s
->conf
->dot11RSNAConfigPMKLifetime
)) {
2595 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid WPA parameter value for "
2596 "dot11RSNAConfigPMKLifetime");
2600 if (wpa_s
->conf
->dot11RSNAConfigPMKReauthThreshold
&&
2601 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
2602 wpa_s
->conf
->dot11RSNAConfigPMKReauthThreshold
)) {
2603 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid WPA parameter value for "
2604 "dot11RSNAConfigPMKReauthThreshold");
2608 if (wpa_s
->conf
->dot11RSNAConfigSATimeout
&&
2609 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
,
2610 wpa_s
->conf
->dot11RSNAConfigSATimeout
)) {
2611 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid WPA parameter value for "
2612 "dot11RSNAConfigSATimeout");
2616 wpa_s
->hw
.modes
= wpa_drv_get_hw_feature_data(wpa_s
,
2617 &wpa_s
->hw
.num_modes
,
2620 if (wpa_drv_get_capa(wpa_s
, &capa
) == 0) {
2621 wpa_s
->drv_capa_known
= 1;
2622 wpa_s
->drv_flags
= capa
.flags
;
2623 wpa_s
->probe_resp_offloads
= capa
.probe_resp_offloads
;
2624 wpa_s
->max_scan_ssids
= capa
.max_scan_ssids
;
2625 wpa_s
->max_sched_scan_ssids
= capa
.max_sched_scan_ssids
;
2626 wpa_s
->sched_scan_supported
= capa
.sched_scan_supported
;
2627 wpa_s
->max_match_sets
= capa
.max_match_sets
;
2628 wpa_s
->max_remain_on_chan
= capa
.max_remain_on_chan
;
2629 wpa_s
->max_stations
= capa
.max_stations
;
2631 if (wpa_s
->max_remain_on_chan
== 0)
2632 wpa_s
->max_remain_on_chan
= 1000;
2634 if (wpa_supplicant_driver_init(wpa_s
) < 0)
2638 if (wpa_tdls_init(wpa_s
->wpa
))
2640 #endif /* CONFIG_TDLS */
2642 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1] &&
2643 wpa_drv_set_country(wpa_s
, wpa_s
->conf
->country
)) {
2644 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to set country");
2648 if (wpas_wps_init(wpa_s
))
2651 if (wpa_supplicant_init_eapol(wpa_s
) < 0)
2653 wpa_sm_set_eapol(wpa_s
->wpa
, wpa_s
->eapol
);
2655 wpa_s
->ctrl_iface
= wpa_supplicant_ctrl_iface_init(wpa_s
);
2656 if (wpa_s
->ctrl_iface
== NULL
) {
2657 wpa_printf(MSG_ERROR
,
2658 "Failed to initialize control interface '%s'.\n"
2659 "You may have another wpa_supplicant process "
2660 "already running or the file was\n"
2661 "left by an unclean termination of wpa_supplicant "
2662 "in which case you will need\n"
2663 "to manually remove this file before starting "
2664 "wpa_supplicant again.\n",
2665 wpa_s
->conf
->ctrl_interface
);
2669 wpa_s
->gas
= gas_query_init(wpa_s
);
2670 if (wpa_s
->gas
== NULL
) {
2671 wpa_printf(MSG_ERROR
, "Failed to initialize GAS query");
2676 if (wpas_p2p_init(wpa_s
->global
, wpa_s
) < 0) {
2677 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to init P2P");
2680 #endif /* CONFIG_P2P */
2682 if (wpa_bss_init(wpa_s
) < 0)
2685 if (pcsc_reader_init(wpa_s
) < 0)
2692 static void wpa_supplicant_deinit_iface(struct wpa_supplicant
*wpa_s
,
2693 int notify
, int terminate
)
2695 if (wpa_s
->drv_priv
) {
2696 wpa_supplicant_deauthenticate(wpa_s
,
2697 WLAN_REASON_DEAUTH_LEAVING
);
2699 wpa_drv_set_countermeasures(wpa_s
, 0);
2700 wpa_clear_keys(wpa_s
, NULL
);
2703 wpa_supplicant_cleanup(wpa_s
);
2705 if (wpa_s
->drv_priv
)
2706 wpa_drv_deinit(wpa_s
);
2709 wpas_notify_iface_removed(wpa_s
);
2712 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_TERMINATING
);
2714 if (wpa_s
->ctrl_iface
) {
2715 wpa_supplicant_ctrl_iface_deinit(wpa_s
->ctrl_iface
);
2716 wpa_s
->ctrl_iface
= NULL
;
2719 if (wpa_s
->conf
!= NULL
) {
2720 wpa_config_free(wpa_s
->conf
);
2727 * wpa_supplicant_add_iface - Add a new network interface
2728 * @global: Pointer to global data from wpa_supplicant_init()
2729 * @iface: Interface configuration options
2730 * Returns: Pointer to the created interface or %NULL on failure
2732 * This function is used to add new network interfaces for %wpa_supplicant.
2733 * This can be called before wpa_supplicant_run() to add interfaces before the
2734 * main event loop has been started. In addition, new interfaces can be added
2735 * dynamically while %wpa_supplicant is already running. This could happen,
2736 * e.g., when a hotplug network adapter is inserted.
2738 struct wpa_supplicant
* wpa_supplicant_add_iface(struct wpa_global
*global
,
2739 struct wpa_interface
*iface
)
2741 struct wpa_supplicant
*wpa_s
;
2742 struct wpa_interface t_iface
;
2743 struct wpa_ssid
*ssid
;
2745 if (global
== NULL
|| iface
== NULL
)
2748 wpa_s
= wpa_supplicant_alloc();
2752 wpa_s
->global
= global
;
2755 if (global
->params
.override_driver
) {
2756 wpa_printf(MSG_DEBUG
, "Override interface parameter: driver "
2758 iface
->driver
, global
->params
.override_driver
);
2759 t_iface
.driver
= global
->params
.override_driver
;
2761 if (global
->params
.override_ctrl_interface
) {
2762 wpa_printf(MSG_DEBUG
, "Override interface parameter: "
2763 "ctrl_interface ('%s' -> '%s')",
2764 iface
->ctrl_interface
,
2765 global
->params
.override_ctrl_interface
);
2766 t_iface
.ctrl_interface
=
2767 global
->params
.override_ctrl_interface
;
2769 if (wpa_supplicant_init_iface(wpa_s
, &t_iface
)) {
2770 wpa_printf(MSG_DEBUG
, "Failed to add interface %s",
2772 wpa_supplicant_deinit_iface(wpa_s
, 0, 0);
2777 /* Notify the control interfaces about new iface */
2778 if (wpas_notify_iface_added(wpa_s
)) {
2779 wpa_supplicant_deinit_iface(wpa_s
, 1, 0);
2784 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
)
2785 wpas_notify_network_added(wpa_s
, ssid
);
2787 wpa_s
->next
= global
->ifaces
;
2788 global
->ifaces
= wpa_s
;
2790 wpa_dbg(wpa_s
, MSG_DEBUG
, "Added interface %s", wpa_s
->ifname
);
2797 * wpa_supplicant_remove_iface - Remove a network interface
2798 * @global: Pointer to global data from wpa_supplicant_init()
2799 * @wpa_s: Pointer to the network interface to be removed
2800 * Returns: 0 if interface was removed, -1 if interface was not found
2802 * This function can be used to dynamically remove network interfaces from
2803 * %wpa_supplicant, e.g., when a hotplug network adapter is ejected. In
2804 * addition, this function is used to remove all remaining interfaces when
2805 * %wpa_supplicant is terminated.
2807 int wpa_supplicant_remove_iface(struct wpa_global
*global
,
2808 struct wpa_supplicant
*wpa_s
,
2811 struct wpa_supplicant
*prev
;
2813 /* Remove interface from the global list of interfaces */
2814 prev
= global
->ifaces
;
2815 if (prev
== wpa_s
) {
2816 global
->ifaces
= wpa_s
->next
;
2818 while (prev
&& prev
->next
!= wpa_s
)
2822 prev
->next
= wpa_s
->next
;
2825 wpa_dbg(wpa_s
, MSG_DEBUG
, "Removing interface %s", wpa_s
->ifname
);
2827 if (global
->p2p_group_formation
== wpa_s
)
2828 global
->p2p_group_formation
= NULL
;
2829 wpa_supplicant_deinit_iface(wpa_s
, 1, terminate
);
2837 * wpa_supplicant_get_eap_mode - Get the current EAP mode
2838 * @wpa_s: Pointer to the network interface
2839 * Returns: Pointer to the eap mode or the string "UNKNOWN" if not found
2841 const char * wpa_supplicant_get_eap_mode(struct wpa_supplicant
*wpa_s
)
2843 const char *eapol_method
;
2845 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) == 0 &&
2846 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
2850 eapol_method
= eapol_sm_get_method_name(wpa_s
->eapol
);
2851 if (eapol_method
== NULL
)
2852 return "UNKNOWN-EAP";
2854 return eapol_method
;
2859 * wpa_supplicant_get_iface - Get a new network interface
2860 * @global: Pointer to global data from wpa_supplicant_init()
2861 * @ifname: Interface name
2862 * Returns: Pointer to the interface or %NULL if not found
2864 struct wpa_supplicant
* wpa_supplicant_get_iface(struct wpa_global
*global
,
2867 struct wpa_supplicant
*wpa_s
;
2869 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2870 if (os_strcmp(wpa_s
->ifname
, ifname
) == 0)
2877 #ifndef CONFIG_NO_WPA_MSG
2878 static const char * wpa_supplicant_msg_ifname_cb(void *ctx
)
2880 struct wpa_supplicant
*wpa_s
= ctx
;
2883 return wpa_s
->ifname
;
2885 #endif /* CONFIG_NO_WPA_MSG */
2889 * wpa_supplicant_init - Initialize %wpa_supplicant
2890 * @params: Parameters for %wpa_supplicant
2891 * Returns: Pointer to global %wpa_supplicant data, or %NULL on failure
2893 * This function is used to initialize %wpa_supplicant. After successful
2894 * initialization, the returned data pointer can be used to add and remove
2895 * network interfaces, and eventually, to deinitialize %wpa_supplicant.
2897 struct wpa_global
* wpa_supplicant_init(struct wpa_params
*params
)
2899 struct wpa_global
*global
;
2905 #ifdef CONFIG_DRIVER_NDIS
2907 void driver_ndis_init_ops(void);
2908 driver_ndis_init_ops();
2910 #endif /* CONFIG_DRIVER_NDIS */
2912 #ifndef CONFIG_NO_WPA_MSG
2913 wpa_msg_register_ifname_cb(wpa_supplicant_msg_ifname_cb
);
2914 #endif /* CONFIG_NO_WPA_MSG */
2916 wpa_debug_open_file(params
->wpa_debug_file_path
);
2917 if (params
->wpa_debug_syslog
)
2918 wpa_debug_open_syslog();
2919 if (params
->wpa_debug_tracing
) {
2920 ret
= wpa_debug_open_linux_tracing();
2922 wpa_printf(MSG_ERROR
,
2923 "Failed to enable trace logging");
2928 ret
= eap_register_methods();
2930 wpa_printf(MSG_ERROR
, "Failed to register EAP methods");
2932 wpa_printf(MSG_ERROR
, "Two or more EAP methods used "
2933 "the same EAP type.");
2937 global
= os_zalloc(sizeof(*global
));
2940 dl_list_init(&global
->p2p_srv_bonjour
);
2941 dl_list_init(&global
->p2p_srv_upnp
);
2942 global
->params
.daemonize
= params
->daemonize
;
2943 global
->params
.wait_for_monitor
= params
->wait_for_monitor
;
2944 global
->params
.dbus_ctrl_interface
= params
->dbus_ctrl_interface
;
2945 if (params
->pid_file
)
2946 global
->params
.pid_file
= os_strdup(params
->pid_file
);
2947 if (params
->ctrl_interface
)
2948 global
->params
.ctrl_interface
=
2949 os_strdup(params
->ctrl_interface
);
2950 if (params
->override_driver
)
2951 global
->params
.override_driver
=
2952 os_strdup(params
->override_driver
);
2953 if (params
->override_ctrl_interface
)
2954 global
->params
.override_ctrl_interface
=
2955 os_strdup(params
->override_ctrl_interface
);
2956 wpa_debug_level
= global
->params
.wpa_debug_level
=
2957 params
->wpa_debug_level
;
2958 wpa_debug_show_keys
= global
->params
.wpa_debug_show_keys
=
2959 params
->wpa_debug_show_keys
;
2960 wpa_debug_timestamp
= global
->params
.wpa_debug_timestamp
=
2961 params
->wpa_debug_timestamp
;
2963 wpa_printf(MSG_DEBUG
, "wpa_supplicant v" VERSION_STR
);
2966 wpa_printf(MSG_ERROR
, "Failed to initialize event loop");
2967 wpa_supplicant_deinit(global
);
2971 random_init(params
->entropy_file
);
2973 global
->ctrl_iface
= wpa_supplicant_global_ctrl_iface_init(global
);
2974 if (global
->ctrl_iface
== NULL
) {
2975 wpa_supplicant_deinit(global
);
2979 if (wpas_notify_supplicant_initialized(global
)) {
2980 wpa_supplicant_deinit(global
);
2984 for (i
= 0; wpa_drivers
[i
]; i
++)
2985 global
->drv_count
++;
2986 if (global
->drv_count
== 0) {
2987 wpa_printf(MSG_ERROR
, "No drivers enabled");
2988 wpa_supplicant_deinit(global
);
2991 global
->drv_priv
= os_zalloc(global
->drv_count
* sizeof(void *));
2992 if (global
->drv_priv
== NULL
) {
2993 wpa_supplicant_deinit(global
);
3002 * wpa_supplicant_run - Run the %wpa_supplicant main event loop
3003 * @global: Pointer to global data from wpa_supplicant_init()
3004 * Returns: 0 after successful event loop run, -1 on failure
3006 * This function starts the main event loop and continues running as long as
3007 * there are any remaining events. In most cases, this function is running as
3008 * long as the %wpa_supplicant process in still in use.
3010 int wpa_supplicant_run(struct wpa_global
*global
)
3012 struct wpa_supplicant
*wpa_s
;
3014 if (global
->params
.daemonize
&&
3015 wpa_supplicant_daemon(global
->params
.pid_file
))
3018 if (global
->params
.wait_for_monitor
) {
3019 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
)
3020 if (wpa_s
->ctrl_iface
)
3021 wpa_supplicant_ctrl_iface_wait(
3025 eloop_register_signal_terminate(wpa_supplicant_terminate
, global
);
3026 eloop_register_signal_reconfig(wpa_supplicant_reconfig
, global
);
3035 * wpa_supplicant_deinit - Deinitialize %wpa_supplicant
3036 * @global: Pointer to global data from wpa_supplicant_init()
3038 * This function is called to deinitialize %wpa_supplicant and to free all
3039 * allocated resources. Remaining network interfaces will also be removed.
3041 void wpa_supplicant_deinit(struct wpa_global
*global
)
3049 wpas_p2p_deinit_global(global
);
3050 #endif /* CONFIG_P2P */
3052 while (global
->ifaces
)
3053 wpa_supplicant_remove_iface(global
, global
->ifaces
, 1);
3055 if (global
->ctrl_iface
)
3056 wpa_supplicant_global_ctrl_iface_deinit(global
->ctrl_iface
);
3058 wpas_notify_supplicant_deinitialized(global
);
3060 eap_peer_unregister_methods();
3062 eap_server_unregister_methods();
3063 #endif /* CONFIG_AP */
3065 for (i
= 0; wpa_drivers
[i
] && global
->drv_priv
; i
++) {
3066 if (!global
->drv_priv
[i
])
3068 wpa_drivers
[i
]->global_deinit(global
->drv_priv
[i
]);
3070 os_free(global
->drv_priv
);
3076 if (global
->params
.pid_file
) {
3077 os_daemonize_terminate(global
->params
.pid_file
);
3078 os_free(global
->params
.pid_file
);
3080 os_free(global
->params
.ctrl_interface
);
3081 os_free(global
->params
.override_driver
);
3082 os_free(global
->params
.override_ctrl_interface
);
3084 os_free(global
->p2p_disallow_freq
);
3087 wpa_debug_close_syslog();
3088 wpa_debug_close_file();
3089 wpa_debug_close_linux_tracing();
3093 void wpa_supplicant_update_config(struct wpa_supplicant
*wpa_s
)
3095 if ((wpa_s
->conf
->changed_parameters
& CFG_CHANGED_COUNTRY
) &&
3096 wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1]) {
3098 country
[0] = wpa_s
->conf
->country
[0];
3099 country
[1] = wpa_s
->conf
->country
[1];
3101 if (wpa_drv_set_country(wpa_s
, country
) < 0) {
3102 wpa_printf(MSG_ERROR
, "Failed to set country code "
3108 wpas_wps_update_config(wpa_s
);
3109 #endif /* CONFIG_WPS */
3112 wpas_p2p_update_config(wpa_s
);
3113 #endif /* CONFIG_P2P */
3115 wpa_s
->conf
->changed_parameters
= 0;
3119 static void add_freq(int *freqs
, int *num_freqs
, int freq
)
3123 for (i
= 0; i
< *num_freqs
; i
++) {
3124 if (freqs
[i
] == freq
)
3128 freqs
[*num_freqs
] = freq
;
3133 static int * get_bss_freqs_in_ess(struct wpa_supplicant
*wpa_s
)
3135 struct wpa_bss
*bss
, *cbss
;
3136 const int max_freqs
= 10;
3140 freqs
= os_zalloc(sizeof(int) * (max_freqs
+ 1));
3144 cbss
= wpa_s
->current_bss
;
3146 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
3149 if (bss
->ssid_len
== cbss
->ssid_len
&&
3150 os_memcmp(bss
->ssid
, cbss
->ssid
, bss
->ssid_len
) == 0 &&
3151 wpa_blacklist_get(wpa_s
, bss
->bssid
) == NULL
) {
3152 add_freq(freqs
, &num_freqs
, bss
->freq
);
3153 if (num_freqs
== max_freqs
)
3158 if (num_freqs
== 0) {
3167 void wpas_connection_failed(struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
3174 * Remove possible authentication timeout since the connection failed.
3176 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
3179 * Add the failed BSSID into the blacklist and speed up next scan
3180 * attempt if there could be other APs that could accept association.
3181 * The current blacklist count indicates how many times we have tried
3182 * connecting to this AP and multiple attempts mean that other APs are
3183 * either not available or has already been tried, so that we can start
3184 * increasing the delay here to avoid constant scanning.
3186 count
= wpa_blacklist_add(wpa_s
, bssid
);
3187 if (count
== 1 && wpa_s
->current_bss
) {
3189 * This BSS was not in the blacklist before. If there is
3190 * another BSS available for the same ESS, we should try that
3191 * next. Otherwise, we may as well try this one once more
3192 * before allowing other, likely worse, ESSes to be considered.
3194 freqs
= get_bss_freqs_in_ess(wpa_s
);
3196 wpa_dbg(wpa_s
, MSG_DEBUG
, "Another BSS in this ESS "
3197 "has been seen; try it next");
3198 wpa_blacklist_add(wpa_s
, bssid
);
3200 * On the next scan, go through only the known channels
3201 * used in this ESS based on previous scans to speed up
3202 * common load balancing use case.
3204 os_free(wpa_s
->next_scan_freqs
);
3205 wpa_s
->next_scan_freqs
= freqs
;
3224 * TODO: if more than one possible AP is available in scan results,
3225 * could try the other ones before requesting a new scan.
3227 wpa_supplicant_req_scan(wpa_s
, timeout
/ 1000,
3228 1000 * (timeout
% 1000));
3232 int wpas_driver_bss_selection(struct wpa_supplicant
*wpa_s
)
3234 return wpa_s
->conf
->ap_scan
== 2 ||
3235 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_BSS_SELECTION
);
3239 #if defined(CONFIG_CTRL_IFACE) || defined(CONFIG_CTRL_IFACE_DBUS_NEW)
3240 int wpa_supplicant_ctrl_iface_ctrl_rsp_handle(struct wpa_supplicant
*wpa_s
,
3241 struct wpa_ssid
*ssid
,
3245 #ifdef IEEE8021X_EAPOL
3246 struct eap_peer_config
*eap
= &ssid
->eap
;
3248 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: response handle field=%s", field
);
3249 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: response value",
3250 (const u8
*) value
, os_strlen(value
));
3252 switch (wpa_supplicant_ctrl_req_from_string(field
)) {
3253 case WPA_CTRL_REQ_EAP_IDENTITY
:
3254 os_free(eap
->identity
);
3255 eap
->identity
= (u8
*) os_strdup(value
);
3256 eap
->identity_len
= os_strlen(value
);
3257 eap
->pending_req_identity
= 0;
3258 if (ssid
== wpa_s
->current_ssid
)
3259 wpa_s
->reassociate
= 1;
3261 case WPA_CTRL_REQ_EAP_PASSWORD
:
3262 os_free(eap
->password
);
3263 eap
->password
= (u8
*) os_strdup(value
);
3264 eap
->password_len
= os_strlen(value
);
3265 eap
->pending_req_password
= 0;
3266 if (ssid
== wpa_s
->current_ssid
)
3267 wpa_s
->reassociate
= 1;
3269 case WPA_CTRL_REQ_EAP_NEW_PASSWORD
:
3270 os_free(eap
->new_password
);
3271 eap
->new_password
= (u8
*) os_strdup(value
);
3272 eap
->new_password_len
= os_strlen(value
);
3273 eap
->pending_req_new_password
= 0;
3274 if (ssid
== wpa_s
->current_ssid
)
3275 wpa_s
->reassociate
= 1;
3277 case WPA_CTRL_REQ_EAP_PIN
:
3279 eap
->pin
= os_strdup(value
);
3280 eap
->pending_req_pin
= 0;
3281 if (ssid
== wpa_s
->current_ssid
)
3282 wpa_s
->reassociate
= 1;
3284 case WPA_CTRL_REQ_EAP_OTP
:
3286 eap
->otp
= (u8
*) os_strdup(value
);
3287 eap
->otp_len
= os_strlen(value
);
3288 os_free(eap
->pending_req_otp
);
3289 eap
->pending_req_otp
= NULL
;
3290 eap
->pending_req_otp_len
= 0;
3292 case WPA_CTRL_REQ_EAP_PASSPHRASE
:
3293 os_free(eap
->private_key_passwd
);
3294 eap
->private_key_passwd
= (u8
*) os_strdup(value
);
3295 eap
->pending_req_passphrase
= 0;
3296 if (ssid
== wpa_s
->current_ssid
)
3297 wpa_s
->reassociate
= 1;
3300 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown field '%s'", field
);
3305 #else /* IEEE8021X_EAPOL */
3306 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: IEEE 802.1X not included");
3308 #endif /* IEEE8021X_EAPOL */
3310 #endif /* CONFIG_CTRL_IFACE || CONFIG_CTRL_IFACE_DBUS_NEW */