Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / drivers / net / wireless / zd1211rw / zd_ieee80211.c
blob7c277ec43f79a6a736f3055a283c18a9c677e5c9
1 /* ZD1211 USB-WLAN driver for Linux
3 * Copyright (C) 2005-2007 Ulrich Kunitz <kune@deine-taler.de>
4 * Copyright (C) 2006-2007 Daniel Drake <dsd@gentoo.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * In the long term, we'll probably find a better way of handling regulatory
23 * requirements outside of the driver.
26 #include <linux/kernel.h>
27 #include <net/mac80211.h>
29 #include "zd_ieee80211.h"
30 #include "zd_mac.h"
32 struct channel_range {
33 u8 regdomain;
34 u8 start;
35 u8 end; /* exclusive (channel must be less than end) */
38 static const struct channel_range channel_ranges[] = {
39 { ZD_REGDOMAIN_FCC, 1, 12 },
40 { ZD_REGDOMAIN_IC, 1, 12 },
41 { ZD_REGDOMAIN_ETSI, 1, 14 },
42 { ZD_REGDOMAIN_JAPAN, 1, 14 },
43 { ZD_REGDOMAIN_SPAIN, 1, 14 },
44 { ZD_REGDOMAIN_FRANCE, 1, 14 },
46 /* Japan originally only had channel 14 available (see CHNL_ID 0x40 in
47 * 802.11). However, in 2001 the range was extended to include channels
48 * 1-13. The ZyDAS devices still use the old region code but are
49 * designed to allow the extra channel access in Japan. */
50 { ZD_REGDOMAIN_JAPAN_ADD, 1, 15 },
53 static const struct channel_range *zd_channel_range(u8 regdomain)
55 int i;
56 for (i = 0; i < ARRAY_SIZE(channel_ranges); i++) {
57 const struct channel_range *range = &channel_ranges[i];
58 if (range->regdomain == regdomain)
59 return range;
61 return NULL;
64 #define CHAN_TO_IDX(chan) ((chan) - 1)
66 static void unmask_bg_channels(struct ieee80211_hw *hw,
67 const struct channel_range *range,
68 struct ieee80211_hw_mode *mode)
70 u8 channel;
72 for (channel = range->start; channel < range->end; channel++) {
73 struct ieee80211_channel *chan =
74 &mode->channels[CHAN_TO_IDX(channel)];
75 chan->flag |= IEEE80211_CHAN_W_SCAN |
76 IEEE80211_CHAN_W_ACTIVE_SCAN |
77 IEEE80211_CHAN_W_IBSS;
81 void zd_geo_init(struct ieee80211_hw *hw, u8 regdomain)
83 struct zd_mac *mac = zd_hw_mac(hw);
84 const struct channel_range *range;
86 dev_dbg(zd_mac_dev(mac), "regdomain %#02x\n", regdomain);
88 range = zd_channel_range(regdomain);
89 if (!range) {
90 /* The vendor driver overrides the regulatory domain and
91 * allowed channel registers and unconditionally restricts
92 * available channels to 1-11 everywhere. Match their
93 * questionable behaviour only for regdomains which we don't
94 * recognise. */
95 dev_warn(zd_mac_dev(mac), "Unrecognised regulatory domain: "
96 "%#02x. Defaulting to FCC.\n", regdomain);
97 range = zd_channel_range(ZD_REGDOMAIN_FCC);
100 unmask_bg_channels(hw, range, &mac->modes[0]);
101 unmask_bg_channels(hw, range, &mac->modes[1]);