]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/staging/rt2860/common/cmm_cfg.c
Staging: rt28x0: run common/*.c files through Lindent
[net-next-2.6.git] / drivers / staging / rt2860 / common / cmm_cfg.c
CommitLineData
ca97b838
BZ
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 cmm_cfg.c
29
30 Abstract:
31 Ralink WiFi Driver configuration related subroutines
32
33 Revision History:
34 Who When What
35 --------- ---------- ----------------------------------------------
36*/
37
ca97b838
BZ
38#include "../rt_config.h"
39
96b3c83d 40char *GetPhyMode(int Mode)
ca97b838 41{
96b3c83d
BZ
42 switch (Mode) {
43 case MODE_CCK:
44 return "CCK";
45
46 case MODE_OFDM:
47 return "OFDM";
48 case MODE_HTMIX:
49 return "HTMIX";
50
51 case MODE_HTGREENFIELD:
52 return "GREEN";
53 default:
54 return "N/A";
ca97b838
BZ
55 }
56}
57
96b3c83d 58char *GetBW(int BW)
ca97b838 59{
96b3c83d
BZ
60 switch (BW) {
61 case BW_10:
62 return "10M";
63
64 case BW_20:
65 return "20M";
66 case BW_40:
67 return "40M";
68 default:
69 return "N/A";
ca97b838
BZ
70 }
71}
72
ca97b838
BZ
73/*
74 ==========================================================================
75 Description:
76 Set Country Region to pAd->CommonCfg.CountryRegion.
77 This command will not work, if the field of CountryRegion in eeprom is programmed.
78
79 Return:
80 TRUE if all parameters are OK, FALSE otherwise
81 ==========================================================================
82*/
96b3c83d 83INT RT_CfgSetCountryRegion(IN PRTMP_ADAPTER pAd, IN PSTRING arg, IN INT band)
ca97b838
BZ
84{
85 LONG region, regionMax;
86 UCHAR *pCountryRegion;
87
88 region = simple_strtol(arg, 0, 10);
89
96b3c83d 90 if (band == BAND_24G) {
ca97b838
BZ
91 pCountryRegion = &pAd->CommonCfg.CountryRegion;
92 regionMax = REGION_MAXIMUM_BG_BAND;
96b3c83d 93 } else {
ca97b838
BZ
94 pCountryRegion = &pAd->CommonCfg.CountryRegionForABand;
95 regionMax = REGION_MAXIMUM_A_BAND;
96 }
97
98 // TODO: Is it neccesay for following check???
99 // Country can be set only when EEPROM not programmed
96b3c83d
BZ
100 if (*pCountryRegion & 0x80) {
101 DBGPRINT(RT_DEBUG_ERROR,
102 ("CfgSetCountryRegion():CountryRegion in eeprom was programmed\n"));
ca97b838
BZ
103 return FALSE;
104 }
105
96b3c83d 106 if ((region >= 0) && (region <= REGION_MAXIMUM_BG_BAND)) {
ca97b838 107 *pCountryRegion = (UCHAR) region;
96b3c83d
BZ
108 } else if ((region == REGION_31_BG_BAND) && (band == BAND_24G)) {
109 *pCountryRegion = (UCHAR) region;
110 } else {
111 DBGPRINT(RT_DEBUG_ERROR,
112 ("CfgSetCountryRegion():region(%ld) out of range!\n",
113 region));
ca97b838
BZ
114 return FALSE;
115 }
116
117 return TRUE;
118
119}
120
ca97b838
BZ
121/*
122 ==========================================================================
123 Description:
124 Set Wireless Mode
125 Return:
126 TRUE if all parameters are OK, FALSE otherwise
127 ==========================================================================
128*/
96b3c83d 129INT RT_CfgSetWirelessMode(IN PRTMP_ADAPTER pAd, IN PSTRING arg)
ca97b838 130{
96b3c83d
BZ
131 INT MaxPhyMode = PHY_11G;
132 LONG WirelessMode;
ca97b838
BZ
133
134 MaxPhyMode = PHY_11N_5G;
135
136 WirelessMode = simple_strtol(arg, 0, 10);
96b3c83d 137 if (WirelessMode <= MaxPhyMode) {
ca97b838
BZ
138 pAd->CommonCfg.PhyMode = WirelessMode;
139 return TRUE;
140 }
141
142 return FALSE;
143
144}
145
96b3c83d 146INT RT_CfgSetShortSlot(IN PRTMP_ADAPTER pAd, IN PSTRING arg)
ca97b838
BZ
147{
148 LONG ShortSlot;
149
150 ShortSlot = simple_strtol(arg, 0, 10);
151
152 if (ShortSlot == 1)
153 pAd->CommonCfg.bUseShortSlotTime = TRUE;
154 else if (ShortSlot == 0)
155 pAd->CommonCfg.bUseShortSlotTime = FALSE;
156 else
96b3c83d 157 return FALSE; //Invalid argument
ca97b838
BZ
158
159 return TRUE;
160}
161
ca97b838
BZ
162/*
163 ==========================================================================
164 Description:
165 Set WEP KEY base on KeyIdx
166 Return:
167 TRUE if all parameters are OK, FALSE otherwise
168 ==========================================================================
169*/
96b3c83d
BZ
170INT RT_CfgSetWepKey(IN PRTMP_ADAPTER pAd,
171 IN PSTRING keyString,
172 IN CIPHER_KEY * pSharedKey, IN INT keyIdx)
ca97b838 173{
96b3c83d
BZ
174 INT KeyLen;
175 INT i;
176 UCHAR CipherAlg = CIPHER_NONE;
177 BOOLEAN bKeyIsHex = FALSE;
ca97b838
BZ
178
179 // TODO: Shall we do memset for the original key info??
180 memset(pSharedKey, 0, sizeof(CIPHER_KEY));
181 KeyLen = strlen(keyString);
96b3c83d
BZ
182 switch (KeyLen) {
183 case 5: //wep 40 Ascii type
184 case 13: //wep 104 Ascii type
185 bKeyIsHex = FALSE;
186 pSharedKey->KeyLen = KeyLen;
187 NdisMoveMemory(pSharedKey->Key, keyString, KeyLen);
188 break;
189
190 case 10: //wep 40 Hex type
191 case 26: //wep 104 Hex type
192 for (i = 0; i < KeyLen; i++) {
193 if (!isxdigit(*(keyString + i)))
194 return FALSE; //Not Hex value;
195 }
196 bKeyIsHex = TRUE;
197 pSharedKey->KeyLen = KeyLen / 2;
198 AtoH(keyString, pSharedKey->Key, pSharedKey->KeyLen);
199 break;
200
201 default: //Invalid argument
202 DBGPRINT(RT_DEBUG_TRACE,
203 ("RT_CfgSetWepKey(keyIdx=%d):Invalid argument (arg=%s)\n",
204 keyIdx, keyString));
205 return FALSE;
ca97b838
BZ
206 }
207
208 pSharedKey->CipherAlg = ((KeyLen % 5) ? CIPHER_WEP128 : CIPHER_WEP64);
96b3c83d
BZ
209 DBGPRINT(RT_DEBUG_TRACE,
210 ("RT_CfgSetWepKey:(KeyIdx=%d,type=%s, Alg=%s)\n", keyIdx,
211 (bKeyIsHex == FALSE ? "Ascii" : "Hex"),
212 CipherName[CipherAlg]));
ca97b838
BZ
213
214 return TRUE;
215}
216
ca97b838
BZ
217/*
218 ==========================================================================
219 Description:
220 Set WPA PSK key
221
222 Arguments:
223 pAdapter Pointer to our adapter
224 keyString WPA pre-shared key string
225 pHashStr String used for password hash function
226 hashStrLen Lenght of the hash string
227 pPMKBuf Output buffer of WPAPSK key
228
229 Return:
230 TRUE if all parameters are OK, FALSE otherwise
231 ==========================================================================
232*/
96b3c83d
BZ
233INT RT_CfgSetWPAPSKKey(IN RTMP_ADAPTER * pAd,
234 IN PSTRING keyString,
235 IN UCHAR * pHashStr,
236 IN INT hashStrLen, OUT PUCHAR pPMKBuf)
ca97b838
BZ
237{
238 int keyLen;
239 UCHAR keyMaterial[40];
240
241 keyLen = strlen(keyString);
96b3c83d
BZ
242 if ((keyLen < 8) || (keyLen > 64)) {
243 DBGPRINT(RT_DEBUG_TRACE,
244 ("WPAPSK Key length(%d) error, required 8 ~ 64 characters!(keyStr=%s)\n",
245 keyLen, keyString));
ca97b838
BZ
246 return FALSE;
247 }
248
249 memset(pPMKBuf, 0, 32);
96b3c83d
BZ
250 if (keyLen == 64) {
251 AtoH(keyString, pPMKBuf, 32);
252 } else {
253 PasswordHash(keyString, pHashStr, hashStrLen, keyMaterial);
254 NdisMoveMemory(pPMKBuf, keyMaterial, 32);
ca97b838
BZ
255 }
256
257 return TRUE;
258}