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

📄 rilmain.cpp

📁 windows mobile RIL软件
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/*++
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.
Copyright (c) Microsoft Corporation. All rights reserved.

Module Name:

rilmain.cpp

Abstract:


Notes:


--*/


#include "precomp.h"
#include "rilhand.h"

//
// Globals
//
CRilEventLog g_RilLog;
CRITICAL_SECTION g_csClosing;
#ifdef RIL_RADIO_RESILIENCE
extern CRITICAL_SECTION g_csReboot;
#else
HANDLE g_hCriticalErrorEvent; // = NULL;
#endif // ! RIL_RADIO_RESILIENCE
HANDLE g_hDriverPresentEvent; // = NULL;
HANDLE g_hNewDialOrHangupEvent; // = NULL;
#ifdef OEM2_DRIVER
HANDLE g_hCPINNEvent;
#endif

DWORD g_dwReadyState;
#ifdef PHILIP_DRIVER_NOUSE

DWORD g_dwRegStatus = RIL_REGSTAT_HOME;

#else
DWORD g_dwRegStatus;
#endif
DWORD g_dwGPRSRegStatus;

BOOL g_rfExternalCalltypeDetermination = FALSE;
RILCALLTYPECALLBACK g_rlpfExternalCalltypeFunction = NULL;
HINSTANCE g_hCalltypeLib = NULL;

extern RILCALLINFO g_rgfCallStates[RIL_MAX_TRACKED_CALL_ID];

extern RINGINGCALLDATA g_rcdRingingCallData;
// CS required for safe access - see RINGINGCALLDATA definition for details
CRITICAL_SECTION g_csRingingCallData;

extern DIALEDCALLDATA g_rcdDialedCallData;
// CS required for safe access - see DIALEDCALLDATA definition for details
CRITICAL_SECTION g_csDialedCallData;

extern WAITINGCALLDATA g_rcdWaitingCallData;
// No CS required for safe access - see WAITINGCALLDATA definition for details

// Storage for the SIM toolkit Terminal Profile settings
//CRilSTKTerminalProfile g_RilSTKTerminalProfile;	//commented by viking wang

#ifdef RIL_LAST_ERROR
DWORD g_dwLastError;            // = 0;
#endif

#if defined(OEM1_DRIVER) || defined(PHILIP_DRIVER)
HANDLE g_hWavDev = INVALID_HANDLE_VALUE;
#endif 

#ifdef RIL_WATSON_REPORT
// Info Cache for Watson reporting
RilInfoCache g_RilInfoCache;
CRITICAL_SECTION g_csRilInfoCache; 
BOOL g_fWatsonCalled;

// In-memory buffer to capture AT Cmd logs for Watson reports.
CRilATCmdLogBuffer g_RilATCmdLogBuffer;

// Unique platform identifier used as a Watson parameter 
const TCHAR* gc_szWatsonDeviceType = TEXT("Generic");

DWORD g_WatsonThreadId = NULL;
#endif

BOOL        g_cphschange = FALSE;
const char *g_pcszCPHS   = NULL;

#ifdef RIL_ENABLE_EONS
EONS      g_eons;
EONSCache g_eonscache;
BOOL      g_eonschange = FALSE;
#endif

DBGPARAM dpCurSettings = 
{ 
    L"RILDrv", 
    {
        L"Error",      L"Info",       L"Trace",      L"Function",
        L"Read",       L"NDIS",       L"NDIS Packets",  L"Undefined",
        L"Undefined",  L"Undefined",  L"Undefined",  L"Undefined",
        L"Undefined",  L"Undefined",  L"Undefined",  L"Undefined" 
    },
    ZONEMASK_ERROR |ZONEMASK_INFO |ZONEMASK_TRACE | ZONEMASK_READ
};

//
// Stubs for unsupported RILDrv_ functions
//
#define UNSUPPORTED(n, m) \
HRESULT n m \
{ \
    FUNCTION_TRACE(n); \
    DEBUGMSG(ZONE_ERROR, (TEXT(#n) TEXT("RILDrv : E :  : E_NOTIMPL\r\n"))); \
    return E_NOTIMPL; \
}


UNSUPPORTED(RILDrv_SetDTMFMonitoring, (DWORD, BOOL));
UNSUPPORTED(RILDrv_GetAudioDevices, (DWORD));
UNSUPPORTED(RILDrv_FetchSimToolkitCmd, (DWORD));
UNSUPPORTED(RILDrv_GetCCBSStatus, (DWORD, DWORD));
UNSUPPORTED(RILDrv_ClearCCBSRegistration, (DWORD, DWORD));
UNSUPPORTED(RILDrv_GetSystemTime, (DWORD));
UNSUPPORTED(RILDrv_GetPacketByteCount, (DWORD));
UNSUPPORTED(RILDrv_ResetPacketByteCount, (DWORD));
UNSUPPORTED(RILDrv_SendFlash, (DWORD, RILADDRESS));
UNSUPPORTED(RILDrv_GetRoamingMode, (DWORD));
UNSUPPORTED(RILDrv_SetRoamingMode, (DWORD, DWORD));
UNSUPPORTED(RILDrv_GetPreferredPrivacyMode, (DWORD));
UNSUPPORTED(RILDrv_SetPreferredPrivacyMode, (DWORD, DWORD));
UNSUPPORTED(RILDrv_GetCurrentPrivacyStatus, (DWORD));
UNSUPPORTED(RILDrv_GetCurrentLocationStatus, (DWORD));
UNSUPPORTED(RILDrv_GetCurrentRoamingStatus, (DWORD));
UNSUPPORTED(RILDrv_SendAKey, (DWORD, LPCSTR));

//
// DLL entry point
//
BOOL WINAPI DllMain(HANDLE hinstDll, DWORD dwReason, LPVOID lpReserved)
{
    if (DLL_PROCESS_ATTACH == dwReason)
    {
        g_RilLog.Register();
        DEBUGREGISTER((HMODULE) hinstDll);
        DEBUGMSG(ZONE_TRACE, (TEXT("RILDrv : t : DllMain : DLL_PROCESS_ATTACH\r\n")));

    }
    else if (DLL_PROCESS_DETACH == dwReason)
    {
        g_RilLog.Unregister();
        DEBUGMSG(ZONE_TRACE, (TEXT("RILDrv : t : DllMain : DLL_PROCESS_DETACH\r\n")));
    }
    return TRUE;
}

#ifdef RIL_ALLOW_DRIVER_REMOVAL_TESTING
CRilHandle * g_pDeviceAllowDriverRemovalTesting = NULL;
#define DRIVERCOOKIE_FROM_RILHANDLE(pDevice)    (DWORD)(g_pDeviceAllowDriverRemovalTesting = pDevice)
#define RILHANDLE_FROM_DRIVERCOOKIE(dwData)     (g_pDeviceAllowDriverRemovalTesting)
#else
#define DRIVERCOOKIE_FROM_RILHANDLE(pDevice)    (DWORD)pDevice;
#define RILHANDLE_FROM_DRIVERCOOKIE(dwData)     (CRilHandle*)dwData;
#endif

//
// RIL driver initialization
//
DWORD RIL_Init(DWORD dwInfo)
{
    FUNCTION_TRACE(RIL_Init);
    DEBUGMSG(ZONE_TRACE, (TEXT("RILDrv : t : RIL_Init : params: dwInfo = %d\r\n"), dwInfo));

    CRilHandle* pDevice = NULL;
    DWORD dwRet = 0;
#ifdef PHILIP_DRIVER
	    NKDbgPrintfW(_T("RIL Init: PHILIP_DRIVER defined!\r\n"));
#endif
#ifdef WAVECOM_DRIVER
	    NKDbgPrintfW(_T("RIL Init: WAVECOM_DRIVER defined!\r\n"));
#endif
#ifdef OEM1_DRIVER
	    NKDbgPrintfW(_T("RIL Init: OEM1_DRIVER defined!\r\n"));
#endif
#ifdef OEM2_DRIVER
	    NKDbgPrintfW(_T("RIL Init: OEM2_DRIVER defined!\r\n"));
#endif
#ifdef OEM1_DRIVER
    HANDLE hThread = NULL;
#endif

    // Initialize globals
    InitializeCriticalSection(&g_csClosing);

#ifdef RIL_RADIO_RESILIENCE
    InitializeCriticalSection(&g_csReboot);
    memset(&g_LastResetTime, 0, sizeof(g_LastResetTime));
#else
    g_hCriticalErrorEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
    if (!g_hCriticalErrorEvent)
    {
        goto Error;
    }
#endif // ! RIL_RADIO_RESILIENCE

#ifdef RIL_WATSON_REPORT
    InitializeCriticalSection(&g_csRilInfoCache);    
#endif // RIL_WATSON_REPORT

#if defined(OEM1_GPRS_DEACT) || defined(EMP_DRIVER)
    InitializeCriticalSection(&g_csGPRSDeactLock);    
#endif // defined(OEM1_GPRS_DEACT) || defined(EMP_DRIVER)

    InitializeCriticalSection(&g_csDeactCringLock);    

    g_hDriverPresentEvent = CreateEvent(NULL, TRUE, FALSE, RILDRIVERPRESENT_EVENT);
    if (!g_hDriverPresentEvent)
    {
        goto Error;
    }

    g_hNewDialOrHangupEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
    if (!g_hNewDialOrHangupEvent)
    {
        goto Error;
    }

#ifdef OEM2_DRIVER
    g_hCPINNEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    if (!g_hCPINNEvent)
    {
        goto Error;
    }
#endif

#ifdef RIL_WATSON_REPORT
    // Initialize the info cache used for watson reporting
    memset(&(g_RilInfoCache), 0, sizeof(g_RilInfoCache));

    // Initialize flag used to prevent multiple Watson reporting of the same problem
    g_fWatsonCalled = FALSE;

    // Initialize the AT Cmd log
    g_RilATCmdLogBuffer.Init(RILATCMDLOGSIZE);
#endif // RIL_WATSON_REPORT

    // Initialize the default Terminal profile settings.
   //g_RilSTKTerminalProfile.InitializeDefault();	//commented by viking wang

    // Allocate a device handle
    pDevice = new CRilHandle;
    if (!pDevice || !pDevice->StartInit())
    {
        goto Error;
    }

    dwRet = DRIVERCOOKIE_FROM_RILHANDLE(pDevice);

#ifdef OEM1_DRIVER_PM
    //
    // PM processing
    //
    hThread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)RIL_PmProc, NULL, 0, NULL);
    if (hThread == NULL)
    {
        RETAILMSG(1, (TEXT("RIL: Error PM CreateThread() !\r\n")));
    }

    // no need to keep track of it
    CloseHandle(hThread);
#endif // OEM1_DRIVER_PM

    // Driver has started successfully, so set
    // the event that says RIL driver is up.
    SetEvent(g_hDriverPresentEvent);
    g_RilLog.LogEvent(RILLOG_ZONE_PRESENCE, RILLOG_EVENT_RADIOPRESENT);

#ifdef OEM1_DRIVER
    // Open Wave driver 
    g_hWavDev = CreateFile(TEXT("WAV1:"),
        GENERIC_READ | GENERIC_WRITE,
        0, NULL,
        OPEN_EXISTING,
        0, NULL);

    if (g_hWavDev == INVALID_HANDLE_VALUE)
    {
        TBD_OUTPUT(TBDCT_INFO, TBDOL_ERROR, TEXT("RIL_Init : failed to open WavDev driver"));
        goto Error;
    }
#endif

    DWORD dwEONSEnabled = 0;

#ifdef RIL_ENABLE_EONS
    {
        /* read EONS cache */
        HRESULT hr = g_eonscache.Read();
        if ( FAILED( hr ) )
        {
            DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RIL_Init : error reading EONS cache -- result [0x%08x]\r\n"), hr));
            goto Error;
        }
        g_eonscache.Dump();

        /* mark as enabled */
        dwEONSEnabled = 1;
    }
#endif

    /* indicate if EONS is enabled */
    {
        DEBUGMSG(ZONE_INFO, (TEXT("RILDrv : i : RIL_Init : EONS [%d]\r\n"), (int)dwEONSEnabled));

        HKEY hkey = NULL;
        LONG l = RegOpenKeyEx( RIL_REGISTRY_ROOT, RIL_SECURE_REGISTRY_KEY, 0, 0, &hkey );
        if ( l == ERROR_SUCCESS )
        {
            DWORD dwSize = sizeof(dwEONSEnabled);
            l = RegSetValueEx( hkey, RIL_REGISTRY_VALUE_EONSENABLED, 0, REG_DWORD, (LPBYTE)&dwEONSEnabled, dwSize );
        }
        if ( hkey != NULL )
        {
            RegCloseKey( hkey );
        }
        hkey = NULL;

        if ( l != ERROR_SUCCESS )
        {
            DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RIL_Init : error writing to RIL secure registry location -- result [0x%08x]\r\n"), HRESULT_FROM_WIN32(l)));
            goto Error;
        }
    }

    //load calltype determination library
    TCHAR tszCalltypeDll[MAXLENGTH_CALLTYPEKEY];
    TCHAR tszCalltypeFunction[MAXLENGTH_CALLTYPEKEY];
    if (!GetRegistrySZ(HKEY_LOCAL_MACHINE, g_tszRegKeyRemoteCalltype, TEXT("CalltypeDLL"), tszCalltypeDll, MAXLENGTH_CALLTYPEKEY))
    {
        DEBUGMSG(ZONE_INFO, (TEXT("RILDrv : i : RIL_Init : No Calltype reg key.\r\n")));
    }
    else
    {
        HINSTANCE hCalltypeLib = LoadLibrary(tszCalltypeDll);
        if (!hCalltypeLib)
            DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RIL_Init : Calltype Lib not loaded, err = 0x%08x.\r\n"),GetLastError()));
        else
        {
            if (!GetRegistrySZ(HKEY_LOCAL_MACHINE, g_tszRegKeyRemoteCalltype, TEXT("CalltypeFunction"), tszCalltypeFunction, MAXLENGTH_CALLTYPEKEY))
            {
                DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RIL_Init : No CalltypeFunction in reg key.\r\n")));
                FreeLibrary(hCalltypeLib);
            }
            else
            {        

⌨️ 快捷键说明

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