Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * hostapd / Hardware feature query and different modes |
| 3 | * Copyright 2002-2003, Instant802 Networks, Inc. |
| 4 | * Copyright 2005-2006, Devicescape Software, Inc. |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [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 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * Alternatively, this software may be distributed under the terms of BSD |
| 12 | * license. |
| 13 | * |
| 14 | * See README and COPYING for more details. |
| 15 | */ |
| 16 | |
| 17 | #include "utils/includes.h" |
| 18 | |
| 19 | #include "utils/common.h" |
| 20 | #include "utils/eloop.h" |
| 21 | #include "common/ieee802_11_defs.h" |
| 22 | #include "common/ieee802_11_common.h" |
| 23 | #include "drivers/driver.h" |
| 24 | #include "hostapd.h" |
| 25 | #include "ap_config.h" |
| 26 | #include "ap_drv_ops.h" |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 27 | #include "acs.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 28 | #include "hw_features.h" |
| 29 | |
| 30 | |
| 31 | void hostapd_free_hw_features(struct hostapd_hw_modes *hw_features, |
| 32 | size_t num_hw_features) |
| 33 | { |
| 34 | size_t i; |
| 35 | |
| 36 | if (hw_features == NULL) |
| 37 | return; |
| 38 | |
| 39 | for (i = 0; i < num_hw_features; i++) { |
| 40 | os_free(hw_features[i].channels); |
| 41 | os_free(hw_features[i].rates); |
| 42 | } |
| 43 | |
| 44 | os_free(hw_features); |
| 45 | } |
| 46 | |
| 47 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 48 | #ifndef CONFIG_NO_STDOUT_DEBUG |
| 49 | static char * dfs_info(struct hostapd_channel_data *chan) |
| 50 | { |
| 51 | static char info[256]; |
| 52 | char *state; |
| 53 | |
| 54 | switch (chan->flag & HOSTAPD_CHAN_DFS_MASK) { |
| 55 | case HOSTAPD_CHAN_DFS_UNKNOWN: |
| 56 | state = "unknown"; |
| 57 | break; |
| 58 | case HOSTAPD_CHAN_DFS_USABLE: |
| 59 | state = "usable"; |
| 60 | break; |
| 61 | case HOSTAPD_CHAN_DFS_UNAVAILABLE: |
| 62 | state = "unavailable"; |
| 63 | break; |
| 64 | case HOSTAPD_CHAN_DFS_AVAILABLE: |
| 65 | state = "available"; |
| 66 | break; |
| 67 | default: |
| 68 | return ""; |
| 69 | } |
| 70 | os_snprintf(info, sizeof(info), " (DFS state = %s)", state); |
| 71 | info[sizeof(info) - 1] = '\0'; |
| 72 | |
| 73 | return info; |
| 74 | } |
| 75 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
| 76 | |
| 77 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 78 | int hostapd_get_hw_features(struct hostapd_iface *iface) |
| 79 | { |
| 80 | struct hostapd_data *hapd = iface->bss[0]; |
| 81 | int ret = 0, i, j; |
| 82 | u16 num_modes, flags; |
| 83 | struct hostapd_hw_modes *modes; |
| 84 | |
| 85 | if (hostapd_drv_none(hapd)) |
| 86 | return -1; |
| 87 | modes = hostapd_get_hw_feature_data(hapd, &num_modes, &flags); |
| 88 | if (modes == NULL) { |
| 89 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, |
| 90 | HOSTAPD_LEVEL_DEBUG, |
| 91 | "Fetching hardware channel/rate support not " |
| 92 | "supported."); |
| 93 | return -1; |
| 94 | } |
| 95 | |
| 96 | iface->hw_flags = flags; |
| 97 | |
| 98 | hostapd_free_hw_features(iface->hw_features, iface->num_hw_features); |
| 99 | iface->hw_features = modes; |
| 100 | iface->num_hw_features = num_modes; |
| 101 | |
| 102 | for (i = 0; i < num_modes; i++) { |
| 103 | struct hostapd_hw_modes *feature = &modes[i]; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 104 | int dfs_enabled = hapd->iconf->ieee80211h && |
| 105 | (iface->drv_flags & WPA_DRIVER_FLAGS_RADAR); |
| 106 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 107 | /* set flag for channels we can use in current regulatory |
| 108 | * domain */ |
| 109 | for (j = 0; j < feature->num_channels; j++) { |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 110 | int dfs = 0; |
| 111 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 112 | /* |
| 113 | * Disable all channels that are marked not to allow |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 114 | * IBSS operation or active scanning. |
| 115 | * Use radar channels only if the driver supports DFS. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 116 | */ |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 117 | if ((feature->channels[j].flag & |
| 118 | HOSTAPD_CHAN_RADAR) && dfs_enabled) { |
| 119 | dfs = 1; |
| 120 | } else if (feature->channels[j].flag & |
| 121 | (HOSTAPD_CHAN_NO_IBSS | |
| 122 | HOSTAPD_CHAN_PASSIVE_SCAN | |
| 123 | HOSTAPD_CHAN_RADAR)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 124 | feature->channels[j].flag |= |
| 125 | HOSTAPD_CHAN_DISABLED; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 128 | if (feature->channels[j].flag & HOSTAPD_CHAN_DISABLED) |
| 129 | continue; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 130 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 131 | wpa_printf(MSG_MSGDUMP, "Allowed channel: mode=%d " |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 132 | "chan=%d freq=%d MHz max_tx_power=%d dBm%s", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 133 | feature->mode, |
| 134 | feature->channels[j].chan, |
| 135 | feature->channels[j].freq, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 136 | feature->channels[j].max_tx_power, |
| 137 | dfs ? dfs_info(&feature->channels[j]) : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | |
| 141 | return ret; |
| 142 | } |
| 143 | |
| 144 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 145 | int hostapd_prepare_rates(struct hostapd_iface *iface, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 146 | struct hostapd_hw_modes *mode) |
| 147 | { |
| 148 | int i, num_basic_rates = 0; |
| 149 | int basic_rates_a[] = { 60, 120, 240, -1 }; |
| 150 | int basic_rates_b[] = { 10, 20, -1 }; |
| 151 | int basic_rates_g[] = { 10, 20, 55, 110, -1 }; |
| 152 | int *basic_rates; |
| 153 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 154 | if (iface->conf->basic_rates) |
| 155 | basic_rates = iface->conf->basic_rates; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 156 | else switch (mode->mode) { |
| 157 | case HOSTAPD_MODE_IEEE80211A: |
| 158 | basic_rates = basic_rates_a; |
| 159 | break; |
| 160 | case HOSTAPD_MODE_IEEE80211B: |
| 161 | basic_rates = basic_rates_b; |
| 162 | break; |
| 163 | case HOSTAPD_MODE_IEEE80211G: |
| 164 | basic_rates = basic_rates_g; |
| 165 | break; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 166 | case HOSTAPD_MODE_IEEE80211AD: |
| 167 | return 0; /* No basic rates for 11ad */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 168 | default: |
| 169 | return -1; |
| 170 | } |
| 171 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 172 | i = 0; |
| 173 | while (basic_rates[i] >= 0) |
| 174 | i++; |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 175 | if (i) |
| 176 | i++; /* -1 termination */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 177 | os_free(iface->basic_rates); |
| 178 | iface->basic_rates = os_malloc(i * sizeof(int)); |
| 179 | if (iface->basic_rates) |
| 180 | os_memcpy(iface->basic_rates, basic_rates, i * sizeof(int)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 181 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 182 | os_free(iface->current_rates); |
| 183 | iface->num_rates = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 184 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 185 | iface->current_rates = |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 186 | os_calloc(mode->num_rates, sizeof(struct hostapd_rate_data)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 187 | if (!iface->current_rates) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 188 | wpa_printf(MSG_ERROR, "Failed to allocate memory for rate " |
| 189 | "table."); |
| 190 | return -1; |
| 191 | } |
| 192 | |
| 193 | for (i = 0; i < mode->num_rates; i++) { |
| 194 | struct hostapd_rate_data *rate; |
| 195 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 196 | if (iface->conf->supported_rates && |
| 197 | !hostapd_rate_found(iface->conf->supported_rates, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 198 | mode->rates[i])) |
| 199 | continue; |
| 200 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 201 | rate = &iface->current_rates[iface->num_rates]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 202 | rate->rate = mode->rates[i]; |
| 203 | if (hostapd_rate_found(basic_rates, rate->rate)) { |
| 204 | rate->flags |= HOSTAPD_RATE_BASIC; |
| 205 | num_basic_rates++; |
| 206 | } |
| 207 | wpa_printf(MSG_DEBUG, "RATE[%d] rate=%d flags=0x%x", |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 208 | iface->num_rates, rate->rate, rate->flags); |
| 209 | iface->num_rates++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 212 | if ((iface->num_rates == 0 || num_basic_rates == 0) && |
| 213 | (!iface->conf->ieee80211n || !iface->conf->require_ht)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 214 | wpa_printf(MSG_ERROR, "No rates remaining in supported/basic " |
| 215 | "rate sets (%d,%d).", |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 216 | iface->num_rates, num_basic_rates); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 217 | return -1; |
| 218 | } |
| 219 | |
| 220 | return 0; |
| 221 | } |
| 222 | |
| 223 | |
| 224 | #ifdef CONFIG_IEEE80211N |
| 225 | static int ieee80211n_allowed_ht40_channel_pair(struct hostapd_iface *iface) |
| 226 | { |
| 227 | int sec_chan, ok, j, first; |
| 228 | int allowed[] = { 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157, |
| 229 | 184, 192 }; |
| 230 | size_t k; |
| 231 | |
| 232 | if (!iface->conf->secondary_channel) |
| 233 | return 1; /* HT40 not used */ |
| 234 | |
| 235 | sec_chan = iface->conf->channel + iface->conf->secondary_channel * 4; |
| 236 | wpa_printf(MSG_DEBUG, "HT40: control channel: %d " |
| 237 | "secondary channel: %d", |
| 238 | iface->conf->channel, sec_chan); |
| 239 | |
| 240 | /* Verify that HT40 secondary channel is an allowed 20 MHz |
| 241 | * channel */ |
| 242 | ok = 0; |
| 243 | for (j = 0; j < iface->current_mode->num_channels; j++) { |
| 244 | struct hostapd_channel_data *chan = |
| 245 | &iface->current_mode->channels[j]; |
| 246 | if (!(chan->flag & HOSTAPD_CHAN_DISABLED) && |
| 247 | chan->chan == sec_chan) { |
| 248 | ok = 1; |
| 249 | break; |
| 250 | } |
| 251 | } |
| 252 | if (!ok) { |
| 253 | wpa_printf(MSG_ERROR, "HT40 secondary channel %d not allowed", |
| 254 | sec_chan); |
| 255 | return 0; |
| 256 | } |
| 257 | |
| 258 | /* |
| 259 | * Verify that HT40 primary,secondary channel pair is allowed per |
| 260 | * IEEE 802.11n Annex J. This is only needed for 5 GHz band since |
| 261 | * 2.4 GHz rules allow all cases where the secondary channel fits into |
| 262 | * the list of allowed channels (already checked above). |
| 263 | */ |
| 264 | if (iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A) |
| 265 | return 1; |
| 266 | |
| 267 | if (iface->conf->secondary_channel > 0) |
| 268 | first = iface->conf->channel; |
| 269 | else |
| 270 | first = sec_chan; |
| 271 | |
| 272 | ok = 0; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame^] | 273 | for (k = 0; k < ARRAY_SIZE(allowed); k++) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 274 | if (first == allowed[k]) { |
| 275 | ok = 1; |
| 276 | break; |
| 277 | } |
| 278 | } |
| 279 | if (!ok) { |
| 280 | wpa_printf(MSG_ERROR, "HT40 channel pair (%d, %d) not allowed", |
| 281 | iface->conf->channel, |
| 282 | iface->conf->secondary_channel); |
| 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | return 1; |
| 287 | } |
| 288 | |
| 289 | |
| 290 | static void ieee80211n_switch_pri_sec(struct hostapd_iface *iface) |
| 291 | { |
| 292 | if (iface->conf->secondary_channel > 0) { |
| 293 | iface->conf->channel += 4; |
| 294 | iface->conf->secondary_channel = -1; |
| 295 | } else { |
| 296 | iface->conf->channel -= 4; |
| 297 | iface->conf->secondary_channel = 1; |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | |
| 302 | static void ieee80211n_get_pri_sec_chan(struct wpa_scan_res *bss, |
| 303 | int *pri_chan, int *sec_chan) |
| 304 | { |
| 305 | struct ieee80211_ht_operation *oper; |
| 306 | struct ieee802_11_elems elems; |
| 307 | |
| 308 | *pri_chan = *sec_chan = 0; |
| 309 | |
| 310 | ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len, &elems, 0); |
| 311 | if (elems.ht_operation && |
| 312 | elems.ht_operation_len >= sizeof(*oper)) { |
| 313 | oper = (struct ieee80211_ht_operation *) elems.ht_operation; |
| 314 | *pri_chan = oper->control_chan; |
| 315 | if (oper->ht_param & HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH) { |
| 316 | int sec = oper->ht_param & |
| 317 | HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK; |
| 318 | if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE) |
| 319 | *sec_chan = *pri_chan + 4; |
| 320 | else if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW) |
| 321 | *sec_chan = *pri_chan - 4; |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | |
| 327 | static int ieee80211n_check_40mhz_5g(struct hostapd_iface *iface, |
| 328 | struct wpa_scan_results *scan_res) |
| 329 | { |
| 330 | int pri_chan, sec_chan, pri_freq, sec_freq, pri_bss, sec_bss; |
| 331 | int bss_pri_chan, bss_sec_chan; |
| 332 | size_t i; |
| 333 | int match; |
| 334 | |
| 335 | pri_chan = iface->conf->channel; |
| 336 | sec_chan = iface->conf->secondary_channel * 4; |
| 337 | pri_freq = hostapd_hw_get_freq(iface->bss[0], pri_chan); |
| 338 | if (iface->conf->secondary_channel > 0) |
| 339 | sec_freq = pri_freq + 20; |
| 340 | else |
| 341 | sec_freq = pri_freq - 20; |
| 342 | |
| 343 | /* |
| 344 | * Switch PRI/SEC channels if Beacons were detected on selected SEC |
| 345 | * channel, but not on selected PRI channel. |
| 346 | */ |
| 347 | pri_bss = sec_bss = 0; |
| 348 | for (i = 0; i < scan_res->num; i++) { |
| 349 | struct wpa_scan_res *bss = scan_res->res[i]; |
| 350 | if (bss->freq == pri_freq) |
| 351 | pri_bss++; |
| 352 | else if (bss->freq == sec_freq) |
| 353 | sec_bss++; |
| 354 | } |
| 355 | if (sec_bss && !pri_bss) { |
| 356 | wpa_printf(MSG_INFO, "Switch own primary and secondary " |
| 357 | "channel to get secondary channel with no Beacons " |
| 358 | "from other BSSes"); |
| 359 | ieee80211n_switch_pri_sec(iface); |
| 360 | } |
| 361 | |
| 362 | /* |
| 363 | * Match PRI/SEC channel with any existing HT40 BSS on the same |
| 364 | * channels that we are about to use (if already mixed order in |
| 365 | * existing BSSes, use own preference). |
| 366 | */ |
| 367 | match = 0; |
| 368 | for (i = 0; i < scan_res->num; i++) { |
| 369 | struct wpa_scan_res *bss = scan_res->res[i]; |
| 370 | ieee80211n_get_pri_sec_chan(bss, &bss_pri_chan, &bss_sec_chan); |
| 371 | if (pri_chan == bss_pri_chan && |
| 372 | sec_chan == bss_sec_chan) { |
| 373 | match = 1; |
| 374 | break; |
| 375 | } |
| 376 | } |
| 377 | if (!match) { |
| 378 | for (i = 0; i < scan_res->num; i++) { |
| 379 | struct wpa_scan_res *bss = scan_res->res[i]; |
| 380 | ieee80211n_get_pri_sec_chan(bss, &bss_pri_chan, |
| 381 | &bss_sec_chan); |
| 382 | if (pri_chan == bss_sec_chan && |
| 383 | sec_chan == bss_pri_chan) { |
| 384 | wpa_printf(MSG_INFO, "Switch own primary and " |
| 385 | "secondary channel due to BSS " |
| 386 | "overlap with " MACSTR, |
| 387 | MAC2STR(bss->bssid)); |
| 388 | ieee80211n_switch_pri_sec(iface); |
| 389 | break; |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | return 1; |
| 395 | } |
| 396 | |
| 397 | |
| 398 | static int ieee80211n_check_40mhz_2g4(struct hostapd_iface *iface, |
| 399 | struct wpa_scan_results *scan_res) |
| 400 | { |
| 401 | int pri_freq, sec_freq; |
| 402 | int affected_start, affected_end; |
| 403 | size_t i; |
| 404 | |
| 405 | pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel); |
| 406 | if (iface->conf->secondary_channel > 0) |
| 407 | sec_freq = pri_freq + 20; |
| 408 | else |
| 409 | sec_freq = pri_freq - 20; |
| 410 | affected_start = (pri_freq + sec_freq) / 2 - 25; |
| 411 | affected_end = (pri_freq + sec_freq) / 2 + 25; |
| 412 | wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz", |
| 413 | affected_start, affected_end); |
| 414 | for (i = 0; i < scan_res->num; i++) { |
| 415 | struct wpa_scan_res *bss = scan_res->res[i]; |
| 416 | int pri = bss->freq; |
| 417 | int sec = pri; |
| 418 | int sec_chan, pri_chan; |
| 419 | |
| 420 | ieee80211n_get_pri_sec_chan(bss, &pri_chan, &sec_chan); |
| 421 | |
| 422 | if (sec_chan) { |
| 423 | if (sec_chan < pri_chan) |
| 424 | sec = pri - 20; |
| 425 | else |
| 426 | sec = pri + 20; |
| 427 | } |
| 428 | |
| 429 | if ((pri < affected_start || pri > affected_end) && |
| 430 | (sec < affected_start || sec > affected_end)) |
| 431 | continue; /* not within affected channel range */ |
| 432 | |
| 433 | wpa_printf(MSG_DEBUG, "Neighboring BSS: " MACSTR |
| 434 | " freq=%d pri=%d sec=%d", |
| 435 | MAC2STR(bss->bssid), bss->freq, pri_chan, sec_chan); |
| 436 | |
| 437 | if (sec_chan) { |
| 438 | if (pri_freq != pri || sec_freq != sec) { |
| 439 | wpa_printf(MSG_DEBUG, "40 MHz pri/sec " |
| 440 | "mismatch with BSS " MACSTR |
| 441 | " <%d,%d> (chan=%d%c) vs. <%d,%d>", |
| 442 | MAC2STR(bss->bssid), |
| 443 | pri, sec, pri_chan, |
| 444 | sec > pri ? '+' : '-', |
| 445 | pri_freq, sec_freq); |
| 446 | return 0; |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | /* TODO: 40 MHz intolerant */ |
| 451 | } |
| 452 | |
| 453 | return 1; |
| 454 | } |
| 455 | |
| 456 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 457 | static void ieee80211n_check_scan(struct hostapd_iface *iface) |
| 458 | { |
| 459 | struct wpa_scan_results *scan_res; |
| 460 | int oper40; |
| 461 | int res; |
| 462 | |
| 463 | /* Check list of neighboring BSSes (from scan) to see whether 40 MHz is |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 464 | * allowed per IEEE Std 802.11-2012, 10.15.3.2 */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 465 | |
| 466 | iface->scan_cb = NULL; |
| 467 | |
| 468 | scan_res = hostapd_driver_get_scan_results(iface->bss[0]); |
| 469 | if (scan_res == NULL) { |
| 470 | hostapd_setup_interface_complete(iface, 1); |
| 471 | return; |
| 472 | } |
| 473 | |
| 474 | if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A) |
| 475 | oper40 = ieee80211n_check_40mhz_5g(iface, scan_res); |
| 476 | else |
| 477 | oper40 = ieee80211n_check_40mhz_2g4(iface, scan_res); |
| 478 | wpa_scan_results_free(scan_res); |
| 479 | |
| 480 | if (!oper40) { |
| 481 | wpa_printf(MSG_INFO, "20/40 MHz operation not permitted on " |
| 482 | "channel pri=%d sec=%d based on overlapping BSSes", |
| 483 | iface->conf->channel, |
| 484 | iface->conf->channel + |
| 485 | iface->conf->secondary_channel * 4); |
| 486 | iface->conf->secondary_channel = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | res = ieee80211n_allowed_ht40_channel_pair(iface); |
| 490 | hostapd_setup_interface_complete(iface, !res); |
| 491 | } |
| 492 | |
| 493 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 494 | static void ieee80211n_scan_channels_2g4(struct hostapd_iface *iface, |
| 495 | struct wpa_driver_scan_params *params) |
| 496 | { |
| 497 | /* Scan only the affected frequency range */ |
| 498 | int pri_freq, sec_freq; |
| 499 | int affected_start, affected_end; |
| 500 | int i, pos; |
| 501 | struct hostapd_hw_modes *mode; |
| 502 | |
| 503 | if (iface->current_mode == NULL) |
| 504 | return; |
| 505 | |
| 506 | pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel); |
| 507 | if (iface->conf->secondary_channel > 0) |
| 508 | sec_freq = pri_freq + 20; |
| 509 | else |
| 510 | sec_freq = pri_freq - 20; |
| 511 | affected_start = (pri_freq + sec_freq) / 2 - 25; |
| 512 | affected_end = (pri_freq + sec_freq) / 2 + 25; |
| 513 | wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz", |
| 514 | affected_start, affected_end); |
| 515 | |
| 516 | mode = iface->current_mode; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 517 | params->freqs = os_calloc(mode->num_channels + 1, sizeof(int)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 518 | if (params->freqs == NULL) |
| 519 | return; |
| 520 | pos = 0; |
| 521 | |
| 522 | for (i = 0; i < mode->num_channels; i++) { |
| 523 | struct hostapd_channel_data *chan = &mode->channels[i]; |
| 524 | if (chan->flag & HOSTAPD_CHAN_DISABLED) |
| 525 | continue; |
| 526 | if (chan->freq < affected_start || |
| 527 | chan->freq > affected_end) |
| 528 | continue; |
| 529 | params->freqs[pos++] = chan->freq; |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 534 | static int ieee80211n_check_40mhz(struct hostapd_iface *iface) |
| 535 | { |
| 536 | struct wpa_driver_scan_params params; |
| 537 | |
| 538 | if (!iface->conf->secondary_channel) |
| 539 | return 0; /* HT40 not used */ |
| 540 | |
| 541 | wpa_printf(MSG_DEBUG, "Scan for neighboring BSSes prior to enabling " |
| 542 | "40 MHz channel"); |
| 543 | os_memset(¶ms, 0, sizeof(params)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 544 | if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G) |
| 545 | ieee80211n_scan_channels_2g4(iface, ¶ms); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 546 | if (hostapd_driver_scan(iface->bss[0], ¶ms) < 0) { |
| 547 | wpa_printf(MSG_ERROR, "Failed to request a scan of " |
| 548 | "neighboring BSSes"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 549 | os_free(params.freqs); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 550 | return -1; |
| 551 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 552 | os_free(params.freqs); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 553 | |
| 554 | iface->scan_cb = ieee80211n_check_scan; |
| 555 | return 1; |
| 556 | } |
| 557 | |
| 558 | |
| 559 | static int ieee80211n_supported_ht_capab(struct hostapd_iface *iface) |
| 560 | { |
| 561 | u16 hw = iface->current_mode->ht_capab; |
| 562 | u16 conf = iface->conf->ht_capab; |
| 563 | |
| 564 | if ((conf & HT_CAP_INFO_LDPC_CODING_CAP) && |
| 565 | !(hw & HT_CAP_INFO_LDPC_CODING_CAP)) { |
| 566 | wpa_printf(MSG_ERROR, "Driver does not support configured " |
| 567 | "HT capability [LDPC]"); |
| 568 | return 0; |
| 569 | } |
| 570 | |
| 571 | if ((conf & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) && |
| 572 | !(hw & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) { |
| 573 | wpa_printf(MSG_ERROR, "Driver does not support configured " |
| 574 | "HT capability [HT40*]"); |
| 575 | return 0; |
| 576 | } |
| 577 | |
| 578 | if ((conf & HT_CAP_INFO_SMPS_MASK) != (hw & HT_CAP_INFO_SMPS_MASK) && |
| 579 | (conf & HT_CAP_INFO_SMPS_MASK) != HT_CAP_INFO_SMPS_DISABLED) { |
| 580 | wpa_printf(MSG_ERROR, "Driver does not support configured " |
| 581 | "HT capability [SMPS-*]"); |
| 582 | return 0; |
| 583 | } |
| 584 | |
| 585 | if ((conf & HT_CAP_INFO_GREEN_FIELD) && |
| 586 | !(hw & HT_CAP_INFO_GREEN_FIELD)) { |
| 587 | wpa_printf(MSG_ERROR, "Driver does not support configured " |
| 588 | "HT capability [GF]"); |
| 589 | return 0; |
| 590 | } |
| 591 | |
| 592 | if ((conf & HT_CAP_INFO_SHORT_GI20MHZ) && |
| 593 | !(hw & HT_CAP_INFO_SHORT_GI20MHZ)) { |
| 594 | wpa_printf(MSG_ERROR, "Driver does not support configured " |
| 595 | "HT capability [SHORT-GI-20]"); |
| 596 | return 0; |
| 597 | } |
| 598 | |
| 599 | if ((conf & HT_CAP_INFO_SHORT_GI40MHZ) && |
| 600 | !(hw & HT_CAP_INFO_SHORT_GI40MHZ)) { |
| 601 | wpa_printf(MSG_ERROR, "Driver does not support configured " |
| 602 | "HT capability [SHORT-GI-40]"); |
| 603 | return 0; |
| 604 | } |
| 605 | |
| 606 | if ((conf & HT_CAP_INFO_TX_STBC) && !(hw & HT_CAP_INFO_TX_STBC)) { |
| 607 | wpa_printf(MSG_ERROR, "Driver does not support configured " |
| 608 | "HT capability [TX-STBC]"); |
| 609 | return 0; |
| 610 | } |
| 611 | |
| 612 | if ((conf & HT_CAP_INFO_RX_STBC_MASK) > |
| 613 | (hw & HT_CAP_INFO_RX_STBC_MASK)) { |
| 614 | wpa_printf(MSG_ERROR, "Driver does not support configured " |
| 615 | "HT capability [RX-STBC*]"); |
| 616 | return 0; |
| 617 | } |
| 618 | |
| 619 | if ((conf & HT_CAP_INFO_DELAYED_BA) && |
| 620 | !(hw & HT_CAP_INFO_DELAYED_BA)) { |
| 621 | wpa_printf(MSG_ERROR, "Driver does not support configured " |
| 622 | "HT capability [DELAYED-BA]"); |
| 623 | return 0; |
| 624 | } |
| 625 | |
| 626 | if ((conf & HT_CAP_INFO_MAX_AMSDU_SIZE) && |
| 627 | !(hw & HT_CAP_INFO_MAX_AMSDU_SIZE)) { |
| 628 | wpa_printf(MSG_ERROR, "Driver does not support configured " |
| 629 | "HT capability [MAX-AMSDU-7935]"); |
| 630 | return 0; |
| 631 | } |
| 632 | |
| 633 | if ((conf & HT_CAP_INFO_DSSS_CCK40MHZ) && |
| 634 | !(hw & HT_CAP_INFO_DSSS_CCK40MHZ)) { |
| 635 | wpa_printf(MSG_ERROR, "Driver does not support configured " |
| 636 | "HT capability [DSSS_CCK-40]"); |
| 637 | return 0; |
| 638 | } |
| 639 | |
| 640 | if ((conf & HT_CAP_INFO_PSMP_SUPP) && !(hw & HT_CAP_INFO_PSMP_SUPP)) { |
| 641 | wpa_printf(MSG_ERROR, "Driver does not support configured " |
| 642 | "HT capability [PSMP]"); |
| 643 | return 0; |
| 644 | } |
| 645 | |
| 646 | if ((conf & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT) && |
| 647 | !(hw & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT)) { |
| 648 | wpa_printf(MSG_ERROR, "Driver does not support configured " |
| 649 | "HT capability [LSIG-TXOP-PROT]"); |
| 650 | return 0; |
| 651 | } |
| 652 | |
| 653 | return 1; |
| 654 | } |
| 655 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame^] | 656 | |
| 657 | #ifdef CONFIG_IEEE80211AC |
| 658 | |
| 659 | static int ieee80211ac_cap_check(u32 hw, u32 conf, u32 cap, const char *name) |
| 660 | { |
| 661 | u32 req_cap = conf & cap; |
| 662 | |
| 663 | /* |
| 664 | * Make sure we support all requested capabilities. |
| 665 | * NOTE: We assume that 'cap' represents a capability mask, |
| 666 | * not a discrete value. |
| 667 | */ |
| 668 | if ((hw & req_cap) != req_cap) { |
| 669 | wpa_printf(MSG_ERROR, "Driver does not support configured VHT capability [%s]", |
| 670 | name); |
| 671 | return 0; |
| 672 | } |
| 673 | return 1; |
| 674 | } |
| 675 | |
| 676 | |
| 677 | static int ieee80211ac_cap_check_max(u32 hw, u32 conf, u32 cap, |
| 678 | const char *name) |
| 679 | { |
| 680 | u32 hw_max = hw & cap; |
| 681 | u32 conf_val = conf & cap; |
| 682 | |
| 683 | if (conf_val > hw_max) { |
| 684 | int offset = find_first_bit(cap); |
| 685 | wpa_printf(MSG_ERROR, "Configured VHT capability [%s] exceeds max value supported by the driver (%d > %d)", |
| 686 | name, conf_val >> offset, hw_max >> offset); |
| 687 | return 0; |
| 688 | } |
| 689 | return 1; |
| 690 | } |
| 691 | |
| 692 | |
| 693 | static int ieee80211ac_supported_vht_capab(struct hostapd_iface *iface) |
| 694 | { |
| 695 | u32 hw = iface->current_mode->vht_capab; |
| 696 | u32 conf = iface->conf->vht_capab; |
| 697 | |
| 698 | wpa_printf(MSG_DEBUG, "hw vht capab: 0x%x, conf vht capab: 0x%x", |
| 699 | hw, conf); |
| 700 | |
| 701 | #define VHT_CAP_CHECK(cap) \ |
| 702 | do { \ |
| 703 | if (!ieee80211ac_cap_check(hw, conf, cap, #cap)) \ |
| 704 | return 0; \ |
| 705 | } while (0) |
| 706 | |
| 707 | #define VHT_CAP_CHECK_MAX(cap) \ |
| 708 | do { \ |
| 709 | if (!ieee80211ac_cap_check_max(hw, conf, cap, #cap)) \ |
| 710 | return 0; \ |
| 711 | } while (0) |
| 712 | |
| 713 | VHT_CAP_CHECK_MAX(VHT_CAP_MAX_MPDU_LENGTH_MASK); |
| 714 | VHT_CAP_CHECK(VHT_CAP_SUPP_CHAN_WIDTH_160MHZ); |
| 715 | VHT_CAP_CHECK(VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ); |
| 716 | VHT_CAP_CHECK(VHT_CAP_RXLDPC); |
| 717 | VHT_CAP_CHECK(VHT_CAP_SHORT_GI_80); |
| 718 | VHT_CAP_CHECK(VHT_CAP_SHORT_GI_160); |
| 719 | VHT_CAP_CHECK(VHT_CAP_TXSTBC); |
| 720 | VHT_CAP_CHECK_MAX(VHT_CAP_RXSTBC_MASK); |
| 721 | VHT_CAP_CHECK(VHT_CAP_SU_BEAMFORMER_CAPABLE); |
| 722 | VHT_CAP_CHECK(VHT_CAP_SU_BEAMFORMEE_CAPABLE); |
| 723 | VHT_CAP_CHECK_MAX(VHT_CAP_BEAMFORMEE_STS_MAX); |
| 724 | VHT_CAP_CHECK_MAX(VHT_CAP_SOUNDING_DIMENSION_MAX); |
| 725 | VHT_CAP_CHECK(VHT_CAP_MU_BEAMFORMER_CAPABLE); |
| 726 | VHT_CAP_CHECK(VHT_CAP_MU_BEAMFORMEE_CAPABLE); |
| 727 | VHT_CAP_CHECK(VHT_CAP_VHT_TXOP_PS); |
| 728 | VHT_CAP_CHECK(VHT_CAP_HTC_VHT); |
| 729 | VHT_CAP_CHECK_MAX(VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT); |
| 730 | VHT_CAP_CHECK(VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB); |
| 731 | VHT_CAP_CHECK(VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB); |
| 732 | VHT_CAP_CHECK(VHT_CAP_RX_ANTENNA_PATTERN); |
| 733 | VHT_CAP_CHECK(VHT_CAP_TX_ANTENNA_PATTERN); |
| 734 | |
| 735 | #undef VHT_CAP_CHECK |
| 736 | #undef VHT_CAP_CHECK_MAX |
| 737 | |
| 738 | return 1; |
| 739 | } |
| 740 | #endif /* CONFIG_IEEE80211AC */ |
| 741 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 742 | #endif /* CONFIG_IEEE80211N */ |
| 743 | |
| 744 | |
| 745 | int hostapd_check_ht_capab(struct hostapd_iface *iface) |
| 746 | { |
| 747 | #ifdef CONFIG_IEEE80211N |
| 748 | int ret; |
| 749 | if (!iface->conf->ieee80211n) |
| 750 | return 0; |
| 751 | if (!ieee80211n_supported_ht_capab(iface)) |
| 752 | return -1; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame^] | 753 | #ifdef CONFIG_IEEE80211AC |
| 754 | if (!ieee80211ac_supported_vht_capab(iface)) |
| 755 | return -1; |
| 756 | #endif /* CONFIG_IEEE80211AC */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 757 | ret = ieee80211n_check_40mhz(iface); |
| 758 | if (ret) |
| 759 | return ret; |
| 760 | if (!ieee80211n_allowed_ht40_channel_pair(iface)) |
| 761 | return -1; |
| 762 | #endif /* CONFIG_IEEE80211N */ |
| 763 | |
| 764 | return 0; |
| 765 | } |
| 766 | |
| 767 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 768 | static int hostapd_is_usable_chan(struct hostapd_iface *iface, |
| 769 | int channel, int primary) |
| 770 | { |
| 771 | int i; |
| 772 | struct hostapd_channel_data *chan; |
| 773 | |
| 774 | for (i = 0; i < iface->current_mode->num_channels; i++) { |
| 775 | chan = &iface->current_mode->channels[i]; |
| 776 | if (chan->chan != channel) |
| 777 | continue; |
| 778 | |
| 779 | if (!(chan->flag & HOSTAPD_CHAN_DISABLED)) |
| 780 | return 1; |
| 781 | |
| 782 | wpa_printf(MSG_DEBUG, |
| 783 | "%schannel [%i] (%i) is disabled for use in AP mode, flags: 0x%x%s%s%s", |
| 784 | primary ? "" : "Configured HT40 secondary ", |
| 785 | i, chan->chan, chan->flag, |
| 786 | chan->flag & HOSTAPD_CHAN_NO_IBSS ? " NO-IBSS" : "", |
| 787 | chan->flag & HOSTAPD_CHAN_PASSIVE_SCAN ? |
| 788 | " PASSIVE-SCAN" : "", |
| 789 | chan->flag & HOSTAPD_CHAN_RADAR ? " RADAR" : ""); |
| 790 | } |
| 791 | |
| 792 | return 0; |
| 793 | } |
| 794 | |
| 795 | |
| 796 | static int hostapd_is_usable_chans(struct hostapd_iface *iface) |
| 797 | { |
| 798 | if (!hostapd_is_usable_chan(iface, iface->conf->channel, 1)) |
| 799 | return 0; |
| 800 | |
| 801 | if (!iface->conf->secondary_channel) |
| 802 | return 1; |
| 803 | |
| 804 | return hostapd_is_usable_chan(iface, iface->conf->channel + |
| 805 | iface->conf->secondary_channel * 4, 0); |
| 806 | } |
| 807 | |
| 808 | |
| 809 | static enum hostapd_chan_status |
| 810 | hostapd_check_chans(struct hostapd_iface *iface) |
| 811 | { |
| 812 | if (iface->conf->channel) { |
| 813 | if (hostapd_is_usable_chans(iface)) |
| 814 | return HOSTAPD_CHAN_VALID; |
| 815 | else |
| 816 | return HOSTAPD_CHAN_INVALID; |
| 817 | } |
| 818 | |
| 819 | /* |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 820 | * The user set channel=0 or channel=acs_survey |
| 821 | * which is used to trigger ACS. |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 822 | */ |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 823 | |
| 824 | switch (acs_init(iface)) { |
| 825 | case HOSTAPD_CHAN_ACS: |
| 826 | return HOSTAPD_CHAN_ACS; |
| 827 | case HOSTAPD_CHAN_VALID: |
| 828 | case HOSTAPD_CHAN_INVALID: |
| 829 | default: |
| 830 | return HOSTAPD_CHAN_INVALID; |
| 831 | } |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | |
| 835 | static void hostapd_notify_bad_chans(struct hostapd_iface *iface) |
| 836 | { |
| 837 | hostapd_logger(iface->bss[0], NULL, |
| 838 | HOSTAPD_MODULE_IEEE80211, |
| 839 | HOSTAPD_LEVEL_WARNING, |
| 840 | "Configured channel (%d) not found from the " |
| 841 | "channel list of current mode (%d) %s", |
| 842 | iface->conf->channel, |
| 843 | iface->current_mode->mode, |
| 844 | hostapd_hw_mode_txt(iface->current_mode->mode)); |
| 845 | hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211, |
| 846 | HOSTAPD_LEVEL_WARNING, |
| 847 | "Hardware does not support configured channel"); |
| 848 | } |
| 849 | |
| 850 | |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 851 | int hostapd_acs_completed(struct hostapd_iface *iface, int err) |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 852 | { |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 853 | int ret = -1; |
| 854 | |
| 855 | if (err) |
| 856 | goto out; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 857 | |
| 858 | switch (hostapd_check_chans(iface)) { |
| 859 | case HOSTAPD_CHAN_VALID: |
| 860 | break; |
| 861 | case HOSTAPD_CHAN_ACS: |
| 862 | wpa_printf(MSG_ERROR, "ACS error - reported complete, but no result available"); |
| 863 | hostapd_notify_bad_chans(iface); |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 864 | goto out; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 865 | case HOSTAPD_CHAN_INVALID: |
| 866 | default: |
| 867 | wpa_printf(MSG_ERROR, "ACS picked unusable channels"); |
| 868 | hostapd_notify_bad_chans(iface); |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 869 | goto out; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | ret = hostapd_check_ht_capab(iface); |
| 873 | if (ret < 0) |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 874 | goto out; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 875 | if (ret == 1) { |
| 876 | wpa_printf(MSG_DEBUG, "Interface initialization will be completed in a callback"); |
| 877 | return 0; |
| 878 | } |
| 879 | |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 880 | ret = 0; |
| 881 | out: |
| 882 | return hostapd_setup_interface_complete(iface, ret); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 886 | /** |
| 887 | * hostapd_select_hw_mode - Select the hardware mode |
| 888 | * @iface: Pointer to interface data. |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 889 | * Returns: 0 on success, < 0 on failure |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 890 | * |
| 891 | * Sets up the hardware mode, channel, rates, and passive scanning |
| 892 | * based on the configuration. |
| 893 | */ |
| 894 | int hostapd_select_hw_mode(struct hostapd_iface *iface) |
| 895 | { |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 896 | int i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 897 | |
| 898 | if (iface->num_hw_features < 1) |
| 899 | return -1; |
| 900 | |
| 901 | iface->current_mode = NULL; |
| 902 | for (i = 0; i < iface->num_hw_features; i++) { |
| 903 | struct hostapd_hw_modes *mode = &iface->hw_features[i]; |
| 904 | if (mode->mode == iface->conf->hw_mode) { |
| 905 | iface->current_mode = mode; |
| 906 | break; |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | if (iface->current_mode == NULL) { |
| 911 | wpa_printf(MSG_ERROR, "Hardware does not support configured " |
| 912 | "mode"); |
| 913 | hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211, |
| 914 | HOSTAPD_LEVEL_WARNING, |
| 915 | "Hardware does not support configured mode " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 916 | "(%d) (hw_mode in hostapd.conf)", |
| 917 | (int) iface->conf->hw_mode); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 918 | return -2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 919 | } |
| 920 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 921 | switch (hostapd_check_chans(iface)) { |
| 922 | case HOSTAPD_CHAN_VALID: |
| 923 | return 0; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 924 | case HOSTAPD_CHAN_ACS: /* ACS will run and later complete */ |
| 925 | return 1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 926 | case HOSTAPD_CHAN_INVALID: |
| 927 | default: |
| 928 | hostapd_notify_bad_chans(iface); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 929 | return -3; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 930 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 931 | |
| 932 | return 0; |
| 933 | } |
| 934 | |
| 935 | |
| 936 | const char * hostapd_hw_mode_txt(int mode) |
| 937 | { |
| 938 | switch (mode) { |
| 939 | case HOSTAPD_MODE_IEEE80211A: |
| 940 | return "IEEE 802.11a"; |
| 941 | case HOSTAPD_MODE_IEEE80211B: |
| 942 | return "IEEE 802.11b"; |
| 943 | case HOSTAPD_MODE_IEEE80211G: |
| 944 | return "IEEE 802.11g"; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 945 | case HOSTAPD_MODE_IEEE80211AD: |
| 946 | return "IEEE 802.11ad"; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 947 | default: |
| 948 | return "UNKNOWN"; |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | |
| 953 | int hostapd_hw_get_freq(struct hostapd_data *hapd, int chan) |
| 954 | { |
| 955 | int i; |
| 956 | |
| 957 | if (!hapd->iface->current_mode) |
| 958 | return 0; |
| 959 | |
| 960 | for (i = 0; i < hapd->iface->current_mode->num_channels; i++) { |
| 961 | struct hostapd_channel_data *ch = |
| 962 | &hapd->iface->current_mode->channels[i]; |
| 963 | if (ch->chan == chan) |
| 964 | return ch->freq; |
| 965 | } |
| 966 | |
| 967 | return 0; |
| 968 | } |
| 969 | |
| 970 | |
| 971 | int hostapd_hw_get_channel(struct hostapd_data *hapd, int freq) |
| 972 | { |
| 973 | int i; |
| 974 | |
| 975 | if (!hapd->iface->current_mode) |
| 976 | return 0; |
| 977 | |
| 978 | for (i = 0; i < hapd->iface->current_mode->num_channels; i++) { |
| 979 | struct hostapd_channel_data *ch = |
| 980 | &hapd->iface->current_mode->channels[i]; |
| 981 | if (ch->freq == freq) |
| 982 | return ch->chan; |
| 983 | } |
| 984 | |
| 985 | return 0; |
| 986 | } |