📄 rilhandndisoem1.cpp
字号:
void
CAsyncResponse::AddCommand ( OEMNDISAPIREFERENCE *lpOemNdisApiReference )
{
PASYNCCOMMAND pEntry = NULL;
if ( lpOemNdisApiReference )
{
AsyncListLock();
if (!IsListEmpty(&m_AsyncFreeList))
{
pEntry = (PASYNCCOMMAND)RemoveHeadList(&m_AsyncFreeList);
}
if (pEntry == NULL)
{
pEntry = (PASYNCCOMMAND)LocalAlloc(LPTR, sizeof(*pEntry));
}
if ( pEntry )
{
memcpy(&pEntry->OemNdisApiReference, lpOemNdisApiReference, sizeof(OEMNDISAPIREFERENCE));
}
InsertTailList(&m_AsyncPendingList, &pEntry->Node);
AsyncListUnlock();
}
}
void
CAsyncResponse::RemoveCommand( HRESULT CommandID )
{
if ( CommandID )
{
PASYNCCOMMAND pEntry;
AsyncListLock();
for (pEntry = (PASYNCCOMMAND)(m_AsyncPendingList.Flink);
TRUE;
pEntry = (PASYNCCOMMAND)pEntry->Node.Flink)
{
if (pEntry == (PASYNCCOMMAND)(&m_AsyncPendingList))
{
DEBUGMSG(ZONE_NDIS, (TEXT("RILNDIS: RemoveCommand CommandID = %x NOT FOUND\r\n"), CommandID));
break;
}
if ( pEntry->OemNdisApiReference.CommandID == CommandID )
{
RemoveEntryList(&pEntry->Node);
InsertTailList(&m_AsyncFreeList, &pEntry->Node);
break;
}
}
AsyncListUnlock();
}
}
void
CAsyncResponse::ProcessCommand ( const OEMNDISAPIREFERENCE *lpOemNdisApiReference )
{
if ( lpOemNdisApiReference )
{
CRilInstanceHandle* pCRilInstance=NULL;
PASYNCCOMMAND pEntry;
AsyncListLock();
for (pEntry = (PASYNCCOMMAND)(m_AsyncPendingList.Flink);
TRUE;
pEntry = (PASYNCCOMMAND)pEntry->Node.Flink)
{
if (pEntry == (PASYNCCOMMAND)(&m_AsyncPendingList))
{
DEBUGMSG(ZONE_NDIS, (TEXT("RILNDIS: ProcessCommand Notify FAILED \r\n")));
break;
}
// Result for other event. Success is passed via the status member of the input structure.
if ( lpOemNdisApiReference->EventType )
{
if ( (lpOemNdisApiReference->EventType == pEntry->OemNdisApiReference.EventType) &&
(lpOemNdisApiReference->ContextID == pEntry->OemNdisApiReference.ContextID))
{
pCRilInstance = (CRilInstanceHandle*)pEntry->OemNdisApiReference.pCRilInstance;
if ( pCRilInstance )
{
DWORD Result = lpOemNdisApiReference->Status ? RIL_RESULT_ERROR : RIL_RESULT_OK;
DWORD Status = lpOemNdisApiReference->Status;
pCRilInstance->Notify( Result,
pEntry->OemNdisApiReference.CommandID,
&Status,
sizeof(Status));
DEBUGMSG(ZONE_NDIS, (TEXT("RILNDIS: ProcessCommand Notify Command Status = %x Comamand ID = %0x \r\n"),
Result,
pEntry->OemNdisApiReference.CommandID));
}
RemoveEntryList(&pEntry->Node);
InsertTailList(&m_AsyncFreeList, &pEntry->Node);
break;
}
}
}
AsyncListUnlock();
}
}
void
CAsyncResponse::RemoveAllCommands( DWORD ContextID )
{
PASYNCCOMMAND pEntry;
BOOL ExitNow = FALSE;
//
// Find entry with matching ContextID in our list of pending requests
//
AsyncListLock();
while ( FALSE == ExitNow )
{
for (pEntry = (PASYNCCOMMAND)(m_AsyncPendingList.Flink);
TRUE;
pEntry = (PASYNCCOMMAND)pEntry->Node.Flink)
{
if (pEntry == (PASYNCCOMMAND)(&m_AsyncPendingList))
{
ExitNow = TRUE;
break;
}
if ( ContextID == pEntry->OemNdisApiReference.ContextID )
{
RemoveEntryList(&pEntry->Node);
InsertTailList(&m_AsyncFreeList, &pEntry->Node);
break;
}
}
}
AsyncListUnlock();
}
inline void
CAsyncResponse::AsyncListLock()
{
EnterCriticalSection(&m_cs);
}
inline void
CAsyncResponse::AsyncListUnlock()
{
LeaveCriticalSection(&m_cs);
}
DWORD WINAPI ProcessObjectsThreadProc(LPVOID pParameter);
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CPdpContext::CPdpContext(PVOID pEventNotification )
{
InitializeCriticalSection(&m_Lock);
m_ProcessObjextsThreadID = 0;
m_CrilCancelEvent = NULL;
m_ContextID = 0;
m_CrilAsyncCommandDone = NULL;
m_RilResultCode = 0;
m_ActivationState = ACTIVATION_STATE_DISCONNECTED;
memset(&m_OemNdisIpConfig, 0, sizeof(m_OemNdisIpConfig));
if ( pEventNotification )
{
m_AppMsgQueue = pEventNotification;
m_ProcessObjectsThread = CreateThread(NULL, 0, ProcessObjectsThreadProc, (LPVOID)this, 0, &m_ProcessObjextsThreadID);
}
DEBUGMSG( ZONE_NDIS, (TEXT("RILNDIS CPdpContext: CPdpContext Create Connection Object %x \r\n"), this));
}
CPdpContext::~CPdpContext()
{
DWORD ExitCode;
DeleteCriticalSection(&m_Lock);
if ( m_ProcessObjectsThread )
{
if ( NULL == m_CrilCancelEvent )
{
if ( GetExitCodeThread(m_ProcessObjectsThread, &ExitCode ))
{
if ( STILL_ACTIVE == ExitCode )
{
Sleep(100);
}
}
}
if ( m_CrilCancelEvent )
{
SetEvent(m_CrilCancelEvent);
WaitForSingleObject(m_ProcessObjectsThread, INFINITE );
CloseHandle(m_ProcessObjectsThread);
}
}
DEBUGMSG( ZONE_NDIS, (TEXT("RILNDIS CPdpContext: CPdpContext Delete Connection Object %x \r\n"), this));
}
inline void
CPdpContext::Lock()
{
EnterCriticalSection(&m_Lock);
}
inline void
CPdpContext::Unlock()
{
LeaveCriticalSection(&m_Lock);
}
inline BOOL
CPdpContext::IsLocked()
{
return m_Lock.OwnerThread == (HANDLE)GetCurrentThreadId();
}
// **************************************************************************
// Function Name: ProcessObjectsThreadProc
//
// Purpose: Process NDIS events from radio.
//
// Arguments:
//
// Return Values:
//
// Side effects:
//
// Description:
// **************************************************************************
DWORD WINAPI ProcessObjectsThreadProc(LPVOID pParameter)
{
CPdpContext* pCPdpContext = (CPdpContext*)pParameter;
DWORD Result;
if (!CeSetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL))
{
return 0;
}
Result = pCPdpContext->ProcessObjectsThread();
return Result;
}
HRESULT
CPdpContext::GetGPRSContextActivatedList(void)
{
HRESULT Result;
Result = S_OK;//AsyncRequestIssue((RIL_FUNCTION)RIL_GetGPRSContextActivatedList, NULL, NULL, CRilRequestTypeGetGPRSContextActivatedList, Arg);
return Result;
}
HRESULT
CPdpContext::GetGPRSAddress(
IN DWORD ContextID)
{
FUNCTION_TRACE(RILDrv_GetGPRSAddress);
HRESULT Result = S_OK;
// Build command
char Cmd[MAX_PATH];
(void)_snprintfz(Cmd, MAX_PATH, "AT+CGPADDR=%u\r", ContextID);
if (!QueueCmdIgnoreRspWithData(APIID_GETGPRSADDRESS, // appiid
Cmd, // szCmd
CMDOPT_FORCEPARSE, // dwOptions
20000, // dwTimeout
NULL, // Parse fn
NULL, // Ptr to notification data
0, // dwRetries
0, // dwRetriesOnError
0, // dwRetryOnErrorDelay
CRilParseGetGPRSAddress,//parse fn with data
this )) // Data )) // dwRetryOnErrorDelay
{
Result = E_FAIL;
}
return Result;
}
//
//
//
HRESULT
CPdpContext::DevSpecific(
IN BYTE* pParams, // @parm parameters for the operation to be performed
IN DWORD Size, // @parm size of the data pointed to by <p lpParams> in bytes
IN BOOL IgnoreResponse
)
{
PFN_CMD_PARSE_DATA pFnCmdParseData = NULL;
HRESULT Result = S_OK;
char Cmd[MAX_PATH];
if (!pParams)
{
Result = E_FAIL;
goto Error;
}
DEBUGCHK(NULL != pParams);
DEBUGCHK(Size > 0);
if ( Size != sizeof(RILATCOMMAND))
{
Result = E_NOTIMPL;
goto Error;
}
if ( Size == sizeof(RILATCOMMAND) )
{
LPRILATCOMMAND pRilATCommand = (LPRILATCOMMAND)pParams;
if ( pRilATCommand && pRilATCommand->Size == sizeof(*pRilATCommand))
{
switch ( pRilATCommand->Operation)
{
case CRilATCommandTypeCGPCO:
{
LPRILATCGPCO pRilCGPCO = (LPRILATCGPCO)pRilATCommand->pData;
if (!pRilCGPCO)
{
Result = E_FAIL;
goto Error;
}
if ( pRilCGPCO->Size == sizeof(*pRilCGPCO) )
{
// Build command
char ATCommand[] = "AT%CGPCO=";
if ( 0 == pRilCGPCO->Mode)// Set
{
pFnCmdParseData = IgnoreResponse ? NULL : CRilParseSetCGPCO;
(void)_snprintfz(Cmd, MAX_PATH, "%s%u,1,\"%s\",%u\r",ATCommand,pRilCGPCO->Mode,pRilCGPCO->ProtocolOptions, pRilCGPCO->ContextID);
if (!QueueCmdIgnoreRspWithData(APIID_GETGPRSADDRESS, // appiid
Cmd, // szCmd
CMDOPT_FORCEPARSE, // dwOptions
20000, // dwTimeout
NULL, // Parse fn
NULL, // Ptr to notification data
0, // dwRetries
0, // dwRetriesOnError
0, // dwRetryOnErrorDelay
pFnCmdParseData,//parse fn with data
this )) // Data )) // dwRetryOnErrorDelay
{
Result = E_FAIL;
goto Error;
}
}
else // Query
{
pFnCmdParseData = IgnoreResponse ? NULL : CRilParseGetCGPCO;
(void)_snprintfz(Cmd, MAX_PATH, "%s%u,1,,%u\r",ATCommand,pRilCGPCO->Mode,pRilCGPCO->ContextID);
if (!QueueCmdIgnoreRspWithData(APIID_GETGPRSADDRESS, // appiid
Cmd, // szCmd
CMDOPT_FORCEPARSE, // dwOptions
20000, // dwTimeout
NULL, // Parse fn
NULL, // Ptr to notification data
0, // dwRetries
0, // dwRetriesOnError
0, // dwRetryOnErrorDelay
pFnCmdParseData,//parse fn with data
this )) // Data )) // dwRetryOnErrorDelay
{
Result = E_FAIL;
goto Error;
}
}
}
else
{
Result = E_FAIL;
}
}
break;
case CRilATCommandTypeDATA:
{
LPRILATDATA pRilData = (LPRILATDATA)pRilATCommand->pData;
if (!pRilData)
{
Result = E_FAIL;
goto Error;
}
if ( pRilData->Size == sizeof(*pRilData) )
{
pFnCmdParseData = IgnoreResponse ? NULL : CRilParseDATA;
// Build command
char ATCommand[] = "AT%DATA=";
(void)_snprintfz(Cmd, MAX_PATH, "%s%u,\"%s\",%u,%u,\"%s\",\"%s\",%u,%u,%u\r",
ATCommand,
pRilData->Mode,
pRilData->DestDeviceName,
pRilData->DestDeviceNum,
pRilData->DestSubNum,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -