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 | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 536 | bool bcast_probe_resp, const u8 *known_bss, |
| 537 | u8 known_bss_len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 538 | { |
| 539 | struct ieee80211_mgmt *resp; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 540 | u8 *pos, *epos, *csa_pos; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 541 | size_t buflen; |
| 542 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 543 | hapd = hostapd_mbssid_get_tx_bss(hapd); |
| 544 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 545 | #define MAX_PROBERESP_LEN 768 |
| 546 | buflen = MAX_PROBERESP_LEN; |
| 547 | #ifdef CONFIG_WPS |
| 548 | if (hapd->wps_probe_resp_ie) |
| 549 | buflen += wpabuf_len(hapd->wps_probe_resp_ie); |
| 550 | #endif /* CONFIG_WPS */ |
| 551 | #ifdef CONFIG_P2P |
| 552 | if (hapd->p2p_probe_resp_ie) |
| 553 | buflen += wpabuf_len(hapd->p2p_probe_resp_ie); |
| 554 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 555 | #ifdef CONFIG_FST |
| 556 | if (hapd->iface->fst_ies) |
| 557 | buflen += wpabuf_len(hapd->iface->fst_ies); |
| 558 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 559 | if (hapd->conf->vendor_elements) |
| 560 | buflen += wpabuf_len(hapd->conf->vendor_elements); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 561 | if (hapd->conf->vendor_vht) { |
| 562 | buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) + |
| 563 | 2 + sizeof(struct ieee80211_vht_operation); |
| 564 | } |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 565 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 566 | #ifdef CONFIG_IEEE80211AX |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 567 | if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 568 | buflen += 3 + sizeof(struct ieee80211_he_capabilities) + |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 569 | 3 + sizeof(struct ieee80211_he_operation) + |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 570 | 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) + |
| 571 | 3 + sizeof(struct ieee80211_spatial_reuse); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 572 | if (is_6ghz_op_class(hapd->iconf->op_class)) { |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 573 | buflen += sizeof(struct ieee80211_he_6ghz_oper_info) + |
| 574 | 3 + sizeof(struct ieee80211_he_6ghz_band_cap); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 575 | /* An additional Transmit Power Envelope element for |
| 576 | * subordinate client */ |
| 577 | if (hapd->iconf->he_6ghz_reg_pwr_type == |
| 578 | HE_6GHZ_INDOOR_AP) |
| 579 | buflen += 4; |
| 580 | } |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 581 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 582 | #endif /* CONFIG_IEEE80211AX */ |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 583 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 584 | #ifdef CONFIG_IEEE80211BE |
| 585 | if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) { |
| 586 | buflen += hostapd_eid_eht_capab_len(hapd, IEEE80211_MODE_AP); |
| 587 | buflen += 3 + sizeof(struct ieee80211_eht_operation); |
| 588 | } |
| 589 | #endif /* CONFIG_IEEE80211BE */ |
| 590 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 591 | buflen += hostapd_eid_mbssid_len(hapd, WLAN_FC_STYPE_PROBE_RESP, NULL, |
| 592 | known_bss, known_bss_len); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 593 | buflen += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_PROBE_RESP); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 594 | buflen += hostapd_mbo_ie_len(hapd); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 595 | buflen += hostapd_eid_owe_trans_len(hapd); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 596 | buflen += hostapd_eid_dpp_cc_len(hapd); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 597 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 598 | resp = os_zalloc(buflen); |
| 599 | if (resp == NULL) |
| 600 | return NULL; |
| 601 | |
| 602 | epos = ((u8 *) resp) + MAX_PROBERESP_LEN; |
| 603 | |
| 604 | resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 605 | WLAN_FC_STYPE_PROBE_RESP); |
| 606 | if (req) |
| 607 | os_memcpy(resp->da, req->sa, ETH_ALEN); |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 608 | else if (bcast_probe_resp) |
| 609 | os_memset(resp->da, 0xff, ETH_ALEN); |
| 610 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 611 | os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN); |
| 612 | |
| 613 | os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN); |
| 614 | resp->u.probe_resp.beacon_int = |
| 615 | host_to_le16(hapd->iconf->beacon_int); |
| 616 | |
| 617 | /* hardware or low-level driver will setup seq_ctrl and timestamp */ |
| 618 | resp->u.probe_resp.capab_info = |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 619 | host_to_le16(hostapd_own_capab_info(hapd)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 620 | |
| 621 | pos = resp->u.probe_resp.variable; |
| 622 | *pos++ = WLAN_EID_SSID; |
| 623 | *pos++ = hapd->conf->ssid.ssid_len; |
| 624 | os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len); |
| 625 | pos += hapd->conf->ssid.ssid_len; |
| 626 | |
| 627 | /* Supported rates */ |
| 628 | pos = hostapd_eid_supp_rates(hapd, pos); |
| 629 | |
| 630 | /* DS Params */ |
| 631 | pos = hostapd_eid_ds_params(hapd, pos); |
| 632 | |
| 633 | pos = hostapd_eid_country(hapd, pos, epos - pos); |
| 634 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 635 | /* Power Constraint element */ |
| 636 | pos = hostapd_eid_pwr_constraint(hapd, pos); |
| 637 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 638 | /* CSA IE */ |
| 639 | csa_pos = hostapd_eid_csa(hapd, pos); |
| 640 | if (csa_pos != pos) |
| 641 | hapd->cs_c_off_proberesp = csa_pos - (u8 *) resp - 1; |
| 642 | pos = csa_pos; |
| 643 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 644 | /* ERP Information element */ |
| 645 | pos = hostapd_eid_erp_info(hapd, pos); |
| 646 | |
| 647 | /* Extended supported rates */ |
| 648 | pos = hostapd_eid_ext_supp_rates(hapd, pos); |
| 649 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 650 | pos = hostapd_get_rsne(hapd, pos, epos - pos); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 651 | pos = hostapd_eid_bss_load(hapd, pos, epos - pos); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 652 | pos = hostapd_eid_mbssid(hapd, pos, epos, WLAN_FC_STYPE_PROBE_RESP, 0, |
| 653 | NULL, known_bss, known_bss_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 654 | pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 655 | pos = hostapd_get_mde(hapd, pos, epos - pos); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 656 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 657 | /* eCSA IE */ |
| 658 | csa_pos = hostapd_eid_ecsa(hapd, pos); |
| 659 | if (csa_pos != pos) |
| 660 | hapd->cs_c_off_ecsa_proberesp = csa_pos - (u8 *) resp - 1; |
| 661 | pos = csa_pos; |
| 662 | |
| 663 | pos = hostapd_eid_supported_op_classes(hapd, pos); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 664 | pos = hostapd_eid_ht_capabilities(hapd, pos); |
| 665 | pos = hostapd_eid_ht_operation(hapd, pos); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 666 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 667 | /* Probe Response frames always include all non-TX profiles except |
| 668 | * when a list of known BSSes is included in the Probe Request frame. */ |
| 669 | pos = hostapd_eid_ext_capab(hapd, pos, |
| 670 | hapd->iconf->mbssid >= MBSSID_ENABLED && |
| 671 | !known_bss_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 672 | |
| 673 | pos = hostapd_eid_time_adv(hapd, pos); |
| 674 | pos = hostapd_eid_time_zone(hapd, pos); |
| 675 | |
| 676 | pos = hostapd_eid_interworking(hapd, pos); |
| 677 | pos = hostapd_eid_adv_proto(hapd, pos); |
| 678 | pos = hostapd_eid_roaming_consortium(hapd, pos); |
| 679 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 680 | #ifdef CONFIG_FST |
| 681 | if (hapd->iface->fst_ies) { |
| 682 | os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies), |
| 683 | wpabuf_len(hapd->iface->fst_ies)); |
| 684 | pos += wpabuf_len(hapd->iface->fst_ies); |
| 685 | } |
| 686 | #endif /* CONFIG_FST */ |
| 687 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 688 | #ifdef CONFIG_IEEE80211AC |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 689 | if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac && |
| 690 | !is_6ghz_op_class(hapd->iconf->op_class)) { |
Dmitry Shmidt | 7d17530 | 2016-09-06 13:11:34 -0700 | [diff] [blame] | 691 | pos = hostapd_eid_vht_capabilities(hapd, pos, 0); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 692 | pos = hostapd_eid_vht_operation(hapd, pos); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 693 | pos = hostapd_eid_txpower_envelope(hapd, pos); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 694 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 695 | #endif /* CONFIG_IEEE80211AC */ |
| 696 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 697 | #ifdef CONFIG_IEEE80211AX |
| 698 | if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax && |
| 699 | is_6ghz_op_class(hapd->iconf->op_class)) |
| 700 | pos = hostapd_eid_txpower_envelope(hapd, pos); |
| 701 | #endif /* CONFIG_IEEE80211AX */ |
| 702 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 703 | pos = hostapd_eid_wb_chsw_wrapper(hapd, pos); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 704 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 705 | pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_PROBE_RESP); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 706 | pos = hostapd_eid_fils_indic(hapd, pos, 0); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 707 | pos = hostapd_get_rsnxe(hapd, pos, epos - pos); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 708 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 709 | #ifdef CONFIG_IEEE80211AX |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 710 | if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) { |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 711 | u8 *cca_pos; |
| 712 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 713 | pos = hostapd_eid_he_capab(hapd, pos, IEEE80211_MODE_AP); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 714 | pos = hostapd_eid_he_operation(hapd, pos); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 715 | |
| 716 | /* BSS Color Change Announcement element */ |
| 717 | cca_pos = hostapd_eid_cca(hapd, pos); |
| 718 | if (cca_pos != pos) |
| 719 | hapd->cca_c_off_proberesp = cca_pos - (u8 *) resp - 2; |
| 720 | pos = cca_pos; |
| 721 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 722 | pos = hostapd_eid_spatial_reuse(hapd, pos); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 723 | pos = hostapd_eid_he_mu_edca_parameter_set(hapd, pos); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 724 | pos = hostapd_eid_he_6ghz_band_cap(hapd, pos); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 725 | } |
| 726 | #endif /* CONFIG_IEEE80211AX */ |
| 727 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 728 | #ifdef CONFIG_IEEE80211BE |
| 729 | if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) { |
| 730 | pos = hostapd_eid_eht_capab(hapd, pos, IEEE80211_MODE_AP); |
| 731 | pos = hostapd_eid_eht_operation(hapd, pos); |
| 732 | } |
| 733 | #endif /* CONFIG_IEEE80211BE */ |
| 734 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 735 | #ifdef CONFIG_IEEE80211AC |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 736 | if (hapd->conf->vendor_vht) |
| 737 | pos = hostapd_eid_vendor_vht(hapd, pos); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 738 | #endif /* CONFIG_IEEE80211AC */ |
| 739 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 740 | /* WPA / OSEN */ |
| 741 | pos = hostapd_get_wpa_ie(hapd, pos, epos - pos); |
| 742 | pos = hostapd_get_osen_ie(hapd, pos, epos - pos); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 743 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 744 | /* Wi-Fi Alliance WMM */ |
| 745 | pos = hostapd_eid_wmm(hapd, pos); |
| 746 | |
| 747 | #ifdef CONFIG_WPS |
| 748 | if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) { |
| 749 | os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie), |
| 750 | wpabuf_len(hapd->wps_probe_resp_ie)); |
| 751 | pos += wpabuf_len(hapd->wps_probe_resp_ie); |
| 752 | } |
| 753 | #endif /* CONFIG_WPS */ |
| 754 | |
| 755 | #ifdef CONFIG_P2P |
| 756 | if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p && |
| 757 | hapd->p2p_probe_resp_ie) { |
| 758 | os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie), |
| 759 | wpabuf_len(hapd->p2p_probe_resp_ie)); |
| 760 | pos += wpabuf_len(hapd->p2p_probe_resp_ie); |
| 761 | } |
| 762 | #endif /* CONFIG_P2P */ |
| 763 | #ifdef CONFIG_P2P_MANAGER |
| 764 | if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) == |
| 765 | P2P_MANAGE) |
| 766 | pos = hostapd_eid_p2p_manage(hapd, pos); |
| 767 | #endif /* CONFIG_P2P_MANAGER */ |
| 768 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 769 | #ifdef CONFIG_HS20 |
| 770 | pos = hostapd_eid_hs20_indication(hapd, pos); |
| 771 | #endif /* CONFIG_HS20 */ |
| 772 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 773 | pos = hostapd_eid_mbo(hapd, pos, (u8 *) resp + buflen - pos); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 774 | pos = hostapd_eid_owe_trans(hapd, pos, (u8 *) resp + buflen - pos); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 775 | pos = hostapd_eid_dpp_cc(hapd, pos, (u8 *) resp + buflen - pos); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 776 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 777 | if (hapd->conf->vendor_elements) { |
| 778 | os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements), |
| 779 | wpabuf_len(hapd->conf->vendor_elements)); |
| 780 | pos += wpabuf_len(hapd->conf->vendor_elements); |
| 781 | } |
| 782 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 783 | *resp_len = pos - (u8 *) resp; |
| 784 | return (u8 *) resp; |
| 785 | } |
| 786 | |
| 787 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 788 | enum ssid_match_result { |
| 789 | NO_SSID_MATCH, |
| 790 | EXACT_SSID_MATCH, |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 791 | WILDCARD_SSID_MATCH, |
| 792 | CO_LOCATED_SSID_MATCH, |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 793 | }; |
| 794 | |
| 795 | static enum ssid_match_result ssid_match(struct hostapd_data *hapd, |
| 796 | const u8 *ssid, size_t ssid_len, |
| 797 | const u8 *ssid_list, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 798 | size_t ssid_list_len, |
| 799 | const u8 *short_ssid_list, |
| 800 | size_t short_ssid_list_len) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 801 | { |
| 802 | const u8 *pos, *end; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 803 | struct hostapd_iface *iface = hapd->iface; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 804 | int wildcard = 0; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 805 | size_t i, j; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 806 | |
| 807 | if (ssid_len == 0) |
| 808 | wildcard = 1; |
| 809 | if (ssid_len == hapd->conf->ssid.ssid_len && |
| 810 | os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0) |
| 811 | return EXACT_SSID_MATCH; |
| 812 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 813 | if (ssid_list) { |
| 814 | pos = ssid_list; |
| 815 | end = ssid_list + ssid_list_len; |
| 816 | while (end - pos >= 2) { |
| 817 | if (2 + pos[1] > end - pos) |
| 818 | break; |
| 819 | if (pos[1] == 0) |
| 820 | wildcard = 1; |
| 821 | if (pos[1] == hapd->conf->ssid.ssid_len && |
| 822 | os_memcmp(pos + 2, hapd->conf->ssid.ssid, |
| 823 | pos[1]) == 0) |
| 824 | return EXACT_SSID_MATCH; |
| 825 | pos += 2 + pos[1]; |
| 826 | } |
| 827 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 828 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 829 | if (short_ssid_list) { |
| 830 | pos = short_ssid_list; |
| 831 | end = short_ssid_list + short_ssid_list_len; |
| 832 | while (end - pos >= 4) { |
| 833 | if (hapd->conf->ssid.short_ssid == WPA_GET_LE32(pos)) |
| 834 | return EXACT_SSID_MATCH; |
| 835 | pos += 4; |
| 836 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 837 | } |
| 838 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 839 | if (wildcard) |
| 840 | return WILDCARD_SSID_MATCH; |
| 841 | |
| 842 | if (!iface->interfaces || iface->interfaces->count <= 1 || |
| 843 | is_6ghz_op_class(hapd->iconf->op_class)) |
| 844 | return NO_SSID_MATCH; |
| 845 | |
| 846 | for (i = 0; i < iface->interfaces->count; i++) { |
| 847 | struct hostapd_iface *colocated; |
| 848 | |
| 849 | colocated = iface->interfaces->iface[i]; |
| 850 | |
| 851 | if (colocated == iface || |
| 852 | !is_6ghz_op_class(colocated->conf->op_class)) |
| 853 | continue; |
| 854 | |
| 855 | for (j = 0; j < colocated->num_bss; j++) { |
| 856 | struct hostapd_bss_config *conf; |
| 857 | |
| 858 | conf = colocated->bss[j]->conf; |
| 859 | if (ssid_len == conf->ssid.ssid_len && |
| 860 | os_memcmp(ssid, conf->ssid.ssid, ssid_len) == 0) |
| 861 | return CO_LOCATED_SSID_MATCH; |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | return NO_SSID_MATCH; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 869 | void sta_track_expire(struct hostapd_iface *iface, int force) |
| 870 | { |
| 871 | struct os_reltime now; |
| 872 | struct hostapd_sta_info *info; |
| 873 | |
| 874 | if (!iface->num_sta_seen) |
| 875 | return; |
| 876 | |
| 877 | os_get_reltime(&now); |
| 878 | while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info, |
| 879 | list))) { |
| 880 | if (!force && |
| 881 | !os_reltime_expired(&now, &info->last_seen, |
| 882 | iface->conf->track_sta_max_age)) |
| 883 | break; |
| 884 | force = 0; |
| 885 | |
| 886 | wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for " |
| 887 | MACSTR, iface->bss[0]->conf->iface, |
| 888 | MAC2STR(info->addr)); |
| 889 | dl_list_del(&info->list); |
| 890 | iface->num_sta_seen--; |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 891 | sta_track_del(info); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 892 | } |
| 893 | } |
| 894 | |
| 895 | |
| 896 | static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface, |
| 897 | const u8 *addr) |
| 898 | { |
| 899 | struct hostapd_sta_info *info; |
| 900 | |
| 901 | dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list) |
| 902 | if (os_memcmp(addr, info->addr, ETH_ALEN) == 0) |
| 903 | return info; |
| 904 | |
| 905 | return NULL; |
| 906 | } |
| 907 | |
| 908 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 909 | 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] | 910 | { |
| 911 | struct hostapd_sta_info *info; |
| 912 | |
| 913 | info = sta_track_get(iface, addr); |
| 914 | if (info) { |
| 915 | /* Move the most recent entry to the end of the list */ |
| 916 | dl_list_del(&info->list); |
| 917 | dl_list_add_tail(&iface->sta_seen, &info->list); |
| 918 | os_get_reltime(&info->last_seen); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 919 | info->ssi_signal = ssi_signal; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 920 | return; |
| 921 | } |
| 922 | |
| 923 | /* Add a new entry */ |
| 924 | info = os_zalloc(sizeof(*info)); |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 925 | if (info == NULL) |
| 926 | return; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 927 | os_memcpy(info->addr, addr, ETH_ALEN); |
| 928 | os_get_reltime(&info->last_seen); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 929 | info->ssi_signal = ssi_signal; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 930 | |
| 931 | if (iface->num_sta_seen >= iface->conf->track_sta_max_num) { |
| 932 | /* Expire oldest entry to make room for a new one */ |
| 933 | sta_track_expire(iface, 1); |
| 934 | } |
| 935 | |
| 936 | wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for " |
| 937 | MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr)); |
| 938 | dl_list_add_tail(&iface->sta_seen, &info->list); |
| 939 | iface->num_sta_seen++; |
| 940 | } |
| 941 | |
| 942 | |
| 943 | struct hostapd_data * |
| 944 | sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr, |
| 945 | const char *ifname) |
| 946 | { |
| 947 | struct hapd_interfaces *interfaces = iface->interfaces; |
| 948 | size_t i, j; |
| 949 | |
| 950 | for (i = 0; i < interfaces->count; i++) { |
| 951 | struct hostapd_data *hapd = NULL; |
| 952 | |
| 953 | iface = interfaces->iface[i]; |
| 954 | for (j = 0; j < iface->num_bss; j++) { |
| 955 | hapd = iface->bss[j]; |
| 956 | if (os_strcmp(ifname, hapd->conf->iface) == 0) |
| 957 | break; |
| 958 | hapd = NULL; |
| 959 | } |
| 960 | |
| 961 | if (hapd && sta_track_get(iface, addr)) |
| 962 | return hapd; |
| 963 | } |
| 964 | |
| 965 | return NULL; |
| 966 | } |
| 967 | |
| 968 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 969 | #ifdef CONFIG_TAXONOMY |
| 970 | void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr, |
| 971 | struct wpabuf **probe_ie_taxonomy) |
| 972 | { |
| 973 | struct hostapd_sta_info *info; |
| 974 | |
| 975 | info = sta_track_get(iface, addr); |
| 976 | if (!info) |
| 977 | return; |
| 978 | |
| 979 | wpabuf_free(*probe_ie_taxonomy); |
| 980 | *probe_ie_taxonomy = info->probe_ie_taxonomy; |
| 981 | info->probe_ie_taxonomy = NULL; |
| 982 | } |
| 983 | #endif /* CONFIG_TAXONOMY */ |
| 984 | |
| 985 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 986 | void handle_probe_req(struct hostapd_data *hapd, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 987 | const struct ieee80211_mgmt *mgmt, size_t len, |
| 988 | int ssi_signal) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 989 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 990 | u8 *resp; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 991 | struct ieee802_11_elems elems; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 992 | const u8 *ie; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 993 | size_t ie_len; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 994 | size_t i, resp_len; |
| 995 | int noack; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 996 | enum ssid_match_result res; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 997 | int ret; |
| 998 | u16 csa_offs[2]; |
| 999 | size_t csa_offs_len; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1000 | struct radius_sta rad_info; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1001 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1002 | if (hapd->iconf->rssi_ignore_probe_request && ssi_signal && |
| 1003 | ssi_signal < hapd->iconf->rssi_ignore_probe_request) |
| 1004 | return; |
| 1005 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1006 | if (len < IEEE80211_HDRLEN) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1007 | return; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1008 | ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1009 | if (hapd->iconf->track_sta_max_num) |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1010 | sta_track_add(hapd->iface, mgmt->sa, ssi_signal); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1011 | ie_len = len - IEEE80211_HDRLEN; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1012 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1013 | ret = hostapd_allowed_address(hapd, mgmt->sa, (const u8 *) mgmt, len, |
| 1014 | &rad_info, 1); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1015 | if (ret == HOSTAPD_ACL_REJECT) { |
| 1016 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, |
| 1017 | "Ignore Probe Request frame from " MACSTR |
| 1018 | " due to ACL reject ", MAC2STR(mgmt->sa)); |
| 1019 | return; |
| 1020 | } |
| 1021 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1022 | for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) |
| 1023 | if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1024 | mgmt->sa, mgmt->da, mgmt->bssid, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1025 | ie, ie_len, ssi_signal) > 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1026 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1027 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1028 | if (!hapd->conf->send_probe_response) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1029 | return; |
| 1030 | |
| 1031 | if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) { |
| 1032 | wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR, |
| 1033 | MAC2STR(mgmt->sa)); |
| 1034 | return; |
| 1035 | } |
| 1036 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1037 | if ((!elems.ssid || !elems.supp_rates)) { |
| 1038 | wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request " |
| 1039 | "without SSID or supported rates element", |
| 1040 | MAC2STR(mgmt->sa)); |
| 1041 | return; |
| 1042 | } |
| 1043 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1044 | /* |
| 1045 | * No need to reply if the Probe Request frame was sent on an adjacent |
| 1046 | * channel. IEEE Std 802.11-2012 describes this as a requirement for an |
| 1047 | * AP with dot11RadioMeasurementActivated set to true, but strictly |
| 1048 | * speaking does not allow such ignoring of Probe Request frames if |
| 1049 | * dot11RadioMeasurementActivated is false. Anyway, this can help reduce |
| 1050 | * number of unnecessary Probe Response frames for cases where the STA |
| 1051 | * is less likely to see them (Probe Request frame sent on a |
| 1052 | * neighboring, but partially overlapping, channel). |
| 1053 | */ |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 1054 | if (elems.ds_params && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1055 | hapd->iface->current_mode && |
| 1056 | (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G || |
| 1057 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) && |
| 1058 | hapd->iconf->channel != elems.ds_params[0]) { |
| 1059 | wpa_printf(MSG_DEBUG, |
| 1060 | "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u", |
| 1061 | hapd->iconf->channel, elems.ds_params[0]); |
| 1062 | return; |
| 1063 | } |
| 1064 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1065 | #ifdef CONFIG_P2P |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 1066 | if (hapd->p2p && hapd->p2p_group && elems.wps_ie) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1067 | struct wpabuf *wps; |
| 1068 | wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA); |
| 1069 | if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) { |
| 1070 | wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request " |
| 1071 | "due to mismatch with Requested Device " |
| 1072 | "Type"); |
| 1073 | wpabuf_free(wps); |
| 1074 | return; |
| 1075 | } |
| 1076 | wpabuf_free(wps); |
| 1077 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1078 | |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 1079 | if (hapd->p2p && hapd->p2p_group && elems.p2p) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1080 | struct wpabuf *p2p; |
| 1081 | p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE); |
| 1082 | if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) { |
| 1083 | wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request " |
| 1084 | "due to mismatch with Device ID"); |
| 1085 | wpabuf_free(p2p); |
| 1086 | return; |
| 1087 | } |
| 1088 | wpabuf_free(p2p); |
| 1089 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1090 | #endif /* CONFIG_P2P */ |
| 1091 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1092 | if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1093 | elems.ssid_list_len == 0 && elems.short_ssid_list_len == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1094 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for " |
| 1095 | "broadcast SSID ignored", MAC2STR(mgmt->sa)); |
| 1096 | return; |
| 1097 | } |
| 1098 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1099 | #ifdef CONFIG_P2P |
| 1100 | if ((hapd->conf->p2p & P2P_GROUP_OWNER) && |
| 1101 | elems.ssid_len == P2P_WILDCARD_SSID_LEN && |
| 1102 | os_memcmp(elems.ssid, P2P_WILDCARD_SSID, |
| 1103 | P2P_WILDCARD_SSID_LEN) == 0) { |
| 1104 | /* Process P2P Wildcard SSID like Wildcard SSID */ |
| 1105 | elems.ssid_len = 0; |
| 1106 | } |
| 1107 | #endif /* CONFIG_P2P */ |
| 1108 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 1109 | #ifdef CONFIG_TAXONOMY |
| 1110 | { |
| 1111 | struct sta_info *sta; |
| 1112 | struct hostapd_sta_info *info; |
| 1113 | |
| 1114 | if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) { |
| 1115 | taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len); |
| 1116 | } else if ((info = sta_track_get(hapd->iface, |
| 1117 | mgmt->sa)) != NULL) { |
| 1118 | taxonomy_hostapd_sta_info_probe_req(hapd, info, |
| 1119 | ie, ie_len); |
| 1120 | } |
| 1121 | } |
| 1122 | #endif /* CONFIG_TAXONOMY */ |
| 1123 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1124 | res = ssid_match(hapd, elems.ssid, elems.ssid_len, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1125 | elems.ssid_list, elems.ssid_list_len, |
| 1126 | elems.short_ssid_list, elems.short_ssid_list_len); |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 1127 | if (res == NO_SSID_MATCH) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1128 | if (!(mgmt->da[0] & 0x01)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1129 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1130 | " for foreign SSID '%s' (DA " MACSTR ")%s", |
Dmitry Shmidt | 3c47937 | 2014-02-04 10:50:36 -0800 | [diff] [blame] | 1131 | MAC2STR(mgmt->sa), |
| 1132 | wpa_ssid_txt(elems.ssid, elems.ssid_len), |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1133 | MAC2STR(mgmt->da), |
| 1134 | elems.ssid_list ? " (SSID list)" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1135 | } |
| 1136 | return; |
| 1137 | } |
| 1138 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1139 | if (hapd->conf->ignore_broadcast_ssid && res == WILDCARD_SSID_MATCH) { |
| 1140 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for " |
| 1141 | "broadcast SSID ignored", MAC2STR(mgmt->sa)); |
| 1142 | return; |
| 1143 | } |
| 1144 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1145 | #ifdef CONFIG_INTERWORKING |
Dmitry Shmidt | f9bdef9 | 2014-04-25 10:46:36 -0700 | [diff] [blame] | 1146 | if (hapd->conf->interworking && |
| 1147 | elems.interworking && elems.interworking_len >= 1) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1148 | u8 ant = elems.interworking[0] & 0x0f; |
| 1149 | if (ant != INTERWORKING_ANT_WILDCARD && |
| 1150 | ant != hapd->conf->access_network_type) { |
| 1151 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR |
| 1152 | " for mismatching ANT %u ignored", |
| 1153 | MAC2STR(mgmt->sa), ant); |
| 1154 | return; |
| 1155 | } |
| 1156 | } |
| 1157 | |
Dmitry Shmidt | f9bdef9 | 2014-04-25 10:46:36 -0700 | [diff] [blame] | 1158 | if (hapd->conf->interworking && elems.interworking && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1159 | (elems.interworking_len == 7 || elems.interworking_len == 9)) { |
| 1160 | const u8 *hessid; |
| 1161 | if (elems.interworking_len == 7) |
| 1162 | hessid = elems.interworking + 1; |
| 1163 | else |
| 1164 | hessid = elems.interworking + 1 + 2; |
| 1165 | if (!is_broadcast_ether_addr(hessid) && |
| 1166 | os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) { |
| 1167 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR |
| 1168 | " for mismatching HESSID " MACSTR |
| 1169 | " ignored", |
| 1170 | MAC2STR(mgmt->sa), MAC2STR(hessid)); |
| 1171 | return; |
| 1172 | } |
| 1173 | } |
| 1174 | #endif /* CONFIG_INTERWORKING */ |
| 1175 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1176 | #ifdef CONFIG_P2P |
| 1177 | if ((hapd->conf->p2p & P2P_GROUP_OWNER) && |
| 1178 | supp_rates_11b_only(&elems)) { |
| 1179 | /* Indicates support for 11b rates only */ |
| 1180 | wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from " |
| 1181 | MACSTR " with only 802.11b rates", |
| 1182 | MAC2STR(mgmt->sa)); |
| 1183 | return; |
| 1184 | } |
| 1185 | #endif /* CONFIG_P2P */ |
| 1186 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1187 | /* TODO: verify that supp_rates contains at least one matching rate |
| 1188 | * with AP configuration */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1189 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1190 | if (hapd->conf->no_probe_resp_if_seen_on && |
| 1191 | is_multicast_ether_addr(mgmt->da) && |
| 1192 | is_multicast_ether_addr(mgmt->bssid) && |
| 1193 | sta_track_seen_on(hapd->iface, mgmt->sa, |
| 1194 | hapd->conf->no_probe_resp_if_seen_on)) { |
| 1195 | wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR |
| 1196 | " since STA has been seen on %s", |
| 1197 | hapd->conf->iface, MAC2STR(mgmt->sa), |
| 1198 | hapd->conf->no_probe_resp_if_seen_on); |
| 1199 | return; |
| 1200 | } |
| 1201 | |
| 1202 | if (hapd->conf->no_probe_resp_if_max_sta && |
| 1203 | is_multicast_ether_addr(mgmt->da) && |
| 1204 | is_multicast_ether_addr(mgmt->bssid) && |
| 1205 | hapd->num_sta >= hapd->conf->max_num_sta && |
| 1206 | !ap_get_sta(hapd, mgmt->sa)) { |
| 1207 | wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR |
| 1208 | " since no room for additional STA", |
| 1209 | hapd->conf->iface, MAC2STR(mgmt->sa)); |
| 1210 | return; |
| 1211 | } |
| 1212 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1213 | #ifdef CONFIG_TESTING_OPTIONS |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 1214 | if (hapd->iconf->ignore_probe_probability > 0.0 && |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1215 | drand48() < hapd->iconf->ignore_probe_probability) { |
| 1216 | wpa_printf(MSG_INFO, |
| 1217 | "TESTING: ignoring probe request from " MACSTR, |
| 1218 | MAC2STR(mgmt->sa)); |
| 1219 | return; |
| 1220 | } |
| 1221 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 1222 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1223 | /* Do not send Probe Response frame from a non-transmitting multiple |
| 1224 | * BSSID profile unless the Probe Request frame is directed at that |
| 1225 | * particular BSS. */ |
| 1226 | if (hapd != hostapd_mbssid_get_tx_bss(hapd) && res != EXACT_SSID_MATCH) |
| 1227 | return; |
| 1228 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1229 | wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, RX_PROBE_REQUEST "sa=" MACSTR |
| 1230 | " signal=%d", MAC2STR(mgmt->sa), ssi_signal); |
| 1231 | |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 1232 | resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1233 | &resp_len, false, elems.mbssid_known_bss, |
| 1234 | elems.mbssid_known_bss_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1235 | if (resp == NULL) |
| 1236 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1237 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1238 | /* |
| 1239 | * If this is a broadcast probe request, apply no ack policy to avoid |
| 1240 | * excessive retries. |
| 1241 | */ |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1242 | noack = !!(res == WILDCARD_SSID_MATCH && |
| 1243 | is_broadcast_ether_addr(mgmt->da)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1244 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1245 | csa_offs_len = 0; |
| 1246 | if (hapd->csa_in_progress) { |
| 1247 | if (hapd->cs_c_off_proberesp) |
| 1248 | csa_offs[csa_offs_len++] = |
| 1249 | hapd->cs_c_off_proberesp; |
| 1250 | |
| 1251 | if (hapd->cs_c_off_ecsa_proberesp) |
| 1252 | csa_offs[csa_offs_len++] = |
| 1253 | hapd->cs_c_off_ecsa_proberesp; |
| 1254 | } |
| 1255 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1256 | ret = hostapd_drv_send_mlme(hostapd_mbssid_get_tx_bss(hapd), resp, |
| 1257 | resp_len, noack, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1258 | csa_offs_len ? csa_offs : NULL, |
| 1259 | csa_offs_len, 0); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1260 | |
| 1261 | if (ret < 0) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1262 | wpa_printf(MSG_INFO, "handle_probe_req: send failed"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1263 | |
| 1264 | os_free(resp); |
| 1265 | |
| 1266 | wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s " |
| 1267 | "SSID", MAC2STR(mgmt->sa), |
| 1268 | elems.ssid_len == 0 ? "broadcast" : "our"); |
| 1269 | } |
| 1270 | |
| 1271 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1272 | static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd, |
| 1273 | size_t *resp_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1274 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1275 | /* check probe response offloading caps and print warnings */ |
| 1276 | if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD)) |
| 1277 | return NULL; |
| 1278 | |
| 1279 | #ifdef CONFIG_WPS |
| 1280 | if (hapd->conf->wps_state && hapd->wps_probe_resp_ie && |
| 1281 | (!(hapd->iface->probe_resp_offloads & |
| 1282 | (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS | |
| 1283 | WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2)))) |
| 1284 | wpa_printf(MSG_WARNING, "Device is trying to offload WPS " |
| 1285 | "Probe Response while not supporting this"); |
| 1286 | #endif /* CONFIG_WPS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1287 | |
| 1288 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1289 | if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie && |
| 1290 | !(hapd->iface->probe_resp_offloads & |
| 1291 | WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P)) |
| 1292 | wpa_printf(MSG_WARNING, "Device is trying to offload P2P " |
| 1293 | "Probe Response while not supporting this"); |
| 1294 | #endif /* CONFIG_P2P */ |
| 1295 | |
| 1296 | if (hapd->conf->interworking && |
| 1297 | !(hapd->iface->probe_resp_offloads & |
| 1298 | WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING)) |
| 1299 | wpa_printf(MSG_WARNING, "Device is trying to offload " |
| 1300 | "Interworking Probe Response while not supporting " |
| 1301 | "this"); |
| 1302 | |
| 1303 | /* Generate a Probe Response template for the non-P2P case */ |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1304 | return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len, false, NULL, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | #endif /* NEED_AP_MLME */ |
| 1308 | |
| 1309 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1310 | #ifdef CONFIG_IEEE80211AX |
| 1311 | /* Unsolicited broadcast Probe Response transmission, 6 GHz only */ |
| 1312 | static u8 * hostapd_unsol_bcast_probe_resp(struct hostapd_data *hapd, |
| 1313 | struct wpa_driver_ap_params *params) |
| 1314 | { |
| 1315 | if (!is_6ghz_op_class(hapd->iconf->op_class)) |
| 1316 | return NULL; |
| 1317 | |
| 1318 | params->unsol_bcast_probe_resp_interval = |
| 1319 | hapd->conf->unsol_bcast_probe_resp_interval; |
| 1320 | |
| 1321 | return hostapd_gen_probe_resp(hapd, NULL, 0, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1322 | ¶ms->unsol_bcast_probe_resp_tmpl_len, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1323 | true, NULL, 0); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1324 | } |
| 1325 | #endif /* CONFIG_IEEE80211AX */ |
| 1326 | |
| 1327 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 1328 | void sta_track_del(struct hostapd_sta_info *info) |
| 1329 | { |
| 1330 | #ifdef CONFIG_TAXONOMY |
| 1331 | wpabuf_free(info->probe_ie_taxonomy); |
| 1332 | info->probe_ie_taxonomy = NULL; |
| 1333 | #endif /* CONFIG_TAXONOMY */ |
| 1334 | os_free(info); |
| 1335 | } |
| 1336 | |
| 1337 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1338 | #ifdef CONFIG_FILS |
| 1339 | |
| 1340 | static u16 hostapd_fils_discovery_cap(struct hostapd_data *hapd) |
| 1341 | { |
| 1342 | u16 cap_info, phy_index = 0; |
| 1343 | u8 chwidth = FD_CAP_BSS_CHWIDTH_20, mcs_nss_size = 4; |
| 1344 | struct hostapd_hw_modes *mode = hapd->iface->current_mode; |
| 1345 | |
| 1346 | cap_info = FD_CAP_ESS; |
| 1347 | if (hapd->conf->wpa) |
| 1348 | cap_info |= FD_CAP_PRIVACY; |
| 1349 | |
| 1350 | if (is_6ghz_op_class(hapd->iconf->op_class)) { |
| 1351 | phy_index = FD_CAP_PHY_INDEX_HE; |
| 1352 | |
| 1353 | switch (hapd->iconf->op_class) { |
| 1354 | case 135: |
| 1355 | mcs_nss_size += 4; |
| 1356 | /* fallthrough */ |
| 1357 | case 134: |
| 1358 | mcs_nss_size += 4; |
| 1359 | chwidth = FD_CAP_BSS_CHWIDTH_160_80_80; |
| 1360 | break; |
| 1361 | case 133: |
| 1362 | chwidth = FD_CAP_BSS_CHWIDTH_80; |
| 1363 | break; |
| 1364 | case 132: |
| 1365 | chwidth = FD_CAP_BSS_CHWIDTH_40; |
| 1366 | break; |
| 1367 | } |
| 1368 | } else { |
| 1369 | switch (hostapd_get_oper_chwidth(hapd->iconf)) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1370 | case CONF_OPER_CHWIDTH_80P80MHZ: |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1371 | mcs_nss_size += 4; |
| 1372 | /* fallthrough */ |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1373 | case CONF_OPER_CHWIDTH_160MHZ: |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1374 | mcs_nss_size += 4; |
| 1375 | chwidth = FD_CAP_BSS_CHWIDTH_160_80_80; |
| 1376 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1377 | case CONF_OPER_CHWIDTH_80MHZ: |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1378 | chwidth = FD_CAP_BSS_CHWIDTH_80; |
| 1379 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1380 | case CONF_OPER_CHWIDTH_USE_HT: |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1381 | if (hapd->iconf->secondary_channel) |
| 1382 | chwidth = FD_CAP_BSS_CHWIDTH_40; |
| 1383 | else |
| 1384 | chwidth = FD_CAP_BSS_CHWIDTH_20; |
| 1385 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1386 | default: |
| 1387 | break; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | #ifdef CONFIG_IEEE80211AX |
| 1391 | if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) |
| 1392 | phy_index = FD_CAP_PHY_INDEX_HE; |
| 1393 | #endif /* CONFIG_IEEE80211AX */ |
| 1394 | #ifdef CONFIG_IEEE80211AC |
| 1395 | if (!phy_index && |
| 1396 | hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) |
| 1397 | phy_index = FD_CAP_PHY_INDEX_VHT; |
| 1398 | #endif /* CONFIG_IEEE80211AC */ |
| 1399 | if (!phy_index && |
| 1400 | hapd->iconf->ieee80211n && !hapd->conf->disable_11n) |
| 1401 | phy_index = FD_CAP_PHY_INDEX_HT; |
| 1402 | } |
| 1403 | |
| 1404 | cap_info |= phy_index << FD_CAP_PHY_INDEX_SHIFT; |
| 1405 | cap_info |= chwidth << FD_CAP_BSS_CHWIDTH_SHIFT; |
| 1406 | |
| 1407 | if (mode) { |
| 1408 | u16 *mcs = (u16 *) mode->he_capab[IEEE80211_MODE_AP].mcs; |
| 1409 | int i; |
| 1410 | u16 nss = 0; |
| 1411 | |
| 1412 | for (i = 0; i < HE_NSS_MAX_STREAMS; i++) { |
| 1413 | u16 nss_mask = 0x3 << (i * 2); |
| 1414 | |
| 1415 | if (mcs_nss_size == 4 && |
| 1416 | (((mcs[0] & nss_mask) == nss_mask) || |
| 1417 | ((mcs[1] & nss_mask) == nss_mask))) |
| 1418 | continue; |
| 1419 | |
| 1420 | if (mcs_nss_size == 8 && |
| 1421 | (((mcs[2] & nss_mask) == nss_mask) || |
| 1422 | ((mcs[3] & nss_mask) == nss_mask))) |
| 1423 | continue; |
| 1424 | |
| 1425 | if (mcs_nss_size == 12 && |
| 1426 | (((mcs[4] & nss_mask) == nss_mask) || |
| 1427 | ((mcs[5] & nss_mask) == nss_mask))) |
| 1428 | continue; |
| 1429 | |
| 1430 | nss++; |
| 1431 | } |
| 1432 | |
| 1433 | if (nss > 4) |
| 1434 | cap_info |= FD_CAP_NSS_5_8 << FD_CAP_NSS_SHIFT; |
| 1435 | else if (nss) |
| 1436 | cap_info |= (nss - 1) << FD_CAP_NSS_SHIFT; |
| 1437 | } |
| 1438 | |
| 1439 | return cap_info; |
| 1440 | } |
| 1441 | |
| 1442 | |
| 1443 | static u8 * hostapd_gen_fils_discovery(struct hostapd_data *hapd, size_t *len) |
| 1444 | { |
| 1445 | struct ieee80211_mgmt *head; |
| 1446 | const u8 *mobility_domain; |
| 1447 | u8 *pos, *length_pos, buf[200]; |
| 1448 | u16 ctl = 0; |
| 1449 | u8 fd_rsn_info[5]; |
| 1450 | size_t total_len, buf_len; |
| 1451 | |
| 1452 | total_len = 24 + 2 + 12; |
| 1453 | |
| 1454 | /* FILS Discovery Frame Control */ |
| 1455 | ctl = (sizeof(hapd->conf->ssid.short_ssid) - 1) | |
| 1456 | FD_FRAME_CTL_SHORT_SSID_PRESENT | |
| 1457 | FD_FRAME_CTL_LENGTH_PRESENT | |
| 1458 | FD_FRAME_CTL_CAP_PRESENT; |
| 1459 | total_len += 4 + 1 + 2; |
| 1460 | |
| 1461 | /* Check for optional subfields and calculate length */ |
| 1462 | if (wpa_auth_write_fd_rsn_info(hapd->wpa_auth, fd_rsn_info)) { |
| 1463 | ctl |= FD_FRAME_CTL_RSN_INFO_PRESENT; |
| 1464 | total_len += sizeof(fd_rsn_info); |
| 1465 | } |
| 1466 | |
| 1467 | mobility_domain = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN); |
| 1468 | if (mobility_domain) { |
| 1469 | ctl |= FD_FRAME_CTL_MD_PRESENT; |
| 1470 | total_len += 3; |
| 1471 | } |
| 1472 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1473 | total_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_ACTION); |
| 1474 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1475 | pos = hostapd_eid_fils_indic(hapd, buf, 0); |
| 1476 | buf_len = pos - buf; |
| 1477 | total_len += buf_len; |
| 1478 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1479 | #ifdef CONFIG_IEEE80211AX |
| 1480 | /* Transmit Power Envelope element(s) */ |
| 1481 | if (is_6ghz_op_class(hapd->iconf->op_class)) { |
| 1482 | total_len += 4; |
| 1483 | if (hapd->iconf->he_6ghz_reg_pwr_type == HE_6GHZ_INDOOR_AP) |
| 1484 | total_len += 4; |
| 1485 | } |
| 1486 | #endif /* CONFIG_IEEE80211AX */ |
| 1487 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1488 | head = os_zalloc(total_len); |
| 1489 | if (!head) |
| 1490 | return NULL; |
| 1491 | |
| 1492 | head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 1493 | WLAN_FC_STYPE_ACTION); |
| 1494 | os_memset(head->da, 0xff, ETH_ALEN); |
| 1495 | os_memcpy(head->sa, hapd->own_addr, ETH_ALEN); |
| 1496 | os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN); |
| 1497 | |
| 1498 | head->u.action.category = WLAN_ACTION_PUBLIC; |
| 1499 | head->u.action.u.public_action.action = WLAN_PA_FILS_DISCOVERY; |
| 1500 | |
| 1501 | pos = &head->u.action.u.public_action.variable[0]; |
| 1502 | |
| 1503 | /* FILS Discovery Information field */ |
| 1504 | |
| 1505 | /* FILS Discovery Frame Control */ |
| 1506 | WPA_PUT_LE16(pos, ctl); |
| 1507 | pos += 2; |
| 1508 | |
| 1509 | /* Hardware or low-level driver will fill in the Timestamp value */ |
| 1510 | pos += 8; |
| 1511 | |
| 1512 | /* Beacon Interval */ |
| 1513 | WPA_PUT_LE16(pos, hapd->iconf->beacon_int); |
| 1514 | pos += 2; |
| 1515 | |
| 1516 | /* Short SSID */ |
| 1517 | WPA_PUT_LE32(pos, hapd->conf->ssid.short_ssid); |
| 1518 | pos += sizeof(hapd->conf->ssid.short_ssid); |
| 1519 | |
| 1520 | /* Store position of FILS discovery information element Length field */ |
| 1521 | length_pos = pos++; |
| 1522 | |
| 1523 | /* FD Capability */ |
| 1524 | WPA_PUT_LE16(pos, hostapd_fils_discovery_cap(hapd)); |
| 1525 | pos += 2; |
| 1526 | |
| 1527 | /* Operating Class - not present */ |
| 1528 | |
| 1529 | /* Primary Channel - not present */ |
| 1530 | |
| 1531 | /* AP Configuration Sequence Number - not present */ |
| 1532 | |
| 1533 | /* Access Network Options - not present */ |
| 1534 | |
| 1535 | /* FD RSN Information */ |
| 1536 | if (ctl & FD_FRAME_CTL_RSN_INFO_PRESENT) { |
| 1537 | os_memcpy(pos, fd_rsn_info, sizeof(fd_rsn_info)); |
| 1538 | pos += sizeof(fd_rsn_info); |
| 1539 | } |
| 1540 | |
| 1541 | /* Channel Center Frequency Segment 1 - not present */ |
| 1542 | |
| 1543 | /* Mobility Domain */ |
| 1544 | if (ctl & FD_FRAME_CTL_MD_PRESENT) { |
| 1545 | os_memcpy(pos, &mobility_domain[2], 3); |
| 1546 | pos += 3; |
| 1547 | } |
| 1548 | |
| 1549 | /* Fill in the Length field value */ |
| 1550 | *length_pos = pos - (length_pos + 1); |
| 1551 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1552 | pos = hostapd_eid_rnr(hapd, pos, WLAN_FC_STYPE_ACTION); |
| 1553 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1554 | /* FILS Indication element */ |
| 1555 | if (buf_len) { |
| 1556 | os_memcpy(pos, buf, buf_len); |
| 1557 | pos += buf_len; |
| 1558 | } |
| 1559 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1560 | if (is_6ghz_op_class(hapd->iconf->op_class)) |
| 1561 | pos = hostapd_eid_txpower_envelope(hapd, pos); |
| 1562 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1563 | *len = pos - (u8 *) head; |
| 1564 | wpa_hexdump(MSG_DEBUG, "FILS Discovery frame template", |
| 1565 | head, pos - (u8 *) head); |
| 1566 | return (u8 *) head; |
| 1567 | } |
| 1568 | |
| 1569 | |
| 1570 | /* Configure FILS Discovery frame transmission parameters */ |
| 1571 | static u8 * hostapd_fils_discovery(struct hostapd_data *hapd, |
| 1572 | struct wpa_driver_ap_params *params) |
| 1573 | { |
| 1574 | params->fd_max_int = hapd->conf->fils_discovery_max_int; |
| 1575 | if (is_6ghz_op_class(hapd->iconf->op_class) && |
| 1576 | params->fd_max_int > FD_MAX_INTERVAL_6GHZ) |
| 1577 | params->fd_max_int = FD_MAX_INTERVAL_6GHZ; |
| 1578 | |
| 1579 | params->fd_min_int = hapd->conf->fils_discovery_min_int; |
| 1580 | if (params->fd_min_int > params->fd_max_int) |
| 1581 | params->fd_min_int = params->fd_max_int; |
| 1582 | |
| 1583 | if (params->fd_max_int) |
| 1584 | return hostapd_gen_fils_discovery(hapd, |
| 1585 | ¶ms->fd_frame_tmpl_len); |
| 1586 | |
| 1587 | return NULL; |
| 1588 | } |
| 1589 | |
| 1590 | #endif /* CONFIG_FILS */ |
| 1591 | |
| 1592 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1593 | int ieee802_11_build_ap_params(struct hostapd_data *hapd, |
| 1594 | struct wpa_driver_ap_params *params) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1595 | { |
| 1596 | struct ieee80211_mgmt *head = NULL; |
| 1597 | u8 *tail = NULL; |
| 1598 | size_t head_len = 0, tail_len = 0; |
| 1599 | u8 *resp = NULL; |
| 1600 | size_t resp_len = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1601 | #ifdef NEED_AP_MLME |
| 1602 | u16 capab_info; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1603 | u8 *pos, *tailpos, *tailend, *csa_pos; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1604 | bool complete = false; |
| 1605 | #endif /* NEED_AP_MLME */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1606 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1607 | os_memset(params, 0, sizeof(*params)); |
| 1608 | |
| 1609 | #ifdef NEED_AP_MLME |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1610 | #define BEACON_HEAD_BUF_SIZE 256 |
| 1611 | #define BEACON_TAIL_BUF_SIZE 512 |
| 1612 | head = os_zalloc(BEACON_HEAD_BUF_SIZE); |
| 1613 | tail_len = BEACON_TAIL_BUF_SIZE; |
| 1614 | #ifdef CONFIG_WPS |
| 1615 | if (hapd->conf->wps_state && hapd->wps_beacon_ie) |
| 1616 | tail_len += wpabuf_len(hapd->wps_beacon_ie); |
| 1617 | #endif /* CONFIG_WPS */ |
| 1618 | #ifdef CONFIG_P2P |
| 1619 | if (hapd->p2p_beacon_ie) |
| 1620 | tail_len += wpabuf_len(hapd->p2p_beacon_ie); |
| 1621 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1622 | #ifdef CONFIG_FST |
| 1623 | if (hapd->iface->fst_ies) |
| 1624 | tail_len += wpabuf_len(hapd->iface->fst_ies); |
| 1625 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1626 | if (hapd->conf->vendor_elements) |
| 1627 | tail_len += wpabuf_len(hapd->conf->vendor_elements); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1628 | |
| 1629 | #ifdef CONFIG_IEEE80211AC |
| 1630 | if (hapd->conf->vendor_vht) { |
| 1631 | tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) + |
| 1632 | 2 + sizeof(struct ieee80211_vht_operation); |
| 1633 | } |
| 1634 | #endif /* CONFIG_IEEE80211AC */ |
| 1635 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1636 | #ifdef CONFIG_IEEE80211AX |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1637 | if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1638 | tail_len += 3 + sizeof(struct ieee80211_he_capabilities) + |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1639 | 3 + sizeof(struct ieee80211_he_operation) + |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1640 | 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) + |
| 1641 | 3 + sizeof(struct ieee80211_spatial_reuse); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1642 | if (is_6ghz_op_class(hapd->iconf->op_class)) { |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1643 | tail_len += sizeof(struct ieee80211_he_6ghz_oper_info) + |
| 1644 | 3 + sizeof(struct ieee80211_he_6ghz_band_cap); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1645 | /* An additional Transmit Power Envelope element for |
| 1646 | * subordinate client */ |
| 1647 | if (hapd->iconf->he_6ghz_reg_pwr_type == |
| 1648 | HE_6GHZ_INDOOR_AP) |
| 1649 | tail_len += 4; |
| 1650 | } |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1651 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1652 | #endif /* CONFIG_IEEE80211AX */ |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1653 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1654 | #ifdef CONFIG_IEEE80211BE |
| 1655 | if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) { |
| 1656 | tail_len += hostapd_eid_eht_capab_len(hapd, IEEE80211_MODE_AP); |
| 1657 | tail_len += 3 + sizeof(struct ieee80211_eht_operation); |
| 1658 | } |
| 1659 | #endif /* CONFIG_IEEE80211BE */ |
| 1660 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1661 | if (hapd->iconf->mbssid == ENHANCED_MBSSID_ENABLED && |
| 1662 | hapd == hostapd_mbssid_get_tx_bss(hapd)) |
| 1663 | tail_len += 5; /* Multiple BSSID Configuration element */ |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1664 | tail_len += hostapd_eid_rnr_len(hapd, WLAN_FC_STYPE_BEACON); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1665 | tail_len += hostapd_mbo_ie_len(hapd); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1666 | tail_len += hostapd_eid_owe_trans_len(hapd); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1667 | tail_len += hostapd_eid_dpp_cc_len(hapd); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1668 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1669 | tailpos = tail = os_malloc(tail_len); |
| 1670 | if (head == NULL || tail == NULL) { |
| 1671 | wpa_printf(MSG_ERROR, "Failed to set beacon data"); |
| 1672 | os_free(head); |
| 1673 | os_free(tail); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1674 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1675 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1676 | tailend = tail + tail_len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1677 | |
| 1678 | head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 1679 | WLAN_FC_STYPE_BEACON); |
| 1680 | head->duration = host_to_le16(0); |
| 1681 | os_memset(head->da, 0xff, ETH_ALEN); |
| 1682 | |
| 1683 | os_memcpy(head->sa, hapd->own_addr, ETH_ALEN); |
| 1684 | os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN); |
| 1685 | head->u.beacon.beacon_int = |
| 1686 | host_to_le16(hapd->iconf->beacon_int); |
| 1687 | |
| 1688 | /* hardware or low-level driver will setup seq_ctrl and timestamp */ |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 1689 | capab_info = hostapd_own_capab_info(hapd); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1690 | head->u.beacon.capab_info = host_to_le16(capab_info); |
| 1691 | pos = &head->u.beacon.variable[0]; |
| 1692 | |
| 1693 | /* SSID */ |
| 1694 | *pos++ = WLAN_EID_SSID; |
| 1695 | if (hapd->conf->ignore_broadcast_ssid == 2) { |
| 1696 | /* clear the data, but keep the correct length of the SSID */ |
| 1697 | *pos++ = hapd->conf->ssid.ssid_len; |
| 1698 | os_memset(pos, 0, hapd->conf->ssid.ssid_len); |
| 1699 | pos += hapd->conf->ssid.ssid_len; |
| 1700 | } else if (hapd->conf->ignore_broadcast_ssid) { |
| 1701 | *pos++ = 0; /* empty SSID */ |
| 1702 | } else { |
| 1703 | *pos++ = hapd->conf->ssid.ssid_len; |
| 1704 | os_memcpy(pos, hapd->conf->ssid.ssid, |
| 1705 | hapd->conf->ssid.ssid_len); |
| 1706 | pos += hapd->conf->ssid.ssid_len; |
| 1707 | } |
| 1708 | |
| 1709 | /* Supported rates */ |
| 1710 | pos = hostapd_eid_supp_rates(hapd, pos); |
| 1711 | |
| 1712 | /* DS Params */ |
| 1713 | pos = hostapd_eid_ds_params(hapd, pos); |
| 1714 | |
| 1715 | head_len = pos - (u8 *) head; |
| 1716 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1717 | tailpos = hostapd_eid_country(hapd, tailpos, tailend - tailpos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1718 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1719 | /* Power Constraint element */ |
| 1720 | tailpos = hostapd_eid_pwr_constraint(hapd, tailpos); |
| 1721 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1722 | /* CSA IE */ |
| 1723 | csa_pos = hostapd_eid_csa(hapd, tailpos); |
| 1724 | if (csa_pos != tailpos) |
| 1725 | hapd->cs_c_off_beacon = csa_pos - tail - 1; |
| 1726 | tailpos = csa_pos; |
| 1727 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1728 | /* ERP Information element */ |
| 1729 | tailpos = hostapd_eid_erp_info(hapd, tailpos); |
| 1730 | |
| 1731 | /* Extended supported rates */ |
| 1732 | tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos); |
| 1733 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1734 | tailpos = hostapd_get_rsne(hapd, tailpos, tailend - tailpos); |
| 1735 | tailpos = hostapd_eid_bss_load(hapd, tailpos, tailend - tailpos); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1736 | tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1737 | tailend - tailpos); |
| 1738 | tailpos = hostapd_get_mde(hapd, tailpos, tailend - tailpos); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1739 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1740 | /* eCSA IE */ |
| 1741 | csa_pos = hostapd_eid_ecsa(hapd, tailpos); |
| 1742 | if (csa_pos != tailpos) |
| 1743 | hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1; |
| 1744 | tailpos = csa_pos; |
| 1745 | |
| 1746 | tailpos = hostapd_eid_supported_op_classes(hapd, tailpos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1747 | tailpos = hostapd_eid_ht_capabilities(hapd, tailpos); |
| 1748 | tailpos = hostapd_eid_ht_operation(hapd, tailpos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1749 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1750 | if (hapd->iconf->mbssid && hapd->iconf->num_bss > 1) { |
| 1751 | if (ieee802_11_build_ap_params_mbssid(hapd, params)) { |
| 1752 | os_free(head); |
| 1753 | os_free(tail); |
| 1754 | wpa_printf(MSG_ERROR, |
| 1755 | "MBSSID: Failed to set beacon data"); |
| 1756 | return -1; |
| 1757 | } |
| 1758 | complete = hapd->iconf->mbssid == MBSSID_ENABLED || |
| 1759 | (hapd->iconf->mbssid == ENHANCED_MBSSID_ENABLED && |
| 1760 | params->mbssid_elem_count == 1); |
| 1761 | } |
| 1762 | |
| 1763 | tailpos = hostapd_eid_ext_capab(hapd, tailpos, complete); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1764 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1765 | /* |
| 1766 | * TODO: Time Advertisement element should only be included in some |
| 1767 | * DTIM Beacon frames. |
| 1768 | */ |
| 1769 | tailpos = hostapd_eid_time_adv(hapd, tailpos); |
| 1770 | |
| 1771 | tailpos = hostapd_eid_interworking(hapd, tailpos); |
| 1772 | tailpos = hostapd_eid_adv_proto(hapd, tailpos); |
| 1773 | tailpos = hostapd_eid_roaming_consortium(hapd, tailpos); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1774 | |
| 1775 | #ifdef CONFIG_FST |
| 1776 | if (hapd->iface->fst_ies) { |
| 1777 | os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies), |
| 1778 | wpabuf_len(hapd->iface->fst_ies)); |
| 1779 | tailpos += wpabuf_len(hapd->iface->fst_ies); |
| 1780 | } |
| 1781 | #endif /* CONFIG_FST */ |
| 1782 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1783 | #ifdef CONFIG_IEEE80211AC |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1784 | if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac && |
| 1785 | !is_6ghz_op_class(hapd->iconf->op_class)) { |
Dmitry Shmidt | 7d17530 | 2016-09-06 13:11:34 -0700 | [diff] [blame] | 1786 | tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1787 | tailpos = hostapd_eid_vht_operation(hapd, tailpos); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 1788 | tailpos = hostapd_eid_txpower_envelope(hapd, tailpos); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1789 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1790 | #endif /* CONFIG_IEEE80211AC */ |
| 1791 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1792 | #ifdef CONFIG_IEEE80211AX |
| 1793 | if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax && |
| 1794 | is_6ghz_op_class(hapd->iconf->op_class)) |
| 1795 | tailpos = hostapd_eid_txpower_envelope(hapd, tailpos); |
| 1796 | #endif /* CONFIG_IEEE80211AX */ |
| 1797 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1798 | tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1799 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1800 | tailpos = hostapd_eid_rnr(hapd, tailpos, WLAN_FC_STYPE_BEACON); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1801 | tailpos = hostapd_eid_fils_indic(hapd, tailpos, 0); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1802 | tailpos = hostapd_get_rsnxe(hapd, tailpos, tailend - tailpos); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1803 | tailpos = hostapd_eid_mbssid_config(hapd, tailpos, |
| 1804 | params->mbssid_elem_count); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1805 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1806 | #ifdef CONFIG_IEEE80211AX |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1807 | if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) { |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1808 | u8 *cca_pos; |
| 1809 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1810 | tailpos = hostapd_eid_he_capab(hapd, tailpos, |
| 1811 | IEEE80211_MODE_AP); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1812 | tailpos = hostapd_eid_he_operation(hapd, tailpos); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1813 | |
| 1814 | /* BSS Color Change Announcement element */ |
| 1815 | cca_pos = hostapd_eid_cca(hapd, tailpos); |
| 1816 | if (cca_pos != tailpos) |
| 1817 | hapd->cca_c_off_beacon = cca_pos - tail - 2; |
| 1818 | tailpos = cca_pos; |
| 1819 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1820 | tailpos = hostapd_eid_spatial_reuse(hapd, tailpos); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1821 | tailpos = hostapd_eid_he_mu_edca_parameter_set(hapd, tailpos); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1822 | tailpos = hostapd_eid_he_6ghz_band_cap(hapd, tailpos); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1823 | } |
| 1824 | #endif /* CONFIG_IEEE80211AX */ |
| 1825 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1826 | #ifdef CONFIG_IEEE80211BE |
| 1827 | if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) { |
| 1828 | tailpos = hostapd_eid_eht_capab(hapd, tailpos, |
| 1829 | IEEE80211_MODE_AP); |
| 1830 | tailpos = hostapd_eid_eht_operation(hapd, tailpos); |
| 1831 | } |
| 1832 | #endif /* CONFIG_IEEE80211BE */ |
| 1833 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1834 | #ifdef CONFIG_IEEE80211AC |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1835 | if (hapd->conf->vendor_vht) |
| 1836 | tailpos = hostapd_eid_vendor_vht(hapd, tailpos); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1837 | #endif /* CONFIG_IEEE80211AC */ |
| 1838 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1839 | /* WPA / OSEN */ |
| 1840 | tailpos = hostapd_get_wpa_ie(hapd, tailpos, tailend - tailpos); |
| 1841 | tailpos = hostapd_get_osen_ie(hapd, tailpos, tailend - tailpos); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 1842 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1843 | /* Wi-Fi Alliance WMM */ |
| 1844 | tailpos = hostapd_eid_wmm(hapd, tailpos); |
| 1845 | |
| 1846 | #ifdef CONFIG_WPS |
| 1847 | if (hapd->conf->wps_state && hapd->wps_beacon_ie) { |
| 1848 | os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie), |
| 1849 | wpabuf_len(hapd->wps_beacon_ie)); |
| 1850 | tailpos += wpabuf_len(hapd->wps_beacon_ie); |
| 1851 | } |
| 1852 | #endif /* CONFIG_WPS */ |
| 1853 | |
| 1854 | #ifdef CONFIG_P2P |
| 1855 | if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) { |
| 1856 | os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie), |
| 1857 | wpabuf_len(hapd->p2p_beacon_ie)); |
| 1858 | tailpos += wpabuf_len(hapd->p2p_beacon_ie); |
| 1859 | } |
| 1860 | #endif /* CONFIG_P2P */ |
| 1861 | #ifdef CONFIG_P2P_MANAGER |
| 1862 | if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) == |
| 1863 | P2P_MANAGE) |
| 1864 | tailpos = hostapd_eid_p2p_manage(hapd, tailpos); |
| 1865 | #endif /* CONFIG_P2P_MANAGER */ |
| 1866 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1867 | #ifdef CONFIG_HS20 |
| 1868 | tailpos = hostapd_eid_hs20_indication(hapd, tailpos); |
| 1869 | #endif /* CONFIG_HS20 */ |
| 1870 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1871 | tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1872 | tailpos = hostapd_eid_owe_trans(hapd, tailpos, |
| 1873 | tail + tail_len - tailpos); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1874 | tailpos = hostapd_eid_dpp_cc(hapd, tailpos, tail + tail_len - tailpos); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1875 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1876 | if (hapd->conf->vendor_elements) { |
| 1877 | os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements), |
| 1878 | wpabuf_len(hapd->conf->vendor_elements)); |
| 1879 | tailpos += wpabuf_len(hapd->conf->vendor_elements); |
| 1880 | } |
| 1881 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1882 | tail_len = tailpos > tail ? tailpos - tail : 0; |
| 1883 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1884 | resp = hostapd_probe_resp_offloads(hapd, &resp_len); |
| 1885 | #endif /* NEED_AP_MLME */ |
| 1886 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1887 | params->head = (u8 *) head; |
| 1888 | params->head_len = head_len; |
| 1889 | params->tail = tail; |
| 1890 | params->tail_len = tail_len; |
| 1891 | params->proberesp = resp; |
| 1892 | params->proberesp_len = resp_len; |
| 1893 | params->dtim_period = hapd->conf->dtim_period; |
| 1894 | params->beacon_int = hapd->iconf->beacon_int; |
| 1895 | params->basic_rates = hapd->iface->basic_rates; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1896 | params->beacon_rate = hapd->iconf->beacon_rate; |
| 1897 | params->rate_type = hapd->iconf->rate_type; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1898 | params->ssid = hapd->conf->ssid.ssid; |
| 1899 | params->ssid_len = hapd->conf->ssid.ssid_len; |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 1900 | if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) == |
| 1901 | (WPA_PROTO_WPA | WPA_PROTO_RSN)) |
| 1902 | params->pairwise_ciphers = hapd->conf->wpa_pairwise | |
| 1903 | hapd->conf->rsn_pairwise; |
| 1904 | else if (hapd->conf->wpa & WPA_PROTO_RSN) |
| 1905 | params->pairwise_ciphers = hapd->conf->rsn_pairwise; |
| 1906 | else if (hapd->conf->wpa & WPA_PROTO_WPA) |
| 1907 | params->pairwise_ciphers = hapd->conf->wpa_pairwise; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1908 | params->group_cipher = hapd->conf->wpa_group; |
| 1909 | params->key_mgmt_suites = hapd->conf->wpa_key_mgmt; |
| 1910 | params->auth_algs = hapd->conf->auth_algs; |
| 1911 | params->wpa_version = hapd->conf->wpa; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1912 | params->privacy = hapd->conf->wpa; |
| 1913 | #ifdef CONFIG_WEP |
| 1914 | params->privacy |= hapd->conf->ssid.wep.keys_set || |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1915 | (hapd->conf->ieee802_1x && |
| 1916 | (hapd->conf->default_wep_key_len || |
| 1917 | hapd->conf->individual_wep_key_len)); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1918 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1919 | switch (hapd->conf->ignore_broadcast_ssid) { |
| 1920 | case 0: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1921 | params->hide_ssid = NO_SSID_HIDING; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1922 | break; |
| 1923 | case 1: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1924 | params->hide_ssid = HIDDEN_SSID_ZERO_LEN; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1925 | break; |
| 1926 | case 2: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1927 | params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1928 | break; |
| 1929 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1930 | params->isolate = hapd->conf->isolate; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1931 | #ifdef NEED_AP_MLME |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1932 | params->cts_protect = !!(ieee802_11_erp_info(hapd) & |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1933 | ERP_INFO_USE_PROTECTION); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1934 | params->preamble = hapd->iface->num_sta_no_short_preamble == 0 && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1935 | hapd->iconf->preamble == SHORT_PREAMBLE; |
| 1936 | if (hapd->iface->current_mode && |
| 1937 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1938 | params->short_slot_time = |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1939 | hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1; |
| 1940 | else |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1941 | params->short_slot_time = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1942 | if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1943 | params->ht_opmode = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1944 | else |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1945 | params->ht_opmode = hapd->iface->ht_op_mode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1946 | #endif /* NEED_AP_MLME */ |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1947 | params->interworking = hapd->conf->interworking; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1948 | if (hapd->conf->interworking && |
| 1949 | !is_zero_ether_addr(hapd->conf->hessid)) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1950 | params->hessid = hapd->conf->hessid; |
| 1951 | params->access_network_type = hapd->conf->access_network_type; |
| 1952 | params->ap_max_inactivity = hapd->conf->ap_max_inactivity; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1953 | #ifdef CONFIG_P2P |
| 1954 | params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow; |
| 1955 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1956 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1957 | params->disable_dgaf = hapd->conf->disable_dgaf; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1958 | if (hapd->conf->osen) { |
| 1959 | params->privacy = 1; |
| 1960 | params->osen = 1; |
| 1961 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1962 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1963 | params->multicast_to_unicast = hapd->conf->multicast_to_unicast; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1964 | params->pbss = hapd->conf->pbss; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1965 | |
| 1966 | if (hapd->conf->ftm_responder) { |
| 1967 | if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_FTM_RESPONDER) { |
| 1968 | params->ftm_responder = 1; |
| 1969 | params->lci = hapd->iface->conf->lci; |
| 1970 | params->civic = hapd->iface->conf->civic; |
| 1971 | } else { |
| 1972 | wpa_printf(MSG_WARNING, |
| 1973 | "Not configuring FTM responder as the driver doesn't advertise support for it"); |
| 1974 | } |
| 1975 | } |
| 1976 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1977 | return 0; |
| 1978 | } |
| 1979 | |
| 1980 | |
| 1981 | void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params) |
| 1982 | { |
| 1983 | os_free(params->tail); |
| 1984 | params->tail = NULL; |
| 1985 | os_free(params->head); |
| 1986 | params->head = NULL; |
| 1987 | os_free(params->proberesp); |
| 1988 | params->proberesp = NULL; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1989 | os_free(params->mbssid_elem); |
| 1990 | params->mbssid_elem = NULL; |
| 1991 | os_free(params->mbssid_elem_offset); |
| 1992 | params->mbssid_elem_offset = NULL; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1993 | #ifdef CONFIG_FILS |
| 1994 | os_free(params->fd_frame_tmpl); |
| 1995 | params->fd_frame_tmpl = NULL; |
| 1996 | #endif /* CONFIG_FILS */ |
| 1997 | #ifdef CONFIG_IEEE80211AX |
| 1998 | os_free(params->unsol_bcast_probe_resp_tmpl); |
| 1999 | params->unsol_bcast_probe_resp_tmpl = NULL; |
| 2000 | #endif /* CONFIG_IEEE80211AX */ |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2004 | static int __ieee802_11_set_beacon(struct hostapd_data *hapd) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2005 | { |
| 2006 | struct wpa_driver_ap_params params; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2007 | struct hostapd_freq_params freq; |
| 2008 | struct hostapd_iface *iface = hapd->iface; |
| 2009 | struct hostapd_config *iconf = iface->conf; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2010 | struct hostapd_hw_modes *cmode = iface->current_mode; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2011 | struct wpabuf *beacon, *proberesp, *assocresp; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2012 | int res, ret = -1; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2013 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2014 | if (!hapd->drv_priv) { |
| 2015 | wpa_printf(MSG_ERROR, "Interface is disabled"); |
| 2016 | return -1; |
| 2017 | } |
| 2018 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 2019 | if (hapd->csa_in_progress) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2020 | wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period"); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2021 | return -1; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2022 | } |
| 2023 | |
| 2024 | hapd->beacon_set_done = 1; |
| 2025 | |
| 2026 | if (ieee802_11_build_ap_params(hapd, ¶ms) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2027 | return -1; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2028 | |
| 2029 | if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) < |
| 2030 | 0) |
| 2031 | goto fail; |
| 2032 | |
| 2033 | params.beacon_ies = beacon; |
| 2034 | params.proberesp_ies = proberesp; |
| 2035 | params.assocresp_ies = assocresp; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2036 | params.reenable = hapd->reenable_beacon; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2037 | #ifdef CONFIG_IEEE80211AX |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2038 | params.he_spr_ctrl = hapd->iface->conf->spr.sr_control; |
| 2039 | params.he_spr_non_srg_obss_pd_max_offset = |
| 2040 | hapd->iface->conf->spr.non_srg_obss_pd_max_offset; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2041 | params.he_spr_srg_obss_pd_min_offset = |
| 2042 | hapd->iface->conf->spr.srg_obss_pd_min_offset; |
| 2043 | params.he_spr_srg_obss_pd_max_offset = |
| 2044 | hapd->iface->conf->spr.srg_obss_pd_max_offset; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2045 | os_memcpy(params.he_spr_bss_color_bitmap, |
| 2046 | hapd->iface->conf->spr.srg_bss_color_bitmap, 8); |
| 2047 | os_memcpy(params.he_spr_partial_bssid_bitmap, |
| 2048 | hapd->iface->conf->spr.srg_partial_bssid_bitmap, 8); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2049 | params.he_bss_color_disabled = |
| 2050 | hapd->iface->conf->he_op.he_bss_color_disabled; |
| 2051 | params.he_bss_color_partial = |
| 2052 | hapd->iface->conf->he_op.he_bss_color_partial; |
| 2053 | params.he_bss_color = hapd->iface->conf->he_op.he_bss_color; |
| 2054 | params.twt_responder = hostapd_get_he_twt_responder(hapd, |
| 2055 | IEEE80211_MODE_AP); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2056 | params.unsol_bcast_probe_resp_tmpl = |
| 2057 | hostapd_unsol_bcast_probe_resp(hapd, ¶ms); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2058 | #endif /* CONFIG_IEEE80211AX */ |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2059 | hapd->reenable_beacon = 0; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2060 | #ifdef CONFIG_SAE |
| 2061 | params.sae_pwe = hapd->conf->sae_pwe; |
| 2062 | #endif /* CONFIG_SAE */ |
| 2063 | |
| 2064 | #ifdef CONFIG_FILS |
| 2065 | params.fd_frame_tmpl = hostapd_fils_discovery(hapd, ¶ms); |
| 2066 | #endif /* CONFIG_FILS */ |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2067 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2068 | if (cmode && |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2069 | hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2070 | iconf->channel, iconf->enable_edmg, |
| 2071 | iconf->edmg_channel, iconf->ieee80211n, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2072 | iconf->ieee80211ac, iconf->ieee80211ax, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2073 | iconf->ieee80211be, |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2074 | iconf->secondary_channel, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2075 | hostapd_get_oper_chwidth(iconf), |
| 2076 | hostapd_get_oper_centr_freq_seg0_idx(iconf), |
| 2077 | hostapd_get_oper_centr_freq_seg1_idx(iconf), |
| 2078 | cmode->vht_capab, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2079 | &cmode->he_capab[IEEE80211_MODE_AP], |
| 2080 | &cmode->eht_capab[IEEE80211_MODE_AP]) == 0) |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2081 | params.freq = &freq; |
| 2082 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2083 | res = hostapd_drv_set_ap(hapd, ¶ms); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2084 | hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2085 | if (res) |
| 2086 | wpa_printf(MSG_ERROR, "Failed to set beacon parameters"); |
| 2087 | else |
| 2088 | ret = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2089 | fail: |
| 2090 | ieee802_11_free_ap_params(¶ms); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2091 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2095 | int ieee802_11_set_beacon(struct hostapd_data *hapd) |
| 2096 | { |
| 2097 | struct hostapd_iface *iface = hapd->iface; |
| 2098 | int ret; |
| 2099 | size_t i, j; |
| 2100 | bool is_6g; |
| 2101 | |
| 2102 | ret = __ieee802_11_set_beacon(hapd); |
| 2103 | if (ret != 0) |
| 2104 | return ret; |
| 2105 | |
| 2106 | if (!iface->interfaces || iface->interfaces->count <= 1) |
| 2107 | return 0; |
| 2108 | |
| 2109 | /* Update Beacon frames in case of 6 GHz colocation */ |
| 2110 | is_6g = is_6ghz_op_class(iface->conf->op_class); |
| 2111 | for (j = 0; j < iface->interfaces->count; j++) { |
| 2112 | struct hostapd_iface *colocated; |
| 2113 | |
| 2114 | colocated = iface->interfaces->iface[j]; |
| 2115 | if (colocated == iface || !colocated || !colocated->conf) |
| 2116 | continue; |
| 2117 | |
| 2118 | if (is_6g == is_6ghz_op_class(colocated->conf->op_class)) |
| 2119 | continue; |
| 2120 | |
| 2121 | for (i = 0; i < colocated->num_bss; i++) { |
| 2122 | if (colocated->bss[i] && colocated->bss[i]->started) |
| 2123 | __ieee802_11_set_beacon(colocated->bss[i]); |
| 2124 | } |
| 2125 | } |
| 2126 | |
| 2127 | return 0; |
| 2128 | } |
| 2129 | |
| 2130 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2131 | int ieee802_11_set_beacons(struct hostapd_iface *iface) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2132 | { |
| 2133 | size_t i; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2134 | int ret = 0; |
| 2135 | |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 2136 | for (i = 0; i < iface->num_bss; i++) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2137 | if (iface->bss[i]->started && |
| 2138 | ieee802_11_set_beacon(iface->bss[i]) < 0) |
| 2139 | ret = -1; |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 2140 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2141 | |
| 2142 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2143 | } |
| 2144 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2145 | |
| 2146 | /* only update beacons if started */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2147 | int ieee802_11_update_beacons(struct hostapd_iface *iface) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2148 | { |
| 2149 | size_t i; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2150 | int ret = 0; |
| 2151 | |
| 2152 | for (i = 0; i < iface->num_bss; i++) { |
| 2153 | if (iface->bss[i]->beacon_set_done && iface->bss[i]->started && |
| 2154 | ieee802_11_set_beacon(iface->bss[i]) < 0) |
| 2155 | ret = -1; |
| 2156 | } |
| 2157 | |
| 2158 | return ret; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2159 | } |
| 2160 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2161 | #endif /* CONFIG_NATIVE_WINDOWS */ |