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