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