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

📄 rilhand.cpp

📁 手机RILGSM实现的源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        g_pRspQ = NULL;
        g_pSimLockedQueue = NULL;

        if (m_hCancelEvent)
        {
            (void)CloseHandle(m_hCancelEvent);
            m_hCancelEvent = NULL;
        }
    }
    return fRet;
}


//
// Test the cancel event
//
BOOL CRilHandle::FCancelSet() const
{
    // // FUNCTION_TRACE(CRilHandle::FCancelSet);
    return (WAIT_OBJECT_0 == WaitForSingleObject(m_hCancelEvent, 0));
}


//
//
//
BOOL CRilHandle::WaitForInit(DWORD dwTimeout) const
{
    // FUNCTION_TRACE(CRilHandle::WaitForInit);
    HANDLE rghEvents[] = { m_hInitEvent, m_hCancelEvent };
    switch (WaitForMultipleObjects(2, rghEvents, FALSE, dwTimeout))
    {
    case WAIT_OBJECT_0:
    case WAIT_OBJECT_0 + 1:
        return TRUE;
    default:
        return FALSE;
    }
}


//
// Returns true if there is a command on the command queue that can
// be executed now.
// Returns false if the command thread should quit.
//
BOOL CRilHandle::WaitForCommandOrCancel() const
{
    BOOL fRet = FALSE;
    CCommand* pCmd = NULL;
    HANDLE rghEvents[] = { g_pCmdQ->GetPutEvent(), m_hCancelEvent, m_hInitEvent };

    if (WAIT_OBJECT_0 == WaitForSingleObject(m_hInitEvent, 0))
    {
        // If the init event is signaled now, then it doesn't
        // matter what the next command is. Set return to true.
        // The subsequent call to Get will block if the queue
        // happens to be empty.
        fRet = TRUE;
    }

    while (!fRet)
    {
        // Look for a command on the queue.
        if (g_pCmdQ->Peek(pCmd))
        {
            if (pCmd->FInit())
            {
                // The next command is for init. Send it.
                fRet = TRUE;
                break;
            }
        }

        switch (WaitForMultipleObjects(3, rghEvents, FALSE, INFINITE))
        {
        case WAIT_OBJECT_0:
            // Put signaled. Loop to see if it is an init command.
            break;

        case WAIT_OBJECT_0 + 1:
            // Cancel signaled, so return FALSE now.
            return FALSE;

        case WAIT_OBJECT_0 + 2:
            // Init command signaled, so ok to send next command.
            fRet = TRUE;
            break;

        default:
            return FALSE;
        }
    }

    DEBUGCHK(TRUE == fRet);

    // Check the cancel event before returning
    // in case some other event (like init)
    // preempted this event.
    return (!FCancelSet());
}


//
//
//
BOOL CRilHandle::AddToList(CRilInstanceHandle* const pInstance)
{
    // FUNCTION_TRACE(CRilHandle::AddToList);
    return m_pInstances->Add(pInstance);
}


//
//
//
BOOL CRilHandle::RemoveFromList(CRilInstanceHandle* const pInstance)
{
    // FUNCTION_TRACE(CRilHandle::RemoveFromList);
    return m_pInstances->Remove(pInstance);
}


//
//
//
HRESULT CRilHandle::GetNextCmdID()
{
    // FUNCTION_TRACE(CRilHandle::GetNextCmdID);
    SYNCBLOCK(m_csCmdID);

    // Make sure not to wrap into error values
    if (FAILED(m_hrNextCmdID))
    {
        m_hrNextCmdID = INITIAL_COMMAND_ID;
    }
    m_hrNextCmdID += 2;
    //end modify
    return m_hrNextCmdID;
}


//
// Function passed to CDlbList::Enum() below
//
BOOL NotifyHandle(void* pItem, DWORD dwData)
{
    FUNCTION_TRACE(NotifyHandle);
    DEBUGCHK(pItem != NULL);
    DEBUGCHK(dwData != NULL);

    CRilInstanceHandle* pHandle = (CRilInstanceHandle*)pItem;
    CNotificationData* pnd = (CNotificationData*)dwData;

    if (pHandle->FReadyForNotifications())
    {
        pHandle->Notify(pnd->GetCode(), S_OK, pnd->GetBlob(), pnd->GetSize());
    }

    // Continue enumeration
    return FALSE;
}


//
// Broadcast a notification to all clients
//
void CRilHandle::BroadcastNotification(CNotificationData*& rpnd)
{
    // FUNCTION_TRACE(CRilHandle::BroadcastNotification);
    DEBUGCHK(NULL != m_pInstances);
    DEBUGCHK(NULL != rpnd);

    DEBUGMSG(ZONE_TRACE, (TEXT("RILDrv : t : CRilHandle::BroadcastNotification : Broadcasting notification 0x%x\r\n"), rpnd->GetCode()));

    // Notify all RIL proxy instances
    m_pInstances->Enum(NotifyHandle, (DWORD)rpnd);

    // Get rid of the notififcation
    delete rpnd;
    rpnd = NULL;
}


//
//
//
BOOL CRilHandle::BroadcastRealBlobNotification(const DWORD dwNotificationCode, const void* const pBlob,
                                               const UINT cbBlob)
{
    // FUNCTION_TRACE(CRilHandle::BroadcastRealBlobNotification);
    CNotificationData* pnd = NULL;
    BOOL fRet = FALSE;

    pnd = new CNotificationData;
    if (!pnd || !pnd->InitFromRealBlob(dwNotificationCode, pBlob, cbBlob))
    {
        goto Error;
    }

    BroadcastNotification(pnd);
    DEBUGCHK(NULL == pnd);
    fRet = TRUE;

    Error:
    delete pnd;
    return fRet;
}

//
//
//
BOOL CRilHandle::BroadcastATLogBlobNotification(const void* const pBlob,
                                                UINT uBlob, BOOL fResponse)
{
    // FUNCTION_TRACE(CRilHandle::BroadcastRealBlobNotification);
    CNotificationData* pnd = NULL;
    BOOL fRet = FALSE;
    RILLOGATINFO rilATLogInfo;
    CRilInstanceHandle* pCRilInstanceHandle;

    // If we don't have a handle to the application, we can' proceed.
    if ( !m_hATCommandLogOwner )
        return fRet;
    else
        pCRilInstanceHandle = (CRilInstanceHandle*)m_hATCommandLogOwner;
    
    memset(&rilATLogInfo, 0x00, sizeof(rilATLogInfo));
    rilATLogInfo.cbSize = sizeof(rilATLogInfo);
    rilATLogInfo.fResponse = fResponse;
    if ( uBlob >= MAXLENGTH_CMD )
         uBlob = MAXLENGTH_CMD -1;
    
    memcpy(rilATLogInfo.szRsp, pBlob, uBlob);
    rilATLogInfo.cbLength = uBlob;
    
    pnd = new CNotificationData;
    if (!pnd || !pnd->InitFromRealBlob(RIL_NOTIFY_ATLOGGING, &rilATLogInfo, sizeof(rilATLogInfo)))
    {
        goto Error;
    }

    if (pCRilInstanceHandle->FReadyForNotifications())
    {
        pCRilInstanceHandle->Notify(pnd->GetCode(), S_OK, pnd->GetBlob(), pnd->GetSize());
    }
    
    fRet = TRUE;

    Error:
    delete pnd;
    return fRet;
}

//
//
//
BOOL CRilHandle::BroadcastDWORDBlobNotification(const DWORD dwNotificationCode, const DWORD dwBlob)
{
    // FUNCTION_TRACE(CRilHandle::BroadcastDWORDBlobNotification);
    CNotificationData* pnd = NULL;
    BOOL fRet = FALSE;

    pnd = new CNotificationData;
    if (!pnd || !pnd->InitFromDWORDBlob(dwNotificationCode, dwBlob))
    {
        goto Error;
    }

    BroadcastNotification(pnd);
    DEBUGCHK(NULL == pnd);
    fRet = TRUE;

    Error:
    delete pnd;
    return fRet;
}

//
//
//
DWORD WINAPI PromptForSimAndRequeueCmdProc(LPVOID lpParameter)
{
    FUNCTION_TRACE(PromptForSimAndRequeueCmdProc);
    HRESULT Result;
    HINSTANCE hInstSimSec;


    // Load the simsec library
    hInstSimSec = LoadLibrary(TEXT("simsec.dll"));
    if (!hInstSimSec)
    {
        goto Exit;
    }

    // Get the address of the simsec ui
    typedef HRESULT (*SIMSECURITYUNLOCKPHONE) (HWND hwndMain, DWORD dwStyle);
    SIMSECURITYUNLOCKPHONE pfnSIMSecurityUnlockPhone;
    pfnSIMSecurityUnlockPhone = (SIMSECURITYUNLOCKPHONE)GetProcAddress(hInstSimSec, TEXT("SIMSecurityUnlockPhone"));
    if (pfnSIMSecurityUnlockPhone)
    {
        // Put up the UI
#ifdef TPC
        Result = pfnSIMSecurityUnlockPhone(NULL, SIMSEC_STYLE_CANNOT_CANCEL | SIMSEC_STYLE_EMERGENCY_CALL | SIMSEC_STYLE_BRANDED);
#else
        Result = pfnSIMSecurityUnlockPhone(NULL, SIMSEC_STYLE_EMERGENCY_CALL);
#endif
    }
    else
    {
#ifdef TPC
        ASSERT(FALSE);
        goto Exit;
#else
        // backward compatibility for old simsecui, which doesn't have UnlockPhone, and instead uses CheckPin
        typedef HRESULT (*SIMSECURITYCHECKPIN) (HWND hwndMain, SIMPIN_TYPE nPinType, DWORD dwStyle);
        SIMSECURITYCHECKPIN pfnSIMSecurityCheckPin;
        pfnSIMSecurityCheckPin = (SIMSECURITYCHECKPIN)GetProcAddress(hInstSimSec, TEXT("SIMSecurityCheckPin"));
        if (pfnSIMSecurityCheckPin)
        {
            // Put up the UI
            Result = pfnSIMSecurityCheckPin(NULL, (SIM_LOCKFACILITY_SIM == g_dwLockFacility) ? SIMPIN_SIM : SIMPIN_SIM2,
                SIMSEC_STYLE_AUTO_CLOSE | SIMSEC_STYLE_EMERGENCY_CALL);
        }
        else
        {
            goto Exit;
        }
#endif // !TPC
    }


    // Free the library
    FreeLibrary(hInstSimSec);

Exit:
    // Not prompting anymore
    g_PromptingForSim=FALSE;

    // Now safe to requeue the pending commands to try again
    // Requeue any existing commands
    // If the SIM was unlocked, they'll now succeed.
    // Otherwise they'll fail as expected.
    CCommand* pCmd;
    while (g_pSimLockedQueue->Get(pCmd, 0)==S_OK)
    {
        if (!g_pCmdQ->Put(pCmd, INFINITE))
        {
            delete pCmd;
        }
    }

    return 0;
}

//
//
//
BOOL PromptForSimAndRequeueCmd(CCommand* pCmd, DWORD dwLockFacility)
{
    FUNCTION_TRACE(PromptForSimAndRequeueCmd);
    DEBUGCHK(NULL != pCmd);

    BOOL fRet=FALSE;

    // Queue command up on SIM retry queue
    if(pCmd->FDial())
    {
        // Not re-queuing dial commands
        // Leave fRet FALSE to indicate that the existing response should be used
    }
    else
    {
        pCmd->ClrCmdOpt(CMDOPT_RETRYONSIMLOCKED);
        fRet = g_pSimLockedQueue->Put(pCmd, 0);
        if (!fRet)
        {
            DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : PromptForSimAndRequeueCmd : Unable to queue cmd\r\n")));
            goto Exit;
        }
    }

    // Is another dialog already up?
    // Note: don't need to worry about
    if (!g_PromptingForSim)
    {
        HANDLE hThread;
        // Remember to save nPinType;
        g_dwLockFacility=dwLockFacility;
        hThread = CreateThread(NULL, 0, PromptForSimAndRequeueCmdProc, (LPVOID)NULL, 0, NULL);
        if (!hThread)
        {
            // Eek, we can't create a thre

⌨️ 快捷键说明

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