Search in sources :

Example 1 with SmsEnvelope

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

the class SmsMessage method createPdu.

/**
     * Creates byte array (pseudo pdu) from SMS object.
     * Note: Do not call this method more than once per object!
     */
private void createPdu() {
    SmsEnvelope env = mEnvelope;
    CdmaSmsAddress addr = env.origAddress;
    ByteArrayOutputStream baos = new ByteArrayOutputStream(100);
    DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(baos));
    try {
        dos.writeInt(env.messageType);
        dos.writeInt(env.teleService);
        dos.writeInt(env.serviceCategory);
        dos.writeByte(addr.digitMode);
        dos.writeByte(addr.numberMode);
        dos.writeByte(addr.ton);
        dos.writeByte(addr.numberPlan);
        dos.writeByte(addr.numberOfDigits);
        // digits
        dos.write(addr.origBytes, 0, addr.origBytes.length);
        dos.writeInt(env.bearerReply);
        // CauseCode values:
        dos.writeByte(env.replySeqNo);
        dos.writeByte(env.errorClass);
        dos.writeByte(env.causeCode);
        //encoded BearerData:
        dos.writeInt(env.bearerData.length);
        dos.write(env.bearerData, 0, env.bearerData.length);
        dos.close();
        /**
             * TODO(cleanup) -- The mPdu field is managed in
             * a fragile manner, and it would be much nicer if
             * accessing the serialized representation used a less
             * fragile mechanism.  Maybe the getPdu method could
             * generate a representation if there was not yet one?
             */
        mPdu = baos.toByteArray();
    } catch (IOException ex) {
        Log.e(LOG_TAG, "createPdu: conversion from object to byte array failed: " + ex);
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) SmsEnvelope(com.android.internal.telephony.cdma.sms.SmsEnvelope) BufferedOutputStream(java.io.BufferedOutputStream) CdmaSmsAddress(com.android.internal.telephony.cdma.sms.CdmaSmsAddress)

Example 2 with SmsEnvelope

use of com.android.internal.telephony.cdma.sms.SmsEnvelope 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 3 with SmsEnvelope

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

the class SmsMessage method privateGetSubmitPdu.

/**
     * Creates BearerData and Envelope from parameters for a Submit SMS.
     * @return byte stream for SubmitPdu.
     */
private static SubmitPdu privateGetSubmitPdu(String destAddrStr, boolean statusReportRequested, UserData userData) {
    /**
         * TODO(cleanup): give this function a more meaningful name.
         */
    /**
         * TODO(cleanup): Make returning null from the getSubmitPdu
         * variations meaningful -- clean up the error feedback
         * mechanism, and avoid null pointer exceptions.
         */
    /**
         * North America Plus Code :
         * Convert + code to 011 and dial out for international SMS
         */
    CdmaSmsAddress destAddr = CdmaSmsAddress.parse(PhoneNumberUtils.cdmaCheckAndProcessPlusCode(destAddrStr));
    if (destAddr == null)
        return null;
    BearerData bearerData = new BearerData();
    bearerData.messageType = BearerData.MESSAGE_TYPE_SUBMIT;
    bearerData.messageId = getNextMessageId();
    bearerData.deliveryAckReq = statusReportRequested;
    bearerData.userAckReq = false;
    bearerData.readAckReq = false;
    bearerData.reportReq = false;
    bearerData.userData = userData;
    byte[] encodedBearerData = BearerData.encode(bearerData);
    if (Log.isLoggable(LOGGABLE_TAG, Log.VERBOSE)) {
        Log.d(LOG_TAG, "MO (encoded) BearerData = " + bearerData);
        Log.d(LOG_TAG, "MO raw BearerData = '" + HexDump.toHexString(encodedBearerData) + "'");
    }
    if (encodedBearerData == null)
        return null;
    int teleservice = bearerData.hasUserDataHeader ? SmsEnvelope.TELESERVICE_WEMT : SmsEnvelope.TELESERVICE_WMT;
    SmsEnvelope envelope = new SmsEnvelope();
    envelope.messageType = SmsEnvelope.MESSAGE_TYPE_POINT_TO_POINT;
    envelope.teleService = teleservice;
    envelope.destAddress = destAddr;
    envelope.bearerReply = RETURN_ACK;
    envelope.bearerData = encodedBearerData;
    try {
        /**
             * TODO(cleanup): reference a spec and get rid of the ugly comments
             */
        ByteArrayOutputStream baos = new ByteArrayOutputStream(100);
        DataOutputStream dos = new DataOutputStream(baos);
        dos.writeInt(envelope.teleService);
        //servicePresent
        dos.writeInt(0);
        //serviceCategory
        dos.writeInt(0);
        dos.write(destAddr.digitMode);
        dos.write(destAddr.numberMode);
        // number_type
        dos.write(destAddr.ton);
        dos.write(destAddr.numberPlan);
        dos.write(destAddr.numberOfDigits);
        // digits
        dos.write(destAddr.origBytes, 0, destAddr.origBytes.length);
        // Subaddress is not supported.
        //subaddressType
        dos.write(0);
        //subaddr_odd
        dos.write(0);
        //subaddr_nbr_of_digits
        dos.write(0);
        dos.write(encodedBearerData.length);
        dos.write(encodedBearerData, 0, encodedBearerData.length);
        dos.close();
        SubmitPdu pdu = new SubmitPdu();
        pdu.encodedMessage = baos.toByteArray();
        pdu.encodedScAddress = null;
        return pdu;
    } catch (IOException ex) {
        Log.e(LOG_TAG, "creating SubmitPdu failed: " + ex);
    }
    return null;
}
Also used : DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) BearerData(com.android.internal.telephony.cdma.sms.BearerData) SmsEnvelope(com.android.internal.telephony.cdma.sms.SmsEnvelope) CdmaSmsAddress(com.android.internal.telephony.cdma.sms.CdmaSmsAddress)

Example 4 with SmsEnvelope

use of com.android.internal.telephony.cdma.sms.SmsEnvelope 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)

Example 5 with SmsEnvelope

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

the class SmsMessage method parsePdu.

/**
     * Decodes pdu to an empty SMS object.
     * In the CDMA case the pdu is just an internal byte stream representation
     * of the SMS Java-object.
     * @see #createPdu()
     */
private void parsePdu(byte[] pdu) {
    ByteArrayInputStream bais = new ByteArrayInputStream(pdu);
    DataInputStream dis = new DataInputStream(bais);
    byte length;
    int bearerDataLength;
    SmsEnvelope env = new SmsEnvelope();
    CdmaSmsAddress addr = new CdmaSmsAddress();
    try {
        env.messageType = dis.readInt();
        env.teleService = dis.readInt();
        env.serviceCategory = dis.readInt();
        addr.digitMode = dis.readByte();
        addr.numberMode = dis.readByte();
        addr.ton = dis.readByte();
        addr.numberPlan = dis.readByte();
        length = dis.readByte();
        addr.numberOfDigits = length;
        addr.origBytes = new byte[length];
        // digits
        dis.read(addr.origBytes, 0, length);
        env.bearerReply = dis.readInt();
        // CauseCode values:
        env.replySeqNo = dis.readByte();
        env.errorClass = dis.readByte();
        env.causeCode = dis.readByte();
        //encoded BearerData:
        bearerDataLength = dis.readInt();
        env.bearerData = new byte[bearerDataLength];
        dis.read(env.bearerData, 0, bearerDataLength);
        dis.close();
    } catch (Exception ex) {
        Log.e(LOG_TAG, "createFromPdu: conversion from byte array to object failed: " + ex);
    }
    // link the filled objects to this SMS
    originatingAddress = addr;
    env.origAddress = addr;
    mEnvelope = env;
    mPdu = pdu;
    parseSms();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) SmsEnvelope(com.android.internal.telephony.cdma.sms.SmsEnvelope) IOException(java.io.IOException) CdmaSmsAddress(com.android.internal.telephony.cdma.sms.CdmaSmsAddress)

Aggregations

CdmaSmsAddress (com.android.internal.telephony.cdma.sms.CdmaSmsAddress)5 SmsEnvelope (com.android.internal.telephony.cdma.sms.SmsEnvelope)5 IOException (java.io.IOException)4 CdmaSmsSubaddress (com.android.internal.telephony.cdma.sms.CdmaSmsSubaddress)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataInputStream (java.io.DataInputStream)2 DataOutputStream (java.io.DataOutputStream)2 BearerData (com.android.internal.telephony.cdma.sms.BearerData)1 BitwiseInputStream (com.android.internal.util.BitwiseInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1