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.
5 * Copyright (c) 2008-2012, Jouni Malinen <j@w1.fi>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * Alternatively, this software may be distributed under the terms of BSD
14 * See README and COPYING for more details.
17 #include "utils/includes.h"
19 #ifndef CONFIG_NATIVE_WINDOWS
21 #include "utils/common.h"
22 #include "common/ieee802_11_defs.h"
23 #include "common/ieee802_11_common.h"
24 #include "drivers/driver.h"
25 #include "wps/wps_defs.h"
28 #include "ieee802_11.h"
31 #include "ap_config.h"
33 #include "p2p_hostapd.h"
34 #include "ap_drv_ops.h"
41 static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
43 #ifdef CONFIG_TESTING_OPTIONS
44 if (hapd->conf->bss_load_test_set) {
47 *eid++ = WLAN_EID_BSS_LOAD;
49 os_memcpy(eid, hapd->conf->bss_load_test, 5);
52 #endif /* CONFIG_TESTING_OPTIONS */
57 static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
61 if (hapd->iface->current_mode == NULL ||
62 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
65 if (hapd->iface->olbc)
66 erp |= ERP_INFO_USE_PROTECTION;
67 if (hapd->iface->num_sta_non_erp > 0) {
68 erp |= ERP_INFO_NON_ERP_PRESENT |
69 ERP_INFO_USE_PROTECTION;
71 if (hapd->iface->num_sta_no_short_preamble > 0 ||
72 hapd->iconf->preamble == LONG_PREAMBLE)
73 erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
79 static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
81 *eid++ = WLAN_EID_DS_PARAMS;
83 *eid++ = hapd->iconf->channel;
88 static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
90 if (hapd->iface->current_mode == NULL ||
91 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
94 /* Set NonERP_present and use_protection bits if there
95 * are any associated NonERP stations. */
96 /* TODO: use_protection bit can be set to zero even if
97 * there are NonERP stations present. This optimization
98 * might be useful if NonERP stations are "quiet".
99 * See 802.11g/D6 E-1 for recommended practice.
100 * In addition, Non ERP present might be set, if AP detects Non ERP
101 * operation on other APs. */
103 /* Add ERP Information element */
104 *eid++ = WLAN_EID_ERP_INFO;
106 *eid++ = ieee802_11_erp_info(hapd);
112 static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
113 struct hostapd_channel_data *start,
114 struct hostapd_channel_data *prev)
119 /* first channel number */
120 *pos++ = start->chan;
121 /* number of channels */
122 *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
123 /* maximum transmit power level */
124 *pos++ = start->max_tx_power;
130 static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
134 u8 *end = eid + max_len;
136 struct hostapd_hw_modes *mode;
137 struct hostapd_channel_data *start, *prev;
138 int chan_spacing = 1;
140 if (!hapd->iconf->ieee80211d || max_len < 6 ||
141 hapd->iface->current_mode == NULL)
144 *pos++ = WLAN_EID_COUNTRY;
145 pos++; /* length will be set later */
146 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
149 mode = hapd->iface->current_mode;
150 if (mode->mode == HOSTAPD_MODE_IEEE80211A)
154 for (i = 0; i < mode->num_channels; i++) {
155 struct hostapd_channel_data *chan = &mode->channels[i];
156 if (chan->flag & HOSTAPD_CHAN_DISABLED)
159 prev->chan + chan_spacing == chan->chan &&
160 start->max_tx_power == chan->max_tx_power) {
162 continue; /* can use same entry */
166 pos = hostapd_eid_country_add(pos, end, chan_spacing,
171 /* Start new group */
176 pos = hostapd_eid_country_add(pos, end, chan_spacing,
180 if ((pos - eid) & 1) {
183 *pos++ = 0; /* pad for 16-bit alignment */
186 eid[1] = (pos - eid) - 2;
192 static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
197 ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
198 if (ie == NULL || ielen > len)
201 os_memcpy(eid, ie, ielen);
206 static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
207 struct sta_info *sta,
208 const struct ieee80211_mgmt *req,
209 int is_p2p, size_t *resp_len)
211 struct ieee80211_mgmt *resp;
215 #define MAX_PROBERESP_LEN 768
216 buflen = MAX_PROBERESP_LEN;
218 if (hapd->wps_probe_resp_ie)
219 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
220 #endif /* CONFIG_WPS */
222 if (hapd->p2p_probe_resp_ie)
223 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
224 #endif /* CONFIG_P2P */
225 if (hapd->conf->vendor_elements)
226 buflen += wpabuf_len(hapd->conf->vendor_elements);
227 resp = os_zalloc(buflen);
231 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
233 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
234 WLAN_FC_STYPE_PROBE_RESP);
236 os_memcpy(resp->da, req->sa, ETH_ALEN);
237 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
239 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
240 resp->u.probe_resp.beacon_int =
241 host_to_le16(hapd->iconf->beacon_int);
243 /* hardware or low-level driver will setup seq_ctrl and timestamp */
244 resp->u.probe_resp.capab_info =
245 host_to_le16(hostapd_own_capab_info(hapd, sta, 1));
247 pos = resp->u.probe_resp.variable;
248 *pos++ = WLAN_EID_SSID;
249 *pos++ = hapd->conf->ssid.ssid_len;
250 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
251 pos += hapd->conf->ssid.ssid_len;
253 /* Supported rates */
254 pos = hostapd_eid_supp_rates(hapd, pos);
257 pos = hostapd_eid_ds_params(hapd, pos);
259 pos = hostapd_eid_country(hapd, pos, epos - pos);
261 /* ERP Information element */
262 pos = hostapd_eid_erp_info(hapd, pos);
264 /* Extended supported rates */
265 pos = hostapd_eid_ext_supp_rates(hapd, pos);
268 pos = hostapd_eid_wpa(hapd, pos, epos - pos);
270 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
272 #ifdef CONFIG_IEEE80211N
273 pos = hostapd_eid_ht_capabilities(hapd, pos);
274 pos = hostapd_eid_ht_operation(hapd, pos);
275 #endif /* CONFIG_IEEE80211N */
277 pos = hostapd_eid_ext_capab(hapd, pos);
279 pos = hostapd_eid_time_adv(hapd, pos);
280 pos = hostapd_eid_time_zone(hapd, pos);
282 pos = hostapd_eid_interworking(hapd, pos);
283 pos = hostapd_eid_adv_proto(hapd, pos);
284 pos = hostapd_eid_roaming_consortium(hapd, pos);
286 #ifdef CONFIG_IEEE80211AC
287 pos = hostapd_eid_vht_capabilities(hapd, pos);
288 pos = hostapd_eid_vht_operation(hapd, pos);
289 #endif /* CONFIG_IEEE80211AC */
291 /* Wi-Fi Alliance WMM */
292 pos = hostapd_eid_wmm(hapd, pos);
295 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
296 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
297 wpabuf_len(hapd->wps_probe_resp_ie));
298 pos += wpabuf_len(hapd->wps_probe_resp_ie);
300 #endif /* CONFIG_WPS */
303 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
304 hapd->p2p_probe_resp_ie) {
305 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
306 wpabuf_len(hapd->p2p_probe_resp_ie));
307 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
309 #endif /* CONFIG_P2P */
310 #ifdef CONFIG_P2P_MANAGER
311 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
313 pos = hostapd_eid_p2p_manage(hapd, pos);
314 #endif /* CONFIG_P2P_MANAGER */
317 pos = hostapd_eid_hs20_indication(hapd, pos);
318 #endif /* CONFIG_HS20 */
320 if (hapd->conf->vendor_elements) {
321 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
322 wpabuf_len(hapd->conf->vendor_elements));
323 pos += wpabuf_len(hapd->conf->vendor_elements);
326 *resp_len = pos - (u8 *) resp;
331 enum ssid_match_result {
337 static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
338 const u8 *ssid, size_t ssid_len,
340 size_t ssid_list_len)
347 if (ssid_len == hapd->conf->ssid.ssid_len &&
348 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
349 return EXACT_SSID_MATCH;
351 if (ssid_list == NULL)
352 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
355 end = ssid_list + ssid_list_len;
356 while (pos + 1 <= end) {
357 if (pos + 2 + pos[1] > end)
361 if (pos[1] == hapd->conf->ssid.ssid_len &&
362 os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0)
363 return EXACT_SSID_MATCH;
367 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
371 void handle_probe_req(struct hostapd_data *hapd,
372 const struct ieee80211_mgmt *mgmt, size_t len,
376 struct ieee802_11_elems elems;
379 struct sta_info *sta = NULL;
382 enum ssid_match_result res;
384 ie = mgmt->u.probe_req.variable;
385 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
387 ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
389 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
390 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
391 mgmt->sa, mgmt->da, mgmt->bssid,
392 ie, ie_len, ssi_signal) > 0)
395 if (!hapd->iconf->send_probe_response)
398 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
399 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
404 if ((!elems.ssid || !elems.supp_rates)) {
405 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
406 "without SSID or supported rates element",
412 if (hapd->p2p && elems.wps_ie) {
414 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
415 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
416 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
417 "due to mismatch with Requested Device "
425 if (hapd->p2p && elems.p2p) {
427 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
428 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
429 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
430 "due to mismatch with Device ID");
436 #endif /* CONFIG_P2P */
438 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
439 elems.ssid_list_len == 0) {
440 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
441 "broadcast SSID ignored", MAC2STR(mgmt->sa));
445 sta = ap_get_sta(hapd, mgmt->sa);
448 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
449 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
450 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
451 P2P_WILDCARD_SSID_LEN) == 0) {
452 /* Process P2P Wildcard SSID like Wildcard SSID */
455 #endif /* CONFIG_P2P */
457 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
458 elems.ssid_list, elems.ssid_list_len);
459 if (res != NO_SSID_MATCH) {
461 sta->ssid_probe = &hapd->conf->ssid;
463 if (!(mgmt->da[0] & 0x01)) {
465 ieee802_11_print_ssid(ssid_txt, elems.ssid,
467 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
468 " for foreign SSID '%s' (DA " MACSTR ")%s",
469 MAC2STR(mgmt->sa), ssid_txt,
471 elems.ssid_list ? " (SSID list)" : "");
476 #ifdef CONFIG_INTERWORKING
477 if (elems.interworking && elems.interworking_len >= 1) {
478 u8 ant = elems.interworking[0] & 0x0f;
479 if (ant != INTERWORKING_ANT_WILDCARD &&
480 ant != hapd->conf->access_network_type) {
481 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
482 " for mismatching ANT %u ignored",
483 MAC2STR(mgmt->sa), ant);
488 if (elems.interworking &&
489 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
491 if (elems.interworking_len == 7)
492 hessid = elems.interworking + 1;
494 hessid = elems.interworking + 1 + 2;
495 if (!is_broadcast_ether_addr(hessid) &&
496 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
497 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
498 " for mismatching HESSID " MACSTR
500 MAC2STR(mgmt->sa), MAC2STR(hessid));
504 #endif /* CONFIG_INTERWORKING */
507 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
508 supp_rates_11b_only(&elems)) {
509 /* Indicates support for 11b rates only */
510 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
511 MACSTR " with only 802.11b rates",
515 #endif /* CONFIG_P2P */
517 /* TODO: verify that supp_rates contains at least one matching rate
518 * with AP configuration */
520 #ifdef CONFIG_TESTING_OPTIONS
521 if (hapd->iconf->ignore_probe_probability > 0.0d &&
522 drand48() < hapd->iconf->ignore_probe_probability) {
524 "TESTING: ignoring probe request from " MACSTR,
528 #endif /* CONFIG_TESTING_OPTIONS */
530 resp = hostapd_gen_probe_resp(hapd, sta, mgmt, elems.p2p != NULL,
536 * If this is a broadcast probe request, apply no ack policy to avoid
539 noack = !!(res == WILDCARD_SSID_MATCH &&
540 is_broadcast_ether_addr(mgmt->da));
542 if (hostapd_drv_send_mlme(hapd, resp, resp_len, noack) < 0)
543 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
547 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
548 "SSID", MAC2STR(mgmt->sa),
549 elems.ssid_len == 0 ? "broadcast" : "our");
553 static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
556 /* check probe response offloading caps and print warnings */
557 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
561 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
562 (!(hapd->iface->probe_resp_offloads &
563 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
564 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
565 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
566 "Probe Response while not supporting this");
567 #endif /* CONFIG_WPS */
570 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
571 !(hapd->iface->probe_resp_offloads &
572 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
573 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
574 "Probe Response while not supporting this");
575 #endif /* CONFIG_P2P */
577 if (hapd->conf->interworking &&
578 !(hapd->iface->probe_resp_offloads &
579 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
580 wpa_printf(MSG_WARNING, "Device is trying to offload "
581 "Interworking Probe Response while not supporting "
584 /* Generate a Probe Response template for the non-P2P case */
585 return hostapd_gen_probe_resp(hapd, NULL, NULL, 0, resp_len);
588 #endif /* NEED_AP_MLME */
591 int ieee802_11_build_ap_params(struct hostapd_data *hapd,
592 struct wpa_driver_ap_params *params)
594 struct ieee80211_mgmt *head = NULL;
596 size_t head_len = 0, tail_len = 0;
603 #define BEACON_HEAD_BUF_SIZE 256
604 #define BEACON_TAIL_BUF_SIZE 512
605 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
606 tail_len = BEACON_TAIL_BUF_SIZE;
608 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
609 tail_len += wpabuf_len(hapd->wps_beacon_ie);
610 #endif /* CONFIG_WPS */
612 if (hapd->p2p_beacon_ie)
613 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
614 #endif /* CONFIG_P2P */
615 if (hapd->conf->vendor_elements)
616 tail_len += wpabuf_len(hapd->conf->vendor_elements);
617 tailpos = tail = os_malloc(tail_len);
618 if (head == NULL || tail == NULL) {
619 wpa_printf(MSG_ERROR, "Failed to set beacon data");
625 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
626 WLAN_FC_STYPE_BEACON);
627 head->duration = host_to_le16(0);
628 os_memset(head->da, 0xff, ETH_ALEN);
630 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
631 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
632 head->u.beacon.beacon_int =
633 host_to_le16(hapd->iconf->beacon_int);
635 /* hardware or low-level driver will setup seq_ctrl and timestamp */
636 capab_info = hostapd_own_capab_info(hapd, NULL, 0);
637 head->u.beacon.capab_info = host_to_le16(capab_info);
638 pos = &head->u.beacon.variable[0];
641 *pos++ = WLAN_EID_SSID;
642 if (hapd->conf->ignore_broadcast_ssid == 2) {
643 /* clear the data, but keep the correct length of the SSID */
644 *pos++ = hapd->conf->ssid.ssid_len;
645 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
646 pos += hapd->conf->ssid.ssid_len;
647 } else if (hapd->conf->ignore_broadcast_ssid) {
648 *pos++ = 0; /* empty SSID */
650 *pos++ = hapd->conf->ssid.ssid_len;
651 os_memcpy(pos, hapd->conf->ssid.ssid,
652 hapd->conf->ssid.ssid_len);
653 pos += hapd->conf->ssid.ssid_len;
656 /* Supported rates */
657 pos = hostapd_eid_supp_rates(hapd, pos);
660 pos = hostapd_eid_ds_params(hapd, pos);
662 head_len = pos - (u8 *) head;
664 tailpos = hostapd_eid_country(hapd, tailpos,
665 tail + BEACON_TAIL_BUF_SIZE - tailpos);
667 /* ERP Information element */
668 tailpos = hostapd_eid_erp_info(hapd, tailpos);
670 /* Extended supported rates */
671 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
674 tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
677 tailpos = hostapd_eid_bss_load(hapd, tailpos,
678 tail + BEACON_TAIL_BUF_SIZE - tailpos);
680 #ifdef CONFIG_IEEE80211N
681 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
682 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
683 #endif /* CONFIG_IEEE80211N */
685 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
688 * TODO: Time Advertisement element should only be included in some
689 * DTIM Beacon frames.
691 tailpos = hostapd_eid_time_adv(hapd, tailpos);
693 tailpos = hostapd_eid_interworking(hapd, tailpos);
694 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
695 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
697 #ifdef CONFIG_IEEE80211AC
698 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos);
699 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
700 #endif /* CONFIG_IEEE80211AC */
702 /* Wi-Fi Alliance WMM */
703 tailpos = hostapd_eid_wmm(hapd, tailpos);
706 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
707 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
708 wpabuf_len(hapd->wps_beacon_ie));
709 tailpos += wpabuf_len(hapd->wps_beacon_ie);
711 #endif /* CONFIG_WPS */
714 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
715 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
716 wpabuf_len(hapd->p2p_beacon_ie));
717 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
719 #endif /* CONFIG_P2P */
720 #ifdef CONFIG_P2P_MANAGER
721 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
723 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
724 #endif /* CONFIG_P2P_MANAGER */
727 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
728 #endif /* CONFIG_HS20 */
730 if (hapd->conf->vendor_elements) {
731 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
732 wpabuf_len(hapd->conf->vendor_elements));
733 tailpos += wpabuf_len(hapd->conf->vendor_elements);
736 tail_len = tailpos > tail ? tailpos - tail : 0;
738 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
739 #endif /* NEED_AP_MLME */
741 os_memset(params, 0, sizeof(*params));
742 params->head = (u8 *) head;
743 params->head_len = head_len;
745 params->tail_len = tail_len;
746 params->proberesp = resp;
747 params->proberesp_len = resp_len;
748 params->dtim_period = hapd->conf->dtim_period;
749 params->beacon_int = hapd->iconf->beacon_int;
750 params->basic_rates = hapd->iface->basic_rates;
751 params->ssid = hapd->conf->ssid.ssid;
752 params->ssid_len = hapd->conf->ssid.ssid_len;
753 params->pairwise_ciphers = hapd->conf->rsn_pairwise ?
754 hapd->conf->rsn_pairwise : hapd->conf->wpa_pairwise;
755 params->group_cipher = hapd->conf->wpa_group;
756 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
757 params->auth_algs = hapd->conf->auth_algs;
758 params->wpa_version = hapd->conf->wpa;
759 params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
760 (hapd->conf->ieee802_1x &&
761 (hapd->conf->default_wep_key_len ||
762 hapd->conf->individual_wep_key_len));
763 switch (hapd->conf->ignore_broadcast_ssid) {
765 params->hide_ssid = NO_SSID_HIDING;
768 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
771 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
774 params->isolate = hapd->conf->isolate;
776 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
777 ERP_INFO_USE_PROTECTION);
778 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
779 hapd->iconf->preamble == SHORT_PREAMBLE;
780 if (hapd->iface->current_mode &&
781 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
782 params->short_slot_time =
783 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
785 params->short_slot_time = -1;
786 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
787 params->ht_opmode = -1;
789 params->ht_opmode = hapd->iface->ht_op_mode;
790 #endif /* NEED_AP_MLME */
791 params->interworking = hapd->conf->interworking;
792 if (hapd->conf->interworking &&
793 !is_zero_ether_addr(hapd->conf->hessid))
794 params->hessid = hapd->conf->hessid;
795 params->access_network_type = hapd->conf->access_network_type;
796 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
798 params->disable_dgaf = hapd->conf->disable_dgaf;
799 #endif /* CONFIG_HS20 */
804 void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
806 os_free(params->tail);
808 os_free(params->head);
810 os_free(params->proberesp);
811 params->proberesp = NULL;
815 void ieee802_11_set_beacon(struct hostapd_data *hapd)
817 struct wpa_driver_ap_params params;
818 struct wpabuf *beacon, *proberesp, *assocresp;
820 hapd->beacon_set_done = 1;
822 if (ieee802_11_build_ap_params(hapd, ¶ms) < 0)
825 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
829 params.beacon_ies = beacon;
830 params.proberesp_ies = proberesp;
831 params.assocresp_ies = assocresp;
833 if (hostapd_drv_set_ap(hapd, ¶ms))
834 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
835 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
837 ieee802_11_free_ap_params(¶ms);
841 void ieee802_11_set_beacons(struct hostapd_iface *iface)
844 for (i = 0; i < iface->num_bss; i++)
845 ieee802_11_set_beacon(iface->bss[i]);
849 /* only update beacons if started */
850 void ieee802_11_update_beacons(struct hostapd_iface *iface)
853 for (i = 0; i < iface->num_bss; i++)
854 if (iface->bss[i]->beacon_set_done)
855 ieee802_11_set_beacon(iface->bss[i]);
858 #endif /* CONFIG_NATIVE_WINDOWS */