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_rm_enabled_capab(struct hostapd_data *hapd, u8 *eid,
40e5b75505Sopenharmony_ci					 size_t len)
41e5b75505Sopenharmony_ci{
42e5b75505Sopenharmony_ci	size_t i;
43e5b75505Sopenharmony_ci
44e5b75505Sopenharmony_ci	for (i = 0; i < RRM_CAPABILITIES_IE_LEN; i++) {
45e5b75505Sopenharmony_ci		if (hapd->conf->radio_measurements[i])
46e5b75505Sopenharmony_ci			break;
47e5b75505Sopenharmony_ci	}
48e5b75505Sopenharmony_ci
49e5b75505Sopenharmony_ci	if (i == RRM_CAPABILITIES_IE_LEN || len < 2 + RRM_CAPABILITIES_IE_LEN)
50e5b75505Sopenharmony_ci		return eid;
51e5b75505Sopenharmony_ci
52e5b75505Sopenharmony_ci	*eid++ = WLAN_EID_RRM_ENABLED_CAPABILITIES;
53e5b75505Sopenharmony_ci	*eid++ = RRM_CAPABILITIES_IE_LEN;
54e5b75505Sopenharmony_ci	os_memcpy(eid, hapd->conf->radio_measurements, RRM_CAPABILITIES_IE_LEN);
55e5b75505Sopenharmony_ci
56e5b75505Sopenharmony_ci	return eid + RRM_CAPABILITIES_IE_LEN;
57e5b75505Sopenharmony_ci}
58e5b75505Sopenharmony_ci
59e5b75505Sopenharmony_ci
60e5b75505Sopenharmony_cistatic u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
61e5b75505Sopenharmony_ci{
62e5b75505Sopenharmony_ci	if (len < 2 + 5)
63e5b75505Sopenharmony_ci		return eid;
64e5b75505Sopenharmony_ci
65e5b75505Sopenharmony_ci#ifdef CONFIG_TESTING_OPTIONS
66e5b75505Sopenharmony_ci	if (hapd->conf->bss_load_test_set) {
67e5b75505Sopenharmony_ci		*eid++ = WLAN_EID_BSS_LOAD;
68e5b75505Sopenharmony_ci		*eid++ = 5;
69e5b75505Sopenharmony_ci		os_memcpy(eid, hapd->conf->bss_load_test, 5);
70e5b75505Sopenharmony_ci		eid += 5;
71e5b75505Sopenharmony_ci		return eid;
72e5b75505Sopenharmony_ci	}
73e5b75505Sopenharmony_ci#endif /* CONFIG_TESTING_OPTIONS */
74e5b75505Sopenharmony_ci	if (hapd->conf->bss_load_update_period) {
75e5b75505Sopenharmony_ci		*eid++ = WLAN_EID_BSS_LOAD;
76e5b75505Sopenharmony_ci		*eid++ = 5;
77e5b75505Sopenharmony_ci		WPA_PUT_LE16(eid, hapd->num_sta);
78e5b75505Sopenharmony_ci		eid += 2;
79e5b75505Sopenharmony_ci		*eid++ = hapd->iface->channel_utilization;
80e5b75505Sopenharmony_ci		WPA_PUT_LE16(eid, 0); /* no available admission capabity */
81e5b75505Sopenharmony_ci		eid += 2;
82e5b75505Sopenharmony_ci	}
83e5b75505Sopenharmony_ci	return eid;
84e5b75505Sopenharmony_ci}
85e5b75505Sopenharmony_ci
86e5b75505Sopenharmony_ci
87e5b75505Sopenharmony_cistatic u8 ieee802_11_erp_info(struct hostapd_data *hapd)
88e5b75505Sopenharmony_ci{
89e5b75505Sopenharmony_ci	u8 erp = 0;
90e5b75505Sopenharmony_ci
91e5b75505Sopenharmony_ci	if (hapd->iface->current_mode == NULL ||
92e5b75505Sopenharmony_ci	    hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
93e5b75505Sopenharmony_ci		return 0;
94e5b75505Sopenharmony_ci
95e5b75505Sopenharmony_ci	if (hapd->iface->olbc)
96e5b75505Sopenharmony_ci		erp |= ERP_INFO_USE_PROTECTION;
97e5b75505Sopenharmony_ci	if (hapd->iface->num_sta_non_erp > 0) {
98e5b75505Sopenharmony_ci		erp |= ERP_INFO_NON_ERP_PRESENT |
99e5b75505Sopenharmony_ci			ERP_INFO_USE_PROTECTION;
100e5b75505Sopenharmony_ci	}
101e5b75505Sopenharmony_ci	if (hapd->iface->num_sta_no_short_preamble > 0 ||
102e5b75505Sopenharmony_ci	    hapd->iconf->preamble == LONG_PREAMBLE)
103e5b75505Sopenharmony_ci		erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
104e5b75505Sopenharmony_ci
105e5b75505Sopenharmony_ci	return erp;
106e5b75505Sopenharmony_ci}
107e5b75505Sopenharmony_ci
108e5b75505Sopenharmony_ci
109e5b75505Sopenharmony_cistatic u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
110e5b75505Sopenharmony_ci{
111e5b75505Sopenharmony_ci	*eid++ = WLAN_EID_DS_PARAMS;
112e5b75505Sopenharmony_ci	*eid++ = 1;
113e5b75505Sopenharmony_ci	*eid++ = hapd->iconf->channel;
114e5b75505Sopenharmony_ci	return eid;
115e5b75505Sopenharmony_ci}
116e5b75505Sopenharmony_ci
117e5b75505Sopenharmony_ci
118e5b75505Sopenharmony_cistatic u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
119e5b75505Sopenharmony_ci{
120e5b75505Sopenharmony_ci	if (hapd->iface->current_mode == NULL ||
121e5b75505Sopenharmony_ci	    hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
122e5b75505Sopenharmony_ci		return eid;
123e5b75505Sopenharmony_ci
124e5b75505Sopenharmony_ci	/* Set NonERP_present and use_protection bits if there
125e5b75505Sopenharmony_ci	 * are any associated NonERP stations. */
126e5b75505Sopenharmony_ci	/* TODO: use_protection bit can be set to zero even if
127e5b75505Sopenharmony_ci	 * there are NonERP stations present. This optimization
128e5b75505Sopenharmony_ci	 * might be useful if NonERP stations are "quiet".
129e5b75505Sopenharmony_ci	 * See 802.11g/D6 E-1 for recommended practice.
130e5b75505Sopenharmony_ci	 * In addition, Non ERP present might be set, if AP detects Non ERP
131e5b75505Sopenharmony_ci	 * operation on other APs. */
132e5b75505Sopenharmony_ci
133e5b75505Sopenharmony_ci	/* Add ERP Information element */
134e5b75505Sopenharmony_ci	*eid++ = WLAN_EID_ERP_INFO;
135e5b75505Sopenharmony_ci	*eid++ = 1;
136e5b75505Sopenharmony_ci	*eid++ = ieee802_11_erp_info(hapd);
137e5b75505Sopenharmony_ci
138e5b75505Sopenharmony_ci	return eid;
139e5b75505Sopenharmony_ci}
140e5b75505Sopenharmony_ci
141e5b75505Sopenharmony_ci
142e5b75505Sopenharmony_cistatic u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid)
143e5b75505Sopenharmony_ci{
144e5b75505Sopenharmony_ci	u8 *pos = eid;
145e5b75505Sopenharmony_ci	u8 local_pwr_constraint = 0;
146e5b75505Sopenharmony_ci	int dfs;
147e5b75505Sopenharmony_ci
148e5b75505Sopenharmony_ci	if (hapd->iface->current_mode == NULL ||
149e5b75505Sopenharmony_ci	    hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
150e5b75505Sopenharmony_ci		return eid;
151e5b75505Sopenharmony_ci
152e5b75505Sopenharmony_ci	/* Let host drivers add this IE if DFS support is offloaded */
153e5b75505Sopenharmony_ci	if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)
154e5b75505Sopenharmony_ci		return eid;
155e5b75505Sopenharmony_ci
156e5b75505Sopenharmony_ci	/*
157e5b75505Sopenharmony_ci	 * There is no DFS support and power constraint was not directly
158e5b75505Sopenharmony_ci	 * requested by config option.
159e5b75505Sopenharmony_ci	 */
160e5b75505Sopenharmony_ci	if (!hapd->iconf->ieee80211h &&
161e5b75505Sopenharmony_ci	    hapd->iconf->local_pwr_constraint == -1)
162e5b75505Sopenharmony_ci		return eid;
163e5b75505Sopenharmony_ci
164e5b75505Sopenharmony_ci	/* Check if DFS is required by regulatory. */
165e5b75505Sopenharmony_ci	dfs = hostapd_is_dfs_required(hapd->iface);
166e5b75505Sopenharmony_ci	if (dfs < 0) {
167e5b75505Sopenharmony_ci		wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
168e5b75505Sopenharmony_ci			   dfs);
169e5b75505Sopenharmony_ci		dfs = 0;
170e5b75505Sopenharmony_ci	}
171e5b75505Sopenharmony_ci
172e5b75505Sopenharmony_ci	if (dfs == 0 && hapd->iconf->local_pwr_constraint == -1)
173e5b75505Sopenharmony_ci		return eid;
174e5b75505Sopenharmony_ci
175e5b75505Sopenharmony_ci	/*
176e5b75505Sopenharmony_ci	 * ieee80211h (DFS) is enabled so Power Constraint element shall
177e5b75505Sopenharmony_ci	 * be added when running on DFS channel whenever local_pwr_constraint
178e5b75505Sopenharmony_ci	 * is configured or not. In order to meet regulations when TPC is not
179e5b75505Sopenharmony_ci	 * implemented using a transmit power that is below the legal maximum
180e5b75505Sopenharmony_ci	 * (including any mitigation factor) should help. In this case,
181e5b75505Sopenharmony_ci	 * indicate 3 dB below maximum allowed transmit power.
182e5b75505Sopenharmony_ci	 */
183e5b75505Sopenharmony_ci	if (hapd->iconf->local_pwr_constraint == -1)
184e5b75505Sopenharmony_ci		local_pwr_constraint = 3;
185e5b75505Sopenharmony_ci
186e5b75505Sopenharmony_ci	/*
187e5b75505Sopenharmony_ci	 * A STA that is not an AP shall use a transmit power less than or
188e5b75505Sopenharmony_ci	 * equal to the local maximum transmit power level for the channel.
189e5b75505Sopenharmony_ci	 * The local maximum transmit power can be calculated from the formula:
190e5b75505Sopenharmony_ci	 * local max TX pwr = max TX pwr - local pwr constraint
191e5b75505Sopenharmony_ci	 * Where max TX pwr is maximum transmit power level specified for
192e5b75505Sopenharmony_ci	 * channel in Country element and local pwr constraint is specified
193e5b75505Sopenharmony_ci	 * for channel in this Power Constraint element.
194e5b75505Sopenharmony_ci	 */
195e5b75505Sopenharmony_ci
196e5b75505Sopenharmony_ci	/* Element ID */
197e5b75505Sopenharmony_ci	*pos++ = WLAN_EID_PWR_CONSTRAINT;
198e5b75505Sopenharmony_ci	/* Length */
199e5b75505Sopenharmony_ci	*pos++ = 1;
200e5b75505Sopenharmony_ci	/* Local Power Constraint */
201e5b75505Sopenharmony_ci	if (local_pwr_constraint)
202e5b75505Sopenharmony_ci		*pos++ = local_pwr_constraint;
203e5b75505Sopenharmony_ci	else
204e5b75505Sopenharmony_ci		*pos++ = hapd->iconf->local_pwr_constraint;
205e5b75505Sopenharmony_ci
206e5b75505Sopenharmony_ci	return pos;
207e5b75505Sopenharmony_ci}
208e5b75505Sopenharmony_ci
209e5b75505Sopenharmony_ci
210e5b75505Sopenharmony_cistatic u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
211e5b75505Sopenharmony_ci				    struct hostapd_channel_data *start,
212e5b75505Sopenharmony_ci				    struct hostapd_channel_data *prev)
213e5b75505Sopenharmony_ci{
214e5b75505Sopenharmony_ci	if (end - pos < 3)
215e5b75505Sopenharmony_ci		return pos;
216e5b75505Sopenharmony_ci
217e5b75505Sopenharmony_ci	/* first channel number */
218e5b75505Sopenharmony_ci	*pos++ = start->chan;
219e5b75505Sopenharmony_ci	/* number of channels */
220e5b75505Sopenharmony_ci	*pos++ = (prev->chan - start->chan) / chan_spacing + 1;
221e5b75505Sopenharmony_ci	/* maximum transmit power level */
222e5b75505Sopenharmony_ci	*pos++ = start->max_tx_power;
223e5b75505Sopenharmony_ci
224e5b75505Sopenharmony_ci	return pos;
225e5b75505Sopenharmony_ci}
226e5b75505Sopenharmony_ci
227e5b75505Sopenharmony_ci
228e5b75505Sopenharmony_cistatic u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
229e5b75505Sopenharmony_ci				int max_len)
230e5b75505Sopenharmony_ci{
231e5b75505Sopenharmony_ci	u8 *pos = eid;
232e5b75505Sopenharmony_ci	u8 *end = eid + max_len;
233e5b75505Sopenharmony_ci	int i;
234e5b75505Sopenharmony_ci	struct hostapd_hw_modes *mode;
235e5b75505Sopenharmony_ci	struct hostapd_channel_data *start, *prev;
236e5b75505Sopenharmony_ci	int chan_spacing = 1;
237e5b75505Sopenharmony_ci
238e5b75505Sopenharmony_ci	if (!hapd->iconf->ieee80211d || max_len < 6 ||
239e5b75505Sopenharmony_ci	    hapd->iface->current_mode == NULL)
240e5b75505Sopenharmony_ci		return eid;
241e5b75505Sopenharmony_ci
242e5b75505Sopenharmony_ci	*pos++ = WLAN_EID_COUNTRY;
243e5b75505Sopenharmony_ci	pos++; /* length will be set later */
244e5b75505Sopenharmony_ci	os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
245e5b75505Sopenharmony_ci	pos += 3;
246e5b75505Sopenharmony_ci
247e5b75505Sopenharmony_ci	mode = hapd->iface->current_mode;
248e5b75505Sopenharmony_ci	if (mode->mode == HOSTAPD_MODE_IEEE80211A)
249e5b75505Sopenharmony_ci		chan_spacing = 4;
250e5b75505Sopenharmony_ci
251e5b75505Sopenharmony_ci	start = prev = NULL;
252e5b75505Sopenharmony_ci	for (i = 0; i < mode->num_channels; i++) {
253e5b75505Sopenharmony_ci		struct hostapd_channel_data *chan = &mode->channels[i];
254e5b75505Sopenharmony_ci		if (chan->flag & HOSTAPD_CHAN_DISABLED)
255e5b75505Sopenharmony_ci			continue;
256e5b75505Sopenharmony_ci		if (start && prev &&
257e5b75505Sopenharmony_ci		    prev->chan + chan_spacing == chan->chan &&
258e5b75505Sopenharmony_ci		    start->max_tx_power == chan->max_tx_power) {
259e5b75505Sopenharmony_ci			prev = chan;
260e5b75505Sopenharmony_ci			continue; /* can use same entry */
261e5b75505Sopenharmony_ci		}
262e5b75505Sopenharmony_ci
263e5b75505Sopenharmony_ci		if (start && prev) {
264e5b75505Sopenharmony_ci			pos = hostapd_eid_country_add(pos, end, chan_spacing,
265e5b75505Sopenharmony_ci						      start, prev);
266e5b75505Sopenharmony_ci			start = NULL;
267e5b75505Sopenharmony_ci		}
268e5b75505Sopenharmony_ci
269e5b75505Sopenharmony_ci		/* Start new group */
270e5b75505Sopenharmony_ci		start = prev = chan;
271e5b75505Sopenharmony_ci	}
272e5b75505Sopenharmony_ci
273e5b75505Sopenharmony_ci	if (start) {
274e5b75505Sopenharmony_ci		pos = hostapd_eid_country_add(pos, end, chan_spacing,
275e5b75505Sopenharmony_ci					      start, prev);
276e5b75505Sopenharmony_ci	}
277e5b75505Sopenharmony_ci
278e5b75505Sopenharmony_ci	if ((pos - eid) & 1) {
279e5b75505Sopenharmony_ci		if (end - pos < 1)
280e5b75505Sopenharmony_ci			return eid;
281e5b75505Sopenharmony_ci		*pos++ = 0; /* pad for 16-bit alignment */
282e5b75505Sopenharmony_ci	}
283e5b75505Sopenharmony_ci
284e5b75505Sopenharmony_ci	eid[1] = (pos - eid) - 2;
285e5b75505Sopenharmony_ci
286e5b75505Sopenharmony_ci	return pos;
287e5b75505Sopenharmony_ci}
288e5b75505Sopenharmony_ci
289e5b75505Sopenharmony_ci
290e5b75505Sopenharmony_cistatic u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
291e5b75505Sopenharmony_ci{
292e5b75505Sopenharmony_ci	const u8 *ie;
293e5b75505Sopenharmony_ci	size_t ielen;
294e5b75505Sopenharmony_ci
295e5b75505Sopenharmony_ci	ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
296e5b75505Sopenharmony_ci	if (ie == NULL || ielen > len)
297e5b75505Sopenharmony_ci		return eid;
298e5b75505Sopenharmony_ci
299e5b75505Sopenharmony_ci	os_memcpy(eid, ie, ielen);
300e5b75505Sopenharmony_ci	return eid + ielen;
301e5b75505Sopenharmony_ci}
302e5b75505Sopenharmony_ci
303e5b75505Sopenharmony_ci
304e5b75505Sopenharmony_cistatic u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
305e5b75505Sopenharmony_ci{
306e5b75505Sopenharmony_ci#ifdef CONFIG_TESTING_OPTIONS
307e5b75505Sopenharmony_ci	if (hapd->iface->cs_oper_class && hapd->iconf->ecsa_ie_only)
308e5b75505Sopenharmony_ci		return eid;
309e5b75505Sopenharmony_ci#endif /* CONFIG_TESTING_OPTIONS */
310e5b75505Sopenharmony_ci
311e5b75505Sopenharmony_ci	if (!hapd->cs_freq_params.channel)
312e5b75505Sopenharmony_ci		return eid;
313e5b75505Sopenharmony_ci
314e5b75505Sopenharmony_ci	*eid++ = WLAN_EID_CHANNEL_SWITCH;
315e5b75505Sopenharmony_ci	*eid++ = 3;
316e5b75505Sopenharmony_ci	*eid++ = hapd->cs_block_tx;
317e5b75505Sopenharmony_ci	*eid++ = hapd->cs_freq_params.channel;
318e5b75505Sopenharmony_ci	*eid++ = hapd->cs_count;
319e5b75505Sopenharmony_ci
320e5b75505Sopenharmony_ci	return eid;
321e5b75505Sopenharmony_ci}
322e5b75505Sopenharmony_ci
323e5b75505Sopenharmony_ci
324e5b75505Sopenharmony_cistatic u8 * hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid)
325e5b75505Sopenharmony_ci{
326e5b75505Sopenharmony_ci	if (!hapd->cs_freq_params.channel || !hapd->iface->cs_oper_class)
327e5b75505Sopenharmony_ci		return eid;
328e5b75505Sopenharmony_ci
329e5b75505Sopenharmony_ci	*eid++ = WLAN_EID_EXT_CHANSWITCH_ANN;
330e5b75505Sopenharmony_ci	*eid++ = 4;
331e5b75505Sopenharmony_ci	*eid++ = hapd->cs_block_tx;
332e5b75505Sopenharmony_ci	*eid++ = hapd->iface->cs_oper_class;
333e5b75505Sopenharmony_ci	*eid++ = hapd->cs_freq_params.channel;
334e5b75505Sopenharmony_ci	*eid++ = hapd->cs_count;
335e5b75505Sopenharmony_ci
336e5b75505Sopenharmony_ci	return eid;
337e5b75505Sopenharmony_ci}
338e5b75505Sopenharmony_ci
339e5b75505Sopenharmony_ci
340e5b75505Sopenharmony_cistatic u8 * hostapd_eid_supported_op_classes(struct hostapd_data *hapd, u8 *eid)
341e5b75505Sopenharmony_ci{
342e5b75505Sopenharmony_ci	u8 op_class, channel;
343e5b75505Sopenharmony_ci
344e5b75505Sopenharmony_ci	if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) ||
345e5b75505Sopenharmony_ci	    !hapd->iface->freq)
346e5b75505Sopenharmony_ci		return eid;
347e5b75505Sopenharmony_ci
348e5b75505Sopenharmony_ci	if (ieee80211_freq_to_channel_ext(hapd->iface->freq,
349e5b75505Sopenharmony_ci					  hapd->iconf->secondary_channel,
350e5b75505Sopenharmony_ci					  hostapd_get_oper_chwidth(hapd->iconf),
351e5b75505Sopenharmony_ci					  &op_class, &channel) ==
352e5b75505Sopenharmony_ci	    NUM_HOSTAPD_MODES)
353e5b75505Sopenharmony_ci		return eid;
354e5b75505Sopenharmony_ci
355e5b75505Sopenharmony_ci	*eid++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES;
356e5b75505Sopenharmony_ci	*eid++ = 2;
357e5b75505Sopenharmony_ci
358e5b75505Sopenharmony_ci	/* Current Operating Class */
359e5b75505Sopenharmony_ci	*eid++ = op_class;
360e5b75505Sopenharmony_ci
361e5b75505Sopenharmony_ci	/* TODO: Advertise all the supported operating classes */
362e5b75505Sopenharmony_ci	*eid++ = 0;
363e5b75505Sopenharmony_ci
364e5b75505Sopenharmony_ci	return eid;
365e5b75505Sopenharmony_ci}
366e5b75505Sopenharmony_ci
367e5b75505Sopenharmony_ci
368e5b75505Sopenharmony_cistatic u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
369e5b75505Sopenharmony_ci				   const struct ieee80211_mgmt *req,
370e5b75505Sopenharmony_ci				   int is_p2p, size_t *resp_len)
371e5b75505Sopenharmony_ci{
372e5b75505Sopenharmony_ci	struct ieee80211_mgmt *resp;
373e5b75505Sopenharmony_ci	u8 *pos, *epos, *csa_pos;
374e5b75505Sopenharmony_ci	size_t buflen;
375e5b75505Sopenharmony_ci
376e5b75505Sopenharmony_ci#define MAX_PROBERESP_LEN 768
377e5b75505Sopenharmony_ci	buflen = MAX_PROBERESP_LEN;
378e5b75505Sopenharmony_ci#ifdef CONFIG_WPS
379e5b75505Sopenharmony_ci	if (hapd->wps_probe_resp_ie)
380e5b75505Sopenharmony_ci		buflen += wpabuf_len(hapd->wps_probe_resp_ie);
381e5b75505Sopenharmony_ci#endif /* CONFIG_WPS */
382e5b75505Sopenharmony_ci#ifdef CONFIG_P2P
383e5b75505Sopenharmony_ci	if (hapd->p2p_probe_resp_ie)
384e5b75505Sopenharmony_ci		buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
385e5b75505Sopenharmony_ci#endif /* CONFIG_P2P */
386e5b75505Sopenharmony_ci#ifdef CONFIG_FST
387e5b75505Sopenharmony_ci	if (hapd->iface->fst_ies)
388e5b75505Sopenharmony_ci		buflen += wpabuf_len(hapd->iface->fst_ies);
389e5b75505Sopenharmony_ci#endif /* CONFIG_FST */
390e5b75505Sopenharmony_ci	if (hapd->conf->vendor_elements)
391e5b75505Sopenharmony_ci		buflen += wpabuf_len(hapd->conf->vendor_elements);
392e5b75505Sopenharmony_ci	if (hapd->conf->vendor_vht) {
393e5b75505Sopenharmony_ci		buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
394e5b75505Sopenharmony_ci			2 + sizeof(struct ieee80211_vht_operation);
395e5b75505Sopenharmony_ci	}
396e5b75505Sopenharmony_ci
397e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AX
398e5b75505Sopenharmony_ci	if (hapd->iconf->ieee80211ax) {
399e5b75505Sopenharmony_ci		buflen += 3 + sizeof(struct ieee80211_he_capabilities) +
400e5b75505Sopenharmony_ci			3 + sizeof(struct ieee80211_he_operation) +
401e5b75505Sopenharmony_ci			3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
402e5b75505Sopenharmony_ci			3 + sizeof(struct ieee80211_spatial_reuse);
403e5b75505Sopenharmony_ci	}
404e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AX */
405e5b75505Sopenharmony_ci
406e5b75505Sopenharmony_ci	buflen += hostapd_mbo_ie_len(hapd);
407e5b75505Sopenharmony_ci	buflen += hostapd_eid_owe_trans_len(hapd);
408e5b75505Sopenharmony_ci
409e5b75505Sopenharmony_ci	resp = os_zalloc(buflen);
410e5b75505Sopenharmony_ci	if (resp == NULL)
411e5b75505Sopenharmony_ci		return NULL;
412e5b75505Sopenharmony_ci
413e5b75505Sopenharmony_ci	epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
414e5b75505Sopenharmony_ci
415e5b75505Sopenharmony_ci	resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
416e5b75505Sopenharmony_ci					   WLAN_FC_STYPE_PROBE_RESP);
417e5b75505Sopenharmony_ci	if (req)
418e5b75505Sopenharmony_ci		os_memcpy(resp->da, req->sa, ETH_ALEN);
419e5b75505Sopenharmony_ci	os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
420e5b75505Sopenharmony_ci
421e5b75505Sopenharmony_ci	os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
422e5b75505Sopenharmony_ci	resp->u.probe_resp.beacon_int =
423e5b75505Sopenharmony_ci		host_to_le16(hapd->iconf->beacon_int);
424e5b75505Sopenharmony_ci
425e5b75505Sopenharmony_ci	/* hardware or low-level driver will setup seq_ctrl and timestamp */
426e5b75505Sopenharmony_ci	resp->u.probe_resp.capab_info =
427e5b75505Sopenharmony_ci		host_to_le16(hostapd_own_capab_info(hapd));
428e5b75505Sopenharmony_ci
429e5b75505Sopenharmony_ci	pos = resp->u.probe_resp.variable;
430e5b75505Sopenharmony_ci	*pos++ = WLAN_EID_SSID;
431e5b75505Sopenharmony_ci	*pos++ = hapd->conf->ssid.ssid_len;
432e5b75505Sopenharmony_ci	os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
433e5b75505Sopenharmony_ci	pos += hapd->conf->ssid.ssid_len;
434e5b75505Sopenharmony_ci
435e5b75505Sopenharmony_ci	/* Supported rates */
436e5b75505Sopenharmony_ci	pos = hostapd_eid_supp_rates(hapd, pos);
437e5b75505Sopenharmony_ci
438e5b75505Sopenharmony_ci	/* DS Params */
439e5b75505Sopenharmony_ci	pos = hostapd_eid_ds_params(hapd, pos);
440e5b75505Sopenharmony_ci
441e5b75505Sopenharmony_ci	pos = hostapd_eid_country(hapd, pos, epos - pos);
442e5b75505Sopenharmony_ci
443e5b75505Sopenharmony_ci	/* Power Constraint element */
444e5b75505Sopenharmony_ci	pos = hostapd_eid_pwr_constraint(hapd, pos);
445e5b75505Sopenharmony_ci
446e5b75505Sopenharmony_ci	/* CSA IE */
447e5b75505Sopenharmony_ci	csa_pos = hostapd_eid_csa(hapd, pos);
448e5b75505Sopenharmony_ci	if (csa_pos != pos)
449e5b75505Sopenharmony_ci		hapd->cs_c_off_proberesp = csa_pos - (u8 *) resp - 1;
450e5b75505Sopenharmony_ci	pos = csa_pos;
451e5b75505Sopenharmony_ci
452e5b75505Sopenharmony_ci	/* ERP Information element */
453e5b75505Sopenharmony_ci	pos = hostapd_eid_erp_info(hapd, pos);
454e5b75505Sopenharmony_ci
455e5b75505Sopenharmony_ci	/* Extended supported rates */
456e5b75505Sopenharmony_ci	pos = hostapd_eid_ext_supp_rates(hapd, pos);
457e5b75505Sopenharmony_ci
458e5b75505Sopenharmony_ci	/* RSN, MDIE */
459e5b75505Sopenharmony_ci	if (hapd->conf->wpa != WPA_PROTO_WPA)
460e5b75505Sopenharmony_ci		pos = hostapd_eid_wpa(hapd, pos, epos - pos);
461e5b75505Sopenharmony_ci
462e5b75505Sopenharmony_ci	pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
463e5b75505Sopenharmony_ci
464e5b75505Sopenharmony_ci	pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
465e5b75505Sopenharmony_ci
466e5b75505Sopenharmony_ci	/* eCSA IE */
467e5b75505Sopenharmony_ci	csa_pos = hostapd_eid_ecsa(hapd, pos);
468e5b75505Sopenharmony_ci	if (csa_pos != pos)
469e5b75505Sopenharmony_ci		hapd->cs_c_off_ecsa_proberesp = csa_pos - (u8 *) resp - 1;
470e5b75505Sopenharmony_ci	pos = csa_pos;
471e5b75505Sopenharmony_ci
472e5b75505Sopenharmony_ci	pos = hostapd_eid_supported_op_classes(hapd, pos);
473e5b75505Sopenharmony_ci
474e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211N
475e5b75505Sopenharmony_ci	/* Secondary Channel Offset element */
476e5b75505Sopenharmony_ci	/* TODO: The standard doesn't specify a position for this element. */
477e5b75505Sopenharmony_ci	pos = hostapd_eid_secondary_channel(hapd, pos);
478e5b75505Sopenharmony_ci
479e5b75505Sopenharmony_ci	pos = hostapd_eid_ht_capabilities(hapd, pos);
480e5b75505Sopenharmony_ci	pos = hostapd_eid_ht_operation(hapd, pos);
481e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211N */
482e5b75505Sopenharmony_ci
483e5b75505Sopenharmony_ci	pos = hostapd_eid_ext_capab(hapd, pos);
484e5b75505Sopenharmony_ci
485e5b75505Sopenharmony_ci	pos = hostapd_eid_time_adv(hapd, pos);
486e5b75505Sopenharmony_ci	pos = hostapd_eid_time_zone(hapd, pos);
487e5b75505Sopenharmony_ci
488e5b75505Sopenharmony_ci	pos = hostapd_eid_interworking(hapd, pos);
489e5b75505Sopenharmony_ci	pos = hostapd_eid_adv_proto(hapd, pos);
490e5b75505Sopenharmony_ci	pos = hostapd_eid_roaming_consortium(hapd, pos);
491e5b75505Sopenharmony_ci
492e5b75505Sopenharmony_ci#ifdef CONFIG_FST
493e5b75505Sopenharmony_ci	if (hapd->iface->fst_ies) {
494e5b75505Sopenharmony_ci		os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies),
495e5b75505Sopenharmony_ci			  wpabuf_len(hapd->iface->fst_ies));
496e5b75505Sopenharmony_ci		pos += wpabuf_len(hapd->iface->fst_ies);
497e5b75505Sopenharmony_ci	}
498e5b75505Sopenharmony_ci#endif /* CONFIG_FST */
499e5b75505Sopenharmony_ci
500e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AC
501e5b75505Sopenharmony_ci	if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
502e5b75505Sopenharmony_ci		pos = hostapd_eid_vht_capabilities(hapd, pos, 0);
503e5b75505Sopenharmony_ci		pos = hostapd_eid_vht_operation(hapd, pos);
504e5b75505Sopenharmony_ci		pos = hostapd_eid_txpower_envelope(hapd, pos);
505e5b75505Sopenharmony_ci		pos = hostapd_eid_wb_chsw_wrapper(hapd, pos);
506e5b75505Sopenharmony_ci	}
507e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AC */
508e5b75505Sopenharmony_ci
509e5b75505Sopenharmony_ci	pos = hostapd_eid_fils_indic(hapd, pos, 0);
510e5b75505Sopenharmony_ci
511e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AX
512e5b75505Sopenharmony_ci	if (hapd->iconf->ieee80211ax) {
513e5b75505Sopenharmony_ci		pos = hostapd_eid_he_capab(hapd, pos, IEEE80211_MODE_AP);
514e5b75505Sopenharmony_ci		pos = hostapd_eid_he_operation(hapd, pos);
515e5b75505Sopenharmony_ci		pos = hostapd_eid_he_mu_edca_parameter_set(hapd, pos);
516e5b75505Sopenharmony_ci		pos = hostapd_eid_spatial_reuse(hapd, pos);
517e5b75505Sopenharmony_ci	}
518e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AX */
519e5b75505Sopenharmony_ci
520e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AC
521e5b75505Sopenharmony_ci	if (hapd->conf->vendor_vht)
522e5b75505Sopenharmony_ci		pos = hostapd_eid_vendor_vht(hapd, pos);
523e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AC */
524e5b75505Sopenharmony_ci
525e5b75505Sopenharmony_ci	/* WPA */
526e5b75505Sopenharmony_ci	if (hapd->conf->wpa == WPA_PROTO_WPA)
527e5b75505Sopenharmony_ci		pos = hostapd_eid_wpa(hapd, pos, epos - pos);
528e5b75505Sopenharmony_ci
529e5b75505Sopenharmony_ci	/* Wi-Fi Alliance WMM */
530e5b75505Sopenharmony_ci	pos = hostapd_eid_wmm(hapd, pos);
531e5b75505Sopenharmony_ci
532e5b75505Sopenharmony_ci#ifdef CONFIG_WPS
533e5b75505Sopenharmony_ci	if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
534e5b75505Sopenharmony_ci		os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
535e5b75505Sopenharmony_ci			  wpabuf_len(hapd->wps_probe_resp_ie));
536e5b75505Sopenharmony_ci		pos += wpabuf_len(hapd->wps_probe_resp_ie);
537e5b75505Sopenharmony_ci	}
538e5b75505Sopenharmony_ci#endif /* CONFIG_WPS */
539e5b75505Sopenharmony_ci
540e5b75505Sopenharmony_ci#ifdef CONFIG_P2P
541e5b75505Sopenharmony_ci	if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
542e5b75505Sopenharmony_ci	    hapd->p2p_probe_resp_ie) {
543e5b75505Sopenharmony_ci		os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
544e5b75505Sopenharmony_ci			  wpabuf_len(hapd->p2p_probe_resp_ie));
545e5b75505Sopenharmony_ci		pos += wpabuf_len(hapd->p2p_probe_resp_ie);
546e5b75505Sopenharmony_ci	}
547e5b75505Sopenharmony_ci#endif /* CONFIG_P2P */
548e5b75505Sopenharmony_ci#ifdef CONFIG_P2P_MANAGER
549e5b75505Sopenharmony_ci	if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
550e5b75505Sopenharmony_ci	    P2P_MANAGE)
551e5b75505Sopenharmony_ci		pos = hostapd_eid_p2p_manage(hapd, pos);
552e5b75505Sopenharmony_ci#endif /* CONFIG_P2P_MANAGER */
553e5b75505Sopenharmony_ci
554e5b75505Sopenharmony_ci#ifdef CONFIG_HS20
555e5b75505Sopenharmony_ci	pos = hostapd_eid_hs20_indication(hapd, pos);
556e5b75505Sopenharmony_ci	pos = hostapd_eid_osen(hapd, pos);
557e5b75505Sopenharmony_ci#endif /* CONFIG_HS20 */
558e5b75505Sopenharmony_ci
559e5b75505Sopenharmony_ci	pos = hostapd_eid_mbo(hapd, pos, (u8 *) resp + buflen - pos);
560e5b75505Sopenharmony_ci	pos = hostapd_eid_owe_trans(hapd, pos, (u8 *) resp + buflen - pos);
561e5b75505Sopenharmony_ci
562e5b75505Sopenharmony_ci	if (hapd->conf->vendor_elements) {
563e5b75505Sopenharmony_ci		os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
564e5b75505Sopenharmony_ci			  wpabuf_len(hapd->conf->vendor_elements));
565e5b75505Sopenharmony_ci		pos += wpabuf_len(hapd->conf->vendor_elements);
566e5b75505Sopenharmony_ci	}
567e5b75505Sopenharmony_ci
568e5b75505Sopenharmony_ci	*resp_len = pos - (u8 *) resp;
569e5b75505Sopenharmony_ci	return (u8 *) resp;
570e5b75505Sopenharmony_ci}
571e5b75505Sopenharmony_ci
572e5b75505Sopenharmony_ci
573e5b75505Sopenharmony_cienum ssid_match_result {
574e5b75505Sopenharmony_ci	NO_SSID_MATCH,
575e5b75505Sopenharmony_ci	EXACT_SSID_MATCH,
576e5b75505Sopenharmony_ci	WILDCARD_SSID_MATCH
577e5b75505Sopenharmony_ci};
578e5b75505Sopenharmony_ci
579e5b75505Sopenharmony_cistatic enum ssid_match_result ssid_match(struct hostapd_data *hapd,
580e5b75505Sopenharmony_ci					 const u8 *ssid, size_t ssid_len,
581e5b75505Sopenharmony_ci					 const u8 *ssid_list,
582e5b75505Sopenharmony_ci					 size_t ssid_list_len)
583e5b75505Sopenharmony_ci{
584e5b75505Sopenharmony_ci	const u8 *pos, *end;
585e5b75505Sopenharmony_ci	int wildcard = 0;
586e5b75505Sopenharmony_ci
587e5b75505Sopenharmony_ci	if (ssid_len == 0)
588e5b75505Sopenharmony_ci		wildcard = 1;
589e5b75505Sopenharmony_ci	if (ssid_len == hapd->conf->ssid.ssid_len &&
590e5b75505Sopenharmony_ci	    os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
591e5b75505Sopenharmony_ci		return EXACT_SSID_MATCH;
592e5b75505Sopenharmony_ci
593e5b75505Sopenharmony_ci	if (ssid_list == NULL)
594e5b75505Sopenharmony_ci		return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
595e5b75505Sopenharmony_ci
596e5b75505Sopenharmony_ci	pos = ssid_list;
597e5b75505Sopenharmony_ci	end = ssid_list + ssid_list_len;
598e5b75505Sopenharmony_ci	while (end - pos >= 2) {
599e5b75505Sopenharmony_ci		if (2 + pos[1] > end - pos)
600e5b75505Sopenharmony_ci			break;
601e5b75505Sopenharmony_ci		if (pos[1] == 0)
602e5b75505Sopenharmony_ci			wildcard = 1;
603e5b75505Sopenharmony_ci		if (pos[1] == hapd->conf->ssid.ssid_len &&
604e5b75505Sopenharmony_ci		    os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0)
605e5b75505Sopenharmony_ci			return EXACT_SSID_MATCH;
606e5b75505Sopenharmony_ci		pos += 2 + pos[1];
607e5b75505Sopenharmony_ci	}
608e5b75505Sopenharmony_ci
609e5b75505Sopenharmony_ci	return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
610e5b75505Sopenharmony_ci}
611e5b75505Sopenharmony_ci
612e5b75505Sopenharmony_ci
613e5b75505Sopenharmony_civoid sta_track_expire(struct hostapd_iface *iface, int force)
614e5b75505Sopenharmony_ci{
615e5b75505Sopenharmony_ci	struct os_reltime now;
616e5b75505Sopenharmony_ci	struct hostapd_sta_info *info;
617e5b75505Sopenharmony_ci
618e5b75505Sopenharmony_ci	if (!iface->num_sta_seen)
619e5b75505Sopenharmony_ci		return;
620e5b75505Sopenharmony_ci
621e5b75505Sopenharmony_ci	os_get_reltime(&now);
622e5b75505Sopenharmony_ci	while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
623e5b75505Sopenharmony_ci				     list))) {
624e5b75505Sopenharmony_ci		if (!force &&
625e5b75505Sopenharmony_ci		    !os_reltime_expired(&now, &info->last_seen,
626e5b75505Sopenharmony_ci					iface->conf->track_sta_max_age))
627e5b75505Sopenharmony_ci			break;
628e5b75505Sopenharmony_ci		force = 0;
629e5b75505Sopenharmony_ci
630e5b75505Sopenharmony_ci		wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
631e5b75505Sopenharmony_ci			   MACSTR, iface->bss[0]->conf->iface,
632e5b75505Sopenharmony_ci			   MAC2STR(info->addr));
633e5b75505Sopenharmony_ci		dl_list_del(&info->list);
634e5b75505Sopenharmony_ci		iface->num_sta_seen--;
635e5b75505Sopenharmony_ci		sta_track_del(info);
636e5b75505Sopenharmony_ci	}
637e5b75505Sopenharmony_ci}
638e5b75505Sopenharmony_ci
639e5b75505Sopenharmony_ci
640e5b75505Sopenharmony_cistatic struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
641e5b75505Sopenharmony_ci					       const u8 *addr)
642e5b75505Sopenharmony_ci{
643e5b75505Sopenharmony_ci	struct hostapd_sta_info *info;
644e5b75505Sopenharmony_ci
645e5b75505Sopenharmony_ci	dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
646e5b75505Sopenharmony_ci		if (os_memcmp(addr, info->addr, ETH_ALEN) == 0)
647e5b75505Sopenharmony_ci			return info;
648e5b75505Sopenharmony_ci
649e5b75505Sopenharmony_ci	return NULL;
650e5b75505Sopenharmony_ci}
651e5b75505Sopenharmony_ci
652e5b75505Sopenharmony_ci
653e5b75505Sopenharmony_civoid sta_track_add(struct hostapd_iface *iface, const u8 *addr, int ssi_signal)
654e5b75505Sopenharmony_ci{
655e5b75505Sopenharmony_ci	struct hostapd_sta_info *info;
656e5b75505Sopenharmony_ci
657e5b75505Sopenharmony_ci	info = sta_track_get(iface, addr);
658e5b75505Sopenharmony_ci	if (info) {
659e5b75505Sopenharmony_ci		/* Move the most recent entry to the end of the list */
660e5b75505Sopenharmony_ci		dl_list_del(&info->list);
661e5b75505Sopenharmony_ci		dl_list_add_tail(&iface->sta_seen, &info->list);
662e5b75505Sopenharmony_ci		os_get_reltime(&info->last_seen);
663e5b75505Sopenharmony_ci		info->ssi_signal = ssi_signal;
664e5b75505Sopenharmony_ci		return;
665e5b75505Sopenharmony_ci	}
666e5b75505Sopenharmony_ci
667e5b75505Sopenharmony_ci	/* Add a new entry */
668e5b75505Sopenharmony_ci	info = os_zalloc(sizeof(*info));
669e5b75505Sopenharmony_ci	if (info == NULL)
670e5b75505Sopenharmony_ci		return;
671e5b75505Sopenharmony_ci	os_memcpy(info->addr, addr, ETH_ALEN);
672e5b75505Sopenharmony_ci	os_get_reltime(&info->last_seen);
673e5b75505Sopenharmony_ci	info->ssi_signal = ssi_signal;
674e5b75505Sopenharmony_ci
675e5b75505Sopenharmony_ci	if (iface->num_sta_seen >= iface->conf->track_sta_max_num) {
676e5b75505Sopenharmony_ci		/* Expire oldest entry to make room for a new one */
677e5b75505Sopenharmony_ci		sta_track_expire(iface, 1);
678e5b75505Sopenharmony_ci	}
679e5b75505Sopenharmony_ci
680e5b75505Sopenharmony_ci	wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
681e5b75505Sopenharmony_ci		   MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr));
682e5b75505Sopenharmony_ci	dl_list_add_tail(&iface->sta_seen, &info->list);
683e5b75505Sopenharmony_ci	iface->num_sta_seen++;
684e5b75505Sopenharmony_ci}
685e5b75505Sopenharmony_ci
686e5b75505Sopenharmony_ci
687e5b75505Sopenharmony_cistruct hostapd_data *
688e5b75505Sopenharmony_cista_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
689e5b75505Sopenharmony_ci		  const char *ifname)
690e5b75505Sopenharmony_ci{
691e5b75505Sopenharmony_ci	struct hapd_interfaces *interfaces = iface->interfaces;
692e5b75505Sopenharmony_ci	size_t i, j;
693e5b75505Sopenharmony_ci
694e5b75505Sopenharmony_ci	for (i = 0; i < interfaces->count; i++) {
695e5b75505Sopenharmony_ci		struct hostapd_data *hapd = NULL;
696e5b75505Sopenharmony_ci
697e5b75505Sopenharmony_ci		iface = interfaces->iface[i];
698e5b75505Sopenharmony_ci		for (j = 0; j < iface->num_bss; j++) {
699e5b75505Sopenharmony_ci			hapd = iface->bss[j];
700e5b75505Sopenharmony_ci			if (os_strcmp(ifname, hapd->conf->iface) == 0)
701e5b75505Sopenharmony_ci				break;
702e5b75505Sopenharmony_ci			hapd = NULL;
703e5b75505Sopenharmony_ci		}
704e5b75505Sopenharmony_ci
705e5b75505Sopenharmony_ci		if (hapd && sta_track_get(iface, addr))
706e5b75505Sopenharmony_ci			return hapd;
707e5b75505Sopenharmony_ci	}
708e5b75505Sopenharmony_ci
709e5b75505Sopenharmony_ci	return NULL;
710e5b75505Sopenharmony_ci}
711e5b75505Sopenharmony_ci
712e5b75505Sopenharmony_ci
713e5b75505Sopenharmony_ci#ifdef CONFIG_TAXONOMY
714e5b75505Sopenharmony_civoid sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr,
715e5b75505Sopenharmony_ci				   struct wpabuf **probe_ie_taxonomy)
716e5b75505Sopenharmony_ci{
717e5b75505Sopenharmony_ci	struct hostapd_sta_info *info;
718e5b75505Sopenharmony_ci
719e5b75505Sopenharmony_ci	info = sta_track_get(iface, addr);
720e5b75505Sopenharmony_ci	if (!info)
721e5b75505Sopenharmony_ci		return;
722e5b75505Sopenharmony_ci
723e5b75505Sopenharmony_ci	wpabuf_free(*probe_ie_taxonomy);
724e5b75505Sopenharmony_ci	*probe_ie_taxonomy = info->probe_ie_taxonomy;
725e5b75505Sopenharmony_ci	info->probe_ie_taxonomy = NULL;
726e5b75505Sopenharmony_ci}
727e5b75505Sopenharmony_ci#endif /* CONFIG_TAXONOMY */
728e5b75505Sopenharmony_ci
729e5b75505Sopenharmony_ci
730e5b75505Sopenharmony_civoid handle_probe_req(struct hostapd_data *hapd,
731e5b75505Sopenharmony_ci		      const struct ieee80211_mgmt *mgmt, size_t len,
732e5b75505Sopenharmony_ci		      int ssi_signal)
733e5b75505Sopenharmony_ci{
734e5b75505Sopenharmony_ci	u8 *resp;
735e5b75505Sopenharmony_ci	struct ieee802_11_elems elems;
736e5b75505Sopenharmony_ci	const u8 *ie;
737e5b75505Sopenharmony_ci	size_t ie_len;
738e5b75505Sopenharmony_ci	size_t i, resp_len;
739e5b75505Sopenharmony_ci	int noack;
740e5b75505Sopenharmony_ci	enum ssid_match_result res;
741e5b75505Sopenharmony_ci	int ret;
742e5b75505Sopenharmony_ci	u16 csa_offs[2];
743e5b75505Sopenharmony_ci	size_t csa_offs_len;
744e5b75505Sopenharmony_ci	u32 session_timeout, acct_interim_interval;
745e5b75505Sopenharmony_ci	struct vlan_description vlan_id;
746e5b75505Sopenharmony_ci	struct hostapd_sta_wpa_psk_short *psk = NULL;
747e5b75505Sopenharmony_ci	char *identity = NULL;
748e5b75505Sopenharmony_ci	char *radius_cui = NULL;
749e5b75505Sopenharmony_ci
750e5b75505Sopenharmony_ci	if (len < IEEE80211_HDRLEN)
751e5b75505Sopenharmony_ci		return;
752e5b75505Sopenharmony_ci	ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN;
753e5b75505Sopenharmony_ci	if (hapd->iconf->track_sta_max_num)
754e5b75505Sopenharmony_ci		sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
755e5b75505Sopenharmony_ci	ie_len = len - IEEE80211_HDRLEN;
756e5b75505Sopenharmony_ci
757e5b75505Sopenharmony_ci	ret = ieee802_11_allowed_address(hapd, mgmt->sa, (const u8 *) mgmt, len,
758e5b75505Sopenharmony_ci					 &session_timeout,
759e5b75505Sopenharmony_ci					 &acct_interim_interval, &vlan_id,
760e5b75505Sopenharmony_ci					 &psk, &identity, &radius_cui, 1);
761e5b75505Sopenharmony_ci	if (ret == HOSTAPD_ACL_REJECT) {
762e5b75505Sopenharmony_ci		wpa_msg(hapd->msg_ctx, MSG_DEBUG,
763e5b75505Sopenharmony_ci			"Ignore Probe Request frame from " MACSTR
764e5b75505Sopenharmony_ci			" due to ACL reject ", MAC2STR(mgmt->sa));
765e5b75505Sopenharmony_ci		return;
766e5b75505Sopenharmony_ci	}
767e5b75505Sopenharmony_ci
768e5b75505Sopenharmony_ci	for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
769e5b75505Sopenharmony_ci		if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
770e5b75505Sopenharmony_ci					    mgmt->sa, mgmt->da, mgmt->bssid,
771e5b75505Sopenharmony_ci					    ie, ie_len, ssi_signal) > 0)
772e5b75505Sopenharmony_ci			return;
773e5b75505Sopenharmony_ci
774e5b75505Sopenharmony_ci	if (!hapd->conf->send_probe_response)
775e5b75505Sopenharmony_ci		return;
776e5b75505Sopenharmony_ci
777e5b75505Sopenharmony_ci	if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
778e5b75505Sopenharmony_ci		wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
779e5b75505Sopenharmony_ci			   MAC2STR(mgmt->sa));
780e5b75505Sopenharmony_ci		return;
781e5b75505Sopenharmony_ci	}
782e5b75505Sopenharmony_ci
783e5b75505Sopenharmony_ci	if ((!elems.ssid || !elems.supp_rates)) {
784e5b75505Sopenharmony_ci		wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
785e5b75505Sopenharmony_ci			   "without SSID or supported rates element",
786e5b75505Sopenharmony_ci			   MAC2STR(mgmt->sa));
787e5b75505Sopenharmony_ci		return;
788e5b75505Sopenharmony_ci	}
789e5b75505Sopenharmony_ci
790e5b75505Sopenharmony_ci	/*
791e5b75505Sopenharmony_ci	 * No need to reply if the Probe Request frame was sent on an adjacent
792e5b75505Sopenharmony_ci	 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
793e5b75505Sopenharmony_ci	 * AP with dot11RadioMeasurementActivated set to true, but strictly
794e5b75505Sopenharmony_ci	 * speaking does not allow such ignoring of Probe Request frames if
795e5b75505Sopenharmony_ci	 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
796e5b75505Sopenharmony_ci	 * number of unnecessary Probe Response frames for cases where the STA
797e5b75505Sopenharmony_ci	 * is less likely to see them (Probe Request frame sent on a
798e5b75505Sopenharmony_ci	 * neighboring, but partially overlapping, channel).
799e5b75505Sopenharmony_ci	 */
800e5b75505Sopenharmony_ci	if (elems.ds_params &&
801e5b75505Sopenharmony_ci	    hapd->iface->current_mode &&
802e5b75505Sopenharmony_ci	    (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
803e5b75505Sopenharmony_ci	     hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
804e5b75505Sopenharmony_ci	    hapd->iconf->channel != elems.ds_params[0]) {
805e5b75505Sopenharmony_ci		wpa_printf(MSG_DEBUG,
806e5b75505Sopenharmony_ci			   "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
807e5b75505Sopenharmony_ci			   hapd->iconf->channel, elems.ds_params[0]);
808e5b75505Sopenharmony_ci		return;
809e5b75505Sopenharmony_ci	}
810e5b75505Sopenharmony_ci
811e5b75505Sopenharmony_ci#ifdef CONFIG_P2P
812e5b75505Sopenharmony_ci	if (hapd->p2p && hapd->p2p_group && elems.wps_ie) {
813e5b75505Sopenharmony_ci		struct wpabuf *wps;
814e5b75505Sopenharmony_ci		wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
815e5b75505Sopenharmony_ci		if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
816e5b75505Sopenharmony_ci			wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
817e5b75505Sopenharmony_ci				   "due to mismatch with Requested Device "
818e5b75505Sopenharmony_ci				   "Type");
819e5b75505Sopenharmony_ci			wpabuf_free(wps);
820e5b75505Sopenharmony_ci			return;
821e5b75505Sopenharmony_ci		}
822e5b75505Sopenharmony_ci		wpabuf_free(wps);
823e5b75505Sopenharmony_ci	}
824e5b75505Sopenharmony_ci
825e5b75505Sopenharmony_ci	if (hapd->p2p && hapd->p2p_group && elems.p2p) {
826e5b75505Sopenharmony_ci		struct wpabuf *p2p;
827e5b75505Sopenharmony_ci		p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
828e5b75505Sopenharmony_ci		if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
829e5b75505Sopenharmony_ci			wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
830e5b75505Sopenharmony_ci				   "due to mismatch with Device ID");
831e5b75505Sopenharmony_ci			wpabuf_free(p2p);
832e5b75505Sopenharmony_ci			return;
833e5b75505Sopenharmony_ci		}
834e5b75505Sopenharmony_ci		wpabuf_free(p2p);
835e5b75505Sopenharmony_ci	}
836e5b75505Sopenharmony_ci#endif /* CONFIG_P2P */
837e5b75505Sopenharmony_ci
838e5b75505Sopenharmony_ci	if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
839e5b75505Sopenharmony_ci	    elems.ssid_list_len == 0) {
840e5b75505Sopenharmony_ci		wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
841e5b75505Sopenharmony_ci			   "broadcast SSID ignored", MAC2STR(mgmt->sa));
842e5b75505Sopenharmony_ci		return;
843e5b75505Sopenharmony_ci	}
844e5b75505Sopenharmony_ci
845e5b75505Sopenharmony_ci#ifdef CONFIG_P2P
846e5b75505Sopenharmony_ci	if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
847e5b75505Sopenharmony_ci	    elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
848e5b75505Sopenharmony_ci	    os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
849e5b75505Sopenharmony_ci		      P2P_WILDCARD_SSID_LEN) == 0) {
850e5b75505Sopenharmony_ci		/* Process P2P Wildcard SSID like Wildcard SSID */
851e5b75505Sopenharmony_ci		elems.ssid_len = 0;
852e5b75505Sopenharmony_ci	}
853e5b75505Sopenharmony_ci#endif /* CONFIG_P2P */
854e5b75505Sopenharmony_ci
855e5b75505Sopenharmony_ci#ifdef CONFIG_TAXONOMY
856e5b75505Sopenharmony_ci	{
857e5b75505Sopenharmony_ci		struct sta_info *sta;
858e5b75505Sopenharmony_ci		struct hostapd_sta_info *info;
859e5b75505Sopenharmony_ci
860e5b75505Sopenharmony_ci		if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) {
861e5b75505Sopenharmony_ci			taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len);
862e5b75505Sopenharmony_ci		} else if ((info = sta_track_get(hapd->iface,
863e5b75505Sopenharmony_ci						 mgmt->sa)) != NULL) {
864e5b75505Sopenharmony_ci			taxonomy_hostapd_sta_info_probe_req(hapd, info,
865e5b75505Sopenharmony_ci							    ie, ie_len);
866e5b75505Sopenharmony_ci		}
867e5b75505Sopenharmony_ci	}
868e5b75505Sopenharmony_ci#endif /* CONFIG_TAXONOMY */
869e5b75505Sopenharmony_ci
870e5b75505Sopenharmony_ci	res = ssid_match(hapd, elems.ssid, elems.ssid_len,
871e5b75505Sopenharmony_ci			 elems.ssid_list, elems.ssid_list_len);
872e5b75505Sopenharmony_ci	if (res == NO_SSID_MATCH) {
873e5b75505Sopenharmony_ci		if (!(mgmt->da[0] & 0x01)) {
874e5b75505Sopenharmony_ci			wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
875e5b75505Sopenharmony_ci				   " for foreign SSID '%s' (DA " MACSTR ")%s",
876e5b75505Sopenharmony_ci				   MAC2STR(mgmt->sa),
877e5b75505Sopenharmony_ci				   wpa_ssid_txt(elems.ssid, elems.ssid_len),
878e5b75505Sopenharmony_ci				   MAC2STR(mgmt->da),
879e5b75505Sopenharmony_ci				   elems.ssid_list ? " (SSID list)" : "");
880e5b75505Sopenharmony_ci		}
881e5b75505Sopenharmony_ci		return;
882e5b75505Sopenharmony_ci	}
883e5b75505Sopenharmony_ci
884e5b75505Sopenharmony_ci#ifdef CONFIG_INTERWORKING
885e5b75505Sopenharmony_ci	if (hapd->conf->interworking &&
886e5b75505Sopenharmony_ci	    elems.interworking && elems.interworking_len >= 1) {
887e5b75505Sopenharmony_ci		u8 ant = elems.interworking[0] & 0x0f;
888e5b75505Sopenharmony_ci		if (ant != INTERWORKING_ANT_WILDCARD &&
889e5b75505Sopenharmony_ci		    ant != hapd->conf->access_network_type) {
890e5b75505Sopenharmony_ci			wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
891e5b75505Sopenharmony_ci				   " for mismatching ANT %u ignored",
892e5b75505Sopenharmony_ci				   MAC2STR(mgmt->sa), ant);
893e5b75505Sopenharmony_ci			return;
894e5b75505Sopenharmony_ci		}
895e5b75505Sopenharmony_ci	}
896e5b75505Sopenharmony_ci
897e5b75505Sopenharmony_ci	if (hapd->conf->interworking && elems.interworking &&
898e5b75505Sopenharmony_ci	    (elems.interworking_len == 7 || elems.interworking_len == 9)) {
899e5b75505Sopenharmony_ci		const u8 *hessid;
900e5b75505Sopenharmony_ci		if (elems.interworking_len == 7)
901e5b75505Sopenharmony_ci			hessid = elems.interworking + 1;
902e5b75505Sopenharmony_ci		else
903e5b75505Sopenharmony_ci			hessid = elems.interworking + 1 + 2;
904e5b75505Sopenharmony_ci		if (!is_broadcast_ether_addr(hessid) &&
905e5b75505Sopenharmony_ci		    os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
906e5b75505Sopenharmony_ci			wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
907e5b75505Sopenharmony_ci				   " for mismatching HESSID " MACSTR
908e5b75505Sopenharmony_ci				   " ignored",
909e5b75505Sopenharmony_ci				   MAC2STR(mgmt->sa), MAC2STR(hessid));
910e5b75505Sopenharmony_ci			return;
911e5b75505Sopenharmony_ci		}
912e5b75505Sopenharmony_ci	}
913e5b75505Sopenharmony_ci#endif /* CONFIG_INTERWORKING */
914e5b75505Sopenharmony_ci
915e5b75505Sopenharmony_ci#ifdef CONFIG_P2P
916e5b75505Sopenharmony_ci	if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
917e5b75505Sopenharmony_ci	    supp_rates_11b_only(&elems)) {
918e5b75505Sopenharmony_ci		/* Indicates support for 11b rates only */
919e5b75505Sopenharmony_ci		wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
920e5b75505Sopenharmony_ci			   MACSTR " with only 802.11b rates",
921e5b75505Sopenharmony_ci			   MAC2STR(mgmt->sa));
922e5b75505Sopenharmony_ci		return;
923e5b75505Sopenharmony_ci	}
924e5b75505Sopenharmony_ci#endif /* CONFIG_P2P */
925e5b75505Sopenharmony_ci
926e5b75505Sopenharmony_ci	/* TODO: verify that supp_rates contains at least one matching rate
927e5b75505Sopenharmony_ci	 * with AP configuration */
928e5b75505Sopenharmony_ci
929e5b75505Sopenharmony_ci	if (hapd->conf->no_probe_resp_if_seen_on &&
930e5b75505Sopenharmony_ci	    is_multicast_ether_addr(mgmt->da) &&
931e5b75505Sopenharmony_ci	    is_multicast_ether_addr(mgmt->bssid) &&
932e5b75505Sopenharmony_ci	    sta_track_seen_on(hapd->iface, mgmt->sa,
933e5b75505Sopenharmony_ci			      hapd->conf->no_probe_resp_if_seen_on)) {
934e5b75505Sopenharmony_ci		wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
935e5b75505Sopenharmony_ci			   " since STA has been seen on %s",
936e5b75505Sopenharmony_ci			   hapd->conf->iface, MAC2STR(mgmt->sa),
937e5b75505Sopenharmony_ci			   hapd->conf->no_probe_resp_if_seen_on);
938e5b75505Sopenharmony_ci		return;
939e5b75505Sopenharmony_ci	}
940e5b75505Sopenharmony_ci
941e5b75505Sopenharmony_ci	if (hapd->conf->no_probe_resp_if_max_sta &&
942e5b75505Sopenharmony_ci	    is_multicast_ether_addr(mgmt->da) &&
943e5b75505Sopenharmony_ci	    is_multicast_ether_addr(mgmt->bssid) &&
944e5b75505Sopenharmony_ci	    hapd->num_sta >= hapd->conf->max_num_sta &&
945e5b75505Sopenharmony_ci	    !ap_get_sta(hapd, mgmt->sa)) {
946e5b75505Sopenharmony_ci		wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
947e5b75505Sopenharmony_ci			   " since no room for additional STA",
948e5b75505Sopenharmony_ci			   hapd->conf->iface, MAC2STR(mgmt->sa));
949e5b75505Sopenharmony_ci		return;
950e5b75505Sopenharmony_ci	}
951e5b75505Sopenharmony_ci
952e5b75505Sopenharmony_ci#ifdef CONFIG_TESTING_OPTIONS
953e5b75505Sopenharmony_ci	if (hapd->iconf->ignore_probe_probability > 0.0 &&
954e5b75505Sopenharmony_ci	    drand48() < hapd->iconf->ignore_probe_probability) {
955e5b75505Sopenharmony_ci		wpa_printf(MSG_INFO,
956e5b75505Sopenharmony_ci			   "TESTING: ignoring probe request from " MACSTR,
957e5b75505Sopenharmony_ci			   MAC2STR(mgmt->sa));
958e5b75505Sopenharmony_ci		return;
959e5b75505Sopenharmony_ci	}
960e5b75505Sopenharmony_ci#endif /* CONFIG_TESTING_OPTIONS */
961e5b75505Sopenharmony_ci
962e5b75505Sopenharmony_ci	wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, RX_PROBE_REQUEST "sa=" MACSTR
963e5b75505Sopenharmony_ci		     " signal=%d", MAC2STR(mgmt->sa), ssi_signal);
964e5b75505Sopenharmony_ci
965e5b75505Sopenharmony_ci	resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL,
966e5b75505Sopenharmony_ci				      &resp_len);
967e5b75505Sopenharmony_ci	if (resp == NULL)
968e5b75505Sopenharmony_ci		return;
969e5b75505Sopenharmony_ci
970e5b75505Sopenharmony_ci	/*
971e5b75505Sopenharmony_ci	 * If this is a broadcast probe request, apply no ack policy to avoid
972e5b75505Sopenharmony_ci	 * excessive retries.
973e5b75505Sopenharmony_ci	 */
974e5b75505Sopenharmony_ci	noack = !!(res == WILDCARD_SSID_MATCH &&
975e5b75505Sopenharmony_ci		   is_broadcast_ether_addr(mgmt->da));
976e5b75505Sopenharmony_ci
977e5b75505Sopenharmony_ci	csa_offs_len = 0;
978e5b75505Sopenharmony_ci	if (hapd->csa_in_progress) {
979e5b75505Sopenharmony_ci		if (hapd->cs_c_off_proberesp)
980e5b75505Sopenharmony_ci			csa_offs[csa_offs_len++] =
981e5b75505Sopenharmony_ci				hapd->cs_c_off_proberesp;
982e5b75505Sopenharmony_ci
983e5b75505Sopenharmony_ci		if (hapd->cs_c_off_ecsa_proberesp)
984e5b75505Sopenharmony_ci			csa_offs[csa_offs_len++] =
985e5b75505Sopenharmony_ci				hapd->cs_c_off_ecsa_proberesp;
986e5b75505Sopenharmony_ci	}
987e5b75505Sopenharmony_ci
988e5b75505Sopenharmony_ci	ret = hostapd_drv_send_mlme_csa(hapd, resp, resp_len, noack,
989e5b75505Sopenharmony_ci					csa_offs_len ? csa_offs : NULL,
990e5b75505Sopenharmony_ci					csa_offs_len);
991e5b75505Sopenharmony_ci
992e5b75505Sopenharmony_ci	if (ret < 0)
993e5b75505Sopenharmony_ci		wpa_printf(MSG_INFO, "handle_probe_req: send failed");
994e5b75505Sopenharmony_ci
995e5b75505Sopenharmony_ci	os_free(resp);
996e5b75505Sopenharmony_ci
997e5b75505Sopenharmony_ci	wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
998e5b75505Sopenharmony_ci		   "SSID", MAC2STR(mgmt->sa),
999e5b75505Sopenharmony_ci		   elems.ssid_len == 0 ? "broadcast" : "our");
1000e5b75505Sopenharmony_ci}
1001e5b75505Sopenharmony_ci
1002e5b75505Sopenharmony_ci
1003e5b75505Sopenharmony_cistatic u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
1004e5b75505Sopenharmony_ci					size_t *resp_len)
1005e5b75505Sopenharmony_ci{
1006e5b75505Sopenharmony_ci	/* check probe response offloading caps and print warnings */
1007e5b75505Sopenharmony_ci	if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
1008e5b75505Sopenharmony_ci		return NULL;
1009e5b75505Sopenharmony_ci
1010e5b75505Sopenharmony_ci#ifdef CONFIG_WPS
1011e5b75505Sopenharmony_ci	if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
1012e5b75505Sopenharmony_ci	    (!(hapd->iface->probe_resp_offloads &
1013e5b75505Sopenharmony_ci	       (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
1014e5b75505Sopenharmony_ci		WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
1015e5b75505Sopenharmony_ci		wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
1016e5b75505Sopenharmony_ci			   "Probe Response while not supporting this");
1017e5b75505Sopenharmony_ci#endif /* CONFIG_WPS */
1018e5b75505Sopenharmony_ci
1019e5b75505Sopenharmony_ci#ifdef CONFIG_P2P
1020e5b75505Sopenharmony_ci	if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
1021e5b75505Sopenharmony_ci	    !(hapd->iface->probe_resp_offloads &
1022e5b75505Sopenharmony_ci	      WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
1023e5b75505Sopenharmony_ci		wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
1024e5b75505Sopenharmony_ci			   "Probe Response while not supporting this");
1025e5b75505Sopenharmony_ci#endif  /* CONFIG_P2P */
1026e5b75505Sopenharmony_ci
1027e5b75505Sopenharmony_ci	if (hapd->conf->interworking &&
1028e5b75505Sopenharmony_ci	    !(hapd->iface->probe_resp_offloads &
1029e5b75505Sopenharmony_ci	      WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
1030e5b75505Sopenharmony_ci		wpa_printf(MSG_WARNING, "Device is trying to offload "
1031e5b75505Sopenharmony_ci			   "Interworking Probe Response while not supporting "
1032e5b75505Sopenharmony_ci			   "this");
1033e5b75505Sopenharmony_ci
1034e5b75505Sopenharmony_ci	/* Generate a Probe Response template for the non-P2P case */
1035e5b75505Sopenharmony_ci	return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len);
1036e5b75505Sopenharmony_ci}
1037e5b75505Sopenharmony_ci
1038e5b75505Sopenharmony_ci#endif /* NEED_AP_MLME */
1039e5b75505Sopenharmony_ci
1040e5b75505Sopenharmony_ci
1041e5b75505Sopenharmony_civoid sta_track_del(struct hostapd_sta_info *info)
1042e5b75505Sopenharmony_ci{
1043e5b75505Sopenharmony_ci#ifdef CONFIG_TAXONOMY
1044e5b75505Sopenharmony_ci	wpabuf_free(info->probe_ie_taxonomy);
1045e5b75505Sopenharmony_ci	info->probe_ie_taxonomy = NULL;
1046e5b75505Sopenharmony_ci#endif /* CONFIG_TAXONOMY */
1047e5b75505Sopenharmony_ci	os_free(info);
1048e5b75505Sopenharmony_ci}
1049e5b75505Sopenharmony_ci
1050e5b75505Sopenharmony_ci
1051e5b75505Sopenharmony_ciint ieee802_11_build_ap_params(struct hostapd_data *hapd,
1052e5b75505Sopenharmony_ci			       struct wpa_driver_ap_params *params)
1053e5b75505Sopenharmony_ci{
1054e5b75505Sopenharmony_ci	struct ieee80211_mgmt *head = NULL;
1055e5b75505Sopenharmony_ci	u8 *tail = NULL;
1056e5b75505Sopenharmony_ci	size_t head_len = 0, tail_len = 0;
1057e5b75505Sopenharmony_ci	u8 *resp = NULL;
1058e5b75505Sopenharmony_ci	size_t resp_len = 0;
1059e5b75505Sopenharmony_ci#ifdef NEED_AP_MLME
1060e5b75505Sopenharmony_ci	u16 capab_info;
1061e5b75505Sopenharmony_ci	u8 *pos, *tailpos, *csa_pos;
1062e5b75505Sopenharmony_ci
1063e5b75505Sopenharmony_ci#define BEACON_HEAD_BUF_SIZE 256
1064e5b75505Sopenharmony_ci#define BEACON_TAIL_BUF_SIZE 512
1065e5b75505Sopenharmony_ci	head = os_zalloc(BEACON_HEAD_BUF_SIZE);
1066e5b75505Sopenharmony_ci	tail_len = BEACON_TAIL_BUF_SIZE;
1067e5b75505Sopenharmony_ci#ifdef CONFIG_WPS
1068e5b75505Sopenharmony_ci	if (hapd->conf->wps_state && hapd->wps_beacon_ie)
1069e5b75505Sopenharmony_ci		tail_len += wpabuf_len(hapd->wps_beacon_ie);
1070e5b75505Sopenharmony_ci#endif /* CONFIG_WPS */
1071e5b75505Sopenharmony_ci#ifdef CONFIG_P2P
1072e5b75505Sopenharmony_ci	if (hapd->p2p_beacon_ie)
1073e5b75505Sopenharmony_ci		tail_len += wpabuf_len(hapd->p2p_beacon_ie);
1074e5b75505Sopenharmony_ci#endif /* CONFIG_P2P */
1075e5b75505Sopenharmony_ci#ifdef CONFIG_FST
1076e5b75505Sopenharmony_ci	if (hapd->iface->fst_ies)
1077e5b75505Sopenharmony_ci		tail_len += wpabuf_len(hapd->iface->fst_ies);
1078e5b75505Sopenharmony_ci#endif /* CONFIG_FST */
1079e5b75505Sopenharmony_ci	if (hapd->conf->vendor_elements)
1080e5b75505Sopenharmony_ci		tail_len += wpabuf_len(hapd->conf->vendor_elements);
1081e5b75505Sopenharmony_ci
1082e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AC
1083e5b75505Sopenharmony_ci	if (hapd->conf->vendor_vht) {
1084e5b75505Sopenharmony_ci		tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
1085e5b75505Sopenharmony_ci			2 + sizeof(struct ieee80211_vht_operation);
1086e5b75505Sopenharmony_ci	}
1087e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AC */
1088e5b75505Sopenharmony_ci
1089e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AX
1090e5b75505Sopenharmony_ci	if (hapd->iconf->ieee80211ax) {
1091e5b75505Sopenharmony_ci		tail_len += 3 + sizeof(struct ieee80211_he_capabilities) +
1092e5b75505Sopenharmony_ci			3 + sizeof(struct ieee80211_he_operation) +
1093e5b75505Sopenharmony_ci			3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
1094e5b75505Sopenharmony_ci			3 + sizeof(struct ieee80211_spatial_reuse);
1095e5b75505Sopenharmony_ci	}
1096e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AX */
1097e5b75505Sopenharmony_ci
1098e5b75505Sopenharmony_ci	tail_len += hostapd_mbo_ie_len(hapd);
1099e5b75505Sopenharmony_ci	tail_len += hostapd_eid_owe_trans_len(hapd);
1100e5b75505Sopenharmony_ci
1101e5b75505Sopenharmony_ci	tailpos = tail = os_malloc(tail_len);
1102e5b75505Sopenharmony_ci	if (head == NULL || tail == NULL) {
1103e5b75505Sopenharmony_ci		wpa_printf(MSG_ERROR, "Failed to set beacon data");
1104e5b75505Sopenharmony_ci		os_free(head);
1105e5b75505Sopenharmony_ci		os_free(tail);
1106e5b75505Sopenharmony_ci		return -1;
1107e5b75505Sopenharmony_ci	}
1108e5b75505Sopenharmony_ci
1109e5b75505Sopenharmony_ci	head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1110e5b75505Sopenharmony_ci					   WLAN_FC_STYPE_BEACON);
1111e5b75505Sopenharmony_ci	head->duration = host_to_le16(0);
1112e5b75505Sopenharmony_ci	os_memset(head->da, 0xff, ETH_ALEN);
1113e5b75505Sopenharmony_ci
1114e5b75505Sopenharmony_ci	os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1115e5b75505Sopenharmony_ci	os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1116e5b75505Sopenharmony_ci	head->u.beacon.beacon_int =
1117e5b75505Sopenharmony_ci		host_to_le16(hapd->iconf->beacon_int);
1118e5b75505Sopenharmony_ci
1119e5b75505Sopenharmony_ci	/* hardware or low-level driver will setup seq_ctrl and timestamp */
1120e5b75505Sopenharmony_ci	capab_info = hostapd_own_capab_info(hapd);
1121e5b75505Sopenharmony_ci	head->u.beacon.capab_info = host_to_le16(capab_info);
1122e5b75505Sopenharmony_ci	pos = &head->u.beacon.variable[0];
1123e5b75505Sopenharmony_ci
1124e5b75505Sopenharmony_ci	/* SSID */
1125e5b75505Sopenharmony_ci	*pos++ = WLAN_EID_SSID;
1126e5b75505Sopenharmony_ci	if (hapd->conf->ignore_broadcast_ssid == 2) {
1127e5b75505Sopenharmony_ci		/* clear the data, but keep the correct length of the SSID */
1128e5b75505Sopenharmony_ci		*pos++ = hapd->conf->ssid.ssid_len;
1129e5b75505Sopenharmony_ci		os_memset(pos, 0, hapd->conf->ssid.ssid_len);
1130e5b75505Sopenharmony_ci		pos += hapd->conf->ssid.ssid_len;
1131e5b75505Sopenharmony_ci	} else if (hapd->conf->ignore_broadcast_ssid) {
1132e5b75505Sopenharmony_ci		*pos++ = 0; /* empty SSID */
1133e5b75505Sopenharmony_ci	} else {
1134e5b75505Sopenharmony_ci		*pos++ = hapd->conf->ssid.ssid_len;
1135e5b75505Sopenharmony_ci		os_memcpy(pos, hapd->conf->ssid.ssid,
1136e5b75505Sopenharmony_ci			  hapd->conf->ssid.ssid_len);
1137e5b75505Sopenharmony_ci		pos += hapd->conf->ssid.ssid_len;
1138e5b75505Sopenharmony_ci	}
1139e5b75505Sopenharmony_ci
1140e5b75505Sopenharmony_ci	/* Supported rates */
1141e5b75505Sopenharmony_ci	pos = hostapd_eid_supp_rates(hapd, pos);
1142e5b75505Sopenharmony_ci
1143e5b75505Sopenharmony_ci	/* DS Params */
1144e5b75505Sopenharmony_ci	pos = hostapd_eid_ds_params(hapd, pos);
1145e5b75505Sopenharmony_ci
1146e5b75505Sopenharmony_ci	head_len = pos - (u8 *) head;
1147e5b75505Sopenharmony_ci
1148e5b75505Sopenharmony_ci	tailpos = hostapd_eid_country(hapd, tailpos,
1149e5b75505Sopenharmony_ci				      tail + BEACON_TAIL_BUF_SIZE - tailpos);
1150e5b75505Sopenharmony_ci
1151e5b75505Sopenharmony_ci	/* Power Constraint element */
1152e5b75505Sopenharmony_ci	tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
1153e5b75505Sopenharmony_ci
1154e5b75505Sopenharmony_ci	/* CSA IE */
1155e5b75505Sopenharmony_ci	csa_pos = hostapd_eid_csa(hapd, tailpos);
1156e5b75505Sopenharmony_ci	if (csa_pos != tailpos)
1157e5b75505Sopenharmony_ci		hapd->cs_c_off_beacon = csa_pos - tail - 1;
1158e5b75505Sopenharmony_ci	tailpos = csa_pos;
1159e5b75505Sopenharmony_ci
1160e5b75505Sopenharmony_ci	/* ERP Information element */
1161e5b75505Sopenharmony_ci	tailpos = hostapd_eid_erp_info(hapd, tailpos);
1162e5b75505Sopenharmony_ci
1163e5b75505Sopenharmony_ci	/* Extended supported rates */
1164e5b75505Sopenharmony_ci	tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
1165e5b75505Sopenharmony_ci
1166e5b75505Sopenharmony_ci	/* RSN, MDIE */
1167e5b75505Sopenharmony_ci	if (hapd->conf->wpa != WPA_PROTO_WPA)
1168e5b75505Sopenharmony_ci		tailpos = hostapd_eid_wpa(hapd, tailpos,
1169e5b75505Sopenharmony_ci					  tail + BEACON_TAIL_BUF_SIZE -
1170e5b75505Sopenharmony_ci					  tailpos);
1171e5b75505Sopenharmony_ci
1172e5b75505Sopenharmony_ci	tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
1173e5b75505Sopenharmony_ci					       tail + BEACON_TAIL_BUF_SIZE -
1174e5b75505Sopenharmony_ci					       tailpos);
1175e5b75505Sopenharmony_ci
1176e5b75505Sopenharmony_ci	tailpos = hostapd_eid_bss_load(hapd, tailpos,
1177e5b75505Sopenharmony_ci				       tail + BEACON_TAIL_BUF_SIZE - tailpos);
1178e5b75505Sopenharmony_ci
1179e5b75505Sopenharmony_ci	/* eCSA IE */
1180e5b75505Sopenharmony_ci	csa_pos = hostapd_eid_ecsa(hapd, tailpos);
1181e5b75505Sopenharmony_ci	if (csa_pos != tailpos)
1182e5b75505Sopenharmony_ci		hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1;
1183e5b75505Sopenharmony_ci	tailpos = csa_pos;
1184e5b75505Sopenharmony_ci
1185e5b75505Sopenharmony_ci	tailpos = hostapd_eid_supported_op_classes(hapd, tailpos);
1186e5b75505Sopenharmony_ci
1187e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211N
1188e5b75505Sopenharmony_ci	/* Secondary Channel Offset element */
1189e5b75505Sopenharmony_ci	/* TODO: The standard doesn't specify a position for this element. */
1190e5b75505Sopenharmony_ci	tailpos = hostapd_eid_secondary_channel(hapd, tailpos);
1191e5b75505Sopenharmony_ci
1192e5b75505Sopenharmony_ci	tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
1193e5b75505Sopenharmony_ci	tailpos = hostapd_eid_ht_operation(hapd, tailpos);
1194e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211N */
1195e5b75505Sopenharmony_ci
1196e5b75505Sopenharmony_ci	tailpos = hostapd_eid_ext_capab(hapd, tailpos);
1197e5b75505Sopenharmony_ci
1198e5b75505Sopenharmony_ci	/*
1199e5b75505Sopenharmony_ci	 * TODO: Time Advertisement element should only be included in some
1200e5b75505Sopenharmony_ci	 * DTIM Beacon frames.
1201e5b75505Sopenharmony_ci	 */
1202e5b75505Sopenharmony_ci	tailpos = hostapd_eid_time_adv(hapd, tailpos);
1203e5b75505Sopenharmony_ci
1204e5b75505Sopenharmony_ci	tailpos = hostapd_eid_interworking(hapd, tailpos);
1205e5b75505Sopenharmony_ci	tailpos = hostapd_eid_adv_proto(hapd, tailpos);
1206e5b75505Sopenharmony_ci	tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
1207e5b75505Sopenharmony_ci
1208e5b75505Sopenharmony_ci#ifdef CONFIG_FST
1209e5b75505Sopenharmony_ci	if (hapd->iface->fst_ies) {
1210e5b75505Sopenharmony_ci		os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies),
1211e5b75505Sopenharmony_ci			  wpabuf_len(hapd->iface->fst_ies));
1212e5b75505Sopenharmony_ci		tailpos += wpabuf_len(hapd->iface->fst_ies);
1213e5b75505Sopenharmony_ci	}
1214e5b75505Sopenharmony_ci#endif /* CONFIG_FST */
1215e5b75505Sopenharmony_ci
1216e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AC
1217e5b75505Sopenharmony_ci	if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
1218e5b75505Sopenharmony_ci		tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0);
1219e5b75505Sopenharmony_ci		tailpos = hostapd_eid_vht_operation(hapd, tailpos);
1220e5b75505Sopenharmony_ci		tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
1221e5b75505Sopenharmony_ci		tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos);
1222e5b75505Sopenharmony_ci	}
1223e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AC */
1224e5b75505Sopenharmony_ci
1225e5b75505Sopenharmony_ci	tailpos = hostapd_eid_fils_indic(hapd, tailpos, 0);
1226e5b75505Sopenharmony_ci
1227e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AX
1228e5b75505Sopenharmony_ci	if (hapd->iconf->ieee80211ax) {
1229e5b75505Sopenharmony_ci		tailpos = hostapd_eid_he_capab(hapd, tailpos,
1230e5b75505Sopenharmony_ci					       IEEE80211_MODE_AP);
1231e5b75505Sopenharmony_ci		tailpos = hostapd_eid_he_operation(hapd, tailpos);
1232e5b75505Sopenharmony_ci		tailpos = hostapd_eid_he_mu_edca_parameter_set(hapd, tailpos);
1233e5b75505Sopenharmony_ci		tailpos = hostapd_eid_spatial_reuse(hapd, tailpos);
1234e5b75505Sopenharmony_ci	}
1235e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AX */
1236e5b75505Sopenharmony_ci
1237e5b75505Sopenharmony_ci#ifdef CONFIG_IEEE80211AC
1238e5b75505Sopenharmony_ci	if (hapd->conf->vendor_vht)
1239e5b75505Sopenharmony_ci		tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
1240e5b75505Sopenharmony_ci#endif /* CONFIG_IEEE80211AC */
1241e5b75505Sopenharmony_ci
1242e5b75505Sopenharmony_ci	/* WPA */
1243e5b75505Sopenharmony_ci	if (hapd->conf->wpa == WPA_PROTO_WPA)
1244e5b75505Sopenharmony_ci		tailpos = hostapd_eid_wpa(hapd, tailpos,
1245e5b75505Sopenharmony_ci					  tail + BEACON_TAIL_BUF_SIZE -
1246e5b75505Sopenharmony_ci					  tailpos);
1247e5b75505Sopenharmony_ci
1248e5b75505Sopenharmony_ci	/* Wi-Fi Alliance WMM */
1249e5b75505Sopenharmony_ci	tailpos = hostapd_eid_wmm(hapd, tailpos);
1250e5b75505Sopenharmony_ci
1251e5b75505Sopenharmony_ci#ifdef CONFIG_WPS
1252e5b75505Sopenharmony_ci	if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
1253e5b75505Sopenharmony_ci		os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
1254e5b75505Sopenharmony_ci			  wpabuf_len(hapd->wps_beacon_ie));
1255e5b75505Sopenharmony_ci		tailpos += wpabuf_len(hapd->wps_beacon_ie);
1256e5b75505Sopenharmony_ci	}
1257e5b75505Sopenharmony_ci#endif /* CONFIG_WPS */
1258e5b75505Sopenharmony_ci
1259e5b75505Sopenharmony_ci#ifdef CONFIG_P2P
1260e5b75505Sopenharmony_ci	if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
1261e5b75505Sopenharmony_ci		os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
1262e5b75505Sopenharmony_ci			  wpabuf_len(hapd->p2p_beacon_ie));
1263e5b75505Sopenharmony_ci		tailpos += wpabuf_len(hapd->p2p_beacon_ie);
1264e5b75505Sopenharmony_ci	}
1265e5b75505Sopenharmony_ci#endif /* CONFIG_P2P */
1266e5b75505Sopenharmony_ci#ifdef CONFIG_P2P_MANAGER
1267e5b75505Sopenharmony_ci	if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
1268e5b75505Sopenharmony_ci	    P2P_MANAGE)
1269e5b75505Sopenharmony_ci		tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
1270e5b75505Sopenharmony_ci#endif /* CONFIG_P2P_MANAGER */
1271e5b75505Sopenharmony_ci
1272e5b75505Sopenharmony_ci#ifdef CONFIG_HS20
1273e5b75505Sopenharmony_ci	tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
1274e5b75505Sopenharmony_ci	tailpos = hostapd_eid_osen(hapd, tailpos);
1275e5b75505Sopenharmony_ci#endif /* CONFIG_HS20 */
1276e5b75505Sopenharmony_ci
1277e5b75505Sopenharmony_ci	tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos);
1278e5b75505Sopenharmony_ci	tailpos = hostapd_eid_owe_trans(hapd, tailpos,
1279e5b75505Sopenharmony_ci					tail + tail_len - tailpos);
1280e5b75505Sopenharmony_ci
1281e5b75505Sopenharmony_ci	if (hapd->conf->vendor_elements) {
1282e5b75505Sopenharmony_ci		os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
1283e5b75505Sopenharmony_ci			  wpabuf_len(hapd->conf->vendor_elements));
1284e5b75505Sopenharmony_ci		tailpos += wpabuf_len(hapd->conf->vendor_elements);
1285e5b75505Sopenharmony_ci	}
1286e5b75505Sopenharmony_ci
1287e5b75505Sopenharmony_ci	tail_len = tailpos > tail ? tailpos - tail : 0;
1288e5b75505Sopenharmony_ci
1289e5b75505Sopenharmony_ci	resp = hostapd_probe_resp_offloads(hapd, &resp_len);
1290e5b75505Sopenharmony_ci#endif /* NEED_AP_MLME */
1291e5b75505Sopenharmony_ci
1292e5b75505Sopenharmony_ci	os_memset(params, 0, sizeof(*params));
1293e5b75505Sopenharmony_ci	params->head = (u8 *) head;
1294e5b75505Sopenharmony_ci	params->head_len = head_len;
1295e5b75505Sopenharmony_ci	params->tail = tail;
1296e5b75505Sopenharmony_ci	params->tail_len = tail_len;
1297e5b75505Sopenharmony_ci	params->proberesp = resp;
1298e5b75505Sopenharmony_ci	params->proberesp_len = resp_len;
1299e5b75505Sopenharmony_ci	params->dtim_period = hapd->conf->dtim_period;
1300e5b75505Sopenharmony_ci	params->beacon_int = hapd->iconf->beacon_int;
1301e5b75505Sopenharmony_ci	params->basic_rates = hapd->iface->basic_rates;
1302e5b75505Sopenharmony_ci	params->beacon_rate = hapd->iconf->beacon_rate;
1303e5b75505Sopenharmony_ci	params->rate_type = hapd->iconf->rate_type;
1304e5b75505Sopenharmony_ci	params->ssid = hapd->conf->ssid.ssid;
1305e5b75505Sopenharmony_ci	params->ssid_len = hapd->conf->ssid.ssid_len;
1306e5b75505Sopenharmony_ci	if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
1307e5b75505Sopenharmony_ci	    (WPA_PROTO_WPA | WPA_PROTO_RSN))
1308e5b75505Sopenharmony_ci		params->pairwise_ciphers = hapd->conf->wpa_pairwise |
1309e5b75505Sopenharmony_ci			hapd->conf->rsn_pairwise;
1310e5b75505Sopenharmony_ci	else if (hapd->conf->wpa & WPA_PROTO_RSN)
1311e5b75505Sopenharmony_ci		params->pairwise_ciphers = hapd->conf->rsn_pairwise;
1312e5b75505Sopenharmony_ci	else if (hapd->conf->wpa & WPA_PROTO_WPA)
1313e5b75505Sopenharmony_ci		params->pairwise_ciphers = hapd->conf->wpa_pairwise;
1314e5b75505Sopenharmony_ci	params->group_cipher = hapd->conf->wpa_group;
1315e5b75505Sopenharmony_ci	params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
1316e5b75505Sopenharmony_ci	params->auth_algs = hapd->conf->auth_algs;
1317e5b75505Sopenharmony_ci	params->wpa_version = hapd->conf->wpa;
1318e5b75505Sopenharmony_ci	params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
1319e5b75505Sopenharmony_ci		(hapd->conf->ieee802_1x &&
1320e5b75505Sopenharmony_ci		 (hapd->conf->default_wep_key_len ||
1321e5b75505Sopenharmony_ci		  hapd->conf->individual_wep_key_len));
1322e5b75505Sopenharmony_ci	switch (hapd->conf->ignore_broadcast_ssid) {
1323e5b75505Sopenharmony_ci	case 0:
1324e5b75505Sopenharmony_ci		params->hide_ssid = NO_SSID_HIDING;
1325e5b75505Sopenharmony_ci		break;
1326e5b75505Sopenharmony_ci	case 1:
1327e5b75505Sopenharmony_ci		params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
1328e5b75505Sopenharmony_ci		break;
1329e5b75505Sopenharmony_ci	case 2:
1330e5b75505Sopenharmony_ci		params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
1331e5b75505Sopenharmony_ci		break;
1332e5b75505Sopenharmony_ci	}
1333e5b75505Sopenharmony_ci	params->isolate = hapd->conf->isolate;
1334e5b75505Sopenharmony_ci	params->smps_mode = hapd->iconf->ht_capab & HT_CAP_INFO_SMPS_MASK;
1335e5b75505Sopenharmony_ci#ifdef NEED_AP_MLME
1336e5b75505Sopenharmony_ci	params->cts_protect = !!(ieee802_11_erp_info(hapd) &
1337e5b75505Sopenharmony_ci				ERP_INFO_USE_PROTECTION);
1338e5b75505Sopenharmony_ci	params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
1339e5b75505Sopenharmony_ci		hapd->iconf->preamble == SHORT_PREAMBLE;
1340e5b75505Sopenharmony_ci	if (hapd->iface->current_mode &&
1341e5b75505Sopenharmony_ci	    hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1342e5b75505Sopenharmony_ci		params->short_slot_time =
1343e5b75505Sopenharmony_ci			hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
1344e5b75505Sopenharmony_ci	else
1345e5b75505Sopenharmony_ci		params->short_slot_time = -1;
1346e5b75505Sopenharmony_ci	if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
1347e5b75505Sopenharmony_ci		params->ht_opmode = -1;
1348e5b75505Sopenharmony_ci	else
1349e5b75505Sopenharmony_ci		params->ht_opmode = hapd->iface->ht_op_mode;
1350e5b75505Sopenharmony_ci#endif /* NEED_AP_MLME */
1351e5b75505Sopenharmony_ci	params->interworking = hapd->conf->interworking;
1352e5b75505Sopenharmony_ci	if (hapd->conf->interworking &&
1353e5b75505Sopenharmony_ci	    !is_zero_ether_addr(hapd->conf->hessid))
1354e5b75505Sopenharmony_ci		params->hessid = hapd->conf->hessid;
1355e5b75505Sopenharmony_ci	params->access_network_type = hapd->conf->access_network_type;
1356e5b75505Sopenharmony_ci	params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
1357e5b75505Sopenharmony_ci#ifdef CONFIG_P2P
1358e5b75505Sopenharmony_ci	params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
1359e5b75505Sopenharmony_ci#endif /* CONFIG_P2P */
1360e5b75505Sopenharmony_ci#ifdef CONFIG_HS20
1361e5b75505Sopenharmony_ci	params->disable_dgaf = hapd->conf->disable_dgaf;
1362e5b75505Sopenharmony_ci	if (hapd->conf->osen) {
1363e5b75505Sopenharmony_ci		params->privacy = 1;
1364e5b75505Sopenharmony_ci		params->osen = 1;
1365e5b75505Sopenharmony_ci	}
1366e5b75505Sopenharmony_ci#endif /* CONFIG_HS20 */
1367e5b75505Sopenharmony_ci	params->multicast_to_unicast = hapd->conf->multicast_to_unicast;
1368e5b75505Sopenharmony_ci	params->pbss = hapd->conf->pbss;
1369e5b75505Sopenharmony_ci
1370e5b75505Sopenharmony_ci	if (hapd->conf->ftm_responder) {
1371e5b75505Sopenharmony_ci		if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_FTM_RESPONDER) {
1372e5b75505Sopenharmony_ci			params->ftm_responder = 1;
1373e5b75505Sopenharmony_ci			params->lci = hapd->iface->conf->lci;
1374e5b75505Sopenharmony_ci			params->civic = hapd->iface->conf->civic;
1375e5b75505Sopenharmony_ci		} else {
1376e5b75505Sopenharmony_ci			wpa_printf(MSG_WARNING,
1377e5b75505Sopenharmony_ci				   "Not configuring FTM responder as the driver doesn't advertise support for it");
1378e5b75505Sopenharmony_ci		}
1379e5b75505Sopenharmony_ci	}
1380e5b75505Sopenharmony_ci
1381e5b75505Sopenharmony_ci	return 0;
1382e5b75505Sopenharmony_ci}
1383e5b75505Sopenharmony_ci
1384e5b75505Sopenharmony_ci
1385e5b75505Sopenharmony_civoid ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
1386e5b75505Sopenharmony_ci{
1387e5b75505Sopenharmony_ci	os_free(params->tail);
1388e5b75505Sopenharmony_ci	params->tail = NULL;
1389e5b75505Sopenharmony_ci	os_free(params->head);
1390e5b75505Sopenharmony_ci	params->head = NULL;
1391e5b75505Sopenharmony_ci	os_free(params->proberesp);
1392e5b75505Sopenharmony_ci	params->proberesp = NULL;
1393e5b75505Sopenharmony_ci}
1394e5b75505Sopenharmony_ci
1395e5b75505Sopenharmony_ci
1396e5b75505Sopenharmony_ciint ieee802_11_set_beacon(struct hostapd_data *hapd)
1397e5b75505Sopenharmony_ci{
1398e5b75505Sopenharmony_ci	struct wpa_driver_ap_params params;
1399e5b75505Sopenharmony_ci	struct hostapd_freq_params freq;
1400e5b75505Sopenharmony_ci	struct hostapd_iface *iface = hapd->iface;
1401e5b75505Sopenharmony_ci	struct hostapd_config *iconf = iface->conf;
1402e5b75505Sopenharmony_ci	struct hostapd_hw_modes *cmode = iface->current_mode;
1403e5b75505Sopenharmony_ci	struct wpabuf *beacon, *proberesp, *assocresp;
1404e5b75505Sopenharmony_ci	int res, ret = -1;
1405e5b75505Sopenharmony_ci
1406e5b75505Sopenharmony_ci	if (hapd->csa_in_progress) {
1407e5b75505Sopenharmony_ci		wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
1408e5b75505Sopenharmony_ci		return -1;
1409e5b75505Sopenharmony_ci	}
1410e5b75505Sopenharmony_ci
1411e5b75505Sopenharmony_ci	hapd->beacon_set_done = 1;
1412e5b75505Sopenharmony_ci
1413e5b75505Sopenharmony_ci	if (ieee802_11_build_ap_params(hapd, &params) < 0)
1414e5b75505Sopenharmony_ci		return -1;
1415e5b75505Sopenharmony_ci
1416e5b75505Sopenharmony_ci	if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
1417e5b75505Sopenharmony_ci	    0)
1418e5b75505Sopenharmony_ci		goto fail;
1419e5b75505Sopenharmony_ci
1420e5b75505Sopenharmony_ci	params.beacon_ies = beacon;
1421e5b75505Sopenharmony_ci	params.proberesp_ies = proberesp;
1422e5b75505Sopenharmony_ci	params.assocresp_ies = assocresp;
1423e5b75505Sopenharmony_ci	params.reenable = hapd->reenable_beacon;
1424e5b75505Sopenharmony_ci	hapd->reenable_beacon = 0;
1425e5b75505Sopenharmony_ci
1426e5b75505Sopenharmony_ci	if (cmode &&
1427e5b75505Sopenharmony_ci	    hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
1428e5b75505Sopenharmony_ci				    iconf->channel, iconf->ieee80211n,
1429e5b75505Sopenharmony_ci				    iconf->ieee80211ac, iconf->ieee80211ax,
1430e5b75505Sopenharmony_ci				    iconf->secondary_channel,
1431e5b75505Sopenharmony_ci				    hostapd_get_oper_chwidth(iconf),
1432e5b75505Sopenharmony_ci				    hostapd_get_oper_centr_freq_seg0_idx(iconf),
1433e5b75505Sopenharmony_ci				    hostapd_get_oper_centr_freq_seg1_idx(iconf),
1434e5b75505Sopenharmony_ci				    cmode->vht_capab,
1435e5b75505Sopenharmony_ci				    &cmode->he_capab[IEEE80211_MODE_AP]) == 0)
1436e5b75505Sopenharmony_ci		params.freq = &freq;
1437e5b75505Sopenharmony_ci
1438e5b75505Sopenharmony_ci	res = hostapd_drv_set_ap(hapd, &params);
1439e5b75505Sopenharmony_ci	hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
1440e5b75505Sopenharmony_ci	if (res)
1441e5b75505Sopenharmony_ci		wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
1442e5b75505Sopenharmony_ci	else
1443e5b75505Sopenharmony_ci		ret = 0;
1444e5b75505Sopenharmony_cifail:
1445e5b75505Sopenharmony_ci	ieee802_11_free_ap_params(&params);
1446e5b75505Sopenharmony_ci	return ret;
1447e5b75505Sopenharmony_ci}
1448e5b75505Sopenharmony_ci
1449e5b75505Sopenharmony_ci
1450e5b75505Sopenharmony_ciint ieee802_11_set_beacons(struct hostapd_iface *iface)
1451e5b75505Sopenharmony_ci{
1452e5b75505Sopenharmony_ci	size_t i;
1453e5b75505Sopenharmony_ci	int ret = 0;
1454e5b75505Sopenharmony_ci
1455e5b75505Sopenharmony_ci	for (i = 0; i < iface->num_bss; i++) {
1456e5b75505Sopenharmony_ci		if (iface->bss[i]->started &&
1457e5b75505Sopenharmony_ci		    ieee802_11_set_beacon(iface->bss[i]) < 0)
1458e5b75505Sopenharmony_ci			ret = -1;
1459e5b75505Sopenharmony_ci	}
1460e5b75505Sopenharmony_ci
1461e5b75505Sopenharmony_ci	return ret;
1462e5b75505Sopenharmony_ci}
1463e5b75505Sopenharmony_ci
1464e5b75505Sopenharmony_ci
1465e5b75505Sopenharmony_ci/* only update beacons if started */
1466e5b75505Sopenharmony_ciint ieee802_11_update_beacons(struct hostapd_iface *iface)
1467e5b75505Sopenharmony_ci{
1468e5b75505Sopenharmony_ci	size_t i;
1469e5b75505Sopenharmony_ci	int ret = 0;
1470e5b75505Sopenharmony_ci
1471e5b75505Sopenharmony_ci	for (i = 0; i < iface->num_bss; i++) {
1472e5b75505Sopenharmony_ci		if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
1473e5b75505Sopenharmony_ci		    ieee802_11_set_beacon(iface->bss[i]) < 0)
1474e5b75505Sopenharmony_ci			ret = -1;
1475e5b75505Sopenharmony_ci	}
1476e5b75505Sopenharmony_ci
1477e5b75505Sopenharmony_ci	return ret;
1478e5b75505Sopenharmony_ci}
1479e5b75505Sopenharmony_ci
1480e5b75505Sopenharmony_ci#endif /* CONFIG_NATIVE_WINDOWS */
1481