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

📄 atcmd.cpp

📁 windows mobile RIL软件
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Copyright (c) 1995-1999  Microsoft Corporation

Module Name:

atcmd.cpp

Abstract:


Notes:


--*/

#include "precomp.h"

//
// Globals
//

// Command Queue
CPriorityQueue<CCommand, 40>* g_pCmdQ = NULL;

// Response Queue
CQueue<CResponse, 10>* g_pRspQ = NULL;

#if defined(OEM1_DRIVER) || defined(OEM2_DRIVER) || defined(EMP_DRIVER)
// certain commands like COPS need to wait for the module to
// "settle" after it's been unlocked.
DWORD g_dwUnlocked;
#endif

#if defined(OEM1_GPRS_DEACT) || defined(EMP_DRIVER)
CRITICAL_SECTION g_csGPRSDeactLock;
bool g_fDeactNotificationRcvd = FALSE;
bool g_fDeactResponseRcvd = FALSE;
DWORD g_LastDeactNotificationRcvd = 0;
#endif

#ifdef RIL_RADIO_RESILIENCE
extern CRITICAL_SECTION g_csReboot;
#endif // RIL_RADIO_RESILIENCE

#if defined(OEM1_CSQ_NOTIFICATION) || defined(OEM2_DRIVER) || defined(EMP_DRIVER)
extern RILSIGNALQUALITY g_rsq;
extern BOOL g_fSignalQualityReceived;
#endif //OEM2_DRIVER

extern BOOL g_rgfCalltypeChecked[RIL_MAX_TRACKED_CALL_ID];
extern DWORD g_rgctCalltype[RIL_MAX_TRACKED_CALL_ID];

extern RILLOCATIONINFO g_rliLocationInfo;
extern BOOL g_fInitialLocationInfoReceived;
extern BOOL g_fLocationInfoReceived;
extern BOOL g_fSuppressRegStatusNotification;
extern BOOL g_fSuppressGPRSRegStatusNotification;

extern BOOL g_rfExternalCalltypeDetermination;

extern RINGINGCALLDATA g_rcdRingingCallData;
extern CRITICAL_SECTION g_csRingingCallData;

extern RILCALLINFO g_rgfCallStates[RIL_MAX_TRACKED_CALL_ID];
extern BOOL g_rgfCallsInProgress[RIL_MAX_TRACKED_CALL_ID];

#ifdef EMP_DRIVER
extern BOOL g_fSystemChanged;
extern DWORD g_dwSystemType;
extern DWORD g_dwSystemCaps;
#endif

//
// Place a command into the Command Queue
//
BOOL QueueCmdWithTimeout(CRilInstanceHandle* const pHandle, const LPCSTR szCmd, const LPCSTR szCmdPart2, const DWORD dwOptions, const APIID apiid,
              const PFN_CMD_PARSE pfnParse, CNotificationData* const pnd, HRESULT& rhrCmdID, DWORD dwTimeout, DWORD dwRetries)
{
    FUNCTION_TRACE(QueueCmdWithTimeout);
    DEBUGCHK(0 != (dwOptions & CMDOPT_NOOP) || NULL != szCmd);

    CRilHandle* pRilDevice = pHandle->GetDevice();
    CCommand* pCmd = NULL;
    CNotificationData* pndNotify = pnd;
    APIINFO apiiInfo; memset(&apiiInfo,0,sizeof(apiiInfo)); // zero struct
    BOOL fRet = FALSE;

    DEBUGCHK(NULL != pRilDevice);

    // Get the info about this API
    pRilDevice->GetAPIInfo(apiid, apiiInfo);
    if (dwTimeout==0)
    {
        dwTimeout=apiiInfo.dwTimeout;
    }

    // Set up a command to be sent
    pCmd = new CCommand;
    if (!pCmd || !pCmd->Init(pHandle, szCmd, szCmdPart2, dwOptions, apiiInfo.dwExecTime, dwTimeout, pndNotify, pfnParse, dwRetries, 0, 0, apiid, NULL, NULL))
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : QueueCmdWithTimeout : Unable to construct or Init CCommand\r\n")));
        goto Error;
    }
    pndNotify = NULL;

    // Add this command to the handle's command list
    pHandle->GetCmdList()->Add(pCmd);

    rhrCmdID = pCmd->GetID();

    DEBUGMSG(ZONE_TRACE, (TEXT("RILDrv : t : Queueing command with ID: 0x%08x\r\n"), rhrCmdID));

#ifdef RIL_RADIO_RESILIENCE
        EnterCriticalSection(&g_csReboot);
#endif // RIL_RADIO_RESILIENCE

    // Place the command into the command queue
    //    (this may block if the queue is full)
    if (!g_pCmdQ->Put(pCmd, INFINITE))
    {
#ifdef RIL_RADIO_RESILIENCE
        LeaveCriticalSection(&g_csReboot);
#endif // RIL_RADIO_RESILIENCE
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : QueueCmdWithTimeout : Unable to Put CCommand\r\n")));
        goto Error;
    }

#ifdef RIL_RADIO_RESILIENCE
    LeaveCriticalSection(&g_csReboot);
#endif // RIL_RADIO_RESILIENCE

    // If this is a hangup command, and we're in data mode, we should drop out of data mode immediately
    // to handle this request
    if (pCmd->FHangup() && pRilDevice->GetComDevice()->FDataMode())
    {
        pRilDevice->SetDataEvent();
    }

    if (pCmd->FHangup() || pCmd->FDial() || pCmd->FAnswer())
    {
        SetEvent(g_hNewDialOrHangupEvent);
    }

    pCmd = NULL;
    fRet = TRUE;

    Error:
    if (!fRet)
    {
        delete pCmd;
        delete pndNotify;
    }
    return fRet;
}

//
// Place a command into the Command Queue
//
BOOL QueueCmd(CRilInstanceHandle* const pHandle, const LPCSTR szCmd, const DWORD dwOptions, const APIID apiid,
              const PFN_CMD_PARSE pfnParse, CNotificationData* const pnd, HRESULT& rhrCmdID)
{
    FUNCTION_TRACE(QueueCmd);
    return QueueCmdWithTimeout(pHandle, szCmd, NULL, dwOptions, apiid, pfnParse, pnd, rhrCmdID, 0, 0);
}

/*******added by viking wang********************/
BOOL QueueInternalCmd( CRilHandle* const pRilDevice, const LPCSTR szCmd, const DWORD dwOptions, const APIID apiid, 
					  DWORD dwTimeout, DWORD dwRetries, DWORD dwRetryDelay, 
                      const PFN_CMD_PARSE pfnParse, const dwRetriesOnError, 
                      const PFN_CMD_PARSE_DATA pfnParseWithData, const PVOID pParseData, CNotificationData* const pnd
                      )
{

 	//FUNCTION_TRACE(QueueInternalCmd);
    //DEBUGCHK(0 != (dwOptions & CMDOPT_NOOP) || NULL != szCmd);

	DEBUGMSG(ZONE_ERROR, (TEXT("+QueueInternalCmd()!\r\n")));
    //CRilHandle* pRilDevice = pRilDevice;
    CCommand* pCmd = NULL;
    CNotificationData* pndNotify = pnd;
    APIINFO apiiInfo; memset(&apiiInfo,0,sizeof(apiiInfo)); // zero struct
    BOOL fRet = FALSE;

    //DEBUGCHK(NULL != pRilDevice);

	DEBUGMSG(ZONE_ERROR, (TEXT("QueueInternalCmd:pRilDevice=%0x\r\n"),pRilDevice));
    // Get the info about this API
   /* 
   pRilDevice->GetAPIInfo(apiid, apiiInfo);
    if (dwTimeout==0)
    {
        dwTimeout=apiiInfo.dwTimeout;
    }
*/
    // Set up a command to be sent
    pCmd = new CCommand;


	/*Init(CRilInstanceHandle* const pHandle, const LPCSTR szCmd, const LPCSTR szCmdPart2, const DWORD dwOptions,
                    const DWORD dwExecTime, const DWORD dwTimeout, CNotificationData* const pnd,
                    const PFN_CMD_PARSE pfnParse, const DWORD dwRetries,
                    const DWORD dwRetriesOnError, const DWORD dwRetryOnErrorDelay, const APIID apiid, const PFN_CMD_PARSE_DATA pfnParseWithData, const PVOID pParseData)
         */
	if (!pCmd || !pCmd->Init(NULL, szCmd, NULL, dwOptions, EXECTIME_API_DEFAULT, g_TimeoutCmdInit, pndNotify, pfnParse, 0, 0, 0, apiid, pfnParseWithData, pParseData))         
   // if (!pCmd || !pCmd->Init(NULL, szCmd, NULL, dwOptions, apiiInfo.dwExecTime, dwTimeout, pndNotify, pfnParse, dwRetries, dwRetriesOnError, dwRetryDelay, apiid, pfnParseWithData, pParseData))
		
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : QueueCmdWithTimeout : Unable to construct or Init CCommand\r\n")));
        goto Error;
    }
    pndNotify = NULL;

    // Add this command to the handle's command list
 //   pHandle->GetCmdList()->Add(pCmd);

    //rhrCmdID = pCmd->GetID();

    //DEBUGMSG(ZONE_TRACE, (TEXT("RILDrv : t : Queueing command with ID: 0x%08x\r\n"), rhrCmdID));

#ifdef RIL_RADIO_RESILIENCE
        EnterCriticalSection(&g_csReboot);
#endif // RIL_RADIO_RESILIENCE

    // Place the command into the command queue
    //    (this may block if the queue is full)
    if (!g_pCmdQ->Put(pCmd, INFINITE))
    {
#ifdef RIL_RADIO_RESILIENCE
        LeaveCriticalSection(&g_csReboot);
#endif // RIL_RADIO_RESILIENCE
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : QueueCmdWithTimeout : Unable to Put CCommand\r\n")));
        goto Error;
    }

#ifdef RIL_RADIO_RESILIENCE
    LeaveCriticalSection(&g_csReboot);
#endif // RIL_RADIO_RESILIENCE

    // If this is a hangup command, and we're in data mode, we should drop out of data mode immediately
    // to handle this request
    /* the below block is disabled by viking wang
    if (pCmd->FHangup() && pRilDevice->GetComDevice()->FDataMode())
    {
        pRilDevice->SetDataEvent();
    }

    if (pCmd->FHangup() || pCmd->FDial() || pCmd->FAnswer())
    {
        SetEvent(g_hNewDialOrHangupEvent);
    }
	*/
    pCmd = NULL;
    fRet = TRUE;

    Error:
    if (!fRet)
    {
        delete pCmd;
        delete pndNotify;
    }
	DEBUGMSG(ZONE_ERROR, (TEXT("-QueueInternalCmd()!\r\n")));
    return fRet;
}

/********end adding by viking wang***************/
//
// Place a multipart command into the Command Queue
//
BOOL QueueMultipartCmd(CRilInstanceHandle* const pHandle, const LPCSTR szCmd, const LPCSTR szCmdPart2, const DWORD dwOptions, const APIID apiid,
              const PFN_CMD_PARSE pfnParse, CNotificationData* const pnd, HRESULT& rhrCmdID)
{
    FUNCTION_TRACE(QueueCmd);
    return QueueCmdWithTimeout(pHandle, szCmd, szCmdPart2, dwOptions, apiid, pfnParse, pnd, rhrCmdID, 0, 0);
}


//
// Place a command into the Command Queue and ignore the response
//
BOOL QueueCmdIgnoreRsp(const APIID apiid, const LPCSTR szCmd, const DWORD dwOptions, DWORD dwTimeout, const PFN_CMD_PARSE pfnParse, CNotificationData* const pnd, DWORD dwRetries, DWORD dwRetriesOnError, DWORD dwRetryOnErrorDelay)
{
    FUNCTION_TRACE(QueueCmdIgnoreRsp);
    DEBUGCHK(0 != (dwOptions & CMDOPT_NOOP) || NULL != szCmd);

    CCommand* pCmd = NULL;
    BOOL fRet = FALSE;

    // Set up a command to be sent
    pCmd = new CCommand;
    if (!pCmd || !pCmd->Init(NULL, szCmd, NULL, dwOptions | CMDOPT_IGNORERSP, EXECTIME_API_DEFAULT, dwTimeout, pnd, pfnParse, dwRetries, dwRetriesOnError, dwRetryOnErrorDelay, apiid, NULL, NULL))
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : QueueCmdIgnoreRsp : Unable to construct or Init CCommand\r\n")));
        goto Error;
    }

#ifdef RIL_RADIO_RESILIENCE
    EnterCriticalSection(&g_csReboot);
#endif // RIL_RADIO_RESILIENCE

    // Place the command into the command queue
    //    (this may block if the queue is full)
    if (!g_pCmdQ->Put(pCmd, INFINITE))
    {
#ifdef RIL_RADIO_RESILIENCE
        LeaveCriticalSection(&g_csReboot);
#endif // RIL_RADIO_RESILIENCE
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : QueueCmdIgnoreRsp : Unable to Put CCommand\r\n")));
        goto Error;
    }
#ifdef RIL_RADIO_RESILIENCE
    LeaveCriticalSection(&g_csReboot);
#endif // RIL_RADIO_RESILIENCE
    pCmd = NULL;
    fRet = TRUE;

    Error:
    if (!fRet)
    {
        delete pCmd;
    }
    return fRet;
}

//
// Place a command into the Command Queue and ignore the response
//
BOOL QueueCmdIgnoreRspWithData(const APIID apiid, const LPCSTR szCmd, const DWORD dwOptions, DWORD dwTimeout, const PFN_CMD_PARSE pfnParse, CNotificationData* const pnd, DWORD dwRetries, DWORD dwRetriesOnError, DWORD dwRetryOnErrorDelay, const PFN_CMD_PARSE_DATA pfnParseWithData, const PVOID pParseData)
{
    FUNCTION_TRACE(QueueCmdIgnoreRsp);
    DEBUGCHK(0 != (dwOptions & CMDOPT_NOOP) || NULL != szCmd);

    CCommand* pCmd = NULL;
    BOOL fRet = FALSE;

    // Set up a command to be sent
    pCmd = new CCommand;
    if (!pCmd || !pCmd->Init(NULL, szCmd, NULL, dwOptions | CMDOPT_IGNORERSP, EXECTIME_API_DEFAULT, dwTimeout, pnd, NULL, dwRetries, dwRetriesOnError, dwRetryOnErrorDelay, apiid, pfnParseWithData, pParseData))
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : QueueCmdIgnoreRsp : Unable to construct or Init CCommand\r\n")));
        goto Error;
    }

#ifdef RIL_RADIO_RESILIENCE
    EnterCriticalSection(&g_csReboot);
#endif // RIL_RADIO_RESILIENCE

    // Place the command into the command queue
    //    (this may block if the queue is full)
    if (!g_pCmdQ->Put(pCmd, INFINITE))
    {
#ifdef RIL_RADIO_RESILIENCE
        LeaveCriticalSection(&g_csReboot);
#endif // RIL_RADIO_RESILIENCE
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : QueueCmdIgnoreRsp : Unable to Put CCommand\r\n")));
        goto Error;
    }
#ifdef RIL_RADIO_RESILIENCE
    LeaveCriticalSection(&g_csReboot);
#endif // RIL_RADIO_RESILIENCE
    pCmd = NULL;
    fRet = TRUE;

    Error:
    if (!fRet)
    {
        delete pCmd;
    }
    return fRet;
}
//
//
//
DWORD WINAPI RequeueThreadProc(LPVOID lpParameter)
{
    FUNCTION_TRACE(RequeueThreadProc);
    REQUEUE_THREAD_DATA* prtd = (REQUEUE_THREAD_DATA*)lpParameter;
    DEBUGCHK(NULL != prtd);
    DEBUGCHK(NULL != prtd->pCmd);

    Sleep(prtd->dwDelay);

#ifdef RIL_RADIO_RESILIENCE
    EnterCriticalSection(&g_csReboot);
#endif // RIL_RADIO_RESILIENCE

    // Place the command into the command queue
    //    (this may block if the queue is full)
    if (!g_pCmdQ->Put(prtd->pCmd, INFINITE))
    {
        delete prtd->pCmd;
    }

#ifdef RIL_RADIO_RESILIENCE
    LeaveCriticalSection(&g_csReboot);
#endif // RIL_RADIO_RESILIENCE

    prtd->pCmd = NULL;
    delete prtd;
    return 0;
}


//
//

⌨️ 快捷键说明

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