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