wnm_sta.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  1. /*
  2. * wpa_supplicant - WNM
  3. * Copyright (c) 2011-2013, Qualcomm Atheros, Inc.
  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 "common/wpa_ctrl.h"
  13. #include "rsn_supp/wpa.h"
  14. #include "wpa_supplicant_i.h"
  15. #include "driver_i.h"
  16. #include "scan.h"
  17. #include "ctrl_iface.h"
  18. #include "bss.h"
  19. #include "wnm_sta.h"
  20. #include "hs20_supplicant.h"
  21. #define MAX_TFS_IE_LEN 1024
  22. #define WNM_MAX_NEIGHBOR_REPORT 10
  23. /* get the TFS IE from driver */
  24. static int ieee80211_11_get_tfs_ie(struct wpa_supplicant *wpa_s, u8 *buf,
  25. u16 *buf_len, enum wnm_oper oper)
  26. {
  27. wpa_printf(MSG_DEBUG, "%s: TFS get operation %d", __func__, oper);
  28. return wpa_drv_wnm_oper(wpa_s, oper, wpa_s->bssid, buf, buf_len);
  29. }
  30. /* set the TFS IE to driver */
  31. static int ieee80211_11_set_tfs_ie(struct wpa_supplicant *wpa_s,
  32. const u8 *addr, u8 *buf, u16 *buf_len,
  33. enum wnm_oper oper)
  34. {
  35. wpa_printf(MSG_DEBUG, "%s: TFS set operation %d", __func__, oper);
  36. return wpa_drv_wnm_oper(wpa_s, oper, addr, buf, buf_len);
  37. }
  38. /* MLME-SLEEPMODE.request */
  39. int ieee802_11_send_wnmsleep_req(struct wpa_supplicant *wpa_s,
  40. u8 action, u16 intval, struct wpabuf *tfs_req)
  41. {
  42. struct ieee80211_mgmt *mgmt;
  43. int res;
  44. size_t len;
  45. struct wnm_sleep_element *wnmsleep_ie;
  46. u8 *wnmtfs_ie;
  47. u8 wnmsleep_ie_len;
  48. u16 wnmtfs_ie_len; /* possibly multiple IE(s) */
  49. enum wnm_oper tfs_oper = action == 0 ? WNM_SLEEP_TFS_REQ_IE_ADD :
  50. WNM_SLEEP_TFS_REQ_IE_NONE;
  51. wpa_printf(MSG_DEBUG, "WNM: Request to send WNM-Sleep Mode Request "
  52. "action=%s to " MACSTR,
  53. action == 0 ? "enter" : "exit",
  54. MAC2STR(wpa_s->bssid));
  55. /* WNM-Sleep Mode IE */
  56. wnmsleep_ie_len = sizeof(struct wnm_sleep_element);
  57. wnmsleep_ie = os_zalloc(sizeof(struct wnm_sleep_element));
  58. if (wnmsleep_ie == NULL)
  59. return -1;
  60. wnmsleep_ie->eid = WLAN_EID_WNMSLEEP;
  61. wnmsleep_ie->len = wnmsleep_ie_len - 2;
  62. wnmsleep_ie->action_type = action;
  63. wnmsleep_ie->status = WNM_STATUS_SLEEP_ACCEPT;
  64. wnmsleep_ie->intval = host_to_le16(intval);
  65. wpa_hexdump(MSG_DEBUG, "WNM: WNM-Sleep Mode element",
  66. (u8 *) wnmsleep_ie, wnmsleep_ie_len);
  67. /* TFS IE(s) */
  68. if (tfs_req) {
  69. wnmtfs_ie_len = wpabuf_len(tfs_req);
  70. wnmtfs_ie = os_malloc(wnmtfs_ie_len);
  71. if (wnmtfs_ie == NULL) {
  72. os_free(wnmsleep_ie);
  73. return -1;
  74. }
  75. os_memcpy(wnmtfs_ie, wpabuf_head(tfs_req), wnmtfs_ie_len);
  76. } else {
  77. wnmtfs_ie = os_zalloc(MAX_TFS_IE_LEN);
  78. if (wnmtfs_ie == NULL) {
  79. os_free(wnmsleep_ie);
  80. return -1;
  81. }
  82. if (ieee80211_11_get_tfs_ie(wpa_s, wnmtfs_ie, &wnmtfs_ie_len,
  83. tfs_oper)) {
  84. wnmtfs_ie_len = 0;
  85. os_free(wnmtfs_ie);
  86. wnmtfs_ie = NULL;
  87. }
  88. }
  89. wpa_hexdump(MSG_DEBUG, "WNM: TFS Request element",
  90. (u8 *) wnmtfs_ie, wnmtfs_ie_len);
  91. mgmt = os_zalloc(sizeof(*mgmt) + wnmsleep_ie_len + wnmtfs_ie_len);
  92. if (mgmt == NULL) {
  93. wpa_printf(MSG_DEBUG, "MLME: Failed to allocate buffer for "
  94. "WNM-Sleep Request action frame");
  95. os_free(wnmsleep_ie);
  96. os_free(wnmtfs_ie);
  97. return -1;
  98. }
  99. os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN);
  100. os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
  101. os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
  102. mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  103. WLAN_FC_STYPE_ACTION);
  104. mgmt->u.action.category = WLAN_ACTION_WNM;
  105. mgmt->u.action.u.wnm_sleep_req.action = WNM_SLEEP_MODE_REQ;
  106. mgmt->u.action.u.wnm_sleep_req.dialogtoken = 1;
  107. os_memcpy(mgmt->u.action.u.wnm_sleep_req.variable, wnmsleep_ie,
  108. wnmsleep_ie_len);
  109. /* copy TFS IE here */
  110. if (wnmtfs_ie_len > 0) {
  111. os_memcpy(mgmt->u.action.u.wnm_sleep_req.variable +
  112. wnmsleep_ie_len, wnmtfs_ie, wnmtfs_ie_len);
  113. }
  114. len = 1 + sizeof(mgmt->u.action.u.wnm_sleep_req) + wnmsleep_ie_len +
  115. wnmtfs_ie_len;
  116. res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
  117. wpa_s->own_addr, wpa_s->bssid,
  118. &mgmt->u.action.category, len, 0);
  119. if (res < 0)
  120. wpa_printf(MSG_DEBUG, "Failed to send WNM-Sleep Request "
  121. "(action=%d, intval=%d)", action, intval);
  122. os_free(wnmsleep_ie);
  123. os_free(wnmtfs_ie);
  124. os_free(mgmt);
  125. return res;
  126. }
  127. static void wnm_sleep_mode_enter_success(struct wpa_supplicant *wpa_s,
  128. u8 *tfsresp_ie_start,
  129. u8 *tfsresp_ie_end)
  130. {
  131. wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_ENTER_CONFIRM,
  132. wpa_s->bssid, NULL, NULL);
  133. /* remove GTK/IGTK ?? */
  134. /* set the TFS Resp IE(s) */
  135. if (tfsresp_ie_start && tfsresp_ie_end &&
  136. tfsresp_ie_end - tfsresp_ie_start >= 0) {
  137. u16 tfsresp_ie_len;
  138. tfsresp_ie_len = (tfsresp_ie_end + tfsresp_ie_end[1] + 2) -
  139. tfsresp_ie_start;
  140. wpa_printf(MSG_DEBUG, "TFS Resp IE(s) found");
  141. /* pass the TFS Resp IE(s) to driver for processing */
  142. if (ieee80211_11_set_tfs_ie(wpa_s, wpa_s->bssid,
  143. tfsresp_ie_start,
  144. &tfsresp_ie_len,
  145. WNM_SLEEP_TFS_RESP_IE_SET))
  146. wpa_printf(MSG_DEBUG, "WNM: Fail to set TFS Resp IE");
  147. }
  148. }
  149. static void wnm_sleep_mode_exit_success(struct wpa_supplicant *wpa_s,
  150. const u8 *frm, u16 key_len_total)
  151. {
  152. u8 *ptr, *end;
  153. u8 gtk_len;
  154. wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_EXIT_CONFIRM, wpa_s->bssid,
  155. NULL, NULL);
  156. /* Install GTK/IGTK */
  157. /* point to key data field */
  158. ptr = (u8 *) frm + 1 + 2;
  159. end = ptr + key_len_total;
  160. wpa_hexdump_key(MSG_DEBUG, "WNM: Key Data", ptr, key_len_total);
  161. while (ptr + 1 < end) {
  162. if (ptr + 2 + ptr[1] > end) {
  163. wpa_printf(MSG_DEBUG, "WNM: Invalid Key Data element "
  164. "length");
  165. if (end > ptr) {
  166. wpa_hexdump(MSG_DEBUG, "WNM: Remaining data",
  167. ptr, end - ptr);
  168. }
  169. break;
  170. }
  171. if (*ptr == WNM_SLEEP_SUBELEM_GTK) {
  172. if (ptr[1] < 11 + 5) {
  173. wpa_printf(MSG_DEBUG, "WNM: Too short GTK "
  174. "subelem");
  175. break;
  176. }
  177. gtk_len = *(ptr + 4);
  178. if (ptr[1] < 11 + gtk_len ||
  179. gtk_len < 5 || gtk_len > 32) {
  180. wpa_printf(MSG_DEBUG, "WNM: Invalid GTK "
  181. "subelem");
  182. break;
  183. }
  184. wpa_wnmsleep_install_key(
  185. wpa_s->wpa,
  186. WNM_SLEEP_SUBELEM_GTK,
  187. ptr);
  188. ptr += 13 + gtk_len;
  189. #ifdef CONFIG_IEEE80211W
  190. } else if (*ptr == WNM_SLEEP_SUBELEM_IGTK) {
  191. if (ptr[1] < 2 + 6 + WPA_IGTK_LEN) {
  192. wpa_printf(MSG_DEBUG, "WNM: Too short IGTK "
  193. "subelem");
  194. break;
  195. }
  196. wpa_wnmsleep_install_key(wpa_s->wpa,
  197. WNM_SLEEP_SUBELEM_IGTK, ptr);
  198. ptr += 10 + WPA_IGTK_LEN;
  199. #endif /* CONFIG_IEEE80211W */
  200. } else
  201. break; /* skip the loop */
  202. }
  203. }
  204. static void ieee802_11_rx_wnmsleep_resp(struct wpa_supplicant *wpa_s,
  205. const u8 *frm, int len)
  206. {
  207. /*
  208. * Action [1] | Dialog Token [1] | Key Data Len [2] | Key Data |
  209. * WNM-Sleep Mode IE | TFS Response IE
  210. */
  211. u8 *pos = (u8 *) frm; /* point to payload after the action field */
  212. u16 key_len_total;
  213. struct wnm_sleep_element *wnmsleep_ie = NULL;
  214. /* multiple TFS Resp IE (assuming consecutive) */
  215. u8 *tfsresp_ie_start = NULL;
  216. u8 *tfsresp_ie_end = NULL;
  217. size_t left;
  218. if (len < 3)
  219. return;
  220. key_len_total = WPA_GET_LE16(frm + 1);
  221. wpa_printf(MSG_DEBUG, "WNM-Sleep Mode Response token=%u key_len_total=%d",
  222. frm[0], key_len_total);
  223. left = len - 3;
  224. if (key_len_total > left) {
  225. wpa_printf(MSG_INFO, "WNM: Too short frame for Key Data field");
  226. return;
  227. }
  228. pos += 3 + key_len_total;
  229. while (pos - frm < len) {
  230. u8 ie_len = *(pos + 1);
  231. if (pos + 2 + ie_len > frm + len) {
  232. wpa_printf(MSG_INFO, "WNM: Invalid IE len %u", ie_len);
  233. break;
  234. }
  235. wpa_hexdump(MSG_DEBUG, "WNM: Element", pos, 2 + ie_len);
  236. if (*pos == WLAN_EID_WNMSLEEP)
  237. wnmsleep_ie = (struct wnm_sleep_element *) pos;
  238. else if (*pos == WLAN_EID_TFS_RESP) {
  239. if (!tfsresp_ie_start)
  240. tfsresp_ie_start = pos;
  241. tfsresp_ie_end = pos;
  242. } else
  243. wpa_printf(MSG_DEBUG, "EID %d not recognized", *pos);
  244. pos += ie_len + 2;
  245. }
  246. if (!wnmsleep_ie) {
  247. wpa_printf(MSG_DEBUG, "No WNM-Sleep IE found");
  248. return;
  249. }
  250. if (wnmsleep_ie->status == WNM_STATUS_SLEEP_ACCEPT ||
  251. wnmsleep_ie->status == WNM_STATUS_SLEEP_EXIT_ACCEPT_GTK_UPDATE) {
  252. wpa_printf(MSG_DEBUG, "Successfully recv WNM-Sleep Response "
  253. "frame (action=%d, intval=%d)",
  254. wnmsleep_ie->action_type, wnmsleep_ie->intval);
  255. if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_ENTER) {
  256. wnm_sleep_mode_enter_success(wpa_s, tfsresp_ie_start,
  257. tfsresp_ie_end);
  258. } else if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_EXIT) {
  259. wnm_sleep_mode_exit_success(wpa_s, frm, key_len_total);
  260. }
  261. } else {
  262. wpa_printf(MSG_DEBUG, "Reject recv WNM-Sleep Response frame "
  263. "(action=%d, intval=%d)",
  264. wnmsleep_ie->action_type, wnmsleep_ie->intval);
  265. if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_ENTER)
  266. wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_ENTER_FAIL,
  267. wpa_s->bssid, NULL, NULL);
  268. else if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_EXIT)
  269. wpa_drv_wnm_oper(wpa_s, WNM_SLEEP_EXIT_FAIL,
  270. wpa_s->bssid, NULL, NULL);
  271. }
  272. }
  273. void wnm_deallocate_memory(struct wpa_supplicant *wpa_s)
  274. {
  275. int i;
  276. for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) {
  277. os_free(wpa_s->wnm_neighbor_report_elements[i].meas_pilot);
  278. os_free(wpa_s->wnm_neighbor_report_elements[i].mul_bssid);
  279. }
  280. wpa_s->wnm_num_neighbor_report = 0;
  281. os_free(wpa_s->wnm_neighbor_report_elements);
  282. wpa_s->wnm_neighbor_report_elements = NULL;
  283. }
  284. static void wnm_parse_neighbor_report_elem(struct neighbor_report *rep,
  285. u8 id, u8 elen, const u8 *pos)
  286. {
  287. switch (id) {
  288. case WNM_NEIGHBOR_TSF:
  289. if (elen < 2 + 2) {
  290. wpa_printf(MSG_DEBUG, "WNM: Too short TSF");
  291. break;
  292. }
  293. rep->tsf_offset = WPA_GET_LE16(pos);
  294. rep->beacon_int = WPA_GET_LE16(pos + 2);
  295. rep->tsf_present = 1;
  296. break;
  297. case WNM_NEIGHBOR_CONDENSED_COUNTRY_STRING:
  298. if (elen < 2) {
  299. wpa_printf(MSG_DEBUG, "WNM: Too short condensed "
  300. "country string");
  301. break;
  302. }
  303. os_memcpy(rep->country, pos, 2);
  304. rep->country_present = 1;
  305. break;
  306. case WNM_NEIGHBOR_BSS_TRANSITION_CANDIDATE:
  307. if (elen < 1) {
  308. wpa_printf(MSG_DEBUG, "WNM: Too short BSS transition "
  309. "candidate");
  310. break;
  311. }
  312. rep->preference = pos[0];
  313. rep->preference_present = 1;
  314. break;
  315. case WNM_NEIGHBOR_BSS_TERMINATION_DURATION:
  316. rep->bss_term_tsf = WPA_GET_LE64(pos);
  317. rep->bss_term_dur = WPA_GET_LE16(pos + 8);
  318. rep->bss_term_present = 1;
  319. break;
  320. case WNM_NEIGHBOR_BEARING:
  321. if (elen < 8) {
  322. wpa_printf(MSG_DEBUG, "WNM: Too short neighbor "
  323. "bearing");
  324. break;
  325. }
  326. rep->bearing = WPA_GET_LE16(pos);
  327. rep->distance = WPA_GET_LE32(pos + 2);
  328. rep->rel_height = WPA_GET_LE16(pos + 2 + 4);
  329. rep->bearing_present = 1;
  330. break;
  331. case WNM_NEIGHBOR_MEASUREMENT_PILOT:
  332. if (elen < 1) {
  333. wpa_printf(MSG_DEBUG, "WNM: Too short measurement "
  334. "pilot");
  335. break;
  336. }
  337. os_free(rep->meas_pilot);
  338. rep->meas_pilot = os_zalloc(sizeof(struct measurement_pilot));
  339. if (rep->meas_pilot == NULL)
  340. break;
  341. rep->meas_pilot->measurement_pilot = pos[0];
  342. rep->meas_pilot->subelem_len = elen - 1;
  343. os_memcpy(rep->meas_pilot->subelems, pos + 1, elen - 1);
  344. break;
  345. case WNM_NEIGHBOR_RRM_ENABLED_CAPABILITIES:
  346. if (elen < 5) {
  347. wpa_printf(MSG_DEBUG, "WNM: Too short RRM enabled "
  348. "capabilities");
  349. break;
  350. }
  351. os_memcpy(rep->rm_capab, pos, 5);
  352. rep->rm_capab_present = 1;
  353. break;
  354. case WNM_NEIGHBOR_MULTIPLE_BSSID:
  355. if (elen < 1) {
  356. wpa_printf(MSG_DEBUG, "WNM: Too short multiple BSSID");
  357. break;
  358. }
  359. os_free(rep->mul_bssid);
  360. rep->mul_bssid = os_zalloc(sizeof(struct multiple_bssid));
  361. if (rep->mul_bssid == NULL)
  362. break;
  363. rep->mul_bssid->max_bssid_indicator = pos[0];
  364. rep->mul_bssid->subelem_len = elen - 1;
  365. os_memcpy(rep->mul_bssid->subelems, pos + 1, elen - 1);
  366. break;
  367. }
  368. }
  369. static int wnm_nei_get_chan(struct wpa_supplicant *wpa_s, u8 op_class, u8 chan)
  370. {
  371. return ieee80211_chan_to_freq(NULL, op_class, chan);
  372. }
  373. static void wnm_parse_neighbor_report(struct wpa_supplicant *wpa_s,
  374. const u8 *pos, u8 len,
  375. struct neighbor_report *rep)
  376. {
  377. u8 left = len;
  378. if (left < 13) {
  379. wpa_printf(MSG_DEBUG, "WNM: Too short neighbor report");
  380. return;
  381. }
  382. os_memcpy(rep->bssid, pos, ETH_ALEN);
  383. rep->bssid_info = WPA_GET_LE32(pos + ETH_ALEN);
  384. rep->regulatory_class = *(pos + 10);
  385. rep->channel_number = *(pos + 11);
  386. rep->phy_type = *(pos + 12);
  387. pos += 13;
  388. left -= 13;
  389. while (left >= 2) {
  390. u8 id, elen;
  391. id = *pos++;
  392. elen = *pos++;
  393. wpa_printf(MSG_DEBUG, "WNM: Subelement id=%u len=%u", id, elen);
  394. left -= 2;
  395. if (elen > left) {
  396. wpa_printf(MSG_DEBUG,
  397. "WNM: Truncated neighbor report subelement");
  398. break;
  399. }
  400. wnm_parse_neighbor_report_elem(rep, id, elen, pos);
  401. left -= elen;
  402. pos += elen;
  403. }
  404. rep->freq = wnm_nei_get_chan(wpa_s, rep->regulatory_class,
  405. rep->channel_number);
  406. }
  407. static struct wpa_bss *
  408. compare_scan_neighbor_results(struct wpa_supplicant *wpa_s)
  409. {
  410. u8 i;
  411. struct wpa_bss *bss = wpa_s->current_bss;
  412. struct wpa_bss *target;
  413. if (!bss)
  414. return 0;
  415. wpa_printf(MSG_DEBUG, "WNM: Current BSS " MACSTR " RSSI %d",
  416. MAC2STR(wpa_s->bssid), bss->level);
  417. for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) {
  418. struct neighbor_report *nei;
  419. nei = &wpa_s->wnm_neighbor_report_elements[i];
  420. if (nei->preference_present && nei->preference == 0) {
  421. wpa_printf(MSG_DEBUG, "Skip excluded BSS " MACSTR,
  422. MAC2STR(nei->bssid));
  423. continue;
  424. }
  425. target = wpa_bss_get_bssid(wpa_s, nei->bssid);
  426. if (!target) {
  427. wpa_printf(MSG_DEBUG, "Candidate BSS " MACSTR
  428. " (pref %d) not found in scan results",
  429. MAC2STR(nei->bssid),
  430. nei->preference_present ? nei->preference :
  431. -1);
  432. continue;
  433. }
  434. if (bss->ssid_len != target->ssid_len ||
  435. os_memcmp(bss->ssid, target->ssid, bss->ssid_len) != 0) {
  436. /*
  437. * TODO: Could consider allowing transition to another
  438. * ESS if PMF was enabled for the association.
  439. */
  440. wpa_printf(MSG_DEBUG, "Candidate BSS " MACSTR
  441. " (pref %d) in different ESS",
  442. MAC2STR(nei->bssid),
  443. nei->preference_present ? nei->preference :
  444. -1);
  445. continue;
  446. }
  447. if (target->level < bss->level && target->level < -80) {
  448. wpa_printf(MSG_DEBUG, "Candidate BSS " MACSTR
  449. " (pref %d) does not have sufficient signal level (%d)",
  450. MAC2STR(nei->bssid),
  451. nei->preference_present ? nei->preference :
  452. -1,
  453. target->level);
  454. continue;
  455. }
  456. wpa_printf(MSG_DEBUG,
  457. "WNM: Found an acceptable preferred transition candidate BSS "
  458. MACSTR " (RSSI %d)",
  459. MAC2STR(nei->bssid), target->level);
  460. return target;
  461. }
  462. return NULL;
  463. }
  464. static void wnm_send_bss_transition_mgmt_resp(
  465. struct wpa_supplicant *wpa_s, u8 dialog_token,
  466. enum bss_trans_mgmt_status_code status, u8 delay,
  467. const u8 *target_bssid)
  468. {
  469. u8 buf[1000], *pos;
  470. struct ieee80211_mgmt *mgmt;
  471. size_t len;
  472. int res;
  473. wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Response "
  474. "to " MACSTR " dialog_token=%u status=%u delay=%d",
  475. MAC2STR(wpa_s->bssid), dialog_token, status, delay);
  476. if (!wpa_s->current_bss) {
  477. wpa_printf(MSG_DEBUG,
  478. "WNM: Current BSS not known - drop response");
  479. return;
  480. }
  481. mgmt = (struct ieee80211_mgmt *) buf;
  482. os_memset(&buf, 0, sizeof(buf));
  483. os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN);
  484. os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
  485. os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
  486. mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  487. WLAN_FC_STYPE_ACTION);
  488. mgmt->u.action.category = WLAN_ACTION_WNM;
  489. mgmt->u.action.u.bss_tm_resp.action = WNM_BSS_TRANS_MGMT_RESP;
  490. mgmt->u.action.u.bss_tm_resp.dialog_token = dialog_token;
  491. mgmt->u.action.u.bss_tm_resp.status_code = status;
  492. mgmt->u.action.u.bss_tm_resp.bss_termination_delay = delay;
  493. pos = mgmt->u.action.u.bss_tm_resp.variable;
  494. if (target_bssid) {
  495. os_memcpy(pos, target_bssid, ETH_ALEN);
  496. pos += ETH_ALEN;
  497. } else if (status == WNM_BSS_TM_ACCEPT) {
  498. /*
  499. * P802.11-REVmc clarifies that the Target BSSID field is always
  500. * present when status code is zero, so use a fake value here if
  501. * no BSSID is yet known.
  502. */
  503. os_memset(pos, 0, ETH_ALEN);
  504. pos += ETH_ALEN;
  505. }
  506. len = pos - (u8 *) &mgmt->u.action.category;
  507. res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
  508. wpa_s->own_addr, wpa_s->bssid,
  509. &mgmt->u.action.category, len, 0);
  510. if (res < 0) {
  511. wpa_printf(MSG_DEBUG,
  512. "WNM: Failed to send BSS Transition Management Response");
  513. }
  514. }
  515. int wnm_scan_process(struct wpa_supplicant *wpa_s, int reply_on_fail)
  516. {
  517. struct wpa_bss *bss;
  518. struct wpa_ssid *ssid = wpa_s->current_ssid;
  519. enum bss_trans_mgmt_status_code status = WNM_BSS_TM_REJECT_UNSPECIFIED;
  520. if (!wpa_s->wnm_neighbor_report_elements)
  521. return 0;
  522. if (os_reltime_before(&wpa_s->wnm_cand_valid_until,
  523. &wpa_s->scan_trigger_time)) {
  524. wpa_printf(MSG_DEBUG, "WNM: Previously stored BSS transition candidate list is not valid anymore - drop it");
  525. wnm_deallocate_memory(wpa_s);
  526. return 0;
  527. }
  528. if (!wpa_s->current_bss ||
  529. os_memcmp(wpa_s->wnm_cand_from_bss, wpa_s->current_bss->bssid,
  530. ETH_ALEN) != 0) {
  531. wpa_printf(MSG_DEBUG, "WNM: Stored BSS transition candidate list not from the current BSS - ignore it");
  532. return 0;
  533. }
  534. /* Compare the Neighbor Report and scan results */
  535. bss = compare_scan_neighbor_results(wpa_s);
  536. if (!bss) {
  537. wpa_printf(MSG_DEBUG, "WNM: No BSS transition candidate match found");
  538. status = WNM_BSS_TM_REJECT_NO_SUITABLE_CANDIDATES;
  539. goto send_bss_resp_fail;
  540. }
  541. /* Associate to the network */
  542. /* Send the BSS Management Response - Accept */
  543. if (wpa_s->wnm_reply) {
  544. wpa_s->wnm_reply = 0;
  545. wnm_send_bss_transition_mgmt_resp(wpa_s,
  546. wpa_s->wnm_dialog_token,
  547. WNM_BSS_TM_ACCEPT,
  548. 0, bss->bssid);
  549. }
  550. if (bss == wpa_s->current_bss) {
  551. wpa_printf(MSG_DEBUG,
  552. "WNM: Already associated with the preferred candidate");
  553. return 1;
  554. }
  555. wpa_s->reassociate = 1;
  556. wpa_supplicant_connect(wpa_s, bss, ssid);
  557. wnm_deallocate_memory(wpa_s);
  558. return 1;
  559. send_bss_resp_fail:
  560. if (!reply_on_fail)
  561. return 0;
  562. /* Send reject response for all the failures */
  563. if (wpa_s->wnm_reply) {
  564. wpa_s->wnm_reply = 0;
  565. wnm_send_bss_transition_mgmt_resp(wpa_s,
  566. wpa_s->wnm_dialog_token,
  567. status, 0, NULL);
  568. }
  569. wnm_deallocate_memory(wpa_s);
  570. return 0;
  571. }
  572. static int cand_pref_compar(const void *a, const void *b)
  573. {
  574. const struct neighbor_report *aa = a;
  575. const struct neighbor_report *bb = b;
  576. if (!aa->preference_present && !bb->preference_present)
  577. return 0;
  578. if (!aa->preference_present)
  579. return 1;
  580. if (!bb->preference_present)
  581. return -1;
  582. if (bb->preference > aa->preference)
  583. return 1;
  584. if (bb->preference < aa->preference)
  585. return -1;
  586. return 0;
  587. }
  588. static void wnm_sort_cand_list(struct wpa_supplicant *wpa_s)
  589. {
  590. if (!wpa_s->wnm_neighbor_report_elements)
  591. return;
  592. qsort(wpa_s->wnm_neighbor_report_elements,
  593. wpa_s->wnm_num_neighbor_report, sizeof(struct neighbor_report),
  594. cand_pref_compar);
  595. }
  596. static void wnm_dump_cand_list(struct wpa_supplicant *wpa_s)
  597. {
  598. unsigned int i;
  599. wpa_printf(MSG_DEBUG, "WNM: BSS Transition Candidate List");
  600. if (!wpa_s->wnm_neighbor_report_elements)
  601. return;
  602. for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) {
  603. struct neighbor_report *nei;
  604. nei = &wpa_s->wnm_neighbor_report_elements[i];
  605. wpa_printf(MSG_DEBUG, "%u: " MACSTR
  606. " info=0x%x op_class=%u chan=%u phy=%u pref=%d freq=%d",
  607. i, MAC2STR(nei->bssid), nei->bssid_info,
  608. nei->regulatory_class,
  609. nei->channel_number, nei->phy_type,
  610. nei->preference_present ? nei->preference : -1,
  611. nei->freq);
  612. }
  613. }
  614. static int chan_supported(struct wpa_supplicant *wpa_s, int freq)
  615. {
  616. unsigned int i;
  617. for (i = 0; i < wpa_s->hw.num_modes; i++) {
  618. struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
  619. int j;
  620. for (j = 0; j < mode->num_channels; j++) {
  621. struct hostapd_channel_data *chan;
  622. chan = &mode->channels[j];
  623. if (chan->freq == freq &&
  624. !(chan->flag & HOSTAPD_CHAN_DISABLED))
  625. return 1;
  626. }
  627. }
  628. return 0;
  629. }
  630. static void wnm_set_scan_freqs(struct wpa_supplicant *wpa_s)
  631. {
  632. int *freqs;
  633. int num_freqs = 0;
  634. unsigned int i;
  635. if (!wpa_s->wnm_neighbor_report_elements)
  636. return;
  637. if (wpa_s->hw.modes == NULL)
  638. return;
  639. os_free(wpa_s->next_scan_freqs);
  640. wpa_s->next_scan_freqs = NULL;
  641. freqs = os_calloc(wpa_s->wnm_num_neighbor_report + 1, sizeof(int));
  642. if (freqs == NULL)
  643. return;
  644. for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) {
  645. struct neighbor_report *nei;
  646. nei = &wpa_s->wnm_neighbor_report_elements[i];
  647. if (nei->freq <= 0) {
  648. wpa_printf(MSG_DEBUG,
  649. "WNM: Unknown neighbor operating frequency for "
  650. MACSTR " - scan all channels",
  651. MAC2STR(nei->bssid));
  652. os_free(freqs);
  653. return;
  654. }
  655. if (chan_supported(wpa_s, nei->freq))
  656. add_freq(freqs, &num_freqs, nei->freq);
  657. }
  658. if (num_freqs == 0) {
  659. os_free(freqs);
  660. return;
  661. }
  662. wpa_printf(MSG_DEBUG,
  663. "WNM: Scan %d frequencies based on transition candidate list",
  664. num_freqs);
  665. wpa_s->next_scan_freqs = freqs;
  666. }
  667. static void ieee802_11_rx_bss_trans_mgmt_req(struct wpa_supplicant *wpa_s,
  668. const u8 *pos, const u8 *end,
  669. int reply)
  670. {
  671. unsigned int beacon_int;
  672. u8 valid_int;
  673. if (pos + 5 > end)
  674. return;
  675. if (wpa_s->current_bss)
  676. beacon_int = wpa_s->current_bss->beacon_int;
  677. else
  678. beacon_int = 100; /* best guess */
  679. wpa_s->wnm_dialog_token = pos[0];
  680. wpa_s->wnm_mode = pos[1];
  681. wpa_s->wnm_dissoc_timer = WPA_GET_LE16(pos + 2);
  682. valid_int = pos[4];
  683. wpa_s->wnm_reply = reply;
  684. wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management Request: "
  685. "dialog_token=%u request_mode=0x%x "
  686. "disassoc_timer=%u validity_interval=%u",
  687. wpa_s->wnm_dialog_token, wpa_s->wnm_mode,
  688. wpa_s->wnm_dissoc_timer, valid_int);
  689. pos += 5;
  690. if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED) {
  691. if (pos + 12 > end) {
  692. wpa_printf(MSG_DEBUG, "WNM: Too short BSS TM Request");
  693. return;
  694. }
  695. os_memcpy(wpa_s->wnm_bss_termination_duration, pos, 12);
  696. pos += 12; /* BSS Termination Duration */
  697. }
  698. if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT) {
  699. char url[256];
  700. if (pos + 1 > end || pos + 1 + pos[0] > end) {
  701. wpa_printf(MSG_DEBUG, "WNM: Invalid BSS Transition "
  702. "Management Request (URL)");
  703. return;
  704. }
  705. os_memcpy(url, pos + 1, pos[0]);
  706. url[pos[0]] = '\0';
  707. pos += 1 + pos[0];
  708. wpa_msg(wpa_s, MSG_INFO, ESS_DISASSOC_IMMINENT "%d %u %s",
  709. wpa_sm_pmf_enabled(wpa_s->wpa),
  710. wpa_s->wnm_dissoc_timer * beacon_int * 128 / 125, url);
  711. }
  712. if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_DISASSOC_IMMINENT) {
  713. wpa_msg(wpa_s, MSG_INFO, "WNM: Disassociation Imminent - "
  714. "Disassociation Timer %u", wpa_s->wnm_dissoc_timer);
  715. if (wpa_s->wnm_dissoc_timer && !wpa_s->scanning) {
  716. /* TODO: mark current BSS less preferred for
  717. * selection */
  718. wpa_printf(MSG_DEBUG, "Trying to find another BSS");
  719. wpa_supplicant_req_scan(wpa_s, 0, 0);
  720. }
  721. }
  722. if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_PREF_CAND_LIST_INCLUDED) {
  723. unsigned int valid_ms;
  724. wpa_msg(wpa_s, MSG_INFO, "WNM: Preferred List Available");
  725. wnm_deallocate_memory(wpa_s);
  726. wpa_s->wnm_neighbor_report_elements = os_zalloc(
  727. WNM_MAX_NEIGHBOR_REPORT *
  728. sizeof(struct neighbor_report));
  729. if (wpa_s->wnm_neighbor_report_elements == NULL)
  730. return;
  731. while (pos + 2 <= end &&
  732. wpa_s->wnm_num_neighbor_report < WNM_MAX_NEIGHBOR_REPORT)
  733. {
  734. u8 tag = *pos++;
  735. u8 len = *pos++;
  736. wpa_printf(MSG_DEBUG, "WNM: Neighbor report tag %u",
  737. tag);
  738. if (pos + len > end) {
  739. wpa_printf(MSG_DEBUG, "WNM: Truncated request");
  740. return;
  741. }
  742. if (tag == WLAN_EID_NEIGHBOR_REPORT) {
  743. struct neighbor_report *rep;
  744. rep = &wpa_s->wnm_neighbor_report_elements[
  745. wpa_s->wnm_num_neighbor_report];
  746. wnm_parse_neighbor_report(wpa_s, pos, len, rep);
  747. }
  748. pos += len;
  749. wpa_s->wnm_num_neighbor_report++;
  750. }
  751. wnm_sort_cand_list(wpa_s);
  752. wnm_dump_cand_list(wpa_s);
  753. valid_ms = valid_int * beacon_int * 128 / 125;
  754. wpa_printf(MSG_DEBUG, "WNM: Candidate list valid for %u ms",
  755. valid_ms);
  756. os_get_reltime(&wpa_s->wnm_cand_valid_until);
  757. wpa_s->wnm_cand_valid_until.sec += valid_ms / 1000;
  758. wpa_s->wnm_cand_valid_until.usec += (valid_ms % 1000) * 1000;
  759. wpa_s->wnm_cand_valid_until.sec +=
  760. wpa_s->wnm_cand_valid_until.usec / 1000000;
  761. wpa_s->wnm_cand_valid_until.usec %= 1000000;
  762. os_memcpy(wpa_s->wnm_cand_from_bss, wpa_s->bssid, ETH_ALEN);
  763. if (wpa_s->last_scan_res_used > 0) {
  764. struct os_reltime now;
  765. os_get_reltime(&now);
  766. if (!os_reltime_expired(&now, &wpa_s->last_scan, 10)) {
  767. wpa_printf(MSG_DEBUG,
  768. "WNM: Try to use recent scan results");
  769. if (wnm_scan_process(wpa_s, 0) > 0)
  770. return;
  771. wpa_printf(MSG_DEBUG,
  772. "WNM: No match in previous scan results - try a new scan");
  773. }
  774. }
  775. wnm_set_scan_freqs(wpa_s);
  776. wpa_supplicant_req_scan(wpa_s, 0, 0);
  777. } else if (reply) {
  778. enum bss_trans_mgmt_status_code status;
  779. if (wpa_s->wnm_mode & WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT)
  780. status = WNM_BSS_TM_ACCEPT;
  781. else {
  782. wpa_msg(wpa_s, MSG_INFO, "WNM: BSS Transition Management Request did not include candidates");
  783. status = WNM_BSS_TM_REJECT_UNSPECIFIED;
  784. }
  785. wnm_send_bss_transition_mgmt_resp(wpa_s,
  786. wpa_s->wnm_dialog_token,
  787. status, 0, NULL);
  788. }
  789. }
  790. int wnm_send_bss_transition_mgmt_query(struct wpa_supplicant *wpa_s,
  791. u8 query_reason)
  792. {
  793. u8 buf[1000], *pos;
  794. struct ieee80211_mgmt *mgmt;
  795. size_t len;
  796. int ret;
  797. wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Query to "
  798. MACSTR " query_reason=%u",
  799. MAC2STR(wpa_s->bssid), query_reason);
  800. mgmt = (struct ieee80211_mgmt *) buf;
  801. os_memset(&buf, 0, sizeof(buf));
  802. os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN);
  803. os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
  804. os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
  805. mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  806. WLAN_FC_STYPE_ACTION);
  807. mgmt->u.action.category = WLAN_ACTION_WNM;
  808. mgmt->u.action.u.bss_tm_query.action = WNM_BSS_TRANS_MGMT_QUERY;
  809. mgmt->u.action.u.bss_tm_query.dialog_token = 1;
  810. mgmt->u.action.u.bss_tm_query.query_reason = query_reason;
  811. pos = mgmt->u.action.u.bss_tm_query.variable;
  812. len = pos - (u8 *) &mgmt->u.action.category;
  813. ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
  814. wpa_s->own_addr, wpa_s->bssid,
  815. &mgmt->u.action.category, len, 0);
  816. return ret;
  817. }
  818. static void ieee802_11_rx_wnm_notif_req_wfa(struct wpa_supplicant *wpa_s,
  819. const u8 *sa, const u8 *data,
  820. int len)
  821. {
  822. const u8 *pos, *end, *next;
  823. u8 ie, ie_len;
  824. pos = data;
  825. end = data + len;
  826. while (pos + 1 < end) {
  827. ie = *pos++;
  828. ie_len = *pos++;
  829. wpa_printf(MSG_DEBUG, "WNM: WFA subelement %u len %u",
  830. ie, ie_len);
  831. if (ie_len > end - pos) {
  832. wpa_printf(MSG_DEBUG, "WNM: Not enough room for "
  833. "subelement");
  834. break;
  835. }
  836. next = pos + ie_len;
  837. if (ie_len < 4) {
  838. pos = next;
  839. continue;
  840. }
  841. wpa_printf(MSG_DEBUG, "WNM: Subelement OUI %06x type %u",
  842. WPA_GET_BE24(pos), pos[3]);
  843. #ifdef CONFIG_HS20
  844. if (ie == WLAN_EID_VENDOR_SPECIFIC && ie_len >= 5 &&
  845. WPA_GET_BE24(pos) == OUI_WFA &&
  846. pos[3] == HS20_WNM_SUB_REM_NEEDED) {
  847. /* Subscription Remediation subelement */
  848. const u8 *ie_end;
  849. u8 url_len;
  850. char *url;
  851. u8 osu_method;
  852. wpa_printf(MSG_DEBUG, "WNM: Subscription Remediation "
  853. "subelement");
  854. ie_end = pos + ie_len;
  855. pos += 4;
  856. url_len = *pos++;
  857. if (url_len == 0) {
  858. wpa_printf(MSG_DEBUG, "WNM: No Server URL included");
  859. url = NULL;
  860. osu_method = 1;
  861. } else {
  862. if (pos + url_len + 1 > ie_end) {
  863. wpa_printf(MSG_DEBUG, "WNM: Not enough room for Server URL (len=%u) and Server Method (left %d)",
  864. url_len,
  865. (int) (ie_end - pos));
  866. break;
  867. }
  868. url = os_malloc(url_len + 1);
  869. if (url == NULL)
  870. break;
  871. os_memcpy(url, pos, url_len);
  872. url[url_len] = '\0';
  873. osu_method = pos[url_len];
  874. }
  875. hs20_rx_subscription_remediation(wpa_s, url,
  876. osu_method);
  877. os_free(url);
  878. pos = next;
  879. continue;
  880. }
  881. if (ie == WLAN_EID_VENDOR_SPECIFIC && ie_len >= 8 &&
  882. WPA_GET_BE24(pos) == OUI_WFA &&
  883. pos[3] == HS20_WNM_DEAUTH_IMMINENT_NOTICE) {
  884. const u8 *ie_end;
  885. u8 url_len;
  886. char *url;
  887. u8 code;
  888. u16 reauth_delay;
  889. ie_end = pos + ie_len;
  890. pos += 4;
  891. code = *pos++;
  892. reauth_delay = WPA_GET_LE16(pos);
  893. pos += 2;
  894. url_len = *pos++;
  895. wpa_printf(MSG_DEBUG, "WNM: HS 2.0 Deauthentication "
  896. "Imminent - Reason Code %u "
  897. "Re-Auth Delay %u URL Length %u",
  898. code, reauth_delay, url_len);
  899. if (pos + url_len > ie_end)
  900. break;
  901. url = os_malloc(url_len + 1);
  902. if (url == NULL)
  903. break;
  904. os_memcpy(url, pos, url_len);
  905. url[url_len] = '\0';
  906. hs20_rx_deauth_imminent_notice(wpa_s, code,
  907. reauth_delay, url);
  908. os_free(url);
  909. pos = next;
  910. continue;
  911. }
  912. #endif /* CONFIG_HS20 */
  913. pos = next;
  914. }
  915. }
  916. static void ieee802_11_rx_wnm_notif_req(struct wpa_supplicant *wpa_s,
  917. const u8 *sa, const u8 *frm, int len)
  918. {
  919. const u8 *pos, *end;
  920. u8 dialog_token, type;
  921. /* Dialog Token [1] | Type [1] | Subelements */
  922. if (len < 2 || sa == NULL)
  923. return;
  924. end = frm + len;
  925. pos = frm;
  926. dialog_token = *pos++;
  927. type = *pos++;
  928. wpa_dbg(wpa_s, MSG_DEBUG, "WNM: Received WNM-Notification Request "
  929. "(dialog_token %u type %u sa " MACSTR ")",
  930. dialog_token, type, MAC2STR(sa));
  931. wpa_hexdump(MSG_DEBUG, "WNM-Notification Request subelements",
  932. pos, end - pos);
  933. if (wpa_s->wpa_state != WPA_COMPLETED ||
  934. os_memcmp(sa, wpa_s->bssid, ETH_ALEN) != 0) {
  935. wpa_dbg(wpa_s, MSG_DEBUG, "WNM: WNM-Notification frame not "
  936. "from our AP - ignore it");
  937. return;
  938. }
  939. switch (type) {
  940. case 1:
  941. ieee802_11_rx_wnm_notif_req_wfa(wpa_s, sa, pos, end - pos);
  942. break;
  943. default:
  944. wpa_dbg(wpa_s, MSG_DEBUG, "WNM: Ignore unknown "
  945. "WNM-Notification type %u", type);
  946. break;
  947. }
  948. }
  949. void ieee802_11_rx_wnm_action(struct wpa_supplicant *wpa_s,
  950. const struct ieee80211_mgmt *mgmt, size_t len)
  951. {
  952. const u8 *pos, *end;
  953. u8 act;
  954. if (len < IEEE80211_HDRLEN + 2)
  955. return;
  956. pos = ((const u8 *) mgmt) + IEEE80211_HDRLEN + 1;
  957. act = *pos++;
  958. end = ((const u8 *) mgmt) + len;
  959. wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR,
  960. act, MAC2STR(mgmt->sa));
  961. if (wpa_s->wpa_state < WPA_ASSOCIATED ||
  962. os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) != 0) {
  963. wpa_printf(MSG_DEBUG, "WNM: Ignore unexpected WNM Action "
  964. "frame");
  965. return;
  966. }
  967. switch (act) {
  968. case WNM_BSS_TRANS_MGMT_REQ:
  969. ieee802_11_rx_bss_trans_mgmt_req(wpa_s, pos, end,
  970. !(mgmt->da[0] & 0x01));
  971. break;
  972. case WNM_SLEEP_MODE_RESP:
  973. ieee802_11_rx_wnmsleep_resp(wpa_s, pos, end - pos);
  974. break;
  975. case WNM_NOTIFICATION_REQ:
  976. ieee802_11_rx_wnm_notif_req(wpa_s, mgmt->sa, pos, end - pos);
  977. break;
  978. default:
  979. wpa_printf(MSG_ERROR, "WNM: Unknown request");
  980. break;
  981. }
  982. }