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

📄 rtusb_init.c

📁 台湾RALink公司的 rt2570无线 802.11g 网卡的 驱动的源代码 ,支持linux2.4以上的 内河
💻 C
📖 第 1 页 / 共 5 页
字号:
									pAd->PortCfg.SharedKey[0].KeyLen = KeyLen / 2 ;
									AtoH(tmpbuf, pAd->PortCfg.SharedKey[0].Key, KeyLen / 2);
									DBGPRINT(RT_DEBUG_TEMP, "%s::(Key1=%s and type=%s)\n", __FUNCTION__, tmpbuf, "Hex");
								}
								break;
							case 13: //wep 104 Ascii type
								pAd->PortCfg.SharedKey[0].KeyLen = KeyLen;
								memcpy(pAd->PortCfg.SharedKey[0].Key, tmpbuf, KeyLen);	
								DBGPRINT(RT_DEBUG_TEMP, "%s::(Key1=%s and type=%s)\n", __FUNCTION__, tmpbuf, "Ascii");
								break;
							case 26: //wep 104 Hex type
								for(i=0; i < KeyLen; i++)
								{
									if( !isxdigit(*(tmpbuf+i)) )
									{
										bIsHex = FALSE;
										break;
									}
								}

								if (bIsHex)
								{
									pAd->PortCfg.SharedKey[0].KeyLen = KeyLen / 2 ;
									AtoH(tmpbuf, pAd->PortCfg.SharedKey[0].Key, KeyLen / 2);
									DBGPRINT(RT_DEBUG_TEMP, "%s::(Key1=%s and type=%s)\n", __FUNCTION__, tmpbuf, "Hex");
								}
								break;
							default:
								pAd->PortCfg.SharedKey[0].KeyLen = 0;
								DBGPRINT(RT_DEBUG_TRACE, "%s::Invalid Key (=%s)\n", __FUNCTION__, tmpbuf);
						}
						DBGPRINT(RT_DEBUG_TRACE,"!!!!!!!!!!!!!!!!!\n");
					   RTUSBMultiWrite(pAd, (USHORT)(SEC_CSR0 + 0 * 0x10), pAd->PortCfg.SharedKey[0].Key, 16);	
						DBGPRINT(RT_DEBUG_TRACE,"!!!!!!!!!!!!!!!!!\n");
				   }
					//Key2Str
					if (RTMPGetKeyParameter("Default", "Key2Str", tmpbuf, 26, buffer))
					{
						KeyLen = strlen(tmpbuf);
						switch (KeyLen)
						{
							case 0:
								pAd->PortCfg.SharedKey[1].KeyLen = 0;
								break;
							case 5: //wep 40 Ascii type
								pAd->PortCfg.SharedKey[1].KeyLen = KeyLen;
								memcpy(pAd->PortCfg.SharedKey[1].Key, tmpbuf, KeyLen);
								DBGPRINT(RT_DEBUG_TRACE, "%s::(Key2=%s and type=%s)\n", __FUNCTION__, tmpbuf, "Ascii");
							case 10: //wep 40 Hex type
								for(i=0; i < KeyLen; i++)
								{
									if( !isxdigit(*(tmpbuf+i)) )
									{
										bIsHex = FALSE;
										break;
									}
								}
								
								if (bIsHex)
								{
									pAd->PortCfg.SharedKey[1].KeyLen = KeyLen / 2 ;
									AtoH(tmpbuf, pAd->PortCfg.SharedKey[1].Key, KeyLen / 2);
									DBGPRINT(RT_DEBUG_TRACE, "%s::(Key2=%s and type=%s)\n", __FUNCTION__, tmpbuf, "Hex");
								}
								break;
							case 13: //wep 104 Ascii type
								pAd->PortCfg.SharedKey[1].KeyLen = KeyLen;
								memcpy(pAd->PortCfg.SharedKey[1].Key, tmpbuf, KeyLen);	
								DBGPRINT(RT_DEBUG_TRACE, "%s::(Key2=%s and type=%s)\n", __FUNCTION__, tmpbuf, "Ascii");
								break;
							case 26: //wep 104 Hex type
								for(i=0; i < KeyLen; i++)
								{
									if( !isxdigit(*(tmpbuf+i)) )
									{
										bIsHex = FALSE;
										break;
									}
								}

								if (bIsHex)
								{
									pAd->PortCfg.SharedKey[1].KeyLen = KeyLen / 2 ;
									AtoH(tmpbuf, pAd->PortCfg.SharedKey[1].Key, KeyLen / 2);
									DBGPRINT(RT_DEBUG_TRACE, "%s::(Key2=%s and type=%s)\n", __FUNCTION__, tmpbuf, "Hex");
								}
								break;
							default:
								pAd->PortCfg.SharedKey[1].KeyLen = 0;
								DBGPRINT(RT_DEBUG_TRACE, "%s::Invalid argument (=%s)\n", __FUNCTION__, tmpbuf);
						}
						RTUSBMultiWrite(pAd, (USHORT)(SEC_CSR0 + 1 * 0x10), pAd->PortCfg.SharedKey[1].Key, 16);	
					}
					//Key3Str
					if (RTMPGetKeyParameter("Default", "Key3Str", tmpbuf, 26, buffer))
					{
						KeyLen = strlen(tmpbuf);
						switch (KeyLen)
						{
							case 0:
								pAd->PortCfg.SharedKey[2].KeyLen = 0;
								break;
							case 5: //wep 40 Ascii type
								pAd->PortCfg.SharedKey[2].KeyLen = KeyLen;
								memcpy(pAd->PortCfg.SharedKey[2].Key, tmpbuf, KeyLen);
								DBGPRINT(RT_DEBUG_TRACE, "%s::(Key3=%s and type=%s)\n", __FUNCTION__, tmpbuf, "Ascii");
							case 10: //wep 40 Hex type
								for(i=0; i < KeyLen; i++)
								{
									if( !isxdigit(*(tmpbuf+i)) )
									{
										bIsHex = FALSE;
										break;
									}
								}

								if (bIsHex)
								{
									pAd->PortCfg.SharedKey[2].KeyLen = KeyLen / 2 ;
									AtoH(tmpbuf, pAd->PortCfg.SharedKey[2].Key, KeyLen / 2);
									DBGPRINT(RT_DEBUG_INFO, "%s::(Key3=%s and type=%s)\n", __FUNCTION__, tmpbuf, "Hex");
								}
								break;
							case 13: //wep 104 Ascii type
								pAd->PortCfg.SharedKey[2].KeyLen = KeyLen;
								memcpy(pAd->PortCfg.SharedKey[2].Key, tmpbuf, KeyLen);	
								DBGPRINT(RT_DEBUG_TRACE, "%s::(Key3=%s and type=%s)\n", __FUNCTION__, tmpbuf, "Ascii");
								break;
							case 26: //wep 104 Hex type
								for(i=0; i < KeyLen; i++)
								{
									if( !isxdigit(*(tmpbuf+i)) )
									{
										bIsHex = FALSE;
										break;
									}
								}

								if (bIsHex)
								{
									pAd->PortCfg.SharedKey[2].KeyLen = KeyLen / 2 ;
									AtoH(tmpbuf, pAd->PortCfg.SharedKey[2].Key, KeyLen / 2);
									DBGPRINT(RT_DEBUG_TRACE, "%s::(Key3=%s and type=%s)\n", __FUNCTION__, tmpbuf, "Hex");
								}
								break;
							default:
								pAd->PortCfg.SharedKey[2].KeyLen = 0;
								DBGPRINT(RT_DEBUG_INFO, "%s::Invalid argument (=%s)\n", __FUNCTION__, tmpbuf);
						}
						RTUSBMultiWrite(pAd, (USHORT)(SEC_CSR0 + 2 * 0x10), pAd->PortCfg.SharedKey[2].Key, 16);	
					}
					//Key4Str
					if (RTMPGetKeyParameter("Default", "Key4Str", tmpbuf, 26, buffer))
					{
						KeyLen = strlen(tmpbuf);
						switch (KeyLen)
						{
							case 0:
								pAd->PortCfg.SharedKey[3].KeyLen = 0;
								break;
							case 5: //wep 40 Ascii type
								pAd->PortCfg.SharedKey[3].KeyLen = KeyLen;
								memcpy(pAd->PortCfg.SharedKey[3].Key, tmpbuf, KeyLen);
								DBGPRINT(RT_DEBUG_TRACE, "%s::(Key4=%s and type=%s)\n", __FUNCTION__, tmpbuf, "Ascii");
							case 10: //wep 40 Hex type
								for(i=0; i < KeyLen; i++)
								{
									if( !isxdigit(*(tmpbuf+i)) )
									{
										bIsHex = FALSE;
										break;
									}
								}

								if (bIsHex)
								{
									pAd->PortCfg.SharedKey[3].KeyLen = KeyLen / 2 ;
									AtoH(tmpbuf, pAd->PortCfg.SharedKey[3].Key, KeyLen / 2);
									DBGPRINT(RT_DEBUG_TRACE, "%s::(Key4=%s and type=%s)\n", __FUNCTION__, tmpbuf, "Hex");
								}
								break;
							case 13: //wep 104 Ascii type
								pAd->PortCfg.SharedKey[3].KeyLen = KeyLen;
								memcpy(pAd->PortCfg.SharedKey[3].Key, tmpbuf, KeyLen);	
								DBGPRINT(RT_DEBUG_TRACE, "%s::(Key4=%s and type=%s)\n", __FUNCTION__, tmpbuf, "Ascii");
								break;
							case 26: //wep 104 Hex type
								for(i=0; i < KeyLen; i++)
								{
									if( !isxdigit(*(tmpbuf+i)) )
									{
										bIsHex = FALSE;
										break;
									}
								}

								if (bIsHex)
								{
									pAd->PortCfg.SharedKey[3].KeyLen = KeyLen / 2 ;
									AtoH(tmpbuf, pAd->PortCfg.SharedKey[3].Key, KeyLen / 2);
									DBGPRINT(RT_DEBUG_TRACE, "%s::(Key4=%s and type=%s)\n", __FUNCTION__, tmpbuf, "Hex");
								}
								break;
							default:
								pAd->PortCfg.SharedKey[3].KeyLen = 0;
								DBGPRINT(RT_DEBUG_TRACE, "%s::Invalid argument (=%s)\n", __FUNCTION__, tmpbuf);
						}
						RTUSBMultiWrite(pAd, (USHORT)(SEC_CSR0 + 3 * 0x10), pAd->PortCfg.SharedKey[3].Key, 16);	
					}
					//EncrypType
					if (RTMPGetKeyParameter("Default", "EncrypType", tmpbuf, 10, buffer))
					{
						Set_EncrypType_Proc(pAd,(PUCHAR)tmpbuf);
						DBGPRINT(RT_DEBUG_TEMP, "%s::(EncrypType=%d)\n", __FUNCTION__, pAd->PortCfg.WepStatus);

					}
				}
			}
			else
			{
				DBGPRINT(RT_DEBUG_TRACE, "--> %s does not have a write method\n", src);
			}
			
			retval=filp_close(srcf,NULL);
			
			if (retval)
			{
				DBGPRINT(RT_DEBUG_TRACE, "--> Error %d closing %s\n", -retval, src);
			}
		}
	}
	
	set_fs(orgfs);
	current->fsuid = orgfsuid;
	current->fsgid = orgfsgid;
#endif	
}


/*
	========================================================================
	
	Routine Description:
		Read additional information from EEPROM, such as MAC address

	Arguments:
		Adapter						Pointer to our adapter

	Return Value:
		NDIS_STATUS_SUCCESS
		NDIS_STATUS_FAILURE

	Note:
	
	========================================================================
*/
NDIS_STATUS	RTUSBWriteHWMACAddress(
	IN	PRT2570ADAPTER		pAdapter)
{
	MAC_CSR2_STRUC		StaMacReg0;
	MAC_CSR3_STRUC		StaMacReg1;
	MAC_CSR4_STRUC		StaMacReg2;
	NDIS_STATUS		Status = NDIS_STATUS_SUCCESS;

	StaMacReg0.field.Byte0 = pAdapter->CurrentAddress[0];
	StaMacReg0.field.Byte1 = pAdapter->CurrentAddress[1];
	StaMacReg1.field.Byte2 = pAdapter->CurrentAddress[2];
	StaMacReg1.field.Byte3 = pAdapter->CurrentAddress[3];
	StaMacReg2.field.Byte4 = pAdapter->CurrentAddress[4];
	StaMacReg2.field.Byte5 = pAdapter->CurrentAddress[5];

	RTUSBWriteMACRegister(pAdapter, MAC_CSR2, StaMacReg0.value);
	RTUSBWriteMACRegister(pAdapter, MAC_CSR3, StaMacReg1.value);
	RTUSBWriteMACRegister(pAdapter, MAC_CSR4, StaMacReg2.value);
	return Status;
}

/*
	========================================================================
	
	Routine Description:
		Read initial parameters from EEPROM
		
	Arguments:
		Adapter						Pointer to our adapter

	Return Value:
		None

	Note:
		
	========================================================================
*/
VOID	NICReadEEPROMParameters(
	IN	PRT2570ADAPTER	pAdapter)
{
	USHORT			i;
	int			value;
	UCHAR			TmpPhy;
	EEPROM_TX_PWR_STRUC	Power;
	EEPROM_ANTENNA_STRUC	Antenna;//blue
//	EEPROM_VERSION_STRUC	Version;
	
	DBGPRINT(RT_DEBUG_TRACE,"--> NICReadEEPROMParameters\n");

	//Read MAC address.
	RTUSBReadEEPROM(pAdapter, EEPROM_MAC_ADDRESS_BASE_OFFSET, pAdapter->PermanentAddress, ETH_LENGTH_OF_ADDRESS);
	DBGPRINT_RAW(RT_DEBUG_TRACE,"MAC address:\n");
	for (i = 0; i < ETH_LENGTH_OF_ADDRESS; i++)
		DBGPRINT_RAW(RT_DEBUG_TRACE,"%02x ", pAdapter->PermanentAddress[i]);
	DBGPRINT_RAW(RT_DEBUG_TRACE,"\n");

	if (pAdapter->PortCfg.bLocalAdminMAC != TRUE)
	{
		pAdapter->CurrentAddress[0] = pAdapter->PermanentAddress[0];
		pAdapter->CurrentAddress[1] = pAdapter->PermanentAddress[1];
		pAdapter->CurrentAddress[2] = pAdapter->PermanentAddress[2];
		pAdapter->CurrentAddress[3] = pAdapter->PermanentAddress[3];
		pAdapter->CurrentAddress[4] = pAdapter->PermanentAddress[4];
		pAdapter->CurrentAddress[5] = pAdapter->PermanentAddress[5];
	}

	// Read BBP default value from EEPROM and store to array(EEPROMDefaultValue) in pAdapter
	RTUSBReadEEPROM(pAdapter, EEPROM_BBP_BASE_OFFSET, (PUCHAR)(pAdapter->EEPROMDefaultValue), 2 * NUM_EEPROM_BBP_PARMS);

	// We have to parse NIC configuration 0 at here.
	// If TSSI did not have preloaded value, it should reset the TxAutoAgc to false
	// Therefore, we have to read TxAutoAgc control beforehand.
	// Read Tx AGC control bit
	Antenna.word = pAdapter->EEPROMDefaultValue[0];
	if (Antenna.field.DynamicTxAgcControl == 1)
		pAdapter->PortCfg.bAutoTxAgc = TRUE;
	else
		pAdapter->PortCfg.bAutoTxAgc = FALSE;		
	

	// Read Tx power value for all 14 channels
	// Value from 1 - 0x7f. Default value is 24.
	RTUSBReadEEPROM(pAdapter, EEPROM_TX_PWR_OFFSET, pAdapter->PortCfg.ChannelTxPower, 2 * NUM_EEPROM_TX_PARMS);
	for (i = 0; i < 2 * NUM_EEPROM_TX_PARMS; i++)
	{
		if (pAdapter->PortCfg.ChannelTxPower[i] > 31)
			pAdapter->PortCfg.ChannelTxPower[i] = 24;
		DBGPRINT(RT_DEBUG_INFO, "Tx power for channel %d : %0x\n", i, pAdapter->PortCfg.ChannelTxPower[i]);
	}

	// Read Tx TSSI reference value, OK to reuse Power data structure
	RTUSBReadEEPROM(pAdapter, EEPROM_TSSI_REF_OFFSET, pAdapter->PortCfg.ChannelTssiRef, 2 * NUM_EEPROM_TX_PARMS);
	for (i = 0; i < 2 * NUM_EEPROM_TX_PARMS; i++)
	{
		if (pAdapter->PortCfg.ChannelTssiRef[i] == 0xff)
			pAdapter->PortCfg.bAutoTxAgc = FALSE;					
		DBGPRINT(RT_DEBUG_INFO, "TSSI reference for channel %d : %0x\n", i, pAdapter->PortCfg.ChannelTssiRef[i]);
	}
	
	// Tx Tssi delta offset 0x24
	RTUSBReadEEPROM(pAdapter, EEPROM_TSSI_DELTA_OFFSET, (PUCHAR)(&(Power.word)), 2);
	pAdapter->PortCfg.ChannelTssiDelta = Power.field.Byte0;
	
	//CountryRegion byte offset = 0x35
	value = pAdapter->EEPROMDefaultValue[2] >> 8;
	DBGPRINT(RT_DEBUG_TRACE,"  CountryRegion= 0x%x \n",value);
	if ((value >= 0) && (value <= 7))
	{
		pAdapter->PortCfg.CountryRegion = (UCHAR) value;
		TmpPhy = pAdapter->PortCfg.PhyMode;
		pAdapter->PortCfg.PhyMode = 0xff;
		RTMPSetPhyMode(pAdapter, TmpPhy);
	}
	else
	{
		// set default country region 
		pAdapter->PortCfg.CountryRegion = 6;
		TmpPhy = pAdapter->PortCfg.PhyMode;
		pAdapter->PortCfg.PhyMode = 0xff;
		RTMPSetPhyMode(pAdapter, TmpPhy);
	}

	RTUSBReadEEPROM(pAdapter, EEPROM_BBP_TUNING_OFFSET, (PUCHAR)(pAdapter->EEPROMBBPTuningParameters), 2 * NUM_EEPROM_BBP_TUNING_PARMS);
	if ((pAdapter->EEPROMBBPTuningParameters[0] != 0xffff) && (pAdapter->EEPROMBBPTuningParameters[0] != 0))
	{
		pAdapter->BBPTuningParameters.BBPTuningThreshold = (UCHAR)((pAdapter->EEPROMBBPTuningParameters[0]) & 0xff);
		DBGPRINT(RT_DEBUG_INFO, "BBPTuningThreshold = %d\n", pAdapter->BBPTuningParameters.BBPTuningThreshold);
	}
	if ((pAdapter->EEPROMBBPTuningParameters[1] != 0xffff) && (pAdapter->EEPROMBBPTuningParameters[1] != 0))
	{
		pAdapter->BBPTuningParameters.R24LowerValue = (UCHAR)(pAdapter->EEPROMBBPTuningParameters[1] & 0xff);
		pAdapter->BBPTuningParameters.R24HigherValue = (UCHAR)((pAdapter->EEPROMBBPTuningParameters[1] & 0xff00) >> 8);
		DBGPRINT(RT_DEBUG_INFO, "R24LowerValue = 0x%x\n", pAdapter->BBPTuningParameters.R24LowerValue);
		DBGPRINT(RT_DEBUG_INFO, "R24HigherValue = 0x%x\n", pAdapter->BBPTuningParameters.R24HigherValue);
	}
	if ((pAdapter->EEPROMBBPTuningParameters[2] != 0xffff) && (pAdapter->EEPROMBBPTuningParameters[2] != 0))
	{
		pAdapter->BBPTuningParameters.R25LowerValue = (UCHAR)(pAdapter->EEPROMBBPTuningParameters[2] & 0xff);
		pAdapter->BBPTuningParameters.R25HigherValue = (UCHAR)((pAdapter->EEPROMBBPTuningParameters[2] & 0xff00) >> 8);
		DBGPRINT(RT_DEBUG_INFO, "R25LowerValue = 0x%x\n", pAdapter->BBPTuningParameters.R25LowerValue);
		DBGPRINT(RT_DEBUG_INFO, "R25HigherValue = 0x%x\n", pAdapter->BBPTuningParameters.R25HigherValue);
	}
	if ((pAdapter->EEPROMBBPTuningParameters[3] != 0xffff) && (pAdapter->EEPROMBBPTuningParameters[3] != 0))
	{
		pAdapter->BBPTuningParameters.R61LowerValue = (UCHAR)(pAdapter->EEPROMBBPTuningParameters[3] & 0xff);
		pAdapter->BBPTuningParameters.R61HigherValue = (UCHAR)((pAdapter->EEPROMBBPTuningParameters[3] & 0xff00) >> 8);
		DBGPRINT(RT_DEBUG_INFO, "R61LowerValue = 0x%x\n", pAdapter->BBPTuningParameters.R61LowerValue);
		DBGPRINT(RT_DEBUG_INFO, "R61HigherValue = 0x%x\n", pAdapter->BBPTuningParameters.R61HigherValue);
	}
	if ((pAdapter->EEPROMBBPTuningParameters[4] != 0xffff) && (pAdapter->EEPROMBBPTuningParameters[4] != 0))
	{
		pAdapter->PortCfg.BbpTuning.VgcUpperBound = (UCHAR)(pAdapter->EEPROMBBPTuningParameters[4] & 0xff);
		DBGPRINT_RAW(RT_DEBUG_INFO, "VgcUpperBound = 0x%x\n", pAdapter->PortCfg.BbpTuning.VgcUpperBound);
	}
	if ((pAdapter->EEPROMBBPTuningParameters[5] != 0xffff) && (pAdapter->EEPROMBBPTuningParameters[5] != 0))
	{
		pAdapter->BBPTuningParameters.BBPR17LowSensitivity = (UCHAR)(pAdapter->EEPROMBBPTuningParameters[5] & 0xff);
		pAdapter->BBPTuningParameters.BBPR17MidSensitivity = (UCHAR)((pAdapter->EEPROMBBPTuningParameters[5] & 0xff00) >> 8);
		DBGPRINT_RAW(RT_DEBUG_INFO, "BBPR17LowSensitivity = 0x%x\n", pAdapter->BBPTuningParameters.BBPR17LowSensitivity);
		DBGPRINT_RAW(RT_DEBUG_INFO, "BBPR17MidSensitivity = 0x%x\n", pAdapter->BBPTuningParameters.BBPR17MidSensitivity);
	}

⌨️ 快捷键说明

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