]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - net/mac80211/regdomain.c
[PATCH] mac80211: regulatory domain cleanup
[linux-2.6-omap-h63xx.git] / net / mac80211 / regdomain.c
1 /*
2  * Copyright 2002-2005, Instant802 Networks, Inc.
3  * Copyright 2005-2006, Devicescape Software, Inc.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  */
9
10 /*
11  * This regulatory domain control implementation is known to be incomplete
12  * and confusing. mac80211 regulatory domain control will be significantly
13  * reworked in the not-too-distant future.
14  *
15  * For now, drivers wishing to control which channels are and aren't available
16  * are advised as follows:
17  *  - set the IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED flag
18  *  - continue to include *ALL* possible channels in the modes registered
19  *    through ieee80211_register_hwmode()
20  *  - for each allowable ieee80211_channel structure registered in the above
21  *    call, set the flag member to some meaningful value such as
22  *    IEEE80211_CHAN_W_SCAN | IEEE80211_CHAN_W_ACTIVE_SCAN |
23  *    IEEE80211_CHAN_W_IBSS.
24  *  - leave flag as 0 for non-allowable channels
25  *
26  * The usual implementation is for a driver to read a device EEPROM to
27  * determine which regulatory domain it should be operating under, then
28  * looking up the allowable channels in a driver-local table, then performing
29  * the above.
30  */
31
32 #include <linux/module.h>
33 #include <linux/netdevice.h>
34 #include <net/mac80211.h>
35
36 static int ieee80211_regdom = 0x10; /* FCC */
37 module_param(ieee80211_regdom, int, 0444);
38 MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain; 64=MKK");
39
40 /*
41  * If firmware is upgraded by the vendor, additional channels can be used based
42  * on the new Japanese regulatory rules. This is indicated by setting
43  * ieee80211_japan_5ghz module parameter to one when loading the 80211 kernel
44  * module.
45  */
46 static int ieee80211_japan_5ghz /* = 0 */;
47 module_param(ieee80211_japan_5ghz, int, 0444);
48 MODULE_PARM_DESC(ieee80211_japan_5ghz, "Vendor-updated firmware for 5 GHz");
49
50
51 struct ieee80211_channel_range {
52         short start_freq;
53         short end_freq;
54         unsigned char power_level;
55         unsigned char antenna_max;
56 };
57
58 static const struct ieee80211_channel_range ieee80211_fcc_channels[] = {
59         { 2412, 2462, 27, 6 } /* IEEE 802.11b/g, channels 1..11 */,
60         { 5180, 5240, 17, 6 } /* IEEE 802.11a, channels 36..48 */,
61         { 5260, 5320, 23, 6 } /* IEEE 802.11a, channels 52..64 */,
62         { 5745, 5825, 30, 6 } /* IEEE 802.11a, channels 149..165, outdoor */,
63         { 0 }
64 };
65
66 static const struct ieee80211_channel_range ieee80211_mkk_channels[] = {
67         { 2412, 2472, 20, 6 } /* IEEE 802.11b/g, channels 1..13 */,
68         { 5170, 5240, 20, 6 } /* IEEE 802.11a, channels 34..48 */,
69         { 5260, 5320, 20, 6 } /* IEEE 802.11a, channels 52..64 */,
70         { 0 }
71 };
72
73
74 static const struct ieee80211_channel_range *channel_range =
75         ieee80211_fcc_channels;
76
77
78 static void ieee80211_unmask_channel(int mode, struct ieee80211_channel *chan)
79 {
80         int i;
81
82         chan->flag = 0;
83
84         if (ieee80211_regdom == 64 &&
85             (mode == MODE_ATHEROS_TURBO || mode == MODE_ATHEROS_TURBOG)) {
86                 /* Do not allow Turbo modes in Japan. */
87                 return;
88         }
89
90         for (i = 0; channel_range[i].start_freq; i++) {
91                 const struct ieee80211_channel_range *r = &channel_range[i];
92                 if (r->start_freq <= chan->freq && r->end_freq >= chan->freq) {
93                         if (ieee80211_regdom == 64 && !ieee80211_japan_5ghz &&
94                             chan->freq >= 5260 && chan->freq <= 5320) {
95                                 /*
96                                  * Skip new channels in Japan since the
97                                  * firmware was not marked having been upgraded
98                                  * by the vendor.
99                                  */
100                                 continue;
101                         }
102
103                         if (ieee80211_regdom == 0x10 &&
104                             (chan->freq == 5190 || chan->freq == 5210 ||
105                              chan->freq == 5230)) {
106                                     /* Skip MKK channels when in FCC domain. */
107                                     continue;
108                         }
109
110                         chan->flag |= IEEE80211_CHAN_W_SCAN |
111                                 IEEE80211_CHAN_W_ACTIVE_SCAN |
112                                 IEEE80211_CHAN_W_IBSS;
113                         chan->power_level = r->power_level;
114                         chan->antenna_max = r->antenna_max;
115
116                         if (ieee80211_regdom == 64 &&
117                             (chan->freq == 5170 || chan->freq == 5190 ||
118                              chan->freq == 5210 || chan->freq == 5230)) {
119                                 /*
120                                  * New regulatory rules in Japan have backwards
121                                  * compatibility with old channels in 5.15-5.25
122                                  * GHz band, but the station is not allowed to
123                                  * use active scan on these old channels.
124                                  */
125                                 chan->flag &= ~IEEE80211_CHAN_W_ACTIVE_SCAN;
126                         }
127
128                         if (ieee80211_regdom == 64 &&
129                             (chan->freq == 5260 || chan->freq == 5280 ||
130                              chan->freq == 5300 || chan->freq == 5320)) {
131                                 /*
132                                  * IBSS is not allowed on 5.25-5.35 GHz band
133                                  * due to radar detection requirements.
134                                  */
135                                 chan->flag &= ~IEEE80211_CHAN_W_IBSS;
136                         }
137
138                         break;
139                 }
140         }
141 }
142
143
144 void ieee80211_set_default_regdomain(struct ieee80211_hw_mode *mode)
145 {
146         int c;
147         for (c = 0; c < mode->num_channels; c++)
148                 ieee80211_unmask_channel(mode->mode, &mode->channels[c]);
149 }
150
151
152 void ieee80211_regdomain_init(void)
153 {
154         if (ieee80211_regdom == 0x40)
155                 channel_range = ieee80211_mkk_channels;
156 }
157