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