3 * Copyright (c) 2003-2011, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
14 * This file implements functions for registering and unregistering
15 * %wpa_supplicant interfaces. In addition, this file contains number of
16 * functions for managing network connections.
22 #include "crypto/random.h"
23 #include "eapol_supp/eapol_supp_sm.h"
24 #include "eap_peer/eap.h"
25 #include "eap_server/eap_methods.h"
26 #include "rsn_supp/wpa.h"
29 #include "l2_packet/l2_packet.h"
30 #include "wpa_supplicant_i.h"
32 #include "ctrl_iface.h"
33 #include "pcsc_funcs.h"
34 #include "common/version.h"
35 #include "rsn_supp/preauth.h"
36 #include "rsn_supp/pmksa_cache.h"
37 #include "common/wpa_ctrl.h"
39 #include "common/ieee802_11_defs.h"
41 #include "blacklist.h"
42 #include "wpas_glue.h"
43 #include "wps_supplicant.h"
47 #include "p2p_supplicant.h"
53 const char *wpa_supplicant_version
=
54 "wpa_supplicant v" VERSION_STR
"\n"
55 "Copyright (c) 2003-2011, Jouni Malinen <j@w1.fi> and contributors";
57 const char *wpa_supplicant_license
=
58 "This program is free software. You can distribute it and/or modify it\n"
59 "under the terms of the GNU General Public License version 2.\n"
61 "Alternatively, this software may be distributed under the terms of the\n"
62 "BSD license. See README and COPYING for more details.\n"
63 #ifdef EAP_TLS_OPENSSL
64 "\nThis product includes software developed by the OpenSSL Project\n"
65 "for use in the OpenSSL Toolkit (http://www.openssl.org/)\n"
66 #endif /* EAP_TLS_OPENSSL */
69 #ifndef CONFIG_NO_STDOUT_DEBUG
70 /* Long text divided into parts in order to fit in C89 strings size limits. */
71 const char *wpa_supplicant_full_license1
=
72 "This program is free software; you can redistribute it and/or modify\n"
73 "it under the terms of the GNU General Public License version 2 as\n"
74 "published by the Free Software Foundation.\n"
76 "This program is distributed in the hope that it will be useful,\n"
77 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
78 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
79 "GNU General Public License for more details.\n"
81 const char *wpa_supplicant_full_license2
=
82 "You should have received a copy of the GNU General Public License\n"
83 "along with this program; if not, write to the Free Software\n"
84 "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n"
86 "Alternatively, this software may be distributed under the terms of the\n"
89 "Redistribution and use in source and binary forms, with or without\n"
90 "modification, are permitted provided that the following conditions are\n"
93 const char *wpa_supplicant_full_license3
=
94 "1. Redistributions of source code must retain the above copyright\n"
95 " notice, this list of conditions and the following disclaimer.\n"
97 "2. Redistributions in binary form must reproduce the above copyright\n"
98 " notice, this list of conditions and the following disclaimer in the\n"
99 " documentation and/or other materials provided with the distribution.\n"
101 const char *wpa_supplicant_full_license4
=
102 "3. Neither the name(s) of the above-listed copyright holder(s) nor the\n"
103 " names of its contributors may be used to endorse or promote products\n"
104 " derived from this software without specific prior written permission.\n"
106 "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n"
107 "\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n"
108 "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n"
109 "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n";
110 const char *wpa_supplicant_full_license5
=
111 "OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n"
112 "SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n"
113 "LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n"
114 "DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n"
115 "THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n"
116 "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n"
117 "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
119 #endif /* CONFIG_NO_STDOUT_DEBUG */
121 extern int wpa_debug_level
;
122 extern int wpa_debug_show_keys
;
123 extern int wpa_debug_timestamp
;
124 extern struct wpa_driver_ops
*wpa_drivers
[];
126 /* Configure default/group WEP keys for static WEP */
127 int wpa_set_wep_keys(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
)
131 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
132 if (ssid
->wep_key_len
[i
] == 0)
136 wpa_drv_set_key(wpa_s
, WPA_ALG_WEP
, NULL
,
137 i
, i
== ssid
->wep_tx_keyidx
, NULL
, 0,
138 ssid
->wep_key
[i
], ssid
->wep_key_len
[i
]);
145 static int wpa_supplicant_set_wpa_none_key(struct wpa_supplicant
*wpa_s
,
146 struct wpa_ssid
*ssid
)
153 /* IBSS/WPA-None uses only one key (Group) for both receiving and
154 * sending unicast and multicast packets. */
156 if (ssid
->mode
!= WPAS_MODE_IBSS
) {
157 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Invalid mode %d (not "
158 "IBSS/ad-hoc) for WPA-None", ssid
->mode
);
162 if (!ssid
->psk_set
) {
163 wpa_msg(wpa_s
, MSG_INFO
, "WPA: No PSK configured for "
168 switch (wpa_s
->group_cipher
) {
169 case WPA_CIPHER_CCMP
:
170 os_memcpy(key
, ssid
->psk
, 16);
174 case WPA_CIPHER_TKIP
:
175 /* WPA-None uses the same Michael MIC key for both TX and RX */
176 os_memcpy(key
, ssid
->psk
, 16 + 8);
177 os_memcpy(key
+ 16 + 8, ssid
->psk
+ 16, 8);
182 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Invalid group cipher %d for "
183 "WPA-None", wpa_s
->group_cipher
);
187 /* TODO: should actually remember the previously used seq#, both for TX
188 * and RX from each STA.. */
190 return wpa_drv_set_key(wpa_s
, alg
, NULL
, 0, 1, seq
, 6, key
, keylen
);
194 static void wpa_supplicant_timeout(void *eloop_ctx
, void *timeout_ctx
)
196 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
197 const u8
*bssid
= wpa_s
->bssid
;
198 if (is_zero_ether_addr(bssid
))
199 bssid
= wpa_s
->pending_bssid
;
200 wpa_msg(wpa_s
, MSG_INFO
, "Authentication with " MACSTR
" timed out.",
202 wpa_blacklist_add(wpa_s
, bssid
);
203 wpa_sm_notify_disassoc(wpa_s
->wpa
);
204 wpa_supplicant_disassociate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
205 wpa_s
->reassociate
= 1;
208 * If we timed out, the AP or the local radio may be busy.
209 * So, wait a second until scanning again.
211 wpa_supplicant_req_scan(wpa_s
, 1, 0);
216 * wpa_supplicant_req_auth_timeout - Schedule a timeout for authentication
217 * @wpa_s: Pointer to wpa_supplicant data
218 * @sec: Number of seconds after which to time out authentication
219 * @usec: Number of microseconds after which to time out authentication
221 * This function is used to schedule a timeout for the current authentication
224 void wpa_supplicant_req_auth_timeout(struct wpa_supplicant
*wpa_s
,
227 if (wpa_s
->conf
&& wpa_s
->conf
->ap_scan
== 0 &&
228 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
))
231 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setting authentication timeout: %d sec "
232 "%d usec", sec
, usec
);
233 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
234 eloop_register_timeout(sec
, usec
, wpa_supplicant_timeout
, wpa_s
, NULL
);
239 * wpa_supplicant_cancel_auth_timeout - Cancel authentication timeout
240 * @wpa_s: Pointer to wpa_supplicant data
242 * This function is used to cancel authentication timeout scheduled with
243 * wpa_supplicant_req_auth_timeout() and it is called when authentication has
246 void wpa_supplicant_cancel_auth_timeout(struct wpa_supplicant
*wpa_s
)
248 wpa_dbg(wpa_s
, MSG_DEBUG
, "Cancelling authentication timeout");
249 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
250 wpa_blacklist_del(wpa_s
, wpa_s
->bssid
);
255 * wpa_supplicant_initiate_eapol - Configure EAPOL state machine
256 * @wpa_s: Pointer to wpa_supplicant data
258 * This function is used to configure EAPOL state machine based on the selected
259 * authentication mode.
261 void wpa_supplicant_initiate_eapol(struct wpa_supplicant
*wpa_s
)
263 #ifdef IEEE8021X_EAPOL
264 struct eapol_config eapol_conf
;
265 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
267 #ifdef CONFIG_IBSS_RSN
268 if (ssid
->mode
== WPAS_MODE_IBSS
&&
269 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
270 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
) {
272 * RSN IBSS authentication is per-STA and we can disable the
273 * per-BSSID EAPOL authentication.
275 eapol_sm_notify_portControl(wpa_s
->eapol
, ForceAuthorized
);
276 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
277 eapol_sm_notify_eap_fail(wpa_s
->eapol
, FALSE
);
280 #endif /* CONFIG_IBSS_RSN */
282 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
283 eapol_sm_notify_eap_fail(wpa_s
->eapol
, FALSE
);
285 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
286 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
287 eapol_sm_notify_portControl(wpa_s
->eapol
, ForceAuthorized
);
289 eapol_sm_notify_portControl(wpa_s
->eapol
, Auto
);
291 os_memset(&eapol_conf
, 0, sizeof(eapol_conf
));
292 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
293 eapol_conf
.accept_802_1x_keys
= 1;
294 eapol_conf
.required_keys
= 0;
295 if (ssid
->eapol_flags
& EAPOL_FLAG_REQUIRE_KEY_UNICAST
) {
296 eapol_conf
.required_keys
|= EAPOL_REQUIRE_KEY_UNICAST
;
298 if (ssid
->eapol_flags
& EAPOL_FLAG_REQUIRE_KEY_BROADCAST
) {
299 eapol_conf
.required_keys
|=
300 EAPOL_REQUIRE_KEY_BROADCAST
;
303 if (wpa_s
->conf
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
))
304 eapol_conf
.required_keys
= 0;
307 eapol_conf
.fast_reauth
= wpa_s
->conf
->fast_reauth
;
308 eapol_conf
.workaround
= ssid
->eap_workaround
;
309 eapol_conf
.eap_disabled
=
310 !wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) &&
311 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
312 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPS
;
313 eapol_sm_notify_config(wpa_s
->eapol
, &ssid
->eap
, &eapol_conf
);
314 #endif /* IEEE8021X_EAPOL */
319 * wpa_supplicant_set_non_wpa_policy - Set WPA parameters to non-WPA mode
320 * @wpa_s: Pointer to wpa_supplicant data
321 * @ssid: Configuration data for the network
323 * This function is used to configure WPA state machine and related parameters
324 * to a mode where WPA is not enabled. This is called as part of the
325 * authentication configuration when the selected network does not use WPA.
327 void wpa_supplicant_set_non_wpa_policy(struct wpa_supplicant
*wpa_s
,
328 struct wpa_ssid
*ssid
)
332 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
333 wpa_s
->key_mgmt
= WPA_KEY_MGMT_WPS
;
334 else if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)
335 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X_NO_WPA
;
337 wpa_s
->key_mgmt
= WPA_KEY_MGMT_NONE
;
338 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
339 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
340 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
341 wpa_s
->pairwise_cipher
= WPA_CIPHER_NONE
;
342 wpa_s
->group_cipher
= WPA_CIPHER_NONE
;
343 wpa_s
->mgmt_group_cipher
= 0;
345 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
346 if (ssid
->wep_key_len
[i
] > 5) {
347 wpa_s
->pairwise_cipher
= WPA_CIPHER_WEP104
;
348 wpa_s
->group_cipher
= WPA_CIPHER_WEP104
;
350 } else if (ssid
->wep_key_len
[i
] > 0) {
351 wpa_s
->pairwise_cipher
= WPA_CIPHER_WEP40
;
352 wpa_s
->group_cipher
= WPA_CIPHER_WEP40
;
357 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_RSN_ENABLED
, 0);
358 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_KEY_MGMT
, wpa_s
->key_mgmt
);
359 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PAIRWISE
,
360 wpa_s
->pairwise_cipher
);
361 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_GROUP
, wpa_s
->group_cipher
);
362 #ifdef CONFIG_IEEE80211W
363 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MGMT_GROUP
,
364 wpa_s
->mgmt_group_cipher
);
365 #endif /* CONFIG_IEEE80211W */
367 pmksa_cache_clear_current(wpa_s
->wpa
);
371 static void wpa_supplicant_cleanup(struct wpa_supplicant
*wpa_s
)
373 bgscan_deinit(wpa_s
);
374 scard_deinit(wpa_s
->scard
);
376 wpa_sm_set_scard_ctx(wpa_s
->wpa
, NULL
);
377 eapol_sm_register_scard_ctx(wpa_s
->eapol
, NULL
);
378 l2_packet_deinit(wpa_s
->l2
);
381 l2_packet_deinit(wpa_s
->l2_br
);
385 if (wpa_s
->ctrl_iface
) {
386 wpa_supplicant_ctrl_iface_deinit(wpa_s
->ctrl_iface
);
387 wpa_s
->ctrl_iface
= NULL
;
389 if (wpa_s
->conf
!= NULL
) {
390 struct wpa_ssid
*ssid
;
391 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
)
392 wpas_notify_network_removed(wpa_s
, ssid
);
393 wpa_config_free(wpa_s
->conf
);
397 os_free(wpa_s
->confname
);
398 wpa_s
->confname
= NULL
;
400 wpa_sm_set_eapol(wpa_s
->wpa
, NULL
);
401 eapol_sm_deinit(wpa_s
->eapol
);
404 rsn_preauth_deinit(wpa_s
->wpa
);
407 wpa_tdls_deinit(wpa_s
->wpa
);
408 #endif /* CONFIG_TDLS */
410 pmksa_candidate_free(wpa_s
->wpa
);
411 wpa_sm_deinit(wpa_s
->wpa
);
413 wpa_blacklist_clear(wpa_s
);
415 wpa_bss_deinit(wpa_s
);
417 wpa_supplicant_cancel_scan(wpa_s
);
418 wpa_supplicant_cancel_auth_timeout(wpa_s
);
420 ieee80211_sta_deinit(wpa_s
);
422 wpas_wps_deinit(wpa_s
);
424 wpabuf_free(wpa_s
->pending_eapol_rx
);
425 wpa_s
->pending_eapol_rx
= NULL
;
427 #ifdef CONFIG_IBSS_RSN
428 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
429 wpa_s
->ibss_rsn
= NULL
;
430 #endif /* CONFIG_IBSS_RSN */
435 wpa_supplicant_ap_deinit(wpa_s
);
436 #endif /* CONFIG_AP */
439 wpas_p2p_deinit(wpa_s
);
440 #endif /* CONFIG_P2P */
442 os_free(wpa_s
->next_scan_freqs
);
443 wpa_s
->next_scan_freqs
= NULL
;
448 * wpa_clear_keys - Clear keys configured for the driver
449 * @wpa_s: Pointer to wpa_supplicant data
450 * @addr: Previously used BSSID or %NULL if not available
452 * This function clears the encryption keys that has been previously configured
455 void wpa_clear_keys(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
457 if (wpa_s
->keys_cleared
) {
458 /* Some drivers (e.g., ndiswrapper & NDIS drivers) seem to have
459 * timing issues with keys being cleared just before new keys
460 * are set or just after association or something similar. This
461 * shows up in group key handshake failing often because of the
462 * client not receiving the first encrypted packets correctly.
463 * Skipping some of the extra key clearing steps seems to help
464 * in completing group key handshake more reliably. */
465 wpa_dbg(wpa_s
, MSG_DEBUG
, "No keys have been configured - "
466 "skip key clearing");
470 /* MLME-DELETEKEYS.request */
471 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
472 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
473 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
474 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
475 #ifdef CONFIG_IEEE80211W
476 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
477 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
478 #endif /* CONFIG_IEEE80211W */
480 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, addr
, 0, 0, NULL
, 0, NULL
,
482 /* MLME-SETPROTECTION.request(None) */
483 wpa_drv_mlme_setprotection(
485 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
486 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
488 wpa_s
->keys_cleared
= 1;
493 * wpa_supplicant_state_txt - Get the connection state name as a text string
494 * @state: State (wpa_state; WPA_*)
495 * Returns: The state name as a printable text string
497 const char * wpa_supplicant_state_txt(enum wpa_states state
)
500 case WPA_DISCONNECTED
:
501 return "DISCONNECTED";
504 case WPA_INTERFACE_DISABLED
:
505 return "INTERFACE_DISABLED";
508 case WPA_AUTHENTICATING
:
509 return "AUTHENTICATING";
510 case WPA_ASSOCIATING
:
511 return "ASSOCIATING";
514 case WPA_4WAY_HANDSHAKE
:
515 return "4WAY_HANDSHAKE";
516 case WPA_GROUP_HANDSHAKE
:
517 return "GROUP_HANDSHAKE";
528 static void wpa_supplicant_start_bgscan(struct wpa_supplicant
*wpa_s
)
530 if (wpa_s
->current_ssid
== wpa_s
->bgscan_ssid
)
533 bgscan_deinit(wpa_s
);
534 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->bgscan
) {
535 if (bgscan_init(wpa_s
, wpa_s
->current_ssid
)) {
536 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to initialize "
539 * Live without bgscan; it is only used as a roaming
540 * optimization, so the initial connection is not
544 wpa_s
->bgscan_ssid
= wpa_s
->current_ssid
;
546 wpa_s
->bgscan_ssid
= NULL
;
550 static void wpa_supplicant_stop_bgscan(struct wpa_supplicant
*wpa_s
)
552 if (wpa_s
->bgscan_ssid
!= NULL
) {
553 bgscan_deinit(wpa_s
);
554 wpa_s
->bgscan_ssid
= NULL
;
558 #endif /* CONFIG_BGSCAN */
562 * wpa_supplicant_set_state - Set current connection state
563 * @wpa_s: Pointer to wpa_supplicant data
564 * @state: The new connection state
566 * This function is called whenever the connection state changes, e.g.,
567 * association is completed for WPA/WPA2 4-Way Handshake is started.
569 void wpa_supplicant_set_state(struct wpa_supplicant
*wpa_s
,
570 enum wpa_states state
)
572 enum wpa_states old_state
= wpa_s
->wpa_state
;
574 wpa_dbg(wpa_s
, MSG_DEBUG
, "State: %s -> %s",
575 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
576 wpa_supplicant_state_txt(state
));
578 if (state
!= WPA_SCANNING
)
579 wpa_supplicant_notify_scanning(wpa_s
, 0);
581 if (state
== WPA_COMPLETED
&& wpa_s
->new_connection
) {
582 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
583 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
584 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
"- Connection to "
585 MACSTR
" completed %s [id=%d id_str=%s]",
586 MAC2STR(wpa_s
->bssid
), wpa_s
->reassociated_connection
?
587 "(reauth)" : "(auth)",
588 ssid
? ssid
->id
: -1,
589 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
590 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
591 wpa_s
->new_connection
= 0;
592 wpa_s
->reassociated_connection
= 1;
593 wpa_drv_set_operstate(wpa_s
, 1);
594 #ifndef IEEE8021X_EAPOL
595 wpa_drv_set_supp_port(wpa_s
, 1);
596 #endif /* IEEE8021X_EAPOL */
597 wpa_s
->after_wps
= 0;
599 wpas_p2p_completed(wpa_s
);
600 #endif /* CONFIG_P2P */
601 } else if (state
== WPA_DISCONNECTED
|| state
== WPA_ASSOCIATING
||
602 state
== WPA_ASSOCIATED
) {
603 wpa_s
->new_connection
= 1;
604 wpa_drv_set_operstate(wpa_s
, 0);
605 #ifndef IEEE8021X_EAPOL
606 wpa_drv_set_supp_port(wpa_s
, 0);
607 #endif /* IEEE8021X_EAPOL */
609 wpa_s
->wpa_state
= state
;
612 if (state
== WPA_COMPLETED
)
613 wpa_supplicant_start_bgscan(wpa_s
);
615 wpa_supplicant_stop_bgscan(wpa_s
);
616 #endif /* CONFIG_BGSCAN */
618 if (wpa_s
->wpa_state
!= old_state
) {
619 wpas_notify_state_changed(wpa_s
, wpa_s
->wpa_state
, old_state
);
621 if (wpa_s
->wpa_state
== WPA_COMPLETED
||
622 old_state
== WPA_COMPLETED
)
623 wpas_notify_auth_changed(wpa_s
);
628 void wpa_supplicant_terminate_proc(struct wpa_global
*global
)
632 struct wpa_supplicant
*wpa_s
= global
->ifaces
;
634 if (wpas_wps_terminate_pending(wpa_s
) == 1)
638 #endif /* CONFIG_WPS */
645 static void wpa_supplicant_terminate(int sig
, void *signal_ctx
)
647 struct wpa_global
*global
= signal_ctx
;
648 struct wpa_supplicant
*wpa_s
;
649 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
650 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_TERMINATING
"- signal %d "
653 wpa_supplicant_terminate_proc(global
);
657 void wpa_supplicant_clear_status(struct wpa_supplicant
*wpa_s
)
659 enum wpa_states old_state
= wpa_s
->wpa_state
;
661 wpa_s
->pairwise_cipher
= 0;
662 wpa_s
->group_cipher
= 0;
663 wpa_s
->mgmt_group_cipher
= 0;
665 if (wpa_s
->wpa_state
!= WPA_INTERFACE_DISABLED
)
666 wpa_s
->wpa_state
= WPA_DISCONNECTED
;
668 if (wpa_s
->wpa_state
!= old_state
)
669 wpas_notify_state_changed(wpa_s
, wpa_s
->wpa_state
, old_state
);
674 * wpa_supplicant_reload_configuration - Reload configuration data
675 * @wpa_s: Pointer to wpa_supplicant data
676 * Returns: 0 on success or -1 if configuration parsing failed
678 * This function can be used to request that the configuration data is reloaded
679 * (e.g., after configuration file change). This function is reloading
680 * configuration only for one interface, so this may need to be called multiple
681 * times if %wpa_supplicant is controlling multiple interfaces and all
682 * interfaces need reconfiguration.
684 int wpa_supplicant_reload_configuration(struct wpa_supplicant
*wpa_s
)
686 struct wpa_config
*conf
;
687 struct wpa_ssid
*old_ssid
;
691 if (wpa_s
->confname
== NULL
)
693 conf
= wpa_config_read(wpa_s
->confname
);
695 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to parse the configuration "
696 "file '%s' - exiting", wpa_s
->confname
);
699 conf
->changed_parameters
= (unsigned int) -1;
701 reconf_ctrl
= !!conf
->ctrl_interface
!= !!wpa_s
->conf
->ctrl_interface
702 || (conf
->ctrl_interface
&& wpa_s
->conf
->ctrl_interface
&&
703 os_strcmp(conf
->ctrl_interface
,
704 wpa_s
->conf
->ctrl_interface
) != 0);
706 if (reconf_ctrl
&& wpa_s
->ctrl_iface
) {
707 wpa_supplicant_ctrl_iface_deinit(wpa_s
->ctrl_iface
);
708 wpa_s
->ctrl_iface
= NULL
;
711 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
712 old_ssid
= wpa_s
->current_ssid
;
713 wpa_s
->current_ssid
= NULL
;
714 if (old_ssid
!= wpa_s
->current_ssid
)
715 wpas_notify_network_changed(wpa_s
);
718 * TODO: should notify EAPOL SM about changes in opensc_engine_path,
719 * pkcs11_engine_path, pkcs11_module_path.
721 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
723 * Clear forced success to clear EAP state for next
726 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
728 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
729 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
730 wpa_sm_set_fast_reauth(wpa_s
->wpa
, wpa_s
->conf
->fast_reauth
);
731 rsn_preauth_deinit(wpa_s
->wpa
);
733 old_ap_scan
= wpa_s
->conf
->ap_scan
;
734 wpa_config_free(wpa_s
->conf
);
736 if (old_ap_scan
!= wpa_s
->conf
->ap_scan
)
737 wpas_notify_ap_scan_changed(wpa_s
);
740 wpa_s
->ctrl_iface
= wpa_supplicant_ctrl_iface_init(wpa_s
);
742 wpa_supplicant_update_config(wpa_s
);
744 wpa_supplicant_clear_status(wpa_s
);
745 if (wpa_supplicant_enabled_networks(wpa_s
->conf
)) {
746 wpa_s
->reassociate
= 1;
747 wpa_supplicant_req_scan(wpa_s
, 0, 0);
749 wpa_dbg(wpa_s
, MSG_DEBUG
, "Reconfiguration completed");
754 static void wpa_supplicant_reconfig(int sig
, void *signal_ctx
)
756 struct wpa_global
*global
= signal_ctx
;
757 struct wpa_supplicant
*wpa_s
;
758 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
759 wpa_dbg(wpa_s
, MSG_DEBUG
, "Signal %d received - reconfiguring",
761 if (wpa_supplicant_reload_configuration(wpa_s
) < 0) {
762 wpa_supplicant_terminate_proc(global
);
768 enum wpa_cipher
cipher_suite2driver(int cipher
)
771 case WPA_CIPHER_NONE
:
773 case WPA_CIPHER_WEP40
:
775 case WPA_CIPHER_WEP104
:
776 return CIPHER_WEP104
;
777 case WPA_CIPHER_CCMP
:
779 case WPA_CIPHER_TKIP
:
786 enum wpa_key_mgmt
key_mgmt2driver(int key_mgmt
)
789 case WPA_KEY_MGMT_NONE
:
790 return KEY_MGMT_NONE
;
791 case WPA_KEY_MGMT_IEEE8021X_NO_WPA
:
792 return KEY_MGMT_802_1X_NO_WPA
;
793 case WPA_KEY_MGMT_IEEE8021X
:
794 return KEY_MGMT_802_1X
;
795 case WPA_KEY_MGMT_WPA_NONE
:
796 return KEY_MGMT_WPA_NONE
;
797 case WPA_KEY_MGMT_FT_IEEE8021X
:
798 return KEY_MGMT_FT_802_1X
;
799 case WPA_KEY_MGMT_FT_PSK
:
800 return KEY_MGMT_FT_PSK
;
801 case WPA_KEY_MGMT_IEEE8021X_SHA256
:
802 return KEY_MGMT_802_1X_SHA256
;
803 case WPA_KEY_MGMT_PSK_SHA256
:
804 return KEY_MGMT_PSK_SHA256
;
805 case WPA_KEY_MGMT_WPS
:
807 case WPA_KEY_MGMT_PSK
:
814 static int wpa_supplicant_suites_from_ai(struct wpa_supplicant
*wpa_s
,
815 struct wpa_ssid
*ssid
,
816 struct wpa_ie_data
*ie
)
818 int ret
= wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, ie
);
821 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Failed to parse WPA IE "
822 "from association info");
827 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Using WPA IE from AssocReq to set "
829 if (!(ie
->group_cipher
& ssid
->group_cipher
)) {
830 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled group "
831 "cipher 0x%x (mask 0x%x) - reject",
832 ie
->group_cipher
, ssid
->group_cipher
);
835 if (!(ie
->pairwise_cipher
& ssid
->pairwise_cipher
)) {
836 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled pairwise "
837 "cipher 0x%x (mask 0x%x) - reject",
838 ie
->pairwise_cipher
, ssid
->pairwise_cipher
);
841 if (!(ie
->key_mgmt
& ssid
->key_mgmt
)) {
842 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled key "
843 "management 0x%x (mask 0x%x) - reject",
844 ie
->key_mgmt
, ssid
->key_mgmt
);
848 #ifdef CONFIG_IEEE80211W
849 if (!(ie
->capabilities
& WPA_CAPABILITY_MFPC
) &&
850 ssid
->ieee80211w
== MGMT_FRAME_PROTECTION_REQUIRED
) {
851 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver associated with an AP "
852 "that does not support management frame protection - "
856 #endif /* CONFIG_IEEE80211W */
863 * wpa_supplicant_set_suites - Set authentication and encryption parameters
864 * @wpa_s: Pointer to wpa_supplicant data
865 * @bss: Scan results for the selected BSS, or %NULL if not available
866 * @ssid: Configuration data for the selected network
867 * @wpa_ie: Buffer for the WPA/RSN IE
868 * @wpa_ie_len: Maximum wpa_ie buffer size on input. This is changed to be the
869 * used buffer length in case the functions returns success.
870 * Returns: 0 on success or -1 on failure
872 * This function is used to configure authentication and encryption parameters
873 * based on the network configuration and scan result for the selected BSS (if
876 int wpa_supplicant_set_suites(struct wpa_supplicant
*wpa_s
,
877 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
,
878 u8
*wpa_ie
, size_t *wpa_ie_len
)
880 struct wpa_ie_data ie
;
882 const u8
*bss_wpa
, *bss_rsn
;
885 bss_wpa
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
886 bss_rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
888 bss_wpa
= bss_rsn
= NULL
;
890 if (bss_rsn
&& (ssid
->proto
& WPA_PROTO_RSN
) &&
891 wpa_parse_wpa_ie(bss_rsn
, 2 + bss_rsn
[1], &ie
) == 0 &&
892 (ie
.group_cipher
& ssid
->group_cipher
) &&
893 (ie
.pairwise_cipher
& ssid
->pairwise_cipher
) &&
894 (ie
.key_mgmt
& ssid
->key_mgmt
)) {
895 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: using IEEE 802.11i/D9.0");
896 proto
= WPA_PROTO_RSN
;
897 } else if (bss_wpa
&& (ssid
->proto
& WPA_PROTO_WPA
) &&
898 wpa_parse_wpa_ie(bss_wpa
, 2 +bss_wpa
[1], &ie
) == 0 &&
899 (ie
.group_cipher
& ssid
->group_cipher
) &&
900 (ie
.pairwise_cipher
& ssid
->pairwise_cipher
) &&
901 (ie
.key_mgmt
& ssid
->key_mgmt
)) {
902 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using IEEE 802.11i/D3.0");
903 proto
= WPA_PROTO_WPA
;
905 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select WPA/RSN");
908 if (ssid
->proto
& WPA_PROTO_RSN
)
909 proto
= WPA_PROTO_RSN
;
911 proto
= WPA_PROTO_WPA
;
912 if (wpa_supplicant_suites_from_ai(wpa_s
, ssid
, &ie
) < 0) {
913 os_memset(&ie
, 0, sizeof(ie
));
914 ie
.group_cipher
= ssid
->group_cipher
;
915 ie
.pairwise_cipher
= ssid
->pairwise_cipher
;
916 ie
.key_mgmt
= ssid
->key_mgmt
;
917 #ifdef CONFIG_IEEE80211W
918 ie
.mgmt_group_cipher
=
919 ssid
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
?
920 WPA_CIPHER_AES_128_CMAC
: 0;
921 #endif /* CONFIG_IEEE80211W */
922 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Set cipher suites "
923 "based on configuration");
928 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Selected cipher suites: group %d "
929 "pairwise %d key_mgmt %d proto %d",
930 ie
.group_cipher
, ie
.pairwise_cipher
, ie
.key_mgmt
, proto
);
931 #ifdef CONFIG_IEEE80211W
932 if (ssid
->ieee80211w
) {
933 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Selected mgmt group cipher %d",
934 ie
.mgmt_group_cipher
);
936 #endif /* CONFIG_IEEE80211W */
938 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PROTO
, proto
);
939 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_RSN_ENABLED
,
940 !!(ssid
->proto
& WPA_PROTO_RSN
));
942 if (bss
|| !wpa_s
->ap_ies_from_associnfo
) {
943 if (wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, bss_wpa
,
944 bss_wpa
? 2 + bss_wpa
[1] : 0) ||
945 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, bss_rsn
,
946 bss_rsn
? 2 + bss_rsn
[1] : 0))
950 sel
= ie
.group_cipher
& ssid
->group_cipher
;
951 if (sel
& WPA_CIPHER_CCMP
) {
952 wpa_s
->group_cipher
= WPA_CIPHER_CCMP
;
953 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using GTK CCMP");
954 } else if (sel
& WPA_CIPHER_TKIP
) {
955 wpa_s
->group_cipher
= WPA_CIPHER_TKIP
;
956 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using GTK TKIP");
957 } else if (sel
& WPA_CIPHER_WEP104
) {
958 wpa_s
->group_cipher
= WPA_CIPHER_WEP104
;
959 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using GTK WEP104");
960 } else if (sel
& WPA_CIPHER_WEP40
) {
961 wpa_s
->group_cipher
= WPA_CIPHER_WEP40
;
962 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using GTK WEP40");
964 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select group "
969 sel
= ie
.pairwise_cipher
& ssid
->pairwise_cipher
;
970 if (sel
& WPA_CIPHER_CCMP
) {
971 wpa_s
->pairwise_cipher
= WPA_CIPHER_CCMP
;
972 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using PTK CCMP");
973 } else if (sel
& WPA_CIPHER_TKIP
) {
974 wpa_s
->pairwise_cipher
= WPA_CIPHER_TKIP
;
975 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using PTK TKIP");
976 } else if (sel
& WPA_CIPHER_NONE
) {
977 wpa_s
->pairwise_cipher
= WPA_CIPHER_NONE
;
978 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using PTK NONE");
980 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select pairwise "
985 sel
= ie
.key_mgmt
& ssid
->key_mgmt
;
987 #ifdef CONFIG_IEEE80211R
988 } else if (sel
& WPA_KEY_MGMT_FT_IEEE8021X
) {
989 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_IEEE8021X
;
990 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FT/802.1X");
991 } else if (sel
& WPA_KEY_MGMT_FT_PSK
) {
992 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_PSK
;
993 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FT/PSK");
994 #endif /* CONFIG_IEEE80211R */
995 #ifdef CONFIG_IEEE80211W
996 } else if (sel
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
997 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X_SHA256
;
998 wpa_dbg(wpa_s
, MSG_DEBUG
,
999 "WPA: using KEY_MGMT 802.1X with SHA256");
1000 } else if (sel
& WPA_KEY_MGMT_PSK_SHA256
) {
1001 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK_SHA256
;
1002 wpa_dbg(wpa_s
, MSG_DEBUG
,
1003 "WPA: using KEY_MGMT PSK with SHA256");
1004 #endif /* CONFIG_IEEE80211W */
1005 } else if (sel
& WPA_KEY_MGMT_IEEE8021X
) {
1006 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X
;
1007 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT 802.1X");
1008 } else if (sel
& WPA_KEY_MGMT_PSK
) {
1009 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK
;
1010 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT WPA-PSK");
1011 } else if (sel
& WPA_KEY_MGMT_WPA_NONE
) {
1012 wpa_s
->key_mgmt
= WPA_KEY_MGMT_WPA_NONE
;
1013 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT WPA-NONE");
1015 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select "
1016 "authenticated key management type");
1020 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_KEY_MGMT
, wpa_s
->key_mgmt
);
1021 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PAIRWISE
,
1022 wpa_s
->pairwise_cipher
);
1023 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_GROUP
, wpa_s
->group_cipher
);
1025 #ifdef CONFIG_IEEE80211W
1026 sel
= ie
.mgmt_group_cipher
;
1027 if (ssid
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
||
1028 !(ie
.capabilities
& WPA_CAPABILITY_MFPC
))
1030 if (sel
& WPA_CIPHER_AES_128_CMAC
) {
1031 wpa_s
->mgmt_group_cipher
= WPA_CIPHER_AES_128_CMAC
;
1032 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using MGMT group cipher "
1035 wpa_s
->mgmt_group_cipher
= 0;
1036 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: not using MGMT group cipher");
1038 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MGMT_GROUP
,
1039 wpa_s
->mgmt_group_cipher
);
1040 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MFP
, ssid
->ieee80211w
);
1041 #endif /* CONFIG_IEEE80211W */
1043 if (wpa_sm_set_assoc_wpa_ie_default(wpa_s
->wpa
, wpa_ie
, wpa_ie_len
)) {
1044 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to generate WPA IE");
1048 if (ssid
->key_mgmt
&
1049 (WPA_KEY_MGMT_PSK
| WPA_KEY_MGMT_FT_PSK
| WPA_KEY_MGMT_PSK_SHA256
))
1050 wpa_sm_set_pmk(wpa_s
->wpa
, ssid
->psk
, PMK_LEN
);
1052 wpa_sm_set_pmk_from_pmksa(wpa_s
->wpa
);
1059 * wpa_supplicant_associate - Request association
1060 * @wpa_s: Pointer to wpa_supplicant data
1061 * @bss: Scan results for the selected BSS, or %NULL if not available
1062 * @ssid: Configuration data for the selected network
1064 * This function is used to request %wpa_supplicant to associate with a BSS.
1066 void wpa_supplicant_associate(struct wpa_supplicant
*wpa_s
,
1067 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
)
1071 int use_crypt
, ret
, i
, bssid_changed
;
1072 int algs
= WPA_AUTH_ALG_OPEN
;
1073 enum wpa_cipher cipher_pairwise
, cipher_group
;
1074 struct wpa_driver_associate_params params
;
1075 int wep_keys_set
= 0;
1076 struct wpa_driver_capa capa
;
1077 int assoc_failed
= 0;
1078 struct wpa_ssid
*old_ssid
;
1080 if (ssid
->mode
== WPAS_MODE_AP
|| ssid
->mode
== WPAS_MODE_P2P_GO
||
1081 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
) {
1083 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_AP
)) {
1084 wpa_msg(wpa_s
, MSG_INFO
, "Driver does not support AP "
1088 wpa_supplicant_create_ap(wpa_s
, ssid
);
1089 wpa_s
->current_bss
= bss
;
1090 #else /* CONFIG_AP */
1091 wpa_msg(wpa_s
, MSG_ERROR
, "AP mode support not included in "
1093 #endif /* CONFIG_AP */
1098 wpa_tdls_ap_ies(wpa_s
->wpa
, (const u8
*) (bss
+ 1), bss
->ie_len
);
1099 #endif /* CONFIG_TDLS */
1101 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
1102 ssid
->mode
== IEEE80211_MODE_INFRA
) {
1103 sme_authenticate(wpa_s
, bss
, ssid
);
1107 os_memset(¶ms
, 0, sizeof(params
));
1108 wpa_s
->reassociate
= 0;
1110 #ifdef CONFIG_IEEE80211R
1111 const u8
*ie
, *md
= NULL
;
1112 #endif /* CONFIG_IEEE80211R */
1113 wpa_msg(wpa_s
, MSG_INFO
, "Trying to associate with " MACSTR
1114 " (SSID='%s' freq=%d MHz)", MAC2STR(bss
->bssid
),
1115 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
), bss
->freq
);
1116 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
1117 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
1118 os_memcpy(wpa_s
->pending_bssid
, bss
->bssid
, ETH_ALEN
);
1120 wpas_notify_bssid_changed(wpa_s
);
1121 #ifdef CONFIG_IEEE80211R
1122 ie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
1123 if (ie
&& ie
[1] >= MOBILITY_DOMAIN_ID_LEN
)
1125 wpa_sm_set_ft_params(wpa_s
->wpa
, ie
, ie
? 2 + ie
[1] : 0);
1127 /* Prepare for the next transition */
1128 wpa_ft_prepare_auth_request(wpa_s
->wpa
, ie
);
1130 #endif /* CONFIG_IEEE80211R */
1132 } else if ((ssid
->ssid
== NULL
|| ssid
->ssid_len
== 0) &&
1133 wpa_s
->conf
->ap_scan
== 2 &&
1134 (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
1135 /* Use ap_scan==1 style network selection to find the network
1137 wpa_s
->scan_req
= 2;
1138 wpa_s
->reassociate
= 1;
1139 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1141 #endif /* CONFIG_WPS */
1143 wpa_msg(wpa_s
, MSG_INFO
, "Trying to associate with SSID '%s'",
1144 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
1145 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1147 wpa_supplicant_cancel_scan(wpa_s
);
1149 /* Starting new association, so clear the possibly used WPA IE from the
1150 * previous association. */
1151 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1153 #ifdef IEEE8021X_EAPOL
1154 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1156 if (ssid
->non_leap
== 0)
1157 algs
= WPA_AUTH_ALG_LEAP
;
1159 algs
|= WPA_AUTH_ALG_LEAP
;
1162 #endif /* IEEE8021X_EAPOL */
1163 wpa_dbg(wpa_s
, MSG_DEBUG
, "Automatic auth_alg selection: 0x%x", algs
);
1164 if (ssid
->auth_alg
) {
1165 algs
= ssid
->auth_alg
;
1166 wpa_dbg(wpa_s
, MSG_DEBUG
, "Overriding auth_alg selection: "
1170 if (bss
&& (wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
) ||
1171 wpa_bss_get_ie(bss
, WLAN_EID_RSN
)) &&
1172 (ssid
->key_mgmt
& (WPA_KEY_MGMT_IEEE8021X
| WPA_KEY_MGMT_PSK
|
1173 WPA_KEY_MGMT_FT_IEEE8021X
|
1174 WPA_KEY_MGMT_FT_PSK
|
1175 WPA_KEY_MGMT_IEEE8021X_SHA256
|
1176 WPA_KEY_MGMT_PSK_SHA256
))) {
1177 int try_opportunistic
;
1178 try_opportunistic
= ssid
->proactive_key_caching
&&
1179 (ssid
->proto
& WPA_PROTO_RSN
);
1180 if (pmksa_cache_set_current(wpa_s
->wpa
, NULL
, bss
->bssid
,
1181 wpa_s
->current_ssid
,
1182 try_opportunistic
) == 0)
1183 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
, 1);
1184 wpa_ie_len
= sizeof(wpa_ie
);
1185 if (wpa_supplicant_set_suites(wpa_s
, bss
, ssid
,
1186 wpa_ie
, &wpa_ie_len
)) {
1187 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to set WPA "
1188 "key management and encryption suites");
1191 } else if (ssid
->key_mgmt
&
1192 (WPA_KEY_MGMT_PSK
| WPA_KEY_MGMT_IEEE8021X
|
1193 WPA_KEY_MGMT_WPA_NONE
| WPA_KEY_MGMT_FT_PSK
|
1194 WPA_KEY_MGMT_FT_IEEE8021X
| WPA_KEY_MGMT_PSK_SHA256
|
1195 WPA_KEY_MGMT_IEEE8021X_SHA256
)) {
1196 wpa_ie_len
= sizeof(wpa_ie
);
1197 if (wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
1198 wpa_ie
, &wpa_ie_len
)) {
1199 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to set WPA "
1200 "key management and encryption suites (no "
1205 } else if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
1206 struct wpabuf
*wps_ie
;
1207 wps_ie
= wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid
));
1208 if (wps_ie
&& wpabuf_len(wps_ie
) <= sizeof(wpa_ie
)) {
1209 wpa_ie_len
= wpabuf_len(wps_ie
);
1210 os_memcpy(wpa_ie
, wpabuf_head(wps_ie
), wpa_ie_len
);
1213 wpabuf_free(wps_ie
);
1214 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
1215 if (!bss
|| (bss
->caps
& IEEE80211_CAP_PRIVACY
))
1216 params
.wps
= WPS_MODE_PRIVACY
;
1218 params
.wps
= WPS_MODE_OPEN
;
1219 #endif /* CONFIG_WPS */
1221 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
1226 if (wpa_s
->global
->p2p
) {
1231 p2p_group
= wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CAPABLE
;
1232 pos
= wpa_ie
+ wpa_ie_len
;
1233 len
= sizeof(wpa_ie
) - wpa_ie_len
;
1234 res
= wpas_p2p_assoc_req_ie(wpa_s
, bss
, pos
, len
, p2p_group
);
1239 wpa_s
->cross_connect_disallowed
= 0;
1242 p2p
= wpa_bss_get_vendor_ie_multi(bss
, P2P_IE_VENDOR_TYPE
);
1244 wpa_s
->cross_connect_disallowed
=
1245 p2p_get_cross_connect_disallowed(p2p
);
1247 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: WLAN AP %s cross "
1249 wpa_s
->cross_connect_disallowed
?
1250 "disallows" : "allows");
1253 #endif /* CONFIG_P2P */
1255 wpa_clear_keys(wpa_s
, bss
? bss
->bssid
: NULL
);
1257 cipher_pairwise
= cipher_suite2driver(wpa_s
->pairwise_cipher
);
1258 cipher_group
= cipher_suite2driver(wpa_s
->group_cipher
);
1259 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1260 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1261 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
)
1263 if (wpa_set_wep_keys(wpa_s
, ssid
)) {
1268 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
)
1271 #ifdef IEEE8021X_EAPOL
1272 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1273 if ((ssid
->eapol_flags
&
1274 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
1275 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
)) == 0 &&
1279 /* Assume that dynamic WEP-104 keys will be used and
1280 * set cipher suites in order for drivers to expect
1282 cipher_pairwise
= cipher_group
= CIPHER_WEP104
;
1285 #endif /* IEEE8021X_EAPOL */
1287 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1288 /* Set the key before (and later after) association */
1289 wpa_supplicant_set_wpa_none_key(wpa_s
, ssid
);
1292 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATING
);
1294 params
.bssid
= bss
->bssid
;
1295 params
.ssid
= bss
->ssid
;
1296 params
.ssid_len
= bss
->ssid_len
;
1297 params
.freq
= bss
->freq
;
1299 params
.ssid
= ssid
->ssid
;
1300 params
.ssid_len
= ssid
->ssid_len
;
1302 if (ssid
->mode
== WPAS_MODE_IBSS
&& ssid
->frequency
> 0 &&
1304 params
.freq
= ssid
->frequency
; /* Initial channel for IBSS */
1305 params
.wpa_ie
= wpa_ie
;
1306 params
.wpa_ie_len
= wpa_ie_len
;
1307 params
.pairwise_suite
= cipher_pairwise
;
1308 params
.group_suite
= cipher_group
;
1309 params
.key_mgmt_suite
= key_mgmt2driver(wpa_s
->key_mgmt
);
1310 params
.auth_alg
= algs
;
1311 params
.mode
= ssid
->mode
;
1312 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
1313 if (ssid
->wep_key_len
[i
])
1314 params
.wep_key
[i
] = ssid
->wep_key
[i
];
1315 params
.wep_key_len
[i
] = ssid
->wep_key_len
[i
];
1317 params
.wep_tx_keyidx
= ssid
->wep_tx_keyidx
;
1319 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1320 (params
.key_mgmt_suite
== KEY_MGMT_PSK
||
1321 params
.key_mgmt_suite
== KEY_MGMT_FT_PSK
)) {
1322 params
.passphrase
= ssid
->passphrase
;
1324 params
.psk
= ssid
->psk
;
1327 params
.drop_unencrypted
= use_crypt
;
1329 #ifdef CONFIG_IEEE80211W
1330 params
.mgmt_frame_protection
= ssid
->ieee80211w
;
1331 if (ssid
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
&& bss
) {
1332 const u8
*rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1333 struct wpa_ie_data ie
;
1334 if (rsn
&& wpa_parse_wpa_ie(rsn
, 2 + rsn
[1], &ie
) == 0 &&
1336 (WPA_CAPABILITY_MFPC
| WPA_CAPABILITY_MFPR
)) {
1337 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Selected AP supports "
1338 "MFP: require MFP");
1339 params
.mgmt_frame_protection
=
1340 MGMT_FRAME_PROTECTION_REQUIRED
;
1343 #endif /* CONFIG_IEEE80211W */
1346 if (wpa_s
->global
->p2p
&&
1347 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CAPABLE
))
1349 #endif /* CONFIG_P2P */
1351 if (wpa_s
->parent
->set_sta_uapsd
)
1352 params
.uapsd
= wpa_s
->parent
->sta_uapsd
;
1356 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
1357 ret
= ieee80211_sta_associate(wpa_s
, ¶ms
);
1359 ret
= wpa_drv_associate(wpa_s
, ¶ms
);
1361 wpa_msg(wpa_s
, MSG_INFO
, "Association request to the driver "
1363 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SANE_ERROR_CODES
) {
1365 * The driver is known to mean what is saying, so we
1366 * can stop right here; the association will not
1369 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1370 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1373 /* try to continue anyway; new association will be tried again
1378 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1379 /* Set the key after the association just in case association
1380 * cleared the previously configured key. */
1381 wpa_supplicant_set_wpa_none_key(wpa_s
, ssid
);
1382 /* No need to timeout authentication since there is no key
1384 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1385 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1386 #ifdef CONFIG_IBSS_RSN
1387 } else if (ssid
->mode
== WPAS_MODE_IBSS
&&
1388 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
1389 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
) {
1390 ibss_rsn_set_psk(wpa_s
->ibss_rsn
, ssid
->psk
);
1392 * RSN IBSS authentication is per-STA and we can disable the
1393 * per-BSSID authentication.
1395 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1396 #endif /* CONFIG_IBSS_RSN */
1398 /* Timeout for IEEE 802.11 authentication and association */
1402 /* give IBSS a bit more time */
1403 timeout
= ssid
->mode
== WPAS_MODE_IBSS
? 10 : 5;
1404 } else if (wpa_s
->conf
->ap_scan
== 1) {
1405 /* give IBSS a bit more time */
1406 timeout
= ssid
->mode
== WPAS_MODE_IBSS
? 20 : 10;
1408 wpa_supplicant_req_auth_timeout(wpa_s
, timeout
, 0);
1411 if (wep_keys_set
&& wpa_drv_get_capa(wpa_s
, &capa
) == 0 &&
1412 capa
.flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC
) {
1413 /* Set static WEP keys again */
1414 wpa_set_wep_keys(wpa_s
, ssid
);
1417 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
) {
1419 * Do not allow EAP session resumption between different
1420 * network configurations.
1422 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
1424 old_ssid
= wpa_s
->current_ssid
;
1425 wpa_s
->current_ssid
= ssid
;
1426 wpa_s
->current_bss
= bss
;
1427 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
1428 wpa_supplicant_initiate_eapol(wpa_s
);
1429 if (old_ssid
!= wpa_s
->current_ssid
)
1430 wpas_notify_network_changed(wpa_s
);
1434 static void wpa_supplicant_clear_connection(struct wpa_supplicant
*wpa_s
,
1437 struct wpa_ssid
*old_ssid
;
1439 wpa_clear_keys(wpa_s
, addr
);
1440 wpa_supplicant_mark_disassoc(wpa_s
);
1441 old_ssid
= wpa_s
->current_ssid
;
1442 wpa_s
->current_ssid
= NULL
;
1443 wpa_s
->current_bss
= NULL
;
1444 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
1445 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
1446 if (old_ssid
!= wpa_s
->current_ssid
)
1447 wpas_notify_network_changed(wpa_s
);
1448 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
1453 * wpa_supplicant_disassociate - Disassociate the current connection
1454 * @wpa_s: Pointer to wpa_supplicant data
1455 * @reason_code: IEEE 802.11 reason code for the disassociate frame
1457 * This function is used to request %wpa_supplicant to disassociate with the
1460 void wpa_supplicant_disassociate(struct wpa_supplicant
*wpa_s
,
1465 if (!is_zero_ether_addr(wpa_s
->bssid
)) {
1466 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
1467 ieee80211_sta_disassociate(wpa_s
, reason_code
);
1469 wpa_drv_disassociate(wpa_s
, wpa_s
->bssid
, reason_code
);
1470 addr
= wpa_s
->bssid
;
1473 wpa_supplicant_clear_connection(wpa_s
, addr
);
1478 * wpa_supplicant_deauthenticate - Deauthenticate the current connection
1479 * @wpa_s: Pointer to wpa_supplicant data
1480 * @reason_code: IEEE 802.11 reason code for the deauthenticate frame
1482 * This function is used to request %wpa_supplicant to deauthenticate from the
1485 void wpa_supplicant_deauthenticate(struct wpa_supplicant
*wpa_s
,
1490 if (!is_zero_ether_addr(wpa_s
->bssid
)) {
1491 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
1492 ieee80211_sta_deauthenticate(wpa_s
, reason_code
);
1494 wpa_drv_deauthenticate(wpa_s
, wpa_s
->bssid
,
1496 addr
= wpa_s
->bssid
;
1499 wpa_supplicant_clear_connection(wpa_s
, addr
);
1504 * wpa_supplicant_enable_network - Mark a configured network as enabled
1505 * @wpa_s: wpa_supplicant structure for a network interface
1506 * @ssid: wpa_ssid structure for a configured network or %NULL
1508 * Enables the specified network or all networks if no network specified.
1510 void wpa_supplicant_enable_network(struct wpa_supplicant
*wpa_s
,
1511 struct wpa_ssid
*ssid
)
1513 struct wpa_ssid
*other_ssid
;
1517 for (other_ssid
= wpa_s
->conf
->ssid
; other_ssid
;
1518 other_ssid
= other_ssid
->next
) {
1519 if (other_ssid
->disabled
== 2)
1520 continue; /* do not change persistent P2P group
1522 if (other_ssid
== wpa_s
->current_ssid
&&
1523 other_ssid
->disabled
)
1524 wpa_s
->reassociate
= 1;
1526 was_disabled
= other_ssid
->disabled
;
1528 other_ssid
->disabled
= 0;
1530 if (was_disabled
!= other_ssid
->disabled
)
1531 wpas_notify_network_enabled_changed(
1534 if (wpa_s
->reassociate
)
1535 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1536 } else if (ssid
->disabled
&& ssid
->disabled
!= 2) {
1537 if (wpa_s
->current_ssid
== NULL
) {
1539 * Try to reassociate since there is no current
1540 * configuration and a new network was made available.
1542 wpa_s
->reassociate
= 1;
1543 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1546 was_disabled
= ssid
->disabled
;
1550 if (was_disabled
!= ssid
->disabled
)
1551 wpas_notify_network_enabled_changed(wpa_s
, ssid
);
1557 * wpa_supplicant_disable_network - Mark a configured network as disabled
1558 * @wpa_s: wpa_supplicant structure for a network interface
1559 * @ssid: wpa_ssid structure for a configured network or %NULL
1561 * Disables the specified network or all networks if no network specified.
1563 void wpa_supplicant_disable_network(struct wpa_supplicant
*wpa_s
,
1564 struct wpa_ssid
*ssid
)
1566 struct wpa_ssid
*other_ssid
;
1570 for (other_ssid
= wpa_s
->conf
->ssid
; other_ssid
;
1571 other_ssid
= other_ssid
->next
) {
1572 was_disabled
= other_ssid
->disabled
;
1573 if (was_disabled
== 2)
1574 continue; /* do not change persistent P2P group
1577 other_ssid
->disabled
= 1;
1579 if (was_disabled
!= other_ssid
->disabled
)
1580 wpas_notify_network_enabled_changed(
1583 if (wpa_s
->current_ssid
)
1584 wpa_supplicant_disassociate(
1585 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1586 } else if (ssid
->disabled
!= 2) {
1587 if (ssid
== wpa_s
->current_ssid
)
1588 wpa_supplicant_disassociate(
1589 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1591 was_disabled
= ssid
->disabled
;
1595 if (was_disabled
!= ssid
->disabled
)
1596 wpas_notify_network_enabled_changed(wpa_s
, ssid
);
1602 * wpa_supplicant_select_network - Attempt association with a network
1603 * @wpa_s: wpa_supplicant structure for a network interface
1604 * @ssid: wpa_ssid structure for a configured network or %NULL for any network
1606 void wpa_supplicant_select_network(struct wpa_supplicant
*wpa_s
,
1607 struct wpa_ssid
*ssid
)
1610 struct wpa_ssid
*other_ssid
;
1612 if (ssid
&& ssid
!= wpa_s
->current_ssid
&& wpa_s
->current_ssid
)
1613 wpa_supplicant_disassociate(
1614 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1617 * Mark all other networks disabled or mark all networks enabled if no
1618 * network specified.
1620 for (other_ssid
= wpa_s
->conf
->ssid
; other_ssid
;
1621 other_ssid
= other_ssid
->next
) {
1622 int was_disabled
= other_ssid
->disabled
;
1623 if (was_disabled
== 2)
1624 continue; /* do not change persistent P2P group data */
1626 other_ssid
->disabled
= ssid
? (ssid
->id
!= other_ssid
->id
) : 0;
1628 if (was_disabled
!= other_ssid
->disabled
)
1629 wpas_notify_network_enabled_changed(wpa_s
, other_ssid
);
1631 wpa_s
->disconnected
= 0;
1632 wpa_s
->reassociate
= 1;
1633 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1636 wpas_notify_network_selected(wpa_s
, ssid
);
1641 * wpa_supplicant_set_ap_scan - Set AP scan mode for interface
1642 * @wpa_s: wpa_supplicant structure for a network interface
1643 * @ap_scan: AP scan mode
1644 * Returns: 0 if succeed or -1 if ap_scan has an invalid value
1647 int wpa_supplicant_set_ap_scan(struct wpa_supplicant
*wpa_s
, int ap_scan
)
1652 if (ap_scan
< 0 || ap_scan
> 2)
1655 old_ap_scan
= wpa_s
->conf
->ap_scan
;
1656 wpa_s
->conf
->ap_scan
= ap_scan
;
1658 if (old_ap_scan
!= wpa_s
->conf
->ap_scan
)
1659 wpas_notify_ap_scan_changed(wpa_s
);
1666 * wpa_supplicant_set_bss_expiration_age - Set BSS entry expiration age
1667 * @wpa_s: wpa_supplicant structure for a network interface
1668 * @expire_age: Expiration age in seconds
1669 * Returns: 0 if succeed or -1 if expire_age has an invalid value
1672 int wpa_supplicant_set_bss_expiration_age(struct wpa_supplicant
*wpa_s
,
1673 unsigned int bss_expire_age
)
1675 if (bss_expire_age
< 10) {
1676 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid bss expiration age %u",
1680 wpa_msg(wpa_s
, MSG_DEBUG
, "Setting bss expiration age: %d sec",
1682 wpa_s
->conf
->bss_expiration_age
= bss_expire_age
;
1689 * wpa_supplicant_set_bss_expiration_count - Set BSS entry expiration scan count
1690 * @wpa_s: wpa_supplicant structure for a network interface
1691 * @expire_count: number of scans after which an unseen BSS is reclaimed
1692 * Returns: 0 if succeed or -1 if expire_count has an invalid value
1695 int wpa_supplicant_set_bss_expiration_count(struct wpa_supplicant
*wpa_s
,
1696 unsigned int bss_expire_count
)
1698 if (bss_expire_count
< 1) {
1699 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid bss expiration count %u",
1703 wpa_msg(wpa_s
, MSG_DEBUG
, "Setting bss expiration scan count: %u",
1705 wpa_s
->conf
->bss_expiration_scan_count
= bss_expire_count
;
1712 * wpa_supplicant_set_debug_params - Set global debug params
1713 * @global: wpa_global structure
1714 * @debug_level: debug level
1715 * @debug_timestamp: determines if show timestamp in debug data
1716 * @debug_show_keys: determines if show keys in debug data
1717 * Returns: 0 if succeed or -1 if debug_level has wrong value
1719 int wpa_supplicant_set_debug_params(struct wpa_global
*global
, int debug_level
,
1720 int debug_timestamp
, int debug_show_keys
)
1723 int old_level
, old_timestamp
, old_show_keys
;
1725 /* check for allowed debuglevels */
1726 if (debug_level
!= MSG_MSGDUMP
&&
1727 debug_level
!= MSG_DEBUG
&&
1728 debug_level
!= MSG_INFO
&&
1729 debug_level
!= MSG_WARNING
&&
1730 debug_level
!= MSG_ERROR
)
1733 old_level
= wpa_debug_level
;
1734 old_timestamp
= wpa_debug_timestamp
;
1735 old_show_keys
= wpa_debug_show_keys
;
1737 wpa_debug_level
= debug_level
;
1738 wpa_debug_timestamp
= debug_timestamp
? 1 : 0;
1739 wpa_debug_show_keys
= debug_show_keys
? 1 : 0;
1741 if (wpa_debug_level
!= old_level
)
1742 wpas_notify_debug_level_changed(global
);
1743 if (wpa_debug_timestamp
!= old_timestamp
)
1744 wpas_notify_debug_timestamp_changed(global
);
1745 if (wpa_debug_show_keys
!= old_show_keys
)
1746 wpas_notify_debug_show_keys_changed(global
);
1753 * wpa_supplicant_get_ssid - Get a pointer to the current network structure
1754 * @wpa_s: Pointer to wpa_supplicant data
1755 * Returns: A pointer to the current network structure or %NULL on failure
1757 struct wpa_ssid
* wpa_supplicant_get_ssid(struct wpa_supplicant
*wpa_s
)
1759 struct wpa_ssid
*entry
;
1760 u8 ssid
[MAX_SSID_LEN
];
1766 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
) {
1767 if (ieee80211_sta_get_ssid(wpa_s
, ssid
, &ssid_len
)) {
1768 wpa_msg(wpa_s
, MSG_WARNING
, "Could not read SSID from "
1773 res
= wpa_drv_get_ssid(wpa_s
, ssid
);
1775 wpa_msg(wpa_s
, MSG_WARNING
, "Could not read SSID from "
1782 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
1783 os_memcpy(bssid
, wpa_s
->bssid
, ETH_ALEN
);
1784 else if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0) {
1785 wpa_msg(wpa_s
, MSG_WARNING
, "Could not read BSSID from "
1790 wired
= wpa_s
->conf
->ap_scan
== 0 &&
1791 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
);
1793 entry
= wpa_s
->conf
->ssid
;
1795 if (!entry
->disabled
&&
1796 ((ssid_len
== entry
->ssid_len
&&
1797 os_memcmp(ssid
, entry
->ssid
, ssid_len
) == 0) || wired
) &&
1798 (!entry
->bssid_set
||
1799 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0))
1802 if (!entry
->disabled
&&
1803 (entry
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
1804 (entry
->ssid
== NULL
|| entry
->ssid_len
== 0) &&
1805 (!entry
->bssid_set
||
1806 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0))
1808 #endif /* CONFIG_WPS */
1809 entry
= entry
->next
;
1816 static int wpa_supplicant_set_driver(struct wpa_supplicant
*wpa_s
,
1821 const char *pos
, *driver
= name
;
1826 if (wpa_drivers
[0] == NULL
) {
1827 wpa_msg(wpa_s
, MSG_ERROR
, "No driver interfaces build into "
1833 /* default to first driver in the list */
1834 wpa_s
->driver
= wpa_drivers
[0];
1835 wpa_s
->global_drv_priv
= wpa_s
->global
->drv_priv
[0];
1840 pos
= os_strchr(driver
, ',');
1844 len
= os_strlen(driver
);
1846 for (i
= 0; wpa_drivers
[i
]; i
++) {
1847 if (os_strlen(wpa_drivers
[i
]->name
) == len
&&
1848 os_strncmp(driver
, wpa_drivers
[i
]->name
, len
) ==
1850 wpa_s
->driver
= wpa_drivers
[i
];
1851 wpa_s
->global_drv_priv
=
1852 wpa_s
->global
->drv_priv
[i
];
1860 wpa_msg(wpa_s
, MSG_ERROR
, "Unsupported driver '%s'", name
);
1866 * wpa_supplicant_rx_eapol - Deliver a received EAPOL frame to wpa_supplicant
1867 * @ctx: Context pointer (wpa_s); this is the ctx variable registered
1868 * with struct wpa_driver_ops::init()
1869 * @src_addr: Source address of the EAPOL frame
1870 * @buf: EAPOL data starting from the EAPOL header (i.e., no Ethernet header)
1871 * @len: Length of the EAPOL data
1873 * This function is called for each received EAPOL frame. Most driver
1874 * interfaces rely on more generic OS mechanism for receiving frames through
1875 * l2_packet, but if such a mechanism is not available, the driver wrapper may
1876 * take care of received EAPOL frames and deliver them to the core supplicant
1877 * code by calling this function.
1879 void wpa_supplicant_rx_eapol(void *ctx
, const u8
*src_addr
,
1880 const u8
*buf
, size_t len
)
1882 struct wpa_supplicant
*wpa_s
= ctx
;
1884 wpa_dbg(wpa_s
, MSG_DEBUG
, "RX EAPOL from " MACSTR
, MAC2STR(src_addr
));
1885 wpa_hexdump(MSG_MSGDUMP
, "RX EAPOL", buf
, len
);
1887 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
) {
1889 * There is possible race condition between receiving the
1890 * association event and the EAPOL frame since they are coming
1891 * through different paths from the driver. In order to avoid
1892 * issues in trying to process the EAPOL frame before receiving
1893 * association information, lets queue it for processing until
1894 * the association event is received.
1896 wpa_dbg(wpa_s
, MSG_DEBUG
, "Not associated - Delay processing "
1897 "of received EAPOL frame");
1898 wpabuf_free(wpa_s
->pending_eapol_rx
);
1899 wpa_s
->pending_eapol_rx
= wpabuf_alloc_copy(buf
, len
);
1900 if (wpa_s
->pending_eapol_rx
) {
1901 os_get_time(&wpa_s
->pending_eapol_rx_time
);
1902 os_memcpy(wpa_s
->pending_eapol_rx_src
, src_addr
,
1909 if (wpa_s
->ap_iface
) {
1910 wpa_supplicant_ap_rx_eapol(wpa_s
, src_addr
, buf
, len
);
1913 #endif /* CONFIG_AP */
1915 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
) {
1916 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignored received EAPOL frame since "
1917 "no key management is configured");
1921 if (wpa_s
->eapol_received
== 0 &&
1922 (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) ||
1923 !wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
1924 wpa_s
->wpa_state
!= WPA_COMPLETED
) &&
1925 (wpa_s
->current_ssid
== NULL
||
1926 wpa_s
->current_ssid
->mode
!= IEEE80211_MODE_IBSS
)) {
1927 /* Timeout for completing IEEE 802.1X and WPA authentication */
1928 wpa_supplicant_req_auth_timeout(
1930 (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
1931 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
||
1932 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
) ?
1935 wpa_s
->eapol_received
++;
1937 if (wpa_s
->countermeasures
) {
1938 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Countermeasures - dropped "
1943 #ifdef CONFIG_IBSS_RSN
1944 if (wpa_s
->current_ssid
&&
1945 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
) {
1946 ibss_rsn_rx_eapol(wpa_s
->ibss_rsn
, src_addr
, buf
, len
);
1949 #endif /* CONFIG_IBSS_RSN */
1951 /* Source address of the incoming EAPOL frame could be compared to the
1952 * current BSSID. However, it is possible that a centralized
1953 * Authenticator could be using another MAC address than the BSSID of
1954 * an AP, so just allow any address to be used for now. The replies are
1955 * still sent to the current BSSID (if available), though. */
1957 os_memcpy(wpa_s
->last_eapol_src
, src_addr
, ETH_ALEN
);
1958 if (!wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) &&
1959 eapol_sm_rx_eapol(wpa_s
->eapol
, src_addr
, buf
, len
) > 0)
1961 wpa_drv_poll(wpa_s
);
1962 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
))
1963 wpa_sm_rx_eapol(wpa_s
->wpa
, src_addr
, buf
, len
);
1964 else if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1966 * Set portValid = TRUE here since we are going to skip 4-way
1967 * handshake processing which would normally set portValid. We
1968 * need this to allow the EAPOL state machines to be completed
1969 * without going through EAPOL-Key handshake.
1971 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1977 * wpa_supplicant_driver_init - Initialize driver interface parameters
1978 * @wpa_s: Pointer to wpa_supplicant data
1979 * Returns: 0 on success, -1 on failure
1981 * This function is called to initialize driver interface parameters.
1982 * wpa_drv_init() must have been called before this function to initialize the
1985 int wpa_supplicant_driver_init(struct wpa_supplicant
*wpa_s
)
1987 static int interface_count
= 0;
1989 if (wpa_s
->driver
->send_eapol
) {
1990 const u8
*addr
= wpa_drv_get_mac_addr(wpa_s
);
1992 os_memcpy(wpa_s
->own_addr
, addr
, ETH_ALEN
);
1993 } else if (!(wpa_s
->drv_flags
&
1994 WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE
)) {
1995 wpa_s
->l2
= l2_packet_init(wpa_s
->ifname
,
1996 wpa_drv_get_mac_addr(wpa_s
),
1998 wpa_supplicant_rx_eapol
, wpa_s
, 0);
1999 if (wpa_s
->l2
== NULL
)
2002 const u8
*addr
= wpa_drv_get_mac_addr(wpa_s
);
2004 os_memcpy(wpa_s
->own_addr
, addr
, ETH_ALEN
);
2007 if (wpa_s
->l2
&& l2_packet_get_own_addr(wpa_s
->l2
, wpa_s
->own_addr
)) {
2008 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to get own L2 address");
2012 wpa_dbg(wpa_s
, MSG_DEBUG
, "Own MAC address: " MACSTR
,
2013 MAC2STR(wpa_s
->own_addr
));
2015 if (wpa_s
->bridge_ifname
[0]) {
2016 wpa_dbg(wpa_s
, MSG_DEBUG
, "Receiving packets from bridge "
2017 "interface '%s'", wpa_s
->bridge_ifname
);
2018 wpa_s
->l2_br
= l2_packet_init(wpa_s
->bridge_ifname
,
2021 wpa_supplicant_rx_eapol
, wpa_s
,
2023 if (wpa_s
->l2_br
== NULL
) {
2024 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to open l2_packet "
2025 "connection for the bridge interface '%s'",
2026 wpa_s
->bridge_ifname
);
2031 wpa_clear_keys(wpa_s
, NULL
);
2033 /* Make sure that TKIP countermeasures are not left enabled (could
2034 * happen if wpa_supplicant is killed during countermeasures. */
2035 wpa_drv_set_countermeasures(wpa_s
, 0);
2037 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: flushing PMKID list in the driver");
2038 wpa_drv_flush_pmkid(wpa_s
);
2040 wpa_s
->prev_scan_ssid
= WILDCARD_SSID_SCAN
;
2041 if (wpa_supplicant_enabled_networks(wpa_s
->conf
)) {
2042 wpa_supplicant_req_scan(wpa_s
, interface_count
, 100000);
2045 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
2051 static int wpa_supplicant_daemon(const char *pid_file
)
2053 wpa_printf(MSG_DEBUG
, "Daemonize..");
2054 return os_daemonize(pid_file
);
2058 static struct wpa_supplicant
* wpa_supplicant_alloc(void)
2060 struct wpa_supplicant
*wpa_s
;
2062 wpa_s
= os_zalloc(sizeof(*wpa_s
));
2065 wpa_s
->scan_req
= 1;
2066 wpa_s
->new_connection
= 1;
2067 wpa_s
->parent
= wpa_s
;
2073 static int wpa_supplicant_init_iface(struct wpa_supplicant
*wpa_s
,
2074 struct wpa_interface
*iface
)
2076 const char *ifname
, *driver
;
2077 struct wpa_driver_capa capa
;
2079 wpa_printf(MSG_DEBUG
, "Initializing interface '%s' conf '%s' driver "
2080 "'%s' ctrl_interface '%s' bridge '%s'", iface
->ifname
,
2081 iface
->confname
? iface
->confname
: "N/A",
2082 iface
->driver
? iface
->driver
: "default",
2083 iface
->ctrl_interface
? iface
->ctrl_interface
: "N/A",
2084 iface
->bridge_ifname
? iface
->bridge_ifname
: "N/A");
2086 if (iface
->confname
) {
2087 #ifdef CONFIG_BACKEND_FILE
2088 wpa_s
->confname
= os_rel2abs_path(iface
->confname
);
2089 if (wpa_s
->confname
== NULL
) {
2090 wpa_printf(MSG_ERROR
, "Failed to get absolute path "
2091 "for configuration file '%s'.",
2095 wpa_printf(MSG_DEBUG
, "Configuration file '%s' -> '%s'",
2096 iface
->confname
, wpa_s
->confname
);
2097 #else /* CONFIG_BACKEND_FILE */
2098 wpa_s
->confname
= os_strdup(iface
->confname
);
2099 #endif /* CONFIG_BACKEND_FILE */
2100 wpa_s
->conf
= wpa_config_read(wpa_s
->confname
);
2101 if (wpa_s
->conf
== NULL
) {
2102 wpa_printf(MSG_ERROR
, "Failed to read or parse "
2103 "configuration '%s'.", wpa_s
->confname
);
2108 * Override ctrl_interface and driver_param if set on command
2111 if (iface
->ctrl_interface
) {
2112 os_free(wpa_s
->conf
->ctrl_interface
);
2113 wpa_s
->conf
->ctrl_interface
=
2114 os_strdup(iface
->ctrl_interface
);
2117 if (iface
->driver_param
) {
2118 os_free(wpa_s
->conf
->driver_param
);
2119 wpa_s
->conf
->driver_param
=
2120 os_strdup(iface
->driver_param
);
2123 wpa_s
->conf
= wpa_config_alloc_empty(iface
->ctrl_interface
,
2124 iface
->driver_param
);
2126 if (wpa_s
->conf
== NULL
) {
2127 wpa_printf(MSG_ERROR
, "\nNo configuration found.");
2131 if (iface
->ifname
== NULL
) {
2132 wpa_printf(MSG_ERROR
, "\nInterface name is required.");
2135 if (os_strlen(iface
->ifname
) >= sizeof(wpa_s
->ifname
)) {
2136 wpa_printf(MSG_ERROR
, "\nToo long interface name '%s'.",
2140 os_strlcpy(wpa_s
->ifname
, iface
->ifname
, sizeof(wpa_s
->ifname
));
2142 if (iface
->bridge_ifname
) {
2143 if (os_strlen(iface
->bridge_ifname
) >=
2144 sizeof(wpa_s
->bridge_ifname
)) {
2145 wpa_printf(MSG_ERROR
, "\nToo long bridge interface "
2146 "name '%s'.", iface
->bridge_ifname
);
2149 os_strlcpy(wpa_s
->bridge_ifname
, iface
->bridge_ifname
,
2150 sizeof(wpa_s
->bridge_ifname
));
2153 /* RSNA Supplicant Key Management - INITIALIZE */
2154 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
2155 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
2157 /* Initialize driver interface and register driver event handler before
2158 * L2 receive handler so that association events are processed before
2159 * EAPOL-Key packets if both become available for the same select()
2161 driver
= iface
->driver
;
2163 if (wpa_supplicant_set_driver(wpa_s
, driver
) < 0)
2166 wpa_s
->drv_priv
= wpa_drv_init(wpa_s
, wpa_s
->ifname
);
2167 if (wpa_s
->drv_priv
== NULL
) {
2169 pos
= driver
? os_strchr(driver
, ',') : NULL
;
2171 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to initialize "
2172 "driver interface - try next driver wrapper");
2176 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to initialize driver "
2180 if (wpa_drv_set_param(wpa_s
, wpa_s
->conf
->driver_param
) < 0) {
2181 wpa_msg(wpa_s
, MSG_ERROR
, "Driver interface rejected "
2182 "driver_param '%s'", wpa_s
->conf
->driver_param
);
2186 ifname
= wpa_drv_get_ifname(wpa_s
);
2187 if (ifname
&& os_strcmp(ifname
, wpa_s
->ifname
) != 0) {
2188 wpa_dbg(wpa_s
, MSG_DEBUG
, "Driver interface replaced "
2189 "interface name with '%s'", ifname
);
2190 os_strlcpy(wpa_s
->ifname
, ifname
, sizeof(wpa_s
->ifname
));
2193 if (wpa_supplicant_init_wpa(wpa_s
) < 0)
2196 wpa_sm_set_ifname(wpa_s
->wpa
, wpa_s
->ifname
,
2197 wpa_s
->bridge_ifname
[0] ? wpa_s
->bridge_ifname
:
2199 wpa_sm_set_fast_reauth(wpa_s
->wpa
, wpa_s
->conf
->fast_reauth
);
2201 if (wpa_s
->conf
->dot11RSNAConfigPMKLifetime
&&
2202 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
2203 wpa_s
->conf
->dot11RSNAConfigPMKLifetime
)) {
2204 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid WPA parameter value for "
2205 "dot11RSNAConfigPMKLifetime");
2209 if (wpa_s
->conf
->dot11RSNAConfigPMKReauthThreshold
&&
2210 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
2211 wpa_s
->conf
->dot11RSNAConfigPMKReauthThreshold
)) {
2212 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid WPA parameter value for "
2213 "dot11RSNAConfigPMKReauthThreshold");
2217 if (wpa_s
->conf
->dot11RSNAConfigSATimeout
&&
2218 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
,
2219 wpa_s
->conf
->dot11RSNAConfigSATimeout
)) {
2220 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid WPA parameter value for "
2221 "dot11RSNAConfigSATimeout");
2225 if (wpa_drv_get_capa(wpa_s
, &capa
) == 0) {
2226 wpa_s
->drv_flags
= capa
.flags
;
2227 if (capa
.flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
) {
2228 if (ieee80211_sta_init(wpa_s
))
2231 wpa_s
->max_scan_ssids
= capa
.max_scan_ssids
;
2232 wpa_s
->max_remain_on_chan
= capa
.max_remain_on_chan
;
2233 wpa_s
->max_stations
= capa
.max_stations
;
2235 if (wpa_s
->max_remain_on_chan
== 0)
2236 wpa_s
->max_remain_on_chan
= 1000;
2238 if (wpa_supplicant_driver_init(wpa_s
) < 0)
2242 if (wpa_tdls_init(wpa_s
->wpa
))
2244 #endif /* CONFIG_TDLS */
2246 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1] &&
2247 wpa_drv_set_country(wpa_s
, wpa_s
->conf
->country
)) {
2248 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to set country");
2252 wpa_sm_set_own_addr(wpa_s
->wpa
, wpa_s
->own_addr
);
2254 if (wpas_wps_init(wpa_s
))
2257 if (wpa_supplicant_init_eapol(wpa_s
) < 0)
2259 wpa_sm_set_eapol(wpa_s
->wpa
, wpa_s
->eapol
);
2261 wpa_s
->ctrl_iface
= wpa_supplicant_ctrl_iface_init(wpa_s
);
2262 if (wpa_s
->ctrl_iface
== NULL
) {
2263 wpa_printf(MSG_ERROR
,
2264 "Failed to initialize control interface '%s'.\n"
2265 "You may have another wpa_supplicant process "
2266 "already running or the file was\n"
2267 "left by an unclean termination of wpa_supplicant "
2268 "in which case you will need\n"
2269 "to manually remove this file before starting "
2270 "wpa_supplicant again.\n",
2271 wpa_s
->conf
->ctrl_interface
);
2275 #ifdef CONFIG_IBSS_RSN
2276 wpa_s
->ibss_rsn
= ibss_rsn_init(wpa_s
);
2277 if (!wpa_s
->ibss_rsn
) {
2278 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to init IBSS RSN");
2281 #endif /* CONFIG_IBSS_RSN */
2284 if (wpas_p2p_init(wpa_s
->global
, wpa_s
) < 0) {
2285 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to init P2P");
2288 #endif /* CONFIG_P2P */
2290 if (wpa_bss_init(wpa_s
) < 0)
2297 static void wpa_supplicant_deinit_iface(struct wpa_supplicant
*wpa_s
,
2300 if (wpa_s
->drv_priv
) {
2301 wpa_supplicant_deauthenticate(wpa_s
,
2302 WLAN_REASON_DEAUTH_LEAVING
);
2304 wpa_drv_set_countermeasures(wpa_s
, 0);
2305 wpa_clear_keys(wpa_s
, NULL
);
2308 wpa_supplicant_cleanup(wpa_s
);
2311 wpas_notify_iface_removed(wpa_s
);
2313 if (wpa_s
->drv_priv
)
2314 wpa_drv_deinit(wpa_s
);
2319 * wpa_supplicant_add_iface - Add a new network interface
2320 * @global: Pointer to global data from wpa_supplicant_init()
2321 * @iface: Interface configuration options
2322 * Returns: Pointer to the created interface or %NULL on failure
2324 * This function is used to add new network interfaces for %wpa_supplicant.
2325 * This can be called before wpa_supplicant_run() to add interfaces before the
2326 * main event loop has been started. In addition, new interfaces can be added
2327 * dynamically while %wpa_supplicant is already running. This could happen,
2328 * e.g., when a hotplug network adapter is inserted.
2330 struct wpa_supplicant
* wpa_supplicant_add_iface(struct wpa_global
*global
,
2331 struct wpa_interface
*iface
)
2333 struct wpa_supplicant
*wpa_s
;
2334 struct wpa_interface t_iface
;
2335 struct wpa_ssid
*ssid
;
2337 if (global
== NULL
|| iface
== NULL
)
2340 wpa_s
= wpa_supplicant_alloc();
2344 wpa_s
->global
= global
;
2347 if (global
->params
.override_driver
) {
2348 wpa_printf(MSG_DEBUG
, "Override interface parameter: driver "
2350 iface
->driver
, global
->params
.override_driver
);
2351 t_iface
.driver
= global
->params
.override_driver
;
2353 if (global
->params
.override_ctrl_interface
) {
2354 wpa_printf(MSG_DEBUG
, "Override interface parameter: "
2355 "ctrl_interface ('%s' -> '%s')",
2356 iface
->ctrl_interface
,
2357 global
->params
.override_ctrl_interface
);
2358 t_iface
.ctrl_interface
=
2359 global
->params
.override_ctrl_interface
;
2361 if (wpa_supplicant_init_iface(wpa_s
, &t_iface
)) {
2362 wpa_printf(MSG_DEBUG
, "Failed to add interface %s",
2364 wpa_supplicant_deinit_iface(wpa_s
, 0);
2369 /* Notify the control interfaces about new iface */
2370 if (wpas_notify_iface_added(wpa_s
)) {
2371 wpa_supplicant_deinit_iface(wpa_s
, 1);
2376 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
)
2377 wpas_notify_network_added(wpa_s
, ssid
);
2379 wpa_s
->next
= global
->ifaces
;
2380 global
->ifaces
= wpa_s
;
2382 wpa_dbg(wpa_s
, MSG_DEBUG
, "Added interface %s", wpa_s
->ifname
);
2389 * wpa_supplicant_remove_iface - Remove a network interface
2390 * @global: Pointer to global data from wpa_supplicant_init()
2391 * @wpa_s: Pointer to the network interface to be removed
2392 * Returns: 0 if interface was removed, -1 if interface was not found
2394 * This function can be used to dynamically remove network interfaces from
2395 * %wpa_supplicant, e.g., when a hotplug network adapter is ejected. In
2396 * addition, this function is used to remove all remaining interfaces when
2397 * %wpa_supplicant is terminated.
2399 int wpa_supplicant_remove_iface(struct wpa_global
*global
,
2400 struct wpa_supplicant
*wpa_s
)
2402 struct wpa_supplicant
*prev
;
2404 /* Remove interface from the global list of interfaces */
2405 prev
= global
->ifaces
;
2406 if (prev
== wpa_s
) {
2407 global
->ifaces
= wpa_s
->next
;
2409 while (prev
&& prev
->next
!= wpa_s
)
2413 prev
->next
= wpa_s
->next
;
2416 wpa_dbg(wpa_s
, MSG_DEBUG
, "Removing interface %s", wpa_s
->ifname
);
2418 if (global
->p2p_group_formation
== wpa_s
)
2419 global
->p2p_group_formation
= NULL
;
2420 wpa_supplicant_deinit_iface(wpa_s
, 1);
2428 * wpa_supplicant_get_eap_mode - Get the current EAP mode
2429 * @wpa_s: Pointer to the network interface
2430 * Returns: Pointer to the eap mode or the string "UNKNOWN" if not found
2432 const char * wpa_supplicant_get_eap_mode(struct wpa_supplicant
*wpa_s
)
2434 const char *eapol_method
;
2436 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) == 0 &&
2437 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
2441 eapol_method
= eapol_sm_get_method_name(wpa_s
->eapol
);
2442 if (eapol_method
== NULL
)
2443 return "UNKNOWN-EAP";
2445 return eapol_method
;
2450 * wpa_supplicant_get_iface - Get a new network interface
2451 * @global: Pointer to global data from wpa_supplicant_init()
2452 * @ifname: Interface name
2453 * Returns: Pointer to the interface or %NULL if not found
2455 struct wpa_supplicant
* wpa_supplicant_get_iface(struct wpa_global
*global
,
2458 struct wpa_supplicant
*wpa_s
;
2460 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2461 if (os_strcmp(wpa_s
->ifname
, ifname
) == 0)
2468 #ifndef CONFIG_NO_WPA_MSG
2469 static const char * wpa_supplicant_msg_ifname_cb(void *ctx
)
2471 struct wpa_supplicant
*wpa_s
= ctx
;
2474 return wpa_s
->ifname
;
2476 #endif /* CONFIG_NO_WPA_MSG */
2480 * wpa_supplicant_init - Initialize %wpa_supplicant
2481 * @params: Parameters for %wpa_supplicant
2482 * Returns: Pointer to global %wpa_supplicant data, or %NULL on failure
2484 * This function is used to initialize %wpa_supplicant. After successful
2485 * initialization, the returned data pointer can be used to add and remove
2486 * network interfaces, and eventually, to deinitialize %wpa_supplicant.
2488 struct wpa_global
* wpa_supplicant_init(struct wpa_params
*params
)
2490 struct wpa_global
*global
;
2496 #ifndef CONFIG_NO_WPA_MSG
2497 wpa_msg_register_ifname_cb(wpa_supplicant_msg_ifname_cb
);
2498 #endif /* CONFIG_NO_WPA_MSG */
2500 wpa_debug_open_file(params
->wpa_debug_file_path
);
2501 if (params
->wpa_debug_syslog
)
2502 wpa_debug_open_syslog();
2504 ret
= eap_register_methods();
2506 wpa_printf(MSG_ERROR
, "Failed to register EAP methods");
2508 wpa_printf(MSG_ERROR
, "Two or more EAP methods used "
2509 "the same EAP type.");
2513 global
= os_zalloc(sizeof(*global
));
2516 dl_list_init(&global
->p2p_srv_bonjour
);
2517 dl_list_init(&global
->p2p_srv_upnp
);
2518 global
->params
.daemonize
= params
->daemonize
;
2519 global
->params
.wait_for_monitor
= params
->wait_for_monitor
;
2520 global
->params
.dbus_ctrl_interface
= params
->dbus_ctrl_interface
;
2521 if (params
->pid_file
)
2522 global
->params
.pid_file
= os_strdup(params
->pid_file
);
2523 if (params
->ctrl_interface
)
2524 global
->params
.ctrl_interface
=
2525 os_strdup(params
->ctrl_interface
);
2526 if (params
->override_driver
)
2527 global
->params
.override_driver
=
2528 os_strdup(params
->override_driver
);
2529 if (params
->override_ctrl_interface
)
2530 global
->params
.override_ctrl_interface
=
2531 os_strdup(params
->override_ctrl_interface
);
2532 wpa_debug_level
= global
->params
.wpa_debug_level
=
2533 params
->wpa_debug_level
;
2534 wpa_debug_show_keys
= global
->params
.wpa_debug_show_keys
=
2535 params
->wpa_debug_show_keys
;
2536 wpa_debug_timestamp
= global
->params
.wpa_debug_timestamp
=
2537 params
->wpa_debug_timestamp
;
2539 wpa_printf(MSG_DEBUG
, "wpa_supplicant v" VERSION_STR
);
2542 wpa_printf(MSG_ERROR
, "Failed to initialize event loop");
2543 wpa_supplicant_deinit(global
);
2549 global
->ctrl_iface
= wpa_supplicant_global_ctrl_iface_init(global
);
2550 if (global
->ctrl_iface
== NULL
) {
2551 wpa_supplicant_deinit(global
);
2555 if (wpas_notify_supplicant_initialized(global
)) {
2556 wpa_supplicant_deinit(global
);
2560 for (i
= 0; wpa_drivers
[i
]; i
++)
2561 global
->drv_count
++;
2562 if (global
->drv_count
== 0) {
2563 wpa_printf(MSG_ERROR
, "No drivers enabled");
2564 wpa_supplicant_deinit(global
);
2567 global
->drv_priv
= os_zalloc(global
->drv_count
* sizeof(void *));
2568 if (global
->drv_priv
== NULL
) {
2569 wpa_supplicant_deinit(global
);
2572 for (i
= 0; wpa_drivers
[i
]; i
++) {
2573 if (!wpa_drivers
[i
]->global_init
)
2575 global
->drv_priv
[i
] = wpa_drivers
[i
]->global_init();
2576 if (global
->drv_priv
[i
] == NULL
) {
2577 wpa_printf(MSG_ERROR
, "Failed to initialize driver "
2578 "'%s'", wpa_drivers
[i
]->name
);
2579 wpa_supplicant_deinit(global
);
2589 * wpa_supplicant_run - Run the %wpa_supplicant main event loop
2590 * @global: Pointer to global data from wpa_supplicant_init()
2591 * Returns: 0 after successful event loop run, -1 on failure
2593 * This function starts the main event loop and continues running as long as
2594 * there are any remaining events. In most cases, this function is running as
2595 * long as the %wpa_supplicant process in still in use.
2597 int wpa_supplicant_run(struct wpa_global
*global
)
2599 struct wpa_supplicant
*wpa_s
;
2601 if (global
->params
.daemonize
&&
2602 wpa_supplicant_daemon(global
->params
.pid_file
))
2605 if (global
->params
.wait_for_monitor
) {
2606 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
)
2607 if (wpa_s
->ctrl_iface
)
2608 wpa_supplicant_ctrl_iface_wait(
2612 eloop_register_signal_terminate(wpa_supplicant_terminate
, global
);
2613 eloop_register_signal_reconfig(wpa_supplicant_reconfig
, global
);
2622 * wpa_supplicant_deinit - Deinitialize %wpa_supplicant
2623 * @global: Pointer to global data from wpa_supplicant_init()
2625 * This function is called to deinitialize %wpa_supplicant and to free all
2626 * allocated resources. Remaining network interfaces will also be removed.
2628 void wpa_supplicant_deinit(struct wpa_global
*global
)
2636 wpas_p2p_deinit_global(global
);
2637 #endif /* CONFIG_P2P */
2639 while (global
->ifaces
)
2640 wpa_supplicant_remove_iface(global
, global
->ifaces
);
2642 if (global
->ctrl_iface
)
2643 wpa_supplicant_global_ctrl_iface_deinit(global
->ctrl_iface
);
2645 wpas_notify_supplicant_deinitialized(global
);
2647 eap_peer_unregister_methods();
2649 eap_server_unregister_methods();
2650 #endif /* CONFIG_AP */
2652 for (i
= 0; wpa_drivers
[i
] && global
->drv_priv
; i
++) {
2653 if (!global
->drv_priv
[i
])
2655 wpa_drivers
[i
]->global_deinit(global
->drv_priv
[i
]);
2657 os_free(global
->drv_priv
);
2663 if (global
->params
.pid_file
) {
2664 os_daemonize_terminate(global
->params
.pid_file
);
2665 os_free(global
->params
.pid_file
);
2667 os_free(global
->params
.ctrl_interface
);
2668 os_free(global
->params
.override_driver
);
2669 os_free(global
->params
.override_ctrl_interface
);
2672 wpa_debug_close_syslog();
2673 wpa_debug_close_file();
2677 void wpa_supplicant_update_config(struct wpa_supplicant
*wpa_s
)
2680 wpas_wps_update_config(wpa_s
);
2681 #endif /* CONFIG_WPS */
2684 wpas_p2p_update_config(wpa_s
);
2685 #endif /* CONFIG_P2P */
2687 wpa_s
->conf
->changed_parameters
= 0;
2691 void ieee80211_sta_free_hw_features(struct hostapd_hw_modes
*hw_features
,
2692 size_t num_hw_features
)
2696 if (hw_features
== NULL
)
2699 for (i
= 0; i
< num_hw_features
; i
++) {
2700 os_free(hw_features
[i
].channels
);
2701 os_free(hw_features
[i
].rates
);
2704 os_free(hw_features
);
2708 static void add_freq(int *freqs
, int *num_freqs
, int freq
)
2712 for (i
= 0; i
< *num_freqs
; i
++) {
2713 if (freqs
[i
] == freq
)
2717 freqs
[*num_freqs
] = freq
;
2722 static int * get_bss_freqs_in_ess(struct wpa_supplicant
*wpa_s
)
2724 struct wpa_bss
*bss
, *cbss
;
2725 const int max_freqs
= 10;
2729 freqs
= os_zalloc(sizeof(int) * (max_freqs
+ 1));
2733 cbss
= wpa_s
->current_bss
;
2735 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
2738 if (bss
->ssid_len
== cbss
->ssid_len
&&
2739 os_memcmp(bss
->ssid
, cbss
->ssid
, bss
->ssid_len
) == 0 &&
2740 wpa_blacklist_get(wpa_s
, bss
->bssid
) == NULL
) {
2741 add_freq(freqs
, &num_freqs
, bss
->freq
);
2742 if (num_freqs
== max_freqs
)
2747 if (num_freqs
== 0) {
2756 void wpas_connection_failed(struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
2763 * Add the failed BSSID into the blacklist and speed up next scan
2764 * attempt if there could be other APs that could accept association.
2765 * The current blacklist count indicates how many times we have tried
2766 * connecting to this AP and multiple attempts mean that other APs are
2767 * either not available or has already been tried, so that we can start
2768 * increasing the delay here to avoid constant scanning.
2770 count
= wpa_blacklist_add(wpa_s
, bssid
);
2771 if (count
== 1 && wpa_s
->current_bss
) {
2773 * This BSS was not in the blacklist before. If there is
2774 * another BSS available for the same ESS, we should try that
2775 * next. Otherwise, we may as well try this one once more
2776 * before allowing other, likely worse, ESSes to be considered.
2778 freqs
= get_bss_freqs_in_ess(wpa_s
);
2780 wpa_dbg(wpa_s
, MSG_DEBUG
, "Another BSS in this ESS "
2781 "has been seen; try it next");
2782 wpa_blacklist_add(wpa_s
, bssid
);
2784 * On the next scan, go through only the known channels
2785 * used in this ESS based on previous scans to speed up
2786 * common load balancing use case.
2788 os_free(wpa_s
->next_scan_freqs
);
2789 wpa_s
->next_scan_freqs
= freqs
;
2808 * TODO: if more than one possible AP is available in scan results,
2809 * could try the other ones before requesting a new scan.
2811 wpa_supplicant_req_scan(wpa_s
, timeout
/ 1000,
2812 1000 * (timeout
% 1000));