wnm_sta.c 30 KB

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