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

📄 rilmain.cpp

📁 ril source code for Windows CE
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    {
        /* read EONS cache */
        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));

        DWORD dwDeposition = 0;

        HKEY hkey = NULL;
        LONG l = RegCreateKeyEx( RIL_REGISTRY_ROOT, RIL_SECURE_REGISTRY_KEY, 0, NULL, 0, 0, NULL, &hkey, &dwDeposition );
        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
            {        
                RILCALLTYPECALLBACK rctcb = (RILCALLTYPECALLBACK)GetProcAddress(hCalltypeLib,tszCalltypeFunction);
                if (!rctcb)
                {
                    DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RIL_Init : Calltype Lib GetProcAddress failed, err = 0x%08x.\r\n"),GetLastError()));
                    FreeLibrary(hCalltypeLib);
                }
                else
                {
                    g_rfExternalCalltypeDetermination = TRUE;
                    g_rlpfExternalCalltypeFunction = rctcb;
                    g_hCalltypeLib = hCalltypeLib;
                    InitializeCriticalSection(&g_csDialedCallData);
                    InitializeCriticalSection(&g_csRingingCallData);
                    DEBUGMSG(ZONE_INFO, (TEXT("RILDrv : i : RIL_Init : Calltype Callback registered, dll = %s, function = %s.\r\n"),tszCalltypeDll,tszCalltypeFunction));
                }
            }
        }
    }

    // Read the registry key to decide if we print out SIM PIN information
    if (!GetRegistryDWORD(HKEY_LOCAL_MACHINE, g_tszRegKeyRILMS, TEXT("PrintSIMPINInfo"), &g_dwPrintSIMPINInfo))
    {
        g_dwPrintSIMPINInfo = 0;
    }

    // Initialize global structures
    memset(&g_rcdRingingCallData, 0, sizeof(g_rcdRingingCallData));
    g_rcdRingingCallData.dwCallId = RIL_MAX_TRACKED_CALL_ID;
    
    memset(&g_rcdDialedCallData, 0, sizeof(g_rcdDialedCallData));
    memset(&g_rcdWaitingCallData, 0, sizeof(g_rcdWaitingCallData));

    memset(&g_rgfCallStates, 0, sizeof(g_rgfCallStates));

    DEBUGMSG(ZONE_TRACE, (TEXT("RILDrv : t : RIL_Init : Started successfully\r\n")));

    Error:
    if (!dwRet)
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RIL_Init : RIL failed to initialize\r\n")));

        RIL_EVENTLOG_MSG((RILLOG_EVENT_DRVINITFAILED));

        delete pDevice;
        if (g_hDriverPresentEvent)
        {
            (void)CloseHandle(g_hDriverPresentEvent);
            g_hDriverPresentEvent = NULL;
        }

#ifdef RIL_RADIO_RESILIENCE
        DeleteCriticalSection(&g_csReboot);
#else
        if (g_hCriticalErrorEvent)
        {
            (void)CloseHandle(g_hCriticalErrorEvent);
            g_hCriticalErrorEvent = NULL;
        }
#endif // ! RIL_RADIO_RESILIENCE
        DeleteCriticalSection(&g_csClosing);
#ifdef RIL_WATSON_REPORT
        DeleteCriticalSection(&g_csRilInfoCache);
#endif // RIL_WATSON_REPORT

        DeleteCriticalSection(&g_csDeactCringLock); 
        DeleteCriticalSection(&g_csCallStates);
        hr = PDD_Deinitialize();
        if ( FAILED( hr ) )
        {
            DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RIL_Init : PDD_Deinitialize failed , hr = [0x%08x]\r\n"), hr));
        }
    }

    return dwRet;
}

//
// Driver de-initialization
//
#ifdef __cplusplus
extern "C" BOOL RIL_Deinit(DWORD dwData)
#else
DWORD BOOL RIL_Deinit(DWORD dwData)
#endif
{
    FUNCTION_TRACE(RIL_Deinit);
    DEBUGCHK(dwData != 0);

    CRilHandle* pDevice = RILHANDLE_FROM_DRIVERCOOKIE(dwData);
    BOOL fRet = FALSE;

    // Driver is going away. Clear event that
    // says RIL driver is up.
    if (g_hDriverPresentEvent)
    {
        ResetEvent(g_hDriverPresentEvent);
        (void)CloseHandle(g_hDriverPresentEvent);
        g_hDriverPresentEvent = NULL;
        RIL_EVENTLOG_MSG((RILLOG_EVENT_RADIOREMOVED));
    }

    if (g_rfExternalCalltypeDetermination)
    {
        g_rfExternalCalltypeDetermination = FALSE;
        g_rlpfExternalCalltypeFunction = NULL;
        if (NULL != g_hCalltypeLib)
            FreeLibrary(g_hCalltypeLib);
        g_hCalltypeLib = NULL;
        DeleteCriticalSection(&g_csRingingCallData);    
        DeleteCriticalSection(&g_csDialedCallData);    
    }

    // Need to clear the RIL handle for CPI notifications.
    g_pRilHandleDevice = NULL;

    if (!pDevice)
    {
        goto Error;
    }
    delete pDevice;

#ifdef RIL_RADIO_RESILIENCE
    g_cbLastLockCapsSize = 0;
    FreeBlob(g_pLastLockCaps);
    DeleteCriticalSection(&g_csReboot);
#else
    if (g_hCriticalErrorEvent)
    {
        (void)CloseHandle(g_hCriticalErrorEvent);
        g_hCriticalErrorEvent = NULL;
    }
#endif // ! RIL_RADIO_RESILIENCE

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

    DeleteCriticalSection(&g_csDeactCringLock); 
    DeleteCriticalSection(&g_csCallStates);
    DeleteCriticalSection(&g_csClosing);
    fRet = TRUE;

    HRESULT hr = PDD_Deinitialize();
    if ( FAILED( hr ) )
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RIL_Deinit : PDD_Deinitialize failed , hr = [0x%08x]\r\n"), hr));
    }
    
    Error:
    return fRet;
}


//
// Open a driver instance
//
#ifdef __cplusplus
extern "C" DWORD RIL_Open(DWORD dwData, DWORD dwAccess, DWORD dwShareMode)
#else
DWORD RIL_Open(DWORD dwData, DWORD dwAccess, DWORD dwShareMode)
#endif
{
    FUNCTION_TRACE(RIL_Open);
    DEBUGCHK(dwData != 0);

    CRilInstanceHandle* pHandle = NULL;
    CRilHandle* pDevice = RILHANDLE_FROM_DRIVERCOOKIE(dwData);
#ifdef RIL_ALLOW_DRIVER_REMOVAL_TESTING
    if (!g_pDeviceAllowDriverRemovalTesting)
    {
        return 0x4321;
    }
#endif
    DWORD dwRet = 0;

    // Wait until the COM port is initialized
    if (!pDevice /* || !pDevice->WaitForInit(MAX_DRIVERINIT_TIME) */ )
    {
        goto Error;
    }

    pHandle = new CRilInstanceHandle;
    if (!pHandle || !pHandle->Init(pDevice))
    {
        goto Error;
    }

    // Insert new handle into the handle list
    if (!pDevice->AddToList(pHandle))
    {
        goto Error;
    }

    dwRet = (DWORD)pHandle;

    Error:
    if (!dwRet)
    {
        delete pHandle;
    }
    return dwRet;
}


//
// Close a driver instance
//
#ifdef __cplusplus
extern "C" BOOL RIL_Close(DWORD dwOpenData)
#else
BOOL RIL_Close(DWORD dwOpenData)
#endif
{
    FUNCTION_TRACE(RIL_Close);
    DEBUGCHK(dwOpenData != 0);

#ifdef RIL_ALLOW_DRIVER_REMOVAL_TESTING
    if (dwOpenData == 0x4321 || !g_pDeviceAllowDriverRemovalTesting)
    {
        return TRUE;
    }
#endif
    CRilInstanceHandle* pHandle = (CRilInstanceHandle*)dwOpenData;
    BOOL fRet = FALSE;

    if (!pHandle)
    {
        goto Error;
    }

    {
        SYNCBLOCK(g_csClosing);

        // Make sure no commands refer to this handle
        pHandle->GetCmdList()->Enum(ClearCmdHandle, 0);
    }

    DEBUGCHK(pHandle->GetDevice() != 0);

    // Remove the handle from the handle list
    if (!pHandle->GetDevice()->RemoveFromList(pHandle))
    {
        goto Error;
    }

    delete pHandle;
    fRet = TRUE;

    Error:
    return fRet;
}



//
// Emulate serial read
//
#ifdef __cplusplus
extern "C" DWORD RIL_Read(DWORD dwOpenData, LPVOID pBuf, DWORD len)
#else
DWORD RIL_Read(DWORD dwOpenData, LPVOID pBuf, DWORD len)
#endif
{
#ifdef RIL_ALLOW_DRIVER_REMOVAL_TESTING
    if (g_pDeviceAllowDriverRemovalTesting)
    {
        RIL_Close(dwOpenData);
        RIL_Deinit(1);
        g_pDeviceAllowDriverRemovalTesting = NULL;
    }
#endif
    return 0;

⌨️ 快捷键说明

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