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