4 * Copyright (c) 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Kyeongchul Kim <kyeongchul.kim@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #ifndef __TET_SMS_UTIL_H_
23 #define __TET_SMS_UTIL_H_
25 #include "ITapiNetText.h"
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
37 #define MAX_UDH_LEN 137
39 #define SMDATA_SIZE_MAX 160
44 //////////////////////////////////TPDU type////////////////////////////////
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
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,
65 * tapi_nettext_vp_type
66 * This enumeration defines the validity period type.
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,
75 } tapi_nettext_vp_type;
78 * tapi_nettext_coding_group_type
79 This enum defined the different sms coding group types
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 */
96 TAPI_NETTEXT_CODGRP_MAX
97 } tapi_nettext_coding_group_type;
100 * tapi_nettext_waiting_type
101 Defines different types of waiting indicators
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 */
109 TAPI_NETTEXT_WAITING_MAX
110 } tapi_nettext_waiting_type;
113 * tapi_nettext_alphabet_type
114 Defines different alphabet types of an sms
117 TAPI_NETTEXT_ALPHABET_DEFAULT, /**< GSM alphabet default 7bit */
118 TAPI_NETTEXT_ALPHABET_8BIT, /**< 8bit */
119 TAPI_NETTEXT_ALPHABET_UCS2, /**< 16bit ucs2 */
121 TAPI_NETTEXT_ALPHABET_KSC5601, /**< for Korean */
123 TAPI_NETTEXT_ALPHABET_MAX
124 } tapi_nettext_alphabet_type;
127 * tapi_nettext_class_type
128 This enum defines the different classes of SMS which indicates the
129 type of storage of the sms.
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,
138 TAPI_NETTEXT_CLASS_MAX
139 } tapi_nettext_class_type;
142 This structure contains the information related to sms coding schemes
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;
156 * tapi_nettext_vp_rel_Value
157 * This structure defines the validity period types.
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;
171 This structure contains all the information
172 related to validity period of a message.
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 */
181 /* This structure contains the details of delete status notification, which comes after calling
182 tel_delete_sms_in_simMsg*/
186 } tel_delete_sms_in_simMsg_status_ind;
189 /* This structure contains the details of save status notification, which comes after calling
190 tel_write_sms_in_simMsg*/
195 } tapi_nettext_save_status_ind;
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 */
211 #define SET_TON_NPI(dest, ton, npi) { \
213 dest |= (ton & 0x07) << 4; \
214 dest |= npi & 0x0F; \
218 /************HEADER************/
221 SmsTPDUType msg_type; //bit 0 ,1
223 // reject duplicates [M]
226 // validity period format [M]
227 tapi_nettext_vp_type vpf; // bits 3, 4
232 // user data header indication
233 TS_BOOL udhi; //bit 6
235 // status report request
236 TS_BOOL srr; // bit 5
238 /************BODY************/
240 //message reference [M]
243 // destination address [M]
244 TelSmsAddressInfo_t desAddr;
246 // protocol identifier [M]
249 // data coding scheme [M]
250 tapi_nettext_coding_scheme dcs;
255 // user data length [M]
264 /************HEADER************/
267 SmsTPDUType msg_type; //bit 0 ,1
269 // user data header indication
270 TS_BOOL udhi; //bit 6
272 /************BODY************/
277 // parameter indicator [M]
280 // service centre time stamp [M]
283 // protocol identifier [M]
286 // data coding scheme
287 tapi_nettext_coding_scheme dcs;
289 // user data length [M]
295 } TPDU_SMS_SUBMIT_REPORT;
298 /************HEADER************/
299 SmsTPDUType msg_type; //bit 0 ,1
301 TS_BOOL mms; // bit 2
305 TS_BOOL udhi; //bit 6
307 TS_BOOL sri; // bit , 5status_report_indication
309 /************BODY************/
311 TelSmsAddressInfo_t orgAddr;
317 tapi_nettext_coding_scheme dcs;
326 /************HEADER************/
327 SmsTPDUType msg_type; //bit 0 ,1
329 TS_BOOL udhi; //bit 6
331 /************BODY************/
339 tapi_nettext_coding_scheme dcs;
345 } TPDU_SMS_DELIVER_REPORT;
348 /************HEADER************/
349 SmsTPDUType msg_type; //bit 0 ,1
351 TS_BOOL udhi; //bit 6
353 TS_BOOL srr; //bit 5, status_report_request
355 /************BODY************/
357 TS_UINT mr; //message_ref
365 TelSmsAddressInfo_t destAddr;
374 /************HEADER************/
376 SmsTPDUType msg_type; //bit 0 ,1
378 TS_BOOL udhi; //bit 6
382 TS_BOOL srq; //bit 5, status_report_qualifier
384 /************BODY************/
388 TelSmsAddressInfo_t rcpAddr; //recipient_addr
392 TmDateTime dt; //discharge_time
400 tapi_nettext_coding_scheme dcs;
406 } TPDU_SMS_STATUS_REPORT;
408 /**************************************************************************************
409 *** (main.c) function header****************************************************************
410 ***************************************************************************************
411 ***************************************************************************************/
415 int ReceiveMessage(int pdu_len, char * pPDU);
416 int GetInformation();
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);
427 /***************************************************************************************/
428 void reverse(char* x, int len);
429 char* AcItoa(int n, char* str, int b);
430 int AcToupper(int ch);
432 char* SmsUtilUnpackGSMCode(char* szData, const TS_BYTE* pIn, int in_len);
433 int SmsUtilPackGSMCode(TS_BYTE* pOut, const char* szData, int in_len);
435 void SmsUtilConvertBCD2Digit(char* pDigits, char* pBCD, int digitLen);
436 void SmsUtilConvertDigit2BCD(char* pBCD, char* pDigits, int digitLen);
438 TmDateTime* SmsUtilDecodeTimeStamp(unsigned char* pTimeStamp, TmDateTime *tmDateTime);
439 unsigned char* SmsUtilEncodeTimeStamp(TmDateTime* tmDateTime, unsigned char* pTimeStamp);
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);
444 int SmsUtilDecodeScAddrField(TelSmsAddressInfo_t* pSmsAddrField, TS_BYTE* pAddrField);
445 int SmsUtilEncodeScAddrField(TS_BYTE* pAddrField, TelSmsAddressInfo_t * pSmsAddrField);
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);
451 void PrepareMessage(TelSmsDatapackageInfo_t *pDataPackage);