1e5b75505Sopenharmony_ci/*
2e5b75505Sopenharmony_ci * hostapd / IEEE 802.11 Management: Beacon and Probe Request/Response
3e5b75505Sopenharmony_ci * Copyright (c) 2002-2004, Instant802 Networks, Inc.
4e5b75505Sopenharmony_ci * Copyright (c) 2005-2006, Devicescape Software, Inc.
5e5b75505Sopenharmony_ci * Copyright (c) 2008-2012, Jouni Malinen <j@w1.fi>
6e5b75505Sopenharmony_ci *
7e5b75505Sopenharmony_ci * This software may be distributed under the terms of the BSD license.
8e5b75505Sopenharmony_ci * See README for more details.
9e5b75505Sopenharmony_ci */
10e5b75505Sopenharmony_ci
11e5b75505Sopenharmony_ci#include "utils/includes.h"
12e5b75505Sopenharmony_ci
13e5b75505Sopenharmony_ci#ifndef CONFIG_NATIVE_WINDOWS
14e5b75505Sopenharmony_ci
15e5b75505Sopenharmony_ci#include "utils/common.h"
16e5b75505Sopenharmony_ci#include "common/ieee802_11_defs.h"
17e5b75505Sopenharmony_ci#include "common/ieee802_11_common.h"
18e5b75505Sopenharmony_ci#include "common/hw_features_common.h"
19e5b75505Sopenharmony_ci#include "common/wpa_ctrl.h"
20e5b75505Sopenharmony_ci#include "wps/wps_defs.h"
21e5b75505Sopenharmony_ci#include "p2p/p2p.h"
22e5b75505Sopenharmony_ci#include "hostapd.h"
23e5b75505Sopenharmony_ci#include "ieee802_11.h"
24e5b75505Sopenharmony_ci#include "wpa_auth.h"
25e5b75505Sopenharmony_ci#include "wmm.h"
26e5b75505Sopenharmony_ci#include "ap_config.h"
27e5b75505Sopenharmony_ci#include "sta_info.h"
28e5b75505Sopenharmony_ci#include "p2p_hostapd.h"
29e5b75505Sopenharmony_ci#include "ap_drv_ops.h"
30e5b75505Sopenharmony_ci#include "beacon.h"
31e5b75505Sopenharmony_ci#include "hs20.h"
32e5b75505Sopenharmony_ci#include "dfs.h"
33e5b75505Sopenharmony_ci#include "taxonomy.h"
34e5b75505Sopenharmony_ci#include "ieee802_11_auth.h"
35e5b75505Sopenharmony_ci
36e5b75505Sopenharmony_ci
37e5b75505Sopenharmony_ci#ifdef NEED_AP_MLME
38e5b75505Sopenharmony_ci
39e5b75505Sopenharmony_cistatic u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
40e5b75505Sopenharmony_ci{
41e5b75505Sopenharmony_ci	if (len < 2 + 5)
42e5b75505Sopenharmony_ci		return eid;
43e5b75505Sopenharmony_ci
44e5b75505Sopenharmony_ci#ifdef CONFIG_TESTING_OPTIONS
45e5b75505Sopenharmony_ci	if (hapd->conf->bss_load_test_set) {
46e5b75505Sopenharmony_ci		*eid++ = WLAN_EID_BSS_LOAD;
47e5b75505Sopenharmony_ci		*eid++ = 5;
48e5b75505Sopenharmony_ci		os_memcpy(eid, hapd->conf->bss_load_test, 5);
49e5b75505Sopenharmony_ci		eid += 5;
50e5b75505Sopenharmony_ci		return eid;
51e5b75505Sopenharmony_ci	}
52e5b75505Sopenharmony_ci#endif /* CONFIG_TESTING_OPTIONS */
53e5b75505Sopenharmony_ci	if (hapd->conf->bss_load_update_period) {
54e5b75505Sopenharmony_ci		*eid++ = WLAN_EID_BSS_LOAD;
55e5b75505Sopenharmony_ci		*eid++ = 5;
56e5b75505Sopenharmony_ci		WPA_PUT_LE16(eid, hapd->num_sta);
57e5b75505Sopenharmony_ci		eid += 2;
58e5b75505Sopenharmony_ci		*eid++ = hapd->iface->channel_utilization;
59e5b75505Sopenharmony_ci		WPA_PUT_LE16(eid, 0); /* no available admission capabity */
60e5b75505Sopenharmony_ci		eid += 2;
61e5b75505Sopenharmony_ci	}
62e5b75505Sopenharmony_ci	return eid;
63e5b75505Sopenharmony_ci}
64e5b75505Sopenharmony_ci
65e5b75505Sopenharmony_ci
66e5b75505Sopenharmony_cistatic u8 ieee802_11_erp_info(struct hostapd_data *hapd)
67e5b75505Sopenharmony_ci{
68e5b75505Sopenharmony_ci	u8 erp = 0;
69e5b75505Sopenharmony_ci
70e5b75505Sopenharmony_ci	if (hapd->iface->current_mode == NULL ||
71e5b75505Sopenharmony_ci	    hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
72e5b75505Sopenharmony_ci		return 0;
73e5b75505Sopenharmony_ci
74e5b75505Sopenharmony_ci	if (hapd->iface->olbc)
75e5b75505Sopenharmony_ci		erp |= ERP_INFO_USE_PROTECTION;
76e5b75505Sopenharmony_ci	if (hapd->iface->num_sta_non_erp > 0) {
77e5b75505Sopenharmony_ci		erp |= ERP_INFO_NON_ERP_PRESENT |
78e5b75505Sopenharmony_ci			ERP_INFO_USE_PROTECTION;
79e5b75505Sopenharmony_ci	}
80e5b75505Sopenharmony_ci	if (hapd->iface->num_sta_no_short_preamble > 0 ||
81e5b75505Sopenharmony_ci	    hapd->iconf->preamble == LONG_PREAMBLE)
82e5b75505Sopenharmony_ci		erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
83e5b75505Sopenharmony_ci
84e5b75505Sopenharmony_ci	return erp;
85e5b75505Sopenharmony_ci}
86e5b75505Sopenharmony_ci
87e5b75505Sopenharmony_ci
88e5b75505Sopenharmony_cistatic u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
89e5b75505Sopenharmony_ci{
90e5b75505Sopenharmony_ci	*eid++ = WLAN_EID_DS_PARAMS;
91e5b75505Sopenharmony_ci	*eid++ = 1;
92e5b75505Sopenharmony_ci	*eid++ = hapd->iconf->channel;
93e5b75505Sopenharmony_ci	return eid;
94e5b75505Sopenharmony_ci}
95e5b75505Sopenharmony_ci
96e5b75505Sopenharmony_ci
97e5b75505Sopenharmony_cistatic u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
98e5b75505Sopenharmony_ci{
99e5b75505Sopenharmony_ci	if (hapd->iface->current_mode == NULL ||
100e5b75505Sopenharmony_ci	    hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
101e5b75505Sopenharmony_ci		return eid;
102e5b75505Sopenharmony_ci
103e5b75505Sopenharmony_ci	/* Set NonERP_present and use_protection bits if there
104e5b75505Sopenharmony_ci	 * are any associated NonERP stations. */
105e5b75505Sopenharmony_ci	/* TODO: use_protection bit can be set to zero even if
106e5b75505Sopenharmony_ci	 * there are NonERP stations present. This optimization
107e5b75505Sopenharmony_ci	 * might be useful if NonERP stations are "quiet".
108e5b75505Sopenharmony_ci	 * See 802.11g/D6 E-1 for recommended practice.
109e5b75505Sopenharmony_ci	 * In addition, Non ERP present might be set, if AP detects Non ERP
110e5b75505Sopenharmony_ci	 * operation on other APs. */
111e5b75505Sopenharmony_ci
112e5b75505Sopenharmony_ci	/* Add ERP Information element */
113e5b75505Sopenharmony_ci	*eid++ = WLAN_EID_ERP_INFO;
114e5b75505Sopenharmony_ci	*eid++ = 1;
115e5b75505Sopenharmony_ci	*eid++ = ieee802_11_erp_info(hapd);
116e5b75505Sopenharmony_ci
117e5b75505Sopenharmony_ci	return eid;
118e5b75505Sopenharmony_ci}
119e5b75505Sopenharmony_ci
120e5b75505Sopenharmony_ci
121e5b75505Sopenharmony_cistatic u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid)
122e5b75505Sopenharmony_ci{
123e5b75505Sopenharmony_ci	u8 *pos = eid;
124e5b75505Sopenharmony_ci	u8 local_pwr_constraint = 0;
125e5b75505Sopenharmony_ci	int dfs;
126e5b75505Sopenharmony_ci
127e5b75505Sopenharmony_ci	if (hapd->iface->current_mode == NULL ||
128e5b75505Sopenharmony_ci	    hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
129e5b75505Sopenharmony_ci		return eid;
130e5b75505Sopenharmony_ci
131e5b75505Sopenharmony_ci	/* Let host drivers add this IE if DFS support is offloaded */
132e5b75505Sopenharmony_ci	if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)
133e5b75505Sopenharmony_ci		return eid;
134e5b75505Sopenharmony_ci
135e5b75505Sopenharmony_ci	/*
136e5b75505Sopenharmony_ci	 * There is no DFS support and power constraint was not directly
137e5b75505Sopenharmony_ci	 * requested by config option.
138e5b75505Sopenharmony_ci	 */
139e5b75505Sopenharmony_ci	if (!hapd->iconf->ieee80211h &&
140e5b75505Sopenharmony_ci	    hapd->iconf->local_pwr_constraint == -1)
141e5b75505Sopenharmony_ci		return eid;
142e5b75505Sopenharmony_ci
143e5b75505Sopenharmony_ci	/* Check if DFS is required by regulatory. */
144e5b75505Sopenharmony_ci	dfs = hostapd_is_dfs_required(hapd->iface);
145e5b75505Sopenharmony_ci	if (dfs < 0) {
146e5b75505Sopenharmony_ci		wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
147e5b75505Sopenharmony_ci			   dfs);
148e5b75505Sopenharmony_ci		dfs = 0;
149e5b75505Sopenharmony_ci	}
150e5b75505Sopenharmony_ci
151e5b75505Sopenharmony_ci	if (dfs == 0 && hapd->iconf->local_pwr_constraint == -1)
152e5b75505Sopenharmony_ci		return eid;
153e5b75505Sopenharmony_ci
154e5b75505Sopenharmony_ci	/*
155e5b75505Sopenharmony_ci	 * ieee80211h (DFS) is enabled so Power Constraint element shall
156e5b75505Sopenharmony_ci	 * be added when running on DFS channel whenever local_pwr_constraint
157e5b75505Sopenharmony_ci	 * is configured or not. In order to meet regulations when TPC is not
158e5b75505Sopenharmony_ci	 * implemented using a transmit power that is below the legal maximum
159e5b75505Sopenharmony_ci	 * (including any mitigation factor) should help. In this case,
160e5b75505Sopenharmony_ci	 * indicate 3 dB below maximum allowed transmit power.
161e5b75505Sopenharmony_ci	 */
162e5b75505Sopenharmony_ci	if (hapd->iconf->local_pwr_constraint == -1)
163e5b75505Sopenharmony_ci		local_pwr_constraint = 3;
164e5b75505Sopenharmony_ci
165e5b75505Sopenharmony_ci	/*
166e5b75505Sopenharmony_ci	 * A STA that is not an AP shall use a transmit power less than or
167e5b75505Sopenharmony_ci	 * equal to the local maximum transmit power level for the channel.
168e5b75505Sopenharmony_ci	 * The local maximum transmit power can be calculated from the formula:
169e5b75505Sopenharmony_ci	 * local max TX pwr = max TX pwr - local pwr constraint
170e5b75505Sopenharmony_ci	 * Where max TX pwr is maximum transmit power level specified for
171e5b75505Sopenharmony_ci	 * channel in Country element and local pwr constraint is specified
172e5b75505Sopenharmony_ci	 * for channel in this Power Constraint element.
173e5b75505Sopenharmony_ci	 */
174e5b75505Sopenharmony_ci
175e5b75505Sopenharmony_ci	/* Element ID */
176e5b75505Sopenharmony_ci	*pos++ = WLAN_EID_PWR_CONSTRAINT;
177e5b75505Sopenharmony_ci	/* Length */
178e5b75505Sopenharmony_ci	*pos++ = 1;
179e5b75505Sopenharmony_ci	/* Local Power Constraint */
180e5b75505Sopenharmony_ci	if (local_pwr_constraint)
181e5b75505Sopenharmony_ci		*pos++ = local_pwr_constraint;
182e5b75505Sopenharmony_ci	else
183e5b75505Sopenharmony_ci		*pos++ = hapd->iconf->local_pwr_constraint;
184e5b75505Sopenharmony_ci
185e5b75505Sopenharmony_ci	return pos;
186e5b75505Sopenharmony_ci}
187e5b75505Sopenharmony_ci
188e5b75505Sopenharmony_ci
189e5b75505Sopenharmony_cistatic u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
190e5b75505Sopenharmony_ci				    struct hostapd_channel_data *start,
191e5b75505Sopenharmony_ci				    struct hostapd_channel_data *prev)
192e5b75505Sopenharmony_ci{
193e5b75505Sopenharmony_ci	if (end - pos < 3)
194e5b75505Sopenharmony_ci		return pos;
195e5b75505Sopenharmony_ci
196e5b75505Sopenharmony_ci	/* first channel number */
197e5b75505Sopenharmony_ci	*pos++ = start->chan;
198e5b75505Sopenharmony_ci	/* number of channels */
199e5b75505Sopenharmony_ci	*pos++ = (prev->chan - start->chan) / chan_spacing + 1;
200e5b75505Sopenharmony_ci	/* maximum transmit power level */
201e5b75505Sopenharmony_ci	*pos++ = start->max_tx_power;
202e5b75505Sopenharmony_ci
203e5b75505Sopenharmony_ci	return pos;
204e5b75505Sopenharmony_ci}
205e5b75505Sopenharmony_ci
206e5b75505Sopenharmony_ci
207e5b75505Sopenharmony_cistatic u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
208e5b75505Sopenharmony_ci				int max_len)
209e5b75505Sopenharmony_ci{
210e5b75505Sopenharmony_ci	u8 *pos = eid;
211e5b75505Sopenharmony_ci	u8 *end = eid + max_len;
212e5b75505Sopenharmony_ci	int i;
213e5b75505Sopenharmony_ci	struct hostapd_hw_modes *mode;
214e5b75505Sopenharmony_ci	struct hostapd_channel_data *start, *prev;
215e5b75505Sopenharmony_ci	int chan_spacing = 1;
216e5b75505Sopenharmony_ci
217e5b75505Sopenharmony_ci	if (!hapd->iconf->ieee80211d || max_len < 6 ||
218e5b75505Sopenharmony_ci	    hapd->iface->current_mode == NULL)
219e5b75505Sopenharmony_ci		return eid;
220e5b75505Sopenharmony_ci
221e5b75505Sopenharmony_ci	*pos++ = WLAN_EID_COUNTRY;
222e5b75505Sopenharmony_ci	pos++; /* length will be set later */
223e5b75505Sopenharmony_ci	os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
224e5b75505Sopenharmony_ci	pos += 3;
225e5b75505Sopenharmony_ci
226e5b75505Sopenharmony_ci	mode = hapd->iface->current_mode;
227e5b75505Sopenharmony_ci	if (mode->mode == HOSTAPD_MODE_IEEE80211A)
228e5b75505Sopenharmony_ci		chan_spacing = 4;
229e5b75505Sopenharmony_ci
230e5b75505Sopenharmony_ci	start = prev = NULL;
231e5b75505Sopenharmony_ci	for (i = 0; i < mode->num_channels; i++) {
232e5b75505Sopenharmony_ci		struct hostapd_channel_data *chan = &mode->channels[i];
233e5b75505Sopenharmony_ci		if (chan->flag & HOSTAPD_CHAN_DISABLED)
234e5b75505Sopenharmony_ci			continue;
235e5b75505Sopenharmony_ci		if (start && prev &&
236e5b75505Sopenharmony_ci		    prev->chan + chan_spacing == chan->chan &&
237e5b75505Sopenharmony_ci		    start->max_tx_power == chan->max_tx_power) {
238e5b75505Sopenharmony_ci			prev = chan;
239e5b75505Sopenharmony_ci			continue; /* can use same entry */
240e5b75505Sopenharmony_ci		}
241e5b75505Sopenharmony_ci
242e5b75505Sopenharmony_ci		if (start && prev) {
243e5b75505Sopenharmony_ci			pos = hostapd_eid_country_add(pos, end, chan_spacing,
244e5b75505Sopenharmony_ci						      start, prev);
245e5b75505Sopenharmony_ci			start = NULL;
246e5b75505Sopenharmony_ci		}
247e5b75505Sopenharmony_ci
248e5b75505Sopenharmony_ci		/* Start new group */
249e5b75505Sopenharmony_ci		start = prev = chan;
250e5b75505Sopenharmony_ci	}
251e5b75505Sopenharmony_ci
252e5b75505Sopenharmony_ci	if (start) {
253e5b75505Sopenharmony_ci		pos = hostapd_eid_country_add(pos, end, chan_spacing,
254e5b75505Sopenharmony_ci					      start, prev);
255e5b75505Sopenharmony_ci	}
256e5b75505Sopenharmony_ci
257e5b75505Sopenharmony_ci	if ((pos - eid) & 1) {
258e5b75505Sopenharmony_ci		if (end - pos < 1)
259e5b75505Sopenharmony_ci			return eid;
260e5b75505Sopenharmony_ci		*pos++ = 0; /* pad for 16-bit alignment */
261e5b75505Sopenharmony_ci	}
262e5b75505Sopenharmony_ci
263e5b75505Sopenharmony_ci	eid[1] = (pos - eid) - 2;
264e5b75505Sopenharmony_ci
265e5b75505Sopenharmony_ci	return pos;
266e5b75505Sopenharmony_ci}
267e5b75505Sopenharmony_ci
268e5b75505Sopenharmony_ci
269e5b75505Sopenharmony_ciconst u8 * hostapd_wpa_ie(struct hostapd_data *hapd, u8 eid)
270e5b75505Sopenharmony_ci{
271e5b75505Sopenharmony_ci	const u8 *ies;
272e5b75505Sopenharmony_ci	size_t ies_len;
273e5b75505Sopenharmony_ci
274e5b75505Sopenharmony_ci	ies = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ies_len);
275e5b75505Sopenharmony_ci	if (!ies)
276e5b75505Sopenharmony_ci		return NULL;
277e5b75505Sopenharmony_ci
278e5b75505Sopenharmony_ci	return get_ie(ies, ies_len, eid);
279e5b75505Sopenharmony_ci}
280e5b75505Sopenharmony_ci
281e5b75505Sopenharmony_ci
282e5b75505Sopenharmony_cistatic const u8 * hostapd_vendor_wpa_ie(struct hostapd_data *hapd,
283e5b75505Sopenharmony_ci					u32 vendor_type)
284e5b75505Sopenharmony_ci{
285e5b75505Sopenharmony_ci	const u8 *ies;
286e5b75505Sopenharmony_ci	size_t ies_len;
287e5b75505Sopenharmony_ci
288e5b75505Sopenharmony_ci	ies = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ies_len);
289e5b75505Sopenharmony_ci	if (!ies)
290e5b75505Sopenharmony_ci		return NULL;
291e5b75505Sopenharmony_ci
292e5b75505Sopenharmony_ci	return get_vendor_ie(ies, ies_len, vendor_type);
293e5b75505Sopenharmony_ci}
294e5b75505Sopenharmony_ci
295e5b75505Sopenharmony_ci
296e5b75505Sopenharmony_cistatic u8 * hostapd_get_rsne(struct hostapd_data *hapd, u8 *pos, size_t len)
297e5b75505Sopenharmony_ci{
298e5b75505Sopenharmony_ci	const u8 *ie;
299e5b75505Sopenharmony_ci
300e5b75505Sopenharmony_ci	ie = hostapd_wpa_ie(hapd, WLAN_EID_RSN);
301e5b75505Sopenharmony_ci	if (!ie || 2U + ie[1] > len)
302e5b75505Sopenharmony_ci		return pos;
303e5b75505Sopenharmony_ci
304e5b75505Sopenharmony_ci	os_memcpy(pos, ie, 2 + ie[1]);
305e5b75505Sopenharmony_ci	return pos + 2 + ie[1];
306e5b75505Sopenharmony_ci}
307e5b75505Sopenharmony_ci
308e5b75505Sopenharmony_ci
309e5b75505Sopenharmony_cistatic u8 * hostapd_get_mde(struct hostapd_data *hapd, u8 *pos, size_t len)
310e5b75505Sopenharmony_ci{
311e5b75505Sopenharmony_ci	const u8 *ie;
312e5b75505Sopenharmony_ci
313e5b75505Sopenharmony_ci	ie = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN);
314e5b75505Sopenharmony_ci	if (!ie || 2U + ie[1] > len)
315e5b75505Sopenharmony_ci		return pos;
316e5b75505Sopenharmony_ci
317e5b75505Sopenharmony_ci	os_memcpy(pos, ie, 2 + ie[1]);
318e5b75505Sopenharmony_ci	return pos + 2 + ie[1];
319e5b75505Sopenharmony_ci}
320e5b75505Sopenharmony_ci
321e5b75505Sopenharmony_ci
322e5b75505Sopenharmony_cistatic u8 * hostapd_get_rsnxe(struct hostapd_data *hapd, u8 *pos, size_t len)
323e5b75505Sopenharmony_ci{
324e5b75505Sopenharmony_ci	const u8 *ie;
325e5b75505Sopenharmony_ci
326e5b75505Sopenharmony_ci#ifdef CONFIG_TESTING_OPTIONS
327e5b75505Sopenharmony_ci	if (hapd->conf->no_beacon_rsnxe) {
328e5b75505Sopenharmony_ci		wpa_printf(MSG_INFO, "TESTING: Do not add RSNXE into Beacon");
329e5b75505Sopenharmony_ci		return pos;
330e5b75505Sopenharmony_ci	}
331e5b75505Sopenharmony_ci#endif /* CONFIG_TESTING_OPTIONS */
332e5b75505Sopenharmony_ci	ie = hostapd_wpa_ie(hapd, WLAN_EID_RSNX);
333e5b75505Sopenharmony_ci	if (!ie || 2U + ie[1] > len)
334e5b75505Sopenharmony_ci		return pos;
335e5b75505Sopenharmony_ci
336e5b75505Sopenharmony_ci	os_memcpy(pos, ie, 2 + ie[1]);
337e5b75505Sopenharmony_ci	return pos + 2 + ie[1];
338e5b75505Sopenharmony_ci}
339e5b75505Sopenharmony_ci
340e5b75505Sopenharmony_ci
341e5b75505Sopenharmony_cistatic u8 * hostapd_get_wpa_ie(struct hostapd_data *hapd, u8 *pos, size_t len)
342e5b75505Sopenharmony_ci{
343e5b75505Sopenharmony_ci	const u8 *ie;
344e5b75505Sopenharmony_ci
345e5b75505Sopenharmony_ci	ie = hostapd_vendor_wpa_ie(hapd, WPA_IE_VENDOR_TYPE);
346e5b75505Sopenharmony_ci	if (!ie || 2U + ie[1] > len)
347e5b75505Sopenharmony_ci		return pos;
348e5b75505Sopenharmony_ci
349e5b75505Sopenharmony_ci	os_memcpy(pos, ie, 2 + ie[1]);
350e5b75505Sopenharmony_ci	return pos + 2 + ie[1];
351e5b75505Sopenharmony_ci}
352e5b75505Sopenharmony_ci
353e5b75505Sopenharmony_ci
354e5b75505Sopenharmony_cistatic u8 * hostapd_get_osen_ie(struct hostapd_data *hapd, u8 *pos, size_t len)
355e5b75505Sopenharmony_ci{
356e5b75505Sopenharmony_ci	const u8 *ie;
357e5b75505Sopenharmony_ci
358e5b75505Sopenharmony_ci	ie = hostapd_vendor_wpa_ie(hapd, OSEN_IE_VENDOR_TYPE);
359e5b75505Sopenharmony_ci	if (!ie || 2U + ie[1] > len)
360e5b75505Sopenharmony_ci		return pos;
361e5b75505Sopenharmony_ci
362e5b75505Sopenharmony_ci	os_memcpy(pos, ie, 2 + ie[1]);
363e5b75505Sopenharmony_ci	return pos + 2 + ie[1];
364e5b75505Sopenharmony_ci}
365e5b75505Sopenharmony_ci
366e5b75505Sopenharmony_ci
367e5b75505Sopenharmony_cistatic u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
368e5b75505Sopenharmony_ci{
369e5b75505Sopenharmony_ci#ifdef CONFIG_TESTING_OPTIONS
370e5b75505Sopenharmony_ci	if (hapd->iface->cs_oper_class && hapd->iconf->ecsa_ie_only)
371e5b75505Sopenharmony_ci		return eid;
372e5b75505Sopenharmony_ci#endif /* CONFIG_TESTING_OPTIONS */
373e5b75505Sopenharmony_ci
374e5b75505Sopenharmony_ci	if (!hapd->cs_freq_params.channel)
375e5b75505Sopenharmony_ci		return eid;
376e5b75505Sopenharmony_ci
377e5b75505Sopenharmony_ci	*eid++ = WLAN_EID_CHANNEL_SWITCH;
378e5b75505Sopenharmony_ci	*eid++ = 3;
379e5b75505Sopenharmony_ci	*eid++ = hapd->cs_block_tx;
380e5b75505Sopenharmony_ci	*eid++ = hapd->cs_freq_params.channel;
381e5b75505Sopenharmony_ci	*eid++ = hapd->cs_count;
382e5b75505Sopenharmony_ci
383e5b75505Sopenharmony_ci	return eid;
384e5b75505Sopenharmony_ci}
385e5b75505Sopenharmony_ci
386e5b75505Sopenharmony_ci
387e5b75505Sopenharmony_cistatic u8 * hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid)
388e5b75505Sopenharmony_ci{
389e5b75505Sopenharmony_ci	if (!hapd->cs_freq_params.channel || !hapd->iface->cs_oper_class)
390e5b75505Sopenharmony_ci		return eid;
391e5b75505Sopenharmony_ci
392e5b75505Sopenharmony_ci	*eid++ = WLAN_EID_EXT_CHANSWITCH_ANN;
393e5b75505Sopenharmony_ci	*eid++ = 4;
394e5b75505Sopenharmony_ci	*eid++ = hapd->cs_block_tx;
395e5b75505Sopenharmony_ci	*eid++ = hapd->iface->cs_oper_class;
396e5b75505Sopenharmony_ci	*eid++ = hapd->cs_freq_params.channel;
397e5b75505Sopenharmony_ci	*eid++ = hapd->cs_count;
398e5b75505Sopenharmony_ci
399e5b75505Sopenharmony_ci	return eid;
400e5b75505Sopenharmony_ci}
401e5b75505Sopenharmony_ci
402e5b75505Sopenharmony_ci
403e5b75505Sopenharmony_cistatic u8 * hostapd_eid_supported_op_classes(struct hostapd_data *hapd, u8 *eid)
404e5b75505Sopenharmony_ci{
405e5b75505Sopenharmony_ci	u8 op_class, channel;
406e5b75505Sopenharmony_ci
407e5b75505Sopenharmony_ci	if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) ||
408e5b75505Sopenharmony_ci	    !hapd->iface->freq)
409e5b75505Sopenharmony_ci		return eid;
410e5b75505Sopenharmony_ci
411e5b75505Sopenharmony_ci	if (ieee80211_freq_to_channel_ext(hapd->iface->freq,
412e5b75505Sopenharmony_ci					  hapd->iconf->secondary_channel,
413e5b75505Sopenharmony_ci					  hostapd_get_oper_chwidth(hapd->iconf),
414e5b75505Sopenharmony_ci					  &op_class, &channel) ==
415e5b75505Sopenharmony_ci	    NUM_HOSTAPD_MODES)
416e5b75505Sopenharmony_ci		return eid;
417e5b75505Sopenharmony_ci
418e5b75505Sopenharmony_ci	*eid++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES;
419e5b75505Sopenharmony_ci	*eid++ = 2;
420e5b75505Sopenharmony_ci
421e5b75505Sopenharmony_ci	/* Current Operating Class */
422e5b75505Sopenharmony_ci	*eid++ = op_class;
423e5b75505Sopenharmony_ci
424e5b75505Sopenharmony_ci	/* TODO: Advertise all the supported operating classes */
425e5b75505Sopenharmony_ci	*eid++ = 0;
426e5b75505Sopenharmony_ci
427e5b75505Sopenharmony_ci	return eid;
428e5b75505Sopenharmony_ci}
429e5b75505Sopenharmony_ci
430e5b75505Sopenharmony_ci
431e5b75505Sopenharmony_cistatic u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
432e5b75505Sopenharmony_ci				   const struct ieee80211_mgmt *req,
433e5b75505Sopenharmony_ci				   int is_p2p, size_t *resp_len)
434e5b75505Sopenharmony_ci{
435e5b75505Sopenharmony_ci	struct ieee80211_mgmt *resp;
436e5b75505Sopenharmony_ci	u8 *pos, *epos, *csa_pos;
437e5b75505Sopenharmony_ci	size_t buflen;
438e5b75505Sopenharmony_ci
439e5b75505Sopenharmony_ci#define MAX_PROBERESP_LEN 768
440e5b75505Sopenharmony_ci	buflen = MAX_PROBERESP_LEN;
441e5b75505Sopenharmony_ci#ifdef CONFIG_WPS
442e5b75505Sopenharmony_ci	if (hapd->wps_probe_resp_ie)
443e5b75505Sopenharmony_ci		buflen += wpabuf_len(hapd->wps_probe_resp_ie);
444e5b75505Sopenharmony_ci#endif /* CONFIG_WPS */
445e5b75505Sopenharmony_ci#ifdef CONFIG_P2P
446e5b75505Sopenharmony_ci	if (hapd->p2p_probe_resp_ie)
447e5b75505Sopenharmony_ci		buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
448e5b75505Sopenharmony_ci#endif /* CONFIG_P2P */
449e5b75505Sopenharmony_ci#ifdef CONFIG_FST
450e5b75505Sopenharmony_ci	if (hapd->iface->fst_ies)
451e5b75505Sopenharmony_ci		buflen += wpabuf_len(hapd->iface->fst_ies);
452e5b75505Sopenharmony_ci#endif /* CONFIG_FST */
453e5b75505Sopenharmony_ci	if (hapd->conf->vendor_elements)
454e5b75505Sopenharmony_ci		buflen += wpabuf_len(hapd->conf->vendor_elements);
455e5b75505Sopenharmony_ci	if (hapd->conf->vendor_vht) {
456e5b75505Sopenharmony_ci		buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
457e5b75505Sopenharmony_ci			2 + sizeof(struct ieee80211_vht_operation);
458e5b75505Sopenharmony_ci	}
459e5b75505Sopenharmony_ci
460e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AX
461e5b75505Sopenharmony_ci	if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
462e5b75505Sopenharmony_ci		buflen += 3 + sizeof(struct ieee80211_he_capabilities) +
463e5b75505Sopenharmony_ci			3 + sizeof(struct ieee80211_he_operation) +
464e5b75505Sopenharmony_ci			3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
465e5b75505Sopenharmony_ci			3 + sizeof(struct ieee80211_spatial_reuse);
466e5b75505Sopenharmony_ci		if (is_6ghz_op_class(hapd->iconf->op_class))
467e5b75505Sopenharmony_ci			buflen += sizeof(struct ieee80211_he_6ghz_oper_info) +
468e5b75505Sopenharmony_ci				3 + sizeof(struct ieee80211_he_6ghz_band_cap);
469e5b75505Sopenharmony_ci	}
470e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AX */
471e5b75505Sopenharmony_ci
472e5b75505Sopenharmony_ci	buflen += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_PROBE_RESP);
473e5b75505Sopenharmony_ci	buflen += hostapd_mbo_ie_len(hapd);
474e5b75505Sopenharmony_ci	buflen += hostapd_eid_owe_trans_len(hapd);
475e5b75505Sopenharmony_ci	buflen += hostapd_eid_dpp_cc_len(hapd);
476e5b75505Sopenharmony_ci
477e5b75505Sopenharmony_ci	resp = os_zalloc(buflen);
478e5b75505Sopenharmony_ci	if (resp == NULL)
479e5b75505Sopenharmony_ci		return NULL;
480e5b75505Sopenharmony_ci
481e5b75505Sopenharmony_ci	epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
482e5b75505Sopenharmony_ci
483e5b75505Sopenharmony_ci	resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
484e5b75505Sopenharmony_ci					   WLAN_FC_STYPE_PROBE_RESP);
485e5b75505Sopenharmony_ci	if (req)
486e5b75505Sopenharmony_ci		os_memcpy(resp->da, req->sa, ETH_ALEN);
487e5b75505Sopenharmony_ci	os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
488e5b75505Sopenharmony_ci
489e5b75505Sopenharmony_ci	os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
490e5b75505Sopenharmony_ci	resp->u.probe_resp.beacon_int =
491e5b75505Sopenharmony_ci		host_to_le16(hapd->iconf->beacon_int);
492e5b75505Sopenharmony_ci
493e5b75505Sopenharmony_ci	/* hardware or low-level driver will setup seq_ctrl and timestamp */
494e5b75505Sopenharmony_ci	resp->u.probe_resp.capab_info =
495e5b75505Sopenharmony_ci		host_to_le16(hostapd_own_capab_info(hapd));
496e5b75505Sopenharmony_ci
497e5b75505Sopenharmony_ci	pos = resp->u.probe_resp.variable;
498e5b75505Sopenharmony_ci	*pos++ = WLAN_EID_SSID;
499e5b75505Sopenharmony_ci	*pos++ = hapd->conf->ssid.ssid_len;
500e5b75505Sopenharmony_ci	os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
501e5b75505Sopenharmony_ci	pos += hapd->conf->ssid.ssid_len;
502e5b75505Sopenharmony_ci
503e5b75505Sopenharmony_ci	/* Supported rates */
504e5b75505Sopenharmony_ci	pos = hostapd_eid_supp_rates(hapd, pos);
505e5b75505Sopenharmony_ci
506e5b75505Sopenharmony_ci	/* DS Params */
507e5b75505Sopenharmony_ci	pos = hostapd_eid_ds_params(hapd, pos);
508e5b75505Sopenharmony_ci
509e5b75505Sopenharmony_ci	pos = hostapd_eid_country(hapd, pos, epos - pos);
510e5b75505Sopenharmony_ci
511e5b75505Sopenharmony_ci	/* Power Constraint element */
512e5b75505Sopenharmony_ci	pos = hostapd_eid_pwr_constraint(hapd, pos);
513e5b75505Sopenharmony_ci
514e5b75505Sopenharmony_ci	/* CSA IE */
515e5b75505Sopenharmony_ci	csa_pos = hostapd_eid_csa(hapd, pos);
516e5b75505Sopenharmony_ci	if (csa_pos != pos)
517e5b75505Sopenharmony_ci		hapd->cs_c_off_proberesp = csa_pos - (u8 *) resp - 1;
518e5b75505Sopenharmony_ci	pos = csa_pos;
519e5b75505Sopenharmony_ci
520e5b75505Sopenharmony_ci	/* ERP Information element */
521e5b75505Sopenharmony_ci	pos = hostapd_eid_erp_info(hapd, pos);
522e5b75505Sopenharmony_ci
523e5b75505Sopenharmony_ci	/* Extended supported rates */
524e5b75505Sopenharmony_ci	pos = hostapd_eid_ext_supp_rates(hapd, pos);
525e5b75505Sopenharmony_ci
526e5b75505Sopenharmony_ci	pos = hostapd_get_rsne(hapd, pos, epos - pos);
527e5b75505Sopenharmony_ci	pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
528e5b75505Sopenharmony_ci	pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
529e5b75505Sopenharmony_ci	pos = hostapd_get_mde(hapd, pos, epos - pos);
530e5b75505Sopenharmony_ci
531e5b75505Sopenharmony_ci	/* eCSA IE */
532e5b75505Sopenharmony_ci	csa_pos = hostapd_eid_ecsa(hapd, pos);
533e5b75505Sopenharmony_ci	if (csa_pos != pos)
534e5b75505Sopenharmony_ci		hapd->cs_c_off_ecsa_proberesp = csa_pos - (u8 *) resp - 1;
535e5b75505Sopenharmony_ci	pos = csa_pos;
536e5b75505Sopenharmony_ci
537e5b75505Sopenharmony_ci	pos = hostapd_eid_supported_op_classes(hapd, pos);
538e5b75505Sopenharmony_ci	pos = hostapd_eid_ht_capabilities(hapd, pos);
539e5b75505Sopenharmony_ci	pos = hostapd_eid_ht_operation(hapd, pos);
540e5b75505Sopenharmony_ci
541e5b75505Sopenharmony_ci	pos = hostapd_eid_ext_capab(hapd, pos);
542e5b75505Sopenharmony_ci
543e5b75505Sopenharmony_ci	pos = hostapd_eid_time_adv(hapd, pos);
544e5b75505Sopenharmony_ci	pos = hostapd_eid_time_zone(hapd, pos);
545e5b75505Sopenharmony_ci
546e5b75505Sopenharmony_ci	pos = hostapd_eid_interworking(hapd, pos);
547e5b75505Sopenharmony_ci	pos = hostapd_eid_adv_proto(hapd, pos);
548e5b75505Sopenharmony_ci	pos = hostapd_eid_roaming_consortium(hapd, pos);
549e5b75505Sopenharmony_ci
550e5b75505Sopenharmony_ci#ifdef CONFIG_FST
551e5b75505Sopenharmony_ci	if (hapd->iface->fst_ies) {
552e5b75505Sopenharmony_ci		os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies),
553e5b75505Sopenharmony_ci			  wpabuf_len(hapd->iface->fst_ies));
554e5b75505Sopenharmony_ci		pos += wpabuf_len(hapd->iface->fst_ies);
555e5b75505Sopenharmony_ci	}
556e5b75505Sopenharmony_ci#endif /* CONFIG_FST */
557e5b75505Sopenharmony_ci
558e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AC
559e5b75505Sopenharmony_ci	if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
560e5b75505Sopenharmony_ci	    !is_6ghz_op_class(hapd->iconf->op_class)) {
561e5b75505Sopenharmony_ci		pos = hostapd_eid_vht_capabilities(hapd, pos, 0);
562e5b75505Sopenharmony_ci		pos = hostapd_eid_vht_operation(hapd, pos);
563e5b75505Sopenharmony_ci		pos = hostapd_eid_txpower_envelope(hapd, pos);
564e5b75505Sopenharmony_ci	}
565e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AC */
566e5b75505Sopenharmony_ci
567e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AX
568e5b75505Sopenharmony_ci	if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax &&
569e5b75505Sopenharmony_ci	    is_6ghz_op_class(hapd->iconf->op_class))
570e5b75505Sopenharmony_ci		pos = hostapd_eid_txpower_envelope(hapd, pos);
571e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AX */
572e5b75505Sopenharmony_ci
573e5b75505Sopenharmony_ci	pos = hostapd_eid_wb_chsw_wrapper(hapd, pos);
574e5b75505Sopenharmony_ci
575e5b75505Sopenharmony_ci	pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_PROBE_RESP);
576e5b75505Sopenharmony_ci	pos = hostapd_eid_fils_indic(hapd, pos, 0);
577e5b75505Sopenharmony_ci	pos = hostapd_get_rsnxe(hapd, pos, epos - pos);
578e5b75505Sopenharmony_ci
579e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AX
580e5b75505Sopenharmony_ci	if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
581e5b75505Sopenharmony_ci		pos = hostapd_eid_he_capab(hapd, pos, IEEE80211_MODE_AP);
582e5b75505Sopenharmony_ci		pos = hostapd_eid_he_operation(hapd, pos);
583e5b75505Sopenharmony_ci		pos = hostapd_eid_spatial_reuse(hapd, pos);
584e5b75505Sopenharmony_ci		pos = hostapd_eid_he_mu_edca_parameter_set(hapd, pos);
585e5b75505Sopenharmony_ci		pos = hostapd_eid_he_6ghz_band_cap(hapd, pos);
586e5b75505Sopenharmony_ci	}
587e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AX */
588e5b75505Sopenharmony_ci
589e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AC
590e5b75505Sopenharmony_ci	if (hapd->conf->vendor_vht)
591e5b75505Sopenharmony_ci		pos = hostapd_eid_vendor_vht(hapd, pos);
592e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AC */
593e5b75505Sopenharmony_ci
594e5b75505Sopenharmony_ci	/* WPA / OSEN */
595e5b75505Sopenharmony_ci	pos = hostapd_get_wpa_ie(hapd, pos, epos - pos);
596e5b75505Sopenharmony_ci	pos = hostapd_get_osen_ie(hapd, pos, epos - pos);
597e5b75505Sopenharmony_ci
598e5b75505Sopenharmony_ci	/* Wi-Fi Alliance WMM */
599e5b75505Sopenharmony_ci	pos = hostapd_eid_wmm(hapd, pos);
600e5b75505Sopenharmony_ci
601e5b75505Sopenharmony_ci#ifdef CONFIG_WPS
602e5b75505Sopenharmony_ci	if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
603e5b75505Sopenharmony_ci		os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
604e5b75505Sopenharmony_ci			  wpabuf_len(hapd->wps_probe_resp_ie));
605e5b75505Sopenharmony_ci		pos += wpabuf_len(hapd->wps_probe_resp_ie);
606e5b75505Sopenharmony_ci	}
607e5b75505Sopenharmony_ci#endif /* CONFIG_WPS */
608e5b75505Sopenharmony_ci
609e5b75505Sopenharmony_ci#ifdef CONFIG_P2P
610e5b75505Sopenharmony_ci	if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
611e5b75505Sopenharmony_ci	    hapd->p2p_probe_resp_ie) {
612e5b75505Sopenharmony_ci		os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
613e5b75505Sopenharmony_ci			  wpabuf_len(hapd->p2p_probe_resp_ie));
614e5b75505Sopenharmony_ci		pos += wpabuf_len(hapd->p2p_probe_resp_ie);
615e5b75505Sopenharmony_ci	}
616e5b75505Sopenharmony_ci#endif /* CONFIG_P2P */
617e5b75505Sopenharmony_ci#ifdef CONFIG_P2P_MANAGER
618e5b75505Sopenharmony_ci	if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
619e5b75505Sopenharmony_ci	    P2P_MANAGE)
620e5b75505Sopenharmony_ci		pos = hostapd_eid_p2p_manage(hapd, pos);
621e5b75505Sopenharmony_ci#endif /* CONFIG_P2P_MANAGER */
622e5b75505Sopenharmony_ci
623e5b75505Sopenharmony_ci#ifdef CONFIG_HS20
624e5b75505Sopenharmony_ci	pos = hostapd_eid_hs20_indication(hapd, pos);
625e5b75505Sopenharmony_ci#endif /* CONFIG_HS20 */
626e5b75505Sopenharmony_ci
627e5b75505Sopenharmony_ci	pos = hostapd_eid_mbo(hapd, pos, (u8 *) resp + buflen - pos);
628e5b75505Sopenharmony_ci	pos = hostapd_eid_owe_trans(hapd, pos, (u8 *) resp + buflen - pos);
629e5b75505Sopenharmony_ci	pos = hostapd_eid_dpp_cc(hapd, pos, (u8 *) resp + buflen - pos);
630e5b75505Sopenharmony_ci
631e5b75505Sopenharmony_ci	if (hapd->conf->vendor_elements) {
632e5b75505Sopenharmony_ci		os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
633e5b75505Sopenharmony_ci			  wpabuf_len(hapd->conf->vendor_elements));
634e5b75505Sopenharmony_ci		pos += wpabuf_len(hapd->conf->vendor_elements);
635e5b75505Sopenharmony_ci	}
636e5b75505Sopenharmony_ci
637e5b75505Sopenharmony_ci	*resp_len = pos - (u8 *) resp;
638e5b75505Sopenharmony_ci	return (u8 *) resp;
639e5b75505Sopenharmony_ci}
640e5b75505Sopenharmony_ci
641e5b75505Sopenharmony_ci
642e5b75505Sopenharmony_cienum ssid_match_result {
643e5b75505Sopenharmony_ci	NO_SSID_MATCH,
644e5b75505Sopenharmony_ci	EXACT_SSID_MATCH,
645e5b75505Sopenharmony_ci	WILDCARD_SSID_MATCH,
646e5b75505Sopenharmony_ci	CO_LOCATED_SSID_MATCH,
647e5b75505Sopenharmony_ci};
648e5b75505Sopenharmony_ci
649e5b75505Sopenharmony_cistatic enum ssid_match_result ssid_match(struct hostapd_data *hapd,
650e5b75505Sopenharmony_ci					 const u8 *ssid, size_t ssid_len,
651e5b75505Sopenharmony_ci					 const u8 *ssid_list,
652e5b75505Sopenharmony_ci					 size_t ssid_list_len,
653e5b75505Sopenharmony_ci					 const u8 *short_ssid_list,
654e5b75505Sopenharmony_ci					 size_t short_ssid_list_len)
655e5b75505Sopenharmony_ci{
656e5b75505Sopenharmony_ci	const u8 *pos, *end;
657e5b75505Sopenharmony_ci	struct hostapd_iface *iface = hapd->iface;
658e5b75505Sopenharmony_ci	int wildcard = 0;
659e5b75505Sopenharmony_ci	size_t i, j;
660e5b75505Sopenharmony_ci
661e5b75505Sopenharmony_ci	if (ssid_len == 0)
662e5b75505Sopenharmony_ci		wildcard = 1;
663e5b75505Sopenharmony_ci	if (ssid_len == hapd->conf->ssid.ssid_len &&
664e5b75505Sopenharmony_ci	    os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
665e5b75505Sopenharmony_ci		return EXACT_SSID_MATCH;
666e5b75505Sopenharmony_ci
667e5b75505Sopenharmony_ci	if (ssid_list) {
668e5b75505Sopenharmony_ci		pos = ssid_list;
669e5b75505Sopenharmony_ci		end = ssid_list + ssid_list_len;
670e5b75505Sopenharmony_ci		while (end - pos >= 2) {
671e5b75505Sopenharmony_ci			if (2 + pos[1] > end - pos)
672e5b75505Sopenharmony_ci				break;
673e5b75505Sopenharmony_ci			if (pos[1] == 0)
674e5b75505Sopenharmony_ci				wildcard = 1;
675e5b75505Sopenharmony_ci			if (pos[1] == hapd->conf->ssid.ssid_len &&
676e5b75505Sopenharmony_ci			    os_memcmp(pos + 2, hapd->conf->ssid.ssid,
677e5b75505Sopenharmony_ci				      pos[1]) == 0)
678e5b75505Sopenharmony_ci				return EXACT_SSID_MATCH;
679e5b75505Sopenharmony_ci			pos += 2 + pos[1];
680e5b75505Sopenharmony_ci		}
681e5b75505Sopenharmony_ci	}
682e5b75505Sopenharmony_ci
683e5b75505Sopenharmony_ci	if (short_ssid_list) {
684e5b75505Sopenharmony_ci		pos = short_ssid_list;
685e5b75505Sopenharmony_ci		end = short_ssid_list + short_ssid_list_len;
686e5b75505Sopenharmony_ci		while (end - pos >= 4) {
687e5b75505Sopenharmony_ci			if (hapd->conf->ssid.short_ssid == WPA_GET_LE32(pos))
688e5b75505Sopenharmony_ci				return EXACT_SSID_MATCH;
689e5b75505Sopenharmony_ci			pos += 4;
690e5b75505Sopenharmony_ci		}
691e5b75505Sopenharmony_ci	}
692e5b75505Sopenharmony_ci
693e5b75505Sopenharmony_ci	if (wildcard)
694e5b75505Sopenharmony_ci		return WILDCARD_SSID_MATCH;
695e5b75505Sopenharmony_ci
696e5b75505Sopenharmony_ci	if (!iface->interfaces || iface->interfaces->count <= 1 ||
697e5b75505Sopenharmony_ci	    is_6ghz_op_class(hapd->iconf->op_class))
698e5b75505Sopenharmony_ci		return NO_SSID_MATCH;
699e5b75505Sopenharmony_ci
700e5b75505Sopenharmony_ci	for (i = 0; i < iface->interfaces->count; i++) {
701e5b75505Sopenharmony_ci		struct hostapd_iface *colocated;
702e5b75505Sopenharmony_ci
703e5b75505Sopenharmony_ci		colocated = iface->interfaces->iface[i];
704e5b75505Sopenharmony_ci
705e5b75505Sopenharmony_ci		if (colocated == iface ||
706e5b75505Sopenharmony_ci		    !is_6ghz_op_class(colocated->conf->op_class))
707e5b75505Sopenharmony_ci			continue;
708e5b75505Sopenharmony_ci
709e5b75505Sopenharmony_ci		for (j = 0; j < colocated->num_bss; j++) {
710e5b75505Sopenharmony_ci			struct hostapd_bss_config *conf;
711e5b75505Sopenharmony_ci
712e5b75505Sopenharmony_ci			conf = colocated->bss[j]->conf;
713e5b75505Sopenharmony_ci			if (ssid_len == conf->ssid.ssid_len &&
714e5b75505Sopenharmony_ci			    os_memcmp(ssid, conf->ssid.ssid, ssid_len) == 0)
715e5b75505Sopenharmony_ci				return CO_LOCATED_SSID_MATCH;
716e5b75505Sopenharmony_ci		}
717e5b75505Sopenharmony_ci	}
718e5b75505Sopenharmony_ci
719e5b75505Sopenharmony_ci	return NO_SSID_MATCH;
720e5b75505Sopenharmony_ci}
721e5b75505Sopenharmony_ci
722e5b75505Sopenharmony_ci
723e5b75505Sopenharmony_civoid sta_track_expire(struct hostapd_iface *iface, int force)
724e5b75505Sopenharmony_ci{
725e5b75505Sopenharmony_ci	struct os_reltime now;
726e5b75505Sopenharmony_ci	struct hostapd_sta_info *info;
727e5b75505Sopenharmony_ci
728e5b75505Sopenharmony_ci	if (!iface->num_sta_seen)
729e5b75505Sopenharmony_ci		return;
730e5b75505Sopenharmony_ci
731e5b75505Sopenharmony_ci	os_get_reltime(&now);
732e5b75505Sopenharmony_ci	while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
733e5b75505Sopenharmony_ci				     list))) {
734e5b75505Sopenharmony_ci		if (!force &&
735e5b75505Sopenharmony_ci		    !os_reltime_expired(&now, &info->last_seen,
736e5b75505Sopenharmony_ci					iface->conf->track_sta_max_age))
737e5b75505Sopenharmony_ci			break;
738e5b75505Sopenharmony_ci		force = 0;
739e5b75505Sopenharmony_ci
740e5b75505Sopenharmony_ci		wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
741e5b75505Sopenharmony_ci			   MACSTR_SEC, iface->bss[0]->conf->iface,
742e5b75505Sopenharmony_ci			   MAC2STR_SEC(info->addr));
743e5b75505Sopenharmony_ci		dl_list_del(&info->list);
744e5b75505Sopenharmony_ci		iface->num_sta_seen--;
745e5b75505Sopenharmony_ci		sta_track_del(info);
746e5b75505Sopenharmony_ci	}
747e5b75505Sopenharmony_ci}
748e5b75505Sopenharmony_ci
749e5b75505Sopenharmony_ci
750e5b75505Sopenharmony_cistatic struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
751e5b75505Sopenharmony_ci					       const u8 *addr)
752e5b75505Sopenharmony_ci{
753e5b75505Sopenharmony_ci	struct hostapd_sta_info *info;
754e5b75505Sopenharmony_ci
755e5b75505Sopenharmony_ci	dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
756e5b75505Sopenharmony_ci		if (os_memcmp(addr, info->addr, ETH_ALEN) == 0)
757e5b75505Sopenharmony_ci			return info;
758e5b75505Sopenharmony_ci
759e5b75505Sopenharmony_ci	return NULL;
760e5b75505Sopenharmony_ci}
761e5b75505Sopenharmony_ci
762e5b75505Sopenharmony_ci
763e5b75505Sopenharmony_civoid sta_track_add(struct hostapd_iface *iface, const u8 *addr, int ssi_signal)
764e5b75505Sopenharmony_ci{
765e5b75505Sopenharmony_ci	struct hostapd_sta_info *info;
766e5b75505Sopenharmony_ci
767e5b75505Sopenharmony_ci	info = sta_track_get(iface, addr);
768e5b75505Sopenharmony_ci	if (info) {
769e5b75505Sopenharmony_ci		/* Move the most recent entry to the end of the list */
770e5b75505Sopenharmony_ci		dl_list_del(&info->list);
771e5b75505Sopenharmony_ci		dl_list_add_tail(&iface->sta_seen, &info->list);
772e5b75505Sopenharmony_ci		os_get_reltime(&info->last_seen);
773e5b75505Sopenharmony_ci		info->ssi_signal = ssi_signal;
774e5b75505Sopenharmony_ci		return;
775e5b75505Sopenharmony_ci	}
776e5b75505Sopenharmony_ci
777e5b75505Sopenharmony_ci	/* Add a new entry */
778e5b75505Sopenharmony_ci	info = os_zalloc(sizeof(*info));
779e5b75505Sopenharmony_ci	if (info == NULL)
780e5b75505Sopenharmony_ci		return;
781e5b75505Sopenharmony_ci	os_memcpy(info->addr, addr, ETH_ALEN);
782e5b75505Sopenharmony_ci	os_get_reltime(&info->last_seen);
783e5b75505Sopenharmony_ci	info->ssi_signal = ssi_signal;
784e5b75505Sopenharmony_ci
785e5b75505Sopenharmony_ci	if (iface->num_sta_seen >= iface->conf->track_sta_max_num) {
786e5b75505Sopenharmony_ci		/* Expire oldest entry to make room for a new one */
787e5b75505Sopenharmony_ci		sta_track_expire(iface, 1);
788e5b75505Sopenharmony_ci	}
789e5b75505Sopenharmony_ci
790e5b75505Sopenharmony_ci	wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
791e5b75505Sopenharmony_ci		   MACSTR_SEC, iface->bss[0]->conf->iface, MAC2STR_SEC(addr));
792e5b75505Sopenharmony_ci	dl_list_add_tail(&iface->sta_seen, &info->list);
793e5b75505Sopenharmony_ci	iface->num_sta_seen++;
794e5b75505Sopenharmony_ci}
795e5b75505Sopenharmony_ci
796e5b75505Sopenharmony_ci
797e5b75505Sopenharmony_cistruct hostapd_data *
798e5b75505Sopenharmony_cista_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
799e5b75505Sopenharmony_ci		  const char *ifname)
800e5b75505Sopenharmony_ci{
801e5b75505Sopenharmony_ci	struct hapd_interfaces *interfaces = iface->interfaces;
802e5b75505Sopenharmony_ci	size_t i, j;
803e5b75505Sopenharmony_ci
804e5b75505Sopenharmony_ci	for (i = 0; i < interfaces->count; i++) {
805e5b75505Sopenharmony_ci		struct hostapd_data *hapd = NULL;
806e5b75505Sopenharmony_ci
807e5b75505Sopenharmony_ci		iface = interfaces->iface[i];
808e5b75505Sopenharmony_ci		for (j = 0; j < iface->num_bss; j++) {
809e5b75505Sopenharmony_ci			hapd = iface->bss[j];
810e5b75505Sopenharmony_ci			if (os_strcmp(ifname, hapd->conf->iface) == 0)
811e5b75505Sopenharmony_ci				break;
812e5b75505Sopenharmony_ci			hapd = NULL;
813e5b75505Sopenharmony_ci		}
814e5b75505Sopenharmony_ci
815e5b75505Sopenharmony_ci		if (hapd && sta_track_get(iface, addr))
816e5b75505Sopenharmony_ci			return hapd;
817e5b75505Sopenharmony_ci	}
818e5b75505Sopenharmony_ci
819e5b75505Sopenharmony_ci	return NULL;
820e5b75505Sopenharmony_ci}
821e5b75505Sopenharmony_ci
822e5b75505Sopenharmony_ci
823e5b75505Sopenharmony_ci#ifdef CONFIG_TAXONOMY
824e5b75505Sopenharmony_civoid sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr,
825e5b75505Sopenharmony_ci				   struct wpabuf **probe_ie_taxonomy)
826e5b75505Sopenharmony_ci{
827e5b75505Sopenharmony_ci	struct hostapd_sta_info *info;
828e5b75505Sopenharmony_ci
829e5b75505Sopenharmony_ci	info = sta_track_get(iface, addr);
830e5b75505Sopenharmony_ci	if (!info)
831e5b75505Sopenharmony_ci		return;
832e5b75505Sopenharmony_ci
833e5b75505Sopenharmony_ci	wpabuf_free(*probe_ie_taxonomy);
834e5b75505Sopenharmony_ci	*probe_ie_taxonomy = info->probe_ie_taxonomy;
835e5b75505Sopenharmony_ci	info->probe_ie_taxonomy = NULL;
836e5b75505Sopenharmony_ci}
837e5b75505Sopenharmony_ci#endif /* CONFIG_TAXONOMY */
838e5b75505Sopenharmony_ci
839e5b75505Sopenharmony_ci
840e5b75505Sopenharmony_civoid handle_probe_req(struct hostapd_data *hapd,
841e5b75505Sopenharmony_ci		      const struct ieee80211_mgmt *mgmt, size_t len,
842e5b75505Sopenharmony_ci		      int ssi_signal)
843e5b75505Sopenharmony_ci{
844e5b75505Sopenharmony_ci	u8 *resp;
845e5b75505Sopenharmony_ci	struct ieee802_11_elems elems;
846e5b75505Sopenharmony_ci	const u8 *ie;
847e5b75505Sopenharmony_ci	size_t ie_len;
848e5b75505Sopenharmony_ci	size_t i, resp_len;
849e5b75505Sopenharmony_ci	int noack;
850e5b75505Sopenharmony_ci	enum ssid_match_result res;
851e5b75505Sopenharmony_ci	int ret;
852e5b75505Sopenharmony_ci	u16 csa_offs[2];
853e5b75505Sopenharmony_ci	size_t csa_offs_len;
854e5b75505Sopenharmony_ci	struct radius_sta rad_info;
855e5b75505Sopenharmony_ci
856e5b75505Sopenharmony_ci	if (hapd->iconf->rssi_ignore_probe_request && ssi_signal &&
857e5b75505Sopenharmony_ci	    ssi_signal < hapd->iconf->rssi_ignore_probe_request)
858e5b75505Sopenharmony_ci		return;
859e5b75505Sopenharmony_ci
860e5b75505Sopenharmony_ci	if (len < IEEE80211_HDRLEN)
861e5b75505Sopenharmony_ci		return;
862e5b75505Sopenharmony_ci	ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN;
863e5b75505Sopenharmony_ci	if (hapd->iconf->track_sta_max_num)
864e5b75505Sopenharmony_ci		sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
865e5b75505Sopenharmony_ci	ie_len = len - IEEE80211_HDRLEN;
866e5b75505Sopenharmony_ci
867e5b75505Sopenharmony_ci	ret = hostapd_allowed_address(hapd, mgmt->sa, (const u8 *) mgmt, len,
868e5b75505Sopenharmony_ci				      &rad_info, 1);
869e5b75505Sopenharmony_ci	if (ret == HOSTAPD_ACL_REJECT) {
870e5b75505Sopenharmony_ci		wpa_msg(hapd->msg_ctx, MSG_DEBUG,
871e5b75505Sopenharmony_ci			"Ignore Probe Request frame from " MACSTR
872e5b75505Sopenharmony_ci			" due to ACL reject ", MAC2STR(mgmt->sa));
873e5b75505Sopenharmony_ci		return;
874e5b75505Sopenharmony_ci	}
875e5b75505Sopenharmony_ci
876e5b75505Sopenharmony_ci	for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
877e5b75505Sopenharmony_ci		if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
878e5b75505Sopenharmony_ci					    mgmt->sa, mgmt->da, mgmt->bssid,
879e5b75505Sopenharmony_ci					    ie, ie_len, ssi_signal) > 0)
880e5b75505Sopenharmony_ci			return;
881e5b75505Sopenharmony_ci
882e5b75505Sopenharmony_ci	if (!hapd->conf->send_probe_response)
883e5b75505Sopenharmony_ci		return;
884e5b75505Sopenharmony_ci
885e5b75505Sopenharmony_ci	if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
886e5b75505Sopenharmony_ci		wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR_SEC,
887e5b75505Sopenharmony_ci			   MAC2STR_SEC(mgmt->sa));
888e5b75505Sopenharmony_ci		return;
889e5b75505Sopenharmony_ci	}
890e5b75505Sopenharmony_ci
891e5b75505Sopenharmony_ci	if ((!elems.ssid || !elems.supp_rates)) {
892e5b75505Sopenharmony_ci		wpa_printf(MSG_DEBUG, "STA " MACSTR_SEC " sent probe request "
893e5b75505Sopenharmony_ci			   "without SSID or supported rates element",
894e5b75505Sopenharmony_ci			   MAC2STR_SEC(mgmt->sa));
895e5b75505Sopenharmony_ci		return;
896e5b75505Sopenharmony_ci	}
897e5b75505Sopenharmony_ci
898e5b75505Sopenharmony_ci	/*
899e5b75505Sopenharmony_ci	 * No need to reply if the Probe Request frame was sent on an adjacent
900e5b75505Sopenharmony_ci	 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
901e5b75505Sopenharmony_ci	 * AP with dot11RadioMeasurementActivated set to true, but strictly
902e5b75505Sopenharmony_ci	 * speaking does not allow such ignoring of Probe Request frames if
903e5b75505Sopenharmony_ci	 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
904e5b75505Sopenharmony_ci	 * number of unnecessary Probe Response frames for cases where the STA
905e5b75505Sopenharmony_ci	 * is less likely to see them (Probe Request frame sent on a
906e5b75505Sopenharmony_ci	 * neighboring, but partially overlapping, channel).
907e5b75505Sopenharmony_ci	 */
908e5b75505Sopenharmony_ci	if (elems.ds_params &&
909e5b75505Sopenharmony_ci	    hapd->iface->current_mode &&
910e5b75505Sopenharmony_ci	    (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
911e5b75505Sopenharmony_ci	     hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
912e5b75505Sopenharmony_ci	    hapd->iconf->channel != elems.ds_params[0]) {
913e5b75505Sopenharmony_ci		wpa_printf(MSG_DEBUG,
914e5b75505Sopenharmony_ci			   "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
915e5b75505Sopenharmony_ci			   hapd->iconf->channel, elems.ds_params[0]);
916e5b75505Sopenharmony_ci		return;
917e5b75505Sopenharmony_ci	}
918e5b75505Sopenharmony_ci
919e5b75505Sopenharmony_ci#ifdef CONFIG_P2P
920e5b75505Sopenharmony_ci	if (hapd->p2p && hapd->p2p_group && elems.wps_ie) {
921e5b75505Sopenharmony_ci		struct wpabuf *wps;
922e5b75505Sopenharmony_ci		wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
923e5b75505Sopenharmony_ci		if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
924e5b75505Sopenharmony_ci			wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
925e5b75505Sopenharmony_ci				   "due to mismatch with Requested Device "
926e5b75505Sopenharmony_ci				   "Type");
927e5b75505Sopenharmony_ci			wpabuf_free(wps);
928e5b75505Sopenharmony_ci			return;
929e5b75505Sopenharmony_ci		}
930e5b75505Sopenharmony_ci		wpabuf_free(wps);
931e5b75505Sopenharmony_ci	}
932e5b75505Sopenharmony_ci
933e5b75505Sopenharmony_ci	if (hapd->p2p && hapd->p2p_group && elems.p2p) {
934e5b75505Sopenharmony_ci		struct wpabuf *p2p;
935e5b75505Sopenharmony_ci		p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
936e5b75505Sopenharmony_ci		if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
937e5b75505Sopenharmony_ci			wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
938e5b75505Sopenharmony_ci				   "due to mismatch with Device ID");
939e5b75505Sopenharmony_ci			wpabuf_free(p2p);
940e5b75505Sopenharmony_ci			return;
941e5b75505Sopenharmony_ci		}
942e5b75505Sopenharmony_ci		wpabuf_free(p2p);
943e5b75505Sopenharmony_ci	}
944e5b75505Sopenharmony_ci#endif /* CONFIG_P2P */
945e5b75505Sopenharmony_ci
946e5b75505Sopenharmony_ci	if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
947e5b75505Sopenharmony_ci	    elems.ssid_list_len == 0 && elems.short_ssid_list_len == 0) {
948e5b75505Sopenharmony_ci		wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR_SEC " for "
949e5b75505Sopenharmony_ci			   "broadcast SSID ignored", MAC2STR_SEC(mgmt->sa));
950e5b75505Sopenharmony_ci		return;
951e5b75505Sopenharmony_ci	}
952e5b75505Sopenharmony_ci
953e5b75505Sopenharmony_ci#ifdef CONFIG_P2P
954e5b75505Sopenharmony_ci	if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
955e5b75505Sopenharmony_ci	    elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
956e5b75505Sopenharmony_ci	    os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
957e5b75505Sopenharmony_ci		      P2P_WILDCARD_SSID_LEN) == 0) {
958e5b75505Sopenharmony_ci		/* Process P2P Wildcard SSID like Wildcard SSID */
959e5b75505Sopenharmony_ci		elems.ssid_len = 0;
960e5b75505Sopenharmony_ci	}
961e5b75505Sopenharmony_ci#endif /* CONFIG_P2P */
962e5b75505Sopenharmony_ci
963e5b75505Sopenharmony_ci#ifdef CONFIG_TAXONOMY
964e5b75505Sopenharmony_ci	{
965e5b75505Sopenharmony_ci		struct sta_info *sta;
966e5b75505Sopenharmony_ci		struct hostapd_sta_info *info;
967e5b75505Sopenharmony_ci
968e5b75505Sopenharmony_ci		if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) {
969e5b75505Sopenharmony_ci			taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len);
970e5b75505Sopenharmony_ci		} else if ((info = sta_track_get(hapd->iface,
971e5b75505Sopenharmony_ci						 mgmt->sa)) != NULL) {
972e5b75505Sopenharmony_ci			taxonomy_hostapd_sta_info_probe_req(hapd, info,
973e5b75505Sopenharmony_ci							    ie, ie_len);
974e5b75505Sopenharmony_ci		}
975e5b75505Sopenharmony_ci	}
976e5b75505Sopenharmony_ci#endif /* CONFIG_TAXONOMY */
977e5b75505Sopenharmony_ci
978e5b75505Sopenharmony_ci	res = ssid_match(hapd, elems.ssid, elems.ssid_len,
979e5b75505Sopenharmony_ci			 elems.ssid_list, elems.ssid_list_len,
980e5b75505Sopenharmony_ci			 elems.short_ssid_list, elems.short_ssid_list_len);
981e5b75505Sopenharmony_ci	if (res == NO_SSID_MATCH) {
982e5b75505Sopenharmony_ci		if (!(mgmt->da[0] & 0x01)) {
983e5b75505Sopenharmony_ci			wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR_SEC
984e5b75505Sopenharmony_ci				   " for foreign SSID '%s' (DA " MACSTR_SEC ")%s",
985e5b75505Sopenharmony_ci				   MAC2STR_SEC(mgmt->sa),
986e5b75505Sopenharmony_ci				   anonymize_ssid(wpa_ssid_txt(elems.ssid, elems.ssid_len)),
987e5b75505Sopenharmony_ci				   MAC2STR_SEC(mgmt->da),
988e5b75505Sopenharmony_ci				   elems.ssid_list ? " (SSID list)" : "");
989e5b75505Sopenharmony_ci		}
990e5b75505Sopenharmony_ci		return;
991e5b75505Sopenharmony_ci	}
992e5b75505Sopenharmony_ci
993e5b75505Sopenharmony_ci	if (hapd->conf->ignore_broadcast_ssid && res == WILDCARD_SSID_MATCH) {
994e5b75505Sopenharmony_ci		wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR_SEC " for "
995e5b75505Sopenharmony_ci			   "broadcast SSID ignored", MAC2STR_SEC(mgmt->sa));
996e5b75505Sopenharmony_ci		return;
997e5b75505Sopenharmony_ci	}
998e5b75505Sopenharmony_ci
999e5b75505Sopenharmony_ci#ifdef CONFIG_INTERWORKING
1000e5b75505Sopenharmony_ci	if (hapd->conf->interworking &&
1001e5b75505Sopenharmony_ci	    elems.interworking && elems.interworking_len >= 1) {
1002e5b75505Sopenharmony_ci		u8 ant = elems.interworking[0] & 0x0f;
1003e5b75505Sopenharmony_ci		if (ant != INTERWORKING_ANT_WILDCARD &&
1004e5b75505Sopenharmony_ci		    ant != hapd->conf->access_network_type) {
1005e5b75505Sopenharmony_ci			wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR_SEC
1006e5b75505Sopenharmony_ci				   " for mismatching ANT %u ignored",
1007e5b75505Sopenharmony_ci				   MAC2STR_SEC(mgmt->sa), ant);
1008e5b75505Sopenharmony_ci			return;
1009e5b75505Sopenharmony_ci		}
1010e5b75505Sopenharmony_ci	}
1011e5b75505Sopenharmony_ci
1012e5b75505Sopenharmony_ci	if (hapd->conf->interworking && elems.interworking &&
1013e5b75505Sopenharmony_ci	    (elems.interworking_len == 7 || elems.interworking_len == 9)) {
1014e5b75505Sopenharmony_ci		const u8 *hessid;
1015e5b75505Sopenharmony_ci		if (elems.interworking_len == 7)
1016e5b75505Sopenharmony_ci			hessid = elems.interworking + 1;
1017e5b75505Sopenharmony_ci		else
1018e5b75505Sopenharmony_ci			hessid = elems.interworking + 1 + 2;
1019e5b75505Sopenharmony_ci		if (!is_broadcast_ether_addr(hessid) &&
1020e5b75505Sopenharmony_ci		    os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
1021e5b75505Sopenharmony_ci			wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR_SEC
1022e5b75505Sopenharmony_ci				   " for mismatching HESSID " MACSTR_SEC
1023e5b75505Sopenharmony_ci				   " ignored",
1024e5b75505Sopenharmony_ci				   MAC2STR_SEC(mgmt->sa), MAC2STR_SEC(hessid));
1025e5b75505Sopenharmony_ci			return;
1026e5b75505Sopenharmony_ci		}
1027e5b75505Sopenharmony_ci	}
1028e5b75505Sopenharmony_ci#endif /* CONFIG_INTERWORKING */
1029e5b75505Sopenharmony_ci
1030e5b75505Sopenharmony_ci#ifdef CONFIG_P2P
1031e5b75505Sopenharmony_ci	if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1032e5b75505Sopenharmony_ci	    supp_rates_11b_only(&elems)) {
1033e5b75505Sopenharmony_ci		/* Indicates support for 11b rates only */
1034e5b75505Sopenharmony_ci		wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
1035e5b75505Sopenharmony_ci			   MACSTR_SEC " with only 802.11b rates",
1036e5b75505Sopenharmony_ci			   MAC2STR_SEC(mgmt->sa));
1037e5b75505Sopenharmony_ci		return;
1038e5b75505Sopenharmony_ci	}
1039e5b75505Sopenharmony_ci#endif /* CONFIG_P2P */
1040e5b75505Sopenharmony_ci
1041e5b75505Sopenharmony_ci	/* TODO: verify that supp_rates contains at least one matching rate
1042e5b75505Sopenharmony_ci	 * with AP configuration */
1043e5b75505Sopenharmony_ci
1044e5b75505Sopenharmony_ci	if (hapd->conf->no_probe_resp_if_seen_on &&
1045e5b75505Sopenharmony_ci	    is_multicast_ether_addr(mgmt->da) &&
1046e5b75505Sopenharmony_ci	    is_multicast_ether_addr(mgmt->bssid) &&
1047e5b75505Sopenharmony_ci	    sta_track_seen_on(hapd->iface, mgmt->sa,
1048e5b75505Sopenharmony_ci			      hapd->conf->no_probe_resp_if_seen_on)) {
1049e5b75505Sopenharmony_ci		wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR_SEC
1050e5b75505Sopenharmony_ci			   " since STA has been seen on %s",
1051e5b75505Sopenharmony_ci			   hapd->conf->iface, MAC2STR_SEC(mgmt->sa),
1052e5b75505Sopenharmony_ci			   hapd->conf->no_probe_resp_if_seen_on);
1053e5b75505Sopenharmony_ci		return;
1054e5b75505Sopenharmony_ci	}
1055e5b75505Sopenharmony_ci
1056e5b75505Sopenharmony_ci	if (hapd->conf->no_probe_resp_if_max_sta &&
1057e5b75505Sopenharmony_ci	    is_multicast_ether_addr(mgmt->da) &&
1058e5b75505Sopenharmony_ci	    is_multicast_ether_addr(mgmt->bssid) &&
1059e5b75505Sopenharmony_ci	    hapd->num_sta >= hapd->conf->max_num_sta &&
1060e5b75505Sopenharmony_ci	    !ap_get_sta(hapd, mgmt->sa)) {
1061e5b75505Sopenharmony_ci		wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR_SEC
1062e5b75505Sopenharmony_ci			   " since no room for additional STA",
1063e5b75505Sopenharmony_ci			   hapd->conf->iface, MAC2STR_SEC(mgmt->sa));
1064e5b75505Sopenharmony_ci		return;
1065e5b75505Sopenharmony_ci	}
1066e5b75505Sopenharmony_ci
1067e5b75505Sopenharmony_ci#ifdef CONFIG_TESTING_OPTIONS
1068e5b75505Sopenharmony_ci	if (hapd->iconf->ignore_probe_probability > 0.0 &&
1069e5b75505Sopenharmony_ci	    drand48() < hapd->iconf->ignore_probe_probability) {
1070e5b75505Sopenharmony_ci		wpa_printf(MSG_INFO,
1071e5b75505Sopenharmony_ci			   "TESTING: ignoring probe request from " MACSTR_SEC,
1072e5b75505Sopenharmony_ci			   MAC2STR_SEC(mgmt->sa));
1073e5b75505Sopenharmony_ci		return;
1074e5b75505Sopenharmony_ci	}
1075e5b75505Sopenharmony_ci#endif /* CONFIG_TESTING_OPTIONS */
1076e5b75505Sopenharmony_ci
1077e5b75505Sopenharmony_ci	wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, RX_PROBE_REQUEST "sa=" MACSTR
1078e5b75505Sopenharmony_ci		     " signal=%d", MAC2STR(mgmt->sa), ssi_signal);
1079e5b75505Sopenharmony_ci
1080e5b75505Sopenharmony_ci	resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL,
1081e5b75505Sopenharmony_ci				      &resp_len);
1082e5b75505Sopenharmony_ci	if (resp == NULL)
1083e5b75505Sopenharmony_ci		return;
1084e5b75505Sopenharmony_ci
1085e5b75505Sopenharmony_ci	/*
1086e5b75505Sopenharmony_ci	 * If this is a broadcast probe request, apply no ack policy to avoid
1087e5b75505Sopenharmony_ci	 * excessive retries.
1088e5b75505Sopenharmony_ci	 */
1089e5b75505Sopenharmony_ci	noack = !!(res == WILDCARD_SSID_MATCH &&
1090e5b75505Sopenharmony_ci		   is_broadcast_ether_addr(mgmt->da));
1091e5b75505Sopenharmony_ci
1092e5b75505Sopenharmony_ci	csa_offs_len = 0;
1093e5b75505Sopenharmony_ci	if (hapd->csa_in_progress) {
1094e5b75505Sopenharmony_ci		if (hapd->cs_c_off_proberesp)
1095e5b75505Sopenharmony_ci			csa_offs[csa_offs_len++] =
1096e5b75505Sopenharmony_ci				hapd->cs_c_off_proberesp;
1097e5b75505Sopenharmony_ci
1098e5b75505Sopenharmony_ci		if (hapd->cs_c_off_ecsa_proberesp)
1099e5b75505Sopenharmony_ci			csa_offs[csa_offs_len++] =
1100e5b75505Sopenharmony_ci				hapd->cs_c_off_ecsa_proberesp;
1101e5b75505Sopenharmony_ci	}
1102e5b75505Sopenharmony_ci
1103e5b75505Sopenharmony_ci	ret = hostapd_drv_send_mlme(hapd, resp, resp_len, noack,
1104e5b75505Sopenharmony_ci				    csa_offs_len ? csa_offs : NULL,
1105e5b75505Sopenharmony_ci				    csa_offs_len, 0);
1106e5b75505Sopenharmony_ci
1107e5b75505Sopenharmony_ci	if (ret < 0)
1108e5b75505Sopenharmony_ci		wpa_printf(MSG_INFO, "handle_probe_req: send failed");
1109e5b75505Sopenharmony_ci
1110e5b75505Sopenharmony_ci	os_free(resp);
1111e5b75505Sopenharmony_ci
1112e5b75505Sopenharmony_ci	wpa_printf(MSG_EXCESSIVE, "STA " MACSTR_SEC " sent probe request for %s "
1113e5b75505Sopenharmony_ci		   "SSID", MAC2STR_SEC(mgmt->sa),
1114e5b75505Sopenharmony_ci		   elems.ssid_len == 0 ? "broadcast" : "our");
1115e5b75505Sopenharmony_ci}
1116e5b75505Sopenharmony_ci
1117e5b75505Sopenharmony_ci
1118e5b75505Sopenharmony_cistatic u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
1119e5b75505Sopenharmony_ci					size_t *resp_len)
1120e5b75505Sopenharmony_ci{
1121e5b75505Sopenharmony_ci	/* check probe response offloading caps and print warnings */
1122e5b75505Sopenharmony_ci	if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
1123e5b75505Sopenharmony_ci		return NULL;
1124e5b75505Sopenharmony_ci
1125e5b75505Sopenharmony_ci#ifdef CONFIG_WPS
1126e5b75505Sopenharmony_ci	if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
1127e5b75505Sopenharmony_ci	    (!(hapd->iface->probe_resp_offloads &
1128e5b75505Sopenharmony_ci	       (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
1129e5b75505Sopenharmony_ci		WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
1130e5b75505Sopenharmony_ci		wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
1131e5b75505Sopenharmony_ci			   "Probe Response while not supporting this");
1132e5b75505Sopenharmony_ci#endif /* CONFIG_WPS */
1133e5b75505Sopenharmony_ci
1134e5b75505Sopenharmony_ci#ifdef CONFIG_P2P
1135e5b75505Sopenharmony_ci	if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
1136e5b75505Sopenharmony_ci	    !(hapd->iface->probe_resp_offloads &
1137e5b75505Sopenharmony_ci	      WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
1138e5b75505Sopenharmony_ci		wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
1139e5b75505Sopenharmony_ci			   "Probe Response while not supporting this");
1140e5b75505Sopenharmony_ci#endif  /* CONFIG_P2P */
1141e5b75505Sopenharmony_ci
1142e5b75505Sopenharmony_ci	if (hapd->conf->interworking &&
1143e5b75505Sopenharmony_ci	    !(hapd->iface->probe_resp_offloads &
1144e5b75505Sopenharmony_ci	      WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
1145e5b75505Sopenharmony_ci		wpa_printf(MSG_WARNING, "Device is trying to offload "
1146e5b75505Sopenharmony_ci			   "Interworking Probe Response while not supporting "
1147e5b75505Sopenharmony_ci			   "this");
1148e5b75505Sopenharmony_ci
1149e5b75505Sopenharmony_ci	/* Generate a Probe Response template for the non-P2P case */
1150e5b75505Sopenharmony_ci	return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len);
1151e5b75505Sopenharmony_ci}
1152e5b75505Sopenharmony_ci
1153e5b75505Sopenharmony_ci#endif /* NEED_AP_MLME */
1154e5b75505Sopenharmony_ci
1155e5b75505Sopenharmony_ci
1156e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AX
1157e5b75505Sopenharmony_ci/* Unsolicited broadcast Probe Response transmission, 6 GHz only */
1158e5b75505Sopenharmony_cistatic u8 * hostapd_unsol_bcast_probe_resp(struct hostapd_data *hapd,
1159e5b75505Sopenharmony_ci					   struct wpa_driver_ap_params *params)
1160e5b75505Sopenharmony_ci{
1161e5b75505Sopenharmony_ci	if (!is_6ghz_op_class(hapd->iconf->op_class))
1162e5b75505Sopenharmony_ci		return NULL;
1163e5b75505Sopenharmony_ci
1164e5b75505Sopenharmony_ci	params->unsol_bcast_probe_resp_interval =
1165e5b75505Sopenharmony_ci		hapd->conf->unsol_bcast_probe_resp_interval;
1166e5b75505Sopenharmony_ci
1167e5b75505Sopenharmony_ci	return hostapd_gen_probe_resp(hapd, NULL, 0,
1168e5b75505Sopenharmony_ci				      &params->unsol_bcast_probe_resp_tmpl_len);
1169e5b75505Sopenharmony_ci}
1170e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AX */
1171e5b75505Sopenharmony_ci
1172e5b75505Sopenharmony_ci
1173e5b75505Sopenharmony_civoid sta_track_del(struct hostapd_sta_info *info)
1174e5b75505Sopenharmony_ci{
1175e5b75505Sopenharmony_ci#ifdef CONFIG_TAXONOMY
1176e5b75505Sopenharmony_ci	wpabuf_free(info->probe_ie_taxonomy);
1177e5b75505Sopenharmony_ci	info->probe_ie_taxonomy = NULL;
1178e5b75505Sopenharmony_ci#endif /* CONFIG_TAXONOMY */
1179e5b75505Sopenharmony_ci	os_free(info);
1180e5b75505Sopenharmony_ci}
1181e5b75505Sopenharmony_ci
1182e5b75505Sopenharmony_ci
1183e5b75505Sopenharmony_ci#ifdef CONFIG_FILS
1184e5b75505Sopenharmony_ci
1185e5b75505Sopenharmony_cistatic u16 hostapd_fils_discovery_cap(struct hostapd_data *hapd)
1186e5b75505Sopenharmony_ci{
1187e5b75505Sopenharmony_ci	u16 cap_info, phy_index = 0;
1188e5b75505Sopenharmony_ci	u8 chwidth = FD_CAP_BSS_CHWIDTH_20, mcs_nss_size = 4;
1189e5b75505Sopenharmony_ci	struct hostapd_hw_modes *mode = hapd->iface->current_mode;
1190e5b75505Sopenharmony_ci
1191e5b75505Sopenharmony_ci	cap_info = FD_CAP_ESS;
1192e5b75505Sopenharmony_ci	if (hapd->conf->wpa)
1193e5b75505Sopenharmony_ci		cap_info |= FD_CAP_PRIVACY;
1194e5b75505Sopenharmony_ci
1195e5b75505Sopenharmony_ci	if (is_6ghz_op_class(hapd->iconf->op_class)) {
1196e5b75505Sopenharmony_ci		phy_index = FD_CAP_PHY_INDEX_HE;
1197e5b75505Sopenharmony_ci
1198e5b75505Sopenharmony_ci		switch (hapd->iconf->op_class) {
1199e5b75505Sopenharmony_ci		case 135:
1200e5b75505Sopenharmony_ci			mcs_nss_size += 4;
1201e5b75505Sopenharmony_ci			/* fallthrough */
1202e5b75505Sopenharmony_ci		case 134:
1203e5b75505Sopenharmony_ci			mcs_nss_size += 4;
1204e5b75505Sopenharmony_ci			chwidth = FD_CAP_BSS_CHWIDTH_160_80_80;
1205e5b75505Sopenharmony_ci			break;
1206e5b75505Sopenharmony_ci		case 133:
1207e5b75505Sopenharmony_ci			chwidth = FD_CAP_BSS_CHWIDTH_80;
1208e5b75505Sopenharmony_ci			break;
1209e5b75505Sopenharmony_ci		case 132:
1210e5b75505Sopenharmony_ci			chwidth = FD_CAP_BSS_CHWIDTH_40;
1211e5b75505Sopenharmony_ci			break;
1212e5b75505Sopenharmony_ci		}
1213e5b75505Sopenharmony_ci	} else {
1214e5b75505Sopenharmony_ci		switch (hostapd_get_oper_chwidth(hapd->iconf)) {
1215e5b75505Sopenharmony_ci		case CHANWIDTH_80P80MHZ:
1216e5b75505Sopenharmony_ci			mcs_nss_size += 4;
1217e5b75505Sopenharmony_ci			/* fallthrough */
1218e5b75505Sopenharmony_ci		case CHANWIDTH_160MHZ:
1219e5b75505Sopenharmony_ci			mcs_nss_size += 4;
1220e5b75505Sopenharmony_ci			chwidth = FD_CAP_BSS_CHWIDTH_160_80_80;
1221e5b75505Sopenharmony_ci			break;
1222e5b75505Sopenharmony_ci		case CHANWIDTH_80MHZ:
1223e5b75505Sopenharmony_ci			chwidth = FD_CAP_BSS_CHWIDTH_80;
1224e5b75505Sopenharmony_ci			break;
1225e5b75505Sopenharmony_ci		case CHANWIDTH_USE_HT:
1226e5b75505Sopenharmony_ci			if (hapd->iconf->secondary_channel)
1227e5b75505Sopenharmony_ci				chwidth = FD_CAP_BSS_CHWIDTH_40;
1228e5b75505Sopenharmony_ci			else
1229e5b75505Sopenharmony_ci				chwidth = FD_CAP_BSS_CHWIDTH_20;
1230e5b75505Sopenharmony_ci			break;
1231e5b75505Sopenharmony_ci		}
1232e5b75505Sopenharmony_ci
1233e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AX
1234e5b75505Sopenharmony_ci		if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax)
1235e5b75505Sopenharmony_ci			phy_index = FD_CAP_PHY_INDEX_HE;
1236e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AX */
1237e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AC
1238e5b75505Sopenharmony_ci		if (!phy_index &&
1239e5b75505Sopenharmony_ci		    hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac)
1240e5b75505Sopenharmony_ci			phy_index = FD_CAP_PHY_INDEX_VHT;
1241e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AC */
1242e5b75505Sopenharmony_ci		if (!phy_index &&
1243e5b75505Sopenharmony_ci		    hapd->iconf->ieee80211n && !hapd->conf->disable_11n)
1244e5b75505Sopenharmony_ci			phy_index = FD_CAP_PHY_INDEX_HT;
1245e5b75505Sopenharmony_ci	}
1246e5b75505Sopenharmony_ci
1247e5b75505Sopenharmony_ci	cap_info |= phy_index << FD_CAP_PHY_INDEX_SHIFT;
1248e5b75505Sopenharmony_ci	cap_info |= chwidth << FD_CAP_BSS_CHWIDTH_SHIFT;
1249e5b75505Sopenharmony_ci
1250e5b75505Sopenharmony_ci	if (mode) {
1251e5b75505Sopenharmony_ci		u16 *mcs = (u16 *) mode->he_capab[IEEE80211_MODE_AP].mcs;
1252e5b75505Sopenharmony_ci		int i;
1253e5b75505Sopenharmony_ci		u16 nss = 0;
1254e5b75505Sopenharmony_ci
1255e5b75505Sopenharmony_ci		for (i = 0; i < HE_NSS_MAX_STREAMS; i++) {
1256e5b75505Sopenharmony_ci			u16 nss_mask = 0x3 << (i * 2);
1257e5b75505Sopenharmony_ci
1258e5b75505Sopenharmony_ci			if (mcs_nss_size == 4 &&
1259e5b75505Sopenharmony_ci			    (((mcs[0] & nss_mask) == nss_mask) ||
1260e5b75505Sopenharmony_ci			     ((mcs[1] & nss_mask) == nss_mask)))
1261e5b75505Sopenharmony_ci				continue;
1262e5b75505Sopenharmony_ci
1263e5b75505Sopenharmony_ci			if (mcs_nss_size == 8 &&
1264e5b75505Sopenharmony_ci			    (((mcs[2] & nss_mask) == nss_mask) ||
1265e5b75505Sopenharmony_ci			     ((mcs[3] & nss_mask) == nss_mask)))
1266e5b75505Sopenharmony_ci				continue;
1267e5b75505Sopenharmony_ci
1268e5b75505Sopenharmony_ci			if (mcs_nss_size == 12 &&
1269e5b75505Sopenharmony_ci			    (((mcs[4] & nss_mask) == nss_mask) ||
1270e5b75505Sopenharmony_ci			     ((mcs[5] & nss_mask) == nss_mask)))
1271e5b75505Sopenharmony_ci				continue;
1272e5b75505Sopenharmony_ci
1273e5b75505Sopenharmony_ci			nss++;
1274e5b75505Sopenharmony_ci		}
1275e5b75505Sopenharmony_ci
1276e5b75505Sopenharmony_ci		if (nss > 4)
1277e5b75505Sopenharmony_ci			cap_info |= FD_CAP_NSS_5_8 << FD_CAP_NSS_SHIFT;
1278e5b75505Sopenharmony_ci		else if (nss)
1279e5b75505Sopenharmony_ci			cap_info |= (nss - 1) << FD_CAP_NSS_SHIFT;
1280e5b75505Sopenharmony_ci	}
1281e5b75505Sopenharmony_ci
1282e5b75505Sopenharmony_ci	return cap_info;
1283e5b75505Sopenharmony_ci}
1284e5b75505Sopenharmony_ci
1285e5b75505Sopenharmony_ci
1286e5b75505Sopenharmony_cistatic u8 * hostapd_gen_fils_discovery(struct hostapd_data *hapd, size_t *len)
1287e5b75505Sopenharmony_ci{
1288e5b75505Sopenharmony_ci	struct ieee80211_mgmt *head;
1289e5b75505Sopenharmony_ci	const u8 *mobility_domain;
1290e5b75505Sopenharmony_ci	u8 *pos, *length_pos, buf[200];
1291e5b75505Sopenharmony_ci	u16 ctl = 0;
1292e5b75505Sopenharmony_ci	u8 fd_rsn_info[5];
1293e5b75505Sopenharmony_ci	size_t total_len, buf_len;
1294e5b75505Sopenharmony_ci
1295e5b75505Sopenharmony_ci	total_len = 24 + 2 + 12;
1296e5b75505Sopenharmony_ci
1297e5b75505Sopenharmony_ci	/* FILS Discovery Frame Control */
1298e5b75505Sopenharmony_ci	ctl = (sizeof(hapd->conf->ssid.short_ssid) - 1) |
1299e5b75505Sopenharmony_ci		FD_FRAME_CTL_SHORT_SSID_PRESENT |
1300e5b75505Sopenharmony_ci		FD_FRAME_CTL_LENGTH_PRESENT |
1301e5b75505Sopenharmony_ci		FD_FRAME_CTL_CAP_PRESENT;
1302e5b75505Sopenharmony_ci	total_len += 4 + 1 + 2;
1303e5b75505Sopenharmony_ci
1304e5b75505Sopenharmony_ci	/* Check for optional subfields and calculate length */
1305e5b75505Sopenharmony_ci	if (wpa_auth_write_fd_rsn_info(hapd->wpa_auth, fd_rsn_info)) {
1306e5b75505Sopenharmony_ci		ctl |= FD_FRAME_CTL_RSN_INFO_PRESENT;
1307e5b75505Sopenharmony_ci		total_len += sizeof(fd_rsn_info);
1308e5b75505Sopenharmony_ci	}
1309e5b75505Sopenharmony_ci
1310e5b75505Sopenharmony_ci	mobility_domain = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN);
1311e5b75505Sopenharmony_ci	if (mobility_domain) {
1312e5b75505Sopenharmony_ci		ctl |= FD_FRAME_CTL_MD_PRESENT;
1313e5b75505Sopenharmony_ci		total_len += 3;
1314e5b75505Sopenharmony_ci	}
1315e5b75505Sopenharmony_ci
1316e5b75505Sopenharmony_ci	total_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_ACTION);
1317e5b75505Sopenharmony_ci
1318e5b75505Sopenharmony_ci	pos = hostapd_eid_fils_indic(hapd, buf, 0);
1319e5b75505Sopenharmony_ci	buf_len = pos - buf;
1320e5b75505Sopenharmony_ci	total_len += buf_len;
1321e5b75505Sopenharmony_ci
1322e5b75505Sopenharmony_ci	head = os_zalloc(total_len);
1323e5b75505Sopenharmony_ci	if (!head)
1324e5b75505Sopenharmony_ci		return NULL;
1325e5b75505Sopenharmony_ci
1326e5b75505Sopenharmony_ci	head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1327e5b75505Sopenharmony_ci					   WLAN_FC_STYPE_ACTION);
1328e5b75505Sopenharmony_ci	os_memset(head->da, 0xff, ETH_ALEN);
1329e5b75505Sopenharmony_ci	os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1330e5b75505Sopenharmony_ci	os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1331e5b75505Sopenharmony_ci
1332e5b75505Sopenharmony_ci	head->u.action.category = WLAN_ACTION_PUBLIC;
1333e5b75505Sopenharmony_ci	head->u.action.u.public_action.action = WLAN_PA_FILS_DISCOVERY;
1334e5b75505Sopenharmony_ci
1335e5b75505Sopenharmony_ci	pos = &head->u.action.u.public_action.variable[0];
1336e5b75505Sopenharmony_ci
1337e5b75505Sopenharmony_ci	/* FILS Discovery Information field */
1338e5b75505Sopenharmony_ci
1339e5b75505Sopenharmony_ci	/* FILS Discovery Frame Control */
1340e5b75505Sopenharmony_ci	WPA_PUT_LE16(pos, ctl);
1341e5b75505Sopenharmony_ci	pos += 2;
1342e5b75505Sopenharmony_ci
1343e5b75505Sopenharmony_ci	/* Hardware or low-level driver will fill in the Timestamp value */
1344e5b75505Sopenharmony_ci	pos += 8;
1345e5b75505Sopenharmony_ci
1346e5b75505Sopenharmony_ci	/* Beacon Interval */
1347e5b75505Sopenharmony_ci	WPA_PUT_LE16(pos, hapd->iconf->beacon_int);
1348e5b75505Sopenharmony_ci	pos += 2;
1349e5b75505Sopenharmony_ci
1350e5b75505Sopenharmony_ci	/* Short SSID */
1351e5b75505Sopenharmony_ci	WPA_PUT_LE32(pos, hapd->conf->ssid.short_ssid);
1352e5b75505Sopenharmony_ci	pos += sizeof(hapd->conf->ssid.short_ssid);
1353e5b75505Sopenharmony_ci
1354e5b75505Sopenharmony_ci	/* Store position of FILS discovery information element Length field */
1355e5b75505Sopenharmony_ci	length_pos = pos++;
1356e5b75505Sopenharmony_ci
1357e5b75505Sopenharmony_ci	/* FD Capability */
1358e5b75505Sopenharmony_ci	WPA_PUT_LE16(pos, hostapd_fils_discovery_cap(hapd));
1359e5b75505Sopenharmony_ci	pos += 2;
1360e5b75505Sopenharmony_ci
1361e5b75505Sopenharmony_ci	/* Operating Class - not present */
1362e5b75505Sopenharmony_ci
1363e5b75505Sopenharmony_ci	/* Primary Channel - not present */
1364e5b75505Sopenharmony_ci
1365e5b75505Sopenharmony_ci	/* AP Configuration Sequence Number - not present */
1366e5b75505Sopenharmony_ci
1367e5b75505Sopenharmony_ci	/* Access Network Options - not present */
1368e5b75505Sopenharmony_ci
1369e5b75505Sopenharmony_ci	/* FD RSN Information */
1370e5b75505Sopenharmony_ci	if (ctl & FD_FRAME_CTL_RSN_INFO_PRESENT) {
1371e5b75505Sopenharmony_ci		os_memcpy(pos, fd_rsn_info, sizeof(fd_rsn_info));
1372e5b75505Sopenharmony_ci		pos += sizeof(fd_rsn_info);
1373e5b75505Sopenharmony_ci	}
1374e5b75505Sopenharmony_ci
1375e5b75505Sopenharmony_ci	/* Channel Center Frequency Segment 1 - not present */
1376e5b75505Sopenharmony_ci
1377e5b75505Sopenharmony_ci	/* Mobility Domain */
1378e5b75505Sopenharmony_ci	if (ctl & FD_FRAME_CTL_MD_PRESENT) {
1379e5b75505Sopenharmony_ci		os_memcpy(pos, &mobility_domain[2], 3);
1380e5b75505Sopenharmony_ci		pos += 3;
1381e5b75505Sopenharmony_ci	}
1382e5b75505Sopenharmony_ci
1383e5b75505Sopenharmony_ci	/* Fill in the Length field value */
1384e5b75505Sopenharmony_ci	*length_pos = pos - (length_pos + 1);
1385e5b75505Sopenharmony_ci
1386e5b75505Sopenharmony_ci	pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_ACTION);
1387e5b75505Sopenharmony_ci
1388e5b75505Sopenharmony_ci	/* FILS Indication element */
1389e5b75505Sopenharmony_ci	if (buf_len) {
1390e5b75505Sopenharmony_ci		os_memcpy(pos, buf, buf_len);
1391e5b75505Sopenharmony_ci		pos += buf_len;
1392e5b75505Sopenharmony_ci	}
1393e5b75505Sopenharmony_ci
1394e5b75505Sopenharmony_ci	*len = pos - (u8 *) head;
1395e5b75505Sopenharmony_ci	wpa_hexdump(MSG_DEBUG, "FILS Discovery frame template",
1396e5b75505Sopenharmony_ci		    head, pos - (u8 *) head);
1397e5b75505Sopenharmony_ci	return (u8 *) head;
1398e5b75505Sopenharmony_ci}
1399e5b75505Sopenharmony_ci
1400e5b75505Sopenharmony_ci
1401e5b75505Sopenharmony_ci/* Configure FILS Discovery frame transmission parameters */
1402e5b75505Sopenharmony_cistatic u8 * hostapd_fils_discovery(struct hostapd_data *hapd,
1403e5b75505Sopenharmony_ci				   struct wpa_driver_ap_params *params)
1404e5b75505Sopenharmony_ci{
1405e5b75505Sopenharmony_ci	params->fd_max_int = hapd->conf->fils_discovery_max_int;
1406e5b75505Sopenharmony_ci	if (is_6ghz_op_class(hapd->iconf->op_class) &&
1407e5b75505Sopenharmony_ci	    params->fd_max_int > FD_MAX_INTERVAL_6GHZ)
1408e5b75505Sopenharmony_ci		params->fd_max_int = FD_MAX_INTERVAL_6GHZ;
1409e5b75505Sopenharmony_ci
1410e5b75505Sopenharmony_ci	params->fd_min_int = hapd->conf->fils_discovery_min_int;
1411e5b75505Sopenharmony_ci	if (params->fd_min_int > params->fd_max_int)
1412e5b75505Sopenharmony_ci		params->fd_min_int = params->fd_max_int;
1413e5b75505Sopenharmony_ci
1414e5b75505Sopenharmony_ci	if (params->fd_max_int)
1415e5b75505Sopenharmony_ci		return hostapd_gen_fils_discovery(hapd,
1416e5b75505Sopenharmony_ci						  &params->fd_frame_tmpl_len);
1417e5b75505Sopenharmony_ci
1418e5b75505Sopenharmony_ci	return NULL;
1419e5b75505Sopenharmony_ci}
1420e5b75505Sopenharmony_ci
1421e5b75505Sopenharmony_ci#endif /* CONFIG_FILS */
1422e5b75505Sopenharmony_ci
1423e5b75505Sopenharmony_ci
1424e5b75505Sopenharmony_ciint ieee802_11_build_ap_params(struct hostapd_data *hapd,
1425e5b75505Sopenharmony_ci			       struct wpa_driver_ap_params *params)
1426e5b75505Sopenharmony_ci{
1427e5b75505Sopenharmony_ci	struct ieee80211_mgmt *head = NULL;
1428e5b75505Sopenharmony_ci	u8 *tail = NULL;
1429e5b75505Sopenharmony_ci	size_t head_len = 0, tail_len = 0;
1430e5b75505Sopenharmony_ci	u8 *resp = NULL;
1431e5b75505Sopenharmony_ci	size_t resp_len = 0;
1432e5b75505Sopenharmony_ci#ifdef NEED_AP_MLME
1433e5b75505Sopenharmony_ci	u16 capab_info;
1434e5b75505Sopenharmony_ci	u8 *pos, *tailpos, *tailend, *csa_pos;
1435e5b75505Sopenharmony_ci
1436e5b75505Sopenharmony_ci#define BEACON_HEAD_BUF_SIZE 256
1437e5b75505Sopenharmony_ci#define BEACON_TAIL_BUF_SIZE 512
1438e5b75505Sopenharmony_ci	head = os_zalloc(BEACON_HEAD_BUF_SIZE);
1439e5b75505Sopenharmony_ci	tail_len = BEACON_TAIL_BUF_SIZE;
1440e5b75505Sopenharmony_ci#ifdef CONFIG_WPS
1441e5b75505Sopenharmony_ci	if (hapd->conf->wps_state && hapd->wps_beacon_ie)
1442e5b75505Sopenharmony_ci		tail_len += wpabuf_len(hapd->wps_beacon_ie);
1443e5b75505Sopenharmony_ci#endif /* CONFIG_WPS */
1444e5b75505Sopenharmony_ci#ifdef CONFIG_P2P
1445e5b75505Sopenharmony_ci	if (hapd->p2p_beacon_ie)
1446e5b75505Sopenharmony_ci		tail_len += wpabuf_len(hapd->p2p_beacon_ie);
1447e5b75505Sopenharmony_ci#endif /* CONFIG_P2P */
1448e5b75505Sopenharmony_ci#ifdef CONFIG_FST
1449e5b75505Sopenharmony_ci	if (hapd->iface->fst_ies)
1450e5b75505Sopenharmony_ci		tail_len += wpabuf_len(hapd->iface->fst_ies);
1451e5b75505Sopenharmony_ci#endif /* CONFIG_FST */
1452e5b75505Sopenharmony_ci	if (hapd->conf->vendor_elements)
1453e5b75505Sopenharmony_ci		tail_len += wpabuf_len(hapd->conf->vendor_elements);
1454e5b75505Sopenharmony_ci
1455e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AC
1456e5b75505Sopenharmony_ci	if (hapd->conf->vendor_vht) {
1457e5b75505Sopenharmony_ci		tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
1458e5b75505Sopenharmony_ci			2 + sizeof(struct ieee80211_vht_operation);
1459e5b75505Sopenharmony_ci	}
1460e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AC */
1461e5b75505Sopenharmony_ci
1462e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AX
1463e5b75505Sopenharmony_ci	if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
1464e5b75505Sopenharmony_ci		tail_len += 3 + sizeof(struct ieee80211_he_capabilities) +
1465e5b75505Sopenharmony_ci			3 + sizeof(struct ieee80211_he_operation) +
1466e5b75505Sopenharmony_ci			3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
1467e5b75505Sopenharmony_ci			3 + sizeof(struct ieee80211_spatial_reuse);
1468e5b75505Sopenharmony_ci		if (is_6ghz_op_class(hapd->iconf->op_class))
1469e5b75505Sopenharmony_ci			tail_len += sizeof(struct ieee80211_he_6ghz_oper_info) +
1470e5b75505Sopenharmony_ci				3 + sizeof(struct ieee80211_he_6ghz_band_cap);
1471e5b75505Sopenharmony_ci	}
1472e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AX */
1473e5b75505Sopenharmony_ci
1474e5b75505Sopenharmony_ci	tail_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_BEACON);
1475e5b75505Sopenharmony_ci	tail_len += hostapd_mbo_ie_len(hapd);
1476e5b75505Sopenharmony_ci	tail_len += hostapd_eid_owe_trans_len(hapd);
1477e5b75505Sopenharmony_ci	tail_len += hostapd_eid_dpp_cc_len(hapd);
1478e5b75505Sopenharmony_ci
1479e5b75505Sopenharmony_ci	tailpos = tail = os_malloc(tail_len);
1480e5b75505Sopenharmony_ci	if (head == NULL || tail == NULL) {
1481e5b75505Sopenharmony_ci		wpa_printf(MSG_ERROR, "Failed to set beacon data");
1482e5b75505Sopenharmony_ci		os_free(head);
1483e5b75505Sopenharmony_ci		os_free(tail);
1484e5b75505Sopenharmony_ci		return -1;
1485e5b75505Sopenharmony_ci	}
1486e5b75505Sopenharmony_ci	tailend = tail + tail_len;
1487e5b75505Sopenharmony_ci
1488e5b75505Sopenharmony_ci	head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1489e5b75505Sopenharmony_ci					   WLAN_FC_STYPE_BEACON);
1490e5b75505Sopenharmony_ci	head->duration = host_to_le16(0);
1491e5b75505Sopenharmony_ci	os_memset(head->da, 0xff, ETH_ALEN);
1492e5b75505Sopenharmony_ci
1493e5b75505Sopenharmony_ci	os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1494e5b75505Sopenharmony_ci	os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1495e5b75505Sopenharmony_ci	head->u.beacon.beacon_int =
1496e5b75505Sopenharmony_ci		host_to_le16(hapd->iconf->beacon_int);
1497e5b75505Sopenharmony_ci
1498e5b75505Sopenharmony_ci	/* hardware or low-level driver will setup seq_ctrl and timestamp */
1499e5b75505Sopenharmony_ci	capab_info = hostapd_own_capab_info(hapd);
1500e5b75505Sopenharmony_ci	head->u.beacon.capab_info = host_to_le16(capab_info);
1501e5b75505Sopenharmony_ci	pos = &head->u.beacon.variable[0];
1502e5b75505Sopenharmony_ci
1503e5b75505Sopenharmony_ci	/* SSID */
1504e5b75505Sopenharmony_ci	*pos++ = WLAN_EID_SSID;
1505e5b75505Sopenharmony_ci	if (hapd->conf->ignore_broadcast_ssid == 2) {
1506e5b75505Sopenharmony_ci		/* clear the data, but keep the correct length of the SSID */
1507e5b75505Sopenharmony_ci		*pos++ = hapd->conf->ssid.ssid_len;
1508e5b75505Sopenharmony_ci		os_memset(pos, 0, hapd->conf->ssid.ssid_len);
1509e5b75505Sopenharmony_ci		pos += hapd->conf->ssid.ssid_len;
1510e5b75505Sopenharmony_ci	} else if (hapd->conf->ignore_broadcast_ssid) {
1511e5b75505Sopenharmony_ci		*pos++ = 0; /* empty SSID */
1512e5b75505Sopenharmony_ci	} else {
1513e5b75505Sopenharmony_ci		*pos++ = hapd->conf->ssid.ssid_len;
1514e5b75505Sopenharmony_ci		os_memcpy(pos, hapd->conf->ssid.ssid,
1515e5b75505Sopenharmony_ci			  hapd->conf->ssid.ssid_len);
1516e5b75505Sopenharmony_ci		pos += hapd->conf->ssid.ssid_len;
1517e5b75505Sopenharmony_ci	}
1518e5b75505Sopenharmony_ci
1519e5b75505Sopenharmony_ci	/* Supported rates */
1520e5b75505Sopenharmony_ci	pos = hostapd_eid_supp_rates(hapd, pos);
1521e5b75505Sopenharmony_ci
1522e5b75505Sopenharmony_ci	/* DS Params */
1523e5b75505Sopenharmony_ci	pos = hostapd_eid_ds_params(hapd, pos);
1524e5b75505Sopenharmony_ci
1525e5b75505Sopenharmony_ci	head_len = pos - (u8 *) head;
1526e5b75505Sopenharmony_ci
1527e5b75505Sopenharmony_ci	tailpos = hostapd_eid_country(hapd, tailpos, tailend - tailpos);
1528e5b75505Sopenharmony_ci
1529e5b75505Sopenharmony_ci	/* Power Constraint element */
1530e5b75505Sopenharmony_ci	tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
1531e5b75505Sopenharmony_ci
1532e5b75505Sopenharmony_ci	/* CSA IE */
1533e5b75505Sopenharmony_ci	csa_pos = hostapd_eid_csa(hapd, tailpos);
1534e5b75505Sopenharmony_ci	if (csa_pos != tailpos)
1535e5b75505Sopenharmony_ci		hapd->cs_c_off_beacon = csa_pos - tail - 1;
1536e5b75505Sopenharmony_ci	tailpos = csa_pos;
1537e5b75505Sopenharmony_ci
1538e5b75505Sopenharmony_ci	/* ERP Information element */
1539e5b75505Sopenharmony_ci	tailpos = hostapd_eid_erp_info(hapd, tailpos);
1540e5b75505Sopenharmony_ci
1541e5b75505Sopenharmony_ci	/* Extended supported rates */
1542e5b75505Sopenharmony_ci	tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
1543e5b75505Sopenharmony_ci
1544e5b75505Sopenharmony_ci	tailpos = hostapd_get_rsne(hapd, tailpos, tailend - tailpos);
1545e5b75505Sopenharmony_ci	tailpos = hostapd_eid_bss_load(hapd, tailpos, tailend - tailpos);
1546e5b75505Sopenharmony_ci	tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
1547e5b75505Sopenharmony_ci					       tailend - tailpos);
1548e5b75505Sopenharmony_ci	tailpos = hostapd_get_mde(hapd, tailpos, tailend - tailpos);
1549e5b75505Sopenharmony_ci
1550e5b75505Sopenharmony_ci	/* eCSA IE */
1551e5b75505Sopenharmony_ci	csa_pos = hostapd_eid_ecsa(hapd, tailpos);
1552e5b75505Sopenharmony_ci	if (csa_pos != tailpos)
1553e5b75505Sopenharmony_ci		hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1;
1554e5b75505Sopenharmony_ci	tailpos = csa_pos;
1555e5b75505Sopenharmony_ci
1556e5b75505Sopenharmony_ci	tailpos = hostapd_eid_supported_op_classes(hapd, tailpos);
1557e5b75505Sopenharmony_ci	tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
1558e5b75505Sopenharmony_ci	tailpos = hostapd_eid_ht_operation(hapd, tailpos);
1559e5b75505Sopenharmony_ci
1560e5b75505Sopenharmony_ci	tailpos = hostapd_eid_ext_capab(hapd, tailpos);
1561e5b75505Sopenharmony_ci
1562e5b75505Sopenharmony_ci	/*
1563e5b75505Sopenharmony_ci	 * TODO: Time Advertisement element should only be included in some
1564e5b75505Sopenharmony_ci	 * DTIM Beacon frames.
1565e5b75505Sopenharmony_ci	 */
1566e5b75505Sopenharmony_ci	tailpos = hostapd_eid_time_adv(hapd, tailpos);
1567e5b75505Sopenharmony_ci
1568e5b75505Sopenharmony_ci	tailpos = hostapd_eid_interworking(hapd, tailpos);
1569e5b75505Sopenharmony_ci	tailpos = hostapd_eid_adv_proto(hapd, tailpos);
1570e5b75505Sopenharmony_ci	tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
1571e5b75505Sopenharmony_ci
1572e5b75505Sopenharmony_ci#ifdef CONFIG_FST
1573e5b75505Sopenharmony_ci	if (hapd->iface->fst_ies) {
1574e5b75505Sopenharmony_ci		os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies),
1575e5b75505Sopenharmony_ci			  wpabuf_len(hapd->iface->fst_ies));
1576e5b75505Sopenharmony_ci		tailpos += wpabuf_len(hapd->iface->fst_ies);
1577e5b75505Sopenharmony_ci	}
1578e5b75505Sopenharmony_ci#endif /* CONFIG_FST */
1579e5b75505Sopenharmony_ci
1580e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AC
1581e5b75505Sopenharmony_ci	if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
1582e5b75505Sopenharmony_ci	    !is_6ghz_op_class(hapd->iconf->op_class)) {
1583e5b75505Sopenharmony_ci		tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0);
1584e5b75505Sopenharmony_ci		tailpos = hostapd_eid_vht_operation(hapd, tailpos);
1585e5b75505Sopenharmony_ci		tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
1586e5b75505Sopenharmony_ci	}
1587e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AC */
1588e5b75505Sopenharmony_ci
1589e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AX
1590e5b75505Sopenharmony_ci	if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax &&
1591e5b75505Sopenharmony_ci	    is_6ghz_op_class(hapd->iconf->op_class))
1592e5b75505Sopenharmony_ci		tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
1593e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AX */
1594e5b75505Sopenharmony_ci
1595e5b75505Sopenharmony_ci	tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos);
1596e5b75505Sopenharmony_ci
1597e5b75505Sopenharmony_ci	tailpos = hostapd_eid_rnr(hapd, tailpos, WLAN_FC_STYPE_BEACON);
1598e5b75505Sopenharmony_ci	tailpos = hostapd_eid_fils_indic(hapd, tailpos, 0);
1599e5b75505Sopenharmony_ci	tailpos = hostapd_get_rsnxe(hapd, tailpos, tailend - tailpos);
1600e5b75505Sopenharmony_ci
1601e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AX
1602e5b75505Sopenharmony_ci	if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
1603e5b75505Sopenharmony_ci		tailpos = hostapd_eid_he_capab(hapd, tailpos,
1604e5b75505Sopenharmony_ci					       IEEE80211_MODE_AP);
1605e5b75505Sopenharmony_ci		tailpos = hostapd_eid_he_operation(hapd, tailpos);
1606e5b75505Sopenharmony_ci		tailpos = hostapd_eid_spatial_reuse(hapd, tailpos);
1607e5b75505Sopenharmony_ci		tailpos = hostapd_eid_he_mu_edca_parameter_set(hapd, tailpos);
1608e5b75505Sopenharmony_ci		tailpos = hostapd_eid_he_6ghz_band_cap(hapd, tailpos);
1609e5b75505Sopenharmony_ci	}
1610e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AX */
1611e5b75505Sopenharmony_ci
1612e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AC
1613e5b75505Sopenharmony_ci	if (hapd->conf->vendor_vht)
1614e5b75505Sopenharmony_ci		tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
1615e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AC */
1616e5b75505Sopenharmony_ci
1617e5b75505Sopenharmony_ci	/* WPA / OSEN */
1618e5b75505Sopenharmony_ci	tailpos = hostapd_get_wpa_ie(hapd, tailpos, tailend - tailpos);
1619e5b75505Sopenharmony_ci	tailpos = hostapd_get_osen_ie(hapd, tailpos, tailend - tailpos);
1620e5b75505Sopenharmony_ci
1621e5b75505Sopenharmony_ci	/* Wi-Fi Alliance WMM */
1622e5b75505Sopenharmony_ci	tailpos = hostapd_eid_wmm(hapd, tailpos);
1623e5b75505Sopenharmony_ci
1624e5b75505Sopenharmony_ci#ifdef CONFIG_WPS
1625e5b75505Sopenharmony_ci	if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
1626e5b75505Sopenharmony_ci		os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
1627e5b75505Sopenharmony_ci			  wpabuf_len(hapd->wps_beacon_ie));
1628e5b75505Sopenharmony_ci		tailpos += wpabuf_len(hapd->wps_beacon_ie);
1629e5b75505Sopenharmony_ci	}
1630e5b75505Sopenharmony_ci#endif /* CONFIG_WPS */
1631e5b75505Sopenharmony_ci
1632e5b75505Sopenharmony_ci#ifdef CONFIG_P2P
1633e5b75505Sopenharmony_ci	if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
1634e5b75505Sopenharmony_ci		os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
1635e5b75505Sopenharmony_ci			  wpabuf_len(hapd->p2p_beacon_ie));
1636e5b75505Sopenharmony_ci		tailpos += wpabuf_len(hapd->p2p_beacon_ie);
1637e5b75505Sopenharmony_ci	}
1638e5b75505Sopenharmony_ci#endif /* CONFIG_P2P */
1639e5b75505Sopenharmony_ci#ifdef CONFIG_P2P_MANAGER
1640e5b75505Sopenharmony_ci	if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
1641e5b75505Sopenharmony_ci	    P2P_MANAGE)
1642e5b75505Sopenharmony_ci		tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
1643e5b75505Sopenharmony_ci#endif /* CONFIG_P2P_MANAGER */
1644e5b75505Sopenharmony_ci
1645e5b75505Sopenharmony_ci#ifdef CONFIG_HS20
1646e5b75505Sopenharmony_ci	tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
1647e5b75505Sopenharmony_ci#endif /* CONFIG_HS20 */
1648e5b75505Sopenharmony_ci
1649e5b75505Sopenharmony_ci	tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos);
1650e5b75505Sopenharmony_ci	tailpos = hostapd_eid_owe_trans(hapd, tailpos,
1651e5b75505Sopenharmony_ci					tail + tail_len - tailpos);
1652e5b75505Sopenharmony_ci	tailpos = hostapd_eid_dpp_cc(hapd, tailpos, tail + tail_len - tailpos);
1653e5b75505Sopenharmony_ci
1654e5b75505Sopenharmony_ci	if (hapd->conf->vendor_elements) {
1655e5b75505Sopenharmony_ci		os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
1656e5b75505Sopenharmony_ci			  wpabuf_len(hapd->conf->vendor_elements));
1657e5b75505Sopenharmony_ci		tailpos += wpabuf_len(hapd->conf->vendor_elements);
1658e5b75505Sopenharmony_ci	}
1659e5b75505Sopenharmony_ci
1660e5b75505Sopenharmony_ci	tail_len = tailpos > tail ? tailpos - tail : 0;
1661e5b75505Sopenharmony_ci
1662e5b75505Sopenharmony_ci	resp = hostapd_probe_resp_offloads(hapd, &resp_len);
1663e5b75505Sopenharmony_ci#endif /* NEED_AP_MLME */
1664e5b75505Sopenharmony_ci
1665e5b75505Sopenharmony_ci	os_memset(params, 0, sizeof(*params));
1666e5b75505Sopenharmony_ci	params->head = (u8 *) head;
1667e5b75505Sopenharmony_ci	params->head_len = head_len;
1668e5b75505Sopenharmony_ci	params->tail = tail;
1669e5b75505Sopenharmony_ci	params->tail_len = tail_len;
1670e5b75505Sopenharmony_ci	params->proberesp = resp;
1671e5b75505Sopenharmony_ci	params->proberesp_len = resp_len;
1672e5b75505Sopenharmony_ci	params->dtim_period = hapd->conf->dtim_period;
1673e5b75505Sopenharmony_ci	params->beacon_int = hapd->iconf->beacon_int;
1674e5b75505Sopenharmony_ci	params->basic_rates = hapd->iface->basic_rates;
1675e5b75505Sopenharmony_ci	params->beacon_rate = hapd->iconf->beacon_rate;
1676e5b75505Sopenharmony_ci	params->rate_type = hapd->iconf->rate_type;
1677e5b75505Sopenharmony_ci	params->ssid = hapd->conf->ssid.ssid;
1678e5b75505Sopenharmony_ci	params->ssid_len = hapd->conf->ssid.ssid_len;
1679e5b75505Sopenharmony_ci	if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
1680e5b75505Sopenharmony_ci	    (WPA_PROTO_WPA | WPA_PROTO_RSN))
1681e5b75505Sopenharmony_ci		params->pairwise_ciphers = hapd->conf->wpa_pairwise |
1682e5b75505Sopenharmony_ci			hapd->conf->rsn_pairwise;
1683e5b75505Sopenharmony_ci	else if (hapd->conf->wpa & WPA_PROTO_RSN)
1684e5b75505Sopenharmony_ci		params->pairwise_ciphers = hapd->conf->rsn_pairwise;
1685e5b75505Sopenharmony_ci	else if (hapd->conf->wpa & WPA_PROTO_WPA)
1686e5b75505Sopenharmony_ci		params->pairwise_ciphers = hapd->conf->wpa_pairwise;
1687e5b75505Sopenharmony_ci	params->group_cipher = hapd->conf->wpa_group;
1688e5b75505Sopenharmony_ci	params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
1689e5b75505Sopenharmony_ci	params->auth_algs = hapd->conf->auth_algs;
1690e5b75505Sopenharmony_ci	params->wpa_version = hapd->conf->wpa;
1691e5b75505Sopenharmony_ci	params->privacy = hapd->conf->wpa;
1692e5b75505Sopenharmony_ci#ifdef CONFIG_WEP
1693e5b75505Sopenharmony_ci	params->privacy |= hapd->conf->ssid.wep.keys_set ||
1694e5b75505Sopenharmony_ci		(hapd->conf->ieee802_1x &&
1695e5b75505Sopenharmony_ci		 (hapd->conf->default_wep_key_len ||
1696e5b75505Sopenharmony_ci		  hapd->conf->individual_wep_key_len));
1697e5b75505Sopenharmony_ci#endif /* CONFIG_WEP */
1698e5b75505Sopenharmony_ci	switch (hapd->conf->ignore_broadcast_ssid) {
1699e5b75505Sopenharmony_ci	case 0:
1700e5b75505Sopenharmony_ci		params->hide_ssid = NO_SSID_HIDING;
1701e5b75505Sopenharmony_ci		break;
1702e5b75505Sopenharmony_ci	case 1:
1703e5b75505Sopenharmony_ci		params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
1704e5b75505Sopenharmony_ci		break;
1705e5b75505Sopenharmony_ci	case 2:
1706e5b75505Sopenharmony_ci		params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
1707e5b75505Sopenharmony_ci		break;
1708e5b75505Sopenharmony_ci	}
1709e5b75505Sopenharmony_ci	params->isolate = hapd->conf->isolate;
1710e5b75505Sopenharmony_ci#ifdef NEED_AP_MLME
1711e5b75505Sopenharmony_ci	params->cts_protect = !!(ieee802_11_erp_info(hapd) &
1712e5b75505Sopenharmony_ci				ERP_INFO_USE_PROTECTION);
1713e5b75505Sopenharmony_ci	params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
1714e5b75505Sopenharmony_ci		hapd->iconf->preamble == SHORT_PREAMBLE;
1715e5b75505Sopenharmony_ci	if (hapd->iface->current_mode &&
1716e5b75505Sopenharmony_ci	    hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1717e5b75505Sopenharmony_ci		params->short_slot_time =
1718e5b75505Sopenharmony_ci			hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
1719e5b75505Sopenharmony_ci	else
1720e5b75505Sopenharmony_ci		params->short_slot_time = -1;
1721e5b75505Sopenharmony_ci	if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
1722e5b75505Sopenharmony_ci		params->ht_opmode = -1;
1723e5b75505Sopenharmony_ci	else
1724e5b75505Sopenharmony_ci		params->ht_opmode = hapd->iface->ht_op_mode;
1725e5b75505Sopenharmony_ci#endif /* NEED_AP_MLME */
1726e5b75505Sopenharmony_ci	params->interworking = hapd->conf->interworking;
1727e5b75505Sopenharmony_ci	if (hapd->conf->interworking &&
1728e5b75505Sopenharmony_ci	    !is_zero_ether_addr(hapd->conf->hessid))
1729e5b75505Sopenharmony_ci		params->hessid = hapd->conf->hessid;
1730e5b75505Sopenharmony_ci	params->access_network_type = hapd->conf->access_network_type;
1731e5b75505Sopenharmony_ci	params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
1732e5b75505Sopenharmony_ci#ifdef CONFIG_P2P
1733e5b75505Sopenharmony_ci	params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
1734e5b75505Sopenharmony_ci#endif /* CONFIG_P2P */
1735e5b75505Sopenharmony_ci#ifdef CONFIG_HS20
1736e5b75505Sopenharmony_ci	params->disable_dgaf = hapd->conf->disable_dgaf;
1737e5b75505Sopenharmony_ci	if (hapd->conf->osen) {
1738e5b75505Sopenharmony_ci		params->privacy = 1;
1739e5b75505Sopenharmony_ci		params->osen = 1;
1740e5b75505Sopenharmony_ci	}
1741e5b75505Sopenharmony_ci#endif /* CONFIG_HS20 */
1742e5b75505Sopenharmony_ci	params->multicast_to_unicast = hapd->conf->multicast_to_unicast;
1743e5b75505Sopenharmony_ci	params->pbss = hapd->conf->pbss;
1744e5b75505Sopenharmony_ci
1745e5b75505Sopenharmony_ci	if (hapd->conf->ftm_responder) {
1746e5b75505Sopenharmony_ci		if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_FTM_RESPONDER) {
1747e5b75505Sopenharmony_ci			params->ftm_responder = 1;
1748e5b75505Sopenharmony_ci			params->lci = hapd->iface->conf->lci;
1749e5b75505Sopenharmony_ci			params->civic = hapd->iface->conf->civic;
1750e5b75505Sopenharmony_ci		} else {
1751e5b75505Sopenharmony_ci			wpa_printf(MSG_WARNING,
1752e5b75505Sopenharmony_ci				   "Not configuring FTM responder as the driver doesn't advertise support for it");
1753e5b75505Sopenharmony_ci		}
1754e5b75505Sopenharmony_ci	}
1755e5b75505Sopenharmony_ci
1756e5b75505Sopenharmony_ci	return 0;
1757e5b75505Sopenharmony_ci}
1758e5b75505Sopenharmony_ci
1759e5b75505Sopenharmony_ci
1760e5b75505Sopenharmony_civoid ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
1761e5b75505Sopenharmony_ci{
1762e5b75505Sopenharmony_ci	os_free(params->tail);
1763e5b75505Sopenharmony_ci	params->tail = NULL;
1764e5b75505Sopenharmony_ci	os_free(params->head);
1765e5b75505Sopenharmony_ci	params->head = NULL;
1766e5b75505Sopenharmony_ci	os_free(params->proberesp);
1767e5b75505Sopenharmony_ci	params->proberesp = NULL;
1768e5b75505Sopenharmony_ci#ifdef CONFIG_FILS
1769e5b75505Sopenharmony_ci	os_free(params->fd_frame_tmpl);
1770e5b75505Sopenharmony_ci	params->fd_frame_tmpl = NULL;
1771e5b75505Sopenharmony_ci#endif /* CONFIG_FILS */
1772e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AX
1773e5b75505Sopenharmony_ci	os_free(params->unsol_bcast_probe_resp_tmpl);
1774e5b75505Sopenharmony_ci	params->unsol_bcast_probe_resp_tmpl = NULL;
1775e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AX */
1776e5b75505Sopenharmony_ci}
1777e5b75505Sopenharmony_ci
1778e5b75505Sopenharmony_ci
1779e5b75505Sopenharmony_cistatic int __ieee802_11_set_beacon(struct hostapd_data *hapd)
1780e5b75505Sopenharmony_ci{
1781e5b75505Sopenharmony_ci	struct wpa_driver_ap_params params;
1782e5b75505Sopenharmony_ci	struct hostapd_freq_params freq;
1783e5b75505Sopenharmony_ci	struct hostapd_iface *iface = hapd->iface;
1784e5b75505Sopenharmony_ci	struct hostapd_config *iconf = iface->conf;
1785e5b75505Sopenharmony_ci	struct hostapd_hw_modes *cmode = iface->current_mode;
1786e5b75505Sopenharmony_ci	struct wpabuf *beacon, *proberesp, *assocresp;
1787e5b75505Sopenharmony_ci	int res, ret = -1;
1788e5b75505Sopenharmony_ci
1789e5b75505Sopenharmony_ci	if (!hapd->drv_priv) {
1790e5b75505Sopenharmony_ci		wpa_printf(MSG_ERROR, "Interface is disabled");
1791e5b75505Sopenharmony_ci		return -1;
1792e5b75505Sopenharmony_ci	}
1793e5b75505Sopenharmony_ci
1794e5b75505Sopenharmony_ci	if (hapd->csa_in_progress) {
1795e5b75505Sopenharmony_ci		wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
1796e5b75505Sopenharmony_ci		return -1;
1797e5b75505Sopenharmony_ci	}
1798e5b75505Sopenharmony_ci
1799e5b75505Sopenharmony_ci	hapd->beacon_set_done = 1;
1800e5b75505Sopenharmony_ci
1801e5b75505Sopenharmony_ci	if (ieee802_11_build_ap_params(hapd, &params) < 0)
1802e5b75505Sopenharmony_ci		return -1;
1803e5b75505Sopenharmony_ci
1804e5b75505Sopenharmony_ci	if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
1805e5b75505Sopenharmony_ci	    0)
1806e5b75505Sopenharmony_ci		goto fail;
1807e5b75505Sopenharmony_ci
1808e5b75505Sopenharmony_ci	params.beacon_ies = beacon;
1809e5b75505Sopenharmony_ci	params.proberesp_ies = proberesp;
1810e5b75505Sopenharmony_ci	params.assocresp_ies = assocresp;
1811e5b75505Sopenharmony_ci	params.reenable = hapd->reenable_beacon;
1812e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AX
1813e5b75505Sopenharmony_ci	params.he_spr_ctrl = hapd->iface->conf->spr.sr_control;
1814e5b75505Sopenharmony_ci	params.he_spr_non_srg_obss_pd_max_offset =
1815e5b75505Sopenharmony_ci		hapd->iface->conf->spr.non_srg_obss_pd_max_offset;
1816e5b75505Sopenharmony_ci	params.he_spr_srg_obss_pd_min_offset =
1817e5b75505Sopenharmony_ci		hapd->iface->conf->spr.srg_obss_pd_min_offset;
1818e5b75505Sopenharmony_ci	params.he_spr_srg_obss_pd_max_offset =
1819e5b75505Sopenharmony_ci		hapd->iface->conf->spr.srg_obss_pd_max_offset;
1820e5b75505Sopenharmony_ci	os_memcpy(params.he_spr_bss_color_bitmap,
1821e5b75505Sopenharmony_ci		  hapd->iface->conf->spr.srg_bss_color_bitmap, 8);
1822e5b75505Sopenharmony_ci	os_memcpy(params.he_spr_partial_bssid_bitmap,
1823e5b75505Sopenharmony_ci		  hapd->iface->conf->spr.srg_partial_bssid_bitmap, 8);
1824e5b75505Sopenharmony_ci	params.he_bss_color_disabled =
1825e5b75505Sopenharmony_ci		hapd->iface->conf->he_op.he_bss_color_disabled;
1826e5b75505Sopenharmony_ci	params.he_bss_color_partial =
1827e5b75505Sopenharmony_ci		hapd->iface->conf->he_op.he_bss_color_partial;
1828e5b75505Sopenharmony_ci	params.he_bss_color = hapd->iface->conf->he_op.he_bss_color;
1829e5b75505Sopenharmony_ci	params.twt_responder = hostapd_get_he_twt_responder(hapd,
1830e5b75505Sopenharmony_ci							    IEEE80211_MODE_AP);
1831e5b75505Sopenharmony_ci	params.unsol_bcast_probe_resp_tmpl =
1832e5b75505Sopenharmony_ci		hostapd_unsol_bcast_probe_resp(hapd, &params);
1833e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AX */
1834e5b75505Sopenharmony_ci	hapd->reenable_beacon = 0;
1835e5b75505Sopenharmony_ci#ifdef CONFIG_SAE
1836e5b75505Sopenharmony_ci	params.sae_pwe = hapd->conf->sae_pwe;
1837e5b75505Sopenharmony_ci#endif /* CONFIG_SAE */
1838e5b75505Sopenharmony_ci
1839e5b75505Sopenharmony_ci#ifdef CONFIG_FILS
1840e5b75505Sopenharmony_ci	params.fd_frame_tmpl = hostapd_fils_discovery(hapd, &params);
1841e5b75505Sopenharmony_ci#endif /* CONFIG_FILS */
1842e5b75505Sopenharmony_ci
1843e5b75505Sopenharmony_ci	if (cmode &&
1844e5b75505Sopenharmony_ci	    hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
1845e5b75505Sopenharmony_ci				    iconf->channel, iconf->enable_edmg,
1846e5b75505Sopenharmony_ci				    iconf->edmg_channel, iconf->ieee80211n,
1847e5b75505Sopenharmony_ci				    iconf->ieee80211ac, iconf->ieee80211ax,
1848e5b75505Sopenharmony_ci				    iconf->secondary_channel,
1849e5b75505Sopenharmony_ci				    hostapd_get_oper_chwidth(iconf),
1850e5b75505Sopenharmony_ci				    hostapd_get_oper_centr_freq_seg0_idx(iconf),
1851e5b75505Sopenharmony_ci				    hostapd_get_oper_centr_freq_seg1_idx(iconf),
1852e5b75505Sopenharmony_ci				    cmode->vht_capab,
1853e5b75505Sopenharmony_ci				    &cmode->he_capab[IEEE80211_MODE_AP]) == 0)
1854e5b75505Sopenharmony_ci		params.freq = &freq;
1855e5b75505Sopenharmony_ci
1856e5b75505Sopenharmony_ci	res = hostapd_drv_set_ap(hapd, &params);
1857e5b75505Sopenharmony_ci	hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
1858e5b75505Sopenharmony_ci	if (res)
1859e5b75505Sopenharmony_ci		wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
1860e5b75505Sopenharmony_ci	else
1861e5b75505Sopenharmony_ci		ret = 0;
1862e5b75505Sopenharmony_cifail:
1863e5b75505Sopenharmony_ci	ieee802_11_free_ap_params(&params);
1864e5b75505Sopenharmony_ci	return ret;
1865e5b75505Sopenharmony_ci}
1866e5b75505Sopenharmony_ci
1867e5b75505Sopenharmony_ci
1868e5b75505Sopenharmony_ciint ieee802_11_set_beacon(struct hostapd_data *hapd)
1869e5b75505Sopenharmony_ci{
1870e5b75505Sopenharmony_ci	struct hostapd_iface *iface = hapd->iface;
1871e5b75505Sopenharmony_ci	int ret;
1872e5b75505Sopenharmony_ci	size_t i, j;
1873e5b75505Sopenharmony_ci	bool is_6g;
1874e5b75505Sopenharmony_ci
1875e5b75505Sopenharmony_ci	ret = __ieee802_11_set_beacon(hapd);
1876e5b75505Sopenharmony_ci	if (ret != 0)
1877e5b75505Sopenharmony_ci		return ret;
1878e5b75505Sopenharmony_ci
1879e5b75505Sopenharmony_ci	if (!iface->interfaces || iface->interfaces->count <= 1)
1880e5b75505Sopenharmony_ci		return 0;
1881e5b75505Sopenharmony_ci
1882e5b75505Sopenharmony_ci	/* Update Beacon frames in case of 6 GHz colocation */
1883e5b75505Sopenharmony_ci	is_6g = is_6ghz_op_class(iface->conf->op_class);
1884e5b75505Sopenharmony_ci	for (j = 0; j < iface->interfaces->count; j++) {
1885e5b75505Sopenharmony_ci		struct hostapd_iface *colocated;
1886e5b75505Sopenharmony_ci
1887e5b75505Sopenharmony_ci		colocated = iface->interfaces->iface[j];
1888e5b75505Sopenharmony_ci		if (colocated == iface || !colocated || !colocated->conf)
1889e5b75505Sopenharmony_ci			continue;
1890e5b75505Sopenharmony_ci
1891e5b75505Sopenharmony_ci		if (is_6g == is_6ghz_op_class(colocated->conf->op_class))
1892e5b75505Sopenharmony_ci			continue;
1893e5b75505Sopenharmony_ci
1894e5b75505Sopenharmony_ci		for (i = 0; i < colocated->num_bss; i++) {
1895e5b75505Sopenharmony_ci			if (colocated->bss[i] && colocated->bss[i]->started)
1896e5b75505Sopenharmony_ci				__ieee802_11_set_beacon(colocated->bss[i]);
1897e5b75505Sopenharmony_ci		}
1898e5b75505Sopenharmony_ci	}
1899e5b75505Sopenharmony_ci
1900e5b75505Sopenharmony_ci	return 0;
1901e5b75505Sopenharmony_ci}
1902e5b75505Sopenharmony_ci
1903e5b75505Sopenharmony_ci
1904e5b75505Sopenharmony_ciint ieee802_11_set_beacons(struct hostapd_iface *iface)
1905e5b75505Sopenharmony_ci{
1906e5b75505Sopenharmony_ci	size_t i;
1907e5b75505Sopenharmony_ci	int ret = 0;
1908e5b75505Sopenharmony_ci
1909e5b75505Sopenharmony_ci	for (i = 0; i < iface->num_bss; i++) {
1910e5b75505Sopenharmony_ci		if (iface->bss[i]->started &&
1911e5b75505Sopenharmony_ci		    ieee802_11_set_beacon(iface->bss[i]) < 0)
1912e5b75505Sopenharmony_ci			ret = -1;
1913e5b75505Sopenharmony_ci	}
1914e5b75505Sopenharmony_ci
1915e5b75505Sopenharmony_ci	return ret;
1916e5b75505Sopenharmony_ci}
1917e5b75505Sopenharmony_ci
1918e5b75505Sopenharmony_ci
1919e5b75505Sopenharmony_ci/* only update beacons if started */
1920e5b75505Sopenharmony_ciint ieee802_11_update_beacons(struct hostapd_iface *iface)
1921e5b75505Sopenharmony_ci{
1922e5b75505Sopenharmony_ci	size_t i;
1923e5b75505Sopenharmony_ci	int ret = 0;
1924e5b75505Sopenharmony_ci
1925e5b75505Sopenharmony_ci	for (i = 0; i < iface->num_bss; i++) {
1926e5b75505Sopenharmony_ci		if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
1927e5b75505Sopenharmony_ci		    ieee802_11_set_beacon(iface->bss[i]) < 0)
1928e5b75505Sopenharmony_ci			ret = -1;
1929e5b75505Sopenharmony_ci	}
1930e5b75505Sopenharmony_ci
1931e5b75505Sopenharmony_ci	return ret;
1932e5b75505Sopenharmony_ci}
1933e5b75505Sopenharmony_ci
1934e5b75505Sopenharmony_ci#endif /* CONFIG_NATIVE_WINDOWS */
1935