1 // SPDX-License-Identifier: GPL-2.0
3 * This file contains helper code to handle channel
4 * settings and keeping track of what is possible at
7 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
8 * Copyright 2013-2014 Intel Mobile Communications GmbH
11 #include <linux/export.h>
12 #include <net/cfg80211.h>
16 void cfg80211_chandef_create(struct cfg80211_chan_def
*chandef
,
17 struct ieee80211_channel
*chan
,
18 enum nl80211_channel_type chan_type
)
24 chandef
->center_freq2
= 0;
27 case NL80211_CHAN_NO_HT
:
28 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
29 chandef
->center_freq1
= chan
->center_freq
;
31 case NL80211_CHAN_HT20
:
32 chandef
->width
= NL80211_CHAN_WIDTH_20
;
33 chandef
->center_freq1
= chan
->center_freq
;
35 case NL80211_CHAN_HT40PLUS
:
36 chandef
->width
= NL80211_CHAN_WIDTH_40
;
37 chandef
->center_freq1
= chan
->center_freq
+ 10;
39 case NL80211_CHAN_HT40MINUS
:
40 chandef
->width
= NL80211_CHAN_WIDTH_40
;
41 chandef
->center_freq1
= chan
->center_freq
- 10;
47 EXPORT_SYMBOL(cfg80211_chandef_create
);
49 bool cfg80211_chandef_valid(const struct cfg80211_chan_def
*chandef
)
56 control_freq
= chandef
->chan
->center_freq
;
58 switch (chandef
->width
) {
59 case NL80211_CHAN_WIDTH_5
:
60 case NL80211_CHAN_WIDTH_10
:
61 case NL80211_CHAN_WIDTH_20
:
62 case NL80211_CHAN_WIDTH_20_NOHT
:
63 if (chandef
->center_freq1
!= control_freq
)
65 if (chandef
->center_freq2
)
68 case NL80211_CHAN_WIDTH_40
:
69 if (chandef
->center_freq1
!= control_freq
+ 10 &&
70 chandef
->center_freq1
!= control_freq
- 10)
72 if (chandef
->center_freq2
)
75 case NL80211_CHAN_WIDTH_80P80
:
76 if (chandef
->center_freq1
!= control_freq
+ 30 &&
77 chandef
->center_freq1
!= control_freq
+ 10 &&
78 chandef
->center_freq1
!= control_freq
- 10 &&
79 chandef
->center_freq1
!= control_freq
- 30)
81 if (!chandef
->center_freq2
)
83 /* adjacent is not allowed -- that's a 160 MHz channel */
84 if (chandef
->center_freq1
- chandef
->center_freq2
== 80 ||
85 chandef
->center_freq2
- chandef
->center_freq1
== 80)
88 case NL80211_CHAN_WIDTH_80
:
89 if (chandef
->center_freq1
!= control_freq
+ 30 &&
90 chandef
->center_freq1
!= control_freq
+ 10 &&
91 chandef
->center_freq1
!= control_freq
- 10 &&
92 chandef
->center_freq1
!= control_freq
- 30)
94 if (chandef
->center_freq2
)
97 case NL80211_CHAN_WIDTH_160
:
98 if (chandef
->center_freq1
!= control_freq
+ 70 &&
99 chandef
->center_freq1
!= control_freq
+ 50 &&
100 chandef
->center_freq1
!= control_freq
+ 30 &&
101 chandef
->center_freq1
!= control_freq
+ 10 &&
102 chandef
->center_freq1
!= control_freq
- 10 &&
103 chandef
->center_freq1
!= control_freq
- 30 &&
104 chandef
->center_freq1
!= control_freq
- 50 &&
105 chandef
->center_freq1
!= control_freq
- 70)
107 if (chandef
->center_freq2
)
116 EXPORT_SYMBOL(cfg80211_chandef_valid
);
118 static void chandef_primary_freqs(const struct cfg80211_chan_def
*c
,
119 u32
*pri40
, u32
*pri80
)
124 case NL80211_CHAN_WIDTH_40
:
125 *pri40
= c
->center_freq1
;
128 case NL80211_CHAN_WIDTH_80
:
129 case NL80211_CHAN_WIDTH_80P80
:
130 *pri80
= c
->center_freq1
;
132 tmp
= (30 + c
->chan
->center_freq
- c
->center_freq1
)/20;
136 *pri40
= c
->center_freq1
- 20 + 40 * tmp
;
138 case NL80211_CHAN_WIDTH_160
:
140 tmp
= (70 + c
->chan
->center_freq
- c
->center_freq1
)/20;
144 *pri40
= c
->center_freq1
- 60 + 40 * tmp
;
147 *pri80
= c
->center_freq1
- 40 + 80 * tmp
;
154 static int cfg80211_chandef_get_width(const struct cfg80211_chan_def
*c
)
159 case NL80211_CHAN_WIDTH_5
:
162 case NL80211_CHAN_WIDTH_10
:
165 case NL80211_CHAN_WIDTH_20
:
166 case NL80211_CHAN_WIDTH_20_NOHT
:
169 case NL80211_CHAN_WIDTH_40
:
172 case NL80211_CHAN_WIDTH_80P80
:
173 case NL80211_CHAN_WIDTH_80
:
176 case NL80211_CHAN_WIDTH_160
:
186 const struct cfg80211_chan_def
*
187 cfg80211_chandef_compatible(const struct cfg80211_chan_def
*c1
,
188 const struct cfg80211_chan_def
*c2
)
190 u32 c1_pri40
, c1_pri80
, c2_pri40
, c2_pri80
;
192 /* If they are identical, return */
193 if (cfg80211_chandef_identical(c1
, c2
))
196 /* otherwise, must have same control channel */
197 if (c1
->chan
!= c2
->chan
)
201 * If they have the same width, but aren't identical,
202 * then they can't be compatible.
204 if (c1
->width
== c2
->width
)
208 * can't be compatible if one of them is 5 or 10 MHz,
209 * but they don't have the same width.
211 if (c1
->width
== NL80211_CHAN_WIDTH_5
||
212 c1
->width
== NL80211_CHAN_WIDTH_10
||
213 c2
->width
== NL80211_CHAN_WIDTH_5
||
214 c2
->width
== NL80211_CHAN_WIDTH_10
)
217 if (c1
->width
== NL80211_CHAN_WIDTH_20_NOHT
||
218 c1
->width
== NL80211_CHAN_WIDTH_20
)
221 if (c2
->width
== NL80211_CHAN_WIDTH_20_NOHT
||
222 c2
->width
== NL80211_CHAN_WIDTH_20
)
225 chandef_primary_freqs(c1
, &c1_pri40
, &c1_pri80
);
226 chandef_primary_freqs(c2
, &c2_pri40
, &c2_pri80
);
228 if (c1_pri40
!= c2_pri40
)
231 WARN_ON(!c1_pri80
&& !c2_pri80
);
232 if (c1_pri80
&& c2_pri80
&& c1_pri80
!= c2_pri80
)
235 if (c1
->width
> c2
->width
)
239 EXPORT_SYMBOL(cfg80211_chandef_compatible
);
241 static void cfg80211_set_chans_dfs_state(struct wiphy
*wiphy
, u32 center_freq
,
243 enum nl80211_dfs_state dfs_state
)
245 struct ieee80211_channel
*c
;
248 for (freq
= center_freq
- bandwidth
/2 + 10;
249 freq
<= center_freq
+ bandwidth
/2 - 10;
251 c
= ieee80211_get_channel(wiphy
, freq
);
252 if (!c
|| !(c
->flags
& IEEE80211_CHAN_RADAR
))
255 c
->dfs_state
= dfs_state
;
256 c
->dfs_state_entered
= jiffies
;
260 void cfg80211_set_dfs_state(struct wiphy
*wiphy
,
261 const struct cfg80211_chan_def
*chandef
,
262 enum nl80211_dfs_state dfs_state
)
266 if (WARN_ON(!cfg80211_chandef_valid(chandef
)))
269 width
= cfg80211_chandef_get_width(chandef
);
273 cfg80211_set_chans_dfs_state(wiphy
, chandef
->center_freq1
,
276 if (!chandef
->center_freq2
)
278 cfg80211_set_chans_dfs_state(wiphy
, chandef
->center_freq2
,
282 static u32
cfg80211_get_start_freq(u32 center_freq
,
288 start_freq
= center_freq
;
290 start_freq
= center_freq
- bandwidth
/2 + 10;
295 static u32
cfg80211_get_end_freq(u32 center_freq
,
301 end_freq
= center_freq
;
303 end_freq
= center_freq
+ bandwidth
/2 - 10;
308 static int cfg80211_get_chans_dfs_required(struct wiphy
*wiphy
,
312 struct ieee80211_channel
*c
;
313 u32 freq
, start_freq
, end_freq
;
315 start_freq
= cfg80211_get_start_freq(center_freq
, bandwidth
);
316 end_freq
= cfg80211_get_end_freq(center_freq
, bandwidth
);
318 for (freq
= start_freq
; freq
<= end_freq
; freq
+= 20) {
319 c
= ieee80211_get_channel(wiphy
, freq
);
323 if (c
->flags
& IEEE80211_CHAN_RADAR
)
330 int cfg80211_chandef_dfs_required(struct wiphy
*wiphy
,
331 const struct cfg80211_chan_def
*chandef
,
332 enum nl80211_iftype iftype
)
337 if (WARN_ON(!cfg80211_chandef_valid(chandef
)))
341 case NL80211_IFTYPE_ADHOC
:
342 case NL80211_IFTYPE_AP
:
343 case NL80211_IFTYPE_P2P_GO
:
344 case NL80211_IFTYPE_MESH_POINT
:
345 width
= cfg80211_chandef_get_width(chandef
);
349 ret
= cfg80211_get_chans_dfs_required(wiphy
,
350 chandef
->center_freq1
,
355 return BIT(chandef
->width
);
357 if (!chandef
->center_freq2
)
360 ret
= cfg80211_get_chans_dfs_required(wiphy
,
361 chandef
->center_freq2
,
366 return BIT(chandef
->width
);
369 case NL80211_IFTYPE_STATION
:
370 case NL80211_IFTYPE_OCB
:
371 case NL80211_IFTYPE_P2P_CLIENT
:
372 case NL80211_IFTYPE_MONITOR
:
373 case NL80211_IFTYPE_AP_VLAN
:
374 case NL80211_IFTYPE_WDS
:
375 case NL80211_IFTYPE_P2P_DEVICE
:
376 case NL80211_IFTYPE_NAN
:
378 case NL80211_IFTYPE_UNSPECIFIED
:
379 case NUM_NL80211_IFTYPES
:
385 EXPORT_SYMBOL(cfg80211_chandef_dfs_required
);
387 static int cfg80211_get_chans_dfs_usable(struct wiphy
*wiphy
,
391 struct ieee80211_channel
*c
;
392 u32 freq
, start_freq
, end_freq
;
395 start_freq
= cfg80211_get_start_freq(center_freq
, bandwidth
);
396 end_freq
= cfg80211_get_end_freq(center_freq
, bandwidth
);
399 * Check entire range of channels for the bandwidth.
400 * Check all channels are DFS channels (DFS_USABLE or
401 * DFS_AVAILABLE). Return number of usable channels
402 * (require CAC). Allow DFS and non-DFS channel mix.
404 for (freq
= start_freq
; freq
<= end_freq
; freq
+= 20) {
405 c
= ieee80211_get_channel(wiphy
, freq
);
409 if (c
->flags
& IEEE80211_CHAN_DISABLED
)
412 if (c
->flags
& IEEE80211_CHAN_RADAR
) {
413 if (c
->dfs_state
== NL80211_DFS_UNAVAILABLE
)
416 if (c
->dfs_state
== NL80211_DFS_USABLE
)
424 bool cfg80211_chandef_dfs_usable(struct wiphy
*wiphy
,
425 const struct cfg80211_chan_def
*chandef
)
430 if (WARN_ON(!cfg80211_chandef_valid(chandef
)))
433 width
= cfg80211_chandef_get_width(chandef
);
437 r1
= cfg80211_get_chans_dfs_usable(wiphy
, chandef
->center_freq1
,
443 switch (chandef
->width
) {
444 case NL80211_CHAN_WIDTH_80P80
:
445 WARN_ON(!chandef
->center_freq2
);
446 r2
= cfg80211_get_chans_dfs_usable(wiphy
,
447 chandef
->center_freq2
,
453 WARN_ON(chandef
->center_freq2
);
457 return (r1
+ r2
> 0);
461 * Checks if center frequency of chan falls with in the bandwidth
464 bool cfg80211_is_sub_chan(struct cfg80211_chan_def
*chandef
,
465 struct ieee80211_channel
*chan
)
470 if (chandef
->chan
->center_freq
== chan
->center_freq
)
473 width
= cfg80211_chandef_get_width(chandef
);
477 for (freq
= chandef
->center_freq1
- width
/ 2 + 10;
478 freq
<= chandef
->center_freq1
+ width
/ 2 - 10; freq
+= 20) {
479 if (chan
->center_freq
== freq
)
483 if (!chandef
->center_freq2
)
486 for (freq
= chandef
->center_freq2
- width
/ 2 + 10;
487 freq
<= chandef
->center_freq2
+ width
/ 2 - 10; freq
+= 20) {
488 if (chan
->center_freq
== freq
)
495 bool cfg80211_beaconing_iface_active(struct wireless_dev
*wdev
)
499 ASSERT_WDEV_LOCK(wdev
);
501 if (!wdev
->chandef
.chan
)
504 switch (wdev
->iftype
) {
505 case NL80211_IFTYPE_AP
:
506 case NL80211_IFTYPE_P2P_GO
:
507 active
= wdev
->beacon_interval
!= 0;
509 case NL80211_IFTYPE_ADHOC
:
510 active
= wdev
->ssid_len
!= 0;
512 case NL80211_IFTYPE_MESH_POINT
:
513 active
= wdev
->mesh_id_len
!= 0;
515 case NL80211_IFTYPE_STATION
:
516 case NL80211_IFTYPE_OCB
:
517 case NL80211_IFTYPE_P2P_CLIENT
:
518 case NL80211_IFTYPE_MONITOR
:
519 case NL80211_IFTYPE_AP_VLAN
:
520 case NL80211_IFTYPE_WDS
:
521 case NL80211_IFTYPE_P2P_DEVICE
:
522 /* Can NAN type be considered as beaconing interface? */
523 case NL80211_IFTYPE_NAN
:
525 case NL80211_IFTYPE_UNSPECIFIED
:
526 case NUM_NL80211_IFTYPES
:
533 static bool cfg80211_is_wiphy_oper_chan(struct wiphy
*wiphy
,
534 struct ieee80211_channel
*chan
)
536 struct wireless_dev
*wdev
;
538 list_for_each_entry(wdev
, &wiphy
->wdev_list
, list
) {
540 if (!cfg80211_beaconing_iface_active(wdev
)) {
545 if (cfg80211_is_sub_chan(&wdev
->chandef
, chan
)) {
555 bool cfg80211_any_wiphy_oper_chan(struct wiphy
*wiphy
,
556 struct ieee80211_channel
*chan
)
558 struct cfg80211_registered_device
*rdev
;
562 if (!(chan
->flags
& IEEE80211_CHAN_RADAR
))
565 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
566 if (!reg_dfs_domain_same(wiphy
, &rdev
->wiphy
))
569 if (cfg80211_is_wiphy_oper_chan(&rdev
->wiphy
, chan
))
576 static bool cfg80211_get_chans_dfs_available(struct wiphy
*wiphy
,
580 struct ieee80211_channel
*c
;
581 u32 freq
, start_freq
, end_freq
;
583 start_freq
= cfg80211_get_start_freq(center_freq
, bandwidth
);
584 end_freq
= cfg80211_get_end_freq(center_freq
, bandwidth
);
587 * Check entire range of channels for the bandwidth.
588 * If any channel in between is disabled or has not
589 * had gone through CAC return false
591 for (freq
= start_freq
; freq
<= end_freq
; freq
+= 20) {
592 c
= ieee80211_get_channel(wiphy
, freq
);
596 if (c
->flags
& IEEE80211_CHAN_DISABLED
)
599 if ((c
->flags
& IEEE80211_CHAN_RADAR
) &&
600 (c
->dfs_state
!= NL80211_DFS_AVAILABLE
))
607 static bool cfg80211_chandef_dfs_available(struct wiphy
*wiphy
,
608 const struct cfg80211_chan_def
*chandef
)
613 if (WARN_ON(!cfg80211_chandef_valid(chandef
)))
616 width
= cfg80211_chandef_get_width(chandef
);
620 r
= cfg80211_get_chans_dfs_available(wiphy
, chandef
->center_freq1
,
623 /* If any of channels unavailable for cf1 just return */
627 switch (chandef
->width
) {
628 case NL80211_CHAN_WIDTH_80P80
:
629 WARN_ON(!chandef
->center_freq2
);
630 r
= cfg80211_get_chans_dfs_available(wiphy
,
631 chandef
->center_freq2
,
635 WARN_ON(chandef
->center_freq2
);
642 static unsigned int cfg80211_get_chans_dfs_cac_time(struct wiphy
*wiphy
,
646 struct ieee80211_channel
*c
;
647 u32 start_freq
, end_freq
, freq
;
648 unsigned int dfs_cac_ms
= 0;
650 start_freq
= cfg80211_get_start_freq(center_freq
, bandwidth
);
651 end_freq
= cfg80211_get_end_freq(center_freq
, bandwidth
);
653 for (freq
= start_freq
; freq
<= end_freq
; freq
+= 20) {
654 c
= ieee80211_get_channel(wiphy
, freq
);
658 if (c
->flags
& IEEE80211_CHAN_DISABLED
)
661 if (!(c
->flags
& IEEE80211_CHAN_RADAR
))
664 if (c
->dfs_cac_ms
> dfs_cac_ms
)
665 dfs_cac_ms
= c
->dfs_cac_ms
;
672 cfg80211_chandef_dfs_cac_time(struct wiphy
*wiphy
,
673 const struct cfg80211_chan_def
*chandef
)
676 unsigned int t1
= 0, t2
= 0;
678 if (WARN_ON(!cfg80211_chandef_valid(chandef
)))
681 width
= cfg80211_chandef_get_width(chandef
);
685 t1
= cfg80211_get_chans_dfs_cac_time(wiphy
,
686 chandef
->center_freq1
,
689 if (!chandef
->center_freq2
)
692 t2
= cfg80211_get_chans_dfs_cac_time(wiphy
,
693 chandef
->center_freq2
,
699 static bool cfg80211_secondary_chans_ok(struct wiphy
*wiphy
,
700 u32 center_freq
, u32 bandwidth
,
701 u32 prohibited_flags
)
703 struct ieee80211_channel
*c
;
704 u32 freq
, start_freq
, end_freq
;
706 start_freq
= cfg80211_get_start_freq(center_freq
, bandwidth
);
707 end_freq
= cfg80211_get_end_freq(center_freq
, bandwidth
);
709 for (freq
= start_freq
; freq
<= end_freq
; freq
+= 20) {
710 c
= ieee80211_get_channel(wiphy
, freq
);
711 if (!c
|| c
->flags
& prohibited_flags
)
718 bool cfg80211_chandef_usable(struct wiphy
*wiphy
,
719 const struct cfg80211_chan_def
*chandef
,
720 u32 prohibited_flags
)
722 struct ieee80211_sta_ht_cap
*ht_cap
;
723 struct ieee80211_sta_vht_cap
*vht_cap
;
724 u32 width
, control_freq
, cap
;
726 if (WARN_ON(!cfg80211_chandef_valid(chandef
)))
729 ht_cap
= &wiphy
->bands
[chandef
->chan
->band
]->ht_cap
;
730 vht_cap
= &wiphy
->bands
[chandef
->chan
->band
]->vht_cap
;
732 control_freq
= chandef
->chan
->center_freq
;
734 switch (chandef
->width
) {
735 case NL80211_CHAN_WIDTH_5
:
738 case NL80211_CHAN_WIDTH_10
:
739 prohibited_flags
|= IEEE80211_CHAN_NO_10MHZ
;
742 case NL80211_CHAN_WIDTH_20
:
743 if (!ht_cap
->ht_supported
)
745 case NL80211_CHAN_WIDTH_20_NOHT
:
746 prohibited_flags
|= IEEE80211_CHAN_NO_20MHZ
;
749 case NL80211_CHAN_WIDTH_40
:
751 if (!ht_cap
->ht_supported
)
753 if (!(ht_cap
->cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) ||
754 ht_cap
->cap
& IEEE80211_HT_CAP_40MHZ_INTOLERANT
)
756 if (chandef
->center_freq1
< control_freq
&&
757 chandef
->chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
)
759 if (chandef
->center_freq1
> control_freq
&&
760 chandef
->chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
)
763 case NL80211_CHAN_WIDTH_80P80
:
764 cap
= vht_cap
->cap
& IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
;
765 if (cap
!= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ
)
767 case NL80211_CHAN_WIDTH_80
:
768 if (!vht_cap
->vht_supported
)
770 prohibited_flags
|= IEEE80211_CHAN_NO_80MHZ
;
773 case NL80211_CHAN_WIDTH_160
:
774 if (!vht_cap
->vht_supported
)
776 cap
= vht_cap
->cap
& IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
;
777 if (cap
!= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
&&
778 cap
!= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ
)
780 prohibited_flags
|= IEEE80211_CHAN_NO_160MHZ
;
789 * TODO: What if there are only certain 80/160/80+80 MHz channels
790 * allowed by the driver, or only certain combinations?
791 * For 40 MHz the driver can set the NO_HT40 flags, but for
792 * 80/160 MHz and in particular 80+80 MHz this isn't really
793 * feasible and we only have NO_80MHZ/NO_160MHZ so far but
794 * no way to cover 80+80 MHz or more complex restrictions.
795 * Note that such restrictions also need to be advertised to
796 * userspace, for example for P2P channel selection.
800 prohibited_flags
|= IEEE80211_CHAN_NO_OFDM
;
802 /* 5 and 10 MHz are only defined for the OFDM PHY */
804 prohibited_flags
|= IEEE80211_CHAN_NO_OFDM
;
807 if (!cfg80211_secondary_chans_ok(wiphy
, chandef
->center_freq1
,
808 width
, prohibited_flags
))
811 if (!chandef
->center_freq2
)
813 return cfg80211_secondary_chans_ok(wiphy
, chandef
->center_freq2
,
814 width
, prohibited_flags
);
816 EXPORT_SYMBOL(cfg80211_chandef_usable
);
819 * Check if the channel can be used under permissive conditions mandated by
820 * some regulatory bodies, i.e., the channel is marked with
821 * IEEE80211_CHAN_IR_CONCURRENT and there is an additional station interface
822 * associated to an AP on the same channel or on the same UNII band
823 * (assuming that the AP is an authorized master).
824 * In addition allow operation on a channel on which indoor operation is
825 * allowed, iff we are currently operating in an indoor environment.
827 static bool cfg80211_ir_permissive_chan(struct wiphy
*wiphy
,
828 enum nl80211_iftype iftype
,
829 struct ieee80211_channel
*chan
)
831 struct wireless_dev
*wdev
;
832 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
836 if (!IS_ENABLED(CONFIG_CFG80211_REG_RELAX_NO_IR
) ||
837 !(wiphy
->regulatory_flags
& REGULATORY_ENABLE_RELAX_NO_IR
))
840 /* only valid for GO and TDLS off-channel (station/p2p-CL) */
841 if (iftype
!= NL80211_IFTYPE_P2P_GO
&&
842 iftype
!= NL80211_IFTYPE_STATION
&&
843 iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
846 if (regulatory_indoor_allowed() &&
847 (chan
->flags
& IEEE80211_CHAN_INDOOR_ONLY
))
850 if (!(chan
->flags
& IEEE80211_CHAN_IR_CONCURRENT
))
854 * Generally, it is possible to rely on another device/driver to allow
855 * the IR concurrent relaxation, however, since the device can further
856 * enforce the relaxation (by doing a similar verifications as this),
857 * and thus fail the GO instantiation, consider only the interfaces of
858 * the current registered device.
860 list_for_each_entry(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
861 struct ieee80211_channel
*other_chan
= NULL
;
865 if (wdev
->iftype
== NL80211_IFTYPE_STATION
&&
867 other_chan
= wdev
->current_bss
->pub
.channel
;
870 * If a GO already operates on the same GO_CONCURRENT channel,
871 * this one (maybe the same one) can beacon as well. We allow
872 * the operation even if the station we relied on with
873 * GO_CONCURRENT is disconnected now. But then we must make sure
874 * we're not outdoor on an indoor-only channel.
876 if (iftype
== NL80211_IFTYPE_P2P_GO
&&
877 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
&&
878 wdev
->beacon_interval
&&
879 !(chan
->flags
& IEEE80211_CHAN_INDOOR_ONLY
))
880 other_chan
= wdev
->chandef
.chan
;
886 if (chan
== other_chan
)
889 if (chan
->band
!= NL80211_BAND_5GHZ
)
892 r1
= cfg80211_get_unii(chan
->center_freq
);
893 r2
= cfg80211_get_unii(other_chan
->center_freq
);
895 if (r1
!= -EINVAL
&& r1
== r2
) {
897 * At some locations channels 149-165 are considered a
898 * bundle, but at other locations, e.g., Indonesia,
899 * channels 149-161 are considered a bundle while
900 * channel 165 is left out and considered to be in a
901 * different bundle. Thus, in case that there is a
902 * station interface connected to an AP on channel 165,
903 * it is assumed that channels 149-161 are allowed for
904 * GO operations. However, having a station interface
905 * connected to an AP on channels 149-161, does not
906 * allow GO operation on channel 165.
908 if (chan
->center_freq
== 5825 &&
909 other_chan
->center_freq
!= 5825)
918 static bool _cfg80211_reg_can_beacon(struct wiphy
*wiphy
,
919 struct cfg80211_chan_def
*chandef
,
920 enum nl80211_iftype iftype
,
924 u32 prohibited_flags
= IEEE80211_CHAN_DISABLED
|
925 IEEE80211_CHAN_RADAR
;
927 trace_cfg80211_reg_can_beacon(wiphy
, chandef
, iftype
, check_no_ir
);
930 prohibited_flags
|= IEEE80211_CHAN_NO_IR
;
932 if (cfg80211_chandef_dfs_required(wiphy
, chandef
, iftype
) > 0 &&
933 cfg80211_chandef_dfs_available(wiphy
, chandef
)) {
934 /* We can skip IEEE80211_CHAN_NO_IR if chandef dfs available */
935 prohibited_flags
= IEEE80211_CHAN_DISABLED
;
938 res
= cfg80211_chandef_usable(wiphy
, chandef
, prohibited_flags
);
940 trace_cfg80211_return_bool(res
);
944 bool cfg80211_reg_can_beacon(struct wiphy
*wiphy
,
945 struct cfg80211_chan_def
*chandef
,
946 enum nl80211_iftype iftype
)
948 return _cfg80211_reg_can_beacon(wiphy
, chandef
, iftype
, true);
950 EXPORT_SYMBOL(cfg80211_reg_can_beacon
);
952 bool cfg80211_reg_can_beacon_relax(struct wiphy
*wiphy
,
953 struct cfg80211_chan_def
*chandef
,
954 enum nl80211_iftype iftype
)
961 * Under certain conditions suggested by some regulatory bodies a
962 * GO/STA can IR on channels marked with IEEE80211_NO_IR. Set this flag
963 * only if such relaxations are not enabled and the conditions are not
966 check_no_ir
= !cfg80211_ir_permissive_chan(wiphy
, iftype
,
969 return _cfg80211_reg_can_beacon(wiphy
, chandef
, iftype
, check_no_ir
);
971 EXPORT_SYMBOL(cfg80211_reg_can_beacon_relax
);
973 int cfg80211_set_monitor_channel(struct cfg80211_registered_device
*rdev
,
974 struct cfg80211_chan_def
*chandef
)
976 if (!rdev
->ops
->set_monitor_channel
)
978 if (!cfg80211_has_monitors_only(rdev
))
981 return rdev_set_monitor_channel(rdev
, chandef
);
985 cfg80211_get_chan_state(struct wireless_dev
*wdev
,
986 struct ieee80211_channel
**chan
,
987 enum cfg80211_chan_mode
*chanmode
,
993 *chanmode
= CHAN_MODE_UNDEFINED
;
995 ASSERT_WDEV_LOCK(wdev
);
997 if (wdev
->netdev
&& !netif_running(wdev
->netdev
))
1000 switch (wdev
->iftype
) {
1001 case NL80211_IFTYPE_ADHOC
:
1002 if (wdev
->current_bss
) {
1003 *chan
= wdev
->current_bss
->pub
.channel
;
1004 *chanmode
= (wdev
->ibss_fixed
&&
1005 !wdev
->ibss_dfs_possible
)
1007 : CHAN_MODE_EXCLUSIVE
;
1009 /* consider worst-case - IBSS can try to return to the
1010 * original user-specified channel as creator */
1011 if (wdev
->ibss_dfs_possible
)
1012 *radar_detect
|= BIT(wdev
->chandef
.width
);
1016 case NL80211_IFTYPE_STATION
:
1017 case NL80211_IFTYPE_P2P_CLIENT
:
1018 if (wdev
->current_bss
) {
1019 *chan
= wdev
->current_bss
->pub
.channel
;
1020 *chanmode
= CHAN_MODE_SHARED
;
1024 case NL80211_IFTYPE_AP
:
1025 case NL80211_IFTYPE_P2P_GO
:
1026 if (wdev
->cac_started
) {
1027 *chan
= wdev
->chandef
.chan
;
1028 *chanmode
= CHAN_MODE_SHARED
;
1029 *radar_detect
|= BIT(wdev
->chandef
.width
);
1030 } else if (wdev
->beacon_interval
) {
1031 *chan
= wdev
->chandef
.chan
;
1032 *chanmode
= CHAN_MODE_SHARED
;
1034 ret
= cfg80211_chandef_dfs_required(wdev
->wiphy
,
1039 *radar_detect
|= BIT(wdev
->chandef
.width
);
1042 case NL80211_IFTYPE_MESH_POINT
:
1043 if (wdev
->mesh_id_len
) {
1044 *chan
= wdev
->chandef
.chan
;
1045 *chanmode
= CHAN_MODE_SHARED
;
1047 ret
= cfg80211_chandef_dfs_required(wdev
->wiphy
,
1052 *radar_detect
|= BIT(wdev
->chandef
.width
);
1055 case NL80211_IFTYPE_OCB
:
1056 if (wdev
->chandef
.chan
) {
1057 *chan
= wdev
->chandef
.chan
;
1058 *chanmode
= CHAN_MODE_SHARED
;
1062 case NL80211_IFTYPE_MONITOR
:
1063 case NL80211_IFTYPE_AP_VLAN
:
1064 case NL80211_IFTYPE_WDS
:
1065 case NL80211_IFTYPE_P2P_DEVICE
:
1066 case NL80211_IFTYPE_NAN
:
1067 /* these interface types don't really have a channel */
1069 case NL80211_IFTYPE_UNSPECIFIED
:
1070 case NUM_NL80211_IFTYPES
: