]>
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. | |
0a66ce3c | 5 | * Copyright (c) 2008-2012, Jouni Malinen <j@w1.fi> |
6fc6879b | 6 | * |
5f9c134a JM |
7 | * This software may be distributed under the terms of the BSD license. |
8 | * See README for more details. | |
6fc6879b JM |
9 | */ |
10 | ||
6226e38d | 11 | #include "utils/includes.h" |
6fc6879b JM |
12 | |
13 | #ifndef CONFIG_NATIVE_WINDOWS | |
14 | ||
6226e38d | 15 | #include "utils/common.h" |
81f4f619 JM |
16 | #include "common/ieee802_11_defs.h" |
17 | #include "common/ieee802_11_common.h" | |
ada157f3 | 18 | #include "common/hw_features_common.h" |
e44f8bf2 JM |
19 | #include "wps/wps_defs.h" |
20 | #include "p2p/p2p.h" | |
6fc6879b JM |
21 | #include "hostapd.h" |
22 | #include "ieee802_11.h" | |
6226e38d | 23 | #include "wpa_auth.h" |
1057d78e | 24 | #include "wmm.h" |
6226e38d | 25 | #include "ap_config.h" |
6fc6879b | 26 | #include "sta_info.h" |
dce044cc | 27 | #include "p2p_hostapd.h" |
cee7d66b | 28 | #include "ap_drv_ops.h" |
6226e38d | 29 | #include "beacon.h" |
19a8ad99 | 30 | #include "hs20.h" |
3d7ad2f6 | 31 | #include "dfs.h" |
6fc6879b JM |
32 | |
33 | ||
062390ef JM |
34 | #ifdef NEED_AP_MLME |
35 | ||
0629eeb4 JM |
36 | static u8 * hostapd_eid_rm_enabled_capab(struct hostapd_data *hapd, u8 *eid, |
37 | size_t len) | |
38 | { | |
39 | if (!hapd->conf->radio_measurements || len < 2 + 4) | |
40 | return eid; | |
41 | ||
42 | *eid++ = WLAN_EID_RRM_ENABLED_CAPABILITIES; | |
43 | *eid++ = 5; | |
44 | *eid++ = (hapd->conf->radio_measurements & BIT(0)) ? | |
45 | WLAN_RRM_CAPS_NEIGHBOR_REPORT : 0x00; | |
46 | *eid++ = 0x00; | |
47 | *eid++ = 0x00; | |
48 | *eid++ = 0x00; | |
49 | *eid++ = 0x00; | |
50 | return eid; | |
51 | } | |
52 | ||
53 | ||
9bc33868 JM |
54 | static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len) |
55 | { | |
ec8f36af KP |
56 | if (len < 2 + 5) |
57 | return eid; | |
58 | ||
9bc33868 JM |
59 | #ifdef CONFIG_TESTING_OPTIONS |
60 | if (hapd->conf->bss_load_test_set) { | |
9bc33868 JM |
61 | *eid++ = WLAN_EID_BSS_LOAD; |
62 | *eid++ = 5; | |
63 | os_memcpy(eid, hapd->conf->bss_load_test, 5); | |
64 | eid += 5; | |
ec8f36af | 65 | return eid; |
9bc33868 JM |
66 | } |
67 | #endif /* CONFIG_TESTING_OPTIONS */ | |
ec8f36af KP |
68 | if (hapd->conf->bss_load_update_period) { |
69 | *eid++ = WLAN_EID_BSS_LOAD; | |
70 | *eid++ = 5; | |
71 | WPA_PUT_LE16(eid, hapd->num_sta); | |
72 | eid += 2; | |
73 | *eid++ = hapd->iface->channel_utilization; | |
74 | WPA_PUT_LE16(eid, 0); /* no available admission capabity */ | |
75 | eid += 2; | |
76 | } | |
9bc33868 JM |
77 | return eid; |
78 | } | |
79 | ||
80 | ||
6fc6879b JM |
81 | static u8 ieee802_11_erp_info(struct hostapd_data *hapd) |
82 | { | |
83 | u8 erp = 0; | |
84 | ||
85 | if (hapd->iface->current_mode == NULL || | |
86 | hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G) | |
87 | return 0; | |
88 | ||
735f6522 JM |
89 | if (hapd->iface->olbc) |
90 | erp |= ERP_INFO_USE_PROTECTION; | |
91 | if (hapd->iface->num_sta_non_erp > 0) { | |
92 | erp |= ERP_INFO_NON_ERP_PRESENT | | |
93 | ERP_INFO_USE_PROTECTION; | |
6fc6879b | 94 | } |
a0fad210 JM |
95 | if (hapd->iface->num_sta_no_short_preamble > 0 || |
96 | hapd->iconf->preamble == LONG_PREAMBLE) | |
6fc6879b JM |
97 | erp |= ERP_INFO_BARKER_PREAMBLE_MODE; |
98 | ||
99 | return erp; | |
100 | } | |
101 | ||
102 | ||
103 | static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid) | |
104 | { | |
105 | *eid++ = WLAN_EID_DS_PARAMS; | |
106 | *eid++ = 1; | |
107 | *eid++ = hapd->iconf->channel; | |
108 | return eid; | |
109 | } | |
110 | ||
111 | ||
112 | static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid) | |
113 | { | |
114 | if (hapd->iface->current_mode == NULL || | |
115 | hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G) | |
116 | return eid; | |
117 | ||
118 | /* Set NonERP_present and use_protection bits if there | |
119 | * are any associated NonERP stations. */ | |
120 | /* TODO: use_protection bit can be set to zero even if | |
121 | * there are NonERP stations present. This optimization | |
122 | * might be useful if NonERP stations are "quiet". | |
123 | * See 802.11g/D6 E-1 for recommended practice. | |
124 | * In addition, Non ERP present might be set, if AP detects Non ERP | |
125 | * operation on other APs. */ | |
126 | ||
127 | /* Add ERP Information element */ | |
128 | *eid++ = WLAN_EID_ERP_INFO; | |
129 | *eid++ = 1; | |
130 | *eid++ = ieee802_11_erp_info(hapd); | |
131 | ||
132 | return eid; | |
133 | } | |
134 | ||
135 | ||
e0392f82 S |
136 | static u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid) |
137 | { | |
138 | u8 *pos = eid; | |
3d7ad2f6 C |
139 | u8 local_pwr_constraint = 0; |
140 | int dfs; | |
e0392f82 | 141 | |
3d7ad2f6 | 142 | if (hapd->iface->current_mode == NULL || |
e0392f82 S |
143 | hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A) |
144 | return eid; | |
145 | ||
c53a9bf8 SD |
146 | /* Let host drivers add this IE if DFS support is offloaded */ |
147 | if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) | |
148 | return eid; | |
149 | ||
3d7ad2f6 C |
150 | /* |
151 | * There is no DFS support and power constraint was not directly | |
152 | * requested by config option. | |
153 | */ | |
154 | if (!hapd->iconf->ieee80211h && | |
155 | hapd->iconf->local_pwr_constraint == -1) | |
156 | return eid; | |
157 | ||
158 | /* Check if DFS is required by regulatory. */ | |
159 | dfs = hostapd_is_dfs_required(hapd->iface); | |
160 | if (dfs < 0) { | |
161 | wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d", | |
162 | dfs); | |
163 | dfs = 0; | |
164 | } | |
165 | ||
166 | if (dfs == 0 && hapd->iconf->local_pwr_constraint == -1) | |
167 | return eid; | |
168 | ||
169 | /* | |
170 | * ieee80211h (DFS) is enabled so Power Constraint element shall | |
171 | * be added when running on DFS channel whenever local_pwr_constraint | |
172 | * is configured or not. In order to meet regulations when TPC is not | |
173 | * implemented using a transmit power that is below the legal maximum | |
174 | * (including any mitigation factor) should help. In this case, | |
175 | * indicate 3 dB below maximum allowed transmit power. | |
176 | */ | |
177 | if (hapd->iconf->local_pwr_constraint == -1) | |
178 | local_pwr_constraint = 3; | |
179 | ||
e0392f82 S |
180 | /* |
181 | * A STA that is not an AP shall use a transmit power less than or | |
182 | * equal to the local maximum transmit power level for the channel. | |
183 | * The local maximum transmit power can be calculated from the formula: | |
184 | * local max TX pwr = max TX pwr - local pwr constraint | |
185 | * Where max TX pwr is maximum transmit power level specified for | |
186 | * channel in Country element and local pwr constraint is specified | |
187 | * for channel in this Power Constraint element. | |
188 | */ | |
189 | ||
190 | /* Element ID */ | |
191 | *pos++ = WLAN_EID_PWR_CONSTRAINT; | |
192 | /* Length */ | |
193 | *pos++ = 1; | |
194 | /* Local Power Constraint */ | |
3d7ad2f6 C |
195 | if (local_pwr_constraint) |
196 | *pos++ = local_pwr_constraint; | |
197 | else | |
198 | *pos++ = hapd->iconf->local_pwr_constraint; | |
e0392f82 S |
199 | |
200 | return pos; | |
201 | } | |
202 | ||
203 | ||
df73d284 JM |
204 | static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing, |
205 | struct hostapd_channel_data *start, | |
206 | struct hostapd_channel_data *prev) | |
207 | { | |
208 | if (end - pos < 3) | |
209 | return pos; | |
210 | ||
211 | /* first channel number */ | |
212 | *pos++ = start->chan; | |
213 | /* number of channels */ | |
214 | *pos++ = (prev->chan - start->chan) / chan_spacing + 1; | |
215 | /* maximum transmit power level */ | |
216 | *pos++ = start->max_tx_power; | |
217 | ||
218 | return pos; | |
219 | } | |
220 | ||
221 | ||
6fc6879b JM |
222 | static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid, |
223 | int max_len) | |
224 | { | |
225 | u8 *pos = eid; | |
df73d284 JM |
226 | u8 *end = eid + max_len; |
227 | int i; | |
228 | struct hostapd_hw_modes *mode; | |
229 | struct hostapd_channel_data *start, *prev; | |
230 | int chan_spacing = 1; | |
231 | ||
232 | if (!hapd->iconf->ieee80211d || max_len < 6 || | |
233 | hapd->iface->current_mode == NULL) | |
6fc6879b JM |
234 | return eid; |
235 | ||
236 | *pos++ = WLAN_EID_COUNTRY; | |
237 | pos++; /* length will be set later */ | |
238 | os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */ | |
239 | pos += 3; | |
240 | ||
df73d284 JM |
241 | mode = hapd->iface->current_mode; |
242 | if (mode->mode == HOSTAPD_MODE_IEEE80211A) | |
243 | chan_spacing = 4; | |
244 | ||
245 | start = prev = NULL; | |
246 | for (i = 0; i < mode->num_channels; i++) { | |
247 | struct hostapd_channel_data *chan = &mode->channels[i]; | |
248 | if (chan->flag & HOSTAPD_CHAN_DISABLED) | |
249 | continue; | |
250 | if (start && prev && | |
251 | prev->chan + chan_spacing == chan->chan && | |
252 | start->max_tx_power == chan->max_tx_power) { | |
253 | prev = chan; | |
254 | continue; /* can use same entry */ | |
255 | } | |
256 | ||
bc32bb70 | 257 | if (start && prev) { |
df73d284 JM |
258 | pos = hostapd_eid_country_add(pos, end, chan_spacing, |
259 | start, prev); | |
260 | start = NULL; | |
261 | } | |
262 | ||
263 | /* Start new group */ | |
264 | start = prev = chan; | |
265 | } | |
266 | ||
267 | if (start) { | |
268 | pos = hostapd_eid_country_add(pos, end, chan_spacing, | |
269 | start, prev); | |
270 | } | |
271 | ||
272 | if ((pos - eid) & 1) { | |
273 | if (end - pos < 1) | |
274 | return eid; | |
6fc6879b | 275 | *pos++ = 0; /* pad for 16-bit alignment */ |
df73d284 | 276 | } |
6fc6879b JM |
277 | |
278 | eid[1] = (pos - eid) - 2; | |
279 | ||
280 | return pos; | |
281 | } | |
282 | ||
283 | ||
6c0575c3 | 284 | static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len) |
6fc6879b JM |
285 | { |
286 | const u8 *ie; | |
287 | size_t ielen; | |
288 | ||
289 | ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen); | |
290 | if (ie == NULL || ielen > len) | |
291 | return eid; | |
292 | ||
293 | os_memcpy(eid, ie, ielen); | |
294 | return eid + ielen; | |
295 | } | |
296 | ||
297 | ||
bf281c12 AO |
298 | static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid) |
299 | { | |
2b6e1216 JB |
300 | #ifdef CONFIG_TESTING_OPTIONS |
301 | if (hapd->iface->cs_oper_class && hapd->iconf->ecsa_ie_only) | |
302 | return eid; | |
303 | #endif /* CONFIG_TESTING_OPTIONS */ | |
304 | ||
9438e9c7 | 305 | if (!hapd->cs_freq_params.channel) |
bf281c12 AO |
306 | return eid; |
307 | ||
308 | *eid++ = WLAN_EID_CHANNEL_SWITCH; | |
309 | *eid++ = 3; | |
6782b684 | 310 | *eid++ = hapd->cs_block_tx; |
9438e9c7 | 311 | *eid++ = hapd->cs_freq_params.channel; |
6782b684 | 312 | *eid++ = hapd->cs_count; |
bf281c12 AO |
313 | |
314 | return eid; | |
315 | } | |
316 | ||
317 | ||
6315bfdb AO |
318 | static u8 * hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid) |
319 | { | |
320 | if (!hapd->cs_freq_params.channel || !hapd->iface->cs_oper_class) | |
321 | return eid; | |
322 | ||
323 | *eid++ = WLAN_EID_EXT_CHANSWITCH_ANN; | |
324 | *eid++ = 4; | |
325 | *eid++ = hapd->cs_block_tx; | |
326 | *eid++ = hapd->iface->cs_oper_class; | |
327 | *eid++ = hapd->cs_freq_params.channel; | |
328 | *eid++ = hapd->cs_count; | |
329 | ||
330 | return eid; | |
331 | } | |
332 | ||
333 | ||
c0d94d61 AO |
334 | static u8 * hostapd_eid_supported_op_classes(struct hostapd_data *hapd, u8 *eid) |
335 | { | |
336 | u8 op_class, channel; | |
337 | ||
338 | if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) || | |
339 | !hapd->iface->freq) | |
340 | return eid; | |
341 | ||
342 | if (ieee80211_freq_to_channel_ext(hapd->iface->freq, | |
343 | hapd->iconf->secondary_channel, | |
344 | hapd->iconf->vht_oper_chwidth, | |
345 | &op_class, &channel) == | |
346 | NUM_HOSTAPD_MODES) | |
347 | return eid; | |
348 | ||
349 | *eid++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES; | |
350 | *eid++ = 2; | |
351 | ||
352 | /* Current Operating Class */ | |
353 | *eid++ = op_class; | |
354 | ||
355 | /* TODO: Advertise all the supported operating classes */ | |
356 | *eid++ = 0; | |
357 | ||
358 | return eid; | |
359 | } | |
360 | ||
361 | ||
eacc6b24 | 362 | static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd, |
eacc6b24 AN |
363 | const struct ieee80211_mgmt *req, |
364 | int is_p2p, size_t *resp_len) | |
365 | { | |
366 | struct ieee80211_mgmt *resp; | |
38d9048f | 367 | u8 *pos, *epos, *csa_pos; |
eacc6b24 AN |
368 | size_t buflen; |
369 | ||
370 | #define MAX_PROBERESP_LEN 768 | |
371 | buflen = MAX_PROBERESP_LEN; | |
372 | #ifdef CONFIG_WPS | |
373 | if (hapd->wps_probe_resp_ie) | |
374 | buflen += wpabuf_len(hapd->wps_probe_resp_ie); | |
375 | #endif /* CONFIG_WPS */ | |
376 | #ifdef CONFIG_P2P | |
377 | if (hapd->p2p_probe_resp_ie) | |
378 | buflen += wpabuf_len(hapd->p2p_probe_resp_ie); | |
379 | #endif /* CONFIG_P2P */ | |
347827ff AN |
380 | #ifdef CONFIG_FST |
381 | if (hapd->iface->fst_ies) | |
382 | buflen += wpabuf_len(hapd->iface->fst_ies); | |
383 | #endif /* CONFIG_FST */ | |
b52f084c JM |
384 | if (hapd->conf->vendor_elements) |
385 | buflen += wpabuf_len(hapd->conf->vendor_elements); | |
e7d0e97b YL |
386 | if (hapd->conf->vendor_vht) { |
387 | buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) + | |
388 | 2 + sizeof(struct ieee80211_vht_operation); | |
389 | } | |
eacc6b24 AN |
390 | resp = os_zalloc(buflen); |
391 | if (resp == NULL) | |
392 | return NULL; | |
393 | ||
394 | epos = ((u8 *) resp) + MAX_PROBERESP_LEN; | |
395 | ||
396 | resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
397 | WLAN_FC_STYPE_PROBE_RESP); | |
398 | if (req) | |
399 | os_memcpy(resp->da, req->sa, ETH_ALEN); | |
400 | os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN); | |
401 | ||
402 | os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN); | |
403 | resp->u.probe_resp.beacon_int = | |
404 | host_to_le16(hapd->iconf->beacon_int); | |
405 | ||
406 | /* hardware or low-level driver will setup seq_ctrl and timestamp */ | |
407 | resp->u.probe_resp.capab_info = | |
f41ded6f | 408 | host_to_le16(hostapd_own_capab_info(hapd)); |
eacc6b24 AN |
409 | |
410 | pos = resp->u.probe_resp.variable; | |
411 | *pos++ = WLAN_EID_SSID; | |
412 | *pos++ = hapd->conf->ssid.ssid_len; | |
413 | os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len); | |
414 | pos += hapd->conf->ssid.ssid_len; | |
415 | ||
416 | /* Supported rates */ | |
417 | pos = hostapd_eid_supp_rates(hapd, pos); | |
418 | ||
419 | /* DS Params */ | |
420 | pos = hostapd_eid_ds_params(hapd, pos); | |
421 | ||
422 | pos = hostapd_eid_country(hapd, pos, epos - pos); | |
423 | ||
e0392f82 S |
424 | /* Power Constraint element */ |
425 | pos = hostapd_eid_pwr_constraint(hapd, pos); | |
426 | ||
38d9048f AO |
427 | /* CSA IE */ |
428 | csa_pos = hostapd_eid_csa(hapd, pos); | |
429 | if (csa_pos != pos) | |
430 | hapd->cs_c_off_proberesp = csa_pos - (u8 *) resp - 1; | |
431 | pos = csa_pos; | |
432 | ||
eacc6b24 AN |
433 | /* ERP Information element */ |
434 | pos = hostapd_eid_erp_info(hapd, pos); | |
435 | ||
436 | /* Extended supported rates */ | |
437 | pos = hostapd_eid_ext_supp_rates(hapd, pos); | |
438 | ||
439 | /* RSN, MDIE, WPA */ | |
440 | pos = hostapd_eid_wpa(hapd, pos, epos - pos); | |
441 | ||
9bc33868 JM |
442 | pos = hostapd_eid_bss_load(hapd, pos, epos - pos); |
443 | ||
0629eeb4 JM |
444 | pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos); |
445 | ||
38d9048f AO |
446 | /* eCSA IE */ |
447 | csa_pos = hostapd_eid_ecsa(hapd, pos); | |
448 | if (csa_pos != pos) | |
449 | hapd->cs_c_off_ecsa_proberesp = csa_pos - (u8 *) resp - 1; | |
450 | pos = csa_pos; | |
451 | ||
c0d94d61 AO |
452 | pos = hostapd_eid_supported_op_classes(hapd, pos); |
453 | ||
eacc6b24 | 454 | #ifdef CONFIG_IEEE80211N |
38d9048f AO |
455 | /* Secondary Channel Offset element */ |
456 | /* TODO: The standard doesn't specify a position for this element. */ | |
457 | pos = hostapd_eid_secondary_channel(hapd, pos); | |
458 | ||
eacc6b24 AN |
459 | pos = hostapd_eid_ht_capabilities(hapd, pos); |
460 | pos = hostapd_eid_ht_operation(hapd, pos); | |
461 | #endif /* CONFIG_IEEE80211N */ | |
462 | ||
463 | pos = hostapd_eid_ext_capab(hapd, pos); | |
464 | ||
465 | pos = hostapd_eid_time_adv(hapd, pos); | |
466 | pos = hostapd_eid_time_zone(hapd, pos); | |
467 | ||
468 | pos = hostapd_eid_interworking(hapd, pos); | |
469 | pos = hostapd_eid_adv_proto(hapd, pos); | |
470 | pos = hostapd_eid_roaming_consortium(hapd, pos); | |
471 | ||
347827ff AN |
472 | #ifdef CONFIG_FST |
473 | if (hapd->iface->fst_ies) { | |
474 | os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies), | |
475 | wpabuf_len(hapd->iface->fst_ies)); | |
476 | pos += wpabuf_len(hapd->iface->fst_ies); | |
477 | } | |
478 | #endif /* CONFIG_FST */ | |
479 | ||
532b16c7 | 480 | #ifdef CONFIG_IEEE80211AC |
e7d0e97b YL |
481 | if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) { |
482 | pos = hostapd_eid_vht_capabilities(hapd, pos); | |
483 | pos = hostapd_eid_vht_operation(hapd, pos); | |
38d9048f | 484 | pos = hostapd_eid_wb_chsw_wrapper(hapd, pos); |
e7d0e97b YL |
485 | } |
486 | if (hapd->conf->vendor_vht) | |
487 | pos = hostapd_eid_vendor_vht(hapd, pos); | |
532b16c7 MP |
488 | #endif /* CONFIG_IEEE80211AC */ |
489 | ||
eacc6b24 AN |
490 | /* Wi-Fi Alliance WMM */ |
491 | pos = hostapd_eid_wmm(hapd, pos); | |
492 | ||
493 | #ifdef CONFIG_WPS | |
494 | if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) { | |
495 | os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie), | |
496 | wpabuf_len(hapd->wps_probe_resp_ie)); | |
497 | pos += wpabuf_len(hapd->wps_probe_resp_ie); | |
498 | } | |
499 | #endif /* CONFIG_WPS */ | |
500 | ||
501 | #ifdef CONFIG_P2P | |
502 | if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p && | |
503 | hapd->p2p_probe_resp_ie) { | |
504 | os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie), | |
505 | wpabuf_len(hapd->p2p_probe_resp_ie)); | |
506 | pos += wpabuf_len(hapd->p2p_probe_resp_ie); | |
507 | } | |
508 | #endif /* CONFIG_P2P */ | |
509 | #ifdef CONFIG_P2P_MANAGER | |
510 | if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) == | |
511 | P2P_MANAGE) | |
512 | pos = hostapd_eid_p2p_manage(hapd, pos); | |
513 | #endif /* CONFIG_P2P_MANAGER */ | |
514 | ||
19a8ad99 JK |
515 | #ifdef CONFIG_HS20 |
516 | pos = hostapd_eid_hs20_indication(hapd, pos); | |
a14896e8 | 517 | pos = hostapd_eid_osen(hapd, pos); |
19a8ad99 JK |
518 | #endif /* CONFIG_HS20 */ |
519 | ||
b52f084c JM |
520 | if (hapd->conf->vendor_elements) { |
521 | os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements), | |
522 | wpabuf_len(hapd->conf->vendor_elements)); | |
523 | pos += wpabuf_len(hapd->conf->vendor_elements); | |
524 | } | |
525 | ||
eacc6b24 AN |
526 | *resp_len = pos - (u8 *) resp; |
527 | return (u8 *) resp; | |
528 | } | |
529 | ||
530 | ||
0a66ce3c JM |
531 | enum ssid_match_result { |
532 | NO_SSID_MATCH, | |
533 | EXACT_SSID_MATCH, | |
534 | WILDCARD_SSID_MATCH | |
535 | }; | |
536 | ||
537 | static enum ssid_match_result ssid_match(struct hostapd_data *hapd, | |
538 | const u8 *ssid, size_t ssid_len, | |
539 | const u8 *ssid_list, | |
540 | size_t ssid_list_len) | |
541 | { | |
542 | const u8 *pos, *end; | |
543 | int wildcard = 0; | |
544 | ||
545 | if (ssid_len == 0) | |
546 | wildcard = 1; | |
547 | if (ssid_len == hapd->conf->ssid.ssid_len && | |
548 | os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0) | |
549 | return EXACT_SSID_MATCH; | |
550 | ||
551 | if (ssid_list == NULL) | |
552 | return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH; | |
553 | ||
554 | pos = ssid_list; | |
555 | end = ssid_list + ssid_list_len; | |
556 | while (pos + 1 <= end) { | |
557 | if (pos + 2 + pos[1] > end) | |
558 | break; | |
559 | if (pos[1] == 0) | |
560 | wildcard = 1; | |
561 | if (pos[1] == hapd->conf->ssid.ssid_len && | |
562 | os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0) | |
563 | return EXACT_SSID_MATCH; | |
564 | pos += 2 + pos[1]; | |
565 | } | |
566 | ||
567 | return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH; | |
568 | } | |
569 | ||
570 | ||
a65a9b8d JM |
571 | void sta_track_expire(struct hostapd_iface *iface, int force) |
572 | { | |
573 | struct os_reltime now; | |
574 | struct hostapd_sta_info *info; | |
575 | ||
576 | if (!iface->num_sta_seen) | |
577 | return; | |
578 | ||
579 | os_get_reltime(&now); | |
580 | while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info, | |
581 | list))) { | |
582 | if (!force && | |
583 | !os_reltime_expired(&now, &info->last_seen, | |
584 | iface->conf->track_sta_max_age)) | |
585 | break; | |
586 | force = 0; | |
587 | ||
588 | wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for " | |
589 | MACSTR, iface->bss[0]->conf->iface, | |
590 | MAC2STR(info->addr)); | |
591 | dl_list_del(&info->list); | |
592 | iface->num_sta_seen--; | |
593 | os_free(info); | |
594 | } | |
595 | } | |
596 | ||
597 | ||
598 | static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface, | |
599 | const u8 *addr) | |
600 | { | |
601 | struct hostapd_sta_info *info; | |
602 | ||
603 | dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list) | |
604 | if (os_memcmp(addr, info->addr, ETH_ALEN) == 0) | |
605 | return info; | |
606 | ||
607 | return NULL; | |
608 | } | |
609 | ||
610 | ||
b308a304 | 611 | void sta_track_add(struct hostapd_iface *iface, const u8 *addr) |
a65a9b8d JM |
612 | { |
613 | struct hostapd_sta_info *info; | |
614 | ||
615 | info = sta_track_get(iface, addr); | |
616 | if (info) { | |
617 | /* Move the most recent entry to the end of the list */ | |
618 | dl_list_del(&info->list); | |
619 | dl_list_add_tail(&iface->sta_seen, &info->list); | |
620 | os_get_reltime(&info->last_seen); | |
621 | return; | |
622 | } | |
623 | ||
624 | /* Add a new entry */ | |
625 | info = os_zalloc(sizeof(*info)); | |
626 | os_memcpy(info->addr, addr, ETH_ALEN); | |
627 | os_get_reltime(&info->last_seen); | |
628 | ||
629 | if (iface->num_sta_seen >= iface->conf->track_sta_max_num) { | |
630 | /* Expire oldest entry to make room for a new one */ | |
631 | sta_track_expire(iface, 1); | |
632 | } | |
633 | ||
634 | wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for " | |
635 | MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr)); | |
636 | dl_list_add_tail(&iface->sta_seen, &info->list); | |
637 | iface->num_sta_seen++; | |
638 | } | |
639 | ||
640 | ||
0e2412d0 JM |
641 | struct hostapd_data * |
642 | sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr, | |
643 | const char *ifname) | |
964f64e2 JM |
644 | { |
645 | struct hapd_interfaces *interfaces = iface->interfaces; | |
646 | size_t i, j; | |
647 | ||
648 | for (i = 0; i < interfaces->count; i++) { | |
0e2412d0 JM |
649 | struct hostapd_data *hapd = NULL; |
650 | ||
964f64e2 JM |
651 | iface = interfaces->iface[i]; |
652 | for (j = 0; j < iface->num_bss; j++) { | |
0e2412d0 | 653 | hapd = iface->bss[j]; |
964f64e2 JM |
654 | if (os_strcmp(ifname, hapd->conf->iface) == 0) |
655 | break; | |
0e2412d0 | 656 | hapd = NULL; |
964f64e2 JM |
657 | } |
658 | ||
0e2412d0 JM |
659 | if (hapd && sta_track_get(iface, addr)) |
660 | return hapd; | |
964f64e2 JM |
661 | } |
662 | ||
0e2412d0 | 663 | return NULL; |
964f64e2 JM |
664 | } |
665 | ||
666 | ||
b57e086c | 667 | void handle_probe_req(struct hostapd_data *hapd, |
baf513d6 JB |
668 | const struct ieee80211_mgmt *mgmt, size_t len, |
669 | int ssi_signal) | |
6fc6879b | 670 | { |
eacc6b24 | 671 | u8 *resp; |
6fc6879b | 672 | struct ieee802_11_elems elems; |
b57e086c | 673 | const u8 *ie; |
eacc6b24 | 674 | size_t ie_len; |
eacc6b24 | 675 | size_t i, resp_len; |
9a898ee8 | 676 | int noack; |
0a66ce3c | 677 | enum ssid_match_result res; |
95e551c5 AO |
678 | int ret; |
679 | u16 csa_offs[2]; | |
680 | size_t csa_offs_len; | |
6fc6879b JM |
681 | |
682 | ie = mgmt->u.probe_req.variable; | |
cbcf92b4 JM |
683 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req)) |
684 | return; | |
a65a9b8d JM |
685 | if (hapd->iconf->track_sta_max_num) |
686 | sta_track_add(hapd->iface, mgmt->sa); | |
6fc6879b JM |
687 | ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req)); |
688 | ||
94709ea3 | 689 | for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) |
cd7d80f3 | 690 | if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx, |
04a85e44 | 691 | mgmt->sa, mgmt->da, mgmt->bssid, |
baf513d6 | 692 | ie, ie_len, ssi_signal) > 0) |
cd7d80f3 | 693 | return; |
ad08c363 | 694 | |
6fc6879b JM |
695 | if (!hapd->iconf->send_probe_response) |
696 | return; | |
697 | ||
3d536eb4 | 698 | if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) { |
6fc6879b JM |
699 | wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR, |
700 | MAC2STR(mgmt->sa)); | |
701 | return; | |
702 | } | |
703 | ||
6fc6879b JM |
704 | if ((!elems.ssid || !elems.supp_rates)) { |
705 | wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request " | |
706 | "without SSID or supported rates element", | |
707 | MAC2STR(mgmt->sa)); | |
708 | return; | |
709 | } | |
710 | ||
c612ae97 IP |
711 | /* |
712 | * No need to reply if the Probe Request frame was sent on an adjacent | |
713 | * channel. IEEE Std 802.11-2012 describes this as a requirement for an | |
714 | * AP with dot11RadioMeasurementActivated set to true, but strictly | |
715 | * speaking does not allow such ignoring of Probe Request frames if | |
716 | * dot11RadioMeasurementActivated is false. Anyway, this can help reduce | |
717 | * number of unnecessary Probe Response frames for cases where the STA | |
718 | * is less likely to see them (Probe Request frame sent on a | |
719 | * neighboring, but partially overlapping, channel). | |
720 | */ | |
f87c99c7 | 721 | if (elems.ds_params && |
c612ae97 IP |
722 | hapd->iface->current_mode && |
723 | (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G || | |
724 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) && | |
725 | hapd->iconf->channel != elems.ds_params[0]) { | |
726 | wpa_printf(MSG_DEBUG, | |
727 | "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u", | |
728 | hapd->iconf->channel, elems.ds_params[0]); | |
729 | return; | |
730 | } | |
731 | ||
e44f8bf2 JM |
732 | #ifdef CONFIG_P2P |
733 | if (hapd->p2p && elems.wps_ie) { | |
734 | struct wpabuf *wps; | |
735 | wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA); | |
736 | if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) { | |
737 | wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request " | |
738 | "due to mismatch with Requested Device " | |
739 | "Type"); | |
740 | wpabuf_free(wps); | |
741 | return; | |
742 | } | |
743 | wpabuf_free(wps); | |
744 | } | |
8017b538 JM |
745 | |
746 | if (hapd->p2p && elems.p2p) { | |
747 | struct wpabuf *p2p; | |
748 | p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE); | |
749 | if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) { | |
750 | wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request " | |
751 | "due to mismatch with Device ID"); | |
752 | wpabuf_free(p2p); | |
753 | return; | |
754 | } | |
755 | wpabuf_free(p2p); | |
756 | } | |
e44f8bf2 JM |
757 | #endif /* CONFIG_P2P */ |
758 | ||
0a66ce3c JM |
759 | if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 && |
760 | elems.ssid_list_len == 0) { | |
6fc6879b JM |
761 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for " |
762 | "broadcast SSID ignored", MAC2STR(mgmt->sa)); | |
763 | return; | |
764 | } | |
765 | ||
e44f8bf2 JM |
766 | #ifdef CONFIG_P2P |
767 | if ((hapd->conf->p2p & P2P_GROUP_OWNER) && | |
768 | elems.ssid_len == P2P_WILDCARD_SSID_LEN && | |
769 | os_memcmp(elems.ssid, P2P_WILDCARD_SSID, | |
770 | P2P_WILDCARD_SSID_LEN) == 0) { | |
771 | /* Process P2P Wildcard SSID like Wildcard SSID */ | |
772 | elems.ssid_len = 0; | |
773 | } | |
774 | #endif /* CONFIG_P2P */ | |
775 | ||
0a66ce3c JM |
776 | res = ssid_match(hapd, elems.ssid, elems.ssid_len, |
777 | elems.ssid_list, elems.ssid_list_len); | |
f41ded6f | 778 | if (res == NO_SSID_MATCH) { |
6fc6879b | 779 | if (!(mgmt->da[0] & 0x01)) { |
6fc6879b | 780 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR |
0a66ce3c | 781 | " for foreign SSID '%s' (DA " MACSTR ")%s", |
b37d582e JM |
782 | MAC2STR(mgmt->sa), |
783 | wpa_ssid_txt(elems.ssid, elems.ssid_len), | |
0a66ce3c JM |
784 | MAC2STR(mgmt->da), |
785 | elems.ssid_list ? " (SSID list)" : ""); | |
6fc6879b JM |
786 | } |
787 | return; | |
788 | } | |
789 | ||
122ba579 | 790 | #ifdef CONFIG_INTERWORKING |
2aa82e52 MB |
791 | if (hapd->conf->interworking && |
792 | elems.interworking && elems.interworking_len >= 1) { | |
122ba579 JM |
793 | u8 ant = elems.interworking[0] & 0x0f; |
794 | if (ant != INTERWORKING_ANT_WILDCARD && | |
795 | ant != hapd->conf->access_network_type) { | |
796 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR | |
797 | " for mismatching ANT %u ignored", | |
798 | MAC2STR(mgmt->sa), ant); | |
799 | return; | |
800 | } | |
801 | } | |
802 | ||
2aa82e52 | 803 | if (hapd->conf->interworking && elems.interworking && |
122ba579 JM |
804 | (elems.interworking_len == 7 || elems.interworking_len == 9)) { |
805 | const u8 *hessid; | |
806 | if (elems.interworking_len == 7) | |
807 | hessid = elems.interworking + 1; | |
808 | else | |
809 | hessid = elems.interworking + 1 + 2; | |
810 | if (!is_broadcast_ether_addr(hessid) && | |
811 | os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) { | |
812 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR | |
813 | " for mismatching HESSID " MACSTR | |
814 | " ignored", | |
815 | MAC2STR(mgmt->sa), MAC2STR(hessid)); | |
816 | return; | |
817 | } | |
818 | } | |
819 | #endif /* CONFIG_INTERWORKING */ | |
820 | ||
85b4eac3 JM |
821 | #ifdef CONFIG_P2P |
822 | if ((hapd->conf->p2p & P2P_GROUP_OWNER) && | |
823 | supp_rates_11b_only(&elems)) { | |
824 | /* Indicates support for 11b rates only */ | |
825 | wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from " | |
826 | MACSTR " with only 802.11b rates", | |
827 | MAC2STR(mgmt->sa)); | |
828 | return; | |
829 | } | |
830 | #endif /* CONFIG_P2P */ | |
831 | ||
6fc6879b JM |
832 | /* TODO: verify that supp_rates contains at least one matching rate |
833 | * with AP configuration */ | |
eacc6b24 | 834 | |
964f64e2 JM |
835 | if (hapd->conf->no_probe_resp_if_seen_on && |
836 | is_multicast_ether_addr(mgmt->da) && | |
837 | is_multicast_ether_addr(mgmt->bssid) && | |
838 | sta_track_seen_on(hapd->iface, mgmt->sa, | |
839 | hapd->conf->no_probe_resp_if_seen_on)) { | |
840 | wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR | |
841 | " since STA has been seen on %s", | |
842 | hapd->conf->iface, MAC2STR(mgmt->sa), | |
843 | hapd->conf->no_probe_resp_if_seen_on); | |
844 | return; | |
845 | } | |
846 | ||
9b7a1bd7 JM |
847 | if (hapd->conf->no_probe_resp_if_max_sta && |
848 | is_multicast_ether_addr(mgmt->da) && | |
849 | is_multicast_ether_addr(mgmt->bssid) && | |
850 | hapd->num_sta >= hapd->conf->max_num_sta && | |
851 | !ap_get_sta(hapd, mgmt->sa)) { | |
852 | wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR | |
853 | " since no room for additional STA", | |
854 | hapd->conf->iface, MAC2STR(mgmt->sa)); | |
855 | return; | |
856 | } | |
857 | ||
c2aff6b1 | 858 | #ifdef CONFIG_TESTING_OPTIONS |
06df2aa6 | 859 | if (hapd->iconf->ignore_probe_probability > 0.0 && |
c2aff6b1 JB |
860 | drand48() < hapd->iconf->ignore_probe_probability) { |
861 | wpa_printf(MSG_INFO, | |
862 | "TESTING: ignoring probe request from " MACSTR, | |
863 | MAC2STR(mgmt->sa)); | |
864 | return; | |
865 | } | |
866 | #endif /* CONFIG_TESTING_OPTIONS */ | |
867 | ||
f41ded6f | 868 | resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL, |
eacc6b24 | 869 | &resp_len); |
6fc6879b JM |
870 | if (resp == NULL) |
871 | return; | |
e44f8bf2 | 872 | |
9a898ee8 HS |
873 | /* |
874 | * If this is a broadcast probe request, apply no ack policy to avoid | |
875 | * excessive retries. | |
876 | */ | |
0a66ce3c JM |
877 | noack = !!(res == WILDCARD_SSID_MATCH && |
878 | is_broadcast_ether_addr(mgmt->da)); | |
9a898ee8 | 879 | |
95e551c5 AO |
880 | csa_offs_len = 0; |
881 | if (hapd->csa_in_progress) { | |
882 | if (hapd->cs_c_off_proberesp) | |
883 | csa_offs[csa_offs_len++] = | |
884 | hapd->cs_c_off_proberesp; | |
885 | ||
886 | if (hapd->cs_c_off_ecsa_proberesp) | |
887 | csa_offs[csa_offs_len++] = | |
888 | hapd->cs_c_off_ecsa_proberesp; | |
889 | } | |
890 | ||
891 | ret = hostapd_drv_send_mlme_csa(hapd, resp, resp_len, noack, | |
892 | csa_offs_len ? csa_offs : NULL, | |
893 | csa_offs_len); | |
894 | ||
895 | if (ret < 0) | |
61323e70 | 896 | wpa_printf(MSG_INFO, "handle_probe_req: send failed"); |
6fc6879b JM |
897 | |
898 | os_free(resp); | |
899 | ||
2d8bf732 | 900 | wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s " |
6fc6879b JM |
901 | "SSID", MAC2STR(mgmt->sa), |
902 | elems.ssid_len == 0 ? "broadcast" : "our"); | |
903 | } | |
904 | ||
5b99e21a AN |
905 | |
906 | static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd, | |
907 | size_t *resp_len) | |
908 | { | |
909 | /* check probe response offloading caps and print warnings */ | |
910 | if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD)) | |
911 | return NULL; | |
912 | ||
913 | #ifdef CONFIG_WPS | |
914 | if (hapd->conf->wps_state && hapd->wps_probe_resp_ie && | |
915 | (!(hapd->iface->probe_resp_offloads & | |
916 | (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS | | |
917 | WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2)))) | |
918 | wpa_printf(MSG_WARNING, "Device is trying to offload WPS " | |
919 | "Probe Response while not supporting this"); | |
920 | #endif /* CONFIG_WPS */ | |
921 | ||
922 | #ifdef CONFIG_P2P | |
923 | if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie && | |
924 | !(hapd->iface->probe_resp_offloads & | |
925 | WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P)) | |
926 | wpa_printf(MSG_WARNING, "Device is trying to offload P2P " | |
927 | "Probe Response while not supporting this"); | |
928 | #endif /* CONFIG_P2P */ | |
929 | ||
930 | if (hapd->conf->interworking && | |
931 | !(hapd->iface->probe_resp_offloads & | |
932 | WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING)) | |
933 | wpa_printf(MSG_WARNING, "Device is trying to offload " | |
934 | "Interworking Probe Response while not supporting " | |
935 | "this"); | |
936 | ||
937 | /* Generate a Probe Response template for the non-P2P case */ | |
f41ded6f | 938 | return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len); |
5b99e21a AN |
939 | } |
940 | ||
062390ef JM |
941 | #endif /* NEED_AP_MLME */ |
942 | ||
943 | ||
e44a384b AO |
944 | int ieee802_11_build_ap_params(struct hostapd_data *hapd, |
945 | struct wpa_driver_ap_params *params) | |
6fc6879b | 946 | { |
062390ef JM |
947 | struct ieee80211_mgmt *head = NULL; |
948 | u8 *tail = NULL; | |
949 | size_t head_len = 0, tail_len = 0; | |
5b99e21a AN |
950 | u8 *resp = NULL; |
951 | size_t resp_len = 0; | |
062390ef JM |
952 | #ifdef NEED_AP_MLME |
953 | u16 capab_info; | |
38d9048f | 954 | u8 *pos, *tailpos, *csa_pos; |
062390ef | 955 | |
6fc6879b JM |
956 | #define BEACON_HEAD_BUF_SIZE 256 |
957 | #define BEACON_TAIL_BUF_SIZE 512 | |
958 | head = os_zalloc(BEACON_HEAD_BUF_SIZE); | |
1c08f8c0 JM |
959 | tail_len = BEACON_TAIL_BUF_SIZE; |
960 | #ifdef CONFIG_WPS | |
961 | if (hapd->conf->wps_state && hapd->wps_beacon_ie) | |
962 | tail_len += wpabuf_len(hapd->wps_beacon_ie); | |
963 | #endif /* CONFIG_WPS */ | |
e44f8bf2 JM |
964 | #ifdef CONFIG_P2P |
965 | if (hapd->p2p_beacon_ie) | |
966 | tail_len += wpabuf_len(hapd->p2p_beacon_ie); | |
967 | #endif /* CONFIG_P2P */ | |
347827ff AN |
968 | #ifdef CONFIG_FST |
969 | if (hapd->iface->fst_ies) | |
970 | tail_len += wpabuf_len(hapd->iface->fst_ies); | |
971 | #endif /* CONFIG_FST */ | |
b52f084c JM |
972 | if (hapd->conf->vendor_elements) |
973 | tail_len += wpabuf_len(hapd->conf->vendor_elements); | |
e7d0e97b YL |
974 | |
975 | #ifdef CONFIG_IEEE80211AC | |
976 | if (hapd->conf->vendor_vht) { | |
977 | tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) + | |
978 | 2 + sizeof(struct ieee80211_vht_operation); | |
979 | } | |
980 | #endif /* CONFIG_IEEE80211AC */ | |
981 | ||
1c08f8c0 | 982 | tailpos = tail = os_malloc(tail_len); |
6fc6879b JM |
983 | if (head == NULL || tail == NULL) { |
984 | wpa_printf(MSG_ERROR, "Failed to set beacon data"); | |
985 | os_free(head); | |
986 | os_free(tail); | |
e44a384b | 987 | return -1; |
6fc6879b JM |
988 | } |
989 | ||
990 | head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
991 | WLAN_FC_STYPE_BEACON); | |
992 | head->duration = host_to_le16(0); | |
993 | os_memset(head->da, 0xff, ETH_ALEN); | |
994 | ||
995 | os_memcpy(head->sa, hapd->own_addr, ETH_ALEN); | |
996 | os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN); | |
997 | head->u.beacon.beacon_int = | |
998 | host_to_le16(hapd->iconf->beacon_int); | |
999 | ||
1000 | /* hardware or low-level driver will setup seq_ctrl and timestamp */ | |
f41ded6f | 1001 | capab_info = hostapd_own_capab_info(hapd); |
6fc6879b JM |
1002 | head->u.beacon.capab_info = host_to_le16(capab_info); |
1003 | pos = &head->u.beacon.variable[0]; | |
1004 | ||
1005 | /* SSID */ | |
1006 | *pos++ = WLAN_EID_SSID; | |
1007 | if (hapd->conf->ignore_broadcast_ssid == 2) { | |
1008 | /* clear the data, but keep the correct length of the SSID */ | |
1009 | *pos++ = hapd->conf->ssid.ssid_len; | |
1010 | os_memset(pos, 0, hapd->conf->ssid.ssid_len); | |
1011 | pos += hapd->conf->ssid.ssid_len; | |
1012 | } else if (hapd->conf->ignore_broadcast_ssid) { | |
1013 | *pos++ = 0; /* empty SSID */ | |
1014 | } else { | |
1015 | *pos++ = hapd->conf->ssid.ssid_len; | |
1016 | os_memcpy(pos, hapd->conf->ssid.ssid, | |
1017 | hapd->conf->ssid.ssid_len); | |
1018 | pos += hapd->conf->ssid.ssid_len; | |
1019 | } | |
1020 | ||
1021 | /* Supported rates */ | |
1022 | pos = hostapd_eid_supp_rates(hapd, pos); | |
1023 | ||
1024 | /* DS Params */ | |
1025 | pos = hostapd_eid_ds_params(hapd, pos); | |
1026 | ||
1027 | head_len = pos - (u8 *) head; | |
1028 | ||
1029 | tailpos = hostapd_eid_country(hapd, tailpos, | |
1030 | tail + BEACON_TAIL_BUF_SIZE - tailpos); | |
1031 | ||
e0392f82 S |
1032 | /* Power Constraint element */ |
1033 | tailpos = hostapd_eid_pwr_constraint(hapd, tailpos); | |
1034 | ||
38d9048f AO |
1035 | /* CSA IE */ |
1036 | csa_pos = hostapd_eid_csa(hapd, tailpos); | |
1037 | if (csa_pos != tailpos) | |
1038 | hapd->cs_c_off_beacon = csa_pos - tail - 1; | |
1039 | tailpos = csa_pos; | |
1040 | ||
6fc6879b JM |
1041 | /* ERP Information element */ |
1042 | tailpos = hostapd_eid_erp_info(hapd, tailpos); | |
1043 | ||
1044 | /* Extended supported rates */ | |
1045 | tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos); | |
1046 | ||
1bc774a1 | 1047 | /* RSN, MDIE, WPA */ |
6fc6879b | 1048 | tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE - |
6c0575c3 | 1049 | tailpos); |
6fc6879b | 1050 | |
0629eeb4 JM |
1051 | tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos, |
1052 | tail + BEACON_TAIL_BUF_SIZE - | |
1053 | tailpos); | |
1054 | ||
9bc33868 JM |
1055 | tailpos = hostapd_eid_bss_load(hapd, tailpos, |
1056 | tail + BEACON_TAIL_BUF_SIZE - tailpos); | |
1057 | ||
38d9048f AO |
1058 | /* eCSA IE */ |
1059 | csa_pos = hostapd_eid_ecsa(hapd, tailpos); | |
1060 | if (csa_pos != tailpos) | |
1061 | hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1; | |
1062 | tailpos = csa_pos; | |
1063 | ||
c0d94d61 AO |
1064 | tailpos = hostapd_eid_supported_op_classes(hapd, tailpos); |
1065 | ||
de9289c8 | 1066 | #ifdef CONFIG_IEEE80211N |
38d9048f AO |
1067 | /* Secondary Channel Offset element */ |
1068 | /* TODO: The standard doesn't specify a position for this element. */ | |
1069 | tailpos = hostapd_eid_secondary_channel(hapd, tailpos); | |
1070 | ||
677449b9 JM |
1071 | tailpos = hostapd_eid_ht_capabilities(hapd, tailpos); |
1072 | tailpos = hostapd_eid_ht_operation(hapd, tailpos); | |
de9289c8 JM |
1073 | #endif /* CONFIG_IEEE80211N */ |
1074 | ||
1161ff1e JM |
1075 | tailpos = hostapd_eid_ext_capab(hapd, tailpos); |
1076 | ||
39b97072 JM |
1077 | /* |
1078 | * TODO: Time Advertisement element should only be included in some | |
1079 | * DTIM Beacon frames. | |
1080 | */ | |
1081 | tailpos = hostapd_eid_time_adv(hapd, tailpos); | |
1082 | ||
b83e3e93 | 1083 | tailpos = hostapd_eid_interworking(hapd, tailpos); |
c7c178e1 | 1084 | tailpos = hostapd_eid_adv_proto(hapd, tailpos); |
4b2a77ab | 1085 | tailpos = hostapd_eid_roaming_consortium(hapd, tailpos); |
347827ff AN |
1086 | |
1087 | #ifdef CONFIG_FST | |
1088 | if (hapd->iface->fst_ies) { | |
1089 | os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies), | |
1090 | wpabuf_len(hapd->iface->fst_ies)); | |
1091 | tailpos += wpabuf_len(hapd->iface->fst_ies); | |
1092 | } | |
1093 | #endif /* CONFIG_FST */ | |
1094 | ||
532b16c7 | 1095 | #ifdef CONFIG_IEEE80211AC |
e7d0e97b YL |
1096 | if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) { |
1097 | tailpos = hostapd_eid_vht_capabilities(hapd, tailpos); | |
1098 | tailpos = hostapd_eid_vht_operation(hapd, tailpos); | |
38d9048f | 1099 | tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos); |
e7d0e97b YL |
1100 | } |
1101 | if (hapd->conf->vendor_vht) | |
1102 | tailpos = hostapd_eid_vendor_vht(hapd, tailpos); | |
532b16c7 MP |
1103 | #endif /* CONFIG_IEEE80211AC */ |
1104 | ||
1bc774a1 JM |
1105 | /* Wi-Fi Alliance WMM */ |
1106 | tailpos = hostapd_eid_wmm(hapd, tailpos); | |
1107 | ||
ad08c363 JM |
1108 | #ifdef CONFIG_WPS |
1109 | if (hapd->conf->wps_state && hapd->wps_beacon_ie) { | |
14f79386 JM |
1110 | os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie), |
1111 | wpabuf_len(hapd->wps_beacon_ie)); | |
1112 | tailpos += wpabuf_len(hapd->wps_beacon_ie); | |
ad08c363 JM |
1113 | } |
1114 | #endif /* CONFIG_WPS */ | |
1115 | ||
e44f8bf2 JM |
1116 | #ifdef CONFIG_P2P |
1117 | if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) { | |
1118 | os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie), | |
1119 | wpabuf_len(hapd->p2p_beacon_ie)); | |
1120 | tailpos += wpabuf_len(hapd->p2p_beacon_ie); | |
1121 | } | |
1122 | #endif /* CONFIG_P2P */ | |
962473c1 JM |
1123 | #ifdef CONFIG_P2P_MANAGER |
1124 | if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) == | |
1125 | P2P_MANAGE) | |
1126 | tailpos = hostapd_eid_p2p_manage(hapd, tailpos); | |
1127 | #endif /* CONFIG_P2P_MANAGER */ | |
e44f8bf2 | 1128 | |
19a8ad99 JK |
1129 | #ifdef CONFIG_HS20 |
1130 | tailpos = hostapd_eid_hs20_indication(hapd, tailpos); | |
a14896e8 | 1131 | tailpos = hostapd_eid_osen(hapd, tailpos); |
19a8ad99 JK |
1132 | #endif /* CONFIG_HS20 */ |
1133 | ||
b52f084c JM |
1134 | if (hapd->conf->vendor_elements) { |
1135 | os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements), | |
1136 | wpabuf_len(hapd->conf->vendor_elements)); | |
1137 | tailpos += wpabuf_len(hapd->conf->vendor_elements); | |
1138 | } | |
1139 | ||
6fc6879b JM |
1140 | tail_len = tailpos > tail ? tailpos - tail : 0; |
1141 | ||
5b99e21a | 1142 | resp = hostapd_probe_resp_offloads(hapd, &resp_len); |
062390ef JM |
1143 | #endif /* NEED_AP_MLME */ |
1144 | ||
e44a384b AO |
1145 | os_memset(params, 0, sizeof(*params)); |
1146 | params->head = (u8 *) head; | |
1147 | params->head_len = head_len; | |
1148 | params->tail = tail; | |
1149 | params->tail_len = tail_len; | |
1150 | params->proberesp = resp; | |
1151 | params->proberesp_len = resp_len; | |
1152 | params->dtim_period = hapd->conf->dtim_period; | |
1153 | params->beacon_int = hapd->iconf->beacon_int; | |
1154 | params->basic_rates = hapd->iface->basic_rates; | |
1155 | params->ssid = hapd->conf->ssid.ssid; | |
1156 | params->ssid_len = hapd->conf->ssid.ssid_len; | |
e19c1d2c JM |
1157 | if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) == |
1158 | (WPA_PROTO_WPA | WPA_PROTO_RSN)) | |
1159 | params->pairwise_ciphers = hapd->conf->wpa_pairwise | | |
1160 | hapd->conf->rsn_pairwise; | |
1161 | else if (hapd->conf->wpa & WPA_PROTO_RSN) | |
1162 | params->pairwise_ciphers = hapd->conf->rsn_pairwise; | |
1163 | else if (hapd->conf->wpa & WPA_PROTO_WPA) | |
1164 | params->pairwise_ciphers = hapd->conf->wpa_pairwise; | |
e44a384b AO |
1165 | params->group_cipher = hapd->conf->wpa_group; |
1166 | params->key_mgmt_suites = hapd->conf->wpa_key_mgmt; | |
1167 | params->auth_algs = hapd->conf->auth_algs; | |
1168 | params->wpa_version = hapd->conf->wpa; | |
1169 | params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa || | |
b11d1d64 JM |
1170 | (hapd->conf->ieee802_1x && |
1171 | (hapd->conf->default_wep_key_len || | |
1172 | hapd->conf->individual_wep_key_len)); | |
97a7a0b5 JM |
1173 | switch (hapd->conf->ignore_broadcast_ssid) { |
1174 | case 0: | |
e44a384b | 1175 | params->hide_ssid = NO_SSID_HIDING; |
97a7a0b5 JM |
1176 | break; |
1177 | case 1: | |
e44a384b | 1178 | params->hide_ssid = HIDDEN_SSID_ZERO_LEN; |
97a7a0b5 JM |
1179 | break; |
1180 | case 2: | |
e44a384b | 1181 | params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS; |
97a7a0b5 JM |
1182 | break; |
1183 | } | |
e44a384b | 1184 | params->isolate = hapd->conf->isolate; |
8f461b50 | 1185 | params->smps_mode = hapd->iconf->ht_capab & HT_CAP_INFO_SMPS_MASK; |
31357268 | 1186 | #ifdef NEED_AP_MLME |
e44a384b | 1187 | params->cts_protect = !!(ieee802_11_erp_info(hapd) & |
31357268 | 1188 | ERP_INFO_USE_PROTECTION); |
e44a384b | 1189 | params->preamble = hapd->iface->num_sta_no_short_preamble == 0 && |
31357268 JM |
1190 | hapd->iconf->preamble == SHORT_PREAMBLE; |
1191 | if (hapd->iface->current_mode && | |
1192 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G) | |
e44a384b | 1193 | params->short_slot_time = |
31357268 JM |
1194 | hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1; |
1195 | else | |
e44a384b | 1196 | params->short_slot_time = -1; |
31357268 | 1197 | if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n) |
e44a384b | 1198 | params->ht_opmode = -1; |
31357268 | 1199 | else |
e44a384b | 1200 | params->ht_opmode = hapd->iface->ht_op_mode; |
31357268 | 1201 | #endif /* NEED_AP_MLME */ |
e44a384b | 1202 | params->interworking = hapd->conf->interworking; |
8a33a63f JM |
1203 | if (hapd->conf->interworking && |
1204 | !is_zero_ether_addr(hapd->conf->hessid)) | |
e44a384b AO |
1205 | params->hessid = hapd->conf->hessid; |
1206 | params->access_network_type = hapd->conf->access_network_type; | |
1207 | params->ap_max_inactivity = hapd->conf->ap_max_inactivity; | |
0b8bcaa5 EP |
1208 | #ifdef CONFIG_P2P |
1209 | params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow; | |
1210 | #endif /* CONFIG_P2P */ | |
83421850 | 1211 | #ifdef CONFIG_HS20 |
e44a384b | 1212 | params->disable_dgaf = hapd->conf->disable_dgaf; |
a14896e8 JM |
1213 | if (hapd->conf->osen) { |
1214 | params->privacy = 1; | |
1215 | params->osen = 1; | |
1216 | } | |
83421850 | 1217 | #endif /* CONFIG_HS20 */ |
e44a384b AO |
1218 | return 0; |
1219 | } | |
1220 | ||
1221 | ||
1222 | void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params) | |
1223 | { | |
1224 | os_free(params->tail); | |
1225 | params->tail = NULL; | |
1226 | os_free(params->head); | |
1227 | params->head = NULL; | |
1228 | os_free(params->proberesp); | |
1229 | params->proberesp = NULL; | |
1230 | } | |
1231 | ||
1232 | ||
bad5cdf4 | 1233 | int ieee802_11_set_beacon(struct hostapd_data *hapd) |
e44a384b AO |
1234 | { |
1235 | struct wpa_driver_ap_params params; | |
196c9c7c PX |
1236 | struct hostapd_freq_params freq; |
1237 | struct hostapd_iface *iface = hapd->iface; | |
1238 | struct hostapd_config *iconf = iface->conf; | |
e44a384b | 1239 | struct wpabuf *beacon, *proberesp, *assocresp; |
bad5cdf4 | 1240 | int res, ret = -1; |
e44a384b | 1241 | |
6782b684 | 1242 | if (hapd->csa_in_progress) { |
bf281c12 | 1243 | wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period"); |
bad5cdf4 | 1244 | return -1; |
bf281c12 AO |
1245 | } |
1246 | ||
e44a384b AO |
1247 | hapd->beacon_set_done = 1; |
1248 | ||
1249 | if (ieee802_11_build_ap_params(hapd, ¶ms) < 0) | |
bad5cdf4 | 1250 | return -1; |
e44a384b AO |
1251 | |
1252 | if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) < | |
1253 | 0) | |
1254 | goto fail; | |
1255 | ||
1256 | params.beacon_ies = beacon; | |
1257 | params.proberesp_ies = proberesp; | |
1258 | params.assocresp_ies = assocresp; | |
f33c8606 JM |
1259 | params.reenable = hapd->reenable_beacon; |
1260 | hapd->reenable_beacon = 0; | |
e44a384b | 1261 | |
196c9c7c PX |
1262 | if (iface->current_mode && |
1263 | hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq, | |
1264 | iconf->channel, iconf->ieee80211n, | |
1265 | iconf->ieee80211ac, | |
1266 | iconf->secondary_channel, | |
1267 | iconf->vht_oper_chwidth, | |
1268 | iconf->vht_oper_centr_freq_seg0_idx, | |
1269 | iconf->vht_oper_centr_freq_seg1_idx, | |
1270 | iface->current_mode->vht_capab) == 0) | |
1271 | params.freq = &freq; | |
1272 | ||
bad5cdf4 | 1273 | res = hostapd_drv_set_ap(hapd, ¶ms); |
fb91db56 | 1274 | hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp); |
bad5cdf4 JM |
1275 | if (res) |
1276 | wpa_printf(MSG_ERROR, "Failed to set beacon parameters"); | |
1277 | else | |
1278 | ret = 0; | |
e44a384b AO |
1279 | fail: |
1280 | ieee802_11_free_ap_params(¶ms); | |
bad5cdf4 | 1281 | return ret; |
6fc6879b JM |
1282 | } |
1283 | ||
1284 | ||
bad5cdf4 | 1285 | int ieee802_11_set_beacons(struct hostapd_iface *iface) |
6fc6879b JM |
1286 | { |
1287 | size_t i; | |
bad5cdf4 JM |
1288 | int ret = 0; |
1289 | ||
77a3e796 | 1290 | for (i = 0; i < iface->num_bss; i++) { |
bad5cdf4 JM |
1291 | if (iface->bss[i]->started && |
1292 | ieee802_11_set_beacon(iface->bss[i]) < 0) | |
1293 | ret = -1; | |
77a3e796 | 1294 | } |
bad5cdf4 JM |
1295 | |
1296 | return ret; | |
6fc6879b JM |
1297 | } |
1298 | ||
370b0761 LC |
1299 | |
1300 | /* only update beacons if started */ | |
bad5cdf4 | 1301 | int ieee802_11_update_beacons(struct hostapd_iface *iface) |
370b0761 LC |
1302 | { |
1303 | size_t i; | |
bad5cdf4 JM |
1304 | int ret = 0; |
1305 | ||
1306 | for (i = 0; i < iface->num_bss; i++) { | |
1307 | if (iface->bss[i]->beacon_set_done && iface->bss[i]->started && | |
1308 | ieee802_11_set_beacon(iface->bss[i]) < 0) | |
1309 | ret = -1; | |
1310 | } | |
1311 | ||
1312 | return ret; | |
370b0761 LC |
1313 | } |
1314 | ||
6fc6879b | 1315 | #endif /* CONFIG_NATIVE_WINDOWS */ |