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