Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 2 | /* |
| 3 | * This file contains helper code to handle channel |
| 4 | * settings and keeping track of what is possible at |
| 5 | * any point in time. |
| 6 | * |
| 7 | * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 2740f0c | 2014-09-03 15:24:58 +0300 | [diff] [blame] | 8 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
Johannes Berg | be98989 | 2021-06-18 13:41:39 +0300 | [diff] [blame] | 9 | * Copyright 2018-2021 Intel Corporation |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 10 | */ |
| 11 | |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 12 | #include <linux/export.h> |
Shay Bar | 3579994 | 2020-08-26 17:31:39 +0300 | [diff] [blame] | 13 | #include <linux/bitfield.h> |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 14 | #include <net/cfg80211.h> |
| 15 | #include "core.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 16 | #include "rdev-ops.h" |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 17 | |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 18 | static bool cfg80211_valid_60g_freq(u32 freq) |
| 19 | { |
| 20 | return freq >= 58320 && freq <= 70200; |
| 21 | } |
| 22 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 23 | void cfg80211_chandef_create(struct cfg80211_chan_def *chandef, |
| 24 | struct ieee80211_channel *chan, |
| 25 | enum nl80211_channel_type chan_type) |
| 26 | { |
| 27 | if (WARN_ON(!chan)) |
| 28 | return; |
| 29 | |
| 30 | chandef->chan = chan; |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 31 | chandef->freq1_offset = chan->freq_offset; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 32 | chandef->center_freq2 = 0; |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 33 | chandef->edmg.bw_config = 0; |
| 34 | chandef->edmg.channels = 0; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 35 | |
| 36 | switch (chan_type) { |
| 37 | case NL80211_CHAN_NO_HT: |
| 38 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 39 | chandef->center_freq1 = chan->center_freq; |
| 40 | break; |
| 41 | case NL80211_CHAN_HT20: |
| 42 | chandef->width = NL80211_CHAN_WIDTH_20; |
| 43 | chandef->center_freq1 = chan->center_freq; |
| 44 | break; |
| 45 | case NL80211_CHAN_HT40PLUS: |
| 46 | chandef->width = NL80211_CHAN_WIDTH_40; |
| 47 | chandef->center_freq1 = chan->center_freq + 10; |
| 48 | break; |
| 49 | case NL80211_CHAN_HT40MINUS: |
| 50 | chandef->width = NL80211_CHAN_WIDTH_40; |
| 51 | chandef->center_freq1 = chan->center_freq - 10; |
| 52 | break; |
| 53 | default: |
| 54 | WARN_ON(1); |
| 55 | } |
| 56 | } |
| 57 | EXPORT_SYMBOL(cfg80211_chandef_create); |
| 58 | |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 59 | static bool cfg80211_edmg_chandef_valid(const struct cfg80211_chan_def *chandef) |
| 60 | { |
| 61 | int max_contiguous = 0; |
| 62 | int num_of_enabled = 0; |
| 63 | int contiguous = 0; |
| 64 | int i; |
| 65 | |
| 66 | if (!chandef->edmg.channels || !chandef->edmg.bw_config) |
| 67 | return false; |
| 68 | |
| 69 | if (!cfg80211_valid_60g_freq(chandef->chan->center_freq)) |
| 70 | return false; |
| 71 | |
| 72 | for (i = 0; i < 6; i++) { |
| 73 | if (chandef->edmg.channels & BIT(i)) { |
| 74 | contiguous++; |
| 75 | num_of_enabled++; |
| 76 | } else { |
| 77 | contiguous = 0; |
| 78 | } |
| 79 | |
| 80 | max_contiguous = max(contiguous, max_contiguous); |
| 81 | } |
| 82 | /* basic verification of edmg configuration according to |
| 83 | * IEEE P802.11ay/D4.0 section 9.4.2.251 |
| 84 | */ |
| 85 | /* check bw_config against contiguous edmg channels */ |
| 86 | switch (chandef->edmg.bw_config) { |
| 87 | case IEEE80211_EDMG_BW_CONFIG_4: |
| 88 | case IEEE80211_EDMG_BW_CONFIG_8: |
| 89 | case IEEE80211_EDMG_BW_CONFIG_12: |
| 90 | if (max_contiguous < 1) |
| 91 | return false; |
| 92 | break; |
| 93 | case IEEE80211_EDMG_BW_CONFIG_5: |
| 94 | case IEEE80211_EDMG_BW_CONFIG_9: |
| 95 | case IEEE80211_EDMG_BW_CONFIG_13: |
| 96 | if (max_contiguous < 2) |
| 97 | return false; |
| 98 | break; |
| 99 | case IEEE80211_EDMG_BW_CONFIG_6: |
| 100 | case IEEE80211_EDMG_BW_CONFIG_10: |
| 101 | case IEEE80211_EDMG_BW_CONFIG_14: |
| 102 | if (max_contiguous < 3) |
| 103 | return false; |
| 104 | break; |
| 105 | case IEEE80211_EDMG_BW_CONFIG_7: |
| 106 | case IEEE80211_EDMG_BW_CONFIG_11: |
| 107 | case IEEE80211_EDMG_BW_CONFIG_15: |
| 108 | if (max_contiguous < 4) |
| 109 | return false; |
| 110 | break; |
| 111 | |
| 112 | default: |
| 113 | return false; |
| 114 | } |
| 115 | |
| 116 | /* check bw_config against aggregated (non contiguous) edmg channels */ |
| 117 | switch (chandef->edmg.bw_config) { |
| 118 | case IEEE80211_EDMG_BW_CONFIG_4: |
| 119 | case IEEE80211_EDMG_BW_CONFIG_5: |
| 120 | case IEEE80211_EDMG_BW_CONFIG_6: |
| 121 | case IEEE80211_EDMG_BW_CONFIG_7: |
| 122 | break; |
| 123 | case IEEE80211_EDMG_BW_CONFIG_8: |
| 124 | case IEEE80211_EDMG_BW_CONFIG_9: |
| 125 | case IEEE80211_EDMG_BW_CONFIG_10: |
| 126 | case IEEE80211_EDMG_BW_CONFIG_11: |
| 127 | if (num_of_enabled < 2) |
| 128 | return false; |
| 129 | break; |
| 130 | case IEEE80211_EDMG_BW_CONFIG_12: |
| 131 | case IEEE80211_EDMG_BW_CONFIG_13: |
| 132 | case IEEE80211_EDMG_BW_CONFIG_14: |
| 133 | case IEEE80211_EDMG_BW_CONFIG_15: |
| 134 | if (num_of_enabled < 4 || max_contiguous < 2) |
| 135 | return false; |
| 136 | break; |
| 137 | default: |
| 138 | return false; |
| 139 | } |
| 140 | |
| 141 | return true; |
| 142 | } |
| 143 | |
Thomas Pedersen | 11b3473 | 2020-09-08 12:03:06 -0700 | [diff] [blame] | 144 | static int nl80211_chan_width_to_mhz(enum nl80211_chan_width chan_width) |
| 145 | { |
| 146 | int mhz; |
| 147 | |
| 148 | switch (chan_width) { |
| 149 | case NL80211_CHAN_WIDTH_1: |
| 150 | mhz = 1; |
| 151 | break; |
| 152 | case NL80211_CHAN_WIDTH_2: |
| 153 | mhz = 2; |
| 154 | break; |
| 155 | case NL80211_CHAN_WIDTH_4: |
| 156 | mhz = 4; |
| 157 | break; |
| 158 | case NL80211_CHAN_WIDTH_8: |
| 159 | mhz = 8; |
| 160 | break; |
| 161 | case NL80211_CHAN_WIDTH_16: |
| 162 | mhz = 16; |
| 163 | break; |
| 164 | case NL80211_CHAN_WIDTH_5: |
| 165 | mhz = 5; |
| 166 | break; |
| 167 | case NL80211_CHAN_WIDTH_10: |
| 168 | mhz = 10; |
| 169 | break; |
| 170 | case NL80211_CHAN_WIDTH_20: |
| 171 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 172 | mhz = 20; |
| 173 | break; |
| 174 | case NL80211_CHAN_WIDTH_40: |
| 175 | mhz = 40; |
| 176 | break; |
| 177 | case NL80211_CHAN_WIDTH_80P80: |
| 178 | case NL80211_CHAN_WIDTH_80: |
| 179 | mhz = 80; |
| 180 | break; |
| 181 | case NL80211_CHAN_WIDTH_160: |
| 182 | mhz = 160; |
| 183 | break; |
| 184 | default: |
| 185 | WARN_ON_ONCE(1); |
| 186 | return -1; |
| 187 | } |
| 188 | return mhz; |
| 189 | } |
| 190 | |
| 191 | static int cfg80211_chandef_get_width(const struct cfg80211_chan_def *c) |
| 192 | { |
| 193 | return nl80211_chan_width_to_mhz(c->width); |
| 194 | } |
| 195 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 196 | bool cfg80211_chandef_valid(const struct cfg80211_chan_def *chandef) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 197 | { |
Thomas Pedersen | 11b3473 | 2020-09-08 12:03:06 -0700 | [diff] [blame] | 198 | u32 control_freq, oper_freq; |
| 199 | int oper_width, control_width; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 200 | |
| 201 | if (!chandef->chan) |
| 202 | return false; |
| 203 | |
Johannes Berg | be689f6 | 2020-04-24 12:01:04 +0200 | [diff] [blame] | 204 | if (chandef->freq1_offset >= 1000) |
| 205 | return false; |
| 206 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 207 | control_freq = chandef->chan->center_freq; |
| 208 | |
| 209 | switch (chandef->width) { |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 210 | case NL80211_CHAN_WIDTH_5: |
| 211 | case NL80211_CHAN_WIDTH_10: |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 212 | case NL80211_CHAN_WIDTH_20: |
| 213 | case NL80211_CHAN_WIDTH_20_NOHT: |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 214 | if (ieee80211_chandef_to_khz(chandef) != |
| 215 | ieee80211_channel_to_khz(chandef->chan)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 216 | return false; |
| 217 | if (chandef->center_freq2) |
| 218 | return false; |
| 219 | break; |
Thomas Pedersen | c1cd35c | 2020-10-05 09:51:22 -0700 | [diff] [blame] | 220 | case NL80211_CHAN_WIDTH_1: |
Thomas Pedersen | 11b3473 | 2020-09-08 12:03:06 -0700 | [diff] [blame] | 221 | case NL80211_CHAN_WIDTH_2: |
| 222 | case NL80211_CHAN_WIDTH_4: |
| 223 | case NL80211_CHAN_WIDTH_8: |
| 224 | case NL80211_CHAN_WIDTH_16: |
Thomas Pedersen | c1cd35c | 2020-10-05 09:51:22 -0700 | [diff] [blame] | 225 | if (chandef->chan->band != NL80211_BAND_S1GHZ) |
| 226 | return false; |
| 227 | |
Thomas Pedersen | 11b3473 | 2020-09-08 12:03:06 -0700 | [diff] [blame] | 228 | control_freq = ieee80211_channel_to_khz(chandef->chan); |
| 229 | oper_freq = ieee80211_chandef_to_khz(chandef); |
| 230 | control_width = nl80211_chan_width_to_mhz( |
| 231 | ieee80211_s1g_channel_width( |
| 232 | chandef->chan)); |
| 233 | oper_width = cfg80211_chandef_get_width(chandef); |
| 234 | |
| 235 | if (oper_width < 0 || control_width < 0) |
| 236 | return false; |
| 237 | if (chandef->center_freq2) |
| 238 | return false; |
| 239 | |
| 240 | if (control_freq + MHZ_TO_KHZ(control_width) / 2 > |
| 241 | oper_freq + MHZ_TO_KHZ(oper_width) / 2) |
| 242 | return false; |
| 243 | |
| 244 | if (control_freq - MHZ_TO_KHZ(control_width) / 2 < |
| 245 | oper_freq - MHZ_TO_KHZ(oper_width) / 2) |
| 246 | return false; |
| 247 | break; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 248 | case NL80211_CHAN_WIDTH_80P80: |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 249 | if (!chandef->center_freq2) |
| 250 | return false; |
Johannes Berg | 9cab315 | 2012-12-14 00:19:08 +0100 | [diff] [blame] | 251 | /* adjacent is not allowed -- that's a 160 MHz channel */ |
| 252 | if (chandef->center_freq1 - chandef->center_freq2 == 80 || |
| 253 | chandef->center_freq2 - chandef->center_freq1 == 80) |
| 254 | return false; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 255 | break; |
Johannes Berg | 3bb1ccc | 2021-11-29 15:32:43 +0200 | [diff] [blame] | 256 | default: |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 257 | if (chandef->center_freq2) |
| 258 | return false; |
| 259 | break; |
Johannes Berg | 3bb1ccc | 2021-11-29 15:32:43 +0200 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | switch (chandef->width) { |
| 263 | case NL80211_CHAN_WIDTH_5: |
| 264 | case NL80211_CHAN_WIDTH_10: |
| 265 | case NL80211_CHAN_WIDTH_20: |
| 266 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 267 | case NL80211_CHAN_WIDTH_1: |
| 268 | case NL80211_CHAN_WIDTH_2: |
| 269 | case NL80211_CHAN_WIDTH_4: |
| 270 | case NL80211_CHAN_WIDTH_8: |
| 271 | case NL80211_CHAN_WIDTH_16: |
| 272 | /* all checked above */ |
| 273 | break; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 274 | case NL80211_CHAN_WIDTH_160: |
Johannes Berg | 3bb1ccc | 2021-11-29 15:32:43 +0200 | [diff] [blame] | 275 | if (chandef->center_freq1 == control_freq + 70 || |
| 276 | chandef->center_freq1 == control_freq + 50 || |
| 277 | chandef->center_freq1 == control_freq - 50 || |
| 278 | chandef->center_freq1 == control_freq - 70) |
| 279 | break; |
| 280 | fallthrough; |
| 281 | case NL80211_CHAN_WIDTH_80P80: |
| 282 | case NL80211_CHAN_WIDTH_80: |
| 283 | if (chandef->center_freq1 == control_freq + 30 || |
| 284 | chandef->center_freq1 == control_freq - 30) |
| 285 | break; |
| 286 | fallthrough; |
| 287 | case NL80211_CHAN_WIDTH_40: |
| 288 | if (chandef->center_freq1 == control_freq + 10 || |
| 289 | chandef->center_freq1 == control_freq - 10) |
| 290 | break; |
| 291 | fallthrough; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 292 | default: |
| 293 | return false; |
| 294 | } |
| 295 | |
Masashi Honma | ec649fe | 2019-10-21 16:50:45 +0900 | [diff] [blame] | 296 | /* channel 14 is only for IEEE 802.11b */ |
| 297 | if (chandef->center_freq1 == 2484 && |
| 298 | chandef->width != NL80211_CHAN_WIDTH_20_NOHT) |
| 299 | return false; |
| 300 | |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 301 | if (cfg80211_chandef_is_edmg(chandef) && |
| 302 | !cfg80211_edmg_chandef_valid(chandef)) |
| 303 | return false; |
| 304 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 305 | return true; |
| 306 | } |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 307 | EXPORT_SYMBOL(cfg80211_chandef_valid); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 308 | |
| 309 | static void chandef_primary_freqs(const struct cfg80211_chan_def *c, |
Johannes Berg | fc1f48f | 2014-10-29 17:05:39 +0100 | [diff] [blame] | 310 | u32 *pri40, u32 *pri80) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 311 | { |
| 312 | int tmp; |
| 313 | |
| 314 | switch (c->width) { |
| 315 | case NL80211_CHAN_WIDTH_40: |
| 316 | *pri40 = c->center_freq1; |
| 317 | *pri80 = 0; |
| 318 | break; |
| 319 | case NL80211_CHAN_WIDTH_80: |
| 320 | case NL80211_CHAN_WIDTH_80P80: |
| 321 | *pri80 = c->center_freq1; |
| 322 | /* n_P20 */ |
| 323 | tmp = (30 + c->chan->center_freq - c->center_freq1)/20; |
| 324 | /* n_P40 */ |
| 325 | tmp /= 2; |
| 326 | /* freq_P40 */ |
| 327 | *pri40 = c->center_freq1 - 20 + 40 * tmp; |
| 328 | break; |
| 329 | case NL80211_CHAN_WIDTH_160: |
| 330 | /* n_P20 */ |
| 331 | tmp = (70 + c->chan->center_freq - c->center_freq1)/20; |
| 332 | /* n_P40 */ |
| 333 | tmp /= 2; |
| 334 | /* freq_P40 */ |
| 335 | *pri40 = c->center_freq1 - 60 + 40 * tmp; |
| 336 | /* n_P80 */ |
| 337 | tmp /= 2; |
| 338 | *pri80 = c->center_freq1 - 40 + 80 * tmp; |
| 339 | break; |
| 340 | default: |
| 341 | WARN_ON_ONCE(1); |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | const struct cfg80211_chan_def * |
| 346 | cfg80211_chandef_compatible(const struct cfg80211_chan_def *c1, |
| 347 | const struct cfg80211_chan_def *c2) |
| 348 | { |
| 349 | u32 c1_pri40, c1_pri80, c2_pri40, c2_pri80; |
| 350 | |
| 351 | /* If they are identical, return */ |
| 352 | if (cfg80211_chandef_identical(c1, c2)) |
| 353 | return c1; |
| 354 | |
| 355 | /* otherwise, must have same control channel */ |
| 356 | if (c1->chan != c2->chan) |
| 357 | return NULL; |
| 358 | |
| 359 | /* |
| 360 | * If they have the same width, but aren't identical, |
| 361 | * then they can't be compatible. |
| 362 | */ |
| 363 | if (c1->width == c2->width) |
| 364 | return NULL; |
| 365 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 366 | /* |
| 367 | * can't be compatible if one of them is 5 or 10 MHz, |
| 368 | * but they don't have the same width. |
| 369 | */ |
| 370 | if (c1->width == NL80211_CHAN_WIDTH_5 || |
| 371 | c1->width == NL80211_CHAN_WIDTH_10 || |
| 372 | c2->width == NL80211_CHAN_WIDTH_5 || |
| 373 | c2->width == NL80211_CHAN_WIDTH_10) |
| 374 | return NULL; |
| 375 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 376 | if (c1->width == NL80211_CHAN_WIDTH_20_NOHT || |
| 377 | c1->width == NL80211_CHAN_WIDTH_20) |
| 378 | return c2; |
| 379 | |
| 380 | if (c2->width == NL80211_CHAN_WIDTH_20_NOHT || |
| 381 | c2->width == NL80211_CHAN_WIDTH_20) |
| 382 | return c1; |
| 383 | |
| 384 | chandef_primary_freqs(c1, &c1_pri40, &c1_pri80); |
| 385 | chandef_primary_freqs(c2, &c2_pri40, &c2_pri80); |
| 386 | |
| 387 | if (c1_pri40 != c2_pri40) |
| 388 | return NULL; |
| 389 | |
| 390 | WARN_ON(!c1_pri80 && !c2_pri80); |
| 391 | if (c1_pri80 && c2_pri80 && c1_pri80 != c2_pri80) |
| 392 | return NULL; |
| 393 | |
| 394 | if (c1->width > c2->width) |
| 395 | return c1; |
| 396 | return c2; |
| 397 | } |
| 398 | EXPORT_SYMBOL(cfg80211_chandef_compatible); |
| 399 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 400 | static void cfg80211_set_chans_dfs_state(struct wiphy *wiphy, u32 center_freq, |
| 401 | u32 bandwidth, |
| 402 | enum nl80211_dfs_state dfs_state) |
| 403 | { |
| 404 | struct ieee80211_channel *c; |
| 405 | u32 freq; |
| 406 | |
| 407 | for (freq = center_freq - bandwidth/2 + 10; |
| 408 | freq <= center_freq + bandwidth/2 - 10; |
| 409 | freq += 20) { |
| 410 | c = ieee80211_get_channel(wiphy, freq); |
| 411 | if (!c || !(c->flags & IEEE80211_CHAN_RADAR)) |
| 412 | continue; |
| 413 | |
| 414 | c->dfs_state = dfs_state; |
| 415 | c->dfs_state_entered = jiffies; |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | void cfg80211_set_dfs_state(struct wiphy *wiphy, |
| 420 | const struct cfg80211_chan_def *chandef, |
| 421 | enum nl80211_dfs_state dfs_state) |
| 422 | { |
| 423 | int width; |
| 424 | |
| 425 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 426 | return; |
| 427 | |
| 428 | width = cfg80211_chandef_get_width(chandef); |
| 429 | if (width < 0) |
| 430 | return; |
| 431 | |
| 432 | cfg80211_set_chans_dfs_state(wiphy, chandef->center_freq1, |
| 433 | width, dfs_state); |
| 434 | |
| 435 | if (!chandef->center_freq2) |
| 436 | return; |
| 437 | cfg80211_set_chans_dfs_state(wiphy, chandef->center_freq2, |
| 438 | width, dfs_state); |
| 439 | } |
| 440 | |
Janusz Dziedzic | 40d1ba6 | 2013-11-05 14:48:47 +0100 | [diff] [blame] | 441 | static u32 cfg80211_get_start_freq(u32 center_freq, |
| 442 | u32 bandwidth) |
| 443 | { |
| 444 | u32 start_freq; |
| 445 | |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 446 | bandwidth = MHZ_TO_KHZ(bandwidth); |
| 447 | if (bandwidth <= MHZ_TO_KHZ(20)) |
Janusz Dziedzic | 40d1ba6 | 2013-11-05 14:48:47 +0100 | [diff] [blame] | 448 | start_freq = center_freq; |
| 449 | else |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 450 | start_freq = center_freq - bandwidth / 2 + MHZ_TO_KHZ(10); |
Janusz Dziedzic | 40d1ba6 | 2013-11-05 14:48:47 +0100 | [diff] [blame] | 451 | |
| 452 | return start_freq; |
| 453 | } |
| 454 | |
| 455 | static u32 cfg80211_get_end_freq(u32 center_freq, |
| 456 | u32 bandwidth) |
| 457 | { |
| 458 | u32 end_freq; |
| 459 | |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 460 | bandwidth = MHZ_TO_KHZ(bandwidth); |
| 461 | if (bandwidth <= MHZ_TO_KHZ(20)) |
Janusz Dziedzic | 40d1ba6 | 2013-11-05 14:48:47 +0100 | [diff] [blame] | 462 | end_freq = center_freq; |
| 463 | else |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 464 | end_freq = center_freq + bandwidth / 2 - MHZ_TO_KHZ(10); |
Janusz Dziedzic | 40d1ba6 | 2013-11-05 14:48:47 +0100 | [diff] [blame] | 465 | |
| 466 | return end_freq; |
| 467 | } |
| 468 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 469 | static int cfg80211_get_chans_dfs_required(struct wiphy *wiphy, |
| 470 | u32 center_freq, |
| 471 | u32 bandwidth) |
| 472 | { |
| 473 | struct ieee80211_channel *c; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 474 | u32 freq, start_freq, end_freq; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 475 | |
Janusz Dziedzic | 40d1ba6 | 2013-11-05 14:48:47 +0100 | [diff] [blame] | 476 | start_freq = cfg80211_get_start_freq(center_freq, bandwidth); |
| 477 | end_freq = cfg80211_get_end_freq(center_freq, bandwidth); |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 478 | |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 479 | for (freq = start_freq; freq <= end_freq; freq += MHZ_TO_KHZ(20)) { |
| 480 | c = ieee80211_get_channel_khz(wiphy, freq); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 481 | if (!c) |
| 482 | return -EINVAL; |
| 483 | |
| 484 | if (c->flags & IEEE80211_CHAN_RADAR) |
| 485 | return 1; |
| 486 | } |
| 487 | return 0; |
| 488 | } |
| 489 | |
| 490 | |
| 491 | int cfg80211_chandef_dfs_required(struct wiphy *wiphy, |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 492 | const struct cfg80211_chan_def *chandef, |
| 493 | enum nl80211_iftype iftype) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 494 | { |
| 495 | int width; |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 496 | int ret; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 497 | |
| 498 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 499 | return -EINVAL; |
| 500 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 501 | switch (iftype) { |
| 502 | case NL80211_IFTYPE_ADHOC: |
| 503 | case NL80211_IFTYPE_AP: |
| 504 | case NL80211_IFTYPE_P2P_GO: |
| 505 | case NL80211_IFTYPE_MESH_POINT: |
| 506 | width = cfg80211_chandef_get_width(chandef); |
| 507 | if (width < 0) |
| 508 | return -EINVAL; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 509 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 510 | ret = cfg80211_get_chans_dfs_required(wiphy, |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 511 | ieee80211_chandef_to_khz(chandef), |
| 512 | width); |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 513 | if (ret < 0) |
| 514 | return ret; |
| 515 | else if (ret > 0) |
| 516 | return BIT(chandef->width); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 517 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 518 | if (!chandef->center_freq2) |
| 519 | return 0; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 520 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 521 | ret = cfg80211_get_chans_dfs_required(wiphy, |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 522 | MHZ_TO_KHZ(chandef->center_freq2), |
| 523 | width); |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 524 | if (ret < 0) |
| 525 | return ret; |
| 526 | else if (ret > 0) |
| 527 | return BIT(chandef->width); |
| 528 | |
| 529 | break; |
| 530 | case NL80211_IFTYPE_STATION: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 531 | case NL80211_IFTYPE_OCB: |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 532 | case NL80211_IFTYPE_P2P_CLIENT: |
| 533 | case NL80211_IFTYPE_MONITOR: |
| 534 | case NL80211_IFTYPE_AP_VLAN: |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 535 | case NL80211_IFTYPE_P2P_DEVICE: |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 536 | case NL80211_IFTYPE_NAN: |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 537 | break; |
Johannes Berg | e7e0517 | 2020-11-09 10:57:47 +0100 | [diff] [blame] | 538 | case NL80211_IFTYPE_WDS: |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 539 | case NL80211_IFTYPE_UNSPECIFIED: |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 540 | case NUM_NL80211_IFTYPES: |
| 541 | WARN_ON(1); |
| 542 | } |
| 543 | |
| 544 | return 0; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 545 | } |
Simon Wunderlich | 774f073 | 2013-08-28 13:41:28 +0200 | [diff] [blame] | 546 | EXPORT_SYMBOL(cfg80211_chandef_dfs_required); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 547 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 548 | static int cfg80211_get_chans_dfs_usable(struct wiphy *wiphy, |
| 549 | u32 center_freq, |
| 550 | u32 bandwidth) |
| 551 | { |
| 552 | struct ieee80211_channel *c; |
| 553 | u32 freq, start_freq, end_freq; |
| 554 | int count = 0; |
| 555 | |
| 556 | start_freq = cfg80211_get_start_freq(center_freq, bandwidth); |
| 557 | end_freq = cfg80211_get_end_freq(center_freq, bandwidth); |
| 558 | |
| 559 | /* |
| 560 | * Check entire range of channels for the bandwidth. |
| 561 | * Check all channels are DFS channels (DFS_USABLE or |
| 562 | * DFS_AVAILABLE). Return number of usable channels |
| 563 | * (require CAC). Allow DFS and non-DFS channel mix. |
| 564 | */ |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 565 | for (freq = start_freq; freq <= end_freq; freq += MHZ_TO_KHZ(20)) { |
| 566 | c = ieee80211_get_channel_khz(wiphy, freq); |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 567 | if (!c) |
| 568 | return -EINVAL; |
| 569 | |
| 570 | if (c->flags & IEEE80211_CHAN_DISABLED) |
| 571 | return -EINVAL; |
| 572 | |
| 573 | if (c->flags & IEEE80211_CHAN_RADAR) { |
| 574 | if (c->dfs_state == NL80211_DFS_UNAVAILABLE) |
| 575 | return -EINVAL; |
| 576 | |
| 577 | if (c->dfs_state == NL80211_DFS_USABLE) |
| 578 | count++; |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | return count; |
| 583 | } |
| 584 | |
| 585 | bool cfg80211_chandef_dfs_usable(struct wiphy *wiphy, |
| 586 | const struct cfg80211_chan_def *chandef) |
| 587 | { |
| 588 | int width; |
| 589 | int r1, r2 = 0; |
| 590 | |
| 591 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 592 | return false; |
| 593 | |
| 594 | width = cfg80211_chandef_get_width(chandef); |
| 595 | if (width < 0) |
| 596 | return false; |
| 597 | |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 598 | r1 = cfg80211_get_chans_dfs_usable(wiphy, |
| 599 | MHZ_TO_KHZ(chandef->center_freq1), |
| 600 | width); |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 601 | |
| 602 | if (r1 < 0) |
| 603 | return false; |
| 604 | |
| 605 | switch (chandef->width) { |
| 606 | case NL80211_CHAN_WIDTH_80P80: |
| 607 | WARN_ON(!chandef->center_freq2); |
| 608 | r2 = cfg80211_get_chans_dfs_usable(wiphy, |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 609 | MHZ_TO_KHZ(chandef->center_freq2), |
| 610 | width); |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 611 | if (r2 < 0) |
| 612 | return false; |
| 613 | break; |
| 614 | default: |
| 615 | WARN_ON(chandef->center_freq2); |
| 616 | break; |
| 617 | } |
| 618 | |
| 619 | return (r1 + r2 > 0); |
| 620 | } |
| 621 | |
Vasanthakumar Thiagarajan | b35a51c | 2017-02-27 17:04:33 +0530 | [diff] [blame] | 622 | /* |
| 623 | * Checks if center frequency of chan falls with in the bandwidth |
| 624 | * range of chandef. |
| 625 | */ |
| 626 | bool cfg80211_is_sub_chan(struct cfg80211_chan_def *chandef, |
| 627 | struct ieee80211_channel *chan) |
| 628 | { |
| 629 | int width; |
Johannes Berg | a67a489 | 2017-10-12 11:23:04 +0200 | [diff] [blame] | 630 | u32 freq; |
Vasanthakumar Thiagarajan | b35a51c | 2017-02-27 17:04:33 +0530 | [diff] [blame] | 631 | |
| 632 | if (chandef->chan->center_freq == chan->center_freq) |
| 633 | return true; |
| 634 | |
| 635 | width = cfg80211_chandef_get_width(chandef); |
| 636 | if (width <= 20) |
| 637 | return false; |
| 638 | |
Vasanthakumar Thiagarajan | b35a51c | 2017-02-27 17:04:33 +0530 | [diff] [blame] | 639 | for (freq = chandef->center_freq1 - width / 2 + 10; |
| 640 | freq <= chandef->center_freq1 + width / 2 - 10; freq += 20) { |
| 641 | if (chan->center_freq == freq) |
| 642 | return true; |
| 643 | } |
| 644 | |
| 645 | if (!chandef->center_freq2) |
| 646 | return false; |
| 647 | |
| 648 | for (freq = chandef->center_freq2 - width / 2 + 10; |
| 649 | freq <= chandef->center_freq2 + width / 2 - 10; freq += 20) { |
| 650 | if (chan->center_freq == freq) |
| 651 | return true; |
| 652 | } |
| 653 | |
| 654 | return false; |
| 655 | } |
| 656 | |
| 657 | bool cfg80211_beaconing_iface_active(struct wireless_dev *wdev) |
| 658 | { |
| 659 | bool active = false; |
| 660 | |
| 661 | ASSERT_WDEV_LOCK(wdev); |
| 662 | |
| 663 | if (!wdev->chandef.chan) |
| 664 | return false; |
| 665 | |
| 666 | switch (wdev->iftype) { |
| 667 | case NL80211_IFTYPE_AP: |
| 668 | case NL80211_IFTYPE_P2P_GO: |
| 669 | active = wdev->beacon_interval != 0; |
| 670 | break; |
| 671 | case NL80211_IFTYPE_ADHOC: |
| 672 | active = wdev->ssid_len != 0; |
| 673 | break; |
| 674 | case NL80211_IFTYPE_MESH_POINT: |
| 675 | active = wdev->mesh_id_len != 0; |
| 676 | break; |
| 677 | case NL80211_IFTYPE_STATION: |
| 678 | case NL80211_IFTYPE_OCB: |
| 679 | case NL80211_IFTYPE_P2P_CLIENT: |
| 680 | case NL80211_IFTYPE_MONITOR: |
| 681 | case NL80211_IFTYPE_AP_VLAN: |
Vasanthakumar Thiagarajan | b35a51c | 2017-02-27 17:04:33 +0530 | [diff] [blame] | 682 | case NL80211_IFTYPE_P2P_DEVICE: |
| 683 | /* Can NAN type be considered as beaconing interface? */ |
| 684 | case NL80211_IFTYPE_NAN: |
| 685 | break; |
| 686 | case NL80211_IFTYPE_UNSPECIFIED: |
Johannes Berg | e7e0517 | 2020-11-09 10:57:47 +0100 | [diff] [blame] | 687 | case NL80211_IFTYPE_WDS: |
Vasanthakumar Thiagarajan | b35a51c | 2017-02-27 17:04:33 +0530 | [diff] [blame] | 688 | case NUM_NL80211_IFTYPES: |
| 689 | WARN_ON(1); |
| 690 | } |
| 691 | |
| 692 | return active; |
| 693 | } |
| 694 | |
Vasanthakumar Thiagarajan | 8976672 | 2017-02-27 17:04:35 +0530 | [diff] [blame] | 695 | static bool cfg80211_is_wiphy_oper_chan(struct wiphy *wiphy, |
| 696 | struct ieee80211_channel *chan) |
Vasanthakumar Thiagarajan | b35a51c | 2017-02-27 17:04:33 +0530 | [diff] [blame] | 697 | { |
| 698 | struct wireless_dev *wdev; |
| 699 | |
Vasanthakumar Thiagarajan | b35a51c | 2017-02-27 17:04:33 +0530 | [diff] [blame] | 700 | list_for_each_entry(wdev, &wiphy->wdev_list, list) { |
| 701 | wdev_lock(wdev); |
| 702 | if (!cfg80211_beaconing_iface_active(wdev)) { |
| 703 | wdev_unlock(wdev); |
| 704 | continue; |
| 705 | } |
| 706 | |
| 707 | if (cfg80211_is_sub_chan(&wdev->chandef, chan)) { |
| 708 | wdev_unlock(wdev); |
| 709 | return true; |
| 710 | } |
| 711 | wdev_unlock(wdev); |
| 712 | } |
| 713 | |
| 714 | return false; |
| 715 | } |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 716 | |
Lorenzo Bianconi | 8415816 | 2021-11-16 15:03:36 +0100 | [diff] [blame] | 717 | static bool |
| 718 | cfg80211_offchan_chain_is_active(struct cfg80211_registered_device *rdev, |
| 719 | struct ieee80211_channel *channel) |
| 720 | { |
Lorenzo Bianconi | a95bfb8 | 2021-11-29 14:11:24 +0100 | [diff] [blame] | 721 | if (!rdev->background_radar_wdev) |
Lorenzo Bianconi | 8415816 | 2021-11-16 15:03:36 +0100 | [diff] [blame] | 722 | return false; |
| 723 | |
Lorenzo Bianconi | a95bfb8 | 2021-11-29 14:11:24 +0100 | [diff] [blame] | 724 | if (!cfg80211_chandef_valid(&rdev->background_radar_chandef)) |
Lorenzo Bianconi | 8415816 | 2021-11-16 15:03:36 +0100 | [diff] [blame] | 725 | return false; |
| 726 | |
Lorenzo Bianconi | a95bfb8 | 2021-11-29 14:11:24 +0100 | [diff] [blame] | 727 | return cfg80211_is_sub_chan(&rdev->background_radar_chandef, channel); |
Lorenzo Bianconi | 8415816 | 2021-11-16 15:03:36 +0100 | [diff] [blame] | 728 | } |
| 729 | |
Vasanthakumar Thiagarajan | 8976672 | 2017-02-27 17:04:35 +0530 | [diff] [blame] | 730 | bool cfg80211_any_wiphy_oper_chan(struct wiphy *wiphy, |
| 731 | struct ieee80211_channel *chan) |
| 732 | { |
| 733 | struct cfg80211_registered_device *rdev; |
| 734 | |
| 735 | ASSERT_RTNL(); |
| 736 | |
| 737 | if (!(chan->flags & IEEE80211_CHAN_RADAR)) |
| 738 | return false; |
| 739 | |
| 740 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 741 | if (!reg_dfs_domain_same(wiphy, &rdev->wiphy)) |
| 742 | continue; |
| 743 | |
| 744 | if (cfg80211_is_wiphy_oper_chan(&rdev->wiphy, chan)) |
| 745 | return true; |
Lorenzo Bianconi | 8415816 | 2021-11-16 15:03:36 +0100 | [diff] [blame] | 746 | |
| 747 | if (cfg80211_offchan_chain_is_active(rdev, chan)) |
| 748 | return true; |
Vasanthakumar Thiagarajan | 8976672 | 2017-02-27 17:04:35 +0530 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | return false; |
| 752 | } |
| 753 | |
Janusz Dziedzic | 6bc54fb | 2013-11-06 13:55:53 +0100 | [diff] [blame] | 754 | static bool cfg80211_get_chans_dfs_available(struct wiphy *wiphy, |
| 755 | u32 center_freq, |
| 756 | u32 bandwidth) |
| 757 | { |
| 758 | struct ieee80211_channel *c; |
| 759 | u32 freq, start_freq, end_freq; |
Dmitry Lebed | 2c390e4 | 2018-03-26 16:36:32 +0300 | [diff] [blame] | 760 | bool dfs_offload; |
| 761 | |
| 762 | dfs_offload = wiphy_ext_feature_isset(wiphy, |
| 763 | NL80211_EXT_FEATURE_DFS_OFFLOAD); |
Janusz Dziedzic | 6bc54fb | 2013-11-06 13:55:53 +0100 | [diff] [blame] | 764 | |
| 765 | start_freq = cfg80211_get_start_freq(center_freq, bandwidth); |
| 766 | end_freq = cfg80211_get_end_freq(center_freq, bandwidth); |
| 767 | |
| 768 | /* |
| 769 | * Check entire range of channels for the bandwidth. |
| 770 | * If any channel in between is disabled or has not |
| 771 | * had gone through CAC return false |
| 772 | */ |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 773 | for (freq = start_freq; freq <= end_freq; freq += MHZ_TO_KHZ(20)) { |
| 774 | c = ieee80211_get_channel_khz(wiphy, freq); |
Janusz Dziedzic | 6bc54fb | 2013-11-06 13:55:53 +0100 | [diff] [blame] | 775 | if (!c) |
| 776 | return false; |
| 777 | |
| 778 | if (c->flags & IEEE80211_CHAN_DISABLED) |
| 779 | return false; |
| 780 | |
Dmitry Lebed | 2c390e4 | 2018-03-26 16:36:32 +0300 | [diff] [blame] | 781 | if ((c->flags & IEEE80211_CHAN_RADAR) && |
| 782 | (c->dfs_state != NL80211_DFS_AVAILABLE) && |
| 783 | !(c->dfs_state == NL80211_DFS_USABLE && dfs_offload)) |
Janusz Dziedzic | 6bc54fb | 2013-11-06 13:55:53 +0100 | [diff] [blame] | 784 | return false; |
| 785 | } |
| 786 | |
| 787 | return true; |
| 788 | } |
| 789 | |
| 790 | static bool cfg80211_chandef_dfs_available(struct wiphy *wiphy, |
| 791 | const struct cfg80211_chan_def *chandef) |
| 792 | { |
| 793 | int width; |
| 794 | int r; |
| 795 | |
| 796 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 797 | return false; |
| 798 | |
| 799 | width = cfg80211_chandef_get_width(chandef); |
| 800 | if (width < 0) |
| 801 | return false; |
| 802 | |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 803 | r = cfg80211_get_chans_dfs_available(wiphy, |
| 804 | MHZ_TO_KHZ(chandef->center_freq1), |
Janusz Dziedzic | 6bc54fb | 2013-11-06 13:55:53 +0100 | [diff] [blame] | 805 | width); |
| 806 | |
| 807 | /* If any of channels unavailable for cf1 just return */ |
| 808 | if (!r) |
| 809 | return r; |
| 810 | |
| 811 | switch (chandef->width) { |
| 812 | case NL80211_CHAN_WIDTH_80P80: |
| 813 | WARN_ON(!chandef->center_freq2); |
| 814 | r = cfg80211_get_chans_dfs_available(wiphy, |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 815 | MHZ_TO_KHZ(chandef->center_freq2), |
| 816 | width); |
Colin Ian King | 680682d | 2016-07-17 19:55:27 +0100 | [diff] [blame] | 817 | break; |
Janusz Dziedzic | 6bc54fb | 2013-11-06 13:55:53 +0100 | [diff] [blame] | 818 | default: |
| 819 | WARN_ON(chandef->center_freq2); |
| 820 | break; |
| 821 | } |
| 822 | |
| 823 | return r; |
| 824 | } |
| 825 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 826 | static unsigned int cfg80211_get_chans_dfs_cac_time(struct wiphy *wiphy, |
| 827 | u32 center_freq, |
| 828 | u32 bandwidth) |
| 829 | { |
| 830 | struct ieee80211_channel *c; |
| 831 | u32 start_freq, end_freq, freq; |
| 832 | unsigned int dfs_cac_ms = 0; |
| 833 | |
| 834 | start_freq = cfg80211_get_start_freq(center_freq, bandwidth); |
| 835 | end_freq = cfg80211_get_end_freq(center_freq, bandwidth); |
| 836 | |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 837 | for (freq = start_freq; freq <= end_freq; freq += MHZ_TO_KHZ(20)) { |
| 838 | c = ieee80211_get_channel_khz(wiphy, freq); |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 839 | if (!c) |
| 840 | return 0; |
| 841 | |
| 842 | if (c->flags & IEEE80211_CHAN_DISABLED) |
| 843 | return 0; |
| 844 | |
| 845 | if (!(c->flags & IEEE80211_CHAN_RADAR)) |
| 846 | continue; |
| 847 | |
| 848 | if (c->dfs_cac_ms > dfs_cac_ms) |
| 849 | dfs_cac_ms = c->dfs_cac_ms; |
| 850 | } |
| 851 | |
| 852 | return dfs_cac_ms; |
| 853 | } |
| 854 | |
| 855 | unsigned int |
| 856 | cfg80211_chandef_dfs_cac_time(struct wiphy *wiphy, |
| 857 | const struct cfg80211_chan_def *chandef) |
| 858 | { |
| 859 | int width; |
| 860 | unsigned int t1 = 0, t2 = 0; |
| 861 | |
| 862 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 863 | return 0; |
| 864 | |
| 865 | width = cfg80211_chandef_get_width(chandef); |
| 866 | if (width < 0) |
| 867 | return 0; |
| 868 | |
| 869 | t1 = cfg80211_get_chans_dfs_cac_time(wiphy, |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 870 | MHZ_TO_KHZ(chandef->center_freq1), |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 871 | width); |
| 872 | |
| 873 | if (!chandef->center_freq2) |
| 874 | return t1; |
| 875 | |
| 876 | t2 = cfg80211_get_chans_dfs_cac_time(wiphy, |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 877 | MHZ_TO_KHZ(chandef->center_freq2), |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 878 | width); |
| 879 | |
| 880 | return max(t1, t2); |
| 881 | } |
Janusz Dziedzic | 6bc54fb | 2013-11-06 13:55:53 +0100 | [diff] [blame] | 882 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 883 | static bool cfg80211_secondary_chans_ok(struct wiphy *wiphy, |
| 884 | u32 center_freq, u32 bandwidth, |
| 885 | u32 prohibited_flags) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 886 | { |
| 887 | struct ieee80211_channel *c; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 888 | u32 freq, start_freq, end_freq; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 889 | |
Janusz Dziedzic | 40d1ba6 | 2013-11-05 14:48:47 +0100 | [diff] [blame] | 890 | start_freq = cfg80211_get_start_freq(center_freq, bandwidth); |
| 891 | end_freq = cfg80211_get_end_freq(center_freq, bandwidth); |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 892 | |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 893 | for (freq = start_freq; freq <= end_freq; freq += MHZ_TO_KHZ(20)) { |
| 894 | c = ieee80211_get_channel_khz(wiphy, freq); |
Janusz Dziedzic | 6bc54fb | 2013-11-06 13:55:53 +0100 | [diff] [blame] | 895 | if (!c || c->flags & prohibited_flags) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 896 | return false; |
| 897 | } |
| 898 | |
| 899 | return true; |
| 900 | } |
| 901 | |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 902 | /* check if the operating channels are valid and supported */ |
| 903 | static bool cfg80211_edmg_usable(struct wiphy *wiphy, u8 edmg_channels, |
| 904 | enum ieee80211_edmg_bw_config edmg_bw_config, |
| 905 | int primary_channel, |
| 906 | struct ieee80211_edmg *edmg_cap) |
| 907 | { |
| 908 | struct ieee80211_channel *chan; |
| 909 | int i, freq; |
| 910 | int channels_counter = 0; |
| 911 | |
| 912 | if (!edmg_channels && !edmg_bw_config) |
| 913 | return true; |
| 914 | |
| 915 | if ((!edmg_channels && edmg_bw_config) || |
| 916 | (edmg_channels && !edmg_bw_config)) |
| 917 | return false; |
| 918 | |
| 919 | if (!(edmg_channels & BIT(primary_channel - 1))) |
| 920 | return false; |
| 921 | |
| 922 | /* 60GHz channels 1..6 */ |
| 923 | for (i = 0; i < 6; i++) { |
| 924 | if (!(edmg_channels & BIT(i))) |
| 925 | continue; |
| 926 | |
| 927 | if (!(edmg_cap->channels & BIT(i))) |
| 928 | return false; |
| 929 | |
| 930 | channels_counter++; |
| 931 | |
| 932 | freq = ieee80211_channel_to_frequency(i + 1, |
| 933 | NL80211_BAND_60GHZ); |
| 934 | chan = ieee80211_get_channel(wiphy, freq); |
| 935 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 936 | return false; |
| 937 | } |
| 938 | |
| 939 | /* IEEE802.11 allows max 4 channels */ |
| 940 | if (channels_counter > 4) |
| 941 | return false; |
| 942 | |
| 943 | /* check bw_config is a subset of what driver supports |
| 944 | * (see IEEE P802.11ay/D4.0 section 9.4.2.251, Table 13) |
| 945 | */ |
| 946 | if ((edmg_bw_config % 4) > (edmg_cap->bw_config % 4)) |
| 947 | return false; |
| 948 | |
| 949 | if (edmg_bw_config > edmg_cap->bw_config) |
| 950 | return false; |
| 951 | |
| 952 | return true; |
| 953 | } |
| 954 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 955 | bool cfg80211_chandef_usable(struct wiphy *wiphy, |
| 956 | const struct cfg80211_chan_def *chandef, |
| 957 | u32 prohibited_flags) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 958 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 959 | struct ieee80211_sta_ht_cap *ht_cap; |
| 960 | struct ieee80211_sta_vht_cap *vht_cap; |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 961 | struct ieee80211_edmg *edmg_cap; |
Jouni Malinen | 08f6f14 | 2014-12-11 23:48:55 +0200 | [diff] [blame] | 962 | u32 width, control_freq, cap; |
Wen Gong | e6ed929 | 2021-05-23 23:36:24 -0400 | [diff] [blame] | 963 | bool ext_nss_cap, support_80_80 = false; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 964 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 965 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 966 | return false; |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 967 | |
| 968 | ht_cap = &wiphy->bands[chandef->chan->band]->ht_cap; |
| 969 | vht_cap = &wiphy->bands[chandef->chan->band]->vht_cap; |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 970 | edmg_cap = &wiphy->bands[chandef->chan->band]->edmg_cap; |
Wen Gong | e6ed929 | 2021-05-23 23:36:24 -0400 | [diff] [blame] | 971 | ext_nss_cap = __le16_to_cpu(vht_cap->vht_mcs.tx_highest) & |
| 972 | IEEE80211_VHT_EXT_NSS_BW_CAPABLE; |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 973 | |
| 974 | if (edmg_cap->channels && |
| 975 | !cfg80211_edmg_usable(wiphy, |
| 976 | chandef->edmg.channels, |
| 977 | chandef->edmg.bw_config, |
| 978 | chandef->chan->hw_value, |
| 979 | edmg_cap)) |
| 980 | return false; |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 981 | |
| 982 | control_freq = chandef->chan->center_freq; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 983 | |
| 984 | switch (chandef->width) { |
Thomas Pedersen | df78a0c | 2020-06-01 23:22:47 -0700 | [diff] [blame] | 985 | case NL80211_CHAN_WIDTH_1: |
| 986 | width = 1; |
| 987 | break; |
| 988 | case NL80211_CHAN_WIDTH_2: |
| 989 | width = 2; |
| 990 | break; |
| 991 | case NL80211_CHAN_WIDTH_4: |
| 992 | width = 4; |
| 993 | break; |
| 994 | case NL80211_CHAN_WIDTH_8: |
| 995 | width = 8; |
| 996 | break; |
| 997 | case NL80211_CHAN_WIDTH_16: |
| 998 | width = 16; |
| 999 | break; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1000 | case NL80211_CHAN_WIDTH_5: |
| 1001 | width = 5; |
| 1002 | break; |
| 1003 | case NL80211_CHAN_WIDTH_10: |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 1004 | prohibited_flags |= IEEE80211_CHAN_NO_10MHZ; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1005 | width = 10; |
| 1006 | break; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1007 | case NL80211_CHAN_WIDTH_20: |
Johannes Berg | ba8f6a0 | 2020-05-28 21:34:40 +0200 | [diff] [blame] | 1008 | if (!ht_cap->ht_supported && |
| 1009 | chandef->chan->band != NL80211_BAND_6GHZ) |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1010 | return false; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1011 | fallthrough; |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1012 | case NL80211_CHAN_WIDTH_20_NOHT: |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 1013 | prohibited_flags |= IEEE80211_CHAN_NO_20MHZ; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1014 | width = 20; |
Mark Mentovai | 09a02fd | 2010-11-17 16:34:37 -0500 | [diff] [blame] | 1015 | break; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1016 | case NL80211_CHAN_WIDTH_40: |
| 1017 | width = 40; |
Johannes Berg | ba8f6a0 | 2020-05-28 21:34:40 +0200 | [diff] [blame] | 1018 | if (chandef->chan->band == NL80211_BAND_6GHZ) |
| 1019 | break; |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1020 | if (!ht_cap->ht_supported) |
| 1021 | return false; |
| 1022 | if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) || |
| 1023 | ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT) |
| 1024 | return false; |
| 1025 | if (chandef->center_freq1 < control_freq && |
| 1026 | chandef->chan->flags & IEEE80211_CHAN_NO_HT40MINUS) |
| 1027 | return false; |
| 1028 | if (chandef->center_freq1 > control_freq && |
| 1029 | chandef->chan->flags & IEEE80211_CHAN_NO_HT40PLUS) |
| 1030 | return false; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1031 | break; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1032 | case NL80211_CHAN_WIDTH_80P80: |
Shay Bar | 3579994 | 2020-08-26 17:31:39 +0300 | [diff] [blame] | 1033 | cap = vht_cap->cap; |
| 1034 | support_80_80 = |
| 1035 | (cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ) || |
| 1036 | (cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ && |
| 1037 | cap & IEEE80211_VHT_CAP_EXT_NSS_BW_MASK) || |
Wen Gong | e6ed929 | 2021-05-23 23:36:24 -0400 | [diff] [blame] | 1038 | (ext_nss_cap && |
| 1039 | u32_get_bits(cap, IEEE80211_VHT_CAP_EXT_NSS_BW_MASK) > 1); |
Shay Bar | 3579994 | 2020-08-26 17:31:39 +0300 | [diff] [blame] | 1040 | if (chandef->chan->band != NL80211_BAND_6GHZ && !support_80_80) |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1041 | return false; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 1042 | fallthrough; |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1043 | case NL80211_CHAN_WIDTH_80: |
Johannes Berg | c7a6ee2 | 2012-12-12 17:50:39 +0100 | [diff] [blame] | 1044 | prohibited_flags |= IEEE80211_CHAN_NO_80MHZ; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1045 | width = 80; |
Johannes Berg | ba8f6a0 | 2020-05-28 21:34:40 +0200 | [diff] [blame] | 1046 | if (chandef->chan->band == NL80211_BAND_6GHZ) |
| 1047 | break; |
| 1048 | if (!vht_cap->vht_supported) |
| 1049 | return false; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1050 | break; |
| 1051 | case NL80211_CHAN_WIDTH_160: |
Johannes Berg | ba8f6a0 | 2020-05-28 21:34:40 +0200 | [diff] [blame] | 1052 | prohibited_flags |= IEEE80211_CHAN_NO_160MHZ; |
| 1053 | width = 160; |
| 1054 | if (chandef->chan->band == NL80211_BAND_6GHZ) |
| 1055 | break; |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1056 | if (!vht_cap->vht_supported) |
| 1057 | return false; |
Jouni Malinen | 08f6f14 | 2014-12-11 23:48:55 +0200 | [diff] [blame] | 1058 | cap = vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK; |
| 1059 | if (cap != IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ && |
Shay Bar | 3579994 | 2020-08-26 17:31:39 +0300 | [diff] [blame] | 1060 | cap != IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ && |
Wen Gong | e6ed929 | 2021-05-23 23:36:24 -0400 | [diff] [blame] | 1061 | !(ext_nss_cap && |
| 1062 | (vht_cap->cap & IEEE80211_VHT_CAP_EXT_NSS_BW_MASK))) |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1063 | return false; |
Mark Mentovai | 09a02fd | 2010-11-17 16:34:37 -0500 | [diff] [blame] | 1064 | break; |
Luis R. Rodriguez | 9236d83 | 2010-11-12 16:31:23 -0800 | [diff] [blame] | 1065 | default: |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1066 | WARN_ON_ONCE(1); |
Luis R. Rodriguez | 9236d83 | 2010-11-12 16:31:23 -0800 | [diff] [blame] | 1067 | return false; |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 1068 | } |
Luis R. Rodriguez | 9236d83 | 2010-11-12 16:31:23 -0800 | [diff] [blame] | 1069 | |
Johannes Berg | c7a6ee2 | 2012-12-12 17:50:39 +0100 | [diff] [blame] | 1070 | /* |
| 1071 | * TODO: What if there are only certain 80/160/80+80 MHz channels |
| 1072 | * allowed by the driver, or only certain combinations? |
| 1073 | * For 40 MHz the driver can set the NO_HT40 flags, but for |
| 1074 | * 80/160 MHz and in particular 80+80 MHz this isn't really |
| 1075 | * feasible and we only have NO_80MHZ/NO_160MHZ so far but |
| 1076 | * no way to cover 80+80 MHz or more complex restrictions. |
| 1077 | * Note that such restrictions also need to be advertised to |
| 1078 | * userspace, for example for P2P channel selection. |
| 1079 | */ |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1080 | |
Johannes Berg | a6662db | 2012-12-04 20:49:42 +0100 | [diff] [blame] | 1081 | if (width > 20) |
| 1082 | prohibited_flags |= IEEE80211_CHAN_NO_OFDM; |
| 1083 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1084 | /* 5 and 10 MHz are only defined for the OFDM PHY */ |
| 1085 | if (width < 20) |
| 1086 | prohibited_flags |= IEEE80211_CHAN_NO_OFDM; |
| 1087 | |
| 1088 | |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 1089 | if (!cfg80211_secondary_chans_ok(wiphy, |
| 1090 | ieee80211_chandef_to_khz(chandef), |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1091 | width, prohibited_flags)) |
| 1092 | return false; |
| 1093 | |
| 1094 | if (!chandef->center_freq2) |
| 1095 | return true; |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 1096 | return cfg80211_secondary_chans_ok(wiphy, |
| 1097 | MHZ_TO_KHZ(chandef->center_freq2), |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1098 | width, prohibited_flags); |
| 1099 | } |
| 1100 | EXPORT_SYMBOL(cfg80211_chandef_usable); |
| 1101 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1102 | /* |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 1103 | * Check if the channel can be used under permissive conditions mandated by |
| 1104 | * some regulatory bodies, i.e., the channel is marked with |
| 1105 | * IEEE80211_CHAN_IR_CONCURRENT and there is an additional station interface |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1106 | * associated to an AP on the same channel or on the same UNII band |
| 1107 | * (assuming that the AP is an authorized master). |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 1108 | * In addition allow operation on a channel on which indoor operation is |
Ilan Peer | c8866e5 | 2014-02-23 09:13:03 +0200 | [diff] [blame] | 1109 | * allowed, iff we are currently operating in an indoor environment. |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1110 | */ |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 1111 | static bool cfg80211_ir_permissive_chan(struct wiphy *wiphy, |
| 1112 | enum nl80211_iftype iftype, |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1113 | struct ieee80211_channel *chan) |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1114 | { |
Avraham Stern | be69c24 | 2015-04-27 16:52:16 +0300 | [diff] [blame] | 1115 | struct wireless_dev *wdev; |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 1116 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1117 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 1118 | lockdep_assert_held(&rdev->wiphy.mtx); |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1119 | |
Masahiro Yamada | 97f2645 | 2016-08-03 13:45:50 -0700 | [diff] [blame] | 1120 | if (!IS_ENABLED(CONFIG_CFG80211_REG_RELAX_NO_IR) || |
Ilan Peer | c8866e5 | 2014-02-23 09:13:03 +0200 | [diff] [blame] | 1121 | !(wiphy->regulatory_flags & REGULATORY_ENABLE_RELAX_NO_IR)) |
| 1122 | return false; |
| 1123 | |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 1124 | /* only valid for GO and TDLS off-channel (station/p2p-CL) */ |
| 1125 | if (iftype != NL80211_IFTYPE_P2P_GO && |
| 1126 | iftype != NL80211_IFTYPE_STATION && |
| 1127 | iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 1128 | return false; |
| 1129 | |
Ilan Peer | c8866e5 | 2014-02-23 09:13:03 +0200 | [diff] [blame] | 1130 | if (regulatory_indoor_allowed() && |
| 1131 | (chan->flags & IEEE80211_CHAN_INDOOR_ONLY)) |
| 1132 | return true; |
| 1133 | |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 1134 | if (!(chan->flags & IEEE80211_CHAN_IR_CONCURRENT)) |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1135 | return false; |
| 1136 | |
| 1137 | /* |
| 1138 | * Generally, it is possible to rely on another device/driver to allow |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 1139 | * the IR concurrent relaxation, however, since the device can further |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1140 | * enforce the relaxation (by doing a similar verifications as this), |
| 1141 | * and thus fail the GO instantiation, consider only the interfaces of |
| 1142 | * the current registered device. |
| 1143 | */ |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 1144 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1145 | struct ieee80211_channel *other_chan = NULL; |
| 1146 | int r1, r2; |
| 1147 | |
Avraham Stern | be69c24 | 2015-04-27 16:52:16 +0300 | [diff] [blame] | 1148 | wdev_lock(wdev); |
| 1149 | if (wdev->iftype == NL80211_IFTYPE_STATION && |
| 1150 | wdev->current_bss) |
| 1151 | other_chan = wdev->current_bss->pub.channel; |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1152 | |
Avraham Stern | be69c24 | 2015-04-27 16:52:16 +0300 | [diff] [blame] | 1153 | /* |
| 1154 | * If a GO already operates on the same GO_CONCURRENT channel, |
| 1155 | * this one (maybe the same one) can beacon as well. We allow |
| 1156 | * the operation even if the station we relied on with |
| 1157 | * GO_CONCURRENT is disconnected now. But then we must make sure |
| 1158 | * we're not outdoor on an indoor-only channel. |
| 1159 | */ |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 1160 | if (iftype == NL80211_IFTYPE_P2P_GO && |
| 1161 | wdev->iftype == NL80211_IFTYPE_P2P_GO && |
Avraham Stern | be69c24 | 2015-04-27 16:52:16 +0300 | [diff] [blame] | 1162 | wdev->beacon_interval && |
| 1163 | !(chan->flags & IEEE80211_CHAN_INDOOR_ONLY)) |
| 1164 | other_chan = wdev->chandef.chan; |
| 1165 | wdev_unlock(wdev); |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1166 | |
| 1167 | if (!other_chan) |
| 1168 | continue; |
| 1169 | |
| 1170 | if (chan == other_chan) |
| 1171 | return true; |
| 1172 | |
Arend van Spriel | 0816e6b | 2019-08-02 13:31:03 +0200 | [diff] [blame] | 1173 | if (chan->band != NL80211_BAND_5GHZ && |
| 1174 | chan->band != NL80211_BAND_6GHZ) |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1175 | continue; |
| 1176 | |
| 1177 | r1 = cfg80211_get_unii(chan->center_freq); |
| 1178 | r2 = cfg80211_get_unii(other_chan->center_freq); |
| 1179 | |
Ilan Peer | 46d5372 | 2014-04-23 09:22:58 +0300 | [diff] [blame] | 1180 | if (r1 != -EINVAL && r1 == r2) { |
| 1181 | /* |
| 1182 | * At some locations channels 149-165 are considered a |
| 1183 | * bundle, but at other locations, e.g., Indonesia, |
| 1184 | * channels 149-161 are considered a bundle while |
| 1185 | * channel 165 is left out and considered to be in a |
| 1186 | * different bundle. Thus, in case that there is a |
| 1187 | * station interface connected to an AP on channel 165, |
| 1188 | * it is assumed that channels 149-161 are allowed for |
| 1189 | * GO operations. However, having a station interface |
| 1190 | * connected to an AP on channels 149-161, does not |
| 1191 | * allow GO operation on channel 165. |
| 1192 | */ |
| 1193 | if (chan->center_freq == 5825 && |
| 1194 | other_chan->center_freq != 5825) |
| 1195 | continue; |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1196 | return true; |
Ilan Peer | 46d5372 | 2014-04-23 09:22:58 +0300 | [diff] [blame] | 1197 | } |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | return false; |
| 1201 | } |
| 1202 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 1203 | static bool _cfg80211_reg_can_beacon(struct wiphy *wiphy, |
| 1204 | struct cfg80211_chan_def *chandef, |
| 1205 | enum nl80211_iftype iftype, |
| 1206 | bool check_no_ir) |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1207 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1208 | bool res; |
Janusz Dziedzic | 6bc54fb | 2013-11-06 13:55:53 +0100 | [diff] [blame] | 1209 | u32 prohibited_flags = IEEE80211_CHAN_DISABLED | |
Janusz Dziedzic | 6bc54fb | 2013-11-06 13:55:53 +0100 | [diff] [blame] | 1210 | IEEE80211_CHAN_RADAR; |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1211 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 1212 | trace_cfg80211_reg_can_beacon(wiphy, chandef, iftype, check_no_ir); |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1213 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 1214 | if (check_no_ir) |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1215 | prohibited_flags |= IEEE80211_CHAN_NO_IR; |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1216 | |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 1217 | if (cfg80211_chandef_dfs_required(wiphy, chandef, iftype) > 0 && |
Janusz Dziedzic | 6bc54fb | 2013-11-06 13:55:53 +0100 | [diff] [blame] | 1218 | cfg80211_chandef_dfs_available(wiphy, chandef)) { |
| 1219 | /* We can skip IEEE80211_CHAN_NO_IR if chandef dfs available */ |
| 1220 | prohibited_flags = IEEE80211_CHAN_DISABLED; |
| 1221 | } |
| 1222 | |
| 1223 | res = cfg80211_chandef_usable(wiphy, chandef, prohibited_flags); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1224 | |
| 1225 | trace_cfg80211_return_bool(res); |
| 1226 | return res; |
Luis R. Rodriguez | 9236d83 | 2010-11-12 16:31:23 -0800 | [diff] [blame] | 1227 | } |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 1228 | |
| 1229 | bool cfg80211_reg_can_beacon(struct wiphy *wiphy, |
| 1230 | struct cfg80211_chan_def *chandef, |
| 1231 | enum nl80211_iftype iftype) |
| 1232 | { |
| 1233 | return _cfg80211_reg_can_beacon(wiphy, chandef, iftype, true); |
| 1234 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1235 | EXPORT_SYMBOL(cfg80211_reg_can_beacon); |
Luis R. Rodriguez | 9236d83 | 2010-11-12 16:31:23 -0800 | [diff] [blame] | 1236 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 1237 | bool cfg80211_reg_can_beacon_relax(struct wiphy *wiphy, |
| 1238 | struct cfg80211_chan_def *chandef, |
| 1239 | enum nl80211_iftype iftype) |
| 1240 | { |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 1241 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 1242 | bool check_no_ir; |
| 1243 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 1244 | lockdep_assert_held(&rdev->wiphy.mtx); |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 1245 | |
| 1246 | /* |
| 1247 | * Under certain conditions suggested by some regulatory bodies a |
| 1248 | * GO/STA can IR on channels marked with IEEE80211_NO_IR. Set this flag |
| 1249 | * only if such relaxations are not enabled and the conditions are not |
| 1250 | * met. |
| 1251 | */ |
| 1252 | check_no_ir = !cfg80211_ir_permissive_chan(wiphy, iftype, |
| 1253 | chandef->chan); |
| 1254 | |
| 1255 | return _cfg80211_reg_can_beacon(wiphy, chandef, iftype, check_no_ir); |
| 1256 | } |
| 1257 | EXPORT_SYMBOL(cfg80211_reg_can_beacon_relax); |
| 1258 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1259 | int cfg80211_set_monitor_channel(struct cfg80211_registered_device *rdev, |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1260 | struct cfg80211_chan_def *chandef) |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 1261 | { |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1262 | if (!rdev->ops->set_monitor_channel) |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 1263 | return -EOPNOTSUPP; |
Michal Kazior | 4f03c1e | 2012-06-29 12:47:03 +0200 | [diff] [blame] | 1264 | if (!cfg80211_has_monitors_only(rdev)) |
| 1265 | return -EBUSY; |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 1266 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1267 | return rdev_set_monitor_channel(rdev, chandef); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 1268 | } |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 1269 | |
| 1270 | void |
Johannes Berg | 8e95ea4 | 2012-07-10 19:39:02 +0200 | [diff] [blame] | 1271 | cfg80211_get_chan_state(struct wireless_dev *wdev, |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 1272 | struct ieee80211_channel **chan, |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 1273 | enum cfg80211_chan_mode *chanmode, |
| 1274 | u8 *radar_detect) |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 1275 | { |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 1276 | int ret; |
| 1277 | |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 1278 | *chan = NULL; |
| 1279 | *chanmode = CHAN_MODE_UNDEFINED; |
| 1280 | |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 1281 | ASSERT_WDEV_LOCK(wdev); |
| 1282 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1283 | if (wdev->netdev && !netif_running(wdev->netdev)) |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 1284 | return; |
| 1285 | |
| 1286 | switch (wdev->iftype) { |
| 1287 | case NL80211_IFTYPE_ADHOC: |
| 1288 | if (wdev->current_bss) { |
| 1289 | *chan = wdev->current_bss->pub.channel; |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 1290 | *chanmode = (wdev->ibss_fixed && |
| 1291 | !wdev->ibss_dfs_possible) |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 1292 | ? CHAN_MODE_SHARED |
| 1293 | : CHAN_MODE_EXCLUSIVE; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 1294 | |
| 1295 | /* consider worst-case - IBSS can try to return to the |
| 1296 | * original user-specified channel as creator */ |
| 1297 | if (wdev->ibss_dfs_possible) |
| 1298 | *radar_detect |= BIT(wdev->chandef.width); |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 1299 | return; |
| 1300 | } |
Johannes Berg | 0f0094b | 2013-10-25 12:46:44 +0200 | [diff] [blame] | 1301 | break; |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 1302 | case NL80211_IFTYPE_STATION: |
| 1303 | case NL80211_IFTYPE_P2P_CLIENT: |
| 1304 | if (wdev->current_bss) { |
| 1305 | *chan = wdev->current_bss->pub.channel; |
| 1306 | *chanmode = CHAN_MODE_SHARED; |
| 1307 | return; |
| 1308 | } |
| 1309 | break; |
| 1310 | case NL80211_IFTYPE_AP: |
| 1311 | case NL80211_IFTYPE_P2P_GO: |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 1312 | if (wdev->cac_started) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 1313 | *chan = wdev->chandef.chan; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 1314 | *chanmode = CHAN_MODE_SHARED; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 1315 | *radar_detect |= BIT(wdev->chandef.width); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 1316 | } else if (wdev->beacon_interval) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 1317 | *chan = wdev->chandef.chan; |
Felix Fietkau | f53594a | 2012-07-12 16:10:02 +0200 | [diff] [blame] | 1318 | *chanmode = CHAN_MODE_SHARED; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 1319 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 1320 | ret = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 1321 | &wdev->chandef, |
| 1322 | wdev->iftype); |
| 1323 | WARN_ON(ret < 0); |
| 1324 | if (ret > 0) |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 1325 | *radar_detect |= BIT(wdev->chandef.width); |
Felix Fietkau | f53594a | 2012-07-12 16:10:02 +0200 | [diff] [blame] | 1326 | } |
| 1327 | return; |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 1328 | case NL80211_IFTYPE_MESH_POINT: |
Felix Fietkau | f53594a | 2012-07-12 16:10:02 +0200 | [diff] [blame] | 1329 | if (wdev->mesh_id_len) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 1330 | *chan = wdev->chandef.chan; |
Felix Fietkau | f53594a | 2012-07-12 16:10:02 +0200 | [diff] [blame] | 1331 | *chanmode = CHAN_MODE_SHARED; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 1332 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 1333 | ret = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 1334 | &wdev->chandef, |
| 1335 | wdev->iftype); |
| 1336 | WARN_ON(ret < 0); |
| 1337 | if (ret > 0) |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 1338 | *radar_detect |= BIT(wdev->chandef.width); |
Felix Fietkau | f53594a | 2012-07-12 16:10:02 +0200 | [diff] [blame] | 1339 | } |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 1340 | return; |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 1341 | case NL80211_IFTYPE_OCB: |
| 1342 | if (wdev->chandef.chan) { |
| 1343 | *chan = wdev->chandef.chan; |
| 1344 | *chanmode = CHAN_MODE_SHARED; |
| 1345 | return; |
| 1346 | } |
| 1347 | break; |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 1348 | case NL80211_IFTYPE_MONITOR: |
| 1349 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1350 | case NL80211_IFTYPE_P2P_DEVICE: |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 1351 | case NL80211_IFTYPE_NAN: |
Johannes Berg | e7aceef | 2014-02-12 14:21:15 +0100 | [diff] [blame] | 1352 | /* these interface types don't really have a channel */ |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1353 | return; |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 1354 | case NL80211_IFTYPE_UNSPECIFIED: |
Johannes Berg | e7e0517 | 2020-11-09 10:57:47 +0100 | [diff] [blame] | 1355 | case NL80211_IFTYPE_WDS: |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 1356 | case NUM_NL80211_IFTYPES: |
| 1357 | WARN_ON(1); |
| 1358 | } |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 1359 | } |
Johannes Berg | be98989 | 2021-06-18 13:41:39 +0300 | [diff] [blame] | 1360 | |
| 1361 | bool cfg80211_any_usable_channels(struct wiphy *wiphy, |
| 1362 | unsigned long sband_mask, |
| 1363 | u32 prohibited_flags) |
| 1364 | { |
| 1365 | int idx; |
| 1366 | |
| 1367 | prohibited_flags |= IEEE80211_CHAN_DISABLED; |
| 1368 | |
| 1369 | for_each_set_bit(idx, &sband_mask, NUM_NL80211_BANDS) { |
| 1370 | struct ieee80211_supported_band *sband = wiphy->bands[idx]; |
| 1371 | int chanidx; |
| 1372 | |
| 1373 | if (!sband) |
| 1374 | continue; |
| 1375 | |
| 1376 | for (chanidx = 0; chanidx < sband->n_channels; chanidx++) { |
| 1377 | struct ieee80211_channel *chan; |
| 1378 | |
| 1379 | chan = &sband->channels[chanidx]; |
| 1380 | |
| 1381 | if (chan->flags & prohibited_flags) |
| 1382 | continue; |
| 1383 | |
| 1384 | return true; |
| 1385 | } |
| 1386 | } |
| 1387 | |
| 1388 | return false; |
| 1389 | } |
| 1390 | EXPORT_SYMBOL(cfg80211_any_usable_channels); |