blob: 02daa9bc653e376b7b70d04122544682fad402c2 [file] [log] [blame]
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001/*
2 * hostapd - WNM
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -08003 * Copyright (c) 2011-2014, Qualcomm Atheros, Inc.
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004 *
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"
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080012#include "utils/eloop.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070013#include "common/ieee802_11_defs.h"
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -080014#include "common/wpa_ctrl.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070015#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"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080020#include "mbo_ap.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070021#include "wnm_ap.h"
22
23#define MAX_TFS_IE_LEN 1024
24
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070025
26/* get the TFS IE from driver */
27static 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 wpa_printf(MSG_DEBUG, "%s: TFS get operation %d", __func__, oper);
31
32 return hostapd_drv_wnm_oper(hapd, oper, addr, buf, buf_len);
33}
34
35
36/* set the TFS IE to driver */
37static 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 wpa_printf(MSG_DEBUG, "%s: TFS set operation %d", __func__, oper);
41
42 return hostapd_drv_wnm_oper(hapd, oper, addr, buf, buf_len);
43}
44
45
46/* MLME-SLEEPMODE.response */
47static 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 size_t gtk_elem_len = 0;
55 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;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080062 enum wnm_oper tfs_oper = action_type == WNM_SLEEP_MODE_ENTER ?
63 WNM_SLEEP_TFS_RESP_IE_ADD : WNM_SLEEP_TFS_RESP_IE_NONE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070064
65 sta = ap_get_sta(hapd, addr);
66 if (sta == NULL) {
67 wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
68 return -EINVAL;
69 }
70
71 /* WNM-Sleep Mode IE */
72 os_memset(&wnmsleep_ie, 0, sizeof(struct wnm_sleep_element));
73 wnmsleep_ie_len = sizeof(struct wnm_sleep_element);
74 wnmsleep_ie.eid = WLAN_EID_WNMSLEEP;
75 wnmsleep_ie.len = wnmsleep_ie_len - 2;
76 wnmsleep_ie.action_type = action_type;
77 wnmsleep_ie.status = WNM_STATUS_SLEEP_ACCEPT;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080078 wnmsleep_ie.intval = host_to_le16(intval);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070079
80 /* TFS IE(s) */
81 wnmtfs_ie = os_zalloc(MAX_TFS_IE_LEN);
82 if (wnmtfs_ie == NULL)
83 return -1;
84 if (ieee80211_11_get_tfs_ie(hapd, addr, wnmtfs_ie, &wnmtfs_ie_len,
85 tfs_oper)) {
86 wnmtfs_ie_len = 0;
87 os_free(wnmtfs_ie);
88 wnmtfs_ie = NULL;
89 }
90
91#define MAX_GTK_SUBELEM_LEN 45
92#define MAX_IGTK_SUBELEM_LEN 26
93 mgmt = os_zalloc(sizeof(*mgmt) + wnmsleep_ie_len +
94 MAX_GTK_SUBELEM_LEN + MAX_IGTK_SUBELEM_LEN);
95 if (mgmt == NULL) {
96 wpa_printf(MSG_DEBUG, "MLME: Failed to allocate buffer for "
97 "WNM-Sleep Response action frame");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080098 os_free(wnmtfs_ie);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070099 return -1;
100 }
101 os_memcpy(mgmt->da, addr, ETH_ALEN);
102 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
103 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
104 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
105 WLAN_FC_STYPE_ACTION);
106 mgmt->u.action.category = WLAN_ACTION_WNM;
107 mgmt->u.action.u.wnm_sleep_resp.action = WNM_SLEEP_MODE_RESP;
108 mgmt->u.action.u.wnm_sleep_resp.dialogtoken = dialog_token;
109 pos = (u8 *)mgmt->u.action.u.wnm_sleep_resp.variable;
110 /* add key data if MFP is enabled */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800111 if (!wpa_auth_uses_mfp(sta->wpa_sm) ||
112 action_type != WNM_SLEEP_MODE_EXIT) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700113 mgmt->u.action.u.wnm_sleep_resp.keydata_len = 0;
114 } else {
115 gtk_elem_len = wpa_wnmsleep_gtk_subelem(sta->wpa_sm, pos);
116 pos += gtk_elem_len;
117 wpa_printf(MSG_DEBUG, "Pass 4, gtk_len = %d",
118 (int) gtk_elem_len);
119#ifdef CONFIG_IEEE80211W
120 res = wpa_wnmsleep_igtk_subelem(sta->wpa_sm, pos);
121 if (res < 0) {
122 os_free(wnmtfs_ie);
123 os_free(mgmt);
124 return -1;
125 }
126 igtk_elem_len = res;
127 pos += igtk_elem_len;
128 wpa_printf(MSG_DEBUG, "Pass 4 igtk_len = %d",
129 (int) igtk_elem_len);
130#endif /* CONFIG_IEEE80211W */
131
132 WPA_PUT_LE16((u8 *)
133 &mgmt->u.action.u.wnm_sleep_resp.keydata_len,
134 gtk_elem_len + igtk_elem_len);
135 }
136 os_memcpy(pos, &wnmsleep_ie, wnmsleep_ie_len);
137 /* copy TFS IE here */
138 pos += wnmsleep_ie_len;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800139 if (wnmtfs_ie)
140 os_memcpy(pos, wnmtfs_ie, wnmtfs_ie_len);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700141
142 len = 1 + sizeof(mgmt->u.action.u.wnm_sleep_resp) + gtk_elem_len +
143 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 res = hostapd_drv_send_action(hapd, hapd->iface->freq, 0,
148 mgmt->da, &mgmt->u.action.category, len);
149
150 if (!res) {
151 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 if (wnmsleep_ie.status == WNM_STATUS_SLEEP_ACCEPT &&
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800160 wnmsleep_ie.action_type == WNM_SLEEP_MODE_ENTER) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800161 sta->flags |= WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700162 hostapd_drv_wnm_oper(hapd, WNM_SLEEP_ENTER_CONFIRM,
163 addr, NULL, NULL);
164 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 */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800171 if ((wnmsleep_ie.status == WNM_STATUS_SLEEP_ACCEPT ||
172 wnmsleep_ie.status ==
173 WNM_STATUS_SLEEP_EXIT_ACCEPT_GTK_UPDATE) &&
174 wnmsleep_ie.action_type == WNM_SLEEP_MODE_EXIT) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800175 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700176 wpa_set_wnmsleep(sta->wpa_sm, 0);
177 hostapd_drv_wnm_oper(hapd, WNM_SLEEP_EXIT_CONFIRM,
178 addr, NULL, NULL);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800179 if (!wpa_auth_uses_mfp(sta->wpa_sm))
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700180 wpa_wnmsleep_rekey_gtk(sta->wpa_sm);
181 }
182 } else
183 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 os_free(wnmtfs_ie);
188 os_free(mgmt);
189 return res;
190}
191
192
193static void ieee802_11_rx_wnmsleep_req(struct hostapd_data *hapd,
194 const u8 *addr, const u8 *frm, int len)
195{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800196 /* Dialog Token [1] | WNM-Sleep Mode IE | TFS Response IE */
197 const u8 *pos = frm;
198 u8 dialog_token;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700199 struct wnm_sleep_element *wnmsleep_ie = NULL;
200 /* multiple TFS Req IE (assuming consecutive) */
201 u8 *tfsreq_ie_start = NULL;
202 u8 *tfsreq_ie_end = NULL;
203 u16 tfsreq_ie_len = 0;
204
Jouni Malinen7a543742018-10-29 20:48:07 +0200205 if (len < 1) {
206 wpa_printf(MSG_DEBUG,
207 "WNM: Ignore too short WNM-Sleep Mode Request from "
208 MACSTR, MAC2STR(addr));
209 return;
210 }
211
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800212 dialog_token = *pos++;
213 while (pos + 1 < frm + len) {
214 u8 ie_len = pos[1];
215 if (pos + 2 + ie_len > frm + len)
216 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700217 if (*pos == WLAN_EID_WNMSLEEP)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800218 wnmsleep_ie = (struct wnm_sleep_element *) pos;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700219 else if (*pos == WLAN_EID_TFS_REQ) {
220 if (!tfsreq_ie_start)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800221 tfsreq_ie_start = (u8 *) pos;
222 tfsreq_ie_end = (u8 *) pos;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700223 } else
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800224 wpa_printf(MSG_DEBUG, "WNM: EID %d not recognized",
225 *pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700226 pos += ie_len + 2;
227 }
228
229 if (!wnmsleep_ie) {
230 wpa_printf(MSG_DEBUG, "No WNM-Sleep IE found");
231 return;
232 }
233
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800234 if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_ENTER &&
235 tfsreq_ie_start && tfsreq_ie_end &&
236 tfsreq_ie_end - tfsreq_ie_start >= 0) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700237 tfsreq_ie_len = (tfsreq_ie_end + tfsreq_ie_end[1] + 2) -
238 tfsreq_ie_start;
239 wpa_printf(MSG_DEBUG, "TFS Req IE(s) found");
240 /* pass the TFS Req IE(s) to driver for processing */
241 if (ieee80211_11_set_tfs_ie(hapd, addr, tfsreq_ie_start,
242 &tfsreq_ie_len,
243 WNM_SLEEP_TFS_REQ_IE_SET))
244 wpa_printf(MSG_DEBUG, "Fail to set TFS Req IE");
245 }
246
247 ieee802_11_send_wnmsleep_resp(hapd, addr, dialog_token,
248 wnmsleep_ie->action_type,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800249 le_to_host16(wnmsleep_ie->intval));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700250
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800251 if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_EXIT) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700252 /* clear the tfs after sending the resp frame */
253 ieee80211_11_set_tfs_ie(hapd, addr, tfsreq_ie_start,
254 &tfsreq_ie_len, WNM_SLEEP_TFS_IE_DEL);
255 }
256}
257
258
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800259static int ieee802_11_send_bss_trans_mgmt_request(struct hostapd_data *hapd,
260 const u8 *addr,
261 u8 dialog_token,
262 const char *url)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700263{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800264 struct ieee80211_mgmt *mgmt;
265 size_t url_len, len;
266 u8 *pos;
267 int res;
268
269 if (url)
270 url_len = os_strlen(url);
271 else
272 url_len = 0;
273
274 mgmt = os_zalloc(sizeof(*mgmt) + (url_len ? 1 + url_len : 0));
275 if (mgmt == NULL)
276 return -1;
277 os_memcpy(mgmt->da, addr, ETH_ALEN);
278 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
279 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
280 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
281 WLAN_FC_STYPE_ACTION);
282 mgmt->u.action.category = WLAN_ACTION_WNM;
283 mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
284 mgmt->u.action.u.bss_tm_req.dialog_token = dialog_token;
285 mgmt->u.action.u.bss_tm_req.req_mode = 0;
286 mgmt->u.action.u.bss_tm_req.disassoc_timer = host_to_le16(0);
287 mgmt->u.action.u.bss_tm_req.validity_interval = 1;
288 pos = mgmt->u.action.u.bss_tm_req.variable;
289 if (url) {
290 *pos++ += url_len;
291 os_memcpy(pos, url, url_len);
292 pos += url_len;
293 }
294
295 wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request to "
296 MACSTR " dialog_token=%u req_mode=0x%x disassoc_timer=%u "
297 "validity_interval=%u",
298 MAC2STR(addr), dialog_token,
299 mgmt->u.action.u.bss_tm_req.req_mode,
300 le_to_host16(mgmt->u.action.u.bss_tm_req.disassoc_timer),
301 mgmt->u.action.u.bss_tm_req.validity_interval);
302
303 len = pos - &mgmt->u.action.category;
304 res = hostapd_drv_send_action(hapd, hapd->iface->freq, 0,
305 mgmt->da, &mgmt->u.action.category, len);
306 os_free(mgmt);
307 return res;
308}
309
310
311static void ieee802_11_rx_bss_trans_mgmt_query(struct hostapd_data *hapd,
312 const u8 *addr, const u8 *frm,
313 size_t len)
314{
315 u8 dialog_token, reason;
316 const u8 *pos, *end;
317
318 if (len < 2) {
319 wpa_printf(MSG_DEBUG, "WNM: Ignore too short BSS Transition Management Query from "
320 MACSTR, MAC2STR(addr));
321 return;
322 }
323
324 pos = frm;
325 end = pos + len;
326 dialog_token = *pos++;
327 reason = *pos++;
328
329 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management Query from "
330 MACSTR " dialog_token=%u reason=%u",
331 MAC2STR(addr), dialog_token, reason);
332
333 wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries",
334 pos, end - pos);
335
336 ieee802_11_send_bss_trans_mgmt_request(hapd, addr, dialog_token, NULL);
337}
338
339
340static void ieee802_11_rx_bss_trans_mgmt_resp(struct hostapd_data *hapd,
341 const u8 *addr, const u8 *frm,
342 size_t len)
343{
344 u8 dialog_token, status_code, bss_termination_delay;
345 const u8 *pos, *end;
346
347 if (len < 3) {
348 wpa_printf(MSG_DEBUG, "WNM: Ignore too short BSS Transition Management Response from "
349 MACSTR, MAC2STR(addr));
350 return;
351 }
352
353 pos = frm;
354 end = pos + len;
355 dialog_token = *pos++;
356 status_code = *pos++;
357 bss_termination_delay = *pos++;
358
359 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management Response from "
360 MACSTR " dialog_token=%u status_code=%u "
361 "bss_termination_delay=%u", MAC2STR(addr), dialog_token,
362 status_code, bss_termination_delay);
363
364 if (status_code == WNM_BSS_TM_ACCEPT) {
365 if (end - pos < ETH_ALEN) {
366 wpa_printf(MSG_DEBUG, "WNM: not enough room for Target BSSID field");
367 return;
368 }
369 wpa_printf(MSG_DEBUG, "WNM: Target BSSID: " MACSTR,
370 MAC2STR(pos));
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800371 wpa_msg(hapd->msg_ctx, MSG_INFO, BSS_TM_RESP MACSTR
372 " status_code=%u bss_termination_delay=%u target_bssid="
373 MACSTR,
374 MAC2STR(addr), status_code, bss_termination_delay,
375 MAC2STR(pos));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800376 pos += ETH_ALEN;
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800377 } else {
378 wpa_msg(hapd->msg_ctx, MSG_INFO, BSS_TM_RESP MACSTR
379 " status_code=%u bss_termination_delay=%u",
380 MAC2STR(addr), status_code, bss_termination_delay);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800381 }
382
383 wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries",
384 pos, end - pos);
385}
386
387
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800388static void ieee802_11_rx_wnm_notification_req(struct hostapd_data *hapd,
389 const u8 *addr, const u8 *buf,
390 size_t len)
391{
392 u8 dialog_token, type;
393
394 if (len < 2)
395 return;
396 dialog_token = *buf++;
397 type = *buf++;
398 len -= 2;
399
400 wpa_printf(MSG_DEBUG,
401 "WNM: Received WNM Notification Request frame from "
402 MACSTR " (dialog_token=%u type=%u)",
403 MAC2STR(addr), dialog_token, type);
404 wpa_hexdump(MSG_MSGDUMP, "WNM: Notification Request subelements",
405 buf, len);
406 if (type == WLAN_EID_VENDOR_SPECIFIC)
407 mbo_ap_wnm_notification_req(hapd, addr, buf, len);
408}
409
410
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800411int ieee802_11_rx_wnm_action_ap(struct hostapd_data *hapd,
412 const struct ieee80211_mgmt *mgmt, size_t len)
413{
414 u8 action;
415 const u8 *payload;
416 size_t plen;
417
418 if (len < IEEE80211_HDRLEN + 2)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800419 return -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700420
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700421 payload = ((const u8 *) mgmt) + IEEE80211_HDRLEN + 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800422 action = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700423 plen = len - IEEE80211_HDRLEN - 2;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800424
425 switch (action) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800426 case WNM_BSS_TRANS_MGMT_QUERY:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800427 ieee802_11_rx_bss_trans_mgmt_query(hapd, mgmt->sa, payload,
428 plen);
429 return 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800430 case WNM_BSS_TRANS_MGMT_RESP:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800431 ieee802_11_rx_bss_trans_mgmt_resp(hapd, mgmt->sa, payload,
432 plen);
433 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700434 case WNM_SLEEP_MODE_REQ:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800435 ieee802_11_rx_wnmsleep_req(hapd, mgmt->sa, payload, plen);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800436 return 0;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800437 case WNM_NOTIFICATION_REQ:
438 ieee802_11_rx_wnm_notification_req(hapd, mgmt->sa, payload,
439 plen);
440 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700441 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700442
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800443 wpa_printf(MSG_DEBUG, "WNM: Unsupported WNM Action %u from " MACSTR,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800444 action, MAC2STR(mgmt->sa));
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800445 return -1;
446}
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800447
448
449int wnm_send_disassoc_imminent(struct hostapd_data *hapd,
450 struct sta_info *sta, int disassoc_timer)
451{
452 u8 buf[1000], *pos;
453 struct ieee80211_mgmt *mgmt;
454
455 os_memset(buf, 0, sizeof(buf));
456 mgmt = (struct ieee80211_mgmt *) buf;
457 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
458 WLAN_FC_STYPE_ACTION);
459 os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
460 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
461 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
462 mgmt->u.action.category = WLAN_ACTION_WNM;
463 mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
464 mgmt->u.action.u.bss_tm_req.dialog_token = 1;
465 mgmt->u.action.u.bss_tm_req.req_mode =
466 WNM_BSS_TM_REQ_DISASSOC_IMMINENT;
467 mgmt->u.action.u.bss_tm_req.disassoc_timer =
468 host_to_le16(disassoc_timer);
469 mgmt->u.action.u.bss_tm_req.validity_interval = 0;
470
471 pos = mgmt->u.action.u.bss_tm_req.variable;
472
473 wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request frame to indicate imminent disassociation (disassoc_timer=%d) to "
474 MACSTR, disassoc_timer, MAC2STR(sta->addr));
475 if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0) < 0) {
476 wpa_printf(MSG_DEBUG, "Failed to send BSS Transition "
477 "Management Request frame");
478 return -1;
479 }
480
481 return 0;
482}
483
484
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800485static void set_disassoc_timer(struct hostapd_data *hapd, struct sta_info *sta,
486 int disassoc_timer)
487{
488 int timeout, beacon_int;
489
490 /*
491 * Prevent STA from reconnecting using cached PMKSA to force
492 * full authentication with the authentication server (which may
493 * decide to reject the connection),
494 */
495 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
496
497 beacon_int = hapd->iconf->beacon_int;
498 if (beacon_int < 1)
499 beacon_int = 100; /* best guess */
500 /* Calculate timeout in ms based on beacon_int in TU */
501 timeout = disassoc_timer * beacon_int * 128 / 125;
502 wpa_printf(MSG_DEBUG, "Disassociation timer for " MACSTR
503 " set to %d ms", MAC2STR(sta->addr), timeout);
504
505 sta->timeout_next = STA_DISASSOC_FROM_CLI;
506 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
507 eloop_register_timeout(timeout / 1000,
508 timeout % 1000 * 1000,
509 ap_handle_timer, hapd, sta);
510}
511
512
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800513int wnm_send_ess_disassoc_imminent(struct hostapd_data *hapd,
514 struct sta_info *sta, const char *url,
515 int disassoc_timer)
516{
517 u8 buf[1000], *pos;
518 struct ieee80211_mgmt *mgmt;
519 size_t url_len;
520
521 os_memset(buf, 0, sizeof(buf));
522 mgmt = (struct ieee80211_mgmt *) buf;
523 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
524 WLAN_FC_STYPE_ACTION);
525 os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
526 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
527 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
528 mgmt->u.action.category = WLAN_ACTION_WNM;
529 mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
530 mgmt->u.action.u.bss_tm_req.dialog_token = 1;
531 mgmt->u.action.u.bss_tm_req.req_mode =
532 WNM_BSS_TM_REQ_DISASSOC_IMMINENT |
533 WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT;
534 mgmt->u.action.u.bss_tm_req.disassoc_timer =
535 host_to_le16(disassoc_timer);
536 mgmt->u.action.u.bss_tm_req.validity_interval = 0x01;
537
538 pos = mgmt->u.action.u.bss_tm_req.variable;
539
540 /* Session Information URL */
541 url_len = os_strlen(url);
542 if (url_len > 255)
543 return -1;
544 *pos++ = url_len;
545 os_memcpy(pos, url, url_len);
546 pos += url_len;
547
548 if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0) < 0) {
549 wpa_printf(MSG_DEBUG, "Failed to send BSS Transition "
550 "Management Request frame");
551 return -1;
552 }
553
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800554 if (disassoc_timer) {
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800555 /* send disassociation frame after time-out */
556 set_disassoc_timer(hapd, sta, disassoc_timer);
557 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800558
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800559 return 0;
560}
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800561
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800562
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800563int wnm_send_bss_tm_req(struct hostapd_data *hapd, struct sta_info *sta,
564 u8 req_mode, int disassoc_timer, u8 valid_int,
565 const u8 *bss_term_dur, const char *url,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800566 const u8 *nei_rep, size_t nei_rep_len,
567 const u8 *mbo_attrs, size_t mbo_len)
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800568{
569 u8 *buf, *pos;
570 struct ieee80211_mgmt *mgmt;
571 size_t url_len;
572
573 wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request to "
574 MACSTR " req_mode=0x%x disassoc_timer=%d valid_int=0x%x",
575 MAC2STR(sta->addr), req_mode, disassoc_timer, valid_int);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800576 buf = os_zalloc(1000 + nei_rep_len + mbo_len);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800577 if (buf == NULL)
578 return -1;
579 mgmt = (struct ieee80211_mgmt *) buf;
580 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
581 WLAN_FC_STYPE_ACTION);
582 os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
583 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
584 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
585 mgmt->u.action.category = WLAN_ACTION_WNM;
586 mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
587 mgmt->u.action.u.bss_tm_req.dialog_token = 1;
588 mgmt->u.action.u.bss_tm_req.req_mode = req_mode;
589 mgmt->u.action.u.bss_tm_req.disassoc_timer =
590 host_to_le16(disassoc_timer);
591 mgmt->u.action.u.bss_tm_req.validity_interval = valid_int;
592
593 pos = mgmt->u.action.u.bss_tm_req.variable;
594
595 if ((req_mode & WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED) &&
596 bss_term_dur) {
597 os_memcpy(pos, bss_term_dur, 12);
598 pos += 12;
599 }
600
601 if (url) {
602 /* Session Information URL */
603 url_len = os_strlen(url);
Dmitry Shmidt432d6032015-01-21 13:19:05 -0800604 if (url_len > 255) {
605 os_free(buf);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800606 return -1;
Dmitry Shmidt432d6032015-01-21 13:19:05 -0800607 }
608
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800609 *pos++ = url_len;
610 os_memcpy(pos, url, url_len);
611 pos += url_len;
612 }
613
614 if (nei_rep) {
615 os_memcpy(pos, nei_rep, nei_rep_len);
616 pos += nei_rep_len;
617 }
618
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800619 if (mbo_len > 0) {
620 pos += mbo_add_ie(pos, buf + sizeof(buf) - pos, mbo_attrs,
621 mbo_len);
622 }
623
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800624 if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0) < 0) {
625 wpa_printf(MSG_DEBUG,
626 "Failed to send BSS Transition Management Request frame");
627 os_free(buf);
628 return -1;
629 }
630 os_free(buf);
631
632 if (disassoc_timer) {
633 /* send disassociation frame after time-out */
634 set_disassoc_timer(hapd, sta, disassoc_timer);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800635 }
636
637 return 0;
638}