\r\n -> \n
[gnokii.git] / include / gsm-sms.h
1 /*
2
3   G N O K I I
4
5   A Linux/Unix toolset and driver for Nokia mobile phones.
6
7   Released under the terms of the GNU GPL, see file COPYING for more details.
8
9 */
10
11 #ifndef __gsm_sms_h
12 #define __gsm_sms_h
13
14 #include "gsm-common.h"
15 #include "gsm-datetime.h"
16
17 /* This data-type is used to specify the type of the number. See the official
18    GSM specification 03.40, version 5.3.0, section 9.1.2.5, page 33. */
19 typedef enum {
20   GNT_UNKNOWN=0x81,       /* Unknown number */
21   GNT_INTERNATIONAL=0x91, /* International number */
22   GNT_ALPHANUMERIC=0xD0   /* Alphanumeric number */
23 } GSM_NumberType;
24
25 /* For folder table */
26 typedef struct {
27   int smsnum;
28   u8 folder;
29   int location;
30 //future use  GSM_SMSMessage *message;
31 } GSM_SMS2Foldertable;
32
33 /* This data type is used to hold the current SMS status. */
34 typedef struct {
35   int UnRead;                           /* The number of unread messages */
36   int Number;                           /* The number of messages */
37   GSM_SMS2Foldertable foldertable[255]; /* for 6210/7110 */
38 } GSM_SMSStatus;
39
40 /* Define datatype for SMS Message Type */
41 typedef enum {
42   GST_SMS,
43   GST_DR, /* Delivery Report */
44   GST_UN  /* Unknown */
45 } GSM_SMSMessageType;
46
47 #define GST_INBOX       0;    /* Mobile Terminated (MT) message - Inbox message  */
48 #define GST_OUTBOX      1;    /* Mobile Originated (MO) message - Outbox message */
49 #define GST_7110_INBOX  0x08; /* Inbox in 6210/7110 */
50 #define GST_7110_OUTBOX 0x10; /* Outbox in 6210/7110 */
51
52 /* Datatype for SMS status */
53 typedef enum {
54   GSS_SENTREAD       = 0x01, /* Sent or read message */
55   GSS_NOTSENTREAD    = 0x03, /* Not sent or not read message */
56   GSS_UNKNOWN        = 0x05, /* RTH FIXME: ? */
57   GSS_TEMPLATE       = 0x07  /* Template ? */
58 } GSM_SMSMessageStatus;
59
60 /* SMS Messages sent as... */
61 typedef enum {
62   GSMF_Text   = 0x00, /* Plain text message. */
63   GSMF_Fax    = 0x22, /* Fax message. */
64   GSMF_Voice  = 0x24, /* Voice mail message. */
65   GSMF_ERMES  = 0x25, /* ERMES message. */
66   GSMF_Paging = 0x26, /* Paging. */
67   GSMF_UCI    = 0x2d, /* Email message in 8110i. */
68   GSMF_Email  = 0x32, /* Email message. */
69   GSMF_X400   = 0x31  /* X.400 message. */
70 } GSM_SMSMessageFormat;
71
72 /* Validity of SMS Messages. */
73 /* Ready values for TP-VP. Don't give them for function packing SMS validity
74    (creating TP-VP from validity value in minutes) */
75 typedef enum {
76   GSMV_1_Hour   = 0x0b,
77   GSMV_6_Hours  = 0x47,
78   GSMV_24_Hours = 0xa7,
79   GSMV_72_Hours = 0xa9,
80   GSMV_1_Week   = 0xad,
81   GSMV_Max_Time = 0xff
82 } GSM_SMSMessageValidity;
83
84 /* 7 bit SMS Coding type */
85 typedef enum {
86   GSM_Coding_Unicode = 0x01,
87   GSM_Coding_Default = 0x02,
88   GSM_Coding_8bit    = 0x03
89 } GSM_Coding_Type;
90
91 /* Define datatype for SMS Message Center */
92 typedef struct {
93   int No;                                          /* Number of the SMSC in the phone memory. */
94   char Name[GSM_MAX_SMS_CENTER_NAME_LENGTH];       /* Name of the SMSC. */
95   GSM_SMSMessageFormat Format;                     /* SMS is sent as text/fax/paging/email. */
96   GSM_SMSMessageValidity Validity;                 /* Validity of SMS Message. */
97   char Number[GSM_MAX_SMS_CENTER_LENGTH];          /* Number of the SMSC. */
98   char DefaultRecipient[GSM_MAX_RECIPIENT_LENGTH]; /* Number of default recipient */
99 } GSM_MessageCenter;
100
101 /* Define datatype for Cell Broadcast message */
102 typedef struct {
103   int Channel;                                      /* channel number */
104   char Message[GSM_MAX_CB_MESSAGE + 1];
105   int New;
106 } GSM_CBMessage;
107
108 /* types of User Data Header */
109 typedef enum {
110   GSM_NoUDH,
111   GSM_ConcatenatedMessages,
112   GSM_OpLogo,
113   GSM_CallerIDLogo,
114   GSM_RingtoneUDH,
115   GSM_EnableVoice,
116   GSM_DisableVoice,
117   GSM_EnableEmail,
118   GSM_DisableEmail,
119   GSM_EnableFax,
120   GSM_DisableFax,
121   GSM_VoidSMS,
122   GSM_HangSMS,
123   GSM_BugSMS,
124   GSM_UnknownUDH, //Gnokii doesn't know this UDH
125   GSM_WAPBookmarkUDH,
126   GSM_WAPBookmarkUDHLong,
127   GSM_WAPSettingsUDH,
128   GSM_CalendarNoteUDH,
129   GSM_CalendarNoteUDH2,
130   GSM_PhonebookUDH,
131   GSM_ProfileUDH,
132 } GSM_UDH;
133
134 /* Define datatype for SMS messages, used for getting SMS messages from the
135    phones memory. */
136 typedef struct {
137   GSM_Coding_Type Coding;
138   GSM_DateTime Time;                             /* Date of reception/response of messages. */
139   GSM_DateTime SMSCTime;                         /* Date of SMSC response if DeliveryReport messages. */
140   int Length;                                    /* Length of the SMS message. */
141   int Validity;                                  /* Validity Period of the SMS message. */
142   GSM_UDH UDHType;                               /* If UDH is present - type of UDH */
143   unsigned char UDH[GSM_MAX_USER_DATA_HEADER_LENGTH]; /* If UDH is present - content of UDH */
144   unsigned char MessageText[GSM_MAX_SMS_LENGTH + 1];  /* Room for null term. */
145   GSM_MessageCenter MessageCenter;               /* SMS Center. */
146   char Sender[GSM_MAX_SENDER_LENGTH + 1];        /* Sender of the SMS message. */
147   char Destination[GSM_MAX_DESTINATION_LENGTH+1];/* Destination of the message. */
148   int MessageNumber;                             /* Location in the memory, where SMS is saved */
149   GSM_MemoryType MemoryType;                     /* Type of memory message is stored in. */
150   GSM_SMSMessageType Type;                       /* Type of the SMS message */
151   GSM_SMSMessageStatus Status;                   /* Status of the SMS message */
152   int Class;                                     /* Class Message: 0, 1, 2, 3 or none; see GSM 03.38 */
153   bool Compression;                              /* Indicates whether SMS contains compressed data */
154   int Location;                                  /* Location in the memory, when save SMS */
155   bool ReplyViaSameSMSC;                         /* Indicates whether "Reply via same center" is set */
156   int folder;                                    /* Folder: 0-Inbox,1-Outbox, etc. */
157   bool SMSData;                                  /* if folder contains sender, SMSC number and sending date */
158   unsigned char Name[25+1];                      /* Name in Nokia 6210/7110, etc. Ignored in other */
159 } GSM_SMSMessage;
160
161 typedef struct {
162   int number;
163   GSM_SMSMessage SMS[6];
164 } GSM_MultiSMSMessage;
165
166 /* Maximal number of SMS folders */
167 /* #define MAX_SMS_FOLDERS 10 */
168 #define MAX_SMS_FOLDERS 24
169
170 typedef struct {
171   char Name[15];     /* Name for SMS folder */
172   u8 locations[160]; /* locations of SMS messages in that folder (6210 specific) */
173   u8 number;         /* number of SMS messages in that folder*/
174 } GSM_OneSMSFolder;
175
176 typedef struct {
177   GSM_OneSMSFolder Folder[MAX_SMS_FOLDERS];
178   u8 FoldersID[MAX_SMS_FOLDERS]; // ID specific for this folder and phone.
179                                  // Used in internal functions. Do not use it.
180   u8 number; //number of SMS folders
181 } GSM_SMSFolders;
182
183 /* Identifiers for Smart Messaging 3.0 multipart SMS */
184 #define SM30_ISOTEXT      0 // ISO 8859-1 text
185 #define SM30_UNICODETEXT  1
186 #define SM30_OTA          2
187 #define SM30_RINGTONE     3                      
188 #define SM30_PROFILENAME  4
189 #define SM30_SCREENSAVER  6
190
191 /* TP-Message-Type-Indicator */
192 /* See GSM 03.40 version 6.1.0 Release 1997 Section 9.2.3.1 */
193 typedef enum {                 
194         SMS_Deliver = 0x00, /* when we save SMS in Inbox */
195         SMS_Deliver_Report, 
196         SMS_Status_Report,  /* Delivery Report received by phone */
197         SMS_Command,
198         SMS_Submit,         /* when we send SMS or save it in Outbox */
199         SMS_Submit_Report  
200 } SMS_MessageType;
201
202 /* Structure to hold UDH Header */
203 typedef struct {
204   GSM_UDH UDHType;     /* Type */
205   int Length;          /* Length */
206   unsigned char *Text; /* Text */
207 } GSM_UDHHeader;
208
209 typedef struct {
210   unsigned char MessageText[GSM_MAX_SMS_LENGTH + 1];
211     /* TP-User-Data. See GSM 03.40 section 9.2.3.24. Room for null term. */
212
213   unsigned char Number[GSM_MAX_SENDER_LENGTH + 1];
214  /*In SMS-Deliver       TP-Originating-Address.See GSM 03.40 section 9.2.3.7 */
215  /*In SMS-Submit        TP-Destination-Address.See GSM 03.40 section 9.2.3.8 */
216  /*In SMS-Status-Report TP-Recipient-Address.  See GSM 03.40 section 9.2.3.14*/
217
218   unsigned char SMSCNumber[GSM_MAX_SMS_CENTER_LENGTH];
219     /* SMSC number */
220
221   unsigned char TPPID;
222     /* TP-Protocol-Identifier. See GSM 03.40 section 9.2.3.9 */
223
224   unsigned char TPDCS;
225     /* TP-Data-Coding-Scheme. See GSM 03.40 section 9.2.3.10 */
226
227   unsigned char DeliveryDateTime[7];
228  /* For SMS-Submit        TP-Validity-Period. See GSM 03.40 section 9.2.3.12 */
229  /* For SMS-Status-Report TP-Discharge Time.  See GSM 03.40 section 9.2.3.13 */
230
231   unsigned char SMSCDateTime[7];
232     /* TP-Service-Centre-Time-Stamp in SMS-Status-Report.
233        See GSM 03.40 section 9.2.3.11 */
234
235   unsigned char TPStatus;
236     /* TP-Status in SMS-Status-Report. See GSM 03.40 section 9.2.3.15 */
237
238   unsigned char TPUDL;
239     /* TP-User-Data-Length. See GSM 03.40 section 9.2.3.16 */
240
241   unsigned char TPVP;
242     /* TP-Validity Period in SMS-Submit. See GSM 03.40 section 9.2.3.12 */
243
244   unsigned char TPMR;
245     /* TP-Message Reference in SMS-Submit. See GSM 03.40 section 9.2.3.6 */
246
247   unsigned char firstbyte;
248     /* Byte contains in SMS-Deliver:
249        TP-Message-Type-Indicator     (2 bits) See GSM 03.40 section 9.2.3.1
250
251        TP-More-Messages-To-Send      (1 bit). See GSM 03.40 section 9.2.3.2
252
253        TP-Reply-Path                 (1 bit). See GSM 03.40 section 9.2.3.17
254        TP-User-Data-Header-Indicator (1 bit). See GSM 03.40 section 9.2.3.23
255        TP-Status-Report-Indicator    (1 bit). See GSM 03.40 section 9.2.3.4
256
257        Byte contains in SMS-Submit:
258
259        TP-Message-Type-Indicator     (2 bits) See GSM 03.40 section 9.2.3.1
260
261        TP-Reject-Duplicates          (1 bit). See GSM 03.40 section
262        TP-Validity-Period-Format     (2 bits).See GSM 03.40 section 9.2.3.3
263
264        TP-Reply-Path                 (1 bit). See GSM 03.40 section 9.2.3.17
265        TP-User-Data-Header-Indicator (1 bit). See GSM 03.40 section 9.2.3.23
266        TP-Status-Report-Request      (1 bit). See GSM 03.40 section 9.2.3.5 */
267 } GSM_ETSISMSMessage;
268
269 int   GSM_PackSemiOctetNumber  (u8 *Number, u8 *Output, bool semioctet);
270 char *GSM_UnpackSemiOctetNumber(u8 *Number, bool semioctet);
271
272 int GSM_UnpackEightBitsToSeven(int fillbits, int in_length, int out_length, unsigned char *input, unsigned char *output);
273 int GSM_PackSevenBitsToEight  (int offset, unsigned char *input, unsigned char *output);
274
275 GSM_Error GSM_EncodeETSISMS(GSM_SMSMessage *SMS, GSM_ETSISMSMessage *ETSI, SMS_MessageType PDU, int *length);
276 GSM_Error GSM_DecodeETSISMS(GSM_SMSMessage *SMS, GSM_ETSISMSMessage *ETSI);
277
278 GSM_Error GSM_EncodeSMSDateTime(GSM_DateTime *DT, unsigned char *req);
279
280 GSM_Error GSM_DecodeETSISMSSubmitData(GSM_SMSMessage *SMS, GSM_ETSISMSMessage *ETSI);
281
282 GSM_Error GSM_DecodeETSISMSStatusReportData(GSM_SMSMessage *SMS, GSM_ETSISMSMessage *ETSI);
283
284 void GSM_SetDefaultSMSData(GSM_SMSMessage *SMS);
285 GSM_Error EncodeUDHHeader(char *text, GSM_UDH UDHType);
286
287 int GSM_MakeSinglePartSMS2(GSM_SMSMessage *SMS,
288     unsigned char *MessageBuffer,int cur, GSM_UDH UDHType, GSM_Coding_Type Coding);
289 void GSM_MakeMultiPartSMS2(GSM_MultiSMSMessage *SMS,
290     unsigned char *MessageBuffer,int MessageLength, GSM_UDH UDHType, GSM_Coding_Type Coding);
291
292 #endif  /* __gsm_sms_h */