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