]> git.ipfire.org Git - thirdparty/hostap.git/blob - src/ap/beacon.c
Allow RSNXE to be removed from Beacon frames for testing purposes
[thirdparty/hostap.git] / src / ap / beacon.c
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.
5 * Copyright (c) 2008-2012, Jouni Malinen <j@w1.fi>
6 *
7 * This software may be distributed under the terms of the BSD license.
8 * See README for more details.
9 */
10
11 #include "utils/includes.h"
12
13 #ifndef CONFIG_NATIVE_WINDOWS
14
15 #include "utils/common.h"
16 #include "common/ieee802_11_defs.h"
17 #include "common/ieee802_11_common.h"
18 #include "common/hw_features_common.h"
19 #include "common/wpa_ctrl.h"
20 #include "wps/wps_defs.h"
21 #include "p2p/p2p.h"
22 #include "hostapd.h"
23 #include "ieee802_11.h"
24 #include "wpa_auth.h"
25 #include "wmm.h"
26 #include "ap_config.h"
27 #include "sta_info.h"
28 #include "p2p_hostapd.h"
29 #include "ap_drv_ops.h"
30 #include "beacon.h"
31 #include "hs20.h"
32 #include "dfs.h"
33 #include "taxonomy.h"
34 #include "ieee802_11_auth.h"
35
36
37 #ifdef NEED_AP_MLME
38
39 static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
40 {
41 if (len < 2 + 5)
42 return eid;
43
44 #ifdef CONFIG_TESTING_OPTIONS
45 if (hapd->conf->bss_load_test_set) {
46 *eid++ = WLAN_EID_BSS_LOAD;
47 *eid++ = 5;
48 os_memcpy(eid, hapd->conf->bss_load_test, 5);
49 eid += 5;
50 return eid;
51 }
52 #endif /* CONFIG_TESTING_OPTIONS */
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 }
62 return eid;
63 }
64
65
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
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;
79 }
80 if (hapd->iface->num_sta_no_short_preamble > 0 ||
81 hapd->iconf->preamble == LONG_PREAMBLE)
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
121 static u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid)
122 {
123 u8 *pos = eid;
124 u8 local_pwr_constraint = 0;
125 int dfs;
126
127 if (hapd->iface->current_mode == NULL ||
128 hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
129 return eid;
130
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
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
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 */
180 if (local_pwr_constraint)
181 *pos++ = local_pwr_constraint;
182 else
183 *pos++ = hapd->iconf->local_pwr_constraint;
184
185 return pos;
186 }
187
188
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
207 static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
208 int max_len)
209 {
210 u8 *pos = eid;
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)
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
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
242 if (start && prev) {
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;
260 *pos++ = 0; /* pad for 16-bit alignment */
261 }
262
263 eid[1] = (pos - eid) - 2;
264
265 return pos;
266 }
267
268
269 static const u8 * hostapd_wpa_ie(struct hostapd_data *hapd, u8 eid)
270 {
271 const u8 *ies;
272 size_t ies_len;
273
274 ies = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ies_len);
275 if (!ies)
276 return NULL;
277
278 return get_ie(ies, ies_len, eid);
279 }
280
281
282 static const u8 * hostapd_vendor_wpa_ie(struct hostapd_data *hapd,
283 u32 vendor_type)
284 {
285 const u8 *ies;
286 size_t ies_len;
287
288 ies = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ies_len);
289 if (!ies)
290 return NULL;
291
292 return get_vendor_ie(ies, ies_len, vendor_type);
293 }
294
295
296 static u8 * hostapd_get_rsne(struct hostapd_data *hapd, u8 *pos, size_t len)
297 {
298 const u8 *ie;
299
300 ie = hostapd_wpa_ie(hapd, WLAN_EID_RSN);
301 if (!ie || 2U + ie[1] > len)
302 return pos;
303
304 os_memcpy(pos, ie, 2 + ie[1]);
305 return pos + 2 + ie[1];
306 }
307
308
309 static u8 * hostapd_get_mde(struct hostapd_data *hapd, u8 *pos, size_t len)
310 {
311 const u8 *ie;
312
313 ie = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN);
314 if (!ie || 2U + ie[1] > len)
315 return pos;
316
317 os_memcpy(pos, ie, 2 + ie[1]);
318 return pos + 2 + ie[1];
319 }
320
321
322 static u8 * hostapd_get_rsnxe(struct hostapd_data *hapd, u8 *pos, size_t len)
323 {
324 const u8 *ie;
325
326 #ifdef CONFIG_TESTING_OPTIONS
327 if (hapd->conf->no_beacon_rsnxe) {
328 wpa_printf(MSG_INFO, "TESTING: Do not add RSNXE into Beacon");
329 return pos;
330 }
331 #endif /* CONFIG_TESTING_OPTIONS */
332 ie = hostapd_wpa_ie(hapd, WLAN_EID_RSNX);
333 if (!ie || 2U + ie[1] > len)
334 return pos;
335
336 os_memcpy(pos, ie, 2 + ie[1]);
337 return pos + 2 + ie[1];
338 }
339
340
341 static u8 * hostapd_get_wpa_ie(struct hostapd_data *hapd, u8 *pos, size_t len)
342 {
343 const u8 *ie;
344
345 ie = hostapd_vendor_wpa_ie(hapd, WPA_IE_VENDOR_TYPE);
346 if (!ie || 2U + ie[1] > len)
347 return pos;
348
349 os_memcpy(pos, ie, 2 + ie[1]);
350 return pos + 2 + ie[1];
351 }
352
353
354 static u8 * hostapd_get_osen_ie(struct hostapd_data *hapd, u8 *pos, size_t len)
355 {
356 const u8 *ie;
357
358 ie = hostapd_vendor_wpa_ie(hapd, OSEN_IE_VENDOR_TYPE);
359 if (!ie || 2U + ie[1] > len)
360 return pos;
361
362 os_memcpy(pos, ie, 2 + ie[1]);
363 return pos + 2 + ie[1];
364 }
365
366
367 static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
368 {
369 #ifdef CONFIG_TESTING_OPTIONS
370 if (hapd->iface->cs_oper_class && hapd->iconf->ecsa_ie_only)
371 return eid;
372 #endif /* CONFIG_TESTING_OPTIONS */
373
374 if (!hapd->cs_freq_params.channel)
375 return eid;
376
377 *eid++ = WLAN_EID_CHANNEL_SWITCH;
378 *eid++ = 3;
379 *eid++ = hapd->cs_block_tx;
380 *eid++ = hapd->cs_freq_params.channel;
381 *eid++ = hapd->cs_count;
382
383 return eid;
384 }
385
386
387 static u8 * hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid)
388 {
389 if (!hapd->cs_freq_params.channel || !hapd->iface->cs_oper_class)
390 return eid;
391
392 *eid++ = WLAN_EID_EXT_CHANSWITCH_ANN;
393 *eid++ = 4;
394 *eid++ = hapd->cs_block_tx;
395 *eid++ = hapd->iface->cs_oper_class;
396 *eid++ = hapd->cs_freq_params.channel;
397 *eid++ = hapd->cs_count;
398
399 return eid;
400 }
401
402
403 static u8 * hostapd_eid_supported_op_classes(struct hostapd_data *hapd, u8 *eid)
404 {
405 u8 op_class, channel;
406
407 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) ||
408 !hapd->iface->freq)
409 return eid;
410
411 if (ieee80211_freq_to_channel_ext(hapd->iface->freq,
412 hapd->iconf->secondary_channel,
413 hostapd_get_oper_chwidth(hapd->iconf),
414 &op_class, &channel) ==
415 NUM_HOSTAPD_MODES)
416 return eid;
417
418 *eid++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES;
419 *eid++ = 2;
420
421 /* Current Operating Class */
422 *eid++ = op_class;
423
424 /* TODO: Advertise all the supported operating classes */
425 *eid++ = 0;
426
427 return eid;
428 }
429
430
431 static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
432 const struct ieee80211_mgmt *req,
433 int is_p2p, size_t *resp_len)
434 {
435 struct ieee80211_mgmt *resp;
436 u8 *pos, *epos, *csa_pos;
437 size_t buflen;
438
439 #define MAX_PROBERESP_LEN 768
440 buflen = MAX_PROBERESP_LEN;
441 #ifdef CONFIG_WPS
442 if (hapd->wps_probe_resp_ie)
443 buflen += wpabuf_len(hapd->wps_probe_resp_ie);
444 #endif /* CONFIG_WPS */
445 #ifdef CONFIG_P2P
446 if (hapd->p2p_probe_resp_ie)
447 buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
448 #endif /* CONFIG_P2P */
449 #ifdef CONFIG_FST
450 if (hapd->iface->fst_ies)
451 buflen += wpabuf_len(hapd->iface->fst_ies);
452 #endif /* CONFIG_FST */
453 if (hapd->conf->vendor_elements)
454 buflen += wpabuf_len(hapd->conf->vendor_elements);
455 if (hapd->conf->vendor_vht) {
456 buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
457 2 + sizeof(struct ieee80211_vht_operation);
458 }
459
460 #ifdef CONFIG_IEEE80211AX
461 if (hapd->iconf->ieee80211ax) {
462 buflen += 3 + sizeof(struct ieee80211_he_capabilities) +
463 3 + sizeof(struct ieee80211_he_operation) +
464 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
465 3 + sizeof(struct ieee80211_spatial_reuse);
466 }
467 #endif /* CONFIG_IEEE80211AX */
468
469 buflen += hostapd_mbo_ie_len(hapd);
470 buflen += hostapd_eid_owe_trans_len(hapd);
471
472 resp = os_zalloc(buflen);
473 if (resp == NULL)
474 return NULL;
475
476 epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
477
478 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
479 WLAN_FC_STYPE_PROBE_RESP);
480 if (req)
481 os_memcpy(resp->da, req->sa, ETH_ALEN);
482 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
483
484 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
485 resp->u.probe_resp.beacon_int =
486 host_to_le16(hapd->iconf->beacon_int);
487
488 /* hardware or low-level driver will setup seq_ctrl and timestamp */
489 resp->u.probe_resp.capab_info =
490 host_to_le16(hostapd_own_capab_info(hapd));
491
492 pos = resp->u.probe_resp.variable;
493 *pos++ = WLAN_EID_SSID;
494 *pos++ = hapd->conf->ssid.ssid_len;
495 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
496 pos += hapd->conf->ssid.ssid_len;
497
498 /* Supported rates */
499 pos = hostapd_eid_supp_rates(hapd, pos);
500
501 /* DS Params */
502 pos = hostapd_eid_ds_params(hapd, pos);
503
504 pos = hostapd_eid_country(hapd, pos, epos - pos);
505
506 /* Power Constraint element */
507 pos = hostapd_eid_pwr_constraint(hapd, pos);
508
509 /* CSA IE */
510 csa_pos = hostapd_eid_csa(hapd, pos);
511 if (csa_pos != pos)
512 hapd->cs_c_off_proberesp = csa_pos - (u8 *) resp - 1;
513 pos = csa_pos;
514
515 /* ERP Information element */
516 pos = hostapd_eid_erp_info(hapd, pos);
517
518 /* Extended supported rates */
519 pos = hostapd_eid_ext_supp_rates(hapd, pos);
520
521 pos = hostapd_get_rsne(hapd, pos, epos - pos);
522 pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
523 pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
524 pos = hostapd_get_mde(hapd, pos, epos - pos);
525
526 /* eCSA IE */
527 csa_pos = hostapd_eid_ecsa(hapd, pos);
528 if (csa_pos != pos)
529 hapd->cs_c_off_ecsa_proberesp = csa_pos - (u8 *) resp - 1;
530 pos = csa_pos;
531
532 pos = hostapd_eid_supported_op_classes(hapd, pos);
533 pos = hostapd_eid_ht_capabilities(hapd, pos);
534 pos = hostapd_eid_ht_operation(hapd, pos);
535
536 pos = hostapd_eid_ext_capab(hapd, pos);
537
538 pos = hostapd_eid_time_adv(hapd, pos);
539 pos = hostapd_eid_time_zone(hapd, pos);
540
541 pos = hostapd_eid_interworking(hapd, pos);
542 pos = hostapd_eid_adv_proto(hapd, pos);
543 pos = hostapd_eid_roaming_consortium(hapd, pos);
544
545 #ifdef CONFIG_FST
546 if (hapd->iface->fst_ies) {
547 os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies),
548 wpabuf_len(hapd->iface->fst_ies));
549 pos += wpabuf_len(hapd->iface->fst_ies);
550 }
551 #endif /* CONFIG_FST */
552
553 #ifdef CONFIG_IEEE80211AC
554 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac &&
555 !is_6ghz_op_class(hapd->iconf->op_class)) {
556 pos = hostapd_eid_vht_capabilities(hapd, pos, 0);
557 pos = hostapd_eid_vht_operation(hapd, pos);
558 pos = hostapd_eid_txpower_envelope(hapd, pos);
559 pos = hostapd_eid_wb_chsw_wrapper(hapd, pos);
560 }
561 #endif /* CONFIG_IEEE80211AC */
562
563 pos = hostapd_eid_fils_indic(hapd, pos, 0);
564 pos = hostapd_get_rsnxe(hapd, pos, epos - pos);
565
566 #ifdef CONFIG_IEEE80211AX
567 if (hapd->iconf->ieee80211ax) {
568 pos = hostapd_eid_he_capab(hapd, pos, IEEE80211_MODE_AP);
569 pos = hostapd_eid_he_operation(hapd, pos);
570 pos = hostapd_eid_spatial_reuse(hapd, pos);
571 pos = hostapd_eid_he_mu_edca_parameter_set(hapd, pos);
572 }
573 #endif /* CONFIG_IEEE80211AX */
574
575 #ifdef CONFIG_IEEE80211AC
576 if (hapd->conf->vendor_vht)
577 pos = hostapd_eid_vendor_vht(hapd, pos);
578 #endif /* CONFIG_IEEE80211AC */
579
580 /* WPA / OSEN */
581 pos = hostapd_get_wpa_ie(hapd, pos, epos - pos);
582 pos = hostapd_get_osen_ie(hapd, pos, epos - pos);
583
584 /* Wi-Fi Alliance WMM */
585 pos = hostapd_eid_wmm(hapd, pos);
586
587 #ifdef CONFIG_WPS
588 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
589 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
590 wpabuf_len(hapd->wps_probe_resp_ie));
591 pos += wpabuf_len(hapd->wps_probe_resp_ie);
592 }
593 #endif /* CONFIG_WPS */
594
595 #ifdef CONFIG_P2P
596 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
597 hapd->p2p_probe_resp_ie) {
598 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
599 wpabuf_len(hapd->p2p_probe_resp_ie));
600 pos += wpabuf_len(hapd->p2p_probe_resp_ie);
601 }
602 #endif /* CONFIG_P2P */
603 #ifdef CONFIG_P2P_MANAGER
604 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
605 P2P_MANAGE)
606 pos = hostapd_eid_p2p_manage(hapd, pos);
607 #endif /* CONFIG_P2P_MANAGER */
608
609 #ifdef CONFIG_HS20
610 pos = hostapd_eid_hs20_indication(hapd, pos);
611 #endif /* CONFIG_HS20 */
612
613 pos = hostapd_eid_mbo(hapd, pos, (u8 *) resp + buflen - pos);
614 pos = hostapd_eid_owe_trans(hapd, pos, (u8 *) resp + buflen - pos);
615
616 if (hapd->conf->vendor_elements) {
617 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
618 wpabuf_len(hapd->conf->vendor_elements));
619 pos += wpabuf_len(hapd->conf->vendor_elements);
620 }
621
622 *resp_len = pos - (u8 *) resp;
623 return (u8 *) resp;
624 }
625
626
627 enum ssid_match_result {
628 NO_SSID_MATCH,
629 EXACT_SSID_MATCH,
630 WILDCARD_SSID_MATCH
631 };
632
633 static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
634 const u8 *ssid, size_t ssid_len,
635 const u8 *ssid_list,
636 size_t ssid_list_len,
637 const u8 *short_ssid_list,
638 size_t short_ssid_list_len)
639 {
640 const u8 *pos, *end;
641 int wildcard = 0;
642
643 if (ssid_len == 0)
644 wildcard = 1;
645 if (ssid_len == hapd->conf->ssid.ssid_len &&
646 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
647 return EXACT_SSID_MATCH;
648
649 if (ssid_list) {
650 pos = ssid_list;
651 end = ssid_list + ssid_list_len;
652 while (end - pos >= 2) {
653 if (2 + pos[1] > end - pos)
654 break;
655 if (pos[1] == 0)
656 wildcard = 1;
657 if (pos[1] == hapd->conf->ssid.ssid_len &&
658 os_memcmp(pos + 2, hapd->conf->ssid.ssid,
659 pos[1]) == 0)
660 return EXACT_SSID_MATCH;
661 pos += 2 + pos[1];
662 }
663 }
664
665 if (short_ssid_list) {
666 pos = short_ssid_list;
667 end = short_ssid_list + short_ssid_list_len;
668 while (end - pos >= 4) {
669 if (hapd->conf->ssid.short_ssid == WPA_GET_LE32(pos))
670 return EXACT_SSID_MATCH;
671 pos += 4;
672 }
673 }
674
675 return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
676 }
677
678
679 void sta_track_expire(struct hostapd_iface *iface, int force)
680 {
681 struct os_reltime now;
682 struct hostapd_sta_info *info;
683
684 if (!iface->num_sta_seen)
685 return;
686
687 os_get_reltime(&now);
688 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
689 list))) {
690 if (!force &&
691 !os_reltime_expired(&now, &info->last_seen,
692 iface->conf->track_sta_max_age))
693 break;
694 force = 0;
695
696 wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
697 MACSTR, iface->bss[0]->conf->iface,
698 MAC2STR(info->addr));
699 dl_list_del(&info->list);
700 iface->num_sta_seen--;
701 sta_track_del(info);
702 }
703 }
704
705
706 static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
707 const u8 *addr)
708 {
709 struct hostapd_sta_info *info;
710
711 dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
712 if (os_memcmp(addr, info->addr, ETH_ALEN) == 0)
713 return info;
714
715 return NULL;
716 }
717
718
719 void sta_track_add(struct hostapd_iface *iface, const u8 *addr, int ssi_signal)
720 {
721 struct hostapd_sta_info *info;
722
723 info = sta_track_get(iface, addr);
724 if (info) {
725 /* Move the most recent entry to the end of the list */
726 dl_list_del(&info->list);
727 dl_list_add_tail(&iface->sta_seen, &info->list);
728 os_get_reltime(&info->last_seen);
729 info->ssi_signal = ssi_signal;
730 return;
731 }
732
733 /* Add a new entry */
734 info = os_zalloc(sizeof(*info));
735 if (info == NULL)
736 return;
737 os_memcpy(info->addr, addr, ETH_ALEN);
738 os_get_reltime(&info->last_seen);
739 info->ssi_signal = ssi_signal;
740
741 if (iface->num_sta_seen >= iface->conf->track_sta_max_num) {
742 /* Expire oldest entry to make room for a new one */
743 sta_track_expire(iface, 1);
744 }
745
746 wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
747 MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr));
748 dl_list_add_tail(&iface->sta_seen, &info->list);
749 iface->num_sta_seen++;
750 }
751
752
753 struct hostapd_data *
754 sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
755 const char *ifname)
756 {
757 struct hapd_interfaces *interfaces = iface->interfaces;
758 size_t i, j;
759
760 for (i = 0; i < interfaces->count; i++) {
761 struct hostapd_data *hapd = NULL;
762
763 iface = interfaces->iface[i];
764 for (j = 0; j < iface->num_bss; j++) {
765 hapd = iface->bss[j];
766 if (os_strcmp(ifname, hapd->conf->iface) == 0)
767 break;
768 hapd = NULL;
769 }
770
771 if (hapd && sta_track_get(iface, addr))
772 return hapd;
773 }
774
775 return NULL;
776 }
777
778
779 #ifdef CONFIG_TAXONOMY
780 void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr,
781 struct wpabuf **probe_ie_taxonomy)
782 {
783 struct hostapd_sta_info *info;
784
785 info = sta_track_get(iface, addr);
786 if (!info)
787 return;
788
789 wpabuf_free(*probe_ie_taxonomy);
790 *probe_ie_taxonomy = info->probe_ie_taxonomy;
791 info->probe_ie_taxonomy = NULL;
792 }
793 #endif /* CONFIG_TAXONOMY */
794
795
796 void handle_probe_req(struct hostapd_data *hapd,
797 const struct ieee80211_mgmt *mgmt, size_t len,
798 int ssi_signal)
799 {
800 u8 *resp;
801 struct ieee802_11_elems elems;
802 const u8 *ie;
803 size_t ie_len;
804 size_t i, resp_len;
805 int noack;
806 enum ssid_match_result res;
807 int ret;
808 u16 csa_offs[2];
809 size_t csa_offs_len;
810 struct radius_sta rad_info;
811
812 if (len < IEEE80211_HDRLEN)
813 return;
814 ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN;
815 if (hapd->iconf->track_sta_max_num)
816 sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
817 ie_len = len - IEEE80211_HDRLEN;
818
819 ret = hostapd_allowed_address(hapd, mgmt->sa, (const u8 *) mgmt, len,
820 &rad_info, 1);
821 if (ret == HOSTAPD_ACL_REJECT) {
822 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
823 "Ignore Probe Request frame from " MACSTR
824 " due to ACL reject ", MAC2STR(mgmt->sa));
825 return;
826 }
827
828 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
829 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
830 mgmt->sa, mgmt->da, mgmt->bssid,
831 ie, ie_len, ssi_signal) > 0)
832 return;
833
834 if (!hapd->conf->send_probe_response)
835 return;
836
837 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
838 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
839 MAC2STR(mgmt->sa));
840 return;
841 }
842
843 if ((!elems.ssid || !elems.supp_rates)) {
844 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
845 "without SSID or supported rates element",
846 MAC2STR(mgmt->sa));
847 return;
848 }
849
850 /*
851 * No need to reply if the Probe Request frame was sent on an adjacent
852 * channel. IEEE Std 802.11-2012 describes this as a requirement for an
853 * AP with dot11RadioMeasurementActivated set to true, but strictly
854 * speaking does not allow such ignoring of Probe Request frames if
855 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
856 * number of unnecessary Probe Response frames for cases where the STA
857 * is less likely to see them (Probe Request frame sent on a
858 * neighboring, but partially overlapping, channel).
859 */
860 if (elems.ds_params &&
861 hapd->iface->current_mode &&
862 (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
863 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
864 hapd->iconf->channel != elems.ds_params[0]) {
865 wpa_printf(MSG_DEBUG,
866 "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
867 hapd->iconf->channel, elems.ds_params[0]);
868 return;
869 }
870
871 #ifdef CONFIG_P2P
872 if (hapd->p2p && hapd->p2p_group && elems.wps_ie) {
873 struct wpabuf *wps;
874 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
875 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
876 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
877 "due to mismatch with Requested Device "
878 "Type");
879 wpabuf_free(wps);
880 return;
881 }
882 wpabuf_free(wps);
883 }
884
885 if (hapd->p2p && hapd->p2p_group && elems.p2p) {
886 struct wpabuf *p2p;
887 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
888 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
889 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
890 "due to mismatch with Device ID");
891 wpabuf_free(p2p);
892 return;
893 }
894 wpabuf_free(p2p);
895 }
896 #endif /* CONFIG_P2P */
897
898 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
899 elems.ssid_list_len == 0 && elems.short_ssid_list_len == 0) {
900 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
901 "broadcast SSID ignored", MAC2STR(mgmt->sa));
902 return;
903 }
904
905 #ifdef CONFIG_P2P
906 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
907 elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
908 os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
909 P2P_WILDCARD_SSID_LEN) == 0) {
910 /* Process P2P Wildcard SSID like Wildcard SSID */
911 elems.ssid_len = 0;
912 }
913 #endif /* CONFIG_P2P */
914
915 #ifdef CONFIG_TAXONOMY
916 {
917 struct sta_info *sta;
918 struct hostapd_sta_info *info;
919
920 if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) {
921 taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len);
922 } else if ((info = sta_track_get(hapd->iface,
923 mgmt->sa)) != NULL) {
924 taxonomy_hostapd_sta_info_probe_req(hapd, info,
925 ie, ie_len);
926 }
927 }
928 #endif /* CONFIG_TAXONOMY */
929
930 res = ssid_match(hapd, elems.ssid, elems.ssid_len,
931 elems.ssid_list, elems.ssid_list_len,
932 elems.short_ssid_list, elems.short_ssid_list_len);
933 if (res == NO_SSID_MATCH) {
934 if (!(mgmt->da[0] & 0x01)) {
935 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
936 " for foreign SSID '%s' (DA " MACSTR ")%s",
937 MAC2STR(mgmt->sa),
938 wpa_ssid_txt(elems.ssid, elems.ssid_len),
939 MAC2STR(mgmt->da),
940 elems.ssid_list ? " (SSID list)" : "");
941 }
942 return;
943 }
944
945 if (hapd->conf->ignore_broadcast_ssid && res == WILDCARD_SSID_MATCH) {
946 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
947 "broadcast SSID ignored", MAC2STR(mgmt->sa));
948 return;
949 }
950
951 #ifdef CONFIG_INTERWORKING
952 if (hapd->conf->interworking &&
953 elems.interworking && elems.interworking_len >= 1) {
954 u8 ant = elems.interworking[0] & 0x0f;
955 if (ant != INTERWORKING_ANT_WILDCARD &&
956 ant != hapd->conf->access_network_type) {
957 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
958 " for mismatching ANT %u ignored",
959 MAC2STR(mgmt->sa), ant);
960 return;
961 }
962 }
963
964 if (hapd->conf->interworking && elems.interworking &&
965 (elems.interworking_len == 7 || elems.interworking_len == 9)) {
966 const u8 *hessid;
967 if (elems.interworking_len == 7)
968 hessid = elems.interworking + 1;
969 else
970 hessid = elems.interworking + 1 + 2;
971 if (!is_broadcast_ether_addr(hessid) &&
972 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
973 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
974 " for mismatching HESSID " MACSTR
975 " ignored",
976 MAC2STR(mgmt->sa), MAC2STR(hessid));
977 return;
978 }
979 }
980 #endif /* CONFIG_INTERWORKING */
981
982 #ifdef CONFIG_P2P
983 if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
984 supp_rates_11b_only(&elems)) {
985 /* Indicates support for 11b rates only */
986 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
987 MACSTR " with only 802.11b rates",
988 MAC2STR(mgmt->sa));
989 return;
990 }
991 #endif /* CONFIG_P2P */
992
993 /* TODO: verify that supp_rates contains at least one matching rate
994 * with AP configuration */
995
996 if (hapd->conf->no_probe_resp_if_seen_on &&
997 is_multicast_ether_addr(mgmt->da) &&
998 is_multicast_ether_addr(mgmt->bssid) &&
999 sta_track_seen_on(hapd->iface, mgmt->sa,
1000 hapd->conf->no_probe_resp_if_seen_on)) {
1001 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1002 " since STA has been seen on %s",
1003 hapd->conf->iface, MAC2STR(mgmt->sa),
1004 hapd->conf->no_probe_resp_if_seen_on);
1005 return;
1006 }
1007
1008 if (hapd->conf->no_probe_resp_if_max_sta &&
1009 is_multicast_ether_addr(mgmt->da) &&
1010 is_multicast_ether_addr(mgmt->bssid) &&
1011 hapd->num_sta >= hapd->conf->max_num_sta &&
1012 !ap_get_sta(hapd, mgmt->sa)) {
1013 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
1014 " since no room for additional STA",
1015 hapd->conf->iface, MAC2STR(mgmt->sa));
1016 return;
1017 }
1018
1019 #ifdef CONFIG_TESTING_OPTIONS
1020 if (hapd->iconf->ignore_probe_probability > 0.0 &&
1021 drand48() < hapd->iconf->ignore_probe_probability) {
1022 wpa_printf(MSG_INFO,
1023 "TESTING: ignoring probe request from " MACSTR,
1024 MAC2STR(mgmt->sa));
1025 return;
1026 }
1027 #endif /* CONFIG_TESTING_OPTIONS */
1028
1029 wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, RX_PROBE_REQUEST "sa=" MACSTR
1030 " signal=%d", MAC2STR(mgmt->sa), ssi_signal);
1031
1032 resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL,
1033 &resp_len);
1034 if (resp == NULL)
1035 return;
1036
1037 /*
1038 * If this is a broadcast probe request, apply no ack policy to avoid
1039 * excessive retries.
1040 */
1041 noack = !!(res == WILDCARD_SSID_MATCH &&
1042 is_broadcast_ether_addr(mgmt->da));
1043
1044 csa_offs_len = 0;
1045 if (hapd->csa_in_progress) {
1046 if (hapd->cs_c_off_proberesp)
1047 csa_offs[csa_offs_len++] =
1048 hapd->cs_c_off_proberesp;
1049
1050 if (hapd->cs_c_off_ecsa_proberesp)
1051 csa_offs[csa_offs_len++] =
1052 hapd->cs_c_off_ecsa_proberesp;
1053 }
1054
1055 ret = hostapd_drv_send_mlme(hapd, resp, resp_len, noack,
1056 csa_offs_len ? csa_offs : NULL,
1057 csa_offs_len, 0);
1058
1059 if (ret < 0)
1060 wpa_printf(MSG_INFO, "handle_probe_req: send failed");
1061
1062 os_free(resp);
1063
1064 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
1065 "SSID", MAC2STR(mgmt->sa),
1066 elems.ssid_len == 0 ? "broadcast" : "our");
1067 }
1068
1069
1070 static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
1071 size_t *resp_len)
1072 {
1073 /* check probe response offloading caps and print warnings */
1074 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
1075 return NULL;
1076
1077 #ifdef CONFIG_WPS
1078 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
1079 (!(hapd->iface->probe_resp_offloads &
1080 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
1081 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
1082 wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
1083 "Probe Response while not supporting this");
1084 #endif /* CONFIG_WPS */
1085
1086 #ifdef CONFIG_P2P
1087 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
1088 !(hapd->iface->probe_resp_offloads &
1089 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
1090 wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
1091 "Probe Response while not supporting this");
1092 #endif /* CONFIG_P2P */
1093
1094 if (hapd->conf->interworking &&
1095 !(hapd->iface->probe_resp_offloads &
1096 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
1097 wpa_printf(MSG_WARNING, "Device is trying to offload "
1098 "Interworking Probe Response while not supporting "
1099 "this");
1100
1101 /* Generate a Probe Response template for the non-P2P case */
1102 return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len);
1103 }
1104
1105 #endif /* NEED_AP_MLME */
1106
1107
1108 void sta_track_del(struct hostapd_sta_info *info)
1109 {
1110 #ifdef CONFIG_TAXONOMY
1111 wpabuf_free(info->probe_ie_taxonomy);
1112 info->probe_ie_taxonomy = NULL;
1113 #endif /* CONFIG_TAXONOMY */
1114 os_free(info);
1115 }
1116
1117
1118 int ieee802_11_build_ap_params(struct hostapd_data *hapd,
1119 struct wpa_driver_ap_params *params)
1120 {
1121 struct ieee80211_mgmt *head = NULL;
1122 u8 *tail = NULL;
1123 size_t head_len = 0, tail_len = 0;
1124 u8 *resp = NULL;
1125 size_t resp_len = 0;
1126 #ifdef NEED_AP_MLME
1127 u16 capab_info;
1128 u8 *pos, *tailpos, *tailend, *csa_pos;
1129
1130 #define BEACON_HEAD_BUF_SIZE 256
1131 #define BEACON_TAIL_BUF_SIZE 512
1132 head = os_zalloc(BEACON_HEAD_BUF_SIZE);
1133 tail_len = BEACON_TAIL_BUF_SIZE;
1134 #ifdef CONFIG_WPS
1135 if (hapd->conf->wps_state && hapd->wps_beacon_ie)
1136 tail_len += wpabuf_len(hapd->wps_beacon_ie);
1137 #endif /* CONFIG_WPS */
1138 #ifdef CONFIG_P2P
1139 if (hapd->p2p_beacon_ie)
1140 tail_len += wpabuf_len(hapd->p2p_beacon_ie);
1141 #endif /* CONFIG_P2P */
1142 #ifdef CONFIG_FST
1143 if (hapd->iface->fst_ies)
1144 tail_len += wpabuf_len(hapd->iface->fst_ies);
1145 #endif /* CONFIG_FST */
1146 if (hapd->conf->vendor_elements)
1147 tail_len += wpabuf_len(hapd->conf->vendor_elements);
1148
1149 #ifdef CONFIG_IEEE80211AC
1150 if (hapd->conf->vendor_vht) {
1151 tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
1152 2 + sizeof(struct ieee80211_vht_operation);
1153 }
1154 #endif /* CONFIG_IEEE80211AC */
1155
1156 #ifdef CONFIG_IEEE80211AX
1157 if (hapd->iconf->ieee80211ax) {
1158 tail_len += 3 + sizeof(struct ieee80211_he_capabilities) +
1159 3 + sizeof(struct ieee80211_he_operation) +
1160 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) +
1161 3 + sizeof(struct ieee80211_spatial_reuse);
1162 }
1163 #endif /* CONFIG_IEEE80211AX */
1164
1165 tail_len += hostapd_mbo_ie_len(hapd);
1166 tail_len += hostapd_eid_owe_trans_len(hapd);
1167
1168 tailpos = tail = os_malloc(tail_len);
1169 if (head == NULL || tail == NULL) {
1170 wpa_printf(MSG_ERROR, "Failed to set beacon data");
1171 os_free(head);
1172 os_free(tail);
1173 return -1;
1174 }
1175 tailend = tail + tail_len;
1176
1177 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1178 WLAN_FC_STYPE_BEACON);
1179 head->duration = host_to_le16(0);
1180 os_memset(head->da, 0xff, ETH_ALEN);
1181
1182 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
1183 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
1184 head->u.beacon.beacon_int =
1185 host_to_le16(hapd->iconf->beacon_int);
1186
1187 /* hardware or low-level driver will setup seq_ctrl and timestamp */
1188 capab_info = hostapd_own_capab_info(hapd);
1189 head->u.beacon.capab_info = host_to_le16(capab_info);
1190 pos = &head->u.beacon.variable[0];
1191
1192 /* SSID */
1193 *pos++ = WLAN_EID_SSID;
1194 if (hapd->conf->ignore_broadcast_ssid == 2) {
1195 /* clear the data, but keep the correct length of the SSID */
1196 *pos++ = hapd->conf->ssid.ssid_len;
1197 os_memset(pos, 0, hapd->conf->ssid.ssid_len);
1198 pos += hapd->conf->ssid.ssid_len;
1199 } else if (hapd->conf->ignore_broadcast_ssid) {
1200 *pos++ = 0; /* empty SSID */
1201 } else {
1202 *pos++ = hapd->conf->ssid.ssid_len;
1203 os_memcpy(pos, hapd->conf->ssid.ssid,
1204 hapd->conf->ssid.ssid_len);
1205 pos += hapd->conf->ssid.ssid_len;
1206 }
1207
1208 /* Supported rates */
1209 pos = hostapd_eid_supp_rates(hapd, pos);
1210
1211 /* DS Params */
1212 pos = hostapd_eid_ds_params(hapd, pos);
1213
1214 head_len = pos - (u8 *) head;
1215
1216 tailpos = hostapd_eid_country(hapd, tailpos, tailend - tailpos);
1217
1218 /* Power Constraint element */
1219 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
1220
1221 /* CSA IE */
1222 csa_pos = hostapd_eid_csa(hapd, tailpos);
1223 if (csa_pos != tailpos)
1224 hapd->cs_c_off_beacon = csa_pos - tail - 1;
1225 tailpos = csa_pos;
1226
1227 /* ERP Information element */
1228 tailpos = hostapd_eid_erp_info(hapd, tailpos);
1229
1230 /* Extended supported rates */
1231 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
1232
1233 tailpos = hostapd_get_rsne(hapd, tailpos, tailend - tailpos);
1234 tailpos = hostapd_eid_bss_load(hapd, tailpos, tailend - tailpos);
1235 tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
1236 tailend - tailpos);
1237 tailpos = hostapd_get_mde(hapd, tailpos, tailend - tailpos);
1238
1239 /* eCSA IE */
1240 csa_pos = hostapd_eid_ecsa(hapd, tailpos);
1241 if (csa_pos != tailpos)
1242 hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1;
1243 tailpos = csa_pos;
1244
1245 tailpos = hostapd_eid_supported_op_classes(hapd, tailpos);
1246 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
1247 tailpos = hostapd_eid_ht_operation(hapd, tailpos);
1248
1249 tailpos = hostapd_eid_ext_capab(hapd, tailpos);
1250
1251 /*
1252 * TODO: Time Advertisement element should only be included in some
1253 * DTIM Beacon frames.
1254 */
1255 tailpos = hostapd_eid_time_adv(hapd, tailpos);
1256
1257 tailpos = hostapd_eid_interworking(hapd, tailpos);
1258 tailpos = hostapd_eid_adv_proto(hapd, tailpos);
1259 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
1260
1261 #ifdef CONFIG_FST
1262 if (hapd->iface->fst_ies) {
1263 os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies),
1264 wpabuf_len(hapd->iface->fst_ies));
1265 tailpos += wpabuf_len(hapd->iface->fst_ies);
1266 }
1267 #endif /* CONFIG_FST */
1268
1269 #ifdef CONFIG_IEEE80211AC
1270 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
1271 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0);
1272 tailpos = hostapd_eid_vht_operation(hapd, tailpos);
1273 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
1274 tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos);
1275 }
1276 #endif /* CONFIG_IEEE80211AC */
1277
1278 tailpos = hostapd_eid_fils_indic(hapd, tailpos, 0);
1279 tailpos = hostapd_get_rsnxe(hapd, tailpos, tailend - tailpos);
1280
1281 #ifdef CONFIG_IEEE80211AX
1282 if (hapd->iconf->ieee80211ax) {
1283 tailpos = hostapd_eid_he_capab(hapd, tailpos,
1284 IEEE80211_MODE_AP);
1285 tailpos = hostapd_eid_he_operation(hapd, tailpos);
1286 tailpos = hostapd_eid_spatial_reuse(hapd, tailpos);
1287 tailpos = hostapd_eid_he_mu_edca_parameter_set(hapd, tailpos);
1288 }
1289 #endif /* CONFIG_IEEE80211AX */
1290
1291 #ifdef CONFIG_IEEE80211AC
1292 if (hapd->conf->vendor_vht)
1293 tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
1294 #endif /* CONFIG_IEEE80211AC */
1295
1296 /* WPA / OSEN */
1297 tailpos = hostapd_get_wpa_ie(hapd, tailpos, tailend - tailpos);
1298 tailpos = hostapd_get_osen_ie(hapd, tailpos, tailend - tailpos);
1299
1300 /* Wi-Fi Alliance WMM */
1301 tailpos = hostapd_eid_wmm(hapd, tailpos);
1302
1303 #ifdef CONFIG_WPS
1304 if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
1305 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
1306 wpabuf_len(hapd->wps_beacon_ie));
1307 tailpos += wpabuf_len(hapd->wps_beacon_ie);
1308 }
1309 #endif /* CONFIG_WPS */
1310
1311 #ifdef CONFIG_P2P
1312 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
1313 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
1314 wpabuf_len(hapd->p2p_beacon_ie));
1315 tailpos += wpabuf_len(hapd->p2p_beacon_ie);
1316 }
1317 #endif /* CONFIG_P2P */
1318 #ifdef CONFIG_P2P_MANAGER
1319 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
1320 P2P_MANAGE)
1321 tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
1322 #endif /* CONFIG_P2P_MANAGER */
1323
1324 #ifdef CONFIG_HS20
1325 tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
1326 #endif /* CONFIG_HS20 */
1327
1328 tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos);
1329 tailpos = hostapd_eid_owe_trans(hapd, tailpos,
1330 tail + tail_len - tailpos);
1331
1332 if (hapd->conf->vendor_elements) {
1333 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
1334 wpabuf_len(hapd->conf->vendor_elements));
1335 tailpos += wpabuf_len(hapd->conf->vendor_elements);
1336 }
1337
1338 tail_len = tailpos > tail ? tailpos - tail : 0;
1339
1340 resp = hostapd_probe_resp_offloads(hapd, &resp_len);
1341 #endif /* NEED_AP_MLME */
1342
1343 os_memset(params, 0, sizeof(*params));
1344 params->head = (u8 *) head;
1345 params->head_len = head_len;
1346 params->tail = tail;
1347 params->tail_len = tail_len;
1348 params->proberesp = resp;
1349 params->proberesp_len = resp_len;
1350 params->dtim_period = hapd->conf->dtim_period;
1351 params->beacon_int = hapd->iconf->beacon_int;
1352 params->basic_rates = hapd->iface->basic_rates;
1353 params->beacon_rate = hapd->iconf->beacon_rate;
1354 params->rate_type = hapd->iconf->rate_type;
1355 params->ssid = hapd->conf->ssid.ssid;
1356 params->ssid_len = hapd->conf->ssid.ssid_len;
1357 if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
1358 (WPA_PROTO_WPA | WPA_PROTO_RSN))
1359 params->pairwise_ciphers = hapd->conf->wpa_pairwise |
1360 hapd->conf->rsn_pairwise;
1361 else if (hapd->conf->wpa & WPA_PROTO_RSN)
1362 params->pairwise_ciphers = hapd->conf->rsn_pairwise;
1363 else if (hapd->conf->wpa & WPA_PROTO_WPA)
1364 params->pairwise_ciphers = hapd->conf->wpa_pairwise;
1365 params->group_cipher = hapd->conf->wpa_group;
1366 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
1367 params->auth_algs = hapd->conf->auth_algs;
1368 params->wpa_version = hapd->conf->wpa;
1369 params->privacy = hapd->conf->wpa;
1370 #ifdef CONFIG_WEP
1371 params->privacy |= hapd->conf->ssid.wep.keys_set ||
1372 (hapd->conf->ieee802_1x &&
1373 (hapd->conf->default_wep_key_len ||
1374 hapd->conf->individual_wep_key_len));
1375 #endif /* CONFIG_WEP */
1376 switch (hapd->conf->ignore_broadcast_ssid) {
1377 case 0:
1378 params->hide_ssid = NO_SSID_HIDING;
1379 break;
1380 case 1:
1381 params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
1382 break;
1383 case 2:
1384 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
1385 break;
1386 }
1387 params->isolate = hapd->conf->isolate;
1388 #ifdef NEED_AP_MLME
1389 params->cts_protect = !!(ieee802_11_erp_info(hapd) &
1390 ERP_INFO_USE_PROTECTION);
1391 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
1392 hapd->iconf->preamble == SHORT_PREAMBLE;
1393 if (hapd->iface->current_mode &&
1394 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1395 params->short_slot_time =
1396 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
1397 else
1398 params->short_slot_time = -1;
1399 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
1400 params->ht_opmode = -1;
1401 else
1402 params->ht_opmode = hapd->iface->ht_op_mode;
1403 #endif /* NEED_AP_MLME */
1404 params->interworking = hapd->conf->interworking;
1405 if (hapd->conf->interworking &&
1406 !is_zero_ether_addr(hapd->conf->hessid))
1407 params->hessid = hapd->conf->hessid;
1408 params->access_network_type = hapd->conf->access_network_type;
1409 params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
1410 #ifdef CONFIG_P2P
1411 params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
1412 #endif /* CONFIG_P2P */
1413 #ifdef CONFIG_HS20
1414 params->disable_dgaf = hapd->conf->disable_dgaf;
1415 if (hapd->conf->osen) {
1416 params->privacy = 1;
1417 params->osen = 1;
1418 }
1419 #endif /* CONFIG_HS20 */
1420 params->multicast_to_unicast = hapd->conf->multicast_to_unicast;
1421 params->pbss = hapd->conf->pbss;
1422
1423 if (hapd->conf->ftm_responder) {
1424 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_FTM_RESPONDER) {
1425 params->ftm_responder = 1;
1426 params->lci = hapd->iface->conf->lci;
1427 params->civic = hapd->iface->conf->civic;
1428 } else {
1429 wpa_printf(MSG_WARNING,
1430 "Not configuring FTM responder as the driver doesn't advertise support for it");
1431 }
1432 }
1433
1434 return 0;
1435 }
1436
1437
1438 void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
1439 {
1440 os_free(params->tail);
1441 params->tail = NULL;
1442 os_free(params->head);
1443 params->head = NULL;
1444 os_free(params->proberesp);
1445 params->proberesp = NULL;
1446 }
1447
1448
1449 int ieee802_11_set_beacon(struct hostapd_data *hapd)
1450 {
1451 struct wpa_driver_ap_params params;
1452 struct hostapd_freq_params freq;
1453 struct hostapd_iface *iface = hapd->iface;
1454 struct hostapd_config *iconf = iface->conf;
1455 struct hostapd_hw_modes *cmode = iface->current_mode;
1456 struct wpabuf *beacon, *proberesp, *assocresp;
1457 int res, ret = -1;
1458
1459 if (hapd->csa_in_progress) {
1460 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
1461 return -1;
1462 }
1463
1464 hapd->beacon_set_done = 1;
1465
1466 if (ieee802_11_build_ap_params(hapd, &params) < 0)
1467 return -1;
1468
1469 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
1470 0)
1471 goto fail;
1472
1473 params.beacon_ies = beacon;
1474 params.proberesp_ies = proberesp;
1475 params.assocresp_ies = assocresp;
1476 params.reenable = hapd->reenable_beacon;
1477 #ifdef CONFIG_IEEE80211AX
1478 params.he_spr = !!hapd->iface->conf->spr.sr_control;
1479 params.he_spr_srg_obss_pd_min_offset =
1480 hapd->iface->conf->spr.srg_obss_pd_min_offset;
1481 params.he_spr_srg_obss_pd_max_offset =
1482 hapd->iface->conf->spr.srg_obss_pd_max_offset;
1483 params.he_bss_color_disabled =
1484 hapd->iface->conf->he_op.he_bss_color_disabled;
1485 params.he_bss_color_partial =
1486 hapd->iface->conf->he_op.he_bss_color_partial;
1487 params.he_bss_color = hapd->iface->conf->he_op.he_bss_color;
1488 params.twt_responder = hostapd_get_he_twt_responder(hapd,
1489 IEEE80211_MODE_AP);
1490 #endif /* CONFIG_IEEE80211AX */
1491 hapd->reenable_beacon = 0;
1492
1493 if (cmode &&
1494 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
1495 iconf->channel, iconf->enable_edmg,
1496 iconf->edmg_channel, iconf->ieee80211n,
1497 iconf->ieee80211ac, iconf->ieee80211ax,
1498 iconf->secondary_channel,
1499 hostapd_get_oper_chwidth(iconf),
1500 hostapd_get_oper_centr_freq_seg0_idx(iconf),
1501 hostapd_get_oper_centr_freq_seg1_idx(iconf),
1502 cmode->vht_capab,
1503 &cmode->he_capab[IEEE80211_MODE_AP]) == 0)
1504 params.freq = &freq;
1505
1506 res = hostapd_drv_set_ap(hapd, &params);
1507 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
1508 if (res)
1509 wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
1510 else
1511 ret = 0;
1512 fail:
1513 ieee802_11_free_ap_params(&params);
1514 return ret;
1515 }
1516
1517
1518 int ieee802_11_set_beacons(struct hostapd_iface *iface)
1519 {
1520 size_t i;
1521 int ret = 0;
1522
1523 for (i = 0; i < iface->num_bss; i++) {
1524 if (iface->bss[i]->started &&
1525 ieee802_11_set_beacon(iface->bss[i]) < 0)
1526 ret = -1;
1527 }
1528
1529 return ret;
1530 }
1531
1532
1533 /* only update beacons if started */
1534 int ieee802_11_update_beacons(struct hostapd_iface *iface)
1535 {
1536 size_t i;
1537 int ret = 0;
1538
1539 for (i = 0; i < iface->num_bss; i++) {
1540 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
1541 ieee802_11_set_beacon(iface->bss[i]) < 0)
1542 ret = -1;
1543 }
1544
1545 return ret;
1546 }
1547
1548 #endif /* CONFIG_NATIVE_WINDOWS */