blob: b3b33b7faf1d968e95c35ac3b023b44bb7e59628 [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 Shmidt2f74e362015-01-21 13:19:05 -0800563 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800564#endif /* CONFIG_IEEE80211AC */
565
Hai Shalom899fcc72020-10-19 14:38:18 -0700566 if ((hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) ||
567 hapd->iconf->ieee80211ax)
568 pos = hostapd_eid_wb_chsw_wrapper(hapd, pos);
569
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800570 pos = hostapd_eid_fils_indic(hapd, pos, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -0700571 pos = hostapd_get_rsnxe(hapd, pos, epos - pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800572
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700573#ifdef CONFIG_IEEE80211AX
574 if (hapd->iconf->ieee80211ax) {
Hai Shalom81f62d82019-07-22 12:10:00 -0700575 pos = hostapd_eid_he_capab(hapd, pos, IEEE80211_MODE_AP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700576 pos = hostapd_eid_he_operation(hapd, pos);
Hai Shalom81f62d82019-07-22 12:10:00 -0700577 pos = hostapd_eid_spatial_reuse(hapd, pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700578 pos = hostapd_eid_he_mu_edca_parameter_set(hapd, pos);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700579 pos = hostapd_eid_he_6ghz_band_cap(hapd, pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700580 }
581#endif /* CONFIG_IEEE80211AX */
582
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800583#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800584 if (hapd->conf->vendor_vht)
585 pos = hostapd_eid_vendor_vht(hapd, pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700586#endif /* CONFIG_IEEE80211AC */
587
Hai Shalomfdcde762020-04-02 11:19:20 -0700588 /* WPA / OSEN */
589 pos = hostapd_get_wpa_ie(hapd, pos, epos - pos);
590 pos = hostapd_get_osen_ie(hapd, pos, epos - pos);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800591
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800592 /* Wi-Fi Alliance WMM */
593 pos = hostapd_eid_wmm(hapd, pos);
594
595#ifdef CONFIG_WPS
596 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
597 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
598 wpabuf_len(hapd->wps_probe_resp_ie));
599 pos += wpabuf_len(hapd->wps_probe_resp_ie);
600 }
601#endif /* CONFIG_WPS */
602
603#ifdef CONFIG_P2P
604 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
605 hapd->p2p_probe_resp_ie) {
606 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
607 wpabuf_len(hapd->p2p_probe_resp_ie));
608 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
609 }
610#endif /* CONFIG_P2P */
611#ifdef CONFIG_P2P_MANAGER
612 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
613 P2P_MANAGE)
614 pos = hostapd_eid_p2p_manage(hapd, pos);
615#endif /* CONFIG_P2P_MANAGER */
616
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700617#ifdef CONFIG_HS20
618 pos = hostapd_eid_hs20_indication(hapd, pos);
619#endif /* CONFIG_HS20 */
620
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800621 pos = hostapd_eid_mbo(hapd, pos, (u8 *) resp + buflen - pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700622 pos = hostapd_eid_owe_trans(hapd, pos, (u8 *) resp + buflen - pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700623 pos = hostapd_eid_dpp_cc(hapd, pos, (u8 *) resp + buflen - pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800624
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700625 if (hapd->conf->vendor_elements) {
626 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
627 wpabuf_len(hapd->conf->vendor_elements));
628 pos += wpabuf_len(hapd->conf->vendor_elements);
629 }
630
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800631 *resp_len = pos - (u8 *) resp;
632 return (u8 *) resp;
633}
634
635
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800636enum ssid_match_result {
637 NO_SSID_MATCH,
638 EXACT_SSID_MATCH,
639 WILDCARD_SSID_MATCH
640};
641
642static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
643 const u8 *ssid, size_t ssid_len,
644 const u8 *ssid_list,
Hai Shalomfdcde762020-04-02 11:19:20 -0700645 size_t ssid_list_len,
646 const u8 *short_ssid_list,
647 size_t short_ssid_list_len)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800648{
649 const u8 *pos, *end;
650 int wildcard = 0;
651
652 if (ssid_len == 0)
653 wildcard = 1;
654 if (ssid_len == hapd->conf->ssid.ssid_len &&
655 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
656 return EXACT_SSID_MATCH;
657
Hai Shalomfdcde762020-04-02 11:19:20 -0700658 if (ssid_list) {
659 pos = ssid_list;
660 end = ssid_list + ssid_list_len;
661 while (end - pos >= 2) {
662 if (2 + pos[1] > end - pos)
663 break;
664 if (pos[1] == 0)
665 wildcard = 1;
666 if (pos[1] == hapd->conf->ssid.ssid_len &&
667 os_memcmp(pos + 2, hapd->conf->ssid.ssid,
668 pos[1]) == 0)
669 return EXACT_SSID_MATCH;
670 pos += 2 + pos[1];
671 }
672 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800673
Hai Shalomfdcde762020-04-02 11:19:20 -0700674 if (short_ssid_list) {
675 pos = short_ssid_list;
676 end = short_ssid_list + short_ssid_list_len;
677 while (end - pos >= 4) {
678 if (hapd->conf->ssid.short_ssid == WPA_GET_LE32(pos))
679 return EXACT_SSID_MATCH;
680 pos += 4;
681 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800682 }
683
684 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
685}
686
687
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800688void sta_track_expire(struct hostapd_iface *iface, int force)
689{
690 struct os_reltime now;
691 struct hostapd_sta_info *info;
692
693 if (!iface->num_sta_seen)
694 return;
695
696 os_get_reltime(&now);
697 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
698 list))) {
699 if (!force &&
700 !os_reltime_expired(&now, &info->last_seen,
701 iface->conf->track_sta_max_age))
702 break;
703 force = 0;
704
705 wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
706 MACSTR, iface->bss[0]->conf->iface,
707 MAC2STR(info->addr));
708 dl_list_del(&info->list);
709 iface->num_sta_seen--;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700710 sta_track_del(info);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800711 }
712}
713
714
715static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
716 const u8 *addr)
717{
718 struct hostapd_sta_info *info;
719
720 dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
721 if (os_memcmp(addr, info->addr, ETH_ALEN) == 0)
722 return info;
723
724 return NULL;
725}
726
727
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800728void sta_track_add(struct hostapd_iface *iface, const u8 *addr, int ssi_signal)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800729{
730 struct hostapd_sta_info *info;
731
732 info = sta_track_get(iface, addr);
733 if (info) {
734 /* Move the most recent entry to the end of the list */
735 dl_list_del(&info->list);
736 dl_list_add_tail(&iface->sta_seen, &info->list);
737 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800738 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800739 return;
740 }
741
742 /* Add a new entry */
743 info = os_zalloc(sizeof(*info));
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700744 if (info == NULL)
745 return;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800746 os_memcpy(info->addr, addr, ETH_ALEN);
747 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800748 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800749
750 if (iface->num_sta_seen >= iface->conf->track_sta_max_num) {
751 /* Expire oldest entry to make room for a new one */
752 sta_track_expire(iface, 1);
753 }
754
755 wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
756 MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr));
757 dl_list_add_tail(&iface->sta_seen, &info->list);
758 iface->num_sta_seen++;
759}
760
761
762struct hostapd_data *
763sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
764 const char *ifname)
765{
766 struct hapd_interfaces *interfaces = iface->interfaces;
767 size_t i, j;
768
769 for (i = 0; i < interfaces->count; i++) {
770 struct hostapd_data *hapd = NULL;
771
772 iface = interfaces->iface[i];
773 for (j = 0; j < iface->num_bss; j++) {
774 hapd = iface->bss[j];
775 if (os_strcmp(ifname, hapd->conf->iface) == 0)
776 break;
777 hapd = NULL;
778 }
779
780 if (hapd && sta_track_get(iface, addr))
781 return hapd;
782 }
783
784 return NULL;
785}
786
787
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700788#ifdef CONFIG_TAXONOMY
789void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr,
790 struct wpabuf **probe_ie_taxonomy)
791{
792 struct hostapd_sta_info *info;
793
794 info = sta_track_get(iface, addr);
795 if (!info)
796 return;
797
798 wpabuf_free(*probe_ie_taxonomy);
799 *probe_ie_taxonomy = info->probe_ie_taxonomy;
800 info->probe_ie_taxonomy = NULL;
801}
802#endif /* CONFIG_TAXONOMY */
803
804
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700805void handle_probe_req(struct hostapd_data *hapd,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700806 const struct ieee80211_mgmt *mgmt, size_t len,
807 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700808{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800809 u8 *resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700810 struct ieee802_11_elems elems;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700811 const u8 *ie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800812 size_t ie_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800813 size_t i, resp_len;
814 int noack;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800815 enum ssid_match_result res;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800816 int ret;
817 u16 csa_offs[2];
818 size_t csa_offs_len;
Hai Shalomfdcde762020-04-02 11:19:20 -0700819 struct radius_sta rad_info;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700820
Dmitry Shmidte4663042016-04-04 10:07:49 -0700821 if (len < IEEE80211_HDRLEN)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700822 return;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700823 ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800824 if (hapd->iconf->track_sta_max_num)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800825 sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
Dmitry Shmidte4663042016-04-04 10:07:49 -0700826 ie_len = len - IEEE80211_HDRLEN;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700827
Hai Shalomfdcde762020-04-02 11:19:20 -0700828 ret = hostapd_allowed_address(hapd, mgmt->sa, (const u8 *) mgmt, len,
829 &rad_info, 1);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700830 if (ret == HOSTAPD_ACL_REJECT) {
831 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
832 "Ignore Probe Request frame from " MACSTR
833 " due to ACL reject ", MAC2STR(mgmt->sa));
834 return;
835 }
836
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700837 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
838 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800839 mgmt->sa, mgmt->da, mgmt->bssid,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700840 ie, ie_len, ssi_signal) > 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700841 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800842
Hai Shalom74f70d42019-02-11 14:42:39 -0800843 if (!hapd->conf->send_probe_response)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700844 return;
845
846 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
847 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
848 MAC2STR(mgmt->sa));
849 return;
850 }
851
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700852 if ((!elems.ssid || !elems.supp_rates)) {
853 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
854 "without SSID or supported rates element",
855 MAC2STR(mgmt->sa));
856 return;
857 }
858
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800859 /*
860 * No need to reply if the Probe Request frame was sent on an adjacent
861 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
862 * AP with dot11RadioMeasurementActivated set to true, but strictly
863 * speaking does not allow such ignoring of Probe Request frames if
864 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
865 * number of unnecessary Probe Response frames for cases where the STA
866 * is less likely to see them (Probe Request frame sent on a
867 * neighboring, but partially overlapping, channel).
868 */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700869 if (elems.ds_params &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800870 hapd->iface->current_mode &&
871 (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
872 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
873 hapd->iconf->channel != elems.ds_params[0]) {
874 wpa_printf(MSG_DEBUG,
875 "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
876 hapd->iconf->channel, elems.ds_params[0]);
877 return;
878 }
879
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700880#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800881 if (hapd->p2p && hapd->p2p_group && elems.wps_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700882 struct wpabuf *wps;
883 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
884 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
885 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
886 "due to mismatch with Requested Device "
887 "Type");
888 wpabuf_free(wps);
889 return;
890 }
891 wpabuf_free(wps);
892 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800893
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800894 if (hapd->p2p && hapd->p2p_group && elems.p2p) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800895 struct wpabuf *p2p;
896 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
897 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
898 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
899 "due to mismatch with Device ID");
900 wpabuf_free(p2p);
901 return;
902 }
903 wpabuf_free(p2p);
904 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700905#endif /* CONFIG_P2P */
906
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800907 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
Hai Shalomfdcde762020-04-02 11:19:20 -0700908 elems.ssid_list_len == 0 && elems.short_ssid_list_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700909 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
910 "broadcast SSID ignored", MAC2STR(mgmt->sa));
911 return;
912 }
913
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700914#ifdef CONFIG_P2P
915 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
916 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
917 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
918 P2P_WILDCARD_SSID_LEN) == 0) {
919 /* Process P2P Wildcard SSID like Wildcard SSID */
920 elems.ssid_len = 0;
921 }
922#endif /* CONFIG_P2P */
923
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700924#ifdef CONFIG_TAXONOMY
925 {
926 struct sta_info *sta;
927 struct hostapd_sta_info *info;
928
929 if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) {
930 taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len);
931 } else if ((info = sta_track_get(hapd->iface,
932 mgmt->sa)) != NULL) {
933 taxonomy_hostapd_sta_info_probe_req(hapd, info,
934 ie, ie_len);
935 }
936 }
937#endif /* CONFIG_TAXONOMY */
938
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800939 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
Hai Shalomfdcde762020-04-02 11:19:20 -0700940 elems.ssid_list, elems.ssid_list_len,
941 elems.short_ssid_list, elems.short_ssid_list_len);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700942 if (res == NO_SSID_MATCH) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700943 if (!(mgmt->da[0] & 0x01)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700944 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800945 " for foreign SSID '%s' (DA " MACSTR ")%s",
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800946 MAC2STR(mgmt->sa),
947 wpa_ssid_txt(elems.ssid, elems.ssid_len),
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800948 MAC2STR(mgmt->da),
949 elems.ssid_list ? " (SSID list)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700950 }
951 return;
952 }
953
Hai Shalomfdcde762020-04-02 11:19:20 -0700954 if (hapd->conf->ignore_broadcast_ssid && res == WILDCARD_SSID_MATCH) {
955 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
956 "broadcast SSID ignored", MAC2STR(mgmt->sa));
957 return;
958 }
959
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800960#ifdef CONFIG_INTERWORKING
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -0700961 if (hapd->conf->interworking &&
962 elems.interworking && elems.interworking_len >= 1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800963 u8 ant = elems.interworking[0] & 0x0f;
964 if (ant != INTERWORKING_ANT_WILDCARD &&
965 ant != hapd->conf->access_network_type) {
966 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
967 " for mismatching ANT %u ignored",
968 MAC2STR(mgmt->sa), ant);
969 return;
970 }
971 }
972
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -0700973 if (hapd->conf->interworking && elems.interworking &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800974 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
975 const u8 *hessid;
976 if (elems.interworking_len == 7)
977 hessid = elems.interworking + 1;
978 else
979 hessid = elems.interworking + 1 + 2;
980 if (!is_broadcast_ether_addr(hessid) &&
981 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
982 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
983 " for mismatching HESSID " MACSTR
984 " ignored",
985 MAC2STR(mgmt->sa), MAC2STR(hessid));
986 return;
987 }
988 }
989#endif /* CONFIG_INTERWORKING */
990
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700991#ifdef CONFIG_P2P
992 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
993 supp_rates_11b_only(&elems)) {
994 /* Indicates support for 11b rates only */
995 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
996 MACSTR " with only 802.11b rates",
997 MAC2STR(mgmt->sa));
998 return;
999 }
1000#endif /* CONFIG_P2P */
1001
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001002 /* TODO: verify that supp_rates contains at least one matching rate
1003 * with AP configuration */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001004
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001005 if (hapd->conf->no_probe_resp_if_seen_on &&
1006 is_multicast_ether_addr(mgmt->da) &&
1007 is_multicast_ether_addr(mgmt->bssid) &&
1008 sta_track_seen_on(hapd->iface, mgmt->sa,
1009 hapd->conf->no_probe_resp_if_seen_on)) {
1010 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1011 " since STA has been seen on %s",
1012 hapd->conf->iface, MAC2STR(mgmt->sa),
1013 hapd->conf->no_probe_resp_if_seen_on);
1014 return;
1015 }
1016
1017 if (hapd->conf->no_probe_resp_if_max_sta &&
1018 is_multicast_ether_addr(mgmt->da) &&
1019 is_multicast_ether_addr(mgmt->bssid) &&
1020 hapd->num_sta >= hapd->conf->max_num_sta &&
1021 !ap_get_sta(hapd, mgmt->sa)) {
1022 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1023 " since no room for additional STA",
1024 hapd->conf->iface, MAC2STR(mgmt->sa));
1025 return;
1026 }
1027
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001028#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001029 if (hapd->iconf->ignore_probe_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001030 drand48() < hapd->iconf->ignore_probe_probability) {
1031 wpa_printf(MSG_INFO,
1032 "TESTING: ignoring probe request from " MACSTR,
1033 MAC2STR(mgmt->sa));
1034 return;
1035 }
1036#endif /* CONFIG_TESTING_OPTIONS */
1037
Roshan Pius3a1667e2018-07-03 15:17:14 -07001038 wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, RX_PROBE_REQUEST "sa=" MACSTR
1039 " signal=%d", MAC2STR(mgmt->sa), ssi_signal);
1040
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001041 resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001042 &resp_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001043 if (resp == NULL)
1044 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001045
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001046 /*
1047 * If this is a broadcast probe request, apply no ack policy to avoid
1048 * excessive retries.
1049 */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001050 noack = !!(res == WILDCARD_SSID_MATCH &&
1051 is_broadcast_ether_addr(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001052
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001053 csa_offs_len = 0;
1054 if (hapd->csa_in_progress) {
1055 if (hapd->cs_c_off_proberesp)
1056 csa_offs[csa_offs_len++] =
1057 hapd->cs_c_off_proberesp;
1058
1059 if (hapd->cs_c_off_ecsa_proberesp)
1060 csa_offs[csa_offs_len++] =
1061 hapd->cs_c_off_ecsa_proberesp;
1062 }
1063
Hai Shalomfdcde762020-04-02 11:19:20 -07001064 ret = hostapd_drv_send_mlme(hapd, resp, resp_len, noack,
1065 csa_offs_len ? csa_offs : NULL,
1066 csa_offs_len, 0);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001067
1068 if (ret < 0)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001069 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001070
1071 os_free(resp);
1072
1073 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
1074 "SSID", MAC2STR(mgmt->sa),
1075 elems.ssid_len == 0 ? "broadcast" : "our");
1076}
1077
1078
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001079static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
1080 size_t *resp_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001081{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001082 /* check probe response offloading caps and print warnings */
1083 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
1084 return NULL;
1085
1086#ifdef CONFIG_WPS
1087 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
1088 (!(hapd->iface->probe_resp_offloads &
1089 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
1090 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
1091 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
1092 "Probe Response while not supporting this");
1093#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001094
1095#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001096 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
1097 !(hapd->iface->probe_resp_offloads &
1098 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
1099 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
1100 "Probe Response while not supporting this");
1101#endif /* CONFIG_P2P */
1102
1103 if (hapd->conf->interworking &&
1104 !(hapd->iface->probe_resp_offloads &
1105 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
1106 wpa_printf(MSG_WARNING, "Device is trying to offload "
1107 "Interworking Probe Response while not supporting "
1108 "this");
1109
1110 /* Generate a Probe Response template for the non-P2P case */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001111 return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001112}
1113
1114#endif /* NEED_AP_MLME */
1115
1116
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001117void sta_track_del(struct hostapd_sta_info *info)
1118{
1119#ifdef CONFIG_TAXONOMY
1120 wpabuf_free(info->probe_ie_taxonomy);
1121 info->probe_ie_taxonomy = NULL;
1122#endif /* CONFIG_TAXONOMY */
1123 os_free(info);
1124}
1125
1126
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001127int ieee802_11_build_ap_params(struct hostapd_data *hapd,
1128 struct wpa_driver_ap_params *params)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001129{
1130 struct ieee80211_mgmt *head = NULL;
1131 u8 *tail = NULL;
1132 size_t head_len = 0, tail_len = 0;
1133 u8 *resp = NULL;
1134 size_t resp_len = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001135#ifdef NEED_AP_MLME
1136 u16 capab_info;
Hai Shalomfdcde762020-04-02 11:19:20 -07001137 u8 *pos, *tailpos, *tailend, *csa_pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001138
1139#define BEACON_HEAD_BUF_SIZE 256
1140#define BEACON_TAIL_BUF_SIZE 512
1141 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
1142 tail_len = BEACON_TAIL_BUF_SIZE;
1143#ifdef CONFIG_WPS
1144 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
1145 tail_len += wpabuf_len(hapd->wps_beacon_ie);
1146#endif /* CONFIG_WPS */
1147#ifdef CONFIG_P2P
1148 if (hapd->p2p_beacon_ie)
1149 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
1150#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001151#ifdef CONFIG_FST
1152 if (hapd->iface->fst_ies)
1153 tail_len += wpabuf_len(hapd->iface->fst_ies);
1154#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001155 if (hapd->conf->vendor_elements)
1156 tail_len += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001157
1158#ifdef CONFIG_IEEE80211AC
1159 if (hapd->conf->vendor_vht) {
1160 tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
1161 2 + sizeof(struct ieee80211_vht_operation);
1162 }
1163#endif /* CONFIG_IEEE80211AC */
1164
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001165#ifdef CONFIG_IEEE80211AX
1166 if (hapd->iconf->ieee80211ax) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001167 tail_len += 3 + sizeof(struct ieee80211_he_capabilities) +
Hai Shalom74f70d42019-02-11 14:42:39 -08001168 3 + sizeof(struct ieee80211_he_operation) +
Hai Shalom81f62d82019-07-22 12:10:00 -07001169 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
1170 3 + sizeof(struct ieee80211_spatial_reuse);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001171 if (is_6ghz_op_class(hapd->iconf->op_class))
1172 tail_len += sizeof(struct ieee80211_he_6ghz_oper_info) +
1173 3 + sizeof(struct ieee80211_he_6ghz_band_cap);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001174 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001175#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001176
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001177 tail_len += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001178 tail_len += hostapd_eid_owe_trans_len(hapd);
Hai Shalomfdcde762020-04-02 11:19:20 -07001179 tail_len += hostapd_eid_dpp_cc_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001180
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001181 tailpos = tail = os_malloc(tail_len);
1182 if (head == NULL || tail == NULL) {
1183 wpa_printf(MSG_ERROR, "Failed to set beacon data");
1184 os_free(head);
1185 os_free(tail);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001186 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001187 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001188 tailend = tail + tail_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001189
1190 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1191 WLAN_FC_STYPE_BEACON);
1192 head->duration = host_to_le16(0);
1193 os_memset(head->da, 0xff, ETH_ALEN);
1194
1195 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1196 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1197 head->u.beacon.beacon_int =
1198 host_to_le16(hapd->iconf->beacon_int);
1199
1200 /* hardware or low-level driver will setup seq_ctrl and timestamp */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001201 capab_info = hostapd_own_capab_info(hapd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001202 head->u.beacon.capab_info = host_to_le16(capab_info);
1203 pos = &head->u.beacon.variable[0];
1204
1205 /* SSID */
1206 *pos++ = WLAN_EID_SSID;
1207 if (hapd->conf->ignore_broadcast_ssid == 2) {
1208 /* clear the data, but keep the correct length of the SSID */
1209 *pos++ = hapd->conf->ssid.ssid_len;
1210 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
1211 pos += hapd->conf->ssid.ssid_len;
1212 } else if (hapd->conf->ignore_broadcast_ssid) {
1213 *pos++ = 0; /* empty SSID */
1214 } else {
1215 *pos++ = hapd->conf->ssid.ssid_len;
1216 os_memcpy(pos, hapd->conf->ssid.ssid,
1217 hapd->conf->ssid.ssid_len);
1218 pos += hapd->conf->ssid.ssid_len;
1219 }
1220
1221 /* Supported rates */
1222 pos = hostapd_eid_supp_rates(hapd, pos);
1223
1224 /* DS Params */
1225 pos = hostapd_eid_ds_params(hapd, pos);
1226
1227 head_len = pos - (u8 *) head;
1228
Hai Shalomfdcde762020-04-02 11:19:20 -07001229 tailpos = hostapd_eid_country(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001230
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001231 /* Power Constraint element */
1232 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
1233
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001234 /* CSA IE */
1235 csa_pos = hostapd_eid_csa(hapd, tailpos);
1236 if (csa_pos != tailpos)
1237 hapd->cs_c_off_beacon = csa_pos - tail - 1;
1238 tailpos = csa_pos;
1239
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001240 /* ERP Information element */
1241 tailpos = hostapd_eid_erp_info(hapd, tailpos);
1242
1243 /* Extended supported rates */
1244 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
1245
Hai Shalomfdcde762020-04-02 11:19:20 -07001246 tailpos = hostapd_get_rsne(hapd, tailpos, tailend - tailpos);
1247 tailpos = hostapd_eid_bss_load(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001248 tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
Hai Shalomfdcde762020-04-02 11:19:20 -07001249 tailend - tailpos);
1250 tailpos = hostapd_get_mde(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001251
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001252 /* eCSA IE */
1253 csa_pos = hostapd_eid_ecsa(hapd, tailpos);
1254 if (csa_pos != tailpos)
1255 hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1;
1256 tailpos = csa_pos;
1257
1258 tailpos = hostapd_eid_supported_op_classes(hapd, tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001259 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
1260 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001261
1262 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
1263
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001264 /*
1265 * TODO: Time Advertisement element should only be included in some
1266 * DTIM Beacon frames.
1267 */
1268 tailpos = hostapd_eid_time_adv(hapd, tailpos);
1269
1270 tailpos = hostapd_eid_interworking(hapd, tailpos);
1271 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
1272 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001273
1274#ifdef CONFIG_FST
1275 if (hapd->iface->fst_ies) {
1276 os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies),
1277 wpabuf_len(hapd->iface->fst_ies));
1278 tailpos += wpabuf_len(hapd->iface->fst_ies);
1279 }
1280#endif /* CONFIG_FST */
1281
Dmitry Shmidt04949592012-07-19 12:16:46 -07001282#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001283 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -07001284 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001285 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08001286 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001287 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001288#endif /* CONFIG_IEEE80211AC */
1289
Hai Shalom899fcc72020-10-19 14:38:18 -07001290 if ((hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) ||
1291 hapd->iconf->ieee80211ax)
1292 tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos);
1293
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001294 tailpos = hostapd_eid_fils_indic(hapd, tailpos, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -07001295 tailpos = hostapd_get_rsnxe(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001296
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001297#ifdef CONFIG_IEEE80211AX
1298 if (hapd->iconf->ieee80211ax) {
Hai Shalom81f62d82019-07-22 12:10:00 -07001299 tailpos = hostapd_eid_he_capab(hapd, tailpos,
1300 IEEE80211_MODE_AP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001301 tailpos = hostapd_eid_he_operation(hapd, tailpos);
Hai Shalom81f62d82019-07-22 12:10:00 -07001302 tailpos = hostapd_eid_spatial_reuse(hapd, tailpos);
Hai Shalomfdcde762020-04-02 11:19:20 -07001303 tailpos = hostapd_eid_he_mu_edca_parameter_set(hapd, tailpos);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001304 tailpos = hostapd_eid_he_6ghz_band_cap(hapd, tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001305 }
1306#endif /* CONFIG_IEEE80211AX */
1307
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001308#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001309 if (hapd->conf->vendor_vht)
1310 tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001311#endif /* CONFIG_IEEE80211AC */
1312
Hai Shalomfdcde762020-04-02 11:19:20 -07001313 /* WPA / OSEN */
1314 tailpos = hostapd_get_wpa_ie(hapd, tailpos, tailend - tailpos);
1315 tailpos = hostapd_get_osen_ie(hapd, tailpos, tailend - tailpos);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001316
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001317 /* Wi-Fi Alliance WMM */
1318 tailpos = hostapd_eid_wmm(hapd, tailpos);
1319
1320#ifdef CONFIG_WPS
1321 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
1322 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
1323 wpabuf_len(hapd->wps_beacon_ie));
1324 tailpos += wpabuf_len(hapd->wps_beacon_ie);
1325 }
1326#endif /* CONFIG_WPS */
1327
1328#ifdef CONFIG_P2P
1329 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
1330 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
1331 wpabuf_len(hapd->p2p_beacon_ie));
1332 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
1333 }
1334#endif /* CONFIG_P2P */
1335#ifdef CONFIG_P2P_MANAGER
1336 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
1337 P2P_MANAGE)
1338 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
1339#endif /* CONFIG_P2P_MANAGER */
1340
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001341#ifdef CONFIG_HS20
1342 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
1343#endif /* CONFIG_HS20 */
1344
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001345 tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001346 tailpos = hostapd_eid_owe_trans(hapd, tailpos,
1347 tail + tail_len - tailpos);
Hai Shalomfdcde762020-04-02 11:19:20 -07001348 tailpos = hostapd_eid_dpp_cc(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001349
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001350 if (hapd->conf->vendor_elements) {
1351 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
1352 wpabuf_len(hapd->conf->vendor_elements));
1353 tailpos += wpabuf_len(hapd->conf->vendor_elements);
1354 }
1355
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001356 tail_len = tailpos > tail ? tailpos - tail : 0;
1357
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001358 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
1359#endif /* NEED_AP_MLME */
1360
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001361 os_memset(params, 0, sizeof(*params));
1362 params->head = (u8 *) head;
1363 params->head_len = head_len;
1364 params->tail = tail;
1365 params->tail_len = tail_len;
1366 params->proberesp = resp;
1367 params->proberesp_len = resp_len;
1368 params->dtim_period = hapd->conf->dtim_period;
1369 params->beacon_int = hapd->iconf->beacon_int;
1370 params->basic_rates = hapd->iface->basic_rates;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001371 params->beacon_rate = hapd->iconf->beacon_rate;
1372 params->rate_type = hapd->iconf->rate_type;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001373 params->ssid = hapd->conf->ssid.ssid;
1374 params->ssid_len = hapd->conf->ssid.ssid_len;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001375 if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
1376 (WPA_PROTO_WPA | WPA_PROTO_RSN))
1377 params->pairwise_ciphers = hapd->conf->wpa_pairwise |
1378 hapd->conf->rsn_pairwise;
1379 else if (hapd->conf->wpa & WPA_PROTO_RSN)
1380 params->pairwise_ciphers = hapd->conf->rsn_pairwise;
1381 else if (hapd->conf->wpa & WPA_PROTO_WPA)
1382 params->pairwise_ciphers = hapd->conf->wpa_pairwise;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001383 params->group_cipher = hapd->conf->wpa_group;
1384 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
1385 params->auth_algs = hapd->conf->auth_algs;
1386 params->wpa_version = hapd->conf->wpa;
Hai Shalomfdcde762020-04-02 11:19:20 -07001387 params->privacy = hapd->conf->wpa;
1388#ifdef CONFIG_WEP
1389 params->privacy |= hapd->conf->ssid.wep.keys_set ||
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001390 (hapd->conf->ieee802_1x &&
1391 (hapd->conf->default_wep_key_len ||
1392 hapd->conf->individual_wep_key_len));
Hai Shalomfdcde762020-04-02 11:19:20 -07001393#endif /* CONFIG_WEP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001394 switch (hapd->conf->ignore_broadcast_ssid) {
1395 case 0:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001396 params->hide_ssid = NO_SSID_HIDING;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001397 break;
1398 case 1:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001399 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001400 break;
1401 case 2:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001402 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001403 break;
1404 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001405 params->isolate = hapd->conf->isolate;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001406#ifdef NEED_AP_MLME
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001407 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001408 ERP_INFO_USE_PROTECTION);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001409 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001410 hapd->iconf->preamble == SHORT_PREAMBLE;
1411 if (hapd->iface->current_mode &&
1412 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001413 params->short_slot_time =
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001414 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
1415 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001416 params->short_slot_time = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001417 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001418 params->ht_opmode = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001419 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001420 params->ht_opmode = hapd->iface->ht_op_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001421#endif /* NEED_AP_MLME */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001422 params->interworking = hapd->conf->interworking;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001423 if (hapd->conf->interworking &&
1424 !is_zero_ether_addr(hapd->conf->hessid))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001425 params->hessid = hapd->conf->hessid;
1426 params->access_network_type = hapd->conf->access_network_type;
1427 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001428#ifdef CONFIG_P2P
1429 params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
1430#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001431#ifdef CONFIG_HS20
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001432 params->disable_dgaf = hapd->conf->disable_dgaf;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001433 if (hapd->conf->osen) {
1434 params->privacy = 1;
1435 params->osen = 1;
1436 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001437#endif /* CONFIG_HS20 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001438 params->multicast_to_unicast = hapd->conf->multicast_to_unicast;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001439 params->pbss = hapd->conf->pbss;
Hai Shalom74f70d42019-02-11 14:42:39 -08001440
1441 if (hapd->conf->ftm_responder) {
1442 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_FTM_RESPONDER) {
1443 params->ftm_responder = 1;
1444 params->lci = hapd->iface->conf->lci;
1445 params->civic = hapd->iface->conf->civic;
1446 } else {
1447 wpa_printf(MSG_WARNING,
1448 "Not configuring FTM responder as the driver doesn't advertise support for it");
1449 }
1450 }
1451
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001452 return 0;
1453}
1454
1455
1456void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
1457{
1458 os_free(params->tail);
1459 params->tail = NULL;
1460 os_free(params->head);
1461 params->head = NULL;
1462 os_free(params->proberesp);
1463 params->proberesp = NULL;
1464}
1465
1466
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001467int ieee802_11_set_beacon(struct hostapd_data *hapd)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001468{
1469 struct wpa_driver_ap_params params;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001470 struct hostapd_freq_params freq;
1471 struct hostapd_iface *iface = hapd->iface;
1472 struct hostapd_config *iconf = iface->conf;
Hai Shalom81f62d82019-07-22 12:10:00 -07001473 struct hostapd_hw_modes *cmode = iface->current_mode;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001474 struct wpabuf *beacon, *proberesp, *assocresp;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001475 int res, ret = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001476
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001477 if (hapd->csa_in_progress) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001478 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001479 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001480 }
1481
1482 hapd->beacon_set_done = 1;
1483
1484 if (ieee802_11_build_ap_params(hapd, &params) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001485 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001486
1487 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
1488 0)
1489 goto fail;
1490
1491 params.beacon_ies = beacon;
1492 params.proberesp_ies = proberesp;
1493 params.assocresp_ies = assocresp;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001494 params.reenable = hapd->reenable_beacon;
Hai Shalomc3565922019-10-28 11:58:20 -07001495#ifdef CONFIG_IEEE80211AX
1496 params.he_spr = !!hapd->iface->conf->spr.sr_control;
1497 params.he_spr_srg_obss_pd_min_offset =
1498 hapd->iface->conf->spr.srg_obss_pd_min_offset;
1499 params.he_spr_srg_obss_pd_max_offset =
1500 hapd->iface->conf->spr.srg_obss_pd_max_offset;
Hai Shalomfdcde762020-04-02 11:19:20 -07001501 params.he_bss_color_disabled =
1502 hapd->iface->conf->he_op.he_bss_color_disabled;
1503 params.he_bss_color_partial =
1504 hapd->iface->conf->he_op.he_bss_color_partial;
1505 params.he_bss_color = hapd->iface->conf->he_op.he_bss_color;
1506 params.twt_responder = hostapd_get_he_twt_responder(hapd,
1507 IEEE80211_MODE_AP);
Hai Shalomc3565922019-10-28 11:58:20 -07001508#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001509 hapd->reenable_beacon = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001510
Hai Shalom81f62d82019-07-22 12:10:00 -07001511 if (cmode &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001512 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
Hai Shalomc3565922019-10-28 11:58:20 -07001513 iconf->channel, iconf->enable_edmg,
1514 iconf->edmg_channel, iconf->ieee80211n,
Hai Shalom81f62d82019-07-22 12:10:00 -07001515 iconf->ieee80211ac, iconf->ieee80211ax,
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001516 iconf->secondary_channel,
Hai Shalom81f62d82019-07-22 12:10:00 -07001517 hostapd_get_oper_chwidth(iconf),
1518 hostapd_get_oper_centr_freq_seg0_idx(iconf),
1519 hostapd_get_oper_centr_freq_seg1_idx(iconf),
1520 cmode->vht_capab,
1521 &cmode->he_capab[IEEE80211_MODE_AP]) == 0)
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001522 params.freq = &freq;
1523
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001524 res = hostapd_drv_set_ap(hapd, &params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001525 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001526 if (res)
1527 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
1528 else
1529 ret = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001530fail:
1531 ieee802_11_free_ap_params(&params);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001532 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001533}
1534
1535
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001536int ieee802_11_set_beacons(struct hostapd_iface *iface)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001537{
1538 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001539 int ret = 0;
1540
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08001541 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001542 if (iface->bss[i]->started &&
1543 ieee802_11_set_beacon(iface->bss[i]) < 0)
1544 ret = -1;
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08001545 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001546
1547 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001548}
1549
Dmitry Shmidt04949592012-07-19 12:16:46 -07001550
1551/* only update beacons if started */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001552int ieee802_11_update_beacons(struct hostapd_iface *iface)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001553{
1554 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001555 int ret = 0;
1556
1557 for (i = 0; i < iface->num_bss; i++) {
1558 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
1559 ieee802_11_set_beacon(iface->bss[i]) < 0)
1560 ret = -1;
1561 }
1562
1563 return ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001564}
1565
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001566#endif /* CONFIG_NATIVE_WINDOWS */