]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/net/wireless/zd1211rw/zd_ieee80211.c
cfg80211 API for channels/bitrates, mac80211 and driver conversion
[mirror_ubuntu-bionic-kernel.git] / drivers / net / wireless / zd1211rw / zd_ieee80211.c
1 /* ZD1211 USB-WLAN driver for Linux
2 *
3 * Copyright (C) 2005-2007 Ulrich Kunitz <kune@deine-taler.de>
4 * Copyright (C) 2006-2007 Daniel Drake <dsd@gentoo.org>
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 as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
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.
15 *
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
19 */
20
21 /*
22 * In the long term, we'll probably find a better way of handling regulatory
23 * requirements outside of the driver.
24 */
25
26 #include <linux/kernel.h>
27 #include <net/mac80211.h>
28
29 #include "zd_ieee80211.h"
30 #include "zd_mac.h"
31
32 struct channel_range {
33 u8 regdomain;
34 u8 start;
35 u8 end; /* exclusive (channel must be less than end) */
36 };
37
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 },
45
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 },
51 };
52
53 static const struct channel_range *zd_channel_range(u8 regdomain)
54 {
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;
60 }
61 return NULL;
62 }
63
64 #define CHAN_TO_IDX(chan) ((chan) - 1)
65
66 static void unmask_bg_channels(struct ieee80211_hw *hw,
67 const struct channel_range *range,
68 struct ieee80211_supported_band *sband)
69 {
70 u8 channel;
71
72 for (channel = range->start; channel < range->end; channel++) {
73 struct ieee80211_channel *chan =
74 &sband->channels[CHAN_TO_IDX(channel)];
75 chan->flags = 0;
76 }
77 }
78
79 void zd_geo_init(struct ieee80211_hw *hw, u8 regdomain)
80 {
81 struct zd_mac *mac = zd_hw_mac(hw);
82 const struct channel_range *range;
83
84 dev_dbg(zd_mac_dev(mac), "regdomain %#02x\n", regdomain);
85
86 range = zd_channel_range(regdomain);
87 if (!range) {
88 /* The vendor driver overrides the regulatory domain and
89 * allowed channel registers and unconditionally restricts
90 * available channels to 1-11 everywhere. Match their
91 * questionable behaviour only for regdomains which we don't
92 * recognise. */
93 dev_warn(zd_mac_dev(mac), "Unrecognised regulatory domain: "
94 "%#02x. Defaulting to FCC.\n", regdomain);
95 range = zd_channel_range(ZD_REGDOMAIN_FCC);
96 }
97
98 unmask_bg_channels(hw, range, &mac->band);
99 }
100