📄 gprs.cpp
字号:
if (!QueueCmd(pHandle,
"AT+CGREG?\r",
CMDOPT_NONE,
APIID_GETGPRSREGISTRATIONSTATUS,
ParseGetGPRSRegistrationStatus, // Parse fn
NULL, // Ptr to notification data
hr))
{
hr = E_FAIL;
goto Error;
}
Error:
return hr;
}
/*
+CGCLASS: <class>
<class>: a string parameter which indicates the GPRS mobile class (in descending order of functionality)
A class A (highest)
B classB
C class C in GPRS and circuit switched alternate mode
CG class C in GPRS only mode
CC class C in circuit switched only mode (lowest)
*/
HRESULT ParseGetGPRSClass(LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
FUNCTION_TRACE(ParseGetGPRSClass);
char szValue[MAX_PATH];
DWORD *pdwClass=NULL;
HRESULT hr = E_FAIL;
pBlob = NULL;
cbBlob = 0;
// Parse "<prefix>"
if (!ParseRspPrefix(szRsp, szRsp))
{
goto Error;
}
// Parse "+CGCLASS: "
if (!MatchStringBeginning(szRsp, "+CGCLASS: ", szRsp))
{
goto Error;
}
pdwClass = (DWORD*)AllocBlob(sizeof(DWORD));
if (!pdwClass)
{
goto Error;
}
// Parse <class>
if (!ParseString(szRsp, szValue, MAX_PATH, szRsp))
{
goto Error;
}
FlagFromString(szValue,g_GprsClass,NUM_GPRSCLASS,*pdwClass);
pBlob = (void*)pdwClass;
cbBlob = sizeof(DWORD);
hr = S_OK;
Error:
if (FAILED(hr))
{
FreeBlob(pdwClass);
}
return hr;
}
// +CGCLASS?
HRESULT RILDrv_GetGPRSClass (DWORD dwParam)
{
FUNCTION_TRACE(RILDrv_GetGPRSClass);
DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RILDrv_GetGPRSClass\r\n")));
HRESULT hr = E_INVALIDARG;
#ifdef EMP_DRIVER
// EMP does not support +CGCLASS
hr = E_NOTIMPL;
goto Error;
#endif
CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
if (!pHandle)
{
goto Error;
}
if (!QueueCmd(pHandle,
"AT+CGCLASS?\r",
CMDOPT_NONE,
APIID_GETGPRSCLASS,
ParseGetGPRSClass, // Parse fn
NULL, // Ptr to notification data
hr))
{
hr = E_FAIL;
goto Error;
}
Error:
return hr;
}
// +CGCLASS=[A|B|C|CG|CC]
HRESULT RILDrv_SetGPRSClass (DWORD dwParam, DWORD dwClass)
{
FUNCTION_TRACE(RILDrv_SetGPRSClass);
DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RILDrv_SetGPRSClass\r\n")));
HRESULT hr = E_INVALIDARG;
#ifdef EMP_DRIVER
// EMP does not support +CGCLASS
hr = E_NOTIMPL;
goto Error;
#endif
CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
if (!pHandle)
{
goto Error;
}
// Build command
char szCmd[MAX_PATH];
LPSTR szString;
if (!StringFromFlag(dwClass,g_GprsClass,NUM_GPRSCLASS,szString))
{
goto Error;
}
(void)_snprintfz(szCmd, MAX_PATH, "AT+CGCLASS=\"%s\"\r", szString);
if (!QueueCmd(pHandle,
szCmd,
CMDOPT_NONE,
APIID_SETGPRSCLASS,
NULL, // Parse fn
NULL, // Ptr to notification data
hr))
{
hr=E_FAIL;
goto Error;
}
Error:
return hr;
}
/*
+CGSMS: <service>
<service>: a numeric parameter which indicates the service or service preference to be used
0 GPRS
1 circuit switched
2 GPRS preferred (use circuit switched if GPRS not available)
3 circuit switched preferred (use GPRS if circuit switched not available)
*/
HRESULT ParseGetMOSMSService(LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
FUNCTION_TRACE(ParseGetMOSMSService);
UINT nValue;
HRESULT hr = E_FAIL;
DWORD *pdwMoSmsService=NULL;
pBlob = NULL;
cbBlob = 0;
// Parse "<prefix>"
if (!ParseRspPrefix(szRsp, szRsp))
{
goto Error;
}
// Parse "+CGSMS: "
if (!MatchStringBeginning(szRsp, "+CGSMS: ", szRsp))
{
goto Error;
}
// Parse <service>
if (!ParseUInt(szRsp, TRUE, nValue, szRsp))
{
goto Error;
}
pdwMoSmsService = (DWORD*)AllocBlob(sizeof(DWORD));
if (!pdwMoSmsService)
{
goto Error;
}
FlagFromValue(nValue,g_GprsMOSMSService,NUM_GPRSMOSMSSERVICE,*pdwMoSmsService);
pBlob = (void*)pdwMoSmsService;
cbBlob = sizeof(DWORD);
hr = S_OK;
Error:
if (FAILED(hr))
{
FreeBlob(pdwMoSmsService);
}
return hr;
}
// +CGSMS?
HRESULT RILDrv_GetMOSMSService (DWORD dwParam)
{
FUNCTION_TRACE(RILDrv_GetMOSMSService);
DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RILDrv_GetMOSMSService\r\n")));
HRESULT hr = E_INVALIDARG;
CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
if (!pHandle)
{
goto Error;
}
if (!QueueCmd(pHandle,
"AT+CGSMS?\r",
CMDOPT_NONE,
APIID_GETMOSMSSERVICE,
ParseGetMOSMSService, // Parse fn
NULL, // Ptr to notification data
hr))
{
hr = E_FAIL;
goto Error;
}
Error:
return hr;
}
// +CGSMS=[0|1|2|3]
HRESULT RILDrv_SetMOSMSService (DWORD dwParam, DWORD dwMoSmsService)
{
FUNCTION_TRACE(RILDrv_SetMOSMSService);
DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RILDrv_SetMOSMSService\r\n")));
UINT Value;
HRESULT hr = E_INVALIDARG;
CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
if (!pHandle)
{
goto Error;
}
// Build command
char szCmd[MAX_PATH];
if (!ValueFromFlag(dwMoSmsService,g_GprsMOSMSService,NUM_GPRSMOSMSSERVICE,Value))
{
goto Error;
}
(void)_snprintfz(szCmd, MAX_PATH, "AT+CGSMS=%u\r",Value);
if (!QueueCmd(pHandle,
szCmd,
CMDOPT_NONE,
APIID_SETMOSMSSERVICE,
NULL, // Parse fn
NULL, // Ptr to notification data
hr))
{
hr = E_FAIL;
goto Error;
}
Error:
return hr;
}
// +CGCLASS: (list of supported <class>s)
HRESULT ParseGetGprsCapsClass(LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
FUNCTION_TRACE(ParseGetGprsCapsClass);
DWORD *pdwClass = NULL;
HRESULT hr = E_FAIL;
pBlob = NULL;
cbBlob = 0;
// Parse "<prefix>"
if (!ParseRspPrefix(szRsp, szRsp))
{
goto Error;
}
// Parse "+CGCLASS: "
if (!MatchStringBeginning(szRsp, "+CGCLASS: ", szRsp))
{
goto Error;
}
pdwClass = (DWORD*)AllocBlob(sizeof(DWORD));
if (!pdwClass)
{
goto Error;
}
// Parse ,<class>
if (!ParseStringList(szRsp, g_GprsClass, NUM_GPRSCLASS, *pdwClass, szRsp))
{
goto Error;
}
pBlob = (void*)pdwClass;
cbBlob = sizeof(DWORD);
hr = S_OK;
Error:
if (FAILED(hr))
{
FreeBlob(pdwClass);
}
return hr;
}
// +CGDCONT: (range of supported <cid>s),<PDP_type>,,,(list of supported <d_comp>s),(list of supported <h_comp>s)[,(list of supported <pd1>s)[,...[,(list of supported <pdN>s)]]]
// [<CR><LF>+CGDCONT: (range of supported <cid>s),<PDP_type>,,,(list of supported <d_comp>s),(list of supported <h_comp>s)[,(list of supported <pd1>s)[,...[,(list of supported <pdN>s)]]]
// [...]]
HRESULT ParseGetGprsCapsContext(LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
FUNCTION_TRACE(ParseGetGprsCapsContext);
PBYTE pBuffer=NULL;
DWORD dwBufferSize=0;
RILGPRSCONTEXTCAPS GPRSContextCaps, *pGPRSContextCaps;
char szValue[MAX_PATH];
LPCSTR szParams, szParamsEnd;
HRESULT hr = E_FAIL;
BOOL bSuccess;
pBlob = NULL;
cbBlob = 0;
// Parse "<prefix>"
if (!ParseRspPrefix(szRsp, szRsp))
{
goto Error;
}
// Parse "+CGDCONT: "
while (MatchStringBeginning(szRsp, "+CGDCONT: ", szRsp))
{
memset(&GPRSContextCaps, 0x00, sizeof(GPRSContextCaps));
// Parse (range of supported <cid>s)
if (!ParseRange(szRsp, GPRSContextCaps.ContextIDRange, szRsp))
{
goto Continue;
}
GPRSContextCaps.dwParams|= RIL_PARAM_GCONT_CONTEXTID;
// Parse ,<PDP_type>
if (!MatchStringBeginning(szRsp, ",", szRsp) ||
!ParseString(szRsp, szValue, MAX_PATH, szRsp))
{
goto Continue;
}
if (FlagFromString(szValue, g_GprsPDPTypes, NUM_GPRSPDPTYPES, GPRSContextCaps.dwProtocolType))
{
GPRSContextCaps.dwParams|= RIL_PARAM_GCONT_PROTOCOLTYPE;
}
// Parse ,,,(list of supported <d_comp>s)
if (!MatchStringBeginning(szRsp, ",,,", szRsp) ||
!ParseRangeList(szRsp, g_GprsDataComp, NUM_GPRSDATACOMP, GPRSContextCaps.dwDataCompression, szRsp))
{
goto Continue;
}
GPRSContextCaps.dwParams|= RIL_PARAM_GCONT_DATACOMPRESSION;
// Parse ,(list of supported <h_comp>s)
if (!MatchStringBeginning(szRsp, ",", szRsp) ||
!ParseRangeList(szRsp, g_GprsHeaderComp, NUM_GPRSHEADERCOMP, GPRSContextCaps.dwHeaderCompression, szRsp))
{
goto Continue;
}
GPRSContextCaps.dwParams|= RIL_PARAM_GCONT_HEADERCOMPRESSION;
// Parse ","
if (!MatchStringBeginning(szRsp, ",", szRsp))
{
goto Continue;
}
szParams = szRsp;
// Parse ,<pd1>[,...[,pdN]]
szParamsEnd = strstr(szParams, "\r\n");
if (!szParamsEnd)
{
goto Error;
}
szRsp = szParamsEnd;
// Set dwParameterLength to be size of string in bytes counting extra null char at end
GPRSContextCaps.dwParameterLength = ((szParamsEnd-szParams)+1);
// Now all the data between szParams and szParamsEnd is the pd1-N string
GPRSContextCaps.dwParams|= RIL_PARAM_GCONT_PARAMETERS;
Continue:
// Find "<postfix>"
bSuccess = FindRspPostfix(szRsp, szRsp);
if (!bSuccess)
{
goto Error;
}
// Init size of GPRSContextCaps
GPRSContextCaps.cbSize = sizeof(GPRSContextCaps);
// Add in size of param string
GPRSContextCaps.cbSize += GPRSContextCaps.dwParameterLength;
// Round up to the nearest 32-bit address for alignment
GPRSContextCaps.cbSize = (GPRSContextCaps.cbSize + 3) & (~0x03);
// Reallocate our buffer for the additional data
pBuffer = (PBYTE)ReallocBlob(pBuffer,dwBufferSize+GPRSContextCaps.cbSize);
if (!pB
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -