Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ACS - Automatic Channel Selection module |
| 3 | * Copyright (c) 2011, Atheros Communications |
| 4 | * Copyright (c) 2013, Qualcomm Atheros, Inc. |
| 5 | * |
| 6 | * This software may be distributed under the terms of the BSD license. |
| 7 | * See README for more details. |
| 8 | */ |
| 9 | |
| 10 | #include "utils/includes.h" |
| 11 | #include <math.h> |
| 12 | |
| 13 | #include "utils/common.h" |
| 14 | #include "utils/list.h" |
| 15 | #include "common/ieee802_11_defs.h" |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 16 | #include "common/hw_features_common.h" |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 17 | #include "common/wpa_ctrl.h" |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 18 | #include "drivers/driver.h" |
| 19 | #include "hostapd.h" |
| 20 | #include "ap_drv_ops.h" |
| 21 | #include "ap_config.h" |
| 22 | #include "hw_features.h" |
| 23 | #include "acs.h" |
| 24 | |
| 25 | /* |
| 26 | * Automatic Channel Selection |
| 27 | * =========================== |
| 28 | * |
| 29 | * More info at |
| 30 | * ------------ |
| 31 | * http://wireless.kernel.org/en/users/Documentation/acs |
| 32 | * |
| 33 | * How to use |
| 34 | * ---------- |
| 35 | * - make sure you have CONFIG_ACS=y in hostapd's .config |
| 36 | * - use channel=0 or channel=acs to enable ACS |
| 37 | * |
| 38 | * How does it work |
| 39 | * ---------------- |
| 40 | * 1. passive scans are used to collect survey data |
| 41 | * (it is assumed that scan trigger collection of survey data in driver) |
| 42 | * 2. interference factor is calculated for each channel |
| 43 | * 3. ideal channel is picked depending on channel width by using adjacent |
| 44 | * channel interference factors |
| 45 | * |
| 46 | * Known limitations |
| 47 | * ----------------- |
| 48 | * - Current implementation depends heavily on the amount of time willing to |
| 49 | * spend gathering survey data during hostapd startup. Short traffic bursts |
| 50 | * may be missed and a suboptimal channel may be picked. |
| 51 | * - Ideal channel may end up overlapping a channel with 40 MHz intolerant BSS |
| 52 | * |
| 53 | * Todo / Ideas |
| 54 | * ------------ |
| 55 | * - implement other interference computation methods |
| 56 | * - BSS/RSSI based |
| 57 | * - spectral scan based |
| 58 | * (should be possibly to hook this up with current ACS scans) |
| 59 | * - add wpa_supplicant support (for P2P) |
| 60 | * - collect a histogram of interference over time allowing more educated |
| 61 | * guess about an ideal channel (perhaps CSA could be used to migrate AP to a |
| 62 | * new "better" channel while running) |
| 63 | * - include neighboring BSS scan to avoid conflicts with 40 MHz intolerant BSSs |
| 64 | * when choosing the ideal channel |
| 65 | * |
| 66 | * Survey interference factor implementation details |
| 67 | * ------------------------------------------------- |
| 68 | * Generic interference_factor in struct hostapd_channel_data is used. |
| 69 | * |
| 70 | * The survey interference factor is defined as the ratio of the |
| 71 | * observed busy time over the time we spent on the channel, |
| 72 | * this value is then amplified by the observed noise floor on |
| 73 | * the channel in comparison to the lowest noise floor observed |
| 74 | * on the entire band. |
| 75 | * |
| 76 | * This corresponds to: |
| 77 | * --- |
| 78 | * (busy time - tx time) / (active time - tx time) * 2^(chan_nf + band_min_nf) |
| 79 | * --- |
| 80 | * |
| 81 | * The coefficient of 2 reflects the way power in "far-field" |
| 82 | * radiation decreases as the square of distance from the antenna [1]. |
| 83 | * What this does is it decreases the observed busy time ratio if the |
| 84 | * noise observed was low but increases it if the noise was high, |
| 85 | * proportionally to the way "far field" radiation changes over |
| 86 | * distance. |
| 87 | * |
| 88 | * If channel busy time is not available the fallback is to use channel RX time. |
| 89 | * |
| 90 | * Since noise floor is in dBm it is necessary to convert it into Watts so that |
| 91 | * combined channel interference (e.g., HT40, which uses two channels) can be |
| 92 | * calculated easily. |
| 93 | * --- |
| 94 | * (busy time - tx time) / (active time - tx time) * |
| 95 | * 2^(10^(chan_nf/10) + 10^(band_min_nf/10)) |
| 96 | * --- |
| 97 | * |
| 98 | * However to account for cases where busy/rx time is 0 (channel load is then |
| 99 | * 0%) channel noise floor signal power is combined into the equation so a |
| 100 | * channel with lower noise floor is preferred. The equation becomes: |
| 101 | * --- |
| 102 | * 10^(chan_nf/5) + (busy time - tx time) / (active time - tx time) * |
| 103 | * 2^(10^(chan_nf/10) + 10^(band_min_nf/10)) |
| 104 | * --- |
| 105 | * |
| 106 | * All this "interference factor" is purely subjective and only time |
| 107 | * will tell how usable this is. By using the minimum noise floor we |
| 108 | * remove any possible issues due to card calibration. The computation |
| 109 | * of the interference factor then is dependent on what the card itself |
| 110 | * picks up as the minimum noise, not an actual real possible card |
| 111 | * noise value. |
| 112 | * |
| 113 | * Total interference computation details |
| 114 | * -------------------------------------- |
| 115 | * The above channel interference factor is calculated with no respect to |
| 116 | * target operational bandwidth. |
| 117 | * |
| 118 | * To find an ideal channel the above data is combined by taking into account |
| 119 | * the target operational bandwidth and selected band. E.g., on 2.4 GHz channels |
| 120 | * overlap with 20 MHz bandwidth, but there is no overlap for 20 MHz bandwidth |
| 121 | * on 5 GHz. |
| 122 | * |
| 123 | * Each valid and possible channel spec (i.e., channel + width) is taken and its |
| 124 | * interference factor is computed by summing up interferences of each channel |
| 125 | * it overlaps. The one with least total interference is picked up. |
| 126 | * |
| 127 | * Note: This implies base channel interference factor must be non-negative |
| 128 | * allowing easy summing up. |
| 129 | * |
| 130 | * Example ACS analysis printout |
| 131 | * ----------------------------- |
| 132 | * |
| 133 | * ACS: Trying survey-based ACS |
| 134 | * ACS: Survey analysis for channel 1 (2412 MHz) |
| 135 | * ACS: 1: min_nf=-113 interference_factor=0.0802469 nf=-113 time=162 busy=0 rx=13 |
| 136 | * ACS: 2: min_nf=-113 interference_factor=0.0745342 nf=-113 time=161 busy=0 rx=12 |
| 137 | * ACS: 3: min_nf=-113 interference_factor=0.0679012 nf=-113 time=162 busy=0 rx=11 |
| 138 | * ACS: 4: min_nf=-113 interference_factor=0.0310559 nf=-113 time=161 busy=0 rx=5 |
| 139 | * ACS: 5: min_nf=-113 interference_factor=0.0248447 nf=-113 time=161 busy=0 rx=4 |
| 140 | * ACS: * interference factor average: 0.0557166 |
| 141 | * ACS: Survey analysis for channel 2 (2417 MHz) |
| 142 | * ACS: 1: min_nf=-113 interference_factor=0.0185185 nf=-113 time=162 busy=0 rx=3 |
| 143 | * ACS: 2: min_nf=-113 interference_factor=0.0246914 nf=-113 time=162 busy=0 rx=4 |
| 144 | * ACS: 3: min_nf=-113 interference_factor=0.037037 nf=-113 time=162 busy=0 rx=6 |
| 145 | * ACS: 4: min_nf=-113 interference_factor=0.149068 nf=-113 time=161 busy=0 rx=24 |
| 146 | * ACS: 5: min_nf=-113 interference_factor=0.0248447 nf=-113 time=161 busy=0 rx=4 |
| 147 | * ACS: * interference factor average: 0.050832 |
| 148 | * ACS: Survey analysis for channel 3 (2422 MHz) |
| 149 | * ACS: 1: min_nf=-113 interference_factor=2.51189e-23 nf=-113 time=162 busy=0 rx=0 |
| 150 | * ACS: 2: min_nf=-113 interference_factor=0.0185185 nf=-113 time=162 busy=0 rx=3 |
| 151 | * ACS: 3: min_nf=-113 interference_factor=0.0186335 nf=-113 time=161 busy=0 rx=3 |
| 152 | * ACS: 4: min_nf=-113 interference_factor=0.0186335 nf=-113 time=161 busy=0 rx=3 |
| 153 | * ACS: 5: min_nf=-113 interference_factor=0.0186335 nf=-113 time=161 busy=0 rx=3 |
| 154 | * ACS: * interference factor average: 0.0148838 |
| 155 | * ACS: Survey analysis for channel 4 (2427 MHz) |
| 156 | * ACS: 1: min_nf=-114 interference_factor=1.58489e-23 nf=-114 time=162 busy=0 rx=0 |
| 157 | * ACS: 2: min_nf=-114 interference_factor=0.0555556 nf=-114 time=162 busy=0 rx=9 |
| 158 | * ACS: 3: min_nf=-114 interference_factor=1.58489e-23 nf=-114 time=161 busy=0 rx=0 |
| 159 | * ACS: 4: min_nf=-114 interference_factor=0.0186335 nf=-114 time=161 busy=0 rx=3 |
| 160 | * ACS: 5: min_nf=-114 interference_factor=0.00621118 nf=-114 time=161 busy=0 rx=1 |
| 161 | * ACS: * interference factor average: 0.0160801 |
| 162 | * ACS: Survey analysis for channel 5 (2432 MHz) |
| 163 | * ACS: 1: min_nf=-114 interference_factor=0.409938 nf=-113 time=161 busy=0 rx=66 |
| 164 | * ACS: 2: min_nf=-114 interference_factor=0.0432099 nf=-113 time=162 busy=0 rx=7 |
| 165 | * ACS: 3: min_nf=-114 interference_factor=0.0124224 nf=-113 time=161 busy=0 rx=2 |
| 166 | * ACS: 4: min_nf=-114 interference_factor=0.677019 nf=-113 time=161 busy=0 rx=109 |
| 167 | * ACS: 5: min_nf=-114 interference_factor=0.0186335 nf=-114 time=161 busy=0 rx=3 |
| 168 | * ACS: * interference factor average: 0.232244 |
| 169 | * ACS: Survey analysis for channel 6 (2437 MHz) |
| 170 | * ACS: 1: min_nf=-113 interference_factor=0.552795 nf=-113 time=161 busy=0 rx=89 |
| 171 | * ACS: 2: min_nf=-113 interference_factor=0.0807453 nf=-112 time=161 busy=0 rx=13 |
| 172 | * ACS: 3: min_nf=-113 interference_factor=0.0310559 nf=-113 time=161 busy=0 rx=5 |
| 173 | * ACS: 4: min_nf=-113 interference_factor=0.434783 nf=-112 time=161 busy=0 rx=70 |
| 174 | * ACS: 5: min_nf=-113 interference_factor=0.0621118 nf=-113 time=161 busy=0 rx=10 |
| 175 | * ACS: * interference factor average: 0.232298 |
| 176 | * ACS: Survey analysis for channel 7 (2442 MHz) |
| 177 | * ACS: 1: min_nf=-113 interference_factor=0.440994 nf=-112 time=161 busy=0 rx=71 |
| 178 | * ACS: 2: min_nf=-113 interference_factor=0.385093 nf=-113 time=161 busy=0 rx=62 |
| 179 | * ACS: 3: min_nf=-113 interference_factor=0.0372671 nf=-113 time=161 busy=0 rx=6 |
| 180 | * ACS: 4: min_nf=-113 interference_factor=0.0372671 nf=-113 time=161 busy=0 rx=6 |
| 181 | * ACS: 5: min_nf=-113 interference_factor=0.0745342 nf=-113 time=161 busy=0 rx=12 |
| 182 | * ACS: * interference factor average: 0.195031 |
| 183 | * ACS: Survey analysis for channel 8 (2447 MHz) |
| 184 | * ACS: 1: min_nf=-114 interference_factor=0.0496894 nf=-112 time=161 busy=0 rx=8 |
| 185 | * ACS: 2: min_nf=-114 interference_factor=0.0496894 nf=-114 time=161 busy=0 rx=8 |
| 186 | * ACS: 3: min_nf=-114 interference_factor=0.0372671 nf=-113 time=161 busy=0 rx=6 |
| 187 | * ACS: 4: min_nf=-114 interference_factor=0.12963 nf=-113 time=162 busy=0 rx=21 |
| 188 | * ACS: 5: min_nf=-114 interference_factor=0.166667 nf=-114 time=162 busy=0 rx=27 |
| 189 | * ACS: * interference factor average: 0.0865885 |
| 190 | * ACS: Survey analysis for channel 9 (2452 MHz) |
| 191 | * ACS: 1: min_nf=-114 interference_factor=0.0124224 nf=-114 time=161 busy=0 rx=2 |
| 192 | * ACS: 2: min_nf=-114 interference_factor=0.0310559 nf=-114 time=161 busy=0 rx=5 |
| 193 | * ACS: 3: min_nf=-114 interference_factor=1.58489e-23 nf=-114 time=161 busy=0 rx=0 |
| 194 | * ACS: 4: min_nf=-114 interference_factor=0.00617284 nf=-114 time=162 busy=0 rx=1 |
| 195 | * ACS: 5: min_nf=-114 interference_factor=1.58489e-23 nf=-114 time=162 busy=0 rx=0 |
| 196 | * ACS: * interference factor average: 0.00993022 |
| 197 | * ACS: Survey analysis for channel 10 (2457 MHz) |
| 198 | * ACS: 1: min_nf=-114 interference_factor=0.00621118 nf=-114 time=161 busy=0 rx=1 |
| 199 | * ACS: 2: min_nf=-114 interference_factor=0.00621118 nf=-114 time=161 busy=0 rx=1 |
| 200 | * ACS: 3: min_nf=-114 interference_factor=0.00621118 nf=-114 time=161 busy=0 rx=1 |
| 201 | * ACS: 4: min_nf=-114 interference_factor=0.0493827 nf=-114 time=162 busy=0 rx=8 |
| 202 | * ACS: 5: min_nf=-114 interference_factor=1.58489e-23 nf=-114 time=162 busy=0 rx=0 |
| 203 | * ACS: * interference factor average: 0.0136033 |
| 204 | * ACS: Survey analysis for channel 11 (2462 MHz) |
| 205 | * ACS: 1: min_nf=-114 interference_factor=1.58489e-23 nf=-114 time=161 busy=0 rx=0 |
| 206 | * ACS: 2: min_nf=-114 interference_factor=2.51189e-23 nf=-113 time=161 busy=0 rx=0 |
| 207 | * ACS: 3: min_nf=-114 interference_factor=2.51189e-23 nf=-113 time=161 busy=0 rx=0 |
| 208 | * ACS: 4: min_nf=-114 interference_factor=0.0432099 nf=-114 time=162 busy=0 rx=7 |
| 209 | * ACS: 5: min_nf=-114 interference_factor=0.0925926 nf=-114 time=162 busy=0 rx=15 |
| 210 | * ACS: * interference factor average: 0.0271605 |
| 211 | * ACS: Survey analysis for channel 12 (2467 MHz) |
| 212 | * ACS: 1: min_nf=-114 interference_factor=0.0621118 nf=-113 time=161 busy=0 rx=10 |
| 213 | * ACS: 2: min_nf=-114 interference_factor=0.00621118 nf=-114 time=161 busy=0 rx=1 |
| 214 | * ACS: 3: min_nf=-114 interference_factor=2.51189e-23 nf=-113 time=162 busy=0 rx=0 |
| 215 | * ACS: 4: min_nf=-114 interference_factor=2.51189e-23 nf=-113 time=162 busy=0 rx=0 |
| 216 | * ACS: 5: min_nf=-114 interference_factor=0.00617284 nf=-113 time=162 busy=0 rx=1 |
| 217 | * ACS: * interference factor average: 0.0148992 |
| 218 | * ACS: Survey analysis for channel 13 (2472 MHz) |
| 219 | * ACS: 1: min_nf=-114 interference_factor=0.0745342 nf=-114 time=161 busy=0 rx=12 |
| 220 | * ACS: 2: min_nf=-114 interference_factor=0.0555556 nf=-114 time=162 busy=0 rx=9 |
| 221 | * ACS: 3: min_nf=-114 interference_factor=1.58489e-23 nf=-114 time=162 busy=0 rx=0 |
| 222 | * ACS: 4: min_nf=-114 interference_factor=1.58489e-23 nf=-114 time=162 busy=0 rx=0 |
| 223 | * ACS: 5: min_nf=-114 interference_factor=1.58489e-23 nf=-114 time=162 busy=0 rx=0 |
| 224 | * ACS: * interference factor average: 0.0260179 |
| 225 | * ACS: Survey analysis for selected bandwidth 20MHz |
| 226 | * ACS: * channel 1: total interference = 0.121432 |
| 227 | * ACS: * channel 2: total interference = 0.137512 |
| 228 | * ACS: * channel 3: total interference = 0.369757 |
| 229 | * ACS: * channel 4: total interference = 0.546338 |
| 230 | * ACS: * channel 5: total interference = 0.690538 |
| 231 | * ACS: * channel 6: total interference = 0.762242 |
| 232 | * ACS: * channel 7: total interference = 0.756092 |
| 233 | * ACS: * channel 8: total interference = 0.537451 |
| 234 | * ACS: * channel 9: total interference = 0.332313 |
| 235 | * ACS: * channel 10: total interference = 0.152182 |
| 236 | * ACS: * channel 11: total interference = 0.0916111 |
| 237 | * ACS: * channel 12: total interference = 0.0816809 |
| 238 | * ACS: * channel 13: total interference = 0.0680776 |
| 239 | * ACS: Ideal channel is 13 (2472 MHz) with total interference factor of 0.0680776 |
| 240 | * |
| 241 | * [1] http://en.wikipedia.org/wiki/Near_and_far_field |
| 242 | */ |
| 243 | |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 244 | enum bw_type { |
| 245 | ACS_BW40, |
| 246 | ACS_BW80, |
| 247 | ACS_BW160, |
| 248 | }; |
| 249 | |
| 250 | struct bw_item { |
| 251 | int first; |
| 252 | int last; |
| 253 | int center_chan; |
| 254 | }; |
| 255 | |
| 256 | static const struct bw_item bw_40[] = { |
| 257 | { 5180, 5200, 38 }, { 5220, 5240, 46 }, { 5260, 5280, 54 }, |
| 258 | { 5300, 5320, 62 }, { 5500, 5520, 102 }, { 5540, 5560, 110 }, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 259 | { 5580, 5600, 118 }, { 5620, 5640, 126 }, { 5660, 5680, 134 }, |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 260 | { 5700, 5720, 142 }, { 5745, 5765, 151 }, { 5785, 5805, 159 }, |
| 261 | { 5825, 5845, 167 }, { 5865, 5885, 175 }, |
| 262 | { 5955, 5975, 3 }, { 5995, 6015, 11 }, { 6035, 6055, 19 }, |
| 263 | { 6075, 6095, 27 }, { 6115, 6135, 35 }, { 6155, 6175, 43 }, |
| 264 | { 6195, 6215, 51 }, { 6235, 6255, 59 }, { 6275, 6295, 67 }, |
| 265 | { 6315, 6335, 75 }, { 6355, 6375, 83 }, { 6395, 6415, 91 }, |
| 266 | { 6435, 6455, 99 }, { 6475, 6495, 107 }, { 6515, 6535, 115 }, |
| 267 | { 6555, 6575, 123 }, { 6595, 6615, 131 }, { 6635, 6655, 139 }, |
| 268 | { 6675, 6695, 147 }, { 6715, 6735, 155 }, { 6755, 6775, 163 }, |
| 269 | { 6795, 6815, 171 }, { 6835, 6855, 179 }, { 6875, 6895, 187 }, |
| 270 | { 6915, 6935, 195 }, { 6955, 6975, 203 }, { 6995, 7015, 211 }, |
| 271 | { 7035, 7055, 219 }, { 7075, 7095, 227}, { -1, -1, -1 } |
| 272 | }; |
| 273 | static const struct bw_item bw_80[] = { |
| 274 | { 5180, 5240, 42 }, { 5260, 5320, 58 }, { 5500, 5560, 106 }, |
| 275 | { 5580, 5640, 122 }, { 5660, 5720, 138 }, { 5745, 5805, 155 }, |
| 276 | { 5825, 5885, 171}, |
| 277 | { 5955, 6015, 7 }, { 6035, 6095, 23 }, { 6115, 6175, 39 }, |
| 278 | { 6195, 6255, 55 }, { 6275, 6335, 71 }, { 6355, 6415, 87 }, |
| 279 | { 6435, 6495, 103 }, { 6515, 6575, 119 }, { 6595, 6655, 135 }, |
| 280 | { 6675, 6735, 151 }, { 6755, 6815, 167 }, { 6835, 6895, 183 }, |
| 281 | { 6915, 6975, 199 }, { 6995, 7055, 215 }, { -1, -1, -1 } |
| 282 | }; |
| 283 | static const struct bw_item bw_160[] = { |
| 284 | { 5180, 5320, 50 }, { 5500, 5640, 114 }, { 5745, 5885, 163 }, |
| 285 | { 5955, 6095, 15 }, { 6115, 6255, 47 }, { 6275, 6415, 79 }, |
| 286 | { 6435, 6575, 111 }, { 6595, 6735, 143 }, |
| 287 | { 6755, 6895, 175 }, { 6915, 7055, 207 }, { -1, -1, -1 } |
| 288 | }; |
| 289 | static const struct bw_item *bw_desc[] = { |
| 290 | [ACS_BW40] = bw_40, |
| 291 | [ACS_BW80] = bw_80, |
| 292 | [ACS_BW160] = bw_160, |
| 293 | }; |
| 294 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 295 | |
| 296 | static int acs_request_scan(struct hostapd_iface *iface); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 297 | static int acs_survey_is_sufficient(struct freq_survey *survey); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 298 | |
| 299 | |
| 300 | static void acs_clean_chan_surveys(struct hostapd_channel_data *chan) |
| 301 | { |
| 302 | struct freq_survey *survey, *tmp; |
| 303 | |
| 304 | if (dl_list_empty(&chan->survey_list)) |
| 305 | return; |
| 306 | |
| 307 | dl_list_for_each_safe(survey, tmp, &chan->survey_list, |
| 308 | struct freq_survey, list) { |
| 309 | dl_list_del(&survey->list); |
| 310 | os_free(survey); |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 315 | static void acs_cleanup_mode(struct hostapd_hw_modes *mode) |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 316 | { |
| 317 | int i; |
| 318 | struct hostapd_channel_data *chan; |
| 319 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 320 | for (i = 0; i < mode->num_channels; i++) { |
| 321 | chan = &mode->channels[i]; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 322 | |
| 323 | if (chan->flag & HOSTAPD_CHAN_SURVEY_LIST_INITIALIZED) |
| 324 | acs_clean_chan_surveys(chan); |
| 325 | |
| 326 | dl_list_init(&chan->survey_list); |
| 327 | chan->flag |= HOSTAPD_CHAN_SURVEY_LIST_INITIALIZED; |
| 328 | chan->min_nf = 0; |
Sunil Ravi | af8751c | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 329 | chan->punct_bitmap = 0; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 330 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | |
| 334 | void acs_cleanup(struct hostapd_iface *iface) |
| 335 | { |
| 336 | int i; |
| 337 | |
| 338 | for (i = 0; i < iface->num_hw_features; i++) |
| 339 | acs_cleanup_mode(&iface->hw_features[i]); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 340 | |
| 341 | iface->chans_surveyed = 0; |
| 342 | iface->acs_num_completed_scans = 0; |
| 343 | } |
| 344 | |
| 345 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 346 | static void acs_fail(struct hostapd_iface *iface) |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 347 | { |
| 348 | wpa_printf(MSG_ERROR, "ACS: Failed to start"); |
| 349 | acs_cleanup(iface); |
Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 350 | hostapd_disable_iface(iface); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | |
| 354 | static long double |
| 355 | acs_survey_interference_factor(struct freq_survey *survey, s8 min_nf) |
| 356 | { |
| 357 | long double factor, busy, total; |
| 358 | |
| 359 | if (survey->filled & SURVEY_HAS_CHAN_TIME_BUSY) |
| 360 | busy = survey->channel_time_busy; |
| 361 | else if (survey->filled & SURVEY_HAS_CHAN_TIME_RX) |
| 362 | busy = survey->channel_time_rx; |
| 363 | else { |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 364 | wpa_printf(MSG_ERROR, "ACS: Survey data missing"); |
| 365 | return 0; |
| 366 | } |
| 367 | |
| 368 | total = survey->channel_time; |
| 369 | |
| 370 | if (survey->filled & SURVEY_HAS_CHAN_TIME_TX) { |
| 371 | busy -= survey->channel_time_tx; |
| 372 | total -= survey->channel_time_tx; |
| 373 | } |
| 374 | |
| 375 | /* TODO: figure out the best multiplier for noise floor base */ |
| 376 | factor = pow(10, survey->nf / 5.0L) + |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 377 | (total ? (busy / total) : 0) * |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 378 | pow(2, pow(10, (long double) survey->nf / 10.0L) - |
| 379 | pow(10, (long double) min_nf / 10.0L)); |
| 380 | |
| 381 | return factor; |
| 382 | } |
| 383 | |
| 384 | |
| 385 | static void |
| 386 | acs_survey_chan_interference_factor(struct hostapd_iface *iface, |
| 387 | struct hostapd_channel_data *chan) |
| 388 | { |
| 389 | struct freq_survey *survey; |
| 390 | unsigned int i = 0; |
| 391 | long double int_factor = 0; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 392 | unsigned count = 0; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 393 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 394 | if (dl_list_empty(&chan->survey_list) || |
| 395 | (chan->flag & HOSTAPD_CHAN_DISABLED)) |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 396 | return; |
| 397 | |
| 398 | chan->interference_factor = 0; |
| 399 | |
| 400 | dl_list_for_each(survey, &chan->survey_list, struct freq_survey, list) |
| 401 | { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 402 | i++; |
| 403 | |
| 404 | if (!acs_survey_is_sufficient(survey)) { |
| 405 | wpa_printf(MSG_DEBUG, "ACS: %d: insufficient data", i); |
| 406 | continue; |
| 407 | } |
| 408 | |
| 409 | count++; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 410 | int_factor = acs_survey_interference_factor(survey, |
| 411 | iface->lowest_nf); |
| 412 | chan->interference_factor += int_factor; |
| 413 | wpa_printf(MSG_DEBUG, "ACS: %d: min_nf=%d interference_factor=%Lg nf=%d time=%lu busy=%lu rx=%lu", |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 414 | i, chan->min_nf, int_factor, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 415 | survey->nf, (unsigned long) survey->channel_time, |
| 416 | (unsigned long) survey->channel_time_busy, |
| 417 | (unsigned long) survey->channel_time_rx); |
| 418 | } |
| 419 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 420 | if (count) |
| 421 | chan->interference_factor /= count; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 425 | static bool acs_usable_bw_chan(const struct hostapd_channel_data *chan, |
| 426 | enum bw_type bw) |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 427 | { |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 428 | unsigned int i = 0; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 429 | |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 430 | while (bw_desc[bw][i].first != -1) { |
| 431 | if (chan->freq == bw_desc[bw][i].first) |
| 432 | return true; |
| 433 | i++; |
| 434 | } |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 435 | |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 436 | return false; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 440 | static int acs_get_bw_center_chan(int freq, enum bw_type bw) |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 441 | { |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 442 | unsigned int i = 0; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 443 | |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 444 | while (bw_desc[bw][i].first != -1) { |
| 445 | if (freq >= bw_desc[bw][i].first && |
| 446 | freq <= bw_desc[bw][i].last) |
| 447 | return bw_desc[bw][i].center_chan; |
| 448 | i++; |
| 449 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 450 | |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 455 | static int acs_survey_is_sufficient(struct freq_survey *survey) |
| 456 | { |
| 457 | if (!(survey->filled & SURVEY_HAS_NF)) { |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 458 | wpa_printf(MSG_INFO, |
| 459 | "ACS: Survey for freq %d is missing noise floor", |
| 460 | survey->freq); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 461 | return 0; |
| 462 | } |
| 463 | |
| 464 | if (!(survey->filled & SURVEY_HAS_CHAN_TIME)) { |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 465 | wpa_printf(MSG_INFO, |
| 466 | "ACS: Survey for freq %d is missing channel time", |
| 467 | survey->freq); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | if (!(survey->filled & SURVEY_HAS_CHAN_TIME_BUSY) && |
| 472 | !(survey->filled & SURVEY_HAS_CHAN_TIME_RX)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 473 | wpa_printf(MSG_INFO, |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 474 | "ACS: Survey for freq %d is missing RX and busy time (at least one is required)", |
| 475 | survey->freq); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | return 1; |
| 480 | } |
| 481 | |
| 482 | |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 483 | static int acs_survey_list_is_sufficient(struct hostapd_channel_data *chan) |
| 484 | { |
| 485 | struct freq_survey *survey; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 486 | int ret = -1; |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 487 | |
| 488 | dl_list_for_each(survey, &chan->survey_list, struct freq_survey, list) |
| 489 | { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 490 | if (acs_survey_is_sufficient(survey)) { |
| 491 | ret = 1; |
| 492 | break; |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 493 | } |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 494 | ret = 0; |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 497 | if (ret == -1) |
| 498 | ret = 1; /* no survey list entries */ |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 499 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 500 | if (!ret) { |
| 501 | wpa_printf(MSG_INFO, |
| 502 | "ACS: Channel %d has insufficient survey data", |
| 503 | chan->chan); |
| 504 | } |
| 505 | |
| 506 | return ret; |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 510 | static int acs_surveys_are_sufficient_mode(struct hostapd_hw_modes *mode) |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 511 | { |
| 512 | int i; |
| 513 | struct hostapd_channel_data *chan; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 514 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 515 | for (i = 0; i < mode->num_channels; i++) { |
| 516 | chan = &mode->channels[i]; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 517 | if (!(chan->flag & HOSTAPD_CHAN_DISABLED) && |
| 518 | acs_survey_list_is_sufficient(chan)) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 519 | return 1; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 522 | return 0; |
| 523 | } |
| 524 | |
| 525 | |
| 526 | static int acs_surveys_are_sufficient(struct hostapd_iface *iface) |
| 527 | { |
| 528 | int i; |
| 529 | struct hostapd_hw_modes *mode; |
| 530 | |
| 531 | for (i = 0; i < iface->num_hw_features; i++) { |
| 532 | mode = &iface->hw_features[i]; |
| 533 | if (!hostapd_hw_skip_mode(iface, mode) && |
| 534 | acs_surveys_are_sufficient_mode(mode)) |
| 535 | return 1; |
| 536 | } |
| 537 | |
| 538 | return 0; |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | |
| 542 | static int acs_usable_chan(struct hostapd_channel_data *chan) |
| 543 | { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 544 | return !dl_list_empty(&chan->survey_list) && |
| 545 | !(chan->flag & HOSTAPD_CHAN_DISABLED) && |
| 546 | acs_survey_list_is_sufficient(chan); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 550 | static int is_in_chanlist(struct hostapd_iface *iface, |
| 551 | struct hostapd_channel_data *chan) |
| 552 | { |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 553 | if (!iface->conf->acs_ch_list.num) |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 554 | return 1; |
| 555 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 556 | return freq_range_list_includes(&iface->conf->acs_ch_list, chan->chan); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 560 | static int is_in_freqlist(struct hostapd_iface *iface, |
| 561 | struct hostapd_channel_data *chan) |
| 562 | { |
| 563 | if (!iface->conf->acs_freq_list.num) |
| 564 | return 1; |
| 565 | |
| 566 | return freq_range_list_includes(&iface->conf->acs_freq_list, |
| 567 | chan->freq); |
| 568 | } |
| 569 | |
| 570 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 571 | static void acs_survey_mode_interference_factor( |
| 572 | struct hostapd_iface *iface, struct hostapd_hw_modes *mode) |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 573 | { |
| 574 | int i; |
| 575 | struct hostapd_channel_data *chan; |
| 576 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 577 | for (i = 0; i < mode->num_channels; i++) { |
| 578 | chan = &mode->channels[i]; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 579 | |
| 580 | if (!acs_usable_chan(chan)) |
| 581 | continue; |
| 582 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 583 | if ((chan->flag & HOSTAPD_CHAN_RADAR) && |
| 584 | iface->conf->acs_exclude_dfs) |
| 585 | continue; |
| 586 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 587 | if (!is_in_chanlist(iface, chan)) |
| 588 | continue; |
| 589 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 590 | if (!is_in_freqlist(iface, chan)) |
| 591 | continue; |
| 592 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 593 | if (chan->max_tx_power < iface->conf->min_tx_power) |
| 594 | continue; |
| 595 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 596 | if ((chan->flag & HOSTAPD_CHAN_INDOOR_ONLY) && |
| 597 | iface->conf->country[2] == 0x4f) |
| 598 | continue; |
| 599 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 600 | wpa_printf(MSG_DEBUG, "ACS: Survey analysis for channel %d (%d MHz)", |
| 601 | chan->chan, chan->freq); |
| 602 | |
| 603 | acs_survey_chan_interference_factor(iface, chan); |
| 604 | |
| 605 | wpa_printf(MSG_DEBUG, "ACS: * interference factor average: %Lg", |
| 606 | chan->interference_factor); |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 611 | static void acs_survey_all_chans_interference_factor( |
| 612 | struct hostapd_iface *iface) |
| 613 | { |
| 614 | int i; |
| 615 | struct hostapd_hw_modes *mode; |
| 616 | |
| 617 | for (i = 0; i < iface->num_hw_features; i++) { |
| 618 | mode = &iface->hw_features[i]; |
| 619 | if (!hostapd_hw_skip_mode(iface, mode)) |
| 620 | acs_survey_mode_interference_factor(iface, mode); |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | |
| 625 | static struct hostapd_channel_data * |
| 626 | acs_find_chan_mode(struct hostapd_hw_modes *mode, int freq) |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 627 | { |
| 628 | struct hostapd_channel_data *chan; |
| 629 | int i; |
| 630 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 631 | for (i = 0; i < mode->num_channels; i++) { |
| 632 | chan = &mode->channels[i]; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 633 | |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 634 | if (chan->flag & HOSTAPD_CHAN_DISABLED) |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 635 | continue; |
| 636 | |
| 637 | if (chan->freq == freq) |
| 638 | return chan; |
| 639 | } |
| 640 | |
| 641 | return NULL; |
| 642 | } |
| 643 | |
| 644 | |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 645 | static enum hostapd_hw_mode |
| 646 | acs_find_mode(struct hostapd_iface *iface, int freq) |
| 647 | { |
| 648 | int i; |
| 649 | struct hostapd_hw_modes *mode; |
| 650 | struct hostapd_channel_data *chan; |
| 651 | |
| 652 | for (i = 0; i < iface->num_hw_features; i++) { |
| 653 | mode = &iface->hw_features[i]; |
| 654 | if (!hostapd_hw_skip_mode(iface, mode)) { |
| 655 | chan = acs_find_chan_mode(mode, freq); |
| 656 | if (chan) |
| 657 | return mode->mode; |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | return HOSTAPD_MODE_IEEE80211ANY; |
| 662 | } |
| 663 | |
| 664 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 665 | static struct hostapd_channel_data * |
| 666 | acs_find_chan(struct hostapd_iface *iface, int freq) |
| 667 | { |
| 668 | int i; |
| 669 | struct hostapd_hw_modes *mode; |
| 670 | struct hostapd_channel_data *chan; |
| 671 | |
| 672 | for (i = 0; i < iface->num_hw_features; i++) { |
| 673 | mode = &iface->hw_features[i]; |
| 674 | if (!hostapd_hw_skip_mode(iface, mode)) { |
| 675 | chan = acs_find_chan_mode(mode, freq); |
| 676 | if (chan) |
| 677 | return chan; |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | return NULL; |
| 682 | } |
| 683 | |
| 684 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 685 | static int is_24ghz_mode(enum hostapd_hw_mode mode) |
| 686 | { |
| 687 | return mode == HOSTAPD_MODE_IEEE80211B || |
| 688 | mode == HOSTAPD_MODE_IEEE80211G; |
| 689 | } |
| 690 | |
| 691 | |
| 692 | static int is_common_24ghz_chan(int chan) |
| 693 | { |
| 694 | return chan == 1 || chan == 6 || chan == 11; |
| 695 | } |
| 696 | |
| 697 | |
| 698 | #ifndef ACS_ADJ_WEIGHT |
| 699 | #define ACS_ADJ_WEIGHT 0.85 |
| 700 | #endif /* ACS_ADJ_WEIGHT */ |
| 701 | |
| 702 | #ifndef ACS_NEXT_ADJ_WEIGHT |
| 703 | #define ACS_NEXT_ADJ_WEIGHT 0.55 |
| 704 | #endif /* ACS_NEXT_ADJ_WEIGHT */ |
| 705 | |
| 706 | #ifndef ACS_24GHZ_PREFER_1_6_11 |
| 707 | /* |
| 708 | * Select commonly used channels 1, 6, 11 by default even if a neighboring |
| 709 | * channel has a smaller interference factor as long as it is not better by more |
| 710 | * than this multiplier. |
| 711 | */ |
| 712 | #define ACS_24GHZ_PREFER_1_6_11 0.8 |
| 713 | #endif /* ACS_24GHZ_PREFER_1_6_11 */ |
| 714 | |
Sunil Ravi | af8751c | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 715 | |
| 716 | #ifdef CONFIG_IEEE80211BE |
| 717 | static void acs_update_puncturing_bitmap(struct hostapd_iface *iface, |
| 718 | struct hostapd_hw_modes *mode, u32 bw, |
| 719 | int n_chans, |
| 720 | struct hostapd_channel_data *chan, |
| 721 | long double factor, |
| 722 | int index_primary) |
| 723 | { |
| 724 | struct hostapd_config *conf = iface->conf; |
| 725 | struct hostapd_channel_data *adj_chan = NULL, *first_chan = chan; |
| 726 | int i; |
| 727 | long double threshold; |
| 728 | |
| 729 | /* |
| 730 | * If threshold is 0 or user configured puncturing pattern is |
| 731 | * available then don't add additional puncturing. |
| 732 | */ |
| 733 | if (!conf->punct_acs_threshold || conf->punct_bitmap) |
| 734 | return; |
| 735 | |
| 736 | if (is_24ghz_mode(mode->mode) || bw < 80) |
| 737 | return; |
| 738 | |
| 739 | threshold = factor * conf->punct_acs_threshold / 100; |
| 740 | for (i = 0; i < n_chans; i++) { |
| 741 | int adj_freq; |
| 742 | |
| 743 | if (i == index_primary) |
| 744 | continue; /* Cannot puncture primary channel */ |
| 745 | |
| 746 | if (i > index_primary) |
| 747 | adj_freq = chan->freq + (i - index_primary) * 20; |
| 748 | else |
| 749 | adj_freq = chan->freq - (index_primary - i) * 20; |
| 750 | |
| 751 | adj_chan = acs_find_chan(iface, adj_freq); |
| 752 | if (!adj_chan) { |
| 753 | chan->punct_bitmap = 0; |
| 754 | return; |
| 755 | } |
| 756 | |
| 757 | if (i == 0) |
| 758 | first_chan = adj_chan; |
| 759 | |
| 760 | if (adj_chan->interference_factor > threshold) |
| 761 | chan->punct_bitmap |= BIT(i); |
| 762 | } |
| 763 | |
| 764 | if (!is_punct_bitmap_valid(bw, (chan->freq - first_chan->freq) / 20, |
| 765 | chan->punct_bitmap)) |
| 766 | chan->punct_bitmap = 0; |
| 767 | } |
| 768 | #endif /* CONFIG_IEEE80211BE */ |
| 769 | |
| 770 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 771 | static void |
| 772 | acs_find_ideal_chan_mode(struct hostapd_iface *iface, |
| 773 | struct hostapd_hw_modes *mode, |
| 774 | int n_chans, u32 bw, |
| 775 | struct hostapd_channel_data **rand_chan, |
| 776 | struct hostapd_channel_data **ideal_chan, |
| 777 | long double *ideal_factor) |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 778 | { |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 779 | struct hostapd_channel_data *chan, *adj_chan = NULL, *best; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 780 | long double factor; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 781 | int i, j; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 782 | unsigned int k; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 783 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 784 | for (i = 0; i < mode->num_channels; i++) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 785 | double total_weight; |
| 786 | struct acs_bias *bias, tmp_bias; |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 787 | bool update_best = true; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 788 | |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 789 | best = chan = &mode->channels[i]; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 790 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 791 | /* Since in the current ACS implementation the first channel is |
| 792 | * always a primary channel, skip channels not available as |
| 793 | * primary until more sophisticated channel selection is |
Sunil Ravi | af8751c | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 794 | * implemented. |
| 795 | * |
| 796 | * If this implementation is changed to allow any channel in |
| 797 | * the bandwidth to be the primary one, the last parameter to |
| 798 | * acs_update_puncturing_bitmap() should be changed to the index |
| 799 | * of the primary channel |
| 800 | */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 801 | if (!chan_pri_allowed(chan)) |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 802 | continue; |
| 803 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 804 | if ((chan->flag & HOSTAPD_CHAN_RADAR) && |
| 805 | iface->conf->acs_exclude_dfs) |
| 806 | continue; |
| 807 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 808 | if (!is_in_chanlist(iface, chan)) |
| 809 | continue; |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 810 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 811 | if (!is_in_freqlist(iface, chan)) |
| 812 | continue; |
| 813 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 814 | if (chan->max_tx_power < iface->conf->min_tx_power) |
| 815 | continue; |
| 816 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 817 | if ((chan->flag & HOSTAPD_CHAN_INDOOR_ONLY) && |
| 818 | iface->conf->country[2] == 0x4f) |
| 819 | continue; |
| 820 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 821 | if (!chan_bw_allowed(chan, bw, 1, 1)) { |
| 822 | wpa_printf(MSG_DEBUG, |
| 823 | "ACS: Channel %d: BW %u is not supported", |
| 824 | chan->chan, bw); |
| 825 | continue; |
| 826 | } |
| 827 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 828 | /* HT40 on 5 GHz has a limited set of primary channels as per |
| 829 | * 11n Annex J */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 830 | if (mode->mode == HOSTAPD_MODE_IEEE80211A && |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 831 | ((iface->conf->ieee80211n && |
| 832 | iface->conf->secondary_channel) || |
| 833 | is_6ghz_freq(chan->freq)) && |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 834 | !acs_usable_bw_chan(chan, ACS_BW40)) { |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 835 | wpa_printf(MSG_DEBUG, |
| 836 | "ACS: Channel %d: not allowed as primary channel for 40 MHz bandwidth", |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 837 | chan->chan); |
| 838 | continue; |
| 839 | } |
| 840 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 841 | if (mode->mode == HOSTAPD_MODE_IEEE80211A && |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 842 | (iface->conf->ieee80211ac || iface->conf->ieee80211ax)) { |
| 843 | if (hostapd_get_oper_chwidth(iface->conf) == |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 844 | CONF_OPER_CHWIDTH_80MHZ && |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 845 | !acs_usable_bw_chan(chan, ACS_BW80)) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 846 | wpa_printf(MSG_DEBUG, |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 847 | "ACS: Channel %d: not allowed as primary channel for 80 MHz bandwidth", |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 848 | chan->chan); |
| 849 | continue; |
| 850 | } |
| 851 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 852 | if (hostapd_get_oper_chwidth(iface->conf) == |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 853 | CONF_OPER_CHWIDTH_160MHZ && |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 854 | !acs_usable_bw_chan(chan, ACS_BW160)) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 855 | wpa_printf(MSG_DEBUG, |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 856 | "ACS: Channel %d: not allowed as primary channel for 160 MHz bandwidth", |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 857 | chan->chan); |
| 858 | continue; |
| 859 | } |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 860 | } |
| 861 | |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 862 | factor = 0; |
| 863 | if (acs_usable_chan(chan)) |
| 864 | factor = chan->interference_factor; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 865 | total_weight = 1; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 866 | |
| 867 | for (j = 1; j < n_chans; j++) { |
| 868 | adj_chan = acs_find_chan(iface, chan->freq + (j * 20)); |
| 869 | if (!adj_chan) |
| 870 | break; |
| 871 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 872 | if (!chan_bw_allowed(adj_chan, bw, 1, 0)) { |
| 873 | wpa_printf(MSG_DEBUG, |
| 874 | "ACS: PRI Channel %d: secondary channel %d BW %u is not supported", |
| 875 | chan->chan, adj_chan->chan, bw); |
| 876 | break; |
| 877 | } |
| 878 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 879 | if (acs_usable_chan(adj_chan)) { |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 880 | factor += adj_chan->interference_factor; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 881 | total_weight += 1; |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 882 | } else { |
| 883 | update_best = false; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 884 | } |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 885 | |
| 886 | /* find the best channel in this segment */ |
| 887 | if (update_best && |
| 888 | adj_chan->interference_factor < |
| 889 | best->interference_factor) |
| 890 | best = adj_chan; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | if (j != n_chans) { |
| 894 | wpa_printf(MSG_DEBUG, "ACS: Channel %d: not enough bandwidth", |
| 895 | chan->chan); |
| 896 | continue; |
| 897 | } |
| 898 | |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 899 | /* If the AP is in the 5 GHz or 6 GHz band, lets prefer a less |
| 900 | * crowded primary channel if one was found in the segment */ |
| 901 | if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A && |
| 902 | chan != best) { |
| 903 | wpa_printf(MSG_DEBUG, |
| 904 | "ACS: promoting channel %d over %d (less interference %Lg/%Lg)", |
| 905 | best->chan, chan->chan, |
| 906 | chan->interference_factor, |
| 907 | best->interference_factor); |
| 908 | chan = best; |
| 909 | } |
| 910 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 911 | /* 2.4 GHz has overlapping 20 MHz channels. Include adjacent |
| 912 | * channel interference factor. */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 913 | if (is_24ghz_mode(mode->mode)) { |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 914 | for (j = 0; j < n_chans; j++) { |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 915 | adj_chan = acs_find_chan(iface, chan->freq + |
| 916 | (j * 20) - 5); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 917 | if (adj_chan && acs_usable_chan(adj_chan)) { |
| 918 | factor += ACS_ADJ_WEIGHT * |
| 919 | adj_chan->interference_factor; |
| 920 | total_weight += ACS_ADJ_WEIGHT; |
| 921 | } |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 922 | |
| 923 | adj_chan = acs_find_chan(iface, chan->freq + |
| 924 | (j * 20) - 10); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 925 | if (adj_chan && acs_usable_chan(adj_chan)) { |
| 926 | factor += ACS_NEXT_ADJ_WEIGHT * |
| 927 | adj_chan->interference_factor; |
| 928 | total_weight += ACS_NEXT_ADJ_WEIGHT; |
| 929 | } |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 930 | |
| 931 | adj_chan = acs_find_chan(iface, chan->freq + |
| 932 | (j * 20) + 5); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 933 | if (adj_chan && acs_usable_chan(adj_chan)) { |
| 934 | factor += ACS_ADJ_WEIGHT * |
| 935 | adj_chan->interference_factor; |
| 936 | total_weight += ACS_ADJ_WEIGHT; |
| 937 | } |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 938 | |
| 939 | adj_chan = acs_find_chan(iface, chan->freq + |
| 940 | (j * 20) + 10); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 941 | if (adj_chan && acs_usable_chan(adj_chan)) { |
| 942 | factor += ACS_NEXT_ADJ_WEIGHT * |
| 943 | adj_chan->interference_factor; |
| 944 | total_weight += ACS_NEXT_ADJ_WEIGHT; |
| 945 | } |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 946 | } |
| 947 | } |
| 948 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 949 | factor /= total_weight; |
| 950 | |
| 951 | bias = NULL; |
| 952 | if (iface->conf->acs_chan_bias) { |
| 953 | for (k = 0; k < iface->conf->num_acs_chan_bias; k++) { |
| 954 | bias = &iface->conf->acs_chan_bias[k]; |
| 955 | if (bias->channel == chan->chan) |
| 956 | break; |
| 957 | bias = NULL; |
| 958 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 959 | } else if (is_24ghz_mode(mode->mode) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 960 | is_common_24ghz_chan(chan->chan)) { |
| 961 | tmp_bias.channel = chan->chan; |
| 962 | tmp_bias.bias = ACS_24GHZ_PREFER_1_6_11; |
| 963 | bias = &tmp_bias; |
| 964 | } |
| 965 | |
| 966 | if (bias) { |
| 967 | factor *= bias->bias; |
| 968 | wpa_printf(MSG_DEBUG, |
| 969 | "ACS: * channel %d: total interference = %Lg (%f bias)", |
| 970 | chan->chan, factor, bias->bias); |
| 971 | } else { |
| 972 | wpa_printf(MSG_DEBUG, |
| 973 | "ACS: * channel %d: total interference = %Lg", |
| 974 | chan->chan, factor); |
| 975 | } |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 976 | |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 977 | if (acs_usable_chan(chan) && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 978 | (!*ideal_chan || factor < *ideal_factor)) { |
Sunil Ravi | af8751c | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 979 | /* Reset puncturing bitmap for the previous ideal |
| 980 | * channel */ |
| 981 | if (*ideal_chan) |
| 982 | (*ideal_chan)->punct_bitmap = 0; |
| 983 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 984 | *ideal_factor = factor; |
| 985 | *ideal_chan = chan; |
Sunil Ravi | af8751c | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 986 | |
| 987 | #ifdef CONFIG_IEEE80211BE |
| 988 | if (iface->conf->ieee80211be) |
| 989 | acs_update_puncturing_bitmap(iface, mode, bw, |
| 990 | n_chans, chan, |
| 991 | factor, 0); |
| 992 | #endif /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 993 | } |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 994 | |
| 995 | /* This channel would at least be usable */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 996 | if (!(*rand_chan)) |
| 997 | *rand_chan = chan; |
| 998 | } |
| 999 | } |
| 1000 | |
| 1001 | |
| 1002 | /* |
| 1003 | * At this point it's assumed chan->interference_factor has been computed. |
| 1004 | * This function should be reusable regardless of interference computation |
| 1005 | * option (survey, BSS, spectral, ...). chan->interference factor must be |
| 1006 | * summable (i.e., must be always greater than zero). |
| 1007 | */ |
| 1008 | static struct hostapd_channel_data * |
| 1009 | acs_find_ideal_chan(struct hostapd_iface *iface) |
| 1010 | { |
| 1011 | struct hostapd_channel_data *ideal_chan = NULL, |
| 1012 | *rand_chan = NULL; |
| 1013 | long double ideal_factor = 0; |
| 1014 | int i; |
| 1015 | int n_chans = 1; |
| 1016 | u32 bw; |
| 1017 | struct hostapd_hw_modes *mode; |
| 1018 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1019 | if (is_6ghz_op_class(iface->conf->op_class)) { |
| 1020 | bw = op_class_to_bandwidth(iface->conf->op_class); |
| 1021 | n_chans = bw / 20; |
| 1022 | goto bw_selected; |
| 1023 | } |
| 1024 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1025 | /* TODO: HT40- support */ |
| 1026 | |
| 1027 | if (iface->conf->ieee80211n && |
| 1028 | iface->conf->secondary_channel == -1) { |
| 1029 | wpa_printf(MSG_ERROR, "ACS: HT40- is not supported yet. Please try HT40+"); |
| 1030 | return NULL; |
| 1031 | } |
| 1032 | |
| 1033 | if (iface->conf->ieee80211n && |
| 1034 | iface->conf->secondary_channel) |
| 1035 | n_chans = 2; |
| 1036 | |
| 1037 | if (iface->conf->ieee80211ac || iface->conf->ieee80211ax) { |
| 1038 | switch (hostapd_get_oper_chwidth(iface->conf)) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1039 | case CONF_OPER_CHWIDTH_80MHZ: |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1040 | n_chans = 4; |
| 1041 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1042 | case CONF_OPER_CHWIDTH_160MHZ: |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1043 | n_chans = 8; |
| 1044 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1045 | default: |
| 1046 | break; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | bw = num_chan_to_bw(n_chans); |
| 1051 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1052 | bw_selected: |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1053 | /* TODO: VHT/HE80+80. Update acs_adjust_center_freq() too. */ |
| 1054 | |
| 1055 | wpa_printf(MSG_DEBUG, |
| 1056 | "ACS: Survey analysis for selected bandwidth %d MHz", bw); |
| 1057 | |
| 1058 | for (i = 0; i < iface->num_hw_features; i++) { |
| 1059 | mode = &iface->hw_features[i]; |
| 1060 | if (!hostapd_hw_skip_mode(iface, mode)) |
| 1061 | acs_find_ideal_chan_mode(iface, mode, n_chans, bw, |
| 1062 | &rand_chan, &ideal_chan, |
| 1063 | &ideal_factor); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1064 | } |
| 1065 | |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 1066 | if (ideal_chan) { |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1067 | wpa_printf(MSG_DEBUG, "ACS: Ideal channel is %d (%d MHz) with total interference factor of %Lg", |
| 1068 | ideal_chan->chan, ideal_chan->freq, ideal_factor); |
Sunil Ravi | af8751c | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 1069 | |
| 1070 | #ifdef CONFIG_IEEE80211BE |
| 1071 | if (iface->conf->punct_acs_threshold) |
| 1072 | wpa_printf(MSG_DEBUG, "ACS: RU puncturing bitmap 0x%x", |
| 1073 | ideal_chan->punct_bitmap); |
| 1074 | #endif /* CONFIG_IEEE80211BE */ |
| 1075 | |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 1076 | return ideal_chan; |
| 1077 | } |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1078 | |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 1079 | return rand_chan; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1083 | static void acs_adjust_secondary(struct hostapd_iface *iface) |
| 1084 | { |
| 1085 | unsigned int i; |
| 1086 | |
| 1087 | /* When working with bandwidth over 20 MHz on the 5 GHz or 6 GHz band, |
| 1088 | * ACS can return a secondary channel which is not the first channel of |
| 1089 | * the segment and we need to adjust. */ |
| 1090 | if (!iface->conf->secondary_channel || |
| 1091 | acs_find_mode(iface, iface->freq) != HOSTAPD_MODE_IEEE80211A) |
| 1092 | return; |
| 1093 | |
| 1094 | wpa_printf(MSG_DEBUG, "ACS: Adjusting HT/VHT/HE secondary frequency"); |
| 1095 | |
| 1096 | for (i = 0; bw_desc[ACS_BW40][i].first != -1; i++) { |
| 1097 | if (iface->freq == bw_desc[ACS_BW40][i].first) |
| 1098 | iface->conf->secondary_channel = 1; |
| 1099 | else if (iface->freq == bw_desc[ACS_BW40][i].last) |
| 1100 | iface->conf->secondary_channel = -1; |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1105 | static void acs_adjust_center_freq(struct hostapd_iface *iface) |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1106 | { |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1107 | int center; |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1108 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1109 | wpa_printf(MSG_DEBUG, "ACS: Adjusting VHT center frequency"); |
| 1110 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1111 | switch (hostapd_get_oper_chwidth(iface->conf)) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1112 | case CONF_OPER_CHWIDTH_USE_HT: |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1113 | if (iface->conf->secondary_channel && |
| 1114 | iface->freq >= 2400 && iface->freq < 2500) |
| 1115 | center = iface->conf->channel + |
| 1116 | 2 * iface->conf->secondary_channel; |
| 1117 | else if (iface->conf->secondary_channel) |
| 1118 | center = acs_get_bw_center_chan(iface->freq, ACS_BW40); |
| 1119 | else |
| 1120 | center = iface->conf->channel; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1121 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1122 | case CONF_OPER_CHWIDTH_80MHZ: |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1123 | center = acs_get_bw_center_chan(iface->freq, ACS_BW80); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1124 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1125 | case CONF_OPER_CHWIDTH_160MHZ: |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1126 | center = acs_get_bw_center_chan(iface->freq, ACS_BW160); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1127 | break; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1128 | default: |
| 1129 | /* TODO: How can this be calculated? Adjust |
| 1130 | * acs_find_ideal_chan() */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1131 | wpa_printf(MSG_INFO, |
| 1132 | "ACS: Only VHT20/40/80/160 is supported now"); |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1133 | return; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1134 | } |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1135 | |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1136 | hostapd_set_oper_centr_freq_seg0_idx(iface->conf, center); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | |
| 1140 | static int acs_study_survey_based(struct hostapd_iface *iface) |
| 1141 | { |
| 1142 | wpa_printf(MSG_DEBUG, "ACS: Trying survey-based ACS"); |
| 1143 | |
| 1144 | if (!iface->chans_surveyed) { |
| 1145 | wpa_printf(MSG_ERROR, "ACS: Unable to collect survey data"); |
| 1146 | return -1; |
| 1147 | } |
| 1148 | |
| 1149 | if (!acs_surveys_are_sufficient(iface)) { |
| 1150 | wpa_printf(MSG_ERROR, "ACS: Surveys have insufficient data"); |
| 1151 | return -1; |
| 1152 | } |
| 1153 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1154 | acs_survey_all_chans_interference_factor(iface); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1155 | return 0; |
| 1156 | } |
| 1157 | |
| 1158 | |
| 1159 | static int acs_study_options(struct hostapd_iface *iface) |
| 1160 | { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1161 | if (acs_study_survey_based(iface) == 0) |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1162 | return 0; |
| 1163 | |
| 1164 | /* TODO: If no surveys are available/sufficient this is a good |
| 1165 | * place to fallback to BSS-based ACS */ |
| 1166 | |
| 1167 | return -1; |
| 1168 | } |
| 1169 | |
| 1170 | |
| 1171 | static void acs_study(struct hostapd_iface *iface) |
| 1172 | { |
| 1173 | struct hostapd_channel_data *ideal_chan; |
| 1174 | int err; |
| 1175 | |
| 1176 | err = acs_study_options(iface); |
| 1177 | if (err < 0) { |
| 1178 | wpa_printf(MSG_ERROR, "ACS: All study options have failed"); |
| 1179 | goto fail; |
| 1180 | } |
| 1181 | |
| 1182 | ideal_chan = acs_find_ideal_chan(iface); |
| 1183 | if (!ideal_chan) { |
| 1184 | wpa_printf(MSG_ERROR, "ACS: Failed to compute ideal channel"); |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 1185 | err = -1; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1186 | goto fail; |
| 1187 | } |
| 1188 | |
| 1189 | iface->conf->channel = ideal_chan->chan; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1190 | iface->freq = ideal_chan->freq; |
Sunil Ravi | af8751c | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 1191 | #ifdef CONFIG_IEEE80211BE |
| 1192 | iface->conf->punct_bitmap = ideal_chan->punct_bitmap; |
| 1193 | #endif /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1194 | |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1195 | if (iface->conf->ieee80211ac || iface->conf->ieee80211ax) { |
| 1196 | acs_adjust_secondary(iface); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1197 | acs_adjust_center_freq(iface); |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1198 | } |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1199 | |
Sunil Ravi | 3e88b0e | 2022-08-10 22:56:55 +0000 | [diff] [blame] | 1200 | err = hostapd_select_hw_mode(iface); |
| 1201 | if (err) { |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1202 | wpa_printf(MSG_ERROR, |
| 1203 | "ACS: Could not (err: %d) select hw_mode for freq=%d channel=%d", |
Sunil Ravi | 3e88b0e | 2022-08-10 22:56:55 +0000 | [diff] [blame] | 1204 | err, iface->freq, iface->conf->channel); |
| 1205 | err = -1; |
| 1206 | goto fail; |
| 1207 | } |
| 1208 | |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 1209 | err = 0; |
| 1210 | fail: |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1211 | /* |
| 1212 | * hostapd_setup_interface_complete() will return -1 on failure, |
| 1213 | * 0 on success and 0 is HOSTAPD_CHAN_VALID :) |
| 1214 | */ |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 1215 | if (hostapd_acs_completed(iface, err) == HOSTAPD_CHAN_VALID) { |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1216 | acs_cleanup(iface); |
| 1217 | return; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1218 | } |
| 1219 | |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 1220 | /* This can possibly happen if channel parameters (secondary |
| 1221 | * channel, center frequencies) are misconfigured */ |
| 1222 | wpa_printf(MSG_ERROR, "ACS: Possibly channel configuration is invalid, please report this along with your config file."); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1223 | acs_fail(iface); |
| 1224 | } |
| 1225 | |
| 1226 | |
| 1227 | static void acs_scan_complete(struct hostapd_iface *iface) |
| 1228 | { |
| 1229 | int err; |
| 1230 | |
| 1231 | iface->scan_cb = NULL; |
| 1232 | |
| 1233 | wpa_printf(MSG_DEBUG, "ACS: Using survey based algorithm (acs_num_scans=%d)", |
| 1234 | iface->conf->acs_num_scans); |
| 1235 | |
| 1236 | err = hostapd_drv_get_survey(iface->bss[0], 0); |
| 1237 | if (err) { |
| 1238 | wpa_printf(MSG_ERROR, "ACS: Failed to get survey data"); |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 1239 | goto fail; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | if (++iface->acs_num_completed_scans < iface->conf->acs_num_scans) { |
| 1243 | err = acs_request_scan(iface); |
| 1244 | if (err) { |
| 1245 | wpa_printf(MSG_ERROR, "ACS: Failed to request scan"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1246 | goto fail; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | return; |
| 1250 | } |
| 1251 | |
| 1252 | acs_study(iface); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1253 | return; |
| 1254 | fail: |
| 1255 | hostapd_acs_completed(iface, 1); |
| 1256 | acs_fail(iface); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1260 | static int * acs_request_scan_add_freqs(struct hostapd_iface *iface, |
| 1261 | struct hostapd_hw_modes *mode, |
| 1262 | int *freq) |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1263 | { |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1264 | struct hostapd_channel_data *chan; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1265 | int i; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1266 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1267 | for (i = 0; i < mode->num_channels; i++) { |
| 1268 | chan = &mode->channels[i]; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1269 | if ((chan->flag & HOSTAPD_CHAN_DISABLED) || |
| 1270 | ((chan->flag & HOSTAPD_CHAN_RADAR) && |
| 1271 | iface->conf->acs_exclude_dfs)) |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1272 | continue; |
| 1273 | |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 1274 | if (!is_in_chanlist(iface, chan)) |
| 1275 | continue; |
| 1276 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1277 | if (!is_in_freqlist(iface, chan)) |
| 1278 | continue; |
| 1279 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1280 | if (chan->max_tx_power < iface->conf->min_tx_power) |
| 1281 | continue; |
| 1282 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1283 | if ((chan->flag & HOSTAPD_CHAN_INDOOR_ONLY) && |
| 1284 | iface->conf->country[2] == 0x4f) |
| 1285 | continue; |
| 1286 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1287 | *freq++ = chan->freq; |
| 1288 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1289 | |
| 1290 | return freq; |
| 1291 | } |
| 1292 | |
| 1293 | |
| 1294 | static int acs_request_scan(struct hostapd_iface *iface) |
| 1295 | { |
| 1296 | struct wpa_driver_scan_params params; |
| 1297 | int i, *freq; |
| 1298 | int num_channels; |
| 1299 | struct hostapd_hw_modes *mode; |
| 1300 | |
| 1301 | os_memset(¶ms, 0, sizeof(params)); |
| 1302 | |
| 1303 | num_channels = 0; |
| 1304 | for (i = 0; i < iface->num_hw_features; i++) { |
| 1305 | mode = &iface->hw_features[i]; |
| 1306 | if (!hostapd_hw_skip_mode(iface, mode)) |
| 1307 | num_channels += mode->num_channels; |
| 1308 | } |
| 1309 | |
| 1310 | params.freqs = os_calloc(num_channels + 1, sizeof(params.freqs[0])); |
| 1311 | if (params.freqs == NULL) |
| 1312 | return -1; |
| 1313 | |
| 1314 | freq = params.freqs; |
| 1315 | |
| 1316 | for (i = 0; i < iface->num_hw_features; i++) { |
| 1317 | mode = &iface->hw_features[i]; |
| 1318 | if (!hostapd_hw_skip_mode(iface, mode)) |
| 1319 | freq = acs_request_scan_add_freqs(iface, mode, freq); |
| 1320 | } |
| 1321 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1322 | *freq = 0; |
| 1323 | |
Neo Jou | e288170 | 2019-10-17 11:32:28 +0800 | [diff] [blame] | 1324 | if (params.freqs == freq) { |
| 1325 | wpa_printf(MSG_ERROR, "ACS: No available channels found"); |
| 1326 | os_free(params.freqs); |
| 1327 | return -1; |
| 1328 | } |
| 1329 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1330 | iface->scan_cb = acs_scan_complete; |
| 1331 | |
| 1332 | wpa_printf(MSG_DEBUG, "ACS: Scanning %d / %d", |
| 1333 | iface->acs_num_completed_scans + 1, |
| 1334 | iface->conf->acs_num_scans); |
| 1335 | |
| 1336 | if (hostapd_driver_scan(iface->bss[0], ¶ms) < 0) { |
| 1337 | wpa_printf(MSG_ERROR, "ACS: Failed to request initial scan"); |
| 1338 | acs_cleanup(iface); |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 1339 | os_free(params.freqs); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1340 | return -1; |
| 1341 | } |
| 1342 | |
| 1343 | os_free(params.freqs); |
| 1344 | return 0; |
| 1345 | } |
| 1346 | |
| 1347 | |
| 1348 | enum hostapd_chan_status acs_init(struct hostapd_iface *iface) |
| 1349 | { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1350 | int err; |
| 1351 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1352 | wpa_printf(MSG_INFO, "ACS: Automatic channel selection started, this may take a bit"); |
| 1353 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1354 | if (iface->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) { |
| 1355 | wpa_printf(MSG_INFO, "ACS: Offloading to driver"); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1356 | |
| 1357 | err = hostapd_drv_do_acs(iface->bss[0]); |
| 1358 | if (err) { |
| 1359 | if (err == 1) |
| 1360 | return HOSTAPD_CHAN_INVALID_NO_IR; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1361 | return HOSTAPD_CHAN_INVALID; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1362 | } |
| 1363 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1364 | return HOSTAPD_CHAN_ACS; |
| 1365 | } |
| 1366 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1367 | if (!iface->current_mode && |
| 1368 | iface->conf->hw_mode != HOSTAPD_MODE_IEEE80211ANY) |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 1369 | return HOSTAPD_CHAN_INVALID; |
| 1370 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1371 | acs_cleanup(iface); |
| 1372 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1373 | if (acs_request_scan(iface) < 0) |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1374 | return HOSTAPD_CHAN_INVALID; |
| 1375 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1376 | hostapd_set_state(iface, HAPD_IFACE_ACS); |
| 1377 | wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_STARTED); |
| 1378 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1379 | return HOSTAPD_CHAN_ACS; |
| 1380 | } |