use of com.android.internal.util.BitwiseInputStream in project XobotOS by xamarin.
the class SmsMessage method parsePduFromEfRecord.
/**
* Decodes 3GPP2 sms stored in CSIM/RUIM cards As per 3GPP2 C.S0015-0
*/
private void parsePduFromEfRecord(byte[] pdu) {
ByteArrayInputStream bais = new ByteArrayInputStream(pdu);
DataInputStream dis = new DataInputStream(bais);
SmsEnvelope env = new SmsEnvelope();
CdmaSmsAddress addr = new CdmaSmsAddress();
CdmaSmsSubaddress subAddr = new CdmaSmsSubaddress();
try {
env.messageType = dis.readByte();
while (dis.available() > 0) {
int parameterId = dis.readByte();
int parameterLen = dis.readByte();
byte[] parameterData = new byte[parameterLen];
switch(parameterId) {
case TELESERVICE_IDENTIFIER:
/*
* 16 bit parameter that identifies which upper layer
* service access point is sending or should receive
* this message
*/
env.teleService = dis.readUnsignedShort();
Log.i(LOG_TAG, "teleservice = " + env.teleService);
break;
case SERVICE_CATEGORY:
/*
* 16 bit parameter that identifies type of service as
* in 3GPP2 C.S0015-0 Table 3.4.3.2-1
*/
env.serviceCategory = dis.readUnsignedShort();
break;
case ORIGINATING_ADDRESS:
case DESTINATION_ADDRESS:
dis.read(parameterData, 0, parameterLen);
BitwiseInputStream addrBis = new BitwiseInputStream(parameterData);
addr.digitMode = addrBis.read(1);
addr.numberMode = addrBis.read(1);
int numberType = 0;
if (addr.digitMode == CdmaSmsAddress.DIGIT_MODE_8BIT_CHAR) {
numberType = addrBis.read(3);
addr.ton = numberType;
if (addr.numberMode == CdmaSmsAddress.NUMBER_MODE_NOT_DATA_NETWORK)
addr.numberPlan = addrBis.read(4);
}
addr.numberOfDigits = addrBis.read(8);
byte[] data = new byte[addr.numberOfDigits];
byte b = 0x00;
if (addr.digitMode == CdmaSmsAddress.DIGIT_MODE_4BIT_DTMF) {
/* As per 3GPP2 C.S0005-0 Table 2.7.1.3.2.4-4 */
for (int index = 0; index < addr.numberOfDigits; index++) {
b = (byte) (0xF & addrBis.read(4));
// convert the value if it is 4-bit DTMF to 8
// bit
data[index] = convertDtmfToAscii(b);
}
} else if (addr.digitMode == CdmaSmsAddress.DIGIT_MODE_8BIT_CHAR) {
if (addr.numberMode == CdmaSmsAddress.NUMBER_MODE_NOT_DATA_NETWORK) {
for (int index = 0; index < addr.numberOfDigits; index++) {
b = (byte) (0xFF & addrBis.read(8));
data[index] = b;
}
} else if (addr.numberMode == CdmaSmsAddress.NUMBER_MODE_DATA_NETWORK) {
if (numberType == 2)
Log.e(LOG_TAG, "TODO: Originating Addr is email id");
else
Log.e(LOG_TAG, "TODO: Originating Addr is data network address");
} else {
Log.e(LOG_TAG, "Originating Addr is of incorrect type");
}
} else {
Log.e(LOG_TAG, "Incorrect Digit mode");
}
addr.origBytes = data;
Log.i(LOG_TAG, "Originating Addr=" + addr.toString());
break;
case ORIGINATING_SUB_ADDRESS:
case DESTINATION_SUB_ADDRESS:
dis.read(parameterData, 0, parameterLen);
BitwiseInputStream subAddrBis = new BitwiseInputStream(parameterData);
subAddr.type = subAddrBis.read(3);
subAddr.odd = subAddrBis.readByteArray(1)[0];
int subAddrLen = subAddrBis.read(8);
byte[] subdata = new byte[subAddrLen];
for (int index = 0; index < subAddrLen; index++) {
b = (byte) (0xFF & subAddrBis.read(4));
// convert the value if it is 4-bit DTMF to 8 bit
subdata[index] = convertDtmfToAscii(b);
}
subAddr.origBytes = subdata;
break;
case BEARER_REPLY_OPTION:
dis.read(parameterData, 0, parameterLen);
BitwiseInputStream replyOptBis = new BitwiseInputStream(parameterData);
env.bearerReply = replyOptBis.read(6);
break;
case CAUSE_CODES:
dis.read(parameterData, 0, parameterLen);
BitwiseInputStream ccBis = new BitwiseInputStream(parameterData);
env.replySeqNo = ccBis.readByteArray(6)[0];
env.errorClass = ccBis.readByteArray(2)[0];
if (env.errorClass != 0x00)
env.causeCode = ccBis.readByteArray(8)[0];
break;
case BEARER_DATA:
dis.read(parameterData, 0, parameterLen);
env.bearerData = parameterData;
break;
default:
throw new Exception("unsupported parameterId (" + parameterId + ")");
}
}
bais.close();
dis.close();
} catch (Exception ex) {
Log.e(LOG_TAG, "parsePduFromEfRecord: conversion from pdu to SmsMessage failed" + ex);
}
// link the filled objects to this SMS
originatingAddress = addr;
env.origAddress = addr;
env.origSubaddress = subAddr;
mEnvelope = env;
mPdu = pdu;
parseSms();
}
use of com.android.internal.util.BitwiseInputStream in project XobotOS by xamarin.
the class BearerData method decodeIs91Cli.
/**
* IS-91 CLI message (callback number) decoding
* (See 3GPP2 C.S0015-A, Table 4.3.1.4.1-1)
*
* Protocol Summary: The data payload may contain 1-32 digits,
* encoded using standard 4-bit DTMF, which are treated as a
* callback number.
*/
private static void decodeIs91Cli(BearerData bData) throws CodingException {
BitwiseInputStream inStream = new BitwiseInputStream(bData.userData.payload);
// 4-bit packed DTMF digit encoding.
int dataLen = inStream.available() / 4;
int numFields = bData.userData.numFields;
if ((dataLen > 14) || (dataLen < 3) || (dataLen < numFields)) {
throw new CodingException("IS-91 voicemail status decoding failed");
}
CdmaSmsAddress addr = new CdmaSmsAddress();
addr.digitMode = CdmaSmsAddress.DIGIT_MODE_4BIT_DTMF;
addr.origBytes = bData.userData.payload;
addr.numberOfDigits = (byte) numFields;
decodeSmsAddress(addr);
bData.callbackNumber = addr;
}
use of com.android.internal.util.BitwiseInputStream in project android_frameworks_base by DirtyUnicorns.
the class BitwiseStreamsTest method testThree.
@SmallTest
public void testThree() throws Exception {
int offset = 4;
byte[] inBuf = HexDump.hexStringToByteArray("00031040900112488ea794e0");
BitwiseOutputStream outStream = new BitwiseOutputStream(30);
outStream.skip(offset);
for (int i = 0; i < inBuf.length; i++) outStream.write(8, inBuf[i]);
BitwiseInputStream inStream = new BitwiseInputStream(outStream.toByteArray());
inStream.skip(offset);
byte[] inBufDup = new byte[inBuf.length];
for (int i = 0; i < inBufDup.length; i++) inBufDup[i] = (byte) inStream.read(8);
assertEquals(HexDump.toHexString(inBuf), HexDump.toHexString(inBufDup));
}
use of com.android.internal.util.BitwiseInputStream in project android_frameworks_base by DirtyUnicorns.
the class BitwiseStreamsTest method testOne.
@SmallTest
public void testOne() throws Exception {
int offset = 3;
byte[] inBuf = HexDump.hexStringToByteArray("FFDD");
BitwiseOutputStream outStream = new BitwiseOutputStream(30);
outStream.skip(offset);
for (int i = 0; i < inBuf.length; i++) outStream.write(8, inBuf[i]);
byte[] outBuf = outStream.toByteArray();
BitwiseInputStream inStream = new BitwiseInputStream(outBuf);
byte[] inBufDup = new byte[inBuf.length];
inStream.skip(offset);
for (int i = 0; i < inBufDup.length; i++) inBufDup[i] = (byte) inStream.read(8);
assertEquals(HexDump.toHexString(inBuf), HexDump.toHexString(inBufDup));
}
use of com.android.internal.util.BitwiseInputStream in project android_frameworks_base by AOSPA.
the class BitwiseStreamsTest method testTwo.
@SmallTest
public void testTwo() throws Exception {
int offset = 3;
byte[] inBuf = HexDump.hexStringToByteArray("11d4f29c0e9ad3c36e72584e064d9b53");
BitwiseOutputStream outStream = new BitwiseOutputStream(30);
outStream.skip(offset);
for (int i = 0; i < inBuf.length; i++) outStream.write(8, inBuf[i]);
BitwiseInputStream inStream = new BitwiseInputStream(outStream.toByteArray());
inStream.skip(offset);
byte[] inBufDup = new byte[inBuf.length];
for (int i = 0; i < inBufDup.length; i++) inBufDup[i] = (byte) inStream.read(8);
assertEquals(HexDump.toHexString(inBuf), HexDump.toHexString(inBufDup));
}
Aggregations