mmc: sdio: don't require CISTPL_VERS_1 to contain 4 strings
[linux-2.6/linux-2.6-openrd.git] / net / wireless / chan.c
bloba46ac6c9b3655dbc056b8a20846a972b2bba9fdb
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.
6 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
7 */
9 #include <net/cfg80211.h>
10 #include "core.h"
12 struct ieee80211_channel *
13 rdev_fixed_channel(struct cfg80211_registered_device *rdev,
14 struct wireless_dev *for_wdev)
16 struct wireless_dev *wdev;
17 struct ieee80211_channel *result = NULL;
19 WARN_ON(!mutex_is_locked(&rdev->devlist_mtx));
21 list_for_each_entry(wdev, &rdev->netdev_list, list) {
22 if (wdev == for_wdev)
23 continue;
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.
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);
37 if (result)
38 break;
41 return result;
44 int rdev_set_freq(struct cfg80211_registered_device *rdev,
45 struct wireless_dev *for_wdev,
46 int freq, enum nl80211_channel_type channel_type)
48 struct ieee80211_channel *chan;
49 struct ieee80211_sta_ht_cap *ht_cap;
50 int result;
52 if (rdev_fixed_channel(rdev, for_wdev))
53 return -EBUSY;
55 if (!rdev->ops->set_channel)
56 return -EOPNOTSUPP;
58 chan = ieee80211_get_channel(&rdev->wiphy, freq);
60 /* Primary channel not allowed */
61 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
62 return -EINVAL;
64 if (channel_type == NL80211_CHAN_HT40MINUS &&
65 chan->flags & IEEE80211_CHAN_NO_HT40MINUS)
66 return -EINVAL;
67 else if (channel_type == NL80211_CHAN_HT40PLUS &&
68 chan->flags & IEEE80211_CHAN_NO_HT40PLUS)
69 return -EINVAL;
71 ht_cap = &rdev->wiphy.bands[chan->band]->ht_cap;
73 if (channel_type != NL80211_CHAN_NO_HT) {
74 if (!ht_cap->ht_supported)
75 return -EINVAL;
77 if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) ||
78 ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT)
79 return -EINVAL;
82 result = rdev->ops->set_channel(&rdev->wiphy, chan, channel_type);
83 if (result)
84 return result;
86 rdev->channel = chan;
88 return 0;