misc.cpp

来自「ril source code for Windows CE」· C++ 代码 · 共 2,215 行 · 第 1/5 页

CPP
2,215
字号
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
/*++
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.

Module Name:

misc.cpp

Abstract:


Notes:


--*/


#include "precomp.h"
#include "connection.h"

#ifdef RIL_ALLOW_UNICODE_PBENTRIES
#define ALLOW_UNICODE_PB_ENTRIES TRUE
#else
#define ALLOW_UNICODE_PB_ENTRIES FALSE
#endif

extern BOOL g_bRadioOff;
extern BOOL g_bSettingMinimumEquipmentState;
HANDLE g_mtxSetEquipmentState = NULL;

//
// Equipment states
//
static const DWORD g_rgdwEquipmentStates[] =
{
    0xFFFFFFFF,     // RIL_EQSTATE_UNKNOWN
    0,      // RIL_EQSTATE_MINIMUM
    1,      // RIL_EQSTATE_FULL
    2,      // RIL_EQSTATE_DISABLETX
    3,      // RIL_EQSTATE_DISABLERX
    4,      // RIL_EQSTATE_DISABLETXANDRX
};
#define NUM_EQSTATES    (sizeof(g_rgdwEquipmentStates) / sizeof(DWORD))

//
// Bit error rates
//
static const DWORD g_rgdwBitErrorRates[] =
{
    14,     // 0
    28,     // 1
    57,     // 2
    113,    // 3
    226,    // 4
    453,    // 5
    905,    // 6
    1810,   // 7
};
#define NUM_BITERRORRATES     (sizeof(g_rgdwBitErrorRates) / sizeof(DWORD))


//
// Restricted SIM commands
//
extern const DWORD g_rgdwRestrictedSIMCmds[] =
{
    0xFFFFFFFF,     // 0
    176,    // RIL_SIMCMD_READBINARY
    178,    // RIL_SIMCMD_READRECORD
    192,    // RIL_SIMCMD_GETRESPONSE
    214,    // RIL_SIMCMD_UPDATEBINARY
    220,    // RIL_SIMCMD_UPDATERECORD
    242,    // RIL_SIMCMD_STATUS
};
#define NUM_RESTRICTEDSIMCMDS   (sizeof(g_rgdwRestrictedSIMCmds) / sizeof(DWORD))


//
//
//
static const DWORD g_rgdwSIMToolkitTermCauses[] =
{
    0xFFFFFFFF,     // 0
    0,      // RIL_SIMTKITTERMCAUSE_USERSTOPPEDREDIAL
    1,      // RIL_SIMTKITTERMCAUSE_ENDOFREDIAL
    2,      // RIL_SIMTKITTERMCAUSE_USERENDEDSESSION
};
#define NUM_SIMTOOLKITTERMCAUSES   (sizeof(g_rgdwSIMToolkitTermCauses) / sizeof(DWORD))


//
//
//
HRESULT ParseGetEquipmentInfo(LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
    FUNCTION_TRACE(ParseGetEquipmentInfo);
    RILEQUIPMENTINFO* prei = NULL;
#ifdef RIL_WATSON_REPORT
    RILEQUIPMENTINFO* preiCache = &(g_RilInfoCache.rileiEquipmentInfo);
#endif // RIL_WATSON_REPORT
    HRESULT hr = S_OK;

    pBlob = NULL;
    cbBlob = 0;

    prei = (RILEQUIPMENTINFO*)AllocBlob(sizeof(RILEQUIPMENTINFO));
    if (!prei) {
        hr = E_OUTOFMEMORY;
        goto Error;
    }
    memset(prei, 0x00, sizeof(RILEQUIPMENTINFO));
    prei->cbSize = sizeof(RILEQUIPMENTINFO);

#ifdef RIL_WATSON_REPORT
    // Clear equipment info cache
    memset(preiCache, 0x00, sizeof(RILEQUIPMENTINFO));
    preiCache->cbSize = sizeof(RILEQUIPMENTINFO);
#endif // RIL_WATSON_REPORT

    // Parse "<prefix><manufacturer_id><postfix>"
    if (!ParseRspPrefix(szRsp, szRsp)                                                       ||
        !ParseUnquotedString(szRsp, '\r', prei->szManufacturer, MAXLENGTH_EQUIPINFO, szRsp) ||
        !ParseRspPostfix(szRsp, szRsp)) {
        hr = E_FAIL;
        goto Error;
    }
    prei->dwParams |= RIL_PARAM_EI_MANUFACTURER;

#ifdef RIL_WATSON_REPORT
    // Copy to cache
    strncpy(preiCache->szManufacturer, prei->szManufacturer, MAXLENGTH_EQUIPINFO);    
    preiCache->dwParams |= RIL_PARAM_EI_MANUFACTURER;
#endif // RIL_WATSON_REPORT

    // Parse "<prefix><model_id><postfix>"
    if (!ParseRspPrefix(szRsp, szRsp)                                                ||
        !ParseUnquotedString(szRsp, '\r', prei->szModel, MAXLENGTH_EQUIPINFO, szRsp) ||
        !ParseRspPostfix(szRsp, szRsp)) {
        hr = E_FAIL;
        goto Error;
    }
    prei->dwParams |= RIL_PARAM_EI_MODEL;

#ifdef RIL_WATSON_REPORT
    // Copy to cache
    strncpy(preiCache->szModel, prei->szModel, MAXLENGTH_EQUIPINFO);
    preiCache->dwParams |= RIL_PARAM_EI_MODEL;
#endif // RIL_WATSON_REPORT

    // Parse "<prefix><revision_id><postfix>"
    if (!ParseRspPrefix(szRsp, szRsp)                                                   ||
        !ParseUnquotedString(szRsp, '\r', prei->szRevision, MAXLENGTH_EQUIPINFO, szRsp) ||
        !ParseRspPostfix(szRsp, szRsp)) {
        hr = E_FAIL;
        goto Error;
    }
    prei->dwParams |= RIL_PARAM_EI_REVISION;

#ifdef RIL_WATSON_REPORT
    // Copy to cache
    strncpy(preiCache->szRevision, prei->szRevision, MAXLENGTH_EQUIPINFO);
    preiCache->dwParams |= RIL_PARAM_EI_REVISION;
#endif // RIL_WATSON_REPORT

    // Parse "<prefix><serial_number><postfix>"
    if (!ParseRspPrefix(szRsp, szRsp)                                                       ||
        !ParseUnquotedString(szRsp, '\r', prei->szSerialNumber, MAXLENGTH_EQUIPINFO, szRsp) ||
        !ParseRspPostfix(szRsp, szRsp)) {
        hr = E_FAIL;
        goto Error;
    }
    prei->dwParams |= RIL_PARAM_EI_SERIALNUMBER;

#ifdef RIL_WATSON_REPORT
    // Copy to cache
    strncpy(preiCache->szSerialNumber, prei->szSerialNumber, MAXLENGTH_EQUIPINFO);
    preiCache->dwParams |= RIL_PARAM_EI_SERIALNUMBER;
#endif // RIL_WATSON_REPORT

    pBlob = (void*)prei;
    cbBlob = sizeof(RILEQUIPMENTINFO);

Error:
    if (FAILED(hr)) {
        FreeBlob(prei);
    }
    return hr;
}


//
//
//
HRESULT RILDrv_GetEquipmentInfo(DWORD dwParam)
{
    FUNCTION_TRACE(RILDrv_GetEquipmentInfo);
    HRESULT hr = S_OK;
    char szCmd[MAX_PATH];
        
    CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
    if (!pHandle) {
        hr = E_FAIL;
        goto Error;
    }

    SAFE_PDD_CREATECOMMAND( szCmd, MAX_PATH, hr, PDD_CreateCommand_GetEquipmentInfo( szCmd, MAX_PATH ) );
    
    if ( FAILED( hr ) )
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : PDD_CreateCommand_GetEquipmentInfo failed , hr = [0x%08x]\r\n"), hr));
        goto Error;
    }    

    if (!QueueCmd(pHandle, szCmd, CMDOPT_NONE, APIID_GETEQUIPMENTINFO, ParseGetEquipmentInfo, NULL, hr)) {
        hr = E_FAIL;
        goto Error;
    }

Error:
    return hr;
}

//
// Helper function to fill RILEQUIPMENTSTATE structure and implement
// driver-specific RIL_RADIOSUPPORT_* mapping.
//
void FillEquipmentStateStruct(RILEQUIPMENTSTATE * pres, DWORD dwEqState)
{
    DEBUGCHK(NULL != pres);

    memset(pres, 0x00, sizeof(RILEQUIPMENTSTATE));

    pres->cbSize = sizeof(RILEQUIPMENTSTATE);
    pres->dwParams = RIL_PARAM_EQUIPMENTSTATE_ALL;
    pres->dwEqState = dwEqState;
    pres->dwReadyState = g_dwReadyState;
    if (RIL_EQSTATE_UNKNOWN == dwEqState)
    {
        pres->dwRadioSupport = RIL_RADIOSUPPORT_UNKNOWN;
    }
    else
    {
        pres->dwRadioSupport = (dwEqState == RIL_EQSTATE_FULL) ? RIL_RADIOSUPPORT_ON : RIL_RADIOSUPPORT_OFF;
    }
}

//
//
//
HRESULT ParseGetEquipmentState(LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
    FUNCTION_TRACE(ParseGetEquipmentState);
    UINT nValue;
    DWORD dwState=RIL_EQSTATE_UNKNOWN;
    RILEQUIPMENTSTATE * pres = NULL;
    UINT i;
    HRESULT hr = S_OK;

    pBlob = NULL;
    cbBlob = 0;

    pres = (RILEQUIPMENTSTATE*)AllocBlob(sizeof(RILEQUIPMENTSTATE));
    if (!pres) {
        hr = E_OUTOFMEMORY;
        goto Error;
    }

    // Parse "<prefix>+CFUN: <state><postfix>"
    // In case there are leading commands, use FindRspPostFix instead of
    // ParseResponsePrefix.
    if (0 != strncmp( szRsp, "+CFUN: " , strlen("+CFUN: "))) {
        if (!FindRspPostfix(szRsp, szRsp)) {
            hr = E_FAIL;
            goto Error;
        }
    }

    if (!ParseRspPrefix(szRsp, szRsp)                  ||
        !MatchStringBeginning(szRsp, "+CFUN: ", szRsp) ||
        !ParseUInt(szRsp, TRUE, nValue, szRsp)         ||
        !ParseRspPostfix(szRsp, szRsp)) {
        hr = E_FAIL;
        goto Error;
    }

    for (i = 0; i < NUM_EQSTATES; i++) {
        if (nValue == g_rgdwEquipmentStates[i]) {
            dwState = i;
            break;
        }
    }
    if (NUM_EQSTATES == i) {
        // We couldn't match the response with anything
        dwState = RIL_EQSTATE_UNKNOWN;
    }

    FillEquipmentStateStruct(pres, dwState);

    pBlob = (void*)pres;
    cbBlob = pres->cbSize;

    if (g_rppPDDParams->fIsRadioOffInMinimumPowerState) {
       g_bRadioOff = (dwState == RIL_EQSTATE_MINIMUM);
       }

Error:
    if (FAILED(hr)) {
        FreeBlob(pres);
    }
    return hr;
}


//
//
//
HRESULT RILDrv_GetEquipmentState(DWORD dwParam)
{
    FUNCTION_TRACE(RILDrv_GetEquipmentState);
    HRESULT hr = S_OK;
    CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
    if (!pHandle) {
        hr = E_FAIL;
        goto Error;
    }

    if (!QueueCmd(pHandle, "AT+CFUN?\r", CMDOPT_IGNORERADIOOFF, APIID_GETEQUIPMENTSTATE, ParseGetEquipmentState, NULL, hr)) {
        hr = E_FAIL;
        goto Error;
    }

Error:
    return hr;
}

extern DWORD g_dwNumCallsInCallList;
#define MAX_EQUPMENTSTATE_WAIT 60L * 1000L
//
//
//
HRESULT RILDrv_SetEquipmentState(DWORD dwParam, DWORD dwEquipmentState)
{
    FUNCTION_TRACE(RILDrv_SetEquipmentState);
    DEBUGCHK(NUM_EQSTATES > dwEquipmentState);

    DWORD dwMutexWait = WAIT_TIMEOUT;
    DWORD dwCmdOpt = CMDOPT_NONE;

    char szCmd[MAX_PATH];
    LPSTR szWalk = szCmd;
    
    HRESULT hr = S_OK;
    CNotificationData * pnd = NULL;
    RILEQUIPMENTSTATE res;
    CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
    if (!pHandle) {
        hr = E_FAIL;
        goto Error;
    }

    if (RIL_EQSTATE_UNKNOWN == dwEquipmentState) {
        hr = E_INVALIDARG;
        goto Error;
    }

    if (NULL == g_mtxSetEquipmentState )
    {
        g_mtxSetEquipmentState = CreateMutex(NULL,FALSE,NULL);
        if ( NULL == g_mtxSetEquipmentState )
        {
            hr = E_FAIL;
            goto Error;
        }
    }

    dwMutexWait = WaitForSingleObject( g_mtxSetEquipmentState, MAX_EQUPMENTSTATE_WAIT);
    ASSERT( WAIT_OBJECT_0 == dwMutexWait );
    if ( WAIT_TIMEOUT == dwMutexWait )
    {
        hr = E_FAIL;
        goto Error;
    }
    if ( RIL_EQSTATE_FULL != dwEquipmentState )
    {
        g_bSettingMinimumEquipmentState = TRUE;
        // Call into the PDD to close active voice and data connections. 
        // The call is synchronous; it won't return until it has completed the necessary actions.
        CloseVoiceAndDataConnections* pCloseConnections = new CloseVoiceAndDataConnections;
        if ( pCloseConnections )
        {
            pCloseConnections->CloseAllConnections(pHandle);
            pCloseConnections->DegisterFromNetwork();
            delete pCloseConnections;
        }
    }

    FillEquipmentStateStruct(&res, dwEquipmentState);
    if (res.dwRadioSupport == RIL_RADIOSUPPORT_OFF)
    {
        // We'll be turning the radio off
        res.dwReadyState = 0;
        g_dwGPRSRegStatus = RIL_REGSTAT_UNKNOWN;
        g_dwRegStatus = RIL_REGSTAT_UNKNOWN;      

#ifdef RIL_WATSON_REPORT        
        // Reset registration status in info cache.
        g_RilInfoCache.dwRegStatus = RIL_REGSTAT_UNKNOWN;
        g_RilInfoCache.dwGPRSRegStatus = RIL_REGSTAT_UNKNOWN;
#endif // RIL_WATSON_REPORT  

    }

    pnd = new CNotificationData;
    if (pnd && !pnd->InitFromRealBlob(RIL_NOTIFY_RADIOEQUIPMENTSTATECHANGED, (void*)&res, res.cbSize))
    {
        delete pnd;
        pnd = NULL;
    }

    // If this command will turn on the radio, then
    // note this in the command option. If this option
    // is not set for the SETEQUIPMENTSTATE command,
    // then it is assumed that it turns off the radio.
    if (RIL_RADIOSUPPORT_ON == res.dwRadioSupport)
    {
        dwCmdOpt |= CMDOPT_SETRADIOON;
        dwCmdOpt |= CMDOPT_REINIT;

       if ((FALSE ==  g_bRadioOff) && g_rppPDDParams->fDontTurnRadioOnIfAlreadyOn)

⌨️ 快捷键说明

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