📄 rilsimtkitbyte.cpp
字号:
wszText = NULL;
if (NULL != pText)
{
// Details exist. If text does not exist in the details, then
// there is no text string.
if ( (RIL_PARAM_SIMTKIT_RSP_DETAILS_TEXT_TEXTOFFSET & pText->dwParams) &&
(RIL_PARAM_SIMTKIT_RSP_DETAILS_TEXT_TEXTSIZE & pText->dwParams) )
{
// Some text exists.
dwTextSize = pText->dwTextSize;
if (0 != dwTextSize)
{
wszText = (LPWSTR) ((LPBYTE)pText + pText->dwTextOffset);
// Set the encoding method if specified.
if (RIL_PARAM_SIMTKIT_RSP_DETAILS_TEXT_DCS & pText->dwParams)
{
bEncode = (BYTE) pText->dwDCS;
}
}
}
}
if (NULL == wszText)
{
// Yes, this is valid -- set length to 0
*(lpb++) = 0x00;
}
else
{
BYTE rgbText[255];
UINT uiLen, uiSpaceLeft;
// Now, convert this, please -- how much space is left in this array? Remember, we can
// only send down 255 bytes. I'm assuming that if text is set, nothing else is (e.g. this
// is the last thing in the response). Also subtract a byte for the encoding scheme and
// a byte for the length (actually 2 for the length if it's more than 0x80)
uiLen = lstrlen(wszText);
uiSpaceLeft = *pdwDataRspSize - (lpb - pbDataRsp) - 2;
if (uiSpaceLeft >= 0x80)
{
// It will take 2 bytes for the length in this case
uiSpaceLeft--;
}
if (bEncode == SIMTKIT_TEXT_ENCODING_UCS2)
{
ConvertUnicodeToUCS2(wszText, uiLen, (const LPSTR) rgbText, uiSpaceLeft, uiLen);
}
else if (bEncode == SIMTKIT_TEXT_ENCODING_UNPACKED)
{
ConvertUnicodeToUnpackedGSM(wszText, uiLen, (const LPSTR) rgbText, uiSpaceLeft, uiLen);
}
else
{
ASSERT(bEncode == SIMTKIT_TEXT_ENCODING_PACKED);
ConvertUnicodeToGSM(wszText, uiLen, (const LPSTR) rgbText, uiSpaceLeft, uiLen, TRUE);
}
// Add one to the length (to take into account the encoding byte)
uiLen++;
// OK, now set the length
// If the length is over 0x80, we need to encode it in two bytes,
// otherwise, we can just encode it in one byte
if (uiLen < 0x80)
{
*(lpb++) = (BYTE) uiLen;
}
else
{
// Make the next byte 0x81
*(lpb++) = 0x81;
*(lpb++) = (BYTE) uiLen;
}
// Set the data coding scheme
*(lpb++) = bEncode;
// And copy over the text string
if ( *pdwDataRspSize - (lpb - pbDataRsp) >= uiLen - 1 )
{
memcpy(lpb, rgbText, uiLen - 1);
lpb += (uiLen - 1);
}
else
{
DEBUGMSG( ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Optional text string copy failed due to insufficient buffer space\r\n")) );
DEBUGCHK( FALSE );
hr = E_FAIL;
goto Exit;
}
}
}
// Optional item identifier
if (fCmdDataNeeded && (SIM_NOTIFY_SELECTITEM == pRsp->dwType))
{
SIMTKITRSPITEM* pItem = (SIMTKITRSPITEM*)pDetails;
// Check to make sure there is are item details.
if (NULL == pItem)
{
DEBUGCHK(FALSE);
hr = E_INVALIDARG;
goto Exit;
}
// Make sure the proper information is available in the details
if ( !(RIL_PARAM_SIMTKIT_RSP_DETAILS_ITEM_ID & pItem->dwParams) )
{
DEBUGCHK(FALSE);
hr = E_INVALIDARG;
goto Exit;
}
// Easy
*(lpb++) = ITEMIDTAG; // Tag
*(lpb++) = 0x01; // Length
*(lpb++) = (BYTE) pItem->dwId; // Item ID
}
// Optional local information
if (fCmdDataNeeded && (SIM_NOTIFY_LOCALINFO == pRsp->dwType))
{
BYTE rgbDigit[15];
LPSIMLOCALINFO psli;
// Local info detailed information is needed.
if (NULL == pDetails)
{
DEBUGCHK(FALSE);
hr = E_INVALIDARG;
goto Exit;
}
psli = (SIMLOCALINFO*) pDetails;
if ((psli->dwParams & SIM_PARAM_SIMLOCALINFO_CELLID) &&
(psli->dwParams & SIM_PARAM_SIMLOCALINFO_LAC) &&
(psli->dwParams & SIM_PARAM_SIMLOCALINFO_NUMNAME))
{
// Location information
*(lpb++) = LOCINFOTAG; // Tag
*(lpb++) = 0x07; // Length
// For this to be a valid name, it needs to have exactly 5 characters, and they
// all need to be a single hexadecimal character
hr = StringToByteArray(psli->lpszNumName, rgbDigit, 5);
if (FAILED(hr))
{
DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Location Information called with invalid name\r\n")));
goto Exit;
}
// Copy over the bytes of MCC and MNC from the name (see GSM 04.08, 10.5.1.3)
// First byte -- first two characters (note these are in reverse order, second
// character is the high half-byte), second byte is third character with 0xf0 in
// the high bits, third byte is fourth and fifth characters
*(lpb++) = (BYTE) (rgbDigit[0] + (rgbDigit[1] << 4));
*(lpb++) = (BYTE) (rgbDigit[2] + 0xf0);
*(lpb++) = (BYTE) (rgbDigit[3] + (rgbDigit[4] << 4));
// Copy over the LAC and the CellId
memcpy(lpb, &(psli->dwLAC), sizeof(DWORD));
lpb += sizeof(DWORD);
}
if (psli->dwParams & SIM_PARAM_SIMLOCALINFO_IMEI)
{
// IMEI
*(lpb++) = IMEITAG; // IMEI
*(lpb++) = 0x08; // Length
// Get 15 digits, please
hr = StringToByteArray(psli->lpszIMEI, rgbDigit, 15);
if (FAILED(hr))
{
DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Need 15 digits for IMEI\r\n")));
goto Exit;
}
// Set these, with the last byte getting an extra 1111
*(lpb++) = (BYTE) (rgbDigit[1] + (rgbDigit[0] << 4));
*(lpb++) = (BYTE) (rgbDigit[3] + (rgbDigit[2] << 4));
*(lpb++) = (BYTE) (rgbDigit[5] + (rgbDigit[4] << 4));
*(lpb++) = (BYTE) (rgbDigit[7] + (rgbDigit[6] << 4));
*(lpb++) = (BYTE) (rgbDigit[9] + (rgbDigit[8] << 4));
*(lpb++) = (BYTE) (rgbDigit[11] + (rgbDigit[10] << 4));
*(lpb++) = (BYTE) (rgbDigit[13] + (rgbDigit[12] << 4));
*(lpb++) = (BYTE) (0x0f + (rgbDigit[14] << 4));
}
if ((psli->dwParams & SIM_PARAM_SIMLOCALINFO_NMR) &&
(psli->dwParams & SIM_PARAM_SIMLOCALINFO_BCCH) &&
(psli->dwParams & SIM_PARAM_SIMLOCALINFO_NUMBCCH))
{
DWORD dwBCCHSize;
// NMR
*(lpb++) = NMRTAG; // NMR
*(lpb++) = MAXLEN_NMR; // Length
memcpy(lpb, psli->rgbNMR, MAXLEN_NMR);
lpb += MAXLEN_NMR;
// BCCH
// Number of BCCH must be 1-3
if ((psli->dwNumBCCH < 1) || (psli->dwNumBCCH > 3))
{
DEBUGCHK(FALSE);
DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Need 1-3 BCCHs\r\n")));
hr = E_INVALIDARG;
goto Exit;
}
*(lpb++) = BCCHTAG; // BCCH
*(lpb++) = (BYTE) (MAXLEN_BCCH * (psli->dwNumBCCH)); // Length
dwBCCHSize = MAXLEN_BCCH * (psli->dwNumBCCH);
memcpy(lpb, psli->rgbBCCH, dwBCCHSize);
lpb += dwBCCHSize;
}
}
// We don't have optional call control or result data object 2
}// else !fSetupMenuReply
// Adjust the Data response size parameter.
*pdwDataRspSize = (LPBYTE)lpb - (LPBYTE)pbDataRsp;
Exit:
return hr;
}
HRESULT CRilSimToolkitResponse::ByteEventDownload(const DWORD dwEvent, const LPBYTE pData, const DWORD dwDataSize, __inout_bcount( *pdwDataRspSize ) LPBYTE pbDataRsp, DWORD *pdwDataRspSize)
{
LPBYTE lpb;
HRESULT hr = S_OK;
// Assert parameters
DEBUGCHK(NULL != pbDataRsp);
DEBUGCHK(MAX_BYTE_RSP <= *pdwDataRspSize); // Make sure there is a enough total room in buffer now,
// so we don't have to check every step of the way.
// Check parameters
if (NULL == pbDataRsp ||
MAX_BYTE_RSP > *pdwDataRspSize)
{
DEBUGCHK(FALSE);
hr = E_INVALIDARG;
goto Exit;
}
// Initialize return buffer.
memset(pbDataRsp, 0, *pdwDataRspSize);
lpb = pbDataRsp;
// Start creation of the Event Download envelope command
*(lpb++) = EVENTDOWNLOADTAG;
// Hard coded length to 7 bytes. As more events are supported this will
// need to be dynamic.
*(lpb++) = (BYTE)0x07;
// Device identities
*(lpb++) = DEVICEIDTAG; // Device identities tag
*(lpb++) = 0x02; // Length of what follows
*(lpb++) = 0x82; // Source = Terminal
*(lpb++) = 0x81; // Destination = SIM
// Item identifier
*(lpb++) = EVENTLISTTAG; // Event list tag
*(lpb++) = 0x01; // Length of what follows
*(lpb++) = (BYTE) dwEvent; // Event that occurred.
// Adjust the Data response size parameter.
*pdwDataRspSize = (LPBYTE)lpb - (LPBYTE)pbDataRsp;
Exit:
return hr;
}
/****************************************************************************
FUNCTION: ByteParseOpenChannelCS
PURPOSE: Parses and incoming Open Channel CS command
RETURNS: HRESULT
****************************************************************************/
HRESULT CRilSimToolkitCommand::ByteParseOpenChannelCS(DWORD* pdwRetVal)
{
HRESULT hr = S_OK;
// The Open Channel CS TLV tags should be:
// Address,(Subaddress),(Duration1),(Duration2), BearerDescription,
// BufferSize,(LocalAddress),(UserLogin:Text),(UserPassword:Text),
// (InterfaceTransportLevel),(DestAddress)
// Address
if (ADDRESSTAG != (*(m_lpbParse) & 0x7f))
{
DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : SIMTKit: Mandatory TLV %x not found. Found: %x\r\n"), ADDRESSTAG, (*(m_lpbParse) & 0x7f)));
*pdwRetVal = SIM_RESPONSE_ERR_COMMANDDATA;
hr = E_FAIL;
goto Exit;
}
m_lpbParse++;
m_dwParseLen--;
hr = ReadAddress();
if (FAILED(hr))
{
DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Function for TLV %x failed\r\n"), ADDRESSTAG));
*pdwRetVal = SIM_RESPONSE_ERR_VALUESMISSING;
hr = E_FAIL;
goto Exit;
}
// (Subaddress)
if (SUBADDRTAG == (*(m_lpbParse) & 0x7f))
{
m_lpbParse++;
m_dwParseLen--;
hr = ReadSubAddress();
if (FAILED(hr))
{
DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Function for TLV %x failed\r\n"), SUBADDRTAG));
*pdwRetVal = SIM_RESPONSE_ERR_VALUESMISSING;
hr = E_FAIL;
goto Exit;
}
}
// (Duration1)
if (DURATIONTAG == (*(m_lpbParse) & 0x7f))
{
m_lpbParse++;
m_dwParseLen--;
hr = ReadDuration();
if (FAILED(hr))
{
DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Function for TLV %x failed\r\n"), DURATIONTAG));
*pdwRetVal = SIM_RESPONSE_ERR_VALUESMISSING;
hr = E_FAIL;
goto Exit;
}
}
// (Duration2)
if (DURATIONTAG == (*(m_lpbParse) & 0x7f))
{
// The ReadDuration function reads the duration into a set class variable which is currently
// set to Duration1. Save that setting to swap the results after a successful read.
DWORD dwDurationTemp = m_dwDuration;
m_lpbParse++;
m_dwParseLen--;
m_dwDuration = SIMTONE_DEFAULTDURATION;
hr = ReadDuration();
if (FAILED(hr))
{
DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Function for TLV %x failed\r\n"), DURATIONTAG));
*pdwRetVal = SIM_RESPONSE_ERR_VALUESMISSING;
hr = E_FAIL;
goto Exit;
}
else
{
// Swap duration 2 and restore duration 1.
m_dwDuration2 = m_dwDuration;
m_dwDuration = dwDurationTemp;
}
}
// Bearer description
if (BEARERDESCRIPTTAG != (*(m_lpbParse) & 0x7f))
{
DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : SIMTKit: Mandatory TLV %x not found. Found: %x\r\n"), BEARERDESCRIPTTAG, (*(m_lpbParse) & 0x7f)));
*pdwRetVal = SIM_RESPONSE_ERR_COMMANDDATA;
hr = E_FAIL;
goto Exit;
}
m_lpbParse++;
m_dwParseLen--;
hr = ReadBearerDescription();
if (FAILED(hr))
{
DEBUGMSG(ZONE_ERROR, (TEXT("RilDrv : SIMTKit: Function for TLV %x failed\r\n"), BEARERDESCRIPTTAG));
*pdwRetVal = SIM_RESPONSE_ERR_VALUESMISSING;
hr = E_FAIL;
goto Exit;
}
// Buffer Size
if (BUFFERSIZETAG != (*(m_lpbParse) & 0x7f))
{
DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : SIMTKit: Mandatory TLV %x not found. Found: %x\r\n"), BUFFERSIZETAG, (*(m_lpbParse) & 0x7f)));
*pdwRetVal = SIM_RESPONSE_ERR_COMMANDDATA;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -