:pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Tue Dec 4 22:45 CET 2001
[gnokii.git] / include / gsm-sms.h
1 /*
2
3   $Id$
4
5   G N O K I I
6
7   A Linux/Unix toolset and driver for Nokia mobile phones.
8
9   Copyright (C) 2001 Pawe³ Kot <pkot@linuxnews.pl>
10
11   Released under the terms of the GNU GPL, see file COPYING for more details.
12
13   Include file for SMS library.
14
15 */
16
17 #ifndef __gnokii_sms_h_
18 #define __gnokii_sms_h_
19
20 #include "misc.h"
21 #include "gsm-error.h"
22
23 /* Maximum length of SMS center name */
24
25 #define GSM_MAX_SMS_CENTER_NAME_LENGTH  (20)
26
27 /* Limits of SMS messages. */
28
29 #define GSM_MAX_SMS_CENTER_LENGTH  (40)
30 #define GSM_MAX_SENDER_LENGTH      (40)
31 #define GSM_MAX_DESTINATION_LENGTH (40)
32
33 #define GSM_MAX_SMS_LENGTH         (160)
34 #define GSM_MAX_8BIT_SMS_LENGTH    (140)
35
36 #define SMS_MAX_ADDRESS_LENGTH      (40)
37
38 /* FIXME: what value should be here? (Pawel Kot) */
39 #define SMS_MAX_UDH_NUMBER 10
40
41 /*** MEMORY INFO ***/
42
43 typedef struct {
44         int Unread; /* Number of unread messages */
45         int Number; /* Number of all messages */
46 } GSM_SMSMemoryStatus;
47
48 /*** DATE AND TIME ***/
49
50 typedef struct {
51         int Year;          /* The complete year specification - e.g. 1999. Y2K :-) */
52         int Month;           /* January = 1 */
53         int Day;
54         int Hour;
55         int Minute;
56         int Second;
57         int Timezone;      /* The difference between local time and GMT */
58 } SMS_DateTime;
59
60 /*** USER DATA HEADER ***/
61
62 /* types of User Data Header */
63 typedef enum {
64         SMS_NoUDH                = 0x00,
65         SMS_ConcatenatedMessages = 0x01,
66         SMS_OpLogo               = 0x02,
67         SMS_CallerIDLogo         = 0x03,
68         SMS_Ringtone             = 0x04,
69         SMS_VoiceMessage         = 0x05,
70         SMS_FaxMessage           = 0x06,
71         SMS_EmailMessage         = 0x07,
72         SMS_OtherMessage         = 0x08,
73         SMS_BusinessCard         = 0x09,
74         SMS_UnknownUDH           = 0x0a
75 } SMS_UDHType;
76
77 typedef struct {
78         SMS_UDHType Type;
79         union {
80                 struct {
81                         unsigned short ReferenceNumber;
82                         unsigned short MaximumNumber;
83                         unsigned short CurrentNumber;
84                 } ConcatenatedShortMessage; /* SMS_ConcatenatedMessages */
85                 struct {
86                         bool Store;
87                         unsigned short MessageCount;
88                 } SpecialSMSMessageIndication; /* SMS_VoiceMessage, SMS_FaxMessage, SMS_EmailMessage, SMS_OtherMessage */
89                 struct {
90                         char NetworkCode[6];
91 //                      ...
92                 } Logo; /* SMS_OpLogo, SMS_CallerIDLogo */
93                 struct {
94 //                      ...
95                 } Ringtone; /* SMS_Ringtone */
96         } u;
97 } SMS_UDHInfo;
98
99 typedef enum {
100         SMS_PID, /* Set Protocol Identifier to `Return Call Message' */
101         SMS_DCS, /* Set Data Coding Scheme "to indicate the type of message waiting and whether there are some messages or no messages" */
102         SMS_UDH  /* Use User Data Header - Special SMS Message Indication; the maximium level of information, may not be supported by all phones */
103 } SMS_MessageWaitingType;
104
105 /*** DATA CODING SCHEME ***/
106
107 typedef enum {
108         SMS_GeneralDataCoding,
109         SMS_MessageWaiting
110 } SMS_DataCodingSchemeType;
111
112 typedef enum {
113         SMS_DefaultAlphabet = 0x00,
114         SMS_8bit            = 0x01,
115         SMS_UCS2            = 0x02
116 } SMS_AlphabetType;
117
118 typedef enum {
119         SMS_VoiceMail = 0x00,
120         SMS_Fax       = 0x01,
121         SMS_Email     = 0x02,
122         SMS_Text      = 0x03,
123         SMS_Other     = 0x04
124 } SMS_IndicationType;
125
126 typedef struct {
127         SMS_DataCodingSchemeType Type;
128         union {
129                 struct {
130                         unsigned short Class; /* 0 - no class
131                                                  1 - Class 0
132                                                  2 - Class 1
133                                                  3 - Class 2
134                                                  4 - Class 3 */
135                         bool Compressed;
136                         SMS_AlphabetType Alphabet;
137                 } General;
138                 struct {
139                         bool Discard;
140                         SMS_AlphabetType Alphabet; /* ucs16 not supported */
141                         bool Active;
142                         SMS_IndicationType Type;
143                 } MessageWaiting;
144         } u;
145 } SMS_DataCodingScheme;
146
147 /*** VALIDITY PERIOD ***/
148
149 typedef enum {
150         SMS_NoValidityPeriod = 0x00,
151         SMS_EnhancedFormat   = 0x01,
152         SMS_RelativeFormat   = 0x02,
153         SMS_AbsoluteFormat   = 0x03
154 } SMS_ValidityPeriodFormat;
155
156 typedef enum {
157         SMS_EnhancedNoValidityPeriod  = 0x00,
158         SMS_EnhancedRelativeFormat    = 0x01,
159         SMS_EnhancedRelativeSeconds   = 0x02, /* Only one ocetet more is used */
160         SMS_EnhancedRelativeSemiOctet = 0x03  /* 3 octets contain relative time in hours, minutes and seconds in semi-octet representation */
161 } SMS_EnhancedValidityPeriodType;
162
163 typedef struct {
164         bool extension; /* we need to set it to 0 at the moment; FIXME: how to handle `1' here? */
165         bool single_shot;
166         SMS_EnhancedValidityPeriodType type;
167         union {
168                 unsigned short relative;
169                 unsigned short seconds;
170                 SMS_DateTime hms;
171         } period;
172 } SMS_EnhancedValidityPeriod;
173
174 /* Validity of SMS Messages. */
175
176 typedef enum {
177         SMS_V1H   = 0x0b,
178         SMS_V6H   = 0x47,
179         SMS_V24H  = 0xa7,
180         SMS_V72H  = 0xa9,
181         SMS_V1W   = 0xad,
182         SMS_VMax  = 0xff
183 } SMS_ValidityPeriod;
184
185 typedef struct {
186         SMS_ValidityPeriodFormat VPF;
187         union {
188                 SMS_EnhancedValidityPeriod Enhanced;
189                 SMS_ValidityPeriod Relative; /* 8 bit */
190                 SMS_DateTime Absolute;
191         } u;
192 } SMS_MessageValidity;
193
194
195 /* This data-type is used to specify the type of the number. See the official
196    GSM specification 03.40, version 6.1.0, section 9.1.2.5, page 35-37. */
197 typedef enum {
198         SMS_Unknown       = 0x81, /* Unknown number */
199         SMS_International = 0x91, /* International number */
200         SMS_National      = 0xa1, /* National number */
201         SMS_Network       = 0xb1, /* Network specific number */
202         SMS_Subscriber    = 0xc1, /* Subscriber number */
203         SMS_Alphanumeric  = 0xd0, /* Alphanumeric number */
204         SMS_Abbreviated   = 0xe1  /* Abbreviated number */
205 } SMS_NumberType;
206
207 /*** MESSAGE CENTER ***/
208
209 typedef enum {
210         SMS_FText   = 0x00, /* Plain text message. */
211         SMS_FFax    = 0x22, /* Fax message. */
212         SMS_FVoice  = 0x24, /* Voice mail message. */
213         SMS_FERMES  = 0x25, /* ERMES message. */
214         SMS_FPaging = 0x26, /* Paging. */
215         SMS_FUCI    = 0x2d, /* Email message in 8110i. */
216         SMS_FEmail  = 0x32, /* Email message. */
217         SMS_FX400   = 0x31  /* X.400 message. */
218 } SMS_MessageFormat;
219
220 typedef struct {
221         int                     No;                                     /* Number of the SMSC in the phone memory. */
222         SMS_NumberType          Type;
223         char                    Name[GSM_MAX_SMS_CENTER_NAME_LENGTH];   /* Name of the SMSC. */
224         SMS_MessageFormat       Format;                                 /* SMS is sent as text/fax/paging/email. */
225         SMS_ValidityPeriod      Validity;                               /* Validity of SMS Message. */
226         char                    Number[GSM_MAX_SMS_CENTER_LENGTH];      /* Number of the SMSC. */
227         char                    Recipient[GSM_MAX_SMS_CENTER_LENGTH];   /* Number of the default recipient. */
228 } SMS_MessageCenter;
229
230 /*** SHORT MESSAGE CORE ***/
231
232 typedef struct {
233         SMS_NumberType type;
234         char number[SMS_MAX_ADDRESS_LENGTH];
235 } SMS_Number;
236
237 typedef enum {                     /* Bits meaning */
238         SMS_Deliver         = 0x00, /* 00 0 First 2 digits are taken from */
239         SMS_Delivery_Report = 0x01, /* 00 1 GSM 03.40 version 6.1.0 Release 1997 */
240         SMS_Submit          = 0x02, /* 01 0 */
241         SMS_Submit_Report   = 0x03, /* 01 1 */
242         SMS_Command         = 0x04, /* 10 0 mark a report */
243         SMS_Status_Report   = 0x05, /* 10 1 Section 9.2.3.1; 3rd digit is to */
244         SMS_Picture         = 0x07  /* Looks like Happy N*kia Engineers (TM) invention */
245 } SMS_MessageType;
246
247 typedef enum {
248         SMS_Enquiry            = 0x00, /* Enquiry relating to previosly submitted short message; sets SRR to 1 */
249         SMS_CancelStatusReport = 0x01, /* Cancel Status Report Request relating to previously submitted short message; sets SRR to 0 */
250         SMS_DeleteSM           = 0x02, /* Delete previousle submitted Short Message; sets SRR to 0 */
251         SMS_EnableStatusReport = 0x03  /* Enable Status Report Request relating to previously submitted short message; sets SRR to 0 */
252 } SMS_CommandType;
253
254 typedef struct {
255         SMS_CommandType Type;
256 } SMS_MessageCommand;
257
258 /* Datatype for SMS status */
259 typedef enum {
260         SMS_Read   = 0x01,
261         SMS_Unread = 0x03,
262         SMS_Sent   = 0x05,
263         SMS_Unsent = 0x07
264 } SMS_MessageStatus;
265
266 /* In contrast to GSM_MemoryType, SMS_MemoryType is phone dependant */
267 typedef enum {
268         GMT_IN = 0x08, /* Inbox in 6210/7110 */
269         GMT_OU = 0x10, /* Outbox in 6210/7110 */
270         GMT_AR = 0x18, /* Archive in 6210/6110 */
271         GMT_TE = 0x20, /* Templates in 6210/7110 */
272         GMT_F1 = 0x29, /* 1st CUSTOM FOLDER in 6210/7110*/
273         GMT_F2 = 0x31,
274         GMT_F3 = 0x39,
275         GMT_F4 = 0x41,
276         GMT_F5 = 0x49,
277         GMT_F6 = 0x51,
278         GMT_F7 = 0x59,
279         GMT_F8 = 0x61,
280         GMT_F9 = 0x69,
281         GMT_F10 = 0x71,
282         GMT_F11 = 0x79,
283         GMT_F12 = 0x81,
284         GMT_F13 = 0x89,
285         GMT_F14 = 0x91,
286         GMT_F15 = 0x99,
287         GMT_F16 = 0xA1,
288         GMT_F17 = 0xA9,
289         GMT_F18 = 0xB1,
290         GMT_F19 = 0xB9,
291         GMT_F20 = 0xC1 /* 20th CUSTOM FOLDER in 6210/7110 */
292 } SMS_MemoryType;
293
294 /* Define datatype for SMS messages, describes precisely GSM Spec 03.40 */
295 typedef struct {
296         /* Specification fields */
297         SMS_MessageType Type;                          /* Message Type Indicator - 2 bits (9.2.3.1) */
298         bool MoreMessages;                             /* More Messages to Send (9.2.3.2) */
299         bool ReplyViaSameSMSC;                         /* Reply Path (9.2.3.17) - `Reply via same centre' in the phone */
300         bool RejectDuplicates;                         /* Reject Duplicates (9.2.3.25) */
301         bool Report;                                   /* Status Report (9.2.3.4, 9.2.3.5 & 9.2.3.26) - `Delivery reports' in the phone */
302
303         unsigned short Number;                         /* Message Number - 8 bits (9.2.3.18) */
304         unsigned short Reference;                      /* Message Reference - 8 bit (9.2.3.6) */
305         unsigned short PID;                            /* Protocol Identifier - 8 bit (9.2.3.9) */
306         unsigned short ReportStatus;                   /* Status - 8 bit (9.2.3.15), Failure Cause (9.2.3.22) */
307         unsigned short Length;                         /* User Data Length (9.2.3.16), Command Data Length (9.2.3.20) */
308
309         SMS_MessageCenter MessageCenter;               /* SMSC Address (9.2.3.7, 9.2.3.8, 9.2.3.14) */
310         SMS_Number RemoteNumber;                       /* Origination, destination, Recipient Address (9.2.3.7, 9.2.3.8, 9.2.3.14) */
311         unsigned char MessageText[GSM_MAX_SMS_LENGTH]; /* User Data (9.2.3.24), Command Data (9.2.3.21) */
312         SMS_DataCodingScheme DCS;                      /* Data Coding Scheme (9.2.3.10) */
313         SMS_MessageValidity Validity;                  /* Validity Period Format & Validity Period (9.2.3.3 & 9.2.3.12) - `Message validity' in the phone */
314   
315         unsigned short UDH_No;                         /* Number of presend UDHs */
316         unsigned int UDH_Length;                       /* Length of the whole UDH */
317         SMS_UDHInfo UDH[SMS_MAX_UDH_NUMBER];           /* User Data Header Indicator & User Data Header (9.2.3.23 & 9.2.3.24) */
318
319         SMS_DateTime SMSCTime;                         /* Service Centre Time Stamp (9.2.3.11) */
320         SMS_DateTime Time;                             /* Discharge Time (9.2.3.13) */
321
322         /* Other fields */
323         SMS_MemoryType MemoryType;                     /* memoryType (for 6210/7110: folder indicator */
324         SMS_MessageStatus Status;                      /* Status of the message: sent/read or unsent/unread */
325
326 //      SMS_CommandType Command;                       /* Command Type - 8 bits (9.2.3.19); FIXME: use it!!!! */
327 //      unsigned char Parameter[???];                  /* Parameter Indicator (9.2.3.27); FIXME: how to use it??? */
328 } GSM_SMSMessage;
329
330 /* Define the layout of the SMS message header */
331 typedef struct {
332         bool IsSupported;
333         short MoreMessages;
334         short ReplyViaSameSMSC;
335         short RejectDuplicates;
336         short Report;
337         short Number;
338         short Reference;
339         short PID;
340         short ReportStatus;
341         short Length;
342         short DataCodingScheme;
343         short Validity;
344         short UserDataHeader;
345         short MessageCenter;
346         bool IsMessageCenterCoded;
347         short RemoteNumber;
348         bool IsRemoteNumberCoded;
349         short SMSCTime;
350         short Time;
351         short MemoryType;
352         short Status;
353         short UserData;
354         bool IsUserDataCoded;
355 } SMSMessage_Layout;
356
357 /* Define set of SMS Headers for the phone series */
358 typedef struct {
359         unsigned short Type;
360         SMSMessage_Layout Deliver;
361         SMSMessage_Layout Submit;
362         SMSMessage_Layout DeliveryReport;
363         SMSMessage_Layout Picture;
364 } SMSMessage_PhoneLayout;
365
366 extern SMSMessage_PhoneLayout layout;
367
368 /*** FOLDERS ***/
369
370 /* Maximal number of SMS folders */
371 #define MAX_SMS_FOLDERS 24
372
373 /* Datatype for SMS folders ins 6210/7110 */
374 typedef struct {
375         char Name[15];     /* Name for SMS folder */
376         bool SMSData;      /* if folder contains sender, SMSC number and sending date */
377         u8 locations[160]; /* locations of SMS messages in that folder (6210 specific) */
378         u8 number;         /* number of SMS messages in that folder*/
379         u8 FolderID;       /* ID od fthe current folder */
380 } SMS_Folder;
381
382 typedef struct {
383         SMS_Folder Folder[MAX_SMS_FOLDERS];
384         u8 FolderID[MAX_SMS_FOLDERS]; /* ID specific for this folder and phone. */
385                                        /* Used in internal functions. Do not use it. */
386         u8 number;                     /* number of SMS folders */
387 } SMS_FolderList;
388
389 /*** CELL BROADCAST ***/
390
391 #define GSM_MAX_CB_MESSAGE         (160)
392
393 /* Define datatype for Cell Broadcast message */
394 typedef struct {
395         int Channel;                                      /* channel number */
396         char Message[GSM_MAX_CB_MESSAGE + 1];
397         int New;
398 } GSM_CBMessage;
399
400 extern int EncodePDUSMS(GSM_SMSMessage *SMS, char *frame);
401 extern GSM_Error DecodePDUSMS(unsigned char *message, GSM_SMSMessage *SMS, int MessageLength);
402 /* Do not use these yet */
403 extern GSM_Error EncodeTextSMS();
404 extern GSM_Error DecodeTextSMS(unsigned char *message, GSM_SMSMessage *SMS);
405
406 /* FIXME: make this static */
407 extern char *GetBCDNumber(u8 *Number);
408
409 #endif /* __gnokii_sms_h_ */