Added an optional mitigation mechanism for certain attacks against TKIP by
[mech_eap.git] / wpa_supplicant / wpas_glue.c
1 /*
2  * WPA Supplicant - Glue code to setup EAPOL and RSN modules
3  * Copyright (c) 2003-2008, Jouni Malinen <j@w1.fi>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  * Alternatively, this software may be distributed under the terms of BSD
10  * license.
11  *
12  * See README and COPYING for more details.
13  */
14
15 #include "includes.h"
16
17 #include "common.h"
18 #include "eapol_supp/eapol_supp_sm.h"
19 #include "wpa.h"
20 #include "eloop.h"
21 #include "config.h"
22 #include "l2_packet/l2_packet.h"
23 #include "wpa_common.h"
24 #include "wpa_supplicant_i.h"
25 #include "pmksa_cache.h"
26 #include "mlme.h"
27 #include "ieee802_11_defs.h"
28 #include "wpa_ctrl.h"
29 #include "wpas_glue.h"
30
31
32 #ifndef CONFIG_NO_CONFIG_BLOBS
33 #if defined(IEEE8021X_EAPOL) || !defined(CONFIG_NO_WPA)
34 static 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
49 static const struct wpa_config_blob *
50 wpa_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)
60 static 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  */
96 static int wpa_ether_send(struct wpa_supplicant *wpa_s, const u8 *dest,
97                           u16 proto, const u8 *buf, size_t len)
98 {
99         if (wpa_s->l2) {
100                 return l2_packet_send(wpa_s->l2, dest, proto, buf, len);
101         }
102
103         return wpa_drv_send_eapol(wpa_s, dest, proto, buf, len);
104 }
105 #endif /* IEEE8021X_EAPOL || !CONFIG_NO_WPA */
106
107
108 #ifdef IEEE8021X_EAPOL
109
110 /**
111  * wpa_supplicant_eapol_send - Send IEEE 802.1X EAPOL packet to Authenticator
112  * @ctx: Pointer to wpa_supplicant data (wpa_s)
113  * @type: IEEE 802.1X packet type (IEEE802_1X_TYPE_*)
114  * @buf: EAPOL payload (after IEEE 802.1X header)
115  * @len: EAPOL payload length
116  * Returns: >=0 on success, <0 on failure
117  *
118  * This function adds Ethernet and IEEE 802.1X header and sends the EAPOL frame
119  * to the current Authenticator.
120  */
121 static int wpa_supplicant_eapol_send(void *ctx, int type, const u8 *buf,
122                                      size_t len)
123 {
124         struct wpa_supplicant *wpa_s = ctx;
125         u8 *msg, *dst, bssid[ETH_ALEN];
126         size_t msglen;
127         int res;
128
129         /* TODO: could add l2_packet_sendmsg that allows fragments to avoid
130          * extra copy here */
131
132         if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
133             wpa_s->key_mgmt == WPA_KEY_MGMT_NONE) {
134                 /* Current SSID is not using IEEE 802.1X/EAP, so drop possible
135                  * EAPOL frames (mainly, EAPOL-Start) from EAPOL state
136                  * machines. */
137                 wpa_printf(MSG_DEBUG, "WPA: drop TX EAPOL in non-IEEE 802.1X "
138                            "mode (type=%d len=%lu)", type,
139                            (unsigned long) len);
140                 return -1;
141         }
142
143         if (pmksa_cache_get_current(wpa_s->wpa) &&
144             type == IEEE802_1X_TYPE_EAPOL_START) {
145                 /* Trying to use PMKSA caching - do not send EAPOL-Start frames
146                  * since they will trigger full EAPOL authentication. */
147                 wpa_printf(MSG_DEBUG, "RSN: PMKSA caching - do not send "
148                            "EAPOL-Start");
149                 return -1;
150         }
151
152         if (is_zero_ether_addr(wpa_s->bssid)) {
153                 wpa_printf(MSG_DEBUG, "BSSID not set when trying to send an "
154                            "EAPOL frame");
155                 if (wpa_drv_get_bssid(wpa_s, bssid) == 0 &&
156                     !is_zero_ether_addr(bssid)) {
157                         dst = bssid;
158                         wpa_printf(MSG_DEBUG, "Using current BSSID " MACSTR
159                                    " from the driver as the EAPOL destination",
160                                    MAC2STR(dst));
161                 } else {
162                         dst = wpa_s->last_eapol_src;
163                         wpa_printf(MSG_DEBUG, "Using the source address of the"
164                                    " last received EAPOL frame " MACSTR " as "
165                                    "the EAPOL destination",
166                                    MAC2STR(dst));
167                 }
168         } else {
169                 /* BSSID was already set (from (Re)Assoc event, so use it as
170                  * the EAPOL destination. */
171                 dst = wpa_s->bssid;
172         }
173
174         msg = wpa_alloc_eapol(wpa_s, type, buf, len, &msglen, NULL);
175         if (msg == NULL)
176                 return -1;
177
178         wpa_printf(MSG_DEBUG, "TX EAPOL: dst=" MACSTR, MAC2STR(dst));
179         wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", msg, msglen);
180         res = wpa_ether_send(wpa_s, dst, ETH_P_EAPOL, msg, msglen);
181         os_free(msg);
182         return res;
183 }
184
185
186 /**
187  * wpa_eapol_set_wep_key - set WEP key for the driver
188  * @ctx: Pointer to wpa_supplicant data (wpa_s)
189  * @unicast: 1 = individual unicast key, 0 = broadcast key
190  * @keyidx: WEP key index (0..3)
191  * @key: Pointer to key data
192  * @keylen: Key length in bytes
193  * Returns: 0 on success or < 0 on error.
194  */
195 static int wpa_eapol_set_wep_key(void *ctx, int unicast, int keyidx,
196                                  const u8 *key, size_t keylen)
197 {
198         struct wpa_supplicant *wpa_s = ctx;
199         if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
200                 int cipher = (keylen == 5) ? WPA_CIPHER_WEP40 :
201                         WPA_CIPHER_WEP104;
202                 if (unicast)
203                         wpa_s->pairwise_cipher = cipher;
204                 else
205                         wpa_s->group_cipher = cipher;
206         }
207         return wpa_drv_set_key(wpa_s, WPA_ALG_WEP,
208                                unicast ? wpa_s->bssid :
209                                (u8 *) "\xff\xff\xff\xff\xff\xff",
210                                keyidx, unicast, (u8 *) "", 0, key, keylen);
211 }
212
213
214 static void wpa_supplicant_aborted_cached(void *ctx)
215 {
216         struct wpa_supplicant *wpa_s = ctx;
217         wpa_sm_aborted_cached(wpa_s->wpa);
218 }
219
220
221 static void wpa_supplicant_eapol_cb(struct eapol_sm *eapol, int success,
222                                     void *ctx)
223 {
224         struct wpa_supplicant *wpa_s = ctx;
225         int res, pmk_len;
226         u8 pmk[PMK_LEN];
227
228         wpa_printf(MSG_DEBUG, "EAPOL authentication completed %ssuccessfully",
229                    success ? "" : "un");
230
231         if (!success) {
232                 /*
233                  * Make sure we do not get stuck here waiting for long EAPOL
234                  * timeout if the AP does not disconnect in case of
235                  * authentication failure.
236                  */
237                 wpa_supplicant_req_auth_timeout(wpa_s, 2, 0);
238         }
239
240         if (!success || !wpa_s->driver_4way_handshake)
241                 return;
242
243         if (!wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt))
244                 return;
245
246         wpa_printf(MSG_DEBUG, "Configure PMK for driver-based RSN 4-way "
247                    "handshake");
248
249         pmk_len = PMK_LEN;
250         res = eapol_sm_get_key(eapol, pmk, PMK_LEN);
251         if (res) {
252                 /*
253                  * EAP-LEAP is an exception from other EAP methods: it
254                  * uses only 16-byte PMK.
255                  */
256                 res = eapol_sm_get_key(eapol, pmk, 16);
257                 pmk_len = 16;
258         }
259
260         if (res) {
261                 wpa_printf(MSG_DEBUG, "Failed to get PMK from EAPOL state "
262                            "machines");
263                 return;
264         }
265
266         if (wpa_drv_set_key(wpa_s, WPA_ALG_PMK, NULL, 0, 0, NULL, 0, pmk,
267                             pmk_len)) {
268                 wpa_printf(MSG_DEBUG, "Failed to set PMK to the driver");
269         }
270
271         wpa_supplicant_cancel_scan(wpa_s);
272         wpa_supplicant_cancel_auth_timeout(wpa_s);
273         wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
274
275 }
276
277
278 static void wpa_supplicant_notify_eapol_done(void *ctx)
279 {
280         struct wpa_supplicant *wpa_s = ctx;
281         wpa_msg(wpa_s, MSG_DEBUG, "WPA: EAPOL processing complete");
282         if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
283                 wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE);
284         } else {
285                 wpa_supplicant_cancel_auth_timeout(wpa_s);
286                 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
287         }
288 }
289
290 #endif /* IEEE8021X_EAPOL */
291
292
293 #ifndef CONFIG_NO_WPA
294
295 static int wpa_get_beacon_ie(struct wpa_supplicant *wpa_s)
296 {
297         size_t i;
298         int ret = 0;
299         struct wpa_scan_res *curr = NULL;
300         struct wpa_ssid *ssid = wpa_s->current_ssid;
301         const u8 *ie;
302
303         if (wpa_s->scan_res == NULL)
304                 return -1;
305
306         for (i = 0; i < wpa_s->scan_res->num; i++) {
307                 struct wpa_scan_res *r = wpa_s->scan_res->res[i];
308                 if (os_memcmp(r->bssid, wpa_s->bssid, ETH_ALEN) != 0)
309                         continue;
310                 ie = wpa_scan_get_ie(r, WLAN_EID_SSID);
311                 if (ssid == NULL ||
312                     ((ie && ie[1] == ssid->ssid_len &&
313                       os_memcmp(ie + 2, ssid->ssid, ssid->ssid_len) == 0) ||
314                      ssid->ssid_len == 0)) {
315                         curr = r;
316                         break;
317                 }
318         }
319
320         if (curr) {
321                 ie = wpa_scan_get_vendor_ie(curr, WPA_IE_VENDOR_TYPE);
322                 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0))
323                         ret = -1;
324
325                 ie = wpa_scan_get_ie(curr, WLAN_EID_RSN);
326                 if (wpa_sm_set_ap_rsn_ie(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0))
327                         ret = -1;
328         } else {
329                 ret = -1;
330         }
331
332         return ret;
333 }
334
335
336 static int wpa_supplicant_get_beacon_ie(void *ctx)
337 {
338         struct wpa_supplicant *wpa_s = ctx;
339         if (wpa_get_beacon_ie(wpa_s) == 0) {
340                 return 0;
341         }
342
343         /* No WPA/RSN IE found in the cached scan results. Try to get updated
344          * scan results from the driver. */
345         if (wpa_supplicant_get_scan_results(wpa_s) < 0) {
346                 return -1;
347         }
348
349         return wpa_get_beacon_ie(wpa_s);
350 }
351
352
353 static u8 * _wpa_alloc_eapol(void *wpa_s, u8 type,
354                              const void *data, u16 data_len,
355                              size_t *msg_len, void **data_pos)
356 {
357         return wpa_alloc_eapol(wpa_s, type, data, data_len, msg_len, data_pos);
358 }
359
360
361 static int _wpa_ether_send(void *wpa_s, const u8 *dest, u16 proto,
362                            const u8 *buf, size_t len)
363 {
364         return wpa_ether_send(wpa_s, dest, proto, buf, len);
365 }
366
367
368 static void _wpa_supplicant_cancel_auth_timeout(void *wpa_s)
369 {
370         wpa_supplicant_cancel_auth_timeout(wpa_s);
371 }
372
373
374 static void _wpa_supplicant_set_state(void *wpa_s, wpa_states state)
375 {
376         wpa_supplicant_set_state(wpa_s, state);
377 }
378
379
380 /**
381  * wpa_supplicant_get_state - Get the connection state
382  * @wpa_s: Pointer to wpa_supplicant data
383  * Returns: The current connection state (WPA_*)
384  */
385 static wpa_states wpa_supplicant_get_state(struct wpa_supplicant *wpa_s)
386 {
387         return wpa_s->wpa_state;
388 }
389
390
391 static wpa_states _wpa_supplicant_get_state(void *wpa_s)
392 {
393         return wpa_supplicant_get_state(wpa_s);
394 }
395
396
397 static void _wpa_supplicant_disassociate(void *wpa_s, int reason_code)
398 {
399         wpa_supplicant_disassociate(wpa_s, reason_code);
400         /* Schedule a scan to make sure we continue looking for networks */
401         wpa_supplicant_req_scan(wpa_s, 0, 0);
402 }
403
404
405 static void _wpa_supplicant_deauthenticate(void *wpa_s, int reason_code)
406 {
407         wpa_supplicant_deauthenticate(wpa_s, reason_code);
408         /* Schedule a scan to make sure we continue looking for networks */
409         wpa_supplicant_req_scan(wpa_s, 0, 0);
410 }
411
412
413 static void * wpa_supplicant_get_network_ctx(void *wpa_s)
414 {
415         return wpa_supplicant_get_ssid(wpa_s);
416 }
417
418
419 static int wpa_supplicant_get_bssid(void *ctx, u8 *bssid)
420 {
421         struct wpa_supplicant *wpa_s = ctx;
422         if (wpa_s->use_client_mlme) {
423                 os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
424                 return 0;
425         }
426         return wpa_drv_get_bssid(wpa_s, bssid);
427 }
428
429
430 static int wpa_supplicant_set_key(void *_wpa_s, wpa_alg alg,
431                                   const u8 *addr, int key_idx, int set_tx,
432                                   const u8 *seq, size_t seq_len,
433                                   const u8 *key, size_t key_len)
434 {
435         struct wpa_supplicant *wpa_s = _wpa_s;
436         if (alg == WPA_ALG_TKIP && key_idx == 0 && key_len == 32) {
437                 /* Clear the MIC error counter when setting a new PTK. */
438                 wpa_s->mic_errors_seen = 0;
439         }
440         return wpa_drv_set_key(wpa_s, alg, addr, key_idx, set_tx, seq, seq_len,
441                                key, key_len);
442 }
443
444
445 static int wpa_supplicant_mlme_setprotection(void *wpa_s, const u8 *addr,
446                                              int protection_type,
447                                              int key_type)
448 {
449         return wpa_drv_mlme_setprotection(wpa_s, addr, protection_type,
450                                           key_type);
451 }
452
453
454 static int wpa_supplicant_add_pmkid(void *wpa_s,
455                                     const u8 *bssid, const u8 *pmkid)
456 {
457         return wpa_drv_add_pmkid(wpa_s, bssid, pmkid);
458 }
459
460
461 static int wpa_supplicant_remove_pmkid(void *wpa_s,
462                                        const u8 *bssid, const u8 *pmkid)
463 {
464         return wpa_drv_remove_pmkid(wpa_s, bssid, pmkid);
465 }
466
467
468 #ifdef CONFIG_IEEE80211R
469 static int wpa_supplicant_update_ft_ies(void *ctx, const u8 *md,
470                                         const u8 *ies, size_t ies_len)
471 {
472         struct wpa_supplicant *wpa_s = ctx;
473         if (wpa_s->use_client_mlme)
474                 return ieee80211_sta_update_ft_ies(wpa_s, md, ies, ies_len);
475         return wpa_drv_update_ft_ies(wpa_s, md, ies, ies_len);
476 }
477
478
479 static int wpa_supplicant_send_ft_action(void *ctx, u8 action,
480                                          const u8 *target_ap,
481                                          const u8 *ies, size_t ies_len)
482 {
483         struct wpa_supplicant *wpa_s = ctx;
484         if (wpa_s->use_client_mlme)
485                 return ieee80211_sta_send_ft_action(wpa_s, action, target_ap,
486                                                     ies, ies_len);
487         return wpa_drv_send_ft_action(wpa_s, action, target_ap, ies, ies_len);
488 }
489 #endif /* CONFIG_IEEE80211R */
490
491 #endif /* CONFIG_NO_WPA */
492
493
494 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
495 static void wpa_supplicant_eap_param_needed(void *ctx, const char *field,
496                                             const char *txt)
497 {
498         struct wpa_supplicant *wpa_s = ctx;
499         struct wpa_ssid *ssid = wpa_s->current_ssid;
500         char *buf;
501         size_t buflen;
502         int len;
503
504         if (ssid == NULL)
505                 return;
506
507         buflen = 100 + os_strlen(txt) + ssid->ssid_len;
508         buf = os_malloc(buflen);
509         if (buf == NULL)
510                 return;
511         len = os_snprintf(buf, buflen,
512                           WPA_CTRL_REQ "%s-%d:%s needed for SSID ",
513                           field, ssid->id, txt);
514         if (len < 0 || (size_t) len >= buflen) {
515                 os_free(buf);
516                 return;
517         }
518         if (ssid->ssid && buflen > len + ssid->ssid_len) {
519                 os_memcpy(buf + len, ssid->ssid, ssid->ssid_len);
520                 len += ssid->ssid_len;
521                 buf[len] = '\0';
522         }
523         buf[buflen - 1] = '\0';
524         wpa_msg(wpa_s, MSG_INFO, "%s", buf);
525         os_free(buf);
526 }
527 #else /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
528 #define wpa_supplicant_eap_param_needed NULL
529 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
530
531
532 int wpa_supplicant_init_eapol(struct wpa_supplicant *wpa_s)
533 {
534 #ifdef IEEE8021X_EAPOL
535         struct eapol_ctx *ctx;
536         ctx = os_zalloc(sizeof(*ctx));
537         if (ctx == NULL) {
538                 wpa_printf(MSG_ERROR, "Failed to allocate EAPOL context.");
539                 return -1;
540         }
541
542         ctx->ctx = wpa_s;
543         ctx->msg_ctx = wpa_s;
544         ctx->eapol_send_ctx = wpa_s;
545         ctx->preauth = 0;
546         ctx->eapol_done_cb = wpa_supplicant_notify_eapol_done;
547         ctx->eapol_send = wpa_supplicant_eapol_send;
548         ctx->set_wep_key = wpa_eapol_set_wep_key;
549         ctx->set_config_blob = wpa_supplicant_set_config_blob;
550         ctx->get_config_blob = wpa_supplicant_get_config_blob;
551         ctx->aborted_cached = wpa_supplicant_aborted_cached;
552 #ifdef EAP_TLS_OPENSSL
553         ctx->opensc_engine_path = wpa_s->conf->opensc_engine_path;
554         ctx->pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path;
555         ctx->pkcs11_module_path = wpa_s->conf->pkcs11_module_path;
556 #endif /* EAP_TLS_OPENSSL */
557         ctx->eap_param_needed = wpa_supplicant_eap_param_needed;
558         ctx->cb = wpa_supplicant_eapol_cb;
559         ctx->cb_ctx = wpa_s;
560         wpa_s->eapol = eapol_sm_init(ctx);
561         if (wpa_s->eapol == NULL) {
562                 os_free(ctx);
563                 wpa_printf(MSG_ERROR, "Failed to initialize EAPOL state "
564                            "machines.");
565                 return -1;
566         }
567 #endif /* IEEE8021X_EAPOL */
568
569         return 0;
570 }
571
572
573 int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s)
574 {
575 #ifndef CONFIG_NO_WPA
576         struct wpa_sm_ctx *ctx;
577         ctx = os_zalloc(sizeof(*ctx));
578         if (ctx == NULL) {
579                 wpa_printf(MSG_ERROR, "Failed to allocate WPA context.");
580                 return -1;
581         }
582
583         ctx->ctx = wpa_s;
584         ctx->set_state = _wpa_supplicant_set_state;
585         ctx->get_state = _wpa_supplicant_get_state;
586         ctx->deauthenticate = _wpa_supplicant_deauthenticate;
587         ctx->disassociate = _wpa_supplicant_disassociate;
588         ctx->set_key = wpa_supplicant_set_key;
589         ctx->get_network_ctx = wpa_supplicant_get_network_ctx;
590         ctx->get_bssid = wpa_supplicant_get_bssid;
591         ctx->ether_send = _wpa_ether_send;
592         ctx->get_beacon_ie = wpa_supplicant_get_beacon_ie;
593         ctx->alloc_eapol = _wpa_alloc_eapol;
594         ctx->cancel_auth_timeout = _wpa_supplicant_cancel_auth_timeout;
595         ctx->add_pmkid = wpa_supplicant_add_pmkid;
596         ctx->remove_pmkid = wpa_supplicant_remove_pmkid;
597 #ifndef CONFIG_NO_CONFIG_BLOBS
598         ctx->set_config_blob = wpa_supplicant_set_config_blob;
599         ctx->get_config_blob = wpa_supplicant_get_config_blob;
600 #endif /* CONFIG_NO_CONFIG_BLOBS */
601         ctx->mlme_setprotection = wpa_supplicant_mlme_setprotection;
602 #ifdef CONFIG_IEEE80211R
603         ctx->update_ft_ies = wpa_supplicant_update_ft_ies;
604         ctx->send_ft_action = wpa_supplicant_send_ft_action;
605 #endif /* CONFIG_IEEE80211R */
606
607         wpa_s->wpa = wpa_sm_init(ctx);
608         if (wpa_s->wpa == NULL) {
609                 wpa_printf(MSG_ERROR, "Failed to initialize WPA state "
610                            "machine");
611                 return -1;
612         }
613 #endif /* CONFIG_NO_WPA */
614
615         return 0;
616 }
617
618
619 void wpa_supplicant_rsn_supp_set_config(struct wpa_supplicant *wpa_s,
620                                         struct wpa_ssid *ssid)
621 {
622         struct rsn_supp_config conf;
623         if (ssid) {
624                 os_memset(&conf, 0, sizeof(conf));
625                 conf.network_ctx = ssid;
626                 conf.peerkey_enabled = ssid->peerkey;
627                 conf.allowed_pairwise_cipher = ssid->pairwise_cipher;
628 #ifdef IEEE8021X_EAPOL
629                 conf.eap_workaround = ssid->eap_workaround;
630                 conf.eap_conf_ctx = &ssid->eap;
631 #endif /* IEEE8021X_EAPOL */
632                 conf.ssid = ssid->ssid;
633                 conf.ssid_len = ssid->ssid_len;
634                 conf.wpa_ptk_rekey = ssid->wpa_ptk_rekey;
635         }
636         wpa_sm_set_config(wpa_s->wpa, ssid ? &conf : NULL);
637 }