Click here to Skip to main content
12,356,154 members (66,701 online)
Click here to Skip to main content
Add your own
alternative version

Stats

227K views
7.2K downloads
59 bookmarked
Posted

Using VB.NET to Decode PDU string

, 21 Feb 2005
Rate this:
Please Sign up or sign in to vote.
Decode PDU string using VB.NET.

Online PDU Decoder

Sample screenshot

Introduction

Wish to develop SMS or EMS application? What do you read from your mobile? PDU code. PDU is a format which you send to a phone to send a SMS or an EMS. You can find more in GSM 03.40.

What is a PDU code and how can I decode it?

Let us take a simple look at PDU code. Here I created a SMS: "Hello, my pretty world!", in my Siemens M55 mobile, and send it to 1861. I use HyperTerminal to communicate with my phone using AT Command set.

First, I set my character set to Unicode:

AT+CSCS="UCS2"

Then I set my preferred message storage to MT:

AT+CPMS="MT"

At last, I read all my SMS out:

AT+CMGL=4

I find the SMS I just created in PDU format:

0891683108200805F01151048181160000FF16C8329BFD66B5F320B8BC4CA7E741F7B79C4D0E01

Now, I decode it manually:

08: Length of Service Center Number
91: Indicate there is a plus at the beginning of Service Center number
683108200805F: Service Center number: 8613800280500 Note when the length 
                                      of number is an odd number, add F.
11: Indicate this SMS will be sent.
51: TP-MR Message Reference, not common used.
04: Length of destination number. Here 1861.
81: No plus here.
8161: Destination number 1861.
00: TP-PID. See GSM 03.40
00: TP-DCS. TP-UD is coded by 7bit charactor method. See GSM 03.38
FF: TP-VP. Valid Period. Here is infinity.
16: Hex value equals to 22. This indicates there are 22 charactors in TP-UD
C8329BFD66B5F320B8BC4CA7E741F7B79C4D0E01: TP-UD, 
           decode it using 7bit charactor method.

Ha-ha, now you may know more about PDU code. Let us start our program.

What is the structure of my PDU Decoder?

I created a must inherit class SMS, it provides basic structure a SMS must have. For example: something relating to service center, first octet, TP_PID, and so on.

In this class I provide a must override sub GetOrignalData, this help me to do further work on the orignal data from PDU code. Here are also a few of shared functions:

  • GetByte()
  • GetString()
  • GetDate()
  • Swap()
  • GetAddress()
  • GetSMSType()
  • DecodeUnicode90()
  • Decode7Bit()

There shared functions will be used frequently. After SMS class, I created SMS_RECEIVED, SMS_SUBMIT, EMS_RECEIVED, EMS_SUBMIT, SMS_STATUS_REPORT classes that inherit from SMS class.

How it works?

I wanted it like, once you create an instance of one class with a PDU code, it decodes it immediately. So, I wrote some code in every Sub New.

Take SMS_RECEIVED, for example:

Sub New(ByVal PDUCode As String)
    Type = SMS.SMSType.SMS_RECEIVED
    GetOrignalData(PDUCode)
End Sub

The Sub GetOrignalData gets original data from PDU code. This decodes a received SMS's PDU code.

Public Overrides Sub GetOrignalData(ByVal PDUCode As String)
    SCAddressLength = GetByte(PDUCode)
    SCAddressType = GetByte(PDUCode)
    SCAddressValue = GetAddress((GetString(PDUCode, (SCAddressLength - 1) * 2)))
    FirstOctet = GetByte(PDUCode)
    SrcAddressLength = GetByte(PDUCode)
    SrcAddressType = GetByte(PDUCode)
    SrcAddressLength += SrcAddressLength Mod 2
    SrcAddressValue = GetAddress((GetString(PDUCode, SrcAddressLength)))
    TP_PID = GetByte(PDUCode)
    TP_DCS = GetByte(PDUCode)
    TP_SCTS = GetDate(GetString(PDUCode, 14))
    TP_UDL = GetByte(PDUCode)
    TP_UD = GetString(PDUCode, TP_UDL * 2)
End Sub

It is so easy to write some code like this after you read GSM 03.40. Shared function here helps me get what I want, a byte or a string or even a date. Note that when you get something from PDU code, it will be got rid of from the PDU code. This seemed like a good way after I failed to control the position of what PDU code I should get, because every time, the shared functions started from the beginning of PDU code.

In EMS, I write a function to get Information Element from PDU code and a structure to store it.

Public Structure InfoElem
    Public Identifier As Byte
    Public Length As Byte
    Public Data As String
End Structure
Shared Function GetIE(ByVal IECode As String) As InfoElem()
    Dim tmp As String = IECode, t As Integer = 0
    Dim result() As InfoElem
    Do Until IECode = ""
        ReDim Preserve result(t)
        With result(t)
            .Identifier = GetByte(IECode)
            .Length = GetByte(IECode)
            .Data = GetString(IECode, .Length * 2)
        End With
        t += 1
    Loop
    Return result
End Function

Maybe, my class is not the best, but it works well Smile | :) .

How can I use this class?

If you know what the type of PDU code is, you simply create an instance of a certain type in SMS or EMS. But when you don't know the type, you use shared function GetSMSType to get the type. Then according to the type, create a certain instance of SMS class, it is decoded automatically.

Still don't know? Sorry for my poor English, run my program and see my code, you will know it better.

Are there some bugs?

Sorry, I don't find bugs when I decode PDU code from Siemens M55 mobile and Nokia 8xxx mobile, I think there will be no bugs. If you find some, please contact me. Thanks!

Some useful documents and sites

Contact me and make friends with me

My email: hesicong@mail.sc.cninfo.net; hesicong@126.com. My QQ (only in China): 38288890. My MSN: hesicong@mail.sc.cninfo.net. My homepage. My CSDN blog. In the end, thanks for using these classes!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

hesicong
Web Developer
China China
I'm a undergraduate student in UESTC in China.
I have being learing computer for more than ten years. And now studying programming and have some software made by myself.
I learned SMS technology and did some work on OBEX, PDU, AT commands, IrDA and so on.
If you have interested in this field, please contact me.
And see more on my web site: http://www.hesicong.net

You may also be interested in...

Comments and Discussions

 
QuestionNeed Help Pin
Humayun Rashed20-Feb-15 4:18
memberHumayun Rashed20-Feb-15 4:18 
QuestionBug of Decoding Pin
Member 111946183-Nov-14 19:53
memberMember 111946183-Nov-14 19:53 
AnswerRe: Bug of Decoding Pin
Huỳnh Hữu Ân22-Dec-14 2:31
memberHuỳnh Hữu Ân22-Dec-14 2:31 
Question?????????? Pin
Member 1033201312-Oct-13 4:12
memberMember 1033201312-Oct-13 4:12 
QuestionPlease share same code into c# Pin
ganesh12311118-Nov-12 1:17
memberganesh12311118-Nov-12 1:17 
QuestionSend two sms at once Pin
Boroumandan27-Aug-11 5:56
memberBoroumandan27-Aug-11 5:56 
GeneralError with same messages (chinese characters appear) Pin
eyanson2-Apr-09 12:36
membereyanson2-Apr-09 12:36 
QuestionHow to send a message from a mobile connected to PC using hyperterminal to another mobile Pin
Shalininl23-Dec-08 15:57
memberShalininl23-Dec-08 15:57 
Generalproblem with Multiple part Pin
Muthuganesh10-Jul-08 4:49
memberMuthuganesh10-Jul-08 4:49 
GeneralRe: problem with Multiple part Pin
vash stampede10-Nov-09 23:09
membervash stampede10-Nov-09 23:09 
Generaltotal number of messages at the memory location Pin
hasanjh729-Apr-08 0:21
memberhasanjh729-Apr-08 0:21 
GeneralRe: total number of messages at the memory location [modified] Pin
Noener3-Jul-08 3:41
memberNoener3-Jul-08 3:41 
GeneralPDU to clear text Pin
jan vokroj7-Jan-08 3:12
memberjan vokroj7-Jan-08 3:12 
GeneralRe: PDU to clear text Pin
hesicong7-Jan-08 3:45
memberhesicong7-Jan-08 3:45 
Generaldecoded as unicode instead of 7 bit Pin
Lambert Antonio30-Sep-07 23:24
memberLambert Antonio30-Sep-07 23:24 
QuestionSMS Pin
justice7519-Oct-06 18:36
memberjustice7519-Oct-06 18:36 
GeneralEMS not decoded properly II Pin
masterEUO18-Oct-06 16:33
membermasterEUO18-Oct-06 16:33 
GeneralRe: EMS not decoded properly II Pin
irani@sina.com25-May-07 3:41
memberirani@sina.com25-May-07 3:41 
GeneralRe: EMS not decoded properly II Pin
Psyris_26-Mar-10 7:21
memberPsyris_26-Mar-10 7:21 
GeneralAn idea.. Pin
s_ruchit9-Aug-06 3:49
members_ruchit9-Aug-06 3:49 
AnswerRe: An idea.. Pin
hesicong9-Aug-06 18:44
memberhesicong9-Aug-06 18:44 
GeneralRe: An idea.. Pin
s_ruchit9-Aug-06 22:51
members_ruchit9-Aug-06 22:51 
AnswerRe: An idea.. Pin
hesicong10-Aug-06 6:16
memberhesicong10-Aug-06 6:16 
Generalhelp me.. Pin
s_ruchit9-Aug-06 3:44
members_ruchit9-Aug-06 3:44 
GeneralRe: help me.. [modified] Pin
hesicong9-Aug-06 18:21
memberhesicong9-Aug-06 18:21 
GeneralWAP push AT Command.. Pin
s_ruchit28-Jul-06 4:01
members_ruchit28-Jul-06 4:01 
GeneralRe: WAP push AT Command.. Pin
hesicong28-Jul-06 18:30
memberhesicong28-Jul-06 18:30 
Generalvb.net application for send sms to mobile Pin
Kunal B Padia24-Apr-06 14:16
memberKunal B Padia24-Apr-06 14:16 
GeneralRe: vb.net application for send sms to mobile Pin
xaml.net13-Jan-07 2:15
memberxaml.net13-Jan-07 2:15 
Generalpc to mobile sms sending Pin
patel nikunj p24-Feb-06 22:24
memberpatel nikunj p24-Feb-06 22:24 
Generalabout pdu decoder&encoder Pin
patel nikunj p24-Feb-06 22:11
memberpatel nikunj p24-Feb-06 22:11 
GeneralProblem decoding symbols Pin
virtual cat9-Feb-06 17:59
membervirtual cat9-Feb-06 17:59 
GeneralRe: Problem decoding symbols Pin
Noener3-Jul-08 3:26
memberNoener3-Jul-08 3:26 
QuestionEMS /PDU CODE? Can you help me? Pin
Revid30-Aug-05 9:05
sussRevid30-Aug-05 9:05 
AnswerRe: EMS /PDU CODE? Can you help me? Pin
hesicong30-Aug-05 22:50
memberhesicong30-Aug-05 22:50 
GeneralRe: EMS /PDU CODE? Can you help me? Pin
Revid31-Aug-05 4:03
sussRevid31-Aug-05 4:03 
GeneralStatus report decode error Pin
jasonliew10-Jun-05 15:15
memberjasonliew10-Jun-05 15:15 
GeneralRe: Status report decode error Pin
Anonymous13-Sep-05 1:17
sussAnonymous13-Sep-05 1:17 
GeneralRe: Status report decode error Pin
irani@sina.com24-May-07 4:47
memberirani@sina.com24-May-07 4:47 
Generalhelp please Pin
bryan_7724-May-05 22:39
memberbryan_7724-May-05 22:39 
GeneralRe: help please Pin
hesicong26-May-05 5:09
memberhesicong26-May-05 5:09 
GeneralMMS messages Pin
blackdoguk21-Apr-05 3:50
memberblackdoguk21-Apr-05 3:50 
GeneralRe: MMS messages Pin
hesicong30-Aug-05 22:53
memberhesicong30-Aug-05 22:53 
GeneralSending SMS with Chinese text in PDU Format Pin
bgm22915-Apr-05 3:54
memberbgm22915-Apr-05 3:54 
GeneralModifying SMS originating address Pin
Trankil25-Oct-04 2:46
memberTrankil25-Oct-04 2:46 
GeneralRe: Modifying SMS originating address Pin
s_ruchit10-Aug-06 0:40
members_ruchit10-Aug-06 0:40 
GeneralSending smart messages Pin
Trankil29-Sep-04 7:23
memberTrankil29-Sep-04 7:23 
GeneralRe: Sending smart messages Pin
hesicong30-Sep-04 2:40
memberhesicong30-Sep-04 2:40 
GeneralUCS2 encoding Pin
Trankil28-Sep-04 0:30
memberTrankil28-Sep-04 0:30 
GeneralRe: UCS2 encoding Pin
hesicong28-Sep-04 17:30
memberhesicong28-Sep-04 17:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 22 Feb 2005
Article Copyright 2004 by hesicong
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid