3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * A lot of this code is generic and should be moved into the upper layers
23 #include <linux/errno.h>
24 #include <linux/wireless.h>
25 #include <linux/kernel.h>
26 #include <net/ieee80211.h>
29 #include "zd_ieee80211.h"
32 static const struct channel_range channel_ranges[] = {
34 [ZD_REGDOMAIN_FCC] = { 1, 12},
35 [ZD_REGDOMAIN_IC] = { 1, 12},
36 [ZD_REGDOMAIN_ETSI] = { 1, 14},
37 [ZD_REGDOMAIN_JAPAN] = { 1, 14},
38 [ZD_REGDOMAIN_SPAIN] = { 1, 14},
39 [ZD_REGDOMAIN_FRANCE] = { 1, 14},
40 [ZD_REGDOMAIN_JAPAN_ADD] = {14, 15},
43 const struct channel_range *zd_channel_range(u8 regdomain)
45 if (regdomain >= ARRAY_SIZE(channel_ranges))
47 return &channel_ranges[regdomain];
50 int zd_regdomain_supports_channel(u8 regdomain, u8 channel)
52 const struct channel_range *range = zd_channel_range(regdomain);
53 return range->start <= channel && channel < range->end;
56 int zd_regdomain_supported(u8 regdomain)
58 const struct channel_range *range = zd_channel_range(regdomain);
59 return range->start != 0;
62 /* Stores channel frequencies in MHz. */
63 static const u16 channel_frequencies[] = {
64 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447,
65 2452, 2457, 2462, 2467, 2472, 2484,
68 #define NUM_CHANNELS ARRAY_SIZE(channel_frequencies)
70 static int compute_freq(struct iw_freq *freq, u32 mhz, u32 hz)
75 if (mhz >= 1000000000U) {
76 pr_debug("zd1211 mhz %u to large\n", mhz);
82 while (mhz >= factor) {
89 freq->m = mhz * (1000000U/factor) + hz/factor;
94 int zd_channel_to_freq(struct iw_freq *freq, u8 channel)
96 if (channel > NUM_CHANNELS) {
106 return compute_freq(freq, channel_frequencies[channel-1], 0);
109 static int freq_to_mhz(const struct iw_freq *freq)
114 /* Such high frequencies are not supported. */
119 for (e = freq->e; e > 0; --e) {
122 factor = 1000000U / factor;
124 if (freq->m % factor) {
128 return freq->m / factor;
131 int zd_find_channel(u8 *channel, const struct iw_freq *freq)
136 if (!(freq->flags & IW_FREQ_FIXED))
139 if (freq->m < 1000) {
140 if (freq->m > NUM_CHANNELS || freq->m == 0)
146 r = freq_to_mhz(freq);
151 for (i = 0; i < NUM_CHANNELS; i++) {
152 if (mhz == channel_frequencies[i]) {
161 int zd_geo_init(struct ieee80211_device *ieee, u8 regdomain)
163 struct ieee80211_geo geo;
164 const struct channel_range *range;
168 dev_dbg(zd_mac_dev(zd_netdev_mac(ieee->dev)),
169 "regdomain %#04x\n", regdomain);
171 range = zd_channel_range(regdomain);
172 if (range->start == 0) {
173 dev_err(zd_mac_dev(zd_netdev_mac(ieee->dev)),
174 "zd1211 regdomain %#04x not supported\n",
179 memset(&geo, 0, sizeof(geo));
181 for (i = 0, channel = range->start; channel < range->end; channel++) {
182 struct ieee80211_channel *chan = &geo.bg[i++];
183 chan->freq = channel_frequencies[channel - 1];
184 chan->channel = channel;
188 memcpy(geo.name, "XX ", 4);
189 ieee80211_set_geo(ieee, &geo);