drm: Fix authentication kernel crash
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / mac80211 / chan.c
blob889c3e93e0f4a9df2a1a2007799f2a2f13e8a496
1 /*
2 * mac80211 - channel management
3 */
5 #include <linux/nl80211.h>
6 #include "ieee80211_i.h"
8 static enum ieee80211_chan_mode
9 __ieee80211_get_channel_mode(struct ieee80211_local *local,
10 struct ieee80211_sub_if_data *ignore)
12 struct ieee80211_sub_if_data *sdata;
14 lockdep_assert_held(&local->iflist_mtx);
16 list_for_each_entry(sdata, &local->interfaces, list) {
17 if (sdata == ignore)
18 continue;
20 if (!ieee80211_sdata_running(sdata))
21 continue;
23 if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
24 continue;
26 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
27 !sdata->u.mgd.associated)
28 continue;
30 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
31 if (!sdata->u.ibss.ssid_len)
32 continue;
33 if (!sdata->u.ibss.fixed_channel)
34 return CHAN_MODE_HOPPING;
37 if (sdata->vif.type == NL80211_IFTYPE_AP &&
38 !sdata->u.ap.beacon)
39 continue;
41 return CHAN_MODE_FIXED;
44 return CHAN_MODE_UNDEFINED;
47 enum ieee80211_chan_mode
48 ieee80211_get_channel_mode(struct ieee80211_local *local,
49 struct ieee80211_sub_if_data *ignore)
51 enum ieee80211_chan_mode mode;
53 mutex_lock(&local->iflist_mtx);
54 mode = __ieee80211_get_channel_mode(local, ignore);
55 mutex_unlock(&local->iflist_mtx);
57 return mode;
60 bool ieee80211_set_channel_type(struct ieee80211_local *local,
61 struct ieee80211_sub_if_data *sdata,
62 enum nl80211_channel_type chantype)
64 struct ieee80211_sub_if_data *tmp;
65 enum nl80211_channel_type superchan = NL80211_CHAN_NO_HT;
66 bool result;
68 mutex_lock(&local->iflist_mtx);
70 list_for_each_entry(tmp, &local->interfaces, list) {
71 if (tmp == sdata)
72 continue;
74 if (!ieee80211_sdata_running(tmp))
75 continue;
77 switch (tmp->vif.bss_conf.channel_type) {
78 case NL80211_CHAN_NO_HT:
79 case NL80211_CHAN_HT20:
80 if (superchan > tmp->vif.bss_conf.channel_type)
81 break;
83 superchan = tmp->vif.bss_conf.channel_type;
84 break;
85 case NL80211_CHAN_HT40PLUS:
86 WARN_ON(superchan == NL80211_CHAN_HT40MINUS);
87 superchan = NL80211_CHAN_HT40PLUS;
88 break;
89 case NL80211_CHAN_HT40MINUS:
90 WARN_ON(superchan == NL80211_CHAN_HT40PLUS);
91 superchan = NL80211_CHAN_HT40MINUS;
92 break;
96 switch (superchan) {
97 case NL80211_CHAN_NO_HT:
98 case NL80211_CHAN_HT20:
100 * allow any change that doesn't go to no-HT
101 * (if it already is no-HT no change is needed)
103 if (chantype == NL80211_CHAN_NO_HT)
104 break;
105 superchan = chantype;
106 break;
107 case NL80211_CHAN_HT40PLUS:
108 case NL80211_CHAN_HT40MINUS:
109 /* allow smaller bandwidth and same */
110 if (chantype == NL80211_CHAN_NO_HT)
111 break;
112 if (chantype == NL80211_CHAN_HT20)
113 break;
114 if (superchan == chantype)
115 break;
116 result = false;
117 goto out;
120 local->_oper_channel_type = superchan;
122 if (sdata)
123 sdata->vif.bss_conf.channel_type = chantype;
125 result = true;
126 out:
127 mutex_unlock(&local->iflist_mtx);
129 return result;