aboutsummaryrefslogtreecommitdiffstats
path: root/net/wireless/chan.c
diff options
context:
space:
mode:
authorJohannes Berg <johannes@sipsolutions.net>2009-08-07 11:22:35 -0400
committerJohn W. Linville <linville@tuxdriver.com>2009-08-14 09:13:42 -0400
commit59bbb6f7574bc693ed8313b98eac641116c95b94 (patch)
treeda24ed15c5e375782e79b3dab7022d2100a7987a /net/wireless/chan.c
parentf26b32ed4bd5780855a79bb17fb1a431fa867dad (diff)
cfg80211: validate channel settings across interfaces
Currently, there's a problem that affects regulatory enforcement and connection stability, in that it is possible to switch the channel while connected to a network or joined to an IBSS. The problem comes from the fact that we only validate the channel against the current interface's type, not against any other interface. Thus, you have any type of interface up, additionally bring up a monitor mode interface and switch the channel on the monitor. This will obviously also switch the channel on the other interface. The problem now is that if you do that while sending beacons for IBSS mode, you can switch to a disabled channel or a channel that doesn't allow beaconing. Combined with a managed mode interface connected to an AP instead of an IBSS interface, you can easily break the connection that way. To fix this, this patch validates any channel change with all available interfaces, and disallows such changes on secondary interfaces if another interface is connected to an AP or joined to an IBSS. Signed-off-by: Johannes Berg <johannes@sipsolutions.net> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'net/wireless/chan.c')
-rw-r--r--net/wireless/chan.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/net/wireless/chan.c b/net/wireless/chan.c
new file mode 100644
index 000000000000..bc00c9a06b3d
--- /dev/null
+++ b/net/wireless/chan.c
@@ -0,0 +1,88 @@
1/*
2 * This file contains helper code to handle channel
3 * settings and keeping track of what is possible at
4 * any point in time.
5 *
6 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
7 */
8
9#include <net/cfg80211.h>
10#include "core.h"
11
12struct ieee80211_channel *
13rdev_fixed_channel(struct cfg80211_registered_device *rdev,
14 struct wireless_dev *for_wdev)
15{
16 struct wireless_dev *wdev;
17 struct ieee80211_channel *result = NULL;
18
19 WARN_ON(!mutex_is_locked(&rdev->devlist_mtx));
20
21 list_for_each_entry(wdev, &rdev->netdev_list, list) {
22 if (wdev == for_wdev)
23 continue;
24
25 /*
26 * Lock manually to tell lockdep about allowed
27 * nesting here if for_wdev->mtx is held already.
28 * This is ok as it's all under the rdev devlist
29 * mutex and as such can only be done once at any
30 * given time.
31 */
32 mutex_lock_nested(&wdev->mtx, SINGLE_DEPTH_NESTING);
33 if (wdev->current_bss)
34 result = wdev->current_bss->pub.channel;
35 wdev_unlock(wdev);
36
37 if (result)
38 break;
39 }
40
41 return result;
42}
43
44int rdev_set_freq(struct cfg80211_registered_device *rdev,
45 int freq, enum nl80211_channel_type channel_type)
46{
47 struct ieee80211_channel *chan;
48 struct ieee80211_sta_ht_cap *ht_cap;
49 int result;
50
51 if (rdev_fixed_channel(rdev, NULL))
52 return -EBUSY;
53
54 if (!rdev->ops->set_channel)
55 return -EOPNOTSUPP;
56
57 chan = ieee80211_get_channel(&rdev->wiphy, freq);
58
59 /* Primary channel not allowed */
60 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
61 return -EINVAL;
62
63 if (channel_type == NL80211_CHAN_HT40MINUS &&
64 chan->flags & IEEE80211_CHAN_NO_HT40MINUS)
65 return -EINVAL;
66 else if (channel_type == NL80211_CHAN_HT40PLUS &&
67 chan->flags & IEEE80211_CHAN_NO_HT40PLUS)
68 return -EINVAL;
69
70 ht_cap = &rdev->wiphy.bands[chan->band]->ht_cap;
71
72 if (channel_type != NL80211_CHAN_NO_HT) {
73 if (!ht_cap->ht_supported)
74 return -EINVAL;
75
76 if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) ||
77 ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT)
78 return -EINVAL;
79 }
80
81 result = rdev->ops->set_channel(&rdev->wiphy, chan, channel_type);
82 if (result)
83 return result;
84
85 rdev->channel = chan;
86
87 return 0;
88}