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 "common/hw_features_common.h"
19 #include "wps/wps_defs.h"
22 #include "ieee802_11.h"
25 #include "ap_config.h"
27 #include "p2p_hostapd.h"
28 #include "ap_drv_ops.h"
36 static u8 * hostapd_eid_rm_enabled_capab(struct hostapd_data *hapd, u8 *eid,
41 for (i = 0; i < RRM_CAPABILITIES_IE_LEN; i++) {
42 if (hapd->conf->radio_measurements[i])
46 if (i == RRM_CAPABILITIES_IE_LEN || len < 2 + RRM_CAPABILITIES_IE_LEN)
49 *eid++ = WLAN_EID_RRM_ENABLED_CAPABILITIES;
50 *eid++ = RRM_CAPABILITIES_IE_LEN;
51 os_memcpy(eid, hapd->conf->radio_measurements, RRM_CAPABILITIES_IE_LEN);
53 return eid + RRM_CAPABILITIES_IE_LEN;
57 static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
62 #ifdef CONFIG_TESTING_OPTIONS
63 if (hapd->conf->bss_load_test_set) {
64 *eid++ = WLAN_EID_BSS_LOAD;
66 os_memcpy(eid, hapd->conf->bss_load_test, 5);
70 #endif /* CONFIG_TESTING_OPTIONS */
71 if (hapd->conf->bss_load_update_period) {
72 *eid++ = WLAN_EID_BSS_LOAD;
74 WPA_PUT_LE16(eid, hapd->num_sta);
76 *eid++ = hapd->iface->channel_utilization;
77 WPA_PUT_LE16(eid, 0); /* no available admission capabity */
84 static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
88 if (hapd->iface->current_mode == NULL ||
89 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
92 if (hapd->iface->olbc)
93 erp |= ERP_INFO_USE_PROTECTION;
94 if (hapd->iface->num_sta_non_erp > 0) {
95 erp |= ERP_INFO_NON_ERP_PRESENT |
96 ERP_INFO_USE_PROTECTION;
98 if (hapd->iface->num_sta_no_short_preamble > 0 ||
99 hapd->iconf->preamble == LONG_PREAMBLE)
100 erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
106 static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
108 *eid++ = WLAN_EID_DS_PARAMS;
110 *eid++ = hapd->iconf->channel;
115 static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
117 if (hapd->iface->current_mode == NULL ||
118 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
121 /* Set NonERP_present and use_protection bits if there
122 * are any associated NonERP stations. */
123 /* TODO: use_protection bit can be set to zero even if
124 * there are NonERP stations present. This optimization
125 * might be useful if NonERP stations are "quiet".
126 * See 802.11g/D6 E-1 for recommended practice.
127 * In addition, Non ERP present might be set, if AP detects Non ERP
128 * operation on other APs. */
130 /* Add ERP Information element */
131 *eid++ = WLAN_EID_ERP_INFO;
133 *eid++ = ieee802_11_erp_info(hapd);
139 static u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid)
142 u8 local_pwr_constraint = 0;
145 if (hapd->iface->current_mode == NULL ||
146 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
149 /* Let host drivers add this IE if DFS support is offloaded */
150 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)
154 * There is no DFS support and power constraint was not directly
155 * requested by config option.
157 if (!hapd->iconf->ieee80211h &&
158 hapd->iconf->local_pwr_constraint == -1)
161 /* Check if DFS is required by regulatory. */
162 dfs = hostapd_is_dfs_required(hapd->iface);
164 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
169 if (dfs == 0 && hapd->iconf->local_pwr_constraint == -1)
173 * ieee80211h (DFS) is enabled so Power Constraint element shall
174 * be added when running on DFS channel whenever local_pwr_constraint
175 * is configured or not. In order to meet regulations when TPC is not
176 * implemented using a transmit power that is below the legal maximum
177 * (including any mitigation factor) should help. In this case,
178 * indicate 3 dB below maximum allowed transmit power.
180 if (hapd->iconf->local_pwr_constraint == -1)
181 local_pwr_constraint = 3;
184 * A STA that is not an AP shall use a transmit power less than or
185 * equal to the local maximum transmit power level for the channel.
186 * The local maximum transmit power can be calculated from the formula:
187 * local max TX pwr = max TX pwr - local pwr constraint
188 * Where max TX pwr is maximum transmit power level specified for
189 * channel in Country element and local pwr constraint is specified
190 * for channel in this Power Constraint element.
194 *pos++ = WLAN_EID_PWR_CONSTRAINT;
197 /* Local Power Constraint */
198 if (local_pwr_constraint)
199 *pos++ = local_pwr_constraint;
201 *pos++ = hapd->iconf->local_pwr_constraint;
207 static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
208 struct hostapd_channel_data *start,
209 struct hostapd_channel_data *prev)
214 /* first channel number */
215 *pos++ = start->chan;
216 /* number of channels */
217 *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
218 /* maximum transmit power level */
219 *pos++ = start->max_tx_power;
225 static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
229 u8 *end = eid + max_len;
231 struct hostapd_hw_modes *mode;
232 struct hostapd_channel_data *start, *prev;
233 int chan_spacing = 1;
235 if (!hapd->iconf->ieee80211d || max_len < 6 ||
236 hapd->iface->current_mode == NULL)
239 *pos++ = WLAN_EID_COUNTRY;
240 pos++; /* length will be set later */
241 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
244 mode = hapd->iface->current_mode;
245 if (mode->mode == HOSTAPD_MODE_IEEE80211A)
249 for (i = 0; i < mode->num_channels; i++) {
250 struct hostapd_channel_data *chan = &mode->channels[i];
251 if (chan->flag & HOSTAPD_CHAN_DISABLED)
254 prev->chan + chan_spacing == chan->chan &&
255 start->max_tx_power == chan->max_tx_power) {
257 continue; /* can use same entry */
261 pos = hostapd_eid_country_add(pos, end, chan_spacing,
266 /* Start new group */
271 pos = hostapd_eid_country_add(pos, end, chan_spacing,
275 if ((pos - eid) & 1) {
278 *pos++ = 0; /* pad for 16-bit alignment */
281 eid[1] = (pos - eid) - 2;
287 static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
292 ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
293 if (ie == NULL || ielen > len)
296 os_memcpy(eid, ie, ielen);
301 static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
303 #ifdef CONFIG_TESTING_OPTIONS
304 if (hapd->iface->cs_oper_class && hapd->iconf->ecsa_ie_only)
306 #endif /* CONFIG_TESTING_OPTIONS */
308 if (!hapd->cs_freq_params.channel)
311 *eid++ = WLAN_EID_CHANNEL_SWITCH;
313 *eid++ = hapd->cs_block_tx;
314 *eid++ = hapd->cs_freq_params.channel;
315 *eid++ = hapd->cs_count;
321 static u8 * hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid)
323 if (!hapd->cs_freq_params.channel || !hapd->iface->cs_oper_class)
326 *eid++ = WLAN_EID_EXT_CHANSWITCH_ANN;
328 *eid++ = hapd->cs_block_tx;
329 *eid++ = hapd->iface->cs_oper_class;
330 *eid++ = hapd->cs_freq_params.channel;
331 *eid++ = hapd->cs_count;
337 static u8 * hostapd_eid_supported_op_classes(struct hostapd_data *hapd, u8 *eid)
339 u8 op_class, channel;
341 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) ||
345 if (ieee80211_freq_to_channel_ext(hapd->iface->freq,
346 hapd->iconf->secondary_channel,
347 hapd->iconf->vht_oper_chwidth,
348 &op_class, &channel) ==
352 *eid++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES;
355 /* Current Operating Class */
358 /* TODO: Advertise all the supported operating classes */
365 static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
366 const struct ieee80211_mgmt *req,
367 int is_p2p, size_t *resp_len)
369 struct ieee80211_mgmt *resp;
370 u8 *pos, *epos, *csa_pos;
373 #define MAX_PROBERESP_LEN 768
374 buflen = MAX_PROBERESP_LEN;
376 if (hapd->wps_probe_resp_ie)
377 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
378 #endif /* CONFIG_WPS */
380 if (hapd->p2p_probe_resp_ie)
381 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
382 #endif /* CONFIG_P2P */
384 if (hapd->iface->fst_ies)
385 buflen += wpabuf_len(hapd->iface->fst_ies);
386 #endif /* CONFIG_FST */
387 if (hapd->conf->vendor_elements)
388 buflen += wpabuf_len(hapd->conf->vendor_elements);
389 if (hapd->conf->vendor_vht) {
390 buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
391 2 + sizeof(struct ieee80211_vht_operation);
394 buflen += hostapd_mbo_ie_len(hapd);
396 resp = os_zalloc(buflen);
400 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
402 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
403 WLAN_FC_STYPE_PROBE_RESP);
405 os_memcpy(resp->da, req->sa, ETH_ALEN);
406 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
408 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
409 resp->u.probe_resp.beacon_int =
410 host_to_le16(hapd->iconf->beacon_int);
412 /* hardware or low-level driver will setup seq_ctrl and timestamp */
413 resp->u.probe_resp.capab_info =
414 host_to_le16(hostapd_own_capab_info(hapd));
416 pos = resp->u.probe_resp.variable;
417 *pos++ = WLAN_EID_SSID;
418 *pos++ = hapd->conf->ssid.ssid_len;
419 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
420 pos += hapd->conf->ssid.ssid_len;
422 /* Supported rates */
423 pos = hostapd_eid_supp_rates(hapd, pos);
426 pos = hostapd_eid_ds_params(hapd, pos);
428 pos = hostapd_eid_country(hapd, pos, epos - pos);
430 /* Power Constraint element */
431 pos = hostapd_eid_pwr_constraint(hapd, pos);
434 csa_pos = hostapd_eid_csa(hapd, pos);
436 hapd->cs_c_off_proberesp = csa_pos - (u8 *) resp - 1;
439 /* ERP Information element */
440 pos = hostapd_eid_erp_info(hapd, pos);
442 /* Extended supported rates */
443 pos = hostapd_eid_ext_supp_rates(hapd, pos);
446 pos = hostapd_eid_wpa(hapd, pos, epos - pos);
448 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
450 pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
453 csa_pos = hostapd_eid_ecsa(hapd, pos);
455 hapd->cs_c_off_ecsa_proberesp = csa_pos - (u8 *) resp - 1;
458 pos = hostapd_eid_supported_op_classes(hapd, pos);
460 #ifdef CONFIG_IEEE80211N
461 /* Secondary Channel Offset element */
462 /* TODO: The standard doesn't specify a position for this element. */
463 pos = hostapd_eid_secondary_channel(hapd, pos);
465 pos = hostapd_eid_ht_capabilities(hapd, pos);
466 pos = hostapd_eid_ht_operation(hapd, pos);
467 #endif /* CONFIG_IEEE80211N */
469 pos = hostapd_eid_ext_capab(hapd, pos);
471 pos = hostapd_eid_time_adv(hapd, pos);
472 pos = hostapd_eid_time_zone(hapd, pos);
474 pos = hostapd_eid_interworking(hapd, pos);
475 pos = hostapd_eid_adv_proto(hapd, pos);
476 pos = hostapd_eid_roaming_consortium(hapd, pos);
479 if (hapd->iface->fst_ies) {
480 os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies),
481 wpabuf_len(hapd->iface->fst_ies));
482 pos += wpabuf_len(hapd->iface->fst_ies);
484 #endif /* CONFIG_FST */
486 #ifdef CONFIG_IEEE80211AC
487 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
488 pos = hostapd_eid_vht_capabilities(hapd, pos);
489 pos = hostapd_eid_vht_operation(hapd, pos);
490 pos = hostapd_eid_txpower_envelope(hapd, pos);
491 pos = hostapd_eid_wb_chsw_wrapper(hapd, pos);
493 if (hapd->conf->vendor_vht)
494 pos = hostapd_eid_vendor_vht(hapd, pos);
495 #endif /* CONFIG_IEEE80211AC */
497 /* Wi-Fi Alliance WMM */
498 pos = hostapd_eid_wmm(hapd, pos);
501 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
502 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
503 wpabuf_len(hapd->wps_probe_resp_ie));
504 pos += wpabuf_len(hapd->wps_probe_resp_ie);
506 #endif /* CONFIG_WPS */
509 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
510 hapd->p2p_probe_resp_ie) {
511 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
512 wpabuf_len(hapd->p2p_probe_resp_ie));
513 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
515 #endif /* CONFIG_P2P */
516 #ifdef CONFIG_P2P_MANAGER
517 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
519 pos = hostapd_eid_p2p_manage(hapd, pos);
520 #endif /* CONFIG_P2P_MANAGER */
523 pos = hostapd_eid_hs20_indication(hapd, pos);
524 pos = hostapd_eid_osen(hapd, pos);
525 #endif /* CONFIG_HS20 */
527 pos = hostapd_eid_mbo(hapd, pos, (u8 *) resp + buflen - pos);
529 if (hapd->conf->vendor_elements) {
530 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
531 wpabuf_len(hapd->conf->vendor_elements));
532 pos += wpabuf_len(hapd->conf->vendor_elements);
535 *resp_len = pos - (u8 *) resp;
540 enum ssid_match_result {
546 static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
547 const u8 *ssid, size_t ssid_len,
549 size_t ssid_list_len)
556 if (ssid_len == hapd->conf->ssid.ssid_len &&
557 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
558 return EXACT_SSID_MATCH;
560 if (ssid_list == NULL)
561 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
564 end = ssid_list + ssid_list_len;
565 while (end - pos >= 1) {
566 if (2 + pos[1] > end - pos)
570 if (pos[1] == hapd->conf->ssid.ssid_len &&
571 os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0)
572 return EXACT_SSID_MATCH;
576 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
580 void sta_track_expire(struct hostapd_iface *iface, int force)
582 struct os_reltime now;
583 struct hostapd_sta_info *info;
585 if (!iface->num_sta_seen)
588 os_get_reltime(&now);
589 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
592 !os_reltime_expired(&now, &info->last_seen,
593 iface->conf->track_sta_max_age))
597 wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
598 MACSTR, iface->bss[0]->conf->iface,
599 MAC2STR(info->addr));
600 dl_list_del(&info->list);
601 iface->num_sta_seen--;
607 static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
610 struct hostapd_sta_info *info;
612 dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
613 if (os_memcmp(addr, info->addr, ETH_ALEN) == 0)
620 void sta_track_add(struct hostapd_iface *iface, const u8 *addr)
622 struct hostapd_sta_info *info;
624 info = sta_track_get(iface, addr);
626 /* Move the most recent entry to the end of the list */
627 dl_list_del(&info->list);
628 dl_list_add_tail(&iface->sta_seen, &info->list);
629 os_get_reltime(&info->last_seen);
633 /* Add a new entry */
634 info = os_zalloc(sizeof(*info));
635 os_memcpy(info->addr, addr, ETH_ALEN);
636 os_get_reltime(&info->last_seen);
638 if (iface->num_sta_seen >= iface->conf->track_sta_max_num) {
639 /* Expire oldest entry to make room for a new one */
640 sta_track_expire(iface, 1);
643 wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
644 MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr));
645 dl_list_add_tail(&iface->sta_seen, &info->list);
646 iface->num_sta_seen++;
650 struct hostapd_data *
651 sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
654 struct hapd_interfaces *interfaces = iface->interfaces;
657 for (i = 0; i < interfaces->count; i++) {
658 struct hostapd_data *hapd = NULL;
660 iface = interfaces->iface[i];
661 for (j = 0; j < iface->num_bss; j++) {
662 hapd = iface->bss[j];
663 if (os_strcmp(ifname, hapd->conf->iface) == 0)
668 if (hapd && sta_track_get(iface, addr))
676 void handle_probe_req(struct hostapd_data *hapd,
677 const struct ieee80211_mgmt *mgmt, size_t len,
681 struct ieee802_11_elems elems;
686 enum ssid_match_result res;
691 if (len < IEEE80211_HDRLEN)
693 ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN;
694 if (hapd->iconf->track_sta_max_num)
695 sta_track_add(hapd->iface, mgmt->sa);
696 ie_len = len - IEEE80211_HDRLEN;
698 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
699 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
700 mgmt->sa, mgmt->da, mgmt->bssid,
701 ie, ie_len, ssi_signal) > 0)
704 if (!hapd->iconf->send_probe_response)
707 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
708 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
713 if ((!elems.ssid || !elems.supp_rates)) {
714 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
715 "without SSID or supported rates element",
721 * No need to reply if the Probe Request frame was sent on an adjacent
722 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
723 * AP with dot11RadioMeasurementActivated set to true, but strictly
724 * speaking does not allow such ignoring of Probe Request frames if
725 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
726 * number of unnecessary Probe Response frames for cases where the STA
727 * is less likely to see them (Probe Request frame sent on a
728 * neighboring, but partially overlapping, channel).
730 if (elems.ds_params &&
731 hapd->iface->current_mode &&
732 (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
733 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
734 hapd->iconf->channel != elems.ds_params[0]) {
735 wpa_printf(MSG_DEBUG,
736 "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
737 hapd->iconf->channel, elems.ds_params[0]);
742 if (hapd->p2p && hapd->p2p_group && elems.wps_ie) {
744 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
745 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
746 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
747 "due to mismatch with Requested Device "
755 if (hapd->p2p && hapd->p2p_group && elems.p2p) {
757 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
758 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
759 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
760 "due to mismatch with Device ID");
766 #endif /* CONFIG_P2P */
768 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
769 elems.ssid_list_len == 0) {
770 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
771 "broadcast SSID ignored", MAC2STR(mgmt->sa));
776 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
777 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
778 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
779 P2P_WILDCARD_SSID_LEN) == 0) {
780 /* Process P2P Wildcard SSID like Wildcard SSID */
783 #endif /* CONFIG_P2P */
785 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
786 elems.ssid_list, elems.ssid_list_len);
787 if (res == NO_SSID_MATCH) {
788 if (!(mgmt->da[0] & 0x01)) {
789 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
790 " for foreign SSID '%s' (DA " MACSTR ")%s",
792 wpa_ssid_txt(elems.ssid, elems.ssid_len),
794 elems.ssid_list ? " (SSID list)" : "");
799 #ifdef CONFIG_INTERWORKING
800 if (hapd->conf->interworking &&
801 elems.interworking && elems.interworking_len >= 1) {
802 u8 ant = elems.interworking[0] & 0x0f;
803 if (ant != INTERWORKING_ANT_WILDCARD &&
804 ant != hapd->conf->access_network_type) {
805 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
806 " for mismatching ANT %u ignored",
807 MAC2STR(mgmt->sa), ant);
812 if (hapd->conf->interworking && elems.interworking &&
813 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
815 if (elems.interworking_len == 7)
816 hessid = elems.interworking + 1;
818 hessid = elems.interworking + 1 + 2;
819 if (!is_broadcast_ether_addr(hessid) &&
820 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
821 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
822 " for mismatching HESSID " MACSTR
824 MAC2STR(mgmt->sa), MAC2STR(hessid));
828 #endif /* CONFIG_INTERWORKING */
831 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
832 supp_rates_11b_only(&elems)) {
833 /* Indicates support for 11b rates only */
834 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
835 MACSTR " with only 802.11b rates",
839 #endif /* CONFIG_P2P */
841 /* TODO: verify that supp_rates contains at least one matching rate
842 * with AP configuration */
844 if (hapd->conf->no_probe_resp_if_seen_on &&
845 is_multicast_ether_addr(mgmt->da) &&
846 is_multicast_ether_addr(mgmt->bssid) &&
847 sta_track_seen_on(hapd->iface, mgmt->sa,
848 hapd->conf->no_probe_resp_if_seen_on)) {
849 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
850 " since STA has been seen on %s",
851 hapd->conf->iface, MAC2STR(mgmt->sa),
852 hapd->conf->no_probe_resp_if_seen_on);
856 if (hapd->conf->no_probe_resp_if_max_sta &&
857 is_multicast_ether_addr(mgmt->da) &&
858 is_multicast_ether_addr(mgmt->bssid) &&
859 hapd->num_sta >= hapd->conf->max_num_sta &&
860 !ap_get_sta(hapd, mgmt->sa)) {
861 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
862 " since no room for additional STA",
863 hapd->conf->iface, MAC2STR(mgmt->sa));
867 #ifdef CONFIG_TESTING_OPTIONS
868 if (hapd->iconf->ignore_probe_probability > 0.0 &&
869 drand48() < hapd->iconf->ignore_probe_probability) {
871 "TESTING: ignoring probe request from " MACSTR,
875 #endif /* CONFIG_TESTING_OPTIONS */
877 resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL,
883 * If this is a broadcast probe request, apply no ack policy to avoid
886 noack = !!(res == WILDCARD_SSID_MATCH &&
887 is_broadcast_ether_addr(mgmt->da));
890 if (hapd->csa_in_progress) {
891 if (hapd->cs_c_off_proberesp)
892 csa_offs[csa_offs_len++] =
893 hapd->cs_c_off_proberesp;
895 if (hapd->cs_c_off_ecsa_proberesp)
896 csa_offs[csa_offs_len++] =
897 hapd->cs_c_off_ecsa_proberesp;
900 ret = hostapd_drv_send_mlme_csa(hapd, resp, resp_len, noack,
901 csa_offs_len ? csa_offs : NULL,
905 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
909 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
910 "SSID", MAC2STR(mgmt->sa),
911 elems.ssid_len == 0 ? "broadcast" : "our");
915 static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
918 /* check probe response offloading caps and print warnings */
919 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
923 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
924 (!(hapd->iface->probe_resp_offloads &
925 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
926 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
927 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
928 "Probe Response while not supporting this");
929 #endif /* CONFIG_WPS */
932 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
933 !(hapd->iface->probe_resp_offloads &
934 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
935 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
936 "Probe Response while not supporting this");
937 #endif /* CONFIG_P2P */
939 if (hapd->conf->interworking &&
940 !(hapd->iface->probe_resp_offloads &
941 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
942 wpa_printf(MSG_WARNING, "Device is trying to offload "
943 "Interworking Probe Response while not supporting "
946 /* Generate a Probe Response template for the non-P2P case */
947 return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len);
950 #endif /* NEED_AP_MLME */
953 int ieee802_11_build_ap_params(struct hostapd_data *hapd,
954 struct wpa_driver_ap_params *params)
956 struct ieee80211_mgmt *head = NULL;
958 size_t head_len = 0, tail_len = 0;
963 u8 *pos, *tailpos, *csa_pos;
965 #define BEACON_HEAD_BUF_SIZE 256
966 #define BEACON_TAIL_BUF_SIZE 512
967 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
968 tail_len = BEACON_TAIL_BUF_SIZE;
970 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
971 tail_len += wpabuf_len(hapd->wps_beacon_ie);
972 #endif /* CONFIG_WPS */
974 if (hapd->p2p_beacon_ie)
975 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
976 #endif /* CONFIG_P2P */
978 if (hapd->iface->fst_ies)
979 tail_len += wpabuf_len(hapd->iface->fst_ies);
980 #endif /* CONFIG_FST */
981 if (hapd->conf->vendor_elements)
982 tail_len += wpabuf_len(hapd->conf->vendor_elements);
984 #ifdef CONFIG_IEEE80211AC
985 if (hapd->conf->vendor_vht) {
986 tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
987 2 + sizeof(struct ieee80211_vht_operation);
989 #endif /* CONFIG_IEEE80211AC */
991 tail_len += hostapd_mbo_ie_len(hapd);
993 tailpos = tail = os_malloc(tail_len);
994 if (head == NULL || tail == NULL) {
995 wpa_printf(MSG_ERROR, "Failed to set beacon data");
1001 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1002 WLAN_FC_STYPE_BEACON);
1003 head->duration = host_to_le16(0);
1004 os_memset(head->da, 0xff, ETH_ALEN);
1006 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1007 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1008 head->u.beacon.beacon_int =
1009 host_to_le16(hapd->iconf->beacon_int);
1011 /* hardware or low-level driver will setup seq_ctrl and timestamp */
1012 capab_info = hostapd_own_capab_info(hapd);
1013 head->u.beacon.capab_info = host_to_le16(capab_info);
1014 pos = &head->u.beacon.variable[0];
1017 *pos++ = WLAN_EID_SSID;
1018 if (hapd->conf->ignore_broadcast_ssid == 2) {
1019 /* clear the data, but keep the correct length of the SSID */
1020 *pos++ = hapd->conf->ssid.ssid_len;
1021 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
1022 pos += hapd->conf->ssid.ssid_len;
1023 } else if (hapd->conf->ignore_broadcast_ssid) {
1024 *pos++ = 0; /* empty SSID */
1026 *pos++ = hapd->conf->ssid.ssid_len;
1027 os_memcpy(pos, hapd->conf->ssid.ssid,
1028 hapd->conf->ssid.ssid_len);
1029 pos += hapd->conf->ssid.ssid_len;
1032 /* Supported rates */
1033 pos = hostapd_eid_supp_rates(hapd, pos);
1036 pos = hostapd_eid_ds_params(hapd, pos);
1038 head_len = pos - (u8 *) head;
1040 tailpos = hostapd_eid_country(hapd, tailpos,
1041 tail + BEACON_TAIL_BUF_SIZE - tailpos);
1043 /* Power Constraint element */
1044 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
1047 csa_pos = hostapd_eid_csa(hapd, tailpos);
1048 if (csa_pos != tailpos)
1049 hapd->cs_c_off_beacon = csa_pos - tail - 1;
1052 /* ERP Information element */
1053 tailpos = hostapd_eid_erp_info(hapd, tailpos);
1055 /* Extended supported rates */
1056 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
1058 /* RSN, MDIE, WPA */
1059 tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
1062 tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
1063 tail + BEACON_TAIL_BUF_SIZE -
1066 tailpos = hostapd_eid_bss_load(hapd, tailpos,
1067 tail + BEACON_TAIL_BUF_SIZE - tailpos);
1070 csa_pos = hostapd_eid_ecsa(hapd, tailpos);
1071 if (csa_pos != tailpos)
1072 hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1;
1075 tailpos = hostapd_eid_supported_op_classes(hapd, tailpos);
1077 #ifdef CONFIG_IEEE80211N
1078 /* Secondary Channel Offset element */
1079 /* TODO: The standard doesn't specify a position for this element. */
1080 tailpos = hostapd_eid_secondary_channel(hapd, tailpos);
1082 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
1083 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
1084 #endif /* CONFIG_IEEE80211N */
1086 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
1089 * TODO: Time Advertisement element should only be included in some
1090 * DTIM Beacon frames.
1092 tailpos = hostapd_eid_time_adv(hapd, tailpos);
1094 tailpos = hostapd_eid_interworking(hapd, tailpos);
1095 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
1096 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
1099 if (hapd->iface->fst_ies) {
1100 os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies),
1101 wpabuf_len(hapd->iface->fst_ies));
1102 tailpos += wpabuf_len(hapd->iface->fst_ies);
1104 #endif /* CONFIG_FST */
1106 #ifdef CONFIG_IEEE80211AC
1107 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
1108 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos);
1109 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
1110 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
1111 tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos);
1113 if (hapd->conf->vendor_vht)
1114 tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
1115 #endif /* CONFIG_IEEE80211AC */
1117 /* Wi-Fi Alliance WMM */
1118 tailpos = hostapd_eid_wmm(hapd, tailpos);
1121 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
1122 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
1123 wpabuf_len(hapd->wps_beacon_ie));
1124 tailpos += wpabuf_len(hapd->wps_beacon_ie);
1126 #endif /* CONFIG_WPS */
1129 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
1130 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
1131 wpabuf_len(hapd->p2p_beacon_ie));
1132 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
1134 #endif /* CONFIG_P2P */
1135 #ifdef CONFIG_P2P_MANAGER
1136 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
1138 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
1139 #endif /* CONFIG_P2P_MANAGER */
1142 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
1143 tailpos = hostapd_eid_osen(hapd, tailpos);
1144 #endif /* CONFIG_HS20 */
1146 tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos);
1148 if (hapd->conf->vendor_elements) {
1149 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
1150 wpabuf_len(hapd->conf->vendor_elements));
1151 tailpos += wpabuf_len(hapd->conf->vendor_elements);
1154 tail_len = tailpos > tail ? tailpos - tail : 0;
1156 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
1157 #endif /* NEED_AP_MLME */
1159 os_memset(params, 0, sizeof(*params));
1160 params->head = (u8 *) head;
1161 params->head_len = head_len;
1162 params->tail = tail;
1163 params->tail_len = tail_len;
1164 params->proberesp = resp;
1165 params->proberesp_len = resp_len;
1166 params->dtim_period = hapd->conf->dtim_period;
1167 params->beacon_int = hapd->iconf->beacon_int;
1168 params->basic_rates = hapd->iface->basic_rates;
1169 params->ssid = hapd->conf->ssid.ssid;
1170 params->ssid_len = hapd->conf->ssid.ssid_len;
1171 if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
1172 (WPA_PROTO_WPA | WPA_PROTO_RSN))
1173 params->pairwise_ciphers = hapd->conf->wpa_pairwise |
1174 hapd->conf->rsn_pairwise;
1175 else if (hapd->conf->wpa & WPA_PROTO_RSN)
1176 params->pairwise_ciphers = hapd->conf->rsn_pairwise;
1177 else if (hapd->conf->wpa & WPA_PROTO_WPA)
1178 params->pairwise_ciphers = hapd->conf->wpa_pairwise;
1179 params->group_cipher = hapd->conf->wpa_group;
1180 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
1181 params->auth_algs = hapd->conf->auth_algs;
1182 params->wpa_version = hapd->conf->wpa;
1183 params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
1184 (hapd->conf->ieee802_1x &&
1185 (hapd->conf->default_wep_key_len ||
1186 hapd->conf->individual_wep_key_len));
1187 switch (hapd->conf->ignore_broadcast_ssid) {
1189 params->hide_ssid = NO_SSID_HIDING;
1192 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
1195 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
1198 params->isolate = hapd->conf->isolate;
1199 params->smps_mode = hapd->iconf->ht_capab & HT_CAP_INFO_SMPS_MASK;
1201 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
1202 ERP_INFO_USE_PROTECTION);
1203 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
1204 hapd->iconf->preamble == SHORT_PREAMBLE;
1205 if (hapd->iface->current_mode &&
1206 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1207 params->short_slot_time =
1208 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
1210 params->short_slot_time = -1;
1211 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
1212 params->ht_opmode = -1;
1214 params->ht_opmode = hapd->iface->ht_op_mode;
1215 #endif /* NEED_AP_MLME */
1216 params->interworking = hapd->conf->interworking;
1217 if (hapd->conf->interworking &&
1218 !is_zero_ether_addr(hapd->conf->hessid))
1219 params->hessid = hapd->conf->hessid;
1220 params->access_network_type = hapd->conf->access_network_type;
1221 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
1223 params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
1224 #endif /* CONFIG_P2P */
1226 params->disable_dgaf = hapd->conf->disable_dgaf;
1227 if (hapd->conf->osen) {
1228 params->privacy = 1;
1231 #endif /* CONFIG_HS20 */
1232 params->pbss = hapd->conf->pbss;
1237 void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
1239 os_free(params->tail);
1240 params->tail = NULL;
1241 os_free(params->head);
1242 params->head = NULL;
1243 os_free(params->proberesp);
1244 params->proberesp = NULL;
1248 int ieee802_11_set_beacon(struct hostapd_data *hapd)
1250 struct wpa_driver_ap_params params;
1251 struct hostapd_freq_params freq;
1252 struct hostapd_iface *iface = hapd->iface;
1253 struct hostapd_config *iconf = iface->conf;
1254 struct wpabuf *beacon, *proberesp, *assocresp;
1257 if (hapd->csa_in_progress) {
1258 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
1262 hapd->beacon_set_done = 1;
1264 if (ieee802_11_build_ap_params(hapd, ¶ms) < 0)
1267 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
1271 params.beacon_ies = beacon;
1272 params.proberesp_ies = proberesp;
1273 params.assocresp_ies = assocresp;
1274 params.reenable = hapd->reenable_beacon;
1275 hapd->reenable_beacon = 0;
1277 if (iface->current_mode &&
1278 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
1279 iconf->channel, iconf->ieee80211n,
1281 iconf->secondary_channel,
1282 iconf->vht_oper_chwidth,
1283 iconf->vht_oper_centr_freq_seg0_idx,
1284 iconf->vht_oper_centr_freq_seg1_idx,
1285 iface->current_mode->vht_capab) == 0)
1286 params.freq = &freq;
1288 res = hostapd_drv_set_ap(hapd, ¶ms);
1289 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
1291 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
1295 ieee802_11_free_ap_params(¶ms);
1300 int ieee802_11_set_beacons(struct hostapd_iface *iface)
1305 for (i = 0; i < iface->num_bss; i++) {
1306 if (iface->bss[i]->started &&
1307 ieee802_11_set_beacon(iface->bss[i]) < 0)
1315 /* only update beacons if started */
1316 int ieee802_11_update_beacons(struct hostapd_iface *iface)
1321 for (i = 0; i < iface->num_bss; i++) {
1322 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
1323 ieee802_11_set_beacon(iface->bss[i]) < 0)
1330 #endif /* CONFIG_NATIVE_WINDOWS */