blob: 4a8703accec39f8f33cfbaa3d287e54fc4594057 [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 Shmidt6c0da2b2015-01-05 13:08:17 -080035static u8 * hostapd_eid_rm_enabled_capab(struct hostapd_data *hapd, u8 *eid,
36 size_t len)
37{
38 if (!hapd->conf->radio_measurements || len < 2 + 4)
39 return eid;
40
41 *eid++ = WLAN_EID_RRM_ENABLED_CAPABILITIES;
42 *eid++ = 5;
43 *eid++ = (hapd->conf->radio_measurements & BIT(0)) ?
44 WLAN_RRM_CAPS_NEIGHBOR_REPORT : 0x00;
45 *eid++ = 0x00;
46 *eid++ = 0x00;
47 *eid++ = 0x00;
48 *eid++ = 0x00;
49 return eid;
50}
51
52
Dmitry Shmidt051af732013-10-22 13:52:46 -070053static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
54{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080055 if (len < 2 + 5)
56 return eid;
57
Dmitry Shmidt051af732013-10-22 13:52:46 -070058#ifdef CONFIG_TESTING_OPTIONS
59 if (hapd->conf->bss_load_test_set) {
Dmitry Shmidt051af732013-10-22 13:52:46 -070060 *eid++ = WLAN_EID_BSS_LOAD;
61 *eid++ = 5;
62 os_memcpy(eid, hapd->conf->bss_load_test, 5);
63 eid += 5;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080064 return eid;
Dmitry Shmidt051af732013-10-22 13:52:46 -070065 }
66#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080067 if (hapd->conf->bss_load_update_period) {
68 *eid++ = WLAN_EID_BSS_LOAD;
69 *eid++ = 5;
70 WPA_PUT_LE16(eid, hapd->num_sta);
71 eid += 2;
72 *eid++ = hapd->iface->channel_utilization;
73 WPA_PUT_LE16(eid, 0); /* no available admission capabity */
74 eid += 2;
75 }
Dmitry Shmidt051af732013-10-22 13:52:46 -070076 return eid;
77}
78
79
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070080static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
81{
82 u8 erp = 0;
83
84 if (hapd->iface->current_mode == NULL ||
85 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
86 return 0;
87
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080088 if (hapd->iface->olbc)
89 erp |= ERP_INFO_USE_PROTECTION;
90 if (hapd->iface->num_sta_non_erp > 0) {
91 erp |= ERP_INFO_NON_ERP_PRESENT |
92 ERP_INFO_USE_PROTECTION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070093 }
94 if (hapd->iface->num_sta_no_short_preamble > 0 ||
95 hapd->iconf->preamble == LONG_PREAMBLE)
96 erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
97
98 return erp;
99}
100
101
102static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
103{
104 *eid++ = WLAN_EID_DS_PARAMS;
105 *eid++ = 1;
106 *eid++ = hapd->iconf->channel;
107 return eid;
108}
109
110
111static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
112{
113 if (hapd->iface->current_mode == NULL ||
114 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
115 return eid;
116
117 /* Set NonERP_present and use_protection bits if there
118 * are any associated NonERP stations. */
119 /* TODO: use_protection bit can be set to zero even if
120 * there are NonERP stations present. This optimization
121 * might be useful if NonERP stations are "quiet".
122 * See 802.11g/D6 E-1 for recommended practice.
123 * In addition, Non ERP present might be set, if AP detects Non ERP
124 * operation on other APs. */
125
126 /* Add ERP Information element */
127 *eid++ = WLAN_EID_ERP_INFO;
128 *eid++ = 1;
129 *eid++ = ieee802_11_erp_info(hapd);
130
131 return eid;
132}
133
134
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800135static u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid)
136{
137 u8 *pos = eid;
138 u8 local_pwr_constraint = 0;
139 int dfs;
140
141 if (hapd->iface->current_mode == NULL ||
142 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
143 return eid;
144
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700145 /* Let host drivers add this IE if DFS support is offloaded */
146 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)
147 return eid;
148
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800149 /*
150 * There is no DFS support and power constraint was not directly
151 * requested by config option.
152 */
153 if (!hapd->iconf->ieee80211h &&
154 hapd->iconf->local_pwr_constraint == -1)
155 return eid;
156
157 /* Check if DFS is required by regulatory. */
158 dfs = hostapd_is_dfs_required(hapd->iface);
159 if (dfs < 0) {
160 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
161 dfs);
162 dfs = 0;
163 }
164
165 if (dfs == 0 && hapd->iconf->local_pwr_constraint == -1)
166 return eid;
167
168 /*
169 * ieee80211h (DFS) is enabled so Power Constraint element shall
170 * be added when running on DFS channel whenever local_pwr_constraint
171 * is configured or not. In order to meet regulations when TPC is not
172 * implemented using a transmit power that is below the legal maximum
173 * (including any mitigation factor) should help. In this case,
174 * indicate 3 dB below maximum allowed transmit power.
175 */
176 if (hapd->iconf->local_pwr_constraint == -1)
177 local_pwr_constraint = 3;
178
179 /*
180 * A STA that is not an AP shall use a transmit power less than or
181 * equal to the local maximum transmit power level for the channel.
182 * The local maximum transmit power can be calculated from the formula:
183 * local max TX pwr = max TX pwr - local pwr constraint
184 * Where max TX pwr is maximum transmit power level specified for
185 * channel in Country element and local pwr constraint is specified
186 * for channel in this Power Constraint element.
187 */
188
189 /* Element ID */
190 *pos++ = WLAN_EID_PWR_CONSTRAINT;
191 /* Length */
192 *pos++ = 1;
193 /* Local Power Constraint */
194 if (local_pwr_constraint)
195 *pos++ = local_pwr_constraint;
196 else
197 *pos++ = hapd->iconf->local_pwr_constraint;
198
199 return pos;
200}
201
202
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700203static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
204 struct hostapd_channel_data *start,
205 struct hostapd_channel_data *prev)
206{
207 if (end - pos < 3)
208 return pos;
209
210 /* first channel number */
211 *pos++ = start->chan;
212 /* number of channels */
213 *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
214 /* maximum transmit power level */
215 *pos++ = start->max_tx_power;
216
217 return pos;
218}
219
220
221static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
222 int max_len)
223{
224 u8 *pos = eid;
225 u8 *end = eid + max_len;
226 int i;
227 struct hostapd_hw_modes *mode;
228 struct hostapd_channel_data *start, *prev;
229 int chan_spacing = 1;
230
231 if (!hapd->iconf->ieee80211d || max_len < 6 ||
232 hapd->iface->current_mode == NULL)
233 return eid;
234
235 *pos++ = WLAN_EID_COUNTRY;
236 pos++; /* length will be set later */
237 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
238 pos += 3;
239
240 mode = hapd->iface->current_mode;
241 if (mode->mode == HOSTAPD_MODE_IEEE80211A)
242 chan_spacing = 4;
243
244 start = prev = NULL;
245 for (i = 0; i < mode->num_channels; i++) {
246 struct hostapd_channel_data *chan = &mode->channels[i];
247 if (chan->flag & HOSTAPD_CHAN_DISABLED)
248 continue;
249 if (start && prev &&
250 prev->chan + chan_spacing == chan->chan &&
251 start->max_tx_power == chan->max_tx_power) {
252 prev = chan;
253 continue; /* can use same entry */
254 }
255
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -0700256 if (start && prev) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700257 pos = hostapd_eid_country_add(pos, end, chan_spacing,
258 start, prev);
259 start = NULL;
260 }
261
262 /* Start new group */
263 start = prev = chan;
264 }
265
266 if (start) {
267 pos = hostapd_eid_country_add(pos, end, chan_spacing,
268 start, prev);
269 }
270
271 if ((pos - eid) & 1) {
272 if (end - pos < 1)
273 return eid;
274 *pos++ = 0; /* pad for 16-bit alignment */
275 }
276
277 eid[1] = (pos - eid) - 2;
278
279 return pos;
280}
281
282
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800283static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700284{
285 const u8 *ie;
286 size_t ielen;
287
288 ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
289 if (ie == NULL || ielen > len)
290 return eid;
291
292 os_memcpy(eid, ie, ielen);
293 return eid + ielen;
294}
295
296
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800297static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
298{
299 u8 chan;
300
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700301 if (!hapd->cs_freq_params.freq)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800302 return eid;
303
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700304 if (ieee80211_freq_to_chan(hapd->cs_freq_params.freq, &chan) ==
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800305 NUM_HOSTAPD_MODES)
306 return eid;
307
308 *eid++ = WLAN_EID_CHANNEL_SWITCH;
309 *eid++ = 3;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700310 *eid++ = hapd->cs_block_tx;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800311 *eid++ = chan;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700312 *eid++ = hapd->cs_count;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800313
314 return eid;
315}
316
317
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800318static u8 * hostapd_eid_secondary_channel(struct hostapd_data *hapd, u8 *eid)
319{
320 u8 sec_ch;
321
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700322 if (!hapd->cs_freq_params.sec_channel_offset)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800323 return eid;
324
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700325 if (hapd->cs_freq_params.sec_channel_offset == -1)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800326 sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700327 else if (hapd->cs_freq_params.sec_channel_offset == 1)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800328 sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE;
329 else
330 return eid;
331
332 *eid++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET;
333 *eid++ = 1;
334 *eid++ = sec_ch;
335
336 return eid;
337}
338
339
340static u8 * hostapd_add_csa_elems(struct hostapd_data *hapd, u8 *pos,
341 u8 *start, unsigned int *csa_counter_off)
342{
343 u8 *old_pos = pos;
344
345 if (!csa_counter_off)
346 return pos;
347
348 *csa_counter_off = 0;
349 pos = hostapd_eid_csa(hapd, pos);
350
351 if (pos != old_pos) {
352 /* save an offset to the counter - should be last byte */
353 *csa_counter_off = pos - start - 1;
354 pos = hostapd_eid_secondary_channel(hapd, pos);
355 }
356
357 return pos;
358}
359
360
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800361static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
362 struct sta_info *sta,
363 const struct ieee80211_mgmt *req,
364 int is_p2p, size_t *resp_len)
365{
366 struct ieee80211_mgmt *resp;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800367 u8 *pos, *epos;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800368 size_t buflen;
369
370#define MAX_PROBERESP_LEN 768
371 buflen = MAX_PROBERESP_LEN;
372#ifdef CONFIG_WPS
373 if (hapd->wps_probe_resp_ie)
374 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
375#endif /* CONFIG_WPS */
376#ifdef CONFIG_P2P
377 if (hapd->p2p_probe_resp_ie)
378 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
379#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700380 if (hapd->conf->vendor_elements)
381 buflen += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800382 resp = os_zalloc(buflen);
383 if (resp == NULL)
384 return NULL;
385
386 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
387
388 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
389 WLAN_FC_STYPE_PROBE_RESP);
390 if (req)
391 os_memcpy(resp->da, req->sa, ETH_ALEN);
392 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
393
394 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
395 resp->u.probe_resp.beacon_int =
396 host_to_le16(hapd->iconf->beacon_int);
397
398 /* hardware or low-level driver will setup seq_ctrl and timestamp */
399 resp->u.probe_resp.capab_info =
400 host_to_le16(hostapd_own_capab_info(hapd, sta, 1));
401
402 pos = resp->u.probe_resp.variable;
403 *pos++ = WLAN_EID_SSID;
404 *pos++ = hapd->conf->ssid.ssid_len;
405 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
406 pos += hapd->conf->ssid.ssid_len;
407
408 /* Supported rates */
409 pos = hostapd_eid_supp_rates(hapd, pos);
410
411 /* DS Params */
412 pos = hostapd_eid_ds_params(hapd, pos);
413
414 pos = hostapd_eid_country(hapd, pos, epos - pos);
415
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800416 /* Power Constraint element */
417 pos = hostapd_eid_pwr_constraint(hapd, pos);
418
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800419 /* ERP Information element */
420 pos = hostapd_eid_erp_info(hapd, pos);
421
422 /* Extended supported rates */
423 pos = hostapd_eid_ext_supp_rates(hapd, pos);
424
425 /* RSN, MDIE, WPA */
426 pos = hostapd_eid_wpa(hapd, pos, epos - pos);
427
Dmitry Shmidt051af732013-10-22 13:52:46 -0700428 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
429
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800430 pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
431
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800432#ifdef CONFIG_IEEE80211N
433 pos = hostapd_eid_ht_capabilities(hapd, pos);
434 pos = hostapd_eid_ht_operation(hapd, pos);
435#endif /* CONFIG_IEEE80211N */
436
437 pos = hostapd_eid_ext_capab(hapd, pos);
438
439 pos = hostapd_eid_time_adv(hapd, pos);
440 pos = hostapd_eid_time_zone(hapd, pos);
441
442 pos = hostapd_eid_interworking(hapd, pos);
443 pos = hostapd_eid_adv_proto(hapd, pos);
444 pos = hostapd_eid_roaming_consortium(hapd, pos);
445
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800446 pos = hostapd_add_csa_elems(hapd, pos, (u8 *)resp,
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700447 &hapd->cs_c_off_proberesp);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700448#ifdef CONFIG_IEEE80211AC
449 pos = hostapd_eid_vht_capabilities(hapd, pos);
450 pos = hostapd_eid_vht_operation(hapd, pos);
451#endif /* CONFIG_IEEE80211AC */
452
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800453 /* Wi-Fi Alliance WMM */
454 pos = hostapd_eid_wmm(hapd, pos);
455
456#ifdef CONFIG_WPS
457 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
458 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
459 wpabuf_len(hapd->wps_probe_resp_ie));
460 pos += wpabuf_len(hapd->wps_probe_resp_ie);
461 }
462#endif /* CONFIG_WPS */
463
464#ifdef CONFIG_P2P
465 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
466 hapd->p2p_probe_resp_ie) {
467 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
468 wpabuf_len(hapd->p2p_probe_resp_ie));
469 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
470 }
471#endif /* CONFIG_P2P */
472#ifdef CONFIG_P2P_MANAGER
473 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
474 P2P_MANAGE)
475 pos = hostapd_eid_p2p_manage(hapd, pos);
476#endif /* CONFIG_P2P_MANAGER */
477
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700478#ifdef CONFIG_HS20
479 pos = hostapd_eid_hs20_indication(hapd, pos);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800480 pos = hostapd_eid_osen(hapd, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700481#endif /* CONFIG_HS20 */
482
483 if (hapd->conf->vendor_elements) {
484 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
485 wpabuf_len(hapd->conf->vendor_elements));
486 pos += wpabuf_len(hapd->conf->vendor_elements);
487 }
488
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800489 *resp_len = pos - (u8 *) resp;
490 return (u8 *) resp;
491}
492
493
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800494enum ssid_match_result {
495 NO_SSID_MATCH,
496 EXACT_SSID_MATCH,
497 WILDCARD_SSID_MATCH
498};
499
500static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
501 const u8 *ssid, size_t ssid_len,
502 const u8 *ssid_list,
503 size_t ssid_list_len)
504{
505 const u8 *pos, *end;
506 int wildcard = 0;
507
508 if (ssid_len == 0)
509 wildcard = 1;
510 if (ssid_len == hapd->conf->ssid.ssid_len &&
511 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
512 return EXACT_SSID_MATCH;
513
514 if (ssid_list == NULL)
515 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
516
517 pos = ssid_list;
518 end = ssid_list + ssid_list_len;
519 while (pos + 1 <= end) {
520 if (pos + 2 + pos[1] > end)
521 break;
522 if (pos[1] == 0)
523 wildcard = 1;
524 if (pos[1] == hapd->conf->ssid.ssid_len &&
525 os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0)
526 return EXACT_SSID_MATCH;
527 pos += 2 + pos[1];
528 }
529
530 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
531}
532
533
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700534void handle_probe_req(struct hostapd_data *hapd,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700535 const struct ieee80211_mgmt *mgmt, size_t len,
536 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700537{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800538 u8 *resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700539 struct ieee802_11_elems elems;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700540 const u8 *ie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800541 size_t ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700542 struct sta_info *sta = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800543 size_t i, resp_len;
544 int noack;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800545 enum ssid_match_result res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700546
547 ie = mgmt->u.probe_req.variable;
548 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
549 return;
550 ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
551
552 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
553 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800554 mgmt->sa, mgmt->da, mgmt->bssid,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700555 ie, ie_len, ssi_signal) > 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700556 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800557
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700558 if (!hapd->iconf->send_probe_response)
559 return;
560
561 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
562 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
563 MAC2STR(mgmt->sa));
564 return;
565 }
566
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700567 if ((!elems.ssid || !elems.supp_rates)) {
568 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
569 "without SSID or supported rates element",
570 MAC2STR(mgmt->sa));
571 return;
572 }
573
574#ifdef CONFIG_P2P
575 if (hapd->p2p && elems.wps_ie) {
576 struct wpabuf *wps;
577 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
578 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
579 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
580 "due to mismatch with Requested Device "
581 "Type");
582 wpabuf_free(wps);
583 return;
584 }
585 wpabuf_free(wps);
586 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800587
588 if (hapd->p2p && elems.p2p) {
589 struct wpabuf *p2p;
590 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
591 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
592 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
593 "due to mismatch with Device ID");
594 wpabuf_free(p2p);
595 return;
596 }
597 wpabuf_free(p2p);
598 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700599#endif /* CONFIG_P2P */
600
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800601 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
602 elems.ssid_list_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700603 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
604 "broadcast SSID ignored", MAC2STR(mgmt->sa));
605 return;
606 }
607
608 sta = ap_get_sta(hapd, mgmt->sa);
609
610#ifdef CONFIG_P2P
611 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
612 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
613 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
614 P2P_WILDCARD_SSID_LEN) == 0) {
615 /* Process P2P Wildcard SSID like Wildcard SSID */
616 elems.ssid_len = 0;
617 }
618#endif /* CONFIG_P2P */
619
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800620 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
621 elems.ssid_list, elems.ssid_list_len);
622 if (res != NO_SSID_MATCH) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700623 if (sta)
624 sta->ssid_probe = &hapd->conf->ssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800625 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700626 if (!(mgmt->da[0] & 0x01)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700627 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800628 " for foreign SSID '%s' (DA " MACSTR ")%s",
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800629 MAC2STR(mgmt->sa),
630 wpa_ssid_txt(elems.ssid, elems.ssid_len),
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800631 MAC2STR(mgmt->da),
632 elems.ssid_list ? " (SSID list)" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700633 }
634 return;
635 }
636
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800637#ifdef CONFIG_INTERWORKING
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -0700638 if (hapd->conf->interworking &&
639 elems.interworking && elems.interworking_len >= 1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800640 u8 ant = elems.interworking[0] & 0x0f;
641 if (ant != INTERWORKING_ANT_WILDCARD &&
642 ant != hapd->conf->access_network_type) {
643 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
644 " for mismatching ANT %u ignored",
645 MAC2STR(mgmt->sa), ant);
646 return;
647 }
648 }
649
Dmitry Shmidtf9bdef92014-04-25 10:46:36 -0700650 if (hapd->conf->interworking && elems.interworking &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800651 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
652 const u8 *hessid;
653 if (elems.interworking_len == 7)
654 hessid = elems.interworking + 1;
655 else
656 hessid = elems.interworking + 1 + 2;
657 if (!is_broadcast_ether_addr(hessid) &&
658 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
659 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
660 " for mismatching HESSID " MACSTR
661 " ignored",
662 MAC2STR(mgmt->sa), MAC2STR(hessid));
663 return;
664 }
665 }
666#endif /* CONFIG_INTERWORKING */
667
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700668#ifdef CONFIG_P2P
669 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
670 supp_rates_11b_only(&elems)) {
671 /* Indicates support for 11b rates only */
672 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
673 MACSTR " with only 802.11b rates",
674 MAC2STR(mgmt->sa));
675 return;
676 }
677#endif /* CONFIG_P2P */
678
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700679 /* TODO: verify that supp_rates contains at least one matching rate
680 * with AP configuration */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800681
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700682#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700683 if (hapd->iconf->ignore_probe_probability > 0.0 &&
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700684 drand48() < hapd->iconf->ignore_probe_probability) {
685 wpa_printf(MSG_INFO,
686 "TESTING: ignoring probe request from " MACSTR,
687 MAC2STR(mgmt->sa));
688 return;
689 }
690#endif /* CONFIG_TESTING_OPTIONS */
691
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800692 resp = hostapd_gen_probe_resp(hapd, sta, mgmt, elems.p2p != NULL,
693 &resp_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700694 if (resp == NULL)
695 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700696
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800697 /*
698 * If this is a broadcast probe request, apply no ack policy to avoid
699 * excessive retries.
700 */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800701 noack = !!(res == WILDCARD_SSID_MATCH &&
702 is_broadcast_ether_addr(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700703
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800704 if (hostapd_drv_send_mlme(hapd, resp, resp_len, noack) < 0)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800705 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700706
707 os_free(resp);
708
709 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
710 "SSID", MAC2STR(mgmt->sa),
711 elems.ssid_len == 0 ? "broadcast" : "our");
712}
713
714
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800715static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
716 size_t *resp_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700717{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800718 /* check probe response offloading caps and print warnings */
719 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
720 return NULL;
721
722#ifdef CONFIG_WPS
723 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
724 (!(hapd->iface->probe_resp_offloads &
725 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
726 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
727 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
728 "Probe Response while not supporting this");
729#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700730
731#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800732 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
733 !(hapd->iface->probe_resp_offloads &
734 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
735 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
736 "Probe Response while not supporting this");
737#endif /* CONFIG_P2P */
738
739 if (hapd->conf->interworking &&
740 !(hapd->iface->probe_resp_offloads &
741 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
742 wpa_printf(MSG_WARNING, "Device is trying to offload "
743 "Interworking Probe Response while not supporting "
744 "this");
745
746 /* Generate a Probe Response template for the non-P2P case */
747 return hostapd_gen_probe_resp(hapd, NULL, NULL, 0, resp_len);
748}
749
750#endif /* NEED_AP_MLME */
751
752
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800753int ieee802_11_build_ap_params(struct hostapd_data *hapd,
754 struct wpa_driver_ap_params *params)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800755{
756 struct ieee80211_mgmt *head = NULL;
757 u8 *tail = NULL;
758 size_t head_len = 0, tail_len = 0;
759 u8 *resp = NULL;
760 size_t resp_len = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800761#ifdef NEED_AP_MLME
762 u16 capab_info;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800763 u8 *pos, *tailpos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700764
765#define BEACON_HEAD_BUF_SIZE 256
766#define BEACON_TAIL_BUF_SIZE 512
767 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
768 tail_len = BEACON_TAIL_BUF_SIZE;
769#ifdef CONFIG_WPS
770 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
771 tail_len += wpabuf_len(hapd->wps_beacon_ie);
772#endif /* CONFIG_WPS */
773#ifdef CONFIG_P2P
774 if (hapd->p2p_beacon_ie)
775 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
776#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700777 if (hapd->conf->vendor_elements)
778 tail_len += wpabuf_len(hapd->conf->vendor_elements);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700779 tailpos = tail = os_malloc(tail_len);
780 if (head == NULL || tail == NULL) {
781 wpa_printf(MSG_ERROR, "Failed to set beacon data");
782 os_free(head);
783 os_free(tail);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800784 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700785 }
786
787 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
788 WLAN_FC_STYPE_BEACON);
789 head->duration = host_to_le16(0);
790 os_memset(head->da, 0xff, ETH_ALEN);
791
792 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
793 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
794 head->u.beacon.beacon_int =
795 host_to_le16(hapd->iconf->beacon_int);
796
797 /* hardware or low-level driver will setup seq_ctrl and timestamp */
798 capab_info = hostapd_own_capab_info(hapd, NULL, 0);
799 head->u.beacon.capab_info = host_to_le16(capab_info);
800 pos = &head->u.beacon.variable[0];
801
802 /* SSID */
803 *pos++ = WLAN_EID_SSID;
804 if (hapd->conf->ignore_broadcast_ssid == 2) {
805 /* clear the data, but keep the correct length of the SSID */
806 *pos++ = hapd->conf->ssid.ssid_len;
807 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
808 pos += hapd->conf->ssid.ssid_len;
809 } else if (hapd->conf->ignore_broadcast_ssid) {
810 *pos++ = 0; /* empty SSID */
811 } else {
812 *pos++ = hapd->conf->ssid.ssid_len;
813 os_memcpy(pos, hapd->conf->ssid.ssid,
814 hapd->conf->ssid.ssid_len);
815 pos += hapd->conf->ssid.ssid_len;
816 }
817
818 /* Supported rates */
819 pos = hostapd_eid_supp_rates(hapd, pos);
820
821 /* DS Params */
822 pos = hostapd_eid_ds_params(hapd, pos);
823
824 head_len = pos - (u8 *) head;
825
826 tailpos = hostapd_eid_country(hapd, tailpos,
827 tail + BEACON_TAIL_BUF_SIZE - tailpos);
828
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800829 /* Power Constraint element */
830 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
831
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700832 /* ERP Information element */
833 tailpos = hostapd_eid_erp_info(hapd, tailpos);
834
835 /* Extended supported rates */
836 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
837
838 /* RSN, MDIE, WPA */
839 tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800840 tailpos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700841
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800842 tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
843 tail + BEACON_TAIL_BUF_SIZE -
844 tailpos);
845
Dmitry Shmidt051af732013-10-22 13:52:46 -0700846 tailpos = hostapd_eid_bss_load(hapd, tailpos,
847 tail + BEACON_TAIL_BUF_SIZE - tailpos);
848
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700849#ifdef CONFIG_IEEE80211N
850 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
851 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
852#endif /* CONFIG_IEEE80211N */
853
854 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
855
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800856 /*
857 * TODO: Time Advertisement element should only be included in some
858 * DTIM Beacon frames.
859 */
860 tailpos = hostapd_eid_time_adv(hapd, tailpos);
861
862 tailpos = hostapd_eid_interworking(hapd, tailpos);
863 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
864 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800865 tailpos = hostapd_add_csa_elems(hapd, tailpos, tail,
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700866 &hapd->cs_c_off_beacon);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700867#ifdef CONFIG_IEEE80211AC
868 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos);
869 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
870#endif /* CONFIG_IEEE80211AC */
871
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700872 /* Wi-Fi Alliance WMM */
873 tailpos = hostapd_eid_wmm(hapd, tailpos);
874
875#ifdef CONFIG_WPS
876 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
877 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
878 wpabuf_len(hapd->wps_beacon_ie));
879 tailpos += wpabuf_len(hapd->wps_beacon_ie);
880 }
881#endif /* CONFIG_WPS */
882
883#ifdef CONFIG_P2P
884 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
885 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
886 wpabuf_len(hapd->p2p_beacon_ie));
887 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
888 }
889#endif /* CONFIG_P2P */
890#ifdef CONFIG_P2P_MANAGER
891 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
892 P2P_MANAGE)
893 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
894#endif /* CONFIG_P2P_MANAGER */
895
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700896#ifdef CONFIG_HS20
897 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800898 tailpos = hostapd_eid_osen(hapd, tailpos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700899#endif /* CONFIG_HS20 */
900
901 if (hapd->conf->vendor_elements) {
902 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
903 wpabuf_len(hapd->conf->vendor_elements));
904 tailpos += wpabuf_len(hapd->conf->vendor_elements);
905 }
906
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700907 tail_len = tailpos > tail ? tailpos - tail : 0;
908
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800909 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
910#endif /* NEED_AP_MLME */
911
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800912 os_memset(params, 0, sizeof(*params));
913 params->head = (u8 *) head;
914 params->head_len = head_len;
915 params->tail = tail;
916 params->tail_len = tail_len;
917 params->proberesp = resp;
918 params->proberesp_len = resp_len;
919 params->dtim_period = hapd->conf->dtim_period;
920 params->beacon_int = hapd->iconf->beacon_int;
921 params->basic_rates = hapd->iface->basic_rates;
922 params->ssid = hapd->conf->ssid.ssid;
923 params->ssid_len = hapd->conf->ssid.ssid_len;
Dmitry Shmidtb5d893b2014-06-04 15:28:27 -0700924 params->pairwise_ciphers = hapd->conf->wpa_pairwise |
925 hapd->conf->rsn_pairwise;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800926 params->group_cipher = hapd->conf->wpa_group;
927 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
928 params->auth_algs = hapd->conf->auth_algs;
929 params->wpa_version = hapd->conf->wpa;
930 params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800931 (hapd->conf->ieee802_1x &&
932 (hapd->conf->default_wep_key_len ||
933 hapd->conf->individual_wep_key_len));
934 switch (hapd->conf->ignore_broadcast_ssid) {
935 case 0:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800936 params->hide_ssid = NO_SSID_HIDING;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800937 break;
938 case 1:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800939 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800940 break;
941 case 2:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800942 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800943 break;
944 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800945 params->isolate = hapd->conf->isolate;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800946 params->smps_mode = hapd->iconf->ht_capab & HT_CAP_INFO_SMPS_MASK;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800947#ifdef NEED_AP_MLME
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800948 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800949 ERP_INFO_USE_PROTECTION);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800950 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800951 hapd->iconf->preamble == SHORT_PREAMBLE;
952 if (hapd->iface->current_mode &&
953 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800954 params->short_slot_time =
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800955 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
956 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800957 params->short_slot_time = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800958 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800959 params->ht_opmode = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800960 else
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800961 params->ht_opmode = hapd->iface->ht_op_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800962#endif /* NEED_AP_MLME */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800963 params->interworking = hapd->conf->interworking;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800964 if (hapd->conf->interworking &&
965 !is_zero_ether_addr(hapd->conf->hessid))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800966 params->hessid = hapd->conf->hessid;
967 params->access_network_type = hapd->conf->access_network_type;
968 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700969#ifdef CONFIG_HS20
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800970 params->disable_dgaf = hapd->conf->disable_dgaf;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800971 if (hapd->conf->osen) {
972 params->privacy = 1;
973 params->osen = 1;
974 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700975#endif /* CONFIG_HS20 */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800976 return 0;
977}
978
979
980void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
981{
982 os_free(params->tail);
983 params->tail = NULL;
984 os_free(params->head);
985 params->head = NULL;
986 os_free(params->proberesp);
987 params->proberesp = NULL;
988}
989
990
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800991int ieee802_11_set_beacon(struct hostapd_data *hapd)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800992{
993 struct wpa_driver_ap_params params;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700994 struct hostapd_freq_params freq;
995 struct hostapd_iface *iface = hapd->iface;
996 struct hostapd_config *iconf = iface->conf;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800997 struct wpabuf *beacon, *proberesp, *assocresp;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800998 int res, ret = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800999
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001000 if (hapd->csa_in_progress) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001001 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001002 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001003 }
1004
1005 hapd->beacon_set_done = 1;
1006
1007 if (ieee802_11_build_ap_params(hapd, &params) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001008 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001009
1010 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
1011 0)
1012 goto fail;
1013
1014 params.beacon_ies = beacon;
1015 params.proberesp_ies = proberesp;
1016 params.assocresp_ies = assocresp;
1017
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001018 if (iface->current_mode &&
1019 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
1020 iconf->channel, iconf->ieee80211n,
1021 iconf->ieee80211ac,
1022 iconf->secondary_channel,
1023 iconf->vht_oper_chwidth,
1024 iconf->vht_oper_centr_freq_seg0_idx,
1025 iconf->vht_oper_centr_freq_seg1_idx,
1026 iface->current_mode->vht_capab) == 0)
1027 params.freq = &freq;
1028
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001029 res = hostapd_drv_set_ap(hapd, &params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001030 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001031 if (res)
1032 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
1033 else
1034 ret = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001035fail:
1036 ieee802_11_free_ap_params(&params);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001037 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001038}
1039
1040
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001041int ieee802_11_set_beacons(struct hostapd_iface *iface)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001042{
1043 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001044 int ret = 0;
1045
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08001046 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001047 if (iface->bss[i]->started &&
1048 ieee802_11_set_beacon(iface->bss[i]) < 0)
1049 ret = -1;
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08001050 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001051
1052 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001053}
1054
Dmitry Shmidt04949592012-07-19 12:16:46 -07001055
1056/* only update beacons if started */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001057int ieee802_11_update_beacons(struct hostapd_iface *iface)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001058{
1059 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001060 int ret = 0;
1061
1062 for (i = 0; i < iface->num_bss; i++) {
1063 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
1064 ieee802_11_set_beacon(iface->bss[i]) < 0)
1065 ret = -1;
1066 }
1067
1068 return ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001069}
1070
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001071#endif /* CONFIG_NATIVE_WINDOWS */