blob: 7b43c7df2d73148d7fee476c70adee2952c543b8 [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
Jouni Malinen83e54022018-10-29 20:48:07 +0200212 if (len < 1) {
213 wpa_printf(MSG_DEBUG,
214 "WNM: Ignore too short WNM-Sleep Mode Request from "
215 MACSTR, MAC2STR(addr));
216 return;
217 }
218
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800219 dialog_token = *pos++;
220 while (pos + 1 < frm + len) {
221 u8 ie_len = pos[1];
222 if (pos + 2 + ie_len > frm + len)
223 break;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800224 if (*pos == WLAN_EID_WNMSLEEP &&
225 ie_len >= (int) sizeof(*wnmsleep_ie) - 2)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800226 wnmsleep_ie = (struct wnm_sleep_element *) pos;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700227 else if (*pos == WLAN_EID_TFS_REQ) {
228 if (!tfsreq_ie_start)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800229 tfsreq_ie_start = (u8 *) pos;
230 tfsreq_ie_end = (u8 *) pos;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700231 } else
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800232 wpa_printf(MSG_DEBUG, "WNM: EID %d not recognized",
233 *pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700234 pos += ie_len + 2;
235 }
236
237 if (!wnmsleep_ie) {
238 wpa_printf(MSG_DEBUG, "No WNM-Sleep IE found");
239 return;
240 }
241
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800242 if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_ENTER &&
243 tfsreq_ie_start && tfsreq_ie_end &&
244 tfsreq_ie_end - tfsreq_ie_start >= 0) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700245 tfsreq_ie_len = (tfsreq_ie_end + tfsreq_ie_end[1] + 2) -
246 tfsreq_ie_start;
247 wpa_printf(MSG_DEBUG, "TFS Req IE(s) found");
248 /* pass the TFS Req IE(s) to driver for processing */
249 if (ieee80211_11_set_tfs_ie(hapd, addr, tfsreq_ie_start,
250 &tfsreq_ie_len,
251 WNM_SLEEP_TFS_REQ_IE_SET))
252 wpa_printf(MSG_DEBUG, "Fail to set TFS Req IE");
253 }
254
255 ieee802_11_send_wnmsleep_resp(hapd, addr, dialog_token,
256 wnmsleep_ie->action_type,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800257 le_to_host16(wnmsleep_ie->intval));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700258
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800259 if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_EXIT) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700260 /* clear the tfs after sending the resp frame */
261 ieee80211_11_set_tfs_ie(hapd, addr, tfsreq_ie_start,
262 &tfsreq_ie_len, WNM_SLEEP_TFS_IE_DEL);
263 }
264}
265
266
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800267static int ieee802_11_send_bss_trans_mgmt_request(struct hostapd_data *hapd,
268 const u8 *addr,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800269 u8 dialog_token)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700270{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800271 struct ieee80211_mgmt *mgmt;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800272 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800273 u8 *pos;
274 int res;
275
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800276 mgmt = os_zalloc(sizeof(*mgmt));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800277 if (mgmt == NULL)
278 return -1;
279 os_memcpy(mgmt->da, addr, ETH_ALEN);
280 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
281 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
282 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
283 WLAN_FC_STYPE_ACTION);
284 mgmt->u.action.category = WLAN_ACTION_WNM;
285 mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
286 mgmt->u.action.u.bss_tm_req.dialog_token = dialog_token;
287 mgmt->u.action.u.bss_tm_req.req_mode = 0;
288 mgmt->u.action.u.bss_tm_req.disassoc_timer = host_to_le16(0);
289 mgmt->u.action.u.bss_tm_req.validity_interval = 1;
290 pos = mgmt->u.action.u.bss_tm_req.variable;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800291
292 wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request to "
293 MACSTR " dialog_token=%u req_mode=0x%x disassoc_timer=%u "
294 "validity_interval=%u",
295 MAC2STR(addr), dialog_token,
296 mgmt->u.action.u.bss_tm_req.req_mode,
297 le_to_host16(mgmt->u.action.u.bss_tm_req.disassoc_timer),
298 mgmt->u.action.u.bss_tm_req.validity_interval);
299
300 len = pos - &mgmt->u.action.category;
301 res = hostapd_drv_send_action(hapd, hapd->iface->freq, 0,
302 mgmt->da, &mgmt->u.action.category, len);
303 os_free(mgmt);
304 return res;
305}
306
307
308static void ieee802_11_rx_bss_trans_mgmt_query(struct hostapd_data *hapd,
309 const u8 *addr, const u8 *frm,
310 size_t len)
311{
312 u8 dialog_token, reason;
313 const u8 *pos, *end;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700314 int enabled = hapd->conf->bss_transition;
315
316#ifdef CONFIG_MBO
317 if (hapd->conf->mbo_enabled)
318 enabled = 1;
319#endif /* CONFIG_MBO */
320 if (!enabled) {
321 wpa_printf(MSG_DEBUG,
322 "Ignore BSS Transition Management Query from "
323 MACSTR
324 " since BSS Transition Management is disabled",
325 MAC2STR(addr));
326 return;
327 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800328
329 if (len < 2) {
330 wpa_printf(MSG_DEBUG, "WNM: Ignore too short BSS Transition Management Query from "
331 MACSTR, MAC2STR(addr));
332 return;
333 }
334
335 pos = frm;
336 end = pos + len;
337 dialog_token = *pos++;
338 reason = *pos++;
339
340 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management Query from "
341 MACSTR " dialog_token=%u reason=%u",
342 MAC2STR(addr), dialog_token, reason);
343
344 wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries",
345 pos, end - pos);
346
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800347 ieee802_11_send_bss_trans_mgmt_request(hapd, addr, dialog_token);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800348}
349
350
Roshan Pius3a1667e2018-07-03 15:17:14 -0700351void ap_sta_reset_steer_flag_timer(void *eloop_ctx, void *timeout_ctx)
352{
353 struct hostapd_data *hapd = eloop_ctx;
354 struct sta_info *sta = timeout_ctx;
355
356 if (sta->agreed_to_steer) {
357 wpa_printf(MSG_DEBUG, "%s: Reset steering flag for STA " MACSTR,
358 hapd->conf->iface, MAC2STR(sta->addr));
359 sta->agreed_to_steer = 0;
360 }
361}
362
363
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800364static void ieee802_11_rx_bss_trans_mgmt_resp(struct hostapd_data *hapd,
365 const u8 *addr, const u8 *frm,
366 size_t len)
367{
368 u8 dialog_token, status_code, bss_termination_delay;
369 const u8 *pos, *end;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700370 int enabled = hapd->conf->bss_transition;
371 struct sta_info *sta;
372
373#ifdef CONFIG_MBO
374 if (hapd->conf->mbo_enabled)
375 enabled = 1;
376#endif /* CONFIG_MBO */
377 if (!enabled) {
378 wpa_printf(MSG_DEBUG,
379 "Ignore BSS Transition Management Response from "
380 MACSTR
381 " since BSS Transition Management is disabled",
382 MAC2STR(addr));
383 return;
384 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800385
386 if (len < 3) {
387 wpa_printf(MSG_DEBUG, "WNM: Ignore too short BSS Transition Management Response from "
388 MACSTR, MAC2STR(addr));
389 return;
390 }
391
392 pos = frm;
393 end = pos + len;
394 dialog_token = *pos++;
395 status_code = *pos++;
396 bss_termination_delay = *pos++;
397
398 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management Response from "
399 MACSTR " dialog_token=%u status_code=%u "
400 "bss_termination_delay=%u", MAC2STR(addr), dialog_token,
401 status_code, bss_termination_delay);
402
Roshan Pius3a1667e2018-07-03 15:17:14 -0700403 sta = ap_get_sta(hapd, addr);
404 if (!sta) {
405 wpa_printf(MSG_DEBUG, "Station " MACSTR
406 " not found for received BSS TM Response",
407 MAC2STR(addr));
408 return;
409 }
410
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800411 if (status_code == WNM_BSS_TM_ACCEPT) {
412 if (end - pos < ETH_ALEN) {
413 wpa_printf(MSG_DEBUG, "WNM: not enough room for Target BSSID field");
414 return;
415 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700416 sta->agreed_to_steer = 1;
417 eloop_cancel_timeout(ap_sta_reset_steer_flag_timer, hapd, sta);
418 eloop_register_timeout(2, 0, ap_sta_reset_steer_flag_timer,
419 hapd, sta);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800420 wpa_printf(MSG_DEBUG, "WNM: Target BSSID: " MACSTR,
421 MAC2STR(pos));
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800422 wpa_msg(hapd->msg_ctx, MSG_INFO, BSS_TM_RESP MACSTR
423 " status_code=%u bss_termination_delay=%u target_bssid="
424 MACSTR,
425 MAC2STR(addr), status_code, bss_termination_delay,
426 MAC2STR(pos));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800427 pos += ETH_ALEN;
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800428 } else {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700429 sta->agreed_to_steer = 0;
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800430 wpa_msg(hapd->msg_ctx, MSG_INFO, BSS_TM_RESP MACSTR
431 " status_code=%u bss_termination_delay=%u",
432 MAC2STR(addr), status_code, bss_termination_delay);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800433 }
434
435 wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries",
436 pos, end - pos);
437}
438
439
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800440static void ieee802_11_rx_wnm_notification_req(struct hostapd_data *hapd,
441 const u8 *addr, const u8 *buf,
442 size_t len)
443{
444 u8 dialog_token, type;
445
446 if (len < 2)
447 return;
448 dialog_token = *buf++;
449 type = *buf++;
450 len -= 2;
451
452 wpa_printf(MSG_DEBUG,
453 "WNM: Received WNM Notification Request frame from "
454 MACSTR " (dialog_token=%u type=%u)",
455 MAC2STR(addr), dialog_token, type);
456 wpa_hexdump(MSG_MSGDUMP, "WNM: Notification Request subelements",
457 buf, len);
458 if (type == WLAN_EID_VENDOR_SPECIFIC)
459 mbo_ap_wnm_notification_req(hapd, addr, buf, len);
460}
461
462
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800463int ieee802_11_rx_wnm_action_ap(struct hostapd_data *hapd,
464 const struct ieee80211_mgmt *mgmt, size_t len)
465{
466 u8 action;
467 const u8 *payload;
468 size_t plen;
469
470 if (len < IEEE80211_HDRLEN + 2)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800471 return -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700472
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700473 payload = ((const u8 *) mgmt) + IEEE80211_HDRLEN + 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800474 action = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700475 plen = len - IEEE80211_HDRLEN - 2;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800476
477 switch (action) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800478 case WNM_BSS_TRANS_MGMT_QUERY:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800479 ieee802_11_rx_bss_trans_mgmt_query(hapd, mgmt->sa, payload,
480 plen);
481 return 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800482 case WNM_BSS_TRANS_MGMT_RESP:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800483 ieee802_11_rx_bss_trans_mgmt_resp(hapd, mgmt->sa, payload,
484 plen);
485 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700486 case WNM_SLEEP_MODE_REQ:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800487 ieee802_11_rx_wnmsleep_req(hapd, mgmt->sa, payload, plen);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800488 return 0;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800489 case WNM_NOTIFICATION_REQ:
490 ieee802_11_rx_wnm_notification_req(hapd, mgmt->sa, payload,
491 plen);
492 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700493 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700494
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800495 wpa_printf(MSG_DEBUG, "WNM: Unsupported WNM Action %u from " MACSTR,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800496 action, MAC2STR(mgmt->sa));
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800497 return -1;
498}
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800499
500
501int wnm_send_disassoc_imminent(struct hostapd_data *hapd,
502 struct sta_info *sta, int disassoc_timer)
503{
504 u8 buf[1000], *pos;
505 struct ieee80211_mgmt *mgmt;
506
507 os_memset(buf, 0, sizeof(buf));
508 mgmt = (struct ieee80211_mgmt *) buf;
509 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
510 WLAN_FC_STYPE_ACTION);
511 os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
512 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
513 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
514 mgmt->u.action.category = WLAN_ACTION_WNM;
515 mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
516 mgmt->u.action.u.bss_tm_req.dialog_token = 1;
517 mgmt->u.action.u.bss_tm_req.req_mode =
518 WNM_BSS_TM_REQ_DISASSOC_IMMINENT;
519 mgmt->u.action.u.bss_tm_req.disassoc_timer =
520 host_to_le16(disassoc_timer);
521 mgmt->u.action.u.bss_tm_req.validity_interval = 0;
522
523 pos = mgmt->u.action.u.bss_tm_req.variable;
524
525 wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request frame to indicate imminent disassociation (disassoc_timer=%d) to "
526 MACSTR, disassoc_timer, MAC2STR(sta->addr));
527 if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0) < 0) {
528 wpa_printf(MSG_DEBUG, "Failed to send BSS Transition "
529 "Management Request frame");
530 return -1;
531 }
532
533 return 0;
534}
535
536
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800537static void set_disassoc_timer(struct hostapd_data *hapd, struct sta_info *sta,
538 int disassoc_timer)
539{
540 int timeout, beacon_int;
541
542 /*
543 * Prevent STA from reconnecting using cached PMKSA to force
544 * full authentication with the authentication server (which may
545 * decide to reject the connection),
546 */
547 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
548
549 beacon_int = hapd->iconf->beacon_int;
550 if (beacon_int < 1)
551 beacon_int = 100; /* best guess */
552 /* Calculate timeout in ms based on beacon_int in TU */
553 timeout = disassoc_timer * beacon_int * 128 / 125;
554 wpa_printf(MSG_DEBUG, "Disassociation timer for " MACSTR
555 " set to %d ms", MAC2STR(sta->addr), timeout);
556
557 sta->timeout_next = STA_DISASSOC_FROM_CLI;
558 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
559 eloop_register_timeout(timeout / 1000,
560 timeout % 1000 * 1000,
561 ap_handle_timer, hapd, sta);
562}
563
564
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800565int wnm_send_ess_disassoc_imminent(struct hostapd_data *hapd,
566 struct sta_info *sta, const char *url,
567 int disassoc_timer)
568{
569 u8 buf[1000], *pos;
570 struct ieee80211_mgmt *mgmt;
571 size_t url_len;
572
573 os_memset(buf, 0, sizeof(buf));
574 mgmt = (struct ieee80211_mgmt *) buf;
575 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
576 WLAN_FC_STYPE_ACTION);
577 os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
578 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
579 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
580 mgmt->u.action.category = WLAN_ACTION_WNM;
581 mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
582 mgmt->u.action.u.bss_tm_req.dialog_token = 1;
583 mgmt->u.action.u.bss_tm_req.req_mode =
584 WNM_BSS_TM_REQ_DISASSOC_IMMINENT |
585 WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT;
586 mgmt->u.action.u.bss_tm_req.disassoc_timer =
587 host_to_le16(disassoc_timer);
588 mgmt->u.action.u.bss_tm_req.validity_interval = 0x01;
589
590 pos = mgmt->u.action.u.bss_tm_req.variable;
591
592 /* Session Information URL */
593 url_len = os_strlen(url);
594 if (url_len > 255)
595 return -1;
596 *pos++ = url_len;
597 os_memcpy(pos, url, url_len);
598 pos += url_len;
599
600 if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0) < 0) {
601 wpa_printf(MSG_DEBUG, "Failed to send BSS Transition "
602 "Management Request frame");
603 return -1;
604 }
605
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800606 if (disassoc_timer) {
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800607 /* send disassociation frame after time-out */
608 set_disassoc_timer(hapd, sta, disassoc_timer);
609 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800610
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800611 return 0;
612}
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800613
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800614
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800615int wnm_send_bss_tm_req(struct hostapd_data *hapd, struct sta_info *sta,
616 u8 req_mode, int disassoc_timer, u8 valid_int,
617 const u8 *bss_term_dur, const char *url,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800618 const u8 *nei_rep, size_t nei_rep_len,
619 const u8 *mbo_attrs, size_t mbo_len)
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800620{
621 u8 *buf, *pos;
622 struct ieee80211_mgmt *mgmt;
623 size_t url_len;
624
625 wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request to "
626 MACSTR " req_mode=0x%x disassoc_timer=%d valid_int=0x%x",
627 MAC2STR(sta->addr), req_mode, disassoc_timer, valid_int);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800628 buf = os_zalloc(1000 + nei_rep_len + mbo_len);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800629 if (buf == NULL)
630 return -1;
631 mgmt = (struct ieee80211_mgmt *) buf;
632 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
633 WLAN_FC_STYPE_ACTION);
634 os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
635 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
636 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
637 mgmt->u.action.category = WLAN_ACTION_WNM;
638 mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
639 mgmt->u.action.u.bss_tm_req.dialog_token = 1;
640 mgmt->u.action.u.bss_tm_req.req_mode = req_mode;
641 mgmt->u.action.u.bss_tm_req.disassoc_timer =
642 host_to_le16(disassoc_timer);
643 mgmt->u.action.u.bss_tm_req.validity_interval = valid_int;
644
645 pos = mgmt->u.action.u.bss_tm_req.variable;
646
647 if ((req_mode & WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED) &&
648 bss_term_dur) {
649 os_memcpy(pos, bss_term_dur, 12);
650 pos += 12;
651 }
652
653 if (url) {
654 /* Session Information URL */
655 url_len = os_strlen(url);
Dmitry Shmidt432d6032015-01-21 13:19:05 -0800656 if (url_len > 255) {
657 os_free(buf);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800658 return -1;
Dmitry Shmidt432d6032015-01-21 13:19:05 -0800659 }
660
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800661 *pos++ = url_len;
662 os_memcpy(pos, url, url_len);
663 pos += url_len;
664 }
665
666 if (nei_rep) {
667 os_memcpy(pos, nei_rep, nei_rep_len);
668 pos += nei_rep_len;
669 }
670
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800671 if (mbo_len > 0) {
672 pos += mbo_add_ie(pos, buf + sizeof(buf) - pos, mbo_attrs,
673 mbo_len);
674 }
675
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800676 if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0) < 0) {
677 wpa_printf(MSG_DEBUG,
678 "Failed to send BSS Transition Management Request frame");
679 os_free(buf);
680 return -1;
681 }
682 os_free(buf);
683
684 if (disassoc_timer) {
685 /* send disassociation frame after time-out */
686 set_disassoc_timer(hapd, sta, disassoc_timer);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800687 }
688
689 return 0;
690}