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