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