blob: 83870433550eee388b032c159dfc84aa5f2e17c2 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Glue code to setup EAPOL and RSN modules
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07003 * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "includes.h"
10
11#include "common.h"
12#include "eapol_supp/eapol_supp_sm.h"
13#include "rsn_supp/wpa.h"
14#include "eloop.h"
15#include "config.h"
16#include "l2_packet/l2_packet.h"
17#include "common/wpa_common.h"
18#include "wpa_supplicant_i.h"
19#include "driver_i.h"
20#include "rsn_supp/pmksa_cache.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070021#include "sme.h"
22#include "common/ieee802_11_defs.h"
23#include "common/wpa_ctrl.h"
24#include "wpas_glue.h"
25#include "wps_supplicant.h"
26#include "bss.h"
27#include "scan.h"
Dmitry Shmidtc55524a2011-07-07 11:18:38 -070028#include "notify.h"
Dmitry Shmidt5a1480c2014-05-12 09:46:02 -070029#include "wpas_kay.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070030
31
32#ifndef CONFIG_NO_CONFIG_BLOBS
33#if defined(IEEE8021X_EAPOL) || !defined(CONFIG_NO_WPA)
34static void wpa_supplicant_set_config_blob(void *ctx,
35 struct wpa_config_blob *blob)
36{
37 struct wpa_supplicant *wpa_s = ctx;
38 wpa_config_set_blob(wpa_s->conf, blob);
39 if (wpa_s->conf->update_config) {
40 int ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
41 if (ret) {
42 wpa_printf(MSG_DEBUG, "Failed to update config after "
43 "blob set");
44 }
45 }
46}
47
48
49static const struct wpa_config_blob *
50wpa_supplicant_get_config_blob(void *ctx, const char *name)
51{
52 struct wpa_supplicant *wpa_s = ctx;
53 return wpa_config_get_blob(wpa_s->conf, name);
54}
55#endif /* defined(IEEE8021X_EAPOL) || !defined(CONFIG_NO_WPA) */
56#endif /* CONFIG_NO_CONFIG_BLOBS */
57
58
59#if defined(IEEE8021X_EAPOL) || !defined(CONFIG_NO_WPA)
60static u8 * wpa_alloc_eapol(const struct wpa_supplicant *wpa_s, u8 type,
61 const void *data, u16 data_len,
62 size_t *msg_len, void **data_pos)
63{
64 struct ieee802_1x_hdr *hdr;
65
66 *msg_len = sizeof(*hdr) + data_len;
67 hdr = os_malloc(*msg_len);
68 if (hdr == NULL)
69 return NULL;
70
71 hdr->version = wpa_s->conf->eapol_version;
72 hdr->type = type;
73 hdr->length = host_to_be16(data_len);
74
75 if (data)
76 os_memcpy(hdr + 1, data, data_len);
77 else
78 os_memset(hdr + 1, 0, data_len);
79
80 if (data_pos)
81 *data_pos = hdr + 1;
82
83 return (u8 *) hdr;
84}
85
86
87/**
88 * wpa_ether_send - Send Ethernet frame
89 * @wpa_s: Pointer to wpa_supplicant data
90 * @dest: Destination MAC address
91 * @proto: Ethertype in host byte order
92 * @buf: Frame payload starting from IEEE 802.1X header
93 * @len: Frame payload length
94 * Returns: >=0 on success, <0 on failure
95 */
96static int wpa_ether_send(struct wpa_supplicant *wpa_s, const u8 *dest,
97 u16 proto, const u8 *buf, size_t len)
98{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080099#ifdef CONFIG_TESTING_OPTIONS
100 if (wpa_s->ext_eapol_frame_io && proto == ETH_P_EAPOL) {
101 size_t hex_len = 2 * len + 1;
102 char *hex = os_malloc(hex_len);
103
104 if (hex == NULL)
105 return -1;
106 wpa_snprintf_hex(hex, hex_len, buf, len);
107 wpa_msg(wpa_s, MSG_INFO, "EAPOL-TX " MACSTR " %s",
108 MAC2STR(dest), hex);
109 os_free(hex);
110 return 0;
111 }
112#endif /* CONFIG_TESTING_OPTIONS */
113
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700114 if (wpa_s->l2) {
115 return l2_packet_send(wpa_s->l2, dest, proto, buf, len);
116 }
117
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800118 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700119}
120#endif /* IEEE8021X_EAPOL || !CONFIG_NO_WPA */
121
122
123#ifdef IEEE8021X_EAPOL
124
125/**
126 * wpa_supplicant_eapol_send - Send IEEE 802.1X EAPOL packet to Authenticator
127 * @ctx: Pointer to wpa_supplicant data (wpa_s)
128 * @type: IEEE 802.1X packet type (IEEE802_1X_TYPE_*)
129 * @buf: EAPOL payload (after IEEE 802.1X header)
130 * @len: EAPOL payload length
131 * Returns: >=0 on success, <0 on failure
132 *
133 * This function adds Ethernet and IEEE 802.1X header and sends the EAPOL frame
134 * to the current Authenticator.
135 */
136static int wpa_supplicant_eapol_send(void *ctx, int type, const u8 *buf,
137 size_t len)
138{
139 struct wpa_supplicant *wpa_s = ctx;
140 u8 *msg, *dst, bssid[ETH_ALEN];
141 size_t msglen;
142 int res;
143
144 /* TODO: could add l2_packet_sendmsg that allows fragments to avoid
145 * extra copy here */
146
147 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
148 wpa_s->key_mgmt == WPA_KEY_MGMT_NONE) {
149 /* Current SSID is not using IEEE 802.1X/EAP, so drop possible
150 * EAPOL frames (mainly, EAPOL-Start) from EAPOL state
151 * machines. */
152 wpa_printf(MSG_DEBUG, "WPA: drop TX EAPOL in non-IEEE 802.1X "
153 "mode (type=%d len=%lu)", type,
154 (unsigned long) len);
155 return -1;
156 }
157
158 if (pmksa_cache_get_current(wpa_s->wpa) &&
159 type == IEEE802_1X_TYPE_EAPOL_START) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700160 /*
161 * We were trying to use PMKSA caching and sending EAPOL-Start
162 * would abort that and trigger full EAPOL authentication.
163 * However, we've already waited for the AP/Authenticator to
164 * start 4-way handshake or EAP authentication, and apparently
165 * it has not done so since the startWhen timer has reached zero
166 * to get the state machine sending EAPOL-Start. This is not
167 * really supposed to happen, but an interoperability issue with
168 * a deployed AP has been identified where the connection fails
169 * due to that AP failing to operate correctly if PMKID is
170 * included in the Association Request frame. To work around
171 * this, assume PMKSA caching failed and try to initiate full
172 * EAP authentication.
173 */
174 if (!wpa_s->current_ssid ||
175 wpa_s->current_ssid->eap_workaround) {
176 wpa_printf(MSG_DEBUG,
177 "RSN: Timeout on waiting for the AP to initiate 4-way handshake for PMKSA caching or EAP authentication - try to force it to start EAP authentication");
178 } else {
179 wpa_printf(MSG_DEBUG,
180 "RSN: PMKSA caching - do not send EAPOL-Start");
181 return -1;
182 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700183 }
184
185 if (is_zero_ether_addr(wpa_s->bssid)) {
186 wpa_printf(MSG_DEBUG, "BSSID not set when trying to send an "
187 "EAPOL frame");
188 if (wpa_drv_get_bssid(wpa_s, bssid) == 0 &&
189 !is_zero_ether_addr(bssid)) {
190 dst = bssid;
191 wpa_printf(MSG_DEBUG, "Using current BSSID " MACSTR
192 " from the driver as the EAPOL destination",
193 MAC2STR(dst));
194 } else {
195 dst = wpa_s->last_eapol_src;
196 wpa_printf(MSG_DEBUG, "Using the source address of the"
197 " last received EAPOL frame " MACSTR " as "
198 "the EAPOL destination",
199 MAC2STR(dst));
200 }
201 } else {
202 /* BSSID was already set (from (Re)Assoc event, so use it as
203 * the EAPOL destination. */
204 dst = wpa_s->bssid;
205 }
206
207 msg = wpa_alloc_eapol(wpa_s, type, buf, len, &msglen, NULL);
208 if (msg == NULL)
209 return -1;
210
211 wpa_printf(MSG_DEBUG, "TX EAPOL: dst=" MACSTR, MAC2STR(dst));
212 wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", msg, msglen);
213 res = wpa_ether_send(wpa_s, dst, ETH_P_EAPOL, msg, msglen);
214 os_free(msg);
215 return res;
216}
217
218
219/**
220 * wpa_eapol_set_wep_key - set WEP key for the driver
221 * @ctx: Pointer to wpa_supplicant data (wpa_s)
222 * @unicast: 1 = individual unicast key, 0 = broadcast key
223 * @keyidx: WEP key index (0..3)
224 * @key: Pointer to key data
225 * @keylen: Key length in bytes
226 * Returns: 0 on success or < 0 on error.
227 */
228static int wpa_eapol_set_wep_key(void *ctx, int unicast, int keyidx,
229 const u8 *key, size_t keylen)
230{
231 struct wpa_supplicant *wpa_s = ctx;
232 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
233 int cipher = (keylen == 5) ? WPA_CIPHER_WEP40 :
234 WPA_CIPHER_WEP104;
235 if (unicast)
236 wpa_s->pairwise_cipher = cipher;
237 else
238 wpa_s->group_cipher = cipher;
239 }
240 return wpa_drv_set_key(wpa_s, WPA_ALG_WEP,
241 unicast ? wpa_s->bssid : NULL,
242 keyidx, unicast, NULL, 0, key, keylen);
243}
244
245
246static void wpa_supplicant_aborted_cached(void *ctx)
247{
248 struct wpa_supplicant *wpa_s = ctx;
249 wpa_sm_aborted_cached(wpa_s->wpa);
250}
251
252
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800253static const char * result_str(enum eapol_supp_result result)
254{
255 switch (result) {
256 case EAPOL_SUPP_RESULT_FAILURE:
257 return "FAILURE";
258 case EAPOL_SUPP_RESULT_SUCCESS:
259 return "SUCCESS";
260 case EAPOL_SUPP_RESULT_EXPECTED_FAILURE:
261 return "EXPECTED_FAILURE";
262 }
263 return "?";
264}
265
266
267static void wpa_supplicant_eapol_cb(struct eapol_sm *eapol,
268 enum eapol_supp_result result,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700269 void *ctx)
270{
271 struct wpa_supplicant *wpa_s = ctx;
272 int res, pmk_len;
273 u8 pmk[PMK_LEN];
274
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800275 wpa_printf(MSG_DEBUG, "EAPOL authentication completed - result=%s",
276 result_str(result));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700277
278 if (wpas_wps_eapol_cb(wpa_s) > 0)
279 return;
280
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800281 wpa_s->eap_expected_failure = result ==
282 EAPOL_SUPP_RESULT_EXPECTED_FAILURE;
283
284 if (result != EAPOL_SUPP_RESULT_SUCCESS) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700285 /*
286 * Make sure we do not get stuck here waiting for long EAPOL
287 * timeout if the AP does not disconnect in case of
288 * authentication failure.
289 */
290 wpa_supplicant_req_auth_timeout(wpa_s, 2, 0);
Dmitry Shmidt5a1480c2014-05-12 09:46:02 -0700291 } else {
292 ieee802_1x_notify_create_actor(wpa_s, wpa_s->last_eapol_src);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700293 }
294
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800295 if (result != EAPOL_SUPP_RESULT_SUCCESS ||
296 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700297 return;
298
299 if (!wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt))
300 return;
301
302 wpa_printf(MSG_DEBUG, "Configure PMK for driver-based RSN 4-way "
303 "handshake");
304
305 pmk_len = PMK_LEN;
306 if (wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
307#ifdef CONFIG_IEEE80211R
308 u8 buf[2 * PMK_LEN];
309 wpa_printf(MSG_DEBUG, "RSN: Use FT XXKey as PMK for "
310 "driver-based 4-way hs and FT");
311 res = eapol_sm_get_key(eapol, buf, 2 * PMK_LEN);
312 if (res == 0) {
313 os_memcpy(pmk, buf + PMK_LEN, PMK_LEN);
314 os_memset(buf, 0, sizeof(buf));
315 }
316#else /* CONFIG_IEEE80211R */
317 res = -1;
318#endif /* CONFIG_IEEE80211R */
319 } else {
320 res = eapol_sm_get_key(eapol, pmk, PMK_LEN);
321 if (res) {
322 /*
323 * EAP-LEAP is an exception from other EAP methods: it
324 * uses only 16-byte PMK.
325 */
326 res = eapol_sm_get_key(eapol, pmk, 16);
327 pmk_len = 16;
328 }
329 }
330
331 if (res) {
332 wpa_printf(MSG_DEBUG, "Failed to get PMK from EAPOL state "
333 "machines");
334 return;
335 }
336
337 wpa_hexdump_key(MSG_DEBUG, "RSN: Configure PMK for driver-based 4-way "
338 "handshake", pmk, pmk_len);
339
340 if (wpa_drv_set_key(wpa_s, WPA_ALG_PMK, NULL, 0, 0, NULL, 0, pmk,
341 pmk_len)) {
342 wpa_printf(MSG_DEBUG, "Failed to set PMK to the driver");
343 }
344
345 wpa_supplicant_cancel_scan(wpa_s);
346 wpa_supplicant_cancel_auth_timeout(wpa_s);
347 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
348
349}
350
351
352static void wpa_supplicant_notify_eapol_done(void *ctx)
353{
354 struct wpa_supplicant *wpa_s = ctx;
355 wpa_msg(wpa_s, MSG_DEBUG, "WPA: EAPOL processing complete");
356 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
357 wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE);
358 } else {
359 wpa_supplicant_cancel_auth_timeout(wpa_s);
360 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
361 }
362}
363
364#endif /* IEEE8021X_EAPOL */
365
366
367#ifndef CONFIG_NO_WPA
368
369static int wpa_get_beacon_ie(struct wpa_supplicant *wpa_s)
370{
371 int ret = 0;
372 struct wpa_bss *curr = NULL, *bss;
373 struct wpa_ssid *ssid = wpa_s->current_ssid;
374 const u8 *ie;
375
376 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
377 if (os_memcmp(bss->bssid, wpa_s->bssid, ETH_ALEN) != 0)
378 continue;
379 if (ssid == NULL ||
380 ((bss->ssid_len == ssid->ssid_len &&
381 os_memcmp(bss->ssid, ssid->ssid, ssid->ssid_len) == 0) ||
382 ssid->ssid_len == 0)) {
383 curr = bss;
384 break;
385 }
386 }
387
388 if (curr) {
389 ie = wpa_bss_get_vendor_ie(curr, WPA_IE_VENDOR_TYPE);
390 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0))
391 ret = -1;
392
393 ie = wpa_bss_get_ie(curr, WLAN_EID_RSN);
394 if (wpa_sm_set_ap_rsn_ie(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0))
395 ret = -1;
396 } else {
397 ret = -1;
398 }
399
400 return ret;
401}
402
403
404static int wpa_supplicant_get_beacon_ie(void *ctx)
405{
406 struct wpa_supplicant *wpa_s = ctx;
407 if (wpa_get_beacon_ie(wpa_s) == 0) {
408 return 0;
409 }
410
411 /* No WPA/RSN IE found in the cached scan results. Try to get updated
412 * scan results from the driver. */
413 if (wpa_supplicant_update_scan_results(wpa_s) < 0)
414 return -1;
415
416 return wpa_get_beacon_ie(wpa_s);
417}
418
419
420static u8 * _wpa_alloc_eapol(void *wpa_s, u8 type,
421 const void *data, u16 data_len,
422 size_t *msg_len, void **data_pos)
423{
424 return wpa_alloc_eapol(wpa_s, type, data, data_len, msg_len, data_pos);
425}
426
427
428static int _wpa_ether_send(void *wpa_s, const u8 *dest, u16 proto,
429 const u8 *buf, size_t len)
430{
431 return wpa_ether_send(wpa_s, dest, proto, buf, len);
432}
433
434
435static void _wpa_supplicant_cancel_auth_timeout(void *wpa_s)
436{
437 wpa_supplicant_cancel_auth_timeout(wpa_s);
438}
439
440
441static void _wpa_supplicant_set_state(void *wpa_s, enum wpa_states state)
442{
443 wpa_supplicant_set_state(wpa_s, state);
444}
445
446
447/**
448 * wpa_supplicant_get_state - Get the connection state
449 * @wpa_s: Pointer to wpa_supplicant data
450 * Returns: The current connection state (WPA_*)
451 */
452static enum wpa_states wpa_supplicant_get_state(struct wpa_supplicant *wpa_s)
453{
454 return wpa_s->wpa_state;
455}
456
457
458static enum wpa_states _wpa_supplicant_get_state(void *wpa_s)
459{
460 return wpa_supplicant_get_state(wpa_s);
461}
462
463
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700464static void _wpa_supplicant_deauthenticate(void *wpa_s, int reason_code)
465{
466 wpa_supplicant_deauthenticate(wpa_s, reason_code);
467 /* Schedule a scan to make sure we continue looking for networks */
468 wpa_supplicant_req_scan(wpa_s, 5, 0);
469}
470
471
472static void * wpa_supplicant_get_network_ctx(void *wpa_s)
473{
474 return wpa_supplicant_get_ssid(wpa_s);
475}
476
477
478static int wpa_supplicant_get_bssid(void *ctx, u8 *bssid)
479{
480 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700481 return wpa_drv_get_bssid(wpa_s, bssid);
482}
483
484
485static int wpa_supplicant_set_key(void *_wpa_s, enum wpa_alg alg,
486 const u8 *addr, int key_idx, int set_tx,
487 const u8 *seq, size_t seq_len,
488 const u8 *key, size_t key_len)
489{
490 struct wpa_supplicant *wpa_s = _wpa_s;
491 if (alg == WPA_ALG_TKIP && key_idx == 0 && key_len == 32) {
492 /* Clear the MIC error counter when setting a new PTK. */
493 wpa_s->mic_errors_seen = 0;
494 }
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700495#ifdef CONFIG_TESTING_GET_GTK
496 if (key_idx > 0 && addr && is_broadcast_ether_addr(addr) &&
497 alg != WPA_ALG_NONE && key_len <= sizeof(wpa_s->last_gtk)) {
498 os_memcpy(wpa_s->last_gtk, key, key_len);
499 wpa_s->last_gtk_len = key_len;
500 }
501#endif /* CONFIG_TESTING_GET_GTK */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700502 return wpa_drv_set_key(wpa_s, alg, addr, key_idx, set_tx, seq, seq_len,
503 key, key_len);
504}
505
506
507static int wpa_supplicant_mlme_setprotection(void *wpa_s, const u8 *addr,
508 int protection_type,
509 int key_type)
510{
511 return wpa_drv_mlme_setprotection(wpa_s, addr, protection_type,
512 key_type);
513}
514
515
516static int wpa_supplicant_add_pmkid(void *wpa_s,
517 const u8 *bssid, const u8 *pmkid)
518{
519 return wpa_drv_add_pmkid(wpa_s, bssid, pmkid);
520}
521
522
523static int wpa_supplicant_remove_pmkid(void *wpa_s,
524 const u8 *bssid, const u8 *pmkid)
525{
526 return wpa_drv_remove_pmkid(wpa_s, bssid, pmkid);
527}
528
529
530#ifdef CONFIG_IEEE80211R
531static int wpa_supplicant_update_ft_ies(void *ctx, const u8 *md,
532 const u8 *ies, size_t ies_len)
533{
534 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700535 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
536 return sme_update_ft_ies(wpa_s, md, ies, ies_len);
537 return wpa_drv_update_ft_ies(wpa_s, md, ies, ies_len);
538}
539
540
541static int wpa_supplicant_send_ft_action(void *ctx, u8 action,
542 const u8 *target_ap,
543 const u8 *ies, size_t ies_len)
544{
545 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800546 int ret;
547 u8 *data, *pos;
548 size_t data_len;
549
550 if (action != 1) {
551 wpa_printf(MSG_ERROR, "Unsupported send_ft_action action %d",
552 action);
553 return -1;
554 }
555
556 /*
557 * Action frame payload:
558 * Category[1] = 6 (Fast BSS Transition)
559 * Action[1] = 1 (Fast BSS Transition Request)
560 * STA Address
561 * Target AP Address
562 * FT IEs
563 */
564
565 data_len = 2 + 2 * ETH_ALEN + ies_len;
566 data = os_malloc(data_len);
567 if (data == NULL)
568 return -1;
569 pos = data;
570 *pos++ = 0x06; /* FT Action category */
571 *pos++ = action;
572 os_memcpy(pos, wpa_s->own_addr, ETH_ALEN);
573 pos += ETH_ALEN;
574 os_memcpy(pos, target_ap, ETH_ALEN);
575 pos += ETH_ALEN;
576 os_memcpy(pos, ies, ies_len);
577
578 ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0,
579 wpa_s->bssid, wpa_s->own_addr, wpa_s->bssid,
580 data, data_len, 0);
581 os_free(data);
582
583 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700584}
585
586
587static int wpa_supplicant_mark_authenticated(void *ctx, const u8 *target_ap)
588{
589 struct wpa_supplicant *wpa_s = ctx;
590 struct wpa_driver_auth_params params;
591 struct wpa_bss *bss;
592
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700593 bss = wpa_bss_get_bssid(wpa_s, target_ap);
594 if (bss == NULL)
595 return -1;
596
597 os_memset(&params, 0, sizeof(params));
598 params.bssid = target_ap;
599 params.freq = bss->freq;
600 params.ssid = bss->ssid;
601 params.ssid_len = bss->ssid_len;
602 params.auth_alg = WPA_AUTH_ALG_FT;
603 params.local_state_change = 1;
604 return wpa_drv_authenticate(wpa_s, &params);
605}
606#endif /* CONFIG_IEEE80211R */
607
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700608
609#ifdef CONFIG_TDLS
610
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800611static int wpa_supplicant_tdls_get_capa(void *ctx, int *tdls_supported,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800612 int *tdls_ext_setup,
613 int *tdls_chan_switch)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800614{
615 struct wpa_supplicant *wpa_s = ctx;
616
617 *tdls_supported = 0;
618 *tdls_ext_setup = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800619 *tdls_chan_switch = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800620
621 if (!wpa_s->drv_capa_known)
622 return -1;
623
624 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)
625 *tdls_supported = 1;
626
627 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP)
628 *tdls_ext_setup = 1;
629
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800630 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)
631 *tdls_chan_switch = 1;
632
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800633 return 0;
634}
635
636
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700637static int wpa_supplicant_send_tdls_mgmt(void *ctx, const u8 *dst,
638 u8 action_code, u8 dialog_token,
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700639 u16 status_code, u32 peer_capab,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700640 int initiator, const u8 *buf,
641 size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700642{
643 struct wpa_supplicant *wpa_s = ctx;
644 return wpa_drv_send_tdls_mgmt(wpa_s, dst, action_code, dialog_token,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700645 status_code, peer_capab, initiator, buf,
646 len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700647}
648
649
650static int wpa_supplicant_tdls_oper(void *ctx, int oper, const u8 *peer)
651{
652 struct wpa_supplicant *wpa_s = ctx;
653 return wpa_drv_tdls_oper(wpa_s, oper, peer);
654}
655
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800656
657static int wpa_supplicant_tdls_peer_addset(
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -0700658 void *ctx, const u8 *peer, int add, u16 aid, u16 capability,
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800659 const u8 *supp_rates, size_t supp_rates_len,
660 const struct ieee80211_ht_capabilities *ht_capab,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -0800661 const struct ieee80211_vht_capabilities *vht_capab,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700662 u8 qosinfo, int wmm, const u8 *ext_capab, size_t ext_capab_len,
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800663 const u8 *supp_channels, size_t supp_channels_len,
664 const u8 *supp_oper_classes, size_t supp_oper_classes_len)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800665{
666 struct wpa_supplicant *wpa_s = ctx;
667 struct hostapd_sta_add_params params;
668
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800669 os_memset(&params, 0, sizeof(params));
670
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800671 params.addr = peer;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -0700672 params.aid = aid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800673 params.capability = capability;
674 params.flags = WPA_STA_TDLS_PEER | WPA_STA_AUTHORIZED;
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800675
676 /*
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700677 * Don't rely only on qosinfo for WMM capability. It may be 0 even when
678 * present. Allow the WMM IE to also indicate QoS support.
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800679 */
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700680 if (wmm || qosinfo)
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800681 params.flags |= WPA_STA_WMM;
682
683 params.ht_capabilities = ht_capab;
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -0800684 params.vht_capabilities = vht_capab;
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800685 params.qosinfo = qosinfo;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800686 params.listen_interval = 0;
687 params.supp_rates = supp_rates;
688 params.supp_rates_len = supp_rates_len;
689 params.set = !add;
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800690 params.ext_capab = ext_capab;
691 params.ext_capab_len = ext_capab_len;
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800692 params.supp_channels = supp_channels;
693 params.supp_channels_len = supp_channels_len;
694 params.supp_oper_classes = supp_oper_classes;
695 params.supp_oper_classes_len = supp_oper_classes_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800696
697 return wpa_drv_sta_add(wpa_s, &params);
698}
699
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800700
701static int wpa_supplicant_tdls_enable_channel_switch(
702 void *ctx, const u8 *addr, u8 oper_class,
703 const struct hostapd_freq_params *params)
704{
705 struct wpa_supplicant *wpa_s = ctx;
706
707 return wpa_drv_tdls_enable_channel_switch(wpa_s, addr, oper_class,
708 params);
709}
710
711
712static int wpa_supplicant_tdls_disable_channel_switch(void *ctx, const u8 *addr)
713{
714 struct wpa_supplicant *wpa_s = ctx;
715
716 return wpa_drv_tdls_disable_channel_switch(wpa_s, addr);
717}
718
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700719#endif /* CONFIG_TDLS */
720
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700721#endif /* CONFIG_NO_WPA */
722
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700723
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800724enum wpa_ctrl_req_type wpa_supplicant_ctrl_req_from_string(const char *field)
725{
726 if (os_strcmp(field, "IDENTITY") == 0)
727 return WPA_CTRL_REQ_EAP_IDENTITY;
728 else if (os_strcmp(field, "PASSWORD") == 0)
729 return WPA_CTRL_REQ_EAP_PASSWORD;
730 else if (os_strcmp(field, "NEW_PASSWORD") == 0)
731 return WPA_CTRL_REQ_EAP_NEW_PASSWORD;
732 else if (os_strcmp(field, "PIN") == 0)
733 return WPA_CTRL_REQ_EAP_PIN;
734 else if (os_strcmp(field, "OTP") == 0)
735 return WPA_CTRL_REQ_EAP_OTP;
736 else if (os_strcmp(field, "PASSPHRASE") == 0)
737 return WPA_CTRL_REQ_EAP_PASSPHRASE;
Dmitry Shmidt051af732013-10-22 13:52:46 -0700738 else if (os_strcmp(field, "SIM") == 0)
739 return WPA_CTRL_REQ_SIM;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800740 return WPA_CTRL_REQ_UNKNOWN;
741}
742
743
744const char * wpa_supplicant_ctrl_req_to_string(enum wpa_ctrl_req_type field,
745 const char *default_txt,
746 const char **txt)
747{
748 const char *ret = NULL;
749
750 *txt = default_txt;
751
752 switch (field) {
753 case WPA_CTRL_REQ_EAP_IDENTITY:
754 *txt = "Identity";
755 ret = "IDENTITY";
756 break;
757 case WPA_CTRL_REQ_EAP_PASSWORD:
758 *txt = "Password";
759 ret = "PASSWORD";
760 break;
761 case WPA_CTRL_REQ_EAP_NEW_PASSWORD:
762 *txt = "New Password";
763 ret = "NEW_PASSWORD";
764 break;
765 case WPA_CTRL_REQ_EAP_PIN:
766 *txt = "PIN";
767 ret = "PIN";
768 break;
769 case WPA_CTRL_REQ_EAP_OTP:
770 ret = "OTP";
771 break;
772 case WPA_CTRL_REQ_EAP_PASSPHRASE:
773 *txt = "Private key passphrase";
774 ret = "PASSPHRASE";
775 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -0700776 case WPA_CTRL_REQ_SIM:
777 ret = "SIM";
778 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800779 default:
780 break;
781 }
782
783 /* txt needs to be something */
784 if (*txt == NULL) {
785 wpa_printf(MSG_WARNING, "No message for request %d", field);
786 ret = NULL;
787 }
788
789 return ret;
790}
791
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700792#ifdef IEEE8021X_EAPOL
793#if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800794static void wpa_supplicant_eap_param_needed(void *ctx,
795 enum wpa_ctrl_req_type field,
796 const char *default_txt)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700797{
798 struct wpa_supplicant *wpa_s = ctx;
799 struct wpa_ssid *ssid = wpa_s->current_ssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800800 const char *field_name, *txt = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700801 char *buf;
802 size_t buflen;
803 int len;
804
805 if (ssid == NULL)
806 return;
807
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800808 wpas_notify_network_request(wpa_s, ssid, field, default_txt);
809
810 field_name = wpa_supplicant_ctrl_req_to_string(field, default_txt,
811 &txt);
812 if (field_name == NULL) {
813 wpa_printf(MSG_WARNING, "Unhandled EAP param %d needed",
814 field);
815 return;
816 }
817
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800818 wpas_notify_eap_status(wpa_s, "eap parameter needed", field_name);
819
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700820 buflen = 100 + os_strlen(txt) + ssid->ssid_len;
821 buf = os_malloc(buflen);
822 if (buf == NULL)
823 return;
824 len = os_snprintf(buf, buflen,
825 WPA_CTRL_REQ "%s-%d:%s needed for SSID ",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800826 field_name, ssid->id, txt);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800827 if (os_snprintf_error(buflen, len)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700828 os_free(buf);
829 return;
830 }
831 if (ssid->ssid && buflen > len + ssid->ssid_len) {
832 os_memcpy(buf + len, ssid->ssid, ssid->ssid_len);
833 len += ssid->ssid_len;
834 buf[len] = '\0';
835 }
836 buf[buflen - 1] = '\0';
837 wpa_msg(wpa_s, MSG_INFO, "%s", buf);
838 os_free(buf);
839}
840#else /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
841#define wpa_supplicant_eap_param_needed NULL
842#endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
843
844
845static void wpa_supplicant_port_cb(void *ctx, int authorized)
846{
847 struct wpa_supplicant *wpa_s = ctx;
848#ifdef CONFIG_AP
849 if (wpa_s->ap_iface) {
850 wpa_printf(MSG_DEBUG, "AP mode active - skip EAPOL Supplicant "
851 "port status: %s",
852 authorized ? "Authorized" : "Unauthorized");
853 return;
854 }
855#endif /* CONFIG_AP */
856 wpa_printf(MSG_DEBUG, "EAPOL: Supplicant port status: %s",
857 authorized ? "Authorized" : "Unauthorized");
858 wpa_drv_set_supp_port(wpa_s, authorized);
859}
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700860
861
862static void wpa_supplicant_cert_cb(void *ctx, int depth, const char *subject,
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800863 const char *altsubject[], int num_altsubject,
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700864 const char *cert_hash,
865 const struct wpabuf *cert)
866{
867 struct wpa_supplicant *wpa_s = ctx;
868
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800869 wpas_notify_certification(wpa_s, depth, subject, altsubject,
870 num_altsubject, cert_hash, cert);
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700871}
Dmitry Shmidt04949592012-07-19 12:16:46 -0700872
873
874static void wpa_supplicant_status_cb(void *ctx, const char *status,
875 const char *parameter)
876{
877 struct wpa_supplicant *wpa_s = ctx;
878
879 wpas_notify_eap_status(wpa_s, status, parameter);
880}
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700881
882
883static void wpa_supplicant_set_anon_id(void *ctx, const u8 *id, size_t len)
884{
885 struct wpa_supplicant *wpa_s = ctx;
886 char *str;
887 int res;
888
889 wpa_hexdump_ascii(MSG_DEBUG, "EAP method updated anonymous_identity",
890 id, len);
891
892 if (wpa_s->current_ssid == NULL)
893 return;
894
895 if (id == NULL) {
896 if (wpa_config_set(wpa_s->current_ssid, "anonymous_identity",
897 "NULL", 0) < 0)
898 return;
899 } else {
900 str = os_malloc(len * 2 + 1);
901 if (str == NULL)
902 return;
903 wpa_snprintf_hex(str, len * 2 + 1, id, len);
904 res = wpa_config_set(wpa_s->current_ssid, "anonymous_identity",
905 str, 0);
906 os_free(str);
907 if (res < 0)
908 return;
909 }
910
911 if (wpa_s->conf->update_config) {
912 res = wpa_config_write(wpa_s->confname, wpa_s->conf);
913 if (res) {
914 wpa_printf(MSG_DEBUG, "Failed to update config after "
915 "anonymous_id update");
916 }
917 }
918}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700919#endif /* IEEE8021X_EAPOL */
920
921
922int wpa_supplicant_init_eapol(struct wpa_supplicant *wpa_s)
923{
924#ifdef IEEE8021X_EAPOL
925 struct eapol_ctx *ctx;
926 ctx = os_zalloc(sizeof(*ctx));
927 if (ctx == NULL) {
928 wpa_printf(MSG_ERROR, "Failed to allocate EAPOL context.");
929 return -1;
930 }
931
932 ctx->ctx = wpa_s;
933 ctx->msg_ctx = wpa_s;
934 ctx->eapol_send_ctx = wpa_s;
935 ctx->preauth = 0;
936 ctx->eapol_done_cb = wpa_supplicant_notify_eapol_done;
937 ctx->eapol_send = wpa_supplicant_eapol_send;
938 ctx->set_wep_key = wpa_eapol_set_wep_key;
Dmitry Shmidt700a1372013-03-15 14:14:44 -0700939#ifndef CONFIG_NO_CONFIG_BLOBS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700940 ctx->set_config_blob = wpa_supplicant_set_config_blob;
941 ctx->get_config_blob = wpa_supplicant_get_config_blob;
Dmitry Shmidt700a1372013-03-15 14:14:44 -0700942#endif /* CONFIG_NO_CONFIG_BLOBS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700943 ctx->aborted_cached = wpa_supplicant_aborted_cached;
944 ctx->opensc_engine_path = wpa_s->conf->opensc_engine_path;
945 ctx->pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path;
946 ctx->pkcs11_module_path = wpa_s->conf->pkcs11_module_path;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800947 ctx->openssl_ciphers = wpa_s->conf->openssl_ciphers;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700948 ctx->wps = wpa_s->wps;
949 ctx->eap_param_needed = wpa_supplicant_eap_param_needed;
950 ctx->port_cb = wpa_supplicant_port_cb;
951 ctx->cb = wpa_supplicant_eapol_cb;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700952 ctx->cert_cb = wpa_supplicant_cert_cb;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800953 ctx->cert_in_cb = wpa_s->conf->cert_in_cb;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700954 ctx->status_cb = wpa_supplicant_status_cb;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700955 ctx->set_anon_id = wpa_supplicant_set_anon_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700956 ctx->cb_ctx = wpa_s;
957 wpa_s->eapol = eapol_sm_init(ctx);
958 if (wpa_s->eapol == NULL) {
959 os_free(ctx);
960 wpa_printf(MSG_ERROR, "Failed to initialize EAPOL state "
961 "machines.");
962 return -1;
963 }
964#endif /* IEEE8021X_EAPOL */
965
966 return 0;
967}
968
969
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800970#ifndef CONFIG_NO_WPA
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800971static void wpa_supplicant_set_rekey_offload(void *ctx, const u8 *kek,
972 const u8 *kck,
973 const u8 *replay_ctr)
974{
975 struct wpa_supplicant *wpa_s = ctx;
976
977 wpa_drv_set_rekey_info(wpa_s, kek, kck, replay_ctr);
978}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800979#endif /* CONFIG_NO_WPA */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800980
981
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800982static int wpa_supplicant_key_mgmt_set_pmk(void *ctx, const u8 *pmk,
983 size_t pmk_len)
984{
985 struct wpa_supplicant *wpa_s = ctx;
986
987 if (wpa_s->conf->key_mgmt_offload)
988 return wpa_drv_set_key(wpa_s, WPA_ALG_PMK, NULL, 0, 0,
989 NULL, 0, pmk, pmk_len);
990 else
991 return 0;
992}
993
994
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700995int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s)
996{
997#ifndef CONFIG_NO_WPA
998 struct wpa_sm_ctx *ctx;
999 ctx = os_zalloc(sizeof(*ctx));
1000 if (ctx == NULL) {
1001 wpa_printf(MSG_ERROR, "Failed to allocate WPA context.");
1002 return -1;
1003 }
1004
1005 ctx->ctx = wpa_s;
1006 ctx->msg_ctx = wpa_s;
1007 ctx->set_state = _wpa_supplicant_set_state;
1008 ctx->get_state = _wpa_supplicant_get_state;
1009 ctx->deauthenticate = _wpa_supplicant_deauthenticate;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001010 ctx->set_key = wpa_supplicant_set_key;
1011 ctx->get_network_ctx = wpa_supplicant_get_network_ctx;
1012 ctx->get_bssid = wpa_supplicant_get_bssid;
1013 ctx->ether_send = _wpa_ether_send;
1014 ctx->get_beacon_ie = wpa_supplicant_get_beacon_ie;
1015 ctx->alloc_eapol = _wpa_alloc_eapol;
1016 ctx->cancel_auth_timeout = _wpa_supplicant_cancel_auth_timeout;
1017 ctx->add_pmkid = wpa_supplicant_add_pmkid;
1018 ctx->remove_pmkid = wpa_supplicant_remove_pmkid;
1019#ifndef CONFIG_NO_CONFIG_BLOBS
1020 ctx->set_config_blob = wpa_supplicant_set_config_blob;
1021 ctx->get_config_blob = wpa_supplicant_get_config_blob;
1022#endif /* CONFIG_NO_CONFIG_BLOBS */
1023 ctx->mlme_setprotection = wpa_supplicant_mlme_setprotection;
1024#ifdef CONFIG_IEEE80211R
1025 ctx->update_ft_ies = wpa_supplicant_update_ft_ies;
1026 ctx->send_ft_action = wpa_supplicant_send_ft_action;
1027 ctx->mark_authenticated = wpa_supplicant_mark_authenticated;
1028#endif /* CONFIG_IEEE80211R */
1029#ifdef CONFIG_TDLS
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001030 ctx->tdls_get_capa = wpa_supplicant_tdls_get_capa;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001031 ctx->send_tdls_mgmt = wpa_supplicant_send_tdls_mgmt;
1032 ctx->tdls_oper = wpa_supplicant_tdls_oper;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001033 ctx->tdls_peer_addset = wpa_supplicant_tdls_peer_addset;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001034 ctx->tdls_enable_channel_switch =
1035 wpa_supplicant_tdls_enable_channel_switch;
1036 ctx->tdls_disable_channel_switch =
1037 wpa_supplicant_tdls_disable_channel_switch;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001038#endif /* CONFIG_TDLS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001039 ctx->set_rekey_offload = wpa_supplicant_set_rekey_offload;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001040 ctx->key_mgmt_set_pmk = wpa_supplicant_key_mgmt_set_pmk;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001041
1042 wpa_s->wpa = wpa_sm_init(ctx);
1043 if (wpa_s->wpa == NULL) {
1044 wpa_printf(MSG_ERROR, "Failed to initialize WPA state "
1045 "machine");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001046 os_free(ctx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001047 return -1;
1048 }
1049#endif /* CONFIG_NO_WPA */
1050
1051 return 0;
1052}
1053
1054
1055void wpa_supplicant_rsn_supp_set_config(struct wpa_supplicant *wpa_s,
1056 struct wpa_ssid *ssid)
1057{
1058 struct rsn_supp_config conf;
1059 if (ssid) {
1060 os_memset(&conf, 0, sizeof(conf));
1061 conf.network_ctx = ssid;
1062 conf.peerkey_enabled = ssid->peerkey;
1063 conf.allowed_pairwise_cipher = ssid->pairwise_cipher;
1064#ifdef IEEE8021X_EAPOL
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001065 conf.proactive_key_caching = ssid->proactive_key_caching < 0 ?
1066 wpa_s->conf->okc : ssid->proactive_key_caching;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001067 conf.eap_workaround = ssid->eap_workaround;
1068 conf.eap_conf_ctx = &ssid->eap;
1069#endif /* IEEE8021X_EAPOL */
1070 conf.ssid = ssid->ssid;
1071 conf.ssid_len = ssid->ssid_len;
1072 conf.wpa_ptk_rekey = ssid->wpa_ptk_rekey;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001073#ifdef CONFIG_P2P
1074 if (ssid->p2p_group && wpa_s->current_bss &&
1075 !wpa_s->p2p_disable_ip_addr_req) {
1076 struct wpabuf *p2p;
1077 p2p = wpa_bss_get_vendor_ie_multi(wpa_s->current_bss,
1078 P2P_IE_VENDOR_TYPE);
1079 if (p2p) {
1080 u8 group_capab;
1081 group_capab = p2p_get_group_capab(p2p);
1082 if (group_capab &
1083 P2P_GROUP_CAPAB_IP_ADDR_ALLOCATION)
1084 conf.p2p = 1;
1085 wpabuf_free(p2p);
1086 }
1087 }
1088#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001089 }
1090 wpa_sm_set_config(wpa_s->wpa, ssid ? &conf : NULL);
1091}