mac80211: add freq_offset to RX status
[linux-2.6-block.git] / net / wireless / chan.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
59bbb6f7
JB
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>
2740f0cf 8 * Copyright 2013-2014 Intel Mobile Communications GmbH
925b5978 9 * Copyright 2018 Intel Corporation
59bbb6f7
JB
10 */
11
54858ee5 12#include <linux/export.h>
59bbb6f7
JB
13#include <net/cfg80211.h>
14#include "core.h"
e35e4d28 15#include "rdev-ops.h"
59bbb6f7 16
2a38075c
AAL
17static bool cfg80211_valid_60g_freq(u32 freq)
18{
19 return freq >= 58320 && freq <= 70200;
20}
21
3d9d1d66
JB
22void cfg80211_chandef_create(struct cfg80211_chan_def *chandef,
23 struct ieee80211_channel *chan,
24 enum nl80211_channel_type chan_type)
9236d838 25{
3d9d1d66
JB
26 if (WARN_ON(!chan))
27 return;
9236d838 28
3d9d1d66 29 chandef->chan = chan;
934f4c7d 30 chandef->freq1_offset = chan->freq_offset;
3d9d1d66 31 chandef->center_freq2 = 0;
2a38075c
AAL
32 chandef->edmg.bw_config = 0;
33 chandef->edmg.channels = 0;
4ee3e063 34
3d9d1d66
JB
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;
9236d838 44 case NL80211_CHAN_HT40PLUS:
3d9d1d66
JB
45 chandef->width = NL80211_CHAN_WIDTH_40;
46 chandef->center_freq1 = chan->center_freq + 10;
09a02fdb 47 break;
9236d838 48 case NL80211_CHAN_HT40MINUS:
3d9d1d66
JB
49 chandef->width = NL80211_CHAN_WIDTH_40;
50 chandef->center_freq1 = chan->center_freq - 10;
09a02fdb 51 break;
9236d838 52 default:
3d9d1d66
JB
53 WARN_ON(1);
54 }
55}
56EXPORT_SYMBOL(cfg80211_chandef_create);
57
2a38075c
AAL
58static 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
9f5e8f6e 143bool cfg80211_chandef_valid(const struct cfg80211_chan_def *chandef)
3d9d1d66
JB
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) {
2f301ab2
SW
153 case NL80211_CHAN_WIDTH_5:
154 case NL80211_CHAN_WIDTH_10:
3d9d1d66
JB
155 case NL80211_CHAN_WIDTH_20:
156 case NL80211_CHAN_WIDTH_20_NOHT:
934f4c7d
TP
157 if (ieee80211_chandef_to_khz(chandef) !=
158 ieee80211_channel_to_khz(chandef->chan))
3d9d1d66
JB
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;
9cab3151
JB
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;
3d9d1d66
JB
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
ec649fed
MH
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
2a38075c
AAL
214 if (cfg80211_chandef_is_edmg(chandef) &&
215 !cfg80211_edmg_chandef_valid(chandef))
216 return false;
217
3d9d1d66
JB
218 return true;
219}
9f5e8f6e 220EXPORT_SYMBOL(cfg80211_chandef_valid);
3d9d1d66
JB
221
222static void chandef_primary_freqs(const struct cfg80211_chan_def *c,
fc1f48ff 223 u32 *pri40, u32 *pri80)
3d9d1d66
JB
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
04f39047
SW
258static int cfg80211_chandef_get_width(const struct cfg80211_chan_def *c)
259{
260 int width;
261
262 switch (c->width) {
2f301ab2
SW
263 case NL80211_CHAN_WIDTH_5:
264 width = 5;
265 break;
266 case NL80211_CHAN_WIDTH_10:
267 width = 10;
268 break;
04f39047
SW
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
3d9d1d66
JB
290const struct cfg80211_chan_def *
291cfg80211_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
2f301ab2
SW
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
3d9d1d66
JB
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}
343EXPORT_SYMBOL(cfg80211_chandef_compatible);
344
04f39047
SW
345static 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
364void 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
40d1ba63
JD
386static u32 cfg80211_get_start_freq(u32 center_freq,
387 u32 bandwidth)
388{
389 u32 start_freq;
390
934f4c7d
TP
391 bandwidth = MHZ_TO_KHZ(bandwidth);
392 if (bandwidth <= MHZ_TO_KHZ(20))
40d1ba63
JD
393 start_freq = center_freq;
394 else
934f4c7d 395 start_freq = center_freq - bandwidth / 2 + MHZ_TO_KHZ(10);
40d1ba63
JD
396
397 return start_freq;
398}
399
400static u32 cfg80211_get_end_freq(u32 center_freq,
401 u32 bandwidth)
402{
403 u32 end_freq;
404
934f4c7d
TP
405 bandwidth = MHZ_TO_KHZ(bandwidth);
406 if (bandwidth <= MHZ_TO_KHZ(20))
40d1ba63
JD
407 end_freq = center_freq;
408 else
934f4c7d 409 end_freq = center_freq + bandwidth / 2 - MHZ_TO_KHZ(10);
40d1ba63
JD
410
411 return end_freq;
412}
413
04f39047
SW
414static int cfg80211_get_chans_dfs_required(struct wiphy *wiphy,
415 u32 center_freq,
416 u32 bandwidth)
417{
418 struct ieee80211_channel *c;
2f301ab2
SW
419 u32 freq, start_freq, end_freq;
420
40d1ba63
JD
421 start_freq = cfg80211_get_start_freq(center_freq, bandwidth);
422 end_freq = cfg80211_get_end_freq(center_freq, bandwidth);
04f39047 423
934f4c7d
TP
424 for (freq = start_freq; freq <= end_freq; freq += MHZ_TO_KHZ(20)) {
425 c = ieee80211_get_channel_khz(wiphy, freq);
04f39047
SW
426 if (!c)
427 return -EINVAL;
428
429 if (c->flags & IEEE80211_CHAN_RADAR)
430 return 1;
431 }
432 return 0;
433}
434
435
436int cfg80211_chandef_dfs_required(struct wiphy *wiphy,
2beb6dab
LC
437 const struct cfg80211_chan_def *chandef,
438 enum nl80211_iftype iftype)
04f39047
SW
439{
440 int width;
2beb6dab 441 int ret;
04f39047
SW
442
443 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
444 return -EINVAL;
445
2beb6dab
LC
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;
04f39047 454
2beb6dab 455 ret = cfg80211_get_chans_dfs_required(wiphy,
934f4c7d
TP
456 ieee80211_chandef_to_khz(chandef),
457 width);
2beb6dab
LC
458 if (ret < 0)
459 return ret;
460 else if (ret > 0)
461 return BIT(chandef->width);
04f39047 462
2beb6dab
LC
463 if (!chandef->center_freq2)
464 return 0;
465
466 ret = cfg80211_get_chans_dfs_required(wiphy,
934f4c7d
TP
467 MHZ_TO_KHZ(chandef->center_freq2),
468 width);
2beb6dab
LC
469 if (ret < 0)
470 return ret;
471 else if (ret > 0)
472 return BIT(chandef->width);
04f39047 473
2beb6dab
LC
474 break;
475 case NL80211_IFTYPE_STATION:
6e0bd6c3 476 case NL80211_IFTYPE_OCB:
2beb6dab
LC
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:
cb3b7d87 482 case NL80211_IFTYPE_NAN:
2beb6dab 483 break;
00ec75fc 484 case NL80211_IFTYPE_UNSPECIFIED:
2beb6dab
LC
485 case NUM_NL80211_IFTYPES:
486 WARN_ON(1);
487 }
488
489 return 0;
04f39047 490}
774f0734 491EXPORT_SYMBOL(cfg80211_chandef_dfs_required);
04f39047 492
fe7c3a1f
JD
493static 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 */
934f4c7d
TP
510 for (freq = start_freq; freq <= end_freq; freq += MHZ_TO_KHZ(20)) {
511 c = ieee80211_get_channel_khz(wiphy, freq);
fe7c3a1f
JD
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
530bool 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
934f4c7d
TP
543 r1 = cfg80211_get_chans_dfs_usable(wiphy,
544 MHZ_TO_KHZ(chandef->center_freq1),
545 width);
fe7c3a1f
JD
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,
934f4c7d
TP
554 MHZ_TO_KHZ(chandef->center_freq2),
555 width);
fe7c3a1f
JD
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
b35a51c7
VT
567/*
568 * Checks if center frequency of chan falls with in the bandwidth
569 * range of chandef.
570 */
571bool cfg80211_is_sub_chan(struct cfg80211_chan_def *chandef,
572 struct ieee80211_channel *chan)
573{
574 int width;
a67a4893 575 u32 freq;
b35a51c7
VT
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
b35a51c7
VT
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
602bool 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
89766727
VT
640static bool cfg80211_is_wiphy_oper_chan(struct wiphy *wiphy,
641 struct ieee80211_channel *chan)
b35a51c7
VT
642{
643 struct wireless_dev *wdev;
644
b35a51c7
VT
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}
fe7c3a1f 661
89766727
VT
662bool 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
6bc54fbc
JD
683static bool cfg80211_get_chans_dfs_available(struct wiphy *wiphy,
684 u32 center_freq,
685 u32 bandwidth)
3d9d1d66
JB
686{
687 struct ieee80211_channel *c;
2f301ab2 688 u32 freq, start_freq, end_freq;
2c390e44
DL
689 bool dfs_offload;
690
691 dfs_offload = wiphy_ext_feature_isset(wiphy,
692 NL80211_EXT_FEATURE_DFS_OFFLOAD);
2f301ab2 693
40d1ba63
JD
694 start_freq = cfg80211_get_start_freq(center_freq, bandwidth);
695 end_freq = cfg80211_get_end_freq(center_freq, bandwidth);
3d9d1d66 696
6bc54fbc
JD
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 */
934f4c7d
TP
702 for (freq = start_freq; freq <= end_freq; freq += MHZ_TO_KHZ(20)) {
703 c = ieee80211_get_channel_khz(wiphy, freq);
04f39047
SW
704 if (!c)
705 return false;
706
6bc54fbc
JD
707 if (c->flags & IEEE80211_CHAN_DISABLED)
708 return false;
709
2c390e44
DL
710 if ((c->flags & IEEE80211_CHAN_RADAR) &&
711 (c->dfs_state != NL80211_DFS_AVAILABLE) &&
712 !(c->dfs_state == NL80211_DFS_USABLE && dfs_offload))
04f39047 713 return false;
6bc54fbc
JD
714 }
715
716 return true;
717}
718
719static 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
934f4c7d
TP
732 r = cfg80211_get_chans_dfs_available(wiphy,
733 MHZ_TO_KHZ(chandef->center_freq1),
6bc54fbc
JD
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,
934f4c7d
TP
744 MHZ_TO_KHZ(chandef->center_freq2),
745 width);
680682d4 746 break;
6bc54fbc
JD
747 default:
748 WARN_ON(chandef->center_freq2);
749 break;
750 }
751
752 return r;
753}
754
31559f35
JD
755static 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
934f4c7d
TP
766 for (freq = start_freq; freq <= end_freq; freq += MHZ_TO_KHZ(20)) {
767 c = ieee80211_get_channel_khz(wiphy, freq);
31559f35
JD
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
784unsigned int
785cfg80211_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,
934f4c7d 799 MHZ_TO_KHZ(chandef->center_freq1),
31559f35
JD
800 width);
801
802 if (!chandef->center_freq2)
803 return t1;
804
805 t2 = cfg80211_get_chans_dfs_cac_time(wiphy,
934f4c7d 806 MHZ_TO_KHZ(chandef->center_freq2),
31559f35
JD
807 width);
808
809 return max(t1, t2);
810}
6bc54fbc
JD
811
812static bool cfg80211_secondary_chans_ok(struct wiphy *wiphy,
813 u32 center_freq, u32 bandwidth,
814 u32 prohibited_flags)
815{
816 struct ieee80211_channel *c;
817 u32 freq, start_freq, end_freq;
04f39047 818
6bc54fbc
JD
819 start_freq = cfg80211_get_start_freq(center_freq, bandwidth);
820 end_freq = cfg80211_get_end_freq(center_freq, bandwidth);
821
934f4c7d
TP
822 for (freq = start_freq; freq <= end_freq; freq += MHZ_TO_KHZ(20)) {
823 c = ieee80211_get_channel_khz(wiphy, freq);
6bc54fbc 824 if (!c || c->flags & prohibited_flags)
3d9d1d66 825 return false;
9236d838
LR
826 }
827
3d9d1d66
JB
828 return true;
829}
830
2a38075c
AAL
831/* check if the operating channels are valid and supported */
832static 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
9f5e8f6e
JB
884bool cfg80211_chandef_usable(struct wiphy *wiphy,
885 const struct cfg80211_chan_def *chandef,
886 u32 prohibited_flags)
3d9d1d66 887{
9f5e8f6e
JB
888 struct ieee80211_sta_ht_cap *ht_cap;
889 struct ieee80211_sta_vht_cap *vht_cap;
2a38075c 890 struct ieee80211_edmg *edmg_cap;
08f6f147 891 u32 width, control_freq, cap;
3d9d1d66 892
9f5e8f6e
JB
893 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
894 return false;
3d9d1d66 895
9f5e8f6e
JB
896 ht_cap = &wiphy->bands[chandef->chan->band]->ht_cap;
897 vht_cap = &wiphy->bands[chandef->chan->band]->vht_cap;
2a38075c
AAL
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;
3d9d1d66 907
9f5e8f6e 908 control_freq = chandef->chan->center_freq;
9236d838 909
3d9d1d66 910 switch (chandef->width) {
2f301ab2
SW
911 case NL80211_CHAN_WIDTH_5:
912 width = 5;
913 break;
914 case NL80211_CHAN_WIDTH_10:
ea077c1c 915 prohibited_flags |= IEEE80211_CHAN_NO_10MHZ;
2f301ab2
SW
916 width = 10;
917 break;
3d9d1d66 918 case NL80211_CHAN_WIDTH_20:
9f5e8f6e
JB
919 if (!ht_cap->ht_supported)
920 return false;
925b5978 921 /* fall through */
9f5e8f6e 922 case NL80211_CHAN_WIDTH_20_NOHT:
ea077c1c 923 prohibited_flags |= IEEE80211_CHAN_NO_20MHZ;
3d9d1d66
JB
924 width = 20;
925 break;
926 case NL80211_CHAN_WIDTH_40:
927 width = 40;
9f5e8f6e
JB
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;
3d9d1d66 939 break;
3d9d1d66 940 case NL80211_CHAN_WIDTH_80P80:
08f6f147
JM
941 cap = vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
942 if (cap != IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
9f5e8f6e 943 return false;
925b5978 944 /* fall through */
9f5e8f6e
JB
945 case NL80211_CHAN_WIDTH_80:
946 if (!vht_cap->vht_supported)
947 return false;
c7a6ee27 948 prohibited_flags |= IEEE80211_CHAN_NO_80MHZ;
3d9d1d66
JB
949 width = 80;
950 break;
951 case NL80211_CHAN_WIDTH_160:
9f5e8f6e
JB
952 if (!vht_cap->vht_supported)
953 return false;
08f6f147
JM
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)
9f5e8f6e 957 return false;
c7a6ee27 958 prohibited_flags |= IEEE80211_CHAN_NO_160MHZ;
3d9d1d66
JB
959 width = 160;
960 break;
961 default:
962 WARN_ON_ONCE(1);
9236d838 963 return false;
4ee3e063 964 }
3d9d1d66 965
c7a6ee27
JB
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 */
9f5e8f6e 976
a6662dba
JB
977 if (width > 20)
978 prohibited_flags |= IEEE80211_CHAN_NO_OFDM;
979
2f301ab2
SW
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
934f4c7d
TP
985 if (!cfg80211_secondary_chans_ok(wiphy,
986 ieee80211_chandef_to_khz(chandef),
9f5e8f6e
JB
987 width, prohibited_flags))
988 return false;
989
990 if (!chandef->center_freq2)
991 return true;
934f4c7d
TP
992 return cfg80211_secondary_chans_ok(wiphy,
993 MHZ_TO_KHZ(chandef->center_freq2),
9f5e8f6e
JB
994 width, prohibited_flags);
995}
996EXPORT_SYMBOL(cfg80211_chandef_usable);
997
174e0cd2 998/*
06f207fc
AN
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
174e0cd2
IP
1002 * associated to an AP on the same channel or on the same UNII band
1003 * (assuming that the AP is an authorized master).
06f207fc 1004 * In addition allow operation on a channel on which indoor operation is
c8866e55 1005 * allowed, iff we are currently operating in an indoor environment.
174e0cd2 1006 */
06f207fc
AN
1007static bool cfg80211_ir_permissive_chan(struct wiphy *wiphy,
1008 enum nl80211_iftype iftype,
174e0cd2
IP
1009 struct ieee80211_channel *chan)
1010{
be69c24a 1011 struct wireless_dev *wdev;
06f207fc 1012 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
174e0cd2
IP
1013
1014 ASSERT_RTNL();
1015
97f2645f 1016 if (!IS_ENABLED(CONFIG_CFG80211_REG_RELAX_NO_IR) ||
c8866e55
IP
1017 !(wiphy->regulatory_flags & REGULATORY_ENABLE_RELAX_NO_IR))
1018 return false;
1019
06f207fc
AN
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
c8866e55
IP
1026 if (regulatory_indoor_allowed() &&
1027 (chan->flags & IEEE80211_CHAN_INDOOR_ONLY))
1028 return true;
1029
06f207fc 1030 if (!(chan->flags & IEEE80211_CHAN_IR_CONCURRENT))
174e0cd2
IP
1031 return false;
1032
1033 /*
1034 * Generally, it is possible to rely on another device/driver to allow
06f207fc 1035 * the IR concurrent relaxation, however, since the device can further
174e0cd2
IP
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 */
53873f13 1040 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
174e0cd2
IP
1041 struct ieee80211_channel *other_chan = NULL;
1042 int r1, r2;
1043
be69c24a
AS
1044 wdev_lock(wdev);
1045 if (wdev->iftype == NL80211_IFTYPE_STATION &&
1046 wdev->current_bss)
1047 other_chan = wdev->current_bss->pub.channel;
1048
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 */
06f207fc
AN
1056 if (iftype == NL80211_IFTYPE_P2P_GO &&
1057 wdev->iftype == NL80211_IFTYPE_P2P_GO &&
be69c24a
AS
1058 wdev->beacon_interval &&
1059 !(chan->flags & IEEE80211_CHAN_INDOOR_ONLY))
1060 other_chan = wdev->chandef.chan;
1061 wdev_unlock(wdev);
174e0cd2
IP
1062
1063 if (!other_chan)
1064 continue;
1065
1066 if (chan == other_chan)
1067 return true;
1068
0816e6b1
AS
1069 if (chan->band != NL80211_BAND_5GHZ &&
1070 chan->band != NL80211_BAND_6GHZ)
174e0cd2
IP
1071 continue;
1072
1073 r1 = cfg80211_get_unii(chan->center_freq);
1074 r2 = cfg80211_get_unii(other_chan->center_freq);
1075
46d53724
IP
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;
174e0cd2 1092 return true;
46d53724 1093 }
174e0cd2
IP
1094 }
1095
1096 return false;
1097}
1098
923b352f
AN
1099static bool _cfg80211_reg_can_beacon(struct wiphy *wiphy,
1100 struct cfg80211_chan_def *chandef,
1101 enum nl80211_iftype iftype,
1102 bool check_no_ir)
9f5e8f6e
JB
1103{
1104 bool res;
6bc54fbc 1105 u32 prohibited_flags = IEEE80211_CHAN_DISABLED |
6bc54fbc 1106 IEEE80211_CHAN_RADAR;
9f5e8f6e 1107
923b352f 1108 trace_cfg80211_reg_can_beacon(wiphy, chandef, iftype, check_no_ir);
174e0cd2 1109
923b352f 1110 if (check_no_ir)
174e0cd2 1111 prohibited_flags |= IEEE80211_CHAN_NO_IR;
3d9d1d66 1112
00ec75fc 1113 if (cfg80211_chandef_dfs_required(wiphy, chandef, iftype) > 0 &&
6bc54fbc
JD
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);
3d9d1d66
JB
1120
1121 trace_cfg80211_return_bool(res);
1122 return res;
9236d838 1123}
923b352f
AN
1124
1125bool 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}
683b6d3b 1131EXPORT_SYMBOL(cfg80211_reg_can_beacon);
9236d838 1132
923b352f
AN
1133bool 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}
1152EXPORT_SYMBOL(cfg80211_reg_can_beacon_relax);
1153
e8c9bd5b 1154int cfg80211_set_monitor_channel(struct cfg80211_registered_device *rdev,
683b6d3b 1155 struct cfg80211_chan_def *chandef)
9588bbd5 1156{
e8c9bd5b 1157 if (!rdev->ops->set_monitor_channel)
9588bbd5 1158 return -EOPNOTSUPP;
4f03c1ed
MK
1159 if (!cfg80211_has_monitors_only(rdev))
1160 return -EBUSY;
9588bbd5 1161
683b6d3b 1162 return rdev_set_monitor_channel(rdev, chandef);
59bbb6f7 1163}
26ab9a0c
MK
1164
1165void
8e95ea49 1166cfg80211_get_chan_state(struct wireless_dev *wdev,
26ab9a0c 1167 struct ieee80211_channel **chan,
9e0e2961
MK
1168 enum cfg80211_chan_mode *chanmode,
1169 u8 *radar_detect)
26ab9a0c 1170{
2beb6dab
LC
1171 int ret;
1172
26ab9a0c
MK
1173 *chan = NULL;
1174 *chanmode = CHAN_MODE_UNDEFINED;
1175
26ab9a0c
MK
1176 ASSERT_WDEV_LOCK(wdev);
1177
98104fde 1178 if (wdev->netdev && !netif_running(wdev->netdev))
26ab9a0c
MK
1179 return;
1180
1181 switch (wdev->iftype) {
1182 case NL80211_IFTYPE_ADHOC:
1183 if (wdev->current_bss) {
1184 *chan = wdev->current_bss->pub.channel;
5336fa88
SW
1185 *chanmode = (wdev->ibss_fixed &&
1186 !wdev->ibss_dfs_possible)
26ab9a0c
MK
1187 ? CHAN_MODE_SHARED
1188 : CHAN_MODE_EXCLUSIVE;
9e0e2961
MK
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);
26ab9a0c
MK
1194 return;
1195 }
0f0094b3 1196 break;
26ab9a0c
MK
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:
04f39047 1207 if (wdev->cac_started) {
9e0e2961 1208 *chan = wdev->chandef.chan;
04f39047 1209 *chanmode = CHAN_MODE_SHARED;
9e0e2961 1210 *radar_detect |= BIT(wdev->chandef.width);
04f39047 1211 } else if (wdev->beacon_interval) {
9e0e2961 1212 *chan = wdev->chandef.chan;
f53594a0 1213 *chanmode = CHAN_MODE_SHARED;
9e0e2961 1214
2beb6dab
LC
1215 ret = cfg80211_chandef_dfs_required(wdev->wiphy,
1216 &wdev->chandef,
1217 wdev->iftype);
1218 WARN_ON(ret < 0);
1219 if (ret > 0)
9e0e2961 1220 *radar_detect |= BIT(wdev->chandef.width);
f53594a0
FF
1221 }
1222 return;
26ab9a0c 1223 case NL80211_IFTYPE_MESH_POINT:
f53594a0 1224 if (wdev->mesh_id_len) {
9e0e2961 1225 *chan = wdev->chandef.chan;
f53594a0 1226 *chanmode = CHAN_MODE_SHARED;
9e0e2961 1227
2beb6dab
LC
1228 ret = cfg80211_chandef_dfs_required(wdev->wiphy,
1229 &wdev->chandef,
1230 wdev->iftype);
1231 WARN_ON(ret < 0);
1232 if (ret > 0)
9e0e2961 1233 *radar_detect |= BIT(wdev->chandef.width);
f53594a0 1234 }
26ab9a0c 1235 return;
6e0bd6c3
RL
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;
26ab9a0c
MK
1243 case NL80211_IFTYPE_MONITOR:
1244 case NL80211_IFTYPE_AP_VLAN:
1245 case NL80211_IFTYPE_WDS:
98104fde 1246 case NL80211_IFTYPE_P2P_DEVICE:
cb3b7d87 1247 case NL80211_IFTYPE_NAN:
e7aceef4 1248 /* these interface types don't really have a channel */
98104fde 1249 return;
26ab9a0c
MK
1250 case NL80211_IFTYPE_UNSPECIFIED:
1251 case NUM_NL80211_IFTYPES:
1252 WARN_ON(1);
1253 }
26ab9a0c 1254}