]> git.ipfire.org Git - thirdparty/hostap.git/blob - wpa_supplicant/wpa_supplicant.c
Reinitialize autoscan on explicit reassocciate/reconnect command
[thirdparty/hostap.git] / wpa_supplicant / wpa_supplicant.c
1 /*
2 * WPA Supplicant
3 * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 *
8 * This file implements functions for registering and unregistering
9 * %wpa_supplicant interfaces. In addition, this file contains number of
10 * functions for managing network connections.
11 */
12
13 #include "includes.h"
14
15 #include "common.h"
16 #include "crypto/random.h"
17 #include "crypto/sha1.h"
18 #include "eapol_supp/eapol_supp_sm.h"
19 #include "eap_peer/eap.h"
20 #include "eap_server/eap_methods.h"
21 #include "rsn_supp/wpa.h"
22 #include "eloop.h"
23 #include "config.h"
24 #include "l2_packet/l2_packet.h"
25 #include "wpa_supplicant_i.h"
26 #include "driver_i.h"
27 #include "ctrl_iface.h"
28 #include "pcsc_funcs.h"
29 #include "common/version.h"
30 #include "rsn_supp/preauth.h"
31 #include "rsn_supp/pmksa_cache.h"
32 #include "common/wpa_ctrl.h"
33 #include "common/ieee802_11_defs.h"
34 #include "p2p/p2p.h"
35 #include "blacklist.h"
36 #include "wpas_glue.h"
37 #include "wps_supplicant.h"
38 #include "ibss_rsn.h"
39 #include "sme.h"
40 #include "gas_query.h"
41 #include "ap.h"
42 #include "p2p_supplicant.h"
43 #include "notify.h"
44 #include "bgscan.h"
45 #include "autoscan.h"
46 #include "bss.h"
47 #include "scan.h"
48 #include "offchannel.h"
49 #include "hs20_supplicant.h"
50
51 const char *wpa_supplicant_version =
52 "wpa_supplicant v" VERSION_STR "\n"
53 "Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi> and contributors";
54
55 const char *wpa_supplicant_license =
56 "This software may be distributed under the terms of the BSD license.\n"
57 "See README for more details.\n"
58 #ifdef EAP_TLS_OPENSSL
59 "\nThis product includes software developed by the OpenSSL Project\n"
60 "for use in the OpenSSL Toolkit (http://www.openssl.org/)\n"
61 #endif /* EAP_TLS_OPENSSL */
62 ;
63
64 #ifndef CONFIG_NO_STDOUT_DEBUG
65 /* Long text divided into parts in order to fit in C89 strings size limits. */
66 const char *wpa_supplicant_full_license1 =
67 "";
68 const char *wpa_supplicant_full_license2 =
69 "This software may be distributed under the terms of the BSD license.\n"
70 "\n"
71 "Redistribution and use in source and binary forms, with or without\n"
72 "modification, are permitted provided that the following conditions are\n"
73 "met:\n"
74 "\n";
75 const char *wpa_supplicant_full_license3 =
76 "1. Redistributions of source code must retain the above copyright\n"
77 " notice, this list of conditions and the following disclaimer.\n"
78 "\n"
79 "2. Redistributions in binary form must reproduce the above copyright\n"
80 " notice, this list of conditions and the following disclaimer in the\n"
81 " documentation and/or other materials provided with the distribution.\n"
82 "\n";
83 const char *wpa_supplicant_full_license4 =
84 "3. Neither the name(s) of the above-listed copyright holder(s) nor the\n"
85 " names of its contributors may be used to endorse or promote products\n"
86 " derived from this software without specific prior written permission.\n"
87 "\n"
88 "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n"
89 "\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n"
90 "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n"
91 "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n";
92 const char *wpa_supplicant_full_license5 =
93 "OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n"
94 "SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n"
95 "LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n"
96 "DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n"
97 "THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n"
98 "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n"
99 "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
100 "\n";
101 #endif /* CONFIG_NO_STDOUT_DEBUG */
102
103 extern int wpa_debug_level;
104 extern int wpa_debug_show_keys;
105 extern int wpa_debug_timestamp;
106 extern struct wpa_driver_ops *wpa_drivers[];
107
108 /* Configure default/group WEP keys for static WEP */
109 int wpa_set_wep_keys(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
110 {
111 int i, set = 0;
112
113 for (i = 0; i < NUM_WEP_KEYS; i++) {
114 if (ssid->wep_key_len[i] == 0)
115 continue;
116
117 set = 1;
118 wpa_drv_set_key(wpa_s, WPA_ALG_WEP, NULL,
119 i, i == ssid->wep_tx_keyidx, NULL, 0,
120 ssid->wep_key[i], ssid->wep_key_len[i]);
121 }
122
123 return set;
124 }
125
126
127 static int wpa_supplicant_set_wpa_none_key(struct wpa_supplicant *wpa_s,
128 struct wpa_ssid *ssid)
129 {
130 u8 key[32];
131 size_t keylen;
132 enum wpa_alg alg;
133 u8 seq[6] = { 0 };
134
135 /* IBSS/WPA-None uses only one key (Group) for both receiving and
136 * sending unicast and multicast packets. */
137
138 if (ssid->mode != WPAS_MODE_IBSS) {
139 wpa_msg(wpa_s, MSG_INFO, "WPA: Invalid mode %d (not "
140 "IBSS/ad-hoc) for WPA-None", ssid->mode);
141 return -1;
142 }
143
144 if (!ssid->psk_set) {
145 wpa_msg(wpa_s, MSG_INFO, "WPA: No PSK configured for "
146 "WPA-None");
147 return -1;
148 }
149
150 switch (wpa_s->group_cipher) {
151 case WPA_CIPHER_CCMP:
152 os_memcpy(key, ssid->psk, 16);
153 keylen = 16;
154 alg = WPA_ALG_CCMP;
155 break;
156 case WPA_CIPHER_TKIP:
157 /* WPA-None uses the same Michael MIC key for both TX and RX */
158 os_memcpy(key, ssid->psk, 16 + 8);
159 os_memcpy(key + 16 + 8, ssid->psk + 16, 8);
160 keylen = 32;
161 alg = WPA_ALG_TKIP;
162 break;
163 default:
164 wpa_msg(wpa_s, MSG_INFO, "WPA: Invalid group cipher %d for "
165 "WPA-None", wpa_s->group_cipher);
166 return -1;
167 }
168
169 /* TODO: should actually remember the previously used seq#, both for TX
170 * and RX from each STA.. */
171
172 return wpa_drv_set_key(wpa_s, alg, NULL, 0, 1, seq, 6, key, keylen);
173 }
174
175
176 static void wpa_supplicant_timeout(void *eloop_ctx, void *timeout_ctx)
177 {
178 struct wpa_supplicant *wpa_s = eloop_ctx;
179 const u8 *bssid = wpa_s->bssid;
180 if (is_zero_ether_addr(bssid))
181 bssid = wpa_s->pending_bssid;
182 wpa_msg(wpa_s, MSG_INFO, "Authentication with " MACSTR " timed out.",
183 MAC2STR(bssid));
184 wpa_blacklist_add(wpa_s, bssid);
185 wpa_sm_notify_disassoc(wpa_s->wpa);
186 wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
187 wpa_s->reassociate = 1;
188
189 /*
190 * If we timed out, the AP or the local radio may be busy.
191 * So, wait a second until scanning again.
192 */
193 wpa_supplicant_req_scan(wpa_s, 1, 0);
194 }
195
196
197 /**
198 * wpa_supplicant_req_auth_timeout - Schedule a timeout for authentication
199 * @wpa_s: Pointer to wpa_supplicant data
200 * @sec: Number of seconds after which to time out authentication
201 * @usec: Number of microseconds after which to time out authentication
202 *
203 * This function is used to schedule a timeout for the current authentication
204 * attempt.
205 */
206 void wpa_supplicant_req_auth_timeout(struct wpa_supplicant *wpa_s,
207 int sec, int usec)
208 {
209 if (wpa_s->conf && wpa_s->conf->ap_scan == 0 &&
210 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED))
211 return;
212
213 wpa_dbg(wpa_s, MSG_DEBUG, "Setting authentication timeout: %d sec "
214 "%d usec", sec, usec);
215 eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL);
216 eloop_register_timeout(sec, usec, wpa_supplicant_timeout, wpa_s, NULL);
217 }
218
219
220 /**
221 * wpa_supplicant_cancel_auth_timeout - Cancel authentication timeout
222 * @wpa_s: Pointer to wpa_supplicant data
223 *
224 * This function is used to cancel authentication timeout scheduled with
225 * wpa_supplicant_req_auth_timeout() and it is called when authentication has
226 * been completed.
227 */
228 void wpa_supplicant_cancel_auth_timeout(struct wpa_supplicant *wpa_s)
229 {
230 wpa_dbg(wpa_s, MSG_DEBUG, "Cancelling authentication timeout");
231 eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL);
232 wpa_blacklist_del(wpa_s, wpa_s->bssid);
233 }
234
235
236 /**
237 * wpa_supplicant_initiate_eapol - Configure EAPOL state machine
238 * @wpa_s: Pointer to wpa_supplicant data
239 *
240 * This function is used to configure EAPOL state machine based on the selected
241 * authentication mode.
242 */
243 void wpa_supplicant_initiate_eapol(struct wpa_supplicant *wpa_s)
244 {
245 #ifdef IEEE8021X_EAPOL
246 struct eapol_config eapol_conf;
247 struct wpa_ssid *ssid = wpa_s->current_ssid;
248
249 #ifdef CONFIG_IBSS_RSN
250 if (ssid->mode == WPAS_MODE_IBSS &&
251 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
252 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE) {
253 /*
254 * RSN IBSS authentication is per-STA and we can disable the
255 * per-BSSID EAPOL authentication.
256 */
257 eapol_sm_notify_portControl(wpa_s->eapol, ForceAuthorized);
258 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
259 eapol_sm_notify_eap_fail(wpa_s->eapol, FALSE);
260 return;
261 }
262 #endif /* CONFIG_IBSS_RSN */
263
264 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
265 eapol_sm_notify_eap_fail(wpa_s->eapol, FALSE);
266
267 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
268 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
269 eapol_sm_notify_portControl(wpa_s->eapol, ForceAuthorized);
270 else
271 eapol_sm_notify_portControl(wpa_s->eapol, Auto);
272
273 os_memset(&eapol_conf, 0, sizeof(eapol_conf));
274 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
275 eapol_conf.accept_802_1x_keys = 1;
276 eapol_conf.required_keys = 0;
277 if (ssid->eapol_flags & EAPOL_FLAG_REQUIRE_KEY_UNICAST) {
278 eapol_conf.required_keys |= EAPOL_REQUIRE_KEY_UNICAST;
279 }
280 if (ssid->eapol_flags & EAPOL_FLAG_REQUIRE_KEY_BROADCAST) {
281 eapol_conf.required_keys |=
282 EAPOL_REQUIRE_KEY_BROADCAST;
283 }
284
285 if (wpa_s->conf && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED))
286 eapol_conf.required_keys = 0;
287 }
288 if (wpa_s->conf)
289 eapol_conf.fast_reauth = wpa_s->conf->fast_reauth;
290 eapol_conf.workaround = ssid->eap_workaround;
291 eapol_conf.eap_disabled =
292 !wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) &&
293 wpa_s->key_mgmt != WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
294 wpa_s->key_mgmt != WPA_KEY_MGMT_WPS;
295 eapol_sm_notify_config(wpa_s->eapol, &ssid->eap, &eapol_conf);
296 #endif /* IEEE8021X_EAPOL */
297 }
298
299
300 /**
301 * wpa_supplicant_set_non_wpa_policy - Set WPA parameters to non-WPA mode
302 * @wpa_s: Pointer to wpa_supplicant data
303 * @ssid: Configuration data for the network
304 *
305 * This function is used to configure WPA state machine and related parameters
306 * to a mode where WPA is not enabled. This is called as part of the
307 * authentication configuration when the selected network does not use WPA.
308 */
309 void wpa_supplicant_set_non_wpa_policy(struct wpa_supplicant *wpa_s,
310 struct wpa_ssid *ssid)
311 {
312 int i;
313
314 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
315 wpa_s->key_mgmt = WPA_KEY_MGMT_WPS;
316 else if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)
317 wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
318 else
319 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
320 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
321 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
322 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
323 wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
324 wpa_s->group_cipher = WPA_CIPHER_NONE;
325 wpa_s->mgmt_group_cipher = 0;
326
327 for (i = 0; i < NUM_WEP_KEYS; i++) {
328 if (ssid->wep_key_len[i] > 5) {
329 wpa_s->pairwise_cipher = WPA_CIPHER_WEP104;
330 wpa_s->group_cipher = WPA_CIPHER_WEP104;
331 break;
332 } else if (ssid->wep_key_len[i] > 0) {
333 wpa_s->pairwise_cipher = WPA_CIPHER_WEP40;
334 wpa_s->group_cipher = WPA_CIPHER_WEP40;
335 break;
336 }
337 }
338
339 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED, 0);
340 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
341 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
342 wpa_s->pairwise_cipher);
343 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
344 #ifdef CONFIG_IEEE80211W
345 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
346 wpa_s->mgmt_group_cipher);
347 #endif /* CONFIG_IEEE80211W */
348
349 pmksa_cache_clear_current(wpa_s->wpa);
350 }
351
352
353 void free_hw_features(struct wpa_supplicant *wpa_s)
354 {
355 int i;
356 if (wpa_s->hw.modes == NULL)
357 return;
358
359 for (i = 0; i < wpa_s->hw.num_modes; i++) {
360 os_free(wpa_s->hw.modes[i].channels);
361 os_free(wpa_s->hw.modes[i].rates);
362 }
363
364 os_free(wpa_s->hw.modes);
365 wpa_s->hw.modes = NULL;
366 }
367
368
369 static void wpa_supplicant_cleanup(struct wpa_supplicant *wpa_s)
370 {
371 bgscan_deinit(wpa_s);
372 autoscan_deinit(wpa_s);
373 scard_deinit(wpa_s->scard);
374 wpa_s->scard = NULL;
375 wpa_sm_set_scard_ctx(wpa_s->wpa, NULL);
376 eapol_sm_register_scard_ctx(wpa_s->eapol, NULL);
377 l2_packet_deinit(wpa_s->l2);
378 wpa_s->l2 = NULL;
379 if (wpa_s->l2_br) {
380 l2_packet_deinit(wpa_s->l2_br);
381 wpa_s->l2_br = NULL;
382 }
383
384 if (wpa_s->conf != NULL) {
385 struct wpa_ssid *ssid;
386 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
387 wpas_notify_network_removed(wpa_s, ssid);
388 }
389
390 os_free(wpa_s->confname);
391 wpa_s->confname = NULL;
392
393 wpa_sm_set_eapol(wpa_s->wpa, NULL);
394 eapol_sm_deinit(wpa_s->eapol);
395 wpa_s->eapol = NULL;
396
397 rsn_preauth_deinit(wpa_s->wpa);
398
399 #ifdef CONFIG_TDLS
400 wpa_tdls_deinit(wpa_s->wpa);
401 #endif /* CONFIG_TDLS */
402
403 pmksa_candidate_free(wpa_s->wpa);
404 wpa_sm_deinit(wpa_s->wpa);
405 wpa_s->wpa = NULL;
406 wpa_blacklist_clear(wpa_s);
407
408 wpa_bss_deinit(wpa_s);
409
410 wpa_supplicant_cancel_scan(wpa_s);
411 wpa_supplicant_cancel_auth_timeout(wpa_s);
412 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
413 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
414 eloop_cancel_timeout(wpa_supplicant_delayed_mic_error_report,
415 wpa_s, NULL);
416 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
417
418 wpas_wps_deinit(wpa_s);
419
420 wpabuf_free(wpa_s->pending_eapol_rx);
421 wpa_s->pending_eapol_rx = NULL;
422
423 #ifdef CONFIG_IBSS_RSN
424 ibss_rsn_deinit(wpa_s->ibss_rsn);
425 wpa_s->ibss_rsn = NULL;
426 #endif /* CONFIG_IBSS_RSN */
427
428 sme_deinit(wpa_s);
429
430 #ifdef CONFIG_AP
431 wpa_supplicant_ap_deinit(wpa_s);
432 #endif /* CONFIG_AP */
433
434 #ifdef CONFIG_P2P
435 wpas_p2p_deinit(wpa_s);
436 #endif /* CONFIG_P2P */
437
438 #ifdef CONFIG_OFFCHANNEL
439 offchannel_deinit(wpa_s);
440 #endif /* CONFIG_OFFCHANNEL */
441
442 wpa_supplicant_cancel_sched_scan(wpa_s);
443
444 os_free(wpa_s->next_scan_freqs);
445 wpa_s->next_scan_freqs = NULL;
446
447 gas_query_deinit(wpa_s->gas);
448 wpa_s->gas = NULL;
449
450 free_hw_features(wpa_s);
451
452 os_free(wpa_s->bssid_filter);
453 wpa_s->bssid_filter = NULL;
454
455 wnm_bss_keep_alive_deinit(wpa_s);
456 }
457
458
459 /**
460 * wpa_clear_keys - Clear keys configured for the driver
461 * @wpa_s: Pointer to wpa_supplicant data
462 * @addr: Previously used BSSID or %NULL if not available
463 *
464 * This function clears the encryption keys that has been previously configured
465 * for the driver.
466 */
467 void wpa_clear_keys(struct wpa_supplicant *wpa_s, const u8 *addr)
468 {
469 if (wpa_s->keys_cleared) {
470 /* Some drivers (e.g., ndiswrapper & NDIS drivers) seem to have
471 * timing issues with keys being cleared just before new keys
472 * are set or just after association or something similar. This
473 * shows up in group key handshake failing often because of the
474 * client not receiving the first encrypted packets correctly.
475 * Skipping some of the extra key clearing steps seems to help
476 * in completing group key handshake more reliably. */
477 wpa_dbg(wpa_s, MSG_DEBUG, "No keys have been configured - "
478 "skip key clearing");
479 return;
480 }
481
482 /* MLME-DELETEKEYS.request */
483 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
484 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
485 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
486 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
487 #ifdef CONFIG_IEEE80211W
488 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
489 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
490 #endif /* CONFIG_IEEE80211W */
491 if (addr) {
492 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, addr, 0, 0, NULL, 0, NULL,
493 0);
494 /* MLME-SETPROTECTION.request(None) */
495 wpa_drv_mlme_setprotection(
496 wpa_s, addr,
497 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
498 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
499 }
500 wpa_s->keys_cleared = 1;
501 }
502
503
504 /**
505 * wpa_supplicant_state_txt - Get the connection state name as a text string
506 * @state: State (wpa_state; WPA_*)
507 * Returns: The state name as a printable text string
508 */
509 const char * wpa_supplicant_state_txt(enum wpa_states state)
510 {
511 switch (state) {
512 case WPA_DISCONNECTED:
513 return "DISCONNECTED";
514 case WPA_INACTIVE:
515 return "INACTIVE";
516 case WPA_INTERFACE_DISABLED:
517 return "INTERFACE_DISABLED";
518 case WPA_SCANNING:
519 return "SCANNING";
520 case WPA_AUTHENTICATING:
521 return "AUTHENTICATING";
522 case WPA_ASSOCIATING:
523 return "ASSOCIATING";
524 case WPA_ASSOCIATED:
525 return "ASSOCIATED";
526 case WPA_4WAY_HANDSHAKE:
527 return "4WAY_HANDSHAKE";
528 case WPA_GROUP_HANDSHAKE:
529 return "GROUP_HANDSHAKE";
530 case WPA_COMPLETED:
531 return "COMPLETED";
532 default:
533 return "UNKNOWN";
534 }
535 }
536
537
538 #ifdef CONFIG_BGSCAN
539
540 static void wpa_supplicant_start_bgscan(struct wpa_supplicant *wpa_s)
541 {
542 if (wpas_driver_bss_selection(wpa_s))
543 return;
544 if (wpa_s->current_ssid == wpa_s->bgscan_ssid)
545 return;
546
547 bgscan_deinit(wpa_s);
548 if (wpa_s->current_ssid && wpa_s->current_ssid->bgscan) {
549 if (bgscan_init(wpa_s, wpa_s->current_ssid)) {
550 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to initialize "
551 "bgscan");
552 /*
553 * Live without bgscan; it is only used as a roaming
554 * optimization, so the initial connection is not
555 * affected.
556 */
557 } else
558 wpa_s->bgscan_ssid = wpa_s->current_ssid;
559 } else
560 wpa_s->bgscan_ssid = NULL;
561 }
562
563
564 static void wpa_supplicant_stop_bgscan(struct wpa_supplicant *wpa_s)
565 {
566 if (wpa_s->bgscan_ssid != NULL) {
567 bgscan_deinit(wpa_s);
568 wpa_s->bgscan_ssid = NULL;
569 }
570 }
571
572 #endif /* CONFIG_BGSCAN */
573
574
575 static void wpa_supplicant_start_autoscan(struct wpa_supplicant *wpa_s)
576 {
577 if (autoscan_init(wpa_s, 0))
578 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to initialize autoscan");
579 }
580
581
582 static void wpa_supplicant_stop_autoscan(struct wpa_supplicant *wpa_s)
583 {
584 autoscan_deinit(wpa_s);
585 }
586
587
588 void wpa_supplicant_reinit_autoscan(struct wpa_supplicant *wpa_s)
589 {
590 if (wpa_s->wpa_state == WPA_DISCONNECTED ||
591 wpa_s->wpa_state == WPA_SCANNING) {
592 autoscan_deinit(wpa_s);
593 wpa_supplicant_start_autoscan(wpa_s);
594 }
595 }
596
597
598 /**
599 * wpa_supplicant_set_state - Set current connection state
600 * @wpa_s: Pointer to wpa_supplicant data
601 * @state: The new connection state
602 *
603 * This function is called whenever the connection state changes, e.g.,
604 * association is completed for WPA/WPA2 4-Way Handshake is started.
605 */
606 void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s,
607 enum wpa_states state)
608 {
609 enum wpa_states old_state = wpa_s->wpa_state;
610
611 wpa_dbg(wpa_s, MSG_DEBUG, "State: %s -> %s",
612 wpa_supplicant_state_txt(wpa_s->wpa_state),
613 wpa_supplicant_state_txt(state));
614
615 if (state != WPA_SCANNING)
616 wpa_supplicant_notify_scanning(wpa_s, 0);
617
618 if (state == WPA_COMPLETED && wpa_s->new_connection) {
619 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
620 struct wpa_ssid *ssid = wpa_s->current_ssid;
621 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED "- Connection to "
622 MACSTR " completed %s [id=%d id_str=%s]",
623 MAC2STR(wpa_s->bssid), wpa_s->reassociated_connection ?
624 "(reauth)" : "(auth)",
625 ssid ? ssid->id : -1,
626 ssid && ssid->id_str ? ssid->id_str : "");
627 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
628 wpa_s->new_connection = 0;
629 wpa_s->reassociated_connection = 1;
630 wpa_drv_set_operstate(wpa_s, 1);
631 #ifndef IEEE8021X_EAPOL
632 wpa_drv_set_supp_port(wpa_s, 1);
633 #endif /* IEEE8021X_EAPOL */
634 wpa_s->after_wps = 0;
635 #ifdef CONFIG_P2P
636 wpas_p2p_completed(wpa_s);
637 #endif /* CONFIG_P2P */
638
639 sme_sched_obss_scan(wpa_s, 1);
640 } else if (state == WPA_DISCONNECTED || state == WPA_ASSOCIATING ||
641 state == WPA_ASSOCIATED) {
642 wpa_s->new_connection = 1;
643 wpa_drv_set_operstate(wpa_s, 0);
644 #ifndef IEEE8021X_EAPOL
645 wpa_drv_set_supp_port(wpa_s, 0);
646 #endif /* IEEE8021X_EAPOL */
647 sme_sched_obss_scan(wpa_s, 0);
648 }
649 wpa_s->wpa_state = state;
650
651 #ifdef CONFIG_BGSCAN
652 if (state == WPA_COMPLETED)
653 wpa_supplicant_start_bgscan(wpa_s);
654 else
655 wpa_supplicant_stop_bgscan(wpa_s);
656 #endif /* CONFIG_BGSCAN */
657
658 if (state == WPA_AUTHENTICATING)
659 wpa_supplicant_stop_autoscan(wpa_s);
660
661 if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
662 wpa_supplicant_start_autoscan(wpa_s);
663
664 if (wpa_s->wpa_state != old_state) {
665 wpas_notify_state_changed(wpa_s, wpa_s->wpa_state, old_state);
666
667 if (wpa_s->wpa_state == WPA_COMPLETED ||
668 old_state == WPA_COMPLETED)
669 wpas_notify_auth_changed(wpa_s);
670 }
671 }
672
673
674 void wpa_supplicant_terminate_proc(struct wpa_global *global)
675 {
676 int pending = 0;
677 #ifdef CONFIG_WPS
678 struct wpa_supplicant *wpa_s = global->ifaces;
679 while (wpa_s) {
680 if (wpas_wps_terminate_pending(wpa_s) == 1)
681 pending = 1;
682 wpa_s = wpa_s->next;
683 }
684 #endif /* CONFIG_WPS */
685 if (pending)
686 return;
687 eloop_terminate();
688 }
689
690
691 static void wpa_supplicant_terminate(int sig, void *signal_ctx)
692 {
693 struct wpa_global *global = signal_ctx;
694 wpa_supplicant_terminate_proc(global);
695 }
696
697
698 void wpa_supplicant_clear_status(struct wpa_supplicant *wpa_s)
699 {
700 enum wpa_states old_state = wpa_s->wpa_state;
701
702 wpa_s->pairwise_cipher = 0;
703 wpa_s->group_cipher = 0;
704 wpa_s->mgmt_group_cipher = 0;
705 wpa_s->key_mgmt = 0;
706 if (wpa_s->wpa_state != WPA_INTERFACE_DISABLED)
707 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
708
709 if (wpa_s->wpa_state != old_state)
710 wpas_notify_state_changed(wpa_s, wpa_s->wpa_state, old_state);
711 }
712
713
714 /**
715 * wpa_supplicant_reload_configuration - Reload configuration data
716 * @wpa_s: Pointer to wpa_supplicant data
717 * Returns: 0 on success or -1 if configuration parsing failed
718 *
719 * This function can be used to request that the configuration data is reloaded
720 * (e.g., after configuration file change). This function is reloading
721 * configuration only for one interface, so this may need to be called multiple
722 * times if %wpa_supplicant is controlling multiple interfaces and all
723 * interfaces need reconfiguration.
724 */
725 int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s)
726 {
727 struct wpa_config *conf;
728 int reconf_ctrl;
729 int old_ap_scan;
730
731 if (wpa_s->confname == NULL)
732 return -1;
733 conf = wpa_config_read(wpa_s->confname);
734 if (conf == NULL) {
735 wpa_msg(wpa_s, MSG_ERROR, "Failed to parse the configuration "
736 "file '%s' - exiting", wpa_s->confname);
737 return -1;
738 }
739 conf->changed_parameters = (unsigned int) -1;
740
741 reconf_ctrl = !!conf->ctrl_interface != !!wpa_s->conf->ctrl_interface
742 || (conf->ctrl_interface && wpa_s->conf->ctrl_interface &&
743 os_strcmp(conf->ctrl_interface,
744 wpa_s->conf->ctrl_interface) != 0);
745
746 if (reconf_ctrl && wpa_s->ctrl_iface) {
747 wpa_supplicant_ctrl_iface_deinit(wpa_s->ctrl_iface);
748 wpa_s->ctrl_iface = NULL;
749 }
750
751 eapol_sm_invalidate_cached_session(wpa_s->eapol);
752 if (wpa_s->current_ssid) {
753 wpa_supplicant_deauthenticate(wpa_s,
754 WLAN_REASON_DEAUTH_LEAVING);
755 }
756
757 /*
758 * TODO: should notify EAPOL SM about changes in opensc_engine_path,
759 * pkcs11_engine_path, pkcs11_module_path.
760 */
761 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
762 /*
763 * Clear forced success to clear EAP state for next
764 * authentication.
765 */
766 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
767 }
768 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
769 wpa_sm_set_config(wpa_s->wpa, NULL);
770 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
771 wpa_sm_set_fast_reauth(wpa_s->wpa, wpa_s->conf->fast_reauth);
772 rsn_preauth_deinit(wpa_s->wpa);
773
774 old_ap_scan = wpa_s->conf->ap_scan;
775 wpa_config_free(wpa_s->conf);
776 wpa_s->conf = conf;
777 if (old_ap_scan != wpa_s->conf->ap_scan)
778 wpas_notify_ap_scan_changed(wpa_s);
779
780 if (reconf_ctrl)
781 wpa_s->ctrl_iface = wpa_supplicant_ctrl_iface_init(wpa_s);
782
783 wpa_supplicant_update_config(wpa_s);
784
785 wpa_supplicant_clear_status(wpa_s);
786 if (wpa_supplicant_enabled_networks(wpa_s)) {
787 wpa_s->reassociate = 1;
788 wpa_supplicant_req_scan(wpa_s, 0, 0);
789 }
790 wpa_dbg(wpa_s, MSG_DEBUG, "Reconfiguration completed");
791 return 0;
792 }
793
794
795 static void wpa_supplicant_reconfig(int sig, void *signal_ctx)
796 {
797 struct wpa_global *global = signal_ctx;
798 struct wpa_supplicant *wpa_s;
799 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
800 wpa_dbg(wpa_s, MSG_DEBUG, "Signal %d received - reconfiguring",
801 sig);
802 if (wpa_supplicant_reload_configuration(wpa_s) < 0) {
803 wpa_supplicant_terminate_proc(global);
804 }
805 }
806 }
807
808
809 enum wpa_cipher cipher_suite2driver(int cipher)
810 {
811 switch (cipher) {
812 case WPA_CIPHER_NONE:
813 return CIPHER_NONE;
814 case WPA_CIPHER_WEP40:
815 return CIPHER_WEP40;
816 case WPA_CIPHER_WEP104:
817 return CIPHER_WEP104;
818 case WPA_CIPHER_CCMP:
819 return CIPHER_CCMP;
820 case WPA_CIPHER_TKIP:
821 default:
822 return CIPHER_TKIP;
823 }
824 }
825
826
827 enum wpa_key_mgmt key_mgmt2driver(int key_mgmt)
828 {
829 switch (key_mgmt) {
830 case WPA_KEY_MGMT_NONE:
831 return KEY_MGMT_NONE;
832 case WPA_KEY_MGMT_IEEE8021X_NO_WPA:
833 return KEY_MGMT_802_1X_NO_WPA;
834 case WPA_KEY_MGMT_IEEE8021X:
835 return KEY_MGMT_802_1X;
836 case WPA_KEY_MGMT_WPA_NONE:
837 return KEY_MGMT_WPA_NONE;
838 case WPA_KEY_MGMT_FT_IEEE8021X:
839 return KEY_MGMT_FT_802_1X;
840 case WPA_KEY_MGMT_FT_PSK:
841 return KEY_MGMT_FT_PSK;
842 case WPA_KEY_MGMT_IEEE8021X_SHA256:
843 return KEY_MGMT_802_1X_SHA256;
844 case WPA_KEY_MGMT_PSK_SHA256:
845 return KEY_MGMT_PSK_SHA256;
846 case WPA_KEY_MGMT_WPS:
847 return KEY_MGMT_WPS;
848 case WPA_KEY_MGMT_PSK:
849 default:
850 return KEY_MGMT_PSK;
851 }
852 }
853
854
855 static int wpa_supplicant_suites_from_ai(struct wpa_supplicant *wpa_s,
856 struct wpa_ssid *ssid,
857 struct wpa_ie_data *ie)
858 {
859 int ret = wpa_sm_parse_own_wpa_ie(wpa_s->wpa, ie);
860 if (ret) {
861 if (ret == -2) {
862 wpa_msg(wpa_s, MSG_INFO, "WPA: Failed to parse WPA IE "
863 "from association info");
864 }
865 return -1;
866 }
867
868 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Using WPA IE from AssocReq to set "
869 "cipher suites");
870 if (!(ie->group_cipher & ssid->group_cipher)) {
871 wpa_msg(wpa_s, MSG_INFO, "WPA: Driver used disabled group "
872 "cipher 0x%x (mask 0x%x) - reject",
873 ie->group_cipher, ssid->group_cipher);
874 return -1;
875 }
876 if (!(ie->pairwise_cipher & ssid->pairwise_cipher)) {
877 wpa_msg(wpa_s, MSG_INFO, "WPA: Driver used disabled pairwise "
878 "cipher 0x%x (mask 0x%x) - reject",
879 ie->pairwise_cipher, ssid->pairwise_cipher);
880 return -1;
881 }
882 if (!(ie->key_mgmt & ssid->key_mgmt)) {
883 wpa_msg(wpa_s, MSG_INFO, "WPA: Driver used disabled key "
884 "management 0x%x (mask 0x%x) - reject",
885 ie->key_mgmt, ssid->key_mgmt);
886 return -1;
887 }
888
889 #ifdef CONFIG_IEEE80211W
890 if (!(ie->capabilities & WPA_CAPABILITY_MFPC) &&
891 ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
892 wpa_msg(wpa_s, MSG_INFO, "WPA: Driver associated with an AP "
893 "that does not support management frame protection - "
894 "reject");
895 return -1;
896 }
897 #endif /* CONFIG_IEEE80211W */
898
899 return 0;
900 }
901
902
903 /**
904 * wpa_supplicant_set_suites - Set authentication and encryption parameters
905 * @wpa_s: Pointer to wpa_supplicant data
906 * @bss: Scan results for the selected BSS, or %NULL if not available
907 * @ssid: Configuration data for the selected network
908 * @wpa_ie: Buffer for the WPA/RSN IE
909 * @wpa_ie_len: Maximum wpa_ie buffer size on input. This is changed to be the
910 * used buffer length in case the functions returns success.
911 * Returns: 0 on success or -1 on failure
912 *
913 * This function is used to configure authentication and encryption parameters
914 * based on the network configuration and scan result for the selected BSS (if
915 * available).
916 */
917 int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s,
918 struct wpa_bss *bss, struct wpa_ssid *ssid,
919 u8 *wpa_ie, size_t *wpa_ie_len)
920 {
921 struct wpa_ie_data ie;
922 int sel, proto;
923 const u8 *bss_wpa, *bss_rsn;
924
925 if (bss) {
926 bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
927 bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
928 } else
929 bss_wpa = bss_rsn = NULL;
930
931 if (bss_rsn && (ssid->proto & WPA_PROTO_RSN) &&
932 wpa_parse_wpa_ie(bss_rsn, 2 + bss_rsn[1], &ie) == 0 &&
933 (ie.group_cipher & ssid->group_cipher) &&
934 (ie.pairwise_cipher & ssid->pairwise_cipher) &&
935 (ie.key_mgmt & ssid->key_mgmt)) {
936 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using IEEE 802.11i/D9.0");
937 proto = WPA_PROTO_RSN;
938 } else if (bss_wpa && (ssid->proto & WPA_PROTO_WPA) &&
939 wpa_parse_wpa_ie(bss_wpa, 2 +bss_wpa[1], &ie) == 0 &&
940 (ie.group_cipher & ssid->group_cipher) &&
941 (ie.pairwise_cipher & ssid->pairwise_cipher) &&
942 (ie.key_mgmt & ssid->key_mgmt)) {
943 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using IEEE 802.11i/D3.0");
944 proto = WPA_PROTO_WPA;
945 } else if (bss) {
946 wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select WPA/RSN");
947 return -1;
948 } else {
949 if (ssid->proto & WPA_PROTO_RSN)
950 proto = WPA_PROTO_RSN;
951 else
952 proto = WPA_PROTO_WPA;
953 if (wpa_supplicant_suites_from_ai(wpa_s, ssid, &ie) < 0) {
954 os_memset(&ie, 0, sizeof(ie));
955 ie.group_cipher = ssid->group_cipher;
956 ie.pairwise_cipher = ssid->pairwise_cipher;
957 ie.key_mgmt = ssid->key_mgmt;
958 #ifdef CONFIG_IEEE80211W
959 ie.mgmt_group_cipher =
960 ssid->ieee80211w != NO_MGMT_FRAME_PROTECTION ?
961 WPA_CIPHER_AES_128_CMAC : 0;
962 #endif /* CONFIG_IEEE80211W */
963 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Set cipher suites "
964 "based on configuration");
965 } else
966 proto = ie.proto;
967 }
968
969 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Selected cipher suites: group %d "
970 "pairwise %d key_mgmt %d proto %d",
971 ie.group_cipher, ie.pairwise_cipher, ie.key_mgmt, proto);
972 #ifdef CONFIG_IEEE80211W
973 if (ssid->ieee80211w) {
974 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Selected mgmt group cipher %d",
975 ie.mgmt_group_cipher);
976 }
977 #endif /* CONFIG_IEEE80211W */
978
979 wpa_s->wpa_proto = proto;
980 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, proto);
981 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
982 !!(ssid->proto & WPA_PROTO_RSN));
983
984 if (bss || !wpa_s->ap_ies_from_associnfo) {
985 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
986 bss_wpa ? 2 + bss_wpa[1] : 0) ||
987 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
988 bss_rsn ? 2 + bss_rsn[1] : 0))
989 return -1;
990 }
991
992 sel = ie.group_cipher & ssid->group_cipher;
993 if (sel & WPA_CIPHER_CCMP) {
994 wpa_s->group_cipher = WPA_CIPHER_CCMP;
995 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK CCMP");
996 } else if (sel & WPA_CIPHER_TKIP) {
997 wpa_s->group_cipher = WPA_CIPHER_TKIP;
998 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK TKIP");
999 } else if (sel & WPA_CIPHER_WEP104) {
1000 wpa_s->group_cipher = WPA_CIPHER_WEP104;
1001 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK WEP104");
1002 } else if (sel & WPA_CIPHER_WEP40) {
1003 wpa_s->group_cipher = WPA_CIPHER_WEP40;
1004 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK WEP40");
1005 } else {
1006 wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select group "
1007 "cipher");
1008 return -1;
1009 }
1010
1011 sel = ie.pairwise_cipher & ssid->pairwise_cipher;
1012 if (sel & WPA_CIPHER_CCMP) {
1013 wpa_s->pairwise_cipher = WPA_CIPHER_CCMP;
1014 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK CCMP");
1015 } else if (sel & WPA_CIPHER_TKIP) {
1016 wpa_s->pairwise_cipher = WPA_CIPHER_TKIP;
1017 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK TKIP");
1018 } else if (sel & WPA_CIPHER_NONE) {
1019 wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
1020 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK NONE");
1021 } else {
1022 wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select pairwise "
1023 "cipher");
1024 return -1;
1025 }
1026
1027 sel = ie.key_mgmt & ssid->key_mgmt;
1028 if (0) {
1029 #ifdef CONFIG_IEEE80211R
1030 } else if (sel & WPA_KEY_MGMT_FT_IEEE8021X) {
1031 wpa_s->key_mgmt = WPA_KEY_MGMT_FT_IEEE8021X;
1032 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FT/802.1X");
1033 } else if (sel & WPA_KEY_MGMT_FT_PSK) {
1034 wpa_s->key_mgmt = WPA_KEY_MGMT_FT_PSK;
1035 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FT/PSK");
1036 #endif /* CONFIG_IEEE80211R */
1037 #ifdef CONFIG_IEEE80211W
1038 } else if (sel & WPA_KEY_MGMT_IEEE8021X_SHA256) {
1039 wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_SHA256;
1040 wpa_dbg(wpa_s, MSG_DEBUG,
1041 "WPA: using KEY_MGMT 802.1X with SHA256");
1042 } else if (sel & WPA_KEY_MGMT_PSK_SHA256) {
1043 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK_SHA256;
1044 wpa_dbg(wpa_s, MSG_DEBUG,
1045 "WPA: using KEY_MGMT PSK with SHA256");
1046 #endif /* CONFIG_IEEE80211W */
1047 } else if (sel & WPA_KEY_MGMT_IEEE8021X) {
1048 wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X;
1049 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT 802.1X");
1050 } else if (sel & WPA_KEY_MGMT_PSK) {
1051 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
1052 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT WPA-PSK");
1053 } else if (sel & WPA_KEY_MGMT_WPA_NONE) {
1054 wpa_s->key_mgmt = WPA_KEY_MGMT_WPA_NONE;
1055 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT WPA-NONE");
1056 } else {
1057 wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select "
1058 "authenticated key management type");
1059 return -1;
1060 }
1061
1062 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
1063 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
1064 wpa_s->pairwise_cipher);
1065 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
1066
1067 #ifdef CONFIG_IEEE80211W
1068 sel = ie.mgmt_group_cipher;
1069 if (ssid->ieee80211w == NO_MGMT_FRAME_PROTECTION ||
1070 !(ie.capabilities & WPA_CAPABILITY_MFPC))
1071 sel = 0;
1072 if (sel & WPA_CIPHER_AES_128_CMAC) {
1073 wpa_s->mgmt_group_cipher = WPA_CIPHER_AES_128_CMAC;
1074 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher "
1075 "AES-128-CMAC");
1076 } else {
1077 wpa_s->mgmt_group_cipher = 0;
1078 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
1079 }
1080 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
1081 wpa_s->mgmt_group_cipher);
1082 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, ssid->ieee80211w);
1083 #endif /* CONFIG_IEEE80211W */
1084
1085 if (wpa_sm_set_assoc_wpa_ie_default(wpa_s->wpa, wpa_ie, wpa_ie_len)) {
1086 wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to generate WPA IE");
1087 return -1;
1088 }
1089
1090 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt)) {
1091 wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN);
1092 #ifndef CONFIG_NO_PBKDF2
1093 if (bss && ssid->bssid_set && ssid->ssid_len == 0 &&
1094 ssid->passphrase) {
1095 u8 psk[PMK_LEN];
1096 pbkdf2_sha1(ssid->passphrase, (char *) bss->ssid,
1097 bss->ssid_len, 4096, psk, PMK_LEN);
1098 wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
1099 psk, PMK_LEN);
1100 wpa_sm_set_pmk(wpa_s->wpa, psk, PMK_LEN);
1101 }
1102 #endif /* CONFIG_NO_PBKDF2 */
1103 } else
1104 wpa_sm_set_pmk_from_pmksa(wpa_s->wpa);
1105
1106 return 0;
1107 }
1108
1109
1110 /**
1111 * wpa_supplicant_associate - Request association
1112 * @wpa_s: Pointer to wpa_supplicant data
1113 * @bss: Scan results for the selected BSS, or %NULL if not available
1114 * @ssid: Configuration data for the selected network
1115 *
1116 * This function is used to request %wpa_supplicant to associate with a BSS.
1117 */
1118 void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
1119 struct wpa_bss *bss, struct wpa_ssid *ssid)
1120 {
1121 u8 wpa_ie[200];
1122 size_t wpa_ie_len;
1123 int use_crypt, ret, i, bssid_changed;
1124 int algs = WPA_AUTH_ALG_OPEN;
1125 enum wpa_cipher cipher_pairwise, cipher_group;
1126 struct wpa_driver_associate_params params;
1127 int wep_keys_set = 0;
1128 struct wpa_driver_capa capa;
1129 int assoc_failed = 0;
1130 struct wpa_ssid *old_ssid;
1131 #ifdef CONFIG_HT_OVERRIDES
1132 struct ieee80211_ht_capabilities htcaps;
1133 struct ieee80211_ht_capabilities htcaps_mask;
1134 #endif /* CONFIG_HT_OVERRIDES */
1135
1136 #ifdef CONFIG_IBSS_RSN
1137 ibss_rsn_deinit(wpa_s->ibss_rsn);
1138 wpa_s->ibss_rsn = NULL;
1139 #endif /* CONFIG_IBSS_RSN */
1140
1141 if (ssid->mode == WPAS_MODE_AP || ssid->mode == WPAS_MODE_P2P_GO ||
1142 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
1143 #ifdef CONFIG_AP
1144 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP)) {
1145 wpa_msg(wpa_s, MSG_INFO, "Driver does not support AP "
1146 "mode");
1147 return;
1148 }
1149 wpa_supplicant_create_ap(wpa_s, ssid);
1150 wpa_s->current_bss = bss;
1151 #else /* CONFIG_AP */
1152 wpa_msg(wpa_s, MSG_ERROR, "AP mode support not included in "
1153 "the build");
1154 #endif /* CONFIG_AP */
1155 return;
1156 }
1157
1158 #ifdef CONFIG_TDLS
1159 if (bss)
1160 wpa_tdls_ap_ies(wpa_s->wpa, (const u8 *) (bss + 1),
1161 bss->ie_len);
1162 #endif /* CONFIG_TDLS */
1163
1164 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1165 ssid->mode == IEEE80211_MODE_INFRA) {
1166 sme_authenticate(wpa_s, bss, ssid);
1167 return;
1168 }
1169
1170 os_memset(&params, 0, sizeof(params));
1171 wpa_s->reassociate = 0;
1172 if (bss && !wpas_driver_bss_selection(wpa_s)) {
1173 #ifdef CONFIG_IEEE80211R
1174 const u8 *ie, *md = NULL;
1175 #endif /* CONFIG_IEEE80211R */
1176 wpa_msg(wpa_s, MSG_INFO, "Trying to associate with " MACSTR
1177 " (SSID='%s' freq=%d MHz)", MAC2STR(bss->bssid),
1178 wpa_ssid_txt(bss->ssid, bss->ssid_len), bss->freq);
1179 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
1180 os_memset(wpa_s->bssid, 0, ETH_ALEN);
1181 os_memcpy(wpa_s->pending_bssid, bss->bssid, ETH_ALEN);
1182 if (bssid_changed)
1183 wpas_notify_bssid_changed(wpa_s);
1184 #ifdef CONFIG_IEEE80211R
1185 ie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
1186 if (ie && ie[1] >= MOBILITY_DOMAIN_ID_LEN)
1187 md = ie + 2;
1188 wpa_sm_set_ft_params(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0);
1189 if (md) {
1190 /* Prepare for the next transition */
1191 wpa_ft_prepare_auth_request(wpa_s->wpa, ie);
1192 }
1193 #endif /* CONFIG_IEEE80211R */
1194 #ifdef CONFIG_WPS
1195 } else if ((ssid->ssid == NULL || ssid->ssid_len == 0) &&
1196 wpa_s->conf->ap_scan == 2 &&
1197 (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1198 /* Use ap_scan==1 style network selection to find the network
1199 */
1200 wpa_s->scan_req = 2;
1201 wpa_s->reassociate = 1;
1202 wpa_supplicant_req_scan(wpa_s, 0, 0);
1203 return;
1204 #endif /* CONFIG_WPS */
1205 } else {
1206 wpa_msg(wpa_s, MSG_INFO, "Trying to associate with SSID '%s'",
1207 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
1208 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1209 }
1210 wpa_supplicant_cancel_sched_scan(wpa_s);
1211 wpa_supplicant_cancel_scan(wpa_s);
1212
1213 /* Starting new association, so clear the possibly used WPA IE from the
1214 * previous association. */
1215 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1216
1217 #ifdef IEEE8021X_EAPOL
1218 if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1219 if (ssid->leap) {
1220 if (ssid->non_leap == 0)
1221 algs = WPA_AUTH_ALG_LEAP;
1222 else
1223 algs |= WPA_AUTH_ALG_LEAP;
1224 }
1225 }
1226 #endif /* IEEE8021X_EAPOL */
1227 wpa_dbg(wpa_s, MSG_DEBUG, "Automatic auth_alg selection: 0x%x", algs);
1228 if (ssid->auth_alg) {
1229 algs = ssid->auth_alg;
1230 wpa_dbg(wpa_s, MSG_DEBUG, "Overriding auth_alg selection: "
1231 "0x%x", algs);
1232 }
1233
1234 if (bss && (wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE) ||
1235 wpa_bss_get_ie(bss, WLAN_EID_RSN)) &&
1236 wpa_key_mgmt_wpa(ssid->key_mgmt)) {
1237 int try_opportunistic;
1238 try_opportunistic = ssid->proactive_key_caching &&
1239 (ssid->proto & WPA_PROTO_RSN);
1240 if (pmksa_cache_set_current(wpa_s->wpa, NULL, bss->bssid,
1241 wpa_s->current_ssid,
1242 try_opportunistic) == 0)
1243 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
1244 wpa_ie_len = sizeof(wpa_ie);
1245 if (wpa_supplicant_set_suites(wpa_s, bss, ssid,
1246 wpa_ie, &wpa_ie_len)) {
1247 wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to set WPA "
1248 "key management and encryption suites");
1249 return;
1250 }
1251 } else if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
1252 wpa_ie_len = sizeof(wpa_ie);
1253 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
1254 wpa_ie, &wpa_ie_len)) {
1255 wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to set WPA "
1256 "key management and encryption suites (no "
1257 "scan results)");
1258 return;
1259 }
1260 #ifdef CONFIG_WPS
1261 } else if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
1262 struct wpabuf *wps_ie;
1263 wps_ie = wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid));
1264 if (wps_ie && wpabuf_len(wps_ie) <= sizeof(wpa_ie)) {
1265 wpa_ie_len = wpabuf_len(wps_ie);
1266 os_memcpy(wpa_ie, wpabuf_head(wps_ie), wpa_ie_len);
1267 } else
1268 wpa_ie_len = 0;
1269 wpabuf_free(wps_ie);
1270 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
1271 if (!bss || (bss->caps & IEEE80211_CAP_PRIVACY))
1272 params.wps = WPS_MODE_PRIVACY;
1273 else
1274 params.wps = WPS_MODE_OPEN;
1275 wpa_s->wpa_proto = 0;
1276 #endif /* CONFIG_WPS */
1277 } else {
1278 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
1279 wpa_ie_len = 0;
1280 wpa_s->wpa_proto = 0;
1281 }
1282
1283 #ifdef CONFIG_P2P
1284 if (wpa_s->global->p2p) {
1285 u8 *pos;
1286 size_t len;
1287 int res;
1288 pos = wpa_ie + wpa_ie_len;
1289 len = sizeof(wpa_ie) - wpa_ie_len;
1290 res = wpas_p2p_assoc_req_ie(wpa_s, bss, pos, len,
1291 ssid->p2p_group);
1292 if (res >= 0)
1293 wpa_ie_len += res;
1294 }
1295
1296 wpa_s->cross_connect_disallowed = 0;
1297 if (bss) {
1298 struct wpabuf *p2p;
1299 p2p = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
1300 if (p2p) {
1301 wpa_s->cross_connect_disallowed =
1302 p2p_get_cross_connect_disallowed(p2p);
1303 wpabuf_free(p2p);
1304 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: WLAN AP %s cross "
1305 "connection",
1306 wpa_s->cross_connect_disallowed ?
1307 "disallows" : "allows");
1308 }
1309 }
1310 #endif /* CONFIG_P2P */
1311
1312 #ifdef CONFIG_HS20
1313 if (wpa_s->conf->hs20) {
1314 struct wpabuf *hs20;
1315 hs20 = wpabuf_alloc(20);
1316 if (hs20) {
1317 wpas_hs20_add_indication(hs20);
1318 os_memcpy(wpa_ie + wpa_ie_len, wpabuf_head(hs20),
1319 wpabuf_len(hs20));
1320 wpa_ie_len += wpabuf_len(hs20);
1321 wpabuf_free(hs20);
1322 }
1323 }
1324 #endif /* CONFIG_HS20 */
1325
1326 #ifdef CONFIG_INTERWORKING
1327 if (wpa_s->conf->interworking) {
1328 u8 *pos = wpa_ie;
1329 if (wpa_ie_len > 0 && pos[0] == WLAN_EID_RSN)
1330 pos += 2 + pos[1];
1331 os_memmove(pos + 6, pos, wpa_ie_len - (pos - wpa_ie));
1332 wpa_ie_len += 6;
1333 *pos++ = WLAN_EID_EXT_CAPAB;
1334 *pos++ = 4;
1335 *pos++ = 0x00;
1336 *pos++ = 0x00;
1337 *pos++ = 0x00;
1338 *pos++ = 0x80; /* Bit 31 - Interworking */
1339 }
1340 #endif /* CONFIG_INTERWORKING */
1341
1342 wpa_clear_keys(wpa_s, bss ? bss->bssid : NULL);
1343 use_crypt = 1;
1344 cipher_pairwise = cipher_suite2driver(wpa_s->pairwise_cipher);
1345 cipher_group = cipher_suite2driver(wpa_s->group_cipher);
1346 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1347 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1348 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE)
1349 use_crypt = 0;
1350 if (wpa_set_wep_keys(wpa_s, ssid)) {
1351 use_crypt = 1;
1352 wep_keys_set = 1;
1353 }
1354 }
1355 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)
1356 use_crypt = 0;
1357
1358 #ifdef IEEE8021X_EAPOL
1359 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1360 if ((ssid->eapol_flags &
1361 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
1362 EAPOL_FLAG_REQUIRE_KEY_BROADCAST)) == 0 &&
1363 !wep_keys_set) {
1364 use_crypt = 0;
1365 } else {
1366 /* Assume that dynamic WEP-104 keys will be used and
1367 * set cipher suites in order for drivers to expect
1368 * encryption. */
1369 cipher_pairwise = cipher_group = CIPHER_WEP104;
1370 }
1371 }
1372 #endif /* IEEE8021X_EAPOL */
1373
1374 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1375 /* Set the key before (and later after) association */
1376 wpa_supplicant_set_wpa_none_key(wpa_s, ssid);
1377 }
1378
1379 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATING);
1380 if (bss) {
1381 params.ssid = bss->ssid;
1382 params.ssid_len = bss->ssid_len;
1383 if (!wpas_driver_bss_selection(wpa_s) || ssid->bssid_set) {
1384 wpa_printf(MSG_DEBUG, "Limit connection to BSSID "
1385 MACSTR " freq=%u MHz based on scan results "
1386 "(bssid_set=%d)",
1387 MAC2STR(bss->bssid), bss->freq,
1388 ssid->bssid_set);
1389 params.bssid = bss->bssid;
1390 params.freq = bss->freq;
1391 }
1392 } else {
1393 params.ssid = ssid->ssid;
1394 params.ssid_len = ssid->ssid_len;
1395 }
1396
1397 if (ssid->mode == WPAS_MODE_IBSS && ssid->bssid_set &&
1398 wpa_s->conf->ap_scan == 2) {
1399 params.bssid = ssid->bssid;
1400 params.fixed_bssid = 1;
1401 }
1402
1403 if (ssid->mode == WPAS_MODE_IBSS && ssid->frequency > 0 &&
1404 params.freq == 0)
1405 params.freq = ssid->frequency; /* Initial channel for IBSS */
1406 params.wpa_ie = wpa_ie;
1407 params.wpa_ie_len = wpa_ie_len;
1408 params.pairwise_suite = cipher_pairwise;
1409 params.group_suite = cipher_group;
1410 params.key_mgmt_suite = key_mgmt2driver(wpa_s->key_mgmt);
1411 params.wpa_proto = wpa_s->wpa_proto;
1412 params.auth_alg = algs;
1413 params.mode = ssid->mode;
1414 params.bg_scan_period = ssid->bg_scan_period;
1415 for (i = 0; i < NUM_WEP_KEYS; i++) {
1416 if (ssid->wep_key_len[i])
1417 params.wep_key[i] = ssid->wep_key[i];
1418 params.wep_key_len[i] = ssid->wep_key_len[i];
1419 }
1420 params.wep_tx_keyidx = ssid->wep_tx_keyidx;
1421
1422 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1423 (params.key_mgmt_suite == KEY_MGMT_PSK ||
1424 params.key_mgmt_suite == KEY_MGMT_FT_PSK)) {
1425 params.passphrase = ssid->passphrase;
1426 if (ssid->psk_set)
1427 params.psk = ssid->psk;
1428 }
1429
1430 params.drop_unencrypted = use_crypt;
1431
1432 #ifdef CONFIG_IEEE80211W
1433 params.mgmt_frame_protection = ssid->ieee80211w;
1434 if (ssid->ieee80211w != NO_MGMT_FRAME_PROTECTION && bss) {
1435 const u8 *rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1436 struct wpa_ie_data ie;
1437 if (rsn && wpa_parse_wpa_ie(rsn, 2 + rsn[1], &ie) == 0 &&
1438 ie.capabilities &
1439 (WPA_CAPABILITY_MFPC | WPA_CAPABILITY_MFPR)) {
1440 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Selected AP supports "
1441 "MFP: require MFP");
1442 params.mgmt_frame_protection =
1443 MGMT_FRAME_PROTECTION_REQUIRED;
1444 }
1445 }
1446 #endif /* CONFIG_IEEE80211W */
1447
1448 params.p2p = ssid->p2p_group;
1449
1450 if (wpa_s->parent->set_sta_uapsd)
1451 params.uapsd = wpa_s->parent->sta_uapsd;
1452 else
1453 params.uapsd = -1;
1454
1455 #ifdef CONFIG_HT_OVERRIDES
1456 os_memset(&htcaps, 0, sizeof(htcaps));
1457 os_memset(&htcaps_mask, 0, sizeof(htcaps_mask));
1458 params.htcaps = (u8 *) &htcaps;
1459 params.htcaps_mask = (u8 *) &htcaps_mask;
1460 wpa_supplicant_apply_ht_overrides(wpa_s, ssid, &params);
1461 #endif /* CONFIG_HT_OVERRIDES */
1462
1463 ret = wpa_drv_associate(wpa_s, &params);
1464 if (ret < 0) {
1465 wpa_msg(wpa_s, MSG_INFO, "Association request to the driver "
1466 "failed");
1467 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SANE_ERROR_CODES) {
1468 /*
1469 * The driver is known to mean what is saying, so we
1470 * can stop right here; the association will not
1471 * succeed.
1472 */
1473 wpas_connection_failed(wpa_s, wpa_s->pending_bssid);
1474 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1475 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1476 return;
1477 }
1478 /* try to continue anyway; new association will be tried again
1479 * after timeout */
1480 assoc_failed = 1;
1481 }
1482
1483 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1484 /* Set the key after the association just in case association
1485 * cleared the previously configured key. */
1486 wpa_supplicant_set_wpa_none_key(wpa_s, ssid);
1487 /* No need to timeout authentication since there is no key
1488 * management. */
1489 wpa_supplicant_cancel_auth_timeout(wpa_s);
1490 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1491 #ifdef CONFIG_IBSS_RSN
1492 } else if (ssid->mode == WPAS_MODE_IBSS &&
1493 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1494 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE) {
1495 /*
1496 * RSN IBSS authentication is per-STA and we can disable the
1497 * per-BSSID authentication.
1498 */
1499 wpa_supplicant_cancel_auth_timeout(wpa_s);
1500 #endif /* CONFIG_IBSS_RSN */
1501 } else {
1502 /* Timeout for IEEE 802.11 authentication and association */
1503 int timeout = 60;
1504
1505 if (assoc_failed) {
1506 /* give IBSS a bit more time */
1507 timeout = ssid->mode == WPAS_MODE_IBSS ? 10 : 5;
1508 } else if (wpa_s->conf->ap_scan == 1) {
1509 /* give IBSS a bit more time */
1510 timeout = ssid->mode == WPAS_MODE_IBSS ? 20 : 10;
1511 }
1512 wpa_supplicant_req_auth_timeout(wpa_s, timeout, 0);
1513 }
1514
1515 if (wep_keys_set && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1516 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC) {
1517 /* Set static WEP keys again */
1518 wpa_set_wep_keys(wpa_s, ssid);
1519 }
1520
1521 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid) {
1522 /*
1523 * Do not allow EAP session resumption between different
1524 * network configurations.
1525 */
1526 eapol_sm_invalidate_cached_session(wpa_s->eapol);
1527 }
1528 old_ssid = wpa_s->current_ssid;
1529 wpa_s->current_ssid = ssid;
1530 wpa_s->current_bss = bss;
1531 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
1532 wpa_supplicant_initiate_eapol(wpa_s);
1533 if (old_ssid != wpa_s->current_ssid)
1534 wpas_notify_network_changed(wpa_s);
1535 }
1536
1537
1538 static void wpa_supplicant_clear_connection(struct wpa_supplicant *wpa_s,
1539 const u8 *addr)
1540 {
1541 struct wpa_ssid *old_ssid;
1542
1543 wpa_clear_keys(wpa_s, addr);
1544 wpa_supplicant_mark_disassoc(wpa_s);
1545 old_ssid = wpa_s->current_ssid;
1546 wpa_s->current_ssid = NULL;
1547 wpa_s->current_bss = NULL;
1548 wpa_sm_set_config(wpa_s->wpa, NULL);
1549 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
1550 if (old_ssid != wpa_s->current_ssid)
1551 wpas_notify_network_changed(wpa_s);
1552 eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL);
1553 }
1554
1555
1556 /**
1557 * wpa_supplicant_disassociate - Disassociate the current connection
1558 * @wpa_s: Pointer to wpa_supplicant data
1559 * @reason_code: IEEE 802.11 reason code for the disassociate frame
1560 *
1561 * This function is used to request %wpa_supplicant to disassociate with the
1562 * current AP.
1563 */
1564 void wpa_supplicant_disassociate(struct wpa_supplicant *wpa_s,
1565 int reason_code)
1566 {
1567 u8 *addr = NULL;
1568 union wpa_event_data event;
1569
1570 if (!is_zero_ether_addr(wpa_s->bssid)) {
1571 wpa_drv_disassociate(wpa_s, wpa_s->bssid, reason_code);
1572 addr = wpa_s->bssid;
1573 os_memset(&event, 0, sizeof(event));
1574 event.disassoc_info.reason_code = (u16) reason_code;
1575 event.disassoc_info.locally_generated = 1;
1576 wpa_supplicant_event(wpa_s, EVENT_DISASSOC, &event);
1577 }
1578
1579 wpa_supplicant_clear_connection(wpa_s, addr);
1580 }
1581
1582
1583 /**
1584 * wpa_supplicant_deauthenticate - Deauthenticate the current connection
1585 * @wpa_s: Pointer to wpa_supplicant data
1586 * @reason_code: IEEE 802.11 reason code for the deauthenticate frame
1587 *
1588 * This function is used to request %wpa_supplicant to deauthenticate from the
1589 * current AP.
1590 */
1591 void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s,
1592 int reason_code)
1593 {
1594 u8 *addr = NULL;
1595 union wpa_event_data event;
1596
1597 if (!is_zero_ether_addr(wpa_s->bssid)) {
1598 wpa_drv_deauthenticate(wpa_s, wpa_s->bssid, reason_code);
1599 addr = wpa_s->bssid;
1600 os_memset(&event, 0, sizeof(event));
1601 event.deauth_info.reason_code = (u16) reason_code;
1602 event.deauth_info.locally_generated = 1;
1603 wpa_supplicant_event(wpa_s, EVENT_DEAUTH, &event);
1604 }
1605
1606 wpa_supplicant_clear_connection(wpa_s, addr);
1607 }
1608
1609
1610 /**
1611 * wpa_supplicant_enable_network - Mark a configured network as enabled
1612 * @wpa_s: wpa_supplicant structure for a network interface
1613 * @ssid: wpa_ssid structure for a configured network or %NULL
1614 *
1615 * Enables the specified network or all networks if no network specified.
1616 */
1617 void wpa_supplicant_enable_network(struct wpa_supplicant *wpa_s,
1618 struct wpa_ssid *ssid)
1619 {
1620 struct wpa_ssid *other_ssid;
1621 int was_disabled;
1622
1623 if (ssid == NULL) {
1624 for (other_ssid = wpa_s->conf->ssid; other_ssid;
1625 other_ssid = other_ssid->next) {
1626 if (other_ssid->disabled == 2)
1627 continue; /* do not change persistent P2P group
1628 * data */
1629 if (other_ssid == wpa_s->current_ssid &&
1630 other_ssid->disabled)
1631 wpa_s->reassociate = 1;
1632
1633 was_disabled = other_ssid->disabled;
1634
1635 other_ssid->disabled = 0;
1636
1637 if (was_disabled != other_ssid->disabled)
1638 wpas_notify_network_enabled_changed(
1639 wpa_s, other_ssid);
1640 }
1641 if (wpa_s->reassociate)
1642 wpa_supplicant_req_scan(wpa_s, 0, 0);
1643 } else if (ssid->disabled && ssid->disabled != 2) {
1644 if (wpa_s->current_ssid == NULL) {
1645 /*
1646 * Try to reassociate since there is no current
1647 * configuration and a new network was made available.
1648 */
1649 wpa_s->reassociate = 1;
1650 wpa_supplicant_req_scan(wpa_s, 0, 0);
1651 }
1652
1653 was_disabled = ssid->disabled;
1654
1655 ssid->disabled = 0;
1656
1657 if (was_disabled != ssid->disabled)
1658 wpas_notify_network_enabled_changed(wpa_s, ssid);
1659 }
1660 }
1661
1662
1663 /**
1664 * wpa_supplicant_disable_network - Mark a configured network as disabled
1665 * @wpa_s: wpa_supplicant structure for a network interface
1666 * @ssid: wpa_ssid structure for a configured network or %NULL
1667 *
1668 * Disables the specified network or all networks if no network specified.
1669 */
1670 void wpa_supplicant_disable_network(struct wpa_supplicant *wpa_s,
1671 struct wpa_ssid *ssid)
1672 {
1673 struct wpa_ssid *other_ssid;
1674 int was_disabled;
1675
1676 if (ssid == NULL) {
1677 for (other_ssid = wpa_s->conf->ssid; other_ssid;
1678 other_ssid = other_ssid->next) {
1679 was_disabled = other_ssid->disabled;
1680 if (was_disabled == 2)
1681 continue; /* do not change persistent P2P group
1682 * data */
1683
1684 other_ssid->disabled = 1;
1685
1686 if (was_disabled != other_ssid->disabled)
1687 wpas_notify_network_enabled_changed(
1688 wpa_s, other_ssid);
1689 }
1690 if (wpa_s->current_ssid)
1691 wpa_supplicant_disassociate(
1692 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1693 } else if (ssid->disabled != 2) {
1694 if (ssid == wpa_s->current_ssid)
1695 wpa_supplicant_disassociate(
1696 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1697
1698 was_disabled = ssid->disabled;
1699
1700 ssid->disabled = 1;
1701
1702 if (was_disabled != ssid->disabled)
1703 wpas_notify_network_enabled_changed(wpa_s, ssid);
1704 }
1705 }
1706
1707
1708 /**
1709 * wpa_supplicant_select_network - Attempt association with a network
1710 * @wpa_s: wpa_supplicant structure for a network interface
1711 * @ssid: wpa_ssid structure for a configured network or %NULL for any network
1712 */
1713 void wpa_supplicant_select_network(struct wpa_supplicant *wpa_s,
1714 struct wpa_ssid *ssid)
1715 {
1716
1717 struct wpa_ssid *other_ssid;
1718 int disconnected = 0;
1719
1720 if (ssid && ssid != wpa_s->current_ssid && wpa_s->current_ssid) {
1721 wpa_supplicant_disassociate(
1722 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1723 disconnected = 1;
1724 }
1725
1726 /*
1727 * Mark all other networks disabled or mark all networks enabled if no
1728 * network specified.
1729 */
1730 for (other_ssid = wpa_s->conf->ssid; other_ssid;
1731 other_ssid = other_ssid->next) {
1732 int was_disabled = other_ssid->disabled;
1733 if (was_disabled == 2)
1734 continue; /* do not change persistent P2P group data */
1735
1736 other_ssid->disabled = ssid ? (ssid->id != other_ssid->id) : 0;
1737
1738 if (was_disabled != other_ssid->disabled)
1739 wpas_notify_network_enabled_changed(wpa_s, other_ssid);
1740 }
1741
1742 if (ssid && ssid == wpa_s->current_ssid && wpa_s->current_ssid) {
1743 /* We are already associated with the selected network */
1744 wpa_printf(MSG_DEBUG, "Already associated with the "
1745 "selected network - do nothing");
1746 return;
1747 }
1748
1749 if (ssid)
1750 wpa_s->current_ssid = ssid;
1751 wpa_s->connect_without_scan = NULL;
1752 wpa_s->disconnected = 0;
1753 wpa_s->reassociate = 1;
1754 wpa_supplicant_req_scan(wpa_s, 0, disconnected ? 100000 : 0);
1755
1756 if (ssid)
1757 wpas_notify_network_selected(wpa_s, ssid);
1758 }
1759
1760
1761 /**
1762 * wpa_supplicant_set_ap_scan - Set AP scan mode for interface
1763 * @wpa_s: wpa_supplicant structure for a network interface
1764 * @ap_scan: AP scan mode
1765 * Returns: 0 if succeed or -1 if ap_scan has an invalid value
1766 *
1767 */
1768 int wpa_supplicant_set_ap_scan(struct wpa_supplicant *wpa_s, int ap_scan)
1769 {
1770
1771 int old_ap_scan;
1772
1773 if (ap_scan < 0 || ap_scan > 2)
1774 return -1;
1775
1776 #ifdef ANDROID
1777 if (ap_scan == 2 && ap_scan != wpa_s->conf->ap_scan &&
1778 wpa_s->wpa_state >= WPA_ASSOCIATING &&
1779 wpa_s->wpa_state < WPA_COMPLETED) {
1780 wpa_printf(MSG_ERROR, "ap_scan = %d (%d) rejected while "
1781 "associating", wpa_s->conf->ap_scan, ap_scan);
1782 return 0;
1783 }
1784 #endif /* ANDROID */
1785
1786 old_ap_scan = wpa_s->conf->ap_scan;
1787 wpa_s->conf->ap_scan = ap_scan;
1788
1789 if (old_ap_scan != wpa_s->conf->ap_scan)
1790 wpas_notify_ap_scan_changed(wpa_s);
1791
1792 return 0;
1793 }
1794
1795
1796 /**
1797 * wpa_supplicant_set_bss_expiration_age - Set BSS entry expiration age
1798 * @wpa_s: wpa_supplicant structure for a network interface
1799 * @expire_age: Expiration age in seconds
1800 * Returns: 0 if succeed or -1 if expire_age has an invalid value
1801 *
1802 */
1803 int wpa_supplicant_set_bss_expiration_age(struct wpa_supplicant *wpa_s,
1804 unsigned int bss_expire_age)
1805 {
1806 if (bss_expire_age < 10) {
1807 wpa_msg(wpa_s, MSG_ERROR, "Invalid bss expiration age %u",
1808 bss_expire_age);
1809 return -1;
1810 }
1811 wpa_msg(wpa_s, MSG_DEBUG, "Setting bss expiration age: %d sec",
1812 bss_expire_age);
1813 wpa_s->conf->bss_expiration_age = bss_expire_age;
1814
1815 return 0;
1816 }
1817
1818
1819 /**
1820 * wpa_supplicant_set_bss_expiration_count - Set BSS entry expiration scan count
1821 * @wpa_s: wpa_supplicant structure for a network interface
1822 * @expire_count: number of scans after which an unseen BSS is reclaimed
1823 * Returns: 0 if succeed or -1 if expire_count has an invalid value
1824 *
1825 */
1826 int wpa_supplicant_set_bss_expiration_count(struct wpa_supplicant *wpa_s,
1827 unsigned int bss_expire_count)
1828 {
1829 if (bss_expire_count < 1) {
1830 wpa_msg(wpa_s, MSG_ERROR, "Invalid bss expiration count %u",
1831 bss_expire_count);
1832 return -1;
1833 }
1834 wpa_msg(wpa_s, MSG_DEBUG, "Setting bss expiration scan count: %u",
1835 bss_expire_count);
1836 wpa_s->conf->bss_expiration_scan_count = bss_expire_count;
1837
1838 return 0;
1839 }
1840
1841
1842 /**
1843 * wpa_supplicant_set_scan_interval - Set scan interval
1844 * @wpa_s: wpa_supplicant structure for a network interface
1845 * @scan_interval: scan interval in seconds
1846 * Returns: 0 if succeed or -1 if scan_interval has an invalid value
1847 *
1848 */
1849 int wpa_supplicant_set_scan_interval(struct wpa_supplicant *wpa_s,
1850 int scan_interval)
1851 {
1852 if (scan_interval < 0) {
1853 wpa_msg(wpa_s, MSG_ERROR, "Invalid scan interval %d",
1854 scan_interval);
1855 return -1;
1856 }
1857 wpa_msg(wpa_s, MSG_DEBUG, "Setting scan interval: %d sec",
1858 scan_interval);
1859 wpa_s->scan_interval = scan_interval;
1860
1861 return 0;
1862 }
1863
1864
1865 /**
1866 * wpa_supplicant_set_debug_params - Set global debug params
1867 * @global: wpa_global structure
1868 * @debug_level: debug level
1869 * @debug_timestamp: determines if show timestamp in debug data
1870 * @debug_show_keys: determines if show keys in debug data
1871 * Returns: 0 if succeed or -1 if debug_level has wrong value
1872 */
1873 int wpa_supplicant_set_debug_params(struct wpa_global *global, int debug_level,
1874 int debug_timestamp, int debug_show_keys)
1875 {
1876
1877 int old_level, old_timestamp, old_show_keys;
1878
1879 /* check for allowed debuglevels */
1880 if (debug_level != MSG_EXCESSIVE &&
1881 debug_level != MSG_MSGDUMP &&
1882 debug_level != MSG_DEBUG &&
1883 debug_level != MSG_INFO &&
1884 debug_level != MSG_WARNING &&
1885 debug_level != MSG_ERROR)
1886 return -1;
1887
1888 old_level = wpa_debug_level;
1889 old_timestamp = wpa_debug_timestamp;
1890 old_show_keys = wpa_debug_show_keys;
1891
1892 wpa_debug_level = debug_level;
1893 wpa_debug_timestamp = debug_timestamp ? 1 : 0;
1894 wpa_debug_show_keys = debug_show_keys ? 1 : 0;
1895
1896 if (wpa_debug_level != old_level)
1897 wpas_notify_debug_level_changed(global);
1898 if (wpa_debug_timestamp != old_timestamp)
1899 wpas_notify_debug_timestamp_changed(global);
1900 if (wpa_debug_show_keys != old_show_keys)
1901 wpas_notify_debug_show_keys_changed(global);
1902
1903 return 0;
1904 }
1905
1906
1907 /**
1908 * wpa_supplicant_get_ssid - Get a pointer to the current network structure
1909 * @wpa_s: Pointer to wpa_supplicant data
1910 * Returns: A pointer to the current network structure or %NULL on failure
1911 */
1912 struct wpa_ssid * wpa_supplicant_get_ssid(struct wpa_supplicant *wpa_s)
1913 {
1914 struct wpa_ssid *entry;
1915 u8 ssid[MAX_SSID_LEN];
1916 int res;
1917 size_t ssid_len;
1918 u8 bssid[ETH_ALEN];
1919 int wired;
1920
1921 res = wpa_drv_get_ssid(wpa_s, ssid);
1922 if (res < 0) {
1923 wpa_msg(wpa_s, MSG_WARNING, "Could not read SSID from "
1924 "driver");
1925 return NULL;
1926 }
1927 ssid_len = res;
1928
1929 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1930 wpa_msg(wpa_s, MSG_WARNING, "Could not read BSSID from "
1931 "driver");
1932 return NULL;
1933 }
1934
1935 wired = wpa_s->conf->ap_scan == 0 &&
1936 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED);
1937
1938 entry = wpa_s->conf->ssid;
1939 while (entry) {
1940 if (!wpas_network_disabled(wpa_s, entry) &&
1941 ((ssid_len == entry->ssid_len &&
1942 os_memcmp(ssid, entry->ssid, ssid_len) == 0) || wired) &&
1943 (!entry->bssid_set ||
1944 os_memcmp(bssid, entry->bssid, ETH_ALEN) == 0))
1945 return entry;
1946 #ifdef CONFIG_WPS
1947 if (!wpas_network_disabled(wpa_s, entry) &&
1948 (entry->key_mgmt & WPA_KEY_MGMT_WPS) &&
1949 (entry->ssid == NULL || entry->ssid_len == 0) &&
1950 (!entry->bssid_set ||
1951 os_memcmp(bssid, entry->bssid, ETH_ALEN) == 0))
1952 return entry;
1953 #endif /* CONFIG_WPS */
1954
1955 if (!wpas_network_disabled(wpa_s, entry) && entry->bssid_set &&
1956 entry->ssid_len == 0 &&
1957 os_memcmp(bssid, entry->bssid, ETH_ALEN) == 0)
1958 return entry;
1959
1960 entry = entry->next;
1961 }
1962
1963 return NULL;
1964 }
1965
1966
1967 static int select_driver(struct wpa_supplicant *wpa_s, int i)
1968 {
1969 struct wpa_global *global = wpa_s->global;
1970
1971 if (wpa_drivers[i]->global_init && global->drv_priv[i] == NULL) {
1972 global->drv_priv[i] = wpa_drivers[i]->global_init();
1973 if (global->drv_priv[i] == NULL) {
1974 wpa_printf(MSG_ERROR, "Failed to initialize driver "
1975 "'%s'", wpa_drivers[i]->name);
1976 return -1;
1977 }
1978 }
1979
1980 wpa_s->driver = wpa_drivers[i];
1981 wpa_s->global_drv_priv = global->drv_priv[i];
1982
1983 return 0;
1984 }
1985
1986
1987 static int wpa_supplicant_set_driver(struct wpa_supplicant *wpa_s,
1988 const char *name)
1989 {
1990 int i;
1991 size_t len;
1992 const char *pos, *driver = name;
1993
1994 if (wpa_s == NULL)
1995 return -1;
1996
1997 if (wpa_drivers[0] == NULL) {
1998 wpa_msg(wpa_s, MSG_ERROR, "No driver interfaces build into "
1999 "wpa_supplicant");
2000 return -1;
2001 }
2002
2003 if (name == NULL) {
2004 /* default to first driver in the list */
2005 return select_driver(wpa_s, 0);
2006 }
2007
2008 do {
2009 pos = os_strchr(driver, ',');
2010 if (pos)
2011 len = pos - driver;
2012 else
2013 len = os_strlen(driver);
2014
2015 for (i = 0; wpa_drivers[i]; i++) {
2016 if (os_strlen(wpa_drivers[i]->name) == len &&
2017 os_strncmp(driver, wpa_drivers[i]->name, len) ==
2018 0) {
2019 /* First driver that succeeds wins */
2020 if (select_driver(wpa_s, i) == 0)
2021 return 0;
2022 }
2023 }
2024
2025 driver = pos + 1;
2026 } while (pos);
2027
2028 wpa_msg(wpa_s, MSG_ERROR, "Unsupported driver '%s'", name);
2029 return -1;
2030 }
2031
2032
2033 /**
2034 * wpa_supplicant_rx_eapol - Deliver a received EAPOL frame to wpa_supplicant
2035 * @ctx: Context pointer (wpa_s); this is the ctx variable registered
2036 * with struct wpa_driver_ops::init()
2037 * @src_addr: Source address of the EAPOL frame
2038 * @buf: EAPOL data starting from the EAPOL header (i.e., no Ethernet header)
2039 * @len: Length of the EAPOL data
2040 *
2041 * This function is called for each received EAPOL frame. Most driver
2042 * interfaces rely on more generic OS mechanism for receiving frames through
2043 * l2_packet, but if such a mechanism is not available, the driver wrapper may
2044 * take care of received EAPOL frames and deliver them to the core supplicant
2045 * code by calling this function.
2046 */
2047 void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr,
2048 const u8 *buf, size_t len)
2049 {
2050 struct wpa_supplicant *wpa_s = ctx;
2051
2052 wpa_dbg(wpa_s, MSG_DEBUG, "RX EAPOL from " MACSTR, MAC2STR(src_addr));
2053 wpa_hexdump(MSG_MSGDUMP, "RX EAPOL", buf, len);
2054
2055 if (wpa_s->wpa_state < WPA_ASSOCIATED) {
2056 /*
2057 * There is possible race condition between receiving the
2058 * association event and the EAPOL frame since they are coming
2059 * through different paths from the driver. In order to avoid
2060 * issues in trying to process the EAPOL frame before receiving
2061 * association information, lets queue it for processing until
2062 * the association event is received.
2063 */
2064 wpa_dbg(wpa_s, MSG_DEBUG, "Not associated - Delay processing "
2065 "of received EAPOL frame");
2066 wpabuf_free(wpa_s->pending_eapol_rx);
2067 wpa_s->pending_eapol_rx = wpabuf_alloc_copy(buf, len);
2068 if (wpa_s->pending_eapol_rx) {
2069 os_get_time(&wpa_s->pending_eapol_rx_time);
2070 os_memcpy(wpa_s->pending_eapol_rx_src, src_addr,
2071 ETH_ALEN);
2072 }
2073 return;
2074 }
2075
2076 #ifdef CONFIG_AP
2077 if (wpa_s->ap_iface) {
2078 wpa_supplicant_ap_rx_eapol(wpa_s, src_addr, buf, len);
2079 return;
2080 }
2081 #endif /* CONFIG_AP */
2082
2083 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE) {
2084 wpa_dbg(wpa_s, MSG_DEBUG, "Ignored received EAPOL frame since "
2085 "no key management is configured");
2086 return;
2087 }
2088
2089 if (wpa_s->eapol_received == 0 &&
2090 (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) ||
2091 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
2092 wpa_s->wpa_state != WPA_COMPLETED) &&
2093 (wpa_s->current_ssid == NULL ||
2094 wpa_s->current_ssid->mode != IEEE80211_MODE_IBSS)) {
2095 /* Timeout for completing IEEE 802.1X and WPA authentication */
2096 wpa_supplicant_req_auth_timeout(
2097 wpa_s,
2098 (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2099 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA ||
2100 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) ?
2101 70 : 10, 0);
2102 }
2103 wpa_s->eapol_received++;
2104
2105 if (wpa_s->countermeasures) {
2106 wpa_msg(wpa_s, MSG_INFO, "WPA: Countermeasures - dropped "
2107 "EAPOL packet");
2108 return;
2109 }
2110
2111 #ifdef CONFIG_IBSS_RSN
2112 if (wpa_s->current_ssid &&
2113 wpa_s->current_ssid->mode == WPAS_MODE_IBSS) {
2114 ibss_rsn_rx_eapol(wpa_s->ibss_rsn, src_addr, buf, len);
2115 return;
2116 }
2117 #endif /* CONFIG_IBSS_RSN */
2118
2119 /* Source address of the incoming EAPOL frame could be compared to the
2120 * current BSSID. However, it is possible that a centralized
2121 * Authenticator could be using another MAC address than the BSSID of
2122 * an AP, so just allow any address to be used for now. The replies are
2123 * still sent to the current BSSID (if available), though. */
2124
2125 os_memcpy(wpa_s->last_eapol_src, src_addr, ETH_ALEN);
2126 if (!wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) &&
2127 eapol_sm_rx_eapol(wpa_s->eapol, src_addr, buf, len) > 0)
2128 return;
2129 wpa_drv_poll(wpa_s);
2130 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE))
2131 wpa_sm_rx_eapol(wpa_s->wpa, src_addr, buf, len);
2132 else if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2133 /*
2134 * Set portValid = TRUE here since we are going to skip 4-way
2135 * handshake processing which would normally set portValid. We
2136 * need this to allow the EAPOL state machines to be completed
2137 * without going through EAPOL-Key handshake.
2138 */
2139 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2140 }
2141 }
2142
2143
2144 int wpa_supplicant_update_mac_addr(struct wpa_supplicant *wpa_s)
2145 {
2146 if (wpa_s->driver->send_eapol) {
2147 const u8 *addr = wpa_drv_get_mac_addr(wpa_s);
2148 if (addr)
2149 os_memcpy(wpa_s->own_addr, addr, ETH_ALEN);
2150 } else if (!(wpa_s->drv_flags &
2151 WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE)) {
2152 l2_packet_deinit(wpa_s->l2);
2153 wpa_s->l2 = l2_packet_init(wpa_s->ifname,
2154 wpa_drv_get_mac_addr(wpa_s),
2155 ETH_P_EAPOL,
2156 wpa_supplicant_rx_eapol, wpa_s, 0);
2157 if (wpa_s->l2 == NULL)
2158 return -1;
2159 } else {
2160 const u8 *addr = wpa_drv_get_mac_addr(wpa_s);
2161 if (addr)
2162 os_memcpy(wpa_s->own_addr, addr, ETH_ALEN);
2163 }
2164
2165 if (wpa_s->l2 && l2_packet_get_own_addr(wpa_s->l2, wpa_s->own_addr)) {
2166 wpa_msg(wpa_s, MSG_ERROR, "Failed to get own L2 address");
2167 return -1;
2168 }
2169
2170 wpa_dbg(wpa_s, MSG_DEBUG, "Own MAC address: " MACSTR,
2171 MAC2STR(wpa_s->own_addr));
2172 wpa_sm_set_own_addr(wpa_s->wpa, wpa_s->own_addr);
2173
2174 return 0;
2175 }
2176
2177
2178 static void wpa_supplicant_rx_eapol_bridge(void *ctx, const u8 *src_addr,
2179 const u8 *buf, size_t len)
2180 {
2181 struct wpa_supplicant *wpa_s = ctx;
2182 const struct l2_ethhdr *eth;
2183
2184 if (len < sizeof(*eth))
2185 return;
2186 eth = (const struct l2_ethhdr *) buf;
2187
2188 if (os_memcmp(eth->h_dest, wpa_s->own_addr, ETH_ALEN) != 0 &&
2189 !(eth->h_dest[0] & 0x01)) {
2190 wpa_dbg(wpa_s, MSG_DEBUG, "RX EAPOL from " MACSTR " to " MACSTR
2191 " (bridge - not for this interface - ignore)",
2192 MAC2STR(src_addr), MAC2STR(eth->h_dest));
2193 return;
2194 }
2195
2196 wpa_dbg(wpa_s, MSG_DEBUG, "RX EAPOL from " MACSTR " to " MACSTR
2197 " (bridge)", MAC2STR(src_addr), MAC2STR(eth->h_dest));
2198 wpa_supplicant_rx_eapol(wpa_s, src_addr, buf + sizeof(*eth),
2199 len - sizeof(*eth));
2200 }
2201
2202
2203 /**
2204 * wpa_supplicant_driver_init - Initialize driver interface parameters
2205 * @wpa_s: Pointer to wpa_supplicant data
2206 * Returns: 0 on success, -1 on failure
2207 *
2208 * This function is called to initialize driver interface parameters.
2209 * wpa_drv_init() must have been called before this function to initialize the
2210 * driver interface.
2211 */
2212 int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s)
2213 {
2214 static int interface_count = 0;
2215
2216 if (wpa_supplicant_update_mac_addr(wpa_s) < 0)
2217 return -1;
2218
2219 if (wpa_s->bridge_ifname[0]) {
2220 wpa_dbg(wpa_s, MSG_DEBUG, "Receiving packets from bridge "
2221 "interface '%s'", wpa_s->bridge_ifname);
2222 wpa_s->l2_br = l2_packet_init(wpa_s->bridge_ifname,
2223 wpa_s->own_addr,
2224 ETH_P_EAPOL,
2225 wpa_supplicant_rx_eapol_bridge,
2226 wpa_s, 1);
2227 if (wpa_s->l2_br == NULL) {
2228 wpa_msg(wpa_s, MSG_ERROR, "Failed to open l2_packet "
2229 "connection for the bridge interface '%s'",
2230 wpa_s->bridge_ifname);
2231 return -1;
2232 }
2233 }
2234
2235 wpa_clear_keys(wpa_s, NULL);
2236
2237 /* Make sure that TKIP countermeasures are not left enabled (could
2238 * happen if wpa_supplicant is killed during countermeasures. */
2239 wpa_drv_set_countermeasures(wpa_s, 0);
2240
2241 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: flushing PMKID list in the driver");
2242 wpa_drv_flush_pmkid(wpa_s);
2243
2244 wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN;
2245 wpa_s->prev_scan_wildcard = 0;
2246
2247 if (wpa_supplicant_enabled_networks(wpa_s)) {
2248 if (wpa_supplicant_delayed_sched_scan(wpa_s, interface_count,
2249 100000))
2250 wpa_supplicant_req_scan(wpa_s, interface_count,
2251 100000);
2252 interface_count++;
2253 } else
2254 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
2255
2256 return 0;
2257 }
2258
2259
2260 static int wpa_supplicant_daemon(const char *pid_file)
2261 {
2262 wpa_printf(MSG_DEBUG, "Daemonize..");
2263 return os_daemonize(pid_file);
2264 }
2265
2266
2267 static struct wpa_supplicant * wpa_supplicant_alloc(void)
2268 {
2269 struct wpa_supplicant *wpa_s;
2270
2271 wpa_s = os_zalloc(sizeof(*wpa_s));
2272 if (wpa_s == NULL)
2273 return NULL;
2274 wpa_s->scan_req = 1;
2275 wpa_s->scan_interval = 5;
2276 wpa_s->new_connection = 1;
2277 wpa_s->parent = wpa_s;
2278 wpa_s->sched_scanning = 0;
2279
2280 return wpa_s;
2281 }
2282
2283
2284 #ifdef CONFIG_HT_OVERRIDES
2285
2286 static int wpa_set_htcap_mcs(struct wpa_supplicant *wpa_s,
2287 struct ieee80211_ht_capabilities *htcaps,
2288 struct ieee80211_ht_capabilities *htcaps_mask,
2289 const char *ht_mcs)
2290 {
2291 /* parse ht_mcs into hex array */
2292 int i;
2293 const char *tmp = ht_mcs;
2294 char *end = NULL;
2295
2296 /* If ht_mcs is null, do not set anything */
2297 if (!ht_mcs)
2298 return 0;
2299
2300 /* This is what we are setting in the kernel */
2301 os_memset(&htcaps->supported_mcs_set, 0, IEEE80211_HT_MCS_MASK_LEN);
2302
2303 wpa_msg(wpa_s, MSG_DEBUG, "set_htcap, ht_mcs -:%s:-", ht_mcs);
2304
2305 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
2306 errno = 0;
2307 long v = strtol(tmp, &end, 16);
2308 if (errno == 0) {
2309 wpa_msg(wpa_s, MSG_DEBUG,
2310 "htcap value[%i]: %ld end: %p tmp: %p",
2311 i, v, end, tmp);
2312 if (end == tmp)
2313 break;
2314
2315 htcaps->supported_mcs_set[i] = v;
2316 tmp = end;
2317 } else {
2318 wpa_msg(wpa_s, MSG_ERROR,
2319 "Failed to parse ht-mcs: %s, error: %s\n",
2320 ht_mcs, strerror(errno));
2321 return -1;
2322 }
2323 }
2324
2325 /*
2326 * If we were able to parse any values, then set mask for the MCS set.
2327 */
2328 if (i) {
2329 os_memset(&htcaps_mask->supported_mcs_set, 0xff,
2330 IEEE80211_HT_MCS_MASK_LEN - 1);
2331 /* skip the 3 reserved bits */
2332 htcaps_mask->supported_mcs_set[IEEE80211_HT_MCS_MASK_LEN - 1] =
2333 0x1f;
2334 }
2335
2336 return 0;
2337 }
2338
2339
2340 static int wpa_disable_max_amsdu(struct wpa_supplicant *wpa_s,
2341 struct ieee80211_ht_capabilities *htcaps,
2342 struct ieee80211_ht_capabilities *htcaps_mask,
2343 int disabled)
2344 {
2345 u16 msk;
2346
2347 wpa_msg(wpa_s, MSG_DEBUG, "set_disable_max_amsdu: %d", disabled);
2348
2349 if (disabled == -1)
2350 return 0;
2351
2352 msk = host_to_le16(HT_CAP_INFO_MAX_AMSDU_SIZE);
2353 htcaps_mask->ht_capabilities_info |= msk;
2354 if (disabled)
2355 htcaps->ht_capabilities_info &= msk;
2356 else
2357 htcaps->ht_capabilities_info |= msk;
2358
2359 return 0;
2360 }
2361
2362
2363 static int wpa_set_ampdu_factor(struct wpa_supplicant *wpa_s,
2364 struct ieee80211_ht_capabilities *htcaps,
2365 struct ieee80211_ht_capabilities *htcaps_mask,
2366 int factor)
2367 {
2368 wpa_msg(wpa_s, MSG_DEBUG, "set_ampdu_factor: %d", factor);
2369
2370 if (factor == -1)
2371 return 0;
2372
2373 if (factor < 0 || factor > 3) {
2374 wpa_msg(wpa_s, MSG_ERROR, "ampdu_factor: %d out of range. "
2375 "Must be 0-3 or -1", factor);
2376 return -EINVAL;
2377 }
2378
2379 htcaps_mask->a_mpdu_params |= 0x3; /* 2 bits for factor */
2380 htcaps->a_mpdu_params &= ~0x3;
2381 htcaps->a_mpdu_params |= factor & 0x3;
2382
2383 return 0;
2384 }
2385
2386
2387 static int wpa_set_ampdu_density(struct wpa_supplicant *wpa_s,
2388 struct ieee80211_ht_capabilities *htcaps,
2389 struct ieee80211_ht_capabilities *htcaps_mask,
2390 int density)
2391 {
2392 wpa_msg(wpa_s, MSG_DEBUG, "set_ampdu_density: %d", density);
2393
2394 if (density == -1)
2395 return 0;
2396
2397 if (density < 0 || density > 7) {
2398 wpa_msg(wpa_s, MSG_ERROR,
2399 "ampdu_density: %d out of range. Must be 0-7 or -1.",
2400 density);
2401 return -EINVAL;
2402 }
2403
2404 htcaps_mask->a_mpdu_params |= 0x1C;
2405 htcaps->a_mpdu_params &= ~(0x1C);
2406 htcaps->a_mpdu_params |= (density << 2) & 0x1C;
2407
2408 return 0;
2409 }
2410
2411
2412 static int wpa_set_disable_ht40(struct wpa_supplicant *wpa_s,
2413 struct ieee80211_ht_capabilities *htcaps,
2414 struct ieee80211_ht_capabilities *htcaps_mask,
2415 int disabled)
2416 {
2417 /* Masking these out disables HT40 */
2418 u16 msk = host_to_le16(HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET |
2419 HT_CAP_INFO_SHORT_GI40MHZ);
2420
2421 wpa_msg(wpa_s, MSG_DEBUG, "set_disable_ht40: %d", disabled);
2422
2423 if (disabled)
2424 htcaps->ht_capabilities_info &= ~msk;
2425 else
2426 htcaps->ht_capabilities_info |= msk;
2427
2428 htcaps_mask->ht_capabilities_info |= msk;
2429
2430 return 0;
2431 }
2432
2433
2434 void wpa_supplicant_apply_ht_overrides(
2435 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
2436 struct wpa_driver_associate_params *params)
2437 {
2438 struct ieee80211_ht_capabilities *htcaps;
2439 struct ieee80211_ht_capabilities *htcaps_mask;
2440
2441 if (!ssid)
2442 return;
2443
2444 params->disable_ht = ssid->disable_ht;
2445 if (!params->htcaps || !params->htcaps_mask)
2446 return;
2447
2448 htcaps = (struct ieee80211_ht_capabilities *) params->htcaps;
2449 htcaps_mask = (struct ieee80211_ht_capabilities *) params->htcaps_mask;
2450 wpa_set_htcap_mcs(wpa_s, htcaps, htcaps_mask, ssid->ht_mcs);
2451 wpa_disable_max_amsdu(wpa_s, htcaps, htcaps_mask,
2452 ssid->disable_max_amsdu);
2453 wpa_set_ampdu_factor(wpa_s, htcaps, htcaps_mask, ssid->ampdu_factor);
2454 wpa_set_ampdu_density(wpa_s, htcaps, htcaps_mask, ssid->ampdu_density);
2455 wpa_set_disable_ht40(wpa_s, htcaps, htcaps_mask, ssid->disable_ht40);
2456 }
2457
2458 #endif /* CONFIG_HT_OVERRIDES */
2459
2460
2461 static int pcsc_reader_init(struct wpa_supplicant *wpa_s)
2462 {
2463 #ifdef PCSC_FUNCS
2464 size_t len;
2465
2466 if (!wpa_s->conf->pcsc_reader)
2467 return 0;
2468
2469 wpa_s->scard = scard_init(SCARD_TRY_BOTH, wpa_s->conf->pcsc_reader);
2470 if (!wpa_s->scard)
2471 return 1;
2472
2473 if (wpa_s->conf->pcsc_pin &&
2474 scard_set_pin(wpa_s->scard, wpa_s->conf->pcsc_pin) < 0) {
2475 scard_deinit(wpa_s->scard);
2476 wpa_s->scard = NULL;
2477 wpa_msg(wpa_s, MSG_ERROR, "PC/SC PIN validation failed");
2478 return -1;
2479 }
2480
2481 len = sizeof(wpa_s->imsi) - 1;
2482 if (scard_get_imsi(wpa_s->scard, wpa_s->imsi, &len)) {
2483 scard_deinit(wpa_s->scard);
2484 wpa_s->scard = NULL;
2485 wpa_msg(wpa_s, MSG_ERROR, "Could not read IMSI");
2486 return -1;
2487 }
2488 wpa_s->imsi[len] = '\0';
2489
2490 wpa_s->mnc_len = scard_get_mnc_len(wpa_s->scard);
2491
2492 wpa_printf(MSG_DEBUG, "SCARD: IMSI %s (MNC length %d)",
2493 wpa_s->imsi, wpa_s->mnc_len);
2494
2495 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
2496 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
2497 #endif /* PCSC_FUNCS */
2498
2499 return 0;
2500 }
2501
2502
2503 static int wpa_supplicant_init_iface(struct wpa_supplicant *wpa_s,
2504 struct wpa_interface *iface)
2505 {
2506 const char *ifname, *driver;
2507 struct wpa_driver_capa capa;
2508
2509 wpa_printf(MSG_DEBUG, "Initializing interface '%s' conf '%s' driver "
2510 "'%s' ctrl_interface '%s' bridge '%s'", iface->ifname,
2511 iface->confname ? iface->confname : "N/A",
2512 iface->driver ? iface->driver : "default",
2513 iface->ctrl_interface ? iface->ctrl_interface : "N/A",
2514 iface->bridge_ifname ? iface->bridge_ifname : "N/A");
2515
2516 if (iface->confname) {
2517 #ifdef CONFIG_BACKEND_FILE
2518 wpa_s->confname = os_rel2abs_path(iface->confname);
2519 if (wpa_s->confname == NULL) {
2520 wpa_printf(MSG_ERROR, "Failed to get absolute path "
2521 "for configuration file '%s'.",
2522 iface->confname);
2523 return -1;
2524 }
2525 wpa_printf(MSG_DEBUG, "Configuration file '%s' -> '%s'",
2526 iface->confname, wpa_s->confname);
2527 #else /* CONFIG_BACKEND_FILE */
2528 wpa_s->confname = os_strdup(iface->confname);
2529 #endif /* CONFIG_BACKEND_FILE */
2530 wpa_s->conf = wpa_config_read(wpa_s->confname);
2531 if (wpa_s->conf == NULL) {
2532 wpa_printf(MSG_ERROR, "Failed to read or parse "
2533 "configuration '%s'.", wpa_s->confname);
2534 return -1;
2535 }
2536
2537 /*
2538 * Override ctrl_interface and driver_param if set on command
2539 * line.
2540 */
2541 if (iface->ctrl_interface) {
2542 os_free(wpa_s->conf->ctrl_interface);
2543 wpa_s->conf->ctrl_interface =
2544 os_strdup(iface->ctrl_interface);
2545 }
2546
2547 if (iface->driver_param) {
2548 os_free(wpa_s->conf->driver_param);
2549 wpa_s->conf->driver_param =
2550 os_strdup(iface->driver_param);
2551 }
2552 } else
2553 wpa_s->conf = wpa_config_alloc_empty(iface->ctrl_interface,
2554 iface->driver_param);
2555
2556 if (wpa_s->conf == NULL) {
2557 wpa_printf(MSG_ERROR, "\nNo configuration found.");
2558 return -1;
2559 }
2560
2561 if (iface->ifname == NULL) {
2562 wpa_printf(MSG_ERROR, "\nInterface name is required.");
2563 return -1;
2564 }
2565 if (os_strlen(iface->ifname) >= sizeof(wpa_s->ifname)) {
2566 wpa_printf(MSG_ERROR, "\nToo long interface name '%s'.",
2567 iface->ifname);
2568 return -1;
2569 }
2570 os_strlcpy(wpa_s->ifname, iface->ifname, sizeof(wpa_s->ifname));
2571
2572 if (iface->bridge_ifname) {
2573 if (os_strlen(iface->bridge_ifname) >=
2574 sizeof(wpa_s->bridge_ifname)) {
2575 wpa_printf(MSG_ERROR, "\nToo long bridge interface "
2576 "name '%s'.", iface->bridge_ifname);
2577 return -1;
2578 }
2579 os_strlcpy(wpa_s->bridge_ifname, iface->bridge_ifname,
2580 sizeof(wpa_s->bridge_ifname));
2581 }
2582
2583 /* RSNA Supplicant Key Management - INITIALIZE */
2584 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2585 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2586
2587 /* Initialize driver interface and register driver event handler before
2588 * L2 receive handler so that association events are processed before
2589 * EAPOL-Key packets if both become available for the same select()
2590 * call. */
2591 driver = iface->driver;
2592 next_driver:
2593 if (wpa_supplicant_set_driver(wpa_s, driver) < 0)
2594 return -1;
2595
2596 wpa_s->drv_priv = wpa_drv_init(wpa_s, wpa_s->ifname);
2597 if (wpa_s->drv_priv == NULL) {
2598 const char *pos;
2599 pos = driver ? os_strchr(driver, ',') : NULL;
2600 if (pos) {
2601 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to initialize "
2602 "driver interface - try next driver wrapper");
2603 driver = pos + 1;
2604 goto next_driver;
2605 }
2606 wpa_msg(wpa_s, MSG_ERROR, "Failed to initialize driver "
2607 "interface");
2608 return -1;
2609 }
2610 if (wpa_drv_set_param(wpa_s, wpa_s->conf->driver_param) < 0) {
2611 wpa_msg(wpa_s, MSG_ERROR, "Driver interface rejected "
2612 "driver_param '%s'", wpa_s->conf->driver_param);
2613 return -1;
2614 }
2615
2616 ifname = wpa_drv_get_ifname(wpa_s);
2617 if (ifname && os_strcmp(ifname, wpa_s->ifname) != 0) {
2618 wpa_dbg(wpa_s, MSG_DEBUG, "Driver interface replaced "
2619 "interface name with '%s'", ifname);
2620 os_strlcpy(wpa_s->ifname, ifname, sizeof(wpa_s->ifname));
2621 }
2622
2623 if (wpa_supplicant_init_wpa(wpa_s) < 0)
2624 return -1;
2625
2626 wpa_sm_set_ifname(wpa_s->wpa, wpa_s->ifname,
2627 wpa_s->bridge_ifname[0] ? wpa_s->bridge_ifname :
2628 NULL);
2629 wpa_sm_set_fast_reauth(wpa_s->wpa, wpa_s->conf->fast_reauth);
2630
2631 if (wpa_s->conf->dot11RSNAConfigPMKLifetime &&
2632 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
2633 wpa_s->conf->dot11RSNAConfigPMKLifetime)) {
2634 wpa_msg(wpa_s, MSG_ERROR, "Invalid WPA parameter value for "
2635 "dot11RSNAConfigPMKLifetime");
2636 return -1;
2637 }
2638
2639 if (wpa_s->conf->dot11RSNAConfigPMKReauthThreshold &&
2640 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
2641 wpa_s->conf->dot11RSNAConfigPMKReauthThreshold)) {
2642 wpa_msg(wpa_s, MSG_ERROR, "Invalid WPA parameter value for "
2643 "dot11RSNAConfigPMKReauthThreshold");
2644 return -1;
2645 }
2646
2647 if (wpa_s->conf->dot11RSNAConfigSATimeout &&
2648 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT,
2649 wpa_s->conf->dot11RSNAConfigSATimeout)) {
2650 wpa_msg(wpa_s, MSG_ERROR, "Invalid WPA parameter value for "
2651 "dot11RSNAConfigSATimeout");
2652 return -1;
2653 }
2654
2655 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(wpa_s,
2656 &wpa_s->hw.num_modes,
2657 &wpa_s->hw.flags);
2658
2659 if (wpa_drv_get_capa(wpa_s, &capa) == 0) {
2660 wpa_s->drv_capa_known = 1;
2661 wpa_s->drv_flags = capa.flags;
2662 wpa_s->drv_enc = capa.enc;
2663 wpa_s->probe_resp_offloads = capa.probe_resp_offloads;
2664 wpa_s->max_scan_ssids = capa.max_scan_ssids;
2665 wpa_s->max_sched_scan_ssids = capa.max_sched_scan_ssids;
2666 wpa_s->sched_scan_supported = capa.sched_scan_supported;
2667 wpa_s->max_match_sets = capa.max_match_sets;
2668 wpa_s->max_remain_on_chan = capa.max_remain_on_chan;
2669 wpa_s->max_stations = capa.max_stations;
2670 }
2671 if (wpa_s->max_remain_on_chan == 0)
2672 wpa_s->max_remain_on_chan = 1000;
2673
2674 if (wpa_supplicant_driver_init(wpa_s) < 0)
2675 return -1;
2676
2677 #ifdef CONFIG_TDLS
2678 if (wpa_tdls_init(wpa_s->wpa))
2679 return -1;
2680 #endif /* CONFIG_TDLS */
2681
2682 if (wpa_s->conf->country[0] && wpa_s->conf->country[1] &&
2683 wpa_drv_set_country(wpa_s, wpa_s->conf->country)) {
2684 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to set country");
2685 return -1;
2686 }
2687
2688 if (wpas_wps_init(wpa_s))
2689 return -1;
2690
2691 if (wpa_supplicant_init_eapol(wpa_s) < 0)
2692 return -1;
2693 wpa_sm_set_eapol(wpa_s->wpa, wpa_s->eapol);
2694
2695 wpa_s->ctrl_iface = wpa_supplicant_ctrl_iface_init(wpa_s);
2696 if (wpa_s->ctrl_iface == NULL) {
2697 wpa_printf(MSG_ERROR,
2698 "Failed to initialize control interface '%s'.\n"
2699 "You may have another wpa_supplicant process "
2700 "already running or the file was\n"
2701 "left by an unclean termination of wpa_supplicant "
2702 "in which case you will need\n"
2703 "to manually remove this file before starting "
2704 "wpa_supplicant again.\n",
2705 wpa_s->conf->ctrl_interface);
2706 return -1;
2707 }
2708
2709 wpa_s->gas = gas_query_init(wpa_s);
2710 if (wpa_s->gas == NULL) {
2711 wpa_printf(MSG_ERROR, "Failed to initialize GAS query");
2712 return -1;
2713 }
2714
2715 #ifdef CONFIG_P2P
2716 if (wpas_p2p_init(wpa_s->global, wpa_s) < 0) {
2717 wpa_msg(wpa_s, MSG_ERROR, "Failed to init P2P");
2718 return -1;
2719 }
2720 #endif /* CONFIG_P2P */
2721
2722 if (wpa_bss_init(wpa_s) < 0)
2723 return -1;
2724
2725 if (pcsc_reader_init(wpa_s) < 0)
2726 return -1;
2727
2728 return 0;
2729 }
2730
2731
2732 static void wpa_supplicant_deinit_iface(struct wpa_supplicant *wpa_s,
2733 int notify, int terminate)
2734 {
2735 if (wpa_s->drv_priv) {
2736 wpa_supplicant_deauthenticate(wpa_s,
2737 WLAN_REASON_DEAUTH_LEAVING);
2738
2739 wpa_drv_set_countermeasures(wpa_s, 0);
2740 wpa_clear_keys(wpa_s, NULL);
2741 }
2742
2743 wpa_supplicant_cleanup(wpa_s);
2744
2745 #ifdef CONFIG_P2P
2746 if (wpa_s == wpa_s->global->p2p_init_wpa_s && wpa_s->global->p2p) {
2747 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Disable P2P since removing "
2748 "the management interface is being removed");
2749 wpas_p2p_deinit_global(wpa_s->global);
2750 }
2751 #endif /* CONFIG_P2P */
2752
2753 if (wpa_s->drv_priv)
2754 wpa_drv_deinit(wpa_s);
2755
2756 if (notify)
2757 wpas_notify_iface_removed(wpa_s);
2758
2759 if (terminate)
2760 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_TERMINATING);
2761
2762 if (wpa_s->ctrl_iface) {
2763 wpa_supplicant_ctrl_iface_deinit(wpa_s->ctrl_iface);
2764 wpa_s->ctrl_iface = NULL;
2765 }
2766
2767 if (wpa_s->conf != NULL) {
2768 wpa_config_free(wpa_s->conf);
2769 wpa_s->conf = NULL;
2770 }
2771 }
2772
2773
2774 /**
2775 * wpa_supplicant_add_iface - Add a new network interface
2776 * @global: Pointer to global data from wpa_supplicant_init()
2777 * @iface: Interface configuration options
2778 * Returns: Pointer to the created interface or %NULL on failure
2779 *
2780 * This function is used to add new network interfaces for %wpa_supplicant.
2781 * This can be called before wpa_supplicant_run() to add interfaces before the
2782 * main event loop has been started. In addition, new interfaces can be added
2783 * dynamically while %wpa_supplicant is already running. This could happen,
2784 * e.g., when a hotplug network adapter is inserted.
2785 */
2786 struct wpa_supplicant * wpa_supplicant_add_iface(struct wpa_global *global,
2787 struct wpa_interface *iface)
2788 {
2789 struct wpa_supplicant *wpa_s;
2790 struct wpa_interface t_iface;
2791 struct wpa_ssid *ssid;
2792
2793 if (global == NULL || iface == NULL)
2794 return NULL;
2795
2796 wpa_s = wpa_supplicant_alloc();
2797 if (wpa_s == NULL)
2798 return NULL;
2799
2800 wpa_s->global = global;
2801
2802 t_iface = *iface;
2803 if (global->params.override_driver) {
2804 wpa_printf(MSG_DEBUG, "Override interface parameter: driver "
2805 "('%s' -> '%s')",
2806 iface->driver, global->params.override_driver);
2807 t_iface.driver = global->params.override_driver;
2808 }
2809 if (global->params.override_ctrl_interface) {
2810 wpa_printf(MSG_DEBUG, "Override interface parameter: "
2811 "ctrl_interface ('%s' -> '%s')",
2812 iface->ctrl_interface,
2813 global->params.override_ctrl_interface);
2814 t_iface.ctrl_interface =
2815 global->params.override_ctrl_interface;
2816 }
2817 if (wpa_supplicant_init_iface(wpa_s, &t_iface)) {
2818 wpa_printf(MSG_DEBUG, "Failed to add interface %s",
2819 iface->ifname);
2820 wpa_supplicant_deinit_iface(wpa_s, 0, 0);
2821 os_free(wpa_s);
2822 return NULL;
2823 }
2824
2825 /* Notify the control interfaces about new iface */
2826 if (wpas_notify_iface_added(wpa_s)) {
2827 wpa_supplicant_deinit_iface(wpa_s, 1, 0);
2828 os_free(wpa_s);
2829 return NULL;
2830 }
2831
2832 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
2833 wpas_notify_network_added(wpa_s, ssid);
2834
2835 wpa_s->next = global->ifaces;
2836 global->ifaces = wpa_s;
2837
2838 wpa_dbg(wpa_s, MSG_DEBUG, "Added interface %s", wpa_s->ifname);
2839 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2840
2841 return wpa_s;
2842 }
2843
2844
2845 /**
2846 * wpa_supplicant_remove_iface - Remove a network interface
2847 * @global: Pointer to global data from wpa_supplicant_init()
2848 * @wpa_s: Pointer to the network interface to be removed
2849 * Returns: 0 if interface was removed, -1 if interface was not found
2850 *
2851 * This function can be used to dynamically remove network interfaces from
2852 * %wpa_supplicant, e.g., when a hotplug network adapter is ejected. In
2853 * addition, this function is used to remove all remaining interfaces when
2854 * %wpa_supplicant is terminated.
2855 */
2856 int wpa_supplicant_remove_iface(struct wpa_global *global,
2857 struct wpa_supplicant *wpa_s,
2858 int terminate)
2859 {
2860 struct wpa_supplicant *prev;
2861
2862 /* Remove interface from the global list of interfaces */
2863 prev = global->ifaces;
2864 if (prev == wpa_s) {
2865 global->ifaces = wpa_s->next;
2866 } else {
2867 while (prev && prev->next != wpa_s)
2868 prev = prev->next;
2869 if (prev == NULL)
2870 return -1;
2871 prev->next = wpa_s->next;
2872 }
2873
2874 wpa_dbg(wpa_s, MSG_DEBUG, "Removing interface %s", wpa_s->ifname);
2875
2876 if (global->p2p_group_formation == wpa_s)
2877 global->p2p_group_formation = NULL;
2878 wpa_supplicant_deinit_iface(wpa_s, 1, terminate);
2879 os_free(wpa_s);
2880
2881 return 0;
2882 }
2883
2884
2885 /**
2886 * wpa_supplicant_get_eap_mode - Get the current EAP mode
2887 * @wpa_s: Pointer to the network interface
2888 * Returns: Pointer to the eap mode or the string "UNKNOWN" if not found
2889 */
2890 const char * wpa_supplicant_get_eap_mode(struct wpa_supplicant *wpa_s)
2891 {
2892 const char *eapol_method;
2893
2894 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) == 0 &&
2895 wpa_s->key_mgmt != WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
2896 return "NO-EAP";
2897 }
2898
2899 eapol_method = eapol_sm_get_method_name(wpa_s->eapol);
2900 if (eapol_method == NULL)
2901 return "UNKNOWN-EAP";
2902
2903 return eapol_method;
2904 }
2905
2906
2907 /**
2908 * wpa_supplicant_get_iface - Get a new network interface
2909 * @global: Pointer to global data from wpa_supplicant_init()
2910 * @ifname: Interface name
2911 * Returns: Pointer to the interface or %NULL if not found
2912 */
2913 struct wpa_supplicant * wpa_supplicant_get_iface(struct wpa_global *global,
2914 const char *ifname)
2915 {
2916 struct wpa_supplicant *wpa_s;
2917
2918 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
2919 if (os_strcmp(wpa_s->ifname, ifname) == 0)
2920 return wpa_s;
2921 }
2922 return NULL;
2923 }
2924
2925
2926 #ifndef CONFIG_NO_WPA_MSG
2927 static const char * wpa_supplicant_msg_ifname_cb(void *ctx)
2928 {
2929 struct wpa_supplicant *wpa_s = ctx;
2930 if (wpa_s == NULL)
2931 return NULL;
2932 return wpa_s->ifname;
2933 }
2934 #endif /* CONFIG_NO_WPA_MSG */
2935
2936
2937 /**
2938 * wpa_supplicant_init - Initialize %wpa_supplicant
2939 * @params: Parameters for %wpa_supplicant
2940 * Returns: Pointer to global %wpa_supplicant data, or %NULL on failure
2941 *
2942 * This function is used to initialize %wpa_supplicant. After successful
2943 * initialization, the returned data pointer can be used to add and remove
2944 * network interfaces, and eventually, to deinitialize %wpa_supplicant.
2945 */
2946 struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
2947 {
2948 struct wpa_global *global;
2949 int ret, i;
2950
2951 if (params == NULL)
2952 return NULL;
2953
2954 #ifdef CONFIG_DRIVER_NDIS
2955 {
2956 void driver_ndis_init_ops(void);
2957 driver_ndis_init_ops();
2958 }
2959 #endif /* CONFIG_DRIVER_NDIS */
2960
2961 #ifndef CONFIG_NO_WPA_MSG
2962 wpa_msg_register_ifname_cb(wpa_supplicant_msg_ifname_cb);
2963 #endif /* CONFIG_NO_WPA_MSG */
2964
2965 wpa_debug_open_file(params->wpa_debug_file_path);
2966 if (params->wpa_debug_syslog)
2967 wpa_debug_open_syslog();
2968 if (params->wpa_debug_tracing) {
2969 ret = wpa_debug_open_linux_tracing();
2970 if (ret) {
2971 wpa_printf(MSG_ERROR,
2972 "Failed to enable trace logging");
2973 return NULL;
2974 }
2975 }
2976
2977 ret = eap_register_methods();
2978 if (ret) {
2979 wpa_printf(MSG_ERROR, "Failed to register EAP methods");
2980 if (ret == -2)
2981 wpa_printf(MSG_ERROR, "Two or more EAP methods used "
2982 "the same EAP type.");
2983 return NULL;
2984 }
2985
2986 global = os_zalloc(sizeof(*global));
2987 if (global == NULL)
2988 return NULL;
2989 dl_list_init(&global->p2p_srv_bonjour);
2990 dl_list_init(&global->p2p_srv_upnp);
2991 global->params.daemonize = params->daemonize;
2992 global->params.wait_for_monitor = params->wait_for_monitor;
2993 global->params.dbus_ctrl_interface = params->dbus_ctrl_interface;
2994 if (params->pid_file)
2995 global->params.pid_file = os_strdup(params->pid_file);
2996 if (params->ctrl_interface)
2997 global->params.ctrl_interface =
2998 os_strdup(params->ctrl_interface);
2999 if (params->override_driver)
3000 global->params.override_driver =
3001 os_strdup(params->override_driver);
3002 if (params->override_ctrl_interface)
3003 global->params.override_ctrl_interface =
3004 os_strdup(params->override_ctrl_interface);
3005 wpa_debug_level = global->params.wpa_debug_level =
3006 params->wpa_debug_level;
3007 wpa_debug_show_keys = global->params.wpa_debug_show_keys =
3008 params->wpa_debug_show_keys;
3009 wpa_debug_timestamp = global->params.wpa_debug_timestamp =
3010 params->wpa_debug_timestamp;
3011
3012 wpa_printf(MSG_DEBUG, "wpa_supplicant v" VERSION_STR);
3013
3014 if (eloop_init()) {
3015 wpa_printf(MSG_ERROR, "Failed to initialize event loop");
3016 wpa_supplicant_deinit(global);
3017 return NULL;
3018 }
3019
3020 random_init(params->entropy_file);
3021
3022 global->ctrl_iface = wpa_supplicant_global_ctrl_iface_init(global);
3023 if (global->ctrl_iface == NULL) {
3024 wpa_supplicant_deinit(global);
3025 return NULL;
3026 }
3027
3028 if (wpas_notify_supplicant_initialized(global)) {
3029 wpa_supplicant_deinit(global);
3030 return NULL;
3031 }
3032
3033 for (i = 0; wpa_drivers[i]; i++)
3034 global->drv_count++;
3035 if (global->drv_count == 0) {
3036 wpa_printf(MSG_ERROR, "No drivers enabled");
3037 wpa_supplicant_deinit(global);
3038 return NULL;
3039 }
3040 global->drv_priv = os_zalloc(global->drv_count * sizeof(void *));
3041 if (global->drv_priv == NULL) {
3042 wpa_supplicant_deinit(global);
3043 return NULL;
3044 }
3045
3046 return global;
3047 }
3048
3049
3050 /**
3051 * wpa_supplicant_run - Run the %wpa_supplicant main event loop
3052 * @global: Pointer to global data from wpa_supplicant_init()
3053 * Returns: 0 after successful event loop run, -1 on failure
3054 *
3055 * This function starts the main event loop and continues running as long as
3056 * there are any remaining events. In most cases, this function is running as
3057 * long as the %wpa_supplicant process in still in use.
3058 */
3059 int wpa_supplicant_run(struct wpa_global *global)
3060 {
3061 struct wpa_supplicant *wpa_s;
3062
3063 if (global->params.daemonize &&
3064 wpa_supplicant_daemon(global->params.pid_file))
3065 return -1;
3066
3067 if (global->params.wait_for_monitor) {
3068 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
3069 if (wpa_s->ctrl_iface)
3070 wpa_supplicant_ctrl_iface_wait(
3071 wpa_s->ctrl_iface);
3072 }
3073
3074 eloop_register_signal_terminate(wpa_supplicant_terminate, global);
3075 eloop_register_signal_reconfig(wpa_supplicant_reconfig, global);
3076
3077 eloop_run();
3078
3079 return 0;
3080 }
3081
3082
3083 /**
3084 * wpa_supplicant_deinit - Deinitialize %wpa_supplicant
3085 * @global: Pointer to global data from wpa_supplicant_init()
3086 *
3087 * This function is called to deinitialize %wpa_supplicant and to free all
3088 * allocated resources. Remaining network interfaces will also be removed.
3089 */
3090 void wpa_supplicant_deinit(struct wpa_global *global)
3091 {
3092 int i;
3093
3094 if (global == NULL)
3095 return;
3096
3097 #ifdef CONFIG_P2P
3098 wpas_p2p_deinit_global(global);
3099 #endif /* CONFIG_P2P */
3100
3101 while (global->ifaces)
3102 wpa_supplicant_remove_iface(global, global->ifaces, 1);
3103
3104 if (global->ctrl_iface)
3105 wpa_supplicant_global_ctrl_iface_deinit(global->ctrl_iface);
3106
3107 wpas_notify_supplicant_deinitialized(global);
3108
3109 eap_peer_unregister_methods();
3110 #ifdef CONFIG_AP
3111 eap_server_unregister_methods();
3112 #endif /* CONFIG_AP */
3113
3114 for (i = 0; wpa_drivers[i] && global->drv_priv; i++) {
3115 if (!global->drv_priv[i])
3116 continue;
3117 wpa_drivers[i]->global_deinit(global->drv_priv[i]);
3118 }
3119 os_free(global->drv_priv);
3120
3121 random_deinit();
3122
3123 eloop_destroy();
3124
3125 if (global->params.pid_file) {
3126 os_daemonize_terminate(global->params.pid_file);
3127 os_free(global->params.pid_file);
3128 }
3129 os_free(global->params.ctrl_interface);
3130 os_free(global->params.override_driver);
3131 os_free(global->params.override_ctrl_interface);
3132
3133 os_free(global->p2p_disallow_freq);
3134
3135 os_free(global);
3136 wpa_debug_close_syslog();
3137 wpa_debug_close_file();
3138 wpa_debug_close_linux_tracing();
3139 }
3140
3141
3142 void wpa_supplicant_update_config(struct wpa_supplicant *wpa_s)
3143 {
3144 if ((wpa_s->conf->changed_parameters & CFG_CHANGED_COUNTRY) &&
3145 wpa_s->conf->country[0] && wpa_s->conf->country[1]) {
3146 char country[3];
3147 country[0] = wpa_s->conf->country[0];
3148 country[1] = wpa_s->conf->country[1];
3149 country[2] = '\0';
3150 if (wpa_drv_set_country(wpa_s, country) < 0) {
3151 wpa_printf(MSG_ERROR, "Failed to set country code "
3152 "'%s'", country);
3153 }
3154 }
3155
3156 #ifdef CONFIG_WPS
3157 wpas_wps_update_config(wpa_s);
3158 #endif /* CONFIG_WPS */
3159
3160 #ifdef CONFIG_P2P
3161 wpas_p2p_update_config(wpa_s);
3162 #endif /* CONFIG_P2P */
3163
3164 wpa_s->conf->changed_parameters = 0;
3165 }
3166
3167
3168 static void add_freq(int *freqs, int *num_freqs, int freq)
3169 {
3170 int i;
3171
3172 for (i = 0; i < *num_freqs; i++) {
3173 if (freqs[i] == freq)
3174 return;
3175 }
3176
3177 freqs[*num_freqs] = freq;
3178 (*num_freqs)++;
3179 }
3180
3181
3182 static int * get_bss_freqs_in_ess(struct wpa_supplicant *wpa_s)
3183 {
3184 struct wpa_bss *bss, *cbss;
3185 const int max_freqs = 10;
3186 int *freqs;
3187 int num_freqs = 0;
3188
3189 freqs = os_zalloc(sizeof(int) * (max_freqs + 1));
3190 if (freqs == NULL)
3191 return NULL;
3192
3193 cbss = wpa_s->current_bss;
3194
3195 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
3196 if (bss == cbss)
3197 continue;
3198 if (bss->ssid_len == cbss->ssid_len &&
3199 os_memcmp(bss->ssid, cbss->ssid, bss->ssid_len) == 0 &&
3200 wpa_blacklist_get(wpa_s, bss->bssid) == NULL) {
3201 add_freq(freqs, &num_freqs, bss->freq);
3202 if (num_freqs == max_freqs)
3203 break;
3204 }
3205 }
3206
3207 if (num_freqs == 0) {
3208 os_free(freqs);
3209 freqs = NULL;
3210 }
3211
3212 return freqs;
3213 }
3214
3215
3216 void wpas_connection_failed(struct wpa_supplicant *wpa_s, const u8 *bssid)
3217 {
3218 int timeout;
3219 int count;
3220 int *freqs = NULL;
3221
3222 /*
3223 * Remove possible authentication timeout since the connection failed.
3224 */
3225 eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL);
3226
3227 /*
3228 * Add the failed BSSID into the blacklist and speed up next scan
3229 * attempt if there could be other APs that could accept association.
3230 * The current blacklist count indicates how many times we have tried
3231 * connecting to this AP and multiple attempts mean that other APs are
3232 * either not available or has already been tried, so that we can start
3233 * increasing the delay here to avoid constant scanning.
3234 */
3235 count = wpa_blacklist_add(wpa_s, bssid);
3236 if (count == 1 && wpa_s->current_bss) {
3237 /*
3238 * This BSS was not in the blacklist before. If there is
3239 * another BSS available for the same ESS, we should try that
3240 * next. Otherwise, we may as well try this one once more
3241 * before allowing other, likely worse, ESSes to be considered.
3242 */
3243 freqs = get_bss_freqs_in_ess(wpa_s);
3244 if (freqs) {
3245 wpa_dbg(wpa_s, MSG_DEBUG, "Another BSS in this ESS "
3246 "has been seen; try it next");
3247 wpa_blacklist_add(wpa_s, bssid);
3248 /*
3249 * On the next scan, go through only the known channels
3250 * used in this ESS based on previous scans to speed up
3251 * common load balancing use case.
3252 */
3253 os_free(wpa_s->next_scan_freqs);
3254 wpa_s->next_scan_freqs = freqs;
3255 }
3256 }
3257
3258 switch (count) {
3259 case 1:
3260 timeout = 100;
3261 break;
3262 case 2:
3263 timeout = 500;
3264 break;
3265 case 3:
3266 timeout = 1000;
3267 break;
3268 default:
3269 timeout = 5000;
3270 }
3271
3272 /*
3273 * TODO: if more than one possible AP is available in scan results,
3274 * could try the other ones before requesting a new scan.
3275 */
3276 wpa_supplicant_req_scan(wpa_s, timeout / 1000,
3277 1000 * (timeout % 1000));
3278 }
3279
3280
3281 int wpas_driver_bss_selection(struct wpa_supplicant *wpa_s)
3282 {
3283 return wpa_s->conf->ap_scan == 2 ||
3284 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION);
3285 }
3286
3287
3288 #if defined(CONFIG_CTRL_IFACE) || defined(CONFIG_CTRL_IFACE_DBUS_NEW)
3289 int wpa_supplicant_ctrl_iface_ctrl_rsp_handle(struct wpa_supplicant *wpa_s,
3290 struct wpa_ssid *ssid,
3291 const char *field,
3292 const char *value)
3293 {
3294 #ifdef IEEE8021X_EAPOL
3295 struct eap_peer_config *eap = &ssid->eap;
3296
3297 wpa_printf(MSG_DEBUG, "CTRL_IFACE: response handle field=%s", field);
3298 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: response value",
3299 (const u8 *) value, os_strlen(value));
3300
3301 switch (wpa_supplicant_ctrl_req_from_string(field)) {
3302 case WPA_CTRL_REQ_EAP_IDENTITY:
3303 os_free(eap->identity);
3304 eap->identity = (u8 *) os_strdup(value);
3305 eap->identity_len = os_strlen(value);
3306 eap->pending_req_identity = 0;
3307 if (ssid == wpa_s->current_ssid)
3308 wpa_s->reassociate = 1;
3309 break;
3310 case WPA_CTRL_REQ_EAP_PASSWORD:
3311 os_free(eap->password);
3312 eap->password = (u8 *) os_strdup(value);
3313 eap->password_len = os_strlen(value);
3314 eap->pending_req_password = 0;
3315 if (ssid == wpa_s->current_ssid)
3316 wpa_s->reassociate = 1;
3317 break;
3318 case WPA_CTRL_REQ_EAP_NEW_PASSWORD:
3319 os_free(eap->new_password);
3320 eap->new_password = (u8 *) os_strdup(value);
3321 eap->new_password_len = os_strlen(value);
3322 eap->pending_req_new_password = 0;
3323 if (ssid == wpa_s->current_ssid)
3324 wpa_s->reassociate = 1;
3325 break;
3326 case WPA_CTRL_REQ_EAP_PIN:
3327 os_free(eap->pin);
3328 eap->pin = os_strdup(value);
3329 eap->pending_req_pin = 0;
3330 if (ssid == wpa_s->current_ssid)
3331 wpa_s->reassociate = 1;
3332 break;
3333 case WPA_CTRL_REQ_EAP_OTP:
3334 os_free(eap->otp);
3335 eap->otp = (u8 *) os_strdup(value);
3336 eap->otp_len = os_strlen(value);
3337 os_free(eap->pending_req_otp);
3338 eap->pending_req_otp = NULL;
3339 eap->pending_req_otp_len = 0;
3340 break;
3341 case WPA_CTRL_REQ_EAP_PASSPHRASE:
3342 os_free(eap->private_key_passwd);
3343 eap->private_key_passwd = (u8 *) os_strdup(value);
3344 eap->pending_req_passphrase = 0;
3345 if (ssid == wpa_s->current_ssid)
3346 wpa_s->reassociate = 1;
3347 break;
3348 default:
3349 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown field '%s'", field);
3350 return -1;
3351 }
3352
3353 return 0;
3354 #else /* IEEE8021X_EAPOL */
3355 wpa_printf(MSG_DEBUG, "CTRL_IFACE: IEEE 802.1X not included");
3356 return -1;
3357 #endif /* IEEE8021X_EAPOL */
3358 }
3359 #endif /* CONFIG_CTRL_IFACE || CONFIG_CTRL_IFACE_DBUS_NEW */
3360
3361
3362 int wpas_network_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
3363 {
3364 int i;
3365 unsigned int drv_enc;
3366
3367 if (ssid == NULL)
3368 return 1;
3369
3370 if (ssid->disabled)
3371 return 1;
3372
3373 if (wpa_s && wpa_s->drv_capa_known)
3374 drv_enc = wpa_s->drv_enc;
3375 else
3376 drv_enc = (unsigned int) -1;
3377
3378 for (i = 0; i < NUM_WEP_KEYS; i++) {
3379 size_t len = ssid->wep_key_len[i];
3380 if (len == 0)
3381 continue;
3382 if (len == 5 && (drv_enc & WPA_DRIVER_CAPA_ENC_WEP40))
3383 continue;
3384 if (len == 13 && (drv_enc & WPA_DRIVER_CAPA_ENC_WEP104))
3385 continue;
3386 if (len == 16 && (drv_enc & WPA_DRIVER_CAPA_ENC_WEP128))
3387 continue;
3388 return 1; /* invalid WEP key */
3389 }
3390
3391 return 0;
3392 }
3393
3394
3395 int wpas_is_p2p_prioritized(struct wpa_supplicant *wpa_s)
3396 {
3397 if (wpa_s->global->conc_pref == WPA_CONC_PREF_P2P)
3398 return 1;
3399 if (wpa_s->global->conc_pref == WPA_CONC_PREF_STA)
3400 return 0;
3401 return -1;
3402 }