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 software may be distributed under the terms of the BSD license.
8 * See README for more details.
11 #include "utils/includes.h"
13 #ifndef CONFIG_NATIVE_WINDOWS
15 #include "utils/common.h"
16 #include "common/ieee802_11_defs.h"
17 #include "common/ieee802_11_common.h"
18 #include "wps/wps_defs.h"
21 #include "ieee802_11.h"
24 #include "ap_config.h"
26 #include "p2p_hostapd.h"
27 #include "ap_drv_ops.h"
35 static u8 * hostapd_eid_rm_enabled_capab(struct hostapd_data *hapd, u8 *eid,
38 if (!hapd->conf->radio_measurements || len < 2 + 4)
41 *eid++ = WLAN_EID_RRM_ENABLED_CAPABILITIES;
43 *eid++ = (hapd->conf->radio_measurements & BIT(0)) ?
44 WLAN_RRM_CAPS_NEIGHBOR_REPORT : 0x00;
53 static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
58 #ifdef CONFIG_TESTING_OPTIONS
59 if (hapd->conf->bss_load_test_set) {
60 *eid++ = WLAN_EID_BSS_LOAD;
62 os_memcpy(eid, hapd->conf->bss_load_test, 5);
66 #endif /* CONFIG_TESTING_OPTIONS */
67 if (hapd->conf->bss_load_update_period) {
68 *eid++ = WLAN_EID_BSS_LOAD;
70 WPA_PUT_LE16(eid, hapd->num_sta);
72 *eid++ = hapd->iface->channel_utilization;
73 WPA_PUT_LE16(eid, 0); /* no available admission capabity */
80 static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
84 if (hapd->iface->current_mode == NULL ||
85 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
88 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;
94 if (hapd->iface->num_sta_no_short_preamble > 0 ||
95 hapd->iconf->preamble == LONG_PREAMBLE)
96 erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
102 static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
104 *eid++ = WLAN_EID_DS_PARAMS;
106 *eid++ = hapd->iconf->channel;
111 static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
113 if (hapd->iface->current_mode == NULL ||
114 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
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. */
126 /* Add ERP Information element */
127 *eid++ = WLAN_EID_ERP_INFO;
129 *eid++ = ieee802_11_erp_info(hapd);
135 static u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid)
138 u8 local_pwr_constraint = 0;
141 if (hapd->iface->current_mode == NULL ||
142 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
145 /* Let host drivers add this IE if DFS support is offloaded */
146 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)
150 * There is no DFS support and power constraint was not directly
151 * requested by config option.
153 if (!hapd->iconf->ieee80211h &&
154 hapd->iconf->local_pwr_constraint == -1)
157 /* Check if DFS is required by regulatory. */
158 dfs = hostapd_is_dfs_required(hapd->iface);
160 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
165 if (dfs == 0 && hapd->iconf->local_pwr_constraint == -1)
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.
176 if (hapd->iconf->local_pwr_constraint == -1)
177 local_pwr_constraint = 3;
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.
190 *pos++ = WLAN_EID_PWR_CONSTRAINT;
193 /* Local Power Constraint */
194 if (local_pwr_constraint)
195 *pos++ = local_pwr_constraint;
197 *pos++ = hapd->iconf->local_pwr_constraint;
203 static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
204 struct hostapd_channel_data *start,
205 struct hostapd_channel_data *prev)
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;
221 static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
225 u8 *end = eid + max_len;
227 struct hostapd_hw_modes *mode;
228 struct hostapd_channel_data *start, *prev;
229 int chan_spacing = 1;
231 if (!hapd->iconf->ieee80211d || max_len < 6 ||
232 hapd->iface->current_mode == NULL)
235 *pos++ = WLAN_EID_COUNTRY;
236 pos++; /* length will be set later */
237 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
240 mode = hapd->iface->current_mode;
241 if (mode->mode == HOSTAPD_MODE_IEEE80211A)
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)
250 prev->chan + chan_spacing == chan->chan &&
251 start->max_tx_power == chan->max_tx_power) {
253 continue; /* can use same entry */
257 pos = hostapd_eid_country_add(pos, end, chan_spacing,
262 /* Start new group */
267 pos = hostapd_eid_country_add(pos, end, chan_spacing,
271 if ((pos - eid) & 1) {
274 *pos++ = 0; /* pad for 16-bit alignment */
277 eid[1] = (pos - eid) - 2;
283 static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
288 ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
289 if (ie == NULL || ielen > len)
292 os_memcpy(eid, ie, ielen);
297 static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
301 if (!hapd->cs_freq_params.freq)
304 if (ieee80211_freq_to_chan(hapd->cs_freq_params.freq, &chan) ==
308 *eid++ = WLAN_EID_CHANNEL_SWITCH;
310 *eid++ = hapd->cs_block_tx;
312 *eid++ = hapd->cs_count;
318 static u8 * hostapd_eid_secondary_channel(struct hostapd_data *hapd, u8 *eid)
322 if (!hapd->cs_freq_params.sec_channel_offset)
325 if (hapd->cs_freq_params.sec_channel_offset == -1)
326 sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW;
327 else if (hapd->cs_freq_params.sec_channel_offset == 1)
328 sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE;
332 *eid++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET;
340 static u8 * hostapd_add_csa_elems(struct hostapd_data *hapd, u8 *pos,
341 u8 *start, unsigned int *csa_counter_off)
345 if (!csa_counter_off)
348 *csa_counter_off = 0;
349 pos = hostapd_eid_csa(hapd, pos);
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);
361 static 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)
366 struct ieee80211_mgmt *resp;
370 #define MAX_PROBERESP_LEN 768
371 buflen = MAX_PROBERESP_LEN;
373 if (hapd->wps_probe_resp_ie)
374 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
375 #endif /* CONFIG_WPS */
377 if (hapd->p2p_probe_resp_ie)
378 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
379 #endif /* CONFIG_P2P */
380 if (hapd->conf->vendor_elements)
381 buflen += wpabuf_len(hapd->conf->vendor_elements);
382 if (hapd->conf->vendor_vht) {
383 buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
384 2 + sizeof(struct ieee80211_vht_operation);
386 resp = os_zalloc(buflen);
390 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
392 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
393 WLAN_FC_STYPE_PROBE_RESP);
395 os_memcpy(resp->da, req->sa, ETH_ALEN);
396 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
398 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
399 resp->u.probe_resp.beacon_int =
400 host_to_le16(hapd->iconf->beacon_int);
402 /* hardware or low-level driver will setup seq_ctrl and timestamp */
403 resp->u.probe_resp.capab_info =
404 host_to_le16(hostapd_own_capab_info(hapd, sta, 1));
406 pos = resp->u.probe_resp.variable;
407 *pos++ = WLAN_EID_SSID;
408 *pos++ = hapd->conf->ssid.ssid_len;
409 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
410 pos += hapd->conf->ssid.ssid_len;
412 /* Supported rates */
413 pos = hostapd_eid_supp_rates(hapd, pos);
416 pos = hostapd_eid_ds_params(hapd, pos);
418 pos = hostapd_eid_country(hapd, pos, epos - pos);
420 /* Power Constraint element */
421 pos = hostapd_eid_pwr_constraint(hapd, pos);
423 /* ERP Information element */
424 pos = hostapd_eid_erp_info(hapd, pos);
426 /* Extended supported rates */
427 pos = hostapd_eid_ext_supp_rates(hapd, pos);
430 pos = hostapd_eid_wpa(hapd, pos, epos - pos);
432 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
434 pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
436 #ifdef CONFIG_IEEE80211N
437 pos = hostapd_eid_ht_capabilities(hapd, pos);
438 pos = hostapd_eid_ht_operation(hapd, pos);
439 #endif /* CONFIG_IEEE80211N */
441 pos = hostapd_eid_ext_capab(hapd, pos);
443 pos = hostapd_eid_time_adv(hapd, pos);
444 pos = hostapd_eid_time_zone(hapd, pos);
446 pos = hostapd_eid_interworking(hapd, pos);
447 pos = hostapd_eid_adv_proto(hapd, pos);
448 pos = hostapd_eid_roaming_consortium(hapd, pos);
450 pos = hostapd_add_csa_elems(hapd, pos, (u8 *)resp,
451 &hapd->cs_c_off_proberesp);
452 #ifdef CONFIG_IEEE80211AC
453 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
454 pos = hostapd_eid_vht_capabilities(hapd, pos);
455 pos = hostapd_eid_vht_operation(hapd, pos);
457 if (hapd->conf->vendor_vht)
458 pos = hostapd_eid_vendor_vht(hapd, pos);
459 #endif /* CONFIG_IEEE80211AC */
461 /* Wi-Fi Alliance WMM */
462 pos = hostapd_eid_wmm(hapd, pos);
465 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
466 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
467 wpabuf_len(hapd->wps_probe_resp_ie));
468 pos += wpabuf_len(hapd->wps_probe_resp_ie);
470 #endif /* CONFIG_WPS */
473 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
474 hapd->p2p_probe_resp_ie) {
475 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
476 wpabuf_len(hapd->p2p_probe_resp_ie));
477 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
479 #endif /* CONFIG_P2P */
480 #ifdef CONFIG_P2P_MANAGER
481 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
483 pos = hostapd_eid_p2p_manage(hapd, pos);
484 #endif /* CONFIG_P2P_MANAGER */
487 pos = hostapd_eid_hs20_indication(hapd, pos);
488 pos = hostapd_eid_osen(hapd, pos);
489 #endif /* CONFIG_HS20 */
491 if (hapd->conf->vendor_elements) {
492 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
493 wpabuf_len(hapd->conf->vendor_elements));
494 pos += wpabuf_len(hapd->conf->vendor_elements);
497 *resp_len = pos - (u8 *) resp;
502 enum ssid_match_result {
508 static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
509 const u8 *ssid, size_t ssid_len,
511 size_t ssid_list_len)
518 if (ssid_len == hapd->conf->ssid.ssid_len &&
519 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
520 return EXACT_SSID_MATCH;
522 if (ssid_list == NULL)
523 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
526 end = ssid_list + ssid_list_len;
527 while (pos + 1 <= end) {
528 if (pos + 2 + pos[1] > end)
532 if (pos[1] == hapd->conf->ssid.ssid_len &&
533 os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0)
534 return EXACT_SSID_MATCH;
538 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
542 void handle_probe_req(struct hostapd_data *hapd,
543 const struct ieee80211_mgmt *mgmt, size_t len,
547 struct ieee802_11_elems elems;
550 struct sta_info *sta = NULL;
553 enum ssid_match_result res;
555 ie = mgmt->u.probe_req.variable;
556 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
558 ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
560 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
561 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
562 mgmt->sa, mgmt->da, mgmt->bssid,
563 ie, ie_len, ssi_signal) > 0)
566 if (!hapd->iconf->send_probe_response)
569 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
570 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
575 if ((!elems.ssid || !elems.supp_rates)) {
576 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
577 "without SSID or supported rates element",
583 * No need to reply if the Probe Request frame was sent on an adjacent
584 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
585 * AP with dot11RadioMeasurementActivated set to true, but strictly
586 * speaking does not allow such ignoring of Probe Request frames if
587 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
588 * number of unnecessary Probe Response frames for cases where the STA
589 * is less likely to see them (Probe Request frame sent on a
590 * neighboring, but partially overlapping, channel).
592 if (elems.ds_params && elems.ds_params_len == 1 &&
593 hapd->iface->current_mode &&
594 (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
595 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
596 hapd->iconf->channel != elems.ds_params[0]) {
597 wpa_printf(MSG_DEBUG,
598 "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
599 hapd->iconf->channel, elems.ds_params[0]);
604 if (hapd->p2p && elems.wps_ie) {
606 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
607 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
608 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
609 "due to mismatch with Requested Device "
617 if (hapd->p2p && elems.p2p) {
619 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
620 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
621 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
622 "due to mismatch with Device ID");
628 #endif /* CONFIG_P2P */
630 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
631 elems.ssid_list_len == 0) {
632 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
633 "broadcast SSID ignored", MAC2STR(mgmt->sa));
637 sta = ap_get_sta(hapd, mgmt->sa);
640 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
641 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
642 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
643 P2P_WILDCARD_SSID_LEN) == 0) {
644 /* Process P2P Wildcard SSID like Wildcard SSID */
647 #endif /* CONFIG_P2P */
649 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
650 elems.ssid_list, elems.ssid_list_len);
651 if (res != NO_SSID_MATCH) {
653 sta->ssid_probe = &hapd->conf->ssid;
655 if (!(mgmt->da[0] & 0x01)) {
656 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
657 " for foreign SSID '%s' (DA " MACSTR ")%s",
659 wpa_ssid_txt(elems.ssid, elems.ssid_len),
661 elems.ssid_list ? " (SSID list)" : "");
666 #ifdef CONFIG_INTERWORKING
667 if (hapd->conf->interworking &&
668 elems.interworking && elems.interworking_len >= 1) {
669 u8 ant = elems.interworking[0] & 0x0f;
670 if (ant != INTERWORKING_ANT_WILDCARD &&
671 ant != hapd->conf->access_network_type) {
672 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
673 " for mismatching ANT %u ignored",
674 MAC2STR(mgmt->sa), ant);
679 if (hapd->conf->interworking && elems.interworking &&
680 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
682 if (elems.interworking_len == 7)
683 hessid = elems.interworking + 1;
685 hessid = elems.interworking + 1 + 2;
686 if (!is_broadcast_ether_addr(hessid) &&
687 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
688 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
689 " for mismatching HESSID " MACSTR
691 MAC2STR(mgmt->sa), MAC2STR(hessid));
695 #endif /* CONFIG_INTERWORKING */
698 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
699 supp_rates_11b_only(&elems)) {
700 /* Indicates support for 11b rates only */
701 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
702 MACSTR " with only 802.11b rates",
706 #endif /* CONFIG_P2P */
708 /* TODO: verify that supp_rates contains at least one matching rate
709 * with AP configuration */
711 #ifdef CONFIG_TESTING_OPTIONS
712 if (hapd->iconf->ignore_probe_probability > 0.0 &&
713 drand48() < hapd->iconf->ignore_probe_probability) {
715 "TESTING: ignoring probe request from " MACSTR,
719 #endif /* CONFIG_TESTING_OPTIONS */
721 resp = hostapd_gen_probe_resp(hapd, sta, mgmt, elems.p2p != NULL,
727 * If this is a broadcast probe request, apply no ack policy to avoid
730 noack = !!(res == WILDCARD_SSID_MATCH &&
731 is_broadcast_ether_addr(mgmt->da));
733 if (hostapd_drv_send_mlme(hapd, resp, resp_len, noack) < 0)
734 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
738 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
739 "SSID", MAC2STR(mgmt->sa),
740 elems.ssid_len == 0 ? "broadcast" : "our");
744 static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
747 /* check probe response offloading caps and print warnings */
748 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
752 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
753 (!(hapd->iface->probe_resp_offloads &
754 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
755 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
756 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
757 "Probe Response while not supporting this");
758 #endif /* CONFIG_WPS */
761 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
762 !(hapd->iface->probe_resp_offloads &
763 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
764 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
765 "Probe Response while not supporting this");
766 #endif /* CONFIG_P2P */
768 if (hapd->conf->interworking &&
769 !(hapd->iface->probe_resp_offloads &
770 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
771 wpa_printf(MSG_WARNING, "Device is trying to offload "
772 "Interworking Probe Response while not supporting "
775 /* Generate a Probe Response template for the non-P2P case */
776 return hostapd_gen_probe_resp(hapd, NULL, NULL, 0, resp_len);
779 #endif /* NEED_AP_MLME */
782 int ieee802_11_build_ap_params(struct hostapd_data *hapd,
783 struct wpa_driver_ap_params *params)
785 struct ieee80211_mgmt *head = NULL;
787 size_t head_len = 0, tail_len = 0;
794 #define BEACON_HEAD_BUF_SIZE 256
795 #define BEACON_TAIL_BUF_SIZE 512
796 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
797 tail_len = BEACON_TAIL_BUF_SIZE;
799 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
800 tail_len += wpabuf_len(hapd->wps_beacon_ie);
801 #endif /* CONFIG_WPS */
803 if (hapd->p2p_beacon_ie)
804 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
805 #endif /* CONFIG_P2P */
806 if (hapd->conf->vendor_elements)
807 tail_len += wpabuf_len(hapd->conf->vendor_elements);
809 #ifdef CONFIG_IEEE80211AC
810 if (hapd->conf->vendor_vht) {
811 tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
812 2 + sizeof(struct ieee80211_vht_operation);
814 #endif /* CONFIG_IEEE80211AC */
816 tailpos = tail = os_malloc(tail_len);
817 if (head == NULL || tail == NULL) {
818 wpa_printf(MSG_ERROR, "Failed to set beacon data");
824 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
825 WLAN_FC_STYPE_BEACON);
826 head->duration = host_to_le16(0);
827 os_memset(head->da, 0xff, ETH_ALEN);
829 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
830 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
831 head->u.beacon.beacon_int =
832 host_to_le16(hapd->iconf->beacon_int);
834 /* hardware or low-level driver will setup seq_ctrl and timestamp */
835 capab_info = hostapd_own_capab_info(hapd, NULL, 0);
836 head->u.beacon.capab_info = host_to_le16(capab_info);
837 pos = &head->u.beacon.variable[0];
840 *pos++ = WLAN_EID_SSID;
841 if (hapd->conf->ignore_broadcast_ssid == 2) {
842 /* clear the data, but keep the correct length of the SSID */
843 *pos++ = hapd->conf->ssid.ssid_len;
844 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
845 pos += hapd->conf->ssid.ssid_len;
846 } else if (hapd->conf->ignore_broadcast_ssid) {
847 *pos++ = 0; /* empty SSID */
849 *pos++ = hapd->conf->ssid.ssid_len;
850 os_memcpy(pos, hapd->conf->ssid.ssid,
851 hapd->conf->ssid.ssid_len);
852 pos += hapd->conf->ssid.ssid_len;
855 /* Supported rates */
856 pos = hostapd_eid_supp_rates(hapd, pos);
859 pos = hostapd_eid_ds_params(hapd, pos);
861 head_len = pos - (u8 *) head;
863 tailpos = hostapd_eid_country(hapd, tailpos,
864 tail + BEACON_TAIL_BUF_SIZE - tailpos);
866 /* Power Constraint element */
867 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
869 /* ERP Information element */
870 tailpos = hostapd_eid_erp_info(hapd, tailpos);
872 /* Extended supported rates */
873 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
876 tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
879 tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
880 tail + BEACON_TAIL_BUF_SIZE -
883 tailpos = hostapd_eid_bss_load(hapd, tailpos,
884 tail + BEACON_TAIL_BUF_SIZE - tailpos);
886 #ifdef CONFIG_IEEE80211N
887 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
888 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
889 #endif /* CONFIG_IEEE80211N */
891 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
894 * TODO: Time Advertisement element should only be included in some
895 * DTIM Beacon frames.
897 tailpos = hostapd_eid_time_adv(hapd, tailpos);
899 tailpos = hostapd_eid_interworking(hapd, tailpos);
900 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
901 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
902 tailpos = hostapd_add_csa_elems(hapd, tailpos, tail,
903 &hapd->cs_c_off_beacon);
904 #ifdef CONFIG_IEEE80211AC
905 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
906 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos);
907 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
909 if (hapd->conf->vendor_vht)
910 tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
911 #endif /* CONFIG_IEEE80211AC */
913 /* Wi-Fi Alliance WMM */
914 tailpos = hostapd_eid_wmm(hapd, tailpos);
917 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
918 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
919 wpabuf_len(hapd->wps_beacon_ie));
920 tailpos += wpabuf_len(hapd->wps_beacon_ie);
922 #endif /* CONFIG_WPS */
925 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
926 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
927 wpabuf_len(hapd->p2p_beacon_ie));
928 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
930 #endif /* CONFIG_P2P */
931 #ifdef CONFIG_P2P_MANAGER
932 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
934 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
935 #endif /* CONFIG_P2P_MANAGER */
938 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
939 tailpos = hostapd_eid_osen(hapd, tailpos);
940 #endif /* CONFIG_HS20 */
942 if (hapd->conf->vendor_elements) {
943 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
944 wpabuf_len(hapd->conf->vendor_elements));
945 tailpos += wpabuf_len(hapd->conf->vendor_elements);
948 tail_len = tailpos > tail ? tailpos - tail : 0;
950 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
951 #endif /* NEED_AP_MLME */
953 os_memset(params, 0, sizeof(*params));
954 params->head = (u8 *) head;
955 params->head_len = head_len;
957 params->tail_len = tail_len;
958 params->proberesp = resp;
959 params->proberesp_len = resp_len;
960 params->dtim_period = hapd->conf->dtim_period;
961 params->beacon_int = hapd->iconf->beacon_int;
962 params->basic_rates = hapd->iface->basic_rates;
963 params->ssid = hapd->conf->ssid.ssid;
964 params->ssid_len = hapd->conf->ssid.ssid_len;
965 params->pairwise_ciphers = hapd->conf->wpa_pairwise |
966 hapd->conf->rsn_pairwise;
967 params->group_cipher = hapd->conf->wpa_group;
968 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
969 params->auth_algs = hapd->conf->auth_algs;
970 params->wpa_version = hapd->conf->wpa;
971 params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
972 (hapd->conf->ieee802_1x &&
973 (hapd->conf->default_wep_key_len ||
974 hapd->conf->individual_wep_key_len));
975 switch (hapd->conf->ignore_broadcast_ssid) {
977 params->hide_ssid = NO_SSID_HIDING;
980 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
983 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
986 params->isolate = hapd->conf->isolate;
987 params->smps_mode = hapd->iconf->ht_capab & HT_CAP_INFO_SMPS_MASK;
989 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
990 ERP_INFO_USE_PROTECTION);
991 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
992 hapd->iconf->preamble == SHORT_PREAMBLE;
993 if (hapd->iface->current_mode &&
994 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
995 params->short_slot_time =
996 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
998 params->short_slot_time = -1;
999 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
1000 params->ht_opmode = -1;
1002 params->ht_opmode = hapd->iface->ht_op_mode;
1003 #endif /* NEED_AP_MLME */
1004 params->interworking = hapd->conf->interworking;
1005 if (hapd->conf->interworking &&
1006 !is_zero_ether_addr(hapd->conf->hessid))
1007 params->hessid = hapd->conf->hessid;
1008 params->access_network_type = hapd->conf->access_network_type;
1009 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
1011 params->disable_dgaf = hapd->conf->disable_dgaf;
1012 if (hapd->conf->osen) {
1013 params->privacy = 1;
1016 #endif /* CONFIG_HS20 */
1021 void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
1023 os_free(params->tail);
1024 params->tail = NULL;
1025 os_free(params->head);
1026 params->head = NULL;
1027 os_free(params->proberesp);
1028 params->proberesp = NULL;
1032 int ieee802_11_set_beacon(struct hostapd_data *hapd)
1034 struct wpa_driver_ap_params params;
1035 struct hostapd_freq_params freq;
1036 struct hostapd_iface *iface = hapd->iface;
1037 struct hostapd_config *iconf = iface->conf;
1038 struct wpabuf *beacon, *proberesp, *assocresp;
1041 if (hapd->csa_in_progress) {
1042 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
1046 hapd->beacon_set_done = 1;
1048 if (ieee802_11_build_ap_params(hapd, ¶ms) < 0)
1051 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
1055 params.beacon_ies = beacon;
1056 params.proberesp_ies = proberesp;
1057 params.assocresp_ies = assocresp;
1058 params.reenable = hapd->reenable_beacon;
1059 hapd->reenable_beacon = 0;
1061 if (iface->current_mode &&
1062 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
1063 iconf->channel, iconf->ieee80211n,
1065 iconf->secondary_channel,
1066 iconf->vht_oper_chwidth,
1067 iconf->vht_oper_centr_freq_seg0_idx,
1068 iconf->vht_oper_centr_freq_seg1_idx,
1069 iface->current_mode->vht_capab) == 0)
1070 params.freq = &freq;
1072 res = hostapd_drv_set_ap(hapd, ¶ms);
1073 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
1075 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
1079 ieee802_11_free_ap_params(¶ms);
1084 int ieee802_11_set_beacons(struct hostapd_iface *iface)
1089 for (i = 0; i < iface->num_bss; i++) {
1090 if (iface->bss[i]->started &&
1091 ieee802_11_set_beacon(iface->bss[i]) < 0)
1099 /* only update beacons if started */
1100 int ieee802_11_update_beacons(struct hostapd_iface *iface)
1105 for (i = 0; i < iface->num_bss; i++) {
1106 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
1107 ieee802_11_set_beacon(iface->bss[i]) < 0)
1114 #endif /* CONFIG_NATIVE_WINDOWS */