1 /* 2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 3 * All rights reserved. 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * 20 * File: channel.c 21 * 22 * Purpose: Channel number mapping 23 * 24 * Author: Lucas Lin 25 * 26 * Date: Dec 24, 2004 27 * 28 * 29 * 30 * Revision History: 31 * 01-18-2005 RobertYu: remove the for loop searching in ChannelValid, 32 * change ChannelRuleTab to lookup-type, reorder table items. 33 * 34 * 35 */ 36 37 #include <linux/kernel.h> 38 #include "device.h" 39 #include "channel.h" 40 #include "rf.h" 41 42 static SChannelTblElement sChannelTbl[CB_MAX_CHANNEL+1] = 43 { 44 {0, 0, false}, 45 {1, 2412, true}, 46 {2, 2417, true}, 47 {3, 2422, true}, 48 {4, 2427, true}, 49 {5, 2432, true}, 50 {6, 2437, true}, 51 {7, 2442, true}, 52 {8, 2447, true}, 53 {9, 2452, true}, 54 {10, 2457, true}, 55 {11, 2462, true}, 56 {12, 2467, true}, 57 {13, 2472, true}, 58 {14, 2484, true}, 59 {183, 4915, true}, //15 60 {184, 4920, true}, //16 61 {185, 4925, true}, //17 62 {187, 4935, true}, //18 63 {188, 4940, true}, //19 64 {189, 4945, true}, //20 65 {192, 4960, true}, //21 66 {196, 4980, true}, //22 67 {7, 5035, true}, //23 68 {8, 5040, true}, //24 69 {9, 5045, true}, //25 70 {11, 5055, true}, //26 71 {12, 5060, true}, //27 72 {16, 5080, true}, //28 73 {34, 5170, true}, //29 74 {36, 5180, true}, //30 75 {38, 5190, true}, //31 76 {40, 5200, true}, //32 77 {42, 5210, true}, //33 78 {44, 5220, true}, //34 79 {46, 5230, true}, //35 80 {48, 5240, true}, //36 81 {52, 5260, true}, //37 82 {56, 5280, true}, //38 83 {60, 5300, true}, //39 84 {64, 5320, true}, //40 85 {100, 5500, true}, //41 86 {104, 5520, true}, //42 87 {108, 5540, true}, //43 88 {112, 5560, true}, //44 89 {116, 5580, true}, //45 90 {120, 5600, true}, //46 91 {124, 5620, true}, //47 92 {128, 5640, true}, //48 93 {132, 5660, true}, //49 94 {136, 5680, true}, //50 95 {140, 5700, true}, //51 96 {149, 5745, true}, //52 97 {153, 5765, true}, //53 98 {157, 5785, true}, //54 99 {161, 5805, true}, //55 100 {165, 5825, true} //56 101 }; 102 103 104 /************************************************************************ 105 * Country Channel Valid 106 * Input: CountryCode, ChannelNum 107 * ChanneIndex is defined as VT3253 MAC channel: 108 * 1 = 2.4G channel 1 109 * 2 = 2.4G channel 2 110 * ... 111 * 14 = 2.4G channel 14 112 * 15 = 4.9G channel 183 113 * 16 = 4.9G channel 184 114 * ..... 115 * Output: true if the specified 5GHz band is allowed to be used. 116 False otherwise. 117 // 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196 (Value:15 ~ 22) 118 119 // 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64, 120 // 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 (Value 23 ~ 56) 121 ************************************************************************/ 122 bool 123 ChannelValid(unsigned int CountryCode, unsigned int ChannelIndex) 124 { 125 bool bValid; 126 127 bValid = false; 128 /* 129 * If Channel Index is invalid, return invalid 130 */ 131 if ((ChannelIndex > CB_MAX_CHANNEL) || 132 (ChannelIndex == 0)) 133 { 134 bValid = false; 135 goto exit; 136 } 137 138 bValid = sChannelTbl[ChannelIndex].bValid; 139 140 exit: 141 return (bValid); 142 143 } /* end ChannelValid */ 144 145 void CHvInitChannelTable(struct vnt_private *pDevice) 146 { 147 bool bMultiBand = false; 148 int ii; 149 150 for (ii = 1; ii <= CB_MAX_CHANNEL; ii++) 151 sChannelTbl[ii].bValid = false; 152 153 switch (pDevice->byRFType) { 154 case RF_AL2230: 155 case RF_AL2230S: 156 case RF_VT3226: 157 case RF_VT3226D0: 158 bMultiBand = false; 159 break; 160 case RF_AIROHA7230: 161 case RF_VT3342A0: 162 default : 163 bMultiBand = true; 164 break; 165 } 166 167 if (bMultiBand == true) { 168 for (ii = 0; ii < CB_MAX_CHANNEL; ii++) { 169 sChannelTbl[ii+1].bValid = true; 170 } 171 } else { 172 for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) { 173 sChannelTbl[ii+1].bValid = true; 174 } 175 } 176 } 177 178 static struct ieee80211_rate vnt_rates_bg[] = { 179 { .bitrate = 10, .hw_value = RATE_1M }, 180 { .bitrate = 20, .hw_value = RATE_2M }, 181 { .bitrate = 55, .hw_value = RATE_5M }, 182 { .bitrate = 110, .hw_value = RATE_11M }, 183 { .bitrate = 60, .hw_value = RATE_6M }, 184 { .bitrate = 90, .hw_value = RATE_9M }, 185 { .bitrate = 120, .hw_value = RATE_12M }, 186 { .bitrate = 180, .hw_value = RATE_18M }, 187 { .bitrate = 240, .hw_value = RATE_24M }, 188 { .bitrate = 360, .hw_value = RATE_36M }, 189 { .bitrate = 480, .hw_value = RATE_48M }, 190 { .bitrate = 540, .hw_value = RATE_54M }, 191 }; 192 193 static struct ieee80211_rate vnt_rates_a[] = { 194 { .bitrate = 60, .hw_value = RATE_6M }, 195 { .bitrate = 90, .hw_value = RATE_9M }, 196 { .bitrate = 120, .hw_value = RATE_12M }, 197 { .bitrate = 180, .hw_value = RATE_18M }, 198 { .bitrate = 240, .hw_value = RATE_24M }, 199 { .bitrate = 360, .hw_value = RATE_36M }, 200 { .bitrate = 480, .hw_value = RATE_48M }, 201 { .bitrate = 540, .hw_value = RATE_54M }, 202 }; 203 204 static struct ieee80211_channel vnt_channels_2ghz[] = { 205 { .center_freq = 2412, .hw_value = 1 }, 206 { .center_freq = 2417, .hw_value = 2 }, 207 { .center_freq = 2422, .hw_value = 3 }, 208 { .center_freq = 2427, .hw_value = 4 }, 209 { .center_freq = 2432, .hw_value = 5 }, 210 { .center_freq = 2437, .hw_value = 6 }, 211 { .center_freq = 2442, .hw_value = 7 }, 212 { .center_freq = 2447, .hw_value = 8 }, 213 { .center_freq = 2452, .hw_value = 9 }, 214 { .center_freq = 2457, .hw_value = 10 }, 215 { .center_freq = 2462, .hw_value = 11 }, 216 { .center_freq = 2467, .hw_value = 12 }, 217 { .center_freq = 2472, .hw_value = 13 }, 218 { .center_freq = 2484, .hw_value = 14 } 219 }; 220 221 static struct ieee80211_channel vnt_channels_5ghz[] = { 222 { .center_freq = 4915, .hw_value = 15 }, 223 { .center_freq = 4920, .hw_value = 16 }, 224 { .center_freq = 4925, .hw_value = 17 }, 225 { .center_freq = 4935, .hw_value = 18 }, 226 { .center_freq = 4940, .hw_value = 19 }, 227 { .center_freq = 4945, .hw_value = 20 }, 228 { .center_freq = 4960, .hw_value = 21 }, 229 { .center_freq = 4980, .hw_value = 22 }, 230 { .center_freq = 5035, .hw_value = 23 }, 231 { .center_freq = 5040, .hw_value = 24 }, 232 { .center_freq = 5045, .hw_value = 25 }, 233 { .center_freq = 5055, .hw_value = 26 }, 234 { .center_freq = 5060, .hw_value = 27 }, 235 { .center_freq = 5080, .hw_value = 28 }, 236 { .center_freq = 5170, .hw_value = 29 }, 237 { .center_freq = 5180, .hw_value = 30 }, 238 { .center_freq = 5190, .hw_value = 31 }, 239 { .center_freq = 5200, .hw_value = 32 }, 240 { .center_freq = 5210, .hw_value = 33 }, 241 { .center_freq = 5220, .hw_value = 34 }, 242 { .center_freq = 5230, .hw_value = 35 }, 243 { .center_freq = 5240, .hw_value = 36 }, 244 { .center_freq = 5260, .hw_value = 37 }, 245 { .center_freq = 5280, .hw_value = 38 }, 246 { .center_freq = 5300, .hw_value = 39 }, 247 { .center_freq = 5320, .hw_value = 40 }, 248 { .center_freq = 5500, .hw_value = 41 }, 249 { .center_freq = 5520, .hw_value = 42 }, 250 { .center_freq = 5540, .hw_value = 43 }, 251 { .center_freq = 5560, .hw_value = 44 }, 252 { .center_freq = 5580, .hw_value = 45 }, 253 { .center_freq = 5600, .hw_value = 46 }, 254 { .center_freq = 5620, .hw_value = 47 }, 255 { .center_freq = 5640, .hw_value = 48 }, 256 { .center_freq = 5660, .hw_value = 49 }, 257 { .center_freq = 5680, .hw_value = 50 }, 258 { .center_freq = 5700, .hw_value = 51 }, 259 { .center_freq = 5745, .hw_value = 52 }, 260 { .center_freq = 5765, .hw_value = 53 }, 261 { .center_freq = 5785, .hw_value = 54 }, 262 { .center_freq = 5805, .hw_value = 55 }, 263 { .center_freq = 5825, .hw_value = 56 } 264 }; 265 266 static struct ieee80211_supported_band vnt_supported_2ghz_band = { 267 .channels = vnt_channels_2ghz, 268 .n_channels = ARRAY_SIZE(vnt_channels_2ghz), 269 .bitrates = vnt_rates_bg, 270 .n_bitrates = ARRAY_SIZE(vnt_rates_bg), 271 }; 272 273 static struct ieee80211_supported_band vnt_supported_5ghz_band = { 274 .channels = vnt_channels_5ghz, 275 .n_channels = ARRAY_SIZE(vnt_channels_5ghz), 276 .bitrates = vnt_rates_a, 277 .n_bitrates = ARRAY_SIZE(vnt_rates_a), 278 }; 279 280 void vnt_init_bands(struct vnt_private *priv) 281 { 282 struct ieee80211_channel *ch; 283 int i; 284 285 switch (priv->byRFType) { 286 case RF_AIROHA7230: 287 case RF_VT3342A0: 288 ch = vnt_channels_5ghz; 289 290 for (i = 0; i < ARRAY_SIZE(vnt_channels_5ghz); i++) { 291 ch[i].max_power = VNT_RF_MAX_POWER; 292 ch[i].flags = IEEE80211_CHAN_NO_HT40; 293 } 294 295 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = 296 &vnt_supported_5ghz_band; 297 /* fallthrough */ 298 case RF_AL2230: 299 case RF_AL2230S: 300 case RF_VT3226: 301 case RF_VT3226D0: 302 ch = vnt_channels_2ghz; 303 304 for (i = 0; i < ARRAY_SIZE(vnt_channels_2ghz); i++) { 305 ch[i].max_power = VNT_RF_MAX_POWER; 306 ch[i].flags = IEEE80211_CHAN_NO_HT40; 307 } 308 309 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = 310 &vnt_supported_2ghz_band; 311 break; 312 } 313 } 314