]>
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 | { | |
300 | u8 chan; | |
301 | ||
6782b684 | 302 | if (!hapd->cs_freq_params.freq) |
bf281c12 AO |
303 | return eid; |
304 | ||
6782b684 | 305 | if (ieee80211_freq_to_chan(hapd->cs_freq_params.freq, &chan) == |
bf281c12 AO |
306 | NUM_HOSTAPD_MODES) |
307 | return eid; | |
308 | ||
309 | *eid++ = WLAN_EID_CHANNEL_SWITCH; | |
310 | *eid++ = 3; | |
6782b684 | 311 | *eid++ = hapd->cs_block_tx; |
bf281c12 | 312 | *eid++ = chan; |
6782b684 | 313 | *eid++ = hapd->cs_count; |
bf281c12 AO |
314 | |
315 | return eid; | |
316 | } | |
317 | ||
318 | ||
76aab030 AO |
319 | static u8 * hostapd_eid_secondary_channel(struct hostapd_data *hapd, u8 *eid) |
320 | { | |
321 | u8 sec_ch; | |
322 | ||
6782b684 | 323 | if (!hapd->cs_freq_params.sec_channel_offset) |
76aab030 AO |
324 | return eid; |
325 | ||
6782b684 | 326 | if (hapd->cs_freq_params.sec_channel_offset == -1) |
76aab030 | 327 | sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW; |
6782b684 | 328 | else if (hapd->cs_freq_params.sec_channel_offset == 1) |
76aab030 AO |
329 | sec_ch = HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE; |
330 | else | |
331 | return eid; | |
332 | ||
333 | *eid++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET; | |
334 | *eid++ = 1; | |
335 | *eid++ = sec_ch; | |
336 | ||
337 | return eid; | |
338 | } | |
339 | ||
340 | ||
341 | static u8 * hostapd_add_csa_elems(struct hostapd_data *hapd, u8 *pos, | |
342 | u8 *start, unsigned int *csa_counter_off) | |
343 | { | |
344 | u8 *old_pos = pos; | |
345 | ||
346 | if (!csa_counter_off) | |
347 | return pos; | |
348 | ||
349 | *csa_counter_off = 0; | |
350 | pos = hostapd_eid_csa(hapd, pos); | |
351 | ||
352 | if (pos != old_pos) { | |
353 | /* save an offset to the counter - should be last byte */ | |
354 | *csa_counter_off = pos - start - 1; | |
355 | pos = hostapd_eid_secondary_channel(hapd, pos); | |
356 | } | |
357 | ||
358 | return pos; | |
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; | |
76aab030 | 367 | u8 *pos, *epos; |
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 */ | |
b52f084c JM |
380 | if (hapd->conf->vendor_elements) |
381 | buflen += wpabuf_len(hapd->conf->vendor_elements); | |
e7d0e97b YL |
382 | if (hapd->conf->vendor_vht) { |
383 | buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) + | |
384 | 2 + sizeof(struct ieee80211_vht_operation); | |
385 | } | |
eacc6b24 AN |
386 | resp = os_zalloc(buflen); |
387 | if (resp == NULL) | |
388 | return NULL; | |
389 | ||
390 | epos = ((u8 *) resp) + MAX_PROBERESP_LEN; | |
391 | ||
392 | resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
393 | WLAN_FC_STYPE_PROBE_RESP); | |
394 | if (req) | |
395 | os_memcpy(resp->da, req->sa, ETH_ALEN); | |
396 | os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN); | |
397 | ||
398 | os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN); | |
399 | resp->u.probe_resp.beacon_int = | |
400 | host_to_le16(hapd->iconf->beacon_int); | |
401 | ||
402 | /* hardware or low-level driver will setup seq_ctrl and timestamp */ | |
403 | resp->u.probe_resp.capab_info = | |
f41ded6f | 404 | host_to_le16(hostapd_own_capab_info(hapd)); |
eacc6b24 AN |
405 | |
406 | pos = resp->u.probe_resp.variable; | |
407 | *pos++ = WLAN_EID_SSID; | |
408 | *pos++ = hapd->conf->ssid.ssid_len; | |
409 | os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len); | |
410 | pos += hapd->conf->ssid.ssid_len; | |
411 | ||
412 | /* Supported rates */ | |
413 | pos = hostapd_eid_supp_rates(hapd, pos); | |
414 | ||
415 | /* DS Params */ | |
416 | pos = hostapd_eid_ds_params(hapd, pos); | |
417 | ||
418 | pos = hostapd_eid_country(hapd, pos, epos - pos); | |
419 | ||
e0392f82 S |
420 | /* Power Constraint element */ |
421 | pos = hostapd_eid_pwr_constraint(hapd, pos); | |
422 | ||
eacc6b24 AN |
423 | /* ERP Information element */ |
424 | pos = hostapd_eid_erp_info(hapd, pos); | |
425 | ||
426 | /* Extended supported rates */ | |
427 | pos = hostapd_eid_ext_supp_rates(hapd, pos); | |
428 | ||
429 | /* RSN, MDIE, WPA */ | |
430 | pos = hostapd_eid_wpa(hapd, pos, epos - pos); | |
431 | ||
9bc33868 JM |
432 | pos = hostapd_eid_bss_load(hapd, pos, epos - pos); |
433 | ||
0629eeb4 JM |
434 | pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos); |
435 | ||
eacc6b24 AN |
436 | #ifdef CONFIG_IEEE80211N |
437 | pos = hostapd_eid_ht_capabilities(hapd, pos); | |
438 | pos = hostapd_eid_ht_operation(hapd, pos); | |
439 | #endif /* CONFIG_IEEE80211N */ | |
440 | ||
441 | pos = hostapd_eid_ext_capab(hapd, pos); | |
442 | ||
443 | pos = hostapd_eid_time_adv(hapd, pos); | |
444 | pos = hostapd_eid_time_zone(hapd, pos); | |
445 | ||
446 | pos = hostapd_eid_interworking(hapd, pos); | |
447 | pos = hostapd_eid_adv_proto(hapd, pos); | |
448 | pos = hostapd_eid_roaming_consortium(hapd, pos); | |
449 | ||
76aab030 | 450 | pos = hostapd_add_csa_elems(hapd, pos, (u8 *)resp, |
6782b684 | 451 | &hapd->cs_c_off_proberesp); |
532b16c7 | 452 | #ifdef CONFIG_IEEE80211AC |
e7d0e97b YL |
453 | if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) { |
454 | pos = hostapd_eid_vht_capabilities(hapd, pos); | |
455 | pos = hostapd_eid_vht_operation(hapd, pos); | |
456 | } | |
457 | if (hapd->conf->vendor_vht) | |
458 | pos = hostapd_eid_vendor_vht(hapd, pos); | |
532b16c7 MP |
459 | #endif /* CONFIG_IEEE80211AC */ |
460 | ||
eacc6b24 AN |
461 | /* Wi-Fi Alliance WMM */ |
462 | pos = hostapd_eid_wmm(hapd, pos); | |
463 | ||
464 | #ifdef CONFIG_WPS | |
465 | if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) { | |
466 | os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie), | |
467 | wpabuf_len(hapd->wps_probe_resp_ie)); | |
468 | pos += wpabuf_len(hapd->wps_probe_resp_ie); | |
469 | } | |
470 | #endif /* CONFIG_WPS */ | |
471 | ||
472 | #ifdef CONFIG_P2P | |
473 | if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p && | |
474 | hapd->p2p_probe_resp_ie) { | |
475 | os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie), | |
476 | wpabuf_len(hapd->p2p_probe_resp_ie)); | |
477 | pos += wpabuf_len(hapd->p2p_probe_resp_ie); | |
478 | } | |
479 | #endif /* CONFIG_P2P */ | |
480 | #ifdef CONFIG_P2P_MANAGER | |
481 | if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) == | |
482 | P2P_MANAGE) | |
483 | pos = hostapd_eid_p2p_manage(hapd, pos); | |
484 | #endif /* CONFIG_P2P_MANAGER */ | |
485 | ||
19a8ad99 JK |
486 | #ifdef CONFIG_HS20 |
487 | pos = hostapd_eid_hs20_indication(hapd, pos); | |
a14896e8 | 488 | pos = hostapd_eid_osen(hapd, pos); |
19a8ad99 JK |
489 | #endif /* CONFIG_HS20 */ |
490 | ||
b52f084c JM |
491 | if (hapd->conf->vendor_elements) { |
492 | os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements), | |
493 | wpabuf_len(hapd->conf->vendor_elements)); | |
494 | pos += wpabuf_len(hapd->conf->vendor_elements); | |
495 | } | |
496 | ||
eacc6b24 AN |
497 | *resp_len = pos - (u8 *) resp; |
498 | return (u8 *) resp; | |
499 | } | |
500 | ||
501 | ||
0a66ce3c JM |
502 | enum ssid_match_result { |
503 | NO_SSID_MATCH, | |
504 | EXACT_SSID_MATCH, | |
505 | WILDCARD_SSID_MATCH | |
506 | }; | |
507 | ||
508 | static enum ssid_match_result ssid_match(struct hostapd_data *hapd, | |
509 | const u8 *ssid, size_t ssid_len, | |
510 | const u8 *ssid_list, | |
511 | size_t ssid_list_len) | |
512 | { | |
513 | const u8 *pos, *end; | |
514 | int wildcard = 0; | |
515 | ||
516 | if (ssid_len == 0) | |
517 | wildcard = 1; | |
518 | if (ssid_len == hapd->conf->ssid.ssid_len && | |
519 | os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0) | |
520 | return EXACT_SSID_MATCH; | |
521 | ||
522 | if (ssid_list == NULL) | |
523 | return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH; | |
524 | ||
525 | pos = ssid_list; | |
526 | end = ssid_list + ssid_list_len; | |
527 | while (pos + 1 <= end) { | |
528 | if (pos + 2 + pos[1] > end) | |
529 | break; | |
530 | if (pos[1] == 0) | |
531 | wildcard = 1; | |
532 | if (pos[1] == hapd->conf->ssid.ssid_len && | |
533 | os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0) | |
534 | return EXACT_SSID_MATCH; | |
535 | pos += 2 + pos[1]; | |
536 | } | |
537 | ||
538 | return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH; | |
539 | } | |
540 | ||
541 | ||
b57e086c | 542 | void handle_probe_req(struct hostapd_data *hapd, |
baf513d6 JB |
543 | const struct ieee80211_mgmt *mgmt, size_t len, |
544 | int ssi_signal) | |
6fc6879b | 545 | { |
eacc6b24 | 546 | u8 *resp; |
6fc6879b | 547 | struct ieee802_11_elems elems; |
b57e086c | 548 | const u8 *ie; |
eacc6b24 | 549 | size_t ie_len; |
eacc6b24 | 550 | size_t i, resp_len; |
9a898ee8 | 551 | int noack; |
0a66ce3c | 552 | enum ssid_match_result res; |
6fc6879b JM |
553 | |
554 | ie = mgmt->u.probe_req.variable; | |
cbcf92b4 JM |
555 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req)) |
556 | return; | |
6fc6879b JM |
557 | ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req)); |
558 | ||
94709ea3 | 559 | for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) |
cd7d80f3 | 560 | if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx, |
04a85e44 | 561 | mgmt->sa, mgmt->da, mgmt->bssid, |
baf513d6 | 562 | ie, ie_len, ssi_signal) > 0) |
cd7d80f3 | 563 | return; |
ad08c363 | 564 | |
6fc6879b JM |
565 | if (!hapd->iconf->send_probe_response) |
566 | return; | |
567 | ||
3d536eb4 | 568 | if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) { |
6fc6879b JM |
569 | wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR, |
570 | MAC2STR(mgmt->sa)); | |
571 | return; | |
572 | } | |
573 | ||
6fc6879b JM |
574 | if ((!elems.ssid || !elems.supp_rates)) { |
575 | wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request " | |
576 | "without SSID or supported rates element", | |
577 | MAC2STR(mgmt->sa)); | |
578 | return; | |
579 | } | |
580 | ||
c612ae97 IP |
581 | /* |
582 | * No need to reply if the Probe Request frame was sent on an adjacent | |
583 | * channel. IEEE Std 802.11-2012 describes this as a requirement for an | |
584 | * AP with dot11RadioMeasurementActivated set to true, but strictly | |
585 | * speaking does not allow such ignoring of Probe Request frames if | |
586 | * dot11RadioMeasurementActivated is false. Anyway, this can help reduce | |
587 | * number of unnecessary Probe Response frames for cases where the STA | |
588 | * is less likely to see them (Probe Request frame sent on a | |
589 | * neighboring, but partially overlapping, channel). | |
590 | */ | |
591 | if (elems.ds_params && elems.ds_params_len == 1 && | |
592 | hapd->iface->current_mode && | |
593 | (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G || | |
594 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) && | |
595 | hapd->iconf->channel != elems.ds_params[0]) { | |
596 | wpa_printf(MSG_DEBUG, | |
597 | "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u", | |
598 | hapd->iconf->channel, elems.ds_params[0]); | |
599 | return; | |
600 | } | |
601 | ||
e44f8bf2 JM |
602 | #ifdef CONFIG_P2P |
603 | if (hapd->p2p && elems.wps_ie) { | |
604 | struct wpabuf *wps; | |
605 | wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA); | |
606 | if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) { | |
607 | wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request " | |
608 | "due to mismatch with Requested Device " | |
609 | "Type"); | |
610 | wpabuf_free(wps); | |
611 | return; | |
612 | } | |
613 | wpabuf_free(wps); | |
614 | } | |
8017b538 JM |
615 | |
616 | if (hapd->p2p && elems.p2p) { | |
617 | struct wpabuf *p2p; | |
618 | p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE); | |
619 | if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) { | |
620 | wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request " | |
621 | "due to mismatch with Device ID"); | |
622 | wpabuf_free(p2p); | |
623 | return; | |
624 | } | |
625 | wpabuf_free(p2p); | |
626 | } | |
e44f8bf2 JM |
627 | #endif /* CONFIG_P2P */ |
628 | ||
0a66ce3c JM |
629 | if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 && |
630 | elems.ssid_list_len == 0) { | |
6fc6879b JM |
631 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for " |
632 | "broadcast SSID ignored", MAC2STR(mgmt->sa)); | |
633 | return; | |
634 | } | |
635 | ||
e44f8bf2 JM |
636 | #ifdef CONFIG_P2P |
637 | if ((hapd->conf->p2p & P2P_GROUP_OWNER) && | |
638 | elems.ssid_len == P2P_WILDCARD_SSID_LEN && | |
639 | os_memcmp(elems.ssid, P2P_WILDCARD_SSID, | |
640 | P2P_WILDCARD_SSID_LEN) == 0) { | |
641 | /* Process P2P Wildcard SSID like Wildcard SSID */ | |
642 | elems.ssid_len = 0; | |
643 | } | |
644 | #endif /* CONFIG_P2P */ | |
645 | ||
0a66ce3c JM |
646 | res = ssid_match(hapd, elems.ssid, elems.ssid_len, |
647 | elems.ssid_list, elems.ssid_list_len); | |
f41ded6f | 648 | if (res == NO_SSID_MATCH) { |
6fc6879b | 649 | if (!(mgmt->da[0] & 0x01)) { |
6fc6879b | 650 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR |
0a66ce3c | 651 | " for foreign SSID '%s' (DA " MACSTR ")%s", |
b37d582e JM |
652 | MAC2STR(mgmt->sa), |
653 | wpa_ssid_txt(elems.ssid, elems.ssid_len), | |
0a66ce3c JM |
654 | MAC2STR(mgmt->da), |
655 | elems.ssid_list ? " (SSID list)" : ""); | |
6fc6879b JM |
656 | } |
657 | return; | |
658 | } | |
659 | ||
122ba579 | 660 | #ifdef CONFIG_INTERWORKING |
2aa82e52 MB |
661 | if (hapd->conf->interworking && |
662 | elems.interworking && elems.interworking_len >= 1) { | |
122ba579 JM |
663 | u8 ant = elems.interworking[0] & 0x0f; |
664 | if (ant != INTERWORKING_ANT_WILDCARD && | |
665 | ant != hapd->conf->access_network_type) { | |
666 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR | |
667 | " for mismatching ANT %u ignored", | |
668 | MAC2STR(mgmt->sa), ant); | |
669 | return; | |
670 | } | |
671 | } | |
672 | ||
2aa82e52 | 673 | if (hapd->conf->interworking && elems.interworking && |
122ba579 JM |
674 | (elems.interworking_len == 7 || elems.interworking_len == 9)) { |
675 | const u8 *hessid; | |
676 | if (elems.interworking_len == 7) | |
677 | hessid = elems.interworking + 1; | |
678 | else | |
679 | hessid = elems.interworking + 1 + 2; | |
680 | if (!is_broadcast_ether_addr(hessid) && | |
681 | os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) { | |
682 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR | |
683 | " for mismatching HESSID " MACSTR | |
684 | " ignored", | |
685 | MAC2STR(mgmt->sa), MAC2STR(hessid)); | |
686 | return; | |
687 | } | |
688 | } | |
689 | #endif /* CONFIG_INTERWORKING */ | |
690 | ||
85b4eac3 JM |
691 | #ifdef CONFIG_P2P |
692 | if ((hapd->conf->p2p & P2P_GROUP_OWNER) && | |
693 | supp_rates_11b_only(&elems)) { | |
694 | /* Indicates support for 11b rates only */ | |
695 | wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from " | |
696 | MACSTR " with only 802.11b rates", | |
697 | MAC2STR(mgmt->sa)); | |
698 | return; | |
699 | } | |
700 | #endif /* CONFIG_P2P */ | |
701 | ||
6fc6879b JM |
702 | /* TODO: verify that supp_rates contains at least one matching rate |
703 | * with AP configuration */ | |
eacc6b24 | 704 | |
c2aff6b1 | 705 | #ifdef CONFIG_TESTING_OPTIONS |
06df2aa6 | 706 | if (hapd->iconf->ignore_probe_probability > 0.0 && |
c2aff6b1 JB |
707 | drand48() < hapd->iconf->ignore_probe_probability) { |
708 | wpa_printf(MSG_INFO, | |
709 | "TESTING: ignoring probe request from " MACSTR, | |
710 | MAC2STR(mgmt->sa)); | |
711 | return; | |
712 | } | |
713 | #endif /* CONFIG_TESTING_OPTIONS */ | |
714 | ||
f41ded6f | 715 | resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL, |
eacc6b24 | 716 | &resp_len); |
6fc6879b JM |
717 | if (resp == NULL) |
718 | return; | |
e44f8bf2 | 719 | |
9a898ee8 HS |
720 | /* |
721 | * If this is a broadcast probe request, apply no ack policy to avoid | |
722 | * excessive retries. | |
723 | */ | |
0a66ce3c JM |
724 | noack = !!(res == WILDCARD_SSID_MATCH && |
725 | is_broadcast_ether_addr(mgmt->da)); | |
9a898ee8 | 726 | |
eacc6b24 | 727 | if (hostapd_drv_send_mlme(hapd, resp, resp_len, noack) < 0) |
61323e70 | 728 | wpa_printf(MSG_INFO, "handle_probe_req: send failed"); |
6fc6879b JM |
729 | |
730 | os_free(resp); | |
731 | ||
2d8bf732 | 732 | wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s " |
6fc6879b JM |
733 | "SSID", MAC2STR(mgmt->sa), |
734 | elems.ssid_len == 0 ? "broadcast" : "our"); | |
735 | } | |
736 | ||
5b99e21a AN |
737 | |
738 | static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd, | |
739 | size_t *resp_len) | |
740 | { | |
741 | /* check probe response offloading caps and print warnings */ | |
742 | if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD)) | |
743 | return NULL; | |
744 | ||
745 | #ifdef CONFIG_WPS | |
746 | if (hapd->conf->wps_state && hapd->wps_probe_resp_ie && | |
747 | (!(hapd->iface->probe_resp_offloads & | |
748 | (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS | | |
749 | WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2)))) | |
750 | wpa_printf(MSG_WARNING, "Device is trying to offload WPS " | |
751 | "Probe Response while not supporting this"); | |
752 | #endif /* CONFIG_WPS */ | |
753 | ||
754 | #ifdef CONFIG_P2P | |
755 | if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie && | |
756 | !(hapd->iface->probe_resp_offloads & | |
757 | WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P)) | |
758 | wpa_printf(MSG_WARNING, "Device is trying to offload P2P " | |
759 | "Probe Response while not supporting this"); | |
760 | #endif /* CONFIG_P2P */ | |
761 | ||
762 | if (hapd->conf->interworking && | |
763 | !(hapd->iface->probe_resp_offloads & | |
764 | WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING)) | |
765 | wpa_printf(MSG_WARNING, "Device is trying to offload " | |
766 | "Interworking Probe Response while not supporting " | |
767 | "this"); | |
768 | ||
769 | /* Generate a Probe Response template for the non-P2P case */ | |
f41ded6f | 770 | return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len); |
5b99e21a AN |
771 | } |
772 | ||
062390ef JM |
773 | #endif /* NEED_AP_MLME */ |
774 | ||
775 | ||
e44a384b AO |
776 | int ieee802_11_build_ap_params(struct hostapd_data *hapd, |
777 | struct wpa_driver_ap_params *params) | |
6fc6879b | 778 | { |
062390ef JM |
779 | struct ieee80211_mgmt *head = NULL; |
780 | u8 *tail = NULL; | |
781 | size_t head_len = 0, tail_len = 0; | |
5b99e21a AN |
782 | u8 *resp = NULL; |
783 | size_t resp_len = 0; | |
062390ef JM |
784 | #ifdef NEED_AP_MLME |
785 | u16 capab_info; | |
76aab030 | 786 | u8 *pos, *tailpos; |
062390ef | 787 | |
6fc6879b JM |
788 | #define BEACON_HEAD_BUF_SIZE 256 |
789 | #define BEACON_TAIL_BUF_SIZE 512 | |
790 | head = os_zalloc(BEACON_HEAD_BUF_SIZE); | |
1c08f8c0 JM |
791 | tail_len = BEACON_TAIL_BUF_SIZE; |
792 | #ifdef CONFIG_WPS | |
793 | if (hapd->conf->wps_state && hapd->wps_beacon_ie) | |
794 | tail_len += wpabuf_len(hapd->wps_beacon_ie); | |
795 | #endif /* CONFIG_WPS */ | |
e44f8bf2 JM |
796 | #ifdef CONFIG_P2P |
797 | if (hapd->p2p_beacon_ie) | |
798 | tail_len += wpabuf_len(hapd->p2p_beacon_ie); | |
799 | #endif /* CONFIG_P2P */ | |
b52f084c JM |
800 | if (hapd->conf->vendor_elements) |
801 | tail_len += wpabuf_len(hapd->conf->vendor_elements); | |
e7d0e97b YL |
802 | |
803 | #ifdef CONFIG_IEEE80211AC | |
804 | if (hapd->conf->vendor_vht) { | |
805 | tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) + | |
806 | 2 + sizeof(struct ieee80211_vht_operation); | |
807 | } | |
808 | #endif /* CONFIG_IEEE80211AC */ | |
809 | ||
1c08f8c0 | 810 | tailpos = tail = os_malloc(tail_len); |
6fc6879b JM |
811 | if (head == NULL || tail == NULL) { |
812 | wpa_printf(MSG_ERROR, "Failed to set beacon data"); | |
813 | os_free(head); | |
814 | os_free(tail); | |
e44a384b | 815 | return -1; |
6fc6879b JM |
816 | } |
817 | ||
818 | head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
819 | WLAN_FC_STYPE_BEACON); | |
820 | head->duration = host_to_le16(0); | |
821 | os_memset(head->da, 0xff, ETH_ALEN); | |
822 | ||
823 | os_memcpy(head->sa, hapd->own_addr, ETH_ALEN); | |
824 | os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN); | |
825 | head->u.beacon.beacon_int = | |
826 | host_to_le16(hapd->iconf->beacon_int); | |
827 | ||
828 | /* hardware or low-level driver will setup seq_ctrl and timestamp */ | |
f41ded6f | 829 | capab_info = hostapd_own_capab_info(hapd); |
6fc6879b JM |
830 | head->u.beacon.capab_info = host_to_le16(capab_info); |
831 | pos = &head->u.beacon.variable[0]; | |
832 | ||
833 | /* SSID */ | |
834 | *pos++ = WLAN_EID_SSID; | |
835 | if (hapd->conf->ignore_broadcast_ssid == 2) { | |
836 | /* clear the data, but keep the correct length of the SSID */ | |
837 | *pos++ = hapd->conf->ssid.ssid_len; | |
838 | os_memset(pos, 0, hapd->conf->ssid.ssid_len); | |
839 | pos += hapd->conf->ssid.ssid_len; | |
840 | } else if (hapd->conf->ignore_broadcast_ssid) { | |
841 | *pos++ = 0; /* empty SSID */ | |
842 | } else { | |
843 | *pos++ = hapd->conf->ssid.ssid_len; | |
844 | os_memcpy(pos, hapd->conf->ssid.ssid, | |
845 | hapd->conf->ssid.ssid_len); | |
846 | pos += hapd->conf->ssid.ssid_len; | |
847 | } | |
848 | ||
849 | /* Supported rates */ | |
850 | pos = hostapd_eid_supp_rates(hapd, pos); | |
851 | ||
852 | /* DS Params */ | |
853 | pos = hostapd_eid_ds_params(hapd, pos); | |
854 | ||
855 | head_len = pos - (u8 *) head; | |
856 | ||
857 | tailpos = hostapd_eid_country(hapd, tailpos, | |
858 | tail + BEACON_TAIL_BUF_SIZE - tailpos); | |
859 | ||
e0392f82 S |
860 | /* Power Constraint element */ |
861 | tailpos = hostapd_eid_pwr_constraint(hapd, tailpos); | |
862 | ||
6fc6879b JM |
863 | /* ERP Information element */ |
864 | tailpos = hostapd_eid_erp_info(hapd, tailpos); | |
865 | ||
866 | /* Extended supported rates */ | |
867 | tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos); | |
868 | ||
1bc774a1 | 869 | /* RSN, MDIE, WPA */ |
6fc6879b | 870 | tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE - |
6c0575c3 | 871 | tailpos); |
6fc6879b | 872 | |
0629eeb4 JM |
873 | tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos, |
874 | tail + BEACON_TAIL_BUF_SIZE - | |
875 | tailpos); | |
876 | ||
9bc33868 JM |
877 | tailpos = hostapd_eid_bss_load(hapd, tailpos, |
878 | tail + BEACON_TAIL_BUF_SIZE - tailpos); | |
879 | ||
de9289c8 | 880 | #ifdef CONFIG_IEEE80211N |
677449b9 JM |
881 | tailpos = hostapd_eid_ht_capabilities(hapd, tailpos); |
882 | tailpos = hostapd_eid_ht_operation(hapd, tailpos); | |
de9289c8 JM |
883 | #endif /* CONFIG_IEEE80211N */ |
884 | ||
1161ff1e JM |
885 | tailpos = hostapd_eid_ext_capab(hapd, tailpos); |
886 | ||
39b97072 JM |
887 | /* |
888 | * TODO: Time Advertisement element should only be included in some | |
889 | * DTIM Beacon frames. | |
890 | */ | |
891 | tailpos = hostapd_eid_time_adv(hapd, tailpos); | |
892 | ||
b83e3e93 | 893 | tailpos = hostapd_eid_interworking(hapd, tailpos); |
c7c178e1 | 894 | tailpos = hostapd_eid_adv_proto(hapd, tailpos); |
4b2a77ab | 895 | tailpos = hostapd_eid_roaming_consortium(hapd, tailpos); |
76aab030 | 896 | tailpos = hostapd_add_csa_elems(hapd, tailpos, tail, |
6782b684 | 897 | &hapd->cs_c_off_beacon); |
532b16c7 | 898 | #ifdef CONFIG_IEEE80211AC |
e7d0e97b YL |
899 | if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) { |
900 | tailpos = hostapd_eid_vht_capabilities(hapd, tailpos); | |
901 | tailpos = hostapd_eid_vht_operation(hapd, tailpos); | |
902 | } | |
903 | if (hapd->conf->vendor_vht) | |
904 | tailpos = hostapd_eid_vendor_vht(hapd, tailpos); | |
532b16c7 MP |
905 | #endif /* CONFIG_IEEE80211AC */ |
906 | ||
1bc774a1 JM |
907 | /* Wi-Fi Alliance WMM */ |
908 | tailpos = hostapd_eid_wmm(hapd, tailpos); | |
909 | ||
ad08c363 JM |
910 | #ifdef CONFIG_WPS |
911 | if (hapd->conf->wps_state && hapd->wps_beacon_ie) { | |
14f79386 JM |
912 | os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie), |
913 | wpabuf_len(hapd->wps_beacon_ie)); | |
914 | tailpos += wpabuf_len(hapd->wps_beacon_ie); | |
ad08c363 JM |
915 | } |
916 | #endif /* CONFIG_WPS */ | |
917 | ||
e44f8bf2 JM |
918 | #ifdef CONFIG_P2P |
919 | if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) { | |
920 | os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie), | |
921 | wpabuf_len(hapd->p2p_beacon_ie)); | |
922 | tailpos += wpabuf_len(hapd->p2p_beacon_ie); | |
923 | } | |
924 | #endif /* CONFIG_P2P */ | |
962473c1 JM |
925 | #ifdef CONFIG_P2P_MANAGER |
926 | if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) == | |
927 | P2P_MANAGE) | |
928 | tailpos = hostapd_eid_p2p_manage(hapd, tailpos); | |
929 | #endif /* CONFIG_P2P_MANAGER */ | |
e44f8bf2 | 930 | |
19a8ad99 JK |
931 | #ifdef CONFIG_HS20 |
932 | tailpos = hostapd_eid_hs20_indication(hapd, tailpos); | |
a14896e8 | 933 | tailpos = hostapd_eid_osen(hapd, tailpos); |
19a8ad99 JK |
934 | #endif /* CONFIG_HS20 */ |
935 | ||
b52f084c JM |
936 | if (hapd->conf->vendor_elements) { |
937 | os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements), | |
938 | wpabuf_len(hapd->conf->vendor_elements)); | |
939 | tailpos += wpabuf_len(hapd->conf->vendor_elements); | |
940 | } | |
941 | ||
6fc6879b JM |
942 | tail_len = tailpos > tail ? tailpos - tail : 0; |
943 | ||
5b99e21a | 944 | resp = hostapd_probe_resp_offloads(hapd, &resp_len); |
062390ef JM |
945 | #endif /* NEED_AP_MLME */ |
946 | ||
e44a384b AO |
947 | os_memset(params, 0, sizeof(*params)); |
948 | params->head = (u8 *) head; | |
949 | params->head_len = head_len; | |
950 | params->tail = tail; | |
951 | params->tail_len = tail_len; | |
952 | params->proberesp = resp; | |
953 | params->proberesp_len = resp_len; | |
954 | params->dtim_period = hapd->conf->dtim_period; | |
955 | params->beacon_int = hapd->iconf->beacon_int; | |
956 | params->basic_rates = hapd->iface->basic_rates; | |
957 | params->ssid = hapd->conf->ssid.ssid; | |
958 | params->ssid_len = hapd->conf->ssid.ssid_len; | |
95b6bca6 DPS |
959 | params->pairwise_ciphers = hapd->conf->wpa_pairwise | |
960 | hapd->conf->rsn_pairwise; | |
e44a384b AO |
961 | params->group_cipher = hapd->conf->wpa_group; |
962 | params->key_mgmt_suites = hapd->conf->wpa_key_mgmt; | |
963 | params->auth_algs = hapd->conf->auth_algs; | |
964 | params->wpa_version = hapd->conf->wpa; | |
965 | params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa || | |
b11d1d64 JM |
966 | (hapd->conf->ieee802_1x && |
967 | (hapd->conf->default_wep_key_len || | |
968 | hapd->conf->individual_wep_key_len)); | |
97a7a0b5 JM |
969 | switch (hapd->conf->ignore_broadcast_ssid) { |
970 | case 0: | |
e44a384b | 971 | params->hide_ssid = NO_SSID_HIDING; |
97a7a0b5 JM |
972 | break; |
973 | case 1: | |
e44a384b | 974 | params->hide_ssid = HIDDEN_SSID_ZERO_LEN; |
97a7a0b5 JM |
975 | break; |
976 | case 2: | |
e44a384b | 977 | params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS; |
97a7a0b5 JM |
978 | break; |
979 | } | |
e44a384b | 980 | params->isolate = hapd->conf->isolate; |
8f461b50 | 981 | params->smps_mode = hapd->iconf->ht_capab & HT_CAP_INFO_SMPS_MASK; |
31357268 | 982 | #ifdef NEED_AP_MLME |
e44a384b | 983 | params->cts_protect = !!(ieee802_11_erp_info(hapd) & |
31357268 | 984 | ERP_INFO_USE_PROTECTION); |
e44a384b | 985 | params->preamble = hapd->iface->num_sta_no_short_preamble == 0 && |
31357268 JM |
986 | hapd->iconf->preamble == SHORT_PREAMBLE; |
987 | if (hapd->iface->current_mode && | |
988 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G) | |
e44a384b | 989 | params->short_slot_time = |
31357268 JM |
990 | hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1; |
991 | else | |
e44a384b | 992 | params->short_slot_time = -1; |
31357268 | 993 | if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n) |
e44a384b | 994 | params->ht_opmode = -1; |
31357268 | 995 | else |
e44a384b | 996 | params->ht_opmode = hapd->iface->ht_op_mode; |
31357268 | 997 | #endif /* NEED_AP_MLME */ |
e44a384b | 998 | params->interworking = hapd->conf->interworking; |
8a33a63f JM |
999 | if (hapd->conf->interworking && |
1000 | !is_zero_ether_addr(hapd->conf->hessid)) | |
e44a384b AO |
1001 | params->hessid = hapd->conf->hessid; |
1002 | params->access_network_type = hapd->conf->access_network_type; | |
1003 | params->ap_max_inactivity = hapd->conf->ap_max_inactivity; | |
0b8bcaa5 EP |
1004 | #ifdef CONFIG_P2P |
1005 | params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow; | |
1006 | #endif /* CONFIG_P2P */ | |
83421850 | 1007 | #ifdef CONFIG_HS20 |
e44a384b | 1008 | params->disable_dgaf = hapd->conf->disable_dgaf; |
a14896e8 JM |
1009 | if (hapd->conf->osen) { |
1010 | params->privacy = 1; | |
1011 | params->osen = 1; | |
1012 | } | |
83421850 | 1013 | #endif /* CONFIG_HS20 */ |
e44a384b AO |
1014 | return 0; |
1015 | } | |
1016 | ||
1017 | ||
1018 | void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params) | |
1019 | { | |
1020 | os_free(params->tail); | |
1021 | params->tail = NULL; | |
1022 | os_free(params->head); | |
1023 | params->head = NULL; | |
1024 | os_free(params->proberesp); | |
1025 | params->proberesp = NULL; | |
1026 | } | |
1027 | ||
1028 | ||
bad5cdf4 | 1029 | int ieee802_11_set_beacon(struct hostapd_data *hapd) |
e44a384b AO |
1030 | { |
1031 | struct wpa_driver_ap_params params; | |
196c9c7c PX |
1032 | struct hostapd_freq_params freq; |
1033 | struct hostapd_iface *iface = hapd->iface; | |
1034 | struct hostapd_config *iconf = iface->conf; | |
e44a384b | 1035 | struct wpabuf *beacon, *proberesp, *assocresp; |
bad5cdf4 | 1036 | int res, ret = -1; |
e44a384b | 1037 | |
6782b684 | 1038 | if (hapd->csa_in_progress) { |
bf281c12 | 1039 | wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period"); |
bad5cdf4 | 1040 | return -1; |
bf281c12 AO |
1041 | } |
1042 | ||
e44a384b AO |
1043 | hapd->beacon_set_done = 1; |
1044 | ||
1045 | if (ieee802_11_build_ap_params(hapd, ¶ms) < 0) | |
bad5cdf4 | 1046 | return -1; |
e44a384b AO |
1047 | |
1048 | if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) < | |
1049 | 0) | |
1050 | goto fail; | |
1051 | ||
1052 | params.beacon_ies = beacon; | |
1053 | params.proberesp_ies = proberesp; | |
1054 | params.assocresp_ies = assocresp; | |
f33c8606 JM |
1055 | params.reenable = hapd->reenable_beacon; |
1056 | hapd->reenable_beacon = 0; | |
e44a384b | 1057 | |
196c9c7c PX |
1058 | if (iface->current_mode && |
1059 | hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq, | |
1060 | iconf->channel, iconf->ieee80211n, | |
1061 | iconf->ieee80211ac, | |
1062 | iconf->secondary_channel, | |
1063 | iconf->vht_oper_chwidth, | |
1064 | iconf->vht_oper_centr_freq_seg0_idx, | |
1065 | iconf->vht_oper_centr_freq_seg1_idx, | |
1066 | iface->current_mode->vht_capab) == 0) | |
1067 | params.freq = &freq; | |
1068 | ||
bad5cdf4 | 1069 | res = hostapd_drv_set_ap(hapd, ¶ms); |
fb91db56 | 1070 | hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp); |
bad5cdf4 JM |
1071 | if (res) |
1072 | wpa_printf(MSG_ERROR, "Failed to set beacon parameters"); | |
1073 | else | |
1074 | ret = 0; | |
e44a384b AO |
1075 | fail: |
1076 | ieee802_11_free_ap_params(¶ms); | |
bad5cdf4 | 1077 | return ret; |
6fc6879b JM |
1078 | } |
1079 | ||
1080 | ||
bad5cdf4 | 1081 | int ieee802_11_set_beacons(struct hostapd_iface *iface) |
6fc6879b JM |
1082 | { |
1083 | size_t i; | |
bad5cdf4 JM |
1084 | int ret = 0; |
1085 | ||
77a3e796 | 1086 | for (i = 0; i < iface->num_bss; i++) { |
bad5cdf4 JM |
1087 | if (iface->bss[i]->started && |
1088 | ieee802_11_set_beacon(iface->bss[i]) < 0) | |
1089 | ret = -1; | |
77a3e796 | 1090 | } |
bad5cdf4 JM |
1091 | |
1092 | return ret; | |
6fc6879b JM |
1093 | } |
1094 | ||
370b0761 LC |
1095 | |
1096 | /* only update beacons if started */ | |
bad5cdf4 | 1097 | int ieee802_11_update_beacons(struct hostapd_iface *iface) |
370b0761 LC |
1098 | { |
1099 | size_t i; | |
bad5cdf4 JM |
1100 | int ret = 0; |
1101 | ||
1102 | for (i = 0; i < iface->num_bss; i++) { | |
1103 | if (iface->bss[i]->beacon_set_done && iface->bss[i]->started && | |
1104 | ieee802_11_set_beacon(iface->bss[i]) < 0) | |
1105 | ret = -1; | |
1106 | } | |
1107 | ||
1108 | return ret; | |
370b0761 LC |
1109 | } |
1110 | ||
6fc6879b | 1111 | #endif /* CONFIG_NATIVE_WINDOWS */ |