xref: /dflybsd-src/contrib/wpa_supplicant/src/ap/beacon.c (revision 3a84a4273475ed07d0ab1c2dfeffdfedef35d9cd)
13ff40c12SJohn Marino /*
23ff40c12SJohn Marino  * hostapd / IEEE 802.11 Management: Beacon and Probe Request/Response
33ff40c12SJohn Marino  * Copyright (c) 2002-2004, Instant802 Networks, Inc.
43ff40c12SJohn Marino  * Copyright (c) 2005-2006, Devicescape Software, Inc.
53ff40c12SJohn Marino  * Copyright (c) 2008-2012, Jouni Malinen <j@w1.fi>
63ff40c12SJohn Marino  *
73ff40c12SJohn Marino  * This software may be distributed under the terms of the BSD license.
83ff40c12SJohn Marino  * See README for more details.
93ff40c12SJohn Marino  */
103ff40c12SJohn Marino 
113ff40c12SJohn Marino #include "utils/includes.h"
123ff40c12SJohn Marino 
133ff40c12SJohn Marino #ifndef CONFIG_NATIVE_WINDOWS
143ff40c12SJohn Marino 
153ff40c12SJohn Marino #include "utils/common.h"
163ff40c12SJohn Marino #include "common/ieee802_11_defs.h"
173ff40c12SJohn Marino #include "common/ieee802_11_common.h"
18*a1157835SDaniel Fojt #include "common/hw_features_common.h"
19*a1157835SDaniel Fojt #include "common/wpa_ctrl.h"
203ff40c12SJohn Marino #include "wps/wps_defs.h"
213ff40c12SJohn Marino #include "p2p/p2p.h"
223ff40c12SJohn Marino #include "hostapd.h"
233ff40c12SJohn Marino #include "ieee802_11.h"
243ff40c12SJohn Marino #include "wpa_auth.h"
253ff40c12SJohn Marino #include "wmm.h"
263ff40c12SJohn Marino #include "ap_config.h"
273ff40c12SJohn Marino #include "sta_info.h"
283ff40c12SJohn Marino #include "p2p_hostapd.h"
293ff40c12SJohn Marino #include "ap_drv_ops.h"
303ff40c12SJohn Marino #include "beacon.h"
313ff40c12SJohn Marino #include "hs20.h"
32*a1157835SDaniel Fojt #include "dfs.h"
33*a1157835SDaniel Fojt #include "taxonomy.h"
34*a1157835SDaniel Fojt #include "ieee802_11_auth.h"
353ff40c12SJohn Marino 
363ff40c12SJohn Marino 
373ff40c12SJohn Marino #ifdef NEED_AP_MLME
383ff40c12SJohn Marino 
hostapd_eid_rm_enabled_capab(struct hostapd_data * hapd,u8 * eid,size_t len)39*a1157835SDaniel Fojt static u8 * hostapd_eid_rm_enabled_capab(struct hostapd_data *hapd, u8 *eid,
40*a1157835SDaniel Fojt 					 size_t len)
41*a1157835SDaniel Fojt {
42*a1157835SDaniel Fojt 	size_t i;
43*a1157835SDaniel Fojt 
44*a1157835SDaniel Fojt 	for (i = 0; i < RRM_CAPABILITIES_IE_LEN; i++) {
45*a1157835SDaniel Fojt 		if (hapd->conf->radio_measurements[i])
46*a1157835SDaniel Fojt 			break;
47*a1157835SDaniel Fojt 	}
48*a1157835SDaniel Fojt 
49*a1157835SDaniel Fojt 	if (i == RRM_CAPABILITIES_IE_LEN || len < 2 + RRM_CAPABILITIES_IE_LEN)
50*a1157835SDaniel Fojt 		return eid;
51*a1157835SDaniel Fojt 
52*a1157835SDaniel Fojt 	*eid++ = WLAN_EID_RRM_ENABLED_CAPABILITIES;
53*a1157835SDaniel Fojt 	*eid++ = RRM_CAPABILITIES_IE_LEN;
54*a1157835SDaniel Fojt 	os_memcpy(eid, hapd->conf->radio_measurements, RRM_CAPABILITIES_IE_LEN);
55*a1157835SDaniel Fojt 
56*a1157835SDaniel Fojt 	return eid + RRM_CAPABILITIES_IE_LEN;
57*a1157835SDaniel Fojt }
58*a1157835SDaniel Fojt 
59*a1157835SDaniel Fojt 
hostapd_eid_bss_load(struct hostapd_data * hapd,u8 * eid,size_t len)603ff40c12SJohn Marino static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
613ff40c12SJohn Marino {
62*a1157835SDaniel Fojt 	if (len < 2 + 5)
63*a1157835SDaniel Fojt 		return eid;
64*a1157835SDaniel Fojt 
653ff40c12SJohn Marino #ifdef CONFIG_TESTING_OPTIONS
663ff40c12SJohn Marino 	if (hapd->conf->bss_load_test_set) {
673ff40c12SJohn Marino 		*eid++ = WLAN_EID_BSS_LOAD;
683ff40c12SJohn Marino 		*eid++ = 5;
693ff40c12SJohn Marino 		os_memcpy(eid, hapd->conf->bss_load_test, 5);
703ff40c12SJohn Marino 		eid += 5;
71*a1157835SDaniel Fojt 		return eid;
723ff40c12SJohn Marino 	}
733ff40c12SJohn Marino #endif /* CONFIG_TESTING_OPTIONS */
74*a1157835SDaniel Fojt 	if (hapd->conf->bss_load_update_period) {
75*a1157835SDaniel Fojt 		*eid++ = WLAN_EID_BSS_LOAD;
76*a1157835SDaniel Fojt 		*eid++ = 5;
77*a1157835SDaniel Fojt 		WPA_PUT_LE16(eid, hapd->num_sta);
78*a1157835SDaniel Fojt 		eid += 2;
79*a1157835SDaniel Fojt 		*eid++ = hapd->iface->channel_utilization;
80*a1157835SDaniel Fojt 		WPA_PUT_LE16(eid, 0); /* no available admission capabity */
81*a1157835SDaniel Fojt 		eid += 2;
82*a1157835SDaniel Fojt 	}
833ff40c12SJohn Marino 	return eid;
843ff40c12SJohn Marino }
853ff40c12SJohn Marino 
863ff40c12SJohn Marino 
ieee802_11_erp_info(struct hostapd_data * hapd)873ff40c12SJohn Marino static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
883ff40c12SJohn Marino {
893ff40c12SJohn Marino 	u8 erp = 0;
903ff40c12SJohn Marino 
913ff40c12SJohn Marino 	if (hapd->iface->current_mode == NULL ||
923ff40c12SJohn Marino 	    hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
933ff40c12SJohn Marino 		return 0;
943ff40c12SJohn Marino 
953ff40c12SJohn Marino 	if (hapd->iface->olbc)
963ff40c12SJohn Marino 		erp |= ERP_INFO_USE_PROTECTION;
973ff40c12SJohn Marino 	if (hapd->iface->num_sta_non_erp > 0) {
983ff40c12SJohn Marino 		erp |= ERP_INFO_NON_ERP_PRESENT |
993ff40c12SJohn Marino 			ERP_INFO_USE_PROTECTION;
1003ff40c12SJohn Marino 	}
1013ff40c12SJohn Marino 	if (hapd->iface->num_sta_no_short_preamble > 0 ||
1023ff40c12SJohn Marino 	    hapd->iconf->preamble == LONG_PREAMBLE)
1033ff40c12SJohn Marino 		erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
1043ff40c12SJohn Marino 
1053ff40c12SJohn Marino 	return erp;
1063ff40c12SJohn Marino }
1073ff40c12SJohn Marino 
1083ff40c12SJohn Marino 
hostapd_eid_ds_params(struct hostapd_data * hapd,u8 * eid)1093ff40c12SJohn Marino static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
1103ff40c12SJohn Marino {
1113ff40c12SJohn Marino 	*eid++ = WLAN_EID_DS_PARAMS;
1123ff40c12SJohn Marino 	*eid++ = 1;
1133ff40c12SJohn Marino 	*eid++ = hapd->iconf->channel;
1143ff40c12SJohn Marino 	return eid;
1153ff40c12SJohn Marino }
1163ff40c12SJohn Marino 
1173ff40c12SJohn Marino 
hostapd_eid_erp_info(struct hostapd_data * hapd,u8 * eid)1183ff40c12SJohn Marino static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
1193ff40c12SJohn Marino {
1203ff40c12SJohn Marino 	if (hapd->iface->current_mode == NULL ||
1213ff40c12SJohn Marino 	    hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
1223ff40c12SJohn Marino 		return eid;
1233ff40c12SJohn Marino 
1243ff40c12SJohn Marino 	/* Set NonERP_present and use_protection bits if there
1253ff40c12SJohn Marino 	 * are any associated NonERP stations. */
1263ff40c12SJohn Marino 	/* TODO: use_protection bit can be set to zero even if
1273ff40c12SJohn Marino 	 * there are NonERP stations present. This optimization
1283ff40c12SJohn Marino 	 * might be useful if NonERP stations are "quiet".
1293ff40c12SJohn Marino 	 * See 802.11g/D6 E-1 for recommended practice.
1303ff40c12SJohn Marino 	 * In addition, Non ERP present might be set, if AP detects Non ERP
1313ff40c12SJohn Marino 	 * operation on other APs. */
1323ff40c12SJohn Marino 
1333ff40c12SJohn Marino 	/* Add ERP Information element */
1343ff40c12SJohn Marino 	*eid++ = WLAN_EID_ERP_INFO;
1353ff40c12SJohn Marino 	*eid++ = 1;
1363ff40c12SJohn Marino 	*eid++ = ieee802_11_erp_info(hapd);
1373ff40c12SJohn Marino 
1383ff40c12SJohn Marino 	return eid;
1393ff40c12SJohn Marino }
1403ff40c12SJohn Marino 
1413ff40c12SJohn Marino 
hostapd_eid_pwr_constraint(struct hostapd_data * hapd,u8 * eid)142*a1157835SDaniel Fojt static u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid)
143*a1157835SDaniel Fojt {
144*a1157835SDaniel Fojt 	u8 *pos = eid;
145*a1157835SDaniel Fojt 	u8 local_pwr_constraint = 0;
146*a1157835SDaniel Fojt 	int dfs;
147*a1157835SDaniel Fojt 
148*a1157835SDaniel Fojt 	if (hapd->iface->current_mode == NULL ||
149*a1157835SDaniel Fojt 	    hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
150*a1157835SDaniel Fojt 		return eid;
151*a1157835SDaniel Fojt 
152*a1157835SDaniel Fojt 	/* Let host drivers add this IE if DFS support is offloaded */
153*a1157835SDaniel Fojt 	if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)
154*a1157835SDaniel Fojt 		return eid;
155*a1157835SDaniel Fojt 
156*a1157835SDaniel Fojt 	/*
157*a1157835SDaniel Fojt 	 * There is no DFS support and power constraint was not directly
158*a1157835SDaniel Fojt 	 * requested by config option.
159*a1157835SDaniel Fojt 	 */
160*a1157835SDaniel Fojt 	if (!hapd->iconf->ieee80211h &&
161*a1157835SDaniel Fojt 	    hapd->iconf->local_pwr_constraint == -1)
162*a1157835SDaniel Fojt 		return eid;
163*a1157835SDaniel Fojt 
164*a1157835SDaniel Fojt 	/* Check if DFS is required by regulatory. */
165*a1157835SDaniel Fojt 	dfs = hostapd_is_dfs_required(hapd->iface);
166*a1157835SDaniel Fojt 	if (dfs < 0) {
167*a1157835SDaniel Fojt 		wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
168*a1157835SDaniel Fojt 			   dfs);
169*a1157835SDaniel Fojt 		dfs = 0;
170*a1157835SDaniel Fojt 	}
171*a1157835SDaniel Fojt 
172*a1157835SDaniel Fojt 	if (dfs == 0 && hapd->iconf->local_pwr_constraint == -1)
173*a1157835SDaniel Fojt 		return eid;
174*a1157835SDaniel Fojt 
175*a1157835SDaniel Fojt 	/*
176*a1157835SDaniel Fojt 	 * ieee80211h (DFS) is enabled so Power Constraint element shall
177*a1157835SDaniel Fojt 	 * be added when running on DFS channel whenever local_pwr_constraint
178*a1157835SDaniel Fojt 	 * is configured or not. In order to meet regulations when TPC is not
179*a1157835SDaniel Fojt 	 * implemented using a transmit power that is below the legal maximum
180*a1157835SDaniel Fojt 	 * (including any mitigation factor) should help. In this case,
181*a1157835SDaniel Fojt 	 * indicate 3 dB below maximum allowed transmit power.
182*a1157835SDaniel Fojt 	 */
183*a1157835SDaniel Fojt 	if (hapd->iconf->local_pwr_constraint == -1)
184*a1157835SDaniel Fojt 		local_pwr_constraint = 3;
185*a1157835SDaniel Fojt 
186*a1157835SDaniel Fojt 	/*
187*a1157835SDaniel Fojt 	 * A STA that is not an AP shall use a transmit power less than or
188*a1157835SDaniel Fojt 	 * equal to the local maximum transmit power level for the channel.
189*a1157835SDaniel Fojt 	 * The local maximum transmit power can be calculated from the formula:
190*a1157835SDaniel Fojt 	 * local max TX pwr = max TX pwr - local pwr constraint
191*a1157835SDaniel Fojt 	 * Where max TX pwr is maximum transmit power level specified for
192*a1157835SDaniel Fojt 	 * channel in Country element and local pwr constraint is specified
193*a1157835SDaniel Fojt 	 * for channel in this Power Constraint element.
194*a1157835SDaniel Fojt 	 */
195*a1157835SDaniel Fojt 
196*a1157835SDaniel Fojt 	/* Element ID */
197*a1157835SDaniel Fojt 	*pos++ = WLAN_EID_PWR_CONSTRAINT;
198*a1157835SDaniel Fojt 	/* Length */
199*a1157835SDaniel Fojt 	*pos++ = 1;
200*a1157835SDaniel Fojt 	/* Local Power Constraint */
201*a1157835SDaniel Fojt 	if (local_pwr_constraint)
202*a1157835SDaniel Fojt 		*pos++ = local_pwr_constraint;
203*a1157835SDaniel Fojt 	else
204*a1157835SDaniel Fojt 		*pos++ = hapd->iconf->local_pwr_constraint;
205*a1157835SDaniel Fojt 
206*a1157835SDaniel Fojt 	return pos;
207*a1157835SDaniel Fojt }
208*a1157835SDaniel Fojt 
209*a1157835SDaniel Fojt 
hostapd_eid_country_add(u8 * pos,u8 * end,int chan_spacing,struct hostapd_channel_data * start,struct hostapd_channel_data * prev)2103ff40c12SJohn Marino static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
2113ff40c12SJohn Marino 				    struct hostapd_channel_data *start,
2123ff40c12SJohn Marino 				    struct hostapd_channel_data *prev)
2133ff40c12SJohn Marino {
2143ff40c12SJohn Marino 	if (end - pos < 3)
2153ff40c12SJohn Marino 		return pos;
2163ff40c12SJohn Marino 
2173ff40c12SJohn Marino 	/* first channel number */
2183ff40c12SJohn Marino 	*pos++ = start->chan;
2193ff40c12SJohn Marino 	/* number of channels */
2203ff40c12SJohn Marino 	*pos++ = (prev->chan - start->chan) / chan_spacing + 1;
2213ff40c12SJohn Marino 	/* maximum transmit power level */
2223ff40c12SJohn Marino 	*pos++ = start->max_tx_power;
2233ff40c12SJohn Marino 
2243ff40c12SJohn Marino 	return pos;
2253ff40c12SJohn Marino }
2263ff40c12SJohn Marino 
2273ff40c12SJohn Marino 
hostapd_eid_country(struct hostapd_data * hapd,u8 * eid,int max_len)2283ff40c12SJohn Marino static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
2293ff40c12SJohn Marino 				int max_len)
2303ff40c12SJohn Marino {
2313ff40c12SJohn Marino 	u8 *pos = eid;
2323ff40c12SJohn Marino 	u8 *end = eid + max_len;
2333ff40c12SJohn Marino 	int i;
2343ff40c12SJohn Marino 	struct hostapd_hw_modes *mode;
2353ff40c12SJohn Marino 	struct hostapd_channel_data *start, *prev;
2363ff40c12SJohn Marino 	int chan_spacing = 1;
2373ff40c12SJohn Marino 
2383ff40c12SJohn Marino 	if (!hapd->iconf->ieee80211d || max_len < 6 ||
2393ff40c12SJohn Marino 	    hapd->iface->current_mode == NULL)
2403ff40c12SJohn Marino 		return eid;
2413ff40c12SJohn Marino 
2423ff40c12SJohn Marino 	*pos++ = WLAN_EID_COUNTRY;
2433ff40c12SJohn Marino 	pos++; /* length will be set later */
2443ff40c12SJohn Marino 	os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
2453ff40c12SJohn Marino 	pos += 3;
2463ff40c12SJohn Marino 
2473ff40c12SJohn Marino 	mode = hapd->iface->current_mode;
2483ff40c12SJohn Marino 	if (mode->mode == HOSTAPD_MODE_IEEE80211A)
2493ff40c12SJohn Marino 		chan_spacing = 4;
2503ff40c12SJohn Marino 
2513ff40c12SJohn Marino 	start = prev = NULL;
2523ff40c12SJohn Marino 	for (i = 0; i < mode->num_channels; i++) {
2533ff40c12SJohn Marino 		struct hostapd_channel_data *chan = &mode->channels[i];
2543ff40c12SJohn Marino 		if (chan->flag & HOSTAPD_CHAN_DISABLED)
2553ff40c12SJohn Marino 			continue;
2563ff40c12SJohn Marino 		if (start && prev &&
2573ff40c12SJohn Marino 		    prev->chan + chan_spacing == chan->chan &&
2583ff40c12SJohn Marino 		    start->max_tx_power == chan->max_tx_power) {
2593ff40c12SJohn Marino 			prev = chan;
2603ff40c12SJohn Marino 			continue; /* can use same entry */
2613ff40c12SJohn Marino 		}
2623ff40c12SJohn Marino 
263*a1157835SDaniel Fojt 		if (start && prev) {
2643ff40c12SJohn Marino 			pos = hostapd_eid_country_add(pos, end, chan_spacing,
2653ff40c12SJohn Marino 						      start, prev);
2663ff40c12SJohn Marino 			start = NULL;
2673ff40c12SJohn Marino 		}
2683ff40c12SJohn Marino 
2693ff40c12SJohn Marino 		/* Start new group */
2703ff40c12SJohn Marino 		start = prev = chan;
2713ff40c12SJohn Marino 	}
2723ff40c12SJohn Marino 
2733ff40c12SJohn Marino 	if (start) {
2743ff40c12SJohn Marino 		pos = hostapd_eid_country_add(pos, end, chan_spacing,
2753ff40c12SJohn Marino 					      start, prev);
2763ff40c12SJohn Marino 	}
2773ff40c12SJohn Marino 
2783ff40c12SJohn Marino 	if ((pos - eid) & 1) {
2793ff40c12SJohn Marino 		if (end - pos < 1)
2803ff40c12SJohn Marino 			return eid;
2813ff40c12SJohn Marino 		*pos++ = 0; /* pad for 16-bit alignment */
2823ff40c12SJohn Marino 	}
2833ff40c12SJohn Marino 
2843ff40c12SJohn Marino 	eid[1] = (pos - eid) - 2;
2853ff40c12SJohn Marino 
2863ff40c12SJohn Marino 	return pos;
2873ff40c12SJohn Marino }
2883ff40c12SJohn Marino 
2893ff40c12SJohn Marino 
hostapd_eid_wpa(struct hostapd_data * hapd,u8 * eid,size_t len)2903ff40c12SJohn Marino static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
2913ff40c12SJohn Marino {
2923ff40c12SJohn Marino 	const u8 *ie;
2933ff40c12SJohn Marino 	size_t ielen;
2943ff40c12SJohn Marino 
2953ff40c12SJohn Marino 	ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
2963ff40c12SJohn Marino 	if (ie == NULL || ielen > len)
2973ff40c12SJohn Marino 		return eid;
2983ff40c12SJohn Marino 
2993ff40c12SJohn Marino 	os_memcpy(eid, ie, ielen);
3003ff40c12SJohn Marino 	return eid + ielen;
3013ff40c12SJohn Marino }
3023ff40c12SJohn Marino 
3033ff40c12SJohn Marino 
hostapd_eid_csa(struct hostapd_data * hapd,u8 * eid)3043ff40c12SJohn Marino static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
3053ff40c12SJohn Marino {
306*a1157835SDaniel Fojt #ifdef CONFIG_TESTING_OPTIONS
307*a1157835SDaniel Fojt 	if (hapd->iface->cs_oper_class && hapd->iconf->ecsa_ie_only)
3083ff40c12SJohn Marino 		return eid;
309*a1157835SDaniel Fojt #endif /* CONFIG_TESTING_OPTIONS */
3103ff40c12SJohn Marino 
311*a1157835SDaniel Fojt 	if (!hapd->cs_freq_params.channel)
3123ff40c12SJohn Marino 		return eid;
3133ff40c12SJohn Marino 
3143ff40c12SJohn Marino 	*eid++ = WLAN_EID_CHANNEL_SWITCH;
3153ff40c12SJohn Marino 	*eid++ = 3;
316*a1157835SDaniel Fojt 	*eid++ = hapd->cs_block_tx;
317*a1157835SDaniel Fojt 	*eid++ = hapd->cs_freq_params.channel;
318*a1157835SDaniel Fojt 	*eid++ = hapd->cs_count;
3193ff40c12SJohn Marino 
3203ff40c12SJohn Marino 	return eid;
3213ff40c12SJohn Marino }
3223ff40c12SJohn Marino 
3233ff40c12SJohn Marino 
hostapd_eid_ecsa(struct hostapd_data * hapd,u8 * eid)324*a1157835SDaniel Fojt static u8 * hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid)
3253ff40c12SJohn Marino {
326*a1157835SDaniel Fojt 	if (!hapd->cs_freq_params.channel || !hapd->iface->cs_oper_class)
3273ff40c12SJohn Marino 		return eid;
3283ff40c12SJohn Marino 
329*a1157835SDaniel Fojt 	*eid++ = WLAN_EID_EXT_CHANSWITCH_ANN;
330*a1157835SDaniel Fojt 	*eid++ = 4;
331*a1157835SDaniel Fojt 	*eid++ = hapd->cs_block_tx;
332*a1157835SDaniel Fojt 	*eid++ = hapd->iface->cs_oper_class;
333*a1157835SDaniel Fojt 	*eid++ = hapd->cs_freq_params.channel;
334*a1157835SDaniel Fojt 	*eid++ = hapd->cs_count;
3353ff40c12SJohn Marino 
3363ff40c12SJohn Marino 	return eid;
3373ff40c12SJohn Marino }
3383ff40c12SJohn Marino 
3393ff40c12SJohn Marino 
hostapd_eid_supported_op_classes(struct hostapd_data * hapd,u8 * eid)340*a1157835SDaniel Fojt static u8 * hostapd_eid_supported_op_classes(struct hostapd_data *hapd, u8 *eid)
3413ff40c12SJohn Marino {
342*a1157835SDaniel Fojt 	u8 op_class, channel;
3433ff40c12SJohn Marino 
344*a1157835SDaniel Fojt 	if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) ||
345*a1157835SDaniel Fojt 	    !hapd->iface->freq)
346*a1157835SDaniel Fojt 		return eid;
3473ff40c12SJohn Marino 
348*a1157835SDaniel Fojt 	if (ieee80211_freq_to_channel_ext(hapd->iface->freq,
349*a1157835SDaniel Fojt 					  hapd->iconf->secondary_channel,
350*a1157835SDaniel Fojt 					  hostapd_get_oper_chwidth(hapd->iconf),
351*a1157835SDaniel Fojt 					  &op_class, &channel) ==
352*a1157835SDaniel Fojt 	    NUM_HOSTAPD_MODES)
353*a1157835SDaniel Fojt 		return eid;
3543ff40c12SJohn Marino 
355*a1157835SDaniel Fojt 	*eid++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES;
356*a1157835SDaniel Fojt 	*eid++ = 2;
3573ff40c12SJohn Marino 
358*a1157835SDaniel Fojt 	/* Current Operating Class */
359*a1157835SDaniel Fojt 	*eid++ = op_class;
360*a1157835SDaniel Fojt 
361*a1157835SDaniel Fojt 	/* TODO: Advertise all the supported operating classes */
362*a1157835SDaniel Fojt 	*eid++ = 0;
363*a1157835SDaniel Fojt 
364*a1157835SDaniel Fojt 	return eid;
3653ff40c12SJohn Marino }
3663ff40c12SJohn Marino 
3673ff40c12SJohn Marino 
hostapd_gen_probe_resp(struct hostapd_data * hapd,const struct ieee80211_mgmt * req,int is_p2p,size_t * resp_len)3683ff40c12SJohn Marino static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
3693ff40c12SJohn Marino 				   const struct ieee80211_mgmt *req,
3703ff40c12SJohn Marino 				   int is_p2p, size_t *resp_len)
3713ff40c12SJohn Marino {
3723ff40c12SJohn Marino 	struct ieee80211_mgmt *resp;
373*a1157835SDaniel Fojt 	u8 *pos, *epos, *csa_pos;
3743ff40c12SJohn Marino 	size_t buflen;
3753ff40c12SJohn Marino 
3763ff40c12SJohn Marino #define MAX_PROBERESP_LEN 768
3773ff40c12SJohn Marino 	buflen = MAX_PROBERESP_LEN;
3783ff40c12SJohn Marino #ifdef CONFIG_WPS
3793ff40c12SJohn Marino 	if (hapd->wps_probe_resp_ie)
3803ff40c12SJohn Marino 		buflen += wpabuf_len(hapd->wps_probe_resp_ie);
3813ff40c12SJohn Marino #endif /* CONFIG_WPS */
3823ff40c12SJohn Marino #ifdef CONFIG_P2P
3833ff40c12SJohn Marino 	if (hapd->p2p_probe_resp_ie)
3843ff40c12SJohn Marino 		buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
3853ff40c12SJohn Marino #endif /* CONFIG_P2P */
386*a1157835SDaniel Fojt #ifdef CONFIG_FST
387*a1157835SDaniel Fojt 	if (hapd->iface->fst_ies)
388*a1157835SDaniel Fojt 		buflen += wpabuf_len(hapd->iface->fst_ies);
389*a1157835SDaniel Fojt #endif /* CONFIG_FST */
3903ff40c12SJohn Marino 	if (hapd->conf->vendor_elements)
3913ff40c12SJohn Marino 		buflen += wpabuf_len(hapd->conf->vendor_elements);
392*a1157835SDaniel Fojt 	if (hapd->conf->vendor_vht) {
393*a1157835SDaniel Fojt 		buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
394*a1157835SDaniel Fojt 			2 + sizeof(struct ieee80211_vht_operation);
395*a1157835SDaniel Fojt 	}
396*a1157835SDaniel Fojt 
397*a1157835SDaniel Fojt #ifdef CONFIG_IEEE80211AX
398*a1157835SDaniel Fojt 	if (hapd->iconf->ieee80211ax) {
399*a1157835SDaniel Fojt 		buflen += 3 + sizeof(struct ieee80211_he_capabilities) +
400*a1157835SDaniel Fojt 			3 + sizeof(struct ieee80211_he_operation) +
401*a1157835SDaniel Fojt 			3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
402*a1157835SDaniel Fojt 			3 + sizeof(struct ieee80211_spatial_reuse);
403*a1157835SDaniel Fojt 	}
404*a1157835SDaniel Fojt #endif /* CONFIG_IEEE80211AX */
405*a1157835SDaniel Fojt 
406*a1157835SDaniel Fojt 	buflen += hostapd_mbo_ie_len(hapd);
407*a1157835SDaniel Fojt 	buflen += hostapd_eid_owe_trans_len(hapd);
408*a1157835SDaniel Fojt 
4093ff40c12SJohn Marino 	resp = os_zalloc(buflen);
4103ff40c12SJohn Marino 	if (resp == NULL)
4113ff40c12SJohn Marino 		return NULL;
4123ff40c12SJohn Marino 
4133ff40c12SJohn Marino 	epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
4143ff40c12SJohn Marino 
4153ff40c12SJohn Marino 	resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
4163ff40c12SJohn Marino 					   WLAN_FC_STYPE_PROBE_RESP);
4173ff40c12SJohn Marino 	if (req)
4183ff40c12SJohn Marino 		os_memcpy(resp->da, req->sa, ETH_ALEN);
4193ff40c12SJohn Marino 	os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
4203ff40c12SJohn Marino 
4213ff40c12SJohn Marino 	os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
4223ff40c12SJohn Marino 	resp->u.probe_resp.beacon_int =
4233ff40c12SJohn Marino 		host_to_le16(hapd->iconf->beacon_int);
4243ff40c12SJohn Marino 
4253ff40c12SJohn Marino 	/* hardware or low-level driver will setup seq_ctrl and timestamp */
4263ff40c12SJohn Marino 	resp->u.probe_resp.capab_info =
427*a1157835SDaniel Fojt 		host_to_le16(hostapd_own_capab_info(hapd));
4283ff40c12SJohn Marino 
4293ff40c12SJohn Marino 	pos = resp->u.probe_resp.variable;
4303ff40c12SJohn Marino 	*pos++ = WLAN_EID_SSID;
4313ff40c12SJohn Marino 	*pos++ = hapd->conf->ssid.ssid_len;
4323ff40c12SJohn Marino 	os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
4333ff40c12SJohn Marino 	pos += hapd->conf->ssid.ssid_len;
4343ff40c12SJohn Marino 
4353ff40c12SJohn Marino 	/* Supported rates */
4363ff40c12SJohn Marino 	pos = hostapd_eid_supp_rates(hapd, pos);
4373ff40c12SJohn Marino 
4383ff40c12SJohn Marino 	/* DS Params */
4393ff40c12SJohn Marino 	pos = hostapd_eid_ds_params(hapd, pos);
4403ff40c12SJohn Marino 
4413ff40c12SJohn Marino 	pos = hostapd_eid_country(hapd, pos, epos - pos);
4423ff40c12SJohn Marino 
443*a1157835SDaniel Fojt 	/* Power Constraint element */
444*a1157835SDaniel Fojt 	pos = hostapd_eid_pwr_constraint(hapd, pos);
445*a1157835SDaniel Fojt 
446*a1157835SDaniel Fojt 	/* CSA IE */
447*a1157835SDaniel Fojt 	csa_pos = hostapd_eid_csa(hapd, pos);
448*a1157835SDaniel Fojt 	if (csa_pos != pos)
449*a1157835SDaniel Fojt 		hapd->cs_c_off_proberesp = csa_pos - (u8 *) resp - 1;
450*a1157835SDaniel Fojt 	pos = csa_pos;
451*a1157835SDaniel Fojt 
4523ff40c12SJohn Marino 	/* ERP Information element */
4533ff40c12SJohn Marino 	pos = hostapd_eid_erp_info(hapd, pos);
4543ff40c12SJohn Marino 
4553ff40c12SJohn Marino 	/* Extended supported rates */
4563ff40c12SJohn Marino 	pos = hostapd_eid_ext_supp_rates(hapd, pos);
4573ff40c12SJohn Marino 
458*a1157835SDaniel Fojt 	/* RSN, MDIE */
459*a1157835SDaniel Fojt 	if (hapd->conf->wpa != WPA_PROTO_WPA)
4603ff40c12SJohn Marino 		pos = hostapd_eid_wpa(hapd, pos, epos - pos);
4613ff40c12SJohn Marino 
4623ff40c12SJohn Marino 	pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
4633ff40c12SJohn Marino 
464*a1157835SDaniel Fojt 	pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
465*a1157835SDaniel Fojt 
466*a1157835SDaniel Fojt 	/* eCSA IE */
467*a1157835SDaniel Fojt 	csa_pos = hostapd_eid_ecsa(hapd, pos);
468*a1157835SDaniel Fojt 	if (csa_pos != pos)
469*a1157835SDaniel Fojt 		hapd->cs_c_off_ecsa_proberesp = csa_pos - (u8 *) resp - 1;
470*a1157835SDaniel Fojt 	pos = csa_pos;
471*a1157835SDaniel Fojt 
472*a1157835SDaniel Fojt 	pos = hostapd_eid_supported_op_classes(hapd, pos);
473*a1157835SDaniel Fojt 
4743ff40c12SJohn Marino #ifdef CONFIG_IEEE80211N
475*a1157835SDaniel Fojt 	/* Secondary Channel Offset element */
476*a1157835SDaniel Fojt 	/* TODO: The standard doesn't specify a position for this element. */
477*a1157835SDaniel Fojt 	pos = hostapd_eid_secondary_channel(hapd, pos);
478*a1157835SDaniel Fojt 
4793ff40c12SJohn Marino 	pos = hostapd_eid_ht_capabilities(hapd, pos);
4803ff40c12SJohn Marino 	pos = hostapd_eid_ht_operation(hapd, pos);
4813ff40c12SJohn Marino #endif /* CONFIG_IEEE80211N */
4823ff40c12SJohn Marino 
4833ff40c12SJohn Marino 	pos = hostapd_eid_ext_capab(hapd, pos);
4843ff40c12SJohn Marino 
4853ff40c12SJohn Marino 	pos = hostapd_eid_time_adv(hapd, pos);
4863ff40c12SJohn Marino 	pos = hostapd_eid_time_zone(hapd, pos);
4873ff40c12SJohn Marino 
4883ff40c12SJohn Marino 	pos = hostapd_eid_interworking(hapd, pos);
4893ff40c12SJohn Marino 	pos = hostapd_eid_adv_proto(hapd, pos);
4903ff40c12SJohn Marino 	pos = hostapd_eid_roaming_consortium(hapd, pos);
4913ff40c12SJohn Marino 
492*a1157835SDaniel Fojt #ifdef CONFIG_FST
493*a1157835SDaniel Fojt 	if (hapd->iface->fst_ies) {
494*a1157835SDaniel Fojt 		os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies),
495*a1157835SDaniel Fojt 			  wpabuf_len(hapd->iface->fst_ies));
496*a1157835SDaniel Fojt 		pos += wpabuf_len(hapd->iface->fst_ies);
497*a1157835SDaniel Fojt 	}
498*a1157835SDaniel Fojt #endif /* CONFIG_FST */
499*a1157835SDaniel Fojt 
5003ff40c12SJohn Marino #ifdef CONFIG_IEEE80211AC
501*a1157835SDaniel Fojt 	if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
502*a1157835SDaniel Fojt 		pos = hostapd_eid_vht_capabilities(hapd, pos, 0);
5033ff40c12SJohn Marino 		pos = hostapd_eid_vht_operation(hapd, pos);
504*a1157835SDaniel Fojt 		pos = hostapd_eid_txpower_envelope(hapd, pos);
505*a1157835SDaniel Fojt 		pos = hostapd_eid_wb_chsw_wrapper(hapd, pos);
506*a1157835SDaniel Fojt 	}
5073ff40c12SJohn Marino #endif /* CONFIG_IEEE80211AC */
5083ff40c12SJohn Marino 
509*a1157835SDaniel Fojt 	pos = hostapd_eid_fils_indic(hapd, pos, 0);
510*a1157835SDaniel Fojt 
511*a1157835SDaniel Fojt #ifdef CONFIG_IEEE80211AX
512*a1157835SDaniel Fojt 	if (hapd->iconf->ieee80211ax) {
513*a1157835SDaniel Fojt 		pos = hostapd_eid_he_capab(hapd, pos, IEEE80211_MODE_AP);
514*a1157835SDaniel Fojt 		pos = hostapd_eid_he_operation(hapd, pos);
515*a1157835SDaniel Fojt 		pos = hostapd_eid_he_mu_edca_parameter_set(hapd, pos);
516*a1157835SDaniel Fojt 		pos = hostapd_eid_spatial_reuse(hapd, pos);
517*a1157835SDaniel Fojt 	}
518*a1157835SDaniel Fojt #endif /* CONFIG_IEEE80211AX */
519*a1157835SDaniel Fojt 
520*a1157835SDaniel Fojt #ifdef CONFIG_IEEE80211AC
521*a1157835SDaniel Fojt 	if (hapd->conf->vendor_vht)
522*a1157835SDaniel Fojt 		pos = hostapd_eid_vendor_vht(hapd, pos);
523*a1157835SDaniel Fojt #endif /* CONFIG_IEEE80211AC */
524*a1157835SDaniel Fojt 
525*a1157835SDaniel Fojt 	/* WPA */
526*a1157835SDaniel Fojt 	if (hapd->conf->wpa == WPA_PROTO_WPA)
527*a1157835SDaniel Fojt 		pos = hostapd_eid_wpa(hapd, pos, epos - pos);
528*a1157835SDaniel Fojt 
5293ff40c12SJohn Marino 	/* Wi-Fi Alliance WMM */
5303ff40c12SJohn Marino 	pos = hostapd_eid_wmm(hapd, pos);
5313ff40c12SJohn Marino 
5323ff40c12SJohn Marino #ifdef CONFIG_WPS
5333ff40c12SJohn Marino 	if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
5343ff40c12SJohn Marino 		os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
5353ff40c12SJohn Marino 			  wpabuf_len(hapd->wps_probe_resp_ie));
5363ff40c12SJohn Marino 		pos += wpabuf_len(hapd->wps_probe_resp_ie);
5373ff40c12SJohn Marino 	}
5383ff40c12SJohn Marino #endif /* CONFIG_WPS */
5393ff40c12SJohn Marino 
5403ff40c12SJohn Marino #ifdef CONFIG_P2P
5413ff40c12SJohn Marino 	if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
5423ff40c12SJohn Marino 	    hapd->p2p_probe_resp_ie) {
5433ff40c12SJohn Marino 		os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
5443ff40c12SJohn Marino 			  wpabuf_len(hapd->p2p_probe_resp_ie));
5453ff40c12SJohn Marino 		pos += wpabuf_len(hapd->p2p_probe_resp_ie);
5463ff40c12SJohn Marino 	}
5473ff40c12SJohn Marino #endif /* CONFIG_P2P */
5483ff40c12SJohn Marino #ifdef CONFIG_P2P_MANAGER
5493ff40c12SJohn Marino 	if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
5503ff40c12SJohn Marino 	    P2P_MANAGE)
5513ff40c12SJohn Marino 		pos = hostapd_eid_p2p_manage(hapd, pos);
5523ff40c12SJohn Marino #endif /* CONFIG_P2P_MANAGER */
5533ff40c12SJohn Marino 
5543ff40c12SJohn Marino #ifdef CONFIG_HS20
5553ff40c12SJohn Marino 	pos = hostapd_eid_hs20_indication(hapd, pos);
556*a1157835SDaniel Fojt 	pos = hostapd_eid_osen(hapd, pos);
5573ff40c12SJohn Marino #endif /* CONFIG_HS20 */
5583ff40c12SJohn Marino 
559*a1157835SDaniel Fojt 	pos = hostapd_eid_mbo(hapd, pos, (u8 *) resp + buflen - pos);
560*a1157835SDaniel Fojt 	pos = hostapd_eid_owe_trans(hapd, pos, (u8 *) resp + buflen - pos);
561*a1157835SDaniel Fojt 
5623ff40c12SJohn Marino 	if (hapd->conf->vendor_elements) {
5633ff40c12SJohn Marino 		os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
5643ff40c12SJohn Marino 			  wpabuf_len(hapd->conf->vendor_elements));
5653ff40c12SJohn Marino 		pos += wpabuf_len(hapd->conf->vendor_elements);
5663ff40c12SJohn Marino 	}
5673ff40c12SJohn Marino 
5683ff40c12SJohn Marino 	*resp_len = pos - (u8 *) resp;
5693ff40c12SJohn Marino 	return (u8 *) resp;
5703ff40c12SJohn Marino }
5713ff40c12SJohn Marino 
5723ff40c12SJohn Marino 
5733ff40c12SJohn Marino enum ssid_match_result {
5743ff40c12SJohn Marino 	NO_SSID_MATCH,
5753ff40c12SJohn Marino 	EXACT_SSID_MATCH,
5763ff40c12SJohn Marino 	WILDCARD_SSID_MATCH
5773ff40c12SJohn Marino };
5783ff40c12SJohn Marino 
ssid_match(struct hostapd_data * hapd,const u8 * ssid,size_t ssid_len,const u8 * ssid_list,size_t ssid_list_len)5793ff40c12SJohn Marino static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
5803ff40c12SJohn Marino 					 const u8 *ssid, size_t ssid_len,
5813ff40c12SJohn Marino 					 const u8 *ssid_list,
5823ff40c12SJohn Marino 					 size_t ssid_list_len)
5833ff40c12SJohn Marino {
5843ff40c12SJohn Marino 	const u8 *pos, *end;
5853ff40c12SJohn Marino 	int wildcard = 0;
5863ff40c12SJohn Marino 
5873ff40c12SJohn Marino 	if (ssid_len == 0)
5883ff40c12SJohn Marino 		wildcard = 1;
5893ff40c12SJohn Marino 	if (ssid_len == hapd->conf->ssid.ssid_len &&
5903ff40c12SJohn Marino 	    os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
5913ff40c12SJohn Marino 		return EXACT_SSID_MATCH;
5923ff40c12SJohn Marino 
5933ff40c12SJohn Marino 	if (ssid_list == NULL)
5943ff40c12SJohn Marino 		return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
5953ff40c12SJohn Marino 
5963ff40c12SJohn Marino 	pos = ssid_list;
5973ff40c12SJohn Marino 	end = ssid_list + ssid_list_len;
598*a1157835SDaniel Fojt 	while (end - pos >= 2) {
599*a1157835SDaniel Fojt 		if (2 + pos[1] > end - pos)
6003ff40c12SJohn Marino 			break;
6013ff40c12SJohn Marino 		if (pos[1] == 0)
6023ff40c12SJohn Marino 			wildcard = 1;
6033ff40c12SJohn Marino 		if (pos[1] == hapd->conf->ssid.ssid_len &&
6043ff40c12SJohn Marino 		    os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0)
6053ff40c12SJohn Marino 			return EXACT_SSID_MATCH;
6063ff40c12SJohn Marino 		pos += 2 + pos[1];
6073ff40c12SJohn Marino 	}
6083ff40c12SJohn Marino 
6093ff40c12SJohn Marino 	return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
6103ff40c12SJohn Marino }
6113ff40c12SJohn Marino 
6123ff40c12SJohn Marino 
sta_track_expire(struct hostapd_iface * iface,int force)613*a1157835SDaniel Fojt void sta_track_expire(struct hostapd_iface *iface, int force)
614*a1157835SDaniel Fojt {
615*a1157835SDaniel Fojt 	struct os_reltime now;
616*a1157835SDaniel Fojt 	struct hostapd_sta_info *info;
617*a1157835SDaniel Fojt 
618*a1157835SDaniel Fojt 	if (!iface->num_sta_seen)
619*a1157835SDaniel Fojt 		return;
620*a1157835SDaniel Fojt 
621*a1157835SDaniel Fojt 	os_get_reltime(&now);
622*a1157835SDaniel Fojt 	while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
623*a1157835SDaniel Fojt 				     list))) {
624*a1157835SDaniel Fojt 		if (!force &&
625*a1157835SDaniel Fojt 		    !os_reltime_expired(&now, &info->last_seen,
626*a1157835SDaniel Fojt 					iface->conf->track_sta_max_age))
627*a1157835SDaniel Fojt 			break;
628*a1157835SDaniel Fojt 		force = 0;
629*a1157835SDaniel Fojt 
630*a1157835SDaniel Fojt 		wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
631*a1157835SDaniel Fojt 			   MACSTR, iface->bss[0]->conf->iface,
632*a1157835SDaniel Fojt 			   MAC2STR(info->addr));
633*a1157835SDaniel Fojt 		dl_list_del(&info->list);
634*a1157835SDaniel Fojt 		iface->num_sta_seen--;
635*a1157835SDaniel Fojt 		sta_track_del(info);
636*a1157835SDaniel Fojt 	}
637*a1157835SDaniel Fojt }
638*a1157835SDaniel Fojt 
639*a1157835SDaniel Fojt 
sta_track_get(struct hostapd_iface * iface,const u8 * addr)640*a1157835SDaniel Fojt static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
641*a1157835SDaniel Fojt 					       const u8 *addr)
642*a1157835SDaniel Fojt {
643*a1157835SDaniel Fojt 	struct hostapd_sta_info *info;
644*a1157835SDaniel Fojt 
645*a1157835SDaniel Fojt 	dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
646*a1157835SDaniel Fojt 		if (os_memcmp(addr, info->addr, ETH_ALEN) == 0)
647*a1157835SDaniel Fojt 			return info;
648*a1157835SDaniel Fojt 
649*a1157835SDaniel Fojt 	return NULL;
650*a1157835SDaniel Fojt }
651*a1157835SDaniel Fojt 
652*a1157835SDaniel Fojt 
sta_track_add(struct hostapd_iface * iface,const u8 * addr,int ssi_signal)653*a1157835SDaniel Fojt void sta_track_add(struct hostapd_iface *iface, const u8 *addr, int ssi_signal)
654*a1157835SDaniel Fojt {
655*a1157835SDaniel Fojt 	struct hostapd_sta_info *info;
656*a1157835SDaniel Fojt 
657*a1157835SDaniel Fojt 	info = sta_track_get(iface, addr);
658*a1157835SDaniel Fojt 	if (info) {
659*a1157835SDaniel Fojt 		/* Move the most recent entry to the end of the list */
660*a1157835SDaniel Fojt 		dl_list_del(&info->list);
661*a1157835SDaniel Fojt 		dl_list_add_tail(&iface->sta_seen, &info->list);
662*a1157835SDaniel Fojt 		os_get_reltime(&info->last_seen);
663*a1157835SDaniel Fojt 		info->ssi_signal = ssi_signal;
664*a1157835SDaniel Fojt 		return;
665*a1157835SDaniel Fojt 	}
666*a1157835SDaniel Fojt 
667*a1157835SDaniel Fojt 	/* Add a new entry */
668*a1157835SDaniel Fojt 	info = os_zalloc(sizeof(*info));
669*a1157835SDaniel Fojt 	if (info == NULL)
670*a1157835SDaniel Fojt 		return;
671*a1157835SDaniel Fojt 	os_memcpy(info->addr, addr, ETH_ALEN);
672*a1157835SDaniel Fojt 	os_get_reltime(&info->last_seen);
673*a1157835SDaniel Fojt 	info->ssi_signal = ssi_signal;
674*a1157835SDaniel Fojt 
675*a1157835SDaniel Fojt 	if (iface->num_sta_seen >= iface->conf->track_sta_max_num) {
676*a1157835SDaniel Fojt 		/* Expire oldest entry to make room for a new one */
677*a1157835SDaniel Fojt 		sta_track_expire(iface, 1);
678*a1157835SDaniel Fojt 	}
679*a1157835SDaniel Fojt 
680*a1157835SDaniel Fojt 	wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
681*a1157835SDaniel Fojt 		   MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr));
682*a1157835SDaniel Fojt 	dl_list_add_tail(&iface->sta_seen, &info->list);
683*a1157835SDaniel Fojt 	iface->num_sta_seen++;
684*a1157835SDaniel Fojt }
685*a1157835SDaniel Fojt 
686*a1157835SDaniel Fojt 
687*a1157835SDaniel Fojt struct hostapd_data *
sta_track_seen_on(struct hostapd_iface * iface,const u8 * addr,const char * ifname)688*a1157835SDaniel Fojt sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
689*a1157835SDaniel Fojt 		  const char *ifname)
690*a1157835SDaniel Fojt {
691*a1157835SDaniel Fojt 	struct hapd_interfaces *interfaces = iface->interfaces;
692*a1157835SDaniel Fojt 	size_t i, j;
693*a1157835SDaniel Fojt 
694*a1157835SDaniel Fojt 	for (i = 0; i < interfaces->count; i++) {
695*a1157835SDaniel Fojt 		struct hostapd_data *hapd = NULL;
696*a1157835SDaniel Fojt 
697*a1157835SDaniel Fojt 		iface = interfaces->iface[i];
698*a1157835SDaniel Fojt 		for (j = 0; j < iface->num_bss; j++) {
699*a1157835SDaniel Fojt 			hapd = iface->bss[j];
700*a1157835SDaniel Fojt 			if (os_strcmp(ifname, hapd->conf->iface) == 0)
701*a1157835SDaniel Fojt 				break;
702*a1157835SDaniel Fojt 			hapd = NULL;
703*a1157835SDaniel Fojt 		}
704*a1157835SDaniel Fojt 
705*a1157835SDaniel Fojt 		if (hapd && sta_track_get(iface, addr))
706*a1157835SDaniel Fojt 			return hapd;
707*a1157835SDaniel Fojt 	}
708*a1157835SDaniel Fojt 
709*a1157835SDaniel Fojt 	return NULL;
710*a1157835SDaniel Fojt }
711*a1157835SDaniel Fojt 
712*a1157835SDaniel Fojt 
713*a1157835SDaniel Fojt #ifdef CONFIG_TAXONOMY
sta_track_claim_taxonomy_info(struct hostapd_iface * iface,const u8 * addr,struct wpabuf ** probe_ie_taxonomy)714*a1157835SDaniel Fojt void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr,
715*a1157835SDaniel Fojt 				   struct wpabuf **probe_ie_taxonomy)
716*a1157835SDaniel Fojt {
717*a1157835SDaniel Fojt 	struct hostapd_sta_info *info;
718*a1157835SDaniel Fojt 
719*a1157835SDaniel Fojt 	info = sta_track_get(iface, addr);
720*a1157835SDaniel Fojt 	if (!info)
721*a1157835SDaniel Fojt 		return;
722*a1157835SDaniel Fojt 
723*a1157835SDaniel Fojt 	wpabuf_free(*probe_ie_taxonomy);
724*a1157835SDaniel Fojt 	*probe_ie_taxonomy = info->probe_ie_taxonomy;
725*a1157835SDaniel Fojt 	info->probe_ie_taxonomy = NULL;
726*a1157835SDaniel Fojt }
727*a1157835SDaniel Fojt #endif /* CONFIG_TAXONOMY */
728*a1157835SDaniel Fojt 
729*a1157835SDaniel Fojt 
handle_probe_req(struct hostapd_data * hapd,const struct ieee80211_mgmt * mgmt,size_t len,int ssi_signal)7303ff40c12SJohn Marino void handle_probe_req(struct hostapd_data *hapd,
7313ff40c12SJohn Marino 		      const struct ieee80211_mgmt *mgmt, size_t len,
7323ff40c12SJohn Marino 		      int ssi_signal)
7333ff40c12SJohn Marino {
7343ff40c12SJohn Marino 	u8 *resp;
7353ff40c12SJohn Marino 	struct ieee802_11_elems elems;
7363ff40c12SJohn Marino 	const u8 *ie;
7373ff40c12SJohn Marino 	size_t ie_len;
7383ff40c12SJohn Marino 	size_t i, resp_len;
7393ff40c12SJohn Marino 	int noack;
7403ff40c12SJohn Marino 	enum ssid_match_result res;
741*a1157835SDaniel Fojt 	int ret;
742*a1157835SDaniel Fojt 	u16 csa_offs[2];
743*a1157835SDaniel Fojt 	size_t csa_offs_len;
744*a1157835SDaniel Fojt 	u32 session_timeout, acct_interim_interval;
745*a1157835SDaniel Fojt 	struct vlan_description vlan_id;
746*a1157835SDaniel Fojt 	struct hostapd_sta_wpa_psk_short *psk = NULL;
747*a1157835SDaniel Fojt 	char *identity = NULL;
748*a1157835SDaniel Fojt 	char *radius_cui = NULL;
7493ff40c12SJohn Marino 
750*a1157835SDaniel Fojt 	if (len < IEEE80211_HDRLEN)
7513ff40c12SJohn Marino 		return;
752*a1157835SDaniel Fojt 	ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN;
753*a1157835SDaniel Fojt 	if (hapd->iconf->track_sta_max_num)
754*a1157835SDaniel Fojt 		sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
755*a1157835SDaniel Fojt 	ie_len = len - IEEE80211_HDRLEN;
756*a1157835SDaniel Fojt 
757*a1157835SDaniel Fojt 	ret = ieee802_11_allowed_address(hapd, mgmt->sa, (const u8 *) mgmt, len,
758*a1157835SDaniel Fojt 					 &session_timeout,
759*a1157835SDaniel Fojt 					 &acct_interim_interval, &vlan_id,
760*a1157835SDaniel Fojt 					 &psk, &identity, &radius_cui, 1);
761*a1157835SDaniel Fojt 	if (ret == HOSTAPD_ACL_REJECT) {
762*a1157835SDaniel Fojt 		wpa_msg(hapd->msg_ctx, MSG_DEBUG,
763*a1157835SDaniel Fojt 			"Ignore Probe Request frame from " MACSTR
764*a1157835SDaniel Fojt 			" due to ACL reject ", MAC2STR(mgmt->sa));
765*a1157835SDaniel Fojt 		return;
766*a1157835SDaniel Fojt 	}
7673ff40c12SJohn Marino 
7683ff40c12SJohn Marino 	for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
7693ff40c12SJohn Marino 		if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
7703ff40c12SJohn Marino 					    mgmt->sa, mgmt->da, mgmt->bssid,
7713ff40c12SJohn Marino 					    ie, ie_len, ssi_signal) > 0)
7723ff40c12SJohn Marino 			return;
7733ff40c12SJohn Marino 
774*a1157835SDaniel Fojt 	if (!hapd->conf->send_probe_response)
7753ff40c12SJohn Marino 		return;
7763ff40c12SJohn Marino 
7773ff40c12SJohn Marino 	if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
7783ff40c12SJohn Marino 		wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
7793ff40c12SJohn Marino 			   MAC2STR(mgmt->sa));
7803ff40c12SJohn Marino 		return;
7813ff40c12SJohn Marino 	}
7823ff40c12SJohn Marino 
7833ff40c12SJohn Marino 	if ((!elems.ssid || !elems.supp_rates)) {
7843ff40c12SJohn Marino 		wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
7853ff40c12SJohn Marino 			   "without SSID or supported rates element",
7863ff40c12SJohn Marino 			   MAC2STR(mgmt->sa));
7873ff40c12SJohn Marino 		return;
7883ff40c12SJohn Marino 	}
7893ff40c12SJohn Marino 
790*a1157835SDaniel Fojt 	/*
791*a1157835SDaniel Fojt 	 * No need to reply if the Probe Request frame was sent on an adjacent
792*a1157835SDaniel Fojt 	 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
793*a1157835SDaniel Fojt 	 * AP with dot11RadioMeasurementActivated set to true, but strictly
794*a1157835SDaniel Fojt 	 * speaking does not allow such ignoring of Probe Request frames if
795*a1157835SDaniel Fojt 	 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
796*a1157835SDaniel Fojt 	 * number of unnecessary Probe Response frames for cases where the STA
797*a1157835SDaniel Fojt 	 * is less likely to see them (Probe Request frame sent on a
798*a1157835SDaniel Fojt 	 * neighboring, but partially overlapping, channel).
799*a1157835SDaniel Fojt 	 */
800*a1157835SDaniel Fojt 	if (elems.ds_params &&
801*a1157835SDaniel Fojt 	    hapd->iface->current_mode &&
802*a1157835SDaniel Fojt 	    (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
803*a1157835SDaniel Fojt 	     hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
804*a1157835SDaniel Fojt 	    hapd->iconf->channel != elems.ds_params[0]) {
805*a1157835SDaniel Fojt 		wpa_printf(MSG_DEBUG,
806*a1157835SDaniel Fojt 			   "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
807*a1157835SDaniel Fojt 			   hapd->iconf->channel, elems.ds_params[0]);
808*a1157835SDaniel Fojt 		return;
809*a1157835SDaniel Fojt 	}
810*a1157835SDaniel Fojt 
8113ff40c12SJohn Marino #ifdef CONFIG_P2P
812*a1157835SDaniel Fojt 	if (hapd->p2p && hapd->p2p_group && elems.wps_ie) {
8133ff40c12SJohn Marino 		struct wpabuf *wps;
8143ff40c12SJohn Marino 		wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
8153ff40c12SJohn Marino 		if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
8163ff40c12SJohn Marino 			wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
8173ff40c12SJohn Marino 				   "due to mismatch with Requested Device "
8183ff40c12SJohn Marino 				   "Type");
8193ff40c12SJohn Marino 			wpabuf_free(wps);
8203ff40c12SJohn Marino 			return;
8213ff40c12SJohn Marino 		}
8223ff40c12SJohn Marino 		wpabuf_free(wps);
8233ff40c12SJohn Marino 	}
8243ff40c12SJohn Marino 
825*a1157835SDaniel Fojt 	if (hapd->p2p && hapd->p2p_group && elems.p2p) {
8263ff40c12SJohn Marino 		struct wpabuf *p2p;
8273ff40c12SJohn Marino 		p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
8283ff40c12SJohn Marino 		if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
8293ff40c12SJohn Marino 			wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
8303ff40c12SJohn Marino 				   "due to mismatch with Device ID");
8313ff40c12SJohn Marino 			wpabuf_free(p2p);
8323ff40c12SJohn Marino 			return;
8333ff40c12SJohn Marino 		}
8343ff40c12SJohn Marino 		wpabuf_free(p2p);
8353ff40c12SJohn Marino 	}
8363ff40c12SJohn Marino #endif /* CONFIG_P2P */
8373ff40c12SJohn Marino 
8383ff40c12SJohn Marino 	if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
8393ff40c12SJohn Marino 	    elems.ssid_list_len == 0) {
8403ff40c12SJohn Marino 		wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
8413ff40c12SJohn Marino 			   "broadcast SSID ignored", MAC2STR(mgmt->sa));
8423ff40c12SJohn Marino 		return;
8433ff40c12SJohn Marino 	}
8443ff40c12SJohn Marino 
8453ff40c12SJohn Marino #ifdef CONFIG_P2P
8463ff40c12SJohn Marino 	if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
8473ff40c12SJohn Marino 	    elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
8483ff40c12SJohn Marino 	    os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
8493ff40c12SJohn Marino 		      P2P_WILDCARD_SSID_LEN) == 0) {
8503ff40c12SJohn Marino 		/* Process P2P Wildcard SSID like Wildcard SSID */
8513ff40c12SJohn Marino 		elems.ssid_len = 0;
8523ff40c12SJohn Marino 	}
8533ff40c12SJohn Marino #endif /* CONFIG_P2P */
8543ff40c12SJohn Marino 
855*a1157835SDaniel Fojt #ifdef CONFIG_TAXONOMY
856*a1157835SDaniel Fojt 	{
857*a1157835SDaniel Fojt 		struct sta_info *sta;
858*a1157835SDaniel Fojt 		struct hostapd_sta_info *info;
859*a1157835SDaniel Fojt 
860*a1157835SDaniel Fojt 		if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) {
861*a1157835SDaniel Fojt 			taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len);
862*a1157835SDaniel Fojt 		} else if ((info = sta_track_get(hapd->iface,
863*a1157835SDaniel Fojt 						 mgmt->sa)) != NULL) {
864*a1157835SDaniel Fojt 			taxonomy_hostapd_sta_info_probe_req(hapd, info,
865*a1157835SDaniel Fojt 							    ie, ie_len);
866*a1157835SDaniel Fojt 		}
867*a1157835SDaniel Fojt 	}
868*a1157835SDaniel Fojt #endif /* CONFIG_TAXONOMY */
869*a1157835SDaniel Fojt 
8703ff40c12SJohn Marino 	res = ssid_match(hapd, elems.ssid, elems.ssid_len,
8713ff40c12SJohn Marino 			 elems.ssid_list, elems.ssid_list_len);
872*a1157835SDaniel Fojt 	if (res == NO_SSID_MATCH) {
8733ff40c12SJohn Marino 		if (!(mgmt->da[0] & 0x01)) {
8743ff40c12SJohn Marino 			wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
8753ff40c12SJohn Marino 				   " for foreign SSID '%s' (DA " MACSTR ")%s",
876*a1157835SDaniel Fojt 				   MAC2STR(mgmt->sa),
877*a1157835SDaniel Fojt 				   wpa_ssid_txt(elems.ssid, elems.ssid_len),
8783ff40c12SJohn Marino 				   MAC2STR(mgmt->da),
8793ff40c12SJohn Marino 				   elems.ssid_list ? " (SSID list)" : "");
8803ff40c12SJohn Marino 		}
8813ff40c12SJohn Marino 		return;
8823ff40c12SJohn Marino 	}
8833ff40c12SJohn Marino 
8843ff40c12SJohn Marino #ifdef CONFIG_INTERWORKING
885*a1157835SDaniel Fojt 	if (hapd->conf->interworking &&
886*a1157835SDaniel Fojt 	    elems.interworking && elems.interworking_len >= 1) {
8873ff40c12SJohn Marino 		u8 ant = elems.interworking[0] & 0x0f;
8883ff40c12SJohn Marino 		if (ant != INTERWORKING_ANT_WILDCARD &&
8893ff40c12SJohn Marino 		    ant != hapd->conf->access_network_type) {
8903ff40c12SJohn Marino 			wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
8913ff40c12SJohn Marino 				   " for mismatching ANT %u ignored",
8923ff40c12SJohn Marino 				   MAC2STR(mgmt->sa), ant);
8933ff40c12SJohn Marino 			return;
8943ff40c12SJohn Marino 		}
8953ff40c12SJohn Marino 	}
8963ff40c12SJohn Marino 
897*a1157835SDaniel Fojt 	if (hapd->conf->interworking && elems.interworking &&
8983ff40c12SJohn Marino 	    (elems.interworking_len == 7 || elems.interworking_len == 9)) {
8993ff40c12SJohn Marino 		const u8 *hessid;
9003ff40c12SJohn Marino 		if (elems.interworking_len == 7)
9013ff40c12SJohn Marino 			hessid = elems.interworking + 1;
9023ff40c12SJohn Marino 		else
9033ff40c12SJohn Marino 			hessid = elems.interworking + 1 + 2;
9043ff40c12SJohn Marino 		if (!is_broadcast_ether_addr(hessid) &&
9053ff40c12SJohn Marino 		    os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
9063ff40c12SJohn Marino 			wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
9073ff40c12SJohn Marino 				   " for mismatching HESSID " MACSTR
9083ff40c12SJohn Marino 				   " ignored",
9093ff40c12SJohn Marino 				   MAC2STR(mgmt->sa), MAC2STR(hessid));
9103ff40c12SJohn Marino 			return;
9113ff40c12SJohn Marino 		}
9123ff40c12SJohn Marino 	}
9133ff40c12SJohn Marino #endif /* CONFIG_INTERWORKING */
9143ff40c12SJohn Marino 
9153ff40c12SJohn Marino #ifdef CONFIG_P2P
9163ff40c12SJohn Marino 	if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
9173ff40c12SJohn Marino 	    supp_rates_11b_only(&elems)) {
9183ff40c12SJohn Marino 		/* Indicates support for 11b rates only */
9193ff40c12SJohn Marino 		wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
9203ff40c12SJohn Marino 			   MACSTR " with only 802.11b rates",
9213ff40c12SJohn Marino 			   MAC2STR(mgmt->sa));
9223ff40c12SJohn Marino 		return;
9233ff40c12SJohn Marino 	}
9243ff40c12SJohn Marino #endif /* CONFIG_P2P */
9253ff40c12SJohn Marino 
9263ff40c12SJohn Marino 	/* TODO: verify that supp_rates contains at least one matching rate
9273ff40c12SJohn Marino 	 * with AP configuration */
9283ff40c12SJohn Marino 
929*a1157835SDaniel Fojt 	if (hapd->conf->no_probe_resp_if_seen_on &&
930*a1157835SDaniel Fojt 	    is_multicast_ether_addr(mgmt->da) &&
931*a1157835SDaniel Fojt 	    is_multicast_ether_addr(mgmt->bssid) &&
932*a1157835SDaniel Fojt 	    sta_track_seen_on(hapd->iface, mgmt->sa,
933*a1157835SDaniel Fojt 			      hapd->conf->no_probe_resp_if_seen_on)) {
934*a1157835SDaniel Fojt 		wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
935*a1157835SDaniel Fojt 			   " since STA has been seen on %s",
936*a1157835SDaniel Fojt 			   hapd->conf->iface, MAC2STR(mgmt->sa),
937*a1157835SDaniel Fojt 			   hapd->conf->no_probe_resp_if_seen_on);
938*a1157835SDaniel Fojt 		return;
939*a1157835SDaniel Fojt 	}
940*a1157835SDaniel Fojt 
941*a1157835SDaniel Fojt 	if (hapd->conf->no_probe_resp_if_max_sta &&
942*a1157835SDaniel Fojt 	    is_multicast_ether_addr(mgmt->da) &&
943*a1157835SDaniel Fojt 	    is_multicast_ether_addr(mgmt->bssid) &&
944*a1157835SDaniel Fojt 	    hapd->num_sta >= hapd->conf->max_num_sta &&
945*a1157835SDaniel Fojt 	    !ap_get_sta(hapd, mgmt->sa)) {
946*a1157835SDaniel Fojt 		wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
947*a1157835SDaniel Fojt 			   " since no room for additional STA",
948*a1157835SDaniel Fojt 			   hapd->conf->iface, MAC2STR(mgmt->sa));
949*a1157835SDaniel Fojt 		return;
950*a1157835SDaniel Fojt 	}
951*a1157835SDaniel Fojt 
9523ff40c12SJohn Marino #ifdef CONFIG_TESTING_OPTIONS
953*a1157835SDaniel Fojt 	if (hapd->iconf->ignore_probe_probability > 0.0 &&
9543ff40c12SJohn Marino 	    drand48() < hapd->iconf->ignore_probe_probability) {
9553ff40c12SJohn Marino 		wpa_printf(MSG_INFO,
9563ff40c12SJohn Marino 			   "TESTING: ignoring probe request from " MACSTR,
9573ff40c12SJohn Marino 			   MAC2STR(mgmt->sa));
9583ff40c12SJohn Marino 		return;
9593ff40c12SJohn Marino 	}
9603ff40c12SJohn Marino #endif /* CONFIG_TESTING_OPTIONS */
9613ff40c12SJohn Marino 
962*a1157835SDaniel Fojt 	wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, RX_PROBE_REQUEST "sa=" MACSTR
963*a1157835SDaniel Fojt 		     " signal=%d", MAC2STR(mgmt->sa), ssi_signal);
964*a1157835SDaniel Fojt 
965*a1157835SDaniel Fojt 	resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL,
9663ff40c12SJohn Marino 				      &resp_len);
9673ff40c12SJohn Marino 	if (resp == NULL)
9683ff40c12SJohn Marino 		return;
9693ff40c12SJohn Marino 
9703ff40c12SJohn Marino 	/*
9713ff40c12SJohn Marino 	 * If this is a broadcast probe request, apply no ack policy to avoid
9723ff40c12SJohn Marino 	 * excessive retries.
9733ff40c12SJohn Marino 	 */
9743ff40c12SJohn Marino 	noack = !!(res == WILDCARD_SSID_MATCH &&
9753ff40c12SJohn Marino 		   is_broadcast_ether_addr(mgmt->da));
9763ff40c12SJohn Marino 
977*a1157835SDaniel Fojt 	csa_offs_len = 0;
978*a1157835SDaniel Fojt 	if (hapd->csa_in_progress) {
979*a1157835SDaniel Fojt 		if (hapd->cs_c_off_proberesp)
980*a1157835SDaniel Fojt 			csa_offs[csa_offs_len++] =
981*a1157835SDaniel Fojt 				hapd->cs_c_off_proberesp;
982*a1157835SDaniel Fojt 
983*a1157835SDaniel Fojt 		if (hapd->cs_c_off_ecsa_proberesp)
984*a1157835SDaniel Fojt 			csa_offs[csa_offs_len++] =
985*a1157835SDaniel Fojt 				hapd->cs_c_off_ecsa_proberesp;
986*a1157835SDaniel Fojt 	}
987*a1157835SDaniel Fojt 
988*a1157835SDaniel Fojt 	ret = hostapd_drv_send_mlme_csa(hapd, resp, resp_len, noack,
989*a1157835SDaniel Fojt 					csa_offs_len ? csa_offs : NULL,
990*a1157835SDaniel Fojt 					csa_offs_len);
991*a1157835SDaniel Fojt 
992*a1157835SDaniel Fojt 	if (ret < 0)
9933ff40c12SJohn Marino 		wpa_printf(MSG_INFO, "handle_probe_req: send failed");
9943ff40c12SJohn Marino 
9953ff40c12SJohn Marino 	os_free(resp);
9963ff40c12SJohn Marino 
9973ff40c12SJohn Marino 	wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
9983ff40c12SJohn Marino 		   "SSID", MAC2STR(mgmt->sa),
9993ff40c12SJohn Marino 		   elems.ssid_len == 0 ? "broadcast" : "our");
10003ff40c12SJohn Marino }
10013ff40c12SJohn Marino 
10023ff40c12SJohn Marino 
hostapd_probe_resp_offloads(struct hostapd_data * hapd,size_t * resp_len)10033ff40c12SJohn Marino static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
10043ff40c12SJohn Marino 					size_t *resp_len)
10053ff40c12SJohn Marino {
10063ff40c12SJohn Marino 	/* check probe response offloading caps and print warnings */
10073ff40c12SJohn Marino 	if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
10083ff40c12SJohn Marino 		return NULL;
10093ff40c12SJohn Marino 
10103ff40c12SJohn Marino #ifdef CONFIG_WPS
10113ff40c12SJohn Marino 	if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
10123ff40c12SJohn Marino 	    (!(hapd->iface->probe_resp_offloads &
10133ff40c12SJohn Marino 	       (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
10143ff40c12SJohn Marino 		WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
10153ff40c12SJohn Marino 		wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
10163ff40c12SJohn Marino 			   "Probe Response while not supporting this");
10173ff40c12SJohn Marino #endif /* CONFIG_WPS */
10183ff40c12SJohn Marino 
10193ff40c12SJohn Marino #ifdef CONFIG_P2P
10203ff40c12SJohn Marino 	if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
10213ff40c12SJohn Marino 	    !(hapd->iface->probe_resp_offloads &
10223ff40c12SJohn Marino 	      WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
10233ff40c12SJohn Marino 		wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
10243ff40c12SJohn Marino 			   "Probe Response while not supporting this");
10253ff40c12SJohn Marino #endif  /* CONFIG_P2P */
10263ff40c12SJohn Marino 
10273ff40c12SJohn Marino 	if (hapd->conf->interworking &&
10283ff40c12SJohn Marino 	    !(hapd->iface->probe_resp_offloads &
10293ff40c12SJohn Marino 	      WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
10303ff40c12SJohn Marino 		wpa_printf(MSG_WARNING, "Device is trying to offload "
10313ff40c12SJohn Marino 			   "Interworking Probe Response while not supporting "
10323ff40c12SJohn Marino 			   "this");
10333ff40c12SJohn Marino 
10343ff40c12SJohn Marino 	/* Generate a Probe Response template for the non-P2P case */
1035*a1157835SDaniel Fojt 	return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len);
10363ff40c12SJohn Marino }
10373ff40c12SJohn Marino 
10383ff40c12SJohn Marino #endif /* NEED_AP_MLME */
10393ff40c12SJohn Marino 
10403ff40c12SJohn Marino 
sta_track_del(struct hostapd_sta_info * info)1041*a1157835SDaniel Fojt void sta_track_del(struct hostapd_sta_info *info)
1042*a1157835SDaniel Fojt {
1043*a1157835SDaniel Fojt #ifdef CONFIG_TAXONOMY
1044*a1157835SDaniel Fojt 	wpabuf_free(info->probe_ie_taxonomy);
1045*a1157835SDaniel Fojt 	info->probe_ie_taxonomy = NULL;
1046*a1157835SDaniel Fojt #endif /* CONFIG_TAXONOMY */
1047*a1157835SDaniel Fojt 	os_free(info);
1048*a1157835SDaniel Fojt }
1049*a1157835SDaniel Fojt 
1050*a1157835SDaniel Fojt 
ieee802_11_build_ap_params(struct hostapd_data * hapd,struct wpa_driver_ap_params * params)10513ff40c12SJohn Marino int ieee802_11_build_ap_params(struct hostapd_data *hapd,
10523ff40c12SJohn Marino 			       struct wpa_driver_ap_params *params)
10533ff40c12SJohn Marino {
10543ff40c12SJohn Marino 	struct ieee80211_mgmt *head = NULL;
10553ff40c12SJohn Marino 	u8 *tail = NULL;
10563ff40c12SJohn Marino 	size_t head_len = 0, tail_len = 0;
10573ff40c12SJohn Marino 	u8 *resp = NULL;
10583ff40c12SJohn Marino 	size_t resp_len = 0;
10593ff40c12SJohn Marino #ifdef NEED_AP_MLME
10603ff40c12SJohn Marino 	u16 capab_info;
1061*a1157835SDaniel Fojt 	u8 *pos, *tailpos, *csa_pos;
10623ff40c12SJohn Marino 
10633ff40c12SJohn Marino #define BEACON_HEAD_BUF_SIZE 256
10643ff40c12SJohn Marino #define BEACON_TAIL_BUF_SIZE 512
10653ff40c12SJohn Marino 	head = os_zalloc(BEACON_HEAD_BUF_SIZE);
10663ff40c12SJohn Marino 	tail_len = BEACON_TAIL_BUF_SIZE;
10673ff40c12SJohn Marino #ifdef CONFIG_WPS
10683ff40c12SJohn Marino 	if (hapd->conf->wps_state && hapd->wps_beacon_ie)
10693ff40c12SJohn Marino 		tail_len += wpabuf_len(hapd->wps_beacon_ie);
10703ff40c12SJohn Marino #endif /* CONFIG_WPS */
10713ff40c12SJohn Marino #ifdef CONFIG_P2P
10723ff40c12SJohn Marino 	if (hapd->p2p_beacon_ie)
10733ff40c12SJohn Marino 		tail_len += wpabuf_len(hapd->p2p_beacon_ie);
10743ff40c12SJohn Marino #endif /* CONFIG_P2P */
1075*a1157835SDaniel Fojt #ifdef CONFIG_FST
1076*a1157835SDaniel Fojt 	if (hapd->iface->fst_ies)
1077*a1157835SDaniel Fojt 		tail_len += wpabuf_len(hapd->iface->fst_ies);
1078*a1157835SDaniel Fojt #endif /* CONFIG_FST */
10793ff40c12SJohn Marino 	if (hapd->conf->vendor_elements)
10803ff40c12SJohn Marino 		tail_len += wpabuf_len(hapd->conf->vendor_elements);
1081*a1157835SDaniel Fojt 
1082*a1157835SDaniel Fojt #ifdef CONFIG_IEEE80211AC
1083*a1157835SDaniel Fojt 	if (hapd->conf->vendor_vht) {
1084*a1157835SDaniel Fojt 		tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
1085*a1157835SDaniel Fojt 			2 + sizeof(struct ieee80211_vht_operation);
1086*a1157835SDaniel Fojt 	}
1087*a1157835SDaniel Fojt #endif /* CONFIG_IEEE80211AC */
1088*a1157835SDaniel Fojt 
1089*a1157835SDaniel Fojt #ifdef CONFIG_IEEE80211AX
1090*a1157835SDaniel Fojt 	if (hapd->iconf->ieee80211ax) {
1091*a1157835SDaniel Fojt 		tail_len += 3 + sizeof(struct ieee80211_he_capabilities) +
1092*a1157835SDaniel Fojt 			3 + sizeof(struct ieee80211_he_operation) +
1093*a1157835SDaniel Fojt 			3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
1094*a1157835SDaniel Fojt 			3 + sizeof(struct ieee80211_spatial_reuse);
1095*a1157835SDaniel Fojt 	}
1096*a1157835SDaniel Fojt #endif /* CONFIG_IEEE80211AX */
1097*a1157835SDaniel Fojt 
1098*a1157835SDaniel Fojt 	tail_len += hostapd_mbo_ie_len(hapd);
1099*a1157835SDaniel Fojt 	tail_len += hostapd_eid_owe_trans_len(hapd);
1100*a1157835SDaniel Fojt 
11013ff40c12SJohn Marino 	tailpos = tail = os_malloc(tail_len);
11023ff40c12SJohn Marino 	if (head == NULL || tail == NULL) {
11033ff40c12SJohn Marino 		wpa_printf(MSG_ERROR, "Failed to set beacon data");
11043ff40c12SJohn Marino 		os_free(head);
11053ff40c12SJohn Marino 		os_free(tail);
11063ff40c12SJohn Marino 		return -1;
11073ff40c12SJohn Marino 	}
11083ff40c12SJohn Marino 
11093ff40c12SJohn Marino 	head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
11103ff40c12SJohn Marino 					   WLAN_FC_STYPE_BEACON);
11113ff40c12SJohn Marino 	head->duration = host_to_le16(0);
11123ff40c12SJohn Marino 	os_memset(head->da, 0xff, ETH_ALEN);
11133ff40c12SJohn Marino 
11143ff40c12SJohn Marino 	os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
11153ff40c12SJohn Marino 	os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
11163ff40c12SJohn Marino 	head->u.beacon.beacon_int =
11173ff40c12SJohn Marino 		host_to_le16(hapd->iconf->beacon_int);
11183ff40c12SJohn Marino 
11193ff40c12SJohn Marino 	/* hardware or low-level driver will setup seq_ctrl and timestamp */
1120*a1157835SDaniel Fojt 	capab_info = hostapd_own_capab_info(hapd);
11213ff40c12SJohn Marino 	head->u.beacon.capab_info = host_to_le16(capab_info);
11223ff40c12SJohn Marino 	pos = &head->u.beacon.variable[0];
11233ff40c12SJohn Marino 
11243ff40c12SJohn Marino 	/* SSID */
11253ff40c12SJohn Marino 	*pos++ = WLAN_EID_SSID;
11263ff40c12SJohn Marino 	if (hapd->conf->ignore_broadcast_ssid == 2) {
11273ff40c12SJohn Marino 		/* clear the data, but keep the correct length of the SSID */
11283ff40c12SJohn Marino 		*pos++ = hapd->conf->ssid.ssid_len;
11293ff40c12SJohn Marino 		os_memset(pos, 0, hapd->conf->ssid.ssid_len);
11303ff40c12SJohn Marino 		pos += hapd->conf->ssid.ssid_len;
11313ff40c12SJohn Marino 	} else if (hapd->conf->ignore_broadcast_ssid) {
11323ff40c12SJohn Marino 		*pos++ = 0; /* empty SSID */
11333ff40c12SJohn Marino 	} else {
11343ff40c12SJohn Marino 		*pos++ = hapd->conf->ssid.ssid_len;
11353ff40c12SJohn Marino 		os_memcpy(pos, hapd->conf->ssid.ssid,
11363ff40c12SJohn Marino 			  hapd->conf->ssid.ssid_len);
11373ff40c12SJohn Marino 		pos += hapd->conf->ssid.ssid_len;
11383ff40c12SJohn Marino 	}
11393ff40c12SJohn Marino 
11403ff40c12SJohn Marino 	/* Supported rates */
11413ff40c12SJohn Marino 	pos = hostapd_eid_supp_rates(hapd, pos);
11423ff40c12SJohn Marino 
11433ff40c12SJohn Marino 	/* DS Params */
11443ff40c12SJohn Marino 	pos = hostapd_eid_ds_params(hapd, pos);
11453ff40c12SJohn Marino 
11463ff40c12SJohn Marino 	head_len = pos - (u8 *) head;
11473ff40c12SJohn Marino 
11483ff40c12SJohn Marino 	tailpos = hostapd_eid_country(hapd, tailpos,
11493ff40c12SJohn Marino 				      tail + BEACON_TAIL_BUF_SIZE - tailpos);
11503ff40c12SJohn Marino 
1151*a1157835SDaniel Fojt 	/* Power Constraint element */
1152*a1157835SDaniel Fojt 	tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
1153*a1157835SDaniel Fojt 
1154*a1157835SDaniel Fojt 	/* CSA IE */
1155*a1157835SDaniel Fojt 	csa_pos = hostapd_eid_csa(hapd, tailpos);
1156*a1157835SDaniel Fojt 	if (csa_pos != tailpos)
1157*a1157835SDaniel Fojt 		hapd->cs_c_off_beacon = csa_pos - tail - 1;
1158*a1157835SDaniel Fojt 	tailpos = csa_pos;
1159*a1157835SDaniel Fojt 
11603ff40c12SJohn Marino 	/* ERP Information element */
11613ff40c12SJohn Marino 	tailpos = hostapd_eid_erp_info(hapd, tailpos);
11623ff40c12SJohn Marino 
11633ff40c12SJohn Marino 	/* Extended supported rates */
11643ff40c12SJohn Marino 	tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
11653ff40c12SJohn Marino 
1166*a1157835SDaniel Fojt 	/* RSN, MDIE */
1167*a1157835SDaniel Fojt 	if (hapd->conf->wpa != WPA_PROTO_WPA)
1168*a1157835SDaniel Fojt 		tailpos = hostapd_eid_wpa(hapd, tailpos,
1169*a1157835SDaniel Fojt 					  tail + BEACON_TAIL_BUF_SIZE -
1170*a1157835SDaniel Fojt 					  tailpos);
1171*a1157835SDaniel Fojt 
1172*a1157835SDaniel Fojt 	tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
1173*a1157835SDaniel Fojt 					       tail + BEACON_TAIL_BUF_SIZE -
11743ff40c12SJohn Marino 					       tailpos);
11753ff40c12SJohn Marino 
11763ff40c12SJohn Marino 	tailpos = hostapd_eid_bss_load(hapd, tailpos,
11773ff40c12SJohn Marino 				       tail + BEACON_TAIL_BUF_SIZE - tailpos);
11783ff40c12SJohn Marino 
1179*a1157835SDaniel Fojt 	/* eCSA IE */
1180*a1157835SDaniel Fojt 	csa_pos = hostapd_eid_ecsa(hapd, tailpos);
1181*a1157835SDaniel Fojt 	if (csa_pos != tailpos)
1182*a1157835SDaniel Fojt 		hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1;
1183*a1157835SDaniel Fojt 	tailpos = csa_pos;
1184*a1157835SDaniel Fojt 
1185*a1157835SDaniel Fojt 	tailpos = hostapd_eid_supported_op_classes(hapd, tailpos);
1186*a1157835SDaniel Fojt 
11873ff40c12SJohn Marino #ifdef CONFIG_IEEE80211N
1188*a1157835SDaniel Fojt 	/* Secondary Channel Offset element */
1189*a1157835SDaniel Fojt 	/* TODO: The standard doesn't specify a position for this element. */
1190*a1157835SDaniel Fojt 	tailpos = hostapd_eid_secondary_channel(hapd, tailpos);
1191*a1157835SDaniel Fojt 
11923ff40c12SJohn Marino 	tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
11933ff40c12SJohn Marino 	tailpos = hostapd_eid_ht_operation(hapd, tailpos);
11943ff40c12SJohn Marino #endif /* CONFIG_IEEE80211N */
11953ff40c12SJohn Marino 
11963ff40c12SJohn Marino 	tailpos = hostapd_eid_ext_capab(hapd, tailpos);
11973ff40c12SJohn Marino 
11983ff40c12SJohn Marino 	/*
11993ff40c12SJohn Marino 	 * TODO: Time Advertisement element should only be included in some
12003ff40c12SJohn Marino 	 * DTIM Beacon frames.
12013ff40c12SJohn Marino 	 */
12023ff40c12SJohn Marino 	tailpos = hostapd_eid_time_adv(hapd, tailpos);
12033ff40c12SJohn Marino 
12043ff40c12SJohn Marino 	tailpos = hostapd_eid_interworking(hapd, tailpos);
12053ff40c12SJohn Marino 	tailpos = hostapd_eid_adv_proto(hapd, tailpos);
12063ff40c12SJohn Marino 	tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
1207*a1157835SDaniel Fojt 
1208*a1157835SDaniel Fojt #ifdef CONFIG_FST
1209*a1157835SDaniel Fojt 	if (hapd->iface->fst_ies) {
1210*a1157835SDaniel Fojt 		os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies),
1211*a1157835SDaniel Fojt 			  wpabuf_len(hapd->iface->fst_ies));
1212*a1157835SDaniel Fojt 		tailpos += wpabuf_len(hapd->iface->fst_ies);
1213*a1157835SDaniel Fojt 	}
1214*a1157835SDaniel Fojt #endif /* CONFIG_FST */
1215*a1157835SDaniel Fojt 
12163ff40c12SJohn Marino #ifdef CONFIG_IEEE80211AC
1217*a1157835SDaniel Fojt 	if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
1218*a1157835SDaniel Fojt 		tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0);
12193ff40c12SJohn Marino 		tailpos = hostapd_eid_vht_operation(hapd, tailpos);
1220*a1157835SDaniel Fojt 		tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
1221*a1157835SDaniel Fojt 		tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos);
1222*a1157835SDaniel Fojt 	}
12233ff40c12SJohn Marino #endif /* CONFIG_IEEE80211AC */
12243ff40c12SJohn Marino 
1225*a1157835SDaniel Fojt 	tailpos = hostapd_eid_fils_indic(hapd, tailpos, 0);
1226*a1157835SDaniel Fojt 
1227*a1157835SDaniel Fojt #ifdef CONFIG_IEEE80211AX
1228*a1157835SDaniel Fojt 	if (hapd->iconf->ieee80211ax) {
1229*a1157835SDaniel Fojt 		tailpos = hostapd_eid_he_capab(hapd, tailpos,
1230*a1157835SDaniel Fojt 					       IEEE80211_MODE_AP);
1231*a1157835SDaniel Fojt 		tailpos = hostapd_eid_he_operation(hapd, tailpos);
1232*a1157835SDaniel Fojt 		tailpos = hostapd_eid_he_mu_edca_parameter_set(hapd, tailpos);
1233*a1157835SDaniel Fojt 		tailpos = hostapd_eid_spatial_reuse(hapd, tailpos);
1234*a1157835SDaniel Fojt 	}
1235*a1157835SDaniel Fojt #endif /* CONFIG_IEEE80211AX */
1236*a1157835SDaniel Fojt 
1237*a1157835SDaniel Fojt #ifdef CONFIG_IEEE80211AC
1238*a1157835SDaniel Fojt 	if (hapd->conf->vendor_vht)
1239*a1157835SDaniel Fojt 		tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
1240*a1157835SDaniel Fojt #endif /* CONFIG_IEEE80211AC */
1241*a1157835SDaniel Fojt 
1242*a1157835SDaniel Fojt 	/* WPA */
1243*a1157835SDaniel Fojt 	if (hapd->conf->wpa == WPA_PROTO_WPA)
1244*a1157835SDaniel Fojt 		tailpos = hostapd_eid_wpa(hapd, tailpos,
1245*a1157835SDaniel Fojt 					  tail + BEACON_TAIL_BUF_SIZE -
1246*a1157835SDaniel Fojt 					  tailpos);
1247*a1157835SDaniel Fojt 
12483ff40c12SJohn Marino 	/* Wi-Fi Alliance WMM */
12493ff40c12SJohn Marino 	tailpos = hostapd_eid_wmm(hapd, tailpos);
12503ff40c12SJohn Marino 
12513ff40c12SJohn Marino #ifdef CONFIG_WPS
12523ff40c12SJohn Marino 	if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
12533ff40c12SJohn Marino 		os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
12543ff40c12SJohn Marino 			  wpabuf_len(hapd->wps_beacon_ie));
12553ff40c12SJohn Marino 		tailpos += wpabuf_len(hapd->wps_beacon_ie);
12563ff40c12SJohn Marino 	}
12573ff40c12SJohn Marino #endif /* CONFIG_WPS */
12583ff40c12SJohn Marino 
12593ff40c12SJohn Marino #ifdef CONFIG_P2P
12603ff40c12SJohn Marino 	if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
12613ff40c12SJohn Marino 		os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
12623ff40c12SJohn Marino 			  wpabuf_len(hapd->p2p_beacon_ie));
12633ff40c12SJohn Marino 		tailpos += wpabuf_len(hapd->p2p_beacon_ie);
12643ff40c12SJohn Marino 	}
12653ff40c12SJohn Marino #endif /* CONFIG_P2P */
12663ff40c12SJohn Marino #ifdef CONFIG_P2P_MANAGER
12673ff40c12SJohn Marino 	if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
12683ff40c12SJohn Marino 	    P2P_MANAGE)
12693ff40c12SJohn Marino 		tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
12703ff40c12SJohn Marino #endif /* CONFIG_P2P_MANAGER */
12713ff40c12SJohn Marino 
12723ff40c12SJohn Marino #ifdef CONFIG_HS20
12733ff40c12SJohn Marino 	tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
1274*a1157835SDaniel Fojt 	tailpos = hostapd_eid_osen(hapd, tailpos);
12753ff40c12SJohn Marino #endif /* CONFIG_HS20 */
12763ff40c12SJohn Marino 
1277*a1157835SDaniel Fojt 	tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos);
1278*a1157835SDaniel Fojt 	tailpos = hostapd_eid_owe_trans(hapd, tailpos,
1279*a1157835SDaniel Fojt 					tail + tail_len - tailpos);
1280*a1157835SDaniel Fojt 
12813ff40c12SJohn Marino 	if (hapd->conf->vendor_elements) {
12823ff40c12SJohn Marino 		os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
12833ff40c12SJohn Marino 			  wpabuf_len(hapd->conf->vendor_elements));
12843ff40c12SJohn Marino 		tailpos += wpabuf_len(hapd->conf->vendor_elements);
12853ff40c12SJohn Marino 	}
12863ff40c12SJohn Marino 
12873ff40c12SJohn Marino 	tail_len = tailpos > tail ? tailpos - tail : 0;
12883ff40c12SJohn Marino 
12893ff40c12SJohn Marino 	resp = hostapd_probe_resp_offloads(hapd, &resp_len);
12903ff40c12SJohn Marino #endif /* NEED_AP_MLME */
12913ff40c12SJohn Marino 
12923ff40c12SJohn Marino 	os_memset(params, 0, sizeof(*params));
12933ff40c12SJohn Marino 	params->head = (u8 *) head;
12943ff40c12SJohn Marino 	params->head_len = head_len;
12953ff40c12SJohn Marino 	params->tail = tail;
12963ff40c12SJohn Marino 	params->tail_len = tail_len;
12973ff40c12SJohn Marino 	params->proberesp = resp;
12983ff40c12SJohn Marino 	params->proberesp_len = resp_len;
12993ff40c12SJohn Marino 	params->dtim_period = hapd->conf->dtim_period;
13003ff40c12SJohn Marino 	params->beacon_int = hapd->iconf->beacon_int;
13013ff40c12SJohn Marino 	params->basic_rates = hapd->iface->basic_rates;
1302*a1157835SDaniel Fojt 	params->beacon_rate = hapd->iconf->beacon_rate;
1303*a1157835SDaniel Fojt 	params->rate_type = hapd->iconf->rate_type;
13043ff40c12SJohn Marino 	params->ssid = hapd->conf->ssid.ssid;
13053ff40c12SJohn Marino 	params->ssid_len = hapd->conf->ssid.ssid_len;
1306*a1157835SDaniel Fojt 	if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
1307*a1157835SDaniel Fojt 	    (WPA_PROTO_WPA | WPA_PROTO_RSN))
1308*a1157835SDaniel Fojt 		params->pairwise_ciphers = hapd->conf->wpa_pairwise |
1309*a1157835SDaniel Fojt 			hapd->conf->rsn_pairwise;
1310*a1157835SDaniel Fojt 	else if (hapd->conf->wpa & WPA_PROTO_RSN)
1311*a1157835SDaniel Fojt 		params->pairwise_ciphers = hapd->conf->rsn_pairwise;
1312*a1157835SDaniel Fojt 	else if (hapd->conf->wpa & WPA_PROTO_WPA)
1313*a1157835SDaniel Fojt 		params->pairwise_ciphers = hapd->conf->wpa_pairwise;
13143ff40c12SJohn Marino 	params->group_cipher = hapd->conf->wpa_group;
13153ff40c12SJohn Marino 	params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
13163ff40c12SJohn Marino 	params->auth_algs = hapd->conf->auth_algs;
13173ff40c12SJohn Marino 	params->wpa_version = hapd->conf->wpa;
13183ff40c12SJohn Marino 	params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
13193ff40c12SJohn Marino 		(hapd->conf->ieee802_1x &&
13203ff40c12SJohn Marino 		 (hapd->conf->default_wep_key_len ||
13213ff40c12SJohn Marino 		  hapd->conf->individual_wep_key_len));
13223ff40c12SJohn Marino 	switch (hapd->conf->ignore_broadcast_ssid) {
13233ff40c12SJohn Marino 	case 0:
13243ff40c12SJohn Marino 		params->hide_ssid = NO_SSID_HIDING;
13253ff40c12SJohn Marino 		break;
13263ff40c12SJohn Marino 	case 1:
13273ff40c12SJohn Marino 		params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
13283ff40c12SJohn Marino 		break;
13293ff40c12SJohn Marino 	case 2:
13303ff40c12SJohn Marino 		params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
13313ff40c12SJohn Marino 		break;
13323ff40c12SJohn Marino 	}
13333ff40c12SJohn Marino 	params->isolate = hapd->conf->isolate;
1334*a1157835SDaniel Fojt 	params->smps_mode = hapd->iconf->ht_capab & HT_CAP_INFO_SMPS_MASK;
13353ff40c12SJohn Marino #ifdef NEED_AP_MLME
13363ff40c12SJohn Marino 	params->cts_protect = !!(ieee802_11_erp_info(hapd) &
13373ff40c12SJohn Marino 				ERP_INFO_USE_PROTECTION);
13383ff40c12SJohn Marino 	params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
13393ff40c12SJohn Marino 		hapd->iconf->preamble == SHORT_PREAMBLE;
13403ff40c12SJohn Marino 	if (hapd->iface->current_mode &&
13413ff40c12SJohn Marino 	    hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
13423ff40c12SJohn Marino 		params->short_slot_time =
13433ff40c12SJohn Marino 			hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
13443ff40c12SJohn Marino 	else
13453ff40c12SJohn Marino 		params->short_slot_time = -1;
13463ff40c12SJohn Marino 	if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
13473ff40c12SJohn Marino 		params->ht_opmode = -1;
13483ff40c12SJohn Marino 	else
13493ff40c12SJohn Marino 		params->ht_opmode = hapd->iface->ht_op_mode;
13503ff40c12SJohn Marino #endif /* NEED_AP_MLME */
13513ff40c12SJohn Marino 	params->interworking = hapd->conf->interworking;
13523ff40c12SJohn Marino 	if (hapd->conf->interworking &&
13533ff40c12SJohn Marino 	    !is_zero_ether_addr(hapd->conf->hessid))
13543ff40c12SJohn Marino 		params->hessid = hapd->conf->hessid;
13553ff40c12SJohn Marino 	params->access_network_type = hapd->conf->access_network_type;
13563ff40c12SJohn Marino 	params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
1357*a1157835SDaniel Fojt #ifdef CONFIG_P2P
1358*a1157835SDaniel Fojt 	params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
1359*a1157835SDaniel Fojt #endif /* CONFIG_P2P */
13603ff40c12SJohn Marino #ifdef CONFIG_HS20
13613ff40c12SJohn Marino 	params->disable_dgaf = hapd->conf->disable_dgaf;
1362*a1157835SDaniel Fojt 	if (hapd->conf->osen) {
1363*a1157835SDaniel Fojt 		params->privacy = 1;
1364*a1157835SDaniel Fojt 		params->osen = 1;
1365*a1157835SDaniel Fojt 	}
13663ff40c12SJohn Marino #endif /* CONFIG_HS20 */
1367*a1157835SDaniel Fojt 	params->multicast_to_unicast = hapd->conf->multicast_to_unicast;
1368*a1157835SDaniel Fojt 	params->pbss = hapd->conf->pbss;
1369*a1157835SDaniel Fojt 
1370*a1157835SDaniel Fojt 	if (hapd->conf->ftm_responder) {
1371*a1157835SDaniel Fojt 		if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_FTM_RESPONDER) {
1372*a1157835SDaniel Fojt 			params->ftm_responder = 1;
1373*a1157835SDaniel Fojt 			params->lci = hapd->iface->conf->lci;
1374*a1157835SDaniel Fojt 			params->civic = hapd->iface->conf->civic;
1375*a1157835SDaniel Fojt 		} else {
1376*a1157835SDaniel Fojt 			wpa_printf(MSG_WARNING,
1377*a1157835SDaniel Fojt 				   "Not configuring FTM responder as the driver doesn't advertise support for it");
1378*a1157835SDaniel Fojt 		}
1379*a1157835SDaniel Fojt 	}
1380*a1157835SDaniel Fojt 
13813ff40c12SJohn Marino 	return 0;
13823ff40c12SJohn Marino }
13833ff40c12SJohn Marino 
13843ff40c12SJohn Marino 
ieee802_11_free_ap_params(struct wpa_driver_ap_params * params)13853ff40c12SJohn Marino void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
13863ff40c12SJohn Marino {
13873ff40c12SJohn Marino 	os_free(params->tail);
13883ff40c12SJohn Marino 	params->tail = NULL;
13893ff40c12SJohn Marino 	os_free(params->head);
13903ff40c12SJohn Marino 	params->head = NULL;
13913ff40c12SJohn Marino 	os_free(params->proberesp);
13923ff40c12SJohn Marino 	params->proberesp = NULL;
13933ff40c12SJohn Marino }
13943ff40c12SJohn Marino 
13953ff40c12SJohn Marino 
ieee802_11_set_beacon(struct hostapd_data * hapd)13963ff40c12SJohn Marino int ieee802_11_set_beacon(struct hostapd_data *hapd)
13973ff40c12SJohn Marino {
13983ff40c12SJohn Marino 	struct wpa_driver_ap_params params;
1399*a1157835SDaniel Fojt 	struct hostapd_freq_params freq;
1400*a1157835SDaniel Fojt 	struct hostapd_iface *iface = hapd->iface;
1401*a1157835SDaniel Fojt 	struct hostapd_config *iconf = iface->conf;
1402*a1157835SDaniel Fojt 	struct hostapd_hw_modes *cmode = iface->current_mode;
14033ff40c12SJohn Marino 	struct wpabuf *beacon, *proberesp, *assocresp;
14043ff40c12SJohn Marino 	int res, ret = -1;
14053ff40c12SJohn Marino 
1406*a1157835SDaniel Fojt 	if (hapd->csa_in_progress) {
14073ff40c12SJohn Marino 		wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
14083ff40c12SJohn Marino 		return -1;
14093ff40c12SJohn Marino 	}
14103ff40c12SJohn Marino 
14113ff40c12SJohn Marino 	hapd->beacon_set_done = 1;
14123ff40c12SJohn Marino 
14133ff40c12SJohn Marino 	if (ieee802_11_build_ap_params(hapd, &params) < 0)
14143ff40c12SJohn Marino 		return -1;
14153ff40c12SJohn Marino 
14163ff40c12SJohn Marino 	if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
14173ff40c12SJohn Marino 	    0)
14183ff40c12SJohn Marino 		goto fail;
14193ff40c12SJohn Marino 
14203ff40c12SJohn Marino 	params.beacon_ies = beacon;
14213ff40c12SJohn Marino 	params.proberesp_ies = proberesp;
14223ff40c12SJohn Marino 	params.assocresp_ies = assocresp;
1423*a1157835SDaniel Fojt 	params.reenable = hapd->reenable_beacon;
1424*a1157835SDaniel Fojt 	hapd->reenable_beacon = 0;
1425*a1157835SDaniel Fojt 
1426*a1157835SDaniel Fojt 	if (cmode &&
1427*a1157835SDaniel Fojt 	    hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
1428*a1157835SDaniel Fojt 				    iconf->channel, iconf->ieee80211n,
1429*a1157835SDaniel Fojt 				    iconf->ieee80211ac, iconf->ieee80211ax,
1430*a1157835SDaniel Fojt 				    iconf->secondary_channel,
1431*a1157835SDaniel Fojt 				    hostapd_get_oper_chwidth(iconf),
1432*a1157835SDaniel Fojt 				    hostapd_get_oper_centr_freq_seg0_idx(iconf),
1433*a1157835SDaniel Fojt 				    hostapd_get_oper_centr_freq_seg1_idx(iconf),
1434*a1157835SDaniel Fojt 				    cmode->vht_capab,
1435*a1157835SDaniel Fojt 				    &cmode->he_capab[IEEE80211_MODE_AP]) == 0)
1436*a1157835SDaniel Fojt 		params.freq = &freq;
14373ff40c12SJohn Marino 
14383ff40c12SJohn Marino 	res = hostapd_drv_set_ap(hapd, &params);
14393ff40c12SJohn Marino 	hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
14403ff40c12SJohn Marino 	if (res)
14413ff40c12SJohn Marino 		wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
14423ff40c12SJohn Marino 	else
14433ff40c12SJohn Marino 		ret = 0;
14443ff40c12SJohn Marino fail:
14453ff40c12SJohn Marino 	ieee802_11_free_ap_params(&params);
14463ff40c12SJohn Marino 	return ret;
14473ff40c12SJohn Marino }
14483ff40c12SJohn Marino 
14493ff40c12SJohn Marino 
ieee802_11_set_beacons(struct hostapd_iface * iface)14503ff40c12SJohn Marino int ieee802_11_set_beacons(struct hostapd_iface *iface)
14513ff40c12SJohn Marino {
14523ff40c12SJohn Marino 	size_t i;
14533ff40c12SJohn Marino 	int ret = 0;
14543ff40c12SJohn Marino 
14553ff40c12SJohn Marino 	for (i = 0; i < iface->num_bss; i++) {
14563ff40c12SJohn Marino 		if (iface->bss[i]->started &&
14573ff40c12SJohn Marino 		    ieee802_11_set_beacon(iface->bss[i]) < 0)
14583ff40c12SJohn Marino 			ret = -1;
14593ff40c12SJohn Marino 	}
14603ff40c12SJohn Marino 
14613ff40c12SJohn Marino 	return ret;
14623ff40c12SJohn Marino }
14633ff40c12SJohn Marino 
14643ff40c12SJohn Marino 
14653ff40c12SJohn Marino /* only update beacons if started */
ieee802_11_update_beacons(struct hostapd_iface * iface)14663ff40c12SJohn Marino int ieee802_11_update_beacons(struct hostapd_iface *iface)
14673ff40c12SJohn Marino {
14683ff40c12SJohn Marino 	size_t i;
14693ff40c12SJohn Marino 	int ret = 0;
14703ff40c12SJohn Marino 
14713ff40c12SJohn Marino 	for (i = 0; i < iface->num_bss; i++) {
14723ff40c12SJohn Marino 		if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
14733ff40c12SJohn Marino 		    ieee802_11_set_beacon(iface->bss[i]) < 0)
14743ff40c12SJohn Marino 			ret = -1;
14753ff40c12SJohn Marino 	}
14763ff40c12SJohn Marino 
14773ff40c12SJohn Marino 	return ret;
14783ff40c12SJohn Marino }
14793ff40c12SJohn Marino 
14803ff40c12SJohn Marino #endif /* CONFIG_NATIVE_WINDOWS */
1481