📄 rilhand.cpp
字号:
}
else
{
g_dwReadyState = 0;
}
// Broadcast the notification
memset(&res, 0x00, sizeof(RILEQUIPMENTSTATE));
res.cbSize = sizeof(RILEQUIPMENTSTATE);
res.dwParams = RIL_PARAM_EQUIPMENTSTATE_READYSTATE;
res.dwReadyState = g_dwReadyState;
pnd = new CNotificationData;
if (pnd && pnd->InitFromRealBlob(RIL_NOTIFY_RADIOEQUIPMENTSTATECHANGED, (void *) &res, res.cbSize))
{
// Note that BroadcastNotification frees pnd
BroadcastNotification(pnd);
pnd = NULL;
}
delete pnd;
/* Below was added for TTPCOM to insure that the status indicators were correct
following boot up
*/
#if defined(OEM2_DRIVER)
pnd = new CNotificationData;
if (pnd && pnd->InitFromRealBlob(RIL_NOTIFY_REGSTATUSCHANGED, (void *) &g_dwRegStatus, sizeof(g_dwRegStatus)))
{
// Note that BroadcastNotification frees pnd
BroadcastNotification(pnd);
pnd = NULL;
}
delete pnd;
#endif
}
//
// Thread responsible for sending commands from the Command Queue to COM port
//
DWORD WINAPI SimReadyThreadProc(LPVOID lpParameter)
{
FUNCTION_TRACE(SimReadyThreadProc);
DEBUGCHK(lpParameter != NULL);
CRilHandle* pRilDevice = (CRilHandle*)lpParameter;
DEBUGMSG(ZONE_TRACE, (TEXT("RILDrv : t : SimReadyThreadProc : Entering, pRilDevice=0x%x\r\n"),pRilDevice));
const DWORD dwReturn = pRilDevice->SimReadyThread();
DEBUGMSG(ZONE_TRACE, (TEXT("RILDrv : t : SimReadyThreadProc : THREAD IS EXITING, dwReturn=0x%x\r\n"),dwReturn));
return dwReturn;
}
//
// Loop until RIL is ready to process SIM commands
//
DWORD CRilHandle::SimReadyThread()
{
CCommand *pCmd = NULL;
APIINFO apiiInfo;
const APIID apiid = APIID_GETPHONELOCKEDSTATE;
// Create an event
m_fSimReady = FALSE;
m_hSimReadyEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if (!m_hSimReadyEvent)
{
goto Error;
}
// Get the info about this API
memset(&apiiInfo,0,sizeof(apiiInfo));
GetAPIInfo(apiid, apiiInfo);
// Query for the PIN until we don't get back 515 as an error
do
{
DEBUGMSG(ZONE_TRACE, (TEXT("RILDrv : t : SimReadyThread : Sending SIM Query Command...\r\n")));
// Set up a CPIN command to be sent
// Note that we don't care what the return value is, so long as it's not that the radio isn't ready
pCmd = new CCommand;
//Alan Luo : try to fix sim card bug
#if defined(WAVECOM_DRIVER) || defined(PHILIP_DRIVER)
if (!pCmd || !pCmd->Init(NULL, "AT+CPIN?\r", NULL, CMDOPT_SIMQUERY, apiiInfo.dwExecTime, apiiInfo.dwTimeout, NULL, NULL, 0, 0, 0, apiid, NULL, NULL))
#else
if (!pCmd || !pCmd->Init(NULL, "AT+CPIN?\r", NULL, CMDOPT_SIMQUERY, apiiInfo.dwExecTime, apiiInfo.dwTimeout, NULL, ParseGetPhoneLockedState, 0, 0, 0, apiid, NULL, NULL))
#endif
{
DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : SimReadyThread : Unable to construct or Init CCommand\r\n")));
goto SimReadyPhase2;
}
// Place the command into the command queue
// (this may block if the queue is full)
if (!g_pCmdQ->Put(pCmd, INFINITE))
{
goto SimReadyPhase2;
}
// Now, block until we get a response back
WaitForSingleObject(m_hSimReadyEvent, apiiInfo.dwTimeout);
// Sleep a bit before the next try
if (!m_fSimReady && !m_fQuitReadyStateThread)
{
Sleep(2000);
}
}
while (!m_fSimReady && !m_fQuitReadyStateThread);
if (m_fQuitReadyStateThread)
{
goto Error;
}
SimReadyPhase2:
if (!m_pSimToolkitHandling->Init(this))
{
//TBD_OUTPUT(TBDCT_INFO, TBDOL_ERROR, (TEXT("SIMUnlockThread : Unable to initialize SIM-Toolkit handling")));
}
#if defined(OEM2_DRIVER) || defined (EMP_DRIVER) || defined(PHILIP_DRIVER)
NKDbgPrintfW(_T("SimReadyPhase2\r\n"));
// Create the needed event
m_fInitedForSMS = FALSE;
m_hInitedForSMSEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if (!m_hInitedForSMSEvent)
{
goto Error;
}
// for OEM2 platforms the measure of SMS readiness is a successful CNMI initialization
do
{
Sleep(10000); //retry every 10s
if (g_dwReadyState & RIL_READYSTATE_UNLOCKED)
{
DEBUGMSG(ZONE_TRACE, (TEXT("RILDrv : t : SMSReadyThread : OEM2 Sending CNMI Init Command...\r\n")));
pCmd = new CCommand;
#ifdef RIL_CELL_BROADCAST
#if defined(PHILIP_DRIVER)
if (!pCmd || !pCmd->Init(NULL, "AT+CNMI=2,4,2,1,0\r", NULL, CMDOPT_SMSINIT | CMDOPT_IGNORERSP, EXECTIME_API_DEFAULT, g_TimeoutCmdInit, NULL, NULL, 0, 0, 0, APIID_NONE, NULL, NULL))
#else
if (!pCmd || !pCmd->Init(NULL, "AT+CNMI=2,2,2,1,0\r", NULL, CMDOPT_SMSINIT | CMDOPT_IGNORERSP, EXECTIME_API_DEFAULT, g_TimeoutCmdInit, NULL, NULL, 0, 0, 0, APIID_NONE, NULL, NULL))
#endif
#else
if (!pCmd || !pCmd->Init(NULL, "AT+CNMI=2,2,0,1,0\r", NULL, CMDOPT_SMSINIT | CMDOPT_IGNORERSP, EXECTIME_API_DEFAULT, g_TimeoutCmdInit, NULL, NULL, 0, 0, 0, APIID_NONE, NULL, NULL))
#endif
{
DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : SMSReadyThread : Unable to construct or Init CCommand\r\n")));
goto SimReadyPhase3;
}
// Place the command into the command queue
// (this may block if the queue is full)
if (!g_pCmdQ->Put(pCmd, INFINITE))
{
goto SimReadyPhase3;
}
// Now, block until we get a response back
WaitForSingleObject(m_hInitedForSMSEvent, g_TimeoutCmdInit);
}
}
while (!m_fInitedForSMS && !m_fQuitReadyStateThread);
if (m_fQuitReadyStateThread)
{
goto Error;
}
SendReadyStateNotification(RIL_READYSTATE_SMS);
SimReadyPhase3:
//Alan Luo: try to fix sim card ready bug
NKDbgPrintfW(_T("SimReadyPhase3\r\n"));
#if defined(OEM2_SIMTOOLKIT)
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;
}
}
#endif
// Create the needed event
m_fInitedForSIMPB = FALSE;
m_dwSIMPBLastSize = (DWORD)-1;
m_hInitedForSIMPBEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if (!m_hInitedForSIMPBEvent)
{
goto Error;
}
// This now only applies to OEM2 with new CSTAT command from OEM1
//now perform SIM phonebook ready check for OEM2 driver
//OEM2 driver does 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 : OEM2 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 : OEM2 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);
//GetSimToolkit()->ParseNotification(szPointer);
this->GetSimToolkit()->QueueSimToolkitCmd(37);
#endif
/* these could take a while to execute */
/* so do these last in this function */
#if defined(OEM2_DRIVER) || defined(EMP_DRIVER)
/* read PLMN Name from CPHS or EF-PNN*/
StartPlmnNameRead();
#ifdef RIL_ENABLE_EONS
/* read EONS */
StartEONSRead();
#endif
#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;
NKDbgPrintfW(TEXT("RILDrv : t : CRilHandle::StartInit\r\n"));
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")));
NKDbgPrintfW(TEXT("RILDrv : t : CRilHandle::StartInit : Couldn't open VSP\r\n"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -