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

📄 rilsimtkitbyte.cpp

📁 ril source code for Windows CE
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

Module Name:

RilSimTKitByte.cpp

Abstract:


Notes:


--*/

#include "precomp.h"

#ifdef assert
#undef assert
#endif
#include "Safeint.hxx"

#include "ccoreutl.h"

// Used for parsing the result for SIMLOCALINFO
HRESULT StringToByteArray(const TCHAR *pwsz, __out_bcount( nSize ) BYTE *rgb, int nSize)
{
    int nLen = lstrlen(pwsz);
    int i, j;

    if (nLen > nSize)
    {
        return E_INVALIDARG;
    }

    // If characters are missing, the first few array entries
    // will be considered 0
    memset(rgb, 0, nSize);
    for (i = nSize - 1, j = nLen - 1; j >= 0; i--, j--)
    {
        if ((pwsz[j] >= TEXT('0')) && (pwsz[j] <= TEXT('9')))
        {
            rgb[i] = (BYTE) (pwsz[j] - '0');
        }
        else if ((pwsz[j] >= TEXT('a')) && (pwsz[j] <= TEXT('f')))
        {
            rgb[i] = (BYTE) (pwsz[j] - 'a' + 10);
        }
        else if ((pwsz[j] >= TEXT('A')) && (pwsz[j] <= TEXT('F')))
        {
            rgb[i] = (BYTE) (pwsz[j] - 'A' + 10);
        }
        else
        {
            return E_INVALIDARG;
        }
    }

    return S_OK;
}

TCHAR ByteToTCHAR(BYTE b)
{
    TCHAR tch;

    // We assume b is between 0 and F, of course
    ASSERT((b >= 0) && (b <= 0xf));

    if (b <= 9)
    {
        tch = (TCHAR) (TEXT('0') + b);
    }
    else
    {
        tch = (TCHAR) (TEXT('A') + (b - 10));
    }

    return tch;
}


HRESULT CRilSimToolkitResponse::ByteFormatResponse(const RILSIMTOOLKITRSP* pRsp, const LPBYTE pDetails, const DWORD dwDetailSize, __inout_bcount( *pdwDataRspSize ) LPBYTE pbDataRsp, DWORD* pdwDataRspSize)
{
    LPBYTE lpb;
    HRESULT hr = S_OK;

    // Assert parameters
    DEBUGCHK(NULL != pRsp);
    DEBUGCHK(NULL != pbDataRsp);
    DEBUGCHK(MAX_BYTE_RSP <= *pdwDataRspSize);  // Make sure there is a enough total room in buffer now,
                                                // so we don't have to check every step of the way.

    // Check parameters
    if (NULL == pRsp ||
        NULL == pbDataRsp ||
        MAX_BYTE_RSP > *pdwDataRspSize)
    {
        DEBUGCHK(FALSE);
        hr = E_INVALIDARG;
        goto Exit;
    }

    // Check dwParams to make sure the necessary fields are supported
    DEBUGCHK(pRsp->dwParams & RIL_PARAM_SIMTKIT_RSP_TYPE);
    DEBUGCHK(pRsp->dwParams & RIL_PARAM_SIMTKIT_RSP_RESPONSE);

    if (!(pRsp->dwParams & RIL_PARAM_SIMTKIT_RSP_TYPE) ||
        !(pRsp->dwParams & RIL_PARAM_SIMTKIT_RSP_RESPONSE))
    {
        hr = E_INVALIDARG;
        goto Exit;
    }

    // Initialize return buffer.
    memset(pbDataRsp, 0, *pdwDataRspSize);
    lpb = pbDataRsp;

    if (SIM_NOTIFY_SETUPMENU_REPLY == pRsp->dwType)
    {
        SIMTKITRSPITEM* pItemDetails = (SIMTKITRSPITEM*)pDetails;

        // Check that the proper details exist.
        if (NULL == pDetails)
        {
            DEBUGCHK(FALSE);
            hr = E_INVALIDARG;
            goto Exit;
        }

        if (!(pItemDetails->dwParams & RIL_PARAM_SIMTKIT_RSP_DETAILS_ITEM_ID))
        {
            DEBUGCHK(FALSE);
            return E_INVALIDARG;
            goto Exit;
        }

        // We're going to be setting up a menu, which is formatted a bit differently than
        // your normal old TERMINAL RESPONSE
        *(lpb++) = MENUSELECTTAG;
        // The length is 7 if no help is requested, otherwise it's 9
        *(lpb++) = (BYTE) ((pRsp->dwResponse == SIM_RESPONSE_OK_HELP) ? 0x09 : 0x07);

        // Device identities
        *(lpb++) = DEVICEIDTAG; // Device identities tag
        *(lpb++) = 0x02;        // Length of what follows
        *(lpb++) = 0x01;        // Source = Keypad
        *(lpb++) = 0x81;        // Destination = SIM

        // Item identifier
        *(lpb++) = ITEMIDTAG;   // Item identifier tag
        *(lpb++) = 0x01;        // Length of what follows
        *(lpb++) = (BYTE) pItemDetails->dwId; // Item which was selected

        // Optional request for help
        if (pRsp->dwResponse == SIM_RESPONSE_OK_HELP)
        {
            *(lpb++) = HELPTAG; // Help request tag
            *(lpb++) = 0x00;    // Length of what follows
        }
    }
    else
    {
        BOOL fCmdDataNeeded = FALSE;

        // OK, let's build up what we want to send down to the SIM
        // Set up command details -- use exactly what we gave to the user
        DEBUGCHK(RIL_PARAM_SIMTKIT_RSP_TAG & pRsp->dwParams);
        DEBUGCHK(RIL_PARAM_SIMTKIT_RSP_ID & pRsp->dwParams);
        DEBUGCHK(RIL_PARAM_SIMTKIT_RSP_TYPE & pRsp->dwParams);
        DEBUGCHK(RIL_PARAM_SIMTKIT_RSP_QUALIFIER & pRsp->dwParams);

        // Send the response command details tag if included.
        if (RIL_PARAM_SIMTKIT_RSP_TAG & pRsp->dwParams)
        {
            *(lpb++) = (BYTE) pRsp->dwTag;
        }
        // If one is not included, default to the command details tag without
        // comprehension set.
        else
        {
            *(lpb++) = COMMANDIDTAG;
        }

        *(lpb++) = 3;   // Length is spec'ed to 3 bytes.

        // Command Details Identifier
        if (RIL_PARAM_SIMTKIT_RSP_ID & pRsp->dwParams)
        {
            *(lpb++) = (BYTE) pRsp->dwId;
        }
        else
        {
            *(lpb++) = 0;
        }

        // Command Details Type
        if (RIL_PARAM_SIMTKIT_RSP_TYPE & pRsp->dwParams)
        {
            *(lpb++) = (BYTE) pRsp->dwType;
        }
        else
        {
            *(lpb++) = 0;
        }

        // Command Details Qualifier
        if (RIL_PARAM_SIMTKIT_RSP_QUALIFIER & pRsp->dwParams)
        {
            *(lpb++) = (BYTE) pRsp->dwQualifier;
        }
        else
        {
            *(lpb++) = 0;
        }

        // Device identities
        *(lpb++) = DEVICEIDTAG; // Device identities tag
        *(lpb++) = 0x02;        // Length of what follows

        if (SIM_NOTIFY_CLOSECHANNEL == pRsp->dwType)
        {
            SIMTKITRSPCLOSECHANNEL* pCloseChannel;

            // Poll interval details are necessary.
            if (NULL == pDetails)
            {
                DEBUGCHK(FALSE);
                hr = E_INVALIDARG;
                goto Exit;
            }
            pCloseChannel = (SIMTKITRSPCLOSECHANNEL*)pDetails;

            // We need the Close channel details for a proper byte response.
            if (NULL == pCloseChannel)
            {
                DEBUGCHK(FALSE);
                hr = E_INVALIDARG;
                goto Exit;
            }

            // Make sure all necessary fields are available.
            if ( !(RIL_PARAM_SIMTKIT_RSP_DETAILS_CLOSECHANNEL_ID & pCloseChannel->dwParams) )
            {
                DEBUGCHK(FALSE);
                hr = E_INVALIDARG;
                goto Exit;
            }
            // Channel ID must be between 0x21 and 0x27
            ASSERT(0x21 <= pCloseChannel->dwChannelId);
            ASSERT(0x27 >= pCloseChannel->dwChannelId);

            *(lpb++) = (BYTE) pCloseChannel->dwChannelId; // Source = Channel ID
        }
        else if(SIM_NOTIFY_RECEIVEDATA == pRsp->dwType)
        {
            SIMTKITRSPRECEIVEDATA* pRcvData;

            // Poll interval details are necessary.
            if (NULL == pDetails)
            {
                DEBUGCHK(FALSE);
                hr = E_INVALIDARG;
                goto Exit;
            }
            pRcvData = (SIMTKITRSPRECEIVEDATA*)pDetails;

            // Make sure all necessary fields are available.
            if ( !(RIL_PARAM_SIMTKIT_RSP_DETAILS_RECEIVEDATA_ID & pRcvData->dwParams) )
            {
                DEBUGCHK(FALSE);
                hr = E_INVALIDARG;
                goto Exit;
            }
            // Channel ID must be between 0x21 and 0x27
            ASSERT(0x21 <= pRcvData->dwChannelId && 0x27 >= pRcvData->dwChannelId);

            *(lpb++) = (BYTE) pRcvData->dwChannelId; // Source = Channel ID
        }
        else if(SIM_NOTIFY_SENDDATA == pRsp->dwType)
        {
            SIMTKITRSPSENDDATA* pSendData;

            // Poll interval details are necessary.
            if (NULL == pDetails)
            {
                DEBUGCHK(FALSE);
                hr = E_INVALIDARG;
                goto Exit;
            }
            pSendData = (SIMTKITRSPSENDDATA*)pDetails;

            // Make sure all necessary fields are available.
            if ( !(RIL_PARAM_SIMTKIT_RSP_DETAILS_RECEIVEDATA_ID & pSendData->dwParams) )
            {
                DEBUGCHK(FALSE);
                hr = E_INVALIDARG;
                goto Exit;
            }

            // Channel ID must be between 0x21 and 0x27
            ASSERT(0x21 <= pSendData->dwChannelId && 0x27 >= pSendData->dwChannelId);

            *(lpb++) = (BYTE) pSendData->dwChannelId; // Source = Channel ID
        }
        else
        {
            *(lpb++) = 0x82;        // Source = ME
        }

        *(lpb++) = 0x81;        // Destination = SIM


        // Result block

        // Note that additional information is limited to a byte for now
        *(lpb++) = RESULTTAG;

        // Length; 2 if additional info present, 1 if not
        *(lpb++) = ((pRsp->dwParams & RIL_PARAM_SIMTKIT_RSP_ADDITIONALINFO) ?  0x02 : 0x01);   // Length
        *(lpb++) = (BYTE) pRsp->dwResponse;

        // Check whether the response type needs or does not need corresponding user data. This is for responses in the
        // 0X range (where ENDSESSION is 10) or for help requests.
        fCmdDataNeeded = (pRsp->dwResponse < SIM_RESPONSE_OK_ENDSESSION || pRsp->dwResponse == SIM_RESPONSE_OK_HELP);

        // Additional info if present
        if (pRsp->dwParams & RIL_PARAM_SIMTKIT_RSP_ADDITIONALINFO)
        {
            *(lpb++) = (BYTE) pRsp->dwAdditionalInfo;
        }

        // Optional duration -- it's given in millisecond intervals, may be able
        // to specify it in minutes or seconds
        if (fCmdDataNeeded && (SIM_NOTIFY_POLLINTERVAL == pRsp->dwType))
        {
            SIMTKITRSPPOLLINTERVAL* pPoll;

            // Poll interval details are necessary.
            if (NULL == pDetails)
            {
                DEBUGCHK(FALSE);
                hr = E_INVALIDARG;
                goto Exit;
            }
            pPoll = (SIMTKITRSPPOLLINTERVAL*)pDetails;

            // Make sure all necessary fields are available.
            if ( !(RIL_PARAM_SIMTKIT_RSP_DETAILS_POLL_ALL & pPoll->dwParams) )
            {
                DEBUGCHK(FALSE);
                hr = E_INVALIDARG;
                goto Exit;
            }

            // The value can't be more than 255
            if (pPoll->dwInterval > 255)
            {
                DEBUGCHK(FALSE);
                hr = E_INVALIDARG;
                goto Exit;
            }

            *(lpb++) = DURATIONTAG;               // Duration
            *(lpb++) = 0x02;                      // Length
            *(lpb++) = (BYTE) pPoll->dwUnit;      // Unit
            *(lpb++) = (BYTE) pPoll->dwInterval;  // Value
        }

        // Optional text string
        // Form text tag for commands that require it.
        if ( fCmdDataNeeded &&
             ((SIM_NOTIFY_GETINKEY == pRsp->dwType) ||
              (SIM_NOTIFY_GETINPUT == pRsp->dwType) ||
              (SIM_NOTIFY_SENDUSSD == pRsp->dwType)) )
        {
            BYTE bEncode = SIMTKIT_TEXT_ENCODING_UCS2; // Default text encoding to UCS2
            const WCHAR *wszText;
            DWORD dwTextSize;


            *(lpb++) = TEXTTAG;                     // Tag

            // Currently all other commands are sending in a Text structure.
            SIMTKITRSPTEXT* pText = (SIMTKITRSPTEXT*)pDetails;

            // Assume there is no text string.

⌨️ 快捷键说明

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