]> bbs.cooldavid.org Git - net-next-2.6.git/blob - net/wireless/chan.c
cfg80211: validate channel settings across interfaces
[net-next-2.6.git] / net / wireless / chan.c
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
12 struct ieee80211_channel *
13 rdev_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
44 int 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 }