blob: e06ce778d4dc705c87cbc442507f4fadb589786f [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 Shmidt8d520ff2011-05-09 14:06:53 -070018#include "wps/wps_defs.h"
19#include "p2p/p2p.h"
20#include "hostapd.h"
21#include "ieee802_11.h"
22#include "wpa_auth.h"
23#include "wmm.h"
24#include "ap_config.h"
25#include "sta_info.h"
26#include "p2p_hostapd.h"
27#include "ap_drv_ops.h"
28#include "beacon.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070029#include "hs20.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080030#include "dfs.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070031
32
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080033#ifdef NEED_AP_MLME
34
Dmitry Shmidt051af732013-10-22 13:52:46 -070035static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
36{
37#ifdef CONFIG_TESTING_OPTIONS
38 if (hapd->conf->bss_load_test_set) {
39 if (2 + 5 > len)
40 return eid;
41 *eid++ = WLAN_EID_BSS_LOAD;
42 *eid++ = 5;
43 os_memcpy(eid, hapd->conf->bss_load_test, 5);
44 eid += 5;
45 }
46#endif /* CONFIG_TESTING_OPTIONS */
47 return eid;
48}
49
50
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070051static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
52{
53 u8 erp = 0;
54
55 if (hapd->iface->current_mode == NULL ||
56 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
57 return 0;
58
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080059 if (hapd->iface->olbc)
60 erp |= ERP_INFO_USE_PROTECTION;
61 if (hapd->iface->num_sta_non_erp > 0) {
62 erp |= ERP_INFO_NON_ERP_PRESENT |
63 ERP_INFO_USE_PROTECTION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070064 }
65 if (hapd->iface->num_sta_no_short_preamble > 0 ||
66 hapd->iconf->preamble == LONG_PREAMBLE)
67 erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
68
69 return erp;
70}
71
72
73static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
74{
75 *eid++ = WLAN_EID_DS_PARAMS;
76 *eid++ = 1;
77 *eid++ = hapd->iconf->channel;
78 return eid;
79}
80
81
82static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
83{
84 if (hapd->iface->current_mode == NULL ||
85 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
86 return eid;
87
88 /* Set NonERP_present and use_protection bits if there
89 * are any associated NonERP stations. */
90 /* TODO: use_protection bit can be set to zero even if
91 * there are NonERP stations present. This optimization
92 * might be useful if NonERP stations are "quiet".
93 * See 802.11g/D6 E-1 for recommended practice.
94 * In addition, Non ERP present might be set, if AP detects Non ERP
95 * operation on other APs. */
96
97 /* Add ERP Information element */
98 *eid++ = WLAN_EID_ERP_INFO;
99 *eid++ = 1;
100 *eid++ = ieee802_11_erp_info(hapd);
101
102 return eid;
103}
104
105
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800106static u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid)
107{
108 u8 *pos = eid;
109 u8 local_pwr_constraint = 0;
110 int dfs;
111
112 if (hapd->iface->current_mode == NULL ||
113 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
114 return eid;
115
116 /*
117 * There is no DFS support and power constraint was not directly
118 * requested by config option.
119 */
120 if (!hapd->iconf->ieee80211h &&
121 hapd->iconf->local_pwr_constraint == -1)
122 return eid;
123
124 /* Check if DFS is required by regulatory. */
125 dfs = hostapd_is_dfs_required(hapd->iface);
126 if (dfs < 0) {
127 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
128 dfs);
129 dfs = 0;
130 }
131
132 if (dfs == 0 && hapd->iconf->local_pwr_constraint == -1)
133 return eid;
134
135 /*
136 * ieee80211h (DFS) is enabled so Power Constraint element shall
137 * be added when running on DFS channel whenever local_pwr_constraint
138 * is configured or not. In order to meet regulations when TPC is not
139 * implemented using a transmit power that is below the legal maximum
140 * (including any mitigation factor) should help. In this case,
141 * indicate 3 dB below maximum allowed transmit power.
142 */
143 if (hapd->iconf->local_pwr_constraint == -1)
144 local_pwr_constraint = 3;
145
146 /*
147 * A STA that is not an AP shall use a transmit power less than or
148 * equal to the local maximum transmit power level for the channel.
149 * The local maximum transmit power can be calculated from the formula:
150 * local max TX pwr = max TX pwr - local pwr constraint
151 * Where max TX pwr is maximum transmit power level specified for
152 * channel in Country element and local pwr constraint is specified
153 * for channel in this Power Constraint element.
154 */
155
156 /* Element ID */
157 *pos++ = WLAN_EID_PWR_CONSTRAINT;
158 /* Length */
159 *pos++ = 1;
160 /* Local Power Constraint */
161 if (local_pwr_constraint)
162 *pos++ = local_pwr_constraint;
163 else
164 *pos++ = hapd->iconf->local_pwr_constraint;
165
166 return pos;
167}
168
169
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700170static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
171 struct hostapd_channel_data *start,
172 struct hostapd_channel_data *prev)
173{
174 if (end - pos < 3)
175 return pos;
176
177 /* first channel number */
178 *pos++ = start->chan;
179 /* number of channels */
180 *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
181 /* maximum transmit power level */
182 *pos++ = start->max_tx_power;
183
184 return pos;
185}
186
187
188static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
189 int max_len)
190{
191 u8 *pos = eid;
192 u8 *end = eid + max_len;
193 int i;
194 struct hostapd_hw_modes *mode;
195 struct hostapd_channel_data *start, *prev;
196 int chan_spacing = 1;
197
198 if (!hapd->iconf->ieee80211d || max_len < 6 ||
199 hapd->iface->current_mode == NULL)
200 return eid;
201
202 *pos++ = WLAN_EID_COUNTRY;
203 pos++; /* length will be set later */
204 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
205 pos += 3;
206
207 mode = hapd->iface->current_mode;
208 if (mode->mode == HOSTAPD_MODE_IEEE80211A)
209 chan_spacing = 4;
210
211 start = prev = NULL;
212 for (i = 0; i < mode->num_channels; i++) {
213 struct hostapd_channel_data *chan = &mode->channels[i];
214 if (chan->flag & HOSTAPD_CHAN_DISABLED)
215 continue;
216 if (start && prev &&
217 prev->chan + chan_spacing == chan->chan &&
218 start->max_tx_power == chan->max_tx_power) {
219 prev = chan;
220 continue; /* can use same entry */
221 }
222
223 if (start) {
224 pos = hostapd_eid_country_add(pos, end, chan_spacing,
225 start, prev);
226 start = NULL;
227 }
228
229 /* Start new group */
230 start = prev = chan;
231 }
232
233 if (start) {
234 pos = hostapd_eid_country_add(pos, end, chan_spacing,
235 start, prev);
236 }
237
238 if ((pos - eid) & 1) {
239 if (end - pos < 1)
240 return eid;
241 *pos++ = 0; /* pad for 16-bit alignment */
242 }
243
244 eid[1] = (pos - eid) - 2;
245
246 return pos;
247}
248
249
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800250static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700251{
252 const u8 *ie;
253 size_t ielen;
254
255 ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
256 if (ie == NULL || ielen > len)
257 return eid;
258
259 os_memcpy(eid, ie, ielen);
260 return eid + ielen;
261}
262
263
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800264static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
265{
266 u8 chan;
267
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800268 if (!hapd->iface->cs_freq_params.freq)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800269 return eid;
270
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800271 if (ieee80211_freq_to_chan(hapd->iface->cs_freq_params.freq, &chan) ==
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800272 NUM_HOSTAPD_MODES)
273 return eid;
274
275 *eid++ = WLAN_EID_CHANNEL_SWITCH;
276 *eid++ = 3;
277 *eid++ = hapd->iface->cs_block_tx;
278 *eid++ = chan;
279 *eid++ = hapd->iface->cs_count;
280
281 return eid;
282}
283
284
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800285static u8 * hostapd_eid_secondary_channel(struct hostapd_data *hapd, u8 *eid)
286{
287 u8 sec_ch;
288
289 if (!hapd->iface->cs_freq_params.sec_channel_offset)
290 return eid;
291
292 if (hapd->iface->cs_freq_params.sec_channel_offset == -1)
293 sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW;
294 else if (hapd->iface->cs_freq_params.sec_channel_offset == 1)
295 sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE;
296 else
297 return eid;
298
299 *eid++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET;
300 *eid++ = 1;
301 *eid++ = sec_ch;
302
303 return eid;
304}
305
306
307static u8 * hostapd_add_csa_elems(struct hostapd_data *hapd, u8 *pos,
308 u8 *start, unsigned int *csa_counter_off)
309{
310 u8 *old_pos = pos;
311
312 if (!csa_counter_off)
313 return pos;
314
315 *csa_counter_off = 0;
316 pos = hostapd_eid_csa(hapd, pos);
317
318 if (pos != old_pos) {
319 /* save an offset to the counter - should be last byte */
320 *csa_counter_off = pos - start - 1;
321 pos = hostapd_eid_secondary_channel(hapd, pos);
322 }
323
324 return pos;
325}
326
327
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800328static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
329 struct sta_info *sta,
330 const struct ieee80211_mgmt *req,
331 int is_p2p, size_t *resp_len)
332{
333 struct ieee80211_mgmt *resp;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800334 u8 *pos, *epos;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800335 size_t buflen;
336
337#define MAX_PROBERESP_LEN 768
338 buflen = MAX_PROBERESP_LEN;
339#ifdef CONFIG_WPS
340 if (hapd->wps_probe_resp_ie)
341 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
342#endif /* CONFIG_WPS */
343#ifdef CONFIG_P2P
344 if (hapd->p2p_probe_resp_ie)
345 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
346#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700347 if (hapd->conf->vendor_elements)
348 buflen += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800349 resp = os_zalloc(buflen);
350 if (resp == NULL)
351 return NULL;
352
353 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
354
355 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
356 WLAN_FC_STYPE_PROBE_RESP);
357 if (req)
358 os_memcpy(resp->da, req->sa, ETH_ALEN);
359 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
360
361 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
362 resp->u.probe_resp.beacon_int =
363 host_to_le16(hapd->iconf->beacon_int);
364
365 /* hardware or low-level driver will setup seq_ctrl and timestamp */
366 resp->u.probe_resp.capab_info =
367 host_to_le16(hostapd_own_capab_info(hapd, sta, 1));
368
369 pos = resp->u.probe_resp.variable;
370 *pos++ = WLAN_EID_SSID;
371 *pos++ = hapd->conf->ssid.ssid_len;
372 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
373 pos += hapd->conf->ssid.ssid_len;
374
375 /* Supported rates */
376 pos = hostapd_eid_supp_rates(hapd, pos);
377
378 /* DS Params */
379 pos = hostapd_eid_ds_params(hapd, pos);
380
381 pos = hostapd_eid_country(hapd, pos, epos - pos);
382
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800383 /* Power Constraint element */
384 pos = hostapd_eid_pwr_constraint(hapd, pos);
385
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800386 /* ERP Information element */
387 pos = hostapd_eid_erp_info(hapd, pos);
388
389 /* Extended supported rates */
390 pos = hostapd_eid_ext_supp_rates(hapd, pos);
391
392 /* RSN, MDIE, WPA */
393 pos = hostapd_eid_wpa(hapd, pos, epos - pos);
394
Dmitry Shmidt051af732013-10-22 13:52:46 -0700395 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
396
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800397#ifdef CONFIG_IEEE80211N
398 pos = hostapd_eid_ht_capabilities(hapd, pos);
399 pos = hostapd_eid_ht_operation(hapd, pos);
400#endif /* CONFIG_IEEE80211N */
401
402 pos = hostapd_eid_ext_capab(hapd, pos);
403
404 pos = hostapd_eid_time_adv(hapd, pos);
405 pos = hostapd_eid_time_zone(hapd, pos);
406
407 pos = hostapd_eid_interworking(hapd, pos);
408 pos = hostapd_eid_adv_proto(hapd, pos);
409 pos = hostapd_eid_roaming_consortium(hapd, pos);
410
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800411 pos = hostapd_add_csa_elems(hapd, pos, (u8 *)resp,
412 &hapd->iface->cs_c_off_proberesp);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700413#ifdef CONFIG_IEEE80211AC
414 pos = hostapd_eid_vht_capabilities(hapd, pos);
415 pos = hostapd_eid_vht_operation(hapd, pos);
416#endif /* CONFIG_IEEE80211AC */
417
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800418 /* Wi-Fi Alliance WMM */
419 pos = hostapd_eid_wmm(hapd, pos);
420
421#ifdef CONFIG_WPS
422 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
423 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
424 wpabuf_len(hapd->wps_probe_resp_ie));
425 pos += wpabuf_len(hapd->wps_probe_resp_ie);
426 }
427#endif /* CONFIG_WPS */
428
429#ifdef CONFIG_P2P
430 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
431 hapd->p2p_probe_resp_ie) {
432 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
433 wpabuf_len(hapd->p2p_probe_resp_ie));
434 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
435 }
436#endif /* CONFIG_P2P */
437#ifdef CONFIG_P2P_MANAGER
438 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
439 P2P_MANAGE)
440 pos = hostapd_eid_p2p_manage(hapd, pos);
441#endif /* CONFIG_P2P_MANAGER */
442
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700443#ifdef CONFIG_HS20
444 pos = hostapd_eid_hs20_indication(hapd, pos);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800445 pos = hostapd_eid_osen(hapd, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700446#endif /* CONFIG_HS20 */
447
448 if (hapd->conf->vendor_elements) {
449 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
450 wpabuf_len(hapd->conf->vendor_elements));
451 pos += wpabuf_len(hapd->conf->vendor_elements);
452 }
453
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800454 *resp_len = pos - (u8 *) resp;
455 return (u8 *) resp;
456}
457
458
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800459enum ssid_match_result {
460 NO_SSID_MATCH,
461 EXACT_SSID_MATCH,
462 WILDCARD_SSID_MATCH
463};
464
465static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
466 const u8 *ssid, size_t ssid_len,
467 const u8 *ssid_list,
468 size_t ssid_list_len)
469{
470 const u8 *pos, *end;
471 int wildcard = 0;
472
473 if (ssid_len == 0)
474 wildcard = 1;
475 if (ssid_len == hapd->conf->ssid.ssid_len &&
476 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
477 return EXACT_SSID_MATCH;
478
479 if (ssid_list == NULL)
480 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
481
482 pos = ssid_list;
483 end = ssid_list + ssid_list_len;
484 while (pos + 1 <= end) {
485 if (pos + 2 + pos[1] > end)
486 break;
487 if (pos[1] == 0)
488 wildcard = 1;
489 if (pos[1] == hapd->conf->ssid.ssid_len &&
490 os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0)
491 return EXACT_SSID_MATCH;
492 pos += 2 + pos[1];
493 }
494
495 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
496}
497
498
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700499void handle_probe_req(struct hostapd_data *hapd,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700500 const struct ieee80211_mgmt *mgmt, size_t len,
501 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700502{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800503 u8 *resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700504 struct ieee802_11_elems elems;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700505 const u8 *ie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800506 size_t ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700507 struct sta_info *sta = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800508 size_t i, resp_len;
509 int noack;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800510 enum ssid_match_result res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700511
512 ie = mgmt->u.probe_req.variable;
513 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
514 return;
515 ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
516
517 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
518 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800519 mgmt->sa, mgmt->da, mgmt->bssid,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700520 ie, ie_len, ssi_signal) > 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700521 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800522
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700523 if (!hapd->iconf->send_probe_response)
524 return;
525
526 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
527 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
528 MAC2STR(mgmt->sa));
529 return;
530 }
531
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700532 if ((!elems.ssid || !elems.supp_rates)) {
533 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
534 "without SSID or supported rates element",
535 MAC2STR(mgmt->sa));
536 return;
537 }
538
539#ifdef CONFIG_P2P
540 if (hapd->p2p && elems.wps_ie) {
541 struct wpabuf *wps;
542 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
543 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
544 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
545 "due to mismatch with Requested Device "
546 "Type");
547 wpabuf_free(wps);
548 return;
549 }
550 wpabuf_free(wps);
551 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800552
553 if (hapd->p2p && elems.p2p) {
554 struct wpabuf *p2p;
555 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
556 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
557 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
558 "due to mismatch with Device ID");
559 wpabuf_free(p2p);
560 return;
561 }
562 wpabuf_free(p2p);
563 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700564#endif /* CONFIG_P2P */
565
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800566 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
567 elems.ssid_list_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700568 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
569 "broadcast SSID ignored", MAC2STR(mgmt->sa));
570 return;
571 }
572
573 sta = ap_get_sta(hapd, mgmt->sa);
574
575#ifdef CONFIG_P2P
576 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
577 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
578 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
579 P2P_WILDCARD_SSID_LEN) == 0) {
580 /* Process P2P Wildcard SSID like Wildcard SSID */
581 elems.ssid_len = 0;
582 }
583#endif /* CONFIG_P2P */
584
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800585 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
586 elems.ssid_list, elems.ssid_list_len);
587 if (res != NO_SSID_MATCH) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700588 if (sta)
589 sta->ssid_probe = &hapd->conf->ssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800590 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700591 if (!(mgmt->da[0] & 0x01)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700592 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800593 " for foreign SSID '%s' (DA " MACSTR ")%s",
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800594 MAC2STR(mgmt->sa),
595 wpa_ssid_txt(elems.ssid, elems.ssid_len),
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800596 MAC2STR(mgmt->da),
597 elems.ssid_list ? " (SSID list)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700598 }
599 return;
600 }
601
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800602#ifdef CONFIG_INTERWORKING
603 if (elems.interworking && elems.interworking_len >= 1) {
604 u8 ant = elems.interworking[0] & 0x0f;
605 if (ant != INTERWORKING_ANT_WILDCARD &&
606 ant != hapd->conf->access_network_type) {
607 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
608 " for mismatching ANT %u ignored",
609 MAC2STR(mgmt->sa), ant);
610 return;
611 }
612 }
613
614 if (elems.interworking &&
615 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
616 const u8 *hessid;
617 if (elems.interworking_len == 7)
618 hessid = elems.interworking + 1;
619 else
620 hessid = elems.interworking + 1 + 2;
621 if (!is_broadcast_ether_addr(hessid) &&
622 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
623 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
624 " for mismatching HESSID " MACSTR
625 " ignored",
626 MAC2STR(mgmt->sa), MAC2STR(hessid));
627 return;
628 }
629 }
630#endif /* CONFIG_INTERWORKING */
631
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700632#ifdef CONFIG_P2P
633 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
634 supp_rates_11b_only(&elems)) {
635 /* Indicates support for 11b rates only */
636 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
637 MACSTR " with only 802.11b rates",
638 MAC2STR(mgmt->sa));
639 return;
640 }
641#endif /* CONFIG_P2P */
642
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700643 /* TODO: verify that supp_rates contains at least one matching rate
644 * with AP configuration */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800645
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700646#ifdef CONFIG_TESTING_OPTIONS
647 if (hapd->iconf->ignore_probe_probability > 0.0d &&
648 drand48() < hapd->iconf->ignore_probe_probability) {
649 wpa_printf(MSG_INFO,
650 "TESTING: ignoring probe request from " MACSTR,
651 MAC2STR(mgmt->sa));
652 return;
653 }
654#endif /* CONFIG_TESTING_OPTIONS */
655
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800656 resp = hostapd_gen_probe_resp(hapd, sta, mgmt, elems.p2p != NULL,
657 &resp_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700658 if (resp == NULL)
659 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700660
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800661 /*
662 * If this is a broadcast probe request, apply no ack policy to avoid
663 * excessive retries.
664 */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800665 noack = !!(res == WILDCARD_SSID_MATCH &&
666 is_broadcast_ether_addr(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700667
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800668 if (hostapd_drv_send_mlme(hapd, resp, resp_len, noack) < 0)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800669 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700670
671 os_free(resp);
672
673 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
674 "SSID", MAC2STR(mgmt->sa),
675 elems.ssid_len == 0 ? "broadcast" : "our");
676}
677
678
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800679static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
680 size_t *resp_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700681{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800682 /* check probe response offloading caps and print warnings */
683 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
684 return NULL;
685
686#ifdef CONFIG_WPS
687 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
688 (!(hapd->iface->probe_resp_offloads &
689 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
690 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
691 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
692 "Probe Response while not supporting this");
693#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700694
695#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800696 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
697 !(hapd->iface->probe_resp_offloads &
698 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
699 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
700 "Probe Response while not supporting this");
701#endif /* CONFIG_P2P */
702
703 if (hapd->conf->interworking &&
704 !(hapd->iface->probe_resp_offloads &
705 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
706 wpa_printf(MSG_WARNING, "Device is trying to offload "
707 "Interworking Probe Response while not supporting "
708 "this");
709
710 /* Generate a Probe Response template for the non-P2P case */
711 return hostapd_gen_probe_resp(hapd, NULL, NULL, 0, resp_len);
712}
713
714#endif /* NEED_AP_MLME */
715
716
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800717int ieee802_11_build_ap_params(struct hostapd_data *hapd,
718 struct wpa_driver_ap_params *params)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800719{
720 struct ieee80211_mgmt *head = NULL;
721 u8 *tail = NULL;
722 size_t head_len = 0, tail_len = 0;
723 u8 *resp = NULL;
724 size_t resp_len = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800725#ifdef NEED_AP_MLME
726 u16 capab_info;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800727 u8 *pos, *tailpos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700728
729#define BEACON_HEAD_BUF_SIZE 256
730#define BEACON_TAIL_BUF_SIZE 512
731 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
732 tail_len = BEACON_TAIL_BUF_SIZE;
733#ifdef CONFIG_WPS
734 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
735 tail_len += wpabuf_len(hapd->wps_beacon_ie);
736#endif /* CONFIG_WPS */
737#ifdef CONFIG_P2P
738 if (hapd->p2p_beacon_ie)
739 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
740#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700741 if (hapd->conf->vendor_elements)
742 tail_len += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700743 tailpos = tail = os_malloc(tail_len);
744 if (head == NULL || tail == NULL) {
745 wpa_printf(MSG_ERROR, "Failed to set beacon data");
746 os_free(head);
747 os_free(tail);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800748 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700749 }
750
751 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
752 WLAN_FC_STYPE_BEACON);
753 head->duration = host_to_le16(0);
754 os_memset(head->da, 0xff, ETH_ALEN);
755
756 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
757 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
758 head->u.beacon.beacon_int =
759 host_to_le16(hapd->iconf->beacon_int);
760
761 /* hardware or low-level driver will setup seq_ctrl and timestamp */
762 capab_info = hostapd_own_capab_info(hapd, NULL, 0);
763 head->u.beacon.capab_info = host_to_le16(capab_info);
764 pos = &head->u.beacon.variable[0];
765
766 /* SSID */
767 *pos++ = WLAN_EID_SSID;
768 if (hapd->conf->ignore_broadcast_ssid == 2) {
769 /* clear the data, but keep the correct length of the SSID */
770 *pos++ = hapd->conf->ssid.ssid_len;
771 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
772 pos += hapd->conf->ssid.ssid_len;
773 } else if (hapd->conf->ignore_broadcast_ssid) {
774 *pos++ = 0; /* empty SSID */
775 } else {
776 *pos++ = hapd->conf->ssid.ssid_len;
777 os_memcpy(pos, hapd->conf->ssid.ssid,
778 hapd->conf->ssid.ssid_len);
779 pos += hapd->conf->ssid.ssid_len;
780 }
781
782 /* Supported rates */
783 pos = hostapd_eid_supp_rates(hapd, pos);
784
785 /* DS Params */
786 pos = hostapd_eid_ds_params(hapd, pos);
787
788 head_len = pos - (u8 *) head;
789
790 tailpos = hostapd_eid_country(hapd, tailpos,
791 tail + BEACON_TAIL_BUF_SIZE - tailpos);
792
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800793 /* Power Constraint element */
794 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
795
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700796 /* ERP Information element */
797 tailpos = hostapd_eid_erp_info(hapd, tailpos);
798
799 /* Extended supported rates */
800 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
801
802 /* RSN, MDIE, WPA */
803 tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800804 tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700805
Dmitry Shmidt051af732013-10-22 13:52:46 -0700806 tailpos = hostapd_eid_bss_load(hapd, tailpos,
807 tail + BEACON_TAIL_BUF_SIZE - tailpos);
808
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700809#ifdef CONFIG_IEEE80211N
810 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
811 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
812#endif /* CONFIG_IEEE80211N */
813
814 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
815
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800816 /*
817 * TODO: Time Advertisement element should only be included in some
818 * DTIM Beacon frames.
819 */
820 tailpos = hostapd_eid_time_adv(hapd, tailpos);
821
822 tailpos = hostapd_eid_interworking(hapd, tailpos);
823 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
824 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800825 tailpos = hostapd_add_csa_elems(hapd, tailpos, tail,
826 &hapd->iface->cs_c_off_beacon);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700827#ifdef CONFIG_IEEE80211AC
828 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos);
829 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
830#endif /* CONFIG_IEEE80211AC */
831
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700832 /* Wi-Fi Alliance WMM */
833 tailpos = hostapd_eid_wmm(hapd, tailpos);
834
835#ifdef CONFIG_WPS
836 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
837 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
838 wpabuf_len(hapd->wps_beacon_ie));
839 tailpos += wpabuf_len(hapd->wps_beacon_ie);
840 }
841#endif /* CONFIG_WPS */
842
843#ifdef CONFIG_P2P
844 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
845 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
846 wpabuf_len(hapd->p2p_beacon_ie));
847 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
848 }
849#endif /* CONFIG_P2P */
850#ifdef CONFIG_P2P_MANAGER
851 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
852 P2P_MANAGE)
853 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
854#endif /* CONFIG_P2P_MANAGER */
855
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700856#ifdef CONFIG_HS20
857 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800858 tailpos = hostapd_eid_osen(hapd, tailpos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700859#endif /* CONFIG_HS20 */
860
861 if (hapd->conf->vendor_elements) {
862 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
863 wpabuf_len(hapd->conf->vendor_elements));
864 tailpos += wpabuf_len(hapd->conf->vendor_elements);
865 }
866
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700867 tail_len = tailpos > tail ? tailpos - tail : 0;
868
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800869 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
870#endif /* NEED_AP_MLME */
871
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800872 os_memset(params, 0, sizeof(*params));
873 params->head = (u8 *) head;
874 params->head_len = head_len;
875 params->tail = tail;
876 params->tail_len = tail_len;
877 params->proberesp = resp;
878 params->proberesp_len = resp_len;
879 params->dtim_period = hapd->conf->dtim_period;
880 params->beacon_int = hapd->iconf->beacon_int;
881 params->basic_rates = hapd->iface->basic_rates;
882 params->ssid = hapd->conf->ssid.ssid;
883 params->ssid_len = hapd->conf->ssid.ssid_len;
884 params->pairwise_ciphers = hapd->conf->rsn_pairwise ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800885 hapd->conf->rsn_pairwise : hapd->conf->wpa_pairwise;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800886 params->group_cipher = hapd->conf->wpa_group;
887 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
888 params->auth_algs = hapd->conf->auth_algs;
889 params->wpa_version = hapd->conf->wpa;
890 params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800891 (hapd->conf->ieee802_1x &&
892 (hapd->conf->default_wep_key_len ||
893 hapd->conf->individual_wep_key_len));
894 switch (hapd->conf->ignore_broadcast_ssid) {
895 case 0:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800896 params->hide_ssid = NO_SSID_HIDING;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800897 break;
898 case 1:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800899 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800900 break;
901 case 2:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800902 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800903 break;
904 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800905 params->isolate = hapd->conf->isolate;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800906#ifdef NEED_AP_MLME
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800907 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800908 ERP_INFO_USE_PROTECTION);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800909 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800910 hapd->iconf->preamble == SHORT_PREAMBLE;
911 if (hapd->iface->current_mode &&
912 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800913 params->short_slot_time =
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800914 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
915 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800916 params->short_slot_time = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800917 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800918 params->ht_opmode = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800919 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800920 params->ht_opmode = hapd->iface->ht_op_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800921#endif /* NEED_AP_MLME */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800922 params->interworking = hapd->conf->interworking;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800923 if (hapd->conf->interworking &&
924 !is_zero_ether_addr(hapd->conf->hessid))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800925 params->hessid = hapd->conf->hessid;
926 params->access_network_type = hapd->conf->access_network_type;
927 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700928#ifdef CONFIG_HS20
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800929 params->disable_dgaf = hapd->conf->disable_dgaf;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800930 if (hapd->conf->osen) {
931 params->privacy = 1;
932 params->osen = 1;
933 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700934#endif /* CONFIG_HS20 */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800935 return 0;
936}
937
938
939void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
940{
941 os_free(params->tail);
942 params->tail = NULL;
943 os_free(params->head);
944 params->head = NULL;
945 os_free(params->proberesp);
946 params->proberesp = NULL;
947}
948
949
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800950int ieee802_11_set_beacon(struct hostapd_data *hapd)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800951{
952 struct wpa_driver_ap_params params;
953 struct wpabuf *beacon, *proberesp, *assocresp;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800954 int res, ret = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800955
956 if (hapd->iface->csa_in_progress) {
957 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800958 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800959 }
960
961 hapd->beacon_set_done = 1;
962
963 if (ieee802_11_build_ap_params(hapd, &params) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800964 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800965
966 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
967 0)
968 goto fail;
969
970 params.beacon_ies = beacon;
971 params.proberesp_ies = proberesp;
972 params.assocresp_ies = assocresp;
973
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800974 res = hostapd_drv_set_ap(hapd, &params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800975 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800976 if (res)
977 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
978 else
979 ret = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800980fail:
981 ieee802_11_free_ap_params(&params);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800982 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700983}
984
985
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800986int ieee802_11_set_beacons(struct hostapd_iface *iface)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700987{
988 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800989 int ret = 0;
990
Dmitry Shmidt292b0c32013-11-22 12:54:42 -0800991 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800992 if (iface->bss[i]->started &&
993 ieee802_11_set_beacon(iface->bss[i]) < 0)
994 ret = -1;
Dmitry Shmidt292b0c32013-11-22 12:54:42 -0800995 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800996
997 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700998}
999
Dmitry Shmidt04949592012-07-19 12:16:46 -07001000
1001/* only update beacons if started */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001002int ieee802_11_update_beacons(struct hostapd_iface *iface)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001003{
1004 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001005 int ret = 0;
1006
1007 for (i = 0; i < iface->num_bss; i++) {
1008 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
1009 ieee802_11_set_beacon(iface->bss[i]) < 0)
1010 ret = -1;
1011 }
1012
1013 return ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001014}
1015
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001016#endif /* CONFIG_NATIVE_WINDOWS */