code clean up and update SIM -authentication feature
[framework/telephony/libslp-tapi.git] / TC / telephony_TC / sms / unit / sms_util.h
1 /*
2  * libslp-tapi
3  *
4  * Copyright (c) 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Kyeongchul Kim <kyeongchul.kim@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20
21
22 #ifndef __TET_SMS_UTIL_H_
23 #define __TET_SMS_UTIL_H_
24
25 #include "ITapiNetText.h"
26
27 #define SIM_TON_UNKNOWN                                 0 //unknown
28 #define SIM_TON_INTERNATIONAL                   1 //international number
29 #define SIM_TON_NATIONAL                                2 //national number
30 #define SIM_TON_NETWORK_SPECIFIC                3 //natwork specific number
31 #define SIM_TON_DEDICATED_ACCESS                4 //subscriber number
32 #define SIM_TON_ALPHA_NUMERIC                   5//alphanumeric, GSM 7-bit default alphabet)
33 #define SIM_TON_ABBREVIATED_NUMBER              6 //abbreviated number
34 #define SIM_TON_RESERVED_FOR_EXT                7 //reserved for extension
35
36
37 #define MAX_UDH_LEN             137
38 #define UDH_MAX                 7
39 #define SMDATA_SIZE_MAX 160
40
41 #define FAIL                    0x00
42 #define SUCCESS         0x01
43
44 //////////////////////////////////TPDU type////////////////////////////////
45 typedef enum {
46         SMS_TPDU_DELIVER                        = 0x00, // sc -> ms
47         SMS_TPDU_DELIVER_REPORT         = 0x00, // ms -> sc
48         SMS_TPDU_SUBMIT                         = 0x01, // ms -> sc
49         SMS_TPDU_SUBMIT_REPORT          = 0x01, // sc -> ms
50         SMS_TPDU_STATUS_REPORT          = 0x02, // sc -> ms
51         SMS_TPDU_COMMAND                        = 0x02, // ms -> sc
52         SMS_PDU_INVALID_TYPE
53 } SmsTPDUType;
54
55 typedef enum {
56         SMS_DAEMON_UNKNOWN_MESSAGE,
57         SMS_DAEMON_RECEIVED_UNREAD_MESSAGE,
58         SMS_DAEMON_RECEIVED_READ_MESSAGE,
59         SMS_DAEMON_UNSENT_MESSAGE,
60         SMS_DAEMON_STORED_SENT_MESSAGE,
61 } sd_message_status;
62
63
64 /*
65  * tapi_nettext_vp_type
66  * This enumeration defines the validity period type.
67  */
68 typedef enum {
69         TAPI_NETTEXT_VP_NOT_USED = 0,           /**< validity period not used */
70         TAPI_NETTEXT_VP_RELATIVE = 2,           /**< after a predetermined time period after the service center has received the message */
71         TAPI_NETTEXT_VP_ABSOLUTE = 3,
72         TAPI_NETTEXT_VP_ENHANCED = 1,
73
74         TAPI_NETTEXT_VP_MAX
75 } tapi_nettext_vp_type;
76
77 /*
78  * tapi_nettext_coding_group_type
79  This enum defined the different sms coding group types
80  */
81 typedef enum {
82         TAPI_NETTEXT_CODGRP_SM_GENERAL_DCS,                     /**< Bits 7..4 00xx */
83         TAPI_NETTEXT_CODGRP_CB_GENERAL_LANG,            /**< 0000 */
84         TAPI_NETTEXT_CODGRP_CB_ALPHA,                           /**< 0001 */
85         TAPI_NETTEXT_CODGRP_CB_RES1,                            /**< 0010 */
86         TAPI_NETTEXT_CODGRP_CB_RES2,                            /**< 0011 */
87         TAPI_NETTEXT_CODGRP_SM_AUTO_DELETION,           /**< 01xx Bits 5..0 are coded the same as SM_GENERAL_DCS */
88         TAPI_NETTEXT_CODGRP_CB_GENERAL_DCS,                     /**< 01xx behavior is as SM_GENERAL_DCS */
89         TAPI_NETTEXT_CODGRP_SM_WAITING_DISCARD,         /**< 1100 */
90         TAPI_NETTEXT_CODGRP_SM_WAITING_STORE,           /**< 1101 */
91         TAPI_NETTEXT_CODGRP_SM_WAITING_STORE_UCS2,      /**< 1110 */
92         TAPI_NETTEXT_CODGRP_CB_WAP,                                     /**< 1110 Cell Broadcast */
93         TAPI_NETTEXT_CODGRP_SM_CLASS_CODING,            /**< 1111 */
94         TAPI_NETTEXT_CODGRP_CB_CLASS_CODING,            /**< 1111 Cell Broadcast */
95
96         TAPI_NETTEXT_CODGRP_MAX
97 } tapi_nettext_coding_group_type;
98
99 /*
100  *  tapi_nettext_waiting_type
101  Defines different types of waiting indicators
102  */
103 typedef enum {
104         TAPI_NETTEXT_WAITING_VOICE_MSG,         /**< voice message waiting */
105         TAPI_NETTEXT_WAITING_FAX_MSG,           /**< FAX message waiting */
106         TAPI_NETTEXT_WAITING_EMAIL_MSG,         /**< E-mail waiting */
107         TAPI_NETTEXT_WAITING_OTHER_MSG,         /**< Other message waiting */
108
109         TAPI_NETTEXT_WAITING_MAX
110 } tapi_nettext_waiting_type;
111
112 /*
113  * tapi_nettext_alphabet_type
114  Defines different alphabet types of an sms
115  */
116 typedef enum {
117         TAPI_NETTEXT_ALPHABET_DEFAULT,  /**< GSM alphabet default 7bit */
118         TAPI_NETTEXT_ALPHABET_8BIT,             /**< 8bit */
119         TAPI_NETTEXT_ALPHABET_UCS2,             /**< 16bit ucs2 */
120
121         TAPI_NETTEXT_ALPHABET_KSC5601,  /**< for Korean */
122
123         TAPI_NETTEXT_ALPHABET_MAX
124 } tapi_nettext_alphabet_type;
125
126 /*
127  * tapi_nettext_class_type
128  This enum defines the different classes of SMS which indicates the
129  type of storage of the sms.
130  */
131 typedef enum {
132         TAPI_NETTEXT_CLASS_0,   /**< display immediately */
133         TAPI_NETTEXT_CLASS_1,   /**< may be stored */
134         TAPI_NETTEXT_CLASS_2,   /**< store in SIM */
135         TAPI_NETTEXT_CLASS_3,   /**< transfer to TE */
136         TAPI_NETTEXT_CLASS_NONE,
137
138         TAPI_NETTEXT_CLASS_MAX
139 } tapi_nettext_class_type;
140
141 /*
142 This structure contains the information related to sms coding schemes
143
144 */
145 typedef struct {
146         TS_BOOL                                                 bCompressed;            /**< if text is compressed this is TRUE */
147         TS_BOOL                                                 bmsg_class_set;         /**< message class indication. if TRUE = bits 1..0, if FALSE = reserved */
148         TS_BOOL                                                 bmsg_ind_active;                /**< message indication group. if TRUE = on, FALSE = off */
149         tapi_nettext_coding_group_type  coding_group_type;      /**< Coding group, GSM 03.38 */
150         tapi_nettext_waiting_type               waiting_type;           /**< Type of message waiting */
151         tapi_nettext_alphabet_type              alphabet_type;          /**< How to encode a message. */
152         tapi_nettext_class_type                 class_type;                     /**< The message class */
153 } tapi_nettext_coding_scheme;
154
155 /*
156  *  tapi_nettext_vp_rel_Value
157  * This structure defines the validity period types.
158  */
159 typedef enum {
160         TAPI_NETTEXT_VP_REL_1H,         /**< One hour */
161         TAPI_NETTEXT_VP_REL_6H,         /**< Six hours */
162         TAPI_NETTEXT_VP_REL_12H,        /**< Twelve hours */
163         TAPI_NETTEXT_VP_REL_1D,         /**< One day */
164         TAPI_NETTEXT_VP_REL_3D,         /**< Three days */
165         TAPI_NETTEXT_VP_REL_1W,         /**< One week */
166         TAPI_NETTEXT_VP_REL_1M,         /**< One Month */
167         TAPI_NETTEXT_VP_REL_MAX         /**< Max = 63 weeks */
168 } tapi_nettext_vp_rel_Value;
169
170 /*
171 This structure contains all the information
172 related to validity period of a message.
173 */
174 typedef struct {
175         tapi_nettext_vp_type vp_type;                   /**< Validity period format */
176         tapi_nettext_vp_rel_Value vp_rel_type;  /**< Validity period value duration the message must retain in the service center while application attempts delivery */
177         TS_UINT32 vpValue;                                              /** Validity period value */
178 } tapi_nettext_vp;
179
180
181 /* This structure contains the details of delete status notification, which comes after calling
182  tel_delete_sms_in_simMsg*/
183 typedef struct {
184         TS_UINT16 result;
185         TS_UINT8 index;
186 } tel_delete_sms_in_simMsg_status_ind;
187
188
189 /* This structure contains the details of save status notification, which comes after calling
190  tel_write_sms_in_simMsg*/
191
192 typedef struct {
193         TS_UINT16 result;
194         TS_UINT8 index;
195 } tapi_nettext_save_status_ind;
196
197 typedef struct {
198         int year;
199         int month;
200         int day;
201         int hour;
202         int minute;
203         int second;
204 } TmDateTime;
205
206
207 #define BASE_YEAR                               70L             /* 1970 is the base year */
208 #define MAX_YEAR                                130L    /* 2030 is the max year */
209 #define SIM_SMSP_ADDRESS_LEN    20              /* digit length */
210
211 #define SET_TON_NPI(dest, ton, npi) {   \
212         dest = 0x80;                                            \
213         dest |= (ton & 0x07) << 4;                      \
214         dest |= npi & 0x0F;                                     \
215 }
216
217 typedef struct {
218         /************HEADER************/
219
220         // message type [M]
221         SmsTPDUType msg_type; //bit 0 ,1
222
223         // reject duplicates [M]
224         TS_BOOL rd; // bit 2
225
226         // validity period format [M]
227         tapi_nettext_vp_type vpf; //  bits 3, 4
228
229         // reply path [M]
230         TS_BOOL rp; //bit 7
231
232         // user data header indication
233         TS_BOOL udhi; //bit 6
234
235         // status report request
236         TS_BOOL srr; // bit 5
237
238         /************BODY************/
239
240         //message reference [M]
241         TS_UINT mr;
242
243         // destination address [M]
244         TelSmsAddressInfo_t desAddr;
245
246         // protocol identifier [M]
247         TS_BYTE pId;
248
249         // data coding scheme [M]
250         tapi_nettext_coding_scheme dcs;
251
252         // validity period
253         tapi_nettext_vp vp;
254
255         // user data length [M]
256         TS_UINT udl;
257
258         // user data
259         TS_BYTE * userData;
260
261 } TPDU_SMS_SUBMIT;
262
263 typedef struct {
264         /************HEADER************/
265
266         // message type [M]
267         SmsTPDUType msg_type; //bit 0 ,1
268
269         // user data header indication
270         TS_BOOL udhi; //bit 6
271
272         /************BODY************/
273
274         // failure Cause [M]
275         TS_UINT fcs;
276
277         // parameter indicator [M]
278         TS_BYTE paraInd;
279
280         // service centre time stamp [M]
281         TmDateTime scts;
282
283         // protocol identifier [M]
284         TS_BYTE pId;
285
286         // data coding scheme
287         tapi_nettext_coding_scheme dcs;
288
289         // user data length [M]
290         TS_UINT udl;
291
292         // user data
293         TS_BYTE * userData;
294
295 } TPDU_SMS_SUBMIT_REPORT;
296
297 typedef struct {
298         /************HEADER************/
299         SmsTPDUType msg_type; //bit 0 ,1
300
301         TS_BOOL mms; // bit 2
302
303         TS_BOOL rp; // bit 7
304
305         TS_BOOL udhi; //bit 6
306
307         TS_BOOL sri; // bit , 5status_report_indication
308
309         /************BODY************/
310
311         TelSmsAddressInfo_t orgAddr;
312
313         TS_BYTE pId;
314
315         TmDateTime scts;
316
317         tapi_nettext_coding_scheme dcs;
318
319         TS_UINT udl;
320
321         TS_BYTE * userData;
322
323 } TPDU_SMS_DELIVER;
324
325 typedef struct {
326         /************HEADER************/
327         SmsTPDUType msg_type; //bit 0 ,1
328
329         TS_BOOL udhi; //bit 6
330
331         /************BODY************/
332
333         TS_UINT fcs;
334
335         TS_BYTE paraInd;
336
337         TS_BYTE pId;
338
339         tapi_nettext_coding_scheme dcs;
340
341         TS_UINT udl;
342
343         TS_BYTE * userData;
344
345 } TPDU_SMS_DELIVER_REPORT;
346
347 typedef struct {
348         /************HEADER************/
349         SmsTPDUType msg_type; //bit 0 ,1
350
351         TS_BOOL udhi; //bit 6
352
353         TS_BOOL srr; //bit 5, status_report_request
354
355         /************BODY************/
356
357         TS_UINT mr; //message_ref
358
359         TS_BYTE pId;
360
361         TS_BYTE cmdType;
362
363         TS_BYTE msgNum;
364
365         TelSmsAddressInfo_t destAddr;
366
367         TS_UINT udl;
368
369         TS_BYTE * userData;
370
371 } TPDU_SMS_COMMAND;
372
373 typedef struct {
374         /************HEADER************/
375
376         SmsTPDUType msg_type; //bit 0 ,1
377
378         TS_BOOL udhi; //bit 6
379
380         TS_BOOL mms; //bit 2
381
382         TS_BOOL srq; //bit 5, status_report_qualifier
383
384         /************BODY************/
385
386         TS_UINT mr;
387
388         TelSmsAddressInfo_t rcpAddr; //recipient_addr
389
390         TmDateTime scts;
391
392         TmDateTime dt; //discharge_time
393
394         TS_BYTE status;
395
396         TS_BYTE paraInd;
397
398         TS_BYTE pId;
399
400         tapi_nettext_coding_scheme dcs;
401
402         TS_UINT udl;
403
404         TS_BYTE * userData;
405
406 } TPDU_SMS_STATUS_REPORT;
407
408 /**************************************************************************************
409 *** (main.c) function header****************************************************************
410 ***************************************************************************************
411 ***************************************************************************************/
412 int SendMessage();
413 int ReadMessage();
414 int DeleteMessage();
415 int ReceiveMessage(int pdu_len, char * pPDU);
416 int GetInformation();
417 int Setting();
418
419 TS_BOOL DecodeCellBroadcastMsg(int length, char * pPDU);
420 TS_BOOL EncodeSmsSubmitTpdu(char* diallingNum, int dialNumLen, char* msg, int msg_len);
421 TS_BOOL DecodeSmsSubmitTpdu(int pdu_len, char * pPDU);
422 int DecodeSmsDeliverTpdu(int pdu_len, char * pPDU);
423 TS_BOOL EncodeSmsDeliverReportTpdu();
424 TS_BOOL DecodeSmsSubmitReportTpdu(int length, char *data);
425 TS_BOOL DecodeSmsStatusReportTpdu(int pdu_len, char * pPDU);
426
427 /***************************************************************************************/
428 void reverse(char* x, int len);
429 char* AcItoa(int n, char* str, int b);
430 int AcToupper(int ch);
431
432 char* SmsUtilUnpackGSMCode(char* szData, const TS_BYTE* pIn, int in_len);
433 int SmsUtilPackGSMCode(TS_BYTE* pOut, const char* szData, int in_len);
434
435 void SmsUtilConvertBCD2Digit(char* pDigits, char* pBCD, int digitLen);
436 void SmsUtilConvertDigit2BCD(char* pBCD, char* pDigits, int digitLen);
437
438 TmDateTime* SmsUtilDecodeTimeStamp(unsigned char* pTimeStamp, TmDateTime *tmDateTime);
439 unsigned char* SmsUtilEncodeTimeStamp(TmDateTime* tmDateTime, unsigned char* pTimeStamp);
440
441 void SmsUtilDecodeAddrField(char *diallingNum, unsigned char * pAddrField, int *result_ton, int *result_npi);
442 int SmsUtilEncodeAddrField(unsigned char* pAddrField, char* diallingNum, int dialnumLen, int ton, int npi);
443
444 int SmsUtilDecodeScAddrField(TelSmsAddressInfo_t* pSmsAddrField, TS_BYTE* pAddrField);
445 int SmsUtilEncodeScAddrField(TS_BYTE* pAddrField, TelSmsAddressInfo_t * pSmsAddrField);
446
447 void SmsUtilDecodeDCS(tapi_nettext_coding_scheme* pCodingScheme, unsigned char dcs);
448 void SmsUtilEncodeDCS(TS_BYTE* pDCS, tapi_nettext_coding_scheme* pCodingScheme);
449 TS_UINT8 SmsUtilEncodeValidity(TS_BYTE* pValidity, tapi_nettext_vp* pVP);
450
451 void PrepareMessage(TelSmsDatapackageInfo_t *pDataPackage);
452
453 #endif
454
455