📄 rilhand.cpp
字号:
}
while (!m_fInitedForSMS && !m_fQuitReadyStateThread);
if (m_fQuitReadyStateThread)
{
goto Error;
}
SendReadyStateNotification(RIL_READYSTATE_SMS);
}
SimPhoneBookReady:
if (g_rppPDDParams->fRequireWaitingForSIMPhoneBookReady) {
// Phase 2 - Wait for SIM phonebook to be ready
pCmd = new CCommand;
if (!pCmd || !pCmd->Init(NULL, "AT+STPD=12,0901FF7F602000106200000F\r", NULL, CMDOPT_IGNORERSP, EXECTIME_API_DEFAULT, g_TimeoutCmdInit, NULL, NULL, 0, 0, 0, APIID_NONE, NULL, NULL))
{
DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : SIMReadyThread : Unable to create SIMTK cmnd\r\n")));
goto Error;
}
else
{
if (!g_pCmdQ->Put(pCmd, INFINITE))
{
goto Error;
}
}
// Create the needed event
m_fInitedForSIMPB = FALSE;
m_dwSIMPBLastSize = (DWORD)-1;
m_hInitedForSIMPBEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if (!m_hInitedForSIMPBEvent)
{
goto Error;
}
//now perform SIM phonebook ready check for some radios
//that do not support a SIM PB ready notification,
//and will simply fail read attempts for SIM PB entries that have not
//yet been copied from non-volatile SIM memory to volatile SIM memory.
//so for those platforms we'll poll every 10 seconds to see whether or not the number of
//SIM entries has stabilized to a steady state, at which point we'll
//call the SIM PB ready.
DEBUGMSG(ZONE_TRACE, (TEXT("RILDrv : t : SIMPBReadyThread : Sending select SIMPB Command...\r\n")));
pCmd = new CCommand;
if (!pCmd || !pCmd->Init(NULL, "AT+CPBS=\"SM\"\r", NULL, CMDOPT_IGNORERSP, EXECTIME_API_DEFAULT, g_TimeoutCmdInit, NULL, NULL, 0, 0, 0, APIID_NONE, NULL, NULL))
{
DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : SIMPBReadyThread : Unable to construct or Init CCommand\r\n")));
goto Error;
}
// Place the command into the command queue
// (this may block if the queue is full)
if (!g_pCmdQ->Put(pCmd, INFINITE))
{
goto Error;
}
do
{
if (g_dwReadyState & RIL_READYSTATE_UNLOCKED)
{
DEBUGMSG(ZONE_TRACE, (TEXT("RILDrv : t : SIMPBReadyThread : Sending SIMPB size query Command...\r\n")));
pCmd = new CCommand;
if (!pCmd || !pCmd->Init(NULL, "AT+CPBS?\r", NULL, CMDOPT_SIMPBINIT | CMDOPT_IGNORERSP, EXECTIME_API_DEFAULT, g_TimeoutCmdInit, NULL, NULL, 0, 0, 0, APIID_NONE, NULL, NULL))
{
DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : SIMPBReadyThread : Unable to construct or Init CCommand\r\n")));
goto Error;
}
// Place the command into the command queue
// (this may block if the queue is full)
if (!g_pCmdQ->Put(pCmd, INFINITE))
{
goto Error;
}
// Now, block until we get a response back
WaitForSingleObject(m_hInitedForSIMPBEvent, g_TimeoutCmdInit);
}
if (!m_fInitedForSIMPB && !m_fQuitReadyStateThread)
{
Sleep(10000); //retry every 10s
}
}
while (!m_fInitedForSIMPB && !m_fQuitReadyStateThread);
if (m_fQuitReadyStateThread)
{
goto Error;
}
SendReadyStateNotification(RIL_READYSTATE_SIM_PB);
}
/* these could take a while to execute */
/* so do these last in this function */
if (!g_rppPDDParams->fExplicitRadioReadyNotification) {
/* read PLMN Name from CPHS or EF-PNN*/
StartPlmnNameRead(); /* read CPHS */
#ifdef RIL_ENABLE_EONS
/* read EONS */
StartEONSRead();
#endif
}
Error:
if (m_hSimReadyEvent)
{
CloseHandle(m_hSimReadyEvent);
m_hSimReadyEvent = NULL;
}
if (m_hInitedForSMSEvent)
{
CloseHandle(m_hInitedForSMSEvent);
m_hInitedForSMSEvent = NULL;
}
if (m_hInitedForSIMPBEvent)
{
CloseHandle(m_hInitedForSIMPBEvent);
m_hInitedForSIMPBEvent = NULL;
}
return 0;
}
//
// Launch a thread to see if the SIM is ready or not
//
void CRilHandle::StartReadyStateQuery()
{
m_fQuitReadyStateThread = FALSE;
HANDLE hThread = CreateThread(NULL, 0, SimReadyThreadProc, (LPVOID)this, 0, NULL);
if (NULL != hThread)
CloseHandle(hThread); // close handle we don't need
}
void CRilHandle::StopReadyStateQuery()
{
m_fQuitReadyStateThread = TRUE;
if (m_hSimReadyEvent)
{
SetEvent(m_hSimReadyEvent);
}
if (m_hInitedForSMSEvent)
{
SetEvent(m_hInitedForSMSEvent);
}
if (m_hInitedForSIMPBEvent)
{
SetEvent(m_hInitedForSIMPBEvent);
}
}
//
// Start initialization
//
BOOL CRilHandle::StartInit()
{
// // FUNCTION_TRACE(CRilHandle::StartInit);
SYNCBLOCK(m_cs);
DWORD dwTemp;
BOOL fRet = FALSE;
if (m_fInited)
{
fRet = TRUE;
goto Error;
}
// Read parameters from the registry
if (GetRegistryDWORD(HKEY_LOCAL_MACHINE, g_tszRegKeyRIL, TEXT("DataModeCmdDelay"), &dwTemp))
{
m_dwDataModeCmdDelay = dwTemp;
}
if (GetRegistryDWORD(HKEY_LOCAL_MACHINE, g_tszRegKeyRIL, TEXT("MaxDataModeTimeWithoutCmd"), &dwTemp))
{
m_dwMaxDataModeTimeWithoutCmd = dwTemp;
}
if (GetRegistryDWORD(HKEY_LOCAL_MACHINE, g_tszRegKeyRIL, TEXT("LastCLIP"), &dwTemp))
{
g_dwLastCLIP = dwTemp;
DEBUGMSG(ZONE_TRACE, (TEXT("RILDrv : t : CRilHandle::StartInit : Retrieved LastCLIP=0x%x\r\n"),g_dwLastCLIP));
}
if (GetRegistryDWORD(HKEY_LOCAL_MACHINE, g_tszRegKeyRIL, TEXT("LastCLIR"), &dwTemp))
{
g_dwLastCLIR = dwTemp;
DEBUGMSG(ZONE_TRACE, (TEXT("RILDrv : t : CRilHandle::StartInit : Retrieved LastCLIR=0x%x\r\n"),g_dwLastCLIR));
}
g_TimeoutCmdInit = TIMEOUT_CMD_INIT;
if (GetRegistryDWORD(HKEY_LOCAL_MACHINE, g_tszRegKeyRIL, TEXT("TimeoutCmdInit"), &dwTemp))
{
g_TimeoutCmdInit = dwTemp;
}
g_TimeoutCmdNoOp = TIMEOUT_CMD_NOOP;
if (GetRegistryDWORD(HKEY_LOCAL_MACHINE, g_tszRegKeyRIL, TEXT("TimeoutCmdNoOp"), &dwTemp))
{
g_TimeoutCmdNoOp = dwTemp;
}
g_TimeoutCmdOnline = TIMEOUT_CMD_ONLINE;
if (GetRegistryDWORD(HKEY_LOCAL_MACHINE, g_tszRegKeyRIL, TEXT("TimeoutCmdOnline"), &dwTemp))
{
g_TimeoutCmdOnline = dwTemp;
}
g_TimeoutAPIDefault = TIMEOUT_API_DEFAULT;
if (GetRegistryDWORD(HKEY_LOCAL_MACHINE, g_tszRegKeyRIL, TEXT("TimeoutAPIDefault"), &dwTemp))
{
g_TimeoutAPIDefault = dwTemp;
}
g_TimeoutDTRDrop = TIMEOUT_DTRDROP;
if (GetRegistryDWORD(HKEY_LOCAL_MACHINE, g_tszRegKeyRIL, TEXT("TimeoutDTRDrop"), &dwTemp))
{
g_TimeoutDTRDrop = dwTemp;
}
g_TimeoutWaitForInit = TIMEOUT_WAITFORINIT;
if (GetRegistryDWORD(HKEY_LOCAL_MACHINE, g_tszRegKeyRIL, TEXT("TimeoutWaitForInit"), &dwTemp))
{
g_TimeoutWaitForInit = dwTemp;
}
// Create init event
m_hInitEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (!m_hInitEvent)
{
goto Error;
}
// Create data event
m_hDataEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if (!m_hDataEvent)
{
goto Error;
}
// Create the instance handle list
m_pInstances = new CDblList<CRilInstanceHandle>;
if (!m_pInstances)
{
goto Error;
}
// Open the serial port
m_pComDevice = COM_OpenInternal();
if (!m_pComDevice)
{
DEBUGMSG(ZONE_TRACE, (TEXT("RILDrv : t : CRilHandle::StartInit : Couldn't open VSP\r\n")));
goto Error;
}
DEBUGMSG(ZONE_TRACE, (TEXT("RILDrv : t : CRilHandle::StartInit : VSP is opened successfully\r\n")));
// Initialize the serial port
if (!m_pComDevice->InitComPortForRIL(NULL, NULL))
{
goto Error;
}
// Launch the auxiliary threads
if (!LaunchThreads())
{
goto Error;
}
#if defined(NO_INIT_ON_BOOT)
GeneralInitDone(TRUE);
#else
// Send the first init string to the COM port
if (!SendComInitString(COM_INIT_INDEX))
{
goto Error;
}
#ifdef RIL_WATSON_REPORT
// Query for the equipment info so it is available in case of watson logging.
QueueCmdIgnoreRsp(APIID_NONE, "AT+CGMI;+CGMM;+CGMR;+CGSN\r", CMDOPT_IGNORERADIOOFF, g_TimeoutCmdInit, ParseGetEquipmentInfo, NULL, 0, 0, 0);
#endif // RIL_WATSON_REPORT
#endif
fRet = TRUE;
Error:
if (!fRet)
{
if (m_pComDevice)
{
COM_CloseInternal(m_pComDevice);
m_pComDevice = NULL;
}
if (m_hInitEvent)
{
(void)CloseHandle(m_hInitEvent);
m_hInitEvent = NULL;
}
if (m_hDataEvent)
{
(void)CloseHandle(m_hDataEvent);
m_hDataEvent = NULL;
}
}
return fRet;
}
void CRilHandle::GeneralInitDone(BOOL bSucceeded)
{
if (m_fInited)
{
DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : CRilHandle::FinishInit : Trying to reinit? Module reset itself?!, rebooting via CPM\r\n")));
}
if (bSucceeded)
{
m_fInited = TRUE;
}
else
{
DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : CRilHandle::FinishInit : Module failed initialization!\r\n")));
m_fFailedInit = TRUE;
}
(void)SetEvent(m_hInitEvent);
// Now we need to send a notification that we've intiailized properly
SendReadyStateNotification(RIL_READYSTATE_INITIALIZED);
}
//
// Finish intialization
//
void CRilHandle::FinishInit(CCommand* pInitCmd, BOOL bSucceeded)
{
// FUNCTION_TRACE(CRilHandle::FinishInit);
DEBUGCHK(NULL != pInitCmd);
// One more thing, check if we are CFUN=1 so that we won't send it down again unnecesarily.
QueueCmdIgnoreRsp(APIID_NONE, "AT+CFUN?\r", CMDOPT_IGNORERADIOOFF, g_TimeoutCmdInit, ParseGetEquipmentState, NULL, 0, 0, 0);
if (pInitCmd->FGeneralInit())
{
GeneralInitDone(bSucceeded);
}
if (pInitCmd->FSMSInit())
{
if (m_fInitedForSMS)
{
DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : CRilHandle::FinishInit : Trying to reinit SMS? Module reset itself?!, rebooting via CPM\r\n")));
}
if (bSucceeded)
{
m_fInitedForSMS = TRUE;
}
}
}
//
// Function passed to CQueue::Enum() below
//
BOOL GenerateCancelledRsp(void* pItem, DWORD dwData)
{
FUNCTION_TRACE(GenerateCancelledRsp);
DEBUGCHK(pItem != NULL);
DEBUGCHK(dwData != NULL);
CCommand* pCmd = (CCommand*)pItem;
HRESULT dwError = RIL_E_CANCELLED;
// Send out cancelled response as a notification
pCmd->SendResponse(RIL_RESULT_ERROR, &dwError, sizeof(HRESULT));
// Continue enumeration
return FALSE;
}
//
//
//
void CRilHandle::PrepareForReinit()
{
// FUNCTION_TRACE(CRilHandle::PrepareForReinit);
(void)ResetEvent(m_hInitEvent);
m_fInited = FALSE;
m_fFailedInit = FALSE;
m_fInitedForSMS = FALSE;
m_fInitedForSIMPB = FALSE;
m_dwSIMPBLastSize = (DWORD)-1;
// Reset g_dwReadyState
SendReadyStateNotification(RIL_READYSTATE_NONE);
// Clear the command queue, sending out "cancelled" responses to response callbacks
// NOTE: The following line has been commented out to prevent commands
// from being cancelled on start up when the shell turns the radio on.
//g_pCmdQ->Enum(GenerateCancelledRsp, (DWORD)this, TRUE);
}
//
// Launch auxiliary threads
//
BOOL CRilHandle::LaunchThreads()
{
// FUNCTION_TRACE(CRilHandle::LaunchThreads);
BOOL fRet = FALSE;
DWORD NumThreads = 2;
if ( m_pCRilNdis )
{
NumThreads++;
}
// Create a cancel event
m_hCancelEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (!m_hCancelEvent)
{
goto Error;
}
// Create command and response queues
g_pCmdQ = new CPriorityQueue<CCommand, 40>;
if (!g_pCmdQ || !g_pCmdQ->Init(m_hCancelEvent))
{
goto Error;
}
g_pRspQ = new CQueue<CResponse, 10>;
if (!g_pRspQ || !g_pRspQ->Init(m_hCancelEvent))
{
goto Error;
}
g_pSimLockedQueue = new CQueue<CCommand, 10>;
if (!g_pSimLockedQueue || !g_pSimLockedQueue->Init(m_hCancelEvent))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -