HS 2.0: Add mechanism for disabling DGAF
[mech_eap.git] / src / ap / beacon.c
1 /*
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-2009, Jouni Malinen <j@w1.fi>
6  *
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.
10  *
11  * Alternatively, this software may be distributed under the terms of BSD
12  * license.
13  *
14  * See README and COPYING for more details.
15  */
16
17 #include "utils/includes.h"
18
19 #ifndef CONFIG_NATIVE_WINDOWS
20
21 #include "utils/common.h"
22 #include "common/ieee802_11_defs.h"
23 #include "common/ieee802_11_common.h"
24 #include "drivers/driver.h"
25 #include "wps/wps_defs.h"
26 #include "p2p/p2p.h"
27 #include "hostapd.h"
28 #include "ieee802_11.h"
29 #include "wpa_auth.h"
30 #include "wmm.h"
31 #include "ap_config.h"
32 #include "sta_info.h"
33 #include "p2p_hostapd.h"
34 #include "ap_drv_ops.h"
35 #include "beacon.h"
36 #include "hs20.h"
37
38
39 #ifdef NEED_AP_MLME
40
41 static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
42 {
43         u8 erp = 0;
44
45         if (hapd->iface->current_mode == NULL ||
46             hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
47                 return 0;
48
49         if (hapd->iface->olbc)
50                 erp |= ERP_INFO_USE_PROTECTION;
51         if (hapd->iface->num_sta_non_erp > 0) {
52                 erp |= ERP_INFO_NON_ERP_PRESENT |
53                         ERP_INFO_USE_PROTECTION;
54         }
55         if (hapd->iface->num_sta_no_short_preamble > 0 ||
56             hapd->iconf->preamble == LONG_PREAMBLE)
57                 erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
58
59         return erp;
60 }
61
62
63 static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
64 {
65         *eid++ = WLAN_EID_DS_PARAMS;
66         *eid++ = 1;
67         *eid++ = hapd->iconf->channel;
68         return eid;
69 }
70
71
72 static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
73 {
74         if (hapd->iface->current_mode == NULL ||
75             hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
76                 return eid;
77
78         /* Set NonERP_present and use_protection bits if there
79          * are any associated NonERP stations. */
80         /* TODO: use_protection bit can be set to zero even if
81          * there are NonERP stations present. This optimization
82          * might be useful if NonERP stations are "quiet".
83          * See 802.11g/D6 E-1 for recommended practice.
84          * In addition, Non ERP present might be set, if AP detects Non ERP
85          * operation on other APs. */
86
87         /* Add ERP Information element */
88         *eid++ = WLAN_EID_ERP_INFO;
89         *eid++ = 1;
90         *eid++ = ieee802_11_erp_info(hapd);
91
92         return eid;
93 }
94
95
96 static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
97                                     struct hostapd_channel_data *start,
98                                     struct hostapd_channel_data *prev)
99 {
100         if (end - pos < 3)
101                 return pos;
102
103         /* first channel number */
104         *pos++ = start->chan;
105         /* number of channels */
106         *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
107         /* maximum transmit power level */
108         *pos++ = start->max_tx_power;
109
110         return pos;
111 }
112
113
114 static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
115                                 int max_len)
116 {
117         u8 *pos = eid;
118         u8 *end = eid + max_len;
119         int i;
120         struct hostapd_hw_modes *mode;
121         struct hostapd_channel_data *start, *prev;
122         int chan_spacing = 1;
123
124         if (!hapd->iconf->ieee80211d || max_len < 6 ||
125             hapd->iface->current_mode == NULL)
126                 return eid;
127
128         *pos++ = WLAN_EID_COUNTRY;
129         pos++; /* length will be set later */
130         os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
131         pos += 3;
132
133         mode = hapd->iface->current_mode;
134         if (mode->mode == HOSTAPD_MODE_IEEE80211A)
135                 chan_spacing = 4;
136
137         start = prev = NULL;
138         for (i = 0; i < mode->num_channels; i++) {
139                 struct hostapd_channel_data *chan = &mode->channels[i];
140                 if (chan->flag & HOSTAPD_CHAN_DISABLED)
141                         continue;
142                 if (start && prev &&
143                     prev->chan + chan_spacing == chan->chan &&
144                     start->max_tx_power == chan->max_tx_power) {
145                         prev = chan;
146                         continue; /* can use same entry */
147                 }
148
149                 if (start) {
150                         pos = hostapd_eid_country_add(pos, end, chan_spacing,
151                                                       start, prev);
152                         start = NULL;
153                 }
154
155                 /* Start new group */
156                 start = prev = chan;
157         }
158
159         if (start) {
160                 pos = hostapd_eid_country_add(pos, end, chan_spacing,
161                                               start, prev);
162         }
163
164         if ((pos - eid) & 1) {
165                 if (end - pos < 1)
166                         return eid;
167                 *pos++ = 0; /* pad for 16-bit alignment */
168         }
169
170         eid[1] = (pos - eid) - 2;
171
172         return pos;
173 }
174
175
176 static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
177 {
178         const u8 *ie;
179         size_t ielen;
180
181         ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
182         if (ie == NULL || ielen > len)
183                 return eid;
184
185         os_memcpy(eid, ie, ielen);
186         return eid + ielen;
187 }
188
189
190 static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
191                                    struct sta_info *sta,
192                                    const struct ieee80211_mgmt *req,
193                                    int is_p2p, size_t *resp_len)
194 {
195         struct ieee80211_mgmt *resp;
196         u8 *pos, *epos;
197         size_t buflen;
198
199 #define MAX_PROBERESP_LEN 768
200         buflen = MAX_PROBERESP_LEN;
201 #ifdef CONFIG_WPS
202         if (hapd->wps_probe_resp_ie)
203                 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
204 #endif /* CONFIG_WPS */
205 #ifdef CONFIG_P2P
206         if (hapd->p2p_probe_resp_ie)
207                 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
208 #endif /* CONFIG_P2P */
209         resp = os_zalloc(buflen);
210         if (resp == NULL)
211                 return NULL;
212
213         epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
214
215         resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
216                                            WLAN_FC_STYPE_PROBE_RESP);
217         if (req)
218                 os_memcpy(resp->da, req->sa, ETH_ALEN);
219         os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
220
221         os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
222         resp->u.probe_resp.beacon_int =
223                 host_to_le16(hapd->iconf->beacon_int);
224
225         /* hardware or low-level driver will setup seq_ctrl and timestamp */
226         resp->u.probe_resp.capab_info =
227                 host_to_le16(hostapd_own_capab_info(hapd, sta, 1));
228
229         pos = resp->u.probe_resp.variable;
230         *pos++ = WLAN_EID_SSID;
231         *pos++ = hapd->conf->ssid.ssid_len;
232         os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
233         pos += hapd->conf->ssid.ssid_len;
234
235         /* Supported rates */
236         pos = hostapd_eid_supp_rates(hapd, pos);
237
238         /* DS Params */
239         pos = hostapd_eid_ds_params(hapd, pos);
240
241         pos = hostapd_eid_country(hapd, pos, epos - pos);
242
243         /* ERP Information element */
244         pos = hostapd_eid_erp_info(hapd, pos);
245
246         /* Extended supported rates */
247         pos = hostapd_eid_ext_supp_rates(hapd, pos);
248
249         /* RSN, MDIE, WPA */
250         pos = hostapd_eid_wpa(hapd, pos, epos - pos);
251
252 #ifdef CONFIG_IEEE80211N
253         pos = hostapd_eid_ht_capabilities(hapd, pos);
254         pos = hostapd_eid_ht_operation(hapd, pos);
255 #endif /* CONFIG_IEEE80211N */
256
257         pos = hostapd_eid_ext_capab(hapd, pos);
258
259         pos = hostapd_eid_time_adv(hapd, pos);
260         pos = hostapd_eid_time_zone(hapd, pos);
261
262         pos = hostapd_eid_interworking(hapd, pos);
263         pos = hostapd_eid_adv_proto(hapd, pos);
264         pos = hostapd_eid_roaming_consortium(hapd, pos);
265
266 #ifdef CONFIG_IEEE80211AC
267         pos = hostapd_eid_vht_capabilities(hapd, pos);
268         pos = hostapd_eid_vht_operation(hapd, pos);
269 #endif /* CONFIG_IEEE80211AC */
270
271         /* Wi-Fi Alliance WMM */
272         pos = hostapd_eid_wmm(hapd, pos);
273
274 #ifdef CONFIG_WPS
275         if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
276                 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
277                           wpabuf_len(hapd->wps_probe_resp_ie));
278                 pos += wpabuf_len(hapd->wps_probe_resp_ie);
279         }
280 #endif /* CONFIG_WPS */
281
282 #ifdef CONFIG_P2P
283         if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
284             hapd->p2p_probe_resp_ie) {
285                 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
286                           wpabuf_len(hapd->p2p_probe_resp_ie));
287                 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
288         }
289 #endif /* CONFIG_P2P */
290 #ifdef CONFIG_P2P_MANAGER
291         if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
292             P2P_MANAGE)
293                 pos = hostapd_eid_p2p_manage(hapd, pos);
294 #endif /* CONFIG_P2P_MANAGER */
295
296 #ifdef CONFIG_HS20
297         pos = hostapd_eid_hs20_indication(hapd, pos);
298 #endif /* CONFIG_HS20 */
299
300         *resp_len = pos - (u8 *) resp;
301         return (u8 *) resp;
302 }
303
304
305 void handle_probe_req(struct hostapd_data *hapd,
306                       const struct ieee80211_mgmt *mgmt, size_t len,
307                       int ssi_signal)
308 {
309         u8 *resp;
310         struct ieee802_11_elems elems;
311         const u8 *ie;
312         size_t ie_len;
313         struct sta_info *sta = NULL;
314         size_t i, resp_len;
315         int noack;
316
317         ie = mgmt->u.probe_req.variable;
318         if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
319                 return;
320         ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
321
322         for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
323                 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
324                                             mgmt->sa, mgmt->da, mgmt->bssid,
325                                             ie, ie_len, ssi_signal) > 0)
326                         return;
327
328         if (!hapd->iconf->send_probe_response)
329                 return;
330
331         if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
332                 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
333                            MAC2STR(mgmt->sa));
334                 return;
335         }
336
337         if ((!elems.ssid || !elems.supp_rates)) {
338                 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
339                            "without SSID or supported rates element",
340                            MAC2STR(mgmt->sa));
341                 return;
342         }
343
344 #ifdef CONFIG_P2P
345         if (hapd->p2p && elems.wps_ie) {
346                 struct wpabuf *wps;
347                 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
348                 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
349                         wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
350                                    "due to mismatch with Requested Device "
351                                    "Type");
352                         wpabuf_free(wps);
353                         return;
354                 }
355                 wpabuf_free(wps);
356         }
357
358         if (hapd->p2p && elems.p2p) {
359                 struct wpabuf *p2p;
360                 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
361                 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
362                         wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
363                                    "due to mismatch with Device ID");
364                         wpabuf_free(p2p);
365                         return;
366                 }
367                 wpabuf_free(p2p);
368         }
369 #endif /* CONFIG_P2P */
370
371         if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0) {
372                 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
373                            "broadcast SSID ignored", MAC2STR(mgmt->sa));
374                 return;
375         }
376
377         sta = ap_get_sta(hapd, mgmt->sa);
378
379 #ifdef CONFIG_P2P
380         if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
381             elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
382             os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
383                       P2P_WILDCARD_SSID_LEN) == 0) {
384                 /* Process P2P Wildcard SSID like Wildcard SSID */
385                 elems.ssid_len = 0;
386         }
387 #endif /* CONFIG_P2P */
388
389         if (elems.ssid_len == 0 ||
390             (elems.ssid_len == hapd->conf->ssid.ssid_len &&
391              os_memcmp(elems.ssid, hapd->conf->ssid.ssid, elems.ssid_len) ==
392              0)) {
393                 if (sta)
394                         sta->ssid_probe = &hapd->conf->ssid;
395         } else {
396                 if (!(mgmt->da[0] & 0x01)) {
397                         char ssid_txt[33];
398                         ieee802_11_print_ssid(ssid_txt, elems.ssid,
399                                               elems.ssid_len);
400                         wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
401                                    " for foreign SSID '%s' (DA " MACSTR ")",
402                                    MAC2STR(mgmt->sa), ssid_txt,
403                                    MAC2STR(mgmt->da));
404                 }
405                 return;
406         }
407
408 #ifdef CONFIG_INTERWORKING
409         if (elems.interworking && elems.interworking_len >= 1) {
410                 u8 ant = elems.interworking[0] & 0x0f;
411                 if (ant != INTERWORKING_ANT_WILDCARD &&
412                     ant != hapd->conf->access_network_type) {
413                         wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
414                                    " for mismatching ANT %u ignored",
415                                    MAC2STR(mgmt->sa), ant);
416                         return;
417                 }
418         }
419
420         if (elems.interworking &&
421             (elems.interworking_len == 7 || elems.interworking_len == 9)) {
422                 const u8 *hessid;
423                 if (elems.interworking_len == 7)
424                         hessid = elems.interworking + 1;
425                 else
426                         hessid = elems.interworking + 1 + 2;
427                 if (!is_broadcast_ether_addr(hessid) &&
428                     os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
429                         wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
430                                    " for mismatching HESSID " MACSTR
431                                    " ignored",
432                                    MAC2STR(mgmt->sa), MAC2STR(hessid));
433                         return;
434                 }
435         }
436 #endif /* CONFIG_INTERWORKING */
437
438         /* TODO: verify that supp_rates contains at least one matching rate
439          * with AP configuration */
440
441         resp = hostapd_gen_probe_resp(hapd, sta, mgmt, elems.p2p != NULL,
442                                       &resp_len);
443         if (resp == NULL)
444                 return;
445
446         /*
447          * If this is a broadcast probe request, apply no ack policy to avoid
448          * excessive retries.
449          */
450         noack = !!(elems.ssid_len == 0 && is_broadcast_ether_addr(mgmt->da));
451
452         if (hostapd_drv_send_mlme(hapd, resp, resp_len, noack) < 0)
453                 perror("handle_probe_req: send");
454
455         os_free(resp);
456
457         wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
458                    "SSID", MAC2STR(mgmt->sa),
459                    elems.ssid_len == 0 ? "broadcast" : "our");
460 }
461
462
463 static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
464                                         size_t *resp_len)
465 {
466         /* check probe response offloading caps and print warnings */
467         if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
468                 return NULL;
469
470 #ifdef CONFIG_WPS
471         if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
472             (!(hapd->iface->probe_resp_offloads &
473                (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
474                 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
475                 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
476                            "Probe Response while not supporting this");
477 #endif /* CONFIG_WPS */
478
479 #ifdef CONFIG_P2P
480         if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
481             !(hapd->iface->probe_resp_offloads &
482               WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
483                 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
484                            "Probe Response while not supporting this");
485 #endif  /* CONFIG_P2P */
486
487         if (hapd->conf->interworking &&
488             !(hapd->iface->probe_resp_offloads &
489               WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
490                 wpa_printf(MSG_WARNING, "Device is trying to offload "
491                            "Interworking Probe Response while not supporting "
492                            "this");
493
494         /* Generate a Probe Response template for the non-P2P case */
495         return hostapd_gen_probe_resp(hapd, NULL, NULL, 0, resp_len);
496 }
497
498 #endif /* NEED_AP_MLME */
499
500
501 void ieee802_11_set_beacon(struct hostapd_data *hapd)
502 {
503         struct ieee80211_mgmt *head = NULL;
504         u8 *tail = NULL;
505         size_t head_len = 0, tail_len = 0;
506         u8 *resp = NULL;
507         size_t resp_len = 0;
508         struct wpa_driver_ap_params params;
509         struct wpabuf *beacon, *proberesp, *assocresp;
510 #ifdef NEED_AP_MLME
511         u16 capab_info;
512         u8 *pos, *tailpos;
513 #endif /* NEED_AP_MLME */
514
515         hapd->beacon_set_done = 1;
516
517 #ifdef NEED_AP_MLME
518
519 #define BEACON_HEAD_BUF_SIZE 256
520 #define BEACON_TAIL_BUF_SIZE 512
521         head = os_zalloc(BEACON_HEAD_BUF_SIZE);
522         tail_len = BEACON_TAIL_BUF_SIZE;
523 #ifdef CONFIG_WPS
524         if (hapd->conf->wps_state && hapd->wps_beacon_ie)
525                 tail_len += wpabuf_len(hapd->wps_beacon_ie);
526 #endif /* CONFIG_WPS */
527 #ifdef CONFIG_P2P
528         if (hapd->p2p_beacon_ie)
529                 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
530 #endif /* CONFIG_P2P */
531         tailpos = tail = os_malloc(tail_len);
532         if (head == NULL || tail == NULL) {
533                 wpa_printf(MSG_ERROR, "Failed to set beacon data");
534                 os_free(head);
535                 os_free(tail);
536                 return;
537         }
538
539         head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
540                                            WLAN_FC_STYPE_BEACON);
541         head->duration = host_to_le16(0);
542         os_memset(head->da, 0xff, ETH_ALEN);
543
544         os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
545         os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
546         head->u.beacon.beacon_int =
547                 host_to_le16(hapd->iconf->beacon_int);
548
549         /* hardware or low-level driver will setup seq_ctrl and timestamp */
550         capab_info = hostapd_own_capab_info(hapd, NULL, 0);
551         head->u.beacon.capab_info = host_to_le16(capab_info);
552         pos = &head->u.beacon.variable[0];
553
554         /* SSID */
555         *pos++ = WLAN_EID_SSID;
556         if (hapd->conf->ignore_broadcast_ssid == 2) {
557                 /* clear the data, but keep the correct length of the SSID */
558                 *pos++ = hapd->conf->ssid.ssid_len;
559                 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
560                 pos += hapd->conf->ssid.ssid_len;
561         } else if (hapd->conf->ignore_broadcast_ssid) {
562                 *pos++ = 0; /* empty SSID */
563         } else {
564                 *pos++ = hapd->conf->ssid.ssid_len;
565                 os_memcpy(pos, hapd->conf->ssid.ssid,
566                           hapd->conf->ssid.ssid_len);
567                 pos += hapd->conf->ssid.ssid_len;
568         }
569
570         /* Supported rates */
571         pos = hostapd_eid_supp_rates(hapd, pos);
572
573         /* DS Params */
574         pos = hostapd_eid_ds_params(hapd, pos);
575
576         head_len = pos - (u8 *) head;
577
578         tailpos = hostapd_eid_country(hapd, tailpos,
579                                       tail + BEACON_TAIL_BUF_SIZE - tailpos);
580
581         /* ERP Information element */
582         tailpos = hostapd_eid_erp_info(hapd, tailpos);
583
584         /* Extended supported rates */
585         tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
586
587         /* RSN, MDIE, WPA */
588         tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
589                                   tailpos);
590
591 #ifdef CONFIG_IEEE80211N
592         tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
593         tailpos = hostapd_eid_ht_operation(hapd, tailpos);
594 #endif /* CONFIG_IEEE80211N */
595
596         tailpos = hostapd_eid_ext_capab(hapd, tailpos);
597
598         /*
599          * TODO: Time Advertisement element should only be included in some
600          * DTIM Beacon frames.
601          */
602         tailpos = hostapd_eid_time_adv(hapd, tailpos);
603
604         tailpos = hostapd_eid_interworking(hapd, tailpos);
605         tailpos = hostapd_eid_adv_proto(hapd, tailpos);
606         tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
607
608 #ifdef CONFIG_IEEE80211AC
609         tailpos = hostapd_eid_vht_capabilities(hapd, tailpos);
610         tailpos = hostapd_eid_vht_operation(hapd, tailpos);
611 #endif /* CONFIG_IEEE80211AC */
612
613         /* Wi-Fi Alliance WMM */
614         tailpos = hostapd_eid_wmm(hapd, tailpos);
615
616 #ifdef CONFIG_WPS
617         if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
618                 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
619                           wpabuf_len(hapd->wps_beacon_ie));
620                 tailpos += wpabuf_len(hapd->wps_beacon_ie);
621         }
622 #endif /* CONFIG_WPS */
623
624 #ifdef CONFIG_P2P
625         if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
626                 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
627                           wpabuf_len(hapd->p2p_beacon_ie));
628                 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
629         }
630 #endif /* CONFIG_P2P */
631 #ifdef CONFIG_P2P_MANAGER
632         if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
633             P2P_MANAGE)
634                 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
635 #endif /* CONFIG_P2P_MANAGER */
636
637 #ifdef CONFIG_HS20
638         tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
639 #endif /* CONFIG_HS20 */
640
641         tail_len = tailpos > tail ? tailpos - tail : 0;
642
643         resp = hostapd_probe_resp_offloads(hapd, &resp_len);
644 #endif /* NEED_AP_MLME */
645
646         os_memset(&params, 0, sizeof(params));
647         params.head = (u8 *) head;
648         params.head_len = head_len;
649         params.tail = tail;
650         params.tail_len = tail_len;
651         params.proberesp = resp;
652         params.proberesp_len = resp_len;
653         params.dtim_period = hapd->conf->dtim_period;
654         params.beacon_int = hapd->iconf->beacon_int;
655         params.basic_rates = hapd->iconf->basic_rates;
656         params.ssid = (u8 *) hapd->conf->ssid.ssid;
657         params.ssid_len = hapd->conf->ssid.ssid_len;
658         params.pairwise_ciphers = hapd->conf->rsn_pairwise ?
659                 hapd->conf->rsn_pairwise : hapd->conf->wpa_pairwise;
660         params.group_cipher = hapd->conf->wpa_group;
661         params.key_mgmt_suites = hapd->conf->wpa_key_mgmt;
662         params.auth_algs = hapd->conf->auth_algs;
663         params.wpa_version = hapd->conf->wpa;
664         params.privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
665                 (hapd->conf->ieee802_1x &&
666                  (hapd->conf->default_wep_key_len ||
667                   hapd->conf->individual_wep_key_len));
668         switch (hapd->conf->ignore_broadcast_ssid) {
669         case 0:
670                 params.hide_ssid = NO_SSID_HIDING;
671                 break;
672         case 1:
673                 params.hide_ssid = HIDDEN_SSID_ZERO_LEN;
674                 break;
675         case 2:
676                 params.hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
677                 break;
678         }
679         hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp);
680         params.beacon_ies = beacon;
681         params.proberesp_ies = proberesp;
682         params.assocresp_ies = assocresp;
683         params.isolate = hapd->conf->isolate;
684 #ifdef NEED_AP_MLME
685         params.cts_protect = !!(ieee802_11_erp_info(hapd) &
686                                 ERP_INFO_USE_PROTECTION);
687         params.preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
688                 hapd->iconf->preamble == SHORT_PREAMBLE;
689         if (hapd->iface->current_mode &&
690             hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
691                 params.short_slot_time =
692                         hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
693         else
694                 params.short_slot_time = -1;
695         if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
696                 params.ht_opmode = -1;
697         else
698                 params.ht_opmode = hapd->iface->ht_op_mode;
699 #endif /* NEED_AP_MLME */
700         params.interworking = hapd->conf->interworking;
701         if (hapd->conf->interworking &&
702             !is_zero_ether_addr(hapd->conf->hessid))
703                 params.hessid = hapd->conf->hessid;
704         params.access_network_type = hapd->conf->access_network_type;
705         params.ap_max_inactivity = hapd->conf->ap_max_inactivity;
706 #ifdef CONFIG_HS20
707         params.disable_dgaf = hapd->conf->disable_dgaf;
708 #endif /* CONFIG_HS20 */
709         if (hostapd_drv_set_ap(hapd, &params))
710                 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
711         hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
712
713         os_free(tail);
714         os_free(head);
715         os_free(resp);
716 }
717
718
719 void ieee802_11_set_beacons(struct hostapd_iface *iface)
720 {
721         size_t i;
722         for (i = 0; i < iface->num_bss; i++)
723                 ieee802_11_set_beacon(iface->bss[i]);
724 }
725
726
727 /* only update beacons if started */
728 void ieee802_11_update_beacons(struct hostapd_iface *iface)
729 {
730         size_t i;
731         for (i = 0; i < iface->num_bss; i++)
732                 if (iface->bss[i]->beacon_set_done)
733                         ieee802_11_set_beacon(iface->bss[i]);
734 }
735
736 #endif /* CONFIG_NATIVE_WINDOWS */