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

📄 rilsimtkittext.cpp

📁 手机RILGSM实现的源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    pbParse = m_lpbParse;
    dwLength = 0;

    // At this point the GetInput notification should be in the form of:
    //
    // ,<dcs>,<text>,<response>,<echo>,<helpInfo>,<minLgth>,<maxLgth>
    // [,<dcs>,<default>[,<iconId>,<dispMode>]]

    // ,<dcs> 
    // Data encoding Scheme:
    // 0 7bit GSM default alphabet (packed)
    // 4 8bit data
    // 8 UCS2 alphabet
    if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse) ||
        !ParseDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwDCS, (LPCSTR&)pbParse)) 
    {
        hr = E_FAIL;
        goto Exit;
    }

    // ,<text>
    // Must manage returned memory
    if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse) ||
        !ParseEncodedText(pbParse, dwDCS, wszTitle, cbTitleBufSize, pbParse)) 
    {
        hr = E_FAIL;
        goto Exit;
    }

    // ,<response> 
    // integer: expected response character format.
    // Digits (0-9, *, # and +) only from SMS default alphabet (unpacked)
    // Digits (0-9, *, # and +) only from SMS default alphabet (packed)
    // Digits from UCS2 alphabet
    // SMS default alphabet (unpacked)
    // SMS default alphabet (packed)
    // UCS2 alphabet
    if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse) ||
        !ParseDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwResponse, (LPCSTR&)pbParse)) 
    {
        hr = E_FAIL;
        goto Exit;
    }

    // ,<echo> 
    if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse) ||
        !ParseDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwEcho, (LPCSTR&)pbParse)) 
    {
        hr = E_FAIL;
        goto Exit;
    }

    // ,<helpInfo>
    if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse) ||
        !ParseDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwHelpInfo, (LPCSTR&)pbParse)) 
    {
        hr = E_FAIL;
        goto Exit;
    }

    // ,<minLgth> 
    if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse) ||
        !ParseDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwMinLength, (LPCSTR&)pbParse)) 
    {
        hr = E_FAIL;
        goto Exit;
    }

    // ,<maxLgth> 
    if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse) ||
        !ParseDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwMaxLength, (LPCSTR&)pbParse)) 
    {
        hr = E_FAIL;
        goto Exit;
    }

    // Optional:
    // ,<dcs>,<default>
    if (MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse))
    {
    
        // <dcs>
        if (!ParseDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwDCS, (LPCSTR&)pbParse)) 
        {
            hr = E_FAIL;
            goto Exit;
        }
            
        // ,<default>
        // Must manage returned memory
        if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse) ||
            !ParseEncodedText(pbParse, dwDCS, wszDefault, cbDefaultBufSize, pbParse)) 
        {
            hr = E_FAIL;
            goto Exit;
        }

        // Optional:
        //[,<iconId>,<dispMode>]
        if (MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse))
        {
            // <iconID>
            if (!ParseDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwIconID, (LPCSTR&)pbParse)) 
            {
                hr = E_FAIL;
                goto Exit;
            }
            
            // ,<dispMode>
            if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse) ||
                !ParseDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwDispMode, (LPCSTR&)pbParse)) 
            {
                hr = E_FAIL;
                goto Exit;
            }        
        }
    }
    
    // Parsing successful, set proper values for build command functions

    switch (dwResponse)
    {
        case SIMTKIT_TEXTPARSE_GETINPUT_DIGIT_UNPACKED:            
            *pbFifthByte |= SIMTKIT_TEXTPARSE_INPUT_KEYPADDIGITS;
            break;
        case SIMTKIT_TEXTPARSE_GETINPUT_DIGIT_PACKED:
            *pbFifthByte |= SIMTKIT_TEXTPARSE_INPUT_KEYPADDIGITS;
            *pbFifthByte |= SIMTKIT_TEXTPARSE_PACKEDRESPONSE;
            break;
        case SIMTKIT_TEXTPARSE_GETINPUT_DIGIT_UCS2:
            // Need to revisit and properly setup results for UCS2.
            break;    
        case SIMTKIT_TEXTPARSE_GETINPUT_ALPHA_UNPACKED:
            *pbFifthByte |= SIMTKIT_TEXTPARSE_INPUT_SMDEFAULTALPHABET;
            break;    
        case SIMTKIT_TEXTPARSE_GETINPUT_ALPHA_PACKED:
            *pbFifthByte |= SIMTKIT_TEXTPARSE_INPUT_SMDEFAULTALPHABET;
            *pbFifthByte |= SIMTKIT_TEXTPARSE_PACKEDRESPONSE;
            break;    
        case SIMTKIT_TEXTPARSE_GETINPUT_ALPHA_UCS2:
            // Need to revisit and properly setup results for UCS2.
            break;    
        default:
            break;
    }

    // <CR><LF>
    if (!ParseRspPostfix((LPCSTR)pbParse, (LPCSTR&)pbParse) )
    {
        hr = E_FAIL;
        goto Exit;
    }

    if (dwEcho)
    {
        *pbFifthByte |= SIMTKIT_TEXTPARSE_NOECHO;
    }


    if (dwHelpInfo)
    {
        *pbFifthByte |= SIMTKIT_TEXTPARSE_HELPINFO;
    }

    m_dwMinResponse = dwMinLength;
    m_dwMaxResponse = dwMaxLength;

    m_pwszText = wszTitle;
    m_dwTextLen = cbTitleBufSize;
    m_pwszDefaultText = wszDefault;
    m_dwDefaultTextLen = cbDefaultBufSize;

    if (SIMTKIT_INVALID_VALUE != dwIconID)
    {
        m_dwIconIdentifier = dwIconID;
    }

    if (SIMTKIT_INVALID_VALUE != dwDispMode)
    {
        m_dwIconQualifier = dwDispMode;
    }

Exit:
    if (FAILED(hr))
    {
        delete[] wszTitle;
        delete[] wszDefault;
    }
    dwLength = pbParse - m_lpbParse;
    m_lpbParse = pbParse;
    m_dwParseLen -= dwLength;

    DEBUGMSG(ZONE_FUNCTION, (TEXT("RilDrv : SIMTKit: -CRilSimToolkitCommand::ParseGetInput\r\n")));
    return hr;
}


HRESULT CRilSimToolkitCommand::ParsePlayTone(void)
{
    BYTE* pbParse;
    LPWSTR wszText = NULL;
    size_t cbTextBufSize = 0;
    DWORD dwLength;
    DWORD dwTone;
    DWORD dwDuration;
    HRESULT hr = S_OK;

    
    DEBUGMSG(ZONE_FUNCTION, (TEXT("RilDrv : SIMTKit: +CRilSimToolkitCommand::ParsePlayTone\r\n")));

    pbParse = m_lpbParse;
    dwLength = 0;

    // At this point the PlayTone notification should be in the form of:
    //
    // [,<alphaId>[,<tone>[,<duration>]]]

    // Optional: ,<alphaId>
    if (MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse))
    {
        if (!ParseEncodedText(pbParse, SIMTKIT_TEXT_ENCODING_ALPHAID, wszText, cbTextBufSize, pbParse))
        {
            hr = E_FAIL;
            goto Exit;
        }
    }
    
    // Optional: ,<tone>
    if (MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse))
    {
        if(!ParseHexDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_LEADINGZERO, dwTone, (LPCSTR&)pbParse))
        {
            hr = E_FAIL;
            goto Exit;
        }
        m_dwTone = dwTone;
    }
        
    // Optional: ,<duration>
    if (MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse))
    {
        if(!ParseDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwDuration, (LPCSTR&)pbParse))
        {
            hr = E_FAIL;
            goto Exit;
        }  
        m_dwDuration = dwDuration;
    }
            
    // <CR><LF>
    if (!ParseRspPostfix((LPCSTR)pbParse, (LPCSTR&)pbParse) )
    {
        hr = E_FAIL;
        goto Exit;
    }

    // Parsing successful, set proper values for build command functions

    m_pwszAlphaId  = wszText;
    m_dwAlphaIdLen = cbTextBufSize;

Exit:
    if (FAILED(hr))
    {
        delete[] wszText;
    }
    dwLength = pbParse - m_lpbParse;
    m_lpbParse = pbParse;
    m_dwParseLen -= dwLength;

    DEBUGMSG(ZONE_FUNCTION, (TEXT("RilDrv : SIMTKit: -CRilSimToolkitCommand::ParsePlayTone\r\n")));
    return hr;
}


HRESULT CRilSimToolkitCommand::ParseUnsolicitedData(void)
{
    BYTE* pbParse;
    LPWSTR wszText = NULL;
    size_t cbTextBufSize = 0;
    DWORD dwIconID = SIMTKIT_INVALID_VALUE;
    DWORD dwDispMode = SIMTKIT_INVALID_VALUE;
    DWORD dwLength;
    HRESULT hr = S_OK;

    
    DEBUGMSG(ZONE_FUNCTION, (TEXT("RilDrv : SIMTKit: +CRilSimToolkitCommand::ParseUnsolicitedData\r\n")));

    pbParse = m_lpbParse;
    dwLength = 0;

    // At this point the basic UnsolicitedData notification should be in the form of:
    //
    // [,<alphaId>[,<iconId>,<dispMode>]]

    // Optional: ,<alphaId> 
    if (MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse))
    {
        if (!ParseEncodedText(pbParse, SIMTKIT_TEXT_ENCODING_ALPHAID, wszText, cbTextBufSize, pbParse)) 
        {
            hr = E_FAIL;
            goto Exit;
        }
    }

    // Optional: ,<iconId>,<dispMode>
    if (MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse))
    {
        if (!ParseDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwIconID, (LPCSTR&)pbParse))
        { 
            hr = E_FAIL;
            goto Exit;
        }

        // ,<dispMode>
        if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse) ||
            !ParseDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwDispMode, (LPCSTR&)pbParse)) 
        {
            hr = E_FAIL;
            goto Exit;
        }
    }

    // <CR><LF>
    if (!ParseRspPostfix((LPCSTR)pbParse, (LPCSTR&)pbParse) )
    {
        hr = E_FAIL;
        goto Exit;
    }

    // Parsing successful, set proper values for build command functions

    if (wszText)
    {
        m_pwszAlphaId  = wszText;
        m_dwAlphaIdLen = cbTextBufSize;
    }

    if (SIMTKIT_INVALID_VALUE != dwIconID)
    {
        m_dwIconIdentifier = dwIconID;
    }

    if (SIMTKIT_INVALID_VALUE != dwDispMode)
    {
        m_dwIconQualifier = dwDispMode;
    }

Exit:
    if (FAILED(hr))
    {
        delete[] wszText;
    }
    dwLength = pbParse - m_lpbParse;
    m_lpbParse = pbParse;
    m_dwParseLen -= dwLength;

    DEBUGMSG(ZONE_FUNCTION, (TEXT("RilDrv : SIMTKit: -CRilSimToolkitCommand::ParseUnsolicitedData\r\n")));
    return hr;
}


HRESULT CRilSimToolkitCommand::ParseRefresh(BYTE* pbFifthByte)
{
    BYTE* pbParse;
    DWORD* pdwFileList = NULL;
    LPBYTE pbFileData = NULL;
    WORD wFileAddress;
    size_t cbFileSize = 0;
    DWORD dwRefMode;
    DWORD dwNumFiles = 0;
    DWORD dwLength;
    DWORD dwCurrentFile;
    HRESULT hr = S_OK;

    
    DEBUGMSG(ZONE_FUNCTION, (TEXT("RilDrv : SIMTKit: +CRilSimToolkitCommand::ParseRefresh\r\n")));

    pbParse = m_lpbParse;
    dwLength = 0;

    // At this point the Refresh notification should be in the form of:
    //
    // ,<refMode>[,<numFiles>,<fileList>]

    // ,<refMode> 
    if (!MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse) ||
        !ParseHexDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_LEADINGZERO, dwRefMode, (LPCSTR&)pbParse)) 
    {
        hr = E_FAIL;
        goto Exit;
    }

    // Optional: ,<numFiles>,<fileList>
    if (MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse))
    {
        // <numFiles>,
        if (!ParseDWord((LPCSTR)pbParse, SIMTKIT_TEXTPARSE_PARSE_NOLEADINGZERO, dwNumFiles, (LPCSTR&)pbParse) ||
            !MatchStringBeginning((LPCSTR)pbParse, ",", (LPCSTR&)pbParse))
        { 
            hr = E_FAIL;
            goto Exit;
        }

        // Create buffer for list of files.
        pdwFileList = new DWORD[dwNumFiles];
        
        // <fileList>
        // string type, hex notation: gives the full paths for the SIM files, 
        // each file being delimited by commas within the string
        for (dwCurrentFile = 0 ; dwCurrentFile < dwNumFiles ; dwCurrentFile++)
        {
            // Get the string encoded hex for the file and convert it to bytes
            // Memory allocated: We must manage the memory returned in pbFileData.
            if (!ParseBytes(pbParse, pbFileData, cbFileSize, pbParse)) 
            {
                hr = E_FAIL;
                goto Exit;
            }

            // Sanity check that we have a correctly formed full path to a
            // elementary file. A full path lists the Master file first which
            // starts with 0x3F
            if (*pbFileData != 0x3F)
            {
                DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Expected master file 3F in file list, saw %x\r\n"), *pbFileData));
                hr = E_INVALIDARG;
                goto Exit;
            }
            
            // From TLV.cpp ReadFileList()
            // Grab the last word -- we're only interested in the last word in each file
            // Note that we don't check each layer down to make sure it's valid
            // (e.g. matches GSM 11.11, sec 6.2)
            wFileAddress = pbFileData[cbFileSize-2];
            wFileAddress = (WORD) ((wFileAddress << 8) + pbFileData[cbFileSize-1]);

            pdwFileList[dwCurrentFile] = (DWORD) wFileAddress;

            // We are done with the dynamic byte buffer for this file.

⌨️ 快捷键说明

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