📄 misc.cpp
字号:
// Set the file ID in the last two bytes, please
rgbSelect[4] = (BYTE) ((dwFileID & 0xff00) >> 8);
rgbSelect[5] = (BYTE) (dwFileID & 0x00ff);
// 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, rgbSelect, dwSize, "\r", szCmd)) {
hr = E_OUTOFMEMORY;
goto Error;
}
if (!QueueCmd(pHandle, szCmd, CMDOPT_NONE, APIID_GETSIMRECORDSTATUS, ParseGetSimRecordStatus, NULL, hr)) {
hr = E_FAIL;
goto Error;
}
Error:
delete szCmd;
#else // OEM1_DRIVER || OEM2_DRIVER
HRESULT hr = E_NOTIMPL;
#endif // OEM1_DRIVER || OEM2_DRIVER
return hr;
}
//
//
//
static HRESULT ParseGetSimToolkitProfile(LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
FUNCTION_TRACE(ParseGetSimToolkitProfile);
UINT i;
UINT nValue;
UINT cbProfileString;
LPSTR szProfileString = NULL;
LPSTR pchProfileStringWalk;
UINT cbProfile;
BYTE* pbProfileWalk;
BYTE* pbProfile = NULL;
HRESULT hr = S_OK;
pBlob = NULL;
cbBlob = 0;
// Parse "<prefix>%SATC: <mode>,"
// for EMP the response is "<prefix>*STKC: <n>,<StkPrfl>"
if (!ParseRspPrefix(szRsp, szRsp) ||
#ifdef EMP_DRIVER
!MatchStringBeginning(szRsp, "*STKC: ", szRsp) ||
#elif defined (PHILIP_DRIVER)
!MatchStringBeginning(szRsp, "+PPSTAC: ", szRsp) ||
#else
!MatchStringBeginning(szRsp, "%SATC: ", szRsp) ||
#endif
!ParseUInt(szRsp, TRUE, nValue, szRsp) ||
!MatchStringBeginning(szRsp, ",", szRsp)) {
hr = E_FAIL;
goto Error;
}
// Parse "<profile>"
// NOTE: we take ownership of allocated szProfileString
#if defined(EMP_DRIVER) || defined(PHILIP_DRIVER)
// <profile> is a quoted string in EMP
if (!ParseUnlimitedString(szRsp, szProfileString, cbProfileString, szRsp)) {
#else
if (!ParseUnlimitedUnquotedString(szRsp, '\r', szProfileString, cbProfileString, szRsp)) {
#endif
hr = E_FAIL;
goto Error;
}
DEBUGCHK(0 == (cbProfileString - 1) % 2);
cbProfile = (cbProfileString - 1) / 2;
// Allocate the byte array of needed size
pbProfile = (BYTE*)AllocBlob(cbProfile);
if (!pbProfile) {
hr = E_OUTOFMEMORY;
goto Error;
}
// Decode the profile
pbProfileWalk = pbProfile;
pchProfileStringWalk = szProfileString;
for (i = 0; i < cbProfile; i++) {
*pbProfileWalk = SemiByteCharsToByte(*pchProfileStringWalk, *(pchProfileStringWalk + 1));
pbProfileWalk++;
pchProfileStringWalk += 2;
}
// Parse "<postfix>"
if (!ParseRspPostfix(szRsp, szRsp)) {
hr = E_FAIL;
goto Error;
}
pBlob = (void*)pbProfile;
cbBlob = cbProfile;
Error:
if (FAILED(hr)) {
FreeBlob(pbProfile);
}
delete[] szProfileString;
return hr;
}
//
//
//
HRESULT RILDrv_GetSimToolkitProfile(DWORD dwParam)
{
HRESULT hr = S_OK;
FUNCTION_TRACE(RILDrv_GetSimToolkitProfile);
#if (defined(RIL_ENABLE_SIMTK) && defined(OEM1_DRIVER)) || defined(EMP_DRIVER)
// HW-SPECIFIC: This uses a OEM1-specific AT%SATC command or a EMP-specific *STKC command
CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
if (!pHandle) {
hr = E_FAIL;
goto Error;
}
#ifdef EMP_DRIVER
if (!QueueCmd(pHandle, "AT*STKC?\r", CMDOPT_NONE, APIID_GETSIMTOOLKITPROFILE, ParseGetSimToolkitProfile, NULL, hr)) {
//#elif defined (PHILIP_DRIVER)
// if (!QueueCmd(pHandle, "AT+PPSTAC?\r", CMDOPT_NONE, APIID_GETSIMTOOLKITPROFILE, ParseGetSimToolkitProfile, NULL, hr)) {
#else
if (!QueueCmd(pHandle, "AT%SATC?\r", CMDOPT_NONE, APIID_GETSIMTOOLKITPROFILE, ParseGetSimToolkitProfile, NULL, hr)) {
#endif
hr = E_FAIL;
goto Error;
}
#elif defined(PHILIP_DRIVER)
CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
if (pHandle) {
return pHandle->GetDevice()->GetSimToolkit()->GetProfile(pHandle);
}
return E_FAIL;
#else
hr = E_NOTIMPL;
Error:
#endif
return hr;
}
//
//
//
HRESULT RILDrv_SetSimToolkitProfile(DWORD dwParam, const BYTE* lpbProfile, DWORD dwSize)
{
HRESULT hr = S_OK;
FUNCTION_TRACE(RILDrv_SetSimToolkitProfile);
#if (defined(RIL_ENABLE_SIMTK) && defined(OEM1_DRIVER)) || defined(OEM2_SIMTOOLKIT) || defined(EMP_DRIVER)
//|| defined (PHILIP_DRIVER)
// HW-SPECIFIC: This uses a OEM1-specific AT%SATC command
DEBUGCHK(NULL != lpbProfile);
DEBUGCHK(0 != dwSize);
CHAR szPrefix[MAX_PATH];
CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
if (!pHandle || !lpbProfile) {
hr = E_FAIL;
goto Error;
}
// Store terminal profile
if (!g_RilSTKTerminalProfile.SetByte((const LPBYTE)lpbProfile, dwSize))
{
hr = E_FAIL;
goto Error;
}
#if defined(OEM2_SIMTOOLKIT)
_snprintfz(szPrefix, ARRAY_LENGTH(szPrefix),"AT+STPD=%d,%s\r", g_RilSTKTerminalProfile.GetSize(), g_RilSTKTerminalProfile.GetText());
#elif defined(EMP_DRIVER)
// EMP uses *STKC to set SIM toolkit profile and the <profile> is a quoted string
_snprintfz(szPrefix, ARRAY_LENGTH(szPrefix),"AT*STKC=1,\"%s\"\r", g_RilSTKTerminalProfile.GetText());
#elif defined (PHILIP_DRIVER)
_snprintfz(szPrefix, ARRAY_LENGTH(szPrefix),"AT+PPSTAC=,\"%s\"\r", g_RilSTKTerminalProfile.GetText());
#else
_snprintfz(szPrefix, ARRAY_LENGTH(szPrefix),"AT%%SATC=1,%s;+CFUN=1\r", g_RilSTKTerminalProfile.GetText());
#endif
if (!QueueCmd(pHandle, szPrefix, CMDOPT_NONE, APIID_SETSIMTOOLKITPROFILE, NULL, NULL, hr)) {
hr = E_FAIL;
goto Error;
}
#elif defined (PHILIP_DRIVER)
CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
if (pHandle) {
return pHandle->GetDevice()->GetSimToolkit()->SetProfile(pHandle);
}
return E_FAIL;
#else // OEM1_DRIVER
Error:
hr = E_NOTIMPL;
#endif // OEM1_DRIVER
return hr;
}
//
//
//
static HRESULT ParseSendSimToolkitEnvelopeCmd(LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
FUNCTION_TRACE(ParseSendSimToolkitEnvelopeCmd);
UINT i;
UINT cbResponseString;
LPSTR szResponseString = NULL;
LPSTR pchResponseStringWalk;
UINT cbResponse;
BYTE* pbResponseWalk;
BYTE* pbResponse = NULL;
HRESULT hr = S_OK;
pBlob = NULL;
cbBlob = 0;
// Parse "<prefix>%SATE: "
// On EMP platform the format is "<prefix>*STKE"
if (!ParseRspPrefix(szRsp, szRsp) ||
#ifdef EMP_DRIVER
!MatchStringBeginning(szRsp, "*STKE: ", szRsp)) {
#else
!MatchStringBeginning(szRsp, "%SATE: ", szRsp)) {
#endif
hr = E_FAIL;
goto Error;
}
// Parse "<response>"
// NOTE: we take ownership of allocated szResponseString
#ifdef EMP_DRIVER
if (!ParseUnlimitedString(szRsp, szResponseString, cbResponseString, szRsp)) {
#else
if (!ParseUnlimitedUnquotedString(szRsp, '\r', szResponseString, cbResponseString, szRsp)) {
#endif
hr = E_FAIL;
goto Error;
}
DEBUGCHK(0 == (cbResponseString - 1) % 2);
cbResponse = (cbResponseString - 1) / 2;
// Allocate the byte array of needed size
pbResponse = (BYTE*)AllocBlob(cbResponse);
if (!pbResponse) {
hr = E_OUTOFMEMORY;
goto Error;
}
// Decode the response
pbResponseWalk = pbResponse;
pchResponseStringWalk = szResponseString;
for (i = 0; i < cbResponse; i++) {
*pbResponseWalk = SemiByteCharsToByte(*pchResponseStringWalk, *(pchResponseStringWalk + 1));
pbResponseWalk++;
pchResponseStringWalk += 2;
}
// Parse "<postfix>"
if (!ParseRspPostfix(szRsp, szRsp)) {
hr = E_FAIL;
goto Error;
}
pBlob = (void*)pbResponse;
cbBlob = cbResponse;
Error:
if (FAILED(hr)) {
FreeBlob(pbResponse);
}
delete[] szResponseString;
return hr;
}
//
//
//
HRESULT RILDrv_SendSimToolkitEnvelopeCmd(DWORD dwParam, const BYTE* lpbCommand, DWORD dwSize) //Selet menu
{
FUNCTION_TRACE(RILDrv_SendSimToolkitEnvelopeCmd);
#if defined(RIL_ENABLE_SIMTK) && defined(OEM1_DRIVER) && !defined(OEM2_SIMTOOLKIT) || defined(EMP_DRIVER)
// HW-SPECIFIC: This uses a OEM1-specific AT%SATE command
DEBUGCHK(NULL != lpbCommand);
DEBUGCHK(0 != dwSize);
LPSTR szCmd = NULL;
HRESULT hr = S_OK;
CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
if (!pHandle || !lpbCommand) {
hr = E_FAIL;
goto Error;
}
// Add "AT%SATE=<command><CR>"
// NOTE: we take ownership of allocated szCmd
#ifdef EMP_DRIVER
// EMP uses *STKE to send a command
// note that ComposeCmdWithByteArray is modified to add quotes to the string
if (!ComposeCmdWithByteArray("AT*STKE=", lpbCommand, dwSize, "\r", szCmd)) {
#else
if (!ComposeCmdWithByteArray("AT%SATE=", lpbCommand, dwSize, "\r", szCmd)) {
#endif
hr = E_OUTOFMEMORY;
goto Error;
}
if (!QueueCmd(pHandle, szCmd, CMDOPT_NONE, APIID_SENDSIMTOOLKITENVELOPECMD, ParseSendSimToolkitEnvelopeCmd,
NULL, hr)) {
hr = E_FAIL;
goto Error;
}
Error:
delete szCmd;
#elif defined(OEM2_SIMTOOLKIT)
// For OEM2, we really aren't sending a Envelope command, since OEM2 does
// not have such a command. However, the RILDrv_SendSimToolkitEnvelopeCmd
// call is used exclusively to select a menu item from the main menu.
// To maintain API compatibility RILDrv_SendSimToolkitEnvelopeCmd will
// send the OEM2 Menu Selection command +STMS.
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+STMS=%s\r", lpbCommand);
if (!QueueCmd(pHandle, szCmd, CMDOPT_NONE, APIID_SENDSIMTOOLKITENVELOPECMD, NULL, NULL, hr)) {
hr = E_FAIL;
goto Error;
}
#elif defined (PHILIP_DRIVER)
char szCmd[MAX_PATH];
HRESULT hr = S_OK;
CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
if (!pHandle) {
hr = E_FAIL;
goto Error;
}
RILRetailTrace((TEXT("+RILDrv_SendSimToolkitEnvelopeCmd()\r\n")));
if(*lpbCommand == MENUSELECTTAG) // MENUSELECTTAG=0xD3
{
int nSelectedItem=*(lpbCommand+dwSize-1);
(void)_snprintfz(szCmd, MAX_PATH, "AT+PPSTUR=37,255,%d\r", nSelectedItem);
if (!QueueCmd(pHandle, szCmd, CMDOPT_NONE, APIID_SENDSIMTOOLKITENVELOPECMD, NULL, NULL, hr)) {
hr = E_FAIL;
goto Error;
}
}
else
HRESULT hr = E_NOTIMPL;
Error:
#else // OEM1_DRIVER
HRESULT hr = E_NOTIMPL;
#endif // OEM1_DRIVER
return hr;
}
//
//
//
//
HRESULT RILDrv_SendSimToolkitCmdResponse(DWORD dwParam, const RILSIMTOOLKITRSP* pRsp, LPBYTE pDetails, const DWORD dwDetailSize)
{
FUNCTION_TRACE(RILDrv_SendSimToolkitCmdResponse);
#if defined(OEM1_DRIVER) || defined(OEM2_SIMTOOLKIT) || defined(EMP_DRIVER)
LPSTR szCmd = NULL;
LPSTR szCmdPrefix = NULL;
LPSTR szCmdSuffix = NULL;
LPSTR szResponse = NULL;
DWORD dwSize = 0;
DWORD dwCmdSize = 0;
CRilSimToolkitResponse crstrRsp;
CRilInstanceHandle* pHandle;
HRESULT hr = S_OK;
pHandle = ExtractHandle(dwParam);
DEBUGCHK(NULL != pRsp);
DEBUGCHK(NULL != pHandle);
if (!pHandle || !pRsp) {
hr = E_FAIL;
goto Error;
}
// Check for needed values in the response parameter. We need to command
// type to determine the correct AT command to send to the radio.
if (!(RIL_PARAM_SIMTKIT_RSP_TYPE & pRsp->dwParams)) {
DEBUGCHK(FALSE);
hr = E_FAIL;
goto Error;
}
// Create a radio formatted response. The CRilSimToolkitResponse class
// will automatically parse the command appropriately for specific radio.
hr = crstrRsp.CreateResponse(pRsp, pDetails, dwDetailSize, &szResponse, &dwSize);
if (FAILED(hr)) {
DEBUGCHK(FALSE);
goto Error;
}
else if(0 >= dwSize) {
// CreateResponse did not create a response for this command,
// which is acceptable. Don't send anything to the radio
// if a response was not created.
hr = E_FAIL;
goto Error;
}
// Setup the AT command prefix and suffix according to what radio we are using.
// We send out a different command for Setup Menu replies.
#if defined(OEM2_SIMTOOLKIT)
if (SIM_NOTIFY_SETUPMENU_REPLY == pRsp->dwType) {
szCmdPrefix = "AT+STMS=";
}
else {
szCmdPrefix = "AT+STCR=";
}
#elif defined(OEM1_DRIVER)
// For newer OEM1 stacks the SIM toolkit envelope and response command can have quotes
// (but are not required) around the data portion of the response. Although, having
// quotes around the data is a more proper form, we do not add them at this time to
// remain as compatible as possible with older stacks.
if (SIM_NOTIFY_SETUPMENU_REPLY == pRsp->dwType) {
szCmdPrefix = "AT%SATE=";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -