2 * hostapd / IEEE 802.11 Management: Beacon and Probe Request/Response
3 * Copyright (c) 2002-2004, Instant802 Networks, Inc.
4 * Copyright (c) 2005-2006, Devicescape Software, Inc.
5 * Copyright (c) 2008-2012, Jouni Malinen <j@w1.fi>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * Alternatively, this software may be distributed under the terms of BSD
14 * See README and COPYING for more details.
17 #include "utils/includes.h"
19 #ifndef CONFIG_NATIVE_WINDOWS
21 #include "utils/common.h"
22 #include "common/ieee802_11_defs.h"
23 #include "common/ieee802_11_common.h"
24 #include "wps/wps_defs.h"
27 #include "ieee802_11.h"
30 #include "ap_config.h"
32 #include "p2p_hostapd.h"
33 #include "ap_drv_ops.h"
40 static u8
* hostapd_eid_bss_load(struct hostapd_data
*hapd
, u8
*eid
, size_t len
)
42 #ifdef CONFIG_TESTING_OPTIONS
43 if (hapd
->conf
->bss_load_test_set
) {
46 *eid
++ = WLAN_EID_BSS_LOAD
;
48 os_memcpy(eid
, hapd
->conf
->bss_load_test
, 5);
51 #endif /* CONFIG_TESTING_OPTIONS */
56 static u8
ieee802_11_erp_info(struct hostapd_data
*hapd
)
60 if (hapd
->iface
->current_mode
== NULL
||
61 hapd
->iface
->current_mode
->mode
!= HOSTAPD_MODE_IEEE80211G
)
64 if (hapd
->iface
->olbc
)
65 erp
|= ERP_INFO_USE_PROTECTION
;
66 if (hapd
->iface
->num_sta_non_erp
> 0) {
67 erp
|= ERP_INFO_NON_ERP_PRESENT
|
68 ERP_INFO_USE_PROTECTION
;
70 if (hapd
->iface
->num_sta_no_short_preamble
> 0 ||
71 hapd
->iconf
->preamble
== LONG_PREAMBLE
)
72 erp
|= ERP_INFO_BARKER_PREAMBLE_MODE
;
78 static u8
* hostapd_eid_ds_params(struct hostapd_data
*hapd
, u8
*eid
)
80 *eid
++ = WLAN_EID_DS_PARAMS
;
82 *eid
++ = hapd
->iconf
->channel
;
87 static u8
* hostapd_eid_erp_info(struct hostapd_data
*hapd
, u8
*eid
)
89 if (hapd
->iface
->current_mode
== NULL
||
90 hapd
->iface
->current_mode
->mode
!= HOSTAPD_MODE_IEEE80211G
)
93 /* Set NonERP_present and use_protection bits if there
94 * are any associated NonERP stations. */
95 /* TODO: use_protection bit can be set to zero even if
96 * there are NonERP stations present. This optimization
97 * might be useful if NonERP stations are "quiet".
98 * See 802.11g/D6 E-1 for recommended practice.
99 * In addition, Non ERP present might be set, if AP detects Non ERP
100 * operation on other APs. */
102 /* Add ERP Information element */
103 *eid
++ = WLAN_EID_ERP_INFO
;
105 *eid
++ = ieee802_11_erp_info(hapd
);
111 static u8
* hostapd_eid_country_add(u8
*pos
, u8
*end
, int chan_spacing
,
112 struct hostapd_channel_data
*start
,
113 struct hostapd_channel_data
*prev
)
118 /* first channel number */
119 *pos
++ = start
->chan
;
120 /* number of channels */
121 *pos
++ = (prev
->chan
- start
->chan
) / chan_spacing
+ 1;
122 /* maximum transmit power level */
123 *pos
++ = start
->max_tx_power
;
129 static u8
* hostapd_eid_country(struct hostapd_data
*hapd
, u8
*eid
,
133 u8
*end
= eid
+ max_len
;
135 struct hostapd_hw_modes
*mode
;
136 struct hostapd_channel_data
*start
, *prev
;
137 int chan_spacing
= 1;
139 if (!hapd
->iconf
->ieee80211d
|| max_len
< 6 ||
140 hapd
->iface
->current_mode
== NULL
)
143 *pos
++ = WLAN_EID_COUNTRY
;
144 pos
++; /* length will be set later */
145 os_memcpy(pos
, hapd
->iconf
->country
, 3); /* e.g., 'US ' */
148 mode
= hapd
->iface
->current_mode
;
149 if (mode
->mode
== HOSTAPD_MODE_IEEE80211A
)
153 for (i
= 0; i
< mode
->num_channels
; i
++) {
154 struct hostapd_channel_data
*chan
= &mode
->channels
[i
];
155 if (chan
->flag
& HOSTAPD_CHAN_DISABLED
)
158 prev
->chan
+ chan_spacing
== chan
->chan
&&
159 start
->max_tx_power
== chan
->max_tx_power
) {
161 continue; /* can use same entry */
165 pos
= hostapd_eid_country_add(pos
, end
, chan_spacing
,
170 /* Start new group */
175 pos
= hostapd_eid_country_add(pos
, end
, chan_spacing
,
179 if ((pos
- eid
) & 1) {
182 *pos
++ = 0; /* pad for 16-bit alignment */
185 eid
[1] = (pos
- eid
) - 2;
191 static u8
* hostapd_eid_wpa(struct hostapd_data
*hapd
, u8
*eid
, size_t len
)
196 ie
= wpa_auth_get_wpa_ie(hapd
->wpa_auth
, &ielen
);
197 if (ie
== NULL
|| ielen
> len
)
200 os_memcpy(eid
, ie
, ielen
);
205 static u8
* hostapd_eid_csa(struct hostapd_data
*hapd
, u8
*eid
)
209 if (!hapd
->iface
->cs_freq_params
.freq
)
212 if (ieee80211_freq_to_chan(hapd
->iface
->cs_freq_params
.freq
, &chan
) ==
216 *eid
++ = WLAN_EID_CHANNEL_SWITCH
;
218 *eid
++ = hapd
->iface
->cs_block_tx
;
220 *eid
++ = hapd
->iface
->cs_count
;
226 static u8
* hostapd_gen_probe_resp(struct hostapd_data
*hapd
,
227 struct sta_info
*sta
,
228 const struct ieee80211_mgmt
*req
,
229 int is_p2p
, size_t *resp_len
)
231 struct ieee80211_mgmt
*resp
;
232 u8
*pos
, *epos
, *old_pos
;
235 #define MAX_PROBERESP_LEN 768
236 buflen
= MAX_PROBERESP_LEN
;
238 if (hapd
->wps_probe_resp_ie
)
239 buflen
+= wpabuf_len(hapd
->wps_probe_resp_ie
);
240 #endif /* CONFIG_WPS */
242 if (hapd
->p2p_probe_resp_ie
)
243 buflen
+= wpabuf_len(hapd
->p2p_probe_resp_ie
);
244 #endif /* CONFIG_P2P */
245 if (hapd
->conf
->vendor_elements
)
246 buflen
+= wpabuf_len(hapd
->conf
->vendor_elements
);
247 resp
= os_zalloc(buflen
);
251 epos
= ((u8
*) resp
) + MAX_PROBERESP_LEN
;
253 resp
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
254 WLAN_FC_STYPE_PROBE_RESP
);
256 os_memcpy(resp
->da
, req
->sa
, ETH_ALEN
);
257 os_memcpy(resp
->sa
, hapd
->own_addr
, ETH_ALEN
);
259 os_memcpy(resp
->bssid
, hapd
->own_addr
, ETH_ALEN
);
260 resp
->u
.probe_resp
.beacon_int
=
261 host_to_le16(hapd
->iconf
->beacon_int
);
263 /* hardware or low-level driver will setup seq_ctrl and timestamp */
264 resp
->u
.probe_resp
.capab_info
=
265 host_to_le16(hostapd_own_capab_info(hapd
, sta
, 1));
267 pos
= resp
->u
.probe_resp
.variable
;
268 *pos
++ = WLAN_EID_SSID
;
269 *pos
++ = hapd
->conf
->ssid
.ssid_len
;
270 os_memcpy(pos
, hapd
->conf
->ssid
.ssid
, hapd
->conf
->ssid
.ssid_len
);
271 pos
+= hapd
->conf
->ssid
.ssid_len
;
273 /* Supported rates */
274 pos
= hostapd_eid_supp_rates(hapd
, pos
);
277 pos
= hostapd_eid_ds_params(hapd
, pos
);
279 pos
= hostapd_eid_country(hapd
, pos
, epos
- pos
);
281 /* ERP Information element */
282 pos
= hostapd_eid_erp_info(hapd
, pos
);
284 /* Extended supported rates */
285 pos
= hostapd_eid_ext_supp_rates(hapd
, pos
);
288 pos
= hostapd_eid_wpa(hapd
, pos
, epos
- pos
);
290 pos
= hostapd_eid_bss_load(hapd
, pos
, epos
- pos
);
292 #ifdef CONFIG_IEEE80211N
293 pos
= hostapd_eid_ht_capabilities(hapd
, pos
);
294 pos
= hostapd_eid_ht_operation(hapd
, pos
);
295 #endif /* CONFIG_IEEE80211N */
297 pos
= hostapd_eid_ext_capab(hapd
, pos
);
299 pos
= hostapd_eid_time_adv(hapd
, pos
);
300 pos
= hostapd_eid_time_zone(hapd
, pos
);
302 pos
= hostapd_eid_interworking(hapd
, pos
);
303 pos
= hostapd_eid_adv_proto(hapd
, pos
);
304 pos
= hostapd_eid_roaming_consortium(hapd
, pos
);
307 pos
= hostapd_eid_csa(hapd
, pos
);
309 /* save an offset to the counter - should be last byte */
310 hapd
->iface
->cs_c_off_proberesp
= (pos
!= old_pos
) ?
311 pos
- (u8
*) resp
- 1 : 0;
313 #ifdef CONFIG_IEEE80211AC
314 pos
= hostapd_eid_vht_capabilities(hapd
, pos
);
315 pos
= hostapd_eid_vht_operation(hapd
, pos
);
316 #endif /* CONFIG_IEEE80211AC */
318 /* Wi-Fi Alliance WMM */
319 pos
= hostapd_eid_wmm(hapd
, pos
);
322 if (hapd
->conf
->wps_state
&& hapd
->wps_probe_resp_ie
) {
323 os_memcpy(pos
, wpabuf_head(hapd
->wps_probe_resp_ie
),
324 wpabuf_len(hapd
->wps_probe_resp_ie
));
325 pos
+= wpabuf_len(hapd
->wps_probe_resp_ie
);
327 #endif /* CONFIG_WPS */
330 if ((hapd
->conf
->p2p
& P2P_ENABLED
) && is_p2p
&&
331 hapd
->p2p_probe_resp_ie
) {
332 os_memcpy(pos
, wpabuf_head(hapd
->p2p_probe_resp_ie
),
333 wpabuf_len(hapd
->p2p_probe_resp_ie
));
334 pos
+= wpabuf_len(hapd
->p2p_probe_resp_ie
);
336 #endif /* CONFIG_P2P */
337 #ifdef CONFIG_P2P_MANAGER
338 if ((hapd
->conf
->p2p
& (P2P_MANAGE
| P2P_ENABLED
| P2P_GROUP_OWNER
)) ==
340 pos
= hostapd_eid_p2p_manage(hapd
, pos
);
341 #endif /* CONFIG_P2P_MANAGER */
344 pos
= hostapd_eid_hs20_indication(hapd
, pos
);
345 #endif /* CONFIG_HS20 */
347 if (hapd
->conf
->vendor_elements
) {
348 os_memcpy(pos
, wpabuf_head(hapd
->conf
->vendor_elements
),
349 wpabuf_len(hapd
->conf
->vendor_elements
));
350 pos
+= wpabuf_len(hapd
->conf
->vendor_elements
);
353 *resp_len
= pos
- (u8
*) resp
;
358 enum ssid_match_result
{
364 static enum ssid_match_result
ssid_match(struct hostapd_data
*hapd
,
365 const u8
*ssid
, size_t ssid_len
,
367 size_t ssid_list_len
)
374 if (ssid_len
== hapd
->conf
->ssid
.ssid_len
&&
375 os_memcmp(ssid
, hapd
->conf
->ssid
.ssid
, ssid_len
) == 0)
376 return EXACT_SSID_MATCH
;
378 if (ssid_list
== NULL
)
379 return wildcard
? WILDCARD_SSID_MATCH
: NO_SSID_MATCH
;
382 end
= ssid_list
+ ssid_list_len
;
383 while (pos
+ 1 <= end
) {
384 if (pos
+ 2 + pos
[1] > end
)
388 if (pos
[1] == hapd
->conf
->ssid
.ssid_len
&&
389 os_memcmp(pos
+ 2, hapd
->conf
->ssid
.ssid
, pos
[1]) == 0)
390 return EXACT_SSID_MATCH
;
394 return wildcard
? WILDCARD_SSID_MATCH
: NO_SSID_MATCH
;
398 void handle_probe_req(struct hostapd_data
*hapd
,
399 const struct ieee80211_mgmt
*mgmt
, size_t len
,
403 struct ieee802_11_elems elems
;
406 struct sta_info
*sta
= NULL
;
409 enum ssid_match_result res
;
411 ie
= mgmt
->u
.probe_req
.variable
;
412 if (len
< IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.probe_req
))
414 ie_len
= len
- (IEEE80211_HDRLEN
+ sizeof(mgmt
->u
.probe_req
));
416 for (i
= 0; hapd
->probereq_cb
&& i
< hapd
->num_probereq_cb
; i
++)
417 if (hapd
->probereq_cb
[i
].cb(hapd
->probereq_cb
[i
].ctx
,
418 mgmt
->sa
, mgmt
->da
, mgmt
->bssid
,
419 ie
, ie_len
, ssi_signal
) > 0)
422 if (!hapd
->iconf
->send_probe_response
)
425 if (ieee802_11_parse_elems(ie
, ie_len
, &elems
, 0) == ParseFailed
) {
426 wpa_printf(MSG_DEBUG
, "Could not parse ProbeReq from " MACSTR
,
431 if ((!elems
.ssid
|| !elems
.supp_rates
)) {
432 wpa_printf(MSG_DEBUG
, "STA " MACSTR
" sent probe request "
433 "without SSID or supported rates element",
439 if (hapd
->p2p
&& elems
.wps_ie
) {
441 wps
= ieee802_11_vendor_ie_concat(ie
, ie_len
, WPS_DEV_OUI_WFA
);
442 if (wps
&& !p2p_group_match_dev_type(hapd
->p2p_group
, wps
)) {
443 wpa_printf(MSG_MSGDUMP
, "P2P: Ignore Probe Request "
444 "due to mismatch with Requested Device "
452 if (hapd
->p2p
&& elems
.p2p
) {
454 p2p
= ieee802_11_vendor_ie_concat(ie
, ie_len
, P2P_IE_VENDOR_TYPE
);
455 if (p2p
&& !p2p_group_match_dev_id(hapd
->p2p_group
, p2p
)) {
456 wpa_printf(MSG_MSGDUMP
, "P2P: Ignore Probe Request "
457 "due to mismatch with Device ID");
463 #endif /* CONFIG_P2P */
465 if (hapd
->conf
->ignore_broadcast_ssid
&& elems
.ssid_len
== 0 &&
466 elems
.ssid_list_len
== 0) {
467 wpa_printf(MSG_MSGDUMP
, "Probe Request from " MACSTR
" for "
468 "broadcast SSID ignored", MAC2STR(mgmt
->sa
));
472 sta
= ap_get_sta(hapd
, mgmt
->sa
);
475 if ((hapd
->conf
->p2p
& P2P_GROUP_OWNER
) &&
476 elems
.ssid_len
== P2P_WILDCARD_SSID_LEN
&&
477 os_memcmp(elems
.ssid
, P2P_WILDCARD_SSID
,
478 P2P_WILDCARD_SSID_LEN
) == 0) {
479 /* Process P2P Wildcard SSID like Wildcard SSID */
482 #endif /* CONFIG_P2P */
484 res
= ssid_match(hapd
, elems
.ssid
, elems
.ssid_len
,
485 elems
.ssid_list
, elems
.ssid_list_len
);
486 if (res
!= NO_SSID_MATCH
) {
488 sta
->ssid_probe
= &hapd
->conf
->ssid
;
490 if (!(mgmt
->da
[0] & 0x01)) {
492 ieee802_11_print_ssid(ssid_txt
, elems
.ssid
,
494 wpa_printf(MSG_MSGDUMP
, "Probe Request from " MACSTR
495 " for foreign SSID '%s' (DA " MACSTR
")%s",
496 MAC2STR(mgmt
->sa
), ssid_txt
,
498 elems
.ssid_list
? " (SSID list)" : "");
503 #ifdef CONFIG_INTERWORKING
504 if (elems
.interworking
&& elems
.interworking_len
>= 1) {
505 u8 ant
= elems
.interworking
[0] & 0x0f;
506 if (ant
!= INTERWORKING_ANT_WILDCARD
&&
507 ant
!= hapd
->conf
->access_network_type
) {
508 wpa_printf(MSG_MSGDUMP
, "Probe Request from " MACSTR
509 " for mismatching ANT %u ignored",
510 MAC2STR(mgmt
->sa
), ant
);
515 if (elems
.interworking
&&
516 (elems
.interworking_len
== 7 || elems
.interworking_len
== 9)) {
518 if (elems
.interworking_len
== 7)
519 hessid
= elems
.interworking
+ 1;
521 hessid
= elems
.interworking
+ 1 + 2;
522 if (!is_broadcast_ether_addr(hessid
) &&
523 os_memcmp(hessid
, hapd
->conf
->hessid
, ETH_ALEN
) != 0) {
524 wpa_printf(MSG_MSGDUMP
, "Probe Request from " MACSTR
525 " for mismatching HESSID " MACSTR
527 MAC2STR(mgmt
->sa
), MAC2STR(hessid
));
531 #endif /* CONFIG_INTERWORKING */
534 if ((hapd
->conf
->p2p
& P2P_GROUP_OWNER
) &&
535 supp_rates_11b_only(&elems
)) {
536 /* Indicates support for 11b rates only */
537 wpa_printf(MSG_EXCESSIVE
, "P2P: Ignore Probe Request from "
538 MACSTR
" with only 802.11b rates",
542 #endif /* CONFIG_P2P */
544 /* TODO: verify that supp_rates contains at least one matching rate
545 * with AP configuration */
547 #ifdef CONFIG_TESTING_OPTIONS
548 if (hapd
->iconf
->ignore_probe_probability
> 0.0d
&&
549 drand48() < hapd
->iconf
->ignore_probe_probability
) {
551 "TESTING: ignoring probe request from " MACSTR
,
555 #endif /* CONFIG_TESTING_OPTIONS */
557 resp
= hostapd_gen_probe_resp(hapd
, sta
, mgmt
, elems
.p2p
!= NULL
,
563 * If this is a broadcast probe request, apply no ack policy to avoid
566 noack
= !!(res
== WILDCARD_SSID_MATCH
&&
567 is_broadcast_ether_addr(mgmt
->da
));
569 if (hostapd_drv_send_mlme(hapd
, resp
, resp_len
, noack
) < 0)
570 wpa_printf(MSG_INFO
, "handle_probe_req: send failed");
574 wpa_printf(MSG_EXCESSIVE
, "STA " MACSTR
" sent probe request for %s "
575 "SSID", MAC2STR(mgmt
->sa
),
576 elems
.ssid_len
== 0 ? "broadcast" : "our");
580 static u8
* hostapd_probe_resp_offloads(struct hostapd_data
*hapd
,
583 /* check probe response offloading caps and print warnings */
584 if (!(hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD
))
588 if (hapd
->conf
->wps_state
&& hapd
->wps_probe_resp_ie
&&
589 (!(hapd
->iface
->probe_resp_offloads
&
590 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS
|
591 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2
))))
592 wpa_printf(MSG_WARNING
, "Device is trying to offload WPS "
593 "Probe Response while not supporting this");
594 #endif /* CONFIG_WPS */
597 if ((hapd
->conf
->p2p
& P2P_ENABLED
) && hapd
->p2p_probe_resp_ie
&&
598 !(hapd
->iface
->probe_resp_offloads
&
599 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P
))
600 wpa_printf(MSG_WARNING
, "Device is trying to offload P2P "
601 "Probe Response while not supporting this");
602 #endif /* CONFIG_P2P */
604 if (hapd
->conf
->interworking
&&
605 !(hapd
->iface
->probe_resp_offloads
&
606 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING
))
607 wpa_printf(MSG_WARNING
, "Device is trying to offload "
608 "Interworking Probe Response while not supporting "
611 /* Generate a Probe Response template for the non-P2P case */
612 return hostapd_gen_probe_resp(hapd
, NULL
, NULL
, 0, resp_len
);
615 #endif /* NEED_AP_MLME */
618 int ieee802_11_build_ap_params(struct hostapd_data
*hapd
,
619 struct wpa_driver_ap_params
*params
)
621 struct ieee80211_mgmt
*head
= NULL
;
623 size_t head_len
= 0, tail_len
= 0;
628 u8
*pos
, *tailpos
, *old_pos
;
630 #define BEACON_HEAD_BUF_SIZE 256
631 #define BEACON_TAIL_BUF_SIZE 512
632 head
= os_zalloc(BEACON_HEAD_BUF_SIZE
);
633 tail_len
= BEACON_TAIL_BUF_SIZE
;
635 if (hapd
->conf
->wps_state
&& hapd
->wps_beacon_ie
)
636 tail_len
+= wpabuf_len(hapd
->wps_beacon_ie
);
637 #endif /* CONFIG_WPS */
639 if (hapd
->p2p_beacon_ie
)
640 tail_len
+= wpabuf_len(hapd
->p2p_beacon_ie
);
641 #endif /* CONFIG_P2P */
642 if (hapd
->conf
->vendor_elements
)
643 tail_len
+= wpabuf_len(hapd
->conf
->vendor_elements
);
644 tailpos
= tail
= os_malloc(tail_len
);
645 if (head
== NULL
|| tail
== NULL
) {
646 wpa_printf(MSG_ERROR
, "Failed to set beacon data");
652 head
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
653 WLAN_FC_STYPE_BEACON
);
654 head
->duration
= host_to_le16(0);
655 os_memset(head
->da
, 0xff, ETH_ALEN
);
657 os_memcpy(head
->sa
, hapd
->own_addr
, ETH_ALEN
);
658 os_memcpy(head
->bssid
, hapd
->own_addr
, ETH_ALEN
);
659 head
->u
.beacon
.beacon_int
=
660 host_to_le16(hapd
->iconf
->beacon_int
);
662 /* hardware or low-level driver will setup seq_ctrl and timestamp */
663 capab_info
= hostapd_own_capab_info(hapd
, NULL
, 0);
664 head
->u
.beacon
.capab_info
= host_to_le16(capab_info
);
665 pos
= &head
->u
.beacon
.variable
[0];
668 *pos
++ = WLAN_EID_SSID
;
669 if (hapd
->conf
->ignore_broadcast_ssid
== 2) {
670 /* clear the data, but keep the correct length of the SSID */
671 *pos
++ = hapd
->conf
->ssid
.ssid_len
;
672 os_memset(pos
, 0, hapd
->conf
->ssid
.ssid_len
);
673 pos
+= hapd
->conf
->ssid
.ssid_len
;
674 } else if (hapd
->conf
->ignore_broadcast_ssid
) {
675 *pos
++ = 0; /* empty SSID */
677 *pos
++ = hapd
->conf
->ssid
.ssid_len
;
678 os_memcpy(pos
, hapd
->conf
->ssid
.ssid
,
679 hapd
->conf
->ssid
.ssid_len
);
680 pos
+= hapd
->conf
->ssid
.ssid_len
;
683 /* Supported rates */
684 pos
= hostapd_eid_supp_rates(hapd
, pos
);
687 pos
= hostapd_eid_ds_params(hapd
, pos
);
689 head_len
= pos
- (u8
*) head
;
691 tailpos
= hostapd_eid_country(hapd
, tailpos
,
692 tail
+ BEACON_TAIL_BUF_SIZE
- tailpos
);
694 /* ERP Information element */
695 tailpos
= hostapd_eid_erp_info(hapd
, tailpos
);
697 /* Extended supported rates */
698 tailpos
= hostapd_eid_ext_supp_rates(hapd
, tailpos
);
701 tailpos
= hostapd_eid_wpa(hapd
, tailpos
, tail
+ BEACON_TAIL_BUF_SIZE
-
704 tailpos
= hostapd_eid_bss_load(hapd
, tailpos
,
705 tail
+ BEACON_TAIL_BUF_SIZE
- tailpos
);
707 #ifdef CONFIG_IEEE80211N
708 tailpos
= hostapd_eid_ht_capabilities(hapd
, tailpos
);
709 tailpos
= hostapd_eid_ht_operation(hapd
, tailpos
);
710 #endif /* CONFIG_IEEE80211N */
712 tailpos
= hostapd_eid_ext_capab(hapd
, tailpos
);
715 * TODO: Time Advertisement element should only be included in some
716 * DTIM Beacon frames.
718 tailpos
= hostapd_eid_time_adv(hapd
, tailpos
);
720 tailpos
= hostapd_eid_interworking(hapd
, tailpos
);
721 tailpos
= hostapd_eid_adv_proto(hapd
, tailpos
);
722 tailpos
= hostapd_eid_roaming_consortium(hapd
, tailpos
);
724 tailpos
= hostapd_eid_csa(hapd
, tailpos
);
725 hapd
->iface
->cs_c_off_beacon
= (old_pos
!= tailpos
) ?
726 tailpos
- tail
- 1 : 0;
728 #ifdef CONFIG_IEEE80211AC
729 tailpos
= hostapd_eid_vht_capabilities(hapd
, tailpos
);
730 tailpos
= hostapd_eid_vht_operation(hapd
, tailpos
);
731 #endif /* CONFIG_IEEE80211AC */
733 /* Wi-Fi Alliance WMM */
734 tailpos
= hostapd_eid_wmm(hapd
, tailpos
);
737 if (hapd
->conf
->wps_state
&& hapd
->wps_beacon_ie
) {
738 os_memcpy(tailpos
, wpabuf_head(hapd
->wps_beacon_ie
),
739 wpabuf_len(hapd
->wps_beacon_ie
));
740 tailpos
+= wpabuf_len(hapd
->wps_beacon_ie
);
742 #endif /* CONFIG_WPS */
745 if ((hapd
->conf
->p2p
& P2P_ENABLED
) && hapd
->p2p_beacon_ie
) {
746 os_memcpy(tailpos
, wpabuf_head(hapd
->p2p_beacon_ie
),
747 wpabuf_len(hapd
->p2p_beacon_ie
));
748 tailpos
+= wpabuf_len(hapd
->p2p_beacon_ie
);
750 #endif /* CONFIG_P2P */
751 #ifdef CONFIG_P2P_MANAGER
752 if ((hapd
->conf
->p2p
& (P2P_MANAGE
| P2P_ENABLED
| P2P_GROUP_OWNER
)) ==
754 tailpos
= hostapd_eid_p2p_manage(hapd
, tailpos
);
755 #endif /* CONFIG_P2P_MANAGER */
758 tailpos
= hostapd_eid_hs20_indication(hapd
, tailpos
);
759 #endif /* CONFIG_HS20 */
761 if (hapd
->conf
->vendor_elements
) {
762 os_memcpy(tailpos
, wpabuf_head(hapd
->conf
->vendor_elements
),
763 wpabuf_len(hapd
->conf
->vendor_elements
));
764 tailpos
+= wpabuf_len(hapd
->conf
->vendor_elements
);
767 tail_len
= tailpos
> tail
? tailpos
- tail
: 0;
769 resp
= hostapd_probe_resp_offloads(hapd
, &resp_len
);
770 #endif /* NEED_AP_MLME */
772 os_memset(params
, 0, sizeof(*params
));
773 params
->head
= (u8
*) head
;
774 params
->head_len
= head_len
;
776 params
->tail_len
= tail_len
;
777 params
->proberesp
= resp
;
778 params
->proberesp_len
= resp_len
;
779 params
->dtim_period
= hapd
->conf
->dtim_period
;
780 params
->beacon_int
= hapd
->iconf
->beacon_int
;
781 params
->basic_rates
= hapd
->iface
->basic_rates
;
782 params
->ssid
= hapd
->conf
->ssid
.ssid
;
783 params
->ssid_len
= hapd
->conf
->ssid
.ssid_len
;
784 params
->pairwise_ciphers
= hapd
->conf
->rsn_pairwise
?
785 hapd
->conf
->rsn_pairwise
: hapd
->conf
->wpa_pairwise
;
786 params
->group_cipher
= hapd
->conf
->wpa_group
;
787 params
->key_mgmt_suites
= hapd
->conf
->wpa_key_mgmt
;
788 params
->auth_algs
= hapd
->conf
->auth_algs
;
789 params
->wpa_version
= hapd
->conf
->wpa
;
790 params
->privacy
= hapd
->conf
->ssid
.wep
.keys_set
|| hapd
->conf
->wpa
||
791 (hapd
->conf
->ieee802_1x
&&
792 (hapd
->conf
->default_wep_key_len
||
793 hapd
->conf
->individual_wep_key_len
));
794 switch (hapd
->conf
->ignore_broadcast_ssid
) {
796 params
->hide_ssid
= NO_SSID_HIDING
;
799 params
->hide_ssid
= HIDDEN_SSID_ZERO_LEN
;
802 params
->hide_ssid
= HIDDEN_SSID_ZERO_CONTENTS
;
805 params
->isolate
= hapd
->conf
->isolate
;
807 params
->cts_protect
= !!(ieee802_11_erp_info(hapd
) &
808 ERP_INFO_USE_PROTECTION
);
809 params
->preamble
= hapd
->iface
->num_sta_no_short_preamble
== 0 &&
810 hapd
->iconf
->preamble
== SHORT_PREAMBLE
;
811 if (hapd
->iface
->current_mode
&&
812 hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
813 params
->short_slot_time
=
814 hapd
->iface
->num_sta_no_short_slot_time
> 0 ? 0 : 1;
816 params
->short_slot_time
= -1;
817 if (!hapd
->iconf
->ieee80211n
|| hapd
->conf
->disable_11n
)
818 params
->ht_opmode
= -1;
820 params
->ht_opmode
= hapd
->iface
->ht_op_mode
;
821 #endif /* NEED_AP_MLME */
822 params
->interworking
= hapd
->conf
->interworking
;
823 if (hapd
->conf
->interworking
&&
824 !is_zero_ether_addr(hapd
->conf
->hessid
))
825 params
->hessid
= hapd
->conf
->hessid
;
826 params
->access_network_type
= hapd
->conf
->access_network_type
;
827 params
->ap_max_inactivity
= hapd
->conf
->ap_max_inactivity
;
829 params
->disable_dgaf
= hapd
->conf
->disable_dgaf
;
830 #endif /* CONFIG_HS20 */
835 void ieee802_11_free_ap_params(struct wpa_driver_ap_params
*params
)
837 os_free(params
->tail
);
839 os_free(params
->head
);
841 os_free(params
->proberesp
);
842 params
->proberesp
= NULL
;
846 void ieee802_11_set_beacon(struct hostapd_data
*hapd
)
848 struct wpa_driver_ap_params params
;
849 struct wpabuf
*beacon
, *proberesp
, *assocresp
;
851 if (hapd
->iface
->csa_in_progress
) {
852 wpa_printf(MSG_ERROR
, "Cannot set beacons during CSA period");
856 hapd
->beacon_set_done
= 1;
858 if (ieee802_11_build_ap_params(hapd
, ¶ms
) < 0)
861 if (hostapd_build_ap_extra_ies(hapd
, &beacon
, &proberesp
, &assocresp
) <
865 params
.beacon_ies
= beacon
;
866 params
.proberesp_ies
= proberesp
;
867 params
.assocresp_ies
= assocresp
;
869 if (hostapd_drv_set_ap(hapd
, ¶ms
))
870 wpa_printf(MSG_ERROR
, "Failed to set beacon parameters");
871 hostapd_free_ap_extra_ies(hapd
, beacon
, proberesp
, assocresp
);
873 ieee802_11_free_ap_params(¶ms
);
877 void ieee802_11_set_beacons(struct hostapd_iface
*iface
)
880 for (i
= 0; i
< iface
->num_bss
; i
++) {
881 if (iface
->bss
[i
]->started
)
882 ieee802_11_set_beacon(iface
->bss
[i
]);
887 /* only update beacons if started */
888 void ieee802_11_update_beacons(struct hostapd_iface
*iface
)
891 for (i
= 0; i
< iface
->num_bss
; i
++)
892 if (iface
->bss
[i
]->beacon_set_done
&& iface
->bss
[i
]->started
)
893 ieee802_11_set_beacon(iface
->bss
[i
]);
896 #endif /* CONFIG_NATIVE_WINDOWS */