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