wpa_ie.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. /*
  2. * wpa_supplicant - WPA/RSN IE and KDE processing
  3. * Copyright (c) 2003-2008, Jouni Malinen <j@w1.fi>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. */
  14. #include "includes.h"
  15. #include "common.h"
  16. #include "wpa.h"
  17. #include "pmksa_cache.h"
  18. #include "common/ieee802_11_defs.h"
  19. #include "wpa_i.h"
  20. #include "wpa_ie.h"
  21. static int wpa_selector_to_bitfield(const u8 *s)
  22. {
  23. if (RSN_SELECTOR_GET(s) == WPA_CIPHER_SUITE_NONE)
  24. return WPA_CIPHER_NONE;
  25. if (RSN_SELECTOR_GET(s) == WPA_CIPHER_SUITE_WEP40)
  26. return WPA_CIPHER_WEP40;
  27. if (RSN_SELECTOR_GET(s) == WPA_CIPHER_SUITE_TKIP)
  28. return WPA_CIPHER_TKIP;
  29. if (RSN_SELECTOR_GET(s) == WPA_CIPHER_SUITE_CCMP)
  30. return WPA_CIPHER_CCMP;
  31. if (RSN_SELECTOR_GET(s) == WPA_CIPHER_SUITE_WEP104)
  32. return WPA_CIPHER_WEP104;
  33. return 0;
  34. }
  35. static int wpa_key_mgmt_to_bitfield(const u8 *s)
  36. {
  37. if (RSN_SELECTOR_GET(s) == WPA_AUTH_KEY_MGMT_UNSPEC_802_1X)
  38. return WPA_KEY_MGMT_IEEE8021X;
  39. if (RSN_SELECTOR_GET(s) == WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X)
  40. return WPA_KEY_MGMT_PSK;
  41. if (RSN_SELECTOR_GET(s) == WPA_AUTH_KEY_MGMT_NONE)
  42. return WPA_KEY_MGMT_WPA_NONE;
  43. return 0;
  44. }
  45. static int wpa_parse_wpa_ie_wpa(const u8 *wpa_ie, size_t wpa_ie_len,
  46. struct wpa_ie_data *data)
  47. {
  48. const struct wpa_ie_hdr *hdr;
  49. const u8 *pos;
  50. int left;
  51. int i, count;
  52. os_memset(data, 0, sizeof(*data));
  53. data->proto = WPA_PROTO_WPA;
  54. data->pairwise_cipher = WPA_CIPHER_TKIP;
  55. data->group_cipher = WPA_CIPHER_TKIP;
  56. data->key_mgmt = WPA_KEY_MGMT_IEEE8021X;
  57. data->capabilities = 0;
  58. data->pmkid = NULL;
  59. data->num_pmkid = 0;
  60. data->mgmt_group_cipher = 0;
  61. if (wpa_ie_len == 0) {
  62. /* No WPA IE - fail silently */
  63. return -1;
  64. }
  65. if (wpa_ie_len < sizeof(struct wpa_ie_hdr)) {
  66. wpa_printf(MSG_DEBUG, "%s: ie len too short %lu",
  67. __func__, (unsigned long) wpa_ie_len);
  68. return -1;
  69. }
  70. hdr = (const struct wpa_ie_hdr *) wpa_ie;
  71. if (hdr->elem_id != WLAN_EID_VENDOR_SPECIFIC ||
  72. hdr->len != wpa_ie_len - 2 ||
  73. RSN_SELECTOR_GET(hdr->oui) != WPA_OUI_TYPE ||
  74. WPA_GET_LE16(hdr->version) != WPA_VERSION) {
  75. wpa_printf(MSG_DEBUG, "%s: malformed ie or unknown version",
  76. __func__);
  77. return -1;
  78. }
  79. pos = (const u8 *) (hdr + 1);
  80. left = wpa_ie_len - sizeof(*hdr);
  81. if (left >= WPA_SELECTOR_LEN) {
  82. data->group_cipher = wpa_selector_to_bitfield(pos);
  83. pos += WPA_SELECTOR_LEN;
  84. left -= WPA_SELECTOR_LEN;
  85. } else if (left > 0) {
  86. wpa_printf(MSG_DEBUG, "%s: ie length mismatch, %u too much",
  87. __func__, left);
  88. return -1;
  89. }
  90. if (left >= 2) {
  91. data->pairwise_cipher = 0;
  92. count = WPA_GET_LE16(pos);
  93. pos += 2;
  94. left -= 2;
  95. if (count == 0 || left < count * WPA_SELECTOR_LEN) {
  96. wpa_printf(MSG_DEBUG, "%s: ie count botch (pairwise), "
  97. "count %u left %u", __func__, count, left);
  98. return -1;
  99. }
  100. for (i = 0; i < count; i++) {
  101. data->pairwise_cipher |= wpa_selector_to_bitfield(pos);
  102. pos += WPA_SELECTOR_LEN;
  103. left -= WPA_SELECTOR_LEN;
  104. }
  105. } else if (left == 1) {
  106. wpa_printf(MSG_DEBUG, "%s: ie too short (for key mgmt)",
  107. __func__);
  108. return -1;
  109. }
  110. if (left >= 2) {
  111. data->key_mgmt = 0;
  112. count = WPA_GET_LE16(pos);
  113. pos += 2;
  114. left -= 2;
  115. if (count == 0 || left < count * WPA_SELECTOR_LEN) {
  116. wpa_printf(MSG_DEBUG, "%s: ie count botch (key mgmt), "
  117. "count %u left %u", __func__, count, left);
  118. return -1;
  119. }
  120. for (i = 0; i < count; i++) {
  121. data->key_mgmt |= wpa_key_mgmt_to_bitfield(pos);
  122. pos += WPA_SELECTOR_LEN;
  123. left -= WPA_SELECTOR_LEN;
  124. }
  125. } else if (left == 1) {
  126. wpa_printf(MSG_DEBUG, "%s: ie too short (for capabilities)",
  127. __func__);
  128. return -1;
  129. }
  130. if (left >= 2) {
  131. data->capabilities = WPA_GET_LE16(pos);
  132. pos += 2;
  133. left -= 2;
  134. }
  135. if (left > 0) {
  136. wpa_printf(MSG_DEBUG, "%s: ie has %u trailing bytes - ignored",
  137. __func__, left);
  138. }
  139. return 0;
  140. }
  141. /**
  142. * wpa_parse_wpa_ie - Parse WPA/RSN IE
  143. * @wpa_ie: Pointer to WPA or RSN IE
  144. * @wpa_ie_len: Length of the WPA/RSN IE
  145. * @data: Pointer to data area for parsing results
  146. * Returns: 0 on success, -1 on failure
  147. *
  148. * Parse the contents of WPA or RSN IE and write the parsed data into data.
  149. */
  150. int wpa_parse_wpa_ie(const u8 *wpa_ie, size_t wpa_ie_len,
  151. struct wpa_ie_data *data)
  152. {
  153. if (wpa_ie_len >= 1 && wpa_ie[0] == WLAN_EID_RSN)
  154. return wpa_parse_wpa_ie_rsn(wpa_ie, wpa_ie_len, data);
  155. else
  156. return wpa_parse_wpa_ie_wpa(wpa_ie, wpa_ie_len, data);
  157. }
  158. static int wpa_gen_wpa_ie_wpa(u8 *wpa_ie, size_t wpa_ie_len,
  159. int pairwise_cipher, int group_cipher,
  160. int key_mgmt)
  161. {
  162. u8 *pos;
  163. struct wpa_ie_hdr *hdr;
  164. if (wpa_ie_len < sizeof(*hdr) + WPA_SELECTOR_LEN +
  165. 2 + WPA_SELECTOR_LEN + 2 + WPA_SELECTOR_LEN)
  166. return -1;
  167. hdr = (struct wpa_ie_hdr *) wpa_ie;
  168. hdr->elem_id = WLAN_EID_VENDOR_SPECIFIC;
  169. RSN_SELECTOR_PUT(hdr->oui, WPA_OUI_TYPE);
  170. WPA_PUT_LE16(hdr->version, WPA_VERSION);
  171. pos = (u8 *) (hdr + 1);
  172. if (group_cipher == WPA_CIPHER_CCMP) {
  173. RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_CCMP);
  174. } else if (group_cipher == WPA_CIPHER_TKIP) {
  175. RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_TKIP);
  176. } else if (group_cipher == WPA_CIPHER_WEP104) {
  177. RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_WEP104);
  178. } else if (group_cipher == WPA_CIPHER_WEP40) {
  179. RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_WEP40);
  180. } else {
  181. wpa_printf(MSG_WARNING, "Invalid group cipher (%d).",
  182. group_cipher);
  183. return -1;
  184. }
  185. pos += WPA_SELECTOR_LEN;
  186. *pos++ = 1;
  187. *pos++ = 0;
  188. if (pairwise_cipher == WPA_CIPHER_CCMP) {
  189. RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_CCMP);
  190. } else if (pairwise_cipher == WPA_CIPHER_TKIP) {
  191. RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_TKIP);
  192. } else if (pairwise_cipher == WPA_CIPHER_NONE) {
  193. RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_NONE);
  194. } else {
  195. wpa_printf(MSG_WARNING, "Invalid pairwise cipher (%d).",
  196. pairwise_cipher);
  197. return -1;
  198. }
  199. pos += WPA_SELECTOR_LEN;
  200. *pos++ = 1;
  201. *pos++ = 0;
  202. if (key_mgmt == WPA_KEY_MGMT_IEEE8021X) {
  203. RSN_SELECTOR_PUT(pos, WPA_AUTH_KEY_MGMT_UNSPEC_802_1X);
  204. } else if (key_mgmt == WPA_KEY_MGMT_PSK) {
  205. RSN_SELECTOR_PUT(pos, WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X);
  206. } else if (key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  207. RSN_SELECTOR_PUT(pos, WPA_AUTH_KEY_MGMT_NONE);
  208. } else {
  209. wpa_printf(MSG_WARNING, "Invalid key management type (%d).",
  210. key_mgmt);
  211. return -1;
  212. }
  213. pos += WPA_SELECTOR_LEN;
  214. /* WPA Capabilities; use defaults, so no need to include it */
  215. hdr->len = (pos - wpa_ie) - 2;
  216. WPA_ASSERT((size_t) (pos - wpa_ie) <= wpa_ie_len);
  217. return pos - wpa_ie;
  218. }
  219. static int wpa_gen_wpa_ie_rsn(u8 *rsn_ie, size_t rsn_ie_len,
  220. int pairwise_cipher, int group_cipher,
  221. int key_mgmt, int mgmt_group_cipher,
  222. struct wpa_sm *sm)
  223. {
  224. #ifndef CONFIG_NO_WPA2
  225. u8 *pos;
  226. struct rsn_ie_hdr *hdr;
  227. u16 capab;
  228. if (rsn_ie_len < sizeof(*hdr) + RSN_SELECTOR_LEN +
  229. 2 + RSN_SELECTOR_LEN + 2 + RSN_SELECTOR_LEN + 2 +
  230. (sm->cur_pmksa ? 2 + PMKID_LEN : 0)) {
  231. wpa_printf(MSG_DEBUG, "RSN: Too short IE buffer (%lu bytes)",
  232. (unsigned long) rsn_ie_len);
  233. return -1;
  234. }
  235. hdr = (struct rsn_ie_hdr *) rsn_ie;
  236. hdr->elem_id = WLAN_EID_RSN;
  237. WPA_PUT_LE16(hdr->version, RSN_VERSION);
  238. pos = (u8 *) (hdr + 1);
  239. if (group_cipher == WPA_CIPHER_CCMP) {
  240. RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_CCMP);
  241. } else if (group_cipher == WPA_CIPHER_TKIP) {
  242. RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_TKIP);
  243. } else if (group_cipher == WPA_CIPHER_WEP104) {
  244. RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_WEP104);
  245. } else if (group_cipher == WPA_CIPHER_WEP40) {
  246. RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_WEP40);
  247. } else {
  248. wpa_printf(MSG_WARNING, "Invalid group cipher (%d).",
  249. group_cipher);
  250. return -1;
  251. }
  252. pos += RSN_SELECTOR_LEN;
  253. *pos++ = 1;
  254. *pos++ = 0;
  255. if (pairwise_cipher == WPA_CIPHER_CCMP) {
  256. RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_CCMP);
  257. } else if (pairwise_cipher == WPA_CIPHER_TKIP) {
  258. RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_TKIP);
  259. } else if (pairwise_cipher == WPA_CIPHER_NONE) {
  260. RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_NONE);
  261. } else {
  262. wpa_printf(MSG_WARNING, "Invalid pairwise cipher (%d).",
  263. pairwise_cipher);
  264. return -1;
  265. }
  266. pos += RSN_SELECTOR_LEN;
  267. *pos++ = 1;
  268. *pos++ = 0;
  269. if (key_mgmt == WPA_KEY_MGMT_IEEE8021X) {
  270. RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_UNSPEC_802_1X);
  271. } else if (key_mgmt == WPA_KEY_MGMT_PSK) {
  272. RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X);
  273. #ifdef CONFIG_IEEE80211R
  274. } else if (key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X) {
  275. RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FT_802_1X);
  276. } else if (key_mgmt == WPA_KEY_MGMT_FT_PSK) {
  277. RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FT_PSK);
  278. #endif /* CONFIG_IEEE80211R */
  279. #ifdef CONFIG_IEEE80211W
  280. } else if (key_mgmt == WPA_KEY_MGMT_IEEE8021X_SHA256) {
  281. RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_802_1X_SHA256);
  282. } else if (key_mgmt == WPA_KEY_MGMT_PSK_SHA256) {
  283. RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_PSK_SHA256);
  284. #endif /* CONFIG_IEEE80211W */
  285. } else {
  286. wpa_printf(MSG_WARNING, "Invalid key management type (%d).",
  287. key_mgmt);
  288. return -1;
  289. }
  290. pos += RSN_SELECTOR_LEN;
  291. /* RSN Capabilities */
  292. capab = 0;
  293. #ifdef CONFIG_IEEE80211W
  294. if (sm->mfp)
  295. capab |= WPA_CAPABILITY_MFPC;
  296. if (sm->mfp == 2)
  297. capab |= WPA_CAPABILITY_MFPR;
  298. #endif /* CONFIG_IEEE80211W */
  299. WPA_PUT_LE16(pos, capab);
  300. pos += 2;
  301. if (sm->cur_pmksa) {
  302. /* PMKID Count (2 octets, little endian) */
  303. *pos++ = 1;
  304. *pos++ = 0;
  305. /* PMKID */
  306. os_memcpy(pos, sm->cur_pmksa->pmkid, PMKID_LEN);
  307. pos += PMKID_LEN;
  308. }
  309. #ifdef CONFIG_IEEE80211W
  310. if (mgmt_group_cipher == WPA_CIPHER_AES_128_CMAC) {
  311. if (!sm->cur_pmksa) {
  312. /* PMKID Count */
  313. WPA_PUT_LE16(pos, 0);
  314. pos += 2;
  315. }
  316. /* Management Group Cipher Suite */
  317. RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_AES_128_CMAC);
  318. pos += RSN_SELECTOR_LEN;
  319. }
  320. #endif /* CONFIG_IEEE80211W */
  321. hdr->len = (pos - rsn_ie) - 2;
  322. WPA_ASSERT((size_t) (pos - rsn_ie) <= rsn_ie_len);
  323. return pos - rsn_ie;
  324. #else /* CONFIG_NO_WPA2 */
  325. return -1;
  326. #endif /* CONFIG_NO_WPA2 */
  327. }
  328. /**
  329. * wpa_gen_wpa_ie - Generate WPA/RSN IE based on current security policy
  330. * @sm: Pointer to WPA state machine data from wpa_sm_init()
  331. * @wpa_ie: Pointer to memory area for the generated WPA/RSN IE
  332. * @wpa_ie_len: Maximum length of the generated WPA/RSN IE
  333. * Returns: Length of the generated WPA/RSN IE or -1 on failure
  334. */
  335. int wpa_gen_wpa_ie(struct wpa_sm *sm, u8 *wpa_ie, size_t wpa_ie_len)
  336. {
  337. if (sm->proto == WPA_PROTO_RSN)
  338. return wpa_gen_wpa_ie_rsn(wpa_ie, wpa_ie_len,
  339. sm->pairwise_cipher,
  340. sm->group_cipher,
  341. sm->key_mgmt, sm->mgmt_group_cipher,
  342. sm);
  343. else
  344. return wpa_gen_wpa_ie_wpa(wpa_ie, wpa_ie_len,
  345. sm->pairwise_cipher,
  346. sm->group_cipher,
  347. sm->key_mgmt);
  348. }
  349. /**
  350. * wpa_parse_generic - Parse EAPOL-Key Key Data Generic IEs
  351. * @pos: Pointer to the IE header
  352. * @end: Pointer to the end of the Key Data buffer
  353. * @ie: Pointer to parsed IE data
  354. * Returns: 0 on success, 1 if end mark is found, -1 on failure
  355. */
  356. static int wpa_parse_generic(const u8 *pos, const u8 *end,
  357. struct wpa_eapol_ie_parse *ie)
  358. {
  359. if (pos[1] == 0)
  360. return 1;
  361. if (pos[1] >= 6 &&
  362. RSN_SELECTOR_GET(pos + 2) == WPA_OUI_TYPE &&
  363. pos[2 + WPA_SELECTOR_LEN] == 1 &&
  364. pos[2 + WPA_SELECTOR_LEN + 1] == 0) {
  365. ie->wpa_ie = pos;
  366. ie->wpa_ie_len = pos[1] + 2;
  367. return 0;
  368. }
  369. if (pos + 1 + RSN_SELECTOR_LEN < end &&
  370. pos[1] >= RSN_SELECTOR_LEN + PMKID_LEN &&
  371. RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_PMKID) {
  372. ie->pmkid = pos + 2 + RSN_SELECTOR_LEN;
  373. return 0;
  374. }
  375. if (pos[1] > RSN_SELECTOR_LEN + 2 &&
  376. RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_GROUPKEY) {
  377. ie->gtk = pos + 2 + RSN_SELECTOR_LEN;
  378. ie->gtk_len = pos[1] - RSN_SELECTOR_LEN;
  379. return 0;
  380. }
  381. if (pos[1] > RSN_SELECTOR_LEN + 2 &&
  382. RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_MAC_ADDR) {
  383. ie->mac_addr = pos + 2 + RSN_SELECTOR_LEN;
  384. ie->mac_addr_len = pos[1] - RSN_SELECTOR_LEN;
  385. return 0;
  386. }
  387. #ifdef CONFIG_PEERKEY
  388. if (pos[1] > RSN_SELECTOR_LEN + 2 &&
  389. RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_SMK) {
  390. ie->smk = pos + 2 + RSN_SELECTOR_LEN;
  391. ie->smk_len = pos[1] - RSN_SELECTOR_LEN;
  392. return 0;
  393. }
  394. if (pos[1] > RSN_SELECTOR_LEN + 2 &&
  395. RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_NONCE) {
  396. ie->nonce = pos + 2 + RSN_SELECTOR_LEN;
  397. ie->nonce_len = pos[1] - RSN_SELECTOR_LEN;
  398. return 0;
  399. }
  400. if (pos[1] > RSN_SELECTOR_LEN + 2 &&
  401. RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_LIFETIME) {
  402. ie->lifetime = pos + 2 + RSN_SELECTOR_LEN;
  403. ie->lifetime_len = pos[1] - RSN_SELECTOR_LEN;
  404. return 0;
  405. }
  406. if (pos[1] > RSN_SELECTOR_LEN + 2 &&
  407. RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_ERROR) {
  408. ie->error = pos + 2 + RSN_SELECTOR_LEN;
  409. ie->error_len = pos[1] - RSN_SELECTOR_LEN;
  410. return 0;
  411. }
  412. #endif /* CONFIG_PEERKEY */
  413. #ifdef CONFIG_IEEE80211W
  414. if (pos[1] > RSN_SELECTOR_LEN + 2 &&
  415. RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_IGTK) {
  416. ie->igtk = pos + 2 + RSN_SELECTOR_LEN;
  417. ie->igtk_len = pos[1] - RSN_SELECTOR_LEN;
  418. return 0;
  419. }
  420. #endif /* CONFIG_IEEE80211W */
  421. return 0;
  422. }
  423. /**
  424. * wpa_supplicant_parse_ies - Parse EAPOL-Key Key Data IEs
  425. * @buf: Pointer to the Key Data buffer
  426. * @len: Key Data Length
  427. * @ie: Pointer to parsed IE data
  428. * Returns: 0 on success, -1 on failure
  429. */
  430. int wpa_supplicant_parse_ies(const u8 *buf, size_t len,
  431. struct wpa_eapol_ie_parse *ie)
  432. {
  433. const u8 *pos, *end;
  434. int ret = 0;
  435. os_memset(ie, 0, sizeof(*ie));
  436. for (pos = buf, end = pos + len; pos + 1 < end; pos += 2 + pos[1]) {
  437. if (pos[0] == 0xdd &&
  438. ((pos == buf + len - 1) || pos[1] == 0)) {
  439. /* Ignore padding */
  440. break;
  441. }
  442. if (pos + 2 + pos[1] > end) {
  443. wpa_printf(MSG_DEBUG, "WPA: EAPOL-Key Key Data "
  444. "underflow (ie=%d len=%d pos=%d)",
  445. pos[0], pos[1], (int) (pos - buf));
  446. wpa_hexdump_key(MSG_DEBUG, "WPA: Key Data",
  447. buf, len);
  448. ret = -1;
  449. break;
  450. }
  451. if (*pos == WLAN_EID_RSN) {
  452. ie->rsn_ie = pos;
  453. ie->rsn_ie_len = pos[1] + 2;
  454. #ifdef CONFIG_IEEE80211R
  455. } else if (*pos == WLAN_EID_MOBILITY_DOMAIN) {
  456. ie->mdie = pos;
  457. ie->mdie_len = pos[1] + 2;
  458. #endif /* CONFIG_IEEE80211R */
  459. } else if (*pos == WLAN_EID_VENDOR_SPECIFIC) {
  460. ret = wpa_parse_generic(pos, end, ie);
  461. if (ret < 0)
  462. break;
  463. if (ret > 0) {
  464. ret = 0;
  465. break;
  466. }
  467. } else {
  468. wpa_hexdump(MSG_DEBUG, "WPA: Unrecognized EAPOL-Key "
  469. "Key Data IE", pos, 2 + pos[1]);
  470. }
  471. }
  472. return ret;
  473. }