📄 rilhand.cpp
字号:
// locked or not. Why not?
DWORD dwReadyState = RIL_READYSTATE_SIM;
void *pBlobSim = NULL;
UINT cbBlobSim = 0;
if (RIL_RESULT_OK == rpRsp->GetNotifyCode())
{
rpRsp->GetBlob(pBlobSim, cbBlobSim);
DEBUGCHK(cbBlobSim == sizeof(DWORD));
if ((*(DWORD *) pBlobSim) == RIL_LOCKEDSTATE_READY)
{
DEBUGMSG(ZONE_INFO, (TEXT("RILDrv : i : The phone was unlocked from boot\r\n")));
dwReadyState |= RIL_READYSTATE_UNLOCKED;
}
}
SendReadyStateNotification(dwReadyState);
}
// Wake up the waiting thread
SetEvent(m_hSimReadyEvent);
fRet = TRUE;
goto Error;
}
if (g_rppPDDParams->fRequireWaitingForSMSReady) {
if (rpCmd->FSMSInit())
{
if (RIL_RESULT_OK == rpRsp->GetNotifyCode())
{
m_fInitedForSMS = TRUE;
}
SetEvent(m_hInitedForSMSEvent);
fRet = TRUE;
goto Error;
}
}
if (g_rppPDDParams->fRequireWaitingForSIMPhoneBookReady) {
if (rpCmd->FSIMPBInit())
{
if (RIL_RESULT_OK == rpRsp->GetNotifyCode())
{
if (SUCCEEDED(ParseGetPhonebookOptions(rpRsp->GetData(), pBlob, cbBlob)))
{
RILPHONEBOOKINFO* prpbi = (RILPHONEBOOKINFO*)pBlob;
if ((sizeof(RILPHONEBOOKINFO) == cbBlob) &&
prpbi &&
(sizeof(RILPHONEBOOKINFO) == prpbi->cbSize))
{
DEBUGCHK((RIL_PARAM_PBI_USED & prpbi->dwParams) != 0);
DEBUGCHK((RIL_PARAM_PBI_STORELOCATION & prpbi->dwParams) != 0);
DEBUGCHK(RIL_PBLOC_SIMPHONEBOOK == prpbi->dwStoreLocation);
if (m_dwSIMPBLastSize == prpbi->dwUsed)
{
m_fInitedForSIMPB = TRUE;
}
m_dwSIMPBLastSize = prpbi->dwUsed;
}
FreeBlob(pBlob);
}
}
SetEvent(m_hInitedForSIMPBEvent);
fRet = TRUE;
goto Error;
}
}
// If we got a CONNECT response, it must be a response to successful ATD or ATA -- change it to OK
if (RIL_NOTIFY_CONNECT == rpRsp->GetNotifyCode())
{
rpRsp->ConnectToOK();
// Some networks seem to require a brief delay after a data connection is made
// before data can be sent via the connection. We pause here before sending the
// connect response to the client. The delay is configured using a registry value.
// If the value is not present, then there is no delay.
DWORD dwTemp = 0;
if (rpCmd->CmdOptIsSet(CMDOPT_DELAYCONNECTRSP) &&
GetRegistryDWORD(HKEY_LOCAL_MACHINE, g_tszRegKeyRIL, TEXT("ConnectResponseDelay"), &dwTemp))
{
Sleep(dwTemp);
}
}
else
{
// For non-CONNECT responses, if we have a notification to send upon success, do it now
pnd = rpCmd->GiveUpNotificationData();
if (pnd)
{
if (RIL_RESULT_OK == rpRsp->GetNotifyCode() &&
(!pnd->FDelayedInitFromRsp() || pnd->FinishInitFromRspBlob(*rpRsp)))
{
BroadcastNotification(pnd);
DEBUGCHK(NULL == pnd);
}
else
{
delete pnd;
pnd = NULL;
}
}
}
// If we got an RIL_E_SIMNOTINSERTED or RIL_E_SIMFAILURE error, send out a "SIM isn't accessible" notification
hrError = rpRsp->GetError();
if (RIL_E_SIMNOTINSERTED == hrError || RIL_E_SIMFAILURE == hrError)
{
(void)BroadcastRealBlobNotification(RIL_NOTIFY_SIMNOTACCESSIBLE, NULL, 0);
}
if (RILERRORCLASS(hrError) == RIL_ERRORCLASS_SIM)
{
UpdateSIMState((DWORD)hrError);
}
// Forward the response we got to the handle that sent the command
rpRsp->GetBlob(pBlob, cbBlob);
// If we just queried the equipment state, then make
// sure the global on/off state is set appropriately.
if (APIID_GETEQUIPMENTSTATE == rpCmd->GetAPIID() &&
RIL_RESULT_OK == rpRsp->GetNotifyCode())
{
RILEQUIPMENTSTATE * pres;
if (NULL != pBlob)
{
ASSERT(sizeof(RILEQUIPMENTSTATE) == cbBlob);
// Take a peek at the response data
pres = (RILEQUIPMENTSTATE *)pBlob;
if (RIL_RADIOSUPPORT_OFF == pres->dwRadioSupport)
{
rfRadioOff = TRUE;
}
else if (RIL_RADIOSUPPORT_ON == pres->dwRadioSupport)
rfRadioOff = FALSE;
}
}
rpCmd->SendResponse(rpRsp->GetNotifyCode(), pBlob, cbBlob);
rpRsp->DeleteBlob();
pBlob = NULL;
cbBlob = 0;
fRet = TRUE;
Error:
delete pnd;
delete rpCmd;
delete rpRsp;
rpCmd = NULL;
rpRsp = NULL;
return fRet;
}
//
//
//
BOOL CRilHandle::AppendReadBytes(LPCSTR szBytes, UINT cbBytes, bool fUseBuffer2)
{
// FUNCTION_TRACE(CRilHandle::AppendReadBytes);
BOOL fRet = FALSE;
CBuffer **ppReadBytes = &m_pReadBytes;
if (fUseBuffer2)
{
ppReadBytes = &m_pReadBytes2;
}
if (!*ppReadBytes)
{
// No buffer yet -- need to allocate it
*ppReadBytes = new CBuffer;
if (!*ppReadBytes)
{
goto Error;
}
}
fRet = (*ppReadBytes)->Append(szBytes, cbBytes);
Error:
if (!fRet)
{
// Critically low on memory
SignalCriticalError(RILLOG_EVENT_LOWMEMORY, __LINE__, __FILE__);
}
return fRet;
}
//
//
//
BOOL CRilHandle::InheritReadBytes(CResponse* const pRsp, bool fUseBuffer2)
{
// FUNCTION_TRACE(CRilHandle::InheritReadBytes);
BOOL fRet = FALSE;
CBuffer **ppReadBytes = &m_pReadBytes;
if (fUseBuffer2)
{
ppReadBytes = &m_pReadBytes2;
}
if (!*ppReadBytes)
{
// No buffer yet -- need to allocate it
*ppReadBytes = new CBuffer;
if (!*ppReadBytes)
{
goto Error;
}
}
(*ppReadBytes)->InheritData(pRsp);
fRet = TRUE;
Error:
return fRet;
}
//
//
//
BOOL CRilHandle::GiveUpReadBytes(LPSTR& rszBytes, UINT& rcbBytes, bool fUseBuffer2)
{
// FUNCTION_TRACE(CRilHandle::GiveUpReadBytes);
BOOL fRet = FALSE;
CBuffer **ppReadBytes = &m_pReadBytes;
if (fUseBuffer2)
{
ppReadBytes = &m_pReadBytes2;
}
if (!*ppReadBytes)
{
// No buffer yet, i.e. no bytes to return
goto Error;
}
rcbBytes = (*ppReadBytes)->GetLength();
rszBytes = (*ppReadBytes)->GiveUpData();
fRet = TRUE;
Error:
return fRet;
}
//
//
//
BOOL CRilHandle::SetEmergencyMode(const BOOL fMode)
{
// FUNCTION_TRACE(CRilHandle::SetEmergencyMode);
SYNCBLOCK(m_csEmergency);
DWORD dwNotificationCode;
BOOL fRet = FALSE;
if (m_fEmergencyMode && fMode)
{
// If we're trying to enter the emergency mode while already in emergency mode, fail
goto Error;
}
DEBUGCHK(FALSE == m_fEmergencyMode || FALSE == fMode);
DEBUGCHK(FALSE != m_fEmergencyMode || FALSE != fMode);
// Set the new mode
m_fEmergencyMode = fMode;
if (m_fEmergencyMode)
{
// We just entered emergency mode
DEBUGMSG(ZONE_INFO, (TEXT("RILDrv : i : CRilHandle::SetEmergencyMode : Entering emergency mode\r\n")));
// Clear the command queue, sending out "cancelled" responses to response callbacks
g_pCmdQ->Enum(GenerateCancelledRsp, (DWORD)this, TRUE);
dwNotificationCode = RIL_NOTIFY_EMERGENCYMODEENTERED;
}
else
{
// We just exited emergency mode
DEBUGMSG(ZONE_INFO, (TEXT("RILDrv : i : CRilHandle::SetEmergencyMode : Exiting emergency mode\r\n")));
dwNotificationCode = RIL_NOTIFY_EMERGENCYMODEEXITED;
}
// Send out an appropriate notification
(void)BroadcastRealBlobNotification(dwNotificationCode, NULL, 0);
fRet = TRUE;
Error:
return fRet;
}
#ifndef RIL_RADIO_RESILIENCE
//
//
//
BOOL CRilHandle::RegisterWithCPM()
{
// FUNCTION_TRACE(CRilHandle::RegisterWithCPM);
BOOL fRet = FALSE;
m_pMonitor = new CMonitor;
if (!m_pMonitor || !m_pMonitor->Init(m_hCancelEvent, m_dwCmdThreadID, m_dwReadThreadID))
{
goto Error;
}
fRet = TRUE;
Error:
if (!fRet)
{
delete m_pMonitor;
m_pMonitor = NULL;
}
return fRet;
}
#endif // RIL_RADIO_RESILIENCE
//
//
//
void CRilHandle::GetAPIInfo(APIID apiid, APIINFO& rapii)
{
// FUNCTION_TRACE(CRilHandle::GetAPIInfo);
TCHAR tszRegKey[MAX_PATH];
APIINFO* pNewAPIInfo = NULL;
// Intialize the output struct with defaults
rapii.dwExecTime = EXECTIME_API_DEFAULT;
rapii.dwTimeout = g_TimeoutAPIDefault;
// See if already loaded info for this API
if (!m_rgpAPIInfo[apiid])
{
// Allocate new API info
pNewAPIInfo = new APIINFO;
if (!pNewAPIInfo)
{
goto Error;
}
// Compose the registry key
StringCbPrintf( tszRegKey, sizeof(tszRegKey), _T("%s%d"), g_tszRegKeyAPIInfo, apiid );
// Read the execution time and the timeout
if (!GetRegistryDWORD(HKEY_LOCAL_MACHINE, tszRegKey, TEXT("ExecutionTime"), &pNewAPIInfo->dwExecTime))
{
// Just use the default
pNewAPIInfo->dwExecTime = EXECTIME_API_DEFAULT;
}
if (!GetRegistryDWORD(HKEY_LOCAL_MACHINE, tszRegKey, TEXT("Timeout"), &pNewAPIInfo->dwTimeout))
{
// Just use the default
pNewAPIInfo->dwTimeout = g_TimeoutAPIDefault;
}
// If the timeout is specified as 0 milliseconds, assume INFINITE timeout
if (!pNewAPIInfo->dwTimeout)
{
pNewAPIInfo->dwTimeout = INFINITE;
}
// Cache the data we just read
m_rgpAPIInfo[apiid] = pNewAPIInfo;
pNewAPIInfo = NULL;
}
DEBUGCHK(NULL != m_rgpAPIInfo[apiid]);
rapii = *m_rgpAPIInfo[apiid];
Error:
delete pNewAPIInfo;
DEBUGMSG(ZONE_TRACE, (TEXT("RILDrv : t : CRilHandle::GetAPIInfo : Info for API %d: exec time: %d msec, timeout: %d msec\r\n"),
apiid, rapii.dwExecTime, rapii.dwTimeout));
}
//
//
//
void CRilHandle::LogATCommand( LPCSTR szChars, UINT cbToWrite, BOOL fResponse )
{
char szPrint[MAXLENGTH_CMD];
const char szCR[] = "<cr>";
const char szLF[] = "<lf>";
const char szSuppressed[] = ATCMD_LOG_SUPPRESSED_TEXT;
UINT iPrint = 0;
UINT iChars = 0;
BOOL fSuppressedCmd = false;
#ifdef RIL_WATSON_REPORT
char szATLog[MAXLENGTH_CMD];
const char szFileEOL[] = "\r\n";
INT nLogChars = 0;
SYSTEMTIME st;
DWORD cbSize;
#endif // RIL_WATSON_REPORT
#ifdef RIL_WATSON_REPORT
// Always process with Watson reporting
#else
// We need the application handle to process
if ( !m_hATCommandLogOwner)
return;
#endif // RIL_WATSON_REPORT
// Check to see if logging is suppressed for this command.
if ( m_pCurrCommand && m_pCurrCommand->CmdOptIsSet(CMDOPT_SUPPRESSLOGGING))
{
fSuppressedCmd = true;
}
#ifndef RIL_WATSON_REPORT
// add tick count
iPrint = _snprintf(szPrint, sizeof(szPrint), "[%u] -> ", GetTickCount());
if (iPrint < 0)
// error case => reset print char index to 0
iPrint = 0 ;
#endif // !RIL_WATSON_REPORT
// convert \r, \n to visible chars.
while (iChars < cbToWrite && iPrint < (sizeof(szPrint) - sizeof(szLF)))
{
if (fSuppressedCmd && fResponse)
{
// Do not log suppressed responses. Only log a
// message that a suppressed response was received.
StringCchCopyA( szPrint + iPrint, MAXLENGTH_CMD - iPrint, szSuppressed );
iPrint += sizeof(szSuppressed) - 1;
if(iPrint >= MAXLENGTH_CMD - 1)
{
iPrint = MAXLENGTH_CMD - 1;
}
break;
}
else if (fSuppressedCmd && szChars[iChars] == '=')
{
// For private commands, we still want to see what command went out,
// but want to avoid sending the private data. To accomplish this,
// the private variables are snipped off by breaking here and letting
// a null character be appended in place of the equal sign (null is
// placed after the while loop).
// i.e. AT+CPIN="1234" becomes AT+CPIN
break;
}
else if (szChars[iChars] == '\r')
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -