wnm_sta.c 31 KB

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