⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtusb_init.c

📁 台湾RALink公司的 rt2570无线 802.11g 网卡的 驱动的源代码 ,支持linux2.4以上的 内河
💻 C
📖 第 1 页 / 共 5 页
字号:
/*
 ***************************************************************************
 * Ralink Tech Inc.
 * 4F, No. 2 Technology 5th Rd.
 * Science-based Industrial Park
 * Hsin-chu, Taiwan, R.O.C.
 *
 * (c) Copyright 2002-2004, Ralink Technology, Inc.
 *
 * This program is free software; you can redistribute it and/or modify  * 
 * it under the terms of the GNU General Public License as published by  * 
 * the Free Software Foundation; either version 2 of the License, or     * 
 * (at your option) any later version.                                   * 
 *                                                                       * 
 * This program is distributed in the hope that it will be useful,       * 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of        * 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * 
 * GNU General Public License for more details.                          * 
 *                                                                       * 
 * You should have received a copy of the GNU General Public License     * 
 * along with this program; if not, write to the                         * 
 * Free Software Foundation, Inc.,                                       * 
 * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * 
 *                                                                       * 
 ************************************************************************
	Module Name:
	rtusb_init.c

	Abstract:

	Revision History:
	Who			When			What
	--------	----------		----------------------------------------------
	Name		Date			Modification logs
	Jan Lee		2005-06-01		Release
*/
#include	"rt_config.h"

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
#define RT2570_USB_ALLOC_URB(iso)	usb_alloc_urb(iso, GFP_ATOMIC);	
#else
#define RT2570_USB_ALLOC_URB(iso)	usb_alloc_urb(iso);
#endif

USHORT	 BBPRegTable[] = {
	0x0302,  // R03
	0x0419,  // R04
	0x0E1C,  // R14
	0x0F30,  // R15
	0x10ac,  // R16
	0x1148,  // R17
	0x1218,  // R18
	0x13ff,  // R19
	0x141E,  // R20
	0x1508,  // R21
	0x1608,  // R22
	0x1708,  // R23
//modified by david    0x1870,	// R24
	0x1880,  // R24	modified by david
//modified by gary	  0x1940,  // R25
	0x1950,  // R25	//modified by gary
	0x1A08,  // R26
	0x1B23,  // R27
	0x1E10,  // R30
	0x1F2B,  // R31
	0x20B9,  // R32
	0x2212,  // R34
	0x2350,  // R35
	0x27c4,  // R39
	0x2802,  // R40
	0x2960,  // R41
	0x3510,  // R53
	0x3618,  // R54
	0x3808,  // R56
	0x3910,  // R57
	0x3A08,  // R58
	0x3D60,  // R61
	0x3E10,  // R62
	0x4BFF,  // R75//by MAX
};
#define	NUM_BBP_REG_PARMS	(sizeof(BBPRegTable) / sizeof(USHORT))
VOID RTMPReadParametersFromFile(PRT2570ADAPTER pAd)
{
#if 0
	UCHAR					src[70];
	struct file				*srcf;
	INT 						retval, orgfsuid, orgfsgid;
	mm_segment_t			orgfs;
	CHAR									buffer[MAX_INI_BUFFER_SIZE];
	CHAR									tmpbuf[255];	
	UCHAR									Channel;
	ULONG									ulInfo;
	RT_802_11_PREAMBLE						Preamble;
	int 									KeyLen;
	int 									i;
	BOOLEAN 								bIsHex = TRUE;
	UCHAR									keyMaterial[40];	
	ULONG		rate_mapping[12] = {1, 2, 5, 11, 6, 9, 12, 18, 24, 36, 48, 54}; //according to README
	// Save uid and gid used for filesystem access.
	// Set user and group to 0 (root)	
	memset(src, 0, sizeof(src));
	memcpy(src, PROFILE_PATH, sizeof(PROFILE_PATH));
	DBGPRINT(RT_DEBUG_TEMP, "--> Read %s \n", src);
	orgfsuid = current->fsuid;
	DBGPRINT(RT_DEBUG_TEMP, "1. orgfsuid = %x\n",orgfsuid);
	orgfsgid = current->fsgid;
	DBGPRINT(RT_DEBUG_TEMP, "2. %x\n",orgfsgid);
	current->fsuid= 0;
	current->fsgid = 0;
	orgfs = get_fs();
	DBGPRINT(RT_DEBUG_TEMP, "4. read_orgfs=0x%x\n",orgfs);
	set_fs(KERNEL_DS);
	if (src && *src) 
	{
		DBGPRINT(RT_DEBUG_TRACE, "--> Read %s \n", src);
		srcf = filp_open(src, O_RDONLY , 0);
		if (IS_ERR(srcf)) 
		{
			DBGPRINT(RT_DEBUG_TRACE, "--> Error %ld opening %s\n", -PTR_ERR(srcf),src);    
		}
		else 
		{
			/* The object must have a read method */
			if (srcf->f_op && srcf->f_op->read) 
			{
				retval=srcf->f_op->read(srcf, buffer, MAX_INI_BUFFER_SIZE, &srcf->f_pos);
				if (retval < 0)
				{
					DBGPRINT(RT_DEBUG_TEMP, "--> Read %s error %d\n", src, -retval);
				}
				else
				{
					//CountryRegion
					if (RTMPGetKeyParameter("Default", "CountryRegion", tmpbuf, 255, buffer))
					{
						ulInfo = simple_strtol(tmpbuf, 0, 10);
						if ((ulInfo >= REGION_MIN) && (ulInfo <= REGION_MAX) )
						{
							pAd->PortCfg.CountryRegion = (UCHAR) ulInfo;
							DBGPRINT(RT_DEBUG_TRACE, "%s::(CountryRegion=%d)\n", __FUNCTION__, pAd->PortCfg.CountryRegion);
						}
					}
					//SSID
					memset(tmpbuf, 0x00, 255);
					if (RTMPGetKeyParameter("Default", "SSID", pAd->PortCfg.Ssid, 32, buffer))
					{
						pAd->PortCfg.SsidLen = strlen(pAd->PortCfg.Ssid);
						pAd->Mlme.CntlAux.SsidLen = pAd->PortCfg.SsidLen;
						memcpy(pAd->Mlme.CntlAux.Ssid, pAd->PortCfg.Ssid, pAd->Mlme.CntlAux.SsidLen);

						DBGPRINT(RT_DEBUG_TRACE, "%s::(SSID=%s Len=%d)\n", __FUNCTION__, pAd->PortCfg.Ssid, pAd->PortCfg.SsidLen);
					}
					 //NetworkType
					if (RTMPGetKeyParameter("Default", "NetworkType", tmpbuf, 255, buffer))
					{
						pAd->bConfigChanged = TRUE;
						if (strcmp(tmpbuf, "Adhoc") == 0)
							pAd->PortCfg.BssType = BSS_INDEP;
						else //Default Infrastructure mode
							pAd->PortCfg.BssType = BSS_INFRA;
						// Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
						pAd->PortCfg.WpaState = SS_NOTUSE;
						DBGPRINT(RT_DEBUG_TEMP, "%s::(NetworkType=%d)\n", __FUNCTION__, pAd->PortCfg.BssType);
					}
					//WirelessMode
					if (RTMPGetKeyParameter("Default", "WirelessMode", tmpbuf, 10, buffer))
					{
						ulInfo = simple_strtol(tmpbuf, 0, 10);
						if ((ulInfo == PHY_11BG_MIXED) || (ulInfo == PHY_11B) ||
							(ulInfo == PHY_11A) || (ulInfo == PHY_11ABG_MIXED))
						{
							RTMPSetPhyMode(pAd, ulInfo);
							DBGPRINT(RT_DEBUG_TEMP, "%s::(WirelessMode=%d)\n", __FUNCTION__, ulInfo);
						}
					}
					//TxRate
					if (RTMPGetKeyParameter("Default", "TxRate", tmpbuf, 10, buffer))
					{
						ulInfo = simple_strtol(tmpbuf, 0, 10);
						{
							if (ulInfo == 0)
								RT2570SetDesiredRates(pAd, -1);
							else if (ulInfo < 13){
					RT2570SetDesiredRates(pAd, (LONG) (rate_mapping[ulInfo-1] * 1000000));
							DBGPRINT(RT_DEBUG_TEMP, "1. %s::(TxRate=%d Mbps %d)\n", __FUNCTION__, rate_mapping[ulInfo-1],ulInfo);
								}
							DBGPRINT(RT_DEBUG_TEMP, "3. %s::(TxRate=%d Mbps %d)\n", __FUNCTION__, rate_mapping[ulInfo-1],ulInfo);
						}
					}
					//Channel
					if (RTMPGetKeyParameter("Default", "Channel", tmpbuf, 10, buffer))
					{
						Channel = (UCHAR) simple_strtol(tmpbuf, 0, 10);
						if (ChannelSanity(pAd, Channel) == TRUE)
						{
							pAd->PortCfg.Channel = Channel;
							// If default profile in Registry is an ADHOC network, driver should use the specified channel 
							// number when starting IBSS the first time, because RaConfig is passive and will not set this
							// via OID_802_11_CONFIGURATION upon driver bootup.
							pAd->PortCfg.IbssConfig.Channel = pAd->PortCfg.Channel;
							DBGPRINT(RT_DEBUG_TEMP, "%s::(Channel=%d)\n", __FUNCTION__, Channel);
						}
					}
					//BGProtection
					if (RTMPGetKeyParameter("Default", "BGProtection", tmpbuf, 10, buffer))
					{
						switch (simple_strtol(tmpbuf, 0, 10))
						{
							case 1: //Always On
								pAd->PortCfg.UseBGProtection = 1;
								break;
							case 2: //Always OFF
								pAd->PortCfg.UseBGProtection = 2;
								break;
							case 0: //AUTO
							default:
								pAd->PortCfg.UseBGProtection = 0;
								break;
						}
								pAd->PortCfg.UseBGProtection = 2;
						DBGPRINT(RT_DEBUG_TEMP, "%s::(BGProtection=%d)\n", __FUNCTION__, pAd->PortCfg.UseBGProtection);
					}
					//TxPreamble
					if (RTMPGetKeyParameter("Default", "TxPreamble", tmpbuf, 10, buffer))
					{
						Preamble = simple_strtol(tmpbuf, 0, 10);
						switch (Preamble)
						{
							case Rt802_11PreambleShort:
								pAd->PortCfg.WindowsTxPreamble = Preamble;
								MlmeSetTxPreamble(pAd, Rt802_11PreambleShort);
								break;
							case Rt802_11PreambleLong:
							case Rt802_11PreambleAuto:
							default:
								// if user wants AUTO, initialize to LONG here, then change according to AP's
								// capability upon association.
								pAd->PortCfg.WindowsTxPreamble = Preamble;
								MlmeSetTxPreamble(pAd, Rt802_11PreambleLong);
						}
						DBGPRINT(RT_DEBUG_TEMP, "%s::(TxPreamble=%d)\n", __FUNCTION__, Preamble);
					}
					//RTSThreshold
					if (RTMPGetKeyParameter("Default", "RTSThreshold", tmpbuf, 10, buffer))
					{
						ulInfo = simple_strtol(tmpbuf, 0, 10);

						if((ulInfo > 0) && (ulInfo <= MAX_RTS_THRESHOLD))
							pAd->PortCfg.RtsThreshold = (USHORT)ulInfo;
						else 
							pAd->PortCfg.RtsThreshold = MAX_RTS_THRESHOLD;

						DBGPRINT(RT_DEBUG_TEMP, "%s::(RTSThreshold=%d)\n", __FUNCTION__, pAd->PortCfg.RtsThreshold);
					}
					//FragThreshold
					if (RTMPGetKeyParameter("Default", "FragThreshold", tmpbuf, 10, buffer))
					{
						ulInfo = simple_strtol(tmpbuf, 0, 10);

						if ( (ulInfo >= MIN_FRAG_THRESHOLD) && (ulInfo <= MAX_FRAG_THRESHOLD))
							pAd->PortCfg.FragmentThreshold = (USHORT)ulInfo;
						else
							pAd->PortCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;

						if (pAd->PortCfg.FragmentThreshold == MAX_FRAG_THRESHOLD)
							pAd->PortCfg.bFragmentZeroDisable = TRUE;
						else
							pAd->PortCfg.bFragmentZeroDisable = FALSE;

						DBGPRINT(RT_DEBUG_TEMP, "%s::(FragThreshold=%d)\n", __FUNCTION__, ulInfo);
					}
					//TxBurst
					if (RTMPGetKeyParameter("Default", "TxBurst", tmpbuf, 10, buffer))
					{
						ulInfo = simple_strtol(tmpbuf, 0, 10);

						if (ulInfo == 1)
							pAd->PortCfg.EnableTxBurst = TRUE;
						else
							pAd->PortCfg.EnableTxBurst = FALSE;

						DBGPRINT(RT_DEBUG_TEMP, "%s::(TxBurst=%d)\n", __FUNCTION__, pAd->PortCfg.EnableTxBurst);
					}
					//TurboRate
					if (RTMPGetKeyParameter("Default", "TurboRate", tmpbuf, 10, buffer))
					{
						ulInfo = simple_strtol(tmpbuf, 0, 10);

						if (ulInfo == 1)
							pAd->PortCfg.EnableTurboRate = TRUE;
						else
							pAd->PortCfg.EnableTurboRate = FALSE;

						DBGPRINT(RT_DEBUG_TEMP, "%s::(TurboRate=%d)\n", __FUNCTION__, pAd->PortCfg.EnableTurboRate);
					}
					//ShortSlot
					if (RTMPGetKeyParameter("Default", "ShortSlot", tmpbuf, 10, buffer))
					{
						ulInfo = simple_strtol(tmpbuf, 0, 10);

						if (ulInfo == 1)
							pAd->PortCfg.UseShortSlotTime = TRUE;
						else
							pAd->PortCfg.UseShortSlotTime = FALSE;

						DBGPRINT(RT_DEBUG_TEMP, "%s::(ShortSlot=%d)\n", __FUNCTION__, pAd->PortCfg.UseShortSlotTime);
					}
					//POWER_MODE
					if (RTMPGetKeyParameter("Default", "PSMode", tmpbuf, 10, buffer))
					{
						if (pAd->PortCfg.BssType == BSS_INFRA)
						{
							if ((strcmp(tmpbuf, "MAX_PSP") == 0) || (strcmp(tmpbuf, "max_psp") == 0))
							{
								// do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
								// to exclude certain situations.
								//	   MlmeSetPsmBit(pAdapter, PWR_SAVE);
									pAd->PortCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
								pAd->PortCfg.RecvDtim = TRUE;  // FALSE;
								pAd->PortCfg.DefaultListenCount = 5;
							}
							else if ((strcmp(tmpbuf, "Fast_PSP") == 0) || (strcmp(tmpbuf, "fast_psp") == 0) 
								|| (strcmp(tmpbuf, "FAST_PSP") == 0))
							{
								// do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
								// to exclude certain situations.
								//	   MlmeSetPsmBit(pAdapter, PWR_SAVE);
								pAd->PortCfg.RecvDtim = TRUE;
									pAd->PortCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
								pAd->PortCfg.DefaultListenCount = 3;
							}
							else
							{ //Default Ndis802_11PowerModeCAM
								// clear PSM bit immediately
								MlmeSetPsmBit(pAd, PWR_ACTIVE);
								pAd->PortCfg.RecvDtim = TRUE;
									pAd->PortCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
							}
							DBGPRINT(RT_DEBUG_TRACE, "%s::(PSMode=%d)\n", __FUNCTION__, pAd->PortCfg.WindowsPowerMode);
						}
					}
					//AuthMode
					if (RTMPGetKeyParameter("Default", "AuthMode", tmpbuf, 10, buffer))
					{
						if ((strcmp(tmpbuf, "SHARED") == 0) || (strcmp(tmpbuf, "shared") == 0)){
							pAd->PortCfg.AuthMode = Ndis802_11AuthModeShared;
						DBGPRINT(RT_DEBUG_INFO, "%s::(AuthMode=shared)\n", __FUNCTION__);
							}
						else if ((strcmp(tmpbuf, "WPAPSK") == 0) || (strcmp(tmpbuf, "wpapsk") == 0))
							pAd->PortCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
						else if ((strcmp(tmpbuf, "WPANONE") == 0) || (strcmp(tmpbuf, "wpanone") == 0))
							pAd->PortCfg.AuthMode = Ndis802_11AuthModeWPANone;
						else{
							pAd->PortCfg.AuthMode = Ndis802_11AuthModeOpen;
						DBGPRINT(RT_DEBUG_INFO, "%s::(AuthMode=open    buf = %s)\n", __FUNCTION__,tmpbuf);
							}

						pAd->PortCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
						DBGPRINT(RT_DEBUG_TEMP, "%s::(AuthMode=%d)\n", __FUNCTION__, pAd->PortCfg.AuthMode);
					}
					//WPAPSK_KEY
					if (RTMPGetKeyParameter("Default", "WPAPSK", tmpbuf, 255, buffer))
					{
						if ((strlen(tmpbuf) >= 8) && (strlen(tmpbuf) <= 64))
						{
							PasswordHash((char *)tmpbuf, pAd->PortCfg.Ssid, pAd->PortCfg.SsidLen, keyMaterial);
							NdisMoveMemory(pAd->PortCfg.PskKey.Key, keyMaterial, 32);
							// Use RaConfig as PSK agent.
							// Start STA supplicant state machine
							pAd->PortCfg.WpaState = SS_START;
							printk("%s WPAPSK Key => \n", __FUNCTION__);
							for (i = 0; i < 32; i++)
							{
								printk("%02x:", pAd->PortCfg.PskKey.Key[i]);
								if (i%16 == 15)
									printk("\n");
							}
							printk("\n");
						}
					}
					//DefaultKeyID
					if (RTMPGetKeyParameter("Default", "DefaultKeyID", tmpbuf, 10, buffer))
					{
						ulInfo = simple_strtol(tmpbuf, 0, 10);
						if((ulInfo >= 1 ) && (ulInfo <= 4))
							pAd->PortCfg.DefaultKeyId = (UCHAR) (ulInfo - 1 );
						else
							pAd->PortCfg.DefaultKeyId = 0;

						DBGPRINT(RT_DEBUG_TEMP, "%s::(DefaultKeyID=%d)\n", __FUNCTION__, pAd->PortCfg.DefaultKeyId);
					}
					//Key1Str
					if (RTMPGetKeyParameter("Default", "Key1Str", tmpbuf, 26, buffer))
					{
						KeyLen = strlen(tmpbuf);
						switch (KeyLen)
						{
							case 0:
								pAd->PortCfg.SharedKey[0].KeyLen = 0;
								break;
							case 5: //wep 40 Ascii type
								pAd->PortCfg.SharedKey[0].KeyLen = KeyLen;
								memcpy(pAd->PortCfg.SharedKey[0].Key, tmpbuf, KeyLen);
								DBGPRINT(RT_DEBUG_TEMP, "%s::(11Key1=%s and type=%s)\n", __FUNCTION__, tmpbuf, "Ascii");
								break;
							case 10: //wep 40 Hex type
								for(i=0; i < KeyLen; i++)
								{
									if( !isxdigit(*(tmpbuf+i)) )
									{
										bIsHex = FALSE;
										break;
									}
								}
								
								if (bIsHex)
								{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -