blob: 710fe502b0fc41abde222473a3b87d22e2a9a03a [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) ||
Roshan Pius3a1667e2018-07-03 15:17:14 -0700112 hapd->conf->wnm_sleep_mode_no_keys ||
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800113 action_type != WNM_SLEEP_MODE_EXIT) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700114 mgmt->u.action.u.wnm_sleep_resp.keydata_len = 0;
115 } else {
116 gtk_elem_len = wpa_wnmsleep_gtk_subelem(sta->wpa_sm, pos);
117 pos += gtk_elem_len;
118 wpa_printf(MSG_DEBUG, "Pass 4, gtk_len = %d",
119 (int) gtk_elem_len);
120#ifdef CONFIG_IEEE80211W
121 res = wpa_wnmsleep_igtk_subelem(sta->wpa_sm, pos);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800122 if (res < 0)
123 goto fail;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700124 igtk_elem_len = res;
125 pos += igtk_elem_len;
126 wpa_printf(MSG_DEBUG, "Pass 4 igtk_len = %d",
127 (int) igtk_elem_len);
128#endif /* CONFIG_IEEE80211W */
129
130 WPA_PUT_LE16((u8 *)
131 &mgmt->u.action.u.wnm_sleep_resp.keydata_len,
132 gtk_elem_len + igtk_elem_len);
133 }
134 os_memcpy(pos, &wnmsleep_ie, wnmsleep_ie_len);
135 /* copy TFS IE here */
136 pos += wnmsleep_ie_len;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800137 if (wnmtfs_ie)
138 os_memcpy(pos, wnmtfs_ie, wnmtfs_ie_len);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700139
140 len = 1 + sizeof(mgmt->u.action.u.wnm_sleep_resp) + gtk_elem_len +
141 igtk_elem_len + wnmsleep_ie_len + wnmtfs_ie_len;
142
143 /* In driver, response frame should be forced to sent when STA is in
144 * PS mode */
145 res = hostapd_drv_send_action(hapd, hapd->iface->freq, 0,
146 mgmt->da, &mgmt->u.action.category, len);
147
148 if (!res) {
149 wpa_printf(MSG_DEBUG, "Successfully send WNM-Sleep Response "
150 "frame");
151
152 /* when entering wnmsleep
153 * 1. pause the node in driver
154 * 2. mark the node so that AP won't update GTK/IGTK during
155 * WNM Sleep
156 */
157 if (wnmsleep_ie.status == WNM_STATUS_SLEEP_ACCEPT &&
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800158 wnmsleep_ie.action_type == WNM_SLEEP_MODE_ENTER) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800159 sta->flags |= WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700160 hostapd_drv_wnm_oper(hapd, WNM_SLEEP_ENTER_CONFIRM,
161 addr, NULL, NULL);
162 wpa_set_wnmsleep(sta->wpa_sm, 1);
163 }
164 /* when exiting wnmsleep
165 * 1. unmark the node
166 * 2. start GTK/IGTK update if MFP is not used
167 * 3. unpause the node in driver
168 */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800169 if ((wnmsleep_ie.status == WNM_STATUS_SLEEP_ACCEPT ||
170 wnmsleep_ie.status ==
171 WNM_STATUS_SLEEP_EXIT_ACCEPT_GTK_UPDATE) &&
172 wnmsleep_ie.action_type == WNM_SLEEP_MODE_EXIT) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800173 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700174 wpa_set_wnmsleep(sta->wpa_sm, 0);
175 hostapd_drv_wnm_oper(hapd, WNM_SLEEP_EXIT_CONFIRM,
176 addr, NULL, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700177 if (!wpa_auth_uses_mfp(sta->wpa_sm) ||
178 hapd->conf->wnm_sleep_mode_no_keys)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700179 wpa_wnmsleep_rekey_gtk(sta->wpa_sm);
180 }
181 } else
182 wpa_printf(MSG_DEBUG, "Fail to send WNM-Sleep Response frame");
183
184#undef MAX_GTK_SUBELEM_LEN
185#undef MAX_IGTK_SUBELEM_LEN
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800186fail:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700187 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
Roshan Pius3a1667e2018-07-03 15:17:14 -0700205 if (!hapd->conf->wnm_sleep_mode) {
206 wpa_printf(MSG_DEBUG, "Ignore WNM-Sleep Mode Request from "
207 MACSTR " since WNM-Sleep Mode is disabled",
208 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 Shmidtebd93af2017-02-21 13:40:44 -0800217 if (*pos == WLAN_EID_WNMSLEEP &&
218 ie_len >= (int) sizeof(*wnmsleep_ie) - 2)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800219 wnmsleep_ie = (struct wnm_sleep_element *) pos;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700220 else if (*pos == WLAN_EID_TFS_REQ) {
221 if (!tfsreq_ie_start)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800222 tfsreq_ie_start = (u8 *) pos;
223 tfsreq_ie_end = (u8 *) pos;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700224 } else
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800225 wpa_printf(MSG_DEBUG, "WNM: EID %d not recognized",
226 *pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700227 pos += ie_len + 2;
228 }
229
230 if (!wnmsleep_ie) {
231 wpa_printf(MSG_DEBUG, "No WNM-Sleep IE found");
232 return;
233 }
234
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800235 if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_ENTER &&
236 tfsreq_ie_start && tfsreq_ie_end &&
237 tfsreq_ie_end - tfsreq_ie_start >= 0) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700238 tfsreq_ie_len = (tfsreq_ie_end + tfsreq_ie_end[1] + 2) -
239 tfsreq_ie_start;
240 wpa_printf(MSG_DEBUG, "TFS Req IE(s) found");
241 /* pass the TFS Req IE(s) to driver for processing */
242 if (ieee80211_11_set_tfs_ie(hapd, addr, tfsreq_ie_start,
243 &tfsreq_ie_len,
244 WNM_SLEEP_TFS_REQ_IE_SET))
245 wpa_printf(MSG_DEBUG, "Fail to set TFS Req IE");
246 }
247
248 ieee802_11_send_wnmsleep_resp(hapd, addr, dialog_token,
249 wnmsleep_ie->action_type,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800250 le_to_host16(wnmsleep_ie->intval));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700251
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800252 if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_EXIT) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700253 /* clear the tfs after sending the resp frame */
254 ieee80211_11_set_tfs_ie(hapd, addr, tfsreq_ie_start,
255 &tfsreq_ie_len, WNM_SLEEP_TFS_IE_DEL);
256 }
257}
258
259
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800260static int ieee802_11_send_bss_trans_mgmt_request(struct hostapd_data *hapd,
261 const u8 *addr,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800262 u8 dialog_token)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700263{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800264 struct ieee80211_mgmt *mgmt;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800265 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800266 u8 *pos;
267 int res;
268
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800269 mgmt = os_zalloc(sizeof(*mgmt));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800270 if (mgmt == NULL)
271 return -1;
272 os_memcpy(mgmt->da, addr, ETH_ALEN);
273 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
274 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
275 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
276 WLAN_FC_STYPE_ACTION);
277 mgmt->u.action.category = WLAN_ACTION_WNM;
278 mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
279 mgmt->u.action.u.bss_tm_req.dialog_token = dialog_token;
280 mgmt->u.action.u.bss_tm_req.req_mode = 0;
281 mgmt->u.action.u.bss_tm_req.disassoc_timer = host_to_le16(0);
282 mgmt->u.action.u.bss_tm_req.validity_interval = 1;
283 pos = mgmt->u.action.u.bss_tm_req.variable;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800284
285 wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request to "
286 MACSTR " dialog_token=%u req_mode=0x%x disassoc_timer=%u "
287 "validity_interval=%u",
288 MAC2STR(addr), dialog_token,
289 mgmt->u.action.u.bss_tm_req.req_mode,
290 le_to_host16(mgmt->u.action.u.bss_tm_req.disassoc_timer),
291 mgmt->u.action.u.bss_tm_req.validity_interval);
292
293 len = pos - &mgmt->u.action.category;
294 res = hostapd_drv_send_action(hapd, hapd->iface->freq, 0,
295 mgmt->da, &mgmt->u.action.category, len);
296 os_free(mgmt);
297 return res;
298}
299
300
301static void ieee802_11_rx_bss_trans_mgmt_query(struct hostapd_data *hapd,
302 const u8 *addr, const u8 *frm,
303 size_t len)
304{
305 u8 dialog_token, reason;
306 const u8 *pos, *end;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700307 int enabled = hapd->conf->bss_transition;
308
309#ifdef CONFIG_MBO
310 if (hapd->conf->mbo_enabled)
311 enabled = 1;
312#endif /* CONFIG_MBO */
313 if (!enabled) {
314 wpa_printf(MSG_DEBUG,
315 "Ignore BSS Transition Management Query from "
316 MACSTR
317 " since BSS Transition Management is disabled",
318 MAC2STR(addr));
319 return;
320 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800321
322 if (len < 2) {
323 wpa_printf(MSG_DEBUG, "WNM: Ignore too short BSS Transition Management Query from "
324 MACSTR, MAC2STR(addr));
325 return;
326 }
327
328 pos = frm;
329 end = pos + len;
330 dialog_token = *pos++;
331 reason = *pos++;
332
333 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management Query from "
334 MACSTR " dialog_token=%u reason=%u",
335 MAC2STR(addr), dialog_token, reason);
336
337 wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries",
338 pos, end - pos);
339
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800340 ieee802_11_send_bss_trans_mgmt_request(hapd, addr, dialog_token);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800341}
342
343
Roshan Pius3a1667e2018-07-03 15:17:14 -0700344void ap_sta_reset_steer_flag_timer(void *eloop_ctx, void *timeout_ctx)
345{
346 struct hostapd_data *hapd = eloop_ctx;
347 struct sta_info *sta = timeout_ctx;
348
349 if (sta->agreed_to_steer) {
350 wpa_printf(MSG_DEBUG, "%s: Reset steering flag for STA " MACSTR,
351 hapd->conf->iface, MAC2STR(sta->addr));
352 sta->agreed_to_steer = 0;
353 }
354}
355
356
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800357static void ieee802_11_rx_bss_trans_mgmt_resp(struct hostapd_data *hapd,
358 const u8 *addr, const u8 *frm,
359 size_t len)
360{
361 u8 dialog_token, status_code, bss_termination_delay;
362 const u8 *pos, *end;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700363 int enabled = hapd->conf->bss_transition;
364 struct sta_info *sta;
365
366#ifdef CONFIG_MBO
367 if (hapd->conf->mbo_enabled)
368 enabled = 1;
369#endif /* CONFIG_MBO */
370 if (!enabled) {
371 wpa_printf(MSG_DEBUG,
372 "Ignore BSS Transition Management Response from "
373 MACSTR
374 " since BSS Transition Management is disabled",
375 MAC2STR(addr));
376 return;
377 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800378
379 if (len < 3) {
380 wpa_printf(MSG_DEBUG, "WNM: Ignore too short BSS Transition Management Response from "
381 MACSTR, MAC2STR(addr));
382 return;
383 }
384
385 pos = frm;
386 end = pos + len;
387 dialog_token = *pos++;
388 status_code = *pos++;
389 bss_termination_delay = *pos++;
390
391 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management Response from "
392 MACSTR " dialog_token=%u status_code=%u "
393 "bss_termination_delay=%u", MAC2STR(addr), dialog_token,
394 status_code, bss_termination_delay);
395
Roshan Pius3a1667e2018-07-03 15:17:14 -0700396 sta = ap_get_sta(hapd, addr);
397 if (!sta) {
398 wpa_printf(MSG_DEBUG, "Station " MACSTR
399 " not found for received BSS TM Response",
400 MAC2STR(addr));
401 return;
402 }
403
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800404 if (status_code == WNM_BSS_TM_ACCEPT) {
405 if (end - pos < ETH_ALEN) {
406 wpa_printf(MSG_DEBUG, "WNM: not enough room for Target BSSID field");
407 return;
408 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700409 sta->agreed_to_steer = 1;
410 eloop_cancel_timeout(ap_sta_reset_steer_flag_timer, hapd, sta);
411 eloop_register_timeout(2, 0, ap_sta_reset_steer_flag_timer,
412 hapd, sta);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800413 wpa_printf(MSG_DEBUG, "WNM: Target BSSID: " MACSTR,
414 MAC2STR(pos));
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800415 wpa_msg(hapd->msg_ctx, MSG_INFO, BSS_TM_RESP MACSTR
416 " status_code=%u bss_termination_delay=%u target_bssid="
417 MACSTR,
418 MAC2STR(addr), status_code, bss_termination_delay,
419 MAC2STR(pos));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800420 pos += ETH_ALEN;
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800421 } else {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700422 sta->agreed_to_steer = 0;
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800423 wpa_msg(hapd->msg_ctx, MSG_INFO, BSS_TM_RESP MACSTR
424 " status_code=%u bss_termination_delay=%u",
425 MAC2STR(addr), status_code, bss_termination_delay);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800426 }
427
428 wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries",
429 pos, end - pos);
430}
431
432
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800433static void ieee802_11_rx_wnm_notification_req(struct hostapd_data *hapd,
434 const u8 *addr, const u8 *buf,
435 size_t len)
436{
437 u8 dialog_token, type;
438
439 if (len < 2)
440 return;
441 dialog_token = *buf++;
442 type = *buf++;
443 len -= 2;
444
445 wpa_printf(MSG_DEBUG,
446 "WNM: Received WNM Notification Request frame from "
447 MACSTR " (dialog_token=%u type=%u)",
448 MAC2STR(addr), dialog_token, type);
449 wpa_hexdump(MSG_MSGDUMP, "WNM: Notification Request subelements",
450 buf, len);
451 if (type == WLAN_EID_VENDOR_SPECIFIC)
452 mbo_ap_wnm_notification_req(hapd, addr, buf, len);
453}
454
455
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800456int ieee802_11_rx_wnm_action_ap(struct hostapd_data *hapd,
457 const struct ieee80211_mgmt *mgmt, size_t len)
458{
459 u8 action;
460 const u8 *payload;
461 size_t plen;
462
463 if (len < IEEE80211_HDRLEN + 2)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800464 return -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700465
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700466 payload = ((const u8 *) mgmt) + IEEE80211_HDRLEN + 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800467 action = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700468 plen = len - IEEE80211_HDRLEN - 2;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800469
470 switch (action) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800471 case WNM_BSS_TRANS_MGMT_QUERY:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800472 ieee802_11_rx_bss_trans_mgmt_query(hapd, mgmt->sa, payload,
473 plen);
474 return 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800475 case WNM_BSS_TRANS_MGMT_RESP:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800476 ieee802_11_rx_bss_trans_mgmt_resp(hapd, mgmt->sa, payload,
477 plen);
478 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700479 case WNM_SLEEP_MODE_REQ:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800480 ieee802_11_rx_wnmsleep_req(hapd, mgmt->sa, payload, plen);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800481 return 0;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800482 case WNM_NOTIFICATION_REQ:
483 ieee802_11_rx_wnm_notification_req(hapd, mgmt->sa, payload,
484 plen);
485 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700486 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700487
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800488 wpa_printf(MSG_DEBUG, "WNM: Unsupported WNM Action %u from " MACSTR,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800489 action, MAC2STR(mgmt->sa));
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800490 return -1;
491}
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800492
493
494int wnm_send_disassoc_imminent(struct hostapd_data *hapd,
495 struct sta_info *sta, int disassoc_timer)
496{
497 u8 buf[1000], *pos;
498 struct ieee80211_mgmt *mgmt;
499
500 os_memset(buf, 0, sizeof(buf));
501 mgmt = (struct ieee80211_mgmt *) buf;
502 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
503 WLAN_FC_STYPE_ACTION);
504 os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
505 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
506 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
507 mgmt->u.action.category = WLAN_ACTION_WNM;
508 mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
509 mgmt->u.action.u.bss_tm_req.dialog_token = 1;
510 mgmt->u.action.u.bss_tm_req.req_mode =
511 WNM_BSS_TM_REQ_DISASSOC_IMMINENT;
512 mgmt->u.action.u.bss_tm_req.disassoc_timer =
513 host_to_le16(disassoc_timer);
514 mgmt->u.action.u.bss_tm_req.validity_interval = 0;
515
516 pos = mgmt->u.action.u.bss_tm_req.variable;
517
518 wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request frame to indicate imminent disassociation (disassoc_timer=%d) to "
519 MACSTR, disassoc_timer, MAC2STR(sta->addr));
520 if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0) < 0) {
521 wpa_printf(MSG_DEBUG, "Failed to send BSS Transition "
522 "Management Request frame");
523 return -1;
524 }
525
526 return 0;
527}
528
529
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800530static void set_disassoc_timer(struct hostapd_data *hapd, struct sta_info *sta,
531 int disassoc_timer)
532{
533 int timeout, beacon_int;
534
535 /*
536 * Prevent STA from reconnecting using cached PMKSA to force
537 * full authentication with the authentication server (which may
538 * decide to reject the connection),
539 */
540 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
541
542 beacon_int = hapd->iconf->beacon_int;
543 if (beacon_int < 1)
544 beacon_int = 100; /* best guess */
545 /* Calculate timeout in ms based on beacon_int in TU */
546 timeout = disassoc_timer * beacon_int * 128 / 125;
547 wpa_printf(MSG_DEBUG, "Disassociation timer for " MACSTR
548 " set to %d ms", MAC2STR(sta->addr), timeout);
549
550 sta->timeout_next = STA_DISASSOC_FROM_CLI;
551 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
552 eloop_register_timeout(timeout / 1000,
553 timeout % 1000 * 1000,
554 ap_handle_timer, hapd, sta);
555}
556
557
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800558int wnm_send_ess_disassoc_imminent(struct hostapd_data *hapd,
559 struct sta_info *sta, const char *url,
560 int disassoc_timer)
561{
562 u8 buf[1000], *pos;
563 struct ieee80211_mgmt *mgmt;
564 size_t url_len;
565
566 os_memset(buf, 0, sizeof(buf));
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 =
577 WNM_BSS_TM_REQ_DISASSOC_IMMINENT |
578 WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT;
579 mgmt->u.action.u.bss_tm_req.disassoc_timer =
580 host_to_le16(disassoc_timer);
581 mgmt->u.action.u.bss_tm_req.validity_interval = 0x01;
582
583 pos = mgmt->u.action.u.bss_tm_req.variable;
584
585 /* Session Information URL */
586 url_len = os_strlen(url);
587 if (url_len > 255)
588 return -1;
589 *pos++ = url_len;
590 os_memcpy(pos, url, url_len);
591 pos += url_len;
592
593 if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0) < 0) {
594 wpa_printf(MSG_DEBUG, "Failed to send BSS Transition "
595 "Management Request frame");
596 return -1;
597 }
598
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800599 if (disassoc_timer) {
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800600 /* send disassociation frame after time-out */
601 set_disassoc_timer(hapd, sta, disassoc_timer);
602 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800603
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800604 return 0;
605}
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800606
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800607
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800608int wnm_send_bss_tm_req(struct hostapd_data *hapd, struct sta_info *sta,
609 u8 req_mode, int disassoc_timer, u8 valid_int,
610 const u8 *bss_term_dur, const char *url,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800611 const u8 *nei_rep, size_t nei_rep_len,
612 const u8 *mbo_attrs, size_t mbo_len)
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800613{
614 u8 *buf, *pos;
615 struct ieee80211_mgmt *mgmt;
616 size_t url_len;
617
618 wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request to "
619 MACSTR " req_mode=0x%x disassoc_timer=%d valid_int=0x%x",
620 MAC2STR(sta->addr), req_mode, disassoc_timer, valid_int);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800621 buf = os_zalloc(1000 + nei_rep_len + mbo_len);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800622 if (buf == NULL)
623 return -1;
624 mgmt = (struct ieee80211_mgmt *) buf;
625 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
626 WLAN_FC_STYPE_ACTION);
627 os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
628 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
629 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
630 mgmt->u.action.category = WLAN_ACTION_WNM;
631 mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
632 mgmt->u.action.u.bss_tm_req.dialog_token = 1;
633 mgmt->u.action.u.bss_tm_req.req_mode = req_mode;
634 mgmt->u.action.u.bss_tm_req.disassoc_timer =
635 host_to_le16(disassoc_timer);
636 mgmt->u.action.u.bss_tm_req.validity_interval = valid_int;
637
638 pos = mgmt->u.action.u.bss_tm_req.variable;
639
640 if ((req_mode & WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED) &&
641 bss_term_dur) {
642 os_memcpy(pos, bss_term_dur, 12);
643 pos += 12;
644 }
645
646 if (url) {
647 /* Session Information URL */
648 url_len = os_strlen(url);
Dmitry Shmidt432d6032015-01-21 13:19:05 -0800649 if (url_len > 255) {
650 os_free(buf);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800651 return -1;
Dmitry Shmidt432d6032015-01-21 13:19:05 -0800652 }
653
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800654 *pos++ = url_len;
655 os_memcpy(pos, url, url_len);
656 pos += url_len;
657 }
658
659 if (nei_rep) {
660 os_memcpy(pos, nei_rep, nei_rep_len);
661 pos += nei_rep_len;
662 }
663
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800664 if (mbo_len > 0) {
665 pos += mbo_add_ie(pos, buf + sizeof(buf) - pos, mbo_attrs,
666 mbo_len);
667 }
668
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800669 if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0) < 0) {
670 wpa_printf(MSG_DEBUG,
671 "Failed to send BSS Transition Management Request frame");
672 os_free(buf);
673 return -1;
674 }
675 os_free(buf);
676
677 if (disassoc_timer) {
678 /* send disassociation frame after time-out */
679 set_disassoc_timer(hapd, sta, disassoc_timer);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800680 }
681
682 return 0;
683}