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 | * |
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 | #include "utils/common.h" |
| 14 | #include "utils/eloop.h" |
| 15 | #include "common/ieee802_11_defs.h" |
| 16 | #include "common/ieee802_11_common.h" |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 17 | #include "common/wpa_ctrl.h" |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 18 | #include "common/hw_features_common.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 19 | #include "hostapd.h" |
| 20 | #include "ap_config.h" |
| 21 | #include "ap_drv_ops.h" |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 22 | #include "acs.h" |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 23 | #include "ieee802_11.h" |
| 24 | #include "beacon.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 25 | #include "hw_features.h" |
| 26 | |
| 27 | |
| 28 | void hostapd_free_hw_features(struct hostapd_hw_modes *hw_features, |
| 29 | size_t num_hw_features) |
| 30 | { |
| 31 | size_t i; |
| 32 | |
| 33 | if (hw_features == NULL) |
| 34 | return; |
| 35 | |
| 36 | for (i = 0; i < num_hw_features; i++) { |
| 37 | os_free(hw_features[i].channels); |
| 38 | os_free(hw_features[i].rates); |
| 39 | } |
| 40 | |
| 41 | os_free(hw_features); |
| 42 | } |
| 43 | |
| 44 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 45 | #ifndef CONFIG_NO_STDOUT_DEBUG |
| 46 | static char * dfs_info(struct hostapd_channel_data *chan) |
| 47 | { |
| 48 | static char info[256]; |
| 49 | char *state; |
| 50 | |
| 51 | switch (chan->flag & HOSTAPD_CHAN_DFS_MASK) { |
| 52 | case HOSTAPD_CHAN_DFS_UNKNOWN: |
| 53 | state = "unknown"; |
| 54 | break; |
| 55 | case HOSTAPD_CHAN_DFS_USABLE: |
| 56 | state = "usable"; |
| 57 | break; |
| 58 | case HOSTAPD_CHAN_DFS_UNAVAILABLE: |
| 59 | state = "unavailable"; |
| 60 | break; |
| 61 | case HOSTAPD_CHAN_DFS_AVAILABLE: |
| 62 | state = "available"; |
| 63 | break; |
| 64 | default: |
| 65 | return ""; |
| 66 | } |
| 67 | os_snprintf(info, sizeof(info), " (DFS state = %s)", state); |
| 68 | info[sizeof(info) - 1] = '\0'; |
| 69 | |
| 70 | return info; |
| 71 | } |
| 72 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
| 73 | |
| 74 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 75 | int hostapd_get_hw_features(struct hostapd_iface *iface) |
| 76 | { |
| 77 | struct hostapd_data *hapd = iface->bss[0]; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame^] | 78 | int i, j; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 79 | u16 num_modes, flags; |
| 80 | struct hostapd_hw_modes *modes; |
| 81 | |
| 82 | if (hostapd_drv_none(hapd)) |
| 83 | return -1; |
| 84 | modes = hostapd_get_hw_feature_data(hapd, &num_modes, &flags); |
| 85 | if (modes == NULL) { |
| 86 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, |
| 87 | HOSTAPD_LEVEL_DEBUG, |
| 88 | "Fetching hardware channel/rate support not " |
| 89 | "supported."); |
| 90 | return -1; |
| 91 | } |
| 92 | |
| 93 | iface->hw_flags = flags; |
| 94 | |
| 95 | hostapd_free_hw_features(iface->hw_features, iface->num_hw_features); |
| 96 | iface->hw_features = modes; |
| 97 | iface->num_hw_features = num_modes; |
| 98 | |
| 99 | for (i = 0; i < num_modes; i++) { |
| 100 | struct hostapd_hw_modes *feature = &modes[i]; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 101 | int dfs_enabled = hapd->iconf->ieee80211h && |
| 102 | (iface->drv_flags & WPA_DRIVER_FLAGS_RADAR); |
| 103 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 104 | /* set flag for channels we can use in current regulatory |
| 105 | * domain */ |
| 106 | for (j = 0; j < feature->num_channels; j++) { |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 107 | int dfs = 0; |
| 108 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 109 | /* |
| 110 | * Disable all channels that are marked not to allow |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 111 | * to initiate radiation (a.k.a. passive scan and no |
| 112 | * IBSS). |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 113 | * Use radar channels only if the driver supports DFS. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 114 | */ |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 115 | if ((feature->channels[j].flag & |
| 116 | HOSTAPD_CHAN_RADAR) && dfs_enabled) { |
| 117 | dfs = 1; |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 118 | } else if (((feature->channels[j].flag & |
| 119 | HOSTAPD_CHAN_RADAR) && |
| 120 | !(iface->drv_flags & |
| 121 | WPA_DRIVER_FLAGS_DFS_OFFLOAD)) || |
| 122 | (feature->channels[j].flag & |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 123 | HOSTAPD_CHAN_NO_IR)) { |
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 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame^] | 141 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 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 | { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 227 | int pri_chan, sec_chan; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 228 | |
| 229 | if (!iface->conf->secondary_channel) |
| 230 | return 1; /* HT40 not used */ |
| 231 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 232 | pri_chan = iface->conf->channel; |
| 233 | sec_chan = pri_chan + iface->conf->secondary_channel * 4; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 234 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 235 | return allowed_ht40_channel_pair(iface->current_mode, pri_chan, |
| 236 | sec_chan); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | |
| 240 | static void ieee80211n_switch_pri_sec(struct hostapd_iface *iface) |
| 241 | { |
| 242 | if (iface->conf->secondary_channel > 0) { |
| 243 | iface->conf->channel += 4; |
| 244 | iface->conf->secondary_channel = -1; |
| 245 | } else { |
| 246 | iface->conf->channel -= 4; |
| 247 | iface->conf->secondary_channel = 1; |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 252 | static int ieee80211n_check_40mhz_5g(struct hostapd_iface *iface, |
| 253 | struct wpa_scan_results *scan_res) |
| 254 | { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 255 | int pri_chan, sec_chan; |
| 256 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 257 | |
| 258 | pri_chan = iface->conf->channel; |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 259 | sec_chan = pri_chan + iface->conf->secondary_channel * 4; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 260 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 261 | res = check_40mhz_5g(iface->current_mode, scan_res, pri_chan, sec_chan); |
| 262 | |
| 263 | if (res == 2) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 264 | ieee80211n_switch_pri_sec(iface); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 265 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 266 | return !!res; |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 270 | static int ieee80211n_check_40mhz_2g4(struct hostapd_iface *iface, |
| 271 | struct wpa_scan_results *scan_res) |
| 272 | { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 273 | int pri_chan, sec_chan; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 274 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 275 | pri_chan = iface->conf->channel; |
| 276 | sec_chan = pri_chan + iface->conf->secondary_channel * 4; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 277 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 278 | return check_40mhz_2g4(iface->current_mode, scan_res, pri_chan, |
| 279 | sec_chan); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 283 | static void ieee80211n_check_scan(struct hostapd_iface *iface) |
| 284 | { |
| 285 | struct wpa_scan_results *scan_res; |
| 286 | int oper40; |
| 287 | int res; |
| 288 | |
| 289 | /* 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] | 290 | * allowed per IEEE Std 802.11-2012, 10.15.3.2 */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 291 | |
| 292 | iface->scan_cb = NULL; |
| 293 | |
| 294 | scan_res = hostapd_driver_get_scan_results(iface->bss[0]); |
| 295 | if (scan_res == NULL) { |
| 296 | hostapd_setup_interface_complete(iface, 1); |
| 297 | return; |
| 298 | } |
| 299 | |
| 300 | if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A) |
| 301 | oper40 = ieee80211n_check_40mhz_5g(iface, scan_res); |
| 302 | else |
| 303 | oper40 = ieee80211n_check_40mhz_2g4(iface, scan_res); |
| 304 | wpa_scan_results_free(scan_res); |
| 305 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 306 | iface->secondary_ch = iface->conf->secondary_channel; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 307 | if (!oper40) { |
| 308 | wpa_printf(MSG_INFO, "20/40 MHz operation not permitted on " |
| 309 | "channel pri=%d sec=%d based on overlapping BSSes", |
| 310 | iface->conf->channel, |
| 311 | iface->conf->channel + |
| 312 | iface->conf->secondary_channel * 4); |
| 313 | iface->conf->secondary_channel = 0; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 314 | if (iface->drv_flags & WPA_DRIVER_FLAGS_HT_2040_COEX) { |
| 315 | /* |
| 316 | * TODO: Could consider scheduling another scan to check |
| 317 | * if channel width can be changed if no coex reports |
| 318 | * are received from associating stations. |
| 319 | */ |
| 320 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | res = ieee80211n_allowed_ht40_channel_pair(iface); |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 324 | if (!res) { |
| 325 | iface->conf->secondary_channel = 0; |
| 326 | wpa_printf(MSG_INFO, "Fallback to 20 MHz"); |
| 327 | } |
| 328 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 329 | hostapd_setup_interface_complete(iface, !res); |
| 330 | } |
| 331 | |
| 332 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 333 | static void ieee80211n_scan_channels_2g4(struct hostapd_iface *iface, |
| 334 | struct wpa_driver_scan_params *params) |
| 335 | { |
| 336 | /* Scan only the affected frequency range */ |
| 337 | int pri_freq, sec_freq; |
| 338 | int affected_start, affected_end; |
| 339 | int i, pos; |
| 340 | struct hostapd_hw_modes *mode; |
| 341 | |
| 342 | if (iface->current_mode == NULL) |
| 343 | return; |
| 344 | |
| 345 | pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel); |
| 346 | if (iface->conf->secondary_channel > 0) |
| 347 | sec_freq = pri_freq + 20; |
| 348 | else |
| 349 | sec_freq = pri_freq - 20; |
| 350 | affected_start = (pri_freq + sec_freq) / 2 - 25; |
| 351 | affected_end = (pri_freq + sec_freq) / 2 + 25; |
| 352 | wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz", |
| 353 | affected_start, affected_end); |
| 354 | |
| 355 | mode = iface->current_mode; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 356 | params->freqs = os_calloc(mode->num_channels + 1, sizeof(int)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 357 | if (params->freqs == NULL) |
| 358 | return; |
| 359 | pos = 0; |
| 360 | |
| 361 | for (i = 0; i < mode->num_channels; i++) { |
| 362 | struct hostapd_channel_data *chan = &mode->channels[i]; |
| 363 | if (chan->flag & HOSTAPD_CHAN_DISABLED) |
| 364 | continue; |
| 365 | if (chan->freq < affected_start || |
| 366 | chan->freq > affected_end) |
| 367 | continue; |
| 368 | params->freqs[pos++] = chan->freq; |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 373 | static void ieee80211n_scan_channels_5g(struct hostapd_iface *iface, |
| 374 | struct wpa_driver_scan_params *params) |
| 375 | { |
| 376 | /* Scan only the affected frequency range */ |
| 377 | int pri_freq; |
| 378 | int affected_start, affected_end; |
| 379 | int i, pos; |
| 380 | struct hostapd_hw_modes *mode; |
| 381 | |
| 382 | if (iface->current_mode == NULL) |
| 383 | return; |
| 384 | |
| 385 | pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel); |
| 386 | if (iface->conf->secondary_channel > 0) { |
| 387 | affected_start = pri_freq - 10; |
| 388 | affected_end = pri_freq + 30; |
| 389 | } else { |
| 390 | affected_start = pri_freq - 30; |
| 391 | affected_end = pri_freq + 10; |
| 392 | } |
| 393 | wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz", |
| 394 | affected_start, affected_end); |
| 395 | |
| 396 | mode = iface->current_mode; |
| 397 | params->freqs = os_calloc(mode->num_channels + 1, sizeof(int)); |
| 398 | if (params->freqs == NULL) |
| 399 | return; |
| 400 | pos = 0; |
| 401 | |
| 402 | for (i = 0; i < mode->num_channels; i++) { |
| 403 | struct hostapd_channel_data *chan = &mode->channels[i]; |
| 404 | if (chan->flag & HOSTAPD_CHAN_DISABLED) |
| 405 | continue; |
| 406 | if (chan->freq < affected_start || |
| 407 | chan->freq > affected_end) |
| 408 | continue; |
| 409 | params->freqs[pos++] = chan->freq; |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 414 | static void ap_ht40_scan_retry(void *eloop_data, void *user_data) |
| 415 | { |
| 416 | #define HT2040_COEX_SCAN_RETRY 15 |
| 417 | struct hostapd_iface *iface = eloop_data; |
| 418 | struct wpa_driver_scan_params params; |
| 419 | int ret; |
| 420 | |
| 421 | os_memset(¶ms, 0, sizeof(params)); |
| 422 | if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G) |
| 423 | ieee80211n_scan_channels_2g4(iface, ¶ms); |
| 424 | else |
| 425 | ieee80211n_scan_channels_5g(iface, ¶ms); |
| 426 | |
| 427 | ret = hostapd_driver_scan(iface->bss[0], ¶ms); |
| 428 | iface->num_ht40_scan_tries++; |
| 429 | os_free(params.freqs); |
| 430 | |
| 431 | if (ret == -EBUSY && |
| 432 | iface->num_ht40_scan_tries < HT2040_COEX_SCAN_RETRY) { |
| 433 | wpa_printf(MSG_ERROR, |
| 434 | "Failed to request a scan of neighboring BSSes ret=%d (%s) - try to scan again (attempt %d)", |
| 435 | ret, strerror(-ret), iface->num_ht40_scan_tries); |
| 436 | eloop_register_timeout(1, 0, ap_ht40_scan_retry, iface, NULL); |
| 437 | return; |
| 438 | } |
| 439 | |
| 440 | if (ret == 0) { |
| 441 | iface->scan_cb = ieee80211n_check_scan; |
| 442 | return; |
| 443 | } |
| 444 | |
| 445 | wpa_printf(MSG_DEBUG, |
| 446 | "Failed to request a scan in device, bringing up in HT20 mode"); |
| 447 | iface->conf->secondary_channel = 0; |
| 448 | iface->conf->ht_capab &= ~HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET; |
| 449 | hostapd_setup_interface_complete(iface, 0); |
| 450 | } |
| 451 | |
| 452 | |
| 453 | void hostapd_stop_setup_timers(struct hostapd_iface *iface) |
| 454 | { |
| 455 | eloop_cancel_timeout(ap_ht40_scan_retry, iface, NULL); |
| 456 | } |
| 457 | |
| 458 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 459 | static int ieee80211n_check_40mhz(struct hostapd_iface *iface) |
| 460 | { |
| 461 | struct wpa_driver_scan_params params; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 462 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 463 | |
| 464 | if (!iface->conf->secondary_channel) |
| 465 | return 0; /* HT40 not used */ |
| 466 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 467 | hostapd_set_state(iface, HAPD_IFACE_HT_SCAN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 468 | wpa_printf(MSG_DEBUG, "Scan for neighboring BSSes prior to enabling " |
| 469 | "40 MHz channel"); |
| 470 | os_memset(¶ms, 0, sizeof(params)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 471 | if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G) |
| 472 | ieee80211n_scan_channels_2g4(iface, ¶ms); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 473 | else |
| 474 | ieee80211n_scan_channels_5g(iface, ¶ms); |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 475 | |
| 476 | ret = hostapd_driver_scan(iface->bss[0], ¶ms); |
| 477 | os_free(params.freqs); |
| 478 | |
| 479 | if (ret == -EBUSY) { |
| 480 | wpa_printf(MSG_ERROR, |
| 481 | "Failed to request a scan of neighboring BSSes ret=%d (%s) - try to scan again", |
| 482 | ret, strerror(-ret)); |
| 483 | iface->num_ht40_scan_tries = 1; |
| 484 | eloop_cancel_timeout(ap_ht40_scan_retry, iface, NULL); |
| 485 | eloop_register_timeout(1, 0, ap_ht40_scan_retry, iface, NULL); |
| 486 | return 1; |
| 487 | } |
| 488 | |
| 489 | if (ret < 0) { |
| 490 | wpa_printf(MSG_ERROR, |
| 491 | "Failed to request a scan of neighboring BSSes ret=%d (%s)", |
| 492 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 493 | return -1; |
| 494 | } |
| 495 | |
| 496 | iface->scan_cb = ieee80211n_check_scan; |
| 497 | return 1; |
| 498 | } |
| 499 | |
| 500 | |
| 501 | static int ieee80211n_supported_ht_capab(struct hostapd_iface *iface) |
| 502 | { |
| 503 | u16 hw = iface->current_mode->ht_capab; |
| 504 | u16 conf = iface->conf->ht_capab; |
| 505 | |
| 506 | if ((conf & HT_CAP_INFO_LDPC_CODING_CAP) && |
| 507 | !(hw & HT_CAP_INFO_LDPC_CODING_CAP)) { |
| 508 | wpa_printf(MSG_ERROR, "Driver does not support configured " |
| 509 | "HT capability [LDPC]"); |
| 510 | return 0; |
| 511 | } |
| 512 | |
| 513 | if ((conf & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) && |
| 514 | !(hw & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) { |
| 515 | wpa_printf(MSG_ERROR, "Driver does not support configured " |
| 516 | "HT capability [HT40*]"); |
| 517 | return 0; |
| 518 | } |
| 519 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 520 | switch (conf & HT_CAP_INFO_SMPS_MASK) { |
| 521 | case HT_CAP_INFO_SMPS_STATIC: |
| 522 | if (!(iface->smps_modes & WPA_DRIVER_SMPS_MODE_STATIC)) { |
| 523 | wpa_printf(MSG_ERROR, |
| 524 | "Driver does not support configured HT capability [SMPS-STATIC]"); |
| 525 | return 0; |
| 526 | } |
| 527 | break; |
| 528 | case HT_CAP_INFO_SMPS_DYNAMIC: |
| 529 | if (!(iface->smps_modes & WPA_DRIVER_SMPS_MODE_DYNAMIC)) { |
| 530 | wpa_printf(MSG_ERROR, |
| 531 | "Driver does not support configured HT capability [SMPS-DYNAMIC]"); |
| 532 | return 0; |
| 533 | } |
| 534 | break; |
| 535 | case HT_CAP_INFO_SMPS_DISABLED: |
| 536 | default: |
| 537 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | if ((conf & HT_CAP_INFO_GREEN_FIELD) && |
| 541 | !(hw & HT_CAP_INFO_GREEN_FIELD)) { |
| 542 | wpa_printf(MSG_ERROR, "Driver does not support configured " |
| 543 | "HT capability [GF]"); |
| 544 | return 0; |
| 545 | } |
| 546 | |
| 547 | if ((conf & HT_CAP_INFO_SHORT_GI20MHZ) && |
| 548 | !(hw & HT_CAP_INFO_SHORT_GI20MHZ)) { |
| 549 | wpa_printf(MSG_ERROR, "Driver does not support configured " |
| 550 | "HT capability [SHORT-GI-20]"); |
| 551 | return 0; |
| 552 | } |
| 553 | |
| 554 | if ((conf & HT_CAP_INFO_SHORT_GI40MHZ) && |
| 555 | !(hw & HT_CAP_INFO_SHORT_GI40MHZ)) { |
| 556 | wpa_printf(MSG_ERROR, "Driver does not support configured " |
| 557 | "HT capability [SHORT-GI-40]"); |
| 558 | return 0; |
| 559 | } |
| 560 | |
| 561 | if ((conf & HT_CAP_INFO_TX_STBC) && !(hw & HT_CAP_INFO_TX_STBC)) { |
| 562 | wpa_printf(MSG_ERROR, "Driver does not support configured " |
| 563 | "HT capability [TX-STBC]"); |
| 564 | return 0; |
| 565 | } |
| 566 | |
| 567 | if ((conf & HT_CAP_INFO_RX_STBC_MASK) > |
| 568 | (hw & HT_CAP_INFO_RX_STBC_MASK)) { |
| 569 | wpa_printf(MSG_ERROR, "Driver does not support configured " |
| 570 | "HT capability [RX-STBC*]"); |
| 571 | return 0; |
| 572 | } |
| 573 | |
| 574 | if ((conf & HT_CAP_INFO_DELAYED_BA) && |
| 575 | !(hw & HT_CAP_INFO_DELAYED_BA)) { |
| 576 | wpa_printf(MSG_ERROR, "Driver does not support configured " |
| 577 | "HT capability [DELAYED-BA]"); |
| 578 | return 0; |
| 579 | } |
| 580 | |
| 581 | if ((conf & HT_CAP_INFO_MAX_AMSDU_SIZE) && |
| 582 | !(hw & HT_CAP_INFO_MAX_AMSDU_SIZE)) { |
| 583 | wpa_printf(MSG_ERROR, "Driver does not support configured " |
| 584 | "HT capability [MAX-AMSDU-7935]"); |
| 585 | return 0; |
| 586 | } |
| 587 | |
| 588 | if ((conf & HT_CAP_INFO_DSSS_CCK40MHZ) && |
| 589 | !(hw & HT_CAP_INFO_DSSS_CCK40MHZ)) { |
| 590 | wpa_printf(MSG_ERROR, "Driver does not support configured " |
| 591 | "HT capability [DSSS_CCK-40]"); |
| 592 | return 0; |
| 593 | } |
| 594 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 595 | if ((conf & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT) && |
| 596 | !(hw & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT)) { |
| 597 | wpa_printf(MSG_ERROR, "Driver does not support configured " |
| 598 | "HT capability [LSIG-TXOP-PROT]"); |
| 599 | return 0; |
| 600 | } |
| 601 | |
| 602 | return 1; |
| 603 | } |
| 604 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 605 | |
| 606 | #ifdef CONFIG_IEEE80211AC |
| 607 | |
| 608 | static int ieee80211ac_cap_check(u32 hw, u32 conf, u32 cap, const char *name) |
| 609 | { |
| 610 | u32 req_cap = conf & cap; |
| 611 | |
| 612 | /* |
| 613 | * Make sure we support all requested capabilities. |
| 614 | * NOTE: We assume that 'cap' represents a capability mask, |
| 615 | * not a discrete value. |
| 616 | */ |
| 617 | if ((hw & req_cap) != req_cap) { |
| 618 | wpa_printf(MSG_ERROR, "Driver does not support configured VHT capability [%s]", |
| 619 | name); |
| 620 | return 0; |
| 621 | } |
| 622 | return 1; |
| 623 | } |
| 624 | |
| 625 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 626 | static int ieee80211ac_cap_check_max(u32 hw, u32 conf, u32 mask, |
| 627 | unsigned int shift, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 628 | const char *name) |
| 629 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 630 | u32 hw_max = hw & mask; |
| 631 | u32 conf_val = conf & mask; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 632 | |
| 633 | if (conf_val > hw_max) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 634 | wpa_printf(MSG_ERROR, "Configured VHT capability [%s] exceeds max value supported by the driver (%d > %d)", |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 635 | name, conf_val >> shift, hw_max >> shift); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 636 | return 0; |
| 637 | } |
| 638 | return 1; |
| 639 | } |
| 640 | |
| 641 | |
| 642 | static int ieee80211ac_supported_vht_capab(struct hostapd_iface *iface) |
| 643 | { |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame^] | 644 | struct hostapd_hw_modes *mode = iface->current_mode; |
| 645 | u32 hw = mode->vht_capab; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 646 | u32 conf = iface->conf->vht_capab; |
| 647 | |
| 648 | wpa_printf(MSG_DEBUG, "hw vht capab: 0x%x, conf vht capab: 0x%x", |
| 649 | hw, conf); |
| 650 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame^] | 651 | if (mode->mode == HOSTAPD_MODE_IEEE80211G && |
| 652 | iface->conf->bss[0]->vendor_vht && |
| 653 | mode->vht_capab == 0 && iface->hw_features) { |
| 654 | int i; |
| 655 | |
| 656 | for (i = 0; i < iface->num_hw_features; i++) { |
| 657 | if (iface->hw_features[i].mode == |
| 658 | HOSTAPD_MODE_IEEE80211A) { |
| 659 | mode = &iface->hw_features[i]; |
| 660 | hw = mode->vht_capab; |
| 661 | wpa_printf(MSG_DEBUG, |
| 662 | "update hw vht capab based on 5 GHz band: 0x%x", |
| 663 | hw); |
| 664 | break; |
| 665 | } |
| 666 | } |
| 667 | } |
| 668 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 669 | #define VHT_CAP_CHECK(cap) \ |
| 670 | do { \ |
| 671 | if (!ieee80211ac_cap_check(hw, conf, cap, #cap)) \ |
| 672 | return 0; \ |
| 673 | } while (0) |
| 674 | |
| 675 | #define VHT_CAP_CHECK_MAX(cap) \ |
| 676 | do { \ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 677 | if (!ieee80211ac_cap_check_max(hw, conf, cap, cap ## _SHIFT, \ |
| 678 | #cap)) \ |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 679 | return 0; \ |
| 680 | } while (0) |
| 681 | |
| 682 | VHT_CAP_CHECK_MAX(VHT_CAP_MAX_MPDU_LENGTH_MASK); |
| 683 | VHT_CAP_CHECK(VHT_CAP_SUPP_CHAN_WIDTH_160MHZ); |
| 684 | VHT_CAP_CHECK(VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ); |
| 685 | VHT_CAP_CHECK(VHT_CAP_RXLDPC); |
| 686 | VHT_CAP_CHECK(VHT_CAP_SHORT_GI_80); |
| 687 | VHT_CAP_CHECK(VHT_CAP_SHORT_GI_160); |
| 688 | VHT_CAP_CHECK(VHT_CAP_TXSTBC); |
| 689 | VHT_CAP_CHECK_MAX(VHT_CAP_RXSTBC_MASK); |
| 690 | VHT_CAP_CHECK(VHT_CAP_SU_BEAMFORMER_CAPABLE); |
| 691 | VHT_CAP_CHECK(VHT_CAP_SU_BEAMFORMEE_CAPABLE); |
| 692 | VHT_CAP_CHECK_MAX(VHT_CAP_BEAMFORMEE_STS_MAX); |
| 693 | VHT_CAP_CHECK_MAX(VHT_CAP_SOUNDING_DIMENSION_MAX); |
| 694 | VHT_CAP_CHECK(VHT_CAP_MU_BEAMFORMER_CAPABLE); |
| 695 | VHT_CAP_CHECK(VHT_CAP_MU_BEAMFORMEE_CAPABLE); |
| 696 | VHT_CAP_CHECK(VHT_CAP_VHT_TXOP_PS); |
| 697 | VHT_CAP_CHECK(VHT_CAP_HTC_VHT); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 698 | VHT_CAP_CHECK_MAX(VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 699 | VHT_CAP_CHECK(VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB); |
| 700 | VHT_CAP_CHECK(VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB); |
| 701 | VHT_CAP_CHECK(VHT_CAP_RX_ANTENNA_PATTERN); |
| 702 | VHT_CAP_CHECK(VHT_CAP_TX_ANTENNA_PATTERN); |
| 703 | |
| 704 | #undef VHT_CAP_CHECK |
| 705 | #undef VHT_CAP_CHECK_MAX |
| 706 | |
| 707 | return 1; |
| 708 | } |
| 709 | #endif /* CONFIG_IEEE80211AC */ |
| 710 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 711 | #endif /* CONFIG_IEEE80211N */ |
| 712 | |
| 713 | |
| 714 | int hostapd_check_ht_capab(struct hostapd_iface *iface) |
| 715 | { |
| 716 | #ifdef CONFIG_IEEE80211N |
| 717 | int ret; |
| 718 | if (!iface->conf->ieee80211n) |
| 719 | return 0; |
| 720 | if (!ieee80211n_supported_ht_capab(iface)) |
| 721 | return -1; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 722 | #ifdef CONFIG_IEEE80211AC |
| 723 | if (!ieee80211ac_supported_vht_capab(iface)) |
| 724 | return -1; |
| 725 | #endif /* CONFIG_IEEE80211AC */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 726 | ret = ieee80211n_check_40mhz(iface); |
| 727 | if (ret) |
| 728 | return ret; |
| 729 | if (!ieee80211n_allowed_ht40_channel_pair(iface)) |
| 730 | return -1; |
| 731 | #endif /* CONFIG_IEEE80211N */ |
| 732 | |
| 733 | return 0; |
| 734 | } |
| 735 | |
| 736 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 737 | static int hostapd_is_usable_chan(struct hostapd_iface *iface, |
| 738 | int channel, int primary) |
| 739 | { |
| 740 | int i; |
| 741 | struct hostapd_channel_data *chan; |
| 742 | |
| 743 | for (i = 0; i < iface->current_mode->num_channels; i++) { |
| 744 | chan = &iface->current_mode->channels[i]; |
| 745 | if (chan->chan != channel) |
| 746 | continue; |
| 747 | |
| 748 | if (!(chan->flag & HOSTAPD_CHAN_DISABLED)) |
| 749 | return 1; |
| 750 | |
| 751 | wpa_printf(MSG_DEBUG, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 752 | "%schannel [%i] (%i) is disabled for use in AP mode, flags: 0x%x%s%s", |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 753 | primary ? "" : "Configured HT40 secondary ", |
| 754 | i, chan->chan, chan->flag, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 755 | chan->flag & HOSTAPD_CHAN_NO_IR ? " NO-IR" : "", |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 756 | chan->flag & HOSTAPD_CHAN_RADAR ? " RADAR" : ""); |
| 757 | } |
| 758 | |
| 759 | return 0; |
| 760 | } |
| 761 | |
| 762 | |
| 763 | static int hostapd_is_usable_chans(struct hostapd_iface *iface) |
| 764 | { |
| 765 | if (!hostapd_is_usable_chan(iface, iface->conf->channel, 1)) |
| 766 | return 0; |
| 767 | |
| 768 | if (!iface->conf->secondary_channel) |
| 769 | return 1; |
| 770 | |
| 771 | return hostapd_is_usable_chan(iface, iface->conf->channel + |
| 772 | iface->conf->secondary_channel * 4, 0); |
| 773 | } |
| 774 | |
| 775 | |
| 776 | static enum hostapd_chan_status |
| 777 | hostapd_check_chans(struct hostapd_iface *iface) |
| 778 | { |
| 779 | if (iface->conf->channel) { |
| 780 | if (hostapd_is_usable_chans(iface)) |
| 781 | return HOSTAPD_CHAN_VALID; |
| 782 | else |
| 783 | return HOSTAPD_CHAN_INVALID; |
| 784 | } |
| 785 | |
| 786 | /* |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 787 | * The user set channel=0 or channel=acs_survey |
| 788 | * which is used to trigger ACS. |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 789 | */ |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 790 | |
| 791 | switch (acs_init(iface)) { |
| 792 | case HOSTAPD_CHAN_ACS: |
| 793 | return HOSTAPD_CHAN_ACS; |
| 794 | case HOSTAPD_CHAN_VALID: |
| 795 | case HOSTAPD_CHAN_INVALID: |
| 796 | default: |
| 797 | return HOSTAPD_CHAN_INVALID; |
| 798 | } |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | |
| 802 | static void hostapd_notify_bad_chans(struct hostapd_iface *iface) |
| 803 | { |
| 804 | hostapd_logger(iface->bss[0], NULL, |
| 805 | HOSTAPD_MODULE_IEEE80211, |
| 806 | HOSTAPD_LEVEL_WARNING, |
| 807 | "Configured channel (%d) not found from the " |
| 808 | "channel list of current mode (%d) %s", |
| 809 | iface->conf->channel, |
| 810 | iface->current_mode->mode, |
| 811 | hostapd_hw_mode_txt(iface->current_mode->mode)); |
| 812 | hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211, |
| 813 | HOSTAPD_LEVEL_WARNING, |
| 814 | "Hardware does not support configured channel"); |
| 815 | } |
| 816 | |
| 817 | |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 818 | int hostapd_acs_completed(struct hostapd_iface *iface, int err) |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 819 | { |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 820 | int ret = -1; |
| 821 | |
| 822 | if (err) |
| 823 | goto out; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 824 | |
| 825 | switch (hostapd_check_chans(iface)) { |
| 826 | case HOSTAPD_CHAN_VALID: |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 827 | wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, |
| 828 | ACS_EVENT_COMPLETED "freq=%d channel=%d", |
| 829 | hostapd_hw_get_freq(iface->bss[0], |
| 830 | iface->conf->channel), |
| 831 | iface->conf->channel); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 832 | break; |
| 833 | case HOSTAPD_CHAN_ACS: |
| 834 | wpa_printf(MSG_ERROR, "ACS error - reported complete, but no result available"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 835 | wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_FAILED); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 836 | hostapd_notify_bad_chans(iface); |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 837 | goto out; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 838 | case HOSTAPD_CHAN_INVALID: |
| 839 | default: |
| 840 | wpa_printf(MSG_ERROR, "ACS picked unusable channels"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 841 | wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_FAILED); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 842 | hostapd_notify_bad_chans(iface); |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 843 | goto out; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | ret = hostapd_check_ht_capab(iface); |
| 847 | if (ret < 0) |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 848 | goto out; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 849 | if (ret == 1) { |
| 850 | wpa_printf(MSG_DEBUG, "Interface initialization will be completed in a callback"); |
| 851 | return 0; |
| 852 | } |
| 853 | |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 854 | ret = 0; |
| 855 | out: |
| 856 | return hostapd_setup_interface_complete(iface, ret); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 860 | /** |
| 861 | * hostapd_select_hw_mode - Select the hardware mode |
| 862 | * @iface: Pointer to interface data. |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 863 | * Returns: 0 on success, < 0 on failure |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 864 | * |
| 865 | * Sets up the hardware mode, channel, rates, and passive scanning |
| 866 | * based on the configuration. |
| 867 | */ |
| 868 | int hostapd_select_hw_mode(struct hostapd_iface *iface) |
| 869 | { |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 870 | int i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 871 | |
| 872 | if (iface->num_hw_features < 1) |
| 873 | return -1; |
| 874 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 875 | if ((iface->conf->hw_mode == HOSTAPD_MODE_IEEE80211G || |
| 876 | iface->conf->ieee80211n || iface->conf->ieee80211ac) && |
| 877 | iface->conf->channel == 14) { |
| 878 | wpa_printf(MSG_INFO, "Disable OFDM/HT/VHT on channel 14"); |
| 879 | iface->conf->hw_mode = HOSTAPD_MODE_IEEE80211B; |
| 880 | iface->conf->ieee80211n = 0; |
| 881 | iface->conf->ieee80211ac = 0; |
| 882 | } |
| 883 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 884 | iface->current_mode = NULL; |
| 885 | for (i = 0; i < iface->num_hw_features; i++) { |
| 886 | struct hostapd_hw_modes *mode = &iface->hw_features[i]; |
| 887 | if (mode->mode == iface->conf->hw_mode) { |
| 888 | iface->current_mode = mode; |
| 889 | break; |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | if (iface->current_mode == NULL) { |
| 894 | wpa_printf(MSG_ERROR, "Hardware does not support configured " |
| 895 | "mode"); |
| 896 | hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211, |
| 897 | HOSTAPD_LEVEL_WARNING, |
| 898 | "Hardware does not support configured mode " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 899 | "(%d) (hw_mode in hostapd.conf)", |
| 900 | (int) iface->conf->hw_mode); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 901 | return -2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 902 | } |
| 903 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 904 | switch (hostapd_check_chans(iface)) { |
| 905 | case HOSTAPD_CHAN_VALID: |
| 906 | return 0; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 907 | case HOSTAPD_CHAN_ACS: /* ACS will run and later complete */ |
| 908 | return 1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 909 | case HOSTAPD_CHAN_INVALID: |
| 910 | default: |
| 911 | hostapd_notify_bad_chans(iface); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 912 | return -3; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 913 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | |
| 917 | const char * hostapd_hw_mode_txt(int mode) |
| 918 | { |
| 919 | switch (mode) { |
| 920 | case HOSTAPD_MODE_IEEE80211A: |
| 921 | return "IEEE 802.11a"; |
| 922 | case HOSTAPD_MODE_IEEE80211B: |
| 923 | return "IEEE 802.11b"; |
| 924 | case HOSTAPD_MODE_IEEE80211G: |
| 925 | return "IEEE 802.11g"; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 926 | case HOSTAPD_MODE_IEEE80211AD: |
| 927 | return "IEEE 802.11ad"; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 928 | default: |
| 929 | return "UNKNOWN"; |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | |
| 934 | int hostapd_hw_get_freq(struct hostapd_data *hapd, int chan) |
| 935 | { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 936 | return hw_get_freq(hapd->iface->current_mode, chan); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | |
| 940 | int hostapd_hw_get_channel(struct hostapd_data *hapd, int freq) |
| 941 | { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 942 | return hw_get_chan(hapd->iface->current_mode, freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 943 | } |