How to calculate the SMPP SM Length field
In the SMPP protocol, the sm_length
field specifies the length in bytes of the short message content contained in the short_message
field of PDUs such as submit_sm
, deliver_sm
, and data_sm
.
Field Details
- Field Name: sm_length
- Size: 1 byte (unsigned integer)
- Range: 0–254 (maximum allowed by SMPP 3.4)
- Location: Directly before the
short_message
field - Purpose: Indicates the number of bytes in the
short_message
payload
Key Behavior
The value of sm_length
depends on the encoding used:
Encoding | Characters per SMS | Byte Size | Notes |
---|---|---|---|
GSM 7-bit | Up to 160 | Up to 140 | Packed bits; actual byte size depends on content |
UCS2 | Up to 70 | 2 × number of characters | Each character is 2 bytes |
8-bit binary | N/A | Up to 140 | Raw byte length |
Example: ASCII Message
A simple message using default 7-bit encoding:
Text: "Hello" Encoding: GSM 7-bit Packed Bytes (Hex): C8 32 9B FD 06 Byte Length: 5 sm_length: 5
Example: UCS2 Encoded Message
A Unicode message using UCS2 encoding (data_coding = 0x08):
Text: "Hi" UCS2 Hex: 0048 0069 Byte Array: 00 48 00 69 Byte Length: 4 sm_length: 4
SMPP PDU Example (submit_sm)
0000003B // Command Length (59 bytes) 00000004 // Command ID: submit_sm 00000000 // Command Status 00000001 // Sequence Number 00 // service_type 01 // source_addr_ton 01 // source_addr_npi 31323334 // source_addr ("1234") 00 01 // dest_addr_ton 01 // dest_addr_npi 35363738 // destination_addr ("5678") 00 00 // esm_class 00 // protocol_id 00 // priority_flag 00 // schedule_delivery_time 00 // validity_period 00 // registered_delivery 00 // replace_if_present_flag 08 // data_coding: UCS2 00 // sm_default_msg_id 04 // sm_length: 4 00480069 // short_message: "Hi" in UCS2
Important Notes
sm_length
refers to byte length, not character count.- If message content is split across multiple messages (concatenation), each part has its own
sm_length
. - Do not confuse
sm_length
with the total message length (PDU length).
Message Splitting & Concatenation
When a message exceeds the maximum payload size, it is split into parts using a UDH (User Data Header). The sm_length
in such cases includes the UDH as well:
Example: UDH (6 bytes) + 67 UCS2 bytes = 73 sm_length = 73
Conclusion
The sm_length
field is critical in SMPP messaging as it defines how many bytes the SMSC should read for the actual message body. Understanding how encoding affects this field ensures accurate and successful message delivery.
References
- SMPP 3.4 Specification
- GSM 03.38 Character Set
- Unicode UCS2 Encoding
More information
- Kako konfigurirati polje SMPP vrsta usluge
- Kako konfigurirati polja SMPP telefonskih brojeva
- Kako konfigurirati polje SMPP ESM klasa
- Kako konfigurirati polje SMPP PID
- Kako konfigurirati polje SMPP prioritet
- Kako konfigurirati polje SMPP planirano vrijeme
- Kako konfigurirati polje SMPP rok valjanosti
- Kako konfigurirati polje SMPP registrirana isporuka
- Kako konfigurirati polje SMPP zamijeni ako postoji
- Kako konfigurirati polje sm_default_msg_id
- Kako konfigurirati polje SMPP DCS
- Kako izračunati polje SMPP SM duljina
- Kako staviti podatke u SMPP SM polje