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.
24 #include <pthread.h> /* pthread functions and data structures */
31 #include "TelDefines.h"
33 #include "ITapiNetText.h"
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
48 #define MAX_UDH_LEN 137
50 #define SMDATA_SIZE_MAX 160
55 //////////////////////////////////TPDU type////////////////////////////////
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
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,
80 * tapi_nettext_vp_type
81 * This enumeration defines the validity period type.
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,
91 } tapi_nettext_vp_type;
93 * tapi_nettext_coding_group_type
94 This enum defined the different sms coding group types
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 */
112 TAPI_NETTEXT_CODGRP_MAX
113 } tapi_nettext_coding_group_type;
115 * tapi_nettext_waiting_type
116 Defines different types of waiting indicators
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 */
125 TAPI_NETTEXT_WAITING_MAX
126 } tapi_nettext_waiting_type;
128 * tapi_nettext_alphabet_type
129 Defines different alphabet types of an sms
133 TAPI_NETTEXT_ALPHABET_DEFAULT, /**< GSM alphabet default 7bit */
134 TAPI_NETTEXT_ALPHABET_8BIT, /**< 8bit */
135 TAPI_NETTEXT_ALPHABET_UCS2, /**< 16bit ucs2 */
137 TAPI_NETTEXT_ALPHABET_KSC5601, /**< for Korean */
139 TAPI_NETTEXT_ALPHABET_MAX
140 } tapi_nettext_alphabet_type;
142 * tapi_nettext_class_type
143 This enum defines the different classes of SMS which indicates the
144 type of storage of the sms.
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,
154 TAPI_NETTEXT_CLASS_MAX
155 } tapi_nettext_class_type;
158 This structure contains the information related to sms coding schemes
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;
173 * tapi_nettext_vp_rel_Value
174 * This structure defines the validity period types.
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;
188 This structure contains all the information
189 related to validity period of a message.
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 */
200 /* This structure contains the details of delete status notification, which comes after calling
201 TelTapiSmsDeleteMsg*/
206 }TelTapiSmsDeleteMsg_status_ind;
209 /* This structure contains the details of save status notification, which comes after calling
216 }tapi_nettext_save_status_ind;
231 #define BASE_YEAR 70L /* 1970 is the base year */
232 #define MAX_YEAR 130L /* 2030 is the max year */
235 #define SIM_SMSP_ADDRESS_LEN 20 // digit length
237 #define SET_TON_NPI(dest, ton, npi) { \
239 dest |= (ton & 0x07) << 4; \
240 dest |= npi & 0x0F; \
248 /************HEADER************/
251 SmsTPDUType msg_type ; //bit 0 ,1
253 // reject duplicates [M]
254 TS_BOOL rd ; // bit 2
256 // validity period format [M]
257 tapi_nettext_vp_type vpf ; // bits 3, 4
262 // user data header indication
263 TS_BOOL udhi ; //bit 6
265 // status report request
266 TS_BOOL srr ; // bit 5
268 /************BODY************/
270 //message reference [M]
273 // destination address [M]
274 TelSmsAddressInfo_t desAddr;
276 // protocol identifier [M]
279 // data coding scheme [M]
280 tapi_nettext_coding_scheme dcs;
285 // user data length [M]
296 /************HEADER************/
299 SmsTPDUType msg_type; //bit 0 ,1
301 // user data header indication
302 TS_BOOL udhi ; //bit 6
304 /************BODY************/
309 // parameter indicator [M]
312 // service centre time stamp [M]
315 // protocol identifier [M]
318 // data coding scheme
319 tapi_nettext_coding_scheme dcs;
321 // user data length [M]
327 }TPDU_SMS_SUBMIT_REPORT;
332 /************HEADER************/
333 SmsTPDUType msg_type; //bit 0 ,1
335 TS_BOOL mms; // bit 2
339 TS_BOOL udhi; //bit 6
341 TS_BOOL sri; // bit , 5status_report_indication
343 /************BODY************/
345 TelSmsAddressInfo_t orgAddr;
351 tapi_nettext_coding_scheme dcs;
361 /************HEADER************/
362 SmsTPDUType msg_type ; //bit 0 ,1
364 TS_BOOL udhi ; //bit 6
366 /************BODY************/
374 tapi_nettext_coding_scheme dcs;
380 }TPDU_SMS_DELIVER_REPORT;
385 /************HEADER************/
386 SmsTPDUType msg_type ; //bit 0 ,1
388 TS_BOOL udhi ; //bit 6
390 TS_BOOL srr; //bit 5, status_report_request
392 /************BODY************/
394 TS_UINT mr; //message_ref
402 TelSmsAddressInfo_t destAddr;
413 /************HEADER************/
415 SmsTPDUType msg_type ; //bit 0 ,1
417 TS_BOOL udhi ; //bit 6
419 TS_BOOL mms ; //bit 2
421 TS_BOOL srq; //bit 5, status_report_qualifier
423 /************BODY************/
427 TelSmsAddressInfo_t rcpAddr; //recipient_addr
431 TmDateTime dt; //discharge_time
439 tapi_nettext_coding_scheme dcs;
445 }TPDU_SMS_STATUS_REPORT;
447 /**************************************************************************************
448 *** (main.c) function header****************************************************************
449 ***************************************************************************************
450 ***************************************************************************************/
454 int ReceiveMessage(int pdu_len, char * pPDU);
455 int GetInformation();
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);
466 /***************************************************************************************/
467 void reverse(char* x, int len);
468 char* AcItoa(int n, char* str, int b) ;
469 int AcToupper(int ch);
471 char* SmsUtilUnpackGSMCode(char* szData, const char* pIn, int in_len );
472 int SmsUtilPackGSMCode( TS_BYTE* pOut, const char* szData, int in_len );
474 void SmsUtilConvertBCD2Digit( char* pDigits, char* pBCD, int digitLen );
475 void SmsUtilConvertDigit2BCD( char* pBCD, char* pDigits, int digitLen );
477 TmDateTime* SmsUtilDecodeTimeStamp(char* pTimeStamp, TmDateTime *tmDateTime );
478 unsigned char* SmsUtilEncodeTimeStamp( TmDateTime* tmDateTime, unsigned char* pTimeStamp );
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 );
484 int SmsUtilDecodeScAddrField( TelSmsAddressInfo_t* pSmsAddrField, TS_BYTE* pAddrField );
485 int SmsUtilEncodeScAddrField( TS_BYTE* pAddrField, TelSmsAddressInfo_t * pSmsAddrField );
487 void SmsUtilDecodeDCS( tapi_nettext_coding_scheme* pCodingScheme, unsigned char dcs );
488 void SmsUtilEncodeDCS( TS_BYTE* pDCS, tapi_nettext_coding_scheme* pCodingScheme);
490 TS_UINT8 SmsUtilEncodeValidity( TS_BYTE* pValidity, tapi_nettext_vp* pVP );