wpas_glue.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237
  1. /*
  2. * WPA Supplicant - Glue code to setup EAPOL and RSN modules
  3. * Copyright (c) 2003-2015, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "includes.h"
  9. #include "common.h"
  10. #include "eapol_supp/eapol_supp_sm.h"
  11. #include "eap_peer/eap.h"
  12. #include "rsn_supp/wpa.h"
  13. #include "eloop.h"
  14. #include "config.h"
  15. #include "l2_packet/l2_packet.h"
  16. #include "common/wpa_common.h"
  17. #include "wpa_supplicant_i.h"
  18. #include "driver_i.h"
  19. #include "rsn_supp/pmksa_cache.h"
  20. #include "sme.h"
  21. #include "common/ieee802_11_defs.h"
  22. #include "common/wpa_ctrl.h"
  23. #include "wpas_glue.h"
  24. #include "wps_supplicant.h"
  25. #include "bss.h"
  26. #include "scan.h"
  27. #include "notify.h"
  28. #include "wpas_kay.h"
  29. #ifndef CONFIG_NO_CONFIG_BLOBS
  30. #if defined(IEEE8021X_EAPOL) || !defined(CONFIG_NO_WPA)
  31. static void wpa_supplicant_set_config_blob(void *ctx,
  32. struct wpa_config_blob *blob)
  33. {
  34. struct wpa_supplicant *wpa_s = ctx;
  35. wpa_config_set_blob(wpa_s->conf, blob);
  36. if (wpa_s->conf->update_config) {
  37. int ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
  38. if (ret) {
  39. wpa_printf(MSG_DEBUG, "Failed to update config after "
  40. "blob set");
  41. }
  42. }
  43. }
  44. static const struct wpa_config_blob *
  45. wpa_supplicant_get_config_blob(void *ctx, const char *name)
  46. {
  47. struct wpa_supplicant *wpa_s = ctx;
  48. return wpa_config_get_blob(wpa_s->conf, name);
  49. }
  50. #endif /* defined(IEEE8021X_EAPOL) || !defined(CONFIG_NO_WPA) */
  51. #endif /* CONFIG_NO_CONFIG_BLOBS */
  52. #if defined(IEEE8021X_EAPOL) || !defined(CONFIG_NO_WPA)
  53. static u8 * wpa_alloc_eapol(const struct wpa_supplicant *wpa_s, u8 type,
  54. const void *data, u16 data_len,
  55. size_t *msg_len, void **data_pos)
  56. {
  57. struct ieee802_1x_hdr *hdr;
  58. *msg_len = sizeof(*hdr) + data_len;
  59. hdr = os_malloc(*msg_len);
  60. if (hdr == NULL)
  61. return NULL;
  62. hdr->version = wpa_s->conf->eapol_version;
  63. hdr->type = type;
  64. hdr->length = host_to_be16(data_len);
  65. if (data)
  66. os_memcpy(hdr + 1, data, data_len);
  67. else
  68. os_memset(hdr + 1, 0, data_len);
  69. if (data_pos)
  70. *data_pos = hdr + 1;
  71. return (u8 *) hdr;
  72. }
  73. /**
  74. * wpa_ether_send - Send Ethernet frame
  75. * @wpa_s: Pointer to wpa_supplicant data
  76. * @dest: Destination MAC address
  77. * @proto: Ethertype in host byte order
  78. * @buf: Frame payload starting from IEEE 802.1X header
  79. * @len: Frame payload length
  80. * Returns: >=0 on success, <0 on failure
  81. */
  82. static int wpa_ether_send(struct wpa_supplicant *wpa_s, const u8 *dest,
  83. u16 proto, const u8 *buf, size_t len)
  84. {
  85. #ifdef CONFIG_TESTING_OPTIONS
  86. if (wpa_s->ext_eapol_frame_io && proto == ETH_P_EAPOL) {
  87. size_t hex_len = 2 * len + 1;
  88. char *hex = os_malloc(hex_len);
  89. if (hex == NULL)
  90. return -1;
  91. wpa_snprintf_hex(hex, hex_len, buf, len);
  92. wpa_msg(wpa_s, MSG_INFO, "EAPOL-TX " MACSTR " %s",
  93. MAC2STR(dest), hex);
  94. os_free(hex);
  95. return 0;
  96. }
  97. #endif /* CONFIG_TESTING_OPTIONS */
  98. if (wpa_s->l2) {
  99. return l2_packet_send(wpa_s->l2, dest, proto, buf, len);
  100. }
  101. return -1;
  102. }
  103. #endif /* IEEE8021X_EAPOL || !CONFIG_NO_WPA */
  104. #ifdef IEEE8021X_EAPOL
  105. /**
  106. * wpa_supplicant_eapol_send - Send IEEE 802.1X EAPOL packet to Authenticator
  107. * @ctx: Pointer to wpa_supplicant data (wpa_s)
  108. * @type: IEEE 802.1X packet type (IEEE802_1X_TYPE_*)
  109. * @buf: EAPOL payload (after IEEE 802.1X header)
  110. * @len: EAPOL payload length
  111. * Returns: >=0 on success, <0 on failure
  112. *
  113. * This function adds Ethernet and IEEE 802.1X header and sends the EAPOL frame
  114. * to the current Authenticator.
  115. */
  116. static int wpa_supplicant_eapol_send(void *ctx, int type, const u8 *buf,
  117. size_t len)
  118. {
  119. struct wpa_supplicant *wpa_s = ctx;
  120. u8 *msg, *dst, bssid[ETH_ALEN];
  121. size_t msglen;
  122. int res;
  123. /* TODO: could add l2_packet_sendmsg that allows fragments to avoid
  124. * extra copy here */
  125. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
  126. wpa_s->key_mgmt == WPA_KEY_MGMT_NONE) {
  127. /* Current SSID is not using IEEE 802.1X/EAP, so drop possible
  128. * EAPOL frames (mainly, EAPOL-Start) from EAPOL state
  129. * machines. */
  130. wpa_printf(MSG_DEBUG, "WPA: drop TX EAPOL in non-IEEE 802.1X "
  131. "mode (type=%d len=%lu)", type,
  132. (unsigned long) len);
  133. return -1;
  134. }
  135. if (pmksa_cache_get_current(wpa_s->wpa) &&
  136. type == IEEE802_1X_TYPE_EAPOL_START) {
  137. /*
  138. * We were trying to use PMKSA caching and sending EAPOL-Start
  139. * would abort that and trigger full EAPOL authentication.
  140. * However, we've already waited for the AP/Authenticator to
  141. * start 4-way handshake or EAP authentication, and apparently
  142. * it has not done so since the startWhen timer has reached zero
  143. * to get the state machine sending EAPOL-Start. This is not
  144. * really supposed to happen, but an interoperability issue with
  145. * a deployed AP has been identified where the connection fails
  146. * due to that AP failing to operate correctly if PMKID is
  147. * included in the Association Request frame. To work around
  148. * this, assume PMKSA caching failed and try to initiate full
  149. * EAP authentication.
  150. */
  151. if (!wpa_s->current_ssid ||
  152. wpa_s->current_ssid->eap_workaround) {
  153. wpa_printf(MSG_DEBUG,
  154. "RSN: Timeout on waiting for the AP to initiate 4-way handshake for PMKSA caching or EAP authentication - try to force it to start EAP authentication");
  155. } else {
  156. wpa_printf(MSG_DEBUG,
  157. "RSN: PMKSA caching - do not send EAPOL-Start");
  158. return -1;
  159. }
  160. }
  161. if (is_zero_ether_addr(wpa_s->bssid)) {
  162. wpa_printf(MSG_DEBUG, "BSSID not set when trying to send an "
  163. "EAPOL frame");
  164. if (wpa_drv_get_bssid(wpa_s, bssid) == 0 &&
  165. !is_zero_ether_addr(bssid)) {
  166. dst = bssid;
  167. wpa_printf(MSG_DEBUG, "Using current BSSID " MACSTR
  168. " from the driver as the EAPOL destination",
  169. MAC2STR(dst));
  170. } else {
  171. dst = wpa_s->last_eapol_src;
  172. wpa_printf(MSG_DEBUG, "Using the source address of the"
  173. " last received EAPOL frame " MACSTR " as "
  174. "the EAPOL destination",
  175. MAC2STR(dst));
  176. }
  177. } else {
  178. /* BSSID was already set (from (Re)Assoc event, so use it as
  179. * the EAPOL destination. */
  180. dst = wpa_s->bssid;
  181. }
  182. msg = wpa_alloc_eapol(wpa_s, type, buf, len, &msglen, NULL);
  183. if (msg == NULL)
  184. return -1;
  185. wpa_printf(MSG_DEBUG, "TX EAPOL: dst=" MACSTR, MAC2STR(dst));
  186. wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", msg, msglen);
  187. res = wpa_ether_send(wpa_s, dst, ETH_P_EAPOL, msg, msglen);
  188. os_free(msg);
  189. return res;
  190. }
  191. /**
  192. * wpa_eapol_set_wep_key - set WEP key for the driver
  193. * @ctx: Pointer to wpa_supplicant data (wpa_s)
  194. * @unicast: 1 = individual unicast key, 0 = broadcast key
  195. * @keyidx: WEP key index (0..3)
  196. * @key: Pointer to key data
  197. * @keylen: Key length in bytes
  198. * Returns: 0 on success or < 0 on error.
  199. */
  200. static int wpa_eapol_set_wep_key(void *ctx, int unicast, int keyidx,
  201. const u8 *key, size_t keylen)
  202. {
  203. struct wpa_supplicant *wpa_s = ctx;
  204. if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
  205. int cipher = (keylen == 5) ? WPA_CIPHER_WEP40 :
  206. WPA_CIPHER_WEP104;
  207. if (unicast)
  208. wpa_s->pairwise_cipher = cipher;
  209. else
  210. wpa_s->group_cipher = cipher;
  211. }
  212. return wpa_drv_set_key(wpa_s, WPA_ALG_WEP,
  213. unicast ? wpa_s->bssid : NULL,
  214. keyidx, unicast, NULL, 0, key, keylen);
  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. static const char * result_str(enum eapol_supp_result result)
  222. {
  223. switch (result) {
  224. case EAPOL_SUPP_RESULT_FAILURE:
  225. return "FAILURE";
  226. case EAPOL_SUPP_RESULT_SUCCESS:
  227. return "SUCCESS";
  228. case EAPOL_SUPP_RESULT_EXPECTED_FAILURE:
  229. return "EXPECTED_FAILURE";
  230. }
  231. return "?";
  232. }
  233. static void wpa_supplicant_eapol_cb(struct eapol_sm *eapol,
  234. enum eapol_supp_result result,
  235. void *ctx)
  236. {
  237. struct wpa_supplicant *wpa_s = ctx;
  238. int res, pmk_len;
  239. u8 pmk[PMK_LEN];
  240. wpa_printf(MSG_DEBUG, "EAPOL authentication completed - result=%s",
  241. result_str(result));
  242. if (wpas_wps_eapol_cb(wpa_s) > 0)
  243. return;
  244. wpa_s->eap_expected_failure = result ==
  245. EAPOL_SUPP_RESULT_EXPECTED_FAILURE;
  246. if (result != EAPOL_SUPP_RESULT_SUCCESS) {
  247. /*
  248. * Make sure we do not get stuck here waiting for long EAPOL
  249. * timeout if the AP does not disconnect in case of
  250. * authentication failure.
  251. */
  252. wpa_supplicant_req_auth_timeout(wpa_s, 2, 0);
  253. } else {
  254. ieee802_1x_notify_create_actor(wpa_s, wpa_s->last_eapol_src);
  255. }
  256. if (result != EAPOL_SUPP_RESULT_SUCCESS ||
  257. !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE))
  258. return;
  259. if (!wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt))
  260. return;
  261. wpa_printf(MSG_DEBUG, "Configure PMK for driver-based RSN 4-way "
  262. "handshake");
  263. pmk_len = PMK_LEN;
  264. if (wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
  265. #ifdef CONFIG_IEEE80211R
  266. u8 buf[2 * PMK_LEN];
  267. wpa_printf(MSG_DEBUG, "RSN: Use FT XXKey as PMK for "
  268. "driver-based 4-way hs and FT");
  269. res = eapol_sm_get_key(eapol, buf, 2 * PMK_LEN);
  270. if (res == 0) {
  271. os_memcpy(pmk, buf + PMK_LEN, PMK_LEN);
  272. os_memset(buf, 0, sizeof(buf));
  273. }
  274. #else /* CONFIG_IEEE80211R */
  275. res = -1;
  276. #endif /* CONFIG_IEEE80211R */
  277. } else {
  278. res = eapol_sm_get_key(eapol, pmk, PMK_LEN);
  279. if (res) {
  280. /*
  281. * EAP-LEAP is an exception from other EAP methods: it
  282. * uses only 16-byte PMK.
  283. */
  284. res = eapol_sm_get_key(eapol, pmk, 16);
  285. pmk_len = 16;
  286. }
  287. }
  288. if (res) {
  289. wpa_printf(MSG_DEBUG, "Failed to get PMK from EAPOL state "
  290. "machines");
  291. return;
  292. }
  293. wpa_hexdump_key(MSG_DEBUG, "RSN: Configure PMK for driver-based 4-way "
  294. "handshake", pmk, pmk_len);
  295. if (wpa_drv_set_key(wpa_s, WPA_ALG_PMK, NULL, 0, 0, NULL, 0, pmk,
  296. pmk_len)) {
  297. wpa_printf(MSG_DEBUG, "Failed to set PMK to the driver");
  298. }
  299. wpa_supplicant_cancel_scan(wpa_s);
  300. wpa_supplicant_cancel_auth_timeout(wpa_s);
  301. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  302. }
  303. static void wpa_supplicant_notify_eapol_done(void *ctx)
  304. {
  305. struct wpa_supplicant *wpa_s = ctx;
  306. wpa_msg(wpa_s, MSG_DEBUG, "WPA: EAPOL processing complete");
  307. if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
  308. wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE);
  309. } else {
  310. wpa_supplicant_cancel_auth_timeout(wpa_s);
  311. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  312. }
  313. }
  314. #endif /* IEEE8021X_EAPOL */
  315. #ifndef CONFIG_NO_WPA
  316. static int wpa_get_beacon_ie(struct wpa_supplicant *wpa_s)
  317. {
  318. int ret = 0;
  319. struct wpa_bss *curr = NULL, *bss;
  320. struct wpa_ssid *ssid = wpa_s->current_ssid;
  321. const u8 *ie;
  322. dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
  323. if (os_memcmp(bss->bssid, wpa_s->bssid, ETH_ALEN) != 0)
  324. continue;
  325. if (ssid == NULL ||
  326. ((bss->ssid_len == ssid->ssid_len &&
  327. os_memcmp(bss->ssid, ssid->ssid, ssid->ssid_len) == 0) ||
  328. ssid->ssid_len == 0)) {
  329. curr = bss;
  330. break;
  331. }
  332. }
  333. if (curr) {
  334. ie = wpa_bss_get_vendor_ie(curr, WPA_IE_VENDOR_TYPE);
  335. if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0))
  336. ret = -1;
  337. ie = wpa_bss_get_ie(curr, WLAN_EID_RSN);
  338. if (wpa_sm_set_ap_rsn_ie(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0))
  339. ret = -1;
  340. } else {
  341. ret = -1;
  342. }
  343. return ret;
  344. }
  345. static int wpa_supplicant_get_beacon_ie(void *ctx)
  346. {
  347. struct wpa_supplicant *wpa_s = ctx;
  348. if (wpa_get_beacon_ie(wpa_s) == 0) {
  349. return 0;
  350. }
  351. /* No WPA/RSN IE found in the cached scan results. Try to get updated
  352. * scan results from the driver. */
  353. if (wpa_supplicant_update_scan_results(wpa_s) < 0)
  354. return -1;
  355. return wpa_get_beacon_ie(wpa_s);
  356. }
  357. static u8 * _wpa_alloc_eapol(void *wpa_s, u8 type,
  358. const void *data, u16 data_len,
  359. size_t *msg_len, void **data_pos)
  360. {
  361. return wpa_alloc_eapol(wpa_s, type, data, data_len, msg_len, data_pos);
  362. }
  363. static int _wpa_ether_send(void *wpa_s, const u8 *dest, u16 proto,
  364. const u8 *buf, size_t len)
  365. {
  366. return wpa_ether_send(wpa_s, dest, proto, buf, len);
  367. }
  368. static void _wpa_supplicant_cancel_auth_timeout(void *wpa_s)
  369. {
  370. wpa_supplicant_cancel_auth_timeout(wpa_s);
  371. }
  372. static void _wpa_supplicant_set_state(void *wpa_s, enum wpa_states state)
  373. {
  374. wpa_supplicant_set_state(wpa_s, state);
  375. }
  376. /**
  377. * wpa_supplicant_get_state - Get the connection state
  378. * @wpa_s: Pointer to wpa_supplicant data
  379. * Returns: The current connection state (WPA_*)
  380. */
  381. static enum wpa_states wpa_supplicant_get_state(struct wpa_supplicant *wpa_s)
  382. {
  383. return wpa_s->wpa_state;
  384. }
  385. static enum wpa_states _wpa_supplicant_get_state(void *wpa_s)
  386. {
  387. return wpa_supplicant_get_state(wpa_s);
  388. }
  389. static void _wpa_supplicant_deauthenticate(void *wpa_s, int reason_code)
  390. {
  391. wpa_supplicant_deauthenticate(wpa_s, reason_code);
  392. /* Schedule a scan to make sure we continue looking for networks */
  393. wpa_supplicant_req_scan(wpa_s, 5, 0);
  394. }
  395. static void * wpa_supplicant_get_network_ctx(void *wpa_s)
  396. {
  397. return wpa_supplicant_get_ssid(wpa_s);
  398. }
  399. static int wpa_supplicant_get_bssid(void *ctx, u8 *bssid)
  400. {
  401. struct wpa_supplicant *wpa_s = ctx;
  402. return wpa_drv_get_bssid(wpa_s, bssid);
  403. }
  404. static int wpa_supplicant_set_key(void *_wpa_s, enum wpa_alg alg,
  405. const u8 *addr, int key_idx, int set_tx,
  406. const u8 *seq, size_t seq_len,
  407. const u8 *key, size_t key_len)
  408. {
  409. struct wpa_supplicant *wpa_s = _wpa_s;
  410. if (alg == WPA_ALG_TKIP && key_idx == 0 && key_len == 32) {
  411. /* Clear the MIC error counter when setting a new PTK. */
  412. wpa_s->mic_errors_seen = 0;
  413. }
  414. #ifdef CONFIG_TESTING_GET_GTK
  415. if (key_idx > 0 && addr && is_broadcast_ether_addr(addr) &&
  416. alg != WPA_ALG_NONE && key_len <= sizeof(wpa_s->last_gtk)) {
  417. os_memcpy(wpa_s->last_gtk, key, key_len);
  418. wpa_s->last_gtk_len = key_len;
  419. }
  420. #endif /* CONFIG_TESTING_GET_GTK */
  421. return wpa_drv_set_key(wpa_s, alg, addr, key_idx, set_tx, seq, seq_len,
  422. key, key_len);
  423. }
  424. static int wpa_supplicant_mlme_setprotection(void *wpa_s, const u8 *addr,
  425. int protection_type,
  426. int key_type)
  427. {
  428. return wpa_drv_mlme_setprotection(wpa_s, addr, protection_type,
  429. key_type);
  430. }
  431. static struct wpa_ssid * wpas_get_network_ctx(struct wpa_supplicant *wpa_s,
  432. void *network_ctx)
  433. {
  434. struct wpa_ssid *ssid;
  435. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  436. if (network_ctx == ssid)
  437. return ssid;
  438. }
  439. return NULL;
  440. }
  441. static int wpa_supplicant_add_pmkid(void *_wpa_s, void *network_ctx,
  442. const u8 *bssid, const u8 *pmkid)
  443. {
  444. struct wpa_supplicant *wpa_s = _wpa_s;
  445. struct wpa_ssid *ssid;
  446. ssid = wpas_get_network_ctx(wpa_s, network_ctx);
  447. if (ssid)
  448. wpa_msg(wpa_s, MSG_INFO, PMKSA_CACHE_ADDED MACSTR " %d",
  449. MAC2STR(bssid), ssid->id);
  450. return wpa_drv_add_pmkid(wpa_s, bssid, pmkid);
  451. }
  452. static int wpa_supplicant_remove_pmkid(void *_wpa_s, void *network_ctx,
  453. const u8 *bssid, const u8 *pmkid)
  454. {
  455. struct wpa_supplicant *wpa_s = _wpa_s;
  456. struct wpa_ssid *ssid;
  457. ssid = wpas_get_network_ctx(wpa_s, network_ctx);
  458. if (ssid)
  459. wpa_msg(wpa_s, MSG_INFO, PMKSA_CACHE_REMOVED MACSTR " %d",
  460. MAC2STR(bssid), ssid->id);
  461. return wpa_drv_remove_pmkid(wpa_s, bssid, pmkid);
  462. }
  463. #ifdef CONFIG_IEEE80211R
  464. static int wpa_supplicant_update_ft_ies(void *ctx, const u8 *md,
  465. const u8 *ies, size_t ies_len)
  466. {
  467. struct wpa_supplicant *wpa_s = ctx;
  468. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  469. return sme_update_ft_ies(wpa_s, md, ies, ies_len);
  470. return wpa_drv_update_ft_ies(wpa_s, md, ies, ies_len);
  471. }
  472. static int wpa_supplicant_send_ft_action(void *ctx, u8 action,
  473. const u8 *target_ap,
  474. const u8 *ies, size_t ies_len)
  475. {
  476. struct wpa_supplicant *wpa_s = ctx;
  477. int ret;
  478. u8 *data, *pos;
  479. size_t data_len;
  480. if (action != 1) {
  481. wpa_printf(MSG_ERROR, "Unsupported send_ft_action action %d",
  482. action);
  483. return -1;
  484. }
  485. /*
  486. * Action frame payload:
  487. * Category[1] = 6 (Fast BSS Transition)
  488. * Action[1] = 1 (Fast BSS Transition Request)
  489. * STA Address
  490. * Target AP Address
  491. * FT IEs
  492. */
  493. data_len = 2 + 2 * ETH_ALEN + ies_len;
  494. data = os_malloc(data_len);
  495. if (data == NULL)
  496. return -1;
  497. pos = data;
  498. *pos++ = 0x06; /* FT Action category */
  499. *pos++ = action;
  500. os_memcpy(pos, wpa_s->own_addr, ETH_ALEN);
  501. pos += ETH_ALEN;
  502. os_memcpy(pos, target_ap, ETH_ALEN);
  503. pos += ETH_ALEN;
  504. os_memcpy(pos, ies, ies_len);
  505. ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0,
  506. wpa_s->bssid, wpa_s->own_addr, wpa_s->bssid,
  507. data, data_len, 0);
  508. os_free(data);
  509. return ret;
  510. }
  511. static int wpa_supplicant_mark_authenticated(void *ctx, const u8 *target_ap)
  512. {
  513. struct wpa_supplicant *wpa_s = ctx;
  514. struct wpa_driver_auth_params params;
  515. struct wpa_bss *bss;
  516. bss = wpa_bss_get_bssid(wpa_s, target_ap);
  517. if (bss == NULL)
  518. return -1;
  519. os_memset(&params, 0, sizeof(params));
  520. params.bssid = target_ap;
  521. params.freq = bss->freq;
  522. params.ssid = bss->ssid;
  523. params.ssid_len = bss->ssid_len;
  524. params.auth_alg = WPA_AUTH_ALG_FT;
  525. params.local_state_change = 1;
  526. return wpa_drv_authenticate(wpa_s, &params);
  527. }
  528. #endif /* CONFIG_IEEE80211R */
  529. #ifdef CONFIG_TDLS
  530. static int wpa_supplicant_tdls_get_capa(void *ctx, int *tdls_supported,
  531. int *tdls_ext_setup,
  532. int *tdls_chan_switch)
  533. {
  534. struct wpa_supplicant *wpa_s = ctx;
  535. *tdls_supported = 0;
  536. *tdls_ext_setup = 0;
  537. *tdls_chan_switch = 0;
  538. if (!wpa_s->drv_capa_known)
  539. return -1;
  540. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)
  541. *tdls_supported = 1;
  542. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP)
  543. *tdls_ext_setup = 1;
  544. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)
  545. *tdls_chan_switch = 1;
  546. return 0;
  547. }
  548. static int wpa_supplicant_send_tdls_mgmt(void *ctx, const u8 *dst,
  549. u8 action_code, u8 dialog_token,
  550. u16 status_code, u32 peer_capab,
  551. int initiator, const u8 *buf,
  552. size_t len)
  553. {
  554. struct wpa_supplicant *wpa_s = ctx;
  555. return wpa_drv_send_tdls_mgmt(wpa_s, dst, action_code, dialog_token,
  556. status_code, peer_capab, initiator, buf,
  557. len);
  558. }
  559. static int wpa_supplicant_tdls_oper(void *ctx, int oper, const u8 *peer)
  560. {
  561. struct wpa_supplicant *wpa_s = ctx;
  562. return wpa_drv_tdls_oper(wpa_s, oper, peer);
  563. }
  564. static int wpa_supplicant_tdls_peer_addset(
  565. void *ctx, const u8 *peer, int add, u16 aid, u16 capability,
  566. const u8 *supp_rates, size_t supp_rates_len,
  567. const struct ieee80211_ht_capabilities *ht_capab,
  568. const struct ieee80211_vht_capabilities *vht_capab,
  569. u8 qosinfo, int wmm, const u8 *ext_capab, size_t ext_capab_len,
  570. const u8 *supp_channels, size_t supp_channels_len,
  571. const u8 *supp_oper_classes, size_t supp_oper_classes_len)
  572. {
  573. struct wpa_supplicant *wpa_s = ctx;
  574. struct hostapd_sta_add_params params;
  575. os_memset(&params, 0, sizeof(params));
  576. params.addr = peer;
  577. params.aid = aid;
  578. params.capability = capability;
  579. params.flags = WPA_STA_TDLS_PEER | WPA_STA_AUTHORIZED;
  580. /*
  581. * Don't rely only on qosinfo for WMM capability. It may be 0 even when
  582. * present. Allow the WMM IE to also indicate QoS support.
  583. */
  584. if (wmm || qosinfo)
  585. params.flags |= WPA_STA_WMM;
  586. params.ht_capabilities = ht_capab;
  587. params.vht_capabilities = vht_capab;
  588. params.qosinfo = qosinfo;
  589. params.listen_interval = 0;
  590. params.supp_rates = supp_rates;
  591. params.supp_rates_len = supp_rates_len;
  592. params.set = !add;
  593. params.ext_capab = ext_capab;
  594. params.ext_capab_len = ext_capab_len;
  595. params.supp_channels = supp_channels;
  596. params.supp_channels_len = supp_channels_len;
  597. params.supp_oper_classes = supp_oper_classes;
  598. params.supp_oper_classes_len = supp_oper_classes_len;
  599. return wpa_drv_sta_add(wpa_s, &params);
  600. }
  601. static int wpa_supplicant_tdls_enable_channel_switch(
  602. void *ctx, const u8 *addr, u8 oper_class,
  603. const struct hostapd_freq_params *params)
  604. {
  605. struct wpa_supplicant *wpa_s = ctx;
  606. return wpa_drv_tdls_enable_channel_switch(wpa_s, addr, oper_class,
  607. params);
  608. }
  609. static int wpa_supplicant_tdls_disable_channel_switch(void *ctx, const u8 *addr)
  610. {
  611. struct wpa_supplicant *wpa_s = ctx;
  612. return wpa_drv_tdls_disable_channel_switch(wpa_s, addr);
  613. }
  614. #endif /* CONFIG_TDLS */
  615. #endif /* CONFIG_NO_WPA */
  616. enum wpa_ctrl_req_type wpa_supplicant_ctrl_req_from_string(const char *field)
  617. {
  618. if (os_strcmp(field, "IDENTITY") == 0)
  619. return WPA_CTRL_REQ_EAP_IDENTITY;
  620. else if (os_strcmp(field, "PASSWORD") == 0)
  621. return WPA_CTRL_REQ_EAP_PASSWORD;
  622. else if (os_strcmp(field, "NEW_PASSWORD") == 0)
  623. return WPA_CTRL_REQ_EAP_NEW_PASSWORD;
  624. else if (os_strcmp(field, "PIN") == 0)
  625. return WPA_CTRL_REQ_EAP_PIN;
  626. else if (os_strcmp(field, "OTP") == 0)
  627. return WPA_CTRL_REQ_EAP_OTP;
  628. else if (os_strcmp(field, "PASSPHRASE") == 0)
  629. return WPA_CTRL_REQ_EAP_PASSPHRASE;
  630. else if (os_strcmp(field, "SIM") == 0)
  631. return WPA_CTRL_REQ_SIM;
  632. else if (os_strcmp(field, "PSK_PASSPHRASE") == 0)
  633. return WPA_CTRL_REQ_PSK_PASSPHRASE;
  634. else if (os_strcmp(field, "EXT_CERT_CHECK") == 0)
  635. return WPA_CTRL_REQ_EXT_CERT_CHECK;
  636. return WPA_CTRL_REQ_UNKNOWN;
  637. }
  638. const char * wpa_supplicant_ctrl_req_to_string(enum wpa_ctrl_req_type field,
  639. const char *default_txt,
  640. const char **txt)
  641. {
  642. const char *ret = NULL;
  643. *txt = default_txt;
  644. switch (field) {
  645. case WPA_CTRL_REQ_EAP_IDENTITY:
  646. *txt = "Identity";
  647. ret = "IDENTITY";
  648. break;
  649. case WPA_CTRL_REQ_EAP_PASSWORD:
  650. *txt = "Password";
  651. ret = "PASSWORD";
  652. break;
  653. case WPA_CTRL_REQ_EAP_NEW_PASSWORD:
  654. *txt = "New Password";
  655. ret = "NEW_PASSWORD";
  656. break;
  657. case WPA_CTRL_REQ_EAP_PIN:
  658. *txt = "PIN";
  659. ret = "PIN";
  660. break;
  661. case WPA_CTRL_REQ_EAP_OTP:
  662. ret = "OTP";
  663. break;
  664. case WPA_CTRL_REQ_EAP_PASSPHRASE:
  665. *txt = "Private key passphrase";
  666. ret = "PASSPHRASE";
  667. break;
  668. case WPA_CTRL_REQ_SIM:
  669. ret = "SIM";
  670. break;
  671. case WPA_CTRL_REQ_PSK_PASSPHRASE:
  672. *txt = "PSK or passphrase";
  673. ret = "PSK_PASSPHRASE";
  674. break;
  675. case WPA_CTRL_REQ_EXT_CERT_CHECK:
  676. *txt = "External server certificate validation";
  677. ret = "EXT_CERT_CHECK";
  678. break;
  679. default:
  680. break;
  681. }
  682. /* txt needs to be something */
  683. if (*txt == NULL) {
  684. wpa_printf(MSG_WARNING, "No message for request %d", field);
  685. ret = NULL;
  686. }
  687. return ret;
  688. }
  689. void wpas_send_ctrl_req(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
  690. const char *field_name, const char *txt)
  691. {
  692. char *buf;
  693. size_t buflen;
  694. int len;
  695. buflen = 100 + os_strlen(txt) + ssid->ssid_len;
  696. buf = os_malloc(buflen);
  697. if (buf == NULL)
  698. return;
  699. len = os_snprintf(buf, buflen, "%s-%d:%s needed for SSID ",
  700. field_name, ssid->id, txt);
  701. if (os_snprintf_error(buflen, len)) {
  702. os_free(buf);
  703. return;
  704. }
  705. if (ssid->ssid && buflen > len + ssid->ssid_len) {
  706. os_memcpy(buf + len, ssid->ssid, ssid->ssid_len);
  707. len += ssid->ssid_len;
  708. buf[len] = '\0';
  709. }
  710. buf[buflen - 1] = '\0';
  711. wpa_msg(wpa_s, MSG_INFO, WPA_CTRL_REQ "%s", buf);
  712. os_free(buf);
  713. }
  714. #ifdef IEEE8021X_EAPOL
  715. #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
  716. static void wpa_supplicant_eap_param_needed(void *ctx,
  717. enum wpa_ctrl_req_type field,
  718. const char *default_txt)
  719. {
  720. struct wpa_supplicant *wpa_s = ctx;
  721. struct wpa_ssid *ssid = wpa_s->current_ssid;
  722. const char *field_name, *txt = NULL;
  723. if (ssid == NULL)
  724. return;
  725. if (field == WPA_CTRL_REQ_EXT_CERT_CHECK)
  726. ssid->eap.pending_ext_cert_check = PENDING_CHECK;
  727. wpas_notify_network_request(wpa_s, ssid, field, default_txt);
  728. field_name = wpa_supplicant_ctrl_req_to_string(field, default_txt,
  729. &txt);
  730. if (field_name == NULL) {
  731. wpa_printf(MSG_WARNING, "Unhandled EAP param %d needed",
  732. field);
  733. return;
  734. }
  735. wpas_notify_eap_status(wpa_s, "eap parameter needed", field_name);
  736. wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
  737. }
  738. #else /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
  739. #define wpa_supplicant_eap_param_needed NULL
  740. #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
  741. #ifdef CONFIG_EAP_PROXY
  742. static void wpa_supplicant_eap_proxy_cb(void *ctx)
  743. {
  744. struct wpa_supplicant *wpa_s = ctx;
  745. size_t len;
  746. wpa_s->mnc_len = eapol_sm_get_eap_proxy_imsi(wpa_s->eapol,
  747. wpa_s->imsi, &len);
  748. if (wpa_s->mnc_len > 0) {
  749. wpa_s->imsi[len] = '\0';
  750. wpa_printf(MSG_DEBUG, "eap_proxy: IMSI %s (MNC length %d)",
  751. wpa_s->imsi, wpa_s->mnc_len);
  752. } else {
  753. wpa_printf(MSG_DEBUG, "eap_proxy: IMSI not available");
  754. }
  755. }
  756. static void wpa_sm_sim_state_error_handler(struct wpa_supplicant *wpa_s)
  757. {
  758. int i;
  759. struct wpa_ssid *ssid;
  760. const struct eap_method_type *eap_methods;
  761. if (!wpa_s->conf)
  762. return;
  763. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  764. eap_methods = ssid->eap.eap_methods;
  765. if (!eap_methods)
  766. continue;
  767. for (i = 0; eap_methods[i].method != EAP_TYPE_NONE; i++) {
  768. if (eap_methods[i].vendor == EAP_VENDOR_IETF &&
  769. (eap_methods[i].method == EAP_TYPE_SIM ||
  770. eap_methods[i].method == EAP_TYPE_AKA ||
  771. eap_methods[i].method == EAP_TYPE_AKA_PRIME)) {
  772. wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
  773. break;
  774. }
  775. }
  776. }
  777. }
  778. static void
  779. wpa_supplicant_eap_proxy_notify_sim_status(void *ctx,
  780. enum eap_proxy_sim_state sim_state)
  781. {
  782. struct wpa_supplicant *wpa_s = ctx;
  783. wpa_printf(MSG_DEBUG, "eap_proxy: SIM card status %u", sim_state);
  784. switch (sim_state) {
  785. case SIM_STATE_ERROR:
  786. wpa_sm_sim_state_error_handler(wpa_s);
  787. break;
  788. default:
  789. wpa_printf(MSG_DEBUG, "eap_proxy: SIM card status unknown");
  790. break;
  791. }
  792. }
  793. #endif /* CONFIG_EAP_PROXY */
  794. static void wpa_supplicant_port_cb(void *ctx, int authorized)
  795. {
  796. struct wpa_supplicant *wpa_s = ctx;
  797. #ifdef CONFIG_AP
  798. if (wpa_s->ap_iface) {
  799. wpa_printf(MSG_DEBUG, "AP mode active - skip EAPOL Supplicant "
  800. "port status: %s",
  801. authorized ? "Authorized" : "Unauthorized");
  802. return;
  803. }
  804. #endif /* CONFIG_AP */
  805. wpa_printf(MSG_DEBUG, "EAPOL: Supplicant port status: %s",
  806. authorized ? "Authorized" : "Unauthorized");
  807. wpa_drv_set_supp_port(wpa_s, authorized);
  808. }
  809. static void wpa_supplicant_cert_cb(void *ctx, int depth, const char *subject,
  810. const char *altsubject[], int num_altsubject,
  811. const char *cert_hash,
  812. const struct wpabuf *cert)
  813. {
  814. struct wpa_supplicant *wpa_s = ctx;
  815. wpas_notify_certification(wpa_s, depth, subject, altsubject,
  816. num_altsubject, cert_hash, cert);
  817. }
  818. static void wpa_supplicant_status_cb(void *ctx, const char *status,
  819. const char *parameter)
  820. {
  821. struct wpa_supplicant *wpa_s = ctx;
  822. wpas_notify_eap_status(wpa_s, status, parameter);
  823. }
  824. static void wpa_supplicant_set_anon_id(void *ctx, const u8 *id, size_t len)
  825. {
  826. struct wpa_supplicant *wpa_s = ctx;
  827. char *str;
  828. int res;
  829. wpa_hexdump_ascii(MSG_DEBUG, "EAP method updated anonymous_identity",
  830. id, len);
  831. if (wpa_s->current_ssid == NULL)
  832. return;
  833. if (id == NULL) {
  834. if (wpa_config_set(wpa_s->current_ssid, "anonymous_identity",
  835. "NULL", 0) < 0)
  836. return;
  837. } else {
  838. str = os_malloc(len * 2 + 1);
  839. if (str == NULL)
  840. return;
  841. wpa_snprintf_hex(str, len * 2 + 1, id, len);
  842. res = wpa_config_set(wpa_s->current_ssid, "anonymous_identity",
  843. str, 0);
  844. os_free(str);
  845. if (res < 0)
  846. return;
  847. }
  848. if (wpa_s->conf->update_config) {
  849. res = wpa_config_write(wpa_s->confname, wpa_s->conf);
  850. if (res) {
  851. wpa_printf(MSG_DEBUG, "Failed to update config after "
  852. "anonymous_id update");
  853. }
  854. }
  855. }
  856. #endif /* IEEE8021X_EAPOL */
  857. int wpa_supplicant_init_eapol(struct wpa_supplicant *wpa_s)
  858. {
  859. #ifdef IEEE8021X_EAPOL
  860. struct eapol_ctx *ctx;
  861. ctx = os_zalloc(sizeof(*ctx));
  862. if (ctx == NULL) {
  863. wpa_printf(MSG_ERROR, "Failed to allocate EAPOL context.");
  864. return -1;
  865. }
  866. ctx->ctx = wpa_s;
  867. ctx->msg_ctx = wpa_s;
  868. ctx->eapol_send_ctx = wpa_s;
  869. ctx->preauth = 0;
  870. ctx->eapol_done_cb = wpa_supplicant_notify_eapol_done;
  871. ctx->eapol_send = wpa_supplicant_eapol_send;
  872. ctx->set_wep_key = wpa_eapol_set_wep_key;
  873. #ifndef CONFIG_NO_CONFIG_BLOBS
  874. ctx->set_config_blob = wpa_supplicant_set_config_blob;
  875. ctx->get_config_blob = wpa_supplicant_get_config_blob;
  876. #endif /* CONFIG_NO_CONFIG_BLOBS */
  877. ctx->aborted_cached = wpa_supplicant_aborted_cached;
  878. ctx->opensc_engine_path = wpa_s->conf->opensc_engine_path;
  879. ctx->pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path;
  880. ctx->pkcs11_module_path = wpa_s->conf->pkcs11_module_path;
  881. ctx->openssl_ciphers = wpa_s->conf->openssl_ciphers;
  882. ctx->wps = wpa_s->wps;
  883. ctx->eap_param_needed = wpa_supplicant_eap_param_needed;
  884. #ifdef CONFIG_EAP_PROXY
  885. ctx->eap_proxy_cb = wpa_supplicant_eap_proxy_cb;
  886. ctx->eap_proxy_notify_sim_status =
  887. wpa_supplicant_eap_proxy_notify_sim_status;
  888. #endif /* CONFIG_EAP_PROXY */
  889. ctx->port_cb = wpa_supplicant_port_cb;
  890. ctx->cb = wpa_supplicant_eapol_cb;
  891. ctx->cert_cb = wpa_supplicant_cert_cb;
  892. ctx->cert_in_cb = wpa_s->conf->cert_in_cb;
  893. ctx->status_cb = wpa_supplicant_status_cb;
  894. ctx->set_anon_id = wpa_supplicant_set_anon_id;
  895. ctx->cb_ctx = wpa_s;
  896. wpa_s->eapol = eapol_sm_init(ctx);
  897. if (wpa_s->eapol == NULL) {
  898. os_free(ctx);
  899. wpa_printf(MSG_ERROR, "Failed to initialize EAPOL state "
  900. "machines.");
  901. return -1;
  902. }
  903. #endif /* IEEE8021X_EAPOL */
  904. return 0;
  905. }
  906. #ifndef CONFIG_NO_WPA
  907. static void wpa_supplicant_set_rekey_offload(void *ctx,
  908. const u8 *kek, size_t kek_len,
  909. const u8 *kck, size_t kck_len,
  910. const u8 *replay_ctr)
  911. {
  912. struct wpa_supplicant *wpa_s = ctx;
  913. wpa_drv_set_rekey_info(wpa_s, kek, kek_len, kck, kck_len, replay_ctr);
  914. }
  915. static int wpa_supplicant_key_mgmt_set_pmk(void *ctx, const u8 *pmk,
  916. size_t pmk_len)
  917. {
  918. struct wpa_supplicant *wpa_s = ctx;
  919. if (wpa_s->conf->key_mgmt_offload &&
  920. (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD))
  921. return wpa_drv_set_key(wpa_s, WPA_ALG_PMK, NULL, 0, 0,
  922. NULL, 0, pmk, pmk_len);
  923. else
  924. return 0;
  925. }
  926. static void wpa_supplicant_fils_hlp_rx(void *ctx, const u8 *dst, const u8 *src,
  927. const u8 *pkt, size_t pkt_len)
  928. {
  929. struct wpa_supplicant *wpa_s = ctx;
  930. char *hex;
  931. size_t hexlen;
  932. hexlen = pkt_len * 2 + 1;
  933. hex = os_malloc(hexlen);
  934. if (!hex)
  935. return;
  936. wpa_snprintf_hex(hex, hexlen, pkt, pkt_len);
  937. wpa_msg(wpa_s, MSG_INFO, FILS_HLP_RX "dst=" MACSTR " src=" MACSTR
  938. " frame=%s", MAC2STR(dst), MAC2STR(src), hex);
  939. os_free(hex);
  940. }
  941. #endif /* CONFIG_NO_WPA */
  942. int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s)
  943. {
  944. #ifndef CONFIG_NO_WPA
  945. struct wpa_sm_ctx *ctx;
  946. ctx = os_zalloc(sizeof(*ctx));
  947. if (ctx == NULL) {
  948. wpa_printf(MSG_ERROR, "Failed to allocate WPA context.");
  949. return -1;
  950. }
  951. ctx->ctx = wpa_s;
  952. ctx->msg_ctx = wpa_s;
  953. ctx->set_state = _wpa_supplicant_set_state;
  954. ctx->get_state = _wpa_supplicant_get_state;
  955. ctx->deauthenticate = _wpa_supplicant_deauthenticate;
  956. ctx->set_key = wpa_supplicant_set_key;
  957. ctx->get_network_ctx = wpa_supplicant_get_network_ctx;
  958. ctx->get_bssid = wpa_supplicant_get_bssid;
  959. ctx->ether_send = _wpa_ether_send;
  960. ctx->get_beacon_ie = wpa_supplicant_get_beacon_ie;
  961. ctx->alloc_eapol = _wpa_alloc_eapol;
  962. ctx->cancel_auth_timeout = _wpa_supplicant_cancel_auth_timeout;
  963. ctx->add_pmkid = wpa_supplicant_add_pmkid;
  964. ctx->remove_pmkid = wpa_supplicant_remove_pmkid;
  965. #ifndef CONFIG_NO_CONFIG_BLOBS
  966. ctx->set_config_blob = wpa_supplicant_set_config_blob;
  967. ctx->get_config_blob = wpa_supplicant_get_config_blob;
  968. #endif /* CONFIG_NO_CONFIG_BLOBS */
  969. ctx->mlme_setprotection = wpa_supplicant_mlme_setprotection;
  970. #ifdef CONFIG_IEEE80211R
  971. ctx->update_ft_ies = wpa_supplicant_update_ft_ies;
  972. ctx->send_ft_action = wpa_supplicant_send_ft_action;
  973. ctx->mark_authenticated = wpa_supplicant_mark_authenticated;
  974. #endif /* CONFIG_IEEE80211R */
  975. #ifdef CONFIG_TDLS
  976. ctx->tdls_get_capa = wpa_supplicant_tdls_get_capa;
  977. ctx->send_tdls_mgmt = wpa_supplicant_send_tdls_mgmt;
  978. ctx->tdls_oper = wpa_supplicant_tdls_oper;
  979. ctx->tdls_peer_addset = wpa_supplicant_tdls_peer_addset;
  980. ctx->tdls_enable_channel_switch =
  981. wpa_supplicant_tdls_enable_channel_switch;
  982. ctx->tdls_disable_channel_switch =
  983. wpa_supplicant_tdls_disable_channel_switch;
  984. #endif /* CONFIG_TDLS */
  985. ctx->set_rekey_offload = wpa_supplicant_set_rekey_offload;
  986. ctx->key_mgmt_set_pmk = wpa_supplicant_key_mgmt_set_pmk;
  987. ctx->fils_hlp_rx = wpa_supplicant_fils_hlp_rx;
  988. wpa_s->wpa = wpa_sm_init(ctx);
  989. if (wpa_s->wpa == NULL) {
  990. wpa_printf(MSG_ERROR, "Failed to initialize WPA state "
  991. "machine");
  992. os_free(ctx);
  993. return -1;
  994. }
  995. #endif /* CONFIG_NO_WPA */
  996. return 0;
  997. }
  998. void wpa_supplicant_rsn_supp_set_config(struct wpa_supplicant *wpa_s,
  999. struct wpa_ssid *ssid)
  1000. {
  1001. struct rsn_supp_config conf;
  1002. if (ssid) {
  1003. os_memset(&conf, 0, sizeof(conf));
  1004. conf.network_ctx = ssid;
  1005. conf.peerkey_enabled = ssid->peerkey;
  1006. conf.allowed_pairwise_cipher = ssid->pairwise_cipher;
  1007. #ifdef IEEE8021X_EAPOL
  1008. conf.proactive_key_caching = ssid->proactive_key_caching < 0 ?
  1009. wpa_s->conf->okc : ssid->proactive_key_caching;
  1010. conf.eap_workaround = ssid->eap_workaround;
  1011. conf.eap_conf_ctx = &ssid->eap;
  1012. #endif /* IEEE8021X_EAPOL */
  1013. conf.ssid = ssid->ssid;
  1014. conf.ssid_len = ssid->ssid_len;
  1015. conf.wpa_ptk_rekey = ssid->wpa_ptk_rekey;
  1016. #ifdef CONFIG_P2P
  1017. if (ssid->p2p_group && wpa_s->current_bss &&
  1018. !wpa_s->p2p_disable_ip_addr_req) {
  1019. struct wpabuf *p2p;
  1020. p2p = wpa_bss_get_vendor_ie_multi(wpa_s->current_bss,
  1021. P2P_IE_VENDOR_TYPE);
  1022. if (p2p) {
  1023. u8 group_capab;
  1024. group_capab = p2p_get_group_capab(p2p);
  1025. if (group_capab &
  1026. P2P_GROUP_CAPAB_IP_ADDR_ALLOCATION)
  1027. conf.p2p = 1;
  1028. wpabuf_free(p2p);
  1029. }
  1030. }
  1031. #endif /* CONFIG_P2P */
  1032. conf.wpa_rsc_relaxation = wpa_s->conf->wpa_rsc_relaxation;
  1033. }
  1034. wpa_sm_set_config(wpa_s->wpa, ssid ? &conf : NULL);
  1035. }