rx_eapol.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034
  1. /*
  2. * Received Data frame processing for EAPOL messages
  3. * Copyright (c) 2010, 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 "utils/includes.h"
  15. #include "utils/common.h"
  16. #include "crypto/aes_wrap.h"
  17. #include "crypto/crypto.h"
  18. #include "common/defs.h"
  19. #include "common/ieee802_11_defs.h"
  20. #include "common/eapol_common.h"
  21. #include "common/wpa_common.h"
  22. #include "rsn_supp/wpa_ie.h"
  23. #include "wlantest.h"
  24. static int is_zero(const u8 *buf, size_t len)
  25. {
  26. size_t i;
  27. for (i = 0; i < len; i++) {
  28. if (buf[i])
  29. return 0;
  30. }
  31. return 1;
  32. }
  33. static int check_mic(const u8 *kck, int ver, const u8 *data, size_t len)
  34. {
  35. u8 *buf;
  36. int ret = -1;
  37. struct ieee802_1x_hdr *hdr;
  38. struct wpa_eapol_key *key;
  39. u8 rx_mic[16];
  40. buf = os_malloc(len);
  41. if (buf == NULL)
  42. return -1;
  43. os_memcpy(buf, data, len);
  44. hdr = (struct ieee802_1x_hdr *) buf;
  45. key = (struct wpa_eapol_key *) (hdr + 1);
  46. os_memcpy(rx_mic, key->key_mic, 16);
  47. os_memset(key->key_mic, 0, 16);
  48. if (wpa_eapol_key_mic(kck, ver, buf, len, key->key_mic) == 0 &&
  49. os_memcmp(rx_mic, key->key_mic, 16) == 0)
  50. ret = 0;
  51. os_free(buf);
  52. return ret;
  53. }
  54. static void rx_data_eapol_key_1_of_4(struct wlantest *wt, const u8 *dst,
  55. const u8 *src, const u8 *data, size_t len)
  56. {
  57. struct wlantest_bss *bss;
  58. struct wlantest_sta *sta;
  59. const struct ieee802_1x_hdr *eapol;
  60. const struct wpa_eapol_key *hdr;
  61. wpa_printf(MSG_DEBUG, "EAPOL-Key 1/4 " MACSTR " -> " MACSTR,
  62. MAC2STR(src), MAC2STR(dst));
  63. bss = bss_get(wt, src);
  64. if (bss == NULL)
  65. return;
  66. sta = sta_get(bss, dst);
  67. if (sta == NULL)
  68. return;
  69. eapol = (const struct ieee802_1x_hdr *) data;
  70. hdr = (const struct wpa_eapol_key *) (eapol + 1);
  71. if (is_zero(hdr->key_nonce, WPA_NONCE_LEN)) {
  72. wpa_printf(MSG_INFO, "EAPOL-Key 1/4 from " MACSTR " used "
  73. "zero nonce", MAC2STR(src));
  74. }
  75. if (!is_zero(hdr->key_rsc, 8)) {
  76. wpa_printf(MSG_INFO, "EAPOL-Key 1/4 from " MACSTR " used "
  77. "non-zero Key RSC", MAC2STR(src));
  78. }
  79. os_memcpy(sta->anonce, hdr->key_nonce, WPA_NONCE_LEN);
  80. }
  81. static int try_pmk(struct wlantest_bss *bss, struct wlantest_sta *sta,
  82. u16 ver, const u8 *data, size_t len,
  83. struct wlantest_pmk *pmk)
  84. {
  85. struct wpa_ptk ptk;
  86. size_t ptk_len = sta->pairwise_cipher == WPA_CIPHER_TKIP ? 64 : 48;
  87. wpa_pmk_to_ptk(pmk->pmk, sizeof(pmk->pmk),
  88. "Pairwise key expansion",
  89. bss->bssid, sta->addr, sta->anonce, sta->snonce,
  90. (u8 *) &ptk, ptk_len,
  91. wpa_key_mgmt_sha256(sta->key_mgmt));
  92. if (check_mic(ptk.kck, ver, data, len) < 0)
  93. return -1;
  94. wpa_printf(MSG_INFO, "Derived PTK for STA " MACSTR " BSSID " MACSTR,
  95. MAC2STR(sta->addr), MAC2STR(bss->bssid));
  96. sta->counters[WLANTEST_STA_COUNTER_PTK_LEARNED]++;
  97. if (sta->ptk_set) {
  98. /*
  99. * Rekeying - use new PTK for EAPOL-Key frames, but continue
  100. * using the old PTK for frame decryption.
  101. */
  102. os_memcpy(&sta->tptk, &ptk, sizeof(ptk));
  103. wpa_hexdump(MSG_DEBUG, "TPTK:KCK", sta->tptk.kck, 16);
  104. wpa_hexdump(MSG_DEBUG, "TPTK:KEK", sta->tptk.kek, 16);
  105. wpa_hexdump(MSG_DEBUG, "TPTK:TK1", sta->tptk.tk1, 16);
  106. if (ptk_len > 48)
  107. wpa_hexdump(MSG_DEBUG, "TPTK:TK2", sta->tptk.u.tk2,
  108. 16);
  109. sta->tptk_set = 1;
  110. return 0;
  111. }
  112. os_memcpy(&sta->ptk, &ptk, sizeof(ptk));
  113. wpa_hexdump(MSG_DEBUG, "PTK:KCK", sta->ptk.kck, 16);
  114. wpa_hexdump(MSG_DEBUG, "PTK:KEK", sta->ptk.kek, 16);
  115. wpa_hexdump(MSG_DEBUG, "PTK:TK1", sta->ptk.tk1, 16);
  116. if (ptk_len > 48)
  117. wpa_hexdump(MSG_DEBUG, "PTK:TK2", sta->ptk.u.tk2, 16);
  118. sta->ptk_set = 1;
  119. os_memset(sta->rsc_tods, 0, sizeof(sta->rsc_tods));
  120. os_memset(sta->rsc_fromds, 0, sizeof(sta->rsc_fromds));
  121. return 0;
  122. }
  123. static void derive_ptk(struct wlantest *wt, struct wlantest_bss *bss,
  124. struct wlantest_sta *sta, u16 ver,
  125. const u8 *data, size_t len)
  126. {
  127. struct wlantest_pmk *pmk;
  128. wpa_printf(MSG_DEBUG, "Trying to derive PTK for " MACSTR,
  129. MAC2STR(sta->addr));
  130. dl_list_for_each(pmk, &bss->pmk, struct wlantest_pmk, list) {
  131. wpa_printf(MSG_DEBUG, "Try per-BSS PMK");
  132. if (try_pmk(bss, sta, ver, data, len, pmk) == 0)
  133. return;
  134. }
  135. dl_list_for_each(pmk, &wt->pmk, struct wlantest_pmk, list) {
  136. wpa_printf(MSG_DEBUG, "Try global PMK");
  137. if (try_pmk(bss, sta, ver, data, len, pmk) == 0)
  138. return;
  139. }
  140. wpa_printf(MSG_DEBUG, "No matching PMK found to derive PTK");
  141. }
  142. static void rx_data_eapol_key_2_of_4(struct wlantest *wt, const u8 *dst,
  143. const u8 *src, const u8 *data, size_t len)
  144. {
  145. struct wlantest_bss *bss;
  146. struct wlantest_sta *sta;
  147. const struct ieee802_1x_hdr *eapol;
  148. const struct wpa_eapol_key *hdr;
  149. const u8 *key_data, *kck;
  150. u16 key_info, key_data_len;
  151. struct wpa_eapol_ie_parse ie;
  152. wpa_printf(MSG_DEBUG, "EAPOL-Key 2/4 " MACSTR " -> " MACSTR,
  153. MAC2STR(src), MAC2STR(dst));
  154. bss = bss_get(wt, dst);
  155. if (bss == NULL)
  156. return;
  157. sta = sta_get(bss, src);
  158. if (sta == NULL)
  159. return;
  160. eapol = (const struct ieee802_1x_hdr *) data;
  161. hdr = (const struct wpa_eapol_key *) (eapol + 1);
  162. if (is_zero(hdr->key_nonce, WPA_NONCE_LEN)) {
  163. wpa_printf(MSG_INFO, "EAPOL-Key 2/4 from " MACSTR " used "
  164. "zero nonce", MAC2STR(src));
  165. }
  166. if (!is_zero(hdr->key_rsc, 8)) {
  167. wpa_printf(MSG_INFO, "EAPOL-Key 2/4 from " MACSTR " used "
  168. "non-zero Key RSC", MAC2STR(src));
  169. }
  170. os_memcpy(sta->snonce, hdr->key_nonce, WPA_NONCE_LEN);
  171. key_info = WPA_GET_BE16(hdr->key_info);
  172. key_data_len = WPA_GET_BE16(hdr->key_data_length);
  173. derive_ptk(wt, bss, sta, key_info & WPA_KEY_INFO_TYPE_MASK, data, len);
  174. if (!sta->ptk_set && !sta->tptk_set) {
  175. wpa_printf(MSG_DEBUG, "No PTK known to process EAPOL-Key 2/4");
  176. return;
  177. }
  178. kck = sta->ptk.kck;
  179. if (sta->tptk_set) {
  180. wpa_printf(MSG_DEBUG, "Use TPTK for validation EAPOL-Key MIC");
  181. kck = sta->tptk.kck;
  182. }
  183. if (check_mic(kck, key_info & WPA_KEY_INFO_TYPE_MASK, data, len) < 0) {
  184. wpa_printf(MSG_INFO, "Mismatch in EAPOL-Key 2/4 MIC");
  185. return;
  186. }
  187. wpa_printf(MSG_DEBUG, "Valid MIC found in EAPOL-Key 2/4");
  188. key_data = (const u8 *) (hdr + 1);
  189. if (wpa_supplicant_parse_ies(key_data, key_data_len, &ie) < 0) {
  190. wpa_printf(MSG_INFO, "Failed to parse EAPOL-Key Key Data");
  191. return;
  192. }
  193. if (ie.wpa_ie) {
  194. wpa_hexdump(MSG_MSGDUMP, "EAPOL-Key Key Data - WPA IE",
  195. ie.wpa_ie, ie.wpa_ie_len);
  196. if (os_memcmp(ie.wpa_ie, sta->rsnie, ie.wpa_ie_len) != 0) {
  197. wpa_printf(MSG_INFO, "Mismatch in WPA IE between "
  198. "EAPOL-Key 2/4 and (Re)Association "
  199. "Request from " MACSTR, MAC2STR(sta->addr));
  200. wpa_hexdump(MSG_INFO, "WPA IE in EAPOL-Key",
  201. ie.wpa_ie, ie.wpa_ie_len);
  202. wpa_hexdump(MSG_INFO, "WPA IE in (Re)Association "
  203. "Request",
  204. sta->rsnie,
  205. sta->rsnie[0] ? 2 + sta->rsnie[1] : 0);
  206. }
  207. }
  208. if (ie.rsn_ie) {
  209. wpa_hexdump(MSG_MSGDUMP, "EAPOL-Key Key Data - RSN IE",
  210. ie.rsn_ie, ie.rsn_ie_len);
  211. if (os_memcmp(ie.rsn_ie, sta->rsnie, ie.rsn_ie_len) != 0) {
  212. wpa_printf(MSG_INFO, "Mismatch in RSN IE between "
  213. "EAPOL-Key 2/4 and (Re)Association "
  214. "Request from " MACSTR, MAC2STR(sta->addr));
  215. wpa_hexdump(MSG_INFO, "RSN IE in EAPOL-Key",
  216. ie.rsn_ie, ie.rsn_ie_len);
  217. wpa_hexdump(MSG_INFO, "RSN IE in (Re)Association "
  218. "Request",
  219. sta->rsnie,
  220. sta->rsnie[0] ? 2 + sta->rsnie[1] : 0);
  221. }
  222. }
  223. }
  224. static u8 * decrypt_eapol_key_data_rc4(const u8 *kek,
  225. const struct wpa_eapol_key *hdr,
  226. size_t *len)
  227. {
  228. u8 ek[32], *buf;
  229. u16 keydatalen = WPA_GET_BE16(hdr->key_data_length);
  230. buf = os_malloc(keydatalen);
  231. if (buf == NULL)
  232. return NULL;
  233. os_memcpy(ek, hdr->key_iv, 16);
  234. os_memcpy(ek + 16, kek, 16);
  235. os_memcpy(buf, hdr + 1, keydatalen);
  236. if (rc4_skip(ek, 32, 256, buf, keydatalen)) {
  237. wpa_printf(MSG_INFO, "RC4 failed");
  238. os_free(buf);
  239. return NULL;
  240. }
  241. *len = keydatalen;
  242. return buf;
  243. }
  244. static u8 * decrypt_eapol_key_data_aes(const u8 *kek,
  245. const struct wpa_eapol_key *hdr,
  246. size_t *len)
  247. {
  248. u8 *buf;
  249. u16 keydatalen = WPA_GET_BE16(hdr->key_data_length);
  250. if (keydatalen % 8) {
  251. wpa_printf(MSG_INFO, "Unsupported AES-WRAP len %d",
  252. keydatalen);
  253. return NULL;
  254. }
  255. keydatalen -= 8; /* AES-WRAP adds 8 bytes */
  256. buf = os_malloc(keydatalen);
  257. if (buf == NULL)
  258. return NULL;
  259. if (aes_unwrap(kek, keydatalen / 8, (u8 *) (hdr + 1), buf)) {
  260. os_free(buf);
  261. wpa_printf(MSG_INFO, "AES unwrap failed - "
  262. "could not decrypt EAPOL-Key key data");
  263. return NULL;
  264. }
  265. *len = keydatalen;
  266. return buf;
  267. }
  268. static u8 * decrypt_eapol_key_data(const u8 *kek, u16 ver,
  269. const struct wpa_eapol_key *hdr,
  270. size_t *len)
  271. {
  272. switch (ver) {
  273. case WPA_KEY_INFO_TYPE_HMAC_MD5_RC4:
  274. return decrypt_eapol_key_data_rc4(kek, hdr, len);
  275. case WPA_KEY_INFO_TYPE_HMAC_SHA1_AES:
  276. case WPA_KEY_INFO_TYPE_AES_128_CMAC:
  277. return decrypt_eapol_key_data_aes(kek, hdr, len);
  278. default:
  279. wpa_printf(MSG_INFO, "Unsupported EAPOL-Key Key Descriptor "
  280. "Version %u", ver);
  281. return NULL;
  282. }
  283. }
  284. static void learn_kde_keys(struct wlantest_bss *bss, const u8 *buf, size_t len,
  285. const u8 *rsc)
  286. {
  287. struct wpa_eapol_ie_parse ie;
  288. if (wpa_supplicant_parse_ies(buf, len, &ie) < 0) {
  289. wpa_printf(MSG_INFO, "Failed to parse EAPOL-Key Key Data");
  290. return;
  291. }
  292. if (ie.wpa_ie) {
  293. wpa_hexdump(MSG_MSGDUMP, "EAPOL-Key Key Data - WPA IE",
  294. ie.wpa_ie, ie.wpa_ie_len);
  295. }
  296. if (ie.rsn_ie) {
  297. wpa_hexdump(MSG_MSGDUMP, "EAPOL-Key Key Data - RSN IE",
  298. ie.rsn_ie, ie.rsn_ie_len);
  299. }
  300. if (ie.gtk) {
  301. wpa_hexdump(MSG_MSGDUMP, "EAPOL-Key Key Data - GTK KDE",
  302. ie.gtk, ie.gtk_len);
  303. if (ie.gtk_len >= 2 && ie.gtk_len <= 2 + 32) {
  304. int id;
  305. id = ie.gtk[0] & 0x03;
  306. wpa_printf(MSG_DEBUG, "GTK KeyID=%u tx=%u",
  307. id, !!(ie.gtk[0] & 0x04));
  308. if ((ie.gtk[0] & 0xf8) || ie.gtk[1])
  309. wpa_printf(MSG_INFO, "GTK KDE: Reserved field "
  310. "set: %02x %02x",
  311. ie.gtk[0], ie.gtk[1]);
  312. wpa_hexdump(MSG_DEBUG, "GTK", ie.gtk + 2,
  313. ie.gtk_len - 2);
  314. bss->gtk_len[id] = ie.gtk_len - 2;
  315. os_memcpy(bss->gtk[id], ie.gtk + 2, ie.gtk_len - 2);
  316. bss->rsc[id][0] = rsc[5];
  317. bss->rsc[id][1] = rsc[4];
  318. bss->rsc[id][2] = rsc[3];
  319. bss->rsc[id][3] = rsc[2];
  320. bss->rsc[id][4] = rsc[1];
  321. bss->rsc[id][5] = rsc[0];
  322. bss->gtk_idx = id;
  323. wpa_hexdump(MSG_DEBUG, "RSC", bss->rsc[id], 6);
  324. } else {
  325. wpa_printf(MSG_INFO, "Invalid GTK KDE length %u",
  326. (unsigned) ie.gtk_len);
  327. }
  328. }
  329. if (ie.igtk) {
  330. wpa_hexdump(MSG_MSGDUMP, "EAPOL-Key Key Data - IGTK KDE",
  331. ie.igtk, ie.igtk_len);
  332. if (ie.igtk_len == 24) {
  333. u16 id;
  334. id = WPA_GET_LE16(ie.igtk);
  335. if (id > 5) {
  336. wpa_printf(MSG_INFO, "Unexpected IGTK KeyID "
  337. "%u", id);
  338. } else {
  339. const u8 *ipn;
  340. wpa_printf(MSG_DEBUG, "IGTK KeyID %u", id);
  341. wpa_hexdump(MSG_DEBUG, "IPN", ie.igtk + 2, 6);
  342. wpa_hexdump(MSG_DEBUG, "IGTK", ie.igtk + 8,
  343. 16);
  344. os_memcpy(bss->igtk[id], ie.igtk + 8, 16);
  345. bss->igtk_set[id] = 1;
  346. ipn = ie.igtk + 2;
  347. bss->ipn[id][0] = ipn[5];
  348. bss->ipn[id][1] = ipn[4];
  349. bss->ipn[id][2] = ipn[3];
  350. bss->ipn[id][3] = ipn[2];
  351. bss->ipn[id][4] = ipn[1];
  352. bss->ipn[id][5] = ipn[0];
  353. bss->igtk_idx = id;
  354. }
  355. } else {
  356. wpa_printf(MSG_INFO, "Invalid IGTK KDE length %u",
  357. (unsigned) ie.igtk_len);
  358. }
  359. }
  360. }
  361. static void rx_data_eapol_key_3_of_4(struct wlantest *wt, const u8 *dst,
  362. const u8 *src, const u8 *data, size_t len)
  363. {
  364. struct wlantest_bss *bss;
  365. struct wlantest_sta *sta;
  366. const struct ieee802_1x_hdr *eapol;
  367. const struct wpa_eapol_key *hdr;
  368. const u8 *key_data, *kck;
  369. int recalc = 0;
  370. u16 key_info, ver;
  371. u8 *decrypted_buf = NULL;
  372. const u8 *decrypted;
  373. size_t decrypted_len = 0;
  374. struct wpa_eapol_ie_parse ie;
  375. wpa_printf(MSG_DEBUG, "EAPOL-Key 3/4 " MACSTR " -> " MACSTR,
  376. MAC2STR(src), MAC2STR(dst));
  377. bss = bss_get(wt, src);
  378. if (bss == NULL)
  379. return;
  380. sta = sta_get(bss, dst);
  381. if (sta == NULL)
  382. return;
  383. eapol = (const struct ieee802_1x_hdr *) data;
  384. hdr = (const struct wpa_eapol_key *) (eapol + 1);
  385. key_info = WPA_GET_BE16(hdr->key_info);
  386. if (os_memcmp(sta->anonce, hdr->key_nonce, WPA_NONCE_LEN) != 0) {
  387. wpa_printf(MSG_INFO, "EAPOL-Key ANonce mismatch between 1/4 "
  388. "and 3/4");
  389. recalc = 1;
  390. }
  391. os_memcpy(sta->anonce, hdr->key_nonce, WPA_NONCE_LEN);
  392. if (recalc) {
  393. derive_ptk(wt, bss, sta, key_info & WPA_KEY_INFO_TYPE_MASK,
  394. data, len);
  395. }
  396. if (!sta->ptk_set && !sta->tptk_set) {
  397. wpa_printf(MSG_DEBUG, "No PTK known to process EAPOL-Key 3/4");
  398. return;
  399. }
  400. kck = sta->ptk.kck;
  401. if (sta->tptk_set) {
  402. wpa_printf(MSG_DEBUG, "Use TPTK for validation EAPOL-Key MIC");
  403. kck = sta->tptk.kck;
  404. }
  405. if (check_mic(kck, key_info & WPA_KEY_INFO_TYPE_MASK, data, len) < 0) {
  406. wpa_printf(MSG_INFO, "Mismatch in EAPOL-Key 3/4 MIC");
  407. return;
  408. }
  409. wpa_printf(MSG_DEBUG, "Valid MIC found in EAPOL-Key 3/4");
  410. key_data = (const u8 *) (hdr + 1);
  411. if (!(key_info & WPA_KEY_INFO_ENCR_KEY_DATA)) {
  412. if (sta->proto & WPA_PROTO_RSN)
  413. wpa_printf(MSG_INFO, "EAPOL-Key 3/4 without "
  414. "EncrKeyData bit");
  415. decrypted = key_data;
  416. decrypted_len = WPA_GET_BE16(hdr->key_data_length);
  417. } else {
  418. ver = key_info & WPA_KEY_INFO_TYPE_MASK;
  419. decrypted_buf = decrypt_eapol_key_data(sta->ptk.kek, ver, hdr,
  420. &decrypted_len);
  421. if (decrypted_buf == NULL) {
  422. wpa_printf(MSG_INFO, "Failed to decrypt EAPOL-Key Key "
  423. "Data");
  424. return;
  425. }
  426. decrypted = decrypted_buf;
  427. wpa_hexdump(MSG_DEBUG, "Decrypted EAPOL-Key Key Data",
  428. decrypted, decrypted_len);
  429. }
  430. if (wt->write_pcap_dumper && decrypted != key_data) {
  431. /* Fill in a dummy Data frame header */
  432. u8 buf[24 + 8 + sizeof(*eapol) + sizeof(*hdr)];
  433. struct ieee80211_hdr *h;
  434. struct wpa_eapol_key *k;
  435. const u8 *p;
  436. u8 *pos;
  437. size_t plain_len;
  438. plain_len = decrypted_len;
  439. p = decrypted;
  440. while (p + 1 < decrypted + decrypted_len) {
  441. if (p[0] == 0xdd && p[1] == 0x00) {
  442. /* Remove padding */
  443. plain_len = p - decrypted;
  444. break;
  445. }
  446. p += 2 + p[1];
  447. }
  448. os_memset(buf, 0, sizeof(buf));
  449. h = (struct ieee80211_hdr *) buf;
  450. h->frame_control = host_to_le16(0x0208);
  451. os_memcpy(h->addr1, dst, ETH_ALEN);
  452. os_memcpy(h->addr2, src, ETH_ALEN);
  453. os_memcpy(h->addr3, src, ETH_ALEN);
  454. pos = (u8 *) (h + 1);
  455. os_memcpy(pos, "\xaa\xaa\x03\x00\x00\x00\x88\x8e", 8);
  456. pos += 8;
  457. os_memcpy(pos, eapol, sizeof(*eapol));
  458. pos += sizeof(*eapol);
  459. os_memcpy(pos, hdr, sizeof(*hdr));
  460. k = (struct wpa_eapol_key *) pos;
  461. WPA_PUT_BE16(k->key_info,
  462. key_info & ~WPA_KEY_INFO_ENCR_KEY_DATA);
  463. WPA_PUT_BE16(k->key_data_length, plain_len);
  464. write_pcap_decrypted(wt, buf, sizeof(buf),
  465. decrypted, plain_len);
  466. }
  467. if (wpa_supplicant_parse_ies(decrypted, decrypted_len, &ie) < 0) {
  468. wpa_printf(MSG_INFO, "Failed to parse EAPOL-Key Key Data");
  469. os_free(decrypted_buf);
  470. return;
  471. }
  472. if ((ie.wpa_ie &&
  473. os_memcmp(ie.wpa_ie, bss->wpaie, ie.wpa_ie_len) != 0) ||
  474. (ie.wpa_ie == NULL && bss->wpaie[0])) {
  475. wpa_printf(MSG_INFO, "Mismatch in WPA IE between "
  476. "EAPOL-Key 3/4 and Beacon/Probe Response "
  477. "from " MACSTR, MAC2STR(bss->bssid));
  478. wpa_hexdump(MSG_INFO, "WPA IE in EAPOL-Key",
  479. ie.wpa_ie, ie.wpa_ie_len);
  480. wpa_hexdump(MSG_INFO, "WPA IE in Beacon/Probe "
  481. "Response",
  482. bss->wpaie,
  483. bss->wpaie[0] ? 2 + bss->wpaie[1] : 0);
  484. }
  485. if ((ie.rsn_ie &&
  486. os_memcmp(ie.rsn_ie, bss->rsnie, ie.rsn_ie_len) != 0) ||
  487. (ie.rsn_ie == NULL && bss->rsnie[0])) {
  488. wpa_printf(MSG_INFO, "Mismatch in RSN IE between "
  489. "EAPOL-Key 3/4 and Beacon/Probe Response "
  490. "from " MACSTR, MAC2STR(bss->bssid));
  491. wpa_hexdump(MSG_INFO, "RSN IE in EAPOL-Key",
  492. ie.rsn_ie, ie.rsn_ie_len);
  493. wpa_hexdump(MSG_INFO, "RSN IE in (Re)Association "
  494. "Request",
  495. bss->rsnie,
  496. bss->rsnie[0] ? 2 + bss->rsnie[1] : 0);
  497. }
  498. learn_kde_keys(bss, decrypted, decrypted_len, hdr->key_rsc);
  499. os_free(decrypted_buf);
  500. }
  501. static void rx_data_eapol_key_4_of_4(struct wlantest *wt, const u8 *dst,
  502. const u8 *src, const u8 *data, size_t len)
  503. {
  504. struct wlantest_bss *bss;
  505. struct wlantest_sta *sta;
  506. const struct ieee802_1x_hdr *eapol;
  507. const struct wpa_eapol_key *hdr;
  508. u16 key_info;
  509. const u8 *kck;
  510. wpa_printf(MSG_DEBUG, "EAPOL-Key 4/4 " MACSTR " -> " MACSTR,
  511. MAC2STR(src), MAC2STR(dst));
  512. bss = bss_get(wt, dst);
  513. if (bss == NULL)
  514. return;
  515. sta = sta_get(bss, src);
  516. if (sta == NULL)
  517. return;
  518. eapol = (const struct ieee802_1x_hdr *) data;
  519. hdr = (const struct wpa_eapol_key *) (eapol + 1);
  520. if (!is_zero(hdr->key_rsc, 8)) {
  521. wpa_printf(MSG_INFO, "EAPOL-Key 4/4 from " MACSTR " used "
  522. "non-zero Key RSC", MAC2STR(src));
  523. }
  524. key_info = WPA_GET_BE16(hdr->key_info);
  525. if (!sta->ptk_set && !sta->tptk_set) {
  526. wpa_printf(MSG_DEBUG, "No PTK known to process EAPOL-Key 4/4");
  527. return;
  528. }
  529. kck = sta->ptk.kck;
  530. if (sta->tptk_set) {
  531. wpa_printf(MSG_DEBUG, "Use TPTK for validation EAPOL-Key MIC");
  532. kck = sta->tptk.kck;
  533. }
  534. if (check_mic(kck, key_info & WPA_KEY_INFO_TYPE_MASK, data, len) < 0) {
  535. wpa_printf(MSG_INFO, "Mismatch in EAPOL-Key 4/4 MIC");
  536. return;
  537. }
  538. wpa_printf(MSG_DEBUG, "Valid MIC found in EAPOL-Key 4/4");
  539. if (sta->tptk_set) {
  540. wpa_printf(MSG_DEBUG, "Update PTK (rekeying)");
  541. os_memcpy(&sta->ptk, &sta->tptk, sizeof(sta->ptk));
  542. sta->ptk_set = 1;
  543. sta->tptk_set = 0;
  544. os_memset(sta->rsc_tods, 0, sizeof(sta->rsc_tods));
  545. os_memset(sta->rsc_fromds, 0, sizeof(sta->rsc_fromds));
  546. }
  547. }
  548. static void rx_data_eapol_key_1_of_2(struct wlantest *wt, const u8 *dst,
  549. const u8 *src, const u8 *data, size_t len)
  550. {
  551. struct wlantest_bss *bss;
  552. struct wlantest_sta *sta;
  553. const struct ieee802_1x_hdr *eapol;
  554. const struct wpa_eapol_key *hdr;
  555. const u8 *key_data;
  556. u16 key_info, ver;
  557. u8 *decrypted;
  558. size_t decrypted_len = 0;
  559. wpa_printf(MSG_DEBUG, "EAPOL-Key 1/2 " MACSTR " -> " MACSTR,
  560. MAC2STR(src), MAC2STR(dst));
  561. bss = bss_get(wt, src);
  562. if (bss == NULL)
  563. return;
  564. sta = sta_get(bss, dst);
  565. if (sta == NULL)
  566. return;
  567. eapol = (const struct ieee802_1x_hdr *) data;
  568. hdr = (const struct wpa_eapol_key *) (eapol + 1);
  569. key_info = WPA_GET_BE16(hdr->key_info);
  570. if (!sta->ptk_set) {
  571. wpa_printf(MSG_DEBUG, "No PTK known to process EAPOL-Key 1/2");
  572. return;
  573. }
  574. if (sta->ptk_set &&
  575. check_mic(sta->ptk.kck, key_info & WPA_KEY_INFO_TYPE_MASK,
  576. data, len) < 0) {
  577. wpa_printf(MSG_INFO, "Mismatch in EAPOL-Key 1/2 MIC");
  578. return;
  579. }
  580. wpa_printf(MSG_DEBUG, "Valid MIC found in EAPOL-Key 1/2");
  581. key_data = (const u8 *) (hdr + 1);
  582. if (sta->proto & WPA_PROTO_RSN &&
  583. !(key_info & WPA_KEY_INFO_ENCR_KEY_DATA)) {
  584. wpa_printf(MSG_INFO, "EAPOL-Key 1/2 without EncrKeyData bit");
  585. return;
  586. }
  587. ver = key_info & WPA_KEY_INFO_TYPE_MASK;
  588. decrypted = decrypt_eapol_key_data(sta->ptk.kek, ver, hdr,
  589. &decrypted_len);
  590. if (decrypted == NULL) {
  591. wpa_printf(MSG_INFO, "Failed to decrypt EAPOL-Key Key Data");
  592. return;
  593. }
  594. wpa_hexdump(MSG_DEBUG, "Decrypted EAPOL-Key Key Data",
  595. decrypted, decrypted_len);
  596. if (wt->write_pcap_dumper) {
  597. /* Fill in a dummy Data frame header */
  598. u8 buf[24 + 8 + sizeof(*eapol) + sizeof(*hdr)];
  599. struct ieee80211_hdr *h;
  600. struct wpa_eapol_key *k;
  601. u8 *pos;
  602. size_t plain_len;
  603. plain_len = decrypted_len;
  604. pos = decrypted;
  605. while (pos + 1 < decrypted + decrypted_len) {
  606. if (pos[0] == 0xdd && pos[1] == 0x00) {
  607. /* Remove padding */
  608. plain_len = pos - decrypted;
  609. break;
  610. }
  611. pos += 2 + pos[1];
  612. }
  613. os_memset(buf, 0, sizeof(buf));
  614. h = (struct ieee80211_hdr *) buf;
  615. h->frame_control = host_to_le16(0x0208);
  616. os_memcpy(h->addr1, dst, ETH_ALEN);
  617. os_memcpy(h->addr2, src, ETH_ALEN);
  618. os_memcpy(h->addr3, src, ETH_ALEN);
  619. pos = (u8 *) (h + 1);
  620. os_memcpy(pos, "\xaa\xaa\x03\x00\x00\x00\x88\x8e", 8);
  621. pos += 8;
  622. os_memcpy(pos, eapol, sizeof(*eapol));
  623. pos += sizeof(*eapol);
  624. os_memcpy(pos, hdr, sizeof(*hdr));
  625. k = (struct wpa_eapol_key *) pos;
  626. WPA_PUT_BE16(k->key_info,
  627. key_info & ~WPA_KEY_INFO_ENCR_KEY_DATA);
  628. WPA_PUT_BE16(k->key_data_length, plain_len);
  629. write_pcap_decrypted(wt, buf, sizeof(buf),
  630. decrypted, plain_len);
  631. }
  632. if (sta->proto & WPA_PROTO_RSN)
  633. learn_kde_keys(bss, decrypted, decrypted_len, hdr->key_rsc);
  634. else {
  635. int klen = bss->group_cipher == WPA_CIPHER_TKIP ? 32 : 16;
  636. if (decrypted_len == klen) {
  637. const u8 *rsc = hdr->key_rsc;
  638. int id;
  639. id = (key_info & WPA_KEY_INFO_KEY_INDEX_MASK) >>
  640. WPA_KEY_INFO_KEY_INDEX_SHIFT;
  641. wpa_printf(MSG_DEBUG, "GTK key index %d", id);
  642. wpa_hexdump(MSG_DEBUG, "GTK", decrypted,
  643. decrypted_len);
  644. bss->gtk_len[id] = decrypted_len;
  645. os_memcpy(bss->gtk[id], decrypted, decrypted_len);
  646. bss->rsc[id][0] = rsc[5];
  647. bss->rsc[id][1] = rsc[4];
  648. bss->rsc[id][2] = rsc[3];
  649. bss->rsc[id][3] = rsc[2];
  650. bss->rsc[id][4] = rsc[1];
  651. bss->rsc[id][5] = rsc[0];
  652. wpa_hexdump(MSG_DEBUG, "RSC", bss->rsc[id], 6);
  653. } else {
  654. wpa_printf(MSG_INFO, "Unexpected WPA Key Data length "
  655. "in Group Key msg 1/2 from " MACSTR,
  656. MAC2STR(src));
  657. }
  658. }
  659. os_free(decrypted);
  660. }
  661. static void rx_data_eapol_key_2_of_2(struct wlantest *wt, const u8 *dst,
  662. const u8 *src, const u8 *data, size_t len)
  663. {
  664. struct wlantest_bss *bss;
  665. struct wlantest_sta *sta;
  666. const struct ieee802_1x_hdr *eapol;
  667. const struct wpa_eapol_key *hdr;
  668. u16 key_info;
  669. wpa_printf(MSG_DEBUG, "EAPOL-Key 2/2 " MACSTR " -> " MACSTR,
  670. MAC2STR(src), MAC2STR(dst));
  671. bss = bss_get(wt, dst);
  672. if (bss == NULL)
  673. return;
  674. sta = sta_get(bss, src);
  675. if (sta == NULL)
  676. return;
  677. eapol = (const struct ieee802_1x_hdr *) data;
  678. hdr = (const struct wpa_eapol_key *) (eapol + 1);
  679. if (!is_zero(hdr->key_rsc, 8)) {
  680. wpa_printf(MSG_INFO, "EAPOL-Key 2/2 from " MACSTR " used "
  681. "non-zero Key RSC", MAC2STR(src));
  682. }
  683. key_info = WPA_GET_BE16(hdr->key_info);
  684. if (!sta->ptk_set) {
  685. wpa_printf(MSG_DEBUG, "No PTK known to process EAPOL-Key 2/2");
  686. return;
  687. }
  688. if (sta->ptk_set &&
  689. check_mic(sta->ptk.kck, key_info & WPA_KEY_INFO_TYPE_MASK,
  690. data, len) < 0) {
  691. wpa_printf(MSG_INFO, "Mismatch in EAPOL-Key 2/2 MIC");
  692. return;
  693. }
  694. wpa_printf(MSG_DEBUG, "Valid MIC found in EAPOL-Key 2/2");
  695. }
  696. static void rx_data_eapol_key(struct wlantest *wt, const u8 *dst,
  697. const u8 *src, const u8 *data, size_t len,
  698. int prot)
  699. {
  700. const struct ieee802_1x_hdr *eapol;
  701. const struct wpa_eapol_key *hdr;
  702. const u8 *key_data;
  703. u16 key_info, key_length, ver, key_data_length;
  704. eapol = (const struct ieee802_1x_hdr *) data;
  705. hdr = (const struct wpa_eapol_key *) (eapol + 1);
  706. wpa_hexdump(MSG_MSGDUMP, "EAPOL-Key",
  707. (const u8 *) hdr, len - sizeof(*eapol));
  708. if (len < sizeof(*hdr)) {
  709. wpa_printf(MSG_INFO, "Too short EAPOL-Key frame from " MACSTR,
  710. MAC2STR(src));
  711. return;
  712. }
  713. if (hdr->type == EAPOL_KEY_TYPE_RC4) {
  714. /* TODO: EAPOL-Key RC4 for WEP */
  715. wpa_printf(MSG_INFO, "EAPOL-Key Descriptor Type RC4 from "
  716. MACSTR, MAC2STR(src));
  717. return;
  718. }
  719. if (hdr->type != EAPOL_KEY_TYPE_RSN &&
  720. hdr->type != EAPOL_KEY_TYPE_WPA) {
  721. wpa_printf(MSG_INFO, "Unsupported EAPOL-Key Descriptor Type "
  722. "%u from " MACSTR, hdr->type, MAC2STR(src));
  723. return;
  724. }
  725. key_info = WPA_GET_BE16(hdr->key_info);
  726. key_length = WPA_GET_BE16(hdr->key_length);
  727. key_data_length = WPA_GET_BE16(hdr->key_data_length);
  728. key_data = (const u8 *) (hdr + 1);
  729. if (key_data + key_data_length > data + len) {
  730. wpa_printf(MSG_INFO, "Truncated EAPOL-Key from " MACSTR,
  731. MAC2STR(src));
  732. return;
  733. }
  734. if (key_data + key_data_length < data + len) {
  735. wpa_hexdump(MSG_DEBUG, "Extra data after EAPOL-Key Key Data "
  736. "field", key_data + key_data_length,
  737. data + len - key_data - key_data_length);
  738. }
  739. ver = key_info & WPA_KEY_INFO_TYPE_MASK;
  740. wpa_printf(MSG_DEBUG, "EAPOL-Key ver=%u %c idx=%u%s%s%s%s%s%s%s%s "
  741. "datalen=%u",
  742. ver, key_info & WPA_KEY_INFO_KEY_TYPE ? 'P' : 'G',
  743. (key_info & WPA_KEY_INFO_KEY_INDEX_MASK) >>
  744. WPA_KEY_INFO_KEY_INDEX_SHIFT,
  745. (key_info & WPA_KEY_INFO_INSTALL) ? " Install" : "",
  746. (key_info & WPA_KEY_INFO_ACK) ? " ACK" : "",
  747. (key_info & WPA_KEY_INFO_MIC) ? " MIC" : "",
  748. (key_info & WPA_KEY_INFO_SECURE) ? " Secure" : "",
  749. (key_info & WPA_KEY_INFO_ERROR) ? " Error" : "",
  750. (key_info & WPA_KEY_INFO_REQUEST) ? " Request" : "",
  751. (key_info & WPA_KEY_INFO_ENCR_KEY_DATA) ? " Encr" : "",
  752. (key_info & WPA_KEY_INFO_SMK_MESSAGE) ? " SMK" : "",
  753. key_data_length);
  754. if (ver != WPA_KEY_INFO_TYPE_HMAC_MD5_RC4 &&
  755. ver != WPA_KEY_INFO_TYPE_HMAC_SHA1_AES &&
  756. ver != WPA_KEY_INFO_TYPE_AES_128_CMAC) {
  757. wpa_printf(MSG_INFO, "Unsupported EAPOL-Key Key Descriptor "
  758. "Version %u from " MACSTR, ver, MAC2STR(src));
  759. return;
  760. }
  761. wpa_hexdump(MSG_MSGDUMP, "EAPOL-Key Replay Counter",
  762. hdr->replay_counter, WPA_REPLAY_COUNTER_LEN);
  763. wpa_hexdump(MSG_MSGDUMP, "EAPOL-Key Key Nonce",
  764. hdr->key_nonce, WPA_NONCE_LEN);
  765. wpa_hexdump(MSG_MSGDUMP, "EAPOL-Key Key IV",
  766. hdr->key_iv, 16);
  767. wpa_hexdump(MSG_MSGDUMP, "EAPOL-Key RSC",
  768. hdr->key_rsc, WPA_KEY_RSC_LEN);
  769. wpa_hexdump(MSG_MSGDUMP, "EAPOL-Key Key MIC",
  770. hdr->key_mic, 16);
  771. wpa_hexdump(MSG_MSGDUMP, "EAPOL-Key Key Data",
  772. key_data, key_data_length);
  773. if (hdr->type == EAPOL_KEY_TYPE_RSN &&
  774. (key_info & (WPA_KEY_INFO_KEY_INDEX_MASK | BIT(14) | BIT(15))) !=
  775. 0) {
  776. wpa_printf(MSG_INFO, "RSN EAPOL-Key with non-zero reserved "
  777. "Key Info bits 0x%x from " MACSTR,
  778. key_info, MAC2STR(src));
  779. }
  780. if (hdr->type == EAPOL_KEY_TYPE_WPA &&
  781. (key_info & (WPA_KEY_INFO_ENCR_KEY_DATA |
  782. WPA_KEY_INFO_SMK_MESSAGE |BIT(14) | BIT(15))) != 0) {
  783. wpa_printf(MSG_INFO, "WPA EAPOL-Key with non-zero reserved "
  784. "Key Info bits 0x%x from " MACSTR,
  785. key_info, MAC2STR(src));
  786. }
  787. if (key_length > 32) {
  788. wpa_printf(MSG_INFO, "EAPOL-Key with invalid Key Length %d "
  789. "from " MACSTR, key_length, MAC2STR(src));
  790. }
  791. if (ver != WPA_KEY_INFO_TYPE_HMAC_MD5_RC4 &&
  792. !is_zero(hdr->key_iv, 16)) {
  793. wpa_printf(MSG_INFO, "EAPOL-Key with non-zero Key IV "
  794. "(reserved with ver=%d) field from " MACSTR,
  795. ver, MAC2STR(src));
  796. wpa_hexdump(MSG_INFO, "EAPOL-Key Key IV (reserved)",
  797. hdr->key_iv, 16);
  798. }
  799. if (!is_zero(hdr->key_id, 8)) {
  800. wpa_printf(MSG_INFO, "EAPOL-Key with non-zero Key ID "
  801. "(reserved) field from " MACSTR, MAC2STR(src));
  802. wpa_hexdump(MSG_INFO, "EAPOL-Key Key ID (reserved)",
  803. hdr->key_id, 8);
  804. }
  805. if (hdr->key_rsc[6] || hdr->key_rsc[7]) {
  806. wpa_printf(MSG_INFO, "EAPOL-Key with non-zero Key RSC octets "
  807. "(last two are unused)" MACSTR, MAC2STR(src));
  808. }
  809. if (key_info & (WPA_KEY_INFO_ERROR | WPA_KEY_INFO_REQUEST))
  810. return;
  811. if (key_info & WPA_KEY_INFO_SMK_MESSAGE)
  812. return;
  813. if (key_info & WPA_KEY_INFO_KEY_TYPE) {
  814. /* 4-Way Handshake */
  815. switch (key_info & (WPA_KEY_INFO_SECURE |
  816. WPA_KEY_INFO_MIC |
  817. WPA_KEY_INFO_ACK |
  818. WPA_KEY_INFO_INSTALL)) {
  819. case WPA_KEY_INFO_ACK:
  820. rx_data_eapol_key_1_of_4(wt, dst, src, data, len);
  821. break;
  822. case WPA_KEY_INFO_MIC:
  823. if (key_data_length == 0)
  824. rx_data_eapol_key_4_of_4(wt, dst, src, data,
  825. len);
  826. else
  827. rx_data_eapol_key_2_of_4(wt, dst, src, data,
  828. len);
  829. break;
  830. case WPA_KEY_INFO_MIC | WPA_KEY_INFO_ACK |
  831. WPA_KEY_INFO_INSTALL:
  832. /* WPA does not include Secure bit in 3/4 */
  833. rx_data_eapol_key_3_of_4(wt, dst, src, data, len);
  834. break;
  835. case WPA_KEY_INFO_SECURE | WPA_KEY_INFO_MIC |
  836. WPA_KEY_INFO_ACK | WPA_KEY_INFO_INSTALL:
  837. rx_data_eapol_key_3_of_4(wt, dst, src, data, len);
  838. break;
  839. case WPA_KEY_INFO_SECURE | WPA_KEY_INFO_MIC:
  840. if (key_data_length == 0)
  841. rx_data_eapol_key_4_of_4(wt, dst, src, data,
  842. len);
  843. else
  844. rx_data_eapol_key_2_of_4(wt, dst, src, data,
  845. len);
  846. break;
  847. default:
  848. wpa_printf(MSG_DEBUG, "Unsupported EAPOL-Key frame");
  849. break;
  850. }
  851. } else {
  852. /* Group Key Handshake */
  853. switch (key_info & (WPA_KEY_INFO_SECURE |
  854. WPA_KEY_INFO_MIC |
  855. WPA_KEY_INFO_ACK)) {
  856. case WPA_KEY_INFO_SECURE | WPA_KEY_INFO_MIC |
  857. WPA_KEY_INFO_ACK:
  858. rx_data_eapol_key_1_of_2(wt, dst, src, data, len);
  859. break;
  860. case WPA_KEY_INFO_SECURE | WPA_KEY_INFO_MIC:
  861. rx_data_eapol_key_2_of_2(wt, dst, src, data, len);
  862. break;
  863. default:
  864. wpa_printf(MSG_DEBUG, "Unsupported EAPOL-Key frame");
  865. break;
  866. }
  867. }
  868. }
  869. void rx_data_eapol(struct wlantest *wt, const u8 *dst, const u8 *src,
  870. const u8 *data, size_t len, int prot)
  871. {
  872. const struct ieee802_1x_hdr *hdr;
  873. u16 length;
  874. const u8 *p;
  875. wpa_hexdump(MSG_EXCESSIVE, "EAPOL", data, len);
  876. if (len < sizeof(*hdr)) {
  877. wpa_printf(MSG_INFO, "Too short EAPOL frame from " MACSTR,
  878. MAC2STR(src));
  879. return;
  880. }
  881. hdr = (const struct ieee802_1x_hdr *) data;
  882. length = be_to_host16(hdr->length);
  883. wpa_printf(MSG_DEBUG, "RX EAPOL: " MACSTR " -> " MACSTR "%s ver=%u "
  884. "type=%u len=%u",
  885. MAC2STR(src), MAC2STR(dst), prot ? " Prot" : "",
  886. hdr->version, hdr->type, length);
  887. if (hdr->version < 1 || hdr->version > 3) {
  888. wpa_printf(MSG_INFO, "Unexpected EAPOL version %u from "
  889. MACSTR, hdr->version, MAC2STR(src));
  890. }
  891. if (sizeof(*hdr) + length > len) {
  892. wpa_printf(MSG_INFO, "Truncated EAPOL frame from " MACSTR,
  893. MAC2STR(src));
  894. return;
  895. }
  896. if (sizeof(*hdr) + length < len) {
  897. wpa_printf(MSG_INFO, "EAPOL frame with %d extra bytes",
  898. (int) (len - sizeof(*hdr) - length));
  899. }
  900. p = (const u8 *) (hdr + 1);
  901. switch (hdr->type) {
  902. case IEEE802_1X_TYPE_EAP_PACKET:
  903. wpa_hexdump(MSG_MSGDUMP, "EAPOL - EAP packet", p, length);
  904. break;
  905. case IEEE802_1X_TYPE_EAPOL_START:
  906. wpa_hexdump(MSG_MSGDUMP, "EAPOL-Start", p, length);
  907. break;
  908. case IEEE802_1X_TYPE_EAPOL_LOGOFF:
  909. wpa_hexdump(MSG_MSGDUMP, "EAPOL-Logoff", p, length);
  910. break;
  911. case IEEE802_1X_TYPE_EAPOL_KEY:
  912. rx_data_eapol_key(wt, dst, src, data, sizeof(*hdr) + length,
  913. prot);
  914. break;
  915. case IEEE802_1X_TYPE_EAPOL_ENCAPSULATED_ASF_ALERT:
  916. wpa_hexdump(MSG_MSGDUMP, "EAPOL - Encapsulated ASF alert",
  917. p, length);
  918. break;
  919. default:
  920. wpa_hexdump(MSG_MSGDUMP, "Unknown EAPOL payload", p, length);
  921. break;
  922. }
  923. }