minstrel_ht: enable frame aggregation for fixed rate
[deliverable/linux.git] / net / wireless / chan.c
CommitLineData
59bbb6f7
JB
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
54858ee5 9#include <linux/export.h>
59bbb6f7
JB
10#include <net/cfg80211.h>
11#include "core.h"
12
9588bbd5
JM
13struct ieee80211_channel *
14rdev_freq_to_chan(struct cfg80211_registered_device *rdev,
59bbb6f7
JB
15 int freq, enum nl80211_channel_type channel_type)
16{
17 struct ieee80211_channel *chan;
18 struct ieee80211_sta_ht_cap *ht_cap;
59bbb6f7
JB
19
20 chan = ieee80211_get_channel(&rdev->wiphy, freq);
21
22 /* Primary channel not allowed */
23 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
9588bbd5 24 return NULL;
59bbb6f7
JB
25
26 if (channel_type == NL80211_CHAN_HT40MINUS &&
27 chan->flags & IEEE80211_CHAN_NO_HT40MINUS)
9588bbd5 28 return NULL;
59bbb6f7
JB
29 else if (channel_type == NL80211_CHAN_HT40PLUS &&
30 chan->flags & IEEE80211_CHAN_NO_HT40PLUS)
9588bbd5 31 return NULL;
59bbb6f7
JB
32
33 ht_cap = &rdev->wiphy.bands[chan->band]->ht_cap;
34
35 if (channel_type != NL80211_CHAN_NO_HT) {
36 if (!ht_cap->ht_supported)
9588bbd5 37 return NULL;
59bbb6f7 38
aed8e1f9
HS
39 if (channel_type != NL80211_CHAN_HT20 &&
40 (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) ||
41 ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT))
9588bbd5 42 return NULL;
59bbb6f7
JB
43 }
44
9588bbd5
JM
45 return chan;
46}
47
294a20e0 48bool cfg80211_can_beacon_sec_chan(struct wiphy *wiphy,
54858ee5
AS
49 struct ieee80211_channel *chan,
50 enum nl80211_channel_type channel_type)
9236d838
LR
51{
52 struct ieee80211_channel *sec_chan;
53 int diff;
54
55 switch (channel_type) {
56 case NL80211_CHAN_HT40PLUS:
57 diff = 20;
09a02fdb 58 break;
9236d838
LR
59 case NL80211_CHAN_HT40MINUS:
60 diff = -20;
09a02fdb 61 break;
9236d838 62 default:
d58e7e37 63 return true;
9236d838
LR
64 }
65
66 sec_chan = ieee80211_get_channel(wiphy, chan->center_freq + diff);
67 if (!sec_chan)
68 return false;
69
70 /* we'll need a DFS capability later */
71 if (sec_chan->flags & (IEEE80211_CHAN_DISABLED |
72 IEEE80211_CHAN_PASSIVE_SCAN |
73 IEEE80211_CHAN_NO_IBSS |
74 IEEE80211_CHAN_RADAR))
75 return false;
76
77 return true;
78}
54858ee5 79EXPORT_SYMBOL(cfg80211_can_beacon_sec_chan);
9236d838 80
e8c9bd5b
JB
81int cfg80211_set_monitor_channel(struct cfg80211_registered_device *rdev,
82 int freq, enum nl80211_channel_type chantype)
9588bbd5
JM
83{
84 struct ieee80211_channel *chan;
b78e8cea 85 int err;
9588bbd5 86
e8c9bd5b 87 if (!rdev->ops->set_monitor_channel)
9588bbd5 88 return -EOPNOTSUPP;
4f03c1ed
MK
89 if (!cfg80211_has_monitors_only(rdev))
90 return -EBUSY;
9588bbd5 91
e8c9bd5b 92 chan = rdev_freq_to_chan(rdev, freq, chantype);
9588bbd5
JM
93 if (!chan)
94 return -EINVAL;
95
b78e8cea
MK
96 err = rdev->ops->set_monitor_channel(&rdev->wiphy, chan, chantype);
97 if (!err) {
98 rdev->monitor_channel = chan;
99 rdev->monitor_channel_type = chantype;
100 }
101
102 return err;
59bbb6f7 103}
26ab9a0c
MK
104
105void
106cfg80211_get_chan_state(struct cfg80211_registered_device *rdev,
107 struct wireless_dev *wdev,
108 struct ieee80211_channel **chan,
109 enum cfg80211_chan_mode *chanmode)
110{
111 *chan = NULL;
112 *chanmode = CHAN_MODE_UNDEFINED;
113
114 ASSERT_RDEV_LOCK(rdev);
115 ASSERT_WDEV_LOCK(wdev);
116
117 if (!netif_running(wdev->netdev))
118 return;
119
120 switch (wdev->iftype) {
121 case NL80211_IFTYPE_ADHOC:
122 if (wdev->current_bss) {
123 *chan = wdev->current_bss->pub.channel;
124 *chanmode = wdev->ibss_fixed
125 ? CHAN_MODE_SHARED
126 : CHAN_MODE_EXCLUSIVE;
127 return;
128 }
129 case NL80211_IFTYPE_STATION:
130 case NL80211_IFTYPE_P2P_CLIENT:
131 if (wdev->current_bss) {
132 *chan = wdev->current_bss->pub.channel;
133 *chanmode = CHAN_MODE_SHARED;
134 return;
135 }
136 break;
137 case NL80211_IFTYPE_AP:
138 case NL80211_IFTYPE_P2P_GO:
139 case NL80211_IFTYPE_MESH_POINT:
140 *chan = wdev->channel;
141 *chanmode = CHAN_MODE_SHARED;
142 return;
143 case NL80211_IFTYPE_MONITOR:
144 case NL80211_IFTYPE_AP_VLAN:
145 case NL80211_IFTYPE_WDS:
146 /* these interface types don't really have a channel */
147 return;
148 case NL80211_IFTYPE_UNSPECIFIED:
149 case NUM_NL80211_IFTYPES:
150 WARN_ON(1);
151 }
152
153 return;
154}
This page took 0.234896 seconds and 5 git commands to generate.