blob: adb66c1a6ca7c91e6250dbea05eaae0d461b9df9 [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 Shmidtebd93af2017-02-21 13:40:44 -080098 res = -1;
99 goto fail;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700100 }
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);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800121 if (res < 0)
122 goto fail;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700123 igtk_elem_len = res;
124 pos += igtk_elem_len;
125 wpa_printf(MSG_DEBUG, "Pass 4 igtk_len = %d",
126 (int) igtk_elem_len);
127#endif /* CONFIG_IEEE80211W */
128
129 WPA_PUT_LE16((u8 *)
130 &mgmt->u.action.u.wnm_sleep_resp.keydata_len,
131 gtk_elem_len + igtk_elem_len);
132 }
133 os_memcpy(pos, &wnmsleep_ie, wnmsleep_ie_len);
134 /* copy TFS IE here */
135 pos += wnmsleep_ie_len;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800136 if (wnmtfs_ie)
137 os_memcpy(pos, wnmtfs_ie, wnmtfs_ie_len);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700138
139 len = 1 + sizeof(mgmt->u.action.u.wnm_sleep_resp) + gtk_elem_len +
140 igtk_elem_len + wnmsleep_ie_len + wnmtfs_ie_len;
141
142 /* In driver, response frame should be forced to sent when STA is in
143 * PS mode */
144 res = hostapd_drv_send_action(hapd, hapd->iface->freq, 0,
145 mgmt->da, &mgmt->u.action.category, len);
146
147 if (!res) {
148 wpa_printf(MSG_DEBUG, "Successfully send WNM-Sleep Response "
149 "frame");
150
151 /* when entering wnmsleep
152 * 1. pause the node in driver
153 * 2. mark the node so that AP won't update GTK/IGTK during
154 * WNM Sleep
155 */
156 if (wnmsleep_ie.status == WNM_STATUS_SLEEP_ACCEPT &&
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800157 wnmsleep_ie.action_type == WNM_SLEEP_MODE_ENTER) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800158 sta->flags |= WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700159 hostapd_drv_wnm_oper(hapd, WNM_SLEEP_ENTER_CONFIRM,
160 addr, NULL, NULL);
161 wpa_set_wnmsleep(sta->wpa_sm, 1);
162 }
163 /* when exiting wnmsleep
164 * 1. unmark the node
165 * 2. start GTK/IGTK update if MFP is not used
166 * 3. unpause the node in driver
167 */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800168 if ((wnmsleep_ie.status == WNM_STATUS_SLEEP_ACCEPT ||
169 wnmsleep_ie.status ==
170 WNM_STATUS_SLEEP_EXIT_ACCEPT_GTK_UPDATE) &&
171 wnmsleep_ie.action_type == WNM_SLEEP_MODE_EXIT) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800172 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700173 wpa_set_wnmsleep(sta->wpa_sm, 0);
174 hostapd_drv_wnm_oper(hapd, WNM_SLEEP_EXIT_CONFIRM,
175 addr, NULL, NULL);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800176 if (!wpa_auth_uses_mfp(sta->wpa_sm))
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700177 wpa_wnmsleep_rekey_gtk(sta->wpa_sm);
178 }
179 } else
180 wpa_printf(MSG_DEBUG, "Fail to send WNM-Sleep Response frame");
181
182#undef MAX_GTK_SUBELEM_LEN
183#undef MAX_IGTK_SUBELEM_LEN
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800184fail:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700185 os_free(wnmtfs_ie);
186 os_free(mgmt);
187 return res;
188}
189
190
191static void ieee802_11_rx_wnmsleep_req(struct hostapd_data *hapd,
192 const u8 *addr, const u8 *frm, int len)
193{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800194 /* Dialog Token [1] | WNM-Sleep Mode IE | TFS Response IE */
195 const u8 *pos = frm;
196 u8 dialog_token;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700197 struct wnm_sleep_element *wnmsleep_ie = NULL;
198 /* multiple TFS Req IE (assuming consecutive) */
199 u8 *tfsreq_ie_start = NULL;
200 u8 *tfsreq_ie_end = NULL;
201 u16 tfsreq_ie_len = 0;
202
Jouni Malinen7a543742018-10-29 20:48:07 +0200203 if (len < 1) {
204 wpa_printf(MSG_DEBUG,
205 "WNM: Ignore too short WNM-Sleep Mode Request from "
206 MACSTR, MAC2STR(addr));
207 return;
208 }
209
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800210 dialog_token = *pos++;
211 while (pos + 1 < frm + len) {
212 u8 ie_len = pos[1];
213 if (pos + 2 + ie_len > frm + len)
214 break;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800215 if (*pos == WLAN_EID_WNMSLEEP &&
216 ie_len >= (int) sizeof(*wnmsleep_ie) - 2)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800217 wnmsleep_ie = (struct wnm_sleep_element *) pos;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700218 else if (*pos == WLAN_EID_TFS_REQ) {
219 if (!tfsreq_ie_start)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800220 tfsreq_ie_start = (u8 *) pos;
221 tfsreq_ie_end = (u8 *) pos;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700222 } else
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800223 wpa_printf(MSG_DEBUG, "WNM: EID %d not recognized",
224 *pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700225 pos += ie_len + 2;
226 }
227
228 if (!wnmsleep_ie) {
229 wpa_printf(MSG_DEBUG, "No WNM-Sleep IE found");
230 return;
231 }
232
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800233 if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_ENTER &&
234 tfsreq_ie_start && tfsreq_ie_end &&
235 tfsreq_ie_end - tfsreq_ie_start >= 0) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700236 tfsreq_ie_len = (tfsreq_ie_end + tfsreq_ie_end[1] + 2) -
237 tfsreq_ie_start;
238 wpa_printf(MSG_DEBUG, "TFS Req IE(s) found");
239 /* pass the TFS Req IE(s) to driver for processing */
240 if (ieee80211_11_set_tfs_ie(hapd, addr, tfsreq_ie_start,
241 &tfsreq_ie_len,
242 WNM_SLEEP_TFS_REQ_IE_SET))
243 wpa_printf(MSG_DEBUG, "Fail to set TFS Req IE");
244 }
245
246 ieee802_11_send_wnmsleep_resp(hapd, addr, dialog_token,
247 wnmsleep_ie->action_type,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800248 le_to_host16(wnmsleep_ie->intval));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700249
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800250 if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_EXIT) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700251 /* clear the tfs after sending the resp frame */
252 ieee80211_11_set_tfs_ie(hapd, addr, tfsreq_ie_start,
253 &tfsreq_ie_len, WNM_SLEEP_TFS_IE_DEL);
254 }
255}
256
257
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800258static int ieee802_11_send_bss_trans_mgmt_request(struct hostapd_data *hapd,
259 const u8 *addr,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800260 u8 dialog_token)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700261{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800262 struct ieee80211_mgmt *mgmt;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800263 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800264 u8 *pos;
265 int res;
266
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800267 mgmt = os_zalloc(sizeof(*mgmt));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800268 if (mgmt == NULL)
269 return -1;
270 os_memcpy(mgmt->da, addr, ETH_ALEN);
271 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
272 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
273 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
274 WLAN_FC_STYPE_ACTION);
275 mgmt->u.action.category = WLAN_ACTION_WNM;
276 mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
277 mgmt->u.action.u.bss_tm_req.dialog_token = dialog_token;
278 mgmt->u.action.u.bss_tm_req.req_mode = 0;
279 mgmt->u.action.u.bss_tm_req.disassoc_timer = host_to_le16(0);
280 mgmt->u.action.u.bss_tm_req.validity_interval = 1;
281 pos = mgmt->u.action.u.bss_tm_req.variable;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800282
283 wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request to "
284 MACSTR " dialog_token=%u req_mode=0x%x disassoc_timer=%u "
285 "validity_interval=%u",
286 MAC2STR(addr), dialog_token,
287 mgmt->u.action.u.bss_tm_req.req_mode,
288 le_to_host16(mgmt->u.action.u.bss_tm_req.disassoc_timer),
289 mgmt->u.action.u.bss_tm_req.validity_interval);
290
291 len = pos - &mgmt->u.action.category;
292 res = hostapd_drv_send_action(hapd, hapd->iface->freq, 0,
293 mgmt->da, &mgmt->u.action.category, len);
294 os_free(mgmt);
295 return res;
296}
297
298
299static void ieee802_11_rx_bss_trans_mgmt_query(struct hostapd_data *hapd,
300 const u8 *addr, const u8 *frm,
301 size_t len)
302{
303 u8 dialog_token, reason;
304 const u8 *pos, *end;
305
306 if (len < 2) {
307 wpa_printf(MSG_DEBUG, "WNM: Ignore too short BSS Transition Management Query from "
308 MACSTR, MAC2STR(addr));
309 return;
310 }
311
312 pos = frm;
313 end = pos + len;
314 dialog_token = *pos++;
315 reason = *pos++;
316
317 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management Query from "
318 MACSTR " dialog_token=%u reason=%u",
319 MAC2STR(addr), dialog_token, reason);
320
321 wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries",
322 pos, end - pos);
323
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800324 ieee802_11_send_bss_trans_mgmt_request(hapd, addr, dialog_token);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800325}
326
327
328static void ieee802_11_rx_bss_trans_mgmt_resp(struct hostapd_data *hapd,
329 const u8 *addr, const u8 *frm,
330 size_t len)
331{
332 u8 dialog_token, status_code, bss_termination_delay;
333 const u8 *pos, *end;
334
335 if (len < 3) {
336 wpa_printf(MSG_DEBUG, "WNM: Ignore too short BSS Transition Management Response from "
337 MACSTR, MAC2STR(addr));
338 return;
339 }
340
341 pos = frm;
342 end = pos + len;
343 dialog_token = *pos++;
344 status_code = *pos++;
345 bss_termination_delay = *pos++;
346
347 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management Response from "
348 MACSTR " dialog_token=%u status_code=%u "
349 "bss_termination_delay=%u", MAC2STR(addr), dialog_token,
350 status_code, bss_termination_delay);
351
352 if (status_code == WNM_BSS_TM_ACCEPT) {
353 if (end - pos < ETH_ALEN) {
354 wpa_printf(MSG_DEBUG, "WNM: not enough room for Target BSSID field");
355 return;
356 }
357 wpa_printf(MSG_DEBUG, "WNM: Target BSSID: " MACSTR,
358 MAC2STR(pos));
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800359 wpa_msg(hapd->msg_ctx, MSG_INFO, BSS_TM_RESP MACSTR
360 " status_code=%u bss_termination_delay=%u target_bssid="
361 MACSTR,
362 MAC2STR(addr), status_code, bss_termination_delay,
363 MAC2STR(pos));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800364 pos += ETH_ALEN;
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800365 } else {
366 wpa_msg(hapd->msg_ctx, MSG_INFO, BSS_TM_RESP MACSTR
367 " status_code=%u bss_termination_delay=%u",
368 MAC2STR(addr), status_code, bss_termination_delay);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800369 }
370
371 wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries",
372 pos, end - pos);
373}
374
375
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800376static void ieee802_11_rx_wnm_notification_req(struct hostapd_data *hapd,
377 const u8 *addr, const u8 *buf,
378 size_t len)
379{
380 u8 dialog_token, type;
381
382 if (len < 2)
383 return;
384 dialog_token = *buf++;
385 type = *buf++;
386 len -= 2;
387
388 wpa_printf(MSG_DEBUG,
389 "WNM: Received WNM Notification Request frame from "
390 MACSTR " (dialog_token=%u type=%u)",
391 MAC2STR(addr), dialog_token, type);
392 wpa_hexdump(MSG_MSGDUMP, "WNM: Notification Request subelements",
393 buf, len);
394 if (type == WLAN_EID_VENDOR_SPECIFIC)
395 mbo_ap_wnm_notification_req(hapd, addr, buf, len);
396}
397
398
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800399int ieee802_11_rx_wnm_action_ap(struct hostapd_data *hapd,
400 const struct ieee80211_mgmt *mgmt, size_t len)
401{
402 u8 action;
403 const u8 *payload;
404 size_t plen;
405
406 if (len < IEEE80211_HDRLEN + 2)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800407 return -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700408
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700409 payload = ((const u8 *) mgmt) + IEEE80211_HDRLEN + 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800410 action = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700411 plen = len - IEEE80211_HDRLEN - 2;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800412
413 switch (action) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800414 case WNM_BSS_TRANS_MGMT_QUERY:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800415 ieee802_11_rx_bss_trans_mgmt_query(hapd, mgmt->sa, payload,
416 plen);
417 return 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800418 case WNM_BSS_TRANS_MGMT_RESP:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800419 ieee802_11_rx_bss_trans_mgmt_resp(hapd, mgmt->sa, payload,
420 plen);
421 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700422 case WNM_SLEEP_MODE_REQ:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800423 ieee802_11_rx_wnmsleep_req(hapd, mgmt->sa, payload, plen);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800424 return 0;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800425 case WNM_NOTIFICATION_REQ:
426 ieee802_11_rx_wnm_notification_req(hapd, mgmt->sa, payload,
427 plen);
428 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700429 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700430
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800431 wpa_printf(MSG_DEBUG, "WNM: Unsupported WNM Action %u from " MACSTR,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800432 action, MAC2STR(mgmt->sa));
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800433 return -1;
434}
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800435
436
437int wnm_send_disassoc_imminent(struct hostapd_data *hapd,
438 struct sta_info *sta, int disassoc_timer)
439{
440 u8 buf[1000], *pos;
441 struct ieee80211_mgmt *mgmt;
442
443 os_memset(buf, 0, sizeof(buf));
444 mgmt = (struct ieee80211_mgmt *) buf;
445 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
446 WLAN_FC_STYPE_ACTION);
447 os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
448 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
449 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
450 mgmt->u.action.category = WLAN_ACTION_WNM;
451 mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
452 mgmt->u.action.u.bss_tm_req.dialog_token = 1;
453 mgmt->u.action.u.bss_tm_req.req_mode =
454 WNM_BSS_TM_REQ_DISASSOC_IMMINENT;
455 mgmt->u.action.u.bss_tm_req.disassoc_timer =
456 host_to_le16(disassoc_timer);
457 mgmt->u.action.u.bss_tm_req.validity_interval = 0;
458
459 pos = mgmt->u.action.u.bss_tm_req.variable;
460
461 wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request frame to indicate imminent disassociation (disassoc_timer=%d) to "
462 MACSTR, disassoc_timer, MAC2STR(sta->addr));
463 if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0) < 0) {
464 wpa_printf(MSG_DEBUG, "Failed to send BSS Transition "
465 "Management Request frame");
466 return -1;
467 }
468
469 return 0;
470}
471
472
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800473static void set_disassoc_timer(struct hostapd_data *hapd, struct sta_info *sta,
474 int disassoc_timer)
475{
476 int timeout, beacon_int;
477
478 /*
479 * Prevent STA from reconnecting using cached PMKSA to force
480 * full authentication with the authentication server (which may
481 * decide to reject the connection),
482 */
483 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
484
485 beacon_int = hapd->iconf->beacon_int;
486 if (beacon_int < 1)
487 beacon_int = 100; /* best guess */
488 /* Calculate timeout in ms based on beacon_int in TU */
489 timeout = disassoc_timer * beacon_int * 128 / 125;
490 wpa_printf(MSG_DEBUG, "Disassociation timer for " MACSTR
491 " set to %d ms", MAC2STR(sta->addr), timeout);
492
493 sta->timeout_next = STA_DISASSOC_FROM_CLI;
494 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
495 eloop_register_timeout(timeout / 1000,
496 timeout % 1000 * 1000,
497 ap_handle_timer, hapd, sta);
498}
499
500
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800501int wnm_send_ess_disassoc_imminent(struct hostapd_data *hapd,
502 struct sta_info *sta, const char *url,
503 int disassoc_timer)
504{
505 u8 buf[1000], *pos;
506 struct ieee80211_mgmt *mgmt;
507 size_t url_len;
508
509 os_memset(buf, 0, sizeof(buf));
510 mgmt = (struct ieee80211_mgmt *) buf;
511 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
512 WLAN_FC_STYPE_ACTION);
513 os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
514 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
515 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
516 mgmt->u.action.category = WLAN_ACTION_WNM;
517 mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
518 mgmt->u.action.u.bss_tm_req.dialog_token = 1;
519 mgmt->u.action.u.bss_tm_req.req_mode =
520 WNM_BSS_TM_REQ_DISASSOC_IMMINENT |
521 WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT;
522 mgmt->u.action.u.bss_tm_req.disassoc_timer =
523 host_to_le16(disassoc_timer);
524 mgmt->u.action.u.bss_tm_req.validity_interval = 0x01;
525
526 pos = mgmt->u.action.u.bss_tm_req.variable;
527
528 /* Session Information URL */
529 url_len = os_strlen(url);
530 if (url_len > 255)
531 return -1;
532 *pos++ = url_len;
533 os_memcpy(pos, url, url_len);
534 pos += url_len;
535
536 if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0) < 0) {
537 wpa_printf(MSG_DEBUG, "Failed to send BSS Transition "
538 "Management Request frame");
539 return -1;
540 }
541
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800542 if (disassoc_timer) {
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800543 /* send disassociation frame after time-out */
544 set_disassoc_timer(hapd, sta, disassoc_timer);
545 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800546
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800547 return 0;
548}
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800549
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800550
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800551int wnm_send_bss_tm_req(struct hostapd_data *hapd, struct sta_info *sta,
552 u8 req_mode, int disassoc_timer, u8 valid_int,
553 const u8 *bss_term_dur, const char *url,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800554 const u8 *nei_rep, size_t nei_rep_len,
555 const u8 *mbo_attrs, size_t mbo_len)
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800556{
557 u8 *buf, *pos;
558 struct ieee80211_mgmt *mgmt;
559 size_t url_len;
560
561 wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request to "
562 MACSTR " req_mode=0x%x disassoc_timer=%d valid_int=0x%x",
563 MAC2STR(sta->addr), req_mode, disassoc_timer, valid_int);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800564 buf = os_zalloc(1000 + nei_rep_len + mbo_len);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800565 if (buf == NULL)
566 return -1;
567 mgmt = (struct ieee80211_mgmt *) buf;
568 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
569 WLAN_FC_STYPE_ACTION);
570 os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
571 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
572 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
573 mgmt->u.action.category = WLAN_ACTION_WNM;
574 mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
575 mgmt->u.action.u.bss_tm_req.dialog_token = 1;
576 mgmt->u.action.u.bss_tm_req.req_mode = req_mode;
577 mgmt->u.action.u.bss_tm_req.disassoc_timer =
578 host_to_le16(disassoc_timer);
579 mgmt->u.action.u.bss_tm_req.validity_interval = valid_int;
580
581 pos = mgmt->u.action.u.bss_tm_req.variable;
582
583 if ((req_mode & WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED) &&
584 bss_term_dur) {
585 os_memcpy(pos, bss_term_dur, 12);
586 pos += 12;
587 }
588
589 if (url) {
590 /* Session Information URL */
591 url_len = os_strlen(url);
Dmitry Shmidt432d6032015-01-21 13:19:05 -0800592 if (url_len > 255) {
593 os_free(buf);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800594 return -1;
Dmitry Shmidt432d6032015-01-21 13:19:05 -0800595 }
596
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800597 *pos++ = url_len;
598 os_memcpy(pos, url, url_len);
599 pos += url_len;
600 }
601
602 if (nei_rep) {
603 os_memcpy(pos, nei_rep, nei_rep_len);
604 pos += nei_rep_len;
605 }
606
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800607 if (mbo_len > 0) {
608 pos += mbo_add_ie(pos, buf + sizeof(buf) - pos, mbo_attrs,
609 mbo_len);
610 }
611
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800612 if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0) < 0) {
613 wpa_printf(MSG_DEBUG,
614 "Failed to send BSS Transition Management Request frame");
615 os_free(buf);
616 return -1;
617 }
618 os_free(buf);
619
620 if (disassoc_timer) {
621 /* send disassociation frame after time-out */
622 set_disassoc_timer(hapd, sta, disassoc_timer);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800623 }
624
625 return 0;
626}