2 * mac80211 - channel management
5 #include <linux/nl80211.h>
6 #include <net/cfg80211.h>
7 #include "ieee80211_i.h"
9 static enum ieee80211_chan_mode
10 __ieee80211_get_channel_mode(struct ieee80211_local
*local
,
11 struct ieee80211_sub_if_data
*ignore
)
13 struct ieee80211_sub_if_data
*sdata
;
15 lockdep_assert_held(&local
->iflist_mtx
);
17 list_for_each_entry(sdata
, &local
->interfaces
, list
) {
21 if (!ieee80211_sdata_running(sdata
))
24 switch (sdata
->vif
.type
) {
25 case NL80211_IFTYPE_MONITOR
:
27 case NL80211_IFTYPE_STATION
:
28 if (!sdata
->u
.mgd
.associated
)
31 case NL80211_IFTYPE_ADHOC
:
32 if (!sdata
->u
.ibss
.ssid_len
)
34 if (!sdata
->u
.ibss
.fixed_channel
)
35 return CHAN_MODE_HOPPING
;
37 case NL80211_IFTYPE_AP_VLAN
:
38 /* will also have _AP interface */
40 case NL80211_IFTYPE_AP
:
41 if (!sdata
->u
.ap
.beacon
)
44 case NL80211_IFTYPE_MESH_POINT
:
45 if (!sdata
->wdev
.mesh_id_len
)
52 return CHAN_MODE_FIXED
;
55 return CHAN_MODE_UNDEFINED
;
58 enum ieee80211_chan_mode
59 ieee80211_get_channel_mode(struct ieee80211_local
*local
,
60 struct ieee80211_sub_if_data
*ignore
)
62 enum ieee80211_chan_mode mode
;
64 mutex_lock(&local
->iflist_mtx
);
65 mode
= __ieee80211_get_channel_mode(local
, ignore
);
66 mutex_unlock(&local
->iflist_mtx
);
71 static enum nl80211_channel_type
72 ieee80211_get_superchan(struct ieee80211_local
*local
,
73 struct ieee80211_sub_if_data
*sdata
)
75 enum nl80211_channel_type superchan
= NL80211_CHAN_NO_HT
;
76 struct ieee80211_sub_if_data
*tmp
;
78 mutex_lock(&local
->iflist_mtx
);
79 list_for_each_entry(tmp
, &local
->interfaces
, list
) {
83 if (!ieee80211_sdata_running(tmp
))
86 switch (tmp
->vif
.bss_conf
.channel_type
) {
87 case NL80211_CHAN_NO_HT
:
88 case NL80211_CHAN_HT20
:
89 if (superchan
> tmp
->vif
.bss_conf
.channel_type
)
92 superchan
= tmp
->vif
.bss_conf
.channel_type
;
94 case NL80211_CHAN_HT40PLUS
:
95 WARN_ON(superchan
== NL80211_CHAN_HT40MINUS
);
96 superchan
= NL80211_CHAN_HT40PLUS
;
98 case NL80211_CHAN_HT40MINUS
:
99 WARN_ON(superchan
== NL80211_CHAN_HT40PLUS
);
100 superchan
= NL80211_CHAN_HT40MINUS
;
104 mutex_unlock(&local
->iflist_mtx
);
110 ieee80211_channel_types_are_compatible(enum nl80211_channel_type chantype1
,
111 enum nl80211_channel_type chantype2
,
112 enum nl80211_channel_type
*compat
)
115 * start out with chantype1 being the result,
116 * overwriting later if needed
122 case NL80211_CHAN_NO_HT
:
126 case NL80211_CHAN_HT20
:
128 * allow any change that doesn't go to no-HT
129 * (if it already is no-HT no change is needed)
131 if (chantype2
== NL80211_CHAN_NO_HT
)
136 case NL80211_CHAN_HT40PLUS
:
137 case NL80211_CHAN_HT40MINUS
:
138 /* allow smaller bandwidth and same */
139 if (chantype2
== NL80211_CHAN_NO_HT
)
141 if (chantype2
== NL80211_CHAN_HT20
)
143 if (chantype2
== chantype1
)
151 bool ieee80211_set_channel_type(struct ieee80211_local
*local
,
152 struct ieee80211_sub_if_data
*sdata
,
153 enum nl80211_channel_type chantype
)
155 enum nl80211_channel_type superchan
;
156 enum nl80211_channel_type compatchan
;
158 superchan
= ieee80211_get_superchan(local
, sdata
);
159 if (!ieee80211_channel_types_are_compatible(superchan
, chantype
,
163 local
->_oper_channel_type
= compatchan
;
166 sdata
->vif
.bss_conf
.channel_type
= chantype
;