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";
492 case WPA_INTERFACE_DISABLED
:
493 return "INTERFACE_DISABLED";
496 case WPA_AUTHENTICATING
:
497 return "AUTHENTICATING";
498 case WPA_ASSOCIATING
:
499 return "ASSOCIATING";
502 case WPA_4WAY_HANDSHAKE
:
503 return "4WAY_HANDSHAKE";
504 case WPA_GROUP_HANDSHAKE
:
505 return "GROUP_HANDSHAKE";
515 * wpa_supplicant_set_state - Set current connection state
516 * @wpa_s: Pointer to wpa_supplicant data
517 * @state: The new connection state
519 * This function is called whenever the connection state changes, e.g.,
520 * association is completed for WPA/WPA2 4-Way Handshake is started.
522 void wpa_supplicant_set_state(struct wpa_supplicant
*wpa_s
,
523 enum wpa_states state
)
525 enum wpa_states old_state
= wpa_s
->wpa_state
;
527 wpa_printf(MSG_DEBUG
, "State: %s -> %s",
528 wpa_supplicant_state_txt(wpa_s
->wpa_state
),
529 wpa_supplicant_state_txt(state
));
531 if (state
!= WPA_SCANNING
)
532 wpa_supplicant_notify_scanning(wpa_s
, 0);
534 if (state
== WPA_COMPLETED
&& wpa_s
->new_connection
) {
535 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
536 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
537 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
"- Connection to "
538 MACSTR
" completed %s [id=%d id_str=%s]",
539 MAC2STR(wpa_s
->bssid
), wpa_s
->reassociated_connection
?
540 "(reauth)" : "(auth)",
541 ssid
? ssid
->id
: -1,
542 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
543 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
544 wpa_s
->new_connection
= 0;
545 wpa_s
->reassociated_connection
= 1;
546 wpa_drv_set_operstate(wpa_s
, 1);
547 wpa_s
->after_wps
= 0;
548 } else if (state
== WPA_DISCONNECTED
|| state
== WPA_ASSOCIATING
||
549 state
== WPA_ASSOCIATED
) {
550 wpa_s
->new_connection
= 1;
551 wpa_drv_set_operstate(wpa_s
, 0);
553 wpa_s
->wpa_state
= state
;
555 if (wpa_s
->wpa_state
!= old_state
)
556 wpas_notify_state_changed(wpa_s
, wpa_s
->wpa_state
, old_state
);
560 void wpa_supplicant_terminate_proc(struct wpa_global
*global
)
564 struct wpa_supplicant
*wpa_s
= global
->ifaces
;
566 if (wpas_wps_terminate_pending(wpa_s
) == 1)
570 #endif /* CONFIG_WPS */
577 static void wpa_supplicant_terminate(int sig
, void *signal_ctx
)
579 struct wpa_global
*global
= signal_ctx
;
580 struct wpa_supplicant
*wpa_s
;
581 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
582 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_TERMINATING
"- signal %d "
585 wpa_supplicant_terminate_proc(global
);
589 static void wpa_supplicant_clear_status(struct wpa_supplicant
*wpa_s
)
591 enum wpa_states old_state
= wpa_s
->wpa_state
;
593 wpa_s
->pairwise_cipher
= 0;
594 wpa_s
->group_cipher
= 0;
595 wpa_s
->mgmt_group_cipher
= 0;
597 if (wpa_s
->wpa_state
!= WPA_INTERFACE_DISABLED
)
598 wpa_s
->wpa_state
= WPA_DISCONNECTED
;
600 if (wpa_s
->wpa_state
!= old_state
)
601 wpas_notify_state_changed(wpa_s
, wpa_s
->wpa_state
, old_state
);
606 * wpa_supplicant_reload_configuration - Reload configuration data
607 * @wpa_s: Pointer to wpa_supplicant data
608 * Returns: 0 on success or -1 if configuration parsing failed
610 * This function can be used to request that the configuration data is reloaded
611 * (e.g., after configuration file change). This function is reloading
612 * configuration only for one interface, so this may need to be called multiple
613 * times if %wpa_supplicant is controlling multiple interfaces and all
614 * interfaces need reconfiguration.
616 int wpa_supplicant_reload_configuration(struct wpa_supplicant
*wpa_s
)
618 struct wpa_config
*conf
;
619 struct wpa_ssid
*old_ssid
;
623 if (wpa_s
->confname
== NULL
)
625 conf
= wpa_config_read(wpa_s
->confname
);
627 wpa_msg(wpa_s
, MSG_ERROR
, "Failed to parse the configuration "
628 "file '%s' - exiting", wpa_s
->confname
);
632 reconf_ctrl
= !!conf
->ctrl_interface
!= !!wpa_s
->conf
->ctrl_interface
633 || (conf
->ctrl_interface
&& wpa_s
->conf
->ctrl_interface
&&
634 os_strcmp(conf
->ctrl_interface
,
635 wpa_s
->conf
->ctrl_interface
) != 0);
637 if (reconf_ctrl
&& wpa_s
->ctrl_iface
) {
638 wpa_supplicant_ctrl_iface_deinit(wpa_s
->ctrl_iface
);
639 wpa_s
->ctrl_iface
= NULL
;
642 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
643 old_ssid
= wpa_s
->current_ssid
;
644 wpa_s
->current_ssid
= NULL
;
645 if (old_ssid
!= wpa_s
->current_ssid
)
646 wpas_notify_network_changed(wpa_s
);
649 * TODO: should notify EAPOL SM about changes in opensc_engine_path,
650 * pkcs11_engine_path, pkcs11_module_path.
652 if (wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
)) {
654 * Clear forced success to clear EAP state for next
657 eapol_sm_notify_eap_success(wpa_s
->eapol
, FALSE
);
659 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
660 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
661 wpa_sm_set_fast_reauth(wpa_s
->wpa
, wpa_s
->conf
->fast_reauth
);
662 rsn_preauth_deinit(wpa_s
->wpa
);
664 old_ap_scan
= wpa_s
->conf
->ap_scan
;
665 wpa_config_free(wpa_s
->conf
);
667 if (old_ap_scan
!= wpa_s
->conf
->ap_scan
)
668 wpas_notify_ap_scan_changed(wpa_s
);
671 wpa_s
->ctrl_iface
= wpa_supplicant_ctrl_iface_init(wpa_s
);
673 wpa_supplicant_clear_status(wpa_s
);
674 wpa_s
->reassociate
= 1;
675 wpa_supplicant_req_scan(wpa_s
, 0, 0);
676 wpa_msg(wpa_s
, MSG_DEBUG
, "Reconfiguration completed");
681 static void wpa_supplicant_reconfig(int sig
, void *signal_ctx
)
683 struct wpa_global
*global
= signal_ctx
;
684 struct wpa_supplicant
*wpa_s
;
685 wpa_printf(MSG_DEBUG
, "Signal %d received - reconfiguring", sig
);
686 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
687 if (wpa_supplicant_reload_configuration(wpa_s
) < 0) {
688 wpa_supplicant_terminate_proc(global
);
694 enum wpa_cipher
cipher_suite2driver(int cipher
)
697 case WPA_CIPHER_NONE
:
699 case WPA_CIPHER_WEP40
:
701 case WPA_CIPHER_WEP104
:
702 return CIPHER_WEP104
;
703 case WPA_CIPHER_CCMP
:
705 case WPA_CIPHER_TKIP
:
712 enum wpa_key_mgmt
key_mgmt2driver(int key_mgmt
)
715 case WPA_KEY_MGMT_NONE
:
716 return KEY_MGMT_NONE
;
717 case WPA_KEY_MGMT_IEEE8021X_NO_WPA
:
718 return KEY_MGMT_802_1X_NO_WPA
;
719 case WPA_KEY_MGMT_IEEE8021X
:
720 return KEY_MGMT_802_1X
;
721 case WPA_KEY_MGMT_WPA_NONE
:
722 return KEY_MGMT_WPA_NONE
;
723 case WPA_KEY_MGMT_FT_IEEE8021X
:
724 return KEY_MGMT_FT_802_1X
;
725 case WPA_KEY_MGMT_FT_PSK
:
726 return KEY_MGMT_FT_PSK
;
727 case WPA_KEY_MGMT_IEEE8021X_SHA256
:
728 return KEY_MGMT_802_1X_SHA256
;
729 case WPA_KEY_MGMT_PSK_SHA256
:
730 return KEY_MGMT_PSK_SHA256
;
731 case WPA_KEY_MGMT_WPS
:
733 case WPA_KEY_MGMT_PSK
:
740 static int wpa_supplicant_suites_from_ai(struct wpa_supplicant
*wpa_s
,
741 struct wpa_ssid
*ssid
,
742 struct wpa_ie_data
*ie
)
744 int ret
= wpa_sm_parse_own_wpa_ie(wpa_s
->wpa
, ie
);
747 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Failed to parse WPA IE "
748 "from association info");
753 wpa_printf(MSG_DEBUG
, "WPA: Using WPA IE from AssocReq to set cipher "
755 if (!(ie
->group_cipher
& ssid
->group_cipher
)) {
756 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled group "
757 "cipher 0x%x (mask 0x%x) - reject",
758 ie
->group_cipher
, ssid
->group_cipher
);
761 if (!(ie
->pairwise_cipher
& ssid
->pairwise_cipher
)) {
762 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled pairwise "
763 "cipher 0x%x (mask 0x%x) - reject",
764 ie
->pairwise_cipher
, ssid
->pairwise_cipher
);
767 if (!(ie
->key_mgmt
& ssid
->key_mgmt
)) {
768 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver used disabled key "
769 "management 0x%x (mask 0x%x) - reject",
770 ie
->key_mgmt
, ssid
->key_mgmt
);
774 #ifdef CONFIG_IEEE80211W
775 if (!(ie
->capabilities
& WPA_CAPABILITY_MFPC
) &&
776 ssid
->ieee80211w
== MGMT_FRAME_PROTECTION_REQUIRED
) {
777 wpa_msg(wpa_s
, MSG_INFO
, "WPA: Driver associated with an AP "
778 "that does not support management frame protection - "
782 #endif /* CONFIG_IEEE80211W */
789 * wpa_supplicant_set_suites - Set authentication and encryption parameters
790 * @wpa_s: Pointer to wpa_supplicant data
791 * @bss: Scan results for the selected BSS, or %NULL if not available
792 * @ssid: Configuration data for the selected network
793 * @wpa_ie: Buffer for the WPA/RSN IE
794 * @wpa_ie_len: Maximum wpa_ie buffer size on input. This is changed to be the
795 * used buffer length in case the functions returns success.
796 * Returns: 0 on success or -1 on failure
798 * This function is used to configure authentication and encryption parameters
799 * based on the network configuration and scan result for the selected BSS (if
802 int wpa_supplicant_set_suites(struct wpa_supplicant
*wpa_s
,
803 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
,
804 u8
*wpa_ie
, size_t *wpa_ie_len
)
806 struct wpa_ie_data ie
;
808 const u8
*bss_wpa
, *bss_rsn
;
811 bss_wpa
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
812 bss_rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
814 bss_wpa
= bss_rsn
= NULL
;
816 if (bss_rsn
&& (ssid
->proto
& WPA_PROTO_RSN
) &&
817 wpa_parse_wpa_ie(bss_rsn
, 2 + bss_rsn
[1], &ie
) == 0 &&
818 (ie
.group_cipher
& ssid
->group_cipher
) &&
819 (ie
.pairwise_cipher
& ssid
->pairwise_cipher
) &&
820 (ie
.key_mgmt
& ssid
->key_mgmt
)) {
821 wpa_msg(wpa_s
, MSG_DEBUG
, "RSN: using IEEE 802.11i/D9.0");
822 proto
= WPA_PROTO_RSN
;
823 } else if (bss_wpa
&& (ssid
->proto
& WPA_PROTO_WPA
) &&
824 wpa_parse_wpa_ie(bss_wpa
, 2 +bss_wpa
[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
, "WPA: using IEEE 802.11i/D3.0");
829 proto
= WPA_PROTO_WPA
;
831 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed to select WPA/RSN");
834 if (ssid
->proto
& WPA_PROTO_RSN
)
835 proto
= WPA_PROTO_RSN
;
837 proto
= WPA_PROTO_WPA
;
838 if (wpa_supplicant_suites_from_ai(wpa_s
, ssid
, &ie
) < 0) {
839 os_memset(&ie
, 0, sizeof(ie
));
840 ie
.group_cipher
= ssid
->group_cipher
;
841 ie
.pairwise_cipher
= ssid
->pairwise_cipher
;
842 ie
.key_mgmt
= ssid
->key_mgmt
;
843 #ifdef CONFIG_IEEE80211W
844 ie
.mgmt_group_cipher
=
845 ssid
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
?
846 WPA_CIPHER_AES_128_CMAC
: 0;
847 #endif /* CONFIG_IEEE80211W */
848 wpa_printf(MSG_DEBUG
, "WPA: Set cipher suites based "
854 wpa_printf(MSG_DEBUG
, "WPA: Selected cipher suites: group %d "
855 "pairwise %d key_mgmt %d proto %d",
856 ie
.group_cipher
, ie
.pairwise_cipher
, ie
.key_mgmt
, proto
);
857 #ifdef CONFIG_IEEE80211W
858 if (ssid
->ieee80211w
) {
859 wpa_printf(MSG_DEBUG
, "WPA: Selected mgmt group cipher %d",
860 ie
.mgmt_group_cipher
);
862 #endif /* CONFIG_IEEE80211W */
864 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PROTO
, proto
);
865 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_RSN_ENABLED
,
866 !!(ssid
->proto
& WPA_PROTO_RSN
));
868 if (bss
|| !wpa_s
->ap_ies_from_associnfo
) {
869 if (wpa_sm_set_ap_wpa_ie(wpa_s
->wpa
, bss_wpa
,
870 bss_wpa
? 2 + bss_wpa
[1] : 0) ||
871 wpa_sm_set_ap_rsn_ie(wpa_s
->wpa
, bss_rsn
,
872 bss_rsn
? 2 + bss_rsn
[1] : 0))
876 sel
= ie
.group_cipher
& ssid
->group_cipher
;
877 if (sel
& WPA_CIPHER_CCMP
) {
878 wpa_s
->group_cipher
= WPA_CIPHER_CCMP
;
879 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using GTK CCMP");
880 } else if (sel
& WPA_CIPHER_TKIP
) {
881 wpa_s
->group_cipher
= WPA_CIPHER_TKIP
;
882 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using GTK TKIP");
883 } else if (sel
& WPA_CIPHER_WEP104
) {
884 wpa_s
->group_cipher
= WPA_CIPHER_WEP104
;
885 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using GTK WEP104");
886 } else if (sel
& WPA_CIPHER_WEP40
) {
887 wpa_s
->group_cipher
= WPA_CIPHER_WEP40
;
888 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using GTK WEP40");
890 wpa_printf(MSG_WARNING
, "WPA: Failed to select group cipher.");
894 sel
= ie
.pairwise_cipher
& ssid
->pairwise_cipher
;
895 if (sel
& WPA_CIPHER_CCMP
) {
896 wpa_s
->pairwise_cipher
= WPA_CIPHER_CCMP
;
897 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using PTK CCMP");
898 } else if (sel
& WPA_CIPHER_TKIP
) {
899 wpa_s
->pairwise_cipher
= WPA_CIPHER_TKIP
;
900 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using PTK TKIP");
901 } else if (sel
& WPA_CIPHER_NONE
) {
902 wpa_s
->pairwise_cipher
= WPA_CIPHER_NONE
;
903 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using PTK NONE");
905 wpa_printf(MSG_WARNING
, "WPA: Failed to select pairwise "
910 sel
= ie
.key_mgmt
& ssid
->key_mgmt
;
912 #ifdef CONFIG_IEEE80211R
913 } else if (sel
& WPA_KEY_MGMT_FT_IEEE8021X
) {
914 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_IEEE8021X
;
915 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FT/802.1X");
916 } else if (sel
& WPA_KEY_MGMT_FT_PSK
) {
917 wpa_s
->key_mgmt
= WPA_KEY_MGMT_FT_PSK
;
918 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT FT/PSK");
919 #endif /* CONFIG_IEEE80211R */
920 #ifdef CONFIG_IEEE80211W
921 } else if (sel
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
922 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X_SHA256
;
923 wpa_msg(wpa_s
, MSG_DEBUG
,
924 "WPA: using KEY_MGMT 802.1X with SHA256");
925 } else if (sel
& WPA_KEY_MGMT_PSK_SHA256
) {
926 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK_SHA256
;
927 wpa_msg(wpa_s
, MSG_DEBUG
,
928 "WPA: using KEY_MGMT PSK with SHA256");
929 #endif /* CONFIG_IEEE80211W */
930 } else if (sel
& WPA_KEY_MGMT_IEEE8021X
) {
931 wpa_s
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X
;
932 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT 802.1X");
933 } else if (sel
& WPA_KEY_MGMT_PSK
) {
934 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK
;
935 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT WPA-PSK");
936 } else if (sel
& WPA_KEY_MGMT_WPA_NONE
) {
937 wpa_s
->key_mgmt
= WPA_KEY_MGMT_WPA_NONE
;
938 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using KEY_MGMT WPA-NONE");
940 wpa_printf(MSG_WARNING
, "WPA: Failed to select authenticated "
941 "key management type.");
945 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_KEY_MGMT
, wpa_s
->key_mgmt
);
946 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_PAIRWISE
,
947 wpa_s
->pairwise_cipher
);
948 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_GROUP
, wpa_s
->group_cipher
);
950 #ifdef CONFIG_IEEE80211W
951 sel
= ie
.mgmt_group_cipher
;
952 if (ssid
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
||
953 !(ie
.capabilities
& WPA_CAPABILITY_MFPC
))
955 if (sel
& WPA_CIPHER_AES_128_CMAC
) {
956 wpa_s
->mgmt_group_cipher
= WPA_CIPHER_AES_128_CMAC
;
957 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: using MGMT group cipher "
960 wpa_s
->mgmt_group_cipher
= 0;
961 wpa_msg(wpa_s
, MSG_DEBUG
, "WPA: not using MGMT group cipher");
963 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MGMT_GROUP
,
964 wpa_s
->mgmt_group_cipher
);
965 wpa_sm_set_param(wpa_s
->wpa
, WPA_PARAM_MFP
, ssid
->ieee80211w
);
966 #endif /* CONFIG_IEEE80211W */
968 if (wpa_sm_set_assoc_wpa_ie_default(wpa_s
->wpa
, wpa_ie
, wpa_ie_len
)) {
969 wpa_printf(MSG_WARNING
, "WPA: Failed to generate WPA IE.");
974 (WPA_KEY_MGMT_PSK
| WPA_KEY_MGMT_FT_PSK
| WPA_KEY_MGMT_PSK_SHA256
))
975 wpa_sm_set_pmk(wpa_s
->wpa
, ssid
->psk
, PMK_LEN
);
977 wpa_sm_set_pmk_from_pmksa(wpa_s
->wpa
);
984 * wpa_supplicant_associate - Request association
985 * @wpa_s: Pointer to wpa_supplicant data
986 * @bss: Scan results for the selected BSS, or %NULL if not available
987 * @ssid: Configuration data for the selected network
989 * This function is used to request %wpa_supplicant to associate with a BSS.
991 void wpa_supplicant_associate(struct wpa_supplicant
*wpa_s
,
992 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
)
996 int use_crypt
, ret
, i
, bssid_changed
;
997 int algs
= WPA_AUTH_ALG_OPEN
;
998 enum wpa_cipher cipher_pairwise
, cipher_group
;
999 struct wpa_driver_associate_params params
;
1000 int wep_keys_set
= 0;
1001 struct wpa_driver_capa capa
;
1002 int assoc_failed
= 0;
1003 struct wpa_ssid
*old_ssid
;
1005 if (ssid
->mode
== WPAS_MODE_AP
) {
1007 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_AP
)) {
1008 wpa_printf(MSG_INFO
, "Driver does not support AP "
1012 wpa_supplicant_create_ap(wpa_s
, ssid
);
1013 wpa_s
->current_bss
= bss
;
1014 #else /* CONFIG_AP */
1015 wpa_printf(MSG_ERROR
, "AP mode support not included in the "
1017 #endif /* CONFIG_AP */
1021 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
1022 ssid
->mode
== IEEE80211_MODE_INFRA
) {
1023 sme_authenticate(wpa_s
, bss
, ssid
);
1027 wpa_s
->reassociate
= 0;
1029 #ifdef CONFIG_IEEE80211R
1030 const u8
*ie
, *md
= NULL
;
1031 #endif /* CONFIG_IEEE80211R */
1032 wpa_msg(wpa_s
, MSG_INFO
, "Trying to associate with " MACSTR
1033 " (SSID='%s' freq=%d MHz)", MAC2STR(bss
->bssid
),
1034 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
), bss
->freq
);
1035 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
1036 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
1037 os_memcpy(wpa_s
->pending_bssid
, bss
->bssid
, ETH_ALEN
);
1039 wpas_notify_bssid_changed(wpa_s
);
1040 #ifdef CONFIG_IEEE80211R
1041 ie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
1042 if (ie
&& ie
[1] >= MOBILITY_DOMAIN_ID_LEN
)
1044 wpa_sm_set_ft_params(wpa_s
->wpa
, ie
, ie
? 2 + ie
[1] : 0);
1046 /* Prepare for the next transition */
1047 wpa_ft_prepare_auth_request(wpa_s
->wpa
, ie
);
1049 #endif /* CONFIG_IEEE80211R */
1051 } else if ((ssid
->ssid
== NULL
|| ssid
->ssid_len
== 0) &&
1052 wpa_s
->conf
->ap_scan
== 2 &&
1053 (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)) {
1054 /* Use ap_scan==1 style network selection to find the network
1056 wpa_s
->scan_req
= 2;
1057 wpa_s
->reassociate
= 1;
1058 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1060 #endif /* CONFIG_WPS */
1062 wpa_msg(wpa_s
, MSG_INFO
, "Trying to associate with SSID '%s'",
1063 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
1064 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1066 wpa_supplicant_cancel_scan(wpa_s
);
1068 /* Starting new association, so clear the possibly used WPA IE from the
1069 * previous association. */
1070 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1072 #ifdef IEEE8021X_EAPOL
1073 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1075 if (ssid
->non_leap
== 0)
1076 algs
= WPA_AUTH_ALG_LEAP
;
1078 algs
|= WPA_AUTH_ALG_LEAP
;
1081 #endif /* IEEE8021X_EAPOL */
1082 wpa_printf(MSG_DEBUG
, "Automatic auth_alg selection: 0x%x", algs
);
1083 if (ssid
->auth_alg
) {
1084 algs
= ssid
->auth_alg
;
1085 wpa_printf(MSG_DEBUG
, "Overriding auth_alg selection: 0x%x",
1089 if (bss
&& (wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
) ||
1090 wpa_bss_get_ie(bss
, WLAN_EID_RSN
)) &&
1091 (ssid
->key_mgmt
& (WPA_KEY_MGMT_IEEE8021X
| WPA_KEY_MGMT_PSK
|
1092 WPA_KEY_MGMT_FT_IEEE8021X
|
1093 WPA_KEY_MGMT_FT_PSK
|
1094 WPA_KEY_MGMT_IEEE8021X_SHA256
|
1095 WPA_KEY_MGMT_PSK_SHA256
))) {
1096 int try_opportunistic
;
1097 try_opportunistic
= ssid
->proactive_key_caching
&&
1098 (ssid
->proto
& WPA_PROTO_RSN
);
1099 if (pmksa_cache_set_current(wpa_s
->wpa
, NULL
, bss
->bssid
,
1100 wpa_s
->current_ssid
,
1101 try_opportunistic
) == 0)
1102 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
, 1);
1103 wpa_ie_len
= sizeof(wpa_ie
);
1104 if (wpa_supplicant_set_suites(wpa_s
, bss
, ssid
,
1105 wpa_ie
, &wpa_ie_len
)) {
1106 wpa_printf(MSG_WARNING
, "WPA: Failed to set WPA key "
1107 "management and encryption suites");
1110 } else if (ssid
->key_mgmt
&
1111 (WPA_KEY_MGMT_PSK
| WPA_KEY_MGMT_IEEE8021X
|
1112 WPA_KEY_MGMT_WPA_NONE
| WPA_KEY_MGMT_FT_PSK
|
1113 WPA_KEY_MGMT_FT_IEEE8021X
| WPA_KEY_MGMT_PSK_SHA256
|
1114 WPA_KEY_MGMT_IEEE8021X_SHA256
)) {
1115 wpa_ie_len
= sizeof(wpa_ie
);
1116 if (wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
1117 wpa_ie
, &wpa_ie_len
)) {
1118 wpa_printf(MSG_WARNING
, "WPA: Failed to set WPA key "
1119 "management and encryption suites (no scan "
1124 } else if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
1125 struct wpabuf
*wps_ie
;
1126 wps_ie
= wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid
));
1127 if (wps_ie
&& wpabuf_len(wps_ie
) <= sizeof(wpa_ie
)) {
1128 wpa_ie_len
= wpabuf_len(wps_ie
);
1129 os_memcpy(wpa_ie
, wpabuf_head(wps_ie
), wpa_ie_len
);
1132 wpabuf_free(wps_ie
);
1133 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
1134 #endif /* CONFIG_WPS */
1136 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
1140 wpa_clear_keys(wpa_s
, bss
? bss
->bssid
: NULL
);
1142 cipher_pairwise
= cipher_suite2driver(wpa_s
->pairwise_cipher
);
1143 cipher_group
= cipher_suite2driver(wpa_s
->group_cipher
);
1144 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
||
1145 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1146 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
)
1148 if (wpa_set_wep_keys(wpa_s
, ssid
)) {
1153 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
)
1156 #ifdef IEEE8021X_EAPOL
1157 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1158 if ((ssid
->eapol_flags
&
1159 (EAPOL_FLAG_REQUIRE_KEY_UNICAST
|
1160 EAPOL_FLAG_REQUIRE_KEY_BROADCAST
)) == 0 &&
1164 /* Assume that dynamic WEP-104 keys will be used and
1165 * set cipher suites in order for drivers to expect
1167 cipher_pairwise
= cipher_group
= CIPHER_WEP104
;
1170 #endif /* IEEE8021X_EAPOL */
1172 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1173 /* Set the key before (and later after) association */
1174 wpa_supplicant_set_wpa_none_key(wpa_s
, ssid
);
1177 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATING
);
1178 os_memset(¶ms
, 0, sizeof(params
));
1180 params
.bssid
= bss
->bssid
;
1181 params
.ssid
= bss
->ssid
;
1182 params
.ssid_len
= bss
->ssid_len
;
1183 params
.freq
= bss
->freq
;
1185 params
.ssid
= ssid
->ssid
;
1186 params
.ssid_len
= ssid
->ssid_len
;
1188 if (ssid
->mode
== WPAS_MODE_IBSS
&& ssid
->frequency
> 0 &&
1190 params
.freq
= ssid
->frequency
; /* Initial channel for IBSS */
1191 params
.wpa_ie
= wpa_ie
;
1192 params
.wpa_ie_len
= wpa_ie_len
;
1193 params
.pairwise_suite
= cipher_pairwise
;
1194 params
.group_suite
= cipher_group
;
1195 params
.key_mgmt_suite
= key_mgmt2driver(wpa_s
->key_mgmt
);
1196 params
.auth_alg
= algs
;
1197 params
.mode
= ssid
->mode
;
1198 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
1199 if (ssid
->wep_key_len
[i
])
1200 params
.wep_key
[i
] = ssid
->wep_key
[i
];
1201 params
.wep_key_len
[i
] = ssid
->wep_key_len
[i
];
1203 params
.wep_tx_keyidx
= ssid
->wep_tx_keyidx
;
1205 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) &&
1206 (params
.key_mgmt_suite
== KEY_MGMT_PSK
||
1207 params
.key_mgmt_suite
== KEY_MGMT_FT_PSK
)) {
1208 params
.passphrase
= ssid
->passphrase
;
1210 params
.psk
= ssid
->psk
;
1213 params
.drop_unencrypted
= use_crypt
;
1215 #ifdef CONFIG_IEEE80211W
1216 params
.mgmt_frame_protection
= ssid
->ieee80211w
;
1217 if (ssid
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
&& bss
) {
1218 const u8
*rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1219 struct wpa_ie_data ie
;
1220 if (rsn
&& wpa_parse_wpa_ie(rsn
, 2 + rsn
[1], &ie
) == 0 &&
1222 (WPA_CAPABILITY_MFPC
| WPA_CAPABILITY_MFPR
)) {
1223 wpa_printf(MSG_DEBUG
, "WPA: Selected AP supports MFP: "
1225 params
.mgmt_frame_protection
=
1226 MGMT_FRAME_PROTECTION_REQUIRED
;
1229 #endif /* CONFIG_IEEE80211W */
1231 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
1232 ret
= ieee80211_sta_associate(wpa_s
, ¶ms
);
1234 ret
= wpa_drv_associate(wpa_s
, ¶ms
);
1236 wpa_msg(wpa_s
, MSG_INFO
, "Association request to the driver "
1238 /* try to continue anyway; new association will be tried again
1243 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPA_NONE
) {
1244 /* Set the key after the association just in case association
1245 * cleared the previously configured key. */
1246 wpa_supplicant_set_wpa_none_key(wpa_s
, ssid
);
1247 /* No need to timeout authentication since there is no key
1249 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1250 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
1251 #ifdef CONFIG_IBSS_RSN
1252 } else if (ssid
->mode
== WPAS_MODE_IBSS
&&
1253 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
1254 wpa_s
->key_mgmt
!= WPA_KEY_MGMT_WPA_NONE
) {
1255 ibss_rsn_set_psk(wpa_s
->ibss_rsn
, ssid
->psk
);
1257 * RSN IBSS authentication is per-STA and we can disable the
1258 * per-BSSID authentication.
1260 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1261 #endif /* CONFIG_IBSS_RSN */
1263 /* Timeout for IEEE 802.11 authentication and association */
1267 /* give IBSS a bit more time */
1268 timeout
= ssid
->mode
== WPAS_MODE_IBSS
? 10 : 5;
1269 } else if (wpa_s
->conf
->ap_scan
== 1) {
1270 /* give IBSS a bit more time */
1271 timeout
= ssid
->mode
== WPAS_MODE_IBSS
? 20 : 10;
1273 wpa_supplicant_req_auth_timeout(wpa_s
, timeout
, 0);
1276 if (wep_keys_set
&& wpa_drv_get_capa(wpa_s
, &capa
) == 0 &&
1277 capa
.flags
& WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC
) {
1278 /* Set static WEP keys again */
1279 wpa_set_wep_keys(wpa_s
, ssid
);
1282 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
!= ssid
) {
1284 * Do not allow EAP session resumption between different
1285 * network configurations.
1287 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
1289 old_ssid
= wpa_s
->current_ssid
;
1290 wpa_s
->current_ssid
= ssid
;
1291 wpa_s
->current_bss
= bss
;
1292 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
1293 wpa_supplicant_initiate_eapol(wpa_s
);
1294 if (old_ssid
!= wpa_s
->current_ssid
)
1295 wpas_notify_network_changed(wpa_s
);
1300 * wpa_supplicant_disassociate - Disassociate the current connection
1301 * @wpa_s: Pointer to wpa_supplicant data
1302 * @reason_code: IEEE 802.11 reason code for the disassociate frame
1304 * This function is used to request %wpa_supplicant to disassociate with the
1307 void wpa_supplicant_disassociate(struct wpa_supplicant
*wpa_s
,
1310 struct wpa_ssid
*old_ssid
;
1313 if (!is_zero_ether_addr(wpa_s
->bssid
)) {
1314 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
1315 ieee80211_sta_disassociate(wpa_s
, reason_code
);
1317 wpa_drv_disassociate(wpa_s
, wpa_s
->bssid
, reason_code
);
1318 addr
= wpa_s
->bssid
;
1320 wpa_clear_keys(wpa_s
, addr
);
1321 wpa_supplicant_mark_disassoc(wpa_s
);
1322 old_ssid
= wpa_s
->current_ssid
;
1323 wpa_s
->current_ssid
= NULL
;
1324 wpa_s
->current_bss
= NULL
;
1325 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
1326 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
1327 if (old_ssid
!= wpa_s
->current_ssid
)
1328 wpas_notify_network_changed(wpa_s
);
1329 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
1334 * wpa_supplicant_deauthenticate - Deauthenticate the current connection
1335 * @wpa_s: Pointer to wpa_supplicant data
1336 * @reason_code: IEEE 802.11 reason code for the deauthenticate frame
1338 * This function is used to request %wpa_supplicant to deauthenticate from the
1341 void wpa_supplicant_deauthenticate(struct wpa_supplicant
*wpa_s
,
1344 struct wpa_ssid
*old_ssid
;
1347 if (!is_zero_ether_addr(wpa_s
->bssid
)) {
1348 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
1349 ieee80211_sta_deauthenticate(wpa_s
, reason_code
);
1351 wpa_drv_deauthenticate(wpa_s
, wpa_s
->bssid
,
1353 addr
= wpa_s
->bssid
;
1355 wpa_clear_keys(wpa_s
, addr
);
1356 wpa_supplicant_mark_disassoc(wpa_s
);
1357 old_ssid
= wpa_s
->current_ssid
;
1358 wpa_s
->current_ssid
= NULL
;
1359 wpa_s
->current_bss
= NULL
;
1360 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
1361 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
1362 if (old_ssid
!= wpa_s
->current_ssid
)
1363 wpas_notify_network_changed(wpa_s
);
1364 eloop_cancel_timeout(wpa_supplicant_timeout
, wpa_s
, NULL
);
1369 * wpa_supplicant_enable_network - Mark a configured network as enabled
1370 * @wpa_s: wpa_supplicant structure for a network interface
1371 * @ssid: wpa_ssid structure for a configured network or %NULL
1373 * Enables the specified network or all networks if no network specified.
1375 void wpa_supplicant_enable_network(struct wpa_supplicant
*wpa_s
,
1376 struct wpa_ssid
*ssid
)
1378 struct wpa_ssid
*other_ssid
;
1382 other_ssid
= wpa_s
->conf
->ssid
;
1383 while (other_ssid
) {
1384 if (other_ssid
== wpa_s
->current_ssid
&&
1385 other_ssid
->disabled
)
1386 wpa_s
->reassociate
= 1;
1388 was_disabled
= other_ssid
->disabled
;
1390 other_ssid
->disabled
= 0;
1392 if (was_disabled
!= other_ssid
->disabled
)
1393 wpas_notify_network_enabled_changed(
1396 other_ssid
= other_ssid
->next
;
1398 if (wpa_s
->reassociate
)
1399 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1400 } else if (ssid
->disabled
) {
1401 if (wpa_s
->current_ssid
== NULL
) {
1403 * Try to reassociate since there is no current
1404 * configuration and a new network was made available.
1406 wpa_s
->reassociate
= 1;
1407 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1410 was_disabled
= ssid
->disabled
;
1414 if (was_disabled
!= ssid
->disabled
)
1415 wpas_notify_network_enabled_changed(wpa_s
, ssid
);
1421 * wpa_supplicant_disable_network - Mark a configured network as disabled
1422 * @wpa_s: wpa_supplicant structure for a network interface
1423 * @ssid: wpa_ssid structure for a configured network or %NULL
1425 * Disables the specified network or all networks if no network specified.
1427 void wpa_supplicant_disable_network(struct wpa_supplicant
*wpa_s
,
1428 struct wpa_ssid
*ssid
)
1430 struct wpa_ssid
*other_ssid
;
1434 other_ssid
= wpa_s
->conf
->ssid
;
1435 while (other_ssid
) {
1436 was_disabled
= other_ssid
->disabled
;
1438 other_ssid
->disabled
= 1;
1440 if (was_disabled
!= other_ssid
->disabled
)
1441 wpas_notify_network_enabled_changed(
1444 other_ssid
= other_ssid
->next
;
1446 if (wpa_s
->current_ssid
)
1447 wpa_supplicant_disassociate(
1448 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1450 if (ssid
== wpa_s
->current_ssid
)
1451 wpa_supplicant_disassociate(
1452 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1454 was_disabled
= ssid
->disabled
;
1458 if (was_disabled
!= ssid
->disabled
)
1459 wpas_notify_network_enabled_changed(wpa_s
, ssid
);
1465 * wpa_supplicant_select_network - Attempt association with a network
1466 * @wpa_s: wpa_supplicant structure for a network interface
1467 * @ssid: wpa_ssid structure for a configured network or %NULL for any network
1469 void wpa_supplicant_select_network(struct wpa_supplicant
*wpa_s
,
1470 struct wpa_ssid
*ssid
)
1473 struct wpa_ssid
*other_ssid
;
1475 if (ssid
&& ssid
!= wpa_s
->current_ssid
&& wpa_s
->current_ssid
)
1476 wpa_supplicant_disassociate(
1477 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1480 * Mark all other networks disabled or mark all networks enabled if no
1481 * network specified.
1483 other_ssid
= wpa_s
->conf
->ssid
;
1484 while (other_ssid
) {
1485 int was_disabled
= other_ssid
->disabled
;
1487 other_ssid
->disabled
= ssid
? (ssid
->id
!= other_ssid
->id
) : 0;
1489 if (was_disabled
!= other_ssid
->disabled
)
1490 wpas_notify_network_enabled_changed(wpa_s
, other_ssid
);
1492 other_ssid
= other_ssid
->next
;
1494 wpa_s
->disconnected
= 0;
1495 wpa_s
->reassociate
= 1;
1496 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1499 wpas_notify_network_selected(wpa_s
, ssid
);
1504 * wpa_supplicant_set_ap_scan - Set AP scan mode for interface
1505 * @wpa_s: wpa_supplicant structure for a network interface
1506 * @ap_scan: AP scan mode
1507 * Returns: 0 if succeed or -1 if ap_scan has an invalid value
1510 int wpa_supplicant_set_ap_scan(struct wpa_supplicant
*wpa_s
, int ap_scan
)
1515 if (ap_scan
< 0 || ap_scan
> 2)
1518 old_ap_scan
= wpa_s
->conf
->ap_scan
;
1519 wpa_s
->conf
->ap_scan
= ap_scan
;
1521 if (old_ap_scan
!= wpa_s
->conf
->ap_scan
)
1522 wpas_notify_ap_scan_changed(wpa_s
);
1529 * wpa_supplicant_set_debug_params - Set global debug params
1530 * @global: wpa_global structure
1531 * @debug_level: debug level
1532 * @debug_timestamp: determines if show timestamp in debug data
1533 * @debug_show_keys: determines if show keys in debug data
1534 * Returns: 0 if succeed or -1 if debug_level has wrong value
1536 int wpa_supplicant_set_debug_params(struct wpa_global
*global
, int debug_level
,
1537 int debug_timestamp
, int debug_show_keys
)
1540 int old_level
, old_timestamp
, old_show_keys
;
1542 /* check for allowed debuglevels */
1543 if (debug_level
!= MSG_MSGDUMP
&&
1544 debug_level
!= MSG_DEBUG
&&
1545 debug_level
!= MSG_INFO
&&
1546 debug_level
!= MSG_WARNING
&&
1547 debug_level
!= MSG_ERROR
)
1550 old_level
= wpa_debug_level
;
1551 old_timestamp
= wpa_debug_timestamp
;
1552 old_show_keys
= wpa_debug_show_keys
;
1554 wpa_debug_level
= debug_level
;
1555 wpa_debug_timestamp
= debug_timestamp
? 1 : 0;
1556 wpa_debug_show_keys
= debug_show_keys
? 1 : 0;
1558 if (wpa_debug_level
!= old_level
)
1559 wpas_notify_debug_level_changed(global
);
1560 if (wpa_debug_timestamp
!= old_timestamp
)
1561 wpas_notify_debug_timestamp_changed(global
);
1562 if (wpa_debug_show_keys
!= old_show_keys
)
1563 wpas_notify_debug_show_keys_changed(global
);
1570 * wpa_supplicant_get_ssid - Get a pointer to the current network structure
1571 * @wpa_s: Pointer to wpa_supplicant data
1572 * Returns: A pointer to the current network structure or %NULL on failure
1574 struct wpa_ssid
* wpa_supplicant_get_ssid(struct wpa_supplicant
*wpa_s
)
1576 struct wpa_ssid
*entry
;
1577 u8 ssid
[MAX_SSID_LEN
];
1583 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
) {
1584 if (ieee80211_sta_get_ssid(wpa_s
, ssid
, &ssid_len
)) {
1585 wpa_printf(MSG_WARNING
, "Could not read SSID from "
1590 res
= wpa_drv_get_ssid(wpa_s
, ssid
);
1592 wpa_printf(MSG_WARNING
, "Could not read SSID from "
1599 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
1600 os_memcpy(bssid
, wpa_s
->bssid
, ETH_ALEN
);
1601 else if (wpa_drv_get_bssid(wpa_s
, bssid
) < 0) {
1602 wpa_printf(MSG_WARNING
, "Could not read BSSID from driver.");
1606 wired
= wpa_s
->conf
->ap_scan
== 0 &&
1607 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
);
1609 entry
= wpa_s
->conf
->ssid
;
1611 if (!entry
->disabled
&&
1612 ((ssid_len
== entry
->ssid_len
&&
1613 os_memcmp(ssid
, entry
->ssid
, ssid_len
) == 0) || wired
) &&
1614 (!entry
->bssid_set
||
1615 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0))
1618 if (!entry
->disabled
&&
1619 (entry
->key_mgmt
& WPA_KEY_MGMT_WPS
) &&
1620 (entry
->ssid
== NULL
|| entry
->ssid_len
== 0) &&
1621 (!entry
->bssid_set
||
1622 os_memcmp(bssid
, entry
->bssid
, ETH_ALEN
) == 0))
1624 #endif /* CONFIG_WPS */
1625 entry
= entry
->next
;
1632 static int wpa_supplicant_set_driver(struct wpa_supplicant
*wpa_s
,
1642 if (wpa_drivers
[0] == NULL
) {
1643 wpa_printf(MSG_ERROR
, "No driver interfaces build into "
1649 /* default to first driver in the list */
1650 wpa_s
->driver
= wpa_drivers
[0];
1651 wpa_s
->global_drv_priv
= wpa_s
->global
->drv_priv
[0];
1655 pos
= os_strchr(name
, ',');
1659 len
= os_strlen(name
);
1660 for (i
= 0; wpa_drivers
[i
]; i
++) {
1661 if (os_strlen(wpa_drivers
[i
]->name
) == len
&&
1662 os_strncmp(name
, wpa_drivers
[i
]->name
, len
) ==
1664 wpa_s
->driver
= wpa_drivers
[i
];
1665 wpa_s
->global_drv_priv
= wpa_s
->global
->drv_priv
[i
];
1670 wpa_printf(MSG_ERROR
, "Unsupported driver '%s'.", name
);
1676 * wpa_supplicant_rx_eapol - Deliver a received EAPOL frame to wpa_supplicant
1677 * @ctx: Context pointer (wpa_s); this is the ctx variable registered
1678 * with struct wpa_driver_ops::init()
1679 * @src_addr: Source address of the EAPOL frame
1680 * @buf: EAPOL data starting from the EAPOL header (i.e., no Ethernet header)
1681 * @len: Length of the EAPOL data
1683 * This function is called for each received EAPOL frame. Most driver
1684 * interfaces rely on more generic OS mechanism for receiving frames through
1685 * l2_packet, but if such a mechanism is not available, the driver wrapper may
1686 * take care of received EAPOL frames and deliver them to the core supplicant
1687 * code by calling this function.
1689 void wpa_supplicant_rx_eapol(void *ctx
, const u8
*src_addr
,
1690 const u8
*buf
, size_t len
)
1692 struct wpa_supplicant
*wpa_s
= ctx
;
1694 wpa_printf(MSG_DEBUG
, "RX EAPOL from " MACSTR
, MAC2STR(src_addr
));
1695 wpa_hexdump(MSG_MSGDUMP
, "RX EAPOL", buf
, len
);
1697 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
) {
1699 * There is possible race condition between receiving the
1700 * association event and the EAPOL frame since they are coming
1701 * through different paths from the driver. In order to avoid
1702 * issues in trying to process the EAPOL frame before receiving
1703 * association information, lets queue it for processing until
1704 * the association event is received.
1706 wpa_printf(MSG_DEBUG
, "Not associated - Delay processing of "
1707 "received EAPOL frame");
1708 wpabuf_free(wpa_s
->pending_eapol_rx
);
1709 wpa_s
->pending_eapol_rx
= wpabuf_alloc_copy(buf
, len
);
1710 if (wpa_s
->pending_eapol_rx
) {
1711 os_get_time(&wpa_s
->pending_eapol_rx_time
);
1712 os_memcpy(wpa_s
->pending_eapol_rx_src
, src_addr
,
1719 if (wpa_s
->ap_iface
) {
1720 wpa_supplicant_ap_rx_eapol(wpa_s
, src_addr
, buf
, len
);
1723 #endif /* CONFIG_AP */
1725 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_NONE
) {
1726 wpa_printf(MSG_DEBUG
, "Ignored received EAPOL frame since "
1727 "no key management is configured");
1731 if (wpa_s
->eapol_received
== 0 &&
1732 (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
) ||
1733 !wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) ||
1734 wpa_s
->wpa_state
!= WPA_COMPLETED
) &&
1735 (wpa_s
->current_ssid
== NULL
||
1736 wpa_s
->current_ssid
->mode
!= IEEE80211_MODE_IBSS
)) {
1737 /* Timeout for completing IEEE 802.1X and WPA authentication */
1738 wpa_supplicant_req_auth_timeout(
1740 (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
1741 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
||
1742 wpa_s
->key_mgmt
== WPA_KEY_MGMT_WPS
) ?
1745 wpa_s
->eapol_received
++;
1747 if (wpa_s
->countermeasures
) {
1748 wpa_printf(MSG_INFO
, "WPA: Countermeasures - dropped EAPOL "
1753 #ifdef CONFIG_IBSS_RSN
1754 if (wpa_s
->current_ssid
&&
1755 wpa_s
->current_ssid
->mode
== WPAS_MODE_IBSS
) {
1756 ibss_rsn_rx_eapol(wpa_s
->ibss_rsn
, src_addr
, buf
, len
);
1759 #endif /* CONFIG_IBSS_RSN */
1761 /* Source address of the incoming EAPOL frame could be compared to the
1762 * current BSSID. However, it is possible that a centralized
1763 * Authenticator could be using another MAC address than the BSSID of
1764 * an AP, so just allow any address to be used for now. The replies are
1765 * still sent to the current BSSID (if available), though. */
1767 os_memcpy(wpa_s
->last_eapol_src
, src_addr
, ETH_ALEN
);
1768 if (!wpa_key_mgmt_wpa_psk(wpa_s
->key_mgmt
) &&
1769 eapol_sm_rx_eapol(wpa_s
->eapol
, src_addr
, buf
, len
) > 0)
1771 wpa_drv_poll(wpa_s
);
1772 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
))
1773 wpa_sm_rx_eapol(wpa_s
->wpa
, src_addr
, buf
, len
);
1774 else if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1776 * Set portValid = TRUE here since we are going to skip 4-way
1777 * handshake processing which would normally set portValid. We
1778 * need this to allow the EAPOL state machines to be completed
1779 * without going through EAPOL-Key handshake.
1781 eapol_sm_notify_portValid(wpa_s
->eapol
, TRUE
);
1787 * wpa_supplicant_driver_init - Initialize driver interface parameters
1788 * @wpa_s: Pointer to wpa_supplicant data
1789 * Returns: 0 on success, -1 on failure
1791 * This function is called to initialize driver interface parameters.
1792 * wpa_drv_init() must have been called before this function to initialize the
1795 int wpa_supplicant_driver_init(struct wpa_supplicant
*wpa_s
)
1797 static int interface_count
= 0;
1799 if (wpa_s
->driver
->send_eapol
) {
1800 const u8
*addr
= wpa_drv_get_mac_addr(wpa_s
);
1802 os_memcpy(wpa_s
->own_addr
, addr
, ETH_ALEN
);
1804 wpa_s
->l2
= l2_packet_init(wpa_s
->ifname
,
1805 wpa_drv_get_mac_addr(wpa_s
),
1807 wpa_supplicant_rx_eapol
, wpa_s
, 0);
1808 if (wpa_s
->l2
== NULL
)
1812 if (wpa_s
->l2
&& l2_packet_get_own_addr(wpa_s
->l2
, wpa_s
->own_addr
)) {
1813 wpa_printf(MSG_ERROR
, "Failed to get own L2 address");
1817 wpa_printf(MSG_DEBUG
, "Own MAC address: " MACSTR
,
1818 MAC2STR(wpa_s
->own_addr
));
1820 if (wpa_s
->bridge_ifname
[0]) {
1821 wpa_printf(MSG_DEBUG
, "Receiving packets from bridge interface"
1822 " '%s'", wpa_s
->bridge_ifname
);
1823 wpa_s
->l2_br
= l2_packet_init(wpa_s
->bridge_ifname
,
1826 wpa_supplicant_rx_eapol
, wpa_s
,
1828 if (wpa_s
->l2_br
== NULL
) {
1829 wpa_printf(MSG_ERROR
, "Failed to open l2_packet "
1830 "connection for the bridge interface '%s'",
1831 wpa_s
->bridge_ifname
);
1836 wpa_clear_keys(wpa_s
, NULL
);
1838 /* Make sure that TKIP countermeasures are not left enabled (could
1839 * happen if wpa_supplicant is killed during countermeasures. */
1840 wpa_drv_set_countermeasures(wpa_s
, 0);
1842 wpa_printf(MSG_DEBUG
, "RSN: flushing PMKID list in the driver");
1843 wpa_drv_flush_pmkid(wpa_s
);
1845 wpa_s
->prev_scan_ssid
= WILDCARD_SSID_SCAN
;
1846 if (wpa_supplicant_enabled_networks(wpa_s
->conf
)) {
1847 wpa_supplicant_req_scan(wpa_s
, interface_count
, 100000);
1850 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
1856 static int wpa_supplicant_daemon(const char *pid_file
)
1858 wpa_printf(MSG_DEBUG
, "Daemonize..");
1859 return os_daemonize(pid_file
);
1863 static struct wpa_supplicant
* wpa_supplicant_alloc(void)
1865 struct wpa_supplicant
*wpa_s
;
1867 wpa_s
= os_zalloc(sizeof(*wpa_s
));
1870 wpa_s
->scan_req
= 1;
1871 wpa_s
->new_connection
= 1;
1877 static int wpa_supplicant_init_iface(struct wpa_supplicant
*wpa_s
,
1878 struct wpa_interface
*iface
)
1880 const char *ifname
, *driver
;
1881 struct wpa_driver_capa capa
;
1883 wpa_printf(MSG_DEBUG
, "Initializing interface '%s' conf '%s' driver "
1884 "'%s' ctrl_interface '%s' bridge '%s'", iface
->ifname
,
1885 iface
->confname
? iface
->confname
: "N/A",
1886 iface
->driver
? iface
->driver
: "default",
1887 iface
->ctrl_interface
? iface
->ctrl_interface
: "N/A",
1888 iface
->bridge_ifname
? iface
->bridge_ifname
: "N/A");
1890 if (iface
->confname
) {
1891 #ifdef CONFIG_BACKEND_FILE
1892 wpa_s
->confname
= os_rel2abs_path(iface
->confname
);
1893 if (wpa_s
->confname
== NULL
) {
1894 wpa_printf(MSG_ERROR
, "Failed to get absolute path "
1895 "for configuration file '%s'.",
1899 wpa_printf(MSG_DEBUG
, "Configuration file '%s' -> '%s'",
1900 iface
->confname
, wpa_s
->confname
);
1901 #else /* CONFIG_BACKEND_FILE */
1902 wpa_s
->confname
= os_strdup(iface
->confname
);
1903 #endif /* CONFIG_BACKEND_FILE */
1904 wpa_s
->conf
= wpa_config_read(wpa_s
->confname
);
1905 if (wpa_s
->conf
== NULL
) {
1906 wpa_printf(MSG_ERROR
, "Failed to read or parse "
1907 "configuration '%s'.", wpa_s
->confname
);
1912 * Override ctrl_interface and driver_param if set on command
1915 if (iface
->ctrl_interface
) {
1916 os_free(wpa_s
->conf
->ctrl_interface
);
1917 wpa_s
->conf
->ctrl_interface
=
1918 os_strdup(iface
->ctrl_interface
);
1921 if (iface
->driver_param
) {
1922 os_free(wpa_s
->conf
->driver_param
);
1923 wpa_s
->conf
->driver_param
=
1924 os_strdup(iface
->driver_param
);
1927 wpa_s
->conf
= wpa_config_alloc_empty(iface
->ctrl_interface
,
1928 iface
->driver_param
);
1930 if (wpa_s
->conf
== NULL
) {
1931 wpa_printf(MSG_ERROR
, "\nNo configuration found.");
1935 if (iface
->ifname
== NULL
) {
1936 wpa_printf(MSG_ERROR
, "\nInterface name is required.");
1939 if (os_strlen(iface
->ifname
) >= sizeof(wpa_s
->ifname
)) {
1940 wpa_printf(MSG_ERROR
, "\nToo long interface name '%s'.",
1944 os_strlcpy(wpa_s
->ifname
, iface
->ifname
, sizeof(wpa_s
->ifname
));
1946 if (iface
->bridge_ifname
) {
1947 if (os_strlen(iface
->bridge_ifname
) >=
1948 sizeof(wpa_s
->bridge_ifname
)) {
1949 wpa_printf(MSG_ERROR
, "\nToo long bridge interface "
1950 "name '%s'.", iface
->bridge_ifname
);
1953 os_strlcpy(wpa_s
->bridge_ifname
, iface
->bridge_ifname
,
1954 sizeof(wpa_s
->bridge_ifname
));
1957 /* RSNA Supplicant Key Management - INITIALIZE */
1958 eapol_sm_notify_portEnabled(wpa_s
->eapol
, FALSE
);
1959 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
1961 /* Initialize driver interface and register driver event handler before
1962 * L2 receive handler so that association events are processed before
1963 * EAPOL-Key packets if both become available for the same select()
1965 driver
= iface
->driver
;
1967 if (wpa_supplicant_set_driver(wpa_s
, driver
) < 0)
1970 wpa_s
->drv_priv
= wpa_drv_init(wpa_s
, wpa_s
->ifname
);
1971 if (wpa_s
->drv_priv
== NULL
) {
1973 pos
= driver
? os_strchr(driver
, ',') : NULL
;
1975 wpa_printf(MSG_DEBUG
, "Failed to initialize driver "
1976 "interface - try next driver wrapper");
1980 wpa_printf(MSG_ERROR
, "Failed to initialize driver interface");
1983 if (wpa_drv_set_param(wpa_s
, wpa_s
->conf
->driver_param
) < 0) {
1984 wpa_printf(MSG_ERROR
, "Driver interface rejected "
1985 "driver_param '%s'", wpa_s
->conf
->driver_param
);
1989 ifname
= wpa_drv_get_ifname(wpa_s
);
1990 if (ifname
&& os_strcmp(ifname
, wpa_s
->ifname
) != 0) {
1991 wpa_printf(MSG_DEBUG
, "Driver interface replaced interface "
1992 "name with '%s'", ifname
);
1993 os_strlcpy(wpa_s
->ifname
, ifname
, sizeof(wpa_s
->ifname
));
1996 if (wpa_supplicant_init_wpa(wpa_s
) < 0)
1999 wpa_sm_set_ifname(wpa_s
->wpa
, wpa_s
->ifname
,
2000 wpa_s
->bridge_ifname
[0] ? wpa_s
->bridge_ifname
:
2002 wpa_sm_set_fast_reauth(wpa_s
->wpa
, wpa_s
->conf
->fast_reauth
);
2004 if (wpa_s
->conf
->dot11RSNAConfigPMKLifetime
&&
2005 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
2006 wpa_s
->conf
->dot11RSNAConfigPMKLifetime
)) {
2007 wpa_printf(MSG_ERROR
, "Invalid WPA parameter value for "
2008 "dot11RSNAConfigPMKLifetime");
2012 if (wpa_s
->conf
->dot11RSNAConfigPMKReauthThreshold
&&
2013 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
2014 wpa_s
->conf
->dot11RSNAConfigPMKReauthThreshold
)) {
2015 wpa_printf(MSG_ERROR
, "Invalid WPA parameter value for "
2016 "dot11RSNAConfigPMKReauthThreshold");
2020 if (wpa_s
->conf
->dot11RSNAConfigSATimeout
&&
2021 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
,
2022 wpa_s
->conf
->dot11RSNAConfigSATimeout
)) {
2023 wpa_printf(MSG_ERROR
, "Invalid WPA parameter value for "
2024 "dot11RSNAConfigSATimeout");
2028 if (wpa_drv_get_capa(wpa_s
, &capa
) == 0) {
2029 wpa_s
->drv_flags
= capa
.flags
;
2030 if (capa
.flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
) {
2031 if (ieee80211_sta_init(wpa_s
))
2034 wpa_s
->max_scan_ssids
= capa
.max_scan_ssids
;
2035 wpa_s
->max_remain_on_chan
= capa
.max_remain_on_chan
;
2037 if (wpa_s
->max_remain_on_chan
== 0)
2038 wpa_s
->max_remain_on_chan
= 1000;
2040 if (wpa_supplicant_driver_init(wpa_s
) < 0)
2043 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1] &&
2044 wpa_drv_set_country(wpa_s
, wpa_s
->conf
->country
)) {
2045 wpa_printf(MSG_DEBUG
, "Failed to set country");
2049 wpa_sm_set_own_addr(wpa_s
->wpa
, wpa_s
->own_addr
);
2051 if (wpas_wps_init(wpa_s
))
2054 if (wpa_supplicant_init_eapol(wpa_s
) < 0)
2056 wpa_sm_set_eapol(wpa_s
->wpa
, wpa_s
->eapol
);
2058 wpa_s
->ctrl_iface
= wpa_supplicant_ctrl_iface_init(wpa_s
);
2059 if (wpa_s
->ctrl_iface
== NULL
) {
2060 wpa_printf(MSG_ERROR
,
2061 "Failed to initialize control interface '%s'.\n"
2062 "You may have another wpa_supplicant process "
2063 "already running or the file was\n"
2064 "left by an unclean termination of wpa_supplicant "
2065 "in which case you will need\n"
2066 "to manually remove this file before starting "
2067 "wpa_supplicant again.\n",
2068 wpa_s
->conf
->ctrl_interface
);
2072 #ifdef CONFIG_IBSS_RSN
2073 wpa_s
->ibss_rsn
= ibss_rsn_init(wpa_s
);
2074 if (!wpa_s
->ibss_rsn
) {
2075 wpa_printf(MSG_DEBUG
, "Failed to init IBSS RSN");
2078 #endif /* CONFIG_IBSS_RSN */
2080 if (wpa_bss_init(wpa_s
) < 0)
2087 static void wpa_supplicant_deinit_iface(struct wpa_supplicant
*wpa_s
,
2090 if (wpa_s
->drv_priv
) {
2091 wpa_supplicant_deauthenticate(wpa_s
,
2092 WLAN_REASON_DEAUTH_LEAVING
);
2094 wpa_drv_set_countermeasures(wpa_s
, 0);
2095 wpa_clear_keys(wpa_s
, NULL
);
2098 wpa_supplicant_cleanup(wpa_s
);
2101 wpas_notify_iface_removed(wpa_s
);
2103 if (wpa_s
->drv_priv
)
2104 wpa_drv_deinit(wpa_s
);
2109 * wpa_supplicant_add_iface - Add a new network interface
2110 * @global: Pointer to global data from wpa_supplicant_init()
2111 * @iface: Interface configuration options
2112 * Returns: Pointer to the created interface or %NULL on failure
2114 * This function is used to add new network interfaces for %wpa_supplicant.
2115 * This can be called before wpa_supplicant_run() to add interfaces before the
2116 * main event loop has been started. In addition, new interfaces can be added
2117 * dynamically while %wpa_supplicant is already running. This could happen,
2118 * e.g., when a hotplug network adapter is inserted.
2120 struct wpa_supplicant
* wpa_supplicant_add_iface(struct wpa_global
*global
,
2121 struct wpa_interface
*iface
)
2123 struct wpa_supplicant
*wpa_s
;
2124 struct wpa_interface t_iface
;
2125 struct wpa_ssid
*ssid
;
2127 if (global
== NULL
|| iface
== NULL
)
2130 wpa_s
= wpa_supplicant_alloc();
2134 wpa_s
->global
= global
;
2137 if (global
->params
.override_driver
) {
2138 wpa_printf(MSG_DEBUG
, "Override interface parameter: driver "
2140 iface
->driver
, global
->params
.override_driver
);
2141 t_iface
.driver
= global
->params
.override_driver
;
2143 if (global
->params
.override_ctrl_interface
) {
2144 wpa_printf(MSG_DEBUG
, "Override interface parameter: "
2145 "ctrl_interface ('%s' -> '%s')",
2146 iface
->ctrl_interface
,
2147 global
->params
.override_ctrl_interface
);
2148 t_iface
.ctrl_interface
=
2149 global
->params
.override_ctrl_interface
;
2151 if (wpa_supplicant_init_iface(wpa_s
, &t_iface
)) {
2152 wpa_printf(MSG_DEBUG
, "Failed to add interface %s",
2154 wpa_supplicant_deinit_iface(wpa_s
, 0);
2159 /* Notify the control interfaces about new iface */
2160 if (wpas_notify_iface_added(wpa_s
)) {
2161 wpa_supplicant_deinit_iface(wpa_s
, 1);
2166 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
)
2167 wpas_notify_network_added(wpa_s
, ssid
);
2169 wpa_s
->next
= global
->ifaces
;
2170 global
->ifaces
= wpa_s
;
2172 wpa_printf(MSG_DEBUG
, "Added interface %s", wpa_s
->ifname
);
2179 * wpa_supplicant_remove_iface - Remove a network interface
2180 * @global: Pointer to global data from wpa_supplicant_init()
2181 * @wpa_s: Pointer to the network interface to be removed
2182 * Returns: 0 if interface was removed, -1 if interface was not found
2184 * This function can be used to dynamically remove network interfaces from
2185 * %wpa_supplicant, e.g., when a hotplug network adapter is ejected. In
2186 * addition, this function is used to remove all remaining interfaces when
2187 * %wpa_supplicant is terminated.
2189 int wpa_supplicant_remove_iface(struct wpa_global
*global
,
2190 struct wpa_supplicant
*wpa_s
)
2192 struct wpa_supplicant
*prev
;
2194 /* Remove interface from the global list of interfaces */
2195 prev
= global
->ifaces
;
2196 if (prev
== wpa_s
) {
2197 global
->ifaces
= wpa_s
->next
;
2199 while (prev
&& prev
->next
!= wpa_s
)
2203 prev
->next
= wpa_s
->next
;
2206 wpa_printf(MSG_DEBUG
, "Removing interface %s", wpa_s
->ifname
);
2208 wpa_supplicant_deinit_iface(wpa_s
, 1);
2216 * wpa_supplicant_get_iface - Get a new network interface
2217 * @global: Pointer to global data from wpa_supplicant_init()
2218 * @ifname: Interface name
2219 * Returns: Pointer to the interface or %NULL if not found
2221 struct wpa_supplicant
* wpa_supplicant_get_iface(struct wpa_global
*global
,
2224 struct wpa_supplicant
*wpa_s
;
2226 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2227 if (os_strcmp(wpa_s
->ifname
, ifname
) == 0)
2235 * wpa_supplicant_init - Initialize %wpa_supplicant
2236 * @params: Parameters for %wpa_supplicant
2237 * Returns: Pointer to global %wpa_supplicant data, or %NULL on failure
2239 * This function is used to initialize %wpa_supplicant. After successful
2240 * initialization, the returned data pointer can be used to add and remove
2241 * network interfaces, and eventually, to deinitialize %wpa_supplicant.
2243 struct wpa_global
* wpa_supplicant_init(struct wpa_params
*params
)
2245 struct wpa_global
*global
;
2251 wpa_debug_open_file(params
->wpa_debug_file_path
);
2252 if (params
->wpa_debug_syslog
)
2253 wpa_debug_open_syslog();
2255 ret
= eap_register_methods();
2257 wpa_printf(MSG_ERROR
, "Failed to register EAP methods");
2259 wpa_printf(MSG_ERROR
, "Two or more EAP methods used "
2260 "the same EAP type.");
2264 global
= os_zalloc(sizeof(*global
));
2267 global
->params
.daemonize
= params
->daemonize
;
2268 global
->params
.wait_for_monitor
= params
->wait_for_monitor
;
2269 global
->params
.dbus_ctrl_interface
= params
->dbus_ctrl_interface
;
2270 if (params
->pid_file
)
2271 global
->params
.pid_file
= os_strdup(params
->pid_file
);
2272 if (params
->ctrl_interface
)
2273 global
->params
.ctrl_interface
=
2274 os_strdup(params
->ctrl_interface
);
2275 if (params
->override_driver
)
2276 global
->params
.override_driver
=
2277 os_strdup(params
->override_driver
);
2278 if (params
->override_ctrl_interface
)
2279 global
->params
.override_ctrl_interface
=
2280 os_strdup(params
->override_ctrl_interface
);
2281 wpa_debug_level
= global
->params
.wpa_debug_level
=
2282 params
->wpa_debug_level
;
2283 wpa_debug_show_keys
= global
->params
.wpa_debug_show_keys
=
2284 params
->wpa_debug_show_keys
;
2285 wpa_debug_timestamp
= global
->params
.wpa_debug_timestamp
=
2286 params
->wpa_debug_timestamp
;
2289 wpa_printf(MSG_ERROR
, "Failed to initialize event loop");
2290 wpa_supplicant_deinit(global
);
2294 global
->ctrl_iface
= wpa_supplicant_global_ctrl_iface_init(global
);
2295 if (global
->ctrl_iface
== NULL
) {
2296 wpa_supplicant_deinit(global
);
2300 if (wpas_notify_supplicant_initialized(global
)) {
2301 wpa_supplicant_deinit(global
);
2305 for (i
= 0; wpa_drivers
[i
]; i
++)
2306 global
->drv_count
++;
2307 if (global
->drv_count
== 0) {
2308 wpa_printf(MSG_ERROR
, "No drivers enabled");
2309 wpa_supplicant_deinit(global
);
2312 global
->drv_priv
= os_zalloc(global
->drv_count
* sizeof(void *));
2313 if (global
->drv_priv
== NULL
) {
2314 wpa_supplicant_deinit(global
);
2317 for (i
= 0; wpa_drivers
[i
]; i
++) {
2318 if (!wpa_drivers
[i
]->global_init
)
2320 global
->drv_priv
[i
] = wpa_drivers
[i
]->global_init();
2321 if (global
->drv_priv
[i
] == NULL
) {
2322 wpa_printf(MSG_ERROR
, "Failed to initialize driver "
2323 "'%s'", wpa_drivers
[i
]->name
);
2324 wpa_supplicant_deinit(global
);
2334 * wpa_supplicant_run - Run the %wpa_supplicant main event loop
2335 * @global: Pointer to global data from wpa_supplicant_init()
2336 * Returns: 0 after successful event loop run, -1 on failure
2338 * This function starts the main event loop and continues running as long as
2339 * there are any remaining events. In most cases, this function is running as
2340 * long as the %wpa_supplicant process in still in use.
2342 int wpa_supplicant_run(struct wpa_global
*global
)
2344 struct wpa_supplicant
*wpa_s
;
2346 if (global
->params
.daemonize
&&
2347 wpa_supplicant_daemon(global
->params
.pid_file
))
2350 if (global
->params
.wait_for_monitor
) {
2351 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
)
2352 if (wpa_s
->ctrl_iface
)
2353 wpa_supplicant_ctrl_iface_wait(
2357 eloop_register_signal_terminate(wpa_supplicant_terminate
, global
);
2358 eloop_register_signal_reconfig(wpa_supplicant_reconfig
, global
);
2367 * wpa_supplicant_deinit - Deinitialize %wpa_supplicant
2368 * @global: Pointer to global data from wpa_supplicant_init()
2370 * This function is called to deinitialize %wpa_supplicant and to free all
2371 * allocated resources. Remaining network interfaces will also be removed.
2373 void wpa_supplicant_deinit(struct wpa_global
*global
)
2380 while (global
->ifaces
)
2381 wpa_supplicant_remove_iface(global
, global
->ifaces
);
2383 if (global
->ctrl_iface
)
2384 wpa_supplicant_global_ctrl_iface_deinit(global
->ctrl_iface
);
2386 wpas_notify_supplicant_deinitialized(global
);
2388 eap_peer_unregister_methods();
2390 eap_server_unregister_methods();
2391 #endif /* CONFIG_AP */
2393 for (i
= 0; wpa_drivers
[i
] && global
->drv_priv
; i
++) {
2394 if (!global
->drv_priv
[i
])
2396 wpa_drivers
[i
]->global_deinit(global
->drv_priv
[i
]);
2398 os_free(global
->drv_priv
);
2402 if (global
->params
.pid_file
) {
2403 os_daemonize_terminate(global
->params
.pid_file
);
2404 os_free(global
->params
.pid_file
);
2406 os_free(global
->params
.ctrl_interface
);
2407 os_free(global
->params
.override_driver
);
2408 os_free(global
->params
.override_ctrl_interface
);
2411 wpa_debug_close_syslog();
2412 wpa_debug_close_file();