?? reboot.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.
//
#include <precomp.h>
#ifdef SIMULATE_HUNG_RADIO
BOOL g_fSimulateHungRadio = FALSE;
#endif
#ifdef RIL_RADIO_RESILIENCE
char g_szOpSelCmd[NETWK_CMDBUF_LENGTH];
BOOL g_fOperatorSelected = FALSE;
char g_szPBLocCmd[MISC_CMDBUF_LENGTH_PBLOC];
BOOL g_fPBLocationSet = FALSE;
extern DWORD g_dwCacheDownlinkVolume;
CRITICAL_SECTION g_csReboot;
BOOL g_fInitedFirstTime = FALSE;
extern BOOL g_bRadioOff;
SYSTEMTIME g_LastResetTime;
BOOL g_fRadioResetRecently =FALSE;
UINT g_cbLastLockCapsSize = 0;
void *g_pLastLockCaps = NULL;
#define SECONDS_TO_100NS(SEC) (((UINT64)(SEC)) * 10000000ui64)
#define RESET_SPOOF_DURATION SECONDS_TO_100NS(10)
extern void FillEquipmentStateStruct(RILEQUIPMENTSTATE * pres, DWORD dwEqState);
BOOL ShouldSpoofCommand()
{
BOOL fReturn = FALSE;
if (g_fRadioResetRecently)
{
SYSTEMTIME CurrentSystemTime;
GetSystemTime(&CurrentSystemTime);
UINT64 CurrentFileTime;
UINT64 LastResetFileTime;
if ((SystemTimeToFileTime(&CurrentSystemTime, (LPFILETIME)&CurrentFileTime)) &&
(SystemTimeToFileTime(&g_LastResetTime, (LPFILETIME)&LastResetFileTime)))
{
if ((CurrentFileTime - LastResetFileTime) < RESET_SPOOF_DURATION)
{
fReturn = TRUE;
}
else
{
// We've passed the time where we are comfortable spoofing this response.
// set the flag so that we won't check next time
g_fRadioResetRecently = FALSE;
}
}
}
return fReturn;
}
BOOL RebootRadio()
{
FUNCTION_TRACE(RebootRadio);
DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : CRilHandle::RebootRadio\r\n")));
#ifdef SIMULATE_HUNG_RADIO
g_fSimulateHungRadio = FALSE;
#endif
HRESULT hr = PDD_RebootRadio();
if ( FAILED( hr ) && E_NOTIMPL != hr )
{
DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RebootRadio : PDD_RebootRadio failed , hr = [0x%08x]\r\n"), hr));
return FALSE;
}
return TRUE;
}
BOOL RebootRestoreState()
{
BOOL fSuccess = FALSE;
char szNextCmd[MAX_PATH];
RILEQUIPMENTSTATE res;
CNotificationData *pnd = NULL;
DWORD dwDisconnectReason = RIL_DISCINIT_REMOTE;
DWORD dwOldReadyState = g_dwReadyState;
BOOL OldRadioOff = g_bRadioOff;
EnterCriticalSection(&g_csReboot);
// Make sure that we turn off the audio path both starting up. Indicate call is inactive to audio driver
IndicateCallActivityToAudioSubsystem(FALSE, FALSE);
// We rebooted, so we want to cycle through the ready states from none again.
g_dwReadyState = RIL_READYSTATE_NONE;
// Test hook for knowing when the radio rebooted
pnd = new CNotificationData;
if (pnd && !pnd->InitFromRealBlob(RIL_NOTIFY_RADIORESET, NULL, 0))
{
delete pnd;
pnd = NULL;
}
else
{
QueueCmdIgnoreRsp(APIID_NONE, NULL, CMDOPT_INIT | CMDOPT_NOOP, g_TimeoutCmdInit, NULL, pnd, 0, 0, 0);
}
// Assume any calls were disconnected
pnd = new CNotificationData;
if (pnd && !pnd->InitFromRealBlob(RIL_NOTIFY_DISCONNECT, (void*)&dwDisconnectReason, sizeof(dwDisconnectReason)))
{
delete pnd;
pnd = NULL;
}
else
{
QueueCmdIgnoreRsp(APIID_NONE, NULL, CMDOPT_INIT | CMDOPT_NOOP, g_TimeoutCmdInit, NULL, pnd, 0, 0, 0);
}
// Some radios may need a bit before we send down the Init strings
Sleep(g_rppPDDParams->dwPostRebootInitDelay);
SendComInitString(COM_INIT_INDEX);
HRESULT hr = E_FAIL;
SAFE_PDD_CREATECOMMAND( szNextCmd, MAX_PATH, hr, PDD_CreateCommand_GetPostRebootDiagnostics( szNextCmd, MAX_PATH ) );
if ( FAILED( hr ) && E_NOTIMPL != hr )
{
DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : PDD_CreateCommand_GetPostRebootDiagnostics failed , hr = [0x%08x]\r\n"), hr));
}
if (S_OK == hr) {
QueueCmdIgnoreRsp(APIID_NONE, szNextCmd, CMDOPT_INIT, g_TimeoutCmdInit, g_rppPDDParams->pfnParsePostRebootDiagnostics, NULL, 0, 0, 0);
}
if (OldRadioOff == FALSE)
{
FillEquipmentStateStruct(&res, RIL_EQSTATE_MINIMUM);
pnd = new CNotificationData;
if (pnd && !pnd->InitFromRealBlob(RIL_NOTIFY_RADIOEQUIPMENTSTATECHANGED, (void*)&res, res.cbSize))
{
delete pnd;
pnd = NULL;
}
}
else
{
// Don't send a CFUN 0 notification if the radio was already off
pnd = NULL;
}
// Cycle the radio equipment state, otherwise some radios will return errors
QueueCmdIgnoreRsp(APIID_SETEQUIPMENTSTATE, "AT+CFUN=0\r", CMDOPT_INIT, g_TimeoutCmdInit, NULL, pnd, 0, 0, 0);
if (OldRadioOff == FALSE)
{
FillEquipmentStateStruct(&res, RIL_EQSTATE_FULL);
pnd = new CNotificationData;
if (pnd && !pnd->InitFromRealBlob(RIL_NOTIFY_RADIOEQUIPMENTSTATECHANGED, (void*)&res, res.cbSize))
{
delete pnd;
pnd = NULL;
}
CHAR szCmdBuf[MAX_PATH];
char* szWalk = szCmdBuf;
HRESULT hr = E_FAIL;
SAFE_PDD_CREATECOMMAND( szWalk, MAX_PATH - ( szWalk - szCmdBuf ), hr, PDD_CreateCommand_SetupBeforeRadioOn( szWalk, MAX_PATH - (szWalk - szCmdBuf), FALSE ) );
if ( FAILED( hr ) && E_NOTIMPL != hr )
{
DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : PDD_CreateCommand_SetupBeforeRadioOn failed , hr = [0x%08x]\r\n"), hr));
}
if (E_NOTIMPL == hr) {
(void)_snprintfz(szWalk, MAX_PATH - (szWalk - szCmdBuf), "AT");
}
szWalk = strchr(szWalk, '\0'); // NO_TYPO: 27
DEBUGCHK(NULL != szWalk);
(void)_snprintfz(szWalk, MAX_PATH - (szWalk - szCmdBuf), "+CFUN=1\r");
QueueCmdIgnoreRsp(APIID_SETEQUIPMENTSTATE, szCmdBuf, CMDOPT_INIT | CMDOPT_SETRADIOON | CMDOPT_IGNORERADIOOFF | CMDOPT_REINIT, g_TimeoutCmdInit, NULL, pnd, 0, 0, 0);
}
// if we just rebooted and were previously unlocked, then unlock the phone
if (dwOldReadyState & RIL_READYSTATE_UNLOCKED)
{
CHAR szLastPIN[256];
if (FetchPINSecure(szLastPIN, sizeof(szLastPIN)))
{
(void)_snprintfz(szNextCmd, MAX_PATH, "AT+CPIN=\"%s\"\r", szLastPIN);
QueueCmdIgnoreRsp(APIID_NONE, szNextCmd, CMDOPT_INIT, g_TimeoutCmdInit, NULL, NULL, 0, 0, 0);
}
}
if (g_fOperatorSelected && (OldRadioOff == FALSE))
{
// if we just rebooted and were previously registered, then reregister on the network
QueueCmdIgnoreRsp(APIID_NONE, g_szOpSelCmd, CMDOPT_INIT, g_TimeoutCmdInit, NULL, NULL, 0, 0, 0);
}
// Restore audio gain
(void)_snprintfz(szNextCmd, MAX_PATH, "AT+CLVL=%u\r", g_dwCacheDownlinkVolume);
QueueCmdIgnoreRsp(APIID_NONE, szNextCmd, CMDOPT_NONE, g_TimeoutCmdInit, NULL, NULL, 0, 0, 0);
// Restore PB location
if (g_fPBLocationSet)
{
QueueCmdIgnoreRsp(APIID_NONE, g_szPBLocCmd, CMDOPT_INIT, g_TimeoutCmdInit, NULL, NULL, 0, 0, 0);
}
fSuccess = TRUE;
LeaveCriticalSection(&g_csReboot);
return fSuccess;
}
HRESULT RILDrv_RebootRadio (DWORD dwParam)
{
FUNCTION_TRACE(RILDrv_RebootRadio);
DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RILDrv_RebootRadio\r\n")));
HRESULT hr = E_INVALIDARG;
CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
if (!pHandle)
{
goto Error;
}
if (!RebootRadio())
{
hr = E_NOTIMPL;
goto Error;
}
// send an OK response
if (!QueueCmd(pHandle, NULL, CMDOPT_NOOP, APIID_REBOOTRADIO, NULL, NULL, hr))
{
hr = E_FAIL;
goto Error;
}
Error:
return hr;
}
#endif // RIL_RADIO_RESILIENCE
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -