blob: 47ced9a166de7c0c5909dca915d0ac8502de8382 [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);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800466 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700467#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800468
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800469 buflen += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700470 buflen += hostapd_eid_owe_trans_len(hapd);
Hai Shalomfdcde762020-04-02 11:19:20 -0700471 buflen += hostapd_eid_dpp_cc_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800472
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800473 resp = os_zalloc(buflen);
474 if (resp == NULL)
475 return NULL;
476
477 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
478
479 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
480 WLAN_FC_STYPE_PROBE_RESP);
481 if (req)
482 os_memcpy(resp->da, req->sa, ETH_ALEN);
483 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
484
485 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
486 resp->u.probe_resp.beacon_int =
487 host_to_le16(hapd->iconf->beacon_int);
488
489 /* hardware or low-level driver will setup seq_ctrl and timestamp */
490 resp->u.probe_resp.capab_info =
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700491 host_to_le16(hostapd_own_capab_info(hapd));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800492
493 pos = resp->u.probe_resp.variable;
494 *pos++ = WLAN_EID_SSID;
495 *pos++ = hapd->conf->ssid.ssid_len;
496 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
497 pos += hapd->conf->ssid.ssid_len;
498
499 /* Supported rates */
500 pos = hostapd_eid_supp_rates(hapd, pos);
501
502 /* DS Params */
503 pos = hostapd_eid_ds_params(hapd, pos);
504
505 pos = hostapd_eid_country(hapd, pos, epos - pos);
506
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800507 /* Power Constraint element */
508 pos = hostapd_eid_pwr_constraint(hapd, pos);
509
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800510 /* CSA IE */
511 csa_pos = hostapd_eid_csa(hapd, pos);
512 if (csa_pos != pos)
513 hapd->cs_c_off_proberesp = csa_pos - (u8 *) resp - 1;
514 pos = csa_pos;
515
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800516 /* ERP Information element */
517 pos = hostapd_eid_erp_info(hapd, pos);
518
519 /* Extended supported rates */
520 pos = hostapd_eid_ext_supp_rates(hapd, pos);
521
Hai Shalomfdcde762020-04-02 11:19:20 -0700522 pos = hostapd_get_rsne(hapd, pos, epos - pos);
Dmitry Shmidt051af732013-10-22 13:52:46 -0700523 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800524 pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700525 pos = hostapd_get_mde(hapd, pos, epos - pos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800526
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800527 /* eCSA IE */
528 csa_pos = hostapd_eid_ecsa(hapd, pos);
529 if (csa_pos != pos)
530 hapd->cs_c_off_ecsa_proberesp = csa_pos - (u8 *) resp - 1;
531 pos = csa_pos;
532
533 pos = hostapd_eid_supported_op_classes(hapd, pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800534 pos = hostapd_eid_ht_capabilities(hapd, pos);
535 pos = hostapd_eid_ht_operation(hapd, pos);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800536
537 pos = hostapd_eid_ext_capab(hapd, pos);
538
539 pos = hostapd_eid_time_adv(hapd, pos);
540 pos = hostapd_eid_time_zone(hapd, pos);
541
542 pos = hostapd_eid_interworking(hapd, pos);
543 pos = hostapd_eid_adv_proto(hapd, pos);
544 pos = hostapd_eid_roaming_consortium(hapd, pos);
545
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800546#ifdef CONFIG_FST
547 if (hapd->iface->fst_ies) {
548 os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies),
549 wpabuf_len(hapd->iface->fst_ies));
550 pos += wpabuf_len(hapd->iface->fst_ies);
551 }
552#endif /* CONFIG_FST */
553
Dmitry Shmidt04949592012-07-19 12:16:46 -0700554#ifdef CONFIG_IEEE80211AC
Hai Shalomc3565922019-10-28 11:58:20 -0700555 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
556 !is_6ghz_op_class(hapd->iconf->op_class)) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700557 pos = hostapd_eid_vht_capabilities(hapd, pos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800558 pos = hostapd_eid_vht_operation(hapd, pos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800559 pos = hostapd_eid_txpower_envelope(hapd, pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800560 pos = hostapd_eid_wb_chsw_wrapper(hapd, pos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800561 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800562#endif /* CONFIG_IEEE80211AC */
563
564 pos = hostapd_eid_fils_indic(hapd, pos, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -0700565 pos = hostapd_get_rsnxe(hapd, pos, epos - pos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800566
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700567#ifdef CONFIG_IEEE80211AX
568 if (hapd->iconf->ieee80211ax) {
Hai Shalom81f62d82019-07-22 12:10:00 -0700569 pos = hostapd_eid_he_capab(hapd, pos, IEEE80211_MODE_AP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700570 pos = hostapd_eid_he_operation(hapd, pos);
Hai Shalom81f62d82019-07-22 12:10:00 -0700571 pos = hostapd_eid_spatial_reuse(hapd, pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700572 pos = hostapd_eid_he_mu_edca_parameter_set(hapd, pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700573 }
574#endif /* CONFIG_IEEE80211AX */
575
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800576#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800577 if (hapd->conf->vendor_vht)
578 pos = hostapd_eid_vendor_vht(hapd, pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700579#endif /* CONFIG_IEEE80211AC */
580
Hai Shalomfdcde762020-04-02 11:19:20 -0700581 /* WPA / OSEN */
582 pos = hostapd_get_wpa_ie(hapd, pos, epos - pos);
583 pos = hostapd_get_osen_ie(hapd, pos, epos - pos);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800584
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800585 /* Wi-Fi Alliance WMM */
586 pos = hostapd_eid_wmm(hapd, pos);
587
588#ifdef CONFIG_WPS
589 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
590 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
591 wpabuf_len(hapd->wps_probe_resp_ie));
592 pos += wpabuf_len(hapd->wps_probe_resp_ie);
593 }
594#endif /* CONFIG_WPS */
595
596#ifdef CONFIG_P2P
597 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
598 hapd->p2p_probe_resp_ie) {
599 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
600 wpabuf_len(hapd->p2p_probe_resp_ie));
601 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
602 }
603#endif /* CONFIG_P2P */
604#ifdef CONFIG_P2P_MANAGER
605 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
606 P2P_MANAGE)
607 pos = hostapd_eid_p2p_manage(hapd, pos);
608#endif /* CONFIG_P2P_MANAGER */
609
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700610#ifdef CONFIG_HS20
611 pos = hostapd_eid_hs20_indication(hapd, pos);
612#endif /* CONFIG_HS20 */
613
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800614 pos = hostapd_eid_mbo(hapd, pos, (u8 *) resp + buflen - pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700615 pos = hostapd_eid_owe_trans(hapd, pos, (u8 *) resp + buflen - pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700616 pos = hostapd_eid_dpp_cc(hapd, pos, (u8 *) resp + buflen - pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800617
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700618 if (hapd->conf->vendor_elements) {
619 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
620 wpabuf_len(hapd->conf->vendor_elements));
621 pos += wpabuf_len(hapd->conf->vendor_elements);
622 }
623
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800624 *resp_len = pos - (u8 *) resp;
625 return (u8 *) resp;
626}
627
628
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800629enum ssid_match_result {
630 NO_SSID_MATCH,
631 EXACT_SSID_MATCH,
632 WILDCARD_SSID_MATCH
633};
634
635static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
636 const u8 *ssid, size_t ssid_len,
637 const u8 *ssid_list,
Hai Shalomfdcde762020-04-02 11:19:20 -0700638 size_t ssid_list_len,
639 const u8 *short_ssid_list,
640 size_t short_ssid_list_len)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800641{
642 const u8 *pos, *end;
643 int wildcard = 0;
644
645 if (ssid_len == 0)
646 wildcard = 1;
647 if (ssid_len == hapd->conf->ssid.ssid_len &&
648 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
649 return EXACT_SSID_MATCH;
650
Hai Shalomfdcde762020-04-02 11:19:20 -0700651 if (ssid_list) {
652 pos = ssid_list;
653 end = ssid_list + ssid_list_len;
654 while (end - pos >= 2) {
655 if (2 + pos[1] > end - pos)
656 break;
657 if (pos[1] == 0)
658 wildcard = 1;
659 if (pos[1] == hapd->conf->ssid.ssid_len &&
660 os_memcmp(pos + 2, hapd->conf->ssid.ssid,
661 pos[1]) == 0)
662 return EXACT_SSID_MATCH;
663 pos += 2 + pos[1];
664 }
665 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800666
Hai Shalomfdcde762020-04-02 11:19:20 -0700667 if (short_ssid_list) {
668 pos = short_ssid_list;
669 end = short_ssid_list + short_ssid_list_len;
670 while (end - pos >= 4) {
671 if (hapd->conf->ssid.short_ssid == WPA_GET_LE32(pos))
672 return EXACT_SSID_MATCH;
673 pos += 4;
674 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800675 }
676
677 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
678}
679
680
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800681void sta_track_expire(struct hostapd_iface *iface, int force)
682{
683 struct os_reltime now;
684 struct hostapd_sta_info *info;
685
686 if (!iface->num_sta_seen)
687 return;
688
689 os_get_reltime(&now);
690 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
691 list))) {
692 if (!force &&
693 !os_reltime_expired(&now, &info->last_seen,
694 iface->conf->track_sta_max_age))
695 break;
696 force = 0;
697
698 wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
699 MACSTR, iface->bss[0]->conf->iface,
700 MAC2STR(info->addr));
701 dl_list_del(&info->list);
702 iface->num_sta_seen--;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700703 sta_track_del(info);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800704 }
705}
706
707
708static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
709 const u8 *addr)
710{
711 struct hostapd_sta_info *info;
712
713 dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
714 if (os_memcmp(addr, info->addr, ETH_ALEN) == 0)
715 return info;
716
717 return NULL;
718}
719
720
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800721void sta_track_add(struct hostapd_iface *iface, const u8 *addr, int ssi_signal)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800722{
723 struct hostapd_sta_info *info;
724
725 info = sta_track_get(iface, addr);
726 if (info) {
727 /* Move the most recent entry to the end of the list */
728 dl_list_del(&info->list);
729 dl_list_add_tail(&iface->sta_seen, &info->list);
730 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800731 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800732 return;
733 }
734
735 /* Add a new entry */
736 info = os_zalloc(sizeof(*info));
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700737 if (info == NULL)
738 return;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800739 os_memcpy(info->addr, addr, ETH_ALEN);
740 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800741 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800742
743 if (iface->num_sta_seen >= iface->conf->track_sta_max_num) {
744 /* Expire oldest entry to make room for a new one */
745 sta_track_expire(iface, 1);
746 }
747
748 wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
749 MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr));
750 dl_list_add_tail(&iface->sta_seen, &info->list);
751 iface->num_sta_seen++;
752}
753
754
755struct hostapd_data *
756sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
757 const char *ifname)
758{
759 struct hapd_interfaces *interfaces = iface->interfaces;
760 size_t i, j;
761
762 for (i = 0; i < interfaces->count; i++) {
763 struct hostapd_data *hapd = NULL;
764
765 iface = interfaces->iface[i];
766 for (j = 0; j < iface->num_bss; j++) {
767 hapd = iface->bss[j];
768 if (os_strcmp(ifname, hapd->conf->iface) == 0)
769 break;
770 hapd = NULL;
771 }
772
773 if (hapd && sta_track_get(iface, addr))
774 return hapd;
775 }
776
777 return NULL;
778}
779
780
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700781#ifdef CONFIG_TAXONOMY
782void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr,
783 struct wpabuf **probe_ie_taxonomy)
784{
785 struct hostapd_sta_info *info;
786
787 info = sta_track_get(iface, addr);
788 if (!info)
789 return;
790
791 wpabuf_free(*probe_ie_taxonomy);
792 *probe_ie_taxonomy = info->probe_ie_taxonomy;
793 info->probe_ie_taxonomy = NULL;
794}
795#endif /* CONFIG_TAXONOMY */
796
797
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700798void handle_probe_req(struct hostapd_data *hapd,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700799 const struct ieee80211_mgmt *mgmt, size_t len,
800 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700801{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800802 u8 *resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700803 struct ieee802_11_elems elems;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700804 const u8 *ie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800805 size_t ie_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800806 size_t i, resp_len;
807 int noack;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800808 enum ssid_match_result res;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800809 int ret;
810 u16 csa_offs[2];
811 size_t csa_offs_len;
Hai Shalomfdcde762020-04-02 11:19:20 -0700812 struct radius_sta rad_info;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700813
Dmitry Shmidte4663042016-04-04 10:07:49 -0700814 if (len < IEEE80211_HDRLEN)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700815 return;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700816 ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800817 if (hapd->iconf->track_sta_max_num)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800818 sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
Dmitry Shmidte4663042016-04-04 10:07:49 -0700819 ie_len = len - IEEE80211_HDRLEN;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700820
Hai Shalomfdcde762020-04-02 11:19:20 -0700821 ret = hostapd_allowed_address(hapd, mgmt->sa, (const u8 *) mgmt, len,
822 &rad_info, 1);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700823 if (ret == HOSTAPD_ACL_REJECT) {
824 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
825 "Ignore Probe Request frame from " MACSTR
826 " due to ACL reject ", MAC2STR(mgmt->sa));
827 return;
828 }
829
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700830 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
831 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800832 mgmt->sa, mgmt->da, mgmt->bssid,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700833 ie, ie_len, ssi_signal) > 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700834 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800835
Hai Shalom74f70d42019-02-11 14:42:39 -0800836 if (!hapd->conf->send_probe_response)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700837 return;
838
839 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
840 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
841 MAC2STR(mgmt->sa));
842 return;
843 }
844
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700845 if ((!elems.ssid || !elems.supp_rates)) {
846 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
847 "without SSID or supported rates element",
848 MAC2STR(mgmt->sa));
849 return;
850 }
851
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800852 /*
853 * No need to reply if the Probe Request frame was sent on an adjacent
854 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
855 * AP with dot11RadioMeasurementActivated set to true, but strictly
856 * speaking does not allow such ignoring of Probe Request frames if
857 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
858 * number of unnecessary Probe Response frames for cases where the STA
859 * is less likely to see them (Probe Request frame sent on a
860 * neighboring, but partially overlapping, channel).
861 */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700862 if (elems.ds_params &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800863 hapd->iface->current_mode &&
864 (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
865 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
866 hapd->iconf->channel != elems.ds_params[0]) {
867 wpa_printf(MSG_DEBUG,
868 "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
869 hapd->iconf->channel, elems.ds_params[0]);
870 return;
871 }
872
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700873#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800874 if (hapd->p2p && hapd->p2p_group && elems.wps_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700875 struct wpabuf *wps;
876 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
877 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
878 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
879 "due to mismatch with Requested Device "
880 "Type");
881 wpabuf_free(wps);
882 return;
883 }
884 wpabuf_free(wps);
885 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800886
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800887 if (hapd->p2p && hapd->p2p_group && elems.p2p) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800888 struct wpabuf *p2p;
889 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
890 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
891 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
892 "due to mismatch with Device ID");
893 wpabuf_free(p2p);
894 return;
895 }
896 wpabuf_free(p2p);
897 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700898#endif /* CONFIG_P2P */
899
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800900 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
Hai Shalomfdcde762020-04-02 11:19:20 -0700901 elems.ssid_list_len == 0 && elems.short_ssid_list_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700902 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
903 "broadcast SSID ignored", MAC2STR(mgmt->sa));
904 return;
905 }
906
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700907#ifdef CONFIG_P2P
908 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
909 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
910 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
911 P2P_WILDCARD_SSID_LEN) == 0) {
912 /* Process P2P Wildcard SSID like Wildcard SSID */
913 elems.ssid_len = 0;
914 }
915#endif /* CONFIG_P2P */
916
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700917#ifdef CONFIG_TAXONOMY
918 {
919 struct sta_info *sta;
920 struct hostapd_sta_info *info;
921
922 if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) {
923 taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len);
924 } else if ((info = sta_track_get(hapd->iface,
925 mgmt->sa)) != NULL) {
926 taxonomy_hostapd_sta_info_probe_req(hapd, info,
927 ie, ie_len);
928 }
929 }
930#endif /* CONFIG_TAXONOMY */
931
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800932 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
Hai Shalomfdcde762020-04-02 11:19:20 -0700933 elems.ssid_list, elems.ssid_list_len,
934 elems.short_ssid_list, elems.short_ssid_list_len);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700935 if (res == NO_SSID_MATCH) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700936 if (!(mgmt->da[0] & 0x01)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700937 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800938 " for foreign SSID '%s' (DA " MACSTR ")%s",
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800939 MAC2STR(mgmt->sa),
940 wpa_ssid_txt(elems.ssid, elems.ssid_len),
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800941 MAC2STR(mgmt->da),
942 elems.ssid_list ? " (SSID list)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700943 }
944 return;
945 }
946
Hai Shalomfdcde762020-04-02 11:19:20 -0700947 if (hapd->conf->ignore_broadcast_ssid && res == WILDCARD_SSID_MATCH) {
948 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
949 "broadcast SSID ignored", MAC2STR(mgmt->sa));
950 return;
951 }
952
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800953#ifdef CONFIG_INTERWORKING
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -0700954 if (hapd->conf->interworking &&
955 elems.interworking && elems.interworking_len >= 1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800956 u8 ant = elems.interworking[0] & 0x0f;
957 if (ant != INTERWORKING_ANT_WILDCARD &&
958 ant != hapd->conf->access_network_type) {
959 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
960 " for mismatching ANT %u ignored",
961 MAC2STR(mgmt->sa), ant);
962 return;
963 }
964 }
965
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -0700966 if (hapd->conf->interworking && elems.interworking &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800967 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
968 const u8 *hessid;
969 if (elems.interworking_len == 7)
970 hessid = elems.interworking + 1;
971 else
972 hessid = elems.interworking + 1 + 2;
973 if (!is_broadcast_ether_addr(hessid) &&
974 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
975 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
976 " for mismatching HESSID " MACSTR
977 " ignored",
978 MAC2STR(mgmt->sa), MAC2STR(hessid));
979 return;
980 }
981 }
982#endif /* CONFIG_INTERWORKING */
983
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700984#ifdef CONFIG_P2P
985 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
986 supp_rates_11b_only(&elems)) {
987 /* Indicates support for 11b rates only */
988 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
989 MACSTR " with only 802.11b rates",
990 MAC2STR(mgmt->sa));
991 return;
992 }
993#endif /* CONFIG_P2P */
994
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700995 /* TODO: verify that supp_rates contains at least one matching rate
996 * with AP configuration */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800997
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800998 if (hapd->conf->no_probe_resp_if_seen_on &&
999 is_multicast_ether_addr(mgmt->da) &&
1000 is_multicast_ether_addr(mgmt->bssid) &&
1001 sta_track_seen_on(hapd->iface, mgmt->sa,
1002 hapd->conf->no_probe_resp_if_seen_on)) {
1003 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1004 " since STA has been seen on %s",
1005 hapd->conf->iface, MAC2STR(mgmt->sa),
1006 hapd->conf->no_probe_resp_if_seen_on);
1007 return;
1008 }
1009
1010 if (hapd->conf->no_probe_resp_if_max_sta &&
1011 is_multicast_ether_addr(mgmt->da) &&
1012 is_multicast_ether_addr(mgmt->bssid) &&
1013 hapd->num_sta >= hapd->conf->max_num_sta &&
1014 !ap_get_sta(hapd, mgmt->sa)) {
1015 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1016 " since no room for additional STA",
1017 hapd->conf->iface, MAC2STR(mgmt->sa));
1018 return;
1019 }
1020
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001021#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001022 if (hapd->iconf->ignore_probe_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001023 drand48() < hapd->iconf->ignore_probe_probability) {
1024 wpa_printf(MSG_INFO,
1025 "TESTING: ignoring probe request from " MACSTR,
1026 MAC2STR(mgmt->sa));
1027 return;
1028 }
1029#endif /* CONFIG_TESTING_OPTIONS */
1030
Roshan Pius3a1667e2018-07-03 15:17:14 -07001031 wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, RX_PROBE_REQUEST "sa=" MACSTR
1032 " signal=%d", MAC2STR(mgmt->sa), ssi_signal);
1033
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001034 resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001035 &resp_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001036 if (resp == NULL)
1037 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001038
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001039 /*
1040 * If this is a broadcast probe request, apply no ack policy to avoid
1041 * excessive retries.
1042 */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001043 noack = !!(res == WILDCARD_SSID_MATCH &&
1044 is_broadcast_ether_addr(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001045
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001046 csa_offs_len = 0;
1047 if (hapd->csa_in_progress) {
1048 if (hapd->cs_c_off_proberesp)
1049 csa_offs[csa_offs_len++] =
1050 hapd->cs_c_off_proberesp;
1051
1052 if (hapd->cs_c_off_ecsa_proberesp)
1053 csa_offs[csa_offs_len++] =
1054 hapd->cs_c_off_ecsa_proberesp;
1055 }
1056
Hai Shalomfdcde762020-04-02 11:19:20 -07001057 ret = hostapd_drv_send_mlme(hapd, resp, resp_len, noack,
1058 csa_offs_len ? csa_offs : NULL,
1059 csa_offs_len, 0);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001060
1061 if (ret < 0)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001062 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001063
1064 os_free(resp);
1065
1066 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
1067 "SSID", MAC2STR(mgmt->sa),
1068 elems.ssid_len == 0 ? "broadcast" : "our");
1069}
1070
1071
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001072static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
1073 size_t *resp_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001074{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001075 /* check probe response offloading caps and print warnings */
1076 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
1077 return NULL;
1078
1079#ifdef CONFIG_WPS
1080 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
1081 (!(hapd->iface->probe_resp_offloads &
1082 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
1083 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
1084 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
1085 "Probe Response while not supporting this");
1086#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001087
1088#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001089 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
1090 !(hapd->iface->probe_resp_offloads &
1091 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
1092 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
1093 "Probe Response while not supporting this");
1094#endif /* CONFIG_P2P */
1095
1096 if (hapd->conf->interworking &&
1097 !(hapd->iface->probe_resp_offloads &
1098 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
1099 wpa_printf(MSG_WARNING, "Device is trying to offload "
1100 "Interworking Probe Response while not supporting "
1101 "this");
1102
1103 /* Generate a Probe Response template for the non-P2P case */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001104 return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001105}
1106
1107#endif /* NEED_AP_MLME */
1108
1109
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001110void sta_track_del(struct hostapd_sta_info *info)
1111{
1112#ifdef CONFIG_TAXONOMY
1113 wpabuf_free(info->probe_ie_taxonomy);
1114 info->probe_ie_taxonomy = NULL;
1115#endif /* CONFIG_TAXONOMY */
1116 os_free(info);
1117}
1118
1119
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001120int ieee802_11_build_ap_params(struct hostapd_data *hapd,
1121 struct wpa_driver_ap_params *params)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001122{
1123 struct ieee80211_mgmt *head = NULL;
1124 u8 *tail = NULL;
1125 size_t head_len = 0, tail_len = 0;
1126 u8 *resp = NULL;
1127 size_t resp_len = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001128#ifdef NEED_AP_MLME
1129 u16 capab_info;
Hai Shalomfdcde762020-04-02 11:19:20 -07001130 u8 *pos, *tailpos, *tailend, *csa_pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001131
1132#define BEACON_HEAD_BUF_SIZE 256
1133#define BEACON_TAIL_BUF_SIZE 512
1134 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
1135 tail_len = BEACON_TAIL_BUF_SIZE;
1136#ifdef CONFIG_WPS
1137 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
1138 tail_len += wpabuf_len(hapd->wps_beacon_ie);
1139#endif /* CONFIG_WPS */
1140#ifdef CONFIG_P2P
1141 if (hapd->p2p_beacon_ie)
1142 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
1143#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001144#ifdef CONFIG_FST
1145 if (hapd->iface->fst_ies)
1146 tail_len += wpabuf_len(hapd->iface->fst_ies);
1147#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001148 if (hapd->conf->vendor_elements)
1149 tail_len += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001150
1151#ifdef CONFIG_IEEE80211AC
1152 if (hapd->conf->vendor_vht) {
1153 tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
1154 2 + sizeof(struct ieee80211_vht_operation);
1155 }
1156#endif /* CONFIG_IEEE80211AC */
1157
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001158#ifdef CONFIG_IEEE80211AX
1159 if (hapd->iconf->ieee80211ax) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001160 tail_len += 3 + sizeof(struct ieee80211_he_capabilities) +
Hai Shalom74f70d42019-02-11 14:42:39 -08001161 3 + sizeof(struct ieee80211_he_operation) +
Hai Shalom81f62d82019-07-22 12:10:00 -07001162 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
1163 3 + sizeof(struct ieee80211_spatial_reuse);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001164 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001165#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001166
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001167 tail_len += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001168 tail_len += hostapd_eid_owe_trans_len(hapd);
Hai Shalomfdcde762020-04-02 11:19:20 -07001169 tail_len += hostapd_eid_dpp_cc_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001170
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001171 tailpos = tail = os_malloc(tail_len);
1172 if (head == NULL || tail == NULL) {
1173 wpa_printf(MSG_ERROR, "Failed to set beacon data");
1174 os_free(head);
1175 os_free(tail);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001176 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001177 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001178 tailend = tail + tail_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001179
1180 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1181 WLAN_FC_STYPE_BEACON);
1182 head->duration = host_to_le16(0);
1183 os_memset(head->da, 0xff, ETH_ALEN);
1184
1185 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1186 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1187 head->u.beacon.beacon_int =
1188 host_to_le16(hapd->iconf->beacon_int);
1189
1190 /* hardware or low-level driver will setup seq_ctrl and timestamp */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001191 capab_info = hostapd_own_capab_info(hapd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001192 head->u.beacon.capab_info = host_to_le16(capab_info);
1193 pos = &head->u.beacon.variable[0];
1194
1195 /* SSID */
1196 *pos++ = WLAN_EID_SSID;
1197 if (hapd->conf->ignore_broadcast_ssid == 2) {
1198 /* clear the data, but keep the correct length of the SSID */
1199 *pos++ = hapd->conf->ssid.ssid_len;
1200 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
1201 pos += hapd->conf->ssid.ssid_len;
1202 } else if (hapd->conf->ignore_broadcast_ssid) {
1203 *pos++ = 0; /* empty SSID */
1204 } else {
1205 *pos++ = hapd->conf->ssid.ssid_len;
1206 os_memcpy(pos, hapd->conf->ssid.ssid,
1207 hapd->conf->ssid.ssid_len);
1208 pos += hapd->conf->ssid.ssid_len;
1209 }
1210
1211 /* Supported rates */
1212 pos = hostapd_eid_supp_rates(hapd, pos);
1213
1214 /* DS Params */
1215 pos = hostapd_eid_ds_params(hapd, pos);
1216
1217 head_len = pos - (u8 *) head;
1218
Hai Shalomfdcde762020-04-02 11:19:20 -07001219 tailpos = hostapd_eid_country(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001220
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001221 /* Power Constraint element */
1222 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
1223
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001224 /* CSA IE */
1225 csa_pos = hostapd_eid_csa(hapd, tailpos);
1226 if (csa_pos != tailpos)
1227 hapd->cs_c_off_beacon = csa_pos - tail - 1;
1228 tailpos = csa_pos;
1229
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001230 /* ERP Information element */
1231 tailpos = hostapd_eid_erp_info(hapd, tailpos);
1232
1233 /* Extended supported rates */
1234 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
1235
Hai Shalomfdcde762020-04-02 11:19:20 -07001236 tailpos = hostapd_get_rsne(hapd, tailpos, tailend - tailpos);
1237 tailpos = hostapd_eid_bss_load(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001238 tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
Hai Shalomfdcde762020-04-02 11:19:20 -07001239 tailend - tailpos);
1240 tailpos = hostapd_get_mde(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001241
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001242 /* eCSA IE */
1243 csa_pos = hostapd_eid_ecsa(hapd, tailpos);
1244 if (csa_pos != tailpos)
1245 hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1;
1246 tailpos = csa_pos;
1247
1248 tailpos = hostapd_eid_supported_op_classes(hapd, tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001249 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
1250 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001251
1252 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
1253
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001254 /*
1255 * TODO: Time Advertisement element should only be included in some
1256 * DTIM Beacon frames.
1257 */
1258 tailpos = hostapd_eid_time_adv(hapd, tailpos);
1259
1260 tailpos = hostapd_eid_interworking(hapd, tailpos);
1261 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
1262 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001263
1264#ifdef CONFIG_FST
1265 if (hapd->iface->fst_ies) {
1266 os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies),
1267 wpabuf_len(hapd->iface->fst_ies));
1268 tailpos += wpabuf_len(hapd->iface->fst_ies);
1269 }
1270#endif /* CONFIG_FST */
1271
Dmitry Shmidt04949592012-07-19 12:16:46 -07001272#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001273 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -07001274 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001275 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08001276 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001277 tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001278 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001279#endif /* CONFIG_IEEE80211AC */
1280
1281 tailpos = hostapd_eid_fils_indic(hapd, tailpos, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -07001282 tailpos = hostapd_get_rsnxe(hapd, tailpos, tailend - tailpos);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001283
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001284#ifdef CONFIG_IEEE80211AX
1285 if (hapd->iconf->ieee80211ax) {
Hai Shalom81f62d82019-07-22 12:10:00 -07001286 tailpos = hostapd_eid_he_capab(hapd, tailpos,
1287 IEEE80211_MODE_AP);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001288 tailpos = hostapd_eid_he_operation(hapd, tailpos);
Hai Shalom81f62d82019-07-22 12:10:00 -07001289 tailpos = hostapd_eid_spatial_reuse(hapd, tailpos);
Hai Shalomfdcde762020-04-02 11:19:20 -07001290 tailpos = hostapd_eid_he_mu_edca_parameter_set(hapd, tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001291 }
1292#endif /* CONFIG_IEEE80211AX */
1293
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001294#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001295 if (hapd->conf->vendor_vht)
1296 tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001297#endif /* CONFIG_IEEE80211AC */
1298
Hai Shalomfdcde762020-04-02 11:19:20 -07001299 /* WPA / OSEN */
1300 tailpos = hostapd_get_wpa_ie(hapd, tailpos, tailend - tailpos);
1301 tailpos = hostapd_get_osen_ie(hapd, tailpos, tailend - tailpos);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001302
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001303 /* Wi-Fi Alliance WMM */
1304 tailpos = hostapd_eid_wmm(hapd, tailpos);
1305
1306#ifdef CONFIG_WPS
1307 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
1308 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
1309 wpabuf_len(hapd->wps_beacon_ie));
1310 tailpos += wpabuf_len(hapd->wps_beacon_ie);
1311 }
1312#endif /* CONFIG_WPS */
1313
1314#ifdef CONFIG_P2P
1315 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
1316 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
1317 wpabuf_len(hapd->p2p_beacon_ie));
1318 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
1319 }
1320#endif /* CONFIG_P2P */
1321#ifdef CONFIG_P2P_MANAGER
1322 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
1323 P2P_MANAGE)
1324 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
1325#endif /* CONFIG_P2P_MANAGER */
1326
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001327#ifdef CONFIG_HS20
1328 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
1329#endif /* CONFIG_HS20 */
1330
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001331 tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001332 tailpos = hostapd_eid_owe_trans(hapd, tailpos,
1333 tail + tail_len - tailpos);
Hai Shalomfdcde762020-04-02 11:19:20 -07001334 tailpos = hostapd_eid_dpp_cc(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001335
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001336 if (hapd->conf->vendor_elements) {
1337 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
1338 wpabuf_len(hapd->conf->vendor_elements));
1339 tailpos += wpabuf_len(hapd->conf->vendor_elements);
1340 }
1341
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001342 tail_len = tailpos > tail ? tailpos - tail : 0;
1343
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001344 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
1345#endif /* NEED_AP_MLME */
1346
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001347 os_memset(params, 0, sizeof(*params));
1348 params->head = (u8 *) head;
1349 params->head_len = head_len;
1350 params->tail = tail;
1351 params->tail_len = tail_len;
1352 params->proberesp = resp;
1353 params->proberesp_len = resp_len;
1354 params->dtim_period = hapd->conf->dtim_period;
1355 params->beacon_int = hapd->iconf->beacon_int;
1356 params->basic_rates = hapd->iface->basic_rates;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001357 params->beacon_rate = hapd->iconf->beacon_rate;
1358 params->rate_type = hapd->iconf->rate_type;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001359 params->ssid = hapd->conf->ssid.ssid;
1360 params->ssid_len = hapd->conf->ssid.ssid_len;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001361 if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
1362 (WPA_PROTO_WPA | WPA_PROTO_RSN))
1363 params->pairwise_ciphers = hapd->conf->wpa_pairwise |
1364 hapd->conf->rsn_pairwise;
1365 else if (hapd->conf->wpa & WPA_PROTO_RSN)
1366 params->pairwise_ciphers = hapd->conf->rsn_pairwise;
1367 else if (hapd->conf->wpa & WPA_PROTO_WPA)
1368 params->pairwise_ciphers = hapd->conf->wpa_pairwise;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001369 params->group_cipher = hapd->conf->wpa_group;
1370 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
1371 params->auth_algs = hapd->conf->auth_algs;
1372 params->wpa_version = hapd->conf->wpa;
Hai Shalomfdcde762020-04-02 11:19:20 -07001373 params->privacy = hapd->conf->wpa;
1374#ifdef CONFIG_WEP
1375 params->privacy |= hapd->conf->ssid.wep.keys_set ||
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001376 (hapd->conf->ieee802_1x &&
1377 (hapd->conf->default_wep_key_len ||
1378 hapd->conf->individual_wep_key_len));
Hai Shalomfdcde762020-04-02 11:19:20 -07001379#endif /* CONFIG_WEP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001380 switch (hapd->conf->ignore_broadcast_ssid) {
1381 case 0:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001382 params->hide_ssid = NO_SSID_HIDING;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001383 break;
1384 case 1:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001385 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001386 break;
1387 case 2:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001388 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001389 break;
1390 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001391 params->isolate = hapd->conf->isolate;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001392#ifdef NEED_AP_MLME
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001393 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001394 ERP_INFO_USE_PROTECTION);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001395 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001396 hapd->iconf->preamble == SHORT_PREAMBLE;
1397 if (hapd->iface->current_mode &&
1398 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001399 params->short_slot_time =
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001400 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
1401 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001402 params->short_slot_time = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001403 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001404 params->ht_opmode = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001405 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001406 params->ht_opmode = hapd->iface->ht_op_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001407#endif /* NEED_AP_MLME */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001408 params->interworking = hapd->conf->interworking;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001409 if (hapd->conf->interworking &&
1410 !is_zero_ether_addr(hapd->conf->hessid))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001411 params->hessid = hapd->conf->hessid;
1412 params->access_network_type = hapd->conf->access_network_type;
1413 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001414#ifdef CONFIG_P2P
1415 params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
1416#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001417#ifdef CONFIG_HS20
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001418 params->disable_dgaf = hapd->conf->disable_dgaf;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001419 if (hapd->conf->osen) {
1420 params->privacy = 1;
1421 params->osen = 1;
1422 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001423#endif /* CONFIG_HS20 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001424 params->multicast_to_unicast = hapd->conf->multicast_to_unicast;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001425 params->pbss = hapd->conf->pbss;
Hai Shalom74f70d42019-02-11 14:42:39 -08001426
1427 if (hapd->conf->ftm_responder) {
1428 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_FTM_RESPONDER) {
1429 params->ftm_responder = 1;
1430 params->lci = hapd->iface->conf->lci;
1431 params->civic = hapd->iface->conf->civic;
1432 } else {
1433 wpa_printf(MSG_WARNING,
1434 "Not configuring FTM responder as the driver doesn't advertise support for it");
1435 }
1436 }
1437
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001438 return 0;
1439}
1440
1441
1442void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
1443{
1444 os_free(params->tail);
1445 params->tail = NULL;
1446 os_free(params->head);
1447 params->head = NULL;
1448 os_free(params->proberesp);
1449 params->proberesp = NULL;
1450}
1451
1452
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001453int ieee802_11_set_beacon(struct hostapd_data *hapd)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001454{
1455 struct wpa_driver_ap_params params;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001456 struct hostapd_freq_params freq;
1457 struct hostapd_iface *iface = hapd->iface;
1458 struct hostapd_config *iconf = iface->conf;
Hai Shalom81f62d82019-07-22 12:10:00 -07001459 struct hostapd_hw_modes *cmode = iface->current_mode;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001460 struct wpabuf *beacon, *proberesp, *assocresp;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001461 int res, ret = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001462
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001463 if (hapd->csa_in_progress) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001464 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001465 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001466 }
1467
1468 hapd->beacon_set_done = 1;
1469
1470 if (ieee802_11_build_ap_params(hapd, &params) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001471 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001472
1473 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
1474 0)
1475 goto fail;
1476
1477 params.beacon_ies = beacon;
1478 params.proberesp_ies = proberesp;
1479 params.assocresp_ies = assocresp;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001480 params.reenable = hapd->reenable_beacon;
Hai Shalomc3565922019-10-28 11:58:20 -07001481#ifdef CONFIG_IEEE80211AX
1482 params.he_spr = !!hapd->iface->conf->spr.sr_control;
1483 params.he_spr_srg_obss_pd_min_offset =
1484 hapd->iface->conf->spr.srg_obss_pd_min_offset;
1485 params.he_spr_srg_obss_pd_max_offset =
1486 hapd->iface->conf->spr.srg_obss_pd_max_offset;
Hai Shalomfdcde762020-04-02 11:19:20 -07001487 params.he_bss_color_disabled =
1488 hapd->iface->conf->he_op.he_bss_color_disabled;
1489 params.he_bss_color_partial =
1490 hapd->iface->conf->he_op.he_bss_color_partial;
1491 params.he_bss_color = hapd->iface->conf->he_op.he_bss_color;
1492 params.twt_responder = hostapd_get_he_twt_responder(hapd,
1493 IEEE80211_MODE_AP);
Hai Shalomc3565922019-10-28 11:58:20 -07001494#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001495 hapd->reenable_beacon = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001496
Hai Shalom81f62d82019-07-22 12:10:00 -07001497 if (cmode &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001498 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
Hai Shalomc3565922019-10-28 11:58:20 -07001499 iconf->channel, iconf->enable_edmg,
1500 iconf->edmg_channel, iconf->ieee80211n,
Hai Shalom81f62d82019-07-22 12:10:00 -07001501 iconf->ieee80211ac, iconf->ieee80211ax,
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001502 iconf->secondary_channel,
Hai Shalom81f62d82019-07-22 12:10:00 -07001503 hostapd_get_oper_chwidth(iconf),
1504 hostapd_get_oper_centr_freq_seg0_idx(iconf),
1505 hostapd_get_oper_centr_freq_seg1_idx(iconf),
1506 cmode->vht_capab,
1507 &cmode->he_capab[IEEE80211_MODE_AP]) == 0)
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001508 params.freq = &freq;
1509
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001510 res = hostapd_drv_set_ap(hapd, &params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001511 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001512 if (res)
1513 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
1514 else
1515 ret = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001516fail:
1517 ieee802_11_free_ap_params(&params);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001518 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001519}
1520
1521
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001522int ieee802_11_set_beacons(struct hostapd_iface *iface)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001523{
1524 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001525 int ret = 0;
1526
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08001527 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001528 if (iface->bss[i]->started &&
1529 ieee802_11_set_beacon(iface->bss[i]) < 0)
1530 ret = -1;
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08001531 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001532
1533 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001534}
1535
Dmitry Shmidt04949592012-07-19 12:16:46 -07001536
1537/* only update beacons if started */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001538int ieee802_11_update_beacons(struct hostapd_iface *iface)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001539{
1540 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001541 int ret = 0;
1542
1543 for (i = 0; i < iface->num_bss; i++) {
1544 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
1545 ieee802_11_set_beacon(iface->bss[i]) < 0)
1546 ret = -1;
1547 }
1548
1549 return ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001550}
1551
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001552#endif /* CONFIG_NATIVE_WINDOWS */