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 * In the long term, we'll probably find a better way of handling regulatory
20 * requirements outside of the driver.
23 #include <linux/kernel.h>
24 #include <net/mac80211.h>
26 #include "zd_ieee80211.h"
29 struct channel_range {
32 u8 end; /* exclusive (channel must be less than end) */
35 static const struct channel_range channel_ranges[] = {
36 { ZD_REGDOMAIN_FCC, 1, 12 },
37 { ZD_REGDOMAIN_IC, 1, 12 },
38 { ZD_REGDOMAIN_ETSI, 1, 14 },
39 { ZD_REGDOMAIN_JAPAN, 1, 14 },
40 { ZD_REGDOMAIN_SPAIN, 1, 14 },
41 { ZD_REGDOMAIN_FRANCE, 1, 14 },
43 /* Japan originally only had channel 14 available (see CHNL_ID 0x40 in
44 * 802.11). However, in 2001 the range was extended to include channels
45 * 1-13. The ZyDAS devices still use the old region code but are
46 * designed to allow the extra channel access in Japan. */
47 { ZD_REGDOMAIN_JAPAN_ADD, 1, 15 },
50 static const struct channel_range *zd_channel_range(u8 regdomain)
53 for (i = 0; i < ARRAY_SIZE(channel_ranges); i++) {
54 const struct channel_range *range = &channel_ranges[i];
55 if (range->regdomain == regdomain)
61 #define CHAN_TO_IDX(chan) ((chan) - 1)
63 static void unmask_bg_channels(struct ieee80211_hw *hw,
64 const struct channel_range *range,
65 struct ieee80211_hw_mode *mode)
69 for (channel = range->start; channel < range->end; channel++) {
70 struct ieee80211_channel *chan =
71 &mode->channels[CHAN_TO_IDX(channel)];
72 chan->flag |= IEEE80211_CHAN_W_SCAN |
73 IEEE80211_CHAN_W_ACTIVE_SCAN |
74 IEEE80211_CHAN_W_IBSS;
78 void zd_geo_init(struct ieee80211_hw *hw, u8 regdomain)
80 struct zd_mac *mac = zd_hw_mac(hw);
81 const struct channel_range *range;
83 dev_dbg(zd_mac_dev(mac), "regdomain %#02x\n", regdomain);
85 range = zd_channel_range(regdomain);
87 /* The vendor driver overrides the regulatory domain and
88 * allowed channel registers and unconditionally restricts
89 * available channels to 1-11 everywhere. Match their
90 * questionable behaviour only for regdomains which we don't
92 dev_warn(zd_mac_dev(mac), "Unrecognised regulatory domain: "
93 "%#02x. Defaulting to FCC.\n", regdomain);
94 range = zd_channel_range(ZD_REGDOMAIN_FCC);
97 unmask_bg_channels(hw, range, &mac->modes[0]);
98 unmask_bg_channels(hw, range, &mac->modes[1]);