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