wpas_glue.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272
  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. const u8 *fils_cache_id,
  445. const u8 *pmk, size_t pmk_len)
  446. {
  447. struct wpa_supplicant *wpa_s = _wpa_s;
  448. struct wpa_ssid *ssid;
  449. struct wpa_pmkid_params params;
  450. os_memset(&params, 0, sizeof(params));
  451. ssid = wpas_get_network_ctx(wpa_s, network_ctx);
  452. if (ssid)
  453. wpa_msg(wpa_s, MSG_INFO, PMKSA_CACHE_ADDED MACSTR " %d",
  454. MAC2STR(bssid), ssid->id);
  455. if (ssid && fils_cache_id) {
  456. params.ssid = ssid->ssid;
  457. params.ssid_len = ssid->ssid_len;
  458. params.fils_cache_id = fils_cache_id;
  459. } else {
  460. params.bssid = bssid;
  461. }
  462. params.pmkid = pmkid;
  463. params.pmk = pmk;
  464. params.pmk_len = pmk_len;
  465. return wpa_drv_add_pmkid(wpa_s, &params);
  466. }
  467. static int wpa_supplicant_remove_pmkid(void *_wpa_s, void *network_ctx,
  468. const u8 *bssid, const u8 *pmkid,
  469. const u8 *fils_cache_id)
  470. {
  471. struct wpa_supplicant *wpa_s = _wpa_s;
  472. struct wpa_ssid *ssid;
  473. struct wpa_pmkid_params params;
  474. os_memset(&params, 0, sizeof(params));
  475. ssid = wpas_get_network_ctx(wpa_s, network_ctx);
  476. if (ssid)
  477. wpa_msg(wpa_s, MSG_INFO, PMKSA_CACHE_REMOVED MACSTR " %d",
  478. MAC2STR(bssid), ssid->id);
  479. if (ssid && fils_cache_id) {
  480. params.ssid = ssid->ssid;
  481. params.ssid_len = ssid->ssid_len;
  482. params.fils_cache_id = fils_cache_id;
  483. } else {
  484. params.bssid = bssid;
  485. }
  486. params.pmkid = pmkid;
  487. return wpa_drv_remove_pmkid(wpa_s, &params);
  488. }
  489. #ifdef CONFIG_IEEE80211R
  490. static int wpa_supplicant_update_ft_ies(void *ctx, const u8 *md,
  491. const u8 *ies, size_t ies_len)
  492. {
  493. struct wpa_supplicant *wpa_s = ctx;
  494. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  495. return sme_update_ft_ies(wpa_s, md, ies, ies_len);
  496. return wpa_drv_update_ft_ies(wpa_s, md, ies, ies_len);
  497. }
  498. static int wpa_supplicant_send_ft_action(void *ctx, u8 action,
  499. const u8 *target_ap,
  500. const u8 *ies, size_t ies_len)
  501. {
  502. struct wpa_supplicant *wpa_s = ctx;
  503. int ret;
  504. u8 *data, *pos;
  505. size_t data_len;
  506. if (action != 1) {
  507. wpa_printf(MSG_ERROR, "Unsupported send_ft_action action %d",
  508. action);
  509. return -1;
  510. }
  511. /*
  512. * Action frame payload:
  513. * Category[1] = 6 (Fast BSS Transition)
  514. * Action[1] = 1 (Fast BSS Transition Request)
  515. * STA Address
  516. * Target AP Address
  517. * FT IEs
  518. */
  519. data_len = 2 + 2 * ETH_ALEN + ies_len;
  520. data = os_malloc(data_len);
  521. if (data == NULL)
  522. return -1;
  523. pos = data;
  524. *pos++ = 0x06; /* FT Action category */
  525. *pos++ = action;
  526. os_memcpy(pos, wpa_s->own_addr, ETH_ALEN);
  527. pos += ETH_ALEN;
  528. os_memcpy(pos, target_ap, ETH_ALEN);
  529. pos += ETH_ALEN;
  530. os_memcpy(pos, ies, ies_len);
  531. ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0,
  532. wpa_s->bssid, wpa_s->own_addr, wpa_s->bssid,
  533. data, data_len, 0);
  534. os_free(data);
  535. return ret;
  536. }
  537. static int wpa_supplicant_mark_authenticated(void *ctx, const u8 *target_ap)
  538. {
  539. struct wpa_supplicant *wpa_s = ctx;
  540. struct wpa_driver_auth_params params;
  541. struct wpa_bss *bss;
  542. bss = wpa_bss_get_bssid(wpa_s, target_ap);
  543. if (bss == NULL)
  544. return -1;
  545. os_memset(&params, 0, sizeof(params));
  546. params.bssid = target_ap;
  547. params.freq = bss->freq;
  548. params.ssid = bss->ssid;
  549. params.ssid_len = bss->ssid_len;
  550. params.auth_alg = WPA_AUTH_ALG_FT;
  551. params.local_state_change = 1;
  552. return wpa_drv_authenticate(wpa_s, &params);
  553. }
  554. #endif /* CONFIG_IEEE80211R */
  555. #ifdef CONFIG_TDLS
  556. static int wpa_supplicant_tdls_get_capa(void *ctx, int *tdls_supported,
  557. int *tdls_ext_setup,
  558. int *tdls_chan_switch)
  559. {
  560. struct wpa_supplicant *wpa_s = ctx;
  561. *tdls_supported = 0;
  562. *tdls_ext_setup = 0;
  563. *tdls_chan_switch = 0;
  564. if (!wpa_s->drv_capa_known)
  565. return -1;
  566. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)
  567. *tdls_supported = 1;
  568. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP)
  569. *tdls_ext_setup = 1;
  570. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)
  571. *tdls_chan_switch = 1;
  572. return 0;
  573. }
  574. static int wpa_supplicant_send_tdls_mgmt(void *ctx, const u8 *dst,
  575. u8 action_code, u8 dialog_token,
  576. u16 status_code, u32 peer_capab,
  577. int initiator, const u8 *buf,
  578. size_t len)
  579. {
  580. struct wpa_supplicant *wpa_s = ctx;
  581. return wpa_drv_send_tdls_mgmt(wpa_s, dst, action_code, dialog_token,
  582. status_code, peer_capab, initiator, buf,
  583. len);
  584. }
  585. static int wpa_supplicant_tdls_oper(void *ctx, int oper, const u8 *peer)
  586. {
  587. struct wpa_supplicant *wpa_s = ctx;
  588. return wpa_drv_tdls_oper(wpa_s, oper, peer);
  589. }
  590. static int wpa_supplicant_tdls_peer_addset(
  591. void *ctx, const u8 *peer, int add, u16 aid, u16 capability,
  592. const u8 *supp_rates, size_t supp_rates_len,
  593. const struct ieee80211_ht_capabilities *ht_capab,
  594. const struct ieee80211_vht_capabilities *vht_capab,
  595. u8 qosinfo, int wmm, const u8 *ext_capab, size_t ext_capab_len,
  596. const u8 *supp_channels, size_t supp_channels_len,
  597. const u8 *supp_oper_classes, size_t supp_oper_classes_len)
  598. {
  599. struct wpa_supplicant *wpa_s = ctx;
  600. struct hostapd_sta_add_params params;
  601. os_memset(&params, 0, sizeof(params));
  602. params.addr = peer;
  603. params.aid = aid;
  604. params.capability = capability;
  605. params.flags = WPA_STA_TDLS_PEER | WPA_STA_AUTHORIZED;
  606. /*
  607. * Don't rely only on qosinfo for WMM capability. It may be 0 even when
  608. * present. Allow the WMM IE to also indicate QoS support.
  609. */
  610. if (wmm || qosinfo)
  611. params.flags |= WPA_STA_WMM;
  612. params.ht_capabilities = ht_capab;
  613. params.vht_capabilities = vht_capab;
  614. params.qosinfo = qosinfo;
  615. params.listen_interval = 0;
  616. params.supp_rates = supp_rates;
  617. params.supp_rates_len = supp_rates_len;
  618. params.set = !add;
  619. params.ext_capab = ext_capab;
  620. params.ext_capab_len = ext_capab_len;
  621. params.supp_channels = supp_channels;
  622. params.supp_channels_len = supp_channels_len;
  623. params.supp_oper_classes = supp_oper_classes;
  624. params.supp_oper_classes_len = supp_oper_classes_len;
  625. return wpa_drv_sta_add(wpa_s, &params);
  626. }
  627. static int wpa_supplicant_tdls_enable_channel_switch(
  628. void *ctx, const u8 *addr, u8 oper_class,
  629. const struct hostapd_freq_params *params)
  630. {
  631. struct wpa_supplicant *wpa_s = ctx;
  632. return wpa_drv_tdls_enable_channel_switch(wpa_s, addr, oper_class,
  633. params);
  634. }
  635. static int wpa_supplicant_tdls_disable_channel_switch(void *ctx, const u8 *addr)
  636. {
  637. struct wpa_supplicant *wpa_s = ctx;
  638. return wpa_drv_tdls_disable_channel_switch(wpa_s, addr);
  639. }
  640. #endif /* CONFIG_TDLS */
  641. #endif /* CONFIG_NO_WPA */
  642. enum wpa_ctrl_req_type wpa_supplicant_ctrl_req_from_string(const char *field)
  643. {
  644. if (os_strcmp(field, "IDENTITY") == 0)
  645. return WPA_CTRL_REQ_EAP_IDENTITY;
  646. else if (os_strcmp(field, "PASSWORD") == 0)
  647. return WPA_CTRL_REQ_EAP_PASSWORD;
  648. else if (os_strcmp(field, "NEW_PASSWORD") == 0)
  649. return WPA_CTRL_REQ_EAP_NEW_PASSWORD;
  650. else if (os_strcmp(field, "PIN") == 0)
  651. return WPA_CTRL_REQ_EAP_PIN;
  652. else if (os_strcmp(field, "OTP") == 0)
  653. return WPA_CTRL_REQ_EAP_OTP;
  654. else if (os_strcmp(field, "PASSPHRASE") == 0)
  655. return WPA_CTRL_REQ_EAP_PASSPHRASE;
  656. else if (os_strcmp(field, "SIM") == 0)
  657. return WPA_CTRL_REQ_SIM;
  658. else if (os_strcmp(field, "PSK_PASSPHRASE") == 0)
  659. return WPA_CTRL_REQ_PSK_PASSPHRASE;
  660. else if (os_strcmp(field, "EXT_CERT_CHECK") == 0)
  661. return WPA_CTRL_REQ_EXT_CERT_CHECK;
  662. return WPA_CTRL_REQ_UNKNOWN;
  663. }
  664. const char * wpa_supplicant_ctrl_req_to_string(enum wpa_ctrl_req_type field,
  665. const char *default_txt,
  666. const char **txt)
  667. {
  668. const char *ret = NULL;
  669. *txt = default_txt;
  670. switch (field) {
  671. case WPA_CTRL_REQ_EAP_IDENTITY:
  672. *txt = "Identity";
  673. ret = "IDENTITY";
  674. break;
  675. case WPA_CTRL_REQ_EAP_PASSWORD:
  676. *txt = "Password";
  677. ret = "PASSWORD";
  678. break;
  679. case WPA_CTRL_REQ_EAP_NEW_PASSWORD:
  680. *txt = "New Password";
  681. ret = "NEW_PASSWORD";
  682. break;
  683. case WPA_CTRL_REQ_EAP_PIN:
  684. *txt = "PIN";
  685. ret = "PIN";
  686. break;
  687. case WPA_CTRL_REQ_EAP_OTP:
  688. ret = "OTP";
  689. break;
  690. case WPA_CTRL_REQ_EAP_PASSPHRASE:
  691. *txt = "Private key passphrase";
  692. ret = "PASSPHRASE";
  693. break;
  694. case WPA_CTRL_REQ_SIM:
  695. ret = "SIM";
  696. break;
  697. case WPA_CTRL_REQ_PSK_PASSPHRASE:
  698. *txt = "PSK or passphrase";
  699. ret = "PSK_PASSPHRASE";
  700. break;
  701. case WPA_CTRL_REQ_EXT_CERT_CHECK:
  702. *txt = "External server certificate validation";
  703. ret = "EXT_CERT_CHECK";
  704. break;
  705. default:
  706. break;
  707. }
  708. /* txt needs to be something */
  709. if (*txt == NULL) {
  710. wpa_printf(MSG_WARNING, "No message for request %d", field);
  711. ret = NULL;
  712. }
  713. return ret;
  714. }
  715. void wpas_send_ctrl_req(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
  716. const char *field_name, const char *txt)
  717. {
  718. char *buf;
  719. size_t buflen;
  720. int len;
  721. buflen = 100 + os_strlen(txt) + ssid->ssid_len;
  722. buf = os_malloc(buflen);
  723. if (buf == NULL)
  724. return;
  725. len = os_snprintf(buf, buflen, "%s-%d:%s needed for SSID ",
  726. field_name, ssid->id, txt);
  727. if (os_snprintf_error(buflen, len)) {
  728. os_free(buf);
  729. return;
  730. }
  731. if (ssid->ssid && buflen > len + ssid->ssid_len) {
  732. os_memcpy(buf + len, ssid->ssid, ssid->ssid_len);
  733. len += ssid->ssid_len;
  734. buf[len] = '\0';
  735. }
  736. buf[buflen - 1] = '\0';
  737. wpa_msg(wpa_s, MSG_INFO, WPA_CTRL_REQ "%s", buf);
  738. os_free(buf);
  739. }
  740. #ifdef IEEE8021X_EAPOL
  741. #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
  742. static void wpa_supplicant_eap_param_needed(void *ctx,
  743. enum wpa_ctrl_req_type field,
  744. const char *default_txt)
  745. {
  746. struct wpa_supplicant *wpa_s = ctx;
  747. struct wpa_ssid *ssid = wpa_s->current_ssid;
  748. const char *field_name, *txt = NULL;
  749. if (ssid == NULL)
  750. return;
  751. if (field == WPA_CTRL_REQ_EXT_CERT_CHECK)
  752. ssid->eap.pending_ext_cert_check = PENDING_CHECK;
  753. wpas_notify_network_request(wpa_s, ssid, field, default_txt);
  754. field_name = wpa_supplicant_ctrl_req_to_string(field, default_txt,
  755. &txt);
  756. if (field_name == NULL) {
  757. wpa_printf(MSG_WARNING, "Unhandled EAP param %d needed",
  758. field);
  759. return;
  760. }
  761. wpas_notify_eap_status(wpa_s, "eap parameter needed", field_name);
  762. wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
  763. }
  764. #else /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
  765. #define wpa_supplicant_eap_param_needed NULL
  766. #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
  767. #ifdef CONFIG_EAP_PROXY
  768. static void wpa_supplicant_eap_proxy_cb(void *ctx)
  769. {
  770. struct wpa_supplicant *wpa_s = ctx;
  771. size_t len;
  772. wpa_s->mnc_len = eapol_sm_get_eap_proxy_imsi(wpa_s->eapol,
  773. wpa_s->imsi, &len);
  774. if (wpa_s->mnc_len > 0) {
  775. wpa_s->imsi[len] = '\0';
  776. wpa_printf(MSG_DEBUG, "eap_proxy: IMSI %s (MNC length %d)",
  777. wpa_s->imsi, wpa_s->mnc_len);
  778. } else {
  779. wpa_printf(MSG_DEBUG, "eap_proxy: IMSI not available");
  780. }
  781. }
  782. static void wpa_sm_sim_state_error_handler(struct wpa_supplicant *wpa_s)
  783. {
  784. int i;
  785. struct wpa_ssid *ssid;
  786. const struct eap_method_type *eap_methods;
  787. if (!wpa_s->conf)
  788. return;
  789. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  790. eap_methods = ssid->eap.eap_methods;
  791. if (!eap_methods)
  792. continue;
  793. for (i = 0; eap_methods[i].method != EAP_TYPE_NONE; i++) {
  794. if (eap_methods[i].vendor == EAP_VENDOR_IETF &&
  795. (eap_methods[i].method == EAP_TYPE_SIM ||
  796. eap_methods[i].method == EAP_TYPE_AKA ||
  797. eap_methods[i].method == EAP_TYPE_AKA_PRIME)) {
  798. wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
  799. break;
  800. }
  801. }
  802. }
  803. }
  804. static void
  805. wpa_supplicant_eap_proxy_notify_sim_status(void *ctx,
  806. enum eap_proxy_sim_state sim_state)
  807. {
  808. struct wpa_supplicant *wpa_s = ctx;
  809. wpa_printf(MSG_DEBUG, "eap_proxy: SIM card status %u", sim_state);
  810. switch (sim_state) {
  811. case SIM_STATE_ERROR:
  812. wpa_sm_sim_state_error_handler(wpa_s);
  813. break;
  814. default:
  815. wpa_printf(MSG_DEBUG, "eap_proxy: SIM card status unknown");
  816. break;
  817. }
  818. }
  819. #endif /* CONFIG_EAP_PROXY */
  820. static void wpa_supplicant_port_cb(void *ctx, int authorized)
  821. {
  822. struct wpa_supplicant *wpa_s = ctx;
  823. #ifdef CONFIG_AP
  824. if (wpa_s->ap_iface) {
  825. wpa_printf(MSG_DEBUG, "AP mode active - skip EAPOL Supplicant "
  826. "port status: %s",
  827. authorized ? "Authorized" : "Unauthorized");
  828. return;
  829. }
  830. #endif /* CONFIG_AP */
  831. wpa_printf(MSG_DEBUG, "EAPOL: Supplicant port status: %s",
  832. authorized ? "Authorized" : "Unauthorized");
  833. wpa_drv_set_supp_port(wpa_s, authorized);
  834. }
  835. static void wpa_supplicant_cert_cb(void *ctx, int depth, const char *subject,
  836. const char *altsubject[], int num_altsubject,
  837. const char *cert_hash,
  838. const struct wpabuf *cert)
  839. {
  840. struct wpa_supplicant *wpa_s = ctx;
  841. wpas_notify_certification(wpa_s, depth, subject, altsubject,
  842. num_altsubject, cert_hash, cert);
  843. }
  844. static void wpa_supplicant_status_cb(void *ctx, const char *status,
  845. const char *parameter)
  846. {
  847. struct wpa_supplicant *wpa_s = ctx;
  848. wpas_notify_eap_status(wpa_s, status, parameter);
  849. }
  850. static void wpa_supplicant_set_anon_id(void *ctx, const u8 *id, size_t len)
  851. {
  852. struct wpa_supplicant *wpa_s = ctx;
  853. char *str;
  854. int res;
  855. wpa_hexdump_ascii(MSG_DEBUG, "EAP method updated anonymous_identity",
  856. id, len);
  857. if (wpa_s->current_ssid == NULL)
  858. return;
  859. if (id == NULL) {
  860. if (wpa_config_set(wpa_s->current_ssid, "anonymous_identity",
  861. "NULL", 0) < 0)
  862. return;
  863. } else {
  864. str = os_malloc(len * 2 + 1);
  865. if (str == NULL)
  866. return;
  867. wpa_snprintf_hex(str, len * 2 + 1, id, len);
  868. res = wpa_config_set(wpa_s->current_ssid, "anonymous_identity",
  869. str, 0);
  870. os_free(str);
  871. if (res < 0)
  872. return;
  873. }
  874. if (wpa_s->conf->update_config) {
  875. res = wpa_config_write(wpa_s->confname, wpa_s->conf);
  876. if (res) {
  877. wpa_printf(MSG_DEBUG, "Failed to update config after "
  878. "anonymous_id update");
  879. }
  880. }
  881. }
  882. #endif /* IEEE8021X_EAPOL */
  883. int wpa_supplicant_init_eapol(struct wpa_supplicant *wpa_s)
  884. {
  885. #ifdef IEEE8021X_EAPOL
  886. struct eapol_ctx *ctx;
  887. ctx = os_zalloc(sizeof(*ctx));
  888. if (ctx == NULL) {
  889. wpa_printf(MSG_ERROR, "Failed to allocate EAPOL context.");
  890. return -1;
  891. }
  892. ctx->ctx = wpa_s;
  893. ctx->msg_ctx = wpa_s;
  894. ctx->eapol_send_ctx = wpa_s;
  895. ctx->preauth = 0;
  896. ctx->eapol_done_cb = wpa_supplicant_notify_eapol_done;
  897. ctx->eapol_send = wpa_supplicant_eapol_send;
  898. ctx->set_wep_key = wpa_eapol_set_wep_key;
  899. #ifndef CONFIG_NO_CONFIG_BLOBS
  900. ctx->set_config_blob = wpa_supplicant_set_config_blob;
  901. ctx->get_config_blob = wpa_supplicant_get_config_blob;
  902. #endif /* CONFIG_NO_CONFIG_BLOBS */
  903. ctx->aborted_cached = wpa_supplicant_aborted_cached;
  904. ctx->opensc_engine_path = wpa_s->conf->opensc_engine_path;
  905. ctx->pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path;
  906. ctx->pkcs11_module_path = wpa_s->conf->pkcs11_module_path;
  907. ctx->openssl_ciphers = wpa_s->conf->openssl_ciphers;
  908. ctx->wps = wpa_s->wps;
  909. ctx->eap_param_needed = wpa_supplicant_eap_param_needed;
  910. #ifdef CONFIG_EAP_PROXY
  911. ctx->eap_proxy_cb = wpa_supplicant_eap_proxy_cb;
  912. ctx->eap_proxy_notify_sim_status =
  913. wpa_supplicant_eap_proxy_notify_sim_status;
  914. #endif /* CONFIG_EAP_PROXY */
  915. ctx->port_cb = wpa_supplicant_port_cb;
  916. ctx->cb = wpa_supplicant_eapol_cb;
  917. ctx->cert_cb = wpa_supplicant_cert_cb;
  918. ctx->cert_in_cb = wpa_s->conf->cert_in_cb;
  919. ctx->status_cb = wpa_supplicant_status_cb;
  920. ctx->set_anon_id = wpa_supplicant_set_anon_id;
  921. ctx->cb_ctx = wpa_s;
  922. wpa_s->eapol = eapol_sm_init(ctx);
  923. if (wpa_s->eapol == NULL) {
  924. os_free(ctx);
  925. wpa_printf(MSG_ERROR, "Failed to initialize EAPOL state "
  926. "machines.");
  927. return -1;
  928. }
  929. #endif /* IEEE8021X_EAPOL */
  930. return 0;
  931. }
  932. #ifndef CONFIG_NO_WPA
  933. static void wpa_supplicant_set_rekey_offload(void *ctx,
  934. const u8 *kek, size_t kek_len,
  935. const u8 *kck, size_t kck_len,
  936. const u8 *replay_ctr)
  937. {
  938. struct wpa_supplicant *wpa_s = ctx;
  939. wpa_drv_set_rekey_info(wpa_s, kek, kek_len, kck, kck_len, replay_ctr);
  940. }
  941. static int wpa_supplicant_key_mgmt_set_pmk(void *ctx, const u8 *pmk,
  942. size_t pmk_len)
  943. {
  944. struct wpa_supplicant *wpa_s = ctx;
  945. if (wpa_s->conf->key_mgmt_offload &&
  946. (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD))
  947. return wpa_drv_set_key(wpa_s, WPA_ALG_PMK, NULL, 0, 0,
  948. NULL, 0, pmk, pmk_len);
  949. else
  950. return 0;
  951. }
  952. static void wpa_supplicant_fils_hlp_rx(void *ctx, const u8 *dst, const u8 *src,
  953. const u8 *pkt, size_t pkt_len)
  954. {
  955. struct wpa_supplicant *wpa_s = ctx;
  956. char *hex;
  957. size_t hexlen;
  958. hexlen = pkt_len * 2 + 1;
  959. hex = os_malloc(hexlen);
  960. if (!hex)
  961. return;
  962. wpa_snprintf_hex(hex, hexlen, pkt, pkt_len);
  963. wpa_msg(wpa_s, MSG_INFO, FILS_HLP_RX "dst=" MACSTR " src=" MACSTR
  964. " frame=%s", MAC2STR(dst), MAC2STR(src), hex);
  965. os_free(hex);
  966. }
  967. #endif /* CONFIG_NO_WPA */
  968. int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s)
  969. {
  970. #ifndef CONFIG_NO_WPA
  971. struct wpa_sm_ctx *ctx;
  972. ctx = os_zalloc(sizeof(*ctx));
  973. if (ctx == NULL) {
  974. wpa_printf(MSG_ERROR, "Failed to allocate WPA context.");
  975. return -1;
  976. }
  977. ctx->ctx = wpa_s;
  978. ctx->msg_ctx = wpa_s;
  979. ctx->set_state = _wpa_supplicant_set_state;
  980. ctx->get_state = _wpa_supplicant_get_state;
  981. ctx->deauthenticate = _wpa_supplicant_deauthenticate;
  982. ctx->set_key = wpa_supplicant_set_key;
  983. ctx->get_network_ctx = wpa_supplicant_get_network_ctx;
  984. ctx->get_bssid = wpa_supplicant_get_bssid;
  985. ctx->ether_send = _wpa_ether_send;
  986. ctx->get_beacon_ie = wpa_supplicant_get_beacon_ie;
  987. ctx->alloc_eapol = _wpa_alloc_eapol;
  988. ctx->cancel_auth_timeout = _wpa_supplicant_cancel_auth_timeout;
  989. ctx->add_pmkid = wpa_supplicant_add_pmkid;
  990. ctx->remove_pmkid = wpa_supplicant_remove_pmkid;
  991. #ifndef CONFIG_NO_CONFIG_BLOBS
  992. ctx->set_config_blob = wpa_supplicant_set_config_blob;
  993. ctx->get_config_blob = wpa_supplicant_get_config_blob;
  994. #endif /* CONFIG_NO_CONFIG_BLOBS */
  995. ctx->mlme_setprotection = wpa_supplicant_mlme_setprotection;
  996. #ifdef CONFIG_IEEE80211R
  997. ctx->update_ft_ies = wpa_supplicant_update_ft_ies;
  998. ctx->send_ft_action = wpa_supplicant_send_ft_action;
  999. ctx->mark_authenticated = wpa_supplicant_mark_authenticated;
  1000. #endif /* CONFIG_IEEE80211R */
  1001. #ifdef CONFIG_TDLS
  1002. ctx->tdls_get_capa = wpa_supplicant_tdls_get_capa;
  1003. ctx->send_tdls_mgmt = wpa_supplicant_send_tdls_mgmt;
  1004. ctx->tdls_oper = wpa_supplicant_tdls_oper;
  1005. ctx->tdls_peer_addset = wpa_supplicant_tdls_peer_addset;
  1006. ctx->tdls_enable_channel_switch =
  1007. wpa_supplicant_tdls_enable_channel_switch;
  1008. ctx->tdls_disable_channel_switch =
  1009. wpa_supplicant_tdls_disable_channel_switch;
  1010. #endif /* CONFIG_TDLS */
  1011. ctx->set_rekey_offload = wpa_supplicant_set_rekey_offload;
  1012. ctx->key_mgmt_set_pmk = wpa_supplicant_key_mgmt_set_pmk;
  1013. ctx->fils_hlp_rx = wpa_supplicant_fils_hlp_rx;
  1014. wpa_s->wpa = wpa_sm_init(ctx);
  1015. if (wpa_s->wpa == NULL) {
  1016. wpa_printf(MSG_ERROR, "Failed to initialize WPA state "
  1017. "machine");
  1018. os_free(ctx);
  1019. return -1;
  1020. }
  1021. #endif /* CONFIG_NO_WPA */
  1022. return 0;
  1023. }
  1024. void wpa_supplicant_rsn_supp_set_config(struct wpa_supplicant *wpa_s,
  1025. struct wpa_ssid *ssid)
  1026. {
  1027. struct rsn_supp_config conf;
  1028. if (ssid) {
  1029. os_memset(&conf, 0, sizeof(conf));
  1030. conf.network_ctx = ssid;
  1031. conf.peerkey_enabled = ssid->peerkey;
  1032. conf.allowed_pairwise_cipher = ssid->pairwise_cipher;
  1033. #ifdef IEEE8021X_EAPOL
  1034. conf.proactive_key_caching = ssid->proactive_key_caching < 0 ?
  1035. wpa_s->conf->okc : ssid->proactive_key_caching;
  1036. conf.eap_workaround = ssid->eap_workaround;
  1037. conf.eap_conf_ctx = &ssid->eap;
  1038. #endif /* IEEE8021X_EAPOL */
  1039. conf.ssid = ssid->ssid;
  1040. conf.ssid_len = ssid->ssid_len;
  1041. conf.wpa_ptk_rekey = ssid->wpa_ptk_rekey;
  1042. #ifdef CONFIG_P2P
  1043. if (ssid->p2p_group && wpa_s->current_bss &&
  1044. !wpa_s->p2p_disable_ip_addr_req) {
  1045. struct wpabuf *p2p;
  1046. p2p = wpa_bss_get_vendor_ie_multi(wpa_s->current_bss,
  1047. P2P_IE_VENDOR_TYPE);
  1048. if (p2p) {
  1049. u8 group_capab;
  1050. group_capab = p2p_get_group_capab(p2p);
  1051. if (group_capab &
  1052. P2P_GROUP_CAPAB_IP_ADDR_ALLOCATION)
  1053. conf.p2p = 1;
  1054. wpabuf_free(p2p);
  1055. }
  1056. }
  1057. #endif /* CONFIG_P2P */
  1058. conf.wpa_rsc_relaxation = wpa_s->conf->wpa_rsc_relaxation;
  1059. #ifdef CONFIG_FILS
  1060. if (wpa_key_mgmt_fils(wpa_s->key_mgmt))
  1061. conf.fils_cache_id =
  1062. wpa_bss_get_fils_cache_id(wpa_s->current_bss);
  1063. #endif /* CONFIG_FILS */
  1064. }
  1065. wpa_sm_set_config(wpa_s->wpa, ssid ? &conf : NULL);
  1066. }