blob: be817978e88a02d13bd45c9003459d4efaf9f972 [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"
Hai Shalom74f70d42019-02-11 14:42:39 -080015#include "common/ocv.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070016#include "ap/hostapd.h"
17#include "ap/sta_info.h"
18#include "ap/ap_config.h"
19#include "ap/ap_drv_ops.h"
20#include "ap/wpa_auth.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080021#include "mbo_ap.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070022#include "wnm_ap.h"
23
24#define MAX_TFS_IE_LEN 1024
25
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070026
27/* get the TFS IE from driver */
28static int ieee80211_11_get_tfs_ie(struct hostapd_data *hapd, const u8 *addr,
29 u8 *buf, u16 *buf_len, enum wnm_oper oper)
30{
31 wpa_printf(MSG_DEBUG, "%s: TFS get operation %d", __func__, oper);
32
33 return hostapd_drv_wnm_oper(hapd, oper, addr, buf, buf_len);
34}
35
36
37/* set the TFS IE to driver */
38static int ieee80211_11_set_tfs_ie(struct hostapd_data *hapd, const u8 *addr,
39 u8 *buf, u16 *buf_len, enum wnm_oper oper)
40{
41 wpa_printf(MSG_DEBUG, "%s: TFS set operation %d", __func__, oper);
42
43 return hostapd_drv_wnm_oper(hapd, oper, addr, buf, buf_len);
44}
45
46
47/* MLME-SLEEPMODE.response */
48static int ieee802_11_send_wnmsleep_resp(struct hostapd_data *hapd,
49 const u8 *addr, u8 dialog_token,
50 u8 action_type, u16 intval)
51{
52 struct ieee80211_mgmt *mgmt;
53 int res;
54 size_t len;
55 size_t gtk_elem_len = 0;
56 size_t igtk_elem_len = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -070057 size_t bigtk_elem_len = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070058 struct wnm_sleep_element wnmsleep_ie;
Hai Shalom74f70d42019-02-11 14:42:39 -080059 u8 *wnmtfs_ie, *oci_ie;
60 u8 wnmsleep_ie_len, oci_ie_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070061 u16 wnmtfs_ie_len;
62 u8 *pos;
63 struct sta_info *sta;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080064 enum wnm_oper tfs_oper = action_type == WNM_SLEEP_MODE_ENTER ?
65 WNM_SLEEP_TFS_RESP_IE_ADD : WNM_SLEEP_TFS_RESP_IE_NONE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070066
67 sta = ap_get_sta(hapd, addr);
68 if (sta == NULL) {
69 wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
70 return -EINVAL;
71 }
72
73 /* WNM-Sleep Mode IE */
74 os_memset(&wnmsleep_ie, 0, sizeof(struct wnm_sleep_element));
75 wnmsleep_ie_len = sizeof(struct wnm_sleep_element);
76 wnmsleep_ie.eid = WLAN_EID_WNMSLEEP;
77 wnmsleep_ie.len = wnmsleep_ie_len - 2;
78 wnmsleep_ie.action_type = action_type;
79 wnmsleep_ie.status = WNM_STATUS_SLEEP_ACCEPT;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080080 wnmsleep_ie.intval = host_to_le16(intval);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070081
82 /* TFS IE(s) */
83 wnmtfs_ie = os_zalloc(MAX_TFS_IE_LEN);
84 if (wnmtfs_ie == NULL)
85 return -1;
86 if (ieee80211_11_get_tfs_ie(hapd, addr, wnmtfs_ie, &wnmtfs_ie_len,
87 tfs_oper)) {
88 wnmtfs_ie_len = 0;
89 os_free(wnmtfs_ie);
90 wnmtfs_ie = NULL;
91 }
92
Hai Shalom74f70d42019-02-11 14:42:39 -080093 oci_ie = NULL;
94 oci_ie_len = 0;
95#ifdef CONFIG_OCV
96 if (action_type == WNM_SLEEP_MODE_EXIT &&
97 wpa_auth_uses_ocv(sta->wpa_sm)) {
98 struct wpa_channel_info ci;
99
100 if (hostapd_drv_channel_info(hapd, &ci) != 0) {
101 wpa_printf(MSG_WARNING,
102 "Failed to get channel info for OCI element in WNM-Sleep Mode frame");
103 os_free(wnmtfs_ie);
104 return -1;
105 }
Hai Shalom899fcc72020-10-19 14:38:18 -0700106#ifdef CONFIG_TESTING_OPTIONS
107 if (hapd->conf->oci_freq_override_wnm_sleep) {
108 wpa_printf(MSG_INFO,
109 "TEST: Override OCI frequency %d -> %u MHz",
110 ci.frequency,
111 hapd->conf->oci_freq_override_wnm_sleep);
112 ci.frequency = hapd->conf->oci_freq_override_wnm_sleep;
113 }
114#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalom74f70d42019-02-11 14:42:39 -0800115
116 oci_ie_len = OCV_OCI_EXTENDED_LEN;
117 oci_ie = os_zalloc(oci_ie_len);
118 if (!oci_ie) {
119 wpa_printf(MSG_WARNING,
120 "Failed to allocate buffer for OCI element in WNM-Sleep Mode frame");
121 os_free(wnmtfs_ie);
122 return -1;
123 }
124
125 if (ocv_insert_extended_oci(&ci, oci_ie) < 0) {
126 os_free(wnmtfs_ie);
127 os_free(oci_ie);
128 return -1;
129 }
130 }
131#endif /* CONFIG_OCV */
132
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700133#define MAX_GTK_SUBELEM_LEN 45
134#define MAX_IGTK_SUBELEM_LEN 26
Hai Shalomfdcde762020-04-02 11:19:20 -0700135#define MAX_BIGTK_SUBELEM_LEN 26
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700136 mgmt = os_zalloc(sizeof(*mgmt) + wnmsleep_ie_len +
Hai Shalom74f70d42019-02-11 14:42:39 -0800137 MAX_GTK_SUBELEM_LEN + MAX_IGTK_SUBELEM_LEN +
Hai Shalomfdcde762020-04-02 11:19:20 -0700138 MAX_BIGTK_SUBELEM_LEN +
Hai Shalom74f70d42019-02-11 14:42:39 -0800139 oci_ie_len);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700140 if (mgmt == NULL) {
141 wpa_printf(MSG_DEBUG, "MLME: Failed to allocate buffer for "
142 "WNM-Sleep Response action frame");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800143 res = -1;
144 goto fail;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700145 }
146 os_memcpy(mgmt->da, addr, ETH_ALEN);
147 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
148 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
149 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
150 WLAN_FC_STYPE_ACTION);
151 mgmt->u.action.category = WLAN_ACTION_WNM;
152 mgmt->u.action.u.wnm_sleep_resp.action = WNM_SLEEP_MODE_RESP;
153 mgmt->u.action.u.wnm_sleep_resp.dialogtoken = dialog_token;
154 pos = (u8 *)mgmt->u.action.u.wnm_sleep_resp.variable;
155 /* add key data if MFP is enabled */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800156 if (!wpa_auth_uses_mfp(sta->wpa_sm) ||
Roshan Pius3a1667e2018-07-03 15:17:14 -0700157 hapd->conf->wnm_sleep_mode_no_keys ||
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800158 action_type != WNM_SLEEP_MODE_EXIT) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700159 mgmt->u.action.u.wnm_sleep_resp.keydata_len = 0;
160 } else {
161 gtk_elem_len = wpa_wnmsleep_gtk_subelem(sta->wpa_sm, pos);
162 pos += gtk_elem_len;
163 wpa_printf(MSG_DEBUG, "Pass 4, gtk_len = %d",
164 (int) gtk_elem_len);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700165 res = wpa_wnmsleep_igtk_subelem(sta->wpa_sm, pos);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800166 if (res < 0)
167 goto fail;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700168 igtk_elem_len = res;
169 pos += igtk_elem_len;
170 wpa_printf(MSG_DEBUG, "Pass 4 igtk_len = %d",
171 (int) igtk_elem_len);
Hai Shalomfdcde762020-04-02 11:19:20 -0700172 if (hapd->conf->beacon_prot) {
173 res = wpa_wnmsleep_bigtk_subelem(sta->wpa_sm, pos);
174 if (res < 0)
175 goto fail;
176 bigtk_elem_len = res;
177 pos += bigtk_elem_len;
178 wpa_printf(MSG_DEBUG, "Pass 4 bigtk_len = %d",
179 (int) bigtk_elem_len);
180 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700181
182 WPA_PUT_LE16((u8 *)
183 &mgmt->u.action.u.wnm_sleep_resp.keydata_len,
Hai Shalomfdcde762020-04-02 11:19:20 -0700184 gtk_elem_len + igtk_elem_len + bigtk_elem_len);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700185 }
186 os_memcpy(pos, &wnmsleep_ie, wnmsleep_ie_len);
187 /* copy TFS IE here */
188 pos += wnmsleep_ie_len;
Hai Shalom74f70d42019-02-11 14:42:39 -0800189 if (wnmtfs_ie) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800190 os_memcpy(pos, wnmtfs_ie, wnmtfs_ie_len);
Hai Shalom74f70d42019-02-11 14:42:39 -0800191 pos += wnmtfs_ie_len;
192 }
193#ifdef CONFIG_OCV
194 /* copy OCV OCI here */
195 if (oci_ie_len > 0)
196 os_memcpy(pos, oci_ie, oci_ie_len);
197#endif /* CONFIG_OCV */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700198
199 len = 1 + sizeof(mgmt->u.action.u.wnm_sleep_resp) + gtk_elem_len +
Hai Shalomfdcde762020-04-02 11:19:20 -0700200 igtk_elem_len + bigtk_elem_len +
201 wnmsleep_ie_len + wnmtfs_ie_len + oci_ie_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700202
203 /* In driver, response frame should be forced to sent when STA is in
204 * PS mode */
205 res = hostapd_drv_send_action(hapd, hapd->iface->freq, 0,
206 mgmt->da, &mgmt->u.action.category, len);
207
208 if (!res) {
209 wpa_printf(MSG_DEBUG, "Successfully send WNM-Sleep Response "
210 "frame");
211
212 /* when entering wnmsleep
213 * 1. pause the node in driver
Hai Shalomfdcde762020-04-02 11:19:20 -0700214 * 2. mark the node so that AP won't update GTK/IGTK/BIGTK
215 * during WNM Sleep
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700216 */
217 if (wnmsleep_ie.status == WNM_STATUS_SLEEP_ACCEPT &&
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800218 wnmsleep_ie.action_type == WNM_SLEEP_MODE_ENTER) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800219 sta->flags |= WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700220 hostapd_drv_wnm_oper(hapd, WNM_SLEEP_ENTER_CONFIRM,
221 addr, NULL, NULL);
222 wpa_set_wnmsleep(sta->wpa_sm, 1);
223 }
224 /* when exiting wnmsleep
225 * 1. unmark the node
Hai Shalomfdcde762020-04-02 11:19:20 -0700226 * 2. start GTK/IGTK/BIGTK update if MFP is not used
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700227 * 3. unpause the node in driver
228 */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800229 if ((wnmsleep_ie.status == WNM_STATUS_SLEEP_ACCEPT ||
230 wnmsleep_ie.status ==
231 WNM_STATUS_SLEEP_EXIT_ACCEPT_GTK_UPDATE) &&
232 wnmsleep_ie.action_type == WNM_SLEEP_MODE_EXIT) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800233 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700234 wpa_set_wnmsleep(sta->wpa_sm, 0);
235 hostapd_drv_wnm_oper(hapd, WNM_SLEEP_EXIT_CONFIRM,
236 addr, NULL, NULL);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700237 if (!wpa_auth_uses_mfp(sta->wpa_sm) ||
238 hapd->conf->wnm_sleep_mode_no_keys)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700239 wpa_wnmsleep_rekey_gtk(sta->wpa_sm);
240 }
241 } else
242 wpa_printf(MSG_DEBUG, "Fail to send WNM-Sleep Response frame");
243
244#undef MAX_GTK_SUBELEM_LEN
245#undef MAX_IGTK_SUBELEM_LEN
Hai Shalomfdcde762020-04-02 11:19:20 -0700246#undef MAX_BIGTK_SUBELEM_LEN
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800247fail:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700248 os_free(wnmtfs_ie);
Hai Shalom74f70d42019-02-11 14:42:39 -0800249 os_free(oci_ie);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700250 os_free(mgmt);
251 return res;
252}
253
254
255static void ieee802_11_rx_wnmsleep_req(struct hostapd_data *hapd,
256 const u8 *addr, const u8 *frm, int len)
257{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800258 /* Dialog Token [1] | WNM-Sleep Mode IE | TFS Response IE */
259 const u8 *pos = frm;
260 u8 dialog_token;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700261 struct wnm_sleep_element *wnmsleep_ie = NULL;
262 /* multiple TFS Req IE (assuming consecutive) */
263 u8 *tfsreq_ie_start = NULL;
264 u8 *tfsreq_ie_end = NULL;
265 u16 tfsreq_ie_len = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -0800266#ifdef CONFIG_OCV
267 struct sta_info *sta;
268 const u8 *oci_ie = NULL;
269 u8 oci_ie_len = 0;
270#endif /* CONFIG_OCV */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700271
Roshan Pius3a1667e2018-07-03 15:17:14 -0700272 if (!hapd->conf->wnm_sleep_mode) {
273 wpa_printf(MSG_DEBUG, "Ignore WNM-Sleep Mode Request from "
274 MACSTR " since WNM-Sleep Mode is disabled",
275 MAC2STR(addr));
276 return;
277 }
278
Jouni Malinen83e54022018-10-29 20:48:07 +0200279 if (len < 1) {
280 wpa_printf(MSG_DEBUG,
281 "WNM: Ignore too short WNM-Sleep Mode Request from "
282 MACSTR, MAC2STR(addr));
283 return;
284 }
285
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800286 dialog_token = *pos++;
287 while (pos + 1 < frm + len) {
288 u8 ie_len = pos[1];
289 if (pos + 2 + ie_len > frm + len)
290 break;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800291 if (*pos == WLAN_EID_WNMSLEEP &&
292 ie_len >= (int) sizeof(*wnmsleep_ie) - 2)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800293 wnmsleep_ie = (struct wnm_sleep_element *) pos;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700294 else if (*pos == WLAN_EID_TFS_REQ) {
295 if (!tfsreq_ie_start)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800296 tfsreq_ie_start = (u8 *) pos;
297 tfsreq_ie_end = (u8 *) pos;
Hai Shalom74f70d42019-02-11 14:42:39 -0800298#ifdef CONFIG_OCV
299 } else if (*pos == WLAN_EID_EXTENSION && ie_len >= 1 &&
300 pos[2] == WLAN_EID_EXT_OCV_OCI) {
301 oci_ie = pos + 3;
302 oci_ie_len = ie_len - 1;
303#endif /* CONFIG_OCV */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700304 } else
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800305 wpa_printf(MSG_DEBUG, "WNM: EID %d not recognized",
306 *pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700307 pos += ie_len + 2;
308 }
309
310 if (!wnmsleep_ie) {
311 wpa_printf(MSG_DEBUG, "No WNM-Sleep IE found");
312 return;
313 }
314
Hai Shalom74f70d42019-02-11 14:42:39 -0800315#ifdef CONFIG_OCV
316 sta = ap_get_sta(hapd, addr);
317 if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_EXIT &&
318 sta && wpa_auth_uses_ocv(sta->wpa_sm)) {
319 struct wpa_channel_info ci;
320
321 if (hostapd_drv_channel_info(hapd, &ci) != 0) {
322 wpa_printf(MSG_WARNING,
323 "Failed to get channel info to validate received OCI in WNM-Sleep Mode frame");
324 return;
325 }
326
327 if (ocv_verify_tx_params(oci_ie, oci_ie_len, &ci,
328 channel_width_to_int(ci.chanwidth),
Hai Shalom899fcc72020-10-19 14:38:18 -0700329 ci.seg1_idx) != OCI_SUCCESS) {
330 wpa_msg(hapd, MSG_WARNING, "WNM: OCV failed: %s",
331 ocv_errorstr);
Hai Shalom74f70d42019-02-11 14:42:39 -0800332 return;
333 }
334 }
335#endif /* CONFIG_OCV */
336
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800337 if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_ENTER &&
338 tfsreq_ie_start && tfsreq_ie_end &&
339 tfsreq_ie_end - tfsreq_ie_start >= 0) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700340 tfsreq_ie_len = (tfsreq_ie_end + tfsreq_ie_end[1] + 2) -
341 tfsreq_ie_start;
342 wpa_printf(MSG_DEBUG, "TFS Req IE(s) found");
343 /* pass the TFS Req IE(s) to driver for processing */
344 if (ieee80211_11_set_tfs_ie(hapd, addr, tfsreq_ie_start,
345 &tfsreq_ie_len,
346 WNM_SLEEP_TFS_REQ_IE_SET))
347 wpa_printf(MSG_DEBUG, "Fail to set TFS Req IE");
348 }
349
350 ieee802_11_send_wnmsleep_resp(hapd, addr, dialog_token,
351 wnmsleep_ie->action_type,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800352 le_to_host16(wnmsleep_ie->intval));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700353
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800354 if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_EXIT) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700355 /* clear the tfs after sending the resp frame */
356 ieee80211_11_set_tfs_ie(hapd, addr, tfsreq_ie_start,
357 &tfsreq_ie_len, WNM_SLEEP_TFS_IE_DEL);
358 }
359}
360
361
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800362static int ieee802_11_send_bss_trans_mgmt_request(struct hostapd_data *hapd,
363 const u8 *addr,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800364 u8 dialog_token)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700365{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800366 struct ieee80211_mgmt *mgmt;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800367 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800368 u8 *pos;
369 int res;
370
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800371 mgmt = os_zalloc(sizeof(*mgmt));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800372 if (mgmt == NULL)
373 return -1;
374 os_memcpy(mgmt->da, addr, ETH_ALEN);
375 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
376 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
377 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
378 WLAN_FC_STYPE_ACTION);
379 mgmt->u.action.category = WLAN_ACTION_WNM;
380 mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
381 mgmt->u.action.u.bss_tm_req.dialog_token = dialog_token;
382 mgmt->u.action.u.bss_tm_req.req_mode = 0;
383 mgmt->u.action.u.bss_tm_req.disassoc_timer = host_to_le16(0);
384 mgmt->u.action.u.bss_tm_req.validity_interval = 1;
385 pos = mgmt->u.action.u.bss_tm_req.variable;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800386
387 wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request to "
388 MACSTR " dialog_token=%u req_mode=0x%x disassoc_timer=%u "
389 "validity_interval=%u",
390 MAC2STR(addr), dialog_token,
391 mgmt->u.action.u.bss_tm_req.req_mode,
392 le_to_host16(mgmt->u.action.u.bss_tm_req.disassoc_timer),
393 mgmt->u.action.u.bss_tm_req.validity_interval);
394
395 len = pos - &mgmt->u.action.category;
396 res = hostapd_drv_send_action(hapd, hapd->iface->freq, 0,
397 mgmt->da, &mgmt->u.action.category, len);
398 os_free(mgmt);
399 return res;
400}
401
402
403static void ieee802_11_rx_bss_trans_mgmt_query(struct hostapd_data *hapd,
404 const u8 *addr, const u8 *frm,
405 size_t len)
406{
407 u8 dialog_token, reason;
408 const u8 *pos, *end;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700409 int enabled = hapd->conf->bss_transition;
410
411#ifdef CONFIG_MBO
412 if (hapd->conf->mbo_enabled)
413 enabled = 1;
414#endif /* CONFIG_MBO */
415 if (!enabled) {
416 wpa_printf(MSG_DEBUG,
417 "Ignore BSS Transition Management Query from "
418 MACSTR
419 " since BSS Transition Management is disabled",
420 MAC2STR(addr));
421 return;
422 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800423
424 if (len < 2) {
425 wpa_printf(MSG_DEBUG, "WNM: Ignore too short BSS Transition Management Query from "
426 MACSTR, MAC2STR(addr));
427 return;
428 }
429
430 pos = frm;
431 end = pos + len;
432 dialog_token = *pos++;
433 reason = *pos++;
434
435 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management Query from "
436 MACSTR " dialog_token=%u reason=%u",
437 MAC2STR(addr), dialog_token, reason);
438
439 wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries",
440 pos, end - pos);
441
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800442 ieee802_11_send_bss_trans_mgmt_request(hapd, addr, dialog_token);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800443}
444
445
Roshan Pius3a1667e2018-07-03 15:17:14 -0700446void ap_sta_reset_steer_flag_timer(void *eloop_ctx, void *timeout_ctx)
447{
448 struct hostapd_data *hapd = eloop_ctx;
449 struct sta_info *sta = timeout_ctx;
450
451 if (sta->agreed_to_steer) {
452 wpa_printf(MSG_DEBUG, "%s: Reset steering flag for STA " MACSTR,
453 hapd->conf->iface, MAC2STR(sta->addr));
454 sta->agreed_to_steer = 0;
455 }
456}
457
458
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800459static void ieee802_11_rx_bss_trans_mgmt_resp(struct hostapd_data *hapd,
460 const u8 *addr, const u8 *frm,
461 size_t len)
462{
463 u8 dialog_token, status_code, bss_termination_delay;
464 const u8 *pos, *end;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700465 int enabled = hapd->conf->bss_transition;
466 struct sta_info *sta;
467
468#ifdef CONFIG_MBO
469 if (hapd->conf->mbo_enabled)
470 enabled = 1;
471#endif /* CONFIG_MBO */
472 if (!enabled) {
473 wpa_printf(MSG_DEBUG,
474 "Ignore BSS Transition Management Response from "
475 MACSTR
476 " since BSS Transition Management is disabled",
477 MAC2STR(addr));
478 return;
479 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800480
481 if (len < 3) {
482 wpa_printf(MSG_DEBUG, "WNM: Ignore too short BSS Transition Management Response from "
483 MACSTR, MAC2STR(addr));
484 return;
485 }
486
487 pos = frm;
488 end = pos + len;
489 dialog_token = *pos++;
490 status_code = *pos++;
491 bss_termination_delay = *pos++;
492
493 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management Response from "
494 MACSTR " dialog_token=%u status_code=%u "
495 "bss_termination_delay=%u", MAC2STR(addr), dialog_token,
496 status_code, bss_termination_delay);
497
Roshan Pius3a1667e2018-07-03 15:17:14 -0700498 sta = ap_get_sta(hapd, addr);
499 if (!sta) {
500 wpa_printf(MSG_DEBUG, "Station " MACSTR
501 " not found for received BSS TM Response",
502 MAC2STR(addr));
503 return;
504 }
505
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800506 if (status_code == WNM_BSS_TM_ACCEPT) {
507 if (end - pos < ETH_ALEN) {
508 wpa_printf(MSG_DEBUG, "WNM: not enough room for Target BSSID field");
509 return;
510 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700511 sta->agreed_to_steer = 1;
512 eloop_cancel_timeout(ap_sta_reset_steer_flag_timer, hapd, sta);
513 eloop_register_timeout(2, 0, ap_sta_reset_steer_flag_timer,
514 hapd, sta);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800515 wpa_printf(MSG_DEBUG, "WNM: Target BSSID: " MACSTR,
516 MAC2STR(pos));
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800517 wpa_msg(hapd->msg_ctx, MSG_INFO, BSS_TM_RESP MACSTR
518 " status_code=%u bss_termination_delay=%u target_bssid="
519 MACSTR,
520 MAC2STR(addr), status_code, bss_termination_delay,
521 MAC2STR(pos));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800522 pos += ETH_ALEN;
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800523 } else {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700524 sta->agreed_to_steer = 0;
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800525 wpa_msg(hapd->msg_ctx, MSG_INFO, BSS_TM_RESP MACSTR
526 " status_code=%u bss_termination_delay=%u",
527 MAC2STR(addr), status_code, bss_termination_delay);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800528 }
529
530 wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries",
531 pos, end - pos);
532}
533
534
Hai Shalomfdcde762020-04-02 11:19:20 -0700535static void wnm_beacon_protection_failure(struct hostapd_data *hapd,
536 const u8 *addr)
537{
538 struct sta_info *sta;
539
540 if (!hapd->conf->beacon_prot)
541 return;
542
543 sta = ap_get_sta(hapd, addr);
544 if (!sta || !(sta->flags & WLAN_STA_AUTHORIZED)) {
545 wpa_printf(MSG_DEBUG, "Station " MACSTR
546 " not found for received WNM-Notification Request",
547 MAC2STR(addr));
548 return;
549 }
550
551 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
552 HOSTAPD_LEVEL_INFO,
553 "Beacon protection failure reported");
554 wpa_msg(hapd->msg_ctx, MSG_INFO, WPA_EVENT_UNPROT_BEACON "reporter="
555 MACSTR, MAC2STR(addr));
556}
557
558
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800559static void ieee802_11_rx_wnm_notification_req(struct hostapd_data *hapd,
560 const u8 *addr, const u8 *buf,
561 size_t len)
562{
563 u8 dialog_token, type;
564
565 if (len < 2)
566 return;
567 dialog_token = *buf++;
568 type = *buf++;
569 len -= 2;
570
571 wpa_printf(MSG_DEBUG,
572 "WNM: Received WNM Notification Request frame from "
573 MACSTR " (dialog_token=%u type=%u)",
574 MAC2STR(addr), dialog_token, type);
575 wpa_hexdump(MSG_MSGDUMP, "WNM: Notification Request subelements",
576 buf, len);
Hai Shalomfdcde762020-04-02 11:19:20 -0700577 switch (type) {
578 case WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE:
579 wnm_beacon_protection_failure(hapd, addr);
580 break;
581 case WNM_NOTIF_TYPE_VENDOR_SPECIFIC:
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800582 mbo_ap_wnm_notification_req(hapd, addr, buf, len);
Hai Shalomfdcde762020-04-02 11:19:20 -0700583 break;
584 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800585}
586
587
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800588static void ieee802_11_rx_wnm_coloc_intf_report(struct hostapd_data *hapd,
589 const u8 *addr, const u8 *buf,
590 size_t len)
591{
592 u8 dialog_token;
593 char *hex;
594 size_t hex_len;
595
596 if (!hapd->conf->coloc_intf_reporting) {
597 wpa_printf(MSG_DEBUG,
598 "WNM: Ignore unexpected Collocated Interference Report from "
599 MACSTR, MAC2STR(addr));
600 return;
601 }
602
603 if (len < 1) {
604 wpa_printf(MSG_DEBUG,
605 "WNM: Ignore too short Collocated Interference Report from "
606 MACSTR, MAC2STR(addr));
607 return;
608 }
609 dialog_token = *buf++;
610 len--;
611
612 wpa_printf(MSG_DEBUG,
613 "WNM: Received Collocated Interference Report frame from "
614 MACSTR " (dialog_token=%u)",
615 MAC2STR(addr), dialog_token);
616 wpa_hexdump(MSG_MSGDUMP, "WNM: Collocated Interference Report Elements",
617 buf, len);
618
619 hex_len = 2 * len + 1;
620 hex = os_malloc(hex_len);
621 if (!hex)
622 return;
623 wpa_snprintf_hex(hex, hex_len, buf, len);
624 wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, COLOC_INTF_REPORT MACSTR " %d %s",
625 MAC2STR(addr), dialog_token, hex);
626 os_free(hex);
627}
628
629
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800630int ieee802_11_rx_wnm_action_ap(struct hostapd_data *hapd,
631 const struct ieee80211_mgmt *mgmt, size_t len)
632{
633 u8 action;
634 const u8 *payload;
635 size_t plen;
636
637 if (len < IEEE80211_HDRLEN + 2)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800638 return -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700639
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700640 payload = ((const u8 *) mgmt) + IEEE80211_HDRLEN + 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800641 action = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700642 plen = len - IEEE80211_HDRLEN - 2;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800643
644 switch (action) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800645 case WNM_BSS_TRANS_MGMT_QUERY:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800646 ieee802_11_rx_bss_trans_mgmt_query(hapd, mgmt->sa, payload,
647 plen);
648 return 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800649 case WNM_BSS_TRANS_MGMT_RESP:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800650 ieee802_11_rx_bss_trans_mgmt_resp(hapd, mgmt->sa, payload,
651 plen);
652 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700653 case WNM_SLEEP_MODE_REQ:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800654 ieee802_11_rx_wnmsleep_req(hapd, mgmt->sa, payload, plen);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800655 return 0;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800656 case WNM_NOTIFICATION_REQ:
657 ieee802_11_rx_wnm_notification_req(hapd, mgmt->sa, payload,
658 plen);
659 return 0;
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800660 case WNM_COLLOCATED_INTERFERENCE_REPORT:
661 ieee802_11_rx_wnm_coloc_intf_report(hapd, mgmt->sa, payload,
662 plen);
663 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700664 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700665
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800666 wpa_printf(MSG_DEBUG, "WNM: Unsupported WNM Action %u from " MACSTR,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800667 action, MAC2STR(mgmt->sa));
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800668 return -1;
669}
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800670
671
672int wnm_send_disassoc_imminent(struct hostapd_data *hapd,
673 struct sta_info *sta, int disassoc_timer)
674{
675 u8 buf[1000], *pos;
676 struct ieee80211_mgmt *mgmt;
677
678 os_memset(buf, 0, sizeof(buf));
679 mgmt = (struct ieee80211_mgmt *) buf;
680 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
681 WLAN_FC_STYPE_ACTION);
682 os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
683 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
684 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
685 mgmt->u.action.category = WLAN_ACTION_WNM;
686 mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
687 mgmt->u.action.u.bss_tm_req.dialog_token = 1;
688 mgmt->u.action.u.bss_tm_req.req_mode =
689 WNM_BSS_TM_REQ_DISASSOC_IMMINENT;
690 mgmt->u.action.u.bss_tm_req.disassoc_timer =
691 host_to_le16(disassoc_timer);
692 mgmt->u.action.u.bss_tm_req.validity_interval = 0;
693
694 pos = mgmt->u.action.u.bss_tm_req.variable;
695
696 wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request frame to indicate imminent disassociation (disassoc_timer=%d) to "
697 MACSTR, disassoc_timer, MAC2STR(sta->addr));
Hai Shalomfdcde762020-04-02 11:19:20 -0700698 if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0, NULL, 0, 0) < 0) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800699 wpa_printf(MSG_DEBUG, "Failed to send BSS Transition "
700 "Management Request frame");
701 return -1;
702 }
703
704 return 0;
705}
706
707
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800708static void set_disassoc_timer(struct hostapd_data *hapd, struct sta_info *sta,
709 int disassoc_timer)
710{
711 int timeout, beacon_int;
712
713 /*
714 * Prevent STA from reconnecting using cached PMKSA to force
715 * full authentication with the authentication server (which may
716 * decide to reject the connection),
717 */
718 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
719
720 beacon_int = hapd->iconf->beacon_int;
721 if (beacon_int < 1)
722 beacon_int = 100; /* best guess */
723 /* Calculate timeout in ms based on beacon_int in TU */
724 timeout = disassoc_timer * beacon_int * 128 / 125;
725 wpa_printf(MSG_DEBUG, "Disassociation timer for " MACSTR
726 " set to %d ms", MAC2STR(sta->addr), timeout);
727
728 sta->timeout_next = STA_DISASSOC_FROM_CLI;
729 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
730 eloop_register_timeout(timeout / 1000,
731 timeout % 1000 * 1000,
732 ap_handle_timer, hapd, sta);
733}
734
735
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800736int wnm_send_ess_disassoc_imminent(struct hostapd_data *hapd,
737 struct sta_info *sta, const char *url,
738 int disassoc_timer)
739{
740 u8 buf[1000], *pos;
741 struct ieee80211_mgmt *mgmt;
742 size_t url_len;
743
744 os_memset(buf, 0, sizeof(buf));
745 mgmt = (struct ieee80211_mgmt *) buf;
746 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
747 WLAN_FC_STYPE_ACTION);
748 os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
749 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
750 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
751 mgmt->u.action.category = WLAN_ACTION_WNM;
752 mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
753 mgmt->u.action.u.bss_tm_req.dialog_token = 1;
754 mgmt->u.action.u.bss_tm_req.req_mode =
755 WNM_BSS_TM_REQ_DISASSOC_IMMINENT |
756 WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT;
757 mgmt->u.action.u.bss_tm_req.disassoc_timer =
758 host_to_le16(disassoc_timer);
759 mgmt->u.action.u.bss_tm_req.validity_interval = 0x01;
760
761 pos = mgmt->u.action.u.bss_tm_req.variable;
762
763 /* Session Information URL */
764 url_len = os_strlen(url);
765 if (url_len > 255)
766 return -1;
767 *pos++ = url_len;
768 os_memcpy(pos, url, url_len);
769 pos += url_len;
770
Hai Shalomfdcde762020-04-02 11:19:20 -0700771 if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0, NULL, 0, 0) < 0) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800772 wpa_printf(MSG_DEBUG, "Failed to send BSS Transition "
773 "Management Request frame");
774 return -1;
775 }
776
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800777 if (disassoc_timer) {
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800778 /* send disassociation frame after time-out */
779 set_disassoc_timer(hapd, sta, disassoc_timer);
780 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800781
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800782 return 0;
783}
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800784
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800785
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800786int wnm_send_bss_tm_req(struct hostapd_data *hapd, struct sta_info *sta,
787 u8 req_mode, int disassoc_timer, u8 valid_int,
788 const u8 *bss_term_dur, const char *url,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800789 const u8 *nei_rep, size_t nei_rep_len,
790 const u8 *mbo_attrs, size_t mbo_len)
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800791{
792 u8 *buf, *pos;
793 struct ieee80211_mgmt *mgmt;
794 size_t url_len;
795
796 wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request to "
797 MACSTR " req_mode=0x%x disassoc_timer=%d valid_int=0x%x",
798 MAC2STR(sta->addr), req_mode, disassoc_timer, valid_int);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800799 buf = os_zalloc(1000 + nei_rep_len + mbo_len);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800800 if (buf == NULL)
801 return -1;
802 mgmt = (struct ieee80211_mgmt *) buf;
803 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
804 WLAN_FC_STYPE_ACTION);
805 os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
806 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
807 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
808 mgmt->u.action.category = WLAN_ACTION_WNM;
809 mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
810 mgmt->u.action.u.bss_tm_req.dialog_token = 1;
811 mgmt->u.action.u.bss_tm_req.req_mode = req_mode;
812 mgmt->u.action.u.bss_tm_req.disassoc_timer =
813 host_to_le16(disassoc_timer);
814 mgmt->u.action.u.bss_tm_req.validity_interval = valid_int;
815
816 pos = mgmt->u.action.u.bss_tm_req.variable;
817
818 if ((req_mode & WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED) &&
819 bss_term_dur) {
820 os_memcpy(pos, bss_term_dur, 12);
821 pos += 12;
822 }
823
824 if (url) {
825 /* Session Information URL */
826 url_len = os_strlen(url);
Dmitry Shmidt432d6032015-01-21 13:19:05 -0800827 if (url_len > 255) {
828 os_free(buf);
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800829 return -1;
Dmitry Shmidt432d6032015-01-21 13:19:05 -0800830 }
831
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800832 *pos++ = url_len;
833 os_memcpy(pos, url, url_len);
834 pos += url_len;
835 }
836
837 if (nei_rep) {
838 os_memcpy(pos, nei_rep, nei_rep_len);
839 pos += nei_rep_len;
840 }
841
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800842 if (mbo_len > 0) {
843 pos += mbo_add_ie(pos, buf + sizeof(buf) - pos, mbo_attrs,
844 mbo_len);
845 }
846
Hai Shalomfdcde762020-04-02 11:19:20 -0700847 if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0, NULL, 0, 0) < 0) {
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800848 wpa_printf(MSG_DEBUG,
849 "Failed to send BSS Transition Management Request frame");
850 os_free(buf);
851 return -1;
852 }
853 os_free(buf);
854
855 if (disassoc_timer) {
856 /* send disassociation frame after time-out */
857 set_disassoc_timer(hapd, sta, disassoc_timer);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800858 }
859
860 return 0;
861}
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800862
863
864int wnm_send_coloc_intf_req(struct hostapd_data *hapd, struct sta_info *sta,
865 unsigned int auto_report, unsigned int timeout)
866{
867 u8 buf[100], *pos;
868 struct ieee80211_mgmt *mgmt;
869 u8 dialog_token = 1;
870
871 if (auto_report > 3 || timeout > 63)
872 return -1;
873 os_memset(buf, 0, sizeof(buf));
874 mgmt = (struct ieee80211_mgmt *) buf;
875 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
876 WLAN_FC_STYPE_ACTION);
877 os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
878 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
879 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
880 mgmt->u.action.category = WLAN_ACTION_WNM;
881 mgmt->u.action.u.coloc_intf_req.action =
882 WNM_COLLOCATED_INTERFERENCE_REQ;
883 mgmt->u.action.u.coloc_intf_req.dialog_token = dialog_token;
884 mgmt->u.action.u.coloc_intf_req.req_info = auto_report | (timeout << 2);
885 pos = &mgmt->u.action.u.coloc_intf_req.req_info;
886 pos++;
887
888 wpa_printf(MSG_DEBUG, "WNM: Sending Collocated Interference Request to "
889 MACSTR " (dialog_token=%u auto_report=%u timeout=%u)",
890 MAC2STR(sta->addr), dialog_token, auto_report, timeout);
Hai Shalomfdcde762020-04-02 11:19:20 -0700891 if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0, NULL, 0, 0) < 0) {
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800892 wpa_printf(MSG_DEBUG,
893 "WNM: Failed to send Collocated Interference Request frame");
894 return -1;
895 }
896
897 return 0;
898}