Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 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. |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5 | * Copyright (c) 2008-2012, Jouni Malinen <j@w1.fi> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6 | * |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7 | * This software may be distributed under the terms of the BSD license. |
| 8 | * See README for more details. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 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" |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 18 | #include "common/hw_features_common.h" |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 19 | #include "common/wpa_ctrl.h" |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 20 | #include "crypto/sha1.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 21 | #include "wps/wps_defs.h" |
| 22 | #include "p2p/p2p.h" |
| 23 | #include "hostapd.h" |
| 24 | #include "ieee802_11.h" |
| 25 | #include "wpa_auth.h" |
| 26 | #include "wmm.h" |
| 27 | #include "ap_config.h" |
| 28 | #include "sta_info.h" |
| 29 | #include "p2p_hostapd.h" |
| 30 | #include "ap_drv_ops.h" |
| 31 | #include "beacon.h" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 32 | #include "hs20.h" |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 33 | #include "dfs.h" |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 34 | #include "taxonomy.h" |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 35 | #include "ieee802_11_auth.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 36 | |
| 37 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 38 | #ifdef NEED_AP_MLME |
| 39 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 40 | static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len) |
| 41 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 42 | if (len < 2 + 5) |
| 43 | return eid; |
| 44 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 45 | #ifdef CONFIG_TESTING_OPTIONS |
| 46 | if (hapd->conf->bss_load_test_set) { |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 47 | *eid++ = WLAN_EID_BSS_LOAD; |
| 48 | *eid++ = 5; |
| 49 | os_memcpy(eid, hapd->conf->bss_load_test, 5); |
| 50 | eid += 5; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 51 | return eid; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 52 | } |
| 53 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 54 | if (hapd->conf->bss_load_update_period) { |
| 55 | *eid++ = WLAN_EID_BSS_LOAD; |
| 56 | *eid++ = 5; |
| 57 | WPA_PUT_LE16(eid, hapd->num_sta); |
| 58 | eid += 2; |
| 59 | *eid++ = hapd->iface->channel_utilization; |
| 60 | WPA_PUT_LE16(eid, 0); /* no available admission capabity */ |
| 61 | eid += 2; |
| 62 | } |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 63 | return eid; |
| 64 | } |
| 65 | |
| 66 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 67 | static u8 ieee802_11_erp_info(struct hostapd_data *hapd) |
| 68 | { |
| 69 | u8 erp = 0; |
| 70 | |
| 71 | if (hapd->iface->current_mode == NULL || |
| 72 | hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G) |
| 73 | return 0; |
| 74 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 75 | if (hapd->iface->olbc) |
| 76 | erp |= ERP_INFO_USE_PROTECTION; |
| 77 | if (hapd->iface->num_sta_non_erp > 0) { |
| 78 | erp |= ERP_INFO_NON_ERP_PRESENT | |
| 79 | ERP_INFO_USE_PROTECTION; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 80 | } |
| 81 | if (hapd->iface->num_sta_no_short_preamble > 0 || |
| 82 | hapd->iconf->preamble == LONG_PREAMBLE) |
| 83 | erp |= ERP_INFO_BARKER_PREAMBLE_MODE; |
| 84 | |
| 85 | return erp; |
| 86 | } |
| 87 | |
| 88 | |
| 89 | static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid) |
| 90 | { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 91 | enum hostapd_hw_mode hw_mode = hapd->iconf->hw_mode; |
| 92 | |
| 93 | if (hw_mode != HOSTAPD_MODE_IEEE80211G && |
| 94 | hw_mode != HOSTAPD_MODE_IEEE80211B) |
| 95 | return eid; |
| 96 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 97 | *eid++ = WLAN_EID_DS_PARAMS; |
| 98 | *eid++ = 1; |
| 99 | *eid++ = hapd->iconf->channel; |
| 100 | return eid; |
| 101 | } |
| 102 | |
| 103 | |
| 104 | static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid) |
| 105 | { |
| 106 | if (hapd->iface->current_mode == NULL || |
| 107 | hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G) |
| 108 | return eid; |
| 109 | |
| 110 | /* Set NonERP_present and use_protection bits if there |
| 111 | * are any associated NonERP stations. */ |
| 112 | /* TODO: use_protection bit can be set to zero even if |
| 113 | * there are NonERP stations present. This optimization |
| 114 | * might be useful if NonERP stations are "quiet". |
| 115 | * See 802.11g/D6 E-1 for recommended practice. |
| 116 | * In addition, Non ERP present might be set, if AP detects Non ERP |
| 117 | * operation on other APs. */ |
| 118 | |
| 119 | /* Add ERP Information element */ |
| 120 | *eid++ = WLAN_EID_ERP_INFO; |
| 121 | *eid++ = 1; |
| 122 | *eid++ = ieee802_11_erp_info(hapd); |
| 123 | |
| 124 | return eid; |
| 125 | } |
| 126 | |
| 127 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 128 | static u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid) |
| 129 | { |
| 130 | u8 *pos = eid; |
| 131 | u8 local_pwr_constraint = 0; |
| 132 | int dfs; |
| 133 | |
| 134 | if (hapd->iface->current_mode == NULL || |
| 135 | hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A) |
| 136 | return eid; |
| 137 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 138 | /* Let host drivers add this IE if DFS support is offloaded */ |
| 139 | if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) |
| 140 | return eid; |
| 141 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 142 | /* |
| 143 | * There is no DFS support and power constraint was not directly |
| 144 | * requested by config option. |
| 145 | */ |
| 146 | if (!hapd->iconf->ieee80211h && |
| 147 | hapd->iconf->local_pwr_constraint == -1) |
| 148 | return eid; |
| 149 | |
| 150 | /* Check if DFS is required by regulatory. */ |
| 151 | dfs = hostapd_is_dfs_required(hapd->iface); |
| 152 | if (dfs < 0) { |
| 153 | wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d", |
| 154 | dfs); |
| 155 | dfs = 0; |
| 156 | } |
| 157 | |
| 158 | if (dfs == 0 && hapd->iconf->local_pwr_constraint == -1) |
| 159 | return eid; |
| 160 | |
| 161 | /* |
| 162 | * ieee80211h (DFS) is enabled so Power Constraint element shall |
| 163 | * be added when running on DFS channel whenever local_pwr_constraint |
| 164 | * is configured or not. In order to meet regulations when TPC is not |
| 165 | * implemented using a transmit power that is below the legal maximum |
| 166 | * (including any mitigation factor) should help. In this case, |
| 167 | * indicate 3 dB below maximum allowed transmit power. |
| 168 | */ |
| 169 | if (hapd->iconf->local_pwr_constraint == -1) |
| 170 | local_pwr_constraint = 3; |
| 171 | |
| 172 | /* |
| 173 | * A STA that is not an AP shall use a transmit power less than or |
| 174 | * equal to the local maximum transmit power level for the channel. |
| 175 | * The local maximum transmit power can be calculated from the formula: |
| 176 | * local max TX pwr = max TX pwr - local pwr constraint |
| 177 | * Where max TX pwr is maximum transmit power level specified for |
| 178 | * channel in Country element and local pwr constraint is specified |
| 179 | * for channel in this Power Constraint element. |
| 180 | */ |
| 181 | |
| 182 | /* Element ID */ |
| 183 | *pos++ = WLAN_EID_PWR_CONSTRAINT; |
| 184 | /* Length */ |
| 185 | *pos++ = 1; |
| 186 | /* Local Power Constraint */ |
| 187 | if (local_pwr_constraint) |
| 188 | *pos++ = local_pwr_constraint; |
| 189 | else |
| 190 | *pos++ = hapd->iconf->local_pwr_constraint; |
| 191 | |
| 192 | return pos; |
| 193 | } |
| 194 | |
| 195 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 196 | static u8 * hostapd_eid_country_add(struct hostapd_data *hapd, u8 *pos, |
| 197 | u8 *end, int chan_spacing, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 198 | struct hostapd_channel_data *start, |
| 199 | struct hostapd_channel_data *prev) |
| 200 | { |
| 201 | if (end - pos < 3) |
| 202 | return pos; |
| 203 | |
| 204 | /* first channel number */ |
| 205 | *pos++ = start->chan; |
| 206 | /* number of channels */ |
| 207 | *pos++ = (prev->chan - start->chan) / chan_spacing + 1; |
| 208 | /* maximum transmit power level */ |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 209 | if (!is_6ghz_op_class(hapd->iconf->op_class)) |
| 210 | *pos++ = start->max_tx_power; |
| 211 | else |
| 212 | *pos++ = 0; /* Reserved when operating on the 6 GHz band */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 213 | |
| 214 | return pos; |
| 215 | } |
| 216 | |
| 217 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 218 | static u8 * hostapd_fill_subband_triplets(struct hostapd_data *hapd, u8 *pos, |
| 219 | u8 *end) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 220 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 221 | int i; |
| 222 | struct hostapd_hw_modes *mode; |
| 223 | struct hostapd_channel_data *start, *prev; |
| 224 | int chan_spacing = 1; |
| 225 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 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 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 242 | if (start && prev) |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 243 | pos = hostapd_eid_country_add(hapd, pos, end, |
| 244 | chan_spacing, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 245 | start, prev); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 246 | |
| 247 | /* Start new group */ |
| 248 | start = prev = chan; |
| 249 | } |
| 250 | |
| 251 | if (start) { |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 252 | pos = hostapd_eid_country_add(hapd, pos, end, chan_spacing, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 253 | start, prev); |
| 254 | } |
| 255 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 256 | return pos; |
| 257 | } |
| 258 | |
| 259 | |
| 260 | static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid, |
| 261 | int max_len) |
| 262 | { |
| 263 | u8 *pos = eid; |
| 264 | u8 *end = eid + max_len; |
| 265 | |
| 266 | if (!hapd->iconf->ieee80211d || max_len < 6 || |
| 267 | hapd->iface->current_mode == NULL) |
| 268 | return eid; |
| 269 | |
| 270 | *pos++ = WLAN_EID_COUNTRY; |
| 271 | pos++; /* length will be set later */ |
| 272 | os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */ |
| 273 | pos += 3; |
| 274 | |
| 275 | if (is_6ghz_op_class(hapd->iconf->op_class)) { |
| 276 | /* Force the third octet of the country string to indicate |
| 277 | * Global Operating Class (Table E-4) */ |
| 278 | eid[4] = 0x04; |
| 279 | |
| 280 | /* Operating Triplet field */ |
| 281 | /* Operating Extension Identifier (>= 201 to indicate this is |
| 282 | * not a Subband Triplet field) */ |
| 283 | *pos++ = 201; |
| 284 | /* Operating Class */ |
| 285 | *pos++ = hapd->iconf->op_class; |
| 286 | /* Coverage Class */ |
| 287 | *pos++ = 0; |
| 288 | /* Subband Triplets are required only for the 20 MHz case */ |
| 289 | if (hapd->iconf->op_class == 131 || |
| 290 | hapd->iconf->op_class == 136) |
| 291 | pos = hostapd_fill_subband_triplets(hapd, pos, end); |
| 292 | } else { |
| 293 | pos = hostapd_fill_subband_triplets(hapd, pos, end); |
| 294 | } |
| 295 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 296 | if ((pos - eid) & 1) { |
| 297 | if (end - pos < 1) |
| 298 | return eid; |
| 299 | *pos++ = 0; /* pad for 16-bit alignment */ |
| 300 | } |
| 301 | |
| 302 | eid[1] = (pos - eid) - 2; |
| 303 | |
| 304 | return pos; |
| 305 | } |
| 306 | |
| 307 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 308 | const u8 * hostapd_wpa_ie(struct hostapd_data *hapd, u8 eid) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 309 | { |
| 310 | const u8 *ies; |
| 311 | size_t ies_len; |
| 312 | |
| 313 | ies = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ies_len); |
| 314 | if (!ies) |
| 315 | return NULL; |
| 316 | |
| 317 | return get_ie(ies, ies_len, eid); |
| 318 | } |
| 319 | |
| 320 | |
| 321 | static const u8 * hostapd_vendor_wpa_ie(struct hostapd_data *hapd, |
| 322 | u32 vendor_type) |
| 323 | { |
| 324 | const u8 *ies; |
| 325 | size_t ies_len; |
| 326 | |
| 327 | ies = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ies_len); |
| 328 | if (!ies) |
| 329 | return NULL; |
| 330 | |
| 331 | return get_vendor_ie(ies, ies_len, vendor_type); |
| 332 | } |
| 333 | |
| 334 | |
| 335 | static u8 * hostapd_get_rsne(struct hostapd_data *hapd, u8 *pos, size_t len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 336 | { |
| 337 | const u8 *ie; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 338 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 339 | ie = hostapd_wpa_ie(hapd, WLAN_EID_RSN); |
| 340 | if (!ie || 2U + ie[1] > len) |
| 341 | return pos; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 342 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 343 | os_memcpy(pos, ie, 2 + ie[1]); |
| 344 | return pos + 2 + ie[1]; |
| 345 | } |
| 346 | |
| 347 | |
| 348 | static u8 * hostapd_get_mde(struct hostapd_data *hapd, u8 *pos, size_t len) |
| 349 | { |
| 350 | const u8 *ie; |
| 351 | |
| 352 | ie = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN); |
| 353 | if (!ie || 2U + ie[1] > len) |
| 354 | return pos; |
| 355 | |
| 356 | os_memcpy(pos, ie, 2 + ie[1]); |
| 357 | return pos + 2 + ie[1]; |
| 358 | } |
| 359 | |
| 360 | |
| 361 | static u8 * hostapd_get_rsnxe(struct hostapd_data *hapd, u8 *pos, size_t len) |
| 362 | { |
| 363 | const u8 *ie; |
| 364 | |
| 365 | #ifdef CONFIG_TESTING_OPTIONS |
| 366 | if (hapd->conf->no_beacon_rsnxe) { |
| 367 | wpa_printf(MSG_INFO, "TESTING: Do not add RSNXE into Beacon"); |
| 368 | return pos; |
| 369 | } |
| 370 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 371 | ie = hostapd_wpa_ie(hapd, WLAN_EID_RSNX); |
| 372 | if (!ie || 2U + ie[1] > len) |
| 373 | return pos; |
| 374 | |
| 375 | os_memcpy(pos, ie, 2 + ie[1]); |
| 376 | return pos + 2 + ie[1]; |
| 377 | } |
| 378 | |
| 379 | |
| 380 | static u8 * hostapd_get_wpa_ie(struct hostapd_data *hapd, u8 *pos, size_t len) |
| 381 | { |
| 382 | const u8 *ie; |
| 383 | |
| 384 | ie = hostapd_vendor_wpa_ie(hapd, WPA_IE_VENDOR_TYPE); |
| 385 | if (!ie || 2U + ie[1] > len) |
| 386 | return pos; |
| 387 | |
| 388 | os_memcpy(pos, ie, 2 + ie[1]); |
| 389 | return pos + 2 + ie[1]; |
| 390 | } |
| 391 | |
| 392 | |
| 393 | static u8 * hostapd_get_osen_ie(struct hostapd_data *hapd, u8 *pos, size_t len) |
| 394 | { |
| 395 | const u8 *ie; |
| 396 | |
| 397 | ie = hostapd_vendor_wpa_ie(hapd, OSEN_IE_VENDOR_TYPE); |
| 398 | if (!ie || 2U + ie[1] > len) |
| 399 | return pos; |
| 400 | |
| 401 | os_memcpy(pos, ie, 2 + ie[1]); |
| 402 | return pos + 2 + ie[1]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 406 | static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid) |
| 407 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 408 | #ifdef CONFIG_TESTING_OPTIONS |
| 409 | if (hapd->iface->cs_oper_class && hapd->iconf->ecsa_ie_only) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 410 | return eid; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 411 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 412 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 413 | if (!hapd->cs_freq_params.channel) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 414 | return eid; |
| 415 | |
| 416 | *eid++ = WLAN_EID_CHANNEL_SWITCH; |
| 417 | *eid++ = 3; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 418 | *eid++ = hapd->cs_block_tx; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 419 | *eid++ = hapd->cs_freq_params.channel; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 420 | *eid++ = hapd->cs_count; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 421 | |
| 422 | return eid; |
| 423 | } |
| 424 | |
| 425 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 426 | static u8 * hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 427 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 428 | if (!hapd->cs_freq_params.channel || !hapd->iface->cs_oper_class) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 429 | return eid; |
| 430 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 431 | *eid++ = WLAN_EID_EXT_CHANSWITCH_ANN; |
| 432 | *eid++ = 4; |
| 433 | *eid++ = hapd->cs_block_tx; |
| 434 | *eid++ = hapd->iface->cs_oper_class; |
| 435 | *eid++ = hapd->cs_freq_params.channel; |
| 436 | *eid++ = hapd->cs_count; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 437 | |
| 438 | return eid; |
| 439 | } |
| 440 | |
| 441 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 442 | static u8 * hostapd_eid_supported_op_classes(struct hostapd_data *hapd, u8 *eid) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 443 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 444 | u8 op_class, channel; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 445 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 446 | if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) || |
| 447 | !hapd->iface->freq) |
| 448 | return eid; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 449 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 450 | if (ieee80211_freq_to_channel_ext(hapd->iface->freq, |
| 451 | hapd->iconf->secondary_channel, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 452 | hostapd_get_oper_chwidth(hapd->iconf), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 453 | &op_class, &channel) == |
| 454 | NUM_HOSTAPD_MODES) |
| 455 | return eid; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 456 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 457 | *eid++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES; |
| 458 | *eid++ = 2; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 459 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 460 | /* Current Operating Class */ |
| 461 | *eid++ = op_class; |
| 462 | |
| 463 | /* TODO: Advertise all the supported operating classes */ |
| 464 | *eid++ = 0; |
| 465 | |
| 466 | return eid; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 470 | static int |
| 471 | ieee802_11_build_ap_params_mbssid(struct hostapd_data *hapd, |
| 472 | struct wpa_driver_ap_params *params) |
| 473 | { |
| 474 | struct hostapd_iface *iface = hapd->iface; |
| 475 | struct hostapd_data *tx_bss; |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 476 | size_t len, rnr_len = 0; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 477 | u8 elem_count = 0, *elem = NULL, **elem_offset = NULL, *end; |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 478 | u8 rnr_elem_count = 0, *rnr_elem = NULL, **rnr_elem_offset = NULL; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 479 | size_t i; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 480 | |
| 481 | if (!iface->mbssid_max_interfaces || |
| 482 | iface->num_bss > iface->mbssid_max_interfaces || |
| 483 | (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED && |
| 484 | !iface->ema_max_periodicity)) |
| 485 | goto fail; |
| 486 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 487 | /* Make sure bss->xrates_supported is set for all BSSs to know whether |
| 488 | * it need to be non-inherited. */ |
| 489 | for (i = 0; i < iface->num_bss; i++) { |
| 490 | u8 buf[100]; |
| 491 | |
| 492 | hostapd_eid_ext_supp_rates(iface->bss[i], buf); |
| 493 | } |
| 494 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 495 | tx_bss = hostapd_mbssid_get_tx_bss(hapd); |
| 496 | len = hostapd_eid_mbssid_len(tx_bss, WLAN_FC_STYPE_BEACON, &elem_count, |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 497 | NULL, 0, &rnr_len); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 498 | if (!len || (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED && |
| 499 | elem_count > iface->ema_max_periodicity)) |
| 500 | goto fail; |
| 501 | |
| 502 | elem = os_zalloc(len); |
| 503 | if (!elem) |
| 504 | goto fail; |
| 505 | |
| 506 | elem_offset = os_zalloc(elem_count * sizeof(u8 *)); |
| 507 | if (!elem_offset) |
| 508 | goto fail; |
| 509 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 510 | if (rnr_len) { |
| 511 | rnr_elem = os_zalloc(rnr_len); |
| 512 | if (!rnr_elem) |
| 513 | goto fail; |
| 514 | |
| 515 | rnr_elem_offset = os_calloc(elem_count + 1, sizeof(u8 *)); |
| 516 | if (!rnr_elem_offset) |
| 517 | goto fail; |
| 518 | } |
| 519 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 520 | end = hostapd_eid_mbssid(tx_bss, elem, elem + len, WLAN_FC_STYPE_BEACON, |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 521 | elem_count, elem_offset, NULL, 0, rnr_elem, |
| 522 | &rnr_elem_count, rnr_elem_offset, rnr_len); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 523 | |
| 524 | params->mbssid_tx_iface = tx_bss->conf->iface; |
| 525 | params->mbssid_index = hostapd_mbssid_get_bss_index(hapd); |
| 526 | params->mbssid_elem = elem; |
| 527 | params->mbssid_elem_len = end - elem; |
| 528 | params->mbssid_elem_count = elem_count; |
| 529 | params->mbssid_elem_offset = elem_offset; |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 530 | params->rnr_elem = rnr_elem; |
| 531 | params->rnr_elem_len = rnr_len; |
| 532 | params->rnr_elem_count = rnr_elem_count; |
| 533 | params->rnr_elem_offset = rnr_elem_offset; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 534 | if (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED) |
| 535 | params->ema = true; |
| 536 | |
| 537 | return 0; |
| 538 | |
| 539 | fail: |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 540 | os_free(rnr_elem); |
| 541 | os_free(rnr_elem_offset); |
| 542 | os_free(elem_offset); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 543 | os_free(elem); |
| 544 | wpa_printf(MSG_ERROR, "MBSSID: Configuration failed"); |
| 545 | return -1; |
| 546 | } |
| 547 | |
| 548 | |
| 549 | static u8 * hostapd_eid_mbssid_config(struct hostapd_data *hapd, u8 *eid, |
| 550 | u8 mbssid_elem_count) |
| 551 | { |
| 552 | struct hostapd_iface *iface = hapd->iface; |
| 553 | |
| 554 | if (iface->conf->mbssid == ENHANCED_MBSSID_ENABLED) { |
| 555 | *eid++ = WLAN_EID_EXTENSION; |
| 556 | *eid++ = 3; |
| 557 | *eid++ = WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION; |
| 558 | *eid++ = iface->num_bss; |
| 559 | *eid++ = mbssid_elem_count; |
| 560 | } |
| 561 | |
| 562 | return eid; |
| 563 | } |
| 564 | |
| 565 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 566 | static size_t he_elem_len(struct hostapd_data *hapd) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 567 | { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 568 | size_t len = 0; |
| 569 | |
| 570 | #ifdef CONFIG_IEEE80211AX |
| 571 | if (!hapd->iconf->ieee80211ax || hapd->conf->disable_11ax) |
| 572 | return len; |
| 573 | |
| 574 | len += 3 + sizeof(struct ieee80211_he_capabilities) + |
| 575 | 3 + sizeof(struct ieee80211_he_operation) + |
| 576 | 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) + |
| 577 | 3 + sizeof(struct ieee80211_spatial_reuse); |
| 578 | if (is_6ghz_op_class(hapd->iconf->op_class)) { |
| 579 | len += sizeof(struct ieee80211_he_6ghz_oper_info) + |
| 580 | 3 + sizeof(struct ieee80211_he_6ghz_band_cap); |
| 581 | /* An additional Transmit Power Envelope element for |
| 582 | * subordinate client */ |
| 583 | if (he_reg_is_indoor(hapd->iconf->he_6ghz_reg_pwr_type)) |
| 584 | len += 4; |
| 585 | |
| 586 | /* An additional Transmit Power Envelope element for |
| 587 | * default client with unit interpretation of regulatory |
| 588 | * client EIRP */ |
| 589 | if (hapd->iconf->reg_def_cli_eirp != -1 && |
| 590 | he_reg_is_sp(hapd->iconf->he_6ghz_reg_pwr_type)) |
| 591 | len += 4; |
| 592 | } |
| 593 | #endif /* CONFIG_IEEE80211AX */ |
| 594 | |
| 595 | return len; |
| 596 | } |
| 597 | |
| 598 | |
| 599 | struct probe_resp_params { |
| 600 | const struct ieee80211_mgmt *req; |
| 601 | bool is_p2p; |
| 602 | |
| 603 | /* Generated IEs will be included inside an ML element */ |
| 604 | bool is_ml_sta_info; |
| 605 | struct hostapd_data *mld_ap; |
| 606 | struct mld_info *mld_info; |
| 607 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 608 | struct ieee80211_mgmt *resp; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 609 | size_t resp_len; |
| 610 | u8 *csa_pos; |
| 611 | u8 *ecsa_pos; |
| 612 | const u8 *known_bss; |
| 613 | u8 known_bss_len; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 614 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 615 | #ifdef CONFIG_IEEE80211AX |
| 616 | u8 *cca_pos; |
| 617 | #endif /* CONFIG_IEEE80211AX */ |
| 618 | }; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 619 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 620 | |
| 621 | static void hostapd_free_probe_resp_params(struct probe_resp_params *params) |
| 622 | { |
| 623 | #ifdef CONFIG_IEEE80211BE |
| 624 | if (!params) |
| 625 | return; |
| 626 | ap_sta_free_sta_profile(params->mld_info); |
| 627 | os_free(params->mld_info); |
| 628 | params->mld_info = NULL; |
| 629 | #endif /* CONFIG_IEEE80211BE */ |
| 630 | } |
| 631 | |
| 632 | |
| 633 | static size_t hostapd_probe_resp_elems_len(struct hostapd_data *hapd, |
| 634 | struct probe_resp_params *params) |
| 635 | { |
| 636 | size_t buflen = 0; |
| 637 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 638 | #ifdef CONFIG_WPS |
| 639 | if (hapd->wps_probe_resp_ie) |
| 640 | buflen += wpabuf_len(hapd->wps_probe_resp_ie); |
| 641 | #endif /* CONFIG_WPS */ |
| 642 | #ifdef CONFIG_P2P |
| 643 | if (hapd->p2p_probe_resp_ie) |
| 644 | buflen += wpabuf_len(hapd->p2p_probe_resp_ie); |
| 645 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 646 | #ifdef CONFIG_FST |
| 647 | if (hapd->iface->fst_ies) |
| 648 | buflen += wpabuf_len(hapd->iface->fst_ies); |
| 649 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 650 | if (hapd->conf->vendor_elements) |
| 651 | buflen += wpabuf_len(hapd->conf->vendor_elements); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 652 | if (hapd->conf->vendor_vht) { |
| 653 | buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) + |
| 654 | 2 + sizeof(struct ieee80211_vht_operation); |
| 655 | } |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 656 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 657 | buflen += he_elem_len(hapd); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 658 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 659 | #ifdef CONFIG_IEEE80211BE |
| 660 | if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) { |
| 661 | buflen += hostapd_eid_eht_capab_len(hapd, IEEE80211_MODE_AP); |
| 662 | buflen += 3 + sizeof(struct ieee80211_eht_operation); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 663 | if (hapd->iconf->punct_bitmap) |
| 664 | buflen += EHT_OPER_DISABLED_SUBCHAN_BITMAP_SIZE; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 665 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 666 | if (!params->is_ml_sta_info && hapd->conf->mld_ap) { |
| 667 | struct hostapd_data *ml_elem_ap = |
| 668 | params->mld_ap ? params->mld_ap : hapd; |
| 669 | |
| 670 | buflen += hostapd_eid_eht_ml_beacon_len( |
| 671 | ml_elem_ap, params->mld_info, !!params->mld_ap); |
| 672 | } |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 673 | } |
| 674 | #endif /* CONFIG_IEEE80211BE */ |
| 675 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 676 | buflen += hostapd_eid_mbssid_len(hapd, WLAN_FC_STYPE_PROBE_RESP, NULL, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 677 | params->known_bss, |
| 678 | params->known_bss_len, NULL); |
| 679 | if (!params->is_ml_sta_info) |
| 680 | buflen += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_PROBE_RESP); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 681 | buflen += hostapd_mbo_ie_len(hapd); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 682 | buflen += hostapd_eid_owe_trans_len(hapd); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 683 | buflen += hostapd_eid_dpp_cc_len(hapd); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 684 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 685 | return buflen; |
| 686 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 687 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 688 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 689 | static u8 * hostapd_probe_resp_fill_elems(struct hostapd_data *hapd, |
| 690 | struct probe_resp_params *params, |
| 691 | u8 *pos, size_t len) |
| 692 | { |
| 693 | u8 *csa_pos; |
| 694 | u8 *epos; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 695 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 696 | epos = pos + len; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 697 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 698 | if (!params->is_ml_sta_info) { |
| 699 | *pos++ = WLAN_EID_SSID; |
| 700 | *pos++ = hapd->conf->ssid.ssid_len; |
| 701 | os_memcpy(pos, hapd->conf->ssid.ssid, |
| 702 | hapd->conf->ssid.ssid_len); |
| 703 | pos += hapd->conf->ssid.ssid_len; |
| 704 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 705 | |
| 706 | /* Supported rates */ |
| 707 | pos = hostapd_eid_supp_rates(hapd, pos); |
| 708 | |
| 709 | /* DS Params */ |
| 710 | pos = hostapd_eid_ds_params(hapd, pos); |
| 711 | |
| 712 | pos = hostapd_eid_country(hapd, pos, epos - pos); |
| 713 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 714 | /* Power Constraint element */ |
| 715 | pos = hostapd_eid_pwr_constraint(hapd, pos); |
| 716 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 717 | /* |
| 718 | * CSA IE |
| 719 | * TODO: This should be included inside the ML sta profile |
| 720 | */ |
| 721 | if (!params->is_ml_sta_info) { |
| 722 | csa_pos = hostapd_eid_csa(hapd, pos); |
| 723 | if (csa_pos != pos) |
| 724 | params->csa_pos = csa_pos - 1; |
| 725 | else |
| 726 | params->csa_pos = NULL; |
| 727 | pos = csa_pos; |
| 728 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 729 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 730 | /* ERP Information element */ |
| 731 | pos = hostapd_eid_erp_info(hapd, pos); |
| 732 | |
| 733 | /* Extended supported rates */ |
| 734 | pos = hostapd_eid_ext_supp_rates(hapd, pos); |
| 735 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 736 | pos = hostapd_get_rsne(hapd, pos, epos - pos); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 737 | pos = hostapd_eid_bss_load(hapd, pos, epos - pos); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 738 | pos = hostapd_eid_mbssid(hapd, pos, epos, WLAN_FC_STYPE_PROBE_RESP, 0, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 739 | NULL, params->known_bss, params->known_bss_len, |
| 740 | NULL, NULL, NULL, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 741 | pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 742 | pos = hostapd_get_mde(hapd, pos, epos - pos); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 743 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 744 | /* |
| 745 | * eCSA IE |
| 746 | * TODO: This should be included inside the ML sta profile |
| 747 | */ |
| 748 | if (!params->is_ml_sta_info) { |
| 749 | csa_pos = hostapd_eid_ecsa(hapd, pos); |
| 750 | if (csa_pos != pos) |
| 751 | params->ecsa_pos = csa_pos - 1; |
| 752 | else |
| 753 | params->ecsa_pos = NULL; |
| 754 | pos = csa_pos; |
| 755 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 756 | |
| 757 | pos = hostapd_eid_supported_op_classes(hapd, pos); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 758 | pos = hostapd_eid_ht_capabilities(hapd, pos); |
| 759 | pos = hostapd_eid_ht_operation(hapd, pos); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 760 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 761 | /* Probe Response frames always include all non-TX profiles except |
| 762 | * when a list of known BSSes is included in the Probe Request frame. */ |
| 763 | pos = hostapd_eid_ext_capab(hapd, pos, |
| 764 | hapd->iconf->mbssid >= MBSSID_ENABLED && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 765 | !params->known_bss_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 766 | |
| 767 | pos = hostapd_eid_time_adv(hapd, pos); |
| 768 | pos = hostapd_eid_time_zone(hapd, pos); |
| 769 | |
| 770 | pos = hostapd_eid_interworking(hapd, pos); |
| 771 | pos = hostapd_eid_adv_proto(hapd, pos); |
| 772 | pos = hostapd_eid_roaming_consortium(hapd, pos); |
| 773 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 774 | #ifdef CONFIG_FST |
| 775 | if (hapd->iface->fst_ies) { |
| 776 | os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies), |
| 777 | wpabuf_len(hapd->iface->fst_ies)); |
| 778 | pos += wpabuf_len(hapd->iface->fst_ies); |
| 779 | } |
| 780 | #endif /* CONFIG_FST */ |
| 781 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 782 | #ifdef CONFIG_IEEE80211AC |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 783 | if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac && |
| 784 | !is_6ghz_op_class(hapd->iconf->op_class)) { |
Dmitry Shmidt | 7d17530 | 2016-09-06 13:11:34 -0700 | [diff] [blame] | 785 | pos = hostapd_eid_vht_capabilities(hapd, pos, 0); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 786 | pos = hostapd_eid_vht_operation(hapd, pos); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 787 | pos = hostapd_eid_txpower_envelope(hapd, pos); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 788 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 789 | #endif /* CONFIG_IEEE80211AC */ |
| 790 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 791 | #ifdef CONFIG_IEEE80211AX |
| 792 | if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax && |
| 793 | is_6ghz_op_class(hapd->iconf->op_class)) |
| 794 | pos = hostapd_eid_txpower_envelope(hapd, pos); |
| 795 | #endif /* CONFIG_IEEE80211AX */ |
| 796 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 797 | pos = hostapd_eid_wb_chsw_wrapper(hapd, pos); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 798 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 799 | if (!params->is_ml_sta_info) |
| 800 | pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_PROBE_RESP); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 801 | pos = hostapd_eid_fils_indic(hapd, pos, 0); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 802 | pos = hostapd_get_rsnxe(hapd, pos, epos - pos); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 803 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 804 | #ifdef CONFIG_IEEE80211AX |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 805 | if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) { |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 806 | u8 *cca_pos; |
| 807 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 808 | pos = hostapd_eid_he_capab(hapd, pos, IEEE80211_MODE_AP); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 809 | pos = hostapd_eid_he_operation(hapd, pos); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 810 | |
| 811 | /* BSS Color Change Announcement element */ |
| 812 | cca_pos = hostapd_eid_cca(hapd, pos); |
| 813 | if (cca_pos != pos) |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 814 | params->cca_pos = cca_pos - 2; |
| 815 | else |
| 816 | params->cca_pos = NULL; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 817 | pos = cca_pos; |
| 818 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 819 | pos = hostapd_eid_spatial_reuse(hapd, pos); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 820 | pos = hostapd_eid_he_mu_edca_parameter_set(hapd, pos); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 821 | pos = hostapd_eid_he_6ghz_band_cap(hapd, pos); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 822 | } |
| 823 | #endif /* CONFIG_IEEE80211AX */ |
| 824 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 825 | #ifdef CONFIG_IEEE80211BE |
| 826 | if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 827 | struct hostapd_data *ml_elem_ap = |
| 828 | params->mld_ap ? params->mld_ap : hapd; |
| 829 | |
| 830 | if (ml_elem_ap->conf->mld_ap) |
| 831 | pos = hostapd_eid_eht_ml_beacon( |
| 832 | ml_elem_ap, params->mld_info, |
| 833 | pos, !!params->mld_ap); |
| 834 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 835 | pos = hostapd_eid_eht_capab(hapd, pos, IEEE80211_MODE_AP); |
| 836 | pos = hostapd_eid_eht_operation(hapd, pos); |
| 837 | } |
| 838 | #endif /* CONFIG_IEEE80211BE */ |
| 839 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 840 | #ifdef CONFIG_IEEE80211AC |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 841 | if (hapd->conf->vendor_vht) |
| 842 | pos = hostapd_eid_vendor_vht(hapd, pos); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 843 | #endif /* CONFIG_IEEE80211AC */ |
| 844 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 845 | /* WPA / OSEN */ |
| 846 | pos = hostapd_get_wpa_ie(hapd, pos, epos - pos); |
| 847 | pos = hostapd_get_osen_ie(hapd, pos, epos - pos); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 848 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 849 | /* Wi-Fi Alliance WMM */ |
| 850 | pos = hostapd_eid_wmm(hapd, pos); |
| 851 | |
| 852 | #ifdef CONFIG_WPS |
| 853 | if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) { |
| 854 | os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie), |
| 855 | wpabuf_len(hapd->wps_probe_resp_ie)); |
| 856 | pos += wpabuf_len(hapd->wps_probe_resp_ie); |
| 857 | } |
| 858 | #endif /* CONFIG_WPS */ |
| 859 | |
| 860 | #ifdef CONFIG_P2P |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 861 | if ((hapd->conf->p2p & P2P_ENABLED) && params->is_p2p && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 862 | hapd->p2p_probe_resp_ie) { |
| 863 | os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie), |
| 864 | wpabuf_len(hapd->p2p_probe_resp_ie)); |
| 865 | pos += wpabuf_len(hapd->p2p_probe_resp_ie); |
| 866 | } |
| 867 | #endif /* CONFIG_P2P */ |
| 868 | #ifdef CONFIG_P2P_MANAGER |
| 869 | if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) == |
| 870 | P2P_MANAGE) |
| 871 | pos = hostapd_eid_p2p_manage(hapd, pos); |
| 872 | #endif /* CONFIG_P2P_MANAGER */ |
| 873 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 874 | #ifdef CONFIG_HS20 |
| 875 | pos = hostapd_eid_hs20_indication(hapd, pos); |
| 876 | #endif /* CONFIG_HS20 */ |
| 877 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 878 | pos = hostapd_eid_mbo(hapd, pos, epos - pos); |
| 879 | pos = hostapd_eid_owe_trans(hapd, pos, epos - pos); |
| 880 | pos = hostapd_eid_dpp_cc(hapd, pos, epos - pos); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 881 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 882 | if (hapd->conf->vendor_elements) { |
| 883 | os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements), |
| 884 | wpabuf_len(hapd->conf->vendor_elements)); |
| 885 | pos += wpabuf_len(hapd->conf->vendor_elements); |
| 886 | } |
| 887 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 888 | return pos; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 892 | static void hostapd_gen_probe_resp(struct hostapd_data *hapd, |
| 893 | struct probe_resp_params *params) |
| 894 | { |
| 895 | u8 *pos; |
| 896 | size_t buflen; |
| 897 | |
| 898 | hapd = hostapd_mbssid_get_tx_bss(hapd); |
| 899 | |
| 900 | #define MAX_PROBERESP_LEN 768 |
| 901 | buflen = MAX_PROBERESP_LEN; |
| 902 | buflen += hostapd_probe_resp_elems_len(hapd, params); |
| 903 | params->resp = os_zalloc(buflen); |
| 904 | if (!params->resp) { |
| 905 | params->resp_len = 0; |
| 906 | return; |
| 907 | } |
| 908 | |
| 909 | params->resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 910 | WLAN_FC_STYPE_PROBE_RESP); |
| 911 | /* Unicast the response to all requests on bands other than 6 GHz. For |
| 912 | * the 6 GHz, unicast is used only if the actual SSID is not included in |
| 913 | * the Beacon frames. Otherwise, broadcast response is used per IEEE |
| 914 | * Std 802.11ax-2021, 26.17.2.3.2. Broadcast address is also used for |
| 915 | * the Probe Response frame template for the unsolicited (i.e., not as |
| 916 | * a response to a specific request) case. */ |
| 917 | if (params->req && (!is_6ghz_op_class(hapd->iconf->op_class) || |
| 918 | hapd->conf->ignore_broadcast_ssid)) |
| 919 | os_memcpy(params->resp->da, params->req->sa, ETH_ALEN); |
| 920 | else |
| 921 | os_memset(params->resp->da, 0xff, ETH_ALEN); |
| 922 | os_memcpy(params->resp->sa, hapd->own_addr, ETH_ALEN); |
| 923 | |
| 924 | os_memcpy(params->resp->bssid, hapd->own_addr, ETH_ALEN); |
| 925 | params->resp->u.probe_resp.beacon_int = |
| 926 | host_to_le16(hapd->iconf->beacon_int); |
| 927 | |
| 928 | /* hardware or low-level driver will setup seq_ctrl and timestamp */ |
| 929 | params->resp->u.probe_resp.capab_info = |
| 930 | host_to_le16(hostapd_own_capab_info(hapd)); |
| 931 | |
| 932 | pos = hostapd_probe_resp_fill_elems(hapd, params, |
| 933 | params->resp->u.probe_resp.variable, |
| 934 | buflen); |
| 935 | |
| 936 | params->resp_len = pos - (u8 *) params->resp; |
| 937 | } |
| 938 | |
| 939 | |
| 940 | #ifdef CONFIG_IEEE80211BE |
| 941 | static void hostapd_fill_probe_resp_ml_params(struct hostapd_data *hapd, |
| 942 | struct probe_resp_params *params, |
| 943 | const struct ieee80211_mgmt *mgmt, |
| 944 | int mld_id, u16 links) |
| 945 | { |
| 946 | struct probe_resp_params sta_info_params; |
| 947 | struct hostapd_data *link; |
| 948 | unsigned int probed_mld_id, i, j; |
| 949 | |
| 950 | params->mld_ap = NULL; |
| 951 | params->mld_info = os_zalloc(sizeof(*params->mld_info)); |
| 952 | if (!params->mld_info) |
| 953 | return; |
| 954 | |
| 955 | wpa_printf(MSG_DEBUG, |
| 956 | "MLD: Got ML probe request with AP MLD ID %d for links %04x", |
| 957 | mld_id, links); |
| 958 | |
| 959 | /* |
| 960 | * We want to include the AP MLD ID in the response if it was |
| 961 | * included in the request. |
| 962 | */ |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 963 | probed_mld_id = mld_id != -1 ? mld_id : hostapd_get_mld_id(hapd); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 964 | |
| 965 | for_each_mld_link(link, i, j, hapd->iface->interfaces, |
| 966 | probed_mld_id) { |
| 967 | struct mld_link_info *link_info; |
| 968 | size_t buflen; |
| 969 | u8 mld_link_id = link->mld_link_id; |
| 970 | u8 *epos; |
| 971 | u8 buf[EHT_ML_MAX_STA_PROF_LEN]; |
| 972 | |
| 973 | /* |
| 974 | * Set mld_ap iff the ML probe request explicitly |
| 975 | * requested a specific MLD ID. In that case, the targeted |
| 976 | * AP may have been a nontransmitted BSSID on the same |
| 977 | * interface. |
| 978 | */ |
| 979 | if (mld_id != -1 && link->iface == hapd->iface) |
| 980 | params->mld_ap = link; |
| 981 | |
| 982 | /* Never duplicate main Probe Response frame body */ |
| 983 | if (link == hapd) |
| 984 | continue; |
| 985 | |
| 986 | /* Only include requested links */ |
| 987 | if (!(BIT(mld_link_id) & links)) |
| 988 | continue; |
| 989 | |
| 990 | link_info = ¶ms->mld_info->links[mld_link_id]; |
| 991 | |
| 992 | sta_info_params.req = params->req; |
| 993 | sta_info_params.is_p2p = false; |
| 994 | sta_info_params.is_ml_sta_info = true; |
| 995 | sta_info_params.mld_ap = NULL; |
| 996 | sta_info_params.mld_info = NULL; |
| 997 | |
| 998 | buflen = MAX_PROBERESP_LEN; |
| 999 | buflen += hostapd_probe_resp_elems_len(link, &sta_info_params); |
| 1000 | |
| 1001 | if (buflen > EHT_ML_MAX_STA_PROF_LEN) { |
| 1002 | wpa_printf(MSG_DEBUG, |
| 1003 | "MLD: Not including link %d in ML probe response (%zu bytes is too long)", |
| 1004 | mld_link_id, buflen); |
| 1005 | goto fail; |
| 1006 | } |
| 1007 | |
| 1008 | /* |
| 1009 | * NOTE: This does not properly handle inheritance and |
| 1010 | * various other things. |
| 1011 | */ |
| 1012 | link_info->valid = true; |
| 1013 | epos = buf; |
| 1014 | |
| 1015 | /* Capabilities is the only fixed parameter */ |
| 1016 | WPA_PUT_LE16(epos, hostapd_own_capab_info(hapd)); |
| 1017 | epos += 2; |
| 1018 | |
| 1019 | epos = hostapd_probe_resp_fill_elems( |
| 1020 | link, &sta_info_params, epos, |
| 1021 | EHT_ML_MAX_STA_PROF_LEN - 2); |
| 1022 | link_info->resp_sta_profile_len = epos - buf; |
| 1023 | os_free(link_info->resp_sta_profile); |
| 1024 | link_info->resp_sta_profile = os_memdup( |
| 1025 | buf, link_info->resp_sta_profile_len); |
| 1026 | if (!link_info->resp_sta_profile) |
| 1027 | link_info->resp_sta_profile_len = 0; |
| 1028 | os_memcpy(link_info->local_addr, link->own_addr, ETH_ALEN); |
| 1029 | |
| 1030 | wpa_printf(MSG_DEBUG, |
| 1031 | "MLD: ML probe response includes link sta info for %d: %u bytes (estimate %zu)", |
| 1032 | mld_link_id, link_info->resp_sta_profile_len, |
| 1033 | buflen); |
| 1034 | } |
| 1035 | |
| 1036 | if (mld_id != -1 && !params->mld_ap) { |
| 1037 | wpa_printf(MSG_DEBUG, |
| 1038 | "MLD: No nontransmitted BSSID for MLD ID %d", |
| 1039 | mld_id); |
| 1040 | goto fail; |
| 1041 | } |
| 1042 | |
| 1043 | return; |
| 1044 | |
| 1045 | fail: |
| 1046 | hostapd_free_probe_resp_params(params); |
| 1047 | params->mld_ap = NULL; |
| 1048 | params->mld_info = NULL; |
| 1049 | } |
| 1050 | #endif /* CONFIG_IEEE80211BE */ |
| 1051 | |
| 1052 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1053 | enum ssid_match_result { |
| 1054 | NO_SSID_MATCH, |
| 1055 | EXACT_SSID_MATCH, |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1056 | WILDCARD_SSID_MATCH, |
| 1057 | CO_LOCATED_SSID_MATCH, |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1058 | }; |
| 1059 | |
| 1060 | static enum ssid_match_result ssid_match(struct hostapd_data *hapd, |
| 1061 | const u8 *ssid, size_t ssid_len, |
| 1062 | const u8 *ssid_list, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1063 | size_t ssid_list_len, |
| 1064 | const u8 *short_ssid_list, |
| 1065 | size_t short_ssid_list_len) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1066 | { |
| 1067 | const u8 *pos, *end; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1068 | struct hostapd_iface *iface = hapd->iface; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1069 | int wildcard = 0; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1070 | size_t i, j; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1071 | |
| 1072 | if (ssid_len == 0) |
| 1073 | wildcard = 1; |
| 1074 | if (ssid_len == hapd->conf->ssid.ssid_len && |
| 1075 | os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0) |
| 1076 | return EXACT_SSID_MATCH; |
| 1077 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1078 | if (ssid_list) { |
| 1079 | pos = ssid_list; |
| 1080 | end = ssid_list + ssid_list_len; |
| 1081 | while (end - pos >= 2) { |
| 1082 | if (2 + pos[1] > end - pos) |
| 1083 | break; |
| 1084 | if (pos[1] == 0) |
| 1085 | wildcard = 1; |
| 1086 | if (pos[1] == hapd->conf->ssid.ssid_len && |
| 1087 | os_memcmp(pos + 2, hapd->conf->ssid.ssid, |
| 1088 | pos[1]) == 0) |
| 1089 | return EXACT_SSID_MATCH; |
| 1090 | pos += 2 + pos[1]; |
| 1091 | } |
| 1092 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1093 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1094 | if (short_ssid_list) { |
| 1095 | pos = short_ssid_list; |
| 1096 | end = short_ssid_list + short_ssid_list_len; |
| 1097 | while (end - pos >= 4) { |
| 1098 | if (hapd->conf->ssid.short_ssid == WPA_GET_LE32(pos)) |
| 1099 | return EXACT_SSID_MATCH; |
| 1100 | pos += 4; |
| 1101 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1102 | } |
| 1103 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1104 | if (wildcard) |
| 1105 | return WILDCARD_SSID_MATCH; |
| 1106 | |
| 1107 | if (!iface->interfaces || iface->interfaces->count <= 1 || |
| 1108 | is_6ghz_op_class(hapd->iconf->op_class)) |
| 1109 | return NO_SSID_MATCH; |
| 1110 | |
| 1111 | for (i = 0; i < iface->interfaces->count; i++) { |
| 1112 | struct hostapd_iface *colocated; |
| 1113 | |
| 1114 | colocated = iface->interfaces->iface[i]; |
| 1115 | |
| 1116 | if (colocated == iface || |
| 1117 | !is_6ghz_op_class(colocated->conf->op_class)) |
| 1118 | continue; |
| 1119 | |
| 1120 | for (j = 0; j < colocated->num_bss; j++) { |
| 1121 | struct hostapd_bss_config *conf; |
| 1122 | |
| 1123 | conf = colocated->bss[j]->conf; |
| 1124 | if (ssid_len == conf->ssid.ssid_len && |
| 1125 | os_memcmp(ssid, conf->ssid.ssid, ssid_len) == 0) |
| 1126 | return CO_LOCATED_SSID_MATCH; |
| 1127 | } |
| 1128 | } |
| 1129 | |
| 1130 | return NO_SSID_MATCH; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1134 | void sta_track_expire(struct hostapd_iface *iface, int force) |
| 1135 | { |
| 1136 | struct os_reltime now; |
| 1137 | struct hostapd_sta_info *info; |
| 1138 | |
| 1139 | if (!iface->num_sta_seen) |
| 1140 | return; |
| 1141 | |
| 1142 | os_get_reltime(&now); |
| 1143 | while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info, |
| 1144 | list))) { |
| 1145 | if (!force && |
| 1146 | !os_reltime_expired(&now, &info->last_seen, |
| 1147 | iface->conf->track_sta_max_age)) |
| 1148 | break; |
| 1149 | force = 0; |
| 1150 | |
| 1151 | wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for " |
| 1152 | MACSTR, iface->bss[0]->conf->iface, |
| 1153 | MAC2STR(info->addr)); |
| 1154 | dl_list_del(&info->list); |
| 1155 | iface->num_sta_seen--; |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 1156 | sta_track_del(info); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | |
| 1161 | static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface, |
| 1162 | const u8 *addr) |
| 1163 | { |
| 1164 | struct hostapd_sta_info *info; |
| 1165 | |
| 1166 | dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list) |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1167 | if (ether_addr_equal(addr, info->addr)) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1168 | return info; |
| 1169 | |
| 1170 | return NULL; |
| 1171 | } |
| 1172 | |
| 1173 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1174 | void sta_track_add(struct hostapd_iface *iface, const u8 *addr, int ssi_signal) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1175 | { |
| 1176 | struct hostapd_sta_info *info; |
| 1177 | |
| 1178 | info = sta_track_get(iface, addr); |
| 1179 | if (info) { |
| 1180 | /* Move the most recent entry to the end of the list */ |
| 1181 | dl_list_del(&info->list); |
| 1182 | dl_list_add_tail(&iface->sta_seen, &info->list); |
| 1183 | os_get_reltime(&info->last_seen); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1184 | info->ssi_signal = ssi_signal; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1185 | return; |
| 1186 | } |
| 1187 | |
| 1188 | /* Add a new entry */ |
| 1189 | info = os_zalloc(sizeof(*info)); |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 1190 | if (info == NULL) |
| 1191 | return; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1192 | os_memcpy(info->addr, addr, ETH_ALEN); |
| 1193 | os_get_reltime(&info->last_seen); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1194 | info->ssi_signal = ssi_signal; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1195 | |
| 1196 | if (iface->num_sta_seen >= iface->conf->track_sta_max_num) { |
| 1197 | /* Expire oldest entry to make room for a new one */ |
| 1198 | sta_track_expire(iface, 1); |
| 1199 | } |
| 1200 | |
| 1201 | wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for " |
| 1202 | MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr)); |
| 1203 | dl_list_add_tail(&iface->sta_seen, &info->list); |
| 1204 | iface->num_sta_seen++; |
| 1205 | } |
| 1206 | |
| 1207 | |
| 1208 | struct hostapd_data * |
| 1209 | sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr, |
| 1210 | const char *ifname) |
| 1211 | { |
| 1212 | struct hapd_interfaces *interfaces = iface->interfaces; |
| 1213 | size_t i, j; |
| 1214 | |
| 1215 | for (i = 0; i < interfaces->count; i++) { |
| 1216 | struct hostapd_data *hapd = NULL; |
| 1217 | |
| 1218 | iface = interfaces->iface[i]; |
| 1219 | for (j = 0; j < iface->num_bss; j++) { |
| 1220 | hapd = iface->bss[j]; |
| 1221 | if (os_strcmp(ifname, hapd->conf->iface) == 0) |
| 1222 | break; |
| 1223 | hapd = NULL; |
| 1224 | } |
| 1225 | |
| 1226 | if (hapd && sta_track_get(iface, addr)) |
| 1227 | return hapd; |
| 1228 | } |
| 1229 | |
| 1230 | return NULL; |
| 1231 | } |
| 1232 | |
| 1233 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 1234 | #ifdef CONFIG_TAXONOMY |
| 1235 | void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr, |
| 1236 | struct wpabuf **probe_ie_taxonomy) |
| 1237 | { |
| 1238 | struct hostapd_sta_info *info; |
| 1239 | |
| 1240 | info = sta_track_get(iface, addr); |
| 1241 | if (!info) |
| 1242 | return; |
| 1243 | |
| 1244 | wpabuf_free(*probe_ie_taxonomy); |
| 1245 | *probe_ie_taxonomy = info->probe_ie_taxonomy; |
| 1246 | info->probe_ie_taxonomy = NULL; |
| 1247 | } |
| 1248 | #endif /* CONFIG_TAXONOMY */ |
| 1249 | |
| 1250 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1251 | #ifdef CONFIG_IEEE80211BE |
| 1252 | static bool parse_ml_probe_req(const struct ieee80211_eht_ml *ml, size_t ml_len, |
| 1253 | int *mld_id, u16 *links) |
| 1254 | { |
| 1255 | u16 ml_control; |
| 1256 | const struct element *sub; |
| 1257 | const u8 *pos; |
| 1258 | size_t len; |
| 1259 | |
| 1260 | *mld_id = -1; |
| 1261 | *links = 0xffff; |
| 1262 | |
| 1263 | if (ml_len < sizeof(struct ieee80211_eht_ml)) |
| 1264 | return false; |
| 1265 | |
| 1266 | ml_control = le_to_host16(ml->ml_control); |
| 1267 | if ((ml_control & MULTI_LINK_CONTROL_TYPE_MASK) != |
| 1268 | MULTI_LINK_CONTROL_TYPE_PROBE_REQ) { |
| 1269 | wpa_printf(MSG_DEBUG, "MLD: Not an ML probe req"); |
| 1270 | return false; |
| 1271 | } |
| 1272 | |
| 1273 | if (sizeof(struct ieee80211_eht_ml) + 1 > ml_len) { |
| 1274 | wpa_printf(MSG_DEBUG, "MLD: ML probe req too short"); |
| 1275 | return false; |
| 1276 | } |
| 1277 | |
| 1278 | pos = ml->variable; |
| 1279 | len = pos[0]; |
| 1280 | if (len < 1 || sizeof(struct ieee80211_eht_ml) + len > ml_len) { |
| 1281 | wpa_printf(MSG_DEBUG, |
| 1282 | "MLD: ML probe request with invalid length"); |
| 1283 | return false; |
| 1284 | } |
| 1285 | |
| 1286 | if (ml_control & EHT_ML_PRES_BM_PROBE_REQ_AP_MLD_ID) { |
| 1287 | if (len < 2) { |
| 1288 | wpa_printf(MSG_DEBUG, |
| 1289 | "MLD: ML probe req too short for MLD ID"); |
| 1290 | return false; |
| 1291 | } |
| 1292 | |
| 1293 | *mld_id = pos[1]; |
| 1294 | } |
| 1295 | pos += len; |
| 1296 | |
| 1297 | /* Parse subelements (if there are any) */ |
| 1298 | len = ml_len - len - sizeof(struct ieee80211_eht_ml); |
| 1299 | for_each_element_id(sub, 0, pos, len) { |
| 1300 | const struct ieee80211_eht_per_sta_profile *sta; |
| 1301 | u16 sta_control; |
| 1302 | |
| 1303 | if (*links == 0xffff) |
| 1304 | *links = 0; |
| 1305 | |
| 1306 | if (sub->datalen < |
| 1307 | sizeof(struct ieee80211_eht_per_sta_profile)) { |
| 1308 | wpa_printf(MSG_DEBUG, |
| 1309 | "MLD: ML probe req %d too short for sta profile", |
| 1310 | sub->datalen); |
| 1311 | return false; |
| 1312 | } |
| 1313 | |
| 1314 | sta = (struct ieee80211_eht_per_sta_profile *) sub->data; |
| 1315 | |
| 1316 | /* |
| 1317 | * Extract the link ID, do not return whether a complete or |
| 1318 | * partial profile was requested. |
| 1319 | */ |
| 1320 | sta_control = le_to_host16(sta->sta_control); |
| 1321 | *links |= BIT(sta_control & EHT_PER_STA_CTRL_LINK_ID_MSK); |
| 1322 | } |
| 1323 | |
| 1324 | if (!for_each_element_completed(sub, pos, len)) { |
| 1325 | wpa_printf(MSG_DEBUG, |
| 1326 | "MLD: ML probe req sub-elements parsing error"); |
| 1327 | return false; |
| 1328 | } |
| 1329 | |
| 1330 | return true; |
| 1331 | } |
| 1332 | #endif /* CONFIG_IEEE80211BE */ |
| 1333 | |
| 1334 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1335 | void handle_probe_req(struct hostapd_data *hapd, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1336 | const struct ieee80211_mgmt *mgmt, size_t len, |
| 1337 | int ssi_signal) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1338 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1339 | struct ieee802_11_elems elems; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1340 | const u8 *ie; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1341 | size_t ie_len; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1342 | size_t i; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1343 | int noack; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1344 | enum ssid_match_result res; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1345 | int ret; |
| 1346 | u16 csa_offs[2]; |
| 1347 | size_t csa_offs_len; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1348 | struct radius_sta rad_info; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1349 | struct probe_resp_params params; |
| 1350 | #ifdef CONFIG_IEEE80211BE |
| 1351 | int mld_id; |
| 1352 | u16 links; |
| 1353 | #endif /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1354 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1355 | if (hapd->iconf->rssi_ignore_probe_request && ssi_signal && |
| 1356 | ssi_signal < hapd->iconf->rssi_ignore_probe_request) |
| 1357 | return; |
| 1358 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1359 | if (len < IEEE80211_HDRLEN) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1360 | return; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1361 | ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1362 | if (hapd->iconf->track_sta_max_num) |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1363 | sta_track_add(hapd->iface, mgmt->sa, ssi_signal); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1364 | ie_len = len - IEEE80211_HDRLEN; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1365 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1366 | ret = hostapd_allowed_address(hapd, mgmt->sa, (const u8 *) mgmt, len, |
| 1367 | &rad_info, 1); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1368 | if (ret == HOSTAPD_ACL_REJECT) { |
| 1369 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, |
| 1370 | "Ignore Probe Request frame from " MACSTR |
| 1371 | " due to ACL reject ", MAC2STR(mgmt->sa)); |
| 1372 | return; |
| 1373 | } |
| 1374 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1375 | for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) |
| 1376 | if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1377 | mgmt->sa, mgmt->da, mgmt->bssid, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1378 | ie, ie_len, ssi_signal) > 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1379 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1380 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1381 | if (!hapd->conf->send_probe_response) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1382 | return; |
| 1383 | |
| 1384 | if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) { |
| 1385 | wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR, |
| 1386 | MAC2STR(mgmt->sa)); |
| 1387 | return; |
| 1388 | } |
| 1389 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1390 | if ((!elems.ssid || !elems.supp_rates)) { |
| 1391 | wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request " |
| 1392 | "without SSID or supported rates element", |
| 1393 | MAC2STR(mgmt->sa)); |
| 1394 | return; |
| 1395 | } |
| 1396 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1397 | /* |
| 1398 | * No need to reply if the Probe Request frame was sent on an adjacent |
| 1399 | * channel. IEEE Std 802.11-2012 describes this as a requirement for an |
| 1400 | * AP with dot11RadioMeasurementActivated set to true, but strictly |
| 1401 | * speaking does not allow such ignoring of Probe Request frames if |
| 1402 | * dot11RadioMeasurementActivated is false. Anyway, this can help reduce |
| 1403 | * number of unnecessary Probe Response frames for cases where the STA |
| 1404 | * is less likely to see them (Probe Request frame sent on a |
| 1405 | * neighboring, but partially overlapping, channel). |
| 1406 | */ |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 1407 | if (elems.ds_params && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1408 | hapd->iface->current_mode && |
| 1409 | (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G || |
| 1410 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) && |
| 1411 | hapd->iconf->channel != elems.ds_params[0]) { |
| 1412 | wpa_printf(MSG_DEBUG, |
| 1413 | "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u", |
| 1414 | hapd->iconf->channel, elems.ds_params[0]); |
| 1415 | return; |
| 1416 | } |
| 1417 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1418 | #ifdef CONFIG_P2P |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 1419 | if (hapd->p2p && hapd->p2p_group && elems.wps_ie) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1420 | struct wpabuf *wps; |
| 1421 | wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA); |
| 1422 | if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) { |
| 1423 | wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request " |
| 1424 | "due to mismatch with Requested Device " |
| 1425 | "Type"); |
| 1426 | wpabuf_free(wps); |
| 1427 | return; |
| 1428 | } |
| 1429 | wpabuf_free(wps); |
| 1430 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1431 | |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 1432 | if (hapd->p2p && hapd->p2p_group && elems.p2p) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1433 | struct wpabuf *p2p; |
| 1434 | p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE); |
| 1435 | if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) { |
| 1436 | wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request " |
| 1437 | "due to mismatch with Device ID"); |
| 1438 | wpabuf_free(p2p); |
| 1439 | return; |
| 1440 | } |
| 1441 | wpabuf_free(p2p); |
| 1442 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1443 | #endif /* CONFIG_P2P */ |
| 1444 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1445 | if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1446 | elems.ssid_list_len == 0 && elems.short_ssid_list_len == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1447 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for " |
| 1448 | "broadcast SSID ignored", MAC2STR(mgmt->sa)); |
| 1449 | return; |
| 1450 | } |
| 1451 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1452 | #ifdef CONFIG_P2P |
| 1453 | if ((hapd->conf->p2p & P2P_GROUP_OWNER) && |
| 1454 | elems.ssid_len == P2P_WILDCARD_SSID_LEN && |
| 1455 | os_memcmp(elems.ssid, P2P_WILDCARD_SSID, |
| 1456 | P2P_WILDCARD_SSID_LEN) == 0) { |
| 1457 | /* Process P2P Wildcard SSID like Wildcard SSID */ |
| 1458 | elems.ssid_len = 0; |
| 1459 | } |
| 1460 | #endif /* CONFIG_P2P */ |
| 1461 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 1462 | #ifdef CONFIG_TAXONOMY |
| 1463 | { |
| 1464 | struct sta_info *sta; |
| 1465 | struct hostapd_sta_info *info; |
| 1466 | |
| 1467 | if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) { |
| 1468 | taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len); |
| 1469 | } else if ((info = sta_track_get(hapd->iface, |
| 1470 | mgmt->sa)) != NULL) { |
| 1471 | taxonomy_hostapd_sta_info_probe_req(hapd, info, |
| 1472 | ie, ie_len); |
| 1473 | } |
| 1474 | } |
| 1475 | #endif /* CONFIG_TAXONOMY */ |
| 1476 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1477 | res = ssid_match(hapd, elems.ssid, elems.ssid_len, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1478 | elems.ssid_list, elems.ssid_list_len, |
| 1479 | elems.short_ssid_list, elems.short_ssid_list_len); |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 1480 | if (res == NO_SSID_MATCH) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1481 | if (!(mgmt->da[0] & 0x01)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1482 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1483 | " for foreign SSID '%s' (DA " MACSTR ")%s", |
Dmitry Shmidt | 3c47937 | 2014-02-04 10:50:36 -0800 | [diff] [blame] | 1484 | MAC2STR(mgmt->sa), |
| 1485 | wpa_ssid_txt(elems.ssid, elems.ssid_len), |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1486 | MAC2STR(mgmt->da), |
| 1487 | elems.ssid_list ? " (SSID list)" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1488 | } |
| 1489 | return; |
| 1490 | } |
| 1491 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1492 | if (hapd->conf->ignore_broadcast_ssid && res == WILDCARD_SSID_MATCH) { |
| 1493 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for " |
| 1494 | "broadcast SSID ignored", MAC2STR(mgmt->sa)); |
| 1495 | return; |
| 1496 | } |
| 1497 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1498 | #ifdef CONFIG_INTERWORKING |
Dmitry Shmidt | f9bdef9 | 2014-04-25 10:46:36 -0700 | [diff] [blame] | 1499 | if (hapd->conf->interworking && |
| 1500 | elems.interworking && elems.interworking_len >= 1) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1501 | u8 ant = elems.interworking[0] & 0x0f; |
| 1502 | if (ant != INTERWORKING_ANT_WILDCARD && |
| 1503 | ant != hapd->conf->access_network_type) { |
| 1504 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR |
| 1505 | " for mismatching ANT %u ignored", |
| 1506 | MAC2STR(mgmt->sa), ant); |
| 1507 | return; |
| 1508 | } |
| 1509 | } |
| 1510 | |
Dmitry Shmidt | f9bdef9 | 2014-04-25 10:46:36 -0700 | [diff] [blame] | 1511 | if (hapd->conf->interworking && elems.interworking && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1512 | (elems.interworking_len == 7 || elems.interworking_len == 9)) { |
| 1513 | const u8 *hessid; |
| 1514 | if (elems.interworking_len == 7) |
| 1515 | hessid = elems.interworking + 1; |
| 1516 | else |
| 1517 | hessid = elems.interworking + 1 + 2; |
| 1518 | if (!is_broadcast_ether_addr(hessid) && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1519 | !ether_addr_equal(hessid, hapd->conf->hessid)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1520 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR |
| 1521 | " for mismatching HESSID " MACSTR |
| 1522 | " ignored", |
| 1523 | MAC2STR(mgmt->sa), MAC2STR(hessid)); |
| 1524 | return; |
| 1525 | } |
| 1526 | } |
| 1527 | #endif /* CONFIG_INTERWORKING */ |
| 1528 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1529 | #ifdef CONFIG_P2P |
| 1530 | if ((hapd->conf->p2p & P2P_GROUP_OWNER) && |
| 1531 | supp_rates_11b_only(&elems)) { |
| 1532 | /* Indicates support for 11b rates only */ |
| 1533 | wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from " |
| 1534 | MACSTR " with only 802.11b rates", |
| 1535 | MAC2STR(mgmt->sa)); |
| 1536 | return; |
| 1537 | } |
| 1538 | #endif /* CONFIG_P2P */ |
| 1539 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1540 | /* TODO: verify that supp_rates contains at least one matching rate |
| 1541 | * with AP configuration */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1542 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1543 | if (hapd->conf->no_probe_resp_if_seen_on && |
| 1544 | is_multicast_ether_addr(mgmt->da) && |
| 1545 | is_multicast_ether_addr(mgmt->bssid) && |
| 1546 | sta_track_seen_on(hapd->iface, mgmt->sa, |
| 1547 | hapd->conf->no_probe_resp_if_seen_on)) { |
| 1548 | wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR |
| 1549 | " since STA has been seen on %s", |
| 1550 | hapd->conf->iface, MAC2STR(mgmt->sa), |
| 1551 | hapd->conf->no_probe_resp_if_seen_on); |
| 1552 | return; |
| 1553 | } |
| 1554 | |
| 1555 | if (hapd->conf->no_probe_resp_if_max_sta && |
| 1556 | is_multicast_ether_addr(mgmt->da) && |
| 1557 | is_multicast_ether_addr(mgmt->bssid) && |
| 1558 | hapd->num_sta >= hapd->conf->max_num_sta && |
| 1559 | !ap_get_sta(hapd, mgmt->sa)) { |
| 1560 | wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR |
| 1561 | " since no room for additional STA", |
| 1562 | hapd->conf->iface, MAC2STR(mgmt->sa)); |
| 1563 | return; |
| 1564 | } |
| 1565 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1566 | #ifdef CONFIG_TESTING_OPTIONS |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 1567 | if (hapd->iconf->ignore_probe_probability > 0.0 && |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1568 | drand48() < hapd->iconf->ignore_probe_probability) { |
| 1569 | wpa_printf(MSG_INFO, |
| 1570 | "TESTING: ignoring probe request from " MACSTR, |
| 1571 | MAC2STR(mgmt->sa)); |
| 1572 | return; |
| 1573 | } |
| 1574 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 1575 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1576 | /* Do not send Probe Response frame from a non-transmitting multiple |
| 1577 | * BSSID profile unless the Probe Request frame is directed at that |
| 1578 | * particular BSS. */ |
| 1579 | if (hapd != hostapd_mbssid_get_tx_bss(hapd) && res != EXACT_SSID_MATCH) |
| 1580 | return; |
| 1581 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1582 | wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, RX_PROBE_REQUEST "sa=" MACSTR |
| 1583 | " signal=%d", MAC2STR(mgmt->sa), ssi_signal); |
| 1584 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1585 | os_memset(¶ms, 0, sizeof(params)); |
| 1586 | |
| 1587 | #ifdef CONFIG_IEEE80211BE |
| 1588 | if (hapd->conf->mld_ap && elems.probe_req_mle && |
| 1589 | parse_ml_probe_req((struct ieee80211_eht_ml *) elems.probe_req_mle, |
| 1590 | elems.probe_req_mle_len, &mld_id, &links)) { |
| 1591 | hostapd_fill_probe_resp_ml_params(hapd, ¶ms, mgmt, |
| 1592 | mld_id, links); |
| 1593 | } |
| 1594 | #endif /* CONFIG_IEEE80211BE */ |
| 1595 | |
| 1596 | params.req = mgmt; |
| 1597 | params.is_p2p = !!elems.p2p; |
| 1598 | params.known_bss = elems.mbssid_known_bss; |
| 1599 | params.known_bss_len = elems.mbssid_known_bss_len; |
| 1600 | params.is_ml_sta_info = false; |
| 1601 | |
| 1602 | hostapd_gen_probe_resp(hapd, ¶ms); |
| 1603 | |
| 1604 | hostapd_free_probe_resp_params(¶ms); |
| 1605 | |
| 1606 | if (!params.resp) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1607 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1608 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1609 | /* |
| 1610 | * If this is a broadcast probe request, apply no ack policy to avoid |
| 1611 | * excessive retries. |
| 1612 | */ |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1613 | noack = !!(res == WILDCARD_SSID_MATCH && |
| 1614 | is_broadcast_ether_addr(mgmt->da)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1615 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1616 | csa_offs_len = 0; |
| 1617 | if (hapd->csa_in_progress) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1618 | if (params.csa_pos) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1619 | csa_offs[csa_offs_len++] = |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1620 | params.csa_pos - (u8 *) params.resp; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1621 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1622 | if (params.ecsa_pos) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1623 | csa_offs[csa_offs_len++] = |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1624 | params.ecsa_pos - (u8 *) params.resp; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1625 | } |
| 1626 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1627 | ret = hostapd_drv_send_mlme(hapd, params.resp, params.resp_len, noack, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1628 | csa_offs_len ? csa_offs : NULL, |
| 1629 | csa_offs_len, 0); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1630 | |
| 1631 | if (ret < 0) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1632 | wpa_printf(MSG_INFO, "handle_probe_req: send failed"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1633 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1634 | os_free(params.resp); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1635 | |
| 1636 | wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s " |
| 1637 | "SSID", MAC2STR(mgmt->sa), |
| 1638 | elems.ssid_len == 0 ? "broadcast" : "our"); |
| 1639 | } |
| 1640 | |
| 1641 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1642 | static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd, |
| 1643 | size_t *resp_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1644 | { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1645 | struct probe_resp_params params; |
| 1646 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1647 | /* check probe response offloading caps and print warnings */ |
| 1648 | if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD)) |
| 1649 | return NULL; |
| 1650 | |
| 1651 | #ifdef CONFIG_WPS |
| 1652 | if (hapd->conf->wps_state && hapd->wps_probe_resp_ie && |
| 1653 | (!(hapd->iface->probe_resp_offloads & |
| 1654 | (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS | |
| 1655 | WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2)))) |
| 1656 | wpa_printf(MSG_WARNING, "Device is trying to offload WPS " |
| 1657 | "Probe Response while not supporting this"); |
| 1658 | #endif /* CONFIG_WPS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1659 | |
| 1660 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1661 | if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie && |
| 1662 | !(hapd->iface->probe_resp_offloads & |
| 1663 | WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P)) |
| 1664 | wpa_printf(MSG_WARNING, "Device is trying to offload P2P " |
| 1665 | "Probe Response while not supporting this"); |
| 1666 | #endif /* CONFIG_P2P */ |
| 1667 | |
| 1668 | if (hapd->conf->interworking && |
| 1669 | !(hapd->iface->probe_resp_offloads & |
| 1670 | WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING)) |
| 1671 | wpa_printf(MSG_WARNING, "Device is trying to offload " |
| 1672 | "Interworking Probe Response while not supporting " |
| 1673 | "this"); |
| 1674 | |
| 1675 | /* Generate a Probe Response template for the non-P2P case */ |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1676 | os_memset(¶ms, 0, sizeof(params)); |
| 1677 | params.req = NULL; |
| 1678 | params.is_p2p = false; |
| 1679 | params.known_bss = NULL; |
| 1680 | params.known_bss_len = 0; |
| 1681 | params.is_ml_sta_info = false; |
| 1682 | params.mld_ap = NULL; |
| 1683 | params.mld_info = NULL; |
| 1684 | |
| 1685 | hostapd_gen_probe_resp(hapd, ¶ms); |
| 1686 | *resp_len = params.resp_len; |
| 1687 | if (!params.resp) |
| 1688 | return NULL; |
| 1689 | |
| 1690 | /* TODO: Avoid passing these through struct hostapd_data */ |
| 1691 | if (params.csa_pos) |
| 1692 | hapd->cs_c_off_proberesp = params.csa_pos - (u8 *) params.resp; |
| 1693 | if (params.ecsa_pos) |
| 1694 | hapd->cs_c_off_ecsa_proberesp = params.ecsa_pos - |
| 1695 | (u8 *) params.resp; |
| 1696 | #ifdef CONFIG_IEEE80211AX |
| 1697 | if (params.cca_pos) |
| 1698 | hapd->cca_c_off_proberesp = params.cca_pos - (u8 *) params.resp; |
| 1699 | #endif /* CONFIG_IEEE80211AX */ |
| 1700 | |
| 1701 | return (u8 *) params.resp; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1702 | } |
| 1703 | |
| 1704 | #endif /* NEED_AP_MLME */ |
| 1705 | |
| 1706 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1707 | #ifdef CONFIG_IEEE80211AX |
| 1708 | /* Unsolicited broadcast Probe Response transmission, 6 GHz only */ |
| 1709 | static u8 * hostapd_unsol_bcast_probe_resp(struct hostapd_data *hapd, |
| 1710 | struct wpa_driver_ap_params *params) |
| 1711 | { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1712 | struct probe_resp_params probe_params; |
| 1713 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1714 | if (!is_6ghz_op_class(hapd->iconf->op_class)) |
| 1715 | return NULL; |
| 1716 | |
| 1717 | params->unsol_bcast_probe_resp_interval = |
| 1718 | hapd->conf->unsol_bcast_probe_resp_interval; |
| 1719 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1720 | os_memset(&probe_params, 0, sizeof(probe_params)); |
| 1721 | probe_params.req = NULL; |
| 1722 | probe_params.is_p2p = false; |
| 1723 | probe_params.known_bss = NULL; |
| 1724 | probe_params.known_bss_len = 0; |
| 1725 | probe_params.is_ml_sta_info = false; |
| 1726 | probe_params.mld_ap = NULL; |
| 1727 | probe_params.mld_info = NULL; |
| 1728 | |
| 1729 | hostapd_gen_probe_resp(hapd, &probe_params); |
| 1730 | params->unsol_bcast_probe_resp_tmpl_len = probe_params.resp_len; |
| 1731 | return (u8 *) probe_params.resp; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1732 | } |
| 1733 | #endif /* CONFIG_IEEE80211AX */ |
| 1734 | |
| 1735 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 1736 | void sta_track_del(struct hostapd_sta_info *info) |
| 1737 | { |
| 1738 | #ifdef CONFIG_TAXONOMY |
| 1739 | wpabuf_free(info->probe_ie_taxonomy); |
| 1740 | info->probe_ie_taxonomy = NULL; |
| 1741 | #endif /* CONFIG_TAXONOMY */ |
| 1742 | os_free(info); |
| 1743 | } |
| 1744 | |
| 1745 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1746 | #ifdef CONFIG_FILS |
| 1747 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1748 | static u16 hostapd_gen_fils_discovery_phy_index(struct hostapd_data *hapd) |
| 1749 | { |
| 1750 | #ifdef CONFIG_IEEE80211BE |
| 1751 | if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) |
| 1752 | return FD_CAP_PHY_INDEX_EHT; |
| 1753 | #endif /* CONFIG_IEEE80211BE */ |
| 1754 | |
| 1755 | #ifdef CONFIG_IEEE80211AX |
| 1756 | if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) |
| 1757 | return FD_CAP_PHY_INDEX_HE; |
| 1758 | #endif /* CONFIG_IEEE80211AX */ |
| 1759 | |
| 1760 | #ifdef CONFIG_IEEE80211AC |
| 1761 | if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) |
| 1762 | return FD_CAP_PHY_INDEX_VHT; |
| 1763 | #endif /* CONFIG_IEEE80211AC */ |
| 1764 | |
| 1765 | if (hapd->iconf->ieee80211n && !hapd->conf->disable_11n) |
| 1766 | return FD_CAP_PHY_INDEX_HT; |
| 1767 | |
| 1768 | return 0; |
| 1769 | } |
| 1770 | |
| 1771 | |
| 1772 | static u16 hostapd_gen_fils_discovery_nss(struct hostapd_hw_modes *mode, |
| 1773 | u16 phy_index, u8 he_mcs_nss_size) |
| 1774 | { |
| 1775 | u16 nss = 0; |
| 1776 | |
| 1777 | if (!mode) |
| 1778 | return 0; |
| 1779 | |
| 1780 | if (phy_index == FD_CAP_PHY_INDEX_HE) { |
| 1781 | const u8 *he_mcs = mode->he_capab[IEEE80211_MODE_AP].mcs; |
| 1782 | int i; |
| 1783 | u16 mcs[6]; |
| 1784 | |
| 1785 | os_memset(mcs, 0xff, 6 * sizeof(u16)); |
| 1786 | |
| 1787 | if (he_mcs_nss_size == 4) { |
| 1788 | mcs[0] = WPA_GET_LE16(&he_mcs[0]); |
| 1789 | mcs[1] = WPA_GET_LE16(&he_mcs[2]); |
| 1790 | } |
| 1791 | |
| 1792 | if (he_mcs_nss_size == 8) { |
| 1793 | mcs[2] = WPA_GET_LE16(&he_mcs[4]); |
| 1794 | mcs[3] = WPA_GET_LE16(&he_mcs[6]); |
| 1795 | } |
| 1796 | |
| 1797 | if (he_mcs_nss_size == 12) { |
| 1798 | mcs[4] = WPA_GET_LE16(&he_mcs[8]); |
| 1799 | mcs[5] = WPA_GET_LE16(&he_mcs[10]); |
| 1800 | } |
| 1801 | |
| 1802 | for (i = 0; i < HE_NSS_MAX_STREAMS; i++) { |
| 1803 | u16 nss_mask = 0x3 << (i * 2); |
| 1804 | |
| 1805 | /* |
| 1806 | * If Tx and/or Rx indicate support for a given NSS, |
| 1807 | * count it towards the maximum NSS. |
| 1808 | */ |
| 1809 | if (he_mcs_nss_size == 4 && |
| 1810 | (((mcs[0] & nss_mask) != nss_mask) || |
| 1811 | ((mcs[1] & nss_mask) != nss_mask))) { |
| 1812 | nss++; |
| 1813 | continue; |
| 1814 | } |
| 1815 | |
| 1816 | if (he_mcs_nss_size == 8 && |
| 1817 | (((mcs[2] & nss_mask) != nss_mask) || |
| 1818 | ((mcs[3] & nss_mask) != nss_mask))) { |
| 1819 | nss++; |
| 1820 | continue; |
| 1821 | } |
| 1822 | |
| 1823 | if (he_mcs_nss_size == 12 && |
| 1824 | (((mcs[4] & nss_mask) != nss_mask) || |
| 1825 | ((mcs[5] & nss_mask) != nss_mask))) { |
| 1826 | nss++; |
| 1827 | continue; |
| 1828 | } |
| 1829 | } |
| 1830 | } else if (phy_index == FD_CAP_PHY_INDEX_EHT) { |
| 1831 | u8 rx_nss, tx_nss, max_nss = 0, i; |
| 1832 | u8 *mcs = mode->eht_capab[IEEE80211_MODE_AP].mcs; |
| 1833 | |
| 1834 | /* |
| 1835 | * The Supported EHT-MCS And NSS Set field for the AP contains |
| 1836 | * one to three EHT-MCS Map fields based on the supported |
| 1837 | * bandwidth. Check the first byte (max NSS for Rx/Tx that |
| 1838 | * supports EHT-MCS 0-9) for each bandwidth (<= 80, |
| 1839 | * 160, 320) to find the maximum NSS. This assumes that |
| 1840 | * the lowest MCS rates support the largest number of spatial |
| 1841 | * streams. If values are different between Tx, Rx or the |
| 1842 | * bandwidths, choose the highest value. |
| 1843 | */ |
| 1844 | for (i = 0; i < 3; i++) { |
| 1845 | rx_nss = mcs[3 * i] & 0x0F; |
| 1846 | if (rx_nss > max_nss) |
| 1847 | max_nss = rx_nss; |
| 1848 | |
| 1849 | tx_nss = (mcs[3 * i] & 0xF0) >> 4; |
| 1850 | if (tx_nss > max_nss) |
| 1851 | max_nss = tx_nss; |
| 1852 | } |
| 1853 | |
| 1854 | nss = max_nss; |
| 1855 | } |
| 1856 | |
| 1857 | if (nss > 4) |
| 1858 | return FD_CAP_NSS_5_8 << FD_CAP_NSS_SHIFT; |
| 1859 | if (nss) |
| 1860 | return (nss - 1) << FD_CAP_NSS_SHIFT; |
| 1861 | |
| 1862 | return 0; |
| 1863 | } |
| 1864 | |
| 1865 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1866 | static u16 hostapd_fils_discovery_cap(struct hostapd_data *hapd) |
| 1867 | { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1868 | u16 cap_info, phy_index; |
| 1869 | u8 chwidth = FD_CAP_BSS_CHWIDTH_20, he_mcs_nss_size = 4; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1870 | struct hostapd_hw_modes *mode = hapd->iface->current_mode; |
| 1871 | |
| 1872 | cap_info = FD_CAP_ESS; |
| 1873 | if (hapd->conf->wpa) |
| 1874 | cap_info |= FD_CAP_PRIVACY; |
| 1875 | |
| 1876 | if (is_6ghz_op_class(hapd->iconf->op_class)) { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1877 | switch (hapd->iconf->op_class) { |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 1878 | case 137: |
| 1879 | chwidth = FD_CAP_BSS_CHWIDTH_320; |
| 1880 | break; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1881 | case 135: |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1882 | he_mcs_nss_size += 4; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1883 | /* fallthrough */ |
| 1884 | case 134: |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1885 | he_mcs_nss_size += 4; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1886 | chwidth = FD_CAP_BSS_CHWIDTH_160_80_80; |
| 1887 | break; |
| 1888 | case 133: |
| 1889 | chwidth = FD_CAP_BSS_CHWIDTH_80; |
| 1890 | break; |
| 1891 | case 132: |
| 1892 | chwidth = FD_CAP_BSS_CHWIDTH_40; |
| 1893 | break; |
| 1894 | } |
| 1895 | } else { |
| 1896 | switch (hostapd_get_oper_chwidth(hapd->iconf)) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1897 | case CONF_OPER_CHWIDTH_80P80MHZ: |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1898 | he_mcs_nss_size += 4; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1899 | /* fallthrough */ |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1900 | case CONF_OPER_CHWIDTH_160MHZ: |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1901 | he_mcs_nss_size += 4; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1902 | chwidth = FD_CAP_BSS_CHWIDTH_160_80_80; |
| 1903 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1904 | case CONF_OPER_CHWIDTH_80MHZ: |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1905 | chwidth = FD_CAP_BSS_CHWIDTH_80; |
| 1906 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1907 | case CONF_OPER_CHWIDTH_USE_HT: |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1908 | if (hapd->iconf->secondary_channel) |
| 1909 | chwidth = FD_CAP_BSS_CHWIDTH_40; |
| 1910 | else |
| 1911 | chwidth = FD_CAP_BSS_CHWIDTH_20; |
| 1912 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1913 | default: |
| 1914 | break; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1915 | } |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1916 | } |
| 1917 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1918 | phy_index = hostapd_gen_fils_discovery_phy_index(hapd); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1919 | cap_info |= phy_index << FD_CAP_PHY_INDEX_SHIFT; |
| 1920 | cap_info |= chwidth << FD_CAP_BSS_CHWIDTH_SHIFT; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1921 | cap_info |= hostapd_gen_fils_discovery_nss(mode, phy_index, |
| 1922 | he_mcs_nss_size); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1923 | return cap_info; |
| 1924 | } |
| 1925 | |
| 1926 | |
| 1927 | static u8 * hostapd_gen_fils_discovery(struct hostapd_data *hapd, size_t *len) |
| 1928 | { |
| 1929 | struct ieee80211_mgmt *head; |
| 1930 | const u8 *mobility_domain; |
| 1931 | u8 *pos, *length_pos, buf[200]; |
| 1932 | u16 ctl = 0; |
| 1933 | u8 fd_rsn_info[5]; |
| 1934 | size_t total_len, buf_len; |
| 1935 | |
| 1936 | total_len = 24 + 2 + 12; |
| 1937 | |
| 1938 | /* FILS Discovery Frame Control */ |
| 1939 | ctl = (sizeof(hapd->conf->ssid.short_ssid) - 1) | |
| 1940 | FD_FRAME_CTL_SHORT_SSID_PRESENT | |
| 1941 | FD_FRAME_CTL_LENGTH_PRESENT | |
| 1942 | FD_FRAME_CTL_CAP_PRESENT; |
| 1943 | total_len += 4 + 1 + 2; |
| 1944 | |
| 1945 | /* Check for optional subfields and calculate length */ |
| 1946 | if (wpa_auth_write_fd_rsn_info(hapd->wpa_auth, fd_rsn_info)) { |
| 1947 | ctl |= FD_FRAME_CTL_RSN_INFO_PRESENT; |
| 1948 | total_len += sizeof(fd_rsn_info); |
| 1949 | } |
| 1950 | |
| 1951 | mobility_domain = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN); |
| 1952 | if (mobility_domain) { |
| 1953 | ctl |= FD_FRAME_CTL_MD_PRESENT; |
| 1954 | total_len += 3; |
| 1955 | } |
| 1956 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1957 | total_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_ACTION); |
| 1958 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1959 | pos = hostapd_eid_fils_indic(hapd, buf, 0); |
| 1960 | buf_len = pos - buf; |
| 1961 | total_len += buf_len; |
| 1962 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1963 | /* he_elem_len() may return too large a value for FD frame, but that is |
| 1964 | * fine here since this is used as the maximum length of the buffer. */ |
| 1965 | total_len += he_elem_len(hapd); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1966 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1967 | head = os_zalloc(total_len); |
| 1968 | if (!head) |
| 1969 | return NULL; |
| 1970 | |
| 1971 | head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 1972 | WLAN_FC_STYPE_ACTION); |
| 1973 | os_memset(head->da, 0xff, ETH_ALEN); |
| 1974 | os_memcpy(head->sa, hapd->own_addr, ETH_ALEN); |
| 1975 | os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN); |
| 1976 | |
| 1977 | head->u.action.category = WLAN_ACTION_PUBLIC; |
| 1978 | head->u.action.u.public_action.action = WLAN_PA_FILS_DISCOVERY; |
| 1979 | |
| 1980 | pos = &head->u.action.u.public_action.variable[0]; |
| 1981 | |
| 1982 | /* FILS Discovery Information field */ |
| 1983 | |
| 1984 | /* FILS Discovery Frame Control */ |
| 1985 | WPA_PUT_LE16(pos, ctl); |
| 1986 | pos += 2; |
| 1987 | |
| 1988 | /* Hardware or low-level driver will fill in the Timestamp value */ |
| 1989 | pos += 8; |
| 1990 | |
| 1991 | /* Beacon Interval */ |
| 1992 | WPA_PUT_LE16(pos, hapd->iconf->beacon_int); |
| 1993 | pos += 2; |
| 1994 | |
| 1995 | /* Short SSID */ |
| 1996 | WPA_PUT_LE32(pos, hapd->conf->ssid.short_ssid); |
| 1997 | pos += sizeof(hapd->conf->ssid.short_ssid); |
| 1998 | |
| 1999 | /* Store position of FILS discovery information element Length field */ |
| 2000 | length_pos = pos++; |
| 2001 | |
| 2002 | /* FD Capability */ |
| 2003 | WPA_PUT_LE16(pos, hostapd_fils_discovery_cap(hapd)); |
| 2004 | pos += 2; |
| 2005 | |
| 2006 | /* Operating Class - not present */ |
| 2007 | |
| 2008 | /* Primary Channel - not present */ |
| 2009 | |
| 2010 | /* AP Configuration Sequence Number - not present */ |
| 2011 | |
| 2012 | /* Access Network Options - not present */ |
| 2013 | |
| 2014 | /* FD RSN Information */ |
| 2015 | if (ctl & FD_FRAME_CTL_RSN_INFO_PRESENT) { |
| 2016 | os_memcpy(pos, fd_rsn_info, sizeof(fd_rsn_info)); |
| 2017 | pos += sizeof(fd_rsn_info); |
| 2018 | } |
| 2019 | |
| 2020 | /* Channel Center Frequency Segment 1 - not present */ |
| 2021 | |
| 2022 | /* Mobility Domain */ |
| 2023 | if (ctl & FD_FRAME_CTL_MD_PRESENT) { |
| 2024 | os_memcpy(pos, &mobility_domain[2], 3); |
| 2025 | pos += 3; |
| 2026 | } |
| 2027 | |
| 2028 | /* Fill in the Length field value */ |
| 2029 | *length_pos = pos - (length_pos + 1); |
| 2030 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2031 | pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_ACTION); |
| 2032 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2033 | /* FILS Indication element */ |
| 2034 | if (buf_len) { |
| 2035 | os_memcpy(pos, buf, buf_len); |
| 2036 | pos += buf_len; |
| 2037 | } |
| 2038 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2039 | if (is_6ghz_op_class(hapd->iconf->op_class)) |
| 2040 | pos = hostapd_eid_txpower_envelope(hapd, pos); |
| 2041 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2042 | *len = pos - (u8 *) head; |
| 2043 | wpa_hexdump(MSG_DEBUG, "FILS Discovery frame template", |
| 2044 | head, pos - (u8 *) head); |
| 2045 | return (u8 *) head; |
| 2046 | } |
| 2047 | |
| 2048 | |
| 2049 | /* Configure FILS Discovery frame transmission parameters */ |
| 2050 | static u8 * hostapd_fils_discovery(struct hostapd_data *hapd, |
| 2051 | struct wpa_driver_ap_params *params) |
| 2052 | { |
| 2053 | params->fd_max_int = hapd->conf->fils_discovery_max_int; |
| 2054 | if (is_6ghz_op_class(hapd->iconf->op_class) && |
| 2055 | params->fd_max_int > FD_MAX_INTERVAL_6GHZ) |
| 2056 | params->fd_max_int = FD_MAX_INTERVAL_6GHZ; |
| 2057 | |
| 2058 | params->fd_min_int = hapd->conf->fils_discovery_min_int; |
| 2059 | if (params->fd_min_int > params->fd_max_int) |
| 2060 | params->fd_min_int = params->fd_max_int; |
| 2061 | |
| 2062 | if (params->fd_max_int) |
| 2063 | return hostapd_gen_fils_discovery(hapd, |
| 2064 | ¶ms->fd_frame_tmpl_len); |
| 2065 | |
| 2066 | return NULL; |
| 2067 | } |
| 2068 | |
| 2069 | #endif /* CONFIG_FILS */ |
| 2070 | |
| 2071 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2072 | int ieee802_11_build_ap_params(struct hostapd_data *hapd, |
| 2073 | struct wpa_driver_ap_params *params) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2074 | { |
| 2075 | struct ieee80211_mgmt *head = NULL; |
| 2076 | u8 *tail = NULL; |
| 2077 | size_t head_len = 0, tail_len = 0; |
| 2078 | u8 *resp = NULL; |
| 2079 | size_t resp_len = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2080 | #ifdef NEED_AP_MLME |
| 2081 | u16 capab_info; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2082 | u8 *pos, *tailpos, *tailend, *csa_pos; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2083 | bool complete = false; |
| 2084 | #endif /* NEED_AP_MLME */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2085 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2086 | os_memset(params, 0, sizeof(*params)); |
| 2087 | |
| 2088 | #ifdef NEED_AP_MLME |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2089 | #define BEACON_HEAD_BUF_SIZE 256 |
| 2090 | #define BEACON_TAIL_BUF_SIZE 512 |
| 2091 | head = os_zalloc(BEACON_HEAD_BUF_SIZE); |
| 2092 | tail_len = BEACON_TAIL_BUF_SIZE; |
| 2093 | #ifdef CONFIG_WPS |
| 2094 | if (hapd->conf->wps_state && hapd->wps_beacon_ie) |
| 2095 | tail_len += wpabuf_len(hapd->wps_beacon_ie); |
| 2096 | #endif /* CONFIG_WPS */ |
| 2097 | #ifdef CONFIG_P2P |
| 2098 | if (hapd->p2p_beacon_ie) |
| 2099 | tail_len += wpabuf_len(hapd->p2p_beacon_ie); |
| 2100 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2101 | #ifdef CONFIG_FST |
| 2102 | if (hapd->iface->fst_ies) |
| 2103 | tail_len += wpabuf_len(hapd->iface->fst_ies); |
| 2104 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2105 | if (hapd->conf->vendor_elements) |
| 2106 | tail_len += wpabuf_len(hapd->conf->vendor_elements); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 2107 | |
| 2108 | #ifdef CONFIG_IEEE80211AC |
| 2109 | if (hapd->conf->vendor_vht) { |
| 2110 | tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) + |
| 2111 | 2 + sizeof(struct ieee80211_vht_operation); |
| 2112 | } |
| 2113 | #endif /* CONFIG_IEEE80211AC */ |
| 2114 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2115 | tail_len += he_elem_len(hapd); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 2116 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2117 | #ifdef CONFIG_IEEE80211BE |
| 2118 | if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) { |
| 2119 | tail_len += hostapd_eid_eht_capab_len(hapd, IEEE80211_MODE_AP); |
| 2120 | tail_len += 3 + sizeof(struct ieee80211_eht_operation); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 2121 | if (hapd->iconf->punct_bitmap) |
| 2122 | tail_len += EHT_OPER_DISABLED_SUBCHAN_BITMAP_SIZE; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2123 | |
| 2124 | /* |
| 2125 | * TODO: Multi-Link element has variable length and can be |
| 2126 | * long based on the common info and number of per |
| 2127 | * station profiles. For now use 256. |
| 2128 | */ |
| 2129 | if (hapd->conf->mld_ap) |
| 2130 | tail_len += 256; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2131 | } |
| 2132 | #endif /* CONFIG_IEEE80211BE */ |
| 2133 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2134 | if (hapd->iconf->mbssid == ENHANCED_MBSSID_ENABLED && |
| 2135 | hapd == hostapd_mbssid_get_tx_bss(hapd)) |
| 2136 | tail_len += 5; /* Multiple BSSID Configuration element */ |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2137 | tail_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_BEACON); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2138 | tail_len += hostapd_mbo_ie_len(hapd); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2139 | tail_len += hostapd_eid_owe_trans_len(hapd); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2140 | tail_len += hostapd_eid_dpp_cc_len(hapd); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2141 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2142 | tailpos = tail = os_malloc(tail_len); |
| 2143 | if (head == NULL || tail == NULL) { |
| 2144 | wpa_printf(MSG_ERROR, "Failed to set beacon data"); |
| 2145 | os_free(head); |
| 2146 | os_free(tail); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2147 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2148 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2149 | tailend = tail + tail_len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2150 | |
| 2151 | head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 2152 | WLAN_FC_STYPE_BEACON); |
| 2153 | head->duration = host_to_le16(0); |
| 2154 | os_memset(head->da, 0xff, ETH_ALEN); |
| 2155 | |
| 2156 | os_memcpy(head->sa, hapd->own_addr, ETH_ALEN); |
| 2157 | os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN); |
| 2158 | head->u.beacon.beacon_int = |
| 2159 | host_to_le16(hapd->iconf->beacon_int); |
| 2160 | |
| 2161 | /* hardware or low-level driver will setup seq_ctrl and timestamp */ |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 2162 | capab_info = hostapd_own_capab_info(hapd); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2163 | head->u.beacon.capab_info = host_to_le16(capab_info); |
| 2164 | pos = &head->u.beacon.variable[0]; |
| 2165 | |
| 2166 | /* SSID */ |
| 2167 | *pos++ = WLAN_EID_SSID; |
| 2168 | if (hapd->conf->ignore_broadcast_ssid == 2) { |
| 2169 | /* clear the data, but keep the correct length of the SSID */ |
| 2170 | *pos++ = hapd->conf->ssid.ssid_len; |
| 2171 | os_memset(pos, 0, hapd->conf->ssid.ssid_len); |
| 2172 | pos += hapd->conf->ssid.ssid_len; |
| 2173 | } else if (hapd->conf->ignore_broadcast_ssid) { |
| 2174 | *pos++ = 0; /* empty SSID */ |
| 2175 | } else { |
| 2176 | *pos++ = hapd->conf->ssid.ssid_len; |
| 2177 | os_memcpy(pos, hapd->conf->ssid.ssid, |
| 2178 | hapd->conf->ssid.ssid_len); |
| 2179 | pos += hapd->conf->ssid.ssid_len; |
| 2180 | } |
| 2181 | |
| 2182 | /* Supported rates */ |
| 2183 | pos = hostapd_eid_supp_rates(hapd, pos); |
| 2184 | |
| 2185 | /* DS Params */ |
| 2186 | pos = hostapd_eid_ds_params(hapd, pos); |
| 2187 | |
| 2188 | head_len = pos - (u8 *) head; |
| 2189 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2190 | tailpos = hostapd_eid_country(hapd, tailpos, tailend - tailpos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2191 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2192 | /* Power Constraint element */ |
| 2193 | tailpos = hostapd_eid_pwr_constraint(hapd, tailpos); |
| 2194 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2195 | /* CSA IE */ |
| 2196 | csa_pos = hostapd_eid_csa(hapd, tailpos); |
| 2197 | if (csa_pos != tailpos) |
| 2198 | hapd->cs_c_off_beacon = csa_pos - tail - 1; |
| 2199 | tailpos = csa_pos; |
| 2200 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2201 | /* ERP Information element */ |
| 2202 | tailpos = hostapd_eid_erp_info(hapd, tailpos); |
| 2203 | |
| 2204 | /* Extended supported rates */ |
| 2205 | tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos); |
| 2206 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2207 | tailpos = hostapd_get_rsne(hapd, tailpos, tailend - tailpos); |
| 2208 | tailpos = hostapd_eid_bss_load(hapd, tailpos, tailend - tailpos); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2209 | tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2210 | tailend - tailpos); |
| 2211 | tailpos = hostapd_get_mde(hapd, tailpos, tailend - tailpos); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2212 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2213 | /* eCSA IE */ |
| 2214 | csa_pos = hostapd_eid_ecsa(hapd, tailpos); |
| 2215 | if (csa_pos != tailpos) |
| 2216 | hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1; |
| 2217 | tailpos = csa_pos; |
| 2218 | |
| 2219 | tailpos = hostapd_eid_supported_op_classes(hapd, tailpos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2220 | tailpos = hostapd_eid_ht_capabilities(hapd, tailpos); |
| 2221 | tailpos = hostapd_eid_ht_operation(hapd, tailpos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2222 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2223 | if (hapd->iconf->mbssid && hapd->iconf->num_bss > 1) { |
| 2224 | if (ieee802_11_build_ap_params_mbssid(hapd, params)) { |
| 2225 | os_free(head); |
| 2226 | os_free(tail); |
| 2227 | wpa_printf(MSG_ERROR, |
| 2228 | "MBSSID: Failed to set beacon data"); |
| 2229 | return -1; |
| 2230 | } |
| 2231 | complete = hapd->iconf->mbssid == MBSSID_ENABLED || |
| 2232 | (hapd->iconf->mbssid == ENHANCED_MBSSID_ENABLED && |
| 2233 | params->mbssid_elem_count == 1); |
| 2234 | } |
| 2235 | |
| 2236 | tailpos = hostapd_eid_ext_capab(hapd, tailpos, complete); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2237 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2238 | /* |
| 2239 | * TODO: Time Advertisement element should only be included in some |
| 2240 | * DTIM Beacon frames. |
| 2241 | */ |
| 2242 | tailpos = hostapd_eid_time_adv(hapd, tailpos); |
| 2243 | |
| 2244 | tailpos = hostapd_eid_interworking(hapd, tailpos); |
| 2245 | tailpos = hostapd_eid_adv_proto(hapd, tailpos); |
| 2246 | tailpos = hostapd_eid_roaming_consortium(hapd, tailpos); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2247 | |
| 2248 | #ifdef CONFIG_FST |
| 2249 | if (hapd->iface->fst_ies) { |
| 2250 | os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies), |
| 2251 | wpabuf_len(hapd->iface->fst_ies)); |
| 2252 | tailpos += wpabuf_len(hapd->iface->fst_ies); |
| 2253 | } |
| 2254 | #endif /* CONFIG_FST */ |
| 2255 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2256 | #ifdef CONFIG_IEEE80211AC |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2257 | if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac && |
| 2258 | !is_6ghz_op_class(hapd->iconf->op_class)) { |
Dmitry Shmidt | 7d17530 | 2016-09-06 13:11:34 -0700 | [diff] [blame] | 2259 | tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 2260 | tailpos = hostapd_eid_vht_operation(hapd, tailpos); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 2261 | tailpos = hostapd_eid_txpower_envelope(hapd, tailpos); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 2262 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2263 | #endif /* CONFIG_IEEE80211AC */ |
| 2264 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2265 | #ifdef CONFIG_IEEE80211AX |
| 2266 | if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax && |
| 2267 | is_6ghz_op_class(hapd->iconf->op_class)) |
| 2268 | tailpos = hostapd_eid_txpower_envelope(hapd, tailpos); |
| 2269 | #endif /* CONFIG_IEEE80211AX */ |
| 2270 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2271 | tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2272 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2273 | tailpos = hostapd_eid_rnr(hapd, tailpos, WLAN_FC_STYPE_BEACON); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2274 | tailpos = hostapd_eid_fils_indic(hapd, tailpos, 0); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2275 | tailpos = hostapd_get_rsnxe(hapd, tailpos, tailend - tailpos); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2276 | tailpos = hostapd_eid_mbssid_config(hapd, tailpos, |
| 2277 | params->mbssid_elem_count); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2278 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2279 | #ifdef CONFIG_IEEE80211AX |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2280 | if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) { |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2281 | u8 *cca_pos; |
| 2282 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2283 | tailpos = hostapd_eid_he_capab(hapd, tailpos, |
| 2284 | IEEE80211_MODE_AP); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2285 | tailpos = hostapd_eid_he_operation(hapd, tailpos); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2286 | |
| 2287 | /* BSS Color Change Announcement element */ |
| 2288 | cca_pos = hostapd_eid_cca(hapd, tailpos); |
| 2289 | if (cca_pos != tailpos) |
| 2290 | hapd->cca_c_off_beacon = cca_pos - tail - 2; |
| 2291 | tailpos = cca_pos; |
| 2292 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2293 | tailpos = hostapd_eid_spatial_reuse(hapd, tailpos); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2294 | tailpos = hostapd_eid_he_mu_edca_parameter_set(hapd, tailpos); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 2295 | tailpos = hostapd_eid_he_6ghz_band_cap(hapd, tailpos); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2296 | } |
| 2297 | #endif /* CONFIG_IEEE80211AX */ |
| 2298 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2299 | #ifdef CONFIG_IEEE80211BE |
| 2300 | if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2301 | if (hapd->conf->mld_ap) |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2302 | tailpos = hostapd_eid_eht_ml_beacon(hapd, NULL, |
| 2303 | tailpos, false); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2304 | tailpos = hostapd_eid_eht_capab(hapd, tailpos, |
| 2305 | IEEE80211_MODE_AP); |
| 2306 | tailpos = hostapd_eid_eht_operation(hapd, tailpos); |
| 2307 | } |
| 2308 | #endif /* CONFIG_IEEE80211BE */ |
| 2309 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2310 | #ifdef CONFIG_IEEE80211AC |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 2311 | if (hapd->conf->vendor_vht) |
| 2312 | tailpos = hostapd_eid_vendor_vht(hapd, tailpos); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2313 | #endif /* CONFIG_IEEE80211AC */ |
| 2314 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2315 | /* WPA / OSEN */ |
| 2316 | tailpos = hostapd_get_wpa_ie(hapd, tailpos, tailend - tailpos); |
| 2317 | tailpos = hostapd_get_osen_ie(hapd, tailpos, tailend - tailpos); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2318 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2319 | /* Wi-Fi Alliance WMM */ |
| 2320 | tailpos = hostapd_eid_wmm(hapd, tailpos); |
| 2321 | |
| 2322 | #ifdef CONFIG_WPS |
| 2323 | if (hapd->conf->wps_state && hapd->wps_beacon_ie) { |
| 2324 | os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie), |
| 2325 | wpabuf_len(hapd->wps_beacon_ie)); |
| 2326 | tailpos += wpabuf_len(hapd->wps_beacon_ie); |
| 2327 | } |
| 2328 | #endif /* CONFIG_WPS */ |
| 2329 | |
| 2330 | #ifdef CONFIG_P2P |
| 2331 | if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) { |
| 2332 | os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie), |
| 2333 | wpabuf_len(hapd->p2p_beacon_ie)); |
| 2334 | tailpos += wpabuf_len(hapd->p2p_beacon_ie); |
| 2335 | } |
| 2336 | #endif /* CONFIG_P2P */ |
| 2337 | #ifdef CONFIG_P2P_MANAGER |
| 2338 | if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) == |
| 2339 | P2P_MANAGE) |
| 2340 | tailpos = hostapd_eid_p2p_manage(hapd, tailpos); |
| 2341 | #endif /* CONFIG_P2P_MANAGER */ |
| 2342 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2343 | #ifdef CONFIG_HS20 |
| 2344 | tailpos = hostapd_eid_hs20_indication(hapd, tailpos); |
| 2345 | #endif /* CONFIG_HS20 */ |
| 2346 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2347 | tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2348 | tailpos = hostapd_eid_owe_trans(hapd, tailpos, |
| 2349 | tail + tail_len - tailpos); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2350 | tailpos = hostapd_eid_dpp_cc(hapd, tailpos, tail + tail_len - tailpos); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2351 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2352 | if (hapd->conf->vendor_elements) { |
| 2353 | os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements), |
| 2354 | wpabuf_len(hapd->conf->vendor_elements)); |
| 2355 | tailpos += wpabuf_len(hapd->conf->vendor_elements); |
| 2356 | } |
| 2357 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2358 | tail_len = tailpos > tail ? tailpos - tail : 0; |
| 2359 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2360 | resp = hostapd_probe_resp_offloads(hapd, &resp_len); |
| 2361 | #endif /* NEED_AP_MLME */ |
| 2362 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2363 | /* If key management offload is enabled, configure PSK to the driver. */ |
| 2364 | if (wpa_key_mgmt_wpa_psk_no_sae(hapd->conf->wpa_key_mgmt) && |
| 2365 | (hapd->iface->drv_flags2 & |
| 2366 | WPA_DRIVER_FLAGS2_4WAY_HANDSHAKE_AP_PSK)) { |
| 2367 | if (hapd->conf->ssid.wpa_psk && hapd->conf->ssid.wpa_psk_set) { |
| 2368 | os_memcpy(params->psk, hapd->conf->ssid.wpa_psk->psk, |
| 2369 | PMK_LEN); |
| 2370 | params->psk_len = PMK_LEN; |
| 2371 | } else if (hapd->conf->ssid.wpa_passphrase && |
| 2372 | pbkdf2_sha1(hapd->conf->ssid.wpa_passphrase, |
| 2373 | hapd->conf->ssid.ssid, |
| 2374 | hapd->conf->ssid.ssid_len, 4096, |
| 2375 | params->psk, PMK_LEN) == 0) { |
| 2376 | params->psk_len = PMK_LEN; |
| 2377 | } |
| 2378 | } |
| 2379 | |
| 2380 | #ifdef CONFIG_SAE |
| 2381 | /* If SAE offload is enabled, provide password to lower layer for |
| 2382 | * SAE authentication and PMK generation. |
| 2383 | */ |
| 2384 | if (wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) && |
| 2385 | (hapd->iface->drv_flags2 & WPA_DRIVER_FLAGS2_SAE_OFFLOAD_AP)) { |
| 2386 | if (hostapd_sae_pk_in_use(hapd->conf)) { |
| 2387 | wpa_printf(MSG_ERROR, |
| 2388 | "SAE PK not supported with SAE offload"); |
| 2389 | return -1; |
| 2390 | } |
| 2391 | |
| 2392 | if (hostapd_sae_pw_id_in_use(hapd->conf)) { |
| 2393 | wpa_printf(MSG_ERROR, |
| 2394 | "SAE Password Identifiers not supported with SAE offload"); |
| 2395 | return -1; |
| 2396 | } |
| 2397 | |
| 2398 | params->sae_password = sae_get_password(hapd, NULL, NULL, NULL, |
| 2399 | NULL, NULL); |
| 2400 | if (!params->sae_password) { |
| 2401 | wpa_printf(MSG_ERROR, "SAE password not configured for offload"); |
| 2402 | return -1; |
| 2403 | } |
| 2404 | } |
| 2405 | #endif /* CONFIG_SAE */ |
| 2406 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2407 | params->head = (u8 *) head; |
| 2408 | params->head_len = head_len; |
| 2409 | params->tail = tail; |
| 2410 | params->tail_len = tail_len; |
| 2411 | params->proberesp = resp; |
| 2412 | params->proberesp_len = resp_len; |
| 2413 | params->dtim_period = hapd->conf->dtim_period; |
| 2414 | params->beacon_int = hapd->iconf->beacon_int; |
| 2415 | params->basic_rates = hapd->iface->basic_rates; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 2416 | params->beacon_rate = hapd->iconf->beacon_rate; |
| 2417 | params->rate_type = hapd->iconf->rate_type; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2418 | params->ssid = hapd->conf->ssid.ssid; |
| 2419 | params->ssid_len = hapd->conf->ssid.ssid_len; |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 2420 | if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) == |
| 2421 | (WPA_PROTO_WPA | WPA_PROTO_RSN)) |
| 2422 | params->pairwise_ciphers = hapd->conf->wpa_pairwise | |
| 2423 | hapd->conf->rsn_pairwise; |
| 2424 | else if (hapd->conf->wpa & WPA_PROTO_RSN) |
| 2425 | params->pairwise_ciphers = hapd->conf->rsn_pairwise; |
| 2426 | else if (hapd->conf->wpa & WPA_PROTO_WPA) |
| 2427 | params->pairwise_ciphers = hapd->conf->wpa_pairwise; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2428 | params->group_cipher = hapd->conf->wpa_group; |
| 2429 | params->key_mgmt_suites = hapd->conf->wpa_key_mgmt; |
| 2430 | params->auth_algs = hapd->conf->auth_algs; |
| 2431 | params->wpa_version = hapd->conf->wpa; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2432 | params->privacy = hapd->conf->wpa; |
| 2433 | #ifdef CONFIG_WEP |
| 2434 | params->privacy |= hapd->conf->ssid.wep.keys_set || |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2435 | (hapd->conf->ieee802_1x && |
| 2436 | (hapd->conf->default_wep_key_len || |
| 2437 | hapd->conf->individual_wep_key_len)); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2438 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2439 | switch (hapd->conf->ignore_broadcast_ssid) { |
| 2440 | case 0: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2441 | params->hide_ssid = NO_SSID_HIDING; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2442 | break; |
| 2443 | case 1: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2444 | params->hide_ssid = HIDDEN_SSID_ZERO_LEN; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2445 | break; |
| 2446 | case 2: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2447 | params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2448 | break; |
| 2449 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2450 | params->isolate = hapd->conf->isolate; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2451 | #ifdef NEED_AP_MLME |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2452 | params->cts_protect = !!(ieee802_11_erp_info(hapd) & |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2453 | ERP_INFO_USE_PROTECTION); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2454 | params->preamble = hapd->iface->num_sta_no_short_preamble == 0 && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2455 | hapd->iconf->preamble == SHORT_PREAMBLE; |
| 2456 | if (hapd->iface->current_mode && |
| 2457 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2458 | params->short_slot_time = |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2459 | hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1; |
| 2460 | else |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2461 | params->short_slot_time = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2462 | if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2463 | params->ht_opmode = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2464 | else |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2465 | params->ht_opmode = hapd->iface->ht_op_mode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2466 | #endif /* NEED_AP_MLME */ |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2467 | params->interworking = hapd->conf->interworking; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2468 | if (hapd->conf->interworking && |
| 2469 | !is_zero_ether_addr(hapd->conf->hessid)) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2470 | params->hessid = hapd->conf->hessid; |
| 2471 | params->access_network_type = hapd->conf->access_network_type; |
| 2472 | params->ap_max_inactivity = hapd->conf->ap_max_inactivity; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2473 | #ifdef CONFIG_P2P |
| 2474 | params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow; |
| 2475 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2476 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2477 | params->disable_dgaf = hapd->conf->disable_dgaf; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2478 | if (hapd->conf->osen) { |
| 2479 | params->privacy = 1; |
| 2480 | params->osen = 1; |
| 2481 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2482 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 2483 | params->multicast_to_unicast = hapd->conf->multicast_to_unicast; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2484 | params->pbss = hapd->conf->pbss; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2485 | |
| 2486 | if (hapd->conf->ftm_responder) { |
| 2487 | if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_FTM_RESPONDER) { |
| 2488 | params->ftm_responder = 1; |
| 2489 | params->lci = hapd->iface->conf->lci; |
| 2490 | params->civic = hapd->iface->conf->civic; |
| 2491 | } else { |
| 2492 | wpa_printf(MSG_WARNING, |
| 2493 | "Not configuring FTM responder as the driver doesn't advertise support for it"); |
| 2494 | } |
| 2495 | } |
| 2496 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2497 | #ifdef CONFIG_IEEE80211BE |
| 2498 | if (hapd->conf->mld_ap && hapd->iconf->ieee80211be && |
| 2499 | !hapd->conf->disable_11be) { |
| 2500 | params->mld_ap = true; |
| 2501 | params->mld_link_id = hapd->mld_link_id; |
| 2502 | } |
| 2503 | #endif /* CONFIG_IEEE80211BE */ |
| 2504 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2505 | return 0; |
| 2506 | } |
| 2507 | |
| 2508 | |
| 2509 | void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params) |
| 2510 | { |
| 2511 | os_free(params->tail); |
| 2512 | params->tail = NULL; |
| 2513 | os_free(params->head); |
| 2514 | params->head = NULL; |
| 2515 | os_free(params->proberesp); |
| 2516 | params->proberesp = NULL; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2517 | os_free(params->mbssid_elem); |
| 2518 | params->mbssid_elem = NULL; |
| 2519 | os_free(params->mbssid_elem_offset); |
| 2520 | params->mbssid_elem_offset = NULL; |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 2521 | os_free(params->rnr_elem); |
| 2522 | params->rnr_elem = NULL; |
| 2523 | os_free(params->rnr_elem_offset); |
| 2524 | params->rnr_elem_offset = NULL; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2525 | #ifdef CONFIG_FILS |
| 2526 | os_free(params->fd_frame_tmpl); |
| 2527 | params->fd_frame_tmpl = NULL; |
| 2528 | #endif /* CONFIG_FILS */ |
| 2529 | #ifdef CONFIG_IEEE80211AX |
| 2530 | os_free(params->unsol_bcast_probe_resp_tmpl); |
| 2531 | params->unsol_bcast_probe_resp_tmpl = NULL; |
| 2532 | #endif /* CONFIG_IEEE80211AX */ |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 2533 | os_free(params->allowed_freqs); |
| 2534 | params->allowed_freqs = NULL; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2535 | } |
| 2536 | |
| 2537 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2538 | static int __ieee802_11_set_beacon(struct hostapd_data *hapd) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2539 | { |
| 2540 | struct wpa_driver_ap_params params; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2541 | struct hostapd_freq_params freq; |
| 2542 | struct hostapd_iface *iface = hapd->iface; |
| 2543 | struct hostapd_config *iconf = iface->conf; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2544 | struct hostapd_hw_modes *cmode = iface->current_mode; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2545 | struct wpabuf *beacon, *proberesp, *assocresp; |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 2546 | int res, ret = -1, i; |
| 2547 | struct hostapd_hw_modes *mode; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2548 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2549 | if (!hapd->drv_priv) { |
| 2550 | wpa_printf(MSG_ERROR, "Interface is disabled"); |
| 2551 | return -1; |
| 2552 | } |
| 2553 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 2554 | if (hapd->csa_in_progress) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2555 | wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period"); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2556 | return -1; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | hapd->beacon_set_done = 1; |
| 2560 | |
| 2561 | if (ieee802_11_build_ap_params(hapd, ¶ms) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2562 | return -1; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2563 | |
| 2564 | if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) < |
| 2565 | 0) |
| 2566 | goto fail; |
| 2567 | |
| 2568 | params.beacon_ies = beacon; |
| 2569 | params.proberesp_ies = proberesp; |
| 2570 | params.assocresp_ies = assocresp; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2571 | params.reenable = hapd->reenable_beacon; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2572 | #ifdef CONFIG_IEEE80211AX |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2573 | params.he_spr_ctrl = hapd->iface->conf->spr.sr_control; |
| 2574 | params.he_spr_non_srg_obss_pd_max_offset = |
| 2575 | hapd->iface->conf->spr.non_srg_obss_pd_max_offset; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2576 | params.he_spr_srg_obss_pd_min_offset = |
| 2577 | hapd->iface->conf->spr.srg_obss_pd_min_offset; |
| 2578 | params.he_spr_srg_obss_pd_max_offset = |
| 2579 | hapd->iface->conf->spr.srg_obss_pd_max_offset; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2580 | os_memcpy(params.he_spr_bss_color_bitmap, |
| 2581 | hapd->iface->conf->spr.srg_bss_color_bitmap, 8); |
| 2582 | os_memcpy(params.he_spr_partial_bssid_bitmap, |
| 2583 | hapd->iface->conf->spr.srg_partial_bssid_bitmap, 8); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2584 | params.he_bss_color_disabled = |
| 2585 | hapd->iface->conf->he_op.he_bss_color_disabled; |
| 2586 | params.he_bss_color_partial = |
| 2587 | hapd->iface->conf->he_op.he_bss_color_partial; |
| 2588 | params.he_bss_color = hapd->iface->conf->he_op.he_bss_color; |
| 2589 | params.twt_responder = hostapd_get_he_twt_responder(hapd, |
| 2590 | IEEE80211_MODE_AP); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2591 | params.unsol_bcast_probe_resp_tmpl = |
| 2592 | hostapd_unsol_bcast_probe_resp(hapd, ¶ms); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2593 | #endif /* CONFIG_IEEE80211AX */ |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2594 | hapd->reenable_beacon = 0; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2595 | #ifdef CONFIG_SAE |
| 2596 | params.sae_pwe = hapd->conf->sae_pwe; |
| 2597 | #endif /* CONFIG_SAE */ |
| 2598 | |
| 2599 | #ifdef CONFIG_FILS |
| 2600 | params.fd_frame_tmpl = hostapd_fils_discovery(hapd, ¶ms); |
| 2601 | #endif /* CONFIG_FILS */ |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2602 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 2603 | #ifdef CONFIG_IEEE80211BE |
| 2604 | params.punct_bitmap = iconf->punct_bitmap; |
| 2605 | #endif /* CONFIG_IEEE80211BE */ |
| 2606 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2607 | if (cmode && |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2608 | hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2609 | iconf->channel, iconf->enable_edmg, |
| 2610 | iconf->edmg_channel, iconf->ieee80211n, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2611 | iconf->ieee80211ac, iconf->ieee80211ax, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2612 | iconf->ieee80211be, |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2613 | iconf->secondary_channel, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2614 | hostapd_get_oper_chwidth(iconf), |
| 2615 | hostapd_get_oper_centr_freq_seg0_idx(iconf), |
| 2616 | hostapd_get_oper_centr_freq_seg1_idx(iconf), |
| 2617 | cmode->vht_capab, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2618 | &cmode->he_capab[IEEE80211_MODE_AP], |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 2619 | &cmode->eht_capab[IEEE80211_MODE_AP], |
| 2620 | hostapd_get_punct_bitmap(hapd)) == 0) |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2621 | params.freq = &freq; |
| 2622 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 2623 | for (i = 0; i < hapd->iface->num_hw_features; i++) { |
| 2624 | mode = &hapd->iface->hw_features[i]; |
| 2625 | |
| 2626 | if (iconf->hw_mode != HOSTAPD_MODE_IEEE80211ANY && |
| 2627 | iconf->hw_mode != mode->mode) |
| 2628 | continue; |
| 2629 | |
| 2630 | hostapd_get_hw_mode_any_channels(hapd, mode, |
| 2631 | !(iconf->acs_freq_list.num || |
| 2632 | iconf->acs_ch_list.num), |
| 2633 | true, ¶ms.allowed_freqs); |
| 2634 | } |
| 2635 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2636 | res = hostapd_drv_set_ap(hapd, ¶ms); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2637 | hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2638 | if (res) |
| 2639 | wpa_printf(MSG_ERROR, "Failed to set beacon parameters"); |
| 2640 | else |
| 2641 | ret = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2642 | fail: |
| 2643 | ieee802_11_free_ap_params(¶ms); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2644 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2645 | } |
| 2646 | |
| 2647 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2648 | void ieee802_11_set_beacon_per_bss_only(struct hostapd_data *hapd) |
| 2649 | { |
| 2650 | __ieee802_11_set_beacon(hapd); |
| 2651 | } |
| 2652 | |
| 2653 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2654 | int ieee802_11_set_beacon(struct hostapd_data *hapd) |
| 2655 | { |
| 2656 | struct hostapd_iface *iface = hapd->iface; |
| 2657 | int ret; |
| 2658 | size_t i, j; |
| 2659 | bool is_6g; |
| 2660 | |
| 2661 | ret = __ieee802_11_set_beacon(hapd); |
| 2662 | if (ret != 0) |
| 2663 | return ret; |
| 2664 | |
| 2665 | if (!iface->interfaces || iface->interfaces->count <= 1) |
| 2666 | return 0; |
| 2667 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2668 | /* Update Beacon frames in case of 6 GHz colocation or AP MLD */ |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2669 | is_6g = is_6ghz_op_class(iface->conf->op_class); |
| 2670 | for (j = 0; j < iface->interfaces->count; j++) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2671 | struct hostapd_iface *other; |
| 2672 | bool mld_ap = false; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2673 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2674 | other = iface->interfaces->iface[j]; |
| 2675 | if (other == iface || !other || !other->conf) |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2676 | continue; |
| 2677 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2678 | #ifdef CONFIG_IEEE80211BE |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 2679 | if (hostapd_is_ml_partner(hapd, other->bss[0])) |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2680 | mld_ap = true; |
| 2681 | #endif /* CONFIG_IEEE80211BE */ |
| 2682 | |
| 2683 | if (is_6g == is_6ghz_op_class(other->conf->op_class) && |
| 2684 | !mld_ap) |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2685 | continue; |
| 2686 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2687 | for (i = 0; i < other->num_bss; i++) { |
| 2688 | if (other->bss[i] && other->bss[i]->started) |
| 2689 | __ieee802_11_set_beacon(other->bss[i]); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2690 | } |
| 2691 | } |
| 2692 | |
| 2693 | return 0; |
| 2694 | } |
| 2695 | |
| 2696 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2697 | int ieee802_11_set_beacons(struct hostapd_iface *iface) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2698 | { |
| 2699 | size_t i; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2700 | int ret = 0; |
| 2701 | |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 2702 | for (i = 0; i < iface->num_bss; i++) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2703 | if (iface->bss[i]->started && |
| 2704 | ieee802_11_set_beacon(iface->bss[i]) < 0) |
| 2705 | ret = -1; |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 2706 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2707 | |
| 2708 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2709 | } |
| 2710 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2711 | |
| 2712 | /* only update beacons if started */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2713 | int ieee802_11_update_beacons(struct hostapd_iface *iface) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2714 | { |
| 2715 | size_t i; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2716 | int ret = 0; |
| 2717 | |
| 2718 | for (i = 0; i < iface->num_bss; i++) { |
| 2719 | if (iface->bss[i]->beacon_set_done && iface->bss[i]->started && |
| 2720 | ieee802_11_set_beacon(iface->bss[i]) < 0) |
| 2721 | ret = -1; |
| 2722 | } |
| 2723 | |
| 2724 | return ret; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2725 | } |
| 2726 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2727 | #endif /* CONFIG_NATIVE_WINDOWS */ |