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

📄 rilsimtkitbyte.cpp

📁 手机RILGSM实现的源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    m_lpbParse++;
    m_dwParseLen--;
    hr = ReadBearerDescription();
    if (FAILED(hr))
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Function for TLV %x failed\r\n"), BEARERDESCRIPTTAG));
        *pdwRetVal = SIM_RESPONSE_ERR_VALUESMISSING;
        hr = E_FAIL;
        goto Exit;
    }

    // Buffer Size
    if (BUFFERSIZETAG != (*(m_lpbParse) & 0x7f))
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : SIMTKit: Mandatory TLV %x not found. Found: %x\r\n"), BUFFERSIZETAG, (*(m_lpbParse) & 0x7f)));
        *pdwRetVal = SIM_RESPONSE_ERR_COMMANDDATA;
        hr = E_FAIL;
        goto Exit;
    }
    m_lpbParse++;
    m_dwParseLen--;
    hr = ReadBufferSize();
    if (FAILED(hr))
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Function for TLV %x failed\r\n"), BUFFERSIZETAG));
        *pdwRetVal = SIM_RESPONSE_ERR_VALUESMISSING;
        hr = E_FAIL;
        goto Exit;
    }

    // (LocalAddress:Other Address)
    if (OTHERADDRTAG == (*(m_lpbParse) & 0x7f))
    {
        m_lpbParse++;
        m_dwParseLen--;
        hr = ReadCommonByteAndByteList(&m_dwLocalAddrType, &m_lpbLocalAddr, &m_dwLocalAddrLen);
        if (FAILED(hr))
        {
            DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Function for TLV %x failed\r\n"), OTHERADDRTAG));
            *pdwRetVal = SIM_RESPONSE_ERR_VALUESMISSING;
            hr = E_FAIL;
            goto Exit;
        }
    }

    // (User Login:Text)
    if (TEXTTAG == (*(m_lpbParse) & 0x7f))
    {
        m_lpbParse++;
        m_dwParseLen--;
        hr = ReadCommonTextString(&m_pwszLogin, &m_dwLoginLen);
        if (FAILED(hr))
        {
            DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Function for TLV %x failed\r\n"), TEXTTAG));
            *pdwRetVal = SIM_RESPONSE_ERR_VALUESMISSING;
            hr = E_FAIL;
            goto Exit;
        }
    }

    // (UserPassword:Text)
    if (TEXTTAG == (*(m_lpbParse) & 0x7f))
    {
        m_lpbParse++;
        m_dwParseLen--;
        hr = ReadCommonTextString(&m_pwszPassword, &m_dwPasswordLen);
        if (FAILED(hr))
        {
            DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Function for TLV %x failed\r\n"), TEXTTAG));
            *pdwRetVal = SIM_RESPONSE_ERR_VALUESMISSING;
            hr = E_FAIL;
            goto Exit;
        }
    }

    // (InterfaceTransportLevel)
    if (TRANSPORTLVLTAG == (*(m_lpbParse) & 0x7f))
    {
        m_lpbParse++;
        m_dwParseLen--;
        hr = ReadTransportLevel();
        if (FAILED(hr))
        {
            DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Function for TLV %x failed\r\n"), TEXTTAG));
            *pdwRetVal = SIM_RESPONSE_ERR_VALUESMISSING;
            hr = E_FAIL;
            goto Exit;
        }
    }

    // (DestAddress:Other Address)
    if (OTHERADDRTAG == (*(m_lpbParse) & 0x7f))
    {
        m_lpbParse++;
        m_dwParseLen--;
        hr = ReadCommonByteAndByteList(&m_dwDestAddrType, &m_lpbDestAddr, &m_dwDestAddrLen);
        if (FAILED(hr))
        {
            DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Function for TLV %x failed\r\n"), OTHERADDRTAG));
            *pdwRetVal = SIM_RESPONSE_ERR_VALUESMISSING;
            hr = E_FAIL;
            goto Exit;
        }
    }

Exit:
return hr;
}

/****************************************************************************

    FUNCTION:   ByteParseOpenChannelGPRS

    PURPOSE:    Parses and incoming Open Channel CS command

    RETURNS:    HRESULT

****************************************************************************/
HRESULT CRilSimToolkitCommand::ByteParseOpenChannelGPRS(DWORD* pdwRetVal)
{
    HRESULT hr = S_OK;

    // The Open Channel GPRS TLV tags should be:
    // BearerDescription,BufferSize,(APN),(LocalAddress),
    // (InterfaceTransportLevel),(DestAddress)

    // Bearer description
    if (BEARERDESCRIPTTAG != (*(m_lpbParse) & 0x7f))
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : SIMTKit: Mandatory TLV %x not found. Found: %x\r\n"), BEARERDESCRIPTTAG, (*(m_lpbParse) & 0x7f)));
        *pdwRetVal = SIM_RESPONSE_ERR_COMMANDDATA;
        hr = E_FAIL;
        goto Exit;
    }
    m_lpbParse++;
    m_dwParseLen--;
    hr = ReadBearerDescription();
    if (FAILED(hr))
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Function for TLV %x failed\r\n"), BEARERDESCRIPTTAG));
        *pdwRetVal = SIM_RESPONSE_ERR_VALUESMISSING;
        hr = E_FAIL;
        goto Exit;
    }

    // Buffer Size
    if (BUFFERSIZETAG != (*(m_lpbParse) & 0x7f))
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : SIMTKit: Mandatory TLV %x not found. Found: %x\r\n"), BUFFERSIZETAG, (*(m_lpbParse) & 0x7f)));
        *pdwRetVal = SIM_RESPONSE_ERR_COMMANDDATA;
        hr = E_FAIL;
        goto Exit;
    }
    m_lpbParse++;
    m_dwParseLen--;
    hr = ReadBufferSize();
    if (FAILED(hr))
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Function for TLV %x failed\r\n"), BUFFERSIZETAG));
        *pdwRetVal = SIM_RESPONSE_ERR_VALUESMISSING;
        hr = E_FAIL;
        goto Exit;
    }

    // (APN)
    if (NETACCESSNAMETAG == (*(m_lpbParse) & 0x7f))
    {
        m_lpbParse++;
        m_dwParseLen--;
        hr = ReadCommonByteList(&m_lpbAccessName, &m_dwAccessNameLen);
        if (FAILED(hr))
        {
            DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Function for TLV %x failed\r\n"), NETACCESSNAMETAG));
            *pdwRetVal = SIM_RESPONSE_ERR_VALUESMISSING;
            hr = E_FAIL;
            goto Exit;
        }
    }

    // (LocalAddress:Other Address)
    if (OTHERADDRTAG == (*(m_lpbParse) & 0x7f))
    {
        m_lpbParse++;
        m_dwParseLen--;
        hr = ReadCommonByteAndByteList(&m_dwLocalAddrType, &m_lpbLocalAddr, &m_dwLocalAddrLen);
        if (FAILED(hr))
        {
            DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Function for TLV %x failed\r\n"), OTHERADDRTAG));
            *pdwRetVal = SIM_RESPONSE_ERR_VALUESMISSING;
            hr = E_FAIL;
            goto Exit;
        }
    }

    // (InterfaceTransportLevel)
    if (TRANSPORTLVLTAG == (*(m_lpbParse) & 0x7f))
    {
        m_lpbParse++;
        m_dwParseLen--;
        hr = ReadTransportLevel();
        if (FAILED(hr))
        {
            DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Function for TLV %x failed\r\n"), TEXTTAG));
            *pdwRetVal = SIM_RESPONSE_ERR_VALUESMISSING;
            hr = E_FAIL;
            goto Exit;
        }
    }

    // (DestAddress:Other Address)
    if (OTHERADDRTAG == (*(m_lpbParse) & 0x7f))
    {
        m_lpbParse++;
        m_dwParseLen--;
        hr = ReadCommonByteAndByteList(&m_dwDestAddrType, &m_lpbDestAddr, &m_dwDestAddrLen);
        if (FAILED(hr))
        {
            DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Function for TLV %x failed\r\n"), OTHERADDRTAG));
            *pdwRetVal = SIM_RESPONSE_ERR_VALUESMISSING;
            hr = E_FAIL;
            goto Exit;
        }
    }

Exit:
    return hr;
}

/****************************************************************************

    FUNCTION:   ReadDialNumberString

    PURPOSE:    Reads a dial number string, including DTMF separators and characters
                    This is used for both the Address and Short String

    PARAMETERS: ppwsz - The string to set
                pdwLen - The length to set

    RETURNS:    HRESULT

****************************************************************************/

HRESULT CRilSimToolkitCommand::ReadDialNumberString(TCHAR **ppwsz, DWORD *pdwLen)
{
    HRESULT hr = S_OK;
    DWORD dwLength;
    TCHAR *pwszAddress;

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

    DEBUGCHK(ppwsz);
    DEBUGCHK(pdwLen);

    if (NULL == ppwsz || 0 >= pdwLen)
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: ReadDialNumberString return parameter is null.\r\n"), hr));
        goto Exit;
    }

    DEBUGCHK(*ppwsz == NULL);
    DEBUGCHK(*pdwLen == 0);

    // OK, read in the length
    hr = ReadCmdLength(&dwLength);
    if (FAILED(hr))
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: ReadCmdLength failed %x\r\n"), hr));
        goto Exit;
    }

    // OK, we should have this much space left
    if (m_dwParseLen < dwLength)
    {
        // Nope, not enough space left
        DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Needed %d bytes, only have %d %x\r\n"), dwLength, m_dwParseLen));
        hr = E_FAIL;
        goto Exit;
    }

    // Now for the actual address string, note that dwLength includes the previous byte
    // Also note that each byte is actually two digits
    pwszAddress = new TCHAR[2 * dwLength + 1];
    if (!pwszAddress)
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Ran out of memory")));
        hr = E_OUTOFMEMORY;
        goto Exit;
    }

    hr = ConvertBytesToDialString(m_lpbParse, dwLength, pwszAddress, &m_dwAddrType, &m_dwNumPlan);
    if (FAILED(hr))
    {
        goto Exit;
    }

    // We're done!
    m_lpbParse += dwLength;
    m_dwParseLen -= dwLength;
    DEBUGMSG(ZONE_INFO, (TEXT("RilDrv : SIMTKit: Address %s, length remaining %d\r\n"), pwszAddress, m_dwParseLen));

    // Set variables
    *ppwsz = pwszAddress;
    *pdwLen = (lstrlen(pwszAddress) + 1) * sizeof(TCHAR);

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

/****************************************************************************

    FUNCTION:   ReadEFADNText

    PURPOSE:    Helper function for any TLV that codes its text the same way
                    as EF-ADN as defined in 11.11, annex B.  Many strings are
                    coded this way, but not (surprise surprise) the string
                    from DISPLAY TEXT, which is coded a different way

    PARAMETERS: ppwszText - Pointer to string which we allocate -- will hold
                                the result
                dwLength - The length of the data that follows
                pdwUsedLen - Set to the size in bytes of the returned string

    RETURNS:    HRESULT

****************************************************************************/

HRESULT CRilSimToolkitCommand::ReadEFADNText(TCHAR **ppwszText, DWORD dwLength, DWORD *pdwUsedLen)
{
    TCHAR *pwsz = NULL;
    HRESULT hr = S_OK;
    BYTE bEncode;
    BOOL fRetVal;
    UINT uiUsedLen = 0, uiBasePage;
    DWORD dwTextLen;
    LPBYTE lpbTemp;

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

    if (NULL == ppwszText)
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: ReadEFADNText return parameter is null.\r\n")));
        hr = E_FAIL;
        goto Exit;
    }

    DEBUGCHK(*ppwszText == NULL);

    if (m_dwParseLen < dwLength)
    {
        // Well, that can't be
        DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Expected %d bytes, only have %d\r\n"), dwLength, m_dwParseLen));
        hr = E_FAIL;
        goto Exit;
    }

    // Allocate enough space for the worst case, which would be the length of what remains
    // (in the unpacked case) -- we'll be off by at most 5 characters
    pwsz = new TCHAR[dwLength + 1];
    if (!pwsz)
    {
        hr = E_OUTOFMEMORY;
        goto Exit;
    }

    // Special case -- the length is 0
    if (dwLength == 0)
    {
        uiUsedLen = 0;
    }
    else
    {
        // This string is coded as in GSM 11.11, Annex B.  The first byte either tells us how the
        // rest of this string is encoded or is the first character of the string itself
        bEncode = *m_lpbParse;

        switch (bEncode)
        {
            case 0x80:
                if( *(m_lpbParse+1) == 0xf3  )
                { 
                    char *ptr = (char *)(m_lpbParse+1);
                    memcpy( ptr,ptr+1,strlen(ptr+1) );
                }
            	
                // UCS2 encoding
                // Per GSM 11.11, Annex B, we should ignore any FF characters at the end of this string
                lpbTemp = m_lpbParse + dwLength - 1;
                while ((lpbTemp > m_lpbParse) && (*lpbTemp == 0xFF))
                {
                    lpbTemp--;
                }

                // Start parsing after the encoding byte, up to the last non-0xFF byte.
                fRetVal = ConvertUCS2ToUnicode((LPCSTR) (m_lpbParse + 1), lpbTemp - m_lpbParse, pwsz, dwLength, uiUsedLen);
                break;

⌨️ 快捷键说明

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