blob: c25a5bbc38512d0280a40d8b77f6655c33fb5573 [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
Sunil Ravia04bd252022-05-02 22:54:18 -0700189static u8 * hostapd_eid_country_add(struct hostapd_data *hapd, u8 *pos,
190 u8 *end, int chan_spacing,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700191 struct hostapd_channel_data *start,
192 struct hostapd_channel_data *prev)
193{
194 if (end - pos < 3)
195 return pos;
196
197 /* first channel number */
198 *pos++ = start->chan;
199 /* number of channels */
200 *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
201 /* maximum transmit power level */
Sunil Ravia04bd252022-05-02 22:54:18 -0700202 if (!is_6ghz_op_class(hapd->iconf->op_class))
203 *pos++ = start->max_tx_power;
204 else
205 *pos++ = 0; /* Reserved when operating on the 6 GHz band */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700206
207 return pos;
208}
209
210
Sunil Ravia04bd252022-05-02 22:54:18 -0700211static u8 * hostapd_fill_subband_triplets(struct hostapd_data *hapd, u8 *pos,
212 u8 *end)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700213{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700214 int i;
215 struct hostapd_hw_modes *mode;
216 struct hostapd_channel_data *start, *prev;
217 int chan_spacing = 1;
218
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700219 mode = hapd->iface->current_mode;
220 if (mode->mode == HOSTAPD_MODE_IEEE80211A)
221 chan_spacing = 4;
222
223 start = prev = NULL;
224 for (i = 0; i < mode->num_channels; i++) {
225 struct hostapd_channel_data *chan = &mode->channels[i];
226 if (chan->flag & HOSTAPD_CHAN_DISABLED)
227 continue;
228 if (start && prev &&
229 prev->chan + chan_spacing == chan->chan &&
230 start->max_tx_power == chan->max_tx_power) {
231 prev = chan;
232 continue; /* can use same entry */
233 }
234
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -0700235 if (start && prev) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700236 pos = hostapd_eid_country_add(hapd, pos, end,
237 chan_spacing,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700238 start, prev);
239 start = NULL;
240 }
241
242 /* Start new group */
243 start = prev = chan;
244 }
245
246 if (start) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700247 pos = hostapd_eid_country_add(hapd, pos, end, chan_spacing,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700248 start, prev);
249 }
250
Sunil Ravia04bd252022-05-02 22:54:18 -0700251 return pos;
252}
253
254
255static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
256 int max_len)
257{
258 u8 *pos = eid;
259 u8 *end = eid + max_len;
260
261 if (!hapd->iconf->ieee80211d || max_len < 6 ||
262 hapd->iface->current_mode == NULL)
263 return eid;
264
265 *pos++ = WLAN_EID_COUNTRY;
266 pos++; /* length will be set later */
267 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
268 pos += 3;
269
270 if (is_6ghz_op_class(hapd->iconf->op_class)) {
271 /* Force the third octet of the country string to indicate
272 * Global Operating Class (Table E-4) */
273 eid[4] = 0x04;
274
275 /* Operating Triplet field */
276 /* Operating Extension Identifier (>= 201 to indicate this is
277 * not a Subband Triplet field) */
278 *pos++ = 201;
279 /* Operating Class */
280 *pos++ = hapd->iconf->op_class;
281 /* Coverage Class */
282 *pos++ = 0;
283 /* Subband Triplets are required only for the 20 MHz case */
284 if (hapd->iconf->op_class == 131 ||
285 hapd->iconf->op_class == 136)
286 pos = hostapd_fill_subband_triplets(hapd, pos, end);
287 } else {
288 pos = hostapd_fill_subband_triplets(hapd, pos, end);
289 }
290
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700291 if ((pos - eid) & 1) {
292 if (end - pos < 1)
293 return eid;
294 *pos++ = 0; /* pad for 16-bit alignment */
295 }
296
297 eid[1] = (pos - eid) - 2;
298
299 return pos;
300}
301
302
Hai Shalom60840252021-02-19 19:02:11 -0800303const u8 * hostapd_wpa_ie(struct hostapd_data *hapd, u8 eid)
Hai Shalomfdcde762020-04-02 11:19:20 -0700304{
305 const u8 *ies;
306 size_t ies_len;
307
308 ies = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ies_len);
309 if (!ies)
310 return NULL;
311
312 return get_ie(ies, ies_len, eid);
313}
314
315
316static const u8 * hostapd_vendor_wpa_ie(struct hostapd_data *hapd,
317 u32 vendor_type)
318{
319 const u8 *ies;
320 size_t ies_len;
321
322 ies = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ies_len);
323 if (!ies)
324 return NULL;
325
326 return get_vendor_ie(ies, ies_len, vendor_type);
327}
328
329
330static u8 * hostapd_get_rsne(struct hostapd_data *hapd, u8 *pos, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700331{
332 const u8 *ie;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700333
Hai Shalomfdcde762020-04-02 11:19:20 -0700334 ie = hostapd_wpa_ie(hapd, WLAN_EID_RSN);
335 if (!ie || 2U + ie[1] > len)
336 return pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700337
Hai Shalomfdcde762020-04-02 11:19:20 -0700338 os_memcpy(pos, ie, 2 + ie[1]);
339 return pos + 2 + ie[1];
340}
341
342
343static u8 * hostapd_get_mde(struct hostapd_data *hapd, u8 *pos, size_t len)
344{
345 const u8 *ie;
346
347 ie = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN);
348 if (!ie || 2U + ie[1] > len)
349 return pos;
350
351 os_memcpy(pos, ie, 2 + ie[1]);
352 return pos + 2 + ie[1];
353}
354
355
356static u8 * hostapd_get_rsnxe(struct hostapd_data *hapd, u8 *pos, size_t len)
357{
358 const u8 *ie;
359
360#ifdef CONFIG_TESTING_OPTIONS
361 if (hapd->conf->no_beacon_rsnxe) {
362 wpa_printf(MSG_INFO, "TESTING: Do not add RSNXE into Beacon");
363 return pos;
364 }
365#endif /* CONFIG_TESTING_OPTIONS */
366 ie = hostapd_wpa_ie(hapd, WLAN_EID_RSNX);
367 if (!ie || 2U + ie[1] > len)
368 return pos;
369
370 os_memcpy(pos, ie, 2 + ie[1]);
371 return pos + 2 + ie[1];
372}
373
374
375static u8 * hostapd_get_wpa_ie(struct hostapd_data *hapd, u8 *pos, size_t len)
376{
377 const u8 *ie;
378
379 ie = hostapd_vendor_wpa_ie(hapd, WPA_IE_VENDOR_TYPE);
380 if (!ie || 2U + ie[1] > len)
381 return pos;
382
383 os_memcpy(pos, ie, 2 + ie[1]);
384 return pos + 2 + ie[1];
385}
386
387
388static u8 * hostapd_get_osen_ie(struct hostapd_data *hapd, u8 *pos, size_t len)
389{
390 const u8 *ie;
391
392 ie = hostapd_vendor_wpa_ie(hapd, OSEN_IE_VENDOR_TYPE);
393 if (!ie || 2U + ie[1] > len)
394 return pos;
395
396 os_memcpy(pos, ie, 2 + ie[1]);
397 return pos + 2 + ie[1];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700398}
399
400
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800401static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
402{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800403#ifdef CONFIG_TESTING_OPTIONS
404 if (hapd->iface->cs_oper_class && hapd->iconf->ecsa_ie_only)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800405 return eid;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800406#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800407
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800408 if (!hapd->cs_freq_params.channel)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800409 return eid;
410
411 *eid++ = WLAN_EID_CHANNEL_SWITCH;
412 *eid++ = 3;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700413 *eid++ = hapd->cs_block_tx;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800414 *eid++ = hapd->cs_freq_params.channel;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700415 *eid++ = hapd->cs_count;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800416
417 return eid;
418}
419
420
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800421static u8 * hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800422{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800423 if (!hapd->cs_freq_params.channel || !hapd->iface->cs_oper_class)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800424 return eid;
425
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800426 *eid++ = WLAN_EID_EXT_CHANSWITCH_ANN;
427 *eid++ = 4;
428 *eid++ = hapd->cs_block_tx;
429 *eid++ = hapd->iface->cs_oper_class;
430 *eid++ = hapd->cs_freq_params.channel;
431 *eid++ = hapd->cs_count;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800432
433 return eid;
434}
435
436
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800437static u8 * hostapd_eid_supported_op_classes(struct hostapd_data *hapd, u8 *eid)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800438{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800439 u8 op_class, channel;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800440
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800441 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) ||
442 !hapd->iface->freq)
443 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800444
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800445 if (ieee80211_freq_to_channel_ext(hapd->iface->freq,
446 hapd->iconf->secondary_channel,
Hai Shalom81f62d82019-07-22 12:10:00 -0700447 hostapd_get_oper_chwidth(hapd->iconf),
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800448 &op_class, &channel) ==
449 NUM_HOSTAPD_MODES)
450 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800451
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800452 *eid++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES;
453 *eid++ = 2;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800454
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800455 /* Current Operating Class */
456 *eid++ = op_class;
457
458 /* TODO: Advertise all the supported operating classes */
459 *eid++ = 0;
460
461 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800462}
463
464
Sunil Ravi77d572f2023-01-17 23:58:31 +0000465static int
466ieee802_11_build_ap_params_mbssid(struct hostapd_data *hapd,
467 struct wpa_driver_ap_params *params)
468{
469 struct hostapd_iface *iface = hapd->iface;
470 struct hostapd_data *tx_bss;
471 size_t len;
472 u8 elem_count = 0, *elem = NULL, **elem_offset = NULL, *end;
473
474 if (!iface->mbssid_max_interfaces ||
475 iface->num_bss > iface->mbssid_max_interfaces ||
476 (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED &&
477 !iface->ema_max_periodicity))
478 goto fail;
479
480 tx_bss = hostapd_mbssid_get_tx_bss(hapd);
481 len = hostapd_eid_mbssid_len(tx_bss, WLAN_FC_STYPE_BEACON, &elem_count,
482 NULL, 0);
483 if (!len || (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED &&
484 elem_count > iface->ema_max_periodicity))
485 goto fail;
486
487 elem = os_zalloc(len);
488 if (!elem)
489 goto fail;
490
491 elem_offset = os_zalloc(elem_count * sizeof(u8 *));
492 if (!elem_offset)
493 goto fail;
494
495 end = hostapd_eid_mbssid(tx_bss, elem, elem + len, WLAN_FC_STYPE_BEACON,
496 elem_count, elem_offset, NULL, 0);
497
498 params->mbssid_tx_iface = tx_bss->conf->iface;
499 params->mbssid_index = hostapd_mbssid_get_bss_index(hapd);
500 params->mbssid_elem = elem;
501 params->mbssid_elem_len = end - elem;
502 params->mbssid_elem_count = elem_count;
503 params->mbssid_elem_offset = elem_offset;
504 if (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED)
505 params->ema = true;
506
507 return 0;
508
509fail:
510 os_free(elem);
511 wpa_printf(MSG_ERROR, "MBSSID: Configuration failed");
512 return -1;
513}
514
515
516static u8 * hostapd_eid_mbssid_config(struct hostapd_data *hapd, u8 *eid,
517 u8 mbssid_elem_count)
518{
519 struct hostapd_iface *iface = hapd->iface;
520
521 if (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED) {
522 *eid++ = WLAN_EID_EXTENSION;
523 *eid++ = 3;
524 *eid++ = WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION;
525 *eid++ = iface->num_bss;
526 *eid++ = mbssid_elem_count;
527 }
528
529 return eid;
530}
531
532
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800533static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800534 const struct ieee80211_mgmt *req,
Sunil8cd6f4d2022-06-28 18:40:46 +0000535 int is_p2p, size_t *resp_len,
Sunil Ravi036cec52023-03-29 11:35:17 -0700536 const u8 *known_bss, u8 known_bss_len)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800537{
538 struct ieee80211_mgmt *resp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800539 u8 *pos, *epos, *csa_pos;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800540 size_t buflen;
541
Sunil Ravi77d572f2023-01-17 23:58:31 +0000542 hapd = hostapd_mbssid_get_tx_bss(hapd);
543
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800544#define MAX_PROBERESP_LEN 768
545 buflen = MAX_PROBERESP_LEN;
546#ifdef CONFIG_WPS
547 if (hapd->wps_probe_resp_ie)
548 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
549#endif /* CONFIG_WPS */
550#ifdef CONFIG_P2P
551 if (hapd->p2p_probe_resp_ie)
552 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
553#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800554#ifdef CONFIG_FST
555 if (hapd->iface->fst_ies)
556 buflen += wpabuf_len(hapd->iface->fst_ies);
557#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700558 if (hapd->conf->vendor_elements)
559 buflen += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800560 if (hapd->conf->vendor_vht) {
561 buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
562 2 + sizeof(struct ieee80211_vht_operation);
563 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800564
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800565#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -0800566 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700567 buflen += 3 + sizeof(struct ieee80211_he_capabilities) +
Hai Shalom74f70d42019-02-11 14:42:39 -0800568 3 + sizeof(struct ieee80211_he_operation) +
Hai Shalom81f62d82019-07-22 12:10:00 -0700569 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
570 3 + sizeof(struct ieee80211_spatial_reuse);
Sunil Ravia04bd252022-05-02 22:54:18 -0700571 if (is_6ghz_op_class(hapd->iconf->op_class)) {
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700572 buflen += sizeof(struct ieee80211_he_6ghz_oper_info) +
573 3 + sizeof(struct ieee80211_he_6ghz_band_cap);
Sunil Ravia04bd252022-05-02 22:54:18 -0700574 /* An additional Transmit Power Envelope element for
575 * subordinate client */
576 if (hapd->iconf->he_6ghz_reg_pwr_type ==
577 HE_6GHZ_INDOOR_AP)
578 buflen += 4;
579 }
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800580 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700581#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800582
Sunil Ravia04bd252022-05-02 22:54:18 -0700583#ifdef CONFIG_IEEE80211BE
584 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
585 buflen += hostapd_eid_eht_capab_len(hapd, IEEE80211_MODE_AP);
586 buflen += 3 + sizeof(struct ieee80211_eht_operation);
Sunil Ravi036cec52023-03-29 11:35:17 -0700587 if (hapd->iconf->punct_bitmap)
588 buflen += EHT_OPER_DISABLED_SUBCHAN_BITMAP_SIZE;
Sunil Ravia04bd252022-05-02 22:54:18 -0700589 }
590#endif /* CONFIG_IEEE80211BE */
591
Sunil Ravi77d572f2023-01-17 23:58:31 +0000592 buflen += hostapd_eid_mbssid_len(hapd, WLAN_FC_STYPE_PROBE_RESP, NULL,
593 known_bss, known_bss_len);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800594 buflen += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_PROBE_RESP);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800595 buflen += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700596 buflen += hostapd_eid_owe_trans_len(hapd);
Hai Shalomfdcde762020-04-02 11:19:20 -0700597 buflen += hostapd_eid_dpp_cc_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800598
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800599 resp = os_zalloc(buflen);
600 if (resp == NULL)
601 return NULL;
602
603 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
604
605 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
606 WLAN_FC_STYPE_PROBE_RESP);
Sunil Ravi036cec52023-03-29 11:35:17 -0700607 /* Unicast the response to all requests on bands other than 6 GHz. For
608 * the 6 GHz, unicast is used only if the actual SSID is not included in
609 * the Beacon frames. Otherwise, broadcast response is used per IEEE
610 * Std 802.11ax-2021, 26.17.2.3.2. Broadcast address is also used for
611 * the Probe Response frame template for the unsolicited (i.e., not as
612 * a response to a specific request) case. */
613 if (req && (!is_6ghz_op_class(hapd->iconf->op_class) ||
614 hapd->conf->ignore_broadcast_ssid))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800615 os_memcpy(resp->da, req->sa, ETH_ALEN);
Sunil Ravi036cec52023-03-29 11:35:17 -0700616 else
Sunil8cd6f4d2022-06-28 18:40:46 +0000617 os_memset(resp->da, 0xff, ETH_ALEN);
618
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800619 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
620
621 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
622 resp->u.probe_resp.beacon_int =
623 host_to_le16(hapd->iconf->beacon_int);
624
625 /* hardware or low-level driver will setup seq_ctrl and timestamp */
626 resp->u.probe_resp.capab_info =
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700627 host_to_le16(hostapd_own_capab_info(hapd));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800628
629 pos = resp->u.probe_resp.variable;
630 *pos++ = WLAN_EID_SSID;
631 *pos++ = hapd->conf->ssid.ssid_len;
632 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
633 pos += hapd->conf->ssid.ssid_len;
634
635 /* Supported rates */
636 pos = hostapd_eid_supp_rates(hapd, pos);
637
638 /* DS Params */
639 pos = hostapd_eid_ds_params(hapd, pos);
640
641 pos = hostapd_eid_country(hapd, pos, epos - pos);
642
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800643 /* Power Constraint element */
644 pos = hostapd_eid_pwr_constraint(hapd, pos);
645
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800646 /* CSA IE */
647 csa_pos = hostapd_eid_csa(hapd, pos);
648 if (csa_pos != pos)
649 hapd->cs_c_off_proberesp = csa_pos - (u8 *) resp - 1;
650 pos = csa_pos;
651
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800652 /* ERP Information element */
653 pos = hostapd_eid_erp_info(hapd, pos);
654
655 /* Extended supported rates */
656 pos = hostapd_eid_ext_supp_rates(hapd, pos);
657
Hai Shalomfdcde762020-04-02 11:19:20 -0700658 pos = hostapd_get_rsne(hapd, pos, epos - pos);
Dmitry Shmidt051af732013-10-22 13:52:46 -0700659 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000660 pos = hostapd_eid_mbssid(hapd, pos, epos, WLAN_FC_STYPE_PROBE_RESP, 0,
661 NULL, known_bss, known_bss_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800662 pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700663 pos = hostapd_get_mde(hapd, pos, epos - pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800664
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800665 /* eCSA IE */
666 csa_pos = hostapd_eid_ecsa(hapd, pos);
667 if (csa_pos != pos)
668 hapd->cs_c_off_ecsa_proberesp = csa_pos - (u8 *) resp - 1;
669 pos = csa_pos;
670
671 pos = hostapd_eid_supported_op_classes(hapd, pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800672 pos = hostapd_eid_ht_capabilities(hapd, pos);
673 pos = hostapd_eid_ht_operation(hapd, pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800674
Sunil Ravi77d572f2023-01-17 23:58:31 +0000675 /* Probe Response frames always include all non-TX profiles except
676 * when a list of known BSSes is included in the Probe Request frame. */
677 pos = hostapd_eid_ext_capab(hapd, pos,
678 hapd->iconf->mbssid >= MBSSID_ENABLED &&
679 !known_bss_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800680
681 pos = hostapd_eid_time_adv(hapd, pos);
682 pos = hostapd_eid_time_zone(hapd, pos);
683
684 pos = hostapd_eid_interworking(hapd, pos);
685 pos = hostapd_eid_adv_proto(hapd, pos);
686 pos = hostapd_eid_roaming_consortium(hapd, pos);
687
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800688#ifdef CONFIG_FST
689 if (hapd->iface->fst_ies) {
690 os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies),
691 wpabuf_len(hapd->iface->fst_ies));
692 pos += wpabuf_len(hapd->iface->fst_ies);
693 }
694#endif /* CONFIG_FST */
695
Dmitry Shmidt04949592012-07-19 12:16:46 -0700696#ifdef CONFIG_IEEE80211AC
Hai Shalomc3565922019-10-28 11:58:20 -0700697 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
698 !is_6ghz_op_class(hapd->iconf->op_class)) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700699 pos = hostapd_eid_vht_capabilities(hapd, pos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800700 pos = hostapd_eid_vht_operation(hapd, pos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800701 pos = hostapd_eid_txpower_envelope(hapd, pos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800702 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800703#endif /* CONFIG_IEEE80211AC */
704
Hai Shalom60840252021-02-19 19:02:11 -0800705#ifdef CONFIG_IEEE80211AX
706 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax &&
707 is_6ghz_op_class(hapd->iconf->op_class))
708 pos = hostapd_eid_txpower_envelope(hapd, pos);
709#endif /* CONFIG_IEEE80211AX */
710
Hai Shaloma20dcd72022-02-04 13:43:00 -0800711 pos = hostapd_eid_wb_chsw_wrapper(hapd, pos);
Hai Shalom899fcc72020-10-19 14:38:18 -0700712
Hai Shaloma20dcd72022-02-04 13:43:00 -0800713 pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_PROBE_RESP);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800714 pos = hostapd_eid_fils_indic(hapd, pos, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -0700715 pos = hostapd_get_rsnxe(hapd, pos, epos - pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800716
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700717#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -0800718 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700719 u8 *cca_pos;
720
Hai Shalom81f62d82019-07-22 12:10:00 -0700721 pos = hostapd_eid_he_capab(hapd, pos, IEEE80211_MODE_AP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700722 pos = hostapd_eid_he_operation(hapd, pos);
Sunil Ravia04bd252022-05-02 22:54:18 -0700723
724 /* BSS Color Change Announcement element */
725 cca_pos = hostapd_eid_cca(hapd, pos);
726 if (cca_pos != pos)
727 hapd->cca_c_off_proberesp = cca_pos - (u8 *) resp - 2;
728 pos = cca_pos;
729
Hai Shalom81f62d82019-07-22 12:10:00 -0700730 pos = hostapd_eid_spatial_reuse(hapd, pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700731 pos = hostapd_eid_he_mu_edca_parameter_set(hapd, pos);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700732 pos = hostapd_eid_he_6ghz_band_cap(hapd, pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700733 }
734#endif /* CONFIG_IEEE80211AX */
735
Sunil Ravia04bd252022-05-02 22:54:18 -0700736#ifdef CONFIG_IEEE80211BE
737 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
738 pos = hostapd_eid_eht_capab(hapd, pos, IEEE80211_MODE_AP);
739 pos = hostapd_eid_eht_operation(hapd, pos);
740 }
741#endif /* CONFIG_IEEE80211BE */
742
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800743#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800744 if (hapd->conf->vendor_vht)
745 pos = hostapd_eid_vendor_vht(hapd, pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700746#endif /* CONFIG_IEEE80211AC */
747
Hai Shalomfdcde762020-04-02 11:19:20 -0700748 /* WPA / OSEN */
749 pos = hostapd_get_wpa_ie(hapd, pos, epos - pos);
750 pos = hostapd_get_osen_ie(hapd, pos, epos - pos);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800751
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800752 /* Wi-Fi Alliance WMM */
753 pos = hostapd_eid_wmm(hapd, pos);
754
755#ifdef CONFIG_WPS
756 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
757 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
758 wpabuf_len(hapd->wps_probe_resp_ie));
759 pos += wpabuf_len(hapd->wps_probe_resp_ie);
760 }
761#endif /* CONFIG_WPS */
762
763#ifdef CONFIG_P2P
764 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
765 hapd->p2p_probe_resp_ie) {
766 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
767 wpabuf_len(hapd->p2p_probe_resp_ie));
768 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
769 }
770#endif /* CONFIG_P2P */
771#ifdef CONFIG_P2P_MANAGER
772 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
773 P2P_MANAGE)
774 pos = hostapd_eid_p2p_manage(hapd, pos);
775#endif /* CONFIG_P2P_MANAGER */
776
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700777#ifdef CONFIG_HS20
778 pos = hostapd_eid_hs20_indication(hapd, pos);
779#endif /* CONFIG_HS20 */
780
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800781 pos = hostapd_eid_mbo(hapd, pos, (u8 *) resp + buflen - pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700782 pos = hostapd_eid_owe_trans(hapd, pos, (u8 *) resp + buflen - pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700783 pos = hostapd_eid_dpp_cc(hapd, pos, (u8 *) resp + buflen - pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800784
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700785 if (hapd->conf->vendor_elements) {
786 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
787 wpabuf_len(hapd->conf->vendor_elements));
788 pos += wpabuf_len(hapd->conf->vendor_elements);
789 }
790
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800791 *resp_len = pos - (u8 *) resp;
792 return (u8 *) resp;
793}
794
795
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800796enum ssid_match_result {
797 NO_SSID_MATCH,
798 EXACT_SSID_MATCH,
Hai Shaloma20dcd72022-02-04 13:43:00 -0800799 WILDCARD_SSID_MATCH,
800 CO_LOCATED_SSID_MATCH,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800801};
802
803static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
804 const u8 *ssid, size_t ssid_len,
805 const u8 *ssid_list,
Hai Shalomfdcde762020-04-02 11:19:20 -0700806 size_t ssid_list_len,
807 const u8 *short_ssid_list,
808 size_t short_ssid_list_len)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800809{
810 const u8 *pos, *end;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800811 struct hostapd_iface *iface = hapd->iface;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800812 int wildcard = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800813 size_t i, j;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800814
815 if (ssid_len == 0)
816 wildcard = 1;
817 if (ssid_len == hapd->conf->ssid.ssid_len &&
818 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
819 return EXACT_SSID_MATCH;
820
Hai Shalomfdcde762020-04-02 11:19:20 -0700821 if (ssid_list) {
822 pos = ssid_list;
823 end = ssid_list + ssid_list_len;
824 while (end - pos >= 2) {
825 if (2 + pos[1] > end - pos)
826 break;
827 if (pos[1] == 0)
828 wildcard = 1;
829 if (pos[1] == hapd->conf->ssid.ssid_len &&
830 os_memcmp(pos + 2, hapd->conf->ssid.ssid,
831 pos[1]) == 0)
832 return EXACT_SSID_MATCH;
833 pos += 2 + pos[1];
834 }
835 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800836
Hai Shalomfdcde762020-04-02 11:19:20 -0700837 if (short_ssid_list) {
838 pos = short_ssid_list;
839 end = short_ssid_list + short_ssid_list_len;
840 while (end - pos >= 4) {
841 if (hapd->conf->ssid.short_ssid == WPA_GET_LE32(pos))
842 return EXACT_SSID_MATCH;
843 pos += 4;
844 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800845 }
846
Hai Shaloma20dcd72022-02-04 13:43:00 -0800847 if (wildcard)
848 return WILDCARD_SSID_MATCH;
849
850 if (!iface->interfaces || iface->interfaces->count <= 1 ||
851 is_6ghz_op_class(hapd->iconf->op_class))
852 return NO_SSID_MATCH;
853
854 for (i = 0; i < iface->interfaces->count; i++) {
855 struct hostapd_iface *colocated;
856
857 colocated = iface->interfaces->iface[i];
858
859 if (colocated == iface ||
860 !is_6ghz_op_class(colocated->conf->op_class))
861 continue;
862
863 for (j = 0; j < colocated->num_bss; j++) {
864 struct hostapd_bss_config *conf;
865
866 conf = colocated->bss[j]->conf;
867 if (ssid_len == conf->ssid.ssid_len &&
868 os_memcmp(ssid, conf->ssid.ssid, ssid_len) == 0)
869 return CO_LOCATED_SSID_MATCH;
870 }
871 }
872
873 return NO_SSID_MATCH;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800874}
875
876
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800877void sta_track_expire(struct hostapd_iface *iface, int force)
878{
879 struct os_reltime now;
880 struct hostapd_sta_info *info;
881
882 if (!iface->num_sta_seen)
883 return;
884
885 os_get_reltime(&now);
886 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
887 list))) {
888 if (!force &&
889 !os_reltime_expired(&now, &info->last_seen,
890 iface->conf->track_sta_max_age))
891 break;
892 force = 0;
893
894 wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
895 MACSTR, iface->bss[0]->conf->iface,
896 MAC2STR(info->addr));
897 dl_list_del(&info->list);
898 iface->num_sta_seen--;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700899 sta_track_del(info);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800900 }
901}
902
903
904static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
905 const u8 *addr)
906{
907 struct hostapd_sta_info *info;
908
909 dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
910 if (os_memcmp(addr, info->addr, ETH_ALEN) == 0)
911 return info;
912
913 return NULL;
914}
915
916
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800917void sta_track_add(struct hostapd_iface *iface, const u8 *addr, int ssi_signal)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800918{
919 struct hostapd_sta_info *info;
920
921 info = sta_track_get(iface, addr);
922 if (info) {
923 /* Move the most recent entry to the end of the list */
924 dl_list_del(&info->list);
925 dl_list_add_tail(&iface->sta_seen, &info->list);
926 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800927 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800928 return;
929 }
930
931 /* Add a new entry */
932 info = os_zalloc(sizeof(*info));
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700933 if (info == NULL)
934 return;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800935 os_memcpy(info->addr, addr, ETH_ALEN);
936 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800937 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800938
939 if (iface->num_sta_seen >= iface->conf->track_sta_max_num) {
940 /* Expire oldest entry to make room for a new one */
941 sta_track_expire(iface, 1);
942 }
943
944 wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
945 MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr));
946 dl_list_add_tail(&iface->sta_seen, &info->list);
947 iface->num_sta_seen++;
948}
949
950
951struct hostapd_data *
952sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
953 const char *ifname)
954{
955 struct hapd_interfaces *interfaces = iface->interfaces;
956 size_t i, j;
957
958 for (i = 0; i < interfaces->count; i++) {
959 struct hostapd_data *hapd = NULL;
960
961 iface = interfaces->iface[i];
962 for (j = 0; j < iface->num_bss; j++) {
963 hapd = iface->bss[j];
964 if (os_strcmp(ifname, hapd->conf->iface) == 0)
965 break;
966 hapd = NULL;
967 }
968
969 if (hapd && sta_track_get(iface, addr))
970 return hapd;
971 }
972
973 return NULL;
974}
975
976
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700977#ifdef CONFIG_TAXONOMY
978void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr,
979 struct wpabuf **probe_ie_taxonomy)
980{
981 struct hostapd_sta_info *info;
982
983 info = sta_track_get(iface, addr);
984 if (!info)
985 return;
986
987 wpabuf_free(*probe_ie_taxonomy);
988 *probe_ie_taxonomy = info->probe_ie_taxonomy;
989 info->probe_ie_taxonomy = NULL;
990}
991#endif /* CONFIG_TAXONOMY */
992
993
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700994void handle_probe_req(struct hostapd_data *hapd,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700995 const struct ieee80211_mgmt *mgmt, size_t len,
996 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700997{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800998 u8 *resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700999 struct ieee802_11_elems elems;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001000 const u8 *ie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001001 size_t ie_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001002 size_t i, resp_len;
1003 int noack;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001004 enum ssid_match_result res;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001005 int ret;
1006 u16 csa_offs[2];
1007 size_t csa_offs_len;
Hai Shalomfdcde762020-04-02 11:19:20 -07001008 struct radius_sta rad_info;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001009
Hai Shalom60840252021-02-19 19:02:11 -08001010 if (hapd->iconf->rssi_ignore_probe_request && ssi_signal &&
1011 ssi_signal < hapd->iconf->rssi_ignore_probe_request)
1012 return;
1013
Dmitry Shmidte4663042016-04-04 10:07:49 -07001014 if (len < IEEE80211_HDRLEN)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001015 return;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001016 ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001017 if (hapd->iconf->track_sta_max_num)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001018 sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
Dmitry Shmidte4663042016-04-04 10:07:49 -07001019 ie_len = len - IEEE80211_HDRLEN;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001020
Hai Shalomfdcde762020-04-02 11:19:20 -07001021 ret = hostapd_allowed_address(hapd, mgmt->sa, (const u8 *) mgmt, len,
1022 &rad_info, 1);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001023 if (ret == HOSTAPD_ACL_REJECT) {
1024 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
1025 "Ignore Probe Request frame from " MACSTR
1026 " due to ACL reject ", MAC2STR(mgmt->sa));
1027 return;
1028 }
1029
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001030 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
1031 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001032 mgmt->sa, mgmt->da, mgmt->bssid,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001033 ie, ie_len, ssi_signal) > 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001034 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001035
Hai Shalom74f70d42019-02-11 14:42:39 -08001036 if (!hapd->conf->send_probe_response)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001037 return;
1038
1039 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
1040 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
1041 MAC2STR(mgmt->sa));
1042 return;
1043 }
1044
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001045 if ((!elems.ssid || !elems.supp_rates)) {
1046 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
1047 "without SSID or supported rates element",
1048 MAC2STR(mgmt->sa));
1049 return;
1050 }
1051
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001052 /*
1053 * No need to reply if the Probe Request frame was sent on an adjacent
1054 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
1055 * AP with dot11RadioMeasurementActivated set to true, but strictly
1056 * speaking does not allow such ignoring of Probe Request frames if
1057 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
1058 * number of unnecessary Probe Response frames for cases where the STA
1059 * is less likely to see them (Probe Request frame sent on a
1060 * neighboring, but partially overlapping, channel).
1061 */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001062 if (elems.ds_params &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001063 hapd->iface->current_mode &&
1064 (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
1065 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
1066 hapd->iconf->channel != elems.ds_params[0]) {
1067 wpa_printf(MSG_DEBUG,
1068 "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
1069 hapd->iconf->channel, elems.ds_params[0]);
1070 return;
1071 }
1072
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001073#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001074 if (hapd->p2p && hapd->p2p_group && elems.wps_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001075 struct wpabuf *wps;
1076 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
1077 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
1078 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
1079 "due to mismatch with Requested Device "
1080 "Type");
1081 wpabuf_free(wps);
1082 return;
1083 }
1084 wpabuf_free(wps);
1085 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001086
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001087 if (hapd->p2p && hapd->p2p_group && elems.p2p) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001088 struct wpabuf *p2p;
1089 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
1090 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
1091 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
1092 "due to mismatch with Device ID");
1093 wpabuf_free(p2p);
1094 return;
1095 }
1096 wpabuf_free(p2p);
1097 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001098#endif /* CONFIG_P2P */
1099
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001100 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
Hai Shalomfdcde762020-04-02 11:19:20 -07001101 elems.ssid_list_len == 0 && elems.short_ssid_list_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001102 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
1103 "broadcast SSID ignored", MAC2STR(mgmt->sa));
1104 return;
1105 }
1106
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001107#ifdef CONFIG_P2P
1108 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1109 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
1110 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
1111 P2P_WILDCARD_SSID_LEN) == 0) {
1112 /* Process P2P Wildcard SSID like Wildcard SSID */
1113 elems.ssid_len = 0;
1114 }
1115#endif /* CONFIG_P2P */
1116
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001117#ifdef CONFIG_TAXONOMY
1118 {
1119 struct sta_info *sta;
1120 struct hostapd_sta_info *info;
1121
1122 if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) {
1123 taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len);
1124 } else if ((info = sta_track_get(hapd->iface,
1125 mgmt->sa)) != NULL) {
1126 taxonomy_hostapd_sta_info_probe_req(hapd, info,
1127 ie, ie_len);
1128 }
1129 }
1130#endif /* CONFIG_TAXONOMY */
1131
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001132 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
Hai Shalomfdcde762020-04-02 11:19:20 -07001133 elems.ssid_list, elems.ssid_list_len,
1134 elems.short_ssid_list, elems.short_ssid_list_len);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001135 if (res == NO_SSID_MATCH) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001136 if (!(mgmt->da[0] & 0x01)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001137 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001138 " for foreign SSID '%s' (DA " MACSTR ")%s",
Dmitry Shmidt3c479372014-02-04 10:50:36 -08001139 MAC2STR(mgmt->sa),
1140 wpa_ssid_txt(elems.ssid, elems.ssid_len),
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001141 MAC2STR(mgmt->da),
1142 elems.ssid_list ? " (SSID list)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001143 }
1144 return;
1145 }
1146
Hai Shalomfdcde762020-04-02 11:19:20 -07001147 if (hapd->conf->ignore_broadcast_ssid && res == WILDCARD_SSID_MATCH) {
1148 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
1149 "broadcast SSID ignored", MAC2STR(mgmt->sa));
1150 return;
1151 }
1152
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001153#ifdef CONFIG_INTERWORKING
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -07001154 if (hapd->conf->interworking &&
1155 elems.interworking && elems.interworking_len >= 1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001156 u8 ant = elems.interworking[0] & 0x0f;
1157 if (ant != INTERWORKING_ANT_WILDCARD &&
1158 ant != hapd->conf->access_network_type) {
1159 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
1160 " for mismatching ANT %u ignored",
1161 MAC2STR(mgmt->sa), ant);
1162 return;
1163 }
1164 }
1165
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -07001166 if (hapd->conf->interworking && elems.interworking &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001167 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
1168 const u8 *hessid;
1169 if (elems.interworking_len == 7)
1170 hessid = elems.interworking + 1;
1171 else
1172 hessid = elems.interworking + 1 + 2;
1173 if (!is_broadcast_ether_addr(hessid) &&
1174 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
1175 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
1176 " for mismatching HESSID " MACSTR
1177 " ignored",
1178 MAC2STR(mgmt->sa), MAC2STR(hessid));
1179 return;
1180 }
1181 }
1182#endif /* CONFIG_INTERWORKING */
1183
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001184#ifdef CONFIG_P2P
1185 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1186 supp_rates_11b_only(&elems)) {
1187 /* Indicates support for 11b rates only */
1188 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
1189 MACSTR " with only 802.11b rates",
1190 MAC2STR(mgmt->sa));
1191 return;
1192 }
1193#endif /* CONFIG_P2P */
1194
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001195 /* TODO: verify that supp_rates contains at least one matching rate
1196 * with AP configuration */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001197
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001198 if (hapd->conf->no_probe_resp_if_seen_on &&
1199 is_multicast_ether_addr(mgmt->da) &&
1200 is_multicast_ether_addr(mgmt->bssid) &&
1201 sta_track_seen_on(hapd->iface, mgmt->sa,
1202 hapd->conf->no_probe_resp_if_seen_on)) {
1203 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1204 " since STA has been seen on %s",
1205 hapd->conf->iface, MAC2STR(mgmt->sa),
1206 hapd->conf->no_probe_resp_if_seen_on);
1207 return;
1208 }
1209
1210 if (hapd->conf->no_probe_resp_if_max_sta &&
1211 is_multicast_ether_addr(mgmt->da) &&
1212 is_multicast_ether_addr(mgmt->bssid) &&
1213 hapd->num_sta >= hapd->conf->max_num_sta &&
1214 !ap_get_sta(hapd, mgmt->sa)) {
1215 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1216 " since no room for additional STA",
1217 hapd->conf->iface, MAC2STR(mgmt->sa));
1218 return;
1219 }
1220
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001221#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001222 if (hapd->iconf->ignore_probe_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001223 drand48() < hapd->iconf->ignore_probe_probability) {
1224 wpa_printf(MSG_INFO,
1225 "TESTING: ignoring probe request from " MACSTR,
1226 MAC2STR(mgmt->sa));
1227 return;
1228 }
1229#endif /* CONFIG_TESTING_OPTIONS */
1230
Sunil Ravi77d572f2023-01-17 23:58:31 +00001231 /* Do not send Probe Response frame from a non-transmitting multiple
1232 * BSSID profile unless the Probe Request frame is directed at that
1233 * particular BSS. */
1234 if (hapd != hostapd_mbssid_get_tx_bss(hapd) && res != EXACT_SSID_MATCH)
1235 return;
1236
Roshan Pius3a1667e2018-07-03 15:17:14 -07001237 wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, RX_PROBE_REQUEST "sa=" MACSTR
1238 " signal=%d", MAC2STR(mgmt->sa), ssi_signal);
1239
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001240 resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL,
Sunil Ravi036cec52023-03-29 11:35:17 -07001241 &resp_len, elems.mbssid_known_bss,
Sunil Ravi77d572f2023-01-17 23:58:31 +00001242 elems.mbssid_known_bss_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001243 if (resp == NULL)
1244 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001245
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001246 /*
1247 * If this is a broadcast probe request, apply no ack policy to avoid
1248 * excessive retries.
1249 */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001250 noack = !!(res == WILDCARD_SSID_MATCH &&
1251 is_broadcast_ether_addr(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001252
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001253 csa_offs_len = 0;
1254 if (hapd->csa_in_progress) {
1255 if (hapd->cs_c_off_proberesp)
1256 csa_offs[csa_offs_len++] =
1257 hapd->cs_c_off_proberesp;
1258
1259 if (hapd->cs_c_off_ecsa_proberesp)
1260 csa_offs[csa_offs_len++] =
1261 hapd->cs_c_off_ecsa_proberesp;
1262 }
1263
Sunil Ravi77d572f2023-01-17 23:58:31 +00001264 ret = hostapd_drv_send_mlme(hostapd_mbssid_get_tx_bss(hapd), resp,
1265 resp_len, noack,
Hai Shalomfdcde762020-04-02 11:19:20 -07001266 csa_offs_len ? csa_offs : NULL,
1267 csa_offs_len, 0);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001268
1269 if (ret < 0)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001270 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001271
1272 os_free(resp);
1273
1274 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
1275 "SSID", MAC2STR(mgmt->sa),
1276 elems.ssid_len == 0 ? "broadcast" : "our");
1277}
1278
1279
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001280static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
1281 size_t *resp_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001282{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001283 /* check probe response offloading caps and print warnings */
1284 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
1285 return NULL;
1286
1287#ifdef CONFIG_WPS
1288 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
1289 (!(hapd->iface->probe_resp_offloads &
1290 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
1291 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
1292 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
1293 "Probe Response while not supporting this");
1294#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001295
1296#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001297 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
1298 !(hapd->iface->probe_resp_offloads &
1299 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
1300 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
1301 "Probe Response while not supporting this");
1302#endif /* CONFIG_P2P */
1303
1304 if (hapd->conf->interworking &&
1305 !(hapd->iface->probe_resp_offloads &
1306 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
1307 wpa_printf(MSG_WARNING, "Device is trying to offload "
1308 "Interworking Probe Response while not supporting "
1309 "this");
1310
1311 /* Generate a Probe Response template for the non-P2P case */
Sunil Ravi036cec52023-03-29 11:35:17 -07001312 return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len, NULL, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001313}
1314
1315#endif /* NEED_AP_MLME */
1316
1317
Hai Shalom60840252021-02-19 19:02:11 -08001318#ifdef CONFIG_IEEE80211AX
1319/* Unsolicited broadcast Probe Response transmission, 6 GHz only */
1320static u8 * hostapd_unsol_bcast_probe_resp(struct hostapd_data *hapd,
1321 struct wpa_driver_ap_params *params)
1322{
1323 if (!is_6ghz_op_class(hapd->iconf->op_class))
1324 return NULL;
1325
1326 params->unsol_bcast_probe_resp_interval =
1327 hapd->conf->unsol_bcast_probe_resp_interval;
1328
1329 return hostapd_gen_probe_resp(hapd, NULL, 0,
Sunil8cd6f4d2022-06-28 18:40:46 +00001330 &params->unsol_bcast_probe_resp_tmpl_len,
Sunil Ravi036cec52023-03-29 11:35:17 -07001331 NULL, 0);
Hai Shalom60840252021-02-19 19:02:11 -08001332}
1333#endif /* CONFIG_IEEE80211AX */
1334
1335
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001336void sta_track_del(struct hostapd_sta_info *info)
1337{
1338#ifdef CONFIG_TAXONOMY
1339 wpabuf_free(info->probe_ie_taxonomy);
1340 info->probe_ie_taxonomy = NULL;
1341#endif /* CONFIG_TAXONOMY */
1342 os_free(info);
1343}
1344
1345
Hai Shalom60840252021-02-19 19:02:11 -08001346#ifdef CONFIG_FILS
1347
1348static u16 hostapd_fils_discovery_cap(struct hostapd_data *hapd)
1349{
1350 u16 cap_info, phy_index = 0;
1351 u8 chwidth = FD_CAP_BSS_CHWIDTH_20, mcs_nss_size = 4;
1352 struct hostapd_hw_modes *mode = hapd->iface->current_mode;
1353
1354 cap_info = FD_CAP_ESS;
1355 if (hapd->conf->wpa)
1356 cap_info |= FD_CAP_PRIVACY;
1357
1358 if (is_6ghz_op_class(hapd->iconf->op_class)) {
1359 phy_index = FD_CAP_PHY_INDEX_HE;
1360
1361 switch (hapd->iconf->op_class) {
Sunil Ravi036cec52023-03-29 11:35:17 -07001362 case 137:
1363 chwidth = FD_CAP_BSS_CHWIDTH_320;
1364 break;
Hai Shalom60840252021-02-19 19:02:11 -08001365 case 135:
1366 mcs_nss_size += 4;
1367 /* fallthrough */
1368 case 134:
1369 mcs_nss_size += 4;
1370 chwidth = FD_CAP_BSS_CHWIDTH_160_80_80;
1371 break;
1372 case 133:
1373 chwidth = FD_CAP_BSS_CHWIDTH_80;
1374 break;
1375 case 132:
1376 chwidth = FD_CAP_BSS_CHWIDTH_40;
1377 break;
1378 }
1379 } else {
1380 switch (hostapd_get_oper_chwidth(hapd->iconf)) {
Sunil8cd6f4d2022-06-28 18:40:46 +00001381 case CONF_OPER_CHWIDTH_80P80MHZ:
Hai Shalom60840252021-02-19 19:02:11 -08001382 mcs_nss_size += 4;
1383 /* fallthrough */
Sunil8cd6f4d2022-06-28 18:40:46 +00001384 case CONF_OPER_CHWIDTH_160MHZ:
Hai Shalom60840252021-02-19 19:02:11 -08001385 mcs_nss_size += 4;
1386 chwidth = FD_CAP_BSS_CHWIDTH_160_80_80;
1387 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00001388 case CONF_OPER_CHWIDTH_80MHZ:
Hai Shalom60840252021-02-19 19:02:11 -08001389 chwidth = FD_CAP_BSS_CHWIDTH_80;
1390 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00001391 case CONF_OPER_CHWIDTH_USE_HT:
Hai Shalom60840252021-02-19 19:02:11 -08001392 if (hapd->iconf->secondary_channel)
1393 chwidth = FD_CAP_BSS_CHWIDTH_40;
1394 else
1395 chwidth = FD_CAP_BSS_CHWIDTH_20;
1396 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00001397 default:
1398 break;
Hai Shalom60840252021-02-19 19:02:11 -08001399 }
1400
1401#ifdef CONFIG_IEEE80211AX
1402 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax)
1403 phy_index = FD_CAP_PHY_INDEX_HE;
1404#endif /* CONFIG_IEEE80211AX */
1405#ifdef CONFIG_IEEE80211AC
1406 if (!phy_index &&
1407 hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac)
1408 phy_index = FD_CAP_PHY_INDEX_VHT;
1409#endif /* CONFIG_IEEE80211AC */
1410 if (!phy_index &&
1411 hapd->iconf->ieee80211n && !hapd->conf->disable_11n)
1412 phy_index = FD_CAP_PHY_INDEX_HT;
1413 }
1414
1415 cap_info |= phy_index << FD_CAP_PHY_INDEX_SHIFT;
1416 cap_info |= chwidth << FD_CAP_BSS_CHWIDTH_SHIFT;
1417
Sunil Ravi036cec52023-03-29 11:35:17 -07001418 if (mode && phy_index == FD_CAP_PHY_INDEX_HE) {
1419 const u8 *he_mcs = mode->he_capab[IEEE80211_MODE_AP].mcs;
Hai Shalom60840252021-02-19 19:02:11 -08001420 int i;
Sunil Ravi036cec52023-03-29 11:35:17 -07001421 u16 nss = 0, mcs[6];
1422
1423 os_memset(mcs, 0xffff, 6 * sizeof(u16));
1424
1425 if (mcs_nss_size == 4) {
1426 mcs[0] = WPA_GET_LE16(&he_mcs[0]);
1427 mcs[1] = WPA_GET_LE16(&he_mcs[2]);
1428 }
1429
1430 if (mcs_nss_size == 8) {
1431 mcs[2] = WPA_GET_LE16(&he_mcs[4]);
1432 mcs[3] = WPA_GET_LE16(&he_mcs[6]);
1433 }
1434
1435 if (mcs_nss_size == 12) {
1436 mcs[4] = WPA_GET_LE16(&he_mcs[8]);
1437 mcs[5] = WPA_GET_LE16(&he_mcs[10]);
1438 }
Hai Shalom60840252021-02-19 19:02:11 -08001439
1440 for (i = 0; i < HE_NSS_MAX_STREAMS; i++) {
1441 u16 nss_mask = 0x3 << (i * 2);
1442
Sunil Ravi036cec52023-03-29 11:35:17 -07001443 /*
1444 * If NSS values supported by RX and TX are different
1445 * then choose the smaller of the two as the maximum
1446 * supported NSS as that is the value supported by
1447 * both RX and TX.
1448 */
Hai Shalom60840252021-02-19 19:02:11 -08001449 if (mcs_nss_size == 4 &&
1450 (((mcs[0] & nss_mask) == nss_mask) ||
1451 ((mcs[1] & nss_mask) == nss_mask)))
1452 continue;
1453
1454 if (mcs_nss_size == 8 &&
1455 (((mcs[2] & nss_mask) == nss_mask) ||
1456 ((mcs[3] & nss_mask) == nss_mask)))
1457 continue;
1458
1459 if (mcs_nss_size == 12 &&
1460 (((mcs[4] & nss_mask) == nss_mask) ||
1461 ((mcs[5] & nss_mask) == nss_mask)))
1462 continue;
1463
1464 nss++;
1465 }
1466
1467 if (nss > 4)
1468 cap_info |= FD_CAP_NSS_5_8 << FD_CAP_NSS_SHIFT;
1469 else if (nss)
1470 cap_info |= (nss - 1) << FD_CAP_NSS_SHIFT;
1471 }
1472
1473 return cap_info;
1474}
1475
1476
1477static u8 * hostapd_gen_fils_discovery(struct hostapd_data *hapd, size_t *len)
1478{
1479 struct ieee80211_mgmt *head;
1480 const u8 *mobility_domain;
1481 u8 *pos, *length_pos, buf[200];
1482 u16 ctl = 0;
1483 u8 fd_rsn_info[5];
1484 size_t total_len, buf_len;
1485
1486 total_len = 24 + 2 + 12;
1487
1488 /* FILS Discovery Frame Control */
1489 ctl = (sizeof(hapd->conf->ssid.short_ssid) - 1) |
1490 FD_FRAME_CTL_SHORT_SSID_PRESENT |
1491 FD_FRAME_CTL_LENGTH_PRESENT |
1492 FD_FRAME_CTL_CAP_PRESENT;
1493 total_len += 4 + 1 + 2;
1494
1495 /* Check for optional subfields and calculate length */
1496 if (wpa_auth_write_fd_rsn_info(hapd->wpa_auth, fd_rsn_info)) {
1497 ctl |= FD_FRAME_CTL_RSN_INFO_PRESENT;
1498 total_len += sizeof(fd_rsn_info);
1499 }
1500
1501 mobility_domain = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN);
1502 if (mobility_domain) {
1503 ctl |= FD_FRAME_CTL_MD_PRESENT;
1504 total_len += 3;
1505 }
1506
Hai Shaloma20dcd72022-02-04 13:43:00 -08001507 total_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_ACTION);
1508
Hai Shalom60840252021-02-19 19:02:11 -08001509 pos = hostapd_eid_fils_indic(hapd, buf, 0);
1510 buf_len = pos - buf;
1511 total_len += buf_len;
1512
Sunil Ravia04bd252022-05-02 22:54:18 -07001513#ifdef CONFIG_IEEE80211AX
1514 /* Transmit Power Envelope element(s) */
1515 if (is_6ghz_op_class(hapd->iconf->op_class)) {
1516 total_len += 4;
1517 if (hapd->iconf->he_6ghz_reg_pwr_type == HE_6GHZ_INDOOR_AP)
1518 total_len += 4;
1519 }
1520#endif /* CONFIG_IEEE80211AX */
1521
Hai Shalom60840252021-02-19 19:02:11 -08001522 head = os_zalloc(total_len);
1523 if (!head)
1524 return NULL;
1525
1526 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1527 WLAN_FC_STYPE_ACTION);
1528 os_memset(head->da, 0xff, ETH_ALEN);
1529 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1530 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1531
1532 head->u.action.category = WLAN_ACTION_PUBLIC;
1533 head->u.action.u.public_action.action = WLAN_PA_FILS_DISCOVERY;
1534
1535 pos = &head->u.action.u.public_action.variable[0];
1536
1537 /* FILS Discovery Information field */
1538
1539 /* FILS Discovery Frame Control */
1540 WPA_PUT_LE16(pos, ctl);
1541 pos += 2;
1542
1543 /* Hardware or low-level driver will fill in the Timestamp value */
1544 pos += 8;
1545
1546 /* Beacon Interval */
1547 WPA_PUT_LE16(pos, hapd->iconf->beacon_int);
1548 pos += 2;
1549
1550 /* Short SSID */
1551 WPA_PUT_LE32(pos, hapd->conf->ssid.short_ssid);
1552 pos += sizeof(hapd->conf->ssid.short_ssid);
1553
1554 /* Store position of FILS discovery information element Length field */
1555 length_pos = pos++;
1556
1557 /* FD Capability */
1558 WPA_PUT_LE16(pos, hostapd_fils_discovery_cap(hapd));
1559 pos += 2;
1560
1561 /* Operating Class - not present */
1562
1563 /* Primary Channel - not present */
1564
1565 /* AP Configuration Sequence Number - not present */
1566
1567 /* Access Network Options - not present */
1568
1569 /* FD RSN Information */
1570 if (ctl & FD_FRAME_CTL_RSN_INFO_PRESENT) {
1571 os_memcpy(pos, fd_rsn_info, sizeof(fd_rsn_info));
1572 pos += sizeof(fd_rsn_info);
1573 }
1574
1575 /* Channel Center Frequency Segment 1 - not present */
1576
1577 /* Mobility Domain */
1578 if (ctl & FD_FRAME_CTL_MD_PRESENT) {
1579 os_memcpy(pos, &mobility_domain[2], 3);
1580 pos += 3;
1581 }
1582
1583 /* Fill in the Length field value */
1584 *length_pos = pos - (length_pos + 1);
1585
Hai Shaloma20dcd72022-02-04 13:43:00 -08001586 pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_ACTION);
1587
Hai Shalom60840252021-02-19 19:02:11 -08001588 /* FILS Indication element */
1589 if (buf_len) {
1590 os_memcpy(pos, buf, buf_len);
1591 pos += buf_len;
1592 }
1593
Sunil Ravia04bd252022-05-02 22:54:18 -07001594 if (is_6ghz_op_class(hapd->iconf->op_class))
1595 pos = hostapd_eid_txpower_envelope(hapd, pos);
1596
Hai Shalom60840252021-02-19 19:02:11 -08001597 *len = pos - (u8 *) head;
1598 wpa_hexdump(MSG_DEBUG, "FILS Discovery frame template",
1599 head, pos - (u8 *) head);
1600 return (u8 *) head;
1601}
1602
1603
1604/* Configure FILS Discovery frame transmission parameters */
1605static u8 * hostapd_fils_discovery(struct hostapd_data *hapd,
1606 struct wpa_driver_ap_params *params)
1607{
1608 params->fd_max_int = hapd->conf->fils_discovery_max_int;
1609 if (is_6ghz_op_class(hapd->iconf->op_class) &&
1610 params->fd_max_int > FD_MAX_INTERVAL_6GHZ)
1611 params->fd_max_int = FD_MAX_INTERVAL_6GHZ;
1612
1613 params->fd_min_int = hapd->conf->fils_discovery_min_int;
1614 if (params->fd_min_int > params->fd_max_int)
1615 params->fd_min_int = params->fd_max_int;
1616
1617 if (params->fd_max_int)
1618 return hostapd_gen_fils_discovery(hapd,
1619 &params->fd_frame_tmpl_len);
1620
1621 return NULL;
1622}
1623
1624#endif /* CONFIG_FILS */
1625
1626
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001627int ieee802_11_build_ap_params(struct hostapd_data *hapd,
1628 struct wpa_driver_ap_params *params)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001629{
1630 struct ieee80211_mgmt *head = NULL;
1631 u8 *tail = NULL;
1632 size_t head_len = 0, tail_len = 0;
1633 u8 *resp = NULL;
1634 size_t resp_len = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001635#ifdef NEED_AP_MLME
1636 u16 capab_info;
Hai Shalomfdcde762020-04-02 11:19:20 -07001637 u8 *pos, *tailpos, *tailend, *csa_pos;
Sunil Ravi77d572f2023-01-17 23:58:31 +00001638 bool complete = false;
1639#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001640
Sunil Ravi77d572f2023-01-17 23:58:31 +00001641 os_memset(params, 0, sizeof(*params));
1642
1643#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001644#define BEACON_HEAD_BUF_SIZE 256
1645#define BEACON_TAIL_BUF_SIZE 512
1646 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
1647 tail_len = BEACON_TAIL_BUF_SIZE;
1648#ifdef CONFIG_WPS
1649 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
1650 tail_len += wpabuf_len(hapd->wps_beacon_ie);
1651#endif /* CONFIG_WPS */
1652#ifdef CONFIG_P2P
1653 if (hapd->p2p_beacon_ie)
1654 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
1655#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001656#ifdef CONFIG_FST
1657 if (hapd->iface->fst_ies)
1658 tail_len += wpabuf_len(hapd->iface->fst_ies);
1659#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001660 if (hapd->conf->vendor_elements)
1661 tail_len += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001662
1663#ifdef CONFIG_IEEE80211AC
1664 if (hapd->conf->vendor_vht) {
1665 tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
1666 2 + sizeof(struct ieee80211_vht_operation);
1667 }
1668#endif /* CONFIG_IEEE80211AC */
1669
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001670#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08001671 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001672 tail_len += 3 + sizeof(struct ieee80211_he_capabilities) +
Hai Shalom74f70d42019-02-11 14:42:39 -08001673 3 + sizeof(struct ieee80211_he_operation) +
Hai Shalom81f62d82019-07-22 12:10:00 -07001674 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
1675 3 + sizeof(struct ieee80211_spatial_reuse);
Sunil Ravia04bd252022-05-02 22:54:18 -07001676 if (is_6ghz_op_class(hapd->iconf->op_class)) {
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001677 tail_len += sizeof(struct ieee80211_he_6ghz_oper_info) +
1678 3 + sizeof(struct ieee80211_he_6ghz_band_cap);
Sunil Ravia04bd252022-05-02 22:54:18 -07001679 /* An additional Transmit Power Envelope element for
1680 * subordinate client */
1681 if (hapd->iconf->he_6ghz_reg_pwr_type ==
1682 HE_6GHZ_INDOOR_AP)
1683 tail_len += 4;
1684 }
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001685 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001686#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001687
Sunil Ravia04bd252022-05-02 22:54:18 -07001688#ifdef CONFIG_IEEE80211BE
1689 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
1690 tail_len += hostapd_eid_eht_capab_len(hapd, IEEE80211_MODE_AP);
1691 tail_len += 3 + sizeof(struct ieee80211_eht_operation);
Sunil Ravi036cec52023-03-29 11:35:17 -07001692 if (hapd->iconf->punct_bitmap)
1693 tail_len += EHT_OPER_DISABLED_SUBCHAN_BITMAP_SIZE;
Sunil Ravia04bd252022-05-02 22:54:18 -07001694 }
1695#endif /* CONFIG_IEEE80211BE */
1696
Sunil Ravi77d572f2023-01-17 23:58:31 +00001697 if (hapd->iconf->mbssid == ENHANCED_MBSSID_ENABLED &&
1698 hapd == hostapd_mbssid_get_tx_bss(hapd))
1699 tail_len += 5; /* Multiple BSSID Configuration element */
Hai Shaloma20dcd72022-02-04 13:43:00 -08001700 tail_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_BEACON);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001701 tail_len += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001702 tail_len += hostapd_eid_owe_trans_len(hapd);
Hai Shalomfdcde762020-04-02 11:19:20 -07001703 tail_len += hostapd_eid_dpp_cc_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001704
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001705 tailpos = tail = os_malloc(tail_len);
1706 if (head == NULL || tail == NULL) {
1707 wpa_printf(MSG_ERROR, "Failed to set beacon data");
1708 os_free(head);
1709 os_free(tail);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001710 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001711 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001712 tailend = tail + tail_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001713
1714 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1715 WLAN_FC_STYPE_BEACON);
1716 head->duration = host_to_le16(0);
1717 os_memset(head->da, 0xff, ETH_ALEN);
1718
1719 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1720 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1721 head->u.beacon.beacon_int =
1722 host_to_le16(hapd->iconf->beacon_int);
1723
1724 /* hardware or low-level driver will setup seq_ctrl and timestamp */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001725 capab_info = hostapd_own_capab_info(hapd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001726 head->u.beacon.capab_info = host_to_le16(capab_info);
1727 pos = &head->u.beacon.variable[0];
1728
1729 /* SSID */
1730 *pos++ = WLAN_EID_SSID;
1731 if (hapd->conf->ignore_broadcast_ssid == 2) {
1732 /* clear the data, but keep the correct length of the SSID */
1733 *pos++ = hapd->conf->ssid.ssid_len;
1734 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
1735 pos += hapd->conf->ssid.ssid_len;
1736 } else if (hapd->conf->ignore_broadcast_ssid) {
1737 *pos++ = 0; /* empty SSID */
1738 } else {
1739 *pos++ = hapd->conf->ssid.ssid_len;
1740 os_memcpy(pos, hapd->conf->ssid.ssid,
1741 hapd->conf->ssid.ssid_len);
1742 pos += hapd->conf->ssid.ssid_len;
1743 }
1744
1745 /* Supported rates */
1746 pos = hostapd_eid_supp_rates(hapd, pos);
1747
1748 /* DS Params */
1749 pos = hostapd_eid_ds_params(hapd, pos);
1750
1751 head_len = pos - (u8 *) head;
1752
Hai Shalomfdcde762020-04-02 11:19:20 -07001753 tailpos = hostapd_eid_country(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001754
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001755 /* Power Constraint element */
1756 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
1757
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001758 /* CSA IE */
1759 csa_pos = hostapd_eid_csa(hapd, tailpos);
1760 if (csa_pos != tailpos)
1761 hapd->cs_c_off_beacon = csa_pos - tail - 1;
1762 tailpos = csa_pos;
1763
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001764 /* ERP Information element */
1765 tailpos = hostapd_eid_erp_info(hapd, tailpos);
1766
1767 /* Extended supported rates */
1768 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
1769
Hai Shalomfdcde762020-04-02 11:19:20 -07001770 tailpos = hostapd_get_rsne(hapd, tailpos, tailend - tailpos);
1771 tailpos = hostapd_eid_bss_load(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001772 tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
Hai Shalomfdcde762020-04-02 11:19:20 -07001773 tailend - tailpos);
1774 tailpos = hostapd_get_mde(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001775
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001776 /* eCSA IE */
1777 csa_pos = hostapd_eid_ecsa(hapd, tailpos);
1778 if (csa_pos != tailpos)
1779 hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1;
1780 tailpos = csa_pos;
1781
1782 tailpos = hostapd_eid_supported_op_classes(hapd, tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001783 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
1784 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001785
Sunil Ravi77d572f2023-01-17 23:58:31 +00001786 if (hapd->iconf->mbssid && hapd->iconf->num_bss > 1) {
1787 if (ieee802_11_build_ap_params_mbssid(hapd, params)) {
1788 os_free(head);
1789 os_free(tail);
1790 wpa_printf(MSG_ERROR,
1791 "MBSSID: Failed to set beacon data");
1792 return -1;
1793 }
1794 complete = hapd->iconf->mbssid == MBSSID_ENABLED ||
1795 (hapd->iconf->mbssid == ENHANCED_MBSSID_ENABLED &&
1796 params->mbssid_elem_count == 1);
1797 }
1798
1799 tailpos = hostapd_eid_ext_capab(hapd, tailpos, complete);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001800
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001801 /*
1802 * TODO: Time Advertisement element should only be included in some
1803 * DTIM Beacon frames.
1804 */
1805 tailpos = hostapd_eid_time_adv(hapd, tailpos);
1806
1807 tailpos = hostapd_eid_interworking(hapd, tailpos);
1808 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
1809 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001810
1811#ifdef CONFIG_FST
1812 if (hapd->iface->fst_ies) {
1813 os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies),
1814 wpabuf_len(hapd->iface->fst_ies));
1815 tailpos += wpabuf_len(hapd->iface->fst_ies);
1816 }
1817#endif /* CONFIG_FST */
1818
Dmitry Shmidt04949592012-07-19 12:16:46 -07001819#ifdef CONFIG_IEEE80211AC
Hai Shalom60840252021-02-19 19:02:11 -08001820 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
1821 !is_6ghz_op_class(hapd->iconf->op_class)) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -07001822 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001823 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08001824 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001825 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001826#endif /* CONFIG_IEEE80211AC */
1827
Hai Shalom60840252021-02-19 19:02:11 -08001828#ifdef CONFIG_IEEE80211AX
1829 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax &&
1830 is_6ghz_op_class(hapd->iconf->op_class))
1831 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
1832#endif /* CONFIG_IEEE80211AX */
1833
Hai Shaloma20dcd72022-02-04 13:43:00 -08001834 tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos);
Hai Shalom899fcc72020-10-19 14:38:18 -07001835
Hai Shaloma20dcd72022-02-04 13:43:00 -08001836 tailpos = hostapd_eid_rnr(hapd, tailpos, WLAN_FC_STYPE_BEACON);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001837 tailpos = hostapd_eid_fils_indic(hapd, tailpos, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -07001838 tailpos = hostapd_get_rsnxe(hapd, tailpos, tailend - tailpos);
Sunil Ravi77d572f2023-01-17 23:58:31 +00001839 tailpos = hostapd_eid_mbssid_config(hapd, tailpos,
1840 params->mbssid_elem_count);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001841
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001842#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08001843 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Sunil Ravia04bd252022-05-02 22:54:18 -07001844 u8 *cca_pos;
1845
Hai Shalom81f62d82019-07-22 12:10:00 -07001846 tailpos = hostapd_eid_he_capab(hapd, tailpos,
1847 IEEE80211_MODE_AP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001848 tailpos = hostapd_eid_he_operation(hapd, tailpos);
Sunil Ravia04bd252022-05-02 22:54:18 -07001849
1850 /* BSS Color Change Announcement element */
1851 cca_pos = hostapd_eid_cca(hapd, tailpos);
1852 if (cca_pos != tailpos)
1853 hapd->cca_c_off_beacon = cca_pos - tail - 2;
1854 tailpos = cca_pos;
1855
Hai Shalom81f62d82019-07-22 12:10:00 -07001856 tailpos = hostapd_eid_spatial_reuse(hapd, tailpos);
Hai Shalomfdcde762020-04-02 11:19:20 -07001857 tailpos = hostapd_eid_he_mu_edca_parameter_set(hapd, tailpos);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001858 tailpos = hostapd_eid_he_6ghz_band_cap(hapd, tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001859 }
1860#endif /* CONFIG_IEEE80211AX */
1861
Sunil Ravia04bd252022-05-02 22:54:18 -07001862#ifdef CONFIG_IEEE80211BE
1863 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
1864 tailpos = hostapd_eid_eht_capab(hapd, tailpos,
1865 IEEE80211_MODE_AP);
1866 tailpos = hostapd_eid_eht_operation(hapd, tailpos);
1867 }
1868#endif /* CONFIG_IEEE80211BE */
1869
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001870#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001871 if (hapd->conf->vendor_vht)
1872 tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001873#endif /* CONFIG_IEEE80211AC */
1874
Hai Shalomfdcde762020-04-02 11:19:20 -07001875 /* WPA / OSEN */
1876 tailpos = hostapd_get_wpa_ie(hapd, tailpos, tailend - tailpos);
1877 tailpos = hostapd_get_osen_ie(hapd, tailpos, tailend - tailpos);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001878
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001879 /* Wi-Fi Alliance WMM */
1880 tailpos = hostapd_eid_wmm(hapd, tailpos);
1881
1882#ifdef CONFIG_WPS
1883 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
1884 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
1885 wpabuf_len(hapd->wps_beacon_ie));
1886 tailpos += wpabuf_len(hapd->wps_beacon_ie);
1887 }
1888#endif /* CONFIG_WPS */
1889
1890#ifdef CONFIG_P2P
1891 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
1892 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
1893 wpabuf_len(hapd->p2p_beacon_ie));
1894 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
1895 }
1896#endif /* CONFIG_P2P */
1897#ifdef CONFIG_P2P_MANAGER
1898 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
1899 P2P_MANAGE)
1900 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
1901#endif /* CONFIG_P2P_MANAGER */
1902
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001903#ifdef CONFIG_HS20
1904 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
1905#endif /* CONFIG_HS20 */
1906
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001907 tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001908 tailpos = hostapd_eid_owe_trans(hapd, tailpos,
1909 tail + tail_len - tailpos);
Hai Shalomfdcde762020-04-02 11:19:20 -07001910 tailpos = hostapd_eid_dpp_cc(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001911
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001912 if (hapd->conf->vendor_elements) {
1913 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
1914 wpabuf_len(hapd->conf->vendor_elements));
1915 tailpos += wpabuf_len(hapd->conf->vendor_elements);
1916 }
1917
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001918 tail_len = tailpos > tail ? tailpos - tail : 0;
1919
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001920 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
1921#endif /* NEED_AP_MLME */
1922
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001923 params->head = (u8 *) head;
1924 params->head_len = head_len;
1925 params->tail = tail;
1926 params->tail_len = tail_len;
1927 params->proberesp = resp;
1928 params->proberesp_len = resp_len;
1929 params->dtim_period = hapd->conf->dtim_period;
1930 params->beacon_int = hapd->iconf->beacon_int;
1931 params->basic_rates = hapd->iface->basic_rates;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001932 params->beacon_rate = hapd->iconf->beacon_rate;
1933 params->rate_type = hapd->iconf->rate_type;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001934 params->ssid = hapd->conf->ssid.ssid;
1935 params->ssid_len = hapd->conf->ssid.ssid_len;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001936 if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
1937 (WPA_PROTO_WPA | WPA_PROTO_RSN))
1938 params->pairwise_ciphers = hapd->conf->wpa_pairwise |
1939 hapd->conf->rsn_pairwise;
1940 else if (hapd->conf->wpa & WPA_PROTO_RSN)
1941 params->pairwise_ciphers = hapd->conf->rsn_pairwise;
1942 else if (hapd->conf->wpa & WPA_PROTO_WPA)
1943 params->pairwise_ciphers = hapd->conf->wpa_pairwise;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001944 params->group_cipher = hapd->conf->wpa_group;
1945 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
1946 params->auth_algs = hapd->conf->auth_algs;
1947 params->wpa_version = hapd->conf->wpa;
Hai Shalomfdcde762020-04-02 11:19:20 -07001948 params->privacy = hapd->conf->wpa;
1949#ifdef CONFIG_WEP
1950 params->privacy |= hapd->conf->ssid.wep.keys_set ||
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001951 (hapd->conf->ieee802_1x &&
1952 (hapd->conf->default_wep_key_len ||
1953 hapd->conf->individual_wep_key_len));
Hai Shalomfdcde762020-04-02 11:19:20 -07001954#endif /* CONFIG_WEP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001955 switch (hapd->conf->ignore_broadcast_ssid) {
1956 case 0:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001957 params->hide_ssid = NO_SSID_HIDING;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001958 break;
1959 case 1:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001960 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001961 break;
1962 case 2:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001963 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001964 break;
1965 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001966 params->isolate = hapd->conf->isolate;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001967#ifdef NEED_AP_MLME
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001968 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001969 ERP_INFO_USE_PROTECTION);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001970 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001971 hapd->iconf->preamble == SHORT_PREAMBLE;
1972 if (hapd->iface->current_mode &&
1973 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001974 params->short_slot_time =
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001975 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
1976 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001977 params->short_slot_time = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001978 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001979 params->ht_opmode = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001980 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001981 params->ht_opmode = hapd->iface->ht_op_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001982#endif /* NEED_AP_MLME */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001983 params->interworking = hapd->conf->interworking;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001984 if (hapd->conf->interworking &&
1985 !is_zero_ether_addr(hapd->conf->hessid))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001986 params->hessid = hapd->conf->hessid;
1987 params->access_network_type = hapd->conf->access_network_type;
1988 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001989#ifdef CONFIG_P2P
1990 params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
1991#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001992#ifdef CONFIG_HS20
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001993 params->disable_dgaf = hapd->conf->disable_dgaf;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001994 if (hapd->conf->osen) {
1995 params->privacy = 1;
1996 params->osen = 1;
1997 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001998#endif /* CONFIG_HS20 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001999 params->multicast_to_unicast = hapd->conf->multicast_to_unicast;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002000 params->pbss = hapd->conf->pbss;
Hai Shalom74f70d42019-02-11 14:42:39 -08002001
2002 if (hapd->conf->ftm_responder) {
2003 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_FTM_RESPONDER) {
2004 params->ftm_responder = 1;
2005 params->lci = hapd->iface->conf->lci;
2006 params->civic = hapd->iface->conf->civic;
2007 } else {
2008 wpa_printf(MSG_WARNING,
2009 "Not configuring FTM responder as the driver doesn't advertise support for it");
2010 }
2011 }
2012
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002013 return 0;
2014}
2015
2016
2017void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
2018{
2019 os_free(params->tail);
2020 params->tail = NULL;
2021 os_free(params->head);
2022 params->head = NULL;
2023 os_free(params->proberesp);
2024 params->proberesp = NULL;
Sunil Ravi77d572f2023-01-17 23:58:31 +00002025 os_free(params->mbssid_elem);
2026 params->mbssid_elem = NULL;
2027 os_free(params->mbssid_elem_offset);
2028 params->mbssid_elem_offset = NULL;
Hai Shalom60840252021-02-19 19:02:11 -08002029#ifdef CONFIG_FILS
2030 os_free(params->fd_frame_tmpl);
2031 params->fd_frame_tmpl = NULL;
2032#endif /* CONFIG_FILS */
2033#ifdef CONFIG_IEEE80211AX
2034 os_free(params->unsol_bcast_probe_resp_tmpl);
2035 params->unsol_bcast_probe_resp_tmpl = NULL;
2036#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002037}
2038
2039
Hai Shaloma20dcd72022-02-04 13:43:00 -08002040static int __ieee802_11_set_beacon(struct hostapd_data *hapd)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002041{
2042 struct wpa_driver_ap_params params;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002043 struct hostapd_freq_params freq;
2044 struct hostapd_iface *iface = hapd->iface;
2045 struct hostapd_config *iconf = iface->conf;
Hai Shalom81f62d82019-07-22 12:10:00 -07002046 struct hostapd_hw_modes *cmode = iface->current_mode;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002047 struct wpabuf *beacon, *proberesp, *assocresp;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002048 int res, ret = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002049
Hai Shaloma20dcd72022-02-04 13:43:00 -08002050 if (!hapd->drv_priv) {
2051 wpa_printf(MSG_ERROR, "Interface is disabled");
2052 return -1;
2053 }
2054
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002055 if (hapd->csa_in_progress) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002056 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002057 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002058 }
2059
2060 hapd->beacon_set_done = 1;
2061
2062 if (ieee802_11_build_ap_params(hapd, &params) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002063 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002064
2065 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
2066 0)
2067 goto fail;
2068
2069 params.beacon_ies = beacon;
2070 params.proberesp_ies = proberesp;
2071 params.assocresp_ies = assocresp;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002072 params.reenable = hapd->reenable_beacon;
Hai Shalomc3565922019-10-28 11:58:20 -07002073#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08002074 params.he_spr_ctrl = hapd->iface->conf->spr.sr_control;
2075 params.he_spr_non_srg_obss_pd_max_offset =
2076 hapd->iface->conf->spr.non_srg_obss_pd_max_offset;
Hai Shalomc3565922019-10-28 11:58:20 -07002077 params.he_spr_srg_obss_pd_min_offset =
2078 hapd->iface->conf->spr.srg_obss_pd_min_offset;
2079 params.he_spr_srg_obss_pd_max_offset =
2080 hapd->iface->conf->spr.srg_obss_pd_max_offset;
Hai Shalom60840252021-02-19 19:02:11 -08002081 os_memcpy(params.he_spr_bss_color_bitmap,
2082 hapd->iface->conf->spr.srg_bss_color_bitmap, 8);
2083 os_memcpy(params.he_spr_partial_bssid_bitmap,
2084 hapd->iface->conf->spr.srg_partial_bssid_bitmap, 8);
Hai Shalomfdcde762020-04-02 11:19:20 -07002085 params.he_bss_color_disabled =
2086 hapd->iface->conf->he_op.he_bss_color_disabled;
2087 params.he_bss_color_partial =
2088 hapd->iface->conf->he_op.he_bss_color_partial;
2089 params.he_bss_color = hapd->iface->conf->he_op.he_bss_color;
2090 params.twt_responder = hostapd_get_he_twt_responder(hapd,
2091 IEEE80211_MODE_AP);
Hai Shalom60840252021-02-19 19:02:11 -08002092 params.unsol_bcast_probe_resp_tmpl =
2093 hostapd_unsol_bcast_probe_resp(hapd, &params);
Hai Shalomc3565922019-10-28 11:58:20 -07002094#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002095 hapd->reenable_beacon = 0;
Hai Shalom60840252021-02-19 19:02:11 -08002096#ifdef CONFIG_SAE
2097 params.sae_pwe = hapd->conf->sae_pwe;
2098#endif /* CONFIG_SAE */
2099
2100#ifdef CONFIG_FILS
2101 params.fd_frame_tmpl = hostapd_fils_discovery(hapd, &params);
2102#endif /* CONFIG_FILS */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002103
Sunil Ravi036cec52023-03-29 11:35:17 -07002104#ifdef CONFIG_IEEE80211BE
2105 params.punct_bitmap = iconf->punct_bitmap;
2106#endif /* CONFIG_IEEE80211BE */
2107
Hai Shalom81f62d82019-07-22 12:10:00 -07002108 if (cmode &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002109 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
Hai Shalomc3565922019-10-28 11:58:20 -07002110 iconf->channel, iconf->enable_edmg,
2111 iconf->edmg_channel, iconf->ieee80211n,
Hai Shalom81f62d82019-07-22 12:10:00 -07002112 iconf->ieee80211ac, iconf->ieee80211ax,
Sunil Ravia04bd252022-05-02 22:54:18 -07002113 iconf->ieee80211be,
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002114 iconf->secondary_channel,
Hai Shalom81f62d82019-07-22 12:10:00 -07002115 hostapd_get_oper_chwidth(iconf),
2116 hostapd_get_oper_centr_freq_seg0_idx(iconf),
2117 hostapd_get_oper_centr_freq_seg1_idx(iconf),
2118 cmode->vht_capab,
Sunil Ravia04bd252022-05-02 22:54:18 -07002119 &cmode->he_capab[IEEE80211_MODE_AP],
2120 &cmode->eht_capab[IEEE80211_MODE_AP]) == 0)
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002121 params.freq = &freq;
2122
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002123 res = hostapd_drv_set_ap(hapd, &params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002124 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002125 if (res)
2126 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
2127 else
2128 ret = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002129fail:
2130 ieee802_11_free_ap_params(&params);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002131 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002132}
2133
2134
Hai Shaloma20dcd72022-02-04 13:43:00 -08002135int ieee802_11_set_beacon(struct hostapd_data *hapd)
2136{
2137 struct hostapd_iface *iface = hapd->iface;
2138 int ret;
2139 size_t i, j;
2140 bool is_6g;
2141
2142 ret = __ieee802_11_set_beacon(hapd);
2143 if (ret != 0)
2144 return ret;
2145
2146 if (!iface->interfaces || iface->interfaces->count <= 1)
2147 return 0;
2148
2149 /* Update Beacon frames in case of 6 GHz colocation */
2150 is_6g = is_6ghz_op_class(iface->conf->op_class);
2151 for (j = 0; j < iface->interfaces->count; j++) {
2152 struct hostapd_iface *colocated;
2153
2154 colocated = iface->interfaces->iface[j];
2155 if (colocated == iface || !colocated || !colocated->conf)
2156 continue;
2157
2158 if (is_6g == is_6ghz_op_class(colocated->conf->op_class))
2159 continue;
2160
2161 for (i = 0; i < colocated->num_bss; i++) {
2162 if (colocated->bss[i] && colocated->bss[i]->started)
2163 __ieee802_11_set_beacon(colocated->bss[i]);
2164 }
2165 }
2166
2167 return 0;
2168}
2169
2170
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002171int ieee802_11_set_beacons(struct hostapd_iface *iface)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002172{
2173 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002174 int ret = 0;
2175
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08002176 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002177 if (iface->bss[i]->started &&
2178 ieee802_11_set_beacon(iface->bss[i]) < 0)
2179 ret = -1;
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08002180 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002181
2182 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002183}
2184
Dmitry Shmidt04949592012-07-19 12:16:46 -07002185
2186/* only update beacons if started */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002187int ieee802_11_update_beacons(struct hostapd_iface *iface)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002188{
2189 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002190 int ret = 0;
2191
2192 for (i = 0; i < iface->num_bss; i++) {
2193 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
2194 ieee802_11_set_beacon(iface->bss[i]) < 0)
2195 ret = -1;
2196 }
2197
2198 return ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002199}
2200
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002201#endif /* CONFIG_NATIVE_WINDOWS */