]>
Commit | Line | Data |
---|---|---|
6fc6879b JM |
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. | |
a49148fd | 5 | * Copyright (c) 2008-2009, Jouni Malinen <j@w1.fi> |
6fc6879b JM |
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 | ||
6226e38d | 17 | #include "utils/includes.h" |
6fc6879b JM |
18 | |
19 | #ifndef CONFIG_NATIVE_WINDOWS | |
20 | ||
6226e38d | 21 | #include "utils/common.h" |
81f4f619 JM |
22 | #include "common/ieee802_11_defs.h" |
23 | #include "common/ieee802_11_common.h" | |
6226e38d | 24 | #include "drivers/driver.h" |
e44f8bf2 JM |
25 | #include "wps/wps_defs.h" |
26 | #include "p2p/p2p.h" | |
6fc6879b JM |
27 | #include "hostapd.h" |
28 | #include "ieee802_11.h" | |
6226e38d | 29 | #include "wpa_auth.h" |
1057d78e | 30 | #include "wmm.h" |
6226e38d | 31 | #include "ap_config.h" |
6fc6879b | 32 | #include "sta_info.h" |
dce044cc | 33 | #include "p2p_hostapd.h" |
cee7d66b | 34 | #include "ap_drv_ops.h" |
6226e38d | 35 | #include "beacon.h" |
6fc6879b JM |
36 | |
37 | ||
062390ef JM |
38 | #ifdef NEED_AP_MLME |
39 | ||
6fc6879b JM |
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 | ||
735f6522 JM |
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; | |
6fc6879b | 53 | } |
a0fad210 JM |
54 | if (hapd->iface->num_sta_no_short_preamble > 0 || |
55 | hapd->iconf->preamble == LONG_PREAMBLE) | |
6fc6879b JM |
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 | ||
df73d284 JM |
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 | ||
6fc6879b JM |
113 | static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid, |
114 | int max_len) | |
115 | { | |
116 | u8 *pos = eid; | |
df73d284 JM |
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) | |
6fc6879b JM |
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 | ||
df73d284 JM |
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; | |
6fc6879b | 166 | *pos++ = 0; /* pad for 16-bit alignment */ |
df73d284 | 167 | } |
6fc6879b JM |
168 | |
169 | eid[1] = (pos - eid) - 2; | |
170 | ||
171 | return pos; | |
172 | } | |
173 | ||
174 | ||
6c0575c3 | 175 | static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len) |
6fc6879b JM |
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 | ||
eacc6b24 AN |
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 | ||
b57e086c | 295 | void handle_probe_req(struct hostapd_data *hapd, |
baf513d6 JB |
296 | const struct ieee80211_mgmt *mgmt, size_t len, |
297 | int ssi_signal) | |
6fc6879b | 298 | { |
eacc6b24 | 299 | u8 *resp; |
6fc6879b | 300 | struct ieee802_11_elems elems; |
b57e086c | 301 | const u8 *ie; |
eacc6b24 | 302 | size_t ie_len; |
6fc6879b | 303 | struct sta_info *sta = NULL; |
eacc6b24 | 304 | size_t i, resp_len; |
9a898ee8 | 305 | int noack; |
6fc6879b JM |
306 | |
307 | ie = mgmt->u.probe_req.variable; | |
cbcf92b4 JM |
308 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req)) |
309 | return; | |
6fc6879b JM |
310 | ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req)); |
311 | ||
94709ea3 | 312 | for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) |
cd7d80f3 | 313 | if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx, |
04a85e44 | 314 | mgmt->sa, mgmt->da, mgmt->bssid, |
baf513d6 | 315 | ie, ie_len, ssi_signal) > 0) |
cd7d80f3 | 316 | return; |
ad08c363 | 317 | |
6fc6879b JM |
318 | if (!hapd->iconf->send_probe_response) |
319 | return; | |
320 | ||
3d536eb4 | 321 | if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) { |
6fc6879b JM |
322 | wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR, |
323 | MAC2STR(mgmt->sa)); | |
324 | return; | |
325 | } | |
326 | ||
6fc6879b JM |
327 | if ((!elems.ssid || !elems.supp_rates)) { |
328 | wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request " | |
329 | "without SSID or supported rates element", | |
330 | MAC2STR(mgmt->sa)); | |
331 | return; | |
332 | } | |
333 | ||
e44f8bf2 JM |
334 | #ifdef CONFIG_P2P |
335 | if (hapd->p2p && elems.wps_ie) { | |
336 | struct wpabuf *wps; | |
337 | wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA); | |
338 | if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) { | |
339 | wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request " | |
340 | "due to mismatch with Requested Device " | |
341 | "Type"); | |
342 | wpabuf_free(wps); | |
343 | return; | |
344 | } | |
345 | wpabuf_free(wps); | |
346 | } | |
8017b538 JM |
347 | |
348 | if (hapd->p2p && elems.p2p) { | |
349 | struct wpabuf *p2p; | |
350 | p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE); | |
351 | if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) { | |
352 | wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request " | |
353 | "due to mismatch with Device ID"); | |
354 | wpabuf_free(p2p); | |
355 | return; | |
356 | } | |
357 | wpabuf_free(p2p); | |
358 | } | |
e44f8bf2 JM |
359 | #endif /* CONFIG_P2P */ |
360 | ||
6fc6879b JM |
361 | if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0) { |
362 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for " | |
363 | "broadcast SSID ignored", MAC2STR(mgmt->sa)); | |
364 | return; | |
365 | } | |
366 | ||
367 | sta = ap_get_sta(hapd, mgmt->sa); | |
368 | ||
e44f8bf2 JM |
369 | #ifdef CONFIG_P2P |
370 | if ((hapd->conf->p2p & P2P_GROUP_OWNER) && | |
371 | elems.ssid_len == P2P_WILDCARD_SSID_LEN && | |
372 | os_memcmp(elems.ssid, P2P_WILDCARD_SSID, | |
373 | P2P_WILDCARD_SSID_LEN) == 0) { | |
374 | /* Process P2P Wildcard SSID like Wildcard SSID */ | |
375 | elems.ssid_len = 0; | |
376 | } | |
377 | #endif /* CONFIG_P2P */ | |
378 | ||
6fc6879b JM |
379 | if (elems.ssid_len == 0 || |
380 | (elems.ssid_len == hapd->conf->ssid.ssid_len && | |
381 | os_memcmp(elems.ssid, hapd->conf->ssid.ssid, elems.ssid_len) == | |
382 | 0)) { | |
6fc6879b JM |
383 | if (sta) |
384 | sta->ssid_probe = &hapd->conf->ssid; | |
eacc6b24 | 385 | } else { |
6fc6879b JM |
386 | if (!(mgmt->da[0] & 0x01)) { |
387 | char ssid_txt[33]; | |
388 | ieee802_11_print_ssid(ssid_txt, elems.ssid, | |
389 | elems.ssid_len); | |
390 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR | |
2d8bf732 JM |
391 | " for foreign SSID '%s' (DA " MACSTR ")", |
392 | MAC2STR(mgmt->sa), ssid_txt, | |
393 | MAC2STR(mgmt->da)); | |
6fc6879b JM |
394 | } |
395 | return; | |
396 | } | |
397 | ||
122ba579 JM |
398 | #ifdef CONFIG_INTERWORKING |
399 | if (elems.interworking && elems.interworking_len >= 1) { | |
400 | u8 ant = elems.interworking[0] & 0x0f; | |
401 | if (ant != INTERWORKING_ANT_WILDCARD && | |
402 | ant != hapd->conf->access_network_type) { | |
403 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR | |
404 | " for mismatching ANT %u ignored", | |
405 | MAC2STR(mgmt->sa), ant); | |
406 | return; | |
407 | } | |
408 | } | |
409 | ||
410 | if (elems.interworking && | |
411 | (elems.interworking_len == 7 || elems.interworking_len == 9)) { | |
412 | const u8 *hessid; | |
413 | if (elems.interworking_len == 7) | |
414 | hessid = elems.interworking + 1; | |
415 | else | |
416 | hessid = elems.interworking + 1 + 2; | |
417 | if (!is_broadcast_ether_addr(hessid) && | |
418 | os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) { | |
419 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR | |
420 | " for mismatching HESSID " MACSTR | |
421 | " ignored", | |
422 | MAC2STR(mgmt->sa), MAC2STR(hessid)); | |
423 | return; | |
424 | } | |
425 | } | |
426 | #endif /* CONFIG_INTERWORKING */ | |
427 | ||
6fc6879b JM |
428 | /* TODO: verify that supp_rates contains at least one matching rate |
429 | * with AP configuration */ | |
eacc6b24 AN |
430 | |
431 | resp = hostapd_gen_probe_resp(hapd, sta, mgmt, elems.p2p != NULL, | |
432 | &resp_len); | |
6fc6879b JM |
433 | if (resp == NULL) |
434 | return; | |
e44f8bf2 | 435 | |
9a898ee8 HS |
436 | /* |
437 | * If this is a broadcast probe request, apply no ack policy to avoid | |
438 | * excessive retries. | |
439 | */ | |
440 | noack = !!(elems.ssid_len == 0 && is_broadcast_ether_addr(mgmt->da)); | |
441 | ||
eacc6b24 | 442 | if (hostapd_drv_send_mlme(hapd, resp, resp_len, noack) < 0) |
6fc6879b JM |
443 | perror("handle_probe_req: send"); |
444 | ||
445 | os_free(resp); | |
446 | ||
2d8bf732 | 447 | wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s " |
6fc6879b JM |
448 | "SSID", MAC2STR(mgmt->sa), |
449 | elems.ssid_len == 0 ? "broadcast" : "our"); | |
450 | } | |
451 | ||
5b99e21a AN |
452 | |
453 | static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd, | |
454 | size_t *resp_len) | |
455 | { | |
456 | /* check probe response offloading caps and print warnings */ | |
457 | if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD)) | |
458 | return NULL; | |
459 | ||
460 | #ifdef CONFIG_WPS | |
461 | if (hapd->conf->wps_state && hapd->wps_probe_resp_ie && | |
462 | (!(hapd->iface->probe_resp_offloads & | |
463 | (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS | | |
464 | WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2)))) | |
465 | wpa_printf(MSG_WARNING, "Device is trying to offload WPS " | |
466 | "Probe Response while not supporting this"); | |
467 | #endif /* CONFIG_WPS */ | |
468 | ||
469 | #ifdef CONFIG_P2P | |
470 | if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie && | |
471 | !(hapd->iface->probe_resp_offloads & | |
472 | WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P)) | |
473 | wpa_printf(MSG_WARNING, "Device is trying to offload P2P " | |
474 | "Probe Response while not supporting this"); | |
475 | #endif /* CONFIG_P2P */ | |
476 | ||
477 | if (hapd->conf->interworking && | |
478 | !(hapd->iface->probe_resp_offloads & | |
479 | WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING)) | |
480 | wpa_printf(MSG_WARNING, "Device is trying to offload " | |
481 | "Interworking Probe Response while not supporting " | |
482 | "this"); | |
483 | ||
484 | /* Generate a Probe Response template for the non-P2P case */ | |
485 | return hostapd_gen_probe_resp(hapd, NULL, NULL, 0, resp_len); | |
486 | } | |
487 | ||
062390ef JM |
488 | #endif /* NEED_AP_MLME */ |
489 | ||
490 | ||
6fc6879b JM |
491 | void ieee802_11_set_beacon(struct hostapd_data *hapd) |
492 | { | |
062390ef JM |
493 | struct ieee80211_mgmt *head = NULL; |
494 | u8 *tail = NULL; | |
495 | size_t head_len = 0, tail_len = 0; | |
5b99e21a AN |
496 | u8 *resp = NULL; |
497 | size_t resp_len = 0; | |
19c3b566 | 498 | struct wpa_driver_ap_params params; |
fb91db56 | 499 | struct wpabuf *beacon, *proberesp, *assocresp; |
062390ef JM |
500 | #ifdef NEED_AP_MLME |
501 | u16 capab_info; | |
502 | u8 *pos, *tailpos; | |
503 | #endif /* NEED_AP_MLME */ | |
6fc6879b | 504 | |
bc45d427 | 505 | hapd->beacon_set_done = 1; |
e44f8bf2 | 506 | |
062390ef JM |
507 | #ifdef NEED_AP_MLME |
508 | ||
6fc6879b JM |
509 | #define BEACON_HEAD_BUF_SIZE 256 |
510 | #define BEACON_TAIL_BUF_SIZE 512 | |
511 | head = os_zalloc(BEACON_HEAD_BUF_SIZE); | |
1c08f8c0 JM |
512 | tail_len = BEACON_TAIL_BUF_SIZE; |
513 | #ifdef CONFIG_WPS | |
514 | if (hapd->conf->wps_state && hapd->wps_beacon_ie) | |
515 | tail_len += wpabuf_len(hapd->wps_beacon_ie); | |
516 | #endif /* CONFIG_WPS */ | |
e44f8bf2 JM |
517 | #ifdef CONFIG_P2P |
518 | if (hapd->p2p_beacon_ie) | |
519 | tail_len += wpabuf_len(hapd->p2p_beacon_ie); | |
520 | #endif /* CONFIG_P2P */ | |
1c08f8c0 | 521 | tailpos = tail = os_malloc(tail_len); |
6fc6879b JM |
522 | if (head == NULL || tail == NULL) { |
523 | wpa_printf(MSG_ERROR, "Failed to set beacon data"); | |
524 | os_free(head); | |
525 | os_free(tail); | |
526 | return; | |
527 | } | |
528 | ||
529 | head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
530 | WLAN_FC_STYPE_BEACON); | |
531 | head->duration = host_to_le16(0); | |
532 | os_memset(head->da, 0xff, ETH_ALEN); | |
533 | ||
534 | os_memcpy(head->sa, hapd->own_addr, ETH_ALEN); | |
535 | os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN); | |
536 | head->u.beacon.beacon_int = | |
537 | host_to_le16(hapd->iconf->beacon_int); | |
538 | ||
539 | /* hardware or low-level driver will setup seq_ctrl and timestamp */ | |
540 | capab_info = hostapd_own_capab_info(hapd, NULL, 0); | |
541 | head->u.beacon.capab_info = host_to_le16(capab_info); | |
542 | pos = &head->u.beacon.variable[0]; | |
543 | ||
544 | /* SSID */ | |
545 | *pos++ = WLAN_EID_SSID; | |
546 | if (hapd->conf->ignore_broadcast_ssid == 2) { | |
547 | /* clear the data, but keep the correct length of the SSID */ | |
548 | *pos++ = hapd->conf->ssid.ssid_len; | |
549 | os_memset(pos, 0, hapd->conf->ssid.ssid_len); | |
550 | pos += hapd->conf->ssid.ssid_len; | |
551 | } else if (hapd->conf->ignore_broadcast_ssid) { | |
552 | *pos++ = 0; /* empty SSID */ | |
553 | } else { | |
554 | *pos++ = hapd->conf->ssid.ssid_len; | |
555 | os_memcpy(pos, hapd->conf->ssid.ssid, | |
556 | hapd->conf->ssid.ssid_len); | |
557 | pos += hapd->conf->ssid.ssid_len; | |
558 | } | |
559 | ||
560 | /* Supported rates */ | |
561 | pos = hostapd_eid_supp_rates(hapd, pos); | |
562 | ||
563 | /* DS Params */ | |
564 | pos = hostapd_eid_ds_params(hapd, pos); | |
565 | ||
566 | head_len = pos - (u8 *) head; | |
567 | ||
568 | tailpos = hostapd_eid_country(hapd, tailpos, | |
569 | tail + BEACON_TAIL_BUF_SIZE - tailpos); | |
570 | ||
6fc6879b JM |
571 | /* ERP Information element */ |
572 | tailpos = hostapd_eid_erp_info(hapd, tailpos); | |
573 | ||
574 | /* Extended supported rates */ | |
575 | tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos); | |
576 | ||
1bc774a1 | 577 | /* RSN, MDIE, WPA */ |
6fc6879b | 578 | tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE - |
6c0575c3 | 579 | tailpos); |
6fc6879b | 580 | |
de9289c8 | 581 | #ifdef CONFIG_IEEE80211N |
677449b9 JM |
582 | tailpos = hostapd_eid_ht_capabilities(hapd, tailpos); |
583 | tailpos = hostapd_eid_ht_operation(hapd, tailpos); | |
de9289c8 JM |
584 | #endif /* CONFIG_IEEE80211N */ |
585 | ||
1161ff1e JM |
586 | tailpos = hostapd_eid_ext_capab(hapd, tailpos); |
587 | ||
39b97072 JM |
588 | /* |
589 | * TODO: Time Advertisement element should only be included in some | |
590 | * DTIM Beacon frames. | |
591 | */ | |
592 | tailpos = hostapd_eid_time_adv(hapd, tailpos); | |
593 | ||
b83e3e93 | 594 | tailpos = hostapd_eid_interworking(hapd, tailpos); |
c7c178e1 | 595 | tailpos = hostapd_eid_adv_proto(hapd, tailpos); |
4b2a77ab | 596 | tailpos = hostapd_eid_roaming_consortium(hapd, tailpos); |
b83e3e93 | 597 | |
1bc774a1 JM |
598 | /* Wi-Fi Alliance WMM */ |
599 | tailpos = hostapd_eid_wmm(hapd, tailpos); | |
600 | ||
ad08c363 JM |
601 | #ifdef CONFIG_WPS |
602 | if (hapd->conf->wps_state && hapd->wps_beacon_ie) { | |
14f79386 JM |
603 | os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie), |
604 | wpabuf_len(hapd->wps_beacon_ie)); | |
605 | tailpos += wpabuf_len(hapd->wps_beacon_ie); | |
ad08c363 JM |
606 | } |
607 | #endif /* CONFIG_WPS */ | |
608 | ||
e44f8bf2 JM |
609 | #ifdef CONFIG_P2P |
610 | if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) { | |
611 | os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie), | |
612 | wpabuf_len(hapd->p2p_beacon_ie)); | |
613 | tailpos += wpabuf_len(hapd->p2p_beacon_ie); | |
614 | } | |
615 | #endif /* CONFIG_P2P */ | |
962473c1 JM |
616 | #ifdef CONFIG_P2P_MANAGER |
617 | if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) == | |
618 | P2P_MANAGE) | |
619 | tailpos = hostapd_eid_p2p_manage(hapd, tailpos); | |
620 | #endif /* CONFIG_P2P_MANAGER */ | |
e44f8bf2 | 621 | |
6fc6879b JM |
622 | tail_len = tailpos > tail ? tailpos - tail : 0; |
623 | ||
5b99e21a | 624 | resp = hostapd_probe_resp_offloads(hapd, &resp_len); |
062390ef JM |
625 | #endif /* NEED_AP_MLME */ |
626 | ||
19c3b566 JM |
627 | os_memset(¶ms, 0, sizeof(params)); |
628 | params.head = (u8 *) head; | |
629 | params.head_len = head_len; | |
630 | params.tail = tail; | |
631 | params.tail_len = tail_len; | |
5b99e21a AN |
632 | params.proberesp = resp; |
633 | params.proberesp_len = resp_len; | |
19c3b566 JM |
634 | params.dtim_period = hapd->conf->dtim_period; |
635 | params.beacon_int = hapd->iconf->beacon_int; | |
e5693c47 | 636 | params.basic_rates = hapd->iconf->basic_rates; |
ccb941e6 JM |
637 | params.ssid = (u8 *) hapd->conf->ssid.ssid; |
638 | params.ssid_len = hapd->conf->ssid.ssid_len; | |
b11d1d64 JM |
639 | params.pairwise_ciphers = hapd->conf->rsn_pairwise ? |
640 | hapd->conf->rsn_pairwise : hapd->conf->wpa_pairwise; | |
641 | params.group_cipher = hapd->conf->wpa_group; | |
642 | params.key_mgmt_suites = hapd->conf->wpa_key_mgmt; | |
643 | params.auth_algs = hapd->conf->auth_algs; | |
644 | params.wpa_version = hapd->conf->wpa; | |
645 | params.privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa || | |
646 | (hapd->conf->ieee802_1x && | |
647 | (hapd->conf->default_wep_key_len || | |
648 | hapd->conf->individual_wep_key_len)); | |
97a7a0b5 JM |
649 | switch (hapd->conf->ignore_broadcast_ssid) { |
650 | case 0: | |
651 | params.hide_ssid = NO_SSID_HIDING; | |
652 | break; | |
653 | case 1: | |
654 | params.hide_ssid = HIDDEN_SSID_ZERO_LEN; | |
655 | break; | |
656 | case 2: | |
657 | params.hide_ssid = HIDDEN_SSID_ZERO_CONTENTS; | |
658 | break; | |
659 | } | |
fb91db56 JM |
660 | hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp); |
661 | params.beacon_ies = beacon; | |
662 | params.proberesp_ies = proberesp; | |
663 | params.assocresp_ies = assocresp; | |
fd13a541 | 664 | params.isolate = hapd->conf->isolate; |
31357268 JM |
665 | #ifdef NEED_AP_MLME |
666 | params.cts_protect = !!(ieee802_11_erp_info(hapd) & | |
667 | ERP_INFO_USE_PROTECTION); | |
668 | params.preamble = hapd->iface->num_sta_no_short_preamble == 0 && | |
669 | hapd->iconf->preamble == SHORT_PREAMBLE; | |
670 | if (hapd->iface->current_mode && | |
671 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G) | |
672 | params.short_slot_time = | |
673 | hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1; | |
674 | else | |
675 | params.short_slot_time = -1; | |
676 | if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n) | |
677 | params.ht_opmode = -1; | |
678 | else | |
679 | params.ht_opmode = hapd->iface->ht_op_mode; | |
680 | #endif /* NEED_AP_MLME */ | |
8a33a63f JM |
681 | params.interworking = hapd->conf->interworking; |
682 | if (hapd->conf->interworking && | |
683 | !is_zero_ether_addr(hapd->conf->hessid)) | |
684 | params.hessid = hapd->conf->hessid; | |
16991cff | 685 | params.access_network_type = hapd->conf->access_network_type; |
a0133ee1 | 686 | params.ap_max_inactivity = hapd->conf->ap_max_inactivity; |
19c3b566 JM |
687 | if (hostapd_drv_set_ap(hapd, ¶ms)) |
688 | wpa_printf(MSG_ERROR, "Failed to set beacon parameters"); | |
fb91db56 | 689 | hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp); |
6fc6879b JM |
690 | |
691 | os_free(tail); | |
692 | os_free(head); | |
5b99e21a | 693 | os_free(resp); |
6fc6879b JM |
694 | } |
695 | ||
696 | ||
697 | void ieee802_11_set_beacons(struct hostapd_iface *iface) | |
698 | { | |
699 | size_t i; | |
700 | for (i = 0; i < iface->num_bss; i++) | |
701 | ieee802_11_set_beacon(iface->bss[i]); | |
702 | } | |
703 | ||
370b0761 LC |
704 | |
705 | /* only update beacons if started */ | |
706 | void ieee802_11_update_beacons(struct hostapd_iface *iface) | |
707 | { | |
708 | size_t i; | |
709 | for (i = 0; i < iface->num_bss; i++) | |
710 | if (iface->bss[i]->beacon_set_done) | |
711 | ieee802_11_set_beacon(iface->bss[i]); | |
712 | } | |
713 | ||
6fc6879b | 714 | #endif /* CONFIG_NATIVE_WINDOWS */ |