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