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

📄 mdata.c

📁 atheros ar5001 5002 driver
💻 C
📖 第 1 页 / 共 5 页
字号:
	if(enableCompare) {
		free(statsInfo.pCompareData);
	}

	if ((i == timeout) && (rxComplete != TRUE))
	{
		mError(devNum, EIO, 
			"Device Number %d:rxDataBegin: timeout reached, without receiving all packets.  Number received = %lu\n", devNum,
			numDesc);
		ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->rxCleanupConfig(devNum);
	}

	return;
}


/**************************************************************************
* rxDataCompleteFixedNumber - receive until get required amount of frames
*
*/
MANLIB_API void rxDataCompleteFixedNumber
(
 A_UINT32 devNum, 
 A_UINT32 timeout, 
 A_UINT32 remoteStats,
 A_UINT32 enableCompare,
 A_UCHAR *dataPattern, 
 A_UINT32 dataPatternLength
)
{
	ISR_EVENT	event;
	A_UINT32	i, statsLoop;
	A_UINT32	numDesc = 0;
	LIB_DEV_INFO *pLibDev = gLibInfo.pLibDevArray[devNum];
	RX_STATS_TEMP_INFO	statsInfo;
//	A_BOOL		statsSent = FALSE;
//	A_BOOL		rxComplete = FALSE;
//	A_UINT16	queueIndex = pLibDev->selQueueIndex;
	A_UINT32	startTime = 0;
	A_UINT32	curTime;
	A_BOOL		skipStats = FALSE;
	A_UINT16     numStatsToSkip = 0;		
	A_UINT32     numReceived = 0;
	A_BOOL	     done = FALSE;

	startTime = milliTime();
	if(remoteStats & ENABLE_STATS_RECEIVE) {
		mError(devNum, EINVAL, "Device Number %d:Stats receive is not supported in this mode.  Returning...\n", devNum);
		return;
	}

	// wait for event
	event.valid = 0;
	event.ISRValue = 0;
	for (i = 0; i < timeout; i++)
	{
		event = pLibDev->devMap.getISREvent(devNum);
		if (event.valid) {
			if(ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->isRxdescEvent(event.ISRValue)) {
				//reset the starttime clock so we timeout from first received
				startTime = milliTime();
				break;
			}
		}

		curTime = milliTime();
		if (curTime > (startTime+timeout)) {
			i = timeout;
			break;
		}
		mSleep(1);	
	}

	
	if (i == timeout) {
		mError(devNum, EIO, "Device Number %d:rxDataBeginFixedNumber: did not recieved required number within %d millisecs (timeout)\n", devNum, timeout);
		ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->rxCleanupConfig(devNum);
		//fall through and gather stats anyway incase we received some
//		return;
	}

	i = 0;
	memset(&statsInfo, 0, sizeof(RX_STATS_TEMP_INFO));
	for(statsLoop = 0; statsLoop < STATS_BINS; statsLoop++) {
		statsInfo.sigStrength[statsLoop].rxMinSigStrength = 127;
	}

	if(remoteStats & SKIP_SOME_STATS) {
		//extract and set number to skip
		skipStats = 1;
		numStatsToSkip = (A_UINT16)((remoteStats & NUM_TO_SKIP_M) >> NUM_TO_SKIP_S);
	}

	if(pLibDev->rx.enablePPM) {
		for( i = 0; i < MAX_TX_QUEUE; i++ )
		{
			for(statsLoop = 0; statsLoop < STATS_BINS; statsLoop++) 
			{
				pLibDev->rx.rxStats[i][statsLoop].ppmMax = -1000;
				pLibDev->rx.rxStats[i][statsLoop].ppmMin = 1000;
			}
		}
	}

	statsInfo.descToRead = pLibDev->rx.descAddress;
	if (enableCompare) {
		//create a max size compare buffer for easy compare
		statsInfo.pCompareData = (A_UCHAR *)malloc(FRAME_BODY_SIZE);

		if(!statsInfo.pCompareData) {
			mError(devNum, ENOMEM, "Device Number %d:rxDataBegin: Unable to allocate memory for compare buffer\n", devNum);
			ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->rxCleanupConfig(devNum);
			return;
		}

		fillCompareBuffer(statsInfo.pCompareData, FRAME_BODY_SIZE, dataPattern, dataPatternLength);
	}	

	//sit in polling loop, looking for descriptors to be done.
	do {
		//read descriptor status words
		pLibDev->devMap.OSmemRead(devNum, statsInfo.descToRead + SECOND_STATUS_WORD, 
					(A_UCHAR *)&statsInfo.status2, sizeof(statsInfo.status2));

		if (statsInfo.status2 & DESC_DONE) {
			pLibDev->devMap.OSmemRead(devNum, statsInfo.descToRead + FIRST_STATUS_WORD, 
					(A_UCHAR *)&statsInfo.status1, sizeof(statsInfo.status1));
			pLibDev->devMap.OSmemRead(devNum, statsInfo.descToRead + BUFFER_POINTER, 
					(A_UCHAR *)&statsInfo.bufferAddr, sizeof(statsInfo.bufferAddr));
			statsInfo.descRate = descRate2bin((statsInfo.status1 >> BITS_TO_RX_DATA_RATE) & pLibDev->rxDataRateMsk);

			// Initialize loop variables
			statsInfo.badPacket = 0;
			statsInfo.gotHeaderInfo = FALSE; // TODO: FIX for multi buffer packet support
			statsInfo.illegalBuffSize = 0;
			statsInfo.controlFrameReceived = 0;
			statsInfo.mdkPktType = 0;

			//just gather simple statistics on the packets received.
			// Increase buffer address for PPM
			if(pLibDev->rx.enablePPM) {
				statsInfo.bufferAddr += PPM_DATA_SIZE;
			}

			//reset our timeout counter
			i = 0;
						
			if (numDesc == pLibDev->rx.numDesc - 1) {
				//This is the final looped rx desc we are done, don't count this one
				printf("Device Number %d:got to looped descriptor\n", devNum);
				done = TRUE;
			}
			//only process packets if things are good
			if ( !(statsInfo.status1 & DESC_MORE) ) {
				if (enableCompare) {
					comparePktData(devNum, &statsInfo);
				}
				if (pLibDev->rx.enablePPM) {
					extractPPM(devNum, &statsInfo);
				}

				if(skipStats && (numStatsToSkip != 0)) {
					numStatsToSkip --;
				}
				else {
					mdkExtractAddrAndSequence(devNum, &statsInfo);
					if(!statsInfo.badPacket) {
						mdkExtractRxStats(devNum, &statsInfo);
						numReceived++;

					}
				}
				if(numReceived == pLibDev->rx.numExpectedPackets) {
					done = TRUE;
				}
			}

			//get next descriptor to process
			statsInfo.descToRead += sizeof(MDK_ATHEROS_DESC);
			numDesc ++;
		}
		else {
			if(i != timeout) {
				curTime = milliTime();
				if (curTime > (startTime+timeout)) {
					i = timeout;
					ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->rxCleanupConfig(devNum);
					continue;
				}
				mSleep(1);
				i++;
			}
			else {
				if(!statsInfo.status2) {
					//timeout and no more descriptors to gather stats from
					done = TRUE;
				}
			}
		}

	} while (!done);
	
	if(remoteStats & ENABLE_STATS_SEND) {
		for( i = 0; i < MAX_TX_QUEUE; i++ )
		{
			for(statsLoop = 1; statsLoop < STATS_BINS; statsLoop++) {
				if((pLibDev->rx.rxStats[i][statsLoop].crcPackets > 0) ||
					(pLibDev->rx.rxStats[i][statsLoop].goodPackets > 0)) {
					sendStatsPkt(devNum, statsLoop, MDK_RX_STATS_PKT, statsInfo.addrPacket.octets);
				}
			}
			sendStatsPkt(devNum, 0, MDK_RX_STATS_PKT, statsInfo.addrPacket.octets);
		}
	}


	//do any other register cleanup required
	if(enableCompare) {
		free(statsInfo.pCompareData);
	}
	return;
}


MANLIB_API A_BOOL rxLastDescStatsSnapshot
(
 A_UINT32 devNum, 
 RX_STATS_SNAPSHOT *pRxStats
)
{
	A_UINT32  compStatus[2];
	LIB_DEV_INFO *pLibDev = gLibInfo.pLibDevArray[devNum];
	A_UINT16  i;

	memset(pRxStats, 0, sizeof(RX_STATS_SNAPSHOT));
	//read the complete status of the last descriptor
	pLibDev->devMap.OSmemRead(devNum, pLibDev->rx.lastDescAddress + FIRST_STATUS_WORD, 
				(A_UCHAR *)&compStatus, 8);

	//extract the stats if the done bit is set
	if(!compStatus[1] & DESC_DONE) {
		//descriptor is not done
		return FALSE;
	}

	//check in case we only got half the status written
	if(!compStatus[0] || !compStatus[1]) {
		//we read an incomplete descriptor
		printf("Device Number %d:SNOOP: read an incomplete descriptor\n", devNum);
		return FALSE;
	}

	if(compStatus[0] & DESC_MORE) {
		//more bit is set, ignore
		printf("Device Number %d:SNOOP: more bit set on descriptor, ignoring\n", devNum);
		return FALSE;
	}

	//read stats
	if(compStatus[1] & DESC_FRM_RCV_OK) {
		pRxStats->goodPackets = 1;

		pRxStats->DataSigStrength = (A_INT8)((compStatus[0] >> pLibDev->bitsToRxSigStrength) & SIG_STRENGTH_MASK);
		pRxStats->dataRate = (A_UINT16)((compStatus[0] >> BITS_TO_RX_DATA_RATE) & pLibDev->rxDataRateMsk);
		//convert the rate
		for(i = 0; i < numRateCodes; i++) {
			if((A_UCHAR)pRxStats->dataRate == rateValues[i]) {
				pRxStats->dataRate = i;
				break;
			}
		}
		pRxStats->bodySize = (A_UINT16)(compStatus[0] & DESC_DATA_LENGTH_FIELDS);

		//remove the 802.11 header, FCS and mdk packet header from this length
		pRxStats->bodySize = pRxStats->bodySize - (sizeof(WLAN_DATA_MAC_HEADER3) + sizeof(MDK_PACKET_HEADER) + FCS_FIELD);
	} 
	else {
		if (compStatus[1] & DESC_CRC_ERR)
		{
			pRxStats->crcPackets = 1;
		}
		else if (compStatus[1] & pLibDev->decryptErrMsk)
		{
			pRxStats->decrypErrors = 1;
		}
		
	}

	//zero out the completion status
	compStatus[0] = 0;
	compStatus[1] = 0;
	pLibDev->devMap.OSmemWrite(devNum, pLibDev->rx.lastDescAddress + FIRST_STATUS_WORD, 
				(A_UCHAR *)&compStatus, 8);

	return TRUE;	


}

////
////
////
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
///////////////////////  RX DATA BEGIN - SPLIT //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////


/**************************************************************************
* txrxDataBegin - Start transmit and reception
*
*/
MANLIB_API void txrxDataBegin
(
 A_UINT32 devNum, 
 A_UINT32 waitTime, 
 A_UINT32 timeout, 
 A_UINT32 remoteStats,
 A_UINT32 enableCompare,
 A_UCHAR *dataPattern, 
 A_UINT32 dataPatternLength
)
{
	ISR_EVENT	event;
	A_UINT32	i, statsLoop;
	A_BOOL		txComplete = FALSE;
	A_BOOL		rxComplete = FALSE;
	LIB_DEV_INFO *pLibDev = gLibInfo.pLibDevArray[devNum];
	A_UINT32	numDesc = 0;
	RX_STATS_TEMP_INFO	rxStatsInfo;
	A_BOOL		statsSent = FALSE;
	A_UINT32 start, finish;
//	A_UINT32	status1, status2;
	A_BOOL		lastPktReceived = FALSE;
	A_BOOL		statsPktReceived = FALSE;
	A_UINT16	queueIndex = pLibDev->selQueueIndex;
	A_UINT32 startTime;
	A_UINT32 curTime;
	A_BOOL		skipStats = FALSE;
	A_UINT16     numStatsToSkip = 0;		

	if (checkDevNum(devNum) == FALSE) {
		mError(devNum, EINVAL, "Device Number %d:txrxDataBegin\n", devNum);
		return;
	}

	if(pLibDev->devState < RESET_STATE) {
		mError(devNum, EILSEQ, "Device Number %d:txrxDataBegin: device not in reset state - resetDevice must be run first\n", devNum);
		return;
	}

	if (!pLibDev->rx.rxEnable || !pLibDev->tx[queueIndex].txEnable) {
		mError(devNum, EILSEQ, 
			"Device Number %d:txrxDataBegin: txDataSetup and rxDataSetup must complete before running txrxDataBegin\n", devNum);
		return; 
	}
	
	//zero out the stats structure
	memset(&(pLibDev->tx[queueIndex].txStats[0]), 0, sizeof(TX_STATS_STRUCT) * STATS_BINS);
	pLibDev->tx[queueIndex].haveStats = 0;
	memset(&(pLibDev->rx.rxStats[0]), 0, sizeof(RX_STATS_STRUCT) * STATS_BINS);
	pLibDev->rx.haveStats = 0;
	if(remoteStats & ENABLE_STATS_RECEIVE) {
		memset(&pLibDev->txRemoteStats[0], 0, sizeof(TX_STATS_STRUCT) * STATS_BINS);	
		memset(&pLibDev->rxRemoteStats[0], 0, sizeof(RX_STATS_STRUCT) * STATS_BINS);	
	}

	// start receive first
	ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->rxBeginConfig(devNum);


	//wait for event
	startTime = milliTime();
	event.valid = 0;
	event.ISRValue = 0;
	for (i = 0; i < waitTime; i++)
	{
		event = pLibDev->devMap.getISREvent(devNum);
		if (event.valid) {
			if(ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->isRxdescEvent(event.ISRValue)) {
				break;
			}
		}
		curTime = milliTime();
		if (curTime > (startTime+waitTime)) {
			i = waitTime;
			break;
		}
		mSleep(1);		
	}
	
	
	if ((i == waitTime) && (waitTime !=0)) {
		mError(devNum, EIO, "Device Number %d:txrxDataBegin: nothing received within %d millisecs (waitTime)\n", devNum, waitTime);
		ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->rxCleanupConfig(devNum);
		return;
	}

	i = 0;
	memset(&rxStatsInfo, 0, sizeof(RX_STATS_TEMP_INFO));

	if(remoteStats & SKIP_SOME_STATS) {
		//extract and set number to skip
		skipStats = 1;
		numStatsToSkip = (A_UINT16)((remoteStats & NUM_TO_SKIP_M) >> NUM_TO_SKIP_S);
	}

	for(statsLoop = 0; statsLoop < STATS_BINS; statsLoop++) {
		rxStatsInfo.sigStrength[statsLoop].rxMinSigStrength = 127;
	}

	if(pLibDev->rx.enablePPM) {
		for( i = 0; i < MAX_TX_QUEUE; i++ )
		{
			for(statsLoop = 0; statsLoop < STATS_BINS; statsLoop++) {
				pLibDev->rx.rxStats[i][statsLoop].ppmMax = -1000;
				pLibDev->rx.rxStats[i][statsLoop].ppmMin = 1000;
			}
		}
	}

⌨️ 快捷键说明

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