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