rx_mgmt.c 30 KB

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