misc.cpp

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

CPP
2,215
字号
       {
            // The radio is already on, no need to turn it on again, particularly since we won't get the CPINN
            // notification again, and this will cause the command thread to time out waiting for it.
            dwCmdOpt |= CMDOPT_NOOP;
       }
    }

    // This command is OK to send, even if the radio is "off".
    dwCmdOpt |= CMDOPT_IGNORERADIOOFF;

    // Set a registry key to save the new state of the radio in a location that persists across rebooting
    (void)SetRegistryDWORD(RIL_LAST_EQUIPMENT_STATE_ROOT, RIL_LAST_EQUIPMENT_STATE_KEY, RIL_LAST_EQUIPMENT_STATE_VALUE, dwEquipmentState);

    bool fPrefixPresent=FALSE;

    if (dwCmdOpt & CMDOPT_SETRADIOON) {
        SAFE_PDD_CREATECOMMAND( szWalk, MAX_PATH - (szWalk - szCmd), hr, PDD_CreateCommand_SetupBeforeRadioOn( szWalk, MAX_PATH - (szWalk - szCmd), fPrefixPresent ) );
       
        if ( FAILED( hr ) && E_NOTIMPL != hr )
        {
            DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : PDD_CreateCommand_SetupBeforeRadioOn failed , hr = [0x%08x]\r\n"), hr));
            goto Error;
        }
        
        if (S_OK == hr) {
            szWalk = strchr(szWalk, '\0');  // NO_TYPO: 27
            DEBUGCHK(NULL != szWalk);
            fPrefixPresent = TRUE;
            }
        }

    if (RIL_EQSTATE_MINIMUM == dwEquipmentState) {
        SAFE_PDD_CREATECOMMAND( szWalk, MAX_PATH - (szWalk - szCmd), hr, PDD_CreateCommand_CleanupBeforeRadioOff( szWalk, MAX_PATH - (szWalk - szCmd), fPrefixPresent ) );
        
        if ( FAILED( hr ) && E_NOTIMPL != hr )
        {
            DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : PDD_CreateCommand_CleanupBeforeRadioOff failed , hr = [0x%08x]\r\n"), hr));
            goto Error;
        }
        
        if (S_OK == hr) {
            szWalk = strchr(szWalk, '\0');  // NO_TYPO: 27
            DEBUGCHK(NULL != szWalk);
            fPrefixPresent = TRUE;
            }
        }
    
    if (!fPrefixPresent) {
        (void)_snprintfz(szWalk, MAX_PATH - (szWalk - szCmd), "AT");
        szWalk = strchr(szWalk, '\0');  // NO_TYPO: 27
        DEBUGCHK(NULL != szWalk);
        }
    
    (void)_snprintfz(szWalk, MAX_PATH - (szWalk - szCmd), "+CFUN=%u\r", g_rgdwEquipmentStates[dwEquipmentState]);

    if (!QueueCmd(pHandle, szCmd, dwCmdOpt, APIID_SETEQUIPMENTSTATE, NULL, pnd, hr)) {
        hr = E_FAIL;
        goto Error;
    }

Error:
    if ( g_mtxSetEquipmentState && (WAIT_OBJECT_0 == dwMutexWait) )
    {
        ReleaseMutex(g_mtxSetEquipmentState);
        if ( (RIL_EQSTATE_FULL != dwEquipmentState) &&  (E_INVALIDARG != hr))
        {
            g_bSettingMinimumEquipmentState = FALSE;
        }
    }
    return hr;
}


//
//
//
HRESULT ParseGetPhonebookOptions(LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
    FUNCTION_TRACE(ParseGetPhonebookOptions);
    UINT i;
    UINT nValue;
    char szLocation[MAX_PATH];
    RILPHONEBOOKINFO* prpbi = NULL;
    HRESULT hr = S_OK;
    const LPCSTR* rgszPBLocations = g_rppPDDParams->pstrPhoneBookLocationTable;
    UINT NUM_PBLOCS = g_rppPDDParams->uiPhoneBookLocationTableSize;
    
    pBlob = NULL;
    cbBlob = 0;

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

    // Parse "<prefix>+CPBS: <storage>"
    if (!ParseRspPrefix(szRsp, szRsp) ||
        !MatchStringBeginning(szRsp, "+CPBS: ", szRsp) ||
        !ParseString(szRsp, szLocation, MAX_PATH, szRsp)) {
        hr = E_FAIL;
        goto Error;
    }
    for (i = 0; i < NUM_PBLOCS; i++) {
        if (!strcmp(szLocation, rgszPBLocations[i])) {
            prpbi->dwStoreLocation = i;
            break;
        }
    }
    if (NUM_PBLOCS == i) {
        // We couldn't match the response with anything
        prpbi->dwStoreLocation = RIL_PBLOC_UNKNOWN;
    }
    prpbi->dwParams |= RIL_PARAM_PBI_STORELOCATION;

    // Parse ","
    if (MatchStringBeginning(szRsp, ",", szRsp)) {
        // Parse "<used>"
        if (!ParseUInt(szRsp, TRUE, nValue, szRsp)) {
            hr = E_FAIL;
            goto Error;
        }
        prpbi->dwUsed = nValue;
        prpbi->dwParams |= RIL_PARAM_PBI_USED;

        // Parse ",<total>"
        if (!MatchStringBeginning(szRsp, ",", szRsp) ||
            !ParseUInt(szRsp, TRUE, nValue, szRsp)) {
            hr = E_FAIL;
            goto Error;
        }

        prpbi->dwTotal = nValue;
        prpbi->dwParams |= RIL_PARAM_PBI_TOTAL;
    }

    // Parse "<postfix>"
    if (!ParseRspPostfix(szRsp, szRsp)) {
        hr = E_FAIL;
        goto Error;
    }

    pBlob = (void*)prpbi;
    cbBlob = sizeof(RILPHONEBOOKINFO);

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


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

    if (!QueueCmd(pHandle, "AT+CPBS?\r", CMDOPT_NONE, APIID_GETPHONEBOOKOPTIONS, ParseGetPhonebookOptions, NULL, hr)) {
        hr = E_FAIL;
        goto Error;
    }

Error:
    return hr;
}


//
//
//
HRESULT RILDrv_SetPhonebookOptions(DWORD dwParam, const RILPHONEBOOKINFO* lpPhonebookInfo)
{
    FUNCTION_TRACE(RILDrv_SetPhonebookOptions);
    CNotificationData* pnd = NULL;
    char szCmd[MAX_PATH];
    HRESULT hr = S_OK;

    const LPCSTR* rgszPBLocations = g_rppPDDParams->pstrPhoneBookLocationTable;
#ifdef DEBUG    
    UINT NUM_PBLOCS = g_rppPDDParams->uiPhoneBookLocationTableSize;
#endif

    CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
    if (!pHandle || !lpPhonebookInfo) {
        hr = E_FAIL;
        goto Error;
    }

    // Store location must be specified
    if (!(lpPhonebookInfo->dwParams & RIL_PARAM_PBI_STORELOCATION)) {
        hr = E_INVALIDARG;
        goto Error;
    }

    // Store location index must be in the valid range
    DEBUGCHK(NUM_PBLOCS > lpPhonebookInfo->dwStoreLocation);
    if (RIL_PBLOC_UNKNOWN == lpPhonebookInfo->dwStoreLocation) {
        hr = E_INVALIDARG;
        goto Error;
    }

    pnd = new CNotificationData;
    if (pnd && !pnd->InitFromDWORDBlob(RIL_NOTIFY_PHONEBOOKSTORAGECHANGED, lpPhonebookInfo->dwStoreLocation)) {
        delete pnd;
        pnd = NULL;
    }
    (void)_snprintfz(szCmd, MAX_PATH, "AT+CPBS=\"%s\"\r", rgszPBLocations[lpPhonebookInfo->dwStoreLocation]);
    if (!QueueCmd(pHandle, szCmd, CMDOPT_NONE, APIID_SETPHONEBOOKOPTIONS, NULL, pnd, hr)) {
        hr = E_FAIL;
        goto Error;
    }
    pnd = NULL;

#ifdef RIL_RADIO_RESILIENCE
    g_fPBLocationSet = TRUE;
    (void)strncpyz(g_szPBLocCmd, szCmd, ARRAYSIZE(g_szPBLocCmd));
#endif // RIL_RADIO_RESILIENCE

Error:
    return hr;
}

static inline
void
ConvertDTMFControlDigitSeparatorCharacter(
   __inout_ecount( AddrCch ) const LPWSTR Addr,
   __in const size_t AddrCch
   )
{
   ASSERT( Addr && AddrCch );
   for ( LPWSTR AddrItor = Addr;
         AddrItor && *AddrItor && (size_t)(AddrItor - Addr) < AddrCch;
         ++AddrItor )
      {
      if ( L'W' == *AddrItor || L'w' == *AddrItor )
         {
         *AddrItor = L'p';
         }
      }
}

//
//
//
static HRESULT ParseArrayOfPhonebookEntries(LPCSTR szCmd, LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
    FUNCTION_TRACE(ParseArrayOfPhonebookEntries);
    UINT nValue;
    UINT nUsed = 0;
    UINT nAllocated = 0;
    char szAddress[MAXLENGTH_ADDRESS];
    WCHAR wszText[MAXLENGTH_PHONEBOOKTEXT];
    RILPHONEBOOKENTRY* rgrbpe = NULL;
    HRESULT hr = S_OK;

    pBlob = NULL;
    cbBlob = 0;

    // Parse "<prefix>"
    if (!ParseRspPrefix(szRsp, szRsp)) {
        hr = E_FAIL;
        goto Error;
    }

    // Parse "<command>"
    while (MatchStringBeginning(szRsp, szCmd, szRsp)) {
        if (nUsed == nAllocated) {
            if (!AllocateOrReallocateStorage((BYTE**)&rgrbpe, sizeof(RILPHONEBOOKENTRY), nUsed, &nAllocated, MISC_ALLOC_NUMBER)) {
                hr = E_OUTOFMEMORY;
                goto Error;
            }
        }

        memset(&rgrbpe[nUsed], 0x00, sizeof(RILPHONEBOOKENTRY));
        rgrbpe[nUsed].cbSize = sizeof(RILPHONEBOOKENTRY);

        // Parse "<index>"
        if (!ParseUInt(szRsp, TRUE, nValue, szRsp)) {
            goto Continue;
        }
        rgrbpe[nUsed].dwIndex = nValue;
        rgrbpe[nUsed].dwParams |= RIL_PARAM_PBE_INDEX;

        // clear buffer before reusing
        memset(szAddress, 0x00, sizeof(szAddress));

        // Parse ",<number>,<type>"
        if (!MatchStringBeginning(szRsp, ",", szRsp)                     ||
            !ParseString(szRsp, szAddress, MAXLENGTH_ADDRESS, szRsp)     ||
            !MatchStringBeginning(szRsp, ",", szRsp)                     ||
            !ParseUIntAndVerifyAbove(szRsp, FALSE, 0x100, nValue, szRsp) ||
            !StringToRILAddress(szAddress, (BYTE)nValue, rgrbpe[nUsed].raAddress)) {
            goto Continue;
        }
        rgrbpe[nUsed].dwParams |= RIL_PARAM_PBE_ADDRESS;
        ConvertDTMFControlDigitSeparatorCharacter( rgrbpe[nUsed].raAddress.wszAddress,
                                                   sizeof(rgrbpe[nUsed].raAddress.wszAddress) / sizeof(*(rgrbpe[nUsed].raAddress.wszAddress)) );

        // clear buffer before reusing
        memset(wszText, 0x00, sizeof(wszText));

        // Parse ",<text>"
        if (!MatchStringBeginning(szRsp, ",", szRsp) ||
            !ParseQuotedEncodedString(g_rppPDDParams->etEncodingTECharset, szRsp, wszText, wszText + MAXLENGTH_PHONEBOOKTEXT)) {
            goto Continue;
        }
        (void)wcsncpyz(rgrbpe[nUsed].wszText, wszText, MAXLENGTH_PHONEBOOKTEXT);
        rgrbpe[nUsed].dwParams |= RIL_PARAM_PBE_TEXT;

        // Increment the array index
        nUsed++;

Continue:
        // Find "<postfix>"
        if (!FindRspPostfix(szRsp, szRsp)) {
            hr = E_FAIL;
            goto Error;
        }
    }

    pBlob = (void*)rgrbpe;
    cbBlob = nUsed * sizeof(RILPHONEBOOKENTRY);

Error:
    if (FAILED(hr)) {
        delete[] (BYTE*)rgrbpe;
    }
    return hr;
}


//
//
//
static HRESULT ParseReadPhonebookEntries(LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
    FUNCTION_TRACE(ParseReadPhonebookEntries);
    return ParseArrayOfPhonebookEntries("+CPBR: ", szRsp, pBlob, cbBlob);
}


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

    (void)_snprintfz(szCmd, MAX_PATH, "AT+CPBR=%u,%u\r", dwStartIndex, dwEndIndex);
    if (!QueueCmd(pHandle, szCmd, CMDOPT_NONE, APIID_READPHONEBOOKENTRIES, ParseReadPhonebookEntries, NULL, hr)) {
        hr = E_FAIL;
        goto Error;
    }

Error:
    return hr;
}


//
//
//
HRESULT RILDrv_WritePhonebookEntry(DWORD dwParam, const RILPHONEBOOKENTRY* lpEntry)
{
    FUNCTION_TRACE(RILDrv_WritePhonebookEntry);
    CNotificationData* pnd = NULL;
    BYTE bTypeOfAddress;
    char szAddress[MAXLENGTH_ADDRESS];
    char szCmd[MISC_CMDBUF_LENGTH_PB];
    LPSTR szWalk = szCmd;
    HRESULT hr = S_OK;
    CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
    if (!pHandle || !lpEntry) {
        hr = E_FAIL;
        goto Error;
    }

    if (!(lpEntry->dwParams & RIL_PARAM_PBE_INDEX) || !(lpEntry->dwParams & RIL_PARAM_PBE_ADDRESS)) {
        hr = E_INVALIDARG;
        goto Error;
    }

    // Determine address and type-of-address byte
    hr = RILAddressToString(lpEntry->raAddress, szAddress, MAXLENGTH_ADDRESS, bTypeOfAddress);
    if (FAILED(hr)) {
        goto Error;
    }

    if (RIL_PBINDEX_FIRSTAVAILABLE == lpEntry->dwIndex) {
        (void)_snprintfz(szWalk, MISC_CMDBUF_LENGTH_PB - (szWalk - szCmd), "AT+CPBW=,\"%s\",%u", szAddress, bTypeOfAddress);
    } else {
        (void)_snprintfz(szWalk, MISC_CMDBUF_LENGTH_PB - (szWalk - szCmd), "AT+CPBW=%u,\"%s\",%u", lpEntry->dwIndex, szAddress,
                         bTypeOfAddress);
    }
    szWalk = strchr(szWalk, '\0');  // NO_TYPO: 27
    DEBUGCHK(NULL != szWalk);

    // Add text, if supplied
    if (lpEntry->dwParams & RIL_PARAM_PBE_TEXT) {
        (void)strncpyz(szWalk, ",", MISC_CMDBUF_LENGTH_PB - (szWalk - szCmd));  // NO_TYPO: 30
        szWalk = strchr(szWalk, '\0');  // NO_TYPO: 27
        DEBUGCHK(NULL != szWalk);

        if (!AppendQuotedEncodedString(g_rppPDDParams->etEncodingTECharset, lpEntry->wszText, szWalk, (PUCHAR)&szCmd[MISC_CMDBUF_LENGTH_PB], ALLOW_UNICODE_PB_ENTRIES))
        {
            hr = E_FAIL;
            goto Error;
        }

    }
    (void)strncpyz(szWalk, "\r", MISC_CMDBUF_LENGTH_PB - (szWalk - szCmd));  // NO_TYPO: 30

    pnd = new CNotificationData;
    if (pnd && !pnd->InitFromDWORDBlob(RIL_NOTIFY_PHONEBOOKENTRYSTORED, lpEntry->dwIndex)) {
        delete pnd;
        pnd = NULL;
    }
    if (!QueueCmd(pHandle, szCmd, CMDOPT_NONE, APIID_WRITEPHONEBOOKENTRY, NULL, pnd, hr)) {
        hr = E_FAIL;
        goto Error;
    }
    pnd = NULL;

Error:
    return hr;

⌨️ 快捷键说明

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