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"
37 static u8 * hostapd_eid_rm_enabled_capab(struct hostapd_data *hapd, u8 *eid,
42 for (i = 0; i < RRM_CAPABILITIES_IE_LEN; i++) {
43 if (hapd->conf->radio_measurements[i])
47 if (i == RRM_CAPABILITIES_IE_LEN || len < 2 + RRM_CAPABILITIES_IE_LEN)
50 *eid++ = WLAN_EID_RRM_ENABLED_CAPABILITIES;
51 *eid++ = RRM_CAPABILITIES_IE_LEN;
52 os_memcpy(eid, hapd->conf->radio_measurements, RRM_CAPABILITIES_IE_LEN);
54 return eid + RRM_CAPABILITIES_IE_LEN;
58 static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
63 #ifdef CONFIG_TESTING_OPTIONS
64 if (hapd->conf->bss_load_test_set) {
65 *eid++ = WLAN_EID_BSS_LOAD;
67 os_memcpy(eid, hapd->conf->bss_load_test, 5);
71 #endif /* CONFIG_TESTING_OPTIONS */
72 if (hapd->conf->bss_load_update_period) {
73 *eid++ = WLAN_EID_BSS_LOAD;
75 WPA_PUT_LE16(eid, hapd->num_sta);
77 *eid++ = hapd->iface->channel_utilization;
78 WPA_PUT_LE16(eid, 0); /* no available admission capabity */
85 static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
89 if (hapd->iface->current_mode == NULL ||
90 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
93 if (hapd->iface->olbc)
94 erp |= ERP_INFO_USE_PROTECTION;
95 if (hapd->iface->num_sta_non_erp > 0) {
96 erp |= ERP_INFO_NON_ERP_PRESENT |
97 ERP_INFO_USE_PROTECTION;
99 if (hapd->iface->num_sta_no_short_preamble > 0 ||
100 hapd->iconf->preamble == LONG_PREAMBLE)
101 erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
107 static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
109 *eid++ = WLAN_EID_DS_PARAMS;
111 *eid++ = hapd->iconf->channel;
116 static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
118 if (hapd->iface->current_mode == NULL ||
119 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
122 /* Set NonERP_present and use_protection bits if there
123 * are any associated NonERP stations. */
124 /* TODO: use_protection bit can be set to zero even if
125 * there are NonERP stations present. This optimization
126 * might be useful if NonERP stations are "quiet".
127 * See 802.11g/D6 E-1 for recommended practice.
128 * In addition, Non ERP present might be set, if AP detects Non ERP
129 * operation on other APs. */
131 /* Add ERP Information element */
132 *eid++ = WLAN_EID_ERP_INFO;
134 *eid++ = ieee802_11_erp_info(hapd);
140 static u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid)
143 u8 local_pwr_constraint = 0;
146 if (hapd->iface->current_mode == NULL ||
147 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
150 /* Let host drivers add this IE if DFS support is offloaded */
151 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)
155 * There is no DFS support and power constraint was not directly
156 * requested by config option.
158 if (!hapd->iconf->ieee80211h &&
159 hapd->iconf->local_pwr_constraint == -1)
162 /* Check if DFS is required by regulatory. */
163 dfs = hostapd_is_dfs_required(hapd->iface);
165 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
170 if (dfs == 0 && hapd->iconf->local_pwr_constraint == -1)
174 * ieee80211h (DFS) is enabled so Power Constraint element shall
175 * be added when running on DFS channel whenever local_pwr_constraint
176 * is configured or not. In order to meet regulations when TPC is not
177 * implemented using a transmit power that is below the legal maximum
178 * (including any mitigation factor) should help. In this case,
179 * indicate 3 dB below maximum allowed transmit power.
181 if (hapd->iconf->local_pwr_constraint == -1)
182 local_pwr_constraint = 3;
185 * A STA that is not an AP shall use a transmit power less than or
186 * equal to the local maximum transmit power level for the channel.
187 * The local maximum transmit power can be calculated from the formula:
188 * local max TX pwr = max TX pwr - local pwr constraint
189 * Where max TX pwr is maximum transmit power level specified for
190 * channel in Country element and local pwr constraint is specified
191 * for channel in this Power Constraint element.
195 *pos++ = WLAN_EID_PWR_CONSTRAINT;
198 /* Local Power Constraint */
199 if (local_pwr_constraint)
200 *pos++ = local_pwr_constraint;
202 *pos++ = hapd->iconf->local_pwr_constraint;
208 static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
209 struct hostapd_channel_data *start,
210 struct hostapd_channel_data *prev)
215 /* first channel number */
216 *pos++ = start->chan;
217 /* number of channels */
218 *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
219 /* maximum transmit power level */
220 *pos++ = start->max_tx_power;
226 static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
230 u8 *end = eid + max_len;
232 struct hostapd_hw_modes *mode;
233 struct hostapd_channel_data *start, *prev;
234 int chan_spacing = 1;
236 if (!hapd->iconf->ieee80211d || max_len < 6 ||
237 hapd->iface->current_mode == NULL)
240 *pos++ = WLAN_EID_COUNTRY;
241 pos++; /* length will be set later */
242 os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
245 mode = hapd->iface->current_mode;
246 if (mode->mode == HOSTAPD_MODE_IEEE80211A)
250 for (i = 0; i < mode->num_channels; i++) {
251 struct hostapd_channel_data *chan = &mode->channels[i];
252 if (chan->flag & HOSTAPD_CHAN_DISABLED)
255 prev->chan + chan_spacing == chan->chan &&
256 start->max_tx_power == chan->max_tx_power) {
258 continue; /* can use same entry */
262 pos = hostapd_eid_country_add(pos, end, chan_spacing,
267 /* Start new group */
272 pos = hostapd_eid_country_add(pos, end, chan_spacing,
276 if ((pos - eid) & 1) {
279 *pos++ = 0; /* pad for 16-bit alignment */
282 eid[1] = (pos - eid) - 2;
288 static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
293 ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
294 if (ie == NULL || ielen > len)
297 os_memcpy(eid, ie, ielen);
302 static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
304 #ifdef CONFIG_TESTING_OPTIONS
305 if (hapd->iface->cs_oper_class && hapd->iconf->ecsa_ie_only)
307 #endif /* CONFIG_TESTING_OPTIONS */
309 if (!hapd->cs_freq_params.channel)
312 *eid++ = WLAN_EID_CHANNEL_SWITCH;
314 *eid++ = hapd->cs_block_tx;
315 *eid++ = hapd->cs_freq_params.channel;
316 *eid++ = hapd->cs_count;
322 static u8 * hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid)
324 if (!hapd->cs_freq_params.channel || !hapd->iface->cs_oper_class)
327 *eid++ = WLAN_EID_EXT_CHANSWITCH_ANN;
329 *eid++ = hapd->cs_block_tx;
330 *eid++ = hapd->iface->cs_oper_class;
331 *eid++ = hapd->cs_freq_params.channel;
332 *eid++ = hapd->cs_count;
338 static u8 * hostapd_eid_supported_op_classes(struct hostapd_data *hapd, u8 *eid)
340 u8 op_class, channel;
342 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) ||
346 if (ieee80211_freq_to_channel_ext(hapd->iface->freq,
347 hapd->iconf->secondary_channel,
348 hapd->iconf->vht_oper_chwidth,
349 &op_class, &channel) ==
353 *eid++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES;
356 /* Current Operating Class */
359 /* TODO: Advertise all the supported operating classes */
366 static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
367 const struct ieee80211_mgmt *req,
368 int is_p2p, size_t *resp_len)
370 struct ieee80211_mgmt *resp;
371 u8 *pos, *epos, *csa_pos;
374 #define MAX_PROBERESP_LEN 768
375 buflen = MAX_PROBERESP_LEN;
377 if (hapd->wps_probe_resp_ie)
378 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
379 #endif /* CONFIG_WPS */
381 if (hapd->p2p_probe_resp_ie)
382 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
383 #endif /* CONFIG_P2P */
385 if (hapd->iface->fst_ies)
386 buflen += wpabuf_len(hapd->iface->fst_ies);
387 #endif /* CONFIG_FST */
388 if (hapd->conf->vendor_elements)
389 buflen += wpabuf_len(hapd->conf->vendor_elements);
390 if (hapd->conf->vendor_vht) {
391 buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
392 2 + sizeof(struct ieee80211_vht_operation);
395 buflen += hostapd_mbo_ie_len(hapd);
397 resp = os_zalloc(buflen);
401 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
403 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
404 WLAN_FC_STYPE_PROBE_RESP);
406 os_memcpy(resp->da, req->sa, ETH_ALEN);
407 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
409 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
410 resp->u.probe_resp.beacon_int =
411 host_to_le16(hapd->iconf->beacon_int);
413 /* hardware or low-level driver will setup seq_ctrl and timestamp */
414 resp->u.probe_resp.capab_info =
415 host_to_le16(hostapd_own_capab_info(hapd));
417 pos = resp->u.probe_resp.variable;
418 *pos++ = WLAN_EID_SSID;
419 *pos++ = hapd->conf->ssid.ssid_len;
420 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
421 pos += hapd->conf->ssid.ssid_len;
423 /* Supported rates */
424 pos = hostapd_eid_supp_rates(hapd, pos);
427 pos = hostapd_eid_ds_params(hapd, pos);
429 pos = hostapd_eid_country(hapd, pos, epos - pos);
431 /* Power Constraint element */
432 pos = hostapd_eid_pwr_constraint(hapd, pos);
435 csa_pos = hostapd_eid_csa(hapd, pos);
437 hapd->cs_c_off_proberesp = csa_pos - (u8 *) resp - 1;
440 /* ERP Information element */
441 pos = hostapd_eid_erp_info(hapd, pos);
443 /* Extended supported rates */
444 pos = hostapd_eid_ext_supp_rates(hapd, pos);
447 pos = hostapd_eid_wpa(hapd, pos, epos - pos);
449 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
451 pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
454 csa_pos = hostapd_eid_ecsa(hapd, pos);
456 hapd->cs_c_off_ecsa_proberesp = csa_pos - (u8 *) resp - 1;
459 pos = hostapd_eid_supported_op_classes(hapd, pos);
461 #ifdef CONFIG_IEEE80211N
462 /* Secondary Channel Offset element */
463 /* TODO: The standard doesn't specify a position for this element. */
464 pos = hostapd_eid_secondary_channel(hapd, pos);
466 pos = hostapd_eid_ht_capabilities(hapd, pos);
467 pos = hostapd_eid_ht_operation(hapd, pos);
468 #endif /* CONFIG_IEEE80211N */
470 pos = hostapd_eid_ext_capab(hapd, pos);
472 pos = hostapd_eid_time_adv(hapd, pos);
473 pos = hostapd_eid_time_zone(hapd, pos);
475 pos = hostapd_eid_interworking(hapd, pos);
476 pos = hostapd_eid_adv_proto(hapd, pos);
477 pos = hostapd_eid_roaming_consortium(hapd, pos);
480 if (hapd->iface->fst_ies) {
481 os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies),
482 wpabuf_len(hapd->iface->fst_ies));
483 pos += wpabuf_len(hapd->iface->fst_ies);
485 #endif /* CONFIG_FST */
487 #ifdef CONFIG_IEEE80211AC
488 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
489 pos = hostapd_eid_vht_capabilities(hapd, pos, 0);
490 pos = hostapd_eid_vht_operation(hapd, pos);
491 pos = hostapd_eid_txpower_envelope(hapd, pos);
492 pos = hostapd_eid_wb_chsw_wrapper(hapd, pos);
494 if (hapd->conf->vendor_vht)
495 pos = hostapd_eid_vendor_vht(hapd, pos);
496 #endif /* CONFIG_IEEE80211AC */
498 /* Wi-Fi Alliance WMM */
499 pos = hostapd_eid_wmm(hapd, pos);
502 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
503 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
504 wpabuf_len(hapd->wps_probe_resp_ie));
505 pos += wpabuf_len(hapd->wps_probe_resp_ie);
507 #endif /* CONFIG_WPS */
510 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
511 hapd->p2p_probe_resp_ie) {
512 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
513 wpabuf_len(hapd->p2p_probe_resp_ie));
514 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
516 #endif /* CONFIG_P2P */
517 #ifdef CONFIG_P2P_MANAGER
518 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
520 pos = hostapd_eid_p2p_manage(hapd, pos);
521 #endif /* CONFIG_P2P_MANAGER */
524 pos = hostapd_eid_hs20_indication(hapd, pos);
525 pos = hostapd_eid_osen(hapd, pos);
526 #endif /* CONFIG_HS20 */
528 pos = hostapd_eid_mbo(hapd, pos, (u8 *) resp + buflen - pos);
530 if (hapd->conf->vendor_elements) {
531 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
532 wpabuf_len(hapd->conf->vendor_elements));
533 pos += wpabuf_len(hapd->conf->vendor_elements);
536 *resp_len = pos - (u8 *) resp;
541 enum ssid_match_result {
547 static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
548 const u8 *ssid, size_t ssid_len,
550 size_t ssid_list_len)
557 if (ssid_len == hapd->conf->ssid.ssid_len &&
558 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
559 return EXACT_SSID_MATCH;
561 if (ssid_list == NULL)
562 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
565 end = ssid_list + ssid_list_len;
566 while (end - pos >= 1) {
567 if (2 + pos[1] > end - pos)
571 if (pos[1] == hapd->conf->ssid.ssid_len &&
572 os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0)
573 return EXACT_SSID_MATCH;
577 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
581 void sta_track_expire(struct hostapd_iface *iface, int force)
583 struct os_reltime now;
584 struct hostapd_sta_info *info;
586 if (!iface->num_sta_seen)
589 os_get_reltime(&now);
590 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
593 !os_reltime_expired(&now, &info->last_seen,
594 iface->conf->track_sta_max_age))
598 wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
599 MACSTR, iface->bss[0]->conf->iface,
600 MAC2STR(info->addr));
601 dl_list_del(&info->list);
602 iface->num_sta_seen--;
608 static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
611 struct hostapd_sta_info *info;
613 dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
614 if (os_memcmp(addr, info->addr, ETH_ALEN) == 0)
621 void sta_track_add(struct hostapd_iface *iface, const u8 *addr)
623 struct hostapd_sta_info *info;
625 info = sta_track_get(iface, addr);
627 /* Move the most recent entry to the end of the list */
628 dl_list_del(&info->list);
629 dl_list_add_tail(&iface->sta_seen, &info->list);
630 os_get_reltime(&info->last_seen);
634 /* Add a new entry */
635 info = os_zalloc(sizeof(*info));
638 os_memcpy(info->addr, addr, ETH_ALEN);
639 os_get_reltime(&info->last_seen);
641 if (iface->num_sta_seen >= iface->conf->track_sta_max_num) {
642 /* Expire oldest entry to make room for a new one */
643 sta_track_expire(iface, 1);
646 wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
647 MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr));
648 dl_list_add_tail(&iface->sta_seen, &info->list);
649 iface->num_sta_seen++;
653 struct hostapd_data *
654 sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
657 struct hapd_interfaces *interfaces = iface->interfaces;
660 for (i = 0; i < interfaces->count; i++) {
661 struct hostapd_data *hapd = NULL;
663 iface = interfaces->iface[i];
664 for (j = 0; j < iface->num_bss; j++) {
665 hapd = iface->bss[j];
666 if (os_strcmp(ifname, hapd->conf->iface) == 0)
671 if (hapd && sta_track_get(iface, addr))
679 #ifdef CONFIG_TAXONOMY
680 void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr,
681 struct wpabuf **probe_ie_taxonomy)
683 struct hostapd_sta_info *info;
685 info = sta_track_get(iface, addr);
689 wpabuf_free(*probe_ie_taxonomy);
690 *probe_ie_taxonomy = info->probe_ie_taxonomy;
691 info->probe_ie_taxonomy = NULL;
693 #endif /* CONFIG_TAXONOMY */
696 void handle_probe_req(struct hostapd_data *hapd,
697 const struct ieee80211_mgmt *mgmt, size_t len,
701 struct ieee802_11_elems elems;
706 enum ssid_match_result res;
711 if (len < IEEE80211_HDRLEN)
713 ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN;
714 if (hapd->iconf->track_sta_max_num)
715 sta_track_add(hapd->iface, mgmt->sa);
716 ie_len = len - IEEE80211_HDRLEN;
718 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
719 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
720 mgmt->sa, mgmt->da, mgmt->bssid,
721 ie, ie_len, ssi_signal) > 0)
724 if (!hapd->iconf->send_probe_response)
727 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
728 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
733 if ((!elems.ssid || !elems.supp_rates)) {
734 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
735 "without SSID or supported rates element",
741 * No need to reply if the Probe Request frame was sent on an adjacent
742 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
743 * AP with dot11RadioMeasurementActivated set to true, but strictly
744 * speaking does not allow such ignoring of Probe Request frames if
745 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
746 * number of unnecessary Probe Response frames for cases where the STA
747 * is less likely to see them (Probe Request frame sent on a
748 * neighboring, but partially overlapping, channel).
750 if (elems.ds_params &&
751 hapd->iface->current_mode &&
752 (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
753 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
754 hapd->iconf->channel != elems.ds_params[0]) {
755 wpa_printf(MSG_DEBUG,
756 "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
757 hapd->iconf->channel, elems.ds_params[0]);
762 if (hapd->p2p && hapd->p2p_group && elems.wps_ie) {
764 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
765 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
766 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
767 "due to mismatch with Requested Device "
775 if (hapd->p2p && hapd->p2p_group && elems.p2p) {
777 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
778 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
779 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
780 "due to mismatch with Device ID");
786 #endif /* CONFIG_P2P */
788 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
789 elems.ssid_list_len == 0) {
790 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
791 "broadcast SSID ignored", MAC2STR(mgmt->sa));
796 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
797 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
798 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
799 P2P_WILDCARD_SSID_LEN) == 0) {
800 /* Process P2P Wildcard SSID like Wildcard SSID */
803 #endif /* CONFIG_P2P */
805 #ifdef CONFIG_TAXONOMY
807 struct sta_info *sta;
808 struct hostapd_sta_info *info;
810 if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) {
811 taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len);
812 } else if ((info = sta_track_get(hapd->iface,
813 mgmt->sa)) != NULL) {
814 taxonomy_hostapd_sta_info_probe_req(hapd, info,
818 #endif /* CONFIG_TAXONOMY */
820 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
821 elems.ssid_list, elems.ssid_list_len);
822 if (res == NO_SSID_MATCH) {
823 if (!(mgmt->da[0] & 0x01)) {
824 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
825 " for foreign SSID '%s' (DA " MACSTR ")%s",
827 wpa_ssid_txt(elems.ssid, elems.ssid_len),
829 elems.ssid_list ? " (SSID list)" : "");
834 #ifdef CONFIG_INTERWORKING
835 if (hapd->conf->interworking &&
836 elems.interworking && elems.interworking_len >= 1) {
837 u8 ant = elems.interworking[0] & 0x0f;
838 if (ant != INTERWORKING_ANT_WILDCARD &&
839 ant != hapd->conf->access_network_type) {
840 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
841 " for mismatching ANT %u ignored",
842 MAC2STR(mgmt->sa), ant);
847 if (hapd->conf->interworking && elems.interworking &&
848 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
850 if (elems.interworking_len == 7)
851 hessid = elems.interworking + 1;
853 hessid = elems.interworking + 1 + 2;
854 if (!is_broadcast_ether_addr(hessid) &&
855 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
856 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
857 " for mismatching HESSID " MACSTR
859 MAC2STR(mgmt->sa), MAC2STR(hessid));
863 #endif /* CONFIG_INTERWORKING */
866 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
867 supp_rates_11b_only(&elems)) {
868 /* Indicates support for 11b rates only */
869 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
870 MACSTR " with only 802.11b rates",
874 #endif /* CONFIG_P2P */
876 /* TODO: verify that supp_rates contains at least one matching rate
877 * with AP configuration */
879 if (hapd->conf->no_probe_resp_if_seen_on &&
880 is_multicast_ether_addr(mgmt->da) &&
881 is_multicast_ether_addr(mgmt->bssid) &&
882 sta_track_seen_on(hapd->iface, mgmt->sa,
883 hapd->conf->no_probe_resp_if_seen_on)) {
884 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
885 " since STA has been seen on %s",
886 hapd->conf->iface, MAC2STR(mgmt->sa),
887 hapd->conf->no_probe_resp_if_seen_on);
891 if (hapd->conf->no_probe_resp_if_max_sta &&
892 is_multicast_ether_addr(mgmt->da) &&
893 is_multicast_ether_addr(mgmt->bssid) &&
894 hapd->num_sta >= hapd->conf->max_num_sta &&
895 !ap_get_sta(hapd, mgmt->sa)) {
896 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
897 " since no room for additional STA",
898 hapd->conf->iface, MAC2STR(mgmt->sa));
902 #ifdef CONFIG_TESTING_OPTIONS
903 if (hapd->iconf->ignore_probe_probability > 0.0 &&
904 drand48() < hapd->iconf->ignore_probe_probability) {
906 "TESTING: ignoring probe request from " MACSTR,
910 #endif /* CONFIG_TESTING_OPTIONS */
912 resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL,
918 * If this is a broadcast probe request, apply no ack policy to avoid
921 noack = !!(res == WILDCARD_SSID_MATCH &&
922 is_broadcast_ether_addr(mgmt->da));
925 if (hapd->csa_in_progress) {
926 if (hapd->cs_c_off_proberesp)
927 csa_offs[csa_offs_len++] =
928 hapd->cs_c_off_proberesp;
930 if (hapd->cs_c_off_ecsa_proberesp)
931 csa_offs[csa_offs_len++] =
932 hapd->cs_c_off_ecsa_proberesp;
935 ret = hostapd_drv_send_mlme_csa(hapd, resp, resp_len, noack,
936 csa_offs_len ? csa_offs : NULL,
940 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
944 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
945 "SSID", MAC2STR(mgmt->sa),
946 elems.ssid_len == 0 ? "broadcast" : "our");
950 static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
953 /* check probe response offloading caps and print warnings */
954 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
958 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
959 (!(hapd->iface->probe_resp_offloads &
960 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
961 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
962 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
963 "Probe Response while not supporting this");
964 #endif /* CONFIG_WPS */
967 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
968 !(hapd->iface->probe_resp_offloads &
969 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
970 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
971 "Probe Response while not supporting this");
972 #endif /* CONFIG_P2P */
974 if (hapd->conf->interworking &&
975 !(hapd->iface->probe_resp_offloads &
976 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
977 wpa_printf(MSG_WARNING, "Device is trying to offload "
978 "Interworking Probe Response while not supporting "
981 /* Generate a Probe Response template for the non-P2P case */
982 return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len);
985 #endif /* NEED_AP_MLME */
988 void sta_track_del(struct hostapd_sta_info *info)
990 #ifdef CONFIG_TAXONOMY
991 wpabuf_free(info->probe_ie_taxonomy);
992 info->probe_ie_taxonomy = NULL;
993 #endif /* CONFIG_TAXONOMY */
998 int ieee802_11_build_ap_params(struct hostapd_data *hapd,
999 struct wpa_driver_ap_params *params)
1001 struct ieee80211_mgmt *head = NULL;
1003 size_t head_len = 0, tail_len = 0;
1005 size_t resp_len = 0;
1008 u8 *pos, *tailpos, *csa_pos;
1010 #define BEACON_HEAD_BUF_SIZE 256
1011 #define BEACON_TAIL_BUF_SIZE 512
1012 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
1013 tail_len = BEACON_TAIL_BUF_SIZE;
1015 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
1016 tail_len += wpabuf_len(hapd->wps_beacon_ie);
1017 #endif /* CONFIG_WPS */
1019 if (hapd->p2p_beacon_ie)
1020 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
1021 #endif /* CONFIG_P2P */
1023 if (hapd->iface->fst_ies)
1024 tail_len += wpabuf_len(hapd->iface->fst_ies);
1025 #endif /* CONFIG_FST */
1026 if (hapd->conf->vendor_elements)
1027 tail_len += wpabuf_len(hapd->conf->vendor_elements);
1029 #ifdef CONFIG_IEEE80211AC
1030 if (hapd->conf->vendor_vht) {
1031 tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
1032 2 + sizeof(struct ieee80211_vht_operation);
1034 #endif /* CONFIG_IEEE80211AC */
1036 tail_len += hostapd_mbo_ie_len(hapd);
1038 tailpos = tail = os_malloc(tail_len);
1039 if (head == NULL || tail == NULL) {
1040 wpa_printf(MSG_ERROR, "Failed to set beacon data");
1046 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1047 WLAN_FC_STYPE_BEACON);
1048 head->duration = host_to_le16(0);
1049 os_memset(head->da, 0xff, ETH_ALEN);
1051 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1052 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1053 head->u.beacon.beacon_int =
1054 host_to_le16(hapd->iconf->beacon_int);
1056 /* hardware or low-level driver will setup seq_ctrl and timestamp */
1057 capab_info = hostapd_own_capab_info(hapd);
1058 head->u.beacon.capab_info = host_to_le16(capab_info);
1059 pos = &head->u.beacon.variable[0];
1062 *pos++ = WLAN_EID_SSID;
1063 if (hapd->conf->ignore_broadcast_ssid == 2) {
1064 /* clear the data, but keep the correct length of the SSID */
1065 *pos++ = hapd->conf->ssid.ssid_len;
1066 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
1067 pos += hapd->conf->ssid.ssid_len;
1068 } else if (hapd->conf->ignore_broadcast_ssid) {
1069 *pos++ = 0; /* empty SSID */
1071 *pos++ = hapd->conf->ssid.ssid_len;
1072 os_memcpy(pos, hapd->conf->ssid.ssid,
1073 hapd->conf->ssid.ssid_len);
1074 pos += hapd->conf->ssid.ssid_len;
1077 /* Supported rates */
1078 pos = hostapd_eid_supp_rates(hapd, pos);
1081 pos = hostapd_eid_ds_params(hapd, pos);
1083 head_len = pos - (u8 *) head;
1085 tailpos = hostapd_eid_country(hapd, tailpos,
1086 tail + BEACON_TAIL_BUF_SIZE - tailpos);
1088 /* Power Constraint element */
1089 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
1092 csa_pos = hostapd_eid_csa(hapd, tailpos);
1093 if (csa_pos != tailpos)
1094 hapd->cs_c_off_beacon = csa_pos - tail - 1;
1097 /* ERP Information element */
1098 tailpos = hostapd_eid_erp_info(hapd, tailpos);
1100 /* Extended supported rates */
1101 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
1103 /* RSN, MDIE, WPA */
1104 tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
1107 tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
1108 tail + BEACON_TAIL_BUF_SIZE -
1111 tailpos = hostapd_eid_bss_load(hapd, tailpos,
1112 tail + BEACON_TAIL_BUF_SIZE - tailpos);
1115 csa_pos = hostapd_eid_ecsa(hapd, tailpos);
1116 if (csa_pos != tailpos)
1117 hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1;
1120 tailpos = hostapd_eid_supported_op_classes(hapd, tailpos);
1122 #ifdef CONFIG_IEEE80211N
1123 /* Secondary Channel Offset element */
1124 /* TODO: The standard doesn't specify a position for this element. */
1125 tailpos = hostapd_eid_secondary_channel(hapd, tailpos);
1127 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
1128 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
1129 #endif /* CONFIG_IEEE80211N */
1131 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
1134 * TODO: Time Advertisement element should only be included in some
1135 * DTIM Beacon frames.
1137 tailpos = hostapd_eid_time_adv(hapd, tailpos);
1139 tailpos = hostapd_eid_interworking(hapd, tailpos);
1140 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
1141 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
1144 if (hapd->iface->fst_ies) {
1145 os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies),
1146 wpabuf_len(hapd->iface->fst_ies));
1147 tailpos += wpabuf_len(hapd->iface->fst_ies);
1149 #endif /* CONFIG_FST */
1151 #ifdef CONFIG_IEEE80211AC
1152 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
1153 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0);
1154 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
1155 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
1156 tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos);
1158 if (hapd->conf->vendor_vht)
1159 tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
1160 #endif /* CONFIG_IEEE80211AC */
1162 /* Wi-Fi Alliance WMM */
1163 tailpos = hostapd_eid_wmm(hapd, tailpos);
1166 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
1167 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
1168 wpabuf_len(hapd->wps_beacon_ie));
1169 tailpos += wpabuf_len(hapd->wps_beacon_ie);
1171 #endif /* CONFIG_WPS */
1174 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
1175 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
1176 wpabuf_len(hapd->p2p_beacon_ie));
1177 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
1179 #endif /* CONFIG_P2P */
1180 #ifdef CONFIG_P2P_MANAGER
1181 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
1183 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
1184 #endif /* CONFIG_P2P_MANAGER */
1187 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
1188 tailpos = hostapd_eid_osen(hapd, tailpos);
1189 #endif /* CONFIG_HS20 */
1191 tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos);
1193 if (hapd->conf->vendor_elements) {
1194 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
1195 wpabuf_len(hapd->conf->vendor_elements));
1196 tailpos += wpabuf_len(hapd->conf->vendor_elements);
1199 tail_len = tailpos > tail ? tailpos - tail : 0;
1201 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
1202 #endif /* NEED_AP_MLME */
1204 os_memset(params, 0, sizeof(*params));
1205 params->head = (u8 *) head;
1206 params->head_len = head_len;
1207 params->tail = tail;
1208 params->tail_len = tail_len;
1209 params->proberesp = resp;
1210 params->proberesp_len = resp_len;
1211 params->dtim_period = hapd->conf->dtim_period;
1212 params->beacon_int = hapd->iconf->beacon_int;
1213 params->basic_rates = hapd->iface->basic_rates;
1214 params->ssid = hapd->conf->ssid.ssid;
1215 params->ssid_len = hapd->conf->ssid.ssid_len;
1216 if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
1217 (WPA_PROTO_WPA | WPA_PROTO_RSN))
1218 params->pairwise_ciphers = hapd->conf->wpa_pairwise |
1219 hapd->conf->rsn_pairwise;
1220 else if (hapd->conf->wpa & WPA_PROTO_RSN)
1221 params->pairwise_ciphers = hapd->conf->rsn_pairwise;
1222 else if (hapd->conf->wpa & WPA_PROTO_WPA)
1223 params->pairwise_ciphers = hapd->conf->wpa_pairwise;
1224 params->group_cipher = hapd->conf->wpa_group;
1225 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
1226 params->auth_algs = hapd->conf->auth_algs;
1227 params->wpa_version = hapd->conf->wpa;
1228 params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
1229 (hapd->conf->ieee802_1x &&
1230 (hapd->conf->default_wep_key_len ||
1231 hapd->conf->individual_wep_key_len));
1232 switch (hapd->conf->ignore_broadcast_ssid) {
1234 params->hide_ssid = NO_SSID_HIDING;
1237 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
1240 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
1243 params->isolate = hapd->conf->isolate;
1244 params->smps_mode = hapd->iconf->ht_capab & HT_CAP_INFO_SMPS_MASK;
1246 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
1247 ERP_INFO_USE_PROTECTION);
1248 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
1249 hapd->iconf->preamble == SHORT_PREAMBLE;
1250 if (hapd->iface->current_mode &&
1251 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1252 params->short_slot_time =
1253 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
1255 params->short_slot_time = -1;
1256 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
1257 params->ht_opmode = -1;
1259 params->ht_opmode = hapd->iface->ht_op_mode;
1260 #endif /* NEED_AP_MLME */
1261 params->interworking = hapd->conf->interworking;
1262 if (hapd->conf->interworking &&
1263 !is_zero_ether_addr(hapd->conf->hessid))
1264 params->hessid = hapd->conf->hessid;
1265 params->access_network_type = hapd->conf->access_network_type;
1266 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
1268 params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
1269 #endif /* CONFIG_P2P */
1271 params->disable_dgaf = hapd->conf->disable_dgaf;
1272 if (hapd->conf->osen) {
1273 params->privacy = 1;
1276 #endif /* CONFIG_HS20 */
1277 params->pbss = hapd->conf->pbss;
1282 void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
1284 os_free(params->tail);
1285 params->tail = NULL;
1286 os_free(params->head);
1287 params->head = NULL;
1288 os_free(params->proberesp);
1289 params->proberesp = NULL;
1293 int ieee802_11_set_beacon(struct hostapd_data *hapd)
1295 struct wpa_driver_ap_params params;
1296 struct hostapd_freq_params freq;
1297 struct hostapd_iface *iface = hapd->iface;
1298 struct hostapd_config *iconf = iface->conf;
1299 struct wpabuf *beacon, *proberesp, *assocresp;
1302 if (hapd->csa_in_progress) {
1303 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
1307 hapd->beacon_set_done = 1;
1309 if (ieee802_11_build_ap_params(hapd, ¶ms) < 0)
1312 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
1316 params.beacon_ies = beacon;
1317 params.proberesp_ies = proberesp;
1318 params.assocresp_ies = assocresp;
1319 params.reenable = hapd->reenable_beacon;
1320 hapd->reenable_beacon = 0;
1322 if (iface->current_mode &&
1323 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
1324 iconf->channel, iconf->ieee80211n,
1326 iconf->secondary_channel,
1327 iconf->vht_oper_chwidth,
1328 iconf->vht_oper_centr_freq_seg0_idx,
1329 iconf->vht_oper_centr_freq_seg1_idx,
1330 iface->current_mode->vht_capab) == 0)
1331 params.freq = &freq;
1333 res = hostapd_drv_set_ap(hapd, ¶ms);
1334 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
1336 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
1340 ieee802_11_free_ap_params(¶ms);
1345 int ieee802_11_set_beacons(struct hostapd_iface *iface)
1350 for (i = 0; i < iface->num_bss; i++) {
1351 if (iface->bss[i]->started &&
1352 ieee802_11_set_beacon(iface->bss[i]) < 0)
1360 /* only update beacons if started */
1361 int ieee802_11_update_beacons(struct hostapd_iface *iface)
1366 for (i = 0; i < iface->num_bss; i++) {
1367 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
1368 ieee802_11_set_beacon(iface->bss[i]) < 0)
1375 #endif /* CONFIG_NATIVE_WINDOWS */