rx_mgmt.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  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",
  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. wpa_hexdump(MSG_INFO, "RX PN", pn, 6);
  803. wpa_hexdump(MSG_INFO, "RSC", rsc, 6);
  804. }
  805. decrypted = ccmp_decrypt(sta->ptk.tk1, hdr, data + 24, len - 24, dlen);
  806. if (decrypted) {
  807. os_memcpy(rsc, pn, 6);
  808. frame = os_malloc(24 + *dlen);
  809. if (frame) {
  810. os_memcpy(frame, data, 24);
  811. os_memcpy(frame + 24, decrypted, *dlen);
  812. *dlen += 24;
  813. }
  814. }
  815. os_free(decrypted);
  816. return frame;
  817. }
  818. static int check_mgmt_ccmp(struct wlantest *wt, const u8 *data, size_t len)
  819. {
  820. const struct ieee80211_mgmt *mgmt;
  821. u16 fc;
  822. struct wlantest_bss *bss;
  823. struct wlantest_sta *sta;
  824. mgmt = (const struct ieee80211_mgmt *) data;
  825. fc = le_to_host16(mgmt->frame_control);
  826. if (WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) {
  827. if (len > 24 &&
  828. mgmt->u.action.category == WLAN_ACTION_PUBLIC)
  829. return 0; /* Not a robust management frame */
  830. }
  831. bss = bss_get(wt, mgmt->bssid);
  832. if (bss == NULL)
  833. return 0;
  834. if (os_memcmp(mgmt->da, mgmt->bssid, ETH_ALEN) == 0)
  835. sta = sta_get(bss, mgmt->sa);
  836. else
  837. sta = sta_get(bss, mgmt->da);
  838. if (sta == NULL)
  839. return 0;
  840. if ((sta->rsn_capab & WPA_CAPABILITY_MFPC) &&
  841. (sta->state == STATE3 ||
  842. WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION)) {
  843. add_note(wt, MSG_INFO, "Robust individually-addressed "
  844. "management frame sent without CCMP by "
  845. MACSTR, MAC2STR(mgmt->sa));
  846. return -1;
  847. }
  848. return 0;
  849. }
  850. void rx_mgmt(struct wlantest *wt, const u8 *data, size_t len)
  851. {
  852. const struct ieee80211_hdr *hdr;
  853. u16 fc, stype;
  854. int valid = 1;
  855. u8 *decrypted = NULL;
  856. size_t dlen;
  857. if (len < 24)
  858. return;
  859. hdr = (const struct ieee80211_hdr *) data;
  860. fc = le_to_host16(hdr->frame_control);
  861. wt->rx_mgmt++;
  862. stype = WLAN_FC_GET_STYPE(fc);
  863. if ((hdr->addr1[0] & 0x01) &&
  864. (stype == WLAN_FC_STYPE_DEAUTH ||
  865. stype == WLAN_FC_STYPE_DISASSOC ||
  866. stype == WLAN_FC_STYPE_ACTION)) {
  867. if (check_bip(wt, data, len) < 0)
  868. valid = 0;
  869. }
  870. wpa_printf((stype == WLAN_FC_STYPE_BEACON ||
  871. stype == WLAN_FC_STYPE_PROBE_RESP ||
  872. stype == WLAN_FC_STYPE_PROBE_REQ) ?
  873. MSG_EXCESSIVE : MSG_MSGDUMP,
  874. "MGMT %s%s%s DA=" MACSTR " SA=" MACSTR " BSSID=" MACSTR,
  875. mgmt_stype(stype),
  876. fc & WLAN_FC_PWRMGT ? " PwrMgt" : "",
  877. fc & WLAN_FC_ISWEP ? " Prot" : "",
  878. MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
  879. MAC2STR(hdr->addr3));
  880. if ((fc & WLAN_FC_ISWEP) &&
  881. !(hdr->addr1[0] & 0x01) &&
  882. (stype == WLAN_FC_STYPE_DEAUTH ||
  883. stype == WLAN_FC_STYPE_DISASSOC ||
  884. stype == WLAN_FC_STYPE_ACTION)) {
  885. decrypted = mgmt_ccmp_decrypt(wt, data, len, &dlen);
  886. if (decrypted) {
  887. write_pcap_decrypted(wt, decrypted, dlen, NULL, 0);
  888. data = decrypted;
  889. len = dlen;
  890. } else
  891. valid = 0;
  892. }
  893. if (!(fc & WLAN_FC_ISWEP) &&
  894. !(hdr->addr1[0] & 0x01) &&
  895. (stype == WLAN_FC_STYPE_DEAUTH ||
  896. stype == WLAN_FC_STYPE_DISASSOC ||
  897. stype == WLAN_FC_STYPE_ACTION)) {
  898. if (check_mgmt_ccmp(wt, data, len) < 0)
  899. valid = 0;
  900. }
  901. switch (stype) {
  902. case WLAN_FC_STYPE_BEACON:
  903. rx_mgmt_beacon(wt, data, len);
  904. break;
  905. case WLAN_FC_STYPE_PROBE_RESP:
  906. rx_mgmt_probe_resp(wt, data, len);
  907. break;
  908. case WLAN_FC_STYPE_AUTH:
  909. rx_mgmt_auth(wt, data, len);
  910. break;
  911. case WLAN_FC_STYPE_DEAUTH:
  912. rx_mgmt_deauth(wt, data, len, valid);
  913. break;
  914. case WLAN_FC_STYPE_ASSOC_REQ:
  915. rx_mgmt_assoc_req(wt, data, len);
  916. break;
  917. case WLAN_FC_STYPE_ASSOC_RESP:
  918. rx_mgmt_assoc_resp(wt, data, len);
  919. break;
  920. case WLAN_FC_STYPE_REASSOC_REQ:
  921. rx_mgmt_reassoc_req(wt, data, len);
  922. break;
  923. case WLAN_FC_STYPE_REASSOC_RESP:
  924. rx_mgmt_reassoc_resp(wt, data, len);
  925. break;
  926. case WLAN_FC_STYPE_DISASSOC:
  927. rx_mgmt_disassoc(wt, data, len, valid);
  928. break;
  929. case WLAN_FC_STYPE_ACTION:
  930. rx_mgmt_action(wt, data, len, valid);
  931. break;
  932. }
  933. os_free(decrypted);
  934. wt->last_mgmt_valid = valid;
  935. }
  936. static void rx_mgmt_deauth_ack(struct wlantest *wt,
  937. const struct ieee80211_hdr *hdr)
  938. {
  939. const struct ieee80211_mgmt *mgmt;
  940. struct wlantest_bss *bss;
  941. struct wlantest_sta *sta;
  942. mgmt = (const struct ieee80211_mgmt *) hdr;
  943. bss = bss_get(wt, mgmt->bssid);
  944. if (bss == NULL)
  945. return;
  946. if (os_memcmp(mgmt->sa, mgmt->bssid, ETH_ALEN) == 0)
  947. sta = sta_get(bss, mgmt->da);
  948. else
  949. sta = sta_get(bss, mgmt->sa);
  950. if (sta == NULL)
  951. return;
  952. add_note(wt, MSG_DEBUG, "DEAUTH from " MACSTR " acknowledged by "
  953. MACSTR, MAC2STR(mgmt->sa), MAC2STR(mgmt->da));
  954. if (os_memcmp(mgmt->sa, mgmt->bssid, ETH_ALEN) == 0) {
  955. int c;
  956. c = wt->last_mgmt_valid ?
  957. WLANTEST_STA_COUNTER_VALID_DEAUTH_RX_ACK :
  958. WLANTEST_STA_COUNTER_INVALID_DEAUTH_RX_ACK;
  959. sta->counters[c]++;
  960. }
  961. }
  962. static void rx_mgmt_disassoc_ack(struct wlantest *wt,
  963. const struct ieee80211_hdr *hdr)
  964. {
  965. const struct ieee80211_mgmt *mgmt;
  966. struct wlantest_bss *bss;
  967. struct wlantest_sta *sta;
  968. mgmt = (const struct ieee80211_mgmt *) hdr;
  969. bss = bss_get(wt, mgmt->bssid);
  970. if (bss == NULL)
  971. return;
  972. if (os_memcmp(mgmt->sa, mgmt->bssid, ETH_ALEN) == 0)
  973. sta = sta_get(bss, mgmt->da);
  974. else
  975. sta = sta_get(bss, mgmt->sa);
  976. if (sta == NULL)
  977. return;
  978. add_note(wt, MSG_DEBUG, "DISASSOC from " MACSTR " acknowledged by "
  979. MACSTR, MAC2STR(mgmt->sa), MAC2STR(mgmt->da));
  980. if (os_memcmp(mgmt->sa, mgmt->bssid, ETH_ALEN) == 0) {
  981. int c;
  982. c = wt->last_mgmt_valid ?
  983. WLANTEST_STA_COUNTER_VALID_DISASSOC_RX_ACK :
  984. WLANTEST_STA_COUNTER_INVALID_DISASSOC_RX_ACK;
  985. sta->counters[c]++;
  986. }
  987. }
  988. void rx_mgmt_ack(struct wlantest *wt, const struct ieee80211_hdr *hdr)
  989. {
  990. u16 fc, stype;
  991. fc = le_to_host16(hdr->frame_control);
  992. stype = WLAN_FC_GET_STYPE(fc);
  993. wpa_printf(MSG_MSGDUMP, "MGMT ACK: stype=%u a1=" MACSTR " a2=" MACSTR
  994. " a3=" MACSTR,
  995. stype, MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
  996. MAC2STR(hdr->addr3));
  997. switch (stype) {
  998. case WLAN_FC_STYPE_DEAUTH:
  999. rx_mgmt_deauth_ack(wt, hdr);
  1000. break;
  1001. case WLAN_FC_STYPE_DISASSOC:
  1002. rx_mgmt_disassoc_ack(wt, hdr);
  1003. break;
  1004. }
  1005. }