wpa_auth_ie.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059
  1. /*
  2. * hostapd - WPA/RSN IE and KDE definitions
  3. * Copyright (c) 2004-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 "utils/includes.h"
  9. #include "utils/common.h"
  10. #include "common/ieee802_11_defs.h"
  11. #include "eapol_auth/eapol_auth_sm.h"
  12. #include "ap_config.h"
  13. #include "ieee802_11.h"
  14. #include "wpa_auth.h"
  15. #include "pmksa_cache_auth.h"
  16. #include "wpa_auth_ie.h"
  17. #include "wpa_auth_i.h"
  18. #ifdef CONFIG_RSN_TESTING
  19. int rsn_testing = 0;
  20. #endif /* CONFIG_RSN_TESTING */
  21. static int wpa_write_wpa_ie(struct wpa_auth_config *conf, u8 *buf, size_t len)
  22. {
  23. struct wpa_ie_hdr *hdr;
  24. int num_suites;
  25. u8 *pos, *count;
  26. u32 suite;
  27. hdr = (struct wpa_ie_hdr *) buf;
  28. hdr->elem_id = WLAN_EID_VENDOR_SPECIFIC;
  29. RSN_SELECTOR_PUT(hdr->oui, WPA_OUI_TYPE);
  30. WPA_PUT_LE16(hdr->version, WPA_VERSION);
  31. pos = (u8 *) (hdr + 1);
  32. suite = wpa_cipher_to_suite(WPA_PROTO_WPA, conf->wpa_group);
  33. if (suite == 0) {
  34. wpa_printf(MSG_DEBUG, "Invalid group cipher (%d).",
  35. conf->wpa_group);
  36. return -1;
  37. }
  38. RSN_SELECTOR_PUT(pos, suite);
  39. pos += WPA_SELECTOR_LEN;
  40. count = pos;
  41. pos += 2;
  42. num_suites = wpa_cipher_put_suites(pos, conf->wpa_pairwise);
  43. if (num_suites == 0) {
  44. wpa_printf(MSG_DEBUG, "Invalid pairwise cipher (%d).",
  45. conf->wpa_pairwise);
  46. return -1;
  47. }
  48. pos += num_suites * WPA_SELECTOR_LEN;
  49. WPA_PUT_LE16(count, num_suites);
  50. num_suites = 0;
  51. count = pos;
  52. pos += 2;
  53. if (conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
  54. RSN_SELECTOR_PUT(pos, WPA_AUTH_KEY_MGMT_UNSPEC_802_1X);
  55. pos += WPA_SELECTOR_LEN;
  56. num_suites++;
  57. }
  58. if (conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK) {
  59. RSN_SELECTOR_PUT(pos, WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X);
  60. pos += WPA_SELECTOR_LEN;
  61. num_suites++;
  62. }
  63. if (num_suites == 0) {
  64. wpa_printf(MSG_DEBUG, "Invalid key management type (%d).",
  65. conf->wpa_key_mgmt);
  66. return -1;
  67. }
  68. WPA_PUT_LE16(count, num_suites);
  69. /* WPA Capabilities; use defaults, so no need to include it */
  70. hdr->len = (pos - buf) - 2;
  71. return pos - buf;
  72. }
  73. int wpa_write_rsn_ie(struct wpa_auth_config *conf, u8 *buf, size_t len,
  74. const u8 *pmkid)
  75. {
  76. struct rsn_ie_hdr *hdr;
  77. int num_suites, res;
  78. u8 *pos, *count;
  79. u16 capab;
  80. u32 suite;
  81. hdr = (struct rsn_ie_hdr *) buf;
  82. hdr->elem_id = WLAN_EID_RSN;
  83. WPA_PUT_LE16(hdr->version, RSN_VERSION);
  84. pos = (u8 *) (hdr + 1);
  85. suite = wpa_cipher_to_suite(WPA_PROTO_RSN, conf->wpa_group);
  86. if (suite == 0) {
  87. wpa_printf(MSG_DEBUG, "Invalid group cipher (%d).",
  88. conf->wpa_group);
  89. return -1;
  90. }
  91. RSN_SELECTOR_PUT(pos, suite);
  92. pos += RSN_SELECTOR_LEN;
  93. num_suites = 0;
  94. count = pos;
  95. pos += 2;
  96. #ifdef CONFIG_RSN_TESTING
  97. if (rsn_testing) {
  98. RSN_SELECTOR_PUT(pos, RSN_SELECTOR(0x12, 0x34, 0x56, 1));
  99. pos += RSN_SELECTOR_LEN;
  100. num_suites++;
  101. }
  102. #endif /* CONFIG_RSN_TESTING */
  103. res = rsn_cipher_put_suites(pos, conf->rsn_pairwise);
  104. num_suites += res;
  105. pos += res * RSN_SELECTOR_LEN;
  106. #ifdef CONFIG_RSN_TESTING
  107. if (rsn_testing) {
  108. RSN_SELECTOR_PUT(pos, RSN_SELECTOR(0x12, 0x34, 0x56, 2));
  109. pos += RSN_SELECTOR_LEN;
  110. num_suites++;
  111. }
  112. #endif /* CONFIG_RSN_TESTING */
  113. if (num_suites == 0) {
  114. wpa_printf(MSG_DEBUG, "Invalid pairwise cipher (%d).",
  115. conf->rsn_pairwise);
  116. return -1;
  117. }
  118. WPA_PUT_LE16(count, num_suites);
  119. num_suites = 0;
  120. count = pos;
  121. pos += 2;
  122. #ifdef CONFIG_RSN_TESTING
  123. if (rsn_testing) {
  124. RSN_SELECTOR_PUT(pos, RSN_SELECTOR(0x12, 0x34, 0x56, 1));
  125. pos += RSN_SELECTOR_LEN;
  126. num_suites++;
  127. }
  128. #endif /* CONFIG_RSN_TESTING */
  129. if (conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
  130. RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_UNSPEC_802_1X);
  131. pos += RSN_SELECTOR_LEN;
  132. num_suites++;
  133. }
  134. if (conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK) {
  135. RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X);
  136. pos += RSN_SELECTOR_LEN;
  137. num_suites++;
  138. }
  139. #ifdef CONFIG_IEEE80211R_AP
  140. if (conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
  141. RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FT_802_1X);
  142. pos += RSN_SELECTOR_LEN;
  143. num_suites++;
  144. }
  145. if (conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_PSK) {
  146. RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FT_PSK);
  147. pos += RSN_SELECTOR_LEN;
  148. num_suites++;
  149. }
  150. #endif /* CONFIG_IEEE80211R_AP */
  151. #ifdef CONFIG_IEEE80211W
  152. if (conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
  153. RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_802_1X_SHA256);
  154. pos += RSN_SELECTOR_LEN;
  155. num_suites++;
  156. }
  157. if (conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
  158. RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_PSK_SHA256);
  159. pos += RSN_SELECTOR_LEN;
  160. num_suites++;
  161. }
  162. #endif /* CONFIG_IEEE80211W */
  163. #ifdef CONFIG_SAE
  164. if (conf->wpa_key_mgmt & WPA_KEY_MGMT_SAE) {
  165. RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_SAE);
  166. pos += RSN_SELECTOR_LEN;
  167. num_suites++;
  168. }
  169. if (conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_SAE) {
  170. RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FT_SAE);
  171. pos += RSN_SELECTOR_LEN;
  172. num_suites++;
  173. }
  174. #endif /* CONFIG_SAE */
  175. if (conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
  176. RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_802_1X_SUITE_B);
  177. pos += RSN_SELECTOR_LEN;
  178. num_suites++;
  179. }
  180. if (conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
  181. RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192);
  182. pos += RSN_SELECTOR_LEN;
  183. num_suites++;
  184. }
  185. #ifdef CONFIG_FILS
  186. if (conf->wpa_key_mgmt & WPA_KEY_MGMT_FILS_SHA256) {
  187. RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FILS_SHA256);
  188. pos += RSN_SELECTOR_LEN;
  189. num_suites++;
  190. }
  191. if (conf->wpa_key_mgmt & WPA_KEY_MGMT_FILS_SHA384) {
  192. RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FILS_SHA384);
  193. pos += RSN_SELECTOR_LEN;
  194. num_suites++;
  195. }
  196. #ifdef CONFIG_IEEE80211R_AP
  197. if (conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) {
  198. RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FT_FILS_SHA256);
  199. pos += RSN_SELECTOR_LEN;
  200. num_suites++;
  201. }
  202. if (conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) {
  203. RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FT_FILS_SHA384);
  204. pos += RSN_SELECTOR_LEN;
  205. num_suites++;
  206. }
  207. #endif /* CONFIG_IEEE80211R_AP */
  208. #endif /* CONFIG_FILS */
  209. #ifdef CONFIG_OWE
  210. if (conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) {
  211. RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_OWE);
  212. pos += RSN_SELECTOR_LEN;
  213. num_suites++;
  214. }
  215. #endif /* CONFIG_OWE */
  216. #ifdef CONFIG_DPP
  217. if (conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) {
  218. RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_DPP);
  219. pos += RSN_SELECTOR_LEN;
  220. num_suites++;
  221. }
  222. #endif /* CONFIG_DPP */
  223. #ifdef CONFIG_RSN_TESTING
  224. if (rsn_testing) {
  225. RSN_SELECTOR_PUT(pos, RSN_SELECTOR(0x12, 0x34, 0x56, 2));
  226. pos += RSN_SELECTOR_LEN;
  227. num_suites++;
  228. }
  229. #endif /* CONFIG_RSN_TESTING */
  230. if (num_suites == 0) {
  231. wpa_printf(MSG_DEBUG, "Invalid key management type (%d).",
  232. conf->wpa_key_mgmt);
  233. return -1;
  234. }
  235. WPA_PUT_LE16(count, num_suites);
  236. /* RSN Capabilities */
  237. capab = 0;
  238. if (conf->rsn_preauth)
  239. capab |= WPA_CAPABILITY_PREAUTH;
  240. if (conf->peerkey)
  241. capab |= WPA_CAPABILITY_PEERKEY_ENABLED;
  242. if (conf->wmm_enabled) {
  243. /* 4 PTKSA replay counters when using WMM */
  244. capab |= (RSN_NUM_REPLAY_COUNTERS_16 << 2);
  245. }
  246. #ifdef CONFIG_IEEE80211W
  247. if (conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
  248. capab |= WPA_CAPABILITY_MFPC;
  249. if (conf->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED)
  250. capab |= WPA_CAPABILITY_MFPR;
  251. }
  252. #endif /* CONFIG_IEEE80211W */
  253. #ifdef CONFIG_RSN_TESTING
  254. if (rsn_testing)
  255. capab |= BIT(8) | BIT(14) | BIT(15);
  256. #endif /* CONFIG_RSN_TESTING */
  257. WPA_PUT_LE16(pos, capab);
  258. pos += 2;
  259. if (pmkid) {
  260. if (2 + PMKID_LEN > buf + len - pos)
  261. return -1;
  262. /* PMKID Count */
  263. WPA_PUT_LE16(pos, 1);
  264. pos += 2;
  265. os_memcpy(pos, pmkid, PMKID_LEN);
  266. pos += PMKID_LEN;
  267. }
  268. #ifdef CONFIG_IEEE80211W
  269. if (conf->ieee80211w != NO_MGMT_FRAME_PROTECTION &&
  270. conf->group_mgmt_cipher != WPA_CIPHER_AES_128_CMAC) {
  271. if (2 + 4 > buf + len - pos)
  272. return -1;
  273. if (pmkid == NULL) {
  274. /* PMKID Count */
  275. WPA_PUT_LE16(pos, 0);
  276. pos += 2;
  277. }
  278. /* Management Group Cipher Suite */
  279. switch (conf->group_mgmt_cipher) {
  280. case WPA_CIPHER_AES_128_CMAC:
  281. RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_AES_128_CMAC);
  282. break;
  283. case WPA_CIPHER_BIP_GMAC_128:
  284. RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_BIP_GMAC_128);
  285. break;
  286. case WPA_CIPHER_BIP_GMAC_256:
  287. RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_BIP_GMAC_256);
  288. break;
  289. case WPA_CIPHER_BIP_CMAC_256:
  290. RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_BIP_CMAC_256);
  291. break;
  292. default:
  293. wpa_printf(MSG_DEBUG,
  294. "Invalid group management cipher (0x%x)",
  295. conf->group_mgmt_cipher);
  296. return -1;
  297. }
  298. pos += RSN_SELECTOR_LEN;
  299. }
  300. #endif /* CONFIG_IEEE80211W */
  301. #ifdef CONFIG_RSN_TESTING
  302. if (rsn_testing) {
  303. /*
  304. * Fill in any defined fields and add extra data to the end of
  305. * the element.
  306. */
  307. int pmkid_count_set = pmkid != NULL;
  308. if (conf->ieee80211w != NO_MGMT_FRAME_PROTECTION)
  309. pmkid_count_set = 1;
  310. /* PMKID Count */
  311. WPA_PUT_LE16(pos, 0);
  312. pos += 2;
  313. if (conf->ieee80211w == NO_MGMT_FRAME_PROTECTION) {
  314. /* Management Group Cipher Suite */
  315. RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_AES_128_CMAC);
  316. pos += RSN_SELECTOR_LEN;
  317. }
  318. os_memset(pos, 0x12, 17);
  319. pos += 17;
  320. }
  321. #endif /* CONFIG_RSN_TESTING */
  322. hdr->len = (pos - buf) - 2;
  323. return pos - buf;
  324. }
  325. static u8 * wpa_write_osen(struct wpa_auth_config *conf, u8 *eid)
  326. {
  327. u8 *len;
  328. u16 capab;
  329. *eid++ = WLAN_EID_VENDOR_SPECIFIC;
  330. len = eid++; /* to be filled */
  331. WPA_PUT_BE24(eid, OUI_WFA);
  332. eid += 3;
  333. *eid++ = HS20_OSEN_OUI_TYPE;
  334. /* Group Data Cipher Suite */
  335. RSN_SELECTOR_PUT(eid, RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED);
  336. eid += RSN_SELECTOR_LEN;
  337. /* Pairwise Cipher Suite Count and List */
  338. WPA_PUT_LE16(eid, 1);
  339. eid += 2;
  340. RSN_SELECTOR_PUT(eid, RSN_CIPHER_SUITE_CCMP);
  341. eid += RSN_SELECTOR_LEN;
  342. /* AKM Suite Count and List */
  343. WPA_PUT_LE16(eid, 1);
  344. eid += 2;
  345. RSN_SELECTOR_PUT(eid, RSN_AUTH_KEY_MGMT_OSEN);
  346. eid += RSN_SELECTOR_LEN;
  347. /* RSN Capabilities */
  348. capab = 0;
  349. if (conf->wmm_enabled) {
  350. /* 4 PTKSA replay counters when using WMM */
  351. capab |= (RSN_NUM_REPLAY_COUNTERS_16 << 2);
  352. }
  353. #ifdef CONFIG_IEEE80211W
  354. if (conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
  355. capab |= WPA_CAPABILITY_MFPC;
  356. if (conf->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED)
  357. capab |= WPA_CAPABILITY_MFPR;
  358. }
  359. #endif /* CONFIG_IEEE80211W */
  360. WPA_PUT_LE16(eid, capab);
  361. eid += 2;
  362. *len = eid - len - 1;
  363. return eid;
  364. }
  365. int wpa_auth_gen_wpa_ie(struct wpa_authenticator *wpa_auth)
  366. {
  367. u8 *pos, buf[128];
  368. int res;
  369. #ifdef CONFIG_TESTING_OPTIONS
  370. if (wpa_auth->conf.own_ie_override_len) {
  371. wpa_hexdump(MSG_DEBUG, "WPA: Forced own IE(s) for testing",
  372. wpa_auth->conf.own_ie_override,
  373. wpa_auth->conf.own_ie_override_len);
  374. os_free(wpa_auth->wpa_ie);
  375. wpa_auth->wpa_ie =
  376. os_malloc(wpa_auth->conf.own_ie_override_len);
  377. if (wpa_auth->wpa_ie == NULL)
  378. return -1;
  379. os_memcpy(wpa_auth->wpa_ie, wpa_auth->conf.own_ie_override,
  380. wpa_auth->conf.own_ie_override_len);
  381. wpa_auth->wpa_ie_len = wpa_auth->conf.own_ie_override_len;
  382. return 0;
  383. }
  384. #endif /* CONFIG_TESTING_OPTIONS */
  385. pos = buf;
  386. if (wpa_auth->conf.wpa == WPA_PROTO_OSEN) {
  387. pos = wpa_write_osen(&wpa_auth->conf, pos);
  388. }
  389. if (wpa_auth->conf.wpa & WPA_PROTO_RSN) {
  390. res = wpa_write_rsn_ie(&wpa_auth->conf,
  391. pos, buf + sizeof(buf) - pos, NULL);
  392. if (res < 0)
  393. return res;
  394. pos += res;
  395. }
  396. #ifdef CONFIG_IEEE80211R_AP
  397. if (wpa_key_mgmt_ft(wpa_auth->conf.wpa_key_mgmt)) {
  398. res = wpa_write_mdie(&wpa_auth->conf, pos,
  399. buf + sizeof(buf) - pos);
  400. if (res < 0)
  401. return res;
  402. pos += res;
  403. }
  404. #endif /* CONFIG_IEEE80211R_AP */
  405. if (wpa_auth->conf.wpa & WPA_PROTO_WPA) {
  406. res = wpa_write_wpa_ie(&wpa_auth->conf,
  407. pos, buf + sizeof(buf) - pos);
  408. if (res < 0)
  409. return res;
  410. pos += res;
  411. }
  412. os_free(wpa_auth->wpa_ie);
  413. wpa_auth->wpa_ie = os_malloc(pos - buf);
  414. if (wpa_auth->wpa_ie == NULL)
  415. return -1;
  416. os_memcpy(wpa_auth->wpa_ie, buf, pos - buf);
  417. wpa_auth->wpa_ie_len = pos - buf;
  418. return 0;
  419. }
  420. u8 * wpa_add_kde(u8 *pos, u32 kde, const u8 *data, size_t data_len,
  421. const u8 *data2, size_t data2_len)
  422. {
  423. *pos++ = WLAN_EID_VENDOR_SPECIFIC;
  424. *pos++ = RSN_SELECTOR_LEN + data_len + data2_len;
  425. RSN_SELECTOR_PUT(pos, kde);
  426. pos += RSN_SELECTOR_LEN;
  427. os_memcpy(pos, data, data_len);
  428. pos += data_len;
  429. if (data2) {
  430. os_memcpy(pos, data2, data2_len);
  431. pos += data2_len;
  432. }
  433. return pos;
  434. }
  435. struct wpa_auth_okc_iter_data {
  436. struct rsn_pmksa_cache_entry *pmksa;
  437. const u8 *aa;
  438. const u8 *spa;
  439. const u8 *pmkid;
  440. };
  441. static int wpa_auth_okc_iter(struct wpa_authenticator *a, void *ctx)
  442. {
  443. struct wpa_auth_okc_iter_data *data = ctx;
  444. data->pmksa = pmksa_cache_get_okc(a->pmksa, data->aa, data->spa,
  445. data->pmkid);
  446. if (data->pmksa)
  447. return 1;
  448. return 0;
  449. }
  450. int wpa_validate_wpa_ie(struct wpa_authenticator *wpa_auth,
  451. struct wpa_state_machine *sm,
  452. const u8 *wpa_ie, size_t wpa_ie_len,
  453. const u8 *mdie, size_t mdie_len,
  454. const u8 *owe_dh, size_t owe_dh_len)
  455. {
  456. struct wpa_ie_data data;
  457. int ciphers, key_mgmt, res, version;
  458. u32 selector;
  459. size_t i;
  460. const u8 *pmkid = NULL;
  461. if (wpa_auth == NULL || sm == NULL)
  462. return WPA_NOT_ENABLED;
  463. if (wpa_ie == NULL || wpa_ie_len < 1)
  464. return WPA_INVALID_IE;
  465. if (wpa_ie[0] == WLAN_EID_RSN)
  466. version = WPA_PROTO_RSN;
  467. else
  468. version = WPA_PROTO_WPA;
  469. if (!(wpa_auth->conf.wpa & version)) {
  470. wpa_printf(MSG_DEBUG, "Invalid WPA proto (%d) from " MACSTR,
  471. version, MAC2STR(sm->addr));
  472. return WPA_INVALID_PROTO;
  473. }
  474. if (version == WPA_PROTO_RSN) {
  475. res = wpa_parse_wpa_ie_rsn(wpa_ie, wpa_ie_len, &data);
  476. selector = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X;
  477. if (0) {
  478. }
  479. else if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192)
  480. selector = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192;
  481. else if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B)
  482. selector = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B;
  483. #ifdef CONFIG_FILS
  484. #ifdef CONFIG_IEEE80211R_AP
  485. else if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384)
  486. selector = RSN_AUTH_KEY_MGMT_FT_FILS_SHA384;
  487. else if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256)
  488. selector = RSN_AUTH_KEY_MGMT_FT_FILS_SHA256;
  489. #endif /* CONFIG_IEEE80211R_AP */
  490. else if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA384)
  491. selector = RSN_AUTH_KEY_MGMT_FILS_SHA384;
  492. else if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA256)
  493. selector = RSN_AUTH_KEY_MGMT_FILS_SHA256;
  494. #endif /* CONFIG_FILS */
  495. #ifdef CONFIG_IEEE80211R_AP
  496. else if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X)
  497. selector = RSN_AUTH_KEY_MGMT_FT_802_1X;
  498. else if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK)
  499. selector = RSN_AUTH_KEY_MGMT_FT_PSK;
  500. #endif /* CONFIG_IEEE80211R_AP */
  501. #ifdef CONFIG_IEEE80211W
  502. else if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256)
  503. selector = RSN_AUTH_KEY_MGMT_802_1X_SHA256;
  504. else if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256)
  505. selector = RSN_AUTH_KEY_MGMT_PSK_SHA256;
  506. #endif /* CONFIG_IEEE80211W */
  507. #ifdef CONFIG_SAE
  508. else if (data.key_mgmt & WPA_KEY_MGMT_SAE)
  509. selector = RSN_AUTH_KEY_MGMT_SAE;
  510. else if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE)
  511. selector = RSN_AUTH_KEY_MGMT_FT_SAE;
  512. #endif /* CONFIG_SAE */
  513. else if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X)
  514. selector = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X;
  515. else if (data.key_mgmt & WPA_KEY_MGMT_PSK)
  516. selector = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X;
  517. #ifdef CONFIG_OWE
  518. else if (data.key_mgmt & WPA_KEY_MGMT_OWE)
  519. selector = RSN_AUTH_KEY_MGMT_OWE;
  520. #endif /* CONFIG_OWE */
  521. #ifdef CONFIG_DPP
  522. else if (data.key_mgmt & WPA_KEY_MGMT_DPP)
  523. selector = RSN_AUTH_KEY_MGMT_DPP;
  524. #endif /* CONFIG_DPP */
  525. wpa_auth->dot11RSNAAuthenticationSuiteSelected = selector;
  526. selector = wpa_cipher_to_suite(WPA_PROTO_RSN,
  527. data.pairwise_cipher);
  528. if (!selector)
  529. selector = RSN_CIPHER_SUITE_CCMP;
  530. wpa_auth->dot11RSNAPairwiseCipherSelected = selector;
  531. selector = wpa_cipher_to_suite(WPA_PROTO_RSN,
  532. data.group_cipher);
  533. if (!selector)
  534. selector = RSN_CIPHER_SUITE_CCMP;
  535. wpa_auth->dot11RSNAGroupCipherSelected = selector;
  536. } else {
  537. res = wpa_parse_wpa_ie_wpa(wpa_ie, wpa_ie_len, &data);
  538. selector = WPA_AUTH_KEY_MGMT_UNSPEC_802_1X;
  539. if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X)
  540. selector = WPA_AUTH_KEY_MGMT_UNSPEC_802_1X;
  541. else if (data.key_mgmt & WPA_KEY_MGMT_PSK)
  542. selector = WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X;
  543. wpa_auth->dot11RSNAAuthenticationSuiteSelected = selector;
  544. selector = wpa_cipher_to_suite(WPA_PROTO_WPA,
  545. data.pairwise_cipher);
  546. if (!selector)
  547. selector = RSN_CIPHER_SUITE_TKIP;
  548. wpa_auth->dot11RSNAPairwiseCipherSelected = selector;
  549. selector = wpa_cipher_to_suite(WPA_PROTO_WPA,
  550. data.group_cipher);
  551. if (!selector)
  552. selector = WPA_CIPHER_SUITE_TKIP;
  553. wpa_auth->dot11RSNAGroupCipherSelected = selector;
  554. }
  555. if (res) {
  556. wpa_printf(MSG_DEBUG, "Failed to parse WPA/RSN IE from "
  557. MACSTR " (res=%d)", MAC2STR(sm->addr), res);
  558. wpa_hexdump(MSG_DEBUG, "WPA/RSN IE", wpa_ie, wpa_ie_len);
  559. return WPA_INVALID_IE;
  560. }
  561. if (data.group_cipher != wpa_auth->conf.wpa_group) {
  562. wpa_printf(MSG_DEBUG, "Invalid WPA group cipher (0x%x) from "
  563. MACSTR, data.group_cipher, MAC2STR(sm->addr));
  564. return WPA_INVALID_GROUP;
  565. }
  566. key_mgmt = data.key_mgmt & wpa_auth->conf.wpa_key_mgmt;
  567. if (!key_mgmt) {
  568. wpa_printf(MSG_DEBUG, "Invalid WPA key mgmt (0x%x) from "
  569. MACSTR, data.key_mgmt, MAC2STR(sm->addr));
  570. return WPA_INVALID_AKMP;
  571. }
  572. if (0) {
  573. }
  574. else if (key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192)
  575. sm->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_SUITE_B_192;
  576. else if (key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B)
  577. sm->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_SUITE_B;
  578. #ifdef CONFIG_FILS
  579. #ifdef CONFIG_IEEE80211R_AP
  580. else if (key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384)
  581. sm->wpa_key_mgmt = WPA_KEY_MGMT_FT_FILS_SHA384;
  582. else if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256)
  583. sm->wpa_key_mgmt = WPA_KEY_MGMT_FT_FILS_SHA256;
  584. #endif /* CONFIG_IEEE80211R_AP */
  585. else if (key_mgmt & WPA_KEY_MGMT_FILS_SHA384)
  586. sm->wpa_key_mgmt = WPA_KEY_MGMT_FILS_SHA384;
  587. else if (key_mgmt & WPA_KEY_MGMT_FILS_SHA256)
  588. sm->wpa_key_mgmt = WPA_KEY_MGMT_FILS_SHA256;
  589. #endif /* CONFIG_FILS */
  590. #ifdef CONFIG_IEEE80211R_AP
  591. else if (key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X)
  592. sm->wpa_key_mgmt = WPA_KEY_MGMT_FT_IEEE8021X;
  593. else if (key_mgmt & WPA_KEY_MGMT_FT_PSK)
  594. sm->wpa_key_mgmt = WPA_KEY_MGMT_FT_PSK;
  595. #endif /* CONFIG_IEEE80211R_AP */
  596. #ifdef CONFIG_IEEE80211W
  597. else if (key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256)
  598. sm->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_SHA256;
  599. else if (key_mgmt & WPA_KEY_MGMT_PSK_SHA256)
  600. sm->wpa_key_mgmt = WPA_KEY_MGMT_PSK_SHA256;
  601. #endif /* CONFIG_IEEE80211W */
  602. #ifdef CONFIG_SAE
  603. else if (key_mgmt & WPA_KEY_MGMT_SAE)
  604. sm->wpa_key_mgmt = WPA_KEY_MGMT_SAE;
  605. else if (key_mgmt & WPA_KEY_MGMT_FT_SAE)
  606. sm->wpa_key_mgmt = WPA_KEY_MGMT_FT_SAE;
  607. #endif /* CONFIG_SAE */
  608. else if (key_mgmt & WPA_KEY_MGMT_IEEE8021X)
  609. sm->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X;
  610. #ifdef CONFIG_OWE
  611. else if (key_mgmt & WPA_KEY_MGMT_OWE)
  612. sm->wpa_key_mgmt = WPA_KEY_MGMT_OWE;
  613. #endif /* CONFIG_OWE */
  614. #ifdef CONFIG_DPP
  615. else if (key_mgmt & WPA_KEY_MGMT_DPP)
  616. sm->wpa_key_mgmt = WPA_KEY_MGMT_DPP;
  617. #endif /* CONFIG_DPP */
  618. else
  619. sm->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
  620. if (version == WPA_PROTO_RSN)
  621. ciphers = data.pairwise_cipher & wpa_auth->conf.rsn_pairwise;
  622. else
  623. ciphers = data.pairwise_cipher & wpa_auth->conf.wpa_pairwise;
  624. if (!ciphers) {
  625. wpa_printf(MSG_DEBUG, "Invalid %s pairwise cipher (0x%x) "
  626. "from " MACSTR,
  627. version == WPA_PROTO_RSN ? "RSN" : "WPA",
  628. data.pairwise_cipher, MAC2STR(sm->addr));
  629. return WPA_INVALID_PAIRWISE;
  630. }
  631. #ifdef CONFIG_IEEE80211W
  632. if (wpa_auth->conf.ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
  633. if (!(data.capabilities & WPA_CAPABILITY_MFPC)) {
  634. wpa_printf(MSG_DEBUG, "Management frame protection "
  635. "required, but client did not enable it");
  636. return WPA_MGMT_FRAME_PROTECTION_VIOLATION;
  637. }
  638. if (ciphers & WPA_CIPHER_TKIP) {
  639. wpa_printf(MSG_DEBUG, "Management frame protection "
  640. "cannot use TKIP");
  641. return WPA_MGMT_FRAME_PROTECTION_VIOLATION;
  642. }
  643. if (data.mgmt_group_cipher != wpa_auth->conf.group_mgmt_cipher)
  644. {
  645. wpa_printf(MSG_DEBUG, "Unsupported management group "
  646. "cipher %d", data.mgmt_group_cipher);
  647. return WPA_INVALID_MGMT_GROUP_CIPHER;
  648. }
  649. }
  650. if (wpa_auth->conf.ieee80211w == NO_MGMT_FRAME_PROTECTION ||
  651. !(data.capabilities & WPA_CAPABILITY_MFPC))
  652. sm->mgmt_frame_prot = 0;
  653. else
  654. sm->mgmt_frame_prot = 1;
  655. #endif /* CONFIG_IEEE80211W */
  656. #ifdef CONFIG_IEEE80211R_AP
  657. if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
  658. if (mdie == NULL || mdie_len < MOBILITY_DOMAIN_ID_LEN + 1) {
  659. wpa_printf(MSG_DEBUG, "RSN: Trying to use FT, but "
  660. "MDIE not included");
  661. return WPA_INVALID_MDIE;
  662. }
  663. if (os_memcmp(mdie, wpa_auth->conf.mobility_domain,
  664. MOBILITY_DOMAIN_ID_LEN) != 0) {
  665. wpa_hexdump(MSG_DEBUG, "RSN: Attempted to use unknown "
  666. "MDIE", mdie, MOBILITY_DOMAIN_ID_LEN);
  667. return WPA_INVALID_MDIE;
  668. }
  669. } else if (mdie != NULL) {
  670. wpa_printf(MSG_DEBUG,
  671. "RSN: Trying to use non-FT AKM suite, but MDIE included");
  672. return WPA_INVALID_AKMP;
  673. }
  674. #endif /* CONFIG_IEEE80211R_AP */
  675. #ifdef CONFIG_OWE
  676. if (sm->wpa_key_mgmt == WPA_KEY_MGMT_OWE && !owe_dh) {
  677. wpa_printf(MSG_DEBUG,
  678. "OWE: No Diffie-Hellman Parameter element");
  679. return WPA_INVALID_AKMP;
  680. }
  681. if (sm->wpa_key_mgmt != WPA_KEY_MGMT_OWE && owe_dh) {
  682. wpa_printf(MSG_DEBUG,
  683. "OWE: Unexpected Diffie-Hellman Parameter element with non-OWE AKM");
  684. return WPA_INVALID_AKMP;
  685. }
  686. #endif /* CONFIG_OWE */
  687. sm->pairwise = wpa_pick_pairwise_cipher(ciphers, 0);
  688. if (sm->pairwise < 0)
  689. return WPA_INVALID_PAIRWISE;
  690. /* TODO: clear WPA/WPA2 state if STA changes from one to another */
  691. if (wpa_ie[0] == WLAN_EID_RSN)
  692. sm->wpa = WPA_VERSION_WPA2;
  693. else
  694. sm->wpa = WPA_VERSION_WPA;
  695. sm->pmksa = NULL;
  696. for (i = 0; i < data.num_pmkid; i++) {
  697. wpa_hexdump(MSG_DEBUG, "RSN IE: STA PMKID",
  698. &data.pmkid[i * PMKID_LEN], PMKID_LEN);
  699. sm->pmksa = pmksa_cache_auth_get(wpa_auth->pmksa, sm->addr,
  700. &data.pmkid[i * PMKID_LEN]);
  701. if (sm->pmksa) {
  702. pmkid = sm->pmksa->pmkid;
  703. break;
  704. }
  705. }
  706. for (i = 0; sm->pmksa == NULL && wpa_auth->conf.okc &&
  707. i < data.num_pmkid; i++) {
  708. struct wpa_auth_okc_iter_data idata;
  709. idata.pmksa = NULL;
  710. idata.aa = wpa_auth->addr;
  711. idata.spa = sm->addr;
  712. idata.pmkid = &data.pmkid[i * PMKID_LEN];
  713. wpa_auth_for_each_auth(wpa_auth, wpa_auth_okc_iter, &idata);
  714. if (idata.pmksa) {
  715. wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG,
  716. "OKC match for PMKID");
  717. sm->pmksa = pmksa_cache_add_okc(wpa_auth->pmksa,
  718. idata.pmksa,
  719. wpa_auth->addr,
  720. idata.pmkid);
  721. pmkid = idata.pmkid;
  722. break;
  723. }
  724. }
  725. if (sm->pmksa && pmkid) {
  726. struct vlan_description *vlan;
  727. vlan = sm->pmksa->vlan_desc;
  728. wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG,
  729. "PMKID found from PMKSA cache eap_type=%d vlan=%d%s",
  730. sm->pmksa->eap_type_authsrv,
  731. vlan ? vlan->untagged : 0,
  732. (vlan && vlan->tagged[0]) ? "+" : "");
  733. os_memcpy(wpa_auth->dot11RSNAPMKIDUsed, pmkid, PMKID_LEN);
  734. }
  735. #ifdef CONFIG_DPP
  736. if (sm->wpa_key_mgmt == WPA_KEY_MGMT_DPP && !sm->pmksa) {
  737. wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG,
  738. "No PMKSA cache entry found for DPP");
  739. return WPA_INVALID_PMKID;
  740. }
  741. #endif /* CONFIG_DPP */
  742. if (sm->wpa_ie == NULL || sm->wpa_ie_len < wpa_ie_len) {
  743. os_free(sm->wpa_ie);
  744. sm->wpa_ie = os_malloc(wpa_ie_len);
  745. if (sm->wpa_ie == NULL)
  746. return WPA_ALLOC_FAIL;
  747. }
  748. os_memcpy(sm->wpa_ie, wpa_ie, wpa_ie_len);
  749. sm->wpa_ie_len = wpa_ie_len;
  750. return WPA_IE_OK;
  751. }
  752. #ifdef CONFIG_HS20
  753. int wpa_validate_osen(struct wpa_authenticator *wpa_auth,
  754. struct wpa_state_machine *sm,
  755. const u8 *osen_ie, size_t osen_ie_len)
  756. {
  757. if (wpa_auth == NULL || sm == NULL)
  758. return -1;
  759. /* TODO: parse OSEN element */
  760. sm->wpa_key_mgmt = WPA_KEY_MGMT_OSEN;
  761. sm->mgmt_frame_prot = 1;
  762. sm->pairwise = WPA_CIPHER_CCMP;
  763. sm->wpa = WPA_VERSION_WPA2;
  764. if (sm->wpa_ie == NULL || sm->wpa_ie_len < osen_ie_len) {
  765. os_free(sm->wpa_ie);
  766. sm->wpa_ie = os_malloc(osen_ie_len);
  767. if (sm->wpa_ie == NULL)
  768. return -1;
  769. }
  770. os_memcpy(sm->wpa_ie, osen_ie, osen_ie_len);
  771. sm->wpa_ie_len = osen_ie_len;
  772. return 0;
  773. }
  774. #endif /* CONFIG_HS20 */
  775. /**
  776. * wpa_parse_generic - Parse EAPOL-Key Key Data Generic IEs
  777. * @pos: Pointer to the IE header
  778. * @end: Pointer to the end of the Key Data buffer
  779. * @ie: Pointer to parsed IE data
  780. * Returns: 0 on success, 1 if end mark is found, -1 on failure
  781. */
  782. static int wpa_parse_generic(const u8 *pos, const u8 *end,
  783. struct wpa_eapol_ie_parse *ie)
  784. {
  785. if (pos[1] == 0)
  786. return 1;
  787. if (pos[1] >= 6 &&
  788. RSN_SELECTOR_GET(pos + 2) == WPA_OUI_TYPE &&
  789. pos[2 + WPA_SELECTOR_LEN] == 1 &&
  790. pos[2 + WPA_SELECTOR_LEN + 1] == 0) {
  791. ie->wpa_ie = pos;
  792. ie->wpa_ie_len = pos[1] + 2;
  793. return 0;
  794. }
  795. if (pos[1] >= 4 && WPA_GET_BE32(pos + 2) == OSEN_IE_VENDOR_TYPE) {
  796. ie->osen = pos;
  797. ie->osen_len = pos[1] + 2;
  798. return 0;
  799. }
  800. if (1 + RSN_SELECTOR_LEN < end - pos &&
  801. pos[1] >= RSN_SELECTOR_LEN + PMKID_LEN &&
  802. RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_PMKID) {
  803. ie->pmkid = pos + 2 + RSN_SELECTOR_LEN;
  804. return 0;
  805. }
  806. if (pos[1] > RSN_SELECTOR_LEN + 2 &&
  807. RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_GROUPKEY) {
  808. ie->gtk = pos + 2 + RSN_SELECTOR_LEN;
  809. ie->gtk_len = pos[1] - RSN_SELECTOR_LEN;
  810. return 0;
  811. }
  812. if (pos[1] > RSN_SELECTOR_LEN + 2 &&
  813. RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_MAC_ADDR) {
  814. ie->mac_addr = pos + 2 + RSN_SELECTOR_LEN;
  815. ie->mac_addr_len = pos[1] - RSN_SELECTOR_LEN;
  816. return 0;
  817. }
  818. #ifdef CONFIG_PEERKEY
  819. if (pos[1] > RSN_SELECTOR_LEN + 2 &&
  820. RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_SMK) {
  821. ie->smk = pos + 2 + RSN_SELECTOR_LEN;
  822. ie->smk_len = pos[1] - RSN_SELECTOR_LEN;
  823. return 0;
  824. }
  825. if (pos[1] > RSN_SELECTOR_LEN + 2 &&
  826. RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_NONCE) {
  827. ie->nonce = pos + 2 + RSN_SELECTOR_LEN;
  828. ie->nonce_len = pos[1] - RSN_SELECTOR_LEN;
  829. return 0;
  830. }
  831. if (pos[1] > RSN_SELECTOR_LEN + 2 &&
  832. RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_LIFETIME) {
  833. ie->lifetime = pos + 2 + RSN_SELECTOR_LEN;
  834. ie->lifetime_len = pos[1] - RSN_SELECTOR_LEN;
  835. return 0;
  836. }
  837. if (pos[1] > RSN_SELECTOR_LEN + 2 &&
  838. RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_ERROR) {
  839. ie->error = pos + 2 + RSN_SELECTOR_LEN;
  840. ie->error_len = pos[1] - RSN_SELECTOR_LEN;
  841. return 0;
  842. }
  843. #endif /* CONFIG_PEERKEY */
  844. #ifdef CONFIG_IEEE80211W
  845. if (pos[1] > RSN_SELECTOR_LEN + 2 &&
  846. RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_IGTK) {
  847. ie->igtk = pos + 2 + RSN_SELECTOR_LEN;
  848. ie->igtk_len = pos[1] - RSN_SELECTOR_LEN;
  849. return 0;
  850. }
  851. #endif /* CONFIG_IEEE80211W */
  852. #ifdef CONFIG_P2P
  853. if (pos[1] >= RSN_SELECTOR_LEN + 1 &&
  854. RSN_SELECTOR_GET(pos + 2) == WFA_KEY_DATA_IP_ADDR_REQ) {
  855. ie->ip_addr_req = pos + 2 + RSN_SELECTOR_LEN;
  856. wpa_hexdump(MSG_DEBUG, "WPA: IP Address Request in EAPOL-Key",
  857. ie->ip_addr_req, pos[1] - RSN_SELECTOR_LEN);
  858. return 0;
  859. }
  860. if (pos[1] >= RSN_SELECTOR_LEN + 3 * 4 &&
  861. RSN_SELECTOR_GET(pos + 2) == WFA_KEY_DATA_IP_ADDR_ALLOC) {
  862. ie->ip_addr_alloc = pos + 2 + RSN_SELECTOR_LEN;
  863. wpa_hexdump(MSG_DEBUG,
  864. "WPA: IP Address Allocation in EAPOL-Key",
  865. ie->ip_addr_alloc, pos[1] - RSN_SELECTOR_LEN);
  866. return 0;
  867. }
  868. #endif /* CONFIG_P2P */
  869. return 0;
  870. }
  871. /**
  872. * wpa_parse_kde_ies - Parse EAPOL-Key Key Data IEs
  873. * @buf: Pointer to the Key Data buffer
  874. * @len: Key Data Length
  875. * @ie: Pointer to parsed IE data
  876. * Returns: 0 on success, -1 on failure
  877. */
  878. int wpa_parse_kde_ies(const u8 *buf, size_t len, struct wpa_eapol_ie_parse *ie)
  879. {
  880. const u8 *pos, *end;
  881. int ret = 0;
  882. os_memset(ie, 0, sizeof(*ie));
  883. for (pos = buf, end = pos + len; end - pos > 1; pos += 2 + pos[1]) {
  884. if (pos[0] == 0xdd &&
  885. ((pos == buf + len - 1) || pos[1] == 0)) {
  886. /* Ignore padding */
  887. break;
  888. }
  889. if (2 + pos[1] > end - pos) {
  890. wpa_printf(MSG_DEBUG, "WPA: EAPOL-Key Key Data "
  891. "underflow (ie=%d len=%d pos=%d)",
  892. pos[0], pos[1], (int) (pos - buf));
  893. wpa_hexdump_key(MSG_DEBUG, "WPA: Key Data",
  894. buf, len);
  895. ret = -1;
  896. break;
  897. }
  898. if (*pos == WLAN_EID_RSN) {
  899. ie->rsn_ie = pos;
  900. ie->rsn_ie_len = pos[1] + 2;
  901. #ifdef CONFIG_IEEE80211R_AP
  902. } else if (*pos == WLAN_EID_MOBILITY_DOMAIN) {
  903. ie->mdie = pos;
  904. ie->mdie_len = pos[1] + 2;
  905. } else if (*pos == WLAN_EID_FAST_BSS_TRANSITION) {
  906. ie->ftie = pos;
  907. ie->ftie_len = pos[1] + 2;
  908. #endif /* CONFIG_IEEE80211R_AP */
  909. } else if (*pos == WLAN_EID_VENDOR_SPECIFIC) {
  910. ret = wpa_parse_generic(pos, end, ie);
  911. if (ret < 0)
  912. break;
  913. if (ret > 0) {
  914. ret = 0;
  915. break;
  916. }
  917. } else {
  918. wpa_hexdump(MSG_DEBUG, "WPA: Unrecognized EAPOL-Key "
  919. "Key Data IE", pos, 2 + pos[1]);
  920. }
  921. }
  922. return ret;
  923. }
  924. int wpa_auth_uses_mfp(struct wpa_state_machine *sm)
  925. {
  926. return sm ? sm->mgmt_frame_prot : 0;
  927. }
  928. #ifdef CONFIG_OWE
  929. u8 * wpa_auth_write_assoc_resp_owe(struct wpa_state_machine *sm,
  930. u8 *pos, size_t max_len,
  931. const u8 *req_ies, size_t req_ies_len)
  932. {
  933. int res;
  934. res = wpa_write_rsn_ie(&sm->wpa_auth->conf, pos, max_len, NULL);
  935. if (res < 0)
  936. return pos;
  937. return pos + res;
  938. }
  939. #endif /* CONFIG_OWE */