rx_mgmt.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176
  1. /*
  2. * Received Management 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 "utils/common.h"
  10. #include "common/ieee802_11_defs.h"
  11. #include "common/ieee802_11_common.h"
  12. #include "crypto/aes_wrap.h"
  13. #include "wlantest.h"
  14. static const char * mgmt_stype(u16 stype)
  15. {
  16. switch (stype) {
  17. case WLAN_FC_STYPE_ASSOC_REQ:
  18. return "ASSOC-REQ";
  19. case WLAN_FC_STYPE_ASSOC_RESP:
  20. return "ASSOC-RESP";
  21. case WLAN_FC_STYPE_REASSOC_REQ:
  22. return "REASSOC-REQ";
  23. case WLAN_FC_STYPE_REASSOC_RESP:
  24. return "REASSOC-RESP";
  25. case WLAN_FC_STYPE_PROBE_REQ:
  26. return "PROBE-REQ";
  27. case WLAN_FC_STYPE_PROBE_RESP:
  28. return "PROBE-RESP";
  29. case WLAN_FC_STYPE_BEACON:
  30. return "BEACON";
  31. case WLAN_FC_STYPE_ATIM:
  32. return "ATIM";
  33. case WLAN_FC_STYPE_DISASSOC:
  34. return "DISASSOC";
  35. case WLAN_FC_STYPE_AUTH:
  36. return "AUTH";
  37. case WLAN_FC_STYPE_DEAUTH:
  38. return "DEAUTH";
  39. case WLAN_FC_STYPE_ACTION:
  40. return "ACTION";
  41. }
  42. return "??";
  43. }
  44. static void rx_mgmt_beacon(struct wlantest *wt, const u8 *data, size_t len)
  45. {
  46. const struct ieee80211_mgmt *mgmt;
  47. struct wlantest_bss *bss;
  48. struct ieee802_11_elems elems;
  49. mgmt = (const struct ieee80211_mgmt *) data;
  50. bss = bss_get(wt, mgmt->bssid);
  51. if (bss == NULL)
  52. return;
  53. if (bss->proberesp_seen)
  54. return; /* do not override with Beacon data */
  55. bss->capab_info = le_to_host16(mgmt->u.beacon.capab_info);
  56. if (ieee802_11_parse_elems(mgmt->u.beacon.variable,
  57. len - (mgmt->u.beacon.variable - data),
  58. &elems, 0) == ParseFailed) {
  59. if (bss->parse_error_reported)
  60. return;
  61. add_note(wt, MSG_INFO, "Invalid IEs in a Beacon frame from "
  62. MACSTR, MAC2STR(mgmt->sa));
  63. bss->parse_error_reported = 1;
  64. return;
  65. }
  66. bss_update(wt, bss, &elems);
  67. }
  68. static void rx_mgmt_probe_resp(struct wlantest *wt, const u8 *data, size_t len)
  69. {
  70. const struct ieee80211_mgmt *mgmt;
  71. struct wlantest_bss *bss;
  72. struct ieee802_11_elems elems;
  73. mgmt = (const struct ieee80211_mgmt *) data;
  74. bss = bss_get(wt, mgmt->bssid);
  75. if (bss == NULL)
  76. return;
  77. bss->counters[WLANTEST_BSS_COUNTER_PROBE_RESPONSE]++;
  78. bss->capab_info = le_to_host16(mgmt->u.probe_resp.capab_info);
  79. if (ieee802_11_parse_elems(mgmt->u.probe_resp.variable,
  80. len - (mgmt->u.probe_resp.variable - data),
  81. &elems, 0) == ParseFailed) {
  82. if (bss->parse_error_reported)
  83. return;
  84. add_note(wt, MSG_INFO, "Invalid IEs in a Probe Response frame "
  85. "from " MACSTR, MAC2STR(mgmt->sa));
  86. bss->parse_error_reported = 1;
  87. return;
  88. }
  89. bss_update(wt, bss, &elems);
  90. }
  91. static void rx_mgmt_auth(struct wlantest *wt, const u8 *data, size_t len)
  92. {
  93. const struct ieee80211_mgmt *mgmt;
  94. struct wlantest_bss *bss;
  95. struct wlantest_sta *sta;
  96. u16 alg, trans, status;
  97. mgmt = (const struct ieee80211_mgmt *) data;
  98. bss = bss_get(wt, mgmt->bssid);
  99. if (bss == NULL)
  100. return;
  101. if (os_memcmp(mgmt->sa, mgmt->bssid, ETH_ALEN) == 0)
  102. sta = sta_get(bss, mgmt->da);
  103. else
  104. sta = sta_get(bss, mgmt->sa);
  105. if (sta == NULL)
  106. return;
  107. if (len < 24 + 6) {
  108. add_note(wt, MSG_INFO, "Too short Authentication frame from "
  109. MACSTR, MAC2STR(mgmt->sa));
  110. return;
  111. }
  112. alg = le_to_host16(mgmt->u.auth.auth_alg);
  113. trans = le_to_host16(mgmt->u.auth.auth_transaction);
  114. status = le_to_host16(mgmt->u.auth.status_code);
  115. wpa_printf(MSG_DEBUG, "AUTH " MACSTR " -> " MACSTR
  116. " (alg=%u trans=%u status=%u)",
  117. MAC2STR(mgmt->sa), MAC2STR(mgmt->da), alg, trans, status);
  118. if (alg == 0 && trans == 2 && status == 0) {
  119. if (sta->state == STATE1) {
  120. add_note(wt, MSG_DEBUG, "STA " MACSTR
  121. " moved to State 2 with " MACSTR,
  122. MAC2STR(sta->addr), MAC2STR(bss->bssid));
  123. sta->state = STATE2;
  124. }
  125. }
  126. if (os_memcmp(mgmt->sa, mgmt->bssid, ETH_ALEN) == 0)
  127. sta->counters[WLANTEST_STA_COUNTER_AUTH_RX]++;
  128. else
  129. sta->counters[WLANTEST_STA_COUNTER_AUTH_TX]++;
  130. }
  131. static void deauth_all_stas(struct wlantest *wt, struct wlantest_bss *bss)
  132. {
  133. struct wlantest_sta *sta;
  134. dl_list_for_each(sta, &bss->sta, struct wlantest_sta, list) {
  135. if (sta->state == STATE1)
  136. continue;
  137. add_note(wt, MSG_DEBUG, "STA " MACSTR
  138. " moved to State 1 with " MACSTR,
  139. MAC2STR(sta->addr), MAC2STR(bss->bssid));
  140. sta->state = STATE1;
  141. }
  142. }
  143. static void tdls_link_down(struct wlantest *wt, struct wlantest_bss *bss,
  144. struct wlantest_sta *sta)
  145. {
  146. struct wlantest_tdls *tdls;
  147. dl_list_for_each(tdls, &bss->tdls, struct wlantest_tdls, list) {
  148. if ((tdls->init == sta || tdls->resp == sta) && tdls->link_up)
  149. {
  150. add_note(wt, MSG_DEBUG, "TDLS: Set link down based on "
  151. "STA deauth/disassoc");
  152. tdls->link_up = 0;
  153. }
  154. }
  155. }
  156. static void rx_mgmt_deauth(struct wlantest *wt, const u8 *data, size_t len,
  157. int valid)
  158. {
  159. const struct ieee80211_mgmt *mgmt;
  160. struct wlantest_bss *bss;
  161. struct wlantest_sta *sta;
  162. u16 fc, reason;
  163. mgmt = (const struct ieee80211_mgmt *) data;
  164. bss = bss_get(wt, mgmt->bssid);
  165. if (bss == NULL)
  166. return;
  167. if (os_memcmp(mgmt->sa, mgmt->bssid, ETH_ALEN) == 0)
  168. sta = sta_get(bss, mgmt->da);
  169. else
  170. sta = sta_get(bss, mgmt->sa);
  171. if (len < 24 + 2) {
  172. add_note(wt, MSG_INFO, "Too short Deauthentication frame from "
  173. MACSTR, MAC2STR(mgmt->sa));
  174. return;
  175. }
  176. reason = le_to_host16(mgmt->u.deauth.reason_code);
  177. wpa_printf(MSG_DEBUG, "DEAUTH " MACSTR " -> " MACSTR
  178. " (reason=%u) (valid=%d)",
  179. MAC2STR(mgmt->sa), MAC2STR(mgmt->da),
  180. reason, valid);
  181. wpa_hexdump(MSG_MSGDUMP, "DEAUTH payload", data + 24, len - 24);
  182. if (sta == NULL) {
  183. if (valid && mgmt->da[0] == 0xff)
  184. deauth_all_stas(wt, bss);
  185. return;
  186. }
  187. if (os_memcmp(mgmt->sa, mgmt->bssid, ETH_ALEN) == 0) {
  188. sta->counters[valid ? WLANTEST_STA_COUNTER_VALID_DEAUTH_RX :
  189. WLANTEST_STA_COUNTER_INVALID_DEAUTH_RX]++;
  190. if (sta->pwrmgt && !sta->pspoll)
  191. sta->counters[WLANTEST_STA_COUNTER_DEAUTH_RX_ASLEEP]++;
  192. else
  193. sta->counters[WLANTEST_STA_COUNTER_DEAUTH_RX_AWAKE]++;
  194. fc = le_to_host16(mgmt->frame_control);
  195. if (!(fc & WLAN_FC_ISWEP) && reason == 6)
  196. sta->counters[WLANTEST_STA_COUNTER_DEAUTH_RX_RC6]++;
  197. else if (!(fc & WLAN_FC_ISWEP) && reason == 7)
  198. sta->counters[WLANTEST_STA_COUNTER_DEAUTH_RX_RC7]++;
  199. } else
  200. sta->counters[valid ? WLANTEST_STA_COUNTER_VALID_DEAUTH_TX :
  201. WLANTEST_STA_COUNTER_INVALID_DEAUTH_TX]++;
  202. if (!valid) {
  203. add_note(wt, MSG_INFO, "Do not change STA " MACSTR " State "
  204. "since Disassociation frame was not protected "
  205. "correctly", MAC2STR(sta->addr));
  206. return;
  207. }
  208. if (sta->state != STATE1) {
  209. add_note(wt, MSG_DEBUG, "STA " MACSTR
  210. " moved to State 1 with " MACSTR,
  211. MAC2STR(sta->addr), MAC2STR(bss->bssid));
  212. sta->state = STATE1;
  213. }
  214. tdls_link_down(wt, bss, sta);
  215. }
  216. static void rx_mgmt_assoc_req(struct wlantest *wt, const u8 *data, size_t len)
  217. {
  218. const struct ieee80211_mgmt *mgmt;
  219. struct wlantest_bss *bss;
  220. struct wlantest_sta *sta;
  221. struct ieee802_11_elems elems;
  222. mgmt = (const struct ieee80211_mgmt *) data;
  223. bss = bss_get(wt, mgmt->bssid);
  224. if (bss == NULL)
  225. return;
  226. sta = sta_get(bss, mgmt->sa);
  227. if (sta == NULL)
  228. return;
  229. if (len < 24 + 4) {
  230. add_note(wt, MSG_INFO, "Too short Association Request frame "
  231. "from " MACSTR, MAC2STR(mgmt->sa));
  232. return;
  233. }
  234. wpa_printf(MSG_DEBUG, "ASSOCREQ " MACSTR " -> " MACSTR
  235. " (capab=0x%x listen_int=%u)",
  236. MAC2STR(mgmt->sa), MAC2STR(mgmt->da),
  237. le_to_host16(mgmt->u.assoc_req.capab_info),
  238. le_to_host16(mgmt->u.assoc_req.listen_interval));
  239. sta->counters[WLANTEST_STA_COUNTER_ASSOCREQ_TX]++;
  240. if (ieee802_11_parse_elems(mgmt->u.assoc_req.variable,
  241. len - (mgmt->u.assoc_req.variable - data),
  242. &elems, 0) == ParseFailed) {
  243. add_note(wt, MSG_INFO, "Invalid IEs in Association Request "
  244. "frame from " MACSTR, MAC2STR(mgmt->sa));
  245. return;
  246. }
  247. sta->assocreq_capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
  248. sta->assocreq_listen_int =
  249. le_to_host16(mgmt->u.assoc_req.listen_interval);
  250. os_free(sta->assocreq_ies);
  251. sta->assocreq_ies_len = len - (mgmt->u.assoc_req.variable - data);
  252. sta->assocreq_ies = os_malloc(sta->assocreq_ies_len);
  253. if (sta->assocreq_ies)
  254. os_memcpy(sta->assocreq_ies, mgmt->u.assoc_req.variable,
  255. sta->assocreq_ies_len);
  256. sta_update_assoc(sta, &elems);
  257. }
  258. static void rx_mgmt_assoc_resp(struct wlantest *wt, const u8 *data, size_t len)
  259. {
  260. const struct ieee80211_mgmt *mgmt;
  261. struct wlantest_bss *bss;
  262. struct wlantest_sta *sta;
  263. u16 capab, status, aid;
  264. mgmt = (const struct ieee80211_mgmt *) data;
  265. bss = bss_get(wt, mgmt->bssid);
  266. if (bss == NULL)
  267. return;
  268. sta = sta_get(bss, mgmt->da);
  269. if (sta == NULL)
  270. return;
  271. if (len < 24 + 6) {
  272. add_note(wt, MSG_INFO, "Too short Association Response frame "
  273. "from " MACSTR, MAC2STR(mgmt->sa));
  274. return;
  275. }
  276. capab = le_to_host16(mgmt->u.assoc_resp.capab_info);
  277. status = le_to_host16(mgmt->u.assoc_resp.status_code);
  278. aid = le_to_host16(mgmt->u.assoc_resp.aid);
  279. wpa_printf(MSG_DEBUG, "ASSOCRESP " MACSTR " -> " MACSTR
  280. " (capab=0x%x status=%u aid=%u)",
  281. MAC2STR(mgmt->sa), MAC2STR(mgmt->da), capab, status,
  282. aid & 0x3fff);
  283. if (status == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY) {
  284. struct ieee802_11_elems elems;
  285. const u8 *ies = mgmt->u.assoc_resp.variable;
  286. size_t ies_len = len - (mgmt->u.assoc_resp.variable - data);
  287. if (ieee802_11_parse_elems(ies, ies_len, &elems, 0) ==
  288. ParseFailed) {
  289. add_note(wt, MSG_INFO, "Failed to parse IEs in "
  290. "AssocResp from " MACSTR,
  291. MAC2STR(mgmt->sa));
  292. } else if (elems.timeout_int == NULL ||
  293. elems.timeout_int_len != 5 ||
  294. elems.timeout_int[0] !=
  295. WLAN_TIMEOUT_ASSOC_COMEBACK) {
  296. add_note(wt, MSG_INFO, "No valid Timeout Interval IE "
  297. "with Assoc Comeback time in AssocResp "
  298. "(status=30) from " MACSTR,
  299. MAC2STR(mgmt->sa));
  300. } else {
  301. sta->counters[
  302. WLANTEST_STA_COUNTER_ASSOCRESP_COMEBACK]++;
  303. }
  304. }
  305. if (status)
  306. return;
  307. if ((aid & 0xc000) != 0xc000) {
  308. add_note(wt, MSG_DEBUG, "Two MSBs of the AID were not set to 1 "
  309. "in Association Response from " MACSTR,
  310. MAC2STR(mgmt->sa));
  311. }
  312. sta->aid = aid & 0xc000;
  313. if (sta->state < STATE2) {
  314. add_note(wt, MSG_DEBUG,
  315. "STA " MACSTR " was not in State 2 when "
  316. "getting associated", MAC2STR(sta->addr));
  317. }
  318. if (sta->state < STATE3) {
  319. add_note(wt, MSG_DEBUG, "STA " MACSTR
  320. " moved to State 3 with " MACSTR,
  321. MAC2STR(sta->addr), MAC2STR(bss->bssid));
  322. sta->state = STATE3;
  323. }
  324. }
  325. static void rx_mgmt_reassoc_req(struct wlantest *wt, const u8 *data,
  326. size_t len)
  327. {
  328. const struct ieee80211_mgmt *mgmt;
  329. struct wlantest_bss *bss;
  330. struct wlantest_sta *sta;
  331. struct ieee802_11_elems elems;
  332. mgmt = (const struct ieee80211_mgmt *) data;
  333. bss = bss_get(wt, mgmt->bssid);
  334. if (bss == NULL)
  335. return;
  336. sta = sta_get(bss, mgmt->sa);
  337. if (sta == NULL)
  338. return;
  339. if (len < 24 + 4 + ETH_ALEN) {
  340. add_note(wt, MSG_INFO, "Too short Reassociation Request frame "
  341. "from " MACSTR, MAC2STR(mgmt->sa));
  342. return;
  343. }
  344. wpa_printf(MSG_DEBUG, "REASSOCREQ " MACSTR " -> " MACSTR
  345. " (capab=0x%x listen_int=%u current_ap=" MACSTR ")",
  346. MAC2STR(mgmt->sa), MAC2STR(mgmt->da),
  347. le_to_host16(mgmt->u.reassoc_req.capab_info),
  348. le_to_host16(mgmt->u.reassoc_req.listen_interval),
  349. MAC2STR(mgmt->u.reassoc_req.current_ap));
  350. sta->counters[WLANTEST_STA_COUNTER_REASSOCREQ_TX]++;
  351. if (ieee802_11_parse_elems(mgmt->u.reassoc_req.variable,
  352. len - (mgmt->u.reassoc_req.variable - data),
  353. &elems, 0) == ParseFailed) {
  354. add_note(wt, MSG_INFO, "Invalid IEs in Reassociation Request "
  355. "frame from " MACSTR, MAC2STR(mgmt->sa));
  356. return;
  357. }
  358. sta->assocreq_capab_info =
  359. le_to_host16(mgmt->u.reassoc_req.capab_info);
  360. sta->assocreq_listen_int =
  361. le_to_host16(mgmt->u.reassoc_req.listen_interval);
  362. os_free(sta->assocreq_ies);
  363. sta->assocreq_ies_len = len - (mgmt->u.reassoc_req.variable - data);
  364. sta->assocreq_ies = os_malloc(sta->assocreq_ies_len);
  365. if (sta->assocreq_ies)
  366. os_memcpy(sta->assocreq_ies, mgmt->u.reassoc_req.variable,
  367. sta->assocreq_ies_len);
  368. sta_update_assoc(sta, &elems);
  369. }
  370. static void rx_mgmt_reassoc_resp(struct wlantest *wt, const u8 *data,
  371. size_t len)
  372. {
  373. const struct ieee80211_mgmt *mgmt;
  374. struct wlantest_bss *bss;
  375. struct wlantest_sta *sta;
  376. u16 capab, status, aid;
  377. mgmt = (const struct ieee80211_mgmt *) data;
  378. bss = bss_get(wt, mgmt->bssid);
  379. if (bss == NULL)
  380. return;
  381. sta = sta_get(bss, mgmt->da);
  382. if (sta == NULL)
  383. return;
  384. if (len < 24 + 6) {
  385. add_note(wt, MSG_INFO, "Too short Reassociation Response frame "
  386. "from " MACSTR, MAC2STR(mgmt->sa));
  387. return;
  388. }
  389. capab = le_to_host16(mgmt->u.reassoc_resp.capab_info);
  390. status = le_to_host16(mgmt->u.reassoc_resp.status_code);
  391. aid = le_to_host16(mgmt->u.reassoc_resp.aid);
  392. wpa_printf(MSG_DEBUG, "REASSOCRESP " MACSTR " -> " MACSTR
  393. " (capab=0x%x status=%u aid=%u)",
  394. MAC2STR(mgmt->sa), MAC2STR(mgmt->da), capab, status,
  395. aid & 0x3fff);
  396. if (status == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY) {
  397. struct ieee802_11_elems elems;
  398. const u8 *ies = mgmt->u.reassoc_resp.variable;
  399. size_t ies_len = len - (mgmt->u.reassoc_resp.variable - data);
  400. if (ieee802_11_parse_elems(ies, ies_len, &elems, 0) ==
  401. ParseFailed) {
  402. add_note(wt, MSG_INFO, "Failed to parse IEs in "
  403. "ReassocResp from " MACSTR,
  404. MAC2STR(mgmt->sa));
  405. } else if (elems.timeout_int == NULL ||
  406. elems.timeout_int_len != 5 ||
  407. elems.timeout_int[0] !=
  408. WLAN_TIMEOUT_ASSOC_COMEBACK) {
  409. add_note(wt, MSG_INFO, "No valid Timeout Interval IE "
  410. "with Assoc Comeback time in ReassocResp "
  411. "(status=30) from " MACSTR,
  412. MAC2STR(mgmt->sa));
  413. } else {
  414. sta->counters[
  415. WLANTEST_STA_COUNTER_REASSOCRESP_COMEBACK]++;
  416. }
  417. }
  418. if (status)
  419. return;
  420. if ((aid & 0xc000) != 0xc000) {
  421. add_note(wt, MSG_DEBUG, "Two MSBs of the AID were not set to 1 "
  422. "in Reassociation Response from " MACSTR,
  423. MAC2STR(mgmt->sa));
  424. }
  425. sta->aid = aid & 0xc000;
  426. if (sta->state < STATE2) {
  427. add_note(wt, MSG_DEBUG,
  428. "STA " MACSTR " was not in State 2 when "
  429. "getting associated", MAC2STR(sta->addr));
  430. }
  431. if (sta->state < STATE3) {
  432. add_note(wt, MSG_DEBUG, "STA " MACSTR
  433. " moved to State 3 with " MACSTR,
  434. MAC2STR(sta->addr), MAC2STR(bss->bssid));
  435. sta->state = STATE3;
  436. }
  437. }
  438. static void disassoc_all_stas(struct wlantest *wt, struct wlantest_bss *bss)
  439. {
  440. struct wlantest_sta *sta;
  441. dl_list_for_each(sta, &bss->sta, struct wlantest_sta, list) {
  442. if (sta->state <= STATE2)
  443. continue;
  444. add_note(wt, MSG_DEBUG, "STA " MACSTR
  445. " moved to State 2 with " MACSTR,
  446. MAC2STR(sta->addr), MAC2STR(bss->bssid));
  447. sta->state = STATE2;
  448. }
  449. }
  450. static void rx_mgmt_disassoc(struct wlantest *wt, const u8 *data, size_t len,
  451. int valid)
  452. {
  453. const struct ieee80211_mgmt *mgmt;
  454. struct wlantest_bss *bss;
  455. struct wlantest_sta *sta;
  456. u16 fc, reason;
  457. mgmt = (const struct ieee80211_mgmt *) data;
  458. bss = bss_get(wt, mgmt->bssid);
  459. if (bss == NULL)
  460. return;
  461. if (os_memcmp(mgmt->sa, mgmt->bssid, ETH_ALEN) == 0)
  462. sta = sta_get(bss, mgmt->da);
  463. else
  464. sta = sta_get(bss, mgmt->sa);
  465. if (len < 24 + 2) {
  466. add_note(wt, MSG_INFO, "Too short Disassociation frame from "
  467. MACSTR, MAC2STR(mgmt->sa));
  468. return;
  469. }
  470. reason = le_to_host16(mgmt->u.disassoc.reason_code);
  471. wpa_printf(MSG_DEBUG, "DISASSOC " MACSTR " -> " MACSTR
  472. " (reason=%u) (valid=%d)",
  473. MAC2STR(mgmt->sa), MAC2STR(mgmt->da),
  474. reason, valid);
  475. wpa_hexdump(MSG_MSGDUMP, "DISASSOC payload", data + 24, len - 24);
  476. if (sta == NULL) {
  477. if (valid && mgmt->da[0] == 0xff)
  478. disassoc_all_stas(wt, bss);
  479. return;
  480. }
  481. if (os_memcmp(mgmt->sa, mgmt->bssid, ETH_ALEN) == 0) {
  482. sta->counters[valid ? WLANTEST_STA_COUNTER_VALID_DISASSOC_RX :
  483. WLANTEST_STA_COUNTER_INVALID_DISASSOC_RX]++;
  484. if (sta->pwrmgt && !sta->pspoll)
  485. sta->counters[
  486. WLANTEST_STA_COUNTER_DISASSOC_RX_ASLEEP]++;
  487. else
  488. sta->counters[
  489. WLANTEST_STA_COUNTER_DISASSOC_RX_AWAKE]++;
  490. fc = le_to_host16(mgmt->frame_control);
  491. if (!(fc & WLAN_FC_ISWEP) && reason == 6)
  492. sta->counters[WLANTEST_STA_COUNTER_DISASSOC_RX_RC6]++;
  493. else if (!(fc & WLAN_FC_ISWEP) && reason == 7)
  494. sta->counters[WLANTEST_STA_COUNTER_DISASSOC_RX_RC7]++;
  495. } else
  496. sta->counters[valid ? WLANTEST_STA_COUNTER_VALID_DISASSOC_TX :
  497. WLANTEST_STA_COUNTER_INVALID_DISASSOC_TX]++;
  498. if (!valid) {
  499. add_note(wt, MSG_INFO, "Do not change STA " MACSTR " State "
  500. "since Disassociation frame was not protected "
  501. "correctly", MAC2STR(sta->addr));
  502. return;
  503. }
  504. if (sta->state < STATE2) {
  505. add_note(wt, MSG_DEBUG,
  506. "STA " MACSTR " was not in State 2 or 3 "
  507. "when getting disassociated", MAC2STR(sta->addr));
  508. }
  509. if (sta->state > STATE2) {
  510. add_note(wt, MSG_DEBUG, "STA " MACSTR
  511. " moved to State 2 with " MACSTR,
  512. MAC2STR(sta->addr), MAC2STR(bss->bssid));
  513. sta->state = STATE2;
  514. }
  515. tdls_link_down(wt, bss, sta);
  516. }
  517. static void rx_mgmt_action_sa_query_req(struct wlantest *wt,
  518. struct wlantest_sta *sta,
  519. const struct ieee80211_mgmt *mgmt,
  520. size_t len, int valid)
  521. {
  522. const u8 *rx_id;
  523. u8 *id;
  524. rx_id = (const u8 *) mgmt->u.action.u.sa_query_req.trans_id;
  525. if (os_memcmp(mgmt->sa, mgmt->bssid, ETH_ALEN) == 0)
  526. id = sta->ap_sa_query_tr;
  527. else
  528. id = sta->sta_sa_query_tr;
  529. add_note(wt, MSG_INFO, "SA Query Request " MACSTR " -> " MACSTR
  530. " (trans_id=%02x%02x)%s",
  531. MAC2STR(mgmt->sa), MAC2STR(mgmt->da), rx_id[0], rx_id[1],
  532. valid ? "" : " (invalid protection)");
  533. os_memcpy(id, mgmt->u.action.u.sa_query_req.trans_id, 2);
  534. if (os_memcmp(mgmt->sa, sta->addr, ETH_ALEN) == 0)
  535. sta->counters[valid ?
  536. WLANTEST_STA_COUNTER_VALID_SAQUERYREQ_TX :
  537. WLANTEST_STA_COUNTER_INVALID_SAQUERYREQ_TX]++;
  538. else
  539. sta->counters[valid ?
  540. WLANTEST_STA_COUNTER_VALID_SAQUERYREQ_RX :
  541. WLANTEST_STA_COUNTER_INVALID_SAQUERYREQ_RX]++;
  542. }
  543. static void rx_mgmt_action_sa_query_resp(struct wlantest *wt,
  544. struct wlantest_sta *sta,
  545. const struct ieee80211_mgmt *mgmt,
  546. size_t len, int valid)
  547. {
  548. const u8 *rx_id;
  549. u8 *id;
  550. int match;
  551. rx_id = (const u8 *) mgmt->u.action.u.sa_query_resp.trans_id;
  552. if (os_memcmp(mgmt->sa, mgmt->bssid, ETH_ALEN) == 0)
  553. id = sta->sta_sa_query_tr;
  554. else
  555. id = sta->ap_sa_query_tr;
  556. match = os_memcmp(rx_id, id, 2) == 0;
  557. add_note(wt, MSG_INFO, "SA Query Response " MACSTR " -> " MACSTR
  558. " (trans_id=%02x%02x; %s)%s",
  559. MAC2STR(mgmt->sa), MAC2STR(mgmt->da), rx_id[0], rx_id[1],
  560. match ? "match" : "mismatch",
  561. valid ? "" : " (invalid protection)");
  562. if (os_memcmp(mgmt->sa, sta->addr, ETH_ALEN) == 0)
  563. sta->counters[(valid && match) ?
  564. WLANTEST_STA_COUNTER_VALID_SAQUERYRESP_TX :
  565. WLANTEST_STA_COUNTER_INVALID_SAQUERYRESP_TX]++;
  566. else
  567. sta->counters[(valid && match) ?
  568. WLANTEST_STA_COUNTER_VALID_SAQUERYRESP_RX :
  569. WLANTEST_STA_COUNTER_INVALID_SAQUERYRESP_RX]++;
  570. }
  571. static void rx_mgmt_action_sa_query(struct wlantest *wt,
  572. struct wlantest_sta *sta,
  573. const struct ieee80211_mgmt *mgmt,
  574. size_t len, int valid)
  575. {
  576. if (len < 24 + 2 + WLAN_SA_QUERY_TR_ID_LEN) {
  577. add_note(wt, MSG_INFO, "Too short SA Query frame from " MACSTR,
  578. MAC2STR(mgmt->sa));
  579. return;
  580. }
  581. if (len > 24 + 2 + WLAN_SA_QUERY_TR_ID_LEN) {
  582. size_t elen = len - (24 + 2 + WLAN_SA_QUERY_TR_ID_LEN);
  583. add_note(wt, MSG_INFO, "Unexpected %u octets of extra data at "
  584. "the end of SA Query frame from " MACSTR,
  585. (unsigned) elen, MAC2STR(mgmt->sa));
  586. wpa_hexdump(MSG_INFO, "SA Query extra data",
  587. ((const u8 *) mgmt) + len - elen, elen);
  588. }
  589. switch (mgmt->u.action.u.sa_query_req.action) {
  590. case WLAN_SA_QUERY_REQUEST:
  591. rx_mgmt_action_sa_query_req(wt, sta, mgmt, len, valid);
  592. break;
  593. case WLAN_SA_QUERY_RESPONSE:
  594. rx_mgmt_action_sa_query_resp(wt, sta, mgmt, len, valid);
  595. break;
  596. default:
  597. add_note(wt, MSG_INFO, "Unexpected SA Query action value %u "
  598. "from " MACSTR,
  599. mgmt->u.action.u.sa_query_req.action,
  600. MAC2STR(mgmt->sa));
  601. }
  602. }
  603. static void rx_mgmt_action(struct wlantest *wt, const u8 *data, size_t len,
  604. int valid)
  605. {
  606. const struct ieee80211_mgmt *mgmt;
  607. struct wlantest_bss *bss;
  608. struct wlantest_sta *sta;
  609. mgmt = (const struct ieee80211_mgmt *) data;
  610. if (mgmt->da[0] & 0x01) {
  611. add_note(wt, MSG_DEBUG, "Group addressed Action frame: DA="
  612. MACSTR " SA=" MACSTR " BSSID=" MACSTR
  613. " category=%u",
  614. MAC2STR(mgmt->da), MAC2STR(mgmt->sa),
  615. MAC2STR(mgmt->bssid), mgmt->u.action.category);
  616. return; /* Ignore group addressed Action frames for now */
  617. }
  618. bss = bss_get(wt, mgmt->bssid);
  619. if (bss == NULL)
  620. return;
  621. if (os_memcmp(mgmt->sa, mgmt->bssid, ETH_ALEN) == 0)
  622. sta = sta_get(bss, mgmt->da);
  623. else
  624. sta = sta_get(bss, mgmt->sa);
  625. if (sta == NULL)
  626. return;
  627. if (len < 24 + 1) {
  628. add_note(wt, MSG_INFO, "Too short Action frame from " MACSTR,
  629. MAC2STR(mgmt->sa));
  630. return;
  631. }
  632. wpa_printf(MSG_DEBUG, "ACTION " MACSTR " -> " MACSTR
  633. " (category=%u) (valid=%d)",
  634. MAC2STR(mgmt->sa), MAC2STR(mgmt->da),
  635. mgmt->u.action.category, valid);
  636. wpa_hexdump(MSG_MSGDUMP, "ACTION payload", data + 24, len - 24);
  637. if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
  638. sta->state < STATE3) {
  639. add_note(wt, MSG_INFO, "Action frame sent when STA is not in "
  640. "State 3 (SA=" MACSTR " DATA=" MACSTR ")",
  641. MAC2STR(mgmt->sa), MAC2STR(mgmt->da));
  642. }
  643. switch (mgmt->u.action.category) {
  644. case WLAN_ACTION_SA_QUERY:
  645. rx_mgmt_action_sa_query(wt, sta, mgmt, len, valid);
  646. break;
  647. }
  648. }
  649. static int check_mmie_mic(const u8 *igtk, const u8 *data, size_t len)
  650. {
  651. u8 *buf;
  652. u8 mic[16];
  653. u16 fc;
  654. const struct ieee80211_hdr *hdr;
  655. buf = os_malloc(len + 20 - 24);
  656. if (buf == NULL)
  657. return -1;
  658. /* BIP AAD: FC(masked) A1 A2 A3 */
  659. hdr = (const struct ieee80211_hdr *) data;
  660. fc = le_to_host16(hdr->frame_control);
  661. fc &= ~(WLAN_FC_RETRY | WLAN_FC_PWRMGT | WLAN_FC_MOREDATA);
  662. WPA_PUT_LE16(buf, fc);
  663. os_memcpy(buf + 2, hdr->addr1, 3 * ETH_ALEN);
  664. /* Frame body with MMIE MIC masked to zero */
  665. os_memcpy(buf + 20, data + 24, len - 24 - 8);
  666. os_memset(buf + 20 + len - 24 - 8, 0, 8);
  667. wpa_hexdump(MSG_MSGDUMP, "BIP: AAD|Body(masked)", buf, len + 20 - 24);
  668. /* MIC = L(AES-128-CMAC(AAD || Frame Body(masked)), 0, 64) */
  669. if (omac1_aes_128(igtk, buf, len + 20 - 24, mic) < 0) {
  670. os_free(buf);
  671. return -1;
  672. }
  673. os_free(buf);
  674. if (os_memcmp(data + len - 8, mic, 8) != 0)
  675. return -1;
  676. return 0;
  677. }
  678. static int check_bip(struct wlantest *wt, const u8 *data, size_t len)
  679. {
  680. const struct ieee80211_mgmt *mgmt;
  681. u16 fc, stype;
  682. const u8 *mmie;
  683. u16 keyid;
  684. struct wlantest_bss *bss;
  685. mgmt = (const struct ieee80211_mgmt *) data;
  686. fc = le_to_host16(mgmt->frame_control);
  687. stype = WLAN_FC_GET_STYPE(fc);
  688. if (stype == WLAN_FC_STYPE_ACTION) {
  689. if (len < 24 + 1)
  690. return 0;
  691. if (mgmt->u.action.category == WLAN_ACTION_PUBLIC)
  692. return 0; /* Not a robust management frame */
  693. }
  694. bss = bss_get(wt, mgmt->bssid);
  695. if (bss == NULL)
  696. return 0; /* No key known yet */
  697. if (len < 24 + 18 || data[len - 18] != WLAN_EID_MMIE ||
  698. data[len - 17] != 16) {
  699. /* No MMIE */
  700. if (bss->rsn_capab & WPA_CAPABILITY_MFPC) {
  701. add_note(wt, MSG_INFO, "Robust group-addressed "
  702. "management frame sent without BIP by "
  703. MACSTR, MAC2STR(mgmt->sa));
  704. bss->counters[WLANTEST_BSS_COUNTER_MISSING_BIP_MMIE]++;
  705. return -1;
  706. }
  707. return 0;
  708. }
  709. mmie = data + len - 16;
  710. keyid = WPA_GET_LE16(mmie);
  711. if (keyid & 0xf000) {
  712. add_note(wt, MSG_INFO, "MMIE KeyID reserved bits not zero "
  713. "(%04x) from " MACSTR, keyid, MAC2STR(mgmt->sa));
  714. keyid &= 0x0fff;
  715. }
  716. if (keyid < 4 || keyid > 5) {
  717. add_note(wt, MSG_INFO, "Unexpected MMIE KeyID %u from " MACSTR,
  718. keyid, MAC2STR(mgmt->sa));
  719. bss->counters[WLANTEST_BSS_COUNTER_INVALID_BIP_MMIE]++;
  720. return 0;
  721. }
  722. wpa_printf(MSG_DEBUG, "MMIE KeyID %u", keyid);
  723. wpa_hexdump(MSG_MSGDUMP, "MMIE IPN", mmie + 2, 6);
  724. wpa_hexdump(MSG_MSGDUMP, "MMIE MIC", mmie + 8, 8);
  725. if (!bss->igtk_set[keyid]) {
  726. add_note(wt, MSG_DEBUG, "No IGTK known to validate BIP frame");
  727. return 0;
  728. }
  729. if (os_memcmp(mmie + 2, bss->ipn[keyid], 6) <= 0) {
  730. add_note(wt, MSG_INFO, "BIP replay detected: SA=" MACSTR,
  731. MAC2STR(mgmt->sa));
  732. wpa_hexdump(MSG_INFO, "RX IPN", mmie + 2, 6);
  733. wpa_hexdump(MSG_INFO, "Last RX IPN", bss->ipn[keyid], 6);
  734. }
  735. if (check_mmie_mic(bss->igtk[keyid], data, len) < 0) {
  736. add_note(wt, MSG_INFO, "Invalid MMIE MIC in a frame from "
  737. MACSTR, MAC2STR(mgmt->sa));
  738. bss->counters[WLANTEST_BSS_COUNTER_INVALID_BIP_MMIE]++;
  739. return -1;
  740. }
  741. add_note(wt, MSG_DEBUG, "Valid MMIE MIC");
  742. os_memcpy(bss->ipn[keyid], mmie + 2, 6);
  743. bss->counters[WLANTEST_BSS_COUNTER_VALID_BIP_MMIE]++;
  744. if (stype == WLAN_FC_STYPE_DEAUTH)
  745. bss->counters[WLANTEST_BSS_COUNTER_BIP_DEAUTH]++;
  746. else if (stype == WLAN_FC_STYPE_DISASSOC)
  747. bss->counters[WLANTEST_BSS_COUNTER_BIP_DISASSOC]++;
  748. return 0;
  749. }
  750. static u8 * mgmt_ccmp_decrypt(struct wlantest *wt, const u8 *data, size_t len,
  751. size_t *dlen)
  752. {
  753. struct wlantest_bss *bss;
  754. struct wlantest_sta *sta;
  755. const struct ieee80211_hdr *hdr;
  756. int keyid;
  757. u8 *decrypted, *frame = NULL;
  758. u8 pn[6], *rsc;
  759. hdr = (const struct ieee80211_hdr *) data;
  760. bss = bss_get(wt, hdr->addr3);
  761. if (bss == NULL)
  762. return NULL;
  763. if (os_memcmp(hdr->addr1, hdr->addr3, ETH_ALEN) == 0)
  764. sta = sta_get(bss, hdr->addr2);
  765. else
  766. sta = sta_get(bss, hdr->addr1);
  767. if (sta == NULL || !sta->ptk_set) {
  768. add_note(wt, MSG_MSGDUMP, "No PTK known to decrypt the frame");
  769. return NULL;
  770. }
  771. if (len < 24 + 4)
  772. return NULL;
  773. if (!(data[24 + 3] & 0x20)) {
  774. add_note(wt, MSG_INFO, "Expected CCMP frame from " MACSTR
  775. " did not have ExtIV bit set to 1",
  776. MAC2STR(hdr->addr2));
  777. return NULL;
  778. }
  779. if (data[24 + 2] != 0 || (data[24 + 3] & 0x1f) != 0) {
  780. add_note(wt, MSG_INFO, "CCMP mgmt frame from " MACSTR " used "
  781. "non-zero reserved bit", MAC2STR(hdr->addr2));
  782. }
  783. keyid = data[24 + 3] >> 6;
  784. if (keyid != 0) {
  785. add_note(wt, MSG_INFO, "Unexpected non-zero KeyID %d in "
  786. "individually addressed Management frame from "
  787. MACSTR, keyid, MAC2STR(hdr->addr2));
  788. }
  789. if (os_memcmp(hdr->addr1, hdr->addr3, ETH_ALEN) == 0)
  790. rsc = sta->rsc_tods[16];
  791. else
  792. rsc = sta->rsc_fromds[16];
  793. ccmp_get_pn(pn, data + 24);
  794. if (os_memcmp(pn, rsc, 6) <= 0) {
  795. u16 seq_ctrl = le_to_host16(hdr->seq_ctrl);
  796. add_note(wt, MSG_INFO, "CCMP/TKIP replay detected: A1=" MACSTR
  797. " A2=" MACSTR " A3=" MACSTR " seq=%u frag=%u%s",
  798. MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
  799. MAC2STR(hdr->addr3),
  800. WLAN_GET_SEQ_SEQ(seq_ctrl),
  801. WLAN_GET_SEQ_FRAG(seq_ctrl),
  802. (le_to_host16(hdr->frame_control) & WLAN_FC_RETRY) ?
  803. " Retry" : "");
  804. wpa_hexdump(MSG_INFO, "RX PN", pn, 6);
  805. wpa_hexdump(MSG_INFO, "RSC", rsc, 6);
  806. }
  807. decrypted = ccmp_decrypt(sta->ptk.tk1, hdr, data + 24, len - 24, dlen);
  808. if (decrypted) {
  809. os_memcpy(rsc, pn, 6);
  810. frame = os_malloc(24 + *dlen);
  811. if (frame) {
  812. os_memcpy(frame, data, 24);
  813. os_memcpy(frame + 24, decrypted, *dlen);
  814. *dlen += 24;
  815. }
  816. }
  817. os_free(decrypted);
  818. return frame;
  819. }
  820. static int check_mgmt_ccmp(struct wlantest *wt, const u8 *data, size_t len)
  821. {
  822. const struct ieee80211_mgmt *mgmt;
  823. u16 fc;
  824. struct wlantest_bss *bss;
  825. struct wlantest_sta *sta;
  826. mgmt = (const struct ieee80211_mgmt *) data;
  827. fc = le_to_host16(mgmt->frame_control);
  828. if (WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) {
  829. if (len > 24 &&
  830. mgmt->u.action.category == WLAN_ACTION_PUBLIC)
  831. return 0; /* Not a robust management frame */
  832. }
  833. bss = bss_get(wt, mgmt->bssid);
  834. if (bss == NULL)
  835. return 0;
  836. if (os_memcmp(mgmt->da, mgmt->bssid, ETH_ALEN) == 0)
  837. sta = sta_get(bss, mgmt->sa);
  838. else
  839. sta = sta_get(bss, mgmt->da);
  840. if (sta == NULL)
  841. return 0;
  842. if ((sta->rsn_capab & WPA_CAPABILITY_MFPC) &&
  843. (sta->state == STATE3 ||
  844. WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION)) {
  845. add_note(wt, MSG_INFO, "Robust individually-addressed "
  846. "management frame sent without CCMP by "
  847. MACSTR, MAC2STR(mgmt->sa));
  848. return -1;
  849. }
  850. return 0;
  851. }
  852. void rx_mgmt(struct wlantest *wt, const u8 *data, size_t len)
  853. {
  854. const struct ieee80211_hdr *hdr;
  855. u16 fc, stype;
  856. int valid = 1;
  857. u8 *decrypted = NULL;
  858. size_t dlen;
  859. if (len < 24)
  860. return;
  861. hdr = (const struct ieee80211_hdr *) data;
  862. fc = le_to_host16(hdr->frame_control);
  863. wt->rx_mgmt++;
  864. stype = WLAN_FC_GET_STYPE(fc);
  865. if ((hdr->addr1[0] & 0x01) &&
  866. (stype == WLAN_FC_STYPE_DEAUTH ||
  867. stype == WLAN_FC_STYPE_DISASSOC ||
  868. stype == WLAN_FC_STYPE_ACTION)) {
  869. if (check_bip(wt, data, len) < 0)
  870. valid = 0;
  871. }
  872. wpa_printf((stype == WLAN_FC_STYPE_BEACON ||
  873. stype == WLAN_FC_STYPE_PROBE_RESP ||
  874. stype == WLAN_FC_STYPE_PROBE_REQ) ?
  875. MSG_EXCESSIVE : MSG_MSGDUMP,
  876. "MGMT %s%s%s DA=" MACSTR " SA=" MACSTR " BSSID=" MACSTR,
  877. mgmt_stype(stype),
  878. fc & WLAN_FC_PWRMGT ? " PwrMgt" : "",
  879. fc & WLAN_FC_ISWEP ? " Prot" : "",
  880. MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
  881. MAC2STR(hdr->addr3));
  882. if ((fc & WLAN_FC_ISWEP) &&
  883. !(hdr->addr1[0] & 0x01) &&
  884. (stype == WLAN_FC_STYPE_DEAUTH ||
  885. stype == WLAN_FC_STYPE_DISASSOC ||
  886. stype == WLAN_FC_STYPE_ACTION)) {
  887. decrypted = mgmt_ccmp_decrypt(wt, data, len, &dlen);
  888. if (decrypted) {
  889. write_pcap_decrypted(wt, decrypted, dlen, NULL, 0);
  890. data = decrypted;
  891. len = dlen;
  892. } else
  893. valid = 0;
  894. }
  895. if (!(fc & WLAN_FC_ISWEP) &&
  896. !(hdr->addr1[0] & 0x01) &&
  897. (stype == WLAN_FC_STYPE_DEAUTH ||
  898. stype == WLAN_FC_STYPE_DISASSOC ||
  899. stype == WLAN_FC_STYPE_ACTION)) {
  900. if (check_mgmt_ccmp(wt, data, len) < 0)
  901. valid = 0;
  902. }
  903. switch (stype) {
  904. case WLAN_FC_STYPE_BEACON:
  905. rx_mgmt_beacon(wt, data, len);
  906. break;
  907. case WLAN_FC_STYPE_PROBE_RESP:
  908. rx_mgmt_probe_resp(wt, data, len);
  909. break;
  910. case WLAN_FC_STYPE_AUTH:
  911. rx_mgmt_auth(wt, data, len);
  912. break;
  913. case WLAN_FC_STYPE_DEAUTH:
  914. rx_mgmt_deauth(wt, data, len, valid);
  915. break;
  916. case WLAN_FC_STYPE_ASSOC_REQ:
  917. rx_mgmt_assoc_req(wt, data, len);
  918. break;
  919. case WLAN_FC_STYPE_ASSOC_RESP:
  920. rx_mgmt_assoc_resp(wt, data, len);
  921. break;
  922. case WLAN_FC_STYPE_REASSOC_REQ:
  923. rx_mgmt_reassoc_req(wt, data, len);
  924. break;
  925. case WLAN_FC_STYPE_REASSOC_RESP:
  926. rx_mgmt_reassoc_resp(wt, data, len);
  927. break;
  928. case WLAN_FC_STYPE_DISASSOC:
  929. rx_mgmt_disassoc(wt, data, len, valid);
  930. break;
  931. case WLAN_FC_STYPE_ACTION:
  932. rx_mgmt_action(wt, data, len, valid);
  933. break;
  934. }
  935. os_free(decrypted);
  936. wt->last_mgmt_valid = valid;
  937. }
  938. static void rx_mgmt_deauth_ack(struct wlantest *wt,
  939. const struct ieee80211_hdr *hdr)
  940. {
  941. const struct ieee80211_mgmt *mgmt;
  942. struct wlantest_bss *bss;
  943. struct wlantest_sta *sta;
  944. mgmt = (const struct ieee80211_mgmt *) hdr;
  945. bss = bss_get(wt, mgmt->bssid);
  946. if (bss == NULL)
  947. return;
  948. if (os_memcmp(mgmt->sa, mgmt->bssid, ETH_ALEN) == 0)
  949. sta = sta_get(bss, mgmt->da);
  950. else
  951. sta = sta_get(bss, mgmt->sa);
  952. if (sta == NULL)
  953. return;
  954. add_note(wt, MSG_DEBUG, "DEAUTH from " MACSTR " acknowledged by "
  955. MACSTR, MAC2STR(mgmt->sa), MAC2STR(mgmt->da));
  956. if (os_memcmp(mgmt->sa, mgmt->bssid, ETH_ALEN) == 0) {
  957. int c;
  958. c = wt->last_mgmt_valid ?
  959. WLANTEST_STA_COUNTER_VALID_DEAUTH_RX_ACK :
  960. WLANTEST_STA_COUNTER_INVALID_DEAUTH_RX_ACK;
  961. sta->counters[c]++;
  962. }
  963. }
  964. static void rx_mgmt_disassoc_ack(struct wlantest *wt,
  965. const struct ieee80211_hdr *hdr)
  966. {
  967. const struct ieee80211_mgmt *mgmt;
  968. struct wlantest_bss *bss;
  969. struct wlantest_sta *sta;
  970. mgmt = (const struct ieee80211_mgmt *) hdr;
  971. bss = bss_get(wt, mgmt->bssid);
  972. if (bss == NULL)
  973. return;
  974. if (os_memcmp(mgmt->sa, mgmt->bssid, ETH_ALEN) == 0)
  975. sta = sta_get(bss, mgmt->da);
  976. else
  977. sta = sta_get(bss, mgmt->sa);
  978. if (sta == NULL)
  979. return;
  980. add_note(wt, MSG_DEBUG, "DISASSOC from " MACSTR " acknowledged by "
  981. MACSTR, MAC2STR(mgmt->sa), MAC2STR(mgmt->da));
  982. if (os_memcmp(mgmt->sa, mgmt->bssid, ETH_ALEN) == 0) {
  983. int c;
  984. c = wt->last_mgmt_valid ?
  985. WLANTEST_STA_COUNTER_VALID_DISASSOC_RX_ACK :
  986. WLANTEST_STA_COUNTER_INVALID_DISASSOC_RX_ACK;
  987. sta->counters[c]++;
  988. }
  989. }
  990. void rx_mgmt_ack(struct wlantest *wt, const struct ieee80211_hdr *hdr)
  991. {
  992. u16 fc, stype;
  993. fc = le_to_host16(hdr->frame_control);
  994. stype = WLAN_FC_GET_STYPE(fc);
  995. wpa_printf(MSG_MSGDUMP, "MGMT ACK: stype=%u a1=" MACSTR " a2=" MACSTR
  996. " a3=" MACSTR,
  997. stype, MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
  998. MAC2STR(hdr->addr3));
  999. switch (stype) {
  1000. case WLAN_FC_STYPE_DEAUTH:
  1001. rx_mgmt_deauth_ack(wt, hdr);
  1002. break;
  1003. case WLAN_FC_STYPE_DISASSOC:
  1004. rx_mgmt_disassoc_ack(wt, hdr);
  1005. break;
  1006. }
  1007. }