wnm_ap.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. /*
  2. * hostapd - WNM
  3. * Copyright (c) 2011-2014, 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 "utils/eloop.h"
  11. #include "common/ieee802_11_defs.h"
  12. #include "common/wpa_ctrl.h"
  13. #include "ap/hostapd.h"
  14. #include "ap/sta_info.h"
  15. #include "ap/ap_config.h"
  16. #include "ap/ap_drv_ops.h"
  17. #include "ap/wpa_auth.h"
  18. #include "wnm_ap.h"
  19. #define MAX_TFS_IE_LEN 1024
  20. /* get the TFS IE from driver */
  21. static int ieee80211_11_get_tfs_ie(struct hostapd_data *hapd, const u8 *addr,
  22. u8 *buf, u16 *buf_len, enum wnm_oper oper)
  23. {
  24. wpa_printf(MSG_DEBUG, "%s: TFS get operation %d", __func__, oper);
  25. return hostapd_drv_wnm_oper(hapd, oper, addr, buf, buf_len);
  26. }
  27. /* set the TFS IE to driver */
  28. static int ieee80211_11_set_tfs_ie(struct hostapd_data *hapd, const u8 *addr,
  29. u8 *buf, u16 *buf_len, enum wnm_oper oper)
  30. {
  31. wpa_printf(MSG_DEBUG, "%s: TFS set operation %d", __func__, oper);
  32. return hostapd_drv_wnm_oper(hapd, oper, addr, buf, buf_len);
  33. }
  34. /* MLME-SLEEPMODE.response */
  35. static int ieee802_11_send_wnmsleep_resp(struct hostapd_data *hapd,
  36. const u8 *addr, u8 dialog_token,
  37. u8 action_type, u16 intval)
  38. {
  39. struct ieee80211_mgmt *mgmt;
  40. int res;
  41. size_t len;
  42. size_t gtk_elem_len = 0;
  43. size_t igtk_elem_len = 0;
  44. struct wnm_sleep_element wnmsleep_ie;
  45. u8 *wnmtfs_ie;
  46. u8 wnmsleep_ie_len;
  47. u16 wnmtfs_ie_len;
  48. u8 *pos;
  49. struct sta_info *sta;
  50. enum wnm_oper tfs_oper = action_type == WNM_SLEEP_MODE_ENTER ?
  51. WNM_SLEEP_TFS_RESP_IE_ADD : WNM_SLEEP_TFS_RESP_IE_NONE;
  52. sta = ap_get_sta(hapd, addr);
  53. if (sta == NULL) {
  54. wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
  55. return -EINVAL;
  56. }
  57. /* WNM-Sleep Mode IE */
  58. os_memset(&wnmsleep_ie, 0, sizeof(struct wnm_sleep_element));
  59. wnmsleep_ie_len = sizeof(struct wnm_sleep_element);
  60. wnmsleep_ie.eid = WLAN_EID_WNMSLEEP;
  61. wnmsleep_ie.len = wnmsleep_ie_len - 2;
  62. wnmsleep_ie.action_type = action_type;
  63. wnmsleep_ie.status = WNM_STATUS_SLEEP_ACCEPT;
  64. wnmsleep_ie.intval = host_to_le16(intval);
  65. /* TFS IE(s) */
  66. wnmtfs_ie = os_zalloc(MAX_TFS_IE_LEN);
  67. if (wnmtfs_ie == NULL)
  68. return -1;
  69. if (ieee80211_11_get_tfs_ie(hapd, addr, wnmtfs_ie, &wnmtfs_ie_len,
  70. tfs_oper)) {
  71. wnmtfs_ie_len = 0;
  72. os_free(wnmtfs_ie);
  73. wnmtfs_ie = NULL;
  74. }
  75. #define MAX_GTK_SUBELEM_LEN 45
  76. #define MAX_IGTK_SUBELEM_LEN 26
  77. mgmt = os_zalloc(sizeof(*mgmt) + wnmsleep_ie_len +
  78. MAX_GTK_SUBELEM_LEN + MAX_IGTK_SUBELEM_LEN);
  79. if (mgmt == NULL) {
  80. wpa_printf(MSG_DEBUG, "MLME: Failed to allocate buffer for "
  81. "WNM-Sleep Response action frame");
  82. return -1;
  83. }
  84. os_memcpy(mgmt->da, addr, ETH_ALEN);
  85. os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
  86. os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
  87. mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  88. WLAN_FC_STYPE_ACTION);
  89. mgmt->u.action.category = WLAN_ACTION_WNM;
  90. mgmt->u.action.u.wnm_sleep_resp.action = WNM_SLEEP_MODE_RESP;
  91. mgmt->u.action.u.wnm_sleep_resp.dialogtoken = dialog_token;
  92. pos = (u8 *)mgmt->u.action.u.wnm_sleep_resp.variable;
  93. /* add key data if MFP is enabled */
  94. if (!wpa_auth_uses_mfp(sta->wpa_sm) ||
  95. action_type != WNM_SLEEP_MODE_EXIT) {
  96. mgmt->u.action.u.wnm_sleep_resp.keydata_len = 0;
  97. } else {
  98. gtk_elem_len = wpa_wnmsleep_gtk_subelem(sta->wpa_sm, pos);
  99. pos += gtk_elem_len;
  100. wpa_printf(MSG_DEBUG, "Pass 4, gtk_len = %d",
  101. (int) gtk_elem_len);
  102. #ifdef CONFIG_IEEE80211W
  103. res = wpa_wnmsleep_igtk_subelem(sta->wpa_sm, pos);
  104. if (res < 0) {
  105. os_free(wnmtfs_ie);
  106. os_free(mgmt);
  107. return -1;
  108. }
  109. igtk_elem_len = res;
  110. pos += igtk_elem_len;
  111. wpa_printf(MSG_DEBUG, "Pass 4 igtk_len = %d",
  112. (int) igtk_elem_len);
  113. #endif /* CONFIG_IEEE80211W */
  114. WPA_PUT_LE16((u8 *)
  115. &mgmt->u.action.u.wnm_sleep_resp.keydata_len,
  116. gtk_elem_len + igtk_elem_len);
  117. }
  118. os_memcpy(pos, &wnmsleep_ie, wnmsleep_ie_len);
  119. /* copy TFS IE here */
  120. pos += wnmsleep_ie_len;
  121. if (wnmtfs_ie)
  122. os_memcpy(pos, wnmtfs_ie, wnmtfs_ie_len);
  123. len = 1 + sizeof(mgmt->u.action.u.wnm_sleep_resp) + gtk_elem_len +
  124. igtk_elem_len + wnmsleep_ie_len + wnmtfs_ie_len;
  125. /* In driver, response frame should be forced to sent when STA is in
  126. * PS mode */
  127. res = hostapd_drv_send_action(hapd, hapd->iface->freq, 0,
  128. mgmt->da, &mgmt->u.action.category, len);
  129. if (!res) {
  130. wpa_printf(MSG_DEBUG, "Successfully send WNM-Sleep Response "
  131. "frame");
  132. /* when entering wnmsleep
  133. * 1. pause the node in driver
  134. * 2. mark the node so that AP won't update GTK/IGTK during
  135. * WNM Sleep
  136. */
  137. if (wnmsleep_ie.status == WNM_STATUS_SLEEP_ACCEPT &&
  138. wnmsleep_ie.action_type == WNM_SLEEP_MODE_ENTER) {
  139. sta->flags |= WLAN_STA_WNM_SLEEP_MODE;
  140. hostapd_drv_wnm_oper(hapd, WNM_SLEEP_ENTER_CONFIRM,
  141. addr, NULL, NULL);
  142. wpa_set_wnmsleep(sta->wpa_sm, 1);
  143. }
  144. /* when exiting wnmsleep
  145. * 1. unmark the node
  146. * 2. start GTK/IGTK update if MFP is not used
  147. * 3. unpause the node in driver
  148. */
  149. if ((wnmsleep_ie.status == WNM_STATUS_SLEEP_ACCEPT ||
  150. wnmsleep_ie.status ==
  151. WNM_STATUS_SLEEP_EXIT_ACCEPT_GTK_UPDATE) &&
  152. wnmsleep_ie.action_type == WNM_SLEEP_MODE_EXIT) {
  153. sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
  154. wpa_set_wnmsleep(sta->wpa_sm, 0);
  155. hostapd_drv_wnm_oper(hapd, WNM_SLEEP_EXIT_CONFIRM,
  156. addr, NULL, NULL);
  157. if (!wpa_auth_uses_mfp(sta->wpa_sm))
  158. wpa_wnmsleep_rekey_gtk(sta->wpa_sm);
  159. }
  160. } else
  161. wpa_printf(MSG_DEBUG, "Fail to send WNM-Sleep Response frame");
  162. #undef MAX_GTK_SUBELEM_LEN
  163. #undef MAX_IGTK_SUBELEM_LEN
  164. os_free(wnmtfs_ie);
  165. os_free(mgmt);
  166. return res;
  167. }
  168. static void ieee802_11_rx_wnmsleep_req(struct hostapd_data *hapd,
  169. const u8 *addr, const u8 *frm, int len)
  170. {
  171. /* Dialog Token [1] | WNM-Sleep Mode IE | TFS Response IE */
  172. const u8 *pos = frm;
  173. u8 dialog_token;
  174. struct wnm_sleep_element *wnmsleep_ie = NULL;
  175. /* multiple TFS Req IE (assuming consecutive) */
  176. u8 *tfsreq_ie_start = NULL;
  177. u8 *tfsreq_ie_end = NULL;
  178. u16 tfsreq_ie_len = 0;
  179. dialog_token = *pos++;
  180. while (pos + 1 < frm + len) {
  181. u8 ie_len = pos[1];
  182. if (pos + 2 + ie_len > frm + len)
  183. break;
  184. if (*pos == WLAN_EID_WNMSLEEP)
  185. wnmsleep_ie = (struct wnm_sleep_element *) pos;
  186. else if (*pos == WLAN_EID_TFS_REQ) {
  187. if (!tfsreq_ie_start)
  188. tfsreq_ie_start = (u8 *) pos;
  189. tfsreq_ie_end = (u8 *) pos;
  190. } else
  191. wpa_printf(MSG_DEBUG, "WNM: EID %d not recognized",
  192. *pos);
  193. pos += ie_len + 2;
  194. }
  195. if (!wnmsleep_ie) {
  196. wpa_printf(MSG_DEBUG, "No WNM-Sleep IE found");
  197. return;
  198. }
  199. if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_ENTER &&
  200. tfsreq_ie_start && tfsreq_ie_end &&
  201. tfsreq_ie_end - tfsreq_ie_start >= 0) {
  202. tfsreq_ie_len = (tfsreq_ie_end + tfsreq_ie_end[1] + 2) -
  203. tfsreq_ie_start;
  204. wpa_printf(MSG_DEBUG, "TFS Req IE(s) found");
  205. /* pass the TFS Req IE(s) to driver for processing */
  206. if (ieee80211_11_set_tfs_ie(hapd, addr, tfsreq_ie_start,
  207. &tfsreq_ie_len,
  208. WNM_SLEEP_TFS_REQ_IE_SET))
  209. wpa_printf(MSG_DEBUG, "Fail to set TFS Req IE");
  210. }
  211. ieee802_11_send_wnmsleep_resp(hapd, addr, dialog_token,
  212. wnmsleep_ie->action_type,
  213. le_to_host16(wnmsleep_ie->intval));
  214. if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_EXIT) {
  215. /* clear the tfs after sending the resp frame */
  216. ieee80211_11_set_tfs_ie(hapd, addr, tfsreq_ie_start,
  217. &tfsreq_ie_len, WNM_SLEEP_TFS_IE_DEL);
  218. }
  219. }
  220. static int ieee802_11_send_bss_trans_mgmt_request(struct hostapd_data *hapd,
  221. const u8 *addr,
  222. u8 dialog_token,
  223. const char *url)
  224. {
  225. struct ieee80211_mgmt *mgmt;
  226. size_t url_len, len;
  227. u8 *pos;
  228. int res;
  229. if (url)
  230. url_len = os_strlen(url);
  231. else
  232. url_len = 0;
  233. mgmt = os_zalloc(sizeof(*mgmt) + (url_len ? 1 + url_len : 0));
  234. if (mgmt == NULL)
  235. return -1;
  236. os_memcpy(mgmt->da, addr, ETH_ALEN);
  237. os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
  238. os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
  239. mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  240. WLAN_FC_STYPE_ACTION);
  241. mgmt->u.action.category = WLAN_ACTION_WNM;
  242. mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
  243. mgmt->u.action.u.bss_tm_req.dialog_token = dialog_token;
  244. mgmt->u.action.u.bss_tm_req.req_mode = 0;
  245. mgmt->u.action.u.bss_tm_req.disassoc_timer = host_to_le16(0);
  246. mgmt->u.action.u.bss_tm_req.validity_interval = 1;
  247. pos = mgmt->u.action.u.bss_tm_req.variable;
  248. if (url) {
  249. *pos++ += url_len;
  250. os_memcpy(pos, url, url_len);
  251. pos += url_len;
  252. }
  253. wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request to "
  254. MACSTR " dialog_token=%u req_mode=0x%x disassoc_timer=%u "
  255. "validity_interval=%u",
  256. MAC2STR(addr), dialog_token,
  257. mgmt->u.action.u.bss_tm_req.req_mode,
  258. le_to_host16(mgmt->u.action.u.bss_tm_req.disassoc_timer),
  259. mgmt->u.action.u.bss_tm_req.validity_interval);
  260. len = pos - &mgmt->u.action.category;
  261. res = hostapd_drv_send_action(hapd, hapd->iface->freq, 0,
  262. mgmt->da, &mgmt->u.action.category, len);
  263. os_free(mgmt);
  264. return res;
  265. }
  266. static void ieee802_11_rx_bss_trans_mgmt_query(struct hostapd_data *hapd,
  267. const u8 *addr, const u8 *frm,
  268. size_t len)
  269. {
  270. u8 dialog_token, reason;
  271. const u8 *pos, *end;
  272. if (len < 2) {
  273. wpa_printf(MSG_DEBUG, "WNM: Ignore too short BSS Transition Management Query from "
  274. MACSTR, MAC2STR(addr));
  275. return;
  276. }
  277. pos = frm;
  278. end = pos + len;
  279. dialog_token = *pos++;
  280. reason = *pos++;
  281. wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management Query from "
  282. MACSTR " dialog_token=%u reason=%u",
  283. MAC2STR(addr), dialog_token, reason);
  284. wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries",
  285. pos, end - pos);
  286. ieee802_11_send_bss_trans_mgmt_request(hapd, addr, dialog_token, NULL);
  287. }
  288. static void ieee802_11_rx_bss_trans_mgmt_resp(struct hostapd_data *hapd,
  289. const u8 *addr, const u8 *frm,
  290. size_t len)
  291. {
  292. u8 dialog_token, status_code, bss_termination_delay;
  293. const u8 *pos, *end;
  294. if (len < 3) {
  295. wpa_printf(MSG_DEBUG, "WNM: Ignore too short BSS Transition Management Response from "
  296. MACSTR, MAC2STR(addr));
  297. return;
  298. }
  299. pos = frm;
  300. end = pos + len;
  301. dialog_token = *pos++;
  302. status_code = *pos++;
  303. bss_termination_delay = *pos++;
  304. wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management Response from "
  305. MACSTR " dialog_token=%u status_code=%u "
  306. "bss_termination_delay=%u", MAC2STR(addr), dialog_token,
  307. status_code, bss_termination_delay);
  308. if (status_code == WNM_BSS_TM_ACCEPT) {
  309. if (end - pos < ETH_ALEN) {
  310. wpa_printf(MSG_DEBUG, "WNM: not enough room for Target BSSID field");
  311. return;
  312. }
  313. wpa_printf(MSG_DEBUG, "WNM: Target BSSID: " MACSTR,
  314. MAC2STR(pos));
  315. wpa_msg(hapd->msg_ctx, MSG_INFO, BSS_TM_RESP MACSTR
  316. " status_code=%u bss_termination_delay=%u target_bssid="
  317. MACSTR,
  318. MAC2STR(addr), status_code, bss_termination_delay,
  319. MAC2STR(pos));
  320. pos += ETH_ALEN;
  321. } else {
  322. wpa_msg(hapd->msg_ctx, MSG_INFO, BSS_TM_RESP MACSTR
  323. " status_code=%u bss_termination_delay=%u",
  324. MAC2STR(addr), status_code, bss_termination_delay);
  325. }
  326. wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries",
  327. pos, end - pos);
  328. }
  329. int ieee802_11_rx_wnm_action_ap(struct hostapd_data *hapd,
  330. const struct ieee80211_mgmt *mgmt, size_t len)
  331. {
  332. u8 action;
  333. const u8 *payload;
  334. size_t plen;
  335. if (len < IEEE80211_HDRLEN + 2)
  336. return -1;
  337. payload = ((const u8 *) mgmt) + IEEE80211_HDRLEN + 1;
  338. action = *payload++;
  339. plen = len - IEEE80211_HDRLEN - 2;
  340. switch (action) {
  341. case WNM_BSS_TRANS_MGMT_QUERY:
  342. ieee802_11_rx_bss_trans_mgmt_query(hapd, mgmt->sa, payload,
  343. plen);
  344. return 0;
  345. case WNM_BSS_TRANS_MGMT_RESP:
  346. ieee802_11_rx_bss_trans_mgmt_resp(hapd, mgmt->sa, payload,
  347. plen);
  348. return 0;
  349. case WNM_SLEEP_MODE_REQ:
  350. ieee802_11_rx_wnmsleep_req(hapd, mgmt->sa, payload, plen);
  351. return 0;
  352. }
  353. wpa_printf(MSG_DEBUG, "WNM: Unsupported WNM Action %u from " MACSTR,
  354. action, MAC2STR(mgmt->sa));
  355. return -1;
  356. }
  357. int wnm_send_disassoc_imminent(struct hostapd_data *hapd,
  358. struct sta_info *sta, int disassoc_timer)
  359. {
  360. u8 buf[1000], *pos;
  361. struct ieee80211_mgmt *mgmt;
  362. os_memset(buf, 0, sizeof(buf));
  363. mgmt = (struct ieee80211_mgmt *) buf;
  364. mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  365. WLAN_FC_STYPE_ACTION);
  366. os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
  367. os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
  368. os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
  369. mgmt->u.action.category = WLAN_ACTION_WNM;
  370. mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
  371. mgmt->u.action.u.bss_tm_req.dialog_token = 1;
  372. mgmt->u.action.u.bss_tm_req.req_mode =
  373. WNM_BSS_TM_REQ_DISASSOC_IMMINENT;
  374. mgmt->u.action.u.bss_tm_req.disassoc_timer =
  375. host_to_le16(disassoc_timer);
  376. mgmt->u.action.u.bss_tm_req.validity_interval = 0;
  377. pos = mgmt->u.action.u.bss_tm_req.variable;
  378. wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request frame to indicate imminent disassociation (disassoc_timer=%d) to "
  379. MACSTR, disassoc_timer, MAC2STR(sta->addr));
  380. if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0) < 0) {
  381. wpa_printf(MSG_DEBUG, "Failed to send BSS Transition "
  382. "Management Request frame");
  383. return -1;
  384. }
  385. return 0;
  386. }
  387. static void set_disassoc_timer(struct hostapd_data *hapd, struct sta_info *sta,
  388. int disassoc_timer)
  389. {
  390. int timeout, beacon_int;
  391. /*
  392. * Prevent STA from reconnecting using cached PMKSA to force
  393. * full authentication with the authentication server (which may
  394. * decide to reject the connection),
  395. */
  396. wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
  397. beacon_int = hapd->iconf->beacon_int;
  398. if (beacon_int < 1)
  399. beacon_int = 100; /* best guess */
  400. /* Calculate timeout in ms based on beacon_int in TU */
  401. timeout = disassoc_timer * beacon_int * 128 / 125;
  402. wpa_printf(MSG_DEBUG, "Disassociation timer for " MACSTR
  403. " set to %d ms", MAC2STR(sta->addr), timeout);
  404. sta->timeout_next = STA_DISASSOC_FROM_CLI;
  405. eloop_cancel_timeout(ap_handle_timer, hapd, sta);
  406. eloop_register_timeout(timeout / 1000,
  407. timeout % 1000 * 1000,
  408. ap_handle_timer, hapd, sta);
  409. }
  410. int wnm_send_ess_disassoc_imminent(struct hostapd_data *hapd,
  411. struct sta_info *sta, const char *url,
  412. int disassoc_timer)
  413. {
  414. u8 buf[1000], *pos;
  415. struct ieee80211_mgmt *mgmt;
  416. size_t url_len;
  417. os_memset(buf, 0, sizeof(buf));
  418. mgmt = (struct ieee80211_mgmt *) buf;
  419. mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  420. WLAN_FC_STYPE_ACTION);
  421. os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
  422. os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
  423. os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
  424. mgmt->u.action.category = WLAN_ACTION_WNM;
  425. mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
  426. mgmt->u.action.u.bss_tm_req.dialog_token = 1;
  427. mgmt->u.action.u.bss_tm_req.req_mode =
  428. WNM_BSS_TM_REQ_DISASSOC_IMMINENT |
  429. WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT;
  430. mgmt->u.action.u.bss_tm_req.disassoc_timer =
  431. host_to_le16(disassoc_timer);
  432. mgmt->u.action.u.bss_tm_req.validity_interval = 0x01;
  433. pos = mgmt->u.action.u.bss_tm_req.variable;
  434. /* Session Information URL */
  435. url_len = os_strlen(url);
  436. if (url_len > 255)
  437. return -1;
  438. *pos++ = url_len;
  439. os_memcpy(pos, url, url_len);
  440. pos += url_len;
  441. if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0) < 0) {
  442. wpa_printf(MSG_DEBUG, "Failed to send BSS Transition "
  443. "Management Request frame");
  444. return -1;
  445. }
  446. if (disassoc_timer) {
  447. /* send disassociation frame after time-out */
  448. set_disassoc_timer(hapd, sta, disassoc_timer);
  449. }
  450. return 0;
  451. }
  452. int wnm_send_bss_tm_req(struct hostapd_data *hapd, struct sta_info *sta,
  453. u8 req_mode, int disassoc_timer, u8 valid_int,
  454. const u8 *bss_term_dur, const char *url,
  455. const u8 *nei_rep, size_t nei_rep_len)
  456. {
  457. u8 *buf, *pos;
  458. struct ieee80211_mgmt *mgmt;
  459. size_t url_len;
  460. wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request to "
  461. MACSTR " req_mode=0x%x disassoc_timer=%d valid_int=0x%x",
  462. MAC2STR(sta->addr), req_mode, disassoc_timer, valid_int);
  463. buf = os_zalloc(1000 + nei_rep_len);
  464. if (buf == NULL)
  465. return -1;
  466. mgmt = (struct ieee80211_mgmt *) buf;
  467. mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  468. WLAN_FC_STYPE_ACTION);
  469. os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
  470. os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
  471. os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
  472. mgmt->u.action.category = WLAN_ACTION_WNM;
  473. mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
  474. mgmt->u.action.u.bss_tm_req.dialog_token = 1;
  475. mgmt->u.action.u.bss_tm_req.req_mode = req_mode;
  476. mgmt->u.action.u.bss_tm_req.disassoc_timer =
  477. host_to_le16(disassoc_timer);
  478. mgmt->u.action.u.bss_tm_req.validity_interval = valid_int;
  479. pos = mgmt->u.action.u.bss_tm_req.variable;
  480. if ((req_mode & WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED) &&
  481. bss_term_dur) {
  482. os_memcpy(pos, bss_term_dur, 12);
  483. pos += 12;
  484. }
  485. if (url) {
  486. /* Session Information URL */
  487. url_len = os_strlen(url);
  488. if (url_len > 255) {
  489. os_free(buf);
  490. return -1;
  491. }
  492. *pos++ = url_len;
  493. os_memcpy(pos, url, url_len);
  494. pos += url_len;
  495. }
  496. if (nei_rep) {
  497. os_memcpy(pos, nei_rep, nei_rep_len);
  498. pos += nei_rep_len;
  499. }
  500. if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0) < 0) {
  501. wpa_printf(MSG_DEBUG,
  502. "Failed to send BSS Transition Management Request frame");
  503. os_free(buf);
  504. return -1;
  505. }
  506. os_free(buf);
  507. if (disassoc_timer) {
  508. /* send disassociation frame after time-out */
  509. set_disassoc_timer(hapd, sta, disassoc_timer);
  510. }
  511. return 0;
  512. }