📜 ⬆️ ⬇️

How to send flash-SMS?

Flash-SMS is such an SMS, the text of which is immediately displayed on the user's phone / smartphone screen instead of being written to the device’s memory. The user reads it and decides whether to keep it in memory or not.

To send flash-SMS you will need to use the so-called PDU mode - Packet Data Unit. This is a mode that allows you to control all the secret SMS parameters described in the ETSI GSM Technical Specification GSM 03.40.
To access the PDU, it is recommended to use any GSM modem or module. Some old phones in modem mode also knew how, but I can’t say anything about modern smartphones, because I don’t know.
I used the Neoway M660 GSM module , but for modems / modules from other manufacturers this should also be true.



In PDU mode, an SMS message is a set of data sent to the modem in the form of ASCII characters.
Let's consider the format of the transmitted SMS message, the sequence of commands sent to the GSM modem, and also create a PDU package and send a flash-SMS “Hello, Habr!” To the hypothetical number +70123456789.
')

The format of the transmitted SMS-message in PDU mode



depicted in the picture:

PDU field nameLength, byteShort description
SCA, Service Center Address1-12SMS Center phone number (may not be indicated)
PDU TypePDU type
MR, Message ReferenceoneThe sequence number of the message set by the modem / module
DA, Destination Address2-12Telephone number of the message recipient
PID, Protocol IdentifieroneProtocol identifier
DCS, Data Coding SchemeoneMessage Encoding
VP, Validity Period0.1 or 7SMS lifetime
UDL, User Data LengthoneUser Data field length in bytes
UD, User Data0-140Message

So, consider the purpose of the individual fields of the PDU packet of the transmitted message.

1. SCA (Service Center Address) - the phone number of the SMS Center (SMSC).
This field is optional, as the SMSC number is stored on the SIM card and is automatically read by the Neoway GSM modules. We will use this opportunity and will not specify the SMS Center number in our example, especially since in this case the contents of the PDU do not depend on the SIM card used. If the SMSC number is not specified in the PDU, the SCA field is 0x00.
But if you still want to read the SMS Center number from the GSM module, can you always do this using the AT + CSCA command? ..

2. PDU Type - PDU Type



2.1 RP (Reply Path)
0 - no response path defined,
1 - the path for the answer is determined, the same SMS Center (SMSC) is used.

2.2 UDHI (User Data Header Included):
0 - the UD field contains only the message itself,
1- UD field contains a message and an additional header.

2.3 SRR (Status Report Request):
0 - the status of the message is not requested,
1 status of the message is requested.

2.4 VPF (Validity Period Format):
00 - VP field is absent,
01 - reserved,
10 - the VP field contains temporal data in a relative format,
11 - the VP field contains time data in absolute format.

2.5 RD (Reject Duplicates):
0 - The SMSC should be forwarded to the recipient if it has the same MR and DA field values ​​as the previous message.
1 - The SMSC should reject the message if it has the same MR and DA field values ​​as the previous message.

2.6 MTI (Message Type Indicator):
00 - received message (from SMSC to module) or acknowledgment (from module to SMSC)
01 - message to be sent (from the module to the SMSC) or confirmation of sending (from the SMSC to the module),
10 - delivery report (from SMSC to module) or SMS command (from module to SMSC)
11 is reserved.

In order to simplify the VP field (SMS lifetime, see clause 7), we will not use it and set the VPF bits to zero. Also set the RP, UDHI, SRR, RD bits to zero. The MTI bits of the sent message must be set to 01. Thus, the byte value of the PDU Type field is taken equal to 0x01.

3. MR (Message Reference) - the sequence number of the message, determined by the module itself. In a PDU, the field value is set to 0x00.

4. DA (Destination Address) - the phone number of the recipient of the message.
The field DA consists of three parts and has the following form:
The number of digits in the recipient's numberRecipient Number TypeRecipient's number
1 byte1 byte0 ... 6 bytes

4.1 The number of digits in the recipient's number is calculated without taking into account the “+” sign and is presented in hexadecimal format.
For example, for the number +70123456789, the byte value “The number of digits in the recipient's number” is 0x0B (11 in decimal).

4.2 Type of recipient number.
In the case of the international format of the byte number, “Type of the recipient's number” is set to 0x91, in the case of the local format - 0x81.

4.3 Recipient number.
The field "Number of the recipient" is formed as follows:
a) in the case of an international number format, the “+” sign is discarded;
b) if the number of digits in the number is odd, “F” is added at the end;
c) numbers in pairs are rearranged in places.

For example, for the number +70123456789, the field “Number of the recipient” will look like: 0721436587F9, and the entire field DA - 0B910721436587F9.

5. PID (Protocol Identifier) ​​- protocol identifier.
In our case, the value of the PID field must be set to 0x00.
More details about the features of this field can be found in ETSI GSM 03.40, clause 9.2.3.9.

6. DCS (Data Coding Scheme) - message encoding.
This is the field that interests us the most now! To send messages with Cyrillic characters, you must use UCS2 encoding.
The value of the DCS field in our case should be set to 0x18 - this is the secret combination that allows you to send flash-SMS in Cyrillic characters (0x08 is a normal SMS).

7. VP (Validity Period) - the lifetime of the message.

Message Lifetime - the time after which the message is destroyed (erased from the SMS Center memory) if it was not delivered to the addressee.
This field is associated with the VPF bits of the PDU Type field; there are three options for sharing them.

7.1 The VP field is not used (remember, we agreed that we will not use it in our example?).
In this case, the length of the VP field is 0 bytes, the VPF bits must be set to 00 (as we have already done).

7.2 The VP field contains data about the lifetime in relative format.
In this case, the VP field length is 1 byte, the VPF bits must be set to 10 (in binary).
Possible values ​​of the VP field in the case of using the relative time format and formulas for calculating the corresponding message lifetime are given in the following table:
VP value hexadecimalVP value decimalVP time valueMaximum lifetime
1..8F0 ... 143(VP + 1) * 5 minutes12 hours
90..A7144 ... 16712 hours + (VP - 143) * 30 minutes24 hours
A8..C4168 ... 196(VP - 166) * 1 day30 days
C5..FF197 ... 255(VP - 192) * 1 week63 weeks

7.3 The VP field contains data on the lifetime in absolute format.
In this case, the length of the VP field is 7 bytes, the VPF bits must be set to 11 (in binary).
The assignment of the bytes in the VP field using the absolute time format is given in this table:
1st byte2nd byte3rd byte4th byte5th byte6th byte7th byte
YearMonthDayHourMinutesSecondsTimezone

In addition, each byte contains two decimal numbers swapped by places. For example, byte 2 in the case of the month of May will be 0x50.
The year is represented by the last two digits.
The time zone indicates the difference between local time and Greenwich Mean Time (GMT), expressed in quarters of an hour. The first bit indicates the sign of this difference: 0 - the difference is positive, 1 - the difference is negative. That is, byte 7 in the case of GMT + 3 time zone will be 0x21.

Since we decided not to use the VP field and set two VPF bits of the PDU Type field to 00, the VP field of our example will not be present in the PDU packet of our example.

8. UDL (User Data Length) - the length of the UD field in bytes.
In the case of using the UCS2 encoding of interest to us, the value of the UDL field can be calculated by multiplying the number of characters in the transmitted message by 2 (each character is encoded with two bytes). For the “Hello, Habr!” Message, the UDL field is 0x1A (26 in decimal).

9. UD (User Data) - message
To send a message in Cyrillic, you must use UCS2 encoding; in this encoding, each letter or character is encoded in two bytes.
Encoding table UCS2 - here
The message “Hello, Habr!” In UCS2 encoding will look like this:
W: 041F
p: 0440
and: 0438
in: 0432
e: 0435
t: 0442
: 002C
: 0020
X: 0425
A: 0430
b: 0431
p: 0440
!: 0021

Hi, Habr !: 041F04400438043204350442002C002004250430043104400021

SMS sending process


Once the PDU package is complete, the process of sending an SMS is easy and consists of two simple steps:

1. Enter the command to send SMS with the number of bytes in the PDU packet with the exception of the SCA field. It does not sound very friendly, but if the SMS Center number is not used, then the SCA field is 0x00 (as we have) and this number is equal to the number of bytes in the PDU packet minus one. For "Hi, Habr!" This value is 39:

AT + CMGS = 39

It is important that this command is terminated by the character '\ r' (0x0D), without additives.
After that, the GSM modem prompts the '>' to enter the PDU packet data.

2. Enter PDU package data.
In the case of the message “Hi, Habr!”, The PDU packet looks like this:
0001000B9100181A041F04400438043204350442002C002004250430043104400021 (in text form),

where is the recipient's number field, in which the numbers are interchanged and the “F” symbol is added at the end in the case of an odd number of digits in the number (as described earlier).
For the number +79123456789, the field of the recipient’s number will be: 9721436587F9,
and the whole PDU packet with the message “Hello, Habr!”, sent to this number:
0001000B919721436587F900181A041F04400438043204350442002C002004250430043104400021

PDU packet data entry must end with byte 0x1A

In case of successful sending of SMS, the modem will respond:

+ CMGS: Message_Reference
Ok

where Message_Reference is the message sequence number set by the modem (see the description of the MR packet field of the PDU).

Source: https://habr.com/ru/post/364643/


All Articles