3 * Copyright (c) 2003-2010, 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 "eapol_supp/eapol_supp_sm.h"
23 #include "eap_peer/eap.h"
24 #include "eap_server/eap_methods.h"
25 #include "rsn_supp/wpa.h"
28 #include "l2_packet/l2_packet.h"
29 #include "wpa_supplicant_i.h"
31 #include "ctrl_iface.h"
32 #include "pcsc_funcs.h"
33 #include "common/version.h"
34 #include "rsn_supp/preauth.h"
35 #include "rsn_supp/pmksa_cache.h"
36 #include "common/wpa_ctrl.h"
38 #include "common/ieee802_11_defs.h"
39 #include "blacklist.h"
40 #include "wpas_glue.h"
41 #include "wps_supplicant.h"
50 const char *wpa_supplicant_version
=
51 "wpa_supplicant v" VERSION_STR
"\n"
52 "Copyright (c) 2003-2010, Jouni Malinen <j@w1.fi> and contributors";
54 const char *wpa_supplicant_license
=
55 "This program is free software. You can distribute it and/or modify it\n"
56 "under the terms of the GNU General Public License version 2.\n"
58 "Alternatively, this software may be distributed under the terms of the\n"
59 "BSD license. See README and COPYING for more details.\n"
60 #ifdef EAP_TLS_OPENSSL
61 "\nThis product includes software developed by the OpenSSL Project\n"
62 "for use in the OpenSSL Toolkit (http://www.openssl.org/)\n"
63 #endif /* EAP_TLS_OPENSSL */
66 #ifndef CONFIG_NO_STDOUT_DEBUG
67 /* Long text divided into parts in order to fit in C89 strings size limits. */
68 const char *wpa_supplicant_full_license1
=
69 "This program is free software; you can redistribute it and/or modify\n"
70 "it under the terms of the GNU General Public License version 2 as\n"
71 "published by the Free Software Foundation.\n"
73 "This program is distributed in the hope that it will be useful,\n"
74 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
75 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
76 "GNU General Public License for more details.\n"
78 const char *wpa_supplicant_full_license2
=
79 "You should have received a copy of the GNU General Public License\n"
80 "along with this program; if not, write to the Free Software\n"
81 "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n"
83 "Alternatively, this software may be distributed under the terms of the\n"
86 "Redistribution and use in source and binary forms, with or without\n"
87 "modification, are permitted provided that the following conditions are\n"
90 const char *wpa_supplicant_full_license3
=
91 "1. Redistributions of source code must retain the above copyright\n"
92 " notice, this list of conditions and the following disclaimer.\n"
94 "2. Redistributions in binary form must reproduce the above copyright\n"
95 " notice, this list of conditions and the following disclaimer in the\n"
96 " documentation and/or other materials provided with the distribution.\n"
98 const char *wpa_supplicant_full_license4
=
99 "3. Neither the name(s) of the above-listed copyright holder(s) nor the\n"
100 " names of its contributors may be used to endorse or promote products\n"
101 " derived from this software without specific prior written permission.\n"
103 "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n"
104 "\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n"
105 "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n"
106 "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n";
107 const char *wpa_supplicant_full_license5
=
108 "OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n"
109 "SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n"
110 "LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n"
111 "DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n"
112 "THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n"
113 "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n"
114 "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
116 #endif /* CONFIG_NO_STDOUT_DEBUG */
118 extern int wpa_debug_level
;
119 extern int wpa_debug_show_keys
;
120 extern int wpa_debug_timestamp
;
121 extern struct wpa_driver_ops
*wpa_drivers
[];
123 /* Configure default/group WEP keys for static WEP */
124 int wpa_set_wep_keys(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
)
128 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
129 if (ssid
->wep_key_len
[i
] == 0)
133 wpa_drv_set_key(wpa_s
, WPA_ALG_WEP
,
134 (u8
*) "\xff\xff\xff\xff\xff\xff",
135 i
, i
== ssid
->wep_tx_keyidx
, (u8
*) "", 0,
136 ssid
->wep_key
[i
], ssid
->wep_key_len
[i
]);
143 static int wpa_supplicant_set_wpa_none_key(struct wpa_supplicant
*wpa_s
,
144 struct wpa_ssid
*ssid
)
151 /* IBSS/WPA-None uses only one key (Group) for both receiving and
152 * sending unicast and multicast packets. */
154 if (ssid
->mode
!= WPAS_MODE_IBSS
) {
155 wpa_printf(MSG_INFO
, "WPA: Invalid mode %d (not IBSS/ad-hoc) "
156 "for WPA-None", ssid
->mode
);
160 if (!ssid
->psk_set
) {
161 wpa_printf(MSG_INFO
, "WPA: No PSK configured for WPA-None");
165 switch (wpa_s
->group_cipher
) {
166 case WPA_CIPHER_CCMP
:
167 os_memcpy(key
, ssid
->psk
, 16);
171 case WPA_CIPHER_TKIP
:
172 /* WPA-None uses the same Michael MIC key for both TX and RX */
173 os_memcpy(key
, ssid
->psk
, 16 + 8);
174 os_memcpy(key
+ 16 + 8, ssid
->psk
+ 16, 8);
179 wpa_printf(MSG_INFO
, "WPA: Invalid group cipher %d for "
180 "WPA-None", wpa_s
->group_cipher
);
184 /* TODO: should actually remember the previously used seq#, both for TX
185 * and RX from each STA.. */
187 return wpa_drv_set_key(wpa_s
, alg
, (u8
*) "\xff\xff\xff\xff\xff\xff",
188 0, 1, seq
, 6, key
, keylen
);
192 static void wpa_supplicant_timeout(void *eloop_ctx
, void *timeout_ctx
)
194 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
195 const u8
*bssid
= wpa_s
->bssid
;
196 if (is_zero_ether_addr(bssid
))
197 bssid
= wpa_s
->pending_bssid
;
198 wpa_msg(wpa_s
, MSG_INFO
, "Authentication with " MACSTR
" timed out.",
200 wpa_blacklist_add(wpa_s
, bssid
);
201 wpa_sm_notify_disassoc(wpa_s
->wpa
);
202 wpa_supplicant_disassociate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
203 wpa_s
->reassociate
= 1;
204 wpa_supplicant_req_scan(wpa_s
, 0, 0);
209 * wpa_supplicant_req_auth_timeout - Schedule a timeout for authentication
210 * @wpa_s: Pointer to wpa_supplicant data
211 * @sec: Number of seconds after which to time out authentication
212 * @usec: Number of microseconds after which to time out authentication
214 * This function is used to schedule a timeout for the current authentication
217 void wpa_supplicant_req_auth_timeout(struct wpa_supplicant
*wpa_s
,
220 if (wpa_s
->conf
&& wpa_s
->conf
->ap_scan
== 0 &&
221 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
))
224 wpa_msg(wpa_s
, MSG_DEBUG
, "Setting authentication timeout: %d sec "
225 "%d usec", sec
, usec
);
226 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
227 eloop_register_timeout(sec
, usec
, wpa_supplicant_timeout
, wpa_s
, NULL
);
232 * wpa_supplicant_cancel_auth_timeout - Cancel authentication timeout
233 * @wpa_s: Pointer to wpa_supplicant data
235 * This function is used to cancel authentication timeout scheduled with
236 * wpa_supplicant_req_auth_timeout() and it is called when authentication has
239 void wpa_supplicant_cancel_auth_timeout(struct wpa_supplicant
*wpa_s
)
241 wpa_msg(wpa_s
, MSG_DEBUG
, "Cancelling authentication timeout");
242 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
243 wpa_blacklist_del(wpa_s
, wpa_s
->bssid
);
248 * wpa_supplicant_initiate_eapol - Configure EAPOL state machine
249 * @wpa_s: Pointer to wpa_supplicant data
251 * This function is used to configure EAPOL state machine based on the selected
252 * authentication mode.
254 void wpa_supplicant_initiate_eapol(struct wpa_supplicant
*wpa_s
)
256 #ifdef IEEE8021X_EAPOL
257 struct eapol_config eapol_conf
;
258 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
260 #ifdef CONFIG_IBSS_RSN
261 if (ssid
->mode
== WPAS_MODE_IBSS
&&
262 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
263 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
) {
265 * RSN IBSS authentication is per-STA and we can disable the
266 * per-BSSID EAPOL authentication.
268 eapol_sm_notify_portControl(wpa_s
->eapol
, ForceAuthorized
);
269 eapol_sm_notify_eap_success(wpa_s
->eapol
, TRUE
);
270 eapol_sm_notify_eap_fail(wpa_s
->eapol
, FALSE
);
273 #endif /* CONFIG_IBSS_RSN */
275 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
276 eapol_sm_notify_eap_fail(wpa_s
->eapol
, FALSE
);
278 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
279 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
)
280 eapol_sm_notify_portControl(wpa_s
->eapol
, ForceAuthorized
);
282 eapol_sm_notify_portControl(wpa_s
->eapol
, Auto
);
284 os_memset(&eapol_conf
, 0, sizeof(eapol_conf
));
285 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
286 eapol_conf
.accept_802_1x_keys
= 1;
287 eapol_conf
.required_keys
= 0;
288 if (ssid
->eapol_flags
& EAPOL_FLAG_REQUIRE_KEY_UNICAST
) {
289 eapol_conf
.required_keys
|= EAPOL_REQUIRE_KEY_UNICAST
;
291 if (ssid
->eapol_flags
& EAPOL_FLAG_REQUIRE_KEY_BROADCAST
) {
292 eapol_conf
.required_keys
|=
293 EAPOL_REQUIRE_KEY_BROADCAST
;
296 if (wpa_s
->conf
&& (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
))
297 eapol_conf
.required_keys
= 0;
300 eapol_conf
.fast_reauth
= wpa_s
->conf
->fast_reauth
;
301 eapol_conf
.workaround
= ssid
->eap_workaround
;
302 eapol_conf
.eap_disabled
=
303 !wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) &&
304 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_IEEE8021X_NO_WPA
&&
305 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPS
;
306 eapol_sm_notify_config(wpa_s
->eapol
, &ssid
->eap
, &eapol_conf
);
307 #endif /* IEEE8021X_EAPOL */
312 * wpa_supplicant_set_non_wpa_policy - Set WPA parameters to non-WPA mode
313 * @wpa_s: Pointer to wpa_supplicant data
314 * @ssid: Configuration data for the network
316 * This function is used to configure WPA state machine and related parameters
317 * to a mode where WPA is not enabled. This is called as part of the
318 * authentication configuration when the selected network does not use WPA.
320 void wpa_supplicant_set_non_wpa_policy(struct wpa_supplicant
*wpa_s
,
321 struct wpa_ssid
*ssid
)
325 if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)
326 wpa_s
->key_mgmt
= WPA_KEY_MGMT_WPS
;
327 else if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
)
328 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X_NO_WPA
;
330 wpa_s
->key_mgmt
= WPA_KEY_MGMT_NONE
;
331 wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, NULL
, 0);
332 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, NULL
, 0);
333 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
334 wpa_s
->pairwise_cipher
= WPA_CIPHER_NONE
;
335 wpa_s
->group_cipher
= WPA_CIPHER_NONE
;
336 wpa_s
->mgmt_group_cipher
= 0;
338 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
339 if (ssid
->wep_key_len
[i
] > 5) {
340 wpa_s
->pairwise_cipher
= WPA_CIPHER_WEP104
;
341 wpa_s
->group_cipher
= WPA_CIPHER_WEP104
;
343 } else if (ssid
->wep_key_len
[i
] > 0) {
344 wpa_s
->pairwise_cipher
= WPA_CIPHER_WEP40
;
345 wpa_s
->group_cipher
= WPA_CIPHER_WEP40
;
350 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_RSN_ENABLED
, 0);
351 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_KEY_MGMT
, wpa_s
->key_mgmt
);
352 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PAIRWISE
,
353 wpa_s
->pairwise_cipher
);
354 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_GROUP
, wpa_s
->group_cipher
);
355 #ifdef CONFIG_IEEE80211W
356 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MGMT_GROUP
,
357 wpa_s
->mgmt_group_cipher
);
358 #endif /* CONFIG_IEEE80211W */
360 pmksa_cache_clear_current(wpa_s
->wpa
);
364 static void wpa_supplicant_cleanup(struct wpa_supplicant
*wpa_s
)
366 bgscan_deinit(wpa_s
);
367 scard_deinit(wpa_s
->scard
);
369 wpa_sm_set_scard_ctx(wpa_s
->wpa
, NULL
);
370 eapol_sm_register_scard_ctx(wpa_s
->eapol
, NULL
);
371 l2_packet_deinit(wpa_s
->l2
);
374 l2_packet_deinit(wpa_s
->l2_br
);
378 if (wpa_s
->ctrl_iface
) {
379 wpa_supplicant_ctrl_iface_deinit(wpa_s
->ctrl_iface
);
380 wpa_s
->ctrl_iface
= NULL
;
382 if (wpa_s
->conf
!= NULL
) {
383 struct wpa_ssid
*ssid
;
384 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
)
385 wpas_notify_network_removed(wpa_s
, ssid
);
386 wpa_config_free(wpa_s
->conf
);
390 os_free(wpa_s
->confname
);
391 wpa_s
->confname
= NULL
;
393 wpa_sm_set_eapol(wpa_s
->wpa
, NULL
);
394 eapol_sm_deinit(wpa_s
->eapol
);
397 rsn_preauth_deinit(wpa_s
->wpa
);
399 pmksa_candidate_free(wpa_s
->wpa
);
400 wpa_sm_deinit(wpa_s
->wpa
);
402 wpa_blacklist_clear(wpa_s
);
404 wpa_bss_deinit(wpa_s
);
406 wpa_supplicant_cancel_scan(wpa_s
);
407 wpa_supplicant_cancel_auth_timeout(wpa_s
);
409 ieee80211_sta_deinit(wpa_s
);
411 wpas_wps_deinit(wpa_s
);
413 wpabuf_free(wpa_s
->pending_eapol_rx
);
414 wpa_s
->pending_eapol_rx
= NULL
;
416 #ifdef CONFIG_IBSS_RSN
417 ibss_rsn_deinit(wpa_s
->ibss_rsn
);
418 wpa_s
->ibss_rsn
= NULL
;
419 #endif /* CONFIG_IBSS_RSN */
422 os_free(wpa_s
->sme
.ft_ies
);
423 wpa_s
->sme
.ft_ies
= NULL
;
424 wpa_s
->sme
.ft_ies_len
= 0;
425 #endif /* CONFIG_SME */
428 wpa_supplicant_ap_deinit(wpa_s
);
429 #endif /* CONFIG_AP */
434 * wpa_clear_keys - Clear keys configured for the driver
435 * @wpa_s: Pointer to wpa_supplicant data
436 * @addr: Previously used BSSID or %NULL if not available
438 * This function clears the encryption keys that has been previously configured
441 void wpa_clear_keys(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
443 u8
*bcast
= (u8
*) "\xff\xff\xff\xff\xff\xff";
445 if (wpa_s
->keys_cleared
) {
446 /* Some drivers (e.g., ndiswrapper & NDIS drivers) seem to have
447 * timing issues with keys being cleared just before new keys
448 * are set or just after association or something similar. This
449 * shows up in group key handshake failing often because of the
450 * client not receiving the first encrypted packets correctly.
451 * Skipping some of the extra key clearing steps seems to help
452 * in completing group key handshake more reliably. */
453 wpa_printf(MSG_DEBUG
, "No keys have been configured - "
454 "skip key clearing");
458 /* MLME-DELETEKEYS.request */
459 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, bcast
, 0, 0, NULL
, 0, NULL
, 0);
460 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, bcast
, 1, 0, NULL
, 0, NULL
, 0);
461 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, bcast
, 2, 0, NULL
, 0, NULL
, 0);
462 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, bcast
, 3, 0, NULL
, 0, NULL
, 0);
463 #ifdef CONFIG_IEEE80211W
464 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, bcast
, 4, 0, NULL
, 0, NULL
, 0);
465 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, bcast
, 5, 0, NULL
, 0, NULL
, 0);
466 #endif /* CONFIG_IEEE80211W */
468 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, addr
, 0, 0, NULL
, 0, NULL
,
470 /* MLME-SETPROTECTION.request(None) */
471 wpa_drv_mlme_setprotection(
473 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
474 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
476 wpa_s
->keys_cleared
= 1;
481 * wpa_supplicant_state_txt - Get the connection state name as a text string
482 * @state: State (wpa_state; WPA_*)
483 * Returns: The state name as a printable text string
485 const char * wpa_supplicant_state_txt(enum wpa_states state
)
488 case WPA_DISCONNECTED
:
489 return "DISCONNECTED";
494 case WPA_AUTHENTICATING
:
495 return "AUTHENTICATING";
496 case WPA_ASSOCIATING
:
497 return "ASSOCIATING";
500 case WPA_4WAY_HANDSHAKE
:
501 return "4WAY_HANDSHAKE";
502 case WPA_GROUP_HANDSHAKE
:
503 return "GROUP_HANDSHAKE";
513 * wpa_supplicant_set_state - Set current connection state
514 * @wpa_s: Pointer to wpa_supplicant data
515 * @state: The new connection state
517 * This function is called whenever the connection state changes, e.g.,
518 * association is completed for WPA/WPA2 4-Way Handshake is started.
520 void wpa_supplicant_set_state(struct wpa_supplicant
*wpa_s
,
521 enum wpa_states state
)
523 enum wpa_states old_state
= wpa_s
->wpa_state
;
525 wpa_printf(MSG_DEBUG
, "State: %s -> %s",
526 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
527 wpa_supplicant_state_txt(state
));
529 if (state
!= WPA_SCANNING
)
530 wpa_supplicant_notify_scanning(wpa_s
, 0);
532 if (state
== WPA_COMPLETED
&& wpa_s
->new_connection
) {
533 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
534 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
535 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
"- Connection to "
536 MACSTR
" completed %s [id=%d id_str=%s]",
537 MAC2STR(wpa_s
->bssid
), wpa_s
->reassociated_connection
?
538 "(reauth)" : "(auth)",
539 ssid
? ssid
->id
: -1,
540 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
541 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
542 wpa_s
->new_connection
= 0;
543 wpa_s
->reassociated_connection
= 1;
544 wpa_drv_set_operstate(wpa_s
, 1);
545 wpa_s
->after_wps
= 0;
546 } else if (state
== WPA_DISCONNECTED
|| state
== WPA_ASSOCIATING
||
547 state
== WPA_ASSOCIATED
) {
548 wpa_s
->new_connection
= 1;
549 wpa_drv_set_operstate(wpa_s
, 0);
551 wpa_s
->wpa_state
= state
;
553 if (wpa_s
->wpa_state
!= old_state
)
554 wpas_notify_state_changed(wpa_s
, wpa_s
->wpa_state
, old_state
);
558 void wpa_supplicant_terminate_proc(struct wpa_global
*global
)
562 struct wpa_supplicant
*wpa_s
= global
->ifaces
;
564 if (wpas_wps_terminate_pending(wpa_s
) == 1)
568 #endif /* CONFIG_WPS */
575 static void wpa_supplicant_terminate(int sig
, void *signal_ctx
)
577 struct wpa_global
*global
= signal_ctx
;
578 struct wpa_supplicant
*wpa_s
;
579 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
580 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_TERMINATING
"- signal %d "
583 wpa_supplicant_terminate_proc(global
);
587 static void wpa_supplicant_clear_status(struct wpa_supplicant
*wpa_s
)
589 enum wpa_states old_state
= wpa_s
->wpa_state
;
591 wpa_s
->pairwise_cipher
= 0;
592 wpa_s
->group_cipher
= 0;
593 wpa_s
->mgmt_group_cipher
= 0;
595 wpa_s
->wpa_state
= WPA_DISCONNECTED
;
597 if (wpa_s
->wpa_state
!= old_state
)
598 wpas_notify_state_changed(wpa_s
, wpa_s
->wpa_state
, old_state
);
603 * wpa_supplicant_reload_configuration - Reload configuration data
604 * @wpa_s: Pointer to wpa_supplicant data
605 * Returns: 0 on success or -1 if configuration parsing failed
607 * This function can be used to request that the configuration data is reloaded
608 * (e.g., after configuration file change). This function is reloading
609 * configuration only for one interface, so this may need to be called multiple
610 * times if %wpa_supplicant is controlling multiple interfaces and all
611 * interfaces need reconfiguration.
613 int wpa_supplicant_reload_configuration(struct wpa_supplicant
*wpa_s
)
615 struct wpa_config
*conf
;
616 struct wpa_ssid
*old_ssid
;
620 if (wpa_s
->confname
== NULL
)
622 conf
= wpa_config_read(wpa_s
->confname
);
624 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to parse the configuration "
625 "file '%s' - exiting", wpa_s
->confname
);
629 reconf_ctrl
= !!conf
->ctrl_interface
!= !!wpa_s
->conf
->ctrl_interface
630 || (conf
->ctrl_interface
&& wpa_s
->conf
->ctrl_interface
&&
631 os_strcmp(conf
->ctrl_interface
,
632 wpa_s
->conf
->ctrl_interface
) != 0);
634 if (reconf_ctrl
&& wpa_s
->ctrl_iface
) {
635 wpa_supplicant_ctrl_iface_deinit(wpa_s
->ctrl_iface
);
636 wpa_s
->ctrl_iface
= NULL
;
639 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
640 old_ssid
= wpa_s
->current_ssid
;
641 wpa_s
->current_ssid
= NULL
;
642 if (old_ssid
!= wpa_s
->current_ssid
)
643 wpas_notify_network_changed(wpa_s
);
646 * TODO: should notify EAPOL SM about changes in opensc_engine_path,
647 * pkcs11_engine_path, pkcs11_module_path.
649 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
651 * Clear forced success to clear EAP state for next
654 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
656 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
657 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
658 wpa_sm_set_fast_reauth(wpa_s
->wpa
, wpa_s
->conf
->fast_reauth
);
659 rsn_preauth_deinit(wpa_s
->wpa
);
661 old_ap_scan
= wpa_s
->conf
->ap_scan
;
662 wpa_config_free(wpa_s
->conf
);
664 if (old_ap_scan
!= wpa_s
->conf
->ap_scan
)
665 wpas_notify_ap_scan_changed(wpa_s
);
668 wpa_s
->ctrl_iface
= wpa_supplicant_ctrl_iface_init(wpa_s
);
670 wpa_supplicant_clear_status(wpa_s
);
671 wpa_s
->reassociate
= 1;
672 wpa_supplicant_req_scan(wpa_s
, 0, 0);
673 wpa_msg(wpa_s
, MSG_DEBUG
, "Reconfiguration completed");
678 static void wpa_supplicant_reconfig(int sig
, void *signal_ctx
)
680 struct wpa_global
*global
= signal_ctx
;
681 struct wpa_supplicant
*wpa_s
;
682 wpa_printf(MSG_DEBUG
, "Signal %d received - reconfiguring", sig
);
683 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
684 if (wpa_supplicant_reload_configuration(wpa_s
) < 0) {
685 wpa_supplicant_terminate_proc(global
);
691 enum wpa_cipher
cipher_suite2driver(int cipher
)
694 case WPA_CIPHER_NONE
:
696 case WPA_CIPHER_WEP40
:
698 case WPA_CIPHER_WEP104
:
699 return CIPHER_WEP104
;
700 case WPA_CIPHER_CCMP
:
702 case WPA_CIPHER_TKIP
:
709 enum wpa_key_mgmt
key_mgmt2driver(int key_mgmt
)
712 case WPA_KEY_MGMT_NONE
:
713 return KEY_MGMT_NONE
;
714 case WPA_KEY_MGMT_IEEE8021X_NO_WPA
:
715 return KEY_MGMT_802_1X_NO_WPA
;
716 case WPA_KEY_MGMT_IEEE8021X
:
717 return KEY_MGMT_802_1X
;
718 case WPA_KEY_MGMT_WPA_NONE
:
719 return KEY_MGMT_WPA_NONE
;
720 case WPA_KEY_MGMT_FT_IEEE8021X
:
721 return KEY_MGMT_FT_802_1X
;
722 case WPA_KEY_MGMT_FT_PSK
:
723 return KEY_MGMT_FT_PSK
;
724 case WPA_KEY_MGMT_IEEE8021X_SHA256
:
725 return KEY_MGMT_802_1X_SHA256
;
726 case WPA_KEY_MGMT_PSK_SHA256
:
727 return KEY_MGMT_PSK_SHA256
;
728 case WPA_KEY_MGMT_WPS
:
730 case WPA_KEY_MGMT_PSK
:
737 static int wpa_supplicant_suites_from_ai(struct wpa_supplicant
*wpa_s
,
738 struct wpa_ssid
*ssid
,
739 struct wpa_ie_data
*ie
)
741 int ret
= wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, ie
);
744 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Failed to parse WPA IE "
745 "from association info");
750 wpa_printf(MSG_DEBUG
, "WPA: Using WPA IE from AssocReq to set cipher "
752 if (!(ie
->group_cipher
& ssid
->group_cipher
)) {
753 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled group "
754 "cipher 0x%x (mask 0x%x) - reject",
755 ie
->group_cipher
, ssid
->group_cipher
);
758 if (!(ie
->pairwise_cipher
& ssid
->pairwise_cipher
)) {
759 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled pairwise "
760 "cipher 0x%x (mask 0x%x) - reject",
761 ie
->pairwise_cipher
, ssid
->pairwise_cipher
);
764 if (!(ie
->key_mgmt
& ssid
->key_mgmt
)) {
765 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled key "
766 "management 0x%x (mask 0x%x) - reject",
767 ie
->key_mgmt
, ssid
->key_mgmt
);
771 #ifdef CONFIG_IEEE80211W
772 if (!(ie
->capabilities
& WPA_CAPABILITY_MFPC
) &&
773 ssid
->ieee80211w
== MGMT_FRAME_PROTECTION_REQUIRED
) {
774 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver associated with an AP "
775 "that does not support management frame protection - "
779 #endif /* CONFIG_IEEE80211W */
786 * wpa_supplicant_set_suites - Set authentication and encryption parameters
787 * @wpa_s: Pointer to wpa_supplicant data
788 * @bss: Scan results for the selected BSS, or %NULL if not available
789 * @ssid: Configuration data for the selected network
790 * @wpa_ie: Buffer for the WPA/RSN IE
791 * @wpa_ie_len: Maximum wpa_ie buffer size on input. This is changed to be the
792 * used buffer length in case the functions returns success.
793 * Returns: 0 on success or -1 on failure
795 * This function is used to configure authentication and encryption parameters
796 * based on the network configuration and scan result for the selected BSS (if
799 int wpa_supplicant_set_suites(struct wpa_supplicant
*wpa_s
,
800 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
,
801 u8
*wpa_ie
, size_t *wpa_ie_len
)
803 struct wpa_ie_data ie
;
805 const u8
*bss_wpa
, *bss_rsn
;
806 struct wpa_driver_capa capa
;
809 bss_wpa
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
810 bss_rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
812 bss_wpa
= bss_rsn
= NULL
;
814 if (wpa_drv_get_capa(wpa_s
, &capa
) == 0) {
815 if (!(capa
.key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
818 if (!(capa
.key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
823 if (bss_rsn
&& (ssid
->proto
& WPA_PROTO_RSN
) &&
824 wpa_parse_wpa_ie(bss_rsn
, 2 + bss_rsn
[1], &ie
) == 0 &&
825 (ie
.group_cipher
& ssid
->group_cipher
) &&
826 (ie
.pairwise_cipher
& ssid
->pairwise_cipher
) &&
827 (ie
.key_mgmt
& ssid
->key_mgmt
)) {
828 wpa_msg(wpa_s
, MSG_DEBUG
, "RSN: using IEEE 802.11i/D9.0");
829 proto
= WPA_PROTO_RSN
;
830 } else if (bss_wpa
&& (ssid
->proto
& WPA_PROTO_WPA
) &&
831 wpa_parse_wpa_ie(bss_wpa
, 2 +bss_wpa
[1], &ie
) == 0 &&
832 (ie
.group_cipher
& ssid
->group_cipher
) &&
833 (ie
.pairwise_cipher
& ssid
->pairwise_cipher
) &&
834 (ie
.key_mgmt
& ssid
->key_mgmt
)) {
835 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using IEEE 802.11i/D3.0");
836 proto
= WPA_PROTO_WPA
;
838 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select WPA/RSN");
841 if (ssid
->proto
& WPA_PROTO_RSN
)
842 proto
= WPA_PROTO_RSN
;
844 proto
= WPA_PROTO_WPA
;
845 if (wpa_supplicant_suites_from_ai(wpa_s
, ssid
, &ie
) < 0) {
846 os_memset(&ie
, 0, sizeof(ie
));
847 ie
.group_cipher
= ssid
->group_cipher
;
848 ie
.pairwise_cipher
= ssid
->pairwise_cipher
;
849 ie
.key_mgmt
= ssid
->key_mgmt
;
850 #ifdef CONFIG_IEEE80211W
851 ie
.mgmt_group_cipher
=
852 ssid
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
?
853 WPA_CIPHER_AES_128_CMAC
: 0;
854 #endif /* CONFIG_IEEE80211W */
855 wpa_printf(MSG_DEBUG
, "WPA: Set cipher suites based "
861 wpa_printf(MSG_DEBUG
, "WPA: Selected cipher suites: group %d "
862 "pairwise %d key_mgmt %d proto %d",
863 ie
.group_cipher
, ie
.pairwise_cipher
, ie
.key_mgmt
, proto
);
864 #ifdef CONFIG_IEEE80211W
865 if (ssid
->ieee80211w
) {
866 wpa_printf(MSG_DEBUG
, "WPA: Selected mgmt group cipher %d",
867 ie
.mgmt_group_cipher
);
869 #endif /* CONFIG_IEEE80211W */
871 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PROTO
, proto
);
872 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_RSN_ENABLED
,
873 !!(ssid
->proto
& WPA_PROTO_RSN
));
875 if (bss
|| !wpa_s
->ap_ies_from_associnfo
) {
876 if (wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, bss_wpa
,
877 bss_wpa
? 2 + bss_wpa
[1] : 0) ||
878 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, bss_rsn
,
879 bss_rsn
? 2 + bss_rsn
[1] : 0))
883 sel
= ie
.group_cipher
& ssid
->group_cipher
;
884 if (sel
& WPA_CIPHER_CCMP
) {
885 wpa_s
->group_cipher
= WPA_CIPHER_CCMP
;
886 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using GTK CCMP");
887 } else if (sel
& WPA_CIPHER_TKIP
) {
888 wpa_s
->group_cipher
= WPA_CIPHER_TKIP
;
889 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using GTK TKIP");
890 } else if (sel
& WPA_CIPHER_WEP104
) {
891 wpa_s
->group_cipher
= WPA_CIPHER_WEP104
;
892 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using GTK WEP104");
893 } else if (sel
& WPA_CIPHER_WEP40
) {
894 wpa_s
->group_cipher
= WPA_CIPHER_WEP40
;
895 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using GTK WEP40");
897 wpa_printf(MSG_WARNING
, "WPA: Failed to select group cipher.");
901 sel
= ie
.pairwise_cipher
& ssid
->pairwise_cipher
;
902 if (wpa_drv_get_capa(wpa_s
, &capa
) == 0) {
903 if (!(capa
.enc
& WPA_DRIVER_CAPA_ENC_TKIP
)) {
904 sel
&= ~WPA_CIPHER_TKIP
;
906 if (!(capa
.enc
& WPA_DRIVER_CAPA_ENC_CCMP
)) {
907 sel
&= ~WPA_CIPHER_CCMP
;
910 if (sel
& WPA_CIPHER_CCMP
) {
911 wpa_s
->pairwise_cipher
= WPA_CIPHER_CCMP
;
912 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using PTK CCMP");
913 } else if (sel
& WPA_CIPHER_TKIP
) {
914 wpa_s
->pairwise_cipher
= WPA_CIPHER_TKIP
;
915 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using PTK TKIP");
916 } else if (sel
& WPA_CIPHER_NONE
) {
917 wpa_s
->pairwise_cipher
= WPA_CIPHER_NONE
;
918 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using PTK NONE");
920 wpa_printf(MSG_WARNING
, "WPA: Failed to select pairwise "
925 sel
= ie
.key_mgmt
& ssid
->key_mgmt
;
927 #ifdef CONFIG_IEEE80211R
928 } else if (sel
& WPA_KEY_MGMT_FT_IEEE8021X
) {
929 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_IEEE8021X
;
930 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FT/802.1X");
931 } else if (sel
& WPA_KEY_MGMT_FT_PSK
) {
932 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_PSK
;
933 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FT/PSK");
934 #endif /* CONFIG_IEEE80211R */
935 #ifdef CONFIG_IEEE80211W
936 } else if (sel
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
937 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X_SHA256
;
938 wpa_msg(wpa_s
, MSG_DEBUG
,
939 "WPA: using KEY_MGMT 802.1X with SHA256");
940 } else if (sel
& WPA_KEY_MGMT_PSK_SHA256
) {
941 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK_SHA256
;
942 wpa_msg(wpa_s
, MSG_DEBUG
,
943 "WPA: using KEY_MGMT PSK with SHA256");
944 #endif /* CONFIG_IEEE80211W */
945 } else if (sel
& WPA_KEY_MGMT_IEEE8021X
) {
946 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X
;
947 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT 802.1X");
948 } else if (sel
& WPA_KEY_MGMT_PSK
) {
949 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK
;
950 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT WPA-PSK");
951 } else if (sel
& WPA_KEY_MGMT_WPA_NONE
) {
952 wpa_s
->key_mgmt
= WPA_KEY_MGMT_WPA_NONE
;
953 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT WPA-NONE");
955 wpa_printf(MSG_WARNING
, "WPA: Failed to select authenticated "
956 "key management type.");
960 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_KEY_MGMT
, wpa_s
->key_mgmt
);
961 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PAIRWISE
,
962 wpa_s
->pairwise_cipher
);
963 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_GROUP
, wpa_s
->group_cipher
);
965 #ifdef CONFIG_IEEE80211W
966 sel
= ie
.mgmt_group_cipher
;
967 if (ssid
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
||
968 !(ie
.capabilities
& WPA_CAPABILITY_MFPC
))
970 if (sel
& WPA_CIPHER_AES_128_CMAC
) {
971 wpa_s
->mgmt_group_cipher
= WPA_CIPHER_AES_128_CMAC
;
972 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using MGMT group cipher "
975 wpa_s
->mgmt_group_cipher
= 0;
976 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: not using MGMT group cipher");
978 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MGMT_GROUP
,
979 wpa_s
->mgmt_group_cipher
);
980 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MFP
, ssid
->ieee80211w
);
981 #endif /* CONFIG_IEEE80211W */
983 if (wpa_sm_set_assoc_wpa_ie_default(wpa_s
->wpa
, wpa_ie
, wpa_ie_len
)) {
984 wpa_printf(MSG_WARNING
, "WPA: Failed to generate WPA IE.");
989 (WPA_KEY_MGMT_PSK
| WPA_KEY_MGMT_FT_PSK
| WPA_KEY_MGMT_PSK_SHA256
))
990 wpa_sm_set_pmk(wpa_s
->wpa
, ssid
->psk
, PMK_LEN
);
992 wpa_sm_set_pmk_from_pmksa(wpa_s
->wpa
);
999 * wpa_supplicant_associate - Request association
1000 * @wpa_s: Pointer to wpa_supplicant data
1001 * @bss: Scan results for the selected BSS, or %NULL if not available
1002 * @ssid: Configuration data for the selected network
1004 * This function is used to request %wpa_supplicant to associate with a BSS.
1006 void wpa_supplicant_associate(struct wpa_supplicant
*wpa_s
,
1007 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
)
1011 int use_crypt
, ret
, i
, bssid_changed
;
1012 int algs
= WPA_AUTH_ALG_OPEN
;
1013 enum wpa_cipher cipher_pairwise
, cipher_group
;
1014 struct wpa_driver_associate_params params
;
1015 int wep_keys_set
= 0;
1016 struct wpa_driver_capa capa
;
1017 int assoc_failed
= 0;
1018 struct wpa_ssid
*old_ssid
;
1020 if (ssid
->mode
== WPAS_MODE_AP
) {
1022 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_AP
)) {
1023 wpa_printf(MSG_INFO
, "Driver does not support AP "
1027 wpa_supplicant_create_ap(wpa_s
, ssid
);
1028 wpa_s
->current_bss
= bss
;
1029 #else /* CONFIG_AP */
1030 wpa_printf(MSG_ERROR
, "AP mode support not included in the "
1032 #endif /* CONFIG_AP */
1036 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
1037 ssid
->mode
== IEEE80211_MODE_INFRA
) {
1038 sme_authenticate(wpa_s
, bss
, ssid
);
1042 wpa_s
->reassociate
= 0;
1044 #ifdef CONFIG_IEEE80211R
1045 const u8
*ie
, *md
= NULL
;
1046 #endif /* CONFIG_IEEE80211R */
1047 wpa_msg(wpa_s
, MSG_INFO
, "Trying to associate with " MACSTR
1048 " (SSID='%s' freq=%d MHz)", MAC2STR(bss
->bssid
),
1049 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
), bss
->freq
);
1050 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
1051 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
1052 os_memcpy(wpa_s
->pending_bssid
, bss
->bssid
, ETH_ALEN
);
1054 wpas_notify_bssid_changed(wpa_s
);
1055 #ifdef CONFIG_IEEE80211R
1056 ie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
1057 if (ie
&& ie
[1] >= MOBILITY_DOMAIN_ID_LEN
)
1059 wpa_sm_set_ft_params(wpa_s
->wpa
, ie
, ie
? 2 + ie
[1] : 0);
1061 /* Prepare for the next transition */
1062 wpa_ft_prepare_auth_request(wpa_s
->wpa
, ie
);
1064 #endif /* CONFIG_IEEE80211R */
1066 } else if ((ssid
->ssid
== NULL
|| ssid
->ssid_len
== 0) &&
1067 wpa_s
->conf
->ap_scan
== 2 &&
1068 (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
1069 /* Use ap_scan==1 style network selection to find the network
1071 wpa_s
->scan_req
= 2;
1072 wpa_s
->reassociate
= 1;
1073 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1075 #endif /* CONFIG_WPS */
1077 wpa_msg(wpa_s
, MSG_INFO
, "Trying to associate with SSID '%s'",
1078 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
1079 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1081 wpa_supplicant_cancel_scan(wpa_s
);
1083 /* Starting new association, so clear the possibly used WPA IE from the
1084 * previous association. */
1085 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1087 #ifdef IEEE8021X_EAPOL
1088 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1090 if (ssid
->non_leap
== 0)
1091 algs
= WPA_AUTH_ALG_LEAP
;
1093 algs
|= WPA_AUTH_ALG_LEAP
;
1096 #endif /* IEEE8021X_EAPOL */
1097 wpa_printf(MSG_DEBUG
, "Automatic auth_alg selection: 0x%x", algs
);
1098 if (ssid
->auth_alg
) {
1099 algs
= ssid
->auth_alg
;
1100 wpa_printf(MSG_DEBUG
, "Overriding auth_alg selection: 0x%x",
1104 if (bss
&& (wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
) ||
1105 wpa_bss_get_ie(bss
, WLAN_EID_RSN
)) &&
1106 (ssid
->key_mgmt
& (WPA_KEY_MGMT_IEEE8021X
| WPA_KEY_MGMT_PSK
|
1107 WPA_KEY_MGMT_FT_IEEE8021X
|
1108 WPA_KEY_MGMT_FT_PSK
|
1109 WPA_KEY_MGMT_IEEE8021X_SHA256
|
1110 WPA_KEY_MGMT_PSK_SHA256
))) {
1111 int try_opportunistic
;
1112 try_opportunistic
= ssid
->proactive_key_caching
&&
1113 (ssid
->proto
& WPA_PROTO_RSN
);
1114 if (pmksa_cache_set_current(wpa_s
->wpa
, NULL
, bss
->bssid
,
1115 wpa_s
->current_ssid
,
1116 try_opportunistic
) == 0)
1117 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
, 1);
1118 wpa_ie_len
= sizeof(wpa_ie
);
1119 if (wpa_supplicant_set_suites(wpa_s
, bss
, ssid
,
1120 wpa_ie
, &wpa_ie_len
)) {
1121 wpa_printf(MSG_WARNING
, "WPA: Failed to set WPA key "
1122 "management and encryption suites");
1125 } else if (ssid
->key_mgmt
&
1126 (WPA_KEY_MGMT_PSK
| WPA_KEY_MGMT_IEEE8021X
|
1127 WPA_KEY_MGMT_WPA_NONE
| WPA_KEY_MGMT_FT_PSK
|
1128 WPA_KEY_MGMT_FT_IEEE8021X
| WPA_KEY_MGMT_PSK_SHA256
|
1129 WPA_KEY_MGMT_IEEE8021X_SHA256
)) {
1130 wpa_ie_len
= sizeof(wpa_ie
);
1131 if (wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
1132 wpa_ie
, &wpa_ie_len
)) {
1133 wpa_printf(MSG_WARNING
, "WPA: Failed to set WPA key "
1134 "management and encryption suites (no scan "
1139 } else if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
1140 struct wpabuf
*wps_ie
;
1141 wps_ie
= wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid
));
1142 if (wps_ie
&& wpabuf_len(wps_ie
) <= sizeof(wpa_ie
)) {
1143 wpa_ie_len
= wpabuf_len(wps_ie
);
1144 os_memcpy(wpa_ie
, wpabuf_head(wps_ie
), wpa_ie_len
);
1147 wpabuf_free(wps_ie
);
1148 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
1149 #endif /* CONFIG_WPS */
1151 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
1155 wpa_clear_keys(wpa_s
, bss
? bss
->bssid
: NULL
);
1157 cipher_pairwise
= cipher_suite2driver(wpa_s
->pairwise_cipher
);
1158 cipher_group
= cipher_suite2driver(wpa_s
->group_cipher
);
1159 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1160 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1161 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
)
1163 if (wpa_set_wep_keys(wpa_s
, ssid
)) {
1168 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
)
1171 #ifdef IEEE8021X_EAPOL
1172 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1173 if ((ssid
->eapol_flags
&
1174 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
1175 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
)) == 0 &&
1179 /* Assume that dynamic WEP-104 keys will be used and
1180 * set cipher suites in order for drivers to expect
1182 cipher_pairwise
= cipher_group
= CIPHER_WEP104
;
1185 #endif /* IEEE8021X_EAPOL */
1187 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1188 /* Set the key before (and later after) association */
1189 wpa_supplicant_set_wpa_none_key(wpa_s
, ssid
);
1192 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATING
);
1193 os_memset(¶ms
, 0, sizeof(params
));
1195 params
.bssid
= bss
->bssid
;
1196 params
.ssid
= bss
->ssid
;
1197 params
.ssid_len
= bss
->ssid_len
;
1198 params
.freq
= bss
->freq
;
1200 params
.ssid
= ssid
->ssid
;
1201 params
.ssid_len
= ssid
->ssid_len
;
1203 if (ssid
->mode
== WPAS_MODE_IBSS
&& ssid
->frequency
> 0 &&
1205 params
.freq
= ssid
->frequency
; /* Initial channel for IBSS */
1206 params
.wpa_ie
= wpa_ie
;
1207 params
.wpa_ie_len
= wpa_ie_len
;
1208 params
.pairwise_suite
= cipher_pairwise
;
1209 params
.group_suite
= cipher_group
;
1210 params
.key_mgmt_suite
= key_mgmt2driver(wpa_s
->key_mgmt
);
1211 params
.auth_alg
= algs
;
1212 params
.mode
= ssid
->mode
;
1213 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
1214 if (ssid
->wep_key_len
[i
])
1215 params
.wep_key
[i
] = ssid
->wep_key
[i
];
1216 params
.wep_key_len
[i
] = ssid
->wep_key_len
[i
];
1218 params
.wep_tx_keyidx
= ssid
->wep_tx_keyidx
;
1220 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1221 (params
.key_mgmt_suite
== KEY_MGMT_PSK
||
1222 params
.key_mgmt_suite
== KEY_MGMT_FT_PSK
)) {
1223 params
.passphrase
= ssid
->passphrase
;
1225 params
.psk
= ssid
->psk
;
1228 params
.drop_unencrypted
= use_crypt
;
1230 #ifdef CONFIG_IEEE80211W
1231 params
.mgmt_frame_protection
= ssid
->ieee80211w
;
1232 if (ssid
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
&& bss
) {
1233 const u8
*rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1234 struct wpa_ie_data ie
;
1235 if (rsn
&& wpa_parse_wpa_ie(rsn
, 2 + rsn
[1], &ie
) == 0 &&
1237 (WPA_CAPABILITY_MFPC
| WPA_CAPABILITY_MFPR
)) {
1238 wpa_printf(MSG_DEBUG
, "WPA: Selected AP supports MFP: "
1240 params
.mgmt_frame_protection
=
1241 MGMT_FRAME_PROTECTION_REQUIRED
;
1244 #endif /* CONFIG_IEEE80211W */
1246 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
1247 ret
= ieee80211_sta_associate(wpa_s
, ¶ms
);
1249 ret
= wpa_drv_associate(wpa_s
, ¶ms
);
1251 wpa_msg(wpa_s
, MSG_INFO
, "Association request to the driver "
1253 /* try to continue anyway; new association will be tried again
1258 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1259 /* Set the key after the association just in case association
1260 * cleared the previously configured key. */
1261 wpa_supplicant_set_wpa_none_key(wpa_s
, ssid
);
1262 /* No need to timeout authentication since there is no key
1264 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1265 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1266 #ifdef CONFIG_IBSS_RSN
1267 } else if (ssid
->mode
== WPAS_MODE_IBSS
&&
1268 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
1269 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
) {
1270 ibss_rsn_set_psk(wpa_s
->ibss_rsn
, ssid
->psk
);
1272 * RSN IBSS authentication is per-STA and we can disable the
1273 * per-BSSID authentication.
1275 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1276 #endif /* CONFIG_IBSS_RSN */
1278 /* Timeout for IEEE 802.11 authentication and association */
1282 /* give IBSS a bit more time */
1283 timeout
= ssid
->mode
== WPAS_MODE_IBSS
? 10 : 5;
1284 } else if (wpa_s
->conf
->ap_scan
== 1) {
1285 /* give IBSS a bit more time */
1286 timeout
= ssid
->mode
== WPAS_MODE_IBSS
? 20 : 10;
1288 wpa_supplicant_req_auth_timeout(wpa_s
, timeout
, 0);
1291 if (wep_keys_set
&& wpa_drv_get_capa(wpa_s
, &capa
) == 0 &&
1292 capa
.flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC
) {
1293 /* Set static WEP keys again */
1294 wpa_set_wep_keys(wpa_s
, ssid
);
1297 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
) {
1299 * Do not allow EAP session resumption between different
1300 * network configurations.
1302 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
1304 old_ssid
= wpa_s
->current_ssid
;
1305 wpa_s
->current_ssid
= ssid
;
1306 wpa_s
->current_bss
= bss
;
1307 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
1308 wpa_supplicant_initiate_eapol(wpa_s
);
1309 if (old_ssid
!= wpa_s
->current_ssid
)
1310 wpas_notify_network_changed(wpa_s
);
1315 * wpa_supplicant_disassociate - Disassociate the current connection
1316 * @wpa_s: Pointer to wpa_supplicant data
1317 * @reason_code: IEEE 802.11 reason code for the disassociate frame
1319 * This function is used to request %wpa_supplicant to disassociate with the
1322 void wpa_supplicant_disassociate(struct wpa_supplicant
*wpa_s
,
1325 struct wpa_ssid
*old_ssid
;
1328 if (!is_zero_ether_addr(wpa_s
->bssid
)) {
1329 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
1330 ieee80211_sta_disassociate(wpa_s
, reason_code
);
1332 wpa_drv_disassociate(wpa_s
, wpa_s
->bssid
, reason_code
);
1333 addr
= wpa_s
->bssid
;
1335 wpa_clear_keys(wpa_s
, addr
);
1336 wpa_supplicant_mark_disassoc(wpa_s
);
1337 old_ssid
= wpa_s
->current_ssid
;
1338 wpa_s
->current_ssid
= NULL
;
1339 wpa_s
->current_bss
= NULL
;
1340 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
1341 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
1342 if (old_ssid
!= wpa_s
->current_ssid
)
1343 wpas_notify_network_changed(wpa_s
);
1344 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
1349 * wpa_supplicant_deauthenticate - Deauthenticate the current connection
1350 * @wpa_s: Pointer to wpa_supplicant data
1351 * @reason_code: IEEE 802.11 reason code for the deauthenticate frame
1353 * This function is used to request %wpa_supplicant to deauthenticate from the
1356 void wpa_supplicant_deauthenticate(struct wpa_supplicant
*wpa_s
,
1359 struct wpa_ssid
*old_ssid
;
1362 if (!is_zero_ether_addr(wpa_s
->bssid
)) {
1363 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
1364 ieee80211_sta_deauthenticate(wpa_s
, reason_code
);
1366 wpa_drv_deauthenticate(wpa_s
, wpa_s
->bssid
,
1368 addr
= wpa_s
->bssid
;
1370 wpa_clear_keys(wpa_s
, addr
);
1371 wpa_supplicant_mark_disassoc(wpa_s
);
1372 old_ssid
= wpa_s
->current_ssid
;
1373 wpa_s
->current_ssid
= NULL
;
1374 wpa_s
->current_bss
= NULL
;
1375 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
1376 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
1377 if (old_ssid
!= wpa_s
->current_ssid
)
1378 wpas_notify_network_changed(wpa_s
);
1379 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
1384 * wpa_supplicant_enable_network - Mark a configured network as enabled
1385 * @wpa_s: wpa_supplicant structure for a network interface
1386 * @ssid: wpa_ssid structure for a configured network or %NULL
1388 * Enables the specified network or all networks if no network specified.
1390 void wpa_supplicant_enable_network(struct wpa_supplicant
*wpa_s
,
1391 struct wpa_ssid
*ssid
)
1393 struct wpa_ssid
*other_ssid
;
1397 other_ssid
= wpa_s
->conf
->ssid
;
1398 while (other_ssid
) {
1399 if (other_ssid
== wpa_s
->current_ssid
&&
1400 other_ssid
->disabled
)
1401 wpa_s
->reassociate
= 1;
1403 was_disabled
= other_ssid
->disabled
;
1405 other_ssid
->disabled
= 0;
1407 if (was_disabled
!= other_ssid
->disabled
)
1408 wpas_notify_network_enabled_changed(
1411 other_ssid
= other_ssid
->next
;
1413 if (wpa_s
->reassociate
)
1414 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1415 } else if (ssid
->disabled
) {
1416 if (wpa_s
->current_ssid
== NULL
) {
1418 * Try to reassociate since there is no current
1419 * configuration and a new network was made available.
1421 wpa_s
->reassociate
= 1;
1422 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1425 was_disabled
= ssid
->disabled
;
1429 if (was_disabled
!= ssid
->disabled
)
1430 wpas_notify_network_enabled_changed(wpa_s
, ssid
);
1436 * wpa_supplicant_disable_network - Mark a configured network as disabled
1437 * @wpa_s: wpa_supplicant structure for a network interface
1438 * @ssid: wpa_ssid structure for a configured network or %NULL
1440 * Disables the specified network or all networks if no network specified.
1442 void wpa_supplicant_disable_network(struct wpa_supplicant
*wpa_s
,
1443 struct wpa_ssid
*ssid
)
1445 struct wpa_ssid
*other_ssid
;
1449 other_ssid
= wpa_s
->conf
->ssid
;
1450 while (other_ssid
) {
1451 was_disabled
= other_ssid
->disabled
;
1453 other_ssid
->disabled
= 1;
1455 if (was_disabled
!= other_ssid
->disabled
)
1456 wpas_notify_network_enabled_changed(
1459 other_ssid
= other_ssid
->next
;
1461 if (wpa_s
->current_ssid
)
1462 wpa_supplicant_disassociate(
1463 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1465 if (ssid
== wpa_s
->current_ssid
)
1466 wpa_supplicant_disassociate(
1467 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1469 was_disabled
= ssid
->disabled
;
1473 if (was_disabled
!= ssid
->disabled
)
1474 wpas_notify_network_enabled_changed(wpa_s
, ssid
);
1480 * wpa_supplicant_select_network - Attempt association with a network
1481 * @wpa_s: wpa_supplicant structure for a network interface
1482 * @ssid: wpa_ssid structure for a configured network or %NULL for any network
1484 void wpa_supplicant_select_network(struct wpa_supplicant
*wpa_s
,
1485 struct wpa_ssid
*ssid
)
1488 struct wpa_ssid
*other_ssid
;
1490 if (ssid
&& ssid
!= wpa_s
->current_ssid
&& wpa_s
->current_ssid
)
1491 wpa_supplicant_disassociate(
1492 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1495 * Mark all other networks disabled or mark all networks enabled if no
1496 * network specified.
1498 other_ssid
= wpa_s
->conf
->ssid
;
1499 while (other_ssid
) {
1500 int was_disabled
= other_ssid
->disabled
;
1502 other_ssid
->disabled
= ssid
? (ssid
->id
!= other_ssid
->id
) : 0;
1504 if (was_disabled
!= other_ssid
->disabled
)
1505 wpas_notify_network_enabled_changed(wpa_s
, other_ssid
);
1507 other_ssid
= other_ssid
->next
;
1509 wpa_s
->disconnected
= 0;
1510 wpa_s
->reassociate
= 1;
1511 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1514 wpas_notify_network_selected(wpa_s
, ssid
);
1519 * wpa_supplicant_set_ap_scan - Set AP scan mode for interface
1520 * @wpa_s: wpa_supplicant structure for a network interface
1521 * @ap_scan: AP scan mode
1522 * Returns: 0 if succeed or -1 if ap_scan has an invalid value
1525 int wpa_supplicant_set_ap_scan(struct wpa_supplicant
*wpa_s
, int ap_scan
)
1530 if (ap_scan
< 0 || ap_scan
> 2)
1533 old_ap_scan
= wpa_s
->conf
->ap_scan
;
1534 wpa_s
->conf
->ap_scan
= ap_scan
;
1536 if (old_ap_scan
!= wpa_s
->conf
->ap_scan
)
1537 wpas_notify_ap_scan_changed(wpa_s
);
1544 * wpa_supplicant_set_debug_params - Set global debug params
1545 * @global: wpa_global structure
1546 * @debug_level: debug level
1547 * @debug_timestamp: determines if show timestamp in debug data
1548 * @debug_show_keys: determines if show keys in debug data
1549 * Returns: 0 if succeed or -1 if debug_level has wrong value
1551 int wpa_supplicant_set_debug_params(struct wpa_global
*global
, int debug_level
,
1552 int debug_timestamp
, int debug_show_keys
)
1555 int old_level
, old_timestamp
, old_show_keys
;
1557 /* check for allowed debuglevels */
1558 if (debug_level
!= MSG_MSGDUMP
&&
1559 debug_level
!= MSG_DEBUG
&&
1560 debug_level
!= MSG_INFO
&&
1561 debug_level
!= MSG_WARNING
&&
1562 debug_level
!= MSG_ERROR
)
1565 old_level
= wpa_debug_level
;
1566 old_timestamp
= wpa_debug_timestamp
;
1567 old_show_keys
= wpa_debug_show_keys
;
1569 wpa_debug_level
= debug_level
;
1570 wpa_debug_timestamp
= debug_timestamp
? 1 : 0;
1571 wpa_debug_show_keys
= debug_show_keys
? 1 : 0;
1573 if (wpa_debug_level
!= old_level
)
1574 wpas_notify_debug_level_changed(global
);
1575 if (wpa_debug_timestamp
!= old_timestamp
)
1576 wpas_notify_debug_timestamp_changed(global
);
1577 if (wpa_debug_show_keys
!= old_show_keys
)
1578 wpas_notify_debug_show_keys_changed(global
);
1585 * wpa_supplicant_get_ssid - Get a pointer to the current network structure
1586 * @wpa_s: Pointer to wpa_supplicant data
1587 * Returns: A pointer to the current network structure or %NULL on failure
1589 struct wpa_ssid
* wpa_supplicant_get_ssid(struct wpa_supplicant
*wpa_s
)
1591 struct wpa_ssid
*entry
;
1592 u8 ssid
[MAX_SSID_LEN
];
1598 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
) {
1599 if (ieee80211_sta_get_ssid(wpa_s
, ssid
, &ssid_len
)) {
1600 wpa_printf(MSG_WARNING
, "Could not read SSID from "
1605 res
= wpa_drv_get_ssid(wpa_s
, ssid
);
1607 wpa_printf(MSG_WARNING
, "Could not read SSID from "
1614 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
1615 os_memcpy(bssid
, wpa_s
->bssid
, ETH_ALEN
);
1616 else if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0) {
1617 wpa_printf(MSG_WARNING
, "Could not read BSSID from driver.");
1621 wired
= wpa_s
->conf
->ap_scan
== 0 &&
1622 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
);
1624 entry
= wpa_s
->conf
->ssid
;
1626 if (!entry
->disabled
&&
1627 ((ssid_len
== entry
->ssid_len
&&
1628 os_memcmp(ssid
, entry
->ssid
, ssid_len
) == 0) || wired
) &&
1629 (!entry
->bssid_set
||
1630 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0))
1633 if (!entry
->disabled
&&
1634 (entry
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
1635 (entry
->ssid
== NULL
|| entry
->ssid_len
== 0) &&
1636 (!entry
->bssid_set
||
1637 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0))
1639 #endif /* CONFIG_WPS */
1640 entry
= entry
->next
;
1647 static int wpa_supplicant_set_driver(struct wpa_supplicant
*wpa_s
,
1657 if (wpa_drivers
[0] == NULL
) {
1658 wpa_printf(MSG_ERROR
, "No driver interfaces built into "
1664 /* default to first driver in the list */
1665 wpa_s
->driver
= wpa_drivers
[0];
1666 wpa_s
->global_drv_priv
= wpa_s
->global
->drv_priv
[0];
1670 pos
= os_strchr(name
, ',');
1674 len
= os_strlen(name
);
1675 for (i
= 0; wpa_drivers
[i
]; i
++) {
1676 if (os_strlen(wpa_drivers
[i
]->name
) == len
&&
1677 os_strncmp(name
, wpa_drivers
[i
]->name
, len
) ==
1679 wpa_s
->driver
= wpa_drivers
[i
];
1680 wpa_s
->global_drv_priv
= wpa_s
->global
->drv_priv
[i
];
1685 wpa_printf(MSG_ERROR
, "Unsupported driver '%s'.", name
);
1691 * wpa_supplicant_rx_eapol - Deliver a received EAPOL frame to wpa_supplicant
1692 * @ctx: Context pointer (wpa_s); this is the ctx variable registered
1693 * with struct wpa_driver_ops::init()
1694 * @src_addr: Source address of the EAPOL frame
1695 * @buf: EAPOL data starting from the EAPOL header (i.e., no Ethernet header)
1696 * @len: Length of the EAPOL data
1698 * This function is called for each received EAPOL frame. Most driver
1699 * interfaces rely on more generic OS mechanism for receiving frames through
1700 * l2_packet, but if such a mechanism is not available, the driver wrapper may
1701 * take care of received EAPOL frames and deliver them to the core supplicant
1702 * code by calling this function.
1704 void wpa_supplicant_rx_eapol(void *ctx
, const u8
*src_addr
,
1705 const u8
*buf
, size_t len
)
1707 struct wpa_supplicant
*wpa_s
= ctx
;
1709 wpa_printf(MSG_DEBUG
, "RX EAPOL from " MACSTR
, MAC2STR(src_addr
));
1710 wpa_hexdump(MSG_MSGDUMP
, "RX EAPOL", buf
, len
);
1712 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
) {
1714 * There is possible race condition between receiving the
1715 * association event and the EAPOL frame since they are coming
1716 * through different paths from the driver. In order to avoid
1717 * issues in trying to process the EAPOL frame before receiving
1718 * association information, lets queue it for processing until
1719 * the association event is received.
1721 wpa_printf(MSG_DEBUG
, "Not associated - Delay processing of "
1722 "received EAPOL frame");
1723 wpabuf_free(wpa_s
->pending_eapol_rx
);
1724 wpa_s
->pending_eapol_rx
= wpabuf_alloc_copy(buf
, len
);
1725 if (wpa_s
->pending_eapol_rx
) {
1726 os_get_time(&wpa_s
->pending_eapol_rx_time
);
1727 os_memcpy(wpa_s
->pending_eapol_rx_src
, src_addr
,
1734 if (wpa_s
->ap_iface
) {
1735 wpa_supplicant_ap_rx_eapol(wpa_s
, src_addr
, buf
, len
);
1738 #endif /* CONFIG_AP */
1740 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
) {
1741 wpa_printf(MSG_DEBUG
, "Ignored received EAPOL frame since "
1742 "no key management is configured");
1746 if (wpa_s
->eapol_received
== 0 &&
1747 (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) ||
1748 !wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
1749 wpa_s
->wpa_state
!= WPA_COMPLETED
) &&
1750 (wpa_s
->current_ssid
== NULL
||
1751 wpa_s
->current_ssid
->mode
!= IEEE80211_MODE_IBSS
)) {
1752 /* Timeout for completing IEEE 802.1X and WPA authentication */
1753 wpa_supplicant_req_auth_timeout(
1755 (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
1756 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
||
1757 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
) ?
1760 wpa_s
->eapol_received
++;
1762 if (wpa_s
->countermeasures
) {
1763 wpa_printf(MSG_INFO
, "WPA: Countermeasures - dropped EAPOL "
1768 #ifdef CONFIG_IBSS_RSN
1769 if (wpa_s
->current_ssid
&&
1770 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
) {
1771 ibss_rsn_rx_eapol(wpa_s
->ibss_rsn
, src_addr
, buf
, len
);
1774 #endif /* CONFIG_IBSS_RSN */
1776 /* Source address of the incoming EAPOL frame could be compared to the
1777 * current BSSID. However, it is possible that a centralized
1778 * Authenticator could be using another MAC address than the BSSID of
1779 * an AP, so just allow any address to be used for now. The replies are
1780 * still sent to the current BSSID (if available), though. */
1782 os_memcpy(wpa_s
->last_eapol_src
, src_addr
, ETH_ALEN
);
1783 if (!wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) &&
1784 eapol_sm_rx_eapol(wpa_s
->eapol
, src_addr
, buf
, len
) > 0)
1786 wpa_drv_poll(wpa_s
);
1787 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
))
1788 wpa_sm_rx_eapol(wpa_s
->wpa
, src_addr
, buf
, len
);
1789 else if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1791 * Set portValid = TRUE here since we are going to skip 4-way
1792 * handshake processing which would normally set portValid. We
1793 * need this to allow the EAPOL state machines to be completed
1794 * without going through EAPOL-Key handshake.
1796 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1802 * wpa_supplicant_driver_init - Initialize driver interface parameters
1803 * @wpa_s: Pointer to wpa_supplicant data
1804 * Returns: 0 on success, -1 on failure
1806 * This function is called to initialize driver interface parameters.
1807 * wpa_drv_init() must have been called before this function to initialize the
1810 int wpa_supplicant_driver_init(struct wpa_supplicant
*wpa_s
)
1812 static int interface_count
= 0;
1814 if (wpa_s
->driver
->send_eapol
) {
1815 const u8
*addr
= wpa_drv_get_mac_addr(wpa_s
);
1817 os_memcpy(wpa_s
->own_addr
, addr
, ETH_ALEN
);
1819 wpa_s
->l2
= l2_packet_init(wpa_s
->ifname
,
1820 wpa_drv_get_mac_addr(wpa_s
),
1822 wpa_supplicant_rx_eapol
, wpa_s
, 0);
1823 if (wpa_s
->l2
== NULL
)
1827 if (wpa_s
->l2
&& l2_packet_get_own_addr(wpa_s
->l2
, wpa_s
->own_addr
)) {
1828 wpa_printf(MSG_ERROR
, "Failed to get own L2 address");
1832 wpa_printf(MSG_DEBUG
, "Own MAC address: " MACSTR
,
1833 MAC2STR(wpa_s
->own_addr
));
1835 if (wpa_s
->bridge_ifname
[0]) {
1836 wpa_printf(MSG_DEBUG
, "Receiving packets from bridge interface"
1837 " '%s'", wpa_s
->bridge_ifname
);
1838 wpa_s
->l2_br
= l2_packet_init(wpa_s
->bridge_ifname
,
1841 wpa_supplicant_rx_eapol
, wpa_s
,
1843 if (wpa_s
->l2_br
== NULL
) {
1844 wpa_printf(MSG_ERROR
, "Failed to open l2_packet "
1845 "connection for the bridge interface '%s'",
1846 wpa_s
->bridge_ifname
);
1851 wpa_clear_keys(wpa_s
, NULL
);
1853 /* Make sure that TKIP countermeasures are not left enabled (could
1854 * happen if wpa_supplicant is killed during countermeasures. */
1855 wpa_drv_set_countermeasures(wpa_s
, 0);
1857 wpa_printf(MSG_DEBUG
, "RSN: flushing PMKID list in the driver");
1858 wpa_drv_flush_pmkid(wpa_s
);
1860 wpa_s
->prev_scan_ssid
= WILDCARD_SSID_SCAN
;
1861 if (wpa_supplicant_enabled_networks(wpa_s
->conf
)) {
1862 wpa_supplicant_req_scan(wpa_s
, interface_count
, 100000);
1865 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
1871 static int wpa_supplicant_daemon(const char *pid_file
)
1873 wpa_printf(MSG_DEBUG
, "Daemonize..");
1874 return os_daemonize(pid_file
);
1878 static struct wpa_supplicant
* wpa_supplicant_alloc(void)
1880 struct wpa_supplicant
*wpa_s
;
1882 wpa_s
= os_zalloc(sizeof(*wpa_s
));
1885 wpa_s
->scan_req
= 1;
1886 wpa_s
->new_connection
= 1;
1892 static int wpa_supplicant_init_iface(struct wpa_supplicant
*wpa_s
,
1893 struct wpa_interface
*iface
)
1895 const char *ifname
, *driver
;
1896 struct wpa_driver_capa capa
;
1898 wpa_printf(MSG_DEBUG
, "Initializing interface '%s' conf '%s' driver "
1899 "'%s' ctrl_interface '%s' bridge '%s'", iface
->ifname
,
1900 iface
->confname
? iface
->confname
: "N/A",
1901 iface
->driver
? iface
->driver
: "default",
1902 iface
->ctrl_interface
? iface
->ctrl_interface
: "N/A",
1903 iface
->bridge_ifname
? iface
->bridge_ifname
: "N/A");
1905 if (iface
->confname
) {
1906 #ifdef CONFIG_BACKEND_FILE
1907 wpa_s
->confname
= os_rel2abs_path(iface
->confname
);
1908 if (wpa_s
->confname
== NULL
) {
1909 wpa_printf(MSG_ERROR
, "Failed to get absolute path "
1910 "for configuration file '%s'.",
1914 wpa_printf(MSG_DEBUG
, "Configuration file '%s' -> '%s'",
1915 iface
->confname
, wpa_s
->confname
);
1916 #else /* CONFIG_BACKEND_FILE */
1917 wpa_s
->confname
= os_strdup(iface
->confname
);
1918 #endif /* CONFIG_BACKEND_FILE */
1919 wpa_s
->conf
= wpa_config_read(wpa_s
->confname
);
1920 if (wpa_s
->conf
== NULL
) {
1921 wpa_printf(MSG_ERROR
, "Failed to read or parse "
1922 "configuration '%s'.", wpa_s
->confname
);
1927 * Override ctrl_interface and driver_param if set on command
1930 if (iface
->ctrl_interface
) {
1931 os_free(wpa_s
->conf
->ctrl_interface
);
1932 wpa_s
->conf
->ctrl_interface
=
1933 os_strdup(iface
->ctrl_interface
);
1936 if (iface
->driver_param
) {
1937 os_free(wpa_s
->conf
->driver_param
);
1938 wpa_s
->conf
->driver_param
=
1939 os_strdup(iface
->driver_param
);
1942 wpa_s
->conf
= wpa_config_alloc_empty(iface
->ctrl_interface
,
1943 iface
->driver_param
);
1945 if (wpa_s
->conf
== NULL
) {
1946 wpa_printf(MSG_ERROR
, "\nNo configuration found.");
1950 if (iface
->ifname
== NULL
) {
1951 wpa_printf(MSG_ERROR
, "\nInterface name is required.");
1954 if (os_strlen(iface
->ifname
) >= sizeof(wpa_s
->ifname
)) {
1955 wpa_printf(MSG_ERROR
, "\nToo long interface name '%s'.",
1959 os_strlcpy(wpa_s
->ifname
, iface
->ifname
, sizeof(wpa_s
->ifname
));
1961 if (iface
->bridge_ifname
) {
1962 if (os_strlen(iface
->bridge_ifname
) >=
1963 sizeof(wpa_s
->bridge_ifname
)) {
1964 wpa_printf(MSG_ERROR
, "\nToo long bridge interface "
1965 "name '%s'.", iface
->bridge_ifname
);
1968 os_strlcpy(wpa_s
->bridge_ifname
, iface
->bridge_ifname
,
1969 sizeof(wpa_s
->bridge_ifname
));
1972 /* RSNA Supplicant Key Management - INITIALIZE */
1973 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
1974 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
1976 /* Initialize driver interface and register driver event handler before
1977 * L2 receive handler so that association events are processed before
1978 * EAPOL-Key packets if both become available for the same select()
1980 driver
= iface
->driver
;
1982 if (wpa_supplicant_set_driver(wpa_s
, driver
) < 0)
1985 wpa_s
->drv_priv
= wpa_drv_init(wpa_s
, wpa_s
->ifname
);
1986 if (wpa_s
->drv_priv
== NULL
) {
1988 pos
= driver
? os_strchr(driver
, ',') : NULL
;
1990 wpa_printf(MSG_DEBUG
, "Failed to initialize driver "
1991 "interface - try next driver wrapper");
1995 wpa_printf(MSG_ERROR
, "Failed to initialize driver interface");
1998 if (wpa_drv_set_param(wpa_s
, wpa_s
->conf
->driver_param
) < 0) {
1999 wpa_printf(MSG_ERROR
, "Driver interface rejected "
2000 "driver_param '%s'", wpa_s
->conf
->driver_param
);
2004 ifname
= wpa_drv_get_ifname(wpa_s
);
2005 if (ifname
&& os_strcmp(ifname
, wpa_s
->ifname
) != 0) {
2006 wpa_printf(MSG_DEBUG
, "Driver interface replaced interface "
2007 "name with '%s'", ifname
);
2008 os_strlcpy(wpa_s
->ifname
, ifname
, sizeof(wpa_s
->ifname
));
2011 if (wpa_supplicant_init_wpa(wpa_s
) < 0)
2014 wpa_sm_set_ifname(wpa_s
->wpa
, wpa_s
->ifname
,
2015 wpa_s
->bridge_ifname
[0] ? wpa_s
->bridge_ifname
:
2017 wpa_sm_set_fast_reauth(wpa_s
->wpa
, wpa_s
->conf
->fast_reauth
);
2019 if (wpa_s
->conf
->dot11RSNAConfigPMKLifetime
&&
2020 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
2021 wpa_s
->conf
->dot11RSNAConfigPMKLifetime
)) {
2022 wpa_printf(MSG_ERROR
, "Invalid WPA parameter value for "
2023 "dot11RSNAConfigPMKLifetime");
2027 if (wpa_s
->conf
->dot11RSNAConfigPMKReauthThreshold
&&
2028 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
2029 wpa_s
->conf
->dot11RSNAConfigPMKReauthThreshold
)) {
2030 wpa_printf(MSG_ERROR
, "Invalid WPA parameter value for "
2031 "dot11RSNAConfigPMKReauthThreshold");
2035 if (wpa_s
->conf
->dot11RSNAConfigSATimeout
&&
2036 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
,
2037 wpa_s
->conf
->dot11RSNAConfigSATimeout
)) {
2038 wpa_printf(MSG_ERROR
, "Invalid WPA parameter value for "
2039 "dot11RSNAConfigSATimeout");
2043 if (wpa_drv_get_capa(wpa_s
, &capa
) == 0) {
2044 wpa_s
->drv_flags
= capa
.flags
;
2045 if (capa
.flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
) {
2046 if (ieee80211_sta_init(wpa_s
))
2049 wpa_s
->max_scan_ssids
= capa
.max_scan_ssids
;
2050 wpa_s
->max_remain_on_chan
= capa
.max_remain_on_chan
;
2052 if (wpa_s
->max_remain_on_chan
== 0)
2053 wpa_s
->max_remain_on_chan
= 1000;
2055 if (wpa_supplicant_driver_init(wpa_s
) < 0)
2058 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1] &&
2059 wpa_drv_set_country(wpa_s
, wpa_s
->conf
->country
)) {
2060 wpa_printf(MSG_DEBUG
, "Failed to set country");
2064 wpa_sm_set_own_addr(wpa_s
->wpa
, wpa_s
->own_addr
);
2066 if (wpas_wps_init(wpa_s
))
2069 if (wpa_supplicant_init_eapol(wpa_s
) < 0)
2071 wpa_sm_set_eapol(wpa_s
->wpa
, wpa_s
->eapol
);
2073 wpa_s
->ctrl_iface
= wpa_supplicant_ctrl_iface_init(wpa_s
);
2074 if (wpa_s
->ctrl_iface
== NULL
) {
2075 wpa_printf(MSG_ERROR
,
2076 "Failed to initialize control interface '%s'.\n"
2077 "You may have another wpa_supplicant process "
2078 "already running or the file was\n"
2079 "left by an unclean termination of wpa_supplicant "
2080 "in which case you will need\n"
2081 "to manually remove this file before starting "
2082 "wpa_supplicant again.\n",
2083 wpa_s
->conf
->ctrl_interface
);
2087 #ifdef CONFIG_IBSS_RSN
2088 wpa_s
->ibss_rsn
= ibss_rsn_init(wpa_s
);
2089 if (!wpa_s
->ibss_rsn
) {
2090 wpa_printf(MSG_DEBUG
, "Failed to init IBSS RSN");
2093 #endif /* CONFIG_IBSS_RSN */
2095 if (wpa_bss_init(wpa_s
) < 0)
2102 static void wpa_supplicant_deinit_iface(struct wpa_supplicant
*wpa_s
,
2105 if (wpa_s
->drv_priv
) {
2106 wpa_supplicant_deauthenticate(wpa_s
,
2107 WLAN_REASON_DEAUTH_LEAVING
);
2109 wpa_drv_set_countermeasures(wpa_s
, 0);
2110 wpa_clear_keys(wpa_s
, NULL
);
2113 wpa_supplicant_cleanup(wpa_s
);
2116 wpas_notify_iface_removed(wpa_s
);
2118 if (wpa_s
->drv_priv
)
2119 wpa_drv_deinit(wpa_s
);
2124 * wpa_supplicant_add_iface - Add a new network interface
2125 * @global: Pointer to global data from wpa_supplicant_init()
2126 * @iface: Interface configuration options
2127 * Returns: Pointer to the created interface or %NULL on failure
2129 * This function is used to add new network interfaces for %wpa_supplicant.
2130 * This can be called before wpa_supplicant_run() to add interfaces before the
2131 * main event loop has been started. In addition, new interfaces can be added
2132 * dynamically while %wpa_supplicant is already running. This could happen,
2133 * e.g., when a hotplug network adapter is inserted.
2135 struct wpa_supplicant
* wpa_supplicant_add_iface(struct wpa_global
*global
,
2136 struct wpa_interface
*iface
)
2138 struct wpa_supplicant
*wpa_s
;
2139 struct wpa_interface t_iface
;
2140 struct wpa_ssid
*ssid
;
2142 if (global
== NULL
|| iface
== NULL
)
2145 wpa_s
= wpa_supplicant_alloc();
2149 wpa_s
->global
= global
;
2152 if (global
->params
.override_driver
) {
2153 wpa_printf(MSG_DEBUG
, "Override interface parameter: driver "
2155 iface
->driver
, global
->params
.override_driver
);
2156 t_iface
.driver
= global
->params
.override_driver
;
2158 if (global
->params
.override_ctrl_interface
) {
2159 wpa_printf(MSG_DEBUG
, "Override interface parameter: "
2160 "ctrl_interface ('%s' -> '%s')",
2161 iface
->ctrl_interface
,
2162 global
->params
.override_ctrl_interface
);
2163 t_iface
.ctrl_interface
=
2164 global
->params
.override_ctrl_interface
;
2166 if (wpa_supplicant_init_iface(wpa_s
, &t_iface
)) {
2167 wpa_printf(MSG_DEBUG
, "Failed to add interface %s",
2169 wpa_supplicant_deinit_iface(wpa_s
, 0);
2174 /* Notify the control interfaces about new iface */
2175 if (wpas_notify_iface_added(wpa_s
)) {
2176 wpa_supplicant_deinit_iface(wpa_s
, 1);
2181 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
)
2182 wpas_notify_network_added(wpa_s
, ssid
);
2184 wpa_s
->next
= global
->ifaces
;
2185 global
->ifaces
= wpa_s
;
2187 wpa_printf(MSG_DEBUG
, "Added interface %s", wpa_s
->ifname
);
2194 * wpa_supplicant_remove_iface - Remove a network interface
2195 * @global: Pointer to global data from wpa_supplicant_init()
2196 * @wpa_s: Pointer to the network interface to be removed
2197 * Returns: 0 if interface was removed, -1 if interface was not found
2199 * This function can be used to dynamically remove network interfaces from
2200 * %wpa_supplicant, e.g., when a hotplug network adapter is ejected. In
2201 * addition, this function is used to remove all remaining interfaces when
2202 * %wpa_supplicant is terminated.
2204 int wpa_supplicant_remove_iface(struct wpa_global
*global
,
2205 struct wpa_supplicant
*wpa_s
)
2207 struct wpa_supplicant
*prev
;
2209 /* Remove interface from the global list of interfaces */
2210 prev
= global
->ifaces
;
2211 if (prev
== wpa_s
) {
2212 global
->ifaces
= wpa_s
->next
;
2214 while (prev
&& prev
->next
!= wpa_s
)
2218 prev
->next
= wpa_s
->next
;
2221 wpa_printf(MSG_DEBUG
, "Removing interface %s", wpa_s
->ifname
);
2223 wpa_supplicant_deinit_iface(wpa_s
, 1);
2231 * wpa_supplicant_get_iface - Get a new network interface
2232 * @global: Pointer to global data from wpa_supplicant_init()
2233 * @ifname: Interface name
2234 * Returns: Pointer to the interface or %NULL if not found
2236 struct wpa_supplicant
* wpa_supplicant_get_iface(struct wpa_global
*global
,
2239 struct wpa_supplicant
*wpa_s
;
2241 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2242 if (os_strcmp(wpa_s
->ifname
, ifname
) == 0)
2250 * wpa_supplicant_init - Initialize %wpa_supplicant
2251 * @params: Parameters for %wpa_supplicant
2252 * Returns: Pointer to global %wpa_supplicant data, or %NULL on failure
2254 * This function is used to initialize %wpa_supplicant. After successful
2255 * initialization, the returned data pointer can be used to add and remove
2256 * network interfaces, and eventually, to deinitialize %wpa_supplicant.
2258 struct wpa_global
* wpa_supplicant_init(struct wpa_params
*params
)
2260 struct wpa_global
*global
;
2266 wpa_debug_open_file(params
->wpa_debug_file_path
);
2267 if (params
->wpa_debug_syslog
)
2268 wpa_debug_open_syslog();
2270 ret
= eap_register_methods();
2272 wpa_printf(MSG_ERROR
, "Failed to register EAP methods");
2274 wpa_printf(MSG_ERROR
, "Two or more EAP methods used "
2275 "the same EAP type.");
2279 global
= os_zalloc(sizeof(*global
));
2282 global
->params
.daemonize
= params
->daemonize
;
2283 global
->params
.wait_for_monitor
= params
->wait_for_monitor
;
2284 global
->params
.dbus_ctrl_interface
= params
->dbus_ctrl_interface
;
2285 if (params
->pid_file
)
2286 global
->params
.pid_file
= os_strdup(params
->pid_file
);
2287 if (params
->ctrl_interface
)
2288 global
->params
.ctrl_interface
=
2289 os_strdup(params
->ctrl_interface
);
2290 if (params
->override_driver
)
2291 global
->params
.override_driver
=
2292 os_strdup(params
->override_driver
);
2293 if (params
->override_ctrl_interface
)
2294 global
->params
.override_ctrl_interface
=
2295 os_strdup(params
->override_ctrl_interface
);
2296 wpa_debug_level
= global
->params
.wpa_debug_level
=
2297 params
->wpa_debug_level
;
2298 wpa_debug_show_keys
= global
->params
.wpa_debug_show_keys
=
2299 params
->wpa_debug_show_keys
;
2300 wpa_debug_timestamp
= global
->params
.wpa_debug_timestamp
=
2301 params
->wpa_debug_timestamp
;
2304 wpa_printf(MSG_ERROR
, "Failed to initialize event loop");
2305 wpa_supplicant_deinit(global
);
2309 global
->ctrl_iface
= wpa_supplicant_global_ctrl_iface_init(global
);
2310 if (global
->ctrl_iface
== NULL
) {
2311 wpa_supplicant_deinit(global
);
2315 if (wpas_notify_supplicant_initialized(global
)) {
2316 wpa_supplicant_deinit(global
);
2320 for (i
= 0; wpa_drivers
[i
]; i
++)
2321 global
->drv_count
++;
2322 if (global
->drv_count
== 0) {
2323 wpa_printf(MSG_ERROR
, "No drivers enabled");
2324 wpa_supplicant_deinit(global
);
2327 global
->drv_priv
= os_zalloc(global
->drv_count
* sizeof(void *));
2328 if (global
->drv_priv
== NULL
) {
2329 wpa_supplicant_deinit(global
);
2332 for (i
= 0; wpa_drivers
[i
]; i
++) {
2333 if (!wpa_drivers
[i
]->global_init
)
2335 global
->drv_priv
[i
] = wpa_drivers
[i
]->global_init();
2336 if (global
->drv_priv
[i
] == NULL
) {
2337 wpa_printf(MSG_ERROR
, "Failed to initialize driver "
2338 "'%s'", wpa_drivers
[i
]->name
);
2339 wpa_supplicant_deinit(global
);
2349 * wpa_supplicant_run - Run the %wpa_supplicant main event loop
2350 * @global: Pointer to global data from wpa_supplicant_init()
2351 * Returns: 0 after successful event loop run, -1 on failure
2353 * This function starts the main event loop and continues running as long as
2354 * there are any remaining events. In most cases, this function is running as
2355 * long as the %wpa_supplicant process in still in use.
2357 int wpa_supplicant_run(struct wpa_global
*global
)
2359 struct wpa_supplicant
*wpa_s
;
2361 if (global
->params
.daemonize
&&
2362 wpa_supplicant_daemon(global
->params
.pid_file
))
2365 if (global
->params
.wait_for_monitor
) {
2366 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
)
2367 if (wpa_s
->ctrl_iface
)
2368 wpa_supplicant_ctrl_iface_wait(
2372 eloop_register_signal_terminate(wpa_supplicant_terminate
, global
);
2373 eloop_register_signal_reconfig(wpa_supplicant_reconfig
, global
);
2382 * wpa_supplicant_deinit - Deinitialize %wpa_supplicant
2383 * @global: Pointer to global data from wpa_supplicant_init()
2385 * This function is called to deinitialize %wpa_supplicant and to free all
2386 * allocated resources. Remaining network interfaces will also be removed.
2388 void wpa_supplicant_deinit(struct wpa_global
*global
)
2395 while (global
->ifaces
)
2396 wpa_supplicant_remove_iface(global
, global
->ifaces
);
2398 if (global
->ctrl_iface
)
2399 wpa_supplicant_global_ctrl_iface_deinit(global
->ctrl_iface
);
2401 wpas_notify_supplicant_deinitialized(global
);
2403 eap_peer_unregister_methods();
2405 eap_server_unregister_methods();
2406 #endif /* CONFIG_AP */
2408 for (i
= 0; wpa_drivers
[i
] && global
->drv_priv
; i
++) {
2409 if (!global
->drv_priv
[i
])
2411 wpa_drivers
[i
]->global_deinit(global
->drv_priv
[i
]);
2413 os_free(global
->drv_priv
);
2417 if (global
->params
.pid_file
) {
2418 os_daemonize_terminate(global
->params
.pid_file
);
2419 os_free(global
->params
.pid_file
);
2421 os_free(global
->params
.ctrl_interface
);
2422 os_free(global
->params
.override_driver
);
2423 os_free(global
->params
.override_ctrl_interface
);
2426 wpa_debug_close_syslog();
2427 wpa_debug_close_file();