📄 rilmain.cpp
字号:
}
//
// Emulate serial write
//
#ifdef __cplusplus
extern "C" DWORD RIL_Write(DWORD dwOpenData, LPCVOID pBuf, DWORD len)
#else
DWORD RIL_Write(DWORD dwOpenData, LPCVOID pBuf, DWORD len)
#endif
{
#ifdef RIL_ALLOW_DRIVER_REMOVAL_TESTING
if (!g_pDeviceAllowDriverRemovalTesting)
{
ASSERT(dwOpenData == 0x4321);
RIL_Init(1);
}
#endif
return 0;
}
//
//
//
#ifdef __cplusplus
extern "C" DWORD RIL_Seek(DWORD dwOpenData, long pos, DWORD type)
#else
DWORD RIL_Seek(DWORD dwOpenData, long pos, DWORD type)
#endif
{
return (DWORD)-1;
}
//
// Defines used in the switch below
//
#define CALLDRVAPI_PARAMS(PARAMSTYPE, APICall) \
{ \
PARAMSTYPE##* pParams = (##PARAMSTYPE##*)BufInDuplicate.ptr(); \
if (BufInDuplicate.ptr() && BufInDuplicate.size() == sizeof(PARAMSTYPE)) { \
*phr = APICall; \
dwOutUsed = sizeof(HRESULT); \
fRet = TRUE; \
} \
ASSERT(BufInDuplicate.ptr() && BufInDuplicate.size() == sizeof(PARAMSTYPE));\
}
#define CALLDRVAPI_CONSTPARAMS(PARAMSTYPE, APICall) \
{ \
const PARAMSTYPE##* pParams = (##PARAMSTYPE##*)BufInDuplicate.ptr(); \
if (BufInDuplicate.ptr() && BufInDuplicate.size() == sizeof(PARAMSTYPE)) { \
*phr = APICall; \
dwOutUsed = sizeof(HRESULT); \
fRet = TRUE; \
} \
ASSERT(BufInDuplicate.ptr() && BufInDuplicate.size() == sizeof(PARAMSTYPE));\
}
#define CALLDRVAPI_VARPARAMS(PARAMSTYPE, APICall) \
{ \
PARAMSTYPE##* pParams = (##PARAMSTYPE##*)BufInDuplicate.ptr(); \
if (BufInDuplicate.ptr() && (BufInDuplicate.size() >= sizeof(PARAMSTYPE)) && (pParams->cbSize == BufInDuplicate.size())) { \
*phr = APICall; \
dwOutUsed = sizeof(HRESULT); \
fRet = TRUE; \
} \
ASSERT(BufInDuplicate.ptr() && BufInDuplicate.size() >= sizeof(PARAMSTYPE) && (pParams->cbSize == BufInDuplicate.size()));\
}
#define CALLDRVAPI_ARRAY(ELEMTYPE, APICall) \
{ \
ELEMTYPE##* pParams = (##ELEMTYPE##*)BufInDuplicate.ptr(); \
if (BufInDuplicate.ptr()) { \
*phr = APICall; \
dwOutUsed = sizeof(HRESULT); \
fRet = TRUE; \
} \
ASSERT(BufInDuplicate.ptr());\
}
#define CALLDRVAPI_CONSTARRAY(ELEMTYPE, APICall) \
{ \
const ELEMTYPE##* pParams = (##ELEMTYPE##*)BufInDuplicate.ptr(); \
if (BufInDuplicate.ptr()) { \
*phr = APICall; \
dwOutUsed = sizeof(HRESULT); \
fRet = TRUE; \
} \
ASSERT(BufInDuplicate.ptr());\
}
#define CALLDRVAPI(APIName) \
*phr = APIName(dwOpenData); \
dwOutUsed = sizeof(HRESULT); \
fRet = TRUE; \
ASSERT(NULL == BufInDuplicate.ptr());
#define NULLTERMINATE(ELEMTYPE) \
{ \
ELEMTYPE##* pArray = (##ELEMTYPE##*)BufInDuplicate.ptr(); \
if ( pArray ) { \
pArray[BufInDuplicate.size()/sizeof(*pArray) - 1] = 0; \
} \
}
//
//
//
#ifdef __cplusplus
extern "C" BOOL RIL_IOControl(DWORD dwOpenData, DWORD dwCode, PBYTE pBufIn, DWORD dwLenIn, __out_bcount( dwLenOut ) PBYTE pBufOut, DWORD dwLenOut,
PDWORD pdwActualOut)
#else
BOOL RIL_IOControl(DWORD dwOpenData, DWORD dwCode, PBYTE pBufIn, DWORD dwLenIn, __out_bcount( dwLenOut ) PBYTE pBufOut, DWORD dwLenOut,
PDWORD pdwActualOut)
#endif
{
FUNCTION_TRACE(RIL_IOControl);
DEBUGCHK(dwOpenData != 0);
DWORD dwOutUsed = 0;
BOOL fRet = FALSE;
DuplicatedBuffer_t BufInDuplicate;
DuplicatedBuffer_t BufOutDuplicate;
DuplicatedBuffer_t BufActualOut;
#ifdef RIL_ALLOW_DRIVER_REMOVAL_TESTING
if (!g_pDeviceAllowDriverRemovalTesting)
{
ASSERT(!"RIL_IOControl should not be called after the driver has gone away");
return FALSE;
}
#endif
CRilInstanceHandle* pHandle = (CRilInstanceHandle*)dwOpenData;
if (!pHandle)
{
goto Error;
}
/* There are quite a few possibilies for in/out coming in to this function:
RIL API:
pBufIn = NULL or data
pBufOut should always be populated and have a size.
Direct RIL IO control calls:
The RIl proxy makes other IOCTL calls. They consist of the following possibilities
pBufIn = NULL or data
pBufOut = NULL or data
Since there are all type of possibilites, it's up to the individual IOCTL to confirm the correct information is present. */
if ( (pBufIn && !dwLenIn) || \
(pBufOut && !dwLenOut) || \
(!pBufIn && dwLenIn) || \
(!pBufOut && dwLenOut) || \
(pBufOut && !pdwActualOut))
{
ASSERT(FALSE);
goto Error;
}
if ( pBufIn )
{
if ( FAILED(BufInDuplicate.Allocate(pBufIn, dwLenIn, ARG_I_PTR)))
{
goto Error;
}
}
if ( pBufOut)
{
if ( FAILED(BufOutDuplicate.Allocate(pBufOut, dwLenOut, ARG_O_PTR)))
{
goto Error;
}
}
if ( pdwActualOut )
{
if ( FAILED(BufActualOut.Allocate(pdwActualOut, sizeof(DWORD), ARG_O_PTR)))
{
goto Error;
}
}
switch (dwCode)
{
// CPM is ready for us to register with it
case IOCTL_RIL_REGISTERWITHCPM:
{
ASSERT(NULL == BufInDuplicate.ptr() && NULL == BufOutDuplicate.ptr());
#ifdef RIL_RADIO_RESILIENCE
// no longer supported
fRet = FALSE;
#else
CRilHandle* pRilDevice = pHandle->GetDevice();
DEBUGCHK(NULL != pRilDevice);
fRet = pRilDevice->RegisterWithCPM();
#endif // ! RIL_RADIO_RESILIENCE
}
break;
// This handle will be used for an emergency call - it should be marked as preferred and RIL should be
// switched into "emergency mode"
case IOCTL_RIL_EMERGENCYSTATUS:
ASSERT(NULL == BufInDuplicate.ptr() && NULL == BufOutDuplicate.ptr());
fRet = pHandle->MakePreferred();
break;
// Initialize notification delivery
case IOCTL_RIL_INITNOTIFICATIONS:
ASSERT(BufInDuplicate.ptr() && BufOutDuplicate.ptr());
if (BufInDuplicate.ptr() && BufOutDuplicate.ptr())
{
fRet = pHandle->CreateNotificationQueue((LPCTSTR)BufInDuplicate.ptr(), (PBYTE)BufOutDuplicate.ptr(), BufOutDuplicate.size(), &dwOutUsed);
}
break;
// Get next RIL notification
case IOCTL_RIL_GETNEXTNOTIFICATION:
{
ASSERT(NULL == BufInDuplicate.ptr() && BufOutDuplicate.ptr());
if ( BufOutDuplicate.ptr() && BufOutDuplicate.size() >= sizeof(RILDRVNOTIFICATION))
{
RILDRVNOTIFICATION* pResult = (RILDRVNOTIFICATION*)BufOutDuplicate.ptr() ;
if( SUCCEEDED(RILDrv_GetNextNotification(dwOpenData, pResult)))
{
dwOutUsed = BufOutDuplicate.size();
fRet = TRUE;
}
}
break;
}
// RIL_GetSerialPortStatistics()
case IOCTL_RIL_GETSERIALPORTSTATISTICS:
{
ASSERT(NULL == BufInDuplicate.ptr() && BufOutDuplicate.ptr() && sizeof(RILSERIALPORTSTATS) == BufOutDuplicate.size());
if ((BufOutDuplicate.ptr() && sizeof(RILSERIALPORTSTATS) == BufOutDuplicate.size()))
{
RILSERIALPORTSTATS* pResult = (RILSERIALPORTSTATS*)BufOutDuplicate.ptr();
if ( SUCCEEDED(RILDrv_GetSerialPortStatistics(dwOpenData, pResult)))
{
dwOutUsed = BufOutDuplicate.size();
fRet = TRUE;
}
}
break;
}
// RIL_GetDriverVersion()
case IOCTL_RIL_GETDRIVERVERSION:
{
ASSERT(NULL == BufInDuplicate.ptr() && BufOutDuplicate.ptr() && sizeof(DWORD) == BufOutDuplicate.size());
if (BufOutDuplicate.ptr() && sizeof(DWORD) == BufOutDuplicate.size())
{
DWORD *pResult = (DWORD *)BufOutDuplicate.ptr();
// For now, versioning is going to be done manually on an as needed basis
*pResult = 0x00020002;
dwOutUsed = BufOutDuplicate.size();
fRet = TRUE;
}
break;
}
#ifdef RIL_LAST_ERROR
case IOCTL_RIL_GETLASTERROR:
{
ASSERT(NULL == BufInDuplicate.ptr() && BufOutDuplicate.ptr() && sizeof(DWORD) == BufOutDuplicate.size());
if (BufInDuplicate.ptr() && sizeof(DWORD) == BufOutDuplicate.size())
{
DWORD *pResult = (DWORD *)BufInDuplicate.ptr();
// Give them back the error
*pResult = g_dwLastError;
dwOutUsed = BufOutDuplicate.size();
fRet = TRUE;
}
break;
}
break;
#endif
case IOCTL_PSL_NOTIFY:
{
pHandle->CancelNotifications();
fRet = TRUE;
break;
}
case IOCTL_RIL_GETSERIALPORTHANDLEFROMCONTEXTID:
{
ASSERT(BufInDuplicate.ptr() && sizeof(DWORD) == BufInDuplicate.size() && BufOutDuplicate.ptr());
if ( BufInDuplicate.ptr() && sizeof(DWORD) == BufInDuplicate.size() && BufOutDuplicate.ptr() )
{
if ( SUCCEEDED(RILDrv_GetSerialPortHandleFromContextID(*((DWORD*)BufInDuplicate.ptr() ), (TCHAR*) BufOutDuplicate.ptr(), BufOutDuplicate.size(), &dwOutUsed)))
{
fRet = TRUE;
}
}
break;
}
case IOCTL_RIL_GETVTSERIALPORTHANDLE:
{
ASSERT( BufOutDuplicate.ptr() && BufOutDuplicate.size() );
fRet = SUCCEEDED( RILDrv_GetVTSerialPortHandle( (LPTSTR)(BufOutDuplicate.ptr()), BufOutDuplicate.size(), &dwOutUsed ) );
break;
}
// Other RIL_ APIs
default:
{
ASSERT(BufOutDuplicate.ptr() && sizeof(HRESULT) == BufOutDuplicate.size());
HRESULT* phr = (HRESULT*)BufOutDuplicate.ptr() ;
if (NULL == BufOutDuplicate.ptr() || BufOutDuplicate.size() != sizeof(HRESULT))
{
goto Error;
}
switch (dwCode)
{
// RIL saving power management io control
case IOCTL_RIL_POWERSUSPEND:
CALLDRVAPI(RILDrv_EnablePowerSavings);
break;
// RIL disable saving power management io control
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -