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

📄 dk_client.c

📁 Atheros AP Test with Agilent N4010A source code
💻 C
📖 第 1 页 / 共 5 页
字号:
    if(hwMemReadBlock(dkThread->currentDevIndex, replyBuf, pCmd->CMD_U.MEM_READ_BLOCK_CMD.physAddr, 
				  pCmd->CMD_U.MEM_READ_BLOCK_CMD.length) == -1)
        {
        uiPrintf("Failed call to hwMemReadBlock()\n");
        return(COMMS_ERR_READ_BLOCK_FAIL);
        }

#ifdef PREDATOR // Just to avoid mac endian register programming
// Currently this functions reads the byte array starting from the
// phyaddr, therefore endianness free


// Swap from big endian to little endian.
#ifdef ENDIAN_SWAP
{
    int noWords;
    int i;
    A_UINT32 *wordPtr;

    noWords =   pCmd->CMD_U.MEM_READ_BLOCK_CMD.length/sizeof(A_UINT32);
    wordPtr = (A_UINT32 *)replyBuf;
    for (i=0;i<noWords;i++)
    {
    	*(wordPtr + i) = ltob_l(*(wordPtr + i));
    }
}
#endif

#endif

    return(0);
    }

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

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

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


	/* check the size , but need to access the structure to do it */
    if( pCmd->cmdLen != sizeof(pCmd->cmdID) + sizeof(pCmd->devNum) + sizeof(pCmd->CMD_U.MEM_WRITE_BLOCK_CMD.physAddr) +
		sizeof(pCmd->CMD_U.MEM_WRITE_BLOCK_CMD.length) + pCmd->CMD_U.MEM_WRITE_BLOCK_CMD.length ) 
        {
        uiPrintf("Error: command Len is not equal to size of expected bytes for MEM_WRITE_BLOCK_CMD\n");
		uiPrintf("     : got %d, expected %d\n", pCmd->cmdLen, sizeof(pCmd->cmdID) +
			sizeof(pCmd->CMD_U.MEM_WRITE_BLOCK_CMD.physAddr) +
			sizeof(pCmd->CMD_U.MEM_WRITE_BLOCK_CMD.length) + pCmd->CMD_U.MEM_WRITE_BLOCK_CMD.length);
        return(COMMS_ERR_BAD_LENGTH);
        }

#ifdef PREDATOR // Just to avoid mac endian register programming
// Currently this functions writes the byte array starting from the
// phyaddr, therefore endianness free


// swap from little endian to big endian
#ifdef ENDIAN_SWAP
{
    int noWords;
    int i;
    A_UINT32 *wordPtr;

    noWords =   pCmd->CMD_U.MEM_WRITE_BLOCK_CMD.length/sizeof(A_UINT32);
    wordPtr = (A_UINT32 *)pCmd->CMD_U.MEM_WRITE_BLOCK_CMD.bytes;
    for (i=0;i<noWords;i++)
    {
    	*(wordPtr + i) = ltob_l(*(wordPtr + i));
    }
}
#endif

#endif

 
    /* write the memory */
    if(hwMemWriteBlock(dkThread->currentDevIndex,pCmd->CMD_U.MEM_WRITE_BLOCK_CMD.bytes, 
				   pCmd->CMD_U.MEM_WRITE_BLOCK_CMD.length, 
				   &(pCmd->CMD_U.MEM_WRITE_BLOCK_CMD.physAddr)) == -1)
        {
        uiPrintf("Failed call to hwMemWriteBlock()\n");
        return(COMMS_ERR_WRITE_BLOCK_FAIL);
        }
    /* copy the address into the return buffer */
    *(A_UINT32 *)replyBuf = pCmd->CMD_U.MEM_WRITE_BLOCK_CMD.physAddr;

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

    return(0);
}


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

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

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

#ifdef ENDIAN_SWAP
	pCmd->CMD_U.CREATE_EVENT_CMD.type = ltob_l(pCmd->CMD_U.CREATE_EVENT_CMD.type);
	pCmd->CMD_U.CREATE_EVENT_CMD.persistent = ltob_l(pCmd->CMD_U.CREATE_EVENT_CMD.persistent);
	pCmd->CMD_U.CREATE_EVENT_CMD.param1 = ltob_l(pCmd->CMD_U.CREATE_EVENT_CMD.param1);
	pCmd->CMD_U.CREATE_EVENT_CMD.param2 = ltob_l(pCmd->CMD_U.CREATE_EVENT_CMD.param2);
	pCmd->CMD_U.CREATE_EVENT_CMD.param3 = ltob_l(pCmd->CMD_U.CREATE_EVENT_CMD.param3);
	pCmd->CMD_U.CREATE_EVENT_CMD.eventHandle.eventID = ltob_s(pCmd->CMD_U.CREATE_EVENT_CMD.eventHandle.eventID);
	pCmd->CMD_U.CREATE_EVENT_CMD.eventHandle.f2Handle = ltob_s(pCmd->CMD_U.CREATE_EVENT_CMD.eventHandle.f2Handle);	
#endif        

	  if(hwCreateEvent(dkThread->currentDevIndex,pCmd) == -1)
        {
        uiPrintf("Error:  unable to Create event\n");
        return(COMMS_ERR_EVENT_CREATE_FAIL);
        }
    return(0);
    }

/**************************************************************************
* processGetEventCmd - Process GET_EVENT_CMD command
*
* Get the first event from the triggered Q
*
* RETURNS: 0 processed OK, an Error code if it is not
*/
A_UINT32 processGetEventCmd
(
	struct dkThreadInfo *dkThread
)
{
	PIPE_CMD      *pCmd;
	CMD_REPLY     *ReplyCmd_p;
	A_UCHAR     *replyBuf;
	MDK_WLAN_DEV_INFO    *pdevInfo;
	EVENT_STRUCT  *evt;


	pCmd = dkThread->PipeBuffer_p;
	ReplyCmd_p = dkThread->ReplyCmd_p;
	replyBuf = (A_UCHAR *)(ReplyCmd_p->cmdBytes);
	pdevInfo = globDrvInfo.pDevInfoArray[dkThread->currentDevIndex];

    // check that the size is appropriate before we access
    if( pCmd->cmdLen != (sizeof(pCmd->cmdID) + sizeof(pCmd->devNum))) {
        uiPrintf("Error, command Len is not correct for GET_EVENT_CMD\n");
        return(COMMS_ERR_BAD_LENGTH);
    }

#ifdef JUNGO
    // Check if the Q has an event.  Set type to 0 if no events...
    if(!(pdevInfo->pdkInfo->pSharedInfo->anyEvents)) {
		((EVENT_STRUCT *)replyBuf)->type = 0;
    } else {
		//call into the kernel plugin to get the event, event will get
		//copied straight into replyBuf
		if(hwGetNextEvent(dkThread->currentDevIndex,(void *)replyBuf) == -1) {
			uiPrintf("Error: Unable to get event from kernel plugin\n");
			return(COMMS_ERR_NO_EVENTS);
		}
	}
#else
	((EVENT_STRUCT *)replyBuf)->type = 0;
	if (hwGetNextEvent(dkThread->currentDevIndex,(void *)replyBuf) == -1) {
			uiPrintf("Error: Unable to get event from kernel plugin\n");
			return(COMMS_ERR_NO_EVENTS);
	}
#endif

#ifdef ENDIAN_SWAP
    	((EVENT_STRUCT *)replyBuf)->type  = btol_l(((EVENT_STRUCT *)replyBuf)->type);
	((EVENT_STRUCT *)replyBuf)->result  = btol_l(((EVENT_STRUCT *)replyBuf)->result);
	((EVENT_STRUCT *)replyBuf)->eventHandle.eventID  = btol_s(((EVENT_STRUCT *)replyBuf)->eventHandle.eventID);
	((EVENT_STRUCT *)replyBuf)->eventHandle.f2Handle = btol_s(((EVENT_STRUCT *)replyBuf)->eventHandle.f2Handle);;
#endif

evt = (EVENT_STRUCT *)replyBuf;

    return(0);
}

A_UINT32 processCloseDeviceCmd
(
	struct dkThreadInfo *dkThread
)
{
	PIPE_CMD      *pCmd;
	CMD_REPLY     *ReplyCmd_p;
	A_UCHAR     *replyBuf;
	A_UINT16     devIndex;

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

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

#if defined(THIN_CLIENT_BUILD)
	devIndex = dkThread->currentDevIndex;

    // Close low level structs for this device
	if (devIndex != (A_UINT16)-1) {
  		deviceCleanup(devIndex);
	}
#else
	devIndex = m_closeDevice(pCmd->devNum);
#endif

	
	semLock(sem);
	removeClientFromThread(dkThread, devIndex);
	semUnLock(sem);
    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;
	CMD_REPLY     *ReplyCmd_p;
	A_UCHAR     *replyBuf;
#if defined(THIN_CLIENT_BUILD)
    A_UINT32    eepromValue, eepromOffset;
#endif

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

	/* check that the size is appropriate before we access */
     	if( pCmd->cmdLen != sizeof(pCmd->CMD_U.EEPROM_READ_CMD)+sizeof(pCmd->cmdID) + sizeof(pCmd->devNum)) 
        {
        	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.offset = ltob_l(pCmd->CMD_U.EEPROM_READ_CMD.offset);
	#endif

#if defined(THIN_CLIENT_BUILD)
#if defined(SPIRIT_AP) || defined(FREEDOM_AP) // || defined(PREDATOR)
    //  16 bit addressing 
    eepromOffset = pCmd->CMD_U.EEPROM_READ_CMD.offset << 1;
    eepromValue = (sysFlashConfigRead(FLC_RADIOCFG, eepromOffset) << 8) | sysFlashConfigRead(FLC_RADIOCFG, (eepromOffset + 1));
    *((A_UINT32 *)replyBuf) = eepromValue;
#else

#if defined(PREDATOR)
	if ( pCmd->CMD_U.EEPROM_READ_CMD.offset & 0x10000000)  {
    	eepromOffset = (pCmd->CMD_U.EEPROM_READ_CMD.offset & 0x7fffffff) + AR5523_FLASH_ADDRESS;
		eepromValue = apRegRead32(eepromOffset);
       	*((A_UINT32 *)replyBuf) = eepromValue;
	}
	else  {
    	eepromOffset = (pCmd->CMD_U.EEPROM_READ_CMD.offset<<1) + AR5523_FLASH_ADDRESS + cal_offset;
		eepromValue = apRegRead32(eepromOffset);
		if (eepromOffset & 0x2)
       		*((A_UINT32 *)replyBuf) = ((eepromValue >> 16) & 0xffff);
		else
       		*((A_UINT32 *)replyBuf) = (eepromValue & 0xffff);
	}
#endif

#if defined(PHOENIX)
	if ( pCmd->CMD_U.EEPROM_READ_CMD.offset & 0x10000000)  {
    	eepromOffset = (pCmd->CMD_U.EEPROM_READ_CMD.offset & 0x7fffffff);
		eepromValue = sysFlashConfigRead(FLC_BOOTLINE, eepromOffset);
       	*((A_UINT32 *)replyBuf) = eepromValue;
	}
	else  {
    	eepromOffset = (pCmd->CMD_U.EEPROM_READ_CMD.offset<<1);
//		eepromValue = sysFlashConfigRead(FLC_RADIOCFG, eepromOffset);
        eepromValue = sysFlashConfigRead(FLC_RADIOCFG, eepromOffset)  | (sysFlashConfigRead(FLC_RADIOCFG, (eepromOffset + 1)) << 8);
	/*	if (eepromOffset & 0x2)
       		*((A_UINT32 *)replyBuf) = ((eepromValue >> 16) & 0xffff);
		else
       		*((A_UINT32 *)replyBuf) = (eepromValue & 0xffff);
    */
        *((A_UINT32 *)replyBuf) = eepromValue & 0xffff;
	}
#endif
    //eepromValue = sysFlashRead(eepromOffset); // We call apRegRead32 as
							// we get an exception for the ecos generated code 

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

#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;
	CMD_REPLY     *ReplyCmd_p;
	A_UCHAR     *replyBuf;
    A_UINT32	 status=0;
#if defined(THIN_CLIENT_BUILD)
    A_UINT32    eepromValue, eepromOffset;
    A_UINT8 *pVal;
    A_UINT16 *pVal16;
#endif

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

	/* check that the size is appropriate before we access */
     	if( pCmd->cmdLen != sizeof(pCmd->CMD_U.EEPROM_WRITE_CMD)+sizeof(pCmd->cmdID) + sizeof(pCmd->devNum)) 
        {
        	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.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


#if defined(THIN_CLIENT_BUILD)
        pVal = (A_UINT8 *)&(pCmd->CMD_U.EEPROM_WRITE_CMD.value);

#if defined(SPIRIT_AP) || defined(FREEDOM_AP) // || defined(PREDATOR)
        sysFlashConfigWrite(FLC_RADIOCFG, pCmd->CMD_U.EEPROM_WRITE_CMD.offset << 1, (pVal+2) , 2);
#else

//		uiPrintf("********** SNOOP:pVal=%x:*pVal=%d:value=%x\n", pVal, *((A_UINT32*)pVal), pCmd->CMD_U.EEPROM_WRITE_CMD.value);

#if defined (PHOENIX)
		if ( pCmd->CMD_U.EEPROM_WRITE_CMD.offset & 0x10000000) 
           status = sysFlashConfigWrite(FLC_BOOTLINE, pCmd->CMD_U.EEPROM_WRITE_CMD.offset << 1, (pVal+2) , 2);
		else
           status = sysFlashConfigWrite(FLC_RADIOCFG, pCmd->CMD_U.EEPROM_WRITE_CMD.offset<<1, (pVal) , 2);
#endif
#if defined (PREDATOR)
           status = sysFlashConfigWrite(pCmd->CMD_U.EEPROM_WRITE_CMD.offset<<1, pVal+2 , 2);
#endif

#endif

#else // THIN_CLIENT_BUILD

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

#endif // THIN_CLIENT_BUILD

    	return status;

}

A_UINT32 processHwReset( struct dkThreadInfo *dkThread) {
	PIPE_CMD      *pCmd;
	CMD_REPLY     *ReplyCmd_p;
	A_UCHAR     *replyBuf;
	MDK_WLAN_DEV_INFO    *pdevInfo;
	A_UINT16 expCmdLen;

	pCmd = dkThread->PipeBuffer_p;
	ReplyCmd_p = dkThread->ReplyCmd_p;
	replyBuf = (A_UCHAR *)(ReplyCmd_p->cmdBytes);
    
	expCmdLen = sizeof(pCmd->CMD_U.HW_RESET_CMD)+sizeof(pCmd->cmdID) + sizeof(pCmd->devNum);
    /* check that the size is appropriate before we access */
    if( pCmd->cmdLen != expCmdLen)

⌨️ 快捷键说明

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