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