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

📄 dk_client.c

📁 atheros ar5001 5002 driver
💻 C
📖 第 1 页 / 共 5 页
字号:
	struct dkThreadInfo *dkThread
)
{
	PIPE_CMD      *pCmd;
	A_UINT32       cmdLen;        
	CMD_REPLY     *ReplyCmd_p;
	A_UCHAR     *replyBuf;

	pCmd = dkThread->PipeBuffer_p;
	cmdLen = pCmd->cmdLen;
	ReplyCmd_p = dkThread->ReplyCmd_p;
	replyBuf = (A_UCHAR *)(ReplyCmd_p->cmdBytes);

    /* check that the size is appropriate before we access */
	if( cmdLen != sizeof(pCmd->CMD_U.ISR_FEATURE_DISABLE_CMD)+sizeof(pCmd->cmdID) ) 
        {
        uiPrintf("Error, command Len is not equal to size of ISR_FEATURE_DISABLE_CMD\n");
        return(COMMS_ERR_BAD_LENGTH);
        }

	if(hwDisableFeature(dkThread->currentDevIndex,pCmd) == -1)
		{
		uiPrintf("Error:  unable to disable feature\n");
		return(COMMS_ERR_EVENT_DISABLE_FEATURE_FAIL);
	    }

	return(0);
	}

/**************************************************************************
* processIsrGetRxStatsCmd - Process ISR_GET_RX_STATS_CMD command
*
* RETURNS: 0 processed OK, an Error code if it is not
*/
A_UINT32 processIsrGetRxStatsCmd
(
	struct dkThreadInfo *dkThread
)
{
	PIPE_CMD      *pCmd;
	A_UINT32       cmdLen;        
	CMD_REPLY     *ReplyCmd_p;
	A_UCHAR     *replyBuf;

	pCmd = dkThread->PipeBuffer_p;
	cmdLen = pCmd->cmdLen;
	ReplyCmd_p = dkThread->ReplyCmd_p;
	replyBuf = (A_UCHAR *)(ReplyCmd_p->cmdBytes);

    /* check that the size is appropriate before we access */
	if( cmdLen != sizeof(pCmd->CMD_U.ISR_GET_STATS_CMD)+sizeof(pCmd->cmdID) ) 
        {
        uiPrintf("Error, command Len is not equal to size of ISR_GET_STATS_CMD\n");
        return(COMMS_ERR_BAD_LENGTH);
        }

	hwGetStats(dkThread->currentDevIndex,pCmd->CMD_U.ISR_GET_STATS_CMD.clearOnRead, replyBuf, TRUE);
	return(0);
	}

/**************************************************************************
* processIsrGettxStatsCmd - Process ISR_GET_TX_STATS_CMD command
*
* RETURNS: 0 processed OK, an Error code if it is not
*/
A_UINT32 processIsrGetTxStatsCmd
(
	struct dkThreadInfo *dkThread
)
{
	PIPE_CMD      *pCmd;
	A_UINT32       cmdLen;        
	CMD_REPLY     *ReplyCmd_p;
	A_UCHAR     *replyBuf;

	pCmd = dkThread->PipeBuffer_p;
	cmdLen = pCmd->cmdLen;
	ReplyCmd_p = dkThread->ReplyCmd_p;
	replyBuf = (A_UCHAR *)(ReplyCmd_p->cmdBytes);

	/* check that the size is appropriate before we access */
    if( cmdLen != sizeof(pCmd->CMD_U.ISR_GET_STATS_CMD)+sizeof(pCmd->cmdID) ) 
        {
        uiPrintf("Error, command Len is not equal to size of ISR_GET_STATS_CMD\n");
        return(COMMS_ERR_BAD_LENGTH);
        }

	hwGetStats(dkThread->currentDevIndex,pCmd->CMD_U.ISR_GET_STATS_CMD.clearOnRead, replyBuf, FALSE);
	return(0);
	}

/**************************************************************************
* processIsrSingleRxStatCmd - Process ISR_SINGLE_RX_STAT_CMD command
*
* RETURNS: 0 processed OK, an Error code if it is not
*/
A_UINT32 processIsrSingleRxStatCmd
(
	struct dkThreadInfo *dkThread
)
{
	PIPE_CMD      *pCmd;
	A_UINT32       cmdLen;        
	CMD_REPLY     *ReplyCmd_p;
	A_UCHAR     *replyBuf;

	pCmd = dkThread->PipeBuffer_p;
	cmdLen = pCmd->cmdLen;
	ReplyCmd_p = dkThread->ReplyCmd_p;
	replyBuf = (A_UCHAR *)(ReplyCmd_p->cmdBytes);

	/* check that the size is appropriate before we access */
    if( cmdLen != sizeof(pCmd->CMD_U.ISR_SINGLE_STAT_CMD)+sizeof(pCmd->cmdID) ) 
        {
        uiPrintf("Error, command Len is not equal to size of ISR_SINGLE_STAT_CMD\n");
        return(COMMS_ERR_BAD_LENGTH);
        }

	hwGetSingleStat(dkThread->currentDevIndex,pCmd->CMD_U.ISR_SINGLE_STAT_CMD.statID, 
					pCmd->CMD_U.ISR_SINGLE_STAT_CMD.clearOnRead, replyBuf, TRUE);
	return(0);
}

/**************************************************************************
* processIsrSingleTxStatCmd - Process ISR_SINGLE_TX_STAT_CMD command
*
* 
*
* RETURNS: 0 processed OK, an Error code if it is not
*/
A_UINT32 processIsrSingleTxStatCmd
(
	struct dkThreadInfo *dkThread
)
{
	PIPE_CMD      *pCmd;
	A_UINT32       cmdLen;        
	CMD_REPLY     *ReplyCmd_p;
	A_UCHAR     *replyBuf;

	pCmd = dkThread->PipeBuffer_p;
	cmdLen = pCmd->cmdLen;
	ReplyCmd_p = dkThread->ReplyCmd_p;
	replyBuf = (A_UCHAR *)(ReplyCmd_p->cmdBytes);

	/* check that the size is appropriate before we access */
     	if( cmdLen != sizeof(pCmd->CMD_U.ISR_SINGLE_STAT_CMD)+sizeof(pCmd->cmdID) ) 
        {
        uiPrintf("Error, command Len is not equal to size of ISR_SINGLE_STAT_CMD\n");
        return(COMMS_ERR_BAD_LENGTH);
        }

	hwGetSingleStat(dkThread->currentDevIndex,pCmd->CMD_U.ISR_SINGLE_STAT_CMD.statID, 
					pCmd->CMD_U.ISR_SINGLE_STAT_CMD.clearOnRead, replyBuf, FALSE);
	return(0);
}


/**************************************************************************
* eepromRead - Read from given EEPROM offset and return the 16 bit value
*
* RETURNS: 16 bit value from given offset (in a 32-bit value)
*/
A_UINT32 processEepromReadCmd
(
	struct dkThreadInfo *dkThread
)
{
	PIPE_CMD      *pCmd;
	A_UINT32       cmdLen;        
	CMD_REPLY     *ReplyCmd_p;
	A_UCHAR     *replyBuf;

	pCmd = dkThread->PipeBuffer_p;
	cmdLen = pCmd->cmdLen;
	ReplyCmd_p = dkThread->ReplyCmd_p;
	replyBuf = (A_UCHAR *)(ReplyCmd_p->cmdBytes);

	/* check that the size is appropriate before we access */
     	if( cmdLen != sizeof(pCmd->CMD_U.EEPROM_READ_CMD)+sizeof(pCmd->cmdID) ) 
        {
        	uiPrintf("Error, command Len is not equal to size of EEPROM_READ_CMD\n");
        	return(COMMS_ERR_BAD_LENGTH);
        }

	#ifdef ENDIAN_SWAP
     		pCmd->CMD_U.EEPROM_READ_CMD.devNum = ltob_l(pCmd->CMD_U.EEPROM_READ_CMD.devNum);
     		pCmd->CMD_U.EEPROM_READ_CMD.offset = ltob_l(pCmd->CMD_U.EEPROM_READ_CMD.offset);
	#endif


    /* read the eeprom */
    *((A_UINT32 *)replyBuf) = m_eepromRead(pCmd->CMD_U.EEPROM_READ_CMD.devNum,pCmd->CMD_U.EEPROM_READ_CMD.offset); 

#ifdef ENDIAN_SWAP
    *((A_UINT32 *)replyBuf) = btol_l(*((A_UINT32 *)replyBuf));
#endif
	
	return 0;

}

/**************************************************************************
* eepromWrite - Write to given EEPROM offset
*
*/

A_UINT32 processEepromWriteCmd
(
	struct dkThreadInfo *dkThread
)
{
	PIPE_CMD      *pCmd;
	A_UINT32       cmdLen;        
	CMD_REPLY     *ReplyCmd_p;
	A_UCHAR     *replyBuf;

	pCmd = dkThread->PipeBuffer_p;
	cmdLen = pCmd->cmdLen;
	ReplyCmd_p = dkThread->ReplyCmd_p;
	replyBuf = (A_UCHAR *)(ReplyCmd_p->cmdBytes);

	/* check that the size is appropriate before we access */
     	if( cmdLen != sizeof(pCmd->CMD_U.EEPROM_WRITE_CMD)+sizeof(pCmd->cmdID) ) 
        {
        	uiPrintf("Error, command Len is not equal to size of EEPROM_WRITE_CMD\n");
        	return(COMMS_ERR_BAD_LENGTH);
        }

	#ifdef ENDIAN_SWAP
     		pCmd->CMD_U.EEPROM_WRITE_CMD.devNum = ltob_l(pCmd->CMD_U.EEPROM_WRITE_CMD.devNum);
     		pCmd->CMD_U.EEPROM_WRITE_CMD.offset = ltob_l(pCmd->CMD_U.EEPROM_WRITE_CMD.offset);
     		pCmd->CMD_U.EEPROM_WRITE_CMD.value  = ltob_l(pCmd->CMD_U.EEPROM_WRITE_CMD.value);
	#endif


    	/* write the eeprom */
    	m_eepromWrite(pCmd->CMD_U.EEPROM_WRITE_CMD.devNum,pCmd->CMD_U.EEPROM_WRITE_CMD.offset,
		      pCmd->CMD_U.EEPROM_WRITE_CMD.value); 

    	return 0;

}

/**************************************************************************
* eepromRead - Read from given EEPROM offset and return the 16 bit value
*/

A_UINT32 processEepromReadBlockCmd
(
	struct dkThreadInfo *dkThread
)
{
	PIPE_CMD      *pCmd;
	A_UINT32       cmdLen;        
	CMD_REPLY     *ReplyCmd_p;
	A_UCHAR     *replyBuf;
	PDWORDBUFFER pDwordBuffer;
	A_UINT32 *pDword;
	A_UINT32 i;

	pCmd = dkThread->PipeBuffer_p;
	cmdLen = pCmd->cmdLen;
	ReplyCmd_p = dkThread->ReplyCmd_p;
	replyBuf = (A_UCHAR *)(ReplyCmd_p->cmdBytes);

	/* check that the size is appropriate before we access */
     	if( cmdLen != sizeof(pCmd->CMD_U.EEPROM_READ_BLOCK_CMD)+sizeof(pCmd->cmdID) ) 
        {
        	uiPrintf("Error, command Len is not equal to size of EEPROM_READ_BLOCK_CMD\n");
        	return(COMMS_ERR_BAD_LENGTH);
        }

	#ifdef ENDIAN_SWAP
     		pCmd->CMD_U.EEPROM_READ_BLOCK_CMD.devNum = ltob_l(pCmd->CMD_U.EEPROM_READ_BLOCK_CMD.devNum);
     		pCmd->CMD_U.EEPROM_READ_BLOCK_CMD.startOffset = ltob_l(pCmd->CMD_U.EEPROM_READ_BLOCK_CMD.startOffset);
     		pCmd->CMD_U.EEPROM_READ_BLOCK_CMD.length = ltob_l(pCmd->CMD_U.EEPROM_READ_BLOCK_CMD.length);
	#endif

	pDwordBuffer = m_eepromReadBlock(pCmd->CMD_U.EEPROM_READ_BLOCK_CMD.devNum,
					 pCmd->CMD_U.EEPROM_READ_BLOCK_CMD.startOffset,
					 pCmd->CMD_U.EEPROM_READ_BLOCK_CMD.length);

	pDword = (A_UINT32 *)replyBuf;	

	if (pDwordBuffer != NULL)
	{
		for (i=0;i<pCmd->CMD_U.EEPROM_READ_BLOCK_CMD.length;i++)
		{
			#ifdef ENDIAN_SWAP
	  	  		pDword[i] = btol_l(pDwordBuffer->pDword[i]);
			#else
				pDword[i] = pDwordBuffer->pDword[i];
			#endif
		}
		A_FREE(pDwordBuffer->pDword);
		A_FREE(pDwordBuffer);
	}
	return 0;
}


/**************************************************************************
*/

A_UINT32 processEepromWriteBlockCmd
(
	struct dkThreadInfo *dkThread
)
{
	PIPE_CMD      *pCmd;
	A_UINT32       cmdLen;        
	CMD_REPLY     *ReplyCmd_p;
	A_UCHAR     *replyBuf;
	PDWORDBUFFER pDwordBuffer;
	A_UINT32 i;

	pCmd = dkThread->PipeBuffer_p;
	cmdLen = pCmd->cmdLen;
	ReplyCmd_p = dkThread->ReplyCmd_p;
	replyBuf = (A_UCHAR *)(ReplyCmd_p->cmdBytes);

	#ifdef ENDIAN_SWAP
     		pCmd->CMD_U.EEPROM_WRITE_BLOCK_CMD.length = ltob_l(pCmd->CMD_U.EEPROM_WRITE_BLOCK_CMD.length); 
	#endif


    	if( cmdLen != (sizeof(pCmd->cmdID) + 
		       sizeof(pCmd->CMD_U.EEPROM_WRITE_BLOCK_CMD)-
		       ((MAX_BLOCK_DWORDS - pCmd->CMD_U.EEPROM_WRITE_BLOCK_CMD.length) * 4)))

        {
        	uiPrintf("Error: command Len is not equal to size of expected bytes for EEPROM_WRITE_BLOCK_CMD\n");
		uiPrintf(": got %d, expected %d\n", cmdLen, (sizeof(pCmd->cmdID) + sizeof(pCmd->CMD_U.EEPROM_WRITE_BLOCK_CMD)
				- ((MAX_BLOCK_DWORDS - pCmd->CMD_U.EEPROM_WRITE_BLOCK_CMD.length) * 4)));
        	return(COMMS_ERR_BAD_LENGTH);
        }


	#ifdef ENDIAN_SWAP
     		pCmd->CMD_U.EEPROM_WRITE_BLOCK_CMD.devNum = ltob_l(pCmd->CMD_U.EEPROM_WRITE_BLOCK_CMD.devNum);
     		pCmd->CMD_U.EEPROM_WRITE_BLOCK_CMD.startOffset = ltob_l(pCmd->CMD_U.EEPROM_WRITE_BLOCK_CMD.startOffset);
	

	#endif

	pDwordBuffer = (PDWORDBUFFER)A_MALLOC(sizeof(PDWORDBUFFER));
	if (pDwordBuffer == NULL)
	{
		uiPrintf("Error, unable to allocate memory for mac PDWORDBUFFER struct \n");
		return (COMMS_ERR_ALLOC_FAIL);	
	}
	pDwordBuffer->Length = (A_UINT16)pCmd->CMD_U.EEPROM_WRITE_BLOCK_CMD.length * 4;

	pDwordBuffer->pDword = (A_UINT32 *)A_MALLOC(pDwordBuffer->Length);
	if (pDwordBuffer->pDword == NULL)
	{
		A_FREE(pDwordBuffer);
		uiPrintf("Error, unable to allocate memory for mac array \n");
		return (COMMS_ERR_ALLOC_FAIL);	
	}
	

	for (i=0;i<pCmd->CMD_U.EEPROM_WRITE_BLOCK_CMD.length;i++)
	{
		#ifdef ENDIAN_SWAP
			pDwordBuffer->pDword[i] = ltob_l(pCmd->CMD_U.EEPROM_WRITE_BLOCK_CMD.eepromValue[i]); 
		#else
			pDwordBuffer->pDword[i] = pCmd->CMD_U.EEPROM_WRITE_BLOCK_CMD.eepromValue[i];
		#endif
	}

    	/* write the eeprom */
    	m_eepromWriteBlock(pCmd->CMD_U.EEPROM_WRITE_BLOCK_CMD.devNum,
			   pCmd->CMD_U.EEPROM_WRITE_BLOCK_CMD.startOffset,
			   pDwordBuffer); 

	A_FREE(pDwordBuffer->pDword);
	A_FREE(pDwordBuffer);

    	return 0;

}

/**************************************************************************
* resetDevice - reset the device and initialize all registers
*
*/

A_UINT32 processResetDeviceCmd
(
	struct dkThreadInfo *dkThread
)
{
	PIPE_CMD      *pCmd;
	A_UINT32       cmdLen;        
	CMD_REPLY     *ReplyCmd_p;
	A_UCHAR     *replyBuf;
	PDATABUFFER mac;
	PDATABUFFER bss;

	pCmd = dkThread->PipeBuffer_p;
	cmdLen = pCmd->cmdLen;
	ReplyCmd_p = dkThread->ReplyCmd_p;
	replyBuf = (A_UCHAR *)(ReplyCmd_p->cmdBytes);

	/* check that the size is appropriate before we access */
     	if( cmdLen != sizeof(pCmd->CMD_U.RESET_DEVICE_CMD)+sizeof(pCmd->cmdID) ) 
        {
        	uiPrintf("Error, command Len is not equal to size of RESET_DEVICE_CMD\n");
        	return(COMMS_ERR_BAD_LENGTH);
        }

	#ifdef ENDIAN_SWAP
     		pCmd->CMD_U.RESET_DEVICE_CMD.devNum = ltob_l(pCmd->CMD_U.RESET_DEVICE_CMD.devNum);
     		pCmd->CMD_U.RESET_DEVICE_CMD.freq = ltob_l(pCmd->CMD_U.RESET_DEVICE_CMD.freq);
     		pCmd->CMD_U.RESET_DEVICE_CMD.turbo  = ltob_l(pCmd->CMD_U.RESET_DEVICE_CMD.turbo);
	#endif

	mac = (PDATABUFFER)A_MALLOC(sizeof(PDATABUFFER));
	if (mac == NULL)
	{
		uiPrintf("Error, unable to allocate memory for mac PDATABUFFER struct \n");
		return (COMMS_ERR_ALLOC_FAIL);	
	}
	mac->Length = 6;
	mac->pData = (A_UCHAR *)A_MALLOC(mac->Length);
	if (mac->pData == NULL)
	{
		A_FREE(mac);
		uiPrintf("Error, unable to allocate memory for mac array \n");
		return (COMMS_ERR_ALLOC_FAIL);	
	}
	memcpy(mac->pData,pCmd->CMD_U.RESET_DEVICE_CMD.mac,mac->Length);

	bss = (PDATABUFFER)A_MALLOC(sizeof(PDATABUFFER));
	if (bss == NULL)
	{
		A_FREE(mac->pData);
		A_FREE(mac);
		uiPrintf("Error, unable to allocate memory for bss PDATABUFFER struct \n");

⌨️ 快捷键说明

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