wpas_glue.c 17 KB

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