Do not store raw scan results
[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 "rsn_supp/wpa.h"
20 #include "eloop.h"
21 #include "config.h"
22 #include "l2_packet/l2_packet.h"
23 #include "common/wpa_common.h"
24 #include "wpa_supplicant_i.h"
25 #include "driver_i.h"
26 #include "rsn_supp/pmksa_cache.h"
27 #include "mlme.h"
28 #include "sme.h"
29 #include "common/ieee802_11_defs.h"
30 #include "common/wpa_ctrl.h"
31 #include "wpas_glue.h"
32 #include "wps_supplicant.h"
33 #include "bss.h"
34
35
36 #ifndef CONFIG_NO_CONFIG_BLOBS
37 #if defined(IEEE8021X_EAPOL) || !defined(CONFIG_NO_WPA)
38 static void wpa_supplicant_set_config_blob(void *ctx,
39                                            struct wpa_config_blob *blob)
40 {
41         struct wpa_supplicant *wpa_s = ctx;
42         wpa_config_set_blob(wpa_s->conf, blob);
43         if (wpa_s->conf->update_config) {
44                 int ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
45                 if (ret) {
46                         wpa_printf(MSG_DEBUG, "Failed to update config after "
47                                    "blob set");
48                 }
49         }
50 }
51
52
53 static const struct wpa_config_blob *
54 wpa_supplicant_get_config_blob(void *ctx, const char *name)
55 {
56         struct wpa_supplicant *wpa_s = ctx;
57         return wpa_config_get_blob(wpa_s->conf, name);
58 }
59 #endif /* defined(IEEE8021X_EAPOL) || !defined(CONFIG_NO_WPA) */
60 #endif /* CONFIG_NO_CONFIG_BLOBS */
61
62
63 #if defined(IEEE8021X_EAPOL) || !defined(CONFIG_NO_WPA)
64 static u8 * wpa_alloc_eapol(const struct wpa_supplicant *wpa_s, u8 type,
65                             const void *data, u16 data_len,
66                             size_t *msg_len, void **data_pos)
67 {
68         struct ieee802_1x_hdr *hdr;
69
70         *msg_len = sizeof(*hdr) + data_len;
71         hdr = os_malloc(*msg_len);
72         if (hdr == NULL)
73                 return NULL;
74
75         hdr->version = wpa_s->conf->eapol_version;
76         hdr->type = type;
77         hdr->length = host_to_be16(data_len);
78
79         if (data)
80                 os_memcpy(hdr + 1, data, data_len);
81         else
82                 os_memset(hdr + 1, 0, data_len);
83
84         if (data_pos)
85                 *data_pos = hdr + 1;
86
87         return (u8 *) hdr;
88 }
89
90
91 /**
92  * wpa_ether_send - Send Ethernet frame
93  * @wpa_s: Pointer to wpa_supplicant data
94  * @dest: Destination MAC address
95  * @proto: Ethertype in host byte order
96  * @buf: Frame payload starting from IEEE 802.1X header
97  * @len: Frame payload length
98  * Returns: >=0 on success, <0 on failure
99  */
100 static int wpa_ether_send(struct wpa_supplicant *wpa_s, const u8 *dest,
101                           u16 proto, const u8 *buf, size_t len)
102 {
103         if (wpa_s->l2) {
104                 return l2_packet_send(wpa_s->l2, dest, proto, buf, len);
105         }
106
107         return wpa_drv_send_eapol(wpa_s, dest, proto, buf, len);
108 }
109 #endif /* IEEE8021X_EAPOL || !CONFIG_NO_WPA */
110
111
112 #ifdef IEEE8021X_EAPOL
113
114 /**
115  * wpa_supplicant_eapol_send - Send IEEE 802.1X EAPOL packet to Authenticator
116  * @ctx: Pointer to wpa_supplicant data (wpa_s)
117  * @type: IEEE 802.1X packet type (IEEE802_1X_TYPE_*)
118  * @buf: EAPOL payload (after IEEE 802.1X header)
119  * @len: EAPOL payload length
120  * Returns: >=0 on success, <0 on failure
121  *
122  * This function adds Ethernet and IEEE 802.1X header and sends the EAPOL frame
123  * to the current Authenticator.
124  */
125 static int wpa_supplicant_eapol_send(void *ctx, int type, const u8 *buf,
126                                      size_t len)
127 {
128         struct wpa_supplicant *wpa_s = ctx;
129         u8 *msg, *dst, bssid[ETH_ALEN];
130         size_t msglen;
131         int res;
132
133         /* TODO: could add l2_packet_sendmsg that allows fragments to avoid
134          * extra copy here */
135
136         if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
137             wpa_s->key_mgmt == WPA_KEY_MGMT_NONE) {
138                 /* Current SSID is not using IEEE 802.1X/EAP, so drop possible
139                  * EAPOL frames (mainly, EAPOL-Start) from EAPOL state
140                  * machines. */
141                 wpa_printf(MSG_DEBUG, "WPA: drop TX EAPOL in non-IEEE 802.1X "
142                            "mode (type=%d len=%lu)", type,
143                            (unsigned long) len);
144                 return -1;
145         }
146
147         if (pmksa_cache_get_current(wpa_s->wpa) &&
148             type == IEEE802_1X_TYPE_EAPOL_START) {
149                 /* Trying to use PMKSA caching - do not send EAPOL-Start frames
150                  * since they will trigger full EAPOL authentication. */
151                 wpa_printf(MSG_DEBUG, "RSN: PMKSA caching - do not send "
152                            "EAPOL-Start");
153                 return -1;
154         }
155
156         if (is_zero_ether_addr(wpa_s->bssid)) {
157                 wpa_printf(MSG_DEBUG, "BSSID not set when trying to send an "
158                            "EAPOL frame");
159                 if (wpa_drv_get_bssid(wpa_s, bssid) == 0 &&
160                     !is_zero_ether_addr(bssid)) {
161                         dst = bssid;
162                         wpa_printf(MSG_DEBUG, "Using current BSSID " MACSTR
163                                    " from the driver as the EAPOL destination",
164                                    MAC2STR(dst));
165                 } else {
166                         dst = wpa_s->last_eapol_src;
167                         wpa_printf(MSG_DEBUG, "Using the source address of the"
168                                    " last received EAPOL frame " MACSTR " as "
169                                    "the EAPOL destination",
170                                    MAC2STR(dst));
171                 }
172         } else {
173                 /* BSSID was already set (from (Re)Assoc event, so use it as
174                  * the EAPOL destination. */
175                 dst = wpa_s->bssid;
176         }
177
178         msg = wpa_alloc_eapol(wpa_s, type, buf, len, &msglen, NULL);
179         if (msg == NULL)
180                 return -1;
181
182         wpa_printf(MSG_DEBUG, "TX EAPOL: dst=" MACSTR, MAC2STR(dst));
183         wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", msg, msglen);
184         res = wpa_ether_send(wpa_s, dst, ETH_P_EAPOL, msg, msglen);
185         os_free(msg);
186         return res;
187 }
188
189
190 /**
191  * wpa_eapol_set_wep_key - set WEP key for the driver
192  * @ctx: Pointer to wpa_supplicant data (wpa_s)
193  * @unicast: 1 = individual unicast key, 0 = broadcast key
194  * @keyidx: WEP key index (0..3)
195  * @key: Pointer to key data
196  * @keylen: Key length in bytes
197  * Returns: 0 on success or < 0 on error.
198  */
199 static int wpa_eapol_set_wep_key(void *ctx, int unicast, int keyidx,
200                                  const u8 *key, size_t keylen)
201 {
202         struct wpa_supplicant *wpa_s = ctx;
203         if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
204                 int cipher = (keylen == 5) ? WPA_CIPHER_WEP40 :
205                         WPA_CIPHER_WEP104;
206                 if (unicast)
207                         wpa_s->pairwise_cipher = cipher;
208                 else
209                         wpa_s->group_cipher = cipher;
210         }
211         return wpa_drv_set_key(wpa_s, WPA_ALG_WEP,
212                                unicast ? wpa_s->bssid :
213                                (u8 *) "\xff\xff\xff\xff\xff\xff",
214                                keyidx, unicast, (u8 *) "", 0, key, keylen);
215 }
216
217
218 static void wpa_supplicant_aborted_cached(void *ctx)
219 {
220         struct wpa_supplicant *wpa_s = ctx;
221         wpa_sm_aborted_cached(wpa_s->wpa);
222 }
223
224
225 static void wpa_supplicant_eapol_cb(struct eapol_sm *eapol, int success,
226                                     void *ctx)
227 {
228         struct wpa_supplicant *wpa_s = ctx;
229         int res, pmk_len;
230         u8 pmk[PMK_LEN];
231
232         wpa_printf(MSG_DEBUG, "EAPOL authentication completed %ssuccessfully",
233                    success ? "" : "un");
234
235         if (wpas_wps_eapol_cb(wpa_s) > 0)
236                 return;
237
238         if (!success) {
239                 /*
240                  * Make sure we do not get stuck here waiting for long EAPOL
241                  * timeout if the AP does not disconnect in case of
242                  * authentication failure.
243                  */
244                 wpa_supplicant_req_auth_timeout(wpa_s, 2, 0);
245         }
246
247         if (!success || !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE))
248                 return;
249
250         if (!wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt))
251                 return;
252
253         wpa_printf(MSG_DEBUG, "Configure PMK for driver-based RSN 4-way "
254                    "handshake");
255
256         pmk_len = PMK_LEN;
257         res = eapol_sm_get_key(eapol, pmk, PMK_LEN);
258         if (res) {
259                 /*
260                  * EAP-LEAP is an exception from other EAP methods: it
261                  * uses only 16-byte PMK.
262                  */
263                 res = eapol_sm_get_key(eapol, pmk, 16);
264                 pmk_len = 16;
265         }
266
267         if (res) {
268                 wpa_printf(MSG_DEBUG, "Failed to get PMK from EAPOL state "
269                            "machines");
270                 return;
271         }
272
273         if (wpa_drv_set_key(wpa_s, WPA_ALG_PMK, NULL, 0, 0, NULL, 0, pmk,
274                             pmk_len)) {
275                 wpa_printf(MSG_DEBUG, "Failed to set PMK to the driver");
276         }
277
278         wpa_supplicant_cancel_scan(wpa_s);
279         wpa_supplicant_cancel_auth_timeout(wpa_s);
280         wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
281
282 }
283
284
285 static void wpa_supplicant_notify_eapol_done(void *ctx)
286 {
287         struct wpa_supplicant *wpa_s = ctx;
288         wpa_msg(wpa_s, MSG_DEBUG, "WPA: EAPOL processing complete");
289         if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
290                 wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE);
291         } else {
292                 wpa_supplicant_cancel_auth_timeout(wpa_s);
293                 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
294         }
295 }
296
297 #endif /* IEEE8021X_EAPOL */
298
299
300 #ifndef CONFIG_NO_WPA
301
302 static int wpa_get_beacon_ie(struct wpa_supplicant *wpa_s)
303 {
304         int ret = 0;
305         struct wpa_bss *curr = NULL, *bss;
306         struct wpa_ssid *ssid = wpa_s->current_ssid;
307         const u8 *ie;
308
309         dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
310                 if (os_memcmp(bss->bssid, wpa_s->bssid, ETH_ALEN) != 0)
311                         continue;
312                 if (ssid == NULL ||
313                     ((bss->ssid_len == ssid->ssid_len &&
314                       os_memcmp(bss->ssid, ssid->ssid, ssid->ssid_len) == 0) ||
315                      ssid->ssid_len == 0)) {
316                         curr = bss;
317                         break;
318                 }
319         }
320
321         if (curr) {
322                 ie = wpa_bss_get_vendor_ie(curr, WPA_IE_VENDOR_TYPE);
323                 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0))
324                         ret = -1;
325
326                 ie = wpa_bss_get_ie(curr, WLAN_EID_RSN);
327                 if (wpa_sm_set_ap_rsn_ie(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0))
328                         ret = -1;
329         } else {
330                 ret = -1;
331         }
332
333         return ret;
334 }
335
336
337 static int wpa_supplicant_get_beacon_ie(void *ctx)
338 {
339         struct wpa_supplicant *wpa_s = ctx;
340         if (wpa_get_beacon_ie(wpa_s) == 0) {
341                 return 0;
342         }
343
344         /* No WPA/RSN IE found in the cached scan results. Try to get updated
345          * scan results from the driver. */
346         if (wpa_supplicant_update_scan_results(wpa_s) < 0)
347                 return -1;
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, enum 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 enum wpa_states wpa_supplicant_get_state(struct wpa_supplicant *wpa_s)
386 {
387         return wpa_s->wpa_state;
388 }
389
390
391 static enum 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, 5, 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, 5, 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->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_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, enum 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->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
474                 return ieee80211_sta_update_ft_ies(wpa_s, md, ies, ies_len);
475         if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
476                 return sme_update_ft_ies(wpa_s, md, ies, ies_len);
477         return wpa_drv_update_ft_ies(wpa_s, md, ies, ies_len);
478 }
479
480
481 static int wpa_supplicant_send_ft_action(void *ctx, u8 action,
482                                          const u8 *target_ap,
483                                          const u8 *ies, size_t ies_len)
484 {
485         struct wpa_supplicant *wpa_s = ctx;
486         if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
487                 return ieee80211_sta_send_ft_action(wpa_s, action, target_ap,
488                                                     ies, ies_len);
489         return wpa_drv_send_ft_action(wpa_s, action, target_ap, ies, ies_len);
490 }
491 #endif /* CONFIG_IEEE80211R */
492
493 #endif /* CONFIG_NO_WPA */
494
495
496 #ifdef IEEE8021X_EAPOL
497 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
498 static void wpa_supplicant_eap_param_needed(void *ctx, const char *field,
499                                             const char *txt)
500 {
501         struct wpa_supplicant *wpa_s = ctx;
502         struct wpa_ssid *ssid = wpa_s->current_ssid;
503         char *buf;
504         size_t buflen;
505         int len;
506
507         if (ssid == NULL)
508                 return;
509
510         buflen = 100 + os_strlen(txt) + ssid->ssid_len;
511         buf = os_malloc(buflen);
512         if (buf == NULL)
513                 return;
514         len = os_snprintf(buf, buflen,
515                           WPA_CTRL_REQ "%s-%d:%s needed for SSID ",
516                           field, ssid->id, txt);
517         if (len < 0 || (size_t) len >= buflen) {
518                 os_free(buf);
519                 return;
520         }
521         if (ssid->ssid && buflen > len + ssid->ssid_len) {
522                 os_memcpy(buf + len, ssid->ssid, ssid->ssid_len);
523                 len += ssid->ssid_len;
524                 buf[len] = '\0';
525         }
526         buf[buflen - 1] = '\0';
527         wpa_msg(wpa_s, MSG_INFO, "%s", buf);
528         os_free(buf);
529 }
530 #else /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
531 #define wpa_supplicant_eap_param_needed NULL
532 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
533
534
535 static void wpa_supplicant_port_cb(void *ctx, int authorized)
536 {
537         struct wpa_supplicant *wpa_s = ctx;
538         wpa_printf(MSG_DEBUG, "EAPOL: Supplicant port status: %s",
539                    authorized ? "Authorized" : "Unauthorized");
540         wpa_drv_set_supp_port(wpa_s, authorized);
541 }
542 #endif /* IEEE8021X_EAPOL */
543
544
545 int wpa_supplicant_init_eapol(struct wpa_supplicant *wpa_s)
546 {
547 #ifdef IEEE8021X_EAPOL
548         struct eapol_ctx *ctx;
549         ctx = os_zalloc(sizeof(*ctx));
550         if (ctx == NULL) {
551                 wpa_printf(MSG_ERROR, "Failed to allocate EAPOL context.");
552                 return -1;
553         }
554
555         ctx->ctx = wpa_s;
556         ctx->msg_ctx = wpa_s;
557         ctx->eapol_send_ctx = wpa_s;
558         ctx->preauth = 0;
559         ctx->eapol_done_cb = wpa_supplicant_notify_eapol_done;
560         ctx->eapol_send = wpa_supplicant_eapol_send;
561         ctx->set_wep_key = wpa_eapol_set_wep_key;
562         ctx->set_config_blob = wpa_supplicant_set_config_blob;
563         ctx->get_config_blob = wpa_supplicant_get_config_blob;
564         ctx->aborted_cached = wpa_supplicant_aborted_cached;
565         ctx->opensc_engine_path = wpa_s->conf->opensc_engine_path;
566         ctx->pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path;
567         ctx->pkcs11_module_path = wpa_s->conf->pkcs11_module_path;
568         ctx->wps = wpa_s->wps;
569         ctx->eap_param_needed = wpa_supplicant_eap_param_needed;
570         ctx->port_cb = wpa_supplicant_port_cb;
571         ctx->cb = wpa_supplicant_eapol_cb;
572         ctx->cb_ctx = wpa_s;
573         wpa_s->eapol = eapol_sm_init(ctx);
574         if (wpa_s->eapol == NULL) {
575                 os_free(ctx);
576                 wpa_printf(MSG_ERROR, "Failed to initialize EAPOL state "
577                            "machines.");
578                 return -1;
579         }
580 #endif /* IEEE8021X_EAPOL */
581
582         return 0;
583 }
584
585
586 int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s)
587 {
588 #ifndef CONFIG_NO_WPA
589         struct wpa_sm_ctx *ctx;
590         ctx = os_zalloc(sizeof(*ctx));
591         if (ctx == NULL) {
592                 wpa_printf(MSG_ERROR, "Failed to allocate WPA context.");
593                 return -1;
594         }
595
596         ctx->ctx = wpa_s;
597         ctx->msg_ctx = wpa_s;
598         ctx->set_state = _wpa_supplicant_set_state;
599         ctx->get_state = _wpa_supplicant_get_state;
600         ctx->deauthenticate = _wpa_supplicant_deauthenticate;
601         ctx->disassociate = _wpa_supplicant_disassociate;
602         ctx->set_key = wpa_supplicant_set_key;
603         ctx->get_network_ctx = wpa_supplicant_get_network_ctx;
604         ctx->get_bssid = wpa_supplicant_get_bssid;
605         ctx->ether_send = _wpa_ether_send;
606         ctx->get_beacon_ie = wpa_supplicant_get_beacon_ie;
607         ctx->alloc_eapol = _wpa_alloc_eapol;
608         ctx->cancel_auth_timeout = _wpa_supplicant_cancel_auth_timeout;
609         ctx->add_pmkid = wpa_supplicant_add_pmkid;
610         ctx->remove_pmkid = wpa_supplicant_remove_pmkid;
611 #ifndef CONFIG_NO_CONFIG_BLOBS
612         ctx->set_config_blob = wpa_supplicant_set_config_blob;
613         ctx->get_config_blob = wpa_supplicant_get_config_blob;
614 #endif /* CONFIG_NO_CONFIG_BLOBS */
615         ctx->mlme_setprotection = wpa_supplicant_mlme_setprotection;
616 #ifdef CONFIG_IEEE80211R
617         ctx->update_ft_ies = wpa_supplicant_update_ft_ies;
618         ctx->send_ft_action = wpa_supplicant_send_ft_action;
619 #endif /* CONFIG_IEEE80211R */
620
621         wpa_s->wpa = wpa_sm_init(ctx);
622         if (wpa_s->wpa == NULL) {
623                 wpa_printf(MSG_ERROR, "Failed to initialize WPA state "
624                            "machine");
625                 return -1;
626         }
627 #endif /* CONFIG_NO_WPA */
628
629         return 0;
630 }
631
632
633 void wpa_supplicant_rsn_supp_set_config(struct wpa_supplicant *wpa_s,
634                                         struct wpa_ssid *ssid)
635 {
636         struct rsn_supp_config conf;
637         if (ssid) {
638                 os_memset(&conf, 0, sizeof(conf));
639                 conf.network_ctx = ssid;
640                 conf.peerkey_enabled = ssid->peerkey;
641                 conf.allowed_pairwise_cipher = ssid->pairwise_cipher;
642 #ifdef IEEE8021X_EAPOL
643                 conf.eap_workaround = ssid->eap_workaround;
644                 conf.eap_conf_ctx = &ssid->eap;
645 #endif /* IEEE8021X_EAPOL */
646                 conf.ssid = ssid->ssid;
647                 conf.ssid_len = ssid->ssid_len;
648                 conf.wpa_ptk_rekey = ssid->wpa_ptk_rekey;
649         }
650         wpa_sm_set_config(wpa_s->wpa, ssid ? &conf : NULL);
651 }