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