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

📄 misc.cpp

📁 手机RILGSM实现的源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    DEBUGCHK(NULL != szPrefixWalk);

    // Add ",<p1>,<p2>,<p3>" to prefix string
    (void)_snprintfz(szPrefixWalk, MAX_PATH - (szPrefixWalk - szPrefix), ",%u,%u,%u",
                     dwParameter1, dwParameter2, dwParameter3);

    // If there's data, add a comma before that data
    if (dwDataSize)
    {
        strcat(szPrefixWalk, ",");
    }

    // Add "<prefix>\"<data>\"<CR>"
    // NOTE: we take ownership of allocated szCmd
    if (!ComposeCmdWithByteArray(szPrefix, lpbData, dwDataSize, "\r", szCmd)) {
        hr = E_OUTOFMEMORY;
        goto Error;
    }

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

Error:
    delete szCmd;

#elif !defined(WAVECOM_DRIVER) // WAVECOM_DRIVER
    // HW-SPECIFIC: WaveCom doesn't support AT+CSIM
    // Send down a SELECT command to find out information about this file

    BYTE rgbSelect[] = { 0xA4, 0x00, 0x00, 0x02, 0x00, 0x00 };
    DWORD dwSize = sizeof(rgbSelect);
    LPSTR szCmd = NULL;
    char szPrefix[MAX_PATH];
    HRESULT hr = S_OK;
    CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
    if (!pHandle) {
        hr = E_FAIL;
        goto Error;
    }

    // Set the file ID in the last two bytes, please
    rgbSelect[4] = (BYTE) ((dwFileID & 0xff00) >> 8);
    rgbSelect[5] = (BYTE) (dwFileID & 0x00ff);

    // Add "AT+CSIM=<length>," to prefix string
    (void)_snprintfz(szPrefix, MAX_PATH, "AT+CSIM=%u,", dwSize * 2);

    // Add "<prefix>\"<command>\"<CR>"
    // NOTE: we take ownership of allocated szCmd
    if (!ComposeCmdWithByteArray(szPrefix, rgbSelect, dwSize, "\r", szCmd)) {
        hr = E_OUTOFMEMORY;
        goto Error;
    }

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

Error:
    delete szCmd;

#else  // OEM1_DRIVER || OEM2_DRIVER

    HRESULT hr = E_NOTIMPL;
#endif // OEM1_DRIVER || OEM2_DRIVER

    return hr;
}


//
//
//
static HRESULT ParseGetSimToolkitProfile(LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
    FUNCTION_TRACE(ParseGetSimToolkitProfile);
    UINT i;
    UINT nValue;
    UINT cbProfileString;
    LPSTR szProfileString = NULL;
    LPSTR pchProfileStringWalk;
    UINT cbProfile;
    BYTE* pbProfileWalk;
    BYTE* pbProfile = NULL;
    HRESULT hr = S_OK;

    pBlob = NULL;
    cbBlob = 0;

    // Parse "<prefix>%SATC: <mode>,"
    if (!ParseRspPrefix(szRsp, szRsp)                  ||
        !MatchStringBeginning(szRsp, "%SATC: ", szRsp) ||
        !ParseUInt(szRsp, TRUE, nValue, szRsp)         ||
        !MatchStringBeginning(szRsp, ",", szRsp)) {
        hr = E_FAIL;
        goto Error;
    }

    // Parse "<profile>"
    // NOTE: we take ownership of allocated szProfileString
    if (!ParseUnlimitedUnquotedString(szRsp, '\r', szProfileString, cbProfileString, szRsp)) {
        hr = E_FAIL;
        goto Error;
    }
    DEBUGCHK(0 == (cbProfileString - 1) % 2);
    cbProfile = (cbProfileString - 1) / 2;

    // Allocate the byte array of needed size
    pbProfile = (BYTE*)AllocBlob(cbProfile);
    if (!pbProfile) {
        hr = E_OUTOFMEMORY;
        goto Error;
    }

    // Decode the profile
    pbProfileWalk = pbProfile;
    pchProfileStringWalk = szProfileString;
    for (i = 0; i < cbProfile; i++) {
        *pbProfileWalk = SemiByteCharsToByte(*pchProfileStringWalk, *(pchProfileStringWalk + 1));
        pbProfileWalk++;
        pchProfileStringWalk += 2;
    }

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

    pBlob = (void*)pbProfile;
    cbBlob = cbProfile;

Error:
    if (FAILED(hr)) {
        FreeBlob(pbProfile);
    }
    delete[] szProfileString;
    return hr;
}


//
//
//
HRESULT RILDrv_GetSimToolkitProfile(DWORD dwParam)
{
    FUNCTION_TRACE(RILDrv_GetSimToolkitProfile);
#if defined(RIL_ENABLE_SIMTK) && defined(OEM1_DRIVER)
    // HW-SPECIFIC: This uses a OEM1-specific AT%SATC command

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

    if (!QueueCmd(pHandle, "AT%SATC?\r", CMDOPT_NONE, APIID_GETSIMTOOLKITPROFILE, ParseGetSimToolkitProfile, NULL, hr)) {
        hr = E_FAIL;
        goto Error;
    }

Error:
#else  // OEM1_DRIVER

    HRESULT hr = E_NOTIMPL;
#endif // OEM1_DRIVER

    return hr;
}


//
//
//
HRESULT RILDrv_SetSimToolkitProfile(DWORD dwParam, const BYTE* lpbProfile, DWORD dwSize)
{
    FUNCTION_TRACE(RILDrv_SetSimToolkitProfile);
#if (defined(RIL_ENABLE_SIMTK) && defined(OEM1_DRIVER)) || defined(OEM2_SIMTOOLKIT)
    // HW-SPECIFIC: This uses a OEM1-specific AT%SATC command

    DEBUGCHK(NULL != lpbProfile);
    DEBUGCHK(0 != dwSize);

    CHAR szPrefix[MAX_PATH];
    HRESULT hr = S_OK;
    CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
    if (!pHandle || !lpbProfile) {
        hr = E_FAIL;
        goto Error;
    }

    // Store terminal profile
    if (!g_RilSTKTerminalProfile.SetByte((const LPBYTE)lpbProfile, dwSize))
    {
        hr = E_FAIL;
        goto Error;
    }

#if defined(OEM2_SIMTOOLKIT)
    _snprintfz(szPrefix, ARRAY_LENGTH(szPrefix),"AT+STPD=%d,%s\r", g_RilSTKTerminalProfile.GetSize(), g_RilSTKTerminalProfile.GetText());
#else
    _snprintfz(szPrefix, ARRAY_LENGTH(szPrefix),"AT%%SATC=1,%s;+CFUN=1\r", g_RilSTKTerminalProfile.GetText());
#endif

    if (!QueueCmd(pHandle, szPrefix, CMDOPT_NONE, APIID_SETSIMTOOLKITPROFILE, NULL, NULL, hr)) {
        hr = E_FAIL;
        goto Error;
    }

Error:
#else  // OEM1_DRIVER

    HRESULT hr = E_NOTIMPL;
#endif // OEM1_DRIVER

    return hr;
}


//
//
//
static HRESULT ParseSendSimToolkitEnvelopeCmd(LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
    FUNCTION_TRACE(ParseSendSimToolkitEnvelopeCmd);
    UINT i;
    UINT cbResponseString;
    LPSTR szResponseString = NULL;
    LPSTR pchResponseStringWalk;
    UINT cbResponse;
    BYTE* pbResponseWalk;
    BYTE* pbResponse = NULL;
    HRESULT hr = S_OK;

    pBlob = NULL;
    cbBlob = 0;

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

    // Parse "<response>"
    // NOTE: we take ownership of allocated szResponseString
    if (!ParseUnlimitedUnquotedString(szRsp, '\r', szResponseString, cbResponseString, szRsp)) {
        hr = E_FAIL;
        goto Error;
    }
    DEBUGCHK(0 == (cbResponseString - 1) % 2);
    cbResponse = (cbResponseString - 1) / 2;

    // Allocate the byte array of needed size
    pbResponse = (BYTE*)AllocBlob(cbResponse);
    if (!pbResponse) {
        hr = E_OUTOFMEMORY;
        goto Error;
    }

    // Decode the response
    pbResponseWalk = pbResponse;
    pchResponseStringWalk = szResponseString;
    for (i = 0; i < cbResponse; i++) {
        *pbResponseWalk = SemiByteCharsToByte(*pchResponseStringWalk, *(pchResponseStringWalk + 1));
        pbResponseWalk++;
        pchResponseStringWalk += 2;
    }

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

    pBlob = (void*)pbResponse;
    cbBlob = cbResponse;

Error:
    if (FAILED(hr)) {
        FreeBlob(pbResponse);
    }
    delete[] szResponseString;
    return hr;
}


//
//
//
HRESULT RILDrv_SendSimToolkitEnvelopeCmd(DWORD dwParam, const BYTE* lpbCommand, DWORD dwSize)
{
    FUNCTION_TRACE(RILDrv_SendSimToolkitEnvelopeCmd);
#if defined(RIL_ENABLE_SIMTK) && defined(OEM1_DRIVER) && !defined(OEM2_SIMTOOLKIT)

    // HW-SPECIFIC: This uses a OEM1-specific AT%SATE command
    DEBUGCHK(NULL != lpbCommand);
    DEBUGCHK(0 != dwSize);

    LPSTR szCmd = NULL;
    HRESULT hr = S_OK;
    CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
    if (!pHandle || !lpbCommand) {
        hr = E_FAIL;
        goto Error;
    }

    // Add "AT%SATE=<command><CR>"
    // NOTE: we take ownership of allocated szCmd
    if (!ComposeCmdWithByteArray("AT%SATE=", lpbCommand, dwSize, "\r", szCmd)) {
        hr = E_OUTOFMEMORY;
        goto Error;
    }

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

Error:
    delete szCmd;

#elif defined(OEM2_SIMTOOLKIT)
    // For OEM2, we really aren't sending a Envelope command, since OEM2 does
    // not have such a command. However, the RILDrv_SendSimToolkitEnvelopeCmd
    // call is used exclusively to select a menu item from the main menu.
    // To maintain API compatibility RILDrv_SendSimToolkitEnvelopeCmd will
    // send the OEM2 Menu Selection command +STMS.

    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+STMS=%s\r", lpbCommand);
    if (!QueueCmd(pHandle, szCmd, CMDOPT_NONE, APIID_SENDSIMTOOLKITENVELOPECMD, NULL, NULL, hr)) {
        hr = E_FAIL;
        goto Error;
    }

Error:

#else  // OEM1_DRIVER

    HRESULT hr = E_NOTIMPL;
#endif // OEM1_DRIVER

    return hr;
}


//
//
//
//
HRESULT RILDrv_SendSimToolkitCmdResponse(DWORD dwParam, const RILSIMTOOLKITRSP* pRsp, LPBYTE pDetails, const DWORD dwDetailSize)
{
    FUNCTION_TRACE(RILDrv_SendSimToolkitCmdResponse);

#if  defined(OEM1_DRIVER) || defined(OEM2_SIMTOOLKIT)
    LPSTR szCmd = NULL;
    LPSTR szCmdPrefix = NULL;
    LPSTR szCmdSuffix = NULL;
    LPSTR szResponse = NULL;
    DWORD dwSize = 0;
    DWORD dwCmdSize = 0;
    CRilSimToolkitResponse crstrRsp;
    CRilInstanceHandle* pHandle;
    HRESULT hr = S_OK;


    pHandle = ExtractHandle(dwParam);

    DEBUGCHK(NULL != pRsp);
    DEBUGCHK(NULL != pHandle);

    if (!pHandle || !pRsp) {
        hr = E_FAIL;
        goto Error;
    }

    // Check for needed values in the response parameter. We need to command
    // type to determine the correct AT command to send to the radio.
    if (!(RIL_PARAM_SIMTKIT_RSP_TYPE & pRsp->dwParams)) {
        DEBUGCHK(FALSE);
        hr = E_FAIL;
        goto Error;
    }

    // Create a radio formatted response. The CRilSimToolkitResponse class
    // will automatically parse the command appropriately for specific radio.
    hr = crstrRsp.CreateResponse(pRsp, pDetails, dwDetailSize, &szResponse, &dwSize);

    if (FAILED(hr)) {
        DEBUGCHK(FALSE);
        goto Error;
    }
    else if(0 >= dwSize) {
        // CreateResponse did not create a response for this command,
        // which is acceptable. Don't send anything to the radio
        // if a response was not created.
        hr = E_FAIL;
        goto Error;
    }

    // Setup the AT command prefix and suffix according to what radio we are using.
    // We send out a different command for Setup Menu replies.
#if defined(OEM2_SIMTOOLKIT)
    if (SIM_NOTIFY_SETUPMENU_REPLY == pRsp->dwType) {
        szCmdPrefix = "AT+STMS=";
    }
    else {
        szCmdPrefix = "AT+STCR=";
    }
#elif defined(OEM1_DRIVER)
    // For newer OEM1 stacks the SIM toolkit envelope and response command can have quotes
    // (but are not required) around the data portion of the response. Although, having
    // quotes around the data is a more proper form, we do not add them at this time to
    // remain 

⌨️ 快捷键说明

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