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

📄 anwi_hw.c

📁 Atheros AP Test with Agilent N4010A source code
💻 C
📖 第 1 页 / 共 2 页
字号:
		}

		return;
}

/**************************************************************************
* hwCfgRead - called by hwCfgRead*
*
* This routine will call into the driver
* 32 bit PCI configuration read.
*
* RETURNS: the value read
*/
A_UINT32 hwCfgRead
(
	struct mdk_wlanDevInfo *pdevInfo,        /* device info pointer */
	A_UINT32 offset                    /* the address to read from */
)
{
	A_BOOL status;
	A_UINT32 bR = 0;
	anwiReturnContext returnContext;
	anwiDevOpStruct inStruct;
	pAnwiDevOpStruct pOutStruct;
	A_UINT32 data;
	HANDLE hnd;

#ifdef LEGACY
		inStruct.cliId = pdevInfo->cliId;
#endif
		inStruct.opType = ANWI_CFG_READ;
		inStruct.param1 = offset;
#ifdef LEGACY
		inStruct.param2 = 0;
#else
		inStruct.param2 = 4;
		inStruct.param3 = 0;
#endif

#ifdef LEGACY
		hnd = hDriver;
#else
		hnd = pdevInfo->hDevice;
#endif

		status = DeviceIoControl  (hnd,
						IOCTL_ANWI_DEV_OP,
						&inStruct,
						sizeof(anwiDevOpStruct),
						&returnContext,
						sizeof(anwiReturnContext),
						&bR,
						NULL);


		if ((!status) || (returnContext.returnCode != ANWI_OK)) {
			printf("Error returned by DEV_OP DeviceIoControl call \n");
			return 0xdeadbeef;
		}

		if (returnContext.contextLen != sizeof(anwiDevOpStruct)) {
			printf("Return size (%d) from DEV_OP DeviceIoControl call doesnt match the expected size (%d) \n",returnContext.contextLen,sizeof(anwiDevOpStruct));
			return 0xdeadbeef;
		}

		pOutStruct = (pAnwiDevOpStruct) returnContext.context;
		data = pOutStruct->param1;
		return data;
}

/**************************************************************************
* hwCfgRead8 - read an 8 bit configuration value
*
* This routine will call into the driver to activate a 8 bit PCI configuration
* read cycle.
*
* RETURNS: the value read
*/
A_UINT8 hwCfgRead8
(
	A_UINT16 devIndex,
	A_UINT32 address                    /* the address to read from */
)
{
	A_UINT32 data;
	A_UINT8 out;
	MDK_WLAN_DEV_INFO *pdevInfo;

	pdevInfo = globDrvInfo.pDevInfoArray[devIndex];

	data = hwCfgRead(pdevInfo,address & 0xfffffffc);
	out = (A_UINT8)((data >> (address & 0x00000003)) & 0x000000ff);

	return out;
}

/**************************************************************************
* hwCfgRead16 - read a 16 bit value
*
* This routine will call into the driver to activate a 16 bit PCI configuration
* read cycle.
*
* RETURNS: the value read
*/
A_UINT16 hwCfgRead16
(
	A_UINT16 devIndex,
	A_UINT32 address                    /* the address to read from */
)
{
	A_UINT32 data;
	A_UINT16 out;
	MDK_WLAN_DEV_INFO *pdevInfo;

	pdevInfo = globDrvInfo.pDevInfoArray[devIndex];

	data = hwCfgRead(pdevInfo, address & 0xfffffffc);
	out = (A_UINT16)((data >> (address & 0x00000002)) & 0x0000ffff);

	return out;
}


/**************************************************************************
* hwCfgRead32 - read a 32 bit value
*
* This routine will call into the driver to activate a 32 bit PCI configuration
* read cycle.
*
* RETURNS: the value read
*/
A_UINT32 hwCfgRead32
(
	A_UINT16 devIndex,
	A_UINT32 address                    /* the address to read from */
)
{
	A_UINT32 data;
	MDK_WLAN_DEV_INFO *pdevInfo;

	pdevInfo = globDrvInfo.pDevInfoArray[devIndex];
	data = hwCfgRead(pdevInfo, address & 0xfffffffc);

	return data;
}

/**************************************************************************
* hwCfgWrite32 - write a 32 bit value
*
* This routine will call into the driver to activate a
* 32 bit PCI configuration write.
*
* RETURNS: N/A
*/
void hwCfgWrite32
(
	A_UINT16 devIndex,
	A_UINT32  offset,                    /* the address to write */
	A_UINT32  value                        /* value to write */
)
{
	A_BOOL status;
	A_UINT32 bR = 0;
	anwiReturnContext returnContext;
	anwiDevOpStruct inStruct;
	HANDLE hnd;
	MDK_WLAN_DEV_INFO *pdevInfo;

	pdevInfo = globDrvInfo.pDevInfoArray[devIndex];


#ifdef LEGACY
		inStruct.cliId = pdevInfo->cliId;
#endif
		inStruct.opType = ANWI_CFG_WRITE;
		inStruct.param1 = offset;
#ifdef LEGACY
		inStruct.param2 = value;
#else
		inStruct.param2 = 4;
		inStruct.param3 = value;
#endif

#ifdef LEGACY
		hnd = hDriver;
#else
		hnd = pdevInfo->hDevice;
#endif

		status = DeviceIoControl  (hnd,
						IOCTL_ANWI_DEV_OP,
						&inStruct,
						sizeof(anwiDevOpStruct),
						&returnContext,
						sizeof(anwiReturnContext),
						&bR,
						NULL);


		if ((!status) || (returnContext.returnCode != ANWI_OK)) {
			printf("Error returned by DEV_OP DeviceIoControl call \n");
			return;
		}

		if (returnContext.contextLen != sizeof(anwiDevOpStruct)) {
			printf("Return size (%d) from DEV_OP DeviceIoControl call doesnt match the expected size (%d) \n",returnContext.contextLen,sizeof(anwiDevOpStruct));
			return;
		}

		return;
}

/**************************************************************************
* hwCfgWrite8 - write an 8 bit value
*
* This routine will call into the simulation environment to activate an
* 8 bit PCI configuration write cycle
*
* RETURNS: N/A
*/
void hwCfgWrite8
(
	A_UINT16 devIndex,
	A_UINT32 address,                    /* the address to write */
	A_UINT8  value                        /* value to write */
)
{
	printf("hwCfgWrite8 not implemented for ANWI \n");
}

/**************************************************************************
* hwCfgWrite16 - write a 16 bit value
*
* This routine will call into the simulation environment to activate a
* 16 bit PCI configuration write cycle
*
* RETURNS: N/A
*/
void hwCfgWrite16
(
	A_UINT16 devIndex,
	A_UINT32 address,                    /* the address to write */
	A_UINT16  value                        /* value to write */
)
{
	printf("hwCfgWrite16 not implemented for ANWI \n");
}

#ifdef ART_BUILD
/**************************************************************************
* hwCreateEvent - Handle event creation within windows environment
*
* Create an event within windows environment
*
*
* RETURNS: 0 on success, -1 on error
*/
A_INT16 hwCreateEvent
(
	A_UINT16 devIndex,
	A_UINT32 type,
	A_UINT32 persistent,
	A_UINT32 param1,
	A_UINT32 param2,
	A_UINT32 param3,
	EVT_HANDLE eventHandle
	)
{
	MDK_WLAN_DEV_INFO *pdevInfo;
	A_BOOL status;
	A_UINT32 bR = 0;
	anwiReturnContext returnContext;
	anwiEventOpStruct event;
	HANDLE hnd;

		pdevInfo = globDrvInfo.pDevInfoArray[devIndex];

#ifdef LEGACY
		event.cliId = pdevInfo->cliId;
#endif
		event.opType = ANWI_CREATE_EVENT;
		event.valid = 1;
		event.param[0] = type;
		event.param[1] = persistent;
		event.param[2] = param1;
		event.param[3] = param2;
		event.param[4] = param3;
		event.param[5] = (eventHandle.f2Handle << 16) | eventHandle.eventID;

#ifdef LEGACY
		hnd = hDriver;
#else
		hnd = pdevInfo->hDevice;
#endif

		status = DeviceIoControl  (hnd,
						IOCTL_ANWI_EVENT_OP,
						&event,
						sizeof(event),
						&returnContext,
						sizeof(anwiReturnContext),
						&bR,
						NULL);


		if ((!status) || (returnContext.returnCode != ANWI_OK)) {
			printf("Error returned by event op DeviceIoControl call \n");
			return -1;
		}

	   return(0);
}

A_UINT16 getNextEvent
(
	A_UINT16 devIndex,
	EVENT_STRUCT *pEvent
)
{
	MDK_WLAN_DEV_INFO *pdevInfo;
	A_BOOL status;
	A_UINT32 bR = 0;
	anwiReturnContext returnContext;
	anwiEventOpStruct inEvent;
	pAnwiEventOpStruct outEvent;
	A_UINT32 i;
	HANDLE hnd;

		pdevInfo = globDrvInfo.pDevInfoArray[devIndex];

#ifdef LEGACY
		inEvent.cliId = pdevInfo->cliId;
#endif
		inEvent.opType = ANWI_GET_NEXT_EVENT;
		inEvent.valid = 0;

#ifdef LEGACY
		hnd = hDriver;
#else
		hnd = pdevInfo->hDevice;
#endif

		status = DeviceIoControl  (hnd,
						IOCTL_ANWI_EVENT_OP,
						&inEvent,
						sizeof(anwiEventOpStruct),
						&returnContext,
						sizeof(anwiReturnContext),
						&bR,
						NULL);


		if ((!status) || (returnContext.returnCode != ANWI_OK)) {
			printf("Error returned by event op DeviceIoControl call \n");
			return 0;
		}

		if (returnContext.contextLen != sizeof(anwiEventOpStruct)) {
			printf("Return size (%d) from event op DeviceIoControl call doesnt match the expected size (%d) \n",returnContext.contextLen,sizeof(anwiEventOpStruct));
			return 0;
		}

		outEvent = (pAnwiEventOpStruct) returnContext.context;

		if (!outEvent->valid) {
			return 0;
		}

		pEvent->type = outEvent->param[0];
		pEvent->persistent = outEvent->param[1];
		pEvent->param1 = outEvent->param[2];
		pEvent->param2 = outEvent->param[3];
		pEvent->param3 = outEvent->param[4];
		pEvent->eventHandle.eventID = outEvent->param[5] & 0xffff;
		pEvent->eventHandle.f2Handle = (outEvent->param[5] >> 16 ) & 0xffff;
		for (i=0;i<6;i++) {
			pEvent->result[i] = outEvent->param[6+i];
		}

	return(1);
}
#else
/**************************************************************************
* hwCreateEvent - Handle event creation within windows environment
*
* Create an event within windows environment
*
*
* RETURNS: 0 on success, -1 on error
*/

A_INT16 hwCreateEvent
(
	A_UINT16 devIndex,
	PIPE_CMD *pCmd
)
{
	A_BOOL status;
	A_UINT32 bR = 0;
	anwiReturnContext returnContext;
	anwiEventOpStruct event;
	HANDLE hnd;
	MDK_WLAN_DEV_INFO *pdevInfo;

	pdevInfo = globDrvInfo.pDevInfoArray[devIndex];

#ifdef LEGACY
		event.cliId = pdevInfo->cliId;
#endif
		event.opType = ANWI_CREATE_EVENT;
		event.valid = 1;
		event.param[0] = pCmd->CMD_U.CREATE_EVENT_CMD.type;
		event.param[1] = pCmd->CMD_U.CREATE_EVENT_CMD.persistent;
		event.param[2] = pCmd->CMD_U.CREATE_EVENT_CMD.param1;
		event.param[3] = pCmd->CMD_U.CREATE_EVENT_CMD.param2;
		event.param[4] = pCmd->CMD_U.CREATE_EVENT_CMD.param3;
		event.param[5] = (pCmd->CMD_U.CREATE_EVENT_CMD.eventHandle.f2Handle << 16) | pCmd->CMD_U.CREATE_EVENT_CMD.eventHandle.eventID;

#ifdef LEGACY
		hnd = hDriver;
#else
		hnd = pdevInfo->hDevice;
#endif

		status = DeviceIoControl  (hnd,
						IOCTL_ANWI_EVENT_OP,
						&event,
						sizeof(event),
						&returnContext,
						sizeof(anwiReturnContext),
						&bR,
						NULL);


		if ((!status) || (returnContext.returnCode != ANWI_OK)) {
			printf("Error returned by event op DeviceIoControl call \n");
			return -1;
		}

	   return(0);
}

A_UINT16 getNextEvent
(
	MDK_WLAN_DEV_INFO *pdevInfo,
	EVENT_STRUCT *pEvent
)
{

	A_BOOL status;
	A_UINT32 bR = 0;
	anwiReturnContext returnContext;
	anwiEventOpStruct inEvent;
	pAnwiEventOpStruct outEvent;
	HANDLE hnd;
	int i;

#ifdef LEGACY
		inEvent.cliId = pdevInfo->cliId;
#endif
		inEvent.opType = ANWI_GET_NEXT_EVENT;
		inEvent.valid = 0;

#ifdef LEGACY
		hnd = hDriver;
#else
		hnd = pdevInfo->hDevice;
#endif

		status = DeviceIoControl  (hnd,
						IOCTL_ANWI_EVENT_OP,
						&inEvent,
						sizeof(anwiEventOpStruct),
						&returnContext,
						sizeof(anwiReturnContext),
						&bR,
						NULL);


		if ((!status) || (returnContext.returnCode != ANWI_OK)) {
			printf("Error returned by event op DeviceIoControl call \n");
			return -1;
		}

		if (returnContext.contextLen != sizeof(anwiEventOpStruct)) {
			printf("Return size (%d) from event op DeviceIoControl call doesnt match the expected size (%d) \n",returnContext.contextLen,sizeof(anwiEventOpStruct));
			return -1;
		}

		pEvent->type = 0;

		outEvent = (pAnwiEventOpStruct) returnContext.context;

		if (!outEvent->valid) {
			return 0;
		}

		pEvent->type = outEvent->param[0];
		pEvent->persistent = outEvent->param[1];
		pEvent->param1 = outEvent->param[2];
		pEvent->param2 = outEvent->param[3];
		pEvent->param3 = outEvent->param[4];
		pEvent->eventHandle.eventID = outEvent->param[5] & 0xffff;
		pEvent->eventHandle.f2Handle = (outEvent->param[5] >> 16 ) & 0xffff;
		pEvent->result = outEvent->param[6];
#ifdef MAUI
		for (i=0;i<5;i++) {
			pEvent->additionalParams[i] = outEvent->param[7+i];
		}
#endif

	return(1);
}

A_INT16 hwGetNextEvent
(
	A_UINT16 devIndex,
	void *pBuf
)
{
	MDK_WLAN_DEV_INFO *pdevInfo;

	pdevInfo = globDrvInfo.pDevInfoArray[devIndex];

	return getNextEvent(pdevInfo,(EVENT_STRUCT *)pBuf);
}

#endif // else ART_BUILD

A_STATUS get_device_client_info(MDK_WLAN_DEV_INFO *pdevInfo, PDRV_VERSION_INFO pDrvVer, PCLI_INFO cliInfo) {
	HANDLE hDevice;
	anwiOutClientInfo anwi_cliInfo;

#ifdef LEGACY
	if (!RegisterClient(pdevInfo->pdkInfo->devIndex,&anwi_cliInfo)) {
		uiPrintf("Error: Unable to register client with the driver \n");
		A_FREE(pdevInfo->pdkInfo);
		A_FREE(pdevInfo);
		return A_ERROR;
	}
	pdevInfo->cliId = cliInfo->cliId;
#else
	hDevice = open_device(pdevInfo->pdkInfo->device_fn, pdevInfo->pdkInfo->devIndex, NULL);
	if (hDevice == INVALID_HANDLE_VALUE) {
		uiPrintf("Error: Unable to open the device !\n");
		return A_ERROR;
	}
	if (getClientInfo(hDevice,&anwi_cliInfo) < 0) {
		uiPrintf("Unable to get client info \n");
		CloseHandle(hDevice);
		return A_ERROR;
	}
	pdevInfo->hDevice = hDevice;
#endif

	pDrvVer->majorVersion = driverVer.majorVersion;
	pDrvVer->minorVersion = driverVer.minorVersion;

	// Copy from driver client info structure
	memcpy(cliInfo, &anwi_cliInfo, sizeof(CLI_INFO));
	return A_OK;
}

void close_device(MDK_WLAN_DEV_INFO *pdevInfo) {

#ifdef LEGACY
	unRegisterClient(pdevInfo->cliId);
#else
	if (pdevInfo->hDevice > 0)
	CloseHandle(pdevInfo->hDevice);
#endif

}


/**************************************************************************
* milliSleep - sleep for the specified number of milliseconds
*
* This routine calls a OS specific routine for sleeping
*
* RETURNS: N/A
*/

void milliSleep
	(
	A_UINT32 millitime
	)
{
	Sleep((DWORD) millitime);
}

⌨️ 快捷键说明

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