wnm_sta.c 30 KB

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