rx_mgmt.c 31 KB

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