Commit | Line | Data |
---|---|---|
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 | |
3d9d1d66 JB |
17 | void cfg80211_chandef_create(struct cfg80211_chan_def *chandef, |
18 | struct ieee80211_channel *chan, | |
19 | enum nl80211_channel_type chan_type) | |
9236d838 | 20 | { |
3d9d1d66 JB |
21 | if (WARN_ON(!chan)) |
22 | return; | |
9236d838 | 23 | |
3d9d1d66 JB |
24 | chandef->chan = chan; |
25 | chandef->center_freq2 = 0; | |
4ee3e063 | 26 | |
3d9d1d66 JB |
27 | switch (chan_type) { |
28 | case NL80211_CHAN_NO_HT: | |
29 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; | |
30 | chandef->center_freq1 = chan->center_freq; | |
31 | break; | |
32 | case NL80211_CHAN_HT20: | |
33 | chandef->width = NL80211_CHAN_WIDTH_20; | |
34 | chandef->center_freq1 = chan->center_freq; | |
35 | break; | |
9236d838 | 36 | case NL80211_CHAN_HT40PLUS: |
3d9d1d66 JB |
37 | chandef->width = NL80211_CHAN_WIDTH_40; |
38 | chandef->center_freq1 = chan->center_freq + 10; | |
09a02fdb | 39 | break; |
9236d838 | 40 | case NL80211_CHAN_HT40MINUS: |
3d9d1d66 JB |
41 | chandef->width = NL80211_CHAN_WIDTH_40; |
42 | chandef->center_freq1 = chan->center_freq - 10; | |
09a02fdb | 43 | break; |
9236d838 | 44 | default: |
3d9d1d66 JB |
45 | WARN_ON(1); |
46 | } | |
47 | } | |
48 | EXPORT_SYMBOL(cfg80211_chandef_create); | |
49 | ||
9f5e8f6e | 50 | bool cfg80211_chandef_valid(const struct cfg80211_chan_def *chandef) |
3d9d1d66 JB |
51 | { |
52 | u32 control_freq; | |
53 | ||
54 | if (!chandef->chan) | |
55 | return false; | |
56 | ||
57 | control_freq = chandef->chan->center_freq; | |
58 | ||
59 | switch (chandef->width) { | |
2f301ab2 SW |
60 | case NL80211_CHAN_WIDTH_5: |
61 | case NL80211_CHAN_WIDTH_10: | |
3d9d1d66 JB |
62 | case NL80211_CHAN_WIDTH_20: |
63 | case NL80211_CHAN_WIDTH_20_NOHT: | |
64 | if (chandef->center_freq1 != control_freq) | |
65 | return false; | |
66 | if (chandef->center_freq2) | |
67 | return false; | |
68 | break; | |
69 | case NL80211_CHAN_WIDTH_40: | |
70 | if (chandef->center_freq1 != control_freq + 10 && | |
71 | chandef->center_freq1 != control_freq - 10) | |
72 | return false; | |
73 | if (chandef->center_freq2) | |
74 | return false; | |
75 | break; | |
76 | case NL80211_CHAN_WIDTH_80P80: | |
77 | if (chandef->center_freq1 != control_freq + 30 && | |
78 | chandef->center_freq1 != control_freq + 10 && | |
79 | chandef->center_freq1 != control_freq - 10 && | |
80 | chandef->center_freq1 != control_freq - 30) | |
81 | return false; | |
82 | if (!chandef->center_freq2) | |
83 | return false; | |
9cab3151 JB |
84 | /* adjacent is not allowed -- that's a 160 MHz channel */ |
85 | if (chandef->center_freq1 - chandef->center_freq2 == 80 || | |
86 | chandef->center_freq2 - chandef->center_freq1 == 80) | |
87 | return false; | |
3d9d1d66 JB |
88 | break; |
89 | case NL80211_CHAN_WIDTH_80: | |
90 | if (chandef->center_freq1 != control_freq + 30 && | |
91 | chandef->center_freq1 != control_freq + 10 && | |
92 | chandef->center_freq1 != control_freq - 10 && | |
93 | chandef->center_freq1 != control_freq - 30) | |
94 | return false; | |
95 | if (chandef->center_freq2) | |
96 | return false; | |
97 | break; | |
98 | case NL80211_CHAN_WIDTH_160: | |
99 | if (chandef->center_freq1 != control_freq + 70 && | |
100 | chandef->center_freq1 != control_freq + 50 && | |
101 | chandef->center_freq1 != control_freq + 30 && | |
102 | chandef->center_freq1 != control_freq + 10 && | |
103 | chandef->center_freq1 != control_freq - 10 && | |
104 | chandef->center_freq1 != control_freq - 30 && | |
105 | chandef->center_freq1 != control_freq - 50 && | |
106 | chandef->center_freq1 != control_freq - 70) | |
107 | return false; | |
108 | if (chandef->center_freq2) | |
109 | return false; | |
110 | break; | |
111 | default: | |
112 | return false; | |
113 | } | |
114 | ||
115 | return true; | |
116 | } | |
9f5e8f6e | 117 | EXPORT_SYMBOL(cfg80211_chandef_valid); |
3d9d1d66 JB |
118 | |
119 | static void chandef_primary_freqs(const struct cfg80211_chan_def *c, | |
fc1f48ff | 120 | u32 *pri40, u32 *pri80) |
3d9d1d66 JB |
121 | { |
122 | int tmp; | |
123 | ||
124 | switch (c->width) { | |
125 | case NL80211_CHAN_WIDTH_40: | |
126 | *pri40 = c->center_freq1; | |
127 | *pri80 = 0; | |
128 | break; | |
129 | case NL80211_CHAN_WIDTH_80: | |
130 | case NL80211_CHAN_WIDTH_80P80: | |
131 | *pri80 = c->center_freq1; | |
132 | /* n_P20 */ | |
133 | tmp = (30 + c->chan->center_freq - c->center_freq1)/20; | |
134 | /* n_P40 */ | |
135 | tmp /= 2; | |
136 | /* freq_P40 */ | |
137 | *pri40 = c->center_freq1 - 20 + 40 * tmp; | |
138 | break; | |
139 | case NL80211_CHAN_WIDTH_160: | |
140 | /* n_P20 */ | |
141 | tmp = (70 + c->chan->center_freq - c->center_freq1)/20; | |
142 | /* n_P40 */ | |
143 | tmp /= 2; | |
144 | /* freq_P40 */ | |
145 | *pri40 = c->center_freq1 - 60 + 40 * tmp; | |
146 | /* n_P80 */ | |
147 | tmp /= 2; | |
148 | *pri80 = c->center_freq1 - 40 + 80 * tmp; | |
149 | break; | |
150 | default: | |
151 | WARN_ON_ONCE(1); | |
152 | } | |
153 | } | |
154 | ||
04f39047 SW |
155 | static int cfg80211_chandef_get_width(const struct cfg80211_chan_def *c) |
156 | { | |
157 | int width; | |
158 | ||
159 | switch (c->width) { | |
2f301ab2 SW |
160 | case NL80211_CHAN_WIDTH_5: |
161 | width = 5; | |
162 | break; | |
163 | case NL80211_CHAN_WIDTH_10: | |
164 | width = 10; | |
165 | break; | |
04f39047 SW |
166 | case NL80211_CHAN_WIDTH_20: |
167 | case NL80211_CHAN_WIDTH_20_NOHT: | |
168 | width = 20; | |
169 | break; | |
170 | case NL80211_CHAN_WIDTH_40: | |
171 | width = 40; | |
172 | break; | |
173 | case NL80211_CHAN_WIDTH_80P80: | |
174 | case NL80211_CHAN_WIDTH_80: | |
175 | width = 80; | |
176 | break; | |
177 | case NL80211_CHAN_WIDTH_160: | |
178 | width = 160; | |
179 | break; | |
180 | default: | |
181 | WARN_ON_ONCE(1); | |
182 | return -1; | |
183 | } | |
184 | return width; | |
185 | } | |
186 | ||
3d9d1d66 JB |
187 | const struct cfg80211_chan_def * |
188 | cfg80211_chandef_compatible(const struct cfg80211_chan_def *c1, | |
189 | const struct cfg80211_chan_def *c2) | |
190 | { | |
191 | u32 c1_pri40, c1_pri80, c2_pri40, c2_pri80; | |
192 | ||
193 | /* If they are identical, return */ | |
194 | if (cfg80211_chandef_identical(c1, c2)) | |
195 | return c1; | |
196 | ||
197 | /* otherwise, must have same control channel */ | |
198 | if (c1->chan != c2->chan) | |
199 | return NULL; | |
200 | ||
201 | /* | |
202 | * If they have the same width, but aren't identical, | |
203 | * then they can't be compatible. | |
204 | */ | |
205 | if (c1->width == c2->width) | |
206 | return NULL; | |
207 | ||
2f301ab2 SW |
208 | /* |
209 | * can't be compatible if one of them is 5 or 10 MHz, | |
210 | * but they don't have the same width. | |
211 | */ | |
212 | if (c1->width == NL80211_CHAN_WIDTH_5 || | |
213 | c1->width == NL80211_CHAN_WIDTH_10 || | |
214 | c2->width == NL80211_CHAN_WIDTH_5 || | |
215 | c2->width == NL80211_CHAN_WIDTH_10) | |
216 | return NULL; | |
217 | ||
3d9d1d66 JB |
218 | if (c1->width == NL80211_CHAN_WIDTH_20_NOHT || |
219 | c1->width == NL80211_CHAN_WIDTH_20) | |
220 | return c2; | |
221 | ||
222 | if (c2->width == NL80211_CHAN_WIDTH_20_NOHT || | |
223 | c2->width == NL80211_CHAN_WIDTH_20) | |
224 | return c1; | |
225 | ||
226 | chandef_primary_freqs(c1, &c1_pri40, &c1_pri80); | |
227 | chandef_primary_freqs(c2, &c2_pri40, &c2_pri80); | |
228 | ||
229 | if (c1_pri40 != c2_pri40) | |
230 | return NULL; | |
231 | ||
232 | WARN_ON(!c1_pri80 && !c2_pri80); | |
233 | if (c1_pri80 && c2_pri80 && c1_pri80 != c2_pri80) | |
234 | return NULL; | |
235 | ||
236 | if (c1->width > c2->width) | |
237 | return c1; | |
238 | return c2; | |
239 | } | |
240 | EXPORT_SYMBOL(cfg80211_chandef_compatible); | |
241 | ||
04f39047 SW |
242 | static void cfg80211_set_chans_dfs_state(struct wiphy *wiphy, u32 center_freq, |
243 | u32 bandwidth, | |
244 | enum nl80211_dfs_state dfs_state) | |
245 | { | |
246 | struct ieee80211_channel *c; | |
247 | u32 freq; | |
248 | ||
249 | for (freq = center_freq - bandwidth/2 + 10; | |
250 | freq <= center_freq + bandwidth/2 - 10; | |
251 | freq += 20) { | |
252 | c = ieee80211_get_channel(wiphy, freq); | |
253 | if (!c || !(c->flags & IEEE80211_CHAN_RADAR)) | |
254 | continue; | |
255 | ||
256 | c->dfs_state = dfs_state; | |
257 | c->dfs_state_entered = jiffies; | |
258 | } | |
259 | } | |
260 | ||
261 | void cfg80211_set_dfs_state(struct wiphy *wiphy, | |
262 | const struct cfg80211_chan_def *chandef, | |
263 | enum nl80211_dfs_state dfs_state) | |
264 | { | |
265 | int width; | |
266 | ||
267 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) | |
268 | return; | |
269 | ||
270 | width = cfg80211_chandef_get_width(chandef); | |
271 | if (width < 0) | |
272 | return; | |
273 | ||
274 | cfg80211_set_chans_dfs_state(wiphy, chandef->center_freq1, | |
275 | width, dfs_state); | |
276 | ||
277 | if (!chandef->center_freq2) | |
278 | return; | |
279 | cfg80211_set_chans_dfs_state(wiphy, chandef->center_freq2, | |
280 | width, dfs_state); | |
281 | } | |
282 | ||
40d1ba63 JD |
283 | static u32 cfg80211_get_start_freq(u32 center_freq, |
284 | u32 bandwidth) | |
285 | { | |
286 | u32 start_freq; | |
287 | ||
288 | if (bandwidth <= 20) | |
289 | start_freq = center_freq; | |
290 | else | |
291 | start_freq = center_freq - bandwidth/2 + 10; | |
292 | ||
293 | return start_freq; | |
294 | } | |
295 | ||
296 | static u32 cfg80211_get_end_freq(u32 center_freq, | |
297 | u32 bandwidth) | |
298 | { | |
299 | u32 end_freq; | |
300 | ||
301 | if (bandwidth <= 20) | |
302 | end_freq = center_freq; | |
303 | else | |
304 | end_freq = center_freq + bandwidth/2 - 10; | |
305 | ||
306 | return end_freq; | |
307 | } | |
308 | ||
04f39047 SW |
309 | static int cfg80211_get_chans_dfs_required(struct wiphy *wiphy, |
310 | u32 center_freq, | |
311 | u32 bandwidth) | |
312 | { | |
313 | struct ieee80211_channel *c; | |
2f301ab2 SW |
314 | u32 freq, start_freq, end_freq; |
315 | ||
40d1ba63 JD |
316 | start_freq = cfg80211_get_start_freq(center_freq, bandwidth); |
317 | end_freq = cfg80211_get_end_freq(center_freq, bandwidth); | |
04f39047 | 318 | |
2f301ab2 | 319 | for (freq = start_freq; freq <= end_freq; freq += 20) { |
04f39047 SW |
320 | c = ieee80211_get_channel(wiphy, freq); |
321 | if (!c) | |
322 | return -EINVAL; | |
323 | ||
324 | if (c->flags & IEEE80211_CHAN_RADAR) | |
325 | return 1; | |
326 | } | |
327 | return 0; | |
328 | } | |
329 | ||
330 | ||
331 | int cfg80211_chandef_dfs_required(struct wiphy *wiphy, | |
2beb6dab LC |
332 | const struct cfg80211_chan_def *chandef, |
333 | enum nl80211_iftype iftype) | |
04f39047 SW |
334 | { |
335 | int width; | |
2beb6dab | 336 | int ret; |
04f39047 SW |
337 | |
338 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) | |
339 | return -EINVAL; | |
340 | ||
2beb6dab LC |
341 | switch (iftype) { |
342 | case NL80211_IFTYPE_ADHOC: | |
343 | case NL80211_IFTYPE_AP: | |
344 | case NL80211_IFTYPE_P2P_GO: | |
345 | case NL80211_IFTYPE_MESH_POINT: | |
346 | width = cfg80211_chandef_get_width(chandef); | |
347 | if (width < 0) | |
348 | return -EINVAL; | |
04f39047 | 349 | |
2beb6dab LC |
350 | ret = cfg80211_get_chans_dfs_required(wiphy, |
351 | chandef->center_freq1, | |
352 | width); | |
353 | if (ret < 0) | |
354 | return ret; | |
355 | else if (ret > 0) | |
356 | return BIT(chandef->width); | |
04f39047 | 357 | |
2beb6dab LC |
358 | if (!chandef->center_freq2) |
359 | return 0; | |
360 | ||
361 | ret = cfg80211_get_chans_dfs_required(wiphy, | |
362 | chandef->center_freq2, | |
363 | width); | |
364 | if (ret < 0) | |
365 | return ret; | |
366 | else if (ret > 0) | |
367 | return BIT(chandef->width); | |
04f39047 | 368 | |
2beb6dab LC |
369 | break; |
370 | case NL80211_IFTYPE_STATION: | |
6e0bd6c3 | 371 | case NL80211_IFTYPE_OCB: |
2beb6dab LC |
372 | case NL80211_IFTYPE_P2P_CLIENT: |
373 | case NL80211_IFTYPE_MONITOR: | |
374 | case NL80211_IFTYPE_AP_VLAN: | |
375 | case NL80211_IFTYPE_WDS: | |
376 | case NL80211_IFTYPE_P2P_DEVICE: | |
cb3b7d87 | 377 | case NL80211_IFTYPE_NAN: |
2beb6dab | 378 | break; |
00ec75fc | 379 | case NL80211_IFTYPE_UNSPECIFIED: |
2beb6dab LC |
380 | case NUM_NL80211_IFTYPES: |
381 | WARN_ON(1); | |
382 | } | |
383 | ||
384 | return 0; | |
04f39047 | 385 | } |
774f0734 | 386 | EXPORT_SYMBOL(cfg80211_chandef_dfs_required); |
04f39047 | 387 | |
fe7c3a1f JD |
388 | static int cfg80211_get_chans_dfs_usable(struct wiphy *wiphy, |
389 | u32 center_freq, | |
390 | u32 bandwidth) | |
391 | { | |
392 | struct ieee80211_channel *c; | |
393 | u32 freq, start_freq, end_freq; | |
394 | int count = 0; | |
395 | ||
396 | start_freq = cfg80211_get_start_freq(center_freq, bandwidth); | |
397 | end_freq = cfg80211_get_end_freq(center_freq, bandwidth); | |
398 | ||
399 | /* | |
400 | * Check entire range of channels for the bandwidth. | |
401 | * Check all channels are DFS channels (DFS_USABLE or | |
402 | * DFS_AVAILABLE). Return number of usable channels | |
403 | * (require CAC). Allow DFS and non-DFS channel mix. | |
404 | */ | |
405 | for (freq = start_freq; freq <= end_freq; freq += 20) { | |
406 | c = ieee80211_get_channel(wiphy, freq); | |
407 | if (!c) | |
408 | return -EINVAL; | |
409 | ||
410 | if (c->flags & IEEE80211_CHAN_DISABLED) | |
411 | return -EINVAL; | |
412 | ||
413 | if (c->flags & IEEE80211_CHAN_RADAR) { | |
414 | if (c->dfs_state == NL80211_DFS_UNAVAILABLE) | |
415 | return -EINVAL; | |
416 | ||
417 | if (c->dfs_state == NL80211_DFS_USABLE) | |
418 | count++; | |
419 | } | |
420 | } | |
421 | ||
422 | return count; | |
423 | } | |
424 | ||
425 | bool cfg80211_chandef_dfs_usable(struct wiphy *wiphy, | |
426 | const struct cfg80211_chan_def *chandef) | |
427 | { | |
428 | int width; | |
429 | int r1, r2 = 0; | |
430 | ||
431 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) | |
432 | return false; | |
433 | ||
434 | width = cfg80211_chandef_get_width(chandef); | |
435 | if (width < 0) | |
436 | return false; | |
437 | ||
438 | r1 = cfg80211_get_chans_dfs_usable(wiphy, chandef->center_freq1, | |
439 | width); | |
440 | ||
441 | if (r1 < 0) | |
442 | return false; | |
443 | ||
444 | switch (chandef->width) { | |
445 | case NL80211_CHAN_WIDTH_80P80: | |
446 | WARN_ON(!chandef->center_freq2); | |
447 | r2 = cfg80211_get_chans_dfs_usable(wiphy, | |
448 | chandef->center_freq2, | |
449 | width); | |
450 | if (r2 < 0) | |
451 | return false; | |
452 | break; | |
453 | default: | |
454 | WARN_ON(chandef->center_freq2); | |
455 | break; | |
456 | } | |
457 | ||
458 | return (r1 + r2 > 0); | |
459 | } | |
460 | ||
b35a51c7 VT |
461 | /* |
462 | * Checks if center frequency of chan falls with in the bandwidth | |
463 | * range of chandef. | |
464 | */ | |
465 | bool cfg80211_is_sub_chan(struct cfg80211_chan_def *chandef, | |
466 | struct ieee80211_channel *chan) | |
467 | { | |
468 | int width; | |
a67a4893 | 469 | u32 freq; |
b35a51c7 VT |
470 | |
471 | if (chandef->chan->center_freq == chan->center_freq) | |
472 | return true; | |
473 | ||
474 | width = cfg80211_chandef_get_width(chandef); | |
475 | if (width <= 20) | |
476 | return false; | |
477 | ||
b35a51c7 VT |
478 | for (freq = chandef->center_freq1 - width / 2 + 10; |
479 | freq <= chandef->center_freq1 + width / 2 - 10; freq += 20) { | |
480 | if (chan->center_freq == freq) | |
481 | return true; | |
482 | } | |
483 | ||
484 | if (!chandef->center_freq2) | |
485 | return false; | |
486 | ||
487 | for (freq = chandef->center_freq2 - width / 2 + 10; | |
488 | freq <= chandef->center_freq2 + width / 2 - 10; freq += 20) { | |
489 | if (chan->center_freq == freq) | |
490 | return true; | |
491 | } | |
492 | ||
493 | return false; | |
494 | } | |
495 | ||
496 | bool cfg80211_beaconing_iface_active(struct wireless_dev *wdev) | |
497 | { | |
498 | bool active = false; | |
499 | ||
500 | ASSERT_WDEV_LOCK(wdev); | |
501 | ||
502 | if (!wdev->chandef.chan) | |
503 | return false; | |
504 | ||
505 | switch (wdev->iftype) { | |
506 | case NL80211_IFTYPE_AP: | |
507 | case NL80211_IFTYPE_P2P_GO: | |
508 | active = wdev->beacon_interval != 0; | |
509 | break; | |
510 | case NL80211_IFTYPE_ADHOC: | |
511 | active = wdev->ssid_len != 0; | |
512 | break; | |
513 | case NL80211_IFTYPE_MESH_POINT: | |
514 | active = wdev->mesh_id_len != 0; | |
515 | break; | |
516 | case NL80211_IFTYPE_STATION: | |
517 | case NL80211_IFTYPE_OCB: | |
518 | case NL80211_IFTYPE_P2P_CLIENT: | |
519 | case NL80211_IFTYPE_MONITOR: | |
520 | case NL80211_IFTYPE_AP_VLAN: | |
521 | case NL80211_IFTYPE_WDS: | |
522 | case NL80211_IFTYPE_P2P_DEVICE: | |
523 | /* Can NAN type be considered as beaconing interface? */ | |
524 | case NL80211_IFTYPE_NAN: | |
525 | break; | |
526 | case NL80211_IFTYPE_UNSPECIFIED: | |
527 | case NUM_NL80211_IFTYPES: | |
528 | WARN_ON(1); | |
529 | } | |
530 | ||
531 | return active; | |
532 | } | |
533 | ||
89766727 VT |
534 | static bool cfg80211_is_wiphy_oper_chan(struct wiphy *wiphy, |
535 | struct ieee80211_channel *chan) | |
b35a51c7 VT |
536 | { |
537 | struct wireless_dev *wdev; | |
538 | ||
b35a51c7 VT |
539 | list_for_each_entry(wdev, &wiphy->wdev_list, list) { |
540 | wdev_lock(wdev); | |
541 | if (!cfg80211_beaconing_iface_active(wdev)) { | |
542 | wdev_unlock(wdev); | |
543 | continue; | |
544 | } | |
545 | ||
546 | if (cfg80211_is_sub_chan(&wdev->chandef, chan)) { | |
547 | wdev_unlock(wdev); | |
548 | return true; | |
549 | } | |
550 | wdev_unlock(wdev); | |
551 | } | |
552 | ||
553 | return false; | |
554 | } | |
fe7c3a1f | 555 | |
89766727 VT |
556 | bool cfg80211_any_wiphy_oper_chan(struct wiphy *wiphy, |
557 | struct ieee80211_channel *chan) | |
558 | { | |
559 | struct cfg80211_registered_device *rdev; | |
560 | ||
561 | ASSERT_RTNL(); | |
562 | ||
563 | if (!(chan->flags & IEEE80211_CHAN_RADAR)) | |
564 | return false; | |
565 | ||
566 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { | |
567 | if (!reg_dfs_domain_same(wiphy, &rdev->wiphy)) | |
568 | continue; | |
569 | ||
570 | if (cfg80211_is_wiphy_oper_chan(&rdev->wiphy, chan)) | |
571 | return true; | |
572 | } | |
573 | ||
574 | return false; | |
575 | } | |
576 | ||
6bc54fbc JD |
577 | static bool cfg80211_get_chans_dfs_available(struct wiphy *wiphy, |
578 | u32 center_freq, | |
579 | u32 bandwidth) | |
3d9d1d66 JB |
580 | { |
581 | struct ieee80211_channel *c; | |
2f301ab2 | 582 | u32 freq, start_freq, end_freq; |
2c390e44 DL |
583 | bool dfs_offload; |
584 | ||
585 | dfs_offload = wiphy_ext_feature_isset(wiphy, | |
586 | NL80211_EXT_FEATURE_DFS_OFFLOAD); | |
2f301ab2 | 587 | |
40d1ba63 JD |
588 | start_freq = cfg80211_get_start_freq(center_freq, bandwidth); |
589 | end_freq = cfg80211_get_end_freq(center_freq, bandwidth); | |
3d9d1d66 | 590 | |
6bc54fbc JD |
591 | /* |
592 | * Check entire range of channels for the bandwidth. | |
593 | * If any channel in between is disabled or has not | |
594 | * had gone through CAC return false | |
595 | */ | |
2f301ab2 | 596 | for (freq = start_freq; freq <= end_freq; freq += 20) { |
3d9d1d66 | 597 | c = ieee80211_get_channel(wiphy, freq); |
04f39047 SW |
598 | if (!c) |
599 | return false; | |
600 | ||
6bc54fbc JD |
601 | if (c->flags & IEEE80211_CHAN_DISABLED) |
602 | return false; | |
603 | ||
2c390e44 DL |
604 | if ((c->flags & IEEE80211_CHAN_RADAR) && |
605 | (c->dfs_state != NL80211_DFS_AVAILABLE) && | |
606 | !(c->dfs_state == NL80211_DFS_USABLE && dfs_offload)) | |
04f39047 | 607 | return false; |
6bc54fbc JD |
608 | } |
609 | ||
610 | return true; | |
611 | } | |
612 | ||
613 | static bool cfg80211_chandef_dfs_available(struct wiphy *wiphy, | |
614 | const struct cfg80211_chan_def *chandef) | |
615 | { | |
616 | int width; | |
617 | int r; | |
618 | ||
619 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) | |
620 | return false; | |
621 | ||
622 | width = cfg80211_chandef_get_width(chandef); | |
623 | if (width < 0) | |
624 | return false; | |
625 | ||
626 | r = cfg80211_get_chans_dfs_available(wiphy, chandef->center_freq1, | |
627 | width); | |
628 | ||
629 | /* If any of channels unavailable for cf1 just return */ | |
630 | if (!r) | |
631 | return r; | |
632 | ||
633 | switch (chandef->width) { | |
634 | case NL80211_CHAN_WIDTH_80P80: | |
635 | WARN_ON(!chandef->center_freq2); | |
636 | r = cfg80211_get_chans_dfs_available(wiphy, | |
637 | chandef->center_freq2, | |
638 | width); | |
680682d4 | 639 | break; |
6bc54fbc JD |
640 | default: |
641 | WARN_ON(chandef->center_freq2); | |
642 | break; | |
643 | } | |
644 | ||
645 | return r; | |
646 | } | |
647 | ||
31559f35 JD |
648 | static unsigned int cfg80211_get_chans_dfs_cac_time(struct wiphy *wiphy, |
649 | u32 center_freq, | |
650 | u32 bandwidth) | |
651 | { | |
652 | struct ieee80211_channel *c; | |
653 | u32 start_freq, end_freq, freq; | |
654 | unsigned int dfs_cac_ms = 0; | |
655 | ||
656 | start_freq = cfg80211_get_start_freq(center_freq, bandwidth); | |
657 | end_freq = cfg80211_get_end_freq(center_freq, bandwidth); | |
658 | ||
659 | for (freq = start_freq; freq <= end_freq; freq += 20) { | |
660 | c = ieee80211_get_channel(wiphy, freq); | |
661 | if (!c) | |
662 | return 0; | |
663 | ||
664 | if (c->flags & IEEE80211_CHAN_DISABLED) | |
665 | return 0; | |
666 | ||
667 | if (!(c->flags & IEEE80211_CHAN_RADAR)) | |
668 | continue; | |
669 | ||
670 | if (c->dfs_cac_ms > dfs_cac_ms) | |
671 | dfs_cac_ms = c->dfs_cac_ms; | |
672 | } | |
673 | ||
674 | return dfs_cac_ms; | |
675 | } | |
676 | ||
677 | unsigned int | |
678 | cfg80211_chandef_dfs_cac_time(struct wiphy *wiphy, | |
679 | const struct cfg80211_chan_def *chandef) | |
680 | { | |
681 | int width; | |
682 | unsigned int t1 = 0, t2 = 0; | |
683 | ||
684 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) | |
685 | return 0; | |
686 | ||
687 | width = cfg80211_chandef_get_width(chandef); | |
688 | if (width < 0) | |
689 | return 0; | |
690 | ||
691 | t1 = cfg80211_get_chans_dfs_cac_time(wiphy, | |
692 | chandef->center_freq1, | |
693 | width); | |
694 | ||
695 | if (!chandef->center_freq2) | |
696 | return t1; | |
697 | ||
698 | t2 = cfg80211_get_chans_dfs_cac_time(wiphy, | |
699 | chandef->center_freq2, | |
700 | width); | |
701 | ||
702 | return max(t1, t2); | |
703 | } | |
6bc54fbc JD |
704 | |
705 | static bool cfg80211_secondary_chans_ok(struct wiphy *wiphy, | |
706 | u32 center_freq, u32 bandwidth, | |
707 | u32 prohibited_flags) | |
708 | { | |
709 | struct ieee80211_channel *c; | |
710 | u32 freq, start_freq, end_freq; | |
04f39047 | 711 | |
6bc54fbc JD |
712 | start_freq = cfg80211_get_start_freq(center_freq, bandwidth); |
713 | end_freq = cfg80211_get_end_freq(center_freq, bandwidth); | |
714 | ||
715 | for (freq = start_freq; freq <= end_freq; freq += 20) { | |
716 | c = ieee80211_get_channel(wiphy, freq); | |
717 | if (!c || c->flags & prohibited_flags) | |
3d9d1d66 | 718 | return false; |
9236d838 LR |
719 | } |
720 | ||
3d9d1d66 JB |
721 | return true; |
722 | } | |
723 | ||
9f5e8f6e JB |
724 | bool cfg80211_chandef_usable(struct wiphy *wiphy, |
725 | const struct cfg80211_chan_def *chandef, | |
726 | u32 prohibited_flags) | |
3d9d1d66 | 727 | { |
9f5e8f6e JB |
728 | struct ieee80211_sta_ht_cap *ht_cap; |
729 | struct ieee80211_sta_vht_cap *vht_cap; | |
08f6f147 | 730 | u32 width, control_freq, cap; |
3d9d1d66 | 731 | |
9f5e8f6e JB |
732 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
733 | return false; | |
3d9d1d66 | 734 | |
9f5e8f6e JB |
735 | ht_cap = &wiphy->bands[chandef->chan->band]->ht_cap; |
736 | vht_cap = &wiphy->bands[chandef->chan->band]->vht_cap; | |
3d9d1d66 | 737 | |
9f5e8f6e | 738 | control_freq = chandef->chan->center_freq; |
9236d838 | 739 | |
3d9d1d66 | 740 | switch (chandef->width) { |
2f301ab2 SW |
741 | case NL80211_CHAN_WIDTH_5: |
742 | width = 5; | |
743 | break; | |
744 | case NL80211_CHAN_WIDTH_10: | |
ea077c1c | 745 | prohibited_flags |= IEEE80211_CHAN_NO_10MHZ; |
2f301ab2 SW |
746 | width = 10; |
747 | break; | |
3d9d1d66 | 748 | case NL80211_CHAN_WIDTH_20: |
9f5e8f6e JB |
749 | if (!ht_cap->ht_supported) |
750 | return false; | |
925b5978 | 751 | /* fall through */ |
9f5e8f6e | 752 | case NL80211_CHAN_WIDTH_20_NOHT: |
ea077c1c | 753 | prohibited_flags |= IEEE80211_CHAN_NO_20MHZ; |
3d9d1d66 JB |
754 | width = 20; |
755 | break; | |
756 | case NL80211_CHAN_WIDTH_40: | |
757 | width = 40; | |
9f5e8f6e JB |
758 | if (!ht_cap->ht_supported) |
759 | return false; | |
760 | if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) || | |
761 | ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT) | |
762 | return false; | |
763 | if (chandef->center_freq1 < control_freq && | |
764 | chandef->chan->flags & IEEE80211_CHAN_NO_HT40MINUS) | |
765 | return false; | |
766 | if (chandef->center_freq1 > control_freq && | |
767 | chandef->chan->flags & IEEE80211_CHAN_NO_HT40PLUS) | |
768 | return false; | |
3d9d1d66 | 769 | break; |
3d9d1d66 | 770 | case NL80211_CHAN_WIDTH_80P80: |
08f6f147 JM |
771 | cap = vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK; |
772 | if (cap != IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ) | |
9f5e8f6e | 773 | return false; |
925b5978 | 774 | /* fall through */ |
9f5e8f6e JB |
775 | case NL80211_CHAN_WIDTH_80: |
776 | if (!vht_cap->vht_supported) | |
777 | return false; | |
c7a6ee27 | 778 | prohibited_flags |= IEEE80211_CHAN_NO_80MHZ; |
3d9d1d66 JB |
779 | width = 80; |
780 | break; | |
781 | case NL80211_CHAN_WIDTH_160: | |
9f5e8f6e JB |
782 | if (!vht_cap->vht_supported) |
783 | return false; | |
08f6f147 JM |
784 | cap = vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK; |
785 | if (cap != IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ && | |
786 | cap != IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ) | |
9f5e8f6e | 787 | return false; |
c7a6ee27 | 788 | prohibited_flags |= IEEE80211_CHAN_NO_160MHZ; |
3d9d1d66 JB |
789 | width = 160; |
790 | break; | |
791 | default: | |
792 | WARN_ON_ONCE(1); | |
9236d838 | 793 | return false; |
4ee3e063 | 794 | } |
3d9d1d66 | 795 | |
c7a6ee27 JB |
796 | /* |
797 | * TODO: What if there are only certain 80/160/80+80 MHz channels | |
798 | * allowed by the driver, or only certain combinations? | |
799 | * For 40 MHz the driver can set the NO_HT40 flags, but for | |
800 | * 80/160 MHz and in particular 80+80 MHz this isn't really | |
801 | * feasible and we only have NO_80MHZ/NO_160MHZ so far but | |
802 | * no way to cover 80+80 MHz or more complex restrictions. | |
803 | * Note that such restrictions also need to be advertised to | |
804 | * userspace, for example for P2P channel selection. | |
805 | */ | |
9f5e8f6e | 806 | |
a6662dba JB |
807 | if (width > 20) |
808 | prohibited_flags |= IEEE80211_CHAN_NO_OFDM; | |
809 | ||
2f301ab2 SW |
810 | /* 5 and 10 MHz are only defined for the OFDM PHY */ |
811 | if (width < 20) | |
812 | prohibited_flags |= IEEE80211_CHAN_NO_OFDM; | |
813 | ||
814 | ||
9f5e8f6e JB |
815 | if (!cfg80211_secondary_chans_ok(wiphy, chandef->center_freq1, |
816 | width, prohibited_flags)) | |
817 | return false; | |
818 | ||
819 | if (!chandef->center_freq2) | |
820 | return true; | |
821 | return cfg80211_secondary_chans_ok(wiphy, chandef->center_freq2, | |
822 | width, prohibited_flags); | |
823 | } | |
824 | EXPORT_SYMBOL(cfg80211_chandef_usable); | |
825 | ||
174e0cd2 | 826 | /* |
06f207fc AN |
827 | * Check if the channel can be used under permissive conditions mandated by |
828 | * some regulatory bodies, i.e., the channel is marked with | |
829 | * IEEE80211_CHAN_IR_CONCURRENT and there is an additional station interface | |
174e0cd2 IP |
830 | * associated to an AP on the same channel or on the same UNII band |
831 | * (assuming that the AP is an authorized master). | |
06f207fc | 832 | * In addition allow operation on a channel on which indoor operation is |
c8866e55 | 833 | * allowed, iff we are currently operating in an indoor environment. |
174e0cd2 | 834 | */ |
06f207fc AN |
835 | static bool cfg80211_ir_permissive_chan(struct wiphy *wiphy, |
836 | enum nl80211_iftype iftype, | |
174e0cd2 IP |
837 | struct ieee80211_channel *chan) |
838 | { | |
be69c24a | 839 | struct wireless_dev *wdev; |
06f207fc | 840 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
174e0cd2 IP |
841 | |
842 | ASSERT_RTNL(); | |
843 | ||
97f2645f | 844 | if (!IS_ENABLED(CONFIG_CFG80211_REG_RELAX_NO_IR) || |
c8866e55 IP |
845 | !(wiphy->regulatory_flags & REGULATORY_ENABLE_RELAX_NO_IR)) |
846 | return false; | |
847 | ||
06f207fc AN |
848 | /* only valid for GO and TDLS off-channel (station/p2p-CL) */ |
849 | if (iftype != NL80211_IFTYPE_P2P_GO && | |
850 | iftype != NL80211_IFTYPE_STATION && | |
851 | iftype != NL80211_IFTYPE_P2P_CLIENT) | |
852 | return false; | |
853 | ||
c8866e55 IP |
854 | if (regulatory_indoor_allowed() && |
855 | (chan->flags & IEEE80211_CHAN_INDOOR_ONLY)) | |
856 | return true; | |
857 | ||
06f207fc | 858 | if (!(chan->flags & IEEE80211_CHAN_IR_CONCURRENT)) |
174e0cd2 IP |
859 | return false; |
860 | ||
861 | /* | |
862 | * Generally, it is possible to rely on another device/driver to allow | |
06f207fc | 863 | * the IR concurrent relaxation, however, since the device can further |
174e0cd2 IP |
864 | * enforce the relaxation (by doing a similar verifications as this), |
865 | * and thus fail the GO instantiation, consider only the interfaces of | |
866 | * the current registered device. | |
867 | */ | |
53873f13 | 868 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
174e0cd2 IP |
869 | struct ieee80211_channel *other_chan = NULL; |
870 | int r1, r2; | |
871 | ||
be69c24a AS |
872 | wdev_lock(wdev); |
873 | if (wdev->iftype == NL80211_IFTYPE_STATION && | |
874 | wdev->current_bss) | |
875 | other_chan = wdev->current_bss->pub.channel; | |
876 | ||
877 | /* | |
878 | * If a GO already operates on the same GO_CONCURRENT channel, | |
879 | * this one (maybe the same one) can beacon as well. We allow | |
880 | * the operation even if the station we relied on with | |
881 | * GO_CONCURRENT is disconnected now. But then we must make sure | |
882 | * we're not outdoor on an indoor-only channel. | |
883 | */ | |
06f207fc AN |
884 | if (iftype == NL80211_IFTYPE_P2P_GO && |
885 | wdev->iftype == NL80211_IFTYPE_P2P_GO && | |
be69c24a AS |
886 | wdev->beacon_interval && |
887 | !(chan->flags & IEEE80211_CHAN_INDOOR_ONLY)) | |
888 | other_chan = wdev->chandef.chan; | |
889 | wdev_unlock(wdev); | |
174e0cd2 IP |
890 | |
891 | if (!other_chan) | |
892 | continue; | |
893 | ||
894 | if (chan == other_chan) | |
895 | return true; | |
896 | ||
57fbcce3 | 897 | if (chan->band != NL80211_BAND_5GHZ) |
174e0cd2 IP |
898 | continue; |
899 | ||
900 | r1 = cfg80211_get_unii(chan->center_freq); | |
901 | r2 = cfg80211_get_unii(other_chan->center_freq); | |
902 | ||
46d53724 IP |
903 | if (r1 != -EINVAL && r1 == r2) { |
904 | /* | |
905 | * At some locations channels 149-165 are considered a | |
906 | * bundle, but at other locations, e.g., Indonesia, | |
907 | * channels 149-161 are considered a bundle while | |
908 | * channel 165 is left out and considered to be in a | |
909 | * different bundle. Thus, in case that there is a | |
910 | * station interface connected to an AP on channel 165, | |
911 | * it is assumed that channels 149-161 are allowed for | |
912 | * GO operations. However, having a station interface | |
913 | * connected to an AP on channels 149-161, does not | |
914 | * allow GO operation on channel 165. | |
915 | */ | |
916 | if (chan->center_freq == 5825 && | |
917 | other_chan->center_freq != 5825) | |
918 | continue; | |
174e0cd2 | 919 | return true; |
46d53724 | 920 | } |
174e0cd2 IP |
921 | } |
922 | ||
923 | return false; | |
924 | } | |
925 | ||
923b352f AN |
926 | static bool _cfg80211_reg_can_beacon(struct wiphy *wiphy, |
927 | struct cfg80211_chan_def *chandef, | |
928 | enum nl80211_iftype iftype, | |
929 | bool check_no_ir) | |
9f5e8f6e JB |
930 | { |
931 | bool res; | |
6bc54fbc | 932 | u32 prohibited_flags = IEEE80211_CHAN_DISABLED | |
6bc54fbc | 933 | IEEE80211_CHAN_RADAR; |
9f5e8f6e | 934 | |
923b352f | 935 | trace_cfg80211_reg_can_beacon(wiphy, chandef, iftype, check_no_ir); |
174e0cd2 | 936 | |
923b352f | 937 | if (check_no_ir) |
174e0cd2 | 938 | prohibited_flags |= IEEE80211_CHAN_NO_IR; |
3d9d1d66 | 939 | |
00ec75fc | 940 | if (cfg80211_chandef_dfs_required(wiphy, chandef, iftype) > 0 && |
6bc54fbc JD |
941 | cfg80211_chandef_dfs_available(wiphy, chandef)) { |
942 | /* We can skip IEEE80211_CHAN_NO_IR if chandef dfs available */ | |
943 | prohibited_flags = IEEE80211_CHAN_DISABLED; | |
944 | } | |
945 | ||
946 | res = cfg80211_chandef_usable(wiphy, chandef, prohibited_flags); | |
3d9d1d66 JB |
947 | |
948 | trace_cfg80211_return_bool(res); | |
949 | return res; | |
9236d838 | 950 | } |
923b352f AN |
951 | |
952 | bool cfg80211_reg_can_beacon(struct wiphy *wiphy, | |
953 | struct cfg80211_chan_def *chandef, | |
954 | enum nl80211_iftype iftype) | |
955 | { | |
956 | return _cfg80211_reg_can_beacon(wiphy, chandef, iftype, true); | |
957 | } | |
683b6d3b | 958 | EXPORT_SYMBOL(cfg80211_reg_can_beacon); |
9236d838 | 959 | |
923b352f AN |
960 | bool cfg80211_reg_can_beacon_relax(struct wiphy *wiphy, |
961 | struct cfg80211_chan_def *chandef, | |
962 | enum nl80211_iftype iftype) | |
963 | { | |
964 | bool check_no_ir; | |
965 | ||
966 | ASSERT_RTNL(); | |
967 | ||
968 | /* | |
969 | * Under certain conditions suggested by some regulatory bodies a | |
970 | * GO/STA can IR on channels marked with IEEE80211_NO_IR. Set this flag | |
971 | * only if such relaxations are not enabled and the conditions are not | |
972 | * met. | |
973 | */ | |
974 | check_no_ir = !cfg80211_ir_permissive_chan(wiphy, iftype, | |
975 | chandef->chan); | |
976 | ||
977 | return _cfg80211_reg_can_beacon(wiphy, chandef, iftype, check_no_ir); | |
978 | } | |
979 | EXPORT_SYMBOL(cfg80211_reg_can_beacon_relax); | |
980 | ||
e8c9bd5b | 981 | int cfg80211_set_monitor_channel(struct cfg80211_registered_device *rdev, |
683b6d3b | 982 | struct cfg80211_chan_def *chandef) |
9588bbd5 | 983 | { |
e8c9bd5b | 984 | if (!rdev->ops->set_monitor_channel) |
9588bbd5 | 985 | return -EOPNOTSUPP; |
4f03c1ed MK |
986 | if (!cfg80211_has_monitors_only(rdev)) |
987 | return -EBUSY; | |
9588bbd5 | 988 | |
683b6d3b | 989 | return rdev_set_monitor_channel(rdev, chandef); |
59bbb6f7 | 990 | } |
26ab9a0c MK |
991 | |
992 | void | |
8e95ea49 | 993 | cfg80211_get_chan_state(struct wireless_dev *wdev, |
26ab9a0c | 994 | struct ieee80211_channel **chan, |
9e0e2961 MK |
995 | enum cfg80211_chan_mode *chanmode, |
996 | u8 *radar_detect) | |
26ab9a0c | 997 | { |
2beb6dab LC |
998 | int ret; |
999 | ||
26ab9a0c MK |
1000 | *chan = NULL; |
1001 | *chanmode = CHAN_MODE_UNDEFINED; | |
1002 | ||
26ab9a0c MK |
1003 | ASSERT_WDEV_LOCK(wdev); |
1004 | ||
98104fde | 1005 | if (wdev->netdev && !netif_running(wdev->netdev)) |
26ab9a0c MK |
1006 | return; |
1007 | ||
1008 | switch (wdev->iftype) { | |
1009 | case NL80211_IFTYPE_ADHOC: | |
1010 | if (wdev->current_bss) { | |
1011 | *chan = wdev->current_bss->pub.channel; | |
5336fa88 SW |
1012 | *chanmode = (wdev->ibss_fixed && |
1013 | !wdev->ibss_dfs_possible) | |
26ab9a0c MK |
1014 | ? CHAN_MODE_SHARED |
1015 | : CHAN_MODE_EXCLUSIVE; | |
9e0e2961 MK |
1016 | |
1017 | /* consider worst-case - IBSS can try to return to the | |
1018 | * original user-specified channel as creator */ | |
1019 | if (wdev->ibss_dfs_possible) | |
1020 | *radar_detect |= BIT(wdev->chandef.width); | |
26ab9a0c MK |
1021 | return; |
1022 | } | |
0f0094b3 | 1023 | break; |
26ab9a0c MK |
1024 | case NL80211_IFTYPE_STATION: |
1025 | case NL80211_IFTYPE_P2P_CLIENT: | |
1026 | if (wdev->current_bss) { | |
1027 | *chan = wdev->current_bss->pub.channel; | |
1028 | *chanmode = CHAN_MODE_SHARED; | |
1029 | return; | |
1030 | } | |
1031 | break; | |
1032 | case NL80211_IFTYPE_AP: | |
1033 | case NL80211_IFTYPE_P2P_GO: | |
04f39047 | 1034 | if (wdev->cac_started) { |
9e0e2961 | 1035 | *chan = wdev->chandef.chan; |
04f39047 | 1036 | *chanmode = CHAN_MODE_SHARED; |
9e0e2961 | 1037 | *radar_detect |= BIT(wdev->chandef.width); |
04f39047 | 1038 | } else if (wdev->beacon_interval) { |
9e0e2961 | 1039 | *chan = wdev->chandef.chan; |
f53594a0 | 1040 | *chanmode = CHAN_MODE_SHARED; |
9e0e2961 | 1041 | |
2beb6dab LC |
1042 | ret = cfg80211_chandef_dfs_required(wdev->wiphy, |
1043 | &wdev->chandef, | |
1044 | wdev->iftype); | |
1045 | WARN_ON(ret < 0); | |
1046 | if (ret > 0) | |
9e0e2961 | 1047 | *radar_detect |= BIT(wdev->chandef.width); |
f53594a0 FF |
1048 | } |
1049 | return; | |
26ab9a0c | 1050 | case NL80211_IFTYPE_MESH_POINT: |
f53594a0 | 1051 | if (wdev->mesh_id_len) { |
9e0e2961 | 1052 | *chan = wdev->chandef.chan; |
f53594a0 | 1053 | *chanmode = CHAN_MODE_SHARED; |
9e0e2961 | 1054 | |
2beb6dab LC |
1055 | ret = cfg80211_chandef_dfs_required(wdev->wiphy, |
1056 | &wdev->chandef, | |
1057 | wdev->iftype); | |
1058 | WARN_ON(ret < 0); | |
1059 | if (ret > 0) | |
9e0e2961 | 1060 | *radar_detect |= BIT(wdev->chandef.width); |
f53594a0 | 1061 | } |
26ab9a0c | 1062 | return; |
6e0bd6c3 RL |
1063 | case NL80211_IFTYPE_OCB: |
1064 | if (wdev->chandef.chan) { | |
1065 | *chan = wdev->chandef.chan; | |
1066 | *chanmode = CHAN_MODE_SHARED; | |
1067 | return; | |
1068 | } | |
1069 | break; | |
26ab9a0c MK |
1070 | case NL80211_IFTYPE_MONITOR: |
1071 | case NL80211_IFTYPE_AP_VLAN: | |
1072 | case NL80211_IFTYPE_WDS: | |
98104fde | 1073 | case NL80211_IFTYPE_P2P_DEVICE: |
cb3b7d87 | 1074 | case NL80211_IFTYPE_NAN: |
e7aceef4 | 1075 | /* these interface types don't really have a channel */ |
98104fde | 1076 | return; |
26ab9a0c MK |
1077 | case NL80211_IFTYPE_UNSPECIFIED: |
1078 | case NUM_NL80211_IFTYPES: | |
1079 | WARN_ON(1); | |
1080 | } | |
26ab9a0c | 1081 | } |