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

📄 art_if.c

📁 atheros ar5001 5002 driver
💻 C
📖 第 1 页 / 共 5 页
字号:
	GlobalCmd.CMD_U.GENERIC_CMD.intVar1 = intVar1;
	GlobalCmd.CMD_U.GENERIC_CMD.intVar2 = intVar2;
	GlobalCmd.CMD_U.GENERIC_CMD.intVar3 = intVar3;


	if(!artSendCmd(&GlobalCmd,
			(sizeof(GlobalCmd.CMD_U.GENERIC_CMD) + sizeof(GlobalCmd.cmdID) - (MAX_GENERIC_CMD_LEN - stringVarLength)),
			NULL)) {
		uiPrintf("Error: Unable to successfully send GENERIC_CMD command\n");
		return 0;
	}

	if(checkLibError(devNum, 1)) {
		return 0;
	}
	return 1;
}

void art_supplyFalseDetectbackoff
(
	A_UINT32 devNum,
	A_UINT32 *pBackoffValues
)
{
	if (!configSetup.remote)
	{
		supplyFalseDetectbackoff(devNum, pBackoffValues);
	} 
	else 
	{
		// create cmd to send to client
		GlobalCmd.cmdID = M_FALSE_DETECT_BACKOFF_VALS_CMD_ID;
		GlobalCmd.CMD_U.FALSE_DETECT_BACKOFF_VALS_CMD.devNum = devNum;
		memcpy((void *)GlobalCmd.CMD_U.FALSE_DETECT_BACKOFF_VALS_CMD.backoffValues,(void *)pBackoffValues,sizeof(A_UINT32)*3);

		if ( !artSendCmd(&GlobalCmd,
						sizeof(GlobalCmd.CMD_U.FALSE_DETECT_BACKOFF_VALS_CMD)+sizeof(GlobalCmd.cmdID),
						NULL)) 
		{
			uiPrintf("Error: Unable to successfully send FALSE_DETECT_BACKOFF_VALS_CMD command to client!\n");
		}
	}
	checkLibError(devNum, 1);
	return;
}

#ifndef __ATH_DJGPPDOS__
/**************************************************************************
* openCommsChannel - Open a comms channel to the specified system
*
* Look to see if a pipe is already open to that F2, if so return the os
* structure for that existing pipe.  If pipe is not already open then try to
* open one and create an os structure for that pipe
*
* RETURNS: NULL on ERROR
*/
ART_SOCK_INFO *openCommsChannel
    (
    A_CHAR	    *machineName
    )
{
    ART_SOCK_INFO   *sockInfo;

    if (machineName == NULL) {
		uiPrintf("Error: invalid machine name (NULL) in openCommsChannel\n");
		return NULL;
    }
   
    sockInfo = osSockConnect(machineName);
    if ( !sockInfo ) {
		uiPrintf("Error:  Unable to connect to %s in openCommsChannel()\n",machineName);
		A_FREE(artSockInfo);
		return NULL;
    }

    return sockInfo;
}


/**************************************************************************
* artSendCmd - Send a command to a dk client
*
* Construct a command to send to the mdk client.  
* Wait for a return struct to verify that the command was successfully 
* excuted.
*
* RETURNS: TRUE if command was successful, FALSE if it was not
*/
A_BOOL artSendCmd
    (
    PIPE_CMD	    *pCmdStruct,	// In:	pointer to structure containing cmd info
    A_UINT32	    cmdSize,		// In:	size of the command structure
    void			**returnCmdStruct	// Out: pointer to structure returned by cmd
    )					// NOTE: if command does not expect a return struct
{
    CMD_REPLY	    *pCmdReply;
    A_BOOL			bGoodWrite = FALSE;
    A_UINT32	    retLen;
	A_UINT16		errorNo;

    // send the command
	q_uiPrintf("Sending Pipe command %d\n", pCmdStruct->cmdID);

//    if ( osSockWrite(artSockInfo, (A_UINT8*)&cmdSize, sizeof(A_UINT32)) ) {
	pCmdStruct->cmdLen = cmdSize;

	if ( osSockWrite(artSockInfo, (A_UINT8*)pCmdStruct, cmdSize+sizeof(pCmdStruct->cmdLen)) ) {
	    bGoodWrite = TRUE;
    }
    if ( !bGoodWrite ) {
	uiPrintf("Error: Unable to write command to pipe in dkcSendCmd()!\n");
	return FALSE;
    }

    // disconnect and close don't expect ANY return (not even the ID ack)
    // so we check for that here
    if ( (DISCONNECT_PIPE_CMD_ID == pCmdStruct->cmdID) || (CLOSE_PIPE_CMD_ID == pCmdStruct->cmdID) )
	return TRUE;

    // wait on reply to command
    if ( !receiveCmdReturn(&retLen) ) {
		uiPrintf("Error: Bad or missing reply from client in response to a command!\n");
		return FALSE;
    }

    pCmdReply = &cmdReply;

    // check to see if the command ID's match.	if they don't, error
    if ( pCmdStruct->cmdID != pCmdReply->replyCmdId ) {
			uiPrintf("Error: client reply to command has mismatched ID!\n");
			uiPrintf("     : sent cmdID: %d, returned: %d, size %d\n",
			pCmdStruct->cmdID, pCmdReply->replyCmdId, retLen);
			return FALSE;
    }

	remoteMdkErrNo = 0;
	errorNo = (A_UINT16) (pCmdReply->status & COMMS_ERR_MASK) >> COMMS_ERR_SHIFT;
	if (errorNo == COMMS_ERR_MDK_ERROR)
	{
		remoteMdkErrNo = (pCmdReply->status & COMMS_ERR_INFO_MASK) >> COMMS_ERR_INFO_SHIFT;
		strncpy(remoteMdkErrStr,(const char *)pCmdReply->cmdBytes,SIZE_ERROR_BUFFER);
		return TRUE;
	}
	
    // check for a bad status in the command reply
	if (errorNo != CMD_OK) {
		uiPrintf("Error: Bad return status in client command response!\n");
		return FALSE;
    }

    if ( !returnCmdStruct ) {
		// see if the length of the reply makes sense
		if ( retLen != (sizeof(pCmdReply->replyCmdId) + sizeof(pCmdReply->status)) ) {
			uiPrintf("Error: Invalid # of bytes in client command response!\n");
			return FALSE;
		}
		return TRUE;
    }

    // reply must be OK, return pointer to additional reply info
    *returnCmdStruct = pCmdReply->cmdBytes;
    return TRUE;
}

/**************************************************************************
* receiveCmdReturn - Get the return info from a command sent
*
* Read from the pipe and get the info returned from a command.	######Need to
* make this timeout if don't receive reply, but don't know how to do that
* yet
*
*
* RETURNS: TRUE if reply was received, FALSE if it was not
*/
A_BOOL receiveCmdReturn
    (
    A_UINT32 *pReturnLength
    )
{
    A_BOOL	    bGoodRead = FALSE;

    if ( osSockRead(artSockInfo, (A_UINT8*)pReturnLength, sizeof(A_UINT32)) ) {
	if ( osSockRead(artSockInfo, (((A_UINT8 *)(&cmdReply))+sizeof(cmdReply.replyCmdLen)), *pReturnLength) )
	    bGoodRead= TRUE;
    }
    if ( !bGoodRead )
	return FALSE;

	cmdReply.replyCmdLen = *pReturnLength;

    return TRUE;
}

/**************************************************************************
* activateCommsInitHandshake - Activate comms pipe with secondary ART session
*
*
* RETURNS: TRUE if activated, FALSE if it was not
*/
A_BOOL activateCommsInitHandshake
(
 A_CHAR *machName
)
{
	pArtSecondarySock = openCommsChannel(machName);

	if (pArtSecondarySock == NULL) {
		uiPrintf("Error: Unable to open communications channel to secondary ART system!\n");
		return FALSE;
	}
	//###########TODO - need to close socket and cleanup mallocs 
	prepare2WayComms();
	return(TRUE);
}

A_BOOL waitCommsInitHandshake
(
 void
)
{
	pArtSecondarySock = (ART_SOCK_INFO *)artConnect();

	if (pArtSecondarySock == NULL) {
		uiPrintf("Error: Unable to open communications channel to secondary ART system!\n");
		return FALSE;
	}
	prepare2WayComms();
	return(TRUE);
	
}

void closeComms
(
 void
)
{
	//do this just in case 
	selectPrimary();
	cleanupSockMem(pArtSecondarySock, 1);
	
}

void activateArtSlave(void)
{
	//Change this to be a bit more sophisticated - more like MDK_Main
//	connectThread(pArtSecondarySock);

}

/**************************************************************************
* selectPrimary - Set flags and pointers back to primary ART session
*
*
* RETURNS: TRUE if selected, FALSE if it was not
*/
A_BOOL selectPrimary
(
 void
)
{
	if(configSetup.primaryAP) {
		if(!pArtPrimarySock) {
			uiPrintf("Fatal Error: Primary ART is AP and no pointer to socket initialized\n");
			return FALSE;
		}
		artSockInfo = pArtPrimarySock;
	}
	else {
		configSetup.remote = 0;
		artSockInfo = NULL;
	}
	return TRUE;
}

/**************************************************************************
* selectSecondary - Set flags and pointers for secondary ART session
*
*
* RETURNS: TRUE if selected, FALSE if it was not
*/
A_BOOL selectSecondary
(
 void
)
{
	if(!pArtSecondarySock) {
		uiPrintf("Fatal Error: Secondary socket is not initialized\n");
		return FALSE;
	}
	artSockInfo = pArtSecondarySock;
	configSetup.remote = 1;
	return TRUE;
}

#else
ART_SOCK_INFO *openCommsChannel
    (
    A_CHAR	    *machineName
    )
{
	//dummy function
	uiPrintf("Error: openCommsChannel() not supported in DOS version\n");
	return NULL;
}

A_BOOL artSendCmd
    (
    PIPE_CMD	    *pCmdStruct,	// In:	pointer to structure containing cmd info
    A_UINT32	    cmdSize,		// In:	size of the command structure
    void			**returnCmdStruct	// Out: pointer to structure returned by cmd
    )					// NOTE: if command does not expect a return struct
{
	//dummy function
	uiPrintf("Error: artSendCmd() not supported in DOS version\n");
	return(FALSE);

}

A_BOOL activateCommsInitHandshake
(
 A_CHAR *machName
)
{
	uiPrintf("Error: activateCommsInitHandshake() not supported in DOS version\n");
	return(FALSE);
}

A_BOOL selectPrimary
(
 void
)
{
	uiPrintf("Error: selectPrimary() not supported in DOS version\n");
	return(FALSE);
}

A_BOOL selectSecondary
(
 void
)
{
	uiPrintf("Error: selectSecondary() not supported in DOS version\n");
	return(FALSE);
}

#endif


/**************************************************************************
* art_getMdkErrNo - Get the last error number from the library
*
*/
A_INT32 art_getMdkErrNo
(
 A_UINT32 devNum
)
{
	if (!configSetup.remote) {
		return getMdkErrNo(devNum);
	}
	else {
		return remoteMdkErrNo;
	}
	return 0;
}


/**************************************************************************
* art_getMdkErrStr - Get the last error string from the library
*
*/
void art_getMdkErrStr
(
 A_UINT32 devNum,
 A_CHAR *pErrStr
)
{
	if (!configSetup.remote)
	{
		getMdkErrStr(devNum, pErrStr);
	}
	else {
		strncpy(pErrStr,remoteMdkErrStr,SIZE_ERROR_BUFFER);
	}
	return;
}

/**************************************************************************
* checkLibError - Check for errors in the last library call
*
* Check mdkErrno for errors.  If error, get and print error message 
* if requested
*
* RETURNS: TRUE if there was an error, FALSE if not
*/
A_BOOL checkLibError
(
 A_UINT32 devNum,	
 A_BOOL	printError 
)
{
	art_mdkErrNo = art_getMdkErrNo(devNum);
	
	if (art_mdkErrNo) {
		if (printError && printLocalInfo) {
			art_getMdkErrStr(devNum, art_mdkErrStr);
			uiPrintf("\nError: %s\n", art_mdkErrStr);
		}
		return TRUE;
	}
	return FALSE;
}


/**************************************************************************
* art_getPowerIndex - Get the power index pointing to the desired power
* level. In gen3, the pcdac table is made maxPower referenced - hence a 
* need for this for dynamicOptimization.
*
* RETURNS: index pointing to the desired power
*/
A_UINT16 art_getPowerIndex
(
	A_UINT32 devNum,
	A_INT32  power   // 2 x power in dB
)
{
	A_UINT16 returnValue;
	A_UINT16 *pRegValue;

	if (!configSetup.remote)
	{
		returnValue = getPowerIndex(devNum, power);
	}
	else {
		GlobalCmd.cmdID = M_GET_POWER_INDEX_CMD_ID;
		GlobalCmd.CMD_U.GET_POWER_INDEX_CMD.devNum = devNum;
		GlobalCmd.CMD_U.GET_POWER_INDEX_CMD.power = power;
		if(!artSendCmd(&GlobalCmd,
					    sizeof(GlobalCmd.CMD_U.GET_POWER_INDEX_CMD)+sizeof(GlobalCmd.cmdID),
						(void **)&pRegValue)) 
		{
			uiPrintf("Error: Unable to successfully send GET_POWER_INDEX_CMD command\n");
			return 0xdead;
		}
		if (checkLibError(devNum, 1)) {
			return(0xdead);
		} 
		returnValue = *pRegValue;

	}
	return returnValue;
}


#ifndef __ATH_DJGPPDOS__
/**************************************************************************
* art_getArtAniLevel - Get current level of noise immunity (NI/BI/SI)
*
* RETURNS: level of NI/BI/SI (0..max)
*
*/
A_UINT32 art_getArtAniLevel
(
	A_UINT32 devNum,
	A_UINT32 artAniType   // NI/BI/SI
)
{
	A_UINT32 returnValue = 0;
	A_UINT32 *pRegValue;

	if (!configSetup.artAniEnable) {
		return returnValue;
	}


	if (!configSetup.remote)
	{
		returnValue = getArtAniLevel(devNum, artAniType);
	}
	else {
		GlobalCmd.cmdID = M_GET_ART_ANI_LEVEL_CMD_ID;
		GlobalCmd.CMD_U.GET_ART_ANI_LEVEL_CMD.devNum = devNum;
		GlobalCmd.CMD_U.GET_ART_ANI_LEVEL_CMD.artAniType = artAniType;
		if(!artSendCmd(&GlobalCmd,
					    sizeof(GlobalCmd.CMD_U.GET_ART_ANI_LEVEL_CMD)+sizeof(GlobalCmd.cmdID),
						(void **)&pRegValue)) 
		{
			uiPrintf("Error: Unable to successfully send GET_ART_ANI_LEVEL_CMD command\n");
			return 0xdead;
		}
		if (checkLibError(devNum, 1)) {
			return(0xdead);
		} 
		returnValue = *pRegValue;

	}
	return returnValue;
}


/**************************************************************************
* art_setArtAniLevel - Set current level of noise immunity (NI/BI/SI)
*
* RETURNS: void
*
*/
void art_setArtAniLevel
(
	A_UINT32 devNum,
	A_UINT32 artAniType,   // NI/BI/SI
	A_UINT32 artAniLevel
)
{
	A_UINT32 *pRegValue;

	if (!configSetup.remote)
	{
		setArtAniLevel(devNum, artAniType, artAniLevel);

⌨️ 快捷键说明

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