blob: 7d079d2615846164c9e95d03d7c4d08127cfd2ad [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 Shmidt6c0da2b2015-01-05 13:08:17 -080039static u8 * hostapd_eid_rm_enabled_capab(struct hostapd_data *hapd, u8 *eid,
40 size_t len)
41{
Dmitry Shmidt849734c2016-05-27 09:59:01 -070042 size_t i;
43
44 for (i = 0; i < RRM_CAPABILITIES_IE_LEN; i++) {
45 if (hapd->conf->radio_measurements[i])
46 break;
47 }
48
49 if (i == RRM_CAPABILITIES_IE_LEN || len < 2 + RRM_CAPABILITIES_IE_LEN)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080050 return eid;
51
52 *eid++ = WLAN_EID_RRM_ENABLED_CAPABILITIES;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070053 *eid++ = RRM_CAPABILITIES_IE_LEN;
54 os_memcpy(eid, hapd->conf->radio_measurements, RRM_CAPABILITIES_IE_LEN);
55
56 return eid + RRM_CAPABILITIES_IE_LEN;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080057}
58
59
Dmitry Shmidt051af732013-10-22 13:52:46 -070060static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
61{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080062 if (len < 2 + 5)
63 return eid;
64
Dmitry Shmidt051af732013-10-22 13:52:46 -070065#ifdef CONFIG_TESTING_OPTIONS
66 if (hapd->conf->bss_load_test_set) {
Dmitry Shmidt051af732013-10-22 13:52:46 -070067 *eid++ = WLAN_EID_BSS_LOAD;
68 *eid++ = 5;
69 os_memcpy(eid, hapd->conf->bss_load_test, 5);
70 eid += 5;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080071 return eid;
Dmitry Shmidt051af732013-10-22 13:52:46 -070072 }
73#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080074 if (hapd->conf->bss_load_update_period) {
75 *eid++ = WLAN_EID_BSS_LOAD;
76 *eid++ = 5;
77 WPA_PUT_LE16(eid, hapd->num_sta);
78 eid += 2;
79 *eid++ = hapd->iface->channel_utilization;
80 WPA_PUT_LE16(eid, 0); /* no available admission capabity */
81 eid += 2;
82 }
Dmitry Shmidt051af732013-10-22 13:52:46 -070083 return eid;
84}
85
86
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070087static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
88{
89 u8 erp = 0;
90
91 if (hapd->iface->current_mode == NULL ||
92 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
93 return 0;
94
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080095 if (hapd->iface->olbc)
96 erp |= ERP_INFO_USE_PROTECTION;
97 if (hapd->iface->num_sta_non_erp > 0) {
98 erp |= ERP_INFO_NON_ERP_PRESENT |
99 ERP_INFO_USE_PROTECTION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700100 }
101 if (hapd->iface->num_sta_no_short_preamble > 0 ||
102 hapd->iconf->preamble == LONG_PREAMBLE)
103 erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
104
105 return erp;
106}
107
108
109static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
110{
111 *eid++ = WLAN_EID_DS_PARAMS;
112 *eid++ = 1;
113 *eid++ = hapd->iconf->channel;
114 return eid;
115}
116
117
118static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
119{
120 if (hapd->iface->current_mode == NULL ||
121 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
122 return eid;
123
124 /* Set NonERP_present and use_protection bits if there
125 * are any associated NonERP stations. */
126 /* TODO: use_protection bit can be set to zero even if
127 * there are NonERP stations present. This optimization
128 * might be useful if NonERP stations are "quiet".
129 * See 802.11g/D6 E-1 for recommended practice.
130 * In addition, Non ERP present might be set, if AP detects Non ERP
131 * operation on other APs. */
132
133 /* Add ERP Information element */
134 *eid++ = WLAN_EID_ERP_INFO;
135 *eid++ = 1;
136 *eid++ = ieee802_11_erp_info(hapd);
137
138 return eid;
139}
140
141
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800142static u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid)
143{
144 u8 *pos = eid;
145 u8 local_pwr_constraint = 0;
146 int dfs;
147
148 if (hapd->iface->current_mode == NULL ||
149 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
150 return eid;
151
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700152 /* Let host drivers add this IE if DFS support is offloaded */
153 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)
154 return eid;
155
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800156 /*
157 * There is no DFS support and power constraint was not directly
158 * requested by config option.
159 */
160 if (!hapd->iconf->ieee80211h &&
161 hapd->iconf->local_pwr_constraint == -1)
162 return eid;
163
164 /* Check if DFS is required by regulatory. */
165 dfs = hostapd_is_dfs_required(hapd->iface);
166 if (dfs < 0) {
167 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
168 dfs);
169 dfs = 0;
170 }
171
172 if (dfs == 0 && hapd->iconf->local_pwr_constraint == -1)
173 return eid;
174
175 /*
176 * ieee80211h (DFS) is enabled so Power Constraint element shall
177 * be added when running on DFS channel whenever local_pwr_constraint
178 * is configured or not. In order to meet regulations when TPC is not
179 * implemented using a transmit power that is below the legal maximum
180 * (including any mitigation factor) should help. In this case,
181 * indicate 3 dB below maximum allowed transmit power.
182 */
183 if (hapd->iconf->local_pwr_constraint == -1)
184 local_pwr_constraint = 3;
185
186 /*
187 * A STA that is not an AP shall use a transmit power less than or
188 * equal to the local maximum transmit power level for the channel.
189 * The local maximum transmit power can be calculated from the formula:
190 * local max TX pwr = max TX pwr - local pwr constraint
191 * Where max TX pwr is maximum transmit power level specified for
192 * channel in Country element and local pwr constraint is specified
193 * for channel in this Power Constraint element.
194 */
195
196 /* Element ID */
197 *pos++ = WLAN_EID_PWR_CONSTRAINT;
198 /* Length */
199 *pos++ = 1;
200 /* Local Power Constraint */
201 if (local_pwr_constraint)
202 *pos++ = local_pwr_constraint;
203 else
204 *pos++ = hapd->iconf->local_pwr_constraint;
205
206 return pos;
207}
208
209
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700210static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
211 struct hostapd_channel_data *start,
212 struct hostapd_channel_data *prev)
213{
214 if (end - pos < 3)
215 return pos;
216
217 /* first channel number */
218 *pos++ = start->chan;
219 /* number of channels */
220 *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
221 /* maximum transmit power level */
222 *pos++ = start->max_tx_power;
223
224 return pos;
225}
226
227
228static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
229 int max_len)
230{
231 u8 *pos = eid;
232 u8 *end = eid + max_len;
233 int i;
234 struct hostapd_hw_modes *mode;
235 struct hostapd_channel_data *start, *prev;
236 int chan_spacing = 1;
237
238 if (!hapd->iconf->ieee80211d || max_len < 6 ||
239 hapd->iface->current_mode == NULL)
240 return eid;
241
242 *pos++ = WLAN_EID_COUNTRY;
243 pos++; /* length will be set later */
244 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
245 pos += 3;
246
247 mode = hapd->iface->current_mode;
248 if (mode->mode == HOSTAPD_MODE_IEEE80211A)
249 chan_spacing = 4;
250
251 start = prev = NULL;
252 for (i = 0; i < mode->num_channels; i++) {
253 struct hostapd_channel_data *chan = &mode->channels[i];
254 if (chan->flag & HOSTAPD_CHAN_DISABLED)
255 continue;
256 if (start && prev &&
257 prev->chan + chan_spacing == chan->chan &&
258 start->max_tx_power == chan->max_tx_power) {
259 prev = chan;
260 continue; /* can use same entry */
261 }
262
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -0700263 if (start && prev) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700264 pos = hostapd_eid_country_add(pos, end, chan_spacing,
265 start, prev);
266 start = NULL;
267 }
268
269 /* Start new group */
270 start = prev = chan;
271 }
272
273 if (start) {
274 pos = hostapd_eid_country_add(pos, end, chan_spacing,
275 start, prev);
276 }
277
278 if ((pos - eid) & 1) {
279 if (end - pos < 1)
280 return eid;
281 *pos++ = 0; /* pad for 16-bit alignment */
282 }
283
284 eid[1] = (pos - eid) - 2;
285
286 return pos;
287}
288
289
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800290static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700291{
292 const u8 *ie;
293 size_t ielen;
294
295 ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
296 if (ie == NULL || ielen > len)
297 return eid;
298
299 os_memcpy(eid, ie, ielen);
300 return eid + ielen;
301}
302
303
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800304static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
305{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800306#ifdef CONFIG_TESTING_OPTIONS
307 if (hapd->iface->cs_oper_class && hapd->iconf->ecsa_ie_only)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800308 return eid;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800309#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800310
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800311 if (!hapd->cs_freq_params.channel)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800312 return eid;
313
314 *eid++ = WLAN_EID_CHANNEL_SWITCH;
315 *eid++ = 3;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700316 *eid++ = hapd->cs_block_tx;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800317 *eid++ = hapd->cs_freq_params.channel;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700318 *eid++ = hapd->cs_count;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800319
320 return eid;
321}
322
323
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800324static u8 * hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800325{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800326 if (!hapd->cs_freq_params.channel || !hapd->iface->cs_oper_class)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800327 return eid;
328
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800329 *eid++ = WLAN_EID_EXT_CHANSWITCH_ANN;
330 *eid++ = 4;
331 *eid++ = hapd->cs_block_tx;
332 *eid++ = hapd->iface->cs_oper_class;
333 *eid++ = hapd->cs_freq_params.channel;
334 *eid++ = hapd->cs_count;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800335
336 return eid;
337}
338
339
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800340static u8 * hostapd_eid_supported_op_classes(struct hostapd_data *hapd, u8 *eid)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800341{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800342 u8 op_class, channel;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800343
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800344 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) ||
345 !hapd->iface->freq)
346 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800347
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800348 if (ieee80211_freq_to_channel_ext(hapd->iface->freq,
349 hapd->iconf->secondary_channel,
350 hapd->iconf->vht_oper_chwidth,
351 &op_class, &channel) ==
352 NUM_HOSTAPD_MODES)
353 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800354
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800355 *eid++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES;
356 *eid++ = 2;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800357
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800358 /* Current Operating Class */
359 *eid++ = op_class;
360
361 /* TODO: Advertise all the supported operating classes */
362 *eid++ = 0;
363
364 return eid;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800365}
366
367
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800368static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800369 const struct ieee80211_mgmt *req,
370 int is_p2p, size_t *resp_len)
371{
372 struct ieee80211_mgmt *resp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800373 u8 *pos, *epos, *csa_pos;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800374 size_t buflen;
375
376#define MAX_PROBERESP_LEN 768
377 buflen = MAX_PROBERESP_LEN;
378#ifdef CONFIG_WPS
379 if (hapd->wps_probe_resp_ie)
380 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
381#endif /* CONFIG_WPS */
382#ifdef CONFIG_P2P
383 if (hapd->p2p_probe_resp_ie)
384 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
385#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800386#ifdef CONFIG_FST
387 if (hapd->iface->fst_ies)
388 buflen += wpabuf_len(hapd->iface->fst_ies);
389#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700390 if (hapd->conf->vendor_elements)
391 buflen += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800392 if (hapd->conf->vendor_vht) {
393 buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
394 2 + sizeof(struct ieee80211_vht_operation);
395 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800396
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800397#ifdef CONFIG_IEEE80211AX
398 if (hapd->iconf->ieee80211ax) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700399 buflen += 3 + sizeof(struct ieee80211_he_capabilities) +
400 3 + sizeof(struct ieee80211_he_operation);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800401 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700402#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800403
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800404 buflen += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700405 buflen += hostapd_eid_owe_trans_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800406
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800407 resp = os_zalloc(buflen);
408 if (resp == NULL)
409 return NULL;
410
411 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
412
413 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
414 WLAN_FC_STYPE_PROBE_RESP);
415 if (req)
416 os_memcpy(resp->da, req->sa, ETH_ALEN);
417 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
418
419 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
420 resp->u.probe_resp.beacon_int =
421 host_to_le16(hapd->iconf->beacon_int);
422
423 /* hardware or low-level driver will setup seq_ctrl and timestamp */
424 resp->u.probe_resp.capab_info =
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700425 host_to_le16(hostapd_own_capab_info(hapd));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800426
427 pos = resp->u.probe_resp.variable;
428 *pos++ = WLAN_EID_SSID;
429 *pos++ = hapd->conf->ssid.ssid_len;
430 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
431 pos += hapd->conf->ssid.ssid_len;
432
433 /* Supported rates */
434 pos = hostapd_eid_supp_rates(hapd, pos);
435
436 /* DS Params */
437 pos = hostapd_eid_ds_params(hapd, pos);
438
439 pos = hostapd_eid_country(hapd, pos, epos - pos);
440
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800441 /* Power Constraint element */
442 pos = hostapd_eid_pwr_constraint(hapd, pos);
443
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800444 /* CSA IE */
445 csa_pos = hostapd_eid_csa(hapd, pos);
446 if (csa_pos != pos)
447 hapd->cs_c_off_proberesp = csa_pos - (u8 *) resp - 1;
448 pos = csa_pos;
449
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800450 /* ERP Information element */
451 pos = hostapd_eid_erp_info(hapd, pos);
452
453 /* Extended supported rates */
454 pos = hostapd_eid_ext_supp_rates(hapd, pos);
455
456 /* RSN, MDIE, WPA */
457 pos = hostapd_eid_wpa(hapd, pos, epos - pos);
458
Dmitry Shmidt051af732013-10-22 13:52:46 -0700459 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
460
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800461 pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
462
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800463 /* eCSA IE */
464 csa_pos = hostapd_eid_ecsa(hapd, pos);
465 if (csa_pos != pos)
466 hapd->cs_c_off_ecsa_proberesp = csa_pos - (u8 *) resp - 1;
467 pos = csa_pos;
468
469 pos = hostapd_eid_supported_op_classes(hapd, pos);
470
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800471#ifdef CONFIG_IEEE80211N
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800472 /* Secondary Channel Offset element */
473 /* TODO: The standard doesn't specify a position for this element. */
474 pos = hostapd_eid_secondary_channel(hapd, pos);
475
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800476 pos = hostapd_eid_ht_capabilities(hapd, pos);
477 pos = hostapd_eid_ht_operation(hapd, pos);
478#endif /* CONFIG_IEEE80211N */
479
480 pos = hostapd_eid_ext_capab(hapd, pos);
481
482 pos = hostapd_eid_time_adv(hapd, pos);
483 pos = hostapd_eid_time_zone(hapd, pos);
484
485 pos = hostapd_eid_interworking(hapd, pos);
486 pos = hostapd_eid_adv_proto(hapd, pos);
487 pos = hostapd_eid_roaming_consortium(hapd, pos);
488
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800489#ifdef CONFIG_FST
490 if (hapd->iface->fst_ies) {
491 os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies),
492 wpabuf_len(hapd->iface->fst_ies));
493 pos += wpabuf_len(hapd->iface->fst_ies);
494 }
495#endif /* CONFIG_FST */
496
Dmitry Shmidt04949592012-07-19 12:16:46 -0700497#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800498 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700499 pos = hostapd_eid_vht_capabilities(hapd, pos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800500 pos = hostapd_eid_vht_operation(hapd, pos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800501 pos = hostapd_eid_txpower_envelope(hapd, pos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800502 pos = hostapd_eid_wb_chsw_wrapper(hapd, pos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800503 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800504#endif /* CONFIG_IEEE80211AC */
505
506 pos = hostapd_eid_fils_indic(hapd, pos, 0);
507
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700508#ifdef CONFIG_IEEE80211AX
509 if (hapd->iconf->ieee80211ax) {
510 pos = hostapd_eid_he_capab(hapd, pos);
511 pos = hostapd_eid_he_operation(hapd, pos);
512 }
513#endif /* CONFIG_IEEE80211AX */
514
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800515#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800516 if (hapd->conf->vendor_vht)
517 pos = hostapd_eid_vendor_vht(hapd, pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700518#endif /* CONFIG_IEEE80211AC */
519
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800520 /* Wi-Fi Alliance WMM */
521 pos = hostapd_eid_wmm(hapd, pos);
522
523#ifdef CONFIG_WPS
524 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
525 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
526 wpabuf_len(hapd->wps_probe_resp_ie));
527 pos += wpabuf_len(hapd->wps_probe_resp_ie);
528 }
529#endif /* CONFIG_WPS */
530
531#ifdef CONFIG_P2P
532 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
533 hapd->p2p_probe_resp_ie) {
534 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
535 wpabuf_len(hapd->p2p_probe_resp_ie));
536 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
537 }
538#endif /* CONFIG_P2P */
539#ifdef CONFIG_P2P_MANAGER
540 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
541 P2P_MANAGE)
542 pos = hostapd_eid_p2p_manage(hapd, pos);
543#endif /* CONFIG_P2P_MANAGER */
544
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700545#ifdef CONFIG_HS20
546 pos = hostapd_eid_hs20_indication(hapd, pos);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800547 pos = hostapd_eid_osen(hapd, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700548#endif /* CONFIG_HS20 */
549
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800550 pos = hostapd_eid_mbo(hapd, pos, (u8 *) resp + buflen - pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700551 pos = hostapd_eid_owe_trans(hapd, pos, (u8 *) resp + buflen - pos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800552
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700553 if (hapd->conf->vendor_elements) {
554 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
555 wpabuf_len(hapd->conf->vendor_elements));
556 pos += wpabuf_len(hapd->conf->vendor_elements);
557 }
558
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800559 *resp_len = pos - (u8 *) resp;
560 return (u8 *) resp;
561}
562
563
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800564enum ssid_match_result {
565 NO_SSID_MATCH,
566 EXACT_SSID_MATCH,
567 WILDCARD_SSID_MATCH
568};
569
570static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
571 const u8 *ssid, size_t ssid_len,
572 const u8 *ssid_list,
573 size_t ssid_list_len)
574{
575 const u8 *pos, *end;
576 int wildcard = 0;
577
578 if (ssid_len == 0)
579 wildcard = 1;
580 if (ssid_len == hapd->conf->ssid.ssid_len &&
581 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
582 return EXACT_SSID_MATCH;
583
584 if (ssid_list == NULL)
585 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
586
587 pos = ssid_list;
588 end = ssid_list + ssid_list_len;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800589 while (end - pos >= 1) {
590 if (2 + pos[1] > end - pos)
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800591 break;
592 if (pos[1] == 0)
593 wildcard = 1;
594 if (pos[1] == hapd->conf->ssid.ssid_len &&
595 os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0)
596 return EXACT_SSID_MATCH;
597 pos += 2 + pos[1];
598 }
599
600 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
601}
602
603
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800604void sta_track_expire(struct hostapd_iface *iface, int force)
605{
606 struct os_reltime now;
607 struct hostapd_sta_info *info;
608
609 if (!iface->num_sta_seen)
610 return;
611
612 os_get_reltime(&now);
613 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
614 list))) {
615 if (!force &&
616 !os_reltime_expired(&now, &info->last_seen,
617 iface->conf->track_sta_max_age))
618 break;
619 force = 0;
620
621 wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
622 MACSTR, iface->bss[0]->conf->iface,
623 MAC2STR(info->addr));
624 dl_list_del(&info->list);
625 iface->num_sta_seen--;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700626 sta_track_del(info);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800627 }
628}
629
630
631static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
632 const u8 *addr)
633{
634 struct hostapd_sta_info *info;
635
636 dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
637 if (os_memcmp(addr, info->addr, ETH_ALEN) == 0)
638 return info;
639
640 return NULL;
641}
642
643
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800644void sta_track_add(struct hostapd_iface *iface, const u8 *addr, int ssi_signal)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800645{
646 struct hostapd_sta_info *info;
647
648 info = sta_track_get(iface, addr);
649 if (info) {
650 /* Move the most recent entry to the end of the list */
651 dl_list_del(&info->list);
652 dl_list_add_tail(&iface->sta_seen, &info->list);
653 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800654 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800655 return;
656 }
657
658 /* Add a new entry */
659 info = os_zalloc(sizeof(*info));
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700660 if (info == NULL)
661 return;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800662 os_memcpy(info->addr, addr, ETH_ALEN);
663 os_get_reltime(&info->last_seen);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800664 info->ssi_signal = ssi_signal;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800665
666 if (iface->num_sta_seen >= iface->conf->track_sta_max_num) {
667 /* Expire oldest entry to make room for a new one */
668 sta_track_expire(iface, 1);
669 }
670
671 wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
672 MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr));
673 dl_list_add_tail(&iface->sta_seen, &info->list);
674 iface->num_sta_seen++;
675}
676
677
678struct hostapd_data *
679sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
680 const char *ifname)
681{
682 struct hapd_interfaces *interfaces = iface->interfaces;
683 size_t i, j;
684
685 for (i = 0; i < interfaces->count; i++) {
686 struct hostapd_data *hapd = NULL;
687
688 iface = interfaces->iface[i];
689 for (j = 0; j < iface->num_bss; j++) {
690 hapd = iface->bss[j];
691 if (os_strcmp(ifname, hapd->conf->iface) == 0)
692 break;
693 hapd = NULL;
694 }
695
696 if (hapd && sta_track_get(iface, addr))
697 return hapd;
698 }
699
700 return NULL;
701}
702
703
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700704#ifdef CONFIG_TAXONOMY
705void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr,
706 struct wpabuf **probe_ie_taxonomy)
707{
708 struct hostapd_sta_info *info;
709
710 info = sta_track_get(iface, addr);
711 if (!info)
712 return;
713
714 wpabuf_free(*probe_ie_taxonomy);
715 *probe_ie_taxonomy = info->probe_ie_taxonomy;
716 info->probe_ie_taxonomy = NULL;
717}
718#endif /* CONFIG_TAXONOMY */
719
720
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700721void handle_probe_req(struct hostapd_data *hapd,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700722 const struct ieee80211_mgmt *mgmt, size_t len,
723 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700724{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800725 u8 *resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700726 struct ieee802_11_elems elems;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700727 const u8 *ie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800728 size_t ie_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800729 size_t i, resp_len;
730 int noack;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800731 enum ssid_match_result res;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800732 int ret;
733 u16 csa_offs[2];
734 size_t csa_offs_len;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700735 u32 session_timeout, acct_interim_interval;
736 struct vlan_description vlan_id;
737 struct hostapd_sta_wpa_psk_short *psk = NULL;
738 char *identity = NULL;
739 char *radius_cui = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700740
Dmitry Shmidte4663042016-04-04 10:07:49 -0700741 if (len < IEEE80211_HDRLEN)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700742 return;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700743 ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800744 if (hapd->iconf->track_sta_max_num)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800745 sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
Dmitry Shmidte4663042016-04-04 10:07:49 -0700746 ie_len = len - IEEE80211_HDRLEN;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700747
Roshan Pius3a1667e2018-07-03 15:17:14 -0700748 ret = ieee802_11_allowed_address(hapd, mgmt->sa, (const u8 *) mgmt, len,
749 &session_timeout,
750 &acct_interim_interval, &vlan_id,
751 &psk, &identity, &radius_cui, 1);
752 if (ret == HOSTAPD_ACL_REJECT) {
753 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
754 "Ignore Probe Request frame from " MACSTR
755 " due to ACL reject ", MAC2STR(mgmt->sa));
756 return;
757 }
758
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700759 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
760 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800761 mgmt->sa, mgmt->da, mgmt->bssid,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700762 ie, ie_len, ssi_signal) > 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700763 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800764
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700765 if (!hapd->iconf->send_probe_response)
766 return;
767
768 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
769 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
770 MAC2STR(mgmt->sa));
771 return;
772 }
773
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700774 if ((!elems.ssid || !elems.supp_rates)) {
775 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
776 "without SSID or supported rates element",
777 MAC2STR(mgmt->sa));
778 return;
779 }
780
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800781 /*
782 * No need to reply if the Probe Request frame was sent on an adjacent
783 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
784 * AP with dot11RadioMeasurementActivated set to true, but strictly
785 * speaking does not allow such ignoring of Probe Request frames if
786 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
787 * number of unnecessary Probe Response frames for cases where the STA
788 * is less likely to see them (Probe Request frame sent on a
789 * neighboring, but partially overlapping, channel).
790 */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700791 if (elems.ds_params &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800792 hapd->iface->current_mode &&
793 (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
794 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
795 hapd->iconf->channel != elems.ds_params[0]) {
796 wpa_printf(MSG_DEBUG,
797 "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
798 hapd->iconf->channel, elems.ds_params[0]);
799 return;
800 }
801
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700802#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800803 if (hapd->p2p && hapd->p2p_group && elems.wps_ie) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700804 struct wpabuf *wps;
805 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
806 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
807 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
808 "due to mismatch with Requested Device "
809 "Type");
810 wpabuf_free(wps);
811 return;
812 }
813 wpabuf_free(wps);
814 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800815
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800816 if (hapd->p2p && hapd->p2p_group && elems.p2p) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800817 struct wpabuf *p2p;
818 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
819 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
820 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
821 "due to mismatch with Device ID");
822 wpabuf_free(p2p);
823 return;
824 }
825 wpabuf_free(p2p);
826 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700827#endif /* CONFIG_P2P */
828
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800829 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
830 elems.ssid_list_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700831 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
832 "broadcast SSID ignored", MAC2STR(mgmt->sa));
833 return;
834 }
835
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700836#ifdef CONFIG_P2P
837 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
838 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
839 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
840 P2P_WILDCARD_SSID_LEN) == 0) {
841 /* Process P2P Wildcard SSID like Wildcard SSID */
842 elems.ssid_len = 0;
843 }
844#endif /* CONFIG_P2P */
845
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700846#ifdef CONFIG_TAXONOMY
847 {
848 struct sta_info *sta;
849 struct hostapd_sta_info *info;
850
851 if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) {
852 taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len);
853 } else if ((info = sta_track_get(hapd->iface,
854 mgmt->sa)) != NULL) {
855 taxonomy_hostapd_sta_info_probe_req(hapd, info,
856 ie, ie_len);
857 }
858 }
859#endif /* CONFIG_TAXONOMY */
860
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800861 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
862 elems.ssid_list, elems.ssid_list_len);
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700863 if (res == NO_SSID_MATCH) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700864 if (!(mgmt->da[0] & 0x01)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700865 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800866 " for foreign SSID '%s' (DA " MACSTR ")%s",
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800867 MAC2STR(mgmt->sa),
868 wpa_ssid_txt(elems.ssid, elems.ssid_len),
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800869 MAC2STR(mgmt->da),
870 elems.ssid_list ? " (SSID list)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700871 }
872 return;
873 }
874
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800875#ifdef CONFIG_INTERWORKING
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -0700876 if (hapd->conf->interworking &&
877 elems.interworking && elems.interworking_len >= 1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800878 u8 ant = elems.interworking[0] & 0x0f;
879 if (ant != INTERWORKING_ANT_WILDCARD &&
880 ant != hapd->conf->access_network_type) {
881 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
882 " for mismatching ANT %u ignored",
883 MAC2STR(mgmt->sa), ant);
884 return;
885 }
886 }
887
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -0700888 if (hapd->conf->interworking && elems.interworking &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800889 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
890 const u8 *hessid;
891 if (elems.interworking_len == 7)
892 hessid = elems.interworking + 1;
893 else
894 hessid = elems.interworking + 1 + 2;
895 if (!is_broadcast_ether_addr(hessid) &&
896 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
897 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
898 " for mismatching HESSID " MACSTR
899 " ignored",
900 MAC2STR(mgmt->sa), MAC2STR(hessid));
901 return;
902 }
903 }
904#endif /* CONFIG_INTERWORKING */
905
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700906#ifdef CONFIG_P2P
907 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
908 supp_rates_11b_only(&elems)) {
909 /* Indicates support for 11b rates only */
910 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
911 MACSTR " with only 802.11b rates",
912 MAC2STR(mgmt->sa));
913 return;
914 }
915#endif /* CONFIG_P2P */
916
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700917 /* TODO: verify that supp_rates contains at least one matching rate
918 * with AP configuration */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800919
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800920 if (hapd->conf->no_probe_resp_if_seen_on &&
921 is_multicast_ether_addr(mgmt->da) &&
922 is_multicast_ether_addr(mgmt->bssid) &&
923 sta_track_seen_on(hapd->iface, mgmt->sa,
924 hapd->conf->no_probe_resp_if_seen_on)) {
925 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
926 " since STA has been seen on %s",
927 hapd->conf->iface, MAC2STR(mgmt->sa),
928 hapd->conf->no_probe_resp_if_seen_on);
929 return;
930 }
931
932 if (hapd->conf->no_probe_resp_if_max_sta &&
933 is_multicast_ether_addr(mgmt->da) &&
934 is_multicast_ether_addr(mgmt->bssid) &&
935 hapd->num_sta >= hapd->conf->max_num_sta &&
936 !ap_get_sta(hapd, mgmt->sa)) {
937 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
938 " since no room for additional STA",
939 hapd->conf->iface, MAC2STR(mgmt->sa));
940 return;
941 }
942
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700943#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700944 if (hapd->iconf->ignore_probe_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700945 drand48() < hapd->iconf->ignore_probe_probability) {
946 wpa_printf(MSG_INFO,
947 "TESTING: ignoring probe request from " MACSTR,
948 MAC2STR(mgmt->sa));
949 return;
950 }
951#endif /* CONFIG_TESTING_OPTIONS */
952
Roshan Pius3a1667e2018-07-03 15:17:14 -0700953 wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, RX_PROBE_REQUEST "sa=" MACSTR
954 " signal=%d", MAC2STR(mgmt->sa), ssi_signal);
955
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700956 resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800957 &resp_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700958 if (resp == NULL)
959 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700960
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800961 /*
962 * If this is a broadcast probe request, apply no ack policy to avoid
963 * excessive retries.
964 */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800965 noack = !!(res == WILDCARD_SSID_MATCH &&
966 is_broadcast_ether_addr(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700967
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800968 csa_offs_len = 0;
969 if (hapd->csa_in_progress) {
970 if (hapd->cs_c_off_proberesp)
971 csa_offs[csa_offs_len++] =
972 hapd->cs_c_off_proberesp;
973
974 if (hapd->cs_c_off_ecsa_proberesp)
975 csa_offs[csa_offs_len++] =
976 hapd->cs_c_off_ecsa_proberesp;
977 }
978
979 ret = hostapd_drv_send_mlme_csa(hapd, resp, resp_len, noack,
980 csa_offs_len ? csa_offs : NULL,
981 csa_offs_len);
982
983 if (ret < 0)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800984 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700985
986 os_free(resp);
987
988 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
989 "SSID", MAC2STR(mgmt->sa),
990 elems.ssid_len == 0 ? "broadcast" : "our");
991}
992
993
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800994static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
995 size_t *resp_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700996{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800997 /* check probe response offloading caps and print warnings */
998 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
999 return NULL;
1000
1001#ifdef CONFIG_WPS
1002 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
1003 (!(hapd->iface->probe_resp_offloads &
1004 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
1005 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
1006 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
1007 "Probe Response while not supporting this");
1008#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001009
1010#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001011 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
1012 !(hapd->iface->probe_resp_offloads &
1013 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
1014 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
1015 "Probe Response while not supporting this");
1016#endif /* CONFIG_P2P */
1017
1018 if (hapd->conf->interworking &&
1019 !(hapd->iface->probe_resp_offloads &
1020 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
1021 wpa_printf(MSG_WARNING, "Device is trying to offload "
1022 "Interworking Probe Response while not supporting "
1023 "this");
1024
1025 /* Generate a Probe Response template for the non-P2P case */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001026 return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001027}
1028
1029#endif /* NEED_AP_MLME */
1030
1031
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001032void sta_track_del(struct hostapd_sta_info *info)
1033{
1034#ifdef CONFIG_TAXONOMY
1035 wpabuf_free(info->probe_ie_taxonomy);
1036 info->probe_ie_taxonomy = NULL;
1037#endif /* CONFIG_TAXONOMY */
1038 os_free(info);
1039}
1040
1041
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001042int ieee802_11_build_ap_params(struct hostapd_data *hapd,
1043 struct wpa_driver_ap_params *params)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001044{
1045 struct ieee80211_mgmt *head = NULL;
1046 u8 *tail = NULL;
1047 size_t head_len = 0, tail_len = 0;
1048 u8 *resp = NULL;
1049 size_t resp_len = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001050#ifdef NEED_AP_MLME
1051 u16 capab_info;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001052 u8 *pos, *tailpos, *csa_pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001053
1054#define BEACON_HEAD_BUF_SIZE 256
1055#define BEACON_TAIL_BUF_SIZE 512
1056 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
1057 tail_len = BEACON_TAIL_BUF_SIZE;
1058#ifdef CONFIG_WPS
1059 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
1060 tail_len += wpabuf_len(hapd->wps_beacon_ie);
1061#endif /* CONFIG_WPS */
1062#ifdef CONFIG_P2P
1063 if (hapd->p2p_beacon_ie)
1064 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
1065#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001066#ifdef CONFIG_FST
1067 if (hapd->iface->fst_ies)
1068 tail_len += wpabuf_len(hapd->iface->fst_ies);
1069#endif /* CONFIG_FST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001070 if (hapd->conf->vendor_elements)
1071 tail_len += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001072
1073#ifdef CONFIG_IEEE80211AC
1074 if (hapd->conf->vendor_vht) {
1075 tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
1076 2 + sizeof(struct ieee80211_vht_operation);
1077 }
1078#endif /* CONFIG_IEEE80211AC */
1079
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001080#ifdef CONFIG_IEEE80211AX
1081 if (hapd->iconf->ieee80211ax) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001082 tail_len += 3 + sizeof(struct ieee80211_he_capabilities) +
1083 3 + sizeof(struct ieee80211_he_operation);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001084 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001085#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001086
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001087 tail_len += hostapd_mbo_ie_len(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001088 tail_len += hostapd_eid_owe_trans_len(hapd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001089
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001090 tailpos = tail = os_malloc(tail_len);
1091 if (head == NULL || tail == NULL) {
1092 wpa_printf(MSG_ERROR, "Failed to set beacon data");
1093 os_free(head);
1094 os_free(tail);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001095 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001096 }
1097
1098 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1099 WLAN_FC_STYPE_BEACON);
1100 head->duration = host_to_le16(0);
1101 os_memset(head->da, 0xff, ETH_ALEN);
1102
1103 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1104 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1105 head->u.beacon.beacon_int =
1106 host_to_le16(hapd->iconf->beacon_int);
1107
1108 /* hardware or low-level driver will setup seq_ctrl and timestamp */
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001109 capab_info = hostapd_own_capab_info(hapd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001110 head->u.beacon.capab_info = host_to_le16(capab_info);
1111 pos = &head->u.beacon.variable[0];
1112
1113 /* SSID */
1114 *pos++ = WLAN_EID_SSID;
1115 if (hapd->conf->ignore_broadcast_ssid == 2) {
1116 /* clear the data, but keep the correct length of the SSID */
1117 *pos++ = hapd->conf->ssid.ssid_len;
1118 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
1119 pos += hapd->conf->ssid.ssid_len;
1120 } else if (hapd->conf->ignore_broadcast_ssid) {
1121 *pos++ = 0; /* empty SSID */
1122 } else {
1123 *pos++ = hapd->conf->ssid.ssid_len;
1124 os_memcpy(pos, hapd->conf->ssid.ssid,
1125 hapd->conf->ssid.ssid_len);
1126 pos += hapd->conf->ssid.ssid_len;
1127 }
1128
1129 /* Supported rates */
1130 pos = hostapd_eid_supp_rates(hapd, pos);
1131
1132 /* DS Params */
1133 pos = hostapd_eid_ds_params(hapd, pos);
1134
1135 head_len = pos - (u8 *) head;
1136
1137 tailpos = hostapd_eid_country(hapd, tailpos,
1138 tail + BEACON_TAIL_BUF_SIZE - tailpos);
1139
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001140 /* Power Constraint element */
1141 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
1142
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001143 /* CSA IE */
1144 csa_pos = hostapd_eid_csa(hapd, tailpos);
1145 if (csa_pos != tailpos)
1146 hapd->cs_c_off_beacon = csa_pos - tail - 1;
1147 tailpos = csa_pos;
1148
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001149 /* ERP Information element */
1150 tailpos = hostapd_eid_erp_info(hapd, tailpos);
1151
1152 /* Extended supported rates */
1153 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
1154
1155 /* RSN, MDIE, WPA */
1156 tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001157 tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001158
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001159 tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
1160 tail + BEACON_TAIL_BUF_SIZE -
1161 tailpos);
1162
Dmitry Shmidt051af732013-10-22 13:52:46 -07001163 tailpos = hostapd_eid_bss_load(hapd, tailpos,
1164 tail + BEACON_TAIL_BUF_SIZE - tailpos);
1165
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001166 /* eCSA IE */
1167 csa_pos = hostapd_eid_ecsa(hapd, tailpos);
1168 if (csa_pos != tailpos)
1169 hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1;
1170 tailpos = csa_pos;
1171
1172 tailpos = hostapd_eid_supported_op_classes(hapd, tailpos);
1173
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001174#ifdef CONFIG_IEEE80211N
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001175 /* Secondary Channel Offset element */
1176 /* TODO: The standard doesn't specify a position for this element. */
1177 tailpos = hostapd_eid_secondary_channel(hapd, tailpos);
1178
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001179 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
1180 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
1181#endif /* CONFIG_IEEE80211N */
1182
1183 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
1184
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001185 /*
1186 * TODO: Time Advertisement element should only be included in some
1187 * DTIM Beacon frames.
1188 */
1189 tailpos = hostapd_eid_time_adv(hapd, tailpos);
1190
1191 tailpos = hostapd_eid_interworking(hapd, tailpos);
1192 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
1193 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001194
1195#ifdef CONFIG_FST
1196 if (hapd->iface->fst_ies) {
1197 os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies),
1198 wpabuf_len(hapd->iface->fst_ies));
1199 tailpos += wpabuf_len(hapd->iface->fst_ies);
1200 }
1201#endif /* CONFIG_FST */
1202
Dmitry Shmidt04949592012-07-19 12:16:46 -07001203#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001204 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
Dmitry Shmidt7d175302016-09-06 13:11:34 -07001205 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001206 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08001207 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001208 tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001209 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001210#endif /* CONFIG_IEEE80211AC */
1211
1212 tailpos = hostapd_eid_fils_indic(hapd, tailpos, 0);
1213
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001214#ifdef CONFIG_IEEE80211AX
1215 if (hapd->iconf->ieee80211ax) {
1216 tailpos = hostapd_eid_he_capab(hapd, tailpos);
1217 tailpos = hostapd_eid_he_operation(hapd, tailpos);
1218 }
1219#endif /* CONFIG_IEEE80211AX */
1220
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001221#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001222 if (hapd->conf->vendor_vht)
1223 tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001224#endif /* CONFIG_IEEE80211AC */
1225
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001226 /* Wi-Fi Alliance WMM */
1227 tailpos = hostapd_eid_wmm(hapd, tailpos);
1228
1229#ifdef CONFIG_WPS
1230 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
1231 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
1232 wpabuf_len(hapd->wps_beacon_ie));
1233 tailpos += wpabuf_len(hapd->wps_beacon_ie);
1234 }
1235#endif /* CONFIG_WPS */
1236
1237#ifdef CONFIG_P2P
1238 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
1239 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
1240 wpabuf_len(hapd->p2p_beacon_ie));
1241 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
1242 }
1243#endif /* CONFIG_P2P */
1244#ifdef CONFIG_P2P_MANAGER
1245 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
1246 P2P_MANAGE)
1247 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
1248#endif /* CONFIG_P2P_MANAGER */
1249
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001250#ifdef CONFIG_HS20
1251 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001252 tailpos = hostapd_eid_osen(hapd, tailpos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001253#endif /* CONFIG_HS20 */
1254
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001255 tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001256 tailpos = hostapd_eid_owe_trans(hapd, tailpos,
1257 tail + tail_len - tailpos);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001258
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001259 if (hapd->conf->vendor_elements) {
1260 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
1261 wpabuf_len(hapd->conf->vendor_elements));
1262 tailpos += wpabuf_len(hapd->conf->vendor_elements);
1263 }
1264
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001265 tail_len = tailpos > tail ? tailpos - tail : 0;
1266
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001267 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
1268#endif /* NEED_AP_MLME */
1269
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001270 os_memset(params, 0, sizeof(*params));
1271 params->head = (u8 *) head;
1272 params->head_len = head_len;
1273 params->tail = tail;
1274 params->tail_len = tail_len;
1275 params->proberesp = resp;
1276 params->proberesp_len = resp_len;
1277 params->dtim_period = hapd->conf->dtim_period;
1278 params->beacon_int = hapd->iconf->beacon_int;
1279 params->basic_rates = hapd->iface->basic_rates;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001280 params->beacon_rate = hapd->iconf->beacon_rate;
1281 params->rate_type = hapd->iconf->rate_type;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001282 params->ssid = hapd->conf->ssid.ssid;
1283 params->ssid_len = hapd->conf->ssid.ssid_len;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001284 if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
1285 (WPA_PROTO_WPA | WPA_PROTO_RSN))
1286 params->pairwise_ciphers = hapd->conf->wpa_pairwise |
1287 hapd->conf->rsn_pairwise;
1288 else if (hapd->conf->wpa & WPA_PROTO_RSN)
1289 params->pairwise_ciphers = hapd->conf->rsn_pairwise;
1290 else if (hapd->conf->wpa & WPA_PROTO_WPA)
1291 params->pairwise_ciphers = hapd->conf->wpa_pairwise;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001292 params->group_cipher = hapd->conf->wpa_group;
1293 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
1294 params->auth_algs = hapd->conf->auth_algs;
1295 params->wpa_version = hapd->conf->wpa;
1296 params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001297 (hapd->conf->ieee802_1x &&
1298 (hapd->conf->default_wep_key_len ||
1299 hapd->conf->individual_wep_key_len));
1300 switch (hapd->conf->ignore_broadcast_ssid) {
1301 case 0:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001302 params->hide_ssid = NO_SSID_HIDING;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001303 break;
1304 case 1:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001305 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001306 break;
1307 case 2:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001308 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001309 break;
1310 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001311 params->isolate = hapd->conf->isolate;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001312 params->smps_mode = hapd->iconf->ht_capab & HT_CAP_INFO_SMPS_MASK;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001313#ifdef NEED_AP_MLME
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001314 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001315 ERP_INFO_USE_PROTECTION);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001316 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001317 hapd->iconf->preamble == SHORT_PREAMBLE;
1318 if (hapd->iface->current_mode &&
1319 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001320 params->short_slot_time =
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001321 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
1322 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001323 params->short_slot_time = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001324 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001325 params->ht_opmode = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001326 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001327 params->ht_opmode = hapd->iface->ht_op_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001328#endif /* NEED_AP_MLME */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001329 params->interworking = hapd->conf->interworking;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001330 if (hapd->conf->interworking &&
1331 !is_zero_ether_addr(hapd->conf->hessid))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001332 params->hessid = hapd->conf->hessid;
1333 params->access_network_type = hapd->conf->access_network_type;
1334 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001335#ifdef CONFIG_P2P
1336 params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
1337#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001338#ifdef CONFIG_HS20
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001339 params->disable_dgaf = hapd->conf->disable_dgaf;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001340 if (hapd->conf->osen) {
1341 params->privacy = 1;
1342 params->osen = 1;
1343 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001344#endif /* CONFIG_HS20 */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001345 params->multicast_to_unicast = hapd->conf->multicast_to_unicast;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001346 params->pbss = hapd->conf->pbss;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001347 return 0;
1348}
1349
1350
1351void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
1352{
1353 os_free(params->tail);
1354 params->tail = NULL;
1355 os_free(params->head);
1356 params->head = NULL;
1357 os_free(params->proberesp);
1358 params->proberesp = NULL;
1359}
1360
1361
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001362int ieee802_11_set_beacon(struct hostapd_data *hapd)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001363{
1364 struct wpa_driver_ap_params params;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001365 struct hostapd_freq_params freq;
1366 struct hostapd_iface *iface = hapd->iface;
1367 struct hostapd_config *iconf = iface->conf;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001368 struct wpabuf *beacon, *proberesp, *assocresp;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001369 int res, ret = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001370
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001371 if (hapd->csa_in_progress) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001372 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001373 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001374 }
1375
1376 hapd->beacon_set_done = 1;
1377
1378 if (ieee802_11_build_ap_params(hapd, &params) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001379 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001380
1381 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
1382 0)
1383 goto fail;
1384
1385 params.beacon_ies = beacon;
1386 params.proberesp_ies = proberesp;
1387 params.assocresp_ies = assocresp;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001388 params.reenable = hapd->reenable_beacon;
1389 hapd->reenable_beacon = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001390
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001391 if (iface->current_mode &&
1392 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
1393 iconf->channel, iconf->ieee80211n,
1394 iconf->ieee80211ac,
1395 iconf->secondary_channel,
1396 iconf->vht_oper_chwidth,
1397 iconf->vht_oper_centr_freq_seg0_idx,
1398 iconf->vht_oper_centr_freq_seg1_idx,
1399 iface->current_mode->vht_capab) == 0)
1400 params.freq = &freq;
1401
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001402 res = hostapd_drv_set_ap(hapd, &params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001403 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001404 if (res)
1405 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
1406 else
1407 ret = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001408fail:
1409 ieee802_11_free_ap_params(&params);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001410 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001411}
1412
1413
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001414int ieee802_11_set_beacons(struct hostapd_iface *iface)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001415{
1416 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001417 int ret = 0;
1418
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08001419 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001420 if (iface->bss[i]->started &&
1421 ieee802_11_set_beacon(iface->bss[i]) < 0)
1422 ret = -1;
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08001423 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001424
1425 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001426}
1427
Dmitry Shmidt04949592012-07-19 12:16:46 -07001428
1429/* only update beacons if started */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001430int ieee802_11_update_beacons(struct hostapd_iface *iface)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001431{
1432 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001433 int ret = 0;
1434
1435 for (i = 0; i < iface->num_bss; i++) {
1436 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
1437 ieee802_11_set_beacon(iface->bss[i]) < 0)
1438 ret = -1;
1439 }
1440
1441 return ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001442}
1443
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001444#endif /* CONFIG_NATIVE_WINDOWS */