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

📄 rtusb_init.c

📁 台湾RALink公司的 rt2570无线 802.11g 网卡的 驱动的源代码 ,支持linux2.4以上的 内河
💻 C
📖 第 1 页 / 共 5 页
字号:
out4:	
	if (NULL != pNullContext->pUrb)
	{
		usb_unlink_urb(pNullContext->pUrb);
		usb_free_urb(pNullContext->pUrb);
		pNullContext->pUrb = NULL;
	}
	if (NULL != pNullContext->TransferBuffer)
	{
		FreeMemory(pNullContext->TransferBuffer);
		pNullContext->TransferBuffer = NULL;
	}
out3:	
	// Free beacon frame resource
	for (i = 0; i < BEACON_RING_SIZE; i++)
	{
		PTX_CONTEXT	pBeaconContext = &(pAdapter->BeaconContext[i]);
		if ( NULL != pBeaconContext->pUrb )
		{
			usb_unlink_urb(pBeaconContext->pUrb);
			usb_free_urb(pBeaconContext->pUrb);
			pBeaconContext->pUrb = NULL;
		}
		
		if ( NULL != pBeaconContext->TransferBuffer )
		{
			FreeMemory( pBeaconContext->TransferBuffer);
			pBeaconContext->TransferBuffer = NULL;
		}
	}
out2:	
	for ( i= 0; i < PRIO_RING_SIZE; i++ )
	{
		PTX_CONTEXT pMLMEContext = &(pAdapter->MLMEContext[i]);
		

		if ( NULL != pMLMEContext->pUrb )
		{
			usb_unlink_urb(pMLMEContext->pUrb);
			usb_free_urb(pMLMEContext->pUrb);
			pMLMEContext->pUrb = NULL;
		}
		
		if ( NULL != pMLMEContext->TransferBuffer )
		{
			FreeMemory( pMLMEContext->TransferBuffer);
			pMLMEContext->TransferBuffer = NULL;
		}
	} // for
out1:	
	for ( i= 0; i < TX_RING_SIZE; i++ )
	{
		PTX_CONTEXT pTxContext = &(pAdapter->TxContext[i]);

		if ( NULL != pTxContext->pUrb )
		{
			usb_unlink_urb(pTxContext->pUrb);
			usb_free_urb(pTxContext->pUrb);
			pTxContext->pUrb = NULL;
		}
		if ( NULL != pTxContext->TransferBuffer )
		{
			FreeMemory( pTxContext->TransferBuffer);
			pTxContext->TransferBuffer = NULL;
		}
	} // for
done:	
	DBGPRINT(RT_DEBUG_TRACE,"<-- NICInitTransmit\n");
	return Status;
}

/*
	========================================================================
	
	Routine Description:
		Initialize receive data structures

	Arguments:
		Adapter 					Pointer to our adapter

	Return Value:
		NDIS_STATUS_SUCCESS
		NDIS_STATUS_RESOURCES

	Note:
		Initialize all receive releated private buffer, include those define
		in RTMP_ADAPTER structure and all private data structures. The mahor
		work is to allocate buffer for each packet and chain buffer to 
		NDIS packet descriptor.
		
	========================================================================
*/
NDIS_STATUS NICInitRecv( PRT2570ADAPTER	pAdapter)
{
	UCHAR	i;
	NDIS_STATUS 	Status = NDIS_STATUS_SUCCESS;


	DBGPRINT(RT_DEBUG_TRACE,"--> NICInitRecv\n");
	pAdapter->NextRxBulkInIndex = 0;
	atomic_set( &pAdapter->PendingRx, 0);
	for (i = 0; i < RX_RING_SIZE; i++)
	{
		PRX_CONTEXT  pRxContext = &(pAdapter->RxContext[i]);
		pRxContext->pUrb = RT2570_USB_ALLOC_URB(0);
		if(pRxContext->pUrb == NULL)
		{
			Status = NDIS_STATUS_RESOURCES;
			DBGPRINT(RT_DEBUG_TRACE,"--> pRxContext->pUrb == NULL\n");
			break;
		}
						
		pRxContext->TransferBuffer= (PUCHAR) kmalloc(BUFFER_SIZE, GFP_KERNEL);
		if(!pRxContext->TransferBuffer)
		{
			DBGPRINT(RT_DEBUG_ERROR,"Not enough memory\n");
			Status = NDIS_STATUS_RESOURCES;
			break;
		}	

		NdisZeroMemory(pRxContext->TransferBuffer, BUFFER_SIZE);
		
		pRxContext->pAdapter = pAdapter;
		pRxContext->InUse = FALSE;
	}

	DBGPRINT(RT_DEBUG_TRACE,"<-- NICInitRecv\n");	
	return Status;
}
NDIS_STATUS RT2570InitAdapterBlock(	PRT2570ADAPTER	pAdapter)
{
	NDIS_STATUS 	Status = NDIS_STATUS_SUCCESS;
	UINT			i;
	PCmdQElmt		cmdqelmt;
	
	do
	{
		for (i = 0; i < COMMAND_QUEUE_SIZE; i++)
		{
			cmdqelmt = &(pAdapter->CmdQElements[i]);
			NdisZeroMemory(cmdqelmt, sizeof(CmdQElmt));
			cmdqelmt->buffer = NULL;
			cmdqelmt->CmdFromNdis = FALSE;
			cmdqelmt->InUse = FALSE;
		}
		RTUSBInitializeCmdQ(&pAdapter->CmdQ);

		init_MUTEX(&(pAdapter->usbdev_semaphore));
		init_MUTEX_LOCKED(&(pAdapter->mlme_semaphore));
		init_MUTEX_LOCKED(&(pAdapter->RTUSBCmd_semaphore));
		init_completion (&pAdapter->notify);
		NdisAllocateSpinLock(&pAdapter->CmdQLock);
		NdisAllocateSpinLock(&pAdapter->SendTxWaitQueueLock);
		NdisAllocateSpinLock(&pAdapter->BulkOutLock);
		NdisAllocateSpinLock(&pAdapter->MLMEWaitQueueLock);
		NdisAllocateSpinLock(&pAdapter->MLMEQLock);
	}while(0);

	return Status;
}
////////////////////////////////////////////////////////////////////////////
//
//	FUNCTION
//		ReleaseAdapter
//
//	DESCRIPTION
//		Calls USB_InterfaceStop and frees memory allocated for the URBs
//		calls NdisMDeregisterDevice and frees the memory
//		allocated in VNetInitialize for the Adapter Object
//		
//	INPUT
//		Adapter 	Pointer to RT2570ADAPTER structure
//
//	OUTPUT
//		-
//		
////////////////////////////////////////////////////////////////////////////
VOID ReleaseAdapter(PRT2570ADAPTER pAdapter, BOOLEAN IsF)
{
	UINT	i, IsFree;
	PTX_CONTEXT	pNullContext = &pAdapter->NullContext;
	PTX_CONTEXT	pPsPollContext = &pAdapter->PsPollContext;
	
	IsFree = 1;
	DBGPRINT(RT_DEBUG_TRACE, "==> ReleaseAdapter\n");
	// Free all resources for the RECEIVE buffer queue.
	for (i = 0; i < RX_RING_SIZE; i++)
	{
		PRX_CONTEXT  pRxContext = &(pAdapter->RxContext[i]);

		if (pRxContext->pUrb != NULL)
		{
			usb_unlink_urb(pRxContext->pUrb);
			if (IsFree)
			usb_free_urb(pRxContext->pUrb);
			pRxContext->pUrb = NULL;
		}
		if (pRxContext->TransferBuffer != NULL)
		{
			FreeMemory(pRxContext->TransferBuffer); 
			pRxContext->TransferBuffer = NULL;
		}

	}
#if 0

	if (NULL != pWpaPskContext->pUrb)
	{
		usb_free_urb(pWpaPskContext->pUrb);
		pWpaPskContext->pUrb = NULL;
	}
	if (NULL != pWpaPskContext->TransferBuffer)
	{
		FreeMemory(pWpaPskContext->TransferBuffer);
		pWpaPskContext->TransferBuffer = NULL;
	}
#endif

	if (NULL != pPsPollContext->pUrb)
	{
		usb_unlink_urb(pPsPollContext->pUrb);
		if (IsFree)
		usb_free_urb(pPsPollContext->pUrb);
		pPsPollContext->pUrb = NULL;
	}
	if (NULL != pPsPollContext->TransferBuffer)
	{
		FreeMemory(pPsPollContext->TransferBuffer);
		pPsPollContext->TransferBuffer = NULL;
	}

	if (NULL != pNullContext->pUrb)
	{
		usb_unlink_urb(pNullContext->pUrb);
		if (IsFree)
		usb_free_urb(pNullContext->pUrb);
		pNullContext->pUrb = NULL;
	}
	if (NULL != pNullContext->TransferBuffer)
	{
		FreeMemory(pNullContext->TransferBuffer);
		pNullContext->TransferBuffer = NULL;
	}
	// Free beacon frame resource
	for (i = 0; i < BEACON_RING_SIZE; i++)
	{
		PTX_CONTEXT	pBeaconContext = &(pAdapter->BeaconContext[i]);
		if ( NULL != pBeaconContext->pUrb )
		{
			usb_unlink_urb(pBeaconContext->pUrb);
			if (IsFree)
			usb_free_urb(pBeaconContext->pUrb);
			pBeaconContext->pUrb = NULL;
		}
		
		if ( NULL != pBeaconContext->TransferBuffer )
		{
			FreeMemory( pBeaconContext->TransferBuffer);
			pBeaconContext->TransferBuffer = NULL;
		}
	}
	for ( i= 0; i < PRIO_RING_SIZE; i++ )
	{
		PTX_CONTEXT pMLMEContext = &(pAdapter->MLMEContext[i]);
		

		if ( NULL != pMLMEContext->pUrb )
		{
			usb_unlink_urb(pMLMEContext->pUrb);
			if (IsFree)
			usb_free_urb(pMLMEContext->pUrb);
			pMLMEContext->pUrb = NULL;
		}
		
		if ( NULL != pMLMEContext->TransferBuffer )
		{
			FreeMemory( pMLMEContext->TransferBuffer);
			pMLMEContext->TransferBuffer = NULL;
		}
	} // for
	for ( i= 0; i < TX_RING_SIZE; i++ )
	{
		PTX_CONTEXT pTxContext = &(pAdapter->TxContext[i]);


		if ( NULL != pTxContext->pUrb )
		{
			usb_unlink_urb(pTxContext->pUrb);
			if (IsFree)
			usb_free_urb(pTxContext->pUrb);
			pTxContext->pUrb = NULL;
		}
		
		if ( NULL != pTxContext->TransferBuffer )
		{
			FreeMemory( pTxContext->TransferBuffer);
			pTxContext->TransferBuffer = NULL;
		}
	} // for

	DBGPRINT(RT_DEBUG_TRACE, "<== ReleaseAdapter\n");

}

VOID PortCfgInit(PRT2570ADAPTER pAdapter)
{
	UINT i;
	
	pAdapter->PortCfg.UseBGProtection = 2; // always not use
	pAdapter->PortCfg.CapabilityInfo = 0x0000;
	pAdapter->BulkOutMaxPacketSize = 64;
	//pAdapter->PortCfg.AuthRspTimeout = AUTH_KEY_TIMEOUT;	 // in msec
	pAdapter->PortCfg.Psm = PWR_ACTIVE;
	pAdapter->PortCfg.BeaconPeriod = 100;	  // in mSec
	//	pAdapter->PortCfg.AssocRspTimeout = ASSOC_TIMEOUT;	// in mSec

#if 1
	pAdapter->BBPR17InitValue = 0x32;
#endif
	pAdapter->PortCfg.CfpMaxDuration = 0;	  // never mind, decided by AP later
	pAdapter->PortCfg.CfpDurRemain = 0; 	  // never mind, decided by AP later
	pAdapter->PortCfg.CfpCount = 0; 		  // never mind, decided by AP later
	pAdapter->PortCfg.CfpPeriod = 0;		  // never mind, decided by AP later
	pAdapter->PortCfg.AuthMode = Ndis802_11AuthModeOpen;
	pAdapter->PortCfg.CipherAlg = CIPHER_NONE;
	pAdapter->PortCfg.MlmeRate = RATE_2;
	pAdapter->PortCfg.RtsRate = RATE_2;
	for(i = 0; i < SHARE_KEY_NO; i++)
	{
		pAdapter->PortCfg.SharedKey[i].KeyLen = 0;
	}

	for(i = 0; i < PAIRWISE_KEY_NO; i++) 
	{
		pAdapter->PortCfg.PairwiseKey[i].KeyLen = 0;
	}

	for(i = 0; i < GROUP_KEY_NO; i++) 
	{
		pAdapter->PortCfg.GroupKey[i].KeyLen = 0;
	}
	pAdapter->PortCfg.WepStatus = Ndis802_11EncryptionDisabled;
	pAdapter->PortCfg.OrigWepStatus = Ndis802_11EncryptionDisabled;
	pAdapter->PortCfg.PairCipher = Ndis802_11EncryptionDisabled;
	pAdapter->PortCfg.GroupCipher = Ndis802_11EncryptionDisabled;
	pAdapter->PortCfg.bMixCipher = FALSE;
	pAdapter->PortCfg.DefaultKeyId = 0;
	
	pAdapter->PortCfg.PrivacyFilter = Ndis802_11PrivFilterAcceptAll;

	// 802.1x port control
	pAdapter->PortCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
	pAdapter->PortCfg.LastMicErrorTime = 0;
	pAdapter->PortCfg.MicErrCnt 	   = 0;
	pAdapter->PortCfg.bBlockAssoc	   = FALSE;

	pAdapter->PortCfg.RtsThreshold = 2347;
	pAdapter->PortCfg.FragmentThreshold = 2346;
	pAdapter->PortCfg.bFragmentZeroDisable = FALSE;

	pAdapter->PortCfg.CurrentTxAntenna = 0xff;	// diversity
	pAdapter->PortCfg.CurrentRxAntenna = 0xff;	// diversity
	pAdapter->PortCfg.NumberOfAntenna = 2;

//	pAdapter->PortCfg.TxPowerLevel[0] = 100;
//	pAdapter->PortCfg.NumOfTxPowerLevel = 1;
	pAdapter->PortCfg.TxPower = 100; //mW
	pAdapter->PortCfg.TxPowerPercentage = 0xffffffff; // AUTO

	pAdapter->PortCfg.AntennaSupportTx = TRUE;
	pAdapter->PortCfg.AntennaSupportRx = TRUE;
	pAdapter->PortCfg.AntennaSupportDiversityRx = TRUE;

	pAdapter->PortCfg.RecvDtim = TRUE;
	NdisZeroMemory(&pAdapter->PortCfg.Bssid, MAC_ADDR_LEN);
	NdisFillMemory(&pAdapter->PortCfg.Broadcast, MAC_ADDR_LEN, 0xff);
	pAdapter->PortCfg.Pss = PWR_ACTIVE;
	pAdapter->PortCfg.RssiTrigger = 0;
	pAdapter->PortCfg.LastRssi = 0;
	pAdapter->PortCfg.AvgRssi  = 0;
	pAdapter->PortCfg.RssiTriggerMode = RSSI_TRIGGERED_UPON_BELOW_THRESHOLD;
	pAdapter->PortCfg.AtimWin = 0;
	pAdapter->PortCfg.Channel = 1;

	pAdapter->PortCfg.Aid = 1;

	pAdapter->PortCfg.DefaultListenCount = 3;//default listen count;
	pAdapter->PortCfg.BssType = BSS_INFRA;	// BSS_INFRA or BSS_INDEP

	pAdapter->PortCfg.SsidLen = 0;
	NdisZeroMemory(pAdapter->PortCfg.Ssid, MAX_LEN_OF_SSID);  // NOT NULL-terminated

	// global variables mXXXX used in MAC protocol state machines
	pAdapter->PortCfg.Mibss = FALSE;
	pAdapter->PortCfg.Massoc = FALSE;
	pAdapter->PortCfg.Mauth = FALSE;

	// PHY specification
	pAdapter->PortCfg.PhyMode = PHY_11BG_MIXED;
	//	  RTMPSetPhyMode(pAdapter, PHY_11BG_MIXED);   // default in 11BG mixed mode
	pAdapter->PortCfg.Dsifs = 10;	   // in units of usec 
	pAdapter->PortCfg.TxPreambleInUsed = Rt802_11PreambleLong; // use Long preamble on TX by defaut

	// user desired power mode
	pAdapter->PortCfg.WindowsPowerMode = Ndis802_11PowerModeCAM; // Ndis802_11PowerModeFast_PSP;
	pAdapter->PortCfg.WindowsTxPreamble = Rt802_11PreambleAuto; // use Long preamble on TX by defaut
	//pAdapter->PortCfg.PacketFilter = NDIS_PACKET_TYPE_ALL_MULTICAST | NDIS_PACKET_TYPE_DIRECTED | NDIS_PACKET_TYPE_BROADCAST;
	pAdapter->bAcceptDirect = TRUE;
	pAdapter->bAcceptMulticast = FALSE;
	pAdapter->bAcceptBroadcast = TRUE;
	pAdapter->bAcceptAllMulticast = TRUE;
	
#ifdef NDIS51_MINIPORT
	pAdapter->PortCfg.WindowsPowerProfile = NdisPowerProfileAcOnLine; // N

⌨️ 快捷键说明

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