rx_data.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. /*
  2. * Received Data frame processing
  3. * Copyright (c) 2010, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "utils/includes.h"
  9. #include <linux/if_ether.h>
  10. #include "utils/common.h"
  11. #include "common/defs.h"
  12. #include "common/ieee802_11_defs.h"
  13. #include "wlantest.h"
  14. extern int wpa_debug_level;
  15. static const char * data_stype(u16 stype)
  16. {
  17. switch (stype) {
  18. case WLAN_FC_STYPE_DATA:
  19. return "DATA";
  20. case WLAN_FC_STYPE_DATA_CFACK:
  21. return "DATA-CFACK";
  22. case WLAN_FC_STYPE_DATA_CFPOLL:
  23. return "DATA-CFPOLL";
  24. case WLAN_FC_STYPE_DATA_CFACKPOLL:
  25. return "DATA-CFACKPOLL";
  26. case WLAN_FC_STYPE_NULLFUNC:
  27. return "NULLFUNC";
  28. case WLAN_FC_STYPE_CFACK:
  29. return "CFACK";
  30. case WLAN_FC_STYPE_CFPOLL:
  31. return "CFPOLL";
  32. case WLAN_FC_STYPE_CFACKPOLL:
  33. return "CFACKPOLL";
  34. case WLAN_FC_STYPE_QOS_DATA:
  35. return "QOSDATA";
  36. case WLAN_FC_STYPE_QOS_DATA_CFACK:
  37. return "QOSDATA-CFACK";
  38. case WLAN_FC_STYPE_QOS_DATA_CFPOLL:
  39. return "QOSDATA-CFPOLL";
  40. case WLAN_FC_STYPE_QOS_DATA_CFACKPOLL:
  41. return "QOSDATA-CFACKPOLL";
  42. case WLAN_FC_STYPE_QOS_NULL:
  43. return "QOS-NULL";
  44. case WLAN_FC_STYPE_QOS_CFPOLL:
  45. return "QOS-CFPOLL";
  46. case WLAN_FC_STYPE_QOS_CFACKPOLL:
  47. return "QOS-CFACKPOLL";
  48. }
  49. return "??";
  50. }
  51. static void rx_data_eth(struct wlantest *wt, const u8 *bssid,
  52. const u8 *sta_addr, const u8 *dst, const u8 *src,
  53. u16 ethertype, const u8 *data, size_t len, int prot,
  54. const u8 *peer_addr)
  55. {
  56. switch (ethertype) {
  57. case ETH_P_PAE:
  58. rx_data_eapol(wt, dst, src, data, len, prot);
  59. break;
  60. case ETH_P_IP:
  61. rx_data_ip(wt, bssid, sta_addr, dst, src, data, len,
  62. peer_addr);
  63. break;
  64. case 0x890d:
  65. rx_data_80211_encap(wt, bssid, sta_addr, dst, src, data, len);
  66. break;
  67. }
  68. }
  69. static void rx_data_process(struct wlantest *wt, const u8 *bssid,
  70. const u8 *sta_addr,
  71. const u8 *dst, const u8 *src,
  72. const u8 *data, size_t len, int prot,
  73. const u8 *peer_addr)
  74. {
  75. if (len == 0)
  76. return;
  77. if (len >= 8 && os_memcmp(data, "\xaa\xaa\x03\x00\x00\x00", 6) == 0) {
  78. rx_data_eth(wt, bssid, sta_addr, dst, src,
  79. WPA_GET_BE16(data + 6), data + 8, len - 8, prot,
  80. peer_addr);
  81. return;
  82. }
  83. wpa_hexdump(MSG_DEBUG, "Unrecognized LLC", data, len > 8 ? 8 : len);
  84. }
  85. static u8 * try_all_ptk(struct wlantest *wt, int pairwise_cipher,
  86. const struct ieee80211_hdr *hdr,
  87. const u8 *data, size_t data_len, size_t *decrypted_len)
  88. {
  89. struct wlantest_ptk *ptk;
  90. u8 *decrypted;
  91. int prev_level = wpa_debug_level;
  92. wpa_debug_level = MSG_WARNING;
  93. dl_list_for_each(ptk, &wt->ptk, struct wlantest_ptk, list) {
  94. decrypted = NULL;
  95. if ((pairwise_cipher == WPA_CIPHER_CCMP ||
  96. pairwise_cipher == 0) && ptk->ptk_len == 48) {
  97. decrypted = ccmp_decrypt(ptk->ptk.tk1, hdr, data,
  98. data_len, decrypted_len);
  99. }
  100. if ((pairwise_cipher == WPA_CIPHER_TKIP ||
  101. pairwise_cipher == 0) && ptk->ptk_len == 64) {
  102. decrypted = tkip_decrypt(ptk->ptk.tk1, hdr, data,
  103. data_len, decrypted_len);
  104. }
  105. if (decrypted) {
  106. wpa_debug_level = prev_level;
  107. add_note(wt, MSG_DEBUG, "Found PTK match from list of all known PTKs");
  108. return decrypted;
  109. }
  110. }
  111. wpa_debug_level = prev_level;
  112. return NULL;
  113. }
  114. static void rx_data_bss_prot_group(struct wlantest *wt,
  115. const struct ieee80211_hdr *hdr,
  116. const u8 *qos, const u8 *dst, const u8 *src,
  117. const u8 *data, size_t len)
  118. {
  119. struct wlantest_bss *bss;
  120. int keyid;
  121. u8 *decrypted;
  122. size_t dlen;
  123. u8 pn[6];
  124. bss = bss_get(wt, hdr->addr2);
  125. if (bss == NULL)
  126. return;
  127. if (len < 4) {
  128. add_note(wt, MSG_INFO, "Too short group addressed data frame");
  129. return;
  130. }
  131. if (bss->group_cipher & (WPA_CIPHER_TKIP | WPA_CIPHER_CCMP) &&
  132. !(data[3] & 0x20)) {
  133. add_note(wt, MSG_INFO, "Expected TKIP/CCMP frame from "
  134. MACSTR " did not have ExtIV bit set to 1",
  135. MAC2STR(bss->bssid));
  136. return;
  137. }
  138. if (bss->group_cipher == WPA_CIPHER_TKIP) {
  139. if (data[3] & 0x1f) {
  140. add_note(wt, MSG_INFO, "TKIP frame from " MACSTR
  141. " used non-zero reserved bit",
  142. MAC2STR(bss->bssid));
  143. }
  144. if (data[1] != ((data[0] | 0x20) & 0x7f)) {
  145. add_note(wt, MSG_INFO, "TKIP frame from " MACSTR
  146. " used incorrect WEPSeed[1] (was 0x%x, "
  147. "expected 0x%x)",
  148. MAC2STR(bss->bssid), data[1],
  149. (data[0] | 0x20) & 0x7f);
  150. }
  151. } else if (bss->group_cipher == WPA_CIPHER_CCMP) {
  152. if (data[2] != 0 || (data[3] & 0x1f) != 0) {
  153. add_note(wt, MSG_INFO, "CCMP frame from " MACSTR
  154. " used non-zero reserved bit",
  155. MAC2STR(bss->bssid));
  156. }
  157. }
  158. keyid = data[3] >> 6;
  159. if (bss->gtk_len[keyid] == 0 && bss->group_cipher != WPA_CIPHER_WEP40)
  160. {
  161. add_note(wt, MSG_MSGDUMP, "No GTK known to decrypt the frame "
  162. "(A2=" MACSTR " KeyID=%d)",
  163. MAC2STR(hdr->addr2), keyid);
  164. return;
  165. }
  166. if (bss->group_cipher == WPA_CIPHER_TKIP)
  167. tkip_get_pn(pn, data);
  168. else if (bss->group_cipher == WPA_CIPHER_WEP40)
  169. goto skip_replay_det;
  170. else
  171. ccmp_get_pn(pn, data);
  172. if (os_memcmp(pn, bss->rsc[keyid], 6) <= 0) {
  173. u16 seq_ctrl = le_to_host16(hdr->seq_ctrl);
  174. add_note(wt, MSG_INFO, "CCMP/TKIP replay detected: A1=" MACSTR
  175. " A2=" MACSTR " A3=" MACSTR " seq=%u frag=%u",
  176. MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
  177. MAC2STR(hdr->addr3),
  178. WLAN_GET_SEQ_SEQ(seq_ctrl),
  179. WLAN_GET_SEQ_FRAG(seq_ctrl));
  180. wpa_hexdump(MSG_INFO, "RX PN", pn, 6);
  181. wpa_hexdump(MSG_INFO, "RSC", bss->rsc[keyid], 6);
  182. }
  183. skip_replay_det:
  184. if (bss->group_cipher == WPA_CIPHER_TKIP)
  185. decrypted = tkip_decrypt(bss->gtk[keyid], hdr, data, len,
  186. &dlen);
  187. else if (bss->group_cipher == WPA_CIPHER_WEP40)
  188. decrypted = wep_decrypt(wt, hdr, data, len, &dlen);
  189. else
  190. decrypted = ccmp_decrypt(bss->gtk[keyid], hdr, data, len,
  191. &dlen);
  192. if (decrypted) {
  193. rx_data_process(wt, bss->bssid, NULL, dst, src, decrypted,
  194. dlen, 1, NULL);
  195. os_memcpy(bss->rsc[keyid], pn, 6);
  196. write_pcap_decrypted(wt, (const u8 *) hdr, 24 + (qos ? 2 : 0),
  197. decrypted, dlen);
  198. } else
  199. add_note(wt, MSG_DEBUG, "Failed to decrypt frame");
  200. os_free(decrypted);
  201. }
  202. static void rx_data_bss_prot(struct wlantest *wt,
  203. const struct ieee80211_hdr *hdr, const u8 *qos,
  204. const u8 *dst, const u8 *src, const u8 *data,
  205. size_t len)
  206. {
  207. struct wlantest_bss *bss;
  208. struct wlantest_sta *sta, *sta2;
  209. int keyid;
  210. u16 fc = le_to_host16(hdr->frame_control);
  211. u8 *decrypted;
  212. size_t dlen;
  213. int tid;
  214. u8 pn[6], *rsc;
  215. struct wlantest_tdls *tdls = NULL, *found;
  216. const u8 *tk = NULL;
  217. int ptk_iter_done = 0;
  218. int try_ptk_iter = 0;
  219. if (hdr->addr1[0] & 0x01) {
  220. rx_data_bss_prot_group(wt, hdr, qos, dst, src, data, len);
  221. return;
  222. }
  223. if (fc & WLAN_FC_TODS) {
  224. bss = bss_get(wt, hdr->addr1);
  225. if (bss == NULL)
  226. return;
  227. sta = sta_get(bss, hdr->addr2);
  228. if (sta)
  229. sta->counters[WLANTEST_STA_COUNTER_PROT_DATA_TX]++;
  230. } else if (fc & WLAN_FC_FROMDS) {
  231. bss = bss_get(wt, hdr->addr2);
  232. if (bss == NULL)
  233. return;
  234. sta = sta_get(bss, hdr->addr1);
  235. } else {
  236. bss = bss_get(wt, hdr->addr3);
  237. if (bss == NULL)
  238. return;
  239. sta = sta_find(bss, hdr->addr2);
  240. sta2 = sta_find(bss, hdr->addr1);
  241. if (sta == NULL || sta2 == NULL)
  242. return;
  243. found = NULL;
  244. dl_list_for_each(tdls, &bss->tdls, struct wlantest_tdls, list)
  245. {
  246. if ((tdls->init == sta && tdls->resp == sta2) ||
  247. (tdls->init == sta2 && tdls->resp == sta)) {
  248. found = tdls;
  249. if (tdls->link_up)
  250. break;
  251. }
  252. }
  253. if (found) {
  254. if (!found->link_up)
  255. add_note(wt, MSG_DEBUG,
  256. "TDLS: Link not up, but Data "
  257. "frame seen");
  258. tk = found->tpk.tk;
  259. tdls = found;
  260. }
  261. }
  262. if ((sta == NULL ||
  263. (!sta->ptk_set && sta->pairwise_cipher != WPA_CIPHER_WEP40)) &&
  264. tk == NULL) {
  265. add_note(wt, MSG_MSGDUMP, "No PTK known to decrypt the frame");
  266. if (dl_list_empty(&wt->ptk))
  267. return;
  268. try_ptk_iter = 1;
  269. }
  270. if (len < 4) {
  271. add_note(wt, MSG_INFO, "Too short encrypted data frame");
  272. return;
  273. }
  274. if (sta == NULL)
  275. return;
  276. if (sta->pairwise_cipher & (WPA_CIPHER_TKIP | WPA_CIPHER_CCMP) &&
  277. !(data[3] & 0x20)) {
  278. add_note(wt, MSG_INFO, "Expected TKIP/CCMP frame from "
  279. MACSTR " did not have ExtIV bit set to 1",
  280. MAC2STR(src));
  281. return;
  282. }
  283. if (tk == NULL && sta->pairwise_cipher == WPA_CIPHER_TKIP) {
  284. if (data[3] & 0x1f) {
  285. add_note(wt, MSG_INFO, "TKIP frame from " MACSTR
  286. " used non-zero reserved bit",
  287. MAC2STR(hdr->addr2));
  288. }
  289. if (data[1] != ((data[0] | 0x20) & 0x7f)) {
  290. add_note(wt, MSG_INFO, "TKIP frame from " MACSTR
  291. " used incorrect WEPSeed[1] (was 0x%x, "
  292. "expected 0x%x)",
  293. MAC2STR(hdr->addr2), data[1],
  294. (data[0] | 0x20) & 0x7f);
  295. }
  296. } else if (tk || sta->pairwise_cipher == WPA_CIPHER_CCMP) {
  297. if (data[2] != 0 || (data[3] & 0x1f) != 0) {
  298. add_note(wt, MSG_INFO, "CCMP frame from " MACSTR
  299. " used non-zero reserved bit",
  300. MAC2STR(hdr->addr2));
  301. }
  302. }
  303. keyid = data[3] >> 6;
  304. if (keyid != 0) {
  305. add_note(wt, MSG_INFO, "Unexpected non-zero KeyID %d in "
  306. "individually addressed Data frame from " MACSTR,
  307. keyid, MAC2STR(hdr->addr2));
  308. }
  309. if (qos) {
  310. tid = qos[0] & 0x0f;
  311. if (fc & WLAN_FC_TODS)
  312. sta->tx_tid[tid]++;
  313. else
  314. sta->rx_tid[tid]++;
  315. } else {
  316. tid = 0;
  317. if (fc & WLAN_FC_TODS)
  318. sta->tx_tid[16]++;
  319. else
  320. sta->rx_tid[16]++;
  321. }
  322. if (tk) {
  323. if (os_memcmp(hdr->addr2, tdls->init->addr, ETH_ALEN) == 0)
  324. rsc = tdls->rsc_init[tid];
  325. else
  326. rsc = tdls->rsc_resp[tid];
  327. } else if (fc & WLAN_FC_TODS)
  328. rsc = sta->rsc_tods[tid];
  329. else
  330. rsc = sta->rsc_fromds[tid];
  331. if (tk == NULL && sta->pairwise_cipher == WPA_CIPHER_TKIP)
  332. tkip_get_pn(pn, data);
  333. else if (sta->pairwise_cipher == WPA_CIPHER_WEP40)
  334. goto skip_replay_det;
  335. else
  336. ccmp_get_pn(pn, data);
  337. if (os_memcmp(pn, rsc, 6) <= 0) {
  338. u16 seq_ctrl = le_to_host16(hdr->seq_ctrl);
  339. add_note(wt, MSG_INFO, "CCMP/TKIP replay detected: A1=" MACSTR
  340. " A2=" MACSTR " A3=" MACSTR " seq=%u frag=%u",
  341. MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
  342. MAC2STR(hdr->addr3),
  343. WLAN_GET_SEQ_SEQ(seq_ctrl),
  344. WLAN_GET_SEQ_FRAG(seq_ctrl));
  345. wpa_hexdump(MSG_INFO, "RX PN", pn, 6);
  346. wpa_hexdump(MSG_INFO, "RSC", rsc, 6);
  347. }
  348. skip_replay_det:
  349. if (tk)
  350. decrypted = ccmp_decrypt(tk, hdr, data, len, &dlen);
  351. else if (sta->pairwise_cipher == WPA_CIPHER_TKIP)
  352. decrypted = tkip_decrypt(sta->ptk.tk1, hdr, data, len, &dlen);
  353. else if (sta->pairwise_cipher == WPA_CIPHER_WEP40)
  354. decrypted = wep_decrypt(wt, hdr, data, len, &dlen);
  355. else if (sta->ptk_set)
  356. decrypted = ccmp_decrypt(sta->ptk.tk1, hdr, data, len, &dlen);
  357. else {
  358. decrypted = try_all_ptk(wt, sta->pairwise_cipher, hdr, data,
  359. len, &dlen);
  360. ptk_iter_done = 1;
  361. }
  362. if (!decrypted && !ptk_iter_done) {
  363. decrypted = try_all_ptk(wt, sta->pairwise_cipher, hdr, data,
  364. len, &dlen);
  365. if (decrypted) {
  366. add_note(wt, MSG_DEBUG, "Current PTK did not work, but found a match from all known PTKs");
  367. }
  368. }
  369. if (decrypted) {
  370. u16 fc = le_to_host16(hdr->frame_control);
  371. const u8 *peer_addr = NULL;
  372. if (!(fc & (WLAN_FC_FROMDS | WLAN_FC_TODS)))
  373. peer_addr = hdr->addr1;
  374. os_memcpy(rsc, pn, 6);
  375. rx_data_process(wt, bss->bssid, sta->addr, dst, src, decrypted,
  376. dlen, 1, peer_addr);
  377. write_pcap_decrypted(wt, (const u8 *) hdr, 24 + (qos ? 2 : 0),
  378. decrypted, dlen);
  379. } else if (!try_ptk_iter)
  380. add_note(wt, MSG_DEBUG, "Failed to decrypt frame");
  381. os_free(decrypted);
  382. }
  383. static void rx_data_bss(struct wlantest *wt, const struct ieee80211_hdr *hdr,
  384. const u8 *qos, const u8 *dst, const u8 *src,
  385. const u8 *data, size_t len)
  386. {
  387. u16 fc = le_to_host16(hdr->frame_control);
  388. int prot = !!(fc & WLAN_FC_ISWEP);
  389. if (qos) {
  390. u8 ack = (qos[0] & 0x60) >> 5;
  391. wpa_printf(MSG_MSGDUMP, "BSS DATA: " MACSTR " -> " MACSTR
  392. " len=%u%s tid=%u%s%s",
  393. MAC2STR(src), MAC2STR(dst), (unsigned int) len,
  394. prot ? " Prot" : "", qos[0] & 0x0f,
  395. (qos[0] & 0x10) ? " EOSP" : "",
  396. ack == 0 ? "" :
  397. (ack == 1 ? " NoAck" :
  398. (ack == 2 ? " NoExpAck" : " BA")));
  399. } else {
  400. wpa_printf(MSG_MSGDUMP, "BSS DATA: " MACSTR " -> " MACSTR
  401. " len=%u%s",
  402. MAC2STR(src), MAC2STR(dst), (unsigned int) len,
  403. prot ? " Prot" : "");
  404. }
  405. if (prot)
  406. rx_data_bss_prot(wt, hdr, qos, dst, src, data, len);
  407. else {
  408. const u8 *bssid, *sta_addr, *peer_addr;
  409. struct wlantest_bss *bss;
  410. if (fc & WLAN_FC_TODS) {
  411. bssid = hdr->addr1;
  412. sta_addr = hdr->addr2;
  413. peer_addr = NULL;
  414. } else if (fc & WLAN_FC_FROMDS) {
  415. bssid = hdr->addr2;
  416. sta_addr = hdr->addr1;
  417. peer_addr = NULL;
  418. } else {
  419. bssid = hdr->addr3;
  420. sta_addr = hdr->addr2;
  421. peer_addr = hdr->addr1;
  422. }
  423. bss = bss_get(wt, bssid);
  424. if (bss) {
  425. struct wlantest_sta *sta = sta_get(bss, sta_addr);
  426. if (sta) {
  427. if (qos) {
  428. int tid = qos[0] & 0x0f;
  429. if (fc & WLAN_FC_TODS)
  430. sta->tx_tid[tid]++;
  431. else
  432. sta->rx_tid[tid]++;
  433. } else {
  434. if (fc & WLAN_FC_TODS)
  435. sta->tx_tid[16]++;
  436. else
  437. sta->rx_tid[16]++;
  438. }
  439. }
  440. }
  441. rx_data_process(wt, bssid, sta_addr, dst, src, data, len, 0,
  442. peer_addr);
  443. }
  444. }
  445. static struct wlantest_tdls * get_tdls(struct wlantest *wt, const u8 *bssid,
  446. const u8 *sta1_addr,
  447. const u8 *sta2_addr)
  448. {
  449. struct wlantest_bss *bss;
  450. struct wlantest_sta *sta1, *sta2;
  451. struct wlantest_tdls *tdls, *found = NULL;
  452. bss = bss_find(wt, bssid);
  453. if (bss == NULL)
  454. return NULL;
  455. sta1 = sta_find(bss, sta1_addr);
  456. if (sta1 == NULL)
  457. return NULL;
  458. sta2 = sta_find(bss, sta2_addr);
  459. if (sta2 == NULL)
  460. return NULL;
  461. dl_list_for_each(tdls, &bss->tdls, struct wlantest_tdls, list) {
  462. if ((tdls->init == sta1 && tdls->resp == sta2) ||
  463. (tdls->init == sta2 && tdls->resp == sta1)) {
  464. found = tdls;
  465. if (tdls->link_up)
  466. break;
  467. }
  468. }
  469. return found;
  470. }
  471. static void add_direct_link(struct wlantest *wt, const u8 *bssid,
  472. const u8 *sta1_addr, const u8 *sta2_addr)
  473. {
  474. struct wlantest_tdls *tdls;
  475. tdls = get_tdls(wt, bssid, sta1_addr, sta2_addr);
  476. if (tdls == NULL)
  477. return;
  478. if (tdls->link_up)
  479. tdls->counters[WLANTEST_TDLS_COUNTER_VALID_DIRECT_LINK]++;
  480. else
  481. tdls->counters[WLANTEST_TDLS_COUNTER_INVALID_DIRECT_LINK]++;
  482. }
  483. static void add_ap_path(struct wlantest *wt, const u8 *bssid,
  484. const u8 *sta1_addr, const u8 *sta2_addr)
  485. {
  486. struct wlantest_tdls *tdls;
  487. tdls = get_tdls(wt, bssid, sta1_addr, sta2_addr);
  488. if (tdls == NULL)
  489. return;
  490. if (tdls->link_up)
  491. tdls->counters[WLANTEST_TDLS_COUNTER_INVALID_AP_PATH]++;
  492. else
  493. tdls->counters[WLANTEST_TDLS_COUNTER_VALID_AP_PATH]++;
  494. }
  495. void rx_data(struct wlantest *wt, const u8 *data, size_t len)
  496. {
  497. const struct ieee80211_hdr *hdr;
  498. u16 fc, stype;
  499. size_t hdrlen;
  500. const u8 *qos = NULL;
  501. if (len < 24)
  502. return;
  503. hdr = (const struct ieee80211_hdr *) data;
  504. fc = le_to_host16(hdr->frame_control);
  505. stype = WLAN_FC_GET_STYPE(fc);
  506. hdrlen = 24;
  507. if ((fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) ==
  508. (WLAN_FC_TODS | WLAN_FC_FROMDS))
  509. hdrlen += ETH_ALEN;
  510. if (stype & 0x08) {
  511. qos = data + hdrlen;
  512. hdrlen += 2;
  513. }
  514. if (len < hdrlen)
  515. return;
  516. wt->rx_data++;
  517. switch (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) {
  518. case 0:
  519. wpa_printf(MSG_EXCESSIVE, "DATA %s%s%s IBSS DA=" MACSTR " SA="
  520. MACSTR " BSSID=" MACSTR,
  521. data_stype(WLAN_FC_GET_STYPE(fc)),
  522. fc & WLAN_FC_PWRMGT ? " PwrMgt" : "",
  523. fc & WLAN_FC_ISWEP ? " Prot" : "",
  524. MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
  525. MAC2STR(hdr->addr3));
  526. add_direct_link(wt, hdr->addr3, hdr->addr1, hdr->addr2);
  527. rx_data_bss(wt, hdr, qos, hdr->addr1, hdr->addr2,
  528. data + hdrlen, len - hdrlen);
  529. break;
  530. case WLAN_FC_FROMDS:
  531. wpa_printf(MSG_EXCESSIVE, "DATA %s%s%s FromDS DA=" MACSTR
  532. " BSSID=" MACSTR " SA=" MACSTR,
  533. data_stype(WLAN_FC_GET_STYPE(fc)),
  534. fc & WLAN_FC_PWRMGT ? " PwrMgt" : "",
  535. fc & WLAN_FC_ISWEP ? " Prot" : "",
  536. MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
  537. MAC2STR(hdr->addr3));
  538. add_ap_path(wt, hdr->addr2, hdr->addr1, hdr->addr3);
  539. rx_data_bss(wt, hdr, qos, hdr->addr1, hdr->addr3,
  540. data + hdrlen, len - hdrlen);
  541. break;
  542. case WLAN_FC_TODS:
  543. wpa_printf(MSG_EXCESSIVE, "DATA %s%s%s ToDS BSSID=" MACSTR
  544. " SA=" MACSTR " DA=" MACSTR,
  545. data_stype(WLAN_FC_GET_STYPE(fc)),
  546. fc & WLAN_FC_PWRMGT ? " PwrMgt" : "",
  547. fc & WLAN_FC_ISWEP ? " Prot" : "",
  548. MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
  549. MAC2STR(hdr->addr3));
  550. add_ap_path(wt, hdr->addr1, hdr->addr3, hdr->addr2);
  551. rx_data_bss(wt, hdr, qos, hdr->addr3, hdr->addr2,
  552. data + hdrlen, len - hdrlen);
  553. break;
  554. case WLAN_FC_TODS | WLAN_FC_FROMDS:
  555. wpa_printf(MSG_EXCESSIVE, "DATA %s%s%s WDS RA=" MACSTR " TA="
  556. MACSTR " DA=" MACSTR " SA=" MACSTR,
  557. data_stype(WLAN_FC_GET_STYPE(fc)),
  558. fc & WLAN_FC_PWRMGT ? " PwrMgt" : "",
  559. fc & WLAN_FC_ISWEP ? " Prot" : "",
  560. MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
  561. MAC2STR(hdr->addr3),
  562. MAC2STR((const u8 *) (hdr + 1)));
  563. break;
  564. }
  565. }