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"
46 #include "gas_query.h"
48 #include "p2p_supplicant.h"
54 const char *wpa_supplicant_version
=
55 "wpa_supplicant v" VERSION_STR
"\n"
56 "Copyright (c) 2003-2011, Jouni Malinen <j@w1.fi> and contributors";
58 const char *wpa_supplicant_license
=
59 "This program is free software. You can distribute it and/or modify it\n"
60 "under the terms of the GNU General Public License version 2.\n"
62 "Alternatively, this software may be distributed under the terms of the\n"
63 "BSD license. See README and COPYING for more details.\n"
64 #ifdef EAP_TLS_OPENSSL
65 "\nThis product includes software developed by the OpenSSL Project\n"
66 "for use in the OpenSSL Toolkit (http://www.openssl.org/)\n"
67 #endif /* EAP_TLS_OPENSSL */
70 #ifndef CONFIG_NO_STDOUT_DEBUG
71 /* Long text divided into parts in order to fit in C89 strings size limits. */
72 const char *wpa_supplicant_full_license1
=
73 "This program is free software; you can redistribute it and/or modify\n"
74 "it under the terms of the GNU General Public License version 2 as\n"
75 "published by the Free Software Foundation.\n"
77 "This program is distributed in the hope that it will be useful,\n"
78 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
79 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
80 "GNU General Public License for more details.\n"
82 const char *wpa_supplicant_full_license2
=
83 "You should have received a copy of the GNU General Public License\n"
84 "along with this program; if not, write to the Free Software\n"
85 "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n"
87 "Alternatively, this software may be distributed under the terms of the\n"
90 "Redistribution and use in source and binary forms, with or without\n"
91 "modification, are permitted provided that the following conditions are\n"
94 const char *wpa_supplicant_full_license3
=
95 "1. Redistributions of source code must retain the above copyright\n"
96 " notice, this list of conditions and the following disclaimer.\n"
98 "2. Redistributions in binary form must reproduce the above copyright\n"
99 " notice, this list of conditions and the following disclaimer in the\n"
100 " documentation and/or other materials provided with the distribution.\n"
102 const char *wpa_supplicant_full_license4
=
103 "3. Neither the name(s) of the above-listed copyright holder(s) nor the\n"
104 " names of its contributors may be used to endorse or promote products\n"
105 " derived from this software without specific prior written permission.\n"
107 "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n"
108 "\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n"
109 "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n"
110 "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n";
111 const char *wpa_supplicant_full_license5
=
112 "OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n"
113 "SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n"
114 "LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n"
115 "DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n"
116 "THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n"
117 "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n"
118 "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
120 #endif /* CONFIG_NO_STDOUT_DEBUG */
122 extern int wpa_debug_level
;
123 extern int wpa_debug_show_keys
;
124 extern int wpa_debug_timestamp
;
125 extern struct wpa_driver_ops
*wpa_drivers
[];
127 /* Configure default/group WEP keys for static WEP */
128 int wpa_set_wep_keys(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
)
132 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
133 if (ssid
->wep_key_len
[i
] == 0)
137 wpa_drv_set_key(wpa_s
, WPA_ALG_WEP
, NULL
,
138 i
, i
== ssid
->wep_tx_keyidx
, NULL
, 0,
139 ssid
->wep_key
[i
], ssid
->wep_key_len
[i
]);
146 static int wpa_supplicant_set_wpa_none_key(struct wpa_supplicant
*wpa_s
,
147 struct wpa_ssid
*ssid
)
154 /* IBSS/WPA-None uses only one key (Group) for both receiving and
155 * sending unicast and multicast packets. */
157 if (ssid
->mode
!= WPAS_MODE_IBSS
) {
158 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Invalid mode %d (not "
159 "IBSS/ad-hoc) for WPA-None", ssid
->mode
);
163 if (!ssid
->psk_set
) {
164 wpa_msg(wpa_s
, MSG_INFO
, "WPA: No PSK configured for "
169 switch (wpa_s
->group_cipher
) {
170 case WPA_CIPHER_CCMP
:
171 os_memcpy(key
, ssid
->psk
, 16);
175 case WPA_CIPHER_TKIP
:
176 /* WPA-None uses the same Michael MIC key for both TX and RX */
177 os_memcpy(key
, ssid
->psk
, 16 + 8);
178 os_memcpy(key
+ 16 + 8, ssid
->psk
+ 16, 8);
183 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Invalid group cipher %d for "
184 "WPA-None", wpa_s
->group_cipher
);
188 /* TODO: should actually remember the previously used seq#, both for TX
189 * and RX from each STA.. */
191 return wpa_drv_set_key(wpa_s
, alg
, NULL
, 0, 1, seq
, 6, key
, keylen
);
195 static void wpa_supplicant_timeout(void *eloop_ctx
, void *timeout_ctx
)
197 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
198 const u8
*bssid
= wpa_s
->bssid
;
199 if (is_zero_ether_addr(bssid
))
200 bssid
= wpa_s
->pending_bssid
;
201 wpa_msg(wpa_s
, MSG_INFO
, "Authentication with " MACSTR
" timed out.",
203 wpa_blacklist_add(wpa_s
, bssid
);
204 wpa_sm_notify_disassoc(wpa_s
->wpa
);
205 wpa_supplicant_disassociate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
206 wpa_s
->reassociate
= 1;
209 * If we timed out, the AP or the local radio may be busy.
210 * So, wait a second until scanning again.
212 wpa_supplicant_req_scan(wpa_s
, 1, 0);
217 * wpa_supplicant_req_auth_timeout - Schedule a timeout for authentication
218 * @wpa_s: Pointer to wpa_supplicant data
219 * @sec: Number of seconds after which to time out authentication
220 * @usec: Number of microseconds after which to time out authentication
222 * This function is used to schedule a timeout for the current authentication
225 void wpa_supplicant_req_auth_timeout(struct wpa_supplicant
*wpa_s
,
228 if (wpa_s
->conf
&& wpa_s
->conf
->ap_scan
== 0 &&
229 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
))
232 wpa_dbg(wpa_s
, MSG_DEBUG
, "Setting authentication timeout: %d sec "
233 "%d usec", sec
, usec
);
234 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
235 eloop_register_timeout(sec
, usec
, wpa_supplicant_timeout
, wpa_s
, NULL
);
240 * wpa_supplicant_cancel_auth_timeout - Cancel authentication timeout
241 * @wpa_s: Pointer to wpa_supplicant data
243 * This function is used to cancel authentication timeout scheduled with
244 * wpa_supplicant_req_auth_timeout() and it is called when authentication has
247 void wpa_supplicant_cancel_auth_timeout(struct wpa_supplicant
*wpa_s
)
249 wpa_dbg(wpa_s
, MSG_DEBUG
, "Cancelling authentication timeout");
250 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
251 wpa_blacklist_del(wpa_s
, wpa_s
->bssid
);
256 * wpa_supplicant_initiate_eapol - Configure EAPOL state machine
257 * @wpa_s: Pointer to wpa_supplicant data
259 * This function is used to configure EAPOL state machine based on the selected
260 * authentication mode.
262 void wpa_supplicant_initiate_eapol(struct wpa_supplicant
*wpa_s
)
264 #ifdef IEEE8021X_EAPOL
265 struct eapol_config eapol_conf
;
266 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
268 #ifdef CONFIG_IBSS_RSN
269 if (ssid
->mode
== WPAS_MODE_IBSS
&&
270 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
271 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
) {
273 * RSN IBSS authentication is per-STA and we can disable the
274 * per-BSSID EAPOL authentication.
276 eapol_sm_notify_portControl(wpa_s
->eapol
, ForceAuthorized
);
277 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
278 eapol_sm_notify_eap_fail(wpa_s
->eapol
, FALSE
);
281 #endif /* CONFIG_IBSS_RSN */
283 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
284 eapol_sm_notify_eap_fail(wpa_s
->eapol
, FALSE
);
286 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
287 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
288 eapol_sm_notify_portControl(wpa_s
->eapol
, ForceAuthorized
);
290 eapol_sm_notify_portControl(wpa_s
->eapol
, Auto
);
292 os_memset(&eapol_conf
, 0, sizeof(eapol_conf
));
293 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
294 eapol_conf
.accept_802_1x_keys
= 1;
295 eapol_conf
.required_keys
= 0;
296 if (ssid
->eapol_flags
& EAPOL_FLAG_REQUIRE_KEY_UNICAST
) {
297 eapol_conf
.required_keys
|= EAPOL_REQUIRE_KEY_UNICAST
;
299 if (ssid
->eapol_flags
& EAPOL_FLAG_REQUIRE_KEY_BROADCAST
) {
300 eapol_conf
.required_keys
|=
301 EAPOL_REQUIRE_KEY_BROADCAST
;
304 if (wpa_s
->conf
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
))
305 eapol_conf
.required_keys
= 0;
308 eapol_conf
.fast_reauth
= wpa_s
->conf
->fast_reauth
;
309 eapol_conf
.workaround
= ssid
->eap_workaround
;
310 eapol_conf
.eap_disabled
=
311 !wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) &&
312 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
313 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPS
;
314 eapol_sm_notify_config(wpa_s
->eapol
, &ssid
->eap
, &eapol_conf
);
315 #endif /* IEEE8021X_EAPOL */
320 * wpa_supplicant_set_non_wpa_policy - Set WPA parameters to non-WPA mode
321 * @wpa_s: Pointer to wpa_supplicant data
322 * @ssid: Configuration data for the network
324 * This function is used to configure WPA state machine and related parameters
325 * to a mode where WPA is not enabled. This is called as part of the
326 * authentication configuration when the selected network does not use WPA.
328 void wpa_supplicant_set_non_wpa_policy(struct wpa_supplicant
*wpa_s
,
329 struct wpa_ssid
*ssid
)
333 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
334 wpa_s
->key_mgmt
= WPA_KEY_MGMT_WPS
;
335 else if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)
336 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X_NO_WPA
;
338 wpa_s
->key_mgmt
= WPA_KEY_MGMT_NONE
;
339 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
340 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
341 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
342 wpa_s
->pairwise_cipher
= WPA_CIPHER_NONE
;
343 wpa_s
->group_cipher
= WPA_CIPHER_NONE
;
344 wpa_s
->mgmt_group_cipher
= 0;
346 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
347 if (ssid
->wep_key_len
[i
] > 5) {
348 wpa_s
->pairwise_cipher
= WPA_CIPHER_WEP104
;
349 wpa_s
->group_cipher
= WPA_CIPHER_WEP104
;
351 } else if (ssid
->wep_key_len
[i
] > 0) {
352 wpa_s
->pairwise_cipher
= WPA_CIPHER_WEP40
;
353 wpa_s
->group_cipher
= WPA_CIPHER_WEP40
;
358 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_RSN_ENABLED
, 0);
359 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_KEY_MGMT
, wpa_s
->key_mgmt
);
360 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PAIRWISE
,
361 wpa_s
->pairwise_cipher
);
362 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_GROUP
, wpa_s
->group_cipher
);
363 #ifdef CONFIG_IEEE80211W
364 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MGMT_GROUP
,
365 wpa_s
->mgmt_group_cipher
);
366 #endif /* CONFIG_IEEE80211W */
368 pmksa_cache_clear_current(wpa_s
->wpa
);
372 static void wpa_supplicant_cleanup(struct wpa_supplicant
*wpa_s
)
374 bgscan_deinit(wpa_s
);
375 scard_deinit(wpa_s
->scard
);
377 wpa_sm_set_scard_ctx(wpa_s
->wpa
, NULL
);
378 eapol_sm_register_scard_ctx(wpa_s
->eapol
, NULL
);
379 l2_packet_deinit(wpa_s
->l2
);
382 l2_packet_deinit(wpa_s
->l2_br
);
386 if (wpa_s
->ctrl_iface
) {
387 wpa_supplicant_ctrl_iface_deinit(wpa_s
->ctrl_iface
);
388 wpa_s
->ctrl_iface
= NULL
;
390 if (wpa_s
->conf
!= NULL
) {
391 struct wpa_ssid
*ssid
;
392 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
)
393 wpas_notify_network_removed(wpa_s
, ssid
);
394 wpa_config_free(wpa_s
->conf
);
398 os_free(wpa_s
->confname
);
399 wpa_s
->confname
= NULL
;
401 wpa_sm_set_eapol(wpa_s
->wpa
, NULL
);
402 eapol_sm_deinit(wpa_s
->eapol
);
405 rsn_preauth_deinit(wpa_s
->wpa
);
408 wpa_tdls_deinit(wpa_s
->wpa
);
409 #endif /* CONFIG_TDLS */
411 pmksa_candidate_free(wpa_s
->wpa
);
412 wpa_sm_deinit(wpa_s
->wpa
);
414 wpa_blacklist_clear(wpa_s
);
416 wpa_bss_deinit(wpa_s
);
418 wpa_supplicant_cancel_scan(wpa_s
);
419 wpa_supplicant_cancel_auth_timeout(wpa_s
);
421 ieee80211_sta_deinit(wpa_s
);
423 wpas_wps_deinit(wpa_s
);
425 wpabuf_free(wpa_s
->pending_eapol_rx
);
426 wpa_s
->pending_eapol_rx
= NULL
;
428 #ifdef CONFIG_IBSS_RSN
429 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
430 wpa_s
->ibss_rsn
= NULL
;
431 #endif /* CONFIG_IBSS_RSN */
436 wpa_supplicant_ap_deinit(wpa_s
);
437 #endif /* CONFIG_AP */
440 wpas_p2p_deinit(wpa_s
);
441 #endif /* CONFIG_P2P */
443 os_free(wpa_s
->next_scan_freqs
);
444 wpa_s
->next_scan_freqs
= NULL
;
446 gas_query_deinit(wpa_s
->gas
);
452 * wpa_clear_keys - Clear keys configured for the driver
453 * @wpa_s: Pointer to wpa_supplicant data
454 * @addr: Previously used BSSID or %NULL if not available
456 * This function clears the encryption keys that has been previously configured
459 void wpa_clear_keys(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
461 if (wpa_s
->keys_cleared
) {
462 /* Some drivers (e.g., ndiswrapper & NDIS drivers) seem to have
463 * timing issues with keys being cleared just before new keys
464 * are set or just after association or something similar. This
465 * shows up in group key handshake failing often because of the
466 * client not receiving the first encrypted packets correctly.
467 * Skipping some of the extra key clearing steps seems to help
468 * in completing group key handshake more reliably. */
469 wpa_dbg(wpa_s
, MSG_DEBUG
, "No keys have been configured - "
470 "skip key clearing");
474 /* MLME-DELETEKEYS.request */
475 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
476 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
477 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
478 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
479 #ifdef CONFIG_IEEE80211W
480 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
481 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
482 #endif /* CONFIG_IEEE80211W */
484 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, addr
, 0, 0, NULL
, 0, NULL
,
486 /* MLME-SETPROTECTION.request(None) */
487 wpa_drv_mlme_setprotection(
489 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
490 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
492 wpa_s
->keys_cleared
= 1;
497 * wpa_supplicant_state_txt - Get the connection state name as a text string
498 * @state: State (wpa_state; WPA_*)
499 * Returns: The state name as a printable text string
501 const char * wpa_supplicant_state_txt(enum wpa_states state
)
504 case WPA_DISCONNECTED
:
505 return "DISCONNECTED";
508 case WPA_INTERFACE_DISABLED
:
509 return "INTERFACE_DISABLED";
512 case WPA_AUTHENTICATING
:
513 return "AUTHENTICATING";
514 case WPA_ASSOCIATING
:
515 return "ASSOCIATING";
518 case WPA_4WAY_HANDSHAKE
:
519 return "4WAY_HANDSHAKE";
520 case WPA_GROUP_HANDSHAKE
:
521 return "GROUP_HANDSHAKE";
532 static void wpa_supplicant_start_bgscan(struct wpa_supplicant
*wpa_s
)
534 if (wpas_driver_bss_selection(wpa_s
))
536 if (wpa_s
->current_ssid
== wpa_s
->bgscan_ssid
)
539 bgscan_deinit(wpa_s
);
540 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->bgscan
) {
541 if (bgscan_init(wpa_s
, wpa_s
->current_ssid
)) {
542 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to initialize "
545 * Live without bgscan; it is only used as a roaming
546 * optimization, so the initial connection is not
550 wpa_s
->bgscan_ssid
= wpa_s
->current_ssid
;
552 wpa_s
->bgscan_ssid
= NULL
;
556 static void wpa_supplicant_stop_bgscan(struct wpa_supplicant
*wpa_s
)
558 if (wpa_s
->bgscan_ssid
!= NULL
) {
559 bgscan_deinit(wpa_s
);
560 wpa_s
->bgscan_ssid
= NULL
;
564 #endif /* CONFIG_BGSCAN */
568 * wpa_supplicant_set_state - Set current connection state
569 * @wpa_s: Pointer to wpa_supplicant data
570 * @state: The new connection state
572 * This function is called whenever the connection state changes, e.g.,
573 * association is completed for WPA/WPA2 4-Way Handshake is started.
575 void wpa_supplicant_set_state(struct wpa_supplicant
*wpa_s
,
576 enum wpa_states state
)
578 enum wpa_states old_state
= wpa_s
->wpa_state
;
580 wpa_dbg(wpa_s
, MSG_DEBUG
, "State: %s -> %s",
581 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
582 wpa_supplicant_state_txt(state
));
584 if (state
!= WPA_SCANNING
)
585 wpa_supplicant_notify_scanning(wpa_s
, 0);
587 if (state
== WPA_COMPLETED
&& wpa_s
->new_connection
) {
588 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
589 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
590 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
"- Connection to "
591 MACSTR
" completed %s [id=%d id_str=%s]",
592 MAC2STR(wpa_s
->bssid
), wpa_s
->reassociated_connection
?
593 "(reauth)" : "(auth)",
594 ssid
? ssid
->id
: -1,
595 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
596 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
597 wpa_s
->new_connection
= 0;
598 wpa_s
->reassociated_connection
= 1;
599 wpa_drv_set_operstate(wpa_s
, 1);
600 #ifndef IEEE8021X_EAPOL
601 wpa_drv_set_supp_port(wpa_s
, 1);
602 #endif /* IEEE8021X_EAPOL */
603 wpa_s
->after_wps
= 0;
605 wpas_p2p_completed(wpa_s
);
606 #endif /* CONFIG_P2P */
607 } else if (state
== WPA_DISCONNECTED
|| state
== WPA_ASSOCIATING
||
608 state
== WPA_ASSOCIATED
) {
609 wpa_s
->new_connection
= 1;
610 wpa_drv_set_operstate(wpa_s
, 0);
611 #ifndef IEEE8021X_EAPOL
612 wpa_drv_set_supp_port(wpa_s
, 0);
613 #endif /* IEEE8021X_EAPOL */
615 wpa_s
->wpa_state
= state
;
618 if (state
== WPA_COMPLETED
)
619 wpa_supplicant_start_bgscan(wpa_s
);
621 wpa_supplicant_stop_bgscan(wpa_s
);
622 #endif /* CONFIG_BGSCAN */
624 if (wpa_s
->wpa_state
!= old_state
) {
625 wpas_notify_state_changed(wpa_s
, wpa_s
->wpa_state
, old_state
);
627 if (wpa_s
->wpa_state
== WPA_COMPLETED
||
628 old_state
== WPA_COMPLETED
)
629 wpas_notify_auth_changed(wpa_s
);
634 void wpa_supplicant_terminate_proc(struct wpa_global
*global
)
638 struct wpa_supplicant
*wpa_s
= global
->ifaces
;
640 if (wpas_wps_terminate_pending(wpa_s
) == 1)
644 #endif /* CONFIG_WPS */
651 static void wpa_supplicant_terminate(int sig
, void *signal_ctx
)
653 struct wpa_global
*global
= signal_ctx
;
654 struct wpa_supplicant
*wpa_s
;
655 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
656 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_TERMINATING
"- signal %d "
659 wpa_supplicant_terminate_proc(global
);
663 void wpa_supplicant_clear_status(struct wpa_supplicant
*wpa_s
)
665 enum wpa_states old_state
= wpa_s
->wpa_state
;
667 wpa_s
->pairwise_cipher
= 0;
668 wpa_s
->group_cipher
= 0;
669 wpa_s
->mgmt_group_cipher
= 0;
671 if (wpa_s
->wpa_state
!= WPA_INTERFACE_DISABLED
)
672 wpa_s
->wpa_state
= WPA_DISCONNECTED
;
674 if (wpa_s
->wpa_state
!= old_state
)
675 wpas_notify_state_changed(wpa_s
, wpa_s
->wpa_state
, old_state
);
680 * wpa_supplicant_reload_configuration - Reload configuration data
681 * @wpa_s: Pointer to wpa_supplicant data
682 * Returns: 0 on success or -1 if configuration parsing failed
684 * This function can be used to request that the configuration data is reloaded
685 * (e.g., after configuration file change). This function is reloading
686 * configuration only for one interface, so this may need to be called multiple
687 * times if %wpa_supplicant is controlling multiple interfaces and all
688 * interfaces need reconfiguration.
690 int wpa_supplicant_reload_configuration(struct wpa_supplicant
*wpa_s
)
692 struct wpa_config
*conf
;
696 if (wpa_s
->confname
== NULL
)
698 conf
= wpa_config_read(wpa_s
->confname
);
700 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to parse the configuration "
701 "file '%s' - exiting", wpa_s
->confname
);
704 conf
->changed_parameters
= (unsigned int) -1;
706 reconf_ctrl
= !!conf
->ctrl_interface
!= !!wpa_s
->conf
->ctrl_interface
707 || (conf
->ctrl_interface
&& wpa_s
->conf
->ctrl_interface
&&
708 os_strcmp(conf
->ctrl_interface
,
709 wpa_s
->conf
->ctrl_interface
) != 0);
711 if (reconf_ctrl
&& wpa_s
->ctrl_iface
) {
712 wpa_supplicant_ctrl_iface_deinit(wpa_s
->ctrl_iface
);
713 wpa_s
->ctrl_iface
= NULL
;
716 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
717 if (wpa_s
->current_ssid
) {
718 wpa_supplicant_deauthenticate(wpa_s
,
719 WLAN_REASON_DEAUTH_LEAVING
);
723 * TODO: should notify EAPOL SM about changes in opensc_engine_path,
724 * pkcs11_engine_path, pkcs11_module_path.
726 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
728 * Clear forced success to clear EAP state for next
731 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
733 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
734 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
735 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
736 wpa_sm_set_fast_reauth(wpa_s
->wpa
, wpa_s
->conf
->fast_reauth
);
737 rsn_preauth_deinit(wpa_s
->wpa
);
739 old_ap_scan
= wpa_s
->conf
->ap_scan
;
740 wpa_config_free(wpa_s
->conf
);
742 if (old_ap_scan
!= wpa_s
->conf
->ap_scan
)
743 wpas_notify_ap_scan_changed(wpa_s
);
746 wpa_s
->ctrl_iface
= wpa_supplicant_ctrl_iface_init(wpa_s
);
748 wpa_supplicant_update_config(wpa_s
);
750 wpa_supplicant_clear_status(wpa_s
);
751 if (wpa_supplicant_enabled_networks(wpa_s
->conf
)) {
752 wpa_s
->reassociate
= 1;
753 wpa_supplicant_req_scan(wpa_s
, 0, 0);
755 wpa_dbg(wpa_s
, MSG_DEBUG
, "Reconfiguration completed");
760 static void wpa_supplicant_reconfig(int sig
, void *signal_ctx
)
762 struct wpa_global
*global
= signal_ctx
;
763 struct wpa_supplicant
*wpa_s
;
764 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
765 wpa_dbg(wpa_s
, MSG_DEBUG
, "Signal %d received - reconfiguring",
767 if (wpa_supplicant_reload_configuration(wpa_s
) < 0) {
768 wpa_supplicant_terminate_proc(global
);
774 enum wpa_cipher
cipher_suite2driver(int cipher
)
777 case WPA_CIPHER_NONE
:
779 case WPA_CIPHER_WEP40
:
781 case WPA_CIPHER_WEP104
:
782 return CIPHER_WEP104
;
783 case WPA_CIPHER_CCMP
:
785 case WPA_CIPHER_TKIP
:
792 enum wpa_key_mgmt
key_mgmt2driver(int key_mgmt
)
795 case WPA_KEY_MGMT_NONE
:
796 return KEY_MGMT_NONE
;
797 case WPA_KEY_MGMT_IEEE8021X_NO_WPA
:
798 return KEY_MGMT_802_1X_NO_WPA
;
799 case WPA_KEY_MGMT_IEEE8021X
:
800 return KEY_MGMT_802_1X
;
801 case WPA_KEY_MGMT_WPA_NONE
:
802 return KEY_MGMT_WPA_NONE
;
803 case WPA_KEY_MGMT_FT_IEEE8021X
:
804 return KEY_MGMT_FT_802_1X
;
805 case WPA_KEY_MGMT_FT_PSK
:
806 return KEY_MGMT_FT_PSK
;
807 case WPA_KEY_MGMT_IEEE8021X_SHA256
:
808 return KEY_MGMT_802_1X_SHA256
;
809 case WPA_KEY_MGMT_PSK_SHA256
:
810 return KEY_MGMT_PSK_SHA256
;
811 case WPA_KEY_MGMT_WPS
:
813 case WPA_KEY_MGMT_PSK
:
820 static int wpa_supplicant_suites_from_ai(struct wpa_supplicant
*wpa_s
,
821 struct wpa_ssid
*ssid
,
822 struct wpa_ie_data
*ie
)
824 int ret
= wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, ie
);
827 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Failed to parse WPA IE "
828 "from association info");
833 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Using WPA IE from AssocReq to set "
835 if (!(ie
->group_cipher
& ssid
->group_cipher
)) {
836 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled group "
837 "cipher 0x%x (mask 0x%x) - reject",
838 ie
->group_cipher
, ssid
->group_cipher
);
841 if (!(ie
->pairwise_cipher
& ssid
->pairwise_cipher
)) {
842 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled pairwise "
843 "cipher 0x%x (mask 0x%x) - reject",
844 ie
->pairwise_cipher
, ssid
->pairwise_cipher
);
847 if (!(ie
->key_mgmt
& ssid
->key_mgmt
)) {
848 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled key "
849 "management 0x%x (mask 0x%x) - reject",
850 ie
->key_mgmt
, ssid
->key_mgmt
);
854 #ifdef CONFIG_IEEE80211W
855 if (!(ie
->capabilities
& WPA_CAPABILITY_MFPC
) &&
856 ssid
->ieee80211w
== MGMT_FRAME_PROTECTION_REQUIRED
) {
857 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver associated with an AP "
858 "that does not support management frame protection - "
862 #endif /* CONFIG_IEEE80211W */
869 * wpa_supplicant_set_suites - Set authentication and encryption parameters
870 * @wpa_s: Pointer to wpa_supplicant data
871 * @bss: Scan results for the selected BSS, or %NULL if not available
872 * @ssid: Configuration data for the selected network
873 * @wpa_ie: Buffer for the WPA/RSN IE
874 * @wpa_ie_len: Maximum wpa_ie buffer size on input. This is changed to be the
875 * used buffer length in case the functions returns success.
876 * Returns: 0 on success or -1 on failure
878 * This function is used to configure authentication and encryption parameters
879 * based on the network configuration and scan result for the selected BSS (if
882 int wpa_supplicant_set_suites(struct wpa_supplicant
*wpa_s
,
883 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
,
884 u8
*wpa_ie
, size_t *wpa_ie_len
)
886 struct wpa_ie_data ie
;
888 const u8
*bss_wpa
, *bss_rsn
;
891 bss_wpa
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
892 bss_rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
894 bss_wpa
= bss_rsn
= NULL
;
896 if (bss_rsn
&& (ssid
->proto
& WPA_PROTO_RSN
) &&
897 wpa_parse_wpa_ie(bss_rsn
, 2 + bss_rsn
[1], &ie
) == 0 &&
898 (ie
.group_cipher
& ssid
->group_cipher
) &&
899 (ie
.pairwise_cipher
& ssid
->pairwise_cipher
) &&
900 (ie
.key_mgmt
& ssid
->key_mgmt
)) {
901 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: using IEEE 802.11i/D9.0");
902 proto
= WPA_PROTO_RSN
;
903 } else if (bss_wpa
&& (ssid
->proto
& WPA_PROTO_WPA
) &&
904 wpa_parse_wpa_ie(bss_wpa
, 2 +bss_wpa
[1], &ie
) == 0 &&
905 (ie
.group_cipher
& ssid
->group_cipher
) &&
906 (ie
.pairwise_cipher
& ssid
->pairwise_cipher
) &&
907 (ie
.key_mgmt
& ssid
->key_mgmt
)) {
908 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using IEEE 802.11i/D3.0");
909 proto
= WPA_PROTO_WPA
;
911 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select WPA/RSN");
914 if (ssid
->proto
& WPA_PROTO_RSN
)
915 proto
= WPA_PROTO_RSN
;
917 proto
= WPA_PROTO_WPA
;
918 if (wpa_supplicant_suites_from_ai(wpa_s
, ssid
, &ie
) < 0) {
919 os_memset(&ie
, 0, sizeof(ie
));
920 ie
.group_cipher
= ssid
->group_cipher
;
921 ie
.pairwise_cipher
= ssid
->pairwise_cipher
;
922 ie
.key_mgmt
= ssid
->key_mgmt
;
923 #ifdef CONFIG_IEEE80211W
924 ie
.mgmt_group_cipher
=
925 ssid
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
?
926 WPA_CIPHER_AES_128_CMAC
: 0;
927 #endif /* CONFIG_IEEE80211W */
928 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Set cipher suites "
929 "based on configuration");
934 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Selected cipher suites: group %d "
935 "pairwise %d key_mgmt %d proto %d",
936 ie
.group_cipher
, ie
.pairwise_cipher
, ie
.key_mgmt
, proto
);
937 #ifdef CONFIG_IEEE80211W
938 if (ssid
->ieee80211w
) {
939 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Selected mgmt group cipher %d",
940 ie
.mgmt_group_cipher
);
942 #endif /* CONFIG_IEEE80211W */
944 wpa_s
->wpa_proto
= proto
;
945 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PROTO
, proto
);
946 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_RSN_ENABLED
,
947 !!(ssid
->proto
& WPA_PROTO_RSN
));
949 if (bss
|| !wpa_s
->ap_ies_from_associnfo
) {
950 if (wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, bss_wpa
,
951 bss_wpa
? 2 + bss_wpa
[1] : 0) ||
952 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, bss_rsn
,
953 bss_rsn
? 2 + bss_rsn
[1] : 0))
957 sel
= ie
.group_cipher
& ssid
->group_cipher
;
958 if (sel
& WPA_CIPHER_CCMP
) {
959 wpa_s
->group_cipher
= WPA_CIPHER_CCMP
;
960 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using GTK CCMP");
961 } else if (sel
& WPA_CIPHER_TKIP
) {
962 wpa_s
->group_cipher
= WPA_CIPHER_TKIP
;
963 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using GTK TKIP");
964 } else if (sel
& WPA_CIPHER_WEP104
) {
965 wpa_s
->group_cipher
= WPA_CIPHER_WEP104
;
966 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using GTK WEP104");
967 } else if (sel
& WPA_CIPHER_WEP40
) {
968 wpa_s
->group_cipher
= WPA_CIPHER_WEP40
;
969 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using GTK WEP40");
971 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select group "
976 sel
= ie
.pairwise_cipher
& ssid
->pairwise_cipher
;
977 if (sel
& WPA_CIPHER_CCMP
) {
978 wpa_s
->pairwise_cipher
= WPA_CIPHER_CCMP
;
979 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using PTK CCMP");
980 } else if (sel
& WPA_CIPHER_TKIP
) {
981 wpa_s
->pairwise_cipher
= WPA_CIPHER_TKIP
;
982 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using PTK TKIP");
983 } else if (sel
& WPA_CIPHER_NONE
) {
984 wpa_s
->pairwise_cipher
= WPA_CIPHER_NONE
;
985 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using PTK NONE");
987 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select pairwise "
992 sel
= ie
.key_mgmt
& ssid
->key_mgmt
;
994 #ifdef CONFIG_IEEE80211R
995 } else if (sel
& WPA_KEY_MGMT_FT_IEEE8021X
) {
996 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_IEEE8021X
;
997 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FT/802.1X");
998 } else if (sel
& WPA_KEY_MGMT_FT_PSK
) {
999 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_PSK
;
1000 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FT/PSK");
1001 #endif /* CONFIG_IEEE80211R */
1002 #ifdef CONFIG_IEEE80211W
1003 } else if (sel
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
1004 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X_SHA256
;
1005 wpa_dbg(wpa_s
, MSG_DEBUG
,
1006 "WPA: using KEY_MGMT 802.1X with SHA256");
1007 } else if (sel
& WPA_KEY_MGMT_PSK_SHA256
) {
1008 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK_SHA256
;
1009 wpa_dbg(wpa_s
, MSG_DEBUG
,
1010 "WPA: using KEY_MGMT PSK with SHA256");
1011 #endif /* CONFIG_IEEE80211W */
1012 } else if (sel
& WPA_KEY_MGMT_IEEE8021X
) {
1013 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X
;
1014 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT 802.1X");
1015 } else if (sel
& WPA_KEY_MGMT_PSK
) {
1016 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK
;
1017 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT WPA-PSK");
1018 } else if (sel
& WPA_KEY_MGMT_WPA_NONE
) {
1019 wpa_s
->key_mgmt
= WPA_KEY_MGMT_WPA_NONE
;
1020 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT WPA-NONE");
1022 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select "
1023 "authenticated key management type");
1027 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_KEY_MGMT
, wpa_s
->key_mgmt
);
1028 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PAIRWISE
,
1029 wpa_s
->pairwise_cipher
);
1030 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_GROUP
, wpa_s
->group_cipher
);
1032 #ifdef CONFIG_IEEE80211W
1033 sel
= ie
.mgmt_group_cipher
;
1034 if (ssid
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
||
1035 !(ie
.capabilities
& WPA_CAPABILITY_MFPC
))
1037 if (sel
& WPA_CIPHER_AES_128_CMAC
) {
1038 wpa_s
->mgmt_group_cipher
= WPA_CIPHER_AES_128_CMAC
;
1039 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: using MGMT group cipher "
1042 wpa_s
->mgmt_group_cipher
= 0;
1043 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: not using MGMT group cipher");
1045 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MGMT_GROUP
,
1046 wpa_s
->mgmt_group_cipher
);
1047 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MFP
, ssid
->ieee80211w
);
1048 #endif /* CONFIG_IEEE80211W */
1050 if (wpa_sm_set_assoc_wpa_ie_default(wpa_s
->wpa
, wpa_ie
, wpa_ie_len
)) {
1051 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to generate WPA IE");
1055 if (ssid
->key_mgmt
&
1056 (WPA_KEY_MGMT_PSK
| WPA_KEY_MGMT_FT_PSK
| WPA_KEY_MGMT_PSK_SHA256
))
1057 wpa_sm_set_pmk(wpa_s
->wpa
, ssid
->psk
, PMK_LEN
);
1059 wpa_sm_set_pmk_from_pmksa(wpa_s
->wpa
);
1066 * wpa_supplicant_associate - Request association
1067 * @wpa_s: Pointer to wpa_supplicant data
1068 * @bss: Scan results for the selected BSS, or %NULL if not available
1069 * @ssid: Configuration data for the selected network
1071 * This function is used to request %wpa_supplicant to associate with a BSS.
1073 void wpa_supplicant_associate(struct wpa_supplicant
*wpa_s
,
1074 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
)
1078 int use_crypt
, ret
, i
, bssid_changed
;
1079 int algs
= WPA_AUTH_ALG_OPEN
;
1080 enum wpa_cipher cipher_pairwise
, cipher_group
;
1081 struct wpa_driver_associate_params params
;
1082 int wep_keys_set
= 0;
1083 struct wpa_driver_capa capa
;
1084 int assoc_failed
= 0;
1085 struct wpa_ssid
*old_ssid
;
1087 #ifdef CONFIG_IBSS_RSN
1088 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
1089 wpa_s
->ibss_rsn
= NULL
;
1090 #endif /* CONFIG_IBSS_RSN */
1092 if (ssid
->mode
== WPAS_MODE_AP
|| ssid
->mode
== WPAS_MODE_P2P_GO
||
1093 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
) {
1095 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_AP
)) {
1096 wpa_msg(wpa_s
, MSG_INFO
, "Driver does not support AP "
1100 wpa_supplicant_create_ap(wpa_s
, ssid
);
1101 wpa_s
->current_bss
= bss
;
1102 #else /* CONFIG_AP */
1103 wpa_msg(wpa_s
, MSG_ERROR
, "AP mode support not included in "
1105 #endif /* CONFIG_AP */
1111 wpa_tdls_ap_ies(wpa_s
->wpa
, (const u8
*) (bss
+ 1),
1113 #endif /* CONFIG_TDLS */
1115 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
1116 ssid
->mode
== IEEE80211_MODE_INFRA
) {
1117 sme_authenticate(wpa_s
, bss
, ssid
);
1121 os_memset(¶ms
, 0, sizeof(params
));
1122 wpa_s
->reassociate
= 0;
1123 if (bss
&& !wpas_driver_bss_selection(wpa_s
)) {
1124 #ifdef CONFIG_IEEE80211R
1125 const u8
*ie
, *md
= NULL
;
1126 #endif /* CONFIG_IEEE80211R */
1127 wpa_msg(wpa_s
, MSG_INFO
, "Trying to associate with " MACSTR
1128 " (SSID='%s' freq=%d MHz)", MAC2STR(bss
->bssid
),
1129 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
), bss
->freq
);
1130 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
1131 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
1132 os_memcpy(wpa_s
->pending_bssid
, bss
->bssid
, ETH_ALEN
);
1134 wpas_notify_bssid_changed(wpa_s
);
1135 #ifdef CONFIG_IEEE80211R
1136 ie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
1137 if (ie
&& ie
[1] >= MOBILITY_DOMAIN_ID_LEN
)
1139 wpa_sm_set_ft_params(wpa_s
->wpa
, ie
, ie
? 2 + ie
[1] : 0);
1141 /* Prepare for the next transition */
1142 wpa_ft_prepare_auth_request(wpa_s
->wpa
, ie
);
1144 #endif /* CONFIG_IEEE80211R */
1146 } else if ((ssid
->ssid
== NULL
|| ssid
->ssid_len
== 0) &&
1147 wpa_s
->conf
->ap_scan
== 2 &&
1148 (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
1149 /* Use ap_scan==1 style network selection to find the network
1151 wpa_s
->scan_req
= 2;
1152 wpa_s
->reassociate
= 1;
1153 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1155 #endif /* CONFIG_WPS */
1157 wpa_msg(wpa_s
, MSG_INFO
, "Trying to associate with SSID '%s'",
1158 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
1159 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1161 wpa_supplicant_cancel_scan(wpa_s
);
1163 /* Starting new association, so clear the possibly used WPA IE from the
1164 * previous association. */
1165 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1167 #ifdef IEEE8021X_EAPOL
1168 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1170 if (ssid
->non_leap
== 0)
1171 algs
= WPA_AUTH_ALG_LEAP
;
1173 algs
|= WPA_AUTH_ALG_LEAP
;
1176 #endif /* IEEE8021X_EAPOL */
1177 wpa_dbg(wpa_s
, MSG_DEBUG
, "Automatic auth_alg selection: 0x%x", algs
);
1178 if (ssid
->auth_alg
) {
1179 algs
= ssid
->auth_alg
;
1180 wpa_dbg(wpa_s
, MSG_DEBUG
, "Overriding auth_alg selection: "
1184 if (bss
&& (wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
) ||
1185 wpa_bss_get_ie(bss
, WLAN_EID_RSN
)) &&
1186 (ssid
->key_mgmt
& (WPA_KEY_MGMT_IEEE8021X
| WPA_KEY_MGMT_PSK
|
1187 WPA_KEY_MGMT_FT_IEEE8021X
|
1188 WPA_KEY_MGMT_FT_PSK
|
1189 WPA_KEY_MGMT_IEEE8021X_SHA256
|
1190 WPA_KEY_MGMT_PSK_SHA256
))) {
1191 int try_opportunistic
;
1192 try_opportunistic
= ssid
->proactive_key_caching
&&
1193 (ssid
->proto
& WPA_PROTO_RSN
);
1194 if (pmksa_cache_set_current(wpa_s
->wpa
, NULL
, bss
->bssid
,
1195 wpa_s
->current_ssid
,
1196 try_opportunistic
) == 0)
1197 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
, 1);
1198 wpa_ie_len
= sizeof(wpa_ie
);
1199 if (wpa_supplicant_set_suites(wpa_s
, bss
, ssid
,
1200 wpa_ie
, &wpa_ie_len
)) {
1201 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to set WPA "
1202 "key management and encryption suites");
1205 } else if (ssid
->key_mgmt
&
1206 (WPA_KEY_MGMT_PSK
| WPA_KEY_MGMT_IEEE8021X
|
1207 WPA_KEY_MGMT_WPA_NONE
| WPA_KEY_MGMT_FT_PSK
|
1208 WPA_KEY_MGMT_FT_IEEE8021X
| WPA_KEY_MGMT_PSK_SHA256
|
1209 WPA_KEY_MGMT_IEEE8021X_SHA256
)) {
1210 wpa_ie_len
= sizeof(wpa_ie
);
1211 if (wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
1212 wpa_ie
, &wpa_ie_len
)) {
1213 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to set WPA "
1214 "key management and encryption suites (no "
1219 } else if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
1220 struct wpabuf
*wps_ie
;
1221 wps_ie
= wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid
));
1222 if (wps_ie
&& wpabuf_len(wps_ie
) <= sizeof(wpa_ie
)) {
1223 wpa_ie_len
= wpabuf_len(wps_ie
);
1224 os_memcpy(wpa_ie
, wpabuf_head(wps_ie
), wpa_ie_len
);
1227 wpabuf_free(wps_ie
);
1228 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
1229 if (!bss
|| (bss
->caps
& IEEE80211_CAP_PRIVACY
))
1230 params
.wps
= WPS_MODE_PRIVACY
;
1232 params
.wps
= WPS_MODE_OPEN
;
1233 wpa_s
->wpa_proto
= 0;
1234 #endif /* CONFIG_WPS */
1236 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
1238 wpa_s
->wpa_proto
= 0;
1242 if (wpa_s
->global
->p2p
) {
1247 p2p_group
= wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CAPABLE
;
1248 pos
= wpa_ie
+ wpa_ie_len
;
1249 len
= sizeof(wpa_ie
) - wpa_ie_len
;
1250 res
= wpas_p2p_assoc_req_ie(wpa_s
, bss
, pos
, len
, p2p_group
);
1255 wpa_s
->cross_connect_disallowed
= 0;
1258 p2p
= wpa_bss_get_vendor_ie_multi(bss
, P2P_IE_VENDOR_TYPE
);
1260 wpa_s
->cross_connect_disallowed
=
1261 p2p_get_cross_connect_disallowed(p2p
);
1263 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: WLAN AP %s cross "
1265 wpa_s
->cross_connect_disallowed
?
1266 "disallows" : "allows");
1269 #endif /* CONFIG_P2P */
1271 wpa_clear_keys(wpa_s
, bss
? bss
->bssid
: NULL
);
1273 cipher_pairwise
= cipher_suite2driver(wpa_s
->pairwise_cipher
);
1274 cipher_group
= cipher_suite2driver(wpa_s
->group_cipher
);
1275 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1276 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1277 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
)
1279 if (wpa_set_wep_keys(wpa_s
, ssid
)) {
1284 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
)
1287 #ifdef IEEE8021X_EAPOL
1288 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1289 if ((ssid
->eapol_flags
&
1290 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
1291 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
)) == 0 &&
1295 /* Assume that dynamic WEP-104 keys will be used and
1296 * set cipher suites in order for drivers to expect
1298 cipher_pairwise
= cipher_group
= CIPHER_WEP104
;
1301 #endif /* IEEE8021X_EAPOL */
1303 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1304 /* Set the key before (and later after) association */
1305 wpa_supplicant_set_wpa_none_key(wpa_s
, ssid
);
1308 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATING
);
1310 params
.ssid
= bss
->ssid
;
1311 params
.ssid_len
= bss
->ssid_len
;
1312 if (!wpas_driver_bss_selection(wpa_s
)) {
1313 params
.bssid
= bss
->bssid
;
1314 params
.freq
= bss
->freq
;
1317 params
.ssid
= ssid
->ssid
;
1318 params
.ssid_len
= ssid
->ssid_len
;
1320 if (ssid
->mode
== WPAS_MODE_IBSS
&& ssid
->frequency
> 0 &&
1322 params
.freq
= ssid
->frequency
; /* Initial channel for IBSS */
1323 params
.wpa_ie
= wpa_ie
;
1324 params
.wpa_ie_len
= wpa_ie_len
;
1325 params
.pairwise_suite
= cipher_pairwise
;
1326 params
.group_suite
= cipher_group
;
1327 params
.key_mgmt_suite
= key_mgmt2driver(wpa_s
->key_mgmt
);
1328 params
.wpa_proto
= wpa_s
->wpa_proto
;
1329 params
.auth_alg
= algs
;
1330 params
.mode
= ssid
->mode
;
1331 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
1332 if (ssid
->wep_key_len
[i
])
1333 params
.wep_key
[i
] = ssid
->wep_key
[i
];
1334 params
.wep_key_len
[i
] = ssid
->wep_key_len
[i
];
1336 params
.wep_tx_keyidx
= ssid
->wep_tx_keyidx
;
1338 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1339 (params
.key_mgmt_suite
== KEY_MGMT_PSK
||
1340 params
.key_mgmt_suite
== KEY_MGMT_FT_PSK
)) {
1341 params
.passphrase
= ssid
->passphrase
;
1343 params
.psk
= ssid
->psk
;
1346 params
.drop_unencrypted
= use_crypt
;
1348 #ifdef CONFIG_IEEE80211W
1349 params
.mgmt_frame_protection
= ssid
->ieee80211w
;
1350 if (ssid
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
&& bss
) {
1351 const u8
*rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1352 struct wpa_ie_data ie
;
1353 if (rsn
&& wpa_parse_wpa_ie(rsn
, 2 + rsn
[1], &ie
) == 0 &&
1355 (WPA_CAPABILITY_MFPC
| WPA_CAPABILITY_MFPR
)) {
1356 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Selected AP supports "
1357 "MFP: require MFP");
1358 params
.mgmt_frame_protection
=
1359 MGMT_FRAME_PROTECTION_REQUIRED
;
1362 #endif /* CONFIG_IEEE80211W */
1364 params
.p2p
= ssid
->p2p_group
;
1366 if (wpa_s
->parent
->set_sta_uapsd
)
1367 params
.uapsd
= wpa_s
->parent
->sta_uapsd
;
1371 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
1372 ret
= ieee80211_sta_associate(wpa_s
, ¶ms
);
1374 ret
= wpa_drv_associate(wpa_s
, ¶ms
);
1376 wpa_msg(wpa_s
, MSG_INFO
, "Association request to the driver "
1378 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SANE_ERROR_CODES
) {
1380 * The driver is known to mean what is saying, so we
1381 * can stop right here; the association will not
1384 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1385 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1388 /* try to continue anyway; new association will be tried again
1393 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1394 /* Set the key after the association just in case association
1395 * cleared the previously configured key. */
1396 wpa_supplicant_set_wpa_none_key(wpa_s
, ssid
);
1397 /* No need to timeout authentication since there is no key
1399 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1400 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1401 #ifdef CONFIG_IBSS_RSN
1402 } else if (ssid
->mode
== WPAS_MODE_IBSS
&&
1403 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
1404 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
) {
1406 * RSN IBSS authentication is per-STA and we can disable the
1407 * per-BSSID authentication.
1409 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1410 #endif /* CONFIG_IBSS_RSN */
1412 /* Timeout for IEEE 802.11 authentication and association */
1416 /* give IBSS a bit more time */
1417 timeout
= ssid
->mode
== WPAS_MODE_IBSS
? 10 : 5;
1418 } else if (wpa_s
->conf
->ap_scan
== 1) {
1419 /* give IBSS a bit more time */
1420 timeout
= ssid
->mode
== WPAS_MODE_IBSS
? 20 : 10;
1422 wpa_supplicant_req_auth_timeout(wpa_s
, timeout
, 0);
1425 if (wep_keys_set
&& wpa_drv_get_capa(wpa_s
, &capa
) == 0 &&
1426 capa
.flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC
) {
1427 /* Set static WEP keys again */
1428 wpa_set_wep_keys(wpa_s
, ssid
);
1431 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
) {
1433 * Do not allow EAP session resumption between different
1434 * network configurations.
1436 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
1438 old_ssid
= wpa_s
->current_ssid
;
1439 wpa_s
->current_ssid
= ssid
;
1440 wpa_s
->current_bss
= bss
;
1441 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
1442 wpa_supplicant_initiate_eapol(wpa_s
);
1443 if (old_ssid
!= wpa_s
->current_ssid
)
1444 wpas_notify_network_changed(wpa_s
);
1448 static void wpa_supplicant_clear_connection(struct wpa_supplicant
*wpa_s
,
1451 struct wpa_ssid
*old_ssid
;
1453 wpa_clear_keys(wpa_s
, addr
);
1454 wpa_supplicant_mark_disassoc(wpa_s
);
1455 old_ssid
= wpa_s
->current_ssid
;
1456 wpa_s
->current_ssid
= NULL
;
1457 wpa_s
->current_bss
= NULL
;
1458 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
1459 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
1460 if (old_ssid
!= wpa_s
->current_ssid
)
1461 wpas_notify_network_changed(wpa_s
);
1462 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
1467 * wpa_supplicant_disassociate - Disassociate the current connection
1468 * @wpa_s: Pointer to wpa_supplicant data
1469 * @reason_code: IEEE 802.11 reason code for the disassociate frame
1471 * This function is used to request %wpa_supplicant to disassociate with the
1474 void wpa_supplicant_disassociate(struct wpa_supplicant
*wpa_s
,
1479 if (!is_zero_ether_addr(wpa_s
->bssid
)) {
1480 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
1481 ieee80211_sta_disassociate(wpa_s
, reason_code
);
1483 wpa_drv_disassociate(wpa_s
, wpa_s
->bssid
, reason_code
);
1484 addr
= wpa_s
->bssid
;
1487 wpa_supplicant_clear_connection(wpa_s
, addr
);
1492 * wpa_supplicant_deauthenticate - Deauthenticate the current connection
1493 * @wpa_s: Pointer to wpa_supplicant data
1494 * @reason_code: IEEE 802.11 reason code for the deauthenticate frame
1496 * This function is used to request %wpa_supplicant to deauthenticate from the
1499 void wpa_supplicant_deauthenticate(struct wpa_supplicant
*wpa_s
,
1504 if (!is_zero_ether_addr(wpa_s
->bssid
)) {
1505 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
1506 ieee80211_sta_deauthenticate(wpa_s
, reason_code
);
1508 wpa_drv_deauthenticate(wpa_s
, wpa_s
->bssid
,
1510 addr
= wpa_s
->bssid
;
1513 wpa_supplicant_clear_connection(wpa_s
, addr
);
1518 * wpa_supplicant_enable_network - Mark a configured network as enabled
1519 * @wpa_s: wpa_supplicant structure for a network interface
1520 * @ssid: wpa_ssid structure for a configured network or %NULL
1522 * Enables the specified network or all networks if no network specified.
1524 void wpa_supplicant_enable_network(struct wpa_supplicant
*wpa_s
,
1525 struct wpa_ssid
*ssid
)
1527 struct wpa_ssid
*other_ssid
;
1531 for (other_ssid
= wpa_s
->conf
->ssid
; other_ssid
;
1532 other_ssid
= other_ssid
->next
) {
1533 if (other_ssid
->disabled
== 2)
1534 continue; /* do not change persistent P2P group
1536 if (other_ssid
== wpa_s
->current_ssid
&&
1537 other_ssid
->disabled
)
1538 wpa_s
->reassociate
= 1;
1540 was_disabled
= other_ssid
->disabled
;
1542 other_ssid
->disabled
= 0;
1544 if (was_disabled
!= other_ssid
->disabled
)
1545 wpas_notify_network_enabled_changed(
1548 if (wpa_s
->reassociate
)
1549 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1550 } else if (ssid
->disabled
&& ssid
->disabled
!= 2) {
1551 if (wpa_s
->current_ssid
== NULL
) {
1553 * Try to reassociate since there is no current
1554 * configuration and a new network was made available.
1556 wpa_s
->reassociate
= 1;
1557 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1560 was_disabled
= ssid
->disabled
;
1564 if (was_disabled
!= ssid
->disabled
)
1565 wpas_notify_network_enabled_changed(wpa_s
, ssid
);
1571 * wpa_supplicant_disable_network - Mark a configured network as disabled
1572 * @wpa_s: wpa_supplicant structure for a network interface
1573 * @ssid: wpa_ssid structure for a configured network or %NULL
1575 * Disables the specified network or all networks if no network specified.
1577 void wpa_supplicant_disable_network(struct wpa_supplicant
*wpa_s
,
1578 struct wpa_ssid
*ssid
)
1580 struct wpa_ssid
*other_ssid
;
1584 for (other_ssid
= wpa_s
->conf
->ssid
; other_ssid
;
1585 other_ssid
= other_ssid
->next
) {
1586 was_disabled
= other_ssid
->disabled
;
1587 if (was_disabled
== 2)
1588 continue; /* do not change persistent P2P group
1591 other_ssid
->disabled
= 1;
1593 if (was_disabled
!= other_ssid
->disabled
)
1594 wpas_notify_network_enabled_changed(
1597 if (wpa_s
->current_ssid
)
1598 wpa_supplicant_disassociate(
1599 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1600 } else if (ssid
->disabled
!= 2) {
1601 if (ssid
== wpa_s
->current_ssid
)
1602 wpa_supplicant_disassociate(
1603 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1605 was_disabled
= ssid
->disabled
;
1609 if (was_disabled
!= ssid
->disabled
)
1610 wpas_notify_network_enabled_changed(wpa_s
, ssid
);
1616 * wpa_supplicant_select_network - Attempt association with a network
1617 * @wpa_s: wpa_supplicant structure for a network interface
1618 * @ssid: wpa_ssid structure for a configured network or %NULL for any network
1620 void wpa_supplicant_select_network(struct wpa_supplicant
*wpa_s
,
1621 struct wpa_ssid
*ssid
)
1624 struct wpa_ssid
*other_ssid
;
1626 if (ssid
&& ssid
!= wpa_s
->current_ssid
&& wpa_s
->current_ssid
)
1627 wpa_supplicant_disassociate(
1628 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1631 * Mark all other networks disabled or mark all networks enabled if no
1632 * network specified.
1634 for (other_ssid
= wpa_s
->conf
->ssid
; other_ssid
;
1635 other_ssid
= other_ssid
->next
) {
1636 int was_disabled
= other_ssid
->disabled
;
1637 if (was_disabled
== 2)
1638 continue; /* do not change persistent P2P group data */
1640 other_ssid
->disabled
= ssid
? (ssid
->id
!= other_ssid
->id
) : 0;
1642 if (was_disabled
!= other_ssid
->disabled
)
1643 wpas_notify_network_enabled_changed(wpa_s
, other_ssid
);
1645 wpa_s
->connect_without_scan
= NULL
;
1646 wpa_s
->disconnected
= 0;
1647 wpa_s
->reassociate
= 1;
1648 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1651 wpas_notify_network_selected(wpa_s
, ssid
);
1656 * wpa_supplicant_set_ap_scan - Set AP scan mode for interface
1657 * @wpa_s: wpa_supplicant structure for a network interface
1658 * @ap_scan: AP scan mode
1659 * Returns: 0 if succeed or -1 if ap_scan has an invalid value
1662 int wpa_supplicant_set_ap_scan(struct wpa_supplicant
*wpa_s
, int ap_scan
)
1667 if (ap_scan
< 0 || ap_scan
> 2)
1670 old_ap_scan
= wpa_s
->conf
->ap_scan
;
1671 wpa_s
->conf
->ap_scan
= ap_scan
;
1673 if (old_ap_scan
!= wpa_s
->conf
->ap_scan
)
1674 wpas_notify_ap_scan_changed(wpa_s
);
1681 * wpa_supplicant_set_bss_expiration_age - Set BSS entry expiration age
1682 * @wpa_s: wpa_supplicant structure for a network interface
1683 * @expire_age: Expiration age in seconds
1684 * Returns: 0 if succeed or -1 if expire_age has an invalid value
1687 int wpa_supplicant_set_bss_expiration_age(struct wpa_supplicant
*wpa_s
,
1688 unsigned int bss_expire_age
)
1690 if (bss_expire_age
< 10) {
1691 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid bss expiration age %u",
1695 wpa_msg(wpa_s
, MSG_DEBUG
, "Setting bss expiration age: %d sec",
1697 wpa_s
->conf
->bss_expiration_age
= bss_expire_age
;
1704 * wpa_supplicant_set_bss_expiration_count - Set BSS entry expiration scan count
1705 * @wpa_s: wpa_supplicant structure for a network interface
1706 * @expire_count: number of scans after which an unseen BSS is reclaimed
1707 * Returns: 0 if succeed or -1 if expire_count has an invalid value
1710 int wpa_supplicant_set_bss_expiration_count(struct wpa_supplicant
*wpa_s
,
1711 unsigned int bss_expire_count
)
1713 if (bss_expire_count
< 1) {
1714 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid bss expiration count %u",
1718 wpa_msg(wpa_s
, MSG_DEBUG
, "Setting bss expiration scan count: %u",
1720 wpa_s
->conf
->bss_expiration_scan_count
= bss_expire_count
;
1727 * wpa_supplicant_set_debug_params - Set global debug params
1728 * @global: wpa_global structure
1729 * @debug_level: debug level
1730 * @debug_timestamp: determines if show timestamp in debug data
1731 * @debug_show_keys: determines if show keys in debug data
1732 * Returns: 0 if succeed or -1 if debug_level has wrong value
1734 int wpa_supplicant_set_debug_params(struct wpa_global
*global
, int debug_level
,
1735 int debug_timestamp
, int debug_show_keys
)
1738 int old_level
, old_timestamp
, old_show_keys
;
1740 /* check for allowed debuglevels */
1741 if (debug_level
!= MSG_EXCESSIVE
&&
1742 debug_level
!= MSG_MSGDUMP
&&
1743 debug_level
!= MSG_DEBUG
&&
1744 debug_level
!= MSG_INFO
&&
1745 debug_level
!= MSG_WARNING
&&
1746 debug_level
!= MSG_ERROR
)
1749 old_level
= wpa_debug_level
;
1750 old_timestamp
= wpa_debug_timestamp
;
1751 old_show_keys
= wpa_debug_show_keys
;
1753 wpa_debug_level
= debug_level
;
1754 wpa_debug_timestamp
= debug_timestamp
? 1 : 0;
1755 wpa_debug_show_keys
= debug_show_keys
? 1 : 0;
1757 if (wpa_debug_level
!= old_level
)
1758 wpas_notify_debug_level_changed(global
);
1759 if (wpa_debug_timestamp
!= old_timestamp
)
1760 wpas_notify_debug_timestamp_changed(global
);
1761 if (wpa_debug_show_keys
!= old_show_keys
)
1762 wpas_notify_debug_show_keys_changed(global
);
1769 * wpa_supplicant_get_ssid - Get a pointer to the current network structure
1770 * @wpa_s: Pointer to wpa_supplicant data
1771 * Returns: A pointer to the current network structure or %NULL on failure
1773 struct wpa_ssid
* wpa_supplicant_get_ssid(struct wpa_supplicant
*wpa_s
)
1775 struct wpa_ssid
*entry
;
1776 u8 ssid
[MAX_SSID_LEN
];
1782 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
) {
1783 if (ieee80211_sta_get_ssid(wpa_s
, ssid
, &ssid_len
)) {
1784 wpa_msg(wpa_s
, MSG_WARNING
, "Could not read SSID from "
1789 res
= wpa_drv_get_ssid(wpa_s
, ssid
);
1791 wpa_msg(wpa_s
, MSG_WARNING
, "Could not read SSID from "
1798 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
1799 os_memcpy(bssid
, wpa_s
->bssid
, ETH_ALEN
);
1800 else if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0) {
1801 wpa_msg(wpa_s
, MSG_WARNING
, "Could not read BSSID from "
1806 wired
= wpa_s
->conf
->ap_scan
== 0 &&
1807 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
);
1809 entry
= wpa_s
->conf
->ssid
;
1811 if (!entry
->disabled
&&
1812 ((ssid_len
== entry
->ssid_len
&&
1813 os_memcmp(ssid
, entry
->ssid
, ssid_len
) == 0) || wired
) &&
1814 (!entry
->bssid_set
||
1815 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0))
1818 if (!entry
->disabled
&&
1819 (entry
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
1820 (entry
->ssid
== NULL
|| entry
->ssid_len
== 0) &&
1821 (!entry
->bssid_set
||
1822 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0))
1824 #endif /* CONFIG_WPS */
1825 entry
= entry
->next
;
1832 static int wpa_supplicant_set_driver(struct wpa_supplicant
*wpa_s
,
1837 const char *pos
, *driver
= name
;
1842 if (wpa_drivers
[0] == NULL
) {
1843 wpa_msg(wpa_s
, MSG_ERROR
, "No driver interfaces build into "
1849 /* default to first driver in the list */
1850 wpa_s
->driver
= wpa_drivers
[0];
1851 wpa_s
->global_drv_priv
= wpa_s
->global
->drv_priv
[0];
1856 pos
= os_strchr(driver
, ',');
1860 len
= os_strlen(driver
);
1862 for (i
= 0; wpa_drivers
[i
]; i
++) {
1863 if (os_strlen(wpa_drivers
[i
]->name
) == len
&&
1864 os_strncmp(driver
, wpa_drivers
[i
]->name
, len
) ==
1866 wpa_s
->driver
= wpa_drivers
[i
];
1867 wpa_s
->global_drv_priv
=
1868 wpa_s
->global
->drv_priv
[i
];
1876 wpa_msg(wpa_s
, MSG_ERROR
, "Unsupported driver '%s'", name
);
1882 * wpa_supplicant_rx_eapol - Deliver a received EAPOL frame to wpa_supplicant
1883 * @ctx: Context pointer (wpa_s); this is the ctx variable registered
1884 * with struct wpa_driver_ops::init()
1885 * @src_addr: Source address of the EAPOL frame
1886 * @buf: EAPOL data starting from the EAPOL header (i.e., no Ethernet header)
1887 * @len: Length of the EAPOL data
1889 * This function is called for each received EAPOL frame. Most driver
1890 * interfaces rely on more generic OS mechanism for receiving frames through
1891 * l2_packet, but if such a mechanism is not available, the driver wrapper may
1892 * take care of received EAPOL frames and deliver them to the core supplicant
1893 * code by calling this function.
1895 void wpa_supplicant_rx_eapol(void *ctx
, const u8
*src_addr
,
1896 const u8
*buf
, size_t len
)
1898 struct wpa_supplicant
*wpa_s
= ctx
;
1900 wpa_dbg(wpa_s
, MSG_DEBUG
, "RX EAPOL from " MACSTR
, MAC2STR(src_addr
));
1901 wpa_hexdump(MSG_MSGDUMP
, "RX EAPOL", buf
, len
);
1903 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
) {
1905 * There is possible race condition between receiving the
1906 * association event and the EAPOL frame since they are coming
1907 * through different paths from the driver. In order to avoid
1908 * issues in trying to process the EAPOL frame before receiving
1909 * association information, lets queue it for processing until
1910 * the association event is received.
1912 wpa_dbg(wpa_s
, MSG_DEBUG
, "Not associated - Delay processing "
1913 "of received EAPOL frame");
1914 wpabuf_free(wpa_s
->pending_eapol_rx
);
1915 wpa_s
->pending_eapol_rx
= wpabuf_alloc_copy(buf
, len
);
1916 if (wpa_s
->pending_eapol_rx
) {
1917 os_get_time(&wpa_s
->pending_eapol_rx_time
);
1918 os_memcpy(wpa_s
->pending_eapol_rx_src
, src_addr
,
1925 if (wpa_s
->ap_iface
) {
1926 wpa_supplicant_ap_rx_eapol(wpa_s
, src_addr
, buf
, len
);
1929 #endif /* CONFIG_AP */
1931 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
) {
1932 wpa_dbg(wpa_s
, MSG_DEBUG
, "Ignored received EAPOL frame since "
1933 "no key management is configured");
1937 if (wpa_s
->eapol_received
== 0 &&
1938 (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) ||
1939 !wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
1940 wpa_s
->wpa_state
!= WPA_COMPLETED
) &&
1941 (wpa_s
->current_ssid
== NULL
||
1942 wpa_s
->current_ssid
->mode
!= IEEE80211_MODE_IBSS
)) {
1943 /* Timeout for completing IEEE 802.1X and WPA authentication */
1944 wpa_supplicant_req_auth_timeout(
1946 (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
1947 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
||
1948 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
) ?
1951 wpa_s
->eapol_received
++;
1953 if (wpa_s
->countermeasures
) {
1954 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Countermeasures - dropped "
1959 #ifdef CONFIG_IBSS_RSN
1960 if (wpa_s
->current_ssid
&&
1961 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
) {
1962 ibss_rsn_rx_eapol(wpa_s
->ibss_rsn
, src_addr
, buf
, len
);
1965 #endif /* CONFIG_IBSS_RSN */
1967 /* Source address of the incoming EAPOL frame could be compared to the
1968 * current BSSID. However, it is possible that a centralized
1969 * Authenticator could be using another MAC address than the BSSID of
1970 * an AP, so just allow any address to be used for now. The replies are
1971 * still sent to the current BSSID (if available), though. */
1973 os_memcpy(wpa_s
->last_eapol_src
, src_addr
, ETH_ALEN
);
1974 if (!wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) &&
1975 eapol_sm_rx_eapol(wpa_s
->eapol
, src_addr
, buf
, len
) > 0)
1977 wpa_drv_poll(wpa_s
);
1978 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
))
1979 wpa_sm_rx_eapol(wpa_s
->wpa
, src_addr
, buf
, len
);
1980 else if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1982 * Set portValid = TRUE here since we are going to skip 4-way
1983 * handshake processing which would normally set portValid. We
1984 * need this to allow the EAPOL state machines to be completed
1985 * without going through EAPOL-Key handshake.
1987 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1993 * wpa_supplicant_driver_init - Initialize driver interface parameters
1994 * @wpa_s: Pointer to wpa_supplicant data
1995 * Returns: 0 on success, -1 on failure
1997 * This function is called to initialize driver interface parameters.
1998 * wpa_drv_init() must have been called before this function to initialize the
2001 int wpa_supplicant_driver_init(struct wpa_supplicant
*wpa_s
)
2003 static int interface_count
= 0;
2005 if (wpa_s
->driver
->send_eapol
) {
2006 const u8
*addr
= wpa_drv_get_mac_addr(wpa_s
);
2008 os_memcpy(wpa_s
->own_addr
, addr
, ETH_ALEN
);
2009 } else if (!(wpa_s
->drv_flags
&
2010 WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE
)) {
2011 wpa_s
->l2
= l2_packet_init(wpa_s
->ifname
,
2012 wpa_drv_get_mac_addr(wpa_s
),
2014 wpa_supplicant_rx_eapol
, wpa_s
, 0);
2015 if (wpa_s
->l2
== NULL
)
2018 const u8
*addr
= wpa_drv_get_mac_addr(wpa_s
);
2020 os_memcpy(wpa_s
->own_addr
, addr
, ETH_ALEN
);
2023 if (wpa_s
->l2
&& l2_packet_get_own_addr(wpa_s
->l2
, wpa_s
->own_addr
)) {
2024 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to get own L2 address");
2028 wpa_dbg(wpa_s
, MSG_DEBUG
, "Own MAC address: " MACSTR
,
2029 MAC2STR(wpa_s
->own_addr
));
2031 if (wpa_s
->bridge_ifname
[0]) {
2032 wpa_dbg(wpa_s
, MSG_DEBUG
, "Receiving packets from bridge "
2033 "interface '%s'", wpa_s
->bridge_ifname
);
2034 wpa_s
->l2_br
= l2_packet_init(wpa_s
->bridge_ifname
,
2037 wpa_supplicant_rx_eapol
, wpa_s
,
2039 if (wpa_s
->l2_br
== NULL
) {
2040 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to open l2_packet "
2041 "connection for the bridge interface '%s'",
2042 wpa_s
->bridge_ifname
);
2047 wpa_clear_keys(wpa_s
, NULL
);
2049 /* Make sure that TKIP countermeasures are not left enabled (could
2050 * happen if wpa_supplicant is killed during countermeasures. */
2051 wpa_drv_set_countermeasures(wpa_s
, 0);
2053 wpa_dbg(wpa_s
, MSG_DEBUG
, "RSN: flushing PMKID list in the driver");
2054 wpa_drv_flush_pmkid(wpa_s
);
2056 wpa_s
->prev_scan_ssid
= WILDCARD_SSID_SCAN
;
2057 if (wpa_supplicant_enabled_networks(wpa_s
->conf
)) {
2058 wpa_supplicant_req_scan(wpa_s
, interface_count
, 100000);
2061 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
2067 static int wpa_supplicant_daemon(const char *pid_file
)
2069 wpa_printf(MSG_DEBUG
, "Daemonize..");
2070 return os_daemonize(pid_file
);
2074 static struct wpa_supplicant
* wpa_supplicant_alloc(void)
2076 struct wpa_supplicant
*wpa_s
;
2078 wpa_s
= os_zalloc(sizeof(*wpa_s
));
2081 wpa_s
->scan_req
= 1;
2082 wpa_s
->scan_interval
= 5;
2083 wpa_s
->new_connection
= 1;
2084 wpa_s
->parent
= wpa_s
;
2090 static int wpa_supplicant_init_iface(struct wpa_supplicant
*wpa_s
,
2091 struct wpa_interface
*iface
)
2093 const char *ifname
, *driver
;
2094 struct wpa_driver_capa capa
;
2096 wpa_printf(MSG_DEBUG
, "Initializing interface '%s' conf '%s' driver "
2097 "'%s' ctrl_interface '%s' bridge '%s'", iface
->ifname
,
2098 iface
->confname
? iface
->confname
: "N/A",
2099 iface
->driver
? iface
->driver
: "default",
2100 iface
->ctrl_interface
? iface
->ctrl_interface
: "N/A",
2101 iface
->bridge_ifname
? iface
->bridge_ifname
: "N/A");
2103 if (iface
->confname
) {
2104 #ifdef CONFIG_BACKEND_FILE
2105 wpa_s
->confname
= os_rel2abs_path(iface
->confname
);
2106 if (wpa_s
->confname
== NULL
) {
2107 wpa_printf(MSG_ERROR
, "Failed to get absolute path "
2108 "for configuration file '%s'.",
2112 wpa_printf(MSG_DEBUG
, "Configuration file '%s' -> '%s'",
2113 iface
->confname
, wpa_s
->confname
);
2114 #else /* CONFIG_BACKEND_FILE */
2115 wpa_s
->confname
= os_strdup(iface
->confname
);
2116 #endif /* CONFIG_BACKEND_FILE */
2117 wpa_s
->conf
= wpa_config_read(wpa_s
->confname
);
2118 if (wpa_s
->conf
== NULL
) {
2119 wpa_printf(MSG_ERROR
, "Failed to read or parse "
2120 "configuration '%s'.", wpa_s
->confname
);
2125 * Override ctrl_interface and driver_param if set on command
2128 if (iface
->ctrl_interface
) {
2129 os_free(wpa_s
->conf
->ctrl_interface
);
2130 wpa_s
->conf
->ctrl_interface
=
2131 os_strdup(iface
->ctrl_interface
);
2134 if (iface
->driver_param
) {
2135 os_free(wpa_s
->conf
->driver_param
);
2136 wpa_s
->conf
->driver_param
=
2137 os_strdup(iface
->driver_param
);
2140 wpa_s
->conf
= wpa_config_alloc_empty(iface
->ctrl_interface
,
2141 iface
->driver_param
);
2143 if (wpa_s
->conf
== NULL
) {
2144 wpa_printf(MSG_ERROR
, "\nNo configuration found.");
2148 if (iface
->ifname
== NULL
) {
2149 wpa_printf(MSG_ERROR
, "\nInterface name is required.");
2152 if (os_strlen(iface
->ifname
) >= sizeof(wpa_s
->ifname
)) {
2153 wpa_printf(MSG_ERROR
, "\nToo long interface name '%s'.",
2157 os_strlcpy(wpa_s
->ifname
, iface
->ifname
, sizeof(wpa_s
->ifname
));
2159 if (iface
->bridge_ifname
) {
2160 if (os_strlen(iface
->bridge_ifname
) >=
2161 sizeof(wpa_s
->bridge_ifname
)) {
2162 wpa_printf(MSG_ERROR
, "\nToo long bridge interface "
2163 "name '%s'.", iface
->bridge_ifname
);
2166 os_strlcpy(wpa_s
->bridge_ifname
, iface
->bridge_ifname
,
2167 sizeof(wpa_s
->bridge_ifname
));
2170 /* RSNA Supplicant Key Management - INITIALIZE */
2171 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
2172 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
2174 /* Initialize driver interface and register driver event handler before
2175 * L2 receive handler so that association events are processed before
2176 * EAPOL-Key packets if both become available for the same select()
2178 driver
= iface
->driver
;
2180 if (wpa_supplicant_set_driver(wpa_s
, driver
) < 0)
2183 wpa_s
->drv_priv
= wpa_drv_init(wpa_s
, wpa_s
->ifname
);
2184 if (wpa_s
->drv_priv
== NULL
) {
2186 pos
= driver
? os_strchr(driver
, ',') : NULL
;
2188 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to initialize "
2189 "driver interface - try next driver wrapper");
2193 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to initialize driver "
2197 if (wpa_drv_set_param(wpa_s
, wpa_s
->conf
->driver_param
) < 0) {
2198 wpa_msg(wpa_s
, MSG_ERROR
, "Driver interface rejected "
2199 "driver_param '%s'", wpa_s
->conf
->driver_param
);
2203 ifname
= wpa_drv_get_ifname(wpa_s
);
2204 if (ifname
&& os_strcmp(ifname
, wpa_s
->ifname
) != 0) {
2205 wpa_dbg(wpa_s
, MSG_DEBUG
, "Driver interface replaced "
2206 "interface name with '%s'", ifname
);
2207 os_strlcpy(wpa_s
->ifname
, ifname
, sizeof(wpa_s
->ifname
));
2210 if (wpa_supplicant_init_wpa(wpa_s
) < 0)
2213 wpa_sm_set_ifname(wpa_s
->wpa
, wpa_s
->ifname
,
2214 wpa_s
->bridge_ifname
[0] ? wpa_s
->bridge_ifname
:
2216 wpa_sm_set_fast_reauth(wpa_s
->wpa
, wpa_s
->conf
->fast_reauth
);
2218 if (wpa_s
->conf
->dot11RSNAConfigPMKLifetime
&&
2219 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
2220 wpa_s
->conf
->dot11RSNAConfigPMKLifetime
)) {
2221 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid WPA parameter value for "
2222 "dot11RSNAConfigPMKLifetime");
2226 if (wpa_s
->conf
->dot11RSNAConfigPMKReauthThreshold
&&
2227 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
2228 wpa_s
->conf
->dot11RSNAConfigPMKReauthThreshold
)) {
2229 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid WPA parameter value for "
2230 "dot11RSNAConfigPMKReauthThreshold");
2234 if (wpa_s
->conf
->dot11RSNAConfigSATimeout
&&
2235 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
,
2236 wpa_s
->conf
->dot11RSNAConfigSATimeout
)) {
2237 wpa_msg(wpa_s
, MSG_ERROR
, "Invalid WPA parameter value for "
2238 "dot11RSNAConfigSATimeout");
2242 if (wpa_drv_get_capa(wpa_s
, &capa
) == 0) {
2243 wpa_s
->drv_flags
= capa
.flags
;
2244 if (capa
.flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
) {
2245 if (ieee80211_sta_init(wpa_s
))
2248 wpa_s
->max_scan_ssids
= capa
.max_scan_ssids
;
2249 wpa_s
->max_remain_on_chan
= capa
.max_remain_on_chan
;
2250 wpa_s
->max_stations
= capa
.max_stations
;
2252 if (wpa_s
->max_remain_on_chan
== 0)
2253 wpa_s
->max_remain_on_chan
= 1000;
2255 if (wpa_supplicant_driver_init(wpa_s
) < 0)
2259 if (wpa_tdls_init(wpa_s
->wpa
))
2261 #endif /* CONFIG_TDLS */
2263 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1] &&
2264 wpa_drv_set_country(wpa_s
, wpa_s
->conf
->country
)) {
2265 wpa_dbg(wpa_s
, MSG_DEBUG
, "Failed to set country");
2269 wpa_sm_set_own_addr(wpa_s
->wpa
, wpa_s
->own_addr
);
2271 if (wpas_wps_init(wpa_s
))
2274 if (wpa_supplicant_init_eapol(wpa_s
) < 0)
2276 wpa_sm_set_eapol(wpa_s
->wpa
, wpa_s
->eapol
);
2278 wpa_s
->ctrl_iface
= wpa_supplicant_ctrl_iface_init(wpa_s
);
2279 if (wpa_s
->ctrl_iface
== NULL
) {
2280 wpa_printf(MSG_ERROR
,
2281 "Failed to initialize control interface '%s'.\n"
2282 "You may have another wpa_supplicant process "
2283 "already running or the file was\n"
2284 "left by an unclean termination of wpa_supplicant "
2285 "in which case you will need\n"
2286 "to manually remove this file before starting "
2287 "wpa_supplicant again.\n",
2288 wpa_s
->conf
->ctrl_interface
);
2292 wpa_s
->gas
= gas_query_init(wpa_s
);
2293 if (wpa_s
->gas
== NULL
) {
2294 wpa_printf(MSG_ERROR
, "Failed to initialize GAS query");
2299 if (wpas_p2p_init(wpa_s
->global
, wpa_s
) < 0) {
2300 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to init P2P");
2303 #endif /* CONFIG_P2P */
2305 if (wpa_bss_init(wpa_s
) < 0)
2312 static void wpa_supplicant_deinit_iface(struct wpa_supplicant
*wpa_s
,
2315 if (wpa_s
->drv_priv
) {
2316 wpa_supplicant_deauthenticate(wpa_s
,
2317 WLAN_REASON_DEAUTH_LEAVING
);
2319 wpa_drv_set_countermeasures(wpa_s
, 0);
2320 wpa_clear_keys(wpa_s
, NULL
);
2323 wpa_supplicant_cleanup(wpa_s
);
2326 wpas_notify_iface_removed(wpa_s
);
2328 if (wpa_s
->drv_priv
)
2329 wpa_drv_deinit(wpa_s
);
2334 * wpa_supplicant_add_iface - Add a new network interface
2335 * @global: Pointer to global data from wpa_supplicant_init()
2336 * @iface: Interface configuration options
2337 * Returns: Pointer to the created interface or %NULL on failure
2339 * This function is used to add new network interfaces for %wpa_supplicant.
2340 * This can be called before wpa_supplicant_run() to add interfaces before the
2341 * main event loop has been started. In addition, new interfaces can be added
2342 * dynamically while %wpa_supplicant is already running. This could happen,
2343 * e.g., when a hotplug network adapter is inserted.
2345 struct wpa_supplicant
* wpa_supplicant_add_iface(struct wpa_global
*global
,
2346 struct wpa_interface
*iface
)
2348 struct wpa_supplicant
*wpa_s
;
2349 struct wpa_interface t_iface
;
2350 struct wpa_ssid
*ssid
;
2352 if (global
== NULL
|| iface
== NULL
)
2355 wpa_s
= wpa_supplicant_alloc();
2359 wpa_s
->global
= global
;
2362 if (global
->params
.override_driver
) {
2363 wpa_printf(MSG_DEBUG
, "Override interface parameter: driver "
2365 iface
->driver
, global
->params
.override_driver
);
2366 t_iface
.driver
= global
->params
.override_driver
;
2368 if (global
->params
.override_ctrl_interface
) {
2369 wpa_printf(MSG_DEBUG
, "Override interface parameter: "
2370 "ctrl_interface ('%s' -> '%s')",
2371 iface
->ctrl_interface
,
2372 global
->params
.override_ctrl_interface
);
2373 t_iface
.ctrl_interface
=
2374 global
->params
.override_ctrl_interface
;
2376 if (wpa_supplicant_init_iface(wpa_s
, &t_iface
)) {
2377 wpa_printf(MSG_DEBUG
, "Failed to add interface %s",
2379 wpa_supplicant_deinit_iface(wpa_s
, 0);
2384 /* Notify the control interfaces about new iface */
2385 if (wpas_notify_iface_added(wpa_s
)) {
2386 wpa_supplicant_deinit_iface(wpa_s
, 1);
2391 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
)
2392 wpas_notify_network_added(wpa_s
, ssid
);
2394 wpa_s
->next
= global
->ifaces
;
2395 global
->ifaces
= wpa_s
;
2397 wpa_dbg(wpa_s
, MSG_DEBUG
, "Added interface %s", wpa_s
->ifname
);
2404 * wpa_supplicant_remove_iface - Remove a network interface
2405 * @global: Pointer to global data from wpa_supplicant_init()
2406 * @wpa_s: Pointer to the network interface to be removed
2407 * Returns: 0 if interface was removed, -1 if interface was not found
2409 * This function can be used to dynamically remove network interfaces from
2410 * %wpa_supplicant, e.g., when a hotplug network adapter is ejected. In
2411 * addition, this function is used to remove all remaining interfaces when
2412 * %wpa_supplicant is terminated.
2414 int wpa_supplicant_remove_iface(struct wpa_global
*global
,
2415 struct wpa_supplicant
*wpa_s
)
2417 struct wpa_supplicant
*prev
;
2419 /* Remove interface from the global list of interfaces */
2420 prev
= global
->ifaces
;
2421 if (prev
== wpa_s
) {
2422 global
->ifaces
= wpa_s
->next
;
2424 while (prev
&& prev
->next
!= wpa_s
)
2428 prev
->next
= wpa_s
->next
;
2431 wpa_dbg(wpa_s
, MSG_DEBUG
, "Removing interface %s", wpa_s
->ifname
);
2433 if (global
->p2p_group_formation
== wpa_s
)
2434 global
->p2p_group_formation
= NULL
;
2435 wpa_supplicant_deinit_iface(wpa_s
, 1);
2443 * wpa_supplicant_get_eap_mode - Get the current EAP mode
2444 * @wpa_s: Pointer to the network interface
2445 * Returns: Pointer to the eap mode or the string "UNKNOWN" if not found
2447 const char * wpa_supplicant_get_eap_mode(struct wpa_supplicant
*wpa_s
)
2449 const char *eapol_method
;
2451 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) == 0 &&
2452 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
2456 eapol_method
= eapol_sm_get_method_name(wpa_s
->eapol
);
2457 if (eapol_method
== NULL
)
2458 return "UNKNOWN-EAP";
2460 return eapol_method
;
2465 * wpa_supplicant_get_iface - Get a new network interface
2466 * @global: Pointer to global data from wpa_supplicant_init()
2467 * @ifname: Interface name
2468 * Returns: Pointer to the interface or %NULL if not found
2470 struct wpa_supplicant
* wpa_supplicant_get_iface(struct wpa_global
*global
,
2473 struct wpa_supplicant
*wpa_s
;
2475 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2476 if (os_strcmp(wpa_s
->ifname
, ifname
) == 0)
2483 #ifndef CONFIG_NO_WPA_MSG
2484 static const char * wpa_supplicant_msg_ifname_cb(void *ctx
)
2486 struct wpa_supplicant
*wpa_s
= ctx
;
2489 return wpa_s
->ifname
;
2491 #endif /* CONFIG_NO_WPA_MSG */
2495 * wpa_supplicant_init - Initialize %wpa_supplicant
2496 * @params: Parameters for %wpa_supplicant
2497 * Returns: Pointer to global %wpa_supplicant data, or %NULL on failure
2499 * This function is used to initialize %wpa_supplicant. After successful
2500 * initialization, the returned data pointer can be used to add and remove
2501 * network interfaces, and eventually, to deinitialize %wpa_supplicant.
2503 struct wpa_global
* wpa_supplicant_init(struct wpa_params
*params
)
2505 struct wpa_global
*global
;
2511 #ifndef CONFIG_NO_WPA_MSG
2512 wpa_msg_register_ifname_cb(wpa_supplicant_msg_ifname_cb
);
2513 #endif /* CONFIG_NO_WPA_MSG */
2515 wpa_debug_open_file(params
->wpa_debug_file_path
);
2516 if (params
->wpa_debug_syslog
)
2517 wpa_debug_open_syslog();
2519 ret
= eap_register_methods();
2521 wpa_printf(MSG_ERROR
, "Failed to register EAP methods");
2523 wpa_printf(MSG_ERROR
, "Two or more EAP methods used "
2524 "the same EAP type.");
2528 global
= os_zalloc(sizeof(*global
));
2531 dl_list_init(&global
->p2p_srv_bonjour
);
2532 dl_list_init(&global
->p2p_srv_upnp
);
2533 global
->params
.daemonize
= params
->daemonize
;
2534 global
->params
.wait_for_monitor
= params
->wait_for_monitor
;
2535 global
->params
.dbus_ctrl_interface
= params
->dbus_ctrl_interface
;
2536 if (params
->pid_file
)
2537 global
->params
.pid_file
= os_strdup(params
->pid_file
);
2538 if (params
->ctrl_interface
)
2539 global
->params
.ctrl_interface
=
2540 os_strdup(params
->ctrl_interface
);
2541 if (params
->override_driver
)
2542 global
->params
.override_driver
=
2543 os_strdup(params
->override_driver
);
2544 if (params
->override_ctrl_interface
)
2545 global
->params
.override_ctrl_interface
=
2546 os_strdup(params
->override_ctrl_interface
);
2547 wpa_debug_level
= global
->params
.wpa_debug_level
=
2548 params
->wpa_debug_level
;
2549 wpa_debug_show_keys
= global
->params
.wpa_debug_show_keys
=
2550 params
->wpa_debug_show_keys
;
2551 wpa_debug_timestamp
= global
->params
.wpa_debug_timestamp
=
2552 params
->wpa_debug_timestamp
;
2554 wpa_printf(MSG_DEBUG
, "wpa_supplicant v" VERSION_STR
);
2557 wpa_printf(MSG_ERROR
, "Failed to initialize event loop");
2558 wpa_supplicant_deinit(global
);
2562 random_init(params
->entropy_file
);
2564 global
->ctrl_iface
= wpa_supplicant_global_ctrl_iface_init(global
);
2565 if (global
->ctrl_iface
== NULL
) {
2566 wpa_supplicant_deinit(global
);
2570 if (wpas_notify_supplicant_initialized(global
)) {
2571 wpa_supplicant_deinit(global
);
2575 for (i
= 0; wpa_drivers
[i
]; i
++)
2576 global
->drv_count
++;
2577 if (global
->drv_count
== 0) {
2578 wpa_printf(MSG_ERROR
, "No drivers enabled");
2579 wpa_supplicant_deinit(global
);
2582 global
->drv_priv
= os_zalloc(global
->drv_count
* sizeof(void *));
2583 if (global
->drv_priv
== NULL
) {
2584 wpa_supplicant_deinit(global
);
2587 for (i
= 0; wpa_drivers
[i
]; i
++) {
2588 if (!wpa_drivers
[i
]->global_init
)
2590 global
->drv_priv
[i
] = wpa_drivers
[i
]->global_init();
2591 if (global
->drv_priv
[i
] == NULL
) {
2592 wpa_printf(MSG_ERROR
, "Failed to initialize driver "
2593 "'%s'", wpa_drivers
[i
]->name
);
2594 wpa_supplicant_deinit(global
);
2604 * wpa_supplicant_run - Run the %wpa_supplicant main event loop
2605 * @global: Pointer to global data from wpa_supplicant_init()
2606 * Returns: 0 after successful event loop run, -1 on failure
2608 * This function starts the main event loop and continues running as long as
2609 * there are any remaining events. In most cases, this function is running as
2610 * long as the %wpa_supplicant process in still in use.
2612 int wpa_supplicant_run(struct wpa_global
*global
)
2614 struct wpa_supplicant
*wpa_s
;
2616 if (global
->params
.daemonize
&&
2617 wpa_supplicant_daemon(global
->params
.pid_file
))
2620 if (global
->params
.wait_for_monitor
) {
2621 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
)
2622 if (wpa_s
->ctrl_iface
)
2623 wpa_supplicant_ctrl_iface_wait(
2627 eloop_register_signal_terminate(wpa_supplicant_terminate
, global
);
2628 eloop_register_signal_reconfig(wpa_supplicant_reconfig
, global
);
2637 * wpa_supplicant_deinit - Deinitialize %wpa_supplicant
2638 * @global: Pointer to global data from wpa_supplicant_init()
2640 * This function is called to deinitialize %wpa_supplicant and to free all
2641 * allocated resources. Remaining network interfaces will also be removed.
2643 void wpa_supplicant_deinit(struct wpa_global
*global
)
2651 wpas_p2p_deinit_global(global
);
2652 #endif /* CONFIG_P2P */
2654 while (global
->ifaces
)
2655 wpa_supplicant_remove_iface(global
, global
->ifaces
);
2657 if (global
->ctrl_iface
)
2658 wpa_supplicant_global_ctrl_iface_deinit(global
->ctrl_iface
);
2660 wpas_notify_supplicant_deinitialized(global
);
2662 eap_peer_unregister_methods();
2664 eap_server_unregister_methods();
2665 #endif /* CONFIG_AP */
2667 for (i
= 0; wpa_drivers
[i
] && global
->drv_priv
; i
++) {
2668 if (!global
->drv_priv
[i
])
2670 wpa_drivers
[i
]->global_deinit(global
->drv_priv
[i
]);
2672 os_free(global
->drv_priv
);
2678 if (global
->params
.pid_file
) {
2679 os_daemonize_terminate(global
->params
.pid_file
);
2680 os_free(global
->params
.pid_file
);
2682 os_free(global
->params
.ctrl_interface
);
2683 os_free(global
->params
.override_driver
);
2684 os_free(global
->params
.override_ctrl_interface
);
2687 wpa_debug_close_syslog();
2688 wpa_debug_close_file();
2692 void wpa_supplicant_update_config(struct wpa_supplicant
*wpa_s
)
2694 if ((wpa_s
->conf
->changed_parameters
& CFG_CHANGED_COUNTRY
) &&
2695 wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1]) {
2697 country
[0] = wpa_s
->conf
->country
[0];
2698 country
[1] = wpa_s
->conf
->country
[1];
2700 if (wpa_drv_set_country(wpa_s
, country
) < 0) {
2701 wpa_printf(MSG_ERROR
, "Failed to set country code "
2707 wpas_wps_update_config(wpa_s
);
2708 #endif /* CONFIG_WPS */
2711 wpas_p2p_update_config(wpa_s
);
2712 #endif /* CONFIG_P2P */
2714 wpa_s
->conf
->changed_parameters
= 0;
2718 void ieee80211_sta_free_hw_features(struct hostapd_hw_modes
*hw_features
,
2719 size_t num_hw_features
)
2723 if (hw_features
== NULL
)
2726 for (i
= 0; i
< num_hw_features
; i
++) {
2727 os_free(hw_features
[i
].channels
);
2728 os_free(hw_features
[i
].rates
);
2731 os_free(hw_features
);
2735 static void add_freq(int *freqs
, int *num_freqs
, int freq
)
2739 for (i
= 0; i
< *num_freqs
; i
++) {
2740 if (freqs
[i
] == freq
)
2744 freqs
[*num_freqs
] = freq
;
2749 static int * get_bss_freqs_in_ess(struct wpa_supplicant
*wpa_s
)
2751 struct wpa_bss
*bss
, *cbss
;
2752 const int max_freqs
= 10;
2756 freqs
= os_zalloc(sizeof(int) * (max_freqs
+ 1));
2760 cbss
= wpa_s
->current_bss
;
2762 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
2765 if (bss
->ssid_len
== cbss
->ssid_len
&&
2766 os_memcmp(bss
->ssid
, cbss
->ssid
, bss
->ssid_len
) == 0 &&
2767 wpa_blacklist_get(wpa_s
, bss
->bssid
) == NULL
) {
2768 add_freq(freqs
, &num_freqs
, bss
->freq
);
2769 if (num_freqs
== max_freqs
)
2774 if (num_freqs
== 0) {
2783 void wpas_connection_failed(struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
2790 * Add the failed BSSID into the blacklist and speed up next scan
2791 * attempt if there could be other APs that could accept association.
2792 * The current blacklist count indicates how many times we have tried
2793 * connecting to this AP and multiple attempts mean that other APs are
2794 * either not available or has already been tried, so that we can start
2795 * increasing the delay here to avoid constant scanning.
2797 count
= wpa_blacklist_add(wpa_s
, bssid
);
2798 if (count
== 1 && wpa_s
->current_bss
) {
2800 * This BSS was not in the blacklist before. If there is
2801 * another BSS available for the same ESS, we should try that
2802 * next. Otherwise, we may as well try this one once more
2803 * before allowing other, likely worse, ESSes to be considered.
2805 freqs
= get_bss_freqs_in_ess(wpa_s
);
2807 wpa_dbg(wpa_s
, MSG_DEBUG
, "Another BSS in this ESS "
2808 "has been seen; try it next");
2809 wpa_blacklist_add(wpa_s
, bssid
);
2811 * On the next scan, go through only the known channels
2812 * used in this ESS based on previous scans to speed up
2813 * common load balancing use case.
2815 os_free(wpa_s
->next_scan_freqs
);
2816 wpa_s
->next_scan_freqs
= freqs
;
2835 * TODO: if more than one possible AP is available in scan results,
2836 * could try the other ones before requesting a new scan.
2838 wpa_supplicant_req_scan(wpa_s
, timeout
/ 1000,
2839 1000 * (timeout
% 1000));
2843 int wpas_driver_bss_selection(struct wpa_supplicant
*wpa_s
)
2845 return wpa_s
->conf
->ap_scan
== 2 ||
2846 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_BSS_SELECTION
);