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

📄 gprs.cpp

📁 ril source code for Windows CE
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    FlagFromString(szValue,g_GprsClass,NUM_GPRSCLASS,*pdwClass);

    pBlob = (void*)pdwClass;
    cbBlob = sizeof(DWORD);
    hr = S_OK;

    Error:
    if (FAILED(hr))
    {
        FreeBlob(pdwClass);
    }

    return hr;
}

// +CGCLASS?
HRESULT RILDrv_GetGPRSClass (DWORD dwParam)
{
    FUNCTION_TRACE(RILDrv_GetGPRSClass);
    DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RILDrv_GetGPRSClass\r\n")));

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


    if (!QueueCmd(pHandle,
                  "AT+CGCLASS?\r",
                  CMDOPT_NONE,
                  APIID_GETGPRSCLASS,
                  ParseGetGPRSClass,  // Parse fn
                  NULL,     // Ptr to notification data
                  hr))
    {
        hr = E_FAIL;
        goto Error;
    }

    Error:
    return hr;
}

// +CGCLASS=[A|B|C|CG|CC]
HRESULT RILDrv_SetGPRSClass (DWORD dwParam, DWORD dwClass)
{
    FUNCTION_TRACE(RILDrv_SetGPRSClass);
    DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RILDrv_SetGPRSClass\r\n")));

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

    // Build command
    char szCmd[MAX_PATH];
    LPCSTR szString;
    if (!StringFromFlag(dwClass,g_GprsClass,NUM_GPRSCLASS,szString))
    {
        goto Error;
    }

    (void)_snprintfz(szCmd, MAX_PATH, "AT+CGCLASS=\"%s\"\r", szString);

    if (!QueueCmd(pHandle,
                  szCmd,
                  CMDOPT_NONE,
                  APIID_SETGPRSCLASS,
                  NULL,  // Parse fn
                  NULL,     // Ptr to notification data
                  hr))
    {
        hr=E_FAIL;
        goto Error;
    }

    Error:
    return hr;
}

/*
+CGSMS: <service>
<service>: a numeric parameter which indicates the service or service preference to be used
0 GPRS
1 circuit switched
2 GPRS preferred (use circuit switched if GPRS not available)
3 circuit switched preferred (use GPRS if circuit switched not available)
*/
HRESULT ParseGetMOSMSService(LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
    FUNCTION_TRACE(ParseGetMOSMSService);
    UINT nValue;
    HRESULT hr = E_FAIL;
    DWORD *pdwMoSmsService=NULL;
    pBlob = NULL;
    cbBlob = 0;

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

    // Parse "+CGSMS: "
    if (!MatchStringBeginning(szRsp, "+CGSMS: ", szRsp))
    {
        goto Error;
    }

    // Parse <service>
    if (!ParseUInt(szRsp, TRUE, nValue, szRsp))
    {
        goto Error;
    }

    pdwMoSmsService = (DWORD*)AllocBlob(sizeof(DWORD));
    if (!pdwMoSmsService)
    {
        goto Error;
    }

    FlagFromValue(nValue,g_GprsMOSMSService,NUM_GPRSMOSMSSERVICE,*pdwMoSmsService);

    pBlob = (void*)pdwMoSmsService;
    cbBlob = sizeof(DWORD);
    hr = S_OK;

    Error:
    if (FAILED(hr))
    {
        FreeBlob(pdwMoSmsService);
    }

    return hr;
}

// +CGSMS?
HRESULT RILDrv_GetMOSMSService (DWORD dwParam)
{
    FUNCTION_TRACE(RILDrv_GetMOSMSService);
    DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RILDrv_GetMOSMSService\r\n")));

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

    if (!QueueCmd(pHandle,
                  "AT+CGSMS?\r",
                  CMDOPT_NONE,
                  APIID_GETMOSMSSERVICE,
                  ParseGetMOSMSService,  // Parse fn
                  NULL,     // Ptr to notification data
                  hr))
    {
        hr = E_FAIL;
        goto Error;
    }

    Error:
    return hr;
}

// +CGSMS=[0|1|2|3]
HRESULT RILDrv_SetMOSMSService (DWORD dwParam, DWORD dwMoSmsService)
{
    FUNCTION_TRACE(RILDrv_SetMOSMSService);
    DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RILDrv_SetMOSMSService\r\n")));

    UINT Value;
    HRESULT hr = E_INVALIDARG;
    CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
    if (!pHandle)
    {
        goto Error;
    }

    // Build command
    char szCmd[MAX_PATH];
    if (!ValueFromFlag(dwMoSmsService,g_GprsMOSMSService,NUM_GPRSMOSMSSERVICE,Value))
    {
        goto Error;
    }
    (void)_snprintfz(szCmd, MAX_PATH, "AT+CGSMS=%u\r",Value);


    if (!QueueCmd(pHandle,
                  szCmd,
                  CMDOPT_NONE,
                  APIID_SETMOSMSSERVICE,
                  NULL,  // Parse fn
                  NULL,  // Ptr to notification data
                  hr))
    {
        hr = E_FAIL;
        goto Error;
    }

    Error:
    return hr;
}


// +CGCLASS: (list of supported <class>s)
HRESULT ParseGetGprsCapsClass(LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
    FUNCTION_TRACE(ParseGetGprsCapsClass);
    DWORD *pdwClass = NULL;
    HRESULT hr = E_FAIL;

    pBlob = NULL;
    cbBlob = 0;

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

    // Parse "+CGCLASS: "
    if (!MatchStringBeginning(szRsp, "+CGCLASS: ", szRsp))
    {
        goto Error;
    }

    pdwClass = (DWORD*)AllocBlob(sizeof(DWORD));
    if (!pdwClass)
    {
        goto Error;
    }

    // Parse ,<class>
    if (!ParseStringList(szRsp, g_GprsClass, NUM_GPRSCLASS, *pdwClass, szRsp))
    {
        goto Error;
    }

    pBlob = (void*)pdwClass;
    cbBlob = sizeof(DWORD);
    hr = S_OK;

    Error:
    if (FAILED(hr))
    {
        FreeBlob(pdwClass);
    }

    return hr;
}

// +CGDCONT: (range of supported <cid>s),<PDP_type>,,,(list of supported <d_comp>s),(list of supported <h_comp>s)[,(list of supported <pd1>s)[,...[,(list of supported <pdN>s)]]]
// [<CR><LF>+CGDCONT: (range of supported <cid>s),<PDP_type>,,,(list of supported <d_comp>s),(list of supported <h_comp>s)[,(list of supported <pd1>s)[,...[,(list of supported <pdN>s)]]]
// [...]]
HRESULT ParseGetGprsCapsContext(LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
    FUNCTION_TRACE(ParseGetGprsCapsContext);

    PBYTE pBuffer=NULL;
    DWORD dwBufferSize=0;

    RILGPRSCONTEXTCAPS GPRSContextCaps, *pGPRSContextCaps;

    char szValue[MAX_PATH];
    LPCSTR szParams, szParamsEnd;

    HRESULT hr = E_FAIL;
    BOOL bSuccess;

    pBlob = NULL;
    cbBlob = 0;

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

    // Parse "+CGDCONT: "
    while (MatchStringBeginning(szRsp, "+CGDCONT: ", szRsp))
    {
        memset(&GPRSContextCaps, 0x00, sizeof(GPRSContextCaps));
        szParams = NULL;

        // Parse (range of supported <cid>s)
        if (!ParseRange(szRsp, GPRSContextCaps.ContextIDRange, szRsp))
        {
            goto Continue;
        }
        GPRSContextCaps.dwParams|= RIL_PARAM_GCONT_CONTEXTID;

        // Parse ,<PDP_type>
        if (!MatchStringBeginning(szRsp, ",", szRsp) ||
            !ParseString(szRsp, szValue, MAX_PATH, szRsp))
        {
            goto Continue;
        }

        if (FlagFromString(szValue, g_GprsPDPTypes, NUM_GPRSPDPTYPES, GPRSContextCaps.dwProtocolType))
        {
            GPRSContextCaps.dwParams|= RIL_PARAM_GCONT_PROTOCOLTYPE;
        }

        // Parse ,,,(list of supported <d_comp>s)
        if (!MatchStringBeginning(szRsp, ",,,", szRsp) ||
            !ParseRangeList(szRsp, g_GprsDataComp, NUM_GPRSDATACOMP, GPRSContextCaps.dwDataCompression, szRsp))
        {
            goto Continue;
        }
        GPRSContextCaps.dwParams|= RIL_PARAM_GCONT_DATACOMPRESSION;

        // Parse ,(list of supported <h_comp>s)
        if (!MatchStringBeginning(szRsp, ",", szRsp) ||
            !ParseRangeList(szRsp, g_GprsHeaderComp, NUM_GPRSHEADERCOMP, GPRSContextCaps.dwHeaderCompression, szRsp))
        {
            goto Continue;
        }
        GPRSContextCaps.dwParams|= RIL_PARAM_GCONT_HEADERCOMPRESSION;

        // Parse ","
        if (!MatchStringBeginning(szRsp, ",", szRsp))
        {
            goto Continue;
        }

        szParams = szRsp;
        // Parse ,<pd1>[,...[,pdN]]
        szParamsEnd = strstr(szParams, "\r\n");
        if ( !szParams || (szParamsEnd < szParams) )
        {
            goto Error;
        }

        szRsp = szParamsEnd;

        // Set dwParameterLength to be size of string in bytes counting extra null char at end
        GPRSContextCaps.dwParameterLength = ((szParamsEnd-szParams)+1);

        // Now all the data between szParams and szParamsEnd is the pd1-N string
        GPRSContextCaps.dwParams|= RIL_PARAM_GCONT_PARAMETERS;

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

        // Init size of GPRSContextCaps
        GPRSContextCaps.cbSize = sizeof(GPRSContextCaps);

        // Add in size of param string
        GPRSContextCaps.cbSize += GPRSContextCaps.dwParameterLength;

        // Round up to the nearest 32-bit address for alignment
        GPRSContextCaps.cbSize = (GPRSContextCaps.cbSize + 3) & (~0x03);

        // Reallocate our buffer for the additional data
        pBuffer = (PBYTE)ReallocBlob(pBuffer,dwBufferSize+GPRSContextCaps.cbSize);
        if (!pBuffer)
        {
            goto Error;
        }

        // Point pGPRSContextCaps to the first byte of the newly allocated section
        pGPRSContextCaps = (RILGPRSCONTEXTCAPS *) (pBuffer+dwBufferSize);

        // Copy struct to buffer
        *pGPRSContextCaps = GPRSContextCaps;

        if (GPRSContextCaps.dwParameterLength)
        {
            DWORD dwLen;
            char *szDestParams = GPRSContextCaps.szParameters;

            // Build the individual param strings
            while (1)
            {
                // Find beginnning of list '('
                if ( !szParams || '(' != *szParams )
                {
                    goto Error;
                }
                szParams++;

                // Find end of list ')'
                szParamsEnd = strchr(szParams,')');
                if ( !szParams || (szParamsEnd < szParams) )
                {
                    goto Error;
                }

                // Get length of string
                dwLen = szParamsEnd-szParams;

                // Copy string
                memcpy(szDestParams,szParams,dwLen);

                // Remember to terminate
                szDestParams[dwLen]='\0';

                // Update dest ptr
                szDestParams+=dwLen+1;

                // Update src ptr
                szParams=szParamsEnd+1;
                if ( !szParams )
                {
                    goto Error;
                }

                // Parse ','
                if (*szParams != ',')
                {
                    // Append final null char
                    *szDestParams=TEXT('\0');
                    break;
                }
            }
        }

        dwBufferSize+=GPRSContextCaps.cbSize;
    }

    pBlob = (void*)pBuffer;
    cbBlob = dwBufferSize;
    hr = S_OK;

    Error:

⌨️ 快捷键说明

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