blob: 86765705ab3272cb8c52e4090c3cfd5b6fa1b56b [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
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800465static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800466 const struct ieee80211_mgmt *req,
Sunil8cd6f4d2022-06-28 18:40:46 +0000467 int is_p2p, size_t *resp_len,
468 bool bcast_probe_resp)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800469{
470 struct ieee80211_mgmt *resp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800471 u8 *pos, *epos, *csa_pos;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800472 size_t buflen;
473
474#define MAX_PROBERESP_LEN 768
475 buflen = MAX_PROBERESP_LEN;
476#ifdef CONFIG_WPS
477 if (hapd->wps_probe_resp_ie)
478 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
479#endif /* CONFIG_WPS */
480#ifdef CONFIG_P2P
481 if (hapd->p2p_probe_resp_ie)
482 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
483#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800484#ifdef CONFIG_FST
485 if (hapd->iface->fst_ies)
486 buflen += wpabuf_len(hapd->iface->fst_ies);
487#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700488 if (hapd->conf->vendor_elements)
489 buflen += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800490 if (hapd->conf->vendor_vht) {
491 buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
492 2 + sizeof(struct ieee80211_vht_operation);
493 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800494
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800495#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -0800496 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700497 buflen += 3 + sizeof(struct ieee80211_he_capabilities) +
Hai Shalom74f70d42019-02-11 14:42:39 -0800498 3 + sizeof(struct ieee80211_he_operation) +
Hai Shalom81f62d82019-07-22 12:10:00 -0700499 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
500 3 + sizeof(struct ieee80211_spatial_reuse);
Sunil Ravia04bd252022-05-02 22:54:18 -0700501 if (is_6ghz_op_class(hapd->iconf->op_class)) {
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700502 buflen += sizeof(struct ieee80211_he_6ghz_oper_info) +
503 3 + sizeof(struct ieee80211_he_6ghz_band_cap);
Sunil Ravia04bd252022-05-02 22:54:18 -0700504 /* An additional Transmit Power Envelope element for
505 * subordinate client */
506 if (hapd->iconf->he_6ghz_reg_pwr_type ==
507 HE_6GHZ_INDOOR_AP)
508 buflen += 4;
509 }
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800510 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700511#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800512
Sunil Ravia04bd252022-05-02 22:54:18 -0700513#ifdef CONFIG_IEEE80211BE
514 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
515 buflen += hostapd_eid_eht_capab_len(hapd, IEEE80211_MODE_AP);
516 buflen += 3 + sizeof(struct ieee80211_eht_operation);
517 }
518#endif /* CONFIG_IEEE80211BE */
519
Hai Shaloma20dcd72022-02-04 13:43:00 -0800520 buflen += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_PROBE_RESP);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800521 buflen += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700522 buflen += hostapd_eid_owe_trans_len(hapd);
Hai Shalomfdcde762020-04-02 11:19:20 -0700523 buflen += hostapd_eid_dpp_cc_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800524
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800525 resp = os_zalloc(buflen);
526 if (resp == NULL)
527 return NULL;
528
529 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
530
531 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
532 WLAN_FC_STYPE_PROBE_RESP);
533 if (req)
534 os_memcpy(resp->da, req->sa, ETH_ALEN);
Sunil8cd6f4d2022-06-28 18:40:46 +0000535 else if (bcast_probe_resp)
536 os_memset(resp->da, 0xff, ETH_ALEN);
537
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800538 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
539
540 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
541 resp->u.probe_resp.beacon_int =
542 host_to_le16(hapd->iconf->beacon_int);
543
544 /* hardware or low-level driver will setup seq_ctrl and timestamp */
545 resp->u.probe_resp.capab_info =
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700546 host_to_le16(hostapd_own_capab_info(hapd));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800547
548 pos = resp->u.probe_resp.variable;
549 *pos++ = WLAN_EID_SSID;
550 *pos++ = hapd->conf->ssid.ssid_len;
551 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
552 pos += hapd->conf->ssid.ssid_len;
553
554 /* Supported rates */
555 pos = hostapd_eid_supp_rates(hapd, pos);
556
557 /* DS Params */
558 pos = hostapd_eid_ds_params(hapd, pos);
559
560 pos = hostapd_eid_country(hapd, pos, epos - pos);
561
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800562 /* Power Constraint element */
563 pos = hostapd_eid_pwr_constraint(hapd, pos);
564
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800565 /* CSA IE */
566 csa_pos = hostapd_eid_csa(hapd, pos);
567 if (csa_pos != pos)
568 hapd->cs_c_off_proberesp = csa_pos - (u8 *) resp - 1;
569 pos = csa_pos;
570
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800571 /* ERP Information element */
572 pos = hostapd_eid_erp_info(hapd, pos);
573
574 /* Extended supported rates */
575 pos = hostapd_eid_ext_supp_rates(hapd, pos);
576
Hai Shalomfdcde762020-04-02 11:19:20 -0700577 pos = hostapd_get_rsne(hapd, pos, epos - pos);
Dmitry Shmidt051af732013-10-22 13:52:46 -0700578 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800579 pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700580 pos = hostapd_get_mde(hapd, pos, epos - pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800581
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800582 /* eCSA IE */
583 csa_pos = hostapd_eid_ecsa(hapd, pos);
584 if (csa_pos != pos)
585 hapd->cs_c_off_ecsa_proberesp = csa_pos - (u8 *) resp - 1;
586 pos = csa_pos;
587
588 pos = hostapd_eid_supported_op_classes(hapd, pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800589 pos = hostapd_eid_ht_capabilities(hapd, pos);
590 pos = hostapd_eid_ht_operation(hapd, pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800591
592 pos = hostapd_eid_ext_capab(hapd, pos);
593
594 pos = hostapd_eid_time_adv(hapd, pos);
595 pos = hostapd_eid_time_zone(hapd, pos);
596
597 pos = hostapd_eid_interworking(hapd, pos);
598 pos = hostapd_eid_adv_proto(hapd, pos);
599 pos = hostapd_eid_roaming_consortium(hapd, pos);
600
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800601#ifdef CONFIG_FST
602 if (hapd->iface->fst_ies) {
603 os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies),
604 wpabuf_len(hapd->iface->fst_ies));
605 pos += wpabuf_len(hapd->iface->fst_ies);
606 }
607#endif /* CONFIG_FST */
608
Dmitry Shmidt04949592012-07-19 12:16:46 -0700609#ifdef CONFIG_IEEE80211AC
Hai Shalomc3565922019-10-28 11:58:20 -0700610 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
611 !is_6ghz_op_class(hapd->iconf->op_class)) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700612 pos = hostapd_eid_vht_capabilities(hapd, pos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800613 pos = hostapd_eid_vht_operation(hapd, pos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800614 pos = hostapd_eid_txpower_envelope(hapd, pos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800615 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800616#endif /* CONFIG_IEEE80211AC */
617
Hai Shalom60840252021-02-19 19:02:11 -0800618#ifdef CONFIG_IEEE80211AX
619 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax &&
620 is_6ghz_op_class(hapd->iconf->op_class))
621 pos = hostapd_eid_txpower_envelope(hapd, pos);
622#endif /* CONFIG_IEEE80211AX */
623
Hai Shaloma20dcd72022-02-04 13:43:00 -0800624 pos = hostapd_eid_wb_chsw_wrapper(hapd, pos);
Hai Shalom899fcc72020-10-19 14:38:18 -0700625
Hai Shaloma20dcd72022-02-04 13:43:00 -0800626 pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_PROBE_RESP);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800627 pos = hostapd_eid_fils_indic(hapd, pos, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -0700628 pos = hostapd_get_rsnxe(hapd, pos, epos - pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800629
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700630#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -0800631 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700632 u8 *cca_pos;
633
Hai Shalom81f62d82019-07-22 12:10:00 -0700634 pos = hostapd_eid_he_capab(hapd, pos, IEEE80211_MODE_AP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700635 pos = hostapd_eid_he_operation(hapd, pos);
Sunil Ravia04bd252022-05-02 22:54:18 -0700636
637 /* BSS Color Change Announcement element */
638 cca_pos = hostapd_eid_cca(hapd, pos);
639 if (cca_pos != pos)
640 hapd->cca_c_off_proberesp = cca_pos - (u8 *) resp - 2;
641 pos = cca_pos;
642
Hai Shalom81f62d82019-07-22 12:10:00 -0700643 pos = hostapd_eid_spatial_reuse(hapd, pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700644 pos = hostapd_eid_he_mu_edca_parameter_set(hapd, pos);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700645 pos = hostapd_eid_he_6ghz_band_cap(hapd, pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700646 }
647#endif /* CONFIG_IEEE80211AX */
648
Sunil Ravia04bd252022-05-02 22:54:18 -0700649#ifdef CONFIG_IEEE80211BE
650 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
651 pos = hostapd_eid_eht_capab(hapd, pos, IEEE80211_MODE_AP);
652 pos = hostapd_eid_eht_operation(hapd, pos);
653 }
654#endif /* CONFIG_IEEE80211BE */
655
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800656#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800657 if (hapd->conf->vendor_vht)
658 pos = hostapd_eid_vendor_vht(hapd, pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700659#endif /* CONFIG_IEEE80211AC */
660
Hai Shalomfdcde762020-04-02 11:19:20 -0700661 /* WPA / OSEN */
662 pos = hostapd_get_wpa_ie(hapd, pos, epos - pos);
663 pos = hostapd_get_osen_ie(hapd, pos, epos - pos);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800664
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800665 /* Wi-Fi Alliance WMM */
666 pos = hostapd_eid_wmm(hapd, pos);
667
668#ifdef CONFIG_WPS
669 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
670 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
671 wpabuf_len(hapd->wps_probe_resp_ie));
672 pos += wpabuf_len(hapd->wps_probe_resp_ie);
673 }
674#endif /* CONFIG_WPS */
675
676#ifdef CONFIG_P2P
677 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
678 hapd->p2p_probe_resp_ie) {
679 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
680 wpabuf_len(hapd->p2p_probe_resp_ie));
681 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
682 }
683#endif /* CONFIG_P2P */
684#ifdef CONFIG_P2P_MANAGER
685 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
686 P2P_MANAGE)
687 pos = hostapd_eid_p2p_manage(hapd, pos);
688#endif /* CONFIG_P2P_MANAGER */
689
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700690#ifdef CONFIG_HS20
691 pos = hostapd_eid_hs20_indication(hapd, pos);
692#endif /* CONFIG_HS20 */
693
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800694 pos = hostapd_eid_mbo(hapd, pos, (u8 *) resp + buflen - pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700695 pos = hostapd_eid_owe_trans(hapd, pos, (u8 *) resp + buflen - pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700696 pos = hostapd_eid_dpp_cc(hapd, pos, (u8 *) resp + buflen - pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800697
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700698 if (hapd->conf->vendor_elements) {
699 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
700 wpabuf_len(hapd->conf->vendor_elements));
701 pos += wpabuf_len(hapd->conf->vendor_elements);
702 }
703
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800704 *resp_len = pos - (u8 *) resp;
705 return (u8 *) resp;
706}
707
708
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800709enum ssid_match_result {
710 NO_SSID_MATCH,
711 EXACT_SSID_MATCH,
Hai Shaloma20dcd72022-02-04 13:43:00 -0800712 WILDCARD_SSID_MATCH,
713 CO_LOCATED_SSID_MATCH,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800714};
715
716static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
717 const u8 *ssid, size_t ssid_len,
718 const u8 *ssid_list,
Hai Shalomfdcde762020-04-02 11:19:20 -0700719 size_t ssid_list_len,
720 const u8 *short_ssid_list,
721 size_t short_ssid_list_len)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800722{
723 const u8 *pos, *end;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800724 struct hostapd_iface *iface = hapd->iface;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800725 int wildcard = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800726 size_t i, j;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800727
728 if (ssid_len == 0)
729 wildcard = 1;
730 if (ssid_len == hapd->conf->ssid.ssid_len &&
731 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
732 return EXACT_SSID_MATCH;
733
Hai Shalomfdcde762020-04-02 11:19:20 -0700734 if (ssid_list) {
735 pos = ssid_list;
736 end = ssid_list + ssid_list_len;
737 while (end - pos >= 2) {
738 if (2 + pos[1] > end - pos)
739 break;
740 if (pos[1] == 0)
741 wildcard = 1;
742 if (pos[1] == hapd->conf->ssid.ssid_len &&
743 os_memcmp(pos + 2, hapd->conf->ssid.ssid,
744 pos[1]) == 0)
745 return EXACT_SSID_MATCH;
746 pos += 2 + pos[1];
747 }
748 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800749
Hai Shalomfdcde762020-04-02 11:19:20 -0700750 if (short_ssid_list) {
751 pos = short_ssid_list;
752 end = short_ssid_list + short_ssid_list_len;
753 while (end - pos >= 4) {
754 if (hapd->conf->ssid.short_ssid == WPA_GET_LE32(pos))
755 return EXACT_SSID_MATCH;
756 pos += 4;
757 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800758 }
759
Hai Shaloma20dcd72022-02-04 13:43:00 -0800760 if (wildcard)
761 return WILDCARD_SSID_MATCH;
762
763 if (!iface->interfaces || iface->interfaces->count <= 1 ||
764 is_6ghz_op_class(hapd->iconf->op_class))
765 return NO_SSID_MATCH;
766
767 for (i = 0; i < iface->interfaces->count; i++) {
768 struct hostapd_iface *colocated;
769
770 colocated = iface->interfaces->iface[i];
771
772 if (colocated == iface ||
773 !is_6ghz_op_class(colocated->conf->op_class))
774 continue;
775
776 for (j = 0; j < colocated->num_bss; j++) {
777 struct hostapd_bss_config *conf;
778
779 conf = colocated->bss[j]->conf;
780 if (ssid_len == conf->ssid.ssid_len &&
781 os_memcmp(ssid, conf->ssid.ssid, ssid_len) == 0)
782 return CO_LOCATED_SSID_MATCH;
783 }
784 }
785
786 return NO_SSID_MATCH;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800787}
788
789
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800790void sta_track_expire(struct hostapd_iface *iface, int force)
791{
792 struct os_reltime now;
793 struct hostapd_sta_info *info;
794
795 if (!iface->num_sta_seen)
796 return;
797
798 os_get_reltime(&now);
799 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
800 list))) {
801 if (!force &&
802 !os_reltime_expired(&now, &info->last_seen,
803 iface->conf->track_sta_max_age))
804 break;
805 force = 0;
806
807 wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
808 MACSTR, iface->bss[0]->conf->iface,
809 MAC2STR(info->addr));
810 dl_list_del(&info->list);
811 iface->num_sta_seen--;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700812 sta_track_del(info);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800813 }
814}
815
816
817static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
818 const u8 *addr)
819{
820 struct hostapd_sta_info *info;
821
822 dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
823 if (os_memcmp(addr, info->addr, ETH_ALEN) == 0)
824 return info;
825
826 return NULL;
827}
828
829
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800830void sta_track_add(struct hostapd_iface *iface, const u8 *addr, int ssi_signal)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800831{
832 struct hostapd_sta_info *info;
833
834 info = sta_track_get(iface, addr);
835 if (info) {
836 /* Move the most recent entry to the end of the list */
837 dl_list_del(&info->list);
838 dl_list_add_tail(&iface->sta_seen, &info->list);
839 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800840 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800841 return;
842 }
843
844 /* Add a new entry */
845 info = os_zalloc(sizeof(*info));
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700846 if (info == NULL)
847 return;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800848 os_memcpy(info->addr, addr, ETH_ALEN);
849 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800850 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800851
852 if (iface->num_sta_seen >= iface->conf->track_sta_max_num) {
853 /* Expire oldest entry to make room for a new one */
854 sta_track_expire(iface, 1);
855 }
856
857 wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
858 MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr));
859 dl_list_add_tail(&iface->sta_seen, &info->list);
860 iface->num_sta_seen++;
861}
862
863
864struct hostapd_data *
865sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
866 const char *ifname)
867{
868 struct hapd_interfaces *interfaces = iface->interfaces;
869 size_t i, j;
870
871 for (i = 0; i < interfaces->count; i++) {
872 struct hostapd_data *hapd = NULL;
873
874 iface = interfaces->iface[i];
875 for (j = 0; j < iface->num_bss; j++) {
876 hapd = iface->bss[j];
877 if (os_strcmp(ifname, hapd->conf->iface) == 0)
878 break;
879 hapd = NULL;
880 }
881
882 if (hapd && sta_track_get(iface, addr))
883 return hapd;
884 }
885
886 return NULL;
887}
888
889
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700890#ifdef CONFIG_TAXONOMY
891void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr,
892 struct wpabuf **probe_ie_taxonomy)
893{
894 struct hostapd_sta_info *info;
895
896 info = sta_track_get(iface, addr);
897 if (!info)
898 return;
899
900 wpabuf_free(*probe_ie_taxonomy);
901 *probe_ie_taxonomy = info->probe_ie_taxonomy;
902 info->probe_ie_taxonomy = NULL;
903}
904#endif /* CONFIG_TAXONOMY */
905
906
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700907void handle_probe_req(struct hostapd_data *hapd,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700908 const struct ieee80211_mgmt *mgmt, size_t len,
909 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700910{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800911 u8 *resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700912 struct ieee802_11_elems elems;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700913 const u8 *ie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800914 size_t ie_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800915 size_t i, resp_len;
916 int noack;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800917 enum ssid_match_result res;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800918 int ret;
919 u16 csa_offs[2];
920 size_t csa_offs_len;
Hai Shalomfdcde762020-04-02 11:19:20 -0700921 struct radius_sta rad_info;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700922
Hai Shalom60840252021-02-19 19:02:11 -0800923 if (hapd->iconf->rssi_ignore_probe_request && ssi_signal &&
924 ssi_signal < hapd->iconf->rssi_ignore_probe_request)
925 return;
926
Dmitry Shmidte4663042016-04-04 10:07:49 -0700927 if (len < IEEE80211_HDRLEN)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700928 return;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700929 ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800930 if (hapd->iconf->track_sta_max_num)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800931 sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
Dmitry Shmidte4663042016-04-04 10:07:49 -0700932 ie_len = len - IEEE80211_HDRLEN;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700933
Hai Shalomfdcde762020-04-02 11:19:20 -0700934 ret = hostapd_allowed_address(hapd, mgmt->sa, (const u8 *) mgmt, len,
935 &rad_info, 1);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700936 if (ret == HOSTAPD_ACL_REJECT) {
937 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
938 "Ignore Probe Request frame from " MACSTR
939 " due to ACL reject ", MAC2STR(mgmt->sa));
940 return;
941 }
942
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700943 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
944 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800945 mgmt->sa, mgmt->da, mgmt->bssid,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700946 ie, ie_len, ssi_signal) > 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700947 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800948
Hai Shalom74f70d42019-02-11 14:42:39 -0800949 if (!hapd->conf->send_probe_response)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700950 return;
951
952 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
953 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
954 MAC2STR(mgmt->sa));
955 return;
956 }
957
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700958 if ((!elems.ssid || !elems.supp_rates)) {
959 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
960 "without SSID or supported rates element",
961 MAC2STR(mgmt->sa));
962 return;
963 }
964
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800965 /*
966 * No need to reply if the Probe Request frame was sent on an adjacent
967 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
968 * AP with dot11RadioMeasurementActivated set to true, but strictly
969 * speaking does not allow such ignoring of Probe Request frames if
970 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
971 * number of unnecessary Probe Response frames for cases where the STA
972 * is less likely to see them (Probe Request frame sent on a
973 * neighboring, but partially overlapping, channel).
974 */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700975 if (elems.ds_params &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800976 hapd->iface->current_mode &&
977 (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
978 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
979 hapd->iconf->channel != elems.ds_params[0]) {
980 wpa_printf(MSG_DEBUG,
981 "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
982 hapd->iconf->channel, elems.ds_params[0]);
983 return;
984 }
985
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700986#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800987 if (hapd->p2p && hapd->p2p_group && elems.wps_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700988 struct wpabuf *wps;
989 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
990 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
991 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
992 "due to mismatch with Requested Device "
993 "Type");
994 wpabuf_free(wps);
995 return;
996 }
997 wpabuf_free(wps);
998 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800999
Dmitry Shmidtde47be72016-01-07 12:52:55 -08001000 if (hapd->p2p && hapd->p2p_group && elems.p2p) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001001 struct wpabuf *p2p;
1002 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
1003 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
1004 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
1005 "due to mismatch with Device ID");
1006 wpabuf_free(p2p);
1007 return;
1008 }
1009 wpabuf_free(p2p);
1010 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001011#endif /* CONFIG_P2P */
1012
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001013 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
Hai Shalomfdcde762020-04-02 11:19:20 -07001014 elems.ssid_list_len == 0 && elems.short_ssid_list_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001015 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
1016 "broadcast SSID ignored", MAC2STR(mgmt->sa));
1017 return;
1018 }
1019
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001020#ifdef CONFIG_P2P
1021 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1022 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
1023 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
1024 P2P_WILDCARD_SSID_LEN) == 0) {
1025 /* Process P2P Wildcard SSID like Wildcard SSID */
1026 elems.ssid_len = 0;
1027 }
1028#endif /* CONFIG_P2P */
1029
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001030#ifdef CONFIG_TAXONOMY
1031 {
1032 struct sta_info *sta;
1033 struct hostapd_sta_info *info;
1034
1035 if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) {
1036 taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len);
1037 } else if ((info = sta_track_get(hapd->iface,
1038 mgmt->sa)) != NULL) {
1039 taxonomy_hostapd_sta_info_probe_req(hapd, info,
1040 ie, ie_len);
1041 }
1042 }
1043#endif /* CONFIG_TAXONOMY */
1044
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001045 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
Hai Shalomfdcde762020-04-02 11:19:20 -07001046 elems.ssid_list, elems.ssid_list_len,
1047 elems.short_ssid_list, elems.short_ssid_list_len);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001048 if (res == NO_SSID_MATCH) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001049 if (!(mgmt->da[0] & 0x01)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001050 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001051 " for foreign SSID '%s' (DA " MACSTR ")%s",
Dmitry Shmidt3c479372014-02-04 10:50:36 -08001052 MAC2STR(mgmt->sa),
1053 wpa_ssid_txt(elems.ssid, elems.ssid_len),
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001054 MAC2STR(mgmt->da),
1055 elems.ssid_list ? " (SSID list)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001056 }
1057 return;
1058 }
1059
Hai Shalomfdcde762020-04-02 11:19:20 -07001060 if (hapd->conf->ignore_broadcast_ssid && res == WILDCARD_SSID_MATCH) {
1061 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
1062 "broadcast SSID ignored", MAC2STR(mgmt->sa));
1063 return;
1064 }
1065
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001066#ifdef CONFIG_INTERWORKING
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -07001067 if (hapd->conf->interworking &&
1068 elems.interworking && elems.interworking_len >= 1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001069 u8 ant = elems.interworking[0] & 0x0f;
1070 if (ant != INTERWORKING_ANT_WILDCARD &&
1071 ant != hapd->conf->access_network_type) {
1072 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
1073 " for mismatching ANT %u ignored",
1074 MAC2STR(mgmt->sa), ant);
1075 return;
1076 }
1077 }
1078
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -07001079 if (hapd->conf->interworking && elems.interworking &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001080 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
1081 const u8 *hessid;
1082 if (elems.interworking_len == 7)
1083 hessid = elems.interworking + 1;
1084 else
1085 hessid = elems.interworking + 1 + 2;
1086 if (!is_broadcast_ether_addr(hessid) &&
1087 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
1088 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
1089 " for mismatching HESSID " MACSTR
1090 " ignored",
1091 MAC2STR(mgmt->sa), MAC2STR(hessid));
1092 return;
1093 }
1094 }
1095#endif /* CONFIG_INTERWORKING */
1096
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001097#ifdef CONFIG_P2P
1098 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1099 supp_rates_11b_only(&elems)) {
1100 /* Indicates support for 11b rates only */
1101 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
1102 MACSTR " with only 802.11b rates",
1103 MAC2STR(mgmt->sa));
1104 return;
1105 }
1106#endif /* CONFIG_P2P */
1107
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001108 /* TODO: verify that supp_rates contains at least one matching rate
1109 * with AP configuration */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001110
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001111 if (hapd->conf->no_probe_resp_if_seen_on &&
1112 is_multicast_ether_addr(mgmt->da) &&
1113 is_multicast_ether_addr(mgmt->bssid) &&
1114 sta_track_seen_on(hapd->iface, mgmt->sa,
1115 hapd->conf->no_probe_resp_if_seen_on)) {
1116 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1117 " since STA has been seen on %s",
1118 hapd->conf->iface, MAC2STR(mgmt->sa),
1119 hapd->conf->no_probe_resp_if_seen_on);
1120 return;
1121 }
1122
1123 if (hapd->conf->no_probe_resp_if_max_sta &&
1124 is_multicast_ether_addr(mgmt->da) &&
1125 is_multicast_ether_addr(mgmt->bssid) &&
1126 hapd->num_sta >= hapd->conf->max_num_sta &&
1127 !ap_get_sta(hapd, mgmt->sa)) {
1128 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1129 " since no room for additional STA",
1130 hapd->conf->iface, MAC2STR(mgmt->sa));
1131 return;
1132 }
1133
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001134#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001135 if (hapd->iconf->ignore_probe_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001136 drand48() < hapd->iconf->ignore_probe_probability) {
1137 wpa_printf(MSG_INFO,
1138 "TESTING: ignoring probe request from " MACSTR,
1139 MAC2STR(mgmt->sa));
1140 return;
1141 }
1142#endif /* CONFIG_TESTING_OPTIONS */
1143
Roshan Pius3a1667e2018-07-03 15:17:14 -07001144 wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, RX_PROBE_REQUEST "sa=" MACSTR
1145 " signal=%d", MAC2STR(mgmt->sa), ssi_signal);
1146
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001147 resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL,
Sunil8cd6f4d2022-06-28 18:40:46 +00001148 &resp_len, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001149 if (resp == NULL)
1150 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001151
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001152 /*
1153 * If this is a broadcast probe request, apply no ack policy to avoid
1154 * excessive retries.
1155 */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001156 noack = !!(res == WILDCARD_SSID_MATCH &&
1157 is_broadcast_ether_addr(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001158
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001159 csa_offs_len = 0;
1160 if (hapd->csa_in_progress) {
1161 if (hapd->cs_c_off_proberesp)
1162 csa_offs[csa_offs_len++] =
1163 hapd->cs_c_off_proberesp;
1164
1165 if (hapd->cs_c_off_ecsa_proberesp)
1166 csa_offs[csa_offs_len++] =
1167 hapd->cs_c_off_ecsa_proberesp;
1168 }
1169
Hai Shalomfdcde762020-04-02 11:19:20 -07001170 ret = hostapd_drv_send_mlme(hapd, resp, resp_len, noack,
1171 csa_offs_len ? csa_offs : NULL,
1172 csa_offs_len, 0);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001173
1174 if (ret < 0)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001175 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001176
1177 os_free(resp);
1178
1179 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
1180 "SSID", MAC2STR(mgmt->sa),
1181 elems.ssid_len == 0 ? "broadcast" : "our");
1182}
1183
1184
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001185static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
1186 size_t *resp_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001187{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001188 /* check probe response offloading caps and print warnings */
1189 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
1190 return NULL;
1191
1192#ifdef CONFIG_WPS
1193 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
1194 (!(hapd->iface->probe_resp_offloads &
1195 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
1196 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
1197 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
1198 "Probe Response while not supporting this");
1199#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001200
1201#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001202 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
1203 !(hapd->iface->probe_resp_offloads &
1204 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
1205 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
1206 "Probe Response while not supporting this");
1207#endif /* CONFIG_P2P */
1208
1209 if (hapd->conf->interworking &&
1210 !(hapd->iface->probe_resp_offloads &
1211 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
1212 wpa_printf(MSG_WARNING, "Device is trying to offload "
1213 "Interworking Probe Response while not supporting "
1214 "this");
1215
1216 /* Generate a Probe Response template for the non-P2P case */
Sunil8cd6f4d2022-06-28 18:40:46 +00001217 return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len, false);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001218}
1219
1220#endif /* NEED_AP_MLME */
1221
1222
Hai Shalom60840252021-02-19 19:02:11 -08001223#ifdef CONFIG_IEEE80211AX
1224/* Unsolicited broadcast Probe Response transmission, 6 GHz only */
1225static u8 * hostapd_unsol_bcast_probe_resp(struct hostapd_data *hapd,
1226 struct wpa_driver_ap_params *params)
1227{
1228 if (!is_6ghz_op_class(hapd->iconf->op_class))
1229 return NULL;
1230
1231 params->unsol_bcast_probe_resp_interval =
1232 hapd->conf->unsol_bcast_probe_resp_interval;
1233
1234 return hostapd_gen_probe_resp(hapd, NULL, 0,
Sunil8cd6f4d2022-06-28 18:40:46 +00001235 &params->unsol_bcast_probe_resp_tmpl_len,
1236 true);
Hai Shalom60840252021-02-19 19:02:11 -08001237}
1238#endif /* CONFIG_IEEE80211AX */
1239
1240
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001241void sta_track_del(struct hostapd_sta_info *info)
1242{
1243#ifdef CONFIG_TAXONOMY
1244 wpabuf_free(info->probe_ie_taxonomy);
1245 info->probe_ie_taxonomy = NULL;
1246#endif /* CONFIG_TAXONOMY */
1247 os_free(info);
1248}
1249
1250
Hai Shalom60840252021-02-19 19:02:11 -08001251#ifdef CONFIG_FILS
1252
1253static u16 hostapd_fils_discovery_cap(struct hostapd_data *hapd)
1254{
1255 u16 cap_info, phy_index = 0;
1256 u8 chwidth = FD_CAP_BSS_CHWIDTH_20, mcs_nss_size = 4;
1257 struct hostapd_hw_modes *mode = hapd->iface->current_mode;
1258
1259 cap_info = FD_CAP_ESS;
1260 if (hapd->conf->wpa)
1261 cap_info |= FD_CAP_PRIVACY;
1262
1263 if (is_6ghz_op_class(hapd->iconf->op_class)) {
1264 phy_index = FD_CAP_PHY_INDEX_HE;
1265
1266 switch (hapd->iconf->op_class) {
1267 case 135:
1268 mcs_nss_size += 4;
1269 /* fallthrough */
1270 case 134:
1271 mcs_nss_size += 4;
1272 chwidth = FD_CAP_BSS_CHWIDTH_160_80_80;
1273 break;
1274 case 133:
1275 chwidth = FD_CAP_BSS_CHWIDTH_80;
1276 break;
1277 case 132:
1278 chwidth = FD_CAP_BSS_CHWIDTH_40;
1279 break;
1280 }
1281 } else {
1282 switch (hostapd_get_oper_chwidth(hapd->iconf)) {
Sunil8cd6f4d2022-06-28 18:40:46 +00001283 case CONF_OPER_CHWIDTH_80P80MHZ:
Hai Shalom60840252021-02-19 19:02:11 -08001284 mcs_nss_size += 4;
1285 /* fallthrough */
Sunil8cd6f4d2022-06-28 18:40:46 +00001286 case CONF_OPER_CHWIDTH_160MHZ:
Hai Shalom60840252021-02-19 19:02:11 -08001287 mcs_nss_size += 4;
1288 chwidth = FD_CAP_BSS_CHWIDTH_160_80_80;
1289 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00001290 case CONF_OPER_CHWIDTH_80MHZ:
Hai Shalom60840252021-02-19 19:02:11 -08001291 chwidth = FD_CAP_BSS_CHWIDTH_80;
1292 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00001293 case CONF_OPER_CHWIDTH_USE_HT:
Hai Shalom60840252021-02-19 19:02:11 -08001294 if (hapd->iconf->secondary_channel)
1295 chwidth = FD_CAP_BSS_CHWIDTH_40;
1296 else
1297 chwidth = FD_CAP_BSS_CHWIDTH_20;
1298 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00001299 default:
1300 break;
Hai Shalom60840252021-02-19 19:02:11 -08001301 }
1302
1303#ifdef CONFIG_IEEE80211AX
1304 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax)
1305 phy_index = FD_CAP_PHY_INDEX_HE;
1306#endif /* CONFIG_IEEE80211AX */
1307#ifdef CONFIG_IEEE80211AC
1308 if (!phy_index &&
1309 hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac)
1310 phy_index = FD_CAP_PHY_INDEX_VHT;
1311#endif /* CONFIG_IEEE80211AC */
1312 if (!phy_index &&
1313 hapd->iconf->ieee80211n && !hapd->conf->disable_11n)
1314 phy_index = FD_CAP_PHY_INDEX_HT;
1315 }
1316
1317 cap_info |= phy_index << FD_CAP_PHY_INDEX_SHIFT;
1318 cap_info |= chwidth << FD_CAP_BSS_CHWIDTH_SHIFT;
1319
1320 if (mode) {
1321 u16 *mcs = (u16 *) mode->he_capab[IEEE80211_MODE_AP].mcs;
1322 int i;
1323 u16 nss = 0;
1324
1325 for (i = 0; i < HE_NSS_MAX_STREAMS; i++) {
1326 u16 nss_mask = 0x3 << (i * 2);
1327
1328 if (mcs_nss_size == 4 &&
1329 (((mcs[0] & nss_mask) == nss_mask) ||
1330 ((mcs[1] & nss_mask) == nss_mask)))
1331 continue;
1332
1333 if (mcs_nss_size == 8 &&
1334 (((mcs[2] & nss_mask) == nss_mask) ||
1335 ((mcs[3] & nss_mask) == nss_mask)))
1336 continue;
1337
1338 if (mcs_nss_size == 12 &&
1339 (((mcs[4] & nss_mask) == nss_mask) ||
1340 ((mcs[5] & nss_mask) == nss_mask)))
1341 continue;
1342
1343 nss++;
1344 }
1345
1346 if (nss > 4)
1347 cap_info |= FD_CAP_NSS_5_8 << FD_CAP_NSS_SHIFT;
1348 else if (nss)
1349 cap_info |= (nss - 1) << FD_CAP_NSS_SHIFT;
1350 }
1351
1352 return cap_info;
1353}
1354
1355
1356static u8 * hostapd_gen_fils_discovery(struct hostapd_data *hapd, size_t *len)
1357{
1358 struct ieee80211_mgmt *head;
1359 const u8 *mobility_domain;
1360 u8 *pos, *length_pos, buf[200];
1361 u16 ctl = 0;
1362 u8 fd_rsn_info[5];
1363 size_t total_len, buf_len;
1364
1365 total_len = 24 + 2 + 12;
1366
1367 /* FILS Discovery Frame Control */
1368 ctl = (sizeof(hapd->conf->ssid.short_ssid) - 1) |
1369 FD_FRAME_CTL_SHORT_SSID_PRESENT |
1370 FD_FRAME_CTL_LENGTH_PRESENT |
1371 FD_FRAME_CTL_CAP_PRESENT;
1372 total_len += 4 + 1 + 2;
1373
1374 /* Check for optional subfields and calculate length */
1375 if (wpa_auth_write_fd_rsn_info(hapd->wpa_auth, fd_rsn_info)) {
1376 ctl |= FD_FRAME_CTL_RSN_INFO_PRESENT;
1377 total_len += sizeof(fd_rsn_info);
1378 }
1379
1380 mobility_domain = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN);
1381 if (mobility_domain) {
1382 ctl |= FD_FRAME_CTL_MD_PRESENT;
1383 total_len += 3;
1384 }
1385
Hai Shaloma20dcd72022-02-04 13:43:00 -08001386 total_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_ACTION);
1387
Hai Shalom60840252021-02-19 19:02:11 -08001388 pos = hostapd_eid_fils_indic(hapd, buf, 0);
1389 buf_len = pos - buf;
1390 total_len += buf_len;
1391
Sunil Ravia04bd252022-05-02 22:54:18 -07001392#ifdef CONFIG_IEEE80211AX
1393 /* Transmit Power Envelope element(s) */
1394 if (is_6ghz_op_class(hapd->iconf->op_class)) {
1395 total_len += 4;
1396 if (hapd->iconf->he_6ghz_reg_pwr_type == HE_6GHZ_INDOOR_AP)
1397 total_len += 4;
1398 }
1399#endif /* CONFIG_IEEE80211AX */
1400
Hai Shalom60840252021-02-19 19:02:11 -08001401 head = os_zalloc(total_len);
1402 if (!head)
1403 return NULL;
1404
1405 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1406 WLAN_FC_STYPE_ACTION);
1407 os_memset(head->da, 0xff, ETH_ALEN);
1408 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1409 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1410
1411 head->u.action.category = WLAN_ACTION_PUBLIC;
1412 head->u.action.u.public_action.action = WLAN_PA_FILS_DISCOVERY;
1413
1414 pos = &head->u.action.u.public_action.variable[0];
1415
1416 /* FILS Discovery Information field */
1417
1418 /* FILS Discovery Frame Control */
1419 WPA_PUT_LE16(pos, ctl);
1420 pos += 2;
1421
1422 /* Hardware or low-level driver will fill in the Timestamp value */
1423 pos += 8;
1424
1425 /* Beacon Interval */
1426 WPA_PUT_LE16(pos, hapd->iconf->beacon_int);
1427 pos += 2;
1428
1429 /* Short SSID */
1430 WPA_PUT_LE32(pos, hapd->conf->ssid.short_ssid);
1431 pos += sizeof(hapd->conf->ssid.short_ssid);
1432
1433 /* Store position of FILS discovery information element Length field */
1434 length_pos = pos++;
1435
1436 /* FD Capability */
1437 WPA_PUT_LE16(pos, hostapd_fils_discovery_cap(hapd));
1438 pos += 2;
1439
1440 /* Operating Class - not present */
1441
1442 /* Primary Channel - not present */
1443
1444 /* AP Configuration Sequence Number - not present */
1445
1446 /* Access Network Options - not present */
1447
1448 /* FD RSN Information */
1449 if (ctl & FD_FRAME_CTL_RSN_INFO_PRESENT) {
1450 os_memcpy(pos, fd_rsn_info, sizeof(fd_rsn_info));
1451 pos += sizeof(fd_rsn_info);
1452 }
1453
1454 /* Channel Center Frequency Segment 1 - not present */
1455
1456 /* Mobility Domain */
1457 if (ctl & FD_FRAME_CTL_MD_PRESENT) {
1458 os_memcpy(pos, &mobility_domain[2], 3);
1459 pos += 3;
1460 }
1461
1462 /* Fill in the Length field value */
1463 *length_pos = pos - (length_pos + 1);
1464
Hai Shaloma20dcd72022-02-04 13:43:00 -08001465 pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_ACTION);
1466
Hai Shalom60840252021-02-19 19:02:11 -08001467 /* FILS Indication element */
1468 if (buf_len) {
1469 os_memcpy(pos, buf, buf_len);
1470 pos += buf_len;
1471 }
1472
Sunil Ravia04bd252022-05-02 22:54:18 -07001473 if (is_6ghz_op_class(hapd->iconf->op_class))
1474 pos = hostapd_eid_txpower_envelope(hapd, pos);
1475
Hai Shalom60840252021-02-19 19:02:11 -08001476 *len = pos - (u8 *) head;
1477 wpa_hexdump(MSG_DEBUG, "FILS Discovery frame template",
1478 head, pos - (u8 *) head);
1479 return (u8 *) head;
1480}
1481
1482
1483/* Configure FILS Discovery frame transmission parameters */
1484static u8 * hostapd_fils_discovery(struct hostapd_data *hapd,
1485 struct wpa_driver_ap_params *params)
1486{
1487 params->fd_max_int = hapd->conf->fils_discovery_max_int;
1488 if (is_6ghz_op_class(hapd->iconf->op_class) &&
1489 params->fd_max_int > FD_MAX_INTERVAL_6GHZ)
1490 params->fd_max_int = FD_MAX_INTERVAL_6GHZ;
1491
1492 params->fd_min_int = hapd->conf->fils_discovery_min_int;
1493 if (params->fd_min_int > params->fd_max_int)
1494 params->fd_min_int = params->fd_max_int;
1495
1496 if (params->fd_max_int)
1497 return hostapd_gen_fils_discovery(hapd,
1498 &params->fd_frame_tmpl_len);
1499
1500 return NULL;
1501}
1502
1503#endif /* CONFIG_FILS */
1504
1505
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001506int ieee802_11_build_ap_params(struct hostapd_data *hapd,
1507 struct wpa_driver_ap_params *params)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001508{
1509 struct ieee80211_mgmt *head = NULL;
1510 u8 *tail = NULL;
1511 size_t head_len = 0, tail_len = 0;
1512 u8 *resp = NULL;
1513 size_t resp_len = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001514#ifdef NEED_AP_MLME
1515 u16 capab_info;
Hai Shalomfdcde762020-04-02 11:19:20 -07001516 u8 *pos, *tailpos, *tailend, *csa_pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001517
1518#define BEACON_HEAD_BUF_SIZE 256
1519#define BEACON_TAIL_BUF_SIZE 512
1520 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
1521 tail_len = BEACON_TAIL_BUF_SIZE;
1522#ifdef CONFIG_WPS
1523 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
1524 tail_len += wpabuf_len(hapd->wps_beacon_ie);
1525#endif /* CONFIG_WPS */
1526#ifdef CONFIG_P2P
1527 if (hapd->p2p_beacon_ie)
1528 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
1529#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001530#ifdef CONFIG_FST
1531 if (hapd->iface->fst_ies)
1532 tail_len += wpabuf_len(hapd->iface->fst_ies);
1533#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001534 if (hapd->conf->vendor_elements)
1535 tail_len += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001536
1537#ifdef CONFIG_IEEE80211AC
1538 if (hapd->conf->vendor_vht) {
1539 tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
1540 2 + sizeof(struct ieee80211_vht_operation);
1541 }
1542#endif /* CONFIG_IEEE80211AC */
1543
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001544#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08001545 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001546 tail_len += 3 + sizeof(struct ieee80211_he_capabilities) +
Hai Shalom74f70d42019-02-11 14:42:39 -08001547 3 + sizeof(struct ieee80211_he_operation) +
Hai Shalom81f62d82019-07-22 12:10:00 -07001548 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
1549 3 + sizeof(struct ieee80211_spatial_reuse);
Sunil Ravia04bd252022-05-02 22:54:18 -07001550 if (is_6ghz_op_class(hapd->iconf->op_class)) {
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001551 tail_len += sizeof(struct ieee80211_he_6ghz_oper_info) +
1552 3 + sizeof(struct ieee80211_he_6ghz_band_cap);
Sunil Ravia04bd252022-05-02 22:54:18 -07001553 /* An additional Transmit Power Envelope element for
1554 * subordinate client */
1555 if (hapd->iconf->he_6ghz_reg_pwr_type ==
1556 HE_6GHZ_INDOOR_AP)
1557 tail_len += 4;
1558 }
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001559 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001560#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001561
Sunil Ravia04bd252022-05-02 22:54:18 -07001562#ifdef CONFIG_IEEE80211BE
1563 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
1564 tail_len += hostapd_eid_eht_capab_len(hapd, IEEE80211_MODE_AP);
1565 tail_len += 3 + sizeof(struct ieee80211_eht_operation);
1566 }
1567#endif /* CONFIG_IEEE80211BE */
1568
Hai Shaloma20dcd72022-02-04 13:43:00 -08001569 tail_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_BEACON);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001570 tail_len += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001571 tail_len += hostapd_eid_owe_trans_len(hapd);
Hai Shalomfdcde762020-04-02 11:19:20 -07001572 tail_len += hostapd_eid_dpp_cc_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001573
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001574 tailpos = tail = os_malloc(tail_len);
1575 if (head == NULL || tail == NULL) {
1576 wpa_printf(MSG_ERROR, "Failed to set beacon data");
1577 os_free(head);
1578 os_free(tail);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001579 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001580 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001581 tailend = tail + tail_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001582
1583 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1584 WLAN_FC_STYPE_BEACON);
1585 head->duration = host_to_le16(0);
1586 os_memset(head->da, 0xff, ETH_ALEN);
1587
1588 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1589 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1590 head->u.beacon.beacon_int =
1591 host_to_le16(hapd->iconf->beacon_int);
1592
1593 /* hardware or low-level driver will setup seq_ctrl and timestamp */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001594 capab_info = hostapd_own_capab_info(hapd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001595 head->u.beacon.capab_info = host_to_le16(capab_info);
1596 pos = &head->u.beacon.variable[0];
1597
1598 /* SSID */
1599 *pos++ = WLAN_EID_SSID;
1600 if (hapd->conf->ignore_broadcast_ssid == 2) {
1601 /* clear the data, but keep the correct length of the SSID */
1602 *pos++ = hapd->conf->ssid.ssid_len;
1603 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
1604 pos += hapd->conf->ssid.ssid_len;
1605 } else if (hapd->conf->ignore_broadcast_ssid) {
1606 *pos++ = 0; /* empty SSID */
1607 } else {
1608 *pos++ = hapd->conf->ssid.ssid_len;
1609 os_memcpy(pos, hapd->conf->ssid.ssid,
1610 hapd->conf->ssid.ssid_len);
1611 pos += hapd->conf->ssid.ssid_len;
1612 }
1613
1614 /* Supported rates */
1615 pos = hostapd_eid_supp_rates(hapd, pos);
1616
1617 /* DS Params */
1618 pos = hostapd_eid_ds_params(hapd, pos);
1619
1620 head_len = pos - (u8 *) head;
1621
Hai Shalomfdcde762020-04-02 11:19:20 -07001622 tailpos = hostapd_eid_country(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001623
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001624 /* Power Constraint element */
1625 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
1626
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001627 /* CSA IE */
1628 csa_pos = hostapd_eid_csa(hapd, tailpos);
1629 if (csa_pos != tailpos)
1630 hapd->cs_c_off_beacon = csa_pos - tail - 1;
1631 tailpos = csa_pos;
1632
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001633 /* ERP Information element */
1634 tailpos = hostapd_eid_erp_info(hapd, tailpos);
1635
1636 /* Extended supported rates */
1637 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
1638
Hai Shalomfdcde762020-04-02 11:19:20 -07001639 tailpos = hostapd_get_rsne(hapd, tailpos, tailend - tailpos);
1640 tailpos = hostapd_eid_bss_load(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001641 tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
Hai Shalomfdcde762020-04-02 11:19:20 -07001642 tailend - tailpos);
1643 tailpos = hostapd_get_mde(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001644
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001645 /* eCSA IE */
1646 csa_pos = hostapd_eid_ecsa(hapd, tailpos);
1647 if (csa_pos != tailpos)
1648 hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1;
1649 tailpos = csa_pos;
1650
1651 tailpos = hostapd_eid_supported_op_classes(hapd, tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001652 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
1653 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001654
1655 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
1656
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001657 /*
1658 * TODO: Time Advertisement element should only be included in some
1659 * DTIM Beacon frames.
1660 */
1661 tailpos = hostapd_eid_time_adv(hapd, tailpos);
1662
1663 tailpos = hostapd_eid_interworking(hapd, tailpos);
1664 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
1665 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001666
1667#ifdef CONFIG_FST
1668 if (hapd->iface->fst_ies) {
1669 os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies),
1670 wpabuf_len(hapd->iface->fst_ies));
1671 tailpos += wpabuf_len(hapd->iface->fst_ies);
1672 }
1673#endif /* CONFIG_FST */
1674
Dmitry Shmidt04949592012-07-19 12:16:46 -07001675#ifdef CONFIG_IEEE80211AC
Hai Shalom60840252021-02-19 19:02:11 -08001676 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
1677 !is_6ghz_op_class(hapd->iconf->op_class)) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -07001678 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001679 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08001680 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001681 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001682#endif /* CONFIG_IEEE80211AC */
1683
Hai Shalom60840252021-02-19 19:02:11 -08001684#ifdef CONFIG_IEEE80211AX
1685 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax &&
1686 is_6ghz_op_class(hapd->iconf->op_class))
1687 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
1688#endif /* CONFIG_IEEE80211AX */
1689
Hai Shaloma20dcd72022-02-04 13:43:00 -08001690 tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos);
Hai Shalom899fcc72020-10-19 14:38:18 -07001691
Hai Shaloma20dcd72022-02-04 13:43:00 -08001692 tailpos = hostapd_eid_rnr(hapd, tailpos, WLAN_FC_STYPE_BEACON);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001693 tailpos = hostapd_eid_fils_indic(hapd, tailpos, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -07001694 tailpos = hostapd_get_rsnxe(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001695
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001696#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08001697 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Sunil Ravia04bd252022-05-02 22:54:18 -07001698 u8 *cca_pos;
1699
Hai Shalom81f62d82019-07-22 12:10:00 -07001700 tailpos = hostapd_eid_he_capab(hapd, tailpos,
1701 IEEE80211_MODE_AP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001702 tailpos = hostapd_eid_he_operation(hapd, tailpos);
Sunil Ravia04bd252022-05-02 22:54:18 -07001703
1704 /* BSS Color Change Announcement element */
1705 cca_pos = hostapd_eid_cca(hapd, tailpos);
1706 if (cca_pos != tailpos)
1707 hapd->cca_c_off_beacon = cca_pos - tail - 2;
1708 tailpos = cca_pos;
1709
Hai Shalom81f62d82019-07-22 12:10:00 -07001710 tailpos = hostapd_eid_spatial_reuse(hapd, tailpos);
Hai Shalomfdcde762020-04-02 11:19:20 -07001711 tailpos = hostapd_eid_he_mu_edca_parameter_set(hapd, tailpos);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001712 tailpos = hostapd_eid_he_6ghz_band_cap(hapd, tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001713 }
1714#endif /* CONFIG_IEEE80211AX */
1715
Sunil Ravia04bd252022-05-02 22:54:18 -07001716#ifdef CONFIG_IEEE80211BE
1717 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
1718 tailpos = hostapd_eid_eht_capab(hapd, tailpos,
1719 IEEE80211_MODE_AP);
1720 tailpos = hostapd_eid_eht_operation(hapd, tailpos);
1721 }
1722#endif /* CONFIG_IEEE80211BE */
1723
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001724#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001725 if (hapd->conf->vendor_vht)
1726 tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001727#endif /* CONFIG_IEEE80211AC */
1728
Hai Shalomfdcde762020-04-02 11:19:20 -07001729 /* WPA / OSEN */
1730 tailpos = hostapd_get_wpa_ie(hapd, tailpos, tailend - tailpos);
1731 tailpos = hostapd_get_osen_ie(hapd, tailpos, tailend - tailpos);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001732
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001733 /* Wi-Fi Alliance WMM */
1734 tailpos = hostapd_eid_wmm(hapd, tailpos);
1735
1736#ifdef CONFIG_WPS
1737 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
1738 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
1739 wpabuf_len(hapd->wps_beacon_ie));
1740 tailpos += wpabuf_len(hapd->wps_beacon_ie);
1741 }
1742#endif /* CONFIG_WPS */
1743
1744#ifdef CONFIG_P2P
1745 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
1746 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
1747 wpabuf_len(hapd->p2p_beacon_ie));
1748 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
1749 }
1750#endif /* CONFIG_P2P */
1751#ifdef CONFIG_P2P_MANAGER
1752 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
1753 P2P_MANAGE)
1754 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
1755#endif /* CONFIG_P2P_MANAGER */
1756
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001757#ifdef CONFIG_HS20
1758 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
1759#endif /* CONFIG_HS20 */
1760
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001761 tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001762 tailpos = hostapd_eid_owe_trans(hapd, tailpos,
1763 tail + tail_len - tailpos);
Hai Shalomfdcde762020-04-02 11:19:20 -07001764 tailpos = hostapd_eid_dpp_cc(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001765
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001766 if (hapd->conf->vendor_elements) {
1767 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
1768 wpabuf_len(hapd->conf->vendor_elements));
1769 tailpos += wpabuf_len(hapd->conf->vendor_elements);
1770 }
1771
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001772 tail_len = tailpos > tail ? tailpos - tail : 0;
1773
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001774 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
1775#endif /* NEED_AP_MLME */
1776
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001777 os_memset(params, 0, sizeof(*params));
1778 params->head = (u8 *) head;
1779 params->head_len = head_len;
1780 params->tail = tail;
1781 params->tail_len = tail_len;
1782 params->proberesp = resp;
1783 params->proberesp_len = resp_len;
1784 params->dtim_period = hapd->conf->dtim_period;
1785 params->beacon_int = hapd->iconf->beacon_int;
1786 params->basic_rates = hapd->iface->basic_rates;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001787 params->beacon_rate = hapd->iconf->beacon_rate;
1788 params->rate_type = hapd->iconf->rate_type;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001789 params->ssid = hapd->conf->ssid.ssid;
1790 params->ssid_len = hapd->conf->ssid.ssid_len;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001791 if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
1792 (WPA_PROTO_WPA | WPA_PROTO_RSN))
1793 params->pairwise_ciphers = hapd->conf->wpa_pairwise |
1794 hapd->conf->rsn_pairwise;
1795 else if (hapd->conf->wpa & WPA_PROTO_RSN)
1796 params->pairwise_ciphers = hapd->conf->rsn_pairwise;
1797 else if (hapd->conf->wpa & WPA_PROTO_WPA)
1798 params->pairwise_ciphers = hapd->conf->wpa_pairwise;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001799 params->group_cipher = hapd->conf->wpa_group;
1800 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
1801 params->auth_algs = hapd->conf->auth_algs;
1802 params->wpa_version = hapd->conf->wpa;
Hai Shalomfdcde762020-04-02 11:19:20 -07001803 params->privacy = hapd->conf->wpa;
1804#ifdef CONFIG_WEP
1805 params->privacy |= hapd->conf->ssid.wep.keys_set ||
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001806 (hapd->conf->ieee802_1x &&
1807 (hapd->conf->default_wep_key_len ||
1808 hapd->conf->individual_wep_key_len));
Hai Shalomfdcde762020-04-02 11:19:20 -07001809#endif /* CONFIG_WEP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001810 switch (hapd->conf->ignore_broadcast_ssid) {
1811 case 0:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001812 params->hide_ssid = NO_SSID_HIDING;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001813 break;
1814 case 1:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001815 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001816 break;
1817 case 2:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001818 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001819 break;
1820 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001821 params->isolate = hapd->conf->isolate;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001822#ifdef NEED_AP_MLME
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001823 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001824 ERP_INFO_USE_PROTECTION);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001825 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001826 hapd->iconf->preamble == SHORT_PREAMBLE;
1827 if (hapd->iface->current_mode &&
1828 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001829 params->short_slot_time =
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001830 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
1831 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001832 params->short_slot_time = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001833 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001834 params->ht_opmode = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001835 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001836 params->ht_opmode = hapd->iface->ht_op_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001837#endif /* NEED_AP_MLME */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001838 params->interworking = hapd->conf->interworking;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001839 if (hapd->conf->interworking &&
1840 !is_zero_ether_addr(hapd->conf->hessid))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001841 params->hessid = hapd->conf->hessid;
1842 params->access_network_type = hapd->conf->access_network_type;
1843 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001844#ifdef CONFIG_P2P
1845 params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
1846#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001847#ifdef CONFIG_HS20
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001848 params->disable_dgaf = hapd->conf->disable_dgaf;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001849 if (hapd->conf->osen) {
1850 params->privacy = 1;
1851 params->osen = 1;
1852 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001853#endif /* CONFIG_HS20 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001854 params->multicast_to_unicast = hapd->conf->multicast_to_unicast;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001855 params->pbss = hapd->conf->pbss;
Hai Shalom74f70d42019-02-11 14:42:39 -08001856
1857 if (hapd->conf->ftm_responder) {
1858 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_FTM_RESPONDER) {
1859 params->ftm_responder = 1;
1860 params->lci = hapd->iface->conf->lci;
1861 params->civic = hapd->iface->conf->civic;
1862 } else {
1863 wpa_printf(MSG_WARNING,
1864 "Not configuring FTM responder as the driver doesn't advertise support for it");
1865 }
1866 }
1867
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001868 return 0;
1869}
1870
1871
1872void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
1873{
1874 os_free(params->tail);
1875 params->tail = NULL;
1876 os_free(params->head);
1877 params->head = NULL;
1878 os_free(params->proberesp);
1879 params->proberesp = NULL;
Hai Shalom60840252021-02-19 19:02:11 -08001880#ifdef CONFIG_FILS
1881 os_free(params->fd_frame_tmpl);
1882 params->fd_frame_tmpl = NULL;
1883#endif /* CONFIG_FILS */
1884#ifdef CONFIG_IEEE80211AX
1885 os_free(params->unsol_bcast_probe_resp_tmpl);
1886 params->unsol_bcast_probe_resp_tmpl = NULL;
1887#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001888}
1889
1890
Hai Shaloma20dcd72022-02-04 13:43:00 -08001891static int __ieee802_11_set_beacon(struct hostapd_data *hapd)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001892{
1893 struct wpa_driver_ap_params params;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001894 struct hostapd_freq_params freq;
1895 struct hostapd_iface *iface = hapd->iface;
1896 struct hostapd_config *iconf = iface->conf;
Hai Shalom81f62d82019-07-22 12:10:00 -07001897 struct hostapd_hw_modes *cmode = iface->current_mode;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001898 struct wpabuf *beacon, *proberesp, *assocresp;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001899 int res, ret = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001900
Hai Shaloma20dcd72022-02-04 13:43:00 -08001901 if (!hapd->drv_priv) {
1902 wpa_printf(MSG_ERROR, "Interface is disabled");
1903 return -1;
1904 }
1905
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001906 if (hapd->csa_in_progress) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001907 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001908 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001909 }
1910
1911 hapd->beacon_set_done = 1;
1912
1913 if (ieee802_11_build_ap_params(hapd, &params) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001914 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001915
1916 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
1917 0)
1918 goto fail;
1919
1920 params.beacon_ies = beacon;
1921 params.proberesp_ies = proberesp;
1922 params.assocresp_ies = assocresp;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001923 params.reenable = hapd->reenable_beacon;
Hai Shalomc3565922019-10-28 11:58:20 -07001924#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08001925 params.he_spr_ctrl = hapd->iface->conf->spr.sr_control;
1926 params.he_spr_non_srg_obss_pd_max_offset =
1927 hapd->iface->conf->spr.non_srg_obss_pd_max_offset;
Hai Shalomc3565922019-10-28 11:58:20 -07001928 params.he_spr_srg_obss_pd_min_offset =
1929 hapd->iface->conf->spr.srg_obss_pd_min_offset;
1930 params.he_spr_srg_obss_pd_max_offset =
1931 hapd->iface->conf->spr.srg_obss_pd_max_offset;
Hai Shalom60840252021-02-19 19:02:11 -08001932 os_memcpy(params.he_spr_bss_color_bitmap,
1933 hapd->iface->conf->spr.srg_bss_color_bitmap, 8);
1934 os_memcpy(params.he_spr_partial_bssid_bitmap,
1935 hapd->iface->conf->spr.srg_partial_bssid_bitmap, 8);
Hai Shalomfdcde762020-04-02 11:19:20 -07001936 params.he_bss_color_disabled =
1937 hapd->iface->conf->he_op.he_bss_color_disabled;
1938 params.he_bss_color_partial =
1939 hapd->iface->conf->he_op.he_bss_color_partial;
1940 params.he_bss_color = hapd->iface->conf->he_op.he_bss_color;
1941 params.twt_responder = hostapd_get_he_twt_responder(hapd,
1942 IEEE80211_MODE_AP);
Hai Shalom60840252021-02-19 19:02:11 -08001943 params.unsol_bcast_probe_resp_tmpl =
1944 hostapd_unsol_bcast_probe_resp(hapd, &params);
Hai Shalomc3565922019-10-28 11:58:20 -07001945#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001946 hapd->reenable_beacon = 0;
Hai Shalom60840252021-02-19 19:02:11 -08001947#ifdef CONFIG_SAE
1948 params.sae_pwe = hapd->conf->sae_pwe;
1949#endif /* CONFIG_SAE */
1950
1951#ifdef CONFIG_FILS
1952 params.fd_frame_tmpl = hostapd_fils_discovery(hapd, &params);
1953#endif /* CONFIG_FILS */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001954
Hai Shalom81f62d82019-07-22 12:10:00 -07001955 if (cmode &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001956 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
Hai Shalomc3565922019-10-28 11:58:20 -07001957 iconf->channel, iconf->enable_edmg,
1958 iconf->edmg_channel, iconf->ieee80211n,
Hai Shalom81f62d82019-07-22 12:10:00 -07001959 iconf->ieee80211ac, iconf->ieee80211ax,
Sunil Ravia04bd252022-05-02 22:54:18 -07001960 iconf->ieee80211be,
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001961 iconf->secondary_channel,
Hai Shalom81f62d82019-07-22 12:10:00 -07001962 hostapd_get_oper_chwidth(iconf),
1963 hostapd_get_oper_centr_freq_seg0_idx(iconf),
1964 hostapd_get_oper_centr_freq_seg1_idx(iconf),
1965 cmode->vht_capab,
Sunil Ravia04bd252022-05-02 22:54:18 -07001966 &cmode->he_capab[IEEE80211_MODE_AP],
1967 &cmode->eht_capab[IEEE80211_MODE_AP]) == 0)
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001968 params.freq = &freq;
1969
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001970 res = hostapd_drv_set_ap(hapd, &params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001971 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001972 if (res)
1973 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
1974 else
1975 ret = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001976fail:
1977 ieee802_11_free_ap_params(&params);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001978 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001979}
1980
1981
Hai Shaloma20dcd72022-02-04 13:43:00 -08001982int ieee802_11_set_beacon(struct hostapd_data *hapd)
1983{
1984 struct hostapd_iface *iface = hapd->iface;
1985 int ret;
1986 size_t i, j;
1987 bool is_6g;
1988
1989 ret = __ieee802_11_set_beacon(hapd);
1990 if (ret != 0)
1991 return ret;
1992
1993 if (!iface->interfaces || iface->interfaces->count <= 1)
1994 return 0;
1995
1996 /* Update Beacon frames in case of 6 GHz colocation */
1997 is_6g = is_6ghz_op_class(iface->conf->op_class);
1998 for (j = 0; j < iface->interfaces->count; j++) {
1999 struct hostapd_iface *colocated;
2000
2001 colocated = iface->interfaces->iface[j];
2002 if (colocated == iface || !colocated || !colocated->conf)
2003 continue;
2004
2005 if (is_6g == is_6ghz_op_class(colocated->conf->op_class))
2006 continue;
2007
2008 for (i = 0; i < colocated->num_bss; i++) {
2009 if (colocated->bss[i] && colocated->bss[i]->started)
2010 __ieee802_11_set_beacon(colocated->bss[i]);
2011 }
2012 }
2013
2014 return 0;
2015}
2016
2017
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002018int ieee802_11_set_beacons(struct hostapd_iface *iface)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002019{
2020 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002021 int ret = 0;
2022
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08002023 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002024 if (iface->bss[i]->started &&
2025 ieee802_11_set_beacon(iface->bss[i]) < 0)
2026 ret = -1;
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08002027 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002028
2029 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002030}
2031
Dmitry Shmidt04949592012-07-19 12:16:46 -07002032
2033/* only update beacons if started */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002034int ieee802_11_update_beacons(struct hostapd_iface *iface)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002035{
2036 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002037 int ret = 0;
2038
2039 for (i = 0; i < iface->num_bss; i++) {
2040 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
2041 ieee802_11_set_beacon(iface->bss[i]) < 0)
2042 ret = -1;
2043 }
2044
2045 return ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002046}
2047
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002048#endif /* CONFIG_NATIVE_WINDOWS */