Sending SMS Data Messages using GSM

Introduction

Besides sending text messages, SMS can also be used to send small data messages. A single SMS message can contain up to 140 bytes of user data. These messages can be used for custom applications, telemetry and over the air programming of the phone or SIM card. Messages such as ringtones, operator logos and WAP Push messages are also encoded as datamessages.

Sending a simple datamessage

To send a simple data message to a device that can process the messages by itself, you only have to change the 'DCS' parameter of the message. This is used for instance by telemetry devices.

Valid values for this 'DCS' paramater are:

0xF5 - Send the 8 bit datamessage to an application on the phone
0xF6 - Send the 8 bit datamessage to an application on the SIM (SIM Toolkit)

In some languages, when the standard GSM Alphabet is not sufficient, 8 bit data SMS is also used to send text messages.

Using the SMS and MMS toolkit, you can simply send data messages by passing a HEX formatted data string to the 'Data' property of the SmsMessage object. You can find a sample for sending a simple data message using a GSM modem below:

Option Explicit

'Declare Variables
Dim objSmsProtocol
Dim objSmsMessage
Dim objConstants

Dim strHex

' Create Objects
Set objSmsProtocol = CreateObject ( "ActiveXperts.SmsProtocolGsm" )
Set objSmsMessage  = CreateObject ( "ActiveXperts.SmsMessage" )
Set objConstants   = CreateObject ( "ActiveXperts.SmsConstants" )

' Define Bytes
strHex   = "000102030405060708090A0B0C0D0E0FFEFF"

' Set Logfile
objSmsProtocol.LogFile = "C:\SmsData.log"

' Set Device
objSmsProtocol.Device  = "Siemens AG WM USB Modem"

' Set the recipient, format and data
objSmsMessage.Data        = strHex
objSmsMessage.Recipient   = "+31647134225"
objSmsMessage.Format      = objConstants.asMESSAGEFORMAT_DATA

' Send the message
objSmsProtocol.Send

' Display the result
WScript.Echo "Sending data message, result: #" & objSmsProtocol.LastError & " (" & objSmsProtocol.GetErrorDescription ( objSmsProtocol.LastError ) & ")"

Sending the data message to an applicationport on the phone

Mobile phones have the capability to listen to a specific port number, similar to UDP/TCP ports in a TCP/IP Network. You can send data to a specific phone port by using the WDP (Wireless Datagram Protocol) Protocol. This protocol can be encapsulated in the UDH (User Data Header) of the SMS.

The following UDH bytes are used to send data to port 1234 on the mobile phone:

06 05 04 04D2 0000

06	Length of UDH Header
05	Port addressing
04  Destination Port
D2  1234 ( 0x04D2 HEX )
00	Source Port
00	0

To notify the receiving phone that you included an User Data Header in your message, you should set the TP-UDHI bit in the SMS. The bit is bit 6 of the first octet of the SMS-SUBMIT PDU. For more info about SMS PDU's see the GSM PDU document. The sample below demonstrates how to send data to an application port of a mobile phone:

Option Explicit

'Declare Variables
Dim objSmsProtocol
Dim objSmsMessage
Dim objConstants

Dim strHex

' Create Objects
Set objSmsProtocol = CreateObject ( "ActiveXperts.SmsProtocolGsm" )
Set objSmsMessage  = CreateObject ( "ActiveXperts.SmsMessage" )
Set objConstants   = CreateObject ( "ActiveXperts.SmsConstants" )

' Set UDH Header
strHex   = "06050404D20000"

' Define Bytes
strHex   = strHex + "000102030405060708090A0B0C0D0E0FFEFF"

' Set Logfile
objSmsProtocol.LogFile = "C:\SmsData.log"

' Set Device
objSmsProtocol.Device  = "Siemens AG WM USB Modem"

' Set the recipient, format and data
objSmsMessage.Data        = strHex
objSmsMessage.Recipient   = "+31647134225"
objSmsMessage.Format      = objConstants.asMESSAGEFORMAT_DATA_UDH

' Send the message
objSmsProtocol.Send

' Display the result
WScript.Echo "Sending data message, result: #" & objSmsProtocol.LastError & " (" & objSmsProtocol.GetErrorDescription ( objSmsProtocol.LastError ) & ")"

There are many working samples included with the product. You can also find them on the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/mobile-messaging-component.