📄 rilhand.cpp
字号:
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Copyright (c) 1995-1999 Microsoft Corporation
Module Name:
rilhand.cpp
Abstract:
Notes:
--*/
#include "precomp.h"
#include "simmgr.h"
HRESULT ParseGetPhoneLockedState(LPCSTR szRsp, void*& pBlob, UINT& cbBlob);
#ifdef RIL_WATSON_REPORT
HRESULT ParseGetEquipmentInfo(LPCSTR szRsp, void*& pBlob, UINT& cbBlob);
#endif // RIL_WATSON_REPORT
HRESULT ParseGetPhonebookOptions(LPCSTR szRsp, void*& pBlob, UINT& cbBlob);
// RIL registry key
#ifdef OEM1_DRIVER
const LPCTSTR g_tszRegKeyRIL = TEXT("Drivers\\BuiltIn\\RIL");
#else
const LPCTSTR g_tszRegKeyRIL = TEXT("Software\\Microsoft\\RIL");
#endif
// RIL API info registry key
const LPCTSTR g_tszRegKeyAPIInfo = TEXT("Software\\Microsoft\\RIL\\APIInfo\\");
// RIL opertor names registry key
const LPCTSTR g_tszRegKeyOperNames = TEXT("Software\\Microsoft\\RIL\\OperatorNames");
// RIL Remote Calltype Determination registry key
const LPCTSTR g_tszRegKeyRemoteCalltype = TEXT("Comm\\Cellular\\RIL\\RemoteCalltype");
const HRESULT INITIAL_COMMAND_ID = 1;
DWORD g_TimeoutCmdInit;
DWORD g_TimeoutCmdNoOp;
DWORD g_TimeoutCmdOnline;
DWORD g_TimeoutAPIDefault;
DWORD g_TimeoutDTRDrop;
DWORD g_TimeoutWaitForInit;
DWORD g_dwLastCLIP = 1;
DWORD g_dwLastCLIR = 0;
// It's safe to put these params in globals since the SIM PW prompt thread is only launched from the command thread,
// and no more than one SIM PW prompt thread at a time is launched.
BOOL g_PromptingForSim=FALSE;
DWORD g_dwLockFacility;
CQueue<CCommand, 10>* g_pSimLockedQueue;
#ifdef PHILIP_DRIVER
//Alan Luo: for sms incoming (sim card)(CNMI)
#define RIL_CELL_BROADCAST
#endif
// HW-SPECIFIC: The following init commands are hardware-specific
// NOTES: Z resets the AT interface
// +CPIN? initializes the SIM (OEM1 only)
// S0=0 disables auto-answer
// E0 disables command echo
// Q0 enable result codes
// V0 enable non-verbose responses
// X3 enable busy signal detection and additional info in CONNECT response (OEM1 only)
// X4 enable busy signal detection and additional info in CONNECT response
// &C1 enables DCD to be used for carrier detection
// &D1 enables DTR to be used for dropping out of data mode
// &S1 enables DSR off ==> cmd mode, DSR on ==> data mode (WaveCom only)
// %C0 disables dat compression (WaveCom series 2 only)
// +WIND=8 enables +WIND notifications (WaveCom only)
// +CMEE=1 enables +CME ERROR and +CMS ERROR responses
// +CFUN=0,2 ensures radio is off and radio will not power on at module power on (OEM2 only)
// +CRC=1 enables +CRING notifications
// +CR=1 enables +CR notifications
// +CMOD=0 enables single call mode
// +CREG=1 enables short +CREG notifications
// +CREG=2 enables extended +CREG notifications (w/ <lac> and <ci>) (OEM1 and WAVECOM only)
// +FCLASS=0 enables data mode
// +CSSN=0,1 enables +CSSU notifications
// +CHSR=1 enables +CHSR notifications
// +COLP=1 enables +COLP notifications
// +CCWA=1 enables +CCWA notifications
// %SATC=1 enables %SATI, %SATN, and %SATA notifications (OEM1 only)
// +CMGF=0 enables SMS PDU mode
// +CNMI=2,2,2,1,0 enables +CMT, +CBM, and +CDS notifications
// +CSCS="8859-1" sets default alphabet to ISO 8859-1
// +CSCS="PCCP437" sets default alphabet to PC CodePage 437 (WaveCom only)
// +STRT=240",1 (OEM2 only) set the SIM toolkit command timeout in seconds. Currently this is set to match the SIMTK internal timeout
// %CSQ=1 enables signal quality notifications (OEM1)
// +EXUNSOL="SQ",1 enables unsolicited signal quality notifications (0 = disable, 1 = enable, 2 = query) (OEM2 only)
// +EXUNSOL="BC",1 enables unsolicited battery notifications (0 = disable, 1 = enable, 2 = query) (OEM2 only)
// +EXUNSOL="UR",1 enables unsolicited call progress notifications (0 = disable, 1 = enable, 2 = query) (OEM2 only)
// PHILIP_DRIVER
// By Alan Luo
// For Philips Modem
// +Z0 default config
// +IPR=115200 modem bitrate
// E0 disable the echo
// E1 enable the echo
// +PPURC=0 disable urc notify
// +VTD=0;+VTS="x" modify
const INITSTRING_DATA g_rgisdModuleInit[] =
{
#if defined(WAVECOM_DRIVER)
// WaveCom init commands
{ "ZS0=0E0Q0V0X4&C1&D1&S1", CMDOPT_INIT | CMDOPT_GENERALINIT},
{ "ZS0=0E0Q0V0X4&C1&D1&S1|+WIND=8;+CMEE=1;+CRC=1;+CR=1;+CMOD=0;"
#ifndef RIL_NO_CREG_LOCATION_UPDATES
"+CREG=2|"
#else
"+CREG=1|"
#endif // RIL_NO_CREG_LOCATION_UPDATES
"+FCLASS=0|+CSSN=0,1|+CMUT=0|", CMDOPT_INIT | CMDOPT_GENERALINIT},
{ "+COLP=0;+CCWA=1,2;+CAOC=2;+CMGF=0;+CNMI=2,2,2,1,0;+CSCS=\"GSM\";+CSAS|&W", CMDOPT_INIT | CMDOPT_SMSINIT},
#elif defined(EMP_DRIVER)
// EMP init commands
// Use AT+CMER to enable +CIEV signal strength notification
{ "V0|E0|S0=0|Q0|X3|&C1|&D1|+CMEE=1|+CRC=1|+CR=1|+CMUT=0|+CMER=3,,,1|"
#ifndef RIL_NO_CREG_LOCATION_UPDATES
"*EREG=2|"
#else
"*EREG=1|"
#endif // RIL_NO_CREG_LOCATION_UPDATES
"+CSSN=0,1;+COLP=0;+CCWA=1;+CSCS=\"UTF-8\";+CMGF=0|+CGREG=1|+CUSD=1|+CGEREP=1,0|+CPMS=\"SM\",\"SM\",\"SM\"|*ECAM=1|"
#ifdef RIL_ENABLE_SIMTK
"*STKC=1,\"0901FF7F00000010\"|"
#endif
"", CMDOPT_INIT | CMDOPT_GENERALINIT},
{"V0|E0|+CRC=1|+CMUT=0|", CMDOPT_INIT | CMDOPT_GENERALINIT},
// No AT command is needed for SMS initialization
{ "", CMDOPT_INIT | CMDOPT_SMSINIT},
#elif defined(PHILIP_DRIVER)
// Philips Modem init commands
//E0&D1|+CMEE=1;+CREG=2;S7=50|S0=255|+IPR=115200|+CCWA=1|+CSCS=\"IRA\"|+PPURC=1919;+PPSURC=4095999,425919"
//"+CREG=2;+CGREG=2;+COLP=1;+CSSN=1,1;+CNMI=2,1,2,1,0;+CRC=1;+CR=0;+CMER=1,0,0,0,0;"
{ "E0&D1|+CMEE=1;+CREG=2;S7=50|S0=255|+PPSTAC=1", CMDOPT_INIT | CMDOPT_GENERALINIT},
{ "+CRC=1;+CR=0;+CSSN=1,1;+CMER=1,0,0,2,0;+CSCS=\"UCS2\";", CMDOPT_INIT | CMDOPT_GENERALINIT},
{ "+CREG=2;+CGREG=2|+PPSIM=1;+PPSTAC=1|+CMGF=0|+PPRI=1|+PPGCW=1|+CCWA=0,0,1|+PPURC=1919;+PPSURC=4095999,425919", CMDOPT_IGNORERSP },//CMDOPT_INIT | CMDOPT_SMSINIT},
#elif defined(OEM1_DRIVER)
// OEM1 init commands
{ "V0|E0|S0=0|Q0|X3|&C1|&D1|%DATA=2,\"UART\",1,,\"SER\",\"UART\",0|+CMEE=1;+CRC=1;+CR=1;+CMOD=0;+CMUT=0|%CGAATT=0,1|%CTZV=1|"
#if defined(OEM1_DRIVER_PKTIO)
"%DATA=2,\"PKTIO\",1,0,\"PKT\",\"UART\",0,0,1|"
"%DATA=2,\"PKTIO\",2,0,\"PKT\",\"UART\",0,0,2|"
"%DATA=2,\"PKTIO\",3,0,\"PKT\",\"UART\",0,0,3|"
#endif
#ifndef RIL_NO_CREG_LOCATION_UPDATES
"+CREG=2;"
#else
"+CREG=1;"
#endif // RIL_NO_CREG_LOCATION_UPDATES
"+CSSN=0,1;+COLP=0;+CCWA=1;+CSCS=\"HEX\";+CMGF=0|+CGREG=1|+CUSD=1|"
#if defined(RIL_ENABLE_SIMTK)
"%SATC=1|"
#endif // defined(RIL_ENABLE_SIMTK)
#if defined(OEM1_CSQ_NOTIFICATION) // catch all of the new OEM1 notifications under this ifdef
"%CSQ=1|%CPI=3|+CGEREP=1,0|%CSTAT=1|"
#endif
#if defined(ENFORA_DRIVER)
#ifdef RIL_CELL_BROADCAST
"+CNMI=2,2,2,1,0|"
#else
"+CNMI=2,2,0,1,0|"
#endif
#endif
"", CMDOPT_INIT | CMDOPT_GENERALINIT}, // OEM1 Init index
{"E0|+CMUT=0|", CMDOPT_INIT | CMDOPT_GENERALINIT},
// {"%DATA=2,\"PKTIO\",1,0,\"PKT\",\"UART\",0,0,1|%DATA=2,\"PKTIO\",2,0,\"PKT\",\"UART\",0,0,2|%DATA=2,\"PKTIO\",3,0,\"PKT\",\"UART\",0,0,3|", CMDOPT_INIT | CMDOPT_GENERALINIT},
#ifdef RIL_CELL_BROADCAST
// OEM1 Re-init index
{ "+CNMI=2,2,2,1,0|", CMDOPT_INIT | CMDOPT_SMSINIT}, // OEM1 SMS-init index
#else
{ "+CNMI=2,2,0,1,0|", CMDOPT_INIT | CMDOPT_SMSINIT}, // OEM1 SMS-init index
#endif
#elif defined(OEM2_DRIVER)
// OEM2 init commands
{ "+CFUN=0,2|Z;S0=0;E0;Q0;V0|X3;&C1;&D1;+CMEE=1;+CRC=1;+CR=1;+CMOD=0;+CREG=1;"
"+FCLASS=0;+CSSN=0,1;+COLP=0;+CCWA=1;+CSCS=\"UCS2\";+CMGF=0|+CGREG=1|+CUSD=1|+CMUT=0|"
#if defined(OEM2_SIMTOOLKIT)
"+STRT=240|+EXUNSOL=\"SQ\",1|+EXUNSOL=\"BC\",1|+EXUNSOL=\"UR\",1|", CMDOPT_INIT | CMDOPT_GENERALINIT},
#else
"+EXUNSOL=\"SQ\",1|+EXUNSOL=\"BC\",1|+EXUNSOL=\"UR\",1|", CMDOPT_INIT | CMDOPT_GENERALINIT},
#endif
{ "E0|+CMUT=0", CMDOPT_INIT | CMDOPT_GENERALINIT},
#else // #elif defined(OEM2_DRIVER)
// Generic init command used by default GSM hardware
{ "ZS0=0E0Q0V0X4&C1&D1;+CMEE=1;+CRC=1;+CR=1;+CMOD=0;+CREG=1;+FCLASS=0;+CSSN=0,1;+CMUT=0;+CHSR=1;+COLP=0;+CCWA=1;+CMGF=0;+CSCS=\"GSM\";&W", CMDOPT_INIT | CMDOPT_GENERALINIT },
#endif
};
//
// RIL handle ctor
//
CRilHandle::CRilHandle()
: m_hInitEvent(NULL),
m_hCancelEvent(NULL),
m_hDataEvent(NULL),
m_hSimReadyEvent(NULL),
m_hInitedForSMSEvent(NULL),
m_hATCommandLogOwner(NULL),
m_hInitedForSIMPBEvent(NULL),
m_hCmdThread(NULL),
m_hReadThread(NULL),
m_fQuitReadyStateThread(FALSE),
m_dwCmdThreadID(0),
m_dwReadThreadID(0),
m_pCheckPoint(NULL),
#ifndef RIL_RADIO_RESILIENCE
m_pMonitor(NULL),
#endif // ! RIL_RADIO_RESILIENCE
m_pInstances(NULL),
m_hrNextCmdID(INITIAL_COMMAND_ID),
m_pComDevice(NULL),
m_pReadBytes(NULL),
#ifdef OEM2_DRIVER
m_pReadBytes2(NULL),
#endif
m_dwDataModeCmdDelay(3000),
m_dwMaxDataModeTimeWithoutCmd(30000),
m_fInited(FALSE),
m_fFailedInit(FALSE),
m_fInitedForSMS(FALSE),
m_fInitedForSIMPB(FALSE),
m_fWaitingForRsp(FALSE),
m_fEmergencyMode(FALSE),
m_fSimReady(FALSE),
m_dwSIMPBLastSize((DWORD)-1),
m_fLastCommandTimedOut(FALSE),
m_pSimToolkitHandling(NULL),
m_pCurrCommand(NULL)
{
// // FUNCTION_TRACE(CRilHandle::CRilHandle);
// Intialize critical sections
InitializeCriticalSection(&m_cs);
InitializeCriticalSection(&m_csInstances);
InitializeCriticalSection(&m_csCmdID);
InitializeCriticalSection(&m_csEmergency);
CRilNdis.Init(this);
memset(m_rgpAPIInfo, 0x00, APIID_TOTAL * sizeof(APIINFO*));
m_pSimToolkitHandling = new CSimToolkitHandling(this); //modified by viking wang
}
//
// Function passed to CDlbList::Enum() below
//
BOOL DeleteInstanceHandle(void* pItem, DWORD dwData)
{
DEBUGCHK(pItem != NULL);
CRilInstanceHandle* pHandle = (CRilInstanceHandle*)pItem;
delete pHandle;
// Continue enumeration
return FALSE;
}
//
// RIL handle dtor
//
CRilHandle::~CRilHandle()
{
// // FUNCTION_TRACE(CRilHandle::~CRilHandle);
UINT i;
{
SYNCBLOCK(m_cs);
// Stop the SIM-Toolkit handling
m_pSimToolkitHandling->Deinit();
delete m_pSimToolkitHandling;
HANDLE rghThreads[2] = { m_hCmdThread, m_hReadThread};
// Signal the cancel event to kill the thread
if (m_hCancelEvent)
{
(void)SetEvent(m_hCancelEvent);
}
// Reset the COM port
if (m_pComDevice)
{
(void)DeinitComPort(m_pComDevice);
}
StopReadyStateQuery();
// Wait for auxiliary threads to terminate
(void)WaitForSingleObject(m_hCmdThread, 10000);
(void)WaitForSingleObject(m_hReadThread, 10000);
// Kill NDIS Thread
CRilNdis.NdisStop();
// Get rid of the threads
if (m_hCmdThread)
{
(void)CloseHandle(m_hCmdThread);
m_hCmdThread = NULL;
m_dwCmdThreadID = 0;
}
if (m_hReadThread)
{
(void)CloseHandle(m_hReadThread);
m_hReadThread = NULL;
m_dwReadThreadID = 0;
}
// Get rid of the event
if (m_hCancelEvent)
{
(void)CloseHandle(m_hCancelEvent);
m_hCancelEvent = NULL;
}
// Get rid of the checkpoint
delete m_pCheckPoint;
m_pCheckPoint = NULL;
#ifndef RIL_RADIO_RESILIENCE
// Get rid of the monitor
delete m_pMonitor;
m_pMonitor = NULL;
#endif // RIL_RADIO_RESILIENCE
// Get rid of the queues
delete g_pCmdQ;
delete g_pRspQ;
delete g_pSimLockedQueue;
g_pCmdQ = NULL;
g_pRspQ = NULL;
g_pSimLockedQueue = NULL;
// Close the serial port
if (m_pComDevice)
{
COM_CloseInternal(m_pComDevice);
m_pComDevice = NULL;
}
// All of the instance handles should be closed
// before the driver handle is destroyed.
m_pInstances->Enum(DeleteInstanceHandle, 0);
// Delete the instance handle list
delete m_pInstances;
m_pInstances = NULL;
// Delete the Read Bytes buffer
delete m_pReadBytes;
m_pReadBytes = NULL;
#ifdef OEM2_DRIVER
// Delete the Read Bytes buffer
delete m_pReadBytes2;
m_pReadBytes2 = NULL;
#endif
// Get rid of init event
if (m_hInitEvent)
{
(void)CloseHandle(m_hInitEvent);
m_hInitEvent = NULL;
}
// Get rid of data event
if (m_hDataEvent)
{
(void)CloseHandle(m_hDataEvent);
m_hDataEvent = NULL;
}
// Delete the API information structures
for (i = 0; i < APIID_TOTAL; i++)
{
delete m_rgpAPIInfo[i];
m_rgpAPIInfo[i] = NULL;
}
DeleteCriticalSection(&m_csInstances);
DeleteCriticalSection(&m_csCmdID);
DeleteCriticalSection(&m_csEmergency);
m_fInited = FALSE;
m_fFailedInit=FALSE;
m_fInitedForSMS = FALSE;
m_fInitedForSIMPB = FALSE;
m_dwSIMPBLastSize = (DWORD)-1;
}
DeleteCriticalSection(&m_cs);
}
//
// Broadcasts a change in the radio ready state
//
void CRilHandle::SendReadyStateNotification(DWORD dwReadyState)
{
RILEQUIPMENTSTATE res;
CNotificationData *pnd = NULL;
#if defined(OEM1_DRIVER) || defined(OEM2_DRIVER) || defined(EMP_DRIVER)
if ((dwReadyState & RIL_READYSTATE_UNLOCKED) && !(g_dwReadyState & RIL_READYSTATE_UNLOCKED))
{
// certain commands like COPS need to wait for the module to
// "settle" after it's been unlocked.
g_dwUnlocked = GetTickCount();
}
#endif
// Set this in our global
if (dwReadyState)
{
g_dwReadyState |= dwReadyState;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -