192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond/*
292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * All rights reserved.
492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * This program is free software; you can redistribute it and/or modify
692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * it under the terms of the GNU General Public License as published by
792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * the Free Software Foundation; either version 2 of the License, or
892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * (at your option) any later version.
992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
1092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * This program is distributed in the hope that it will be useful,
1192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * but WITHOUT ANY WARRANTY; without even the implied warranty of
1292b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * GNU General Public License for more details.
1492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
1592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * You should have received a copy of the GNU General Public License along
1692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * with this program; if not, write to the Free Software Foundation, Inc.,
1792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
1992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
2092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * File: channel.c
2192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
22bbc9a9916bc1cd997f3bf303e7930d5f3c804d37André Goddard Rosa * Purpose: Channel number mapping
2392b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
2492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * Author: Lucas Lin
2592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
2692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * Date: Dec 24, 2004
2792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
2892b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
2992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
3092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond * Revision History:
31618d7d07bd11d077842e0384aded23655080b817Peter Senna Tschudin *	01-18-2005	RobertYu:	remove the for loop searching in
32618d7d07bd11d077842e0384aded23655080b817Peter Senna Tschudin *					ChannelValid, change ChannelRuleTab
33618d7d07bd11d077842e0384aded23655080b817Peter Senna Tschudin *					to lookup-type, reorder table items.
3492b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
3592b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond *
3692b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond */
3792b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
38110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley#include "device.h"
3992b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond#include "channel.h"
4092b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond#include "rf.h"
4192b96797118e5836294a6d42a5a8e10b86f50e3fForest Bond
42110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestleystatic struct ieee80211_rate vnt_rates_bg[] = {
43110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .bitrate = 10,  .hw_value = RATE_1M },
44110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .bitrate = 20,  .hw_value = RATE_2M },
45110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .bitrate = 55,  .hw_value = RATE_5M },
46110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .bitrate = 110, .hw_value = RATE_11M },
47110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .bitrate = 60,  .hw_value = RATE_6M },
48110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .bitrate = 90,  .hw_value = RATE_9M },
49110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .bitrate = 120, .hw_value = RATE_12M },
50110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .bitrate = 180, .hw_value = RATE_18M },
51110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .bitrate = 240, .hw_value = RATE_24M },
52110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .bitrate = 360, .hw_value = RATE_36M },
53110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .bitrate = 480, .hw_value = RATE_48M },
54110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .bitrate = 540, .hw_value = RATE_54M },
55110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley};
56110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley
57110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestleystatic struct ieee80211_rate vnt_rates_a[] = {
58110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .bitrate = 60,  .hw_value = RATE_6M },
59110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .bitrate = 90,  .hw_value = RATE_9M },
60110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .bitrate = 120, .hw_value = RATE_12M },
61110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .bitrate = 180, .hw_value = RATE_18M },
62110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .bitrate = 240, .hw_value = RATE_24M },
63110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .bitrate = 360, .hw_value = RATE_36M },
64110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .bitrate = 480, .hw_value = RATE_48M },
65110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .bitrate = 540, .hw_value = RATE_54M },
66110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley};
67110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley
68110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestleystatic struct ieee80211_channel vnt_channels_2ghz[] = {
69110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 2412, .hw_value = 1 },
70110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 2417, .hw_value = 2 },
71110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 2422, .hw_value = 3 },
72110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 2427, .hw_value = 4 },
73110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 2432, .hw_value = 5 },
74110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 2437, .hw_value = 6 },
75110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 2442, .hw_value = 7 },
76110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 2447, .hw_value = 8 },
77110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 2452, .hw_value = 9 },
78110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 2457, .hw_value = 10 },
79110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 2462, .hw_value = 11 },
80110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 2467, .hw_value = 12 },
81110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 2472, .hw_value = 13 },
82110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 2484, .hw_value = 14 }
83110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley};
84110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley
85110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestleystatic struct ieee80211_channel vnt_channels_5ghz[] = {
86110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 4915, .hw_value = 15 },
87110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 4920, .hw_value = 16 },
88110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 4925, .hw_value = 17 },
89110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 4935, .hw_value = 18 },
90110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 4940, .hw_value = 19 },
91110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 4945, .hw_value = 20 },
92110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 4960, .hw_value = 21 },
93110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 4980, .hw_value = 22 },
94110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5035, .hw_value = 23 },
95110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5040, .hw_value = 24 },
96110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5045, .hw_value = 25 },
97110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5055, .hw_value = 26 },
98110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5060, .hw_value = 27 },
99110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5080, .hw_value = 28 },
100110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5170, .hw_value = 29 },
101110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5180, .hw_value = 30 },
102110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5190, .hw_value = 31 },
103110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5200, .hw_value = 32 },
104110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5210, .hw_value = 33 },
105110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5220, .hw_value = 34 },
106110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5230, .hw_value = 35 },
107110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5240, .hw_value = 36 },
108110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5260, .hw_value = 37 },
109110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5280, .hw_value = 38 },
110110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5300, .hw_value = 39 },
111110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5320, .hw_value = 40 },
112110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5500, .hw_value = 41 },
113110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5520, .hw_value = 42 },
114110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5540, .hw_value = 43 },
115110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5560, .hw_value = 44 },
116110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5580, .hw_value = 45 },
117110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5600, .hw_value = 46 },
118110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5620, .hw_value = 47 },
119110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5640, .hw_value = 48 },
120110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5660, .hw_value = 49 },
121110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5680, .hw_value = 50 },
122110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5700, .hw_value = 51 },
123110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5745, .hw_value = 52 },
124110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5765, .hw_value = 53 },
125110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5785, .hw_value = 54 },
126110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5805, .hw_value = 55 },
127110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	{ .center_freq = 5825, .hw_value = 56 }
128110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley};
129110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley
130110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestleystatic struct ieee80211_supported_band vnt_supported_2ghz_band = {
131110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	.channels = vnt_channels_2ghz,
132110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	.n_channels = ARRAY_SIZE(vnt_channels_2ghz),
133110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	.bitrates = vnt_rates_bg,
134110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	.n_bitrates = ARRAY_SIZE(vnt_rates_bg),
135110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley};
136110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley
137110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestleystatic struct ieee80211_supported_band vnt_supported_5ghz_band = {
138110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	.channels = vnt_channels_5ghz,
139110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	.n_channels = ARRAY_SIZE(vnt_channels_5ghz),
140110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	.bitrates = vnt_rates_a,
141110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	.n_bitrates = ARRAY_SIZE(vnt_rates_a),
142110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley};
143110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley
144110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestleyvoid vnt_init_bands(struct vnt_private *priv)
145110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley{
146110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	struct ieee80211_channel *ch;
147110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	int i;
148110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley
1496242ecaeb6e3b6e3a864e9e6878817e3f5c0cb84Malcolm Priestley	switch (priv->rf_type) {
150110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	case RF_AIROHA7230:
151110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	case RF_VT3342A0:
152b63d6ed6ca857d9aac6e93635c9fc42656cd0c44Malcolm Priestley	default:
153110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley		ch = vnt_channels_5ghz;
154110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley
155110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley		for (i = 0; i < ARRAY_SIZE(vnt_channels_5ghz); i++) {
156110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley			ch[i].max_power = VNT_RF_MAX_POWER;
157110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley			ch[i].flags = IEEE80211_CHAN_NO_HT40;
158110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley		}
159110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley
160110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley		priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
161110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley						&vnt_supported_5ghz_band;
162110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	/* fallthrough */
163110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	case RF_AL2230:
164110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	case RF_AL2230S:
165110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	case RF_VT3226:
166110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	case RF_VT3226D0:
167110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley		ch = vnt_channels_2ghz;
168110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley
169110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley		for (i = 0; i < ARRAY_SIZE(vnt_channels_2ghz); i++) {
170110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley			ch[i].max_power = VNT_RF_MAX_POWER;
171110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley			ch[i].flags = IEEE80211_CHAN_NO_HT40;
172110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley		}
173110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley
174110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley		priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
175110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley						&vnt_supported_2ghz_band;
176110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley		break;
177110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley	}
178110f97e937476d56d595805c7bf5b98260468ea2Malcolm Priestley}
179