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 const u8 * hostapd_wpa_ie(struct hostapd_data *hapd, u8 eid) 270 { 271 const u8 *ies; 272 size_t ies_len; 273 274 ies = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ies_len); 275 if (!ies) 276 return NULL; 277 278 return get_ie(ies, ies_len, eid); 279 } 280 281 282 static const u8 * hostapd_vendor_wpa_ie(struct hostapd_data *hapd, 283 u32 vendor_type) 284 { 285 const u8 *ies; 286 size_t ies_len; 287 288 ies = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ies_len); 289 if (!ies) 290 return NULL; 291 292 return get_vendor_ie(ies, ies_len, vendor_type); 293 } 294 295 296 static u8 * hostapd_get_rsne(struct hostapd_data *hapd, u8 *pos, size_t len) 297 { 298 const u8 *ie; 299 300 ie = hostapd_wpa_ie(hapd, WLAN_EID_RSN); 301 if (!ie || 2U + ie[1] > len) 302 return pos; 303 304 os_memcpy(pos, ie, 2 + ie[1]); 305 return pos + 2 + ie[1]; 306 } 307 308 309 static u8 * hostapd_get_mde(struct hostapd_data *hapd, u8 *pos, size_t len) 310 { 311 const u8 *ie; 312 313 ie = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN); 314 if (!ie || 2U + ie[1] > len) 315 return pos; 316 317 os_memcpy(pos, ie, 2 + ie[1]); 318 return pos + 2 + ie[1]; 319 } 320 321 322 static u8 * hostapd_get_rsnxe(struct hostapd_data *hapd, u8 *pos, size_t len) 323 { 324 const u8 *ie; 325 326 #ifdef CONFIG_TESTING_OPTIONS 327 if (hapd->conf->no_beacon_rsnxe) { 328 wpa_printf(MSG_INFO, "TESTING: Do not add RSNXE into Beacon"); 329 return pos; 330 } 331 #endif /* CONFIG_TESTING_OPTIONS */ 332 ie = hostapd_wpa_ie(hapd, WLAN_EID_RSNX); 333 if (!ie || 2U + ie[1] > len) 334 return pos; 335 336 os_memcpy(pos, ie, 2 + ie[1]); 337 return pos + 2 + ie[1]; 338 } 339 340 341 static u8 * hostapd_get_wpa_ie(struct hostapd_data *hapd, u8 *pos, size_t len) 342 { 343 const u8 *ie; 344 345 ie = hostapd_vendor_wpa_ie(hapd, WPA_IE_VENDOR_TYPE); 346 if (!ie || 2U + ie[1] > len) 347 return pos; 348 349 os_memcpy(pos, ie, 2 + ie[1]); 350 return pos + 2 + ie[1]; 351 } 352 353 354 static u8 * hostapd_get_osen_ie(struct hostapd_data *hapd, u8 *pos, size_t len) 355 { 356 const u8 *ie; 357 358 ie = hostapd_vendor_wpa_ie(hapd, OSEN_IE_VENDOR_TYPE); 359 if (!ie || 2U + ie[1] > len) 360 return pos; 361 362 os_memcpy(pos, ie, 2 + ie[1]); 363 return pos + 2 + ie[1]; 364 } 365 366 367 static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid) 368 { 369 #ifdef CONFIG_TESTING_OPTIONS 370 if (hapd->iface->cs_oper_class && hapd->iconf->ecsa_ie_only) 371 return eid; 372 #endif /* CONFIG_TESTING_OPTIONS */ 373 374 if (!hapd->cs_freq_params.channel) 375 return eid; 376 377 *eid++ = WLAN_EID_CHANNEL_SWITCH; 378 *eid++ = 3; 379 *eid++ = hapd->cs_block_tx; 380 *eid++ = hapd->cs_freq_params.channel; 381 *eid++ = hapd->cs_count; 382 383 return eid; 384 } 385 386 387 static u8 * hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid) 388 { 389 if (!hapd->cs_freq_params.channel || !hapd->iface->cs_oper_class) 390 return eid; 391 392 *eid++ = WLAN_EID_EXT_CHANSWITCH_ANN; 393 *eid++ = 4; 394 *eid++ = hapd->cs_block_tx; 395 *eid++ = hapd->iface->cs_oper_class; 396 *eid++ = hapd->cs_freq_params.channel; 397 *eid++ = hapd->cs_count; 398 399 return eid; 400 } 401 402 403 static u8 * hostapd_eid_supported_op_classes(struct hostapd_data *hapd, u8 *eid) 404 { 405 u8 op_class, channel; 406 407 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) || 408 !hapd->iface->freq) 409 return eid; 410 411 if (ieee80211_freq_to_channel_ext(hapd->iface->freq, 412 hapd->iconf->secondary_channel, 413 hostapd_get_oper_chwidth(hapd->iconf), 414 &op_class, &channel) == 415 NUM_HOSTAPD_MODES) 416 return eid; 417 418 *eid++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES; 419 *eid++ = 2; 420 421 /* Current Operating Class */ 422 *eid++ = op_class; 423 424 /* TODO: Advertise all the supported operating classes */ 425 *eid++ = 0; 426 427 return eid; 428 } 429 430 431 static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd, 432 const struct ieee80211_mgmt *req, 433 int is_p2p, size_t *resp_len) 434 { 435 struct ieee80211_mgmt *resp; 436 u8 *pos, *epos, *csa_pos; 437 size_t buflen; 438 439 #define MAX_PROBERESP_LEN 768 440 buflen = MAX_PROBERESP_LEN; 441 #ifdef CONFIG_WPS 442 if (hapd->wps_probe_resp_ie) 443 buflen += wpabuf_len(hapd->wps_probe_resp_ie); 444 #endif /* CONFIG_WPS */ 445 #ifdef CONFIG_P2P 446 if (hapd->p2p_probe_resp_ie) 447 buflen += wpabuf_len(hapd->p2p_probe_resp_ie); 448 #endif /* CONFIG_P2P */ 449 #ifdef CONFIG_FST 450 if (hapd->iface->fst_ies) 451 buflen += wpabuf_len(hapd->iface->fst_ies); 452 #endif /* CONFIG_FST */ 453 if (hapd->conf->vendor_elements) 454 buflen += wpabuf_len(hapd->conf->vendor_elements); 455 if (hapd->conf->vendor_vht) { 456 buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) + 457 2 + sizeof(struct ieee80211_vht_operation); 458 } 459 460 #ifdef CONFIG_IEEE80211AX 461 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) { 462 buflen += 3 + sizeof(struct ieee80211_he_capabilities) + 463 3 + sizeof(struct ieee80211_he_operation) + 464 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) + 465 3 + sizeof(struct ieee80211_spatial_reuse); 466 if (is_6ghz_op_class(hapd->iconf->op_class)) 467 buflen += sizeof(struct ieee80211_he_6ghz_oper_info) + 468 3 + sizeof(struct ieee80211_he_6ghz_band_cap); 469 } 470 #endif /* CONFIG_IEEE80211AX */ 471 472 buflen += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_PROBE_RESP); 473 buflen += hostapd_mbo_ie_len(hapd); 474 buflen += hostapd_eid_owe_trans_len(hapd); 475 buflen += hostapd_eid_dpp_cc_len(hapd); 476 477 resp = os_zalloc(buflen); 478 if (resp == NULL) 479 return NULL; 480 481 epos = ((u8 *) resp) + MAX_PROBERESP_LEN; 482 483 resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, 484 WLAN_FC_STYPE_PROBE_RESP); 485 if (req) 486 os_memcpy(resp->da, req->sa, ETH_ALEN); 487 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN); 488 489 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN); 490 resp->u.probe_resp.beacon_int = 491 host_to_le16(hapd->iconf->beacon_int); 492 493 /* hardware or low-level driver will setup seq_ctrl and timestamp */ 494 resp->u.probe_resp.capab_info = 495 host_to_le16(hostapd_own_capab_info(hapd)); 496 497 pos = resp->u.probe_resp.variable; 498 *pos++ = WLAN_EID_SSID; 499 *pos++ = hapd->conf->ssid.ssid_len; 500 os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len); 501 pos += hapd->conf->ssid.ssid_len; 502 503 /* Supported rates */ 504 pos = hostapd_eid_supp_rates(hapd, pos); 505 506 /* DS Params */ 507 pos = hostapd_eid_ds_params(hapd, pos); 508 509 pos = hostapd_eid_country(hapd, pos, epos - pos); 510 511 /* Power Constraint element */ 512 pos = hostapd_eid_pwr_constraint(hapd, pos); 513 514 /* CSA IE */ 515 csa_pos = hostapd_eid_csa(hapd, pos); 516 if (csa_pos != pos) 517 hapd->cs_c_off_proberesp = csa_pos - (u8 *) resp - 1; 518 pos = csa_pos; 519 520 /* ERP Information element */ 521 pos = hostapd_eid_erp_info(hapd, pos); 522 523 /* Extended supported rates */ 524 pos = hostapd_eid_ext_supp_rates(hapd, pos); 525 526 pos = hostapd_get_rsne(hapd, pos, epos - pos); 527 pos = hostapd_eid_bss_load(hapd, pos, epos - pos); 528 pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos); 529 pos = hostapd_get_mde(hapd, pos, epos - pos); 530 531 /* eCSA IE */ 532 csa_pos = hostapd_eid_ecsa(hapd, pos); 533 if (csa_pos != pos) 534 hapd->cs_c_off_ecsa_proberesp = csa_pos - (u8 *) resp - 1; 535 pos = csa_pos; 536 537 pos = hostapd_eid_supported_op_classes(hapd, pos); 538 pos = hostapd_eid_ht_capabilities(hapd, pos); 539 pos = hostapd_eid_ht_operation(hapd, pos); 540 541 pos = hostapd_eid_ext_capab(hapd, pos); 542 543 pos = hostapd_eid_time_adv(hapd, pos); 544 pos = hostapd_eid_time_zone(hapd, pos); 545 546 pos = hostapd_eid_interworking(hapd, pos); 547 pos = hostapd_eid_adv_proto(hapd, pos); 548 pos = hostapd_eid_roaming_consortium(hapd, pos); 549 550 #ifdef CONFIG_FST 551 if (hapd->iface->fst_ies) { 552 os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies), 553 wpabuf_len(hapd->iface->fst_ies)); 554 pos += wpabuf_len(hapd->iface->fst_ies); 555 } 556 #endif /* CONFIG_FST */ 557 558 #ifdef CONFIG_IEEE80211AC 559 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac && 560 !is_6ghz_op_class(hapd->iconf->op_class)) { 561 pos = hostapd_eid_vht_capabilities(hapd, pos, 0); 562 pos = hostapd_eid_vht_operation(hapd, pos); 563 pos = hostapd_eid_txpower_envelope(hapd, pos); 564 } 565 #endif /* CONFIG_IEEE80211AC */ 566 567 #ifdef CONFIG_IEEE80211AX 568 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax && 569 is_6ghz_op_class(hapd->iconf->op_class)) 570 pos = hostapd_eid_txpower_envelope(hapd, pos); 571 #endif /* CONFIG_IEEE80211AX */ 572 573 if ((hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) || 574 (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax)) 575 pos = hostapd_eid_wb_chsw_wrapper(hapd, pos); 576 577 pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_PROBE_RESP); 578 pos = hostapd_eid_fils_indic(hapd, pos, 0); 579 pos = hostapd_get_rsnxe(hapd, pos, epos - pos); 580 581 #ifdef CONFIG_IEEE80211AX 582 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) { 583 pos = hostapd_eid_he_capab(hapd, pos, IEEE80211_MODE_AP); 584 pos = hostapd_eid_he_operation(hapd, pos); 585 pos = hostapd_eid_spatial_reuse(hapd, pos); 586 pos = hostapd_eid_he_mu_edca_parameter_set(hapd, pos); 587 pos = hostapd_eid_he_6ghz_band_cap(hapd, pos); 588 } 589 #endif /* CONFIG_IEEE80211AX */ 590 591 #ifdef CONFIG_IEEE80211AC 592 if (hapd->conf->vendor_vht) 593 pos = hostapd_eid_vendor_vht(hapd, pos); 594 #endif /* CONFIG_IEEE80211AC */ 595 596 /* WPA / OSEN */ 597 pos = hostapd_get_wpa_ie(hapd, pos, epos - pos); 598 pos = hostapd_get_osen_ie(hapd, pos, epos - pos); 599 600 /* Wi-Fi Alliance WMM */ 601 pos = hostapd_eid_wmm(hapd, pos); 602 603 #ifdef CONFIG_WPS 604 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) { 605 os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie), 606 wpabuf_len(hapd->wps_probe_resp_ie)); 607 pos += wpabuf_len(hapd->wps_probe_resp_ie); 608 } 609 #endif /* CONFIG_WPS */ 610 611 #ifdef CONFIG_P2P 612 if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p && 613 hapd->p2p_probe_resp_ie) { 614 os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie), 615 wpabuf_len(hapd->p2p_probe_resp_ie)); 616 pos += wpabuf_len(hapd->p2p_probe_resp_ie); 617 } 618 #endif /* CONFIG_P2P */ 619 #ifdef CONFIG_P2P_MANAGER 620 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) == 621 P2P_MANAGE) 622 pos = hostapd_eid_p2p_manage(hapd, pos); 623 #endif /* CONFIG_P2P_MANAGER */ 624 625 #ifdef CONFIG_HS20 626 pos = hostapd_eid_hs20_indication(hapd, pos); 627 #endif /* CONFIG_HS20 */ 628 629 pos = hostapd_eid_mbo(hapd, pos, (u8 *) resp + buflen - pos); 630 pos = hostapd_eid_owe_trans(hapd, pos, (u8 *) resp + buflen - pos); 631 pos = hostapd_eid_dpp_cc(hapd, pos, (u8 *) resp + buflen - pos); 632 633 if (hapd->conf->vendor_elements) { 634 os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements), 635 wpabuf_len(hapd->conf->vendor_elements)); 636 pos += wpabuf_len(hapd->conf->vendor_elements); 637 } 638 639 *resp_len = pos - (u8 *) resp; 640 return (u8 *) resp; 641 } 642 643 644 enum ssid_match_result { 645 NO_SSID_MATCH, 646 EXACT_SSID_MATCH, 647 WILDCARD_SSID_MATCH, 648 CO_LOCATED_SSID_MATCH, 649 }; 650 651 static enum ssid_match_result ssid_match(struct hostapd_data *hapd, 652 const u8 *ssid, size_t ssid_len, 653 const u8 *ssid_list, 654 size_t ssid_list_len, 655 const u8 *short_ssid_list, 656 size_t short_ssid_list_len) 657 { 658 const u8 *pos, *end; 659 struct hostapd_iface *iface = hapd->iface; 660 int wildcard = 0; 661 size_t i, j; 662 663 if (ssid_len == 0) 664 wildcard = 1; 665 if (ssid_len == hapd->conf->ssid.ssid_len && 666 os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0) 667 return EXACT_SSID_MATCH; 668 669 if (ssid_list) { 670 pos = ssid_list; 671 end = ssid_list + ssid_list_len; 672 while (end - pos >= 2) { 673 if (2 + pos[1] > end - pos) 674 break; 675 if (pos[1] == 0) 676 wildcard = 1; 677 if (pos[1] == hapd->conf->ssid.ssid_len && 678 os_memcmp(pos + 2, hapd->conf->ssid.ssid, 679 pos[1]) == 0) 680 return EXACT_SSID_MATCH; 681 pos += 2 + pos[1]; 682 } 683 } 684 685 if (short_ssid_list) { 686 pos = short_ssid_list; 687 end = short_ssid_list + short_ssid_list_len; 688 while (end - pos >= 4) { 689 if (hapd->conf->ssid.short_ssid == WPA_GET_LE32(pos)) 690 return EXACT_SSID_MATCH; 691 pos += 4; 692 } 693 } 694 695 if (wildcard) 696 return WILDCARD_SSID_MATCH; 697 698 if (!iface->interfaces || iface->interfaces->count <= 1 || 699 is_6ghz_op_class(hapd->iconf->op_class)) 700 return NO_SSID_MATCH; 701 702 for (i = 0; i < iface->interfaces->count; i++) { 703 struct hostapd_iface *colocated; 704 705 colocated = iface->interfaces->iface[i]; 706 707 if (colocated == iface || 708 !is_6ghz_op_class(colocated->conf->op_class)) 709 continue; 710 711 for (j = 0; j < colocated->num_bss; j++) { 712 struct hostapd_bss_config *conf; 713 714 conf = colocated->bss[j]->conf; 715 if (ssid_len == conf->ssid.ssid_len && 716 os_memcmp(ssid, conf->ssid.ssid, ssid_len) == 0) 717 return CO_LOCATED_SSID_MATCH; 718 } 719 } 720 721 return NO_SSID_MATCH; 722 } 723 724 725 void sta_track_expire(struct hostapd_iface *iface, int force) 726 { 727 struct os_reltime now; 728 struct hostapd_sta_info *info; 729 730 if (!iface->num_sta_seen) 731 return; 732 733 os_get_reltime(&now); 734 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info, 735 list))) { 736 if (!force && 737 !os_reltime_expired(&now, &info->last_seen, 738 iface->conf->track_sta_max_age)) 739 break; 740 force = 0; 741 742 wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for " 743 MACSTR, iface->bss[0]->conf->iface, 744 MAC2STR(info->addr)); 745 dl_list_del(&info->list); 746 iface->num_sta_seen--; 747 sta_track_del(info); 748 } 749 } 750 751 752 static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface, 753 const u8 *addr) 754 { 755 struct hostapd_sta_info *info; 756 757 dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list) 758 if (os_memcmp(addr, info->addr, ETH_ALEN) == 0) 759 return info; 760 761 return NULL; 762 } 763 764 765 void sta_track_add(struct hostapd_iface *iface, const u8 *addr, int ssi_signal) 766 { 767 struct hostapd_sta_info *info; 768 769 info = sta_track_get(iface, addr); 770 if (info) { 771 /* Move the most recent entry to the end of the list */ 772 dl_list_del(&info->list); 773 dl_list_add_tail(&iface->sta_seen, &info->list); 774 os_get_reltime(&info->last_seen); 775 info->ssi_signal = ssi_signal; 776 return; 777 } 778 779 /* Add a new entry */ 780 info = os_zalloc(sizeof(*info)); 781 if (info == NULL) 782 return; 783 os_memcpy(info->addr, addr, ETH_ALEN); 784 os_get_reltime(&info->last_seen); 785 info->ssi_signal = ssi_signal; 786 787 if (iface->num_sta_seen >= iface->conf->track_sta_max_num) { 788 /* Expire oldest entry to make room for a new one */ 789 sta_track_expire(iface, 1); 790 } 791 792 wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for " 793 MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr)); 794 dl_list_add_tail(&iface->sta_seen, &info->list); 795 iface->num_sta_seen++; 796 } 797 798 799 struct hostapd_data * 800 sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr, 801 const char *ifname) 802 { 803 struct hapd_interfaces *interfaces = iface->interfaces; 804 size_t i, j; 805 806 for (i = 0; i < interfaces->count; i++) { 807 struct hostapd_data *hapd = NULL; 808 809 iface = interfaces->iface[i]; 810 for (j = 0; j < iface->num_bss; j++) { 811 hapd = iface->bss[j]; 812 if (os_strcmp(ifname, hapd->conf->iface) == 0) 813 break; 814 hapd = NULL; 815 } 816 817 if (hapd && sta_track_get(iface, addr)) 818 return hapd; 819 } 820 821 return NULL; 822 } 823 824 825 #ifdef CONFIG_TAXONOMY 826 void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr, 827 struct wpabuf **probe_ie_taxonomy) 828 { 829 struct hostapd_sta_info *info; 830 831 info = sta_track_get(iface, addr); 832 if (!info) 833 return; 834 835 wpabuf_free(*probe_ie_taxonomy); 836 *probe_ie_taxonomy = info->probe_ie_taxonomy; 837 info->probe_ie_taxonomy = NULL; 838 } 839 #endif /* CONFIG_TAXONOMY */ 840 841 842 void handle_probe_req(struct hostapd_data *hapd, 843 const struct ieee80211_mgmt *mgmt, size_t len, 844 int ssi_signal) 845 { 846 u8 *resp; 847 struct ieee802_11_elems elems; 848 const u8 *ie; 849 size_t ie_len; 850 size_t i, resp_len; 851 int noack; 852 enum ssid_match_result res; 853 int ret; 854 u16 csa_offs[2]; 855 size_t csa_offs_len; 856 struct radius_sta rad_info; 857 858 if (hapd->iconf->rssi_ignore_probe_request && ssi_signal && 859 ssi_signal < hapd->iconf->rssi_ignore_probe_request) 860 return; 861 862 if (len < IEEE80211_HDRLEN) 863 return; 864 ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN; 865 if (hapd->iconf->track_sta_max_num) 866 sta_track_add(hapd->iface, mgmt->sa, ssi_signal); 867 ie_len = len - IEEE80211_HDRLEN; 868 869 ret = hostapd_allowed_address(hapd, mgmt->sa, (const u8 *) mgmt, len, 870 &rad_info, 1); 871 if (ret == HOSTAPD_ACL_REJECT) { 872 wpa_msg(hapd->msg_ctx, MSG_DEBUG, 873 "Ignore Probe Request frame from " MACSTR 874 " due to ACL reject ", MAC2STR(mgmt->sa)); 875 return; 876 } 877 878 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) 879 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx, 880 mgmt->sa, mgmt->da, mgmt->bssid, 881 ie, ie_len, ssi_signal) > 0) 882 return; 883 884 if (!hapd->conf->send_probe_response) 885 return; 886 887 if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) { 888 wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR, 889 MAC2STR(mgmt->sa)); 890 return; 891 } 892 893 if ((!elems.ssid || !elems.supp_rates)) { 894 wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request " 895 "without SSID or supported rates element", 896 MAC2STR(mgmt->sa)); 897 return; 898 } 899 900 /* 901 * No need to reply if the Probe Request frame was sent on an adjacent 902 * channel. IEEE Std 802.11-2012 describes this as a requirement for an 903 * AP with dot11RadioMeasurementActivated set to true, but strictly 904 * speaking does not allow such ignoring of Probe Request frames if 905 * dot11RadioMeasurementActivated is false. Anyway, this can help reduce 906 * number of unnecessary Probe Response frames for cases where the STA 907 * is less likely to see them (Probe Request frame sent on a 908 * neighboring, but partially overlapping, channel). 909 */ 910 if (elems.ds_params && 911 hapd->iface->current_mode && 912 (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G || 913 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) && 914 hapd->iconf->channel != elems.ds_params[0]) { 915 wpa_printf(MSG_DEBUG, 916 "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u", 917 hapd->iconf->channel, elems.ds_params[0]); 918 return; 919 } 920 921 #ifdef CONFIG_P2P 922 if (hapd->p2p && hapd->p2p_group && elems.wps_ie) { 923 struct wpabuf *wps; 924 wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA); 925 if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) { 926 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request " 927 "due to mismatch with Requested Device " 928 "Type"); 929 wpabuf_free(wps); 930 return; 931 } 932 wpabuf_free(wps); 933 } 934 935 if (hapd->p2p && hapd->p2p_group && elems.p2p) { 936 struct wpabuf *p2p; 937 p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE); 938 if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) { 939 wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request " 940 "due to mismatch with Device ID"); 941 wpabuf_free(p2p); 942 return; 943 } 944 wpabuf_free(p2p); 945 } 946 #endif /* CONFIG_P2P */ 947 948 if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 && 949 elems.ssid_list_len == 0 && elems.short_ssid_list_len == 0) { 950 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for " 951 "broadcast SSID ignored", MAC2STR(mgmt->sa)); 952 return; 953 } 954 955 #ifdef CONFIG_P2P 956 if ((hapd->conf->p2p & P2P_GROUP_OWNER) && 957 elems.ssid_len == P2P_WILDCARD_SSID_LEN && 958 os_memcmp(elems.ssid, P2P_WILDCARD_SSID, 959 P2P_WILDCARD_SSID_LEN) == 0) { 960 /* Process P2P Wildcard SSID like Wildcard SSID */ 961 elems.ssid_len = 0; 962 } 963 #endif /* CONFIG_P2P */ 964 965 #ifdef CONFIG_TAXONOMY 966 { 967 struct sta_info *sta; 968 struct hostapd_sta_info *info; 969 970 if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) { 971 taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len); 972 } else if ((info = sta_track_get(hapd->iface, 973 mgmt->sa)) != NULL) { 974 taxonomy_hostapd_sta_info_probe_req(hapd, info, 975 ie, ie_len); 976 } 977 } 978 #endif /* CONFIG_TAXONOMY */ 979 980 res = ssid_match(hapd, elems.ssid, elems.ssid_len, 981 elems.ssid_list, elems.ssid_list_len, 982 elems.short_ssid_list, elems.short_ssid_list_len); 983 if (res == NO_SSID_MATCH) { 984 if (!(mgmt->da[0] & 0x01)) { 985 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR 986 " for foreign SSID '%s' (DA " MACSTR ")%s", 987 MAC2STR(mgmt->sa), 988 wpa_ssid_txt(elems.ssid, elems.ssid_len), 989 MAC2STR(mgmt->da), 990 elems.ssid_list ? " (SSID list)" : ""); 991 } 992 return; 993 } 994 995 if (hapd->conf->ignore_broadcast_ssid && res == WILDCARD_SSID_MATCH) { 996 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for " 997 "broadcast SSID ignored", MAC2STR(mgmt->sa)); 998 return; 999 } 1000 1001 #ifdef CONFIG_INTERWORKING 1002 if (hapd->conf->interworking && 1003 elems.interworking && elems.interworking_len >= 1) { 1004 u8 ant = elems.interworking[0] & 0x0f; 1005 if (ant != INTERWORKING_ANT_WILDCARD && 1006 ant != hapd->conf->access_network_type) { 1007 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR 1008 " for mismatching ANT %u ignored", 1009 MAC2STR(mgmt->sa), ant); 1010 return; 1011 } 1012 } 1013 1014 if (hapd->conf->interworking && elems.interworking && 1015 (elems.interworking_len == 7 || elems.interworking_len == 9)) { 1016 const u8 *hessid; 1017 if (elems.interworking_len == 7) 1018 hessid = elems.interworking + 1; 1019 else 1020 hessid = elems.interworking + 1 + 2; 1021 if (!is_broadcast_ether_addr(hessid) && 1022 os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) { 1023 wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR 1024 " for mismatching HESSID " MACSTR 1025 " ignored", 1026 MAC2STR(mgmt->sa), MAC2STR(hessid)); 1027 return; 1028 } 1029 } 1030 #endif /* CONFIG_INTERWORKING */ 1031 1032 #ifdef CONFIG_P2P 1033 if ((hapd->conf->p2p & P2P_GROUP_OWNER) && 1034 supp_rates_11b_only(&elems)) { 1035 /* Indicates support for 11b rates only */ 1036 wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from " 1037 MACSTR " with only 802.11b rates", 1038 MAC2STR(mgmt->sa)); 1039 return; 1040 } 1041 #endif /* CONFIG_P2P */ 1042 1043 /* TODO: verify that supp_rates contains at least one matching rate 1044 * with AP configuration */ 1045 1046 if (hapd->conf->no_probe_resp_if_seen_on && 1047 is_multicast_ether_addr(mgmt->da) && 1048 is_multicast_ether_addr(mgmt->bssid) && 1049 sta_track_seen_on(hapd->iface, mgmt->sa, 1050 hapd->conf->no_probe_resp_if_seen_on)) { 1051 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR 1052 " since STA has been seen on %s", 1053 hapd->conf->iface, MAC2STR(mgmt->sa), 1054 hapd->conf->no_probe_resp_if_seen_on); 1055 return; 1056 } 1057 1058 if (hapd->conf->no_probe_resp_if_max_sta && 1059 is_multicast_ether_addr(mgmt->da) && 1060 is_multicast_ether_addr(mgmt->bssid) && 1061 hapd->num_sta >= hapd->conf->max_num_sta && 1062 !ap_get_sta(hapd, mgmt->sa)) { 1063 wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR 1064 " since no room for additional STA", 1065 hapd->conf->iface, MAC2STR(mgmt->sa)); 1066 return; 1067 } 1068 1069 #ifdef CONFIG_TESTING_OPTIONS 1070 if (hapd->iconf->ignore_probe_probability > 0.0 && 1071 drand48() < hapd->iconf->ignore_probe_probability) { 1072 wpa_printf(MSG_INFO, 1073 "TESTING: ignoring probe request from " MACSTR, 1074 MAC2STR(mgmt->sa)); 1075 return; 1076 } 1077 #endif /* CONFIG_TESTING_OPTIONS */ 1078 1079 wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, RX_PROBE_REQUEST "sa=" MACSTR 1080 " signal=%d", MAC2STR(mgmt->sa), ssi_signal); 1081 1082 resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL, 1083 &resp_len); 1084 if (resp == NULL) 1085 return; 1086 1087 /* 1088 * If this is a broadcast probe request, apply no ack policy to avoid 1089 * excessive retries. 1090 */ 1091 noack = !!(res == WILDCARD_SSID_MATCH && 1092 is_broadcast_ether_addr(mgmt->da)); 1093 1094 csa_offs_len = 0; 1095 if (hapd->csa_in_progress) { 1096 if (hapd->cs_c_off_proberesp) 1097 csa_offs[csa_offs_len++] = 1098 hapd->cs_c_off_proberesp; 1099 1100 if (hapd->cs_c_off_ecsa_proberesp) 1101 csa_offs[csa_offs_len++] = 1102 hapd->cs_c_off_ecsa_proberesp; 1103 } 1104 1105 ret = hostapd_drv_send_mlme(hapd, resp, resp_len, noack, 1106 csa_offs_len ? csa_offs : NULL, 1107 csa_offs_len, 0); 1108 1109 if (ret < 0) 1110 wpa_printf(MSG_INFO, "handle_probe_req: send failed"); 1111 1112 os_free(resp); 1113 1114 wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s " 1115 "SSID", MAC2STR(mgmt->sa), 1116 elems.ssid_len == 0 ? "broadcast" : "our"); 1117 } 1118 1119 1120 static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd, 1121 size_t *resp_len) 1122 { 1123 /* check probe response offloading caps and print warnings */ 1124 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD)) 1125 return NULL; 1126 1127 #ifdef CONFIG_WPS 1128 if (hapd->conf->wps_state && hapd->wps_probe_resp_ie && 1129 (!(hapd->iface->probe_resp_offloads & 1130 (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS | 1131 WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2)))) 1132 wpa_printf(MSG_WARNING, "Device is trying to offload WPS " 1133 "Probe Response while not supporting this"); 1134 #endif /* CONFIG_WPS */ 1135 1136 #ifdef CONFIG_P2P 1137 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie && 1138 !(hapd->iface->probe_resp_offloads & 1139 WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P)) 1140 wpa_printf(MSG_WARNING, "Device is trying to offload P2P " 1141 "Probe Response while not supporting this"); 1142 #endif /* CONFIG_P2P */ 1143 1144 if (hapd->conf->interworking && 1145 !(hapd->iface->probe_resp_offloads & 1146 WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING)) 1147 wpa_printf(MSG_WARNING, "Device is trying to offload " 1148 "Interworking Probe Response while not supporting " 1149 "this"); 1150 1151 /* Generate a Probe Response template for the non-P2P case */ 1152 return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len); 1153 } 1154 1155 #endif /* NEED_AP_MLME */ 1156 1157 1158 #ifdef CONFIG_IEEE80211AX 1159 /* Unsolicited broadcast Probe Response transmission, 6 GHz only */ 1160 static u8 * hostapd_unsol_bcast_probe_resp(struct hostapd_data *hapd, 1161 struct wpa_driver_ap_params *params) 1162 { 1163 if (!is_6ghz_op_class(hapd->iconf->op_class)) 1164 return NULL; 1165 1166 params->unsol_bcast_probe_resp_interval = 1167 hapd->conf->unsol_bcast_probe_resp_interval; 1168 1169 return hostapd_gen_probe_resp(hapd, NULL, 0, 1170 ¶ms->unsol_bcast_probe_resp_tmpl_len); 1171 } 1172 #endif /* CONFIG_IEEE80211AX */ 1173 1174 1175 void sta_track_del(struct hostapd_sta_info *info) 1176 { 1177 #ifdef CONFIG_TAXONOMY 1178 wpabuf_free(info->probe_ie_taxonomy); 1179 info->probe_ie_taxonomy = NULL; 1180 #endif /* CONFIG_TAXONOMY */ 1181 os_free(info); 1182 } 1183 1184 1185 #ifdef CONFIG_FILS 1186 1187 static u16 hostapd_fils_discovery_cap(struct hostapd_data *hapd) 1188 { 1189 u16 cap_info, phy_index = 0; 1190 u8 chwidth = FD_CAP_BSS_CHWIDTH_20, mcs_nss_size = 4; 1191 struct hostapd_hw_modes *mode = hapd->iface->current_mode; 1192 1193 cap_info = FD_CAP_ESS; 1194 if (hapd->conf->wpa) 1195 cap_info |= FD_CAP_PRIVACY; 1196 1197 if (is_6ghz_op_class(hapd->iconf->op_class)) { 1198 phy_index = FD_CAP_PHY_INDEX_HE; 1199 1200 switch (hapd->iconf->op_class) { 1201 case 135: 1202 mcs_nss_size += 4; 1203 /* fallthrough */ 1204 case 134: 1205 mcs_nss_size += 4; 1206 chwidth = FD_CAP_BSS_CHWIDTH_160_80_80; 1207 break; 1208 case 133: 1209 chwidth = FD_CAP_BSS_CHWIDTH_80; 1210 break; 1211 case 132: 1212 chwidth = FD_CAP_BSS_CHWIDTH_40; 1213 break; 1214 } 1215 } else { 1216 switch (hostapd_get_oper_chwidth(hapd->iconf)) { 1217 case CHANWIDTH_80P80MHZ: 1218 mcs_nss_size += 4; 1219 /* fallthrough */ 1220 case CHANWIDTH_160MHZ: 1221 mcs_nss_size += 4; 1222 chwidth = FD_CAP_BSS_CHWIDTH_160_80_80; 1223 break; 1224 case CHANWIDTH_80MHZ: 1225 chwidth = FD_CAP_BSS_CHWIDTH_80; 1226 break; 1227 case CHANWIDTH_USE_HT: 1228 if (hapd->iconf->secondary_channel) 1229 chwidth = FD_CAP_BSS_CHWIDTH_40; 1230 else 1231 chwidth = FD_CAP_BSS_CHWIDTH_20; 1232 break; 1233 } 1234 1235 #ifdef CONFIG_IEEE80211AX 1236 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) 1237 phy_index = FD_CAP_PHY_INDEX_HE; 1238 #endif /* CONFIG_IEEE80211AX */ 1239 #ifdef CONFIG_IEEE80211AC 1240 if (!phy_index && 1241 hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) 1242 phy_index = FD_CAP_PHY_INDEX_VHT; 1243 #endif /* CONFIG_IEEE80211AC */ 1244 if (!phy_index && 1245 hapd->iconf->ieee80211n && !hapd->conf->disable_11n) 1246 phy_index = FD_CAP_PHY_INDEX_HT; 1247 } 1248 1249 cap_info |= phy_index << FD_CAP_PHY_INDEX_SHIFT; 1250 cap_info |= chwidth << FD_CAP_BSS_CHWIDTH_SHIFT; 1251 1252 if (mode) { 1253 u16 *mcs = (u16 *) mode->he_capab[IEEE80211_MODE_AP].mcs; 1254 int i; 1255 u16 nss = 0; 1256 1257 for (i = 0; i < HE_NSS_MAX_STREAMS; i++) { 1258 u16 nss_mask = 0x3 << (i * 2); 1259 1260 if (mcs_nss_size == 4 && 1261 (((mcs[0] & nss_mask) == nss_mask) || 1262 ((mcs[1] & nss_mask) == nss_mask))) 1263 continue; 1264 1265 if (mcs_nss_size == 8 && 1266 (((mcs[2] & nss_mask) == nss_mask) || 1267 ((mcs[3] & nss_mask) == nss_mask))) 1268 continue; 1269 1270 if (mcs_nss_size == 12 && 1271 (((mcs[4] & nss_mask) == nss_mask) || 1272 ((mcs[5] & nss_mask) == nss_mask))) 1273 continue; 1274 1275 nss++; 1276 } 1277 1278 if (nss > 4) 1279 cap_info |= FD_CAP_NSS_5_8 << FD_CAP_NSS_SHIFT; 1280 else if (nss) 1281 cap_info |= (nss - 1) << FD_CAP_NSS_SHIFT; 1282 } 1283 1284 return cap_info; 1285 } 1286 1287 1288 static u8 * hostapd_gen_fils_discovery(struct hostapd_data *hapd, size_t *len) 1289 { 1290 struct ieee80211_mgmt *head; 1291 const u8 *mobility_domain; 1292 u8 *pos, *length_pos, buf[200]; 1293 u16 ctl = 0; 1294 u8 fd_rsn_info[5]; 1295 size_t total_len, buf_len; 1296 1297 total_len = 24 + 2 + 12; 1298 1299 /* FILS Discovery Frame Control */ 1300 ctl = (sizeof(hapd->conf->ssid.short_ssid) - 1) | 1301 FD_FRAME_CTL_SHORT_SSID_PRESENT | 1302 FD_FRAME_CTL_LENGTH_PRESENT | 1303 FD_FRAME_CTL_CAP_PRESENT; 1304 total_len += 4 + 1 + 2; 1305 1306 /* Check for optional subfields and calculate length */ 1307 if (wpa_auth_write_fd_rsn_info(hapd->wpa_auth, fd_rsn_info)) { 1308 ctl |= FD_FRAME_CTL_RSN_INFO_PRESENT; 1309 total_len += sizeof(fd_rsn_info); 1310 } 1311 1312 mobility_domain = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN); 1313 if (mobility_domain) { 1314 ctl |= FD_FRAME_CTL_MD_PRESENT; 1315 total_len += 3; 1316 } 1317 1318 total_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_ACTION); 1319 1320 pos = hostapd_eid_fils_indic(hapd, buf, 0); 1321 buf_len = pos - buf; 1322 total_len += buf_len; 1323 1324 head = os_zalloc(total_len); 1325 if (!head) 1326 return NULL; 1327 1328 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, 1329 WLAN_FC_STYPE_ACTION); 1330 os_memset(head->da, 0xff, ETH_ALEN); 1331 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN); 1332 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN); 1333 1334 head->u.action.category = WLAN_ACTION_PUBLIC; 1335 head->u.action.u.public_action.action = WLAN_PA_FILS_DISCOVERY; 1336 1337 pos = &head->u.action.u.public_action.variable[0]; 1338 1339 /* FILS Discovery Information field */ 1340 1341 /* FILS Discovery Frame Control */ 1342 WPA_PUT_LE16(pos, ctl); 1343 pos += 2; 1344 1345 /* Hardware or low-level driver will fill in the Timestamp value */ 1346 pos += 8; 1347 1348 /* Beacon Interval */ 1349 WPA_PUT_LE16(pos, hapd->iconf->beacon_int); 1350 pos += 2; 1351 1352 /* Short SSID */ 1353 WPA_PUT_LE32(pos, hapd->conf->ssid.short_ssid); 1354 pos += sizeof(hapd->conf->ssid.short_ssid); 1355 1356 /* Store position of FILS discovery information element Length field */ 1357 length_pos = pos++; 1358 1359 /* FD Capability */ 1360 WPA_PUT_LE16(pos, hostapd_fils_discovery_cap(hapd)); 1361 pos += 2; 1362 1363 /* Operating Class - not present */ 1364 1365 /* Primary Channel - not present */ 1366 1367 /* AP Configuration Sequence Number - not present */ 1368 1369 /* Access Network Options - not present */ 1370 1371 /* FD RSN Information */ 1372 if (ctl & FD_FRAME_CTL_RSN_INFO_PRESENT) { 1373 os_memcpy(pos, fd_rsn_info, sizeof(fd_rsn_info)); 1374 pos += sizeof(fd_rsn_info); 1375 } 1376 1377 /* Channel Center Frequency Segment 1 - not present */ 1378 1379 /* Mobility Domain */ 1380 if (ctl & FD_FRAME_CTL_MD_PRESENT) { 1381 os_memcpy(pos, &mobility_domain[2], 3); 1382 pos += 3; 1383 } 1384 1385 /* Fill in the Length field value */ 1386 *length_pos = pos - (length_pos + 1); 1387 1388 pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_ACTION); 1389 1390 /* FILS Indication element */ 1391 if (buf_len) { 1392 os_memcpy(pos, buf, buf_len); 1393 pos += buf_len; 1394 } 1395 1396 *len = pos - (u8 *) head; 1397 wpa_hexdump(MSG_DEBUG, "FILS Discovery frame template", 1398 head, pos - (u8 *) head); 1399 return (u8 *) head; 1400 } 1401 1402 1403 /* Configure FILS Discovery frame transmission parameters */ 1404 static u8 * hostapd_fils_discovery(struct hostapd_data *hapd, 1405 struct wpa_driver_ap_params *params) 1406 { 1407 params->fd_max_int = hapd->conf->fils_discovery_max_int; 1408 if (is_6ghz_op_class(hapd->iconf->op_class) && 1409 params->fd_max_int > FD_MAX_INTERVAL_6GHZ) 1410 params->fd_max_int = FD_MAX_INTERVAL_6GHZ; 1411 1412 params->fd_min_int = hapd->conf->fils_discovery_min_int; 1413 if (params->fd_min_int > params->fd_max_int) 1414 params->fd_min_int = params->fd_max_int; 1415 1416 if (params->fd_max_int) 1417 return hostapd_gen_fils_discovery(hapd, 1418 ¶ms->fd_frame_tmpl_len); 1419 1420 return NULL; 1421 } 1422 1423 #endif /* CONFIG_FILS */ 1424 1425 1426 int ieee802_11_build_ap_params(struct hostapd_data *hapd, 1427 struct wpa_driver_ap_params *params) 1428 { 1429 struct ieee80211_mgmt *head = NULL; 1430 u8 *tail = NULL; 1431 size_t head_len = 0, tail_len = 0; 1432 u8 *resp = NULL; 1433 size_t resp_len = 0; 1434 #ifdef NEED_AP_MLME 1435 u16 capab_info; 1436 u8 *pos, *tailpos, *tailend, *csa_pos; 1437 1438 #define BEACON_HEAD_BUF_SIZE 256 1439 #define BEACON_TAIL_BUF_SIZE 512 1440 head = os_zalloc(BEACON_HEAD_BUF_SIZE); 1441 tail_len = BEACON_TAIL_BUF_SIZE; 1442 #ifdef CONFIG_WPS 1443 if (hapd->conf->wps_state && hapd->wps_beacon_ie) 1444 tail_len += wpabuf_len(hapd->wps_beacon_ie); 1445 #endif /* CONFIG_WPS */ 1446 #ifdef CONFIG_P2P 1447 if (hapd->p2p_beacon_ie) 1448 tail_len += wpabuf_len(hapd->p2p_beacon_ie); 1449 #endif /* CONFIG_P2P */ 1450 #ifdef CONFIG_FST 1451 if (hapd->iface->fst_ies) 1452 tail_len += wpabuf_len(hapd->iface->fst_ies); 1453 #endif /* CONFIG_FST */ 1454 if (hapd->conf->vendor_elements) 1455 tail_len += wpabuf_len(hapd->conf->vendor_elements); 1456 1457 #ifdef CONFIG_IEEE80211AC 1458 if (hapd->conf->vendor_vht) { 1459 tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) + 1460 2 + sizeof(struct ieee80211_vht_operation); 1461 } 1462 #endif /* CONFIG_IEEE80211AC */ 1463 1464 #ifdef CONFIG_IEEE80211AX 1465 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) { 1466 tail_len += 3 + sizeof(struct ieee80211_he_capabilities) + 1467 3 + sizeof(struct ieee80211_he_operation) + 1468 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) + 1469 3 + sizeof(struct ieee80211_spatial_reuse); 1470 if (is_6ghz_op_class(hapd->iconf->op_class)) 1471 tail_len += sizeof(struct ieee80211_he_6ghz_oper_info) + 1472 3 + sizeof(struct ieee80211_he_6ghz_band_cap); 1473 } 1474 #endif /* CONFIG_IEEE80211AX */ 1475 1476 tail_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_BEACON); 1477 tail_len += hostapd_mbo_ie_len(hapd); 1478 tail_len += hostapd_eid_owe_trans_len(hapd); 1479 tail_len += hostapd_eid_dpp_cc_len(hapd); 1480 1481 tailpos = tail = os_malloc(tail_len); 1482 if (head == NULL || tail == NULL) { 1483 wpa_printf(MSG_ERROR, "Failed to set beacon data"); 1484 os_free(head); 1485 os_free(tail); 1486 return -1; 1487 } 1488 tailend = tail + tail_len; 1489 1490 head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, 1491 WLAN_FC_STYPE_BEACON); 1492 head->duration = host_to_le16(0); 1493 os_memset(head->da, 0xff, ETH_ALEN); 1494 1495 os_memcpy(head->sa, hapd->own_addr, ETH_ALEN); 1496 os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN); 1497 head->u.beacon.beacon_int = 1498 host_to_le16(hapd->iconf->beacon_int); 1499 1500 /* hardware or low-level driver will setup seq_ctrl and timestamp */ 1501 capab_info = hostapd_own_capab_info(hapd); 1502 head->u.beacon.capab_info = host_to_le16(capab_info); 1503 pos = &head->u.beacon.variable[0]; 1504 1505 /* SSID */ 1506 *pos++ = WLAN_EID_SSID; 1507 if (hapd->conf->ignore_broadcast_ssid == 2) { 1508 /* clear the data, but keep the correct length of the SSID */ 1509 *pos++ = hapd->conf->ssid.ssid_len; 1510 os_memset(pos, 0, hapd->conf->ssid.ssid_len); 1511 pos += hapd->conf->ssid.ssid_len; 1512 } else if (hapd->conf->ignore_broadcast_ssid) { 1513 *pos++ = 0; /* empty SSID */ 1514 } else { 1515 *pos++ = hapd->conf->ssid.ssid_len; 1516 os_memcpy(pos, hapd->conf->ssid.ssid, 1517 hapd->conf->ssid.ssid_len); 1518 pos += hapd->conf->ssid.ssid_len; 1519 } 1520 1521 /* Supported rates */ 1522 pos = hostapd_eid_supp_rates(hapd, pos); 1523 1524 /* DS Params */ 1525 pos = hostapd_eid_ds_params(hapd, pos); 1526 1527 head_len = pos - (u8 *) head; 1528 1529 tailpos = hostapd_eid_country(hapd, tailpos, tailend - tailpos); 1530 1531 /* Power Constraint element */ 1532 tailpos = hostapd_eid_pwr_constraint(hapd, tailpos); 1533 1534 /* CSA IE */ 1535 csa_pos = hostapd_eid_csa(hapd, tailpos); 1536 if (csa_pos != tailpos) 1537 hapd->cs_c_off_beacon = csa_pos - tail - 1; 1538 tailpos = csa_pos; 1539 1540 /* ERP Information element */ 1541 tailpos = hostapd_eid_erp_info(hapd, tailpos); 1542 1543 /* Extended supported rates */ 1544 tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos); 1545 1546 tailpos = hostapd_get_rsne(hapd, tailpos, tailend - tailpos); 1547 tailpos = hostapd_eid_bss_load(hapd, tailpos, tailend - tailpos); 1548 tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos, 1549 tailend - tailpos); 1550 tailpos = hostapd_get_mde(hapd, tailpos, tailend - tailpos); 1551 1552 /* eCSA IE */ 1553 csa_pos = hostapd_eid_ecsa(hapd, tailpos); 1554 if (csa_pos != tailpos) 1555 hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1; 1556 tailpos = csa_pos; 1557 1558 tailpos = hostapd_eid_supported_op_classes(hapd, tailpos); 1559 tailpos = hostapd_eid_ht_capabilities(hapd, tailpos); 1560 tailpos = hostapd_eid_ht_operation(hapd, tailpos); 1561 1562 tailpos = hostapd_eid_ext_capab(hapd, tailpos); 1563 1564 /* 1565 * TODO: Time Advertisement element should only be included in some 1566 * DTIM Beacon frames. 1567 */ 1568 tailpos = hostapd_eid_time_adv(hapd, tailpos); 1569 1570 tailpos = hostapd_eid_interworking(hapd, tailpos); 1571 tailpos = hostapd_eid_adv_proto(hapd, tailpos); 1572 tailpos = hostapd_eid_roaming_consortium(hapd, tailpos); 1573 1574 #ifdef CONFIG_FST 1575 if (hapd->iface->fst_ies) { 1576 os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies), 1577 wpabuf_len(hapd->iface->fst_ies)); 1578 tailpos += wpabuf_len(hapd->iface->fst_ies); 1579 } 1580 #endif /* CONFIG_FST */ 1581 1582 #ifdef CONFIG_IEEE80211AC 1583 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac && 1584 !is_6ghz_op_class(hapd->iconf->op_class)) { 1585 tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0); 1586 tailpos = hostapd_eid_vht_operation(hapd, tailpos); 1587 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos); 1588 } 1589 #endif /* CONFIG_IEEE80211AC */ 1590 1591 #ifdef CONFIG_IEEE80211AX 1592 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax && 1593 is_6ghz_op_class(hapd->iconf->op_class)) 1594 tailpos = hostapd_eid_txpower_envelope(hapd, tailpos); 1595 #endif /* CONFIG_IEEE80211AX */ 1596 1597 if ((hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) || 1598 (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax)) 1599 tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos); 1600 1601 tailpos = hostapd_eid_rnr(hapd, tailpos, WLAN_FC_STYPE_BEACON); 1602 tailpos = hostapd_eid_fils_indic(hapd, tailpos, 0); 1603 tailpos = hostapd_get_rsnxe(hapd, tailpos, tailend - tailpos); 1604 1605 #ifdef CONFIG_IEEE80211AX 1606 if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) { 1607 tailpos = hostapd_eid_he_capab(hapd, tailpos, 1608 IEEE80211_MODE_AP); 1609 tailpos = hostapd_eid_he_operation(hapd, tailpos); 1610 tailpos = hostapd_eid_spatial_reuse(hapd, tailpos); 1611 tailpos = hostapd_eid_he_mu_edca_parameter_set(hapd, tailpos); 1612 tailpos = hostapd_eid_he_6ghz_band_cap(hapd, tailpos); 1613 } 1614 #endif /* CONFIG_IEEE80211AX */ 1615 1616 #ifdef CONFIG_IEEE80211AC 1617 if (hapd->conf->vendor_vht) 1618 tailpos = hostapd_eid_vendor_vht(hapd, tailpos); 1619 #endif /* CONFIG_IEEE80211AC */ 1620 1621 /* WPA / OSEN */ 1622 tailpos = hostapd_get_wpa_ie(hapd, tailpos, tailend - tailpos); 1623 tailpos = hostapd_get_osen_ie(hapd, tailpos, tailend - tailpos); 1624 1625 /* Wi-Fi Alliance WMM */ 1626 tailpos = hostapd_eid_wmm(hapd, tailpos); 1627 1628 #ifdef CONFIG_WPS 1629 if (hapd->conf->wps_state && hapd->wps_beacon_ie) { 1630 os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie), 1631 wpabuf_len(hapd->wps_beacon_ie)); 1632 tailpos += wpabuf_len(hapd->wps_beacon_ie); 1633 } 1634 #endif /* CONFIG_WPS */ 1635 1636 #ifdef CONFIG_P2P 1637 if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) { 1638 os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie), 1639 wpabuf_len(hapd->p2p_beacon_ie)); 1640 tailpos += wpabuf_len(hapd->p2p_beacon_ie); 1641 } 1642 #endif /* CONFIG_P2P */ 1643 #ifdef CONFIG_P2P_MANAGER 1644 if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) == 1645 P2P_MANAGE) 1646 tailpos = hostapd_eid_p2p_manage(hapd, tailpos); 1647 #endif /* CONFIG_P2P_MANAGER */ 1648 1649 #ifdef CONFIG_HS20 1650 tailpos = hostapd_eid_hs20_indication(hapd, tailpos); 1651 #endif /* CONFIG_HS20 */ 1652 1653 tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos); 1654 tailpos = hostapd_eid_owe_trans(hapd, tailpos, 1655 tail + tail_len - tailpos); 1656 tailpos = hostapd_eid_dpp_cc(hapd, tailpos, tail + tail_len - tailpos); 1657 1658 if (hapd->conf->vendor_elements) { 1659 os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements), 1660 wpabuf_len(hapd->conf->vendor_elements)); 1661 tailpos += wpabuf_len(hapd->conf->vendor_elements); 1662 } 1663 1664 tail_len = tailpos > tail ? tailpos - tail : 0; 1665 1666 resp = hostapd_probe_resp_offloads(hapd, &resp_len); 1667 #endif /* NEED_AP_MLME */ 1668 1669 os_memset(params, 0, sizeof(*params)); 1670 params->head = (u8 *) head; 1671 params->head_len = head_len; 1672 params->tail = tail; 1673 params->tail_len = tail_len; 1674 params->proberesp = resp; 1675 params->proberesp_len = resp_len; 1676 params->dtim_period = hapd->conf->dtim_period; 1677 params->beacon_int = hapd->iconf->beacon_int; 1678 params->basic_rates = hapd->iface->basic_rates; 1679 params->beacon_rate = hapd->iconf->beacon_rate; 1680 params->rate_type = hapd->iconf->rate_type; 1681 params->ssid = hapd->conf->ssid.ssid; 1682 params->ssid_len = hapd->conf->ssid.ssid_len; 1683 if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) == 1684 (WPA_PROTO_WPA | WPA_PROTO_RSN)) 1685 params->pairwise_ciphers = hapd->conf->wpa_pairwise | 1686 hapd->conf->rsn_pairwise; 1687 else if (hapd->conf->wpa & WPA_PROTO_RSN) 1688 params->pairwise_ciphers = hapd->conf->rsn_pairwise; 1689 else if (hapd->conf->wpa & WPA_PROTO_WPA) 1690 params->pairwise_ciphers = hapd->conf->wpa_pairwise; 1691 params->group_cipher = hapd->conf->wpa_group; 1692 params->key_mgmt_suites = hapd->conf->wpa_key_mgmt; 1693 params->auth_algs = hapd->conf->auth_algs; 1694 params->wpa_version = hapd->conf->wpa; 1695 params->privacy = hapd->conf->wpa; 1696 #ifdef CONFIG_WEP 1697 params->privacy |= hapd->conf->ssid.wep.keys_set || 1698 (hapd->conf->ieee802_1x && 1699 (hapd->conf->default_wep_key_len || 1700 hapd->conf->individual_wep_key_len)); 1701 #endif /* CONFIG_WEP */ 1702 switch (hapd->conf->ignore_broadcast_ssid) { 1703 case 0: 1704 params->hide_ssid = NO_SSID_HIDING; 1705 break; 1706 case 1: 1707 params->hide_ssid = HIDDEN_SSID_ZERO_LEN; 1708 break; 1709 case 2: 1710 params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS; 1711 break; 1712 } 1713 params->isolate = hapd->conf->isolate; 1714 #ifdef NEED_AP_MLME 1715 params->cts_protect = !!(ieee802_11_erp_info(hapd) & 1716 ERP_INFO_USE_PROTECTION); 1717 params->preamble = hapd->iface->num_sta_no_short_preamble == 0 && 1718 hapd->iconf->preamble == SHORT_PREAMBLE; 1719 if (hapd->iface->current_mode && 1720 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G) 1721 params->short_slot_time = 1722 hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1; 1723 else 1724 params->short_slot_time = -1; 1725 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n) 1726 params->ht_opmode = -1; 1727 else 1728 params->ht_opmode = hapd->iface->ht_op_mode; 1729 #endif /* NEED_AP_MLME */ 1730 params->interworking = hapd->conf->interworking; 1731 if (hapd->conf->interworking && 1732 !is_zero_ether_addr(hapd->conf->hessid)) 1733 params->hessid = hapd->conf->hessid; 1734 params->access_network_type = hapd->conf->access_network_type; 1735 params->ap_max_inactivity = hapd->conf->ap_max_inactivity; 1736 #ifdef CONFIG_P2P 1737 params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow; 1738 #endif /* CONFIG_P2P */ 1739 #ifdef CONFIG_HS20 1740 params->disable_dgaf = hapd->conf->disable_dgaf; 1741 if (hapd->conf->osen) { 1742 params->privacy = 1; 1743 params->osen = 1; 1744 } 1745 #endif /* CONFIG_HS20 */ 1746 params->multicast_to_unicast = hapd->conf->multicast_to_unicast; 1747 params->pbss = hapd->conf->pbss; 1748 1749 if (hapd->conf->ftm_responder) { 1750 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_FTM_RESPONDER) { 1751 params->ftm_responder = 1; 1752 params->lci = hapd->iface->conf->lci; 1753 params->civic = hapd->iface->conf->civic; 1754 } else { 1755 wpa_printf(MSG_WARNING, 1756 "Not configuring FTM responder as the driver doesn't advertise support for it"); 1757 } 1758 } 1759 1760 return 0; 1761 } 1762 1763 1764 void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params) 1765 { 1766 os_free(params->tail); 1767 params->tail = NULL; 1768 os_free(params->head); 1769 params->head = NULL; 1770 os_free(params->proberesp); 1771 params->proberesp = NULL; 1772 #ifdef CONFIG_FILS 1773 os_free(params->fd_frame_tmpl); 1774 params->fd_frame_tmpl = NULL; 1775 #endif /* CONFIG_FILS */ 1776 #ifdef CONFIG_IEEE80211AX 1777 os_free(params->unsol_bcast_probe_resp_tmpl); 1778 params->unsol_bcast_probe_resp_tmpl = NULL; 1779 #endif /* CONFIG_IEEE80211AX */ 1780 } 1781 1782 1783 static int __ieee802_11_set_beacon(struct hostapd_data *hapd) 1784 { 1785 struct wpa_driver_ap_params params; 1786 struct hostapd_freq_params freq; 1787 struct hostapd_iface *iface = hapd->iface; 1788 struct hostapd_config *iconf = iface->conf; 1789 struct hostapd_hw_modes *cmode = iface->current_mode; 1790 struct wpabuf *beacon, *proberesp, *assocresp; 1791 int res, ret = -1; 1792 1793 if (!hapd->drv_priv) { 1794 wpa_printf(MSG_ERROR, "Interface is disabled"); 1795 return -1; 1796 } 1797 1798 if (hapd->csa_in_progress) { 1799 wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period"); 1800 return -1; 1801 } 1802 1803 hapd->beacon_set_done = 1; 1804 1805 if (ieee802_11_build_ap_params(hapd, ¶ms) < 0) 1806 return -1; 1807 1808 if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) < 1809 0) 1810 goto fail; 1811 1812 params.beacon_ies = beacon; 1813 params.proberesp_ies = proberesp; 1814 params.assocresp_ies = assocresp; 1815 params.reenable = hapd->reenable_beacon; 1816 #ifdef CONFIG_IEEE80211AX 1817 params.he_spr_ctrl = hapd->iface->conf->spr.sr_control; 1818 params.he_spr_non_srg_obss_pd_max_offset = 1819 hapd->iface->conf->spr.non_srg_obss_pd_max_offset; 1820 params.he_spr_srg_obss_pd_min_offset = 1821 hapd->iface->conf->spr.srg_obss_pd_min_offset; 1822 params.he_spr_srg_obss_pd_max_offset = 1823 hapd->iface->conf->spr.srg_obss_pd_max_offset; 1824 os_memcpy(params.he_spr_bss_color_bitmap, 1825 hapd->iface->conf->spr.srg_bss_color_bitmap, 8); 1826 os_memcpy(params.he_spr_partial_bssid_bitmap, 1827 hapd->iface->conf->spr.srg_partial_bssid_bitmap, 8); 1828 params.he_bss_color_disabled = 1829 hapd->iface->conf->he_op.he_bss_color_disabled; 1830 params.he_bss_color_partial = 1831 hapd->iface->conf->he_op.he_bss_color_partial; 1832 params.he_bss_color = hapd->iface->conf->he_op.he_bss_color; 1833 params.twt_responder = hostapd_get_he_twt_responder(hapd, 1834 IEEE80211_MODE_AP); 1835 params.unsol_bcast_probe_resp_tmpl = 1836 hostapd_unsol_bcast_probe_resp(hapd, ¶ms); 1837 #endif /* CONFIG_IEEE80211AX */ 1838 hapd->reenable_beacon = 0; 1839 #ifdef CONFIG_SAE 1840 params.sae_pwe = hapd->conf->sae_pwe; 1841 #endif /* CONFIG_SAE */ 1842 1843 #ifdef CONFIG_FILS 1844 params.fd_frame_tmpl = hostapd_fils_discovery(hapd, ¶ms); 1845 #endif /* CONFIG_FILS */ 1846 1847 if (cmode && 1848 hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq, 1849 iconf->channel, iconf->enable_edmg, 1850 iconf->edmg_channel, iconf->ieee80211n, 1851 iconf->ieee80211ac, iconf->ieee80211ax, 1852 iconf->secondary_channel, 1853 hostapd_get_oper_chwidth(iconf), 1854 hostapd_get_oper_centr_freq_seg0_idx(iconf), 1855 hostapd_get_oper_centr_freq_seg1_idx(iconf), 1856 cmode->vht_capab, 1857 &cmode->he_capab[IEEE80211_MODE_AP]) == 0) 1858 params.freq = &freq; 1859 1860 res = hostapd_drv_set_ap(hapd, ¶ms); 1861 hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp); 1862 if (res) 1863 wpa_printf(MSG_ERROR, "Failed to set beacon parameters"); 1864 else 1865 ret = 0; 1866 fail: 1867 ieee802_11_free_ap_params(¶ms); 1868 return ret; 1869 } 1870 1871 1872 int ieee802_11_set_beacon(struct hostapd_data *hapd) 1873 { 1874 struct hostapd_iface *iface = hapd->iface; 1875 int ret; 1876 size_t i, j; 1877 bool is_6g; 1878 1879 ret = __ieee802_11_set_beacon(hapd); 1880 if (ret != 0) 1881 return ret; 1882 1883 if (!iface->interfaces || iface->interfaces->count <= 1) 1884 return 0; 1885 1886 /* Update Beacon frames in case of 6 GHz colocation */ 1887 is_6g = is_6ghz_op_class(iface->conf->op_class); 1888 for (j = 0; j < iface->interfaces->count; j++) { 1889 struct hostapd_iface *colocated; 1890 1891 colocated = iface->interfaces->iface[j]; 1892 if (colocated == iface || !colocated || !colocated->conf) 1893 continue; 1894 1895 if (is_6g == is_6ghz_op_class(colocated->conf->op_class)) 1896 continue; 1897 1898 for (i = 0; i < colocated->num_bss; i++) { 1899 if (colocated->bss[i] && colocated->bss[i]->started) 1900 __ieee802_11_set_beacon(colocated->bss[i]); 1901 } 1902 } 1903 1904 return 0; 1905 } 1906 1907 1908 int ieee802_11_set_beacons(struct hostapd_iface *iface) 1909 { 1910 size_t i; 1911 int ret = 0; 1912 1913 for (i = 0; i < iface->num_bss; i++) { 1914 if (iface->bss[i]->started && 1915 ieee802_11_set_beacon(iface->bss[i]) < 0) 1916 ret = -1; 1917 } 1918 1919 return ret; 1920 } 1921 1922 1923 /* only update beacons if started */ 1924 int ieee802_11_update_beacons(struct hostapd_iface *iface) 1925 { 1926 size_t i; 1927 int ret = 0; 1928 1929 for (i = 0; i < iface->num_bss; i++) { 1930 if (iface->bss[i]->beacon_set_done && iface->bss[i]->started && 1931 ieee802_11_set_beacon(iface->bss[i]) < 0) 1932 ret = -1; 1933 } 1934 1935 return ret; 1936 } 1937 1938 #endif /* CONFIG_NATIVE_WINDOWS */ 1939