Create CDMA (3gpp2) PDU in Android
Asked Answered
T

0

3

I asked a similar question last week and even set a bounty on it, after realizing the problem was the answer given was for a GSM PDU (3gpp) and it worked flawlessly in the emulator (android 2.2). I accepted the Answer and awarded the bounty, and changed the title for future reference.

Question:

Now, I'm asking how to create a CDMA (3gpp2) PDU, similar to creating a GSM PDU (3gpp), that can be parsed in Android's API createFromPdu()

Trying to avoid writing it my self:

I was excited when reading the new method createFromPDU(byte[] pdu, String format) then realized that wouldn't be backwards compatible.

I was even curious of using com.android.internal.telephony.gsm.SmsMessage.createFromPdu(pdu); using the GSM PDU generated from the original question and answer. But I'm not quite sure if that would be safe...

So I've decided the best way would be either create a GSM or CDMA PDU depending on the type of device.

Does anyone have a snippet laying around that can create a CDMA PDU?

Or know how to convert the method creating a GSM PDU to a CDMA PDU format?

UPDATE:

I've been working on manually creating a method to create a CDMA (3gpp2) pdu I've gotten close to getting success following the awesome breakdown of a cdma pdu But I can't seem to understand how to 7bit pack the BearerData and cat the date string to the end of the pdu properly, this is what I have so far

private static byte[] createCDMAPDU(String sender, String body) {

    byte[] pdu = null;

    ByteArrayOutputStream baos = new ByteArrayOutputStream(100);
    DataOutputStream dos = new DataOutputStream(baos);

    Date now = new Date ();
    byte[] dateBytes = new byte[6];
    Calendar calendar = new GregorianCalendar();
    dateBytes[0] = (byte) (asBytes(""+calendar.get(Calendar.YEAR))[0]);
    dateBytes[1] = (byte) (asBytes(""+calendar.get(Calendar.MONTH) + 1)[0]);
    dateBytes[2] = (byte) (asBytes(""+calendar.get(Calendar.DAY_OF_MONTH))[0]);
    dateBytes[3] = (byte) (asBytes(""+calendar.get(Calendar.HOUR_OF_DAY))[0]);
    dateBytes[4] = (byte) (asBytes(""+calendar.get(Calendar.MINUTE))[0]);
    dateBytes[5] = (byte) (asBytes(""+calendar.get(Calendar.SECOND))[0]);

    try {
        dos.write(0);// unknown padding
        dos.write(0);// unknown padding
        dos.write(0);// unknown padding
        // MESSAGE_TYPE_POINT_TO_POINT = 0x00;
        // MESSAGE_TYPE_BROADCAST = 0x01;
        // MESSAGE_TYPE_ACKNOWLEDGE = 0x02;
        dos.write(0x00);// message type - MESSAGE_TYPE_POINT_TO_POINT
        // TELESERVICE_NOT_SET = 0x0000;
        // TELESERVICE_WMT = 0x1002;
        // TELESERVICE_VMN = 0x1003;
        // TELESERVICE_WAP = 0x1004;
        // TELESERVICE_WEMT = 0x1005;
        dos.writeInt(0x1002); // teleservice - TELESERVICE_NOT_SET
        // dos.writeInt(0); // servicePresent
        dos.writeInt(0); // serviceCategory
        // DIGIT_MODE_4BIT_DTMF = 0x00;
        // DIGIT_MODE_8BIT_CHAR = 0x01;
        dos.write(0x01);// digit mode - DIGIT_MODE_4BIT_DTMF
        // NUMBER_MODE_NOT_DATA_NETWORK = 0x00;
        // NUMBER_MODE_DATA_NETWORK = 0x01;
        dos.write(0x00);// number mode - NUMBER_MODE_NOT_DATA_NETWORK
        // TON_UNKNOWN = 0x00;
        // TON_INTERNATIONAL_OR_IP = 0x01;
        // TON_NATIONAL_OR_EMAIL = 0x02;
        // TON_NETWORK = 0x03;
        // TON_SUBSCRIBER = 0x04;
        // TON_ALPHANUMERIC = 0x05;
        // TON_ABBREVIATED = 0x06;
        // TON_RESERVED = 0x07;
        dos.write(0x00); // number_type - TON_UNKNOWN
        // NUMBERING_PLAN_UNKNOWN = 0x0;
        // NUMBERING_PLAN_ISDN_TELEPHONY = 0x1;
        dos.write(0x0);// number plan - NUMBERING_PLAN_UNKNOWN
        dos.write(sender.length());// number of digits
        dos.write(sender.getBytes(), 0, sender.getBytes().length); // digits
        dos.write(0);// bearer reply ?
        dos.write(0);// bearer reply ?
        // Subaddress is not supported.
        dos.write(0); // subaddressType
        dos.write(0); // subaddr_odd
        dos.write(0); // subaddr_nbr_of_digits
        // dos.write(encodedBearerData.length);
        // dos.write(encodedBearerData, 0, encodedBearerData.length);
        dos.write(0);
        dos.write(0);
        dos.write(0);
        dos.write(0);
        dos.write(0);
        byte[] bodybytes = getAsciiBytes(body);
        dos.write(bodybytes.length);
        dos.write(0);
        dos.write(0x03);
        dos.write(0x10);
        dos.write(0);
        dos.write(bodybytes, 0, bodybytes.length);
        dos.write(0);
        dos.write(dateBytes.length);
        dos.write(dateBytes);
        dos.close();

        pdu = baos.toByteArray();
    } catch (IOException e) {
    }
    return pdu;
}

I'm not sure if I'm on the right track or not.

Tereus answered 19/9, 2012 at 2:10 Comment(3)
Hi we meet again. You can try using reflection to get this createPdu() method. mEnvelop created from newFromParcel. And the last ril.cpp they mentionCertainty
@Yul Any chance you can add to the progress I've made, manually creating it? (I'm not entirely sure If I'm even on the right track) But I figured I'd try to avoid reflection as much as possible. Unless you can finish it with reflection, I'd accept that too.Tereus
I haven't work with Android for a while. I'll add answer if i find something interesting :).Certainty

© 2022 - 2024 — McMap. All rights reserved.