📄 misc.cpp
字号:
!MatchStringBeginning(szRsp, ",", szRsp) ||
!ParseUIntAndVerifyAbove(szRsp, FALSE, 0x100, nValue, szRsp) ||
!StringToRILAddress(szAddress, (BYTE)nValue, rgrbpe[nUsed].raAddress)) {
goto Continue;
}
rgrbpe[nUsed].dwParams |= RIL_PARAM_PBE_ADDRESS;
#if defined (OEM1_DRIVER)|| defined(OEM2_DRIVER)
ConvertDTMFControlDigitSeparatorCharacter(rgrbpe[nUsed].raAddress.wszAddress);
#endif
// clear buffer before reusing
memset(wszText, 0x00, sizeof(wszText));
// Parse ",<text>"
if (!MatchStringBeginning(szRsp, ",", szRsp) ||
!ParseQuotedEncodedString(ENCODING_TECHARSET, szRsp, wszText, wszText + MAXLENGTH_PHONEBOOKTEXT)) {
goto Continue;
}
(void)wcsncpyz(rgrbpe[nUsed].wszText, wszText, MAXLENGTH_PHONEBOOKTEXT);
rgrbpe[nUsed].dwParams |= RIL_PARAM_PBE_TEXT;
// Increment the array index
nUsed++;
Continue:
// Find "<postfix>"
if (!FindRspPostfix(szRsp, szRsp)) {
hr = E_FAIL;
goto Error;
}
}
pBlob = (void*)rgrbpe;
cbBlob = nUsed * sizeof(RILPHONEBOOKENTRY);
Error:
if (FAILED(hr)) {
delete[] (BYTE*)rgrbpe;
}
return hr;
}
//
//
//
static HRESULT ParseReadPhonebookEntries(LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
FUNCTION_TRACE(ParseReadPhonebookEntries);
return ParseArrayOfPhonebookEntries("+CPBR: ", szRsp, pBlob, cbBlob);
}
//
//
//
HRESULT RILDrv_ReadPhonebookEntries(DWORD dwParam, DWORD dwStartIndex, DWORD dwEndIndex)
{
FUNCTION_TRACE(RILDrv_ReadPhonebookEntries);
char szCmd[MAX_PATH];
HRESULT hr = S_OK;
CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
if (!pHandle) {
hr = E_FAIL;
goto Error;
}
(void)_snprintfz(szCmd, MAX_PATH, "AT+CPBR=%u,%u\r", dwStartIndex, dwEndIndex);
// roughly over 100 entries read in 10 secs based on current empirical data
unsigned Timeout = 0; // in msec
DWORD PbEntries = dwEndIndex - dwStartIndex;
if ( (dwEndIndex > dwStartIndex) && (PbEntries > 100) &&
!safeIntUMul( PbEntries, 100, &Timeout ) )
{
Timeout = UINT_MAX;
}
if ( !QueueCmdWithTimeout( pHandle, szCmd, NULL, CMDOPT_NONE, APIID_READPHONEBOOKENTRIES,
ParseReadPhonebookEntries, NULL, hr, Timeout, 0 ) ) {
hr = E_FAIL;
goto Error;
}
Error:
return hr;
}
//
//
//
HRESULT RILDrv_WritePhonebookEntry(DWORD dwParam, const RILPHONEBOOKENTRY* lpEntry)
{
FUNCTION_TRACE(RILDrv_WritePhonebookEntry);
#if 0
CNotificationData* pnd = NULL;
#endif
BYTE bTypeOfAddress;
char szAddress[MAXLENGTH_ADDRESS];
char szCmd[MISC_CMDBUF_LENGTH_PB];
LPSTR szWalk = szCmd;
HRESULT hr = S_OK;
CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
if (!pHandle || !lpEntry) {
hr = E_FAIL;
goto Error;
}
if (!(lpEntry->dwParams & RIL_PARAM_PBE_INDEX) || !(lpEntry->dwParams & RIL_PARAM_PBE_ADDRESS)) {
hr = E_INVALIDARG;
goto Error;
}
// Determine address and type-of-address byte
hr = RILAddressToString(lpEntry->raAddress, szAddress, MAXLENGTH_ADDRESS, bTypeOfAddress);
if (FAILED(hr)) {
goto Error;
}
if (RIL_PBINDEX_FIRSTAVAILABLE == lpEntry->dwIndex) {
(void)_snprintfz(szWalk, MISC_CMDBUF_LENGTH_PB - (szWalk - szCmd), "AT+CPBW=,\"%s\",%u", szAddress, bTypeOfAddress);
} else {
(void)_snprintfz(szWalk, MISC_CMDBUF_LENGTH_PB - (szWalk - szCmd), "AT+CPBW=%u,\"%s\",%u", lpEntry->dwIndex, szAddress,
bTypeOfAddress);
}
szWalk = strchr(szWalk, '\0'); // NO_TYPO: 27
DEBUGCHK(NULL != szWalk);
// Add text, if supplied
if (lpEntry->dwParams & RIL_PARAM_PBE_TEXT) {
(void)strncpyz(szWalk, ",", MISC_CMDBUF_LENGTH_PB - (szWalk - szCmd)); // NO_TYPO: 30
szWalk = strchr(szWalk, '\0'); // NO_TYPO: 27
DEBUGCHK(NULL != szWalk);
if (!AppendQuotedEncodedString(ENCODING_TECHARSET, lpEntry->wszText, szWalk, (PUCHAR)&szCmd[MISC_CMDBUF_LENGTH_PB], ALLOW_UNICODE_PB_ENTRIES))
{
hr = E_FAIL;
goto Error;
}
}
(void)strncpyz(szWalk, "\r", MISC_CMDBUF_LENGTH_PB - (szWalk - szCmd)); // NO_TYPO: 30
//unbroacast notification for dual_card add by qianli
#if 0
pnd = new CNotificationData;
if (pnd && !pnd->InitFromDWORDBlob(RIL_NOTIFY_PHONEBOOKENTRYSTORED, lpEntry->dwIndex))
{
delete pnd;
pnd = NULL;
}
if (!QueueCmd(pHandle, szCmd, CMDOPT_NONE, APIID_WRITEPHONEBOOKENTRY, NULL, pnd, hr))
{
hr = E_FAIL;
goto Error;
}
pnd = NULL;
#endif
if (!QueueCmd(pHandle, szCmd, CMDOPT_NONE, APIID_WRITEPHONEBOOKENTRY, NULL, NULL, hr))
{
hr = E_FAIL;
goto Error;
}
Error:
return hr;
}
//
//
//
HRESULT RILDrv_DeletePhonebookEntry(DWORD dwParam, DWORD dwIndex)
{
FUNCTION_TRACE(RILDrv_DeletePhonebookEntry);
#if 0
CNotificationData* pnd = NULL;
#endif
char szCmd[MAX_PATH];
HRESULT hr = S_OK;
CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
if (!pHandle) {
hr = E_FAIL;
goto Error;
}
//unbroacast notification for dual_card add by qianli
#if 0
pnd = new CNotificationData;
if (pnd && !pnd->InitFromDWORDBlob(RIL_NOTIFY_PHONEBOOKENTRYDELETED, dwIndex)) {
delete pnd;
pnd = NULL;
}
(void)_snprintfz(szCmd, MAX_PATH, "AT+CPBW=%u\r", dwIndex);
if (!QueueCmd(pHandle, szCmd, CMDOPT_NONE, APIID_DELETEPHONEBOOKENTRY, NULL, pnd, hr)) {
hr = E_FAIL;
goto Error;
}
pnd = NULL;
#endif
(void)_snprintfz(szCmd, MAX_PATH, "AT+CPBW=%u\r", dwIndex);
if (!QueueCmd(pHandle, szCmd, CMDOPT_NONE, APIID_DELETEPHONEBOOKENTRY, NULL, NULL, hr))
{
hr = E_FAIL;
goto Error;
}
Error:
return hr;
}
//
//
//
HRESULT RILDrv_GetContactNameInfo(DWORD dwParam, WCHAR* wszContactName, CONTACT_NAME_INFO *contactinfo)
{
FUNCTION_TRACE(RILDrv_GetContactNameInfo);
char szCmd[MISC_CMDBUF_LENGTH_PB];
LPSTR szWalk = szCmd;
HRESULT hr = S_OK;
CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
RETAILMSG(1,(TEXT("[TI][RILDrv_GetContactNameInfo]:pHandle=%08x wszContactName=%08x contactinfo=%08x\r\n"),pHandle,wszContactName,contactinfo));
if (!pHandle || !wszContactName || !contactinfo) {
hr = E_FAIL;
goto Error;
}
g_EncodeType = ENCODE_NONE;
g_bEncodeHex = FALSE;
if (!AppendQuotedEncodedString(ENCODING_TECHARSET, wszContactName, szWalk, (const PUCHAR)(szCmd+sizeof(szCmd)), ALLOW_UNICODE_PB_ENTRIES))
{
hr = E_FAIL;
goto Error;
}
if( ENCODE_NONE == g_EncodeType)
{
RETAILMSG(1,(TEXT("[TI][RILDrv_GetContactNameInfo]:ERROR: g_EncodeType=ENCODE_NONE\r\n")));
hr = E_FAIL;
goto Error;
}
contactinfo->type = g_EncodeType;
contactinfo->encoded_length = szWalk - szCmd - 2;
if(g_bEncodeHex)
{
contactinfo->encoded_length >>= 1;
}
RETAILMSG(1,(TEXT("[TI][RILDrv_GetContactNameInfo]:type=%08x encoded_length=%08x\r\n"),contactinfo->type,contactinfo->encoded_length));
Error:
RETAILMSG(1,(TEXT("[TI][RILDrv_GetContactNameInfo]:return: %08x\r\n"), hr));
return hr;
}
//
//
//
static HRESULT ParseSendSimCmd(LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
FUNCTION_TRACE(ParseSendSimCmd);
UINT i;
UINT nValue = 0;
UINT cbResponse = 0;
BYTE* pbResponse = NULL;
BYTE* pbResponseWalk;
HRESULT hr = S_OK;
pBlob = NULL;
cbBlob = 0;
// Parse "<prefix>+CSIM: <length>,"
if (!ParseRspPrefix(szRsp, szRsp) ||
!MatchStringBeginning(szRsp, "+CSIM: ", szRsp) ||
!ParseUInt(szRsp, TRUE, nValue, szRsp) ||
!MatchStringBeginning(szRsp, ",", szRsp)) {
hr = E_FAIL;
goto Error;
}
DEBUGCHK(0 == nValue % 2);
if (0 < nValue) {
// Allocate the storage
cbResponse = nValue / 2;
pbResponse = (BYTE *)AllocBlob(cbResponse);
if (!pbResponse) {
hr = E_OUTOFMEMORY;
goto Error;
}
pbResponseWalk = pbResponse;
for (i = 0; i < cbResponse; i++) {
if (!*szRsp || !*(szRsp + 1)) {
hr = E_FAIL;
goto Error;
}
*pbResponseWalk = SemiByteCharsToByte(*szRsp, *(szRsp + 1));
pbResponseWalk++;
szRsp += 2;
}
// Parse "<postfix>"
if (!ParseRspPostfix(szRsp, szRsp)) {
hr = E_FAIL;
goto Error;
}
}
else {
// Special case where the response was 0 length.
// Handle it by trashing the rest of the response.
DEBUGCHK(FALSE);
if (!MatchStringAnywhere(szRsp, "\r\n", szRsp))
{
hr = E_FAIL;
goto Error;
}
}
pBlob = (void*)pbResponse;
cbBlob = cbResponse;
Error:
if (FAILED(hr)) {
FreeBlob(pbResponse);
}
return hr;
}
//
//
//
HRESULT RILDrv_SendSimCmd(DWORD dwParam, const BYTE* lpbCommand, DWORD dwSize)
{
FUNCTION_TRACE(RILDrv_SendSimCmd);
#if defined(OEM1_DRIVER)
// HW-SPECIFIC: WaveCom does not support AT+CSIM
DEBUGCHK(NULL != lpbCommand);
DEBUGCHK(0 != dwSize);
LPSTR szCmd = NULL;
char szPrefix[MAX_PATH];
HRESULT hr = S_OK;
CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
if (!pHandle || !lpbCommand) {
hr = E_FAIL;
goto Error;
}
// Add "AT+CSIM=<length>," to prefix string
(void)_snprintfz(szPrefix, MAX_PATH, "AT+CSIM=%u,", dwSize * 2);
// Add "<prefix>\"<command>\"<CR>"
// NOTE: we take ownership of allocated szCmd
if (!ComposeCmdWithByteArray(szPrefix, lpbCommand, dwSize, "\r", szCmd)) {
hr = E_OUTOFMEMORY;
goto Error;
}
if (!QueueCmd(pHandle, szCmd, CMDOPT_NONE | CMDOPT_SUPPRESSLOGGING, APIID_SENDSIMCMD, ParseSendSimCmd, NULL, hr)) {
hr = E_FAIL;
goto Error;
}
Error:
delete szCmd;
#else // defined(OEM1_DRIVER)
HRESULT hr = E_NOTIMPL;
#endif // defined(OEM1_DRIVER)
return hr;
}
//
//
//
HRESULT ParseATRInfo(LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
FUNCTION_TRACE(ParseATRInfo);
HRESULT hr = S_OK;
RILATRINFO* pATRInfo = NULL;
UINT uiPhase;
UINT uiCurATRChar;
UINT cbATRString;
UINT cbATRData;
LPSTR szATRString = NULL;
LPSTR pchATRStringWalk;
BYTE* pbATRDataWalk;
// Check parameters
if (NULL == szRsp)
{
DEBUGCHK(FALSE);
return E_INVALIDARG;
}
// Initialize output parameters
pBlob = NULL;
cbBlob = 0;
pATRInfo = (RILATRINFO*)AllocBlob(sizeof(RILATRINFO));
if (NULL == pATRInfo)
{
DEBUGCHK(FALSE);
hr = E_OUTOFMEMORY;
goto Error;
}
memset(pATRInfo, 0, sizeof(RILATRINFO));
pATRInfo->cbSize = sizeof(RILATRINFO);
// Parse "<prefix>%ATR: <Phase>,<ATR>"
// We take ownership of szATRString and are responsible for freeing the memory.
if (!ParseRspPrefix(szRsp, szRsp) ||
!MatchStringBeginning(szRsp, "%ATR: ", szRsp) ||
!ParseHexUInt(szRsp, TRUE, uiPhase, szRsp) ||
!MatchStringBeginning(szRsp, ",", szRsp) ||
!ParseUnlimitedUnquotedString(szRsp, '\r', szATRString, cbATRString, szRsp)) {
hr = E_FAIL;
goto Error;
}
// Assert that the data we received is an even length.
DEBUGCHK(0 == (cbATRString-1) % 2);
cbATRData = (cbATRString-1) / 2;
pchATRStringWalk = szATRString;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -