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 * Oct, 26th. 2011. TIZEN
193 * Add a function to check current networks is set for wps in this file
196 static int wpas_wps_in_use_wpasupplicant(struct wpa_config *conf)
198 struct wpa_ssid *ssid;
201 for (ssid = conf->ssid; ssid; ssid = ssid->next) {
202 if (!(ssid->key_mgmt & WPA_KEY_MGMT_WPS))
207 if (!ssid->eap.phase1)
210 if (os_strstr(ssid->eap.phase1, "pbc=1"))
216 #endif /* CONFIG_WPS */
218 static void wpa_supplicant_timeout(void *eloop_ctx, void *timeout_ctx)
221 * Oct, 26th. 2011. TIZEN
222 * A wps variable is added for check enabled networks is set for WPS
225 struct wpa_supplicant *wpa_s = eloop_ctx;
227 * Oct, 26th. 2011. TIZEN
228 * A wps variable is added for check enabled networks is set for WPS
230 struct wpa_ssid *start = wpa_s->conf->ssid;
231 const u8 *bssid = wpa_s->bssid;
232 if (is_zero_ether_addr(bssid))
233 bssid = wpa_s->pending_bssid;
234 wpa_msg(wpa_s, MSG_INFO, "Authentication with " MACSTR " timed out.",
236 wpa_blacklist_add(wpa_s, bssid);
237 wpa_sm_notify_disassoc(wpa_s->wpa);
238 wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
241 * Oct, 26th. 2011. TIZEN
242 * WPS check routine is added due to our changes's side effect
244 wps = wpas_wps_in_use_wpasupplicant(wpa_s->conf);
249 * September, 29th 2011. TIZEN
251 * Change reassociate to 0 and add disconnect 1
254 wpa_msg(wpa_s,MSG_INFO, "wpa_s->reassociate %d, wpa_s->associate_num %d",wpa_s->reassociate ,wpa_s->associate_num);
255 if(wpa_s->disconnected == 0)
257 if(wpa_s->associate_num < 2)
259 if(wpa_s->associate_num == 1)
263 start->scan_ssid = 0;
267 wpa_s->reassociate = 1;
268 wpa_s->associate_num++;
269 wpa_supplicant_req_scan(wpa_s, 0, 0);
274 wpa_s->reassociate = 0;
275 wpa_s->disconnected = 1;
279 start->scan_ssid = 0;
284 wpa_printf(MSG_DEBUG,"===============================");
285 wpa_printf(MSG_DEBUG,"Scan request after timeout");
286 wpa_printf(MSG_DEBUG,"===============================");
287 wpa_supplicant_req_scan(wpa_s, 0, 0);
292 * wpa_supplicant_req_auth_timeout - Schedule a timeout for authentication
293 * @wpa_s: Pointer to wpa_supplicant data
294 * @sec: Number of seconds after which to time out authentication
295 * @usec: Number of microseconds after which to time out authentication
297 * This function is used to schedule a timeout for the current authentication
300 void wpa_supplicant_req_auth_timeout(struct wpa_supplicant *wpa_s,
303 if (wpa_s->conf && wpa_s->conf->ap_scan == 0 &&
304 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED))
307 wpa_msg(wpa_s, MSG_DEBUG, "Setting authentication timeout: %d sec "
308 "%d usec", sec, usec);
309 eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL);
310 eloop_register_timeout(sec, usec, wpa_supplicant_timeout, wpa_s, NULL);
315 * wpa_supplicant_cancel_auth_timeout - Cancel authentication timeout
316 * @wpa_s: Pointer to wpa_supplicant data
318 * This function is used to cancel authentication timeout scheduled with
319 * wpa_supplicant_req_auth_timeout() and it is called when authentication has
322 void wpa_supplicant_cancel_auth_timeout(struct wpa_supplicant *wpa_s)
324 wpa_msg(wpa_s, MSG_DEBUG, "Cancelling authentication timeout");
325 eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL);
326 wpa_blacklist_del(wpa_s, wpa_s->bssid);
331 * wpa_supplicant_initiate_eapol - Configure EAPOL state machine
332 * @wpa_s: Pointer to wpa_supplicant data
334 * This function is used to configure EAPOL state machine based on the selected
335 * authentication mode.
337 void wpa_supplicant_initiate_eapol(struct wpa_supplicant *wpa_s)
339 #ifdef IEEE8021X_EAPOL
340 struct eapol_config eapol_conf;
341 struct wpa_ssid *ssid = wpa_s->current_ssid;
343 #ifdef CONFIG_IBSS_RSN
344 if (ssid->mode == WPAS_MODE_IBSS &&
345 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
346 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE) {
348 * RSN IBSS authentication is per-STA and we can disable the
349 * per-BSSID EAPOL authentication.
351 eapol_sm_notify_portControl(wpa_s->eapol, ForceAuthorized);
352 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
353 eapol_sm_notify_eap_fail(wpa_s->eapol, FALSE);
356 #endif /* CONFIG_IBSS_RSN */
358 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
359 eapol_sm_notify_eap_fail(wpa_s->eapol, FALSE);
361 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
362 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
363 eapol_sm_notify_portControl(wpa_s->eapol, ForceAuthorized);
365 eapol_sm_notify_portControl(wpa_s->eapol, Auto);
367 os_memset(&eapol_conf, 0, sizeof(eapol_conf));
368 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
369 eapol_conf.accept_802_1x_keys = 1;
370 eapol_conf.required_keys = 0;
371 if (ssid->eapol_flags & EAPOL_FLAG_REQUIRE_KEY_UNICAST) {
372 eapol_conf.required_keys |= EAPOL_REQUIRE_KEY_UNICAST;
374 if (ssid->eapol_flags & EAPOL_FLAG_REQUIRE_KEY_BROADCAST) {
375 eapol_conf.required_keys |=
376 EAPOL_REQUIRE_KEY_BROADCAST;
379 if (wpa_s->conf && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED))
380 eapol_conf.required_keys = 0;
383 eapol_conf.fast_reauth = wpa_s->conf->fast_reauth;
384 eapol_conf.workaround = ssid->eap_workaround;
385 eapol_conf.eap_disabled =
386 !wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) &&
387 wpa_s->key_mgmt != WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
388 wpa_s->key_mgmt != WPA_KEY_MGMT_WPS;
389 eapol_sm_notify_config(wpa_s->eapol, &ssid->eap, &eapol_conf);
390 #endif /* IEEE8021X_EAPOL */
395 * wpa_supplicant_set_non_wpa_policy - Set WPA parameters to non-WPA mode
396 * @wpa_s: Pointer to wpa_supplicant data
397 * @ssid: Configuration data for the network
399 * This function is used to configure WPA state machine and related parameters
400 * to a mode where WPA is not enabled. This is called as part of the
401 * authentication configuration when the selected network does not use WPA.
403 void wpa_supplicant_set_non_wpa_policy(struct wpa_supplicant *wpa_s,
404 struct wpa_ssid *ssid)
408 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
409 wpa_s->key_mgmt = WPA_KEY_MGMT_WPS;
410 else if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)
411 wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
413 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
414 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
415 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
416 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
417 wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
418 wpa_s->group_cipher = WPA_CIPHER_NONE;
419 wpa_s->mgmt_group_cipher = 0;
421 for (i = 0; i < NUM_WEP_KEYS; i++) {
422 if (ssid->wep_key_len[i] > 5) {
423 wpa_s->pairwise_cipher = WPA_CIPHER_WEP104;
424 wpa_s->group_cipher = WPA_CIPHER_WEP104;
426 } else if (ssid->wep_key_len[i] > 0) {
427 wpa_s->pairwise_cipher = WPA_CIPHER_WEP40;
428 wpa_s->group_cipher = WPA_CIPHER_WEP40;
433 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED, 0);
434 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
435 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
436 wpa_s->pairwise_cipher);
437 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
438 #ifdef CONFIG_IEEE80211W
439 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
440 wpa_s->mgmt_group_cipher);
441 #endif /* CONFIG_IEEE80211W */
443 pmksa_cache_clear_current(wpa_s->wpa);
447 static void wpa_supplicant_cleanup(struct wpa_supplicant *wpa_s)
449 bgscan_deinit(wpa_s);
450 scard_deinit(wpa_s->scard);
452 wpa_sm_set_scard_ctx(wpa_s->wpa, NULL);
453 eapol_sm_register_scard_ctx(wpa_s->eapol, NULL);
454 l2_packet_deinit(wpa_s->l2);
457 l2_packet_deinit(wpa_s->l2_br);
461 if (wpa_s->ctrl_iface) {
462 wpa_supplicant_ctrl_iface_deinit(wpa_s->ctrl_iface);
463 wpa_s->ctrl_iface = NULL;
465 if (wpa_s->conf != NULL) {
466 struct wpa_ssid *ssid;
467 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
468 wpas_notify_network_removed(wpa_s, ssid);
469 wpa_config_free(wpa_s->conf);
473 os_free(wpa_s->confname);
474 wpa_s->confname = NULL;
476 wpa_sm_set_eapol(wpa_s->wpa, NULL);
477 eapol_sm_deinit(wpa_s->eapol);
480 rsn_preauth_deinit(wpa_s->wpa);
482 pmksa_candidate_free(wpa_s->wpa);
483 wpa_sm_deinit(wpa_s->wpa);
485 wpa_blacklist_clear(wpa_s);
487 wpa_bss_deinit(wpa_s);
489 wpa_supplicant_cancel_scan(wpa_s);
490 wpa_supplicant_cancel_auth_timeout(wpa_s);
492 ieee80211_sta_deinit(wpa_s);
494 wpas_wps_deinit(wpa_s);
496 wpabuf_free(wpa_s->pending_eapol_rx);
497 wpa_s->pending_eapol_rx = NULL;
499 #ifdef CONFIG_IBSS_RSN
500 ibss_rsn_deinit(wpa_s->ibss_rsn);
501 wpa_s->ibss_rsn = NULL;
502 #endif /* CONFIG_IBSS_RSN */
505 os_free(wpa_s->sme.ft_ies);
506 wpa_s->sme.ft_ies = NULL;
507 wpa_s->sme.ft_ies_len = 0;
508 #endif /* CONFIG_SME */
511 wpa_supplicant_ap_deinit(wpa_s);
512 #endif /* CONFIG_AP */
517 * wpa_clear_keys - Clear keys configured for the driver
518 * @wpa_s: Pointer to wpa_supplicant data
519 * @addr: Previously used BSSID or %NULL if not available
521 * This function clears the encryption keys that has been previously configured
524 void wpa_clear_keys(struct wpa_supplicant *wpa_s, const u8 *addr)
526 u8 *bcast = (u8 *) "\xff\xff\xff\xff\xff\xff";
528 if (wpa_s->keys_cleared) {
529 /* Some drivers (e.g., ndiswrapper & NDIS drivers) seem to have
530 * timing issues with keys being cleared just before new keys
531 * are set or just after association or something similar. This
532 * shows up in group key handshake failing often because of the
533 * client not receiving the first encrypted packets correctly.
534 * Skipping some of the extra key clearing steps seems to help
535 * in completing group key handshake more reliably. */
536 wpa_printf(MSG_DEBUG, "No keys have been configured - "
537 "skip key clearing");
541 /* MLME-DELETEKEYS.request */
542 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, bcast, 0, 0, NULL, 0, NULL, 0);
543 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, bcast, 1, 0, NULL, 0, NULL, 0);
544 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, bcast, 2, 0, NULL, 0, NULL, 0);
545 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, bcast, 3, 0, NULL, 0, NULL, 0);
546 #ifdef CONFIG_IEEE80211W
547 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, bcast, 4, 0, NULL, 0, NULL, 0);
548 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, bcast, 5, 0, NULL, 0, NULL, 0);
549 #endif /* CONFIG_IEEE80211W */
551 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, addr, 0, 0, NULL, 0, NULL,
553 /* MLME-SETPROTECTION.request(None) */
554 wpa_drv_mlme_setprotection(
556 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
557 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
559 wpa_s->keys_cleared = 1;
564 * wpa_supplicant_state_txt - Get the connection state name as a text string
565 * @state: State (wpa_state; WPA_*)
566 * Returns: The state name as a printable text string
568 const char * wpa_supplicant_state_txt(enum wpa_states state)
571 case WPA_DISCONNECTED:
572 return "DISCONNECTED";
577 case WPA_AUTHENTICATING:
578 return "AUTHENTICATING";
579 case WPA_ASSOCIATING:
580 return "ASSOCIATING";
583 case WPA_4WAY_HANDSHAKE:
584 return "4WAY_HANDSHAKE";
585 case WPA_GROUP_HANDSHAKE:
586 return "GROUP_HANDSHAKE";
596 * wpa_supplicant_set_state - Set current connection state
597 * @wpa_s: Pointer to wpa_supplicant data
598 * @state: The new connection state
600 * This function is called whenever the connection state changes, e.g.,
601 * association is completed for WPA/WPA2 4-Way Handshake is started.
603 void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s,
604 enum wpa_states state)
606 enum wpa_states old_state = wpa_s->wpa_state;
608 wpa_printf(MSG_DEBUG, "State: %s -> %s",
609 wpa_supplicant_state_txt(wpa_s->wpa_state),
610 wpa_supplicant_state_txt(state));
612 if (state != WPA_SCANNING)
613 wpa_supplicant_notify_scanning(wpa_s, 0);
615 if (state == WPA_COMPLETED && wpa_s->new_connection) {
616 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
617 struct wpa_ssid *ssid = wpa_s->current_ssid;
618 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED "- Connection to "
619 MACSTR " completed %s [id=%d id_str=%s]",
620 MAC2STR(wpa_s->bssid), wpa_s->reassociated_connection ?
621 "(reauth)" : "(auth)",
622 ssid ? ssid->id : -1,
623 ssid && ssid->id_str ? ssid->id_str : "");
624 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
625 wpa_s->new_connection = 0;
626 wpa_s->reassociated_connection = 1;
627 wpa_drv_set_operstate(wpa_s, 1);
628 wpa_s->after_wps = 0;
630 * Nov, 2nd. 2011. TIZEN
631 * After association is completed, scan should be set full scan.
633 if( wpa_s->conf->ssid != NULL)
635 struct wpa_ssid *start = wpa_s->conf->ssid;
638 start->scan_ssid = 0;
642 } else if (state == WPA_DISCONNECTED || state == WPA_ASSOCIATING ||
643 state == WPA_ASSOCIATED) {
644 wpa_s->new_connection = 1;
645 wpa_drv_set_operstate(wpa_s, 0);
647 wpa_s->wpa_state = state;
649 if (wpa_s->wpa_state != old_state)
650 wpas_notify_state_changed(wpa_s, wpa_s->wpa_state, old_state);
654 void wpa_supplicant_terminate_proc(struct wpa_global *global)
658 struct wpa_supplicant *wpa_s = global->ifaces;
660 if (wpas_wps_terminate_pending(wpa_s) == 1)
664 #endif /* CONFIG_WPS */
671 static void wpa_supplicant_terminate(int sig, void *signal_ctx)
673 struct wpa_global *global = signal_ctx;
674 struct wpa_supplicant *wpa_s;
675 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
676 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_TERMINATING "- signal %d "
679 wpa_supplicant_terminate_proc(global);
683 static void wpa_supplicant_clear_status(struct wpa_supplicant *wpa_s)
685 enum wpa_states old_state = wpa_s->wpa_state;
687 wpa_s->pairwise_cipher = 0;
688 wpa_s->group_cipher = 0;
689 wpa_s->mgmt_group_cipher = 0;
691 wpa_s->wpa_state = WPA_DISCONNECTED;
693 if (wpa_s->wpa_state != old_state)
694 wpas_notify_state_changed(wpa_s, wpa_s->wpa_state, old_state);
699 * wpa_supplicant_reload_configuration - Reload configuration data
700 * @wpa_s: Pointer to wpa_supplicant data
701 * Returns: 0 on success or -1 if configuration parsing failed
703 * This function can be used to request that the configuration data is reloaded
704 * (e.g., after configuration file change). This function is reloading
705 * configuration only for one interface, so this may need to be called multiple
706 * times if %wpa_supplicant is controlling multiple interfaces and all
707 * interfaces need reconfiguration.
709 int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s)
711 struct wpa_config *conf;
712 struct wpa_ssid *old_ssid;
716 if (wpa_s->confname == NULL)
718 conf = wpa_config_read(wpa_s->confname);
720 wpa_msg(wpa_s, MSG_ERROR, "Failed to parse the configuration "
721 "file '%s' - exiting", wpa_s->confname);
725 reconf_ctrl = !!conf->ctrl_interface != !!wpa_s->conf->ctrl_interface
726 || (conf->ctrl_interface && wpa_s->conf->ctrl_interface &&
727 os_strcmp(conf->ctrl_interface,
728 wpa_s->conf->ctrl_interface) != 0);
730 if (reconf_ctrl && wpa_s->ctrl_iface) {
731 wpa_supplicant_ctrl_iface_deinit(wpa_s->ctrl_iface);
732 wpa_s->ctrl_iface = NULL;
735 eapol_sm_invalidate_cached_session(wpa_s->eapol);
736 old_ssid = wpa_s->current_ssid;
737 wpa_s->current_ssid = NULL;
738 if (old_ssid != wpa_s->current_ssid)
739 wpas_notify_network_changed(wpa_s);
742 * TODO: should notify EAPOL SM about changes in opensc_engine_path,
743 * pkcs11_engine_path, pkcs11_module_path.
745 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
747 * Clear forced success to clear EAP state for next
750 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
752 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
753 wpa_sm_set_config(wpa_s->wpa, NULL);
754 wpa_sm_set_fast_reauth(wpa_s->wpa, wpa_s->conf->fast_reauth);
755 rsn_preauth_deinit(wpa_s->wpa);
757 old_ap_scan = wpa_s->conf->ap_scan;
758 wpa_config_free(wpa_s->conf);
760 if (old_ap_scan != wpa_s->conf->ap_scan)
761 wpas_notify_ap_scan_changed(wpa_s);
764 wpa_s->ctrl_iface = wpa_supplicant_ctrl_iface_init(wpa_s);
766 wpa_supplicant_clear_status(wpa_s);
767 wpa_s->reassociate = 1;
768 wpa_supplicant_req_scan(wpa_s, 0, 0);
769 wpa_msg(wpa_s, MSG_DEBUG, "Reconfiguration completed");
774 static void wpa_supplicant_reconfig(int sig, void *signal_ctx)
776 struct wpa_global *global = signal_ctx;
777 struct wpa_supplicant *wpa_s;
778 wpa_printf(MSG_DEBUG, "Signal %d received - reconfiguring", sig);
779 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
780 if (wpa_supplicant_reload_configuration(wpa_s) < 0) {
781 wpa_supplicant_terminate_proc(global);
787 enum wpa_cipher cipher_suite2driver(int cipher)
790 case WPA_CIPHER_NONE:
792 case WPA_CIPHER_WEP40:
794 case WPA_CIPHER_WEP104:
795 return CIPHER_WEP104;
796 case WPA_CIPHER_CCMP:
798 case WPA_CIPHER_TKIP:
805 enum wpa_key_mgmt key_mgmt2driver(int key_mgmt)
808 case WPA_KEY_MGMT_NONE:
809 return KEY_MGMT_NONE;
810 case WPA_KEY_MGMT_IEEE8021X_NO_WPA:
811 return KEY_MGMT_802_1X_NO_WPA;
812 case WPA_KEY_MGMT_IEEE8021X:
813 return KEY_MGMT_802_1X;
814 case WPA_KEY_MGMT_WPA_NONE:
815 return KEY_MGMT_WPA_NONE;
816 case WPA_KEY_MGMT_FT_IEEE8021X:
817 return KEY_MGMT_FT_802_1X;
818 case WPA_KEY_MGMT_FT_PSK:
819 return KEY_MGMT_FT_PSK;
820 case WPA_KEY_MGMT_IEEE8021X_SHA256:
821 return KEY_MGMT_802_1X_SHA256;
822 case WPA_KEY_MGMT_PSK_SHA256:
823 return KEY_MGMT_PSK_SHA256;
824 case WPA_KEY_MGMT_WPS:
826 case WPA_KEY_MGMT_PSK:
833 static int wpa_supplicant_suites_from_ai(struct wpa_supplicant *wpa_s,
834 struct wpa_ssid *ssid,
835 struct wpa_ie_data *ie)
837 int ret = wpa_sm_parse_own_wpa_ie(wpa_s->wpa, ie);
840 wpa_msg(wpa_s, MSG_INFO, "WPA: Failed to parse WPA IE "
841 "from association info");
846 wpa_printf(MSG_DEBUG, "WPA: Using WPA IE from AssocReq to set cipher "
848 if (!(ie->group_cipher & ssid->group_cipher)) {
849 wpa_msg(wpa_s, MSG_INFO, "WPA: Driver used disabled group "
850 "cipher 0x%x (mask 0x%x) - reject",
851 ie->group_cipher, ssid->group_cipher);
854 if (!(ie->pairwise_cipher & ssid->pairwise_cipher)) {
855 wpa_msg(wpa_s, MSG_INFO, "WPA: Driver used disabled pairwise "
856 "cipher 0x%x (mask 0x%x) - reject",
857 ie->pairwise_cipher, ssid->pairwise_cipher);
860 if (!(ie->key_mgmt & ssid->key_mgmt)) {
861 wpa_msg(wpa_s, MSG_INFO, "WPA: Driver used disabled key "
862 "management 0x%x (mask 0x%x) - reject",
863 ie->key_mgmt, ssid->key_mgmt);
867 #ifdef CONFIG_IEEE80211W
868 if (!(ie->capabilities & WPA_CAPABILITY_MFPC) &&
869 ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
870 wpa_msg(wpa_s, MSG_INFO, "WPA: Driver associated with an AP "
871 "that does not support management frame protection - "
875 #endif /* CONFIG_IEEE80211W */
882 * wpa_supplicant_set_suites - Set authentication and encryption parameters
883 * @wpa_s: Pointer to wpa_supplicant data
884 * @bss: Scan results for the selected BSS, or %NULL if not available
885 * @ssid: Configuration data for the selected network
886 * @wpa_ie: Buffer for the WPA/RSN IE
887 * @wpa_ie_len: Maximum wpa_ie buffer size on input. This is changed to be the
888 * used buffer length in case the functions returns success.
889 * Returns: 0 on success or -1 on failure
891 * This function is used to configure authentication and encryption parameters
892 * based on the network configuration and scan result for the selected BSS (if
895 int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s,
896 struct wpa_bss *bss, struct wpa_ssid *ssid,
897 u8 *wpa_ie, size_t *wpa_ie_len)
899 struct wpa_ie_data ie;
901 const u8 *bss_wpa, *bss_rsn;
904 bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
905 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
907 bss_wpa = bss_rsn = NULL;
909 if (bss_rsn && (ssid->proto & WPA_PROTO_RSN) &&
910 wpa_parse_wpa_ie(bss_rsn, 2 + bss_rsn[1], &ie) == 0 &&
911 (ie.group_cipher & ssid->group_cipher) &&
912 (ie.pairwise_cipher & ssid->pairwise_cipher) &&
913 (ie.key_mgmt & ssid->key_mgmt)) {
914 wpa_msg(wpa_s, MSG_DEBUG, "RSN: using IEEE 802.11i/D9.0");
915 proto = WPA_PROTO_RSN;
916 } else if (bss_wpa && (ssid->proto & WPA_PROTO_WPA) &&
917 wpa_parse_wpa_ie(bss_wpa, 2 +bss_wpa[1], &ie) == 0 &&
918 (ie.group_cipher & ssid->group_cipher) &&
919 (ie.pairwise_cipher & ssid->pairwise_cipher) &&
920 (ie.key_mgmt & ssid->key_mgmt)) {
921 wpa_msg(wpa_s, MSG_DEBUG, "WPA: using IEEE 802.11i/D3.0");
922 proto = WPA_PROTO_WPA;
924 wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select WPA/RSN");
927 if (ssid->proto & WPA_PROTO_RSN)
928 proto = WPA_PROTO_RSN;
930 proto = WPA_PROTO_WPA;
931 if (wpa_supplicant_suites_from_ai(wpa_s, ssid, &ie) < 0) {
932 os_memset(&ie, 0, sizeof(ie));
933 ie.group_cipher = ssid->group_cipher;
934 ie.pairwise_cipher = ssid->pairwise_cipher;
935 ie.key_mgmt = ssid->key_mgmt;
936 #ifdef CONFIG_IEEE80211W
937 ie.mgmt_group_cipher =
938 ssid->ieee80211w != NO_MGMT_FRAME_PROTECTION ?
939 WPA_CIPHER_AES_128_CMAC : 0;
940 #endif /* CONFIG_IEEE80211W */
941 wpa_printf(MSG_DEBUG, "WPA: Set cipher suites based "
947 wpa_printf(MSG_DEBUG, "WPA: Selected cipher suites: group %d "
948 "pairwise %d key_mgmt %d proto %d",
949 ie.group_cipher, ie.pairwise_cipher, ie.key_mgmt, proto);
950 #ifdef CONFIG_IEEE80211W
951 if (ssid->ieee80211w) {
952 wpa_printf(MSG_DEBUG, "WPA: Selected mgmt group cipher %d",
953 ie.mgmt_group_cipher);
955 #endif /* CONFIG_IEEE80211W */
957 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, proto);
958 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
959 !!(ssid->proto & WPA_PROTO_RSN));
961 if (bss || !wpa_s->ap_ies_from_associnfo) {
962 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
963 bss_wpa ? 2 + bss_wpa[1] : 0) ||
964 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
965 bss_rsn ? 2 + bss_rsn[1] : 0))
969 sel = ie.group_cipher & ssid->group_cipher;
970 if (sel & WPA_CIPHER_CCMP) {
971 wpa_s->group_cipher = WPA_CIPHER_CCMP;
972 wpa_msg(wpa_s, MSG_DEBUG, "WPA: using GTK CCMP");
973 } else if (sel & WPA_CIPHER_TKIP) {
974 wpa_s->group_cipher = WPA_CIPHER_TKIP;
975 wpa_msg(wpa_s, MSG_DEBUG, "WPA: using GTK TKIP");
976 } else if (sel & WPA_CIPHER_WEP104) {
977 wpa_s->group_cipher = WPA_CIPHER_WEP104;
978 wpa_msg(wpa_s, MSG_DEBUG, "WPA: using GTK WEP104");
979 } else if (sel & WPA_CIPHER_WEP40) {
980 wpa_s->group_cipher = WPA_CIPHER_WEP40;
981 wpa_msg(wpa_s, MSG_DEBUG, "WPA: using GTK WEP40");
983 wpa_printf(MSG_WARNING, "WPA: Failed to select group cipher.");
987 sel = ie.pairwise_cipher & ssid->pairwise_cipher;
988 if (sel & WPA_CIPHER_CCMP) {
989 wpa_s->pairwise_cipher = WPA_CIPHER_CCMP;
990 wpa_msg(wpa_s, MSG_DEBUG, "WPA: using PTK CCMP");
991 } else if (sel & WPA_CIPHER_TKIP) {
992 wpa_s->pairwise_cipher = WPA_CIPHER_TKIP;
993 wpa_msg(wpa_s, MSG_DEBUG, "WPA: using PTK TKIP");
994 } else if (sel & WPA_CIPHER_NONE) {
995 wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
996 wpa_msg(wpa_s, MSG_DEBUG, "WPA: using PTK NONE");
998 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
1003 sel = ie.key_mgmt & ssid->key_mgmt;
1005 #ifdef CONFIG_IEEE80211R
1006 } else if (sel & WPA_KEY_MGMT_FT_IEEE8021X) {
1007 wpa_s->key_mgmt = WPA_KEY_MGMT_FT_IEEE8021X;
1008 wpa_msg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FT/802.1X");
1009 } else if (sel & WPA_KEY_MGMT_FT_PSK) {
1010 wpa_s->key_mgmt = WPA_KEY_MGMT_FT_PSK;
1011 wpa_msg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FT/PSK");
1012 #endif /* CONFIG_IEEE80211R */
1013 #ifdef CONFIG_IEEE80211W
1014 } else if (sel & WPA_KEY_MGMT_IEEE8021X_SHA256) {
1015 wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_SHA256;
1016 wpa_msg(wpa_s, MSG_DEBUG,
1017 "WPA: using KEY_MGMT 802.1X with SHA256");
1018 } else if (sel & WPA_KEY_MGMT_PSK_SHA256) {
1019 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK_SHA256;
1020 wpa_msg(wpa_s, MSG_DEBUG,
1021 "WPA: using KEY_MGMT PSK with SHA256");
1022 #endif /* CONFIG_IEEE80211W */
1023 } else if (sel & WPA_KEY_MGMT_IEEE8021X) {
1024 wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X;
1025 wpa_msg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT 802.1X");
1026 } else if (sel & WPA_KEY_MGMT_PSK) {
1027 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
1028 wpa_msg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT WPA-PSK");
1029 } else if (sel & WPA_KEY_MGMT_WPA_NONE) {
1030 wpa_s->key_mgmt = WPA_KEY_MGMT_WPA_NONE;
1031 wpa_msg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT WPA-NONE");
1033 wpa_printf(MSG_WARNING, "WPA: Failed to select authenticated "
1034 "key management type.");
1038 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
1039 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
1040 wpa_s->pairwise_cipher);
1041 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
1043 #ifdef CONFIG_IEEE80211W
1044 sel = ie.mgmt_group_cipher;
1045 if (ssid->ieee80211w == NO_MGMT_FRAME_PROTECTION ||
1046 !(ie.capabilities & WPA_CAPABILITY_MFPC))
1048 if (sel & WPA_CIPHER_AES_128_CMAC) {
1049 wpa_s->mgmt_group_cipher = WPA_CIPHER_AES_128_CMAC;
1050 wpa_msg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher "
1053 wpa_s->mgmt_group_cipher = 0;
1054 wpa_msg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
1056 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
1057 wpa_s->mgmt_group_cipher);
1058 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, ssid->ieee80211w);
1059 #endif /* CONFIG_IEEE80211W */
1061 if (wpa_sm_set_assoc_wpa_ie_default(wpa_s->wpa, wpa_ie, wpa_ie_len)) {
1062 wpa_printf(MSG_WARNING, "WPA: Failed to generate WPA IE.");
1066 if (ssid->key_mgmt &
1067 (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_PSK_SHA256))
1068 wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN);
1070 wpa_sm_set_pmk_from_pmksa(wpa_s->wpa);
1077 * wpa_supplicant_associate - Request association
1078 * @wpa_s: Pointer to wpa_supplicant data
1079 * @bss: Scan results for the selected BSS, or %NULL if not available
1080 * @ssid: Configuration data for the selected network
1082 * This function is used to request %wpa_supplicant to associate with a BSS.
1084 void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
1085 struct wpa_bss *bss, struct wpa_ssid *ssid)
1089 int use_crypt, ret, i, bssid_changed;
1090 int algs = WPA_AUTH_ALG_OPEN;
1091 enum wpa_cipher cipher_pairwise, cipher_group;
1092 struct wpa_driver_associate_params params;
1093 int wep_keys_set = 0;
1094 struct wpa_driver_capa capa;
1095 int assoc_failed = 0;
1096 struct wpa_ssid *old_ssid;
1098 if (ssid->mode == WPAS_MODE_AP) {
1100 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP)) {
1101 wpa_printf(MSG_INFO, "Driver does not support AP "
1105 wpa_supplicant_create_ap(wpa_s, ssid);
1106 wpa_s->current_bss = bss;
1107 #else /* CONFIG_AP */
1108 wpa_printf(MSG_ERROR, "AP mode support not included in the "
1110 #endif /* CONFIG_AP */
1114 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1115 ssid->mode == IEEE80211_MODE_INFRA) {
1116 sme_authenticate(wpa_s, bss, ssid);
1120 wpa_s->reassociate = 0;
1122 #ifdef CONFIG_IEEE80211R
1123 const u8 *ie, *md = NULL;
1124 #endif /* CONFIG_IEEE80211R */
1125 wpa_msg(wpa_s, MSG_INFO, "Trying to associate with " MACSTR
1126 " (SSID='%s' freq=%d MHz)", MAC2STR(bss->bssid),
1127 wpa_ssid_txt(bss->ssid, bss->ssid_len), bss->freq);
1128 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
1129 os_memset(wpa_s->bssid, 0, ETH_ALEN);
1130 os_memcpy(wpa_s->pending_bssid, bss->bssid, ETH_ALEN);
1132 wpas_notify_bssid_changed(wpa_s);
1133 #ifdef CONFIG_IEEE80211R
1134 ie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
1135 if (ie && ie[1] >= MOBILITY_DOMAIN_ID_LEN)
1137 wpa_sm_set_ft_params(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0);
1139 /* Prepare for the next transition */
1140 wpa_ft_prepare_auth_request(wpa_s->wpa, ie);
1142 #endif /* CONFIG_IEEE80211R */
1144 } else if ((ssid->ssid == NULL || ssid->ssid_len == 0) &&
1145 wpa_s->conf->ap_scan == 2 &&
1146 (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1147 /* Use ap_scan==1 style network selection to find the network
1149 wpa_s->scan_req = 2;
1150 wpa_s->reassociate = 1;
1151 wpa_supplicant_req_scan(wpa_s, 0, 0);
1153 #endif /* CONFIG_WPS */
1155 wpa_msg(wpa_s, MSG_INFO, "Trying to associate with SSID '%s'",
1156 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
1157 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1159 wpa_supplicant_cancel_scan(wpa_s);
1161 /* Starting new association, so clear the possibly used WPA IE from the
1162 * previous association. */
1163 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1165 #ifdef IEEE8021X_EAPOL
1166 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1168 if (ssid->non_leap == 0)
1169 algs = WPA_AUTH_ALG_LEAP;
1171 algs |= WPA_AUTH_ALG_LEAP;
1174 #endif /* IEEE8021X_EAPOL */
1175 wpa_printf(MSG_DEBUG, "Automatic auth_alg selection: 0x%x", algs);
1176 if (ssid->auth_alg) {
1177 algs = ssid->auth_alg;
1178 wpa_printf(MSG_DEBUG, "Overriding auth_alg selection: 0x%x",
1182 if (bss && (wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE) ||
1183 wpa_bss_get_ie(bss, WLAN_EID_RSN)) &&
1184 (ssid->key_mgmt & (WPA_KEY_MGMT_IEEE8021X | WPA_KEY_MGMT_PSK |
1185 WPA_KEY_MGMT_FT_IEEE8021X |
1186 WPA_KEY_MGMT_FT_PSK |
1187 WPA_KEY_MGMT_IEEE8021X_SHA256 |
1188 WPA_KEY_MGMT_PSK_SHA256))) {
1189 int try_opportunistic;
1190 try_opportunistic = ssid->proactive_key_caching &&
1191 (ssid->proto & WPA_PROTO_RSN);
1192 if (pmksa_cache_set_current(wpa_s->wpa, NULL, bss->bssid,
1193 wpa_s->current_ssid,
1194 try_opportunistic) == 0)
1195 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
1196 wpa_ie_len = sizeof(wpa_ie);
1197 if (wpa_supplicant_set_suites(wpa_s, bss, ssid,
1198 wpa_ie, &wpa_ie_len)) {
1199 wpa_printf(MSG_WARNING, "WPA: Failed to set WPA key "
1200 "management and encryption suites");
1203 } else if (ssid->key_mgmt &
1204 (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_IEEE8021X |
1205 WPA_KEY_MGMT_WPA_NONE | WPA_KEY_MGMT_FT_PSK |
1206 WPA_KEY_MGMT_FT_IEEE8021X | WPA_KEY_MGMT_PSK_SHA256 |
1207 WPA_KEY_MGMT_IEEE8021X_SHA256)) {
1208 wpa_ie_len = sizeof(wpa_ie);
1209 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
1210 wpa_ie, &wpa_ie_len)) {
1211 wpa_printf(MSG_WARNING, "WPA: Failed to set WPA key "
1212 "management and encryption suites (no scan "
1217 } else if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
1218 struct wpabuf *wps_ie;
1219 wps_ie = wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid));
1220 if (wps_ie && wpabuf_len(wps_ie) <= sizeof(wpa_ie)) {
1221 wpa_ie_len = wpabuf_len(wps_ie);
1222 os_memcpy(wpa_ie, wpabuf_head(wps_ie), wpa_ie_len);
1225 wpabuf_free(wps_ie);
1226 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
1227 #endif /* CONFIG_WPS */
1229 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
1233 wpa_clear_keys(wpa_s, bss ? bss->bssid : NULL);
1235 cipher_pairwise = cipher_suite2driver(wpa_s->pairwise_cipher);
1236 cipher_group = cipher_suite2driver(wpa_s->group_cipher);
1237 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1238 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1239 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE)
1241 if (wpa_set_wep_keys(wpa_s, ssid)) {
1246 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)
1249 #ifdef IEEE8021X_EAPOL
1250 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1251 if ((ssid->eapol_flags &
1252 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
1253 EAPOL_FLAG_REQUIRE_KEY_BROADCAST)) == 0 &&
1257 /* Assume that dynamic WEP-104 keys will be used and
1258 * set cipher suites in order for drivers to expect
1260 cipher_pairwise = cipher_group = CIPHER_WEP104;
1263 #endif /* IEEE8021X_EAPOL */
1265 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1266 /* Set the key before (and later after) association */
1267 wpa_supplicant_set_wpa_none_key(wpa_s, ssid);
1270 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATING);
1271 os_memset(¶ms, 0, sizeof(params));
1273 params.bssid = bss->bssid;
1274 params.ssid = bss->ssid;
1275 params.ssid_len = bss->ssid_len;
1276 params.freq = bss->freq;
1278 params.ssid = ssid->ssid;
1279 params.ssid_len = ssid->ssid_len;
1281 if (ssid->mode == WPAS_MODE_IBSS && ssid->frequency > 0 &&
1283 params.freq = ssid->frequency; /* Initial channel for IBSS */
1284 params.wpa_ie = wpa_ie;
1285 params.wpa_ie_len = wpa_ie_len;
1286 params.pairwise_suite = cipher_pairwise;
1287 params.group_suite = cipher_group;
1288 params.key_mgmt_suite = key_mgmt2driver(wpa_s->key_mgmt);
1289 params.auth_alg = algs;
1290 params.mode = ssid->mode;
1291 for (i = 0; i < NUM_WEP_KEYS; i++) {
1292 if (ssid->wep_key_len[i])
1293 params.wep_key[i] = ssid->wep_key[i];
1294 params.wep_key_len[i] = ssid->wep_key_len[i];
1296 params.wep_tx_keyidx = ssid->wep_tx_keyidx;
1298 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1299 (params.key_mgmt_suite == KEY_MGMT_PSK ||
1300 params.key_mgmt_suite == KEY_MGMT_FT_PSK)) {
1301 params.passphrase = ssid->passphrase;
1303 params.psk = ssid->psk;
1306 params.drop_unencrypted = use_crypt;
1308 #ifdef CONFIG_IEEE80211W
1309 params.mgmt_frame_protection = ssid->ieee80211w;
1310 if (ssid->ieee80211w != NO_MGMT_FRAME_PROTECTION && bss) {
1311 const u8 *rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1312 struct wpa_ie_data ie;
1313 if (rsn && wpa_parse_wpa_ie(rsn, 2 + rsn[1], &ie) == 0 &&
1315 (WPA_CAPABILITY_MFPC | WPA_CAPABILITY_MFPR)) {
1316 wpa_printf(MSG_DEBUG, "WPA: Selected AP supports MFP: "
1318 params.mgmt_frame_protection =
1319 MGMT_FRAME_PROTECTION_REQUIRED;
1322 #endif /* CONFIG_IEEE80211W */
1324 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
1325 ret = ieee80211_sta_associate(wpa_s, ¶ms);
1327 ret = wpa_drv_associate(wpa_s, ¶ms);
1329 wpa_msg(wpa_s, MSG_INFO, "Association request to the driver "
1331 /* try to continue anyway; new association will be tried again
1336 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1337 /* Set the key after the association just in case association
1338 * cleared the previously configured key. */
1339 wpa_supplicant_set_wpa_none_key(wpa_s, ssid);
1340 /* No need to timeout authentication since there is no key
1342 wpa_supplicant_cancel_auth_timeout(wpa_s);
1343 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1344 #ifdef CONFIG_IBSS_RSN
1345 } else if (ssid->mode == WPAS_MODE_IBSS &&
1346 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1347 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE) {
1348 ibss_rsn_set_psk(wpa_s->ibss_rsn, ssid->psk);
1350 * RSN IBSS authentication is per-STA and we can disable the
1351 * per-BSSID authentication.
1353 wpa_supplicant_cancel_auth_timeout(wpa_s);
1354 #endif /* CONFIG_IBSS_RSN */
1356 /* Timeout for IEEE 802.11 authentication and association */
1360 /* give IBSS a bit more time */
1361 timeout = ssid->mode == WPAS_MODE_IBSS ? 10 : 5;
1362 } else if (wpa_s->conf->ap_scan == 1) {
1363 /* give IBSS a bit more time */
1364 timeout = ssid->mode == WPAS_MODE_IBSS ? 20 : 10;
1366 wpa_supplicant_req_auth_timeout(wpa_s, timeout, 0);
1369 if (wep_keys_set && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1370 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC) {
1371 /* Set static WEP keys again */
1372 wpa_set_wep_keys(wpa_s, ssid);
1375 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid) {
1377 * Do not allow EAP session resumption between different
1378 * network configurations.
1380 eapol_sm_invalidate_cached_session(wpa_s->eapol);
1382 old_ssid = wpa_s->current_ssid;
1383 wpa_s->current_ssid = ssid;
1384 wpa_s->current_bss = bss;
1385 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
1386 wpa_supplicant_initiate_eapol(wpa_s);
1387 if (old_ssid != wpa_s->current_ssid)
1388 wpas_notify_network_changed(wpa_s);
1393 * wpa_supplicant_disassociate - Disassociate the current connection
1394 * @wpa_s: Pointer to wpa_supplicant data
1395 * @reason_code: IEEE 802.11 reason code for the disassociate frame
1397 * This function is used to request %wpa_supplicant to disassociate with the
1400 void wpa_supplicant_disassociate(struct wpa_supplicant *wpa_s,
1403 struct wpa_ssid *old_ssid;
1406 if (!is_zero_ether_addr(wpa_s->bssid)) {
1407 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
1408 ieee80211_sta_disassociate(wpa_s, reason_code);
1410 wpa_drv_disassociate(wpa_s, wpa_s->bssid, reason_code);
1411 addr = wpa_s->bssid;
1413 wpa_clear_keys(wpa_s, addr);
1414 wpa_supplicant_mark_disassoc(wpa_s);
1415 old_ssid = wpa_s->current_ssid;
1416 wpa_s->current_ssid = NULL;
1417 wpa_s->current_bss = NULL;
1418 wpa_sm_set_config(wpa_s->wpa, NULL);
1419 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
1420 if (old_ssid != wpa_s->current_ssid)
1421 wpas_notify_network_changed(wpa_s);
1422 eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL);
1427 * wpa_supplicant_deauthenticate - Deauthenticate the current connection
1428 * @wpa_s: Pointer to wpa_supplicant data
1429 * @reason_code: IEEE 802.11 reason code for the deauthenticate frame
1431 * This function is used to request %wpa_supplicant to deauthenticate from the
1434 void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s,
1437 struct wpa_ssid *old_ssid;
1440 if (!is_zero_ether_addr(wpa_s->bssid)) {
1441 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
1442 ieee80211_sta_deauthenticate(wpa_s, reason_code);
1444 wpa_drv_deauthenticate(wpa_s, wpa_s->bssid,
1446 addr = wpa_s->bssid;
1448 wpa_clear_keys(wpa_s, addr);
1449 wpa_supplicant_mark_disassoc(wpa_s);
1450 old_ssid = wpa_s->current_ssid;
1451 wpa_s->current_ssid = NULL;
1452 wpa_s->current_bss = NULL;
1453 wpa_sm_set_config(wpa_s->wpa, NULL);
1454 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
1455 if (old_ssid != wpa_s->current_ssid)
1456 wpas_notify_network_changed(wpa_s);
1457 eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL);
1462 * wpa_supplicant_enable_network - Mark a configured network as enabled
1463 * @wpa_s: wpa_supplicant structure for a network interface
1464 * @ssid: wpa_ssid structure for a configured network or %NULL
1466 * Enables the specified network or all networks if no network specified.
1468 void wpa_supplicant_enable_network(struct wpa_supplicant *wpa_s,
1469 struct wpa_ssid *ssid)
1471 struct wpa_ssid *other_ssid;
1475 other_ssid = wpa_s->conf->ssid;
1476 while (other_ssid) {
1477 if (other_ssid == wpa_s->current_ssid &&
1478 other_ssid->disabled)
1479 wpa_s->reassociate = 1;
1481 was_disabled = other_ssid->disabled;
1483 other_ssid->disabled = 0;
1485 if (was_disabled != other_ssid->disabled)
1486 wpas_notify_network_enabled_changed(
1489 other_ssid = other_ssid->next;
1491 if (wpa_s->reassociate)
1492 wpa_supplicant_req_scan(wpa_s, 0, 0);
1493 } else if (ssid->disabled) {
1494 if (wpa_s->current_ssid == NULL) {
1496 * Try to reassociate since there is no current
1497 * configuration and a new network was made available.
1499 wpa_s->reassociate = 1;
1500 wpa_supplicant_req_scan(wpa_s, 0, 0);
1503 was_disabled = ssid->disabled;
1507 if (was_disabled != ssid->disabled)
1508 wpas_notify_network_enabled_changed(wpa_s, ssid);
1514 * wpa_supplicant_disable_network - Mark a configured network as disabled
1515 * @wpa_s: wpa_supplicant structure for a network interface
1516 * @ssid: wpa_ssid structure for a configured network or %NULL
1518 * Disables the specified network or all networks if no network specified.
1520 void wpa_supplicant_disable_network(struct wpa_supplicant *wpa_s,
1521 struct wpa_ssid *ssid)
1523 struct wpa_ssid *other_ssid;
1527 other_ssid = wpa_s->conf->ssid;
1528 while (other_ssid) {
1529 was_disabled = other_ssid->disabled;
1531 other_ssid->disabled = 1;
1533 if (was_disabled != other_ssid->disabled)
1534 wpas_notify_network_enabled_changed(
1537 other_ssid = other_ssid->next;
1539 if (wpa_s->current_ssid)
1540 wpa_supplicant_disassociate(
1541 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1543 if (ssid == wpa_s->current_ssid)
1544 wpa_supplicant_disassociate(
1545 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1547 was_disabled = ssid->disabled;
1551 if (was_disabled != ssid->disabled)
1552 wpas_notify_network_enabled_changed(wpa_s, ssid);
1558 * wpa_supplicant_select_network - Attempt association with a network
1559 * @wpa_s: wpa_supplicant structure for a network interface
1560 * @ssid: wpa_ssid structure for a configured network or %NULL for any network
1562 void wpa_supplicant_select_network(struct wpa_supplicant *wpa_s,
1563 struct wpa_ssid *ssid)
1565 struct wpa_bss *selected_bss;
1566 struct wpa_ssid *other_ssid;
1568 if (ssid && ssid != wpa_s->current_ssid && wpa_s->current_ssid)
1569 wpa_supplicant_disassociate(
1570 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1573 * Mark all other networks disabled or mark all networks enabled if no
1574 * network specified.
1576 other_ssid = wpa_s->conf->ssid;
1577 while (other_ssid) {
1578 int was_disabled = other_ssid->disabled;
1580 other_ssid->disabled = ssid ? (ssid->id != other_ssid->id) : 0;
1582 if (was_disabled != other_ssid->disabled)
1583 wpas_notify_network_enabled_changed(wpa_s, other_ssid);
1585 other_ssid = other_ssid->next;
1587 wpa_s->disconnected = 0;
1588 wpa_s->reassociate = 1;
1590 wpa_printf(MSG_DEBUG, "==================================================");
1591 wpa_printf(MSG_DEBUG, "Select network start ssid : '%s'", ssid->ssid);
1592 wpa_printf(MSG_DEBUG, "==================================================");
1595 * August 1st, 2011 TIZEN
1596 * This part is changed to reduce associating duration.
1598 wpa_s->associate_num = 0;
1599 if( (selected_bss = wpa_bss_check_scan_res(wpa_s,ssid->ssid)) == NULL)
1601 wpa_supplicant_req_scan(wpa_s, 0, 0);
1603 wpas_notify_network_selected(wpa_s, ssid);
1608 wpas_notify_network_selected(wpa_s, ssid);
1610 wpa_supplicant_connect(wpa_s, selected_bss, ssid);
1618 * wpa_supplicant_set_ap_scan - Set AP scan mode for interface
1619 * @wpa_s: wpa_supplicant structure for a network interface
1620 * @ap_scan: AP scan mode
1621 * Returns: 0 if succeed or -1 if ap_scan has an invalid value
1624 int wpa_supplicant_set_ap_scan(struct wpa_supplicant *wpa_s, int ap_scan)
1629 if (ap_scan < 0 || ap_scan > 2)
1632 old_ap_scan = wpa_s->conf->ap_scan;
1633 wpa_s->conf->ap_scan = ap_scan;
1635 if (old_ap_scan != wpa_s->conf->ap_scan)
1636 wpas_notify_ap_scan_changed(wpa_s);
1643 * wpa_supplicant_set_debug_params - Set global debug params
1644 * @global: wpa_global structure
1645 * @debug_level: debug level
1646 * @debug_timestamp: determines if show timestamp in debug data
1647 * @debug_show_keys: determines if show keys in debug data
1648 * Returns: 0 if succeed or -1 if debug_level has wrong value
1650 int wpa_supplicant_set_debug_params(struct wpa_global *global, int debug_level,
1651 int debug_timestamp, int debug_show_keys)
1654 int old_level, old_timestamp, old_show_keys;
1656 /* check for allowed debuglevels */
1657 if (debug_level != MSG_MSGDUMP &&
1658 debug_level != MSG_DEBUG &&
1659 debug_level != MSG_INFO &&
1660 debug_level != MSG_WARNING &&
1661 debug_level != MSG_ERROR)
1664 old_level = wpa_debug_level;
1665 old_timestamp = wpa_debug_timestamp;
1666 old_show_keys = wpa_debug_show_keys;
1668 wpa_debug_level = debug_level;
1669 wpa_debug_timestamp = debug_timestamp ? 1 : 0;
1670 wpa_debug_show_keys = debug_show_keys ? 1 : 0;
1672 if (wpa_debug_level != old_level)
1673 wpas_notify_debug_level_changed(global);
1674 if (wpa_debug_timestamp != old_timestamp)
1675 wpas_notify_debug_timestamp_changed(global);
1676 if (wpa_debug_show_keys != old_show_keys)
1677 wpas_notify_debug_show_keys_changed(global);
1684 * wpa_supplicant_get_ssid - Get a pointer to the current network structure
1685 * @wpa_s: Pointer to wpa_supplicant data
1686 * Returns: A pointer to the current network structure or %NULL on failure
1688 struct wpa_ssid * wpa_supplicant_get_ssid(struct wpa_supplicant *wpa_s)
1690 struct wpa_ssid *entry;
1691 u8 ssid[MAX_SSID_LEN];
1697 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) {
1698 if (ieee80211_sta_get_ssid(wpa_s, ssid, &ssid_len)) {
1699 wpa_printf(MSG_WARNING, "Could not read SSID from "
1704 res = wpa_drv_get_ssid(wpa_s, ssid);
1706 wpa_printf(MSG_WARNING, "Could not read SSID from "
1713 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
1714 os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
1715 else if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1716 wpa_printf(MSG_WARNING, "Could not read BSSID from driver.");
1720 wired = wpa_s->conf->ap_scan == 0 &&
1721 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED);
1723 entry = wpa_s->conf->ssid;
1725 if (!entry->disabled &&
1726 ((ssid_len == entry->ssid_len &&
1727 os_memcmp(ssid, entry->ssid, ssid_len) == 0) || wired) &&
1728 (!entry->bssid_set ||
1729 os_memcmp(bssid, entry->bssid, ETH_ALEN) == 0))
1732 if (!entry->disabled &&
1733 (entry->key_mgmt & WPA_KEY_MGMT_WPS) &&
1734 (entry->ssid == NULL || entry->ssid_len == 0) &&
1735 (!entry->bssid_set ||
1736 os_memcmp(bssid, entry->bssid, ETH_ALEN) == 0))
1738 #endif /* CONFIG_WPS */
1739 entry = entry->next;
1746 static int wpa_supplicant_set_driver(struct wpa_supplicant *wpa_s,
1756 if (wpa_drivers[0] == NULL) {
1757 wpa_printf(MSG_ERROR, "No driver interfaces build into "
1763 /* default to first driver in the list */
1764 wpa_s->driver = wpa_drivers[0];
1765 wpa_s->global_drv_priv = wpa_s->global->drv_priv[0];
1769 pos = os_strchr(name, ',');
1773 len = os_strlen(name);
1774 for (i = 0; wpa_drivers[i]; i++) {
1775 if (os_strlen(wpa_drivers[i]->name) == len &&
1776 os_strncmp(name, wpa_drivers[i]->name, len) ==
1778 wpa_s->driver = wpa_drivers[i];
1779 wpa_s->global_drv_priv = wpa_s->global->drv_priv[i];
1784 wpa_printf(MSG_ERROR, "Unsupported driver '%s'.", name);
1790 * wpa_supplicant_rx_eapol - Deliver a received EAPOL frame to wpa_supplicant
1791 * @ctx: Context pointer (wpa_s); this is the ctx variable registered
1792 * with struct wpa_driver_ops::init()
1793 * @src_addr: Source address of the EAPOL frame
1794 * @buf: EAPOL data starting from the EAPOL header (i.e., no Ethernet header)
1795 * @len: Length of the EAPOL data
1797 * This function is called for each received EAPOL frame. Most driver
1798 * interfaces rely on more generic OS mechanism for receiving frames through
1799 * l2_packet, but if such a mechanism is not available, the driver wrapper may
1800 * take care of received EAPOL frames and deliver them to the core supplicant
1801 * code by calling this function.
1803 void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr,
1804 const u8 *buf, size_t len)
1806 struct wpa_supplicant *wpa_s = ctx;
1808 wpa_printf(MSG_DEBUG, "RX EAPOL from " MACSTR, MAC2STR(src_addr));
1809 wpa_hexdump(MSG_MSGDUMP, "RX EAPOL", buf, len);
1811 if (wpa_s->wpa_state < WPA_ASSOCIATED) {
1813 * There is possible race condition between receiving the
1814 * association event and the EAPOL frame since they are coming
1815 * through different paths from the driver. In order to avoid
1816 * issues in trying to process the EAPOL frame before receiving
1817 * association information, lets queue it for processing until
1818 * the association event is received.
1820 wpa_printf(MSG_DEBUG, "Not associated - Delay processing of "
1821 "received EAPOL frame");
1822 wpabuf_free(wpa_s->pending_eapol_rx);
1823 wpa_s->pending_eapol_rx = wpabuf_alloc_copy(buf, len);
1824 if (wpa_s->pending_eapol_rx) {
1825 os_get_time(&wpa_s->pending_eapol_rx_time);
1826 os_memcpy(wpa_s->pending_eapol_rx_src, src_addr,
1833 if (wpa_s->ap_iface) {
1834 wpa_supplicant_ap_rx_eapol(wpa_s, src_addr, buf, len);
1837 #endif /* CONFIG_AP */
1839 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE) {
1840 wpa_printf(MSG_DEBUG, "Ignored received EAPOL frame since "
1841 "no key management is configured");
1845 if (wpa_s->eapol_received == 0 &&
1846 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) ||
1847 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
1848 wpa_s->wpa_state != WPA_COMPLETED) &&
1849 (wpa_s->current_ssid == NULL ||
1850 wpa_s->current_ssid->mode != IEEE80211_MODE_IBSS)) {
1851 /* Timeout for completing IEEE 802.1X and WPA authentication */
1852 wpa_supplicant_req_auth_timeout(
1854 (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1855 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA ||
1856 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) ?
1859 wpa_s->eapol_received++;
1861 if (wpa_s->countermeasures) {
1862 wpa_printf(MSG_INFO, "WPA: Countermeasures - dropped EAPOL "
1867 #ifdef CONFIG_IBSS_RSN
1868 if (wpa_s->current_ssid &&
1869 wpa_s->current_ssid->mode == WPAS_MODE_IBSS) {
1870 ibss_rsn_rx_eapol(wpa_s->ibss_rsn, src_addr, buf, len);
1873 #endif /* CONFIG_IBSS_RSN */
1875 /* Source address of the incoming EAPOL frame could be compared to the
1876 * current BSSID. However, it is possible that a centralized
1877 * Authenticator could be using another MAC address than the BSSID of
1878 * an AP, so just allow any address to be used for now. The replies are
1879 * still sent to the current BSSID (if available), though. */
1881 os_memcpy(wpa_s->last_eapol_src, src_addr, ETH_ALEN);
1882 if (!wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) &&
1883 eapol_sm_rx_eapol(wpa_s->eapol, src_addr, buf, len) > 0)
1885 wpa_drv_poll(wpa_s);
1886 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE))
1887 wpa_sm_rx_eapol(wpa_s->wpa, src_addr, buf, len);
1888 else if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1890 * Set portValid = TRUE here since we are going to skip 4-way
1891 * handshake processing which would normally set portValid. We
1892 * need this to allow the EAPOL state machines to be completed
1893 * without going through EAPOL-Key handshake.
1895 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1901 * wpa_supplicant_driver_init - Initialize driver interface parameters
1902 * @wpa_s: Pointer to wpa_supplicant data
1903 * Returns: 0 on success, -1 on failure
1905 * This function is called to initialize driver interface parameters.
1906 * wpa_drv_init() must have been called before this function to initialize the
1909 int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s)
1911 static int interface_count = 0;
1913 if (wpa_s->driver->send_eapol) {
1914 const u8 *addr = wpa_drv_get_mac_addr(wpa_s);
1916 os_memcpy(wpa_s->own_addr, addr, ETH_ALEN);
1918 wpa_s->l2 = l2_packet_init(wpa_s->ifname,
1919 wpa_drv_get_mac_addr(wpa_s),
1921 wpa_supplicant_rx_eapol, wpa_s, 0);
1922 if (wpa_s->l2 == NULL)
1926 if (wpa_s->l2 && l2_packet_get_own_addr(wpa_s->l2, wpa_s->own_addr)) {
1927 wpa_printf(MSG_ERROR, "Failed to get own L2 address");
1931 wpa_printf(MSG_DEBUG, "Own MAC address: " MACSTR,
1932 MAC2STR(wpa_s->own_addr));
1934 if (wpa_s->bridge_ifname[0]) {
1935 wpa_printf(MSG_DEBUG, "Receiving packets from bridge interface"
1936 " '%s'", wpa_s->bridge_ifname);
1937 wpa_s->l2_br = l2_packet_init(wpa_s->bridge_ifname,
1940 wpa_supplicant_rx_eapol, wpa_s,
1942 if (wpa_s->l2_br == NULL) {
1943 wpa_printf(MSG_ERROR, "Failed to open l2_packet "
1944 "connection for the bridge interface '%s'",
1945 wpa_s->bridge_ifname);
1950 wpa_clear_keys(wpa_s, NULL);
1952 /* Make sure that TKIP countermeasures are not left enabled (could
1953 * happen if wpa_supplicant is killed during countermeasures. */
1954 wpa_drv_set_countermeasures(wpa_s, 0);
1956 wpa_printf(MSG_DEBUG, "RSN: flushing PMKID list in the driver");
1957 wpa_drv_flush_pmkid(wpa_s);
1959 wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN;
1960 if (wpa_supplicant_enabled_networks(wpa_s->conf)) {
1961 wpa_supplicant_req_scan(wpa_s, interface_count, 100000);
1964 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1970 static int wpa_supplicant_daemon(const char *pid_file)
1972 wpa_printf(MSG_DEBUG, "Daemonize..");
1973 return os_daemonize(pid_file);
1977 static struct wpa_supplicant * wpa_supplicant_alloc(void)
1979 struct wpa_supplicant *wpa_s;
1981 wpa_s = os_zalloc(sizeof(*wpa_s));
1984 wpa_s->scan_req = 1;
1985 wpa_s->new_connection = 1;
1991 static int wpa_supplicant_init_iface(struct wpa_supplicant *wpa_s,
1992 struct wpa_interface *iface)
1994 const char *ifname, *driver;
1995 struct wpa_driver_capa capa;
1997 wpa_printf(MSG_DEBUG, "Initializing interface '%s' conf '%s' driver "
1998 "'%s' ctrl_interface '%s' bridge '%s'", iface->ifname,
1999 iface->confname ? iface->confname : "N/A",
2000 iface->driver ? iface->driver : "default",
2001 iface->ctrl_interface ? iface->ctrl_interface : "N/A",
2002 iface->bridge_ifname ? iface->bridge_ifname : "N/A");
2004 if (iface->confname) {
2005 #ifdef CONFIG_BACKEND_FILE
2006 wpa_s->confname = os_rel2abs_path(iface->confname);
2007 if (wpa_s->confname == NULL) {
2008 wpa_printf(MSG_ERROR, "Failed to get absolute path "
2009 "for configuration file '%s'.",
2013 wpa_printf(MSG_DEBUG, "Configuration file '%s' -> '%s'",
2014 iface->confname, wpa_s->confname);
2015 #else /* CONFIG_BACKEND_FILE */
2016 wpa_s->confname = os_strdup(iface->confname);
2017 #endif /* CONFIG_BACKEND_FILE */
2018 wpa_s->conf = wpa_config_read(wpa_s->confname);
2019 if (wpa_s->conf == NULL) {
2020 wpa_printf(MSG_ERROR, "Failed to read or parse "
2021 "configuration '%s'.", wpa_s->confname);
2026 * Override ctrl_interface and driver_param if set on command
2029 if (iface->ctrl_interface) {
2030 os_free(wpa_s->conf->ctrl_interface);
2031 wpa_s->conf->ctrl_interface =
2032 os_strdup(iface->ctrl_interface);
2035 if (iface->driver_param) {
2036 os_free(wpa_s->conf->driver_param);
2037 wpa_s->conf->driver_param =
2038 os_strdup(iface->driver_param);
2041 wpa_s->conf = wpa_config_alloc_empty(iface->ctrl_interface,
2042 iface->driver_param);
2044 * October 11st, 2011 TIZEN
2045 * Workaround for timeout.
2047 wpa_s->associate_num =2;
2049 if (wpa_s->conf == NULL) {
2050 wpa_printf(MSG_ERROR, "\nNo configuration found.");
2054 if (iface->ifname == NULL) {
2055 wpa_printf(MSG_ERROR, "\nInterface name is required.");
2058 if (os_strlen(iface->ifname) >= sizeof(wpa_s->ifname)) {
2059 wpa_printf(MSG_ERROR, "\nToo long interface name '%s'.",
2063 os_strlcpy(wpa_s->ifname, iface->ifname, sizeof(wpa_s->ifname));
2065 if (iface->bridge_ifname) {
2066 if (os_strlen(iface->bridge_ifname) >=
2067 sizeof(wpa_s->bridge_ifname)) {
2068 wpa_printf(MSG_ERROR, "\nToo long bridge interface "
2069 "name '%s'.", iface->bridge_ifname);
2072 os_strlcpy(wpa_s->bridge_ifname, iface->bridge_ifname,
2073 sizeof(wpa_s->bridge_ifname));
2076 /* RSNA Supplicant Key Management - INITIALIZE */
2077 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2078 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2080 /* Initialize driver interface and register driver event handler before
2081 * L2 receive handler so that association events are processed before
2082 * EAPOL-Key packets if both become available for the same select()
2084 driver = iface->driver;
2086 if (wpa_supplicant_set_driver(wpa_s, driver) < 0)
2089 wpa_s->drv_priv = wpa_drv_init(wpa_s, wpa_s->ifname);
2090 if (wpa_s->drv_priv == NULL) {
2092 pos = driver ? os_strchr(driver, ',') : NULL;
2094 wpa_printf(MSG_DEBUG, "Failed to initialize driver "
2095 "interface - try next driver wrapper");
2099 wpa_printf(MSG_ERROR, "Failed to initialize driver interface");
2102 if (wpa_drv_set_param(wpa_s, wpa_s->conf->driver_param) < 0) {
2103 wpa_printf(MSG_ERROR, "Driver interface rejected "
2104 "driver_param '%s'", wpa_s->conf->driver_param);
2108 ifname = wpa_drv_get_ifname(wpa_s);
2109 if (ifname && os_strcmp(ifname, wpa_s->ifname) != 0) {
2110 wpa_printf(MSG_DEBUG, "Driver interface replaced interface "
2111 "name with '%s'", ifname);
2112 os_strlcpy(wpa_s->ifname, ifname, sizeof(wpa_s->ifname));
2115 if (wpa_supplicant_init_wpa(wpa_s) < 0)
2118 wpa_sm_set_ifname(wpa_s->wpa, wpa_s->ifname,
2119 wpa_s->bridge_ifname[0] ? wpa_s->bridge_ifname :
2121 wpa_sm_set_fast_reauth(wpa_s->wpa, wpa_s->conf->fast_reauth);
2123 if (wpa_s->conf->dot11RSNAConfigPMKLifetime &&
2124 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
2125 wpa_s->conf->dot11RSNAConfigPMKLifetime)) {
2126 wpa_printf(MSG_ERROR, "Invalid WPA parameter value for "
2127 "dot11RSNAConfigPMKLifetime");
2131 if (wpa_s->conf->dot11RSNAConfigPMKReauthThreshold &&
2132 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
2133 wpa_s->conf->dot11RSNAConfigPMKReauthThreshold)) {
2134 wpa_printf(MSG_ERROR, "Invalid WPA parameter value for "
2135 "dot11RSNAConfigPMKReauthThreshold");
2139 if (wpa_s->conf->dot11RSNAConfigSATimeout &&
2140 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT,
2141 wpa_s->conf->dot11RSNAConfigSATimeout)) {
2142 wpa_printf(MSG_ERROR, "Invalid WPA parameter value for "
2143 "dot11RSNAConfigSATimeout");
2147 if (wpa_drv_get_capa(wpa_s, &capa) == 0) {
2148 wpa_s->drv_flags = capa.flags;
2149 if (capa.flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) {
2150 if (ieee80211_sta_init(wpa_s))
2153 wpa_s->max_scan_ssids = capa.max_scan_ssids;
2154 wpa_s->max_remain_on_chan = capa.max_remain_on_chan;
2156 if (wpa_s->max_remain_on_chan == 0)
2157 wpa_s->max_remain_on_chan = 1000;
2159 if (wpa_supplicant_driver_init(wpa_s) < 0)
2162 if (wpa_s->conf->country[0] && wpa_s->conf->country[1] &&
2163 wpa_drv_set_country(wpa_s, wpa_s->conf->country)) {
2164 wpa_printf(MSG_DEBUG, "Failed to set country");
2168 wpa_sm_set_own_addr(wpa_s->wpa, wpa_s->own_addr);
2170 if (wpas_wps_init(wpa_s))
2173 if (wpa_supplicant_init_eapol(wpa_s) < 0)
2175 wpa_sm_set_eapol(wpa_s->wpa, wpa_s->eapol);
2177 wpa_s->ctrl_iface = wpa_supplicant_ctrl_iface_init(wpa_s);
2178 if (wpa_s->ctrl_iface == NULL) {
2179 wpa_printf(MSG_ERROR,
2180 "Failed to initialize control interface '%s'.\n"
2181 "You may have another wpa_supplicant process "
2182 "already running or the file was\n"
2183 "left by an unclean termination of wpa_supplicant "
2184 "in which case you will need\n"
2185 "to manually remove this file before starting "
2186 "wpa_supplicant again.\n",
2187 wpa_s->conf->ctrl_interface);
2191 #ifdef CONFIG_IBSS_RSN
2192 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2193 if (!wpa_s->ibss_rsn) {
2194 wpa_printf(MSG_DEBUG, "Failed to init IBSS RSN");
2197 #endif /* CONFIG_IBSS_RSN */
2199 if (wpa_bss_init(wpa_s) < 0)
2206 static void wpa_supplicant_deinit_iface(struct wpa_supplicant *wpa_s,
2209 if (wpa_s->drv_priv) {
2210 wpa_supplicant_deauthenticate(wpa_s,
2211 WLAN_REASON_DEAUTH_LEAVING);
2213 wpa_drv_set_countermeasures(wpa_s, 0);
2214 wpa_clear_keys(wpa_s, NULL);
2217 wpa_supplicant_cleanup(wpa_s);
2220 wpas_notify_iface_removed(wpa_s);
2222 if (wpa_s->drv_priv)
2223 wpa_drv_deinit(wpa_s);
2228 * wpa_supplicant_add_iface - Add a new network interface
2229 * @global: Pointer to global data from wpa_supplicant_init()
2230 * @iface: Interface configuration options
2231 * Returns: Pointer to the created interface or %NULL on failure
2233 * This function is used to add new network interfaces for %wpa_supplicant.
2234 * This can be called before wpa_supplicant_run() to add interfaces before the
2235 * main event loop has been started. In addition, new interfaces can be added
2236 * dynamically while %wpa_supplicant is already running. This could happen,
2237 * e.g., when a hotplug network adapter is inserted.
2239 struct wpa_supplicant * wpa_supplicant_add_iface(struct wpa_global *global,
2240 struct wpa_interface *iface)
2242 struct wpa_supplicant *wpa_s;
2243 struct wpa_interface t_iface;
2244 struct wpa_ssid *ssid;
2246 if (global == NULL || iface == NULL)
2249 wpa_s = wpa_supplicant_alloc();
2253 wpa_s->global = global;
2256 if (global->params.override_driver) {
2257 wpa_printf(MSG_DEBUG, "Override interface parameter: driver "
2259 iface->driver, global->params.override_driver);
2260 t_iface.driver = global->params.override_driver;
2262 if (global->params.override_ctrl_interface) {
2263 wpa_printf(MSG_DEBUG, "Override interface parameter: "
2264 "ctrl_interface ('%s' -> '%s')",
2265 iface->ctrl_interface,
2266 global->params.override_ctrl_interface);
2267 t_iface.ctrl_interface =
2268 global->params.override_ctrl_interface;
2270 if (wpa_supplicant_init_iface(wpa_s, &t_iface)) {
2271 wpa_printf(MSG_DEBUG, "Failed to add interface %s",
2273 wpa_supplicant_deinit_iface(wpa_s, 0);
2278 /* Notify the control interfaces about new iface */
2279 if (wpas_notify_iface_added(wpa_s)) {
2280 wpa_supplicant_deinit_iface(wpa_s, 1);
2285 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
2286 wpas_notify_network_added(wpa_s, ssid);
2288 wpa_s->next = global->ifaces;
2289 global->ifaces = wpa_s;
2291 wpa_printf(MSG_DEBUG, "Added interface %s", wpa_s->ifname);
2298 * wpa_supplicant_remove_iface - Remove a network interface
2299 * @global: Pointer to global data from wpa_supplicant_init()
2300 * @wpa_s: Pointer to the network interface to be removed
2301 * Returns: 0 if interface was removed, -1 if interface was not found
2303 * This function can be used to dynamically remove network interfaces from
2304 * %wpa_supplicant, e.g., when a hotplug network adapter is ejected. In
2305 * addition, this function is used to remove all remaining interfaces when
2306 * %wpa_supplicant is terminated.
2308 int wpa_supplicant_remove_iface(struct wpa_global *global,
2309 struct wpa_supplicant *wpa_s)
2311 struct wpa_supplicant *prev;
2313 /* Remove interface from the global list of interfaces */
2314 prev = global->ifaces;
2315 if (prev == wpa_s) {
2316 global->ifaces = wpa_s->next;
2318 while (prev && prev->next != wpa_s)
2322 prev->next = wpa_s->next;
2325 wpa_printf(MSG_DEBUG, "Removing interface %s", wpa_s->ifname);
2327 wpa_supplicant_deinit_iface(wpa_s, 1);
2335 * wpa_supplicant_get_iface - Get a new network interface
2336 * @global: Pointer to global data from wpa_supplicant_init()
2337 * @ifname: Interface name
2338 * Returns: Pointer to the interface or %NULL if not found
2340 struct wpa_supplicant * wpa_supplicant_get_iface(struct wpa_global *global,
2343 struct wpa_supplicant *wpa_s;
2345 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
2346 if (os_strcmp(wpa_s->ifname, ifname) == 0)
2354 * wpa_supplicant_init - Initialize %wpa_supplicant
2355 * @params: Parameters for %wpa_supplicant
2356 * Returns: Pointer to global %wpa_supplicant data, or %NULL on failure
2358 * This function is used to initialize %wpa_supplicant. After successful
2359 * initialization, the returned data pointer can be used to add and remove
2360 * network interfaces, and eventually, to deinitialize %wpa_supplicant.
2362 struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
2364 struct wpa_global *global;
2370 wpa_debug_open_file(params->wpa_debug_file_path);
2371 if (params->wpa_debug_syslog)
2372 wpa_debug_open_syslog();
2374 ret = eap_register_methods();
2376 wpa_printf(MSG_ERROR, "Failed to register EAP methods");
2378 wpa_printf(MSG_ERROR, "Two or more EAP methods used "
2379 "the same EAP type.");
2383 global = os_zalloc(sizeof(*global));
2386 global->params.daemonize = params->daemonize;
2387 global->params.wait_for_monitor = params->wait_for_monitor;
2388 global->params.dbus_ctrl_interface = params->dbus_ctrl_interface;
2389 if (params->pid_file)
2390 global->params.pid_file = os_strdup(params->pid_file);
2391 if (params->ctrl_interface)
2392 global->params.ctrl_interface =
2393 os_strdup(params->ctrl_interface);
2394 if (params->override_driver)
2395 global->params.override_driver =
2396 os_strdup(params->override_driver);
2397 if (params->override_ctrl_interface)
2398 global->params.override_ctrl_interface =
2399 os_strdup(params->override_ctrl_interface);
2400 wpa_debug_level = global->params.wpa_debug_level =
2401 params->wpa_debug_level;
2402 wpa_debug_show_keys = global->params.wpa_debug_show_keys =
2403 params->wpa_debug_show_keys;
2404 wpa_debug_timestamp = global->params.wpa_debug_timestamp =
2405 params->wpa_debug_timestamp;
2408 wpa_printf(MSG_ERROR, "Failed to initialize event loop");
2409 wpa_supplicant_deinit(global);
2413 global->ctrl_iface = wpa_supplicant_global_ctrl_iface_init(global);
2414 if (global->ctrl_iface == NULL) {
2415 wpa_supplicant_deinit(global);
2419 if (wpas_notify_supplicant_initialized(global)) {
2420 wpa_supplicant_deinit(global);
2424 for (i = 0; wpa_drivers[i]; i++)
2425 global->drv_count++;
2426 if (global->drv_count == 0) {
2427 wpa_printf(MSG_ERROR, "No drivers enabled");
2428 wpa_supplicant_deinit(global);
2431 global->drv_priv = os_zalloc(global->drv_count * sizeof(void *));
2432 if (global->drv_priv == NULL) {
2433 wpa_supplicant_deinit(global);
2436 for (i = 0; wpa_drivers[i]; i++) {
2437 if (!wpa_drivers[i]->global_init)
2439 global->drv_priv[i] = wpa_drivers[i]->global_init();
2440 if (global->drv_priv[i] == NULL) {
2441 wpa_printf(MSG_ERROR, "Failed to initialize driver "
2442 "'%s'", wpa_drivers[i]->name);
2443 wpa_supplicant_deinit(global);
2453 * wpa_supplicant_run - Run the %wpa_supplicant main event loop
2454 * @global: Pointer to global data from wpa_supplicant_init()
2455 * Returns: 0 after successful event loop run, -1 on failure
2457 * This function starts the main event loop and continues running as long as
2458 * there are any remaining events. In most cases, this function is running as
2459 * long as the %wpa_supplicant process in still in use.
2461 int wpa_supplicant_run(struct wpa_global *global)
2463 struct wpa_supplicant *wpa_s;
2465 if (global->params.daemonize &&
2466 wpa_supplicant_daemon(global->params.pid_file))
2469 if (global->params.wait_for_monitor) {
2470 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
2471 if (wpa_s->ctrl_iface)
2472 wpa_supplicant_ctrl_iface_wait(
2476 eloop_register_signal_terminate(wpa_supplicant_terminate, global);
2477 eloop_register_signal_reconfig(wpa_supplicant_reconfig, global);
2486 * wpa_supplicant_deinit - Deinitialize %wpa_supplicant
2487 * @global: Pointer to global data from wpa_supplicant_init()
2489 * This function is called to deinitialize %wpa_supplicant and to free all
2490 * allocated resources. Remaining network interfaces will also be removed.
2492 void wpa_supplicant_deinit(struct wpa_global *global)
2499 while (global->ifaces)
2500 wpa_supplicant_remove_iface(global, global->ifaces);
2502 if (global->ctrl_iface)
2503 wpa_supplicant_global_ctrl_iface_deinit(global->ctrl_iface);
2505 wpas_notify_supplicant_deinitialized(global);
2507 eap_peer_unregister_methods();
2509 eap_server_unregister_methods();
2510 #endif /* CONFIG_AP */
2512 for (i = 0; wpa_drivers[i] && global->drv_priv; i++) {
2513 if (!global->drv_priv[i])
2515 wpa_drivers[i]->global_deinit(global->drv_priv[i]);
2517 os_free(global->drv_priv);
2521 if (global->params.pid_file) {
2522 os_daemonize_terminate(global->params.pid_file);
2523 os_free(global->params.pid_file);
2525 os_free(global->params.ctrl_interface);
2526 os_free(global->params.override_driver);
2527 os_free(global->params.override_ctrl_interface);
2530 wpa_debug_close_syslog();
2531 wpa_debug_close_file();