wpas_glue.c 33 KB

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