wpas_glue.c 16 KB

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