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