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