Search in sources :

Example 1 with CdmaSmsSubaddress

use of com.android.internal.telephony.cdma.sms.CdmaSmsSubaddress in project XobotOS by xamarin.

the class SmsMessage method newFromParcel.

/**
     *  Create a "raw" CDMA SmsMessage from a Parcel that was forged in ril.cpp.
     *  Note: Only primitive fields are set.
     */
public static SmsMessage newFromParcel(Parcel p) {
    // Note: Parcel.readByte actually reads one Int and masks to byte
    SmsMessage msg = new SmsMessage();
    SmsEnvelope env = new SmsEnvelope();
    CdmaSmsAddress addr = new CdmaSmsAddress();
    CdmaSmsSubaddress subaddr = new CdmaSmsSubaddress();
    byte[] data;
    byte count;
    int countInt;
    int addressDigitMode;
    //currently not supported by the modem-lib: env.mMessageType
    //p_cur->uTeleserviceID
    env.teleService = p.readInt();
    if (0 != p.readByte()) {
        //p_cur->bIsServicePresent
        env.messageType = SmsEnvelope.MESSAGE_TYPE_BROADCAST;
    } else {
        if (SmsEnvelope.TELESERVICE_NOT_SET == env.teleService) {
            // assume type ACK
            env.messageType = SmsEnvelope.MESSAGE_TYPE_ACKNOWLEDGE;
        } else {
            env.messageType = SmsEnvelope.MESSAGE_TYPE_POINT_TO_POINT;
        }
    }
    //p_cur->uServicecategory
    env.serviceCategory = p.readInt();
    // address
    addressDigitMode = p.readInt();
    //p_cur->sAddress.digit_mode
    addr.digitMode = (byte) (0xFF & addressDigitMode);
    //p_cur->sAddress.number_mode
    addr.numberMode = (byte) (0xFF & p.readInt());
    //p_cur->sAddress.number_type
    addr.ton = p.readInt();
    //p_cur->sAddress.number_plan
    addr.numberPlan = (byte) (0xFF & p.readInt());
    //p_cur->sAddress.number_of_digits
    count = p.readByte();
    addr.numberOfDigits = count;
    data = new byte[count];
    //p_cur->sAddress.digits[digitCount]
    for (int index = 0; index < count; index++) {
        data[index] = p.readByte();
        // convert the value if it is 4-bit DTMF to 8 bit
        if (addressDigitMode == CdmaSmsAddress.DIGIT_MODE_4BIT_DTMF) {
            data[index] = msg.convertDtmfToAscii(data[index]);
        }
    }
    addr.origBytes = data;
    // p_cur->sSubAddress.subaddressType
    subaddr.type = p.readInt();
    // p_cur->sSubAddress.odd
    subaddr.odd = p.readByte();
    // p_cur->sSubAddress.number_of_digits
    count = p.readByte();
    if (count < 0) {
        count = 0;
    }
    // p_cur->sSubAddress.digits[digitCount] :
    data = new byte[count];
    for (int index = 0; index < count; ++index) {
        data[index] = p.readByte();
    }
    subaddr.origBytes = data;
    /* currently not supported by the modem-lib:
            env.bearerReply
            env.replySeqNo
            env.errorClass
            env.causeCode
        */
    // bearer data
    //p_cur->uBearerDataLen
    countInt = p.readInt();
    if (countInt > 0) {
        data = new byte[countInt];
        //p_cur->aBearerData[digitCount] :
        for (int index = 0; index < countInt; index++) {
            data[index] = p.readByte();
        }
        env.bearerData = data;
    // BD gets further decoded when accessed in SMSDispatcher
    }
    // link the the filled objects to the SMS
    env.origAddress = addr;
    env.origSubaddress = subaddr;
    msg.originatingAddress = addr;
    msg.mEnvelope = env;
    // create byte stream representation for transportation through the layers.
    msg.createPdu();
    return msg;
}
Also used : CdmaSmsSubaddress(com.android.internal.telephony.cdma.sms.CdmaSmsSubaddress) SmsEnvelope(com.android.internal.telephony.cdma.sms.SmsEnvelope) CdmaSmsAddress(com.android.internal.telephony.cdma.sms.CdmaSmsAddress)

Example 2 with CdmaSmsSubaddress

use of com.android.internal.telephony.cdma.sms.CdmaSmsSubaddress 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();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CdmaSmsSubaddress(com.android.internal.telephony.cdma.sms.CdmaSmsSubaddress) DataInputStream(java.io.DataInputStream) SmsEnvelope(com.android.internal.telephony.cdma.sms.SmsEnvelope) BitwiseInputStream(com.android.internal.util.BitwiseInputStream) IOException(java.io.IOException) CdmaSmsAddress(com.android.internal.telephony.cdma.sms.CdmaSmsAddress)

Aggregations

CdmaSmsAddress (com.android.internal.telephony.cdma.sms.CdmaSmsAddress)2 CdmaSmsSubaddress (com.android.internal.telephony.cdma.sms.CdmaSmsSubaddress)2 SmsEnvelope (com.android.internal.telephony.cdma.sms.SmsEnvelope)2 BitwiseInputStream (com.android.internal.util.BitwiseInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1