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 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 189 | static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing, |
| 190 | struct hostapd_channel_data *start, |
| 191 | struct hostapd_channel_data *prev) |
| 192 | { |
| 193 | if (end - pos < 3) |
| 194 | return pos; |
| 195 | |
| 196 | /* first channel number */ |
| 197 | *pos++ = start->chan; |
| 198 | /* number of channels */ |
| 199 | *pos++ = (prev->chan - start->chan) / chan_spacing + 1; |
| 200 | /* maximum transmit power level */ |
| 201 | *pos++ = start->max_tx_power; |
| 202 | |
| 203 | return pos; |
| 204 | } |
| 205 | |
| 206 | |
| 207 | static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid, |
| 208 | int max_len) |
| 209 | { |
| 210 | u8 *pos = eid; |
| 211 | u8 *end = eid + max_len; |
| 212 | int i; |
| 213 | struct hostapd_hw_modes *mode; |
| 214 | struct hostapd_channel_data *start, *prev; |
| 215 | int chan_spacing = 1; |
| 216 | |
| 217 | if (!hapd->iconf->ieee80211d || max_len < 6 || |
| 218 | hapd->iface->current_mode == NULL) |
| 219 | return eid; |
| 220 | |
| 221 | *pos++ = WLAN_EID_COUNTRY; |
| 222 | pos++; /* length will be set later */ |
| 223 | os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */ |
| 224 | pos += 3; |
| 225 | |
| 226 | mode = hapd->iface->current_mode; |
| 227 | if (mode->mode == HOSTAPD_MODE_IEEE80211A) |
| 228 | chan_spacing = 4; |
| 229 | |
| 230 | start = prev = NULL; |
| 231 | for (i = 0; i < mode->num_channels; i++) { |
| 232 | struct hostapd_channel_data *chan = &mode->channels[i]; |
| 233 | if (chan->flag & HOSTAPD_CHAN_DISABLED) |
| 234 | continue; |
| 235 | if (start && prev && |
| 236 | prev->chan + chan_spacing == chan->chan && |
| 237 | start->max_tx_power == chan->max_tx_power) { |
| 238 | prev = chan; |
| 239 | continue; /* can use same entry */ |
| 240 | } |
| 241 | |
Dmitry Shmidt | 09f57ba | 2014-06-10 16:07:13 -0700 | [diff] [blame] | 242 | if (start && prev) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 243 | pos = hostapd_eid_country_add(pos, end, chan_spacing, |
| 244 | start, prev); |
| 245 | start = NULL; |
| 246 | } |
| 247 | |
| 248 | /* Start new group */ |
| 249 | start = prev = chan; |
| 250 | } |
| 251 | |
| 252 | if (start) { |
| 253 | pos = hostapd_eid_country_add(pos, end, chan_spacing, |
| 254 | start, prev); |
| 255 | } |
| 256 | |
| 257 | if ((pos - eid) & 1) { |
| 258 | if (end - pos < 1) |
| 259 | return eid; |
| 260 | *pos++ = 0; /* pad for 16-bit alignment */ |
| 261 | } |
| 262 | |
| 263 | eid[1] = (pos - eid) - 2; |
| 264 | |
| 265 | return pos; |
| 266 | } |
| 267 | |
| 268 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 269 | static const u8 * hostapd_wpa_ie(struct hostapd_data *hapd, u8 eid) |
| 270 | { |
| 271 | const u8 *ies; |
| 272 | size_t ies_len; |
| 273 | |
| 274 | ies = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ies_len); |
| 275 | if (!ies) |
| 276 | return NULL; |
| 277 | |
| 278 | return get_ie(ies, ies_len, eid); |
| 279 | } |
| 280 | |
| 281 | |
| 282 | static const u8 * hostapd_vendor_wpa_ie(struct hostapd_data *hapd, |
| 283 | u32 vendor_type) |
| 284 | { |
| 285 | const u8 *ies; |
| 286 | size_t ies_len; |
| 287 | |
| 288 | ies = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ies_len); |
| 289 | if (!ies) |
| 290 | return NULL; |
| 291 | |
| 292 | return get_vendor_ie(ies, ies_len, vendor_type); |
| 293 | } |
| 294 | |
| 295 | |
| 296 | 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] | 297 | { |
| 298 | const u8 *ie; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 299 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 300 | ie = hostapd_wpa_ie(hapd, WLAN_EID_RSN); |
| 301 | if (!ie || 2U + ie[1] > len) |
| 302 | return pos; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 303 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 304 | os_memcpy(pos, ie, 2 + ie[1]); |
| 305 | return pos + 2 + ie[1]; |
| 306 | } |
| 307 | |
| 308 | |
| 309 | static u8 * hostapd_get_mde(struct hostapd_data *hapd, u8 *pos, size_t len) |
| 310 | { |
| 311 | const u8 *ie; |
| 312 | |
| 313 | ie = hostapd_wpa_ie(hapd, WLAN_EID_MOBILITY_DOMAIN); |
| 314 | if (!ie || 2U + ie[1] > len) |
| 315 | return pos; |
| 316 | |
| 317 | os_memcpy(pos, ie, 2 + ie[1]); |
| 318 | return pos + 2 + ie[1]; |
| 319 | } |
| 320 | |
| 321 | |
| 322 | static u8 * hostapd_get_rsnxe(struct hostapd_data *hapd, u8 *pos, size_t len) |
| 323 | { |
| 324 | const u8 *ie; |
| 325 | |
| 326 | #ifdef CONFIG_TESTING_OPTIONS |
| 327 | if (hapd->conf->no_beacon_rsnxe) { |
| 328 | wpa_printf(MSG_INFO, "TESTING: Do not add RSNXE into Beacon"); |
| 329 | return pos; |
| 330 | } |
| 331 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 332 | ie = hostapd_wpa_ie(hapd, WLAN_EID_RSNX); |
| 333 | if (!ie || 2U + ie[1] > len) |
| 334 | return pos; |
| 335 | |
| 336 | os_memcpy(pos, ie, 2 + ie[1]); |
| 337 | return pos + 2 + ie[1]; |
| 338 | } |
| 339 | |
| 340 | |
| 341 | static u8 * hostapd_get_wpa_ie(struct hostapd_data *hapd, u8 *pos, size_t len) |
| 342 | { |
| 343 | const u8 *ie; |
| 344 | |
| 345 | ie = hostapd_vendor_wpa_ie(hapd, WPA_IE_VENDOR_TYPE); |
| 346 | if (!ie || 2U + ie[1] > len) |
| 347 | return pos; |
| 348 | |
| 349 | os_memcpy(pos, ie, 2 + ie[1]); |
| 350 | return pos + 2 + ie[1]; |
| 351 | } |
| 352 | |
| 353 | |
| 354 | static u8 * hostapd_get_osen_ie(struct hostapd_data *hapd, u8 *pos, size_t len) |
| 355 | { |
| 356 | const u8 *ie; |
| 357 | |
| 358 | ie = hostapd_vendor_wpa_ie(hapd, OSEN_IE_VENDOR_TYPE); |
| 359 | if (!ie || 2U + ie[1] > len) |
| 360 | return pos; |
| 361 | |
| 362 | os_memcpy(pos, ie, 2 + ie[1]); |
| 363 | return pos + 2 + ie[1]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 367 | static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid) |
| 368 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 369 | #ifdef CONFIG_TESTING_OPTIONS |
| 370 | if (hapd->iface->cs_oper_class && hapd->iconf->ecsa_ie_only) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 371 | return eid; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 372 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 373 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 374 | if (!hapd->cs_freq_params.channel) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 375 | return eid; |
| 376 | |
| 377 | *eid++ = WLAN_EID_CHANNEL_SWITCH; |
| 378 | *eid++ = 3; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 379 | *eid++ = hapd->cs_block_tx; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 380 | *eid++ = hapd->cs_freq_params.channel; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 381 | *eid++ = hapd->cs_count; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 382 | |
| 383 | return eid; |
| 384 | } |
| 385 | |
| 386 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 387 | static u8 * hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 388 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 389 | if (!hapd->cs_freq_params.channel || !hapd->iface->cs_oper_class) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 390 | return eid; |
| 391 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 392 | *eid++ = WLAN_EID_EXT_CHANSWITCH_ANN; |
| 393 | *eid++ = 4; |
| 394 | *eid++ = hapd->cs_block_tx; |
| 395 | *eid++ = hapd->iface->cs_oper_class; |
| 396 | *eid++ = hapd->cs_freq_params.channel; |
| 397 | *eid++ = hapd->cs_count; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 398 | |
| 399 | return eid; |
| 400 | } |
| 401 | |
| 402 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 403 | 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] | 404 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 405 | u8 op_class, channel; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 406 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 407 | if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) || |
| 408 | !hapd->iface->freq) |
| 409 | return eid; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 410 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 411 | if (ieee80211_freq_to_channel_ext(hapd->iface->freq, |
| 412 | hapd->iconf->secondary_channel, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 413 | hostapd_get_oper_chwidth(hapd->iconf), |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 414 | &op_class, &channel) == |
| 415 | NUM_HOSTAPD_MODES) |
| 416 | return eid; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 417 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 418 | *eid++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES; |
| 419 | *eid++ = 2; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 420 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 421 | /* Current Operating Class */ |
| 422 | *eid++ = op_class; |
| 423 | |
| 424 | /* TODO: Advertise all the supported operating classes */ |
| 425 | *eid++ = 0; |
| 426 | |
| 427 | return eid; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 431 | static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 432 | const struct ieee80211_mgmt *req, |
| 433 | int is_p2p, size_t *resp_len) |
| 434 | { |
| 435 | struct ieee80211_mgmt *resp; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 436 | u8 *pos, *epos, *csa_pos; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 437 | size_t buflen; |
| 438 | |
| 439 | #define MAX_PROBERESP_LEN 768 |
| 440 | buflen = MAX_PROBERESP_LEN; |
| 441 | #ifdef CONFIG_WPS |
| 442 | if (hapd->wps_probe_resp_ie) |
| 443 | buflen += wpabuf_len(hapd->wps_probe_resp_ie); |
| 444 | #endif /* CONFIG_WPS */ |
| 445 | #ifdef CONFIG_P2P |
| 446 | if (hapd->p2p_probe_resp_ie) |
| 447 | buflen += wpabuf_len(hapd->p2p_probe_resp_ie); |
| 448 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 449 | #ifdef CONFIG_FST |
| 450 | if (hapd->iface->fst_ies) |
| 451 | buflen += wpabuf_len(hapd->iface->fst_ies); |
| 452 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 453 | if (hapd->conf->vendor_elements) |
| 454 | buflen += wpabuf_len(hapd->conf->vendor_elements); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 455 | if (hapd->conf->vendor_vht) { |
| 456 | buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) + |
| 457 | 2 + sizeof(struct ieee80211_vht_operation); |
| 458 | } |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 459 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 460 | #ifdef CONFIG_IEEE80211AX |
| 461 | if (hapd->iconf->ieee80211ax) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 462 | buflen += 3 + sizeof(struct ieee80211_he_capabilities) + |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 463 | 3 + sizeof(struct ieee80211_he_operation) + |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 464 | 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) + |
| 465 | 3 + sizeof(struct ieee80211_spatial_reuse); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 466 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 467 | #endif /* CONFIG_IEEE80211AX */ |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 468 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 469 | buflen += hostapd_mbo_ie_len(hapd); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 470 | buflen += hostapd_eid_owe_trans_len(hapd); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 471 | buflen += hostapd_eid_dpp_cc_len(hapd); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 472 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 473 | resp = os_zalloc(buflen); |
| 474 | if (resp == NULL) |
| 475 | return NULL; |
| 476 | |
| 477 | epos = ((u8 *) resp) + MAX_PROBERESP_LEN; |
| 478 | |
| 479 | resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 480 | WLAN_FC_STYPE_PROBE_RESP); |
| 481 | if (req) |
| 482 | os_memcpy(resp->da, req->sa, ETH_ALEN); |
| 483 | os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN); |
| 484 | |
| 485 | os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN); |
| 486 | resp->u.probe_resp.beacon_int = |
| 487 | host_to_le16(hapd->iconf->beacon_int); |
| 488 | |
| 489 | /* hardware or low-level driver will setup seq_ctrl and timestamp */ |
| 490 | resp->u.probe_resp.capab_info = |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 491 | host_to_le16(hostapd_own_capab_info(hapd)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 492 | |
| 493 | pos = resp->u.probe_resp.variable; |
| 494 | *pos++ = WLAN_EID_SSID; |
| 495 | *pos++ = hapd->conf->ssid.ssid_len; |
| 496 | os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len); |
| 497 | pos += hapd->conf->ssid.ssid_len; |
| 498 | |
| 499 | /* Supported rates */ |
| 500 | pos = hostapd_eid_supp_rates(hapd, pos); |
| 501 | |
| 502 | /* DS Params */ |
| 503 | pos = hostapd_eid_ds_params(hapd, pos); |
| 504 | |
| 505 | pos = hostapd_eid_country(hapd, pos, epos - pos); |
| 506 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 507 | /* Power Constraint element */ |
| 508 | pos = hostapd_eid_pwr_constraint(hapd, pos); |
| 509 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 510 | /* CSA IE */ |
| 511 | csa_pos = hostapd_eid_csa(hapd, pos); |
| 512 | if (csa_pos != pos) |
| 513 | hapd->cs_c_off_proberesp = csa_pos - (u8 *) resp - 1; |
| 514 | pos = csa_pos; |
| 515 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 516 | /* ERP Information element */ |
| 517 | pos = hostapd_eid_erp_info(hapd, pos); |
| 518 | |
| 519 | /* Extended supported rates */ |
| 520 | pos = hostapd_eid_ext_supp_rates(hapd, pos); |
| 521 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 522 | pos = hostapd_get_rsne(hapd, pos, epos - pos); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 523 | pos = hostapd_eid_bss_load(hapd, pos, epos - pos); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 524 | pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 525 | pos = hostapd_get_mde(hapd, pos, epos - pos); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 526 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 527 | /* eCSA IE */ |
| 528 | csa_pos = hostapd_eid_ecsa(hapd, pos); |
| 529 | if (csa_pos != pos) |
| 530 | hapd->cs_c_off_ecsa_proberesp = csa_pos - (u8 *) resp - 1; |
| 531 | pos = csa_pos; |
| 532 | |
| 533 | pos = hostapd_eid_supported_op_classes(hapd, pos); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 534 | pos = hostapd_eid_ht_capabilities(hapd, pos); |
| 535 | pos = hostapd_eid_ht_operation(hapd, pos); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 536 | |
| 537 | pos = hostapd_eid_ext_capab(hapd, pos); |
| 538 | |
| 539 | pos = hostapd_eid_time_adv(hapd, pos); |
| 540 | pos = hostapd_eid_time_zone(hapd, pos); |
| 541 | |
| 542 | pos = hostapd_eid_interworking(hapd, pos); |
| 543 | pos = hostapd_eid_adv_proto(hapd, pos); |
| 544 | pos = hostapd_eid_roaming_consortium(hapd, pos); |
| 545 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 546 | #ifdef CONFIG_FST |
| 547 | if (hapd->iface->fst_ies) { |
| 548 | os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies), |
| 549 | wpabuf_len(hapd->iface->fst_ies)); |
| 550 | pos += wpabuf_len(hapd->iface->fst_ies); |
| 551 | } |
| 552 | #endif /* CONFIG_FST */ |
| 553 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 554 | #ifdef CONFIG_IEEE80211AC |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 555 | if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac && |
| 556 | !is_6ghz_op_class(hapd->iconf->op_class)) { |
Dmitry Shmidt | 7d17530 | 2016-09-06 13:11:34 -0700 | [diff] [blame] | 557 | pos = hostapd_eid_vht_capabilities(hapd, pos, 0); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 558 | pos = hostapd_eid_vht_operation(hapd, pos); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 559 | pos = hostapd_eid_txpower_envelope(hapd, pos); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 560 | pos = hostapd_eid_wb_chsw_wrapper(hapd, pos); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 561 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 562 | #endif /* CONFIG_IEEE80211AC */ |
| 563 | |
| 564 | pos = hostapd_eid_fils_indic(hapd, pos, 0); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 565 | pos = hostapd_get_rsnxe(hapd, pos, epos - pos); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 566 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 567 | #ifdef CONFIG_IEEE80211AX |
| 568 | if (hapd->iconf->ieee80211ax) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 569 | pos = hostapd_eid_he_capab(hapd, pos, IEEE80211_MODE_AP); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 570 | pos = hostapd_eid_he_operation(hapd, pos); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 571 | pos = hostapd_eid_spatial_reuse(hapd, pos); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 572 | pos = hostapd_eid_he_mu_edca_parameter_set(hapd, pos); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 573 | } |
| 574 | #endif /* CONFIG_IEEE80211AX */ |
| 575 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 576 | #ifdef CONFIG_IEEE80211AC |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 577 | if (hapd->conf->vendor_vht) |
| 578 | pos = hostapd_eid_vendor_vht(hapd, pos); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 579 | #endif /* CONFIG_IEEE80211AC */ |
| 580 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 581 | /* WPA / OSEN */ |
| 582 | pos = hostapd_get_wpa_ie(hapd, pos, epos - pos); |
| 583 | pos = hostapd_get_osen_ie(hapd, pos, epos - pos); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 584 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 585 | /* Wi-Fi Alliance WMM */ |
| 586 | pos = hostapd_eid_wmm(hapd, pos); |
| 587 | |
| 588 | #ifdef CONFIG_WPS |
| 589 | if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) { |
| 590 | os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie), |
| 591 | wpabuf_len(hapd->wps_probe_resp_ie)); |
| 592 | pos += wpabuf_len(hapd->wps_probe_resp_ie); |
| 593 | } |
| 594 | #endif /* CONFIG_WPS */ |
| 595 | |
| 596 | #ifdef CONFIG_P2P |
| 597 | if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p && |
| 598 | hapd->p2p_probe_resp_ie) { |
| 599 | os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie), |
| 600 | wpabuf_len(hapd->p2p_probe_resp_ie)); |
| 601 | pos += wpabuf_len(hapd->p2p_probe_resp_ie); |
| 602 | } |
| 603 | #endif /* CONFIG_P2P */ |
| 604 | #ifdef CONFIG_P2P_MANAGER |
| 605 | if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) == |
| 606 | P2P_MANAGE) |
| 607 | pos = hostapd_eid_p2p_manage(hapd, pos); |
| 608 | #endif /* CONFIG_P2P_MANAGER */ |
| 609 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 610 | #ifdef CONFIG_HS20 |
| 611 | pos = hostapd_eid_hs20_indication(hapd, pos); |
| 612 | #endif /* CONFIG_HS20 */ |
| 613 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 614 | pos = hostapd_eid_mbo(hapd, pos, (u8 *) resp + buflen - pos); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 615 | pos = hostapd_eid_owe_trans(hapd, pos, (u8 *) resp + buflen - pos); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 616 | pos = hostapd_eid_dpp_cc(hapd, pos, (u8 *) resp + buflen - pos); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 617 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 618 | if (hapd->conf->vendor_elements) { |
| 619 | os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements), |
| 620 | wpabuf_len(hapd->conf->vendor_elements)); |
| 621 | pos += wpabuf_len(hapd->conf->vendor_elements); |
| 622 | } |
| 623 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 624 | *resp_len = pos - (u8 *) resp; |
| 625 | return (u8 *) resp; |
| 626 | } |
| 627 | |
| 628 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 629 | enum ssid_match_result { |
| 630 | NO_SSID_MATCH, |
| 631 | EXACT_SSID_MATCH, |
| 632 | WILDCARD_SSID_MATCH |
| 633 | }; |
| 634 | |
| 635 | static enum ssid_match_result ssid_match(struct hostapd_data *hapd, |
| 636 | const u8 *ssid, size_t ssid_len, |
| 637 | const u8 *ssid_list, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 638 | size_t ssid_list_len, |
| 639 | const u8 *short_ssid_list, |
| 640 | size_t short_ssid_list_len) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 641 | { |
| 642 | const u8 *pos, *end; |
| 643 | int wildcard = 0; |
| 644 | |
| 645 | if (ssid_len == 0) |
| 646 | wildcard = 1; |
| 647 | if (ssid_len == hapd->conf->ssid.ssid_len && |
| 648 | os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0) |
| 649 | return EXACT_SSID_MATCH; |
| 650 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 651 | if (ssid_list) { |
| 652 | pos = ssid_list; |
| 653 | end = ssid_list + ssid_list_len; |
| 654 | while (end - pos >= 2) { |
| 655 | if (2 + pos[1] > end - pos) |
| 656 | break; |
| 657 | if (pos[1] == 0) |
| 658 | wildcard = 1; |
| 659 | if (pos[1] == hapd->conf->ssid.ssid_len && |
| 660 | os_memcmp(pos + 2, hapd->conf->ssid.ssid, |
| 661 | pos[1]) == 0) |
| 662 | return EXACT_SSID_MATCH; |
| 663 | pos += 2 + pos[1]; |
| 664 | } |
| 665 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 666 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 667 | if (short_ssid_list) { |
| 668 | pos = short_ssid_list; |
| 669 | end = short_ssid_list + short_ssid_list_len; |
| 670 | while (end - pos >= 4) { |
| 671 | if (hapd->conf->ssid.short_ssid == WPA_GET_LE32(pos)) |
| 672 | return EXACT_SSID_MATCH; |
| 673 | pos += 4; |
| 674 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH; |
| 678 | } |
| 679 | |
| 680 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 681 | void sta_track_expire(struct hostapd_iface *iface, int force) |
| 682 | { |
| 683 | struct os_reltime now; |
| 684 | struct hostapd_sta_info *info; |
| 685 | |
| 686 | if (!iface->num_sta_seen) |
| 687 | return; |
| 688 | |
| 689 | os_get_reltime(&now); |
| 690 | while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info, |
| 691 | list))) { |
| 692 | if (!force && |
| 693 | !os_reltime_expired(&now, &info->last_seen, |
| 694 | iface->conf->track_sta_max_age)) |
| 695 | break; |
| 696 | force = 0; |
| 697 | |
| 698 | wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for " |
| 699 | MACSTR, iface->bss[0]->conf->iface, |
| 700 | MAC2STR(info->addr)); |
| 701 | dl_list_del(&info->list); |
| 702 | iface->num_sta_seen--; |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 703 | sta_track_del(info); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 704 | } |
| 705 | } |
| 706 | |
| 707 | |
| 708 | static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface, |
| 709 | const u8 *addr) |
| 710 | { |
| 711 | struct hostapd_sta_info *info; |
| 712 | |
| 713 | dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list) |
| 714 | if (os_memcmp(addr, info->addr, ETH_ALEN) == 0) |
| 715 | return info; |
| 716 | |
| 717 | return NULL; |
| 718 | } |
| 719 | |
| 720 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 721 | 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] | 722 | { |
| 723 | struct hostapd_sta_info *info; |
| 724 | |
| 725 | info = sta_track_get(iface, addr); |
| 726 | if (info) { |
| 727 | /* Move the most recent entry to the end of the list */ |
| 728 | dl_list_del(&info->list); |
| 729 | dl_list_add_tail(&iface->sta_seen, &info->list); |
| 730 | os_get_reltime(&info->last_seen); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 731 | info->ssi_signal = ssi_signal; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 732 | return; |
| 733 | } |
| 734 | |
| 735 | /* Add a new entry */ |
| 736 | info = os_zalloc(sizeof(*info)); |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 737 | if (info == NULL) |
| 738 | return; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 739 | os_memcpy(info->addr, addr, ETH_ALEN); |
| 740 | os_get_reltime(&info->last_seen); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 741 | info->ssi_signal = ssi_signal; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 742 | |
| 743 | if (iface->num_sta_seen >= iface->conf->track_sta_max_num) { |
| 744 | /* Expire oldest entry to make room for a new one */ |
| 745 | sta_track_expire(iface, 1); |
| 746 | } |
| 747 | |
| 748 | wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for " |
| 749 | MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr)); |
| 750 | dl_list_add_tail(&iface->sta_seen, &info->list); |
| 751 | iface->num_sta_seen++; |
| 752 | } |
| 753 | |
| 754 | |
| 755 | struct hostapd_data * |
| 756 | sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr, |
| 757 | const char *ifname) |
| 758 | { |
| 759 | struct hapd_interfaces *interfaces = iface->interfaces; |
| 760 | size_t i, j; |
| 761 | |
| 762 | for (i = 0; i < interfaces->count; i++) { |
| 763 | struct hostapd_data *hapd = NULL; |
| 764 | |
| 765 | iface = interfaces->iface[i]; |
| 766 | for (j = 0; j < iface->num_bss; j++) { |
| 767 | hapd = iface->bss[j]; |
| 768 | if (os_strcmp(ifname, hapd->conf->iface) == 0) |
| 769 | break; |
| 770 | hapd = NULL; |
| 771 | } |
| 772 | |
| 773 | if (hapd && sta_track_get(iface, addr)) |
| 774 | return hapd; |
| 775 | } |
| 776 | |
| 777 | return NULL; |
| 778 | } |
| 779 | |
| 780 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 781 | #ifdef CONFIG_TAXONOMY |
| 782 | void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr, |
| 783 | struct wpabuf **probe_ie_taxonomy) |
| 784 | { |
| 785 | struct hostapd_sta_info *info; |
| 786 | |
| 787 | info = sta_track_get(iface, addr); |
| 788 | if (!info) |
| 789 | return; |
| 790 | |
| 791 | wpabuf_free(*probe_ie_taxonomy); |
| 792 | *probe_ie_taxonomy = info->probe_ie_taxonomy; |
| 793 | info->probe_ie_taxonomy = NULL; |
| 794 | } |
| 795 | #endif /* CONFIG_TAXONOMY */ |
| 796 | |
| 797 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 798 | void handle_probe_req(struct hostapd_data *hapd, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 799 | const struct ieee80211_mgmt *mgmt, size_t len, |
| 800 | int ssi_signal) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 801 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 802 | u8 *resp; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 803 | struct ieee802_11_elems elems; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 804 | const u8 *ie; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 805 | size_t ie_len; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 806 | size_t i, resp_len; |
| 807 | int noack; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 808 | enum ssid_match_result res; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 809 | int ret; |
| 810 | u16 csa_offs[2]; |
| 811 | size_t csa_offs_len; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 812 | struct radius_sta rad_info; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 813 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 814 | if (len < IEEE80211_HDRLEN) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 815 | return; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 816 | ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 817 | if (hapd->iconf->track_sta_max_num) |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 818 | sta_track_add(hapd->iface, mgmt->sa, ssi_signal); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 819 | ie_len = len - IEEE80211_HDRLEN; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 820 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 821 | ret = hostapd_allowed_address(hapd, mgmt->sa, (const u8 *) mgmt, len, |
| 822 | &rad_info, 1); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 823 | if (ret == HOSTAPD_ACL_REJECT) { |
| 824 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, |
| 825 | "Ignore Probe Request frame from " MACSTR |
| 826 | " due to ACL reject ", MAC2STR(mgmt->sa)); |
| 827 | return; |
| 828 | } |
| 829 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 830 | for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) |
| 831 | if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 832 | mgmt->sa, mgmt->da, mgmt->bssid, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 833 | ie, ie_len, ssi_signal) > 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 834 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 835 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 836 | if (!hapd->conf->send_probe_response) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 837 | return; |
| 838 | |
| 839 | if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) { |
| 840 | wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR, |
| 841 | MAC2STR(mgmt->sa)); |
| 842 | return; |
| 843 | } |
| 844 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 845 | if ((!elems.ssid || !elems.supp_rates)) { |
| 846 | wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request " |
| 847 | "without SSID or supported rates element", |
| 848 | MAC2STR(mgmt->sa)); |
| 849 | return; |
| 850 | } |
| 851 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 852 | /* |
| 853 | * No need to reply if the Probe Request frame was sent on an adjacent |
| 854 | * channel. IEEE Std 802.11-2012 describes this as a requirement for an |
| 855 | * AP with dot11RadioMeasurementActivated set to true, but strictly |
| 856 | * speaking does not allow such ignoring of Probe Request frames if |
| 857 | * dot11RadioMeasurementActivated is false. Anyway, this can help reduce |
| 858 | * number of unnecessary Probe Response frames for cases where the STA |
| 859 | * is less likely to see them (Probe Request frame sent on a |
| 860 | * neighboring, but partially overlapping, channel). |
| 861 | */ |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 862 | if (elems.ds_params && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 863 | hapd->iface->current_mode && |
| 864 | (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G || |
| 865 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) && |
| 866 | hapd->iconf->channel != elems.ds_params[0]) { |
| 867 | wpa_printf(MSG_DEBUG, |
| 868 | "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u", |
| 869 | hapd->iconf->channel, elems.ds_params[0]); |
| 870 | return; |
| 871 | } |
| 872 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 873 | #ifdef CONFIG_P2P |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 874 | if (hapd->p2p && hapd->p2p_group && elems.wps_ie) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 875 | struct wpabuf *wps; |
| 876 | wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA); |
| 877 | if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) { |
| 878 | wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request " |
| 879 | "due to mismatch with Requested Device " |
| 880 | "Type"); |
| 881 | wpabuf_free(wps); |
| 882 | return; |
| 883 | } |
| 884 | wpabuf_free(wps); |
| 885 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 886 | |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 887 | if (hapd->p2p && hapd->p2p_group && elems.p2p) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 888 | struct wpabuf *p2p; |
| 889 | p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE); |
| 890 | if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) { |
| 891 | wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request " |
| 892 | "due to mismatch with Device ID"); |
| 893 | wpabuf_free(p2p); |
| 894 | return; |
| 895 | } |
| 896 | wpabuf_free(p2p); |
| 897 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 898 | #endif /* CONFIG_P2P */ |
| 899 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 900 | if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 901 | elems.ssid_list_len == 0 && elems.short_ssid_list_len == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 902 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for " |
| 903 | "broadcast SSID ignored", MAC2STR(mgmt->sa)); |
| 904 | return; |
| 905 | } |
| 906 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 907 | #ifdef CONFIG_P2P |
| 908 | if ((hapd->conf->p2p & P2P_GROUP_OWNER) && |
| 909 | elems.ssid_len == P2P_WILDCARD_SSID_LEN && |
| 910 | os_memcmp(elems.ssid, P2P_WILDCARD_SSID, |
| 911 | P2P_WILDCARD_SSID_LEN) == 0) { |
| 912 | /* Process P2P Wildcard SSID like Wildcard SSID */ |
| 913 | elems.ssid_len = 0; |
| 914 | } |
| 915 | #endif /* CONFIG_P2P */ |
| 916 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 917 | #ifdef CONFIG_TAXONOMY |
| 918 | { |
| 919 | struct sta_info *sta; |
| 920 | struct hostapd_sta_info *info; |
| 921 | |
| 922 | if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) { |
| 923 | taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len); |
| 924 | } else if ((info = sta_track_get(hapd->iface, |
| 925 | mgmt->sa)) != NULL) { |
| 926 | taxonomy_hostapd_sta_info_probe_req(hapd, info, |
| 927 | ie, ie_len); |
| 928 | } |
| 929 | } |
| 930 | #endif /* CONFIG_TAXONOMY */ |
| 931 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 932 | res = ssid_match(hapd, elems.ssid, elems.ssid_len, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 933 | elems.ssid_list, elems.ssid_list_len, |
| 934 | elems.short_ssid_list, elems.short_ssid_list_len); |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 935 | if (res == NO_SSID_MATCH) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 936 | if (!(mgmt->da[0] & 0x01)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 937 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 938 | " for foreign SSID '%s' (DA " MACSTR ")%s", |
Dmitry Shmidt | 3c47937 | 2014-02-04 10:50:36 -0800 | [diff] [blame] | 939 | MAC2STR(mgmt->sa), |
| 940 | wpa_ssid_txt(elems.ssid, elems.ssid_len), |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 941 | MAC2STR(mgmt->da), |
| 942 | elems.ssid_list ? " (SSID list)" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 943 | } |
| 944 | return; |
| 945 | } |
| 946 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 947 | if (hapd->conf->ignore_broadcast_ssid && res == WILDCARD_SSID_MATCH) { |
| 948 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for " |
| 949 | "broadcast SSID ignored", MAC2STR(mgmt->sa)); |
| 950 | return; |
| 951 | } |
| 952 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 953 | #ifdef CONFIG_INTERWORKING |
Dmitry Shmidt | f9bdef9 | 2014-04-25 10:46:36 -0700 | [diff] [blame] | 954 | if (hapd->conf->interworking && |
| 955 | elems.interworking && elems.interworking_len >= 1) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 956 | u8 ant = elems.interworking[0] & 0x0f; |
| 957 | if (ant != INTERWORKING_ANT_WILDCARD && |
| 958 | ant != hapd->conf->access_network_type) { |
| 959 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR |
| 960 | " for mismatching ANT %u ignored", |
| 961 | MAC2STR(mgmt->sa), ant); |
| 962 | return; |
| 963 | } |
| 964 | } |
| 965 | |
Dmitry Shmidt | f9bdef9 | 2014-04-25 10:46:36 -0700 | [diff] [blame] | 966 | if (hapd->conf->interworking && elems.interworking && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 967 | (elems.interworking_len == 7 || elems.interworking_len == 9)) { |
| 968 | const u8 *hessid; |
| 969 | if (elems.interworking_len == 7) |
| 970 | hessid = elems.interworking + 1; |
| 971 | else |
| 972 | hessid = elems.interworking + 1 + 2; |
| 973 | if (!is_broadcast_ether_addr(hessid) && |
| 974 | os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) { |
| 975 | wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR |
| 976 | " for mismatching HESSID " MACSTR |
| 977 | " ignored", |
| 978 | MAC2STR(mgmt->sa), MAC2STR(hessid)); |
| 979 | return; |
| 980 | } |
| 981 | } |
| 982 | #endif /* CONFIG_INTERWORKING */ |
| 983 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 984 | #ifdef CONFIG_P2P |
| 985 | if ((hapd->conf->p2p & P2P_GROUP_OWNER) && |
| 986 | supp_rates_11b_only(&elems)) { |
| 987 | /* Indicates support for 11b rates only */ |
| 988 | wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from " |
| 989 | MACSTR " with only 802.11b rates", |
| 990 | MAC2STR(mgmt->sa)); |
| 991 | return; |
| 992 | } |
| 993 | #endif /* CONFIG_P2P */ |
| 994 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 995 | /* TODO: verify that supp_rates contains at least one matching rate |
| 996 | * with AP configuration */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 997 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 998 | if (hapd->conf->no_probe_resp_if_seen_on && |
| 999 | is_multicast_ether_addr(mgmt->da) && |
| 1000 | is_multicast_ether_addr(mgmt->bssid) && |
| 1001 | sta_track_seen_on(hapd->iface, mgmt->sa, |
| 1002 | hapd->conf->no_probe_resp_if_seen_on)) { |
| 1003 | wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR |
| 1004 | " since STA has been seen on %s", |
| 1005 | hapd->conf->iface, MAC2STR(mgmt->sa), |
| 1006 | hapd->conf->no_probe_resp_if_seen_on); |
| 1007 | return; |
| 1008 | } |
| 1009 | |
| 1010 | if (hapd->conf->no_probe_resp_if_max_sta && |
| 1011 | is_multicast_ether_addr(mgmt->da) && |
| 1012 | is_multicast_ether_addr(mgmt->bssid) && |
| 1013 | hapd->num_sta >= hapd->conf->max_num_sta && |
| 1014 | !ap_get_sta(hapd, mgmt->sa)) { |
| 1015 | wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR |
| 1016 | " since no room for additional STA", |
| 1017 | hapd->conf->iface, MAC2STR(mgmt->sa)); |
| 1018 | return; |
| 1019 | } |
| 1020 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1021 | #ifdef CONFIG_TESTING_OPTIONS |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 1022 | if (hapd->iconf->ignore_probe_probability > 0.0 && |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1023 | drand48() < hapd->iconf->ignore_probe_probability) { |
| 1024 | wpa_printf(MSG_INFO, |
| 1025 | "TESTING: ignoring probe request from " MACSTR, |
| 1026 | MAC2STR(mgmt->sa)); |
| 1027 | return; |
| 1028 | } |
| 1029 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 1030 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1031 | wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, RX_PROBE_REQUEST "sa=" MACSTR |
| 1032 | " signal=%d", MAC2STR(mgmt->sa), ssi_signal); |
| 1033 | |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 1034 | resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1035 | &resp_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1036 | if (resp == NULL) |
| 1037 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1038 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1039 | /* |
| 1040 | * If this is a broadcast probe request, apply no ack policy to avoid |
| 1041 | * excessive retries. |
| 1042 | */ |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1043 | noack = !!(res == WILDCARD_SSID_MATCH && |
| 1044 | is_broadcast_ether_addr(mgmt->da)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1045 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1046 | csa_offs_len = 0; |
| 1047 | if (hapd->csa_in_progress) { |
| 1048 | if (hapd->cs_c_off_proberesp) |
| 1049 | csa_offs[csa_offs_len++] = |
| 1050 | hapd->cs_c_off_proberesp; |
| 1051 | |
| 1052 | if (hapd->cs_c_off_ecsa_proberesp) |
| 1053 | csa_offs[csa_offs_len++] = |
| 1054 | hapd->cs_c_off_ecsa_proberesp; |
| 1055 | } |
| 1056 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1057 | ret = hostapd_drv_send_mlme(hapd, resp, resp_len, noack, |
| 1058 | csa_offs_len ? csa_offs : NULL, |
| 1059 | csa_offs_len, 0); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1060 | |
| 1061 | if (ret < 0) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1062 | wpa_printf(MSG_INFO, "handle_probe_req: send failed"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1063 | |
| 1064 | os_free(resp); |
| 1065 | |
| 1066 | wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s " |
| 1067 | "SSID", MAC2STR(mgmt->sa), |
| 1068 | elems.ssid_len == 0 ? "broadcast" : "our"); |
| 1069 | } |
| 1070 | |
| 1071 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1072 | static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd, |
| 1073 | size_t *resp_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1074 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1075 | /* check probe response offloading caps and print warnings */ |
| 1076 | if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD)) |
| 1077 | return NULL; |
| 1078 | |
| 1079 | #ifdef CONFIG_WPS |
| 1080 | if (hapd->conf->wps_state && hapd->wps_probe_resp_ie && |
| 1081 | (!(hapd->iface->probe_resp_offloads & |
| 1082 | (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS | |
| 1083 | WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2)))) |
| 1084 | wpa_printf(MSG_WARNING, "Device is trying to offload WPS " |
| 1085 | "Probe Response while not supporting this"); |
| 1086 | #endif /* CONFIG_WPS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1087 | |
| 1088 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1089 | if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie && |
| 1090 | !(hapd->iface->probe_resp_offloads & |
| 1091 | WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P)) |
| 1092 | wpa_printf(MSG_WARNING, "Device is trying to offload P2P " |
| 1093 | "Probe Response while not supporting this"); |
| 1094 | #endif /* CONFIG_P2P */ |
| 1095 | |
| 1096 | if (hapd->conf->interworking && |
| 1097 | !(hapd->iface->probe_resp_offloads & |
| 1098 | WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING)) |
| 1099 | wpa_printf(MSG_WARNING, "Device is trying to offload " |
| 1100 | "Interworking Probe Response while not supporting " |
| 1101 | "this"); |
| 1102 | |
| 1103 | /* Generate a Probe Response template for the non-P2P case */ |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 1104 | return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | #endif /* NEED_AP_MLME */ |
| 1108 | |
| 1109 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 1110 | void sta_track_del(struct hostapd_sta_info *info) |
| 1111 | { |
| 1112 | #ifdef CONFIG_TAXONOMY |
| 1113 | wpabuf_free(info->probe_ie_taxonomy); |
| 1114 | info->probe_ie_taxonomy = NULL; |
| 1115 | #endif /* CONFIG_TAXONOMY */ |
| 1116 | os_free(info); |
| 1117 | } |
| 1118 | |
| 1119 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1120 | int ieee802_11_build_ap_params(struct hostapd_data *hapd, |
| 1121 | struct wpa_driver_ap_params *params) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1122 | { |
| 1123 | struct ieee80211_mgmt *head = NULL; |
| 1124 | u8 *tail = NULL; |
| 1125 | size_t head_len = 0, tail_len = 0; |
| 1126 | u8 *resp = NULL; |
| 1127 | size_t resp_len = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1128 | #ifdef NEED_AP_MLME |
| 1129 | u16 capab_info; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1130 | u8 *pos, *tailpos, *tailend, *csa_pos; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1131 | |
| 1132 | #define BEACON_HEAD_BUF_SIZE 256 |
| 1133 | #define BEACON_TAIL_BUF_SIZE 512 |
| 1134 | head = os_zalloc(BEACON_HEAD_BUF_SIZE); |
| 1135 | tail_len = BEACON_TAIL_BUF_SIZE; |
| 1136 | #ifdef CONFIG_WPS |
| 1137 | if (hapd->conf->wps_state && hapd->wps_beacon_ie) |
| 1138 | tail_len += wpabuf_len(hapd->wps_beacon_ie); |
| 1139 | #endif /* CONFIG_WPS */ |
| 1140 | #ifdef CONFIG_P2P |
| 1141 | if (hapd->p2p_beacon_ie) |
| 1142 | tail_len += wpabuf_len(hapd->p2p_beacon_ie); |
| 1143 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1144 | #ifdef CONFIG_FST |
| 1145 | if (hapd->iface->fst_ies) |
| 1146 | tail_len += wpabuf_len(hapd->iface->fst_ies); |
| 1147 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1148 | if (hapd->conf->vendor_elements) |
| 1149 | tail_len += wpabuf_len(hapd->conf->vendor_elements); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1150 | |
| 1151 | #ifdef CONFIG_IEEE80211AC |
| 1152 | if (hapd->conf->vendor_vht) { |
| 1153 | tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) + |
| 1154 | 2 + sizeof(struct ieee80211_vht_operation); |
| 1155 | } |
| 1156 | #endif /* CONFIG_IEEE80211AC */ |
| 1157 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1158 | #ifdef CONFIG_IEEE80211AX |
| 1159 | if (hapd->iconf->ieee80211ax) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1160 | tail_len += 3 + sizeof(struct ieee80211_he_capabilities) + |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1161 | 3 + sizeof(struct ieee80211_he_operation) + |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1162 | 3 + sizeof(struct ieee80211_he_mu_edca_parameter_set) + |
| 1163 | 3 + sizeof(struct ieee80211_spatial_reuse); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1164 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1165 | #endif /* CONFIG_IEEE80211AX */ |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1166 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1167 | tail_len += hostapd_mbo_ie_len(hapd); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1168 | tail_len += hostapd_eid_owe_trans_len(hapd); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1169 | tail_len += hostapd_eid_dpp_cc_len(hapd); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1170 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1171 | tailpos = tail = os_malloc(tail_len); |
| 1172 | if (head == NULL || tail == NULL) { |
| 1173 | wpa_printf(MSG_ERROR, "Failed to set beacon data"); |
| 1174 | os_free(head); |
| 1175 | os_free(tail); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1176 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1177 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1178 | tailend = tail + tail_len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1179 | |
| 1180 | head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 1181 | WLAN_FC_STYPE_BEACON); |
| 1182 | head->duration = host_to_le16(0); |
| 1183 | os_memset(head->da, 0xff, ETH_ALEN); |
| 1184 | |
| 1185 | os_memcpy(head->sa, hapd->own_addr, ETH_ALEN); |
| 1186 | os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN); |
| 1187 | head->u.beacon.beacon_int = |
| 1188 | host_to_le16(hapd->iconf->beacon_int); |
| 1189 | |
| 1190 | /* hardware or low-level driver will setup seq_ctrl and timestamp */ |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 1191 | capab_info = hostapd_own_capab_info(hapd); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1192 | head->u.beacon.capab_info = host_to_le16(capab_info); |
| 1193 | pos = &head->u.beacon.variable[0]; |
| 1194 | |
| 1195 | /* SSID */ |
| 1196 | *pos++ = WLAN_EID_SSID; |
| 1197 | if (hapd->conf->ignore_broadcast_ssid == 2) { |
| 1198 | /* clear the data, but keep the correct length of the SSID */ |
| 1199 | *pos++ = hapd->conf->ssid.ssid_len; |
| 1200 | os_memset(pos, 0, hapd->conf->ssid.ssid_len); |
| 1201 | pos += hapd->conf->ssid.ssid_len; |
| 1202 | } else if (hapd->conf->ignore_broadcast_ssid) { |
| 1203 | *pos++ = 0; /* empty SSID */ |
| 1204 | } else { |
| 1205 | *pos++ = hapd->conf->ssid.ssid_len; |
| 1206 | os_memcpy(pos, hapd->conf->ssid.ssid, |
| 1207 | hapd->conf->ssid.ssid_len); |
| 1208 | pos += hapd->conf->ssid.ssid_len; |
| 1209 | } |
| 1210 | |
| 1211 | /* Supported rates */ |
| 1212 | pos = hostapd_eid_supp_rates(hapd, pos); |
| 1213 | |
| 1214 | /* DS Params */ |
| 1215 | pos = hostapd_eid_ds_params(hapd, pos); |
| 1216 | |
| 1217 | head_len = pos - (u8 *) head; |
| 1218 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1219 | tailpos = hostapd_eid_country(hapd, tailpos, tailend - tailpos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1220 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1221 | /* Power Constraint element */ |
| 1222 | tailpos = hostapd_eid_pwr_constraint(hapd, tailpos); |
| 1223 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1224 | /* CSA IE */ |
| 1225 | csa_pos = hostapd_eid_csa(hapd, tailpos); |
| 1226 | if (csa_pos != tailpos) |
| 1227 | hapd->cs_c_off_beacon = csa_pos - tail - 1; |
| 1228 | tailpos = csa_pos; |
| 1229 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1230 | /* ERP Information element */ |
| 1231 | tailpos = hostapd_eid_erp_info(hapd, tailpos); |
| 1232 | |
| 1233 | /* Extended supported rates */ |
| 1234 | tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos); |
| 1235 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1236 | tailpos = hostapd_get_rsne(hapd, tailpos, tailend - tailpos); |
| 1237 | tailpos = hostapd_eid_bss_load(hapd, tailpos, tailend - tailpos); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1238 | tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1239 | tailend - tailpos); |
| 1240 | tailpos = hostapd_get_mde(hapd, tailpos, tailend - tailpos); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1241 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1242 | /* eCSA IE */ |
| 1243 | csa_pos = hostapd_eid_ecsa(hapd, tailpos); |
| 1244 | if (csa_pos != tailpos) |
| 1245 | hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1; |
| 1246 | tailpos = csa_pos; |
| 1247 | |
| 1248 | tailpos = hostapd_eid_supported_op_classes(hapd, tailpos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1249 | tailpos = hostapd_eid_ht_capabilities(hapd, tailpos); |
| 1250 | tailpos = hostapd_eid_ht_operation(hapd, tailpos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1251 | |
| 1252 | tailpos = hostapd_eid_ext_capab(hapd, tailpos); |
| 1253 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1254 | /* |
| 1255 | * TODO: Time Advertisement element should only be included in some |
| 1256 | * DTIM Beacon frames. |
| 1257 | */ |
| 1258 | tailpos = hostapd_eid_time_adv(hapd, tailpos); |
| 1259 | |
| 1260 | tailpos = hostapd_eid_interworking(hapd, tailpos); |
| 1261 | tailpos = hostapd_eid_adv_proto(hapd, tailpos); |
| 1262 | tailpos = hostapd_eid_roaming_consortium(hapd, tailpos); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1263 | |
| 1264 | #ifdef CONFIG_FST |
| 1265 | if (hapd->iface->fst_ies) { |
| 1266 | os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies), |
| 1267 | wpabuf_len(hapd->iface->fst_ies)); |
| 1268 | tailpos += wpabuf_len(hapd->iface->fst_ies); |
| 1269 | } |
| 1270 | #endif /* CONFIG_FST */ |
| 1271 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1272 | #ifdef CONFIG_IEEE80211AC |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1273 | if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) { |
Dmitry Shmidt | 7d17530 | 2016-09-06 13:11:34 -0700 | [diff] [blame] | 1274 | tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1275 | tailpos = hostapd_eid_vht_operation(hapd, tailpos); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 1276 | tailpos = hostapd_eid_txpower_envelope(hapd, tailpos); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1277 | tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1278 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1279 | #endif /* CONFIG_IEEE80211AC */ |
| 1280 | |
| 1281 | tailpos = hostapd_eid_fils_indic(hapd, tailpos, 0); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1282 | tailpos = hostapd_get_rsnxe(hapd, tailpos, tailend - tailpos); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1283 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1284 | #ifdef CONFIG_IEEE80211AX |
| 1285 | if (hapd->iconf->ieee80211ax) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1286 | tailpos = hostapd_eid_he_capab(hapd, tailpos, |
| 1287 | IEEE80211_MODE_AP); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1288 | tailpos = hostapd_eid_he_operation(hapd, tailpos); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1289 | tailpos = hostapd_eid_spatial_reuse(hapd, tailpos); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1290 | tailpos = hostapd_eid_he_mu_edca_parameter_set(hapd, tailpos); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1291 | } |
| 1292 | #endif /* CONFIG_IEEE80211AX */ |
| 1293 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1294 | #ifdef CONFIG_IEEE80211AC |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1295 | if (hapd->conf->vendor_vht) |
| 1296 | tailpos = hostapd_eid_vendor_vht(hapd, tailpos); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1297 | #endif /* CONFIG_IEEE80211AC */ |
| 1298 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1299 | /* WPA / OSEN */ |
| 1300 | tailpos = hostapd_get_wpa_ie(hapd, tailpos, tailend - tailpos); |
| 1301 | tailpos = hostapd_get_osen_ie(hapd, tailpos, tailend - tailpos); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 1302 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1303 | /* Wi-Fi Alliance WMM */ |
| 1304 | tailpos = hostapd_eid_wmm(hapd, tailpos); |
| 1305 | |
| 1306 | #ifdef CONFIG_WPS |
| 1307 | if (hapd->conf->wps_state && hapd->wps_beacon_ie) { |
| 1308 | os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie), |
| 1309 | wpabuf_len(hapd->wps_beacon_ie)); |
| 1310 | tailpos += wpabuf_len(hapd->wps_beacon_ie); |
| 1311 | } |
| 1312 | #endif /* CONFIG_WPS */ |
| 1313 | |
| 1314 | #ifdef CONFIG_P2P |
| 1315 | if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) { |
| 1316 | os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie), |
| 1317 | wpabuf_len(hapd->p2p_beacon_ie)); |
| 1318 | tailpos += wpabuf_len(hapd->p2p_beacon_ie); |
| 1319 | } |
| 1320 | #endif /* CONFIG_P2P */ |
| 1321 | #ifdef CONFIG_P2P_MANAGER |
| 1322 | if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) == |
| 1323 | P2P_MANAGE) |
| 1324 | tailpos = hostapd_eid_p2p_manage(hapd, tailpos); |
| 1325 | #endif /* CONFIG_P2P_MANAGER */ |
| 1326 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1327 | #ifdef CONFIG_HS20 |
| 1328 | tailpos = hostapd_eid_hs20_indication(hapd, tailpos); |
| 1329 | #endif /* CONFIG_HS20 */ |
| 1330 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1331 | tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1332 | tailpos = hostapd_eid_owe_trans(hapd, tailpos, |
| 1333 | tail + tail_len - tailpos); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1334 | tailpos = hostapd_eid_dpp_cc(hapd, tailpos, tail + tail_len - tailpos); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1335 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1336 | if (hapd->conf->vendor_elements) { |
| 1337 | os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements), |
| 1338 | wpabuf_len(hapd->conf->vendor_elements)); |
| 1339 | tailpos += wpabuf_len(hapd->conf->vendor_elements); |
| 1340 | } |
| 1341 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1342 | tail_len = tailpos > tail ? tailpos - tail : 0; |
| 1343 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1344 | resp = hostapd_probe_resp_offloads(hapd, &resp_len); |
| 1345 | #endif /* NEED_AP_MLME */ |
| 1346 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1347 | os_memset(params, 0, sizeof(*params)); |
| 1348 | params->head = (u8 *) head; |
| 1349 | params->head_len = head_len; |
| 1350 | params->tail = tail; |
| 1351 | params->tail_len = tail_len; |
| 1352 | params->proberesp = resp; |
| 1353 | params->proberesp_len = resp_len; |
| 1354 | params->dtim_period = hapd->conf->dtim_period; |
| 1355 | params->beacon_int = hapd->iconf->beacon_int; |
| 1356 | params->basic_rates = hapd->iface->basic_rates; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1357 | params->beacon_rate = hapd->iconf->beacon_rate; |
| 1358 | params->rate_type = hapd->iconf->rate_type; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1359 | params->ssid = hapd->conf->ssid.ssid; |
| 1360 | params->ssid_len = hapd->conf->ssid.ssid_len; |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 1361 | if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) == |
| 1362 | (WPA_PROTO_WPA | WPA_PROTO_RSN)) |
| 1363 | params->pairwise_ciphers = hapd->conf->wpa_pairwise | |
| 1364 | hapd->conf->rsn_pairwise; |
| 1365 | else if (hapd->conf->wpa & WPA_PROTO_RSN) |
| 1366 | params->pairwise_ciphers = hapd->conf->rsn_pairwise; |
| 1367 | else if (hapd->conf->wpa & WPA_PROTO_WPA) |
| 1368 | params->pairwise_ciphers = hapd->conf->wpa_pairwise; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1369 | params->group_cipher = hapd->conf->wpa_group; |
| 1370 | params->key_mgmt_suites = hapd->conf->wpa_key_mgmt; |
| 1371 | params->auth_algs = hapd->conf->auth_algs; |
| 1372 | params->wpa_version = hapd->conf->wpa; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1373 | params->privacy = hapd->conf->wpa; |
| 1374 | #ifdef CONFIG_WEP |
| 1375 | params->privacy |= hapd->conf->ssid.wep.keys_set || |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1376 | (hapd->conf->ieee802_1x && |
| 1377 | (hapd->conf->default_wep_key_len || |
| 1378 | hapd->conf->individual_wep_key_len)); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1379 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1380 | switch (hapd->conf->ignore_broadcast_ssid) { |
| 1381 | case 0: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1382 | params->hide_ssid = NO_SSID_HIDING; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1383 | break; |
| 1384 | case 1: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1385 | params->hide_ssid = HIDDEN_SSID_ZERO_LEN; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1386 | break; |
| 1387 | case 2: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1388 | params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1389 | break; |
| 1390 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1391 | params->isolate = hapd->conf->isolate; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1392 | #ifdef NEED_AP_MLME |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1393 | params->cts_protect = !!(ieee802_11_erp_info(hapd) & |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1394 | ERP_INFO_USE_PROTECTION); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1395 | params->preamble = hapd->iface->num_sta_no_short_preamble == 0 && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1396 | hapd->iconf->preamble == SHORT_PREAMBLE; |
| 1397 | if (hapd->iface->current_mode && |
| 1398 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1399 | params->short_slot_time = |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1400 | hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1; |
| 1401 | else |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1402 | params->short_slot_time = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1403 | if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1404 | params->ht_opmode = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1405 | else |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1406 | params->ht_opmode = hapd->iface->ht_op_mode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1407 | #endif /* NEED_AP_MLME */ |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1408 | params->interworking = hapd->conf->interworking; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1409 | if (hapd->conf->interworking && |
| 1410 | !is_zero_ether_addr(hapd->conf->hessid)) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1411 | params->hessid = hapd->conf->hessid; |
| 1412 | params->access_network_type = hapd->conf->access_network_type; |
| 1413 | params->ap_max_inactivity = hapd->conf->ap_max_inactivity; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1414 | #ifdef CONFIG_P2P |
| 1415 | params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow; |
| 1416 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1417 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1418 | params->disable_dgaf = hapd->conf->disable_dgaf; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1419 | if (hapd->conf->osen) { |
| 1420 | params->privacy = 1; |
| 1421 | params->osen = 1; |
| 1422 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1423 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1424 | params->multicast_to_unicast = hapd->conf->multicast_to_unicast; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1425 | params->pbss = hapd->conf->pbss; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1426 | |
| 1427 | if (hapd->conf->ftm_responder) { |
| 1428 | if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_FTM_RESPONDER) { |
| 1429 | params->ftm_responder = 1; |
| 1430 | params->lci = hapd->iface->conf->lci; |
| 1431 | params->civic = hapd->iface->conf->civic; |
| 1432 | } else { |
| 1433 | wpa_printf(MSG_WARNING, |
| 1434 | "Not configuring FTM responder as the driver doesn't advertise support for it"); |
| 1435 | } |
| 1436 | } |
| 1437 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1438 | return 0; |
| 1439 | } |
| 1440 | |
| 1441 | |
| 1442 | void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params) |
| 1443 | { |
| 1444 | os_free(params->tail); |
| 1445 | params->tail = NULL; |
| 1446 | os_free(params->head); |
| 1447 | params->head = NULL; |
| 1448 | os_free(params->proberesp); |
| 1449 | params->proberesp = NULL; |
| 1450 | } |
| 1451 | |
| 1452 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1453 | int ieee802_11_set_beacon(struct hostapd_data *hapd) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1454 | { |
| 1455 | struct wpa_driver_ap_params params; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 1456 | struct hostapd_freq_params freq; |
| 1457 | struct hostapd_iface *iface = hapd->iface; |
| 1458 | struct hostapd_config *iconf = iface->conf; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1459 | struct hostapd_hw_modes *cmode = iface->current_mode; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1460 | struct wpabuf *beacon, *proberesp, *assocresp; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1461 | int res, ret = -1; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1462 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 1463 | if (hapd->csa_in_progress) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1464 | wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period"); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1465 | return -1; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1466 | } |
| 1467 | |
| 1468 | hapd->beacon_set_done = 1; |
| 1469 | |
| 1470 | if (ieee802_11_build_ap_params(hapd, ¶ms) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1471 | return -1; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1472 | |
| 1473 | if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) < |
| 1474 | 0) |
| 1475 | goto fail; |
| 1476 | |
| 1477 | params.beacon_ies = beacon; |
| 1478 | params.proberesp_ies = proberesp; |
| 1479 | params.assocresp_ies = assocresp; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1480 | params.reenable = hapd->reenable_beacon; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1481 | #ifdef CONFIG_IEEE80211AX |
| 1482 | params.he_spr = !!hapd->iface->conf->spr.sr_control; |
| 1483 | params.he_spr_srg_obss_pd_min_offset = |
| 1484 | hapd->iface->conf->spr.srg_obss_pd_min_offset; |
| 1485 | params.he_spr_srg_obss_pd_max_offset = |
| 1486 | hapd->iface->conf->spr.srg_obss_pd_max_offset; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1487 | params.he_bss_color_disabled = |
| 1488 | hapd->iface->conf->he_op.he_bss_color_disabled; |
| 1489 | params.he_bss_color_partial = |
| 1490 | hapd->iface->conf->he_op.he_bss_color_partial; |
| 1491 | params.he_bss_color = hapd->iface->conf->he_op.he_bss_color; |
| 1492 | params.twt_responder = hostapd_get_he_twt_responder(hapd, |
| 1493 | IEEE80211_MODE_AP); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1494 | #endif /* CONFIG_IEEE80211AX */ |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1495 | hapd->reenable_beacon = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1496 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1497 | if (cmode && |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 1498 | hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1499 | iconf->channel, iconf->enable_edmg, |
| 1500 | iconf->edmg_channel, iconf->ieee80211n, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1501 | iconf->ieee80211ac, iconf->ieee80211ax, |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 1502 | iconf->secondary_channel, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1503 | hostapd_get_oper_chwidth(iconf), |
| 1504 | hostapd_get_oper_centr_freq_seg0_idx(iconf), |
| 1505 | hostapd_get_oper_centr_freq_seg1_idx(iconf), |
| 1506 | cmode->vht_capab, |
| 1507 | &cmode->he_capab[IEEE80211_MODE_AP]) == 0) |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 1508 | params.freq = &freq; |
| 1509 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1510 | res = hostapd_drv_set_ap(hapd, ¶ms); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1511 | hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1512 | if (res) |
| 1513 | wpa_printf(MSG_ERROR, "Failed to set beacon parameters"); |
| 1514 | else |
| 1515 | ret = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1516 | fail: |
| 1517 | ieee802_11_free_ap_params(¶ms); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1518 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1522 | int ieee802_11_set_beacons(struct hostapd_iface *iface) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1523 | { |
| 1524 | size_t i; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1525 | int ret = 0; |
| 1526 | |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 1527 | for (i = 0; i < iface->num_bss; i++) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1528 | if (iface->bss[i]->started && |
| 1529 | ieee802_11_set_beacon(iface->bss[i]) < 0) |
| 1530 | ret = -1; |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 1531 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1532 | |
| 1533 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1534 | } |
| 1535 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1536 | |
| 1537 | /* only update beacons if started */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1538 | int ieee802_11_update_beacons(struct hostapd_iface *iface) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1539 | { |
| 1540 | size_t i; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1541 | int ret = 0; |
| 1542 | |
| 1543 | for (i = 0; i < iface->num_bss; i++) { |
| 1544 | if (iface->bss[i]->beacon_set_done && iface->bss[i]->started && |
| 1545 | ieee802_11_set_beacon(iface->bss[i]) < 0) |
| 1546 | ret = -1; |
| 1547 | } |
| 1548 | |
| 1549 | return ret; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1550 | } |
| 1551 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1552 | #endif /* CONFIG_NATIVE_WINDOWS */ |