blob: 61d2f65fa388be2ec5b9159d2b2018ad093bfeba [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;
Hai Shalombf6e0ba2019-02-11 12:01:50 -080057 u8 *wnmtfs_ie;
58 u8 wnmsleep_ie_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070059 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 +
Hai Shalombf6e0ba2019-02-11 12:01:50 -080094 MAX_GTK_SUBELEM_LEN + MAX_IGTK_SUBELEM_LEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070095 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;
Hai Shalombf6e0ba2019-02-11 12:01:50 -0800137 if (wnmtfs_ie)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800138 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 +
Hai Shalombf6e0ba2019-02-11 12:01:50 -0800141 igtk_elem_len + wnmsleep_ie_len + wnmtfs_ie_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700142
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
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800463static void ieee802_11_rx_wnm_coloc_intf_report(struct hostapd_data *hapd,
464 const u8 *addr, const u8 *buf,
465 size_t len)
466{
467 u8 dialog_token;
468 char *hex;
469 size_t hex_len;
470
471 if (!hapd->conf->coloc_intf_reporting) {
472 wpa_printf(MSG_DEBUG,
473 "WNM: Ignore unexpected Collocated Interference Report from "
474 MACSTR, MAC2STR(addr));
475 return;
476 }
477
478 if (len < 1) {
479 wpa_printf(MSG_DEBUG,
480 "WNM: Ignore too short Collocated Interference Report from "
481 MACSTR, MAC2STR(addr));
482 return;
483 }
484 dialog_token = *buf++;
485 len--;
486
487 wpa_printf(MSG_DEBUG,
488 "WNM: Received Collocated Interference Report frame from "
489 MACSTR " (dialog_token=%u)",
490 MAC2STR(addr), dialog_token);
491 wpa_hexdump(MSG_MSGDUMP, "WNM: Collocated Interference Report Elements",
492 buf, len);
493
494 hex_len = 2 * len + 1;
495 hex = os_malloc(hex_len);
496 if (!hex)
497 return;
498 wpa_snprintf_hex(hex, hex_len, buf, len);
499 wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, COLOC_INTF_REPORT MACSTR " %d %s",
500 MAC2STR(addr), dialog_token, hex);
501 os_free(hex);
502}
503
504
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800505int ieee802_11_rx_wnm_action_ap(struct hostapd_data *hapd,
506 const struct ieee80211_mgmt *mgmt, size_t len)
507{
508 u8 action;
509 const u8 *payload;
510 size_t plen;
511
512 if (len < IEEE80211_HDRLEN + 2)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800513 return -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700514
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700515 payload = ((const u8 *) mgmt) + IEEE80211_HDRLEN + 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800516 action = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700517 plen = len - IEEE80211_HDRLEN - 2;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800518
519 switch (action) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800520 case WNM_BSS_TRANS_MGMT_QUERY:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800521 ieee802_11_rx_bss_trans_mgmt_query(hapd, mgmt->sa, payload,
522 plen);
523 return 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800524 case WNM_BSS_TRANS_MGMT_RESP:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800525 ieee802_11_rx_bss_trans_mgmt_resp(hapd, mgmt->sa, payload,
526 plen);
527 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700528 case WNM_SLEEP_MODE_REQ:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800529 ieee802_11_rx_wnmsleep_req(hapd, mgmt->sa, payload, plen);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800530 return 0;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800531 case WNM_NOTIFICATION_REQ:
532 ieee802_11_rx_wnm_notification_req(hapd, mgmt->sa, payload,
533 plen);
534 return 0;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800535 case WNM_COLLOCATED_INTERFERENCE_REPORT:
536 ieee802_11_rx_wnm_coloc_intf_report(hapd, mgmt->sa, payload,
537 plen);
538 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700539 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700540
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800541 wpa_printf(MSG_DEBUG, "WNM: Unsupported WNM Action %u from " MACSTR,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800542 action, MAC2STR(mgmt->sa));
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800543 return -1;
544}
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800545
546
547int wnm_send_disassoc_imminent(struct hostapd_data *hapd,
548 struct sta_info *sta, int disassoc_timer)
549{
550 u8 buf[1000], *pos;
551 struct ieee80211_mgmt *mgmt;
552
553 os_memset(buf, 0, sizeof(buf));
554 mgmt = (struct ieee80211_mgmt *) buf;
555 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
556 WLAN_FC_STYPE_ACTION);
557 os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
558 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
559 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
560 mgmt->u.action.category = WLAN_ACTION_WNM;
561 mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
562 mgmt->u.action.u.bss_tm_req.dialog_token = 1;
563 mgmt->u.action.u.bss_tm_req.req_mode =
564 WNM_BSS_TM_REQ_DISASSOC_IMMINENT;
565 mgmt->u.action.u.bss_tm_req.disassoc_timer =
566 host_to_le16(disassoc_timer);
567 mgmt->u.action.u.bss_tm_req.validity_interval = 0;
568
569 pos = mgmt->u.action.u.bss_tm_req.variable;
570
571 wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request frame to indicate imminent disassociation (disassoc_timer=%d) to "
572 MACSTR, disassoc_timer, MAC2STR(sta->addr));
573 if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0) < 0) {
574 wpa_printf(MSG_DEBUG, "Failed to send BSS Transition "
575 "Management Request frame");
576 return -1;
577 }
578
579 return 0;
580}
581
582
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800583static void set_disassoc_timer(struct hostapd_data *hapd, struct sta_info *sta,
584 int disassoc_timer)
585{
586 int timeout, beacon_int;
587
588 /*
589 * Prevent STA from reconnecting using cached PMKSA to force
590 * full authentication with the authentication server (which may
591 * decide to reject the connection),
592 */
593 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
594
595 beacon_int = hapd->iconf->beacon_int;
596 if (beacon_int < 1)
597 beacon_int = 100; /* best guess */
598 /* Calculate timeout in ms based on beacon_int in TU */
599 timeout = disassoc_timer * beacon_int * 128 / 125;
600 wpa_printf(MSG_DEBUG, "Disassociation timer for " MACSTR
601 " set to %d ms", MAC2STR(sta->addr), timeout);
602
603 sta->timeout_next = STA_DISASSOC_FROM_CLI;
604 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
605 eloop_register_timeout(timeout / 1000,
606 timeout % 1000 * 1000,
607 ap_handle_timer, hapd, sta);
608}
609
610
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800611int wnm_send_ess_disassoc_imminent(struct hostapd_data *hapd,
612 struct sta_info *sta, const char *url,
613 int disassoc_timer)
614{
615 u8 buf[1000], *pos;
616 struct ieee80211_mgmt *mgmt;
617 size_t url_len;
618
619 os_memset(buf, 0, sizeof(buf));
620 mgmt = (struct ieee80211_mgmt *) buf;
621 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
622 WLAN_FC_STYPE_ACTION);
623 os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
624 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
625 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
626 mgmt->u.action.category = WLAN_ACTION_WNM;
627 mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
628 mgmt->u.action.u.bss_tm_req.dialog_token = 1;
629 mgmt->u.action.u.bss_tm_req.req_mode =
630 WNM_BSS_TM_REQ_DISASSOC_IMMINENT |
631 WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT;
632 mgmt->u.action.u.bss_tm_req.disassoc_timer =
633 host_to_le16(disassoc_timer);
634 mgmt->u.action.u.bss_tm_req.validity_interval = 0x01;
635
636 pos = mgmt->u.action.u.bss_tm_req.variable;
637
638 /* Session Information URL */
639 url_len = os_strlen(url);
640 if (url_len > 255)
641 return -1;
642 *pos++ = url_len;
643 os_memcpy(pos, url, url_len);
644 pos += url_len;
645
646 if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0) < 0) {
647 wpa_printf(MSG_DEBUG, "Failed to send BSS Transition "
648 "Management Request frame");
649 return -1;
650 }
651
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800652 if (disassoc_timer) {
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800653 /* send disassociation frame after time-out */
654 set_disassoc_timer(hapd, sta, disassoc_timer);
655 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800656
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800657 return 0;
658}
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800659
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800660
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800661int wnm_send_bss_tm_req(struct hostapd_data *hapd, struct sta_info *sta,
662 u8 req_mode, int disassoc_timer, u8 valid_int,
663 const u8 *bss_term_dur, const char *url,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800664 const u8 *nei_rep, size_t nei_rep_len,
665 const u8 *mbo_attrs, size_t mbo_len)
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800666{
667 u8 *buf, *pos;
668 struct ieee80211_mgmt *mgmt;
669 size_t url_len;
670
671 wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request to "
672 MACSTR " req_mode=0x%x disassoc_timer=%d valid_int=0x%x",
673 MAC2STR(sta->addr), req_mode, disassoc_timer, valid_int);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800674 buf = os_zalloc(1000 + nei_rep_len + mbo_len);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800675 if (buf == NULL)
676 return -1;
677 mgmt = (struct ieee80211_mgmt *) buf;
678 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
679 WLAN_FC_STYPE_ACTION);
680 os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
681 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
682 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
683 mgmt->u.action.category = WLAN_ACTION_WNM;
684 mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
685 mgmt->u.action.u.bss_tm_req.dialog_token = 1;
686 mgmt->u.action.u.bss_tm_req.req_mode = req_mode;
687 mgmt->u.action.u.bss_tm_req.disassoc_timer =
688 host_to_le16(disassoc_timer);
689 mgmt->u.action.u.bss_tm_req.validity_interval = valid_int;
690
691 pos = mgmt->u.action.u.bss_tm_req.variable;
692
693 if ((req_mode & WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED) &&
694 bss_term_dur) {
695 os_memcpy(pos, bss_term_dur, 12);
696 pos += 12;
697 }
698
699 if (url) {
700 /* Session Information URL */
701 url_len = os_strlen(url);
Dmitry Shmidt432d6032015-01-21 13:19:05 -0800702 if (url_len > 255) {
703 os_free(buf);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800704 return -1;
Dmitry Shmidt432d6032015-01-21 13:19:05 -0800705 }
706
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800707 *pos++ = url_len;
708 os_memcpy(pos, url, url_len);
709 pos += url_len;
710 }
711
712 if (nei_rep) {
713 os_memcpy(pos, nei_rep, nei_rep_len);
714 pos += nei_rep_len;
715 }
716
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800717 if (mbo_len > 0) {
718 pos += mbo_add_ie(pos, buf + sizeof(buf) - pos, mbo_attrs,
719 mbo_len);
720 }
721
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800722 if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0) < 0) {
723 wpa_printf(MSG_DEBUG,
724 "Failed to send BSS Transition Management Request frame");
725 os_free(buf);
726 return -1;
727 }
728 os_free(buf);
729
730 if (disassoc_timer) {
731 /* send disassociation frame after time-out */
732 set_disassoc_timer(hapd, sta, disassoc_timer);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800733 }
734
735 return 0;
736}
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800737
738
739int wnm_send_coloc_intf_req(struct hostapd_data *hapd, struct sta_info *sta,
740 unsigned int auto_report, unsigned int timeout)
741{
742 u8 buf[100], *pos;
743 struct ieee80211_mgmt *mgmt;
744 u8 dialog_token = 1;
745
746 if (auto_report > 3 || timeout > 63)
747 return -1;
748 os_memset(buf, 0, sizeof(buf));
749 mgmt = (struct ieee80211_mgmt *) buf;
750 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
751 WLAN_FC_STYPE_ACTION);
752 os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
753 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
754 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
755 mgmt->u.action.category = WLAN_ACTION_WNM;
756 mgmt->u.action.u.coloc_intf_req.action =
757 WNM_COLLOCATED_INTERFERENCE_REQ;
758 mgmt->u.action.u.coloc_intf_req.dialog_token = dialog_token;
759 mgmt->u.action.u.coloc_intf_req.req_info = auto_report | (timeout << 2);
760 pos = &mgmt->u.action.u.coloc_intf_req.req_info;
761 pos++;
762
763 wpa_printf(MSG_DEBUG, "WNM: Sending Collocated Interference Request to "
764 MACSTR " (dialog_token=%u auto_report=%u timeout=%u)",
765 MAC2STR(sta->addr), dialog_token, auto_report, timeout);
766 if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0) < 0) {
767 wpa_printf(MSG_DEBUG,
768 "WNM: Failed to send Collocated Interference Request frame");
769 return -1;
770 }
771
772 return 0;
773}