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