rx_data.c 29 KB

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