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