2 *************************************************************************
4 * 5F., No.36, Taiyuan St., Jhubei City,
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
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. *
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. *
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. *
25 *************************************************************************
31 Ralink WiFi Driver configuration related subroutines
35 --------- ---------- ----------------------------------------------
38 #include "../rt_config.h"
40 char *GetPhyMode(int Mode)
51 case MODE_HTGREENFIELD:
74 ==========================================================================
76 Set Country Region to pAd->CommonCfg.CountryRegion.
77 This command will not work, if the field of CountryRegion in eeprom is programmed.
80 TRUE if all parameters are OK, FALSE otherwise
81 ==========================================================================
83 int RT_CfgSetCountryRegion(struct rt_rtmp_adapter *pAd, char *arg, int band)
85 long region, regionMax;
88 region = simple_strtol(arg, 0, 10);
90 if (band == BAND_24G) {
91 pCountryRegion = &pAd->CommonCfg.CountryRegion;
92 regionMax = REGION_MAXIMUM_BG_BAND;
94 pCountryRegion = &pAd->CommonCfg.CountryRegionForABand;
95 regionMax = REGION_MAXIMUM_A_BAND;
98 /* TODO: Is it neccesay for following check??? */
99 /* Country can be set only when EEPROM not programmed */
100 if (*pCountryRegion & 0x80) {
101 DBGPRINT(RT_DEBUG_ERROR,
102 ("CfgSetCountryRegion():CountryRegion in eeprom was programmed\n"));
106 if ((region >= 0) && (region <= REGION_MAXIMUM_BG_BAND)) {
107 *pCountryRegion = (u8)region;
108 } else if ((region == REGION_31_BG_BAND) && (band == BAND_24G)) {
109 *pCountryRegion = (u8)region;
111 DBGPRINT(RT_DEBUG_ERROR,
112 ("CfgSetCountryRegion():region(%ld) out of range!\n",
122 ==========================================================================
126 TRUE if all parameters are OK, FALSE otherwise
127 ==========================================================================
129 int RT_CfgSetWirelessMode(struct rt_rtmp_adapter *pAd, char *arg)
131 int MaxPhyMode = PHY_11G;
134 MaxPhyMode = PHY_11N_5G;
136 WirelessMode = simple_strtol(arg, 0, 10);
137 if (WirelessMode <= MaxPhyMode) {
138 pAd->CommonCfg.PhyMode = WirelessMode;
146 int RT_CfgSetShortSlot(struct rt_rtmp_adapter *pAd, char *arg)
150 ShortSlot = simple_strtol(arg, 0, 10);
153 pAd->CommonCfg.bUseShortSlotTime = TRUE;
154 else if (ShortSlot == 0)
155 pAd->CommonCfg.bUseShortSlotTime = FALSE;
157 return FALSE; /*Invalid argument */
163 ==========================================================================
165 Set WEP KEY base on KeyIdx
167 TRUE if all parameters are OK, FALSE otherwise
168 ==========================================================================
170 int RT_CfgSetWepKey(struct rt_rtmp_adapter *pAd,
172 struct rt_cipher_key *pSharedKey, int keyIdx)
176 u8 CipherAlg = CIPHER_NONE;
177 BOOLEAN bKeyIsHex = FALSE;
179 /* TODO: Shall we do memset for the original key info?? */
180 memset(pSharedKey, 0, sizeof(struct rt_cipher_key));
181 KeyLen = strlen(keyString);
183 case 5: /*wep 40 Ascii type */
184 case 13: /*wep 104 Ascii type */
186 pSharedKey->KeyLen = KeyLen;
187 NdisMoveMemory(pSharedKey->Key, keyString, KeyLen);
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; */
197 pSharedKey->KeyLen = KeyLen / 2;
198 AtoH(keyString, pSharedKey->Key, pSharedKey->KeyLen);
201 default: /*Invalid argument */
202 DBGPRINT(RT_DEBUG_TRACE,
203 ("RT_CfgSetWepKey(keyIdx=%d):Invalid argument (arg=%s)\n",
208 pSharedKey->CipherAlg = ((KeyLen % 5) ? CIPHER_WEP128 : CIPHER_WEP64);
209 DBGPRINT(RT_DEBUG_TRACE,
210 ("RT_CfgSetWepKey:(KeyIdx=%d,type=%s, Alg=%s)\n", keyIdx,
211 (bKeyIsHex == FALSE ? "Ascii" : "Hex"),
212 CipherName[CipherAlg]));
218 ==========================================================================
223 pAdapter Pointer to our adapter
224 keyString WPA pre-shared key string
225 pHashStr String used for password hash function
226 hashStrLen Length of the hash string
227 pPMKBuf Output buffer of WPAPSK key
230 TRUE if all parameters are OK, FALSE otherwise
231 ==========================================================================
233 int RT_CfgSetWPAPSKKey(struct rt_rtmp_adapter *pAd,
236 int hashStrLen, u8 *pPMKBuf)
241 keyLen = strlen(keyString);
242 if ((keyLen < 8) || (keyLen > 64)) {
243 DBGPRINT(RT_DEBUG_TRACE,
244 ("WPAPSK Key length(%d) error, required 8 ~ 64 characters!(keyStr=%s)\n",
249 memset(pPMKBuf, 0, 32);
251 AtoH(keyString, pPMKBuf, 32);
253 PasswordHash(keyString, pHashStr, hashStrLen, keyMaterial);
254 NdisMoveMemory(pPMKBuf, keyMaterial, 32);