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