blob: 1b5cea96b23b816fca4c6bc45a67f9487e30473e [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 Ravieb83e2a2024-06-28 17:34:56 +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);
Sunil Ravieb83e2a2024-06-28 17:34:56 +0000246 start = NULL;
247 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700248
249 /* Start new group */
250 start = prev = chan;
251 }
252
253 if (start) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700254 pos = hostapd_eid_country_add(hapd, pos, end, chan_spacing,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700255 start, prev);
256 }
257
Sunil Ravia04bd252022-05-02 22:54:18 -0700258 return pos;
259}
260
261
262static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
263 int max_len)
264{
265 u8 *pos = eid;
266 u8 *end = eid + max_len;
267
268 if (!hapd->iconf->ieee80211d || max_len < 6 ||
269 hapd->iface->current_mode == NULL)
270 return eid;
271
272 *pos++ = WLAN_EID_COUNTRY;
273 pos++; /* length will be set later */
274 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
275 pos += 3;
276
277 if (is_6ghz_op_class(hapd->iconf->op_class)) {
278 /* Force the third octet of the country string to indicate
279 * Global Operating Class (Table E-4) */
280 eid[4] = 0x04;
281
282 /* Operating Triplet field */
283 /* Operating Extension Identifier (>= 201 to indicate this is
284 * not a Subband Triplet field) */
285 *pos++ = 201;
286 /* Operating Class */
287 *pos++ = hapd->iconf->op_class;
288 /* Coverage Class */
289 *pos++ = 0;
290 /* Subband Triplets are required only for the 20 MHz case */
291 if (hapd->iconf->op_class == 131 ||
292 hapd->iconf->op_class == 136)
293 pos = hostapd_fill_subband_triplets(hapd, pos, end);
294 } else {
295 pos = hostapd_fill_subband_triplets(hapd, pos, end);
296 }
297
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700298 if ((pos - eid) & 1) {
299 if (end - pos < 1)
300 return eid;
301 *pos++ = 0; /* pad for 16-bit alignment */
302 }
303
304 eid[1] = (pos - eid) - 2;
305
306 return pos;
307}
308
309
Hai Shalom60840252021-02-19 19:02:11 -0800310const u8 * hostapd_wpa_ie(struct hostapd_data *hapd, u8 eid)
Hai Shalomfdcde762020-04-02 11:19:20 -0700311{
312 const u8 *ies;
313 size_t ies_len;
314
315 ies = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ies_len);
316 if (!ies)
317 return NULL;
318
319 return get_ie(ies, ies_len, eid);
320}
321
322
323static const u8 * hostapd_vendor_wpa_ie(struct hostapd_data *hapd,
324 u32 vendor_type)
325{
326 const u8 *ies;
327 size_t ies_len;
328
329 ies = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ies_len);
330 if (!ies)
331 return NULL;
332
333 return get_vendor_ie(ies, ies_len, vendor_type);
334}
335
336
337static u8 * hostapd_get_rsne(struct hostapd_data *hapd, u8 *pos, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700338{
339 const u8 *ie;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700340
Hai Shalomfdcde762020-04-02 11:19:20 -0700341 ie = hostapd_wpa_ie(hapd, WLAN_EID_RSN);
342 if (!ie || 2U + ie[1] > len)
343 return pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700344
Hai Shalomfdcde762020-04-02 11:19:20 -0700345 os_memcpy(pos, ie, 2 + ie[1]);
346 return pos + 2 + ie[1];
347}
348
349
350static u8 * hostapd_get_mde(struct hostapd_data *hapd, u8 *pos, size_t len)
351{
352 const u8 *ie;
353
354 ie = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN);
355 if (!ie || 2U + ie[1] > len)
356 return pos;
357
358 os_memcpy(pos, ie, 2 + ie[1]);
359 return pos + 2 + ie[1];
360}
361
362
363static u8 * hostapd_get_rsnxe(struct hostapd_data *hapd, u8 *pos, size_t len)
364{
365 const u8 *ie;
366
367#ifdef CONFIG_TESTING_OPTIONS
368 if (hapd->conf->no_beacon_rsnxe) {
369 wpa_printf(MSG_INFO, "TESTING: Do not add RSNXE into Beacon");
370 return pos;
371 }
372#endif /* CONFIG_TESTING_OPTIONS */
373 ie = hostapd_wpa_ie(hapd, WLAN_EID_RSNX);
374 if (!ie || 2U + ie[1] > len)
375 return pos;
376
377 os_memcpy(pos, ie, 2 + ie[1]);
378 return pos + 2 + ie[1];
379}
380
381
382static u8 * hostapd_get_wpa_ie(struct hostapd_data *hapd, u8 *pos, size_t len)
383{
384 const u8 *ie;
385
386 ie = hostapd_vendor_wpa_ie(hapd, WPA_IE_VENDOR_TYPE);
387 if (!ie || 2U + ie[1] > len)
388 return pos;
389
390 os_memcpy(pos, ie, 2 + ie[1]);
391 return pos + 2 + ie[1];
392}
393
394
395static u8 * hostapd_get_osen_ie(struct hostapd_data *hapd, u8 *pos, size_t len)
396{
397 const u8 *ie;
398
399 ie = hostapd_vendor_wpa_ie(hapd, OSEN_IE_VENDOR_TYPE);
400 if (!ie || 2U + ie[1] > len)
401 return pos;
402
403 os_memcpy(pos, ie, 2 + ie[1]);
404 return pos + 2 + ie[1];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700405}
406
407
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800408static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
409{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800410#ifdef CONFIG_TESTING_OPTIONS
411 if (hapd->iface->cs_oper_class && hapd->iconf->ecsa_ie_only)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800412 return eid;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800413#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800414
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800415 if (!hapd->cs_freq_params.channel)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800416 return eid;
417
418 *eid++ = WLAN_EID_CHANNEL_SWITCH;
419 *eid++ = 3;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700420 *eid++ = hapd->cs_block_tx;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800421 *eid++ = hapd->cs_freq_params.channel;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700422 *eid++ = hapd->cs_count;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800423
424 return eid;
425}
426
427
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800428static u8 * hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800429{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800430 if (!hapd->cs_freq_params.channel || !hapd->iface->cs_oper_class)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800431 return eid;
432
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800433 *eid++ = WLAN_EID_EXT_CHANSWITCH_ANN;
434 *eid++ = 4;
435 *eid++ = hapd->cs_block_tx;
436 *eid++ = hapd->iface->cs_oper_class;
437 *eid++ = hapd->cs_freq_params.channel;
438 *eid++ = hapd->cs_count;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800439
440 return eid;
441}
442
443
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800444static u8 * hostapd_eid_supported_op_classes(struct hostapd_data *hapd, u8 *eid)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800445{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800446 u8 op_class, channel;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800447
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800448 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) ||
449 !hapd->iface->freq)
450 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800451
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800452 if (ieee80211_freq_to_channel_ext(hapd->iface->freq,
453 hapd->iconf->secondary_channel,
Hai Shalom81f62d82019-07-22 12:10:00 -0700454 hostapd_get_oper_chwidth(hapd->iconf),
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800455 &op_class, &channel) ==
456 NUM_HOSTAPD_MODES)
457 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800458
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800459 *eid++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES;
460 *eid++ = 2;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800461
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800462 /* Current Operating Class */
463 *eid++ = op_class;
464
465 /* TODO: Advertise all the supported operating classes */
466 *eid++ = 0;
467
468 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800469}
470
471
Sunil Ravi77d572f2023-01-17 23:58:31 +0000472static int
473ieee802_11_build_ap_params_mbssid(struct hostapd_data *hapd,
474 struct wpa_driver_ap_params *params)
475{
476 struct hostapd_iface *iface = hapd->iface;
477 struct hostapd_data *tx_bss;
Sunil Ravi640215c2023-06-28 23:08:09 +0000478 size_t len, rnr_len = 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +0000479 u8 elem_count = 0, *elem = NULL, **elem_offset = NULL, *end;
Sunil Ravi640215c2023-06-28 23:08:09 +0000480 u8 rnr_elem_count = 0, *rnr_elem = NULL, **rnr_elem_offset = NULL;
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000481 size_t i;
Sunil Ravi77d572f2023-01-17 23:58:31 +0000482
483 if (!iface->mbssid_max_interfaces ||
484 iface->num_bss > iface->mbssid_max_interfaces ||
485 (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED &&
486 !iface->ema_max_periodicity))
487 goto fail;
488
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000489 /* Make sure bss->xrates_supported is set for all BSSs to know whether
490 * it need to be non-inherited. */
491 for (i = 0; i < iface->num_bss; i++) {
492 u8 buf[100];
493
494 hostapd_eid_ext_supp_rates(iface->bss[i], buf);
495 }
496
Sunil Ravi77d572f2023-01-17 23:58:31 +0000497 tx_bss = hostapd_mbssid_get_tx_bss(hapd);
498 len = hostapd_eid_mbssid_len(tx_bss, WLAN_FC_STYPE_BEACON, &elem_count,
Sunil Ravi640215c2023-06-28 23:08:09 +0000499 NULL, 0, &rnr_len);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000500 if (!len || (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED &&
501 elem_count > iface->ema_max_periodicity))
502 goto fail;
503
504 elem = os_zalloc(len);
505 if (!elem)
506 goto fail;
507
508 elem_offset = os_zalloc(elem_count * sizeof(u8 *));
509 if (!elem_offset)
510 goto fail;
511
Sunil Ravi640215c2023-06-28 23:08:09 +0000512 if (rnr_len) {
513 rnr_elem = os_zalloc(rnr_len);
514 if (!rnr_elem)
515 goto fail;
516
517 rnr_elem_offset = os_calloc(elem_count + 1, sizeof(u8 *));
518 if (!rnr_elem_offset)
519 goto fail;
520 }
521
Sunil Ravi77d572f2023-01-17 23:58:31 +0000522 end = hostapd_eid_mbssid(tx_bss, elem, elem + len, WLAN_FC_STYPE_BEACON,
Sunil Ravi640215c2023-06-28 23:08:09 +0000523 elem_count, elem_offset, NULL, 0, rnr_elem,
524 &rnr_elem_count, rnr_elem_offset, rnr_len);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000525
526 params->mbssid_tx_iface = tx_bss->conf->iface;
527 params->mbssid_index = hostapd_mbssid_get_bss_index(hapd);
528 params->mbssid_elem = elem;
529 params->mbssid_elem_len = end - elem;
530 params->mbssid_elem_count = elem_count;
531 params->mbssid_elem_offset = elem_offset;
Sunil Ravi640215c2023-06-28 23:08:09 +0000532 params->rnr_elem = rnr_elem;
533 params->rnr_elem_len = rnr_len;
534 params->rnr_elem_count = rnr_elem_count;
535 params->rnr_elem_offset = rnr_elem_offset;
Sunil Ravi77d572f2023-01-17 23:58:31 +0000536 if (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED)
537 params->ema = true;
538
539 return 0;
540
541fail:
Sunil Ravi640215c2023-06-28 23:08:09 +0000542 os_free(rnr_elem);
543 os_free(rnr_elem_offset);
544 os_free(elem_offset);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000545 os_free(elem);
546 wpa_printf(MSG_ERROR, "MBSSID: Configuration failed");
547 return -1;
548}
549
550
551static u8 * hostapd_eid_mbssid_config(struct hostapd_data *hapd, u8 *eid,
552 u8 mbssid_elem_count)
553{
554 struct hostapd_iface *iface = hapd->iface;
555
556 if (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED) {
557 *eid++ = WLAN_EID_EXTENSION;
558 *eid++ = 3;
559 *eid++ = WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION;
560 *eid++ = iface->num_bss;
561 *eid++ = mbssid_elem_count;
562 }
563
564 return eid;
565}
566
567
Sunil Ravieb83e2a2024-06-28 17:34:56 +0000568static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
569 const struct ieee80211_mgmt *req,
570 int is_p2p, size_t *resp_len,
571 const u8 *known_bss, u8 known_bss_len)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800572{
573 struct ieee80211_mgmt *resp;
Sunil Ravieb83e2a2024-06-28 17:34:56 +0000574 u8 *pos, *epos, *csa_pos;
575 size_t buflen;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800576
Sunil Ravieb83e2a2024-06-28 17:34:56 +0000577 hapd = hostapd_mbssid_get_tx_bss(hapd);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000578
Sunil Ravieb83e2a2024-06-28 17:34:56 +0000579#define MAX_PROBERESP_LEN 768
580 buflen = MAX_PROBERESP_LEN;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800581#ifdef CONFIG_WPS
582 if (hapd->wps_probe_resp_ie)
583 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
584#endif /* CONFIG_WPS */
585#ifdef CONFIG_P2P
586 if (hapd->p2p_probe_resp_ie)
587 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
588#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800589#ifdef CONFIG_FST
590 if (hapd->iface->fst_ies)
591 buflen += wpabuf_len(hapd->iface->fst_ies);
592#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700593 if (hapd->conf->vendor_elements)
594 buflen += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800595 if (hapd->conf->vendor_vht) {
596 buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
597 2 + sizeof(struct ieee80211_vht_operation);
598 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800599
Sunil Ravieb83e2a2024-06-28 17:34:56 +0000600#ifdef CONFIG_IEEE80211AX
601 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
602 buflen += 3 + sizeof(struct ieee80211_he_capabilities) +
603 3 + sizeof(struct ieee80211_he_operation) +
604 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
605 3 + sizeof(struct ieee80211_spatial_reuse);
606 if (is_6ghz_op_class(hapd->iconf->op_class)) {
607 buflen += sizeof(struct ieee80211_he_6ghz_oper_info) +
608 3 + sizeof(struct ieee80211_he_6ghz_band_cap);
609 /* An additional Transmit Power Envelope element for
610 * subordinate client */
611 if (hapd->iconf->he_6ghz_reg_pwr_type ==
612 HE_6GHZ_INDOOR_AP)
613 buflen += 4;
614 }
615 }
616#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800617
Sunil Ravia04bd252022-05-02 22:54:18 -0700618#ifdef CONFIG_IEEE80211BE
619 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
620 buflen += hostapd_eid_eht_capab_len(hapd, IEEE80211_MODE_AP);
621 buflen += 3 + sizeof(struct ieee80211_eht_operation);
Sunil Ravi036cec52023-03-29 11:35:17 -0700622 if (hapd->iconf->punct_bitmap)
623 buflen += EHT_OPER_DISABLED_SUBCHAN_BITMAP_SIZE;
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000624
Sunil Ravieb83e2a2024-06-28 17:34:56 +0000625 /*
626 * TODO: Multi-Link element has variable length and can be
627 * long based on the common info and number of per
628 * station profiles. For now use 256.
629 */
630 if (hapd->conf->mld_ap)
631 buflen += 256;
Sunil Ravia04bd252022-05-02 22:54:18 -0700632 }
633#endif /* CONFIG_IEEE80211BE */
634
Sunil Ravi77d572f2023-01-17 23:58:31 +0000635 buflen += hostapd_eid_mbssid_len(hapd, WLAN_FC_STYPE_PROBE_RESP, NULL,
Sunil Ravieb83e2a2024-06-28 17:34:56 +0000636 known_bss, known_bss_len, NULL);
637 buflen += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_PROBE_RESP);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800638 buflen += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700639 buflen += hostapd_eid_owe_trans_len(hapd);
Hai Shalomfdcde762020-04-02 11:19:20 -0700640 buflen += hostapd_eid_dpp_cc_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800641
Sunil Ravieb83e2a2024-06-28 17:34:56 +0000642 resp = os_zalloc(buflen);
643 if (resp == NULL)
644 return NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800645
Sunil Ravieb83e2a2024-06-28 17:34:56 +0000646 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800647
Sunil Ravieb83e2a2024-06-28 17:34:56 +0000648 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
649 WLAN_FC_STYPE_PROBE_RESP);
650 /* Unicast the response to all requests on bands other than 6 GHz. For
651 * the 6 GHz, unicast is used only if the actual SSID is not included in
652 * the Beacon frames. Otherwise, broadcast response is used per IEEE
653 * Std 802.11ax-2021, 26.17.2.3.2. Broadcast address is also used for
654 * the Probe Response frame template for the unsolicited (i.e., not as
655 * a response to a specific request) case. */
656 if (req && (!is_6ghz_op_class(hapd->iconf->op_class) ||
657 hapd->conf->ignore_broadcast_ssid))
658 os_memcpy(resp->da, req->sa, ETH_ALEN);
659 else
660 os_memset(resp->da, 0xff, ETH_ALEN);
Sunil8cd6f4d2022-06-28 18:40:46 +0000661
Sunil Ravieb83e2a2024-06-28 17:34:56 +0000662 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800663
Sunil Ravieb83e2a2024-06-28 17:34:56 +0000664 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
665 resp->u.probe_resp.beacon_int =
666 host_to_le16(hapd->iconf->beacon_int);
667
668 /* hardware or low-level driver will setup seq_ctrl and timestamp */
669 resp->u.probe_resp.capab_info =
670 host_to_le16(hostapd_own_capab_info(hapd));
671
672 pos = resp->u.probe_resp.variable;
673 *pos++ = WLAN_EID_SSID;
674 *pos++ = hapd->conf->ssid.ssid_len;
675 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
676 pos += hapd->conf->ssid.ssid_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800677
678 /* Supported rates */
679 pos = hostapd_eid_supp_rates(hapd, pos);
680
681 /* DS Params */
682 pos = hostapd_eid_ds_params(hapd, pos);
683
684 pos = hostapd_eid_country(hapd, pos, epos - pos);
685
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800686 /* Power Constraint element */
687 pos = hostapd_eid_pwr_constraint(hapd, pos);
688
Sunil Ravieb83e2a2024-06-28 17:34:56 +0000689 /* CSA IE */
690 csa_pos = hostapd_eid_csa(hapd, pos);
691 if (csa_pos != pos)
692 hapd->cs_c_off_proberesp = csa_pos - (u8 *) resp - 1;
693 pos = csa_pos;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800694
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800695 /* ERP Information element */
696 pos = hostapd_eid_erp_info(hapd, pos);
697
698 /* Extended supported rates */
699 pos = hostapd_eid_ext_supp_rates(hapd, pos);
700
Hai Shalomfdcde762020-04-02 11:19:20 -0700701 pos = hostapd_get_rsne(hapd, pos, epos - pos);
Dmitry Shmidt051af732013-10-22 13:52:46 -0700702 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000703 pos = hostapd_eid_mbssid(hapd, pos, epos, WLAN_FC_STYPE_PROBE_RESP, 0,
Sunil Ravieb83e2a2024-06-28 17:34:56 +0000704 NULL, known_bss, known_bss_len, NULL, NULL,
705 NULL, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800706 pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700707 pos = hostapd_get_mde(hapd, pos, epos - pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800708
Sunil Ravieb83e2a2024-06-28 17:34:56 +0000709 /* eCSA IE */
710 csa_pos = hostapd_eid_ecsa(hapd, pos);
711 if (csa_pos != pos)
712 hapd->cs_c_off_ecsa_proberesp = csa_pos - (u8 *) resp - 1;
713 pos = csa_pos;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800714
715 pos = hostapd_eid_supported_op_classes(hapd, pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800716 pos = hostapd_eid_ht_capabilities(hapd, pos);
717 pos = hostapd_eid_ht_operation(hapd, pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800718
Sunil Ravi77d572f2023-01-17 23:58:31 +0000719 /* Probe Response frames always include all non-TX profiles except
720 * when a list of known BSSes is included in the Probe Request frame. */
721 pos = hostapd_eid_ext_capab(hapd, pos,
722 hapd->iconf->mbssid >= MBSSID_ENABLED &&
Sunil Ravieb83e2a2024-06-28 17:34:56 +0000723 !known_bss_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800724
725 pos = hostapd_eid_time_adv(hapd, pos);
726 pos = hostapd_eid_time_zone(hapd, pos);
727
728 pos = hostapd_eid_interworking(hapd, pos);
729 pos = hostapd_eid_adv_proto(hapd, pos);
730 pos = hostapd_eid_roaming_consortium(hapd, pos);
731
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800732#ifdef CONFIG_FST
733 if (hapd->iface->fst_ies) {
734 os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies),
735 wpabuf_len(hapd->iface->fst_ies));
736 pos += wpabuf_len(hapd->iface->fst_ies);
737 }
738#endif /* CONFIG_FST */
739
Dmitry Shmidt04949592012-07-19 12:16:46 -0700740#ifdef CONFIG_IEEE80211AC
Hai Shalomc3565922019-10-28 11:58:20 -0700741 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
742 !is_6ghz_op_class(hapd->iconf->op_class)) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700743 pos = hostapd_eid_vht_capabilities(hapd, pos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800744 pos = hostapd_eid_vht_operation(hapd, pos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800745 pos = hostapd_eid_txpower_envelope(hapd, pos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800746 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800747#endif /* CONFIG_IEEE80211AC */
748
Hai Shalom60840252021-02-19 19:02:11 -0800749#ifdef CONFIG_IEEE80211AX
750 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax &&
751 is_6ghz_op_class(hapd->iconf->op_class))
752 pos = hostapd_eid_txpower_envelope(hapd, pos);
753#endif /* CONFIG_IEEE80211AX */
754
Hai Shaloma20dcd72022-02-04 13:43:00 -0800755 pos = hostapd_eid_wb_chsw_wrapper(hapd, pos);
Hai Shalom899fcc72020-10-19 14:38:18 -0700756
Sunil Ravieb83e2a2024-06-28 17:34:56 +0000757 pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_PROBE_RESP);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800758 pos = hostapd_eid_fils_indic(hapd, pos, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -0700759 pos = hostapd_get_rsnxe(hapd, pos, epos - pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800760
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700761#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -0800762 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700763 u8 *cca_pos;
764
Hai Shalom81f62d82019-07-22 12:10:00 -0700765 pos = hostapd_eid_he_capab(hapd, pos, IEEE80211_MODE_AP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700766 pos = hostapd_eid_he_operation(hapd, pos);
Sunil Ravia04bd252022-05-02 22:54:18 -0700767
768 /* BSS Color Change Announcement element */
769 cca_pos = hostapd_eid_cca(hapd, pos);
770 if (cca_pos != pos)
Sunil Ravieb83e2a2024-06-28 17:34:56 +0000771 hapd->cca_c_off_proberesp = cca_pos - (u8 *) resp - 2;
Sunil Ravia04bd252022-05-02 22:54:18 -0700772 pos = cca_pos;
773
Hai Shalom81f62d82019-07-22 12:10:00 -0700774 pos = hostapd_eid_spatial_reuse(hapd, pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700775 pos = hostapd_eid_he_mu_edca_parameter_set(hapd, pos);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700776 pos = hostapd_eid_he_6ghz_band_cap(hapd, pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700777 }
778#endif /* CONFIG_IEEE80211AX */
779
Sunil Ravia04bd252022-05-02 22:54:18 -0700780#ifdef CONFIG_IEEE80211BE
781 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
Sunil Ravieb83e2a2024-06-28 17:34:56 +0000782 if (hapd->conf->mld_ap)
783 pos = hostapd_eid_eht_basic_ml(hapd, pos, NULL, true);
Sunil Ravia04bd252022-05-02 22:54:18 -0700784 pos = hostapd_eid_eht_capab(hapd, pos, IEEE80211_MODE_AP);
785 pos = hostapd_eid_eht_operation(hapd, pos);
786 }
787#endif /* CONFIG_IEEE80211BE */
788
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800789#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800790 if (hapd->conf->vendor_vht)
791 pos = hostapd_eid_vendor_vht(hapd, pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700792#endif /* CONFIG_IEEE80211AC */
793
Hai Shalomfdcde762020-04-02 11:19:20 -0700794 /* WPA / OSEN */
795 pos = hostapd_get_wpa_ie(hapd, pos, epos - pos);
796 pos = hostapd_get_osen_ie(hapd, pos, epos - pos);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800797
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800798 /* Wi-Fi Alliance WMM */
799 pos = hostapd_eid_wmm(hapd, pos);
800
801#ifdef CONFIG_WPS
802 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
803 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
804 wpabuf_len(hapd->wps_probe_resp_ie));
805 pos += wpabuf_len(hapd->wps_probe_resp_ie);
806 }
807#endif /* CONFIG_WPS */
808
809#ifdef CONFIG_P2P
Sunil Ravieb83e2a2024-06-28 17:34:56 +0000810 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800811 hapd->p2p_probe_resp_ie) {
812 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
813 wpabuf_len(hapd->p2p_probe_resp_ie));
814 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
815 }
816#endif /* CONFIG_P2P */
817#ifdef CONFIG_P2P_MANAGER
818 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
819 P2P_MANAGE)
820 pos = hostapd_eid_p2p_manage(hapd, pos);
821#endif /* CONFIG_P2P_MANAGER */
822
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700823#ifdef CONFIG_HS20
824 pos = hostapd_eid_hs20_indication(hapd, pos);
825#endif /* CONFIG_HS20 */
826
Sunil Ravieb83e2a2024-06-28 17:34:56 +0000827 pos = hostapd_eid_mbo(hapd, pos, (u8 *) resp + buflen - pos);
828 pos = hostapd_eid_owe_trans(hapd, pos, (u8 *) resp + buflen - pos);
829 pos = hostapd_eid_dpp_cc(hapd, pos, (u8 *) resp + buflen - pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800830
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700831 if (hapd->conf->vendor_elements) {
832 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
833 wpabuf_len(hapd->conf->vendor_elements));
834 pos += wpabuf_len(hapd->conf->vendor_elements);
835 }
836
Sunil Ravieb83e2a2024-06-28 17:34:56 +0000837 *resp_len = pos - (u8 *) resp;
838 return (u8 *) resp;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800839}
840
841
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800842enum ssid_match_result {
843 NO_SSID_MATCH,
844 EXACT_SSID_MATCH,
Hai Shaloma20dcd72022-02-04 13:43:00 -0800845 WILDCARD_SSID_MATCH,
846 CO_LOCATED_SSID_MATCH,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800847};
848
849static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
850 const u8 *ssid, size_t ssid_len,
851 const u8 *ssid_list,
Hai Shalomfdcde762020-04-02 11:19:20 -0700852 size_t ssid_list_len,
853 const u8 *short_ssid_list,
854 size_t short_ssid_list_len)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800855{
856 const u8 *pos, *end;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800857 struct hostapd_iface *iface = hapd->iface;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800858 int wildcard = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800859 size_t i, j;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800860
861 if (ssid_len == 0)
862 wildcard = 1;
863 if (ssid_len == hapd->conf->ssid.ssid_len &&
864 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
865 return EXACT_SSID_MATCH;
866
Hai Shalomfdcde762020-04-02 11:19:20 -0700867 if (ssid_list) {
868 pos = ssid_list;
869 end = ssid_list + ssid_list_len;
870 while (end - pos >= 2) {
871 if (2 + pos[1] > end - pos)
872 break;
873 if (pos[1] == 0)
874 wildcard = 1;
875 if (pos[1] == hapd->conf->ssid.ssid_len &&
876 os_memcmp(pos + 2, hapd->conf->ssid.ssid,
877 pos[1]) == 0)
878 return EXACT_SSID_MATCH;
879 pos += 2 + pos[1];
880 }
881 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800882
Hai Shalomfdcde762020-04-02 11:19:20 -0700883 if (short_ssid_list) {
884 pos = short_ssid_list;
885 end = short_ssid_list + short_ssid_list_len;
886 while (end - pos >= 4) {
887 if (hapd->conf->ssid.short_ssid == WPA_GET_LE32(pos))
888 return EXACT_SSID_MATCH;
889 pos += 4;
890 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800891 }
892
Hai Shaloma20dcd72022-02-04 13:43:00 -0800893 if (wildcard)
894 return WILDCARD_SSID_MATCH;
895
896 if (!iface->interfaces || iface->interfaces->count <= 1 ||
897 is_6ghz_op_class(hapd->iconf->op_class))
898 return NO_SSID_MATCH;
899
900 for (i = 0; i < iface->interfaces->count; i++) {
901 struct hostapd_iface *colocated;
902
903 colocated = iface->interfaces->iface[i];
904
905 if (colocated == iface ||
906 !is_6ghz_op_class(colocated->conf->op_class))
907 continue;
908
909 for (j = 0; j < colocated->num_bss; j++) {
910 struct hostapd_bss_config *conf;
911
912 conf = colocated->bss[j]->conf;
913 if (ssid_len == conf->ssid.ssid_len &&
914 os_memcmp(ssid, conf->ssid.ssid, ssid_len) == 0)
915 return CO_LOCATED_SSID_MATCH;
916 }
917 }
918
919 return NO_SSID_MATCH;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800920}
921
922
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800923void sta_track_expire(struct hostapd_iface *iface, int force)
924{
925 struct os_reltime now;
926 struct hostapd_sta_info *info;
927
928 if (!iface->num_sta_seen)
929 return;
930
931 os_get_reltime(&now);
932 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
933 list))) {
934 if (!force &&
935 !os_reltime_expired(&now, &info->last_seen,
936 iface->conf->track_sta_max_age))
937 break;
938 force = 0;
939
940 wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
941 MACSTR, iface->bss[0]->conf->iface,
942 MAC2STR(info->addr));
943 dl_list_del(&info->list);
944 iface->num_sta_seen--;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700945 sta_track_del(info);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800946 }
947}
948
949
950static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
951 const u8 *addr)
952{
953 struct hostapd_sta_info *info;
954
955 dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
Sunil Ravieb83e2a2024-06-28 17:34:56 +0000956 if (os_memcmp(addr, info->addr, ETH_ALEN) == 0)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800957 return info;
958
959 return NULL;
960}
961
962
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800963void sta_track_add(struct hostapd_iface *iface, const u8 *addr, int ssi_signal)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800964{
965 struct hostapd_sta_info *info;
966
967 info = sta_track_get(iface, addr);
968 if (info) {
969 /* Move the most recent entry to the end of the list */
970 dl_list_del(&info->list);
971 dl_list_add_tail(&iface->sta_seen, &info->list);
972 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800973 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800974 return;
975 }
976
977 /* Add a new entry */
978 info = os_zalloc(sizeof(*info));
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700979 if (info == NULL)
980 return;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800981 os_memcpy(info->addr, addr, ETH_ALEN);
982 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800983 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800984
985 if (iface->num_sta_seen >= iface->conf->track_sta_max_num) {
986 /* Expire oldest entry to make room for a new one */
987 sta_track_expire(iface, 1);
988 }
989
990 wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
991 MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr));
992 dl_list_add_tail(&iface->sta_seen, &info->list);
993 iface->num_sta_seen++;
994}
995
996
997struct hostapd_data *
998sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
999 const char *ifname)
1000{
1001 struct hapd_interfaces *interfaces = iface->interfaces;
1002 size_t i, j;
1003
1004 for (i = 0; i < interfaces->count; i++) {
1005 struct hostapd_data *hapd = NULL;
1006
1007 iface = interfaces->iface[i];
1008 for (j = 0; j < iface->num_bss; j++) {
1009 hapd = iface->bss[j];
1010 if (os_strcmp(ifname, hapd->conf->iface) == 0)
1011 break;
1012 hapd = NULL;
1013 }
1014
1015 if (hapd && sta_track_get(iface, addr))
1016 return hapd;
1017 }
1018
1019 return NULL;
1020}
1021
1022
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001023#ifdef CONFIG_TAXONOMY
1024void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr,
1025 struct wpabuf **probe_ie_taxonomy)
1026{
1027 struct hostapd_sta_info *info;
1028
1029 info = sta_track_get(iface, addr);
1030 if (!info)
1031 return;
1032
1033 wpabuf_free(*probe_ie_taxonomy);
1034 *probe_ie_taxonomy = info->probe_ie_taxonomy;
1035 info->probe_ie_taxonomy = NULL;
1036}
1037#endif /* CONFIG_TAXONOMY */
1038
1039
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001040void handle_probe_req(struct hostapd_data *hapd,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001041 const struct ieee80211_mgmt *mgmt, size_t len,
1042 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001043{
Sunil Ravieb83e2a2024-06-28 17:34:56 +00001044 u8 *resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001045 struct ieee802_11_elems elems;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001046 const u8 *ie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001047 size_t ie_len;
Sunil Ravieb83e2a2024-06-28 17:34:56 +00001048 size_t i, resp_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001049 int noack;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001050 enum ssid_match_result res;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001051 int ret;
1052 u16 csa_offs[2];
1053 size_t csa_offs_len;
Hai Shalomfdcde762020-04-02 11:19:20 -07001054 struct radius_sta rad_info;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001055
Hai Shalom60840252021-02-19 19:02:11 -08001056 if (hapd->iconf->rssi_ignore_probe_request && ssi_signal &&
1057 ssi_signal < hapd->iconf->rssi_ignore_probe_request)
1058 return;
1059
Dmitry Shmidte4663042016-04-04 10:07:49 -07001060 if (len < IEEE80211_HDRLEN)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001061 return;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001062 ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001063 if (hapd->iconf->track_sta_max_num)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001064 sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
Dmitry Shmidte4663042016-04-04 10:07:49 -07001065 ie_len = len - IEEE80211_HDRLEN;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001066
Hai Shalomfdcde762020-04-02 11:19:20 -07001067 ret = hostapd_allowed_address(hapd, mgmt->sa, (const u8 *) mgmt, len,
1068 &rad_info, 1);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001069 if (ret == HOSTAPD_ACL_REJECT) {
1070 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
1071 "Ignore Probe Request frame from " MACSTR
1072 " due to ACL reject ", MAC2STR(mgmt->sa));
1073 return;
1074 }
1075
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001076 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
1077 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001078 mgmt->sa, mgmt->da, mgmt->bssid,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001079 ie, ie_len, ssi_signal) > 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001080 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001081
Hai Shalom74f70d42019-02-11 14:42:39 -08001082 if (!hapd->conf->send_probe_response)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001083 return;
1084
1085 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
1086 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
1087 MAC2STR(mgmt->sa));
1088 return;
1089 }
1090
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001091 if ((!elems.ssid || !elems.supp_rates)) {
1092 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
1093 "without SSID or supported rates element",
1094 MAC2STR(mgmt->sa));
1095 return;
1096 }
1097
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001098 /*
1099 * No need to reply if the Probe Request frame was sent on an adjacent
1100 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
1101 * AP with dot11RadioMeasurementActivated set to true, but strictly
1102 * speaking does not allow such ignoring of Probe Request frames if
1103 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
1104 * number of unnecessary Probe Response frames for cases where the STA
1105 * is less likely to see them (Probe Request frame sent on a
1106 * neighboring, but partially overlapping, channel).
1107 */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001108 if (elems.ds_params &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001109 hapd->iface->current_mode &&
1110 (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
1111 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
1112 hapd->iconf->channel != elems.ds_params[0]) {
1113 wpa_printf(MSG_DEBUG,
1114 "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
1115 hapd->iconf->channel, elems.ds_params[0]);
1116 return;
1117 }
1118
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001119#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001120 if (hapd->p2p && hapd->p2p_group && elems.wps_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001121 struct wpabuf *wps;
1122 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
1123 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
1124 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
1125 "due to mismatch with Requested Device "
1126 "Type");
1127 wpabuf_free(wps);
1128 return;
1129 }
1130 wpabuf_free(wps);
1131 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001132
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001133 if (hapd->p2p && hapd->p2p_group && elems.p2p) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001134 struct wpabuf *p2p;
1135 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
1136 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
1137 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
1138 "due to mismatch with Device ID");
1139 wpabuf_free(p2p);
1140 return;
1141 }
1142 wpabuf_free(p2p);
1143 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001144#endif /* CONFIG_P2P */
1145
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001146 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
Hai Shalomfdcde762020-04-02 11:19:20 -07001147 elems.ssid_list_len == 0 && elems.short_ssid_list_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001148 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
1149 "broadcast SSID ignored", MAC2STR(mgmt->sa));
1150 return;
1151 }
1152
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001153#ifdef CONFIG_P2P
1154 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1155 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
1156 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
1157 P2P_WILDCARD_SSID_LEN) == 0) {
1158 /* Process P2P Wildcard SSID like Wildcard SSID */
1159 elems.ssid_len = 0;
1160 }
1161#endif /* CONFIG_P2P */
1162
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001163#ifdef CONFIG_TAXONOMY
1164 {
1165 struct sta_info *sta;
1166 struct hostapd_sta_info *info;
1167
1168 if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) {
1169 taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len);
1170 } else if ((info = sta_track_get(hapd->iface,
1171 mgmt->sa)) != NULL) {
1172 taxonomy_hostapd_sta_info_probe_req(hapd, info,
1173 ie, ie_len);
1174 }
1175 }
1176#endif /* CONFIG_TAXONOMY */
1177
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001178 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
Hai Shalomfdcde762020-04-02 11:19:20 -07001179 elems.ssid_list, elems.ssid_list_len,
1180 elems.short_ssid_list, elems.short_ssid_list_len);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001181 if (res == NO_SSID_MATCH) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001182 if (!(mgmt->da[0] & 0x01)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001183 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001184 " for foreign SSID '%s' (DA " MACSTR ")%s",
Dmitry Shmidt3c479372014-02-04 10:50:36 -08001185 MAC2STR(mgmt->sa),
1186 wpa_ssid_txt(elems.ssid, elems.ssid_len),
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001187 MAC2STR(mgmt->da),
1188 elems.ssid_list ? " (SSID list)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001189 }
1190 return;
1191 }
1192
Hai Shalomfdcde762020-04-02 11:19:20 -07001193 if (hapd->conf->ignore_broadcast_ssid && res == WILDCARD_SSID_MATCH) {
1194 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
1195 "broadcast SSID ignored", MAC2STR(mgmt->sa));
1196 return;
1197 }
1198
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001199#ifdef CONFIG_INTERWORKING
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -07001200 if (hapd->conf->interworking &&
1201 elems.interworking && elems.interworking_len >= 1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001202 u8 ant = elems.interworking[0] & 0x0f;
1203 if (ant != INTERWORKING_ANT_WILDCARD &&
1204 ant != hapd->conf->access_network_type) {
1205 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
1206 " for mismatching ANT %u ignored",
1207 MAC2STR(mgmt->sa), ant);
1208 return;
1209 }
1210 }
1211
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -07001212 if (hapd->conf->interworking && elems.interworking &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001213 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
1214 const u8 *hessid;
1215 if (elems.interworking_len == 7)
1216 hessid = elems.interworking + 1;
1217 else
1218 hessid = elems.interworking + 1 + 2;
1219 if (!is_broadcast_ether_addr(hessid) &&
Sunil Ravieb83e2a2024-06-28 17:34:56 +00001220 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001221 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
1222 " for mismatching HESSID " MACSTR
1223 " ignored",
1224 MAC2STR(mgmt->sa), MAC2STR(hessid));
1225 return;
1226 }
1227 }
1228#endif /* CONFIG_INTERWORKING */
1229
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001230#ifdef CONFIG_P2P
1231 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1232 supp_rates_11b_only(&elems)) {
1233 /* Indicates support for 11b rates only */
1234 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
1235 MACSTR " with only 802.11b rates",
1236 MAC2STR(mgmt->sa));
1237 return;
1238 }
1239#endif /* CONFIG_P2P */
1240
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001241 /* TODO: verify that supp_rates contains at least one matching rate
1242 * with AP configuration */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001243
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001244 if (hapd->conf->no_probe_resp_if_seen_on &&
1245 is_multicast_ether_addr(mgmt->da) &&
1246 is_multicast_ether_addr(mgmt->bssid) &&
1247 sta_track_seen_on(hapd->iface, mgmt->sa,
1248 hapd->conf->no_probe_resp_if_seen_on)) {
1249 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1250 " since STA has been seen on %s",
1251 hapd->conf->iface, MAC2STR(mgmt->sa),
1252 hapd->conf->no_probe_resp_if_seen_on);
1253 return;
1254 }
1255
1256 if (hapd->conf->no_probe_resp_if_max_sta &&
1257 is_multicast_ether_addr(mgmt->da) &&
1258 is_multicast_ether_addr(mgmt->bssid) &&
1259 hapd->num_sta >= hapd->conf->max_num_sta &&
1260 !ap_get_sta(hapd, mgmt->sa)) {
1261 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1262 " since no room for additional STA",
1263 hapd->conf->iface, MAC2STR(mgmt->sa));
1264 return;
1265 }
1266
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001267#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001268 if (hapd->iconf->ignore_probe_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001269 drand48() < hapd->iconf->ignore_probe_probability) {
1270 wpa_printf(MSG_INFO,
1271 "TESTING: ignoring probe request from " MACSTR,
1272 MAC2STR(mgmt->sa));
1273 return;
1274 }
1275#endif /* CONFIG_TESTING_OPTIONS */
1276
Sunil Ravi77d572f2023-01-17 23:58:31 +00001277 /* Do not send Probe Response frame from a non-transmitting multiple
1278 * BSSID profile unless the Probe Request frame is directed at that
1279 * particular BSS. */
1280 if (hapd != hostapd_mbssid_get_tx_bss(hapd) && res != EXACT_SSID_MATCH)
1281 return;
1282
Roshan Pius3a1667e2018-07-03 15:17:14 -07001283 wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, RX_PROBE_REQUEST "sa=" MACSTR
1284 " signal=%d", MAC2STR(mgmt->sa), ssi_signal);
1285
Sunil Ravieb83e2a2024-06-28 17:34:56 +00001286 resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL,
1287 &resp_len, elems.mbssid_known_bss,
1288 elems.mbssid_known_bss_len);
1289 if (resp == NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001290 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001291
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001292 /*
1293 * If this is a broadcast probe request, apply no ack policy to avoid
1294 * excessive retries.
1295 */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001296 noack = !!(res == WILDCARD_SSID_MATCH &&
1297 is_broadcast_ether_addr(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001298
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001299 csa_offs_len = 0;
1300 if (hapd->csa_in_progress) {
Sunil Ravieb83e2a2024-06-28 17:34:56 +00001301 if (hapd->cs_c_off_proberesp)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001302 csa_offs[csa_offs_len++] =
Sunil Ravieb83e2a2024-06-28 17:34:56 +00001303 hapd->cs_c_off_proberesp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001304
Sunil Ravieb83e2a2024-06-28 17:34:56 +00001305 if (hapd->cs_c_off_ecsa_proberesp)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001306 csa_offs[csa_offs_len++] =
Sunil Ravieb83e2a2024-06-28 17:34:56 +00001307 hapd->cs_c_off_ecsa_proberesp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001308 }
1309
Sunil Ravieb83e2a2024-06-28 17:34:56 +00001310 ret = hostapd_drv_send_mlme(hostapd_mbssid_get_tx_bss(hapd), resp,
1311 resp_len, noack,
Hai Shalomfdcde762020-04-02 11:19:20 -07001312 csa_offs_len ? csa_offs : NULL,
1313 csa_offs_len, 0);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001314
1315 if (ret < 0)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001316 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001317
Sunil Ravieb83e2a2024-06-28 17:34:56 +00001318 os_free(resp);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001319
1320 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
1321 "SSID", MAC2STR(mgmt->sa),
1322 elems.ssid_len == 0 ? "broadcast" : "our");
1323}
1324
1325
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001326static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
1327 size_t *resp_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001328{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001329 /* check probe response offloading caps and print warnings */
1330 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
1331 return NULL;
1332
1333#ifdef CONFIG_WPS
1334 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
1335 (!(hapd->iface->probe_resp_offloads &
1336 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
1337 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
1338 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
1339 "Probe Response while not supporting this");
1340#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001341
1342#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001343 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
1344 !(hapd->iface->probe_resp_offloads &
1345 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
1346 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
1347 "Probe Response while not supporting this");
1348#endif /* CONFIG_P2P */
1349
1350 if (hapd->conf->interworking &&
1351 !(hapd->iface->probe_resp_offloads &
1352 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
1353 wpa_printf(MSG_WARNING, "Device is trying to offload "
1354 "Interworking Probe Response while not supporting "
1355 "this");
1356
1357 /* Generate a Probe Response template for the non-P2P case */
Sunil Ravieb83e2a2024-06-28 17:34:56 +00001358 return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len, NULL, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001359}
1360
1361#endif /* NEED_AP_MLME */
1362
1363
Hai Shalom60840252021-02-19 19:02:11 -08001364#ifdef CONFIG_IEEE80211AX
1365/* Unsolicited broadcast Probe Response transmission, 6 GHz only */
1366static u8 * hostapd_unsol_bcast_probe_resp(struct hostapd_data *hapd,
1367 struct wpa_driver_ap_params *params)
1368{
1369 if (!is_6ghz_op_class(hapd->iconf->op_class))
1370 return NULL;
1371
1372 params->unsol_bcast_probe_resp_interval =
1373 hapd->conf->unsol_bcast_probe_resp_interval;
1374
Sunil Ravieb83e2a2024-06-28 17:34:56 +00001375 return hostapd_gen_probe_resp(hapd, NULL, 0,
1376 &params->unsol_bcast_probe_resp_tmpl_len,
1377 NULL, 0);
Hai Shalom60840252021-02-19 19:02:11 -08001378}
1379#endif /* CONFIG_IEEE80211AX */
1380
1381
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001382void sta_track_del(struct hostapd_sta_info *info)
1383{
1384#ifdef CONFIG_TAXONOMY
1385 wpabuf_free(info->probe_ie_taxonomy);
1386 info->probe_ie_taxonomy = NULL;
1387#endif /* CONFIG_TAXONOMY */
1388 os_free(info);
1389}
1390
1391
Hai Shalom60840252021-02-19 19:02:11 -08001392#ifdef CONFIG_FILS
1393
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001394static u16 hostapd_gen_fils_discovery_phy_index(struct hostapd_data *hapd)
1395{
1396#ifdef CONFIG_IEEE80211BE
1397 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be)
1398 return FD_CAP_PHY_INDEX_EHT;
1399#endif /* CONFIG_IEEE80211BE */
1400
1401#ifdef CONFIG_IEEE80211AX
1402 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax)
1403 return FD_CAP_PHY_INDEX_HE;
1404#endif /* CONFIG_IEEE80211AX */
1405
1406#ifdef CONFIG_IEEE80211AC
1407 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac)
1408 return FD_CAP_PHY_INDEX_VHT;
1409#endif /* CONFIG_IEEE80211AC */
1410
1411 if (hapd->iconf->ieee80211n && !hapd->conf->disable_11n)
1412 return FD_CAP_PHY_INDEX_HT;
1413
1414 return 0;
1415}
1416
1417
1418static u16 hostapd_gen_fils_discovery_nss(struct hostapd_hw_modes *mode,
1419 u16 phy_index, u8 he_mcs_nss_size)
1420{
1421 u16 nss = 0;
1422
1423 if (!mode)
1424 return 0;
1425
1426 if (phy_index == FD_CAP_PHY_INDEX_HE) {
1427 const u8 *he_mcs = mode->he_capab[IEEE80211_MODE_AP].mcs;
1428 int i;
1429 u16 mcs[6];
1430
1431 os_memset(mcs, 0xff, 6 * sizeof(u16));
1432
1433 if (he_mcs_nss_size == 4) {
1434 mcs[0] = WPA_GET_LE16(&he_mcs[0]);
1435 mcs[1] = WPA_GET_LE16(&he_mcs[2]);
1436 }
1437
1438 if (he_mcs_nss_size == 8) {
1439 mcs[2] = WPA_GET_LE16(&he_mcs[4]);
1440 mcs[3] = WPA_GET_LE16(&he_mcs[6]);
1441 }
1442
1443 if (he_mcs_nss_size == 12) {
1444 mcs[4] = WPA_GET_LE16(&he_mcs[8]);
1445 mcs[5] = WPA_GET_LE16(&he_mcs[10]);
1446 }
1447
1448 for (i = 0; i < HE_NSS_MAX_STREAMS; i++) {
1449 u16 nss_mask = 0x3 << (i * 2);
1450
1451 /*
1452 * If Tx and/or Rx indicate support for a given NSS,
1453 * count it towards the maximum NSS.
1454 */
1455 if (he_mcs_nss_size == 4 &&
1456 (((mcs[0] & nss_mask) != nss_mask) ||
1457 ((mcs[1] & nss_mask) != nss_mask))) {
1458 nss++;
1459 continue;
1460 }
1461
1462 if (he_mcs_nss_size == 8 &&
1463 (((mcs[2] & nss_mask) != nss_mask) ||
1464 ((mcs[3] & nss_mask) != nss_mask))) {
1465 nss++;
1466 continue;
1467 }
1468
1469 if (he_mcs_nss_size == 12 &&
1470 (((mcs[4] & nss_mask) != nss_mask) ||
1471 ((mcs[5] & nss_mask) != nss_mask))) {
1472 nss++;
1473 continue;
1474 }
1475 }
1476 } else if (phy_index == FD_CAP_PHY_INDEX_EHT) {
1477 u8 rx_nss, tx_nss, max_nss = 0, i;
1478 u8 *mcs = mode->eht_capab[IEEE80211_MODE_AP].mcs;
1479
1480 /*
1481 * The Supported EHT-MCS And NSS Set field for the AP contains
1482 * one to three EHT-MCS Map fields based on the supported
1483 * bandwidth. Check the first byte (max NSS for Rx/Tx that
1484 * supports EHT-MCS 0-9) for each bandwidth (<= 80,
1485 * 160, 320) to find the maximum NSS. This assumes that
1486 * the lowest MCS rates support the largest number of spatial
1487 * streams. If values are different between Tx, Rx or the
1488 * bandwidths, choose the highest value.
1489 */
1490 for (i = 0; i < 3; i++) {
1491 rx_nss = mcs[3 * i] & 0x0F;
1492 if (rx_nss > max_nss)
1493 max_nss = rx_nss;
1494
1495 tx_nss = (mcs[3 * i] & 0xF0) >> 4;
1496 if (tx_nss > max_nss)
1497 max_nss = tx_nss;
1498 }
1499
1500 nss = max_nss;
1501 }
1502
1503 if (nss > 4)
1504 return FD_CAP_NSS_5_8 << FD_CAP_NSS_SHIFT;
1505 if (nss)
1506 return (nss - 1) << FD_CAP_NSS_SHIFT;
1507
1508 return 0;
1509}
1510
1511
Hai Shalom60840252021-02-19 19:02:11 -08001512static u16 hostapd_fils_discovery_cap(struct hostapd_data *hapd)
1513{
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001514 u16 cap_info, phy_index;
1515 u8 chwidth = FD_CAP_BSS_CHWIDTH_20, he_mcs_nss_size = 4;
Hai Shalom60840252021-02-19 19:02:11 -08001516 struct hostapd_hw_modes *mode = hapd->iface->current_mode;
1517
1518 cap_info = FD_CAP_ESS;
1519 if (hapd->conf->wpa)
1520 cap_info |= FD_CAP_PRIVACY;
1521
1522 if (is_6ghz_op_class(hapd->iconf->op_class)) {
Hai Shalom60840252021-02-19 19:02:11 -08001523 switch (hapd->iconf->op_class) {
Sunil Ravi036cec52023-03-29 11:35:17 -07001524 case 137:
1525 chwidth = FD_CAP_BSS_CHWIDTH_320;
1526 break;
Hai Shalom60840252021-02-19 19:02:11 -08001527 case 135:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001528 he_mcs_nss_size += 4;
Hai Shalom60840252021-02-19 19:02:11 -08001529 /* fallthrough */
1530 case 134:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001531 he_mcs_nss_size += 4;
Hai Shalom60840252021-02-19 19:02:11 -08001532 chwidth = FD_CAP_BSS_CHWIDTH_160_80_80;
1533 break;
1534 case 133:
1535 chwidth = FD_CAP_BSS_CHWIDTH_80;
1536 break;
1537 case 132:
1538 chwidth = FD_CAP_BSS_CHWIDTH_40;
1539 break;
1540 }
1541 } else {
1542 switch (hostapd_get_oper_chwidth(hapd->iconf)) {
Sunil8cd6f4d2022-06-28 18:40:46 +00001543 case CONF_OPER_CHWIDTH_80P80MHZ:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001544 he_mcs_nss_size += 4;
Hai Shalom60840252021-02-19 19:02:11 -08001545 /* fallthrough */
Sunil8cd6f4d2022-06-28 18:40:46 +00001546 case CONF_OPER_CHWIDTH_160MHZ:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001547 he_mcs_nss_size += 4;
Hai Shalom60840252021-02-19 19:02:11 -08001548 chwidth = FD_CAP_BSS_CHWIDTH_160_80_80;
1549 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00001550 case CONF_OPER_CHWIDTH_80MHZ:
Hai Shalom60840252021-02-19 19:02:11 -08001551 chwidth = FD_CAP_BSS_CHWIDTH_80;
1552 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00001553 case CONF_OPER_CHWIDTH_USE_HT:
Hai Shalom60840252021-02-19 19:02:11 -08001554 if (hapd->iconf->secondary_channel)
1555 chwidth = FD_CAP_BSS_CHWIDTH_40;
1556 else
1557 chwidth = FD_CAP_BSS_CHWIDTH_20;
1558 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00001559 default:
1560 break;
Hai Shalom60840252021-02-19 19:02:11 -08001561 }
Hai Shalom60840252021-02-19 19:02:11 -08001562 }
1563
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001564 phy_index = hostapd_gen_fils_discovery_phy_index(hapd);
Hai Shalom60840252021-02-19 19:02:11 -08001565 cap_info |= phy_index << FD_CAP_PHY_INDEX_SHIFT;
1566 cap_info |= chwidth << FD_CAP_BSS_CHWIDTH_SHIFT;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001567 cap_info |= hostapd_gen_fils_discovery_nss(mode, phy_index,
1568 he_mcs_nss_size);
Hai Shalom60840252021-02-19 19:02:11 -08001569 return cap_info;
1570}
1571
1572
1573static u8 * hostapd_gen_fils_discovery(struct hostapd_data *hapd, size_t *len)
1574{
1575 struct ieee80211_mgmt *head;
1576 const u8 *mobility_domain;
1577 u8 *pos, *length_pos, buf[200];
1578 u16 ctl = 0;
1579 u8 fd_rsn_info[5];
1580 size_t total_len, buf_len;
1581
1582 total_len = 24 + 2 + 12;
1583
1584 /* FILS Discovery Frame Control */
1585 ctl = (sizeof(hapd->conf->ssid.short_ssid) - 1) |
1586 FD_FRAME_CTL_SHORT_SSID_PRESENT |
1587 FD_FRAME_CTL_LENGTH_PRESENT |
1588 FD_FRAME_CTL_CAP_PRESENT;
1589 total_len += 4 + 1 + 2;
1590
1591 /* Check for optional subfields and calculate length */
1592 if (wpa_auth_write_fd_rsn_info(hapd->wpa_auth, fd_rsn_info)) {
1593 ctl |= FD_FRAME_CTL_RSN_INFO_PRESENT;
1594 total_len += sizeof(fd_rsn_info);
1595 }
1596
1597 mobility_domain = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN);
1598 if (mobility_domain) {
1599 ctl |= FD_FRAME_CTL_MD_PRESENT;
1600 total_len += 3;
1601 }
1602
Hai Shaloma20dcd72022-02-04 13:43:00 -08001603 total_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_ACTION);
1604
Hai Shalom60840252021-02-19 19:02:11 -08001605 pos = hostapd_eid_fils_indic(hapd, buf, 0);
1606 buf_len = pos - buf;
1607 total_len += buf_len;
1608
Sunil Ravieb83e2a2024-06-28 17:34:56 +00001609#ifdef CONFIG_IEEE80211AX
1610 /* Transmit Power Envelope element(s) */
1611 if (is_6ghz_op_class(hapd->iconf->op_class)) {
1612 total_len += 4;
1613 if (hapd->iconf->he_6ghz_reg_pwr_type == HE_6GHZ_INDOOR_AP)
1614 total_len += 4;
1615 }
1616#endif /* CONFIG_IEEE80211AX */
Sunil Ravia04bd252022-05-02 22:54:18 -07001617
Hai Shalom60840252021-02-19 19:02:11 -08001618 head = os_zalloc(total_len);
1619 if (!head)
1620 return NULL;
1621
1622 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1623 WLAN_FC_STYPE_ACTION);
1624 os_memset(head->da, 0xff, ETH_ALEN);
1625 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1626 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1627
1628 head->u.action.category = WLAN_ACTION_PUBLIC;
1629 head->u.action.u.public_action.action = WLAN_PA_FILS_DISCOVERY;
1630
1631 pos = &head->u.action.u.public_action.variable[0];
1632
1633 /* FILS Discovery Information field */
1634
1635 /* FILS Discovery Frame Control */
1636 WPA_PUT_LE16(pos, ctl);
1637 pos += 2;
1638
1639 /* Hardware or low-level driver will fill in the Timestamp value */
1640 pos += 8;
1641
1642 /* Beacon Interval */
1643 WPA_PUT_LE16(pos, hapd->iconf->beacon_int);
1644 pos += 2;
1645
1646 /* Short SSID */
1647 WPA_PUT_LE32(pos, hapd->conf->ssid.short_ssid);
1648 pos += sizeof(hapd->conf->ssid.short_ssid);
1649
1650 /* Store position of FILS discovery information element Length field */
1651 length_pos = pos++;
1652
1653 /* FD Capability */
1654 WPA_PUT_LE16(pos, hostapd_fils_discovery_cap(hapd));
1655 pos += 2;
1656
1657 /* Operating Class - not present */
1658
1659 /* Primary Channel - not present */
1660
1661 /* AP Configuration Sequence Number - not present */
1662
1663 /* Access Network Options - not present */
1664
1665 /* FD RSN Information */
1666 if (ctl & FD_FRAME_CTL_RSN_INFO_PRESENT) {
1667 os_memcpy(pos, fd_rsn_info, sizeof(fd_rsn_info));
1668 pos += sizeof(fd_rsn_info);
1669 }
1670
1671 /* Channel Center Frequency Segment 1 - not present */
1672
1673 /* Mobility Domain */
1674 if (ctl & FD_FRAME_CTL_MD_PRESENT) {
1675 os_memcpy(pos, &mobility_domain[2], 3);
1676 pos += 3;
1677 }
1678
1679 /* Fill in the Length field value */
1680 *length_pos = pos - (length_pos + 1);
1681
Hai Shaloma20dcd72022-02-04 13:43:00 -08001682 pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_ACTION);
1683
Hai Shalom60840252021-02-19 19:02:11 -08001684 /* FILS Indication element */
1685 if (buf_len) {
1686 os_memcpy(pos, buf, buf_len);
1687 pos += buf_len;
1688 }
1689
Sunil Ravia04bd252022-05-02 22:54:18 -07001690 if (is_6ghz_op_class(hapd->iconf->op_class))
1691 pos = hostapd_eid_txpower_envelope(hapd, pos);
1692
Hai Shalom60840252021-02-19 19:02:11 -08001693 *len = pos - (u8 *) head;
1694 wpa_hexdump(MSG_DEBUG, "FILS Discovery frame template",
1695 head, pos - (u8 *) head);
1696 return (u8 *) head;
1697}
1698
1699
1700/* Configure FILS Discovery frame transmission parameters */
1701static u8 * hostapd_fils_discovery(struct hostapd_data *hapd,
1702 struct wpa_driver_ap_params *params)
1703{
1704 params->fd_max_int = hapd->conf->fils_discovery_max_int;
1705 if (is_6ghz_op_class(hapd->iconf->op_class) &&
1706 params->fd_max_int > FD_MAX_INTERVAL_6GHZ)
1707 params->fd_max_int = FD_MAX_INTERVAL_6GHZ;
1708
1709 params->fd_min_int = hapd->conf->fils_discovery_min_int;
1710 if (params->fd_min_int > params->fd_max_int)
1711 params->fd_min_int = params->fd_max_int;
1712
1713 if (params->fd_max_int)
1714 return hostapd_gen_fils_discovery(hapd,
1715 &params->fd_frame_tmpl_len);
1716
1717 return NULL;
1718}
1719
1720#endif /* CONFIG_FILS */
1721
1722
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001723int ieee802_11_build_ap_params(struct hostapd_data *hapd,
1724 struct wpa_driver_ap_params *params)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001725{
1726 struct ieee80211_mgmt *head = NULL;
1727 u8 *tail = NULL;
1728 size_t head_len = 0, tail_len = 0;
1729 u8 *resp = NULL;
1730 size_t resp_len = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001731#ifdef NEED_AP_MLME
1732 u16 capab_info;
Hai Shalomfdcde762020-04-02 11:19:20 -07001733 u8 *pos, *tailpos, *tailend, *csa_pos;
Sunil Ravi77d572f2023-01-17 23:58:31 +00001734 bool complete = false;
1735#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001736
Sunil Ravi77d572f2023-01-17 23:58:31 +00001737 os_memset(params, 0, sizeof(*params));
1738
1739#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001740#define BEACON_HEAD_BUF_SIZE 256
1741#define BEACON_TAIL_BUF_SIZE 512
1742 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
1743 tail_len = BEACON_TAIL_BUF_SIZE;
1744#ifdef CONFIG_WPS
1745 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
1746 tail_len += wpabuf_len(hapd->wps_beacon_ie);
1747#endif /* CONFIG_WPS */
1748#ifdef CONFIG_P2P
1749 if (hapd->p2p_beacon_ie)
1750 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
1751#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001752#ifdef CONFIG_FST
1753 if (hapd->iface->fst_ies)
1754 tail_len += wpabuf_len(hapd->iface->fst_ies);
1755#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001756 if (hapd->conf->vendor_elements)
1757 tail_len += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001758
1759#ifdef CONFIG_IEEE80211AC
1760 if (hapd->conf->vendor_vht) {
1761 tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
1762 2 + sizeof(struct ieee80211_vht_operation);
1763 }
1764#endif /* CONFIG_IEEE80211AC */
1765
Sunil Ravieb83e2a2024-06-28 17:34:56 +00001766#ifdef CONFIG_IEEE80211AX
1767 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
1768 tail_len += 3 + sizeof(struct ieee80211_he_capabilities) +
1769 3 + sizeof(struct ieee80211_he_operation) +
1770 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
1771 3 + sizeof(struct ieee80211_spatial_reuse);
1772 if (is_6ghz_op_class(hapd->iconf->op_class)) {
1773 tail_len += sizeof(struct ieee80211_he_6ghz_oper_info) +
1774 3 + sizeof(struct ieee80211_he_6ghz_band_cap);
1775 /* An additional Transmit Power Envelope element for
1776 * subordinate client */
1777 if (hapd->iconf->he_6ghz_reg_pwr_type ==
1778 HE_6GHZ_INDOOR_AP)
1779 tail_len += 4;
1780 }
1781 }
1782#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001783
Sunil Ravia04bd252022-05-02 22:54:18 -07001784#ifdef CONFIG_IEEE80211BE
1785 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
1786 tail_len += hostapd_eid_eht_capab_len(hapd, IEEE80211_MODE_AP);
1787 tail_len += 3 + sizeof(struct ieee80211_eht_operation);
Sunil Ravi036cec52023-03-29 11:35:17 -07001788 if (hapd->iconf->punct_bitmap)
1789 tail_len += EHT_OPER_DISABLED_SUBCHAN_BITMAP_SIZE;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001790
1791 /*
1792 * TODO: Multi-Link element has variable length and can be
1793 * long based on the common info and number of per
1794 * station profiles. For now use 256.
1795 */
1796 if (hapd->conf->mld_ap)
1797 tail_len += 256;
Sunil Ravia04bd252022-05-02 22:54:18 -07001798 }
1799#endif /* CONFIG_IEEE80211BE */
1800
Sunil Ravi77d572f2023-01-17 23:58:31 +00001801 if (hapd->iconf->mbssid == ENHANCED_MBSSID_ENABLED &&
1802 hapd == hostapd_mbssid_get_tx_bss(hapd))
1803 tail_len += 5; /* Multiple BSSID Configuration element */
Hai Shaloma20dcd72022-02-04 13:43:00 -08001804 tail_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_BEACON);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001805 tail_len += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001806 tail_len += hostapd_eid_owe_trans_len(hapd);
Hai Shalomfdcde762020-04-02 11:19:20 -07001807 tail_len += hostapd_eid_dpp_cc_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001808
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001809 tailpos = tail = os_malloc(tail_len);
1810 if (head == NULL || tail == NULL) {
1811 wpa_printf(MSG_ERROR, "Failed to set beacon data");
1812 os_free(head);
1813 os_free(tail);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001814 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001815 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001816 tailend = tail + tail_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001817
1818 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1819 WLAN_FC_STYPE_BEACON);
1820 head->duration = host_to_le16(0);
1821 os_memset(head->da, 0xff, ETH_ALEN);
1822
1823 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1824 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1825 head->u.beacon.beacon_int =
1826 host_to_le16(hapd->iconf->beacon_int);
1827
1828 /* hardware or low-level driver will setup seq_ctrl and timestamp */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001829 capab_info = hostapd_own_capab_info(hapd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001830 head->u.beacon.capab_info = host_to_le16(capab_info);
1831 pos = &head->u.beacon.variable[0];
1832
1833 /* SSID */
1834 *pos++ = WLAN_EID_SSID;
1835 if (hapd->conf->ignore_broadcast_ssid == 2) {
1836 /* clear the data, but keep the correct length of the SSID */
1837 *pos++ = hapd->conf->ssid.ssid_len;
1838 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
1839 pos += hapd->conf->ssid.ssid_len;
1840 } else if (hapd->conf->ignore_broadcast_ssid) {
1841 *pos++ = 0; /* empty SSID */
1842 } else {
1843 *pos++ = hapd->conf->ssid.ssid_len;
1844 os_memcpy(pos, hapd->conf->ssid.ssid,
1845 hapd->conf->ssid.ssid_len);
1846 pos += hapd->conf->ssid.ssid_len;
1847 }
1848
1849 /* Supported rates */
1850 pos = hostapd_eid_supp_rates(hapd, pos);
1851
1852 /* DS Params */
1853 pos = hostapd_eid_ds_params(hapd, pos);
1854
1855 head_len = pos - (u8 *) head;
1856
Hai Shalomfdcde762020-04-02 11:19:20 -07001857 tailpos = hostapd_eid_country(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001858
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001859 /* Power Constraint element */
1860 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
1861
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001862 /* CSA IE */
1863 csa_pos = hostapd_eid_csa(hapd, tailpos);
1864 if (csa_pos != tailpos)
1865 hapd->cs_c_off_beacon = csa_pos - tail - 1;
1866 tailpos = csa_pos;
1867
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001868 /* ERP Information element */
1869 tailpos = hostapd_eid_erp_info(hapd, tailpos);
1870
1871 /* Extended supported rates */
1872 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
1873
Hai Shalomfdcde762020-04-02 11:19:20 -07001874 tailpos = hostapd_get_rsne(hapd, tailpos, tailend - tailpos);
1875 tailpos = hostapd_eid_bss_load(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001876 tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
Hai Shalomfdcde762020-04-02 11:19:20 -07001877 tailend - tailpos);
1878 tailpos = hostapd_get_mde(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001879
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001880 /* eCSA IE */
1881 csa_pos = hostapd_eid_ecsa(hapd, tailpos);
1882 if (csa_pos != tailpos)
1883 hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1;
1884 tailpos = csa_pos;
1885
1886 tailpos = hostapd_eid_supported_op_classes(hapd, tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001887 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
1888 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001889
Sunil Ravi77d572f2023-01-17 23:58:31 +00001890 if (hapd->iconf->mbssid && hapd->iconf->num_bss > 1) {
1891 if (ieee802_11_build_ap_params_mbssid(hapd, params)) {
1892 os_free(head);
1893 os_free(tail);
1894 wpa_printf(MSG_ERROR,
1895 "MBSSID: Failed to set beacon data");
1896 return -1;
1897 }
1898 complete = hapd->iconf->mbssid == MBSSID_ENABLED ||
1899 (hapd->iconf->mbssid == ENHANCED_MBSSID_ENABLED &&
1900 params->mbssid_elem_count == 1);
1901 }
1902
1903 tailpos = hostapd_eid_ext_capab(hapd, tailpos, complete);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001904
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001905 /*
1906 * TODO: Time Advertisement element should only be included in some
1907 * DTIM Beacon frames.
1908 */
1909 tailpos = hostapd_eid_time_adv(hapd, tailpos);
1910
1911 tailpos = hostapd_eid_interworking(hapd, tailpos);
1912 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
1913 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001914
1915#ifdef CONFIG_FST
1916 if (hapd->iface->fst_ies) {
1917 os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies),
1918 wpabuf_len(hapd->iface->fst_ies));
1919 tailpos += wpabuf_len(hapd->iface->fst_ies);
1920 }
1921#endif /* CONFIG_FST */
1922
Dmitry Shmidt04949592012-07-19 12:16:46 -07001923#ifdef CONFIG_IEEE80211AC
Hai Shalom60840252021-02-19 19:02:11 -08001924 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
1925 !is_6ghz_op_class(hapd->iconf->op_class)) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -07001926 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001927 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08001928 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001929 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001930#endif /* CONFIG_IEEE80211AC */
1931
Hai Shalom60840252021-02-19 19:02:11 -08001932#ifdef CONFIG_IEEE80211AX
1933 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax &&
1934 is_6ghz_op_class(hapd->iconf->op_class))
1935 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
1936#endif /* CONFIG_IEEE80211AX */
1937
Hai Shaloma20dcd72022-02-04 13:43:00 -08001938 tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos);
Hai Shalom899fcc72020-10-19 14:38:18 -07001939
Hai Shaloma20dcd72022-02-04 13:43:00 -08001940 tailpos = hostapd_eid_rnr(hapd, tailpos, WLAN_FC_STYPE_BEACON);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001941 tailpos = hostapd_eid_fils_indic(hapd, tailpos, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -07001942 tailpos = hostapd_get_rsnxe(hapd, tailpos, tailend - tailpos);
Sunil Ravi77d572f2023-01-17 23:58:31 +00001943 tailpos = hostapd_eid_mbssid_config(hapd, tailpos,
1944 params->mbssid_elem_count);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001945
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001946#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08001947 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Sunil Ravia04bd252022-05-02 22:54:18 -07001948 u8 *cca_pos;
1949
Hai Shalom81f62d82019-07-22 12:10:00 -07001950 tailpos = hostapd_eid_he_capab(hapd, tailpos,
1951 IEEE80211_MODE_AP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001952 tailpos = hostapd_eid_he_operation(hapd, tailpos);
Sunil Ravia04bd252022-05-02 22:54:18 -07001953
1954 /* BSS Color Change Announcement element */
1955 cca_pos = hostapd_eid_cca(hapd, tailpos);
1956 if (cca_pos != tailpos)
1957 hapd->cca_c_off_beacon = cca_pos - tail - 2;
1958 tailpos = cca_pos;
1959
Hai Shalom81f62d82019-07-22 12:10:00 -07001960 tailpos = hostapd_eid_spatial_reuse(hapd, tailpos);
Hai Shalomfdcde762020-04-02 11:19:20 -07001961 tailpos = hostapd_eid_he_mu_edca_parameter_set(hapd, tailpos);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001962 tailpos = hostapd_eid_he_6ghz_band_cap(hapd, tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001963 }
1964#endif /* CONFIG_IEEE80211AX */
1965
Sunil Ravia04bd252022-05-02 22:54:18 -07001966#ifdef CONFIG_IEEE80211BE
1967 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001968 if (hapd->conf->mld_ap)
Sunil Ravieb83e2a2024-06-28 17:34:56 +00001969 tailpos = hostapd_eid_eht_basic_ml(hapd, tailpos, NULL,
1970 true);
Sunil Ravia04bd252022-05-02 22:54:18 -07001971 tailpos = hostapd_eid_eht_capab(hapd, tailpos,
1972 IEEE80211_MODE_AP);
1973 tailpos = hostapd_eid_eht_operation(hapd, tailpos);
1974 }
1975#endif /* CONFIG_IEEE80211BE */
1976
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001977#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001978 if (hapd->conf->vendor_vht)
1979 tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001980#endif /* CONFIG_IEEE80211AC */
1981
Hai Shalomfdcde762020-04-02 11:19:20 -07001982 /* WPA / OSEN */
1983 tailpos = hostapd_get_wpa_ie(hapd, tailpos, tailend - tailpos);
1984 tailpos = hostapd_get_osen_ie(hapd, tailpos, tailend - tailpos);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001985
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001986 /* Wi-Fi Alliance WMM */
1987 tailpos = hostapd_eid_wmm(hapd, tailpos);
1988
1989#ifdef CONFIG_WPS
1990 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
1991 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
1992 wpabuf_len(hapd->wps_beacon_ie));
1993 tailpos += wpabuf_len(hapd->wps_beacon_ie);
1994 }
1995#endif /* CONFIG_WPS */
1996
1997#ifdef CONFIG_P2P
1998 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
1999 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
2000 wpabuf_len(hapd->p2p_beacon_ie));
2001 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
2002 }
2003#endif /* CONFIG_P2P */
2004#ifdef CONFIG_P2P_MANAGER
2005 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
2006 P2P_MANAGE)
2007 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
2008#endif /* CONFIG_P2P_MANAGER */
2009
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002010#ifdef CONFIG_HS20
2011 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
2012#endif /* CONFIG_HS20 */
2013
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002014 tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002015 tailpos = hostapd_eid_owe_trans(hapd, tailpos,
2016 tail + tail_len - tailpos);
Hai Shalomfdcde762020-04-02 11:19:20 -07002017 tailpos = hostapd_eid_dpp_cc(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002018
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002019 if (hapd->conf->vendor_elements) {
2020 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
2021 wpabuf_len(hapd->conf->vendor_elements));
2022 tailpos += wpabuf_len(hapd->conf->vendor_elements);
2023 }
2024
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002025 tail_len = tailpos > tail ? tailpos - tail : 0;
2026
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002027 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
2028#endif /* NEED_AP_MLME */
2029
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002030 /* If key management offload is enabled, configure PSK to the driver. */
2031 if (wpa_key_mgmt_wpa_psk_no_sae(hapd->conf->wpa_key_mgmt) &&
2032 (hapd->iface->drv_flags2 &
2033 WPA_DRIVER_FLAGS2_4WAY_HANDSHAKE_AP_PSK)) {
2034 if (hapd->conf->ssid.wpa_psk && hapd->conf->ssid.wpa_psk_set) {
2035 os_memcpy(params->psk, hapd->conf->ssid.wpa_psk->psk,
2036 PMK_LEN);
2037 params->psk_len = PMK_LEN;
2038 } else if (hapd->conf->ssid.wpa_passphrase &&
2039 pbkdf2_sha1(hapd->conf->ssid.wpa_passphrase,
2040 hapd->conf->ssid.ssid,
2041 hapd->conf->ssid.ssid_len, 4096,
2042 params->psk, PMK_LEN) == 0) {
2043 params->psk_len = PMK_LEN;
2044 }
2045 }
2046
2047#ifdef CONFIG_SAE
2048 /* If SAE offload is enabled, provide password to lower layer for
2049 * SAE authentication and PMK generation.
2050 */
2051 if (wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
2052 (hapd->iface->drv_flags2 & WPA_DRIVER_FLAGS2_SAE_OFFLOAD_AP)) {
2053 if (hostapd_sae_pk_in_use(hapd->conf)) {
2054 wpa_printf(MSG_ERROR,
2055 "SAE PK not supported with SAE offload");
2056 return -1;
2057 }
2058
2059 if (hostapd_sae_pw_id_in_use(hapd->conf)) {
2060 wpa_printf(MSG_ERROR,
2061 "SAE Password Identifiers not supported with SAE offload");
2062 return -1;
2063 }
2064
2065 params->sae_password = sae_get_password(hapd, NULL, NULL, NULL,
2066 NULL, NULL);
2067 if (!params->sae_password) {
2068 wpa_printf(MSG_ERROR, "SAE password not configured for offload");
2069 return -1;
2070 }
2071 }
2072#endif /* CONFIG_SAE */
2073
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002074 params->head = (u8 *) head;
2075 params->head_len = head_len;
2076 params->tail = tail;
2077 params->tail_len = tail_len;
2078 params->proberesp = resp;
2079 params->proberesp_len = resp_len;
2080 params->dtim_period = hapd->conf->dtim_period;
2081 params->beacon_int = hapd->iconf->beacon_int;
2082 params->basic_rates = hapd->iface->basic_rates;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002083 params->beacon_rate = hapd->iconf->beacon_rate;
2084 params->rate_type = hapd->iconf->rate_type;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002085 params->ssid = hapd->conf->ssid.ssid;
2086 params->ssid_len = hapd->conf->ssid.ssid_len;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07002087 if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
2088 (WPA_PROTO_WPA | WPA_PROTO_RSN))
2089 params->pairwise_ciphers = hapd->conf->wpa_pairwise |
2090 hapd->conf->rsn_pairwise;
2091 else if (hapd->conf->wpa & WPA_PROTO_RSN)
2092 params->pairwise_ciphers = hapd->conf->rsn_pairwise;
2093 else if (hapd->conf->wpa & WPA_PROTO_WPA)
2094 params->pairwise_ciphers = hapd->conf->wpa_pairwise;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002095 params->group_cipher = hapd->conf->wpa_group;
2096 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
2097 params->auth_algs = hapd->conf->auth_algs;
2098 params->wpa_version = hapd->conf->wpa;
Hai Shalomfdcde762020-04-02 11:19:20 -07002099 params->privacy = hapd->conf->wpa;
2100#ifdef CONFIG_WEP
2101 params->privacy |= hapd->conf->ssid.wep.keys_set ||
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002102 (hapd->conf->ieee802_1x &&
2103 (hapd->conf->default_wep_key_len ||
2104 hapd->conf->individual_wep_key_len));
Hai Shalomfdcde762020-04-02 11:19:20 -07002105#endif /* CONFIG_WEP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002106 switch (hapd->conf->ignore_broadcast_ssid) {
2107 case 0:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002108 params->hide_ssid = NO_SSID_HIDING;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002109 break;
2110 case 1:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002111 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002112 break;
2113 case 2:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002114 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002115 break;
2116 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002117 params->isolate = hapd->conf->isolate;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002118#ifdef NEED_AP_MLME
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002119 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002120 ERP_INFO_USE_PROTECTION);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002121 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002122 hapd->iconf->preamble == SHORT_PREAMBLE;
2123 if (hapd->iface->current_mode &&
2124 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002125 params->short_slot_time =
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002126 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
2127 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002128 params->short_slot_time = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002129 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002130 params->ht_opmode = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002131 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002132 params->ht_opmode = hapd->iface->ht_op_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002133#endif /* NEED_AP_MLME */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002134 params->interworking = hapd->conf->interworking;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002135 if (hapd->conf->interworking &&
2136 !is_zero_ether_addr(hapd->conf->hessid))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002137 params->hessid = hapd->conf->hessid;
2138 params->access_network_type = hapd->conf->access_network_type;
2139 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002140#ifdef CONFIG_P2P
2141 params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
2142#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002143#ifdef CONFIG_HS20
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002144 params->disable_dgaf = hapd->conf->disable_dgaf;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002145 if (hapd->conf->osen) {
2146 params->privacy = 1;
2147 params->osen = 1;
2148 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002149#endif /* CONFIG_HS20 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002150 params->multicast_to_unicast = hapd->conf->multicast_to_unicast;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002151 params->pbss = hapd->conf->pbss;
Hai Shalom74f70d42019-02-11 14:42:39 -08002152
2153 if (hapd->conf->ftm_responder) {
2154 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_FTM_RESPONDER) {
2155 params->ftm_responder = 1;
2156 params->lci = hapd->iface->conf->lci;
2157 params->civic = hapd->iface->conf->civic;
2158 } else {
2159 wpa_printf(MSG_WARNING,
2160 "Not configuring FTM responder as the driver doesn't advertise support for it");
2161 }
2162 }
2163
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002164#ifdef CONFIG_IEEE80211BE
2165 if (hapd->conf->mld_ap && hapd->iconf->ieee80211be &&
2166 !hapd->conf->disable_11be) {
2167 params->mld_ap = true;
2168 params->mld_link_id = hapd->mld_link_id;
2169 }
2170#endif /* CONFIG_IEEE80211BE */
2171
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002172 return 0;
2173}
2174
2175
2176void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
2177{
2178 os_free(params->tail);
2179 params->tail = NULL;
2180 os_free(params->head);
2181 params->head = NULL;
2182 os_free(params->proberesp);
2183 params->proberesp = NULL;
Sunil Ravi77d572f2023-01-17 23:58:31 +00002184 os_free(params->mbssid_elem);
2185 params->mbssid_elem = NULL;
2186 os_free(params->mbssid_elem_offset);
2187 params->mbssid_elem_offset = NULL;
Sunil Ravi640215c2023-06-28 23:08:09 +00002188 os_free(params->rnr_elem);
2189 params->rnr_elem = NULL;
2190 os_free(params->rnr_elem_offset);
2191 params->rnr_elem_offset = NULL;
Hai Shalom60840252021-02-19 19:02:11 -08002192#ifdef CONFIG_FILS
2193 os_free(params->fd_frame_tmpl);
2194 params->fd_frame_tmpl = NULL;
2195#endif /* CONFIG_FILS */
2196#ifdef CONFIG_IEEE80211AX
2197 os_free(params->unsol_bcast_probe_resp_tmpl);
2198 params->unsol_bcast_probe_resp_tmpl = NULL;
2199#endif /* CONFIG_IEEE80211AX */
Sunil Ravi640215c2023-06-28 23:08:09 +00002200 os_free(params->allowed_freqs);
2201 params->allowed_freqs = NULL;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002202}
2203
2204
Hai Shaloma20dcd72022-02-04 13:43:00 -08002205static int __ieee802_11_set_beacon(struct hostapd_data *hapd)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002206{
2207 struct wpa_driver_ap_params params;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002208 struct hostapd_freq_params freq;
2209 struct hostapd_iface *iface = hapd->iface;
2210 struct hostapd_config *iconf = iface->conf;
Hai Shalom81f62d82019-07-22 12:10:00 -07002211 struct hostapd_hw_modes *cmode = iface->current_mode;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002212 struct wpabuf *beacon, *proberesp, *assocresp;
Sunil Ravi640215c2023-06-28 23:08:09 +00002213 int res, ret = -1, i;
2214 struct hostapd_hw_modes *mode;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002215
Hai Shaloma20dcd72022-02-04 13:43:00 -08002216 if (!hapd->drv_priv) {
2217 wpa_printf(MSG_ERROR, "Interface is disabled");
2218 return -1;
2219 }
2220
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002221 if (hapd->csa_in_progress) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002222 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002223 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002224 }
2225
2226 hapd->beacon_set_done = 1;
2227
2228 if (ieee802_11_build_ap_params(hapd, &params) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002229 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002230
2231 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
2232 0)
2233 goto fail;
2234
2235 params.beacon_ies = beacon;
2236 params.proberesp_ies = proberesp;
2237 params.assocresp_ies = assocresp;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002238 params.reenable = hapd->reenable_beacon;
Hai Shalomc3565922019-10-28 11:58:20 -07002239#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08002240 params.he_spr_ctrl = hapd->iface->conf->spr.sr_control;
2241 params.he_spr_non_srg_obss_pd_max_offset =
2242 hapd->iface->conf->spr.non_srg_obss_pd_max_offset;
Hai Shalomc3565922019-10-28 11:58:20 -07002243 params.he_spr_srg_obss_pd_min_offset =
2244 hapd->iface->conf->spr.srg_obss_pd_min_offset;
2245 params.he_spr_srg_obss_pd_max_offset =
2246 hapd->iface->conf->spr.srg_obss_pd_max_offset;
Hai Shalom60840252021-02-19 19:02:11 -08002247 os_memcpy(params.he_spr_bss_color_bitmap,
2248 hapd->iface->conf->spr.srg_bss_color_bitmap, 8);
2249 os_memcpy(params.he_spr_partial_bssid_bitmap,
2250 hapd->iface->conf->spr.srg_partial_bssid_bitmap, 8);
Hai Shalomfdcde762020-04-02 11:19:20 -07002251 params.he_bss_color_disabled =
2252 hapd->iface->conf->he_op.he_bss_color_disabled;
2253 params.he_bss_color_partial =
2254 hapd->iface->conf->he_op.he_bss_color_partial;
2255 params.he_bss_color = hapd->iface->conf->he_op.he_bss_color;
2256 params.twt_responder = hostapd_get_he_twt_responder(hapd,
2257 IEEE80211_MODE_AP);
Hai Shalom60840252021-02-19 19:02:11 -08002258 params.unsol_bcast_probe_resp_tmpl =
2259 hostapd_unsol_bcast_probe_resp(hapd, &params);
Hai Shalomc3565922019-10-28 11:58:20 -07002260#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002261 hapd->reenable_beacon = 0;
Hai Shalom60840252021-02-19 19:02:11 -08002262#ifdef CONFIG_SAE
2263 params.sae_pwe = hapd->conf->sae_pwe;
2264#endif /* CONFIG_SAE */
2265
2266#ifdef CONFIG_FILS
2267 params.fd_frame_tmpl = hostapd_fils_discovery(hapd, &params);
2268#endif /* CONFIG_FILS */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002269
Sunil Ravi036cec52023-03-29 11:35:17 -07002270#ifdef CONFIG_IEEE80211BE
2271 params.punct_bitmap = iconf->punct_bitmap;
2272#endif /* CONFIG_IEEE80211BE */
2273
Hai Shalom81f62d82019-07-22 12:10:00 -07002274 if (cmode &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002275 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
Hai Shalomc3565922019-10-28 11:58:20 -07002276 iconf->channel, iconf->enable_edmg,
2277 iconf->edmg_channel, iconf->ieee80211n,
Hai Shalom81f62d82019-07-22 12:10:00 -07002278 iconf->ieee80211ac, iconf->ieee80211ax,
Sunil Ravia04bd252022-05-02 22:54:18 -07002279 iconf->ieee80211be,
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002280 iconf->secondary_channel,
Hai Shalom81f62d82019-07-22 12:10:00 -07002281 hostapd_get_oper_chwidth(iconf),
2282 hostapd_get_oper_centr_freq_seg0_idx(iconf),
2283 hostapd_get_oper_centr_freq_seg1_idx(iconf),
2284 cmode->vht_capab,
Sunil Ravia04bd252022-05-02 22:54:18 -07002285 &cmode->he_capab[IEEE80211_MODE_AP],
Sunil Ravi88611412024-06-28 17:34:56 +00002286 &cmode->eht_capab[IEEE80211_MODE_AP]) == 0)
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002287 params.freq = &freq;
2288
Sunil Ravi640215c2023-06-28 23:08:09 +00002289 for (i = 0; i < hapd->iface->num_hw_features; i++) {
2290 mode = &hapd->iface->hw_features[i];
2291
2292 if (iconf->hw_mode != HOSTAPD_MODE_IEEE80211ANY &&
2293 iconf->hw_mode != mode->mode)
2294 continue;
2295
2296 hostapd_get_hw_mode_any_channels(hapd, mode,
2297 !(iconf->acs_freq_list.num ||
2298 iconf->acs_ch_list.num),
2299 true, &params.allowed_freqs);
2300 }
2301
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002302 res = hostapd_drv_set_ap(hapd, &params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002303 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002304 if (res)
2305 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
2306 else
2307 ret = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002308fail:
2309 ieee802_11_free_ap_params(&params);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002310 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002311}
2312
2313
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002314void ieee802_11_set_beacon_per_bss_only(struct hostapd_data *hapd)
2315{
2316 __ieee802_11_set_beacon(hapd);
2317}
2318
2319
Hai Shaloma20dcd72022-02-04 13:43:00 -08002320int ieee802_11_set_beacon(struct hostapd_data *hapd)
2321{
2322 struct hostapd_iface *iface = hapd->iface;
2323 int ret;
2324 size_t i, j;
2325 bool is_6g;
2326
2327 ret = __ieee802_11_set_beacon(hapd);
2328 if (ret != 0)
2329 return ret;
2330
2331 if (!iface->interfaces || iface->interfaces->count <= 1)
2332 return 0;
2333
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002334 /* Update Beacon frames in case of 6 GHz colocation or AP MLD */
Hai Shaloma20dcd72022-02-04 13:43:00 -08002335 is_6g = is_6ghz_op_class(iface->conf->op_class);
2336 for (j = 0; j < iface->interfaces->count; j++) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002337 struct hostapd_iface *other;
2338 bool mld_ap = false;
Hai Shaloma20dcd72022-02-04 13:43:00 -08002339
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002340 other = iface->interfaces->iface[j];
2341 if (other == iface || !other || !other->conf)
Hai Shaloma20dcd72022-02-04 13:43:00 -08002342 continue;
2343
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002344#ifdef CONFIG_IEEE80211BE
Sunil Ravi88611412024-06-28 17:34:56 +00002345 if (hapd->conf->mld_ap && other->bss[0]->conf->mld_ap &&
2346 hapd->conf->mld_id == other->bss[0]->conf->mld_id)
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002347 mld_ap = true;
2348#endif /* CONFIG_IEEE80211BE */
2349
2350 if (is_6g == is_6ghz_op_class(other->conf->op_class) &&
2351 !mld_ap)
Hai Shaloma20dcd72022-02-04 13:43:00 -08002352 continue;
2353
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002354 for (i = 0; i < other->num_bss; i++) {
2355 if (other->bss[i] && other->bss[i]->started)
2356 __ieee802_11_set_beacon(other->bss[i]);
Hai Shaloma20dcd72022-02-04 13:43:00 -08002357 }
2358 }
2359
2360 return 0;
2361}
2362
2363
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002364int ieee802_11_set_beacons(struct hostapd_iface *iface)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002365{
2366 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002367 int ret = 0;
2368
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08002369 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002370 if (iface->bss[i]->started &&
2371 ieee802_11_set_beacon(iface->bss[i]) < 0)
2372 ret = -1;
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08002373 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002374
2375 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002376}
2377
Dmitry Shmidt04949592012-07-19 12:16:46 -07002378
2379/* only update beacons if started */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002380int ieee802_11_update_beacons(struct hostapd_iface *iface)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002381{
2382 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002383 int ret = 0;
2384
2385 for (i = 0; i < iface->num_bss; i++) {
2386 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
2387 ieee802_11_set_beacon(iface->bss[i]) < 0)
2388 ret = -1;
2389 }
2390
2391 return ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002392}
2393
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002394#endif /* CONFIG_NATIVE_WINDOWS */