wnm_sta.c 30 KB

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