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