wpas_glue.c 17 KB

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