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