📄 rilhand.cpp
字号:
{
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)
{
// 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);
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 thread!
if(pCmd->FDial())
{
// Dial commands were not put on the queue, so we don't need to remove them now
}
else
{
// By definition, our command must be the only one in the queue. Just get it back out.
// When we return fRet==FALSE, the calling code will fail the response to the app.
CCommand *pCmdTmp;
g_pSimLockedQueue->Get(pCmdTmp, 0);
DEBUGCHK(pCmd == pCmdTmp);
}
DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : PromptForSimAndRequeueCmd : Unable to CreateThread(PromptForSimAndRequeueCmdProc)\r\n")));
goto Exit;
}
else
{
CloseHandle(hThread); // close handle we don't need
}
g_PromptingForSim=TRUE;
}
if(!pCmd->FDial())
{
// See comment above about leaving fRet FALSE for dial commands
fRet=TRUE;
}
Exit:
return fRet;
}
//
// Handle response to an AT command
//
BOOL CRilHandle::HandleRsp(CCommand*& rpCmd, CResponse*& rpRsp, BOOL& rfHungUp, BOOL& rfRadioOff)
{
// FUNCTION_TRACE(CRilHandle::HandleRsp);
DEBUGCHK(rpCmd != NULL);
DEBUGCHK(rpRsp != NULL);
void* pBlob = NULL;
UINT cbBlob = 0;
HRESULT hrError;
CNotificationData* pnd = NULL;
BOOL fRet = FALSE;
rfHungUp = FALSE;
// Handle logging of OK and ERROR responses
if (NULL == rpCmd->GetParseFunc() && !rpCmd->FNoOp())
{
DWORD dwZone = rpCmd->CmdOptIsSet(CMDOPT_POLLING) ?
RILLOG_ZONE_CMD_POLLING : RILLOG_ZONE_CMD;
if (RIL_RESULT_OK == rpRsp->GetNotifyCode())
{
g_RilLog.LogEvent(dwZone, RILLOG_EVENT_CMDRSPOK);
}
else if (E_FAIL == rpRsp->GetError())
{
g_RilLog.LogEvent(dwZone, RILLOG_EVENT_CMDRSPERROR);
}
}
// Is this the last modem init command? If so, and if it succeeded, then we're done with initialization
if (rpCmd->FFinalInit())
{
#ifdef RIL_RADIO_RESILIENCE
g_fInitedFirstTime = TRUE;
#endif // !RIL_RADIO_RESILIENCE
NKDbgPrintfW(TEXT("Prepare to enter FinishInit!!!!\r\n"));
FinishInit(rpCmd,(RIL_RESULT_OK == rpRsp->GetNotifyCode()));
}
if ((rpCmd->CmdOptIsSet(CMDOPT_UNLOCKING)) && (RIL_RESULT_OK == rpRsp->GetNotifyCode()))
{
// Well, looks like we successfully unlocked the phone
DEBUGMSG(ZONE_INFO, (TEXT("RILDrv : i : The phone is now unlocked\r\n")));
SendReadyStateNotification(RIL_READYSTATE_UNLOCKED);
}
if ((rpCmd->CmdOptIsSet(CMDOPT_RETRYONSIMLOCKED)) && (rpRsp->GetNotifyCode()==RIL_RESULT_ERROR))
{
BOOL bPrompt=FALSE;
void* pBlobSim = NULL;
UINT cbBlobSim = 0;
rpRsp->GetBlob(pBlobSim, cbBlobSim);
ASSERT(cbBlobSim==sizeof(DWORD));
DWORD dwLockFacility;
switch(*(DWORD*)pBlobSim)
{
case RIL_E_PHSIMPINREQUIRED:
case RIL_E_PHFSIMPINREQUIRED:
case RIL_E_PHFSIMPUKREQUIRED:
case RIL_E_SIMPINREQUIRED:
case RIL_E_SIMPUKREQUIRED:
case RIL_E_SIMNOTINSERTED:
case RIL_E_SIMFAILURE:
dwLockFacility=SIM_LOCKFACILITY_SIM;
bPrompt=TRUE;
break;
case RIL_E_SIMPIN2REQUIRED:
case RIL_E_SIMPUK2REQUIRED:
dwLockFacility=SIM_LOCKFACILITY_SIM_PIN2;
bPrompt=TRUE;
}
if (bPrompt)
{
if (PromptForSimAndRequeueCmd(rpCmd,dwLockFacility))
{
delete pnd;
delete rpRsp;
rpCmd = NULL;
rpRsp = NULL;
return TRUE;
}
}
}
#if 0
// This code isn't really used anymore, since the inside of the SendRILCmdHandleRsp function also does something similar
// for timed out commands
// If this was an init command and it failed, try again up to some limit
if (rpCmd->FInit())
{
if (RIL_RESULT_OK != rpRsp->GetNotifyCode())
{
if (rpCmd->OkToRetry())
{
if (!RequeueCmdWithDelay(rpCmd, 5000))
{
goto Error;
}
}
}
}
#endif
// If we need to re-init the modem after this command and the command was sucessful, do it
if (rpCmd->FReinit() && RIL_RESULT_OK == rpRsp->GetNotifyCode())
{
NKDbgPrintfW(TEXT("CRilHandle::HandleRsp: Process re-init!!!!\r\n"));
PrepareForReinit();
if (!SendComInitString(COM_REINIT_INDEX))
{
// We failed sending the init strings -- RIL is not initialized
goto Error;
}
}
if (rpCmd->FHangup())
{
// If this is a hangup command and we got a NO CARRIER response, turn it into OK
if (RIL_RESULT_NOCARRIER == rpRsp->GetNotifyCode())
{
rpRsp->NoCarrierToOK();
}
// If hangup was successful, let the caller know
if (RIL_RESULT_OK == rpRsp->GetNotifyCode())
{
rfHungUp = TRUE;
}
}
if (rpCmd->FRequireConnectRsp())
{
// ??? Do we want to set rfHungUp for all commands with NO CARRIER response?
if (RIL_RESULT_NOCARRIER == rpRsp->GetNotifyCode())
{
rfHungUp = TRUE;
}
#if defined(WAVECOM_DRIVER) || defined(PHILIP_DRIVER)
else if (RIL_RESULT_ERROR == rpRsp->GetNotifyCode() &&
RIL_E_OPNOTALLOWED == rpRsp->GetError())
{
rfHungUp = TRUE;
}
#endif
}
// Even though we may ultimately ignore the response, we should still parse it
// so that we can cache it if desired.
if ((RIL_RESULT_OK == rpRsp->GetNotifyCode()) || rpCmd->CmdOptIsSet(CMDOPT_FORCEPARSE))
{
(void)rpRsp->ParseOKData(rpCmd);
}
if (rpCmd->CmdOptIsSet(CMDOPT_SIMQUERY))
{
// We were just checking to see if the SIM is ready or not. We only care about if the return
// value is NOT READY or not in this case
hrError = rpRsp->GetError();
m_fSimReady = (hrError != RIL_E_NOTREADY);
if (m_fSimReady)
{
// Hey, as long as we got the PIN state, let's see if it's
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -