update for beta universally
[framework/telephony/libslp-tapi.git] / src / test_apps / tapi_sms_test.c
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 #include <stdlib.h>
23 #include <signal.h>
24 #include <stdio.h>
25 #include <errno.h>
26 #include <pthread.h>
27 #include <glib.h>
28 #include <string.h>
29 #include <unistd.h>
30 #include <assert.h>
31 #include <glib.h>
32
33 #include "TelUtility.h"
34 #include <TapiCommon.h>
35 #include <TelNetText.h>
36 #include <ITapiNetText.h>
37
38 #include "tapi_test_utility.h"
39 #include "tapi_sms_test.h"
40
41 /******* prototype ******* */
42 #include "tapi_sms_util.h"
43
44 #define TAPI_NETTEXT_MSG_SIZE_MAX                               918
45 #define TAPI_NETTEXT_CB_SIZE_MAX                                93
46 #define TAPI_NETTEXT_ADDRESS_LEN_MAX                    20
47 #define TAPI_NETTEXT_SCADDRESS_LEN_MAX                  18
48
49 #define TEST_DEBUG(frmt, args...)       \
50 {do { fprintf(stderr, "[SMS Test][%s:%04d] "frmt "\n", __func__, __LINE__, ##args); } while (FALSE) ;}
51
52 // Global Variable
53 static unsigned int *   SMS_subscription_id;
54 int                                     dcs_pos =0;
55 unsigned int                    SmsMsgId = 0;
56
57 // same as tapievent
58 typedef struct
59 {
60         int group;
61         int type;
62         int requestid;
63         int status;
64         void *dst;
65 }data_t;
66
67 //extern int EvtDeliveryHandle ;
68 //int error_code;
69
70 TS_UINT8 tp_mr = 0x00;
71
72
73 BOOL EncodeCdmaSmsParamTeleservice(int teleservice_id ,ParamTeleserv_t *ParamTeleserv)
74 {
75         BOOL ret = FALSE;
76
77         if(ParamTeleserv == NULL){
78                 printf("[EncodeCdmaSmsParamTeleservice] NULL pointer  \n");
79                 return ret;
80         }
81
82         switch(teleservice_id){
83                 case TELESERVICEID_CPT95:
84                 case TELESERVICEID_CMT95:
85                 case TELESERVICEID_VMN95:
86                 case TELESERVICEID_WAP:
87                         ret = TRUE;
88                         break;
89                 default:
90                         ret = FALSE;
91         }
92
93         if(ret == TRUE){
94                 ParamTeleserv->param_id = PARAMID_TELESERVICE_ID;
95                 ParamTeleserv->param_len = 2;
96                 ParamTeleserv->teleserv_id = teleservice_id;
97         }
98
99         return ret;
100 }
101
102 BOOL EncodeCdmaSmsParamDestAddress(int NumberPlan, char* diallingNum ,ParamAddress_t *ParamAddr)
103 {
104         BOOL ret = FALSE;
105         int length = 0;
106
107         if(ParamAddr == NULL || diallingNum == NULL){
108                 printf("[EncodeCdmaSmsParamAddress] NULL pointer  \n");
109                 return ret;
110         }
111
112         length = strlen(diallingNum); //remove CR
113
114         ParamAddr->param_id = PARAMID_ADDRESS;
115         ParamAddr->len = length;
116         ParamAddr->digit = DIGITMODE_4BITDTMF;
117         ParamAddr->num = NUMMODE_NONE_DATANETWORK;
118         ParamAddr->numtype = NUMBER_TYPE_UNKNOWN;
119         ParamAddr->numplan = NumberPlan;
120
121         strncpy((char *)ParamAddr->CHARi, diallingNum, length);
122
123         length +=5;
124         ParamAddr->param_len = length;
125
126         ret = TRUE;
127
128         return ret;
129 }
130
131 BOOL EncodeCdmaSmsParamCallbackAddress(int NumberPlan, char* diallingNum ,ParamCallback_t *ParamCallback)
132 {
133         BOOL ret = FALSE;
134         int length = 0;
135
136         if(ParamCallback == NULL || diallingNum == NULL){
137                 printf("[EncodeCdmaSmsParamAddress] NULL pointer  \n");
138                 return ret;
139         }
140
141         length = strlen(diallingNum); //remove CR
142
143
144         ParamCallback->param_id = PARAMID_CALLBACK;
145         ParamCallback->digit = DIGITMODE_4BITDTMF;
146         ParamCallback->numtype = NUMBER_TYPE_UNKNOWN;
147         ParamCallback->numplan = NumberPlan;
148         ParamCallback->len = length;
149         strncpy((char *)ParamCallback->CHARi, diallingNum, length);
150
151         length +=4;
152         ParamCallback->param_len = length;
153
154         ret = TRUE;
155
156         return ret;
157 }
158
159 BOOL EncodeCdmaSmsParamMsgId(int type, ParamMsgId_t *ParamMsg)
160 {
161         BOOL ret = FALSE;
162
163         if(ParamMsg == NULL){
164                 printf("[EncodeCdmaSmsParamMsgId] NULL pointer  \n");
165                 return ret;
166         }
167
168         ParamMsg->param_id = PARAMID_MESSAGE_ID;
169         ParamMsg->param_len =3;
170         ParamMsg->type = type;
171         ParamMsg->msg_id = SmsMsgId++;
172
173
174         ret = TRUE;
175
176         return ret;
177 }
178
179 BOOL EncodeCdmaSmsParamUserData(char* SendTxt, ParamUserData_t *ParamUser)
180 {
181         BOOL ret = FALSE;
182         int length = 0;
183
184         if(ParamUser == NULL || SendTxt == NULL){
185                 printf("[EncodeCdmaSmsParamUserData] NULL pointer  \n");
186                 return ret;
187         }
188
189         length = strlen(SendTxt);
190
191         ParamUser->param_id = PARAMID_USER_DATA;
192         ParamUser->encoding = MSGENCODING_7BIT_ASCII;
193         strncpy((char *)ParamUser->CHARi, SendTxt, length);
194
195         ParamUser->len =  length;
196         length += 2;;
197         ParamUser->param_len = length;
198
199         ret = TRUE;
200
201         return ret;
202 }
203
204 BOOL EncodeCdmaSmsSubmitTpdu(char* diallingNum, int dialNumLen, char* msgTxt, int msg_len)
205 {
206         ParamTeleserv_t ParamTeleserv = {0, };
207         ParamAddress_t ParamAddr = {0, };
208         //ParamCallback_t Paramcallback = {0, };
209         ParamMsgId_t ParamMsg = {0, };
210         ParamUserData_t ParamUser = {0, };
211
212         int i;
213         int requestId = 0;
214         //char CallbackNum[] = "1117908499";
215         TapiResult_t returnStatus;
216
217         TEST_DEBUG("EncodeCdmaSmsSubmitTpdu Func Enter");
218
219         TelSmsMsgInfo_t *pDataPackage = malloc(sizeof(TelSmsMsgInfo_t));
220         memset(pDataPackage, 0, sizeof(TelSmsMsgInfo_t));
221
222         pDataPackage->MsgType = TAPI_NETTEXT_MESSAGETYPE_SUBMIT;
223
224         //1 TeleService Identifier
225         EncodeCdmaSmsParamTeleservice(TELESERVICEID_CMT95, &ParamTeleserv);
226         pDataPackage->ParamMask |= TAPI_NETTEXT_PARAM_TELESERVICE_MASK;
227         memcpy(&pDataPackage->MsgData.OutSubmit.TeleService, &ParamTeleserv.teleserv_id, sizeof(unsigned short));
228         TEST_DEBUG("teleservice at TEST APP: 0x%x", pDataPackage->MsgData.OutSubmit.TeleService);
229
230         //1 Destination Address
231         diallingNum[dialNumLen] = '\0';
232         EncodeCdmaSmsParamDestAddress(NUMBER_PLAN_UNKNOWN, diallingNum, &ParamAddr);
233         pDataPackage->ParamMask |= TAPI_NETTEXT_PARAM_ADDRESS_MASK;
234         pDataPackage->MsgData.OutSubmit.DstAddr.Digit = ParamAddr.digit;
235         pDataPackage->MsgData.OutSubmit.DstAddr.NumberMode = ParamAddr.num;
236         pDataPackage->MsgData.OutSubmit.DstAddr.NumberType = ParamAddr.numtype;
237         pDataPackage->MsgData.OutSubmit.DstAddr.NumberPlan = ParamAddr.numplan;
238         pDataPackage->MsgData.OutSubmit.DstAddr.szAddrLength = ParamAddr.len;
239         memcpy(pDataPackage->MsgData.OutSubmit.DstAddr.szAddress, ParamAddr.CHARi, ParamAddr.len);
240
241         //1  Message Identifier
242         EncodeCdmaSmsParamMsgId(MESSAGETYPE_SUBMIT, &ParamMsg);
243         pDataPackage->ParamMask |= TAPI_NETTEXT_PARAM_MESSAGE_ID_MASK;
244         pDataPackage->MsgData.OutSubmit.MsgId = ParamMsg.type;
245         pDataPackage->MsgType = ParamMsg.type;
246
247         //1  bearer
248         pDataPackage->ParamMask |= TAPI_NETTEXT_PARAM_BEARER_REPLY_MASK;
249         pDataPackage->MsgData.OutSubmit.ReplySeqNumber = 1;
250
251 #if 0
252         //1 Callback Address
253         EncodeCdmaSmsParamCallbackAddress(NUMBER_PLAN_UNKNOWN, CallbackNum, &Paramcallback);
254         pDataPackage->ParamMask |= TAPI_NETTEXT_PARAM_CALLBACK_MASK;
255         pDataPackage->MsgData.OutSubmit.CallBackNumber.Digit = Paramcallback.digit;
256         pDataPackage->MsgData.OutSubmit.CallBackNumber.NumberType = Paramcallback.numtype;
257         pDataPackage->MsgData.OutSubmit.CallBackNumber.NumberPlan = Paramcallback.numplan;
258         pDataPackage->MsgData.OutSubmit.CallBackNumber.szAddrLength = Paramcallback.len;
259         memcpy(pDataPackage->MsgData.OutSubmit.CallBackNumber.szAddress, Paramcallback.CHARi, Paramcallback.len);
260 #endif
261         //1 User Date
262         msgTxt[msg_len - 1] = '\0';
263         EncodeCdmaSmsParamUserData(msgTxt, &ParamUser);
264         pDataPackage->ParamMask |= TAPI_NETTEXT_PARAM_USER_DATA_MASK;
265         pDataPackage->MsgData.OutSubmit.MsgEncoding = ParamUser.encoding;
266         pDataPackage->MsgData.OutSubmit.MsgLength = ParamUser.len;
267         memcpy(pDataPackage->MsgData.OutSubmit.szData, ParamUser.CHARi, ParamUser.len);
268
269         TEST_DEBUG("");
270         TEST_DEBUG("=============== Test App Message =================");
271         TEST_DEBUG(" - MsgType: %d", pDataPackage->MsgType);
272         TEST_DEBUG(" - ParamMask: 0x%08x", pDataPackage->ParamMask);
273         printf("0000: ");
274         for (i = 0; i < sizeof(TelSmsMsgInfo_t); i++) {
275                 printf("%02x ", *(((unsigned char *) pDataPackage) + i));
276                 if ((i + 1) % 8 == 0)
277                         printf("  ");
278
279                 if ((i + 1) % 16 == 0)
280                         printf("\n%04x: ", i+1);
281         }
282         printf("\n");
283         fflush(stdout);
284
285         TEST_DEBUG("==============================================");
286
287         returnStatus = tel_send_sms_msg(pDataPackage, 0x26, &requestId); //more to send is false since it is not concatenated.for concatenated send 1
288
289         TEST_DEBUG("tel_send_sms_msg() returnStatus: %d, requestId: %d", returnStatus, requestId);
290
291         free(pDataPackage);
292
293         return TRUE;
294 }
295
296
297 BOOL DecodeCellBroadcastMsg(int length,char * pPDU)
298 {
299         int                     msgLength;
300         int                     sn = 0; //serial number
301         int                     msgID; //message identifier
302         tapi_nettext_coding_scheme  dcs;
303
304         TS_UINT8        page[2];
305         int                     contents_length;
306         char     contents[TAPI_NETTEXT_CB_SIZE_MAX];
307
308         TS_UINT8        gs;
309         TS_UINT8        msgCode;
310         TS_UINT8        updateNumber;
311
312         if(pPDU == NULL){
313                 TEST_DEBUG("pData is Null")
314                 return FALSE;
315         }
316
317         TEST_DEBUG("cb msg type is %x",pPDU[0]);
318         TEST_DEBUG("cb msg len is %x",pPDU[1]);
319
320
321         TEST_DEBUG("$$$$$$$$$$$$$$$length of cb msg is %d",length);
322         sn = (pPDU[2] <<8 ) |pPDU[1] ;
323
324         gs = (pPDU[2] & 0xC0) >> 6;  //bit 7, bit 6
325
326         msgCode = (( (pPDU[2] & 0x3F) <<4 ) | pPDU[3] ) & 0xF0 ;
327
328         updateNumber = pPDU[3] & 0x0F;  //bit3, bit2, bit1, bit0
329
330         msgID = pPDU[4] << 4 |pPDU[3];
331
332         SmsUtilDecodeDCS( &dcs, pPDU[6] );
333
334         page[0] = pPDU[7] & 0x0F; //total page
335         page[1] = (pPDU[7] & 0xF0)>>4 ; //current page
336
337
338         msgLength = length -2;
339
340         contents_length = msgLength -6;
341
342         if (dcs.alphabet_type == TAPI_NETTEXT_ALPHABET_DEFAULT )
343         {
344                 TS_BYTE inData[TAPI_NETTEXT_CB_SIZE_MAX+1];
345
346                 memset( inData, 0x00, TAPI_NETTEXT_CB_SIZE_MAX + 1 );
347
348                 memcpy( (void*) inData, (void*) &pPDU[8], contents_length);
349                 SmsUtilUnpackGSMCode(contents,  &pPDU[8], msgLength );
350         }
351         else
352         {
353                 memcpy( contents, &pPDU[8], msgLength);
354                 contents[msgLength] = 0;
355         }
356
357         printf("*************************************\n");
358         printf("serical number : 0x%04x \n" , sn);
359         printf("Geographical Scope: 0x%x\n" , gs);
360         printf("message code : 0x%x\n", msgCode);
361         printf("update Number : 0x%x\n",updateNumber);
362         printf("message identifier :  0x%x\n" , msgID);
363         printf("DCS-Commpressed?: %d (1: true)\n" , dcs.bCompressed);
364         printf("DCS-coding_group_type:  %x\n" , dcs.coding_group_type);
365         printf("contents bytes size : %d\n", contents_length);
366         printf("page : (%d /%d) (page /total ) \n", page[1], page[0] );
367         printf("contents: %s\n", contents);
368         printf("*************************************\n");
369         /*
370            if(dcs.class_type = TAPI_NETTEXT_CLASS_2)
371            {
372            TelSmsDatapackageInfo_t * pDataPackage;
373
374            pDataPackage = malloc(sizeof(TelSmsDatapackageInfo_t));
375
376            pDataPackage->MsgLength =length ;
377            memcpy(pDataPackage->szData, pPDU, pDataPackage->MsgLength);
378
379            returnStatus = TelTapiSmsWrite(0x01, pDataPackage,&requestId);
380            TEST_DEBUG("Write : returnstatus %d requestId :%d",returnStatus,requestId);
381            }
382            */
383         return TRUE;
384 }
385
386 BOOL EncodeSmsSubmitTpdu(char* diallingNum, int dialNumLen, char* msg, int msg_len)
387 {
388
389         TPDU_SMS_SUBMIT tpdu_submit;
390
391         TS_BYTE  packet[TAPI_NETTEXT_MSG_SIZE_MAX];
392
393         TS_BYTE  SCA[TAPI_NETTEXT_SCADDRESS_LEN_MAX]; //send SMS ï¿½Ò¶ï¿½ ï¿½ï¿½ï¿½ï¿½Ï´ï¿½ ï¿½ï¿½ï¿½ï¿½ SCA��
394         int ret = 0;
395
396         //      TS_UINT8 tp_mr = 0x03;
397         tp_mr++;
398         TS_UINT8 tp_pid = 0; //reaplace type (65)
399         TS_UINT8 tp_dcs; //=17; //class_1(17),class_2(18)
400         TS_UINT8 tp_vp;
401
402
403         int index = 0, ScIndex = 0;
404         int i;
405         int requestId=0;
406         unsigned char             sca_len =0;
407         TapiResult_t returnStatus ;
408
409         TelSmsDatapackageInfo_t *pDataPackage= malloc(sizeof(TelSmsDatapackageInfo_t));
410
411         memset(pDataPackage, 0, sizeof(TelSmsDatapackageInfo_t));
412
413         memset(packet, 0, TAPI_NETTEXT_MSG_SIZE_MAX);
414
415         /************SCA ADDRESS GET START**************/
416         /*
417            returnStatus = TelTapiSmsGetSCA(&sc_addr,0);
418            printf("Service center addr returned from TAPI SCA address %s returnStatus %d\n",sc_addr.szDiallingNum,returnStatus);
419            SmsUtilDecodeAddrField(decodeScaAddr, &sc_addr.szDiallingNum[0],&sc_addr.Ton, &sc_addr.Npi);
420            sca_len = strlen( decodeScaAddr );
421
422            memcpy( SCA, decodeScaAddr, sca_len);
423            SCA[sca_len] = '\0';
424            */
425         TEST_DEBUG("Enter SCA: ");
426         memset(SCA,0,sizeof(SCA));
427
428         ret = read(0, SCA, sizeof(SCA));
429
430         if (ret <= 0) {
431                 TEST_DEBUG(" NULL msg can NOT be sent ");
432                 return -1;
433         }
434
435         sca_len=strlen((char *)SCA)-1;
436
437         TEST_DEBUG("Decode SCA Address =========");
438         TEST_DEBUG("SCA Number :%s, SCA Length :%d ",SCA , sca_len);
439         TEST_DEBUG("========================");
440
441         //SCA ADDRESS GET END
442
443         //SCA
444
445         //TODO : SCA
446
447         //      index +=SmsUtilEncodeAddrField(packet,SCA, strlen(SCA)  ,0x01,0x01);
448         ScIndex  =SmsUtilEncodeAddrField((unsigned char*)pDataPackage->Sca ,(char *)SCA, sca_len  ,0x01,0x01);
449
450
451         TEST_DEBUG("ScIndex is %d", ScIndex);
452
453         // TP-MTI, TP-RD, TP-VPF, TP-SRR, TP_UDHI, TP-RP
454         tpdu_submit.msg_type = SMS_TPDU_SUBMIT;
455         tpdu_submit.rd   =FALSE; //false :accept duplicate msg , true: reject duplicate msg
456         tpdu_submit.vpf = TAPI_NETTEXT_VP_RELATIVE;
457         tpdu_submit.srr  = FALSE;   //false :A status report is not requested , true: A status report is requested
458         tpdu_submit.udhi = FALSE ; //false: contains only the short message , true :a Header in addition to the short message
459         tpdu_submit.rp = FALSE  ; //false :TP Reply Path parameter is not set in this SMS SUBMIT, true : TP Reply Path parameter is set in this SMS SUBMIT
460
461         packet[index] =  tpdu_submit.msg_type;                                                  // SUBMIT: bits 0, 1
462         packet[index] |= tpdu_submit.rd? 0x04 : 0;                                              // bit 2
463         packet[index] |= tpdu_submit.vpf  << 3; // bits 3, 4
464         packet[index] |= tpdu_submit.srr ? 0x20 : 0;                                            // bit 5
465         packet[index] |= tpdu_submit.udhi? 0x40 : 0;                                            // bit 6
466         packet[index] |= tpdu_submit.rp ? 0x80 : 0;                                             // bit 7
467
468         index++;
469         TEST_DEBUG("index of message ref is %d, msgref is %d",index,tp_mr);
470         /* TP-MR */
471         packet[index++] = tp_mr;
472
473         // TP-DA
474         index +=  SmsUtilEncodeAddrField( packet+index, diallingNum, dialNumLen, 0x02, 0x01);
475
476         //TEST_DEBUG("DESTINATTION  ADDR Encoded =========");
477
478         //TP-PID
479         packet[index++] = tp_pid;
480
481         // TP_DCS (Data Coding Scheme)
482
483         tpdu_submit.dcs.bCompressed = FALSE;
484         tpdu_submit.dcs.bmsg_class_set = TRUE;
485         tpdu_submit.dcs.coding_group_type =TAPI_NETTEXT_CODGRP_SM_GENERAL_DCS;
486         tpdu_submit.dcs.alphabet_type = TAPI_NETTEXT_ALPHABET_DEFAULT;
487         tpdu_submit.dcs.class_type = TAPI_NETTEXT_CLASS_2;
488
489         SmsUtilEncodeDCS(&tp_dcs, &tpdu_submit.dcs);
490
491         packet[index++] = tp_dcs;
492
493         //TEST_DEBUG("DCS Encoded:tp_dcs =%d =========",tp_dcs);
494
495         //TP-VP
496
497         tpdu_submit.vp.vp_rel_type = TAPI_NETTEXT_VP_REL_6H ;
498         tpdu_submit.vp.vp_type = TAPI_NETTEXT_VP_RELATIVE;
499         tpdu_submit.vp.vpValue =0xff ;
500
501         SmsUtilEncodeValidity(&tp_vp,&tpdu_submit.vp);
502
503         //tp_vp =65;
504         packet[index++] = tp_vp;
505         //TEST_DEBUG("Validity Encoded :tp_vp =%d =========",tp_vp);
506
507         // UDL
508         packet[index++] = msg_len;
509
510         // TP-UD
511
512         if (tpdu_submit.dcs.alphabet_type == TAPI_NETTEXT_ALPHABET_DEFAULT )
513         {
514                 int pos;
515                 pos =SmsUtilPackGSMCode( packet + index, msg, msg_len);
516                 index += pos;
517         }
518
519         TEST_DEBUG("Send packet to phonseSever[%d] -----", index);
520
521         for(i=0; i< index ; i++ )
522         {
523                 TEST_DEBUG("[%02x]", packet[i]);
524                 if( i%10 == 9)
525                         TEST_DEBUG("\n");
526         }
527         TEST_DEBUG("\n");
528
529         memcpy( pDataPackage->szData, packet, index);
530         pDataPackage->MsgLength = index;
531
532         TEST_DEBUG("***Sending the Message (Api:SendMsg)***");
533
534         TEST_DEBUG("Length : %d",pDataPackage->MsgLength);
535
536         returnStatus = tel_send_sms( pDataPackage, 0 ,&requestId); //more to send is false since it is not concatenated.for concatenated send 1
537
538         TEST_DEBUG("SendMsg : returnStatus=%d requestId=%d", returnStatus, requestId);
539
540         free(pDataPackage);
541
542         return TRUE;
543
544 }
545 TS_BOOL DecodeSmsSubmitTpdu(int pdu_len, char * pPDU)
546 {
547         TPDU_SMS_SUBMIT         tpdu_submit;
548         TS_BYTE              scaAddr_len =0;
549         int                         destAddr_len = 0;
550         char            diallingNum[TAPI_NETTEXT_ADDRESS_LEN_MAX];
551         char     scaAddr[TAPI_NETTEXT_SCADDRESS_LEN_MAX]; //service center address
552         char        destAddr[TAPI_NETTEXT_ADDRESS_LEN_MAX]; //destination number
553         int         sca_ton, sca_npi, dest_ton,dest_npi;
554         int         position;
555
556         position=0;
557
558         /* SCA_ADDR */
559         memset(diallingNum, 0, sizeof(diallingNum));
560
561         SmsUtilDecodeAddrField(diallingNum, &pPDU[position],&sca_ton, &sca_npi);
562
563         position+=2;  //include Address-Length, Type of Address
564
565         scaAddr_len = strlen( (char *)diallingNum );
566
567         if ( scaAddr_len % 2 )
568                 position += scaAddr_len / 2 + 1;
569         else
570                 position += scaAddr_len / 2;
571
572
573         if ( sca_ton == SIM_TON_INTERNATIONAL )
574         {
575                 scaAddr[0] = '+';
576                 memcpy( &scaAddr[1], diallingNum, scaAddr_len );
577                 scaAddr[scaAddr_len+1] = '\0';
578         }
579         else
580         {
581                 memcpy( scaAddr, diallingNum, scaAddr_len );
582                 scaAddr[scaAddr_len] = '\0';
583         }
584
585         //TEST_DEBUG(" sca length: %d , sca # : %s", scaAddr_len, scaAddr);
586
587         /* TP-MTI, TP-RD, TP-VPF,  TP-RP, TP_UDHI, TP-SRR */
588
589         tpdu_submit.msg_type = SMS_TPDU_SUBMIT; // bit 0,1(Message Type Indicator )
590         tpdu_submit.rd = ( pPDU[position] & 0x04 ) ? TRUE : FALSE;// bit 2 (Message Type Indicator)
591         tpdu_submit.vpf =( pPDU[position] & 0x18) >> 3; //  bits 3, 4 ( validity period format)
592         tpdu_submit.srr=( pPDU[position] & 0x20 ) ? TRUE : FALSE;       // bit 5 (Status Report Request)
593         tpdu_submit.udhi=( pPDU[position] & 0x40 ) ? TRUE : FALSE;      // bit 6 (User Data Header Indicator)
594         tpdu_submit.rp = ( pPDU[position] & 0x80 ) ? TRUE : FALSE;      // bit 7 (Reply Path)
595
596         position++ ;
597
598         /* TP-MR */
599         tpdu_submit.mr = pPDU[position];
600
601         position++ ;
602
603         /* TP-DA */
604
605         memset(diallingNum, 0, sizeof(diallingNum));
606
607         SmsUtilDecodeAddrField(diallingNum, &pPDU[position],&dest_ton, &dest_npi);
608
609         position+=2;
610
611         destAddr_len = strlen( (char*) diallingNum );
612         if ( destAddr_len % 2 )
613                 position += destAddr_len / 2 + 1;
614         else
615                 position += destAddr_len / 2;
616
617
618         if ( dest_ton == SIM_TON_INTERNATIONAL )
619         {
620                 destAddr[0] = '+';
621                 memcpy( &destAddr[1], diallingNum, destAddr_len );
622                 destAddr[destAddr_len+1] = '\0';
623         }
624         else
625         {
626                 memcpy( destAddr, diallingNum, destAddr_len );
627                 destAddr[destAddr_len] = '\0';
628         }
629         //TEST_DEBUG(" dest length: %d , dest # : %s", destAddr_len, destAddr);
630
631         tpdu_submit.desAddr.DialNumLen= destAddr_len;
632         memcpy(tpdu_submit.desAddr.szDiallingNum, destAddr , destAddr_len);
633         tpdu_submit.desAddr.Npi = dest_npi;
634         tpdu_submit.desAddr.Ton = dest_ton;
635
636         /* TP-PID */
637
638         tpdu_submit.pId = pPDU[position];
639         position++ ;
640
641         /* TP DCS */
642         SmsUtilDecodeDCS( &tpdu_submit.dcs, pPDU[position] );
643         position ++;
644
645         /* TP VP */
646         tpdu_submit.vp.vp_type = TAPI_NETTEXT_VP_RELATIVE;  //temp
647
648         if(tpdu_submit.vp.vp_type ==  TAPI_NETTEXT_VP_RELATIVE)
649         {
650                 tpdu_submit.vp.vpValue = pPDU[position];
651                 tpdu_submit.vp.vp_rel_type = TAPI_NETTEXT_VP_REL_1D;
652                 position++;
653         }
654         else if (tpdu_submit.vp.vp_type ==  TAPI_NETTEXT_VP_ABSOLUTE || tpdu_submit.vp.vp_type ==  TAPI_NETTEXT_VP_ENHANCED)
655         {
656                 position += 7;
657         }
658
659         /* TP UDL */
660         tpdu_submit.udl = pPDU[position] ;
661
662         if ( tpdu_submit.udl> TAPI_NETTEXT_SMDATA_SIZE_MAX )
663                 tpdu_submit.udl = TAPI_NETTEXT_SMDATA_SIZE_MAX;
664
665         position++;
666
667         /* TP UD */
668         tpdu_submit.userData = malloc( sizeof ( unsigned char ) * ( TAPI_NETTEXT_SMDATA_SIZE_MAX + 1 ) );
669
670         memset(tpdu_submit.userData, 0, sizeof ( unsigned char ) * ( TAPI_NETTEXT_SMDATA_SIZE_MAX + 1 ) );
671
672         if (tpdu_submit.dcs.alphabet_type == TAPI_NETTEXT_ALPHABET_DEFAULT )
673         {
674                 char    inData[TAPI_NETTEXT_SMDATA_SIZE_MAX+1];
675
676                 memset( inData, 0x00, TAPI_NETTEXT_SMDATA_SIZE_MAX + 1 );
677
678                 memcpy( (void*) inData, (void*) &pPDU[position], tpdu_submit.udl );
679
680                 SmsUtilUnpackGSMCode((char *)tpdu_submit.userData, inData, (TS_UINT8) tpdu_submit.udl);
681         }
682
683         TEST_DEBUG("*************************************");
684         TEST_DEBUG("Msg Type: TPDU_SUBMIT");
685
686         if(tpdu_submit.rd)
687         {
688                 TEST_DEBUG("RD: Reject Duplicate")
689         }
690
691         else if(!tpdu_submit.rd)
692         {
693                 TEST_DEBUG("RD: Accept Duplicate")
694         }
695
696         if(tpdu_submit.srr)
697         {
698                 TEST_DEBUG("SRR: A status report is requested")
699         }
700
701         else if(!tpdu_submit.srr)
702         {
703                 TEST_DEBUG("SRR: A status report is not  requested")
704         }
705
706         if(tpdu_submit.udhi)
707         {
708                 TEST_DEBUG("UDHI: Contains a Header in addition to the short message.")
709         }
710         else if(!tpdu_submit.udhi)
711         {
712                 TEST_DEBUG("UDHI: Only Short Message")
713         }
714
715         if(tpdu_submit.rp)
716         {
717                 TEST_DEBUG("RP: Set Reply Path")
718         }
719
720         else if(!tpdu_submit.rp)
721         {
722                 TEST_DEBUG("RP: Not set Reply Path")
723         }
724
725         TEST_DEBUG("SCA Addr : %s",scaAddr);
726         TEST_DEBUG("To : %s" ,destAddr);
727         TEST_DEBUG("Message : %s " , tpdu_submit.userData);
728         TEST_DEBUG("*************************************");
729
730         return TRUE;
731 }
732
733 int   DecodeSmsDeliverTpdu(int tpdu_len , char* pTPDU)
734 {
735         TPDU_SMS_DELIVER   tpdu_deliver;
736         TmDateTime                 SCTimeStamp;;
737         int                 orgAddr_len = 0;
738         char        diallingNum[TAPI_NETTEXT_ADDRESS_LEN_MAX];
739         char                orgAddr[TAPI_NETTEXT_ADDRESS_LEN_MAX]; //originating number
740         int                 org_ton,org_npi;
741         int                 position=0;
742
743         /* TP-MTI, TP-MMS, TP-SRI, TP_UDHI, TP-RP */
744         tpdu_deliver.msg_type = SMS_TPDU_DELIVER;
745         tpdu_deliver.mms = ( pTPDU[position] & 0x04 ) ? TRUE : FALSE;// bit 2 (Message Type Indicator)
746         tpdu_deliver.sri =( pTPDU[position] & 0x20 ) ? TRUE : FALSE;    // bit 5 (Status Report Indication)
747         tpdu_deliver.udhi=( pTPDU[position] & 0x40 ) ? TRUE : FALSE;    // bit 6 (User Data Header Indicator)
748         tpdu_deliver.rp = ( pTPDU[position] & 0x80 ) ? TRUE : FALSE;    // bit 7 (Reply Path)
749
750         position++ ;
751
752         /* TP-OA */
753
754         memset(diallingNum, 0, sizeof(diallingNum));
755
756         orgAddr_len = SmsUtilDecodeAddrField(diallingNum, &pTPDU[position],&org_ton, &org_npi);
757
758         position+=2;
759
760         if ( orgAddr_len % 2 )
761                 position += orgAddr_len / 2 + 1;
762         else
763                 position += orgAddr_len / 2;
764
765         TEST_DEBUG("pos = %d, length = %d",position, orgAddr_len);
766
767         if ( org_ton == SIM_TON_INTERNATIONAL )
768         {
769                 orgAddr[0] = '+';
770                 memcpy( &orgAddr[1], diallingNum, orgAddr_len );
771                 orgAddr[orgAddr_len+1] = '\0';
772         }
773         else
774         {
775                 memcpy( orgAddr, diallingNum, orgAddr_len );
776                 orgAddr[orgAddr_len] = '\0';
777         }
778
779         /* TP-PID */
780         tpdu_deliver.pId= pTPDU[position];
781
782         position ++;
783
784         /* TP-DCS */
785         SmsUtilDecodeDCS( &tpdu_deliver.dcs, pTPDU[position] );
786         dcs_pos = position;
787         position++;
788
789         /* TP-SCTS */
790         SmsUtilDecodeTimeStamp( &pTPDU[position], & SCTimeStamp );
791
792         position+=7;
793
794         /* TP-UDL */
795         tpdu_deliver.udl = pTPDU[position];
796
797         if ( tpdu_deliver.udl> TAPI_NETTEXT_SMDATA_SIZE_MAX )
798                 tpdu_deliver.udl = TAPI_NETTEXT_SMDATA_SIZE_MAX;
799
800         position++;
801
802         /* TP-UD */
803         tpdu_deliver.userData = malloc( sizeof ( unsigned char ) * ( TAPI_NETTEXT_SMDATA_SIZE_MAX + 1 ) );
804
805         memset(tpdu_deliver.userData, 0, sizeof ( unsigned char ) * ( TAPI_NETTEXT_SMDATA_SIZE_MAX + 1 ) );
806
807         if (tpdu_deliver.dcs.alphabet_type == TAPI_NETTEXT_ALPHABET_DEFAULT )
808         {
809                 char    inData[TAPI_NETTEXT_SMDATA_SIZE_MAX+1];
810
811                 memset( inData, 0x00, TAPI_NETTEXT_SMDATA_SIZE_MAX + 1 );
812
813                 memcpy( (void*) inData, (void*) &pTPDU[position], tpdu_deliver.udl );
814
815                 SmsUtilUnpackGSMCode(tpdu_deliver.userData, inData, (TS_UINT8) tpdu_deliver.udl);
816         }
817
818         TEST_DEBUG("*************************************");
819         TEST_DEBUG("Msg Type: TPDU_DELIVER");
820
821         if(tpdu_deliver.rp )
822         {TEST_DEBUG("RP: Set Reply Path")}
823         else if(!tpdu_deliver.rp )
824         {TEST_DEBUG("RP: Not set Reply Path")}
825
826         if(tpdu_deliver.sri)
827         {TEST_DEBUG("SRI: A status report shall be returned to the SME")}
828         else if(!tpdu_deliver.sri)
829         {TEST_DEBUG("SRI: A status report shall be not returned to the SME")}
830
831         if(tpdu_deliver.mms)
832         {TEST_DEBUG("MMS: No more messages are waiting for the MS in this SC")}
833         else if(!tpdu_deliver.mms)
834         {TEST_DEBUG("MMS: More messages are waiting for the MS in this SC")}
835
836         if(tpdu_deliver.udhi)
837         {TEST_DEBUG("UDHI: Contains a Header in addition to the short message.")}
838         else    if(!tpdu_deliver.udhi)
839         {TEST_DEBUG("UDHI: Only short message.")}
840
841                                                                         TEST_DEBUG("DcsClass : %x (4 means Class None) ",tpdu_deliver.dcs.class_type);
842
843
844         TEST_DEBUG("From : %10s" ,orgAddr );
845         TEST_DEBUG("Time : %d-%d-%d  , %d:%d:%d",
846                         SCTimeStamp.year, SCTimeStamp.month, SCTimeStamp.day, SCTimeStamp.hour, SCTimeStamp.minute ,SCTimeStamp.second);
847         TEST_DEBUG("Message : %s " , tpdu_deliver.userData);
848         TEST_DEBUG("*************************************");
849
850
851         return dcs_pos;
852 }
853 BOOL EncodeSmsDeliverReportTpdu()
854 {
855         TPDU_SMS_DELIVER_REPORT deliver_report;
856         unsigned char packet[500];
857         TelSmsDatapackageInfo_t * pDataPackage;
858         TS_BYTE tp_dcs;
859         TS_BYTE mask=0x69;
860         int index=0;
861         int i ;
862
863         TelSmsDatapackageInfo_t  del_report;
864
865
866         memset(&(del_report), 0 , sizeof(TelSmsDatapackageInfo_t));
867
868         pDataPackage = malloc(sizeof(TelSmsDatapackageInfo_t));
869         memset(pDataPackage, 0, sizeof(TelSmsDatapackageInfo_t));
870
871         memset(packet, 0, 500);
872
873
874         /* TP-MTI , TP-UDHI */
875         deliver_report.msg_type = SMS_TPDU_DELIVER_REPORT;
876         deliver_report.udhi = FALSE;
877
878         packet[index] = deliver_report.msg_type;                                                //DELIVER REPORT
879         packet[index] |= deliver_report.udhi? 0x40 : 0; //bit 6
880
881         index ++;
882
883         /* TP-FCS */
884         //if(result==FAIL)
885         //{
886
887
888         //}
889
890
891         /* TP -PI */
892         deliver_report.paraInd = mask;
893         packet[index] = deliver_report.paraInd ;
894
895         if ( ( mask != 0xFF ) && ( mask != 0 ) )
896         {
897                 index++;
898                 /* TP-PID */
899                 if ( mask & 0x01)
900                 {
901                         deliver_report.pId = 0x65 ;
902                         packet[index++] = deliver_report.pId;
903                 }
904
905                 /* TP-DCS */
906                 if ( mask & 0x02)
907                 {
908                         deliver_report.dcs.bCompressed = FALSE;
909                         deliver_report.dcs.bmsg_class_set = TRUE;
910                         deliver_report.dcs.coding_group_type =TAPI_NETTEXT_CODGRP_SM_GENERAL_DCS;
911                         deliver_report.dcs.alphabet_type = TAPI_NETTEXT_ALPHABET_DEFAULT;
912                         deliver_report.dcs.class_type = TAPI_NETTEXT_CLASS_2;
913
914                         SmsUtilEncodeDCS(&tp_dcs, &deliver_report.dcs);
915                         packet[index++] = tp_dcs;
916                 }
917                 /* TP-UDL */
918                 if ( mask & 0x04)
919                 {
920                         deliver_report.udl =0x00;
921                         packet[index++] = deliver_report.udl;
922
923                         /* TP-UD */
924
925                         if (deliver_report.dcs.alphabet_type == TAPI_NETTEXT_ALPHABET_DEFAULT )
926                         {
927                                 //SmsUtilPackGSMCode( packet + index, msg, msg_len);
928                         }
929                 }
930         }
931         TEST_DEBUG("EncodeSmsDeliverReportTpdu");
932         TEST_DEBUG("Send packet to phonseSever[%d] -----", index);
933
934         for(i=0; i< index ; i++ )
935         {
936                 TEST_DEBUG("[%02x]", packet[i]);
937                 if( i%10 == 9)
938                         TEST_DEBUG("\n");
939         }
940         TEST_DEBUG("\n");
941         memcpy( del_report.szData, packet, index);
942         del_report.MsgLength = index;
943         TEST_DEBUG("msgLength :%d",del_report.MsgLength);
944         int requestId =0;
945         tel_send_sms_deliver_report(&del_report,0, &requestId);//madhavi
946         TEST_DEBUG("after send deliver report request id is %d",requestId);
947         return TRUE;
948 }
949
950
951 BOOL DecodeSmsSubmitReportTpdu(int length , char *data)
952 {
953
954         TPDU_SMS_SUBMIT_REPORT  submit_report;
955         TmDateTime                              SCTimeStamp;;
956         int                                             position=1;
957         int                                             i=0;
958         TS_BYTE                                         msgRef, tpdu_len;
959         int result=0;
960         TS_BYTE                                 mask;
961
962         /* Result */
963
964         if(data == NULL){
965                 TEST_DEBUG("pData is Null")
966                 return FALSE;
967         }
968
969         TEST_DEBUG("length :%d",length);
970
971
972         for(i=0;i<length;i++)
973                 TEST_DEBUG("[%02x]",data[i]);
974
975
976         result = data[position];
977
978         TEST_DEBUG("In ackrecv (return status) result is %x",result);
979         position ++;
980
981         /* Msg Reference */
982
983         msgRef =  data[position++];
984         TEST_DEBUG("In ackrecv  position :%d msgref is %x",position,msgRef);
985         position ++;
986
987         /* TPDU Length */
988
989         tpdu_len = data[position];
990         TEST_DEBUG("In ackrecv position :%d len is %d",position,tpdu_len);
991
992
993
994         /**** SUBMIT REPORT TPDU PARSING
995          ***/
996
997         /* TP-MTI , TP-UDHI */
998         TEST_DEBUG("before TPDU position value:%d",position);
999
1000         submit_report.msg_type = data[position] & 0x03; //bit 0,1
1001         submit_report.udhi = data[position] & 0x40 ? TRUE : FALSE;       //bit 6;
1002
1003         position ++;
1004
1005         if(result == FAIL)
1006         {
1007                 /* TP-FCS */
1008                 submit_report.fcs =  data[position] ;
1009                 position ++;
1010         }
1011
1012         /* TP-PI  - set to a 1 indicates that a particular optional parameter is present in the fields which follow. */
1013         /* Masking Bit  - TP -PID (bit 0), TP-DCS(bit 1), TP-UDL(bit 2) */
1014
1015         submit_report.paraInd = data[position] ;
1016         mask =  submit_report.paraInd;
1017         position ++;
1018
1019         //TEST_DEBUG("Parmeter Indication mask =%x", mask);
1020
1021         /* TP-SCTS */
1022
1023         SmsUtilDecodeTimeStamp( &data[position], & SCTimeStamp );
1024
1025         position+=7;
1026
1027         if( ( mask != 0xFF ) && ( mask != 0 ) )
1028         {
1029                 /* TP-PID */
1030                 if ( mask & 0x01)
1031                 {
1032                         submit_report.pId= data[position];
1033                         position ++;
1034                         TEST_DEBUG("TP-PID :%x", submit_report.pId);
1035                 }
1036
1037                 /* TP-DCS */
1038                 if ( mask & 0x02)
1039                 {
1040                         SmsUtilDecodeDCS( &submit_report.dcs, data[position] );
1041                         position ++;
1042                         TEST_DEBUG("TP-DCS :%x",data[position] );
1043                 }
1044
1045                 if ( mask & 0x04)
1046                 {
1047                         /* TP-UDL */
1048                         submit_report.udl = data[position];
1049                         position++;
1050
1051                         TEST_DEBUG("TP-UDL :%x",data[position] );
1052
1053                         /* TP-UD */
1054
1055                         submit_report.userData = malloc( sizeof ( TS_BYTE ) * ( TAPI_NETTEXT_SMDATA_SIZE_MAX + 1 ) );
1056
1057                         memset(submit_report.userData, 0, sizeof ( TS_BYTE ) * ( TAPI_NETTEXT_SMDATA_SIZE_MAX + 1 ) );
1058
1059                         if (submit_report.dcs.alphabet_type == TAPI_NETTEXT_ALPHABET_DEFAULT )
1060                         {
1061                                 char    inData[TAPI_NETTEXT_SMDATA_SIZE_MAX+1];
1062
1063                                 memset( inData, 0x00, TAPI_NETTEXT_SMDATA_SIZE_MAX + 1 );
1064
1065                                 memcpy( (void*) inData, (void*) &data[position], submit_report.udl );
1066
1067                                 SmsUtilUnpackGSMCode(submit_report.userData, inData, (TS_UINT8) submit_report.udl);
1068                         }
1069
1070                 }
1071         }
1072
1073         TEST_DEBUG("*************************************");
1074
1075         if(result != 0x00)
1076                 TEST_DEBUG("SMS SEND FAIL!!")
1077         else
1078                 TEST_DEBUG("SMS SEND SUCCESS!!")
1079
1080         if(result != 0x00)
1081                                 TEST_DEBUG("Failure Code : %x",submit_report.fcs)
1082
1083
1084                                         TEST_DEBUG("*************************************");
1085
1086         return TRUE;
1087 }
1088
1089 TS_BOOL DecodeSmsStatusReportTpdu(int tpdu_len, char* pTPDU)
1090 {
1091         TPDU_SMS_STATUS_REPORT status_report;
1092
1093
1094         TmDateTime   SCTimeStamp;
1095         TmDateTime   DischargeTime;
1096
1097         int                     rcpAddr_len = 0;
1098         char            diallingNum[TAPI_NETTEXT_ADDRESS_LEN_MAX];
1099
1100         char                  rcpAddr[TAPI_NETTEXT_ADDRESS_LEN_MAX]; //recipient number
1101         int                   rcp_ton,rcp_npi;
1102         int                   position=0;
1103         TS_UINT               mask;
1104
1105         /* TP-MTI, TP MMS, TP SRQ, TP_UDHI */
1106
1107         status_report.msg_type = pTPDU[position] & 0x03; // bit 0,1
1108         status_report.mms = pTPDU[position] & 0x04 ? TRUE : FALSE ; // bit 2
1109         status_report.srq = pTPDU[position] &  0x20 ? TRUE : FALSE ; //bit 5
1110         status_report.udhi = pTPDU[position] & 0x40 ? TRUE : FALSE;      //bit 6
1111
1112         position ++;
1113
1114         /* TP-MR */
1115         status_report.mr = pTPDU[position];
1116         position ++;
1117
1118         /* TP-RA */
1119
1120         memset(diallingNum, 0, sizeof(diallingNum));
1121
1122         SmsUtilDecodeAddrField(diallingNum, &pTPDU[position],&rcp_ton, &rcp_npi);
1123
1124         position+=2;
1125
1126         rcpAddr_len = strlen( (char*) diallingNum );
1127         if ( rcpAddr_len % 2 )
1128                 position += rcpAddr_len / 2 + 1;
1129         else
1130                 position += rcpAddr_len / 2;
1131
1132
1133         if ( rcp_ton == SIM_TON_INTERNATIONAL )
1134         {
1135                 rcpAddr[0] = '+';
1136                 memcpy( &rcpAddr[1], diallingNum, rcpAddr_len );
1137                 rcpAddr[rcpAddr_len+1] = '\0';
1138         }
1139         else
1140         {
1141                 memcpy( rcpAddr, diallingNum, rcpAddr_len );
1142                 rcpAddr[rcpAddr_len] = '\0';
1143         }
1144
1145         status_report.rcpAddr.DialNumLen= rcpAddr_len;
1146         memcpy(status_report.rcpAddr.szDiallingNum, rcpAddr , rcpAddr_len);
1147         status_report.rcpAddr.Npi = rcp_npi;
1148         status_report.rcpAddr.Ton = rcp_ton;
1149
1150         /* TP-SCTS */
1151         SmsUtilDecodeTimeStamp( &pTPDU[position], & SCTimeStamp );
1152         position+=7;
1153
1154         /* TP-DT */
1155         SmsUtilDecodeTimeStamp( &pTPDU[position], & DischargeTime );
1156         position+=7;
1157
1158         /* TP-ST */
1159         status_report.status = pTPDU[position];
1160         position ++;
1161
1162         /* TP-PI */
1163         status_report.paraInd = pTPDU[position];
1164
1165         mask = status_report.paraInd  ;
1166
1167         if ( ( mask != 0xFF ) && ( mask != 0 ) )
1168         {
1169                 /* Increment only if mask is valid */
1170                 position ++;
1171
1172                 /* TP-PID */
1173                 if ( mask & 0x01)
1174                 {
1175                         status_report.pId= pTPDU[position];
1176                         position ++;
1177                 }
1178                 /* TP-DCS */
1179                 if ( mask & 0x02)
1180                 {
1181                         SmsUtilDecodeDCS( &status_report.dcs, pTPDU[position] );
1182                         position ++;
1183                 }
1184                 if ( mask & 0x04)
1185                 {
1186                         /* TP-UDL */
1187                         status_report.udl = pTPDU[position];
1188                         position++;
1189
1190                         /* TP-UD */
1191
1192                         status_report.userData = malloc( sizeof ( unsigned char ) * ( TAPI_NETTEXT_SMDATA_SIZE_MAX + 1 ) );
1193
1194                         memset(status_report.userData, 0, sizeof ( unsigned char ) * ( TAPI_NETTEXT_SMDATA_SIZE_MAX + 1 ) );
1195
1196                         if (status_report.dcs.alphabet_type == TAPI_NETTEXT_ALPHABET_DEFAULT )
1197                         {
1198                                 char    inData[TAPI_NETTEXT_SMDATA_SIZE_MAX+1];
1199
1200                                 memset( inData, 0x00, TAPI_NETTEXT_SMDATA_SIZE_MAX + 1 );
1201
1202                                 memcpy( (void*) inData, (void*) &pTPDU[position], status_report.udl );
1203
1204                                 SmsUtilUnpackGSMCode(status_report.userData, inData, (TS_UINT8) status_report.udl);
1205                         }
1206
1207                 }
1208         }
1209
1210         TEST_DEBUG("*************************************");
1211         TEST_DEBUG("Msg Type: STATUS_REPORT");
1212         if(status_report.mms)
1213         {TEST_DEBUG("MMS: No more messages are waiting for the MS in this SC")}
1214         else if(!status_report.mms)
1215         {TEST_DEBUG("MMS: More messages are waiting for the MS in this SC")}
1216
1217         if(status_report.srq)
1218         {TEST_DEBUG("SRQ: the result of an SMS COMMAND ")}
1219         else if(!status_report.srq)
1220         {TEST_DEBUG("SRQ: the result of a SMS SUBMIT.")}
1221
1222         if(status_report.udhi)
1223         {TEST_DEBUG("UDHI: Contains a Header in addition to the short message.")}
1224         else if(!status_report.udhi)
1225         {TEST_DEBUG("UDHI: Only Short Message")}
1226
1227         TEST_DEBUG("STATUS:%x",status_report.status);
1228         if(status_report.status==0x00)
1229                 {TEST_DEBUG("STATUS : Short message received by the SME")}
1230         else if(status_report.status==0x01)
1231         {TEST_DEBUG("STATUS : Short message forwarded by the SC to the SMEbut the SC is unable to confirm delivery")}
1232         else if(status_report.status==0x02)
1233         {TEST_DEBUG("STATUS : Short message replaced by the SC")}
1234
1235         TEST_DEBUG("Recipient Number : %s" ,rcpAddr );
1236         TEST_DEBUG("SC Time Stamp : %d-%d-%d  , %d:%d:%d",
1237                         SCTimeStamp.year, SCTimeStamp.month, SCTimeStamp.day, SCTimeStamp.hour, SCTimeStamp.minute ,SCTimeStamp.second);
1238         TEST_DEBUG("Discharge Time : %d-%d-%d  , %d:%d:%d",
1239                         DischargeTime.year, DischargeTime.month, DischargeTime.day, DischargeTime.hour, DischargeTime.minute ,DischargeTime.second);
1240
1241         if(mask & 0x04)
1242                 TEST_DEBUG("Message : %s " , status_report.userData);
1243
1244         TEST_DEBUG("*************************************");
1245
1246         return TRUE;
1247 }
1248
1249 void MsgCountNotification(int length, char *pData)
1250 {
1251
1252         static TelSmsStoredMsgCountInfo_t       *countInfo;
1253         int loop_counter = 0;
1254         TapiResult_t returnStatus ;
1255         int requestId = 0;
1256
1257         if(pData == NULL){
1258                 TEST_DEBUG("pData is Null")
1259                 return;
1260         }
1261
1262         countInfo = (TelSmsStoredMsgCountInfo_t*) pData;
1263
1264         if( countInfo->UsedCount != 0x00 )      //if used count is not zero
1265         {
1266                 TEST_DEBUG("Index LIST..........");
1267                 for(loop_counter  = 0; loop_counter < countInfo->UsedCount ; loop_counter++)
1268                 {
1269                         TEST_DEBUG("[%02x]", countInfo->IndexList[loop_counter]);
1270                         returnStatus = tel_read_sms_in_sim(countInfo->IndexList[loop_counter],&requestId);
1271                         TEST_DEBUG("After read msg: returnstatus %d request id is %d",returnStatus,requestId);
1272                 }
1273                 TEST_DEBUG("In MsgCountNotification total cnt is %d, usedcnt is %dapi_err %d",countInfo->TotalCount, countInfo->UsedCount,returnStatus);
1274         }
1275
1276         TEST_DEBUG("In MsgCountNotification total cnt is %d, usedcnt is %d",countInfo->TotalCount, countInfo->UsedCount);
1277 }//Madhavi
1278
1279
1280 void ReadMsgNotification(int length, char *pData)
1281 {
1282         TelSmsData_t  * sim_data;
1283         int                scaAddr_len =0;
1284         char                * pTPDU;
1285         int                 tpdu_len =0;
1286         char                diallingNum[TAPI_NETTEXT_ADDRESS_LEN_MAX];
1287         char             scaAddr[TAPI_NETTEXT_SCADDRESS_LEN_MAX]; //service center address
1288         int                 sca_ton, sca_npi;
1289         int                 position;
1290
1291         if(pData == NULL){
1292                 TEST_DEBUG("pData is Null");
1293                 return;
1294         }
1295
1296         scaAddr_len = pData[7];
1297
1298         int i = 0;
1299         for( i=0;i<length ; i++)
1300                 TEST_DEBUG("[%02x]", pData[i]);
1301
1302         sim_data = (TelSmsData_t *)pData;
1303
1304         if(sim_data->MsgStatus== TAPI_NETTEXT_STATUS_UNREAD)
1305                 TEST_DEBUG("Msg Staus : received unread msg")
1306         else if(sim_data->MsgStatus==TAPI_NETTEXT_STATUS_READ)
1307                 TEST_DEBUG("Msg Staus : received read msg")
1308         else if(sim_data->MsgStatus==TAPI_NETTEXT_STATUS_UNSENT)
1309                 TEST_DEBUG("Msg Staus : unsent msg")
1310         else
1311                 TEST_DEBUG("Msg Staus : [%d]", sim_data->MsgStatus)
1312
1313         TEST_DEBUG("First Data [%x]", sim_data->SmsData.szData[0]);
1314         TEST_DEBUG("Second Data [%x]", sim_data->SmsData.szData[1]);
1315         TEST_DEBUG("Third Data [%x]", sim_data->SmsData.szData[2]);
1316         TEST_DEBUG("Fourth Data [%x]", sim_data->SmsData.szData[3]);
1317
1318         //if(sim_data->MsgStatus ==0x01 || sim_data->MsgStatus==0x02)
1319         {
1320                 position=0;
1321                 // SCA_ADDR
1322                 memset(diallingNum, 0, sizeof(diallingNum));
1323
1324                 SmsUtilDecodeAddrField(diallingNum, (char *)sim_data->SmsData.Sca, &sca_ton, &sca_npi);
1325
1326                 position+=2;  //include Address-Length, Type of Address
1327
1328                 scaAddr_len = strlen( (char *)diallingNum );
1329
1330                 if ( scaAddr_len % 2 )
1331                         position += scaAddr_len / 2 + 1;
1332                 else
1333                         position += scaAddr_len / 2;
1334
1335
1336                 if ( sca_ton == SIM_TON_INTERNATIONAL )
1337                 {
1338                         scaAddr[0] = '+';
1339                         memcpy( &scaAddr[1], diallingNum, scaAddr_len );
1340                         scaAddr[scaAddr_len+1] = '\0';
1341                 }
1342                 else
1343                 {
1344                         memcpy( scaAddr, diallingNum, scaAddr_len );
1345                         scaAddr[scaAddr_len] = '\0';
1346                 }
1347
1348                 memcpy(&sim_data->SmsData.MsgLength, &pData[4+7 + position], sizeof(char) );    //position is 7(sca)
1349
1350                 tpdu_len = sim_data->SmsData.MsgLength ;
1351
1352                 memcpy(&sim_data->SmsData.szData, &pData[4+position+4 + 7], tpdu_len );
1353
1354                 TEST_DEBUG("SCA Number : %s tpdu_len is %d",scaAddr,tpdu_len);
1355
1356                 pTPDU = malloc(sizeof(TS_BYTE) * tpdu_len);
1357                 TEST_DEBUG("bfor memcopy position is %d",position);
1358                 memcpy(pTPDU, &(sim_data->SmsData.szData[0]), tpdu_len);
1359                 TEST_DEBUG("after memcpy");
1360
1361                 DecodeSmsDeliverTpdu(tpdu_len, pTPDU);
1362
1363                 free(pTPDU);
1364         }
1365
1366 }//Madhavi
1367
1368 void MemoryFullNotification(int length, char *pData)
1369 {
1370         int * memory_ind;
1371
1372         if(pData == NULL){
1373                 TEST_DEBUG("pData is Null")
1374                 return;
1375         }
1376         memory_ind = (int *)pData;
1377         TEST_DEBUG("In memory full notification status %d",*memory_ind);
1378
1379 }//Madhavi
1380
1381
1382 void DeleteMsgNotification(int length, char *pData)
1383 {
1384         int *index;
1385
1386         if(pData == NULL){
1387                 TEST_DEBUG("pData is Null")
1388                 return;
1389         }
1390         index = (int *) pData;
1391         TEST_DEBUG("In deletenotifcation the result and index are [%d]", *index);
1392
1393
1394 }//madhavi
1395
1396 void SaveMsgNotification(int length, char *pData)
1397 {
1398         int *index;
1399
1400         if(pData == NULL){
1401                 TEST_DEBUG("pData is Null")
1402                 return;
1403         }
1404         index = (int *)pData;
1405         TEST_DEBUG("In savestatus noti, index [%d]", *index);
1406
1407 }
1408
1409 void GetCBNotification(int length, char *pData)
1410 {
1411         TelSmsCbConfig_t * CBConfig;
1412         int i =0;
1413
1414         if(pData == NULL){
1415                 TEST_DEBUG("pData is Null")
1416                 return;
1417         }
1418
1419         CBConfig =(TelSmsCbConfig_t *) pData;
1420
1421
1422         TEST_DEBUG("=========CB Configuration=========");
1423
1424         /*** CB Enable/Diable ***/
1425         if(CBConfig->bCBEnabled==TRUE)
1426                 TEST_DEBUG("Cell Broadcast Msg Enabled...")
1427         else
1428                 TEST_DEBUG("Cell Broadcast Msg Disabled...")
1429
1430
1431                         /*** Selected ID ***/
1432                         if(CBConfig->SelectedId == 0x01)
1433                                 TEST_DEBUG("All CBMI is selected... ")
1434                         else if(CBConfig->SelectedId == 0x02)
1435                                 TEST_DEBUG("There are some selected CBMI...");
1436
1437         /*** CBMI  Count ***/
1438         TEST_DEBUG("CBMI Count: %d \n",CBConfig->MsgIdCount);
1439
1440         /*** CBMI  List ***/
1441
1442         if(CBConfig->MsgIdCount !=0)
1443         {
1444
1445                 TEST_DEBUG("----- CBMI List -----");
1446
1447                 for(i =0 ; i < CBConfig->MsgIdCount; i++)
1448                 {
1449
1450                         TEST_DEBUG("No.%d - [0x%04x]", i,CBConfig->MsgIDs[i]);
1451
1452                 }
1453
1454         }
1455         TEST_DEBUG("==================================");
1456
1457 }
1458
1459 void param_get_noti(int length, char *pData)
1460 {
1461         TelSmsParams_t *smsp_param;
1462
1463         if(pData == NULL){
1464                 TEST_DEBUG("pData is Null")
1465                 return;
1466         }
1467         smsp_param = (TelSmsParams_t  *)pData;
1468
1469         TEST_DEBUG("record index is %x",smsp_param->RecordIndex);
1470         TEST_DEBUG("record len  is %x",smsp_param->RecordLen);
1471         TEST_DEBUG("alpha_id len  is %lu ",smsp_param->AlphaIdLen);
1472         TEST_DEBUG("alpha_id is %s ",smsp_param->szAlphaId);
1473         TEST_DEBUG("param indicator is  %xn",smsp_param->ParamIndicator);
1474         TEST_DEBUG("dest dialling num is %s",smsp_param->TpDestAddr.szDiallingNum);
1475         TEST_DEBUG("svcaddr dialling num is %s",smsp_param->TpSvcCntrAddr.szDiallingNum);
1476         TEST_DEBUG("pid %x",smsp_param->TpProtocolId);
1477         TEST_DEBUG("dcs is %x",smsp_param->TpDataCodingScheme);
1478         TEST_DEBUG("validity is %x",smsp_param->TpValidityPeriod);
1479 }
1480
1481
1482 void Device_ReadyNoti(int length, char *pData)
1483 {
1484         int *device_status;
1485
1486         if(pData == NULL){
1487                 TEST_DEBUG("pData is Null")
1488                 return;
1489         }
1490
1491         device_status = (int *)pData;
1492
1493         if(*device_status == TRUE){
1494                 TEST_DEBUG("Device Ready");
1495         }
1496         else if(*device_status  == FALSE){
1497                 TEST_DEBUG("Device Not Ready");
1498         }
1499         else{
1500                 TEST_DEBUG("In device ready noti the result is %d",*device_status );
1501         }
1502         return;
1503 }
1504
1505 void Deliver_ReportNoti(int status)
1506 {
1507         if(status == TAPI_NETTEXT_SENDSMS_SUCCESS){
1508                 TEST_DEBUG("DELIVERY REPORT SUCCESS");
1509         }
1510         else{
1511                 TEST_DEBUG("DELIVERY REPORT Fail : Reason[0x%0x]", status);
1512         }
1513
1514         return;
1515 }
1516
1517
1518 void get_preferred_bearer_noti(int length,char *pData)
1519
1520 {
1521         TEST_DEBUG("get preferred bearer");
1522         int svc=0;
1523         TelSmsBearerType_t *bearer;
1524
1525         if(pData == NULL){
1526                 TEST_DEBUG("pData is Null")
1527                 return;
1528         }
1529
1530         bearer=(TelSmsBearerType_t *)pData;
1531         TEST_DEBUG("In GetPreferredBearer noti bearer:%d",*bearer);
1532         svc=*bearer;
1533         TEST_DEBUG("svc:%d",svc);
1534
1535         if(svc== TAPI_NETTEXT_BEARER_PS_ONLY)
1536                 TEST_DEBUG("Packet Domain")
1537         else if(svc== TAPI_NETTEXT_BEARER_CS_ONLY)
1538                 TEST_DEBUG("Circuit Switched")
1539         else if(svc== TAPI_NETTEXT_BEARER_PS_PREFERRED)
1540                 TEST_DEBUG("Packet Domain preferred ")
1541         else if(svc== TAPI_NETTEXT_BEARER_CS_PREFERRED)
1542                 TEST_DEBUG("Circuit Switched preferred")
1543
1544 }
1545
1546 void set_request_confirm_noti(int length, char *pData)
1547 {
1548         TEST_DEBUG("***Set Request  confirm Notification*******");
1549
1550         TelSmsSetResponse *pSetReqConfType;
1551
1552         if(pData == NULL){
1553                 TEST_DEBUG("pData is Null")
1554                 return;
1555         }
1556         pSetReqConfType = (TelSmsSetResponse *)pData;
1557
1558         switch(*pSetReqConfType)
1559         {
1560                 case TAPI_NETTEXT_CBSETCONFIG_RSP:
1561                         TEST_DEBUG("TAPI_NETTEXT_CBSETCONFIG_RSP");
1562                         break;
1563 #if 0
1564                 case TAPI_NETTEXT_SETPREFERREDBEARER_RSP:
1565                         TEST_DEBUG("TAPI_NETTEXT_SETPREFERREDBEARER_RSP");
1566                         break;
1567 #endif
1568                 case TAPI_NETTEXT_SETPARAMETERS_RSP:
1569                         TEST_DEBUG("TAPI_NETTEXT_SETPARAMETERS_RSP");
1570                         break;
1571
1572                 case TAPI_NETTEXT_SETMEMORYSTATUS_RSP:
1573                         TEST_DEBUG("TAPI_NETTEXT_SETMEMORYSTATUS_RSP");
1574                         break;
1575
1576                 case TAPI_NETTEXT_SETMESSAGESTATUS_RSP:
1577                         TEST_DEBUG("TAPI_NETTEXT_SETMESSAGESTATUS_RSP");
1578                         break;
1579
1580                 case TAPI_NETTEXT_SETDEVICESTATUS_RSP:
1581                         TEST_DEBUG("TAPI_NETTEXT_SETDEVICESTATUS_RSP");
1582                         break;
1583
1584                 case TAPI_NETTEXT_SETSCADDR_RSP:
1585                         TEST_DEBUG("TAPI_NETTEXT_SETSCADDR_RSP");
1586                         break;
1587
1588                 default:
1589                         TEST_DEBUG("Unknown set request confirm noti");
1590                         break;
1591
1592         }
1593
1594         TEST_DEBUG("Notification Received Successfully");
1595 }
1596
1597 void param_count_noti(int length, char *pData)
1598 {
1599         int  * RecordCount;
1600
1601         if(pData == NULL){
1602                 TEST_DEBUG("pData is Null")
1603                 return;
1604         }
1605
1606         RecordCount = (int *)pData;
1607
1608         TEST_DEBUG("ParamCnt Length[%d]", length);
1609         TEST_DEBUG("In param_count_noti the record count is %d", *RecordCount);
1610 }
1611
1612 int  SendMessage()
1613 {
1614         int     ret;
1615         int     msg_len=0;
1616         char buf[512];
1617         char message[512];
1618         //char bearerType[2];
1619         char diallingNum[TAPI_NETTEXT_ADDRESS_LEN_MAX];
1620         int     diallingNum_len=0;
1621
1622         memset(buf,0, sizeof(buf));
1623         memset(diallingNum,0,sizeof(diallingNum));
1624         diallingNum_len=0;
1625
1626         TEST_DEBUG("Enter destination Number: ");
1627
1628         ret = read(0, buf, sizeof(buf));
1629         if (ret < 0)
1630         {
1631                 if (errno == EINTR)
1632                         perror("read(1)");
1633                 return -1;
1634         }
1635         else if (ret == 0)
1636                 return ret;
1637
1638         diallingNum_len=strlen(diallingNum);
1639         memcpy(&diallingNum[diallingNum_len], buf,sizeof(buf));
1640
1641         diallingNum_len = strlen(diallingNum); //recalculate
1642         TEST_DEBUG("dialling num %s and dialling num len is %d",diallingNum,diallingNum_len);
1643         diallingNum[diallingNum_len]=0;
1644         diallingNum_len =diallingNum_len-1;
1645
1646         TEST_DEBUG("Enter Message: ");
1647         memset(message,0,sizeof(message));
1648
1649         ret = read(0, message, sizeof(message));
1650
1651         if (ret <= 0) {
1652                 TEST_DEBUG(" NULL msg can NOT be sent ");
1653                 return -1;
1654         }
1655
1656         msg_len=strlen(message);
1657
1658         TEST_DEBUG("==========================");
1659         TEST_DEBUG("To :%s", diallingNum);
1660         TEST_DEBUG("Message: %sMsg Length:%d",message, msg_len);
1661         TEST_DEBUG("Dialling number Length : %d" ,diallingNum_len);
1662         TEST_DEBUG("==========================\n");
1663
1664         EncodeSmsSubmitTpdu(diallingNum, diallingNum_len,message, msg_len) ;
1665         return 1;
1666
1667 }
1668
1669 int SendMessageCDMA()
1670 {
1671         int ret;
1672         int msg_len = 0;
1673         char buf[512] = {0,};
1674         char message[512] = {0,};
1675         char diallingNum[TAPI_NETTEXT_ADDRESS_LEN_MAX] = {0,};
1676         int diallingNum_len = 0;
1677
1678         printf("\n");
1679         printf("Enter destination Number:\n>> ");
1680         fflush(stdout);
1681
1682         ret = read(0, buf, sizeof(buf));
1683         if (ret < 0) {
1684                 if (errno == EINTR)
1685                         perror("read(1)");
1686                 return -1;
1687         }
1688         else if (ret == 0)
1689                 return ret;
1690
1691         diallingNum_len = strlen(diallingNum);
1692         memcpy(&diallingNum[diallingNum_len], buf, sizeof(buf));
1693
1694         diallingNum_len = strlen(diallingNum); //recalculate
1695         diallingNum[diallingNum_len] = 0;
1696         diallingNum_len = diallingNum_len - 1;
1697         printf("dialling num [%s], dialling num len [%d]\n", diallingNum, diallingNum_len);
1698
1699         printf("Enter Message\n>> ");
1700         fflush(stdout);
1701
1702         ret = read(0, message, sizeof(message));
1703         if (ret <= 0) {
1704                 printf(" NULL msg can NOT be sent \n");
1705                 return -1;
1706         }
1707
1708         msg_len = strlen(message);
1709
1710         printf("===========================\n");
1711         printf("To: [%s] (len: %d)\n", diallingNum, diallingNum_len);
1712         printf("Message: [%s]\nMsg Length: [%d]\n", message, msg_len);
1713         printf("===========================\n\n");
1714
1715         EncodeCdmaSmsSubmitTpdu(diallingNum, diallingNum_len, message, msg_len);
1716         //EncodeSmsSubmitTpdu(diallingNum, diallingNum_len,message, msg_len) ;
1717
1718         return 1;
1719 }
1720
1721
1722
1723
1724 int ReadMessage()
1725 {
1726         int             menu;
1727         int             ret;
1728         char    buf[100];
1729
1730         TapiResult_t returnStatus;
1731         int requestId = 0;
1732         memset(buf,0, sizeof(buf));
1733
1734         TEST_DEBUG("*************************************");
1735         TEST_DEBUG("1. SIM Message");
1736
1737         TEST_DEBUG("Select Number:");
1738
1739         ret = read(0, buf, sizeof(buf));
1740
1741         if (ret < 0)
1742         {
1743                 if (errno == EINTR)
1744                         perror("read(1)");
1745                 return -1;
1746         }
1747         else if (ret == 0)
1748                 return ret;
1749
1750         menu = atoi(buf);
1751         TEST_DEBUG("menu in read message(value is 1) is %d ",menu);
1752         switch(menu)
1753         {
1754                 case 1:
1755
1756                         TEST_DEBUG("***Reading the message(Api:GetMsgCount)***");
1757                         returnStatus = tel_get_sms_count(&requestId);
1758                         TEST_DEBUG("status for read message is %d request Id %d",returnStatus,requestId);
1759
1760         }
1761         return 1;
1762 }
1763
1764 int DeleteMessage(
1765                 )
1766 {
1767         int     ret;
1768         int     index;
1769         char buf[100];
1770
1771         TapiResult_t returnStatus;
1772
1773         int requestId = 0;
1774
1775         memset(buf, 0, sizeof(buf));
1776
1777         TEST_DEBUG("Enter delete index >>");
1778
1779         ret = read(0, buf, sizeof(buf));
1780         if (ret < 0)
1781         {
1782                 if (errno == EINTR)
1783                         perror("read(1)");
1784                 return -1;
1785         }
1786         else if (ret == 0)
1787                 return ret;
1788
1789         index=atoi(buf);
1790         TEST_DEBUG("index value :%d",index);
1791
1792
1793         TEST_DEBUG("***Deleting the message(Api:DeleteMsg,GetMsgCount)***");
1794
1795         returnStatus = tel_delete_sms_in_sim(index,&requestId);
1796         TEST_DEBUG("returnstatus  delete message  is for delete%d request id %d",returnStatus,requestId);
1797         returnStatus = tel_get_sms_count(&requestId);
1798         TEST_DEBUG("returnStatus for  delete msg msgcnt  %d requestid %d",returnStatus,requestId);
1799
1800
1801         return 1;
1802
1803 }
1804
1805 int ReceiveMessage(int pdu_len, char * pPDU)
1806 {
1807
1808         int                scaAddr_len =0;
1809         char                * pTPDU;
1810         int                 tpdu_len =0;
1811         char                diallingNum[TAPI_NETTEXT_ADDRESS_LEN_MAX];
1812         char             scaAddr[TAPI_NETTEXT_SCADDRESS_LEN_MAX]; //service center address
1813         int                 sca_ton, sca_npi;
1814         int                 position;
1815
1816         TS_BYTE MTI = 0;
1817         TS_BYTE MMS = 0;
1818         TS_BYTE SRI = 0;
1819         TS_BYTE UDHI = 0;
1820         TS_BYTE RP = 0;
1821
1822         tapi_nettext_coding_scheme dcs;
1823         TelSmsDatapackageInfo_t * datapackage;
1824         TapiResult_t returnStatus;
1825         position=0;
1826         int requestId = 0;
1827
1828         if(pPDU == NULL){
1829                 TEST_DEBUG("pData is Null")
1830                 return FALSE;
1831         }
1832         /*      for debug
1833                 for( i=0;i<pdu_len ; i++)
1834                 TEST_DEBUG("[%02x]", pPDU[i]);
1835                 */
1836
1837         datapackage = (TelSmsDatapackageInfo_t *)pPDU;
1838
1839         memset(diallingNum, 0, sizeof(diallingNum));
1840
1841         SmsUtilDecodeAddrField(diallingNum, (char *)datapackage->Sca, &sca_ton, &sca_npi);
1842
1843         scaAddr_len = strlen( diallingNum );
1844
1845         if ( sca_ton == SIM_TON_INTERNATIONAL )
1846         {
1847                 scaAddr[0] = '+';
1848                 memcpy( &scaAddr[1], diallingNum, scaAddr_len );
1849                 scaAddr[scaAddr_len+1] = '\0';
1850         }
1851         else
1852         {
1853                 memcpy( scaAddr, diallingNum, scaAddr_len );
1854                 scaAddr[scaAddr_len] = '\0';
1855         }
1856
1857         TEST_DEBUG("Sc address in test app is %s",scaAddr);
1858
1859         RP = datapackage->szData[position] & 0x80;
1860         UDHI = datapackage->szData[position] & 0x40;
1861         SRI = datapackage->szData[position] & 0x20;
1862         MMS = datapackage->szData[position] & 0x04;
1863         MTI = datapackage->szData[position] & 0x03;
1864
1865         TEST_DEBUG("RP [%x]", RP);
1866         TEST_DEBUG("UDHI [%x]", UDHI);
1867         TEST_DEBUG("SRI [%x]", SRI);
1868         TEST_DEBUG("MMS [%x]", MMS);
1869         TEST_DEBUG("MTI [%02x]", MTI);
1870
1871         tpdu_len = datapackage->MsgLength;
1872
1873         pTPDU = malloc(sizeof(TS_BYTE) * tpdu_len);
1874
1875         memcpy(pTPDU, &datapackage->szData[position], tpdu_len);
1876
1877         if(MTI ==SMS_TPDU_DELIVER)
1878         {
1879                 DecodeSmsDeliverTpdu(tpdu_len, pTPDU);
1880
1881                 TEST_DEBUG("dcs_pos : %d", dcs_pos);
1882
1883                 SmsUtilDecodeDCS(&dcs, datapackage->szData[position+dcs_pos]);
1884
1885                 //if(dcs.class_type == TAPI_NETTEXT_CLASS_2)
1886                 {
1887                         TEST_DEBUG("dcs type is of class2");
1888                         TelSmsData_t WriteData;
1889
1890                         memset(&WriteData, 0, sizeof(TelSmsData_t));
1891
1892                         memcpy(WriteData.SmsData.Sca , datapackage->Sca, TAPI_SIM_SMSP_ADDRESS_LEN);
1893
1894                         WriteData.SmsData.MsgLength = datapackage->MsgLength;
1895
1896                         memcpy(WriteData.SmsData.szData, datapackage->szData, datapackage->MsgLength);
1897
1898                         WriteData.MsgStatus = TAPI_NETTEXT_STATUS_READ;
1899
1900                         returnStatus = tel_write_sms_in_sim(&WriteData, &requestId);
1901
1902                         TEST_DEBUG("returnStatus for write  %d requestId :%d",returnStatus,requestId);
1903                 }
1904
1905
1906         }
1907         else if(MTI==SMS_TPDU_STATUS_REPORT)
1908         {
1909                 DecodeSmsStatusReportTpdu(tpdu_len, pTPDU);
1910         }
1911
1912         TelSmsDatapackageInfo_t * del_report= NULL;
1913
1914         del_report= malloc(sizeof(TelSmsDatapackageInfo_t));
1915
1916         memset(del_report, 0, sizeof(TelSmsDatapackageInfo_t));
1917
1918         memcpy(del_report->Sca, datapackage->Sca, TAPI_SIM_SMSP_ADDRESS_LEN);
1919
1920         del_report->szData[0] = SMS_TPDU_DELIVER_REPORT;        //TP-UDHI[bit6] : 0
1921         del_report->szData[1] = 0;      // TP-PI = 0; bit2: TP-UDL bit1: TP-DCS bit0: TP-PID (No option field)
1922         del_report->MsgLength = 2;
1923
1924         TEST_DEBUG("***receive message (Api:SendDeliverreport)****");
1925
1926
1927         returnStatus =tel_send_sms_deliver_report(del_report,TAPI_NETTEXT_SENDSMS_SUCCESS, &requestId);
1928
1929         TEST_DEBUG("AFter send deliver report request id[%d] & result [0x%x]",requestId,returnStatus);
1930
1931         free(del_report);
1932
1933         free(pTPDU);
1934
1935         return 1;
1936 }
1937
1938 int GetInformation()
1939 {
1940         int             menu;
1941         int             ret;
1942         char    buf[100];
1943
1944         TapiResult_t returnStatus;
1945
1946         /* Get CB Setting Information */
1947         //TS_UINT16 CBChannel[MAX_GSM_SMS_CBMI_LIST_SIZE];
1948         int requestId=0;
1949
1950         memset(buf,0, sizeof(buf));
1951
1952         TEST_DEBUG("*************************************");
1953         TEST_DEBUG("1.Get Service Center Number");
1954         TEST_DEBUG("2.Get CB Setting Information");
1955         TEST_DEBUG("3.Get SMS Parameters");
1956         TEST_DEBUG("4.Get SMS PreferredBearer Information (Not supported)");
1957         TEST_DEBUG("5.Get SMS Parameter Count");
1958         TEST_DEBUG("6.Get Message Count");
1959         TEST_DEBUG("*************************************");
1960         TEST_DEBUG("Select Number:");
1961
1962         ret = read(0, buf, sizeof(buf));
1963
1964         if (ret < 0)
1965         {
1966                 if (errno == EINTR)
1967                         perror("read(1)");
1968                 return -1;
1969         }
1970         else if (ret == 0)
1971                 return ret;
1972
1973         menu = atoi(buf);
1974
1975         switch(menu)
1976         {
1977                 case 1:
1978                         {
1979                                 TEST_DEBUG("***Getting the SCA(Api: GetSCA)****");
1980                                 returnStatus = tel_get_sms_sca(0, &requestId);
1981                                 TEST_DEBUG("returnstatus for scaddr get %d",returnStatus);
1982 #if 0
1983                                 SmsUtilDecodeAddrField(decodeScaAddr, (char*)sc_addr.szDiallingNum, (int *)&sc_addr.Ton, (int *)&sc_addr.Npi);
1984
1985                                 sca_len = strlen( decodeScaAddr );
1986
1987                                 if ( sc_addr.Ton== SIM_TON_INTERNATIONAL )
1988                                 {
1989                                         realScaAddr[0] = '+';
1990                                         memcpy( &realScaAddr[1], decodeScaAddr, sca_len );
1991                                         realScaAddr[sca_len+1] = '\0';
1992                                 }
1993                                 else
1994                                 {
1995                                         memcpy( realScaAddr, decodeScaAddr, sca_len );
1996                                         realScaAddr[sca_len] = '\0';
1997                                 }
1998
1999                                 TEST_DEBUG("===== Decode SCA Address =====");
2000                                 TEST_DEBUG("SCA Number :%s ",realScaAddr);
2001                                 TEST_DEBUG("==============================");
2002 #endif
2003                                 break;
2004                         }
2005
2006
2007                 case 2:
2008                         {
2009
2010                                 TEST_DEBUG("***Getting the CB Configuration(Api: GetCBConfig)***");
2011                                 returnStatus =  tel_get_sms_cb_config(&requestId);
2012                                 TEST_DEBUG("ReturnStatus[%d] Requestid0x%x]",returnStatus,requestId);
2013                                 break;
2014                         }
2015
2016                 case 3:
2017                         {
2018
2019                                 TEST_DEBUG("****Getting the parameter(Api:GetParameter)****");
2020                                 returnStatus = tel_get_sms_parameters(0,&requestId);
2021                                 TEST_DEBUG("ReturnStatus[%d] Requestid0x%x]",returnStatus,requestId);
2022                                 break;
2023                         }
2024                 case 4:
2025                         {
2026
2027                                 //TEST_DEBUG("***Getting preferrredBearer(Api:GetPreferredBearer)***");
2028                                 //returnStatus=tel_get_sms_preferred_bearer(&requestId);
2029                                 //TEST_DEBUG("ReturnStatus[%d] Requestid0x%x]",returnStatus,requestId);
2030                                 break;
2031                         }
2032
2033                 case 5:
2034                         {
2035                                 returnStatus = tel_get_sms_parameter_count(&requestId);
2036                                 TEST_DEBUG("ReturnStatus[%d] Requestid0x%x]",returnStatus,requestId);
2037                                 break;
2038                         }
2039                 case 6:
2040                         {
2041                                 returnStatus = tel_get_sms_count(&requestId);
2042                                 TEST_DEBUG("ReturnStatus[%d] Requestid0x%x]",returnStatus,requestId);
2043                                 break;
2044                         }
2045                 default:
2046                         return -1;
2047
2048         }
2049
2050         return 1;
2051 }
2052
2053 int Setting()
2054 {
2055         int                             settingMenu;
2056         int                             ret;
2057         char                    buf[512];
2058
2059         char            MemoryStatus[2]; //2006/8/8
2060         char                    bearerType[2];  //2006/8/8
2061         char            cbEnable[2];//2006/8/8
2062
2063         TelSmsCbConfig_t   *pCBConfig;
2064
2065         int                             memType;
2066         int                             index;
2067         int                             msgStauts;
2068
2069         TelSmsParams_t  smsParameters = {0,};
2070         TapiResult_t returnStatus;
2071         int requestId=0;
2072
2073         memset(buf,0, sizeof(buf));
2074
2075         TEST_DEBUG("*************************************");
2076         TEST_DEBUG("1.Set Service Center Number");
2077         TEST_DEBUG("2.Set PreferredBearer Type");
2078         TEST_DEBUG("3.Set Deliver Report");
2079         TEST_DEBUG("4.Set CB Enable/Disable");
2080         TEST_DEBUG("5.Set SMS Parameters");
2081         TEST_DEBUG("6.Set Memory Status");
2082         TEST_DEBUG("7.Set Stored MsgStaus");
2083         TEST_DEBUG("8.Set Device Ready");
2084         TEST_DEBUG("9.Check Device Status");
2085         TEST_DEBUG("*************************************");
2086         TEST_DEBUG("Select Number:");
2087
2088         ret = read(0, buf, sizeof(buf));
2089
2090         if (ret < 0)
2091         {
2092                 if (errno == EINTR)
2093                         perror("read(1)");
2094                 return -1;
2095         }
2096         else if (ret == 0)
2097                 return ret;
2098
2099         settingMenu = atoi(buf);
2100
2101
2102         switch(settingMenu)
2103         {
2104                 case 1:  //Set Service Center Number
2105                         {
2106                                 TEST_DEBUG("***Setting the SCA(Api:SetSCA)****");
2107                                 TelSmsAddressInfo_t sca;
2108
2109                                 memset(&sca, 0, sizeof(TelSmsAddressInfo_t));
2110
2111                                 sca.DialNumLen = 0x5;
2112                                 sca.Npi = TAPI_SIM_NPI_ISDN_TEL;
2113                                 sca.Ton = TAPI_SIM_TON_INTERNATIONAL;
2114                                 sca.szDiallingNum[0] = 0x28;
2115                                 sca.szDiallingNum[1] = 0x01;
2116                                 sca.szDiallingNum[2] = 0x19;
2117                                 sca.szDiallingNum[3] = 0x11;
2118                                 sca.szDiallingNum[4] = 0x11;
2119
2120                                 returnStatus =  tel_set_sms_sca(&sca,0,&requestId);
2121
2122                                 TEST_DEBUG("returnstatus after scaddr get is is %d requestId:%d ",returnStatus,requestId);
2123
2124                                 break;
2125                         }
2126
2127                 case 2:
2128                         {
2129                                 TEST_DEBUG("****Setting the BearerType(Api:SetPreferredBearer)****");
2130
2131                                 TEST_DEBUG("Enter Bearer Type(1:PD, 2:CS, 3:PDP 4:CSP):");
2132
2133                                 memset(bearerType,0 ,sizeof(bearerType));
2134
2135                                 ret = read(0, bearerType, sizeof(bearerType));
2136                                 if (ret <= 0) {
2137                                         TEST_DEBUG(" NULL msg can NOT be sent ");
2138                                         return -1;
2139                                 }
2140                                 TEST_DEBUG("Set Preferred Bearer : bearerType =%d ", atoi(bearerType));
2141
2142                                 returnStatus = tel_set_sms_preferred_bearer(atoi(bearerType),&requestId);
2143                                 TEST_DEBUG("returnStatus  after prefbearer set  is %d, reqid=[%d]",returnStatus,requestId);
2144
2145                                 break;
2146                         }
2147
2148                 case 3: //Set Deliver Report
2149                         {
2150                                 TEST_DEBUG("****Setting  Deliver Report(Api:SetDeliverReport)****");
2151                                 //EncodeSmsDeliverReportTpdu();
2152                                 break;
2153                         }
2154                 case 4: //Set CB Enable/Disable
2155                         {
2156                                 TEST_DEBUG("****Setting the CB configuration(Api:SetCbConfig)****");
2157
2158                                 TEST_DEBUG("Enter CB ON/OFF (1: Enable, 2:Disable):");
2159
2160                                 memset(cbEnable,0 ,sizeof(cbEnable));
2161                                 pCBConfig = malloc(sizeof(TelSmsCbConfig_t));
2162
2163                                 ret = read(0, cbEnable, sizeof(cbEnable));
2164
2165                                 if (ret <= 0) {
2166                                         TEST_DEBUG(" NULL msg can NOT be sent ");
2167                                         return -1;
2168                                 }
2169
2170                                 pCBConfig->bCBEnabled = atoi(cbEnable);
2171                                 pCBConfig->SelectedId = 0x01;
2172                                 pCBConfig->MsgIdCount = 0x02;
2173
2174                                 pCBConfig->MsgIDs[0] = 0x0c;
2175                                 pCBConfig->MsgIDs[1] = 0x0c;
2176                                 pCBConfig->MsgIDs[2] = 0xdf;
2177                                 pCBConfig->MsgIDs[3] = 0x00;
2178
2179                                 TEST_DEBUG("from sms test setting the cb configuration:CBEnabled:%d,selectedId:%d,msgCount:%d,msgId: %d\t %d\t %d\t %d",pCBConfig->bCBEnabled,pCBConfig->SelectedId,pCBConfig->MsgIdCount,pCBConfig->MsgIDs[0],pCBConfig->MsgIDs[1],pCBConfig->MsgIDs[2],pCBConfig->MsgIDs[3]);
2180
2181                                 returnStatus = tel_set_sms_cb_config(pCBConfig,&requestId);
2182                                 TEST_DEBUG("returnStatus after cbconfig set is is [%d], reqid [%d]",returnStatus,requestId);
2183
2184                                 free(pCBConfig);
2185                                 break;
2186                         }
2187
2188                 case 5:
2189                         {
2190                                 char* name = "Lpg";
2191                                 char* num = "0103001408";
2192                                 char* sca = "8210911111";
2193
2194
2195                                 TEST_DEBUG("****Setting Parameters(Api:SetParameters)****");
2196
2197                                 smsParameters.RecordIndex = 0x00;
2198                                 smsParameters.RecordLen = 31;
2199                                 smsParameters.AlphaIdLen = 3;
2200                                 memcpy(&smsParameters.szAlphaId,name,strlen(name));
2201
2202
2203                                 smsParameters.ParamIndicator = 0xe0;
2204                                 smsParameters.TpDestAddr.DialNumLen = 10;
2205                                 smsParameters.TpDestAddr.Ton = 1;
2206                                 smsParameters.TpDestAddr.Npi = 1;
2207
2208                                 smsParameters.TpSvcCntrAddr.DialNumLen = 10;
2209                                 smsParameters.TpSvcCntrAddr.Ton = 1;
2210                                 smsParameters.TpSvcCntrAddr.Npi = 1;
2211
2212                                 memcpy(smsParameters.TpDestAddr.szDiallingNum , num, strlen(num));
2213                                 memcpy(smsParameters.TpSvcCntrAddr.szDiallingNum, sca, strlen(sca));
2214                                 smsParameters.TpProtocolId = 3;
2215                                 smsParameters.TpDataCodingScheme = 2;
2216                                 smsParameters.TpValidityPeriod = 1;
2217
2218                                 returnStatus = tel_set_sms_parameters(&smsParameters,&requestId);
2219                                 TEST_DEBUG("returnstatus after sparam set  is %d reqid %d",returnStatus,requestId);
2220                                 break;
2221                         }
2222                 case 6: //Set Memory Full Notification
2223                         {
2224                                 TEST_DEBUG("Enter Memory Status to be set(1:Memory Available, 2:Memory Full)");
2225                                 memset(MemoryStatus,0 ,sizeof(MemoryStatus));
2226                                 ret = read(0, MemoryStatus, sizeof(MemoryStatus));
2227                                 if (ret <= 0) {
2228                                         TEST_DEBUG(" NULL msg can NOT be sent ");
2229                                         return -1;
2230                                 }
2231                                 TEST_DEBUG("Memory Status type is %d ", atoi(MemoryStatus));
2232                                 returnStatus =tel_set_sms_memory_status(atoi(MemoryStatus), &requestId);//Set to full 0x02-Full, 0x01-available
2233                                 TEST_DEBUG("api err after memstatus set is is %d",returnStatus);
2234                                 break;
2235                         }
2236                 case 7: //Set Stored MsgStaus
2237                         {
2238                                 memType=2;
2239                                 index=2;
2240                                 msgStauts =2;
2241
2242                                 //TapiReadNetText(index, &CurMsgStauts, &DataPackage);
2243                                 returnStatus = tel_read_sms_in_sim(index,&requestId);//To avoid  mismatch of prototypes
2244                                 TEST_DEBUG("returnStatus after read is is %d",returnStatus);
2245
2246                                 TEST_DEBUG("Before set status : index = %d, CurMsgStauts=%d",index,msgStauts);
2247
2248                                 returnStatus = tel_set_sms_message_status(index,  msgStauts,&requestId);
2249                                 TEST_DEBUG("returnStatus after msgstatus set is %d",returnStatus);
2250
2251                                 //tapi_nettext_read(index, &CurMsgStauts, &DataPackage);
2252                                 returnStatus = tel_read_sms_in_sim(index,&requestId);//To avoid  mismatch of prototypes
2253                                 TEST_DEBUG("returnStatus after read is %d",returnStatus);
2254
2255                                 break;
2256                         }
2257                 case 8:
2258                         {
2259                                 returnStatus =tel_set_sms_device_status();
2260                                 TEST_DEBUG("returnStatus after read is %d",returnStatus);
2261                                 break;
2262                         }
2263                 case 9:
2264                         {
2265                                 int status = 0;
2266                                 returnStatus =tel_check_sms_device_status(&status);
2267                                 if (status == 1)
2268                                 {
2269                                         TEST_DEBUG("Device Ready");
2270                                 }
2271                                 else
2272                                 {
2273                                         TEST_DEBUG("Device Not Ready");
2274                                 }
2275                                 TEST_DEBUG("returnStatus after read is %d",returnStatus);
2276                                 break;
2277                         }
2278                 default:
2279                         return -1;
2280         }
2281         return 1;
2282 }
2283
2284
2285 int sms_read_key_input_cdma(void)
2286 {
2287
2288         int     ret;
2289         char    buf[512];
2290
2291         //initialize value
2292         memset(buf, 0, sizeof(buf));
2293
2294         printf("\n");
2295         printf("*************************************\n");
2296         printf("1.Send New Message\n");
2297         printf("2.SMS Exit\n");
2298         printf("*************************************\n");
2299         printf("Select Number >> ");
2300         fflush(stdout);
2301
2302         ret = read(0, buf, sizeof(buf));
2303         if (ret < 0) {
2304                 if (errno == EINTR)
2305                         perror("read(1)");
2306                 return -1;
2307         }
2308         else if (ret == 0)
2309                 return ret;
2310
2311         if (memcmp(buf, "1", sizeof("1") - 1) == 0) {
2312                 SendMessageCDMA();
2313         }
2314         if (memcmp(buf, "2", sizeof("2") - 1) == 0) {
2315                 return -1;
2316         }
2317
2318         return 0;
2319 }
2320
2321 int sms_read_key_input(void)
2322 {
2323
2324         int     ret;
2325         char    buf[512];
2326         int returnStatus=0;
2327
2328         //initialize value
2329         memset(buf,0, sizeof(buf));
2330
2331         ret = read(0, buf, sizeof(buf));
2332         if (ret < 0)
2333         {
2334                 if (errno == EINTR)
2335                         perror("read(1)");
2336                 return -1;
2337         }
2338         else if (ret == 0)
2339                 return ret;
2340
2341         TEST_DEBUG("*************************************");
2342         TEST_DEBUG("1.Send New Message");
2343         TEST_DEBUG("2.Read Message");
2344         TEST_DEBUG("3.Delete Message");
2345         TEST_DEBUG("4.Delete All Message");
2346         TEST_DEBUG("5.Setting");
2347         TEST_DEBUG("6.Getting SMS Information");
2348         TEST_DEBUG("7.SMS Exit");
2349         TEST_DEBUG("*************************************");
2350         TEST_DEBUG("Select Number : %s", buf);
2351
2352         int requestId = 0;
2353
2354         if( memcmp(buf,"1",sizeof("1")-1) == 0 ){ SendMessage();}
2355         if( memcmp(buf,"2",sizeof("2")-1) == 0 ){ ReadMessage();}
2356         if( memcmp(buf,"3",sizeof("3")-1) == 0 ){ DeleteMessage();}
2357         if( memcmp(buf,"4",sizeof("4")-1) == 0 ){ returnStatus=tel_delete_sms_in_sim(-1,&requestId);TEST_DEBUG("returnStatus:%d,requestId:%d ",returnStatus,requestId);}
2358         if( memcmp(buf,"5",sizeof("5")-1) == 0 ){ Setting();}
2359         if( memcmp(buf,"6",sizeof("6")-1) == 0 ){ GetInformation();}
2360         if( memcmp(buf,"7",sizeof("7")-1) == 0 ){ return -1; }
2361
2362         return 0;
2363 }
2364
2365 void SMS_async_event_callback(TelTapiEvent_t* event)
2366 {
2367         //char event_string[IF_NAME_MAX];
2368         //char event_string[100];
2369         int iSize = 0;
2370
2371         TEST_DEBUG("Func Entrance");
2372         TEST_DEBUG("Request ID : [0x%x]\n", event->RequestId);
2373
2374 //      TAPI_GET_EVENT_NAME(  event->EventType, event_string);
2375 //      TEST_DEBUG("Event Type [%s]\n", event_string);
2376
2377         TEST_DEBUG("TAPI Event Status = [0x%0x]", event->Status);
2378         if(event->pData==NULL)
2379         {
2380                 TEST_DEBUG("No Event Data!!");
2381         }
2382         else{
2383                 iSize = sizeof(event->pData);
2384                 TEST_DEBUG("Data length:%d", iSize);
2385         }
2386
2387
2388         switch(event->EventType)
2389         {
2390
2391                 case TAPI_EVENT_NETTEXT_READ_SMS_CNF:
2392                         TEST_DEBUG("***************************************");
2393                         TEST_DEBUG("$$Read Msg Notification $$$");
2394                         ReadMsgNotification(iSize, event->pData);
2395                         TEST_DEBUG("***************************************");
2396                         break;
2397                 case TAPI_EVENT_NETTEXT_GET_COUNT_CNF:
2398                         TEST_DEBUG("***************************************");
2399                         TEST_DEBUG("$$$GetMsgCountNotification$$$$");
2400                         MsgCountNotification(iSize, event->pData);
2401                         TEST_DEBUG("***************************************");
2402                         break;
2403
2404                 case TAPI_EVENT_NETTEXT_SENTSTATUS_CNF:
2405                         TEST_DEBUG("***************************************");
2406                         TEST_DEBUG("$$$$$$ RECEIVE  ACK NOTIFICATION $$$$$$ ");
2407                         DecodeSmsSubmitReportTpdu(iSize, event->pData);
2408                         TEST_DEBUG("***************************************");
2409                         break;
2410
2411                 case TAPI_EVENT_NETTEXT_GET_PARAM_CNF:
2412                         TEST_DEBUG("***************************************");
2413                         TEST_DEBUG("$$$ GET PARAM NOTI$$$");
2414                         param_get_noti(iSize, event->pData);
2415                         TEST_DEBUG("***************************************");
2416                         break;
2417
2418                 case TAPI_EVENT_NETTEXT_DELETE_STATUS_CNF:
2419                         TEST_DEBUG("***************************************");
2420                         TEST_DEBUG("$$Delete Notification$$$");
2421                         DeleteMsgNotification(iSize, event->pData);
2422                         TEST_DEBUG("***************************************");
2423                         break;
2424
2425                 case TAPI_EVENT_NETTEXT_SAVE_STATUS_CNF:
2426                         TEST_DEBUG("***************************************");
2427                         TEST_DEBUG("$$Save Status Notification$$");
2428                         SaveMsgNotification(iSize, event->pData);
2429                         TEST_DEBUG("***************************************");
2430                         break;
2431
2432                 case TAPI_EVENT_NETTEXT_SET_REQUEST_CNF:
2433                         TEST_DEBUG("***************************************");
2434                         TEST_DEBUG("$$$ SET REQUESTCONFIRM NOTI$$$");
2435                         set_request_confirm_noti(iSize, event->pData);
2436                         TEST_DEBUG("***************************************");
2437                         break;
2438
2439                 case TAPI_EVENT_NETTEXT_GET_CB_CONFIG_CNF:
2440                         TEST_DEBUG("***************************************");
2441                         TEST_DEBUG("$$$GET CB Config$$$");
2442                         GetCBNotification(iSize, event->pData);
2443                         TEST_DEBUG("***************************************");
2444                         break;
2445
2446                 case TAPI_EVENT_NETTEXT_GET_SMSBEARER_CNF:
2447                         TEST_DEBUG("****************************************");
2448                         TEST_DEBUG("$$$ GET PREFERRED BEARER$$$");
2449                         get_preferred_bearer_noti(iSize, event->pData);
2450                         TEST_DEBUG("****************************************");
2451                         break;
2452
2453                 case TAPI_EVENT_NETTEXT_DELIVERY_REPORT_CNF:
2454                         TEST_DEBUG("***************************************");
2455                         TEST_DEBUG("$$$$$$ DELIVER REPORT NOTI $$$$$$");
2456                         Deliver_ReportNoti(event->Status);
2457                         TEST_DEBUG("***************************************");
2458                         break;
2459
2460                 case TAPI_EVENT_NETTEXT_INCOM_IND:
2461                         TEST_DEBUG("***************************************");
2462                         TEST_DEBUG("$$$$$$ INCOMING MESSAGE NOTIFICATION $$$$$$ ");
2463                         ReceiveMessage(iSize, event->pData);
2464                         TEST_DEBUG("***************************************");
2465                         break;
2466
2467                 case TAPI_EVENT_NETTEXT_CB_INCOM_IND:
2468                         TEST_DEBUG("***************************************");
2469                         TEST_DEBUG("$$$$$$ INCOMING CB NOTIFICATION $$$$$$ ");
2470                         DecodeCellBroadcastMsg(iSize, event->pData);
2471                         TEST_DEBUG("***************************************");
2472                         break;
2473
2474                 case TAPI_EVENT_NETTEXT_MEMORY_STATUS_IND:
2475                         TEST_DEBUG("***************************************");
2476                         TEST_DEBUG("$$$$$$ MEMORYF STATUS NOTIFICATION $$$$$$ ");
2477                         MemoryFullNotification(iSize, event->pData);
2478                         TEST_DEBUG("***************************************");
2479                         break;
2480
2481                 case TAPI_EVENT_NETTEXT_DEVICE_READY_IND:
2482                         TEST_DEBUG("***************************************");
2483                         TEST_DEBUG("$$$ DEVICE READY NOTI$$$");
2484                         Device_ReadyNoti(iSize, event->pData);
2485                         TEST_DEBUG("***************************************");
2486                         break;
2487
2488                 case TAPI_EVENT_NETTEXT_PARAM_COUNT_IND:
2489                         TEST_DEBUG("***************************************");
2490                         TEST_DEBUG("$$$ PARAM COUNT NOTI$$$");
2491                         param_count_noti(iSize, event->pData);
2492                         TEST_DEBUG("***************************************");
2493                         break;
2494                 case TAPI_EVENT_NETTEXT_SENTSTATUS_EX_CNF :
2495                         TEST_DEBUG("***************************************");
2496                         TEST_DEBUG("$$$$$$ SENT STATUS EX NOTIFICATION $$$$$$");
2497                         TEST_DEBUG("Test appl. is Not implemented yet");
2498                         TEST_DEBUG("***************************************");
2499                         break;
2500                 case TAPI_EVENT_NETTEXT_INCOM_EX_IND:
2501                         TEST_DEBUG("***************************************");
2502                         TEST_DEBUG("$$$$$$ INCOM EX NOTIFICATION $$$$$$");
2503                         TEST_DEBUG("Test appl. is Not implemented yet");
2504                         TEST_DEBUG("***************************************");
2505                         break;
2506                 case TAPI_EVENT_NETTEXT_CB_INCOM_EX_IND:
2507                         TEST_DEBUG("***************************************");
2508                         TEST_DEBUG("$$$$$$ CB INCOM EX NOTIFICATION $$$$$$");
2509                         TEST_DEBUG("Test appl. is Not implemented yet");
2510                         TEST_DEBUG("***************************************");
2511                         break;
2512
2513                 case TAPI_EVENT_NETTEXT_GET_SCA_CNF:
2514                         TEST_DEBUG("***************************************");
2515                         TEST_DEBUG("$$$$$$ GET SCA NOTIFICATION $$$$$$");
2516                         TEST_DEBUG("Test appl. is Not implemented yet");
2517                         TEST_DEBUG("***************************************");
2518                         break;
2519
2520                 default:
2521                         TEST_DEBUG("Event Type: unknown event:[%d]\n", event->EventType);
2522                         break;
2523         }
2524 }
2525
2526
2527 int sms_subscribe_tapi_events()
2528 {
2529         int i = 0;
2530         int ret_val = TRUE;
2531         int iNumOfSMSEvt = 0;
2532         TapiResult_t    api_err = TAPI_API_SUCCESS;
2533
2534
2535         int SMSEvtList[] =
2536         {
2537                 TAPI_EVENT_NETTEXT_READ_SMS_CNF,
2538                 TAPI_EVENT_NETTEXT_GET_COUNT_CNF,
2539                 TAPI_EVENT_NETTEXT_SENTSTATUS_CNF,
2540                 TAPI_EVENT_NETTEXT_GET_PARAM_CNF,
2541                 TAPI_EVENT_NETTEXT_DELETE_STATUS_CNF,
2542                 TAPI_EVENT_NETTEXT_SAVE_STATUS_CNF,
2543                 TAPI_EVENT_NETTEXT_SET_REQUEST_CNF,
2544                 TAPI_EVENT_NETTEXT_GET_CB_CONFIG_CNF,
2545                 TAPI_EVENT_NETTEXT_GET_SMSBEARER_CNF,
2546                 TAPI_EVENT_NETTEXT_DELIVERY_REPORT_CNF,
2547                 TAPI_EVENT_NETTEXT_INCOM_IND,
2548                 TAPI_EVENT_NETTEXT_CB_INCOM_IND,
2549                 TAPI_EVENT_NETTEXT_MEMORY_STATUS_IND,
2550                 TAPI_EVENT_NETTEXT_DEVICE_READY_IND,
2551                 TAPI_EVENT_NETTEXT_PARAM_COUNT_IND,
2552                 TAPI_EVENT_NETTEXT_SENTSTATUS_EX_CNF,
2553                 TAPI_EVENT_NETTEXT_INCOM_EX_IND,
2554                 TAPI_EVENT_NETTEXT_CB_INCOM_EX_IND,
2555                 TAPI_EVENT_NETTEXT_GET_SCA_CNF,
2556         };
2557
2558         iNumOfSMSEvt = sizeof(SMSEvtList)/sizeof(int);
2559         //TAPI_CALLOC(SMS_subscription_id, iNumOfSMSEvt, unsigned int)
2560         //#define TAPI_CALLOC(ptr, no_elements, type)   s
2561         SMS_subscription_id = (unsigned int *) calloc (iNumOfSMSEvt , sizeof (unsigned int));
2562         if(SMS_subscription_id == NULL)
2563         {
2564                 TEST_DEBUG("calloc error -NULL, errno is [%d]", errno);
2565         }
2566
2567
2568         if(tel_init() == TAPI_API_SUCCESS)
2569         {
2570                 for( i=0 ; i< iNumOfSMSEvt; i++ )
2571                 {
2572                         api_err = tel_register_event(SMSEvtList[i], &SMS_subscription_id[i],(TelAppCallback)&SMS_async_event_callback,NULL);
2573
2574                         if(api_err != TAPI_API_SUCCESS)
2575                         {
2576                                 TEST_DEBUG("isn't subscribed. event id is %d, api_err is %d\n", SMSEvtList[i],api_err);
2577                                 ret_val = FALSE;
2578                                 break;
2579                         }
2580                 }
2581         }
2582         else
2583         {
2584                 TEST_DEBUG("TelTapiInit() failed");
2585         }
2586         return ret_val;
2587 }
2588
2589 void sms_select_loop_cdma(void)
2590 {
2591         int ret;
2592         fd_set readfds;
2593         printf("Select Loop!\nPress enter key\n");
2594         fflush(stdout);
2595
2596         while (1)
2597         {
2598                 FD_ZERO(&readfds);
2599                 FD_SET(0, &readfds);
2600
2601                 ret = select(0 + 1, &readfds, NULL, NULL, NULL);
2602                 if (ret)
2603                 {
2604                         if (FD_ISSET(0, &readfds))
2605                         {
2606                                 if( sms_read_key_input_cdma() < 0)
2607                                 {
2608                                         return;
2609                                 }
2610                         }
2611                 }
2612         }
2613 }
2614
2615 void sms_select_loop_wcdma(void)
2616 {
2617         int ret;
2618         fd_set readfds;
2619         printf("Select Loop!\n");
2620
2621         while (1)
2622         {
2623                 FD_ZERO(&readfds);
2624                 FD_SET(0, &readfds);
2625
2626                 ret = select(0 + 1, &readfds, NULL, NULL, NULL);
2627                 if (ret)
2628                 {
2629                         if (FD_ISSET(0, &readfds))
2630                         {
2631                                 if( sms_read_key_input() <0 )
2632                                 {
2633                                         return;
2634                                 }
2635                         }
2636                 }
2637         }
2638 }
2639
2640
2641
2642 void sms_select_loop()
2643 {
2644         int iNum;
2645         char buf[255];
2646
2647         while (1) {
2648                 printf("*************************************\n");
2649                 printf("1. WCDMA\n");
2650                 printf("2. CDMA\n");
2651                 printf("0. Exit\n");
2652                 printf("*************************************\n");
2653                 printf("Select Number by Network Type\n>> ");
2654
2655                 fflush(stdout);
2656                 fflush(stdin);
2657
2658                 memset(buf, 0, 255);
2659                 fgets(buf, 255, stdin);
2660                 iNum = atoi(buf);
2661
2662                 if (iNum == 1) {
2663                         sms_select_loop_wcdma();
2664                 }
2665                 else if (iNum == 2) {
2666                         sms_select_loop_cdma();
2667                 }
2668                 else if (iNum == 0) {
2669                         printf("SMS Program is terminated.\n");
2670                         return;
2671                 }
2672                 else {
2673                         printf("Input wrong number\n");
2674                 }
2675         }
2676
2677         return;
2678 }
2679
2680 void tapi_sms_thread()
2681 {
2682         TEST_DEBUG("start tapi_nettext_thread");
2683         //select_loop();
2684         TEST_DEBUG ("thread exited");
2685         pthread_exit(NULL);
2686 }
2687
2688 void sms_test_main(int argc, char *argv[])
2689 {
2690
2691         int ret = 0, subscription_id = 0;
2692         pthread_t nettext_thread_id;
2693         TapiResult_t api_err = TAPI_API_SUCCESS;
2694
2695         TEST_DEBUG("\n ===== NETTEXT  ver RAMU =====");
2696
2697         ret = pthread_create(&nettext_thread_id, NULL, (void *)&tapi_sms_thread, NULL);
2698
2699         if(ret != 0)
2700         {
2701                 TEST_DEBUG("Thread for TAPI Events Failed");
2702         }
2703
2704         TEST_DEBUG("Before pthread join");
2705
2706         TEST_DEBUG("after TelTapiRegisterClass sub id is %d api_err is %d",subscription_id,api_err);
2707
2708         pthread_join(nettext_thread_id, NULL);
2709
2710         return;
2711 }
2712 //eof
2713