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

📄 rt_linux.c

📁 Linux下的RT系列无线网卡驱动,可以直接在x86平台上编译
💻 C
📖 第 1 页 / 共 3 页
字号:
/* ************************************************************************* * Ralink Tech Inc. * 4F, No. 2 Technology 5th Rd. * Science-based Industrial Park * Hsin-chu, Taiwan, R.O.C. * * (c) Copyright 2002-2007, 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.             *  *                                                                       *  ************************************************************************* */#include "rt_config.h"ULONG	RTDebugLevel = RT_DEBUG_ERROR;BUILD_TIMER_FUNCTION(MlmePeriodicExec);//BUILD_TIMER_FUNCTION(MlmeRssiReportExec);BUILD_TIMER_FUNCTION(AsicRxAntEvalTimeout);BUILD_TIMER_FUNCTION(APSDPeriodicExec);BUILD_TIMER_FUNCTION(AsicRfTuningExec);#ifdef CONFIG_STA_SUPPORTBUILD_TIMER_FUNCTION(BeaconTimeout);BUILD_TIMER_FUNCTION(ScanTimeout);BUILD_TIMER_FUNCTION(AuthTimeout);BUILD_TIMER_FUNCTION(AssocTimeout);BUILD_TIMER_FUNCTION(ReassocTimeout);BUILD_TIMER_FUNCTION(DisassocTimeout);BUILD_TIMER_FUNCTION(LinkDownExec);#ifdef LEAP_SUPPORTBUILD_TIMER_FUNCTION(LeapAuthTimeout);#endifBUILD_TIMER_FUNCTION(StaQuickResponeForRateUpExec);BUILD_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc);#endif // CONFIG_STA_SUPPORT //// for wireless event messagechar const *pWirelessEventText[IW_EVENT_TYPE_NUM] = {        "had associated successfully",							/* IW_ASSOC_EVENT_FLAG */    "had disassociated",									/* IW_DISASSOC_EVENT_FLAG */    "had deauthenticated",									/* IW_DEAUTH_EVENT_FLAG */    "had been aged-out and disassociated",					/* IW_AGEOUT_EVENT_FLAG */    "occurred CounterMeasures attack",						/* IW_COUNTER_MEASURES_EVENT_FLAG */	    "occurred replay counter different in Key Handshaking",	/* IW_REPLAY_COUNTER_DIFF_EVENT_FLAG */    "occurred RSNIE different in Key Handshaking",			/* IW_RSNIE_DIFF_EVENT_FLAG */    "occurred MIC different in Key Handshaking",			/* IW_MIC_DIFF_EVENT_FLAG */    "occurred ICV error in RX",								/* IW_ICV_ERROR_EVENT_FLAG */    "occurred MIC error in RX",								/* IW_MIC_ERROR_EVENT_FLAG */	"Group Key Handshaking timeout",						/* IW_GROUP_HS_TIMEOUT_EVENT_FLAG */ 	"Pairwise Key Handshaking timeout",						/* IW_PAIRWISE_HS_TIMEOUT_EVENT_FLAG */ 	"RSN IE sanity check failure",							/* IW_RSNIE_SANITY_FAIL_EVENT_FLAG */ 	"set key done in WPA/WPAPSK",							/* IW_SET_KEY_DONE_WPA1_EVENT_FLAG */ 	"set key done in WPA2/WPA2PSK"};						/* IW_SET_KEY_DONE_WPA2_EVENT_FLAG */ /* timeout -- ms */VOID RTMP_SetPeriodicTimer(	IN	NDIS_MINIPORT_TIMER *pTimer, 	IN	unsigned long timeout){	timeout = ((timeout*HZ) / 1000);	pTimer->expires = jiffies + timeout;	add_timer(pTimer);}/* convert NdisMInitializeTimer --> RTMP_OS_Init_Timer */VOID RTMP_OS_Init_Timer(	IN	PRTMP_ADAPTER pAd,	IN	NDIS_MINIPORT_TIMER *pTimer, 	IN	TIMER_FUNCTION function,	IN	PVOID data){	init_timer(pTimer);    pTimer->data = (unsigned long)data;    pTimer->function = function;		}VOID RTMP_OS_Add_Timer(	IN	NDIS_MINIPORT_TIMER		*pTimer,	IN	unsigned long timeout){	timeout = ((timeout*HZ) / 1000);	pTimer->expires = jiffies + timeout;	add_timer(pTimer);}VOID RTMP_OS_Mod_Timer(	IN	NDIS_MINIPORT_TIMER		*pTimer,	IN	unsigned long timeout){	timeout = ((timeout*HZ) / 1000);	mod_timer(pTimer, jiffies + timeout);}VOID RTMP_OS_Del_Timer(	IN	NDIS_MINIPORT_TIMER		*pTimer,	OUT	BOOLEAN					*pCancelled){	if (timer_pending(pTimer))	{			*pCancelled = del_timer_sync(pTimer);		}	else	{		*pCancelled = TRUE;	}	}VOID RTMP_OS_Release_Packet(	IN	PRTMP_ADAPTER pAd,	IN	PQUEUE_ENTRY  pEntry){	//RELEASE_NDIS_PACKET(pAd, (struct sk_buff *)pEntry);}	// Unify all delay routine by using udelayVOID RTMPusecDelay(	IN	ULONG	usec){	ULONG	i;	for (i = 0; i < (usec / 50); i++)		udelay(50);	if (usec % 50)		udelay(usec % 50);}void RTMP_GetCurrentSystemTime(LARGE_INTEGER *time){	time->u.LowPart = jiffies;}// pAd MUST allow to be NULLNDIS_STATUS os_alloc_mem(	IN	PRTMP_ADAPTER pAd,	OUT	PUCHAR *mem,	IN	ULONG  size){		*mem = (PUCHAR) kmalloc(size, GFP_ATOMIC);	if (*mem)		return (NDIS_STATUS_SUCCESS);	else		return (NDIS_STATUS_FAILURE);}// pAd MUST allow to be NULLNDIS_STATUS os_free_mem(	IN	PRTMP_ADAPTER pAd,	IN	PUCHAR mem){		ASSERT(mem);	kfree(mem);	return (NDIS_STATUS_SUCCESS);}NDIS_STATUS AdapterBlockAllocateMemory(	IN PVOID	handle,	OUT	PVOID	*ppAd){	PPCI_DEV pci_dev;	dma_addr_t	*phy_addr;	POS_COOKIE pObj = (POS_COOKIE) handle;		pci_dev = pObj->pci_dev;	phy_addr = &pObj->pAd_pa;		*ppAd = (PVOID)vmalloc(sizeof(RTMP_ADAPTER)); //pci_alloc_consistent(pci_dev, sizeof(RTMP_ADAPTER), phy_addr);    	if (*ppAd) 	{		NdisZeroMemory(*ppAd, sizeof(RTMP_ADAPTER));		((PRTMP_ADAPTER)*ppAd)->OS_Cookie = handle;		return (NDIS_STATUS_SUCCESS);	} else {		return (NDIS_STATUS_FAILURE);	}}void RTMP_AllocateTxDescMemory(	IN	PRTMP_ADAPTER pAd,	IN	UINT	Index,	IN	ULONG	Length,	IN	BOOLEAN	Cached,	OUT	PVOID	*VirtualAddress,	OUT	PNDIS_PHYSICAL_ADDRESS PhysicalAddress){	POS_COOKIE pObj = (POS_COOKIE)pAd->OS_Cookie;	*VirtualAddress = (PVOID)pci_alloc_consistent(pObj->pci_dev,sizeof(char)*Length, PhysicalAddress);}void RTMP_AllocateMgmtDescMemory(	IN	PRTMP_ADAPTER pAd,	IN	ULONG	Length,	IN	BOOLEAN	Cached,	OUT	PVOID	*VirtualAddress,	OUT	PNDIS_PHYSICAL_ADDRESS PhysicalAddress){	POS_COOKIE pObj = (POS_COOKIE)pAd->OS_Cookie;	*VirtualAddress = (PVOID)pci_alloc_consistent(pObj->pci_dev,sizeof(char)*Length, PhysicalAddress);}void RTMP_AllocateRxDescMemory(	IN	PRTMP_ADAPTER pAd,	IN	ULONG	Length,	IN	BOOLEAN	Cached,	OUT	PVOID	*VirtualAddress,	OUT	PNDIS_PHYSICAL_ADDRESS PhysicalAddress){	POS_COOKIE pObj = (POS_COOKIE)pAd->OS_Cookie;	*VirtualAddress = (PVOID)pci_alloc_consistent(pObj->pci_dev,sizeof(char)*Length, PhysicalAddress);}void RTMP_FreeRxDescMemory(	IN	PRTMP_ADAPTER pAd,	IN	ULONG	Length,	IN	PVOID	VirtualAddress,	IN	NDIS_PHYSICAL_ADDRESS PhysicalAddress){	POS_COOKIE pObj = (POS_COOKIE)pAd->OS_Cookie;		pci_free_consistent(pObj->pci_dev, Length, VirtualAddress, PhysicalAddress);}void RTMP_AllocateFirstTxBuffer(	IN	PRTMP_ADAPTER pAd,	IN	UINT	Index,	IN	ULONG	Length,	IN	BOOLEAN	Cached,	OUT	PVOID	*VirtualAddress,	OUT	PNDIS_PHYSICAL_ADDRESS PhysicalAddress){	POS_COOKIE pObj = (POS_COOKIE)pAd->OS_Cookie;	*VirtualAddress = (PVOID)pci_alloc_consistent(pObj->pci_dev,sizeof(char)*Length, PhysicalAddress);}/* * FUNCTION: Allocate a common buffer for DMA * ARGUMENTS: *     AdapterHandle:  AdapterHandle *     Length:  Number of bytes to allocate *     Cached:  Whether or not the memory can be cached *     VirtualAddress:  Pointer to memory is returned here *     PhysicalAddress:  Physical address corresponding to virtual address */void RTMP_AllocateSharedMemory(	IN	PRTMP_ADAPTER pAd,	IN	ULONG	Length,	IN	BOOLEAN	Cached,	OUT	PVOID	*VirtualAddress,	OUT	PNDIS_PHYSICAL_ADDRESS PhysicalAddress){	POS_COOKIE pObj = (POS_COOKIE)pAd->OS_Cookie;	*VirtualAddress = (PVOID)pci_alloc_consistent(pObj->pci_dev,sizeof(char)*Length, PhysicalAddress);	}VOID RTMPFreeDMAMemory(    IN  PRTMP_ADAPTER   pAd){	int index, num , j;	PRTMP_TX_RING pTxRing;	PTXD_STRUC	  pTxD;	PNDIS_PACKET  pPacket;	POS_COOKIE pObj =(POS_COOKIE) pAd->OS_Cookie;		DBGPRINT(RT_DEBUG_TRACE, ("--> RTMPFreeDMAMemory\n"));		// Free TxSwQueue Packet	for (index=0; index <NUM_OF_TX_RING; index++)	{		PQUEUE_ENTRY pEntry;		PNDIS_PACKET pPacket;		PQUEUE_HEADER   pQueue;				pQueue = &pAd->TxSwQueue[index];		while (pQueue->Head)		{			pEntry = RemoveHeadQueue(pQueue);			pPacket = QUEUE_ENTRY_TO_PACKET(pEntry);			RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);		}		}	// Free Tx Ring Packet	for (index=0;index< NUM_OF_TX_RING;index++)	{		pTxRing = &pAd->TxRing[index];				for (j=0; j< TX_RING_SIZE; j++)		{				pTxD = (PTXD_STRUC) (pTxRing->Cell[j].AllocVa);			pPacket = pTxRing->Cell[j].pNdisPacket;			if (pPacket)			{            	PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr0, pTxD->SDLen0, PCI_DMA_TODEVICE);				RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS);			}					//Always assign pNdisPacket as NULL after clear			pTxRing->Cell[j].pNdisPacket = NULL;								pPacket = pTxRing->Cell[j].pNextNdisPacket;						if (pPacket)			{            	PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1, pTxD->SDLen1, PCI_DMA_TODEVICE);				RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS);			}			//Always assign pNextNdisPacket as NULL after clear			pTxRing->Cell[pTxRing->TxSwFreeIdx].pNextNdisPacket = NULL;		}	}			for (index = RX_RING_SIZE - 1 ; index >= 0; index--)	{		if ((pAd->RxRing.Cell[index].DmaBuf.AllocVa) && (pAd->RxRing.Cell[index].pNdisPacket))		{			pci_unmap_single(pObj->pci_dev, pAd->RxRing.Cell[index].DmaBuf.AllocPa, pAd->RxRing.Cell[index].DmaBuf.AllocSize, PCI_DMA_FROMDEVICE);			RELEASE_NDIS_PACKET(pAd, pAd->RxRing.Cell[index].pNdisPacket, NDIS_STATUS_SUCCESS);		}#ifdef RX_SCATTERED		if ((pAd->RxRing.Cell[index].NextDmaBuf.AllocVa) && (pAd->RxRing.Cell[index].pNextNdisPacket))		{			pci_unmap_single(pObj->pci_dev, pAd->RxRing.Cell[index].NextDmaBuf.AllocPa, pAd->RxRing.Cell[index].NextDmaBuf.AllocSize, PCI_DMA_FROMDEVICE);			RELEASE_NDIS_PACKET(pAd, pAd->RxRing.Cell[index].pNextNdisPacket, NDIS_STATUS_SUCCESS);		}#endif			}	NdisZeroMemory(pAd->RxRing.Cell, RX_RING_SIZE * sizeof(RTMP_DMACB));		if (pAd->RxDescRing.AllocVa)    {    	pci_free_consistent(pObj->pci_dev, pAd->RxDescRing.AllocSize, pAd->RxDescRing.AllocVa, pAd->RxDescRing.AllocPa);    }    NdisZeroMemory(&pAd->RxDescRing, sizeof(RTMP_DMABUF));		if (pAd->MgmtDescRing.AllocVa)	{		pci_free_consistent(pObj->pci_dev, pAd->MgmtDescRing.AllocSize,	pAd->MgmtDescRing.AllocVa, pAd->MgmtDescRing.AllocPa);	}	NdisZeroMemory(&pAd->MgmtDescRing, sizeof(RTMP_DMABUF));	for (num = 0; num < NUM_OF_TX_RING; num++)	{    	if (pAd->TxBufSpace[num].AllocVa)	    {	    	pci_free_consistent(pObj->pci_dev, pAd->TxBufSpace[num].AllocSize, pAd->TxBufSpace[num].AllocVa, pAd->TxBufSpace[num].AllocPa);	    }	    NdisZeroMemory(&pAd->TxBufSpace[num], sizeof(RTMP_DMABUF));	        	if (pAd->TxDescRing[num].AllocVa)	    {

⌨️ 快捷键说明

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