• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * hostapd - WNM
3  * Copyright (c) 2011-2014, Qualcomm Atheros, Inc.
4  *
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"
12 #include "utils/eloop.h"
13 #include "common/ieee802_11_defs.h"
14 #include "common/wpa_ctrl.h"
15 #include "common/ocv.h"
16 #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"
21 #include "mbo_ap.h"
22 #include "wnm_ap.h"
23 
24 #define MAX_TFS_IE_LEN  1024
25 
26 
27 /* get the TFS IE from driver */
ieee80211_11_get_tfs_ie(struct hostapd_data * hapd,const u8 * addr,u8 * buf,u16 * buf_len,enum wnm_oper oper)28 static 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 */
ieee80211_11_set_tfs_ie(struct hostapd_data * hapd,const u8 * addr,u8 * buf,u16 * buf_len,enum wnm_oper oper)38 static 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 */
ieee802_11_send_wnmsleep_resp(struct hostapd_data * hapd,const u8 * addr,u8 dialog_token,u8 action_type,u16 intval)48 static 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;
57 	size_t bigtk_elem_len = 0;
58 	struct wnm_sleep_element wnmsleep_ie;
59 	u8 *wnmtfs_ie, *oci_ie;
60 	u8 wnmsleep_ie_len, oci_ie_len;
61 	u16 wnmtfs_ie_len;
62 	u8 *pos;
63 	struct sta_info *sta;
64 	enum wnm_oper tfs_oper = action_type == WNM_SLEEP_MODE_ENTER ?
65 		WNM_SLEEP_TFS_RESP_IE_ADD : WNM_SLEEP_TFS_RESP_IE_NONE;
66 
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;
80 	wnmsleep_ie.intval = host_to_le16(intval);
81 
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 
93 	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 		}
106 #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 */
115 
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 
133 #define MAX_GTK_SUBELEM_LEN 45
134 #define MAX_IGTK_SUBELEM_LEN 26
135 #define MAX_BIGTK_SUBELEM_LEN 26
136 	mgmt = os_zalloc(sizeof(*mgmt) + wnmsleep_ie_len +
137 			 MAX_GTK_SUBELEM_LEN + MAX_IGTK_SUBELEM_LEN +
138 			 MAX_BIGTK_SUBELEM_LEN +
139 			 oci_ie_len);
140 	if (mgmt == NULL) {
141 		wpa_printf(MSG_DEBUG, "MLME: Failed to allocate buffer for "
142 			   "WNM-Sleep Response action frame");
143 		res = -1;
144 		goto fail;
145 	}
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 */
156 	if (!wpa_auth_uses_mfp(sta->wpa_sm) ||
157 	    hapd->conf->wnm_sleep_mode_no_keys ||
158 	    action_type != WNM_SLEEP_MODE_EXIT) {
159 		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);
165 		res = wpa_wnmsleep_igtk_subelem(sta->wpa_sm, pos);
166 		if (res < 0)
167 			goto fail;
168 		igtk_elem_len = res;
169 		pos += igtk_elem_len;
170 		wpa_printf(MSG_DEBUG, "Pass 4 igtk_len = %d",
171 			   (int) igtk_elem_len);
172 		if (hapd->conf->beacon_prot &&
173 		    (hapd->iface->drv_flags &
174 		     WPA_DRIVER_FLAGS_BEACON_PROTECTION)) {
175 			res = wpa_wnmsleep_bigtk_subelem(sta->wpa_sm, pos);
176 			if (res < 0)
177 				goto fail;
178 			bigtk_elem_len = res;
179 			pos += bigtk_elem_len;
180 			wpa_printf(MSG_DEBUG, "Pass 4 bigtk_len = %d",
181 				   (int) bigtk_elem_len);
182 		}
183 
184 		WPA_PUT_LE16((u8 *)
185 			     &mgmt->u.action.u.wnm_sleep_resp.keydata_len,
186 			     gtk_elem_len + igtk_elem_len + bigtk_elem_len);
187 	}
188 	os_memcpy(pos, &wnmsleep_ie, wnmsleep_ie_len);
189 	/* copy TFS IE here */
190 	pos += wnmsleep_ie_len;
191 	if (wnmtfs_ie) {
192 		os_memcpy(pos, wnmtfs_ie, wnmtfs_ie_len);
193 		pos += wnmtfs_ie_len;
194 	}
195 #ifdef CONFIG_OCV
196 	/* copy OCV OCI here */
197 	if (oci_ie_len > 0)
198 		os_memcpy(pos, oci_ie, oci_ie_len);
199 #endif /* CONFIG_OCV */
200 
201 	len = 1 + sizeof(mgmt->u.action.u.wnm_sleep_resp) + gtk_elem_len +
202 		igtk_elem_len + bigtk_elem_len +
203 		wnmsleep_ie_len + wnmtfs_ie_len + oci_ie_len;
204 
205 	/* In driver, response frame should be forced to sent when STA is in
206 	 * PS mode */
207 	res = hostapd_drv_send_action(hapd, hapd->iface->freq, 0,
208 				      mgmt->da, &mgmt->u.action.category, len);
209 
210 	if (!res) {
211 		wpa_printf(MSG_DEBUG, "Successfully send WNM-Sleep Response "
212 			   "frame");
213 
214 		/* when entering wnmsleep
215 		 * 1. pause the node in driver
216 		 * 2. mark the node so that AP won't update GTK/IGTK/BIGTK
217 		 * during WNM Sleep
218 		 */
219 		if (wnmsleep_ie.status == WNM_STATUS_SLEEP_ACCEPT &&
220 		    wnmsleep_ie.action_type == WNM_SLEEP_MODE_ENTER) {
221 			sta->flags |= WLAN_STA_WNM_SLEEP_MODE;
222 			hostapd_drv_wnm_oper(hapd, WNM_SLEEP_ENTER_CONFIRM,
223 					     addr, NULL, NULL);
224 			wpa_set_wnmsleep(sta->wpa_sm, 1);
225 		}
226 		/* when exiting wnmsleep
227 		 * 1. unmark the node
228 		 * 2. start GTK/IGTK/BIGTK update if MFP is not used
229 		 * 3. unpause the node in driver
230 		 */
231 		if ((wnmsleep_ie.status == WNM_STATUS_SLEEP_ACCEPT ||
232 		     wnmsleep_ie.status ==
233 		     WNM_STATUS_SLEEP_EXIT_ACCEPT_GTK_UPDATE) &&
234 		    wnmsleep_ie.action_type == WNM_SLEEP_MODE_EXIT) {
235 			sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
236 			wpa_set_wnmsleep(sta->wpa_sm, 0);
237 			hostapd_drv_wnm_oper(hapd, WNM_SLEEP_EXIT_CONFIRM,
238 					     addr, NULL, NULL);
239 			if (!wpa_auth_uses_mfp(sta->wpa_sm) ||
240 			    hapd->conf->wnm_sleep_mode_no_keys)
241 				wpa_wnmsleep_rekey_gtk(sta->wpa_sm);
242 		}
243 	} else
244 		wpa_printf(MSG_DEBUG, "Fail to send WNM-Sleep Response frame");
245 
246 #undef MAX_GTK_SUBELEM_LEN
247 #undef MAX_IGTK_SUBELEM_LEN
248 #undef MAX_BIGTK_SUBELEM_LEN
249 fail:
250 	os_free(wnmtfs_ie);
251 	os_free(oci_ie);
252 	os_free(mgmt);
253 	return res;
254 }
255 
256 
ieee802_11_rx_wnmsleep_req(struct hostapd_data * hapd,const u8 * addr,const u8 * frm,int len)257 static void ieee802_11_rx_wnmsleep_req(struct hostapd_data *hapd,
258 				       const u8 *addr, const u8 *frm, int len)
259 {
260 	/* Dialog Token [1] | WNM-Sleep Mode IE | TFS Response IE */
261 	const u8 *pos = frm;
262 	u8 dialog_token;
263 	struct wnm_sleep_element *wnmsleep_ie = NULL;
264 	/* multiple TFS Req IE (assuming consecutive) */
265 	u8 *tfsreq_ie_start = NULL;
266 	u8 *tfsreq_ie_end = NULL;
267 	u16 tfsreq_ie_len = 0;
268 #ifdef CONFIG_OCV
269 	struct sta_info *sta;
270 	const u8 *oci_ie = NULL;
271 	u8 oci_ie_len = 0;
272 #endif /* CONFIG_OCV */
273 
274 	if (!hapd->conf->wnm_sleep_mode) {
275 		wpa_printf(MSG_DEBUG, "Ignore WNM-Sleep Mode Request from "
276 			   MACSTR " since WNM-Sleep Mode is disabled",
277 			   MAC2STR(addr));
278 		return;
279 	}
280 
281 	if (len < 1) {
282 		wpa_printf(MSG_DEBUG,
283 			   "WNM: Ignore too short WNM-Sleep Mode Request from "
284 			   MACSTR, MAC2STR(addr));
285 		return;
286 	}
287 
288 	dialog_token = *pos++;
289 	while (pos + 1 < frm + len) {
290 		u8 ie_len = pos[1];
291 		if (pos + 2 + ie_len > frm + len)
292 			break;
293 		if (*pos == WLAN_EID_WNMSLEEP &&
294 		    ie_len >= (int) sizeof(*wnmsleep_ie) - 2)
295 			wnmsleep_ie = (struct wnm_sleep_element *) pos;
296 		else if (*pos == WLAN_EID_TFS_REQ) {
297 			if (!tfsreq_ie_start)
298 				tfsreq_ie_start = (u8 *) pos;
299 			tfsreq_ie_end = (u8 *) pos;
300 #ifdef CONFIG_OCV
301 		} else if (*pos == WLAN_EID_EXTENSION && ie_len >= 1 &&
302 			   pos[2] == WLAN_EID_EXT_OCV_OCI) {
303 			oci_ie = pos + 3;
304 			oci_ie_len = ie_len - 1;
305 #endif /* CONFIG_OCV */
306 		} else
307 			wpa_printf(MSG_DEBUG, "WNM: EID %d not recognized",
308 				   *pos);
309 		pos += ie_len + 2;
310 	}
311 
312 	if (!wnmsleep_ie) {
313 		wpa_printf(MSG_DEBUG, "No WNM-Sleep IE found");
314 		return;
315 	}
316 
317 #ifdef CONFIG_OCV
318 	sta = ap_get_sta(hapd, addr);
319 	if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_EXIT &&
320 	    sta && wpa_auth_uses_ocv(sta->wpa_sm)) {
321 		struct wpa_channel_info ci;
322 
323 		if (hostapd_drv_channel_info(hapd, &ci) != 0) {
324 			wpa_printf(MSG_WARNING,
325 				   "Failed to get channel info to validate received OCI in WNM-Sleep Mode frame");
326 			return;
327 		}
328 
329 		if (ocv_verify_tx_params(oci_ie, oci_ie_len, &ci,
330 					 channel_width_to_int(ci.chanwidth),
331 					 ci.seg1_idx) != OCI_SUCCESS) {
332 			wpa_msg(hapd, MSG_WARNING, "WNM: OCV failed: %s",
333 				ocv_errorstr);
334 			return;
335 		}
336 	}
337 #endif /* CONFIG_OCV */
338 
339 	if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_ENTER &&
340 	    tfsreq_ie_start && tfsreq_ie_end &&
341 	    tfsreq_ie_end - tfsreq_ie_start >= 0) {
342 		tfsreq_ie_len = (tfsreq_ie_end + tfsreq_ie_end[1] + 2) -
343 			tfsreq_ie_start;
344 		wpa_printf(MSG_DEBUG, "TFS Req IE(s) found");
345 		/* pass the TFS Req IE(s) to driver for processing */
346 		if (ieee80211_11_set_tfs_ie(hapd, addr, tfsreq_ie_start,
347 					    &tfsreq_ie_len,
348 					    WNM_SLEEP_TFS_REQ_IE_SET))
349 			wpa_printf(MSG_DEBUG, "Fail to set TFS Req IE");
350 	}
351 
352 	ieee802_11_send_wnmsleep_resp(hapd, addr, dialog_token,
353 				      wnmsleep_ie->action_type,
354 				      le_to_host16(wnmsleep_ie->intval));
355 
356 	if (wnmsleep_ie->action_type == WNM_SLEEP_MODE_EXIT) {
357 		/* clear the tfs after sending the resp frame */
358 		ieee80211_11_set_tfs_ie(hapd, addr, tfsreq_ie_start,
359 					&tfsreq_ie_len, WNM_SLEEP_TFS_IE_DEL);
360 	}
361 }
362 
363 
ieee802_11_send_bss_trans_mgmt_request(struct hostapd_data * hapd,const u8 * addr,u8 dialog_token)364 static int ieee802_11_send_bss_trans_mgmt_request(struct hostapd_data *hapd,
365 						  const u8 *addr,
366 						  u8 dialog_token)
367 {
368 	struct ieee80211_mgmt *mgmt;
369 	size_t len;
370 	u8 *pos;
371 	int res;
372 
373 	mgmt = os_zalloc(sizeof(*mgmt));
374 	if (mgmt == NULL)
375 		return -1;
376 	os_memcpy(mgmt->da, addr, ETH_ALEN);
377 	os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
378 	os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
379 	mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
380 					   WLAN_FC_STYPE_ACTION);
381 	mgmt->u.action.category = WLAN_ACTION_WNM;
382 	mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
383 	mgmt->u.action.u.bss_tm_req.dialog_token = dialog_token;
384 	mgmt->u.action.u.bss_tm_req.req_mode = 0;
385 	mgmt->u.action.u.bss_tm_req.disassoc_timer = host_to_le16(0);
386 	mgmt->u.action.u.bss_tm_req.validity_interval = 1;
387 	pos = mgmt->u.action.u.bss_tm_req.variable;
388 
389 	wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request to "
390 		   MACSTR " dialog_token=%u req_mode=0x%x disassoc_timer=%u "
391 		   "validity_interval=%u",
392 		   MAC2STR(addr), dialog_token,
393 		   mgmt->u.action.u.bss_tm_req.req_mode,
394 		   le_to_host16(mgmt->u.action.u.bss_tm_req.disassoc_timer),
395 		   mgmt->u.action.u.bss_tm_req.validity_interval);
396 
397 	len = pos - &mgmt->u.action.category;
398 	res = hostapd_drv_send_action(hapd, hapd->iface->freq, 0,
399 				      mgmt->da, &mgmt->u.action.category, len);
400 	os_free(mgmt);
401 	return res;
402 }
403 
404 
ieee802_11_rx_bss_trans_mgmt_query(struct hostapd_data * hapd,const u8 * addr,const u8 * frm,size_t len)405 static void ieee802_11_rx_bss_trans_mgmt_query(struct hostapd_data *hapd,
406 					       const u8 *addr, const u8 *frm,
407 					       size_t len)
408 {
409 	u8 dialog_token, reason;
410 	const u8 *pos, *end;
411 	int enabled = hapd->conf->bss_transition;
412 	char *hex = NULL;
413 	size_t hex_len;
414 
415 #ifdef CONFIG_MBO
416 	if (hapd->conf->mbo_enabled)
417 		enabled = 1;
418 #endif /* CONFIG_MBO */
419 	if (!enabled) {
420 		wpa_printf(MSG_DEBUG,
421 			   "Ignore BSS Transition Management Query from "
422 			   MACSTR
423 			   " since BSS Transition Management is disabled",
424 			   MAC2STR(addr));
425 		return;
426 	}
427 
428 	if (len < 2) {
429 		wpa_printf(MSG_DEBUG, "WNM: Ignore too short BSS Transition Management Query from "
430 			   MACSTR, MAC2STR(addr));
431 		return;
432 	}
433 
434 	pos = frm;
435 	end = pos + len;
436 	dialog_token = *pos++;
437 	reason = *pos++;
438 
439 	wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management Query from "
440 		   MACSTR " dialog_token=%u reason=%u",
441 		   MAC2STR(addr), dialog_token, reason);
442 
443 	wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries",
444 		    pos, end - pos);
445 
446 	hex_len = 2 * (end - pos) + 1;
447 	if (hex_len > 1) {
448 		hex = os_malloc(hex_len);
449 		if (hex)
450 			wpa_snprintf_hex(hex, hex_len, pos, end - pos);
451 	}
452 	wpa_msg(hapd->msg_ctx, MSG_INFO,
453 		BSS_TM_QUERY MACSTR " reason=%u%s%s",
454 		MAC2STR(addr), reason, hex ? " neighbor=" : "", hex);
455 	os_free(hex);
456 
457 	ieee802_11_send_bss_trans_mgmt_request(hapd, addr, dialog_token);
458 }
459 
460 
ap_sta_reset_steer_flag_timer(void * eloop_ctx,void * timeout_ctx)461 void ap_sta_reset_steer_flag_timer(void *eloop_ctx, void *timeout_ctx)
462 {
463 	struct hostapd_data *hapd = eloop_ctx;
464 	struct sta_info *sta = timeout_ctx;
465 
466 	if (sta->agreed_to_steer) {
467 		wpa_printf(MSG_DEBUG, "%s: Reset steering flag for STA " MACSTR,
468 			   hapd->conf->iface, MAC2STR(sta->addr));
469 		sta->agreed_to_steer = 0;
470 	}
471 }
472 
473 
ieee802_11_rx_bss_trans_mgmt_resp(struct hostapd_data * hapd,const u8 * addr,const u8 * frm,size_t len)474 static void ieee802_11_rx_bss_trans_mgmt_resp(struct hostapd_data *hapd,
475 					      const u8 *addr, const u8 *frm,
476 					      size_t len)
477 {
478 	u8 dialog_token, status_code, bss_termination_delay;
479 	const u8 *pos, *end;
480 	int enabled = hapd->conf->bss_transition;
481 	struct sta_info *sta;
482 
483 #ifdef CONFIG_MBO
484 	if (hapd->conf->mbo_enabled)
485 		enabled = 1;
486 #endif /* CONFIG_MBO */
487 	if (!enabled) {
488 		wpa_printf(MSG_DEBUG,
489 			   "Ignore BSS Transition Management Response from "
490 			   MACSTR
491 			   " since BSS Transition Management is disabled",
492 			   MAC2STR(addr));
493 		return;
494 	}
495 
496 	if (len < 3) {
497 		wpa_printf(MSG_DEBUG, "WNM: Ignore too short BSS Transition Management Response from "
498 			   MACSTR, MAC2STR(addr));
499 		return;
500 	}
501 
502 	pos = frm;
503 	end = pos + len;
504 	dialog_token = *pos++;
505 	status_code = *pos++;
506 	bss_termination_delay = *pos++;
507 
508 	wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management Response from "
509 		   MACSTR " dialog_token=%u status_code=%u "
510 		   "bss_termination_delay=%u", MAC2STR(addr), dialog_token,
511 		   status_code, bss_termination_delay);
512 
513 	sta = ap_get_sta(hapd, addr);
514 	if (!sta) {
515 		wpa_printf(MSG_DEBUG, "Station " MACSTR
516 			   " not found for received BSS TM Response",
517 			   MAC2STR(addr));
518 		return;
519 	}
520 
521 	if (status_code == WNM_BSS_TM_ACCEPT) {
522 		if (end - pos < ETH_ALEN) {
523 			wpa_printf(MSG_DEBUG, "WNM: not enough room for Target BSSID field");
524 			return;
525 		}
526 		sta->agreed_to_steer = 1;
527 		eloop_cancel_timeout(ap_sta_reset_steer_flag_timer, hapd, sta);
528 		eloop_register_timeout(2, 0, ap_sta_reset_steer_flag_timer,
529 				       hapd, sta);
530 		wpa_printf(MSG_DEBUG, "WNM: Target BSSID: " MACSTR,
531 			   MAC2STR(pos));
532 		wpa_msg(hapd->msg_ctx, MSG_INFO, BSS_TM_RESP MACSTR
533 			" status_code=%u bss_termination_delay=%u target_bssid="
534 			MACSTR,
535 			MAC2STR(addr), status_code, bss_termination_delay,
536 			MAC2STR(pos));
537 		pos += ETH_ALEN;
538 	} else {
539 		sta->agreed_to_steer = 0;
540 		wpa_msg(hapd->msg_ctx, MSG_INFO, BSS_TM_RESP MACSTR
541 			" status_code=%u bss_termination_delay=%u",
542 			MAC2STR(addr), status_code, bss_termination_delay);
543 	}
544 
545 	wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries",
546 		    pos, end - pos);
547 }
548 
549 
wnm_beacon_protection_failure(struct hostapd_data * hapd,const u8 * addr)550 static void wnm_beacon_protection_failure(struct hostapd_data *hapd,
551 					  const u8 *addr)
552 {
553 	struct sta_info *sta;
554 
555 	if (!hapd->conf->beacon_prot ||
556 	    !(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_BEACON_PROTECTION))
557 		return;
558 
559 	sta = ap_get_sta(hapd, addr);
560 	if (!sta || !(sta->flags & WLAN_STA_AUTHORIZED)) {
561 		wpa_printf(MSG_DEBUG, "Station " MACSTR
562 			   " not found for received WNM-Notification Request",
563 			   MAC2STR(addr));
564 		return;
565 	}
566 
567 	hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
568 		       HOSTAPD_LEVEL_INFO,
569 		       "Beacon protection failure reported");
570 	wpa_msg(hapd->msg_ctx, MSG_INFO, WPA_EVENT_UNPROT_BEACON "reporter="
571 		MACSTR, MAC2STR(addr));
572 }
573 
574 
ieee802_11_rx_wnm_notification_req(struct hostapd_data * hapd,const u8 * addr,const u8 * buf,size_t len)575 static void ieee802_11_rx_wnm_notification_req(struct hostapd_data *hapd,
576 					       const u8 *addr, const u8 *buf,
577 					       size_t len)
578 {
579 	u8 dialog_token, type;
580 
581 	if (len < 2)
582 		return;
583 	dialog_token = *buf++;
584 	type = *buf++;
585 	len -= 2;
586 
587 	wpa_printf(MSG_DEBUG,
588 		   "WNM: Received WNM Notification Request frame from "
589 		   MACSTR " (dialog_token=%u type=%u)",
590 		   MAC2STR(addr), dialog_token, type);
591 	wpa_hexdump(MSG_MSGDUMP, "WNM: Notification Request subelements",
592 		    buf, len);
593 	switch (type) {
594 	case WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE:
595 		wnm_beacon_protection_failure(hapd, addr);
596 		break;
597 	case WNM_NOTIF_TYPE_VENDOR_SPECIFIC:
598 		mbo_ap_wnm_notification_req(hapd, addr, buf, len);
599 		break;
600 	}
601 }
602 
603 
ieee802_11_rx_wnm_coloc_intf_report(struct hostapd_data * hapd,const u8 * addr,const u8 * buf,size_t len)604 static void ieee802_11_rx_wnm_coloc_intf_report(struct hostapd_data *hapd,
605 						const u8 *addr, const u8 *buf,
606 						size_t len)
607 {
608 	u8 dialog_token;
609 	char *hex;
610 	size_t hex_len;
611 
612 	if (!hapd->conf->coloc_intf_reporting) {
613 		wpa_printf(MSG_DEBUG,
614 			   "WNM: Ignore unexpected Collocated Interference Report from "
615 			   MACSTR, MAC2STR(addr));
616 		return;
617 	}
618 
619 	if (len < 1) {
620 		wpa_printf(MSG_DEBUG,
621 			   "WNM: Ignore too short Collocated Interference Report from "
622 			   MACSTR, MAC2STR(addr));
623 		return;
624 	}
625 	dialog_token = *buf++;
626 	len--;
627 
628 	wpa_printf(MSG_DEBUG,
629 		   "WNM: Received Collocated Interference Report frame from "
630 		   MACSTR " (dialog_token=%u)",
631 		   MAC2STR(addr), dialog_token);
632 	wpa_hexdump(MSG_MSGDUMP, "WNM: Collocated Interference Report Elements",
633 		    buf, len);
634 
635 	hex_len = 2 * len + 1;
636 	hex = os_malloc(hex_len);
637 	if (!hex)
638 		return;
639 	wpa_snprintf_hex(hex, hex_len, buf, len);
640 	wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, COLOC_INTF_REPORT MACSTR " %d %s",
641 		     MAC2STR(addr), dialog_token, hex);
642 	os_free(hex);
643 }
644 
645 
646 
wnm_event_type2str(enum wnm_event_report_type wtype)647 static const char * wnm_event_type2str(enum wnm_event_report_type wtype)
648 {
649 #define W2S(wtype) case WNM_EVENT_TYPE_ ## wtype: return #wtype;
650 	switch (wtype) {
651 	W2S(TRANSITION)
652 	W2S(RSNA)
653 	W2S(P2P_LINK)
654 	W2S(WNM_LOG)
655 	W2S(BSS_COLOR_COLLISION)
656 	W2S(BSS_COLOR_IN_USE)
657 	}
658 	return "UNKNOWN";
659 #undef W2S
660 }
661 
662 
ieee802_11_rx_wnm_event_report(struct hostapd_data * hapd,const u8 * addr,const u8 * buf,size_t len)663 static void ieee802_11_rx_wnm_event_report(struct hostapd_data *hapd,
664 					   const u8 *addr, const u8 *buf,
665 					   size_t len)
666 {
667 	struct sta_info *sta;
668 	u8 dialog_token;
669 	struct wnm_event_report_element *report_ie;
670 	const u8 *pos = buf, *end = buf + len;
671 	const size_t fixed_field_len = 3; /* Event Token/Type/Report Status */
672 #ifdef CONFIG_IEEE80211AX
673 	const size_t tsf_len = 8;
674 	u8 color;
675 	u64 bitmap;
676 #endif /* CONFIG_IEEE80211AX */
677 
678 	if (end - pos < 1 + 2) {
679 		wpa_printf(MSG_DEBUG,
680 			   "WNM: Ignore too short WNM Event Report frame from "
681 			   MACSTR, MAC2STR(addr));
682 		return;
683 	}
684 
685 	dialog_token = *pos++;
686 	report_ie = (struct wnm_event_report_element *) pos;
687 
688 	if (end - pos < 2 + report_ie->len ||
689 	    report_ie->len < fixed_field_len) {
690 		wpa_printf(MSG_DEBUG,
691 			   "WNM: Ignore truncated WNM Event Report frame from "
692 			   MACSTR, MAC2STR(addr));
693 		return;
694 	}
695 
696 	if (report_ie->eid != WLAN_EID_EVENT_REPORT ||
697 	    report_ie->status != WNM_STATUS_SUCCESSFUL)
698 		return;
699 
700 	wpa_printf(MSG_DEBUG, "WNM: Received WNM Event Report frame from "
701 		   MACSTR " dialog_token=%u event_token=%u type=%d (%s)",
702 		   MAC2STR(addr), dialog_token, report_ie->token,
703 		   report_ie->type, wnm_event_type2str(report_ie->type));
704 
705 	pos += 2 + fixed_field_len;
706 	wpa_hexdump(MSG_MSGDUMP, "WNM: Event Report", pos, end - pos);
707 
708 	sta = ap_get_sta(hapd, addr);
709 	if (!sta || !(sta->flags & WLAN_STA_ASSOC)) {
710 		wpa_printf(MSG_DEBUG, "Station " MACSTR
711 			   " not found for received WNM Event Report",
712 			   MAC2STR(addr));
713 		return;
714 	}
715 
716 	switch (report_ie->type) {
717 #ifdef CONFIG_IEEE80211AX
718 	case WNM_EVENT_TYPE_BSS_COLOR_COLLISION:
719 		if (!hapd->iconf->ieee80211ax || hapd->conf->disable_11ax)
720 			return;
721 		if (report_ie->len <
722 		    fixed_field_len + tsf_len + 8) {
723 			wpa_printf(MSG_DEBUG,
724 				   "WNM: Too short BSS color collision event report from "
725 				   MACSTR, MAC2STR(addr));
726 			return;
727 		}
728 		bitmap = WPA_GET_LE64(report_ie->u.bss_color_collision.color_bitmap);
729 		wpa_printf(MSG_DEBUG,
730 			   "WNM: BSS color collision bitmap 0x%llx reported by "
731 			   MACSTR, (unsigned long long) bitmap, MAC2STR(addr));
732 		hostapd_switch_color(hapd->iface->bss[0], bitmap);
733 		break;
734 	case WNM_EVENT_TYPE_BSS_COLOR_IN_USE:
735 		if (!hapd->iconf->ieee80211ax || hapd->conf->disable_11ax)
736 			return;
737 		if (report_ie->len < fixed_field_len + tsf_len + 1) {
738 			wpa_printf(MSG_DEBUG,
739 				   "WNM: Too short BSS color in use event report from "
740 				   MACSTR, MAC2STR(addr));
741 			return;
742 		}
743 		color = report_ie->u.bss_color_in_use.color;
744 		if (color > 63) {
745 			wpa_printf(MSG_DEBUG,
746 				   "WNM: Invalid BSS color %u report from "
747 				   MACSTR, color, MAC2STR(addr));
748 			return;
749 		}
750 		if (color == 0) {
751 			wpa_printf(MSG_DEBUG,
752 				   "WNM: BSS color use report canceled by "
753 				   MACSTR, MAC2STR(addr));
754 			/* TODO: Clear stored color from the collision bitmap
755 			 * if there are no other users for it. */
756 			return;
757 		}
758 		wpa_printf(MSG_DEBUG, "WNM: BSS color %u use report by "
759 			   MACSTR, color, MAC2STR(addr));
760 		hapd->color_collision_bitmap |= 1ULL << color;
761 		break;
762 #endif /* CONFIG_IEEE80211AX */
763 	default:
764 		wpa_printf(MSG_DEBUG,
765 			   "WNM Event Report type=%d (%s) not supported",
766 			   report_ie->type,
767 			   wnm_event_type2str(report_ie->type));
768 		break;
769 	}
770 }
771 
772 
ieee802_11_rx_wnm_action_ap(struct hostapd_data * hapd,const struct ieee80211_mgmt * mgmt,size_t len)773 int ieee802_11_rx_wnm_action_ap(struct hostapd_data *hapd,
774 				const struct ieee80211_mgmt *mgmt, size_t len)
775 {
776 	u8 action;
777 	const u8 *payload;
778 	size_t plen;
779 
780 	if (len < IEEE80211_HDRLEN + 2)
781 		return -1;
782 
783 	payload = ((const u8 *) mgmt) + IEEE80211_HDRLEN + 1;
784 	action = *payload++;
785 	plen = len - IEEE80211_HDRLEN - 2;
786 
787 	switch (action) {
788 	case WNM_EVENT_REPORT:
789 		ieee802_11_rx_wnm_event_report(hapd, mgmt->sa, payload,
790 					       plen);
791 		return 0;
792 	case WNM_BSS_TRANS_MGMT_QUERY:
793 		ieee802_11_rx_bss_trans_mgmt_query(hapd, mgmt->sa, payload,
794 						   plen);
795 		return 0;
796 	case WNM_BSS_TRANS_MGMT_RESP:
797 		ieee802_11_rx_bss_trans_mgmt_resp(hapd, mgmt->sa, payload,
798 						  plen);
799 		return 0;
800 	case WNM_SLEEP_MODE_REQ:
801 		ieee802_11_rx_wnmsleep_req(hapd, mgmt->sa, payload, plen);
802 		return 0;
803 	case WNM_NOTIFICATION_REQ:
804 		ieee802_11_rx_wnm_notification_req(hapd, mgmt->sa, payload,
805 						   plen);
806 		return 0;
807 	case WNM_COLLOCATED_INTERFERENCE_REPORT:
808 		ieee802_11_rx_wnm_coloc_intf_report(hapd, mgmt->sa, payload,
809 						    plen);
810 		return 0;
811 	}
812 
813 	wpa_printf(MSG_DEBUG, "WNM: Unsupported WNM Action %u from " MACSTR,
814 		   action, MAC2STR(mgmt->sa));
815 	return -1;
816 }
817 
818 
wnm_send_disassoc_imminent(struct hostapd_data * hapd,struct sta_info * sta,int disassoc_timer)819 int wnm_send_disassoc_imminent(struct hostapd_data *hapd,
820 			       struct sta_info *sta, int disassoc_timer)
821 {
822 	u8 buf[1000], *pos;
823 	struct ieee80211_mgmt *mgmt;
824 
825 	os_memset(buf, 0, sizeof(buf));
826 	mgmt = (struct ieee80211_mgmt *) buf;
827 	mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
828 					   WLAN_FC_STYPE_ACTION);
829 	os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
830 	os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
831 	os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
832 	mgmt->u.action.category = WLAN_ACTION_WNM;
833 	mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
834 	mgmt->u.action.u.bss_tm_req.dialog_token = 1;
835 	mgmt->u.action.u.bss_tm_req.req_mode =
836 		WNM_BSS_TM_REQ_DISASSOC_IMMINENT;
837 	mgmt->u.action.u.bss_tm_req.disassoc_timer =
838 		host_to_le16(disassoc_timer);
839 	mgmt->u.action.u.bss_tm_req.validity_interval = 0;
840 
841 	pos = mgmt->u.action.u.bss_tm_req.variable;
842 
843 	wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request frame to indicate imminent disassociation (disassoc_timer=%d) to "
844 		   MACSTR, disassoc_timer, MAC2STR(sta->addr));
845 	if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0, NULL, 0, 0) < 0) {
846 		wpa_printf(MSG_DEBUG, "Failed to send BSS Transition "
847 			   "Management Request frame");
848 		return -1;
849 	}
850 
851 	return 0;
852 }
853 
854 
set_disassoc_timer(struct hostapd_data * hapd,struct sta_info * sta,int disassoc_timer)855 static void set_disassoc_timer(struct hostapd_data *hapd, struct sta_info *sta,
856 			       int disassoc_timer)
857 {
858 	int timeout, beacon_int;
859 
860 	/*
861 	 * Prevent STA from reconnecting using cached PMKSA to force
862 	 * full authentication with the authentication server (which may
863 	 * decide to reject the connection),
864 	 */
865 	wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
866 
867 	beacon_int = hapd->iconf->beacon_int;
868 	if (beacon_int < 1)
869 		beacon_int = 100; /* best guess */
870 	/* Calculate timeout in ms based on beacon_int in TU */
871 	timeout = disassoc_timer * beacon_int * 128 / 125;
872 	wpa_printf(MSG_DEBUG, "Disassociation timer for " MACSTR
873 		   " set to %d ms", MAC2STR(sta->addr), timeout);
874 
875 	sta->timeout_next = STA_DISASSOC_FROM_CLI;
876 	eloop_cancel_timeout(ap_handle_timer, hapd, sta);
877 	eloop_register_timeout(timeout / 1000,
878 			       timeout % 1000 * 1000,
879 			       ap_handle_timer, hapd, sta);
880 }
881 
882 
wnm_send_ess_disassoc_imminent(struct hostapd_data * hapd,struct sta_info * sta,const char * url,int disassoc_timer)883 int wnm_send_ess_disassoc_imminent(struct hostapd_data *hapd,
884 				   struct sta_info *sta, const char *url,
885 				   int disassoc_timer)
886 {
887 	u8 buf[1000], *pos;
888 	struct ieee80211_mgmt *mgmt;
889 	size_t url_len;
890 
891 	os_memset(buf, 0, sizeof(buf));
892 	mgmt = (struct ieee80211_mgmt *) buf;
893 	mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
894 					   WLAN_FC_STYPE_ACTION);
895 	os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
896 	os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
897 	os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
898 	mgmt->u.action.category = WLAN_ACTION_WNM;
899 	mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
900 	mgmt->u.action.u.bss_tm_req.dialog_token = 1;
901 	mgmt->u.action.u.bss_tm_req.req_mode =
902 		WNM_BSS_TM_REQ_DISASSOC_IMMINENT |
903 		WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT;
904 	mgmt->u.action.u.bss_tm_req.disassoc_timer =
905 		host_to_le16(disassoc_timer);
906 	mgmt->u.action.u.bss_tm_req.validity_interval = 0x01;
907 
908 	pos = mgmt->u.action.u.bss_tm_req.variable;
909 
910 	/* Session Information URL */
911 	url_len = os_strlen(url);
912 	if (url_len > 255)
913 		return -1;
914 	*pos++ = url_len;
915 	os_memcpy(pos, url, url_len);
916 	pos += url_len;
917 
918 	if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0, NULL, 0, 0) < 0) {
919 		wpa_printf(MSG_DEBUG, "Failed to send BSS Transition "
920 			   "Management Request frame");
921 		return -1;
922 	}
923 
924 	if (disassoc_timer) {
925 		/* send disassociation frame after time-out */
926 		set_disassoc_timer(hapd, sta, disassoc_timer);
927 	}
928 
929 	return 0;
930 }
931 
932 
wnm_send_bss_tm_req(struct hostapd_data * hapd,struct sta_info * sta,u8 req_mode,int disassoc_timer,u8 valid_int,const u8 * bss_term_dur,u8 dialog_token,const char * url,const u8 * nei_rep,size_t nei_rep_len,const u8 * mbo_attrs,size_t mbo_len)933 int wnm_send_bss_tm_req(struct hostapd_data *hapd, struct sta_info *sta,
934 			u8 req_mode, int disassoc_timer, u8 valid_int,
935 			const u8 *bss_term_dur, u8 dialog_token,
936 			const char *url, const u8 *nei_rep, size_t nei_rep_len,
937 			const u8 *mbo_attrs, size_t mbo_len)
938 {
939 	u8 *buf, *pos;
940 	struct ieee80211_mgmt *mgmt;
941 	size_t url_len;
942 
943 	wpa_printf(MSG_DEBUG, "WNM: Send BSS Transition Management Request to "
944 		   MACSTR
945 		   " req_mode=0x%x disassoc_timer=%d valid_int=0x%x dialog_token=%u",
946 		   MAC2STR(sta->addr), req_mode, disassoc_timer, valid_int,
947 		   dialog_token);
948 	buf = os_zalloc(1000 + nei_rep_len + mbo_len);
949 	if (buf == NULL)
950 		return -1;
951 	mgmt = (struct ieee80211_mgmt *) buf;
952 	mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
953 					   WLAN_FC_STYPE_ACTION);
954 	os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
955 	os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
956 	os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
957 	mgmt->u.action.category = WLAN_ACTION_WNM;
958 	mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
959 	mgmt->u.action.u.bss_tm_req.dialog_token = dialog_token;
960 	mgmt->u.action.u.bss_tm_req.req_mode = req_mode;
961 	mgmt->u.action.u.bss_tm_req.disassoc_timer =
962 		host_to_le16(disassoc_timer);
963 	mgmt->u.action.u.bss_tm_req.validity_interval = valid_int;
964 
965 	pos = mgmt->u.action.u.bss_tm_req.variable;
966 
967 	if ((req_mode & WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED) &&
968 	    bss_term_dur) {
969 		os_memcpy(pos, bss_term_dur, 12);
970 		pos += 12;
971 	}
972 
973 	if (url) {
974 		/* Session Information URL */
975 		url_len = os_strlen(url);
976 		if (url_len > 255) {
977 			os_free(buf);
978 			return -1;
979 		}
980 
981 		*pos++ = url_len;
982 		os_memcpy(pos, url, url_len);
983 		pos += url_len;
984 	}
985 
986 	if (nei_rep) {
987 		os_memcpy(pos, nei_rep, nei_rep_len);
988 		pos += nei_rep_len;
989 	}
990 
991 	if (mbo_len > 0) {
992 		pos += mbo_add_ie(pos, buf + sizeof(buf) - pos, mbo_attrs,
993 				  mbo_len);
994 	}
995 
996 	if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0, NULL, 0, 0) < 0) {
997 		wpa_printf(MSG_DEBUG,
998 			   "Failed to send BSS Transition Management Request frame");
999 		os_free(buf);
1000 		return -1;
1001 	}
1002 	os_free(buf);
1003 
1004 	if (disassoc_timer) {
1005 		/* send disassociation frame after time-out */
1006 		set_disassoc_timer(hapd, sta, disassoc_timer);
1007 	}
1008 
1009 	return 0;
1010 }
1011 
1012 
wnm_send_coloc_intf_req(struct hostapd_data * hapd,struct sta_info * sta,unsigned int auto_report,unsigned int timeout)1013 int wnm_send_coloc_intf_req(struct hostapd_data *hapd, struct sta_info *sta,
1014 			    unsigned int auto_report, unsigned int timeout)
1015 {
1016 	u8 buf[100], *pos;
1017 	struct ieee80211_mgmt *mgmt;
1018 	u8 dialog_token = 1;
1019 
1020 	if (auto_report > 3 || timeout > 63)
1021 		return -1;
1022 	os_memset(buf, 0, sizeof(buf));
1023 	mgmt = (struct ieee80211_mgmt *) buf;
1024 	mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1025 					   WLAN_FC_STYPE_ACTION);
1026 	os_memcpy(mgmt->da, sta->addr, ETH_ALEN);
1027 	os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
1028 	os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
1029 	mgmt->u.action.category = WLAN_ACTION_WNM;
1030 	mgmt->u.action.u.coloc_intf_req.action =
1031 		WNM_COLLOCATED_INTERFERENCE_REQ;
1032 	mgmt->u.action.u.coloc_intf_req.dialog_token = dialog_token;
1033 	mgmt->u.action.u.coloc_intf_req.req_info = auto_report | (timeout << 2);
1034 	pos = &mgmt->u.action.u.coloc_intf_req.req_info;
1035 	pos++;
1036 
1037 	wpa_printf(MSG_DEBUG, "WNM: Sending Collocated Interference Request to "
1038 		   MACSTR " (dialog_token=%u auto_report=%u timeout=%u)",
1039 		   MAC2STR(sta->addr), dialog_token, auto_report, timeout);
1040 	if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0, NULL, 0, 0) < 0) {
1041 		wpa_printf(MSG_DEBUG,
1042 			   "WNM: Failed to send Collocated Interference Request frame");
1043 		return -1;
1044 	}
1045 
1046 	return 0;
1047 }
1048