aboutsummaryrefslogtreecommitdiffstats
path: root/net/wireless
diff options
context:
space:
mode:
Diffstat (limited to 'net/wireless')
-rw-r--r--net/wireless/Makefile2
-rw-r--r--net/wireless/core.c41
-rw-r--r--net/wireless/core.h3
-rw-r--r--net/wireless/reg.c153
-rw-r--r--net/wireless/util.c98
5 files changed, 296 insertions, 1 deletions
diff --git a/net/wireless/Makefile b/net/wireless/Makefile
index 65710a42e5a7..b9f943c45f3b 100644
--- a/net/wireless/Makefile
+++ b/net/wireless/Makefile
@@ -1,5 +1,5 @@
1obj-$(CONFIG_WIRELESS_EXT) += wext.o 1obj-$(CONFIG_WIRELESS_EXT) += wext.o
2obj-$(CONFIG_CFG80211) += cfg80211.o 2obj-$(CONFIG_CFG80211) += cfg80211.o
3 3
4cfg80211-y += core.o sysfs.o radiotap.o 4cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o
5cfg80211-$(CONFIG_NL80211) += nl80211.o 5cfg80211-$(CONFIG_NL80211) += nl80211.o
diff --git a/net/wireless/core.c b/net/wireless/core.c
index cfc5fc5f9e75..80afacdae46c 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -232,6 +232,47 @@ int wiphy_register(struct wiphy *wiphy)
232{ 232{
233 struct cfg80211_registered_device *drv = wiphy_to_dev(wiphy); 233 struct cfg80211_registered_device *drv = wiphy_to_dev(wiphy);
234 int res; 234 int res;
235 enum ieee80211_band band;
236 struct ieee80211_supported_band *sband;
237 bool have_band = false;
238 int i;
239
240 /* sanity check supported bands/channels */
241 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
242 sband = wiphy->bands[band];
243 if (!sband)
244 continue;
245
246 sband->band = band;
247
248 if (!sband->n_channels || !sband->n_bitrates) {
249 WARN_ON(1);
250 return -EINVAL;
251 }
252
253 for (i = 0; i < sband->n_channels; i++) {
254 sband->channels[i].orig_flags =
255 sband->channels[i].flags;
256 sband->channels[i].orig_mag =
257 sband->channels[i].max_antenna_gain;
258 sband->channels[i].orig_mpwr =
259 sband->channels[i].max_power;
260 sband->channels[i].band = band;
261 }
262
263 have_band = true;
264 }
265
266 if (!have_band) {
267 WARN_ON(1);
268 return -EINVAL;
269 }
270
271 /* check and set up bitrates */
272 ieee80211_set_bitrate_flags(wiphy);
273
274 /* set up regulatory info */
275 wiphy_update_regulatory(wiphy);
235 276
236 mutex_lock(&cfg80211_drv_mutex); 277 mutex_lock(&cfg80211_drv_mutex);
237 278
diff --git a/net/wireless/core.h b/net/wireless/core.h
index eb0f846b40df..7a02c356d63d 100644
--- a/net/wireless/core.h
+++ b/net/wireless/core.h
@@ -78,4 +78,7 @@ extern void cfg80211_dev_free(struct cfg80211_registered_device *drv);
78extern int cfg80211_dev_rename(struct cfg80211_registered_device *drv, 78extern int cfg80211_dev_rename(struct cfg80211_registered_device *drv,
79 char *newname); 79 char *newname);
80 80
81void ieee80211_set_bitrate_flags(struct wiphy *wiphy);
82void wiphy_update_regulatory(struct wiphy *wiphy);
83
81#endif /* __NET_WIRELESS_CORE_H */ 84#endif /* __NET_WIRELESS_CORE_H */
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
new file mode 100644
index 000000000000..2b63c96dcf19
--- /dev/null
+++ b/net/wireless/reg.c
@@ -0,0 +1,153 @@
1/*
2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11/*
12 * This regulatory domain control implementation is highly incomplete, it
13 * only exists for the purpose of not regressing mac80211.
14 *
15 * For now, drivers can restrict the set of allowed channels by either
16 * not registering those channels or setting the IEEE80211_CHAN_DISABLED
17 * flag; that flag will only be *set* by this code, never *cleared.
18 *
19 * The usual implementation is for a driver to read a device EEPROM to
20 * determine which regulatory domain it should be operating under, then
21 * looking up the allowable channels in a driver-local table and finally
22 * registering those channels in the wiphy structure.
23 *
24 * Alternatively, drivers that trust the regulatory domain control here
25 * will register a complete set of capabilities and the control code
26 * will restrict the set by setting the IEEE80211_CHAN_* flags.
27 */
28#include <linux/kernel.h>
29#include <net/wireless.h>
30#include "core.h"
31
32static char *ieee80211_regdom = "US";
33module_param(ieee80211_regdom, charp, 0444);
34MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code");
35
36struct ieee80211_channel_range {
37 short start_freq;
38 short end_freq;
39 int max_power;
40 int max_antenna_gain;
41 u32 flags;
42};
43
44struct ieee80211_regdomain {
45 const char *code;
46 const struct ieee80211_channel_range *ranges;
47 int n_ranges;
48};
49
50#define RANGE_PWR(_start, _end, _pwr, _ag, _flags) \
51 { _start, _end, _pwr, _ag, _flags }
52
53
54/*
55 * Ideally, in the future, these definitions will be loaded from a
56 * userspace table via some daemon.
57 */
58static const struct ieee80211_channel_range ieee80211_US_channels[] = {
59 /* IEEE 802.11b/g, channels 1..11 */
60 RANGE_PWR(2412, 2462, 27, 6, 0),
61 /* IEEE 802.11a, channels 52..64 */
62 RANGE_PWR(5260, 5320, 23, 6, 0),
63 /* IEEE 802.11a, channels 149..165, outdoor */
64 RANGE_PWR(5745, 5825, 30, 6, 0),
65};
66
67static const struct ieee80211_channel_range ieee80211_JP_channels[] = {
68 /* IEEE 802.11b/g, channels 1..14 */
69 RANGE_PWR(2412, 2484, 20, 6, 0),
70 /* IEEE 802.11a, channels 34..48 */
71 RANGE_PWR(5170, 5240, 20, 6, IEEE80211_CHAN_PASSIVE_SCAN),
72 /* IEEE 802.11a, channels 52..64 */
73 RANGE_PWR(5260, 5320, 20, 6, IEEE80211_CHAN_NO_IBSS |
74 IEEE80211_CHAN_RADAR),
75};
76
77#define REGDOM(_code) \
78 { \
79 .code = __stringify(_code), \
80 .ranges = ieee80211_ ##_code## _channels, \
81 .n_ranges = ARRAY_SIZE(ieee80211_ ##_code## _channels), \
82 }
83
84static const struct ieee80211_regdomain ieee80211_regdoms[] = {
85 REGDOM(US),
86 REGDOM(JP),
87};
88
89
90static const struct ieee80211_regdomain *get_regdom(void)
91{
92 static const struct ieee80211_channel_range
93 ieee80211_world_channels[] = {
94 /* IEEE 802.11b/g, channels 1..11 */
95 RANGE_PWR(2412, 2462, 27, 6, 0),
96 };
97 static const struct ieee80211_regdomain regdom_world = REGDOM(world);
98 int i;
99
100 for (i = 0; i < ARRAY_SIZE(ieee80211_regdoms); i++)
101 if (strcmp(ieee80211_regdom, ieee80211_regdoms[i].code) == 0)
102 return &ieee80211_regdoms[i];
103
104 return &regdom_world;
105}
106
107
108static void handle_channel(struct ieee80211_channel *chan,
109 const struct ieee80211_regdomain *rd)
110{
111 int i;
112 u32 flags = chan->orig_flags;
113 const struct ieee80211_channel_range *rg = NULL;
114
115 for (i = 0; i < rd->n_ranges; i++) {
116 if (rd->ranges[i].start_freq <= chan->center_freq &&
117 chan->center_freq <= rd->ranges[i].end_freq) {
118 rg = &rd->ranges[i];
119 break;
120 }
121 }
122
123 if (!rg) {
124 /* not found */
125 flags |= IEEE80211_CHAN_DISABLED;
126 chan->flags = flags;
127 return;
128 }
129
130 chan->flags = flags;
131 chan->max_antenna_gain = min(chan->orig_mag,
132 rg->max_antenna_gain);
133 chan->max_power = min(chan->orig_mpwr, rg->max_power);
134}
135
136static void handle_band(struct ieee80211_supported_band *sband,
137 const struct ieee80211_regdomain *rd)
138{
139 int i;
140
141 for (i = 0; i < sband->n_channels; i++)
142 handle_channel(&sband->channels[i], rd);
143}
144
145void wiphy_update_regulatory(struct wiphy *wiphy)
146{
147 enum ieee80211_band band;
148 const struct ieee80211_regdomain *rd = get_regdom();
149
150 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
151 if (wiphy->bands[band])
152 handle_band(wiphy->bands[band], rd);
153}
diff --git a/net/wireless/util.c b/net/wireless/util.c
new file mode 100644
index 000000000000..0dcccbf3eb57
--- /dev/null
+++ b/net/wireless/util.c
@@ -0,0 +1,98 @@
1/*
2 * Wireless utility functions
3 *
4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
5 */
6#include <net/wireless.h>
7#include <asm/bitops.h>
8#include "core.h"
9
10int ieee80211_channel_to_frequency(int chan)
11{
12 if (chan < 14)
13 return 2407 + chan * 5;
14
15 if (chan == 14)
16 return 2484;
17
18 /* FIXME: 802.11j 17.3.8.3.2 */
19 return (chan + 1000) * 5;
20}
21EXPORT_SYMBOL(ieee80211_channel_to_frequency);
22
23int ieee80211_frequency_to_channel(int freq)
24{
25 if (freq == 2484)
26 return 14;
27
28 if (freq < 2484)
29 return (freq - 2407) / 5;
30
31 /* FIXME: 802.11j 17.3.8.3.2 */
32 return freq/5 - 1000;
33}
34EXPORT_SYMBOL(ieee80211_frequency_to_channel);
35
36static void set_mandatory_flags_band(struct ieee80211_supported_band *sband,
37 enum ieee80211_band band)
38{
39 int i, want;
40
41 switch (band) {
42 case IEEE80211_BAND_5GHZ:
43 want = 3;
44 for (i = 0; i < sband->n_bitrates; i++) {
45 if (sband->bitrates[i].bitrate == 60 ||
46 sband->bitrates[i].bitrate == 120 ||
47 sband->bitrates[i].bitrate == 240) {
48 sband->bitrates[i].flags |=
49 IEEE80211_RATE_MANDATORY_A;
50 want--;
51 }
52 }
53 WARN_ON(want);
54 break;
55 case IEEE80211_BAND_2GHZ:
56 want = 7;
57 for (i = 0; i < sband->n_bitrates; i++) {
58 if (sband->bitrates[i].bitrate == 10) {
59 sband->bitrates[i].flags |=
60 IEEE80211_RATE_MANDATORY_B |
61 IEEE80211_RATE_MANDATORY_G;
62 want--;
63 }
64
65 if (sband->bitrates[i].bitrate == 20 ||
66 sband->bitrates[i].bitrate == 55 ||
67 sband->bitrates[i].bitrate == 110 ||
68 sband->bitrates[i].bitrate == 60 ||
69 sband->bitrates[i].bitrate == 120 ||
70 sband->bitrates[i].bitrate == 240) {
71 sband->bitrates[i].flags |=
72 IEEE80211_RATE_MANDATORY_G;
73 want--;
74 }
75
76 if (sband->bitrates[i].bitrate == 10 ||
77 sband->bitrates[i].bitrate == 20 ||
78 sband->bitrates[i].bitrate == 55 ||
79 sband->bitrates[i].bitrate == 110)
80 sband->bitrates[i].flags |=
81 IEEE80211_RATE_ERP_G;
82 }
83 WARN_ON(want != 0 && want != 6);
84 break;
85 case IEEE80211_NUM_BANDS:
86 WARN_ON(1);
87 break;
88 }
89}
90
91void ieee80211_set_bitrate_flags(struct wiphy *wiphy)
92{
93 enum ieee80211_band band;
94
95 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
96 if (wiphy->bands[band])
97 set_mandatory_flags_band(wiphy->bands[band], band);
98}