Greenisha
Greenisha

Reputation: 1437

How can I get a short number when I receive a binary formatted sms in applet

I have a java card applet that can receive binary sms and process them. Now I need to check if they come from specific short number.

That's what i have done

case EVENT_FORMATTED_SMS_PP_ENV:{
final EnvelopeHandler eh = EnvelopeHandler.getTheHandler();
    short sd_len = eh.getSecuredDataLength();
    short sd_offset = eh.getSecuredDataOffset();
    byte[] tmpData = new byte[10];
    short dataLen = 0;
    if (eh.findTLV(ToolkitConstants.TAG_ADDRESS, (byte) 1) != ToolkitConstants.TLV_NOT_FOUND) {
        dataLen = eh.getValueLength();   
        eh.copyValue((short)0,tmpData,(short)0,(short)dataLen);
    }

    actions.showNumberBuffer(tmpData, (short)dataLen);      
                    break;
                }

I successfully receive address, but it differs from the short number, that sends binary sms Maybe some other way to get short number?

Upvotes: 1

Views: 1684

Answers (1)

David
David

Reputation: 4047

The Address TLV is Service Centre address.

The sender's address is the TP-OA inside SMS-TPDU TLV. Hence, you need to parse it manually.

Here's an example:

// Format of data under first SMS TPDU TLV, taken using EnvelopeHandler.findTLV()
// ----------+-----+---------+---------+--------+--------+---------+--------+-------+
//     1     |  1  |     1   |  0~10   |    1   |   1    |    7    |   1    | 0~140 |
// ----------+-----+---------+---------+--------+--------+---------+--------+-------+
//           | Len | TON/NPI | Address |        |        |         |        |       |
// TP-MTI... |        TP-OA            | TP-PID | TP-DCS | TP-SCTS | TP-UDL | TP-UD |
// ----------+-----+---------+---------+--------+--------+---------+--------+-------+

// Get received TPOA
EnvelopeHandler envHdlr = EnvelopeHandler.getTheHandler();
envHdlr.findTLV(ToolkitConstants.TAG_SMS_TPDU, (byte) 1);

// Assign TPOA to a buffer [0] for bytes-length [1..12] for the value as coded in 3GPP TS 23.040
envHdlr.copyValue((short) 1, tpdaBuf, (short) 1, (short) 12);
byte lengthTPOA = (byte) ((tpdaBuf[1] + 5) / 2);
tpdaBuf[0] = lengthTPOA;

Upvotes: 1

Related Questions