blob: 3ea28a76e798484c7dcbf09b861dc0bc54d4744e [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"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070019#include "wps/wps_defs.h"
20#include "p2p/p2p.h"
21#include "hostapd.h"
22#include "ieee802_11.h"
23#include "wpa_auth.h"
24#include "wmm.h"
25#include "ap_config.h"
26#include "sta_info.h"
27#include "p2p_hostapd.h"
28#include "ap_drv_ops.h"
29#include "beacon.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070030#include "hs20.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080031#include "dfs.h"
Dmitry Shmidtaca489e2016-09-28 15:44:14 -070032#include "taxonomy.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070033
34
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080035#ifdef NEED_AP_MLME
36
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080037static u8 * hostapd_eid_rm_enabled_capab(struct hostapd_data *hapd, u8 *eid,
38 size_t len)
39{
Dmitry Shmidt849734c2016-05-27 09:59:01 -070040 size_t i;
41
42 for (i = 0; i < RRM_CAPABILITIES_IE_LEN; i++) {
43 if (hapd->conf->radio_measurements[i])
44 break;
45 }
46
47 if (i == RRM_CAPABILITIES_IE_LEN || len < 2 + RRM_CAPABILITIES_IE_LEN)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080048 return eid;
49
50 *eid++ = WLAN_EID_RRM_ENABLED_CAPABILITIES;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070051 *eid++ = RRM_CAPABILITIES_IE_LEN;
52 os_memcpy(eid, hapd->conf->radio_measurements, RRM_CAPABILITIES_IE_LEN);
53
54 return eid + RRM_CAPABILITIES_IE_LEN;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080055}
56
57
Dmitry Shmidt051af732013-10-22 13:52:46 -070058static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
59{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080060 if (len < 2 + 5)
61 return eid;
62
Dmitry Shmidt051af732013-10-22 13:52:46 -070063#ifdef CONFIG_TESTING_OPTIONS
64 if (hapd->conf->bss_load_test_set) {
Dmitry Shmidt051af732013-10-22 13:52:46 -070065 *eid++ = WLAN_EID_BSS_LOAD;
66 *eid++ = 5;
67 os_memcpy(eid, hapd->conf->bss_load_test, 5);
68 eid += 5;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080069 return eid;
Dmitry Shmidt051af732013-10-22 13:52:46 -070070 }
71#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080072 if (hapd->conf->bss_load_update_period) {
73 *eid++ = WLAN_EID_BSS_LOAD;
74 *eid++ = 5;
75 WPA_PUT_LE16(eid, hapd->num_sta);
76 eid += 2;
77 *eid++ = hapd->iface->channel_utilization;
78 WPA_PUT_LE16(eid, 0); /* no available admission capabity */
79 eid += 2;
80 }
Dmitry Shmidt051af732013-10-22 13:52:46 -070081 return eid;
82}
83
84
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070085static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
86{
87 u8 erp = 0;
88
89 if (hapd->iface->current_mode == NULL ||
90 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
91 return 0;
92
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080093 if (hapd->iface->olbc)
94 erp |= ERP_INFO_USE_PROTECTION;
95 if (hapd->iface->num_sta_non_erp > 0) {
96 erp |= ERP_INFO_NON_ERP_PRESENT |
97 ERP_INFO_USE_PROTECTION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070098 }
99 if (hapd->iface->num_sta_no_short_preamble > 0 ||
100 hapd->iconf->preamble == LONG_PREAMBLE)
101 erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
102
103 return erp;
104}
105
106
107static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
108{
109 *eid++ = WLAN_EID_DS_PARAMS;
110 *eid++ = 1;
111 *eid++ = hapd->iconf->channel;
112 return eid;
113}
114
115
116static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
117{
118 if (hapd->iface->current_mode == NULL ||
119 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
120 return eid;
121
122 /* Set NonERP_present and use_protection bits if there
123 * are any associated NonERP stations. */
124 /* TODO: use_protection bit can be set to zero even if
125 * there are NonERP stations present. This optimization
126 * might be useful if NonERP stations are "quiet".
127 * See 802.11g/D6 E-1 for recommended practice.
128 * In addition, Non ERP present might be set, if AP detects Non ERP
129 * operation on other APs. */
130
131 /* Add ERP Information element */
132 *eid++ = WLAN_EID_ERP_INFO;
133 *eid++ = 1;
134 *eid++ = ieee802_11_erp_info(hapd);
135
136 return eid;
137}
138
139
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800140static u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid)
141{
142 u8 *pos = eid;
143 u8 local_pwr_constraint = 0;
144 int dfs;
145
146 if (hapd->iface->current_mode == NULL ||
147 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
148 return eid;
149
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700150 /* Let host drivers add this IE if DFS support is offloaded */
151 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)
152 return eid;
153
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800154 /*
155 * There is no DFS support and power constraint was not directly
156 * requested by config option.
157 */
158 if (!hapd->iconf->ieee80211h &&
159 hapd->iconf->local_pwr_constraint == -1)
160 return eid;
161
162 /* Check if DFS is required by regulatory. */
163 dfs = hostapd_is_dfs_required(hapd->iface);
164 if (dfs < 0) {
165 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
166 dfs);
167 dfs = 0;
168 }
169
170 if (dfs == 0 && hapd->iconf->local_pwr_constraint == -1)
171 return eid;
172
173 /*
174 * ieee80211h (DFS) is enabled so Power Constraint element shall
175 * be added when running on DFS channel whenever local_pwr_constraint
176 * is configured or not. In order to meet regulations when TPC is not
177 * implemented using a transmit power that is below the legal maximum
178 * (including any mitigation factor) should help. In this case,
179 * indicate 3 dB below maximum allowed transmit power.
180 */
181 if (hapd->iconf->local_pwr_constraint == -1)
182 local_pwr_constraint = 3;
183
184 /*
185 * A STA that is not an AP shall use a transmit power less than or
186 * equal to the local maximum transmit power level for the channel.
187 * The local maximum transmit power can be calculated from the formula:
188 * local max TX pwr = max TX pwr - local pwr constraint
189 * Where max TX pwr is maximum transmit power level specified for
190 * channel in Country element and local pwr constraint is specified
191 * for channel in this Power Constraint element.
192 */
193
194 /* Element ID */
195 *pos++ = WLAN_EID_PWR_CONSTRAINT;
196 /* Length */
197 *pos++ = 1;
198 /* Local Power Constraint */
199 if (local_pwr_constraint)
200 *pos++ = local_pwr_constraint;
201 else
202 *pos++ = hapd->iconf->local_pwr_constraint;
203
204 return pos;
205}
206
207
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700208static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
209 struct hostapd_channel_data *start,
210 struct hostapd_channel_data *prev)
211{
212 if (end - pos < 3)
213 return pos;
214
215 /* first channel number */
216 *pos++ = start->chan;
217 /* number of channels */
218 *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
219 /* maximum transmit power level */
220 *pos++ = start->max_tx_power;
221
222 return pos;
223}
224
225
226static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
227 int max_len)
228{
229 u8 *pos = eid;
230 u8 *end = eid + max_len;
231 int i;
232 struct hostapd_hw_modes *mode;
233 struct hostapd_channel_data *start, *prev;
234 int chan_spacing = 1;
235
236 if (!hapd->iconf->ieee80211d || max_len < 6 ||
237 hapd->iface->current_mode == NULL)
238 return eid;
239
240 *pos++ = WLAN_EID_COUNTRY;
241 pos++; /* length will be set later */
242 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
243 pos += 3;
244
245 mode = hapd->iface->current_mode;
246 if (mode->mode == HOSTAPD_MODE_IEEE80211A)
247 chan_spacing = 4;
248
249 start = prev = NULL;
250 for (i = 0; i < mode->num_channels; i++) {
251 struct hostapd_channel_data *chan = &mode->channels[i];
252 if (chan->flag & HOSTAPD_CHAN_DISABLED)
253 continue;
254 if (start && prev &&
255 prev->chan + chan_spacing == chan->chan &&
256 start->max_tx_power == chan->max_tx_power) {
257 prev = chan;
258 continue; /* can use same entry */
259 }
260
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -0700261 if (start && prev) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700262 pos = hostapd_eid_country_add(pos, end, chan_spacing,
263 start, prev);
264 start = NULL;
265 }
266
267 /* Start new group */
268 start = prev = chan;
269 }
270
271 if (start) {
272 pos = hostapd_eid_country_add(pos, end, chan_spacing,
273 start, prev);
274 }
275
276 if ((pos - eid) & 1) {
277 if (end - pos < 1)
278 return eid;
279 *pos++ = 0; /* pad for 16-bit alignment */
280 }
281
282 eid[1] = (pos - eid) - 2;
283
284 return pos;
285}
286
287
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800288static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700289{
290 const u8 *ie;
291 size_t ielen;
292
293 ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
294 if (ie == NULL || ielen > len)
295 return eid;
296
297 os_memcpy(eid, ie, ielen);
298 return eid + ielen;
299}
300
301
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800302static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
303{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800304#ifdef CONFIG_TESTING_OPTIONS
305 if (hapd->iface->cs_oper_class && hapd->iconf->ecsa_ie_only)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800306 return eid;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800307#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800308
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800309 if (!hapd->cs_freq_params.channel)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800310 return eid;
311
312 *eid++ = WLAN_EID_CHANNEL_SWITCH;
313 *eid++ = 3;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700314 *eid++ = hapd->cs_block_tx;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800315 *eid++ = hapd->cs_freq_params.channel;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700316 *eid++ = hapd->cs_count;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800317
318 return eid;
319}
320
321
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800322static u8 * hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800323{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800324 if (!hapd->cs_freq_params.channel || !hapd->iface->cs_oper_class)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800325 return eid;
326
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800327 *eid++ = WLAN_EID_EXT_CHANSWITCH_ANN;
328 *eid++ = 4;
329 *eid++ = hapd->cs_block_tx;
330 *eid++ = hapd->iface->cs_oper_class;
331 *eid++ = hapd->cs_freq_params.channel;
332 *eid++ = hapd->cs_count;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800333
334 return eid;
335}
336
337
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800338static u8 * hostapd_eid_supported_op_classes(struct hostapd_data *hapd, u8 *eid)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800339{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800340 u8 op_class, channel;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800341
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800342 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) ||
343 !hapd->iface->freq)
344 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800345
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800346 if (ieee80211_freq_to_channel_ext(hapd->iface->freq,
347 hapd->iconf->secondary_channel,
348 hapd->iconf->vht_oper_chwidth,
349 &op_class, &channel) ==
350 NUM_HOSTAPD_MODES)
351 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800352
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800353 *eid++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES;
354 *eid++ = 2;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800355
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800356 /* Current Operating Class */
357 *eid++ = op_class;
358
359 /* TODO: Advertise all the supported operating classes */
360 *eid++ = 0;
361
362 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800363}
364
365
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700366#ifdef CONFIG_OWE
367static int hostapd_eid_owe_trans_enabled(struct hostapd_data *hapd)
368{
369 return hapd->conf->owe_transition_ssid_len > 0 &&
370 !is_zero_ether_addr(hapd->conf->owe_transition_bssid);
371}
372#endif /* CONFIG_OWE */
373
374
375static size_t hostapd_eid_owe_trans_len(struct hostapd_data *hapd)
376{
377#ifdef CONFIG_OWE
378 if (!hostapd_eid_owe_trans_enabled(hapd))
379 return 0;
380 return 6 + ETH_ALEN + 1 + hapd->conf->owe_transition_ssid_len;
381#else /* CONFIG_OWE */
382 return 0;
383#endif /* CONFIG_OWE */
384}
385
386
387static u8 * hostapd_eid_owe_trans(struct hostapd_data *hapd, u8 *eid,
388 size_t len)
389{
390#ifdef CONFIG_OWE
391 u8 *pos = eid;
392 size_t elen;
393
394 if (hapd->conf->owe_transition_ifname[0] &&
395 !hostapd_eid_owe_trans_enabled(hapd))
396 hostapd_owe_trans_get_info(hapd);
397
398 if (!hostapd_eid_owe_trans_enabled(hapd))
399 return pos;
400
401 elen = hostapd_eid_owe_trans_len(hapd);
402 if (len < elen) {
403 wpa_printf(MSG_DEBUG,
404 "OWE: Not enough room in the buffer for OWE IE");
405 return pos;
406 }
407
408 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
409 *pos++ = elen - 2;
410 WPA_PUT_BE24(pos, OUI_WFA);
411 pos += 3;
412 *pos++ = OWE_OUI_TYPE;
413 os_memcpy(pos, hapd->conf->owe_transition_bssid, ETH_ALEN);
414 pos += ETH_ALEN;
415 *pos++ = hapd->conf->owe_transition_ssid_len;
416 os_memcpy(pos, hapd->conf->owe_transition_ssid,
417 hapd->conf->owe_transition_ssid_len);
418 pos += hapd->conf->owe_transition_ssid_len;
419
420 return pos;
421#else /* CONFIG_OWE */
422 return eid;
423#endif /* CONFIG_OWE */
424}
425
426
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800427static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800428 const struct ieee80211_mgmt *req,
429 int is_p2p, size_t *resp_len)
430{
431 struct ieee80211_mgmt *resp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800432 u8 *pos, *epos, *csa_pos;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800433 size_t buflen;
434
435#define MAX_PROBERESP_LEN 768
436 buflen = MAX_PROBERESP_LEN;
437#ifdef CONFIG_WPS
438 if (hapd->wps_probe_resp_ie)
439 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
440#endif /* CONFIG_WPS */
441#ifdef CONFIG_P2P
442 if (hapd->p2p_probe_resp_ie)
443 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
444#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800445#ifdef CONFIG_FST
446 if (hapd->iface->fst_ies)
447 buflen += wpabuf_len(hapd->iface->fst_ies);
448#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700449 if (hapd->conf->vendor_elements)
450 buflen += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800451 if (hapd->conf->vendor_vht) {
452 buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
453 2 + sizeof(struct ieee80211_vht_operation);
454 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800455
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800456#ifdef CONFIG_IEEE80211AX
457 if (hapd->iconf->ieee80211ax) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700458 buflen += 3 + sizeof(struct ieee80211_he_capabilities) +
459 3 + sizeof(struct ieee80211_he_operation);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800460 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700461#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800462
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800463 buflen += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700464 buflen += hostapd_eid_owe_trans_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800465
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800466 resp = os_zalloc(buflen);
467 if (resp == NULL)
468 return NULL;
469
470 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
471
472 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
473 WLAN_FC_STYPE_PROBE_RESP);
474 if (req)
475 os_memcpy(resp->da, req->sa, ETH_ALEN);
476 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
477
478 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
479 resp->u.probe_resp.beacon_int =
480 host_to_le16(hapd->iconf->beacon_int);
481
482 /* hardware or low-level driver will setup seq_ctrl and timestamp */
483 resp->u.probe_resp.capab_info =
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700484 host_to_le16(hostapd_own_capab_info(hapd));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800485
486 pos = resp->u.probe_resp.variable;
487 *pos++ = WLAN_EID_SSID;
488 *pos++ = hapd->conf->ssid.ssid_len;
489 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
490 pos += hapd->conf->ssid.ssid_len;
491
492 /* Supported rates */
493 pos = hostapd_eid_supp_rates(hapd, pos);
494
495 /* DS Params */
496 pos = hostapd_eid_ds_params(hapd, pos);
497
498 pos = hostapd_eid_country(hapd, pos, epos - pos);
499
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800500 /* Power Constraint element */
501 pos = hostapd_eid_pwr_constraint(hapd, pos);
502
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800503 /* CSA IE */
504 csa_pos = hostapd_eid_csa(hapd, pos);
505 if (csa_pos != pos)
506 hapd->cs_c_off_proberesp = csa_pos - (u8 *) resp - 1;
507 pos = csa_pos;
508
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800509 /* ERP Information element */
510 pos = hostapd_eid_erp_info(hapd, pos);
511
512 /* Extended supported rates */
513 pos = hostapd_eid_ext_supp_rates(hapd, pos);
514
515 /* RSN, MDIE, WPA */
516 pos = hostapd_eid_wpa(hapd, pos, epos - pos);
517
Dmitry Shmidt051af732013-10-22 13:52:46 -0700518 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
519
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800520 pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
521
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800522 /* eCSA IE */
523 csa_pos = hostapd_eid_ecsa(hapd, pos);
524 if (csa_pos != pos)
525 hapd->cs_c_off_ecsa_proberesp = csa_pos - (u8 *) resp - 1;
526 pos = csa_pos;
527
528 pos = hostapd_eid_supported_op_classes(hapd, pos);
529
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800530#ifdef CONFIG_IEEE80211N
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800531 /* Secondary Channel Offset element */
532 /* TODO: The standard doesn't specify a position for this element. */
533 pos = hostapd_eid_secondary_channel(hapd, pos);
534
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800535 pos = hostapd_eid_ht_capabilities(hapd, pos);
536 pos = hostapd_eid_ht_operation(hapd, pos);
537#endif /* CONFIG_IEEE80211N */
538
539 pos = hostapd_eid_ext_capab(hapd, pos);
540
541 pos = hostapd_eid_time_adv(hapd, pos);
542 pos = hostapd_eid_time_zone(hapd, pos);
543
544 pos = hostapd_eid_interworking(hapd, pos);
545 pos = hostapd_eid_adv_proto(hapd, pos);
546 pos = hostapd_eid_roaming_consortium(hapd, pos);
547
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800548#ifdef CONFIG_FST
549 if (hapd->iface->fst_ies) {
550 os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies),
551 wpabuf_len(hapd->iface->fst_ies));
552 pos += wpabuf_len(hapd->iface->fst_ies);
553 }
554#endif /* CONFIG_FST */
555
Dmitry Shmidt04949592012-07-19 12:16:46 -0700556#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800557 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700558 pos = hostapd_eid_vht_capabilities(hapd, pos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800559 pos = hostapd_eid_vht_operation(hapd, pos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800560 pos = hostapd_eid_txpower_envelope(hapd, pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800561 pos = hostapd_eid_wb_chsw_wrapper(hapd, pos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800562 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800563#endif /* CONFIG_IEEE80211AC */
564
565 pos = hostapd_eid_fils_indic(hapd, pos, 0);
566
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700567#ifdef CONFIG_IEEE80211AX
568 if (hapd->iconf->ieee80211ax) {
569 pos = hostapd_eid_he_capab(hapd, pos);
570 pos = hostapd_eid_he_operation(hapd, pos);
571 }
572#endif /* CONFIG_IEEE80211AX */
573
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800574#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800575 if (hapd->conf->vendor_vht)
576 pos = hostapd_eid_vendor_vht(hapd, pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700577#endif /* CONFIG_IEEE80211AC */
578
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800579 /* Wi-Fi Alliance WMM */
580 pos = hostapd_eid_wmm(hapd, pos);
581
582#ifdef CONFIG_WPS
583 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
584 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
585 wpabuf_len(hapd->wps_probe_resp_ie));
586 pos += wpabuf_len(hapd->wps_probe_resp_ie);
587 }
588#endif /* CONFIG_WPS */
589
590#ifdef CONFIG_P2P
591 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
592 hapd->p2p_probe_resp_ie) {
593 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
594 wpabuf_len(hapd->p2p_probe_resp_ie));
595 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
596 }
597#endif /* CONFIG_P2P */
598#ifdef CONFIG_P2P_MANAGER
599 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
600 P2P_MANAGE)
601 pos = hostapd_eid_p2p_manage(hapd, pos);
602#endif /* CONFIG_P2P_MANAGER */
603
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700604#ifdef CONFIG_HS20
605 pos = hostapd_eid_hs20_indication(hapd, pos);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800606 pos = hostapd_eid_osen(hapd, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700607#endif /* CONFIG_HS20 */
608
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800609 pos = hostapd_eid_mbo(hapd, pos, (u8 *) resp + buflen - pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700610 pos = hostapd_eid_owe_trans(hapd, pos, (u8 *) resp + buflen - pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800611
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700612 if (hapd->conf->vendor_elements) {
613 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
614 wpabuf_len(hapd->conf->vendor_elements));
615 pos += wpabuf_len(hapd->conf->vendor_elements);
616 }
617
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800618 *resp_len = pos - (u8 *) resp;
619 return (u8 *) resp;
620}
621
622
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800623enum ssid_match_result {
624 NO_SSID_MATCH,
625 EXACT_SSID_MATCH,
626 WILDCARD_SSID_MATCH
627};
628
629static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
630 const u8 *ssid, size_t ssid_len,
631 const u8 *ssid_list,
632 size_t ssid_list_len)
633{
634 const u8 *pos, *end;
635 int wildcard = 0;
636
637 if (ssid_len == 0)
638 wildcard = 1;
639 if (ssid_len == hapd->conf->ssid.ssid_len &&
640 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
641 return EXACT_SSID_MATCH;
642
643 if (ssid_list == NULL)
644 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
645
646 pos = ssid_list;
647 end = ssid_list + ssid_list_len;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800648 while (end - pos >= 1) {
649 if (2 + pos[1] > end - pos)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800650 break;
651 if (pos[1] == 0)
652 wildcard = 1;
653 if (pos[1] == hapd->conf->ssid.ssid_len &&
654 os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0)
655 return EXACT_SSID_MATCH;
656 pos += 2 + pos[1];
657 }
658
659 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
660}
661
662
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800663void sta_track_expire(struct hostapd_iface *iface, int force)
664{
665 struct os_reltime now;
666 struct hostapd_sta_info *info;
667
668 if (!iface->num_sta_seen)
669 return;
670
671 os_get_reltime(&now);
672 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
673 list))) {
674 if (!force &&
675 !os_reltime_expired(&now, &info->last_seen,
676 iface->conf->track_sta_max_age))
677 break;
678 force = 0;
679
680 wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
681 MACSTR, iface->bss[0]->conf->iface,
682 MAC2STR(info->addr));
683 dl_list_del(&info->list);
684 iface->num_sta_seen--;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700685 sta_track_del(info);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800686 }
687}
688
689
690static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
691 const u8 *addr)
692{
693 struct hostapd_sta_info *info;
694
695 dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
696 if (os_memcmp(addr, info->addr, ETH_ALEN) == 0)
697 return info;
698
699 return NULL;
700}
701
702
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800703void sta_track_add(struct hostapd_iface *iface, const u8 *addr, int ssi_signal)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800704{
705 struct hostapd_sta_info *info;
706
707 info = sta_track_get(iface, addr);
708 if (info) {
709 /* Move the most recent entry to the end of the list */
710 dl_list_del(&info->list);
711 dl_list_add_tail(&iface->sta_seen, &info->list);
712 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800713 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800714 return;
715 }
716
717 /* Add a new entry */
718 info = os_zalloc(sizeof(*info));
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700719 if (info == NULL)
720 return;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800721 os_memcpy(info->addr, addr, ETH_ALEN);
722 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800723 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800724
725 if (iface->num_sta_seen >= iface->conf->track_sta_max_num) {
726 /* Expire oldest entry to make room for a new one */
727 sta_track_expire(iface, 1);
728 }
729
730 wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
731 MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr));
732 dl_list_add_tail(&iface->sta_seen, &info->list);
733 iface->num_sta_seen++;
734}
735
736
737struct hostapd_data *
738sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
739 const char *ifname)
740{
741 struct hapd_interfaces *interfaces = iface->interfaces;
742 size_t i, j;
743
744 for (i = 0; i < interfaces->count; i++) {
745 struct hostapd_data *hapd = NULL;
746
747 iface = interfaces->iface[i];
748 for (j = 0; j < iface->num_bss; j++) {
749 hapd = iface->bss[j];
750 if (os_strcmp(ifname, hapd->conf->iface) == 0)
751 break;
752 hapd = NULL;
753 }
754
755 if (hapd && sta_track_get(iface, addr))
756 return hapd;
757 }
758
759 return NULL;
760}
761
762
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700763#ifdef CONFIG_TAXONOMY
764void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr,
765 struct wpabuf **probe_ie_taxonomy)
766{
767 struct hostapd_sta_info *info;
768
769 info = sta_track_get(iface, addr);
770 if (!info)
771 return;
772
773 wpabuf_free(*probe_ie_taxonomy);
774 *probe_ie_taxonomy = info->probe_ie_taxonomy;
775 info->probe_ie_taxonomy = NULL;
776}
777#endif /* CONFIG_TAXONOMY */
778
779
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700780void handle_probe_req(struct hostapd_data *hapd,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700781 const struct ieee80211_mgmt *mgmt, size_t len,
782 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700783{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800784 u8 *resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700785 struct ieee802_11_elems elems;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700786 const u8 *ie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800787 size_t ie_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800788 size_t i, resp_len;
789 int noack;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800790 enum ssid_match_result res;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800791 int ret;
792 u16 csa_offs[2];
793 size_t csa_offs_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700794
Dmitry Shmidte4663042016-04-04 10:07:49 -0700795 if (len < IEEE80211_HDRLEN)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700796 return;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700797 ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800798 if (hapd->iconf->track_sta_max_num)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800799 sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
Dmitry Shmidte4663042016-04-04 10:07:49 -0700800 ie_len = len - IEEE80211_HDRLEN;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700801
802 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
803 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800804 mgmt->sa, mgmt->da, mgmt->bssid,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700805 ie, ie_len, ssi_signal) > 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700806 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800807
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700808 if (!hapd->iconf->send_probe_response)
809 return;
810
811 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
812 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
813 MAC2STR(mgmt->sa));
814 return;
815 }
816
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700817 if ((!elems.ssid || !elems.supp_rates)) {
818 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
819 "without SSID or supported rates element",
820 MAC2STR(mgmt->sa));
821 return;
822 }
823
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800824 /*
825 * No need to reply if the Probe Request frame was sent on an adjacent
826 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
827 * AP with dot11RadioMeasurementActivated set to true, but strictly
828 * speaking does not allow such ignoring of Probe Request frames if
829 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
830 * number of unnecessary Probe Response frames for cases where the STA
831 * is less likely to see them (Probe Request frame sent on a
832 * neighboring, but partially overlapping, channel).
833 */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700834 if (elems.ds_params &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800835 hapd->iface->current_mode &&
836 (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
837 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
838 hapd->iconf->channel != elems.ds_params[0]) {
839 wpa_printf(MSG_DEBUG,
840 "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
841 hapd->iconf->channel, elems.ds_params[0]);
842 return;
843 }
844
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700845#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800846 if (hapd->p2p && hapd->p2p_group && elems.wps_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700847 struct wpabuf *wps;
848 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
849 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
850 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
851 "due to mismatch with Requested Device "
852 "Type");
853 wpabuf_free(wps);
854 return;
855 }
856 wpabuf_free(wps);
857 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800858
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800859 if (hapd->p2p && hapd->p2p_group && elems.p2p) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800860 struct wpabuf *p2p;
861 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
862 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
863 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
864 "due to mismatch with Device ID");
865 wpabuf_free(p2p);
866 return;
867 }
868 wpabuf_free(p2p);
869 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700870#endif /* CONFIG_P2P */
871
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800872 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
873 elems.ssid_list_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700874 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
875 "broadcast SSID ignored", MAC2STR(mgmt->sa));
876 return;
877 }
878
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700879#ifdef CONFIG_P2P
880 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
881 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
882 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
883 P2P_WILDCARD_SSID_LEN) == 0) {
884 /* Process P2P Wildcard SSID like Wildcard SSID */
885 elems.ssid_len = 0;
886 }
887#endif /* CONFIG_P2P */
888
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700889#ifdef CONFIG_TAXONOMY
890 {
891 struct sta_info *sta;
892 struct hostapd_sta_info *info;
893
894 if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) {
895 taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len);
896 } else if ((info = sta_track_get(hapd->iface,
897 mgmt->sa)) != NULL) {
898 taxonomy_hostapd_sta_info_probe_req(hapd, info,
899 ie, ie_len);
900 }
901 }
902#endif /* CONFIG_TAXONOMY */
903
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800904 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
905 elems.ssid_list, elems.ssid_list_len);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700906 if (res == NO_SSID_MATCH) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700907 if (!(mgmt->da[0] & 0x01)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700908 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800909 " for foreign SSID '%s' (DA " MACSTR ")%s",
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800910 MAC2STR(mgmt->sa),
911 wpa_ssid_txt(elems.ssid, elems.ssid_len),
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800912 MAC2STR(mgmt->da),
913 elems.ssid_list ? " (SSID list)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700914 }
915 return;
916 }
917
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800918#ifdef CONFIG_INTERWORKING
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -0700919 if (hapd->conf->interworking &&
920 elems.interworking && elems.interworking_len >= 1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800921 u8 ant = elems.interworking[0] & 0x0f;
922 if (ant != INTERWORKING_ANT_WILDCARD &&
923 ant != hapd->conf->access_network_type) {
924 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
925 " for mismatching ANT %u ignored",
926 MAC2STR(mgmt->sa), ant);
927 return;
928 }
929 }
930
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -0700931 if (hapd->conf->interworking && elems.interworking &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800932 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
933 const u8 *hessid;
934 if (elems.interworking_len == 7)
935 hessid = elems.interworking + 1;
936 else
937 hessid = elems.interworking + 1 + 2;
938 if (!is_broadcast_ether_addr(hessid) &&
939 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
940 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
941 " for mismatching HESSID " MACSTR
942 " ignored",
943 MAC2STR(mgmt->sa), MAC2STR(hessid));
944 return;
945 }
946 }
947#endif /* CONFIG_INTERWORKING */
948
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700949#ifdef CONFIG_P2P
950 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
951 supp_rates_11b_only(&elems)) {
952 /* Indicates support for 11b rates only */
953 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
954 MACSTR " with only 802.11b rates",
955 MAC2STR(mgmt->sa));
956 return;
957 }
958#endif /* CONFIG_P2P */
959
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700960 /* TODO: verify that supp_rates contains at least one matching rate
961 * with AP configuration */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800962
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800963 if (hapd->conf->no_probe_resp_if_seen_on &&
964 is_multicast_ether_addr(mgmt->da) &&
965 is_multicast_ether_addr(mgmt->bssid) &&
966 sta_track_seen_on(hapd->iface, mgmt->sa,
967 hapd->conf->no_probe_resp_if_seen_on)) {
968 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
969 " since STA has been seen on %s",
970 hapd->conf->iface, MAC2STR(mgmt->sa),
971 hapd->conf->no_probe_resp_if_seen_on);
972 return;
973 }
974
975 if (hapd->conf->no_probe_resp_if_max_sta &&
976 is_multicast_ether_addr(mgmt->da) &&
977 is_multicast_ether_addr(mgmt->bssid) &&
978 hapd->num_sta >= hapd->conf->max_num_sta &&
979 !ap_get_sta(hapd, mgmt->sa)) {
980 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
981 " since no room for additional STA",
982 hapd->conf->iface, MAC2STR(mgmt->sa));
983 return;
984 }
985
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700986#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700987 if (hapd->iconf->ignore_probe_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700988 drand48() < hapd->iconf->ignore_probe_probability) {
989 wpa_printf(MSG_INFO,
990 "TESTING: ignoring probe request from " MACSTR,
991 MAC2STR(mgmt->sa));
992 return;
993 }
994#endif /* CONFIG_TESTING_OPTIONS */
995
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700996 resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800997 &resp_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700998 if (resp == NULL)
999 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001000
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001001 /*
1002 * If this is a broadcast probe request, apply no ack policy to avoid
1003 * excessive retries.
1004 */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001005 noack = !!(res == WILDCARD_SSID_MATCH &&
1006 is_broadcast_ether_addr(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001007
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001008 csa_offs_len = 0;
1009 if (hapd->csa_in_progress) {
1010 if (hapd->cs_c_off_proberesp)
1011 csa_offs[csa_offs_len++] =
1012 hapd->cs_c_off_proberesp;
1013
1014 if (hapd->cs_c_off_ecsa_proberesp)
1015 csa_offs[csa_offs_len++] =
1016 hapd->cs_c_off_ecsa_proberesp;
1017 }
1018
1019 ret = hostapd_drv_send_mlme_csa(hapd, resp, resp_len, noack,
1020 csa_offs_len ? csa_offs : NULL,
1021 csa_offs_len);
1022
1023 if (ret < 0)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001024 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001025
1026 os_free(resp);
1027
1028 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
1029 "SSID", MAC2STR(mgmt->sa),
1030 elems.ssid_len == 0 ? "broadcast" : "our");
1031}
1032
1033
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001034static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
1035 size_t *resp_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001036{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001037 /* check probe response offloading caps and print warnings */
1038 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
1039 return NULL;
1040
1041#ifdef CONFIG_WPS
1042 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
1043 (!(hapd->iface->probe_resp_offloads &
1044 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
1045 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
1046 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
1047 "Probe Response while not supporting this");
1048#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001049
1050#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001051 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
1052 !(hapd->iface->probe_resp_offloads &
1053 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
1054 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
1055 "Probe Response while not supporting this");
1056#endif /* CONFIG_P2P */
1057
1058 if (hapd->conf->interworking &&
1059 !(hapd->iface->probe_resp_offloads &
1060 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
1061 wpa_printf(MSG_WARNING, "Device is trying to offload "
1062 "Interworking Probe Response while not supporting "
1063 "this");
1064
1065 /* Generate a Probe Response template for the non-P2P case */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001066 return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001067}
1068
1069#endif /* NEED_AP_MLME */
1070
1071
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001072void sta_track_del(struct hostapd_sta_info *info)
1073{
1074#ifdef CONFIG_TAXONOMY
1075 wpabuf_free(info->probe_ie_taxonomy);
1076 info->probe_ie_taxonomy = NULL;
1077#endif /* CONFIG_TAXONOMY */
1078 os_free(info);
1079}
1080
1081
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001082int ieee802_11_build_ap_params(struct hostapd_data *hapd,
1083 struct wpa_driver_ap_params *params)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001084{
1085 struct ieee80211_mgmt *head = NULL;
1086 u8 *tail = NULL;
1087 size_t head_len = 0, tail_len = 0;
1088 u8 *resp = NULL;
1089 size_t resp_len = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001090#ifdef NEED_AP_MLME
1091 u16 capab_info;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001092 u8 *pos, *tailpos, *csa_pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001093
1094#define BEACON_HEAD_BUF_SIZE 256
1095#define BEACON_TAIL_BUF_SIZE 512
1096 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
1097 tail_len = BEACON_TAIL_BUF_SIZE;
1098#ifdef CONFIG_WPS
1099 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
1100 tail_len += wpabuf_len(hapd->wps_beacon_ie);
1101#endif /* CONFIG_WPS */
1102#ifdef CONFIG_P2P
1103 if (hapd->p2p_beacon_ie)
1104 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
1105#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001106#ifdef CONFIG_FST
1107 if (hapd->iface->fst_ies)
1108 tail_len += wpabuf_len(hapd->iface->fst_ies);
1109#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001110 if (hapd->conf->vendor_elements)
1111 tail_len += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001112
1113#ifdef CONFIG_IEEE80211AC
1114 if (hapd->conf->vendor_vht) {
1115 tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
1116 2 + sizeof(struct ieee80211_vht_operation);
1117 }
1118#endif /* CONFIG_IEEE80211AC */
1119
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001120#ifdef CONFIG_IEEE80211AX
1121 if (hapd->iconf->ieee80211ax) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001122 tail_len += 3 + sizeof(struct ieee80211_he_capabilities) +
1123 3 + sizeof(struct ieee80211_he_operation);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001124 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001125#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001126
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001127 tail_len += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001128 tail_len += hostapd_eid_owe_trans_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001129
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001130 tailpos = tail = os_malloc(tail_len);
1131 if (head == NULL || tail == NULL) {
1132 wpa_printf(MSG_ERROR, "Failed to set beacon data");
1133 os_free(head);
1134 os_free(tail);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001135 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001136 }
1137
1138 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1139 WLAN_FC_STYPE_BEACON);
1140 head->duration = host_to_le16(0);
1141 os_memset(head->da, 0xff, ETH_ALEN);
1142
1143 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1144 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1145 head->u.beacon.beacon_int =
1146 host_to_le16(hapd->iconf->beacon_int);
1147
1148 /* hardware or low-level driver will setup seq_ctrl and timestamp */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001149 capab_info = hostapd_own_capab_info(hapd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001150 head->u.beacon.capab_info = host_to_le16(capab_info);
1151 pos = &head->u.beacon.variable[0];
1152
1153 /* SSID */
1154 *pos++ = WLAN_EID_SSID;
1155 if (hapd->conf->ignore_broadcast_ssid == 2) {
1156 /* clear the data, but keep the correct length of the SSID */
1157 *pos++ = hapd->conf->ssid.ssid_len;
1158 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
1159 pos += hapd->conf->ssid.ssid_len;
1160 } else if (hapd->conf->ignore_broadcast_ssid) {
1161 *pos++ = 0; /* empty SSID */
1162 } else {
1163 *pos++ = hapd->conf->ssid.ssid_len;
1164 os_memcpy(pos, hapd->conf->ssid.ssid,
1165 hapd->conf->ssid.ssid_len);
1166 pos += hapd->conf->ssid.ssid_len;
1167 }
1168
1169 /* Supported rates */
1170 pos = hostapd_eid_supp_rates(hapd, pos);
1171
1172 /* DS Params */
1173 pos = hostapd_eid_ds_params(hapd, pos);
1174
1175 head_len = pos - (u8 *) head;
1176
1177 tailpos = hostapd_eid_country(hapd, tailpos,
1178 tail + BEACON_TAIL_BUF_SIZE - tailpos);
1179
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001180 /* Power Constraint element */
1181 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
1182
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001183 /* CSA IE */
1184 csa_pos = hostapd_eid_csa(hapd, tailpos);
1185 if (csa_pos != tailpos)
1186 hapd->cs_c_off_beacon = csa_pos - tail - 1;
1187 tailpos = csa_pos;
1188
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001189 /* ERP Information element */
1190 tailpos = hostapd_eid_erp_info(hapd, tailpos);
1191
1192 /* Extended supported rates */
1193 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
1194
1195 /* RSN, MDIE, WPA */
1196 tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001197 tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001198
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001199 tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
1200 tail + BEACON_TAIL_BUF_SIZE -
1201 tailpos);
1202
Dmitry Shmidt051af732013-10-22 13:52:46 -07001203 tailpos = hostapd_eid_bss_load(hapd, tailpos,
1204 tail + BEACON_TAIL_BUF_SIZE - tailpos);
1205
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001206 /* eCSA IE */
1207 csa_pos = hostapd_eid_ecsa(hapd, tailpos);
1208 if (csa_pos != tailpos)
1209 hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1;
1210 tailpos = csa_pos;
1211
1212 tailpos = hostapd_eid_supported_op_classes(hapd, tailpos);
1213
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001214#ifdef CONFIG_IEEE80211N
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001215 /* Secondary Channel Offset element */
1216 /* TODO: The standard doesn't specify a position for this element. */
1217 tailpos = hostapd_eid_secondary_channel(hapd, tailpos);
1218
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001219 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
1220 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
1221#endif /* CONFIG_IEEE80211N */
1222
1223 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
1224
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001225 /*
1226 * TODO: Time Advertisement element should only be included in some
1227 * DTIM Beacon frames.
1228 */
1229 tailpos = hostapd_eid_time_adv(hapd, tailpos);
1230
1231 tailpos = hostapd_eid_interworking(hapd, tailpos);
1232 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
1233 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001234
1235#ifdef CONFIG_FST
1236 if (hapd->iface->fst_ies) {
1237 os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies),
1238 wpabuf_len(hapd->iface->fst_ies));
1239 tailpos += wpabuf_len(hapd->iface->fst_ies);
1240 }
1241#endif /* CONFIG_FST */
1242
Dmitry Shmidt04949592012-07-19 12:16:46 -07001243#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001244 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -07001245 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001246 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08001247 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001248 tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001249 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001250#endif /* CONFIG_IEEE80211AC */
1251
1252 tailpos = hostapd_eid_fils_indic(hapd, tailpos, 0);
1253
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001254#ifdef CONFIG_IEEE80211AX
1255 if (hapd->iconf->ieee80211ax) {
1256 tailpos = hostapd_eid_he_capab(hapd, tailpos);
1257 tailpos = hostapd_eid_he_operation(hapd, tailpos);
1258 }
1259#endif /* CONFIG_IEEE80211AX */
1260
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001261#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001262 if (hapd->conf->vendor_vht)
1263 tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001264#endif /* CONFIG_IEEE80211AC */
1265
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001266 /* Wi-Fi Alliance WMM */
1267 tailpos = hostapd_eid_wmm(hapd, tailpos);
1268
1269#ifdef CONFIG_WPS
1270 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
1271 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
1272 wpabuf_len(hapd->wps_beacon_ie));
1273 tailpos += wpabuf_len(hapd->wps_beacon_ie);
1274 }
1275#endif /* CONFIG_WPS */
1276
1277#ifdef CONFIG_P2P
1278 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
1279 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
1280 wpabuf_len(hapd->p2p_beacon_ie));
1281 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
1282 }
1283#endif /* CONFIG_P2P */
1284#ifdef CONFIG_P2P_MANAGER
1285 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
1286 P2P_MANAGE)
1287 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
1288#endif /* CONFIG_P2P_MANAGER */
1289
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001290#ifdef CONFIG_HS20
1291 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001292 tailpos = hostapd_eid_osen(hapd, tailpos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001293#endif /* CONFIG_HS20 */
1294
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001295 tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001296 tailpos = hostapd_eid_owe_trans(hapd, tailpos,
1297 tail + tail_len - tailpos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001298
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001299 if (hapd->conf->vendor_elements) {
1300 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
1301 wpabuf_len(hapd->conf->vendor_elements));
1302 tailpos += wpabuf_len(hapd->conf->vendor_elements);
1303 }
1304
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001305 tail_len = tailpos > tail ? tailpos - tail : 0;
1306
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001307 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
1308#endif /* NEED_AP_MLME */
1309
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001310 os_memset(params, 0, sizeof(*params));
1311 params->head = (u8 *) head;
1312 params->head_len = head_len;
1313 params->tail = tail;
1314 params->tail_len = tail_len;
1315 params->proberesp = resp;
1316 params->proberesp_len = resp_len;
1317 params->dtim_period = hapd->conf->dtim_period;
1318 params->beacon_int = hapd->iconf->beacon_int;
1319 params->basic_rates = hapd->iface->basic_rates;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001320 params->beacon_rate = hapd->iconf->beacon_rate;
1321 params->rate_type = hapd->iconf->rate_type;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001322 params->ssid = hapd->conf->ssid.ssid;
1323 params->ssid_len = hapd->conf->ssid.ssid_len;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001324 if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
1325 (WPA_PROTO_WPA | WPA_PROTO_RSN))
1326 params->pairwise_ciphers = hapd->conf->wpa_pairwise |
1327 hapd->conf->rsn_pairwise;
1328 else if (hapd->conf->wpa & WPA_PROTO_RSN)
1329 params->pairwise_ciphers = hapd->conf->rsn_pairwise;
1330 else if (hapd->conf->wpa & WPA_PROTO_WPA)
1331 params->pairwise_ciphers = hapd->conf->wpa_pairwise;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001332 params->group_cipher = hapd->conf->wpa_group;
1333 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
1334 params->auth_algs = hapd->conf->auth_algs;
1335 params->wpa_version = hapd->conf->wpa;
1336 params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001337 (hapd->conf->ieee802_1x &&
1338 (hapd->conf->default_wep_key_len ||
1339 hapd->conf->individual_wep_key_len));
1340 switch (hapd->conf->ignore_broadcast_ssid) {
1341 case 0:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001342 params->hide_ssid = NO_SSID_HIDING;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001343 break;
1344 case 1:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001345 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001346 break;
1347 case 2:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001348 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001349 break;
1350 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001351 params->isolate = hapd->conf->isolate;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001352 params->smps_mode = hapd->iconf->ht_capab & HT_CAP_INFO_SMPS_MASK;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001353#ifdef NEED_AP_MLME
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001354 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001355 ERP_INFO_USE_PROTECTION);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001356 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001357 hapd->iconf->preamble == SHORT_PREAMBLE;
1358 if (hapd->iface->current_mode &&
1359 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001360 params->short_slot_time =
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001361 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
1362 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001363 params->short_slot_time = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001364 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001365 params->ht_opmode = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001366 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001367 params->ht_opmode = hapd->iface->ht_op_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001368#endif /* NEED_AP_MLME */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001369 params->interworking = hapd->conf->interworking;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001370 if (hapd->conf->interworking &&
1371 !is_zero_ether_addr(hapd->conf->hessid))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001372 params->hessid = hapd->conf->hessid;
1373 params->access_network_type = hapd->conf->access_network_type;
1374 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001375#ifdef CONFIG_P2P
1376 params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
1377#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001378#ifdef CONFIG_HS20
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001379 params->disable_dgaf = hapd->conf->disable_dgaf;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001380 if (hapd->conf->osen) {
1381 params->privacy = 1;
1382 params->osen = 1;
1383 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001384#endif /* CONFIG_HS20 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001385 params->multicast_to_unicast = hapd->conf->multicast_to_unicast;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001386 params->pbss = hapd->conf->pbss;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001387 return 0;
1388}
1389
1390
1391void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
1392{
1393 os_free(params->tail);
1394 params->tail = NULL;
1395 os_free(params->head);
1396 params->head = NULL;
1397 os_free(params->proberesp);
1398 params->proberesp = NULL;
1399}
1400
1401
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001402int ieee802_11_set_beacon(struct hostapd_data *hapd)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001403{
1404 struct wpa_driver_ap_params params;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001405 struct hostapd_freq_params freq;
1406 struct hostapd_iface *iface = hapd->iface;
1407 struct hostapd_config *iconf = iface->conf;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001408 struct wpabuf *beacon, *proberesp, *assocresp;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001409 int res, ret = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001410
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001411 if (hapd->csa_in_progress) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001412 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001413 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001414 }
1415
1416 hapd->beacon_set_done = 1;
1417
1418 if (ieee802_11_build_ap_params(hapd, &params) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001419 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001420
1421 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
1422 0)
1423 goto fail;
1424
1425 params.beacon_ies = beacon;
1426 params.proberesp_ies = proberesp;
1427 params.assocresp_ies = assocresp;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001428 params.reenable = hapd->reenable_beacon;
1429 hapd->reenable_beacon = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001430
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001431 if (iface->current_mode &&
1432 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
1433 iconf->channel, iconf->ieee80211n,
1434 iconf->ieee80211ac,
1435 iconf->secondary_channel,
1436 iconf->vht_oper_chwidth,
1437 iconf->vht_oper_centr_freq_seg0_idx,
1438 iconf->vht_oper_centr_freq_seg1_idx,
1439 iface->current_mode->vht_capab) == 0)
1440 params.freq = &freq;
1441
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001442 res = hostapd_drv_set_ap(hapd, &params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001443 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001444 if (res)
1445 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
1446 else
1447 ret = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001448fail:
1449 ieee802_11_free_ap_params(&params);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001450 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001451}
1452
1453
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001454int ieee802_11_set_beacons(struct hostapd_iface *iface)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001455{
1456 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001457 int ret = 0;
1458
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08001459 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001460 if (iface->bss[i]->started &&
1461 ieee802_11_set_beacon(iface->bss[i]) < 0)
1462 ret = -1;
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08001463 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001464
1465 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001466}
1467
Dmitry Shmidt04949592012-07-19 12:16:46 -07001468
1469/* only update beacons if started */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001470int ieee802_11_update_beacons(struct hostapd_iface *iface)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001471{
1472 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001473 int ret = 0;
1474
1475 for (i = 0; i < iface->num_bss; i++) {
1476 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
1477 ieee802_11_set_beacon(iface->bss[i]) < 0)
1478 ret = -1;
1479 }
1480
1481 return ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001482}
1483
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001484#endif /* CONFIG_NATIVE_WINDOWS */