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