blob: de944fed37136e73e3ea6df1b42af49652e2e0d5 [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;
Sunil Ravi640215c2023-06-28 23:08:09 +0000471 size_t len, rnr_len = 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +0000472 u8 elem_count = 0, *elem = NULL, **elem_offset = NULL, *end;
Sunil Ravi640215c2023-06-28 23:08:09 +0000473 u8 rnr_elem_count = 0, *rnr_elem = NULL, **rnr_elem_offset = NULL;
Sunil Ravi77d572f2023-01-17 23:58:31 +0000474
475 if (!iface->mbssid_max_interfaces ||
476 iface->num_bss > iface->mbssid_max_interfaces ||
477 (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED &&
478 !iface->ema_max_periodicity))
479 goto fail;
480
481 tx_bss = hostapd_mbssid_get_tx_bss(hapd);
482 len = hostapd_eid_mbssid_len(tx_bss, WLAN_FC_STYPE_BEACON, &elem_count,
Sunil Ravi640215c2023-06-28 23:08:09 +0000483 NULL, 0, &rnr_len);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000484 if (!len || (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED &&
485 elem_count > iface->ema_max_periodicity))
486 goto fail;
487
488 elem = os_zalloc(len);
489 if (!elem)
490 goto fail;
491
492 elem_offset = os_zalloc(elem_count * sizeof(u8 *));
493 if (!elem_offset)
494 goto fail;
495
Sunil Ravi640215c2023-06-28 23:08:09 +0000496 if (rnr_len) {
497 rnr_elem = os_zalloc(rnr_len);
498 if (!rnr_elem)
499 goto fail;
500
501 rnr_elem_offset = os_calloc(elem_count + 1, sizeof(u8 *));
502 if (!rnr_elem_offset)
503 goto fail;
504 }
505
Sunil Ravi77d572f2023-01-17 23:58:31 +0000506 end = hostapd_eid_mbssid(tx_bss, elem, elem + len, WLAN_FC_STYPE_BEACON,
Sunil Ravi640215c2023-06-28 23:08:09 +0000507 elem_count, elem_offset, NULL, 0, rnr_elem,
508 &rnr_elem_count, rnr_elem_offset, rnr_len);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000509
510 params->mbssid_tx_iface = tx_bss->conf->iface;
511 params->mbssid_index = hostapd_mbssid_get_bss_index(hapd);
512 params->mbssid_elem = elem;
513 params->mbssid_elem_len = end - elem;
514 params->mbssid_elem_count = elem_count;
515 params->mbssid_elem_offset = elem_offset;
Sunil Ravi640215c2023-06-28 23:08:09 +0000516 params->rnr_elem = rnr_elem;
517 params->rnr_elem_len = rnr_len;
518 params->rnr_elem_count = rnr_elem_count;
519 params->rnr_elem_offset = rnr_elem_offset;
Sunil Ravi77d572f2023-01-17 23:58:31 +0000520 if (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED)
521 params->ema = true;
522
523 return 0;
524
525fail:
Sunil Ravi640215c2023-06-28 23:08:09 +0000526 os_free(rnr_elem);
527 os_free(rnr_elem_offset);
528 os_free(elem_offset);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000529 os_free(elem);
530 wpa_printf(MSG_ERROR, "MBSSID: Configuration failed");
531 return -1;
532}
533
534
535static u8 * hostapd_eid_mbssid_config(struct hostapd_data *hapd, u8 *eid,
536 u8 mbssid_elem_count)
537{
538 struct hostapd_iface *iface = hapd->iface;
539
540 if (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED) {
541 *eid++ = WLAN_EID_EXTENSION;
542 *eid++ = 3;
543 *eid++ = WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION;
544 *eid++ = iface->num_bss;
545 *eid++ = mbssid_elem_count;
546 }
547
548 return eid;
549}
550
551
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800552static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800553 const struct ieee80211_mgmt *req,
Sunil8cd6f4d2022-06-28 18:40:46 +0000554 int is_p2p, size_t *resp_len,
Sunil Ravi036cec52023-03-29 11:35:17 -0700555 const u8 *known_bss, u8 known_bss_len)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800556{
557 struct ieee80211_mgmt *resp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800558 u8 *pos, *epos, *csa_pos;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800559 size_t buflen;
560
Sunil Ravi77d572f2023-01-17 23:58:31 +0000561 hapd = hostapd_mbssid_get_tx_bss(hapd);
562
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800563#define MAX_PROBERESP_LEN 768
564 buflen = MAX_PROBERESP_LEN;
565#ifdef CONFIG_WPS
566 if (hapd->wps_probe_resp_ie)
567 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
568#endif /* CONFIG_WPS */
569#ifdef CONFIG_P2P
570 if (hapd->p2p_probe_resp_ie)
571 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
572#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800573#ifdef CONFIG_FST
574 if (hapd->iface->fst_ies)
575 buflen += wpabuf_len(hapd->iface->fst_ies);
576#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700577 if (hapd->conf->vendor_elements)
578 buflen += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800579 if (hapd->conf->vendor_vht) {
580 buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
581 2 + sizeof(struct ieee80211_vht_operation);
582 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800583
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800584#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -0800585 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700586 buflen += 3 + sizeof(struct ieee80211_he_capabilities) +
Hai Shalom74f70d42019-02-11 14:42:39 -0800587 3 + sizeof(struct ieee80211_he_operation) +
Hai Shalom81f62d82019-07-22 12:10:00 -0700588 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
589 3 + sizeof(struct ieee80211_spatial_reuse);
Sunil Ravia04bd252022-05-02 22:54:18 -0700590 if (is_6ghz_op_class(hapd->iconf->op_class)) {
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700591 buflen += sizeof(struct ieee80211_he_6ghz_oper_info) +
592 3 + sizeof(struct ieee80211_he_6ghz_band_cap);
Sunil Ravia04bd252022-05-02 22:54:18 -0700593 /* An additional Transmit Power Envelope element for
594 * subordinate client */
595 if (hapd->iconf->he_6ghz_reg_pwr_type ==
596 HE_6GHZ_INDOOR_AP)
597 buflen += 4;
598 }
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800599 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700600#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800601
Sunil Ravia04bd252022-05-02 22:54:18 -0700602#ifdef CONFIG_IEEE80211BE
603 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
604 buflen += hostapd_eid_eht_capab_len(hapd, IEEE80211_MODE_AP);
605 buflen += 3 + sizeof(struct ieee80211_eht_operation);
Sunil Ravi036cec52023-03-29 11:35:17 -0700606 if (hapd->iconf->punct_bitmap)
607 buflen += EHT_OPER_DISABLED_SUBCHAN_BITMAP_SIZE;
Sunil Ravia04bd252022-05-02 22:54:18 -0700608 }
609#endif /* CONFIG_IEEE80211BE */
610
Sunil Ravi77d572f2023-01-17 23:58:31 +0000611 buflen += hostapd_eid_mbssid_len(hapd, WLAN_FC_STYPE_PROBE_RESP, NULL,
Sunil Ravi640215c2023-06-28 23:08:09 +0000612 known_bss, known_bss_len, NULL);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800613 buflen += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_PROBE_RESP);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800614 buflen += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700615 buflen += hostapd_eid_owe_trans_len(hapd);
Hai Shalomfdcde762020-04-02 11:19:20 -0700616 buflen += hostapd_eid_dpp_cc_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800617
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800618 resp = os_zalloc(buflen);
619 if (resp == NULL)
620 return NULL;
621
622 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
623
624 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
625 WLAN_FC_STYPE_PROBE_RESP);
Sunil Ravi036cec52023-03-29 11:35:17 -0700626 /* Unicast the response to all requests on bands other than 6 GHz. For
627 * the 6 GHz, unicast is used only if the actual SSID is not included in
628 * the Beacon frames. Otherwise, broadcast response is used per IEEE
629 * Std 802.11ax-2021, 26.17.2.3.2. Broadcast address is also used for
630 * the Probe Response frame template for the unsolicited (i.e., not as
631 * a response to a specific request) case. */
632 if (req && (!is_6ghz_op_class(hapd->iconf->op_class) ||
633 hapd->conf->ignore_broadcast_ssid))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800634 os_memcpy(resp->da, req->sa, ETH_ALEN);
Sunil Ravi036cec52023-03-29 11:35:17 -0700635 else
Sunil8cd6f4d2022-06-28 18:40:46 +0000636 os_memset(resp->da, 0xff, ETH_ALEN);
637
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800638 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
639
640 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
641 resp->u.probe_resp.beacon_int =
642 host_to_le16(hapd->iconf->beacon_int);
643
644 /* hardware or low-level driver will setup seq_ctrl and timestamp */
645 resp->u.probe_resp.capab_info =
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700646 host_to_le16(hostapd_own_capab_info(hapd));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800647
648 pos = resp->u.probe_resp.variable;
649 *pos++ = WLAN_EID_SSID;
650 *pos++ = hapd->conf->ssid.ssid_len;
651 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
652 pos += hapd->conf->ssid.ssid_len;
653
654 /* Supported rates */
655 pos = hostapd_eid_supp_rates(hapd, pos);
656
657 /* DS Params */
658 pos = hostapd_eid_ds_params(hapd, pos);
659
660 pos = hostapd_eid_country(hapd, pos, epos - pos);
661
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800662 /* Power Constraint element */
663 pos = hostapd_eid_pwr_constraint(hapd, pos);
664
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800665 /* CSA IE */
666 csa_pos = hostapd_eid_csa(hapd, pos);
667 if (csa_pos != pos)
668 hapd->cs_c_off_proberesp = csa_pos - (u8 *) resp - 1;
669 pos = csa_pos;
670
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800671 /* ERP Information element */
672 pos = hostapd_eid_erp_info(hapd, pos);
673
674 /* Extended supported rates */
675 pos = hostapd_eid_ext_supp_rates(hapd, pos);
676
Hai Shalomfdcde762020-04-02 11:19:20 -0700677 pos = hostapd_get_rsne(hapd, pos, epos - pos);
Dmitry Shmidt051af732013-10-22 13:52:46 -0700678 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000679 pos = hostapd_eid_mbssid(hapd, pos, epos, WLAN_FC_STYPE_PROBE_RESP, 0,
Sunil Ravi640215c2023-06-28 23:08:09 +0000680 NULL, known_bss, known_bss_len, NULL, NULL,
681 NULL, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800682 pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700683 pos = hostapd_get_mde(hapd, pos, epos - pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800684
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800685 /* eCSA IE */
686 csa_pos = hostapd_eid_ecsa(hapd, pos);
687 if (csa_pos != pos)
688 hapd->cs_c_off_ecsa_proberesp = csa_pos - (u8 *) resp - 1;
689 pos = csa_pos;
690
691 pos = hostapd_eid_supported_op_classes(hapd, pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800692 pos = hostapd_eid_ht_capabilities(hapd, pos);
693 pos = hostapd_eid_ht_operation(hapd, pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800694
Sunil Ravi77d572f2023-01-17 23:58:31 +0000695 /* Probe Response frames always include all non-TX profiles except
696 * when a list of known BSSes is included in the Probe Request frame. */
697 pos = hostapd_eid_ext_capab(hapd, pos,
698 hapd->iconf->mbssid >= MBSSID_ENABLED &&
699 !known_bss_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800700
701 pos = hostapd_eid_time_adv(hapd, pos);
702 pos = hostapd_eid_time_zone(hapd, pos);
703
704 pos = hostapd_eid_interworking(hapd, pos);
705 pos = hostapd_eid_adv_proto(hapd, pos);
706 pos = hostapd_eid_roaming_consortium(hapd, pos);
707
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800708#ifdef CONFIG_FST
709 if (hapd->iface->fst_ies) {
710 os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies),
711 wpabuf_len(hapd->iface->fst_ies));
712 pos += wpabuf_len(hapd->iface->fst_ies);
713 }
714#endif /* CONFIG_FST */
715
Dmitry Shmidt04949592012-07-19 12:16:46 -0700716#ifdef CONFIG_IEEE80211AC
Hai Shalomc3565922019-10-28 11:58:20 -0700717 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
718 !is_6ghz_op_class(hapd->iconf->op_class)) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700719 pos = hostapd_eid_vht_capabilities(hapd, pos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800720 pos = hostapd_eid_vht_operation(hapd, pos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800721 pos = hostapd_eid_txpower_envelope(hapd, pos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800722 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800723#endif /* CONFIG_IEEE80211AC */
724
Hai Shalom60840252021-02-19 19:02:11 -0800725#ifdef CONFIG_IEEE80211AX
726 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax &&
727 is_6ghz_op_class(hapd->iconf->op_class))
728 pos = hostapd_eid_txpower_envelope(hapd, pos);
729#endif /* CONFIG_IEEE80211AX */
730
Hai Shaloma20dcd72022-02-04 13:43:00 -0800731 pos = hostapd_eid_wb_chsw_wrapper(hapd, pos);
Hai Shalom899fcc72020-10-19 14:38:18 -0700732
Hai Shaloma20dcd72022-02-04 13:43:00 -0800733 pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_PROBE_RESP);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800734 pos = hostapd_eid_fils_indic(hapd, pos, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -0700735 pos = hostapd_get_rsnxe(hapd, pos, epos - pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800736
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700737#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -0800738 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700739 u8 *cca_pos;
740
Hai Shalom81f62d82019-07-22 12:10:00 -0700741 pos = hostapd_eid_he_capab(hapd, pos, IEEE80211_MODE_AP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700742 pos = hostapd_eid_he_operation(hapd, pos);
Sunil Ravia04bd252022-05-02 22:54:18 -0700743
744 /* BSS Color Change Announcement element */
745 cca_pos = hostapd_eid_cca(hapd, pos);
746 if (cca_pos != pos)
747 hapd->cca_c_off_proberesp = cca_pos - (u8 *) resp - 2;
748 pos = cca_pos;
749
Hai Shalom81f62d82019-07-22 12:10:00 -0700750 pos = hostapd_eid_spatial_reuse(hapd, pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700751 pos = hostapd_eid_he_mu_edca_parameter_set(hapd, pos);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700752 pos = hostapd_eid_he_6ghz_band_cap(hapd, pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700753 }
754#endif /* CONFIG_IEEE80211AX */
755
Sunil Ravia04bd252022-05-02 22:54:18 -0700756#ifdef CONFIG_IEEE80211BE
757 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
758 pos = hostapd_eid_eht_capab(hapd, pos, IEEE80211_MODE_AP);
759 pos = hostapd_eid_eht_operation(hapd, pos);
760 }
761#endif /* CONFIG_IEEE80211BE */
762
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800763#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800764 if (hapd->conf->vendor_vht)
765 pos = hostapd_eid_vendor_vht(hapd, pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700766#endif /* CONFIG_IEEE80211AC */
767
Hai Shalomfdcde762020-04-02 11:19:20 -0700768 /* WPA / OSEN */
769 pos = hostapd_get_wpa_ie(hapd, pos, epos - pos);
770 pos = hostapd_get_osen_ie(hapd, pos, epos - pos);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800771
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800772 /* Wi-Fi Alliance WMM */
773 pos = hostapd_eid_wmm(hapd, pos);
774
775#ifdef CONFIG_WPS
776 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
777 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
778 wpabuf_len(hapd->wps_probe_resp_ie));
779 pos += wpabuf_len(hapd->wps_probe_resp_ie);
780 }
781#endif /* CONFIG_WPS */
782
783#ifdef CONFIG_P2P
784 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
785 hapd->p2p_probe_resp_ie) {
786 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
787 wpabuf_len(hapd->p2p_probe_resp_ie));
788 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
789 }
790#endif /* CONFIG_P2P */
791#ifdef CONFIG_P2P_MANAGER
792 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
793 P2P_MANAGE)
794 pos = hostapd_eid_p2p_manage(hapd, pos);
795#endif /* CONFIG_P2P_MANAGER */
796
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700797#ifdef CONFIG_HS20
798 pos = hostapd_eid_hs20_indication(hapd, pos);
799#endif /* CONFIG_HS20 */
800
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800801 pos = hostapd_eid_mbo(hapd, pos, (u8 *) resp + buflen - pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700802 pos = hostapd_eid_owe_trans(hapd, pos, (u8 *) resp + buflen - pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700803 pos = hostapd_eid_dpp_cc(hapd, pos, (u8 *) resp + buflen - pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800804
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700805 if (hapd->conf->vendor_elements) {
806 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
807 wpabuf_len(hapd->conf->vendor_elements));
808 pos += wpabuf_len(hapd->conf->vendor_elements);
809 }
810
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800811 *resp_len = pos - (u8 *) resp;
812 return (u8 *) resp;
813}
814
815
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800816enum ssid_match_result {
817 NO_SSID_MATCH,
818 EXACT_SSID_MATCH,
Hai Shaloma20dcd72022-02-04 13:43:00 -0800819 WILDCARD_SSID_MATCH,
820 CO_LOCATED_SSID_MATCH,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800821};
822
823static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
824 const u8 *ssid, size_t ssid_len,
825 const u8 *ssid_list,
Hai Shalomfdcde762020-04-02 11:19:20 -0700826 size_t ssid_list_len,
827 const u8 *short_ssid_list,
828 size_t short_ssid_list_len)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800829{
830 const u8 *pos, *end;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800831 struct hostapd_iface *iface = hapd->iface;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800832 int wildcard = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800833 size_t i, j;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800834
835 if (ssid_len == 0)
836 wildcard = 1;
837 if (ssid_len == hapd->conf->ssid.ssid_len &&
838 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
839 return EXACT_SSID_MATCH;
840
Hai Shalomfdcde762020-04-02 11:19:20 -0700841 if (ssid_list) {
842 pos = ssid_list;
843 end = ssid_list + ssid_list_len;
844 while (end - pos >= 2) {
845 if (2 + pos[1] > end - pos)
846 break;
847 if (pos[1] == 0)
848 wildcard = 1;
849 if (pos[1] == hapd->conf->ssid.ssid_len &&
850 os_memcmp(pos + 2, hapd->conf->ssid.ssid,
851 pos[1]) == 0)
852 return EXACT_SSID_MATCH;
853 pos += 2 + pos[1];
854 }
855 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800856
Hai Shalomfdcde762020-04-02 11:19:20 -0700857 if (short_ssid_list) {
858 pos = short_ssid_list;
859 end = short_ssid_list + short_ssid_list_len;
860 while (end - pos >= 4) {
861 if (hapd->conf->ssid.short_ssid == WPA_GET_LE32(pos))
862 return EXACT_SSID_MATCH;
863 pos += 4;
864 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800865 }
866
Hai Shaloma20dcd72022-02-04 13:43:00 -0800867 if (wildcard)
868 return WILDCARD_SSID_MATCH;
869
870 if (!iface->interfaces || iface->interfaces->count <= 1 ||
871 is_6ghz_op_class(hapd->iconf->op_class))
872 return NO_SSID_MATCH;
873
874 for (i = 0; i < iface->interfaces->count; i++) {
875 struct hostapd_iface *colocated;
876
877 colocated = iface->interfaces->iface[i];
878
879 if (colocated == iface ||
880 !is_6ghz_op_class(colocated->conf->op_class))
881 continue;
882
883 for (j = 0; j < colocated->num_bss; j++) {
884 struct hostapd_bss_config *conf;
885
886 conf = colocated->bss[j]->conf;
887 if (ssid_len == conf->ssid.ssid_len &&
888 os_memcmp(ssid, conf->ssid.ssid, ssid_len) == 0)
889 return CO_LOCATED_SSID_MATCH;
890 }
891 }
892
893 return NO_SSID_MATCH;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800894}
895
896
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800897void sta_track_expire(struct hostapd_iface *iface, int force)
898{
899 struct os_reltime now;
900 struct hostapd_sta_info *info;
901
902 if (!iface->num_sta_seen)
903 return;
904
905 os_get_reltime(&now);
906 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
907 list))) {
908 if (!force &&
909 !os_reltime_expired(&now, &info->last_seen,
910 iface->conf->track_sta_max_age))
911 break;
912 force = 0;
913
914 wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
915 MACSTR, iface->bss[0]->conf->iface,
916 MAC2STR(info->addr));
917 dl_list_del(&info->list);
918 iface->num_sta_seen--;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700919 sta_track_del(info);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800920 }
921}
922
923
924static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
925 const u8 *addr)
926{
927 struct hostapd_sta_info *info;
928
929 dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
930 if (os_memcmp(addr, info->addr, ETH_ALEN) == 0)
931 return info;
932
933 return NULL;
934}
935
936
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800937void sta_track_add(struct hostapd_iface *iface, const u8 *addr, int ssi_signal)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800938{
939 struct hostapd_sta_info *info;
940
941 info = sta_track_get(iface, addr);
942 if (info) {
943 /* Move the most recent entry to the end of the list */
944 dl_list_del(&info->list);
945 dl_list_add_tail(&iface->sta_seen, &info->list);
946 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800947 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800948 return;
949 }
950
951 /* Add a new entry */
952 info = os_zalloc(sizeof(*info));
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700953 if (info == NULL)
954 return;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800955 os_memcpy(info->addr, addr, ETH_ALEN);
956 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800957 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800958
959 if (iface->num_sta_seen >= iface->conf->track_sta_max_num) {
960 /* Expire oldest entry to make room for a new one */
961 sta_track_expire(iface, 1);
962 }
963
964 wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
965 MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr));
966 dl_list_add_tail(&iface->sta_seen, &info->list);
967 iface->num_sta_seen++;
968}
969
970
971struct hostapd_data *
972sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
973 const char *ifname)
974{
975 struct hapd_interfaces *interfaces = iface->interfaces;
976 size_t i, j;
977
978 for (i = 0; i < interfaces->count; i++) {
979 struct hostapd_data *hapd = NULL;
980
981 iface = interfaces->iface[i];
982 for (j = 0; j < iface->num_bss; j++) {
983 hapd = iface->bss[j];
984 if (os_strcmp(ifname, hapd->conf->iface) == 0)
985 break;
986 hapd = NULL;
987 }
988
989 if (hapd && sta_track_get(iface, addr))
990 return hapd;
991 }
992
993 return NULL;
994}
995
996
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700997#ifdef CONFIG_TAXONOMY
998void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr,
999 struct wpabuf **probe_ie_taxonomy)
1000{
1001 struct hostapd_sta_info *info;
1002
1003 info = sta_track_get(iface, addr);
1004 if (!info)
1005 return;
1006
1007 wpabuf_free(*probe_ie_taxonomy);
1008 *probe_ie_taxonomy = info->probe_ie_taxonomy;
1009 info->probe_ie_taxonomy = NULL;
1010}
1011#endif /* CONFIG_TAXONOMY */
1012
1013
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001014void handle_probe_req(struct hostapd_data *hapd,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001015 const struct ieee80211_mgmt *mgmt, size_t len,
1016 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001017{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001018 u8 *resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001019 struct ieee802_11_elems elems;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001020 const u8 *ie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001021 size_t ie_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001022 size_t i, resp_len;
1023 int noack;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001024 enum ssid_match_result res;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001025 int ret;
1026 u16 csa_offs[2];
1027 size_t csa_offs_len;
Hai Shalomfdcde762020-04-02 11:19:20 -07001028 struct radius_sta rad_info;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001029
Hai Shalom60840252021-02-19 19:02:11 -08001030 if (hapd->iconf->rssi_ignore_probe_request && ssi_signal &&
1031 ssi_signal < hapd->iconf->rssi_ignore_probe_request)
1032 return;
1033
Dmitry Shmidte4663042016-04-04 10:07:49 -07001034 if (len < IEEE80211_HDRLEN)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001035 return;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001036 ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001037 if (hapd->iconf->track_sta_max_num)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001038 sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
Dmitry Shmidte4663042016-04-04 10:07:49 -07001039 ie_len = len - IEEE80211_HDRLEN;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001040
Hai Shalomfdcde762020-04-02 11:19:20 -07001041 ret = hostapd_allowed_address(hapd, mgmt->sa, (const u8 *) mgmt, len,
1042 &rad_info, 1);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001043 if (ret == HOSTAPD_ACL_REJECT) {
1044 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
1045 "Ignore Probe Request frame from " MACSTR
1046 " due to ACL reject ", MAC2STR(mgmt->sa));
1047 return;
1048 }
1049
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001050 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
1051 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001052 mgmt->sa, mgmt->da, mgmt->bssid,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001053 ie, ie_len, ssi_signal) > 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001054 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001055
Hai Shalom74f70d42019-02-11 14:42:39 -08001056 if (!hapd->conf->send_probe_response)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001057 return;
1058
1059 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
1060 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
1061 MAC2STR(mgmt->sa));
1062 return;
1063 }
1064
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001065 if ((!elems.ssid || !elems.supp_rates)) {
1066 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
1067 "without SSID or supported rates element",
1068 MAC2STR(mgmt->sa));
1069 return;
1070 }
1071
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001072 /*
1073 * No need to reply if the Probe Request frame was sent on an adjacent
1074 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
1075 * AP with dot11RadioMeasurementActivated set to true, but strictly
1076 * speaking does not allow such ignoring of Probe Request frames if
1077 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
1078 * number of unnecessary Probe Response frames for cases where the STA
1079 * is less likely to see them (Probe Request frame sent on a
1080 * neighboring, but partially overlapping, channel).
1081 */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001082 if (elems.ds_params &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001083 hapd->iface->current_mode &&
1084 (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
1085 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
1086 hapd->iconf->channel != elems.ds_params[0]) {
1087 wpa_printf(MSG_DEBUG,
1088 "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
1089 hapd->iconf->channel, elems.ds_params[0]);
1090 return;
1091 }
1092
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001093#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001094 if (hapd->p2p && hapd->p2p_group && elems.wps_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001095 struct wpabuf *wps;
1096 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
1097 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
1098 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
1099 "due to mismatch with Requested Device "
1100 "Type");
1101 wpabuf_free(wps);
1102 return;
1103 }
1104 wpabuf_free(wps);
1105 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001106
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001107 if (hapd->p2p && hapd->p2p_group && elems.p2p) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001108 struct wpabuf *p2p;
1109 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
1110 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
1111 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
1112 "due to mismatch with Device ID");
1113 wpabuf_free(p2p);
1114 return;
1115 }
1116 wpabuf_free(p2p);
1117 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001118#endif /* CONFIG_P2P */
1119
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001120 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
Hai Shalomfdcde762020-04-02 11:19:20 -07001121 elems.ssid_list_len == 0 && elems.short_ssid_list_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001122 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
1123 "broadcast SSID ignored", MAC2STR(mgmt->sa));
1124 return;
1125 }
1126
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001127#ifdef CONFIG_P2P
1128 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1129 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
1130 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
1131 P2P_WILDCARD_SSID_LEN) == 0) {
1132 /* Process P2P Wildcard SSID like Wildcard SSID */
1133 elems.ssid_len = 0;
1134 }
1135#endif /* CONFIG_P2P */
1136
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001137#ifdef CONFIG_TAXONOMY
1138 {
1139 struct sta_info *sta;
1140 struct hostapd_sta_info *info;
1141
1142 if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) {
1143 taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len);
1144 } else if ((info = sta_track_get(hapd->iface,
1145 mgmt->sa)) != NULL) {
1146 taxonomy_hostapd_sta_info_probe_req(hapd, info,
1147 ie, ie_len);
1148 }
1149 }
1150#endif /* CONFIG_TAXONOMY */
1151
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001152 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
Hai Shalomfdcde762020-04-02 11:19:20 -07001153 elems.ssid_list, elems.ssid_list_len,
1154 elems.short_ssid_list, elems.short_ssid_list_len);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001155 if (res == NO_SSID_MATCH) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001156 if (!(mgmt->da[0] & 0x01)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001157 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001158 " for foreign SSID '%s' (DA " MACSTR ")%s",
Dmitry Shmidt3c479372014-02-04 10:50:36 -08001159 MAC2STR(mgmt->sa),
1160 wpa_ssid_txt(elems.ssid, elems.ssid_len),
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001161 MAC2STR(mgmt->da),
1162 elems.ssid_list ? " (SSID list)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001163 }
1164 return;
1165 }
1166
Hai Shalomfdcde762020-04-02 11:19:20 -07001167 if (hapd->conf->ignore_broadcast_ssid && res == WILDCARD_SSID_MATCH) {
1168 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
1169 "broadcast SSID ignored", MAC2STR(mgmt->sa));
1170 return;
1171 }
1172
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001173#ifdef CONFIG_INTERWORKING
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -07001174 if (hapd->conf->interworking &&
1175 elems.interworking && elems.interworking_len >= 1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001176 u8 ant = elems.interworking[0] & 0x0f;
1177 if (ant != INTERWORKING_ANT_WILDCARD &&
1178 ant != hapd->conf->access_network_type) {
1179 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
1180 " for mismatching ANT %u ignored",
1181 MAC2STR(mgmt->sa), ant);
1182 return;
1183 }
1184 }
1185
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -07001186 if (hapd->conf->interworking && elems.interworking &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001187 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
1188 const u8 *hessid;
1189 if (elems.interworking_len == 7)
1190 hessid = elems.interworking + 1;
1191 else
1192 hessid = elems.interworking + 1 + 2;
1193 if (!is_broadcast_ether_addr(hessid) &&
1194 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
1195 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
1196 " for mismatching HESSID " MACSTR
1197 " ignored",
1198 MAC2STR(mgmt->sa), MAC2STR(hessid));
1199 return;
1200 }
1201 }
1202#endif /* CONFIG_INTERWORKING */
1203
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001204#ifdef CONFIG_P2P
1205 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1206 supp_rates_11b_only(&elems)) {
1207 /* Indicates support for 11b rates only */
1208 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
1209 MACSTR " with only 802.11b rates",
1210 MAC2STR(mgmt->sa));
1211 return;
1212 }
1213#endif /* CONFIG_P2P */
1214
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001215 /* TODO: verify that supp_rates contains at least one matching rate
1216 * with AP configuration */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001217
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001218 if (hapd->conf->no_probe_resp_if_seen_on &&
1219 is_multicast_ether_addr(mgmt->da) &&
1220 is_multicast_ether_addr(mgmt->bssid) &&
1221 sta_track_seen_on(hapd->iface, mgmt->sa,
1222 hapd->conf->no_probe_resp_if_seen_on)) {
1223 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1224 " since STA has been seen on %s",
1225 hapd->conf->iface, MAC2STR(mgmt->sa),
1226 hapd->conf->no_probe_resp_if_seen_on);
1227 return;
1228 }
1229
1230 if (hapd->conf->no_probe_resp_if_max_sta &&
1231 is_multicast_ether_addr(mgmt->da) &&
1232 is_multicast_ether_addr(mgmt->bssid) &&
1233 hapd->num_sta >= hapd->conf->max_num_sta &&
1234 !ap_get_sta(hapd, mgmt->sa)) {
1235 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1236 " since no room for additional STA",
1237 hapd->conf->iface, MAC2STR(mgmt->sa));
1238 return;
1239 }
1240
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001241#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001242 if (hapd->iconf->ignore_probe_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001243 drand48() < hapd->iconf->ignore_probe_probability) {
1244 wpa_printf(MSG_INFO,
1245 "TESTING: ignoring probe request from " MACSTR,
1246 MAC2STR(mgmt->sa));
1247 return;
1248 }
1249#endif /* CONFIG_TESTING_OPTIONS */
1250
Sunil Ravi77d572f2023-01-17 23:58:31 +00001251 /* Do not send Probe Response frame from a non-transmitting multiple
1252 * BSSID profile unless the Probe Request frame is directed at that
1253 * particular BSS. */
1254 if (hapd != hostapd_mbssid_get_tx_bss(hapd) && res != EXACT_SSID_MATCH)
1255 return;
1256
Roshan Pius3a1667e2018-07-03 15:17:14 -07001257 wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, RX_PROBE_REQUEST "sa=" MACSTR
1258 " signal=%d", MAC2STR(mgmt->sa), ssi_signal);
1259
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001260 resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL,
Sunil Ravi036cec52023-03-29 11:35:17 -07001261 &resp_len, elems.mbssid_known_bss,
Sunil Ravi77d572f2023-01-17 23:58:31 +00001262 elems.mbssid_known_bss_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001263 if (resp == NULL)
1264 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001265
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001266 /*
1267 * If this is a broadcast probe request, apply no ack policy to avoid
1268 * excessive retries.
1269 */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001270 noack = !!(res == WILDCARD_SSID_MATCH &&
1271 is_broadcast_ether_addr(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001272
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001273 csa_offs_len = 0;
1274 if (hapd->csa_in_progress) {
1275 if (hapd->cs_c_off_proberesp)
1276 csa_offs[csa_offs_len++] =
1277 hapd->cs_c_off_proberesp;
1278
1279 if (hapd->cs_c_off_ecsa_proberesp)
1280 csa_offs[csa_offs_len++] =
1281 hapd->cs_c_off_ecsa_proberesp;
1282 }
1283
Sunil Ravi77d572f2023-01-17 23:58:31 +00001284 ret = hostapd_drv_send_mlme(hostapd_mbssid_get_tx_bss(hapd), resp,
1285 resp_len, noack,
Hai Shalomfdcde762020-04-02 11:19:20 -07001286 csa_offs_len ? csa_offs : NULL,
1287 csa_offs_len, 0);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001288
1289 if (ret < 0)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001290 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001291
1292 os_free(resp);
1293
1294 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
1295 "SSID", MAC2STR(mgmt->sa),
1296 elems.ssid_len == 0 ? "broadcast" : "our");
1297}
1298
1299
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001300static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
1301 size_t *resp_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001302{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001303 /* check probe response offloading caps and print warnings */
1304 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
1305 return NULL;
1306
1307#ifdef CONFIG_WPS
1308 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
1309 (!(hapd->iface->probe_resp_offloads &
1310 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
1311 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
1312 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
1313 "Probe Response while not supporting this");
1314#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001315
1316#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001317 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
1318 !(hapd->iface->probe_resp_offloads &
1319 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
1320 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
1321 "Probe Response while not supporting this");
1322#endif /* CONFIG_P2P */
1323
1324 if (hapd->conf->interworking &&
1325 !(hapd->iface->probe_resp_offloads &
1326 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
1327 wpa_printf(MSG_WARNING, "Device is trying to offload "
1328 "Interworking Probe Response while not supporting "
1329 "this");
1330
1331 /* Generate a Probe Response template for the non-P2P case */
Sunil Ravi036cec52023-03-29 11:35:17 -07001332 return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len, NULL, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001333}
1334
1335#endif /* NEED_AP_MLME */
1336
1337
Hai Shalom60840252021-02-19 19:02:11 -08001338#ifdef CONFIG_IEEE80211AX
1339/* Unsolicited broadcast Probe Response transmission, 6 GHz only */
1340static u8 * hostapd_unsol_bcast_probe_resp(struct hostapd_data *hapd,
1341 struct wpa_driver_ap_params *params)
1342{
1343 if (!is_6ghz_op_class(hapd->iconf->op_class))
1344 return NULL;
1345
1346 params->unsol_bcast_probe_resp_interval =
1347 hapd->conf->unsol_bcast_probe_resp_interval;
1348
1349 return hostapd_gen_probe_resp(hapd, NULL, 0,
Sunil8cd6f4d2022-06-28 18:40:46 +00001350 &params->unsol_bcast_probe_resp_tmpl_len,
Sunil Ravi036cec52023-03-29 11:35:17 -07001351 NULL, 0);
Hai Shalom60840252021-02-19 19:02:11 -08001352}
1353#endif /* CONFIG_IEEE80211AX */
1354
1355
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001356void sta_track_del(struct hostapd_sta_info *info)
1357{
1358#ifdef CONFIG_TAXONOMY
1359 wpabuf_free(info->probe_ie_taxonomy);
1360 info->probe_ie_taxonomy = NULL;
1361#endif /* CONFIG_TAXONOMY */
1362 os_free(info);
1363}
1364
1365
Hai Shalom60840252021-02-19 19:02:11 -08001366#ifdef CONFIG_FILS
1367
1368static u16 hostapd_fils_discovery_cap(struct hostapd_data *hapd)
1369{
1370 u16 cap_info, phy_index = 0;
1371 u8 chwidth = FD_CAP_BSS_CHWIDTH_20, mcs_nss_size = 4;
1372 struct hostapd_hw_modes *mode = hapd->iface->current_mode;
1373
1374 cap_info = FD_CAP_ESS;
1375 if (hapd->conf->wpa)
1376 cap_info |= FD_CAP_PRIVACY;
1377
1378 if (is_6ghz_op_class(hapd->iconf->op_class)) {
1379 phy_index = FD_CAP_PHY_INDEX_HE;
1380
1381 switch (hapd->iconf->op_class) {
Sunil Ravi036cec52023-03-29 11:35:17 -07001382 case 137:
1383 chwidth = FD_CAP_BSS_CHWIDTH_320;
1384 break;
Hai Shalom60840252021-02-19 19:02:11 -08001385 case 135:
1386 mcs_nss_size += 4;
1387 /* fallthrough */
1388 case 134:
1389 mcs_nss_size += 4;
1390 chwidth = FD_CAP_BSS_CHWIDTH_160_80_80;
1391 break;
1392 case 133:
1393 chwidth = FD_CAP_BSS_CHWIDTH_80;
1394 break;
1395 case 132:
1396 chwidth = FD_CAP_BSS_CHWIDTH_40;
1397 break;
1398 }
1399 } else {
1400 switch (hostapd_get_oper_chwidth(hapd->iconf)) {
Sunil8cd6f4d2022-06-28 18:40:46 +00001401 case CONF_OPER_CHWIDTH_80P80MHZ:
Hai Shalom60840252021-02-19 19:02:11 -08001402 mcs_nss_size += 4;
1403 /* fallthrough */
Sunil8cd6f4d2022-06-28 18:40:46 +00001404 case CONF_OPER_CHWIDTH_160MHZ:
Hai Shalom60840252021-02-19 19:02:11 -08001405 mcs_nss_size += 4;
1406 chwidth = FD_CAP_BSS_CHWIDTH_160_80_80;
1407 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00001408 case CONF_OPER_CHWIDTH_80MHZ:
Hai Shalom60840252021-02-19 19:02:11 -08001409 chwidth = FD_CAP_BSS_CHWIDTH_80;
1410 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00001411 case CONF_OPER_CHWIDTH_USE_HT:
Hai Shalom60840252021-02-19 19:02:11 -08001412 if (hapd->iconf->secondary_channel)
1413 chwidth = FD_CAP_BSS_CHWIDTH_40;
1414 else
1415 chwidth = FD_CAP_BSS_CHWIDTH_20;
1416 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00001417 default:
1418 break;
Hai Shalom60840252021-02-19 19:02:11 -08001419 }
1420
1421#ifdef CONFIG_IEEE80211AX
1422 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax)
1423 phy_index = FD_CAP_PHY_INDEX_HE;
1424#endif /* CONFIG_IEEE80211AX */
1425#ifdef CONFIG_IEEE80211AC
1426 if (!phy_index &&
1427 hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac)
1428 phy_index = FD_CAP_PHY_INDEX_VHT;
1429#endif /* CONFIG_IEEE80211AC */
1430 if (!phy_index &&
1431 hapd->iconf->ieee80211n && !hapd->conf->disable_11n)
1432 phy_index = FD_CAP_PHY_INDEX_HT;
1433 }
1434
1435 cap_info |= phy_index << FD_CAP_PHY_INDEX_SHIFT;
1436 cap_info |= chwidth << FD_CAP_BSS_CHWIDTH_SHIFT;
1437
Sunil Ravi036cec52023-03-29 11:35:17 -07001438 if (mode && phy_index == FD_CAP_PHY_INDEX_HE) {
1439 const u8 *he_mcs = mode->he_capab[IEEE80211_MODE_AP].mcs;
Hai Shalom60840252021-02-19 19:02:11 -08001440 int i;
Sunil Ravi036cec52023-03-29 11:35:17 -07001441 u16 nss = 0, mcs[6];
1442
1443 os_memset(mcs, 0xffff, 6 * sizeof(u16));
1444
1445 if (mcs_nss_size == 4) {
1446 mcs[0] = WPA_GET_LE16(&he_mcs[0]);
1447 mcs[1] = WPA_GET_LE16(&he_mcs[2]);
1448 }
1449
1450 if (mcs_nss_size == 8) {
1451 mcs[2] = WPA_GET_LE16(&he_mcs[4]);
1452 mcs[3] = WPA_GET_LE16(&he_mcs[6]);
1453 }
1454
1455 if (mcs_nss_size == 12) {
1456 mcs[4] = WPA_GET_LE16(&he_mcs[8]);
1457 mcs[5] = WPA_GET_LE16(&he_mcs[10]);
1458 }
Hai Shalom60840252021-02-19 19:02:11 -08001459
1460 for (i = 0; i < HE_NSS_MAX_STREAMS; i++) {
1461 u16 nss_mask = 0x3 << (i * 2);
1462
Sunil Ravi036cec52023-03-29 11:35:17 -07001463 /*
1464 * If NSS values supported by RX and TX are different
1465 * then choose the smaller of the two as the maximum
1466 * supported NSS as that is the value supported by
1467 * both RX and TX.
1468 */
Hai Shalom60840252021-02-19 19:02:11 -08001469 if (mcs_nss_size == 4 &&
1470 (((mcs[0] & nss_mask) == nss_mask) ||
1471 ((mcs[1] & nss_mask) == nss_mask)))
1472 continue;
1473
1474 if (mcs_nss_size == 8 &&
1475 (((mcs[2] & nss_mask) == nss_mask) ||
1476 ((mcs[3] & nss_mask) == nss_mask)))
1477 continue;
1478
1479 if (mcs_nss_size == 12 &&
1480 (((mcs[4] & nss_mask) == nss_mask) ||
1481 ((mcs[5] & nss_mask) == nss_mask)))
1482 continue;
1483
1484 nss++;
1485 }
1486
1487 if (nss > 4)
1488 cap_info |= FD_CAP_NSS_5_8 << FD_CAP_NSS_SHIFT;
1489 else if (nss)
1490 cap_info |= (nss - 1) << FD_CAP_NSS_SHIFT;
1491 }
1492
1493 return cap_info;
1494}
1495
1496
1497static u8 * hostapd_gen_fils_discovery(struct hostapd_data *hapd, size_t *len)
1498{
1499 struct ieee80211_mgmt *head;
1500 const u8 *mobility_domain;
1501 u8 *pos, *length_pos, buf[200];
1502 u16 ctl = 0;
1503 u8 fd_rsn_info[5];
1504 size_t total_len, buf_len;
1505
1506 total_len = 24 + 2 + 12;
1507
1508 /* FILS Discovery Frame Control */
1509 ctl = (sizeof(hapd->conf->ssid.short_ssid) - 1) |
1510 FD_FRAME_CTL_SHORT_SSID_PRESENT |
1511 FD_FRAME_CTL_LENGTH_PRESENT |
1512 FD_FRAME_CTL_CAP_PRESENT;
1513 total_len += 4 + 1 + 2;
1514
1515 /* Check for optional subfields and calculate length */
1516 if (wpa_auth_write_fd_rsn_info(hapd->wpa_auth, fd_rsn_info)) {
1517 ctl |= FD_FRAME_CTL_RSN_INFO_PRESENT;
1518 total_len += sizeof(fd_rsn_info);
1519 }
1520
1521 mobility_domain = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN);
1522 if (mobility_domain) {
1523 ctl |= FD_FRAME_CTL_MD_PRESENT;
1524 total_len += 3;
1525 }
1526
Hai Shaloma20dcd72022-02-04 13:43:00 -08001527 total_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_ACTION);
1528
Hai Shalom60840252021-02-19 19:02:11 -08001529 pos = hostapd_eid_fils_indic(hapd, buf, 0);
1530 buf_len = pos - buf;
1531 total_len += buf_len;
1532
Sunil Ravia04bd252022-05-02 22:54:18 -07001533#ifdef CONFIG_IEEE80211AX
1534 /* Transmit Power Envelope element(s) */
1535 if (is_6ghz_op_class(hapd->iconf->op_class)) {
1536 total_len += 4;
1537 if (hapd->iconf->he_6ghz_reg_pwr_type == HE_6GHZ_INDOOR_AP)
1538 total_len += 4;
1539 }
1540#endif /* CONFIG_IEEE80211AX */
1541
Hai Shalom60840252021-02-19 19:02:11 -08001542 head = os_zalloc(total_len);
1543 if (!head)
1544 return NULL;
1545
1546 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1547 WLAN_FC_STYPE_ACTION);
1548 os_memset(head->da, 0xff, ETH_ALEN);
1549 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1550 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1551
1552 head->u.action.category = WLAN_ACTION_PUBLIC;
1553 head->u.action.u.public_action.action = WLAN_PA_FILS_DISCOVERY;
1554
1555 pos = &head->u.action.u.public_action.variable[0];
1556
1557 /* FILS Discovery Information field */
1558
1559 /* FILS Discovery Frame Control */
1560 WPA_PUT_LE16(pos, ctl);
1561 pos += 2;
1562
1563 /* Hardware or low-level driver will fill in the Timestamp value */
1564 pos += 8;
1565
1566 /* Beacon Interval */
1567 WPA_PUT_LE16(pos, hapd->iconf->beacon_int);
1568 pos += 2;
1569
1570 /* Short SSID */
1571 WPA_PUT_LE32(pos, hapd->conf->ssid.short_ssid);
1572 pos += sizeof(hapd->conf->ssid.short_ssid);
1573
1574 /* Store position of FILS discovery information element Length field */
1575 length_pos = pos++;
1576
1577 /* FD Capability */
1578 WPA_PUT_LE16(pos, hostapd_fils_discovery_cap(hapd));
1579 pos += 2;
1580
1581 /* Operating Class - not present */
1582
1583 /* Primary Channel - not present */
1584
1585 /* AP Configuration Sequence Number - not present */
1586
1587 /* Access Network Options - not present */
1588
1589 /* FD RSN Information */
1590 if (ctl & FD_FRAME_CTL_RSN_INFO_PRESENT) {
1591 os_memcpy(pos, fd_rsn_info, sizeof(fd_rsn_info));
1592 pos += sizeof(fd_rsn_info);
1593 }
1594
1595 /* Channel Center Frequency Segment 1 - not present */
1596
1597 /* Mobility Domain */
1598 if (ctl & FD_FRAME_CTL_MD_PRESENT) {
1599 os_memcpy(pos, &mobility_domain[2], 3);
1600 pos += 3;
1601 }
1602
1603 /* Fill in the Length field value */
1604 *length_pos = pos - (length_pos + 1);
1605
Hai Shaloma20dcd72022-02-04 13:43:00 -08001606 pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_ACTION);
1607
Hai Shalom60840252021-02-19 19:02:11 -08001608 /* FILS Indication element */
1609 if (buf_len) {
1610 os_memcpy(pos, buf, buf_len);
1611 pos += buf_len;
1612 }
1613
Sunil Ravia04bd252022-05-02 22:54:18 -07001614 if (is_6ghz_op_class(hapd->iconf->op_class))
1615 pos = hostapd_eid_txpower_envelope(hapd, pos);
1616
Hai Shalom60840252021-02-19 19:02:11 -08001617 *len = pos - (u8 *) head;
1618 wpa_hexdump(MSG_DEBUG, "FILS Discovery frame template",
1619 head, pos - (u8 *) head);
1620 return (u8 *) head;
1621}
1622
1623
1624/* Configure FILS Discovery frame transmission parameters */
1625static u8 * hostapd_fils_discovery(struct hostapd_data *hapd,
1626 struct wpa_driver_ap_params *params)
1627{
1628 params->fd_max_int = hapd->conf->fils_discovery_max_int;
1629 if (is_6ghz_op_class(hapd->iconf->op_class) &&
1630 params->fd_max_int > FD_MAX_INTERVAL_6GHZ)
1631 params->fd_max_int = FD_MAX_INTERVAL_6GHZ;
1632
1633 params->fd_min_int = hapd->conf->fils_discovery_min_int;
1634 if (params->fd_min_int > params->fd_max_int)
1635 params->fd_min_int = params->fd_max_int;
1636
1637 if (params->fd_max_int)
1638 return hostapd_gen_fils_discovery(hapd,
1639 &params->fd_frame_tmpl_len);
1640
1641 return NULL;
1642}
1643
1644#endif /* CONFIG_FILS */
1645
1646
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001647int ieee802_11_build_ap_params(struct hostapd_data *hapd,
1648 struct wpa_driver_ap_params *params)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001649{
1650 struct ieee80211_mgmt *head = NULL;
1651 u8 *tail = NULL;
1652 size_t head_len = 0, tail_len = 0;
1653 u8 *resp = NULL;
1654 size_t resp_len = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001655#ifdef NEED_AP_MLME
1656 u16 capab_info;
Hai Shalomfdcde762020-04-02 11:19:20 -07001657 u8 *pos, *tailpos, *tailend, *csa_pos;
Sunil Ravi77d572f2023-01-17 23:58:31 +00001658 bool complete = false;
1659#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001660
Sunil Ravi77d572f2023-01-17 23:58:31 +00001661 os_memset(params, 0, sizeof(*params));
1662
1663#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001664#define BEACON_HEAD_BUF_SIZE 256
1665#define BEACON_TAIL_BUF_SIZE 512
1666 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
1667 tail_len = BEACON_TAIL_BUF_SIZE;
1668#ifdef CONFIG_WPS
1669 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
1670 tail_len += wpabuf_len(hapd->wps_beacon_ie);
1671#endif /* CONFIG_WPS */
1672#ifdef CONFIG_P2P
1673 if (hapd->p2p_beacon_ie)
1674 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
1675#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001676#ifdef CONFIG_FST
1677 if (hapd->iface->fst_ies)
1678 tail_len += wpabuf_len(hapd->iface->fst_ies);
1679#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001680 if (hapd->conf->vendor_elements)
1681 tail_len += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001682
1683#ifdef CONFIG_IEEE80211AC
1684 if (hapd->conf->vendor_vht) {
1685 tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
1686 2 + sizeof(struct ieee80211_vht_operation);
1687 }
1688#endif /* CONFIG_IEEE80211AC */
1689
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001690#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08001691 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001692 tail_len += 3 + sizeof(struct ieee80211_he_capabilities) +
Hai Shalom74f70d42019-02-11 14:42:39 -08001693 3 + sizeof(struct ieee80211_he_operation) +
Hai Shalom81f62d82019-07-22 12:10:00 -07001694 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
1695 3 + sizeof(struct ieee80211_spatial_reuse);
Sunil Ravia04bd252022-05-02 22:54:18 -07001696 if (is_6ghz_op_class(hapd->iconf->op_class)) {
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001697 tail_len += sizeof(struct ieee80211_he_6ghz_oper_info) +
1698 3 + sizeof(struct ieee80211_he_6ghz_band_cap);
Sunil Ravia04bd252022-05-02 22:54:18 -07001699 /* An additional Transmit Power Envelope element for
1700 * subordinate client */
1701 if (hapd->iconf->he_6ghz_reg_pwr_type ==
1702 HE_6GHZ_INDOOR_AP)
1703 tail_len += 4;
1704 }
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001705 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001706#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001707
Sunil Ravia04bd252022-05-02 22:54:18 -07001708#ifdef CONFIG_IEEE80211BE
1709 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
1710 tail_len += hostapd_eid_eht_capab_len(hapd, IEEE80211_MODE_AP);
1711 tail_len += 3 + sizeof(struct ieee80211_eht_operation);
Sunil Ravi036cec52023-03-29 11:35:17 -07001712 if (hapd->iconf->punct_bitmap)
1713 tail_len += EHT_OPER_DISABLED_SUBCHAN_BITMAP_SIZE;
Sunil Ravia04bd252022-05-02 22:54:18 -07001714 }
1715#endif /* CONFIG_IEEE80211BE */
1716
Sunil Ravi77d572f2023-01-17 23:58:31 +00001717 if (hapd->iconf->mbssid == ENHANCED_MBSSID_ENABLED &&
1718 hapd == hostapd_mbssid_get_tx_bss(hapd))
1719 tail_len += 5; /* Multiple BSSID Configuration element */
Hai Shaloma20dcd72022-02-04 13:43:00 -08001720 tail_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_BEACON);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001721 tail_len += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001722 tail_len += hostapd_eid_owe_trans_len(hapd);
Hai Shalomfdcde762020-04-02 11:19:20 -07001723 tail_len += hostapd_eid_dpp_cc_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001724
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001725 tailpos = tail = os_malloc(tail_len);
1726 if (head == NULL || tail == NULL) {
1727 wpa_printf(MSG_ERROR, "Failed to set beacon data");
1728 os_free(head);
1729 os_free(tail);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001730 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001731 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001732 tailend = tail + tail_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001733
1734 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1735 WLAN_FC_STYPE_BEACON);
1736 head->duration = host_to_le16(0);
1737 os_memset(head->da, 0xff, ETH_ALEN);
1738
1739 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1740 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1741 head->u.beacon.beacon_int =
1742 host_to_le16(hapd->iconf->beacon_int);
1743
1744 /* hardware or low-level driver will setup seq_ctrl and timestamp */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001745 capab_info = hostapd_own_capab_info(hapd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001746 head->u.beacon.capab_info = host_to_le16(capab_info);
1747 pos = &head->u.beacon.variable[0];
1748
1749 /* SSID */
1750 *pos++ = WLAN_EID_SSID;
1751 if (hapd->conf->ignore_broadcast_ssid == 2) {
1752 /* clear the data, but keep the correct length of the SSID */
1753 *pos++ = hapd->conf->ssid.ssid_len;
1754 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
1755 pos += hapd->conf->ssid.ssid_len;
1756 } else if (hapd->conf->ignore_broadcast_ssid) {
1757 *pos++ = 0; /* empty SSID */
1758 } else {
1759 *pos++ = hapd->conf->ssid.ssid_len;
1760 os_memcpy(pos, hapd->conf->ssid.ssid,
1761 hapd->conf->ssid.ssid_len);
1762 pos += hapd->conf->ssid.ssid_len;
1763 }
1764
1765 /* Supported rates */
1766 pos = hostapd_eid_supp_rates(hapd, pos);
1767
1768 /* DS Params */
1769 pos = hostapd_eid_ds_params(hapd, pos);
1770
1771 head_len = pos - (u8 *) head;
1772
Hai Shalomfdcde762020-04-02 11:19:20 -07001773 tailpos = hostapd_eid_country(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001774
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001775 /* Power Constraint element */
1776 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
1777
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001778 /* CSA IE */
1779 csa_pos = hostapd_eid_csa(hapd, tailpos);
1780 if (csa_pos != tailpos)
1781 hapd->cs_c_off_beacon = csa_pos - tail - 1;
1782 tailpos = csa_pos;
1783
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001784 /* ERP Information element */
1785 tailpos = hostapd_eid_erp_info(hapd, tailpos);
1786
1787 /* Extended supported rates */
1788 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
1789
Hai Shalomfdcde762020-04-02 11:19:20 -07001790 tailpos = hostapd_get_rsne(hapd, tailpos, tailend - tailpos);
1791 tailpos = hostapd_eid_bss_load(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001792 tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
Hai Shalomfdcde762020-04-02 11:19:20 -07001793 tailend - tailpos);
1794 tailpos = hostapd_get_mde(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001795
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001796 /* eCSA IE */
1797 csa_pos = hostapd_eid_ecsa(hapd, tailpos);
1798 if (csa_pos != tailpos)
1799 hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1;
1800 tailpos = csa_pos;
1801
1802 tailpos = hostapd_eid_supported_op_classes(hapd, tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001803 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
1804 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001805
Sunil Ravi77d572f2023-01-17 23:58:31 +00001806 if (hapd->iconf->mbssid && hapd->iconf->num_bss > 1) {
1807 if (ieee802_11_build_ap_params_mbssid(hapd, params)) {
1808 os_free(head);
1809 os_free(tail);
1810 wpa_printf(MSG_ERROR,
1811 "MBSSID: Failed to set beacon data");
1812 return -1;
1813 }
1814 complete = hapd->iconf->mbssid == MBSSID_ENABLED ||
1815 (hapd->iconf->mbssid == ENHANCED_MBSSID_ENABLED &&
1816 params->mbssid_elem_count == 1);
1817 }
1818
1819 tailpos = hostapd_eid_ext_capab(hapd, tailpos, complete);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001820
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001821 /*
1822 * TODO: Time Advertisement element should only be included in some
1823 * DTIM Beacon frames.
1824 */
1825 tailpos = hostapd_eid_time_adv(hapd, tailpos);
1826
1827 tailpos = hostapd_eid_interworking(hapd, tailpos);
1828 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
1829 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001830
1831#ifdef CONFIG_FST
1832 if (hapd->iface->fst_ies) {
1833 os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies),
1834 wpabuf_len(hapd->iface->fst_ies));
1835 tailpos += wpabuf_len(hapd->iface->fst_ies);
1836 }
1837#endif /* CONFIG_FST */
1838
Dmitry Shmidt04949592012-07-19 12:16:46 -07001839#ifdef CONFIG_IEEE80211AC
Hai Shalom60840252021-02-19 19:02:11 -08001840 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
1841 !is_6ghz_op_class(hapd->iconf->op_class)) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -07001842 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001843 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08001844 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001845 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001846#endif /* CONFIG_IEEE80211AC */
1847
Hai Shalom60840252021-02-19 19:02:11 -08001848#ifdef CONFIG_IEEE80211AX
1849 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax &&
1850 is_6ghz_op_class(hapd->iconf->op_class))
1851 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
1852#endif /* CONFIG_IEEE80211AX */
1853
Hai Shaloma20dcd72022-02-04 13:43:00 -08001854 tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos);
Hai Shalom899fcc72020-10-19 14:38:18 -07001855
Hai Shaloma20dcd72022-02-04 13:43:00 -08001856 tailpos = hostapd_eid_rnr(hapd, tailpos, WLAN_FC_STYPE_BEACON);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001857 tailpos = hostapd_eid_fils_indic(hapd, tailpos, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -07001858 tailpos = hostapd_get_rsnxe(hapd, tailpos, tailend - tailpos);
Sunil Ravi77d572f2023-01-17 23:58:31 +00001859 tailpos = hostapd_eid_mbssid_config(hapd, tailpos,
1860 params->mbssid_elem_count);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001861
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001862#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08001863 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Sunil Ravia04bd252022-05-02 22:54:18 -07001864 u8 *cca_pos;
1865
Hai Shalom81f62d82019-07-22 12:10:00 -07001866 tailpos = hostapd_eid_he_capab(hapd, tailpos,
1867 IEEE80211_MODE_AP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001868 tailpos = hostapd_eid_he_operation(hapd, tailpos);
Sunil Ravia04bd252022-05-02 22:54:18 -07001869
1870 /* BSS Color Change Announcement element */
1871 cca_pos = hostapd_eid_cca(hapd, tailpos);
1872 if (cca_pos != tailpos)
1873 hapd->cca_c_off_beacon = cca_pos - tail - 2;
1874 tailpos = cca_pos;
1875
Hai Shalom81f62d82019-07-22 12:10:00 -07001876 tailpos = hostapd_eid_spatial_reuse(hapd, tailpos);
Hai Shalomfdcde762020-04-02 11:19:20 -07001877 tailpos = hostapd_eid_he_mu_edca_parameter_set(hapd, tailpos);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001878 tailpos = hostapd_eid_he_6ghz_band_cap(hapd, tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001879 }
1880#endif /* CONFIG_IEEE80211AX */
1881
Sunil Ravia04bd252022-05-02 22:54:18 -07001882#ifdef CONFIG_IEEE80211BE
1883 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
1884 tailpos = hostapd_eid_eht_capab(hapd, tailpos,
1885 IEEE80211_MODE_AP);
1886 tailpos = hostapd_eid_eht_operation(hapd, tailpos);
1887 }
1888#endif /* CONFIG_IEEE80211BE */
1889
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001890#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001891 if (hapd->conf->vendor_vht)
1892 tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001893#endif /* CONFIG_IEEE80211AC */
1894
Hai Shalomfdcde762020-04-02 11:19:20 -07001895 /* WPA / OSEN */
1896 tailpos = hostapd_get_wpa_ie(hapd, tailpos, tailend - tailpos);
1897 tailpos = hostapd_get_osen_ie(hapd, tailpos, tailend - tailpos);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001898
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001899 /* Wi-Fi Alliance WMM */
1900 tailpos = hostapd_eid_wmm(hapd, tailpos);
1901
1902#ifdef CONFIG_WPS
1903 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
1904 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
1905 wpabuf_len(hapd->wps_beacon_ie));
1906 tailpos += wpabuf_len(hapd->wps_beacon_ie);
1907 }
1908#endif /* CONFIG_WPS */
1909
1910#ifdef CONFIG_P2P
1911 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
1912 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
1913 wpabuf_len(hapd->p2p_beacon_ie));
1914 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
1915 }
1916#endif /* CONFIG_P2P */
1917#ifdef CONFIG_P2P_MANAGER
1918 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
1919 P2P_MANAGE)
1920 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
1921#endif /* CONFIG_P2P_MANAGER */
1922
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001923#ifdef CONFIG_HS20
1924 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
1925#endif /* CONFIG_HS20 */
1926
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001927 tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001928 tailpos = hostapd_eid_owe_trans(hapd, tailpos,
1929 tail + tail_len - tailpos);
Hai Shalomfdcde762020-04-02 11:19:20 -07001930 tailpos = hostapd_eid_dpp_cc(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001931
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001932 if (hapd->conf->vendor_elements) {
1933 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
1934 wpabuf_len(hapd->conf->vendor_elements));
1935 tailpos += wpabuf_len(hapd->conf->vendor_elements);
1936 }
1937
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001938 tail_len = tailpos > tail ? tailpos - tail : 0;
1939
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001940 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
1941#endif /* NEED_AP_MLME */
1942
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001943 params->head = (u8 *) head;
1944 params->head_len = head_len;
1945 params->tail = tail;
1946 params->tail_len = tail_len;
1947 params->proberesp = resp;
1948 params->proberesp_len = resp_len;
1949 params->dtim_period = hapd->conf->dtim_period;
1950 params->beacon_int = hapd->iconf->beacon_int;
1951 params->basic_rates = hapd->iface->basic_rates;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001952 params->beacon_rate = hapd->iconf->beacon_rate;
1953 params->rate_type = hapd->iconf->rate_type;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001954 params->ssid = hapd->conf->ssid.ssid;
1955 params->ssid_len = hapd->conf->ssid.ssid_len;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001956 if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
1957 (WPA_PROTO_WPA | WPA_PROTO_RSN))
1958 params->pairwise_ciphers = hapd->conf->wpa_pairwise |
1959 hapd->conf->rsn_pairwise;
1960 else if (hapd->conf->wpa & WPA_PROTO_RSN)
1961 params->pairwise_ciphers = hapd->conf->rsn_pairwise;
1962 else if (hapd->conf->wpa & WPA_PROTO_WPA)
1963 params->pairwise_ciphers = hapd->conf->wpa_pairwise;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001964 params->group_cipher = hapd->conf->wpa_group;
1965 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
1966 params->auth_algs = hapd->conf->auth_algs;
1967 params->wpa_version = hapd->conf->wpa;
Hai Shalomfdcde762020-04-02 11:19:20 -07001968 params->privacy = hapd->conf->wpa;
1969#ifdef CONFIG_WEP
1970 params->privacy |= hapd->conf->ssid.wep.keys_set ||
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001971 (hapd->conf->ieee802_1x &&
1972 (hapd->conf->default_wep_key_len ||
1973 hapd->conf->individual_wep_key_len));
Hai Shalomfdcde762020-04-02 11:19:20 -07001974#endif /* CONFIG_WEP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001975 switch (hapd->conf->ignore_broadcast_ssid) {
1976 case 0:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001977 params->hide_ssid = NO_SSID_HIDING;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001978 break;
1979 case 1:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001980 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001981 break;
1982 case 2:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001983 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001984 break;
1985 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001986 params->isolate = hapd->conf->isolate;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001987#ifdef NEED_AP_MLME
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001988 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001989 ERP_INFO_USE_PROTECTION);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001990 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001991 hapd->iconf->preamble == SHORT_PREAMBLE;
1992 if (hapd->iface->current_mode &&
1993 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001994 params->short_slot_time =
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001995 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
1996 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001997 params->short_slot_time = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001998 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001999 params->ht_opmode = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002000 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002001 params->ht_opmode = hapd->iface->ht_op_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002002#endif /* NEED_AP_MLME */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002003 params->interworking = hapd->conf->interworking;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002004 if (hapd->conf->interworking &&
2005 !is_zero_ether_addr(hapd->conf->hessid))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002006 params->hessid = hapd->conf->hessid;
2007 params->access_network_type = hapd->conf->access_network_type;
2008 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002009#ifdef CONFIG_P2P
2010 params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
2011#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002012#ifdef CONFIG_HS20
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002013 params->disable_dgaf = hapd->conf->disable_dgaf;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002014 if (hapd->conf->osen) {
2015 params->privacy = 1;
2016 params->osen = 1;
2017 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002018#endif /* CONFIG_HS20 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002019 params->multicast_to_unicast = hapd->conf->multicast_to_unicast;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002020 params->pbss = hapd->conf->pbss;
Hai Shalom74f70d42019-02-11 14:42:39 -08002021
2022 if (hapd->conf->ftm_responder) {
2023 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_FTM_RESPONDER) {
2024 params->ftm_responder = 1;
2025 params->lci = hapd->iface->conf->lci;
2026 params->civic = hapd->iface->conf->civic;
2027 } else {
2028 wpa_printf(MSG_WARNING,
2029 "Not configuring FTM responder as the driver doesn't advertise support for it");
2030 }
2031 }
2032
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002033 return 0;
2034}
2035
2036
2037void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
2038{
2039 os_free(params->tail);
2040 params->tail = NULL;
2041 os_free(params->head);
2042 params->head = NULL;
2043 os_free(params->proberesp);
2044 params->proberesp = NULL;
Sunil Ravi77d572f2023-01-17 23:58:31 +00002045 os_free(params->mbssid_elem);
2046 params->mbssid_elem = NULL;
2047 os_free(params->mbssid_elem_offset);
2048 params->mbssid_elem_offset = NULL;
Sunil Ravi640215c2023-06-28 23:08:09 +00002049 os_free(params->rnr_elem);
2050 params->rnr_elem = NULL;
2051 os_free(params->rnr_elem_offset);
2052 params->rnr_elem_offset = NULL;
Hai Shalom60840252021-02-19 19:02:11 -08002053#ifdef CONFIG_FILS
2054 os_free(params->fd_frame_tmpl);
2055 params->fd_frame_tmpl = NULL;
2056#endif /* CONFIG_FILS */
2057#ifdef CONFIG_IEEE80211AX
2058 os_free(params->unsol_bcast_probe_resp_tmpl);
2059 params->unsol_bcast_probe_resp_tmpl = NULL;
2060#endif /* CONFIG_IEEE80211AX */
Sunil Ravi640215c2023-06-28 23:08:09 +00002061 os_free(params->allowed_freqs);
2062 params->allowed_freqs = NULL;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002063}
2064
2065
Hai Shaloma20dcd72022-02-04 13:43:00 -08002066static int __ieee802_11_set_beacon(struct hostapd_data *hapd)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002067{
2068 struct wpa_driver_ap_params params;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002069 struct hostapd_freq_params freq;
2070 struct hostapd_iface *iface = hapd->iface;
2071 struct hostapd_config *iconf = iface->conf;
Hai Shalom81f62d82019-07-22 12:10:00 -07002072 struct hostapd_hw_modes *cmode = iface->current_mode;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002073 struct wpabuf *beacon, *proberesp, *assocresp;
Sunil Ravi640215c2023-06-28 23:08:09 +00002074 int res, ret = -1, i;
2075 struct hostapd_hw_modes *mode;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002076
Hai Shaloma20dcd72022-02-04 13:43:00 -08002077 if (!hapd->drv_priv) {
2078 wpa_printf(MSG_ERROR, "Interface is disabled");
2079 return -1;
2080 }
2081
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002082 if (hapd->csa_in_progress) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002083 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002084 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002085 }
2086
2087 hapd->beacon_set_done = 1;
2088
2089 if (ieee802_11_build_ap_params(hapd, &params) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002090 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002091
2092 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
2093 0)
2094 goto fail;
2095
2096 params.beacon_ies = beacon;
2097 params.proberesp_ies = proberesp;
2098 params.assocresp_ies = assocresp;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002099 params.reenable = hapd->reenable_beacon;
Hai Shalomc3565922019-10-28 11:58:20 -07002100#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08002101 params.he_spr_ctrl = hapd->iface->conf->spr.sr_control;
2102 params.he_spr_non_srg_obss_pd_max_offset =
2103 hapd->iface->conf->spr.non_srg_obss_pd_max_offset;
Hai Shalomc3565922019-10-28 11:58:20 -07002104 params.he_spr_srg_obss_pd_min_offset =
2105 hapd->iface->conf->spr.srg_obss_pd_min_offset;
2106 params.he_spr_srg_obss_pd_max_offset =
2107 hapd->iface->conf->spr.srg_obss_pd_max_offset;
Hai Shalom60840252021-02-19 19:02:11 -08002108 os_memcpy(params.he_spr_bss_color_bitmap,
2109 hapd->iface->conf->spr.srg_bss_color_bitmap, 8);
2110 os_memcpy(params.he_spr_partial_bssid_bitmap,
2111 hapd->iface->conf->spr.srg_partial_bssid_bitmap, 8);
Hai Shalomfdcde762020-04-02 11:19:20 -07002112 params.he_bss_color_disabled =
2113 hapd->iface->conf->he_op.he_bss_color_disabled;
2114 params.he_bss_color_partial =
2115 hapd->iface->conf->he_op.he_bss_color_partial;
2116 params.he_bss_color = hapd->iface->conf->he_op.he_bss_color;
2117 params.twt_responder = hostapd_get_he_twt_responder(hapd,
2118 IEEE80211_MODE_AP);
Hai Shalom60840252021-02-19 19:02:11 -08002119 params.unsol_bcast_probe_resp_tmpl =
2120 hostapd_unsol_bcast_probe_resp(hapd, &params);
Hai Shalomc3565922019-10-28 11:58:20 -07002121#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002122 hapd->reenable_beacon = 0;
Hai Shalom60840252021-02-19 19:02:11 -08002123#ifdef CONFIG_SAE
2124 params.sae_pwe = hapd->conf->sae_pwe;
2125#endif /* CONFIG_SAE */
2126
2127#ifdef CONFIG_FILS
2128 params.fd_frame_tmpl = hostapd_fils_discovery(hapd, &params);
2129#endif /* CONFIG_FILS */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002130
Sunil Ravi036cec52023-03-29 11:35:17 -07002131#ifdef CONFIG_IEEE80211BE
2132 params.punct_bitmap = iconf->punct_bitmap;
2133#endif /* CONFIG_IEEE80211BE */
2134
Hai Shalom81f62d82019-07-22 12:10:00 -07002135 if (cmode &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002136 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
Hai Shalomc3565922019-10-28 11:58:20 -07002137 iconf->channel, iconf->enable_edmg,
2138 iconf->edmg_channel, iconf->ieee80211n,
Hai Shalom81f62d82019-07-22 12:10:00 -07002139 iconf->ieee80211ac, iconf->ieee80211ax,
Sunil Ravia04bd252022-05-02 22:54:18 -07002140 iconf->ieee80211be,
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002141 iconf->secondary_channel,
Hai Shalom81f62d82019-07-22 12:10:00 -07002142 hostapd_get_oper_chwidth(iconf),
2143 hostapd_get_oper_centr_freq_seg0_idx(iconf),
2144 hostapd_get_oper_centr_freq_seg1_idx(iconf),
2145 cmode->vht_capab,
Sunil Ravia04bd252022-05-02 22:54:18 -07002146 &cmode->he_capab[IEEE80211_MODE_AP],
2147 &cmode->eht_capab[IEEE80211_MODE_AP]) == 0)
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002148 params.freq = &freq;
2149
Sunil Ravi640215c2023-06-28 23:08:09 +00002150 for (i = 0; i < hapd->iface->num_hw_features; i++) {
2151 mode = &hapd->iface->hw_features[i];
2152
2153 if (iconf->hw_mode != HOSTAPD_MODE_IEEE80211ANY &&
2154 iconf->hw_mode != mode->mode)
2155 continue;
2156
2157 hostapd_get_hw_mode_any_channels(hapd, mode,
2158 !(iconf->acs_freq_list.num ||
2159 iconf->acs_ch_list.num),
2160 true, &params.allowed_freqs);
2161 }
2162
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002163 res = hostapd_drv_set_ap(hapd, &params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002164 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002165 if (res)
2166 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
2167 else
2168 ret = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002169fail:
2170 ieee802_11_free_ap_params(&params);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002171 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002172}
2173
2174
Hai Shaloma20dcd72022-02-04 13:43:00 -08002175int ieee802_11_set_beacon(struct hostapd_data *hapd)
2176{
2177 struct hostapd_iface *iface = hapd->iface;
2178 int ret;
2179 size_t i, j;
2180 bool is_6g;
2181
2182 ret = __ieee802_11_set_beacon(hapd);
2183 if (ret != 0)
2184 return ret;
2185
2186 if (!iface->interfaces || iface->interfaces->count <= 1)
2187 return 0;
2188
2189 /* Update Beacon frames in case of 6 GHz colocation */
2190 is_6g = is_6ghz_op_class(iface->conf->op_class);
2191 for (j = 0; j < iface->interfaces->count; j++) {
2192 struct hostapd_iface *colocated;
2193
2194 colocated = iface->interfaces->iface[j];
2195 if (colocated == iface || !colocated || !colocated->conf)
2196 continue;
2197
2198 if (is_6g == is_6ghz_op_class(colocated->conf->op_class))
2199 continue;
2200
2201 for (i = 0; i < colocated->num_bss; i++) {
2202 if (colocated->bss[i] && colocated->bss[i]->started)
2203 __ieee802_11_set_beacon(colocated->bss[i]);
2204 }
2205 }
2206
2207 return 0;
2208}
2209
2210
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002211int ieee802_11_set_beacons(struct hostapd_iface *iface)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002212{
2213 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002214 int ret = 0;
2215
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08002216 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002217 if (iface->bss[i]->started &&
2218 ieee802_11_set_beacon(iface->bss[i]) < 0)
2219 ret = -1;
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08002220 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002221
2222 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002223}
2224
Dmitry Shmidt04949592012-07-19 12:16:46 -07002225
2226/* only update beacons if started */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002227int ieee802_11_update_beacons(struct hostapd_iface *iface)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002228{
2229 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002230 int ret = 0;
2231
2232 for (i = 0; i < iface->num_bss; i++) {
2233 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
2234 ieee802_11_set_beacon(iface->bss[i]) < 0)
2235 ret = -1;
2236 }
2237
2238 return ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002239}
2240
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002241#endif /* CONFIG_NATIVE_WINDOWS */