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_bss_load(struct hostapd_data
*hapd
, u8
*eid
, size_t len
)
40 #ifdef CONFIG_TESTING_OPTIONS
41 if (hapd
->conf
->bss_load_test_set
) {
42 *eid
++ = WLAN_EID_BSS_LOAD
;
44 os_memcpy(eid
, hapd
->conf
->bss_load_test
, 5);
48 #endif /* CONFIG_TESTING_OPTIONS */
49 if (hapd
->conf
->bss_load_update_period
) {
50 *eid
++ = WLAN_EID_BSS_LOAD
;
52 WPA_PUT_LE16(eid
, hapd
->num_sta
);
54 *eid
++ = hapd
->iface
->channel_utilization
;
55 WPA_PUT_LE16(eid
, 0); /* no available admission capabity */
62 static u8
ieee802_11_erp_info(struct hostapd_data
*hapd
)
66 if (hapd
->iface
->current_mode
== NULL
||
67 hapd
->iface
->current_mode
->mode
!= HOSTAPD_MODE_IEEE80211G
)
70 if (hapd
->iface
->olbc
)
71 erp
|= ERP_INFO_USE_PROTECTION
;
72 if (hapd
->iface
->num_sta_non_erp
> 0) {
73 erp
|= ERP_INFO_NON_ERP_PRESENT
|
74 ERP_INFO_USE_PROTECTION
;
76 if (hapd
->iface
->num_sta_no_short_preamble
> 0 ||
77 hapd
->iconf
->preamble
== LONG_PREAMBLE
)
78 erp
|= ERP_INFO_BARKER_PREAMBLE_MODE
;
84 static u8
* hostapd_eid_ds_params(struct hostapd_data
*hapd
, u8
*eid
)
86 *eid
++ = WLAN_EID_DS_PARAMS
;
88 *eid
++ = hapd
->iconf
->channel
;
93 static u8
* hostapd_eid_erp_info(struct hostapd_data
*hapd
, u8
*eid
)
95 if (hapd
->iface
->current_mode
== NULL
||
96 hapd
->iface
->current_mode
->mode
!= HOSTAPD_MODE_IEEE80211G
)
99 /* Set NonERP_present and use_protection bits if there
100 * are any associated NonERP stations. */
101 /* TODO: use_protection bit can be set to zero even if
102 * there are NonERP stations present. This optimization
103 * might be useful if NonERP stations are "quiet".
104 * See 802.11g/D6 E-1 for recommended practice.
105 * In addition, Non ERP present might be set, if AP detects Non ERP
106 * operation on other APs. */
108 /* Add ERP Information element */
109 *eid
++ = WLAN_EID_ERP_INFO
;
111 *eid
++ = ieee802_11_erp_info(hapd
);
117 static u8
* hostapd_eid_pwr_constraint(struct hostapd_data
*hapd
, u8
*eid
)
120 u8 local_pwr_constraint
= 0;
123 if (hapd
->iface
->current_mode
== NULL
||
124 hapd
->iface
->current_mode
->mode
!= HOSTAPD_MODE_IEEE80211A
)
127 /* Let host drivers add this IE if DFS support is offloaded */
128 if (hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_DFS_OFFLOAD
)
132 * There is no DFS support and power constraint was not directly
133 * requested by config option.
135 if (!hapd
->iconf
->ieee80211h
&&
136 hapd
->iconf
->local_pwr_constraint
== -1)
139 /* Check if DFS is required by regulatory. */
140 dfs
= hostapd_is_dfs_required(hapd
->iface
);
142 wpa_printf(MSG_WARNING
, "Failed to check if DFS is required; ret=%d",
147 if (dfs
== 0 && hapd
->iconf
->local_pwr_constraint
== -1)
151 * ieee80211h (DFS) is enabled so Power Constraint element shall
152 * be added when running on DFS channel whenever local_pwr_constraint
153 * is configured or not. In order to meet regulations when TPC is not
154 * implemented using a transmit power that is below the legal maximum
155 * (including any mitigation factor) should help. In this case,
156 * indicate 3 dB below maximum allowed transmit power.
158 if (hapd
->iconf
->local_pwr_constraint
== -1)
159 local_pwr_constraint
= 3;
162 * A STA that is not an AP shall use a transmit power less than or
163 * equal to the local maximum transmit power level for the channel.
164 * The local maximum transmit power can be calculated from the formula:
165 * local max TX pwr = max TX pwr - local pwr constraint
166 * Where max TX pwr is maximum transmit power level specified for
167 * channel in Country element and local pwr constraint is specified
168 * for channel in this Power Constraint element.
172 *pos
++ = WLAN_EID_PWR_CONSTRAINT
;
175 /* Local Power Constraint */
176 if (local_pwr_constraint
)
177 *pos
++ = local_pwr_constraint
;
179 *pos
++ = hapd
->iconf
->local_pwr_constraint
;
185 static u8
* hostapd_eid_country_add(u8
*pos
, u8
*end
, int chan_spacing
,
186 struct hostapd_channel_data
*start
,
187 struct hostapd_channel_data
*prev
)
192 /* first channel number */
193 *pos
++ = start
->chan
;
194 /* number of channels */
195 *pos
++ = (prev
->chan
- start
->chan
) / chan_spacing
+ 1;
196 /* maximum transmit power level */
197 *pos
++ = start
->max_tx_power
;
203 static u8
* hostapd_eid_country(struct hostapd_data
*hapd
, u8
*eid
,
207 u8
*end
= eid
+ max_len
;
209 struct hostapd_hw_modes
*mode
;
210 struct hostapd_channel_data
*start
, *prev
;
211 int chan_spacing
= 1;
213 if (!hapd
->iconf
->ieee80211d
|| max_len
< 6 ||
214 hapd
->iface
->current_mode
== NULL
)
217 *pos
++ = WLAN_EID_COUNTRY
;
218 pos
++; /* length will be set later */
219 os_memcpy(pos
, hapd
->iconf
->country
, 3); /* e.g., 'US ' */
222 mode
= hapd
->iface
->current_mode
;
223 if (mode
->mode
== HOSTAPD_MODE_IEEE80211A
)
227 for (i
= 0; i
< mode
->num_channels
; i
++) {
228 struct hostapd_channel_data
*chan
= &mode
->channels
[i
];
229 if (chan
->flag
& HOSTAPD_CHAN_DISABLED
)
232 prev
->chan
+ chan_spacing
== chan
->chan
&&
233 start
->max_tx_power
== chan
->max_tx_power
) {
235 continue; /* can use same entry */
239 pos
= hostapd_eid_country_add(pos
, end
, chan_spacing
,
244 /* Start new group */
249 pos
= hostapd_eid_country_add(pos
, end
, chan_spacing
,
253 if ((pos
- eid
) & 1) {
256 *pos
++ = 0; /* pad for 16-bit alignment */
259 eid
[1] = (pos
- eid
) - 2;
265 static u8
* hostapd_eid_wpa(struct hostapd_data
*hapd
, u8
*eid
, size_t len
)
270 ie
= wpa_auth_get_wpa_ie(hapd
->wpa_auth
, &ielen
);
271 if (ie
== NULL
|| ielen
> len
)
274 os_memcpy(eid
, ie
, ielen
);
279 static u8
* hostapd_eid_csa(struct hostapd_data
*hapd
, u8
*eid
)
283 if (!hapd
->cs_freq_params
.freq
)
286 if (ieee80211_freq_to_chan(hapd
->cs_freq_params
.freq
, &chan
) ==
290 *eid
++ = WLAN_EID_CHANNEL_SWITCH
;
292 *eid
++ = hapd
->cs_block_tx
;
294 *eid
++ = hapd
->cs_count
;
300 static u8
* hostapd_eid_secondary_channel(struct hostapd_data
*hapd
, u8
*eid
)
304 if (!hapd
->cs_freq_params
.sec_channel_offset
)
307 if (hapd
->cs_freq_params
.sec_channel_offset
== -1)
308 sec_ch
= HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW
;
309 else if (hapd
->cs_freq_params
.sec_channel_offset
== 1)
310 sec_ch
= HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE
;
314 *eid
++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET
;
322 static u8
* hostapd_add_csa_elems(struct hostapd_data
*hapd
, u8
*pos
,
323 u8
*start
, unsigned int *csa_counter_off
)
327 if (!csa_counter_off
)
330 *csa_counter_off
= 0;
331 pos
= hostapd_eid_csa(hapd
, pos
);
333 if (pos
!= old_pos
) {
334 /* save an offset to the counter - should be last byte */
335 *csa_counter_off
= pos
- start
- 1;
336 pos
= hostapd_eid_secondary_channel(hapd
, pos
);
343 static u8
* hostapd_gen_probe_resp(struct hostapd_data
*hapd
,
344 struct sta_info
*sta
,
345 const struct ieee80211_mgmt
*req
,
346 int is_p2p
, size_t *resp_len
)
348 struct ieee80211_mgmt
*resp
;
352 #define MAX_PROBERESP_LEN 768
353 buflen
= MAX_PROBERESP_LEN
;
355 if (hapd
->wps_probe_resp_ie
)
356 buflen
+= wpabuf_len(hapd
->wps_probe_resp_ie
);
357 #endif /* CONFIG_WPS */
359 if (hapd
->p2p_probe_resp_ie
)
360 buflen
+= wpabuf_len(hapd
->p2p_probe_resp_ie
);
361 #endif /* CONFIG_P2P */
362 if (hapd
->conf
->vendor_elements
)
363 buflen
+= wpabuf_len(hapd
->conf
->vendor_elements
);
364 resp
= os_zalloc(buflen
);
368 epos
= ((u8
*) resp
) + MAX_PROBERESP_LEN
;
370 resp
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
371 WLAN_FC_STYPE_PROBE_RESP
);
373 os_memcpy(resp
->da
, req
->sa
, ETH_ALEN
);
374 os_memcpy(resp
->sa
, hapd
->own_addr
, ETH_ALEN
);
376 os_memcpy(resp
->bssid
, hapd
->own_addr
, ETH_ALEN
);
377 resp
->u
.probe_resp
.beacon_int
=
378 host_to_le16(hapd
->iconf
->beacon_int
);
380 /* hardware or low-level driver will setup seq_ctrl and timestamp */
381 resp
->u
.probe_resp
.capab_info
=
382 host_to_le16(hostapd_own_capab_info(hapd
, sta
, 1));
384 pos
= resp
->u
.probe_resp
.variable
;
385 *pos
++ = WLAN_EID_SSID
;
386 *pos
++ = hapd
->conf
->ssid
.ssid_len
;
387 os_memcpy(pos
, hapd
->conf
->ssid
.ssid
, hapd
->conf
->ssid
.ssid_len
);
388 pos
+= hapd
->conf
->ssid
.ssid_len
;
390 /* Supported rates */
391 pos
= hostapd_eid_supp_rates(hapd
, pos
);
394 pos
= hostapd_eid_ds_params(hapd
, pos
);
396 pos
= hostapd_eid_country(hapd
, pos
, epos
- pos
);
398 /* Power Constraint element */
399 pos
= hostapd_eid_pwr_constraint(hapd
, pos
);
401 /* ERP Information element */
402 pos
= hostapd_eid_erp_info(hapd
, pos
);
404 /* Extended supported rates */
405 pos
= hostapd_eid_ext_supp_rates(hapd
, pos
);
408 pos
= hostapd_eid_wpa(hapd
, pos
, epos
- pos
);
410 pos
= hostapd_eid_bss_load(hapd
, pos
, epos
- pos
);
412 #ifdef CONFIG_IEEE80211N
413 pos
= hostapd_eid_ht_capabilities(hapd
, pos
);
414 pos
= hostapd_eid_ht_operation(hapd
, pos
);
415 #endif /* CONFIG_IEEE80211N */
417 pos
= hostapd_eid_ext_capab(hapd
, pos
);
419 pos
= hostapd_eid_time_adv(hapd
, pos
);
420 pos
= hostapd_eid_time_zone(hapd
, pos
);
422 pos
= hostapd_eid_interworking(hapd
, pos
);
423 pos
= hostapd_eid_adv_proto(hapd
, pos
);
424 pos
= hostapd_eid_roaming_consortium(hapd
, pos
);
426 pos
= hostapd_add_csa_elems(hapd
, pos
, (u8
*)resp
,
427 &hapd
->cs_c_off_proberesp
);
428 #ifdef CONFIG_IEEE80211AC
429 pos
= hostapd_eid_vht_capabilities(hapd
, pos
);
430 pos
= hostapd_eid_vht_operation(hapd
, pos
);
431 #endif /* CONFIG_IEEE80211AC */
433 /* Wi-Fi Alliance WMM */
434 pos
= hostapd_eid_wmm(hapd
, pos
);
437 if (hapd
->conf
->wps_state
&& hapd
->wps_probe_resp_ie
) {
438 os_memcpy(pos
, wpabuf_head(hapd
->wps_probe_resp_ie
),
439 wpabuf_len(hapd
->wps_probe_resp_ie
));
440 pos
+= wpabuf_len(hapd
->wps_probe_resp_ie
);
442 #endif /* CONFIG_WPS */
445 if ((hapd
->conf
->p2p
& P2P_ENABLED
) && is_p2p
&&
446 hapd
->p2p_probe_resp_ie
) {
447 os_memcpy(pos
, wpabuf_head(hapd
->p2p_probe_resp_ie
),
448 wpabuf_len(hapd
->p2p_probe_resp_ie
));
449 pos
+= wpabuf_len(hapd
->p2p_probe_resp_ie
);
451 #endif /* CONFIG_P2P */
452 #ifdef CONFIG_P2P_MANAGER
453 if ((hapd
->conf
->p2p
& (P2P_MANAGE
| P2P_ENABLED
| P2P_GROUP_OWNER
)) ==
455 pos
= hostapd_eid_p2p_manage(hapd
, pos
);
456 #endif /* CONFIG_P2P_MANAGER */
459 pos
= hostapd_eid_hs20_indication(hapd
, pos
);
460 pos
= hostapd_eid_osen(hapd
, pos
);
461 #endif /* CONFIG_HS20 */
463 if (hapd
->conf
->vendor_elements
) {
464 os_memcpy(pos
, wpabuf_head(hapd
->conf
->vendor_elements
),
465 wpabuf_len(hapd
->conf
->vendor_elements
));
466 pos
+= wpabuf_len(hapd
->conf
->vendor_elements
);
469 *resp_len
= pos
- (u8
*) resp
;
474 enum ssid_match_result
{
480 static enum ssid_match_result
ssid_match(struct hostapd_data
*hapd
,
481 const u8
*ssid
, size_t ssid_len
,
483 size_t ssid_list_len
)
490 if (ssid_len
== hapd
->conf
->ssid
.ssid_len
&&
491 os_memcmp(ssid
, hapd
->conf
->ssid
.ssid
, ssid_len
) == 0)
492 return EXACT_SSID_MATCH
;
494 if (ssid_list
== NULL
)
495 return wildcard
? WILDCARD_SSID_MATCH
: NO_SSID_MATCH
;
498 end
= ssid_list
+ ssid_list_len
;
499 while (pos
+ 1 <= end
) {
500 if (pos
+ 2 + pos
[1] > end
)
504 if (pos
[1] == hapd
->conf
->ssid
.ssid_len
&&
505 os_memcmp(pos
+ 2, hapd
->conf
->ssid
.ssid
, pos
[1]) == 0)
506 return EXACT_SSID_MATCH
;
510 return wildcard
? WILDCARD_SSID_MATCH
: NO_SSID_MATCH
;
514 void handle_probe_req(struct hostapd_data
*hapd
,
515 const struct ieee80211_mgmt
*mgmt
, size_t len
,
519 struct ieee802_11_elems elems
;
522 struct sta_info
*sta
= NULL
;
525 enum ssid_match_result res
;
527 ie
= mgmt
->u
.probe_req
.variable
;
528 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.probe_req
))
530 ie_len
= len
- (IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.probe_req
));
532 for (i
= 0; hapd
->probereq_cb
&& i
< hapd
->num_probereq_cb
; i
++)
533 if (hapd
->probereq_cb
[i
].cb(hapd
->probereq_cb
[i
].ctx
,
534 mgmt
->sa
, mgmt
->da
, mgmt
->bssid
,
535 ie
, ie_len
, ssi_signal
) > 0)
538 if (!hapd
->iconf
->send_probe_response
)
541 if (ieee802_11_parse_elems(ie
, ie_len
, &elems
, 0) == ParseFailed
) {
542 wpa_printf(MSG_DEBUG
, "Could not parse ProbeReq from " MACSTR
,
547 if ((!elems
.ssid
|| !elems
.supp_rates
)) {
548 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" sent probe request "
549 "without SSID or supported rates element",
555 if (hapd
->p2p
&& elems
.wps_ie
) {
557 wps
= ieee802_11_vendor_ie_concat(ie
, ie_len
, WPS_DEV_OUI_WFA
);
558 if (wps
&& !p2p_group_match_dev_type(hapd
->p2p_group
, wps
)) {
559 wpa_printf(MSG_MSGDUMP
, "P2P: Ignore Probe Request "
560 "due to mismatch with Requested Device "
568 if (hapd
->p2p
&& elems
.p2p
) {
570 p2p
= ieee802_11_vendor_ie_concat(ie
, ie_len
, P2P_IE_VENDOR_TYPE
);
571 if (p2p
&& !p2p_group_match_dev_id(hapd
->p2p_group
, p2p
)) {
572 wpa_printf(MSG_MSGDUMP
, "P2P: Ignore Probe Request "
573 "due to mismatch with Device ID");
579 #endif /* CONFIG_P2P */
581 if (hapd
->conf
->ignore_broadcast_ssid
&& elems
.ssid_len
== 0 &&
582 elems
.ssid_list_len
== 0) {
583 wpa_printf(MSG_MSGDUMP
, "Probe Request from " MACSTR
" for "
584 "broadcast SSID ignored", MAC2STR(mgmt
->sa
));
588 sta
= ap_get_sta(hapd
, mgmt
->sa
);
591 if ((hapd
->conf
->p2p
& P2P_GROUP_OWNER
) &&
592 elems
.ssid_len
== P2P_WILDCARD_SSID_LEN
&&
593 os_memcmp(elems
.ssid
, P2P_WILDCARD_SSID
,
594 P2P_WILDCARD_SSID_LEN
) == 0) {
595 /* Process P2P Wildcard SSID like Wildcard SSID */
598 #endif /* CONFIG_P2P */
600 res
= ssid_match(hapd
, elems
.ssid
, elems
.ssid_len
,
601 elems
.ssid_list
, elems
.ssid_list_len
);
602 if (res
!= NO_SSID_MATCH
) {
604 sta
->ssid_probe
= &hapd
->conf
->ssid
;
606 if (!(mgmt
->da
[0] & 0x01)) {
607 wpa_printf(MSG_MSGDUMP
, "Probe Request from " MACSTR
608 " for foreign SSID '%s' (DA " MACSTR
")%s",
610 wpa_ssid_txt(elems
.ssid
, elems
.ssid_len
),
612 elems
.ssid_list
? " (SSID list)" : "");
617 #ifdef CONFIG_INTERWORKING
618 if (hapd
->conf
->interworking
&&
619 elems
.interworking
&& elems
.interworking_len
>= 1) {
620 u8 ant
= elems
.interworking
[0] & 0x0f;
621 if (ant
!= INTERWORKING_ANT_WILDCARD
&&
622 ant
!= hapd
->conf
->access_network_type
) {
623 wpa_printf(MSG_MSGDUMP
, "Probe Request from " MACSTR
624 " for mismatching ANT %u ignored",
625 MAC2STR(mgmt
->sa
), ant
);
630 if (hapd
->conf
->interworking
&& elems
.interworking
&&
631 (elems
.interworking_len
== 7 || elems
.interworking_len
== 9)) {
633 if (elems
.interworking_len
== 7)
634 hessid
= elems
.interworking
+ 1;
636 hessid
= elems
.interworking
+ 1 + 2;
637 if (!is_broadcast_ether_addr(hessid
) &&
638 os_memcmp(hessid
, hapd
->conf
->hessid
, ETH_ALEN
) != 0) {
639 wpa_printf(MSG_MSGDUMP
, "Probe Request from " MACSTR
640 " for mismatching HESSID " MACSTR
642 MAC2STR(mgmt
->sa
), MAC2STR(hessid
));
646 #endif /* CONFIG_INTERWORKING */
649 if ((hapd
->conf
->p2p
& P2P_GROUP_OWNER
) &&
650 supp_rates_11b_only(&elems
)) {
651 /* Indicates support for 11b rates only */
652 wpa_printf(MSG_EXCESSIVE
, "P2P: Ignore Probe Request from "
653 MACSTR
" with only 802.11b rates",
657 #endif /* CONFIG_P2P */
659 /* TODO: verify that supp_rates contains at least one matching rate
660 * with AP configuration */
662 #ifdef CONFIG_TESTING_OPTIONS
663 if (hapd
->iconf
->ignore_probe_probability
> 0.0 &&
664 drand48() < hapd
->iconf
->ignore_probe_probability
) {
666 "TESTING: ignoring probe request from " MACSTR
,
670 #endif /* CONFIG_TESTING_OPTIONS */
672 resp
= hostapd_gen_probe_resp(hapd
, sta
, mgmt
, elems
.p2p
!= NULL
,
678 * If this is a broadcast probe request, apply no ack policy to avoid
681 noack
= !!(res
== WILDCARD_SSID_MATCH
&&
682 is_broadcast_ether_addr(mgmt
->da
));
684 if (hostapd_drv_send_mlme(hapd
, resp
, resp_len
, noack
) < 0)
685 wpa_printf(MSG_INFO
, "handle_probe_req: send failed");
689 wpa_printf(MSG_EXCESSIVE
, "STA " MACSTR
" sent probe request for %s "
690 "SSID", MAC2STR(mgmt
->sa
),
691 elems
.ssid_len
== 0 ? "broadcast" : "our");
695 static u8
* hostapd_probe_resp_offloads(struct hostapd_data
*hapd
,
698 /* check probe response offloading caps and print warnings */
699 if (!(hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD
))
703 if (hapd
->conf
->wps_state
&& hapd
->wps_probe_resp_ie
&&
704 (!(hapd
->iface
->probe_resp_offloads
&
705 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS
|
706 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2
))))
707 wpa_printf(MSG_WARNING
, "Device is trying to offload WPS "
708 "Probe Response while not supporting this");
709 #endif /* CONFIG_WPS */
712 if ((hapd
->conf
->p2p
& P2P_ENABLED
) && hapd
->p2p_probe_resp_ie
&&
713 !(hapd
->iface
->probe_resp_offloads
&
714 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P
))
715 wpa_printf(MSG_WARNING
, "Device is trying to offload P2P "
716 "Probe Response while not supporting this");
717 #endif /* CONFIG_P2P */
719 if (hapd
->conf
->interworking
&&
720 !(hapd
->iface
->probe_resp_offloads
&
721 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING
))
722 wpa_printf(MSG_WARNING
, "Device is trying to offload "
723 "Interworking Probe Response while not supporting "
726 /* Generate a Probe Response template for the non-P2P case */
727 return hostapd_gen_probe_resp(hapd
, NULL
, NULL
, 0, resp_len
);
730 #endif /* NEED_AP_MLME */
733 int ieee802_11_build_ap_params(struct hostapd_data
*hapd
,
734 struct wpa_driver_ap_params
*params
)
736 struct ieee80211_mgmt
*head
= NULL
;
738 size_t head_len
= 0, tail_len
= 0;
745 #define BEACON_HEAD_BUF_SIZE 256
746 #define BEACON_TAIL_BUF_SIZE 512
747 head
= os_zalloc(BEACON_HEAD_BUF_SIZE
);
748 tail_len
= BEACON_TAIL_BUF_SIZE
;
750 if (hapd
->conf
->wps_state
&& hapd
->wps_beacon_ie
)
751 tail_len
+= wpabuf_len(hapd
->wps_beacon_ie
);
752 #endif /* CONFIG_WPS */
754 if (hapd
->p2p_beacon_ie
)
755 tail_len
+= wpabuf_len(hapd
->p2p_beacon_ie
);
756 #endif /* CONFIG_P2P */
757 if (hapd
->conf
->vendor_elements
)
758 tail_len
+= wpabuf_len(hapd
->conf
->vendor_elements
);
759 tailpos
= tail
= os_malloc(tail_len
);
760 if (head
== NULL
|| tail
== NULL
) {
761 wpa_printf(MSG_ERROR
, "Failed to set beacon data");
767 head
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
768 WLAN_FC_STYPE_BEACON
);
769 head
->duration
= host_to_le16(0);
770 os_memset(head
->da
, 0xff, ETH_ALEN
);
772 os_memcpy(head
->sa
, hapd
->own_addr
, ETH_ALEN
);
773 os_memcpy(head
->bssid
, hapd
->own_addr
, ETH_ALEN
);
774 head
->u
.beacon
.beacon_int
=
775 host_to_le16(hapd
->iconf
->beacon_int
);
777 /* hardware or low-level driver will setup seq_ctrl and timestamp */
778 capab_info
= hostapd_own_capab_info(hapd
, NULL
, 0);
779 head
->u
.beacon
.capab_info
= host_to_le16(capab_info
);
780 pos
= &head
->u
.beacon
.variable
[0];
783 *pos
++ = WLAN_EID_SSID
;
784 if (hapd
->conf
->ignore_broadcast_ssid
== 2) {
785 /* clear the data, but keep the correct length of the SSID */
786 *pos
++ = hapd
->conf
->ssid
.ssid_len
;
787 os_memset(pos
, 0, hapd
->conf
->ssid
.ssid_len
);
788 pos
+= hapd
->conf
->ssid
.ssid_len
;
789 } else if (hapd
->conf
->ignore_broadcast_ssid
) {
790 *pos
++ = 0; /* empty SSID */
792 *pos
++ = hapd
->conf
->ssid
.ssid_len
;
793 os_memcpy(pos
, hapd
->conf
->ssid
.ssid
,
794 hapd
->conf
->ssid
.ssid_len
);
795 pos
+= hapd
->conf
->ssid
.ssid_len
;
798 /* Supported rates */
799 pos
= hostapd_eid_supp_rates(hapd
, pos
);
802 pos
= hostapd_eid_ds_params(hapd
, pos
);
804 head_len
= pos
- (u8
*) head
;
806 tailpos
= hostapd_eid_country(hapd
, tailpos
,
807 tail
+ BEACON_TAIL_BUF_SIZE
- tailpos
);
809 /* Power Constraint element */
810 tailpos
= hostapd_eid_pwr_constraint(hapd
, tailpos
);
812 /* ERP Information element */
813 tailpos
= hostapd_eid_erp_info(hapd
, tailpos
);
815 /* Extended supported rates */
816 tailpos
= hostapd_eid_ext_supp_rates(hapd
, tailpos
);
819 tailpos
= hostapd_eid_wpa(hapd
, tailpos
, tail
+ BEACON_TAIL_BUF_SIZE
-
822 tailpos
= hostapd_eid_bss_load(hapd
, tailpos
,
823 tail
+ BEACON_TAIL_BUF_SIZE
- tailpos
);
825 #ifdef CONFIG_IEEE80211N
826 tailpos
= hostapd_eid_ht_capabilities(hapd
, tailpos
);
827 tailpos
= hostapd_eid_ht_operation(hapd
, tailpos
);
828 #endif /* CONFIG_IEEE80211N */
830 tailpos
= hostapd_eid_ext_capab(hapd
, tailpos
);
833 * TODO: Time Advertisement element should only be included in some
834 * DTIM Beacon frames.
836 tailpos
= hostapd_eid_time_adv(hapd
, tailpos
);
838 tailpos
= hostapd_eid_interworking(hapd
, tailpos
);
839 tailpos
= hostapd_eid_adv_proto(hapd
, tailpos
);
840 tailpos
= hostapd_eid_roaming_consortium(hapd
, tailpos
);
841 tailpos
= hostapd_add_csa_elems(hapd
, tailpos
, tail
,
842 &hapd
->cs_c_off_beacon
);
843 #ifdef CONFIG_IEEE80211AC
844 tailpos
= hostapd_eid_vht_capabilities(hapd
, tailpos
);
845 tailpos
= hostapd_eid_vht_operation(hapd
, tailpos
);
846 #endif /* CONFIG_IEEE80211AC */
848 /* Wi-Fi Alliance WMM */
849 tailpos
= hostapd_eid_wmm(hapd
, tailpos
);
852 if (hapd
->conf
->wps_state
&& hapd
->wps_beacon_ie
) {
853 os_memcpy(tailpos
, wpabuf_head(hapd
->wps_beacon_ie
),
854 wpabuf_len(hapd
->wps_beacon_ie
));
855 tailpos
+= wpabuf_len(hapd
->wps_beacon_ie
);
857 #endif /* CONFIG_WPS */
860 if ((hapd
->conf
->p2p
& P2P_ENABLED
) && hapd
->p2p_beacon_ie
) {
861 os_memcpy(tailpos
, wpabuf_head(hapd
->p2p_beacon_ie
),
862 wpabuf_len(hapd
->p2p_beacon_ie
));
863 tailpos
+= wpabuf_len(hapd
->p2p_beacon_ie
);
865 #endif /* CONFIG_P2P */
866 #ifdef CONFIG_P2P_MANAGER
867 if ((hapd
->conf
->p2p
& (P2P_MANAGE
| P2P_ENABLED
| P2P_GROUP_OWNER
)) ==
869 tailpos
= hostapd_eid_p2p_manage(hapd
, tailpos
);
870 #endif /* CONFIG_P2P_MANAGER */
873 tailpos
= hostapd_eid_hs20_indication(hapd
, tailpos
);
874 tailpos
= hostapd_eid_osen(hapd
, tailpos
);
875 #endif /* CONFIG_HS20 */
877 if (hapd
->conf
->vendor_elements
) {
878 os_memcpy(tailpos
, wpabuf_head(hapd
->conf
->vendor_elements
),
879 wpabuf_len(hapd
->conf
->vendor_elements
));
880 tailpos
+= wpabuf_len(hapd
->conf
->vendor_elements
);
883 tail_len
= tailpos
> tail
? tailpos
- tail
: 0;
885 resp
= hostapd_probe_resp_offloads(hapd
, &resp_len
);
886 #endif /* NEED_AP_MLME */
888 os_memset(params
, 0, sizeof(*params
));
889 params
->head
= (u8
*) head
;
890 params
->head_len
= head_len
;
892 params
->tail_len
= tail_len
;
893 params
->proberesp
= resp
;
894 params
->proberesp_len
= resp_len
;
895 params
->dtim_period
= hapd
->conf
->dtim_period
;
896 params
->beacon_int
= hapd
->iconf
->beacon_int
;
897 params
->basic_rates
= hapd
->iface
->basic_rates
;
898 params
->ssid
= hapd
->conf
->ssid
.ssid
;
899 params
->ssid_len
= hapd
->conf
->ssid
.ssid_len
;
900 params
->pairwise_ciphers
= hapd
->conf
->wpa_pairwise
|
901 hapd
->conf
->rsn_pairwise
;
902 params
->group_cipher
= hapd
->conf
->wpa_group
;
903 params
->key_mgmt_suites
= hapd
->conf
->wpa_key_mgmt
;
904 params
->auth_algs
= hapd
->conf
->auth_algs
;
905 params
->wpa_version
= hapd
->conf
->wpa
;
906 params
->privacy
= hapd
->conf
->ssid
.wep
.keys_set
|| hapd
->conf
->wpa
||
907 (hapd
->conf
->ieee802_1x
&&
908 (hapd
->conf
->default_wep_key_len
||
909 hapd
->conf
->individual_wep_key_len
));
910 switch (hapd
->conf
->ignore_broadcast_ssid
) {
912 params
->hide_ssid
= NO_SSID_HIDING
;
915 params
->hide_ssid
= HIDDEN_SSID_ZERO_LEN
;
918 params
->hide_ssid
= HIDDEN_SSID_ZERO_CONTENTS
;
921 params
->isolate
= hapd
->conf
->isolate
;
922 params
->smps_mode
= hapd
->iconf
->ht_capab
& HT_CAP_INFO_SMPS_MASK
;
924 params
->cts_protect
= !!(ieee802_11_erp_info(hapd
) &
925 ERP_INFO_USE_PROTECTION
);
926 params
->preamble
= hapd
->iface
->num_sta_no_short_preamble
== 0 &&
927 hapd
->iconf
->preamble
== SHORT_PREAMBLE
;
928 if (hapd
->iface
->current_mode
&&
929 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
930 params
->short_slot_time
=
931 hapd
->iface
->num_sta_no_short_slot_time
> 0 ? 0 : 1;
933 params
->short_slot_time
= -1;
934 if (!hapd
->iconf
->ieee80211n
|| hapd
->conf
->disable_11n
)
935 params
->ht_opmode
= -1;
937 params
->ht_opmode
= hapd
->iface
->ht_op_mode
;
938 #endif /* NEED_AP_MLME */
939 params
->interworking
= hapd
->conf
->interworking
;
940 if (hapd
->conf
->interworking
&&
941 !is_zero_ether_addr(hapd
->conf
->hessid
))
942 params
->hessid
= hapd
->conf
->hessid
;
943 params
->access_network_type
= hapd
->conf
->access_network_type
;
944 params
->ap_max_inactivity
= hapd
->conf
->ap_max_inactivity
;
946 params
->disable_dgaf
= hapd
->conf
->disable_dgaf
;
947 if (hapd
->conf
->osen
) {
951 #endif /* CONFIG_HS20 */
956 void ieee802_11_free_ap_params(struct wpa_driver_ap_params
*params
)
958 os_free(params
->tail
);
960 os_free(params
->head
);
962 os_free(params
->proberesp
);
963 params
->proberesp
= NULL
;
967 int ieee802_11_set_beacon(struct hostapd_data
*hapd
)
969 struct wpa_driver_ap_params params
;
970 struct hostapd_freq_params freq
;
971 struct hostapd_iface
*iface
= hapd
->iface
;
972 struct hostapd_config
*iconf
= iface
->conf
;
973 struct wpabuf
*beacon
, *proberesp
, *assocresp
;
976 if (hapd
->csa_in_progress
) {
977 wpa_printf(MSG_ERROR
, "Cannot set beacons during CSA period");
981 hapd
->beacon_set_done
= 1;
983 if (ieee802_11_build_ap_params(hapd
, ¶ms
) < 0)
986 if (hostapd_build_ap_extra_ies(hapd
, &beacon
, &proberesp
, &assocresp
) <
990 params
.beacon_ies
= beacon
;
991 params
.proberesp_ies
= proberesp
;
992 params
.assocresp_ies
= assocresp
;
994 if (iface
->current_mode
&&
995 hostapd_set_freq_params(&freq
, iconf
->hw_mode
, iface
->freq
,
996 iconf
->channel
, iconf
->ieee80211n
,
998 iconf
->secondary_channel
,
999 iconf
->vht_oper_chwidth
,
1000 iconf
->vht_oper_centr_freq_seg0_idx
,
1001 iconf
->vht_oper_centr_freq_seg1_idx
,
1002 iface
->current_mode
->vht_capab
) == 0)
1003 params
.freq
= &freq
;
1005 res
= hostapd_drv_set_ap(hapd
, ¶ms
);
1006 hostapd_free_ap_extra_ies(hapd
, beacon
, proberesp
, assocresp
);
1008 wpa_printf(MSG_ERROR
, "Failed to set beacon parameters");
1012 ieee802_11_free_ap_params(¶ms
);
1017 int ieee802_11_set_beacons(struct hostapd_iface
*iface
)
1022 for (i
= 0; i
< iface
->num_bss
; i
++) {
1023 if (iface
->bss
[i
]->started
&&
1024 ieee802_11_set_beacon(iface
->bss
[i
]) < 0)
1032 /* only update beacons if started */
1033 int ieee802_11_update_beacons(struct hostapd_iface
*iface
)
1038 for (i
= 0; i
< iface
->num_bss
; i
++) {
1039 if (iface
->bss
[i
]->beacon_set_done
&& iface
->bss
[i
]->started
&&
1040 ieee802_11_set_beacon(iface
->bss
[i
]) < 0)
1047 #endif /* CONFIG_NATIVE_WINDOWS */