blob: f8ce8103f0ad29166425c5727a246097f1da89c7 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / IEEE 802.11 Management: Beacon and Probe Request/Response
3 * Copyright (c) 2002-2004, Instant802 Networks, Inc.
4 * Copyright (c) 2005-2006, Devicescape Software, Inc.
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005 * Copyright (c) 2008-2012, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006 *
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007 * This software may be distributed under the terms of the BSD license.
8 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009 */
10
11#include "utils/includes.h"
12
13#ifndef CONFIG_NATIVE_WINDOWS
14
15#include "utils/common.h"
16#include "common/ieee802_11_defs.h"
17#include "common/ieee802_11_common.h"
Dmitry Shmidt7f656022015-02-25 14:36:37 -080018#include "common/hw_features_common.h"
Roshan Pius3a1667e2018-07-03 15:17:14 -070019#include "common/wpa_ctrl.h"
Sunil Ravi2a14cf12023-11-21 00:54:38 +000020#include "crypto/sha1.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070021#include "wps/wps_defs.h"
22#include "p2p/p2p.h"
23#include "hostapd.h"
24#include "ieee802_11.h"
25#include "wpa_auth.h"
26#include "wmm.h"
27#include "ap_config.h"
28#include "sta_info.h"
29#include "p2p_hostapd.h"
30#include "ap_drv_ops.h"
31#include "beacon.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070032#include "hs20.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080033#include "dfs.h"
Dmitry Shmidtaca489e2016-09-28 15:44:14 -070034#include "taxonomy.h"
Roshan Pius3a1667e2018-07-03 15:17:14 -070035#include "ieee802_11_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070036
37
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080038#ifdef NEED_AP_MLME
39
Dmitry Shmidt051af732013-10-22 13:52:46 -070040static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
41{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080042 if (len < 2 + 5)
43 return eid;
44
Dmitry Shmidt051af732013-10-22 13:52:46 -070045#ifdef CONFIG_TESTING_OPTIONS
46 if (hapd->conf->bss_load_test_set) {
Dmitry Shmidt051af732013-10-22 13:52:46 -070047 *eid++ = WLAN_EID_BSS_LOAD;
48 *eid++ = 5;
49 os_memcpy(eid, hapd->conf->bss_load_test, 5);
50 eid += 5;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080051 return eid;
Dmitry Shmidt051af732013-10-22 13:52:46 -070052 }
53#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080054 if (hapd->conf->bss_load_update_period) {
55 *eid++ = WLAN_EID_BSS_LOAD;
56 *eid++ = 5;
57 WPA_PUT_LE16(eid, hapd->num_sta);
58 eid += 2;
59 *eid++ = hapd->iface->channel_utilization;
60 WPA_PUT_LE16(eid, 0); /* no available admission capabity */
61 eid += 2;
62 }
Dmitry Shmidt051af732013-10-22 13:52:46 -070063 return eid;
64}
65
66
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070067static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
68{
69 u8 erp = 0;
70
71 if (hapd->iface->current_mode == NULL ||
72 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
73 return 0;
74
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080075 if (hapd->iface->olbc)
76 erp |= ERP_INFO_USE_PROTECTION;
77 if (hapd->iface->num_sta_non_erp > 0) {
78 erp |= ERP_INFO_NON_ERP_PRESENT |
79 ERP_INFO_USE_PROTECTION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070080 }
81 if (hapd->iface->num_sta_no_short_preamble > 0 ||
82 hapd->iconf->preamble == LONG_PREAMBLE)
83 erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
84
85 return erp;
86}
87
88
89static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
90{
Sunil Ravi2a14cf12023-11-21 00:54:38 +000091 enum hostapd_hw_mode hw_mode = hapd->iconf->hw_mode;
92
93 if (hw_mode != HOSTAPD_MODE_IEEE80211G &&
94 hw_mode != HOSTAPD_MODE_IEEE80211B)
95 return eid;
96
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070097 *eid++ = WLAN_EID_DS_PARAMS;
98 *eid++ = 1;
99 *eid++ = hapd->iconf->channel;
100 return eid;
101}
102
103
104static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
105{
106 if (hapd->iface->current_mode == NULL ||
107 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
108 return eid;
109
110 /* Set NonERP_present and use_protection bits if there
111 * are any associated NonERP stations. */
112 /* TODO: use_protection bit can be set to zero even if
113 * there are NonERP stations present. This optimization
114 * might be useful if NonERP stations are "quiet".
115 * See 802.11g/D6 E-1 for recommended practice.
116 * In addition, Non ERP present might be set, if AP detects Non ERP
117 * operation on other APs. */
118
119 /* Add ERP Information element */
120 *eid++ = WLAN_EID_ERP_INFO;
121 *eid++ = 1;
122 *eid++ = ieee802_11_erp_info(hapd);
123
124 return eid;
125}
126
127
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800128static u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid)
129{
130 u8 *pos = eid;
131 u8 local_pwr_constraint = 0;
132 int dfs;
133
134 if (hapd->iface->current_mode == NULL ||
135 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
136 return eid;
137
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700138 /* Let host drivers add this IE if DFS support is offloaded */
139 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)
140 return eid;
141
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800142 /*
143 * There is no DFS support and power constraint was not directly
144 * requested by config option.
145 */
146 if (!hapd->iconf->ieee80211h &&
147 hapd->iconf->local_pwr_constraint == -1)
148 return eid;
149
150 /* Check if DFS is required by regulatory. */
151 dfs = hostapd_is_dfs_required(hapd->iface);
152 if (dfs < 0) {
153 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
154 dfs);
155 dfs = 0;
156 }
157
158 if (dfs == 0 && hapd->iconf->local_pwr_constraint == -1)
159 return eid;
160
161 /*
162 * ieee80211h (DFS) is enabled so Power Constraint element shall
163 * be added when running on DFS channel whenever local_pwr_constraint
164 * is configured or not. In order to meet regulations when TPC is not
165 * implemented using a transmit power that is below the legal maximum
166 * (including any mitigation factor) should help. In this case,
167 * indicate 3 dB below maximum allowed transmit power.
168 */
169 if (hapd->iconf->local_pwr_constraint == -1)
170 local_pwr_constraint = 3;
171
172 /*
173 * A STA that is not an AP shall use a transmit power less than or
174 * equal to the local maximum transmit power level for the channel.
175 * The local maximum transmit power can be calculated from the formula:
176 * local max TX pwr = max TX pwr - local pwr constraint
177 * Where max TX pwr is maximum transmit power level specified for
178 * channel in Country element and local pwr constraint is specified
179 * for channel in this Power Constraint element.
180 */
181
182 /* Element ID */
183 *pos++ = WLAN_EID_PWR_CONSTRAINT;
184 /* Length */
185 *pos++ = 1;
186 /* Local Power Constraint */
187 if (local_pwr_constraint)
188 *pos++ = local_pwr_constraint;
189 else
190 *pos++ = hapd->iconf->local_pwr_constraint;
191
192 return pos;
193}
194
195
Sunil Ravia04bd252022-05-02 22:54:18 -0700196static u8 * hostapd_eid_country_add(struct hostapd_data *hapd, u8 *pos,
197 u8 *end, int chan_spacing,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700198 struct hostapd_channel_data *start,
199 struct hostapd_channel_data *prev)
200{
201 if (end - pos < 3)
202 return pos;
203
204 /* first channel number */
205 *pos++ = start->chan;
206 /* number of channels */
207 *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
208 /* maximum transmit power level */
Sunil Ravia04bd252022-05-02 22:54:18 -0700209 if (!is_6ghz_op_class(hapd->iconf->op_class))
210 *pos++ = start->max_tx_power;
211 else
212 *pos++ = 0; /* Reserved when operating on the 6 GHz band */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700213
214 return pos;
215}
216
217
Sunil Ravia04bd252022-05-02 22:54:18 -0700218static u8 * hostapd_fill_subband_triplets(struct hostapd_data *hapd, u8 *pos,
219 u8 *end)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700220{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700221 int i;
222 struct hostapd_hw_modes *mode;
223 struct hostapd_channel_data *start, *prev;
224 int chan_spacing = 1;
225
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700226 mode = hapd->iface->current_mode;
227 if (mode->mode == HOSTAPD_MODE_IEEE80211A)
228 chan_spacing = 4;
229
230 start = prev = NULL;
231 for (i = 0; i < mode->num_channels; i++) {
232 struct hostapd_channel_data *chan = &mode->channels[i];
233 if (chan->flag & HOSTAPD_CHAN_DISABLED)
234 continue;
235 if (start && prev &&
236 prev->chan + chan_spacing == chan->chan &&
237 start->max_tx_power == chan->max_tx_power) {
238 prev = chan;
239 continue; /* can use same entry */
240 }
241
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000242 if (start && prev)
Sunil Ravia04bd252022-05-02 22:54:18 -0700243 pos = hostapd_eid_country_add(hapd, pos, end,
244 chan_spacing,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700245 start, prev);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700246
247 /* Start new group */
248 start = prev = chan;
249 }
250
251 if (start) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700252 pos = hostapd_eid_country_add(hapd, pos, end, chan_spacing,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700253 start, prev);
254 }
255
Sunil Ravia04bd252022-05-02 22:54:18 -0700256 return pos;
257}
258
259
260static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
261 int max_len)
262{
263 u8 *pos = eid;
264 u8 *end = eid + max_len;
265
266 if (!hapd->iconf->ieee80211d || max_len < 6 ||
267 hapd->iface->current_mode == NULL)
268 return eid;
269
270 *pos++ = WLAN_EID_COUNTRY;
271 pos++; /* length will be set later */
272 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
273 pos += 3;
274
275 if (is_6ghz_op_class(hapd->iconf->op_class)) {
276 /* Force the third octet of the country string to indicate
277 * Global Operating Class (Table E-4) */
278 eid[4] = 0x04;
279
280 /* Operating Triplet field */
281 /* Operating Extension Identifier (>= 201 to indicate this is
282 * not a Subband Triplet field) */
283 *pos++ = 201;
284 /* Operating Class */
285 *pos++ = hapd->iconf->op_class;
286 /* Coverage Class */
287 *pos++ = 0;
288 /* Subband Triplets are required only for the 20 MHz case */
289 if (hapd->iconf->op_class == 131 ||
290 hapd->iconf->op_class == 136)
291 pos = hostapd_fill_subband_triplets(hapd, pos, end);
292 } else {
293 pos = hostapd_fill_subband_triplets(hapd, pos, end);
294 }
295
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700296 if ((pos - eid) & 1) {
297 if (end - pos < 1)
298 return eid;
299 *pos++ = 0; /* pad for 16-bit alignment */
300 }
301
302 eid[1] = (pos - eid) - 2;
303
304 return pos;
305}
306
307
Hai Shalom60840252021-02-19 19:02:11 -0800308const u8 * hostapd_wpa_ie(struct hostapd_data *hapd, u8 eid)
Hai Shalomfdcde762020-04-02 11:19:20 -0700309{
310 const u8 *ies;
311 size_t ies_len;
312
313 ies = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ies_len);
314 if (!ies)
315 return NULL;
316
317 return get_ie(ies, ies_len, eid);
318}
319
320
321static const u8 * hostapd_vendor_wpa_ie(struct hostapd_data *hapd,
322 u32 vendor_type)
323{
324 const u8 *ies;
325 size_t ies_len;
326
327 ies = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ies_len);
328 if (!ies)
329 return NULL;
330
331 return get_vendor_ie(ies, ies_len, vendor_type);
332}
333
334
335static u8 * hostapd_get_rsne(struct hostapd_data *hapd, u8 *pos, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700336{
337 const u8 *ie;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700338
Hai Shalomfdcde762020-04-02 11:19:20 -0700339 ie = hostapd_wpa_ie(hapd, WLAN_EID_RSN);
340 if (!ie || 2U + ie[1] > len)
341 return pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700342
Hai Shalomfdcde762020-04-02 11:19:20 -0700343 os_memcpy(pos, ie, 2 + ie[1]);
344 return pos + 2 + ie[1];
345}
346
347
348static u8 * hostapd_get_mde(struct hostapd_data *hapd, u8 *pos, size_t len)
349{
350 const u8 *ie;
351
352 ie = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN);
353 if (!ie || 2U + ie[1] > len)
354 return pos;
355
356 os_memcpy(pos, ie, 2 + ie[1]);
357 return pos + 2 + ie[1];
358}
359
360
361static u8 * hostapd_get_rsnxe(struct hostapd_data *hapd, u8 *pos, size_t len)
362{
363 const u8 *ie;
364
365#ifdef CONFIG_TESTING_OPTIONS
366 if (hapd->conf->no_beacon_rsnxe) {
367 wpa_printf(MSG_INFO, "TESTING: Do not add RSNXE into Beacon");
368 return pos;
369 }
370#endif /* CONFIG_TESTING_OPTIONS */
371 ie = hostapd_wpa_ie(hapd, WLAN_EID_RSNX);
372 if (!ie || 2U + ie[1] > len)
373 return pos;
374
375 os_memcpy(pos, ie, 2 + ie[1]);
376 return pos + 2 + ie[1];
377}
378
379
380static u8 * hostapd_get_wpa_ie(struct hostapd_data *hapd, u8 *pos, size_t len)
381{
382 const u8 *ie;
383
384 ie = hostapd_vendor_wpa_ie(hapd, WPA_IE_VENDOR_TYPE);
385 if (!ie || 2U + ie[1] > len)
386 return pos;
387
388 os_memcpy(pos, ie, 2 + ie[1]);
389 return pos + 2 + ie[1];
390}
391
392
393static u8 * hostapd_get_osen_ie(struct hostapd_data *hapd, u8 *pos, size_t len)
394{
395 const u8 *ie;
396
397 ie = hostapd_vendor_wpa_ie(hapd, OSEN_IE_VENDOR_TYPE);
398 if (!ie || 2U + ie[1] > len)
399 return pos;
400
401 os_memcpy(pos, ie, 2 + ie[1]);
402 return pos + 2 + ie[1];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700403}
404
405
Sunil Ravi7f769292024-07-23 22:21:32 +0000406static u8 * hostapd_get_rsne_override(struct hostapd_data *hapd, u8 *pos,
407 size_t len)
408{
409 const u8 *ie;
410
411 ie = hostapd_vendor_wpa_ie(hapd, RSNE_OVERRIDE_IE_VENDOR_TYPE);
412 if (!ie || 2U + ie[1] > len)
413 return pos;
414
415 os_memcpy(pos, ie, 2 + ie[1]);
416 return pos + 2 + ie[1];
417}
418
419
420static u8 * hostapd_get_rsne_override_2(struct hostapd_data *hapd, u8 *pos,
421 size_t len)
422{
423 const u8 *ie;
424
425 ie = hostapd_vendor_wpa_ie(hapd, RSNE_OVERRIDE_2_IE_VENDOR_TYPE);
426 if (!ie || 2U + ie[1] > len)
427 return pos;
428
429 os_memcpy(pos, ie, 2 + ie[1]);
430 return pos + 2 + ie[1];
431}
432
433
434static u8 * hostapd_get_rsnxe_override(struct hostapd_data *hapd, u8 *pos,
435 size_t len)
436{
437 const u8 *ie;
438
439 ie = hostapd_vendor_wpa_ie(hapd, RSNXE_OVERRIDE_IE_VENDOR_TYPE);
440 if (!ie || 2U + ie[1] > len)
441 return pos;
442
443 os_memcpy(pos, ie, 2 + ie[1]);
444 return pos + 2 + ie[1];
445}
446
447
448static size_t hostapd_get_rsne_override_len(struct hostapd_data *hapd)
449{
450 const u8 *ie;
451
452 ie = hostapd_vendor_wpa_ie(hapd, RSNE_OVERRIDE_IE_VENDOR_TYPE);
453 if (!ie)
454 return 0;
455 return 2 + ie[1];
456}
457
458
459static size_t hostapd_get_rsne_override_2_len(struct hostapd_data *hapd)
460{
461 const u8 *ie;
462
463 ie = hostapd_vendor_wpa_ie(hapd, RSNE_OVERRIDE_2_IE_VENDOR_TYPE);
464 if (!ie)
465 return 0;
466 return 2 + ie[1];
467}
468
469
470static size_t hostapd_get_rsnxe_override_len(struct hostapd_data *hapd)
471{
472 const u8 *ie;
473
474 ie = hostapd_vendor_wpa_ie(hapd, RSNXE_OVERRIDE_IE_VENDOR_TYPE);
475 if (!ie)
476 return 0;
477 return 2 + ie[1];
478}
479
480
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800481static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
482{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800483#ifdef CONFIG_TESTING_OPTIONS
484 if (hapd->iface->cs_oper_class && hapd->iconf->ecsa_ie_only)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800485 return eid;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800486#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800487
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800488 if (!hapd->cs_freq_params.channel)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800489 return eid;
490
491 *eid++ = WLAN_EID_CHANNEL_SWITCH;
492 *eid++ = 3;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700493 *eid++ = hapd->cs_block_tx;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800494 *eid++ = hapd->cs_freq_params.channel;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700495 *eid++ = hapd->cs_count;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800496
497 return eid;
498}
499
500
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800501static u8 * hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800502{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800503 if (!hapd->cs_freq_params.channel || !hapd->iface->cs_oper_class)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800504 return eid;
505
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800506 *eid++ = WLAN_EID_EXT_CHANSWITCH_ANN;
507 *eid++ = 4;
508 *eid++ = hapd->cs_block_tx;
509 *eid++ = hapd->iface->cs_oper_class;
510 *eid++ = hapd->cs_freq_params.channel;
511 *eid++ = hapd->cs_count;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800512
513 return eid;
514}
515
516
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800517static u8 * hostapd_eid_supported_op_classes(struct hostapd_data *hapd, u8 *eid)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800518{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800519 u8 op_class, channel;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800520
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800521 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) ||
522 !hapd->iface->freq)
523 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800524
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800525 if (ieee80211_freq_to_channel_ext(hapd->iface->freq,
526 hapd->iconf->secondary_channel,
Hai Shalom81f62d82019-07-22 12:10:00 -0700527 hostapd_get_oper_chwidth(hapd->iconf),
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800528 &op_class, &channel) ==
529 NUM_HOSTAPD_MODES)
530 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800531
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800532 *eid++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES;
533 *eid++ = 2;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800534
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800535 /* Current Operating Class */
536 *eid++ = op_class;
537
538 /* TODO: Advertise all the supported operating classes */
539 *eid++ = 0;
540
541 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800542}
543
544
Sunil Ravi77d572f2023-01-17 23:58:31 +0000545static int
546ieee802_11_build_ap_params_mbssid(struct hostapd_data *hapd,
547 struct wpa_driver_ap_params *params)
548{
549 struct hostapd_iface *iface = hapd->iface;
550 struct hostapd_data *tx_bss;
Sunil Ravi640215c2023-06-28 23:08:09 +0000551 size_t len, rnr_len = 0;
Sunil Ravi77d572f2023-01-17 23:58:31 +0000552 u8 elem_count = 0, *elem = NULL, **elem_offset = NULL, *end;
Sunil Ravi640215c2023-06-28 23:08:09 +0000553 u8 rnr_elem_count = 0, *rnr_elem = NULL, **rnr_elem_offset = NULL;
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000554 size_t i;
Sunil Ravi77d572f2023-01-17 23:58:31 +0000555
556 if (!iface->mbssid_max_interfaces ||
557 iface->num_bss > iface->mbssid_max_interfaces ||
558 (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED &&
559 !iface->ema_max_periodicity))
560 goto fail;
561
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000562 /* Make sure bss->xrates_supported is set for all BSSs to know whether
563 * it need to be non-inherited. */
564 for (i = 0; i < iface->num_bss; i++) {
565 u8 buf[100];
566
567 hostapd_eid_ext_supp_rates(iface->bss[i], buf);
568 }
569
Sunil Ravi77d572f2023-01-17 23:58:31 +0000570 tx_bss = hostapd_mbssid_get_tx_bss(hapd);
571 len = hostapd_eid_mbssid_len(tx_bss, WLAN_FC_STYPE_BEACON, &elem_count,
Sunil Ravi640215c2023-06-28 23:08:09 +0000572 NULL, 0, &rnr_len);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000573 if (!len || (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED &&
574 elem_count > iface->ema_max_periodicity))
575 goto fail;
576
577 elem = os_zalloc(len);
578 if (!elem)
579 goto fail;
580
581 elem_offset = os_zalloc(elem_count * sizeof(u8 *));
582 if (!elem_offset)
583 goto fail;
584
Sunil Ravi640215c2023-06-28 23:08:09 +0000585 if (rnr_len) {
586 rnr_elem = os_zalloc(rnr_len);
587 if (!rnr_elem)
588 goto fail;
589
590 rnr_elem_offset = os_calloc(elem_count + 1, sizeof(u8 *));
591 if (!rnr_elem_offset)
592 goto fail;
593 }
594
Sunil Ravi77d572f2023-01-17 23:58:31 +0000595 end = hostapd_eid_mbssid(tx_bss, elem, elem + len, WLAN_FC_STYPE_BEACON,
Sunil Ravi640215c2023-06-28 23:08:09 +0000596 elem_count, elem_offset, NULL, 0, rnr_elem,
597 &rnr_elem_count, rnr_elem_offset, rnr_len);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000598
599 params->mbssid_tx_iface = tx_bss->conf->iface;
600 params->mbssid_index = hostapd_mbssid_get_bss_index(hapd);
601 params->mbssid_elem = elem;
602 params->mbssid_elem_len = end - elem;
603 params->mbssid_elem_count = elem_count;
604 params->mbssid_elem_offset = elem_offset;
Sunil Ravi640215c2023-06-28 23:08:09 +0000605 params->rnr_elem = rnr_elem;
606 params->rnr_elem_len = rnr_len;
607 params->rnr_elem_count = rnr_elem_count;
608 params->rnr_elem_offset = rnr_elem_offset;
Sunil Ravi77d572f2023-01-17 23:58:31 +0000609 if (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED)
610 params->ema = true;
611
612 return 0;
613
614fail:
Sunil Ravi640215c2023-06-28 23:08:09 +0000615 os_free(rnr_elem);
616 os_free(rnr_elem_offset);
617 os_free(elem_offset);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000618 os_free(elem);
619 wpa_printf(MSG_ERROR, "MBSSID: Configuration failed");
620 return -1;
621}
622
623
624static u8 * hostapd_eid_mbssid_config(struct hostapd_data *hapd, u8 *eid,
625 u8 mbssid_elem_count)
626{
627 struct hostapd_iface *iface = hapd->iface;
628
629 if (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED) {
630 *eid++ = WLAN_EID_EXTENSION;
631 *eid++ = 3;
632 *eid++ = WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION;
633 *eid++ = iface->num_bss;
634 *eid++ = mbssid_elem_count;
635 }
636
637 return eid;
638}
639
640
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000641static size_t he_elem_len(struct hostapd_data *hapd)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800642{
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000643 size_t len = 0;
644
645#ifdef CONFIG_IEEE80211AX
646 if (!hapd->iconf->ieee80211ax || hapd->conf->disable_11ax)
647 return len;
648
649 len += 3 + sizeof(struct ieee80211_he_capabilities) +
650 3 + sizeof(struct ieee80211_he_operation) +
651 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
652 3 + sizeof(struct ieee80211_spatial_reuse);
653 if (is_6ghz_op_class(hapd->iconf->op_class)) {
654 len += sizeof(struct ieee80211_he_6ghz_oper_info) +
655 3 + sizeof(struct ieee80211_he_6ghz_band_cap);
656 /* An additional Transmit Power Envelope element for
657 * subordinate client */
658 if (he_reg_is_indoor(hapd->iconf->he_6ghz_reg_pwr_type))
659 len += 4;
660
661 /* An additional Transmit Power Envelope element for
662 * default client with unit interpretation of regulatory
663 * client EIRP */
664 if (hapd->iconf->reg_def_cli_eirp != -1 &&
665 he_reg_is_sp(hapd->iconf->he_6ghz_reg_pwr_type))
666 len += 4;
667 }
668#endif /* CONFIG_IEEE80211AX */
669
670 return len;
671}
672
673
674struct probe_resp_params {
675 const struct ieee80211_mgmt *req;
676 bool is_p2p;
677
678 /* Generated IEs will be included inside an ML element */
679 bool is_ml_sta_info;
680 struct hostapd_data *mld_ap;
681 struct mld_info *mld_info;
682
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800683 struct ieee80211_mgmt *resp;
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000684 size_t resp_len;
685 u8 *csa_pos;
686 u8 *ecsa_pos;
687 const u8 *known_bss;
688 u8 known_bss_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800689
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000690#ifdef CONFIG_IEEE80211AX
691 u8 *cca_pos;
692#endif /* CONFIG_IEEE80211AX */
693};
Sunil Ravi77d572f2023-01-17 23:58:31 +0000694
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000695
696static void hostapd_free_probe_resp_params(struct probe_resp_params *params)
697{
698#ifdef CONFIG_IEEE80211BE
699 if (!params)
700 return;
701 ap_sta_free_sta_profile(params->mld_info);
702 os_free(params->mld_info);
703 params->mld_info = NULL;
704#endif /* CONFIG_IEEE80211BE */
705}
706
707
708static size_t hostapd_probe_resp_elems_len(struct hostapd_data *hapd,
709 struct probe_resp_params *params)
710{
711 size_t buflen = 0;
712
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800713#ifdef CONFIG_WPS
714 if (hapd->wps_probe_resp_ie)
715 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
716#endif /* CONFIG_WPS */
717#ifdef CONFIG_P2P
718 if (hapd->p2p_probe_resp_ie)
719 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
720#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800721#ifdef CONFIG_FST
722 if (hapd->iface->fst_ies)
723 buflen += wpabuf_len(hapd->iface->fst_ies);
724#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700725 if (hapd->conf->vendor_elements)
726 buflen += wpabuf_len(hapd->conf->vendor_elements);
Sunil Ravi7f769292024-07-23 22:21:32 +0000727#ifdef CONFIG_TESTING_OPTIONS
728 if (hapd->conf->presp_elements)
729 buflen += wpabuf_len(hapd->conf->presp_elements);
730#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800731 if (hapd->conf->vendor_vht) {
732 buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
733 2 + sizeof(struct ieee80211_vht_operation);
734 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800735
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000736 buflen += he_elem_len(hapd);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800737
Sunil Ravia04bd252022-05-02 22:54:18 -0700738#ifdef CONFIG_IEEE80211BE
739 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
740 buflen += hostapd_eid_eht_capab_len(hapd, IEEE80211_MODE_AP);
741 buflen += 3 + sizeof(struct ieee80211_eht_operation);
Sunil Ravi036cec52023-03-29 11:35:17 -0700742 if (hapd->iconf->punct_bitmap)
743 buflen += EHT_OPER_DISABLED_SUBCHAN_BITMAP_SIZE;
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000744
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000745 if (!params->is_ml_sta_info && hapd->conf->mld_ap) {
746 struct hostapd_data *ml_elem_ap =
747 params->mld_ap ? params->mld_ap : hapd;
748
749 buflen += hostapd_eid_eht_ml_beacon_len(
750 ml_elem_ap, params->mld_info, !!params->mld_ap);
751 }
Sunil Ravia04bd252022-05-02 22:54:18 -0700752 }
753#endif /* CONFIG_IEEE80211BE */
754
Sunil Ravi77d572f2023-01-17 23:58:31 +0000755 buflen += hostapd_eid_mbssid_len(hapd, WLAN_FC_STYPE_PROBE_RESP, NULL,
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000756 params->known_bss,
757 params->known_bss_len, NULL);
758 if (!params->is_ml_sta_info)
Sunil Ravi7f769292024-07-23 22:21:32 +0000759 buflen += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_PROBE_RESP,
760 true);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800761 buflen += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700762 buflen += hostapd_eid_owe_trans_len(hapd);
Hai Shalomfdcde762020-04-02 11:19:20 -0700763 buflen += hostapd_eid_dpp_cc_len(hapd);
Sunil Ravi7f769292024-07-23 22:21:32 +0000764 buflen += hostapd_get_rsne_override_len(hapd);
765 buflen += hostapd_get_rsne_override_2_len(hapd);
766 buflen += hostapd_get_rsnxe_override_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800767
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000768 return buflen;
769}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800770
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800771
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000772static u8 * hostapd_probe_resp_fill_elems(struct hostapd_data *hapd,
773 struct probe_resp_params *params,
774 u8 *pos, size_t len)
775{
776 u8 *csa_pos;
777 u8 *epos;
Sunil8cd6f4d2022-06-28 18:40:46 +0000778
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000779 epos = pos + len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800780
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000781 if (!params->is_ml_sta_info) {
782 *pos++ = WLAN_EID_SSID;
783 *pos++ = hapd->conf->ssid.ssid_len;
784 os_memcpy(pos, hapd->conf->ssid.ssid,
785 hapd->conf->ssid.ssid_len);
786 pos += hapd->conf->ssid.ssid_len;
787 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800788
789 /* Supported rates */
790 pos = hostapd_eid_supp_rates(hapd, pos);
791
792 /* DS Params */
793 pos = hostapd_eid_ds_params(hapd, pos);
794
795 pos = hostapd_eid_country(hapd, pos, epos - pos);
796
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800797 /* Power Constraint element */
798 pos = hostapd_eid_pwr_constraint(hapd, pos);
799
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000800 /*
801 * CSA IE
802 * TODO: This should be included inside the ML sta profile
803 */
804 if (!params->is_ml_sta_info) {
805 csa_pos = hostapd_eid_csa(hapd, pos);
806 if (csa_pos != pos)
807 params->csa_pos = csa_pos - 1;
808 else
809 params->csa_pos = NULL;
810 pos = csa_pos;
811 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800812
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800813 /* ERP Information element */
814 pos = hostapd_eid_erp_info(hapd, pos);
815
816 /* Extended supported rates */
817 pos = hostapd_eid_ext_supp_rates(hapd, pos);
818
Hai Shalomfdcde762020-04-02 11:19:20 -0700819 pos = hostapd_get_rsne(hapd, pos, epos - pos);
Dmitry Shmidt051af732013-10-22 13:52:46 -0700820 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000821 pos = hostapd_eid_mbssid(hapd, pos, epos, WLAN_FC_STYPE_PROBE_RESP, 0,
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000822 NULL, params->known_bss, params->known_bss_len,
823 NULL, NULL, NULL, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800824 pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700825 pos = hostapd_get_mde(hapd, pos, epos - pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800826
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000827 /*
828 * eCSA IE
829 * TODO: This should be included inside the ML sta profile
830 */
831 if (!params->is_ml_sta_info) {
832 csa_pos = hostapd_eid_ecsa(hapd, pos);
833 if (csa_pos != pos)
834 params->ecsa_pos = csa_pos - 1;
835 else
836 params->ecsa_pos = NULL;
837 pos = csa_pos;
838 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800839
840 pos = hostapd_eid_supported_op_classes(hapd, pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800841 pos = hostapd_eid_ht_capabilities(hapd, pos);
842 pos = hostapd_eid_ht_operation(hapd, pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800843
Sunil Ravi77d572f2023-01-17 23:58:31 +0000844 /* Probe Response frames always include all non-TX profiles except
845 * when a list of known BSSes is included in the Probe Request frame. */
846 pos = hostapd_eid_ext_capab(hapd, pos,
847 hapd->iconf->mbssid >= MBSSID_ENABLED &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000848 !params->known_bss_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800849
850 pos = hostapd_eid_time_adv(hapd, pos);
851 pos = hostapd_eid_time_zone(hapd, pos);
852
853 pos = hostapd_eid_interworking(hapd, pos);
854 pos = hostapd_eid_adv_proto(hapd, pos);
855 pos = hostapd_eid_roaming_consortium(hapd, pos);
856
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800857#ifdef CONFIG_FST
858 if (hapd->iface->fst_ies) {
859 os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies),
860 wpabuf_len(hapd->iface->fst_ies));
861 pos += wpabuf_len(hapd->iface->fst_ies);
862 }
863#endif /* CONFIG_FST */
864
Dmitry Shmidt04949592012-07-19 12:16:46 -0700865#ifdef CONFIG_IEEE80211AC
Hai Shalomc3565922019-10-28 11:58:20 -0700866 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
867 !is_6ghz_op_class(hapd->iconf->op_class)) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700868 pos = hostapd_eid_vht_capabilities(hapd, pos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800869 pos = hostapd_eid_vht_operation(hapd, pos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800870 pos = hostapd_eid_txpower_envelope(hapd, pos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800871 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800872#endif /* CONFIG_IEEE80211AC */
873
Hai Shalom60840252021-02-19 19:02:11 -0800874#ifdef CONFIG_IEEE80211AX
875 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax &&
876 is_6ghz_op_class(hapd->iconf->op_class))
877 pos = hostapd_eid_txpower_envelope(hapd, pos);
878#endif /* CONFIG_IEEE80211AX */
879
Hai Shaloma20dcd72022-02-04 13:43:00 -0800880 pos = hostapd_eid_wb_chsw_wrapper(hapd, pos);
Hai Shalom899fcc72020-10-19 14:38:18 -0700881
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000882 if (!params->is_ml_sta_info)
Sunil Ravi7f769292024-07-23 22:21:32 +0000883 pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_PROBE_RESP,
884 true);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800885 pos = hostapd_eid_fils_indic(hapd, pos, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -0700886 pos = hostapd_get_rsnxe(hapd, pos, epos - pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800887
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700888#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -0800889 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700890 u8 *cca_pos;
891
Hai Shalom81f62d82019-07-22 12:10:00 -0700892 pos = hostapd_eid_he_capab(hapd, pos, IEEE80211_MODE_AP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700893 pos = hostapd_eid_he_operation(hapd, pos);
Sunil Ravia04bd252022-05-02 22:54:18 -0700894
895 /* BSS Color Change Announcement element */
896 cca_pos = hostapd_eid_cca(hapd, pos);
897 if (cca_pos != pos)
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000898 params->cca_pos = cca_pos - 2;
899 else
900 params->cca_pos = NULL;
Sunil Ravia04bd252022-05-02 22:54:18 -0700901 pos = cca_pos;
902
Hai Shalom81f62d82019-07-22 12:10:00 -0700903 pos = hostapd_eid_spatial_reuse(hapd, pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700904 pos = hostapd_eid_he_mu_edca_parameter_set(hapd, pos);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700905 pos = hostapd_eid_he_6ghz_band_cap(hapd, pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700906 }
907#endif /* CONFIG_IEEE80211AX */
908
Sunil Ravia04bd252022-05-02 22:54:18 -0700909#ifdef CONFIG_IEEE80211BE
910 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000911 struct hostapd_data *ml_elem_ap =
912 params->mld_ap ? params->mld_ap : hapd;
913
914 if (ml_elem_ap->conf->mld_ap)
915 pos = hostapd_eid_eht_ml_beacon(
916 ml_elem_ap, params->mld_info,
917 pos, !!params->mld_ap);
918
Sunil Ravia04bd252022-05-02 22:54:18 -0700919 pos = hostapd_eid_eht_capab(hapd, pos, IEEE80211_MODE_AP);
920 pos = hostapd_eid_eht_operation(hapd, pos);
921 }
922#endif /* CONFIG_IEEE80211BE */
923
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800924#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800925 if (hapd->conf->vendor_vht)
926 pos = hostapd_eid_vendor_vht(hapd, pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700927#endif /* CONFIG_IEEE80211AC */
928
Hai Shalomfdcde762020-04-02 11:19:20 -0700929 /* WPA / OSEN */
930 pos = hostapd_get_wpa_ie(hapd, pos, epos - pos);
931 pos = hostapd_get_osen_ie(hapd, pos, epos - pos);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800932
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800933 /* Wi-Fi Alliance WMM */
934 pos = hostapd_eid_wmm(hapd, pos);
935
936#ifdef CONFIG_WPS
937 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
938 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
939 wpabuf_len(hapd->wps_probe_resp_ie));
940 pos += wpabuf_len(hapd->wps_probe_resp_ie);
941 }
942#endif /* CONFIG_WPS */
943
944#ifdef CONFIG_P2P
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000945 if ((hapd->conf->p2p & P2P_ENABLED) && params->is_p2p &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800946 hapd->p2p_probe_resp_ie) {
947 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
948 wpabuf_len(hapd->p2p_probe_resp_ie));
949 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
950 }
951#endif /* CONFIG_P2P */
952#ifdef CONFIG_P2P_MANAGER
953 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
954 P2P_MANAGE)
955 pos = hostapd_eid_p2p_manage(hapd, pos);
956#endif /* CONFIG_P2P_MANAGER */
957
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700958#ifdef CONFIG_HS20
959 pos = hostapd_eid_hs20_indication(hapd, pos);
960#endif /* CONFIG_HS20 */
961
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000962 pos = hostapd_eid_mbo(hapd, pos, epos - pos);
963 pos = hostapd_eid_owe_trans(hapd, pos, epos - pos);
964 pos = hostapd_eid_dpp_cc(hapd, pos, epos - pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800965
Sunil Ravi7f769292024-07-23 22:21:32 +0000966 pos = hostapd_get_rsne_override(hapd, pos, epos - pos);
967 pos = hostapd_get_rsne_override_2(hapd, pos, epos - pos);
968 pos = hostapd_get_rsnxe_override(hapd, pos, epos - pos);
969
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700970 if (hapd->conf->vendor_elements) {
971 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
972 wpabuf_len(hapd->conf->vendor_elements));
973 pos += wpabuf_len(hapd->conf->vendor_elements);
974 }
975
Sunil Ravi7f769292024-07-23 22:21:32 +0000976#ifdef CONFIG_TESTING_OPTIONS
977 if (hapd->conf->presp_elements) {
978 os_memcpy(pos, wpabuf_head(hapd->conf->presp_elements),
979 wpabuf_len(hapd->conf->presp_elements));
980 pos += wpabuf_len(hapd->conf->presp_elements);
981 }
982#endif /* CONFIG_TESTING_OPTIONS */
983
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000984 return pos;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800985}
986
987
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000988static void hostapd_gen_probe_resp(struct hostapd_data *hapd,
989 struct probe_resp_params *params)
990{
991 u8 *pos;
992 size_t buflen;
993
994 hapd = hostapd_mbssid_get_tx_bss(hapd);
995
996#define MAX_PROBERESP_LEN 768
997 buflen = MAX_PROBERESP_LEN;
998 buflen += hostapd_probe_resp_elems_len(hapd, params);
999 params->resp = os_zalloc(buflen);
1000 if (!params->resp) {
1001 params->resp_len = 0;
1002 return;
1003 }
1004
1005 params->resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1006 WLAN_FC_STYPE_PROBE_RESP);
1007 /* Unicast the response to all requests on bands other than 6 GHz. For
1008 * the 6 GHz, unicast is used only if the actual SSID is not included in
1009 * the Beacon frames. Otherwise, broadcast response is used per IEEE
1010 * Std 802.11ax-2021, 26.17.2.3.2. Broadcast address is also used for
1011 * the Probe Response frame template for the unsolicited (i.e., not as
1012 * a response to a specific request) case. */
1013 if (params->req && (!is_6ghz_op_class(hapd->iconf->op_class) ||
1014 hapd->conf->ignore_broadcast_ssid))
1015 os_memcpy(params->resp->da, params->req->sa, ETH_ALEN);
1016 else
1017 os_memset(params->resp->da, 0xff, ETH_ALEN);
1018 os_memcpy(params->resp->sa, hapd->own_addr, ETH_ALEN);
1019
1020 os_memcpy(params->resp->bssid, hapd->own_addr, ETH_ALEN);
1021 params->resp->u.probe_resp.beacon_int =
1022 host_to_le16(hapd->iconf->beacon_int);
1023
1024 /* hardware or low-level driver will setup seq_ctrl and timestamp */
1025 params->resp->u.probe_resp.capab_info =
1026 host_to_le16(hostapd_own_capab_info(hapd));
1027
1028 pos = hostapd_probe_resp_fill_elems(hapd, params,
1029 params->resp->u.probe_resp.variable,
1030 buflen);
1031
1032 params->resp_len = pos - (u8 *) params->resp;
1033}
1034
1035
1036#ifdef CONFIG_IEEE80211BE
1037static void hostapd_fill_probe_resp_ml_params(struct hostapd_data *hapd,
1038 struct probe_resp_params *params,
1039 const struct ieee80211_mgmt *mgmt,
1040 int mld_id, u16 links)
1041{
1042 struct probe_resp_params sta_info_params;
1043 struct hostapd_data *link;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001044
1045 params->mld_ap = NULL;
1046 params->mld_info = os_zalloc(sizeof(*params->mld_info));
1047 if (!params->mld_info)
1048 return;
1049
1050 wpa_printf(MSG_DEBUG,
1051 "MLD: Got ML probe request with AP MLD ID %d for links %04x",
1052 mld_id, links);
1053
Sunil Ravi7f769292024-07-23 22:21:32 +00001054 for_each_mld_link(link, hapd) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001055 struct mld_link_info *link_info;
1056 size_t buflen;
1057 u8 mld_link_id = link->mld_link_id;
1058 u8 *epos;
1059 u8 buf[EHT_ML_MAX_STA_PROF_LEN];
1060
1061 /*
1062 * Set mld_ap iff the ML probe request explicitly
1063 * requested a specific MLD ID. In that case, the targeted
1064 * AP may have been a nontransmitted BSSID on the same
1065 * interface.
1066 */
1067 if (mld_id != -1 && link->iface == hapd->iface)
1068 params->mld_ap = link;
1069
1070 /* Never duplicate main Probe Response frame body */
1071 if (link == hapd)
1072 continue;
1073
1074 /* Only include requested links */
1075 if (!(BIT(mld_link_id) & links))
1076 continue;
1077
1078 link_info = &params->mld_info->links[mld_link_id];
1079
1080 sta_info_params.req = params->req;
1081 sta_info_params.is_p2p = false;
1082 sta_info_params.is_ml_sta_info = true;
1083 sta_info_params.mld_ap = NULL;
1084 sta_info_params.mld_info = NULL;
1085
1086 buflen = MAX_PROBERESP_LEN;
1087 buflen += hostapd_probe_resp_elems_len(link, &sta_info_params);
1088
1089 if (buflen > EHT_ML_MAX_STA_PROF_LEN) {
1090 wpa_printf(MSG_DEBUG,
1091 "MLD: Not including link %d in ML probe response (%zu bytes is too long)",
1092 mld_link_id, buflen);
1093 goto fail;
1094 }
1095
1096 /*
1097 * NOTE: This does not properly handle inheritance and
1098 * various other things.
1099 */
1100 link_info->valid = true;
1101 epos = buf;
1102
1103 /* Capabilities is the only fixed parameter */
1104 WPA_PUT_LE16(epos, hostapd_own_capab_info(hapd));
1105 epos += 2;
1106
1107 epos = hostapd_probe_resp_fill_elems(
1108 link, &sta_info_params, epos,
1109 EHT_ML_MAX_STA_PROF_LEN - 2);
1110 link_info->resp_sta_profile_len = epos - buf;
1111 os_free(link_info->resp_sta_profile);
1112 link_info->resp_sta_profile = os_memdup(
1113 buf, link_info->resp_sta_profile_len);
1114 if (!link_info->resp_sta_profile)
1115 link_info->resp_sta_profile_len = 0;
1116 os_memcpy(link_info->local_addr, link->own_addr, ETH_ALEN);
1117
1118 wpa_printf(MSG_DEBUG,
1119 "MLD: ML probe response includes link sta info for %d: %u bytes (estimate %zu)",
1120 mld_link_id, link_info->resp_sta_profile_len,
1121 buflen);
1122 }
1123
1124 if (mld_id != -1 && !params->mld_ap) {
1125 wpa_printf(MSG_DEBUG,
1126 "MLD: No nontransmitted BSSID for MLD ID %d",
1127 mld_id);
1128 goto fail;
1129 }
1130
1131 return;
1132
1133fail:
1134 hostapd_free_probe_resp_params(params);
1135 params->mld_ap = NULL;
1136 params->mld_info = NULL;
1137}
1138#endif /* CONFIG_IEEE80211BE */
1139
1140
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001141enum ssid_match_result {
1142 NO_SSID_MATCH,
1143 EXACT_SSID_MATCH,
Hai Shaloma20dcd72022-02-04 13:43:00 -08001144 WILDCARD_SSID_MATCH,
1145 CO_LOCATED_SSID_MATCH,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001146};
1147
1148static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
1149 const u8 *ssid, size_t ssid_len,
1150 const u8 *ssid_list,
Hai Shalomfdcde762020-04-02 11:19:20 -07001151 size_t ssid_list_len,
1152 const u8 *short_ssid_list,
1153 size_t short_ssid_list_len)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001154{
1155 const u8 *pos, *end;
Hai Shaloma20dcd72022-02-04 13:43:00 -08001156 struct hostapd_iface *iface = hapd->iface;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001157 int wildcard = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -08001158 size_t i, j;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001159
1160 if (ssid_len == 0)
1161 wildcard = 1;
1162 if (ssid_len == hapd->conf->ssid.ssid_len &&
1163 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
1164 return EXACT_SSID_MATCH;
1165
Hai Shalomfdcde762020-04-02 11:19:20 -07001166 if (ssid_list) {
1167 pos = ssid_list;
1168 end = ssid_list + ssid_list_len;
1169 while (end - pos >= 2) {
1170 if (2 + pos[1] > end - pos)
1171 break;
1172 if (pos[1] == 0)
1173 wildcard = 1;
1174 if (pos[1] == hapd->conf->ssid.ssid_len &&
1175 os_memcmp(pos + 2, hapd->conf->ssid.ssid,
1176 pos[1]) == 0)
1177 return EXACT_SSID_MATCH;
1178 pos += 2 + pos[1];
1179 }
1180 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001181
Hai Shalomfdcde762020-04-02 11:19:20 -07001182 if (short_ssid_list) {
1183 pos = short_ssid_list;
1184 end = short_ssid_list + short_ssid_list_len;
1185 while (end - pos >= 4) {
1186 if (hapd->conf->ssid.short_ssid == WPA_GET_LE32(pos))
1187 return EXACT_SSID_MATCH;
1188 pos += 4;
1189 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001190 }
1191
Hai Shaloma20dcd72022-02-04 13:43:00 -08001192 if (wildcard)
1193 return WILDCARD_SSID_MATCH;
1194
1195 if (!iface->interfaces || iface->interfaces->count <= 1 ||
1196 is_6ghz_op_class(hapd->iconf->op_class))
1197 return NO_SSID_MATCH;
1198
1199 for (i = 0; i < iface->interfaces->count; i++) {
1200 struct hostapd_iface *colocated;
1201
1202 colocated = iface->interfaces->iface[i];
1203
1204 if (colocated == iface ||
1205 !is_6ghz_op_class(colocated->conf->op_class))
1206 continue;
1207
1208 for (j = 0; j < colocated->num_bss; j++) {
1209 struct hostapd_bss_config *conf;
1210
1211 conf = colocated->bss[j]->conf;
1212 if (ssid_len == conf->ssid.ssid_len &&
1213 os_memcmp(ssid, conf->ssid.ssid, ssid_len) == 0)
1214 return CO_LOCATED_SSID_MATCH;
1215 }
1216 }
1217
1218 return NO_SSID_MATCH;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001219}
1220
1221
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001222void sta_track_expire(struct hostapd_iface *iface, int force)
1223{
1224 struct os_reltime now;
1225 struct hostapd_sta_info *info;
1226
1227 if (!iface->num_sta_seen)
1228 return;
1229
1230 os_get_reltime(&now);
1231 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
1232 list))) {
1233 if (!force &&
1234 !os_reltime_expired(&now, &info->last_seen,
1235 iface->conf->track_sta_max_age))
1236 break;
1237 force = 0;
1238
1239 wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
1240 MACSTR, iface->bss[0]->conf->iface,
1241 MAC2STR(info->addr));
1242 dl_list_del(&info->list);
1243 iface->num_sta_seen--;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001244 sta_track_del(info);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001245 }
1246}
1247
1248
1249static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
1250 const u8 *addr)
1251{
1252 struct hostapd_sta_info *info;
1253
1254 dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001255 if (ether_addr_equal(addr, info->addr))
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001256 return info;
1257
1258 return NULL;
1259}
1260
1261
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001262void sta_track_add(struct hostapd_iface *iface, const u8 *addr, int ssi_signal)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001263{
1264 struct hostapd_sta_info *info;
1265
1266 info = sta_track_get(iface, addr);
1267 if (info) {
1268 /* Move the most recent entry to the end of the list */
1269 dl_list_del(&info->list);
1270 dl_list_add_tail(&iface->sta_seen, &info->list);
1271 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001272 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001273 return;
1274 }
1275
1276 /* Add a new entry */
1277 info = os_zalloc(sizeof(*info));
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001278 if (info == NULL)
1279 return;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001280 os_memcpy(info->addr, addr, ETH_ALEN);
1281 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001282 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001283
1284 if (iface->num_sta_seen >= iface->conf->track_sta_max_num) {
1285 /* Expire oldest entry to make room for a new one */
1286 sta_track_expire(iface, 1);
1287 }
1288
1289 wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
1290 MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr));
1291 dl_list_add_tail(&iface->sta_seen, &info->list);
1292 iface->num_sta_seen++;
1293}
1294
1295
1296struct hostapd_data *
1297sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
1298 const char *ifname)
1299{
1300 struct hapd_interfaces *interfaces = iface->interfaces;
1301 size_t i, j;
1302
1303 for (i = 0; i < interfaces->count; i++) {
1304 struct hostapd_data *hapd = NULL;
1305
1306 iface = interfaces->iface[i];
1307 for (j = 0; j < iface->num_bss; j++) {
1308 hapd = iface->bss[j];
1309 if (os_strcmp(ifname, hapd->conf->iface) == 0)
1310 break;
1311 hapd = NULL;
1312 }
1313
1314 if (hapd && sta_track_get(iface, addr))
1315 return hapd;
1316 }
1317
1318 return NULL;
1319}
1320
1321
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001322#ifdef CONFIG_TAXONOMY
1323void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr,
1324 struct wpabuf **probe_ie_taxonomy)
1325{
1326 struct hostapd_sta_info *info;
1327
1328 info = sta_track_get(iface, addr);
1329 if (!info)
1330 return;
1331
1332 wpabuf_free(*probe_ie_taxonomy);
1333 *probe_ie_taxonomy = info->probe_ie_taxonomy;
1334 info->probe_ie_taxonomy = NULL;
1335}
1336#endif /* CONFIG_TAXONOMY */
1337
1338
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001339#ifdef CONFIG_IEEE80211BE
1340static bool parse_ml_probe_req(const struct ieee80211_eht_ml *ml, size_t ml_len,
1341 int *mld_id, u16 *links)
1342{
1343 u16 ml_control;
1344 const struct element *sub;
1345 const u8 *pos;
1346 size_t len;
1347
1348 *mld_id = -1;
1349 *links = 0xffff;
1350
1351 if (ml_len < sizeof(struct ieee80211_eht_ml))
1352 return false;
1353
1354 ml_control = le_to_host16(ml->ml_control);
1355 if ((ml_control & MULTI_LINK_CONTROL_TYPE_MASK) !=
1356 MULTI_LINK_CONTROL_TYPE_PROBE_REQ) {
1357 wpa_printf(MSG_DEBUG, "MLD: Not an ML probe req");
1358 return false;
1359 }
1360
1361 if (sizeof(struct ieee80211_eht_ml) + 1 > ml_len) {
1362 wpa_printf(MSG_DEBUG, "MLD: ML probe req too short");
1363 return false;
1364 }
1365
1366 pos = ml->variable;
1367 len = pos[0];
1368 if (len < 1 || sizeof(struct ieee80211_eht_ml) + len > ml_len) {
1369 wpa_printf(MSG_DEBUG,
1370 "MLD: ML probe request with invalid length");
1371 return false;
1372 }
1373
1374 if (ml_control & EHT_ML_PRES_BM_PROBE_REQ_AP_MLD_ID) {
1375 if (len < 2) {
1376 wpa_printf(MSG_DEBUG,
1377 "MLD: ML probe req too short for MLD ID");
1378 return false;
1379 }
1380
1381 *mld_id = pos[1];
1382 }
1383 pos += len;
1384
1385 /* Parse subelements (if there are any) */
1386 len = ml_len - len - sizeof(struct ieee80211_eht_ml);
1387 for_each_element_id(sub, 0, pos, len) {
1388 const struct ieee80211_eht_per_sta_profile *sta;
1389 u16 sta_control;
1390
1391 if (*links == 0xffff)
1392 *links = 0;
1393
1394 if (sub->datalen <
1395 sizeof(struct ieee80211_eht_per_sta_profile)) {
1396 wpa_printf(MSG_DEBUG,
1397 "MLD: ML probe req %d too short for sta profile",
1398 sub->datalen);
1399 return false;
1400 }
1401
1402 sta = (struct ieee80211_eht_per_sta_profile *) sub->data;
1403
1404 /*
1405 * Extract the link ID, do not return whether a complete or
1406 * partial profile was requested.
1407 */
1408 sta_control = le_to_host16(sta->sta_control);
1409 *links |= BIT(sta_control & EHT_PER_STA_CTRL_LINK_ID_MSK);
1410 }
1411
1412 if (!for_each_element_completed(sub, pos, len)) {
1413 wpa_printf(MSG_DEBUG,
1414 "MLD: ML probe req sub-elements parsing error");
1415 return false;
1416 }
1417
1418 return true;
1419}
1420#endif /* CONFIG_IEEE80211BE */
1421
1422
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001423void handle_probe_req(struct hostapd_data *hapd,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001424 const struct ieee80211_mgmt *mgmt, size_t len,
1425 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001426{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001427 struct ieee802_11_elems elems;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001428 const u8 *ie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001429 size_t ie_len;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001430 size_t i;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001431 int noack;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001432 enum ssid_match_result res;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001433 int ret;
1434 u16 csa_offs[2];
1435 size_t csa_offs_len;
Hai Shalomfdcde762020-04-02 11:19:20 -07001436 struct radius_sta rad_info;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001437 struct probe_resp_params params;
1438#ifdef CONFIG_IEEE80211BE
1439 int mld_id;
1440 u16 links;
1441#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001442
Hai Shalom60840252021-02-19 19:02:11 -08001443 if (hapd->iconf->rssi_ignore_probe_request && ssi_signal &&
1444 ssi_signal < hapd->iconf->rssi_ignore_probe_request)
1445 return;
1446
Dmitry Shmidte4663042016-04-04 10:07:49 -07001447 if (len < IEEE80211_HDRLEN)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001448 return;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001449 ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001450 if (hapd->iconf->track_sta_max_num)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001451 sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
Dmitry Shmidte4663042016-04-04 10:07:49 -07001452 ie_len = len - IEEE80211_HDRLEN;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001453
Hai Shalomfdcde762020-04-02 11:19:20 -07001454 ret = hostapd_allowed_address(hapd, mgmt->sa, (const u8 *) mgmt, len,
1455 &rad_info, 1);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001456 if (ret == HOSTAPD_ACL_REJECT) {
1457 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
1458 "Ignore Probe Request frame from " MACSTR
1459 " due to ACL reject ", MAC2STR(mgmt->sa));
1460 return;
1461 }
1462
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001463 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
1464 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001465 mgmt->sa, mgmt->da, mgmt->bssid,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001466 ie, ie_len, ssi_signal) > 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001467 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001468
Hai Shalom74f70d42019-02-11 14:42:39 -08001469 if (!hapd->conf->send_probe_response)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001470 return;
1471
1472 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
1473 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
1474 MAC2STR(mgmt->sa));
1475 return;
1476 }
1477
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001478 if ((!elems.ssid || !elems.supp_rates)) {
1479 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
1480 "without SSID or supported rates element",
1481 MAC2STR(mgmt->sa));
1482 return;
1483 }
1484
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001485 /*
1486 * No need to reply if the Probe Request frame was sent on an adjacent
1487 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
1488 * AP with dot11RadioMeasurementActivated set to true, but strictly
1489 * speaking does not allow such ignoring of Probe Request frames if
1490 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
1491 * number of unnecessary Probe Response frames for cases where the STA
1492 * is less likely to see them (Probe Request frame sent on a
1493 * neighboring, but partially overlapping, channel).
1494 */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001495 if (elems.ds_params &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001496 hapd->iface->current_mode &&
1497 (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
1498 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
1499 hapd->iconf->channel != elems.ds_params[0]) {
1500 wpa_printf(MSG_DEBUG,
1501 "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
1502 hapd->iconf->channel, elems.ds_params[0]);
1503 return;
1504 }
1505
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001506#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001507 if (hapd->p2p && hapd->p2p_group && elems.wps_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001508 struct wpabuf *wps;
1509 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
1510 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
1511 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
1512 "due to mismatch with Requested Device "
1513 "Type");
1514 wpabuf_free(wps);
1515 return;
1516 }
1517 wpabuf_free(wps);
1518 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001519
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001520 if (hapd->p2p && hapd->p2p_group && elems.p2p) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001521 struct wpabuf *p2p;
1522 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
1523 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
1524 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
1525 "due to mismatch with Device ID");
1526 wpabuf_free(p2p);
1527 return;
1528 }
1529 wpabuf_free(p2p);
1530 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001531#endif /* CONFIG_P2P */
1532
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001533 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
Hai Shalomfdcde762020-04-02 11:19:20 -07001534 elems.ssid_list_len == 0 && elems.short_ssid_list_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001535 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
1536 "broadcast SSID ignored", MAC2STR(mgmt->sa));
1537 return;
1538 }
1539
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001540#ifdef CONFIG_P2P
1541 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1542 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
1543 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
1544 P2P_WILDCARD_SSID_LEN) == 0) {
1545 /* Process P2P Wildcard SSID like Wildcard SSID */
1546 elems.ssid_len = 0;
1547 }
1548#endif /* CONFIG_P2P */
1549
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001550#ifdef CONFIG_TAXONOMY
1551 {
1552 struct sta_info *sta;
1553 struct hostapd_sta_info *info;
1554
1555 if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) {
1556 taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len);
1557 } else if ((info = sta_track_get(hapd->iface,
1558 mgmt->sa)) != NULL) {
1559 taxonomy_hostapd_sta_info_probe_req(hapd, info,
1560 ie, ie_len);
1561 }
1562 }
1563#endif /* CONFIG_TAXONOMY */
1564
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001565 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
Hai Shalomfdcde762020-04-02 11:19:20 -07001566 elems.ssid_list, elems.ssid_list_len,
1567 elems.short_ssid_list, elems.short_ssid_list_len);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001568 if (res == NO_SSID_MATCH) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001569 if (!(mgmt->da[0] & 0x01)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001570 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001571 " for foreign SSID '%s' (DA " MACSTR ")%s",
Dmitry Shmidt3c479372014-02-04 10:50:36 -08001572 MAC2STR(mgmt->sa),
1573 wpa_ssid_txt(elems.ssid, elems.ssid_len),
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001574 MAC2STR(mgmt->da),
1575 elems.ssid_list ? " (SSID list)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001576 }
1577 return;
1578 }
1579
Hai Shalomfdcde762020-04-02 11:19:20 -07001580 if (hapd->conf->ignore_broadcast_ssid && res == WILDCARD_SSID_MATCH) {
1581 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
1582 "broadcast SSID ignored", MAC2STR(mgmt->sa));
1583 return;
1584 }
1585
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001586#ifdef CONFIG_INTERWORKING
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -07001587 if (hapd->conf->interworking &&
1588 elems.interworking && elems.interworking_len >= 1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001589 u8 ant = elems.interworking[0] & 0x0f;
1590 if (ant != INTERWORKING_ANT_WILDCARD &&
1591 ant != hapd->conf->access_network_type) {
1592 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
1593 " for mismatching ANT %u ignored",
1594 MAC2STR(mgmt->sa), ant);
1595 return;
1596 }
1597 }
1598
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -07001599 if (hapd->conf->interworking && elems.interworking &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001600 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
1601 const u8 *hessid;
1602 if (elems.interworking_len == 7)
1603 hessid = elems.interworking + 1;
1604 else
1605 hessid = elems.interworking + 1 + 2;
1606 if (!is_broadcast_ether_addr(hessid) &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001607 !ether_addr_equal(hessid, hapd->conf->hessid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001608 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
1609 " for mismatching HESSID " MACSTR
1610 " ignored",
1611 MAC2STR(mgmt->sa), MAC2STR(hessid));
1612 return;
1613 }
1614 }
1615#endif /* CONFIG_INTERWORKING */
1616
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001617#ifdef CONFIG_P2P
1618 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1619 supp_rates_11b_only(&elems)) {
1620 /* Indicates support for 11b rates only */
1621 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
1622 MACSTR " with only 802.11b rates",
1623 MAC2STR(mgmt->sa));
1624 return;
1625 }
1626#endif /* CONFIG_P2P */
1627
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001628 /* TODO: verify that supp_rates contains at least one matching rate
1629 * with AP configuration */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001630
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001631 if (hapd->conf->no_probe_resp_if_seen_on &&
1632 is_multicast_ether_addr(mgmt->da) &&
1633 is_multicast_ether_addr(mgmt->bssid) &&
1634 sta_track_seen_on(hapd->iface, mgmt->sa,
1635 hapd->conf->no_probe_resp_if_seen_on)) {
1636 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1637 " since STA has been seen on %s",
1638 hapd->conf->iface, MAC2STR(mgmt->sa),
1639 hapd->conf->no_probe_resp_if_seen_on);
1640 return;
1641 }
1642
1643 if (hapd->conf->no_probe_resp_if_max_sta &&
1644 is_multicast_ether_addr(mgmt->da) &&
1645 is_multicast_ether_addr(mgmt->bssid) &&
1646 hapd->num_sta >= hapd->conf->max_num_sta &&
1647 !ap_get_sta(hapd, mgmt->sa)) {
1648 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1649 " since no room for additional STA",
1650 hapd->conf->iface, MAC2STR(mgmt->sa));
1651 return;
1652 }
1653
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001654#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001655 if (hapd->iconf->ignore_probe_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001656 drand48() < hapd->iconf->ignore_probe_probability) {
1657 wpa_printf(MSG_INFO,
1658 "TESTING: ignoring probe request from " MACSTR,
1659 MAC2STR(mgmt->sa));
1660 return;
1661 }
1662#endif /* CONFIG_TESTING_OPTIONS */
1663
Sunil Ravi77d572f2023-01-17 23:58:31 +00001664 /* Do not send Probe Response frame from a non-transmitting multiple
1665 * BSSID profile unless the Probe Request frame is directed at that
1666 * particular BSS. */
1667 if (hapd != hostapd_mbssid_get_tx_bss(hapd) && res != EXACT_SSID_MATCH)
1668 return;
1669
Roshan Pius3a1667e2018-07-03 15:17:14 -07001670 wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, RX_PROBE_REQUEST "sa=" MACSTR
1671 " signal=%d", MAC2STR(mgmt->sa), ssi_signal);
1672
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001673 os_memset(&params, 0, sizeof(params));
1674
1675#ifdef CONFIG_IEEE80211BE
1676 if (hapd->conf->mld_ap && elems.probe_req_mle &&
1677 parse_ml_probe_req((struct ieee80211_eht_ml *) elems.probe_req_mle,
1678 elems.probe_req_mle_len, &mld_id, &links)) {
1679 hostapd_fill_probe_resp_ml_params(hapd, &params, mgmt,
1680 mld_id, links);
1681 }
1682#endif /* CONFIG_IEEE80211BE */
1683
1684 params.req = mgmt;
1685 params.is_p2p = !!elems.p2p;
1686 params.known_bss = elems.mbssid_known_bss;
1687 params.known_bss_len = elems.mbssid_known_bss_len;
1688 params.is_ml_sta_info = false;
1689
1690 hostapd_gen_probe_resp(hapd, &params);
1691
1692 hostapd_free_probe_resp_params(&params);
1693
1694 if (!params.resp)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001695 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001696
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001697 /*
1698 * If this is a broadcast probe request, apply no ack policy to avoid
1699 * excessive retries.
1700 */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001701 noack = !!(res == WILDCARD_SSID_MATCH &&
1702 is_broadcast_ether_addr(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001703
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001704 csa_offs_len = 0;
1705 if (hapd->csa_in_progress) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001706 if (params.csa_pos)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001707 csa_offs[csa_offs_len++] =
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001708 params.csa_pos - (u8 *) params.resp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001709
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001710 if (params.ecsa_pos)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001711 csa_offs[csa_offs_len++] =
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001712 params.ecsa_pos - (u8 *) params.resp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001713 }
1714
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001715 ret = hostapd_drv_send_mlme(hapd, params.resp, params.resp_len, noack,
Hai Shalomfdcde762020-04-02 11:19:20 -07001716 csa_offs_len ? csa_offs : NULL,
1717 csa_offs_len, 0);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001718
1719 if (ret < 0)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001720 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001721
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001722 os_free(params.resp);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001723
1724 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
1725 "SSID", MAC2STR(mgmt->sa),
1726 elems.ssid_len == 0 ? "broadcast" : "our");
1727}
1728
1729
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001730static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
1731 size_t *resp_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001732{
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001733 struct probe_resp_params params;
1734
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001735 /* check probe response offloading caps and print warnings */
1736 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
1737 return NULL;
1738
1739#ifdef CONFIG_WPS
1740 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
1741 (!(hapd->iface->probe_resp_offloads &
1742 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
1743 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
1744 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
1745 "Probe Response while not supporting this");
1746#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001747
1748#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001749 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
1750 !(hapd->iface->probe_resp_offloads &
1751 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
1752 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
1753 "Probe Response while not supporting this");
1754#endif /* CONFIG_P2P */
1755
1756 if (hapd->conf->interworking &&
1757 !(hapd->iface->probe_resp_offloads &
1758 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
1759 wpa_printf(MSG_WARNING, "Device is trying to offload "
1760 "Interworking Probe Response while not supporting "
1761 "this");
1762
1763 /* Generate a Probe Response template for the non-P2P case */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001764 os_memset(&params, 0, sizeof(params));
1765 params.req = NULL;
1766 params.is_p2p = false;
1767 params.known_bss = NULL;
1768 params.known_bss_len = 0;
1769 params.is_ml_sta_info = false;
1770 params.mld_ap = NULL;
1771 params.mld_info = NULL;
1772
1773 hostapd_gen_probe_resp(hapd, &params);
1774 *resp_len = params.resp_len;
1775 if (!params.resp)
1776 return NULL;
1777
1778 /* TODO: Avoid passing these through struct hostapd_data */
1779 if (params.csa_pos)
1780 hapd->cs_c_off_proberesp = params.csa_pos - (u8 *) params.resp;
1781 if (params.ecsa_pos)
1782 hapd->cs_c_off_ecsa_proberesp = params.ecsa_pos -
1783 (u8 *) params.resp;
1784#ifdef CONFIG_IEEE80211AX
1785 if (params.cca_pos)
1786 hapd->cca_c_off_proberesp = params.cca_pos - (u8 *) params.resp;
1787#endif /* CONFIG_IEEE80211AX */
1788
1789 return (u8 *) params.resp;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001790}
1791
1792#endif /* NEED_AP_MLME */
1793
1794
Hai Shalom60840252021-02-19 19:02:11 -08001795#ifdef CONFIG_IEEE80211AX
1796/* Unsolicited broadcast Probe Response transmission, 6 GHz only */
Sunil Ravi7f769292024-07-23 22:21:32 +00001797u8 * hostapd_unsol_bcast_probe_resp(struct hostapd_data *hapd,
1798 struct unsol_bcast_probe_resp *ubpr)
Hai Shalom60840252021-02-19 19:02:11 -08001799{
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001800 struct probe_resp_params probe_params;
1801
Hai Shalom60840252021-02-19 19:02:11 -08001802 if (!is_6ghz_op_class(hapd->iconf->op_class))
1803 return NULL;
1804
Sunil Ravi7f769292024-07-23 22:21:32 +00001805 ubpr->unsol_bcast_probe_resp_interval =
Hai Shalom60840252021-02-19 19:02:11 -08001806 hapd->conf->unsol_bcast_probe_resp_interval;
1807
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001808 os_memset(&probe_params, 0, sizeof(probe_params));
1809 probe_params.req = NULL;
1810 probe_params.is_p2p = false;
1811 probe_params.known_bss = NULL;
1812 probe_params.known_bss_len = 0;
1813 probe_params.is_ml_sta_info = false;
1814 probe_params.mld_ap = NULL;
1815 probe_params.mld_info = NULL;
1816
1817 hostapd_gen_probe_resp(hapd, &probe_params);
Sunil Ravi7f769292024-07-23 22:21:32 +00001818 ubpr->unsol_bcast_probe_resp_tmpl_len = probe_params.resp_len;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001819 return (u8 *) probe_params.resp;
Hai Shalom60840252021-02-19 19:02:11 -08001820}
1821#endif /* CONFIG_IEEE80211AX */
1822
1823
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001824void sta_track_del(struct hostapd_sta_info *info)
1825{
1826#ifdef CONFIG_TAXONOMY
1827 wpabuf_free(info->probe_ie_taxonomy);
1828 info->probe_ie_taxonomy = NULL;
1829#endif /* CONFIG_TAXONOMY */
1830 os_free(info);
1831}
1832
1833
Hai Shalom60840252021-02-19 19:02:11 -08001834#ifdef CONFIG_FILS
1835
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001836static u16 hostapd_gen_fils_discovery_phy_index(struct hostapd_data *hapd)
1837{
1838#ifdef CONFIG_IEEE80211BE
1839 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be)
1840 return FD_CAP_PHY_INDEX_EHT;
1841#endif /* CONFIG_IEEE80211BE */
1842
1843#ifdef CONFIG_IEEE80211AX
1844 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax)
1845 return FD_CAP_PHY_INDEX_HE;
1846#endif /* CONFIG_IEEE80211AX */
1847
1848#ifdef CONFIG_IEEE80211AC
1849 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac)
1850 return FD_CAP_PHY_INDEX_VHT;
1851#endif /* CONFIG_IEEE80211AC */
1852
1853 if (hapd->iconf->ieee80211n && !hapd->conf->disable_11n)
1854 return FD_CAP_PHY_INDEX_HT;
1855
1856 return 0;
1857}
1858
1859
1860static u16 hostapd_gen_fils_discovery_nss(struct hostapd_hw_modes *mode,
1861 u16 phy_index, u8 he_mcs_nss_size)
1862{
1863 u16 nss = 0;
1864
1865 if (!mode)
1866 return 0;
1867
1868 if (phy_index == FD_CAP_PHY_INDEX_HE) {
1869 const u8 *he_mcs = mode->he_capab[IEEE80211_MODE_AP].mcs;
1870 int i;
1871 u16 mcs[6];
1872
1873 os_memset(mcs, 0xff, 6 * sizeof(u16));
1874
1875 if (he_mcs_nss_size == 4) {
1876 mcs[0] = WPA_GET_LE16(&he_mcs[0]);
1877 mcs[1] = WPA_GET_LE16(&he_mcs[2]);
1878 }
1879
1880 if (he_mcs_nss_size == 8) {
1881 mcs[2] = WPA_GET_LE16(&he_mcs[4]);
1882 mcs[3] = WPA_GET_LE16(&he_mcs[6]);
1883 }
1884
1885 if (he_mcs_nss_size == 12) {
1886 mcs[4] = WPA_GET_LE16(&he_mcs[8]);
1887 mcs[5] = WPA_GET_LE16(&he_mcs[10]);
1888 }
1889
1890 for (i = 0; i < HE_NSS_MAX_STREAMS; i++) {
1891 u16 nss_mask = 0x3 << (i * 2);
1892
1893 /*
1894 * If Tx and/or Rx indicate support for a given NSS,
1895 * count it towards the maximum NSS.
1896 */
1897 if (he_mcs_nss_size == 4 &&
1898 (((mcs[0] & nss_mask) != nss_mask) ||
1899 ((mcs[1] & nss_mask) != nss_mask))) {
1900 nss++;
1901 continue;
1902 }
1903
1904 if (he_mcs_nss_size == 8 &&
1905 (((mcs[2] & nss_mask) != nss_mask) ||
1906 ((mcs[3] & nss_mask) != nss_mask))) {
1907 nss++;
1908 continue;
1909 }
1910
1911 if (he_mcs_nss_size == 12 &&
1912 (((mcs[4] & nss_mask) != nss_mask) ||
1913 ((mcs[5] & nss_mask) != nss_mask))) {
1914 nss++;
1915 continue;
1916 }
1917 }
1918 } else if (phy_index == FD_CAP_PHY_INDEX_EHT) {
1919 u8 rx_nss, tx_nss, max_nss = 0, i;
1920 u8 *mcs = mode->eht_capab[IEEE80211_MODE_AP].mcs;
1921
1922 /*
1923 * The Supported EHT-MCS And NSS Set field for the AP contains
1924 * one to three EHT-MCS Map fields based on the supported
1925 * bandwidth. Check the first byte (max NSS for Rx/Tx that
1926 * supports EHT-MCS 0-9) for each bandwidth (<= 80,
1927 * 160, 320) to find the maximum NSS. This assumes that
1928 * the lowest MCS rates support the largest number of spatial
1929 * streams. If values are different between Tx, Rx or the
1930 * bandwidths, choose the highest value.
1931 */
1932 for (i = 0; i < 3; i++) {
1933 rx_nss = mcs[3 * i] & 0x0F;
1934 if (rx_nss > max_nss)
1935 max_nss = rx_nss;
1936
1937 tx_nss = (mcs[3 * i] & 0xF0) >> 4;
1938 if (tx_nss > max_nss)
1939 max_nss = tx_nss;
1940 }
1941
1942 nss = max_nss;
1943 }
1944
1945 if (nss > 4)
1946 return FD_CAP_NSS_5_8 << FD_CAP_NSS_SHIFT;
1947 if (nss)
1948 return (nss - 1) << FD_CAP_NSS_SHIFT;
1949
1950 return 0;
1951}
1952
1953
Hai Shalom60840252021-02-19 19:02:11 -08001954static u16 hostapd_fils_discovery_cap(struct hostapd_data *hapd)
1955{
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001956 u16 cap_info, phy_index;
1957 u8 chwidth = FD_CAP_BSS_CHWIDTH_20, he_mcs_nss_size = 4;
Hai Shalom60840252021-02-19 19:02:11 -08001958 struct hostapd_hw_modes *mode = hapd->iface->current_mode;
1959
1960 cap_info = FD_CAP_ESS;
1961 if (hapd->conf->wpa)
1962 cap_info |= FD_CAP_PRIVACY;
1963
1964 if (is_6ghz_op_class(hapd->iconf->op_class)) {
Hai Shalom60840252021-02-19 19:02:11 -08001965 switch (hapd->iconf->op_class) {
Sunil Ravi036cec52023-03-29 11:35:17 -07001966 case 137:
1967 chwidth = FD_CAP_BSS_CHWIDTH_320;
1968 break;
Hai Shalom60840252021-02-19 19:02:11 -08001969 case 135:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001970 he_mcs_nss_size += 4;
Hai Shalom60840252021-02-19 19:02:11 -08001971 /* fallthrough */
1972 case 134:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001973 he_mcs_nss_size += 4;
Hai Shalom60840252021-02-19 19:02:11 -08001974 chwidth = FD_CAP_BSS_CHWIDTH_160_80_80;
1975 break;
1976 case 133:
1977 chwidth = FD_CAP_BSS_CHWIDTH_80;
1978 break;
1979 case 132:
1980 chwidth = FD_CAP_BSS_CHWIDTH_40;
1981 break;
1982 }
1983 } else {
1984 switch (hostapd_get_oper_chwidth(hapd->iconf)) {
Sunil8cd6f4d2022-06-28 18:40:46 +00001985 case CONF_OPER_CHWIDTH_80P80MHZ:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001986 he_mcs_nss_size += 4;
Hai Shalom60840252021-02-19 19:02:11 -08001987 /* fallthrough */
Sunil8cd6f4d2022-06-28 18:40:46 +00001988 case CONF_OPER_CHWIDTH_160MHZ:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001989 he_mcs_nss_size += 4;
Hai Shalom60840252021-02-19 19:02:11 -08001990 chwidth = FD_CAP_BSS_CHWIDTH_160_80_80;
1991 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00001992 case CONF_OPER_CHWIDTH_80MHZ:
Hai Shalom60840252021-02-19 19:02:11 -08001993 chwidth = FD_CAP_BSS_CHWIDTH_80;
1994 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00001995 case CONF_OPER_CHWIDTH_USE_HT:
Hai Shalom60840252021-02-19 19:02:11 -08001996 if (hapd->iconf->secondary_channel)
1997 chwidth = FD_CAP_BSS_CHWIDTH_40;
1998 else
1999 chwidth = FD_CAP_BSS_CHWIDTH_20;
2000 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00002001 default:
2002 break;
Hai Shalom60840252021-02-19 19:02:11 -08002003 }
Hai Shalom60840252021-02-19 19:02:11 -08002004 }
2005
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002006 phy_index = hostapd_gen_fils_discovery_phy_index(hapd);
Hai Shalom60840252021-02-19 19:02:11 -08002007 cap_info |= phy_index << FD_CAP_PHY_INDEX_SHIFT;
2008 cap_info |= chwidth << FD_CAP_BSS_CHWIDTH_SHIFT;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002009 cap_info |= hostapd_gen_fils_discovery_nss(mode, phy_index,
2010 he_mcs_nss_size);
Hai Shalom60840252021-02-19 19:02:11 -08002011 return cap_info;
2012}
2013
2014
2015static u8 * hostapd_gen_fils_discovery(struct hostapd_data *hapd, size_t *len)
2016{
2017 struct ieee80211_mgmt *head;
2018 const u8 *mobility_domain;
2019 u8 *pos, *length_pos, buf[200];
2020 u16 ctl = 0;
2021 u8 fd_rsn_info[5];
2022 size_t total_len, buf_len;
2023
2024 total_len = 24 + 2 + 12;
2025
2026 /* FILS Discovery Frame Control */
2027 ctl = (sizeof(hapd->conf->ssid.short_ssid) - 1) |
2028 FD_FRAME_CTL_SHORT_SSID_PRESENT |
2029 FD_FRAME_CTL_LENGTH_PRESENT |
2030 FD_FRAME_CTL_CAP_PRESENT;
2031 total_len += 4 + 1 + 2;
2032
Sunil Ravi7f769292024-07-23 22:21:32 +00002033 /* Fill primary channel information for 6 GHz channels with over 20 MHz
2034 * bandwidth, if the primary channel is not a PSC */
2035 if (is_6ghz_op_class(hapd->iconf->op_class) &&
2036 !is_6ghz_psc_frequency(ieee80211_chan_to_freq(
2037 NULL, hapd->iconf->op_class,
2038 hapd->iconf->channel)) &&
2039 op_class_to_bandwidth(hapd->iconf->op_class) > 20) {
2040 ctl |= FD_FRAME_CTL_PRI_CHAN_PRESENT;
2041 total_len += 2;
2042 }
2043
Hai Shalom60840252021-02-19 19:02:11 -08002044 /* Check for optional subfields and calculate length */
2045 if (wpa_auth_write_fd_rsn_info(hapd->wpa_auth, fd_rsn_info)) {
2046 ctl |= FD_FRAME_CTL_RSN_INFO_PRESENT;
2047 total_len += sizeof(fd_rsn_info);
2048 }
2049
2050 mobility_domain = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN);
2051 if (mobility_domain) {
2052 ctl |= FD_FRAME_CTL_MD_PRESENT;
2053 total_len += 3;
2054 }
2055
Sunil Ravi7f769292024-07-23 22:21:32 +00002056 total_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_ACTION, true);
Hai Shaloma20dcd72022-02-04 13:43:00 -08002057
Hai Shalom60840252021-02-19 19:02:11 -08002058 pos = hostapd_eid_fils_indic(hapd, buf, 0);
2059 buf_len = pos - buf;
2060 total_len += buf_len;
2061
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002062 /* he_elem_len() may return too large a value for FD frame, but that is
2063 * fine here since this is used as the maximum length of the buffer. */
2064 total_len += he_elem_len(hapd);
Sunil Ravia04bd252022-05-02 22:54:18 -07002065
Hai Shalom60840252021-02-19 19:02:11 -08002066 head = os_zalloc(total_len);
2067 if (!head)
2068 return NULL;
2069
2070 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
2071 WLAN_FC_STYPE_ACTION);
2072 os_memset(head->da, 0xff, ETH_ALEN);
2073 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
2074 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
2075
2076 head->u.action.category = WLAN_ACTION_PUBLIC;
2077 head->u.action.u.public_action.action = WLAN_PA_FILS_DISCOVERY;
2078
2079 pos = &head->u.action.u.public_action.variable[0];
2080
2081 /* FILS Discovery Information field */
2082
2083 /* FILS Discovery Frame Control */
2084 WPA_PUT_LE16(pos, ctl);
2085 pos += 2;
2086
2087 /* Hardware or low-level driver will fill in the Timestamp value */
2088 pos += 8;
2089
2090 /* Beacon Interval */
2091 WPA_PUT_LE16(pos, hapd->iconf->beacon_int);
2092 pos += 2;
2093
2094 /* Short SSID */
2095 WPA_PUT_LE32(pos, hapd->conf->ssid.short_ssid);
2096 pos += sizeof(hapd->conf->ssid.short_ssid);
2097
2098 /* Store position of FILS discovery information element Length field */
2099 length_pos = pos++;
2100
2101 /* FD Capability */
2102 WPA_PUT_LE16(pos, hostapd_fils_discovery_cap(hapd));
2103 pos += 2;
2104
Sunil Ravi7f769292024-07-23 22:21:32 +00002105 /* Operating Class and Primary Channel - if a 6 GHz chan is non PSC */
2106 if (ctl & FD_FRAME_CTL_PRI_CHAN_PRESENT) {
2107 *pos++ = hapd->iconf->op_class;
2108 *pos++ = hapd->iconf->channel;
2109 }
Hai Shalom60840252021-02-19 19:02:11 -08002110
2111 /* AP Configuration Sequence Number - not present */
2112
2113 /* Access Network Options - not present */
2114
2115 /* FD RSN Information */
2116 if (ctl & FD_FRAME_CTL_RSN_INFO_PRESENT) {
2117 os_memcpy(pos, fd_rsn_info, sizeof(fd_rsn_info));
2118 pos += sizeof(fd_rsn_info);
2119 }
2120
2121 /* Channel Center Frequency Segment 1 - not present */
2122
2123 /* Mobility Domain */
2124 if (ctl & FD_FRAME_CTL_MD_PRESENT) {
2125 os_memcpy(pos, &mobility_domain[2], 3);
2126 pos += 3;
2127 }
2128
2129 /* Fill in the Length field value */
2130 *length_pos = pos - (length_pos + 1);
2131
Sunil Ravi7f769292024-07-23 22:21:32 +00002132 pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_ACTION, true);
Hai Shaloma20dcd72022-02-04 13:43:00 -08002133
Hai Shalom60840252021-02-19 19:02:11 -08002134 /* FILS Indication element */
2135 if (buf_len) {
2136 os_memcpy(pos, buf, buf_len);
2137 pos += buf_len;
2138 }
2139
Sunil Ravia04bd252022-05-02 22:54:18 -07002140 if (is_6ghz_op_class(hapd->iconf->op_class))
2141 pos = hostapd_eid_txpower_envelope(hapd, pos);
2142
Hai Shalom60840252021-02-19 19:02:11 -08002143 *len = pos - (u8 *) head;
2144 wpa_hexdump(MSG_DEBUG, "FILS Discovery frame template",
2145 head, pos - (u8 *) head);
2146 return (u8 *) head;
2147}
2148
2149
2150/* Configure FILS Discovery frame transmission parameters */
2151static u8 * hostapd_fils_discovery(struct hostapd_data *hapd,
2152 struct wpa_driver_ap_params *params)
2153{
2154 params->fd_max_int = hapd->conf->fils_discovery_max_int;
2155 if (is_6ghz_op_class(hapd->iconf->op_class) &&
2156 params->fd_max_int > FD_MAX_INTERVAL_6GHZ)
2157 params->fd_max_int = FD_MAX_INTERVAL_6GHZ;
2158
2159 params->fd_min_int = hapd->conf->fils_discovery_min_int;
2160 if (params->fd_min_int > params->fd_max_int)
2161 params->fd_min_int = params->fd_max_int;
2162
2163 if (params->fd_max_int)
2164 return hostapd_gen_fils_discovery(hapd,
2165 &params->fd_frame_tmpl_len);
2166
2167 return NULL;
2168}
2169
2170#endif /* CONFIG_FILS */
2171
2172
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002173int ieee802_11_build_ap_params(struct hostapd_data *hapd,
2174 struct wpa_driver_ap_params *params)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002175{
2176 struct ieee80211_mgmt *head = NULL;
2177 u8 *tail = NULL;
2178 size_t head_len = 0, tail_len = 0;
2179 u8 *resp = NULL;
2180 size_t resp_len = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002181#ifdef NEED_AP_MLME
2182 u16 capab_info;
Hai Shalomfdcde762020-04-02 11:19:20 -07002183 u8 *pos, *tailpos, *tailend, *csa_pos;
Sunil Ravi77d572f2023-01-17 23:58:31 +00002184 bool complete = false;
2185#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002186
Sunil Ravi77d572f2023-01-17 23:58:31 +00002187 os_memset(params, 0, sizeof(*params));
2188
2189#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002190#define BEACON_HEAD_BUF_SIZE 256
2191#define BEACON_TAIL_BUF_SIZE 512
2192 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
2193 tail_len = BEACON_TAIL_BUF_SIZE;
2194#ifdef CONFIG_WPS
2195 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
2196 tail_len += wpabuf_len(hapd->wps_beacon_ie);
2197#endif /* CONFIG_WPS */
2198#ifdef CONFIG_P2P
2199 if (hapd->p2p_beacon_ie)
2200 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
2201#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002202#ifdef CONFIG_FST
2203 if (hapd->iface->fst_ies)
2204 tail_len += wpabuf_len(hapd->iface->fst_ies);
2205#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002206 if (hapd->conf->vendor_elements)
2207 tail_len += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08002208
2209#ifdef CONFIG_IEEE80211AC
2210 if (hapd->conf->vendor_vht) {
2211 tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
2212 2 + sizeof(struct ieee80211_vht_operation);
2213 }
2214#endif /* CONFIG_IEEE80211AC */
2215
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002216 tail_len += he_elem_len(hapd);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002217
Sunil Ravia04bd252022-05-02 22:54:18 -07002218#ifdef CONFIG_IEEE80211BE
2219 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
2220 tail_len += hostapd_eid_eht_capab_len(hapd, IEEE80211_MODE_AP);
2221 tail_len += 3 + sizeof(struct ieee80211_eht_operation);
Sunil Ravi036cec52023-03-29 11:35:17 -07002222 if (hapd->iconf->punct_bitmap)
2223 tail_len += EHT_OPER_DISABLED_SUBCHAN_BITMAP_SIZE;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002224
2225 /*
2226 * TODO: Multi-Link element has variable length and can be
2227 * long based on the common info and number of per
2228 * station profiles. For now use 256.
2229 */
2230 if (hapd->conf->mld_ap)
2231 tail_len += 256;
Sunil Ravia04bd252022-05-02 22:54:18 -07002232 }
2233#endif /* CONFIG_IEEE80211BE */
2234
Sunil Ravi77d572f2023-01-17 23:58:31 +00002235 if (hapd->iconf->mbssid == ENHANCED_MBSSID_ENABLED &&
2236 hapd == hostapd_mbssid_get_tx_bss(hapd))
2237 tail_len += 5; /* Multiple BSSID Configuration element */
Sunil Ravi7f769292024-07-23 22:21:32 +00002238 tail_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_BEACON, true);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002239 tail_len += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002240 tail_len += hostapd_eid_owe_trans_len(hapd);
Hai Shalomfdcde762020-04-02 11:19:20 -07002241 tail_len += hostapd_eid_dpp_cc_len(hapd);
Sunil Ravi7f769292024-07-23 22:21:32 +00002242 tail_len += hostapd_get_rsne_override_len(hapd);
2243 tail_len += hostapd_get_rsne_override_2_len(hapd);
2244 tail_len += hostapd_get_rsnxe_override_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002245
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002246 tailpos = tail = os_malloc(tail_len);
2247 if (head == NULL || tail == NULL) {
2248 wpa_printf(MSG_ERROR, "Failed to set beacon data");
2249 os_free(head);
2250 os_free(tail);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002251 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002252 }
Hai Shalomfdcde762020-04-02 11:19:20 -07002253 tailend = tail + tail_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002254
2255 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
2256 WLAN_FC_STYPE_BEACON);
2257 head->duration = host_to_le16(0);
2258 os_memset(head->da, 0xff, ETH_ALEN);
2259
2260 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
2261 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
2262 head->u.beacon.beacon_int =
2263 host_to_le16(hapd->iconf->beacon_int);
2264
2265 /* hardware or low-level driver will setup seq_ctrl and timestamp */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002266 capab_info = hostapd_own_capab_info(hapd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002267 head->u.beacon.capab_info = host_to_le16(capab_info);
2268 pos = &head->u.beacon.variable[0];
2269
2270 /* SSID */
2271 *pos++ = WLAN_EID_SSID;
2272 if (hapd->conf->ignore_broadcast_ssid == 2) {
2273 /* clear the data, but keep the correct length of the SSID */
2274 *pos++ = hapd->conf->ssid.ssid_len;
2275 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
2276 pos += hapd->conf->ssid.ssid_len;
2277 } else if (hapd->conf->ignore_broadcast_ssid) {
2278 *pos++ = 0; /* empty SSID */
2279 } else {
2280 *pos++ = hapd->conf->ssid.ssid_len;
2281 os_memcpy(pos, hapd->conf->ssid.ssid,
2282 hapd->conf->ssid.ssid_len);
2283 pos += hapd->conf->ssid.ssid_len;
2284 }
2285
2286 /* Supported rates */
2287 pos = hostapd_eid_supp_rates(hapd, pos);
2288
2289 /* DS Params */
2290 pos = hostapd_eid_ds_params(hapd, pos);
2291
2292 head_len = pos - (u8 *) head;
2293
Hai Shalomfdcde762020-04-02 11:19:20 -07002294 tailpos = hostapd_eid_country(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002295
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002296 /* Power Constraint element */
2297 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
2298
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002299 /* CSA IE */
2300 csa_pos = hostapd_eid_csa(hapd, tailpos);
2301 if (csa_pos != tailpos)
2302 hapd->cs_c_off_beacon = csa_pos - tail - 1;
2303 tailpos = csa_pos;
2304
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002305 /* ERP Information element */
2306 tailpos = hostapd_eid_erp_info(hapd, tailpos);
2307
2308 /* Extended supported rates */
2309 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
2310
Hai Shalomfdcde762020-04-02 11:19:20 -07002311 tailpos = hostapd_get_rsne(hapd, tailpos, tailend - tailpos);
2312 tailpos = hostapd_eid_bss_load(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002313 tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
Hai Shalomfdcde762020-04-02 11:19:20 -07002314 tailend - tailpos);
2315 tailpos = hostapd_get_mde(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt051af732013-10-22 13:52:46 -07002316
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002317 /* eCSA IE */
2318 csa_pos = hostapd_eid_ecsa(hapd, tailpos);
2319 if (csa_pos != tailpos)
2320 hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1;
2321 tailpos = csa_pos;
2322
2323 tailpos = hostapd_eid_supported_op_classes(hapd, tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002324 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
2325 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002326
Sunil Ravi77d572f2023-01-17 23:58:31 +00002327 if (hapd->iconf->mbssid && hapd->iconf->num_bss > 1) {
2328 if (ieee802_11_build_ap_params_mbssid(hapd, params)) {
2329 os_free(head);
2330 os_free(tail);
2331 wpa_printf(MSG_ERROR,
2332 "MBSSID: Failed to set beacon data");
2333 return -1;
2334 }
2335 complete = hapd->iconf->mbssid == MBSSID_ENABLED ||
2336 (hapd->iconf->mbssid == ENHANCED_MBSSID_ENABLED &&
2337 params->mbssid_elem_count == 1);
2338 }
2339
2340 tailpos = hostapd_eid_ext_capab(hapd, tailpos, complete);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002341
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002342 /*
2343 * TODO: Time Advertisement element should only be included in some
2344 * DTIM Beacon frames.
2345 */
2346 tailpos = hostapd_eid_time_adv(hapd, tailpos);
2347
2348 tailpos = hostapd_eid_interworking(hapd, tailpos);
2349 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
2350 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002351
2352#ifdef CONFIG_FST
2353 if (hapd->iface->fst_ies) {
2354 os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies),
2355 wpabuf_len(hapd->iface->fst_ies));
2356 tailpos += wpabuf_len(hapd->iface->fst_ies);
2357 }
2358#endif /* CONFIG_FST */
2359
Dmitry Shmidt04949592012-07-19 12:16:46 -07002360#ifdef CONFIG_IEEE80211AC
Hai Shalom60840252021-02-19 19:02:11 -08002361 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
2362 !is_6ghz_op_class(hapd->iconf->op_class)) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -07002363 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08002364 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002365 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08002366 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002367#endif /* CONFIG_IEEE80211AC */
2368
Hai Shalom60840252021-02-19 19:02:11 -08002369#ifdef CONFIG_IEEE80211AX
2370 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax &&
2371 is_6ghz_op_class(hapd->iconf->op_class))
2372 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
2373#endif /* CONFIG_IEEE80211AX */
2374
Hai Shaloma20dcd72022-02-04 13:43:00 -08002375 tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos);
Hai Shalom899fcc72020-10-19 14:38:18 -07002376
Sunil Ravi7f769292024-07-23 22:21:32 +00002377 tailpos = hostapd_eid_rnr(hapd, tailpos, WLAN_FC_STYPE_BEACON, true);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002378 tailpos = hostapd_eid_fils_indic(hapd, tailpos, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -07002379 tailpos = hostapd_get_rsnxe(hapd, tailpos, tailend - tailpos);
Sunil Ravi77d572f2023-01-17 23:58:31 +00002380 tailpos = hostapd_eid_mbssid_config(hapd, tailpos,
2381 params->mbssid_elem_count);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002382
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002383#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08002384 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Sunil Ravia04bd252022-05-02 22:54:18 -07002385 u8 *cca_pos;
2386
Hai Shalom81f62d82019-07-22 12:10:00 -07002387 tailpos = hostapd_eid_he_capab(hapd, tailpos,
2388 IEEE80211_MODE_AP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002389 tailpos = hostapd_eid_he_operation(hapd, tailpos);
Sunil Ravia04bd252022-05-02 22:54:18 -07002390
2391 /* BSS Color Change Announcement element */
2392 cca_pos = hostapd_eid_cca(hapd, tailpos);
2393 if (cca_pos != tailpos)
2394 hapd->cca_c_off_beacon = cca_pos - tail - 2;
2395 tailpos = cca_pos;
2396
Hai Shalom81f62d82019-07-22 12:10:00 -07002397 tailpos = hostapd_eid_spatial_reuse(hapd, tailpos);
Hai Shalomfdcde762020-04-02 11:19:20 -07002398 tailpos = hostapd_eid_he_mu_edca_parameter_set(hapd, tailpos);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002399 tailpos = hostapd_eid_he_6ghz_band_cap(hapd, tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002400 }
2401#endif /* CONFIG_IEEE80211AX */
2402
Sunil Ravia04bd252022-05-02 22:54:18 -07002403#ifdef CONFIG_IEEE80211BE
2404 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002405 if (hapd->conf->mld_ap)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002406 tailpos = hostapd_eid_eht_ml_beacon(hapd, NULL,
2407 tailpos, false);
Sunil Ravia04bd252022-05-02 22:54:18 -07002408 tailpos = hostapd_eid_eht_capab(hapd, tailpos,
2409 IEEE80211_MODE_AP);
2410 tailpos = hostapd_eid_eht_operation(hapd, tailpos);
2411 }
2412#endif /* CONFIG_IEEE80211BE */
2413
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002414#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08002415 if (hapd->conf->vendor_vht)
2416 tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002417#endif /* CONFIG_IEEE80211AC */
2418
Hai Shalomfdcde762020-04-02 11:19:20 -07002419 /* WPA / OSEN */
2420 tailpos = hostapd_get_wpa_ie(hapd, tailpos, tailend - tailpos);
2421 tailpos = hostapd_get_osen_ie(hapd, tailpos, tailend - tailpos);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08002422
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002423 /* Wi-Fi Alliance WMM */
2424 tailpos = hostapd_eid_wmm(hapd, tailpos);
2425
2426#ifdef CONFIG_WPS
2427 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
2428 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
2429 wpabuf_len(hapd->wps_beacon_ie));
2430 tailpos += wpabuf_len(hapd->wps_beacon_ie);
2431 }
2432#endif /* CONFIG_WPS */
2433
2434#ifdef CONFIG_P2P
2435 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
2436 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
2437 wpabuf_len(hapd->p2p_beacon_ie));
2438 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
2439 }
2440#endif /* CONFIG_P2P */
2441#ifdef CONFIG_P2P_MANAGER
2442 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
2443 P2P_MANAGE)
2444 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
2445#endif /* CONFIG_P2P_MANAGER */
2446
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002447#ifdef CONFIG_HS20
2448 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
2449#endif /* CONFIG_HS20 */
2450
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002451 tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002452 tailpos = hostapd_eid_owe_trans(hapd, tailpos,
2453 tail + tail_len - tailpos);
Hai Shalomfdcde762020-04-02 11:19:20 -07002454 tailpos = hostapd_eid_dpp_cc(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002455
Sunil Ravi7f769292024-07-23 22:21:32 +00002456 tailpos = hostapd_get_rsne_override(hapd, tailpos,
2457 tail + tail_len - tailpos);
2458 tailpos = hostapd_get_rsne_override_2(hapd, tailpos,
2459 tail + tail_len - tailpos);
2460 tailpos = hostapd_get_rsnxe_override(hapd, tailpos,
2461 tail + tail_len - tailpos);
2462
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002463 if (hapd->conf->vendor_elements) {
2464 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
2465 wpabuf_len(hapd->conf->vendor_elements));
2466 tailpos += wpabuf_len(hapd->conf->vendor_elements);
2467 }
2468
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002469 tail_len = tailpos > tail ? tailpos - tail : 0;
2470
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002471 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
2472#endif /* NEED_AP_MLME */
2473
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002474 /* If key management offload is enabled, configure PSK to the driver. */
2475 if (wpa_key_mgmt_wpa_psk_no_sae(hapd->conf->wpa_key_mgmt) &&
2476 (hapd->iface->drv_flags2 &
2477 WPA_DRIVER_FLAGS2_4WAY_HANDSHAKE_AP_PSK)) {
2478 if (hapd->conf->ssid.wpa_psk && hapd->conf->ssid.wpa_psk_set) {
2479 os_memcpy(params->psk, hapd->conf->ssid.wpa_psk->psk,
2480 PMK_LEN);
2481 params->psk_len = PMK_LEN;
2482 } else if (hapd->conf->ssid.wpa_passphrase &&
2483 pbkdf2_sha1(hapd->conf->ssid.wpa_passphrase,
2484 hapd->conf->ssid.ssid,
2485 hapd->conf->ssid.ssid_len, 4096,
2486 params->psk, PMK_LEN) == 0) {
2487 params->psk_len = PMK_LEN;
2488 }
2489 }
2490
2491#ifdef CONFIG_SAE
2492 /* If SAE offload is enabled, provide password to lower layer for
2493 * SAE authentication and PMK generation.
2494 */
Sunil Ravi7f769292024-07-23 22:21:32 +00002495 if (wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt |
2496 hapd->conf->rsn_override_key_mgmt |
2497 hapd->conf->rsn_override_key_mgmt_2) &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002498 (hapd->iface->drv_flags2 & WPA_DRIVER_FLAGS2_SAE_OFFLOAD_AP)) {
2499 if (hostapd_sae_pk_in_use(hapd->conf)) {
2500 wpa_printf(MSG_ERROR,
2501 "SAE PK not supported with SAE offload");
2502 return -1;
2503 }
2504
2505 if (hostapd_sae_pw_id_in_use(hapd->conf)) {
2506 wpa_printf(MSG_ERROR,
2507 "SAE Password Identifiers not supported with SAE offload");
2508 return -1;
2509 }
2510
2511 params->sae_password = sae_get_password(hapd, NULL, NULL, NULL,
2512 NULL, NULL);
2513 if (!params->sae_password) {
2514 wpa_printf(MSG_ERROR, "SAE password not configured for offload");
2515 return -1;
2516 }
2517 }
2518#endif /* CONFIG_SAE */
2519
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002520 params->head = (u8 *) head;
2521 params->head_len = head_len;
2522 params->tail = tail;
2523 params->tail_len = tail_len;
2524 params->proberesp = resp;
2525 params->proberesp_len = resp_len;
2526 params->dtim_period = hapd->conf->dtim_period;
2527 params->beacon_int = hapd->iconf->beacon_int;
2528 params->basic_rates = hapd->iface->basic_rates;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002529 params->beacon_rate = hapd->iconf->beacon_rate;
2530 params->rate_type = hapd->iconf->rate_type;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002531 params->ssid = hapd->conf->ssid.ssid;
2532 params->ssid_len = hapd->conf->ssid.ssid_len;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07002533 if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
2534 (WPA_PROTO_WPA | WPA_PROTO_RSN))
2535 params->pairwise_ciphers = hapd->conf->wpa_pairwise |
2536 hapd->conf->rsn_pairwise;
2537 else if (hapd->conf->wpa & WPA_PROTO_RSN)
2538 params->pairwise_ciphers = hapd->conf->rsn_pairwise;
2539 else if (hapd->conf->wpa & WPA_PROTO_WPA)
2540 params->pairwise_ciphers = hapd->conf->wpa_pairwise;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002541 params->group_cipher = hapd->conf->wpa_group;
Sunil Ravi7f769292024-07-23 22:21:32 +00002542 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt |
2543 hapd->conf->rsn_override_key_mgmt |
2544 hapd->conf->rsn_override_key_mgmt_2;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002545 params->auth_algs = hapd->conf->auth_algs;
2546 params->wpa_version = hapd->conf->wpa;
Hai Shalomfdcde762020-04-02 11:19:20 -07002547 params->privacy = hapd->conf->wpa;
2548#ifdef CONFIG_WEP
2549 params->privacy |= hapd->conf->ssid.wep.keys_set ||
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002550 (hapd->conf->ieee802_1x &&
2551 (hapd->conf->default_wep_key_len ||
2552 hapd->conf->individual_wep_key_len));
Hai Shalomfdcde762020-04-02 11:19:20 -07002553#endif /* CONFIG_WEP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002554 switch (hapd->conf->ignore_broadcast_ssid) {
2555 case 0:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002556 params->hide_ssid = NO_SSID_HIDING;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002557 break;
2558 case 1:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002559 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002560 break;
2561 case 2:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002562 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002563 break;
2564 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002565 params->isolate = hapd->conf->isolate;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002566#ifdef NEED_AP_MLME
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002567 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002568 ERP_INFO_USE_PROTECTION);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002569 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002570 hapd->iconf->preamble == SHORT_PREAMBLE;
2571 if (hapd->iface->current_mode &&
2572 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002573 params->short_slot_time =
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002574 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
2575 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002576 params->short_slot_time = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002577 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002578 params->ht_opmode = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002579 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002580 params->ht_opmode = hapd->iface->ht_op_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002581#endif /* NEED_AP_MLME */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002582 params->interworking = hapd->conf->interworking;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002583 if (hapd->conf->interworking &&
2584 !is_zero_ether_addr(hapd->conf->hessid))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002585 params->hessid = hapd->conf->hessid;
2586 params->access_network_type = hapd->conf->access_network_type;
2587 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002588#ifdef CONFIG_P2P
2589 params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
2590#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002591#ifdef CONFIG_HS20
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002592 params->disable_dgaf = hapd->conf->disable_dgaf;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002593 if (hapd->conf->osen) {
2594 params->privacy = 1;
2595 params->osen = 1;
2596 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002597#endif /* CONFIG_HS20 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002598 params->multicast_to_unicast = hapd->conf->multicast_to_unicast;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002599 params->pbss = hapd->conf->pbss;
Hai Shalom74f70d42019-02-11 14:42:39 -08002600
2601 if (hapd->conf->ftm_responder) {
2602 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_FTM_RESPONDER) {
2603 params->ftm_responder = 1;
2604 params->lci = hapd->iface->conf->lci;
2605 params->civic = hapd->iface->conf->civic;
2606 } else {
2607 wpa_printf(MSG_WARNING,
2608 "Not configuring FTM responder as the driver doesn't advertise support for it");
2609 }
2610 }
2611
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002612#ifdef CONFIG_IEEE80211BE
2613 if (hapd->conf->mld_ap && hapd->iconf->ieee80211be &&
2614 !hapd->conf->disable_11be) {
2615 params->mld_ap = true;
2616 params->mld_link_id = hapd->mld_link_id;
2617 }
2618#endif /* CONFIG_IEEE80211BE */
2619
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002620 return 0;
2621}
2622
2623
2624void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
2625{
2626 os_free(params->tail);
2627 params->tail = NULL;
2628 os_free(params->head);
2629 params->head = NULL;
2630 os_free(params->proberesp);
2631 params->proberesp = NULL;
Sunil Ravi77d572f2023-01-17 23:58:31 +00002632 os_free(params->mbssid_elem);
2633 params->mbssid_elem = NULL;
2634 os_free(params->mbssid_elem_offset);
2635 params->mbssid_elem_offset = NULL;
Sunil Ravi640215c2023-06-28 23:08:09 +00002636 os_free(params->rnr_elem);
2637 params->rnr_elem = NULL;
2638 os_free(params->rnr_elem_offset);
2639 params->rnr_elem_offset = NULL;
Hai Shalom60840252021-02-19 19:02:11 -08002640#ifdef CONFIG_FILS
2641 os_free(params->fd_frame_tmpl);
2642 params->fd_frame_tmpl = NULL;
2643#endif /* CONFIG_FILS */
2644#ifdef CONFIG_IEEE80211AX
Sunil Ravi7f769292024-07-23 22:21:32 +00002645 os_free(params->ubpr.unsol_bcast_probe_resp_tmpl);
2646 params->ubpr.unsol_bcast_probe_resp_tmpl = NULL;
Hai Shalom60840252021-02-19 19:02:11 -08002647#endif /* CONFIG_IEEE80211AX */
Sunil Ravi640215c2023-06-28 23:08:09 +00002648 os_free(params->allowed_freqs);
2649 params->allowed_freqs = NULL;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002650}
2651
2652
Hai Shaloma20dcd72022-02-04 13:43:00 -08002653static int __ieee802_11_set_beacon(struct hostapd_data *hapd)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002654{
2655 struct wpa_driver_ap_params params;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002656 struct hostapd_freq_params freq;
2657 struct hostapd_iface *iface = hapd->iface;
2658 struct hostapd_config *iconf = iface->conf;
Hai Shalom81f62d82019-07-22 12:10:00 -07002659 struct hostapd_hw_modes *cmode = iface->current_mode;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002660 struct wpabuf *beacon, *proberesp, *assocresp;
Sunil Ravi7f769292024-07-23 22:21:32 +00002661 bool twt_he_responder = false;
Sunil Ravi640215c2023-06-28 23:08:09 +00002662 int res, ret = -1, i;
2663 struct hostapd_hw_modes *mode;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002664
Hai Shaloma20dcd72022-02-04 13:43:00 -08002665 if (!hapd->drv_priv) {
2666 wpa_printf(MSG_ERROR, "Interface is disabled");
2667 return -1;
2668 }
2669
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002670 if (hapd->csa_in_progress) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002671 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002672 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002673 }
2674
2675 hapd->beacon_set_done = 1;
2676
2677 if (ieee802_11_build_ap_params(hapd, &params) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002678 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002679
2680 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
2681 0)
2682 goto fail;
2683
2684 params.beacon_ies = beacon;
2685 params.proberesp_ies = proberesp;
2686 params.assocresp_ies = assocresp;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002687 params.reenable = hapd->reenable_beacon;
Hai Shalomc3565922019-10-28 11:58:20 -07002688#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08002689 params.he_spr_ctrl = hapd->iface->conf->spr.sr_control;
2690 params.he_spr_non_srg_obss_pd_max_offset =
2691 hapd->iface->conf->spr.non_srg_obss_pd_max_offset;
Hai Shalomc3565922019-10-28 11:58:20 -07002692 params.he_spr_srg_obss_pd_min_offset =
2693 hapd->iface->conf->spr.srg_obss_pd_min_offset;
2694 params.he_spr_srg_obss_pd_max_offset =
2695 hapd->iface->conf->spr.srg_obss_pd_max_offset;
Hai Shalom60840252021-02-19 19:02:11 -08002696 os_memcpy(params.he_spr_bss_color_bitmap,
2697 hapd->iface->conf->spr.srg_bss_color_bitmap, 8);
2698 os_memcpy(params.he_spr_partial_bssid_bitmap,
2699 hapd->iface->conf->spr.srg_partial_bssid_bitmap, 8);
Hai Shalomfdcde762020-04-02 11:19:20 -07002700 params.he_bss_color_disabled =
2701 hapd->iface->conf->he_op.he_bss_color_disabled;
2702 params.he_bss_color_partial =
2703 hapd->iface->conf->he_op.he_bss_color_partial;
2704 params.he_bss_color = hapd->iface->conf->he_op.he_bss_color;
Sunil Ravi7f769292024-07-23 22:21:32 +00002705 twt_he_responder = hostapd_get_he_twt_responder(hapd,
2706 IEEE80211_MODE_AP);
2707 params.ubpr.unsol_bcast_probe_resp_tmpl =
2708 hostapd_unsol_bcast_probe_resp(hapd, &params.ubpr);
Hai Shalomc3565922019-10-28 11:58:20 -07002709#endif /* CONFIG_IEEE80211AX */
Sunil Ravi7f769292024-07-23 22:21:32 +00002710 params.twt_responder =
2711 twt_he_responder || hostapd_get_ht_vht_twt_responder(hapd);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002712 hapd->reenable_beacon = 0;
Hai Shalom60840252021-02-19 19:02:11 -08002713#ifdef CONFIG_SAE
2714 params.sae_pwe = hapd->conf->sae_pwe;
2715#endif /* CONFIG_SAE */
2716
2717#ifdef CONFIG_FILS
2718 params.fd_frame_tmpl = hostapd_fils_discovery(hapd, &params);
2719#endif /* CONFIG_FILS */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002720
Sunil Ravi036cec52023-03-29 11:35:17 -07002721#ifdef CONFIG_IEEE80211BE
2722 params.punct_bitmap = iconf->punct_bitmap;
2723#endif /* CONFIG_IEEE80211BE */
2724
Hai Shalom81f62d82019-07-22 12:10:00 -07002725 if (cmode &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002726 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
Hai Shalomc3565922019-10-28 11:58:20 -07002727 iconf->channel, iconf->enable_edmg,
2728 iconf->edmg_channel, iconf->ieee80211n,
Hai Shalom81f62d82019-07-22 12:10:00 -07002729 iconf->ieee80211ac, iconf->ieee80211ax,
Sunil Ravia04bd252022-05-02 22:54:18 -07002730 iconf->ieee80211be,
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002731 iconf->secondary_channel,
Hai Shalom81f62d82019-07-22 12:10:00 -07002732 hostapd_get_oper_chwidth(iconf),
2733 hostapd_get_oper_centr_freq_seg0_idx(iconf),
2734 hostapd_get_oper_centr_freq_seg1_idx(iconf),
2735 cmode->vht_capab,
Sunil Ravia04bd252022-05-02 22:54:18 -07002736 &cmode->he_capab[IEEE80211_MODE_AP],
Sunil Ravi99c035e2024-07-12 01:42:03 +00002737 &cmode->eht_capab[IEEE80211_MODE_AP],
Sunil Ravi7f769292024-07-23 22:21:32 +00002738 hostapd_get_punct_bitmap(hapd)) == 0) {
2739 freq.link_id = -1;
2740#ifdef CONFIG_IEEE80211BE
2741 if (hapd->conf->mld_ap)
2742 freq.link_id = hapd->mld_link_id;
2743#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002744 params.freq = &freq;
Sunil Ravi7f769292024-07-23 22:21:32 +00002745 }
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002746
Sunil Ravi640215c2023-06-28 23:08:09 +00002747 for (i = 0; i < hapd->iface->num_hw_features; i++) {
2748 mode = &hapd->iface->hw_features[i];
2749
2750 if (iconf->hw_mode != HOSTAPD_MODE_IEEE80211ANY &&
2751 iconf->hw_mode != mode->mode)
2752 continue;
2753
2754 hostapd_get_hw_mode_any_channels(hapd, mode,
2755 !(iconf->acs_freq_list.num ||
2756 iconf->acs_ch_list.num),
2757 true, &params.allowed_freqs);
2758 }
2759
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002760 res = hostapd_drv_set_ap(hapd, &params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002761 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002762 if (res)
2763 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
2764 else
2765 ret = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002766fail:
2767 ieee802_11_free_ap_params(&params);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002768 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002769}
2770
2771
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002772void ieee802_11_set_beacon_per_bss_only(struct hostapd_data *hapd)
2773{
2774 __ieee802_11_set_beacon(hapd);
2775}
2776
2777
Hai Shaloma20dcd72022-02-04 13:43:00 -08002778int ieee802_11_set_beacon(struct hostapd_data *hapd)
2779{
2780 struct hostapd_iface *iface = hapd->iface;
2781 int ret;
2782 size_t i, j;
Sunil Ravi7f769292024-07-23 22:21:32 +00002783 bool is_6g, hapd_mld = false;
Hai Shaloma20dcd72022-02-04 13:43:00 -08002784
2785 ret = __ieee802_11_set_beacon(hapd);
2786 if (ret != 0)
2787 return ret;
2788
2789 if (!iface->interfaces || iface->interfaces->count <= 1)
2790 return 0;
2791
Sunil Ravi7f769292024-07-23 22:21:32 +00002792#ifdef CONFIG_IEEE80211BE
2793 hapd_mld = hapd->conf->mld_ap;
2794#endif /* CONFIG_IEEE80211BE */
2795
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002796 /* Update Beacon frames in case of 6 GHz colocation or AP MLD */
Hai Shaloma20dcd72022-02-04 13:43:00 -08002797 is_6g = is_6ghz_op_class(iface->conf->op_class);
2798 for (j = 0; j < iface->interfaces->count; j++) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002799 struct hostapd_iface *other;
Sunil Ravi7f769292024-07-23 22:21:32 +00002800 bool other_iface_6g;
Hai Shaloma20dcd72022-02-04 13:43:00 -08002801
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002802 other = iface->interfaces->iface[j];
2803 if (other == iface || !other || !other->conf)
Hai Shaloma20dcd72022-02-04 13:43:00 -08002804 continue;
2805
Sunil Ravi7f769292024-07-23 22:21:32 +00002806 other_iface_6g = is_6ghz_op_class(other->conf->op_class);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002807
Sunil Ravi7f769292024-07-23 22:21:32 +00002808 if (is_6g == other_iface_6g && !hapd_mld)
Hai Shaloma20dcd72022-02-04 13:43:00 -08002809 continue;
2810
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002811 for (i = 0; i < other->num_bss; i++) {
Sunil Ravi7f769292024-07-23 22:21:32 +00002812#ifdef CONFIG_IEEE80211BE
2813 if (is_6g == other_iface_6g &&
2814 !(hapd_mld && other->bss[i]->conf->mld_ap &&
2815 hostapd_is_ml_partner(hapd, other->bss[i])))
2816 continue;
2817#endif /* CONFIG_IEEE80211BE */
2818
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002819 if (other->bss[i] && other->bss[i]->started)
2820 __ieee802_11_set_beacon(other->bss[i]);
Hai Shaloma20dcd72022-02-04 13:43:00 -08002821 }
2822 }
2823
2824 return 0;
2825}
2826
2827
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002828int ieee802_11_set_beacons(struct hostapd_iface *iface)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002829{
2830 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002831 int ret = 0;
2832
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08002833 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002834 if (iface->bss[i]->started &&
2835 ieee802_11_set_beacon(iface->bss[i]) < 0)
2836 ret = -1;
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08002837 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002838
2839 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002840}
2841
Dmitry Shmidt04949592012-07-19 12:16:46 -07002842
2843/* only update beacons if started */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002844int ieee802_11_update_beacons(struct hostapd_iface *iface)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002845{
2846 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002847 int ret = 0;
2848
2849 for (i = 0; i < iface->num_bss; i++) {
2850 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
2851 ieee802_11_set_beacon(iface->bss[i]) < 0)
2852 ret = -1;
2853 }
2854
2855 return ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002856}
2857
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002858#endif /* CONFIG_NATIVE_WINDOWS */