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

📄 eons.cpp

📁 ril source code for Windows CE
💻 CPP
📖 第 1 页 / 共 4 页
字号:
//
// 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.
//

/* EONS requires LOCATIONUPDATES */
#ifdef RIL_ENABLE_EONS
#ifdef RIL_NO_CREG_LOCATION_UPDATES
#error RIL_ENABLE_EONS requires RIL_NO_CREG_LOCATION_UPDATES not set
#endif
#endif

/* atcmd */
#include <precomp.h>
#include <atcmd.h>

#include <eons.h>

/* for RIL_REGISTRY_ROOT and RIL_SECURE_REGISTRY_KEY */
#include <ril.h>

/* enable this to vigorously check EFopl and EFpnn coherency */
#if 0
#define CHECK
#endif

extern const DWORD g_rgdwRestrictedSIMCmds[];

/****************************************************************************/
/*** start of helper ATCmd **************************************************/

class CRSMStatus : public ATCmd
{
public:
    CRSMStatus( DWORD dwAddress )
    {
        m_dwAddress = dwAddress;
        memset( &m_rsrs, 0, sizeof(m_rsrs) );
        m_rsrs.dwSize = sizeof(m_rsrs);
    }
    virtual ~CRSMStatus()
    {
    }
    HRESULT Read()
    {
        HRESULT hr = E_FAIL;

        char *szCmd = NULL;
        char buf[128];

        /* based on misc.cpp:RILDrv_GetSimRecordStatus() */
        /* simplied for use in the EONS context */

        StringCchPrintfA( buf, ARRAY_LENGTH(buf), "AT+CRSM=%u,%u,%u,%u,%u",
                            g_rgdwRestrictedSIMCmds[ g_rppPDDParams->dwCRSMStatusCommandId ], m_dwAddress, 0, 0, 15 );

        BOOL fOk = ComposeCmdWithByteArray( buf, NULL, 0, "\r", szCmd );
        if ( fOk )
        {
            hr = Execute( szCmd );
        }
        else
        {
            hr = E_OUTOFMEMORY;
        }

        if ( szCmd != NULL )
        {
            delete[] szCmd;
            szCmd = NULL;
        }

        return hr;
    }
    RILSIMRECORDSTATUS GetStatus() const
    {
        return m_rsrs;
    }
    virtual void Dump() const
    {
#ifdef DEBUG
        DEBUGMSG(ZONE_EONS,(TEXT("RILDrv : i : ---RILSIMRECORDSTATUS[0x%04x]----------\r\n"), m_dwAddress));
        ATCmd::Dump();
        DEBUGMSG(ZONE_EONS,(TEXT("RILDrv : i : cbSize       [%u]\r\n"), m_rsrs.cbSize));
        DEBUGMSG(ZONE_EONS,(TEXT("RILDrv : i : dwParams     [%u]\r\n"), m_rsrs.dwParams));
        if ( m_rsrs.dwParams & RIL_PARAM_SRS_RECORDTYPE )
        {
            DEBUGMSG(ZONE_EONS,(TEXT("RILDrv : i : dwRecordType [%u]\r\n"), m_rsrs.dwRecordType));
        }
        if ( m_rsrs.dwParams & RIL_PARAM_SRS_ITEMCOUNT )
        {
            DEBUGMSG(ZONE_EONS,(TEXT("RILDrv : i : dwItemCount  [%u]\r\n"), m_rsrs.dwItemCount));
        }
        if ( m_rsrs.dwParams & RIL_PARAM_SRS_SIZE )
        {
            DEBUGMSG(ZONE_EONS,(TEXT("RILDrv : i : dwSize       [%u]\r\n"), m_rsrs.dwSize));
        }
        DEBUGMSG(ZONE_EONS,(TEXT("RILDrv : i : ---RILSIMRECORDSTATUS[0x%04x]----------\r\n"), m_dwAddress));
#endif
    }
protected:
    virtual HRESULT Parse( LPCSTR szRsp )
    {
        void *pBlob = NULL;
        UINT cbBlob = 0;

        HRESULT hr = ParseGetSimRecordStatus( szRsp, pBlob, cbBlob );
        if ( SUCCEEDED( hr ) && pBlob != NULL && cbBlob == sizeof(m_rsrs) )
        {
            memcpy( &m_rsrs, pBlob, sizeof(m_rsrs) );
        }

        if ( pBlob != NULL )
        {
            FreeBlob( pBlob );
            pBlob = NULL;
        }

        return hr;
    }
private:
    DWORD m_dwAddress;
    RILSIMRECORDSTATUS m_rsrs;
};

class CRSMRecord : public ATCmd
{
public:
    CRSMRecord( DWORD dwAddress, DWORD dwIndex, DWORD dwSize )
    {
        m_dwAddress = dwAddress;
        m_dwIndex = dwIndex;
        m_dwSize = dwSize;
        m_prsr = NULL;
    }
    virtual ~CRSMRecord()
    {
        if ( m_prsr != NULL )
        {
            FreeBlob( m_prsr );
            m_prsr = NULL;
        }
    }
    HRESULT Read()
    {
        HRESULT hr = E_FAIL;

        char *szCmd = NULL;
        char buf[128];

        /* based on misc.cpp:RILDrv_SendRestrictedSimCmd() */
        /* based on simrecrd.cpp:ReadRecord() */
        /* simplied for use in the EONS context */

        StringCchPrintfA( buf, ARRAY_LENGTH(buf), "AT+CRSM=%u,%u,%u,%u,%u",
                            178, m_dwAddress, m_dwIndex, 4, m_dwSize );

        BOOL fOk = ComposeCmdWithByteArray( buf, NULL, 0, "\r", szCmd );
        if ( fOk )
        {
            hr = Execute( szCmd );
        }
        else
        {
            hr = E_OUTOFMEMORY;
        }

        if ( szCmd != NULL )
        {
            delete[] szCmd;
            szCmd = NULL;
        }

        return hr;
    }
    RILSIMRESPONSE GetResponse() const
    {
        RILSIMRESPONSE rsr;
        memset( &rsr, 0, sizeof(rsr) );
        if ( m_prsr != NULL )
        {
            memcpy( &rsr, m_prsr, sizeof(rsr) );
        }
        return rsr;
    }
    BOOL GetRecord( __in_ecount(cbData) BYTE *pData, DWORD& cbData ) const
    {
        BOOL fOk = FALSE;
        if ( m_prsr != NULL && pData != NULL && cbData > 0 )
        {
            int totalsize = (int)m_prsr->cbSize;
            int responsesize = (int)sizeof(RILSIMRESPONSE);
            int recordsize = ( totalsize - responsesize );
            if ( totalsize > 0 && recordsize > 0 && cbData >= (DWORD)recordsize )
            {
                const BYTE *pPtr = (BYTE*)m_prsr;

                memset( pData, 0, cbData );

                memcpy( pData, pPtr+responsesize, recordsize );
                cbData = (DWORD)recordsize;

                fOk = TRUE;
            }
        }
        return fOk;
    }
    virtual void Dump() const
    {
#ifdef DEBUG
        DEBUGMSG(ZONE_EONS,(TEXT("RILDrv : i : ---RILSIMRESPONSE[%u@0x%04x]----------\r\n"), m_dwIndex, m_dwAddress));
        ATCmd::Dump();
        if ( m_prsr != NULL )
        {
            DEBUGMSG(ZONE_EONS,(TEXT("RILDrv : i : cbSize        [%u]\r\n"), m_prsr->cbSize));
            DEBUGMSG(ZONE_EONS,(TEXT("RILDrv : i : dwParams      [%u]\r\n"), m_prsr->dwParams));
            if ( m_prsr->dwParams & RIL_PARAM_SR_STATUSWORD1 )
            {
                DEBUGMSG(ZONE_EONS,(TEXT("RILDrv : i : dwStatusWord1 [%u]\r\n"), m_prsr->dwStatusWord1));
            }
            if ( m_prsr->dwParams & RIL_PARAM_SR_STATUSWORD2 )
            {
                DEBUGMSG(ZONE_EONS,(TEXT("RILDrv : i : dwStatusWord2 [%u]\r\n"), m_prsr->dwStatusWord2));
            }
            if ( m_prsr->dwParams & RIL_PARAM_SR_RESPONSE )
            {
               DEBUGMSG(ZONE_EONS,(TEXT("RILDrv : i : record length [%u]\r\n"), m_prsr->cbSize-sizeof(RILSIMRESPONSE)));
            }
        }
        DEBUGMSG(ZONE_EONS,(TEXT("RILDrv : i : ---RILSIMRESPONSE[%u@0x%04x]----------\r\n"), m_dwIndex, m_dwAddress));
#endif
    }
protected:
    virtual HRESULT Parse( LPCSTR szRsp )
    {
        void *pBlob = NULL;
        UINT cbBlob = 0;

        HRESULT hr = ParseSendRestrictedSimCmd( szRsp, pBlob, cbBlob );
        if ( SUCCEEDED( hr ) && pBlob != NULL && cbBlob >= sizeof(RILSIMRESPONSE) )
        {
            m_prsr = static_cast<RILSIMRESPONSE*>( pBlob );
        }

        return hr;
    }
private:
    DWORD m_dwAddress;
    DWORD m_dwIndex;
    DWORD m_dwSize;
    RILSIMRESPONSE *m_prsr;
};

/*** end of helper ATCmd ****************************************************/
/****************************************************************************/

/* 3GPP TS 31.102 version 5.7.0 Release 5 sections 4.2.58 and 4.2.59 */
const DWORD EONS::EFopl = 0x6fc6;
const DWORD EONS::EFpnn = 0x6fc5;

const char EONS::WILDCARD = '*';
const char EONS::DONTCARE = 'x';

/* 3GPP TS 24.008 version 3.2.1 Release 1999 Table 9.2.18 */
const int EONS::IEIfullname  = 0x43;
const int EONS::IEIshortname = 0x45;

EONS::EONS()
{
    InitializeCriticalSection( &m_cs );
    m_hThread = NULL;
    m_fDoneReading = FALSE;
}

EONS::EONS( const EONS& ref )
    : m_opl( ref.m_opl ), m_pnn( ref.m_pnn )
{
    InitializeCriticalSection( &m_cs );
    m_hThread = NULL;
    m_fDoneReading = TRUE;    
}

EONS::~EONS()
{
    Clear();
    DeleteCriticalSection( &m_cs );
}

void
EONS::Clear()
{
    SYNCBLOCK( m_cs );

    m_fDoneReading = FALSE;

    m_opl.RemoveAllThings();
    m_pnn.RemoveAllThings();

    if ( m_hThread != NULL )
    {
        CloseHandle( m_hThread );
    }
    m_hThread = NULL;
}

BOOL
EONS::Ready() const
{
    BOOL fReady = FALSE;
    {
        BOOL fCS = TryEnterCriticalSection( &m_cs );
        if ( fCS )
        {
            fReady = m_fDoneReading;
            LeaveCriticalSection( &m_cs );
        }
    }
    return fReady;
}

BOOL
EONS::Search( DWORD dwPLMN, RILOPERATORNAMES *pRON ) const
{
    BOOL fMatched = Match( dwPLMN, 0xFFFFFFFF, pRON );
    return fMatched;
}

BOOL
EONS::Search( DWORD dwPLMN, DWORD dwLAC, RILOPERATORNAMES *pRON ) const
{
    BOOL fMatched = FALSE;
    if ( dwLAC != 0xFFFFFFFF )
    {
        fMatched = Match( dwPLMN, dwLAC, pRON );
    }
    return fMatched;
}

void
EONS::Dump() const
{
#ifdef DEBUG
    SYNCBLOCK( m_cs );
    DEBUGMSG(ZONE_EONS,(TEXT("RILDrv : i : eons -- ready[%d]\r\n"), (int)m_fDoneReading ));
    {
        int c = const_cast<GrowableThingCollection<OPLStruct>*>( &m_opl )->GetSize();
        for( int i = 0; i < c; i++ )
        {
            OPLStruct opl = const_cast<GrowableThingCollection<OPLStruct>*>( &m_opl )->GetThingAtIndex( i );
             DEBUGMSG(ZONE_EONS,(TEXT("RILDrv : i : opl[%d] -- plmn [%hs] lacA [0x%04x] lacZ [0x%04x] pnn [%u]\r\n"), i+1, opl.szPLMN, opl.dwLACa, opl.dwLACz, opl.dwIndex ));
       }
    }
    {
        int c = const_cast<GrowableThingCollection<RILOPERATORNAMES>*>( &m_pnn )->GetSize();
        for( int i = 0; i < c; i++ )
        {
            RILOPERATORNAMES ron = const_cast<GrowableThingCollection<RILOPERATORNAMES>*>( &m_pnn )->GetThingAtIndex( i );
            DEBUGMSG(ZONE_EONS,(TEXT("RILDrv : i : pnn[%d] -- size [%u] param [%u]\r\n"), i+1, ron.cbSize, ron.dwParams));
            if ( ron.dwParams & RIL_PARAM_ON_LONGNAME )
            {
                DEBUGMSG(ZONE_EONS,(TEXT("RILDrv : i : pnn[%d]    long [%hs]\r\n"), i+1, ron.szLongName));
            }
            if ( ron.dwParams & RIL_PARAM_ON_SHORTNAME )

⌨️ 快捷键说明

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