blob: 8cd1c417043e7aa181ba87a4bb470680b2db44c9 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / IEEE 802.11 Management: Beacon and Probe Request/Response
3 * Copyright (c) 2002-2004, Instant802 Networks, Inc.
4 * Copyright (c) 2005-2006, Devicescape Software, Inc.
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005 * Copyright (c) 2008-2012, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006 *
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007 * This software may be distributed under the terms of the BSD license.
8 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009 */
10
11#include "utils/includes.h"
12
13#ifndef CONFIG_NATIVE_WINDOWS
14
15#include "utils/common.h"
16#include "common/ieee802_11_defs.h"
17#include "common/ieee802_11_common.h"
Dmitry Shmidt7f656022015-02-25 14:36:37 -080018#include "common/hw_features_common.h"
Roshan Pius3a1667e2018-07-03 15:17:14 -070019#include "common/wpa_ctrl.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070020#include "wps/wps_defs.h"
21#include "p2p/p2p.h"
22#include "hostapd.h"
23#include "ieee802_11.h"
24#include "wpa_auth.h"
25#include "wmm.h"
26#include "ap_config.h"
27#include "sta_info.h"
28#include "p2p_hostapd.h"
29#include "ap_drv_ops.h"
30#include "beacon.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070031#include "hs20.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080032#include "dfs.h"
Dmitry Shmidtaca489e2016-09-28 15:44:14 -070033#include "taxonomy.h"
Roshan Pius3a1667e2018-07-03 15:17:14 -070034#include "ieee802_11_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070035
36
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080037#ifdef NEED_AP_MLME
38
Dmitry Shmidt051af732013-10-22 13:52:46 -070039static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
40{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080041 if (len < 2 + 5)
42 return eid;
43
Dmitry Shmidt051af732013-10-22 13:52:46 -070044#ifdef CONFIG_TESTING_OPTIONS
45 if (hapd->conf->bss_load_test_set) {
Dmitry Shmidt051af732013-10-22 13:52:46 -070046 *eid++ = WLAN_EID_BSS_LOAD;
47 *eid++ = 5;
48 os_memcpy(eid, hapd->conf->bss_load_test, 5);
49 eid += 5;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080050 return eid;
Dmitry Shmidt051af732013-10-22 13:52:46 -070051 }
52#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080053 if (hapd->conf->bss_load_update_period) {
54 *eid++ = WLAN_EID_BSS_LOAD;
55 *eid++ = 5;
56 WPA_PUT_LE16(eid, hapd->num_sta);
57 eid += 2;
58 *eid++ = hapd->iface->channel_utilization;
59 WPA_PUT_LE16(eid, 0); /* no available admission capabity */
60 eid += 2;
61 }
Dmitry Shmidt051af732013-10-22 13:52:46 -070062 return eid;
63}
64
65
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070066static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
67{
68 u8 erp = 0;
69
70 if (hapd->iface->current_mode == NULL ||
71 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
72 return 0;
73
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080074 if (hapd->iface->olbc)
75 erp |= ERP_INFO_USE_PROTECTION;
76 if (hapd->iface->num_sta_non_erp > 0) {
77 erp |= ERP_INFO_NON_ERP_PRESENT |
78 ERP_INFO_USE_PROTECTION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070079 }
80 if (hapd->iface->num_sta_no_short_preamble > 0 ||
81 hapd->iconf->preamble == LONG_PREAMBLE)
82 erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
83
84 return erp;
85}
86
87
88static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
89{
90 *eid++ = WLAN_EID_DS_PARAMS;
91 *eid++ = 1;
92 *eid++ = hapd->iconf->channel;
93 return eid;
94}
95
96
97static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
98{
99 if (hapd->iface->current_mode == NULL ||
100 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
101 return eid;
102
103 /* Set NonERP_present and use_protection bits if there
104 * are any associated NonERP stations. */
105 /* TODO: use_protection bit can be set to zero even if
106 * there are NonERP stations present. This optimization
107 * might be useful if NonERP stations are "quiet".
108 * See 802.11g/D6 E-1 for recommended practice.
109 * In addition, Non ERP present might be set, if AP detects Non ERP
110 * operation on other APs. */
111
112 /* Add ERP Information element */
113 *eid++ = WLAN_EID_ERP_INFO;
114 *eid++ = 1;
115 *eid++ = ieee802_11_erp_info(hapd);
116
117 return eid;
118}
119
120
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800121static u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid)
122{
123 u8 *pos = eid;
124 u8 local_pwr_constraint = 0;
125 int dfs;
126
127 if (hapd->iface->current_mode == NULL ||
128 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
129 return eid;
130
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700131 /* Let host drivers add this IE if DFS support is offloaded */
132 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)
133 return eid;
134
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800135 /*
136 * There is no DFS support and power constraint was not directly
137 * requested by config option.
138 */
139 if (!hapd->iconf->ieee80211h &&
140 hapd->iconf->local_pwr_constraint == -1)
141 return eid;
142
143 /* Check if DFS is required by regulatory. */
144 dfs = hostapd_is_dfs_required(hapd->iface);
145 if (dfs < 0) {
146 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
147 dfs);
148 dfs = 0;
149 }
150
151 if (dfs == 0 && hapd->iconf->local_pwr_constraint == -1)
152 return eid;
153
154 /*
155 * ieee80211h (DFS) is enabled so Power Constraint element shall
156 * be added when running on DFS channel whenever local_pwr_constraint
157 * is configured or not. In order to meet regulations when TPC is not
158 * implemented using a transmit power that is below the legal maximum
159 * (including any mitigation factor) should help. In this case,
160 * indicate 3 dB below maximum allowed transmit power.
161 */
162 if (hapd->iconf->local_pwr_constraint == -1)
163 local_pwr_constraint = 3;
164
165 /*
166 * A STA that is not an AP shall use a transmit power less than or
167 * equal to the local maximum transmit power level for the channel.
168 * The local maximum transmit power can be calculated from the formula:
169 * local max TX pwr = max TX pwr - local pwr constraint
170 * Where max TX pwr is maximum transmit power level specified for
171 * channel in Country element and local pwr constraint is specified
172 * for channel in this Power Constraint element.
173 */
174
175 /* Element ID */
176 *pos++ = WLAN_EID_PWR_CONSTRAINT;
177 /* Length */
178 *pos++ = 1;
179 /* Local Power Constraint */
180 if (local_pwr_constraint)
181 *pos++ = local_pwr_constraint;
182 else
183 *pos++ = hapd->iconf->local_pwr_constraint;
184
185 return pos;
186}
187
188
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700189static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
190 struct hostapd_channel_data *start,
191 struct hostapd_channel_data *prev)
192{
193 if (end - pos < 3)
194 return pos;
195
196 /* first channel number */
197 *pos++ = start->chan;
198 /* number of channels */
199 *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
200 /* maximum transmit power level */
201 *pos++ = start->max_tx_power;
202
203 return pos;
204}
205
206
207static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
208 int max_len)
209{
210 u8 *pos = eid;
211 u8 *end = eid + max_len;
212 int i;
213 struct hostapd_hw_modes *mode;
214 struct hostapd_channel_data *start, *prev;
215 int chan_spacing = 1;
216
217 if (!hapd->iconf->ieee80211d || max_len < 6 ||
218 hapd->iface->current_mode == NULL)
219 return eid;
220
221 *pos++ = WLAN_EID_COUNTRY;
222 pos++; /* length will be set later */
223 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
224 pos += 3;
225
226 mode = hapd->iface->current_mode;
227 if (mode->mode == HOSTAPD_MODE_IEEE80211A)
228 chan_spacing = 4;
229
230 start = prev = NULL;
231 for (i = 0; i < mode->num_channels; i++) {
232 struct hostapd_channel_data *chan = &mode->channels[i];
233 if (chan->flag & HOSTAPD_CHAN_DISABLED)
234 continue;
235 if (start && prev &&
236 prev->chan + chan_spacing == chan->chan &&
237 start->max_tx_power == chan->max_tx_power) {
238 prev = chan;
239 continue; /* can use same entry */
240 }
241
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -0700242 if (start && prev) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700243 pos = hostapd_eid_country_add(pos, end, chan_spacing,
244 start, prev);
245 start = NULL;
246 }
247
248 /* Start new group */
249 start = prev = chan;
250 }
251
252 if (start) {
253 pos = hostapd_eid_country_add(pos, end, chan_spacing,
254 start, prev);
255 }
256
257 if ((pos - eid) & 1) {
258 if (end - pos < 1)
259 return eid;
260 *pos++ = 0; /* pad for 16-bit alignment */
261 }
262
263 eid[1] = (pos - eid) - 2;
264
265 return pos;
266}
267
268
Hai Shalom60840252021-02-19 19:02:11 -0800269const u8 * hostapd_wpa_ie(struct hostapd_data *hapd, u8 eid)
Hai Shalomfdcde762020-04-02 11:19:20 -0700270{
271 const u8 *ies;
272 size_t ies_len;
273
274 ies = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ies_len);
275 if (!ies)
276 return NULL;
277
278 return get_ie(ies, ies_len, eid);
279}
280
281
282static const u8 * hostapd_vendor_wpa_ie(struct hostapd_data *hapd,
283 u32 vendor_type)
284{
285 const u8 *ies;
286 size_t ies_len;
287
288 ies = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ies_len);
289 if (!ies)
290 return NULL;
291
292 return get_vendor_ie(ies, ies_len, vendor_type);
293}
294
295
296static u8 * hostapd_get_rsne(struct hostapd_data *hapd, u8 *pos, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700297{
298 const u8 *ie;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700299
Hai Shalomfdcde762020-04-02 11:19:20 -0700300 ie = hostapd_wpa_ie(hapd, WLAN_EID_RSN);
301 if (!ie || 2U + ie[1] > len)
302 return pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700303
Hai Shalomfdcde762020-04-02 11:19:20 -0700304 os_memcpy(pos, ie, 2 + ie[1]);
305 return pos + 2 + ie[1];
306}
307
308
309static u8 * hostapd_get_mde(struct hostapd_data *hapd, u8 *pos, size_t len)
310{
311 const u8 *ie;
312
313 ie = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN);
314 if (!ie || 2U + ie[1] > len)
315 return pos;
316
317 os_memcpy(pos, ie, 2 + ie[1]);
318 return pos + 2 + ie[1];
319}
320
321
322static u8 * hostapd_get_rsnxe(struct hostapd_data *hapd, u8 *pos, size_t len)
323{
324 const u8 *ie;
325
326#ifdef CONFIG_TESTING_OPTIONS
327 if (hapd->conf->no_beacon_rsnxe) {
328 wpa_printf(MSG_INFO, "TESTING: Do not add RSNXE into Beacon");
329 return pos;
330 }
331#endif /* CONFIG_TESTING_OPTIONS */
332 ie = hostapd_wpa_ie(hapd, WLAN_EID_RSNX);
333 if (!ie || 2U + ie[1] > len)
334 return pos;
335
336 os_memcpy(pos, ie, 2 + ie[1]);
337 return pos + 2 + ie[1];
338}
339
340
341static u8 * hostapd_get_wpa_ie(struct hostapd_data *hapd, u8 *pos, size_t len)
342{
343 const u8 *ie;
344
345 ie = hostapd_vendor_wpa_ie(hapd, WPA_IE_VENDOR_TYPE);
346 if (!ie || 2U + ie[1] > len)
347 return pos;
348
349 os_memcpy(pos, ie, 2 + ie[1]);
350 return pos + 2 + ie[1];
351}
352
353
354static u8 * hostapd_get_osen_ie(struct hostapd_data *hapd, u8 *pos, size_t len)
355{
356 const u8 *ie;
357
358 ie = hostapd_vendor_wpa_ie(hapd, OSEN_IE_VENDOR_TYPE);
359 if (!ie || 2U + ie[1] > len)
360 return pos;
361
362 os_memcpy(pos, ie, 2 + ie[1]);
363 return pos + 2 + ie[1];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700364}
365
366
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800367static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
368{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800369#ifdef CONFIG_TESTING_OPTIONS
370 if (hapd->iface->cs_oper_class && hapd->iconf->ecsa_ie_only)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800371 return eid;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800372#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800373
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800374 if (!hapd->cs_freq_params.channel)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800375 return eid;
376
377 *eid++ = WLAN_EID_CHANNEL_SWITCH;
378 *eid++ = 3;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700379 *eid++ = hapd->cs_block_tx;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800380 *eid++ = hapd->cs_freq_params.channel;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700381 *eid++ = hapd->cs_count;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800382
383 return eid;
384}
385
386
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800387static u8 * hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800388{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800389 if (!hapd->cs_freq_params.channel || !hapd->iface->cs_oper_class)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800390 return eid;
391
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800392 *eid++ = WLAN_EID_EXT_CHANSWITCH_ANN;
393 *eid++ = 4;
394 *eid++ = hapd->cs_block_tx;
395 *eid++ = hapd->iface->cs_oper_class;
396 *eid++ = hapd->cs_freq_params.channel;
397 *eid++ = hapd->cs_count;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800398
399 return eid;
400}
401
402
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800403static u8 * hostapd_eid_supported_op_classes(struct hostapd_data *hapd, u8 *eid)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800404{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800405 u8 op_class, channel;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800406
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800407 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) ||
408 !hapd->iface->freq)
409 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800410
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800411 if (ieee80211_freq_to_channel_ext(hapd->iface->freq,
412 hapd->iconf->secondary_channel,
Hai Shalom81f62d82019-07-22 12:10:00 -0700413 hostapd_get_oper_chwidth(hapd->iconf),
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800414 &op_class, &channel) ==
415 NUM_HOSTAPD_MODES)
416 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800417
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800418 *eid++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES;
419 *eid++ = 2;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800420
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800421 /* Current Operating Class */
422 *eid++ = op_class;
423
424 /* TODO: Advertise all the supported operating classes */
425 *eid++ = 0;
426
427 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800428}
429
430
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800431static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800432 const struct ieee80211_mgmt *req,
433 int is_p2p, size_t *resp_len)
434{
435 struct ieee80211_mgmt *resp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800436 u8 *pos, *epos, *csa_pos;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800437 size_t buflen;
438
439#define MAX_PROBERESP_LEN 768
440 buflen = MAX_PROBERESP_LEN;
441#ifdef CONFIG_WPS
442 if (hapd->wps_probe_resp_ie)
443 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
444#endif /* CONFIG_WPS */
445#ifdef CONFIG_P2P
446 if (hapd->p2p_probe_resp_ie)
447 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
448#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800449#ifdef CONFIG_FST
450 if (hapd->iface->fst_ies)
451 buflen += wpabuf_len(hapd->iface->fst_ies);
452#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700453 if (hapd->conf->vendor_elements)
454 buflen += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800455 if (hapd->conf->vendor_vht) {
456 buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
457 2 + sizeof(struct ieee80211_vht_operation);
458 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800459
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800460#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -0800461 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700462 buflen += 3 + sizeof(struct ieee80211_he_capabilities) +
Hai Shalom74f70d42019-02-11 14:42:39 -0800463 3 + sizeof(struct ieee80211_he_operation) +
Hai Shalom81f62d82019-07-22 12:10:00 -0700464 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
465 3 + sizeof(struct ieee80211_spatial_reuse);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700466 if (is_6ghz_op_class(hapd->iconf->op_class))
467 buflen += sizeof(struct ieee80211_he_6ghz_oper_info) +
468 3 + sizeof(struct ieee80211_he_6ghz_band_cap);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800469 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700470#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800471
Hai Shaloma20dcd72022-02-04 13:43:00 -0800472 buflen += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_PROBE_RESP);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800473 buflen += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700474 buflen += hostapd_eid_owe_trans_len(hapd);
Hai Shalomfdcde762020-04-02 11:19:20 -0700475 buflen += hostapd_eid_dpp_cc_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800476
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800477 resp = os_zalloc(buflen);
478 if (resp == NULL)
479 return NULL;
480
481 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
482
483 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
484 WLAN_FC_STYPE_PROBE_RESP);
485 if (req)
486 os_memcpy(resp->da, req->sa, ETH_ALEN);
487 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
488
489 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
490 resp->u.probe_resp.beacon_int =
491 host_to_le16(hapd->iconf->beacon_int);
492
493 /* hardware or low-level driver will setup seq_ctrl and timestamp */
494 resp->u.probe_resp.capab_info =
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700495 host_to_le16(hostapd_own_capab_info(hapd));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800496
497 pos = resp->u.probe_resp.variable;
498 *pos++ = WLAN_EID_SSID;
499 *pos++ = hapd->conf->ssid.ssid_len;
500 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
501 pos += hapd->conf->ssid.ssid_len;
502
503 /* Supported rates */
504 pos = hostapd_eid_supp_rates(hapd, pos);
505
506 /* DS Params */
507 pos = hostapd_eid_ds_params(hapd, pos);
508
509 pos = hostapd_eid_country(hapd, pos, epos - pos);
510
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800511 /* Power Constraint element */
512 pos = hostapd_eid_pwr_constraint(hapd, pos);
513
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800514 /* CSA IE */
515 csa_pos = hostapd_eid_csa(hapd, pos);
516 if (csa_pos != pos)
517 hapd->cs_c_off_proberesp = csa_pos - (u8 *) resp - 1;
518 pos = csa_pos;
519
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800520 /* ERP Information element */
521 pos = hostapd_eid_erp_info(hapd, pos);
522
523 /* Extended supported rates */
524 pos = hostapd_eid_ext_supp_rates(hapd, pos);
525
Hai Shalomfdcde762020-04-02 11:19:20 -0700526 pos = hostapd_get_rsne(hapd, pos, epos - pos);
Dmitry Shmidt051af732013-10-22 13:52:46 -0700527 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800528 pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700529 pos = hostapd_get_mde(hapd, pos, epos - pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800530
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800531 /* eCSA IE */
532 csa_pos = hostapd_eid_ecsa(hapd, pos);
533 if (csa_pos != pos)
534 hapd->cs_c_off_ecsa_proberesp = csa_pos - (u8 *) resp - 1;
535 pos = csa_pos;
536
537 pos = hostapd_eid_supported_op_classes(hapd, pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800538 pos = hostapd_eid_ht_capabilities(hapd, pos);
539 pos = hostapd_eid_ht_operation(hapd, pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800540
541 pos = hostapd_eid_ext_capab(hapd, pos);
542
543 pos = hostapd_eid_time_adv(hapd, pos);
544 pos = hostapd_eid_time_zone(hapd, pos);
545
546 pos = hostapd_eid_interworking(hapd, pos);
547 pos = hostapd_eid_adv_proto(hapd, pos);
548 pos = hostapd_eid_roaming_consortium(hapd, pos);
549
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800550#ifdef CONFIG_FST
551 if (hapd->iface->fst_ies) {
552 os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies),
553 wpabuf_len(hapd->iface->fst_ies));
554 pos += wpabuf_len(hapd->iface->fst_ies);
555 }
556#endif /* CONFIG_FST */
557
Dmitry Shmidt04949592012-07-19 12:16:46 -0700558#ifdef CONFIG_IEEE80211AC
Hai Shalomc3565922019-10-28 11:58:20 -0700559 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
560 !is_6ghz_op_class(hapd->iconf->op_class)) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700561 pos = hostapd_eid_vht_capabilities(hapd, pos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800562 pos = hostapd_eid_vht_operation(hapd, pos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800563 pos = hostapd_eid_txpower_envelope(hapd, pos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800564 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800565#endif /* CONFIG_IEEE80211AC */
566
Hai Shalom60840252021-02-19 19:02:11 -0800567#ifdef CONFIG_IEEE80211AX
568 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax &&
569 is_6ghz_op_class(hapd->iconf->op_class))
570 pos = hostapd_eid_txpower_envelope(hapd, pos);
571#endif /* CONFIG_IEEE80211AX */
572
Hai Shaloma20dcd72022-02-04 13:43:00 -0800573 pos = hostapd_eid_wb_chsw_wrapper(hapd, pos);
Hai Shalom899fcc72020-10-19 14:38:18 -0700574
Hai Shaloma20dcd72022-02-04 13:43:00 -0800575 pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_PROBE_RESP);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800576 pos = hostapd_eid_fils_indic(hapd, pos, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -0700577 pos = hostapd_get_rsnxe(hapd, pos, epos - pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800578
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700579#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -0800580 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Hai Shalom81f62d82019-07-22 12:10:00 -0700581 pos = hostapd_eid_he_capab(hapd, pos, IEEE80211_MODE_AP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700582 pos = hostapd_eid_he_operation(hapd, pos);
Hai Shalom81f62d82019-07-22 12:10:00 -0700583 pos = hostapd_eid_spatial_reuse(hapd, pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700584 pos = hostapd_eid_he_mu_edca_parameter_set(hapd, pos);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700585 pos = hostapd_eid_he_6ghz_band_cap(hapd, pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700586 }
587#endif /* CONFIG_IEEE80211AX */
588
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800589#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800590 if (hapd->conf->vendor_vht)
591 pos = hostapd_eid_vendor_vht(hapd, pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700592#endif /* CONFIG_IEEE80211AC */
593
Hai Shalomfdcde762020-04-02 11:19:20 -0700594 /* WPA / OSEN */
595 pos = hostapd_get_wpa_ie(hapd, pos, epos - pos);
596 pos = hostapd_get_osen_ie(hapd, pos, epos - pos);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800597
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800598 /* Wi-Fi Alliance WMM */
599 pos = hostapd_eid_wmm(hapd, pos);
600
601#ifdef CONFIG_WPS
602 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
603 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
604 wpabuf_len(hapd->wps_probe_resp_ie));
605 pos += wpabuf_len(hapd->wps_probe_resp_ie);
606 }
607#endif /* CONFIG_WPS */
608
609#ifdef CONFIG_P2P
610 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
611 hapd->p2p_probe_resp_ie) {
612 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
613 wpabuf_len(hapd->p2p_probe_resp_ie));
614 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
615 }
616#endif /* CONFIG_P2P */
617#ifdef CONFIG_P2P_MANAGER
618 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
619 P2P_MANAGE)
620 pos = hostapd_eid_p2p_manage(hapd, pos);
621#endif /* CONFIG_P2P_MANAGER */
622
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700623#ifdef CONFIG_HS20
624 pos = hostapd_eid_hs20_indication(hapd, pos);
625#endif /* CONFIG_HS20 */
626
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800627 pos = hostapd_eid_mbo(hapd, pos, (u8 *) resp + buflen - pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700628 pos = hostapd_eid_owe_trans(hapd, pos, (u8 *) resp + buflen - pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700629 pos = hostapd_eid_dpp_cc(hapd, pos, (u8 *) resp + buflen - pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800630
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700631 if (hapd->conf->vendor_elements) {
632 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
633 wpabuf_len(hapd->conf->vendor_elements));
634 pos += wpabuf_len(hapd->conf->vendor_elements);
635 }
636
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800637 *resp_len = pos - (u8 *) resp;
638 return (u8 *) resp;
639}
640
641
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800642enum ssid_match_result {
643 NO_SSID_MATCH,
644 EXACT_SSID_MATCH,
Hai Shaloma20dcd72022-02-04 13:43:00 -0800645 WILDCARD_SSID_MATCH,
646 CO_LOCATED_SSID_MATCH,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800647};
648
649static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
650 const u8 *ssid, size_t ssid_len,
651 const u8 *ssid_list,
Hai Shalomfdcde762020-04-02 11:19:20 -0700652 size_t ssid_list_len,
653 const u8 *short_ssid_list,
654 size_t short_ssid_list_len)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800655{
656 const u8 *pos, *end;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800657 struct hostapd_iface *iface = hapd->iface;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800658 int wildcard = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800659 size_t i, j;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800660
661 if (ssid_len == 0)
662 wildcard = 1;
663 if (ssid_len == hapd->conf->ssid.ssid_len &&
664 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
665 return EXACT_SSID_MATCH;
666
Hai Shalomfdcde762020-04-02 11:19:20 -0700667 if (ssid_list) {
668 pos = ssid_list;
669 end = ssid_list + ssid_list_len;
670 while (end - pos >= 2) {
671 if (2 + pos[1] > end - pos)
672 break;
673 if (pos[1] == 0)
674 wildcard = 1;
675 if (pos[1] == hapd->conf->ssid.ssid_len &&
676 os_memcmp(pos + 2, hapd->conf->ssid.ssid,
677 pos[1]) == 0)
678 return EXACT_SSID_MATCH;
679 pos += 2 + pos[1];
680 }
681 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800682
Hai Shalomfdcde762020-04-02 11:19:20 -0700683 if (short_ssid_list) {
684 pos = short_ssid_list;
685 end = short_ssid_list + short_ssid_list_len;
686 while (end - pos >= 4) {
687 if (hapd->conf->ssid.short_ssid == WPA_GET_LE32(pos))
688 return EXACT_SSID_MATCH;
689 pos += 4;
690 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800691 }
692
Hai Shaloma20dcd72022-02-04 13:43:00 -0800693 if (wildcard)
694 return WILDCARD_SSID_MATCH;
695
696 if (!iface->interfaces || iface->interfaces->count <= 1 ||
697 is_6ghz_op_class(hapd->iconf->op_class))
698 return NO_SSID_MATCH;
699
700 for (i = 0; i < iface->interfaces->count; i++) {
701 struct hostapd_iface *colocated;
702
703 colocated = iface->interfaces->iface[i];
704
705 if (colocated == iface ||
706 !is_6ghz_op_class(colocated->conf->op_class))
707 continue;
708
709 for (j = 0; j < colocated->num_bss; j++) {
710 struct hostapd_bss_config *conf;
711
712 conf = colocated->bss[j]->conf;
713 if (ssid_len == conf->ssid.ssid_len &&
714 os_memcmp(ssid, conf->ssid.ssid, ssid_len) == 0)
715 return CO_LOCATED_SSID_MATCH;
716 }
717 }
718
719 return NO_SSID_MATCH;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800720}
721
722
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800723void sta_track_expire(struct hostapd_iface *iface, int force)
724{
725 struct os_reltime now;
726 struct hostapd_sta_info *info;
727
728 if (!iface->num_sta_seen)
729 return;
730
731 os_get_reltime(&now);
732 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
733 list))) {
734 if (!force &&
735 !os_reltime_expired(&now, &info->last_seen,
736 iface->conf->track_sta_max_age))
737 break;
738 force = 0;
739
740 wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
741 MACSTR, iface->bss[0]->conf->iface,
742 MAC2STR(info->addr));
743 dl_list_del(&info->list);
744 iface->num_sta_seen--;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700745 sta_track_del(info);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800746 }
747}
748
749
750static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
751 const u8 *addr)
752{
753 struct hostapd_sta_info *info;
754
755 dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
756 if (os_memcmp(addr, info->addr, ETH_ALEN) == 0)
757 return info;
758
759 return NULL;
760}
761
762
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800763void sta_track_add(struct hostapd_iface *iface, const u8 *addr, int ssi_signal)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800764{
765 struct hostapd_sta_info *info;
766
767 info = sta_track_get(iface, addr);
768 if (info) {
769 /* Move the most recent entry to the end of the list */
770 dl_list_del(&info->list);
771 dl_list_add_tail(&iface->sta_seen, &info->list);
772 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800773 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800774 return;
775 }
776
777 /* Add a new entry */
778 info = os_zalloc(sizeof(*info));
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700779 if (info == NULL)
780 return;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800781 os_memcpy(info->addr, addr, ETH_ALEN);
782 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800783 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800784
785 if (iface->num_sta_seen >= iface->conf->track_sta_max_num) {
786 /* Expire oldest entry to make room for a new one */
787 sta_track_expire(iface, 1);
788 }
789
790 wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
791 MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr));
792 dl_list_add_tail(&iface->sta_seen, &info->list);
793 iface->num_sta_seen++;
794}
795
796
797struct hostapd_data *
798sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
799 const char *ifname)
800{
801 struct hapd_interfaces *interfaces = iface->interfaces;
802 size_t i, j;
803
804 for (i = 0; i < interfaces->count; i++) {
805 struct hostapd_data *hapd = NULL;
806
807 iface = interfaces->iface[i];
808 for (j = 0; j < iface->num_bss; j++) {
809 hapd = iface->bss[j];
810 if (os_strcmp(ifname, hapd->conf->iface) == 0)
811 break;
812 hapd = NULL;
813 }
814
815 if (hapd && sta_track_get(iface, addr))
816 return hapd;
817 }
818
819 return NULL;
820}
821
822
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700823#ifdef CONFIG_TAXONOMY
824void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr,
825 struct wpabuf **probe_ie_taxonomy)
826{
827 struct hostapd_sta_info *info;
828
829 info = sta_track_get(iface, addr);
830 if (!info)
831 return;
832
833 wpabuf_free(*probe_ie_taxonomy);
834 *probe_ie_taxonomy = info->probe_ie_taxonomy;
835 info->probe_ie_taxonomy = NULL;
836}
837#endif /* CONFIG_TAXONOMY */
838
839
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700840void handle_probe_req(struct hostapd_data *hapd,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700841 const struct ieee80211_mgmt *mgmt, size_t len,
842 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700843{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800844 u8 *resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700845 struct ieee802_11_elems elems;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700846 const u8 *ie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800847 size_t ie_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800848 size_t i, resp_len;
849 int noack;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800850 enum ssid_match_result res;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800851 int ret;
852 u16 csa_offs[2];
853 size_t csa_offs_len;
Hai Shalomfdcde762020-04-02 11:19:20 -0700854 struct radius_sta rad_info;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700855
Hai Shalom60840252021-02-19 19:02:11 -0800856 if (hapd->iconf->rssi_ignore_probe_request && ssi_signal &&
857 ssi_signal < hapd->iconf->rssi_ignore_probe_request)
858 return;
859
Dmitry Shmidte4663042016-04-04 10:07:49 -0700860 if (len < IEEE80211_HDRLEN)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700861 return;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700862 ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800863 if (hapd->iconf->track_sta_max_num)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800864 sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
Dmitry Shmidte4663042016-04-04 10:07:49 -0700865 ie_len = len - IEEE80211_HDRLEN;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700866
Hai Shalomfdcde762020-04-02 11:19:20 -0700867 ret = hostapd_allowed_address(hapd, mgmt->sa, (const u8 *) mgmt, len,
868 &rad_info, 1);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700869 if (ret == HOSTAPD_ACL_REJECT) {
870 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
871 "Ignore Probe Request frame from " MACSTR
872 " due to ACL reject ", MAC2STR(mgmt->sa));
873 return;
874 }
875
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700876 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
877 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800878 mgmt->sa, mgmt->da, mgmt->bssid,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700879 ie, ie_len, ssi_signal) > 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700880 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800881
Hai Shalom74f70d42019-02-11 14:42:39 -0800882 if (!hapd->conf->send_probe_response)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700883 return;
884
885 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
886 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
887 MAC2STR(mgmt->sa));
888 return;
889 }
890
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700891 if ((!elems.ssid || !elems.supp_rates)) {
892 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
893 "without SSID or supported rates element",
894 MAC2STR(mgmt->sa));
895 return;
896 }
897
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800898 /*
899 * No need to reply if the Probe Request frame was sent on an adjacent
900 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
901 * AP with dot11RadioMeasurementActivated set to true, but strictly
902 * speaking does not allow such ignoring of Probe Request frames if
903 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
904 * number of unnecessary Probe Response frames for cases where the STA
905 * is less likely to see them (Probe Request frame sent on a
906 * neighboring, but partially overlapping, channel).
907 */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700908 if (elems.ds_params &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800909 hapd->iface->current_mode &&
910 (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
911 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
912 hapd->iconf->channel != elems.ds_params[0]) {
913 wpa_printf(MSG_DEBUG,
914 "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
915 hapd->iconf->channel, elems.ds_params[0]);
916 return;
917 }
918
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700919#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800920 if (hapd->p2p && hapd->p2p_group && elems.wps_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700921 struct wpabuf *wps;
922 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
923 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
924 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
925 "due to mismatch with Requested Device "
926 "Type");
927 wpabuf_free(wps);
928 return;
929 }
930 wpabuf_free(wps);
931 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800932
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800933 if (hapd->p2p && hapd->p2p_group && elems.p2p) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800934 struct wpabuf *p2p;
935 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
936 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
937 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
938 "due to mismatch with Device ID");
939 wpabuf_free(p2p);
940 return;
941 }
942 wpabuf_free(p2p);
943 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700944#endif /* CONFIG_P2P */
945
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800946 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
Hai Shalomfdcde762020-04-02 11:19:20 -0700947 elems.ssid_list_len == 0 && elems.short_ssid_list_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700948 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
949 "broadcast SSID ignored", MAC2STR(mgmt->sa));
950 return;
951 }
952
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700953#ifdef CONFIG_P2P
954 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
955 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
956 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
957 P2P_WILDCARD_SSID_LEN) == 0) {
958 /* Process P2P Wildcard SSID like Wildcard SSID */
959 elems.ssid_len = 0;
960 }
961#endif /* CONFIG_P2P */
962
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700963#ifdef CONFIG_TAXONOMY
964 {
965 struct sta_info *sta;
966 struct hostapd_sta_info *info;
967
968 if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) {
969 taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len);
970 } else if ((info = sta_track_get(hapd->iface,
971 mgmt->sa)) != NULL) {
972 taxonomy_hostapd_sta_info_probe_req(hapd, info,
973 ie, ie_len);
974 }
975 }
976#endif /* CONFIG_TAXONOMY */
977
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800978 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
Hai Shalomfdcde762020-04-02 11:19:20 -0700979 elems.ssid_list, elems.ssid_list_len,
980 elems.short_ssid_list, elems.short_ssid_list_len);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700981 if (res == NO_SSID_MATCH) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700982 if (!(mgmt->da[0] & 0x01)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700983 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800984 " for foreign SSID '%s' (DA " MACSTR ")%s",
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800985 MAC2STR(mgmt->sa),
986 wpa_ssid_txt(elems.ssid, elems.ssid_len),
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800987 MAC2STR(mgmt->da),
988 elems.ssid_list ? " (SSID list)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700989 }
990 return;
991 }
992
Hai Shalomfdcde762020-04-02 11:19:20 -0700993 if (hapd->conf->ignore_broadcast_ssid && res == WILDCARD_SSID_MATCH) {
994 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
995 "broadcast SSID ignored", MAC2STR(mgmt->sa));
996 return;
997 }
998
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800999#ifdef CONFIG_INTERWORKING
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -07001000 if (hapd->conf->interworking &&
1001 elems.interworking && elems.interworking_len >= 1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001002 u8 ant = elems.interworking[0] & 0x0f;
1003 if (ant != INTERWORKING_ANT_WILDCARD &&
1004 ant != hapd->conf->access_network_type) {
1005 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
1006 " for mismatching ANT %u ignored",
1007 MAC2STR(mgmt->sa), ant);
1008 return;
1009 }
1010 }
1011
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -07001012 if (hapd->conf->interworking && elems.interworking &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001013 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
1014 const u8 *hessid;
1015 if (elems.interworking_len == 7)
1016 hessid = elems.interworking + 1;
1017 else
1018 hessid = elems.interworking + 1 + 2;
1019 if (!is_broadcast_ether_addr(hessid) &&
1020 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
1021 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
1022 " for mismatching HESSID " MACSTR
1023 " ignored",
1024 MAC2STR(mgmt->sa), MAC2STR(hessid));
1025 return;
1026 }
1027 }
1028#endif /* CONFIG_INTERWORKING */
1029
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001030#ifdef CONFIG_P2P
1031 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1032 supp_rates_11b_only(&elems)) {
1033 /* Indicates support for 11b rates only */
1034 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
1035 MACSTR " with only 802.11b rates",
1036 MAC2STR(mgmt->sa));
1037 return;
1038 }
1039#endif /* CONFIG_P2P */
1040
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001041 /* TODO: verify that supp_rates contains at least one matching rate
1042 * with AP configuration */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001043
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001044 if (hapd->conf->no_probe_resp_if_seen_on &&
1045 is_multicast_ether_addr(mgmt->da) &&
1046 is_multicast_ether_addr(mgmt->bssid) &&
1047 sta_track_seen_on(hapd->iface, mgmt->sa,
1048 hapd->conf->no_probe_resp_if_seen_on)) {
1049 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1050 " since STA has been seen on %s",
1051 hapd->conf->iface, MAC2STR(mgmt->sa),
1052 hapd->conf->no_probe_resp_if_seen_on);
1053 return;
1054 }
1055
1056 if (hapd->conf->no_probe_resp_if_max_sta &&
1057 is_multicast_ether_addr(mgmt->da) &&
1058 is_multicast_ether_addr(mgmt->bssid) &&
1059 hapd->num_sta >= hapd->conf->max_num_sta &&
1060 !ap_get_sta(hapd, mgmt->sa)) {
1061 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1062 " since no room for additional STA",
1063 hapd->conf->iface, MAC2STR(mgmt->sa));
1064 return;
1065 }
1066
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001067#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001068 if (hapd->iconf->ignore_probe_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001069 drand48() < hapd->iconf->ignore_probe_probability) {
1070 wpa_printf(MSG_INFO,
1071 "TESTING: ignoring probe request from " MACSTR,
1072 MAC2STR(mgmt->sa));
1073 return;
1074 }
1075#endif /* CONFIG_TESTING_OPTIONS */
1076
Roshan Pius3a1667e2018-07-03 15:17:14 -07001077 wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, RX_PROBE_REQUEST "sa=" MACSTR
1078 " signal=%d", MAC2STR(mgmt->sa), ssi_signal);
1079
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001080 resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001081 &resp_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001082 if (resp == NULL)
1083 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001084
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001085 /*
1086 * If this is a broadcast probe request, apply no ack policy to avoid
1087 * excessive retries.
1088 */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001089 noack = !!(res == WILDCARD_SSID_MATCH &&
1090 is_broadcast_ether_addr(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001091
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001092 csa_offs_len = 0;
1093 if (hapd->csa_in_progress) {
1094 if (hapd->cs_c_off_proberesp)
1095 csa_offs[csa_offs_len++] =
1096 hapd->cs_c_off_proberesp;
1097
1098 if (hapd->cs_c_off_ecsa_proberesp)
1099 csa_offs[csa_offs_len++] =
1100 hapd->cs_c_off_ecsa_proberesp;
1101 }
1102
Hai Shalomfdcde762020-04-02 11:19:20 -07001103 ret = hostapd_drv_send_mlme(hapd, resp, resp_len, noack,
1104 csa_offs_len ? csa_offs : NULL,
1105 csa_offs_len, 0);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001106
1107 if (ret < 0)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001108 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001109
1110 os_free(resp);
1111
1112 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
1113 "SSID", MAC2STR(mgmt->sa),
1114 elems.ssid_len == 0 ? "broadcast" : "our");
1115}
1116
1117
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001118static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
1119 size_t *resp_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001120{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001121 /* check probe response offloading caps and print warnings */
1122 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
1123 return NULL;
1124
1125#ifdef CONFIG_WPS
1126 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
1127 (!(hapd->iface->probe_resp_offloads &
1128 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
1129 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
1130 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
1131 "Probe Response while not supporting this");
1132#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001133
1134#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001135 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
1136 !(hapd->iface->probe_resp_offloads &
1137 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
1138 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
1139 "Probe Response while not supporting this");
1140#endif /* CONFIG_P2P */
1141
1142 if (hapd->conf->interworking &&
1143 !(hapd->iface->probe_resp_offloads &
1144 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
1145 wpa_printf(MSG_WARNING, "Device is trying to offload "
1146 "Interworking Probe Response while not supporting "
1147 "this");
1148
1149 /* Generate a Probe Response template for the non-P2P case */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001150 return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001151}
1152
1153#endif /* NEED_AP_MLME */
1154
1155
Hai Shalom60840252021-02-19 19:02:11 -08001156#ifdef CONFIG_IEEE80211AX
1157/* Unsolicited broadcast Probe Response transmission, 6 GHz only */
1158static u8 * hostapd_unsol_bcast_probe_resp(struct hostapd_data *hapd,
1159 struct wpa_driver_ap_params *params)
1160{
1161 if (!is_6ghz_op_class(hapd->iconf->op_class))
1162 return NULL;
1163
1164 params->unsol_bcast_probe_resp_interval =
1165 hapd->conf->unsol_bcast_probe_resp_interval;
1166
1167 return hostapd_gen_probe_resp(hapd, NULL, 0,
1168 &params->unsol_bcast_probe_resp_tmpl_len);
1169}
1170#endif /* CONFIG_IEEE80211AX */
1171
1172
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001173void sta_track_del(struct hostapd_sta_info *info)
1174{
1175#ifdef CONFIG_TAXONOMY
1176 wpabuf_free(info->probe_ie_taxonomy);
1177 info->probe_ie_taxonomy = NULL;
1178#endif /* CONFIG_TAXONOMY */
1179 os_free(info);
1180}
1181
1182
Hai Shalom60840252021-02-19 19:02:11 -08001183#ifdef CONFIG_FILS
1184
1185static u16 hostapd_fils_discovery_cap(struct hostapd_data *hapd)
1186{
1187 u16 cap_info, phy_index = 0;
1188 u8 chwidth = FD_CAP_BSS_CHWIDTH_20, mcs_nss_size = 4;
1189 struct hostapd_hw_modes *mode = hapd->iface->current_mode;
1190
1191 cap_info = FD_CAP_ESS;
1192 if (hapd->conf->wpa)
1193 cap_info |= FD_CAP_PRIVACY;
1194
1195 if (is_6ghz_op_class(hapd->iconf->op_class)) {
1196 phy_index = FD_CAP_PHY_INDEX_HE;
1197
1198 switch (hapd->iconf->op_class) {
1199 case 135:
1200 mcs_nss_size += 4;
1201 /* fallthrough */
1202 case 134:
1203 mcs_nss_size += 4;
1204 chwidth = FD_CAP_BSS_CHWIDTH_160_80_80;
1205 break;
1206 case 133:
1207 chwidth = FD_CAP_BSS_CHWIDTH_80;
1208 break;
1209 case 132:
1210 chwidth = FD_CAP_BSS_CHWIDTH_40;
1211 break;
1212 }
1213 } else {
1214 switch (hostapd_get_oper_chwidth(hapd->iconf)) {
1215 case CHANWIDTH_80P80MHZ:
1216 mcs_nss_size += 4;
1217 /* fallthrough */
1218 case CHANWIDTH_160MHZ:
1219 mcs_nss_size += 4;
1220 chwidth = FD_CAP_BSS_CHWIDTH_160_80_80;
1221 break;
1222 case CHANWIDTH_80MHZ:
1223 chwidth = FD_CAP_BSS_CHWIDTH_80;
1224 break;
1225 case CHANWIDTH_USE_HT:
1226 if (hapd->iconf->secondary_channel)
1227 chwidth = FD_CAP_BSS_CHWIDTH_40;
1228 else
1229 chwidth = FD_CAP_BSS_CHWIDTH_20;
1230 break;
1231 }
1232
1233#ifdef CONFIG_IEEE80211AX
1234 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax)
1235 phy_index = FD_CAP_PHY_INDEX_HE;
1236#endif /* CONFIG_IEEE80211AX */
1237#ifdef CONFIG_IEEE80211AC
1238 if (!phy_index &&
1239 hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac)
1240 phy_index = FD_CAP_PHY_INDEX_VHT;
1241#endif /* CONFIG_IEEE80211AC */
1242 if (!phy_index &&
1243 hapd->iconf->ieee80211n && !hapd->conf->disable_11n)
1244 phy_index = FD_CAP_PHY_INDEX_HT;
1245 }
1246
1247 cap_info |= phy_index << FD_CAP_PHY_INDEX_SHIFT;
1248 cap_info |= chwidth << FD_CAP_BSS_CHWIDTH_SHIFT;
1249
1250 if (mode) {
1251 u16 *mcs = (u16 *) mode->he_capab[IEEE80211_MODE_AP].mcs;
1252 int i;
1253 u16 nss = 0;
1254
1255 for (i = 0; i < HE_NSS_MAX_STREAMS; i++) {
1256 u16 nss_mask = 0x3 << (i * 2);
1257
1258 if (mcs_nss_size == 4 &&
1259 (((mcs[0] & nss_mask) == nss_mask) ||
1260 ((mcs[1] & nss_mask) == nss_mask)))
1261 continue;
1262
1263 if (mcs_nss_size == 8 &&
1264 (((mcs[2] & nss_mask) == nss_mask) ||
1265 ((mcs[3] & nss_mask) == nss_mask)))
1266 continue;
1267
1268 if (mcs_nss_size == 12 &&
1269 (((mcs[4] & nss_mask) == nss_mask) ||
1270 ((mcs[5] & nss_mask) == nss_mask)))
1271 continue;
1272
1273 nss++;
1274 }
1275
1276 if (nss > 4)
1277 cap_info |= FD_CAP_NSS_5_8 << FD_CAP_NSS_SHIFT;
1278 else if (nss)
1279 cap_info |= (nss - 1) << FD_CAP_NSS_SHIFT;
1280 }
1281
1282 return cap_info;
1283}
1284
1285
1286static u8 * hostapd_gen_fils_discovery(struct hostapd_data *hapd, size_t *len)
1287{
1288 struct ieee80211_mgmt *head;
1289 const u8 *mobility_domain;
1290 u8 *pos, *length_pos, buf[200];
1291 u16 ctl = 0;
1292 u8 fd_rsn_info[5];
1293 size_t total_len, buf_len;
1294
1295 total_len = 24 + 2 + 12;
1296
1297 /* FILS Discovery Frame Control */
1298 ctl = (sizeof(hapd->conf->ssid.short_ssid) - 1) |
1299 FD_FRAME_CTL_SHORT_SSID_PRESENT |
1300 FD_FRAME_CTL_LENGTH_PRESENT |
1301 FD_FRAME_CTL_CAP_PRESENT;
1302 total_len += 4 + 1 + 2;
1303
1304 /* Check for optional subfields and calculate length */
1305 if (wpa_auth_write_fd_rsn_info(hapd->wpa_auth, fd_rsn_info)) {
1306 ctl |= FD_FRAME_CTL_RSN_INFO_PRESENT;
1307 total_len += sizeof(fd_rsn_info);
1308 }
1309
1310 mobility_domain = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN);
1311 if (mobility_domain) {
1312 ctl |= FD_FRAME_CTL_MD_PRESENT;
1313 total_len += 3;
1314 }
1315
Hai Shaloma20dcd72022-02-04 13:43:00 -08001316 total_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_ACTION);
1317
Hai Shalom60840252021-02-19 19:02:11 -08001318 pos = hostapd_eid_fils_indic(hapd, buf, 0);
1319 buf_len = pos - buf;
1320 total_len += buf_len;
1321
1322 head = os_zalloc(total_len);
1323 if (!head)
1324 return NULL;
1325
1326 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1327 WLAN_FC_STYPE_ACTION);
1328 os_memset(head->da, 0xff, ETH_ALEN);
1329 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1330 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1331
1332 head->u.action.category = WLAN_ACTION_PUBLIC;
1333 head->u.action.u.public_action.action = WLAN_PA_FILS_DISCOVERY;
1334
1335 pos = &head->u.action.u.public_action.variable[0];
1336
1337 /* FILS Discovery Information field */
1338
1339 /* FILS Discovery Frame Control */
1340 WPA_PUT_LE16(pos, ctl);
1341 pos += 2;
1342
1343 /* Hardware or low-level driver will fill in the Timestamp value */
1344 pos += 8;
1345
1346 /* Beacon Interval */
1347 WPA_PUT_LE16(pos, hapd->iconf->beacon_int);
1348 pos += 2;
1349
1350 /* Short SSID */
1351 WPA_PUT_LE32(pos, hapd->conf->ssid.short_ssid);
1352 pos += sizeof(hapd->conf->ssid.short_ssid);
1353
1354 /* Store position of FILS discovery information element Length field */
1355 length_pos = pos++;
1356
1357 /* FD Capability */
1358 WPA_PUT_LE16(pos, hostapd_fils_discovery_cap(hapd));
1359 pos += 2;
1360
1361 /* Operating Class - not present */
1362
1363 /* Primary Channel - not present */
1364
1365 /* AP Configuration Sequence Number - not present */
1366
1367 /* Access Network Options - not present */
1368
1369 /* FD RSN Information */
1370 if (ctl & FD_FRAME_CTL_RSN_INFO_PRESENT) {
1371 os_memcpy(pos, fd_rsn_info, sizeof(fd_rsn_info));
1372 pos += sizeof(fd_rsn_info);
1373 }
1374
1375 /* Channel Center Frequency Segment 1 - not present */
1376
1377 /* Mobility Domain */
1378 if (ctl & FD_FRAME_CTL_MD_PRESENT) {
1379 os_memcpy(pos, &mobility_domain[2], 3);
1380 pos += 3;
1381 }
1382
1383 /* Fill in the Length field value */
1384 *length_pos = pos - (length_pos + 1);
1385
Hai Shaloma20dcd72022-02-04 13:43:00 -08001386 pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_ACTION);
1387
Hai Shalom60840252021-02-19 19:02:11 -08001388 /* FILS Indication element */
1389 if (buf_len) {
1390 os_memcpy(pos, buf, buf_len);
1391 pos += buf_len;
1392 }
1393
1394 *len = pos - (u8 *) head;
1395 wpa_hexdump(MSG_DEBUG, "FILS Discovery frame template",
1396 head, pos - (u8 *) head);
1397 return (u8 *) head;
1398}
1399
1400
1401/* Configure FILS Discovery frame transmission parameters */
1402static u8 * hostapd_fils_discovery(struct hostapd_data *hapd,
1403 struct wpa_driver_ap_params *params)
1404{
1405 params->fd_max_int = hapd->conf->fils_discovery_max_int;
1406 if (is_6ghz_op_class(hapd->iconf->op_class) &&
1407 params->fd_max_int > FD_MAX_INTERVAL_6GHZ)
1408 params->fd_max_int = FD_MAX_INTERVAL_6GHZ;
1409
1410 params->fd_min_int = hapd->conf->fils_discovery_min_int;
1411 if (params->fd_min_int > params->fd_max_int)
1412 params->fd_min_int = params->fd_max_int;
1413
1414 if (params->fd_max_int)
1415 return hostapd_gen_fils_discovery(hapd,
1416 &params->fd_frame_tmpl_len);
1417
1418 return NULL;
1419}
1420
1421#endif /* CONFIG_FILS */
1422
1423
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001424int ieee802_11_build_ap_params(struct hostapd_data *hapd,
1425 struct wpa_driver_ap_params *params)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001426{
1427 struct ieee80211_mgmt *head = NULL;
1428 u8 *tail = NULL;
1429 size_t head_len = 0, tail_len = 0;
1430 u8 *resp = NULL;
1431 size_t resp_len = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001432#ifdef NEED_AP_MLME
1433 u16 capab_info;
Hai Shalomfdcde762020-04-02 11:19:20 -07001434 u8 *pos, *tailpos, *tailend, *csa_pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001435
1436#define BEACON_HEAD_BUF_SIZE 256
1437#define BEACON_TAIL_BUF_SIZE 512
1438 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
1439 tail_len = BEACON_TAIL_BUF_SIZE;
1440#ifdef CONFIG_WPS
1441 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
1442 tail_len += wpabuf_len(hapd->wps_beacon_ie);
1443#endif /* CONFIG_WPS */
1444#ifdef CONFIG_P2P
1445 if (hapd->p2p_beacon_ie)
1446 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
1447#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001448#ifdef CONFIG_FST
1449 if (hapd->iface->fst_ies)
1450 tail_len += wpabuf_len(hapd->iface->fst_ies);
1451#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001452 if (hapd->conf->vendor_elements)
1453 tail_len += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001454
1455#ifdef CONFIG_IEEE80211AC
1456 if (hapd->conf->vendor_vht) {
1457 tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
1458 2 + sizeof(struct ieee80211_vht_operation);
1459 }
1460#endif /* CONFIG_IEEE80211AC */
1461
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001462#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08001463 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001464 tail_len += 3 + sizeof(struct ieee80211_he_capabilities) +
Hai Shalom74f70d42019-02-11 14:42:39 -08001465 3 + sizeof(struct ieee80211_he_operation) +
Hai Shalom81f62d82019-07-22 12:10:00 -07001466 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
1467 3 + sizeof(struct ieee80211_spatial_reuse);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001468 if (is_6ghz_op_class(hapd->iconf->op_class))
1469 tail_len += sizeof(struct ieee80211_he_6ghz_oper_info) +
1470 3 + sizeof(struct ieee80211_he_6ghz_band_cap);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001471 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001472#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001473
Hai Shaloma20dcd72022-02-04 13:43:00 -08001474 tail_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_BEACON);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001475 tail_len += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001476 tail_len += hostapd_eid_owe_trans_len(hapd);
Hai Shalomfdcde762020-04-02 11:19:20 -07001477 tail_len += hostapd_eid_dpp_cc_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001478
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001479 tailpos = tail = os_malloc(tail_len);
1480 if (head == NULL || tail == NULL) {
1481 wpa_printf(MSG_ERROR, "Failed to set beacon data");
1482 os_free(head);
1483 os_free(tail);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001484 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001485 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001486 tailend = tail + tail_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001487
1488 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1489 WLAN_FC_STYPE_BEACON);
1490 head->duration = host_to_le16(0);
1491 os_memset(head->da, 0xff, ETH_ALEN);
1492
1493 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1494 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1495 head->u.beacon.beacon_int =
1496 host_to_le16(hapd->iconf->beacon_int);
1497
1498 /* hardware or low-level driver will setup seq_ctrl and timestamp */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001499 capab_info = hostapd_own_capab_info(hapd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001500 head->u.beacon.capab_info = host_to_le16(capab_info);
1501 pos = &head->u.beacon.variable[0];
1502
1503 /* SSID */
1504 *pos++ = WLAN_EID_SSID;
1505 if (hapd->conf->ignore_broadcast_ssid == 2) {
1506 /* clear the data, but keep the correct length of the SSID */
1507 *pos++ = hapd->conf->ssid.ssid_len;
1508 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
1509 pos += hapd->conf->ssid.ssid_len;
1510 } else if (hapd->conf->ignore_broadcast_ssid) {
1511 *pos++ = 0; /* empty SSID */
1512 } else {
1513 *pos++ = hapd->conf->ssid.ssid_len;
1514 os_memcpy(pos, hapd->conf->ssid.ssid,
1515 hapd->conf->ssid.ssid_len);
1516 pos += hapd->conf->ssid.ssid_len;
1517 }
1518
1519 /* Supported rates */
1520 pos = hostapd_eid_supp_rates(hapd, pos);
1521
1522 /* DS Params */
1523 pos = hostapd_eid_ds_params(hapd, pos);
1524
1525 head_len = pos - (u8 *) head;
1526
Hai Shalomfdcde762020-04-02 11:19:20 -07001527 tailpos = hostapd_eid_country(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001528
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001529 /* Power Constraint element */
1530 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
1531
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001532 /* CSA IE */
1533 csa_pos = hostapd_eid_csa(hapd, tailpos);
1534 if (csa_pos != tailpos)
1535 hapd->cs_c_off_beacon = csa_pos - tail - 1;
1536 tailpos = csa_pos;
1537
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001538 /* ERP Information element */
1539 tailpos = hostapd_eid_erp_info(hapd, tailpos);
1540
1541 /* Extended supported rates */
1542 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
1543
Hai Shalomfdcde762020-04-02 11:19:20 -07001544 tailpos = hostapd_get_rsne(hapd, tailpos, tailend - tailpos);
1545 tailpos = hostapd_eid_bss_load(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001546 tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
Hai Shalomfdcde762020-04-02 11:19:20 -07001547 tailend - tailpos);
1548 tailpos = hostapd_get_mde(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001549
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001550 /* eCSA IE */
1551 csa_pos = hostapd_eid_ecsa(hapd, tailpos);
1552 if (csa_pos != tailpos)
1553 hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1;
1554 tailpos = csa_pos;
1555
1556 tailpos = hostapd_eid_supported_op_classes(hapd, tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001557 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
1558 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001559
1560 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
1561
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001562 /*
1563 * TODO: Time Advertisement element should only be included in some
1564 * DTIM Beacon frames.
1565 */
1566 tailpos = hostapd_eid_time_adv(hapd, tailpos);
1567
1568 tailpos = hostapd_eid_interworking(hapd, tailpos);
1569 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
1570 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001571
1572#ifdef CONFIG_FST
1573 if (hapd->iface->fst_ies) {
1574 os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies),
1575 wpabuf_len(hapd->iface->fst_ies));
1576 tailpos += wpabuf_len(hapd->iface->fst_ies);
1577 }
1578#endif /* CONFIG_FST */
1579
Dmitry Shmidt04949592012-07-19 12:16:46 -07001580#ifdef CONFIG_IEEE80211AC
Hai Shalom60840252021-02-19 19:02:11 -08001581 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
1582 !is_6ghz_op_class(hapd->iconf->op_class)) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -07001583 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001584 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08001585 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001586 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001587#endif /* CONFIG_IEEE80211AC */
1588
Hai Shalom60840252021-02-19 19:02:11 -08001589#ifdef CONFIG_IEEE80211AX
1590 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax &&
1591 is_6ghz_op_class(hapd->iconf->op_class))
1592 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
1593#endif /* CONFIG_IEEE80211AX */
1594
Hai Shaloma20dcd72022-02-04 13:43:00 -08001595 tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos);
Hai Shalom899fcc72020-10-19 14:38:18 -07001596
Hai Shaloma20dcd72022-02-04 13:43:00 -08001597 tailpos = hostapd_eid_rnr(hapd, tailpos, WLAN_FC_STYPE_BEACON);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001598 tailpos = hostapd_eid_fils_indic(hapd, tailpos, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -07001599 tailpos = hostapd_get_rsnxe(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001600
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001601#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08001602 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Hai Shalom81f62d82019-07-22 12:10:00 -07001603 tailpos = hostapd_eid_he_capab(hapd, tailpos,
1604 IEEE80211_MODE_AP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001605 tailpos = hostapd_eid_he_operation(hapd, tailpos);
Hai Shalom81f62d82019-07-22 12:10:00 -07001606 tailpos = hostapd_eid_spatial_reuse(hapd, tailpos);
Hai Shalomfdcde762020-04-02 11:19:20 -07001607 tailpos = hostapd_eid_he_mu_edca_parameter_set(hapd, tailpos);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001608 tailpos = hostapd_eid_he_6ghz_band_cap(hapd, tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001609 }
1610#endif /* CONFIG_IEEE80211AX */
1611
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001612#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001613 if (hapd->conf->vendor_vht)
1614 tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001615#endif /* CONFIG_IEEE80211AC */
1616
Hai Shalomfdcde762020-04-02 11:19:20 -07001617 /* WPA / OSEN */
1618 tailpos = hostapd_get_wpa_ie(hapd, tailpos, tailend - tailpos);
1619 tailpos = hostapd_get_osen_ie(hapd, tailpos, tailend - tailpos);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001620
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001621 /* Wi-Fi Alliance WMM */
1622 tailpos = hostapd_eid_wmm(hapd, tailpos);
1623
1624#ifdef CONFIG_WPS
1625 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
1626 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
1627 wpabuf_len(hapd->wps_beacon_ie));
1628 tailpos += wpabuf_len(hapd->wps_beacon_ie);
1629 }
1630#endif /* CONFIG_WPS */
1631
1632#ifdef CONFIG_P2P
1633 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
1634 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
1635 wpabuf_len(hapd->p2p_beacon_ie));
1636 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
1637 }
1638#endif /* CONFIG_P2P */
1639#ifdef CONFIG_P2P_MANAGER
1640 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
1641 P2P_MANAGE)
1642 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
1643#endif /* CONFIG_P2P_MANAGER */
1644
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001645#ifdef CONFIG_HS20
1646 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
1647#endif /* CONFIG_HS20 */
1648
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001649 tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001650 tailpos = hostapd_eid_owe_trans(hapd, tailpos,
1651 tail + tail_len - tailpos);
Hai Shalomfdcde762020-04-02 11:19:20 -07001652 tailpos = hostapd_eid_dpp_cc(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001653
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001654 if (hapd->conf->vendor_elements) {
1655 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
1656 wpabuf_len(hapd->conf->vendor_elements));
1657 tailpos += wpabuf_len(hapd->conf->vendor_elements);
1658 }
1659
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001660 tail_len = tailpos > tail ? tailpos - tail : 0;
1661
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001662 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
1663#endif /* NEED_AP_MLME */
1664
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001665 os_memset(params, 0, sizeof(*params));
1666 params->head = (u8 *) head;
1667 params->head_len = head_len;
1668 params->tail = tail;
1669 params->tail_len = tail_len;
1670 params->proberesp = resp;
1671 params->proberesp_len = resp_len;
1672 params->dtim_period = hapd->conf->dtim_period;
1673 params->beacon_int = hapd->iconf->beacon_int;
1674 params->basic_rates = hapd->iface->basic_rates;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001675 params->beacon_rate = hapd->iconf->beacon_rate;
1676 params->rate_type = hapd->iconf->rate_type;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001677 params->ssid = hapd->conf->ssid.ssid;
1678 params->ssid_len = hapd->conf->ssid.ssid_len;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001679 if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
1680 (WPA_PROTO_WPA | WPA_PROTO_RSN))
1681 params->pairwise_ciphers = hapd->conf->wpa_pairwise |
1682 hapd->conf->rsn_pairwise;
1683 else if (hapd->conf->wpa & WPA_PROTO_RSN)
1684 params->pairwise_ciphers = hapd->conf->rsn_pairwise;
1685 else if (hapd->conf->wpa & WPA_PROTO_WPA)
1686 params->pairwise_ciphers = hapd->conf->wpa_pairwise;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001687 params->group_cipher = hapd->conf->wpa_group;
1688 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
1689 params->auth_algs = hapd->conf->auth_algs;
1690 params->wpa_version = hapd->conf->wpa;
Hai Shalomfdcde762020-04-02 11:19:20 -07001691 params->privacy = hapd->conf->wpa;
1692#ifdef CONFIG_WEP
1693 params->privacy |= hapd->conf->ssid.wep.keys_set ||
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001694 (hapd->conf->ieee802_1x &&
1695 (hapd->conf->default_wep_key_len ||
1696 hapd->conf->individual_wep_key_len));
Hai Shalomfdcde762020-04-02 11:19:20 -07001697#endif /* CONFIG_WEP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001698 switch (hapd->conf->ignore_broadcast_ssid) {
1699 case 0:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001700 params->hide_ssid = NO_SSID_HIDING;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001701 break;
1702 case 1:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001703 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001704 break;
1705 case 2:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001706 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001707 break;
1708 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001709 params->isolate = hapd->conf->isolate;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001710#ifdef NEED_AP_MLME
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001711 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001712 ERP_INFO_USE_PROTECTION);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001713 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001714 hapd->iconf->preamble == SHORT_PREAMBLE;
1715 if (hapd->iface->current_mode &&
1716 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001717 params->short_slot_time =
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001718 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
1719 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001720 params->short_slot_time = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001721 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001722 params->ht_opmode = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001723 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001724 params->ht_opmode = hapd->iface->ht_op_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001725#endif /* NEED_AP_MLME */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001726 params->interworking = hapd->conf->interworking;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001727 if (hapd->conf->interworking &&
1728 !is_zero_ether_addr(hapd->conf->hessid))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001729 params->hessid = hapd->conf->hessid;
1730 params->access_network_type = hapd->conf->access_network_type;
1731 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001732#ifdef CONFIG_P2P
1733 params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
1734#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001735#ifdef CONFIG_HS20
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001736 params->disable_dgaf = hapd->conf->disable_dgaf;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001737 if (hapd->conf->osen) {
1738 params->privacy = 1;
1739 params->osen = 1;
1740 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001741#endif /* CONFIG_HS20 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001742 params->multicast_to_unicast = hapd->conf->multicast_to_unicast;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001743 params->pbss = hapd->conf->pbss;
Hai Shalom74f70d42019-02-11 14:42:39 -08001744
1745 if (hapd->conf->ftm_responder) {
1746 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_FTM_RESPONDER) {
1747 params->ftm_responder = 1;
1748 params->lci = hapd->iface->conf->lci;
1749 params->civic = hapd->iface->conf->civic;
1750 } else {
1751 wpa_printf(MSG_WARNING,
1752 "Not configuring FTM responder as the driver doesn't advertise support for it");
1753 }
1754 }
1755
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001756 return 0;
1757}
1758
1759
1760void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
1761{
1762 os_free(params->tail);
1763 params->tail = NULL;
1764 os_free(params->head);
1765 params->head = NULL;
1766 os_free(params->proberesp);
1767 params->proberesp = NULL;
Hai Shalom60840252021-02-19 19:02:11 -08001768#ifdef CONFIG_FILS
1769 os_free(params->fd_frame_tmpl);
1770 params->fd_frame_tmpl = NULL;
1771#endif /* CONFIG_FILS */
1772#ifdef CONFIG_IEEE80211AX
1773 os_free(params->unsol_bcast_probe_resp_tmpl);
1774 params->unsol_bcast_probe_resp_tmpl = NULL;
1775#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001776}
1777
1778
Hai Shaloma20dcd72022-02-04 13:43:00 -08001779static int __ieee802_11_set_beacon(struct hostapd_data *hapd)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001780{
1781 struct wpa_driver_ap_params params;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001782 struct hostapd_freq_params freq;
1783 struct hostapd_iface *iface = hapd->iface;
1784 struct hostapd_config *iconf = iface->conf;
Hai Shalom81f62d82019-07-22 12:10:00 -07001785 struct hostapd_hw_modes *cmode = iface->current_mode;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001786 struct wpabuf *beacon, *proberesp, *assocresp;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001787 int res, ret = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001788
Hai Shaloma20dcd72022-02-04 13:43:00 -08001789 if (!hapd->drv_priv) {
1790 wpa_printf(MSG_ERROR, "Interface is disabled");
1791 return -1;
1792 }
1793
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001794 if (hapd->csa_in_progress) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001795 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001796 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001797 }
1798
1799 hapd->beacon_set_done = 1;
1800
1801 if (ieee802_11_build_ap_params(hapd, &params) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001802 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001803
1804 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
1805 0)
1806 goto fail;
1807
1808 params.beacon_ies = beacon;
1809 params.proberesp_ies = proberesp;
1810 params.assocresp_ies = assocresp;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001811 params.reenable = hapd->reenable_beacon;
Hai Shalomc3565922019-10-28 11:58:20 -07001812#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08001813 params.he_spr_ctrl = hapd->iface->conf->spr.sr_control;
1814 params.he_spr_non_srg_obss_pd_max_offset =
1815 hapd->iface->conf->spr.non_srg_obss_pd_max_offset;
Hai Shalomc3565922019-10-28 11:58:20 -07001816 params.he_spr_srg_obss_pd_min_offset =
1817 hapd->iface->conf->spr.srg_obss_pd_min_offset;
1818 params.he_spr_srg_obss_pd_max_offset =
1819 hapd->iface->conf->spr.srg_obss_pd_max_offset;
Hai Shalom60840252021-02-19 19:02:11 -08001820 os_memcpy(params.he_spr_bss_color_bitmap,
1821 hapd->iface->conf->spr.srg_bss_color_bitmap, 8);
1822 os_memcpy(params.he_spr_partial_bssid_bitmap,
1823 hapd->iface->conf->spr.srg_partial_bssid_bitmap, 8);
Hai Shalomfdcde762020-04-02 11:19:20 -07001824 params.he_bss_color_disabled =
1825 hapd->iface->conf->he_op.he_bss_color_disabled;
1826 params.he_bss_color_partial =
1827 hapd->iface->conf->he_op.he_bss_color_partial;
1828 params.he_bss_color = hapd->iface->conf->he_op.he_bss_color;
1829 params.twt_responder = hostapd_get_he_twt_responder(hapd,
1830 IEEE80211_MODE_AP);
Hai Shalom60840252021-02-19 19:02:11 -08001831 params.unsol_bcast_probe_resp_tmpl =
1832 hostapd_unsol_bcast_probe_resp(hapd, &params);
Hai Shalomc3565922019-10-28 11:58:20 -07001833#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001834 hapd->reenable_beacon = 0;
Hai Shalom60840252021-02-19 19:02:11 -08001835#ifdef CONFIG_SAE
1836 params.sae_pwe = hapd->conf->sae_pwe;
1837#endif /* CONFIG_SAE */
1838
1839#ifdef CONFIG_FILS
1840 params.fd_frame_tmpl = hostapd_fils_discovery(hapd, &params);
1841#endif /* CONFIG_FILS */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001842
Hai Shalom81f62d82019-07-22 12:10:00 -07001843 if (cmode &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001844 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
Hai Shalomc3565922019-10-28 11:58:20 -07001845 iconf->channel, iconf->enable_edmg,
1846 iconf->edmg_channel, iconf->ieee80211n,
Hai Shalom81f62d82019-07-22 12:10:00 -07001847 iconf->ieee80211ac, iconf->ieee80211ax,
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001848 iconf->secondary_channel,
Hai Shalom81f62d82019-07-22 12:10:00 -07001849 hostapd_get_oper_chwidth(iconf),
1850 hostapd_get_oper_centr_freq_seg0_idx(iconf),
1851 hostapd_get_oper_centr_freq_seg1_idx(iconf),
1852 cmode->vht_capab,
1853 &cmode->he_capab[IEEE80211_MODE_AP]) == 0)
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001854 params.freq = &freq;
1855
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001856 res = hostapd_drv_set_ap(hapd, &params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001857 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001858 if (res)
1859 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
1860 else
1861 ret = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001862fail:
1863 ieee802_11_free_ap_params(&params);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001864 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001865}
1866
1867
Hai Shaloma20dcd72022-02-04 13:43:00 -08001868int ieee802_11_set_beacon(struct hostapd_data *hapd)
1869{
1870 struct hostapd_iface *iface = hapd->iface;
1871 int ret;
1872 size_t i, j;
1873 bool is_6g;
1874
1875 ret = __ieee802_11_set_beacon(hapd);
1876 if (ret != 0)
1877 return ret;
1878
1879 if (!iface->interfaces || iface->interfaces->count <= 1)
1880 return 0;
1881
1882 /* Update Beacon frames in case of 6 GHz colocation */
1883 is_6g = is_6ghz_op_class(iface->conf->op_class);
1884 for (j = 0; j < iface->interfaces->count; j++) {
1885 struct hostapd_iface *colocated;
1886
1887 colocated = iface->interfaces->iface[j];
1888 if (colocated == iface || !colocated || !colocated->conf)
1889 continue;
1890
1891 if (is_6g == is_6ghz_op_class(colocated->conf->op_class))
1892 continue;
1893
1894 for (i = 0; i < colocated->num_bss; i++) {
1895 if (colocated->bss[i] && colocated->bss[i]->started)
1896 __ieee802_11_set_beacon(colocated->bss[i]);
1897 }
1898 }
1899
1900 return 0;
1901}
1902
1903
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001904int ieee802_11_set_beacons(struct hostapd_iface *iface)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001905{
1906 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001907 int ret = 0;
1908
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08001909 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001910 if (iface->bss[i]->started &&
1911 ieee802_11_set_beacon(iface->bss[i]) < 0)
1912 ret = -1;
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08001913 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001914
1915 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001916}
1917
Dmitry Shmidt04949592012-07-19 12:16:46 -07001918
1919/* only update beacons if started */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001920int ieee802_11_update_beacons(struct hostapd_iface *iface)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001921{
1922 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001923 int ret = 0;
1924
1925 for (i = 0; i < iface->num_bss; i++) {
1926 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
1927 ieee802_11_set_beacon(iface->bss[i]) < 0)
1928 ret = -1;
1929 }
1930
1931 return ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001932}
1933
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001934#endif /* CONFIG_NATIVE_WINDOWS */