wnm_sta.c 31 KB

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