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
9 * Copyright 2018 Intel Corporation
12 #include <linux/export.h>
13 #include <net/cfg80211.h>
17 void cfg80211_chandef_create(struct cfg80211_chan_def
*chandef
,
18 struct ieee80211_channel
*chan
,
19 enum nl80211_channel_type chan_type
)
25 chandef
->center_freq2
= 0;
28 case NL80211_CHAN_NO_HT
:
29 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
30 chandef
->center_freq1
= chan
->center_freq
;
32 case NL80211_CHAN_HT20
:
33 chandef
->width
= NL80211_CHAN_WIDTH_20
;
34 chandef
->center_freq1
= chan
->center_freq
;
36 case NL80211_CHAN_HT40PLUS
:
37 chandef
->width
= NL80211_CHAN_WIDTH_40
;
38 chandef
->center_freq1
= chan
->center_freq
+ 10;
40 case NL80211_CHAN_HT40MINUS
:
41 chandef
->width
= NL80211_CHAN_WIDTH_40
;
42 chandef
->center_freq1
= chan
->center_freq
- 10;
48 EXPORT_SYMBOL(cfg80211_chandef_create
);
50 bool cfg80211_chandef_valid(const struct cfg80211_chan_def
*chandef
)
57 control_freq
= chandef
->chan
->center_freq
;
59 switch (chandef
->width
) {
60 case NL80211_CHAN_WIDTH_5
:
61 case NL80211_CHAN_WIDTH_10
:
62 case NL80211_CHAN_WIDTH_20
:
63 case NL80211_CHAN_WIDTH_20_NOHT
:
64 if (chandef
->center_freq1
!= control_freq
)
66 if (chandef
->center_freq2
)
69 case NL80211_CHAN_WIDTH_40
:
70 if (chandef
->center_freq1
!= control_freq
+ 10 &&
71 chandef
->center_freq1
!= control_freq
- 10)
73 if (chandef
->center_freq2
)
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)
82 if (!chandef
->center_freq2
)
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)
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)
95 if (chandef
->center_freq2
)
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)
108 if (chandef
->center_freq2
)
117 EXPORT_SYMBOL(cfg80211_chandef_valid
);
119 static void chandef_primary_freqs(const struct cfg80211_chan_def
*c
,
120 u32
*pri40
, u32
*pri80
)
125 case NL80211_CHAN_WIDTH_40
:
126 *pri40
= c
->center_freq1
;
129 case NL80211_CHAN_WIDTH_80
:
130 case NL80211_CHAN_WIDTH_80P80
:
131 *pri80
= c
->center_freq1
;
133 tmp
= (30 + c
->chan
->center_freq
- c
->center_freq1
)/20;
137 *pri40
= c
->center_freq1
- 20 + 40 * tmp
;
139 case NL80211_CHAN_WIDTH_160
:
141 tmp
= (70 + c
->chan
->center_freq
- c
->center_freq1
)/20;
145 *pri40
= c
->center_freq1
- 60 + 40 * tmp
;
148 *pri80
= c
->center_freq1
- 40 + 80 * tmp
;
155 static int cfg80211_chandef_get_width(const struct cfg80211_chan_def
*c
)
160 case NL80211_CHAN_WIDTH_5
:
163 case NL80211_CHAN_WIDTH_10
:
166 case NL80211_CHAN_WIDTH_20
:
167 case NL80211_CHAN_WIDTH_20_NOHT
:
170 case NL80211_CHAN_WIDTH_40
:
173 case NL80211_CHAN_WIDTH_80P80
:
174 case NL80211_CHAN_WIDTH_80
:
177 case NL80211_CHAN_WIDTH_160
:
187 const struct cfg80211_chan_def
*
188 cfg80211_chandef_compatible(const struct cfg80211_chan_def
*c1
,
189 const struct cfg80211_chan_def
*c2
)
191 u32 c1_pri40
, c1_pri80
, c2_pri40
, c2_pri80
;
193 /* If they are identical, return */
194 if (cfg80211_chandef_identical(c1
, c2
))
197 /* otherwise, must have same control channel */
198 if (c1
->chan
!= c2
->chan
)
202 * If they have the same width, but aren't identical,
203 * then they can't be compatible.
205 if (c1
->width
== c2
->width
)
209 * can't be compatible if one of them is 5 or 10 MHz,
210 * but they don't have the same width.
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
)
218 if (c1
->width
== NL80211_CHAN_WIDTH_20_NOHT
||
219 c1
->width
== NL80211_CHAN_WIDTH_20
)
222 if (c2
->width
== NL80211_CHAN_WIDTH_20_NOHT
||
223 c2
->width
== NL80211_CHAN_WIDTH_20
)
226 chandef_primary_freqs(c1
, &c1_pri40
, &c1_pri80
);
227 chandef_primary_freqs(c2
, &c2_pri40
, &c2_pri80
);
229 if (c1_pri40
!= c2_pri40
)
232 WARN_ON(!c1_pri80
&& !c2_pri80
);
233 if (c1_pri80
&& c2_pri80
&& c1_pri80
!= c2_pri80
)
236 if (c1
->width
> c2
->width
)
240 EXPORT_SYMBOL(cfg80211_chandef_compatible
);
242 static void cfg80211_set_chans_dfs_state(struct wiphy
*wiphy
, u32 center_freq
,
244 enum nl80211_dfs_state dfs_state
)
246 struct ieee80211_channel
*c
;
249 for (freq
= center_freq
- bandwidth
/2 + 10;
250 freq
<= center_freq
+ bandwidth
/2 - 10;
252 c
= ieee80211_get_channel(wiphy
, freq
);
253 if (!c
|| !(c
->flags
& IEEE80211_CHAN_RADAR
))
256 c
->dfs_state
= dfs_state
;
257 c
->dfs_state_entered
= jiffies
;
261 void cfg80211_set_dfs_state(struct wiphy
*wiphy
,
262 const struct cfg80211_chan_def
*chandef
,
263 enum nl80211_dfs_state dfs_state
)
267 if (WARN_ON(!cfg80211_chandef_valid(chandef
)))
270 width
= cfg80211_chandef_get_width(chandef
);
274 cfg80211_set_chans_dfs_state(wiphy
, chandef
->center_freq1
,
277 if (!chandef
->center_freq2
)
279 cfg80211_set_chans_dfs_state(wiphy
, chandef
->center_freq2
,
283 static u32
cfg80211_get_start_freq(u32 center_freq
,
289 start_freq
= center_freq
;
291 start_freq
= center_freq
- bandwidth
/2 + 10;
296 static u32
cfg80211_get_end_freq(u32 center_freq
,
302 end_freq
= center_freq
;
304 end_freq
= center_freq
+ bandwidth
/2 - 10;
309 static int cfg80211_get_chans_dfs_required(struct wiphy
*wiphy
,
313 struct ieee80211_channel
*c
;
314 u32 freq
, start_freq
, end_freq
;
316 start_freq
= cfg80211_get_start_freq(center_freq
, bandwidth
);
317 end_freq
= cfg80211_get_end_freq(center_freq
, bandwidth
);
319 for (freq
= start_freq
; freq
<= end_freq
; freq
+= 20) {
320 c
= ieee80211_get_channel(wiphy
, freq
);
324 if (c
->flags
& IEEE80211_CHAN_RADAR
)
331 int cfg80211_chandef_dfs_required(struct wiphy
*wiphy
,
332 const struct cfg80211_chan_def
*chandef
,
333 enum nl80211_iftype iftype
)
338 if (WARN_ON(!cfg80211_chandef_valid(chandef
)))
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
);
350 ret
= cfg80211_get_chans_dfs_required(wiphy
,
351 chandef
->center_freq1
,
356 return BIT(chandef
->width
);
358 if (!chandef
->center_freq2
)
361 ret
= cfg80211_get_chans_dfs_required(wiphy
,
362 chandef
->center_freq2
,
367 return BIT(chandef
->width
);
370 case NL80211_IFTYPE_STATION
:
371 case NL80211_IFTYPE_OCB
:
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
:
377 case NL80211_IFTYPE_NAN
:
379 case NL80211_IFTYPE_UNSPECIFIED
:
380 case NUM_NL80211_IFTYPES
:
386 EXPORT_SYMBOL(cfg80211_chandef_dfs_required
);
388 static int cfg80211_get_chans_dfs_usable(struct wiphy
*wiphy
,
392 struct ieee80211_channel
*c
;
393 u32 freq
, start_freq
, end_freq
;
396 start_freq
= cfg80211_get_start_freq(center_freq
, bandwidth
);
397 end_freq
= cfg80211_get_end_freq(center_freq
, bandwidth
);
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.
405 for (freq
= start_freq
; freq
<= end_freq
; freq
+= 20) {
406 c
= ieee80211_get_channel(wiphy
, freq
);
410 if (c
->flags
& IEEE80211_CHAN_DISABLED
)
413 if (c
->flags
& IEEE80211_CHAN_RADAR
) {
414 if (c
->dfs_state
== NL80211_DFS_UNAVAILABLE
)
417 if (c
->dfs_state
== NL80211_DFS_USABLE
)
425 bool cfg80211_chandef_dfs_usable(struct wiphy
*wiphy
,
426 const struct cfg80211_chan_def
*chandef
)
431 if (WARN_ON(!cfg80211_chandef_valid(chandef
)))
434 width
= cfg80211_chandef_get_width(chandef
);
438 r1
= cfg80211_get_chans_dfs_usable(wiphy
, chandef
->center_freq1
,
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
,
454 WARN_ON(chandef
->center_freq2
);
458 return (r1
+ r2
> 0);
462 * Checks if center frequency of chan falls with in the bandwidth
465 bool cfg80211_is_sub_chan(struct cfg80211_chan_def
*chandef
,
466 struct ieee80211_channel
*chan
)
471 if (chandef
->chan
->center_freq
== chan
->center_freq
)
474 width
= cfg80211_chandef_get_width(chandef
);
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
)
484 if (!chandef
->center_freq2
)
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
)
496 bool cfg80211_beaconing_iface_active(struct wireless_dev
*wdev
)
500 ASSERT_WDEV_LOCK(wdev
);
502 if (!wdev
->chandef
.chan
)
505 switch (wdev
->iftype
) {
506 case NL80211_IFTYPE_AP
:
507 case NL80211_IFTYPE_P2P_GO
:
508 active
= wdev
->beacon_interval
!= 0;
510 case NL80211_IFTYPE_ADHOC
:
511 active
= wdev
->ssid_len
!= 0;
513 case NL80211_IFTYPE_MESH_POINT
:
514 active
= wdev
->mesh_id_len
!= 0;
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
:
526 case NL80211_IFTYPE_UNSPECIFIED
:
527 case NUM_NL80211_IFTYPES
:
534 static bool cfg80211_is_wiphy_oper_chan(struct wiphy
*wiphy
,
535 struct ieee80211_channel
*chan
)
537 struct wireless_dev
*wdev
;
539 list_for_each_entry(wdev
, &wiphy
->wdev_list
, list
) {
541 if (!cfg80211_beaconing_iface_active(wdev
)) {
546 if (cfg80211_is_sub_chan(&wdev
->chandef
, chan
)) {
556 bool cfg80211_any_wiphy_oper_chan(struct wiphy
*wiphy
,
557 struct ieee80211_channel
*chan
)
559 struct cfg80211_registered_device
*rdev
;
563 if (!(chan
->flags
& IEEE80211_CHAN_RADAR
))
566 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
567 if (!reg_dfs_domain_same(wiphy
, &rdev
->wiphy
))
570 if (cfg80211_is_wiphy_oper_chan(&rdev
->wiphy
, chan
))
577 static bool cfg80211_get_chans_dfs_available(struct wiphy
*wiphy
,
581 struct ieee80211_channel
*c
;
582 u32 freq
, start_freq
, end_freq
;
585 dfs_offload
= wiphy_ext_feature_isset(wiphy
,
586 NL80211_EXT_FEATURE_DFS_OFFLOAD
);
588 start_freq
= cfg80211_get_start_freq(center_freq
, bandwidth
);
589 end_freq
= cfg80211_get_end_freq(center_freq
, bandwidth
);
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
596 for (freq
= start_freq
; freq
<= end_freq
; freq
+= 20) {
597 c
= ieee80211_get_channel(wiphy
, freq
);
601 if (c
->flags
& IEEE80211_CHAN_DISABLED
)
604 if ((c
->flags
& IEEE80211_CHAN_RADAR
) &&
605 (c
->dfs_state
!= NL80211_DFS_AVAILABLE
) &&
606 !(c
->dfs_state
== NL80211_DFS_USABLE
&& dfs_offload
))
613 static bool cfg80211_chandef_dfs_available(struct wiphy
*wiphy
,
614 const struct cfg80211_chan_def
*chandef
)
619 if (WARN_ON(!cfg80211_chandef_valid(chandef
)))
622 width
= cfg80211_chandef_get_width(chandef
);
626 r
= cfg80211_get_chans_dfs_available(wiphy
, chandef
->center_freq1
,
629 /* If any of channels unavailable for cf1 just return */
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
,
641 WARN_ON(chandef
->center_freq2
);
648 static unsigned int cfg80211_get_chans_dfs_cac_time(struct wiphy
*wiphy
,
652 struct ieee80211_channel
*c
;
653 u32 start_freq
, end_freq
, freq
;
654 unsigned int dfs_cac_ms
= 0;
656 start_freq
= cfg80211_get_start_freq(center_freq
, bandwidth
);
657 end_freq
= cfg80211_get_end_freq(center_freq
, bandwidth
);
659 for (freq
= start_freq
; freq
<= end_freq
; freq
+= 20) {
660 c
= ieee80211_get_channel(wiphy
, freq
);
664 if (c
->flags
& IEEE80211_CHAN_DISABLED
)
667 if (!(c
->flags
& IEEE80211_CHAN_RADAR
))
670 if (c
->dfs_cac_ms
> dfs_cac_ms
)
671 dfs_cac_ms
= c
->dfs_cac_ms
;
678 cfg80211_chandef_dfs_cac_time(struct wiphy
*wiphy
,
679 const struct cfg80211_chan_def
*chandef
)
682 unsigned int t1
= 0, t2
= 0;
684 if (WARN_ON(!cfg80211_chandef_valid(chandef
)))
687 width
= cfg80211_chandef_get_width(chandef
);
691 t1
= cfg80211_get_chans_dfs_cac_time(wiphy
,
692 chandef
->center_freq1
,
695 if (!chandef
->center_freq2
)
698 t2
= cfg80211_get_chans_dfs_cac_time(wiphy
,
699 chandef
->center_freq2
,
705 static bool cfg80211_secondary_chans_ok(struct wiphy
*wiphy
,
706 u32 center_freq
, u32 bandwidth
,
707 u32 prohibited_flags
)
709 struct ieee80211_channel
*c
;
710 u32 freq
, start_freq
, end_freq
;
712 start_freq
= cfg80211_get_start_freq(center_freq
, bandwidth
);
713 end_freq
= cfg80211_get_end_freq(center_freq
, bandwidth
);
715 for (freq
= start_freq
; freq
<= end_freq
; freq
+= 20) {
716 c
= ieee80211_get_channel(wiphy
, freq
);
717 if (!c
|| c
->flags
& prohibited_flags
)
724 bool cfg80211_chandef_usable(struct wiphy
*wiphy
,
725 const struct cfg80211_chan_def
*chandef
,
726 u32 prohibited_flags
)
728 struct ieee80211_sta_ht_cap
*ht_cap
;
729 struct ieee80211_sta_vht_cap
*vht_cap
;
730 u32 width
, control_freq
, cap
;
732 if (WARN_ON(!cfg80211_chandef_valid(chandef
)))
735 ht_cap
= &wiphy
->bands
[chandef
->chan
->band
]->ht_cap
;
736 vht_cap
= &wiphy
->bands
[chandef
->chan
->band
]->vht_cap
;
738 control_freq
= chandef
->chan
->center_freq
;
740 switch (chandef
->width
) {
741 case NL80211_CHAN_WIDTH_5
:
744 case NL80211_CHAN_WIDTH_10
:
745 prohibited_flags
|= IEEE80211_CHAN_NO_10MHZ
;
748 case NL80211_CHAN_WIDTH_20
:
749 if (!ht_cap
->ht_supported
)
752 case NL80211_CHAN_WIDTH_20_NOHT
:
753 prohibited_flags
|= IEEE80211_CHAN_NO_20MHZ
;
756 case NL80211_CHAN_WIDTH_40
:
758 if (!ht_cap
->ht_supported
)
760 if (!(ht_cap
->cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) ||
761 ht_cap
->cap
& IEEE80211_HT_CAP_40MHZ_INTOLERANT
)
763 if (chandef
->center_freq1
< control_freq
&&
764 chandef
->chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
)
766 if (chandef
->center_freq1
> control_freq
&&
767 chandef
->chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
)
770 case NL80211_CHAN_WIDTH_80P80
:
771 cap
= vht_cap
->cap
& IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
;
772 if (cap
!= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ
)
775 case NL80211_CHAN_WIDTH_80
:
776 if (!vht_cap
->vht_supported
)
778 prohibited_flags
|= IEEE80211_CHAN_NO_80MHZ
;
781 case NL80211_CHAN_WIDTH_160
:
782 if (!vht_cap
->vht_supported
)
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
)
788 prohibited_flags
|= IEEE80211_CHAN_NO_160MHZ
;
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.
808 prohibited_flags
|= IEEE80211_CHAN_NO_OFDM
;
810 /* 5 and 10 MHz are only defined for the OFDM PHY */
812 prohibited_flags
|= IEEE80211_CHAN_NO_OFDM
;
815 if (!cfg80211_secondary_chans_ok(wiphy
, chandef
->center_freq1
,
816 width
, prohibited_flags
))
819 if (!chandef
->center_freq2
)
821 return cfg80211_secondary_chans_ok(wiphy
, chandef
->center_freq2
,
822 width
, prohibited_flags
);
824 EXPORT_SYMBOL(cfg80211_chandef_usable
);
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
830 * associated to an AP on the same channel or on the same UNII band
831 * (assuming that the AP is an authorized master).
832 * In addition allow operation on a channel on which indoor operation is
833 * allowed, iff we are currently operating in an indoor environment.
835 static bool cfg80211_ir_permissive_chan(struct wiphy
*wiphy
,
836 enum nl80211_iftype iftype
,
837 struct ieee80211_channel
*chan
)
839 struct wireless_dev
*wdev
;
840 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
844 if (!IS_ENABLED(CONFIG_CFG80211_REG_RELAX_NO_IR
) ||
845 !(wiphy
->regulatory_flags
& REGULATORY_ENABLE_RELAX_NO_IR
))
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
)
854 if (regulatory_indoor_allowed() &&
855 (chan
->flags
& IEEE80211_CHAN_INDOOR_ONLY
))
858 if (!(chan
->flags
& IEEE80211_CHAN_IR_CONCURRENT
))
862 * Generally, it is possible to rely on another device/driver to allow
863 * the IR concurrent relaxation, however, since the device can further
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.
868 list_for_each_entry(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
869 struct ieee80211_channel
*other_chan
= NULL
;
873 if (wdev
->iftype
== NL80211_IFTYPE_STATION
&&
875 other_chan
= wdev
->current_bss
->pub
.channel
;
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.
884 if (iftype
== NL80211_IFTYPE_P2P_GO
&&
885 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
&&
886 wdev
->beacon_interval
&&
887 !(chan
->flags
& IEEE80211_CHAN_INDOOR_ONLY
))
888 other_chan
= wdev
->chandef
.chan
;
894 if (chan
== other_chan
)
897 if (chan
->band
!= NL80211_BAND_5GHZ
)
900 r1
= cfg80211_get_unii(chan
->center_freq
);
901 r2
= cfg80211_get_unii(other_chan
->center_freq
);
903 if (r1
!= -EINVAL
&& r1
== r2
) {
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.
916 if (chan
->center_freq
== 5825 &&
917 other_chan
->center_freq
!= 5825)
926 static bool _cfg80211_reg_can_beacon(struct wiphy
*wiphy
,
927 struct cfg80211_chan_def
*chandef
,
928 enum nl80211_iftype iftype
,
932 u32 prohibited_flags
= IEEE80211_CHAN_DISABLED
|
933 IEEE80211_CHAN_RADAR
;
935 trace_cfg80211_reg_can_beacon(wiphy
, chandef
, iftype
, check_no_ir
);
938 prohibited_flags
|= IEEE80211_CHAN_NO_IR
;
940 if (cfg80211_chandef_dfs_required(wiphy
, chandef
, iftype
) > 0 &&
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
;
946 res
= cfg80211_chandef_usable(wiphy
, chandef
, prohibited_flags
);
948 trace_cfg80211_return_bool(res
);
952 bool cfg80211_reg_can_beacon(struct wiphy
*wiphy
,
953 struct cfg80211_chan_def
*chandef
,
954 enum nl80211_iftype iftype
)
956 return _cfg80211_reg_can_beacon(wiphy
, chandef
, iftype
, true);
958 EXPORT_SYMBOL(cfg80211_reg_can_beacon
);
960 bool cfg80211_reg_can_beacon_relax(struct wiphy
*wiphy
,
961 struct cfg80211_chan_def
*chandef
,
962 enum nl80211_iftype iftype
)
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
974 check_no_ir
= !cfg80211_ir_permissive_chan(wiphy
, iftype
,
977 return _cfg80211_reg_can_beacon(wiphy
, chandef
, iftype
, check_no_ir
);
979 EXPORT_SYMBOL(cfg80211_reg_can_beacon_relax
);
981 int cfg80211_set_monitor_channel(struct cfg80211_registered_device
*rdev
,
982 struct cfg80211_chan_def
*chandef
)
984 if (!rdev
->ops
->set_monitor_channel
)
986 if (!cfg80211_has_monitors_only(rdev
))
989 return rdev_set_monitor_channel(rdev
, chandef
);
993 cfg80211_get_chan_state(struct wireless_dev
*wdev
,
994 struct ieee80211_channel
**chan
,
995 enum cfg80211_chan_mode
*chanmode
,
1001 *chanmode
= CHAN_MODE_UNDEFINED
;
1003 ASSERT_WDEV_LOCK(wdev
);
1005 if (wdev
->netdev
&& !netif_running(wdev
->netdev
))
1008 switch (wdev
->iftype
) {
1009 case NL80211_IFTYPE_ADHOC
:
1010 if (wdev
->current_bss
) {
1011 *chan
= wdev
->current_bss
->pub
.channel
;
1012 *chanmode
= (wdev
->ibss_fixed
&&
1013 !wdev
->ibss_dfs_possible
)
1015 : CHAN_MODE_EXCLUSIVE
;
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
);
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
;
1032 case NL80211_IFTYPE_AP
:
1033 case NL80211_IFTYPE_P2P_GO
:
1034 if (wdev
->cac_started
) {
1035 *chan
= wdev
->chandef
.chan
;
1036 *chanmode
= CHAN_MODE_SHARED
;
1037 *radar_detect
|= BIT(wdev
->chandef
.width
);
1038 } else if (wdev
->beacon_interval
) {
1039 *chan
= wdev
->chandef
.chan
;
1040 *chanmode
= CHAN_MODE_SHARED
;
1042 ret
= cfg80211_chandef_dfs_required(wdev
->wiphy
,
1047 *radar_detect
|= BIT(wdev
->chandef
.width
);
1050 case NL80211_IFTYPE_MESH_POINT
:
1051 if (wdev
->mesh_id_len
) {
1052 *chan
= wdev
->chandef
.chan
;
1053 *chanmode
= CHAN_MODE_SHARED
;
1055 ret
= cfg80211_chandef_dfs_required(wdev
->wiphy
,
1060 *radar_detect
|= BIT(wdev
->chandef
.width
);
1063 case NL80211_IFTYPE_OCB
:
1064 if (wdev
->chandef
.chan
) {
1065 *chan
= wdev
->chandef
.chan
;
1066 *chanmode
= CHAN_MODE_SHARED
;
1070 case NL80211_IFTYPE_MONITOR
:
1071 case NL80211_IFTYPE_AP_VLAN
:
1072 case NL80211_IFTYPE_WDS
:
1073 case NL80211_IFTYPE_P2P_DEVICE
:
1074 case NL80211_IFTYPE_NAN
:
1075 /* these interface types don't really have a channel */
1077 case NL80211_IFTYPE_UNSPECIFIED
:
1078 case NUM_NL80211_IFTYPES
: