blob: dbc6b062b84122822c0b5d1517ad3181e57d7e0a [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / IEEE 802.11 Management: Beacon and Probe Request/Response
3 * Copyright (c) 2002-2004, Instant802 Networks, Inc.
4 * Copyright (c) 2005-2006, Devicescape Software, Inc.
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005 * Copyright (c) 2008-2012, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006 *
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007 * This software may be distributed under the terms of the BSD license.
8 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009 */
10
11#include "utils/includes.h"
12
13#ifndef CONFIG_NATIVE_WINDOWS
14
15#include "utils/common.h"
16#include "common/ieee802_11_defs.h"
17#include "common/ieee802_11_common.h"
Dmitry Shmidt7f656022015-02-25 14:36:37 -080018#include "common/hw_features_common.h"
Roshan Pius3a1667e2018-07-03 15:17:14 -070019#include "common/wpa_ctrl.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070020#include "wps/wps_defs.h"
21#include "p2p/p2p.h"
22#include "hostapd.h"
23#include "ieee802_11.h"
24#include "wpa_auth.h"
25#include "wmm.h"
26#include "ap_config.h"
27#include "sta_info.h"
28#include "p2p_hostapd.h"
29#include "ap_drv_ops.h"
30#include "beacon.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070031#include "hs20.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080032#include "dfs.h"
Dmitry Shmidtaca489e2016-09-28 15:44:14 -070033#include "taxonomy.h"
Roshan Pius3a1667e2018-07-03 15:17:14 -070034#include "ieee802_11_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070035
36
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080037#ifdef NEED_AP_MLME
38
Dmitry Shmidt051af732013-10-22 13:52:46 -070039static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
40{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080041 if (len < 2 + 5)
42 return eid;
43
Dmitry Shmidt051af732013-10-22 13:52:46 -070044#ifdef CONFIG_TESTING_OPTIONS
45 if (hapd->conf->bss_load_test_set) {
Dmitry Shmidt051af732013-10-22 13:52:46 -070046 *eid++ = WLAN_EID_BSS_LOAD;
47 *eid++ = 5;
48 os_memcpy(eid, hapd->conf->bss_load_test, 5);
49 eid += 5;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080050 return eid;
Dmitry Shmidt051af732013-10-22 13:52:46 -070051 }
52#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080053 if (hapd->conf->bss_load_update_period) {
54 *eid++ = WLAN_EID_BSS_LOAD;
55 *eid++ = 5;
56 WPA_PUT_LE16(eid, hapd->num_sta);
57 eid += 2;
58 *eid++ = hapd->iface->channel_utilization;
59 WPA_PUT_LE16(eid, 0); /* no available admission capabity */
60 eid += 2;
61 }
Dmitry Shmidt051af732013-10-22 13:52:46 -070062 return eid;
63}
64
65
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070066static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
67{
68 u8 erp = 0;
69
70 if (hapd->iface->current_mode == NULL ||
71 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
72 return 0;
73
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080074 if (hapd->iface->olbc)
75 erp |= ERP_INFO_USE_PROTECTION;
76 if (hapd->iface->num_sta_non_erp > 0) {
77 erp |= ERP_INFO_NON_ERP_PRESENT |
78 ERP_INFO_USE_PROTECTION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070079 }
80 if (hapd->iface->num_sta_no_short_preamble > 0 ||
81 hapd->iconf->preamble == LONG_PREAMBLE)
82 erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
83
84 return erp;
85}
86
87
88static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
89{
90 *eid++ = WLAN_EID_DS_PARAMS;
91 *eid++ = 1;
92 *eid++ = hapd->iconf->channel;
93 return eid;
94}
95
96
97static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
98{
99 if (hapd->iface->current_mode == NULL ||
100 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
101 return eid;
102
103 /* Set NonERP_present and use_protection bits if there
104 * are any associated NonERP stations. */
105 /* TODO: use_protection bit can be set to zero even if
106 * there are NonERP stations present. This optimization
107 * might be useful if NonERP stations are "quiet".
108 * See 802.11g/D6 E-1 for recommended practice.
109 * In addition, Non ERP present might be set, if AP detects Non ERP
110 * operation on other APs. */
111
112 /* Add ERP Information element */
113 *eid++ = WLAN_EID_ERP_INFO;
114 *eid++ = 1;
115 *eid++ = ieee802_11_erp_info(hapd);
116
117 return eid;
118}
119
120
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800121static u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid)
122{
123 u8 *pos = eid;
124 u8 local_pwr_constraint = 0;
125 int dfs;
126
127 if (hapd->iface->current_mode == NULL ||
128 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
129 return eid;
130
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700131 /* Let host drivers add this IE if DFS support is offloaded */
132 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)
133 return eid;
134
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800135 /*
136 * There is no DFS support and power constraint was not directly
137 * requested by config option.
138 */
139 if (!hapd->iconf->ieee80211h &&
140 hapd->iconf->local_pwr_constraint == -1)
141 return eid;
142
143 /* Check if DFS is required by regulatory. */
144 dfs = hostapd_is_dfs_required(hapd->iface);
145 if (dfs < 0) {
146 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
147 dfs);
148 dfs = 0;
149 }
150
151 if (dfs == 0 && hapd->iconf->local_pwr_constraint == -1)
152 return eid;
153
154 /*
155 * ieee80211h (DFS) is enabled so Power Constraint element shall
156 * be added when running on DFS channel whenever local_pwr_constraint
157 * is configured or not. In order to meet regulations when TPC is not
158 * implemented using a transmit power that is below the legal maximum
159 * (including any mitigation factor) should help. In this case,
160 * indicate 3 dB below maximum allowed transmit power.
161 */
162 if (hapd->iconf->local_pwr_constraint == -1)
163 local_pwr_constraint = 3;
164
165 /*
166 * A STA that is not an AP shall use a transmit power less than or
167 * equal to the local maximum transmit power level for the channel.
168 * The local maximum transmit power can be calculated from the formula:
169 * local max TX pwr = max TX pwr - local pwr constraint
170 * Where max TX pwr is maximum transmit power level specified for
171 * channel in Country element and local pwr constraint is specified
172 * for channel in this Power Constraint element.
173 */
174
175 /* Element ID */
176 *pos++ = WLAN_EID_PWR_CONSTRAINT;
177 /* Length */
178 *pos++ = 1;
179 /* Local Power Constraint */
180 if (local_pwr_constraint)
181 *pos++ = local_pwr_constraint;
182 else
183 *pos++ = hapd->iconf->local_pwr_constraint;
184
185 return pos;
186}
187
188
Sunil Ravia04bd252022-05-02 22:54:18 -0700189static u8 * hostapd_eid_country_add(struct hostapd_data *hapd, u8 *pos,
190 u8 *end, int chan_spacing,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700191 struct hostapd_channel_data *start,
192 struct hostapd_channel_data *prev)
193{
194 if (end - pos < 3)
195 return pos;
196
197 /* first channel number */
198 *pos++ = start->chan;
199 /* number of channels */
200 *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
201 /* maximum transmit power level */
Sunil Ravia04bd252022-05-02 22:54:18 -0700202 if (!is_6ghz_op_class(hapd->iconf->op_class))
203 *pos++ = start->max_tx_power;
204 else
205 *pos++ = 0; /* Reserved when operating on the 6 GHz band */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700206
207 return pos;
208}
209
210
Sunil Ravia04bd252022-05-02 22:54:18 -0700211static u8 * hostapd_fill_subband_triplets(struct hostapd_data *hapd, u8 *pos,
212 u8 *end)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700213{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700214 int i;
215 struct hostapd_hw_modes *mode;
216 struct hostapd_channel_data *start, *prev;
217 int chan_spacing = 1;
218
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700219 mode = hapd->iface->current_mode;
220 if (mode->mode == HOSTAPD_MODE_IEEE80211A)
221 chan_spacing = 4;
222
223 start = prev = NULL;
224 for (i = 0; i < mode->num_channels; i++) {
225 struct hostapd_channel_data *chan = &mode->channels[i];
226 if (chan->flag & HOSTAPD_CHAN_DISABLED)
227 continue;
228 if (start && prev &&
229 prev->chan + chan_spacing == chan->chan &&
230 start->max_tx_power == chan->max_tx_power) {
231 prev = chan;
232 continue; /* can use same entry */
233 }
234
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -0700235 if (start && prev) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700236 pos = hostapd_eid_country_add(hapd, pos, end,
237 chan_spacing,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700238 start, prev);
239 start = NULL;
240 }
241
242 /* Start new group */
243 start = prev = chan;
244 }
245
246 if (start) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700247 pos = hostapd_eid_country_add(hapd, pos, end, chan_spacing,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700248 start, prev);
249 }
250
Sunil Ravia04bd252022-05-02 22:54:18 -0700251 return pos;
252}
253
254
255static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
256 int max_len)
257{
258 u8 *pos = eid;
259 u8 *end = eid + max_len;
260
261 if (!hapd->iconf->ieee80211d || max_len < 6 ||
262 hapd->iface->current_mode == NULL)
263 return eid;
264
265 *pos++ = WLAN_EID_COUNTRY;
266 pos++; /* length will be set later */
267 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
268 pos += 3;
269
270 if (is_6ghz_op_class(hapd->iconf->op_class)) {
271 /* Force the third octet of the country string to indicate
272 * Global Operating Class (Table E-4) */
273 eid[4] = 0x04;
274
275 /* Operating Triplet field */
276 /* Operating Extension Identifier (>= 201 to indicate this is
277 * not a Subband Triplet field) */
278 *pos++ = 201;
279 /* Operating Class */
280 *pos++ = hapd->iconf->op_class;
281 /* Coverage Class */
282 *pos++ = 0;
283 /* Subband Triplets are required only for the 20 MHz case */
284 if (hapd->iconf->op_class == 131 ||
285 hapd->iconf->op_class == 136)
286 pos = hostapd_fill_subband_triplets(hapd, pos, end);
287 } else {
288 pos = hostapd_fill_subband_triplets(hapd, pos, end);
289 }
290
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700291 if ((pos - eid) & 1) {
292 if (end - pos < 1)
293 return eid;
294 *pos++ = 0; /* pad for 16-bit alignment */
295 }
296
297 eid[1] = (pos - eid) - 2;
298
299 return pos;
300}
301
302
Hai Shalom60840252021-02-19 19:02:11 -0800303const u8 * hostapd_wpa_ie(struct hostapd_data *hapd, u8 eid)
Hai Shalomfdcde762020-04-02 11:19:20 -0700304{
305 const u8 *ies;
306 size_t ies_len;
307
308 ies = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ies_len);
309 if (!ies)
310 return NULL;
311
312 return get_ie(ies, ies_len, eid);
313}
314
315
316static const u8 * hostapd_vendor_wpa_ie(struct hostapd_data *hapd,
317 u32 vendor_type)
318{
319 const u8 *ies;
320 size_t ies_len;
321
322 ies = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ies_len);
323 if (!ies)
324 return NULL;
325
326 return get_vendor_ie(ies, ies_len, vendor_type);
327}
328
329
330static u8 * hostapd_get_rsne(struct hostapd_data *hapd, u8 *pos, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700331{
332 const u8 *ie;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700333
Hai Shalomfdcde762020-04-02 11:19:20 -0700334 ie = hostapd_wpa_ie(hapd, WLAN_EID_RSN);
335 if (!ie || 2U + ie[1] > len)
336 return pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700337
Hai Shalomfdcde762020-04-02 11:19:20 -0700338 os_memcpy(pos, ie, 2 + ie[1]);
339 return pos + 2 + ie[1];
340}
341
342
343static u8 * hostapd_get_mde(struct hostapd_data *hapd, u8 *pos, size_t len)
344{
345 const u8 *ie;
346
347 ie = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN);
348 if (!ie || 2U + ie[1] > len)
349 return pos;
350
351 os_memcpy(pos, ie, 2 + ie[1]);
352 return pos + 2 + ie[1];
353}
354
355
356static u8 * hostapd_get_rsnxe(struct hostapd_data *hapd, u8 *pos, size_t len)
357{
358 const u8 *ie;
359
360#ifdef CONFIG_TESTING_OPTIONS
361 if (hapd->conf->no_beacon_rsnxe) {
362 wpa_printf(MSG_INFO, "TESTING: Do not add RSNXE into Beacon");
363 return pos;
364 }
365#endif /* CONFIG_TESTING_OPTIONS */
366 ie = hostapd_wpa_ie(hapd, WLAN_EID_RSNX);
367 if (!ie || 2U + ie[1] > len)
368 return pos;
369
370 os_memcpy(pos, ie, 2 + ie[1]);
371 return pos + 2 + ie[1];
372}
373
374
375static u8 * hostapd_get_wpa_ie(struct hostapd_data *hapd, u8 *pos, size_t len)
376{
377 const u8 *ie;
378
379 ie = hostapd_vendor_wpa_ie(hapd, WPA_IE_VENDOR_TYPE);
380 if (!ie || 2U + ie[1] > len)
381 return pos;
382
383 os_memcpy(pos, ie, 2 + ie[1]);
384 return pos + 2 + ie[1];
385}
386
387
388static u8 * hostapd_get_osen_ie(struct hostapd_data *hapd, u8 *pos, size_t len)
389{
390 const u8 *ie;
391
392 ie = hostapd_vendor_wpa_ie(hapd, OSEN_IE_VENDOR_TYPE);
393 if (!ie || 2U + ie[1] > len)
394 return pos;
395
396 os_memcpy(pos, ie, 2 + ie[1]);
397 return pos + 2 + ie[1];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700398}
399
400
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800401static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
402{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800403#ifdef CONFIG_TESTING_OPTIONS
404 if (hapd->iface->cs_oper_class && hapd->iconf->ecsa_ie_only)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800405 return eid;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800406#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800407
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800408 if (!hapd->cs_freq_params.channel)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800409 return eid;
410
411 *eid++ = WLAN_EID_CHANNEL_SWITCH;
412 *eid++ = 3;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700413 *eid++ = hapd->cs_block_tx;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800414 *eid++ = hapd->cs_freq_params.channel;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700415 *eid++ = hapd->cs_count;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800416
417 return eid;
418}
419
420
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800421static u8 * hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800422{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800423 if (!hapd->cs_freq_params.channel || !hapd->iface->cs_oper_class)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800424 return eid;
425
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800426 *eid++ = WLAN_EID_EXT_CHANSWITCH_ANN;
427 *eid++ = 4;
428 *eid++ = hapd->cs_block_tx;
429 *eid++ = hapd->iface->cs_oper_class;
430 *eid++ = hapd->cs_freq_params.channel;
431 *eid++ = hapd->cs_count;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800432
433 return eid;
434}
435
436
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800437static u8 * hostapd_eid_supported_op_classes(struct hostapd_data *hapd, u8 *eid)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800438{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800439 u8 op_class, channel;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800440
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800441 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) ||
442 !hapd->iface->freq)
443 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800444
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800445 if (ieee80211_freq_to_channel_ext(hapd->iface->freq,
446 hapd->iconf->secondary_channel,
Hai Shalom81f62d82019-07-22 12:10:00 -0700447 hostapd_get_oper_chwidth(hapd->iconf),
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800448 &op_class, &channel) ==
449 NUM_HOSTAPD_MODES)
450 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800451
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800452 *eid++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES;
453 *eid++ = 2;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800454
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800455 /* Current Operating Class */
456 *eid++ = op_class;
457
458 /* TODO: Advertise all the supported operating classes */
459 *eid++ = 0;
460
461 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800462}
463
464
Sunil Ravi77d572f2023-01-17 23:58:31 +0000465static int
466ieee802_11_build_ap_params_mbssid(struct hostapd_data *hapd,
467 struct wpa_driver_ap_params *params)
468{
469 struct hostapd_iface *iface = hapd->iface;
470 struct hostapd_data *tx_bss;
471 size_t len;
472 u8 elem_count = 0, *elem = NULL, **elem_offset = NULL, *end;
473
474 if (!iface->mbssid_max_interfaces ||
475 iface->num_bss > iface->mbssid_max_interfaces ||
476 (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED &&
477 !iface->ema_max_periodicity))
478 goto fail;
479
480 tx_bss = hostapd_mbssid_get_tx_bss(hapd);
481 len = hostapd_eid_mbssid_len(tx_bss, WLAN_FC_STYPE_BEACON, &elem_count,
482 NULL, 0);
483 if (!len || (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED &&
484 elem_count > iface->ema_max_periodicity))
485 goto fail;
486
487 elem = os_zalloc(len);
488 if (!elem)
489 goto fail;
490
491 elem_offset = os_zalloc(elem_count * sizeof(u8 *));
492 if (!elem_offset)
493 goto fail;
494
495 end = hostapd_eid_mbssid(tx_bss, elem, elem + len, WLAN_FC_STYPE_BEACON,
496 elem_count, elem_offset, NULL, 0);
497
498 params->mbssid_tx_iface = tx_bss->conf->iface;
499 params->mbssid_index = hostapd_mbssid_get_bss_index(hapd);
500 params->mbssid_elem = elem;
501 params->mbssid_elem_len = end - elem;
502 params->mbssid_elem_count = elem_count;
503 params->mbssid_elem_offset = elem_offset;
504 if (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED)
505 params->ema = true;
506
507 return 0;
508
509fail:
510 os_free(elem);
511 wpa_printf(MSG_ERROR, "MBSSID: Configuration failed");
512 return -1;
513}
514
515
516static u8 * hostapd_eid_mbssid_config(struct hostapd_data *hapd, u8 *eid,
517 u8 mbssid_elem_count)
518{
519 struct hostapd_iface *iface = hapd->iface;
520
521 if (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED) {
522 *eid++ = WLAN_EID_EXTENSION;
523 *eid++ = 3;
524 *eid++ = WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION;
525 *eid++ = iface->num_bss;
526 *eid++ = mbssid_elem_count;
527 }
528
529 return eid;
530}
531
532
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800533static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800534 const struct ieee80211_mgmt *req,
Sunil8cd6f4d2022-06-28 18:40:46 +0000535 int is_p2p, size_t *resp_len,
Sunil Ravi77d572f2023-01-17 23:58:31 +0000536 bool bcast_probe_resp, const u8 *known_bss,
537 u8 known_bss_len)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800538{
539 struct ieee80211_mgmt *resp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800540 u8 *pos, *epos, *csa_pos;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800541 size_t buflen;
542
Sunil Ravi77d572f2023-01-17 23:58:31 +0000543 hapd = hostapd_mbssid_get_tx_bss(hapd);
544
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800545#define MAX_PROBERESP_LEN 768
546 buflen = MAX_PROBERESP_LEN;
547#ifdef CONFIG_WPS
548 if (hapd->wps_probe_resp_ie)
549 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
550#endif /* CONFIG_WPS */
551#ifdef CONFIG_P2P
552 if (hapd->p2p_probe_resp_ie)
553 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
554#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800555#ifdef CONFIG_FST
556 if (hapd->iface->fst_ies)
557 buflen += wpabuf_len(hapd->iface->fst_ies);
558#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700559 if (hapd->conf->vendor_elements)
560 buflen += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800561 if (hapd->conf->vendor_vht) {
562 buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
563 2 + sizeof(struct ieee80211_vht_operation);
564 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800565
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800566#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -0800567 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700568 buflen += 3 + sizeof(struct ieee80211_he_capabilities) +
Hai Shalom74f70d42019-02-11 14:42:39 -0800569 3 + sizeof(struct ieee80211_he_operation) +
Hai Shalom81f62d82019-07-22 12:10:00 -0700570 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
571 3 + sizeof(struct ieee80211_spatial_reuse);
Sunil Ravia04bd252022-05-02 22:54:18 -0700572 if (is_6ghz_op_class(hapd->iconf->op_class)) {
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700573 buflen += sizeof(struct ieee80211_he_6ghz_oper_info) +
574 3 + sizeof(struct ieee80211_he_6ghz_band_cap);
Sunil Ravia04bd252022-05-02 22:54:18 -0700575 /* An additional Transmit Power Envelope element for
576 * subordinate client */
577 if (hapd->iconf->he_6ghz_reg_pwr_type ==
578 HE_6GHZ_INDOOR_AP)
579 buflen += 4;
580 }
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800581 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700582#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800583
Sunil Ravia04bd252022-05-02 22:54:18 -0700584#ifdef CONFIG_IEEE80211BE
585 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
586 buflen += hostapd_eid_eht_capab_len(hapd, IEEE80211_MODE_AP);
587 buflen += 3 + sizeof(struct ieee80211_eht_operation);
588 }
589#endif /* CONFIG_IEEE80211BE */
590
Sunil Ravi77d572f2023-01-17 23:58:31 +0000591 buflen += hostapd_eid_mbssid_len(hapd, WLAN_FC_STYPE_PROBE_RESP, NULL,
592 known_bss, known_bss_len);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800593 buflen += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_PROBE_RESP);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800594 buflen += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700595 buflen += hostapd_eid_owe_trans_len(hapd);
Hai Shalomfdcde762020-04-02 11:19:20 -0700596 buflen += hostapd_eid_dpp_cc_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800597
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800598 resp = os_zalloc(buflen);
599 if (resp == NULL)
600 return NULL;
601
602 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
603
604 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
605 WLAN_FC_STYPE_PROBE_RESP);
606 if (req)
607 os_memcpy(resp->da, req->sa, ETH_ALEN);
Sunil8cd6f4d2022-06-28 18:40:46 +0000608 else if (bcast_probe_resp)
609 os_memset(resp->da, 0xff, ETH_ALEN);
610
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800611 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
612
613 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
614 resp->u.probe_resp.beacon_int =
615 host_to_le16(hapd->iconf->beacon_int);
616
617 /* hardware or low-level driver will setup seq_ctrl and timestamp */
618 resp->u.probe_resp.capab_info =
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700619 host_to_le16(hostapd_own_capab_info(hapd));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800620
621 pos = resp->u.probe_resp.variable;
622 *pos++ = WLAN_EID_SSID;
623 *pos++ = hapd->conf->ssid.ssid_len;
624 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
625 pos += hapd->conf->ssid.ssid_len;
626
627 /* Supported rates */
628 pos = hostapd_eid_supp_rates(hapd, pos);
629
630 /* DS Params */
631 pos = hostapd_eid_ds_params(hapd, pos);
632
633 pos = hostapd_eid_country(hapd, pos, epos - pos);
634
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800635 /* Power Constraint element */
636 pos = hostapd_eid_pwr_constraint(hapd, pos);
637
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800638 /* CSA IE */
639 csa_pos = hostapd_eid_csa(hapd, pos);
640 if (csa_pos != pos)
641 hapd->cs_c_off_proberesp = csa_pos - (u8 *) resp - 1;
642 pos = csa_pos;
643
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800644 /* ERP Information element */
645 pos = hostapd_eid_erp_info(hapd, pos);
646
647 /* Extended supported rates */
648 pos = hostapd_eid_ext_supp_rates(hapd, pos);
649
Hai Shalomfdcde762020-04-02 11:19:20 -0700650 pos = hostapd_get_rsne(hapd, pos, epos - pos);
Dmitry Shmidt051af732013-10-22 13:52:46 -0700651 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000652 pos = hostapd_eid_mbssid(hapd, pos, epos, WLAN_FC_STYPE_PROBE_RESP, 0,
653 NULL, known_bss, known_bss_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800654 pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700655 pos = hostapd_get_mde(hapd, pos, epos - pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800656
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800657 /* eCSA IE */
658 csa_pos = hostapd_eid_ecsa(hapd, pos);
659 if (csa_pos != pos)
660 hapd->cs_c_off_ecsa_proberesp = csa_pos - (u8 *) resp - 1;
661 pos = csa_pos;
662
663 pos = hostapd_eid_supported_op_classes(hapd, pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800664 pos = hostapd_eid_ht_capabilities(hapd, pos);
665 pos = hostapd_eid_ht_operation(hapd, pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800666
Sunil Ravi77d572f2023-01-17 23:58:31 +0000667 /* Probe Response frames always include all non-TX profiles except
668 * when a list of known BSSes is included in the Probe Request frame. */
669 pos = hostapd_eid_ext_capab(hapd, pos,
670 hapd->iconf->mbssid >= MBSSID_ENABLED &&
671 !known_bss_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800672
673 pos = hostapd_eid_time_adv(hapd, pos);
674 pos = hostapd_eid_time_zone(hapd, pos);
675
676 pos = hostapd_eid_interworking(hapd, pos);
677 pos = hostapd_eid_adv_proto(hapd, pos);
678 pos = hostapd_eid_roaming_consortium(hapd, pos);
679
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800680#ifdef CONFIG_FST
681 if (hapd->iface->fst_ies) {
682 os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies),
683 wpabuf_len(hapd->iface->fst_ies));
684 pos += wpabuf_len(hapd->iface->fst_ies);
685 }
686#endif /* CONFIG_FST */
687
Dmitry Shmidt04949592012-07-19 12:16:46 -0700688#ifdef CONFIG_IEEE80211AC
Hai Shalomc3565922019-10-28 11:58:20 -0700689 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
690 !is_6ghz_op_class(hapd->iconf->op_class)) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700691 pos = hostapd_eid_vht_capabilities(hapd, pos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800692 pos = hostapd_eid_vht_operation(hapd, pos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800693 pos = hostapd_eid_txpower_envelope(hapd, pos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800694 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800695#endif /* CONFIG_IEEE80211AC */
696
Hai Shalom60840252021-02-19 19:02:11 -0800697#ifdef CONFIG_IEEE80211AX
698 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax &&
699 is_6ghz_op_class(hapd->iconf->op_class))
700 pos = hostapd_eid_txpower_envelope(hapd, pos);
701#endif /* CONFIG_IEEE80211AX */
702
Hai Shaloma20dcd72022-02-04 13:43:00 -0800703 pos = hostapd_eid_wb_chsw_wrapper(hapd, pos);
Hai Shalom899fcc72020-10-19 14:38:18 -0700704
Hai Shaloma20dcd72022-02-04 13:43:00 -0800705 pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_PROBE_RESP);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800706 pos = hostapd_eid_fils_indic(hapd, pos, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -0700707 pos = hostapd_get_rsnxe(hapd, pos, epos - pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800708
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700709#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -0800710 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700711 u8 *cca_pos;
712
Hai Shalom81f62d82019-07-22 12:10:00 -0700713 pos = hostapd_eid_he_capab(hapd, pos, IEEE80211_MODE_AP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700714 pos = hostapd_eid_he_operation(hapd, pos);
Sunil Ravia04bd252022-05-02 22:54:18 -0700715
716 /* BSS Color Change Announcement element */
717 cca_pos = hostapd_eid_cca(hapd, pos);
718 if (cca_pos != pos)
719 hapd->cca_c_off_proberesp = cca_pos - (u8 *) resp - 2;
720 pos = cca_pos;
721
Hai Shalom81f62d82019-07-22 12:10:00 -0700722 pos = hostapd_eid_spatial_reuse(hapd, pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700723 pos = hostapd_eid_he_mu_edca_parameter_set(hapd, pos);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700724 pos = hostapd_eid_he_6ghz_band_cap(hapd, pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700725 }
726#endif /* CONFIG_IEEE80211AX */
727
Sunil Ravia04bd252022-05-02 22:54:18 -0700728#ifdef CONFIG_IEEE80211BE
729 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
730 pos = hostapd_eid_eht_capab(hapd, pos, IEEE80211_MODE_AP);
731 pos = hostapd_eid_eht_operation(hapd, pos);
732 }
733#endif /* CONFIG_IEEE80211BE */
734
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800735#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800736 if (hapd->conf->vendor_vht)
737 pos = hostapd_eid_vendor_vht(hapd, pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700738#endif /* CONFIG_IEEE80211AC */
739
Hai Shalomfdcde762020-04-02 11:19:20 -0700740 /* WPA / OSEN */
741 pos = hostapd_get_wpa_ie(hapd, pos, epos - pos);
742 pos = hostapd_get_osen_ie(hapd, pos, epos - pos);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800743
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800744 /* Wi-Fi Alliance WMM */
745 pos = hostapd_eid_wmm(hapd, pos);
746
747#ifdef CONFIG_WPS
748 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
749 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
750 wpabuf_len(hapd->wps_probe_resp_ie));
751 pos += wpabuf_len(hapd->wps_probe_resp_ie);
752 }
753#endif /* CONFIG_WPS */
754
755#ifdef CONFIG_P2P
756 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
757 hapd->p2p_probe_resp_ie) {
758 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
759 wpabuf_len(hapd->p2p_probe_resp_ie));
760 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
761 }
762#endif /* CONFIG_P2P */
763#ifdef CONFIG_P2P_MANAGER
764 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
765 P2P_MANAGE)
766 pos = hostapd_eid_p2p_manage(hapd, pos);
767#endif /* CONFIG_P2P_MANAGER */
768
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700769#ifdef CONFIG_HS20
770 pos = hostapd_eid_hs20_indication(hapd, pos);
771#endif /* CONFIG_HS20 */
772
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800773 pos = hostapd_eid_mbo(hapd, pos, (u8 *) resp + buflen - pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700774 pos = hostapd_eid_owe_trans(hapd, pos, (u8 *) resp + buflen - pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700775 pos = hostapd_eid_dpp_cc(hapd, pos, (u8 *) resp + buflen - pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800776
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700777 if (hapd->conf->vendor_elements) {
778 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
779 wpabuf_len(hapd->conf->vendor_elements));
780 pos += wpabuf_len(hapd->conf->vendor_elements);
781 }
782
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800783 *resp_len = pos - (u8 *) resp;
784 return (u8 *) resp;
785}
786
787
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800788enum ssid_match_result {
789 NO_SSID_MATCH,
790 EXACT_SSID_MATCH,
Hai Shaloma20dcd72022-02-04 13:43:00 -0800791 WILDCARD_SSID_MATCH,
792 CO_LOCATED_SSID_MATCH,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800793};
794
795static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
796 const u8 *ssid, size_t ssid_len,
797 const u8 *ssid_list,
Hai Shalomfdcde762020-04-02 11:19:20 -0700798 size_t ssid_list_len,
799 const u8 *short_ssid_list,
800 size_t short_ssid_list_len)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800801{
802 const u8 *pos, *end;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800803 struct hostapd_iface *iface = hapd->iface;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800804 int wildcard = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800805 size_t i, j;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800806
807 if (ssid_len == 0)
808 wildcard = 1;
809 if (ssid_len == hapd->conf->ssid.ssid_len &&
810 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
811 return EXACT_SSID_MATCH;
812
Hai Shalomfdcde762020-04-02 11:19:20 -0700813 if (ssid_list) {
814 pos = ssid_list;
815 end = ssid_list + ssid_list_len;
816 while (end - pos >= 2) {
817 if (2 + pos[1] > end - pos)
818 break;
819 if (pos[1] == 0)
820 wildcard = 1;
821 if (pos[1] == hapd->conf->ssid.ssid_len &&
822 os_memcmp(pos + 2, hapd->conf->ssid.ssid,
823 pos[1]) == 0)
824 return EXACT_SSID_MATCH;
825 pos += 2 + pos[1];
826 }
827 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800828
Hai Shalomfdcde762020-04-02 11:19:20 -0700829 if (short_ssid_list) {
830 pos = short_ssid_list;
831 end = short_ssid_list + short_ssid_list_len;
832 while (end - pos >= 4) {
833 if (hapd->conf->ssid.short_ssid == WPA_GET_LE32(pos))
834 return EXACT_SSID_MATCH;
835 pos += 4;
836 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800837 }
838
Hai Shaloma20dcd72022-02-04 13:43:00 -0800839 if (wildcard)
840 return WILDCARD_SSID_MATCH;
841
842 if (!iface->interfaces || iface->interfaces->count <= 1 ||
843 is_6ghz_op_class(hapd->iconf->op_class))
844 return NO_SSID_MATCH;
845
846 for (i = 0; i < iface->interfaces->count; i++) {
847 struct hostapd_iface *colocated;
848
849 colocated = iface->interfaces->iface[i];
850
851 if (colocated == iface ||
852 !is_6ghz_op_class(colocated->conf->op_class))
853 continue;
854
855 for (j = 0; j < colocated->num_bss; j++) {
856 struct hostapd_bss_config *conf;
857
858 conf = colocated->bss[j]->conf;
859 if (ssid_len == conf->ssid.ssid_len &&
860 os_memcmp(ssid, conf->ssid.ssid, ssid_len) == 0)
861 return CO_LOCATED_SSID_MATCH;
862 }
863 }
864
865 return NO_SSID_MATCH;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800866}
867
868
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800869void sta_track_expire(struct hostapd_iface *iface, int force)
870{
871 struct os_reltime now;
872 struct hostapd_sta_info *info;
873
874 if (!iface->num_sta_seen)
875 return;
876
877 os_get_reltime(&now);
878 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
879 list))) {
880 if (!force &&
881 !os_reltime_expired(&now, &info->last_seen,
882 iface->conf->track_sta_max_age))
883 break;
884 force = 0;
885
886 wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
887 MACSTR, iface->bss[0]->conf->iface,
888 MAC2STR(info->addr));
889 dl_list_del(&info->list);
890 iface->num_sta_seen--;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700891 sta_track_del(info);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800892 }
893}
894
895
896static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
897 const u8 *addr)
898{
899 struct hostapd_sta_info *info;
900
901 dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
902 if (os_memcmp(addr, info->addr, ETH_ALEN) == 0)
903 return info;
904
905 return NULL;
906}
907
908
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800909void sta_track_add(struct hostapd_iface *iface, const u8 *addr, int ssi_signal)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800910{
911 struct hostapd_sta_info *info;
912
913 info = sta_track_get(iface, addr);
914 if (info) {
915 /* Move the most recent entry to the end of the list */
916 dl_list_del(&info->list);
917 dl_list_add_tail(&iface->sta_seen, &info->list);
918 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800919 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800920 return;
921 }
922
923 /* Add a new entry */
924 info = os_zalloc(sizeof(*info));
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700925 if (info == NULL)
926 return;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800927 os_memcpy(info->addr, addr, ETH_ALEN);
928 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800929 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800930
931 if (iface->num_sta_seen >= iface->conf->track_sta_max_num) {
932 /* Expire oldest entry to make room for a new one */
933 sta_track_expire(iface, 1);
934 }
935
936 wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
937 MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr));
938 dl_list_add_tail(&iface->sta_seen, &info->list);
939 iface->num_sta_seen++;
940}
941
942
943struct hostapd_data *
944sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
945 const char *ifname)
946{
947 struct hapd_interfaces *interfaces = iface->interfaces;
948 size_t i, j;
949
950 for (i = 0; i < interfaces->count; i++) {
951 struct hostapd_data *hapd = NULL;
952
953 iface = interfaces->iface[i];
954 for (j = 0; j < iface->num_bss; j++) {
955 hapd = iface->bss[j];
956 if (os_strcmp(ifname, hapd->conf->iface) == 0)
957 break;
958 hapd = NULL;
959 }
960
961 if (hapd && sta_track_get(iface, addr))
962 return hapd;
963 }
964
965 return NULL;
966}
967
968
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700969#ifdef CONFIG_TAXONOMY
970void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr,
971 struct wpabuf **probe_ie_taxonomy)
972{
973 struct hostapd_sta_info *info;
974
975 info = sta_track_get(iface, addr);
976 if (!info)
977 return;
978
979 wpabuf_free(*probe_ie_taxonomy);
980 *probe_ie_taxonomy = info->probe_ie_taxonomy;
981 info->probe_ie_taxonomy = NULL;
982}
983#endif /* CONFIG_TAXONOMY */
984
985
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700986void handle_probe_req(struct hostapd_data *hapd,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700987 const struct ieee80211_mgmt *mgmt, size_t len,
988 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700989{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800990 u8 *resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700991 struct ieee802_11_elems elems;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700992 const u8 *ie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800993 size_t ie_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800994 size_t i, resp_len;
995 int noack;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800996 enum ssid_match_result res;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800997 int ret;
998 u16 csa_offs[2];
999 size_t csa_offs_len;
Hai Shalomfdcde762020-04-02 11:19:20 -07001000 struct radius_sta rad_info;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001001
Hai Shalom60840252021-02-19 19:02:11 -08001002 if (hapd->iconf->rssi_ignore_probe_request && ssi_signal &&
1003 ssi_signal < hapd->iconf->rssi_ignore_probe_request)
1004 return;
1005
Dmitry Shmidte4663042016-04-04 10:07:49 -07001006 if (len < IEEE80211_HDRLEN)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001007 return;
Dmitry Shmidte4663042016-04-04 10:07:49 -07001008 ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001009 if (hapd->iconf->track_sta_max_num)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001010 sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
Dmitry Shmidte4663042016-04-04 10:07:49 -07001011 ie_len = len - IEEE80211_HDRLEN;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001012
Hai Shalomfdcde762020-04-02 11:19:20 -07001013 ret = hostapd_allowed_address(hapd, mgmt->sa, (const u8 *) mgmt, len,
1014 &rad_info, 1);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001015 if (ret == HOSTAPD_ACL_REJECT) {
1016 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
1017 "Ignore Probe Request frame from " MACSTR
1018 " due to ACL reject ", MAC2STR(mgmt->sa));
1019 return;
1020 }
1021
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001022 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
1023 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001024 mgmt->sa, mgmt->da, mgmt->bssid,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001025 ie, ie_len, ssi_signal) > 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001026 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001027
Hai Shalom74f70d42019-02-11 14:42:39 -08001028 if (!hapd->conf->send_probe_response)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001029 return;
1030
1031 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
1032 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
1033 MAC2STR(mgmt->sa));
1034 return;
1035 }
1036
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001037 if ((!elems.ssid || !elems.supp_rates)) {
1038 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
1039 "without SSID or supported rates element",
1040 MAC2STR(mgmt->sa));
1041 return;
1042 }
1043
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001044 /*
1045 * No need to reply if the Probe Request frame was sent on an adjacent
1046 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
1047 * AP with dot11RadioMeasurementActivated set to true, but strictly
1048 * speaking does not allow such ignoring of Probe Request frames if
1049 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
1050 * number of unnecessary Probe Response frames for cases where the STA
1051 * is less likely to see them (Probe Request frame sent on a
1052 * neighboring, but partially overlapping, channel).
1053 */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001054 if (elems.ds_params &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001055 hapd->iface->current_mode &&
1056 (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
1057 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
1058 hapd->iconf->channel != elems.ds_params[0]) {
1059 wpa_printf(MSG_DEBUG,
1060 "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
1061 hapd->iconf->channel, elems.ds_params[0]);
1062 return;
1063 }
1064
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001065#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001066 if (hapd->p2p && hapd->p2p_group && elems.wps_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001067 struct wpabuf *wps;
1068 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
1069 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
1070 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
1071 "due to mismatch with Requested Device "
1072 "Type");
1073 wpabuf_free(wps);
1074 return;
1075 }
1076 wpabuf_free(wps);
1077 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001078
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001079 if (hapd->p2p && hapd->p2p_group && elems.p2p) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001080 struct wpabuf *p2p;
1081 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
1082 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
1083 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
1084 "due to mismatch with Device ID");
1085 wpabuf_free(p2p);
1086 return;
1087 }
1088 wpabuf_free(p2p);
1089 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001090#endif /* CONFIG_P2P */
1091
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001092 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
Hai Shalomfdcde762020-04-02 11:19:20 -07001093 elems.ssid_list_len == 0 && elems.short_ssid_list_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001094 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
1095 "broadcast SSID ignored", MAC2STR(mgmt->sa));
1096 return;
1097 }
1098
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001099#ifdef CONFIG_P2P
1100 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1101 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
1102 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
1103 P2P_WILDCARD_SSID_LEN) == 0) {
1104 /* Process P2P Wildcard SSID like Wildcard SSID */
1105 elems.ssid_len = 0;
1106 }
1107#endif /* CONFIG_P2P */
1108
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001109#ifdef CONFIG_TAXONOMY
1110 {
1111 struct sta_info *sta;
1112 struct hostapd_sta_info *info;
1113
1114 if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) {
1115 taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len);
1116 } else if ((info = sta_track_get(hapd->iface,
1117 mgmt->sa)) != NULL) {
1118 taxonomy_hostapd_sta_info_probe_req(hapd, info,
1119 ie, ie_len);
1120 }
1121 }
1122#endif /* CONFIG_TAXONOMY */
1123
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001124 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
Hai Shalomfdcde762020-04-02 11:19:20 -07001125 elems.ssid_list, elems.ssid_list_len,
1126 elems.short_ssid_list, elems.short_ssid_list_len);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001127 if (res == NO_SSID_MATCH) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001128 if (!(mgmt->da[0] & 0x01)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001129 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001130 " for foreign SSID '%s' (DA " MACSTR ")%s",
Dmitry Shmidt3c479372014-02-04 10:50:36 -08001131 MAC2STR(mgmt->sa),
1132 wpa_ssid_txt(elems.ssid, elems.ssid_len),
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001133 MAC2STR(mgmt->da),
1134 elems.ssid_list ? " (SSID list)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001135 }
1136 return;
1137 }
1138
Hai Shalomfdcde762020-04-02 11:19:20 -07001139 if (hapd->conf->ignore_broadcast_ssid && res == WILDCARD_SSID_MATCH) {
1140 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
1141 "broadcast SSID ignored", MAC2STR(mgmt->sa));
1142 return;
1143 }
1144
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001145#ifdef CONFIG_INTERWORKING
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -07001146 if (hapd->conf->interworking &&
1147 elems.interworking && elems.interworking_len >= 1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001148 u8 ant = elems.interworking[0] & 0x0f;
1149 if (ant != INTERWORKING_ANT_WILDCARD &&
1150 ant != hapd->conf->access_network_type) {
1151 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
1152 " for mismatching ANT %u ignored",
1153 MAC2STR(mgmt->sa), ant);
1154 return;
1155 }
1156 }
1157
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -07001158 if (hapd->conf->interworking && elems.interworking &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001159 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
1160 const u8 *hessid;
1161 if (elems.interworking_len == 7)
1162 hessid = elems.interworking + 1;
1163 else
1164 hessid = elems.interworking + 1 + 2;
1165 if (!is_broadcast_ether_addr(hessid) &&
1166 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
1167 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
1168 " for mismatching HESSID " MACSTR
1169 " ignored",
1170 MAC2STR(mgmt->sa), MAC2STR(hessid));
1171 return;
1172 }
1173 }
1174#endif /* CONFIG_INTERWORKING */
1175
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001176#ifdef CONFIG_P2P
1177 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1178 supp_rates_11b_only(&elems)) {
1179 /* Indicates support for 11b rates only */
1180 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
1181 MACSTR " with only 802.11b rates",
1182 MAC2STR(mgmt->sa));
1183 return;
1184 }
1185#endif /* CONFIG_P2P */
1186
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001187 /* TODO: verify that supp_rates contains at least one matching rate
1188 * with AP configuration */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001189
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001190 if (hapd->conf->no_probe_resp_if_seen_on &&
1191 is_multicast_ether_addr(mgmt->da) &&
1192 is_multicast_ether_addr(mgmt->bssid) &&
1193 sta_track_seen_on(hapd->iface, mgmt->sa,
1194 hapd->conf->no_probe_resp_if_seen_on)) {
1195 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1196 " since STA has been seen on %s",
1197 hapd->conf->iface, MAC2STR(mgmt->sa),
1198 hapd->conf->no_probe_resp_if_seen_on);
1199 return;
1200 }
1201
1202 if (hapd->conf->no_probe_resp_if_max_sta &&
1203 is_multicast_ether_addr(mgmt->da) &&
1204 is_multicast_ether_addr(mgmt->bssid) &&
1205 hapd->num_sta >= hapd->conf->max_num_sta &&
1206 !ap_get_sta(hapd, mgmt->sa)) {
1207 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1208 " since no room for additional STA",
1209 hapd->conf->iface, MAC2STR(mgmt->sa));
1210 return;
1211 }
1212
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001213#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001214 if (hapd->iconf->ignore_probe_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001215 drand48() < hapd->iconf->ignore_probe_probability) {
1216 wpa_printf(MSG_INFO,
1217 "TESTING: ignoring probe request from " MACSTR,
1218 MAC2STR(mgmt->sa));
1219 return;
1220 }
1221#endif /* CONFIG_TESTING_OPTIONS */
1222
Sunil Ravi77d572f2023-01-17 23:58:31 +00001223 /* Do not send Probe Response frame from a non-transmitting multiple
1224 * BSSID profile unless the Probe Request frame is directed at that
1225 * particular BSS. */
1226 if (hapd != hostapd_mbssid_get_tx_bss(hapd) && res != EXACT_SSID_MATCH)
1227 return;
1228
Roshan Pius3a1667e2018-07-03 15:17:14 -07001229 wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, RX_PROBE_REQUEST "sa=" MACSTR
1230 " signal=%d", MAC2STR(mgmt->sa), ssi_signal);
1231
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001232 resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL,
Sunil Ravi77d572f2023-01-17 23:58:31 +00001233 &resp_len, false, elems.mbssid_known_bss,
1234 elems.mbssid_known_bss_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001235 if (resp == NULL)
1236 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001237
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001238 /*
1239 * If this is a broadcast probe request, apply no ack policy to avoid
1240 * excessive retries.
1241 */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001242 noack = !!(res == WILDCARD_SSID_MATCH &&
1243 is_broadcast_ether_addr(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001244
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001245 csa_offs_len = 0;
1246 if (hapd->csa_in_progress) {
1247 if (hapd->cs_c_off_proberesp)
1248 csa_offs[csa_offs_len++] =
1249 hapd->cs_c_off_proberesp;
1250
1251 if (hapd->cs_c_off_ecsa_proberesp)
1252 csa_offs[csa_offs_len++] =
1253 hapd->cs_c_off_ecsa_proberesp;
1254 }
1255
Sunil Ravi77d572f2023-01-17 23:58:31 +00001256 ret = hostapd_drv_send_mlme(hostapd_mbssid_get_tx_bss(hapd), resp,
1257 resp_len, noack,
Hai Shalomfdcde762020-04-02 11:19:20 -07001258 csa_offs_len ? csa_offs : NULL,
1259 csa_offs_len, 0);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001260
1261 if (ret < 0)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001262 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001263
1264 os_free(resp);
1265
1266 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
1267 "SSID", MAC2STR(mgmt->sa),
1268 elems.ssid_len == 0 ? "broadcast" : "our");
1269}
1270
1271
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001272static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
1273 size_t *resp_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001274{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001275 /* check probe response offloading caps and print warnings */
1276 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
1277 return NULL;
1278
1279#ifdef CONFIG_WPS
1280 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
1281 (!(hapd->iface->probe_resp_offloads &
1282 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
1283 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
1284 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
1285 "Probe Response while not supporting this");
1286#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001287
1288#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001289 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
1290 !(hapd->iface->probe_resp_offloads &
1291 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
1292 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
1293 "Probe Response while not supporting this");
1294#endif /* CONFIG_P2P */
1295
1296 if (hapd->conf->interworking &&
1297 !(hapd->iface->probe_resp_offloads &
1298 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
1299 wpa_printf(MSG_WARNING, "Device is trying to offload "
1300 "Interworking Probe Response while not supporting "
1301 "this");
1302
1303 /* Generate a Probe Response template for the non-P2P case */
Sunil Ravi77d572f2023-01-17 23:58:31 +00001304 return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len, false, NULL, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001305}
1306
1307#endif /* NEED_AP_MLME */
1308
1309
Hai Shalom60840252021-02-19 19:02:11 -08001310#ifdef CONFIG_IEEE80211AX
1311/* Unsolicited broadcast Probe Response transmission, 6 GHz only */
1312static u8 * hostapd_unsol_bcast_probe_resp(struct hostapd_data *hapd,
1313 struct wpa_driver_ap_params *params)
1314{
1315 if (!is_6ghz_op_class(hapd->iconf->op_class))
1316 return NULL;
1317
1318 params->unsol_bcast_probe_resp_interval =
1319 hapd->conf->unsol_bcast_probe_resp_interval;
1320
1321 return hostapd_gen_probe_resp(hapd, NULL, 0,
Sunil8cd6f4d2022-06-28 18:40:46 +00001322 &params->unsol_bcast_probe_resp_tmpl_len,
Sunil Ravi77d572f2023-01-17 23:58:31 +00001323 true, NULL, 0);
Hai Shalom60840252021-02-19 19:02:11 -08001324}
1325#endif /* CONFIG_IEEE80211AX */
1326
1327
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001328void sta_track_del(struct hostapd_sta_info *info)
1329{
1330#ifdef CONFIG_TAXONOMY
1331 wpabuf_free(info->probe_ie_taxonomy);
1332 info->probe_ie_taxonomy = NULL;
1333#endif /* CONFIG_TAXONOMY */
1334 os_free(info);
1335}
1336
1337
Hai Shalom60840252021-02-19 19:02:11 -08001338#ifdef CONFIG_FILS
1339
1340static u16 hostapd_fils_discovery_cap(struct hostapd_data *hapd)
1341{
1342 u16 cap_info, phy_index = 0;
1343 u8 chwidth = FD_CAP_BSS_CHWIDTH_20, mcs_nss_size = 4;
1344 struct hostapd_hw_modes *mode = hapd->iface->current_mode;
1345
1346 cap_info = FD_CAP_ESS;
1347 if (hapd->conf->wpa)
1348 cap_info |= FD_CAP_PRIVACY;
1349
1350 if (is_6ghz_op_class(hapd->iconf->op_class)) {
1351 phy_index = FD_CAP_PHY_INDEX_HE;
1352
1353 switch (hapd->iconf->op_class) {
1354 case 135:
1355 mcs_nss_size += 4;
1356 /* fallthrough */
1357 case 134:
1358 mcs_nss_size += 4;
1359 chwidth = FD_CAP_BSS_CHWIDTH_160_80_80;
1360 break;
1361 case 133:
1362 chwidth = FD_CAP_BSS_CHWIDTH_80;
1363 break;
1364 case 132:
1365 chwidth = FD_CAP_BSS_CHWIDTH_40;
1366 break;
1367 }
1368 } else {
1369 switch (hostapd_get_oper_chwidth(hapd->iconf)) {
Sunil8cd6f4d2022-06-28 18:40:46 +00001370 case CONF_OPER_CHWIDTH_80P80MHZ:
Hai Shalom60840252021-02-19 19:02:11 -08001371 mcs_nss_size += 4;
1372 /* fallthrough */
Sunil8cd6f4d2022-06-28 18:40:46 +00001373 case CONF_OPER_CHWIDTH_160MHZ:
Hai Shalom60840252021-02-19 19:02:11 -08001374 mcs_nss_size += 4;
1375 chwidth = FD_CAP_BSS_CHWIDTH_160_80_80;
1376 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00001377 case CONF_OPER_CHWIDTH_80MHZ:
Hai Shalom60840252021-02-19 19:02:11 -08001378 chwidth = FD_CAP_BSS_CHWIDTH_80;
1379 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00001380 case CONF_OPER_CHWIDTH_USE_HT:
Hai Shalom60840252021-02-19 19:02:11 -08001381 if (hapd->iconf->secondary_channel)
1382 chwidth = FD_CAP_BSS_CHWIDTH_40;
1383 else
1384 chwidth = FD_CAP_BSS_CHWIDTH_20;
1385 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00001386 default:
1387 break;
Hai Shalom60840252021-02-19 19:02:11 -08001388 }
1389
1390#ifdef CONFIG_IEEE80211AX
1391 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax)
1392 phy_index = FD_CAP_PHY_INDEX_HE;
1393#endif /* CONFIG_IEEE80211AX */
1394#ifdef CONFIG_IEEE80211AC
1395 if (!phy_index &&
1396 hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac)
1397 phy_index = FD_CAP_PHY_INDEX_VHT;
1398#endif /* CONFIG_IEEE80211AC */
1399 if (!phy_index &&
1400 hapd->iconf->ieee80211n && !hapd->conf->disable_11n)
1401 phy_index = FD_CAP_PHY_INDEX_HT;
1402 }
1403
1404 cap_info |= phy_index << FD_CAP_PHY_INDEX_SHIFT;
1405 cap_info |= chwidth << FD_CAP_BSS_CHWIDTH_SHIFT;
1406
1407 if (mode) {
1408 u16 *mcs = (u16 *) mode->he_capab[IEEE80211_MODE_AP].mcs;
1409 int i;
1410 u16 nss = 0;
1411
1412 for (i = 0; i < HE_NSS_MAX_STREAMS; i++) {
1413 u16 nss_mask = 0x3 << (i * 2);
1414
1415 if (mcs_nss_size == 4 &&
1416 (((mcs[0] & nss_mask) == nss_mask) ||
1417 ((mcs[1] & nss_mask) == nss_mask)))
1418 continue;
1419
1420 if (mcs_nss_size == 8 &&
1421 (((mcs[2] & nss_mask) == nss_mask) ||
1422 ((mcs[3] & nss_mask) == nss_mask)))
1423 continue;
1424
1425 if (mcs_nss_size == 12 &&
1426 (((mcs[4] & nss_mask) == nss_mask) ||
1427 ((mcs[5] & nss_mask) == nss_mask)))
1428 continue;
1429
1430 nss++;
1431 }
1432
1433 if (nss > 4)
1434 cap_info |= FD_CAP_NSS_5_8 << FD_CAP_NSS_SHIFT;
1435 else if (nss)
1436 cap_info |= (nss - 1) << FD_CAP_NSS_SHIFT;
1437 }
1438
1439 return cap_info;
1440}
1441
1442
1443static u8 * hostapd_gen_fils_discovery(struct hostapd_data *hapd, size_t *len)
1444{
1445 struct ieee80211_mgmt *head;
1446 const u8 *mobility_domain;
1447 u8 *pos, *length_pos, buf[200];
1448 u16 ctl = 0;
1449 u8 fd_rsn_info[5];
1450 size_t total_len, buf_len;
1451
1452 total_len = 24 + 2 + 12;
1453
1454 /* FILS Discovery Frame Control */
1455 ctl = (sizeof(hapd->conf->ssid.short_ssid) - 1) |
1456 FD_FRAME_CTL_SHORT_SSID_PRESENT |
1457 FD_FRAME_CTL_LENGTH_PRESENT |
1458 FD_FRAME_CTL_CAP_PRESENT;
1459 total_len += 4 + 1 + 2;
1460
1461 /* Check for optional subfields and calculate length */
1462 if (wpa_auth_write_fd_rsn_info(hapd->wpa_auth, fd_rsn_info)) {
1463 ctl |= FD_FRAME_CTL_RSN_INFO_PRESENT;
1464 total_len += sizeof(fd_rsn_info);
1465 }
1466
1467 mobility_domain = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN);
1468 if (mobility_domain) {
1469 ctl |= FD_FRAME_CTL_MD_PRESENT;
1470 total_len += 3;
1471 }
1472
Hai Shaloma20dcd72022-02-04 13:43:00 -08001473 total_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_ACTION);
1474
Hai Shalom60840252021-02-19 19:02:11 -08001475 pos = hostapd_eid_fils_indic(hapd, buf, 0);
1476 buf_len = pos - buf;
1477 total_len += buf_len;
1478
Sunil Ravia04bd252022-05-02 22:54:18 -07001479#ifdef CONFIG_IEEE80211AX
1480 /* Transmit Power Envelope element(s) */
1481 if (is_6ghz_op_class(hapd->iconf->op_class)) {
1482 total_len += 4;
1483 if (hapd->iconf->he_6ghz_reg_pwr_type == HE_6GHZ_INDOOR_AP)
1484 total_len += 4;
1485 }
1486#endif /* CONFIG_IEEE80211AX */
1487
Hai Shalom60840252021-02-19 19:02:11 -08001488 head = os_zalloc(total_len);
1489 if (!head)
1490 return NULL;
1491
1492 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1493 WLAN_FC_STYPE_ACTION);
1494 os_memset(head->da, 0xff, ETH_ALEN);
1495 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1496 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1497
1498 head->u.action.category = WLAN_ACTION_PUBLIC;
1499 head->u.action.u.public_action.action = WLAN_PA_FILS_DISCOVERY;
1500
1501 pos = &head->u.action.u.public_action.variable[0];
1502
1503 /* FILS Discovery Information field */
1504
1505 /* FILS Discovery Frame Control */
1506 WPA_PUT_LE16(pos, ctl);
1507 pos += 2;
1508
1509 /* Hardware or low-level driver will fill in the Timestamp value */
1510 pos += 8;
1511
1512 /* Beacon Interval */
1513 WPA_PUT_LE16(pos, hapd->iconf->beacon_int);
1514 pos += 2;
1515
1516 /* Short SSID */
1517 WPA_PUT_LE32(pos, hapd->conf->ssid.short_ssid);
1518 pos += sizeof(hapd->conf->ssid.short_ssid);
1519
1520 /* Store position of FILS discovery information element Length field */
1521 length_pos = pos++;
1522
1523 /* FD Capability */
1524 WPA_PUT_LE16(pos, hostapd_fils_discovery_cap(hapd));
1525 pos += 2;
1526
1527 /* Operating Class - not present */
1528
1529 /* Primary Channel - not present */
1530
1531 /* AP Configuration Sequence Number - not present */
1532
1533 /* Access Network Options - not present */
1534
1535 /* FD RSN Information */
1536 if (ctl & FD_FRAME_CTL_RSN_INFO_PRESENT) {
1537 os_memcpy(pos, fd_rsn_info, sizeof(fd_rsn_info));
1538 pos += sizeof(fd_rsn_info);
1539 }
1540
1541 /* Channel Center Frequency Segment 1 - not present */
1542
1543 /* Mobility Domain */
1544 if (ctl & FD_FRAME_CTL_MD_PRESENT) {
1545 os_memcpy(pos, &mobility_domain[2], 3);
1546 pos += 3;
1547 }
1548
1549 /* Fill in the Length field value */
1550 *length_pos = pos - (length_pos + 1);
1551
Hai Shaloma20dcd72022-02-04 13:43:00 -08001552 pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_ACTION);
1553
Hai Shalom60840252021-02-19 19:02:11 -08001554 /* FILS Indication element */
1555 if (buf_len) {
1556 os_memcpy(pos, buf, buf_len);
1557 pos += buf_len;
1558 }
1559
Sunil Ravia04bd252022-05-02 22:54:18 -07001560 if (is_6ghz_op_class(hapd->iconf->op_class))
1561 pos = hostapd_eid_txpower_envelope(hapd, pos);
1562
Hai Shalom60840252021-02-19 19:02:11 -08001563 *len = pos - (u8 *) head;
1564 wpa_hexdump(MSG_DEBUG, "FILS Discovery frame template",
1565 head, pos - (u8 *) head);
1566 return (u8 *) head;
1567}
1568
1569
1570/* Configure FILS Discovery frame transmission parameters */
1571static u8 * hostapd_fils_discovery(struct hostapd_data *hapd,
1572 struct wpa_driver_ap_params *params)
1573{
1574 params->fd_max_int = hapd->conf->fils_discovery_max_int;
1575 if (is_6ghz_op_class(hapd->iconf->op_class) &&
1576 params->fd_max_int > FD_MAX_INTERVAL_6GHZ)
1577 params->fd_max_int = FD_MAX_INTERVAL_6GHZ;
1578
1579 params->fd_min_int = hapd->conf->fils_discovery_min_int;
1580 if (params->fd_min_int > params->fd_max_int)
1581 params->fd_min_int = params->fd_max_int;
1582
1583 if (params->fd_max_int)
1584 return hostapd_gen_fils_discovery(hapd,
1585 &params->fd_frame_tmpl_len);
1586
1587 return NULL;
1588}
1589
1590#endif /* CONFIG_FILS */
1591
1592
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001593int ieee802_11_build_ap_params(struct hostapd_data *hapd,
1594 struct wpa_driver_ap_params *params)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001595{
1596 struct ieee80211_mgmt *head = NULL;
1597 u8 *tail = NULL;
1598 size_t head_len = 0, tail_len = 0;
1599 u8 *resp = NULL;
1600 size_t resp_len = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001601#ifdef NEED_AP_MLME
1602 u16 capab_info;
Hai Shalomfdcde762020-04-02 11:19:20 -07001603 u8 *pos, *tailpos, *tailend, *csa_pos;
Sunil Ravi77d572f2023-01-17 23:58:31 +00001604 bool complete = false;
1605#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001606
Sunil Ravi77d572f2023-01-17 23:58:31 +00001607 os_memset(params, 0, sizeof(*params));
1608
1609#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001610#define BEACON_HEAD_BUF_SIZE 256
1611#define BEACON_TAIL_BUF_SIZE 512
1612 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
1613 tail_len = BEACON_TAIL_BUF_SIZE;
1614#ifdef CONFIG_WPS
1615 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
1616 tail_len += wpabuf_len(hapd->wps_beacon_ie);
1617#endif /* CONFIG_WPS */
1618#ifdef CONFIG_P2P
1619 if (hapd->p2p_beacon_ie)
1620 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
1621#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001622#ifdef CONFIG_FST
1623 if (hapd->iface->fst_ies)
1624 tail_len += wpabuf_len(hapd->iface->fst_ies);
1625#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001626 if (hapd->conf->vendor_elements)
1627 tail_len += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001628
1629#ifdef CONFIG_IEEE80211AC
1630 if (hapd->conf->vendor_vht) {
1631 tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
1632 2 + sizeof(struct ieee80211_vht_operation);
1633 }
1634#endif /* CONFIG_IEEE80211AC */
1635
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001636#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08001637 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001638 tail_len += 3 + sizeof(struct ieee80211_he_capabilities) +
Hai Shalom74f70d42019-02-11 14:42:39 -08001639 3 + sizeof(struct ieee80211_he_operation) +
Hai Shalom81f62d82019-07-22 12:10:00 -07001640 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
1641 3 + sizeof(struct ieee80211_spatial_reuse);
Sunil Ravia04bd252022-05-02 22:54:18 -07001642 if (is_6ghz_op_class(hapd->iconf->op_class)) {
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001643 tail_len += sizeof(struct ieee80211_he_6ghz_oper_info) +
1644 3 + sizeof(struct ieee80211_he_6ghz_band_cap);
Sunil Ravia04bd252022-05-02 22:54:18 -07001645 /* An additional Transmit Power Envelope element for
1646 * subordinate client */
1647 if (hapd->iconf->he_6ghz_reg_pwr_type ==
1648 HE_6GHZ_INDOOR_AP)
1649 tail_len += 4;
1650 }
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001651 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001652#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001653
Sunil Ravia04bd252022-05-02 22:54:18 -07001654#ifdef CONFIG_IEEE80211BE
1655 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
1656 tail_len += hostapd_eid_eht_capab_len(hapd, IEEE80211_MODE_AP);
1657 tail_len += 3 + sizeof(struct ieee80211_eht_operation);
1658 }
1659#endif /* CONFIG_IEEE80211BE */
1660
Sunil Ravi77d572f2023-01-17 23:58:31 +00001661 if (hapd->iconf->mbssid == ENHANCED_MBSSID_ENABLED &&
1662 hapd == hostapd_mbssid_get_tx_bss(hapd))
1663 tail_len += 5; /* Multiple BSSID Configuration element */
Hai Shaloma20dcd72022-02-04 13:43:00 -08001664 tail_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_BEACON);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001665 tail_len += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001666 tail_len += hostapd_eid_owe_trans_len(hapd);
Hai Shalomfdcde762020-04-02 11:19:20 -07001667 tail_len += hostapd_eid_dpp_cc_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001668
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001669 tailpos = tail = os_malloc(tail_len);
1670 if (head == NULL || tail == NULL) {
1671 wpa_printf(MSG_ERROR, "Failed to set beacon data");
1672 os_free(head);
1673 os_free(tail);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001674 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001675 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001676 tailend = tail + tail_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001677
1678 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1679 WLAN_FC_STYPE_BEACON);
1680 head->duration = host_to_le16(0);
1681 os_memset(head->da, 0xff, ETH_ALEN);
1682
1683 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1684 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1685 head->u.beacon.beacon_int =
1686 host_to_le16(hapd->iconf->beacon_int);
1687
1688 /* hardware or low-level driver will setup seq_ctrl and timestamp */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001689 capab_info = hostapd_own_capab_info(hapd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001690 head->u.beacon.capab_info = host_to_le16(capab_info);
1691 pos = &head->u.beacon.variable[0];
1692
1693 /* SSID */
1694 *pos++ = WLAN_EID_SSID;
1695 if (hapd->conf->ignore_broadcast_ssid == 2) {
1696 /* clear the data, but keep the correct length of the SSID */
1697 *pos++ = hapd->conf->ssid.ssid_len;
1698 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
1699 pos += hapd->conf->ssid.ssid_len;
1700 } else if (hapd->conf->ignore_broadcast_ssid) {
1701 *pos++ = 0; /* empty SSID */
1702 } else {
1703 *pos++ = hapd->conf->ssid.ssid_len;
1704 os_memcpy(pos, hapd->conf->ssid.ssid,
1705 hapd->conf->ssid.ssid_len);
1706 pos += hapd->conf->ssid.ssid_len;
1707 }
1708
1709 /* Supported rates */
1710 pos = hostapd_eid_supp_rates(hapd, pos);
1711
1712 /* DS Params */
1713 pos = hostapd_eid_ds_params(hapd, pos);
1714
1715 head_len = pos - (u8 *) head;
1716
Hai Shalomfdcde762020-04-02 11:19:20 -07001717 tailpos = hostapd_eid_country(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001718
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001719 /* Power Constraint element */
1720 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
1721
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001722 /* CSA IE */
1723 csa_pos = hostapd_eid_csa(hapd, tailpos);
1724 if (csa_pos != tailpos)
1725 hapd->cs_c_off_beacon = csa_pos - tail - 1;
1726 tailpos = csa_pos;
1727
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001728 /* ERP Information element */
1729 tailpos = hostapd_eid_erp_info(hapd, tailpos);
1730
1731 /* Extended supported rates */
1732 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
1733
Hai Shalomfdcde762020-04-02 11:19:20 -07001734 tailpos = hostapd_get_rsne(hapd, tailpos, tailend - tailpos);
1735 tailpos = hostapd_eid_bss_load(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001736 tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
Hai Shalomfdcde762020-04-02 11:19:20 -07001737 tailend - tailpos);
1738 tailpos = hostapd_get_mde(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001739
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001740 /* eCSA IE */
1741 csa_pos = hostapd_eid_ecsa(hapd, tailpos);
1742 if (csa_pos != tailpos)
1743 hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1;
1744 tailpos = csa_pos;
1745
1746 tailpos = hostapd_eid_supported_op_classes(hapd, tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001747 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
1748 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001749
Sunil Ravi77d572f2023-01-17 23:58:31 +00001750 if (hapd->iconf->mbssid && hapd->iconf->num_bss > 1) {
1751 if (ieee802_11_build_ap_params_mbssid(hapd, params)) {
1752 os_free(head);
1753 os_free(tail);
1754 wpa_printf(MSG_ERROR,
1755 "MBSSID: Failed to set beacon data");
1756 return -1;
1757 }
1758 complete = hapd->iconf->mbssid == MBSSID_ENABLED ||
1759 (hapd->iconf->mbssid == ENHANCED_MBSSID_ENABLED &&
1760 params->mbssid_elem_count == 1);
1761 }
1762
1763 tailpos = hostapd_eid_ext_capab(hapd, tailpos, complete);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001764
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001765 /*
1766 * TODO: Time Advertisement element should only be included in some
1767 * DTIM Beacon frames.
1768 */
1769 tailpos = hostapd_eid_time_adv(hapd, tailpos);
1770
1771 tailpos = hostapd_eid_interworking(hapd, tailpos);
1772 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
1773 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001774
1775#ifdef CONFIG_FST
1776 if (hapd->iface->fst_ies) {
1777 os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies),
1778 wpabuf_len(hapd->iface->fst_ies));
1779 tailpos += wpabuf_len(hapd->iface->fst_ies);
1780 }
1781#endif /* CONFIG_FST */
1782
Dmitry Shmidt04949592012-07-19 12:16:46 -07001783#ifdef CONFIG_IEEE80211AC
Hai Shalom60840252021-02-19 19:02:11 -08001784 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
1785 !is_6ghz_op_class(hapd->iconf->op_class)) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -07001786 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001787 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08001788 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001789 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001790#endif /* CONFIG_IEEE80211AC */
1791
Hai Shalom60840252021-02-19 19:02:11 -08001792#ifdef CONFIG_IEEE80211AX
1793 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax &&
1794 is_6ghz_op_class(hapd->iconf->op_class))
1795 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
1796#endif /* CONFIG_IEEE80211AX */
1797
Hai Shaloma20dcd72022-02-04 13:43:00 -08001798 tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos);
Hai Shalom899fcc72020-10-19 14:38:18 -07001799
Hai Shaloma20dcd72022-02-04 13:43:00 -08001800 tailpos = hostapd_eid_rnr(hapd, tailpos, WLAN_FC_STYPE_BEACON);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001801 tailpos = hostapd_eid_fils_indic(hapd, tailpos, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -07001802 tailpos = hostapd_get_rsnxe(hapd, tailpos, tailend - tailpos);
Sunil Ravi77d572f2023-01-17 23:58:31 +00001803 tailpos = hostapd_eid_mbssid_config(hapd, tailpos,
1804 params->mbssid_elem_count);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001805
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001806#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08001807 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Sunil Ravia04bd252022-05-02 22:54:18 -07001808 u8 *cca_pos;
1809
Hai Shalom81f62d82019-07-22 12:10:00 -07001810 tailpos = hostapd_eid_he_capab(hapd, tailpos,
1811 IEEE80211_MODE_AP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001812 tailpos = hostapd_eid_he_operation(hapd, tailpos);
Sunil Ravia04bd252022-05-02 22:54:18 -07001813
1814 /* BSS Color Change Announcement element */
1815 cca_pos = hostapd_eid_cca(hapd, tailpos);
1816 if (cca_pos != tailpos)
1817 hapd->cca_c_off_beacon = cca_pos - tail - 2;
1818 tailpos = cca_pos;
1819
Hai Shalom81f62d82019-07-22 12:10:00 -07001820 tailpos = hostapd_eid_spatial_reuse(hapd, tailpos);
Hai Shalomfdcde762020-04-02 11:19:20 -07001821 tailpos = hostapd_eid_he_mu_edca_parameter_set(hapd, tailpos);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001822 tailpos = hostapd_eid_he_6ghz_band_cap(hapd, tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001823 }
1824#endif /* CONFIG_IEEE80211AX */
1825
Sunil Ravia04bd252022-05-02 22:54:18 -07001826#ifdef CONFIG_IEEE80211BE
1827 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
1828 tailpos = hostapd_eid_eht_capab(hapd, tailpos,
1829 IEEE80211_MODE_AP);
1830 tailpos = hostapd_eid_eht_operation(hapd, tailpos);
1831 }
1832#endif /* CONFIG_IEEE80211BE */
1833
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001834#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001835 if (hapd->conf->vendor_vht)
1836 tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001837#endif /* CONFIG_IEEE80211AC */
1838
Hai Shalomfdcde762020-04-02 11:19:20 -07001839 /* WPA / OSEN */
1840 tailpos = hostapd_get_wpa_ie(hapd, tailpos, tailend - tailpos);
1841 tailpos = hostapd_get_osen_ie(hapd, tailpos, tailend - tailpos);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001842
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001843 /* Wi-Fi Alliance WMM */
1844 tailpos = hostapd_eid_wmm(hapd, tailpos);
1845
1846#ifdef CONFIG_WPS
1847 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
1848 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
1849 wpabuf_len(hapd->wps_beacon_ie));
1850 tailpos += wpabuf_len(hapd->wps_beacon_ie);
1851 }
1852#endif /* CONFIG_WPS */
1853
1854#ifdef CONFIG_P2P
1855 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
1856 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
1857 wpabuf_len(hapd->p2p_beacon_ie));
1858 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
1859 }
1860#endif /* CONFIG_P2P */
1861#ifdef CONFIG_P2P_MANAGER
1862 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
1863 P2P_MANAGE)
1864 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
1865#endif /* CONFIG_P2P_MANAGER */
1866
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001867#ifdef CONFIG_HS20
1868 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
1869#endif /* CONFIG_HS20 */
1870
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001871 tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001872 tailpos = hostapd_eid_owe_trans(hapd, tailpos,
1873 tail + tail_len - tailpos);
Hai Shalomfdcde762020-04-02 11:19:20 -07001874 tailpos = hostapd_eid_dpp_cc(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001875
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001876 if (hapd->conf->vendor_elements) {
1877 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
1878 wpabuf_len(hapd->conf->vendor_elements));
1879 tailpos += wpabuf_len(hapd->conf->vendor_elements);
1880 }
1881
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001882 tail_len = tailpos > tail ? tailpos - tail : 0;
1883
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001884 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
1885#endif /* NEED_AP_MLME */
1886
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001887 params->head = (u8 *) head;
1888 params->head_len = head_len;
1889 params->tail = tail;
1890 params->tail_len = tail_len;
1891 params->proberesp = resp;
1892 params->proberesp_len = resp_len;
1893 params->dtim_period = hapd->conf->dtim_period;
1894 params->beacon_int = hapd->iconf->beacon_int;
1895 params->basic_rates = hapd->iface->basic_rates;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001896 params->beacon_rate = hapd->iconf->beacon_rate;
1897 params->rate_type = hapd->iconf->rate_type;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001898 params->ssid = hapd->conf->ssid.ssid;
1899 params->ssid_len = hapd->conf->ssid.ssid_len;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001900 if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
1901 (WPA_PROTO_WPA | WPA_PROTO_RSN))
1902 params->pairwise_ciphers = hapd->conf->wpa_pairwise |
1903 hapd->conf->rsn_pairwise;
1904 else if (hapd->conf->wpa & WPA_PROTO_RSN)
1905 params->pairwise_ciphers = hapd->conf->rsn_pairwise;
1906 else if (hapd->conf->wpa & WPA_PROTO_WPA)
1907 params->pairwise_ciphers = hapd->conf->wpa_pairwise;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001908 params->group_cipher = hapd->conf->wpa_group;
1909 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
1910 params->auth_algs = hapd->conf->auth_algs;
1911 params->wpa_version = hapd->conf->wpa;
Hai Shalomfdcde762020-04-02 11:19:20 -07001912 params->privacy = hapd->conf->wpa;
1913#ifdef CONFIG_WEP
1914 params->privacy |= hapd->conf->ssid.wep.keys_set ||
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001915 (hapd->conf->ieee802_1x &&
1916 (hapd->conf->default_wep_key_len ||
1917 hapd->conf->individual_wep_key_len));
Hai Shalomfdcde762020-04-02 11:19:20 -07001918#endif /* CONFIG_WEP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001919 switch (hapd->conf->ignore_broadcast_ssid) {
1920 case 0:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001921 params->hide_ssid = NO_SSID_HIDING;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001922 break;
1923 case 1:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001924 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001925 break;
1926 case 2:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001927 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001928 break;
1929 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001930 params->isolate = hapd->conf->isolate;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001931#ifdef NEED_AP_MLME
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001932 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001933 ERP_INFO_USE_PROTECTION);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001934 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001935 hapd->iconf->preamble == SHORT_PREAMBLE;
1936 if (hapd->iface->current_mode &&
1937 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001938 params->short_slot_time =
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001939 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
1940 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001941 params->short_slot_time = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001942 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001943 params->ht_opmode = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001944 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001945 params->ht_opmode = hapd->iface->ht_op_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001946#endif /* NEED_AP_MLME */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001947 params->interworking = hapd->conf->interworking;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001948 if (hapd->conf->interworking &&
1949 !is_zero_ether_addr(hapd->conf->hessid))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001950 params->hessid = hapd->conf->hessid;
1951 params->access_network_type = hapd->conf->access_network_type;
1952 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001953#ifdef CONFIG_P2P
1954 params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
1955#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001956#ifdef CONFIG_HS20
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001957 params->disable_dgaf = hapd->conf->disable_dgaf;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001958 if (hapd->conf->osen) {
1959 params->privacy = 1;
1960 params->osen = 1;
1961 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001962#endif /* CONFIG_HS20 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001963 params->multicast_to_unicast = hapd->conf->multicast_to_unicast;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001964 params->pbss = hapd->conf->pbss;
Hai Shalom74f70d42019-02-11 14:42:39 -08001965
1966 if (hapd->conf->ftm_responder) {
1967 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_FTM_RESPONDER) {
1968 params->ftm_responder = 1;
1969 params->lci = hapd->iface->conf->lci;
1970 params->civic = hapd->iface->conf->civic;
1971 } else {
1972 wpa_printf(MSG_WARNING,
1973 "Not configuring FTM responder as the driver doesn't advertise support for it");
1974 }
1975 }
1976
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001977 return 0;
1978}
1979
1980
1981void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
1982{
1983 os_free(params->tail);
1984 params->tail = NULL;
1985 os_free(params->head);
1986 params->head = NULL;
1987 os_free(params->proberesp);
1988 params->proberesp = NULL;
Sunil Ravi77d572f2023-01-17 23:58:31 +00001989 os_free(params->mbssid_elem);
1990 params->mbssid_elem = NULL;
1991 os_free(params->mbssid_elem_offset);
1992 params->mbssid_elem_offset = NULL;
Hai Shalom60840252021-02-19 19:02:11 -08001993#ifdef CONFIG_FILS
1994 os_free(params->fd_frame_tmpl);
1995 params->fd_frame_tmpl = NULL;
1996#endif /* CONFIG_FILS */
1997#ifdef CONFIG_IEEE80211AX
1998 os_free(params->unsol_bcast_probe_resp_tmpl);
1999 params->unsol_bcast_probe_resp_tmpl = NULL;
2000#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002001}
2002
2003
Hai Shaloma20dcd72022-02-04 13:43:00 -08002004static int __ieee802_11_set_beacon(struct hostapd_data *hapd)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002005{
2006 struct wpa_driver_ap_params params;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002007 struct hostapd_freq_params freq;
2008 struct hostapd_iface *iface = hapd->iface;
2009 struct hostapd_config *iconf = iface->conf;
Hai Shalom81f62d82019-07-22 12:10:00 -07002010 struct hostapd_hw_modes *cmode = iface->current_mode;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002011 struct wpabuf *beacon, *proberesp, *assocresp;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002012 int res, ret = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002013
Hai Shaloma20dcd72022-02-04 13:43:00 -08002014 if (!hapd->drv_priv) {
2015 wpa_printf(MSG_ERROR, "Interface is disabled");
2016 return -1;
2017 }
2018
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002019 if (hapd->csa_in_progress) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002020 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002021 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002022 }
2023
2024 hapd->beacon_set_done = 1;
2025
2026 if (ieee802_11_build_ap_params(hapd, &params) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002027 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002028
2029 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
2030 0)
2031 goto fail;
2032
2033 params.beacon_ies = beacon;
2034 params.proberesp_ies = proberesp;
2035 params.assocresp_ies = assocresp;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002036 params.reenable = hapd->reenable_beacon;
Hai Shalomc3565922019-10-28 11:58:20 -07002037#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08002038 params.he_spr_ctrl = hapd->iface->conf->spr.sr_control;
2039 params.he_spr_non_srg_obss_pd_max_offset =
2040 hapd->iface->conf->spr.non_srg_obss_pd_max_offset;
Hai Shalomc3565922019-10-28 11:58:20 -07002041 params.he_spr_srg_obss_pd_min_offset =
2042 hapd->iface->conf->spr.srg_obss_pd_min_offset;
2043 params.he_spr_srg_obss_pd_max_offset =
2044 hapd->iface->conf->spr.srg_obss_pd_max_offset;
Hai Shalom60840252021-02-19 19:02:11 -08002045 os_memcpy(params.he_spr_bss_color_bitmap,
2046 hapd->iface->conf->spr.srg_bss_color_bitmap, 8);
2047 os_memcpy(params.he_spr_partial_bssid_bitmap,
2048 hapd->iface->conf->spr.srg_partial_bssid_bitmap, 8);
Hai Shalomfdcde762020-04-02 11:19:20 -07002049 params.he_bss_color_disabled =
2050 hapd->iface->conf->he_op.he_bss_color_disabled;
2051 params.he_bss_color_partial =
2052 hapd->iface->conf->he_op.he_bss_color_partial;
2053 params.he_bss_color = hapd->iface->conf->he_op.he_bss_color;
2054 params.twt_responder = hostapd_get_he_twt_responder(hapd,
2055 IEEE80211_MODE_AP);
Hai Shalom60840252021-02-19 19:02:11 -08002056 params.unsol_bcast_probe_resp_tmpl =
2057 hostapd_unsol_bcast_probe_resp(hapd, &params);
Hai Shalomc3565922019-10-28 11:58:20 -07002058#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002059 hapd->reenable_beacon = 0;
Hai Shalom60840252021-02-19 19:02:11 -08002060#ifdef CONFIG_SAE
2061 params.sae_pwe = hapd->conf->sae_pwe;
2062#endif /* CONFIG_SAE */
2063
2064#ifdef CONFIG_FILS
2065 params.fd_frame_tmpl = hostapd_fils_discovery(hapd, &params);
2066#endif /* CONFIG_FILS */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002067
Hai Shalom81f62d82019-07-22 12:10:00 -07002068 if (cmode &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002069 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
Hai Shalomc3565922019-10-28 11:58:20 -07002070 iconf->channel, iconf->enable_edmg,
2071 iconf->edmg_channel, iconf->ieee80211n,
Hai Shalom81f62d82019-07-22 12:10:00 -07002072 iconf->ieee80211ac, iconf->ieee80211ax,
Sunil Ravia04bd252022-05-02 22:54:18 -07002073 iconf->ieee80211be,
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002074 iconf->secondary_channel,
Hai Shalom81f62d82019-07-22 12:10:00 -07002075 hostapd_get_oper_chwidth(iconf),
2076 hostapd_get_oper_centr_freq_seg0_idx(iconf),
2077 hostapd_get_oper_centr_freq_seg1_idx(iconf),
2078 cmode->vht_capab,
Sunil Ravia04bd252022-05-02 22:54:18 -07002079 &cmode->he_capab[IEEE80211_MODE_AP],
2080 &cmode->eht_capab[IEEE80211_MODE_AP]) == 0)
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002081 params.freq = &freq;
2082
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002083 res = hostapd_drv_set_ap(hapd, &params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002084 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002085 if (res)
2086 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
2087 else
2088 ret = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002089fail:
2090 ieee802_11_free_ap_params(&params);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002091 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002092}
2093
2094
Hai Shaloma20dcd72022-02-04 13:43:00 -08002095int ieee802_11_set_beacon(struct hostapd_data *hapd)
2096{
2097 struct hostapd_iface *iface = hapd->iface;
2098 int ret;
2099 size_t i, j;
2100 bool is_6g;
2101
2102 ret = __ieee802_11_set_beacon(hapd);
2103 if (ret != 0)
2104 return ret;
2105
2106 if (!iface->interfaces || iface->interfaces->count <= 1)
2107 return 0;
2108
2109 /* Update Beacon frames in case of 6 GHz colocation */
2110 is_6g = is_6ghz_op_class(iface->conf->op_class);
2111 for (j = 0; j < iface->interfaces->count; j++) {
2112 struct hostapd_iface *colocated;
2113
2114 colocated = iface->interfaces->iface[j];
2115 if (colocated == iface || !colocated || !colocated->conf)
2116 continue;
2117
2118 if (is_6g == is_6ghz_op_class(colocated->conf->op_class))
2119 continue;
2120
2121 for (i = 0; i < colocated->num_bss; i++) {
2122 if (colocated->bss[i] && colocated->bss[i]->started)
2123 __ieee802_11_set_beacon(colocated->bss[i]);
2124 }
2125 }
2126
2127 return 0;
2128}
2129
2130
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002131int ieee802_11_set_beacons(struct hostapd_iface *iface)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002132{
2133 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002134 int ret = 0;
2135
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08002136 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002137 if (iface->bss[i]->started &&
2138 ieee802_11_set_beacon(iface->bss[i]) < 0)
2139 ret = -1;
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08002140 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002141
2142 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002143}
2144
Dmitry Shmidt04949592012-07-19 12:16:46 -07002145
2146/* only update beacons if started */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002147int ieee802_11_update_beacons(struct hostapd_iface *iface)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002148{
2149 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002150 int ret = 0;
2151
2152 for (i = 0; i < iface->num_bss; i++) {
2153 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
2154 ieee802_11_set_beacon(iface->bss[i]) < 0)
2155 ret = -1;
2156 }
2157
2158 return ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002159}
2160
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002161#endif /* CONFIG_NATIVE_WINDOWS */