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