blob: 22e672c8d5b15a79e3fbcd11597df8d5e6238880 [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
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700189static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
190 struct hostapd_channel_data *start,
191 struct hostapd_channel_data *prev)
192{
193 if (end - pos < 3)
194 return pos;
195
196 /* first channel number */
197 *pos++ = start->chan;
198 /* number of channels */
199 *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
200 /* maximum transmit power level */
201 *pos++ = start->max_tx_power;
202
203 return pos;
204}
205
206
207static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
208 int max_len)
209{
210 u8 *pos = eid;
211 u8 *end = eid + max_len;
212 int i;
213 struct hostapd_hw_modes *mode;
214 struct hostapd_channel_data *start, *prev;
215 int chan_spacing = 1;
216
217 if (!hapd->iconf->ieee80211d || max_len < 6 ||
218 hapd->iface->current_mode == NULL)
219 return eid;
220
221 *pos++ = WLAN_EID_COUNTRY;
222 pos++; /* length will be set later */
223 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
224 pos += 3;
225
226 mode = hapd->iface->current_mode;
227 if (mode->mode == HOSTAPD_MODE_IEEE80211A)
228 chan_spacing = 4;
229
230 start = prev = NULL;
231 for (i = 0; i < mode->num_channels; i++) {
232 struct hostapd_channel_data *chan = &mode->channels[i];
233 if (chan->flag & HOSTAPD_CHAN_DISABLED)
234 continue;
235 if (start && prev &&
236 prev->chan + chan_spacing == chan->chan &&
237 start->max_tx_power == chan->max_tx_power) {
238 prev = chan;
239 continue; /* can use same entry */
240 }
241
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -0700242 if (start && prev) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700243 pos = hostapd_eid_country_add(pos, end, chan_spacing,
244 start, prev);
245 start = NULL;
246 }
247
248 /* Start new group */
249 start = prev = chan;
250 }
251
252 if (start) {
253 pos = hostapd_eid_country_add(pos, end, chan_spacing,
254 start, prev);
255 }
256
257 if ((pos - eid) & 1) {
258 if (end - pos < 1)
259 return eid;
260 *pos++ = 0; /* pad for 16-bit alignment */
261 }
262
263 eid[1] = (pos - eid) - 2;
264
265 return pos;
266}
267
268
Hai Shalomfdcde762020-04-02 11:19:20 -0700269static const u8 * hostapd_wpa_ie(struct hostapd_data *hapd, u8 eid)
270{
271 const u8 *ies;
272 size_t ies_len;
273
274 ies = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ies_len);
275 if (!ies)
276 return NULL;
277
278 return get_ie(ies, ies_len, eid);
279}
280
281
282static const u8 * hostapd_vendor_wpa_ie(struct hostapd_data *hapd,
283 u32 vendor_type)
284{
285 const u8 *ies;
286 size_t ies_len;
287
288 ies = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ies_len);
289 if (!ies)
290 return NULL;
291
292 return get_vendor_ie(ies, ies_len, vendor_type);
293}
294
295
296static u8 * hostapd_get_rsne(struct hostapd_data *hapd, u8 *pos, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700297{
298 const u8 *ie;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700299
Hai Shalomfdcde762020-04-02 11:19:20 -0700300 ie = hostapd_wpa_ie(hapd, WLAN_EID_RSN);
301 if (!ie || 2U + ie[1] > len)
302 return pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700303
Hai Shalomfdcde762020-04-02 11:19:20 -0700304 os_memcpy(pos, ie, 2 + ie[1]);
305 return pos + 2 + ie[1];
306}
307
308
309static u8 * hostapd_get_mde(struct hostapd_data *hapd, u8 *pos, size_t len)
310{
311 const u8 *ie;
312
313 ie = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN);
314 if (!ie || 2U + ie[1] > len)
315 return pos;
316
317 os_memcpy(pos, ie, 2 + ie[1]);
318 return pos + 2 + ie[1];
319}
320
321
322static u8 * hostapd_get_rsnxe(struct hostapd_data *hapd, u8 *pos, size_t len)
323{
324 const u8 *ie;
325
326#ifdef CONFIG_TESTING_OPTIONS
327 if (hapd->conf->no_beacon_rsnxe) {
328 wpa_printf(MSG_INFO, "TESTING: Do not add RSNXE into Beacon");
329 return pos;
330 }
331#endif /* CONFIG_TESTING_OPTIONS */
332 ie = hostapd_wpa_ie(hapd, WLAN_EID_RSNX);
333 if (!ie || 2U + ie[1] > len)
334 return pos;
335
336 os_memcpy(pos, ie, 2 + ie[1]);
337 return pos + 2 + ie[1];
338}
339
340
341static u8 * hostapd_get_wpa_ie(struct hostapd_data *hapd, u8 *pos, size_t len)
342{
343 const u8 *ie;
344
345 ie = hostapd_vendor_wpa_ie(hapd, WPA_IE_VENDOR_TYPE);
346 if (!ie || 2U + ie[1] > len)
347 return pos;
348
349 os_memcpy(pos, ie, 2 + ie[1]);
350 return pos + 2 + ie[1];
351}
352
353
354static u8 * hostapd_get_osen_ie(struct hostapd_data *hapd, u8 *pos, size_t len)
355{
356 const u8 *ie;
357
358 ie = hostapd_vendor_wpa_ie(hapd, OSEN_IE_VENDOR_TYPE);
359 if (!ie || 2U + ie[1] > len)
360 return pos;
361
362 os_memcpy(pos, ie, 2 + ie[1]);
363 return pos + 2 + ie[1];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700364}
365
366
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800367static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
368{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800369#ifdef CONFIG_TESTING_OPTIONS
370 if (hapd->iface->cs_oper_class && hapd->iconf->ecsa_ie_only)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800371 return eid;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800372#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800373
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800374 if (!hapd->cs_freq_params.channel)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800375 return eid;
376
377 *eid++ = WLAN_EID_CHANNEL_SWITCH;
378 *eid++ = 3;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700379 *eid++ = hapd->cs_block_tx;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800380 *eid++ = hapd->cs_freq_params.channel;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700381 *eid++ = hapd->cs_count;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800382
383 return eid;
384}
385
386
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800387static u8 * hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800388{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800389 if (!hapd->cs_freq_params.channel || !hapd->iface->cs_oper_class)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800390 return eid;
391
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800392 *eid++ = WLAN_EID_EXT_CHANSWITCH_ANN;
393 *eid++ = 4;
394 *eid++ = hapd->cs_block_tx;
395 *eid++ = hapd->iface->cs_oper_class;
396 *eid++ = hapd->cs_freq_params.channel;
397 *eid++ = hapd->cs_count;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800398
399 return eid;
400}
401
402
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800403static u8 * hostapd_eid_supported_op_classes(struct hostapd_data *hapd, u8 *eid)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800404{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800405 u8 op_class, channel;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800406
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800407 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) ||
408 !hapd->iface->freq)
409 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800410
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800411 if (ieee80211_freq_to_channel_ext(hapd->iface->freq,
412 hapd->iconf->secondary_channel,
Hai Shalom81f62d82019-07-22 12:10:00 -0700413 hostapd_get_oper_chwidth(hapd->iconf),
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800414 &op_class, &channel) ==
415 NUM_HOSTAPD_MODES)
416 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800417
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800418 *eid++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES;
419 *eid++ = 2;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800420
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800421 /* Current Operating Class */
422 *eid++ = op_class;
423
424 /* TODO: Advertise all the supported operating classes */
425 *eid++ = 0;
426
427 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800428}
429
430
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800431static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800432 const struct ieee80211_mgmt *req,
433 int is_p2p, size_t *resp_len)
434{
435 struct ieee80211_mgmt *resp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800436 u8 *pos, *epos, *csa_pos;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800437 size_t buflen;
438
439#define MAX_PROBERESP_LEN 768
440 buflen = MAX_PROBERESP_LEN;
441#ifdef CONFIG_WPS
442 if (hapd->wps_probe_resp_ie)
443 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
444#endif /* CONFIG_WPS */
445#ifdef CONFIG_P2P
446 if (hapd->p2p_probe_resp_ie)
447 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
448#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800449#ifdef CONFIG_FST
450 if (hapd->iface->fst_ies)
451 buflen += wpabuf_len(hapd->iface->fst_ies);
452#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700453 if (hapd->conf->vendor_elements)
454 buflen += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800455 if (hapd->conf->vendor_vht) {
456 buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
457 2 + sizeof(struct ieee80211_vht_operation);
458 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800459
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800460#ifdef CONFIG_IEEE80211AX
461 if (hapd->iconf->ieee80211ax) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700462 buflen += 3 + sizeof(struct ieee80211_he_capabilities) +
Hai Shalom74f70d42019-02-11 14:42:39 -0800463 3 + sizeof(struct ieee80211_he_operation) +
Hai Shalom81f62d82019-07-22 12:10:00 -0700464 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
465 3 + sizeof(struct ieee80211_spatial_reuse);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700466 if (is_6ghz_op_class(hapd->iconf->op_class))
467 buflen += sizeof(struct ieee80211_he_6ghz_oper_info) +
468 3 + sizeof(struct ieee80211_he_6ghz_band_cap);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800469 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700470#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800471
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800472 buflen += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700473 buflen += hostapd_eid_owe_trans_len(hapd);
Hai Shalomfdcde762020-04-02 11:19:20 -0700474 buflen += hostapd_eid_dpp_cc_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800475
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800476 resp = os_zalloc(buflen);
477 if (resp == NULL)
478 return NULL;
479
480 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
481
482 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
483 WLAN_FC_STYPE_PROBE_RESP);
484 if (req)
485 os_memcpy(resp->da, req->sa, ETH_ALEN);
486 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
487
488 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
489 resp->u.probe_resp.beacon_int =
490 host_to_le16(hapd->iconf->beacon_int);
491
492 /* hardware or low-level driver will setup seq_ctrl and timestamp */
493 resp->u.probe_resp.capab_info =
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700494 host_to_le16(hostapd_own_capab_info(hapd));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800495
496 pos = resp->u.probe_resp.variable;
497 *pos++ = WLAN_EID_SSID;
498 *pos++ = hapd->conf->ssid.ssid_len;
499 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
500 pos += hapd->conf->ssid.ssid_len;
501
502 /* Supported rates */
503 pos = hostapd_eid_supp_rates(hapd, pos);
504
505 /* DS Params */
506 pos = hostapd_eid_ds_params(hapd, pos);
507
508 pos = hostapd_eid_country(hapd, pos, epos - pos);
509
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800510 /* Power Constraint element */
511 pos = hostapd_eid_pwr_constraint(hapd, pos);
512
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800513 /* CSA IE */
514 csa_pos = hostapd_eid_csa(hapd, pos);
515 if (csa_pos != pos)
516 hapd->cs_c_off_proberesp = csa_pos - (u8 *) resp - 1;
517 pos = csa_pos;
518
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800519 /* ERP Information element */
520 pos = hostapd_eid_erp_info(hapd, pos);
521
522 /* Extended supported rates */
523 pos = hostapd_eid_ext_supp_rates(hapd, pos);
524
Hai Shalomfdcde762020-04-02 11:19:20 -0700525 pos = hostapd_get_rsne(hapd, pos, epos - pos);
Dmitry Shmidt051af732013-10-22 13:52:46 -0700526 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800527 pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700528 pos = hostapd_get_mde(hapd, pos, epos - pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800529
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800530 /* eCSA IE */
531 csa_pos = hostapd_eid_ecsa(hapd, pos);
532 if (csa_pos != pos)
533 hapd->cs_c_off_ecsa_proberesp = csa_pos - (u8 *) resp - 1;
534 pos = csa_pos;
535
536 pos = hostapd_eid_supported_op_classes(hapd, pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800537 pos = hostapd_eid_ht_capabilities(hapd, pos);
538 pos = hostapd_eid_ht_operation(hapd, pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800539
540 pos = hostapd_eid_ext_capab(hapd, pos);
541
542 pos = hostapd_eid_time_adv(hapd, pos);
543 pos = hostapd_eid_time_zone(hapd, pos);
544
545 pos = hostapd_eid_interworking(hapd, pos);
546 pos = hostapd_eid_adv_proto(hapd, pos);
547 pos = hostapd_eid_roaming_consortium(hapd, pos);
548
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800549#ifdef CONFIG_FST
550 if (hapd->iface->fst_ies) {
551 os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies),
552 wpabuf_len(hapd->iface->fst_ies));
553 pos += wpabuf_len(hapd->iface->fst_ies);
554 }
555#endif /* CONFIG_FST */
556
Dmitry Shmidt04949592012-07-19 12:16:46 -0700557#ifdef CONFIG_IEEE80211AC
Hai Shalomc3565922019-10-28 11:58:20 -0700558 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
559 !is_6ghz_op_class(hapd->iconf->op_class)) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700560 pos = hostapd_eid_vht_capabilities(hapd, pos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800561 pos = hostapd_eid_vht_operation(hapd, pos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800562 pos = hostapd_eid_txpower_envelope(hapd, pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800563 pos = hostapd_eid_wb_chsw_wrapper(hapd, pos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800564 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800565#endif /* CONFIG_IEEE80211AC */
566
567 pos = hostapd_eid_fils_indic(hapd, pos, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -0700568 pos = hostapd_get_rsnxe(hapd, pos, epos - pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800569
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700570#ifdef CONFIG_IEEE80211AX
571 if (hapd->iconf->ieee80211ax) {
Hai Shalom81f62d82019-07-22 12:10:00 -0700572 pos = hostapd_eid_he_capab(hapd, pos, IEEE80211_MODE_AP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700573 pos = hostapd_eid_he_operation(hapd, pos);
Hai Shalom81f62d82019-07-22 12:10:00 -0700574 pos = hostapd_eid_spatial_reuse(hapd, pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700575 pos = hostapd_eid_he_mu_edca_parameter_set(hapd, pos);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700576 pos = hostapd_eid_he_6ghz_band_cap(hapd, pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700577 }
578#endif /* CONFIG_IEEE80211AX */
579
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800580#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800581 if (hapd->conf->vendor_vht)
582 pos = hostapd_eid_vendor_vht(hapd, pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700583#endif /* CONFIG_IEEE80211AC */
584
Hai Shalomfdcde762020-04-02 11:19:20 -0700585 /* WPA / OSEN */
586 pos = hostapd_get_wpa_ie(hapd, pos, epos - pos);
587 pos = hostapd_get_osen_ie(hapd, pos, epos - pos);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800588
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800589 /* Wi-Fi Alliance WMM */
590 pos = hostapd_eid_wmm(hapd, pos);
591
592#ifdef CONFIG_WPS
593 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
594 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
595 wpabuf_len(hapd->wps_probe_resp_ie));
596 pos += wpabuf_len(hapd->wps_probe_resp_ie);
597 }
598#endif /* CONFIG_WPS */
599
600#ifdef CONFIG_P2P
601 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
602 hapd->p2p_probe_resp_ie) {
603 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
604 wpabuf_len(hapd->p2p_probe_resp_ie));
605 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
606 }
607#endif /* CONFIG_P2P */
608#ifdef CONFIG_P2P_MANAGER
609 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
610 P2P_MANAGE)
611 pos = hostapd_eid_p2p_manage(hapd, pos);
612#endif /* CONFIG_P2P_MANAGER */
613
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700614#ifdef CONFIG_HS20
615 pos = hostapd_eid_hs20_indication(hapd, pos);
616#endif /* CONFIG_HS20 */
617
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800618 pos = hostapd_eid_mbo(hapd, pos, (u8 *) resp + buflen - pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700619 pos = hostapd_eid_owe_trans(hapd, pos, (u8 *) resp + buflen - pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700620 pos = hostapd_eid_dpp_cc(hapd, pos, (u8 *) resp + buflen - pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800621
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700622 if (hapd->conf->vendor_elements) {
623 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
624 wpabuf_len(hapd->conf->vendor_elements));
625 pos += wpabuf_len(hapd->conf->vendor_elements);
626 }
627
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800628 *resp_len = pos - (u8 *) resp;
629 return (u8 *) resp;
630}
631
632
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800633enum ssid_match_result {
634 NO_SSID_MATCH,
635 EXACT_SSID_MATCH,
636 WILDCARD_SSID_MATCH
637};
638
639static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
640 const u8 *ssid, size_t ssid_len,
641 const u8 *ssid_list,
Hai Shalomfdcde762020-04-02 11:19:20 -0700642 size_t ssid_list_len,
643 const u8 *short_ssid_list,
644 size_t short_ssid_list_len)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800645{
646 const u8 *pos, *end;
647 int wildcard = 0;
648
649 if (ssid_len == 0)
650 wildcard = 1;
651 if (ssid_len == hapd->conf->ssid.ssid_len &&
652 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
653 return EXACT_SSID_MATCH;
654
Hai Shalomfdcde762020-04-02 11:19:20 -0700655 if (ssid_list) {
656 pos = ssid_list;
657 end = ssid_list + ssid_list_len;
658 while (end - pos >= 2) {
659 if (2 + pos[1] > end - pos)
660 break;
661 if (pos[1] == 0)
662 wildcard = 1;
663 if (pos[1] == hapd->conf->ssid.ssid_len &&
664 os_memcmp(pos + 2, hapd->conf->ssid.ssid,
665 pos[1]) == 0)
666 return EXACT_SSID_MATCH;
667 pos += 2 + pos[1];
668 }
669 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800670
Hai Shalomfdcde762020-04-02 11:19:20 -0700671 if (short_ssid_list) {
672 pos = short_ssid_list;
673 end = short_ssid_list + short_ssid_list_len;
674 while (end - pos >= 4) {
675 if (hapd->conf->ssid.short_ssid == WPA_GET_LE32(pos))
676 return EXACT_SSID_MATCH;
677 pos += 4;
678 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800679 }
680
681 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
682}
683
684
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800685void sta_track_expire(struct hostapd_iface *iface, int force)
686{
687 struct os_reltime now;
688 struct hostapd_sta_info *info;
689
690 if (!iface->num_sta_seen)
691 return;
692
693 os_get_reltime(&now);
694 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
695 list))) {
696 if (!force &&
697 !os_reltime_expired(&now, &info->last_seen,
698 iface->conf->track_sta_max_age))
699 break;
700 force = 0;
701
702 wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
703 MACSTR, iface->bss[0]->conf->iface,
704 MAC2STR(info->addr));
705 dl_list_del(&info->list);
706 iface->num_sta_seen--;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700707 sta_track_del(info);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800708 }
709}
710
711
712static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
713 const u8 *addr)
714{
715 struct hostapd_sta_info *info;
716
717 dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
718 if (os_memcmp(addr, info->addr, ETH_ALEN) == 0)
719 return info;
720
721 return NULL;
722}
723
724
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800725void sta_track_add(struct hostapd_iface *iface, const u8 *addr, int ssi_signal)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800726{
727 struct hostapd_sta_info *info;
728
729 info = sta_track_get(iface, addr);
730 if (info) {
731 /* Move the most recent entry to the end of the list */
732 dl_list_del(&info->list);
733 dl_list_add_tail(&iface->sta_seen, &info->list);
734 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800735 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800736 return;
737 }
738
739 /* Add a new entry */
740 info = os_zalloc(sizeof(*info));
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700741 if (info == NULL)
742 return;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800743 os_memcpy(info->addr, addr, ETH_ALEN);
744 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800745 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800746
747 if (iface->num_sta_seen >= iface->conf->track_sta_max_num) {
748 /* Expire oldest entry to make room for a new one */
749 sta_track_expire(iface, 1);
750 }
751
752 wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
753 MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr));
754 dl_list_add_tail(&iface->sta_seen, &info->list);
755 iface->num_sta_seen++;
756}
757
758
759struct hostapd_data *
760sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
761 const char *ifname)
762{
763 struct hapd_interfaces *interfaces = iface->interfaces;
764 size_t i, j;
765
766 for (i = 0; i < interfaces->count; i++) {
767 struct hostapd_data *hapd = NULL;
768
769 iface = interfaces->iface[i];
770 for (j = 0; j < iface->num_bss; j++) {
771 hapd = iface->bss[j];
772 if (os_strcmp(ifname, hapd->conf->iface) == 0)
773 break;
774 hapd = NULL;
775 }
776
777 if (hapd && sta_track_get(iface, addr))
778 return hapd;
779 }
780
781 return NULL;
782}
783
784
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700785#ifdef CONFIG_TAXONOMY
786void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr,
787 struct wpabuf **probe_ie_taxonomy)
788{
789 struct hostapd_sta_info *info;
790
791 info = sta_track_get(iface, addr);
792 if (!info)
793 return;
794
795 wpabuf_free(*probe_ie_taxonomy);
796 *probe_ie_taxonomy = info->probe_ie_taxonomy;
797 info->probe_ie_taxonomy = NULL;
798}
799#endif /* CONFIG_TAXONOMY */
800
801
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700802void handle_probe_req(struct hostapd_data *hapd,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700803 const struct ieee80211_mgmt *mgmt, size_t len,
804 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700805{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800806 u8 *resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700807 struct ieee802_11_elems elems;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700808 const u8 *ie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800809 size_t ie_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800810 size_t i, resp_len;
811 int noack;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800812 enum ssid_match_result res;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800813 int ret;
814 u16 csa_offs[2];
815 size_t csa_offs_len;
Hai Shalomfdcde762020-04-02 11:19:20 -0700816 struct radius_sta rad_info;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700817
Dmitry Shmidte4663042016-04-04 10:07:49 -0700818 if (len < IEEE80211_HDRLEN)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700819 return;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700820 ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800821 if (hapd->iconf->track_sta_max_num)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800822 sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
Dmitry Shmidte4663042016-04-04 10:07:49 -0700823 ie_len = len - IEEE80211_HDRLEN;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700824
Hai Shalomfdcde762020-04-02 11:19:20 -0700825 ret = hostapd_allowed_address(hapd, mgmt->sa, (const u8 *) mgmt, len,
826 &rad_info, 1);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700827 if (ret == HOSTAPD_ACL_REJECT) {
828 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
829 "Ignore Probe Request frame from " MACSTR
830 " due to ACL reject ", MAC2STR(mgmt->sa));
831 return;
832 }
833
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700834 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
835 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800836 mgmt->sa, mgmt->da, mgmt->bssid,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700837 ie, ie_len, ssi_signal) > 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700838 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800839
Hai Shalom74f70d42019-02-11 14:42:39 -0800840 if (!hapd->conf->send_probe_response)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700841 return;
842
843 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
844 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
845 MAC2STR(mgmt->sa));
846 return;
847 }
848
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700849 if ((!elems.ssid || !elems.supp_rates)) {
850 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
851 "without SSID or supported rates element",
852 MAC2STR(mgmt->sa));
853 return;
854 }
855
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800856 /*
857 * No need to reply if the Probe Request frame was sent on an adjacent
858 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
859 * AP with dot11RadioMeasurementActivated set to true, but strictly
860 * speaking does not allow such ignoring of Probe Request frames if
861 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
862 * number of unnecessary Probe Response frames for cases where the STA
863 * is less likely to see them (Probe Request frame sent on a
864 * neighboring, but partially overlapping, channel).
865 */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700866 if (elems.ds_params &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800867 hapd->iface->current_mode &&
868 (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
869 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
870 hapd->iconf->channel != elems.ds_params[0]) {
871 wpa_printf(MSG_DEBUG,
872 "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
873 hapd->iconf->channel, elems.ds_params[0]);
874 return;
875 }
876
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700877#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800878 if (hapd->p2p && hapd->p2p_group && elems.wps_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700879 struct wpabuf *wps;
880 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
881 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
882 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
883 "due to mismatch with Requested Device "
884 "Type");
885 wpabuf_free(wps);
886 return;
887 }
888 wpabuf_free(wps);
889 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800890
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800891 if (hapd->p2p && hapd->p2p_group && elems.p2p) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800892 struct wpabuf *p2p;
893 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
894 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
895 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
896 "due to mismatch with Device ID");
897 wpabuf_free(p2p);
898 return;
899 }
900 wpabuf_free(p2p);
901 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700902#endif /* CONFIG_P2P */
903
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800904 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
Hai Shalomfdcde762020-04-02 11:19:20 -0700905 elems.ssid_list_len == 0 && elems.short_ssid_list_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700906 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
907 "broadcast SSID ignored", MAC2STR(mgmt->sa));
908 return;
909 }
910
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700911#ifdef CONFIG_P2P
912 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
913 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
914 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
915 P2P_WILDCARD_SSID_LEN) == 0) {
916 /* Process P2P Wildcard SSID like Wildcard SSID */
917 elems.ssid_len = 0;
918 }
919#endif /* CONFIG_P2P */
920
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700921#ifdef CONFIG_TAXONOMY
922 {
923 struct sta_info *sta;
924 struct hostapd_sta_info *info;
925
926 if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) {
927 taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len);
928 } else if ((info = sta_track_get(hapd->iface,
929 mgmt->sa)) != NULL) {
930 taxonomy_hostapd_sta_info_probe_req(hapd, info,
931 ie, ie_len);
932 }
933 }
934#endif /* CONFIG_TAXONOMY */
935
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800936 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
Hai Shalomfdcde762020-04-02 11:19:20 -0700937 elems.ssid_list, elems.ssid_list_len,
938 elems.short_ssid_list, elems.short_ssid_list_len);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700939 if (res == NO_SSID_MATCH) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700940 if (!(mgmt->da[0] & 0x01)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700941 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800942 " for foreign SSID '%s' (DA " MACSTR ")%s",
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800943 MAC2STR(mgmt->sa),
944 wpa_ssid_txt(elems.ssid, elems.ssid_len),
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800945 MAC2STR(mgmt->da),
946 elems.ssid_list ? " (SSID list)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700947 }
948 return;
949 }
950
Hai Shalomfdcde762020-04-02 11:19:20 -0700951 if (hapd->conf->ignore_broadcast_ssid && res == WILDCARD_SSID_MATCH) {
952 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
953 "broadcast SSID ignored", MAC2STR(mgmt->sa));
954 return;
955 }
956
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800957#ifdef CONFIG_INTERWORKING
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -0700958 if (hapd->conf->interworking &&
959 elems.interworking && elems.interworking_len >= 1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800960 u8 ant = elems.interworking[0] & 0x0f;
961 if (ant != INTERWORKING_ANT_WILDCARD &&
962 ant != hapd->conf->access_network_type) {
963 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
964 " for mismatching ANT %u ignored",
965 MAC2STR(mgmt->sa), ant);
966 return;
967 }
968 }
969
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -0700970 if (hapd->conf->interworking && elems.interworking &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800971 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
972 const u8 *hessid;
973 if (elems.interworking_len == 7)
974 hessid = elems.interworking + 1;
975 else
976 hessid = elems.interworking + 1 + 2;
977 if (!is_broadcast_ether_addr(hessid) &&
978 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
979 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
980 " for mismatching HESSID " MACSTR
981 " ignored",
982 MAC2STR(mgmt->sa), MAC2STR(hessid));
983 return;
984 }
985 }
986#endif /* CONFIG_INTERWORKING */
987
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700988#ifdef CONFIG_P2P
989 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
990 supp_rates_11b_only(&elems)) {
991 /* Indicates support for 11b rates only */
992 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
993 MACSTR " with only 802.11b rates",
994 MAC2STR(mgmt->sa));
995 return;
996 }
997#endif /* CONFIG_P2P */
998
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700999 /* TODO: verify that supp_rates contains at least one matching rate
1000 * with AP configuration */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001001
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001002 if (hapd->conf->no_probe_resp_if_seen_on &&
1003 is_multicast_ether_addr(mgmt->da) &&
1004 is_multicast_ether_addr(mgmt->bssid) &&
1005 sta_track_seen_on(hapd->iface, mgmt->sa,
1006 hapd->conf->no_probe_resp_if_seen_on)) {
1007 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1008 " since STA has been seen on %s",
1009 hapd->conf->iface, MAC2STR(mgmt->sa),
1010 hapd->conf->no_probe_resp_if_seen_on);
1011 return;
1012 }
1013
1014 if (hapd->conf->no_probe_resp_if_max_sta &&
1015 is_multicast_ether_addr(mgmt->da) &&
1016 is_multicast_ether_addr(mgmt->bssid) &&
1017 hapd->num_sta >= hapd->conf->max_num_sta &&
1018 !ap_get_sta(hapd, mgmt->sa)) {
1019 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1020 " since no room for additional STA",
1021 hapd->conf->iface, MAC2STR(mgmt->sa));
1022 return;
1023 }
1024
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001025#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001026 if (hapd->iconf->ignore_probe_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001027 drand48() < hapd->iconf->ignore_probe_probability) {
1028 wpa_printf(MSG_INFO,
1029 "TESTING: ignoring probe request from " MACSTR,
1030 MAC2STR(mgmt->sa));
1031 return;
1032 }
1033#endif /* CONFIG_TESTING_OPTIONS */
1034
Roshan Pius3a1667e2018-07-03 15:17:14 -07001035 wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, RX_PROBE_REQUEST "sa=" MACSTR
1036 " signal=%d", MAC2STR(mgmt->sa), ssi_signal);
1037
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001038 resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001039 &resp_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001040 if (resp == NULL)
1041 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001042
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001043 /*
1044 * If this is a broadcast probe request, apply no ack policy to avoid
1045 * excessive retries.
1046 */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001047 noack = !!(res == WILDCARD_SSID_MATCH &&
1048 is_broadcast_ether_addr(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001049
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001050 csa_offs_len = 0;
1051 if (hapd->csa_in_progress) {
1052 if (hapd->cs_c_off_proberesp)
1053 csa_offs[csa_offs_len++] =
1054 hapd->cs_c_off_proberesp;
1055
1056 if (hapd->cs_c_off_ecsa_proberesp)
1057 csa_offs[csa_offs_len++] =
1058 hapd->cs_c_off_ecsa_proberesp;
1059 }
1060
Hai Shalomfdcde762020-04-02 11:19:20 -07001061 ret = hostapd_drv_send_mlme(hapd, resp, resp_len, noack,
1062 csa_offs_len ? csa_offs : NULL,
1063 csa_offs_len, 0);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001064
1065 if (ret < 0)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001066 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001067
1068 os_free(resp);
1069
1070 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
1071 "SSID", MAC2STR(mgmt->sa),
1072 elems.ssid_len == 0 ? "broadcast" : "our");
1073}
1074
1075
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001076static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
1077 size_t *resp_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001078{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001079 /* check probe response offloading caps and print warnings */
1080 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
1081 return NULL;
1082
1083#ifdef CONFIG_WPS
1084 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
1085 (!(hapd->iface->probe_resp_offloads &
1086 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
1087 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
1088 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
1089 "Probe Response while not supporting this");
1090#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001091
1092#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001093 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
1094 !(hapd->iface->probe_resp_offloads &
1095 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
1096 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
1097 "Probe Response while not supporting this");
1098#endif /* CONFIG_P2P */
1099
1100 if (hapd->conf->interworking &&
1101 !(hapd->iface->probe_resp_offloads &
1102 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
1103 wpa_printf(MSG_WARNING, "Device is trying to offload "
1104 "Interworking Probe Response while not supporting "
1105 "this");
1106
1107 /* Generate a Probe Response template for the non-P2P case */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001108 return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001109}
1110
1111#endif /* NEED_AP_MLME */
1112
1113
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001114void sta_track_del(struct hostapd_sta_info *info)
1115{
1116#ifdef CONFIG_TAXONOMY
1117 wpabuf_free(info->probe_ie_taxonomy);
1118 info->probe_ie_taxonomy = NULL;
1119#endif /* CONFIG_TAXONOMY */
1120 os_free(info);
1121}
1122
1123
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001124int ieee802_11_build_ap_params(struct hostapd_data *hapd,
1125 struct wpa_driver_ap_params *params)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001126{
1127 struct ieee80211_mgmt *head = NULL;
1128 u8 *tail = NULL;
1129 size_t head_len = 0, tail_len = 0;
1130 u8 *resp = NULL;
1131 size_t resp_len = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001132#ifdef NEED_AP_MLME
1133 u16 capab_info;
Hai Shalomfdcde762020-04-02 11:19:20 -07001134 u8 *pos, *tailpos, *tailend, *csa_pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001135
1136#define BEACON_HEAD_BUF_SIZE 256
1137#define BEACON_TAIL_BUF_SIZE 512
1138 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
1139 tail_len = BEACON_TAIL_BUF_SIZE;
1140#ifdef CONFIG_WPS
1141 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
1142 tail_len += wpabuf_len(hapd->wps_beacon_ie);
1143#endif /* CONFIG_WPS */
1144#ifdef CONFIG_P2P
1145 if (hapd->p2p_beacon_ie)
1146 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
1147#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001148#ifdef CONFIG_FST
1149 if (hapd->iface->fst_ies)
1150 tail_len += wpabuf_len(hapd->iface->fst_ies);
1151#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001152 if (hapd->conf->vendor_elements)
1153 tail_len += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001154
1155#ifdef CONFIG_IEEE80211AC
1156 if (hapd->conf->vendor_vht) {
1157 tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
1158 2 + sizeof(struct ieee80211_vht_operation);
1159 }
1160#endif /* CONFIG_IEEE80211AC */
1161
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001162#ifdef CONFIG_IEEE80211AX
1163 if (hapd->iconf->ieee80211ax) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001164 tail_len += 3 + sizeof(struct ieee80211_he_capabilities) +
Hai Shalom74f70d42019-02-11 14:42:39 -08001165 3 + sizeof(struct ieee80211_he_operation) +
Hai Shalom81f62d82019-07-22 12:10:00 -07001166 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
1167 3 + sizeof(struct ieee80211_spatial_reuse);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001168 if (is_6ghz_op_class(hapd->iconf->op_class))
1169 tail_len += sizeof(struct ieee80211_he_6ghz_oper_info) +
1170 3 + sizeof(struct ieee80211_he_6ghz_band_cap);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001171 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001172#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001173
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001174 tail_len += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001175 tail_len += hostapd_eid_owe_trans_len(hapd);
Hai Shalomfdcde762020-04-02 11:19:20 -07001176 tail_len += hostapd_eid_dpp_cc_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001177
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001178 tailpos = tail = os_malloc(tail_len);
1179 if (head == NULL || tail == NULL) {
1180 wpa_printf(MSG_ERROR, "Failed to set beacon data");
1181 os_free(head);
1182 os_free(tail);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001183 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001184 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001185 tailend = tail + tail_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001186
1187 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1188 WLAN_FC_STYPE_BEACON);
1189 head->duration = host_to_le16(0);
1190 os_memset(head->da, 0xff, ETH_ALEN);
1191
1192 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1193 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1194 head->u.beacon.beacon_int =
1195 host_to_le16(hapd->iconf->beacon_int);
1196
1197 /* hardware or low-level driver will setup seq_ctrl and timestamp */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001198 capab_info = hostapd_own_capab_info(hapd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001199 head->u.beacon.capab_info = host_to_le16(capab_info);
1200 pos = &head->u.beacon.variable[0];
1201
1202 /* SSID */
1203 *pos++ = WLAN_EID_SSID;
1204 if (hapd->conf->ignore_broadcast_ssid == 2) {
1205 /* clear the data, but keep the correct length of the SSID */
1206 *pos++ = hapd->conf->ssid.ssid_len;
1207 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
1208 pos += hapd->conf->ssid.ssid_len;
1209 } else if (hapd->conf->ignore_broadcast_ssid) {
1210 *pos++ = 0; /* empty SSID */
1211 } else {
1212 *pos++ = hapd->conf->ssid.ssid_len;
1213 os_memcpy(pos, hapd->conf->ssid.ssid,
1214 hapd->conf->ssid.ssid_len);
1215 pos += hapd->conf->ssid.ssid_len;
1216 }
1217
1218 /* Supported rates */
1219 pos = hostapd_eid_supp_rates(hapd, pos);
1220
1221 /* DS Params */
1222 pos = hostapd_eid_ds_params(hapd, pos);
1223
1224 head_len = pos - (u8 *) head;
1225
Hai Shalomfdcde762020-04-02 11:19:20 -07001226 tailpos = hostapd_eid_country(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001227
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001228 /* Power Constraint element */
1229 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
1230
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001231 /* CSA IE */
1232 csa_pos = hostapd_eid_csa(hapd, tailpos);
1233 if (csa_pos != tailpos)
1234 hapd->cs_c_off_beacon = csa_pos - tail - 1;
1235 tailpos = csa_pos;
1236
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001237 /* ERP Information element */
1238 tailpos = hostapd_eid_erp_info(hapd, tailpos);
1239
1240 /* Extended supported rates */
1241 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
1242
Hai Shalomfdcde762020-04-02 11:19:20 -07001243 tailpos = hostapd_get_rsne(hapd, tailpos, tailend - tailpos);
1244 tailpos = hostapd_eid_bss_load(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001245 tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
Hai Shalomfdcde762020-04-02 11:19:20 -07001246 tailend - tailpos);
1247 tailpos = hostapd_get_mde(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001248
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001249 /* eCSA IE */
1250 csa_pos = hostapd_eid_ecsa(hapd, tailpos);
1251 if (csa_pos != tailpos)
1252 hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1;
1253 tailpos = csa_pos;
1254
1255 tailpos = hostapd_eid_supported_op_classes(hapd, tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001256 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
1257 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001258
1259 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
1260
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001261 /*
1262 * TODO: Time Advertisement element should only be included in some
1263 * DTIM Beacon frames.
1264 */
1265 tailpos = hostapd_eid_time_adv(hapd, tailpos);
1266
1267 tailpos = hostapd_eid_interworking(hapd, tailpos);
1268 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
1269 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001270
1271#ifdef CONFIG_FST
1272 if (hapd->iface->fst_ies) {
1273 os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies),
1274 wpabuf_len(hapd->iface->fst_ies));
1275 tailpos += wpabuf_len(hapd->iface->fst_ies);
1276 }
1277#endif /* CONFIG_FST */
1278
Dmitry Shmidt04949592012-07-19 12:16:46 -07001279#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001280 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -07001281 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001282 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08001283 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001284 tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001285 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001286#endif /* CONFIG_IEEE80211AC */
1287
1288 tailpos = hostapd_eid_fils_indic(hapd, tailpos, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -07001289 tailpos = hostapd_get_rsnxe(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001290
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001291#ifdef CONFIG_IEEE80211AX
1292 if (hapd->iconf->ieee80211ax) {
Hai Shalom81f62d82019-07-22 12:10:00 -07001293 tailpos = hostapd_eid_he_capab(hapd, tailpos,
1294 IEEE80211_MODE_AP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001295 tailpos = hostapd_eid_he_operation(hapd, tailpos);
Hai Shalom81f62d82019-07-22 12:10:00 -07001296 tailpos = hostapd_eid_spatial_reuse(hapd, tailpos);
Hai Shalomfdcde762020-04-02 11:19:20 -07001297 tailpos = hostapd_eid_he_mu_edca_parameter_set(hapd, tailpos);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001298 tailpos = hostapd_eid_he_6ghz_band_cap(hapd, tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001299 }
1300#endif /* CONFIG_IEEE80211AX */
1301
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001302#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001303 if (hapd->conf->vendor_vht)
1304 tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001305#endif /* CONFIG_IEEE80211AC */
1306
Hai Shalomfdcde762020-04-02 11:19:20 -07001307 /* WPA / OSEN */
1308 tailpos = hostapd_get_wpa_ie(hapd, tailpos, tailend - tailpos);
1309 tailpos = hostapd_get_osen_ie(hapd, tailpos, tailend - tailpos);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001310
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001311 /* Wi-Fi Alliance WMM */
1312 tailpos = hostapd_eid_wmm(hapd, tailpos);
1313
1314#ifdef CONFIG_WPS
1315 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
1316 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
1317 wpabuf_len(hapd->wps_beacon_ie));
1318 tailpos += wpabuf_len(hapd->wps_beacon_ie);
1319 }
1320#endif /* CONFIG_WPS */
1321
1322#ifdef CONFIG_P2P
1323 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
1324 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
1325 wpabuf_len(hapd->p2p_beacon_ie));
1326 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
1327 }
1328#endif /* CONFIG_P2P */
1329#ifdef CONFIG_P2P_MANAGER
1330 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
1331 P2P_MANAGE)
1332 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
1333#endif /* CONFIG_P2P_MANAGER */
1334
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001335#ifdef CONFIG_HS20
1336 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
1337#endif /* CONFIG_HS20 */
1338
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001339 tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001340 tailpos = hostapd_eid_owe_trans(hapd, tailpos,
1341 tail + tail_len - tailpos);
Hai Shalomfdcde762020-04-02 11:19:20 -07001342 tailpos = hostapd_eid_dpp_cc(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001343
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001344 if (hapd->conf->vendor_elements) {
1345 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
1346 wpabuf_len(hapd->conf->vendor_elements));
1347 tailpos += wpabuf_len(hapd->conf->vendor_elements);
1348 }
1349
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001350 tail_len = tailpos > tail ? tailpos - tail : 0;
1351
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001352 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
1353#endif /* NEED_AP_MLME */
1354
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001355 os_memset(params, 0, sizeof(*params));
1356 params->head = (u8 *) head;
1357 params->head_len = head_len;
1358 params->tail = tail;
1359 params->tail_len = tail_len;
1360 params->proberesp = resp;
1361 params->proberesp_len = resp_len;
1362 params->dtim_period = hapd->conf->dtim_period;
1363 params->beacon_int = hapd->iconf->beacon_int;
1364 params->basic_rates = hapd->iface->basic_rates;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001365 params->beacon_rate = hapd->iconf->beacon_rate;
1366 params->rate_type = hapd->iconf->rate_type;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001367 params->ssid = hapd->conf->ssid.ssid;
1368 params->ssid_len = hapd->conf->ssid.ssid_len;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001369 if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
1370 (WPA_PROTO_WPA | WPA_PROTO_RSN))
1371 params->pairwise_ciphers = hapd->conf->wpa_pairwise |
1372 hapd->conf->rsn_pairwise;
1373 else if (hapd->conf->wpa & WPA_PROTO_RSN)
1374 params->pairwise_ciphers = hapd->conf->rsn_pairwise;
1375 else if (hapd->conf->wpa & WPA_PROTO_WPA)
1376 params->pairwise_ciphers = hapd->conf->wpa_pairwise;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001377 params->group_cipher = hapd->conf->wpa_group;
1378 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
1379 params->auth_algs = hapd->conf->auth_algs;
1380 params->wpa_version = hapd->conf->wpa;
Hai Shalomfdcde762020-04-02 11:19:20 -07001381 params->privacy = hapd->conf->wpa;
1382#ifdef CONFIG_WEP
1383 params->privacy |= hapd->conf->ssid.wep.keys_set ||
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001384 (hapd->conf->ieee802_1x &&
1385 (hapd->conf->default_wep_key_len ||
1386 hapd->conf->individual_wep_key_len));
Hai Shalomfdcde762020-04-02 11:19:20 -07001387#endif /* CONFIG_WEP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001388 switch (hapd->conf->ignore_broadcast_ssid) {
1389 case 0:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001390 params->hide_ssid = NO_SSID_HIDING;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001391 break;
1392 case 1:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001393 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001394 break;
1395 case 2:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001396 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001397 break;
1398 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001399 params->isolate = hapd->conf->isolate;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001400#ifdef NEED_AP_MLME
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001401 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001402 ERP_INFO_USE_PROTECTION);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001403 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001404 hapd->iconf->preamble == SHORT_PREAMBLE;
1405 if (hapd->iface->current_mode &&
1406 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001407 params->short_slot_time =
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001408 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
1409 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001410 params->short_slot_time = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001411 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001412 params->ht_opmode = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001413 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001414 params->ht_opmode = hapd->iface->ht_op_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001415#endif /* NEED_AP_MLME */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001416 params->interworking = hapd->conf->interworking;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001417 if (hapd->conf->interworking &&
1418 !is_zero_ether_addr(hapd->conf->hessid))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001419 params->hessid = hapd->conf->hessid;
1420 params->access_network_type = hapd->conf->access_network_type;
1421 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001422#ifdef CONFIG_P2P
1423 params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
1424#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001425#ifdef CONFIG_HS20
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001426 params->disable_dgaf = hapd->conf->disable_dgaf;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001427 if (hapd->conf->osen) {
1428 params->privacy = 1;
1429 params->osen = 1;
1430 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001431#endif /* CONFIG_HS20 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001432 params->multicast_to_unicast = hapd->conf->multicast_to_unicast;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001433 params->pbss = hapd->conf->pbss;
Hai Shalom74f70d42019-02-11 14:42:39 -08001434
1435 if (hapd->conf->ftm_responder) {
1436 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_FTM_RESPONDER) {
1437 params->ftm_responder = 1;
1438 params->lci = hapd->iface->conf->lci;
1439 params->civic = hapd->iface->conf->civic;
1440 } else {
1441 wpa_printf(MSG_WARNING,
1442 "Not configuring FTM responder as the driver doesn't advertise support for it");
1443 }
1444 }
1445
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001446 return 0;
1447}
1448
1449
1450void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
1451{
1452 os_free(params->tail);
1453 params->tail = NULL;
1454 os_free(params->head);
1455 params->head = NULL;
1456 os_free(params->proberesp);
1457 params->proberesp = NULL;
1458}
1459
1460
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001461int ieee802_11_set_beacon(struct hostapd_data *hapd)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001462{
1463 struct wpa_driver_ap_params params;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001464 struct hostapd_freq_params freq;
1465 struct hostapd_iface *iface = hapd->iface;
1466 struct hostapd_config *iconf = iface->conf;
Hai Shalom81f62d82019-07-22 12:10:00 -07001467 struct hostapd_hw_modes *cmode = iface->current_mode;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001468 struct wpabuf *beacon, *proberesp, *assocresp;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001469 int res, ret = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001470
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001471 if (hapd->csa_in_progress) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001472 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001473 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001474 }
1475
1476 hapd->beacon_set_done = 1;
1477
1478 if (ieee802_11_build_ap_params(hapd, &params) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001479 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001480
1481 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
1482 0)
1483 goto fail;
1484
1485 params.beacon_ies = beacon;
1486 params.proberesp_ies = proberesp;
1487 params.assocresp_ies = assocresp;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001488 params.reenable = hapd->reenable_beacon;
Hai Shalomc3565922019-10-28 11:58:20 -07001489#ifdef CONFIG_IEEE80211AX
1490 params.he_spr = !!hapd->iface->conf->spr.sr_control;
1491 params.he_spr_srg_obss_pd_min_offset =
1492 hapd->iface->conf->spr.srg_obss_pd_min_offset;
1493 params.he_spr_srg_obss_pd_max_offset =
1494 hapd->iface->conf->spr.srg_obss_pd_max_offset;
Hai Shalomfdcde762020-04-02 11:19:20 -07001495 params.he_bss_color_disabled =
1496 hapd->iface->conf->he_op.he_bss_color_disabled;
1497 params.he_bss_color_partial =
1498 hapd->iface->conf->he_op.he_bss_color_partial;
1499 params.he_bss_color = hapd->iface->conf->he_op.he_bss_color;
1500 params.twt_responder = hostapd_get_he_twt_responder(hapd,
1501 IEEE80211_MODE_AP);
Hai Shalomc3565922019-10-28 11:58:20 -07001502#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001503 hapd->reenable_beacon = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001504
Hai Shalom81f62d82019-07-22 12:10:00 -07001505 if (cmode &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001506 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
Hai Shalomc3565922019-10-28 11:58:20 -07001507 iconf->channel, iconf->enable_edmg,
1508 iconf->edmg_channel, iconf->ieee80211n,
Hai Shalom81f62d82019-07-22 12:10:00 -07001509 iconf->ieee80211ac, iconf->ieee80211ax,
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001510 iconf->secondary_channel,
Hai Shalom81f62d82019-07-22 12:10:00 -07001511 hostapd_get_oper_chwidth(iconf),
1512 hostapd_get_oper_centr_freq_seg0_idx(iconf),
1513 hostapd_get_oper_centr_freq_seg1_idx(iconf),
1514 cmode->vht_capab,
1515 &cmode->he_capab[IEEE80211_MODE_AP]) == 0)
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001516 params.freq = &freq;
1517
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001518 res = hostapd_drv_set_ap(hapd, &params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001519 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001520 if (res)
1521 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
1522 else
1523 ret = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001524fail:
1525 ieee802_11_free_ap_params(&params);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001526 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001527}
1528
1529
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001530int ieee802_11_set_beacons(struct hostapd_iface *iface)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001531{
1532 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001533 int ret = 0;
1534
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08001535 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001536 if (iface->bss[i]->started &&
1537 ieee802_11_set_beacon(iface->bss[i]) < 0)
1538 ret = -1;
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08001539 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001540
1541 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001542}
1543
Dmitry Shmidt04949592012-07-19 12:16:46 -07001544
1545/* only update beacons if started */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001546int ieee802_11_update_beacons(struct hostapd_iface *iface)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001547{
1548 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001549 int ret = 0;
1550
1551 for (i = 0; i < iface->num_bss; i++) {
1552 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
1553 ieee802_11_set_beacon(iface->bss[i]) < 0)
1554 ret = -1;
1555 }
1556
1557 return ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001558}
1559
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001560#endif /* CONFIG_NATIVE_WINDOWS */