📄 rilhand.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
/*++
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:
--*/
//------------------------------------------------------------------------------
// Revision History
// Date Author Activity ID Activity Headline
// 2006-04-07 zhangchunzhong CEDB00012896 手机sleep一段时间后唤醒,gprs图标显示连接状态,但是实际连接不到网络
// 2006-04-27 wuguangliang CEDB200000271 Add addtional processs when sim card is removed
// 2007-01-29 XieFei CEDB200042432 modify phone book and SMS module for exporting
// 2007-02-13 likai CEDB200044510 modify for CSQ
// 2007-03-12 likai CEDB200047681 modify for net state
// 2007-03-30 XieFei CEDB200049615 Merge crowsbow code to cynthia850
// 2007-05-16 dongqiang CEDB200054889 add for CFUN response
// 2007-05-21 likai CEDB200055309 fix bug of set reg error for net state titlebar
// 2007-05-22 fengguisen CEDB200055583 add new code for cc of Cynthia850
// 2007-07-18 xiangming WM600010395 add the G/E icon function
// 2007-09-03 Cuiguoqing WM600013374 Synchronize codes between Projec Gallic and Projec Cynthia850.
// 2007-09-10 Cuiguoqing WM600016355 fix bug for card slot disaccord between idle interface and wireless manager.
// 2007-09-20 Cuiguoqing WM600017567 Modify codes in order to input PIN code for TI modem automatically.
// 2007-09-26 Cuiguoqing WM600018286 Modify for no signal bar on ver2.01.
// 2007-09-27 Cuiguoqing WM600018341 Modify codes to resolve the network operator name wrong after manual network select.
// 2007-09-30 sunrenhong WM600018812 broadcaset message RIL_NOTIFY_SPEC2NDCALLANSWERED
// 2007-10-18 Cuiguoqing WM600020042 Add a registry and write some codes for callflag icon on cynthia850_ver2.04.
// 2007-11-01 qinxuetao WM600014640 Limit the max size of notification data to 10KB
// 2007-11-05 Cuiguoqing WM600021316 change COPS CMD_OPT from CMD_NONE to CMD_INIT in Cynthia850_ver2.07.
// 2007-11-09 sunrenhong WM600021853 fix bug WM600021853 WM600022398 WM600022452 WM600022456
// 2007-11-09 Cuiguoqing WM600021394 modify for primary card setting in Cynthia850_ver2.08.
// 2007-11-13 sunrenhong WM600022706 delete the code for atd erro
// 2007-11-14 Cuiguoqing WM600021486 Add a registry for CCFC icon in Cynthia850 ver2.08.
// 2007-11-15 zhongchuren WM600021797 fixed the issue about TI modem not response to CGEREP.
// 2007-11-16 qinxuetao WM600021585 Sending AT+COPS=0 only after unlocking PIN
// 2007-09-19 Cuiguoqing WM600023412 update CurrentKey registry key value only for unconditional CCFC.
// 2007-11-21 Cuiguoqing WM600023190 add notify RIL_NOTIFY_SPECIALCHANGEPRIMARYCARD in order to change primary card settings.
// 2007-11-21 zhongchuren WM600023517 Fix the issue with power On/Off
// 2007-11-22 Chenjianjun WM600023499 When deleting all contacts in card 2, there are still 7 left.
// 2007-11-23 Cuiguoqing WM600024052 Modify for display correctly afer unlock phone with puk .
// 2007-11-26 qinxuetao WM600024004 Fix the deadlock issue while updating +CLCC times
// 2007-11-27 Cuiguoqing WM600024255 update CurrentKey registry key value only for cancel unconditional CCFC.
// 2007-12-06 Cuiguoqing WM600025007 Modify for offering a IMEI and IMSI api Interface on ver2.13.
// 2007-12-11 Sunrenhong WM600025448 delete the code for answer ok code
// 2007-12-14 Cuiguoqing WM600025478 Change the order of get IMEI at command in order to solve TI stack confussion on ver2.14.
// 2007-12-14 zhongchuren WM600025529 fixed the issue about Power off when Attach GPRS.
// 2007-12-17 Cuiguoqing WM600026179 Synchronize Gallic codes for bug WM600021830.
// 2007-12-20 Cuiguoqing WM600026245 Delete extra AT+COPS=0 AT COMMAND just after unlock phone.
// 2007-12-25 Cuiguoqing WM600025698 Modify for getting IMEI and IMSI but doesn't affect TI protocol stack.
// 2007-12-30 Cuiguoqing WM600027669 Modify for save correctly pin in order to unlock sim card just after radio off and radio on.
// 2008-01-08 Cuiguoqing WM600028320 Delete judge master card state for send AT+COPS=0 in ver2.19.
// 2008-01-09 qinxuetao WM600027958 Modify init strings and SimReadyThread
// 2008-01-10 Cuiguoqing WM600028599 Modify for sim identify in project N99.
// 2008-01-11 Cuiguoqing WM600028742 Modify for can't register on network just after unblock phone with gsm string.
// 2008-01-16 Cuiguoqing WM600029394 change registry about network operator.
// 2008-01-29 qinxuetao WM600030160 Fix SMS and SIMPB ready notification problem
// 2008-02-19 Cuiguoqing WM600031498 Modify some codes in order to meet the new requirement that user can set whether select card interface has been loaded.
// 2008-02-22 zhongchuren WM600031915 display Spn name in idle
// 2008-03-06 Cuiguoqing WM600033062 Add AT+CMEE=1 at command when user select the specific slot to be close on power on.
//------------------------------------------------------------------------------
#include "precomp.h"
#include "simmgr.h"
DWORD g_isflymode = MODEMMODE_UNKNOW;
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);
//adding for update the pin reg for APP
BOOL ChangePINReg(DWORD dwPINState);
BOOL AnotherCardNeedPIN(void);
BOOL ChangePrimaryCard(DWORD dwCardNum);
DWORD g_dwSimStatus = RIL_LOCKEDSTATE_UNKNOWN;
BOOL g_bFirstIntialized = FALSE;
// RIL registry key
#ifdef OEM1_DRIVER
const LPCTSTR g_tszRegKeyRIL = TEXT("Drivers\\BuiltIn\\RLO");
#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 = 2;
DWORD g_TimeoutCmdInit;
DWORD g_TimeoutCmdNoOp;
DWORD g_TimeoutCmdOnline;
DWORD g_TimeoutAPIDefault;
DWORD g_TimeoutDTRDrop;
DWORD g_TimeoutWaitForInit;
DWORD g_TimeoutRegisterNetwork;
DWORD g_dwLastCLIP = 1;
DWORD g_dwLastCLIR = 0;
//Dual-card:xiefei
BOOL g_Initialized = FALSE;
BOOL g_SpecReady = FALSE;
// 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;
CHAR g_szCard2Pin[10]={""};
CQueue<CCommand, 10>* g_pSimLockedQueue;
#ifdef CHANGEPINWRONG
BOOL g_ChangePINWrong = FALSE;
#endif
#ifdef OFFER_IMEI_IMSI
BOOL g_bFirstSetEquipment = TRUE;
#endif
//add by fengguisen for Simultaneous voice and data call
extern CALLCTRL_CID g_stDriver1CIDMap[CALLCTRL_MAX_CID] ;
extern HANDLE g_ShareMemHandle;//DMDC share memory handle
extern HANDLE g_ShareMemMutexHandle;//DMDC share memory Mutex Handle
extern LPCALLCTRL_SHARE_MEMORY g_pShareMem;//point to the share momory buffer
extern CRITICAL_SECTION g_csUpdateCLCCTimes ; //CRITICAL SECTION for access clcc times
extern UINT g_nGetCallListTimes ;//times for get call list
extern BOOL g_bRadioOff ;
BOOL g_fNoSIM = FALSE;
#define FIRST_POWERON_PATH TEXT("Software\\Microsoft\\RIL")
#define FIRST_POWERON_VALUE TEXT("Solt2IsFirstPowerON")
//end add
// 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)
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(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|"
#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
"%CREG=1|" //xiangming add for %creg at 070612
"%CGREG=1|" //xiangming add for %cgreg
#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,1|%CSTAT=1|"
#endif
//Added by wuguangliang 2006/04/18
#if defined(OEM1_SIMIND_NOTIFICATION)
"%SIMIND=1|"
#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_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*));
}
BOOL GetConnExistInfoFromRegistry(DWORD dwCardID, BOOL* pbConnExist);
//
// 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;
}
//
//Judge wheather it is a primary card
//
BOOL IsPrimaryCard(void)
{
//TCHAR* szRegCom = TEXT("System\\CardInfo\\CardCom");
DWORD dwCardPrimary = 0;
if( !GetRegistryDWORD(HKEY_LOCAL_MACHINE, TEXT("System\\CardInfo\\CardCom"), TEXT("CardPrimary"), &dwCardPrimary) )
{
RETAILMSG(1,(TEXT("[TI]GetRegistryCI-get CardPrimary from reg fail \r\n")));
return FALSE;
}
else
{
RETAILMSG(1,(TEXT("[TI]GetRegistryCI-CardPrimary=%d \r\n"), dwCardPrimary));
}
if (!(dwCardPrimary == 0x01))
{
return TRUE;
}
return FALSE;
}
//
//Judge wheather the card slot is open or close
//
BOOL GetCardOnOff(void)
{
// TCHAR* szRegLoc = TEXT("System\\CardInfo\\Card2");
DWORD dwCardOnOff = 0;
if( !GetRegistryDWORD(HKEY_LOCAL_MACHINE, TEXT("System\\CardInfo\\Card2"), TEXT("CardOnoff"), &dwCardOnOff) )
{
RETAILMSG(1,(TEXT("[TI]GetRegistryCI-get GetCardOnOff from reg fail \r\n")));
return FALSE;
}
else
{
RETAILMSG(1,(TEXT("[TI]GetCardOnOff-=%d \r\n"), dwCardOnOff));
}
if (dwCardOnOff == 0x00)
{
return FALSE;
}
else
{
return TRUE;
}
}
//Change the Reg state for exporting PB and SMS
//0: PIN ready; 1:PIN lock; 2:PUK block; 3:No SIM inserted
//
BOOL ChangePINReg(DWORD dwPINState)
{
//write the reg state
if( !SetRegistryDWORD(HKEY_LOCAL_MACHINE, TEXT("System\\CardInfo\\Card2"), TEXT("CardPin"), dwPINState))
{
RETAILMSG(1, (TEXT("[TI]SetRegistry-set PIN state failed\r\n")));
return FALSE;
}
else
{
RETAILMSG(1, (TEXT("[TI]SetRegistry-set PIN state is %d\r\n"),dwPINState));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -