blob: e50f0a0c976e075b8eeef3fe45d1e9e1bc7eeb37 [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"
Sunil Ravi2a14cf12023-11-21 00:54:38 +000020#include "crypto/sha1.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070021#include "wps/wps_defs.h"
22#include "p2p/p2p.h"
23#include "hostapd.h"
24#include "ieee802_11.h"
25#include "wpa_auth.h"
26#include "wmm.h"
27#include "ap_config.h"
28#include "sta_info.h"
29#include "p2p_hostapd.h"
30#include "ap_drv_ops.h"
31#include "beacon.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070032#include "hs20.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080033#include "dfs.h"
Dmitry Shmidtaca489e2016-09-28 15:44:14 -070034#include "taxonomy.h"
Roshan Pius3a1667e2018-07-03 15:17:14 -070035#include "ieee802_11_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070036
37
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080038#ifdef NEED_AP_MLME
39
Dmitry Shmidt051af732013-10-22 13:52:46 -070040static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
41{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080042 if (len < 2 + 5)
43 return eid;
44
Dmitry Shmidt051af732013-10-22 13:52:46 -070045#ifdef CONFIG_TESTING_OPTIONS
46 if (hapd->conf->bss_load_test_set) {
Dmitry Shmidt051af732013-10-22 13:52:46 -070047 *eid++ = WLAN_EID_BSS_LOAD;
48 *eid++ = 5;
49 os_memcpy(eid, hapd->conf->bss_load_test, 5);
50 eid += 5;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080051 return eid;
Dmitry Shmidt051af732013-10-22 13:52:46 -070052 }
53#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080054 if (hapd->conf->bss_load_update_period) {
55 *eid++ = WLAN_EID_BSS_LOAD;
56 *eid++ = 5;
57 WPA_PUT_LE16(eid, hapd->num_sta);
58 eid += 2;
59 *eid++ = hapd->iface->channel_utilization;
60 WPA_PUT_LE16(eid, 0); /* no available admission capabity */
61 eid += 2;
62 }
Dmitry Shmidt051af732013-10-22 13:52:46 -070063 return eid;
64}
65
66
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070067static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
68{
69 u8 erp = 0;
70
71 if (hapd->iface->current_mode == NULL ||
72 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
73 return 0;
74
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080075 if (hapd->iface->olbc)
76 erp |= ERP_INFO_USE_PROTECTION;
77 if (hapd->iface->num_sta_non_erp > 0) {
78 erp |= ERP_INFO_NON_ERP_PRESENT |
79 ERP_INFO_USE_PROTECTION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070080 }
81 if (hapd->iface->num_sta_no_short_preamble > 0 ||
82 hapd->iconf->preamble == LONG_PREAMBLE)
83 erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
84
85 return erp;
86}
87
88
89static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
90{
Sunil Ravi2a14cf12023-11-21 00:54:38 +000091 enum hostapd_hw_mode hw_mode = hapd->iconf->hw_mode;
92
93 if (hw_mode != HOSTAPD_MODE_IEEE80211G &&
94 hw_mode != HOSTAPD_MODE_IEEE80211B)
95 return eid;
96
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070097 *eid++ = WLAN_EID_DS_PARAMS;
98 *eid++ = 1;
99 *eid++ = hapd->iconf->channel;
100 return eid;
101}
102
103
104static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
105{
106 if (hapd->iface->current_mode == NULL ||
107 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
108 return eid;
109
110 /* Set NonERP_present and use_protection bits if there
111 * are any associated NonERP stations. */
112 /* TODO: use_protection bit can be set to zero even if
113 * there are NonERP stations present. This optimization
114 * might be useful if NonERP stations are "quiet".
115 * See 802.11g/D6 E-1 for recommended practice.
116 * In addition, Non ERP present might be set, if AP detects Non ERP
117 * operation on other APs. */
118
119 /* Add ERP Information element */
120 *eid++ = WLAN_EID_ERP_INFO;
121 *eid++ = 1;
122 *eid++ = ieee802_11_erp_info(hapd);
123
124 return eid;
125}
126
127
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800128static u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid)
129{
130 u8 *pos = eid;
131 u8 local_pwr_constraint = 0;
132 int dfs;
133
134 if (hapd->iface->current_mode == NULL ||
135 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
136 return eid;
137
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700138 /* Let host drivers add this IE if DFS support is offloaded */
139 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)
140 return eid;
141
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800142 /*
143 * There is no DFS support and power constraint was not directly
144 * requested by config option.
145 */
146 if (!hapd->iconf->ieee80211h &&
147 hapd->iconf->local_pwr_constraint == -1)
148 return eid;
149
150 /* Check if DFS is required by regulatory. */
151 dfs = hostapd_is_dfs_required(hapd->iface);
152 if (dfs < 0) {
153 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
154 dfs);
155 dfs = 0;
156 }
157
158 if (dfs == 0 && hapd->iconf->local_pwr_constraint == -1)
159 return eid;
160
161 /*
162 * ieee80211h (DFS) is enabled so Power Constraint element shall
163 * be added when running on DFS channel whenever local_pwr_constraint
164 * is configured or not. In order to meet regulations when TPC is not
165 * implemented using a transmit power that is below the legal maximum
166 * (including any mitigation factor) should help. In this case,
167 * indicate 3 dB below maximum allowed transmit power.
168 */
169 if (hapd->iconf->local_pwr_constraint == -1)
170 local_pwr_constraint = 3;
171
172 /*
173 * A STA that is not an AP shall use a transmit power less than or
174 * equal to the local maximum transmit power level for the channel.
175 * The local maximum transmit power can be calculated from the formula:
176 * local max TX pwr = max TX pwr - local pwr constraint
177 * Where max TX pwr is maximum transmit power level specified for
178 * channel in Country element and local pwr constraint is specified
179 * for channel in this Power Constraint element.
180 */
181
182 /* Element ID */
183 *pos++ = WLAN_EID_PWR_CONSTRAINT;
184 /* Length */
185 *pos++ = 1;
186 /* Local Power Constraint */
187 if (local_pwr_constraint)
188 *pos++ = local_pwr_constraint;
189 else
190 *pos++ = hapd->iconf->local_pwr_constraint;
191
192 return pos;
193}
194
195
Sunil Ravia04bd252022-05-02 22:54:18 -0700196static u8 * hostapd_eid_country_add(struct hostapd_data *hapd, u8 *pos,
197 u8 *end, int chan_spacing,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700198 struct hostapd_channel_data *start,
199 struct hostapd_channel_data *prev)
200{
201 if (end - pos < 3)
202 return pos;
203
204 /* first channel number */
205 *pos++ = start->chan;
206 /* number of channels */
207 *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
208 /* maximum transmit power level */
Sunil Ravia04bd252022-05-02 22:54:18 -0700209 if (!is_6ghz_op_class(hapd->iconf->op_class))
210 *pos++ = start->max_tx_power;
211 else
212 *pos++ = 0; /* Reserved when operating on the 6 GHz band */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700213
214 return pos;
215}
216
217
Sunil Ravia04bd252022-05-02 22:54:18 -0700218static u8 * hostapd_fill_subband_triplets(struct hostapd_data *hapd, u8 *pos,
219 u8 *end)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700220{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700221 int i;
222 struct hostapd_hw_modes *mode;
223 struct hostapd_channel_data *start, *prev;
224 int chan_spacing = 1;
225
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700226 mode = hapd->iface->current_mode;
227 if (mode->mode == HOSTAPD_MODE_IEEE80211A)
228 chan_spacing = 4;
229
230 start = prev = NULL;
231 for (i = 0; i < mode->num_channels; i++) {
232 struct hostapd_channel_data *chan = &mode->channels[i];
233 if (chan->flag & HOSTAPD_CHAN_DISABLED)
234 continue;
235 if (start && prev &&
236 prev->chan + chan_spacing == chan->chan &&
237 start->max_tx_power == chan->max_tx_power) {
238 prev = chan;
239 continue; /* can use same entry */
240 }
241
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000242 if (start && prev)
Sunil Ravia04bd252022-05-02 22:54:18 -0700243 pos = hostapd_eid_country_add(hapd, pos, end,
244 chan_spacing,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700245 start, prev);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700246
247 /* Start new group */
248 start = prev = chan;
249 }
250
251 if (start) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700252 pos = hostapd_eid_country_add(hapd, pos, end, chan_spacing,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700253 start, prev);
254 }
255
Sunil Ravia04bd252022-05-02 22:54:18 -0700256 return pos;
257}
258
259
260static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
261 int max_len)
262{
263 u8 *pos = eid;
264 u8 *end = eid + max_len;
265
266 if (!hapd->iconf->ieee80211d || max_len < 6 ||
267 hapd->iface->current_mode == NULL)
268 return eid;
269
270 *pos++ = WLAN_EID_COUNTRY;
271 pos++; /* length will be set later */
272 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
273 pos += 3;
274
275 if (is_6ghz_op_class(hapd->iconf->op_class)) {
276 /* Force the third octet of the country string to indicate
277 * Global Operating Class (Table E-4) */
278 eid[4] = 0x04;
279
280 /* Operating Triplet field */
281 /* Operating Extension Identifier (>= 201 to indicate this is
282 * not a Subband Triplet field) */
283 *pos++ = 201;
284 /* Operating Class */
285 *pos++ = hapd->iconf->op_class;
286 /* Coverage Class */
287 *pos++ = 0;
288 /* Subband Triplets are required only for the 20 MHz case */
289 if (hapd->iconf->op_class == 131 ||
290 hapd->iconf->op_class == 136)
291 pos = hostapd_fill_subband_triplets(hapd, pos, end);
292 } else {
293 pos = hostapd_fill_subband_triplets(hapd, pos, end);
294 }
295
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700296 if ((pos - eid) & 1) {
297 if (end - pos < 1)
298 return eid;
299 *pos++ = 0; /* pad for 16-bit alignment */
300 }
301
302 eid[1] = (pos - eid) - 2;
303
304 return pos;
305}
306
307
Hai Shalom60840252021-02-19 19:02:11 -0800308const u8 * hostapd_wpa_ie(struct hostapd_data *hapd, u8 eid)
Hai Shalomfdcde762020-04-02 11:19:20 -0700309{
310 const u8 *ies;
311 size_t ies_len;
312
313 ies = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ies_len);
314 if (!ies)
315 return NULL;
316
317 return get_ie(ies, ies_len, eid);
318}
319
320
321static const u8 * hostapd_vendor_wpa_ie(struct hostapd_data *hapd,
322 u32 vendor_type)
323{
324 const u8 *ies;
325 size_t ies_len;
326
327 ies = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ies_len);
328 if (!ies)
329 return NULL;
330
331 return get_vendor_ie(ies, ies_len, vendor_type);
332}
333
334
335static u8 * hostapd_get_rsne(struct hostapd_data *hapd, u8 *pos, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700336{
337 const u8 *ie;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700338
Hai Shalomfdcde762020-04-02 11:19:20 -0700339 ie = hostapd_wpa_ie(hapd, WLAN_EID_RSN);
340 if (!ie || 2U + ie[1] > len)
341 return pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700342
Hai Shalomfdcde762020-04-02 11:19:20 -0700343 os_memcpy(pos, ie, 2 + ie[1]);
344 return pos + 2 + ie[1];
345}
346
347
348static u8 * hostapd_get_mde(struct hostapd_data *hapd, u8 *pos, size_t len)
349{
350 const u8 *ie;
351
352 ie = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN);
353 if (!ie || 2U + ie[1] > len)
354 return pos;
355
356 os_memcpy(pos, ie, 2 + ie[1]);
357 return pos + 2 + ie[1];
358}
359
360
361static u8 * hostapd_get_rsnxe(struct hostapd_data *hapd, u8 *pos, size_t len)
362{
363 const u8 *ie;
364
365#ifdef CONFIG_TESTING_OPTIONS
366 if (hapd->conf->no_beacon_rsnxe) {
367 wpa_printf(MSG_INFO, "TESTING: Do not add RSNXE into Beacon");
368 return pos;
369 }
370#endif /* CONFIG_TESTING_OPTIONS */
371 ie = hostapd_wpa_ie(hapd, WLAN_EID_RSNX);
372 if (!ie || 2U + ie[1] > len)
373 return pos;
374
375 os_memcpy(pos, ie, 2 + ie[1]);
376 return pos + 2 + ie[1];
377}
378
379
380static u8 * hostapd_get_wpa_ie(struct hostapd_data *hapd, u8 *pos, size_t len)
381{
382 const u8 *ie;
383
384 ie = hostapd_vendor_wpa_ie(hapd, WPA_IE_VENDOR_TYPE);
385 if (!ie || 2U + ie[1] > len)
386 return pos;
387
388 os_memcpy(pos, ie, 2 + ie[1]);
389 return pos + 2 + ie[1];
390}
391
392
393static u8 * hostapd_get_osen_ie(struct hostapd_data *hapd, u8 *pos, size_t len)
394{
395 const u8 *ie;
396
397 ie = hostapd_vendor_wpa_ie(hapd, OSEN_IE_VENDOR_TYPE);
398 if (!ie || 2U + ie[1] > len)
399 return pos;
400
401 os_memcpy(pos, ie, 2 + ie[1]);
402 return pos + 2 + ie[1];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700403}
404
405
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800406static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
407{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800408#ifdef CONFIG_TESTING_OPTIONS
409 if (hapd->iface->cs_oper_class && hapd->iconf->ecsa_ie_only)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800410 return eid;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800411#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800412
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800413 if (!hapd->cs_freq_params.channel)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800414 return eid;
415
416 *eid++ = WLAN_EID_CHANNEL_SWITCH;
417 *eid++ = 3;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700418 *eid++ = hapd->cs_block_tx;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800419 *eid++ = hapd->cs_freq_params.channel;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700420 *eid++ = hapd->cs_count;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800421
422 return eid;
423}
424
425
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800426static u8 * hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800427{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800428 if (!hapd->cs_freq_params.channel || !hapd->iface->cs_oper_class)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800429 return eid;
430
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800431 *eid++ = WLAN_EID_EXT_CHANSWITCH_ANN;
432 *eid++ = 4;
433 *eid++ = hapd->cs_block_tx;
434 *eid++ = hapd->iface->cs_oper_class;
435 *eid++ = hapd->cs_freq_params.channel;
436 *eid++ = hapd->cs_count;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800437
438 return eid;
439}
440
441
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800442static u8 * hostapd_eid_supported_op_classes(struct hostapd_data *hapd, u8 *eid)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800443{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800444 u8 op_class, channel;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800445
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800446 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) ||
447 !hapd->iface->freq)
448 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800449
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800450 if (ieee80211_freq_to_channel_ext(hapd->iface->freq,
451 hapd->iconf->secondary_channel,
Hai Shalom81f62d82019-07-22 12:10:00 -0700452 hostapd_get_oper_chwidth(hapd->iconf),
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800453 &op_class, &channel) ==
454 NUM_HOSTAPD_MODES)
455 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800456
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800457 *eid++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES;
458 *eid++ = 2;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800459
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800460 /* Current Operating Class */
461 *eid++ = op_class;
462
463 /* TODO: Advertise all the supported operating classes */
464 *eid++ = 0;
465
466 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800467}
468
469
Sunil Ravi77d572f2023-01-17 23:58:31 +0000470static int
471ieee802_11_build_ap_params_mbssid(struct hostapd_data *hapd,
472 struct wpa_driver_ap_params *params)
473{
474 struct hostapd_iface *iface = hapd->iface;
475 struct hostapd_data *tx_bss;
Sunil Ravi640215c2023-06-28 23:08:09 +0000476 size_t len, rnr_len = 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +0000477 u8 elem_count = 0, *elem = NULL, **elem_offset = NULL, *end;
Sunil Ravi640215c2023-06-28 23:08:09 +0000478 u8 rnr_elem_count = 0, *rnr_elem = NULL, **rnr_elem_offset = NULL;
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000479 size_t i;
Sunil Ravi77d572f2023-01-17 23:58:31 +0000480
481 if (!iface->mbssid_max_interfaces ||
482 iface->num_bss > iface->mbssid_max_interfaces ||
483 (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED &&
484 !iface->ema_max_periodicity))
485 goto fail;
486
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000487 /* Make sure bss->xrates_supported is set for all BSSs to know whether
488 * it need to be non-inherited. */
489 for (i = 0; i < iface->num_bss; i++) {
490 u8 buf[100];
491
492 hostapd_eid_ext_supp_rates(iface->bss[i], buf);
493 }
494
Sunil Ravi77d572f2023-01-17 23:58:31 +0000495 tx_bss = hostapd_mbssid_get_tx_bss(hapd);
496 len = hostapd_eid_mbssid_len(tx_bss, WLAN_FC_STYPE_BEACON, &elem_count,
Sunil Ravi640215c2023-06-28 23:08:09 +0000497 NULL, 0, &rnr_len);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000498 if (!len || (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED &&
499 elem_count > iface->ema_max_periodicity))
500 goto fail;
501
502 elem = os_zalloc(len);
503 if (!elem)
504 goto fail;
505
506 elem_offset = os_zalloc(elem_count * sizeof(u8 *));
507 if (!elem_offset)
508 goto fail;
509
Sunil Ravi640215c2023-06-28 23:08:09 +0000510 if (rnr_len) {
511 rnr_elem = os_zalloc(rnr_len);
512 if (!rnr_elem)
513 goto fail;
514
515 rnr_elem_offset = os_calloc(elem_count + 1, sizeof(u8 *));
516 if (!rnr_elem_offset)
517 goto fail;
518 }
519
Sunil Ravi77d572f2023-01-17 23:58:31 +0000520 end = hostapd_eid_mbssid(tx_bss, elem, elem + len, WLAN_FC_STYPE_BEACON,
Sunil Ravi640215c2023-06-28 23:08:09 +0000521 elem_count, elem_offset, NULL, 0, rnr_elem,
522 &rnr_elem_count, rnr_elem_offset, rnr_len);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000523
524 params->mbssid_tx_iface = tx_bss->conf->iface;
525 params->mbssid_index = hostapd_mbssid_get_bss_index(hapd);
526 params->mbssid_elem = elem;
527 params->mbssid_elem_len = end - elem;
528 params->mbssid_elem_count = elem_count;
529 params->mbssid_elem_offset = elem_offset;
Sunil Ravi640215c2023-06-28 23:08:09 +0000530 params->rnr_elem = rnr_elem;
531 params->rnr_elem_len = rnr_len;
532 params->rnr_elem_count = rnr_elem_count;
533 params->rnr_elem_offset = rnr_elem_offset;
Sunil Ravi77d572f2023-01-17 23:58:31 +0000534 if (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED)
535 params->ema = true;
536
537 return 0;
538
539fail:
Sunil Ravi640215c2023-06-28 23:08:09 +0000540 os_free(rnr_elem);
541 os_free(rnr_elem_offset);
542 os_free(elem_offset);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000543 os_free(elem);
544 wpa_printf(MSG_ERROR, "MBSSID: Configuration failed");
545 return -1;
546}
547
548
549static u8 * hostapd_eid_mbssid_config(struct hostapd_data *hapd, u8 *eid,
550 u8 mbssid_elem_count)
551{
552 struct hostapd_iface *iface = hapd->iface;
553
554 if (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED) {
555 *eid++ = WLAN_EID_EXTENSION;
556 *eid++ = 3;
557 *eid++ = WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION;
558 *eid++ = iface->num_bss;
559 *eid++ = mbssid_elem_count;
560 }
561
562 return eid;
563}
564
565
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000566static size_t he_elem_len(struct hostapd_data *hapd)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800567{
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000568 size_t len = 0;
569
570#ifdef CONFIG_IEEE80211AX
571 if (!hapd->iconf->ieee80211ax || hapd->conf->disable_11ax)
572 return len;
573
574 len += 3 + sizeof(struct ieee80211_he_capabilities) +
575 3 + sizeof(struct ieee80211_he_operation) +
576 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
577 3 + sizeof(struct ieee80211_spatial_reuse);
578 if (is_6ghz_op_class(hapd->iconf->op_class)) {
579 len += sizeof(struct ieee80211_he_6ghz_oper_info) +
580 3 + sizeof(struct ieee80211_he_6ghz_band_cap);
581 /* An additional Transmit Power Envelope element for
582 * subordinate client */
583 if (he_reg_is_indoor(hapd->iconf->he_6ghz_reg_pwr_type))
584 len += 4;
585
586 /* An additional Transmit Power Envelope element for
587 * default client with unit interpretation of regulatory
588 * client EIRP */
589 if (hapd->iconf->reg_def_cli_eirp != -1 &&
590 he_reg_is_sp(hapd->iconf->he_6ghz_reg_pwr_type))
591 len += 4;
592 }
593#endif /* CONFIG_IEEE80211AX */
594
595 return len;
596}
597
598
599struct probe_resp_params {
600 const struct ieee80211_mgmt *req;
601 bool is_p2p;
602
603 /* Generated IEs will be included inside an ML element */
604 bool is_ml_sta_info;
605 struct hostapd_data *mld_ap;
606 struct mld_info *mld_info;
607
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800608 struct ieee80211_mgmt *resp;
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000609 size_t resp_len;
610 u8 *csa_pos;
611 u8 *ecsa_pos;
612 const u8 *known_bss;
613 u8 known_bss_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800614
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000615#ifdef CONFIG_IEEE80211AX
616 u8 *cca_pos;
617#endif /* CONFIG_IEEE80211AX */
618};
Sunil Ravi77d572f2023-01-17 23:58:31 +0000619
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000620
621static void hostapd_free_probe_resp_params(struct probe_resp_params *params)
622{
623#ifdef CONFIG_IEEE80211BE
624 if (!params)
625 return;
626 ap_sta_free_sta_profile(params->mld_info);
627 os_free(params->mld_info);
628 params->mld_info = NULL;
629#endif /* CONFIG_IEEE80211BE */
630}
631
632
633static size_t hostapd_probe_resp_elems_len(struct hostapd_data *hapd,
634 struct probe_resp_params *params)
635{
636 size_t buflen = 0;
637
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800638#ifdef CONFIG_WPS
639 if (hapd->wps_probe_resp_ie)
640 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
641#endif /* CONFIG_WPS */
642#ifdef CONFIG_P2P
643 if (hapd->p2p_probe_resp_ie)
644 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
645#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800646#ifdef CONFIG_FST
647 if (hapd->iface->fst_ies)
648 buflen += wpabuf_len(hapd->iface->fst_ies);
649#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700650 if (hapd->conf->vendor_elements)
651 buflen += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800652 if (hapd->conf->vendor_vht) {
653 buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
654 2 + sizeof(struct ieee80211_vht_operation);
655 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800656
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000657 buflen += he_elem_len(hapd);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800658
Sunil Ravia04bd252022-05-02 22:54:18 -0700659#ifdef CONFIG_IEEE80211BE
660 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
661 buflen += hostapd_eid_eht_capab_len(hapd, IEEE80211_MODE_AP);
662 buflen += 3 + sizeof(struct ieee80211_eht_operation);
Sunil Ravi036cec52023-03-29 11:35:17 -0700663 if (hapd->iconf->punct_bitmap)
664 buflen += EHT_OPER_DISABLED_SUBCHAN_BITMAP_SIZE;
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000665
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000666 if (!params->is_ml_sta_info && hapd->conf->mld_ap) {
667 struct hostapd_data *ml_elem_ap =
668 params->mld_ap ? params->mld_ap : hapd;
669
670 buflen += hostapd_eid_eht_ml_beacon_len(
671 ml_elem_ap, params->mld_info, !!params->mld_ap);
672 }
Sunil Ravia04bd252022-05-02 22:54:18 -0700673 }
674#endif /* CONFIG_IEEE80211BE */
675
Sunil Ravi77d572f2023-01-17 23:58:31 +0000676 buflen += hostapd_eid_mbssid_len(hapd, WLAN_FC_STYPE_PROBE_RESP, NULL,
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000677 params->known_bss,
678 params->known_bss_len, NULL);
679 if (!params->is_ml_sta_info)
680 buflen += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_PROBE_RESP);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800681 buflen += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700682 buflen += hostapd_eid_owe_trans_len(hapd);
Hai Shalomfdcde762020-04-02 11:19:20 -0700683 buflen += hostapd_eid_dpp_cc_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800684
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000685 return buflen;
686}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800687
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800688
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000689static u8 * hostapd_probe_resp_fill_elems(struct hostapd_data *hapd,
690 struct probe_resp_params *params,
691 u8 *pos, size_t len)
692{
693 u8 *csa_pos;
694 u8 *epos;
Sunil8cd6f4d2022-06-28 18:40:46 +0000695
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000696 epos = pos + len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800697
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000698 if (!params->is_ml_sta_info) {
699 *pos++ = WLAN_EID_SSID;
700 *pos++ = hapd->conf->ssid.ssid_len;
701 os_memcpy(pos, hapd->conf->ssid.ssid,
702 hapd->conf->ssid.ssid_len);
703 pos += hapd->conf->ssid.ssid_len;
704 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800705
706 /* Supported rates */
707 pos = hostapd_eid_supp_rates(hapd, pos);
708
709 /* DS Params */
710 pos = hostapd_eid_ds_params(hapd, pos);
711
712 pos = hostapd_eid_country(hapd, pos, epos - pos);
713
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800714 /* Power Constraint element */
715 pos = hostapd_eid_pwr_constraint(hapd, pos);
716
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000717 /*
718 * CSA IE
719 * TODO: This should be included inside the ML sta profile
720 */
721 if (!params->is_ml_sta_info) {
722 csa_pos = hostapd_eid_csa(hapd, pos);
723 if (csa_pos != pos)
724 params->csa_pos = csa_pos - 1;
725 else
726 params->csa_pos = NULL;
727 pos = csa_pos;
728 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800729
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800730 /* ERP Information element */
731 pos = hostapd_eid_erp_info(hapd, pos);
732
733 /* Extended supported rates */
734 pos = hostapd_eid_ext_supp_rates(hapd, pos);
735
Hai Shalomfdcde762020-04-02 11:19:20 -0700736 pos = hostapd_get_rsne(hapd, pos, epos - pos);
Dmitry Shmidt051af732013-10-22 13:52:46 -0700737 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000738 pos = hostapd_eid_mbssid(hapd, pos, epos, WLAN_FC_STYPE_PROBE_RESP, 0,
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000739 NULL, params->known_bss, params->known_bss_len,
740 NULL, NULL, NULL, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800741 pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700742 pos = hostapd_get_mde(hapd, pos, epos - pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800743
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000744 /*
745 * eCSA IE
746 * TODO: This should be included inside the ML sta profile
747 */
748 if (!params->is_ml_sta_info) {
749 csa_pos = hostapd_eid_ecsa(hapd, pos);
750 if (csa_pos != pos)
751 params->ecsa_pos = csa_pos - 1;
752 else
753 params->ecsa_pos = NULL;
754 pos = csa_pos;
755 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800756
757 pos = hostapd_eid_supported_op_classes(hapd, pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800758 pos = hostapd_eid_ht_capabilities(hapd, pos);
759 pos = hostapd_eid_ht_operation(hapd, pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800760
Sunil Ravi77d572f2023-01-17 23:58:31 +0000761 /* Probe Response frames always include all non-TX profiles except
762 * when a list of known BSSes is included in the Probe Request frame. */
763 pos = hostapd_eid_ext_capab(hapd, pos,
764 hapd->iconf->mbssid >= MBSSID_ENABLED &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000765 !params->known_bss_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800766
767 pos = hostapd_eid_time_adv(hapd, pos);
768 pos = hostapd_eid_time_zone(hapd, pos);
769
770 pos = hostapd_eid_interworking(hapd, pos);
771 pos = hostapd_eid_adv_proto(hapd, pos);
772 pos = hostapd_eid_roaming_consortium(hapd, pos);
773
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800774#ifdef CONFIG_FST
775 if (hapd->iface->fst_ies) {
776 os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies),
777 wpabuf_len(hapd->iface->fst_ies));
778 pos += wpabuf_len(hapd->iface->fst_ies);
779 }
780#endif /* CONFIG_FST */
781
Dmitry Shmidt04949592012-07-19 12:16:46 -0700782#ifdef CONFIG_IEEE80211AC
Hai Shalomc3565922019-10-28 11:58:20 -0700783 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
784 !is_6ghz_op_class(hapd->iconf->op_class)) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700785 pos = hostapd_eid_vht_capabilities(hapd, pos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800786 pos = hostapd_eid_vht_operation(hapd, pos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800787 pos = hostapd_eid_txpower_envelope(hapd, pos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800788 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800789#endif /* CONFIG_IEEE80211AC */
790
Hai Shalom60840252021-02-19 19:02:11 -0800791#ifdef CONFIG_IEEE80211AX
792 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax &&
793 is_6ghz_op_class(hapd->iconf->op_class))
794 pos = hostapd_eid_txpower_envelope(hapd, pos);
795#endif /* CONFIG_IEEE80211AX */
796
Hai Shaloma20dcd72022-02-04 13:43:00 -0800797 pos = hostapd_eid_wb_chsw_wrapper(hapd, pos);
Hai Shalom899fcc72020-10-19 14:38:18 -0700798
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000799 if (!params->is_ml_sta_info)
800 pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_PROBE_RESP);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800801 pos = hostapd_eid_fils_indic(hapd, pos, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -0700802 pos = hostapd_get_rsnxe(hapd, pos, epos - pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800803
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700804#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -0800805 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700806 u8 *cca_pos;
807
Hai Shalom81f62d82019-07-22 12:10:00 -0700808 pos = hostapd_eid_he_capab(hapd, pos, IEEE80211_MODE_AP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700809 pos = hostapd_eid_he_operation(hapd, pos);
Sunil Ravia04bd252022-05-02 22:54:18 -0700810
811 /* BSS Color Change Announcement element */
812 cca_pos = hostapd_eid_cca(hapd, pos);
813 if (cca_pos != pos)
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000814 params->cca_pos = cca_pos - 2;
815 else
816 params->cca_pos = NULL;
Sunil Ravia04bd252022-05-02 22:54:18 -0700817 pos = cca_pos;
818
Hai Shalom81f62d82019-07-22 12:10:00 -0700819 pos = hostapd_eid_spatial_reuse(hapd, pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700820 pos = hostapd_eid_he_mu_edca_parameter_set(hapd, pos);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700821 pos = hostapd_eid_he_6ghz_band_cap(hapd, pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700822 }
823#endif /* CONFIG_IEEE80211AX */
824
Sunil Ravia04bd252022-05-02 22:54:18 -0700825#ifdef CONFIG_IEEE80211BE
826 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000827 struct hostapd_data *ml_elem_ap =
828 params->mld_ap ? params->mld_ap : hapd;
829
830 if (ml_elem_ap->conf->mld_ap)
831 pos = hostapd_eid_eht_ml_beacon(
832 ml_elem_ap, params->mld_info,
833 pos, !!params->mld_ap);
834
Sunil Ravia04bd252022-05-02 22:54:18 -0700835 pos = hostapd_eid_eht_capab(hapd, pos, IEEE80211_MODE_AP);
836 pos = hostapd_eid_eht_operation(hapd, pos);
837 }
838#endif /* CONFIG_IEEE80211BE */
839
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800840#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800841 if (hapd->conf->vendor_vht)
842 pos = hostapd_eid_vendor_vht(hapd, pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700843#endif /* CONFIG_IEEE80211AC */
844
Hai Shalomfdcde762020-04-02 11:19:20 -0700845 /* WPA / OSEN */
846 pos = hostapd_get_wpa_ie(hapd, pos, epos - pos);
847 pos = hostapd_get_osen_ie(hapd, pos, epos - pos);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800848
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800849 /* Wi-Fi Alliance WMM */
850 pos = hostapd_eid_wmm(hapd, pos);
851
852#ifdef CONFIG_WPS
853 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
854 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
855 wpabuf_len(hapd->wps_probe_resp_ie));
856 pos += wpabuf_len(hapd->wps_probe_resp_ie);
857 }
858#endif /* CONFIG_WPS */
859
860#ifdef CONFIG_P2P
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000861 if ((hapd->conf->p2p & P2P_ENABLED) && params->is_p2p &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800862 hapd->p2p_probe_resp_ie) {
863 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
864 wpabuf_len(hapd->p2p_probe_resp_ie));
865 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
866 }
867#endif /* CONFIG_P2P */
868#ifdef CONFIG_P2P_MANAGER
869 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
870 P2P_MANAGE)
871 pos = hostapd_eid_p2p_manage(hapd, pos);
872#endif /* CONFIG_P2P_MANAGER */
873
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700874#ifdef CONFIG_HS20
875 pos = hostapd_eid_hs20_indication(hapd, pos);
876#endif /* CONFIG_HS20 */
877
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000878 pos = hostapd_eid_mbo(hapd, pos, epos - pos);
879 pos = hostapd_eid_owe_trans(hapd, pos, epos - pos);
880 pos = hostapd_eid_dpp_cc(hapd, pos, epos - pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800881
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700882 if (hapd->conf->vendor_elements) {
883 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
884 wpabuf_len(hapd->conf->vendor_elements));
885 pos += wpabuf_len(hapd->conf->vendor_elements);
886 }
887
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000888 return pos;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800889}
890
891
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000892static void hostapd_gen_probe_resp(struct hostapd_data *hapd,
893 struct probe_resp_params *params)
894{
895 u8 *pos;
896 size_t buflen;
897
898 hapd = hostapd_mbssid_get_tx_bss(hapd);
899
900#define MAX_PROBERESP_LEN 768
901 buflen = MAX_PROBERESP_LEN;
902 buflen += hostapd_probe_resp_elems_len(hapd, params);
903 params->resp = os_zalloc(buflen);
904 if (!params->resp) {
905 params->resp_len = 0;
906 return;
907 }
908
909 params->resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
910 WLAN_FC_STYPE_PROBE_RESP);
911 /* Unicast the response to all requests on bands other than 6 GHz. For
912 * the 6 GHz, unicast is used only if the actual SSID is not included in
913 * the Beacon frames. Otherwise, broadcast response is used per IEEE
914 * Std 802.11ax-2021, 26.17.2.3.2. Broadcast address is also used for
915 * the Probe Response frame template for the unsolicited (i.e., not as
916 * a response to a specific request) case. */
917 if (params->req && (!is_6ghz_op_class(hapd->iconf->op_class) ||
918 hapd->conf->ignore_broadcast_ssid))
919 os_memcpy(params->resp->da, params->req->sa, ETH_ALEN);
920 else
921 os_memset(params->resp->da, 0xff, ETH_ALEN);
922 os_memcpy(params->resp->sa, hapd->own_addr, ETH_ALEN);
923
924 os_memcpy(params->resp->bssid, hapd->own_addr, ETH_ALEN);
925 params->resp->u.probe_resp.beacon_int =
926 host_to_le16(hapd->iconf->beacon_int);
927
928 /* hardware or low-level driver will setup seq_ctrl and timestamp */
929 params->resp->u.probe_resp.capab_info =
930 host_to_le16(hostapd_own_capab_info(hapd));
931
932 pos = hostapd_probe_resp_fill_elems(hapd, params,
933 params->resp->u.probe_resp.variable,
934 buflen);
935
936 params->resp_len = pos - (u8 *) params->resp;
937}
938
939
940#ifdef CONFIG_IEEE80211BE
941static void hostapd_fill_probe_resp_ml_params(struct hostapd_data *hapd,
942 struct probe_resp_params *params,
943 const struct ieee80211_mgmt *mgmt,
944 int mld_id, u16 links)
945{
946 struct probe_resp_params sta_info_params;
947 struct hostapd_data *link;
948 unsigned int probed_mld_id, i, j;
949
950 params->mld_ap = NULL;
951 params->mld_info = os_zalloc(sizeof(*params->mld_info));
952 if (!params->mld_info)
953 return;
954
955 wpa_printf(MSG_DEBUG,
956 "MLD: Got ML probe request with AP MLD ID %d for links %04x",
957 mld_id, links);
958
959 /*
960 * We want to include the AP MLD ID in the response if it was
961 * included in the request.
962 */
963 probed_mld_id = mld_id != -1 ? mld_id : hapd->conf->mld_id;
964
965 for_each_mld_link(link, i, j, hapd->iface->interfaces,
966 probed_mld_id) {
967 struct mld_link_info *link_info;
968 size_t buflen;
969 u8 mld_link_id = link->mld_link_id;
970 u8 *epos;
971 u8 buf[EHT_ML_MAX_STA_PROF_LEN];
972
973 /*
974 * Set mld_ap iff the ML probe request explicitly
975 * requested a specific MLD ID. In that case, the targeted
976 * AP may have been a nontransmitted BSSID on the same
977 * interface.
978 */
979 if (mld_id != -1 && link->iface == hapd->iface)
980 params->mld_ap = link;
981
982 /* Never duplicate main Probe Response frame body */
983 if (link == hapd)
984 continue;
985
986 /* Only include requested links */
987 if (!(BIT(mld_link_id) & links))
988 continue;
989
990 link_info = &params->mld_info->links[mld_link_id];
991
992 sta_info_params.req = params->req;
993 sta_info_params.is_p2p = false;
994 sta_info_params.is_ml_sta_info = true;
995 sta_info_params.mld_ap = NULL;
996 sta_info_params.mld_info = NULL;
997
998 buflen = MAX_PROBERESP_LEN;
999 buflen += hostapd_probe_resp_elems_len(link, &sta_info_params);
1000
1001 if (buflen > EHT_ML_MAX_STA_PROF_LEN) {
1002 wpa_printf(MSG_DEBUG,
1003 "MLD: Not including link %d in ML probe response (%zu bytes is too long)",
1004 mld_link_id, buflen);
1005 goto fail;
1006 }
1007
1008 /*
1009 * NOTE: This does not properly handle inheritance and
1010 * various other things.
1011 */
1012 link_info->valid = true;
1013 epos = buf;
1014
1015 /* Capabilities is the only fixed parameter */
1016 WPA_PUT_LE16(epos, hostapd_own_capab_info(hapd));
1017 epos += 2;
1018
1019 epos = hostapd_probe_resp_fill_elems(
1020 link, &sta_info_params, epos,
1021 EHT_ML_MAX_STA_PROF_LEN - 2);
1022 link_info->resp_sta_profile_len = epos - buf;
1023 os_free(link_info->resp_sta_profile);
1024 link_info->resp_sta_profile = os_memdup(
1025 buf, link_info->resp_sta_profile_len);
1026 if (!link_info->resp_sta_profile)
1027 link_info->resp_sta_profile_len = 0;
1028 os_memcpy(link_info->local_addr, link->own_addr, ETH_ALEN);
1029
1030 wpa_printf(MSG_DEBUG,
1031 "MLD: ML probe response includes link sta info for %d: %u bytes (estimate %zu)",
1032 mld_link_id, link_info->resp_sta_profile_len,
1033 buflen);
1034 }
1035
1036 if (mld_id != -1 && !params->mld_ap) {
1037 wpa_printf(MSG_DEBUG,
1038 "MLD: No nontransmitted BSSID for MLD ID %d",
1039 mld_id);
1040 goto fail;
1041 }
1042
1043 return;
1044
1045fail:
1046 hostapd_free_probe_resp_params(params);
1047 params->mld_ap = NULL;
1048 params->mld_info = NULL;
1049}
1050#endif /* CONFIG_IEEE80211BE */
1051
1052
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001053enum ssid_match_result {
1054 NO_SSID_MATCH,
1055 EXACT_SSID_MATCH,
Hai Shaloma20dcd72022-02-04 13:43:00 -08001056 WILDCARD_SSID_MATCH,
1057 CO_LOCATED_SSID_MATCH,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001058};
1059
1060static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
1061 const u8 *ssid, size_t ssid_len,
1062 const u8 *ssid_list,
Hai Shalomfdcde762020-04-02 11:19:20 -07001063 size_t ssid_list_len,
1064 const u8 *short_ssid_list,
1065 size_t short_ssid_list_len)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001066{
1067 const u8 *pos, *end;
Hai Shaloma20dcd72022-02-04 13:43:00 -08001068 struct hostapd_iface *iface = hapd->iface;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001069 int wildcard = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -08001070 size_t i, j;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001071
1072 if (ssid_len == 0)
1073 wildcard = 1;
1074 if (ssid_len == hapd->conf->ssid.ssid_len &&
1075 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
1076 return EXACT_SSID_MATCH;
1077
Hai Shalomfdcde762020-04-02 11:19:20 -07001078 if (ssid_list) {
1079 pos = ssid_list;
1080 end = ssid_list + ssid_list_len;
1081 while (end - pos >= 2) {
1082 if (2 + pos[1] > end - pos)
1083 break;
1084 if (pos[1] == 0)
1085 wildcard = 1;
1086 if (pos[1] == hapd->conf->ssid.ssid_len &&
1087 os_memcmp(pos + 2, hapd->conf->ssid.ssid,
1088 pos[1]) == 0)
1089 return EXACT_SSID_MATCH;
1090 pos += 2 + pos[1];
1091 }
1092 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001093
Hai Shalomfdcde762020-04-02 11:19:20 -07001094 if (short_ssid_list) {
1095 pos = short_ssid_list;
1096 end = short_ssid_list + short_ssid_list_len;
1097 while (end - pos >= 4) {
1098 if (hapd->conf->ssid.short_ssid == WPA_GET_LE32(pos))
1099 return EXACT_SSID_MATCH;
1100 pos += 4;
1101 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001102 }
1103
Hai Shaloma20dcd72022-02-04 13:43:00 -08001104 if (wildcard)
1105 return WILDCARD_SSID_MATCH;
1106
1107 if (!iface->interfaces || iface->interfaces->count <= 1 ||
1108 is_6ghz_op_class(hapd->iconf->op_class))
1109 return NO_SSID_MATCH;
1110
1111 for (i = 0; i < iface->interfaces->count; i++) {
1112 struct hostapd_iface *colocated;
1113
1114 colocated = iface->interfaces->iface[i];
1115
1116 if (colocated == iface ||
1117 !is_6ghz_op_class(colocated->conf->op_class))
1118 continue;
1119
1120 for (j = 0; j < colocated->num_bss; j++) {
1121 struct hostapd_bss_config *conf;
1122
1123 conf = colocated->bss[j]->conf;
1124 if (ssid_len == conf->ssid.ssid_len &&
1125 os_memcmp(ssid, conf->ssid.ssid, ssid_len) == 0)
1126 return CO_LOCATED_SSID_MATCH;
1127 }
1128 }
1129
1130 return NO_SSID_MATCH;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001131}
1132
1133
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001134void sta_track_expire(struct hostapd_iface *iface, int force)
1135{
1136 struct os_reltime now;
1137 struct hostapd_sta_info *info;
1138
1139 if (!iface->num_sta_seen)
1140 return;
1141
1142 os_get_reltime(&now);
1143 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
1144 list))) {
1145 if (!force &&
1146 !os_reltime_expired(&now, &info->last_seen,
1147 iface->conf->track_sta_max_age))
1148 break;
1149 force = 0;
1150
1151 wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
1152 MACSTR, iface->bss[0]->conf->iface,
1153 MAC2STR(info->addr));
1154 dl_list_del(&info->list);
1155 iface->num_sta_seen--;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001156 sta_track_del(info);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001157 }
1158}
1159
1160
1161static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
1162 const u8 *addr)
1163{
1164 struct hostapd_sta_info *info;
1165
1166 dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001167 if (ether_addr_equal(addr, info->addr))
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001168 return info;
1169
1170 return NULL;
1171}
1172
1173
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001174void sta_track_add(struct hostapd_iface *iface, const u8 *addr, int ssi_signal)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001175{
1176 struct hostapd_sta_info *info;
1177
1178 info = sta_track_get(iface, addr);
1179 if (info) {
1180 /* Move the most recent entry to the end of the list */
1181 dl_list_del(&info->list);
1182 dl_list_add_tail(&iface->sta_seen, &info->list);
1183 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001184 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001185 return;
1186 }
1187
1188 /* Add a new entry */
1189 info = os_zalloc(sizeof(*info));
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001190 if (info == NULL)
1191 return;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001192 os_memcpy(info->addr, addr, ETH_ALEN);
1193 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001194 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001195
1196 if (iface->num_sta_seen >= iface->conf->track_sta_max_num) {
1197 /* Expire oldest entry to make room for a new one */
1198 sta_track_expire(iface, 1);
1199 }
1200
1201 wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
1202 MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr));
1203 dl_list_add_tail(&iface->sta_seen, &info->list);
1204 iface->num_sta_seen++;
1205}
1206
1207
1208struct hostapd_data *
1209sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
1210 const char *ifname)
1211{
1212 struct hapd_interfaces *interfaces = iface->interfaces;
1213 size_t i, j;
1214
1215 for (i = 0; i < interfaces->count; i++) {
1216 struct hostapd_data *hapd = NULL;
1217
1218 iface = interfaces->iface[i];
1219 for (j = 0; j < iface->num_bss; j++) {
1220 hapd = iface->bss[j];
1221 if (os_strcmp(ifname, hapd->conf->iface) == 0)
1222 break;
1223 hapd = NULL;
1224 }
1225
1226 if (hapd && sta_track_get(iface, addr))
1227 return hapd;
1228 }
1229
1230 return NULL;
1231}
1232
1233
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001234#ifdef CONFIG_TAXONOMY
1235void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr,
1236 struct wpabuf **probe_ie_taxonomy)
1237{
1238 struct hostapd_sta_info *info;
1239
1240 info = sta_track_get(iface, addr);
1241 if (!info)
1242 return;
1243
1244 wpabuf_free(*probe_ie_taxonomy);
1245 *probe_ie_taxonomy = info->probe_ie_taxonomy;
1246 info->probe_ie_taxonomy = NULL;
1247}
1248#endif /* CONFIG_TAXONOMY */
1249
1250
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001251#ifdef CONFIG_IEEE80211BE
1252static bool parse_ml_probe_req(const struct ieee80211_eht_ml *ml, size_t ml_len,
1253 int *mld_id, u16 *links)
1254{
1255 u16 ml_control;
1256 const struct element *sub;
1257 const u8 *pos;
1258 size_t len;
1259
1260 *mld_id = -1;
1261 *links = 0xffff;
1262
1263 if (ml_len < sizeof(struct ieee80211_eht_ml))
1264 return false;
1265
1266 ml_control = le_to_host16(ml->ml_control);
1267 if ((ml_control & MULTI_LINK_CONTROL_TYPE_MASK) !=
1268 MULTI_LINK_CONTROL_TYPE_PROBE_REQ) {
1269 wpa_printf(MSG_DEBUG, "MLD: Not an ML probe req");
1270 return false;
1271 }
1272
1273 if (sizeof(struct ieee80211_eht_ml) + 1 > ml_len) {
1274 wpa_printf(MSG_DEBUG, "MLD: ML probe req too short");
1275 return false;
1276 }
1277
1278 pos = ml->variable;
1279 len = pos[0];
1280 if (len < 1 || sizeof(struct ieee80211_eht_ml) + len > ml_len) {
1281 wpa_printf(MSG_DEBUG,
1282 "MLD: ML probe request with invalid length");
1283 return false;
1284 }
1285
1286 if (ml_control & EHT_ML_PRES_BM_PROBE_REQ_AP_MLD_ID) {
1287 if (len < 2) {
1288 wpa_printf(MSG_DEBUG,
1289 "MLD: ML probe req too short for MLD ID");
1290 return false;
1291 }
1292
1293 *mld_id = pos[1];
1294 }
1295 pos += len;
1296
1297 /* Parse subelements (if there are any) */
1298 len = ml_len - len - sizeof(struct ieee80211_eht_ml);
1299 for_each_element_id(sub, 0, pos, len) {
1300 const struct ieee80211_eht_per_sta_profile *sta;
1301 u16 sta_control;
1302
1303 if (*links == 0xffff)
1304 *links = 0;
1305
1306 if (sub->datalen <
1307 sizeof(struct ieee80211_eht_per_sta_profile)) {
1308 wpa_printf(MSG_DEBUG,
1309 "MLD: ML probe req %d too short for sta profile",
1310 sub->datalen);
1311 return false;
1312 }
1313
1314 sta = (struct ieee80211_eht_per_sta_profile *) sub->data;
1315
1316 /*
1317 * Extract the link ID, do not return whether a complete or
1318 * partial profile was requested.
1319 */
1320 sta_control = le_to_host16(sta->sta_control);
1321 *links |= BIT(sta_control & EHT_PER_STA_CTRL_LINK_ID_MSK);
1322 }
1323
1324 if (!for_each_element_completed(sub, pos, len)) {
1325 wpa_printf(MSG_DEBUG,
1326 "MLD: ML probe req sub-elements parsing error");
1327 return false;
1328 }
1329
1330 return true;
1331}
1332#endif /* CONFIG_IEEE80211BE */
1333
1334
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001335void handle_probe_req(struct hostapd_data *hapd,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001336 const struct ieee80211_mgmt *mgmt, size_t len,
1337 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001338{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001339 struct ieee802_11_elems elems;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001340 const u8 *ie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001341 size_t ie_len;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001342 size_t i;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001343 int noack;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001344 enum ssid_match_result res;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001345 int ret;
1346 u16 csa_offs[2];
1347 size_t csa_offs_len;
Hai Shalomfdcde762020-04-02 11:19:20 -07001348 struct radius_sta rad_info;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001349 struct probe_resp_params params;
1350#ifdef CONFIG_IEEE80211BE
1351 int mld_id;
1352 u16 links;
1353#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001354
Hai Shalom60840252021-02-19 19:02:11 -08001355 if (hapd->iconf->rssi_ignore_probe_request && ssi_signal &&
1356 ssi_signal < hapd->iconf->rssi_ignore_probe_request)
1357 return;
1358
Dmitry Shmidte4663042016-04-04 10:07:49 -07001359 if (len < IEEE80211_HDRLEN)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001360 return;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001361 ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001362 if (hapd->iconf->track_sta_max_num)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001363 sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
Dmitry Shmidte4663042016-04-04 10:07:49 -07001364 ie_len = len - IEEE80211_HDRLEN;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001365
Hai Shalomfdcde762020-04-02 11:19:20 -07001366 ret = hostapd_allowed_address(hapd, mgmt->sa, (const u8 *) mgmt, len,
1367 &rad_info, 1);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001368 if (ret == HOSTAPD_ACL_REJECT) {
1369 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
1370 "Ignore Probe Request frame from " MACSTR
1371 " due to ACL reject ", MAC2STR(mgmt->sa));
1372 return;
1373 }
1374
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001375 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
1376 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001377 mgmt->sa, mgmt->da, mgmt->bssid,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001378 ie, ie_len, ssi_signal) > 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001379 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001380
Hai Shalom74f70d42019-02-11 14:42:39 -08001381 if (!hapd->conf->send_probe_response)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001382 return;
1383
1384 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
1385 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
1386 MAC2STR(mgmt->sa));
1387 return;
1388 }
1389
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001390 if ((!elems.ssid || !elems.supp_rates)) {
1391 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
1392 "without SSID or supported rates element",
1393 MAC2STR(mgmt->sa));
1394 return;
1395 }
1396
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001397 /*
1398 * No need to reply if the Probe Request frame was sent on an adjacent
1399 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
1400 * AP with dot11RadioMeasurementActivated set to true, but strictly
1401 * speaking does not allow such ignoring of Probe Request frames if
1402 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
1403 * number of unnecessary Probe Response frames for cases where the STA
1404 * is less likely to see them (Probe Request frame sent on a
1405 * neighboring, but partially overlapping, channel).
1406 */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001407 if (elems.ds_params &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001408 hapd->iface->current_mode &&
1409 (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
1410 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
1411 hapd->iconf->channel != elems.ds_params[0]) {
1412 wpa_printf(MSG_DEBUG,
1413 "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
1414 hapd->iconf->channel, elems.ds_params[0]);
1415 return;
1416 }
1417
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001418#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001419 if (hapd->p2p && hapd->p2p_group && elems.wps_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001420 struct wpabuf *wps;
1421 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
1422 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
1423 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
1424 "due to mismatch with Requested Device "
1425 "Type");
1426 wpabuf_free(wps);
1427 return;
1428 }
1429 wpabuf_free(wps);
1430 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001431
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001432 if (hapd->p2p && hapd->p2p_group && elems.p2p) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001433 struct wpabuf *p2p;
1434 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
1435 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
1436 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
1437 "due to mismatch with Device ID");
1438 wpabuf_free(p2p);
1439 return;
1440 }
1441 wpabuf_free(p2p);
1442 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001443#endif /* CONFIG_P2P */
1444
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001445 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
Hai Shalomfdcde762020-04-02 11:19:20 -07001446 elems.ssid_list_len == 0 && elems.short_ssid_list_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001447 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
1448 "broadcast SSID ignored", MAC2STR(mgmt->sa));
1449 return;
1450 }
1451
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001452#ifdef CONFIG_P2P
1453 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1454 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
1455 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
1456 P2P_WILDCARD_SSID_LEN) == 0) {
1457 /* Process P2P Wildcard SSID like Wildcard SSID */
1458 elems.ssid_len = 0;
1459 }
1460#endif /* CONFIG_P2P */
1461
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001462#ifdef CONFIG_TAXONOMY
1463 {
1464 struct sta_info *sta;
1465 struct hostapd_sta_info *info;
1466
1467 if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) {
1468 taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len);
1469 } else if ((info = sta_track_get(hapd->iface,
1470 mgmt->sa)) != NULL) {
1471 taxonomy_hostapd_sta_info_probe_req(hapd, info,
1472 ie, ie_len);
1473 }
1474 }
1475#endif /* CONFIG_TAXONOMY */
1476
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001477 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
Hai Shalomfdcde762020-04-02 11:19:20 -07001478 elems.ssid_list, elems.ssid_list_len,
1479 elems.short_ssid_list, elems.short_ssid_list_len);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001480 if (res == NO_SSID_MATCH) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001481 if (!(mgmt->da[0] & 0x01)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001482 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001483 " for foreign SSID '%s' (DA " MACSTR ")%s",
Dmitry Shmidt3c479372014-02-04 10:50:36 -08001484 MAC2STR(mgmt->sa),
1485 wpa_ssid_txt(elems.ssid, elems.ssid_len),
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001486 MAC2STR(mgmt->da),
1487 elems.ssid_list ? " (SSID list)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001488 }
1489 return;
1490 }
1491
Hai Shalomfdcde762020-04-02 11:19:20 -07001492 if (hapd->conf->ignore_broadcast_ssid && res == WILDCARD_SSID_MATCH) {
1493 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
1494 "broadcast SSID ignored", MAC2STR(mgmt->sa));
1495 return;
1496 }
1497
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001498#ifdef CONFIG_INTERWORKING
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -07001499 if (hapd->conf->interworking &&
1500 elems.interworking && elems.interworking_len >= 1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001501 u8 ant = elems.interworking[0] & 0x0f;
1502 if (ant != INTERWORKING_ANT_WILDCARD &&
1503 ant != hapd->conf->access_network_type) {
1504 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
1505 " for mismatching ANT %u ignored",
1506 MAC2STR(mgmt->sa), ant);
1507 return;
1508 }
1509 }
1510
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -07001511 if (hapd->conf->interworking && elems.interworking &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001512 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
1513 const u8 *hessid;
1514 if (elems.interworking_len == 7)
1515 hessid = elems.interworking + 1;
1516 else
1517 hessid = elems.interworking + 1 + 2;
1518 if (!is_broadcast_ether_addr(hessid) &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001519 !ether_addr_equal(hessid, hapd->conf->hessid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001520 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
1521 " for mismatching HESSID " MACSTR
1522 " ignored",
1523 MAC2STR(mgmt->sa), MAC2STR(hessid));
1524 return;
1525 }
1526 }
1527#endif /* CONFIG_INTERWORKING */
1528
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001529#ifdef CONFIG_P2P
1530 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1531 supp_rates_11b_only(&elems)) {
1532 /* Indicates support for 11b rates only */
1533 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
1534 MACSTR " with only 802.11b rates",
1535 MAC2STR(mgmt->sa));
1536 return;
1537 }
1538#endif /* CONFIG_P2P */
1539
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001540 /* TODO: verify that supp_rates contains at least one matching rate
1541 * with AP configuration */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001542
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001543 if (hapd->conf->no_probe_resp_if_seen_on &&
1544 is_multicast_ether_addr(mgmt->da) &&
1545 is_multicast_ether_addr(mgmt->bssid) &&
1546 sta_track_seen_on(hapd->iface, mgmt->sa,
1547 hapd->conf->no_probe_resp_if_seen_on)) {
1548 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1549 " since STA has been seen on %s",
1550 hapd->conf->iface, MAC2STR(mgmt->sa),
1551 hapd->conf->no_probe_resp_if_seen_on);
1552 return;
1553 }
1554
1555 if (hapd->conf->no_probe_resp_if_max_sta &&
1556 is_multicast_ether_addr(mgmt->da) &&
1557 is_multicast_ether_addr(mgmt->bssid) &&
1558 hapd->num_sta >= hapd->conf->max_num_sta &&
1559 !ap_get_sta(hapd, mgmt->sa)) {
1560 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1561 " since no room for additional STA",
1562 hapd->conf->iface, MAC2STR(mgmt->sa));
1563 return;
1564 }
1565
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001566#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001567 if (hapd->iconf->ignore_probe_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001568 drand48() < hapd->iconf->ignore_probe_probability) {
1569 wpa_printf(MSG_INFO,
1570 "TESTING: ignoring probe request from " MACSTR,
1571 MAC2STR(mgmt->sa));
1572 return;
1573 }
1574#endif /* CONFIG_TESTING_OPTIONS */
1575
Sunil Ravi77d572f2023-01-17 23:58:31 +00001576 /* Do not send Probe Response frame from a non-transmitting multiple
1577 * BSSID profile unless the Probe Request frame is directed at that
1578 * particular BSS. */
1579 if (hapd != hostapd_mbssid_get_tx_bss(hapd) && res != EXACT_SSID_MATCH)
1580 return;
1581
Roshan Pius3a1667e2018-07-03 15:17:14 -07001582 wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, RX_PROBE_REQUEST "sa=" MACSTR
1583 " signal=%d", MAC2STR(mgmt->sa), ssi_signal);
1584
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001585 os_memset(&params, 0, sizeof(params));
1586
1587#ifdef CONFIG_IEEE80211BE
1588 if (hapd->conf->mld_ap && elems.probe_req_mle &&
1589 parse_ml_probe_req((struct ieee80211_eht_ml *) elems.probe_req_mle,
1590 elems.probe_req_mle_len, &mld_id, &links)) {
1591 hostapd_fill_probe_resp_ml_params(hapd, &params, mgmt,
1592 mld_id, links);
1593 }
1594#endif /* CONFIG_IEEE80211BE */
1595
1596 params.req = mgmt;
1597 params.is_p2p = !!elems.p2p;
1598 params.known_bss = elems.mbssid_known_bss;
1599 params.known_bss_len = elems.mbssid_known_bss_len;
1600 params.is_ml_sta_info = false;
1601
1602 hostapd_gen_probe_resp(hapd, &params);
1603
1604 hostapd_free_probe_resp_params(&params);
1605
1606 if (!params.resp)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001607 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001608
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001609 /*
1610 * If this is a broadcast probe request, apply no ack policy to avoid
1611 * excessive retries.
1612 */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001613 noack = !!(res == WILDCARD_SSID_MATCH &&
1614 is_broadcast_ether_addr(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001615
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001616 csa_offs_len = 0;
1617 if (hapd->csa_in_progress) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001618 if (params.csa_pos)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001619 csa_offs[csa_offs_len++] =
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001620 params.csa_pos - (u8 *) params.resp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001621
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001622 if (params.ecsa_pos)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001623 csa_offs[csa_offs_len++] =
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001624 params.ecsa_pos - (u8 *) params.resp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001625 }
1626
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001627 ret = hostapd_drv_send_mlme(hapd, params.resp, params.resp_len, noack,
Hai Shalomfdcde762020-04-02 11:19:20 -07001628 csa_offs_len ? csa_offs : NULL,
1629 csa_offs_len, 0);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001630
1631 if (ret < 0)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001632 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001633
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001634 os_free(params.resp);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001635
1636 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
1637 "SSID", MAC2STR(mgmt->sa),
1638 elems.ssid_len == 0 ? "broadcast" : "our");
1639}
1640
1641
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001642static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
1643 size_t *resp_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001644{
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001645 struct probe_resp_params params;
1646
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001647 /* check probe response offloading caps and print warnings */
1648 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
1649 return NULL;
1650
1651#ifdef CONFIG_WPS
1652 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
1653 (!(hapd->iface->probe_resp_offloads &
1654 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
1655 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
1656 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
1657 "Probe Response while not supporting this");
1658#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001659
1660#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001661 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
1662 !(hapd->iface->probe_resp_offloads &
1663 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
1664 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
1665 "Probe Response while not supporting this");
1666#endif /* CONFIG_P2P */
1667
1668 if (hapd->conf->interworking &&
1669 !(hapd->iface->probe_resp_offloads &
1670 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
1671 wpa_printf(MSG_WARNING, "Device is trying to offload "
1672 "Interworking Probe Response while not supporting "
1673 "this");
1674
1675 /* Generate a Probe Response template for the non-P2P case */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001676 os_memset(&params, 0, sizeof(params));
1677 params.req = NULL;
1678 params.is_p2p = false;
1679 params.known_bss = NULL;
1680 params.known_bss_len = 0;
1681 params.is_ml_sta_info = false;
1682 params.mld_ap = NULL;
1683 params.mld_info = NULL;
1684
1685 hostapd_gen_probe_resp(hapd, &params);
1686 *resp_len = params.resp_len;
1687 if (!params.resp)
1688 return NULL;
1689
1690 /* TODO: Avoid passing these through struct hostapd_data */
1691 if (params.csa_pos)
1692 hapd->cs_c_off_proberesp = params.csa_pos - (u8 *) params.resp;
1693 if (params.ecsa_pos)
1694 hapd->cs_c_off_ecsa_proberesp = params.ecsa_pos -
1695 (u8 *) params.resp;
1696#ifdef CONFIG_IEEE80211AX
1697 if (params.cca_pos)
1698 hapd->cca_c_off_proberesp = params.cca_pos - (u8 *) params.resp;
1699#endif /* CONFIG_IEEE80211AX */
1700
1701 return (u8 *) params.resp;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001702}
1703
1704#endif /* NEED_AP_MLME */
1705
1706
Hai Shalom60840252021-02-19 19:02:11 -08001707#ifdef CONFIG_IEEE80211AX
1708/* Unsolicited broadcast Probe Response transmission, 6 GHz only */
1709static u8 * hostapd_unsol_bcast_probe_resp(struct hostapd_data *hapd,
1710 struct wpa_driver_ap_params *params)
1711{
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001712 struct probe_resp_params probe_params;
1713
Hai Shalom60840252021-02-19 19:02:11 -08001714 if (!is_6ghz_op_class(hapd->iconf->op_class))
1715 return NULL;
1716
1717 params->unsol_bcast_probe_resp_interval =
1718 hapd->conf->unsol_bcast_probe_resp_interval;
1719
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001720 os_memset(&probe_params, 0, sizeof(probe_params));
1721 probe_params.req = NULL;
1722 probe_params.is_p2p = false;
1723 probe_params.known_bss = NULL;
1724 probe_params.known_bss_len = 0;
1725 probe_params.is_ml_sta_info = false;
1726 probe_params.mld_ap = NULL;
1727 probe_params.mld_info = NULL;
1728
1729 hostapd_gen_probe_resp(hapd, &probe_params);
1730 params->unsol_bcast_probe_resp_tmpl_len = probe_params.resp_len;
1731 return (u8 *) probe_params.resp;
Hai Shalom60840252021-02-19 19:02:11 -08001732}
1733#endif /* CONFIG_IEEE80211AX */
1734
1735
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001736void sta_track_del(struct hostapd_sta_info *info)
1737{
1738#ifdef CONFIG_TAXONOMY
1739 wpabuf_free(info->probe_ie_taxonomy);
1740 info->probe_ie_taxonomy = NULL;
1741#endif /* CONFIG_TAXONOMY */
1742 os_free(info);
1743}
1744
1745
Hai Shalom60840252021-02-19 19:02:11 -08001746#ifdef CONFIG_FILS
1747
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001748static u16 hostapd_gen_fils_discovery_phy_index(struct hostapd_data *hapd)
1749{
1750#ifdef CONFIG_IEEE80211BE
1751 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be)
1752 return FD_CAP_PHY_INDEX_EHT;
1753#endif /* CONFIG_IEEE80211BE */
1754
1755#ifdef CONFIG_IEEE80211AX
1756 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax)
1757 return FD_CAP_PHY_INDEX_HE;
1758#endif /* CONFIG_IEEE80211AX */
1759
1760#ifdef CONFIG_IEEE80211AC
1761 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac)
1762 return FD_CAP_PHY_INDEX_VHT;
1763#endif /* CONFIG_IEEE80211AC */
1764
1765 if (hapd->iconf->ieee80211n && !hapd->conf->disable_11n)
1766 return FD_CAP_PHY_INDEX_HT;
1767
1768 return 0;
1769}
1770
1771
1772static u16 hostapd_gen_fils_discovery_nss(struct hostapd_hw_modes *mode,
1773 u16 phy_index, u8 he_mcs_nss_size)
1774{
1775 u16 nss = 0;
1776
1777 if (!mode)
1778 return 0;
1779
1780 if (phy_index == FD_CAP_PHY_INDEX_HE) {
1781 const u8 *he_mcs = mode->he_capab[IEEE80211_MODE_AP].mcs;
1782 int i;
1783 u16 mcs[6];
1784
1785 os_memset(mcs, 0xff, 6 * sizeof(u16));
1786
1787 if (he_mcs_nss_size == 4) {
1788 mcs[0] = WPA_GET_LE16(&he_mcs[0]);
1789 mcs[1] = WPA_GET_LE16(&he_mcs[2]);
1790 }
1791
1792 if (he_mcs_nss_size == 8) {
1793 mcs[2] = WPA_GET_LE16(&he_mcs[4]);
1794 mcs[3] = WPA_GET_LE16(&he_mcs[6]);
1795 }
1796
1797 if (he_mcs_nss_size == 12) {
1798 mcs[4] = WPA_GET_LE16(&he_mcs[8]);
1799 mcs[5] = WPA_GET_LE16(&he_mcs[10]);
1800 }
1801
1802 for (i = 0; i < HE_NSS_MAX_STREAMS; i++) {
1803 u16 nss_mask = 0x3 << (i * 2);
1804
1805 /*
1806 * If Tx and/or Rx indicate support for a given NSS,
1807 * count it towards the maximum NSS.
1808 */
1809 if (he_mcs_nss_size == 4 &&
1810 (((mcs[0] & nss_mask) != nss_mask) ||
1811 ((mcs[1] & nss_mask) != nss_mask))) {
1812 nss++;
1813 continue;
1814 }
1815
1816 if (he_mcs_nss_size == 8 &&
1817 (((mcs[2] & nss_mask) != nss_mask) ||
1818 ((mcs[3] & nss_mask) != nss_mask))) {
1819 nss++;
1820 continue;
1821 }
1822
1823 if (he_mcs_nss_size == 12 &&
1824 (((mcs[4] & nss_mask) != nss_mask) ||
1825 ((mcs[5] & nss_mask) != nss_mask))) {
1826 nss++;
1827 continue;
1828 }
1829 }
1830 } else if (phy_index == FD_CAP_PHY_INDEX_EHT) {
1831 u8 rx_nss, tx_nss, max_nss = 0, i;
1832 u8 *mcs = mode->eht_capab[IEEE80211_MODE_AP].mcs;
1833
1834 /*
1835 * The Supported EHT-MCS And NSS Set field for the AP contains
1836 * one to three EHT-MCS Map fields based on the supported
1837 * bandwidth. Check the first byte (max NSS for Rx/Tx that
1838 * supports EHT-MCS 0-9) for each bandwidth (<= 80,
1839 * 160, 320) to find the maximum NSS. This assumes that
1840 * the lowest MCS rates support the largest number of spatial
1841 * streams. If values are different between Tx, Rx or the
1842 * bandwidths, choose the highest value.
1843 */
1844 for (i = 0; i < 3; i++) {
1845 rx_nss = mcs[3 * i] & 0x0F;
1846 if (rx_nss > max_nss)
1847 max_nss = rx_nss;
1848
1849 tx_nss = (mcs[3 * i] & 0xF0) >> 4;
1850 if (tx_nss > max_nss)
1851 max_nss = tx_nss;
1852 }
1853
1854 nss = max_nss;
1855 }
1856
1857 if (nss > 4)
1858 return FD_CAP_NSS_5_8 << FD_CAP_NSS_SHIFT;
1859 if (nss)
1860 return (nss - 1) << FD_CAP_NSS_SHIFT;
1861
1862 return 0;
1863}
1864
1865
Hai Shalom60840252021-02-19 19:02:11 -08001866static u16 hostapd_fils_discovery_cap(struct hostapd_data *hapd)
1867{
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001868 u16 cap_info, phy_index;
1869 u8 chwidth = FD_CAP_BSS_CHWIDTH_20, he_mcs_nss_size = 4;
Hai Shalom60840252021-02-19 19:02:11 -08001870 struct hostapd_hw_modes *mode = hapd->iface->current_mode;
1871
1872 cap_info = FD_CAP_ESS;
1873 if (hapd->conf->wpa)
1874 cap_info |= FD_CAP_PRIVACY;
1875
1876 if (is_6ghz_op_class(hapd->iconf->op_class)) {
Hai Shalom60840252021-02-19 19:02:11 -08001877 switch (hapd->iconf->op_class) {
Sunil Ravi036cec52023-03-29 11:35:17 -07001878 case 137:
1879 chwidth = FD_CAP_BSS_CHWIDTH_320;
1880 break;
Hai Shalom60840252021-02-19 19:02:11 -08001881 case 135:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001882 he_mcs_nss_size += 4;
Hai Shalom60840252021-02-19 19:02:11 -08001883 /* fallthrough */
1884 case 134:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001885 he_mcs_nss_size += 4;
Hai Shalom60840252021-02-19 19:02:11 -08001886 chwidth = FD_CAP_BSS_CHWIDTH_160_80_80;
1887 break;
1888 case 133:
1889 chwidth = FD_CAP_BSS_CHWIDTH_80;
1890 break;
1891 case 132:
1892 chwidth = FD_CAP_BSS_CHWIDTH_40;
1893 break;
1894 }
1895 } else {
1896 switch (hostapd_get_oper_chwidth(hapd->iconf)) {
Sunil8cd6f4d2022-06-28 18:40:46 +00001897 case CONF_OPER_CHWIDTH_80P80MHZ:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001898 he_mcs_nss_size += 4;
Hai Shalom60840252021-02-19 19:02:11 -08001899 /* fallthrough */
Sunil8cd6f4d2022-06-28 18:40:46 +00001900 case CONF_OPER_CHWIDTH_160MHZ:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001901 he_mcs_nss_size += 4;
Hai Shalom60840252021-02-19 19:02:11 -08001902 chwidth = FD_CAP_BSS_CHWIDTH_160_80_80;
1903 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00001904 case CONF_OPER_CHWIDTH_80MHZ:
Hai Shalom60840252021-02-19 19:02:11 -08001905 chwidth = FD_CAP_BSS_CHWIDTH_80;
1906 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00001907 case CONF_OPER_CHWIDTH_USE_HT:
Hai Shalom60840252021-02-19 19:02:11 -08001908 if (hapd->iconf->secondary_channel)
1909 chwidth = FD_CAP_BSS_CHWIDTH_40;
1910 else
1911 chwidth = FD_CAP_BSS_CHWIDTH_20;
1912 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00001913 default:
1914 break;
Hai Shalom60840252021-02-19 19:02:11 -08001915 }
Hai Shalom60840252021-02-19 19:02:11 -08001916 }
1917
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001918 phy_index = hostapd_gen_fils_discovery_phy_index(hapd);
Hai Shalom60840252021-02-19 19:02:11 -08001919 cap_info |= phy_index << FD_CAP_PHY_INDEX_SHIFT;
1920 cap_info |= chwidth << FD_CAP_BSS_CHWIDTH_SHIFT;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001921 cap_info |= hostapd_gen_fils_discovery_nss(mode, phy_index,
1922 he_mcs_nss_size);
Hai Shalom60840252021-02-19 19:02:11 -08001923 return cap_info;
1924}
1925
1926
1927static u8 * hostapd_gen_fils_discovery(struct hostapd_data *hapd, size_t *len)
1928{
1929 struct ieee80211_mgmt *head;
1930 const u8 *mobility_domain;
1931 u8 *pos, *length_pos, buf[200];
1932 u16 ctl = 0;
1933 u8 fd_rsn_info[5];
1934 size_t total_len, buf_len;
1935
1936 total_len = 24 + 2 + 12;
1937
1938 /* FILS Discovery Frame Control */
1939 ctl = (sizeof(hapd->conf->ssid.short_ssid) - 1) |
1940 FD_FRAME_CTL_SHORT_SSID_PRESENT |
1941 FD_FRAME_CTL_LENGTH_PRESENT |
1942 FD_FRAME_CTL_CAP_PRESENT;
1943 total_len += 4 + 1 + 2;
1944
1945 /* Check for optional subfields and calculate length */
1946 if (wpa_auth_write_fd_rsn_info(hapd->wpa_auth, fd_rsn_info)) {
1947 ctl |= FD_FRAME_CTL_RSN_INFO_PRESENT;
1948 total_len += sizeof(fd_rsn_info);
1949 }
1950
1951 mobility_domain = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN);
1952 if (mobility_domain) {
1953 ctl |= FD_FRAME_CTL_MD_PRESENT;
1954 total_len += 3;
1955 }
1956
Hai Shaloma20dcd72022-02-04 13:43:00 -08001957 total_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_ACTION);
1958
Hai Shalom60840252021-02-19 19:02:11 -08001959 pos = hostapd_eid_fils_indic(hapd, buf, 0);
1960 buf_len = pos - buf;
1961 total_len += buf_len;
1962
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001963 /* he_elem_len() may return too large a value for FD frame, but that is
1964 * fine here since this is used as the maximum length of the buffer. */
1965 total_len += he_elem_len(hapd);
Sunil Ravia04bd252022-05-02 22:54:18 -07001966
Hai Shalom60840252021-02-19 19:02:11 -08001967 head = os_zalloc(total_len);
1968 if (!head)
1969 return NULL;
1970
1971 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1972 WLAN_FC_STYPE_ACTION);
1973 os_memset(head->da, 0xff, ETH_ALEN);
1974 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1975 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1976
1977 head->u.action.category = WLAN_ACTION_PUBLIC;
1978 head->u.action.u.public_action.action = WLAN_PA_FILS_DISCOVERY;
1979
1980 pos = &head->u.action.u.public_action.variable[0];
1981
1982 /* FILS Discovery Information field */
1983
1984 /* FILS Discovery Frame Control */
1985 WPA_PUT_LE16(pos, ctl);
1986 pos += 2;
1987
1988 /* Hardware or low-level driver will fill in the Timestamp value */
1989 pos += 8;
1990
1991 /* Beacon Interval */
1992 WPA_PUT_LE16(pos, hapd->iconf->beacon_int);
1993 pos += 2;
1994
1995 /* Short SSID */
1996 WPA_PUT_LE32(pos, hapd->conf->ssid.short_ssid);
1997 pos += sizeof(hapd->conf->ssid.short_ssid);
1998
1999 /* Store position of FILS discovery information element Length field */
2000 length_pos = pos++;
2001
2002 /* FD Capability */
2003 WPA_PUT_LE16(pos, hostapd_fils_discovery_cap(hapd));
2004 pos += 2;
2005
2006 /* Operating Class - not present */
2007
2008 /* Primary Channel - not present */
2009
2010 /* AP Configuration Sequence Number - not present */
2011
2012 /* Access Network Options - not present */
2013
2014 /* FD RSN Information */
2015 if (ctl & FD_FRAME_CTL_RSN_INFO_PRESENT) {
2016 os_memcpy(pos, fd_rsn_info, sizeof(fd_rsn_info));
2017 pos += sizeof(fd_rsn_info);
2018 }
2019
2020 /* Channel Center Frequency Segment 1 - not present */
2021
2022 /* Mobility Domain */
2023 if (ctl & FD_FRAME_CTL_MD_PRESENT) {
2024 os_memcpy(pos, &mobility_domain[2], 3);
2025 pos += 3;
2026 }
2027
2028 /* Fill in the Length field value */
2029 *length_pos = pos - (length_pos + 1);
2030
Hai Shaloma20dcd72022-02-04 13:43:00 -08002031 pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_ACTION);
2032
Hai Shalom60840252021-02-19 19:02:11 -08002033 /* FILS Indication element */
2034 if (buf_len) {
2035 os_memcpy(pos, buf, buf_len);
2036 pos += buf_len;
2037 }
2038
Sunil Ravia04bd252022-05-02 22:54:18 -07002039 if (is_6ghz_op_class(hapd->iconf->op_class))
2040 pos = hostapd_eid_txpower_envelope(hapd, pos);
2041
Hai Shalom60840252021-02-19 19:02:11 -08002042 *len = pos - (u8 *) head;
2043 wpa_hexdump(MSG_DEBUG, "FILS Discovery frame template",
2044 head, pos - (u8 *) head);
2045 return (u8 *) head;
2046}
2047
2048
2049/* Configure FILS Discovery frame transmission parameters */
2050static u8 * hostapd_fils_discovery(struct hostapd_data *hapd,
2051 struct wpa_driver_ap_params *params)
2052{
2053 params->fd_max_int = hapd->conf->fils_discovery_max_int;
2054 if (is_6ghz_op_class(hapd->iconf->op_class) &&
2055 params->fd_max_int > FD_MAX_INTERVAL_6GHZ)
2056 params->fd_max_int = FD_MAX_INTERVAL_6GHZ;
2057
2058 params->fd_min_int = hapd->conf->fils_discovery_min_int;
2059 if (params->fd_min_int > params->fd_max_int)
2060 params->fd_min_int = params->fd_max_int;
2061
2062 if (params->fd_max_int)
2063 return hostapd_gen_fils_discovery(hapd,
2064 &params->fd_frame_tmpl_len);
2065
2066 return NULL;
2067}
2068
2069#endif /* CONFIG_FILS */
2070
2071
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002072int ieee802_11_build_ap_params(struct hostapd_data *hapd,
2073 struct wpa_driver_ap_params *params)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002074{
2075 struct ieee80211_mgmt *head = NULL;
2076 u8 *tail = NULL;
2077 size_t head_len = 0, tail_len = 0;
2078 u8 *resp = NULL;
2079 size_t resp_len = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002080#ifdef NEED_AP_MLME
2081 u16 capab_info;
Hai Shalomfdcde762020-04-02 11:19:20 -07002082 u8 *pos, *tailpos, *tailend, *csa_pos;
Sunil Ravi77d572f2023-01-17 23:58:31 +00002083 bool complete = false;
2084#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002085
Sunil Ravi77d572f2023-01-17 23:58:31 +00002086 os_memset(params, 0, sizeof(*params));
2087
2088#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002089#define BEACON_HEAD_BUF_SIZE 256
2090#define BEACON_TAIL_BUF_SIZE 512
2091 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
2092 tail_len = BEACON_TAIL_BUF_SIZE;
2093#ifdef CONFIG_WPS
2094 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
2095 tail_len += wpabuf_len(hapd->wps_beacon_ie);
2096#endif /* CONFIG_WPS */
2097#ifdef CONFIG_P2P
2098 if (hapd->p2p_beacon_ie)
2099 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
2100#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002101#ifdef CONFIG_FST
2102 if (hapd->iface->fst_ies)
2103 tail_len += wpabuf_len(hapd->iface->fst_ies);
2104#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002105 if (hapd->conf->vendor_elements)
2106 tail_len += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08002107
2108#ifdef CONFIG_IEEE80211AC
2109 if (hapd->conf->vendor_vht) {
2110 tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
2111 2 + sizeof(struct ieee80211_vht_operation);
2112 }
2113#endif /* CONFIG_IEEE80211AC */
2114
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002115 tail_len += he_elem_len(hapd);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002116
Sunil Ravia04bd252022-05-02 22:54:18 -07002117#ifdef CONFIG_IEEE80211BE
2118 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
2119 tail_len += hostapd_eid_eht_capab_len(hapd, IEEE80211_MODE_AP);
2120 tail_len += 3 + sizeof(struct ieee80211_eht_operation);
Sunil Ravi036cec52023-03-29 11:35:17 -07002121 if (hapd->iconf->punct_bitmap)
2122 tail_len += EHT_OPER_DISABLED_SUBCHAN_BITMAP_SIZE;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002123
2124 /*
2125 * TODO: Multi-Link element has variable length and can be
2126 * long based on the common info and number of per
2127 * station profiles. For now use 256.
2128 */
2129 if (hapd->conf->mld_ap)
2130 tail_len += 256;
Sunil Ravia04bd252022-05-02 22:54:18 -07002131 }
2132#endif /* CONFIG_IEEE80211BE */
2133
Sunil Ravi77d572f2023-01-17 23:58:31 +00002134 if (hapd->iconf->mbssid == ENHANCED_MBSSID_ENABLED &&
2135 hapd == hostapd_mbssid_get_tx_bss(hapd))
2136 tail_len += 5; /* Multiple BSSID Configuration element */
Hai Shaloma20dcd72022-02-04 13:43:00 -08002137 tail_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_BEACON);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002138 tail_len += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002139 tail_len += hostapd_eid_owe_trans_len(hapd);
Hai Shalomfdcde762020-04-02 11:19:20 -07002140 tail_len += hostapd_eid_dpp_cc_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002141
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002142 tailpos = tail = os_malloc(tail_len);
2143 if (head == NULL || tail == NULL) {
2144 wpa_printf(MSG_ERROR, "Failed to set beacon data");
2145 os_free(head);
2146 os_free(tail);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002147 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002148 }
Hai Shalomfdcde762020-04-02 11:19:20 -07002149 tailend = tail + tail_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002150
2151 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
2152 WLAN_FC_STYPE_BEACON);
2153 head->duration = host_to_le16(0);
2154 os_memset(head->da, 0xff, ETH_ALEN);
2155
2156 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
2157 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
2158 head->u.beacon.beacon_int =
2159 host_to_le16(hapd->iconf->beacon_int);
2160
2161 /* hardware or low-level driver will setup seq_ctrl and timestamp */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002162 capab_info = hostapd_own_capab_info(hapd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002163 head->u.beacon.capab_info = host_to_le16(capab_info);
2164 pos = &head->u.beacon.variable[0];
2165
2166 /* SSID */
2167 *pos++ = WLAN_EID_SSID;
2168 if (hapd->conf->ignore_broadcast_ssid == 2) {
2169 /* clear the data, but keep the correct length of the SSID */
2170 *pos++ = hapd->conf->ssid.ssid_len;
2171 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
2172 pos += hapd->conf->ssid.ssid_len;
2173 } else if (hapd->conf->ignore_broadcast_ssid) {
2174 *pos++ = 0; /* empty SSID */
2175 } else {
2176 *pos++ = hapd->conf->ssid.ssid_len;
2177 os_memcpy(pos, hapd->conf->ssid.ssid,
2178 hapd->conf->ssid.ssid_len);
2179 pos += hapd->conf->ssid.ssid_len;
2180 }
2181
2182 /* Supported rates */
2183 pos = hostapd_eid_supp_rates(hapd, pos);
2184
2185 /* DS Params */
2186 pos = hostapd_eid_ds_params(hapd, pos);
2187
2188 head_len = pos - (u8 *) head;
2189
Hai Shalomfdcde762020-04-02 11:19:20 -07002190 tailpos = hostapd_eid_country(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002191
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002192 /* Power Constraint element */
2193 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
2194
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002195 /* CSA IE */
2196 csa_pos = hostapd_eid_csa(hapd, tailpos);
2197 if (csa_pos != tailpos)
2198 hapd->cs_c_off_beacon = csa_pos - tail - 1;
2199 tailpos = csa_pos;
2200
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002201 /* ERP Information element */
2202 tailpos = hostapd_eid_erp_info(hapd, tailpos);
2203
2204 /* Extended supported rates */
2205 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
2206
Hai Shalomfdcde762020-04-02 11:19:20 -07002207 tailpos = hostapd_get_rsne(hapd, tailpos, tailend - tailpos);
2208 tailpos = hostapd_eid_bss_load(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002209 tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
Hai Shalomfdcde762020-04-02 11:19:20 -07002210 tailend - tailpos);
2211 tailpos = hostapd_get_mde(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt051af732013-10-22 13:52:46 -07002212
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002213 /* eCSA IE */
2214 csa_pos = hostapd_eid_ecsa(hapd, tailpos);
2215 if (csa_pos != tailpos)
2216 hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1;
2217 tailpos = csa_pos;
2218
2219 tailpos = hostapd_eid_supported_op_classes(hapd, tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002220 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
2221 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002222
Sunil Ravi77d572f2023-01-17 23:58:31 +00002223 if (hapd->iconf->mbssid && hapd->iconf->num_bss > 1) {
2224 if (ieee802_11_build_ap_params_mbssid(hapd, params)) {
2225 os_free(head);
2226 os_free(tail);
2227 wpa_printf(MSG_ERROR,
2228 "MBSSID: Failed to set beacon data");
2229 return -1;
2230 }
2231 complete = hapd->iconf->mbssid == MBSSID_ENABLED ||
2232 (hapd->iconf->mbssid == ENHANCED_MBSSID_ENABLED &&
2233 params->mbssid_elem_count == 1);
2234 }
2235
2236 tailpos = hostapd_eid_ext_capab(hapd, tailpos, complete);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002237
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002238 /*
2239 * TODO: Time Advertisement element should only be included in some
2240 * DTIM Beacon frames.
2241 */
2242 tailpos = hostapd_eid_time_adv(hapd, tailpos);
2243
2244 tailpos = hostapd_eid_interworking(hapd, tailpos);
2245 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
2246 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002247
2248#ifdef CONFIG_FST
2249 if (hapd->iface->fst_ies) {
2250 os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies),
2251 wpabuf_len(hapd->iface->fst_ies));
2252 tailpos += wpabuf_len(hapd->iface->fst_ies);
2253 }
2254#endif /* CONFIG_FST */
2255
Dmitry Shmidt04949592012-07-19 12:16:46 -07002256#ifdef CONFIG_IEEE80211AC
Hai Shalom60840252021-02-19 19:02:11 -08002257 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
2258 !is_6ghz_op_class(hapd->iconf->op_class)) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -07002259 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08002260 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002261 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08002262 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002263#endif /* CONFIG_IEEE80211AC */
2264
Hai Shalom60840252021-02-19 19:02:11 -08002265#ifdef CONFIG_IEEE80211AX
2266 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax &&
2267 is_6ghz_op_class(hapd->iconf->op_class))
2268 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
2269#endif /* CONFIG_IEEE80211AX */
2270
Hai Shaloma20dcd72022-02-04 13:43:00 -08002271 tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos);
Hai Shalom899fcc72020-10-19 14:38:18 -07002272
Hai Shaloma20dcd72022-02-04 13:43:00 -08002273 tailpos = hostapd_eid_rnr(hapd, tailpos, WLAN_FC_STYPE_BEACON);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002274 tailpos = hostapd_eid_fils_indic(hapd, tailpos, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -07002275 tailpos = hostapd_get_rsnxe(hapd, tailpos, tailend - tailpos);
Sunil Ravi77d572f2023-01-17 23:58:31 +00002276 tailpos = hostapd_eid_mbssid_config(hapd, tailpos,
2277 params->mbssid_elem_count);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002278
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002279#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08002280 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Sunil Ravia04bd252022-05-02 22:54:18 -07002281 u8 *cca_pos;
2282
Hai Shalom81f62d82019-07-22 12:10:00 -07002283 tailpos = hostapd_eid_he_capab(hapd, tailpos,
2284 IEEE80211_MODE_AP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002285 tailpos = hostapd_eid_he_operation(hapd, tailpos);
Sunil Ravia04bd252022-05-02 22:54:18 -07002286
2287 /* BSS Color Change Announcement element */
2288 cca_pos = hostapd_eid_cca(hapd, tailpos);
2289 if (cca_pos != tailpos)
2290 hapd->cca_c_off_beacon = cca_pos - tail - 2;
2291 tailpos = cca_pos;
2292
Hai Shalom81f62d82019-07-22 12:10:00 -07002293 tailpos = hostapd_eid_spatial_reuse(hapd, tailpos);
Hai Shalomfdcde762020-04-02 11:19:20 -07002294 tailpos = hostapd_eid_he_mu_edca_parameter_set(hapd, tailpos);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002295 tailpos = hostapd_eid_he_6ghz_band_cap(hapd, tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002296 }
2297#endif /* CONFIG_IEEE80211AX */
2298
Sunil Ravia04bd252022-05-02 22:54:18 -07002299#ifdef CONFIG_IEEE80211BE
2300 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002301 if (hapd->conf->mld_ap)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002302 tailpos = hostapd_eid_eht_ml_beacon(hapd, NULL,
2303 tailpos, false);
Sunil Ravia04bd252022-05-02 22:54:18 -07002304 tailpos = hostapd_eid_eht_capab(hapd, tailpos,
2305 IEEE80211_MODE_AP);
2306 tailpos = hostapd_eid_eht_operation(hapd, tailpos);
2307 }
2308#endif /* CONFIG_IEEE80211BE */
2309
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002310#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08002311 if (hapd->conf->vendor_vht)
2312 tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002313#endif /* CONFIG_IEEE80211AC */
2314
Hai Shalomfdcde762020-04-02 11:19:20 -07002315 /* WPA / OSEN */
2316 tailpos = hostapd_get_wpa_ie(hapd, tailpos, tailend - tailpos);
2317 tailpos = hostapd_get_osen_ie(hapd, tailpos, tailend - tailpos);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002318
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002319 /* Wi-Fi Alliance WMM */
2320 tailpos = hostapd_eid_wmm(hapd, tailpos);
2321
2322#ifdef CONFIG_WPS
2323 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
2324 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
2325 wpabuf_len(hapd->wps_beacon_ie));
2326 tailpos += wpabuf_len(hapd->wps_beacon_ie);
2327 }
2328#endif /* CONFIG_WPS */
2329
2330#ifdef CONFIG_P2P
2331 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
2332 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
2333 wpabuf_len(hapd->p2p_beacon_ie));
2334 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
2335 }
2336#endif /* CONFIG_P2P */
2337#ifdef CONFIG_P2P_MANAGER
2338 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
2339 P2P_MANAGE)
2340 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
2341#endif /* CONFIG_P2P_MANAGER */
2342
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002343#ifdef CONFIG_HS20
2344 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
2345#endif /* CONFIG_HS20 */
2346
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002347 tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002348 tailpos = hostapd_eid_owe_trans(hapd, tailpos,
2349 tail + tail_len - tailpos);
Hai Shalomfdcde762020-04-02 11:19:20 -07002350 tailpos = hostapd_eid_dpp_cc(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002351
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002352 if (hapd->conf->vendor_elements) {
2353 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
2354 wpabuf_len(hapd->conf->vendor_elements));
2355 tailpos += wpabuf_len(hapd->conf->vendor_elements);
2356 }
2357
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002358 tail_len = tailpos > tail ? tailpos - tail : 0;
2359
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002360 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
2361#endif /* NEED_AP_MLME */
2362
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002363 /* If key management offload is enabled, configure PSK to the driver. */
2364 if (wpa_key_mgmt_wpa_psk_no_sae(hapd->conf->wpa_key_mgmt) &&
2365 (hapd->iface->drv_flags2 &
2366 WPA_DRIVER_FLAGS2_4WAY_HANDSHAKE_AP_PSK)) {
2367 if (hapd->conf->ssid.wpa_psk && hapd->conf->ssid.wpa_psk_set) {
2368 os_memcpy(params->psk, hapd->conf->ssid.wpa_psk->psk,
2369 PMK_LEN);
2370 params->psk_len = PMK_LEN;
2371 } else if (hapd->conf->ssid.wpa_passphrase &&
2372 pbkdf2_sha1(hapd->conf->ssid.wpa_passphrase,
2373 hapd->conf->ssid.ssid,
2374 hapd->conf->ssid.ssid_len, 4096,
2375 params->psk, PMK_LEN) == 0) {
2376 params->psk_len = PMK_LEN;
2377 }
2378 }
2379
2380#ifdef CONFIG_SAE
2381 /* If SAE offload is enabled, provide password to lower layer for
2382 * SAE authentication and PMK generation.
2383 */
2384 if (wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
2385 (hapd->iface->drv_flags2 & WPA_DRIVER_FLAGS2_SAE_OFFLOAD_AP)) {
2386 if (hostapd_sae_pk_in_use(hapd->conf)) {
2387 wpa_printf(MSG_ERROR,
2388 "SAE PK not supported with SAE offload");
2389 return -1;
2390 }
2391
2392 if (hostapd_sae_pw_id_in_use(hapd->conf)) {
2393 wpa_printf(MSG_ERROR,
2394 "SAE Password Identifiers not supported with SAE offload");
2395 return -1;
2396 }
2397
2398 params->sae_password = sae_get_password(hapd, NULL, NULL, NULL,
2399 NULL, NULL);
2400 if (!params->sae_password) {
2401 wpa_printf(MSG_ERROR, "SAE password not configured for offload");
2402 return -1;
2403 }
2404 }
2405#endif /* CONFIG_SAE */
2406
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002407 params->head = (u8 *) head;
2408 params->head_len = head_len;
2409 params->tail = tail;
2410 params->tail_len = tail_len;
2411 params->proberesp = resp;
2412 params->proberesp_len = resp_len;
2413 params->dtim_period = hapd->conf->dtim_period;
2414 params->beacon_int = hapd->iconf->beacon_int;
2415 params->basic_rates = hapd->iface->basic_rates;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002416 params->beacon_rate = hapd->iconf->beacon_rate;
2417 params->rate_type = hapd->iconf->rate_type;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002418 params->ssid = hapd->conf->ssid.ssid;
2419 params->ssid_len = hapd->conf->ssid.ssid_len;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07002420 if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
2421 (WPA_PROTO_WPA | WPA_PROTO_RSN))
2422 params->pairwise_ciphers = hapd->conf->wpa_pairwise |
2423 hapd->conf->rsn_pairwise;
2424 else if (hapd->conf->wpa & WPA_PROTO_RSN)
2425 params->pairwise_ciphers = hapd->conf->rsn_pairwise;
2426 else if (hapd->conf->wpa & WPA_PROTO_WPA)
2427 params->pairwise_ciphers = hapd->conf->wpa_pairwise;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002428 params->group_cipher = hapd->conf->wpa_group;
2429 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
2430 params->auth_algs = hapd->conf->auth_algs;
2431 params->wpa_version = hapd->conf->wpa;
Hai Shalomfdcde762020-04-02 11:19:20 -07002432 params->privacy = hapd->conf->wpa;
2433#ifdef CONFIG_WEP
2434 params->privacy |= hapd->conf->ssid.wep.keys_set ||
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002435 (hapd->conf->ieee802_1x &&
2436 (hapd->conf->default_wep_key_len ||
2437 hapd->conf->individual_wep_key_len));
Hai Shalomfdcde762020-04-02 11:19:20 -07002438#endif /* CONFIG_WEP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002439 switch (hapd->conf->ignore_broadcast_ssid) {
2440 case 0:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002441 params->hide_ssid = NO_SSID_HIDING;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002442 break;
2443 case 1:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002444 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002445 break;
2446 case 2:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002447 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002448 break;
2449 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002450 params->isolate = hapd->conf->isolate;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002451#ifdef NEED_AP_MLME
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002452 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002453 ERP_INFO_USE_PROTECTION);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002454 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002455 hapd->iconf->preamble == SHORT_PREAMBLE;
2456 if (hapd->iface->current_mode &&
2457 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002458 params->short_slot_time =
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002459 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
2460 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002461 params->short_slot_time = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002462 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002463 params->ht_opmode = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002464 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002465 params->ht_opmode = hapd->iface->ht_op_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002466#endif /* NEED_AP_MLME */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002467 params->interworking = hapd->conf->interworking;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002468 if (hapd->conf->interworking &&
2469 !is_zero_ether_addr(hapd->conf->hessid))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002470 params->hessid = hapd->conf->hessid;
2471 params->access_network_type = hapd->conf->access_network_type;
2472 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002473#ifdef CONFIG_P2P
2474 params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
2475#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002476#ifdef CONFIG_HS20
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002477 params->disable_dgaf = hapd->conf->disable_dgaf;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002478 if (hapd->conf->osen) {
2479 params->privacy = 1;
2480 params->osen = 1;
2481 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002482#endif /* CONFIG_HS20 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002483 params->multicast_to_unicast = hapd->conf->multicast_to_unicast;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002484 params->pbss = hapd->conf->pbss;
Hai Shalom74f70d42019-02-11 14:42:39 -08002485
2486 if (hapd->conf->ftm_responder) {
2487 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_FTM_RESPONDER) {
2488 params->ftm_responder = 1;
2489 params->lci = hapd->iface->conf->lci;
2490 params->civic = hapd->iface->conf->civic;
2491 } else {
2492 wpa_printf(MSG_WARNING,
2493 "Not configuring FTM responder as the driver doesn't advertise support for it");
2494 }
2495 }
2496
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002497#ifdef CONFIG_IEEE80211BE
2498 if (hapd->conf->mld_ap && hapd->iconf->ieee80211be &&
2499 !hapd->conf->disable_11be) {
2500 params->mld_ap = true;
2501 params->mld_link_id = hapd->mld_link_id;
2502 }
2503#endif /* CONFIG_IEEE80211BE */
2504
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002505 return 0;
2506}
2507
2508
2509void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
2510{
2511 os_free(params->tail);
2512 params->tail = NULL;
2513 os_free(params->head);
2514 params->head = NULL;
2515 os_free(params->proberesp);
2516 params->proberesp = NULL;
Sunil Ravi77d572f2023-01-17 23:58:31 +00002517 os_free(params->mbssid_elem);
2518 params->mbssid_elem = NULL;
2519 os_free(params->mbssid_elem_offset);
2520 params->mbssid_elem_offset = NULL;
Sunil Ravi640215c2023-06-28 23:08:09 +00002521 os_free(params->rnr_elem);
2522 params->rnr_elem = NULL;
2523 os_free(params->rnr_elem_offset);
2524 params->rnr_elem_offset = NULL;
Hai Shalom60840252021-02-19 19:02:11 -08002525#ifdef CONFIG_FILS
2526 os_free(params->fd_frame_tmpl);
2527 params->fd_frame_tmpl = NULL;
2528#endif /* CONFIG_FILS */
2529#ifdef CONFIG_IEEE80211AX
2530 os_free(params->unsol_bcast_probe_resp_tmpl);
2531 params->unsol_bcast_probe_resp_tmpl = NULL;
2532#endif /* CONFIG_IEEE80211AX */
Sunil Ravi640215c2023-06-28 23:08:09 +00002533 os_free(params->allowed_freqs);
2534 params->allowed_freqs = NULL;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002535}
2536
2537
Hai Shaloma20dcd72022-02-04 13:43:00 -08002538static int __ieee802_11_set_beacon(struct hostapd_data *hapd)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002539{
2540 struct wpa_driver_ap_params params;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002541 struct hostapd_freq_params freq;
2542 struct hostapd_iface *iface = hapd->iface;
2543 struct hostapd_config *iconf = iface->conf;
Hai Shalom81f62d82019-07-22 12:10:00 -07002544 struct hostapd_hw_modes *cmode = iface->current_mode;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002545 struct wpabuf *beacon, *proberesp, *assocresp;
Sunil Ravi640215c2023-06-28 23:08:09 +00002546 int res, ret = -1, i;
2547 struct hostapd_hw_modes *mode;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002548
Hai Shaloma20dcd72022-02-04 13:43:00 -08002549 if (!hapd->drv_priv) {
2550 wpa_printf(MSG_ERROR, "Interface is disabled");
2551 return -1;
2552 }
2553
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002554 if (hapd->csa_in_progress) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002555 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002556 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002557 }
2558
2559 hapd->beacon_set_done = 1;
2560
2561 if (ieee802_11_build_ap_params(hapd, &params) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002562 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002563
2564 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
2565 0)
2566 goto fail;
2567
2568 params.beacon_ies = beacon;
2569 params.proberesp_ies = proberesp;
2570 params.assocresp_ies = assocresp;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002571 params.reenable = hapd->reenable_beacon;
Hai Shalomc3565922019-10-28 11:58:20 -07002572#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08002573 params.he_spr_ctrl = hapd->iface->conf->spr.sr_control;
2574 params.he_spr_non_srg_obss_pd_max_offset =
2575 hapd->iface->conf->spr.non_srg_obss_pd_max_offset;
Hai Shalomc3565922019-10-28 11:58:20 -07002576 params.he_spr_srg_obss_pd_min_offset =
2577 hapd->iface->conf->spr.srg_obss_pd_min_offset;
2578 params.he_spr_srg_obss_pd_max_offset =
2579 hapd->iface->conf->spr.srg_obss_pd_max_offset;
Hai Shalom60840252021-02-19 19:02:11 -08002580 os_memcpy(params.he_spr_bss_color_bitmap,
2581 hapd->iface->conf->spr.srg_bss_color_bitmap, 8);
2582 os_memcpy(params.he_spr_partial_bssid_bitmap,
2583 hapd->iface->conf->spr.srg_partial_bssid_bitmap, 8);
Hai Shalomfdcde762020-04-02 11:19:20 -07002584 params.he_bss_color_disabled =
2585 hapd->iface->conf->he_op.he_bss_color_disabled;
2586 params.he_bss_color_partial =
2587 hapd->iface->conf->he_op.he_bss_color_partial;
2588 params.he_bss_color = hapd->iface->conf->he_op.he_bss_color;
2589 params.twt_responder = hostapd_get_he_twt_responder(hapd,
2590 IEEE80211_MODE_AP);
Hai Shalom60840252021-02-19 19:02:11 -08002591 params.unsol_bcast_probe_resp_tmpl =
2592 hostapd_unsol_bcast_probe_resp(hapd, &params);
Hai Shalomc3565922019-10-28 11:58:20 -07002593#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002594 hapd->reenable_beacon = 0;
Hai Shalom60840252021-02-19 19:02:11 -08002595#ifdef CONFIG_SAE
2596 params.sae_pwe = hapd->conf->sae_pwe;
2597#endif /* CONFIG_SAE */
2598
2599#ifdef CONFIG_FILS
2600 params.fd_frame_tmpl = hostapd_fils_discovery(hapd, &params);
2601#endif /* CONFIG_FILS */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002602
Sunil Ravi036cec52023-03-29 11:35:17 -07002603#ifdef CONFIG_IEEE80211BE
2604 params.punct_bitmap = iconf->punct_bitmap;
2605#endif /* CONFIG_IEEE80211BE */
2606
Hai Shalom81f62d82019-07-22 12:10:00 -07002607 if (cmode &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002608 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
Hai Shalomc3565922019-10-28 11:58:20 -07002609 iconf->channel, iconf->enable_edmg,
2610 iconf->edmg_channel, iconf->ieee80211n,
Hai Shalom81f62d82019-07-22 12:10:00 -07002611 iconf->ieee80211ac, iconf->ieee80211ax,
Sunil Ravia04bd252022-05-02 22:54:18 -07002612 iconf->ieee80211be,
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002613 iconf->secondary_channel,
Hai Shalom81f62d82019-07-22 12:10:00 -07002614 hostapd_get_oper_chwidth(iconf),
2615 hostapd_get_oper_centr_freq_seg0_idx(iconf),
2616 hostapd_get_oper_centr_freq_seg1_idx(iconf),
2617 cmode->vht_capab,
Sunil Ravia04bd252022-05-02 22:54:18 -07002618 &cmode->he_capab[IEEE80211_MODE_AP],
Sunil Ravi88611412024-06-28 17:34:56 +00002619 &cmode->eht_capab[IEEE80211_MODE_AP]) == 0)
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002620 params.freq = &freq;
2621
Sunil Ravi640215c2023-06-28 23:08:09 +00002622 for (i = 0; i < hapd->iface->num_hw_features; i++) {
2623 mode = &hapd->iface->hw_features[i];
2624
2625 if (iconf->hw_mode != HOSTAPD_MODE_IEEE80211ANY &&
2626 iconf->hw_mode != mode->mode)
2627 continue;
2628
2629 hostapd_get_hw_mode_any_channels(hapd, mode,
2630 !(iconf->acs_freq_list.num ||
2631 iconf->acs_ch_list.num),
2632 true, &params.allowed_freqs);
2633 }
2634
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002635 res = hostapd_drv_set_ap(hapd, &params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002636 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002637 if (res)
2638 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
2639 else
2640 ret = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002641fail:
2642 ieee802_11_free_ap_params(&params);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002643 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002644}
2645
2646
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002647void ieee802_11_set_beacon_per_bss_only(struct hostapd_data *hapd)
2648{
2649 __ieee802_11_set_beacon(hapd);
2650}
2651
2652
Hai Shaloma20dcd72022-02-04 13:43:00 -08002653int ieee802_11_set_beacon(struct hostapd_data *hapd)
2654{
2655 struct hostapd_iface *iface = hapd->iface;
2656 int ret;
2657 size_t i, j;
2658 bool is_6g;
2659
2660 ret = __ieee802_11_set_beacon(hapd);
2661 if (ret != 0)
2662 return ret;
2663
2664 if (!iface->interfaces || iface->interfaces->count <= 1)
2665 return 0;
2666
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002667 /* Update Beacon frames in case of 6 GHz colocation or AP MLD */
Hai Shaloma20dcd72022-02-04 13:43:00 -08002668 is_6g = is_6ghz_op_class(iface->conf->op_class);
2669 for (j = 0; j < iface->interfaces->count; j++) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002670 struct hostapd_iface *other;
2671 bool mld_ap = false;
Hai Shaloma20dcd72022-02-04 13:43:00 -08002672
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002673 other = iface->interfaces->iface[j];
2674 if (other == iface || !other || !other->conf)
Hai Shaloma20dcd72022-02-04 13:43:00 -08002675 continue;
2676
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002677#ifdef CONFIG_IEEE80211BE
Sunil Ravi88611412024-06-28 17:34:56 +00002678 if (hapd->conf->mld_ap && other->bss[0]->conf->mld_ap &&
2679 hapd->conf->mld_id == other->bss[0]->conf->mld_id)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002680 mld_ap = true;
2681#endif /* CONFIG_IEEE80211BE */
2682
2683 if (is_6g == is_6ghz_op_class(other->conf->op_class) &&
2684 !mld_ap)
Hai Shaloma20dcd72022-02-04 13:43:00 -08002685 continue;
2686
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002687 for (i = 0; i < other->num_bss; i++) {
2688 if (other->bss[i] && other->bss[i]->started)
2689 __ieee802_11_set_beacon(other->bss[i]);
Hai Shaloma20dcd72022-02-04 13:43:00 -08002690 }
2691 }
2692
2693 return 0;
2694}
2695
2696
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002697int ieee802_11_set_beacons(struct hostapd_iface *iface)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002698{
2699 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002700 int ret = 0;
2701
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08002702 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002703 if (iface->bss[i]->started &&
2704 ieee802_11_set_beacon(iface->bss[i]) < 0)
2705 ret = -1;
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08002706 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002707
2708 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002709}
2710
Dmitry Shmidt04949592012-07-19 12:16:46 -07002711
2712/* only update beacons if started */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002713int ieee802_11_update_beacons(struct hostapd_iface *iface)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002714{
2715 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002716 int ret = 0;
2717
2718 for (i = 0; i < iface->num_bss; i++) {
2719 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
2720 ieee802_11_set_beacon(iface->bss[i]) < 0)
2721 ret = -1;
2722 }
2723
2724 return ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002725}
2726
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002727#endif /* CONFIG_NATIVE_WINDOWS */