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