2870_main_dev.c

来自「ralink最新rt3070 usb wifi 无线网卡驱动程序」· C语言 代码 · 共 1,628 行 · 第 1/3 页

C
1,628
字号
		printk("rt2870: Error! Device Descriptor not matching!\n");		return FALSE;	}	return TRUE;}/*========================================================================Routine Description:    Init net device structure.Arguments:    _dev_p				Point to the PCI or USB device    *net_dev			Point to the net device	*pAd				the raxx interface data pointerReturn Value:    TRUE				Init ok	FALSE				Init failNote:========================================================================*/BOOLEAN RT28XXNetDevInit(	IN void 				*_dev_p,	IN struct  net_device	*net_dev,	IN RTMP_ADAPTER 		*pAd){#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)	/* kernel 2.4 series */	struct usb_device *dev_p = (struct usb_device *)_dev_p;#else	struct usb_interface *intf = (struct usb_interface *)_dev_p;	struct usb_device *dev_p = interface_to_usbdev(intf);#endif // LINUX_VERSION_CODE //#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)	/* kernel 2.4 series */	pAd->config = dev_p->config;#else	pAd->config = &dev_p->config->desc;#endif // LINUX_VERSION_CODE //	return TRUE;}/*========================================================================Routine Description:    Init net device structure.Arguments:    _dev_p				Point to the PCI or USB device	*pAd				the raxx interface data pointerReturn Value:    TRUE				Config ok	FALSE				Config failNote:========================================================================*/#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)BOOLEAN RT28XXProbePostConfig(	IN void 				*_dev_p,	IN RTMP_ADAPTER 		*pAd,	IN INT32				interface){	struct usb_device *dev_p = (struct usb_device *)_dev_p;	struct usb_interface *intf;	struct usb_interface_descriptor *iface_desc;	struct usb_endpoint_descriptor *endpoint;	ULONG BulkOutIdx;	UINT32 i;	/* get the active interface descriptor */	intf = &dev_p->actconfig->interface[interface];	iface_desc = &intf->altsetting[0];	/* get # of enpoints */	pAd->NumberOfPipes = iface_desc->bNumEndpoints;	DBGPRINT(RT_DEBUG_TRACE, ("NumEndpoints=%d\n", iface_desc->bNumEndpoints));		 	/* Configure Pipes */	endpoint = &iface_desc->endpoint[0];	BulkOutIdx = 0;	for(i=0; i<pAd->NumberOfPipes; i++)	{		if ((endpoint[i].bmAttributes == USB_ENDPOINT_XFER_BULK) && 			((endpoint[i].bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN))		{			pAd->BulkInEpAddr = endpoint[i].bEndpointAddress;			pAd->BulkInMaxPacketSize = endpoint[i].wMaxPacketSize;			DBGPRINT_RAW(RT_DEBUG_TRACE,				("BULK IN MaximumPacketSize = %d\n", pAd->BulkInMaxPacketSize));			DBGPRINT_RAW(RT_DEBUG_TRACE,				("EP address = 0x%2x  \n", endpoint[i].bEndpointAddress));		}		else if ((endpoint[i].bmAttributes == USB_ENDPOINT_XFER_BULK) && 				((endpoint[i].bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT))		{			// There are 6 bulk out EP. EP6 highest priority.			// EP1-4 is EDCA.  EP5 is HCCA.			pAd->BulkOutEpAddr[BulkOutIdx++] = endpoint[i].bEndpointAddress;			pAd->BulkOutMaxPacketSize = endpoint[i].wMaxPacketSize;			DBGPRINT_RAW(RT_DEBUG_TRACE,				("BULK OUT MaximumPacketSize = %d\n", pAd->BulkOutMaxPacketSize));			DBGPRINT_RAW(RT_DEBUG_TRACE,				("EP address = 0x%2x  \n", endpoint[i].bEndpointAddress));		}	}	if (!(pAd->BulkInEpAddr && pAd->BulkOutEpAddr[0])) 	{		printk("Could not find both bulk-in and bulk-out endpoints\n");		return FALSE;	}	return TRUE;}#elseBOOLEAN RT28XXProbePostConfig(	IN void 				*_dev_p,	IN RTMP_ADAPTER 		*pAd,	IN INT32				interface){	struct usb_interface *intf = (struct usb_interface *)_dev_p;	struct usb_host_interface *iface_desc;	ULONG BulkOutIdx;	UINT32 i;	/* get the active interface descriptor */	iface_desc = intf->cur_altsetting;	/* get # of enpoints  */	pAd->NumberOfPipes = iface_desc->desc.bNumEndpoints;	DBGPRINT(RT_DEBUG_TRACE,			("NumEndpoints=%d\n", iface_desc->desc.bNumEndpoints));		  	/* Configure Pipes */	BulkOutIdx = 0;	for(i=0; i<pAd->NumberOfPipes; i++)	{ 		if ((iface_desc->endpoint[i].desc.bmAttributes == 				USB_ENDPOINT_XFER_BULK) && 			((iface_desc->endpoint[i].desc.bEndpointAddress &				USB_ENDPOINT_DIR_MASK) == USB_DIR_IN))		{			pAd->BulkInEpAddr = iface_desc->endpoint[i].desc.bEndpointAddress;			pAd->BulkInMaxPacketSize = iface_desc->endpoint[i].desc.wMaxPacketSize;			DBGPRINT_RAW(RT_DEBUG_TRACE,				("BULK IN MaximumPacketSize = %d\n", pAd->BulkInMaxPacketSize));			DBGPRINT_RAW(RT_DEBUG_TRACE,				("EP address = 0x%2x\n", iface_desc->endpoint[i].desc.bEndpointAddress));		}		else if ((iface_desc->endpoint[i].desc.bmAttributes ==					USB_ENDPOINT_XFER_BULK) && 				((iface_desc->endpoint[i].desc.bEndpointAddress &					USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT))		{			// there are 6 bulk out EP. EP6 highest priority.			// EP1-4 is EDCA.  EP5 is HCCA.			pAd->BulkOutEpAddr[BulkOutIdx++] = iface_desc->endpoint[i].desc.bEndpointAddress;			pAd->BulkOutMaxPacketSize = iface_desc->endpoint[i].desc.wMaxPacketSize;			DBGPRINT_RAW(RT_DEBUG_TRACE,				("BULK OUT MaximumPacketSize = %d\n", pAd->BulkOutMaxPacketSize));			DBGPRINT_RAW(RT_DEBUG_TRACE,				("EP address = 0x%2x  \n", iface_desc->endpoint[i].desc.bEndpointAddress));		}	}	if (!(pAd->BulkInEpAddr && pAd->BulkOutEpAddr[0])) 	{		printk("%s: Could not find both bulk-in and bulk-out endpoints\n", __FUNCTION__);		return FALSE;	}	return TRUE;}#endif // LINUX_VERSION_CODE ///*========================================================================Routine Description:    Disable DMA.Arguments:	*pAd				the raxx interface data pointerReturn Value:	NoneNote:========================================================================*/VOID RT28XXDMADisable(	IN RTMP_ADAPTER 		*pAd){	// no use}/*========================================================================Routine Description:    Enable DMA.Arguments:	*pAd				the raxx interface data pointerReturn Value:	NoneNote:========================================================================*/VOID RT28XXDMAEnable(	IN RTMP_ADAPTER 		*pAd){	WPDMA_GLO_CFG_STRUC	GloCfg;	USB_DMA_CFG_STRUC	UsbCfg;	int					i = 0;			RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x4);	do	{		RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);		if ((GloCfg.field.TxDMABusy == 0)  && (GloCfg.field.RxDMABusy == 0))			break;				DBGPRINT(RT_DEBUG_TRACE, ("==>  DMABusy\n"));		RTMPusecDelay(1000);		i++;	}while ( i <200);	RTMPusecDelay(50);	GloCfg.field.EnTXWriteBackDDONE = 1;	GloCfg.field.EnableRxDMA = 1;	GloCfg.field.EnableTxDMA = 1;	DBGPRINT(RT_DEBUG_TRACE, ("<== WRITE DMA offset 0x208 = 0x%x\n", GloCfg.word));		RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word);		UsbCfg.word = 0;	UsbCfg.field.phyclear = 0;	/* usb version is 1.1,do not use bulk in aggregation */	if (pAd->BulkInMaxPacketSize == 512)			UsbCfg.field.RxBulkAggEn = 1;	/* for last packet, PBF might use more than limited, so minus 2 to prevent from error */	UsbCfg.field.RxBulkAggLmt = (MAX_RXBULK_SIZE /1024)-3;	UsbCfg.field.RxBulkAggTOut = 0x80; /* 2006-10-18 */	UsbCfg.field.RxBulkEn = 1;	UsbCfg.field.TxBulkEn = 1;	RTUSBWriteMACRegister(pAd, USB_DMA_CFG, UsbCfg.word);}/*========================================================================Routine Description:    Write Beacon buffer to Asic.Arguments:	*pAd				the raxx interface data pointerReturn Value:	NoneNote:========================================================================*/VOID RT28xx_UpdateBeaconToAsic(	IN RTMP_ADAPTER		*pAd,	IN INT				apidx,	IN ULONG			FrameLen,	IN ULONG			UpdatePos){	PUCHAR        	pBeaconFrame = NULL;	UCHAR  			*ptr;	UINT  			i, padding;	BEACON_SYNC_STRUCT	*pBeaconSync = pAd->CommonCfg.pBeaconSync;	UINT32			longValue;//	USHORT			shortValue;	BOOLEAN			bBcnReq = FALSE;	UCHAR			bcn_idx = 0;	if (pBeaconFrame == NULL)	{		DBGPRINT(RT_DEBUG_ERROR,("pBeaconFrame is NULL!\n"));		return;	}	if (pBeaconSync == NULL)	{		DBGPRINT(RT_DEBUG_ERROR,("pBeaconSync is NULL!\n"));		return;	}		//if ((pAd->WdsTab.Mode == WDS_BRIDGE_MODE) || 	//	((pAd->ApCfg.MBSSID[apidx].MSSIDDev == NULL) || !(pAd->ApCfg.MBSSID[apidx].MSSIDDev->flags & IFF_UP))	//	)	if (bBcnReq == FALSE)	{		/* when the ra interface is down, do not send its beacon frame */		/* clear all zero */		for(i=0; i<TXWI_SIZE; i+=4) {			RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[bcn_idx] + i, 0x00);		}		pBeaconSync->BeaconBitMap &= (~(BEACON_BITMAP_MASK & (1 << bcn_idx)));		NdisZeroMemory(pBeaconSync->BeaconTxWI[bcn_idx], TXWI_SIZE);	}	else	{		ptr = (PUCHAR)&pAd->BeaconTxWI;#ifdef RT_BIG_ENDIAN		RTMPWIEndianChange(ptr, TYPE_TXWI);#endif		if (NdisEqualMemory(pBeaconSync->BeaconTxWI[bcn_idx], &pAd->BeaconTxWI, TXWI_SIZE) == FALSE)		{	// If BeaconTxWI changed, we need to rewrite the TxWI for the Beacon frames.			pBeaconSync->BeaconBitMap &= (~(BEACON_BITMAP_MASK & (1 << bcn_idx)));			NdisMoveMemory(pBeaconSync->BeaconTxWI[bcn_idx], &pAd->BeaconTxWI, TXWI_SIZE);		}				if ((pBeaconSync->BeaconBitMap & (1 << bcn_idx)) != (1 << bcn_idx))		{			for (i=0; i<TXWI_SIZE; i+=4)  // 16-byte TXWI field			{				longValue =  *ptr + (*(ptr+1)<<8) + (*(ptr+2)<<16) + (*(ptr+3)<<24);				RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[bcn_idx] + i, longValue);				ptr += 4;			}		}		ptr = pBeaconSync->BeaconBuf[bcn_idx];		padding = (FrameLen & 0x01);		NdisZeroMemory((PUCHAR)(pBeaconFrame + FrameLen), padding);		FrameLen += padding;		for (i = 0 ; i < FrameLen /*HW_BEACON_OFFSET*/; i += 2)		{			if (NdisEqualMemory(ptr, pBeaconFrame, 2) == FALSE)			{				NdisMoveMemory(ptr, pBeaconFrame, 2);				//shortValue = *ptr + (*(ptr+1)<<8);				//RTMP_IO_WRITE8(pAd, pAd->BeaconOffset[bcn_idx] + TXWI_SIZE + i, shortValue);				RTUSBMultiWrite(pAd, pAd->BeaconOffset[bcn_idx] + TXWI_SIZE + i, ptr, 2);			}			ptr +=2;			pBeaconFrame += 2;		}		pBeaconSync->BeaconBitMap |= (1 << bcn_idx);		// For AP interface, set the DtimBitOn so that we can send Bcast/Mcast frame out after this beacon frame.	}	}VOID RT2870_BssBeaconStop(	IN RTMP_ADAPTER *pAd){	BEACON_SYNC_STRUCT	*pBeaconSync;	int i, offset;	BOOLEAN	Cancelled = TRUE;	pBeaconSync = pAd->CommonCfg.pBeaconSync;	if (pBeaconSync && pBeaconSync->EnableBeacon)	{		INT NumOfBcn;#ifdef CONFIG_STA_SUPPORT		IF_DEV_CONFIG_OPMODE_ON_STA(pAd)		{			NumOfBcn = MAX_MESH_NUM;		}#endif // CONFIG_STA_SUPPORT //		RTMPCancelTimer(&pAd->CommonCfg.BeaconUpdateTimer, &Cancelled);		for(i=0; i<NumOfBcn; i++)		{			NdisZeroMemory(pBeaconSync->BeaconBuf[i], HW_BEACON_OFFSET);			NdisZeroMemory(pBeaconSync->BeaconTxWI[i], TXWI_SIZE);			for (offset=0; offset<HW_BEACON_OFFSET; offset+=4)				RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[i] + offset, 0x00);						pBeaconSync->CapabilityInfoLocationInBeacon[i] = 0;			pBeaconSync->TimIELocationInBeacon[i] = 0;		}		pBeaconSync->BeaconBitMap = 0;		pBeaconSync->DtimBitOn = 0;	}}VOID RT2870_BssBeaconStart(	IN RTMP_ADAPTER *pAd){	int apidx;	BEACON_SYNC_STRUCT	*pBeaconSync;//	LARGE_INTEGER 	tsfTime, deltaTime;	pBeaconSync = pAd->CommonCfg.pBeaconSync;	if (pBeaconSync && pBeaconSync->EnableBeacon)	{		INT NumOfBcn;#ifdef CONFIG_STA_SUPPORT		IF_DEV_CONFIG_OPMODE_ON_STA(pAd)		{			NumOfBcn = MAX_MESH_NUM;		}#endif // CONFIG_STA_SUPPORT //		for(apidx=0; apidx<NumOfBcn; apidx++)		{			UCHAR CapabilityInfoLocationInBeacon = 0;			UCHAR TimIELocationInBeacon = 0;#ifdef CONFIG_STA_SUPPORT#endif // CONFIG_STA_SUPPORT //			NdisZeroMemory(pBeaconSync->BeaconBuf[apidx], HW_BEACON_OFFSET);			pBeaconSync->CapabilityInfoLocationInBeacon[apidx] = CapabilityInfoLocationInBeacon;			pBeaconSync->TimIELocationInBeacon[apidx] = TimIELocationInBeacon;			NdisZeroMemory(pBeaconSync->BeaconTxWI[apidx], TXWI_SIZE);		}		pBeaconSync->BeaconBitMap = 0;		pBeaconSync->DtimBitOn = 0;		pAd->CommonCfg.BeaconUpdateTimer.Repeat = TRUE;		pAd->CommonCfg.BeaconAdjust = 0;		pAd->CommonCfg.BeaconFactor = 0xffffffff / (pAd->CommonCfg.BeaconPeriod << 10);		pAd->CommonCfg.BeaconRemain = (0xffffffff % (pAd->CommonCfg.BeaconPeriod << 10)) + 1;		printk("RT2870_BssBeaconStart:BeaconFactor=%d, BeaconRemain=%d!\n", pAd->CommonCfg.BeaconFactor, pAd->CommonCfg.BeaconRemain);		RTMPSetTimer(&pAd->CommonCfg.BeaconUpdateTimer, pAd->CommonCfg.BeaconPeriod);	}}VOID RT2870_BssBeaconInit(	IN RTMP_ADAPTER *pAd){	BEACON_SYNC_STRUCT	*pBeaconSync;	int i;	NdisAllocMemory(pAd->CommonCfg.pBeaconSync, sizeof(BEACON_SYNC_STRUCT), MEM_ALLOC_FLAG);	if (pAd->CommonCfg.pBeaconSync)	{		pBeaconSync = pAd->CommonCfg.pBeaconSync;		NdisZeroMemory(pBeaconSync, sizeof(BEACON_SYNC_STRUCT));		for(i=0; i < HW_BEACON_MAX_COUNT; i++)		{			NdisZeroMemory(pBeaconSync->BeaconBuf[i], HW_BEACON_OFFSET);			pBeaconSync->CapabilityInfoLocationInBeacon[i] = 0;			pBeaconSync->TimIELocationInBeacon[i] = 0;			NdisZeroMemory(pBeaconSync->BeaconTxWI[i], TXWI_SIZE);		}		pBeaconSync->BeaconBitMap = 0;				//RTMPInitTimer(pAd, &pAd->CommonCfg.BeaconUpdateTimer, GET_TIMER_FUNCTION(BeaconUpdateExec), pAd, TRUE);		pBeaconSync->EnableBeacon = TRUE;	}}VOID RT2870_BssBeaconExit(	IN RTMP_ADAPTER *pAd){	BEACON_SYNC_STRUCT	*pBeaconSync;	BOOLEAN	Cancelled = TRUE;	int i;	if (pAd->CommonCfg.pBeaconSync)	{		pBeaconSync = pAd->CommonCfg.pBeaconSync;		pBeaconSync->EnableBeacon = FALSE;		RTMPCancelTimer(&pAd->CommonCfg.BeaconUpdateTimer, &Cancelled);		pBeaconSync->BeaconBitMap = 0;		for(i=0; i<HW_BEACON_MAX_COUNT; i++)		{			NdisZeroMemory(pBeaconSync->BeaconBuf[i], HW_BEACON_OFFSET);			pBeaconSync->CapabilityInfoLocationInBeacon[i] = 0;			pBeaconSync->TimIELocationInBeacon[i] = 0;			NdisZeroMemory(pBeaconSync->BeaconTxWI[i], TXWI_SIZE);		}				NdisFreeMemory(pAd->CommonCfg.pBeaconSync, HW_BEACON_OFFSET * HW_BEACON_MAX_COUNT, 0);		pAd->CommonCfg.pBeaconSync = NULL;	}}VOID BeaconUpdateExec(    IN PVOID SystemSpecific1,     IN PVOID FunctionContext,     IN PVOID SystemSpecific2,     IN PVOID SystemSpecific3){	PRTMP_ADAPTER	pAd = (PRTMP_ADAPTER)FunctionContext;	LARGE_INTEGER	tsfTime_a;//, tsfTime_b, deltaTime_exp, deltaTime_ab;	UINT32			delta, remain, remain_low, remain_high;//	BOOLEAN			positive;	ReSyncBeaconTime(pAd);	RTMP_IO_READ32(pAd, TSF_TIMER_DW0, &tsfTime_a.u.LowPart);	RTMP_IO_READ32(pAd, TSF_TIMER_DW1, &tsfTime_a.u.HighPart);		//positive=getDeltaTime(tsfTime_a, expectedTime, &deltaTime_exp);	remain_high = pAd->CommonCfg.BeaconRemain * tsfTime_a.u.HighPart;	remain_low = tsfTime_a.u.LowPart % (pAd->CommonCfg.BeaconPeriod << 10);	remain = (remain_high + remain_low)%(pAd->CommonCfg.BeaconPeriod << 10);	delta = (pAd->CommonCfg.BeaconPeriod << 10) - remain;	pAd->CommonCfg.BeaconUpdateTimer.TimerValue = (delta >> 10) + 10;}

⌨️ 快捷键说明

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