blob: eaa403326c0ad71a511c1e0a2968673722abb926 [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,
467 int is_p2p, size_t *resp_len)
468{
469 struct ieee80211_mgmt *resp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800470 u8 *pos, *epos, *csa_pos;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800471 size_t buflen;
472
473#define MAX_PROBERESP_LEN 768
474 buflen = MAX_PROBERESP_LEN;
475#ifdef CONFIG_WPS
476 if (hapd->wps_probe_resp_ie)
477 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
478#endif /* CONFIG_WPS */
479#ifdef CONFIG_P2P
480 if (hapd->p2p_probe_resp_ie)
481 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
482#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800483#ifdef CONFIG_FST
484 if (hapd->iface->fst_ies)
485 buflen += wpabuf_len(hapd->iface->fst_ies);
486#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700487 if (hapd->conf->vendor_elements)
488 buflen += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800489 if (hapd->conf->vendor_vht) {
490 buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
491 2 + sizeof(struct ieee80211_vht_operation);
492 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800493
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800494#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -0800495 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700496 buflen += 3 + sizeof(struct ieee80211_he_capabilities) +
Hai Shalom74f70d42019-02-11 14:42:39 -0800497 3 + sizeof(struct ieee80211_he_operation) +
Hai Shalom81f62d82019-07-22 12:10:00 -0700498 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
499 3 + sizeof(struct ieee80211_spatial_reuse);
Sunil Ravia04bd252022-05-02 22:54:18 -0700500 if (is_6ghz_op_class(hapd->iconf->op_class)) {
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700501 buflen += sizeof(struct ieee80211_he_6ghz_oper_info) +
502 3 + sizeof(struct ieee80211_he_6ghz_band_cap);
Sunil Ravia04bd252022-05-02 22:54:18 -0700503 /* An additional Transmit Power Envelope element for
504 * subordinate client */
505 if (hapd->iconf->he_6ghz_reg_pwr_type ==
506 HE_6GHZ_INDOOR_AP)
507 buflen += 4;
508 }
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800509 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700510#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800511
Sunil Ravia04bd252022-05-02 22:54:18 -0700512#ifdef CONFIG_IEEE80211BE
513 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
514 buflen += hostapd_eid_eht_capab_len(hapd, IEEE80211_MODE_AP);
515 buflen += 3 + sizeof(struct ieee80211_eht_operation);
516 }
517#endif /* CONFIG_IEEE80211BE */
518
Hai Shaloma20dcd72022-02-04 13:43:00 -0800519 buflen += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_PROBE_RESP);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800520 buflen += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700521 buflen += hostapd_eid_owe_trans_len(hapd);
Hai Shalomfdcde762020-04-02 11:19:20 -0700522 buflen += hostapd_eid_dpp_cc_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800523
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800524 resp = os_zalloc(buflen);
525 if (resp == NULL)
526 return NULL;
527
528 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
529
530 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
531 WLAN_FC_STYPE_PROBE_RESP);
532 if (req)
533 os_memcpy(resp->da, req->sa, ETH_ALEN);
534 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
535
536 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
537 resp->u.probe_resp.beacon_int =
538 host_to_le16(hapd->iconf->beacon_int);
539
540 /* hardware or low-level driver will setup seq_ctrl and timestamp */
541 resp->u.probe_resp.capab_info =
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700542 host_to_le16(hostapd_own_capab_info(hapd));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800543
544 pos = resp->u.probe_resp.variable;
545 *pos++ = WLAN_EID_SSID;
546 *pos++ = hapd->conf->ssid.ssid_len;
547 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
548 pos += hapd->conf->ssid.ssid_len;
549
550 /* Supported rates */
551 pos = hostapd_eid_supp_rates(hapd, pos);
552
553 /* DS Params */
554 pos = hostapd_eid_ds_params(hapd, pos);
555
556 pos = hostapd_eid_country(hapd, pos, epos - pos);
557
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800558 /* Power Constraint element */
559 pos = hostapd_eid_pwr_constraint(hapd, pos);
560
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800561 /* CSA IE */
562 csa_pos = hostapd_eid_csa(hapd, pos);
563 if (csa_pos != pos)
564 hapd->cs_c_off_proberesp = csa_pos - (u8 *) resp - 1;
565 pos = csa_pos;
566
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800567 /* ERP Information element */
568 pos = hostapd_eid_erp_info(hapd, pos);
569
570 /* Extended supported rates */
571 pos = hostapd_eid_ext_supp_rates(hapd, pos);
572
Hai Shalomfdcde762020-04-02 11:19:20 -0700573 pos = hostapd_get_rsne(hapd, pos, epos - pos);
Dmitry Shmidt051af732013-10-22 13:52:46 -0700574 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800575 pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700576 pos = hostapd_get_mde(hapd, pos, epos - pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800577
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800578 /* eCSA IE */
579 csa_pos = hostapd_eid_ecsa(hapd, pos);
580 if (csa_pos != pos)
581 hapd->cs_c_off_ecsa_proberesp = csa_pos - (u8 *) resp - 1;
582 pos = csa_pos;
583
584 pos = hostapd_eid_supported_op_classes(hapd, pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800585 pos = hostapd_eid_ht_capabilities(hapd, pos);
586 pos = hostapd_eid_ht_operation(hapd, pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800587
588 pos = hostapd_eid_ext_capab(hapd, pos);
589
590 pos = hostapd_eid_time_adv(hapd, pos);
591 pos = hostapd_eid_time_zone(hapd, pos);
592
593 pos = hostapd_eid_interworking(hapd, pos);
594 pos = hostapd_eid_adv_proto(hapd, pos);
595 pos = hostapd_eid_roaming_consortium(hapd, pos);
596
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800597#ifdef CONFIG_FST
598 if (hapd->iface->fst_ies) {
599 os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies),
600 wpabuf_len(hapd->iface->fst_ies));
601 pos += wpabuf_len(hapd->iface->fst_ies);
602 }
603#endif /* CONFIG_FST */
604
Dmitry Shmidt04949592012-07-19 12:16:46 -0700605#ifdef CONFIG_IEEE80211AC
Hai Shalomc3565922019-10-28 11:58:20 -0700606 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
607 !is_6ghz_op_class(hapd->iconf->op_class)) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700608 pos = hostapd_eid_vht_capabilities(hapd, pos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800609 pos = hostapd_eid_vht_operation(hapd, pos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800610 pos = hostapd_eid_txpower_envelope(hapd, pos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800611 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800612#endif /* CONFIG_IEEE80211AC */
613
Hai Shalom60840252021-02-19 19:02:11 -0800614#ifdef CONFIG_IEEE80211AX
615 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax &&
616 is_6ghz_op_class(hapd->iconf->op_class))
617 pos = hostapd_eid_txpower_envelope(hapd, pos);
618#endif /* CONFIG_IEEE80211AX */
619
Hai Shaloma20dcd72022-02-04 13:43:00 -0800620 pos = hostapd_eid_wb_chsw_wrapper(hapd, pos);
Hai Shalom899fcc72020-10-19 14:38:18 -0700621
Hai Shaloma20dcd72022-02-04 13:43:00 -0800622 pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_PROBE_RESP);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800623 pos = hostapd_eid_fils_indic(hapd, pos, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -0700624 pos = hostapd_get_rsnxe(hapd, pos, epos - pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800625
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700626#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -0800627 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Sunil Ravia04bd252022-05-02 22:54:18 -0700628 u8 *cca_pos;
629
Hai Shalom81f62d82019-07-22 12:10:00 -0700630 pos = hostapd_eid_he_capab(hapd, pos, IEEE80211_MODE_AP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700631 pos = hostapd_eid_he_operation(hapd, pos);
Sunil Ravia04bd252022-05-02 22:54:18 -0700632
633 /* BSS Color Change Announcement element */
634 cca_pos = hostapd_eid_cca(hapd, pos);
635 if (cca_pos != pos)
636 hapd->cca_c_off_proberesp = cca_pos - (u8 *) resp - 2;
637 pos = cca_pos;
638
Hai Shalom81f62d82019-07-22 12:10:00 -0700639 pos = hostapd_eid_spatial_reuse(hapd, pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700640 pos = hostapd_eid_he_mu_edca_parameter_set(hapd, pos);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700641 pos = hostapd_eid_he_6ghz_band_cap(hapd, pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700642 }
643#endif /* CONFIG_IEEE80211AX */
644
Sunil Ravia04bd252022-05-02 22:54:18 -0700645#ifdef CONFIG_IEEE80211BE
646 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
647 pos = hostapd_eid_eht_capab(hapd, pos, IEEE80211_MODE_AP);
648 pos = hostapd_eid_eht_operation(hapd, pos);
649 }
650#endif /* CONFIG_IEEE80211BE */
651
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800652#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800653 if (hapd->conf->vendor_vht)
654 pos = hostapd_eid_vendor_vht(hapd, pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700655#endif /* CONFIG_IEEE80211AC */
656
Hai Shalomfdcde762020-04-02 11:19:20 -0700657 /* WPA / OSEN */
658 pos = hostapd_get_wpa_ie(hapd, pos, epos - pos);
659 pos = hostapd_get_osen_ie(hapd, pos, epos - pos);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800660
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800661 /* Wi-Fi Alliance WMM */
662 pos = hostapd_eid_wmm(hapd, pos);
663
664#ifdef CONFIG_WPS
665 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
666 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
667 wpabuf_len(hapd->wps_probe_resp_ie));
668 pos += wpabuf_len(hapd->wps_probe_resp_ie);
669 }
670#endif /* CONFIG_WPS */
671
672#ifdef CONFIG_P2P
673 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
674 hapd->p2p_probe_resp_ie) {
675 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
676 wpabuf_len(hapd->p2p_probe_resp_ie));
677 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
678 }
679#endif /* CONFIG_P2P */
680#ifdef CONFIG_P2P_MANAGER
681 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
682 P2P_MANAGE)
683 pos = hostapd_eid_p2p_manage(hapd, pos);
684#endif /* CONFIG_P2P_MANAGER */
685
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700686#ifdef CONFIG_HS20
687 pos = hostapd_eid_hs20_indication(hapd, pos);
688#endif /* CONFIG_HS20 */
689
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800690 pos = hostapd_eid_mbo(hapd, pos, (u8 *) resp + buflen - pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700691 pos = hostapd_eid_owe_trans(hapd, pos, (u8 *) resp + buflen - pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700692 pos = hostapd_eid_dpp_cc(hapd, pos, (u8 *) resp + buflen - pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800693
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700694 if (hapd->conf->vendor_elements) {
695 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
696 wpabuf_len(hapd->conf->vendor_elements));
697 pos += wpabuf_len(hapd->conf->vendor_elements);
698 }
699
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800700 *resp_len = pos - (u8 *) resp;
701 return (u8 *) resp;
702}
703
704
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800705enum ssid_match_result {
706 NO_SSID_MATCH,
707 EXACT_SSID_MATCH,
Hai Shaloma20dcd72022-02-04 13:43:00 -0800708 WILDCARD_SSID_MATCH,
709 CO_LOCATED_SSID_MATCH,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800710};
711
712static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
713 const u8 *ssid, size_t ssid_len,
714 const u8 *ssid_list,
Hai Shalomfdcde762020-04-02 11:19:20 -0700715 size_t ssid_list_len,
716 const u8 *short_ssid_list,
717 size_t short_ssid_list_len)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800718{
719 const u8 *pos, *end;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800720 struct hostapd_iface *iface = hapd->iface;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800721 int wildcard = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800722 size_t i, j;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800723
724 if (ssid_len == 0)
725 wildcard = 1;
726 if (ssid_len == hapd->conf->ssid.ssid_len &&
727 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
728 return EXACT_SSID_MATCH;
729
Hai Shalomfdcde762020-04-02 11:19:20 -0700730 if (ssid_list) {
731 pos = ssid_list;
732 end = ssid_list + ssid_list_len;
733 while (end - pos >= 2) {
734 if (2 + pos[1] > end - pos)
735 break;
736 if (pos[1] == 0)
737 wildcard = 1;
738 if (pos[1] == hapd->conf->ssid.ssid_len &&
739 os_memcmp(pos + 2, hapd->conf->ssid.ssid,
740 pos[1]) == 0)
741 return EXACT_SSID_MATCH;
742 pos += 2 + pos[1];
743 }
744 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800745
Hai Shalomfdcde762020-04-02 11:19:20 -0700746 if (short_ssid_list) {
747 pos = short_ssid_list;
748 end = short_ssid_list + short_ssid_list_len;
749 while (end - pos >= 4) {
750 if (hapd->conf->ssid.short_ssid == WPA_GET_LE32(pos))
751 return EXACT_SSID_MATCH;
752 pos += 4;
753 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800754 }
755
Hai Shaloma20dcd72022-02-04 13:43:00 -0800756 if (wildcard)
757 return WILDCARD_SSID_MATCH;
758
759 if (!iface->interfaces || iface->interfaces->count <= 1 ||
760 is_6ghz_op_class(hapd->iconf->op_class))
761 return NO_SSID_MATCH;
762
763 for (i = 0; i < iface->interfaces->count; i++) {
764 struct hostapd_iface *colocated;
765
766 colocated = iface->interfaces->iface[i];
767
768 if (colocated == iface ||
769 !is_6ghz_op_class(colocated->conf->op_class))
770 continue;
771
772 for (j = 0; j < colocated->num_bss; j++) {
773 struct hostapd_bss_config *conf;
774
775 conf = colocated->bss[j]->conf;
776 if (ssid_len == conf->ssid.ssid_len &&
777 os_memcmp(ssid, conf->ssid.ssid, ssid_len) == 0)
778 return CO_LOCATED_SSID_MATCH;
779 }
780 }
781
782 return NO_SSID_MATCH;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800783}
784
785
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800786void sta_track_expire(struct hostapd_iface *iface, int force)
787{
788 struct os_reltime now;
789 struct hostapd_sta_info *info;
790
791 if (!iface->num_sta_seen)
792 return;
793
794 os_get_reltime(&now);
795 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
796 list))) {
797 if (!force &&
798 !os_reltime_expired(&now, &info->last_seen,
799 iface->conf->track_sta_max_age))
800 break;
801 force = 0;
802
803 wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
804 MACSTR, iface->bss[0]->conf->iface,
805 MAC2STR(info->addr));
806 dl_list_del(&info->list);
807 iface->num_sta_seen--;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700808 sta_track_del(info);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800809 }
810}
811
812
813static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
814 const u8 *addr)
815{
816 struct hostapd_sta_info *info;
817
818 dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
819 if (os_memcmp(addr, info->addr, ETH_ALEN) == 0)
820 return info;
821
822 return NULL;
823}
824
825
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800826void sta_track_add(struct hostapd_iface *iface, const u8 *addr, int ssi_signal)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800827{
828 struct hostapd_sta_info *info;
829
830 info = sta_track_get(iface, addr);
831 if (info) {
832 /* Move the most recent entry to the end of the list */
833 dl_list_del(&info->list);
834 dl_list_add_tail(&iface->sta_seen, &info->list);
835 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800836 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800837 return;
838 }
839
840 /* Add a new entry */
841 info = os_zalloc(sizeof(*info));
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700842 if (info == NULL)
843 return;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800844 os_memcpy(info->addr, addr, ETH_ALEN);
845 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800846 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800847
848 if (iface->num_sta_seen >= iface->conf->track_sta_max_num) {
849 /* Expire oldest entry to make room for a new one */
850 sta_track_expire(iface, 1);
851 }
852
853 wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
854 MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr));
855 dl_list_add_tail(&iface->sta_seen, &info->list);
856 iface->num_sta_seen++;
857}
858
859
860struct hostapd_data *
861sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
862 const char *ifname)
863{
864 struct hapd_interfaces *interfaces = iface->interfaces;
865 size_t i, j;
866
867 for (i = 0; i < interfaces->count; i++) {
868 struct hostapd_data *hapd = NULL;
869
870 iface = interfaces->iface[i];
871 for (j = 0; j < iface->num_bss; j++) {
872 hapd = iface->bss[j];
873 if (os_strcmp(ifname, hapd->conf->iface) == 0)
874 break;
875 hapd = NULL;
876 }
877
878 if (hapd && sta_track_get(iface, addr))
879 return hapd;
880 }
881
882 return NULL;
883}
884
885
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700886#ifdef CONFIG_TAXONOMY
887void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr,
888 struct wpabuf **probe_ie_taxonomy)
889{
890 struct hostapd_sta_info *info;
891
892 info = sta_track_get(iface, addr);
893 if (!info)
894 return;
895
896 wpabuf_free(*probe_ie_taxonomy);
897 *probe_ie_taxonomy = info->probe_ie_taxonomy;
898 info->probe_ie_taxonomy = NULL;
899}
900#endif /* CONFIG_TAXONOMY */
901
902
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700903void handle_probe_req(struct hostapd_data *hapd,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700904 const struct ieee80211_mgmt *mgmt, size_t len,
905 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700906{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800907 u8 *resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700908 struct ieee802_11_elems elems;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700909 const u8 *ie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800910 size_t ie_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800911 size_t i, resp_len;
912 int noack;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800913 enum ssid_match_result res;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800914 int ret;
915 u16 csa_offs[2];
916 size_t csa_offs_len;
Hai Shalomfdcde762020-04-02 11:19:20 -0700917 struct radius_sta rad_info;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700918
Hai Shalom60840252021-02-19 19:02:11 -0800919 if (hapd->iconf->rssi_ignore_probe_request && ssi_signal &&
920 ssi_signal < hapd->iconf->rssi_ignore_probe_request)
921 return;
922
Dmitry Shmidte4663042016-04-04 10:07:49 -0700923 if (len < IEEE80211_HDRLEN)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700924 return;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700925 ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800926 if (hapd->iconf->track_sta_max_num)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800927 sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
Dmitry Shmidte4663042016-04-04 10:07:49 -0700928 ie_len = len - IEEE80211_HDRLEN;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700929
Hai Shalomfdcde762020-04-02 11:19:20 -0700930 ret = hostapd_allowed_address(hapd, mgmt->sa, (const u8 *) mgmt, len,
931 &rad_info, 1);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700932 if (ret == HOSTAPD_ACL_REJECT) {
933 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
934 "Ignore Probe Request frame from " MACSTR
935 " due to ACL reject ", MAC2STR(mgmt->sa));
936 return;
937 }
938
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700939 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
940 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800941 mgmt->sa, mgmt->da, mgmt->bssid,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700942 ie, ie_len, ssi_signal) > 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700943 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800944
Hai Shalom74f70d42019-02-11 14:42:39 -0800945 if (!hapd->conf->send_probe_response)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700946 return;
947
948 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
949 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
950 MAC2STR(mgmt->sa));
951 return;
952 }
953
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700954 if ((!elems.ssid || !elems.supp_rates)) {
955 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
956 "without SSID or supported rates element",
957 MAC2STR(mgmt->sa));
958 return;
959 }
960
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800961 /*
962 * No need to reply if the Probe Request frame was sent on an adjacent
963 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
964 * AP with dot11RadioMeasurementActivated set to true, but strictly
965 * speaking does not allow such ignoring of Probe Request frames if
966 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
967 * number of unnecessary Probe Response frames for cases where the STA
968 * is less likely to see them (Probe Request frame sent on a
969 * neighboring, but partially overlapping, channel).
970 */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700971 if (elems.ds_params &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800972 hapd->iface->current_mode &&
973 (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
974 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
975 hapd->iconf->channel != elems.ds_params[0]) {
976 wpa_printf(MSG_DEBUG,
977 "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
978 hapd->iconf->channel, elems.ds_params[0]);
979 return;
980 }
981
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700982#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800983 if (hapd->p2p && hapd->p2p_group && elems.wps_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700984 struct wpabuf *wps;
985 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
986 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
987 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
988 "due to mismatch with Requested Device "
989 "Type");
990 wpabuf_free(wps);
991 return;
992 }
993 wpabuf_free(wps);
994 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800995
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800996 if (hapd->p2p && hapd->p2p_group && elems.p2p) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800997 struct wpabuf *p2p;
998 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
999 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
1000 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
1001 "due to mismatch with Device ID");
1002 wpabuf_free(p2p);
1003 return;
1004 }
1005 wpabuf_free(p2p);
1006 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001007#endif /* CONFIG_P2P */
1008
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001009 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
Hai Shalomfdcde762020-04-02 11:19:20 -07001010 elems.ssid_list_len == 0 && elems.short_ssid_list_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001011 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
1012 "broadcast SSID ignored", MAC2STR(mgmt->sa));
1013 return;
1014 }
1015
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001016#ifdef CONFIG_P2P
1017 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1018 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
1019 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
1020 P2P_WILDCARD_SSID_LEN) == 0) {
1021 /* Process P2P Wildcard SSID like Wildcard SSID */
1022 elems.ssid_len = 0;
1023 }
1024#endif /* CONFIG_P2P */
1025
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001026#ifdef CONFIG_TAXONOMY
1027 {
1028 struct sta_info *sta;
1029 struct hostapd_sta_info *info;
1030
1031 if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) {
1032 taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len);
1033 } else if ((info = sta_track_get(hapd->iface,
1034 mgmt->sa)) != NULL) {
1035 taxonomy_hostapd_sta_info_probe_req(hapd, info,
1036 ie, ie_len);
1037 }
1038 }
1039#endif /* CONFIG_TAXONOMY */
1040
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001041 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
Hai Shalomfdcde762020-04-02 11:19:20 -07001042 elems.ssid_list, elems.ssid_list_len,
1043 elems.short_ssid_list, elems.short_ssid_list_len);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001044 if (res == NO_SSID_MATCH) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001045 if (!(mgmt->da[0] & 0x01)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001046 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001047 " for foreign SSID '%s' (DA " MACSTR ")%s",
Dmitry Shmidt3c479372014-02-04 10:50:36 -08001048 MAC2STR(mgmt->sa),
1049 wpa_ssid_txt(elems.ssid, elems.ssid_len),
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001050 MAC2STR(mgmt->da),
1051 elems.ssid_list ? " (SSID list)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001052 }
1053 return;
1054 }
1055
Hai Shalomfdcde762020-04-02 11:19:20 -07001056 if (hapd->conf->ignore_broadcast_ssid && res == WILDCARD_SSID_MATCH) {
1057 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
1058 "broadcast SSID ignored", MAC2STR(mgmt->sa));
1059 return;
1060 }
1061
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001062#ifdef CONFIG_INTERWORKING
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -07001063 if (hapd->conf->interworking &&
1064 elems.interworking && elems.interworking_len >= 1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001065 u8 ant = elems.interworking[0] & 0x0f;
1066 if (ant != INTERWORKING_ANT_WILDCARD &&
1067 ant != hapd->conf->access_network_type) {
1068 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
1069 " for mismatching ANT %u ignored",
1070 MAC2STR(mgmt->sa), ant);
1071 return;
1072 }
1073 }
1074
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -07001075 if (hapd->conf->interworking && elems.interworking &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001076 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
1077 const u8 *hessid;
1078 if (elems.interworking_len == 7)
1079 hessid = elems.interworking + 1;
1080 else
1081 hessid = elems.interworking + 1 + 2;
1082 if (!is_broadcast_ether_addr(hessid) &&
1083 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
1084 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
1085 " for mismatching HESSID " MACSTR
1086 " ignored",
1087 MAC2STR(mgmt->sa), MAC2STR(hessid));
1088 return;
1089 }
1090 }
1091#endif /* CONFIG_INTERWORKING */
1092
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001093#ifdef CONFIG_P2P
1094 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1095 supp_rates_11b_only(&elems)) {
1096 /* Indicates support for 11b rates only */
1097 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
1098 MACSTR " with only 802.11b rates",
1099 MAC2STR(mgmt->sa));
1100 return;
1101 }
1102#endif /* CONFIG_P2P */
1103
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001104 /* TODO: verify that supp_rates contains at least one matching rate
1105 * with AP configuration */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001106
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001107 if (hapd->conf->no_probe_resp_if_seen_on &&
1108 is_multicast_ether_addr(mgmt->da) &&
1109 is_multicast_ether_addr(mgmt->bssid) &&
1110 sta_track_seen_on(hapd->iface, mgmt->sa,
1111 hapd->conf->no_probe_resp_if_seen_on)) {
1112 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1113 " since STA has been seen on %s",
1114 hapd->conf->iface, MAC2STR(mgmt->sa),
1115 hapd->conf->no_probe_resp_if_seen_on);
1116 return;
1117 }
1118
1119 if (hapd->conf->no_probe_resp_if_max_sta &&
1120 is_multicast_ether_addr(mgmt->da) &&
1121 is_multicast_ether_addr(mgmt->bssid) &&
1122 hapd->num_sta >= hapd->conf->max_num_sta &&
1123 !ap_get_sta(hapd, mgmt->sa)) {
1124 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1125 " since no room for additional STA",
1126 hapd->conf->iface, MAC2STR(mgmt->sa));
1127 return;
1128 }
1129
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001130#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001131 if (hapd->iconf->ignore_probe_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001132 drand48() < hapd->iconf->ignore_probe_probability) {
1133 wpa_printf(MSG_INFO,
1134 "TESTING: ignoring probe request from " MACSTR,
1135 MAC2STR(mgmt->sa));
1136 return;
1137 }
1138#endif /* CONFIG_TESTING_OPTIONS */
1139
Roshan Pius3a1667e2018-07-03 15:17:14 -07001140 wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, RX_PROBE_REQUEST "sa=" MACSTR
1141 " signal=%d", MAC2STR(mgmt->sa), ssi_signal);
1142
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001143 resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001144 &resp_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001145 if (resp == NULL)
1146 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001147
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001148 /*
1149 * If this is a broadcast probe request, apply no ack policy to avoid
1150 * excessive retries.
1151 */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001152 noack = !!(res == WILDCARD_SSID_MATCH &&
1153 is_broadcast_ether_addr(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001154
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001155 csa_offs_len = 0;
1156 if (hapd->csa_in_progress) {
1157 if (hapd->cs_c_off_proberesp)
1158 csa_offs[csa_offs_len++] =
1159 hapd->cs_c_off_proberesp;
1160
1161 if (hapd->cs_c_off_ecsa_proberesp)
1162 csa_offs[csa_offs_len++] =
1163 hapd->cs_c_off_ecsa_proberesp;
1164 }
1165
Hai Shalomfdcde762020-04-02 11:19:20 -07001166 ret = hostapd_drv_send_mlme(hapd, resp, resp_len, noack,
1167 csa_offs_len ? csa_offs : NULL,
1168 csa_offs_len, 0);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001169
1170 if (ret < 0)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001171 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001172
1173 os_free(resp);
1174
1175 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
1176 "SSID", MAC2STR(mgmt->sa),
1177 elems.ssid_len == 0 ? "broadcast" : "our");
1178}
1179
1180
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001181static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
1182 size_t *resp_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001183{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001184 /* check probe response offloading caps and print warnings */
1185 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
1186 return NULL;
1187
1188#ifdef CONFIG_WPS
1189 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
1190 (!(hapd->iface->probe_resp_offloads &
1191 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
1192 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
1193 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
1194 "Probe Response while not supporting this");
1195#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001196
1197#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001198 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
1199 !(hapd->iface->probe_resp_offloads &
1200 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
1201 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
1202 "Probe Response while not supporting this");
1203#endif /* CONFIG_P2P */
1204
1205 if (hapd->conf->interworking &&
1206 !(hapd->iface->probe_resp_offloads &
1207 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
1208 wpa_printf(MSG_WARNING, "Device is trying to offload "
1209 "Interworking Probe Response while not supporting "
1210 "this");
1211
1212 /* Generate a Probe Response template for the non-P2P case */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001213 return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001214}
1215
1216#endif /* NEED_AP_MLME */
1217
1218
Hai Shalom60840252021-02-19 19:02:11 -08001219#ifdef CONFIG_IEEE80211AX
1220/* Unsolicited broadcast Probe Response transmission, 6 GHz only */
1221static u8 * hostapd_unsol_bcast_probe_resp(struct hostapd_data *hapd,
1222 struct wpa_driver_ap_params *params)
1223{
1224 if (!is_6ghz_op_class(hapd->iconf->op_class))
1225 return NULL;
1226
1227 params->unsol_bcast_probe_resp_interval =
1228 hapd->conf->unsol_bcast_probe_resp_interval;
1229
1230 return hostapd_gen_probe_resp(hapd, NULL, 0,
1231 &params->unsol_bcast_probe_resp_tmpl_len);
1232}
1233#endif /* CONFIG_IEEE80211AX */
1234
1235
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001236void sta_track_del(struct hostapd_sta_info *info)
1237{
1238#ifdef CONFIG_TAXONOMY
1239 wpabuf_free(info->probe_ie_taxonomy);
1240 info->probe_ie_taxonomy = NULL;
1241#endif /* CONFIG_TAXONOMY */
1242 os_free(info);
1243}
1244
1245
Hai Shalom60840252021-02-19 19:02:11 -08001246#ifdef CONFIG_FILS
1247
1248static u16 hostapd_fils_discovery_cap(struct hostapd_data *hapd)
1249{
1250 u16 cap_info, phy_index = 0;
1251 u8 chwidth = FD_CAP_BSS_CHWIDTH_20, mcs_nss_size = 4;
1252 struct hostapd_hw_modes *mode = hapd->iface->current_mode;
1253
1254 cap_info = FD_CAP_ESS;
1255 if (hapd->conf->wpa)
1256 cap_info |= FD_CAP_PRIVACY;
1257
1258 if (is_6ghz_op_class(hapd->iconf->op_class)) {
1259 phy_index = FD_CAP_PHY_INDEX_HE;
1260
1261 switch (hapd->iconf->op_class) {
1262 case 135:
1263 mcs_nss_size += 4;
1264 /* fallthrough */
1265 case 134:
1266 mcs_nss_size += 4;
1267 chwidth = FD_CAP_BSS_CHWIDTH_160_80_80;
1268 break;
1269 case 133:
1270 chwidth = FD_CAP_BSS_CHWIDTH_80;
1271 break;
1272 case 132:
1273 chwidth = FD_CAP_BSS_CHWIDTH_40;
1274 break;
1275 }
1276 } else {
1277 switch (hostapd_get_oper_chwidth(hapd->iconf)) {
1278 case CHANWIDTH_80P80MHZ:
1279 mcs_nss_size += 4;
1280 /* fallthrough */
1281 case CHANWIDTH_160MHZ:
1282 mcs_nss_size += 4;
1283 chwidth = FD_CAP_BSS_CHWIDTH_160_80_80;
1284 break;
1285 case CHANWIDTH_80MHZ:
1286 chwidth = FD_CAP_BSS_CHWIDTH_80;
1287 break;
1288 case CHANWIDTH_USE_HT:
1289 if (hapd->iconf->secondary_channel)
1290 chwidth = FD_CAP_BSS_CHWIDTH_40;
1291 else
1292 chwidth = FD_CAP_BSS_CHWIDTH_20;
1293 break;
1294 }
1295
1296#ifdef CONFIG_IEEE80211AX
1297 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax)
1298 phy_index = FD_CAP_PHY_INDEX_HE;
1299#endif /* CONFIG_IEEE80211AX */
1300#ifdef CONFIG_IEEE80211AC
1301 if (!phy_index &&
1302 hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac)
1303 phy_index = FD_CAP_PHY_INDEX_VHT;
1304#endif /* CONFIG_IEEE80211AC */
1305 if (!phy_index &&
1306 hapd->iconf->ieee80211n && !hapd->conf->disable_11n)
1307 phy_index = FD_CAP_PHY_INDEX_HT;
1308 }
1309
1310 cap_info |= phy_index << FD_CAP_PHY_INDEX_SHIFT;
1311 cap_info |= chwidth << FD_CAP_BSS_CHWIDTH_SHIFT;
1312
1313 if (mode) {
1314 u16 *mcs = (u16 *) mode->he_capab[IEEE80211_MODE_AP].mcs;
1315 int i;
1316 u16 nss = 0;
1317
1318 for (i = 0; i < HE_NSS_MAX_STREAMS; i++) {
1319 u16 nss_mask = 0x3 << (i * 2);
1320
1321 if (mcs_nss_size == 4 &&
1322 (((mcs[0] & nss_mask) == nss_mask) ||
1323 ((mcs[1] & nss_mask) == nss_mask)))
1324 continue;
1325
1326 if (mcs_nss_size == 8 &&
1327 (((mcs[2] & nss_mask) == nss_mask) ||
1328 ((mcs[3] & nss_mask) == nss_mask)))
1329 continue;
1330
1331 if (mcs_nss_size == 12 &&
1332 (((mcs[4] & nss_mask) == nss_mask) ||
1333 ((mcs[5] & nss_mask) == nss_mask)))
1334 continue;
1335
1336 nss++;
1337 }
1338
1339 if (nss > 4)
1340 cap_info |= FD_CAP_NSS_5_8 << FD_CAP_NSS_SHIFT;
1341 else if (nss)
1342 cap_info |= (nss - 1) << FD_CAP_NSS_SHIFT;
1343 }
1344
1345 return cap_info;
1346}
1347
1348
1349static u8 * hostapd_gen_fils_discovery(struct hostapd_data *hapd, size_t *len)
1350{
1351 struct ieee80211_mgmt *head;
1352 const u8 *mobility_domain;
1353 u8 *pos, *length_pos, buf[200];
1354 u16 ctl = 0;
1355 u8 fd_rsn_info[5];
1356 size_t total_len, buf_len;
1357
1358 total_len = 24 + 2 + 12;
1359
1360 /* FILS Discovery Frame Control */
1361 ctl = (sizeof(hapd->conf->ssid.short_ssid) - 1) |
1362 FD_FRAME_CTL_SHORT_SSID_PRESENT |
1363 FD_FRAME_CTL_LENGTH_PRESENT |
1364 FD_FRAME_CTL_CAP_PRESENT;
1365 total_len += 4 + 1 + 2;
1366
1367 /* Check for optional subfields and calculate length */
1368 if (wpa_auth_write_fd_rsn_info(hapd->wpa_auth, fd_rsn_info)) {
1369 ctl |= FD_FRAME_CTL_RSN_INFO_PRESENT;
1370 total_len += sizeof(fd_rsn_info);
1371 }
1372
1373 mobility_domain = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN);
1374 if (mobility_domain) {
1375 ctl |= FD_FRAME_CTL_MD_PRESENT;
1376 total_len += 3;
1377 }
1378
Hai Shaloma20dcd72022-02-04 13:43:00 -08001379 total_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_ACTION);
1380
Hai Shalom60840252021-02-19 19:02:11 -08001381 pos = hostapd_eid_fils_indic(hapd, buf, 0);
1382 buf_len = pos - buf;
1383 total_len += buf_len;
1384
Sunil Ravia04bd252022-05-02 22:54:18 -07001385#ifdef CONFIG_IEEE80211AX
1386 /* Transmit Power Envelope element(s) */
1387 if (is_6ghz_op_class(hapd->iconf->op_class)) {
1388 total_len += 4;
1389 if (hapd->iconf->he_6ghz_reg_pwr_type == HE_6GHZ_INDOOR_AP)
1390 total_len += 4;
1391 }
1392#endif /* CONFIG_IEEE80211AX */
1393
Hai Shalom60840252021-02-19 19:02:11 -08001394 head = os_zalloc(total_len);
1395 if (!head)
1396 return NULL;
1397
1398 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1399 WLAN_FC_STYPE_ACTION);
1400 os_memset(head->da, 0xff, ETH_ALEN);
1401 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1402 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1403
1404 head->u.action.category = WLAN_ACTION_PUBLIC;
1405 head->u.action.u.public_action.action = WLAN_PA_FILS_DISCOVERY;
1406
1407 pos = &head->u.action.u.public_action.variable[0];
1408
1409 /* FILS Discovery Information field */
1410
1411 /* FILS Discovery Frame Control */
1412 WPA_PUT_LE16(pos, ctl);
1413 pos += 2;
1414
1415 /* Hardware or low-level driver will fill in the Timestamp value */
1416 pos += 8;
1417
1418 /* Beacon Interval */
1419 WPA_PUT_LE16(pos, hapd->iconf->beacon_int);
1420 pos += 2;
1421
1422 /* Short SSID */
1423 WPA_PUT_LE32(pos, hapd->conf->ssid.short_ssid);
1424 pos += sizeof(hapd->conf->ssid.short_ssid);
1425
1426 /* Store position of FILS discovery information element Length field */
1427 length_pos = pos++;
1428
1429 /* FD Capability */
1430 WPA_PUT_LE16(pos, hostapd_fils_discovery_cap(hapd));
1431 pos += 2;
1432
1433 /* Operating Class - not present */
1434
1435 /* Primary Channel - not present */
1436
1437 /* AP Configuration Sequence Number - not present */
1438
1439 /* Access Network Options - not present */
1440
1441 /* FD RSN Information */
1442 if (ctl & FD_FRAME_CTL_RSN_INFO_PRESENT) {
1443 os_memcpy(pos, fd_rsn_info, sizeof(fd_rsn_info));
1444 pos += sizeof(fd_rsn_info);
1445 }
1446
1447 /* Channel Center Frequency Segment 1 - not present */
1448
1449 /* Mobility Domain */
1450 if (ctl & FD_FRAME_CTL_MD_PRESENT) {
1451 os_memcpy(pos, &mobility_domain[2], 3);
1452 pos += 3;
1453 }
1454
1455 /* Fill in the Length field value */
1456 *length_pos = pos - (length_pos + 1);
1457
Hai Shaloma20dcd72022-02-04 13:43:00 -08001458 pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_ACTION);
1459
Hai Shalom60840252021-02-19 19:02:11 -08001460 /* FILS Indication element */
1461 if (buf_len) {
1462 os_memcpy(pos, buf, buf_len);
1463 pos += buf_len;
1464 }
1465
Sunil Ravia04bd252022-05-02 22:54:18 -07001466 if (is_6ghz_op_class(hapd->iconf->op_class))
1467 pos = hostapd_eid_txpower_envelope(hapd, pos);
1468
Hai Shalom60840252021-02-19 19:02:11 -08001469 *len = pos - (u8 *) head;
1470 wpa_hexdump(MSG_DEBUG, "FILS Discovery frame template",
1471 head, pos - (u8 *) head);
1472 return (u8 *) head;
1473}
1474
1475
1476/* Configure FILS Discovery frame transmission parameters */
1477static u8 * hostapd_fils_discovery(struct hostapd_data *hapd,
1478 struct wpa_driver_ap_params *params)
1479{
1480 params->fd_max_int = hapd->conf->fils_discovery_max_int;
1481 if (is_6ghz_op_class(hapd->iconf->op_class) &&
1482 params->fd_max_int > FD_MAX_INTERVAL_6GHZ)
1483 params->fd_max_int = FD_MAX_INTERVAL_6GHZ;
1484
1485 params->fd_min_int = hapd->conf->fils_discovery_min_int;
1486 if (params->fd_min_int > params->fd_max_int)
1487 params->fd_min_int = params->fd_max_int;
1488
1489 if (params->fd_max_int)
1490 return hostapd_gen_fils_discovery(hapd,
1491 &params->fd_frame_tmpl_len);
1492
1493 return NULL;
1494}
1495
1496#endif /* CONFIG_FILS */
1497
1498
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001499int ieee802_11_build_ap_params(struct hostapd_data *hapd,
1500 struct wpa_driver_ap_params *params)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001501{
1502 struct ieee80211_mgmt *head = NULL;
1503 u8 *tail = NULL;
1504 size_t head_len = 0, tail_len = 0;
1505 u8 *resp = NULL;
1506 size_t resp_len = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001507#ifdef NEED_AP_MLME
1508 u16 capab_info;
Hai Shalomfdcde762020-04-02 11:19:20 -07001509 u8 *pos, *tailpos, *tailend, *csa_pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001510
1511#define BEACON_HEAD_BUF_SIZE 256
1512#define BEACON_TAIL_BUF_SIZE 512
1513 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
1514 tail_len = BEACON_TAIL_BUF_SIZE;
1515#ifdef CONFIG_WPS
1516 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
1517 tail_len += wpabuf_len(hapd->wps_beacon_ie);
1518#endif /* CONFIG_WPS */
1519#ifdef CONFIG_P2P
1520 if (hapd->p2p_beacon_ie)
1521 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
1522#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001523#ifdef CONFIG_FST
1524 if (hapd->iface->fst_ies)
1525 tail_len += wpabuf_len(hapd->iface->fst_ies);
1526#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001527 if (hapd->conf->vendor_elements)
1528 tail_len += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001529
1530#ifdef CONFIG_IEEE80211AC
1531 if (hapd->conf->vendor_vht) {
1532 tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
1533 2 + sizeof(struct ieee80211_vht_operation);
1534 }
1535#endif /* CONFIG_IEEE80211AC */
1536
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001537#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08001538 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001539 tail_len += 3 + sizeof(struct ieee80211_he_capabilities) +
Hai Shalom74f70d42019-02-11 14:42:39 -08001540 3 + sizeof(struct ieee80211_he_operation) +
Hai Shalom81f62d82019-07-22 12:10:00 -07001541 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
1542 3 + sizeof(struct ieee80211_spatial_reuse);
Sunil Ravia04bd252022-05-02 22:54:18 -07001543 if (is_6ghz_op_class(hapd->iconf->op_class)) {
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001544 tail_len += sizeof(struct ieee80211_he_6ghz_oper_info) +
1545 3 + sizeof(struct ieee80211_he_6ghz_band_cap);
Sunil Ravia04bd252022-05-02 22:54:18 -07001546 /* An additional Transmit Power Envelope element for
1547 * subordinate client */
1548 if (hapd->iconf->he_6ghz_reg_pwr_type ==
1549 HE_6GHZ_INDOOR_AP)
1550 tail_len += 4;
1551 }
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001552 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001553#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001554
Sunil Ravia04bd252022-05-02 22:54:18 -07001555#ifdef CONFIG_IEEE80211BE
1556 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
1557 tail_len += hostapd_eid_eht_capab_len(hapd, IEEE80211_MODE_AP);
1558 tail_len += 3 + sizeof(struct ieee80211_eht_operation);
1559 }
1560#endif /* CONFIG_IEEE80211BE */
1561
Hai Shaloma20dcd72022-02-04 13:43:00 -08001562 tail_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_BEACON);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001563 tail_len += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001564 tail_len += hostapd_eid_owe_trans_len(hapd);
Hai Shalomfdcde762020-04-02 11:19:20 -07001565 tail_len += hostapd_eid_dpp_cc_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001566
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001567 tailpos = tail = os_malloc(tail_len);
1568 if (head == NULL || tail == NULL) {
1569 wpa_printf(MSG_ERROR, "Failed to set beacon data");
1570 os_free(head);
1571 os_free(tail);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001572 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001573 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001574 tailend = tail + tail_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001575
1576 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1577 WLAN_FC_STYPE_BEACON);
1578 head->duration = host_to_le16(0);
1579 os_memset(head->da, 0xff, ETH_ALEN);
1580
1581 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1582 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1583 head->u.beacon.beacon_int =
1584 host_to_le16(hapd->iconf->beacon_int);
1585
1586 /* hardware or low-level driver will setup seq_ctrl and timestamp */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001587 capab_info = hostapd_own_capab_info(hapd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001588 head->u.beacon.capab_info = host_to_le16(capab_info);
1589 pos = &head->u.beacon.variable[0];
1590
1591 /* SSID */
1592 *pos++ = WLAN_EID_SSID;
1593 if (hapd->conf->ignore_broadcast_ssid == 2) {
1594 /* clear the data, but keep the correct length of the SSID */
1595 *pos++ = hapd->conf->ssid.ssid_len;
1596 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
1597 pos += hapd->conf->ssid.ssid_len;
1598 } else if (hapd->conf->ignore_broadcast_ssid) {
1599 *pos++ = 0; /* empty SSID */
1600 } else {
1601 *pos++ = hapd->conf->ssid.ssid_len;
1602 os_memcpy(pos, hapd->conf->ssid.ssid,
1603 hapd->conf->ssid.ssid_len);
1604 pos += hapd->conf->ssid.ssid_len;
1605 }
1606
1607 /* Supported rates */
1608 pos = hostapd_eid_supp_rates(hapd, pos);
1609
1610 /* DS Params */
1611 pos = hostapd_eid_ds_params(hapd, pos);
1612
1613 head_len = pos - (u8 *) head;
1614
Hai Shalomfdcde762020-04-02 11:19:20 -07001615 tailpos = hostapd_eid_country(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001616
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001617 /* Power Constraint element */
1618 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
1619
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001620 /* CSA IE */
1621 csa_pos = hostapd_eid_csa(hapd, tailpos);
1622 if (csa_pos != tailpos)
1623 hapd->cs_c_off_beacon = csa_pos - tail - 1;
1624 tailpos = csa_pos;
1625
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001626 /* ERP Information element */
1627 tailpos = hostapd_eid_erp_info(hapd, tailpos);
1628
1629 /* Extended supported rates */
1630 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
1631
Hai Shalomfdcde762020-04-02 11:19:20 -07001632 tailpos = hostapd_get_rsne(hapd, tailpos, tailend - tailpos);
1633 tailpos = hostapd_eid_bss_load(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001634 tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
Hai Shalomfdcde762020-04-02 11:19:20 -07001635 tailend - tailpos);
1636 tailpos = hostapd_get_mde(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001637
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001638 /* eCSA IE */
1639 csa_pos = hostapd_eid_ecsa(hapd, tailpos);
1640 if (csa_pos != tailpos)
1641 hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1;
1642 tailpos = csa_pos;
1643
1644 tailpos = hostapd_eid_supported_op_classes(hapd, tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001645 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
1646 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001647
1648 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
1649
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001650 /*
1651 * TODO: Time Advertisement element should only be included in some
1652 * DTIM Beacon frames.
1653 */
1654 tailpos = hostapd_eid_time_adv(hapd, tailpos);
1655
1656 tailpos = hostapd_eid_interworking(hapd, tailpos);
1657 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
1658 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001659
1660#ifdef CONFIG_FST
1661 if (hapd->iface->fst_ies) {
1662 os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies),
1663 wpabuf_len(hapd->iface->fst_ies));
1664 tailpos += wpabuf_len(hapd->iface->fst_ies);
1665 }
1666#endif /* CONFIG_FST */
1667
Dmitry Shmidt04949592012-07-19 12:16:46 -07001668#ifdef CONFIG_IEEE80211AC
Hai Shalom60840252021-02-19 19:02:11 -08001669 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
1670 !is_6ghz_op_class(hapd->iconf->op_class)) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -07001671 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001672 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08001673 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001674 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001675#endif /* CONFIG_IEEE80211AC */
1676
Hai Shalom60840252021-02-19 19:02:11 -08001677#ifdef CONFIG_IEEE80211AX
1678 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax &&
1679 is_6ghz_op_class(hapd->iconf->op_class))
1680 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
1681#endif /* CONFIG_IEEE80211AX */
1682
Hai Shaloma20dcd72022-02-04 13:43:00 -08001683 tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos);
Hai Shalom899fcc72020-10-19 14:38:18 -07001684
Hai Shaloma20dcd72022-02-04 13:43:00 -08001685 tailpos = hostapd_eid_rnr(hapd, tailpos, WLAN_FC_STYPE_BEACON);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001686 tailpos = hostapd_eid_fils_indic(hapd, tailpos, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -07001687 tailpos = hostapd_get_rsnxe(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001688
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001689#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08001690 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) {
Sunil Ravia04bd252022-05-02 22:54:18 -07001691 u8 *cca_pos;
1692
Hai Shalom81f62d82019-07-22 12:10:00 -07001693 tailpos = hostapd_eid_he_capab(hapd, tailpos,
1694 IEEE80211_MODE_AP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001695 tailpos = hostapd_eid_he_operation(hapd, tailpos);
Sunil Ravia04bd252022-05-02 22:54:18 -07001696
1697 /* BSS Color Change Announcement element */
1698 cca_pos = hostapd_eid_cca(hapd, tailpos);
1699 if (cca_pos != tailpos)
1700 hapd->cca_c_off_beacon = cca_pos - tail - 2;
1701 tailpos = cca_pos;
1702
Hai Shalom81f62d82019-07-22 12:10:00 -07001703 tailpos = hostapd_eid_spatial_reuse(hapd, tailpos);
Hai Shalomfdcde762020-04-02 11:19:20 -07001704 tailpos = hostapd_eid_he_mu_edca_parameter_set(hapd, tailpos);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001705 tailpos = hostapd_eid_he_6ghz_band_cap(hapd, tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001706 }
1707#endif /* CONFIG_IEEE80211AX */
1708
Sunil Ravia04bd252022-05-02 22:54:18 -07001709#ifdef CONFIG_IEEE80211BE
1710 if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) {
1711 tailpos = hostapd_eid_eht_capab(hapd, tailpos,
1712 IEEE80211_MODE_AP);
1713 tailpos = hostapd_eid_eht_operation(hapd, tailpos);
1714 }
1715#endif /* CONFIG_IEEE80211BE */
1716
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001717#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001718 if (hapd->conf->vendor_vht)
1719 tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001720#endif /* CONFIG_IEEE80211AC */
1721
Hai Shalomfdcde762020-04-02 11:19:20 -07001722 /* WPA / OSEN */
1723 tailpos = hostapd_get_wpa_ie(hapd, tailpos, tailend - tailpos);
1724 tailpos = hostapd_get_osen_ie(hapd, tailpos, tailend - tailpos);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001725
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001726 /* Wi-Fi Alliance WMM */
1727 tailpos = hostapd_eid_wmm(hapd, tailpos);
1728
1729#ifdef CONFIG_WPS
1730 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
1731 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
1732 wpabuf_len(hapd->wps_beacon_ie));
1733 tailpos += wpabuf_len(hapd->wps_beacon_ie);
1734 }
1735#endif /* CONFIG_WPS */
1736
1737#ifdef CONFIG_P2P
1738 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
1739 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
1740 wpabuf_len(hapd->p2p_beacon_ie));
1741 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
1742 }
1743#endif /* CONFIG_P2P */
1744#ifdef CONFIG_P2P_MANAGER
1745 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
1746 P2P_MANAGE)
1747 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
1748#endif /* CONFIG_P2P_MANAGER */
1749
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001750#ifdef CONFIG_HS20
1751 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
1752#endif /* CONFIG_HS20 */
1753
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001754 tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001755 tailpos = hostapd_eid_owe_trans(hapd, tailpos,
1756 tail + tail_len - tailpos);
Hai Shalomfdcde762020-04-02 11:19:20 -07001757 tailpos = hostapd_eid_dpp_cc(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001758
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001759 if (hapd->conf->vendor_elements) {
1760 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
1761 wpabuf_len(hapd->conf->vendor_elements));
1762 tailpos += wpabuf_len(hapd->conf->vendor_elements);
1763 }
1764
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001765 tail_len = tailpos > tail ? tailpos - tail : 0;
1766
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001767 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
1768#endif /* NEED_AP_MLME */
1769
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001770 os_memset(params, 0, sizeof(*params));
1771 params->head = (u8 *) head;
1772 params->head_len = head_len;
1773 params->tail = tail;
1774 params->tail_len = tail_len;
1775 params->proberesp = resp;
1776 params->proberesp_len = resp_len;
1777 params->dtim_period = hapd->conf->dtim_period;
1778 params->beacon_int = hapd->iconf->beacon_int;
1779 params->basic_rates = hapd->iface->basic_rates;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001780 params->beacon_rate = hapd->iconf->beacon_rate;
1781 params->rate_type = hapd->iconf->rate_type;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001782 params->ssid = hapd->conf->ssid.ssid;
1783 params->ssid_len = hapd->conf->ssid.ssid_len;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001784 if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
1785 (WPA_PROTO_WPA | WPA_PROTO_RSN))
1786 params->pairwise_ciphers = hapd->conf->wpa_pairwise |
1787 hapd->conf->rsn_pairwise;
1788 else if (hapd->conf->wpa & WPA_PROTO_RSN)
1789 params->pairwise_ciphers = hapd->conf->rsn_pairwise;
1790 else if (hapd->conf->wpa & WPA_PROTO_WPA)
1791 params->pairwise_ciphers = hapd->conf->wpa_pairwise;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001792 params->group_cipher = hapd->conf->wpa_group;
1793 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
1794 params->auth_algs = hapd->conf->auth_algs;
1795 params->wpa_version = hapd->conf->wpa;
Hai Shalomfdcde762020-04-02 11:19:20 -07001796 params->privacy = hapd->conf->wpa;
1797#ifdef CONFIG_WEP
1798 params->privacy |= hapd->conf->ssid.wep.keys_set ||
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001799 (hapd->conf->ieee802_1x &&
1800 (hapd->conf->default_wep_key_len ||
1801 hapd->conf->individual_wep_key_len));
Hai Shalomfdcde762020-04-02 11:19:20 -07001802#endif /* CONFIG_WEP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001803 switch (hapd->conf->ignore_broadcast_ssid) {
1804 case 0:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001805 params->hide_ssid = NO_SSID_HIDING;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001806 break;
1807 case 1:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001808 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001809 break;
1810 case 2:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001811 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001812 break;
1813 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001814 params->isolate = hapd->conf->isolate;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001815#ifdef NEED_AP_MLME
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001816 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001817 ERP_INFO_USE_PROTECTION);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001818 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001819 hapd->iconf->preamble == SHORT_PREAMBLE;
1820 if (hapd->iface->current_mode &&
1821 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001822 params->short_slot_time =
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001823 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
1824 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001825 params->short_slot_time = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001826 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001827 params->ht_opmode = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001828 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001829 params->ht_opmode = hapd->iface->ht_op_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001830#endif /* NEED_AP_MLME */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001831 params->interworking = hapd->conf->interworking;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001832 if (hapd->conf->interworking &&
1833 !is_zero_ether_addr(hapd->conf->hessid))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001834 params->hessid = hapd->conf->hessid;
1835 params->access_network_type = hapd->conf->access_network_type;
1836 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001837#ifdef CONFIG_P2P
1838 params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
1839#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001840#ifdef CONFIG_HS20
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001841 params->disable_dgaf = hapd->conf->disable_dgaf;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001842 if (hapd->conf->osen) {
1843 params->privacy = 1;
1844 params->osen = 1;
1845 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001846#endif /* CONFIG_HS20 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001847 params->multicast_to_unicast = hapd->conf->multicast_to_unicast;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001848 params->pbss = hapd->conf->pbss;
Hai Shalom74f70d42019-02-11 14:42:39 -08001849
1850 if (hapd->conf->ftm_responder) {
1851 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_FTM_RESPONDER) {
1852 params->ftm_responder = 1;
1853 params->lci = hapd->iface->conf->lci;
1854 params->civic = hapd->iface->conf->civic;
1855 } else {
1856 wpa_printf(MSG_WARNING,
1857 "Not configuring FTM responder as the driver doesn't advertise support for it");
1858 }
1859 }
1860
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001861 return 0;
1862}
1863
1864
1865void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
1866{
1867 os_free(params->tail);
1868 params->tail = NULL;
1869 os_free(params->head);
1870 params->head = NULL;
1871 os_free(params->proberesp);
1872 params->proberesp = NULL;
Hai Shalom60840252021-02-19 19:02:11 -08001873#ifdef CONFIG_FILS
1874 os_free(params->fd_frame_tmpl);
1875 params->fd_frame_tmpl = NULL;
1876#endif /* CONFIG_FILS */
1877#ifdef CONFIG_IEEE80211AX
1878 os_free(params->unsol_bcast_probe_resp_tmpl);
1879 params->unsol_bcast_probe_resp_tmpl = NULL;
1880#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001881}
1882
1883
Hai Shaloma20dcd72022-02-04 13:43:00 -08001884static int __ieee802_11_set_beacon(struct hostapd_data *hapd)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001885{
1886 struct wpa_driver_ap_params params;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001887 struct hostapd_freq_params freq;
1888 struct hostapd_iface *iface = hapd->iface;
1889 struct hostapd_config *iconf = iface->conf;
Hai Shalom81f62d82019-07-22 12:10:00 -07001890 struct hostapd_hw_modes *cmode = iface->current_mode;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001891 struct wpabuf *beacon, *proberesp, *assocresp;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001892 int res, ret = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001893
Hai Shaloma20dcd72022-02-04 13:43:00 -08001894 if (!hapd->drv_priv) {
1895 wpa_printf(MSG_ERROR, "Interface is disabled");
1896 return -1;
1897 }
1898
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001899 if (hapd->csa_in_progress) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001900 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001901 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001902 }
1903
1904 hapd->beacon_set_done = 1;
1905
1906 if (ieee802_11_build_ap_params(hapd, &params) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001907 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001908
1909 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
1910 0)
1911 goto fail;
1912
1913 params.beacon_ies = beacon;
1914 params.proberesp_ies = proberesp;
1915 params.assocresp_ies = assocresp;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001916 params.reenable = hapd->reenable_beacon;
Hai Shalomc3565922019-10-28 11:58:20 -07001917#ifdef CONFIG_IEEE80211AX
Hai Shalom60840252021-02-19 19:02:11 -08001918 params.he_spr_ctrl = hapd->iface->conf->spr.sr_control;
1919 params.he_spr_non_srg_obss_pd_max_offset =
1920 hapd->iface->conf->spr.non_srg_obss_pd_max_offset;
Hai Shalomc3565922019-10-28 11:58:20 -07001921 params.he_spr_srg_obss_pd_min_offset =
1922 hapd->iface->conf->spr.srg_obss_pd_min_offset;
1923 params.he_spr_srg_obss_pd_max_offset =
1924 hapd->iface->conf->spr.srg_obss_pd_max_offset;
Hai Shalom60840252021-02-19 19:02:11 -08001925 os_memcpy(params.he_spr_bss_color_bitmap,
1926 hapd->iface->conf->spr.srg_bss_color_bitmap, 8);
1927 os_memcpy(params.he_spr_partial_bssid_bitmap,
1928 hapd->iface->conf->spr.srg_partial_bssid_bitmap, 8);
Hai Shalomfdcde762020-04-02 11:19:20 -07001929 params.he_bss_color_disabled =
1930 hapd->iface->conf->he_op.he_bss_color_disabled;
1931 params.he_bss_color_partial =
1932 hapd->iface->conf->he_op.he_bss_color_partial;
1933 params.he_bss_color = hapd->iface->conf->he_op.he_bss_color;
1934 params.twt_responder = hostapd_get_he_twt_responder(hapd,
1935 IEEE80211_MODE_AP);
Hai Shalom60840252021-02-19 19:02:11 -08001936 params.unsol_bcast_probe_resp_tmpl =
1937 hostapd_unsol_bcast_probe_resp(hapd, &params);
Hai Shalomc3565922019-10-28 11:58:20 -07001938#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001939 hapd->reenable_beacon = 0;
Hai Shalom60840252021-02-19 19:02:11 -08001940#ifdef CONFIG_SAE
1941 params.sae_pwe = hapd->conf->sae_pwe;
1942#endif /* CONFIG_SAE */
1943
1944#ifdef CONFIG_FILS
1945 params.fd_frame_tmpl = hostapd_fils_discovery(hapd, &params);
1946#endif /* CONFIG_FILS */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001947
Hai Shalom81f62d82019-07-22 12:10:00 -07001948 if (cmode &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001949 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
Hai Shalomc3565922019-10-28 11:58:20 -07001950 iconf->channel, iconf->enable_edmg,
1951 iconf->edmg_channel, iconf->ieee80211n,
Hai Shalom81f62d82019-07-22 12:10:00 -07001952 iconf->ieee80211ac, iconf->ieee80211ax,
Sunil Ravia04bd252022-05-02 22:54:18 -07001953 iconf->ieee80211be,
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001954 iconf->secondary_channel,
Hai Shalom81f62d82019-07-22 12:10:00 -07001955 hostapd_get_oper_chwidth(iconf),
1956 hostapd_get_oper_centr_freq_seg0_idx(iconf),
1957 hostapd_get_oper_centr_freq_seg1_idx(iconf),
1958 cmode->vht_capab,
Sunil Ravia04bd252022-05-02 22:54:18 -07001959 &cmode->he_capab[IEEE80211_MODE_AP],
1960 &cmode->eht_capab[IEEE80211_MODE_AP]) == 0)
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001961 params.freq = &freq;
1962
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001963 res = hostapd_drv_set_ap(hapd, &params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001964 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001965 if (res)
1966 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
1967 else
1968 ret = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001969fail:
1970 ieee802_11_free_ap_params(&params);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001971 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001972}
1973
1974
Hai Shaloma20dcd72022-02-04 13:43:00 -08001975int ieee802_11_set_beacon(struct hostapd_data *hapd)
1976{
1977 struct hostapd_iface *iface = hapd->iface;
1978 int ret;
1979 size_t i, j;
1980 bool is_6g;
1981
1982 ret = __ieee802_11_set_beacon(hapd);
1983 if (ret != 0)
1984 return ret;
1985
1986 if (!iface->interfaces || iface->interfaces->count <= 1)
1987 return 0;
1988
1989 /* Update Beacon frames in case of 6 GHz colocation */
1990 is_6g = is_6ghz_op_class(iface->conf->op_class);
1991 for (j = 0; j < iface->interfaces->count; j++) {
1992 struct hostapd_iface *colocated;
1993
1994 colocated = iface->interfaces->iface[j];
1995 if (colocated == iface || !colocated || !colocated->conf)
1996 continue;
1997
1998 if (is_6g == is_6ghz_op_class(colocated->conf->op_class))
1999 continue;
2000
2001 for (i = 0; i < colocated->num_bss; i++) {
2002 if (colocated->bss[i] && colocated->bss[i]->started)
2003 __ieee802_11_set_beacon(colocated->bss[i]);
2004 }
2005 }
2006
2007 return 0;
2008}
2009
2010
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002011int ieee802_11_set_beacons(struct hostapd_iface *iface)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002012{
2013 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002014 int ret = 0;
2015
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08002016 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002017 if (iface->bss[i]->started &&
2018 ieee802_11_set_beacon(iface->bss[i]) < 0)
2019 ret = -1;
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08002020 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002021
2022 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002023}
2024
Dmitry Shmidt04949592012-07-19 12:16:46 -07002025
2026/* only update beacons if started */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002027int ieee802_11_update_beacons(struct hostapd_iface *iface)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002028{
2029 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002030 int ret = 0;
2031
2032 for (i = 0; i < iface->num_bss; i++) {
2033 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
2034 ieee802_11_set_beacon(iface->bss[i]) < 0)
2035 ret = -1;
2036 }
2037
2038 return ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002039}
2040
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002041#endif /* CONFIG_NATIVE_WINDOWS */