2 * Telephony test application
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Ja-young Gu <jygu@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 #define MAX_UDH_LEN 137
34 #define SMS_SMSP_ALPHA_ID_LEN_MAX 128 /* EF-SMSP alpha id length */
36 #define SMS_MSG_SIZE_MAX 918
37 #define SMS_CB_SIZE_MAX 93
38 #define SMS_ADDRESS_LEN_MAX 20
39 #define SMS_SCADDRESS_LEN_MAX 18
41 #define SMS_CB_PAGE_SIZE_MAX 9 /**< CB maximum page size*/
42 #define SMS_GSM_SMS_MSG_NUM_MAX 255 /**< Maximum GSM SMS message number*/
43 #define SMS_GSM_SMS_CBMI_LIST_SIZE_MAX 50 /**< Maximum GSM SMS CBMI list size*/
44 #define SMS_SMDATA_SIZE_MAX 165 /**< Maximum SMS data size that can be stored*/
45 #define SMS_MAX_SMS_SERVICE_CENTER_ADDR 12 /**<Maximum SMS service center address*/
46 #define SMS_MAX_INDEX 25 /**< Maximum index value for SMS */
53 SMS_STATUS_READ, /**< MT message, stored and read */
54 SMS_STATUS_UNREAD, /**< MT message, stored and unread */
55 SMS_STATUS_SENT, /**< MO message, stored and sent */
56 SMS_STATUS_UNSENT, /**< MO message, stored but not sent */
57 SMS_STATUS_DELIVERED, /**< delivered destination */
58 SMS_STATUS_DELIVERY_UNCONFIRMED, /**< Service centre forwarded message but is unable to confirm delivery*/
59 SMS_STATUS_MESSAGE_REPLACED, /**< Message has been replaced*/
60 SMS_STATUS_RESERVED /**< Reserved for future use*/
65 SMS_SENDSMS_SUCCESS = 0x00, /**<Message send success*/
66 SMS_ROUTING_NOT_AVAILABLE, /**< Message routing not available*/
67 SMS_INVALID_PARAMETER, /**< Invalid parameter present in TPDU*/
68 SMS_DEVICE_FAILURE, /**< Device failure*/
69 SMS_SERVICE_RESERVED, /**< Reserved Service*/
70 SMS_INVALID_LOCATION, /**< Invalid location*/
71 SMS_NO_SIM, /**< No SIM error*/
72 SMS_SIM_NOT_READY, /**< SIM not ready error*/
73 SMS_NO_NETWORK_RESP, /**< No response from network*/
74 SMS_DEST_ADDRESS_FDN_RESTRICTED, /**< Destination address restricted*/
75 SMS_SCADDRESS_FDN_RESTRICTED, /**< Service center address restricted*/
76 SMS_RESEND_ALREADY_DONE, /**< Resend a operation already done*/
77 SMS_SCADDRESS_NOT_AVAILABLE, /**< SCA address not available*/
78 SMS_UNASSIGNED_NUMBER = 0x8001, /**< Unassigned number*/
79 SMS_OPERATOR_DETERMINED_BARRING = 0x8008, /**< Operator determined barring*/
80 SMS_CALL_BARRED = 0x800A, /**< Call barred*/
81 SMS_MESSAGE_TRANSFER_REJECTED = 0x8015, /**< Message transfer rejected*/
82 SMS_MEMORY_CAPACITY_EXCEEDED = 0x8016, /**< Memory capacity exceeded/memory full*/
83 SMS_DESTINAITION_OUTOFSERVICE = 0x801B, /**< Destination number/address out of service*/
84 SMS_UNSPECIFIED_SUBSCRIBER = 0x801C, /**< Unspecified subscriber*/
85 SMS_FACILITY_REJECTED = 0x801D, /**< Facility rejected*/
86 SMS_UNKNOWN_SUBSCRIBER = 0x801E, /**< Unknown subscriber*/
87 SMS_NETWORK_OUTOFORDER = 0x8026, /**< Network out of order*/
88 SMS_TEMPORARY_FAILURE = 0x8029, /**< Temporary failure*/
89 SMS_CONGESTION = 0x802A, /**< Congestion happened*/
90 SMS_RESOURCES_UNAVAILABLE = 0x802F, /**< Resource unavailable*/
91 SMS_FACILITY_NOT_SUBSCRIBED = 0x8032, /**< Facility not subscribed by the user*/
92 SMS_FACILITY_NOT_IMPLEMENTED = 0x8045, /**< Facility not implemented*/
93 SMS_INVALID_REF_VALUE = 0x8051, /**< Invalid reference value*/
94 SMS_INVALID_MSG = 0x805F, /**< Invalid message*/
95 SMS_INVALID_MANDATORY_INFO = 0x8060, /**< Invalid Mandatory information*/
96 SMS_MESSAGE_TYPE_NOT_IMPLEMENTED = 0x8061, /**< Message type not implemented*/
97 SMS_MESSAGE_NOT_COMPAT_PROTOCOL = 0x8062, /**< Message not compact protocol*/
98 SMS_IE_NOT_IMPLEMENTED = 0x8063, /**< Information element not implemented*/
99 SMS_PROTOCOL_ERROR = 0x806F, /**< Protocol error*/
100 SMS_INTERWORKING = 0x807F, /**< Networking error*/
101 SMS_ME_FULL = 0x8080, /**< SMS ME FULL */
102 SMS_SIM_FULL = 0x8081, /**< SMS SIM FULL */
103 SMS_TIMEOUT /**< Timeout error */
106 //////////////////////////////////TPDU type////////////////////////////////
109 SMS_TPDU_DELIVER = 0x00, // sc -> ms
110 SMS_TPDU_DELIVER_REPORT = 0x00, // ms -> sc
111 SMS_TPDU_SUBMIT = 0x01, // ms -> sc
112 SMS_TPDU_SUBMIT_REPORT = 0x01, // sc -> ms
113 SMS_TPDU_STATUS_REPORT = 0x02, // sc -> ms
114 SMS_TPDU_COMMAND = 0x02, // ms -> sc
121 SMS_DAEMON_UNKNOWN_MESSAGE,
122 SMS_DAEMON_RECEIVED_UNREAD_MESSAGE,
123 SMS_DAEMON_RECEIVED_READ_MESSAGE,
124 SMS_DAEMON_UNSENT_MESSAGE,
125 SMS_DAEMON_STORED_SENT_MESSAGE,
131 SMS_TON_UNKNOWN = 0, /**< unknown */
132 SMS_TON_INTERNATIONAL=1, /**< international number */
133 SMS_TON_NATIONAL = 2, /**< national number */
134 SMS_TON_NETWORK_SPECIFIC = 3, /**< network specific number */
135 SMS_TON_DEDICATED_ACCESS = 4, /**< subscriber number */
136 SMS_TON_ALPHA_NUMERIC = 5, /**< alphanumeric, GSM 7-bit default alphabet) */
137 SMS_TON_ABBREVIATED_NUMBER = 6, /**< abbreviated number */
138 SMS_TON_RESERVED_FOR_EXT = 7 /**< reserved for extension */
143 SMS_NPI_UNKNOWN = 0, /**< Unknown */
144 SMS_NPI_ISDN_TEL = 1, /**< ISDN/Telephone numbering plan */
145 SMS_NPI_DATA_NUMBERING_PLAN = 3, /**< Data numbering plan */
146 SMS_NPI_TELEX = 4, /**< Telex numbering plan */
147 SMS_NPI_SVC_CNTR_SPECIFIC_PLAN = 5, /**< Service Center Specific plan */
148 SMS_NPI_SVC_CNTR_SPECIFIC_PLAN2 = 6, /**< Service Center Specific plan */
149 SMS_NPI_NATIONAL = 8, /**< National numbering plan */
150 SMS_NPI_PRIVATE = 9, /**< Private numbering plan */
151 SMS_NPI_ERMES_NUMBERING_PLAN = 10, /**< ERMES numbering plan */
152 SMS_NPI_RESERVED_FOR_EXT = 0xF /**< Reserved for extension */
153 } SimNumberingPlanIdentity_t;
156 unsigned int DialNumLen; /**< length of address. If Service center address is not set, then this will be zero */
157 SimTypeOfNum_t Ton; /**< Type of number*/
158 SimNumberingPlanIdentity_t Npi; /**<Numbering plan identification*/
159 unsigned char szDiallingNum[SMS_ADDRESS_LEN_MAX + 1]; /**< destination address. If Address not set, then set to 0xFF */
164 * This enumeration defines the validity period type.
168 SMS_VP_NOT_USED = 0, /**< validity period not used */
169 SMS_VP_RELATIVE = 2, /**< after a predetermined time period after the service center has received the message */
176 * Sms_coding_group_type
177 This enum defined the different sms coding group types
181 SMS_CODGRP_SM_GENERAL_DCS, /**< Bits 7..4 00xx */
182 SMS_CODGRP_CB_GENERAL_LANG, /**< 0000 */
183 SMS_CODGRP_CB_ALPHA, /**< 0001 */
184 SMS_CODGRP_CB_RES1, /**< 0010 */
185 SMS_CODGRP_CB_RES2, /**< 0011 */
186 SMS_CODGRP_SM_AUTO_DELETION, /**< 01xx Bits 5..0 are coded the same as SM_GENERAL_DCS */
187 SMS_CODGRP_CB_GENERAL_DCS, /**< 01xx behavior is as SM_GENERAL_DCS */
188 SMS_CODGRP_SM_WAITING_DISCARD, /**< 1100 */
189 SMS_CODGRP_SM_WAITING_STORE, /**< 1101 */
190 SMS_CODGRP_SM_WAITING_STORE_UCS2, /**< 1110 */
191 SMS_CODGRP_CB_WAP, /**< 1110 Cell Broadcast */
192 SMS_CODGRP_SM_CLASS_CODING, /**< 1111 */
193 SMS_CODGRP_CB_CLASS_CODING, /**< 1111 Cell Broadcast */
196 } Sms_coding_group_type;
199 Defines different types of waiting indicators
203 SMS_WAITING_VOICE_MSG, /**< voice message waiting */
204 SMS_WAITING_FAX_MSG, /**< FAX message waiting */
205 SMS_WAITING_EMAIL_MSG, /**< E-mail waiting */
206 SMS_WAITING_OTHER_MSG, /**< Other message waiting */
212 Defines different alphabet types of an sms
216 SMS_ALPHABET_DEFAULT, /**< GSM alphabet default 7bit */
217 SMS_ALPHABET_8BIT, /**< 8bit */
218 SMS_ALPHABET_UCS2, /**< 16bit ucs2 */
220 SMS_ALPHABET_KSC5601, /**< for Korean */
226 This enum defines the different classes of SMS which indicates the
227 type of storage of the sms.
231 SMS_CLASS_0, /**< display immediately */
232 SMS_CLASS_1, /**< may be stored */
233 SMS_CLASS_2, /**< store in SIM */
234 SMS_CLASS_3, /**< transfer to TE */
241 This structure contains the information related to sms coding schemes
246 int bCompressed; /**< if text is compressed this is TRUE */
247 int bmsg_class_set; /**< message class indication. if TRUE = bits 1..0, if FALSE = reserved */
248 int bmsg_ind_active; /**< message indication group. if TRUE = on, FALSE = off */
249 Sms_coding_group_type coding_group_type; /**< Coding group, GSM 03.38 */
250 Sms_waiting_type waiting_type; /**< Type of message waiting */
251 Sms_alphabet_type alphabet_type; /**< How to encode a message. */
252 Sms_class_type class_type; /**< The message class */
257 * This structure defines the validity period types.
261 SMS_VP_REL_1H, /**< One hour */
262 SMS_VP_REL_6H, /**< Six hours */
263 SMS_VP_REL_12H, /**< Twelve hours */
264 SMS_VP_REL_1D, /**< One day */
265 SMS_VP_REL_3D, /**< Three days */
266 SMS_VP_REL_1W, /**< One week */
267 SMS_VP_REL_1M, /**< One Month */
268 SMS_VP_REL_MAX /**< Max = 63 weeks */
271 This structure contains all the information
272 related to validity period of a message.
277 Sms_vp_type vp_type; /**< Validity period format */
278 Sms_vp_rel_Value vp_rel_type; /**< Validity period value duration the message must retain in the service center while application attempts delivery */
279 unsigned long vpValue; /** Validity period value */
283 /* This structure contains the details of delete status notification, which comes after calling
284 TelTapiSmsDeleteMsg*/
287 unsigned short result;
289 }TelTapiSmsDeleteMsg_status_ind;
292 /* This structure contains the details of save status notification, which comes after calling
297 unsigned short result;
299 }Sms_save_status_ind;
314 #define BASE_YEAR 70L /* 1970 is the base year */
315 #define MAX_YEAR 130L /* 2030 is the max year */
318 #define SIM_SMSP_ADDRESS_LEN 20 // digit length
320 #define SET_TON_NPI(dest, ton, npi) { \
322 dest |= (ton & 0x07) << 4; \
323 dest |= npi & 0x0F; \
331 /************HEADER************/
334 SmsTPDUType msg_type ; //bit 0 ,1
336 // reject duplicates [M]
339 // validity period format [M]
340 Sms_vp_type vpf ; // bits 3, 4
345 // user data header indication
348 // status report request
351 /************BODY************/
352 //message reference [M]
355 // destination address [M]
356 SmsAddressInfo_t desAddr;
358 // protocol identifier [M]
361 // data coding scheme [M]
362 Sms_coding_scheme dcs;
367 // user data length [M]
378 /************HEADER************/
381 SmsTPDUType msg_type; //bit 0 ,1
383 // user data header indication
386 /************BODY************/
391 // parameter indicator [M]
392 unsigned char paraInd;
394 // service centre time stamp [M]
397 // protocol identifier [M]
400 // data coding scheme
401 Sms_coding_scheme dcs;
403 // user data length [M]
409 }TPDU_SMS_SUBMIT_REPORT;
414 /************HEADER************/
415 SmsTPDUType msg_type; //bit 0 ,1
423 int sri; // bit , 5status_report_indication
425 /************BODY************/
427 SmsAddressInfo_t orgAddr;
433 Sms_coding_scheme dcs;
443 /************HEADER************/
444 SmsTPDUType msg_type ; //bit 0 ,1
448 /************BODY************/
452 unsigned char paraInd;
456 Sms_coding_scheme dcs;
460 unsigned char * userData;
462 }TPDU_SMS_DELIVER_REPORT;
467 /************HEADER************/
468 SmsTPDUType msg_type ; //bit 0 ,1
472 int srr; //bit 5, status_report_request
474 /************BODY************/
476 unsigned int mr; //message_ref
480 unsigned char cmdType;
482 unsigned char msgNum;
484 SmsAddressInfo_t destAddr;
488 unsigned char * userData;
495 /************HEADER************/
497 SmsTPDUType msg_type ; //bit 0 ,1
503 int srq; //bit 5, status_report_qualifier
505 /************BODY************/
509 SmsAddressInfo_t rcpAddr; //recipient_addr
513 TmDateTime dt; //discharge_time
515 unsigned char status;
517 unsigned char paraInd;
521 Sms_coding_scheme dcs;
527 }TPDU_SMS_STATUS_REPORT;
529 /***************************************************************************************/
530 void reverse(char* x, int len);
531 char* AcItoa(int n, char* str, int b) ;
532 int AcToupper(int ch);
534 char* SmsUtilUnpackGSMCode(char* szData, const char* pIn, int in_len );
535 int SmsUtilPackGSMCode( unsigned char* pOut, const char* szData, int in_len );
537 void SmsUtilConvertBCD2Digit( char* pDigits, char* pBCD, int digitLen );
538 void SmsUtilConvertDigit2BCD( char* pBCD, char* pDigits, int digitLen );
540 TmDateTime* SmsUtilDecodeTimeStamp(char* pTimeStamp, TmDateTime *tmDateTime );
541 unsigned char* SmsUtilEncodeTimeStamp( TmDateTime* tmDateTime, unsigned char* pTimeStamp );
544 int SmsUtilDecodeAddrField(char *diallingNum, char * pAddrField, int *result_ton, int *result_npi );
545 int SmsUtilEncodeAddrField( unsigned char* pAddrField, char* diallingNum, int dialnumLen, int ton, int npi );
547 int SmsUtilDecodeScAddrField( SmsAddressInfo_t* pSmsAddrField, unsigned char* pAddrField );
548 int SmsUtilEncodeScAddrField( unsigned char* pAddrField, SmsAddressInfo_t * pSmsAddrField );
550 void SmsUtilDecodeDCS( Sms_coding_scheme* pCodingScheme, unsigned char dcs );
551 void SmsUtilEncodeDCS( unsigned char* pDCS, Sms_coding_scheme* pCodingScheme);
553 unsigned char SmsUtilEncodeValidity( unsigned char* pValidity, Sms_vp* pVP );