blob: e575b65cbf3ace94e186f6be63ef3be8e8e788d9 [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 Shmidt8d520ff2011-05-09 14:06:53 -070032
33
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080034#ifdef NEED_AP_MLME
35
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080036static u8 * hostapd_eid_rm_enabled_capab(struct hostapd_data *hapd, u8 *eid,
37 size_t len)
38{
39 if (!hapd->conf->radio_measurements || len < 2 + 4)
40 return eid;
41
42 *eid++ = WLAN_EID_RRM_ENABLED_CAPABILITIES;
43 *eid++ = 5;
44 *eid++ = (hapd->conf->radio_measurements & BIT(0)) ?
45 WLAN_RRM_CAPS_NEIGHBOR_REPORT : 0x00;
46 *eid++ = 0x00;
47 *eid++ = 0x00;
48 *eid++ = 0x00;
49 *eid++ = 0x00;
50 return eid;
51}
52
53
Dmitry Shmidt051af732013-10-22 13:52:46 -070054static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
55{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080056 if (len < 2 + 5)
57 return eid;
58
Dmitry Shmidt051af732013-10-22 13:52:46 -070059#ifdef CONFIG_TESTING_OPTIONS
60 if (hapd->conf->bss_load_test_set) {
Dmitry Shmidt051af732013-10-22 13:52:46 -070061 *eid++ = WLAN_EID_BSS_LOAD;
62 *eid++ = 5;
63 os_memcpy(eid, hapd->conf->bss_load_test, 5);
64 eid += 5;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080065 return eid;
Dmitry Shmidt051af732013-10-22 13:52:46 -070066 }
67#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080068 if (hapd->conf->bss_load_update_period) {
69 *eid++ = WLAN_EID_BSS_LOAD;
70 *eid++ = 5;
71 WPA_PUT_LE16(eid, hapd->num_sta);
72 eid += 2;
73 *eid++ = hapd->iface->channel_utilization;
74 WPA_PUT_LE16(eid, 0); /* no available admission capabity */
75 eid += 2;
76 }
Dmitry Shmidt051af732013-10-22 13:52:46 -070077 return eid;
78}
79
80
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070081static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
82{
83 u8 erp = 0;
84
85 if (hapd->iface->current_mode == NULL ||
86 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
87 return 0;
88
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080089 if (hapd->iface->olbc)
90 erp |= ERP_INFO_USE_PROTECTION;
91 if (hapd->iface->num_sta_non_erp > 0) {
92 erp |= ERP_INFO_NON_ERP_PRESENT |
93 ERP_INFO_USE_PROTECTION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070094 }
95 if (hapd->iface->num_sta_no_short_preamble > 0 ||
96 hapd->iconf->preamble == LONG_PREAMBLE)
97 erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
98
99 return erp;
100}
101
102
103static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
104{
105 *eid++ = WLAN_EID_DS_PARAMS;
106 *eid++ = 1;
107 *eid++ = hapd->iconf->channel;
108 return eid;
109}
110
111
112static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
113{
114 if (hapd->iface->current_mode == NULL ||
115 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
116 return eid;
117
118 /* Set NonERP_present and use_protection bits if there
119 * are any associated NonERP stations. */
120 /* TODO: use_protection bit can be set to zero even if
121 * there are NonERP stations present. This optimization
122 * might be useful if NonERP stations are "quiet".
123 * See 802.11g/D6 E-1 for recommended practice.
124 * In addition, Non ERP present might be set, if AP detects Non ERP
125 * operation on other APs. */
126
127 /* Add ERP Information element */
128 *eid++ = WLAN_EID_ERP_INFO;
129 *eid++ = 1;
130 *eid++ = ieee802_11_erp_info(hapd);
131
132 return eid;
133}
134
135
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800136static u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid)
137{
138 u8 *pos = eid;
139 u8 local_pwr_constraint = 0;
140 int dfs;
141
142 if (hapd->iface->current_mode == NULL ||
143 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
144 return eid;
145
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700146 /* Let host drivers add this IE if DFS support is offloaded */
147 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)
148 return eid;
149
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800150 /*
151 * There is no DFS support and power constraint was not directly
152 * requested by config option.
153 */
154 if (!hapd->iconf->ieee80211h &&
155 hapd->iconf->local_pwr_constraint == -1)
156 return eid;
157
158 /* Check if DFS is required by regulatory. */
159 dfs = hostapd_is_dfs_required(hapd->iface);
160 if (dfs < 0) {
161 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
162 dfs);
163 dfs = 0;
164 }
165
166 if (dfs == 0 && hapd->iconf->local_pwr_constraint == -1)
167 return eid;
168
169 /*
170 * ieee80211h (DFS) is enabled so Power Constraint element shall
171 * be added when running on DFS channel whenever local_pwr_constraint
172 * is configured or not. In order to meet regulations when TPC is not
173 * implemented using a transmit power that is below the legal maximum
174 * (including any mitigation factor) should help. In this case,
175 * indicate 3 dB below maximum allowed transmit power.
176 */
177 if (hapd->iconf->local_pwr_constraint == -1)
178 local_pwr_constraint = 3;
179
180 /*
181 * A STA that is not an AP shall use a transmit power less than or
182 * equal to the local maximum transmit power level for the channel.
183 * The local maximum transmit power can be calculated from the formula:
184 * local max TX pwr = max TX pwr - local pwr constraint
185 * Where max TX pwr is maximum transmit power level specified for
186 * channel in Country element and local pwr constraint is specified
187 * for channel in this Power Constraint element.
188 */
189
190 /* Element ID */
191 *pos++ = WLAN_EID_PWR_CONSTRAINT;
192 /* Length */
193 *pos++ = 1;
194 /* Local Power Constraint */
195 if (local_pwr_constraint)
196 *pos++ = local_pwr_constraint;
197 else
198 *pos++ = hapd->iconf->local_pwr_constraint;
199
200 return pos;
201}
202
203
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700204static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
205 struct hostapd_channel_data *start,
206 struct hostapd_channel_data *prev)
207{
208 if (end - pos < 3)
209 return pos;
210
211 /* first channel number */
212 *pos++ = start->chan;
213 /* number of channels */
214 *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
215 /* maximum transmit power level */
216 *pos++ = start->max_tx_power;
217
218 return pos;
219}
220
221
222static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
223 int max_len)
224{
225 u8 *pos = eid;
226 u8 *end = eid + max_len;
227 int i;
228 struct hostapd_hw_modes *mode;
229 struct hostapd_channel_data *start, *prev;
230 int chan_spacing = 1;
231
232 if (!hapd->iconf->ieee80211d || max_len < 6 ||
233 hapd->iface->current_mode == NULL)
234 return eid;
235
236 *pos++ = WLAN_EID_COUNTRY;
237 pos++; /* length will be set later */
238 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
239 pos += 3;
240
241 mode = hapd->iface->current_mode;
242 if (mode->mode == HOSTAPD_MODE_IEEE80211A)
243 chan_spacing = 4;
244
245 start = prev = NULL;
246 for (i = 0; i < mode->num_channels; i++) {
247 struct hostapd_channel_data *chan = &mode->channels[i];
248 if (chan->flag & HOSTAPD_CHAN_DISABLED)
249 continue;
250 if (start && prev &&
251 prev->chan + chan_spacing == chan->chan &&
252 start->max_tx_power == chan->max_tx_power) {
253 prev = chan;
254 continue; /* can use same entry */
255 }
256
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -0700257 if (start && prev) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700258 pos = hostapd_eid_country_add(pos, end, chan_spacing,
259 start, prev);
260 start = NULL;
261 }
262
263 /* Start new group */
264 start = prev = chan;
265 }
266
267 if (start) {
268 pos = hostapd_eid_country_add(pos, end, chan_spacing,
269 start, prev);
270 }
271
272 if ((pos - eid) & 1) {
273 if (end - pos < 1)
274 return eid;
275 *pos++ = 0; /* pad for 16-bit alignment */
276 }
277
278 eid[1] = (pos - eid) - 2;
279
280 return pos;
281}
282
283
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800284static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700285{
286 const u8 *ie;
287 size_t ielen;
288
289 ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
290 if (ie == NULL || ielen > len)
291 return eid;
292
293 os_memcpy(eid, ie, ielen);
294 return eid + ielen;
295}
296
297
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800298static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
299{
300 u8 chan;
301
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700302 if (!hapd->cs_freq_params.freq)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800303 return eid;
304
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700305 if (ieee80211_freq_to_chan(hapd->cs_freq_params.freq, &chan) ==
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800306 NUM_HOSTAPD_MODES)
307 return eid;
308
309 *eid++ = WLAN_EID_CHANNEL_SWITCH;
310 *eid++ = 3;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700311 *eid++ = hapd->cs_block_tx;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800312 *eid++ = chan;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700313 *eid++ = hapd->cs_count;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800314
315 return eid;
316}
317
318
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800319static u8 * hostapd_eid_secondary_channel(struct hostapd_data *hapd, u8 *eid)
320{
321 u8 sec_ch;
322
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700323 if (!hapd->cs_freq_params.sec_channel_offset)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800324 return eid;
325
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700326 if (hapd->cs_freq_params.sec_channel_offset == -1)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800327 sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700328 else if (hapd->cs_freq_params.sec_channel_offset == 1)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800329 sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE;
330 else
331 return eid;
332
333 *eid++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET;
334 *eid++ = 1;
335 *eid++ = sec_ch;
336
337 return eid;
338}
339
340
341static u8 * hostapd_add_csa_elems(struct hostapd_data *hapd, u8 *pos,
342 u8 *start, unsigned int *csa_counter_off)
343{
344 u8 *old_pos = pos;
345
346 if (!csa_counter_off)
347 return pos;
348
349 *csa_counter_off = 0;
350 pos = hostapd_eid_csa(hapd, pos);
351
352 if (pos != old_pos) {
353 /* save an offset to the counter - should be last byte */
354 *csa_counter_off = pos - start - 1;
355 pos = hostapd_eid_secondary_channel(hapd, pos);
356 }
357
358 return pos;
359}
360
361
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800362static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
363 struct sta_info *sta,
364 const struct ieee80211_mgmt *req,
365 int is_p2p, size_t *resp_len)
366{
367 struct ieee80211_mgmt *resp;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800368 u8 *pos, *epos;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800369 size_t buflen;
370
371#define MAX_PROBERESP_LEN 768
372 buflen = MAX_PROBERESP_LEN;
373#ifdef CONFIG_WPS
374 if (hapd->wps_probe_resp_ie)
375 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
376#endif /* CONFIG_WPS */
377#ifdef CONFIG_P2P
378 if (hapd->p2p_probe_resp_ie)
379 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
380#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700381 if (hapd->conf->vendor_elements)
382 buflen += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800383 if (hapd->conf->vendor_vht) {
384 buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
385 2 + sizeof(struct ieee80211_vht_operation);
386 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800387 resp = os_zalloc(buflen);
388 if (resp == NULL)
389 return NULL;
390
391 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
392
393 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
394 WLAN_FC_STYPE_PROBE_RESP);
395 if (req)
396 os_memcpy(resp->da, req->sa, ETH_ALEN);
397 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
398
399 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
400 resp->u.probe_resp.beacon_int =
401 host_to_le16(hapd->iconf->beacon_int);
402
403 /* hardware or low-level driver will setup seq_ctrl and timestamp */
404 resp->u.probe_resp.capab_info =
405 host_to_le16(hostapd_own_capab_info(hapd, sta, 1));
406
407 pos = resp->u.probe_resp.variable;
408 *pos++ = WLAN_EID_SSID;
409 *pos++ = hapd->conf->ssid.ssid_len;
410 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
411 pos += hapd->conf->ssid.ssid_len;
412
413 /* Supported rates */
414 pos = hostapd_eid_supp_rates(hapd, pos);
415
416 /* DS Params */
417 pos = hostapd_eid_ds_params(hapd, pos);
418
419 pos = hostapd_eid_country(hapd, pos, epos - pos);
420
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800421 /* Power Constraint element */
422 pos = hostapd_eid_pwr_constraint(hapd, pos);
423
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800424 /* ERP Information element */
425 pos = hostapd_eid_erp_info(hapd, pos);
426
427 /* Extended supported rates */
428 pos = hostapd_eid_ext_supp_rates(hapd, pos);
429
430 /* RSN, MDIE, WPA */
431 pos = hostapd_eid_wpa(hapd, pos, epos - pos);
432
Dmitry Shmidt051af732013-10-22 13:52:46 -0700433 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
434
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800435 pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
436
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800437#ifdef CONFIG_IEEE80211N
438 pos = hostapd_eid_ht_capabilities(hapd, pos);
439 pos = hostapd_eid_ht_operation(hapd, pos);
440#endif /* CONFIG_IEEE80211N */
441
442 pos = hostapd_eid_ext_capab(hapd, pos);
443
444 pos = hostapd_eid_time_adv(hapd, pos);
445 pos = hostapd_eid_time_zone(hapd, pos);
446
447 pos = hostapd_eid_interworking(hapd, pos);
448 pos = hostapd_eid_adv_proto(hapd, pos);
449 pos = hostapd_eid_roaming_consortium(hapd, pos);
450
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800451 pos = hostapd_add_csa_elems(hapd, pos, (u8 *)resp,
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700452 &hapd->cs_c_off_proberesp);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700453#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800454 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
455 pos = hostapd_eid_vht_capabilities(hapd, pos);
456 pos = hostapd_eid_vht_operation(hapd, pos);
457 }
458 if (hapd->conf->vendor_vht)
459 pos = hostapd_eid_vendor_vht(hapd, pos);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700460#endif /* CONFIG_IEEE80211AC */
461
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800462 /* Wi-Fi Alliance WMM */
463 pos = hostapd_eid_wmm(hapd, pos);
464
465#ifdef CONFIG_WPS
466 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
467 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
468 wpabuf_len(hapd->wps_probe_resp_ie));
469 pos += wpabuf_len(hapd->wps_probe_resp_ie);
470 }
471#endif /* CONFIG_WPS */
472
473#ifdef CONFIG_P2P
474 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
475 hapd->p2p_probe_resp_ie) {
476 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
477 wpabuf_len(hapd->p2p_probe_resp_ie));
478 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
479 }
480#endif /* CONFIG_P2P */
481#ifdef CONFIG_P2P_MANAGER
482 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
483 P2P_MANAGE)
484 pos = hostapd_eid_p2p_manage(hapd, pos);
485#endif /* CONFIG_P2P_MANAGER */
486
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700487#ifdef CONFIG_HS20
488 pos = hostapd_eid_hs20_indication(hapd, pos);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800489 pos = hostapd_eid_osen(hapd, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700490#endif /* CONFIG_HS20 */
491
492 if (hapd->conf->vendor_elements) {
493 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
494 wpabuf_len(hapd->conf->vendor_elements));
495 pos += wpabuf_len(hapd->conf->vendor_elements);
496 }
497
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800498 *resp_len = pos - (u8 *) resp;
499 return (u8 *) resp;
500}
501
502
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800503enum ssid_match_result {
504 NO_SSID_MATCH,
505 EXACT_SSID_MATCH,
506 WILDCARD_SSID_MATCH
507};
508
509static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
510 const u8 *ssid, size_t ssid_len,
511 const u8 *ssid_list,
512 size_t ssid_list_len)
513{
514 const u8 *pos, *end;
515 int wildcard = 0;
516
517 if (ssid_len == 0)
518 wildcard = 1;
519 if (ssid_len == hapd->conf->ssid.ssid_len &&
520 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
521 return EXACT_SSID_MATCH;
522
523 if (ssid_list == NULL)
524 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
525
526 pos = ssid_list;
527 end = ssid_list + ssid_list_len;
528 while (pos + 1 <= end) {
529 if (pos + 2 + pos[1] > end)
530 break;
531 if (pos[1] == 0)
532 wildcard = 1;
533 if (pos[1] == hapd->conf->ssid.ssid_len &&
534 os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0)
535 return EXACT_SSID_MATCH;
536 pos += 2 + pos[1];
537 }
538
539 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
540}
541
542
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700543void handle_probe_req(struct hostapd_data *hapd,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700544 const struct ieee80211_mgmt *mgmt, size_t len,
545 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700546{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800547 u8 *resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700548 struct ieee802_11_elems elems;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700549 const u8 *ie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800550 size_t ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700551 struct sta_info *sta = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800552 size_t i, resp_len;
553 int noack;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800554 enum ssid_match_result res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700555
556 ie = mgmt->u.probe_req.variable;
557 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
558 return;
559 ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
560
561 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
562 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800563 mgmt->sa, mgmt->da, mgmt->bssid,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700564 ie, ie_len, ssi_signal) > 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700565 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800566
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700567 if (!hapd->iconf->send_probe_response)
568 return;
569
570 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
571 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
572 MAC2STR(mgmt->sa));
573 return;
574 }
575
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700576 if ((!elems.ssid || !elems.supp_rates)) {
577 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
578 "without SSID or supported rates element",
579 MAC2STR(mgmt->sa));
580 return;
581 }
582
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800583 /*
584 * No need to reply if the Probe Request frame was sent on an adjacent
585 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
586 * AP with dot11RadioMeasurementActivated set to true, but strictly
587 * speaking does not allow such ignoring of Probe Request frames if
588 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
589 * number of unnecessary Probe Response frames for cases where the STA
590 * is less likely to see them (Probe Request frame sent on a
591 * neighboring, but partially overlapping, channel).
592 */
593 if (elems.ds_params && elems.ds_params_len == 1 &&
594 hapd->iface->current_mode &&
595 (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
596 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
597 hapd->iconf->channel != elems.ds_params[0]) {
598 wpa_printf(MSG_DEBUG,
599 "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
600 hapd->iconf->channel, elems.ds_params[0]);
601 return;
602 }
603
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700604#ifdef CONFIG_P2P
605 if (hapd->p2p && elems.wps_ie) {
606 struct wpabuf *wps;
607 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
608 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
609 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
610 "due to mismatch with Requested Device "
611 "Type");
612 wpabuf_free(wps);
613 return;
614 }
615 wpabuf_free(wps);
616 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800617
618 if (hapd->p2p && elems.p2p) {
619 struct wpabuf *p2p;
620 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
621 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
622 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
623 "due to mismatch with Device ID");
624 wpabuf_free(p2p);
625 return;
626 }
627 wpabuf_free(p2p);
628 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700629#endif /* CONFIG_P2P */
630
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800631 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
632 elems.ssid_list_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700633 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
634 "broadcast SSID ignored", MAC2STR(mgmt->sa));
635 return;
636 }
637
638 sta = ap_get_sta(hapd, mgmt->sa);
639
640#ifdef CONFIG_P2P
641 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
642 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
643 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
644 P2P_WILDCARD_SSID_LEN) == 0) {
645 /* Process P2P Wildcard SSID like Wildcard SSID */
646 elems.ssid_len = 0;
647 }
648#endif /* CONFIG_P2P */
649
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800650 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
651 elems.ssid_list, elems.ssid_list_len);
652 if (res != NO_SSID_MATCH) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700653 if (sta)
654 sta->ssid_probe = &hapd->conf->ssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800655 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700656 if (!(mgmt->da[0] & 0x01)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700657 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800658 " for foreign SSID '%s' (DA " MACSTR ")%s",
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800659 MAC2STR(mgmt->sa),
660 wpa_ssid_txt(elems.ssid, elems.ssid_len),
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800661 MAC2STR(mgmt->da),
662 elems.ssid_list ? " (SSID list)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700663 }
664 return;
665 }
666
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800667#ifdef CONFIG_INTERWORKING
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -0700668 if (hapd->conf->interworking &&
669 elems.interworking && elems.interworking_len >= 1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800670 u8 ant = elems.interworking[0] & 0x0f;
671 if (ant != INTERWORKING_ANT_WILDCARD &&
672 ant != hapd->conf->access_network_type) {
673 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
674 " for mismatching ANT %u ignored",
675 MAC2STR(mgmt->sa), ant);
676 return;
677 }
678 }
679
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -0700680 if (hapd->conf->interworking && elems.interworking &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800681 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
682 const u8 *hessid;
683 if (elems.interworking_len == 7)
684 hessid = elems.interworking + 1;
685 else
686 hessid = elems.interworking + 1 + 2;
687 if (!is_broadcast_ether_addr(hessid) &&
688 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
689 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
690 " for mismatching HESSID " MACSTR
691 " ignored",
692 MAC2STR(mgmt->sa), MAC2STR(hessid));
693 return;
694 }
695 }
696#endif /* CONFIG_INTERWORKING */
697
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700698#ifdef CONFIG_P2P
699 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
700 supp_rates_11b_only(&elems)) {
701 /* Indicates support for 11b rates only */
702 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
703 MACSTR " with only 802.11b rates",
704 MAC2STR(mgmt->sa));
705 return;
706 }
707#endif /* CONFIG_P2P */
708
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700709 /* TODO: verify that supp_rates contains at least one matching rate
710 * with AP configuration */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800711
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700712#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700713 if (hapd->iconf->ignore_probe_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700714 drand48() < hapd->iconf->ignore_probe_probability) {
715 wpa_printf(MSG_INFO,
716 "TESTING: ignoring probe request from " MACSTR,
717 MAC2STR(mgmt->sa));
718 return;
719 }
720#endif /* CONFIG_TESTING_OPTIONS */
721
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800722 resp = hostapd_gen_probe_resp(hapd, sta, mgmt, elems.p2p != NULL,
723 &resp_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700724 if (resp == NULL)
725 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700726
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800727 /*
728 * If this is a broadcast probe request, apply no ack policy to avoid
729 * excessive retries.
730 */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800731 noack = !!(res == WILDCARD_SSID_MATCH &&
732 is_broadcast_ether_addr(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700733
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800734 if (hostapd_drv_send_mlme(hapd, resp, resp_len, noack) < 0)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800735 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700736
737 os_free(resp);
738
739 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
740 "SSID", MAC2STR(mgmt->sa),
741 elems.ssid_len == 0 ? "broadcast" : "our");
742}
743
744
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800745static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
746 size_t *resp_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700747{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800748 /* check probe response offloading caps and print warnings */
749 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
750 return NULL;
751
752#ifdef CONFIG_WPS
753 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
754 (!(hapd->iface->probe_resp_offloads &
755 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
756 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
757 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
758 "Probe Response while not supporting this");
759#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700760
761#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800762 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
763 !(hapd->iface->probe_resp_offloads &
764 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
765 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
766 "Probe Response while not supporting this");
767#endif /* CONFIG_P2P */
768
769 if (hapd->conf->interworking &&
770 !(hapd->iface->probe_resp_offloads &
771 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
772 wpa_printf(MSG_WARNING, "Device is trying to offload "
773 "Interworking Probe Response while not supporting "
774 "this");
775
776 /* Generate a Probe Response template for the non-P2P case */
777 return hostapd_gen_probe_resp(hapd, NULL, NULL, 0, resp_len);
778}
779
780#endif /* NEED_AP_MLME */
781
782
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800783int ieee802_11_build_ap_params(struct hostapd_data *hapd,
784 struct wpa_driver_ap_params *params)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800785{
786 struct ieee80211_mgmt *head = NULL;
787 u8 *tail = NULL;
788 size_t head_len = 0, tail_len = 0;
789 u8 *resp = NULL;
790 size_t resp_len = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800791#ifdef NEED_AP_MLME
792 u16 capab_info;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800793 u8 *pos, *tailpos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700794
795#define BEACON_HEAD_BUF_SIZE 256
796#define BEACON_TAIL_BUF_SIZE 512
797 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
798 tail_len = BEACON_TAIL_BUF_SIZE;
799#ifdef CONFIG_WPS
800 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
801 tail_len += wpabuf_len(hapd->wps_beacon_ie);
802#endif /* CONFIG_WPS */
803#ifdef CONFIG_P2P
804 if (hapd->p2p_beacon_ie)
805 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
806#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700807 if (hapd->conf->vendor_elements)
808 tail_len += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800809
810#ifdef CONFIG_IEEE80211AC
811 if (hapd->conf->vendor_vht) {
812 tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
813 2 + sizeof(struct ieee80211_vht_operation);
814 }
815#endif /* CONFIG_IEEE80211AC */
816
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700817 tailpos = tail = os_malloc(tail_len);
818 if (head == NULL || tail == NULL) {
819 wpa_printf(MSG_ERROR, "Failed to set beacon data");
820 os_free(head);
821 os_free(tail);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800822 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700823 }
824
825 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
826 WLAN_FC_STYPE_BEACON);
827 head->duration = host_to_le16(0);
828 os_memset(head->da, 0xff, ETH_ALEN);
829
830 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
831 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
832 head->u.beacon.beacon_int =
833 host_to_le16(hapd->iconf->beacon_int);
834
835 /* hardware or low-level driver will setup seq_ctrl and timestamp */
836 capab_info = hostapd_own_capab_info(hapd, NULL, 0);
837 head->u.beacon.capab_info = host_to_le16(capab_info);
838 pos = &head->u.beacon.variable[0];
839
840 /* SSID */
841 *pos++ = WLAN_EID_SSID;
842 if (hapd->conf->ignore_broadcast_ssid == 2) {
843 /* clear the data, but keep the correct length of the SSID */
844 *pos++ = hapd->conf->ssid.ssid_len;
845 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
846 pos += hapd->conf->ssid.ssid_len;
847 } else if (hapd->conf->ignore_broadcast_ssid) {
848 *pos++ = 0; /* empty SSID */
849 } else {
850 *pos++ = hapd->conf->ssid.ssid_len;
851 os_memcpy(pos, hapd->conf->ssid.ssid,
852 hapd->conf->ssid.ssid_len);
853 pos += hapd->conf->ssid.ssid_len;
854 }
855
856 /* Supported rates */
857 pos = hostapd_eid_supp_rates(hapd, pos);
858
859 /* DS Params */
860 pos = hostapd_eid_ds_params(hapd, pos);
861
862 head_len = pos - (u8 *) head;
863
864 tailpos = hostapd_eid_country(hapd, tailpos,
865 tail + BEACON_TAIL_BUF_SIZE - tailpos);
866
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800867 /* Power Constraint element */
868 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
869
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700870 /* ERP Information element */
871 tailpos = hostapd_eid_erp_info(hapd, tailpos);
872
873 /* Extended supported rates */
874 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
875
876 /* RSN, MDIE, WPA */
877 tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800878 tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700879
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800880 tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
881 tail + BEACON_TAIL_BUF_SIZE -
882 tailpos);
883
Dmitry Shmidt051af732013-10-22 13:52:46 -0700884 tailpos = hostapd_eid_bss_load(hapd, tailpos,
885 tail + BEACON_TAIL_BUF_SIZE - tailpos);
886
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700887#ifdef CONFIG_IEEE80211N
888 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
889 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
890#endif /* CONFIG_IEEE80211N */
891
892 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
893
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800894 /*
895 * TODO: Time Advertisement element should only be included in some
896 * DTIM Beacon frames.
897 */
898 tailpos = hostapd_eid_time_adv(hapd, tailpos);
899
900 tailpos = hostapd_eid_interworking(hapd, tailpos);
901 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
902 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800903 tailpos = hostapd_add_csa_elems(hapd, tailpos, tail,
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700904 &hapd->cs_c_off_beacon);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700905#ifdef CONFIG_IEEE80211AC
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800906 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
907 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos);
908 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
909 }
910 if (hapd->conf->vendor_vht)
911 tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700912#endif /* CONFIG_IEEE80211AC */
913
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700914 /* Wi-Fi Alliance WMM */
915 tailpos = hostapd_eid_wmm(hapd, tailpos);
916
917#ifdef CONFIG_WPS
918 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
919 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
920 wpabuf_len(hapd->wps_beacon_ie));
921 tailpos += wpabuf_len(hapd->wps_beacon_ie);
922 }
923#endif /* CONFIG_WPS */
924
925#ifdef CONFIG_P2P
926 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
927 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
928 wpabuf_len(hapd->p2p_beacon_ie));
929 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
930 }
931#endif /* CONFIG_P2P */
932#ifdef CONFIG_P2P_MANAGER
933 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
934 P2P_MANAGE)
935 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
936#endif /* CONFIG_P2P_MANAGER */
937
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700938#ifdef CONFIG_HS20
939 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800940 tailpos = hostapd_eid_osen(hapd, tailpos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700941#endif /* CONFIG_HS20 */
942
943 if (hapd->conf->vendor_elements) {
944 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
945 wpabuf_len(hapd->conf->vendor_elements));
946 tailpos += wpabuf_len(hapd->conf->vendor_elements);
947 }
948
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700949 tail_len = tailpos > tail ? tailpos - tail : 0;
950
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800951 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
952#endif /* NEED_AP_MLME */
953
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800954 os_memset(params, 0, sizeof(*params));
955 params->head = (u8 *) head;
956 params->head_len = head_len;
957 params->tail = tail;
958 params->tail_len = tail_len;
959 params->proberesp = resp;
960 params->proberesp_len = resp_len;
961 params->dtim_period = hapd->conf->dtim_period;
962 params->beacon_int = hapd->iconf->beacon_int;
963 params->basic_rates = hapd->iface->basic_rates;
964 params->ssid = hapd->conf->ssid.ssid;
965 params->ssid_len = hapd->conf->ssid.ssid_len;
Dmitry Shmidtb5d893b2014-06-04 15:28:27 -0700966 params->pairwise_ciphers = hapd->conf->wpa_pairwise |
967 hapd->conf->rsn_pairwise;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800968 params->group_cipher = hapd->conf->wpa_group;
969 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
970 params->auth_algs = hapd->conf->auth_algs;
971 params->wpa_version = hapd->conf->wpa;
972 params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800973 (hapd->conf->ieee802_1x &&
974 (hapd->conf->default_wep_key_len ||
975 hapd->conf->individual_wep_key_len));
976 switch (hapd->conf->ignore_broadcast_ssid) {
977 case 0:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800978 params->hide_ssid = NO_SSID_HIDING;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800979 break;
980 case 1:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800981 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800982 break;
983 case 2:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800984 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800985 break;
986 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800987 params->isolate = hapd->conf->isolate;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800988 params->smps_mode = hapd->iconf->ht_capab & HT_CAP_INFO_SMPS_MASK;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800989#ifdef NEED_AP_MLME
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800990 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800991 ERP_INFO_USE_PROTECTION);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800992 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800993 hapd->iconf->preamble == SHORT_PREAMBLE;
994 if (hapd->iface->current_mode &&
995 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800996 params->short_slot_time =
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800997 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
998 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800999 params->short_slot_time = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001000 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001001 params->ht_opmode = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001002 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001003 params->ht_opmode = hapd->iface->ht_op_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001004#endif /* NEED_AP_MLME */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001005 params->interworking = hapd->conf->interworking;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001006 if (hapd->conf->interworking &&
1007 !is_zero_ether_addr(hapd->conf->hessid))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001008 params->hessid = hapd->conf->hessid;
1009 params->access_network_type = hapd->conf->access_network_type;
1010 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001011#ifdef CONFIG_P2P
1012 params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
1013#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001014#ifdef CONFIG_HS20
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001015 params->disable_dgaf = hapd->conf->disable_dgaf;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001016 if (hapd->conf->osen) {
1017 params->privacy = 1;
1018 params->osen = 1;
1019 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001020#endif /* CONFIG_HS20 */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001021 return 0;
1022}
1023
1024
1025void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
1026{
1027 os_free(params->tail);
1028 params->tail = NULL;
1029 os_free(params->head);
1030 params->head = NULL;
1031 os_free(params->proberesp);
1032 params->proberesp = NULL;
1033}
1034
1035
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001036int ieee802_11_set_beacon(struct hostapd_data *hapd)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001037{
1038 struct wpa_driver_ap_params params;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001039 struct hostapd_freq_params freq;
1040 struct hostapd_iface *iface = hapd->iface;
1041 struct hostapd_config *iconf = iface->conf;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001042 struct wpabuf *beacon, *proberesp, *assocresp;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001043 int res, ret = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001044
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001045 if (hapd->csa_in_progress) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001046 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001047 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001048 }
1049
1050 hapd->beacon_set_done = 1;
1051
1052 if (ieee802_11_build_ap_params(hapd, &params) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001053 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001054
1055 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
1056 0)
1057 goto fail;
1058
1059 params.beacon_ies = beacon;
1060 params.proberesp_ies = proberesp;
1061 params.assocresp_ies = assocresp;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001062 params.reenable = hapd->reenable_beacon;
1063 hapd->reenable_beacon = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001064
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001065 if (iface->current_mode &&
1066 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
1067 iconf->channel, iconf->ieee80211n,
1068 iconf->ieee80211ac,
1069 iconf->secondary_channel,
1070 iconf->vht_oper_chwidth,
1071 iconf->vht_oper_centr_freq_seg0_idx,
1072 iconf->vht_oper_centr_freq_seg1_idx,
1073 iface->current_mode->vht_capab) == 0)
1074 params.freq = &freq;
1075
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001076 res = hostapd_drv_set_ap(hapd, &params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001077 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001078 if (res)
1079 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
1080 else
1081 ret = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001082fail:
1083 ieee802_11_free_ap_params(&params);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001084 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001085}
1086
1087
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001088int ieee802_11_set_beacons(struct hostapd_iface *iface)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001089{
1090 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001091 int ret = 0;
1092
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08001093 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001094 if (iface->bss[i]->started &&
1095 ieee802_11_set_beacon(iface->bss[i]) < 0)
1096 ret = -1;
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08001097 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001098
1099 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001100}
1101
Dmitry Shmidt04949592012-07-19 12:16:46 -07001102
1103/* only update beacons if started */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001104int ieee802_11_update_beacons(struct hostapd_iface *iface)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001105{
1106 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001107 int ret = 0;
1108
1109 for (i = 0; i < iface->num_bss; i++) {
1110 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
1111 ieee802_11_set_beacon(iface->bss[i]) < 0)
1112 ret = -1;
1113 }
1114
1115 return ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001116}
1117
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001118#endif /* CONFIG_NATIVE_WINDOWS */