update for beta universally
[framework/telephony/libslp-tapi.git] / src / test_apps / tapi_sim_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 /* standard header files*/
23 #include <stdlib.h>
24 #include <signal.h>
25 #include <stdio.h>
26 #include <errno.h>
27 #include <fcntl.h>
28 #include <string.h>
29 #include <sys/stat.h>
30 #include <unistd.h>
31 #include <pthread.h>
32 #include <linux/stat.h>
33 #include <assert.h>
34
35 /*Dbus header files*/
36 #include <glib.h>
37
38 #include "ITapiSim.h"
39 #include "TelErr.h"
40 #include "TapiCommon.h"
41 #include "TelUtility.h"
42 #include "TapiEvent.h"
43
44 #define SIM_APPLICATION_ID  10
45 #define _TAPI_DEBUG_ON_SCREEN_
46 #define TEST_DEBUG(frmt, args...) \
47 {do { fprintf(stderr, "[SIM Test][%s:%04d] "frmt "\n", __func__,__LINE__, ##args); } while (FALSE); }
48
49 #ifndef false
50 #define false 0
51 #endif
52 #ifndef true
53 #define true  !0
54 #endif
55 #ifndef bool
56 #define bool  char
57 #endif
58
59 //extern int EvtDeliveryHandle ;
60 int request_id;
61 int iNumOfSIMEvt = 0;
62 int error_code;
63 static unsigned int* SIM_subscription_id;
64
65 void sim_async_event_callback(TelTapiEvent_t* sim_event);
66
67 // same as tapievent
68 typedef struct {
69         int group;
70         int type;
71         int ID;
72         int status;
73         void *dst;
74 } data_t;
75
76 int strlen2(register const char * s) {
77         int count = 0;
78         while (*s++)
79                 count++;
80         return count;
81 }
82
83 int _fgets(register char * digit, int n) {
84
85         if (!fgets(digit, n, stdin)) {
86                 return -1;
87         }
88         if (*(digit + (n = strlen2(digit) - 1)) ^ '\n') {
89                 n = 0;
90                 while (getchar() ^ '\n')
91                         n--;
92                 if (n)
93                         return 1;
94
95                 return 0;
96         } else
97                 *(digit + n) = 0;
98         return 0;
99 }
100
101 TelSimPbFileType_t __InputStorageType() {
102         TelSimPbFileType_t storage_type = 0;
103
104         int iStorageType = 0;
105         char dummy = 0;
106
107         TEST_DEBUG(" storage types are below : ");
108         TEST_DEBUG(" 2 - Emergency numbers ");
109         TEST_DEBUG(" 3 - Fixed dialing numbers ");
110         TEST_DEBUG(" 4-  Last dialled numbers ");
111         TEST_DEBUG(" 8 - Own numbers ");
112         TEST_DEBUG(" 10 - 2G SIM numbers ");
113         TEST_DEBUG(" 11 - Service dialing numbers ");
114         TEST_DEBUG(" 12 - 3G SIM numbers ");
115         TEST_DEBUG(" 15 - Additional string numbers ");
116         TEST_DEBUG(" 16 - Grouping text string ");
117
118         TEST_DEBUG("Please input storage type: ");
119         scanf("%d%c", &iStorageType, &dummy);
120
121         switch (iStorageType) {
122         case 2: {
123                 storage_type = TAPI_SIM_PB_EN;
124         }
125                 break;
126
127         case 3: {
128                 storage_type = TAPI_SIM_PB_FDN;
129         }
130                 break;
131
132         case 4: {
133                 storage_type = TAPI_SIM_PB_LDN;
134         }
135                 break;
136
137         case 8: {
138                 storage_type = TAPI_SIM_PB_MSISDN;
139         }
140                 break;
141
142         case 10: {
143                 storage_type = TAPI_SIM_PB_ADN;
144         }
145                 break;
146
147         case 11: {
148                 storage_type = TAPI_SIM_PB_SDN;
149         }
150                 break;
151
152         case 12: {
153                 storage_type = TAPI_SIM_PB_3GSIM;
154         }
155                 break;
156
157         case 15: {
158                 storage_type = TAPI_SIM_PB_AAS;
159         }
160                 break;
161
162         case 16: {
163                 storage_type = TAPI_SIM_PB_GAS;
164         }
165                 break;
166
167         default: {
168                 storage_type = TAPI_SIM_PB_UNKNOWNN;
169         }
170                 break;
171         }
172         return storage_type;
173
174 }
175
176 void __PrintStorageType(TelSimPbFileType_t tSimPbFileType) {
177         switch (tSimPbFileType) {
178         case TAPI_SIM_PB_EN: {
179                 TEST_DEBUG("TAPI_SIM_PB_EN [0x%x]", tSimPbFileType);
180         }
181                 break;
182
183         case TAPI_SIM_PB_FDN: {
184                 TEST_DEBUG("TAPI_SIM_PB_FDN [0x%x]", tSimPbFileType);
185         }
186                 break;
187
188         case TAPI_SIM_PB_LDN: {
189                 TEST_DEBUG("TAPI_SIM_PB_LDN [0x%x]", tSimPbFileType);
190         }
191                 break;
192
193         case TAPI_SIM_PB_MSISDN: {
194                 TEST_DEBUG("TAPI_SIM_PB_MSISDN [0x%x]", tSimPbFileType);
195         }
196                 break;
197
198         case TAPI_SIM_PB_ADN: {
199                 TEST_DEBUG("TAPI_SIM_PB_ADN [0x%x]", tSimPbFileType);
200         }
201                 break;
202
203         case TAPI_SIM_PB_SDN: {
204                 TEST_DEBUG("TAPI_SIM_PB_SDN [0x%x]", tSimPbFileType);
205         }
206                 break;
207
208         case TAPI_SIM_PB_3GSIM: {
209                 TEST_DEBUG("TAPI_SIM_PB_3GSIM [0x%x]", tSimPbFileType);
210         }
211                 break;
212
213         case TAPI_SIM_PB_AAS: {
214                 TEST_DEBUG("TAPI_SIM_PB_AAS [0x%x]", tSimPbFileType);
215         }
216                 break;
217
218         case TAPI_SIM_PB_GAS: {
219                 TEST_DEBUG("TAPI_SIM_PB_GAS [0x%x]", tSimPbFileType);
220         }
221                 break;
222
223         default: {
224                 TEST_DEBUG("Undefined Storage Type returnted [0x%x]", tSimPbFileType);
225         }
226                 break;
227         }
228 }
229
230 void __PrintPbFiledType(TelSimPb3GFileType_t tSimPb3GFileType) {
231         switch (tSimPb3GFileType) {
232         case TAPI_PB_3G_NAME: {
233                 TEST_DEBUG("PB Type: TAPI_PB_3G_NAME [0x%x]", tSimPb3GFileType);
234                 break;
235         }
236
237         case TAPI_PB_3G_NUMBER: {
238                 TEST_DEBUG("PB Type: TAPI_PB_3G_NUMBER [0x%x]", tSimPb3GFileType);
239                 break;
240         }
241         case TAPI_PB_3G_ANR: {
242                 TEST_DEBUG("PB Type: TAPI_PB_3G_ANR [0x%x]", tSimPb3GFileType);
243                 break;
244         }
245         case TAPI_PB_3G_EMAIL: {
246                 TEST_DEBUG("PB Type: TAPI_PB_3G_EMAIL [0x%x]", tSimPb3GFileType);
247                 break;
248         }
249         case TAPI_PB_3G_SNE: {
250                 TEST_DEBUG("PB Type: TAPI_PB_3G_SNE [0x%x]", tSimPb3GFileType);
251                 break;
252         }
253         case TAPI_PB_3G_GRP: {
254                 TEST_DEBUG("PB Type: TAPI_PB_3G_GRP [0x%x]", tSimPb3GFileType);
255                 break;
256         }
257         case TAPI_PB_3G_PBC: {
258                 TEST_DEBUG("PB Type: TAPI_PB_3G_PBC [0x%x]", tSimPb3GFileType);
259                 break;
260         }
261         case TAPI_PB_3G_ANRA: {
262                 TEST_DEBUG("PB Type: TAPI_PB_3G_ANRA [0x%x]", tSimPb3GFileType);
263                 break;
264         }
265         case TAPI_PB_3G_ANRB: {
266                 TEST_DEBUG("PB Type: TAPI_PB_3G_ANRB [0x%x]", tSimPb3GFileType);
267                 break;
268         }
269         default: {
270                 TEST_DEBUG("PB Type: Undefined PB 3G File Type [0x%x]", tSimPb3GFileType);
271         }
272         }
273 }
274
275 #if 0
276 void __PrintLockType(TelSimLockType_t tSimLockType)
277 {
278         switch(tSimLockType)
279         {
280                 case TAPI_SIM_LOCK_READY:
281                 TEST_DEBUG("Lock Type: TAPI_SIM_LOCK_READY [0x%x]", tSimLockType);
282                 break;
283                 case TAPI_SIM_LOCK_PS:
284                 TEST_DEBUG("Lock Type: TAPI_SIM_LOCK_PS (Phone-Sim Lock) [0x%x]", tSimLockType);
285                 break;
286                 case TAPI_SIM_LOCK_PF:
287                 TEST_DEBUG("Lock Type: TAPI_SIM_LOCK_PF (Phone first SIM) [0x%x]", tSimLockType);
288                 break;
289                 case TAPI_SIM_LOCK_SC:
290                 TEST_DEBUG("Lock Type: TAPI_SIM_LOCK_SC (PIN, PIN2, PUK, PUK2 Lock)  [0x%x]", tSimLockType);
291                 break;
292                 case TAPI_SIM_LOCK_FD:
293                 TEST_DEBUG("Lock Type: TAPI_SIM_LOCK_FD (FDN) [0x%x]", tSimLockType);
294                 break;
295                 case TAPI_SIM_LOCK_PN:
296                 TEST_DEBUG("Lock Type: TAPI_SIM_LOCK_PN (Network Personalization) [0x%x]", tSimLockType);
297                 break;
298                 case TAPI_SIM_LOCK_PU:
299                 TEST_DEBUG("Lock Type: TAPI_SIM_LOCK_PU (Network Subset Personalization) [0x%x]", tSimLockType);
300                 break;
301                 case TAPI_SIM_LOCK_PP:
302                 TEST_DEBUG("Lock Type: TAPI_SIM_LOCK_PP (Service Provider Personalization) [0x%x]", tSimLockType);
303                 break;
304                 case TAPI_SIM_LOCK_PC:
305                 TEST_DEBUG("Lock Type: TAPI_SIM_LOCK_PC (Corporate Personalization) [0x%x]", tSimLockType);
306                 break;
307                 case TAPI_SIM_LOCK_SC2:
308                 TEST_DEBUG("Lock Type: TAPI_SIM_LOCK_SC2 (PIN2 Lock) [0x%x]", tSimLockType);
309                 break;
310                 case TAPI_SIM_LOCK_SCPUK2:
311                 TEST_DEBUG("Lock Type: TAPI_SIM_LOCK_SCPUK2 (PIN2 Unblocking Key) [0x%x]", tSimLockType);
312                 break;
313                 case TAPI_SIM_LOCK_ACL:
314                 TEST_DEBUG("Lock Type: TAPI_SIM_LOCK_ACL (ACL Lock) [0x%x]", tSimLockType);
315                 break;
316                 case TAPI_SIM_NO_SIM:
317                 TEST_DEBUG("Lock Type: TAPI_SIM_NO_SIM [0x%x]", tSimLockType);
318                 break;
319                 case TAPI_SIM_UNAVAIL:
320                 TEST_DEBUG("Lock Type: TAPI_SIM_UNAVAIL [0x%x]", tSimLockType);
321                 break;
322                 case TAPI_SIM_INIT_COMPLETE:
323                 TEST_DEBUG("Lock Type: TAPI_SIM_INIT_COMPLETE [0x%x]", tSimLockType);
324                 break;
325                 case TAPI_SIM_PB_INIT_COMPLETE:
326                 TEST_DEBUG("Lock Type: TAPI_SIM_PB_INIT_COMPLETE [0x%x]", tSimLockType);
327                 break;
328                 default:
329                 TEST_DEBUG("Lock Type: Undefined Lcok Type [0x%x]", tSimLockType);
330         }
331 }
332
333 void __PrintLockKey(TelSimLockKey_t tSimLockKey)
334 {
335         switch(tSimLockKey)
336         {
337                 case TAPI_SIM_LOCK_KEY_NOT_NEED:
338                 TEST_DEBUG(" Lock Key:  TAPI_SIM_LOCK_KEY_NOT_NEED [0x%x]", tSimLockKey);
339                 break;
340                 case TAPI_SIM_LOCK_KEY_PIN:
341                 TEST_DEBUG(" Lock Key:  TAPI_SIM_LOCK_KEY_PIN [0x%x]", tSimLockKey);
342                 break;
343                 case TAPI_SIM_LOCK_KEY_PUK:
344                 TEST_DEBUG(" Lock Key:  TAPI_SIM_LOCK_KEY_PUK [0x%x]", tSimLockKey);
345                 break;
346                 case TAPI_SIM_LOCK_KEY_PIN2:
347                 TEST_DEBUG(" Lock Key:  TAPI_SIM_LOCK_KEY_PIN2 [0x%x]", tSimLockKey);
348                 break;
349                 case TAPI_SIM_LOCK_KEY_PUK2:
350                 TEST_DEBUG(" Lock Key:  TAPI_SIM_LOCK_KEY_PUK2 [0x%x]", tSimLockKey);
351                 break;
352                 case TAPI_SIM_LOCK_PERM_BLOCKED:
353                 TEST_DEBUG(" Lock Key:  TAPI_SIM_LOCK_PERM_BLOCKED [0x%x]", tSimLockKey);
354                 break;
355                 case TAPI_SIM_LOCK_DISABLE:
356                 TEST_DEBUG(" Lock Key:  TAPI_SIM_LOCK_DISABLE [0x%x]", tSimLockKey);
357                 break;
358                 case TAPI_SIM_LOCK_KEY_SIMLOCK:
359                 TEST_DEBUG(" Lock Key:  TAPI_SIM_LOCK_KEY_SIMLOCK [0x%x]", tSimLockKey);
360                 break;
361                 default:
362                 TEST_DEBUG(" Lock Key:  Undefined Lock key [0x%x]", tSimLockKey);
363         }
364 }
365 #endif
366
367 void __PrintCardStatus(char* str, TelSimCardStatus_t tSimCardStatus) {
368         switch (tSimCardStatus) {
369         case TAPI_SIM_STATUS_CARD_ERROR:
370                 TEST_DEBUG("[%s]TAPI_SIM_STATUS_CARD_ERROR [0x%x]", str, tSimCardStatus)
371                 ;
372                 break;
373         case TAPI_SIM_STATUS_CARD_NOT_PRESENT:
374                 TEST_DEBUG("[%s]TAPI_SIM_STATUS_CARD_NOT_PRESENT [0x%x]", str, tSimCardStatus)
375                 ;
376                 break;
377         case TAPI_SIM_STATUS_SIM_INITIALIZING:
378                 TEST_DEBUG("[%s]TAPI_SIM_STATUS_SIM_INITIALIZING [0x%x]", str, tSimCardStatus)
379                 ;
380                 break;
381         case TAPI_SIM_STATUS_SIM_INIT_COMPLETED:
382                 TEST_DEBUG("[%s]TAPI_SIM_STATUS_SIM_INIT_COMPLETED [0x%x]", str, tSimCardStatus)
383                 ;
384                 break;
385         case TAPI_SIM_STATUS_SIM_PIN_REQUIRED:
386                 TEST_DEBUG("[%s]TAPI_SIM_STATUS_SIM_PIN_REQUIRED [0x%x]", str, tSimCardStatus)
387                 ;
388                 break;
389         case TAPI_SIM_STATUS_SIM_PUK_REQUIRED:
390                 TEST_DEBUG("[%s]TAPI_SIM_STATUS_SIM_PUK_REQUIRED [0x%x]", str, tSimCardStatus)
391                 ;
392                 break;
393         case TAPI_SIM_STATUS_CARD_BLOCKED:
394                 TEST_DEBUG("[%s]TAPI_SIM_STATUS_CARD_BLOCKED [0x%x]", str, tSimCardStatus)
395                 ;
396                 break;
397         case TAPI_SIM_STATUS_SIM_NCK_REQUIRED:
398                 TEST_DEBUG("[%s]TAPI_SIM_STATUS_SIM_NCK_REQUIRED [0x%x]", str, tSimCardStatus)
399                 ;
400                 break;
401         case TAPI_SIM_STATUS_SIM_NSCK_REQUIRED:
402                 TEST_DEBUG("[%s]TAPI_SIM_STATUS_SIM_NSCK_REQUIRED [0x%x]", str, tSimCardStatus)
403                 ;
404                 break;
405         case TAPI_SIM_STATUS_SIM_SPCK_REQUIRED:
406                 TEST_DEBUG("[%s]TAPI_SIM_STATUS_SIM_SPCK_REQUIRED [0x%x]", str, tSimCardStatus)
407                 ;
408                 break;
409         case TAPI_SIM_STATUS_SIM_CCK_REQUIRED:
410                 TEST_DEBUG("[%s]TAPI_SIM_STATUS_SIM_CCK_REQUIRED [0x%x]", str, tSimCardStatus)
411                 ;
412                 break;
413         case TAPI_SIM_STATUS_CARD_REMOVED:
414                 TEST_DEBUG("[%s]TAPI_SIM_STATUS_CARD_REMOVED [0x%x]", str, tSimCardStatus)
415                 ;
416                 break;
417         case TAPI_SIM_STATUS_SIM_LOCK_REQUIRED:
418                 TEST_DEBUG("[%s]TAPI_SIM_STATUS_SIM_LOCK_REQUIRED [0x%x]", str, tSimCardStatus)
419                 ;
420                 break;
421         default:
422                 TEST_DEBUG("[%s]Undefined Card Status [0x%x]", str, tSimCardStatus)
423                 ;
424         }
425 }
426
427 void __PrintPinStatus(char* str, TelSimPinStatus_t tSimPinStatus) {
428         switch (tSimPinStatus) {
429         case TAPI_SIM_PIN_STATUS_DISABLED:
430                 TEST_DEBUG("%sTAPI_SIM_PIN_STATUS_DISABLED [0x%x]", str, tSimPinStatus)
431                 ;
432                 break;
433         case TAPI_SIM_PIN_STATUS_ENABLED:
434                 TEST_DEBUG("%sTAPI_SIM_PIN_STATUS_ENABLED [0x%x]", str, tSimPinStatus)
435                 ;
436                 break;
437         case TAPI_SIM_PIN_STATUS_BLOCKED:
438                 TEST_DEBUG("%sTAPI_SIM_PIN_STATUS_BLOCKED [0x%x]", str, tSimPinStatus)
439                 ;
440                 break;
441         case TAPI_SIM_PIN_STATUS_PUK_BLOCKED:
442                 TEST_DEBUG("%sTAPI_SIM_PIN_STATUS_PUK_BLOCKED [0x%x]", str, tSimPinStatus)
443                 ;
444                 break;
445         case TAPI_SIM_PIN_STATUS_UNKNOWN:
446                 TEST_DEBUG("%sTAPI_SIM_PIN_STATUS_UNKNOWN [0x%x]", str, tSimPinStatus)
447                 ;
448                 break;
449         default:
450                 TEST_DEBUG("%sUndefined Pin Status [0x%x]", str, tSimPinStatus)
451                 ;
452                 break;
453
454         }
455 }
456
457 void __PrintCardType(char* str, TelSimCardType_t tSimCardType) {
458         switch (tSimCardType) {
459         case TAPI_SIM_CARD_TYPE_UNKNOWN:
460                 TEST_DEBUG("%sTAPI_SIM_CARD_TYPE_UNKNOWN [0x%x]", str, tSimCardType)
461                 ;
462                 break;
463         case TAPI_SIM_CARD_TYPE_GSM:
464                 TEST_DEBUG("%sTAPI_SIM_CARD_TYPE_GSM [0x%x]", str, tSimCardType)
465                 ;
466                 break;
467         case TAPI_SIM_CARD_TYPE_USIM:
468                 TEST_DEBUG("%sTAPI_SIM_CARD_TYPE_USIM [0x%x]", str, tSimCardType)
469                 ;
470                 break;
471         default:
472                 TEST_DEBUG("%sUndefined Card Type [0x%x]", str, tSimCardType)
473                 ;
474         }
475 }
476
477 void __PrintECCSvcInfo(TelSimEccEmergencyServiceInfo_t tSimECCSvcInfo) {
478         switch (tSimECCSvcInfo) {
479         case TAPI_SIM_ECC_ESC_POLICE:
480                 TEST_DEBUG("TAPI_SIM_ECC_ESC_POLICE [0x%x]", tSimECCSvcInfo)
481                 ;
482                 break;
483         case TAPI_SIM_ECC_ESC_AMBULANCE:
484                 TEST_DEBUG("TAPI_SIM_ECC_ESC_AMBULANCE [0x%x]", tSimECCSvcInfo)
485                 ;
486                 break;
487         case TAPI_SIM_ECC_ESC_FIREBRIGADE:
488                 TEST_DEBUG("TAPI_SIM_ECC_ESC_FIREBRIGADE [0x%x]", tSimECCSvcInfo)
489                 ;
490                 break;
491         case TAPI_SIM_ECC_ESC_MARAINEGUARD:
492                 TEST_DEBUG("TAPI_SIM_ECC_ESC_MARAINEGUARD [0x%x]", tSimECCSvcInfo)
493                 ;
494                 break;
495         case TAPI_SIM_ECC_ESC_MOUTAINRESCUE:
496                 TEST_DEBUG("TAPI_SIM_ECC_ESC_MOUTAINRESCUE [0x%x]", tSimECCSvcInfo)
497                 ;
498                 break;
499         case TAPI_SIM_ECC_ESC_SPARE:
500                 TEST_DEBUG("TAPI_SIM_ECC_ESC_SPARE [0x%x]", tSimECCSvcInfo)
501                 ;
502                 break;
503         default:
504                 TEST_DEBUG("Undefined ECC Sercie Info [0x%x]", tSimECCSvcInfo)
505                 ;
506         }
507 }
508
509 void __PrintUSTData(unsigned long UstLen, unsigned short UstData[]) {
510         int i = 0;
511         fprintf(stderr, "UST Data: ");
512         for (i = 0; i < UstLen; i++) {
513                 fprintf(stderr, "0x%x ", UstData[i]);
514         }
515         fprintf(stderr, "\n");
516 }
517
518 #if 0
519 void __PrintUSimSvcTable(TelUSimServiceTable_t tUSimSVCTable)
520 {
521         TEST_DEBUG("-------- UST Table -------- (1: On, 0:Off)");
522         TEST_DEBUG("Local Phonebook [%d] ", tUSimSVCTable.bLocalPhoneBook);
523         TEST_DEBUG("FDN [%d] ", tUSimSVCTable.bFdn);
524         TEST_DEBUG("EXT2 [%d] ", tUSimSVCTable.bExtension2);
525         TEST_DEBUG("SDN [%d] ", tUSimSVCTable.bSdn);
526         TEST_DEBUG("EXT3 [%d] ", tUSimSVCTable.bExtension3);
527         TEST_DEBUG("BDN [%d] ", tUSimSVCTable.bBdn);
528         TEST_DEBUG("EXT4 [%d] ", tUSimSVCTable.bExtension4);
529         TEST_DEBUG("OUT Going Call Info. [%d] ", tUSimSVCTable.bOCIOCT);
530         TEST_DEBUG("Call control [%d] ", tUSimSVCTable.bUsimCallControl);
531         TEST_DEBUG("Added more Table as you need");
532         TEST_DEBUG("---------------------------");
533 }
534
535 void __PrintSimSvcTable(TelSimServiceTable_t tSimSVCTable)
536 {
537         TEST_DEBUG("-------- UST Table --------");
538         TEST_DEBUG("FDN [%d] ", tSimSVCTable.bFdn);
539         TEST_DEBUG("EXT2 [%d] ", tSimSVCTable.bExtension2);
540         TEST_DEBUG("SDN [%d] ", tSimSVCTable.bSdn);
541         TEST_DEBUG("EXT3 [%d] ", tSimSVCTable.bExtension3);
542         TEST_DEBUG("BDN [%d] ", tSimSVCTable.bBdn);
543         TEST_DEBUG("EXT4 [%d] ", tSimSVCTable.bExtension4);
544         TEST_DEBUG("PIN1 Disable func. [%d] ", tSimSVCTable.bPIN1DisableFunction );
545         TEST_DEBUG("Adn [%d] ", tSimSVCTable.bAdn);
546         TEST_DEBUG("Added more Table as you need");
547         TEST_DEBUG("---------------------------");
548 }
549 #endif
550
551 void __PrintSSTData(unsigned long SstLen, unsigned short SstData[]) {
552         int i = 0;
553         TEST_DEBUG("SST Data: ");
554         for (i = 0; i < SstLen; i++) {
555                 fprintf(stderr, "0x%x ", SstData[i]);
556         }
557 }
558
559 void __PrintLangInfo(char *str, TelSimLanguagePreferenceCode_t tSimLP) {
560         switch (tSimLP) {
561         case TAPI_SIM_LP_GERMAN:
562                 TEST_DEBUG("%s TAPI_SIM_LP_GERMAN", str)
563                 ;
564                 break;
565
566         case TAPI_SIM_LP_ENGLISH:
567                 TEST_DEBUG("%s TAPI_SIM_LP_ENGLISH", str)
568                 ;
569                 break;
570
571         case TAPI_SIM_LP_ITALIAN:
572                 TEST_DEBUG("%s TAPI_SIM_LP_ITALIAN", str)
573                 ;
574                 break;
575
576         case TAPI_SIM_LP_FRENCH:
577                 TEST_DEBUG("%s TAPI_SIM_LP_FRENCH", str)
578                 ;
579                 break;
580
581         case TAPI_SIM_LP_SPANISH:
582                 TEST_DEBUG("%s TAPI_SIM_LP_SPANISH", str)
583                 ;
584                 break;
585
586         case TAPI_SIM_LP_DUTCH:
587                 TEST_DEBUG("%s TAPI_SIM_LP_DUTCH", str)
588                 ;
589                 break;
590
591         case TAPI_SIM_LP_SWEDISH:
592                 TEST_DEBUG("%s TAPI_SIM_LP_SWEDISH", str)
593                 ;
594                 break;
595
596         case TAPI_SIM_LP_DANISH:
597                 TEST_DEBUG("%s TAPI_SIM_LP_DANISH", str)
598                 ;
599                 break;
600
601         case TAPI_SIM_LP_PORTUGUESE:
602                 TEST_DEBUG("%s TAPI_SIM_LP_PORTUGUESE", str)
603                 ;
604                 break;
605
606         case TAPI_SIM_LP_FINNISH:
607                 TEST_DEBUG("%s TAPI_SIM_LP_FINNISH", str)
608                 ;
609                 break;
610
611         case TAPI_SIM_LP_NORWEGIAN:
612                 TEST_DEBUG("%s TAPI_SIM_LP_NORWEGIAN", str)
613                 ;
614                 break;
615
616         case TAPI_SIM_LP_GREEK:
617                 TEST_DEBUG("%s TAPI_SIM_LP_GREEK", str)
618                 ;
619                 break;
620
621         case TAPI_SIM_LP_TURKISH:
622                 TEST_DEBUG("%s TAPI_SIM_LP_TURKISH", str)
623                 ;
624                 break;
625
626         case TAPI_SIM_LP_HUNGARIAN:
627                 TEST_DEBUG("%s TAPI_SIM_LP_HUNGARIAN", str)
628                 ;
629                 break;
630
631         case TAPI_SIM_LP_POLISH:
632                 TEST_DEBUG("%s TAPI_SIM_LP_POLISH", str)
633                 ;
634                 break;
635
636         case TAPI_SIM_LP_KOREAN:
637                 TEST_DEBUG("%s TAPI_SIM_LP_KOREAN", str)
638                 ;
639                 break;
640
641         case TAPI_SIM_LP_CHINESE:
642                 TEST_DEBUG("%s TAPI_SIM_LP_CHINESE", str)
643                 ;
644                 break;
645
646         case TAPI_SIM_LP_RUSSIAN:
647                 TEST_DEBUG("%s TAPI_SIM_LP_RUSSIAN", str)
648                 ;
649                 break;
650
651         case TAPI_SIM_LP_JAPANESE:
652                 TEST_DEBUG("%s TAPI_SIM_LP_JAPANESE", str)
653                 ;
654                 break;
655
656         case TAPI_SIM_LP_LANG_UNSPECIFIED:
657         default:
658                 TEST_DEBUG("%s Undefined Language Preference Code", str)
659                 ;
660                 break;
661         }
662 }
663
664 void __PrintPBResult(char *str, TelSimPbAccessResult_t tPBResult) {
665         switch (tPBResult) {
666         case TAPI_SIM_PB_SUCCESS:
667                 TEST_DEBUG("%s TAPI_SIM_PB_SUCCESS", str)
668                 ;
669                 break;
670
671         case TAPI_SIM_PB_FAIL:
672                 TEST_DEBUG("%s TAPI_SIM_PB_FAIL", str)
673                 ;
674                 break;
675
676         case TAPI_SIM_PB_INVALID_INDEX:
677                 TEST_DEBUG("%s TAPI_SIM_PB_INVALID_INDEX", str)
678                 ;
679                 break;
680
681         case TAPI_SIM_PB_INVALID_NUMBER_LENGTH:
682                 TEST_DEBUG("%s TAPI_SIM_PB_INVALID_NUMBER_LENGTH", str)
683                 ;
684                 break;
685
686         case TAPI_SIM_PB_INVALID_NAME_LENGTH:
687                 TEST_DEBUG("%s TAPI_SIM_PB_INVALID_NAME_LENGTH", str)
688                 ;
689                 break;
690
691         case TAPI_SIM_PB_ACCESS_CONDITION_NOT_SATISFIED:
692                 TEST_DEBUG("%s TAPI_SIM_PB_ACCESS_CONDITION_NOT_SATISFIED", str)
693                 ;
694                 break;
695
696         default:
697                 TEST_DEBUG("%s Undefined PB Access Result", str)
698                 ;
699                 break;
700         }
701 }
702
703 void __PrintPBStorageList(char *str, TS_UINT16 StorageList) {
704         if (StorageList & (0x01 << TAPI_SIM_PB_FDN)) {
705                 TEST_DEBUG("%s PB_FDN is in the StorageList", str);
706         }
707
708         if (StorageList & (0x01 << TAPI_SIM_PB_LDN)) {
709                 TEST_DEBUG("%s PB_LDN is in the StorageList", str);
710         }
711
712         if (StorageList & (0x01 << TAPI_SIM_PB_MSISDN)) {
713                 TEST_DEBUG("%s PB_MSISDN is in the StorageList", str);
714         }
715
716         if (StorageList & (0x01 << TAPI_SIM_PB_ADN)) {
717                 TEST_DEBUG("%s PB_ADN is in the StorageList", str);
718         }
719
720         if (StorageList & (0x01 << TAPI_SIM_PB_SDN)) {
721                 TEST_DEBUG("%s PB_SDN is in the StorageList", str);
722         }
723
724         if (StorageList & (0x01 << TAPI_SIM_PB_EN)) {
725                 TEST_DEBUG("%s PB_EN is in the StorageList", str);
726         }
727
728         if (StorageList & (0x01 << TAPI_SIM_PB_3GSIM)) {
729                 TEST_DEBUG("%s PB_3GSIM is in the StorageList", str);
730         }
731
732         if (StorageList & (0x01 << TAPI_SIM_PB_AAS)) {
733                 TEST_DEBUG("%s PB_AAS is in the StorageList", str);
734         }
735
736         if (StorageList & (0x01 << TAPI_SIM_PB_GAS)) {
737                 TEST_DEBUG("%s PB_GAS is in the StorageList", str);
738         }
739 }
740
741 #if 0
742 TelSimReadFileRequestData_t __SelectBinary()
743 {
744         int iSelect = 0;
745         TelSimReadFileRequestData_t ReadFileReqData = { {0,}};
746
747         ReadFileReqData.Offset = 0; /**< offset if read binary */
748
749         ReadFileReqData.FileType = TAPI_SIM_FTYPE_TRANSPARENT;
750         // if record
751         ReadFileReqData.RecordIndex =0; /**< record index if read record */
752         ReadFileReqData.RecordIndexFrom=0;
753         ReadFileReqData.RecordIndexTo=0;
754         ReadFileReqData.RecordMode=TAPI_SIM_RECORD_NONE; /**< record index if read record */
755
756         TEST_DEBUG("---- EF File List ----");
757         TEST_DEBUG("1: ICCID");
758         TEST_DEBUG("2: SPN");
759         TEST_DEBUG("----------------------");
760         TEST_DEBUG("Select EF File: ");
761
762         scanf("%d", &iSelect);
763         if(iSelect == 1)
764         {
765                 ReadFileReqData.FileID.FileName = TAPI_SIM_EFILE_ICCID;
766                 ReadFileReqData.DataLength = 0x0A; /* hard code 10 bytes */;
767         }
768         else if(iSelect == 2)
769         {
770                 ReadFileReqData.FileID.FileName = TAPI_SIM_EFILE_SPN;
771                 ReadFileReqData.DataLength = 17;
772         }
773         else if(iSelect == 2)
774         {
775                 ReadFileReqData.FileID.FileName = TAPI_SIM_EFILE_LP;
776         }
777         else
778         {
779                 TEST_DEBUG("Invalid Selection!");
780         }
781
782         return ReadFileReqData;
783
784 }
785 #endif
786
787 /**
788  * This function  is used for encoding a ASCII text into UNICODE text
789  *
790  * @return              This function returns a TRUE on Success and FALSE on failure
791  * @param[in]           text_len -input text lenght
792  * @param[in]           text_data - input text data
793  * @param[in]   unicode_text_len - unicode converted tex lenght
794  * @param[in]   unicode_text - unicode text
795  * @Interface           Asynchronous.
796  * @remark
797  * @Refer
798  */
799 TS_BOOL __encode_text_unicode(char text_len, char *text_data,
800                 char *unicode_text_len, char *unicode_text) {
801         int j, i;
802         i = j = 0;
803
804         if (text_len == 0) {
805                 TEST_DEBUG("Unicode encoding failed - input text string length is 0!");
806                 return FALSE;
807         }
808         /*UNicode conversion*/
809         /* a  = Ascii is 61 and in Unicode it is 0061 but modem expects 6100 */
810         for (j = 0, i = 0; i < text_len * 2; i++) {
811                 unicode_text[i++] = text_data[j++];
812                 unicode_text[i] = 0x00;
813         }
814         *unicode_text_len = text_len * 2;
815         return TRUE;
816
817 }
818
819 /**
820  * This function  is used for encoding a ASCII text into GSM7 bit text
821  *
822  * @return              This function returns a TRUE on Success and FALSE on failure
823  * @param[in]           text_len - input text lenght
824  * @param[in]           text_data - input text data
825  * @param[in]   out_len_max - gsm7bit converted text lenght
826  * @param[in]   gsm7bit_text - gsm7bit converted tex data
827  * @return              This function returns a TRUE on Success and FALSE on failure
828  */
829 TS_BOOL __encode_gsm_7_bit_chars(char text_len, const char* text_data,
830                 char *out_len_max, char* gsm7bit_text) {
831         int i;
832         int pos;
833         TS_UINT16 shift = 0;
834
835         for (pos = 0, i = 0; i < text_len; pos++, i++) {
836                 /* pack the low bits - for single char */
837                 gsm7bit_text[pos] = text_data[i] >> shift;
838
839                 if (i + 1 < text_len) {
840                         /* pack the high bits using the low bits of the next character */
841                         gsm7bit_text[pos] |= text_data[i + 1] << (7 - shift);
842
843                         shift++;
844
845                         if (shift == 7) {
846                                 shift = 0;
847                                 i++;
848                         }
849                 }
850         }
851         *out_len_max = (text_len * 7) / 8;
852
853         /* done */
854         return pos;
855
856 }
857
858 /**
859  * This function converts unicode to ascii text
860  *
861  * @return              This function returns a 1 on Success and -1 on failure
862  * @param[in]           phone_pb_type
863  * @Interface           Asynchronous.
864  * @remark
865  * @Refer
866  */
867 TS_BOOL __decode_unicode_to_asci_str(char text_len, char *text_data,
868                 char *ascii_text_len, char *ascii_text) {
869         int i, j;
870         i = j = 0;
871         if (text_len == 0 || text_data == NULL || ascii_text == NULL) {
872                 TEST_DEBUG("Unicode Decode Failed as text length is 0");
873                 return FALSE;
874         }
875
876         if (0 != (text_len % 2)) {
877                 TEST_DEBUG(" ##### Unicode decoding failed due to invalid text length [%d]", text_len );
878                 return FALSE;
879         }
880
881         for (i = 0; i < text_len; i++) {
882                 ascii_text[i] = text_data[j];
883                 j = j + 2;
884         }
885         *ascii_text_len = (text_len / 2);
886         ascii_text[i] = '\0';
887         return TRUE;
888 }
889
890 int sim_test_subscribe_tapi_events() {
891         int i = 0;
892         int ret_val = TRUE;
893         TapiResult_t api_err = TAPI_API_SUCCESS;
894
895         int SIMEvtList[] = { TAPI_EVENT_SIM_PB_STORAGE_COUNT_CNF,
896                         TAPI_EVENT_SIM_PB_ENTRY_INFO_CNF,
897                         TAPI_EVENT_SIM_PB_ACCESS_READ_CNF,
898
899                         TAPI_EVENT_SIM_PB_UPDATE_CNF, TAPI_EVENT_SIM_PB_DELETE_CNF,
900                         TAPI_EVENT_SIM_STATUS_IND, TAPI_EVENT_SIM_FDN_STATUS_IND,
901
902                         TAPI_EVENT_SIM_PB_CAPABILITY_INFO_CNF,
903                         TAPI_EVENT_SIM_ISIM_AUTHENTICATION_CNF,
904                         TAPI_EVENT_SIM_SAP_CONNECT_NOTI, TAPI_EVENT_SIM_SAP_CONNECT_CNF,
905                         TAPI_EVENT_SIM_SAP_CONNECT_STATUS_CNF,
906                         TAPI_EVENT_SIM_SAP_TRANSFER_ATR_CNF,
907                         TAPI_EVENT_SIM_SAP_TRANSFER_APDU_CNF,
908                         TAPI_EVENT_SIM_SAP_SET_PROTOCOL_CNF,
909                         TAPI_EVENT_SIM_SAP_SET_SIM_POWER_CNF,
910                         TAPI_EVENT_SIM_SAP_CARD_READER_STATUS_CNF, TAPI_EVENT_SIM_APDU_CNF,
911                         TAPI_EVENT_SIM_ATR_CNF,
912
913                         TAPI_EVENT_SIM_GET_INDICATION_CNF,
914                         TAPI_EVENT_SIM_SET_INDICATION_CNF, TAPI_EVENT_SIM_GET_MAILBOX_CNF,
915                         TAPI_EVENT_SIM_SET_MAILBOX_CNF, TAPI_EVENT_SIM_SET_LANGUAGE_CNF,
916                         TAPI_EVENT_SIM_RSIM_ACCESS_CNF, TAPI_EVENT_SIM_VERIFY_SEC_CNF,
917                         TAPI_EVENT_SIM_VERIFY_PUK_CNF, TAPI_EVENT_SIM_CHANGE_PINS_CNF,
918                         TAPI_EVENT_SIM_DISABLE_SEC_CNF, TAPI_EVENT_SIM_ENABLE_SEC_CNF,
919                         TAPI_EVENT_SIM_DISABLE_FDNMODE_CNF,
920                         TAPI_EVENT_SIM_ENABLE_FDNMODE_CNF, TAPI_EVENT_SIM_PERS_STATUS_CNF,
921                         TAPI_EVENT_SIM_DISABLE_PERS_CNF, TAPI_EVENT_SIM_ENABLE_PERS_CNF };
922
923         iNumOfSIMEvt = sizeof(SIMEvtList) / sizeof(int);
924         TEST_DEBUG("Number of SIM Event List to be registered: %d", iNumOfSIMEvt);
925         //TAPI_CALLOC(SIM_subscription_id, iNumOfSIMEvt, unsigned int)
926         //#define TAPI_CALLOC(ptr, no_elements, type)   s
927         SIM_subscription_id = (unsigned int *) calloc(iNumOfSIMEvt,
928                         sizeof(unsigned int));
929         if (SIM_subscription_id == NULL) {
930                 TEST_DEBUG("calloc error -NULL, errno is [%d]", errno);
931         }
932
933         for (i = 0; i < iNumOfSIMEvt; i++) {
934                 api_err = tel_register_event(SIMEvtList[i], &SIM_subscription_id[i],
935                                 (TelAppCallback) &sim_async_event_callback, NULL);
936
937                 if (api_err != TAPI_API_SUCCESS) {
938                         TEST_DEBUG("isn't subscribed. sub id is [%d], api_err is [%d]\n", SIM_subscription_id[i],api_err);
939                         ret_val = FALSE;
940                         break;
941                 }
942         }
943
944         return ret_val;
945
946 }
947
948 int sim_test_unsubscribe_tapi_events(void) {
949         int i = 0;
950         TapiResult_t api_err = TAPI_API_SUCCESS;
951         int ret_val = TRUE;
952
953         for (i = 0; i < iNumOfSIMEvt; i++) {
954                 api_err = tel_deregister_event(SIM_subscription_id[i]);
955                 if (api_err != TAPI_API_SUCCESS) {
956                         TEST_DEBUG("TelTapiDeRegister isn't unsubscribed. sub id is [%d] api_err is [%d]\n",SIM_subscription_id[i],api_err);
957                         ret_val = FALSE;
958                         break;
959                 }
960
961         }
962
963         return ret_val;
964 }
965
966 void sim_async_event_callback(TelTapiEvent_t* sim_event)
967 {
968         //int i;
969         //static unsigned int fileSize = 0;
970
971         TEST_DEBUG("Func Entrance");
972         TEST_DEBUG("Request ID : [0x%x]\n", sim_event->RequestId);
973
974         if (sim_event->pData == NULL) {
975                 TEST_DEBUG("No Event Data!!");
976                 //              return;
977         }
978
979         TEST_DEBUG("*************** Callback data **********************");
980         TEST_DEBUG("EventClass [%d],EventType [0x%x], Reques Id[%d], Event status [%d], sim_event->pDataLen[%d]",
981                         sim_event->EventClass, sim_event->EventType, sim_event->RequestId, sim_event->Status,sim_event->pDataLen);
982 #if 0
983         if(sim_event->Status != TAPI_SIM_PB_SUCCESS)
984         {
985                 __PrintPBResult("SIM Result", sim_event->Status);
986                 TEST_DEBUG("TAPI Fail: EventStatus [%d]", sim_event->Status);
987                 return;
988         }
989 #endif
990
991         if (sim_event->EventClass == TAPI_EVENT_CLASS_SIM) {
992                 switch (sim_event->EventType) {
993                 case TAPI_EVENT_SIM_STATUS_IND: {
994                         TEST_DEBUG("***********TAPI_EVENT_SIM_STATUS_IND**************");
995
996                         //      TEST_DEBUG("Event status [%d]", sim_event->Status);
997
998                         if (sim_event->Status == TAPI_SIM_STATUS_CARD_ERROR) {
999                                 TEST_DEBUG("SIM CARD ERROR");
1000                         } else if (sim_event->Status == TAPI_SIM_STATUS_CARD_NOT_PRESENT) {
1001                                 TEST_DEBUG("SIM CARD NOT INSERTED");
1002                         } else if (sim_event->Status == TAPI_SIM_STATUS_SIM_INITIALIZING) {
1003                                 TelSimCardType_t CardType =
1004                                                 *((TelSimCardType_t*) (sim_event->pData));
1005
1006                                 TEST_DEBUG("SIM INITITIALIZING");
1007                                 __PrintCardType("CardType: ", CardType);
1008                         } else if (sim_event->Status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) {
1009                                 TEST_DEBUG("SIM INIT COMPLETED");
1010                         } else if (sim_event->Status == TAPI_SIM_STATUS_SIM_PIN_REQUIRED) {
1011                                 TEST_DEBUG("SIM PIN REQUIRED");
1012                         } else if (sim_event->Status == TAPI_SIM_STATUS_SIM_PUK_REQUIRED) {
1013                                 TEST_DEBUG("SIM PUK REQUIRED");
1014                         } else if (sim_event->Status == TAPI_SIM_STATUS_CARD_BLOCKED) {
1015                                 TEST_DEBUG("SIM CARD BLOCKED");
1016                         }
1017                         TEST_DEBUG("********************************************");
1018
1019                 }
1020                         break;
1021
1022                 case TAPI_EVENT_SIM_PB_CAPABILITY_INFO_CNF: {
1023                         TEST_DEBUG("*****************TAPI_EVENT_SIM_PB_CAPABILITY_INFO_CNF***************************");
1024
1025                         //TEST_DEBUG("SIM PB Capability Info event status = [0x%x]", sim_event->Status);
1026
1027                         TelSimPbCapabilityInfo_t *sim_capability_info =
1028                                         (TelSimPbCapabilityInfo_t*) sim_event->pData;
1029
1030                         int i;
1031                         for (i = 0; i < sim_capability_info->FileTypeCount; i++) {
1032                                 __PrintPbFiledType(
1033                                                 sim_capability_info->FileTypeInfo[i].FileType3G);
1034                                 // TEST_DEBUG(" Filed tag type [%d]", sim_capability_info->FileTypeInfo[i].FileType3G);
1035                                 TEST_DEBUG(" max index [%d]", sim_capability_info->FileTypeInfo[i].PbIndexMax);
1036                                 TEST_DEBUG(" max entry [%d]", sim_capability_info->FileTypeInfo[i].PbTextMax);
1037                                 TEST_DEBUG(" used count [%d]", sim_capability_info->FileTypeInfo[i].TotalRecordCount);
1038                         }
1039
1040                         TEST_DEBUG("****************************************************");
1041
1042                 }
1043                         break;
1044
1045                 case TAPI_EVENT_SIM_PB_STORAGE_COUNT_CNF: {
1046                         TEST_DEBUG("*****TAPI_EVENT_SIM_PB_STORAGE_COUNT_CNF*****");
1047
1048                         TelSimPbStorageInfo_t *storageInfo =
1049                                         (TelSimPbStorageInfo_t*) sim_event->pData;
1050
1051                         //TEST_DEBUG("SIM PB storage count event status = [0x%x]", sim_event->Status);
1052
1053
1054                         __PrintStorageType(storageInfo->StorageFileType);
1055                         //TEST_DEBUG("PB_STORAGE_TYPE 0x%x", storageInfo->StorageFileType);
1056                         TEST_DEBUG("TOTAL_COUNT = %d", storageInfo->TotalRecordCount);
1057                         TEST_DEBUG("USED_COUNT =  %d", storageInfo->UsedRecordCount);
1058
1059                         TEST_DEBUG("********************************************");
1060                 }
1061                         break;
1062
1063                 case TAPI_EVENT_SIM_PB_ENTRY_INFO_CNF: {
1064                         TEST_DEBUG("**********TAPI_EVENT_SIM_PB_ENTRY_INFO_CNF********");
1065
1066                         TelSimPbEntryInfo_t *entryInfo =
1067                                         (TelSimPbEntryInfo_t*) sim_event->pData;
1068
1069                         //TEST_DEBUG("SIM PB entry info event status = [0x%x]", sim_event->Status);
1070
1071                         //TEST_DEBUG("STORAGE TYPE [%d]", entryInfo->StorageFileType);
1072                         __PrintStorageType(entryInfo->StorageFileType);
1073                         TEST_DEBUG("PB_INDEX_MIN %d", entryInfo->PbIndexMin);
1074                         TEST_DEBUG("PB_INDEX_MAX = %d", entryInfo->PbIndexMax);
1075                         TEST_DEBUG("PB_NUM_LEN_MAX =  %d", entryInfo->PbNumLenMax);
1076                         TEST_DEBUG("PB_TEXT_LEN_MAX =  %d", entryInfo->PbTextLenMax);
1077
1078                         TEST_DEBUG("********************************************");
1079                 }
1080                         break;
1081
1082                 case TAPI_EVENT_SIM_PB_ACCESS_READ_CNF: {
1083                         TEST_DEBUG("*********TAPI_EVENT_SIM_PB_ACCESS_READ_CNF*********");
1084
1085                         //TEST_DEBUG("SIM PB access read event status = [0x%x]", sim_event->Status);
1086
1087                         TelSimPbRecordData_t *sim_acces_info =
1088                                         (TelSimPbRecordData_t*) sim_event->pData;
1089
1090                         __PrintStorageType(sim_acces_info->StorageFileType);
1091                         //TEST_DEBUG("storaget type is [0x%x]",sim_acces_info->StorageFileType);
1092
1093                         if (sim_event->Status != TAPI_SIM_PB_SUCCESS) {
1094                                 TEST_DEBUG(" SIM phone book access error [%d]", sim_event->Status);
1095                                 break;
1096                         }
1097
1098                         int ascii_text_len = 0;
1099                         char ascii_text[256] = { 0, };
1100
1101                         if (sim_acces_info->StorageFileType == TAPI_SIM_PB_EN
1102                                         || sim_acces_info->StorageFileType == TAPI_SIM_PB_FDN
1103                                         || sim_acces_info->StorageFileType == TAPI_SIM_PB_LDN
1104                                         || sim_acces_info->StorageFileType == TAPI_SIM_PB_MSISDN
1105                                         || sim_acces_info->StorageFileType == TAPI_SIM_PB_ADN
1106                                         || sim_acces_info->StorageFileType == TAPI_SIM_PB_SDN) {
1107                                 TEST_DEBUG(" 2G Type SIM phone book access");
1108                                 TEST_DEBUG(" sim_acces_info->StorageFileType[%d](0-fdn,1-ldn,2-msisdn,3-adn,4-sdn,5-en), number[%s]",sim_acces_info->StorageFileType, (char *)sim_acces_info->ContactInfo.Pb2GData.Number);
1109
1110                                 /* unicode decoding */
1111                                 if (sim_acces_info->ContactInfo.Pb2GData.NameEncryptType
1112                                                 == TAPI_SIM_TEXT_ENC_UCS2) {
1113                                         TEST_DEBUG("Decoding UCS2 to ASCII");
1114                                         if (FALSE
1115                                                         == __decode_unicode_to_asci_str(
1116                                                                         sim_acces_info->ContactInfo.Pb2GData.NameLen,
1117                                                                         (char *) &sim_acces_info->ContactInfo.Pb2GData.Name,
1118                                                                         (char *) &ascii_text_len, ascii_text)) {
1119                                                 TEST_DEBUG(" Deocing to ascii failed ");
1120                                                 break;
1121                                         }
1122                                 } else if (sim_acces_info->ContactInfo.Pb2GData.NameEncryptType
1123                                                 == TAPI_SIM_TEXT_ENC_ASCII
1124                                                 || sim_acces_info->ContactInfo.Pb2GData.NameEncryptType
1125                                                                 == TAPI_SIM_TEXT_ENC_GSM7BIT) {
1126                                         //TAPI_MEMCPY(ascii_text, sim_acces_info->ContactInfo.Pb2GData.Name, 256, TAPI_SIM_NUM_TEXT_LEN_MAX);
1127                                         //#define TAPI_MEMCPY(dest , src , dest_len , src_len)
1128                                         if (256 >= TAPI_SIM_NUM_TEXT_LEN_MAX) {
1129                                                 memcpy(ascii_text,
1130                                                                 sim_acces_info->ContactInfo.Pb2GData.Name,
1131                                                                 TAPI_SIM_NUM_TEXT_LEN_MAX);
1132                                         } else {
1133                                                 TEST_DEBUG("memcpy FAILURE - dest_len(%d) < src_len(%d)", 256, TAPI_SIM_NUM_TEXT_LEN_MAX);
1134                                         }
1135                                 } else {
1136                                         TEST_DEBUG("Name Encryption is not UCS2 / ASCII / unpacked GSM7bit");
1137                                         break;
1138                                 }
1139                                 TEST_DEBUG("text[%s]", ascii_text);
1140                         } else if (sim_acces_info->StorageFileType == TAPI_SIM_PB_3GSIM) {
1141                                 int i, k;
1142                                 int tmp_size;
1143                                 int num_of_pb_rec = 0;
1144
1145                                 TEST_DEBUG(" sim_event->pDataLen [%d]",sim_event->pDataLen);
1146                                 TEST_DEBUG(" sizeof(TelSimPbRecordData_t)[%d]",sizeof(TelSimPbRecordData_t));
1147                                 TEST_DEBUG(" strlen(sim_event->pData)[%d]", strlen(sim_event->pData));
1148
1149                                 num_of_pb_rec = (sim_event->pDataLen
1150                                                 / sizeof(TelSimPbRecordData_t));
1151
1152                                 TEST_DEBUG("Number of Saved Records [%d]",num_of_pb_rec);
1153
1154                                 char * temp = (char*) malloc(sim_event->pDataLen);
1155                                 memcpy(temp, (char*) sim_event->pData, sim_event->pDataLen);
1156
1157                                 TelSimPbRecordData_t *sim_3g_access_info;
1158
1159                                 for (k = 0; k < num_of_pb_rec; k++) {
1160                                         tmp_size = k * sizeof(TelSimPbRecordData_t);
1161                                         sim_3g_access_info = (TelSimPbRecordData_t*) (temp
1162                                                         + tmp_size);
1163
1164                                         TEST_DEBUG("****************************************************");
1165                                         TEST_DEBUG(" Record Num = [%d], index = [%d], next index = [%d] ",k , sim_3g_access_info->Index,sim_3g_access_info->NextIndex);
1166
1167                                         TEST_DEBUG(" Num of Fields = [%d]",sim_3g_access_info->ContactInfo.Pb3GData.FileTypeCount);
1168                                         for (i = 0; i
1169                                                         < sim_3g_access_info->ContactInfo.Pb3GData.FileTypeCount; i++) {
1170                                                 TEST_DEBUG("-------------------------------------");
1171                                                 TEST_DEBUG("Field_type = [%d], FiledLen = [%d]",
1172                                                                 sim_3g_access_info->ContactInfo.Pb3GData.PbFileDataInfo[i].FileType,
1173                                                                 sim_3g_access_info->ContactInfo.Pb3GData.PbFileDataInfo[i].FileDataLength);
1174
1175                                                 if (sim_3g_access_info->ContactInfo.Pb3GData.PbFileDataInfo[i].FileType
1176                                                                 == TAPI_PB_3G_GRP) {
1177                                                         int grp_index;
1178                                                         TEST_DEBUG("Number of groups [%d]",sim_3g_access_info->ContactInfo.Pb3GData.PbFileDataInfo[i].FileDataLength );
1179
1180                                                         for (grp_index = 0; grp_index
1181                                                                         < (sim_3g_access_info->ContactInfo.Pb3GData.PbFileDataInfo[i].FileDataLength); grp_index++) {
1182                                                                 TEST_DEBUG(" Groupd Index [%d]",sim_3g_access_info->ContactInfo.Pb3GData.PbFileDataInfo[i].FileData[grp_index]); //ignore data_type byte
1183
1184                                                         }
1185
1186                                                 } else if (sim_3g_access_info->ContactInfo.Pb3GData.PbFileDataInfo[i].FileType
1187                                                                 == TAPI_PB_3G_NAME
1188                                                                 || sim_3g_access_info->ContactInfo.Pb3GData.PbFileDataInfo[i].FileType
1189                                                                                 == TAPI_PB_3G_EMAIL
1190                                                                 || sim_3g_access_info->ContactInfo.Pb3GData.PbFileDataInfo[i].FileType
1191                                                                                 == TAPI_PB_3G_SNE) {
1192                                                         TEST_DEBUG("3G Name or Email or SNE");
1193                                                         if (sim_3g_access_info->ContactInfo.Pb3GData.PbFileDataInfo[i].FileDataType.EncryptionType
1194                                                                         == TAPI_SIM_TEXT_ENC_UCS2) {
1195                                                                 TEST_DEBUG("EncryptionType: UCS2");
1196                                                                 if (FALSE
1197                                                                                 == __decode_unicode_to_asci_str(
1198                                                                                                 sim_3g_access_info->ContactInfo.Pb3GData.PbFileDataInfo[i].FileDataLength,
1199                                                                                                 (char *) &sim_3g_access_info->ContactInfo.Pb3GData.PbFileDataInfo[i].FileData,
1200                                                                                                 (char *) &ascii_text_len,
1201                                                                                                 ascii_text)) {
1202                                                                         TEST_DEBUG("Deocing ucs2 to ascii failed ");
1203                                                                         break;
1204                                                                 }
1205                                                         } else if (sim_3g_access_info->ContactInfo.Pb3GData.PbFileDataInfo[i].FileDataType.EncryptionType
1206                                                                         == TAPI_SIM_TEXT_ENC_ASCII) {
1207                                                                 TEST_DEBUG("EncryptionType: ASCII");
1208                                                                 //TAPI_MEMCPY(ascii_text, sim_3g_access_info->ContactInfo.Pb3GData.PbFileDataInfo[i].FileData, 256, TAPI_SIM_NUM_TEXT_LEN_MAX);
1209                                                                 //#define TAPI_MEMCPY(dest , src , dest_len , src_len)
1210                                                                 if (256 >= TAPI_SIM_NUM_TEXT_LEN_MAX) {
1211                                                                         memcpy(
1212                                                                                         ascii_text,
1213                                                                                         sim_3g_access_info->ContactInfo.Pb3GData.PbFileDataInfo[i].FileData,
1214                                                                                         TAPI_SIM_NUM_TEXT_LEN_MAX);
1215                                                                 } else {
1216                                                                         TEST_DEBUG("memcpy FAILURE - dest_len(%d) < src_len(%d)", 256, TAPI_SIM_NUM_TEXT_LEN_MAX);
1217                                                                 }
1218
1219                                                         } else if (sim_3g_access_info->ContactInfo.Pb3GData.PbFileDataInfo[i].FileDataType.EncryptionType
1220                                                                         == TAPI_SIM_TEXT_ENC_GSM7BIT) {
1221                                                                 TEST_DEBUG("EncryptionType: GSM7 bit");
1222                                                                 //TAPI_MEMCPY(ascii_text, sim_3g_access_info->ContactInfo.Pb3GData.PbFileDataInfo[i].FileData, 256, TAPI_SIM_NUM_TEXT_LEN_MAX);
1223                                                                 //#define TAPI_MEMCPY(dest , src , dest_len , src_len)
1224                                                                 if (256 >= TAPI_SIM_NUM_TEXT_LEN_MAX) {
1225                                                                         memcpy(
1226                                                                                         ascii_text,
1227                                                                                         sim_3g_access_info->ContactInfo.Pb3GData.PbFileDataInfo[i].FileData,
1228                                                                                         TAPI_SIM_NUM_TEXT_LEN_MAX);
1229                                                                 } else {
1230                                                                         TEST_DEBUG("memcpy FAILURE - dest_len(%d) < src_len(%d)", 256, TAPI_SIM_NUM_TEXT_LEN_MAX);
1231                                                                 }
1232
1233                                                         } else {
1234                                                                 TEST_DEBUG("Name Encryption is not UCS2 / ASCII / unpacked GSM7bit");
1235                                                                 break;
1236                                                         }
1237
1238                                                         TEST_DEBUG("Field_data[%s]", ascii_text);
1239
1240                                                 } else {
1241                                                         TEST_DEBUG("Number Type[%d]", sim_3g_access_info->ContactInfo.Pb3GData.PbFileDataInfo[i].FileDataType.NumType);
1242                                                         TEST_DEBUG("AAS RecID [0x%x]", sim_3g_access_info->ContactInfo.Pb3GData.PbFileDataInfo[i].AasRecordIdentifier);
1243
1244                                                         if (sim_3g_access_info->ContactInfo.Pb3GData.PbFileDataInfo[i].FileType
1245                                                                         == TAPI_PB_3G_ANR) {
1246                                                                 TEST_DEBUG("3G ANR Type");
1247                                                         } else {
1248                                                                 TEST_DEBUG("3G Number Type");
1249                                                         }
1250                                                         TEST_DEBUG("Number_data[%s]",sim_3g_access_info->ContactInfo.Pb3GData.PbFileDataInfo[i].FileData);
1251                                                 }
1252                                         }
1253                                 }
1254
1255                         } else if (sim_acces_info->StorageFileType == TAPI_SIM_PB_AAS
1256                                         || sim_acces_info->StorageFileType == TAPI_SIM_PB_GAS) {
1257                                 TEST_DEBUG(" AAS and GAS");
1258                                 TEST_DEBUG(" index = [%d]",sim_acces_info->Index);
1259                                 __PrintStorageType(sim_acces_info->StorageFileType);
1260                                 TEST_DEBUG(" str len = [%d]",sim_acces_info->ContactInfo.PbAdditionalNumStringData.TextLength);
1261                                 TEST_DEBUG(" encrypt type = [%d]",sim_acces_info->ContactInfo.PbAdditionalNumStringData.EncryptionType);
1262                                 TEST_DEBUG(" string = [%s]",sim_acces_info->ContactInfo.PbAdditionalNumStringData.TextData);
1263                         }
1264                         TEST_DEBUG("********************************************");
1265                 }
1266                         break;
1267
1268                 case TAPI_EVENT_SIM_PB_UPDATE_CNF: {
1269                         TEST_DEBUG("*****************TAPI_EVENT_SIM_PB_UPDATE_CNF***************************");
1270
1271                         TelSimPbUpdateResp_t *pUpdateResp =
1272                                         (TelSimPbUpdateResp_t*) sim_event->pData;
1273
1274                         __PrintStorageType(pUpdateResp->PbStorageInfo.StorageFileType);
1275                         TEST_DEBUG("Storage Info Total Record cnt [%d]", pUpdateResp->PbStorageInfo.TotalRecordCount);
1276                         TEST_DEBUG("Storage File Used Record Cnt [%d]", pUpdateResp->PbStorageInfo.UsedRecordCount);
1277                         //TEST_DEBUG(" Storage File Type [%d] ", pUpdateResp->PbStorageInfo.StorageFileType);
1278                         TEST_DEBUG("Storage File Index [%d]", pUpdateResp->PbIndex);
1279                         TEST_DEBUG("********************************************");
1280                 }
1281                         break;
1282
1283                 case TAPI_EVENT_SIM_PB_DELETE_CNF: {
1284                         TEST_DEBUG("*****************TAPI_EVENT_SIM_PB_DELETE_CNF***************************");
1285
1286                         TEST_DEBUG("SIM Delete PB event status = [0x%x]", sim_event->Status);
1287
1288                         TelSimPbUpdateResp_t *pDeleteResp =
1289                                         (TelSimPbUpdateResp_t*) sim_event->pData;
1290                         TEST_DEBUG(" Storage File Type [%d] ", pDeleteResp->PbStorageInfo.StorageFileType);
1291                         TEST_DEBUG(" Storage File Index [%d]", pDeleteResp->PbIndex);
1292
1293                         TEST_DEBUG("********************************************");
1294                 }
1295                         break;
1296
1297                 case TAPI_EVENT_SIM_FDN_STATUS_IND: {
1298                         TEST_DEBUG("*****************TAPI_EVENT_SIM_FDN_STATUS_IND***************************");
1299
1300                         TEST_DEBUG("SIM FDN status event status = [0x%x]", sim_event->Status);
1301
1302                         TEST_DEBUG("********************************************");
1303
1304                 }
1305                         break;
1306
1307                         /** will be tested later **/
1308 #if 1
1309                 case TAPI_EVENT_SIM_AUTHENTICATION_CNF: {
1310                         TEST_DEBUG("*****************IMS Authentication **********************");
1311 #if 0
1312                         TelSimAuthenticationResponse_t *auth_resp =
1313                                         (TelSimAuthenticationResponse_t*) sim_event->pData;
1314
1315                         TEST_DEBUG("SIM ISIM authentication event status = [0x%x]", sim_event->Status);
1316
1317                         TEST_DEBUG(" auth resp data [%s]",auth_resp->ResponeData);
1318                         TEST_DEBUG("  auth string [%s]",auth_resp->AuthenticationString);
1319                         TEST_DEBUG(" auth cipher key [%s]",auth_resp->CipherKey);
1320                         TEST_DEBUG(" auth integrity key [%s]",auth_resp->IntegrityKey);
1321 #endif
1322                 }
1323                         break;
1324
1325                 case TAPI_EVENT_SIM_SAP_CONNECT_CNF: {
1326                         TEST_DEBUG("*********** SAP CONNECT RESP *************");
1327
1328                         TelSimSapConnect_t *sap_conn_resp =
1329                                         (TelSimSapConnect_t*) sim_event->pData;
1330
1331                         TEST_DEBUG("SIM SAP connect request event status  = [0x%x]", sim_event->Status);
1332
1333                         TEST_DEBUG(" message id [0x%x]", sap_conn_resp->MsgId);
1334                         TEST_DEBUG("connection status [0x%x] ", sap_conn_resp->ConnectionStatus);
1335                         TEST_DEBUG("max message size [%d]", sap_conn_resp->MaxMsgSize);
1336
1337                         TEST_DEBUG("*****************************************");
1338                 }
1339                         break;
1340
1341                 case TAPI_EVENT_SIM_SAP_CONNECT_STATUS_CNF: {
1342                         TEST_DEBUG("*********** SAP CONNECT STATUS *************");
1343
1344                         TEST_DEBUG("SIM SAP connect event status = [0x%x]", sim_event->Status);
1345
1346                         TelSimSapStatusInfo_t *sap_conn_status =
1347                                         (TelSimSapStatusInfo_t*) sim_event->pData;
1348                         TEST_DEBUG(" connection status info [0x%x]", *sap_conn_status);
1349
1350                         TEST_DEBUG("*****************************************");
1351                 }
1352                         break;
1353
1354                 case TAPI_EVENT_SIM_SAP_TRANSFER_ATR_CNF: {
1355                         TEST_DEBUG("*********** SAP TRANSFER ATR *************");
1356
1357                         int i = 0;
1358                         TelSimSapAtrInfo_t *sap_transfer_atr =
1359                                         (TelSimSapAtrInfo_t*) sim_event->pData;
1360
1361                         TEST_DEBUG("SIM SAP trasfer ATR event status  = [0x%x]", sim_event->Status);
1362
1363                         TEST_DEBUG(" ATR result [0x%x]", sap_transfer_atr->AtrResult);
1364                         TEST_DEBUG(" ATR length [%lu]", sap_transfer_atr->AtrLength);
1365                         TEST_DEBUG(" ATR data ---> " );
1366                         for (i = 0; i < sap_transfer_atr->AtrLength; i++)
1367                                 TEST_DEBUG(" [0x%x]", sap_transfer_atr->AtrData[i]);
1368
1369                         TEST_DEBUG("*****************************************");
1370                 }
1371                         break;
1372
1373                 case TAPI_EVENT_SIM_SAP_TRANSFER_APDU_CNF: {
1374                         TEST_DEBUG("*********** SAP TRANSFER APDU *************");
1375
1376                         int i = 0;
1377                         TelSimSapApduData_t *sap_transfer_apdu =
1378                                         (TelSimSapApduData_t*) sim_event->pData;
1379
1380                         TEST_DEBUG("SIM SAP trasfer APDU event status  = [0x%x]", sim_event->Status);
1381
1382                         TEST_DEBUG(" APDU  length [0x%x]", sap_transfer_apdu->ApduLength);
1383                         TEST_DEBUG(" APDU  data ---> " );
1384                         for (i = 0; i < sap_transfer_apdu->ApduLength; i++)
1385                                 TEST_DEBUG(" [0x%x]", sap_transfer_apdu->Apdu[i]);
1386
1387                         TEST_DEBUG("*****************************************");
1388                 }
1389                         break;
1390
1391                 case TAPI_EVENT_SIM_SAP_SET_PROTOCOL_CNF: {
1392                         TEST_DEBUG("*********** SAP SET PROTOCOL  *************");
1393
1394                         TelSimSapProtocol_t *sap_result_code =
1395                                         (TelSimSapProtocol_t*) sim_event->pData;
1396
1397                         TEST_DEBUG("SIM SAP set protocol event status  = [0x%x]", sim_event->Status);
1398                         TEST_DEBUG("SAP SET protocol  result [0x%x]", *sap_result_code );
1399
1400                         TEST_DEBUG("*****************************************");
1401                 }
1402                         break;
1403
1404                 case TAPI_EVENT_SIM_SAP_SET_SIM_POWER_CNF: {
1405                         TEST_DEBUG("*********** SAP SET SIM POWER ON/OFF  *************");
1406
1407                         TelSimSapPower_t *sap_sim_power =
1408                                         (TelSimSapPower_t*) sim_event->pData;
1409
1410                         TEST_DEBUG("SIM SAP set SIM power  event status  = [0x%x]", sim_event->Status);
1411
1412                         TEST_DEBUG("message id [0x%x]", sap_sim_power->MsgId);
1413                         TEST_DEBUG(" sim power on/off result [0x%x]", sap_sim_power->SimPowerResult);
1414
1415                         TEST_DEBUG("*****************************************");
1416                 }
1417                         break;
1418
1419                 case TAPI_EVENT_SIM_SAP_CARD_READER_STATUS_CNF: {
1420                         TEST_DEBUG("*********** SAP CARD READER STATUS *************");
1421
1422                         TelSimCardReaderStatus_t *sap_card_reader_status =
1423                                         (TelSimCardReaderStatus_t*) sim_event->pData;
1424
1425                         TEST_DEBUG("SIM SAP card reader event status  = [0x%x]", sim_event->Status);
1426
1427                         TEST_DEBUG(" card reader result [0x%x] ", sap_card_reader_status->CardReaderResult);
1428                         TEST_DEBUG(" card reader status bitwise encoded data [%d]", sap_card_reader_status->CardReaderStatus);
1429
1430                         TEST_DEBUG("*****************************************");
1431                 }
1432                         break;
1433 #endif
1434
1435                         /******************************************************************************************************************************/
1436                         /*                                                                              NEW EVENT                                                                               */
1437                         /******************************************************************************************************************************/
1438                 case TAPI_EVENT_SIM_RSIM_ACCESS_CNF: {
1439                         TEST_DEBUG("********NEW*TAPI_EVENT_SIM_RSIM_ACCESS_CNF**********");
1440
1441                         TelSimReadFileRaw_t * rsim_resp =
1442                                         (TelSimReadFileRaw_t*) sim_event->pData;
1443
1444                         if (sim_event->Status == TAPI_SIM_ACCESS_SUCCESS) {
1445                                 TEST_DEBUG("rsim_resp->sw1[0x%x]", rsim_resp->sw1);
1446                                 TEST_DEBUG("rsim_resp->sw2[0x%x]", rsim_resp->sw2);
1447                                 TEST_DEBUG("rsim_resp->DataLen[%d]", rsim_resp->DataLen);
1448                                 TEST_DEBUG("rsim_resp->Data[%s]", rsim_resp->Data);
1449                         } else {
1450                                 TEST_DEBUG("OPERATION FAILED");
1451                         }
1452
1453                         TEST_DEBUG("********NEW*TAPI_EVENT_SIM_RSIM_ACCESS_CNF**********");
1454                 }
1455                         break;
1456
1457                 case TAPI_EVENT_SIM_VERIFY_SEC_CNF: {
1458                         TEST_DEBUG("********NEW*TAPI_EVENT_SIM_VERIFY_SEC_CNF**********");
1459
1460                         TelSimSecResult_t *pPinInfo = (TelSimSecResult_t*) sim_event->pData;
1461
1462                         //TEST_DEBUG("SIM Verify PIN event status = [0x%x]", sim_event->Status);
1463
1464                         if (sim_event->Status == TAPI_SIM_OPERATION_TIMEOUT) {
1465                                 TEST_DEBUG("TAPI SIM Operation Timeout!!");
1466                         } else if (sim_event->Status == TAPI_SIM_PIN_OPERATION_SUCCESS) {
1467                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN1) {
1468                                         TEST_DEBUG("PIN1 Verification Success!");
1469                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_SIM) {
1470                                         TEST_DEBUG("PIN1 Verification Success!");
1471                                 } else {
1472                                         TEST_DEBUG("PIN2 Vefication Success!");
1473                                 }
1474                         } else {
1475                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN1) {
1476                                         TEST_DEBUG("PIN1 Verification Failed! - PIN Required ");
1477                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1478                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PUK1) {
1479                                         TEST_DEBUG("PIN1 Verification Failed! - PUK Required ");
1480                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1481                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2) {
1482                                         TEST_DEBUG("PIN2 Verification Failed! - PIN2 Required ");
1483                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1484                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PUK2) {
1485                                         TEST_DEBUG("PIN2 Verification Failed! - PUK2 Required ");
1486                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1487                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_SIM) {
1488                                         TEST_DEBUG("SIM Lock Verification Failed! - SIM Lock code Required");
1489                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1490                                 }
1491                         }
1492                         TEST_DEBUG("********************************************");
1493                 }
1494                         break;
1495
1496                 case TAPI_EVENT_SIM_VERIFY_PUK_CNF: {
1497                         TEST_DEBUG("**********NEW*TAPI_EVENT_SIM_VERIFY_PUK_CNF********");
1498
1499                         TelSimSecResult_t *pPinInfo = (TelSimSecResult_t*) sim_event->pData;
1500
1501                         //TEST_DEBUG("SIM Unblock PIN event status = [0x%x]", sim_event->Status);
1502
1503                         if (sim_event->Status == TAPI_SIM_PIN_OPERATION_SUCCESS) {
1504                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN1) {
1505                                         TEST_DEBUG("Unblock PIN1 Success!");
1506                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2) {
1507                                         TEST_DEBUG("Unblock PIN2 Success!");
1508                                 }
1509                         } else {
1510                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN1) {
1511                                         TEST_DEBUG("PIN1 Verification Failed! - PIN Required ");
1512                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1513                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PUK1) {
1514                                         TEST_DEBUG("PIN1 Verification Failed! - PUK Required ");
1515                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1516                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2) {
1517                                         TEST_DEBUG("PIN2 Verification Failed! - PIN2 Required ");
1518                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1519                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PUK2) {
1520                                         TEST_DEBUG("PIN2 Verification Failed! - PUK2 Required ");
1521                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1522                                 }
1523                         }
1524                         TEST_DEBUG("********************************************");
1525                 }
1526                         break;
1527
1528                 case TAPI_EVENT_SIM_CHANGE_PINS_CNF: {
1529                         TEST_DEBUG("********NEW*TAPI_EVENT_SIM_CHANGE_PINS_CNF***************************");
1530
1531                         TelSimSecResult_t *pPinInfo = (TelSimSecResult_t*) sim_event->pData;
1532
1533                         //TEST_DEBUG("SIM Change PIN event status = [0x%x], pinType[%d]", sim_event->Status, pPinInfo->PinType);
1534                         TEST_DEBUG("PinType[%d]", pPinInfo->type);
1535
1536                         if (sim_event->Status == TAPI_SIM_PIN_OPERATION_SUCCESS) {
1537                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN1) {
1538                                         TEST_DEBUG("Change PIN1 Success!");
1539                                 } else {
1540                                         TEST_DEBUG("Change PIN2 Success!");
1541                                 }
1542                         } else {
1543                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN1) {
1544                                         TEST_DEBUG("PIN1 Verification Failed! - PIN Required ");
1545                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1546                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PUK1) {
1547                                         TEST_DEBUG("PIN1 Verification Failed! - PUK Required ");
1548                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1549                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2) {
1550                                         TEST_DEBUG("PIN2 Verification Failed! - PIN2 Required ");
1551                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1552                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PUK2) {
1553                                         TEST_DEBUG("PIN2 Verification Failed! - PUK2 Required ");
1554                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1555                                 }
1556                         }
1557                         TEST_DEBUG("********************************************");
1558                 }
1559                         break;
1560
1561                 case TAPI_EVENT_SIM_DISABLE_SEC_CNF: {
1562                         TEST_DEBUG("****************NEW*TAPI_EVENT_SIM_DISABLE_SEC_CNF****************");
1563
1564                         TelSimSecResult_t *pPinInfo = (TelSimSecResult_t*) sim_event->pData;
1565
1566                         //TEST_DEBUG("SIM Disable SEC event status = [0x%x]", sim_event->Status);
1567
1568                         if (sim_event->Status == TAPI_SIM_PIN_OPERATION_SUCCESS) {
1569                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN1) {
1570                                         TEST_DEBUG("Disable PIN1 Success!");
1571                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2) {
1572                                         TEST_DEBUG("Disable PIN2 Success!");
1573                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_SIM) {
1574                                         TEST_DEBUG("Disable SIM LOCK Success!");
1575                                 }
1576                         } else {
1577                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN1) {
1578                                         TEST_DEBUG("PIN1 Verification Failed! - PIN1Required ");
1579                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1580                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2) {
1581                                         TEST_DEBUG("PIN2 Verification Failed! - PIN2 Required ");
1582                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1583                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PUK1) {
1584                                         TEST_DEBUG("PIN1 Verification Failed! - PUK1 Required ");
1585                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1586                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PUK2) {
1587                                         TEST_DEBUG("PIN2 Verification Failed! - PUK2 Required ");
1588                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1589                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_SIM) {
1590                                         TEST_DEBUG("SIM LOCK Verification Failed! - SIM LOCK CODE Required ");
1591                                         TEST_DEBUG("Remainint attempts [%d] - Useless value", pPinInfo->retry_count);
1592                                 }
1593                         }
1594                         TEST_DEBUG("********************************************");
1595
1596                 }
1597                         break;
1598
1599                 case TAPI_EVENT_SIM_ENABLE_SEC_CNF: {
1600                         TEST_DEBUG("****************NEW*TAPI_EVENT_SIM_ENABLE_SEC_CNF****************");
1601
1602                         TelSimSecResult_t *pPinInfo = (TelSimSecResult_t*) sim_event->pData;
1603
1604                         //TEST_DEBUG("SIM ENABLE SEC event status = [0x%x]", sim_event->Status);
1605
1606                         if (sim_event->Status == TAPI_SIM_PIN_OPERATION_SUCCESS) {
1607                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN1) {
1608                                         TEST_DEBUG("Enable PIN1 Success!");
1609                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2) {
1610                                         TEST_DEBUG("Enable PIN2 Success!");
1611                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_SIM) {
1612                                         TEST_DEBUG("Enable SIM LOCK Success!");
1613                                 }
1614                         } else {
1615                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN1) {
1616                                         TEST_DEBUG("PIN1 Verification Failed! - PIN1Required ");
1617                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1618                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2) {
1619                                         TEST_DEBUG("PIN2 Verification Failed! - PIN2 Required ");
1620                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1621                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PUK1) {
1622                                         TEST_DEBUG("PIN1 Verification Failed! - PUK1 Required ");
1623                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1624                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PUK2) {
1625                                         TEST_DEBUG("PIN2 Verification Failed! - PUK2 Required ");
1626                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1627                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_SIM) {
1628                                         TEST_DEBUG("SIM LOCK Verification Failed! - SIM LOCK CODE Required ");
1629                                         TEST_DEBUG("Remainint attempts [%d] - Useless value", pPinInfo->retry_count);
1630                                 }
1631                         }
1632                         TEST_DEBUG("********************************************");
1633                 }
1634                         break;
1635
1636                 case TAPI_EVENT_SIM_DISABLE_FDNMODE_CNF: {
1637                         TEST_DEBUG("****************NEW*TAPI_EVENT_SIM_DISABLE_FDNMODE_CNF****************");
1638
1639                         TelSimSecResult_t *pPinInfo = (TelSimSecResult_t*) sim_event->pData;
1640
1641                         //TEST_DEBUG("SIM Disable FDN event status = [0x%x]", sim_event->Status);
1642
1643                         if (sim_event->Status == TAPI_SIM_PIN_OPERATION_SUCCESS) {
1644                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2) {
1645                                         TEST_DEBUG("Disable FDN Success!");
1646                                 } else {
1647                                         TEST_DEBUG("Unhandled type[%d]", pPinInfo->type);
1648                                 }
1649                         } else {
1650                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2) {
1651                                         TEST_DEBUG("PIN2 Verification Failed! - PIN2 Required ");
1652                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1653                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PUK2) {
1654                                         TEST_DEBUG("PIN2 Verification Failed! - PUK2 Required ");
1655                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1656                                 } else {
1657                                         TEST_DEBUG("Unhandled type[%d]", pPinInfo->type);
1658                                 }
1659                         }
1660                         TEST_DEBUG("********************************************");
1661                 }
1662                         break;
1663
1664                 case TAPI_EVENT_SIM_ENABLE_FDNMODE_CNF: {
1665                         TEST_DEBUG("****************NEW*TAPI_EVENT_SIM_ENABLE_FDNMODE_CNF****************");
1666
1667                         TelSimSecResult_t *pPinInfo = (TelSimSecResult_t*) sim_event->pData;
1668
1669                         //TEST_DEBUG("SIM Enable FDN event status = [0x%x]", sim_event->Status);
1670
1671                         if (sim_event->Status == TAPI_SIM_PIN_OPERATION_SUCCESS) {
1672                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2) {
1673                                         TEST_DEBUG("Enable FDN Success!");
1674                                 } else {
1675                                         TEST_DEBUG("Unhandled type[%d]", pPinInfo->type);
1676                                 }
1677                         } else {
1678                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2) {
1679                                         TEST_DEBUG("PIN2 Verification Failed! - PIN2 Required ");
1680                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1681                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PUK2) {
1682                                         TEST_DEBUG("PIN2 Verification Failed! - PUK2 Required ");
1683                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1684                                 } else {
1685                                         TEST_DEBUG("Unhandled type[%d]", pPinInfo->type);
1686                                 }
1687                         }
1688                         TEST_DEBUG("********************************************");
1689                 }
1690                         break;
1691
1692                 case TAPI_EVENT_SIM_PERS_STATUS_CNF: {
1693                         TelSimPersStatus_t* pers_status =
1694                                         (TelSimPersStatus_t*) sim_event->pData;
1695
1696                         printf(
1697                                         "[SIM APP]**********NEW* TAPI_EVENT_SIM_PERS_STATUS_CNF************\n");
1698                         printf("[SIM APP]SIM lock personalisation event status = [%x]\n",
1699                                         sim_event->Status);
1700                         printf(
1701                                         "[SIM APP]SIM lock personalisation status - net0-ns1-sp2-cp3  = [%d]\n",
1702                                         pers_status->type);
1703                         printf(
1704                                         "[SIM APP]SIM lock personalisation status - unlock0-lock1  = [%d]\n",
1705                                         pers_status->mode);
1706                         printf(
1707                                         "[SIM APP]***************************************************\n");
1708                 }
1709                         break;
1710
1711                 case TAPI_EVENT_SIM_DISABLE_PERS_CNF: {
1712                         TelSimPinOperationResult_t opResult =
1713                                         (TelSimPinOperationResult_t) sim_event->Status;
1714
1715                         printf(
1716                                         "[SIM APP]*********NEW*TAPI_EVENT_SIM_DISABLE_PERS_CNF************\n");
1717                         printf("[SIM APP]Eable Personalization event status = [%x]\n",
1718                                         opResult);
1719
1720                         if (opResult == TAPI_SIM_PIN_OPERATION_SUCCESS) {
1721                                 printf("[SIM APP]Disable Personalization Success!\n");
1722                         } else {
1723                                 printf(
1724                                                 "[SIM APP]Verification Failed! - Correct Password Required\n");
1725                         }
1726                         printf(
1727                                         "\n***************************************************************\n");
1728                 }
1729                         break;
1730
1731                 case TAPI_EVENT_SIM_ENABLE_PERS_CNF: {
1732                         TelSimPinOperationResult_t opResult =
1733                                         (TelSimPinOperationResult_t) sim_event->Status;
1734
1735                         printf(
1736                                         "[SIM APP]*********NEW*TAPI_EVENT_SIM_ENABLE_PERS_CNF************\n");
1737                         printf("[SIM APP]Eable Personalization event status = [%x]\n",
1738                                         opResult);
1739
1740                         if (opResult == TAPI_SIM_PIN_OPERATION_SUCCESS) {
1741                                 printf("[SIM APP]Enable Personalization Success!\n");
1742                         } else {
1743                                 printf(
1744                                                 "[SIM APP]Verification Failed! - Correct Password Required\n");
1745                         }
1746                         printf(
1747                                         "\n***************************************************************\n");
1748                 }
1749                         break;
1750
1751                 case TAPI_EVENT_SIM_SET_LANGUAGE_CNF: {
1752                         TEST_DEBUG("*********NEW*TAPI_EVENT_SIM_SET_LANGUAGE_CNF************");
1753                         TEST_DEBUG("update event status = [0x%x]", sim_event->Status);
1754                         TEST_DEBUG("**********************************************************");
1755                 }
1756                         break;
1757
1758                 case TAPI_EVENT_SIM_APDU_CNF: {
1759                         TelSimApduResp_t* apdu_resp = (TelSimApduResp_t*) sim_event->pData;
1760                         int i = 0;
1761                         TEST_DEBUG("*********NEW*TAPI_EVENT_SIM_APDU_CNF************");
1762                         TEST_DEBUG("update event status = [0x%x]", sim_event->Status);
1763
1764                         if (sim_event->Status == 1234) {
1765                                 TEST_DEBUG("timeout happended. this means, modem didn`t reply");
1766                                 return;
1767                         }
1768
1769                         if (apdu_resp != NULL) {
1770                                 TEST_DEBUG("apdu_resp->apdu_resp_len[%d]",apdu_resp->apdu_resp_len);
1771
1772                                 for (i = 0; i < apdu_resp->apdu_resp_len; i++)
1773                                         TEST_DEBUG("apdu_resp->apdu_resp[%d]=[0x%x]",i,apdu_resp->apdu_resp[i]);
1774
1775                         } else {
1776                                 TEST_DEBUG("atr_resp == NULL");
1777                         }
1778                         TEST_DEBUG("**********************************************************");;
1779                 }
1780                         break;
1781
1782                 case TAPI_EVENT_SIM_ATR_CNF: {
1783                         TelSimAtrResp_t* atr_resp = (TelSimAtrResp_t*) sim_event->pData;
1784                         int i = 0;
1785
1786                         TEST_DEBUG("*********NEW*TAPI_EVENT_SIM_ATR_CNF************");
1787                         TEST_DEBUG("update event status = [0x%x]", sim_event->Status);
1788
1789                         if (sim_event->Status == 1234) {
1790                                 TEST_DEBUG("timeout happended. this means, modem didn`t reply");
1791                                 return;
1792                         }
1793
1794                         if (atr_resp != NULL) {
1795                                 TEST_DEBUG("atr_resp->atr_resp_len[%d]",atr_resp->atr_resp_len);
1796
1797                                 for (i = 0; i < atr_resp->atr_resp_len; i++)
1798                                         TEST_DEBUG("atr_resp->atr_resp[%d]=[0x%x]",i,atr_resp->atr_resp[i]);
1799                         } else {
1800                                 TEST_DEBUG("atr_resp == NULL");
1801                         }
1802                         TEST_DEBUG("**********************************************************");
1803                 }
1804                         break;
1805
1806 #if 0
1807
1808                         case TAPI_SIM_EVENT_PB_GET_STORAGE_LIST:
1809                         {
1810                                 TEST_DEBUG("****************TAPI_SIM_EVENT_PB_GET_STORAGE_LIST****************************");
1811                                 char *p = (char*)&sim_event->pData;
1812
1813                                 TEST_DEBUG("SIM phone book storage list Information ");
1814                                 if(*p & 0x01)
1815                                 TEST_DEBUG("IPC_PB_STORAGE_TYPE_DC - ME Dailled Call list");
1816                                 if(*p & 0x02)
1817                                 TEST_DEBUG("IPC_PB_STORAGE_TYPE_EN - Emergency Number");
1818                                 if(*p & 0x03)
1819                                 TEST_DEBUG("IPC_PB_STORAGE_TYPE_FD - Fixed dialing phonebook");
1820                                 if(*p & 0x04)
1821                                 TEST_DEBUG("IPC_PB_STORAGE_TYPE_LD - Last dialled phonebook");
1822                                 if(*p & 0x05)
1823                                 TEST_DEBUG("IPC_PB_STORAGE_TYPE_MC -Missed call list");
1824                                 if(*p & 0x06)
1825                                 TEST_DEBUG("IPC_PB_STORAGE_TYPE_ME - ME phone book");
1826                                 if(*p & 0x07)
1827                                 TEST_DEBUG("IPC_PB_STORAGE_TYPE_MT - ME and sim combined phone book");
1828                                 if(*p & 0x08)
1829                                 TEST_DEBUG("IPC_PB_STORAGE_TYPE_ON - My own number - MSISDN");
1830                                 if(*p & 0x09)
1831                                 TEST_DEBUG("IPC_PB_STORAGE_TYPE_RC - ME Received calls");
1832                                 if(*p & 0x0A)
1833                                 TEST_DEBUG("IPC_PB_STORAGE_TYPE_SIM - SIM phone book");
1834                                 if(*p & 0x0B)
1835                                 TEST_DEBUG("IPC_PB_STORAGE_TYPE_SDN - Service dailing number");
1836
1837                                 TEST_DEBUG("********************************************");
1838                         }
1839                         break;
1840 #endif
1841
1842                 default:
1843                         TEST_DEBUG("Undhandled event type [0x%x]",sim_event->EventType)
1844                         ;
1845                 }
1846                 printf("\n");
1847         }//end switch (Type)
1848         else {
1849                 TEST_DEBUG("Undhandled EventClass [0x%x]",sim_event->EventClass);
1850         }
1851         return;
1852
1853 }// end func
1854
1855
1856 int sim_read_key_input(void) {
1857         char buf[256] = { 0, };
1858         int ret = 0;
1859         TapiResult_t err_code = TAPI_API_SUCCESS;
1860         char ch;
1861
1862         ret = read(0, buf, sizeof(buf));
1863
1864         if (ret < 0) {
1865                 if (errno == EINTR)
1866                         perror("read(1)");
1867                 return -1;
1868
1869         } else if (ret == 0)
1870                 return ret;
1871
1872         printf("************************************\n");
1873         printf("op : show all OP | q : quit sim test app \n");
1874         printf("************************************\n");
1875         printf("SIM OP in : %s\n", buf);
1876
1877         if (memcmp(buf, "op", sizeof("op") - 1) == 0) {
1878                 printf("***************************** NEW Asynchronous APIs *******************************\n");
1879                 printf("rsim : rsim \n");
1880                 printf("pin1 : verify pin1 number \n");
1881                 printf("pin2 : verify pin2 number\n");
1882                 printf("sim : verify sim lock number\n");
1883                 printf("puk1 : Unblocking CHV1 \n");
1884                 printf("puk2 : Unblocking CHV2 \n");
1885                 printf("chpin1 : change pin1 number \n");
1886                 printf("chpin2 : change pin2 number \n");
1887                 printf("enpin : CHV enable\n");
1888                 printf("dispin : CHV disable\n");
1889                 printf("enfdn : FDN enable\n");
1890                 printf("disfdn : FDN disable\n");
1891                 printf("ensim : enable sim lock\n");
1892                 printf("dissim : disable sim lock\n");
1893                 printf("getpers : Get lock personalisation information \n");
1894                 printf("medepers : de-personalization test\n");
1895                 printf("mepers : personalization test\n");
1896                 printf("setlang : update sim language info\n");
1897                 printf("apdu : send apdu\n");
1898                 printf("atr : request atr\n");
1899                 printf("***************************** Synchronous APIs *******************************\n");
1900                 printf("siminit : Get SIM init Information\n");
1901                 printf("getpin1 : Get CHV1 status info\n");
1902                 printf("getfdn : Get FDN status info\n");
1903                 printf("getpin2 : Get CHV2 status Info \n");
1904                 printf("getsim : Get CHV2 status Info \n");
1905                 printf("gettype : show Sim Card Type\n");
1906                 printf("getimsi : show Sim IMSI\n");
1907                 printf("geticcid : show Sim ICCID\n");
1908                 printf("getlang:Language Indication Info\n");
1909                 printf("getecc : get SIM ECC\n");
1910                 printf("getuecc : get USIM ECC\n");
1911                 printf("getmb : get mailbox number\n");
1912                 printf("getmw : get message waiting information\n");
1913                 printf("getcf : get callforwarding information\n");
1914                 printf("getcphs : get cphs information\n");
1915                 printf("getmsisdn : get msisdn information\n");
1916                 printf("******************************* PHONE BOOK ***********************************\n");
1917                 printf("pbinit : Get pb init info\n");
1918                 printf("pbcapa : pb capability info \n");
1919                 printf("pbcnt : phonebook used and total count\n");
1920                 printf("pbentry : phonebook entry info\n");
1921                 printf("pbadd : phonebook add\n");
1922                 printf("pbdel : phonebook delete\n");
1923                 printf("pbread:phonebook read\n");
1924                 //              printf("****************************** SAP commands **********************************\n");
1925                 //              printf("sapconnect: SAP Connect request\n");
1926                 //              printf("sapstatus : SAP current connection status request \n");
1927                 //              printf("sapatr: SAP transfer atr request\n");
1928                 //              printf("sapapdu: SAP transfer apdu request\n");
1929                 //              printf("sapsetproto: SAP set protocol request\n");
1930                 //              printf("sapsimpwr: SAP SIM power on/off request\n");
1931                 //              printf("sapreaderstat: SAP card reader status request\n");
1932                 //              printf("*****************************************************************************\n");
1933         }
1934
1935         /*NEW API -START*/
1936         if (memcmp(buf, "siminit", sizeof("siminit") - 1) == 0) {
1937                 TelSimCardStatus_t status = 0x00;
1938                 int b_card_changed = 0;
1939
1940                 err_code = tel_get_sim_init_info(&status, &b_card_changed);
1941
1942                 if (err_code == TAPI_API_SUCCESS) {
1943                         TEST_DEBUG("*************************************************************");
1944                         __PrintCardStatus("CardStatus: ", status);
1945                         TEST_DEBUG("b_card_changed[%d]\n",b_card_changed);
1946                         TEST_DEBUG("*************************************************************");
1947                 } else {
1948                         TEST_DEBUG("TAPI Fail: Error Code [%d]\n",err_code);
1949                 }
1950         } else if (memcmp(buf, "rsim", sizeof("rsim") - 1) == 0) {
1951                 TEST_DEBUG("rsim....");
1952
1953                 TelSimRSimReq_t rsim = { 0, };
1954
1955                 rsim.file_id = 0x6F60;
1956                 rsim.rsim_cmd = TAPI_SIM_GET_RESPONSE;
1957
1958                 err_code = tel_req_sim_access((const TelSimRSimReq_t*) &rsim,
1959                                 &request_id);
1960                 if (err_code != TAPI_API_SUCCESS) {
1961                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
1962                 }
1963         } else if (memcmp(buf, "pin1", sizeof("pin1") - 1) == 0) {
1964                 TEST_DEBUG("Pin1 Verification");
1965                 int length = TAPI_SIM_PIN_LENGTH + 1;
1966                 char init_pin_val[TAPI_SIM_PIN_LENGTH + 1];
1967
1968                 getchar();
1969
1970                 TEST_DEBUG(" PUT PIN1 CODE: ");
1971
1972                 _fgets(init_pin_val, 9);
1973
1974                 TelSimSecPw_t pin_data = { 0, };
1975
1976                 pin_data.type = TAPI_SIM_PTYPE_PIN1; // 0x00
1977                 pin_data.pw_len = strlen(init_pin_val);
1978
1979                 TEST_DEBUG("pw_len[%d]", pin_data.pw_len);
1980
1981                 pin_data.pw = (unsigned char*) malloc(length);
1982                 memcpy(pin_data.pw, init_pin_val, length);
1983
1984                 err_code = tel_verifiy_sim_pins(&pin_data, &request_id);
1985
1986                 if (err_code != TAPI_API_SUCCESS) {
1987                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
1988                 }
1989
1990         } else if (memcmp(buf, "pin2", sizeof("pin2") - 1) == 0) {
1991                 TEST_DEBUG("Pin2 Verification");
1992                 int length = TAPI_SIM_PIN_LENGTH + 1;
1993                 char init_pin_val[TAPI_SIM_PIN_LENGTH + 1];
1994
1995                 getchar();
1996
1997                 TEST_DEBUG(" PUT PIN2 CODE: ");
1998
1999                 _fgets(init_pin_val, 9);
2000
2001                 TelSimSecPw_t pin_data = { 0, };
2002
2003                 pin_data.type = TAPI_SIM_PTYPE_PIN2; // 0x00
2004                 pin_data.pw_len = strlen(init_pin_val);
2005                 TEST_DEBUG("pw_len[%d]", pin_data.pw_len);
2006
2007                 pin_data.pw = (unsigned char*) malloc(length);
2008                 memcpy(pin_data.pw, init_pin_val, length);
2009
2010                 err_code = tel_verifiy_sim_pins(&pin_data, &request_id);
2011
2012                 if (err_code != TAPI_API_SUCCESS) {
2013                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2014                 }
2015
2016         } else if (memcmp(buf, "sim", sizeof("sim") - 1) == 0) {
2017                 TEST_DEBUG("sim lock verification");
2018                 int length = TAPI_SIM_PIN_LENGTH + 1;
2019                 char init_pin_val[TAPI_SIM_PIN_LENGTH + 1];
2020
2021                 //puts("Flushing input - Enter \ to exit! ");
2022                 //while ((ch = getchar()) != '\n' && ch != EOF);
2023                 getchar();
2024
2025                 TEST_DEBUG(" PUT SIM LOCK CODE: 4 DIGIT ");
2026
2027                 _fgets(init_pin_val, 9);
2028
2029                 TelSimSecPw_t pin_data = { 0, };
2030
2031                 pin_data.type = TAPI_SIM_PTYPE_SIM; // 0x06
2032                 pin_data.pw_len = strlen(init_pin_val);
2033                 TEST_DEBUG("pw_len[%d]", pin_data.pw_len);
2034
2035                 pin_data.pw = (unsigned char*) malloc(length);
2036                 memcpy(pin_data.pw, init_pin_val, length);
2037
2038                 err_code = tel_verifiy_sim_pins(&pin_data, &request_id);
2039
2040                 if (err_code != TAPI_API_SUCCESS) {
2041                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2042                 }
2043         }
2044         // Disable pin1
2045         else if (memcmp(buf, "dispin", sizeof("dispin") - 1) == 0) {
2046                 getchar();
2047
2048                 TEST_DEBUG("Disable npin1");
2049                 TEST_DEBUG("Plese input PIN1 CODE: ");
2050
2051                 int length = TAPI_SIM_PIN_LENGTH + 1;
2052                 char init_pin_val[length];
2053
2054                 _fgets(init_pin_val, 9);
2055
2056                 TelSimSecPw_t sec_data = { 0, };
2057                 sec_data.type = TAPI_SIM_PTYPE_PIN1; // 0x00
2058                 sec_data.pw_len = strlen(init_pin_val);
2059                 TEST_DEBUG("pw_len[%d]", sec_data.pw_len);
2060
2061                 sec_data.pw = (unsigned char*) malloc(length);
2062                 memcpy(sec_data.pw, init_pin_val, length);
2063
2064                 err_code = tel_disable_sim_security(&sec_data, &request_id);
2065
2066                 if (err_code != TAPI_API_SUCCESS) {
2067                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2068                 }
2069         }
2070
2071         // Enable pin1
2072         else if (memcmp(buf, "enpin", sizeof("enpin") - 1) == 0) {
2073                 //TEST_DEBUG("Flushing input - Enter \ to exit!");
2074                 //while ((ch = getchar()) != '\n' && ch != EOF);
2075                 getchar();
2076
2077                 TEST_DEBUG("Enable npin1");
2078                 TEST_DEBUG("Plese input PIN1 CODE: ");
2079
2080                 int length = TAPI_SIM_PIN_LENGTH + 1;
2081                 char init_pin_val[length];
2082
2083                 _fgets(init_pin_val, 9);
2084
2085                 TelSimSecPw_t sec_data = { 0, };
2086                 sec_data.type = TAPI_SIM_PTYPE_PIN1; // 0x00
2087                 sec_data.pw_len = strlen(init_pin_val);
2088                 TEST_DEBUG("pw_len[%d]", sec_data.pw_len);
2089
2090                 sec_data.pw = (unsigned char*) malloc(length);
2091                 memcpy(sec_data.pw, init_pin_val, length);
2092
2093                 err_code = tel_enable_sim_security(&sec_data, &request_id);
2094
2095                 if (err_code != TAPI_API_SUCCESS) {
2096                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2097                 }
2098         }
2099
2100         // Disable sim lock
2101         else if (memcmp(buf, "dissim", sizeof("dissim") - 1) == 0) {
2102                 getchar();
2103
2104                 TEST_DEBUG("Disable ndissim");
2105                 TEST_DEBUG("Plese input SIM LOCK CODE: ");
2106
2107                 int length = TAPI_SIM_PIN_LENGTH + 1;
2108                 char init_pin_val[length];
2109
2110                 _fgets(init_pin_val, 9);
2111
2112                 TelSimSecPw_t sec_data = { 0, };
2113                 sec_data.type = TAPI_SIM_PTYPE_SIM; // 0x00
2114                 sec_data.pw_len = strlen(init_pin_val);
2115                 TEST_DEBUG("pw_len[%d]", sec_data.pw_len);
2116
2117                 sec_data.pw = (unsigned char*) malloc(length);
2118                 memcpy(sec_data.pw, init_pin_val, length);
2119
2120                 err_code = tel_disable_sim_security(&sec_data, &request_id);
2121
2122                 if (err_code != TAPI_API_SUCCESS) {
2123                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2124                 }
2125         }
2126
2127         // Enable pin1
2128         else if (memcmp(buf, "ensim", sizeof("ensim") - 1) == 0) {
2129                 getchar();
2130
2131                 TEST_DEBUG("Enable nensim");
2132                 TEST_DEBUG("Plese input SIM LOCK CODE: ");
2133
2134                 int length = TAPI_SIM_PIN_LENGTH + 1;
2135                 char init_pin_val[length];
2136
2137                 _fgets(init_pin_val, 9);
2138
2139                 TelSimSecPw_t sec_data = { 0, };
2140                 sec_data.type = TAPI_SIM_PTYPE_SIM; // 0x00
2141                 sec_data.pw_len = strlen(init_pin_val);
2142                 TEST_DEBUG("pw_len[%d]", sec_data.pw_len);
2143
2144                 sec_data.pw = (unsigned char*) malloc(length);
2145                 memcpy(sec_data.pw, init_pin_val, length);
2146
2147                 err_code = tel_enable_sim_security(&sec_data, &request_id);
2148
2149                 if (err_code != TAPI_API_SUCCESS) {
2150                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2151                 }
2152         }
2153
2154         // get pin1 status
2155         else if (memcmp(buf, "getpin1", sizeof("getpin1") - 1) == 0) {
2156                 TelSimPinType_t type = TAPI_SIM_PTYPE_PIN1;
2157                 TelSimPinStatus_t status = -1;
2158                 TEST_DEBUG("Get pin1 status");
2159
2160                 err_code = tel_get_sim_security_status(type, &status);
2161
2162                 if (err_code == TAPI_API_SUCCESS) {
2163
2164                         TEST_DEBUG(" *****************************************************");
2165                         switch (status) {
2166                         case TAPI_SIM_PIN_STATUS_DISABLED: {
2167                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_DISABLED ");
2168                         }
2169                                 break;
2170
2171                         case TAPI_SIM_PIN_STATUS_ENABLED: {
2172                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_ENABLED ");
2173                         }
2174                                 break;
2175
2176                         case TAPI_SIM_PIN_STATUS_BLOCKED: {
2177                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_BLOCKED ");
2178                         }
2179                                 break;
2180
2181                         case TAPI_SIM_PIN_STATUS_PUK_BLOCKED: {
2182                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_PUK_BLOCKED ");
2183                         }
2184                                 break;
2185
2186                         case TAPI_SIM_PIN_STATUS_UNKNOWN: {
2187                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_UNKNOWN ");
2188                         }
2189                                 break;
2190
2191                         default:
2192                                 TEST_DEBUG(" Default case statment: pin1_status(%d)", status)
2193                                 ;
2194                         }
2195                 } else {
2196                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2197                 }
2198
2199                 TEST_DEBUG("*****************************************************");
2200         }
2201         // get pin2 status
2202         else if (memcmp(buf, "getpin2", sizeof("getpin2") - 1) == 0) {
2203                 TelSimPinType_t type = TAPI_SIM_PTYPE_PIN2;
2204                 TelSimPinStatus_t status = -1;
2205                 TEST_DEBUG("Get pin2 status");
2206
2207                 err_code = tel_get_sim_security_status(type, &status);
2208
2209                 if (err_code == TAPI_API_SUCCESS) {
2210
2211                         TEST_DEBUG(" *****************************************************");
2212                         switch (status) {
2213                         case TAPI_SIM_PIN_STATUS_DISABLED: {
2214                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_DISABLED ");
2215                         }
2216                                 break;
2217
2218                         case TAPI_SIM_PIN_STATUS_ENABLED: {
2219                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_ENABLED ");
2220                         }
2221                                 break;
2222
2223                         case TAPI_SIM_PIN_STATUS_BLOCKED: {
2224                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_BLOCKED ");
2225                         }
2226                                 break;
2227
2228                         case TAPI_SIM_PIN_STATUS_PUK_BLOCKED: {
2229                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_PUK_BLOCKED ");
2230                         }
2231                                 break;
2232
2233                         case TAPI_SIM_PIN_STATUS_UNKNOWN: {
2234                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_UNKNOWN ");
2235                         }
2236                                 break;
2237
2238                         default:
2239                                 TEST_DEBUG(" Default case statment: pin2_status(%d)", status)
2240                                 ;
2241                         }
2242                 } else {
2243                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2244                 }
2245
2246                 TEST_DEBUG("*****************************************************");
2247         } else if (memcmp(buf, "getsim", sizeof("getsim") - 1) == 0) {
2248                 TelSimPinType_t type = TAPI_SIM_PTYPE_SIM;
2249                 TelSimPinStatus_t status = -1;
2250                 TEST_DEBUG("Get SIM LOCK status");
2251
2252                 err_code = tel_get_sim_security_status(type, &status);
2253
2254                 if (err_code == TAPI_API_SUCCESS) {
2255
2256                         TEST_DEBUG(" *****************************************************");
2257                         switch (status) {
2258                         case TAPI_SIM_PIN_STATUS_DISABLED: {
2259                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_DISABLED ");
2260                         }
2261                                 break;
2262
2263                         case TAPI_SIM_PIN_STATUS_ENABLED: {
2264                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_ENABLED ");
2265                         }
2266                                 break;
2267
2268                         case TAPI_SIM_PIN_STATUS_BLOCKED: {
2269                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_BLOCKED ");
2270                         }
2271                                 break;
2272
2273                         case TAPI_SIM_PIN_STATUS_PUK_BLOCKED: {
2274                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_PUK_BLOCKED ");
2275                         }
2276                                 break;
2277
2278                         case TAPI_SIM_PIN_STATUS_UNKNOWN: {
2279                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_UNKNOWN ");
2280                         }
2281                                 break;
2282
2283                         default:
2284                                 TEST_DEBUG(" Default case statment: sim_status(%d)", status)
2285                                 ;
2286                         }
2287                 } else {
2288                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2289                 }
2290
2291                 TEST_DEBUG("*****************************************************");
2292         }
2293         // Enable FDN
2294         else if (memcmp(buf, "enfdn", sizeof("enfdn") - 1) == 0) {
2295                 //puts("Flushing input - Enter \ to exit! ");
2296                 //while ((ch = getchar()) != '\n' && ch != EOF);
2297                 getchar();
2298
2299                 TEST_DEBUG("Enable FDN");
2300                 TEST_DEBUG("Plese input PIN2 CODE: ");
2301
2302                 int length = TAPI_SIM_PIN_LENGTH + 1;
2303                 char init_pin_val[length];
2304
2305                 _fgets(init_pin_val, 9);
2306
2307                 TelSimSecPw_t sec_data = { 0, };
2308                 sec_data.type = TAPI_SIM_PTYPE_PIN2; // 0x00
2309                 sec_data.pw_len = strlen(init_pin_val);
2310                 TEST_DEBUG("pw_len[%d]", sec_data.pw_len);
2311
2312                 sec_data.pw = (unsigned char*) malloc(length);
2313                 memcpy(sec_data.pw, init_pin_val, length);
2314
2315                 err_code = tel_enable_sim_fdn(sec_data.pw, (int *)&sec_data.pw_len,
2316                                 &request_id);
2317
2318                 if (err_code != TAPI_API_SUCCESS) {
2319                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2320                 }
2321         }
2322         // Disable FDN
2323         else if (memcmp(buf, "disfdn", sizeof("disfdn") - 1) == 0) {
2324                 getchar();
2325
2326                 TEST_DEBUG("Disable FDN");
2327                 TEST_DEBUG("Plese input PIN2 CODE");
2328
2329                 int length = TAPI_SIM_PIN_LENGTH + 1;
2330                 char init_pin_val[length];
2331
2332                 _fgets(init_pin_val, 9);
2333
2334                 TelSimSecPw_t sec_data = { 0, };
2335                 sec_data.type = TAPI_SIM_PTYPE_PIN2; // 0x00
2336                 sec_data.pw_len = strlen(init_pin_val);
2337                 TEST_DEBUG("pw_len[%d]", sec_data.pw_len);
2338
2339                 sec_data.pw = (unsigned char*) malloc(length);
2340                 memcpy(sec_data.pw, init_pin_val, length);
2341
2342                 err_code = tel_disable_sim_fdn(sec_data.pw, (int *)&sec_data.pw_len,
2343                                 &request_id);
2344
2345                 if (err_code != TAPI_API_SUCCESS) {
2346                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2347                 }
2348         }
2349         // get FDN status
2350         else if (memcmp(buf, "getfdn", sizeof("getfdn") - 1) == 0) {
2351                 TEST_DEBUG("Get FDN status");
2352                 int fdn_status = 0;
2353
2354                 err_code = tel_get_sim_fdn_status(&fdn_status);
2355
2356                 if (err_code == TAPI_API_SUCCESS) {
2357                         if (fdn_status == 0) {
2358                                 TEST_DEBUG("*************************");
2359                                 TEST_DEBUG("FDN disabled ");
2360                                 TEST_DEBUG("*************************");
2361                         } else {
2362                                 TEST_DEBUG("*************************");
2363                                 TEST_DEBUG("FDN enabled");
2364                                 TEST_DEBUG("*************************");
2365                         }
2366                 } else {
2367                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2368                 }
2369         } else if (memcmp(buf, "gettype", sizeof("gettype") - 1) == 0) {
2370                 TelSimCardType_t cardInfo;
2371                 TEST_DEBUG("Get card type !!!");
2372                 err_code = tel_get_sim_type(&cardInfo);
2373
2374                 if (err_code == TAPI_API_SUCCESS) {
2375                         TEST_DEBUG("*************************************************************");
2376                         __PrintCardType("", cardInfo);
2377                         TEST_DEBUG("*************************************************************");
2378                 } else {
2379                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2380                 }
2381         } else if (memcmp(buf, "getimsi", sizeof("getimsi") - 1) == 0) {
2382                 TelSimImsiInfo_t imsi;
2383                 TEST_DEBUG("Get IMSI type !!!");
2384                 err_code = tel_get_sim_imsi(&imsi);
2385
2386                 if (err_code == TAPI_API_SUCCESS) {
2387                         TEST_DEBUG("*************************************************************");
2388                         TEST_DEBUG("* imsi.bValid[%d]",imsi.bValid);
2389                         TEST_DEBUG("* imsi.szMcc[%s]",imsi.szMcc);
2390                         TEST_DEBUG("* imsi.szMnc[%s]",imsi.szMnc);
2391                         TEST_DEBUG("* imsi.szMsin[%s]",imsi.szMsin);
2392                         TEST_DEBUG("*************************************************************");
2393                 } else {
2394                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2395                 }
2396         } else if (memcmp(buf, "geticcid", sizeof("geticcid") - 1) == 0) {
2397                 TelSimIccIdInfo_t iccid;
2398                 TEST_DEBUG("Get ICCID  !!!");
2399                 err_code = tel_get_sim_iccid(&iccid);
2400                 int i = 0;
2401
2402                 if (err_code == TAPI_API_SUCCESS) {
2403                         TEST_DEBUG("*************************************************************");
2404                         TEST_DEBUG("* iccid.icc_length[%d]",iccid.icc_length);
2405                         for (i = 0; i < iccid.icc_length; i++) {
2406                                 TEST_DEBUG("* iccid.icc_num[%c]",iccid.icc_num[i]);
2407                         }
2408                         TEST_DEBUG("*************************************************************");
2409                 } else {
2410                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2411                 }
2412         }
2413
2414         else if (memcmp(buf, "getlang", sizeof("getlang") - 1) == 0) {
2415                 TEST_DEBUG("Language Preference INFO ");
2416                 int i;
2417                 TelSimLanguageInfo_t li_info = { 0, };
2418
2419                 err_code = tel_get_sim_language(&li_info);
2420
2421                 if (err_code == TAPI_API_SUCCESS) {
2422                         TEST_DEBUG(" ============================================");
2423                         TEST_DEBUG("************ LI  INFO ***********************");
2424                         TEST_DEBUG("LpCount: [%lu]", li_info.LpCount);
2425                         for (i = 0; i < li_info.LpCount; i++) {
2426                                 fprintf(stderr, "Loop(%d), ", i);
2427                                 __PrintLangInfo("LpCode: ", li_info.Lp[i]);
2428                         }
2429                         TEST_DEBUG("============================================");
2430                 } else {
2431                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2432                 }
2433         }
2434
2435         else if (memcmp(buf, "getecc", sizeof("getecc") - 1) == 0) {
2436                 TEST_DEBUG(" Get SIM ECC  ");
2437                 int ecc_rec_count = 0;
2438                 TelSimEccData_t ecc_info = { { { 0, } } };
2439                 TelSimEccInfo_t SimEccInfo = { { 0, } };
2440
2441                 err_code = tel_get_sim_ecc(&ecc_info, &ecc_rec_count);
2442
2443                 if (err_code == TAPI_API_SUCCESS) {
2444                         SimEccInfo = ecc_info.EccInfo;
2445                         TEST_DEBUG(" ============================================");
2446                         TEST_DEBUG(" EEC count [%d]", ecc_rec_count);
2447                         TEST_DEBUG(" ============================================");
2448
2449                         if (ecc_rec_count != 0) {
2450                                 TEST_DEBUG("ECC1 [%s]", SimEccInfo.szEcc1);
2451                                 TEST_DEBUG("ECC2 [%s]", SimEccInfo.szEcc2);
2452                                 TEST_DEBUG("ECC3 [%s]", SimEccInfo.szEcc3);
2453                                 TEST_DEBUG("ECC4 [%s]", SimEccInfo.szEcc4);
2454                                 TEST_DEBUG("ECC5 [%s]", SimEccInfo.szEcc5);
2455                         }
2456                         TEST_DEBUG(" ============================================");
2457                 } else {
2458                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2459                 }
2460         }
2461
2462         else if (memcmp(buf, "getuecc", sizeof("getuecc") - 1) == 0) {
2463                 int i = 0;
2464                 int uecc_rec_count = 0;
2465
2466                 TEST_DEBUG(" Get USIM ECC  ");
2467
2468                 TelSimEccData_t uecc_info = { { { 0, } } };
2469
2470                 err_code = tel_get_sim_ecc(&uecc_info, &uecc_rec_count);
2471
2472                 if (err_code == TAPI_API_SUCCESS) {
2473
2474                         TEST_DEBUG("ECC count [%d]",uecc_rec_count );
2475
2476                         for (i = 0; i < uecc_rec_count; i++) {
2477                                 TEST_DEBUG("Loop(%d): ", i);
2478                                 TEST_DEBUG(" ECC Used [%d]", uecc_info.UeccInfo[i].bUsed);
2479                                 TEST_DEBUG(" ECC Len [%d]", uecc_info.UeccInfo[i].EccLen);
2480
2481                                 if (NULL != uecc_info.UeccInfo[i].szEcc) {
2482                                         TEST_DEBUG("ECC string [%s]", uecc_info.UeccInfo[i].szEcc);
2483                                 } else {
2484                                         TEST_DEBUG("ECC string [null]");
2485                                 }
2486
2487                                 TEST_DEBUG("ECC alphaID [%s]",uecc_info.UeccInfo[i].szEccAlphaIdentifier);
2488                                 __PrintECCSvcInfo(uecc_info.UeccInfo[i].EccEmergencyServiceInfo);
2489                         }
2490
2491                 } else {
2492                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2493                 }
2494         }
2495
2496         else if (memcmp(buf, "getimsi", sizeof("getimsi") - 1) == 0) {
2497                 TEST_DEBUG("Get IMSI INFO ");
2498
2499                 TelSimImsiInfo_t sim_imsi_info;
2500
2501                 err_code = tel_get_sim_imsi(&sim_imsi_info);
2502
2503                 if (err_code == TAPI_API_SUCCESS) {
2504                         TEST_DEBUG(" ============================================");
2505                         TEST_DEBUG(" IMSI [mcc,mnc,msin]= ");
2506                         TEST_DEBUG(" [%s]",sim_imsi_info.szMcc);
2507                         TEST_DEBUG(" [%s]",sim_imsi_info.szMnc);
2508                         TEST_DEBUG(" [%s]",sim_imsi_info.szMsin);
2509                         TEST_DEBUG(" ============================================");
2510                 } else {
2511                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2512                 }
2513         }
2514
2515         else if (memcmp(buf, "getmb", sizeof("getmb") - 1) == 0) {
2516                 TEST_DEBUG("Get MAILBOX INFO ");
2517
2518                 TelSimMailboxNumbers_s mbox;
2519
2520                 err_code = tel_get_sim_mailbox_info(&mbox);
2521
2522                 if (err_code == TAPI_API_SUCCESS) {
2523                         TEST_DEBUG(" ============================================");
2524
2525                         if (mbox.b_cphs) {
2526                                 TEST_DEBUG("Current SIM is CPHS");
2527                         } else {
2528                                 TEST_DEBUG("Current SIM is not CPHS but 3GPP");
2529                         }
2530                         TEST_DEBUG(" ============================================");
2531                         TEST_DEBUG(" voice_line1.bUsed[%d]",mbox.voice_line1.bUsed);
2532                         TEST_DEBUG(" voice_line1.AlphaIdLength[%lu]",mbox.voice_line1.AlphaIdLength);
2533                         TEST_DEBUG(" voice_line1.AlphaId[%s]",mbox.voice_line1.AlphaId);
2534                         TEST_DEBUG(" voice_line1.DiallingnumLength[%lu]",mbox.voice_line1.DiallingnumLength);
2535                         TEST_DEBUG(" voice_line1.DiallingNum[%s]",mbox.voice_line1.DiallingNum);
2536                         TEST_DEBUG(" voice_line1.NumberingPlanIdent[%d]",mbox.voice_line1.NumberingPlanIdent);
2537                         TEST_DEBUG(" voice_line1.TypeOfNumber[%u]",mbox.voice_line1.TypeOfNumber);
2538                         TEST_DEBUG(" ============================================");
2539                         TEST_DEBUG(" voice_line2.bUsed[%d]",mbox.voice_line2.bUsed);
2540                         TEST_DEBUG(" voice_line2.AlphaIdLength[%lu]",mbox.voice_line2.AlphaIdLength);
2541                         TEST_DEBUG(" voice_line2.AlphaId[%s]",mbox.voice_line2.AlphaId);
2542                         TEST_DEBUG(" voice_line2.DiallingnumLength[%lu]",mbox.voice_line2.DiallingnumLength);
2543                         TEST_DEBUG(" voice_line2.DiallingNum[%s]",mbox.voice_line2.DiallingNum);
2544                         TEST_DEBUG(" voice_line2.NumberingPlanIdent[%d]",mbox.voice_line2.NumberingPlanIdent);
2545                         TEST_DEBUG(" voice_line2.TypeOfNumber[%d]",mbox.voice_line2.TypeOfNumber);
2546                         TEST_DEBUG(" ============================================");
2547                         TEST_DEBUG(" video.bUsed[%d]",mbox.video.bUsed);
2548                         TEST_DEBUG(" video.AlphaIdLength[%lu]",mbox.video.AlphaIdLength);
2549                         TEST_DEBUG(" video.AlphaId[%s]",mbox.video.AlphaId);
2550                         TEST_DEBUG(" video.DiallingnumLength[%lu]",mbox.video.DiallingnumLength);
2551                         TEST_DEBUG(" video.DiallingNum[%s]",mbox.video.DiallingNum);
2552                         TEST_DEBUG(" video.NumberingPlanIdent[%d]",mbox.video.NumberingPlanIdent);
2553                         TEST_DEBUG(" video.TypeOfNumber[%d]",mbox.video.TypeOfNumber);
2554                         TEST_DEBUG(" ============================================");
2555                         TEST_DEBUG(" fax.bUsed[%d]",mbox.fax.bUsed);
2556                         TEST_DEBUG(" fax.AlphaIdLength[%lu]",mbox.fax.AlphaIdLength);
2557                         TEST_DEBUG(" fax.AlphaId[%s]",mbox.fax.AlphaId);
2558                         TEST_DEBUG(" fax.DiallingnumLength[%lu]",mbox.fax.DiallingnumLength);
2559                         TEST_DEBUG(" fax.DiallingNum[%s]",mbox.fax.DiallingNum);
2560                         TEST_DEBUG(" fax.NumberingPlanIdent[%d]",mbox.fax.NumberingPlanIdent);
2561                         TEST_DEBUG(" fax.TypeOfNumber[%d]",mbox.fax.TypeOfNumber);
2562                         TEST_DEBUG(" ============================================");
2563                         TEST_DEBUG(" email.bUsed[%d]",mbox.email.bUsed);
2564                         TEST_DEBUG(" email.AlphaIdLength[%lu]",mbox.email.AlphaIdLength);
2565                         TEST_DEBUG(" email.AlphaId[%s]",mbox.email.AlphaId);
2566                         TEST_DEBUG(" email.DiallingnumLength[%lu]",mbox.email.DiallingnumLength);
2567                         TEST_DEBUG(" email.DiallingNum[%s]",mbox.email.DiallingNum);
2568                         TEST_DEBUG(" email.NumberingPlanIdent[%d]",mbox.email.NumberingPlanIdent);
2569                         TEST_DEBUG(" email.TypeOfNumber[%d]",mbox.email.TypeOfNumber);
2570                         TEST_DEBUG(" ============================================");
2571
2572                 } else {
2573                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2574                 }
2575         }
2576
2577         else if (memcmp(buf, "getmw", sizeof("getmw") - 1) == 0) {
2578                 TEST_DEBUG("Get MESSAGE WAITING INFO ");
2579
2580                 TelSimMessageWaiting_s mw;
2581
2582                 err_code = tel_get_sim_messagewaiting_info(&mw);
2583
2584                 if (err_code == TAPI_API_SUCCESS) {
2585                         TEST_DEBUG(" ============================================");
2586
2587                         if (mw.b_cphs) {
2588                                 TEST_DEBUG("Current SIM is CPHS");
2589                                 TEST_DEBUG(" ============================================");
2590                                 TEST_DEBUG(" cphs_mw.bWaitVoiceMsgLine1[%d]",mw.mw_data_u.cphs_mw.bWaitVoiceMsgLine1);
2591                                 TEST_DEBUG(" cphs_mw.bWaitVoiceMsgLine2[%d]",mw.mw_data_u.cphs_mw.bWaitVoiceMsgLine2);
2592                                 TEST_DEBUG(" cphs_mw.bWaitFaxMsg[%d]",mw.mw_data_u.cphs_mw.bWaitFaxMsg);
2593                                 TEST_DEBUG(" cphs_mw.bWaitDataMsg[%d]",mw.mw_data_u.cphs_mw.bWaitDataMsg);
2594
2595                         } else {
2596                                 TEST_DEBUG("Current SIM is not CPHS but 3GPP");
2597                                 TEST_DEBUG(" ============================================");
2598                                 TEST_DEBUG(" mw_data_u.mw.IndicatorType[0x%x]",mw.mw_data_u.mw.IndicatorType);
2599                                 TEST_DEBUG(" mw_data_u.mw.VoiceMailCount[%d]",mw.mw_data_u.mw.VoiceMailCount);
2600                                 TEST_DEBUG(" mw_data_u.mw.FaxCount[%d]",mw.mw_data_u.mw.FaxCount);
2601                                 TEST_DEBUG(" mw_data_u.mw.EmailCount[%d]",mw.mw_data_u.mw.EmailCount);
2602                                 TEST_DEBUG(" mw_data_u.mw.OtherCount[%d]",mw.mw_data_u.mw.OtherCount);
2603                                 TEST_DEBUG(" mw_data_u.mw.VideoMailCount[%d]",mw.mw_data_u.mw.VideoMailCount);
2604                         }
2605                         TEST_DEBUG(" ============================================");
2606
2607                 } else {
2608                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2609                 }
2610         }
2611
2612         else if (memcmp(buf, "getcf", sizeof("getcf") - 1) == 0) {
2613                 TEST_DEBUG("Get CALLFORWARDING INFO ");
2614
2615                 TelSimCallForwarding_s cf;
2616
2617                 err_code = tel_get_sim_callforwarding_info(&cf);
2618
2619                 if (err_code == TAPI_API_SUCCESS) {
2620                         TEST_DEBUG(" ============================================");
2621
2622                         if (cf.b_cphs) {
2623                                 TEST_DEBUG("Current SIM is CPHS");
2624                                 TEST_DEBUG(" ============================================");
2625                                 TEST_DEBUG(" cphs_cf.bCallForwardUnconditionalLine1[%d]",cf.cf_data_u.cphs_cf.bCallForwardUnconditionalLine1);
2626                                 TEST_DEBUG(" cphs_cf.bCallForwardUnconditionalLine2[%d]",cf.cf_data_u.cphs_cf.bCallForwardUnconditionalLine2);
2627                                 TEST_DEBUG(" cphs_cf.bCallForwardUnconditionalFax[%d]",cf.cf_data_u.cphs_cf.bCallForwardUnconditionalFax);
2628                                 TEST_DEBUG(" cphs_cf.bCallForwardUnconditionalData[%d]",cf.cf_data_u.cphs_cf.bCallForwardUnconditionalData);
2629                                 TEST_DEBUG(" cphs_cf.bCallForwardUnconditionalSms[%d]",cf.cf_data_u.cphs_cf.bCallForwardUnconditionalSms);
2630                                 TEST_DEBUG(" cphs_cf.bCallForwardUnconditionalBearer[%d]",cf.cf_data_u.cphs_cf.bCallForwardUnconditionalBearer);
2631                         } else {
2632                                 TEST_DEBUG("Current SIM is not CPHS but 3GPP");
2633                                 TEST_DEBUG(" ============================================");
2634                                 TEST_DEBUG(" cf.bUsed[%d]",cf.cf_data_u.cf.bUsed);
2635                                 TEST_DEBUG(" cf.MspNumber[%d]",cf.cf_data_u.cf.MspNumber);
2636                                 TEST_DEBUG(" cf.Status[0x%x]",cf.cf_data_u.cf.Status);
2637                                 TEST_DEBUG(" cf.DiallingnumLen[%lu]",cf.cf_data_u.cf.DiallingnumLen);
2638                                 TEST_DEBUG(" cf.TypeOfNumber[%d]",cf.cf_data_u.cf.TypeOfNumber);
2639                                 TEST_DEBUG(" cf.NumberingPlanIdent[%d]",cf.cf_data_u.cf.NumberingPlanIdent);
2640                                 TEST_DEBUG(" cf.DiallingNum[%s]",cf.cf_data_u.cf.DiallingNum);
2641                         }
2642                         TEST_DEBUG(" ============================================");
2643                 } else {
2644                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2645                 }
2646         }
2647
2648         else if (memcmp(buf, "getcphs", sizeof("getcphs") - 1) == 0) {
2649                 TEST_DEBUG("Get CPHS INFO ");
2650
2651                 TelSimCphsLocalInfo_t cphs;
2652
2653                 err_code = tel_get_sim_cphs_info(&cphs);
2654
2655                 if (err_code == TAPI_API_SUCCESS) {
2656                         TEST_DEBUG(" ============================================");
2657
2658                         if (cphs.b_used) {
2659                                 TEST_DEBUG("Current SIM is CPHS");
2660                                 TEST_DEBUG(" ============================================");
2661                                 TEST_DEBUG("cphs.cphsinfo.CphsPhase[%d]",cphs.cphsinfo.CphsPhase);
2662                                 TEST_DEBUG("cphs.cphsinfo.CphsServiceTable.bCustomerServiceProfile[%d]",cphs.cphsinfo.CphsServiceTable.bCustomerServiceProfile);
2663                                 TEST_DEBUG("cphs.cphsinfo.CphsServiceTable.bServiceStringTable[%d]",cphs.cphsinfo.CphsServiceTable.bServiceStringTable);
2664                                 TEST_DEBUG("cphs.cphsinfo.CphsServiceTable.bMailBoxNumbers[%d]",cphs.cphsinfo.CphsServiceTable.bMailBoxNumbers);
2665                                 TEST_DEBUG("cphs.cphsinfo.CphsServiceTable.bOperatorNameShortForm[%d]",cphs.cphsinfo.CphsServiceTable.bOperatorNameShortForm);
2666                                 TEST_DEBUG("cphs.cphsinfo.CphsServiceTable.bInformationNumbers[%d]",cphs.cphsinfo.CphsServiceTable.bInformationNumbers);
2667                                 TEST_DEBUG(" ============================================");
2668                                 TEST_DEBUG("cphs.csp.ServiceProfileEntry[0].CustomerServiceGroup[%d]",cphs.csp.ServiceProfileEntry[0].CustomerServiceGroup);
2669                                 TEST_DEBUG(" ============================================");
2670                                 TEST_DEBUG("cphs.infn.bUsed[%d]",cphs.infn.bUsed);
2671                                 TEST_DEBUG("cphs.infn.AlphaIdLength[%d]",cphs.infn.AlphaIdLength);
2672                                 TEST_DEBUG("cphs.infn.IndexLevelIndicator[%d]",cphs.infn.IndexLevelIndicator);
2673                                 TEST_DEBUG("cphs.infn.PremiumServiceIndicator[%d]",cphs.infn.PremiumServiceIndicator);
2674                                 TEST_DEBUG("cphs.infn.NetworkSpecificIndicator[%d]",cphs.infn.NetworkSpecificIndicator);
2675                                 TEST_DEBUG("cphs.infn.Alpha_id[%s]",cphs.infn.Alpha_id);
2676                                 TEST_DEBUG("cphs.infn.DiallingnumLength[%lu]",cphs.infn.DiallingnumLength);
2677                                 TEST_DEBUG("cphs.infn.TypeOfNumber[%d]",cphs.infn.TypeOfNumber);
2678                                 TEST_DEBUG("cphs.infn.NumberingPlanIdentity[%d]",cphs.infn.NumberingPlanIdentity);
2679                                 TEST_DEBUG("cphs.infn.DiallingNum[%s]",cphs.infn.DiallingNum);
2680                                 TEST_DEBUG("cphs.infn.Ext1RecordId[%d]",cphs.infn.Ext1RecordId);
2681                                 TEST_DEBUG(" ============================================");
2682                                 TEST_DEBUG("cphs.opname.NameLength[%d]",cphs.opname.NameLength);
2683                                 TEST_DEBUG("cphs.opname.OperatorName[%s]",cphs.opname.OperatorName);
2684                                 TEST_DEBUG(" ============================================");
2685                                 TEST_DEBUG("cphs.opshortform.ShortNameLength[%d]",cphs.opshortform.ShortNameLength);
2686                                 TEST_DEBUG("cphs.opshortform.OperatorShortName[%s]",cphs.opshortform.OperatorShortName);
2687                                 TEST_DEBUG(" ============================================");
2688                                 TEST_DEBUG("cphs.dflagsinfo.DynamicFlags[%d]",cphs.dflagsinfo.DynamicFlags);
2689                                 TEST_DEBUG(" ============================================");
2690                                 TEST_DEBUG("cphs.d2flagsinfo.Dynamic2Flag[%d]",cphs.d2flagsinfo.Dynamic2Flag);
2691                         } else {
2692                                 TEST_DEBUG("Current SIM is not CPHS but 3GPP");
2693                                 TEST_DEBUG(" ============================================");
2694
2695                         }
2696                         TEST_DEBUG(" ============================================");
2697                 } else {
2698                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2699                 }
2700
2701         } else if (memcmp(buf, "getmsisdn", sizeof("getmsisdn") - 1) == 0) {
2702                 TEST_DEBUG("Get MSISDN INFO ");
2703
2704                 TelSimSubscriberInfo_t msisdn;
2705
2706                 err_code = tel_get_sim_msisdn(&msisdn);
2707
2708                 if (err_code == TAPI_API_SUCCESS) {
2709                         TEST_DEBUG(" ============================================");
2710                         TEST_DEBUG("name[%s]",msisdn.name);
2711                         TEST_DEBUG("num[%s]",msisdn.num);
2712                         if (msisdn.name == '\0')
2713                                 TEST_DEBUG("name is null string");
2714
2715                         if (msisdn.num == '\0')
2716                                 TEST_DEBUG("number is null string");
2717                 } else {
2718                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2719                 }
2720         } else if (memcmp(buf, "pbinit", sizeof("pbinit") - 1) == 0) {
2721                 TEST_DEBUG("npbinit status");
2722
2723                 int valid_index = 0;
2724                 TelSimPbList_t pb_list = { 0, };
2725                 int pPbInitCompleted = 0;
2726
2727                 err_code = tel_get_sim_pb_init_info(&pPbInitCompleted, &pb_list,
2728                                 &valid_index);
2729
2730                 if (err_code == TAPI_API_SUCCESS) {
2731                         if (pPbInitCompleted == 0) {
2732                                 TEST_DEBUG(" SIM PB INIT NOT completed ");
2733                         } else {
2734                                 TEST_DEBUG("SIM PB INIT completed");
2735                                 /* if no sim records at all then valid_index = 0xFF */TEST_DEBUG("ADN First index is [%d]",valid_index);
2736                                 TEST_DEBUG("SIM phone book storage list Information ");
2737                                 TEST_DEBUG("********************************************");
2738                                 TEST_DEBUG("pb_list.b_fdn[%d]",pb_list.b_fdn);
2739                                 TEST_DEBUG("pb_list.b_msisdn[%d]",pb_list.b_msisdn);
2740                                 TEST_DEBUG("pb_list.b_adn[%d]",pb_list.b_adn);
2741                                 TEST_DEBUG("pb_list.b_sdn[%d]",pb_list.b_sdn);
2742                                 TEST_DEBUG("pb_list.b_3g[%d]",pb_list.b_3g);
2743                                 TEST_DEBUG("pb_list.b_aas[%d]",pb_list.b_aas);
2744                                 TEST_DEBUG("pb_list.b_gas[%d]",pb_list.b_gas);
2745
2746                                 /*
2747                                  if(pb_list & 0x01)
2748                                  TEST_DEBUG("ME dialed calls list stored in NV");
2749                                  if(pb_list & 0x02)
2750                                  TEST_DEBUG("SIM(or ME) emergency number");
2751                                  if(pb_list & 0x03)
2752                                  TEST_DEBUG("SIM fixed-dialing phonebook");
2753                                  if(pb_list & 0x04)
2754                                  TEST_DEBUG("SIM last-dialing phonebook");
2755                                  if(pb_list & 0x05)
2756                                  TEST_DEBUG("ME missed calls list");
2757                                  if(pb_list & 0x06)
2758                                  TEST_DEBUG("ME phonebook");
2759                                  if(pb_list & 0x07)
2760                                  TEST_DEBUG("Combined ME and SIM phonebook");
2761                                  if(pb_list & 0x08)
2762                                  TEST_DEBUG("SIM(or ME) own numbers ( MSISDNs) list");
2763                                  if(pb_list & 0x09)
2764                                  TEST_DEBUG("ME received calls list stored in NV");
2765                                  if(pb_list & 0x0A)
2766                                  TEST_DEBUG("2G SIM phonebook");
2767                                  if(pb_list & 0x0B)
2768                                  TEST_DEBUG("Service Dialing Number");
2769                                  if(pb_list & 0x0C)
2770                                  TEST_DEBUG("3G SIM phonebook");
2771                                  if(pb_list & 0x0D)
2772                                  TEST_DEBUG("Incoming Call Information");
2773                                  if(pb_list & 0x0E)
2774                                  TEST_DEBUG("Outgoing Call Information");
2775                                  if(pb_list & 0x0F)
2776                                  TEST_DEBUG("Additional Number Alpha String");
2777                                  if(pb_list & 0x10)
2778                                  TEST_DEBUG("Grouping Information Alpha String");
2779                                  */
2780                                 /*
2781                                  PB_DC  0x01    ME dialed calls list stored in NV
2782                                  PB_EN  0x02    SIM(or ME) emergency number
2783                                  PB_FD  0x03    SIM fixed-dialing phonebook
2784                                  PB_LD  0x04    SIM last-dialing phonebook
2785                                  PB_MC  0x05    ME missed calls list
2786                                  PB_ME  0x06    ME phonebook
2787                                  PB_MT  0x07    Combined ME and SIM phonebook
2788                                  PB_ON  0x08    SIM(or ME) own numbers ( MSISDNs) list
2789                                  PB_RC  0x09    ME received calls list stored in NV
2790                                  PB_SIM 0x0A    2G SIM phonebook
2791                                  PB_SDN 0x0B    Service Dialing Number
2792                                  PB_3GSIM       0x0C    3G SIM phonebook
2793                                  PB_ICI 0x0D    Incoming Call Information
2794                                  PB_OCI 0x0E    Outgoing Call Information
2795                                  PB_AAS 0x0F    Additional Number Alpha String
2796                                  PB_GAS 0x10    Grouping Information Alpha String
2797                                  */
2798
2799                                 TEST_DEBUG("********************************************");
2800                         }
2801                 } else {
2802                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2803                 }
2804
2805         }
2806
2807         //change pin1 number
2808         else if (memcmp(buf, "chpin1", sizeof("chpin1") - 1) == 0) {
2809                 int length = TAPI_SIM_PIN_LENGTH + 1;
2810                 char init_old_pin_val[length];
2811                 char init_new_pin_val[length];
2812
2813                 memset(&init_old_pin_val, 0, length);
2814                 memset(&init_new_pin_val, 0, length);
2815
2816                 TelSimSecPw_t old_pin = { 0, };
2817                 TelSimSecPw_t new_pin = { 0, };
2818
2819                 getchar();
2820
2821                 TEST_DEBUG("Change PIN1 CODE");
2822                 TEST_DEBUG("Input Current PIN1 Code: ");
2823
2824                 _fgets(init_old_pin_val, 9);
2825
2826                 old_pin.type = TAPI_SIM_PTYPE_PIN1; // 0x00
2827                 old_pin.pw_len = strlen(init_old_pin_val);
2828                 TEST_DEBUG("pw_len[%d]", old_pin.pw_len);
2829                 old_pin.pw = (unsigned char*) malloc(length);
2830                 memcpy(old_pin.pw, init_old_pin_val, length);
2831
2832                 TEST_DEBUG("Input New PIN1 Code: ");
2833
2834                 _fgets(init_new_pin_val, 9);
2835
2836                 new_pin.type = TAPI_SIM_PTYPE_PIN1; // 0x00
2837                 new_pin.pw_len = strlen(init_new_pin_val);
2838                 TEST_DEBUG("pw_len[%d]", new_pin.pw_len);
2839                 new_pin.pw = (unsigned char*) malloc(length);
2840                 memcpy(new_pin.pw, init_new_pin_val, length);
2841
2842                 err_code = tel_change_sim_pins(&old_pin, &new_pin, &request_id);
2843
2844                 if (err_code != TAPI_API_SUCCESS) {
2845                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2846                 }
2847         }
2848
2849         //change pin2 number
2850         else if (memcmp(buf, "chpin2", sizeof("chpin2") - 1) == 0) {
2851                 int length = TAPI_SIM_PIN_LENGTH + 1;
2852                 char init_old_pin_val[length];
2853                 char init_new_pin_val[length];
2854
2855                 memset(&init_old_pin_val, 0, length);
2856                 memset(&init_new_pin_val, 0, length);
2857
2858                 TelSimSecPw_t old_pin = { 0, };
2859                 TelSimSecPw_t new_pin = { 0, };
2860
2861                 getchar();
2862
2863                 TEST_DEBUG("Change PIN2 CODE");
2864                 TEST_DEBUG("Input Current PIN2 Code: ");
2865
2866                 _fgets(init_old_pin_val, 9);
2867
2868                 old_pin.type = TAPI_SIM_PTYPE_PIN2; // 0x00
2869                 old_pin.pw_len = strlen(init_old_pin_val);
2870                 TEST_DEBUG("pw_len[%d]", old_pin.pw_len);
2871                 old_pin.pw = (unsigned char*) malloc(length);
2872                 memcpy(old_pin.pw, init_old_pin_val, length);
2873
2874                 TEST_DEBUG("Input New PIN2 Code: ");
2875
2876                 _fgets(init_new_pin_val, 9);
2877
2878                 new_pin.type = TAPI_SIM_PTYPE_PIN2; // 0x00
2879                 new_pin.pw_len = strlen(init_new_pin_val);
2880                 TEST_DEBUG("pw_len[%d]", new_pin.pw_len);
2881                 new_pin.pw = (unsigned char*) malloc(length);
2882                 memcpy(new_pin.pw, init_new_pin_val, length);
2883
2884                 err_code = tel_change_sim_pins(&old_pin, &new_pin, &request_id);
2885
2886                 if (err_code != TAPI_API_SUCCESS) {
2887                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2888                 }
2889         }
2890
2891         // unblock CHV and enter new pin code
2892         else if (memcmp(buf, "puk1", sizeof("puk1") - 1) == 0) {
2893                 getchar();
2894
2895                 TEST_DEBUG("PUK1 verification");
2896
2897                 int length = TAPI_SIM_PIN_LENGTH + 1;
2898                 char init_pin_val[length];
2899                 char init_puk_val[length];
2900
2901                 TEST_DEBUG("Plese input PUK CODE: ");
2902
2903                 _fgets(init_puk_val, 9);
2904
2905                 TEST_DEBUG("NEW PIN1 CODE: ");
2906                 _fgets(init_pin_val, 9);
2907
2908                 TelSimSecPw_t puk_data = { 0, };
2909                 TelSimSecPw_t new_pin_data = { 0, };
2910
2911                 puk_data.type = TAPI_SIM_PTYPE_PUK1; // 0x00
2912                 puk_data.pw_len = strlen(init_puk_val);
2913                 TEST_DEBUG("pw_len[%d]", puk_data.pw_len);
2914                 puk_data.pw = (unsigned char*) malloc(length);
2915                 memcpy(puk_data.pw, init_puk_val, length);
2916
2917                 new_pin_data.type = TAPI_SIM_PTYPE_PIN1; // 0x00
2918                 new_pin_data.pw_len = strlen(init_pin_val);
2919                 TEST_DEBUG("pw_len[%d]", new_pin_data.pw_len);
2920                 new_pin_data.pw = (unsigned char*) malloc(length);
2921                 memcpy(new_pin_data.pw, init_pin_val, length);
2922
2923                 //  sim pin init
2924                 TEST_DEBUG("PUKtype Value %d",puk_data.type);
2925                 TEST_DEBUG("PUK Value %s",puk_data.pw);
2926                 TEST_DEBUG("New Pin Value %s",new_pin_data.pw);
2927
2928                 err_code = tel_verify_sim_puks(&puk_data, &new_pin_data, &request_id);
2929
2930                 if (err_code != TAPI_API_SUCCESS) {
2931                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2932                 }
2933         }
2934
2935         // unblock CHV2 and enter new pin2 code
2936         else if (memcmp(buf, "puk2", sizeof("puk2") - 1) == 0) {
2937                 getchar();
2938
2939                 TEST_DEBUG("PUK2 verification");
2940
2941                 int length = TAPI_SIM_PIN_LENGTH + 1;
2942                 char init_pin_val[length];
2943                 char init_puk_val[length];
2944
2945                 TEST_DEBUG("Plese input PUK2 CODE: ");
2946
2947                 _fgets(init_puk_val, 9);
2948
2949                 TEST_DEBUG("NEW PIN2 CODE: ");
2950                 _fgets(init_pin_val, 9);
2951
2952                 TelSimSecPw_t puk_data = { 0, };
2953                 TelSimSecPw_t new_pin_data = { 0, };
2954
2955                 puk_data.type = TAPI_SIM_PTYPE_PUK2; // 0x00
2956                 puk_data.pw_len = strlen(init_puk_val);
2957                 TEST_DEBUG("pw_len[%d]", puk_data.pw_len);
2958                 puk_data.pw = (unsigned char*) malloc(length);
2959                 memcpy(puk_data.pw, init_puk_val, length);
2960
2961                 new_pin_data.type = TAPI_SIM_PTYPE_PIN2; // 0x00
2962                 new_pin_data.pw_len = strlen(init_pin_val);
2963                 TEST_DEBUG("pw_len[%d]", new_pin_data.pw_len);
2964                 new_pin_data.pw = (unsigned char*) malloc(length);
2965                 memcpy(new_pin_data.pw, init_pin_val, length);
2966
2967                 //  sim pin init
2968                 TEST_DEBUG("PUKtype Value %d",puk_data.type);
2969                 TEST_DEBUG("PUK Value %s",puk_data.pw);
2970                 TEST_DEBUG("New Pin Value %s",new_pin_data.pw);
2971
2972                 err_code = tel_verify_sim_puks(&puk_data, &new_pin_data, &request_id);
2973
2974                 if (err_code != TAPI_API_SUCCESS) {
2975                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2976                 }
2977         }
2978
2979         else if (memcmp(buf, "mepers", sizeof("mepers") - 1) == 0) {
2980                 int tempi;
2981                 char dummy;
2982
2983                 TelSimPersPw_t lock_pers = { 0, };
2984
2985                 printf("------------------------------ \n");
2986                 printf("Personalization Type : \n");
2987                 printf("------------------------------ \n");
2988                 printf("1 - Network  \n");
2989                 printf("2 - Network Subset \n");
2990                 printf("3 - Service Provider \n");
2991                 printf("4 - Corporate \n");
2992                 printf("------------------------------ \n");
2993
2994                 printf("\nPlease input type: \n");
2995                 scanf("%d%c", &tempi, &dummy);
2996
2997                 switch (tempi) {
2998                 case 1: {
2999                         lock_pers.type = TAPI_SIM_PERS_NET;
3000                 }
3001                         break;
3002
3003                 case 2: {
3004                         lock_pers.type = TAPI_SIM_PERS_NS;
3005                 }
3006                         break;
3007
3008                 case 3: {
3009                         lock_pers.type = TAPI_SIM_PERS_SP;
3010                 }
3011                         break;
3012
3013                 case 4: {
3014                         lock_pers.type = TAPI_SIM_PERS_CP;
3015                 }
3016                         break;
3017
3018                 default: {
3019                         printf("wrong pers type! exit!\n");
3020                         exit(1);
3021                 }
3022                         break;
3023                 }
3024
3025                 switch (lock_pers.type) {
3026                 case TAPI_SIM_PERS_NET: {
3027                         puts("Flushing input - Enter \\n to exit! ");
3028
3029                         while ((ch = getchar()) != '\n' && ch != EOF)
3030                                 ;
3031
3032                         printf("Lock Personalisation MCC+MNC 5\n");
3033                         printf(
3034                                         "Plese input Network Lock CODE : length of MCC+MNC, MCC, MNC, NCK\n");
3035                         printf(
3036                                         "We need to use this for testing : length of MCC+MNC(5), MCC(450), MNC(01), NCK(12345678) => 54500112345678\n");
3037
3038                         int length = 14 + 1;
3039                         char init_password_val[length];
3040                         _fgets(init_password_val, 15);
3041
3042                         lock_pers.pw_len = 14;
3043                         lock_pers.pw = (unsigned char*) malloc(length);
3044                         memcpy(lock_pers.pw, init_password_val, length);
3045
3046                 }
3047                         break;
3048
3049                 case TAPI_SIM_PERS_NS: {
3050                         puts("Flushing input - Enter \\n to exit! ");
3051
3052                         while ((ch = getchar()) != '\n' && ch != EOF)
3053                                 ;
3054
3055                         printf(
3056                                         "Network Subset Personalisation MCC+MNC 5 byte, subset 2byte \n");
3057                         printf(
3058                                         "We need to use this for testing : length of MCC+MNC(5), MCC(450), MNC(01), lengthof NSP(2), NSP(11) NSPCK(12345678) => 54500121112345678\n");
3059
3060                         int length = 17 + 1;
3061                         char init_password_val[length];
3062                         _fgets(init_password_val, 18);
3063
3064                         lock_pers.pw_len = 17;
3065                         lock_pers.pw = (unsigned char*) malloc(length);
3066                         memcpy(lock_pers.pw, init_password_val, length);
3067                 }
3068                         break;
3069
3070                 case TAPI_SIM_PERS_SP: {
3071                         puts("Flushing input - Enter \\n to exit! ");
3072
3073                         while ((ch = getchar()) != '\n' && ch != EOF)
3074                                 ;
3075
3076                         printf(
3077                                         "Service Provider Personalisation MCC+MNC 5 byte, SP 2byte \n");
3078                         printf(
3079                                         "We need to use this for testing : length of MCC+MNC(5), MCC(450), MNC(01), SP(11) SPCK(12345678) => 5450011112345678\n");
3080
3081                         int length = 16 + 1;
3082                         char init_password_val[length];
3083                         _fgets(init_password_val, 17);
3084
3085                         lock_pers.pw_len = 16;
3086                         lock_pers.pw = (unsigned char*) malloc(length);
3087                         memcpy(lock_pers.pw, init_password_val, length);
3088                 }
3089                         break;
3090
3091                 case TAPI_SIM_PERS_CP: {
3092                         puts("Flushing input - Enter \\n to exit! ");
3093
3094                         while ((ch = getchar()) != '\n' && ch != EOF)
3095                                 ;
3096
3097                         printf(
3098                                         "Corporate Personalisation MCC+MNC 5 byte, SP 2byte CP 2byte \n");
3099                         printf(
3100                                         "We need to use this for testing : length of MCC+MNC(5), MCC(450), MNC(01), SP(11) CP(11) CPCK(12345678) => 545001111112345678\n");
3101
3102                         int length = 18 + 1;
3103                         char init_password_val[length];
3104                         _fgets(init_password_val, 19);
3105
3106                         lock_pers.pw_len = 18;
3107                         lock_pers.pw = (unsigned char*) malloc(length);
3108                         memcpy(lock_pers.pw, init_password_val, length);
3109                 }
3110                         break;
3111
3112                 default: {
3113                         printf("wrong condition exit\n");
3114                         exit(1);
3115                 }
3116                         break;
3117                 }
3118
3119                 err_code = tel_enable_sim_personalization(&lock_pers, &request_id);
3120                 printf("Error Code [%x]\n", err_code);
3121
3122         }
3123
3124         if (memcmp(buf, "medepers", sizeof("medepers") - 1) == 0) {
3125                 int tempi;
3126                 char dummy;
3127
3128                 TelSimPersPw_t lock_pers = { 0, };
3129
3130                 printf("------------------------------ \n");
3131                 printf("de-Personalization Type : \n");
3132                 printf("------------------------------ \n");
3133                 printf("1 - Network  \n");
3134                 printf("2 - Network Subset \n");
3135                 printf("3 - Service Provider \n");
3136                 printf("4 - Corporate \n");
3137                 printf("------------------------------ \n");
3138
3139                 printf("\nPlease input type: \n");
3140                 scanf("%d%c", &tempi, &dummy);
3141
3142                 switch (tempi) {
3143                 case 1: {
3144                         lock_pers.type = TAPI_SIM_PERS_NET;
3145                 }
3146                         break;
3147
3148                 case 2: {
3149                         lock_pers.type = TAPI_SIM_PERS_NS;
3150                 }
3151                         break;
3152
3153                 case 3: {
3154                         lock_pers.type = TAPI_SIM_PERS_SP;
3155                 }
3156                         break;
3157
3158                 case 4: {
3159                         lock_pers.type = TAPI_SIM_PERS_CP;
3160                 }
3161                         break;
3162
3163                 default: {
3164                         printf("wrong pers type! exit!\n");
3165                         exit(1);
3166                 }
3167                         break;
3168                 }
3169
3170                 puts("Flushing input - Enter \\n to exit! ");
3171
3172                 while ((ch = getchar()) != '\n' && ch != EOF)
3173                         ;
3174
3175                 printf("de Personalisation key is 8 byte \n");
3176                 printf("We need to use this for testing : 12345678\n");
3177
3178                 int length = 8 + 1;
3179                 char init_password_val[length];
3180                 _fgets(init_password_val, 9);
3181
3182                 lock_pers.pw_len = 8 /*control key*/;
3183                 lock_pers.pw = (unsigned char*) malloc(length);
3184                 memcpy(lock_pers.pw, init_password_val, length);
3185
3186                 err_code = tel_disable_sim_personalization(&lock_pers, &request_id);
3187
3188                 printf("Error Code [%x]\n", err_code);
3189
3190         }
3191
3192         if (memcmp(buf, "getpers", sizeof("getpers") - 1) == 0) {
3193                 int tempi = 0;
3194                 char dummy = 0;
3195
3196                 TelSimPersType_t type = 0;
3197
3198                 puts("Flushing input - Enter \\n to exit! ");
3199
3200                 while ((ch = getchar()) != '\n' && ch != EOF)
3201                         ;
3202
3203                 printf("getpers status\n");
3204                 printf("Here - 1\n");
3205                 printf(
3206                                 "================================================================ \n");
3207                 printf("TAPI_SIM_PERS_NET               = 0x00, /**< Network Lock */ \n");
3208                 printf("TAPI_SIM_PERS_NS                = 0x01, /**< Nettwork Subset Lock */\n");
3209                 printf("TAPI_SIM_PERS_SP                = 0x02, /**< Service Provider Lock */\n");
3210                 printf("TAPI_SIM_PERS_CP                = 0x03, /**< Coporate Lock */\n");
3211                 printf(
3212                                 "================================================================ \n");
3213                 printf("Plese input Lock type \n");
3214
3215                 scanf("%d%c", &tempi, &dummy);
3216                 type = tempi;
3217
3218                 err_code = tel_get_sim_personalization_status(type, &request_id);
3219                 printf("Error Code [%x]\n", err_code);
3220
3221         } else if (memcmp(buf, "setlang", sizeof("setlang") - 1) == 0) {
3222                 int tempi;
3223                 char dummy;
3224
3225                 TelSimLanguagePreferenceCode_t language = 0x00;
3226
3227                 printf("------------------------------ \n");
3228                 printf("select language which will be updated: \n");
3229                 printf("------------------------------ \n");
3230                 printf("should select inside here ( 0.DE / 1.EN / 2.IT / 3.FR ) \n");
3231                 printf(
3232                                 "should select inside here ( 4.SPANISH / 5.DUTCH / 6.SWEDISH / 7.DANISH ) \n");
3233                 printf(
3234                                 "should select inside here ( 8.PORTUGUESE / 9.FINNISH / 10.NORWEGIAN / 11.GREEK ) \n");
3235                 printf(
3236                                 "should select inside here ( 12.TURKISH / 13.HUNGARIAN / 14.POLISH / 15.KOREAN ) \n");
3237                 printf(
3238                                 "should select inside here ( 16.CHINESE / 17.RUSSIAN / 18.JAPANESE ) \n");
3239                 printf("------------------------------ \n");
3240
3241                 printf("\nPlease input type: \n");
3242                 scanf("%d%c", &tempi, &dummy);
3243
3244                 language = (TelSimLanguagePreferenceCode_t) tempi;
3245
3246                 err_code = tel_set_sim_language(language, &request_id);
3247
3248                 if (err_code == TAPI_API_SUCCESS) {
3249                         TEST_DEBUG("TAPI API SUCCESS");
3250                 } else {
3251                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3252                 }
3253
3254         } else if (memcmp(buf, "apdu", sizeof("apdu") - 1) == 0) {
3255                 printf("------------------------------ \n");
3256                 printf("APDU\n");
3257                 printf("------------------------------ \n");
3258
3259                 TelSimApdu_t apdu_data = { 0, };
3260
3261                 char tmp_apdu[4] = { 0x41, 0xC0, 0x05, 0x6f };
3262
3263                 apdu_data.apdu_len = 4;
3264                 apdu_data.apdu = (unsigned char*) &tmp_apdu;
3265
3266                 err_code = tel_req_sim_apdu(&apdu_data, &request_id);
3267
3268                 if (err_code == TAPI_API_SUCCESS) {
3269                         TEST_DEBUG("TAPI API SUCCESS");
3270                 } else {
3271                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3272                 }
3273
3274         } else if (memcmp(buf, "atr", sizeof("atr") - 1) == 0) {
3275                 printf("------------------------------ \n");
3276                 printf("ATR request: \n");
3277                 printf("------------------------------ \n");
3278
3279                 err_code = tel_req_sim_atr(&request_id);
3280
3281                 if (err_code == TAPI_API_SUCCESS) {
3282                         TEST_DEBUG("TAPI API SUCCESS");
3283                 } else {
3284                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3285                 }
3286
3287         }
3288
3289         ////////////////////////////////////////////////////////////////////////
3290         ///////////////////////  Phone Book ///////////////////////////////////
3291         ///////////////////////////////////////////////////////////////////////
3292         else if (memcmp(buf, "pbcapa", sizeof("pbcapa") - 1) == 0) {
3293                 TEST_DEBUG("PB capability info");
3294
3295                 err_code = tel_get_sim_pb_3g_meta_info(&request_id);
3296                 if (err_code != TAPI_API_SUCCESS) {
3297                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3298                 }
3299         }
3300
3301         else if (memcmp(buf, "pbcnt", sizeof("pbcnt") - 1) == 0) {
3302                 TEST_DEBUG("PB storage count info");
3303
3304                 TelSimPbFileType_t storage_type = __InputStorageType();
3305
3306                 __PrintStorageType(storage_type);
3307
3308                 err_code = tel_get_sim_pb_count(storage_type, &request_id);
3309
3310                 if (err_code != TAPI_API_SUCCESS) {
3311                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3312                 }
3313         }
3314
3315         else if (memcmp(buf, "pbentry", sizeof("pbentry") - 1) == 0) {
3316                 TEST_DEBUG("PB Entry info");
3317
3318                 TelSimPbFileType_t storage_type = __InputStorageType();
3319
3320                 err_code = tel_get_sim_pb_meta_info(storage_type, &request_id);
3321
3322                 if (err_code != TAPI_API_SUCCESS) {
3323                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3324                 }
3325         }
3326
3327         ///////////////////////////////////
3328         /*
3329          0x01 : ADD
3330          0x02 : DELETE
3331          0x03 : EDIT
3332          0x04 : WRITE (�ش� index�� data ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ unconditional write)
3333          0x05 : DELETE ALL (�ش� phone book id�� ï¿½ï¿½ï¿½ï¿½ ï¿½ï¿½ï¿½ï¿½ï¿½Ï´ï¿½ ï¿½ï¿½ï¿½ ï¿½ï¿½ï¿½ï¿½ï¿½Í¸ï¿½ delete)
3334          */
3335         else if (memcmp(buf, "pbadd", sizeof("pbadd") - 1) == 0) {
3336                 TelSimPbRecordData_t pb_add = { 0, };
3337                 char dummy;
3338                 char unicode_text[256];
3339                 int unicode_text_len = 0;
3340                 int index = 0;
3341
3342                 TelSimPbFileType_t storage_type = __InputStorageType();
3343                 pb_add.StorageFileType = storage_type;
3344
3345                 TEST_DEBUG("Plese input index : ");
3346                 scanf("%d%c", &index, &dummy);
3347                 pb_add.Index = index;
3348
3349                 if (pb_add.StorageFileType == TAPI_SIM_PB_EN || pb_add.StorageFileType
3350                                 == TAPI_SIM_PB_FDN || pb_add.StorageFileType
3351                                 == TAPI_SIM_PB_MSISDN || pb_add.StorageFileType
3352                                 == TAPI_SIM_PB_LDN || pb_add.StorageFileType == TAPI_SIM_PB_ADN
3353                                 || pb_add.StorageFileType == TAPI_SIM_PB_SDN) {
3354                         int tmpInput;
3355                         TEST_DEBUG("2g phone book entry");
3356
3357                         TEST_DEBUG(" Number Types are below ");
3358                         TEST_DEBUG(" 1 - INTERNATIONAL");
3359                         TEST_DEBUG(" 2 - NATIONAL");
3360                         TEST_DEBUG(" 3 - NETWORK");
3361                         TEST_DEBUG(" 4 - DEDICATE");
3362                         TEST_DEBUG("Select Numer Type: ");
3363
3364                         scanf("%d%c", &tmpInput, &dummy);
3365                         pb_add.ContactInfo.Pb2GData.NumType = tmpInput;
3366
3367                         TEST_DEBUG("Plese input contact number : ");
3368                         _fgets((char *) pb_add.ContactInfo.Pb2GData.Number, 15);
3369                         pb_add.ContactInfo.Pb2GData.NumLen = strlen(
3370                                         (char*) pb_add.ContactInfo.Pb2GData.Number);
3371
3372                         TEST_DEBUG(" Encryption Types are below ");
3373                         TEST_DEBUG(" 1 - ASCII - DO NOT SUPPORT");
3374                         TEST_DEBUG(" 2 - GSM7 Bit");
3375                         TEST_DEBUG(" 3 - UCS2");
3376                         TEST_DEBUG(" 4 - HEX - DO NOT SUPPORT");
3377                         TEST_DEBUG("Select Text Encryption Type: ");
3378
3379                         scanf("%d%c", &tmpInput, &dummy);
3380                         pb_add.ContactInfo.Pb2GData.NameEncryptType = tmpInput - 1;
3381
3382                         TEST_DEBUG("Plese input contact name : ");
3383                         _fgets((char *) pb_add.ContactInfo.Pb2GData.Name, 20);
3384
3385                         if (pb_add.ContactInfo.Pb2GData.NameEncryptType
3386                                         == TAPI_SIM_TEXT_ENC_UCS2) {
3387                                 TEST_DEBUG("TAPI_SIM_TEXT_ENC_UCS2 Encoding");
3388                                 /* unicode encoding */
3389                                 if (FALSE == __encode_text_unicode(
3390                                                 strlen((char *) pb_add.ContactInfo.Pb2GData.Name),
3391                                                 (char*) pb_add.ContactInfo.Pb2GData.Name,
3392                                                 (char *) &unicode_text_len, unicode_text)) {
3393                                         TEST_DEBUG("Encoding failed ! ");
3394
3395                                 } else {
3396                                         pb_add.ContactInfo.Pb2GData.NameLen = unicode_text_len;
3397                                         memcpy(pb_add.ContactInfo.Pb2GData.Name, unicode_text,
3398                                                         unicode_text_len);
3399                                 }
3400                         } else {
3401                                 pb_add.ContactInfo.Pb2GData.NameLen = strlen(
3402                                                 (char *) pb_add.ContactInfo.Pb2GData.Name);
3403                         }
3404                 } else if (pb_add.StorageFileType == TAPI_SIM_PB_3GSIM) {
3405                         int tempi;
3406                         char num_field_type;
3407                         int i = 0;
3408
3409                         TEST_DEBUG("3g phone book entry");
3410
3411                         TEST_DEBUG("Input Nuumber of fields to be entered: ");
3412
3413                         scanf("%d%c", &tempi, &dummy);
3414
3415                         num_field_type = tempi;
3416
3417                         pb_add.ContactInfo.Pb3GData.FileTypeCount = num_field_type;
3418
3419                         for (i = 0; i < num_field_type; i++) {
3420                                 TEST_DEBUG(" Field Types are below ");
3421                                 TEST_DEBUG(" 1 - Contact Name : (EF_ADN)");
3422                                 TEST_DEBUG(" 2 - Contact Mobile Number (EF_ADN)");
3423                                 TEST_DEBUG(" 3 - Contact Another Number (EF_ANR)");
3424                                 TEST_DEBUG(" 4 - Contact Email (EF_EMAIL)");
3425                                 TEST_DEBUG(" 5 - Contact Nick Name (EF_SNE)");
3426                                 TEST_DEBUG(" 6 - Contact Group (EF_GRP)");
3427                                 TEST_DEBUG(" 7 - Contact Hidden entry (EF_PBC) - NOT SUPPORT YET");
3428                                 TEST_DEBUG(" 8 - Contact Another Number A (EF_ANRA)");
3429                                 TEST_DEBUG(" 9 - Contact Another Number B (EF_ANRB)");
3430
3431                                 TEST_DEBUG("Select Field type: ");
3432
3433                                 scanf("%d%c", &tempi, &dummy);
3434
3435                                 pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileType = tempi;
3436
3437                                 if (tempi == 1 || tempi == 4 || tempi == 5 || tempi == 6) {
3438                                         TEST_DEBUG(" Encryption Types are below ");
3439                                         TEST_DEBUG(" 1 - ASCII");
3440                                         TEST_DEBUG(" 2 - GSM7 Bit");
3441                                         TEST_DEBUG(" 3 - UCS2");
3442                                         TEST_DEBUG(" 4 - HEX");
3443                                         TEST_DEBUG("Select Text Encryption Type: ");
3444
3445                                         scanf("%d%c", &tempi, &dummy);
3446                                         pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileDataType.EncryptionType
3447                                                         = tempi - 1;
3448
3449                                 } else {
3450                                         TEST_DEBUG(" Number Types are below ");
3451                                         TEST_DEBUG(" 1 - INTERNATIONAL");
3452                                         TEST_DEBUG(" 2 - NATIONAL");
3453                                         TEST_DEBUG(" 3 - NETWORK");
3454                                         TEST_DEBUG(" 4 - DEDICATE");
3455                                         TEST_DEBUG("Select Numer Type: ");
3456
3457                                         scanf("%d%c", &tempi, &dummy);
3458                                         pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileDataType.NumType
3459                                                         = tempi;
3460                                 }
3461
3462                                 if (pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileType
3463                                                 == TAPI_PB_3G_GRP) {
3464                                         int c, count, k = 0;
3465
3466                                         TEST_DEBUG("Please input number of index to add in GRP");
3467                                         scanf("%d%c", &tempi, &dummy);
3468
3469                                         count = tempi;
3470                                         for (c = 0; c < count; c++) {
3471                                                 TEST_DEBUG("Please input index of GRP: ");
3472                                                 scanf("%d%c", &tempi, &dummy);
3473
3474                                                 pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileData[k]
3475                                                                 = tempi;
3476                                                 k++;
3477                                                 //pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileData[k] = 0;
3478                                                 //k++;
3479                                         }
3480                                         pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileDataLength
3481                                                         = count;
3482                                 } else if (pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileType
3483                                                 == TAPI_PB_3G_NAME
3484                                                 || pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileType
3485                                                                 == TAPI_PB_3G_EMAIL
3486                                                 || pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileType
3487                                                                 == TAPI_PB_3G_SNE) {
3488                                         TEST_DEBUG("Plese input  field string data: ");
3489                                         _fgets(
3490                                                         (char *) pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileData,
3491                                                         30);
3492
3493                                         TEST_DEBUG("strlen about input data[%d]",strlen((char *)pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileData) );
3494
3495                                         if (pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileDataType.EncryptionType
3496                                                         == TAPI_SIM_TEXT_ENC_UCS2) {
3497                                                 /* unicode encoding */
3498                                                 if (FALSE
3499                                                                 == __encode_text_unicode(
3500                                                                                 strlen(
3501                                                                                                 (char *) pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileData),
3502                                                                                 (char *) pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileData,
3503                                                                                 (char *) &unicode_text_len,
3504                                                                                 unicode_text)) {
3505                                                         TEST_DEBUG("Encoding failed ! ");
3506                                                 } else {
3507                                                         memcpy(
3508                                                                         pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileData,
3509                                                                         unicode_text, unicode_text_len);
3510                                                         pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileDataLength
3511                                                                         = unicode_text_len;
3512                                                 }
3513                                         } else {
3514                                                 pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileDataLength
3515                                                                 = strlen(
3516                                                                                 (char *) pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileData);
3517                                         }
3518                                 } else {
3519                                         TEST_DEBUG("Plese input  field data: ");
3520                                         _fgets(
3521                                                         (char *) pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileData,
3522                                                         20);
3523                                         pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileDataLength
3524                                                         = strlen(
3525                                                                         (char *) pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileData);
3526                                 }
3527
3528                         }
3529
3530                 } else if (pb_add.StorageFileType == TAPI_SIM_PB_AAS
3531                                 || pb_add.StorageFileType == TAPI_SIM_PB_GAS) {
3532                         TEST_DEBUG("additional num Alpha string or Group Alpha string ");
3533
3534                         TEST_DEBUG("Plese input Alpha name : ");
3535                         _fgets(
3536                                         (char *) pb_add.ContactInfo.PbAdditionalNumStringData.TextData,
3537                                         20);
3538 #if 0
3539                         /* GSM 7bit conversion */
3540                         __encode_gsm_7_bit_chars(strlen((char *)pb_add.ContactInfo.PbAdditionalNumStringData.TextData) ,
3541                                         (char *)pb_add.ContactInfo.PbAdditionalNumStringData.TextData, (char *)&unicode_text_len, unicode_text);
3542
3543                         memcpy(pb_add.ContactInfo.PbAdditionalNumStringData.TextData, unicode_text, unicode_text_len );
3544
3545                         pb_add.ContactInfo.PbAdditionalNumStringData.TextLength = unicode_text_len;
3546
3547                         pb_add.ContactInfo.PbAdditionalNumStringData.EncryptionType = TAPI_SIM_TEXT_ENC_GSM7BIT; // always 2 for GAS and AAS
3548 #endif
3549                         pb_add.ContactInfo.PbAdditionalNumStringData.TextLength
3550                                         = strlen(
3551                                                         (char *) pb_add.ContactInfo.PbAdditionalNumStringData.TextData);
3552                         pb_add.ContactInfo.PbAdditionalNumStringData.EncryptionType
3553                                         = TAPI_SIM_TEXT_ENC_GSM7BIT; // But real type is ASCII (because current GSM7 is GSM7 with bit 8 set to '0')
3554
3555                 } else {
3556                         TEST_DEBUG("Undefined Storage File Type [0x%x]", pb_add.StorageFileType);
3557
3558                 }
3559
3560                 err_code = tel_update_sim_pb_record(&pb_add, &request_id);
3561
3562                 if (err_code != TAPI_API_SUCCESS) {
3563                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3564                 }
3565
3566         } else if (memcmp(buf, "pbdel", sizeof("pbdel") - 1) == 0) {
3567                 TelSimPbFileType_t storage_type = __InputStorageType();
3568
3569                 TEST_DEBUG(" PB delete ");
3570
3571                 unsigned short index = 0;
3572                 char dummy = 0;
3573                 TEST_DEBUG("Plese input index : ");
3574                 scanf("%d%c", (int *)&index, &dummy);
3575
3576                 err_code = tel_delete_sim_pb_record(storage_type, index, &request_id);
3577
3578                 if (err_code != TAPI_API_SUCCESS) {
3579                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3580                 }
3581
3582         } else if (memcmp(buf, "pbread", sizeof("pbread") - 1) == 0) {
3583                 TEST_DEBUG("PB read");
3584
3585                 unsigned short index = 0;
3586                 char dummy = 0;
3587
3588                 TelSimPbFileType_t storage_type = __InputStorageType();
3589
3590                 TEST_DEBUG("Plese input index : ");
3591                 scanf("%d%c", (int *)&index, &dummy);
3592
3593                 err_code = tel_read_sim_pb_record(storage_type, index, &request_id);
3594
3595                 if (err_code != TAPI_API_SUCCESS) {
3596                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3597                 }
3598         }
3599
3600         else if (memcmp(buf, "isimauth", sizeof("isimauth") - 1) == 0) {
3601                 TEST_DEBUG("ISIM Authentication ");
3602 #if 0
3603                 getchar();
3604
3605                 TelSimAuthenticationData_t auth_req = { 0, };
3606
3607                 memset(&auth_req, 0, sizeof(TelSimAuthenticationData_t));
3608
3609                 TEST_DEBUG(" Enter  RAND data ");
3610                 _fgets((char *) &auth_req.rand_data, 20);
3611
3612                 auth_req.rand_length
3613                                 = strlen((char *) auth_req.rand_data);
3614
3615                 TEST_DEBUG(" Enter Authentication  data ");
3616                 _fgets((char *) &auth_req.autn_data, 20);
3617
3618                 auth_req.autn_length = strlen((char *) auth_req.autn_data);
3619
3620                 TEST_DEBUG("TelTapiSimIsimAuthenticationRequest is not tested yet!");
3621                 /*
3622                  err_code = TelTapiSimIsimAuthenticationRequest( &auth_req, &request_id);
3623
3624                  if(err_code == TAPI_API_SUCCESS)
3625                  {
3626                  TEST_DEBUG("TAPI API SUCCESS");
3627                  }
3628                  else
3629                  {
3630                  TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3631                  }
3632                  */
3633 #endif
3634         }
3635
3636         else if (memcmp(buf, "sapcon", sizeof("sapcon") - 1) == 0) {
3637                 TEST_DEBUG("SAP Connect request  ");
3638                 TelSimSapConnect_t con_req = { 0, };
3639                 con_req.MsgId = TAPI_SIM_SAP_CONNECT_REQ;
3640                 con_req.MaxMsgSize = 10; //temp for testing only - not clear
3641
3642                 err_code = tel_req_sap_connection(&con_req, &request_id);
3643
3644                 if (err_code != TAPI_API_SUCCESS) {
3645                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3646                 }
3647         }
3648
3649         else if (memcmp(buf, "sapdiscon", sizeof("sapdiscon") - 1) == 0) {
3650                 TEST_DEBUG("SAP Disconnect request  ");
3651                 TelSimSapConnect_t con_req = { 0, };
3652                 con_req.MsgId = TAPI_SIM_SAP_DISCONNECT_REQ;
3653                 con_req.MaxMsgSize = 10; //temp for testing only - not clear
3654
3655                 err_code = tel_req_sap_connection(&con_req, &request_id);
3656
3657                 if (err_code != TAPI_API_SUCCESS) {
3658                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3659                 }
3660         }
3661
3662         else if (memcmp(buf, "sapstatus", sizeof("sapstatus") - 1) == 0) {
3663                 TEST_DEBUG("SAP Status request  ");
3664
3665                 err_code = tel_req_sap_connection_status(&request_id);
3666
3667                 if (err_code != TAPI_API_SUCCESS) {
3668                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3669                 }
3670         }
3671
3672         else if (memcmp(buf, "sapatr", sizeof("sapatr") - 1) == 0) {
3673                 TEST_DEBUG("SAP ATR request  ");
3674
3675                 err_code = tel_req_sap_transfer_atr(&request_id);
3676
3677                 if (err_code != TAPI_API_SUCCESS) {
3678                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3679                 }
3680         }
3681
3682         else if (memcmp(buf, "sapapdu", sizeof("sapapdu") - 1) == 0) {
3683                 TEST_DEBUG("SAP APDU transfer  ");
3684
3685                 int file_id = TAPI_SIM_EFILE_ICCID;
3686
3687                 /* for selecting EF ICCID */
3688                 TelSimSapApduData_t apdu_data;
3689
3690                 apdu_data.ApduLength = 7;
3691                 apdu_data.Apdu[0] = 0xA0; // class
3692                 apdu_data.Apdu[1] = 0xA4; // instruction
3693                 apdu_data.Apdu[2] = 0; // p1 = parameter 1
3694                 apdu_data.Apdu[3] = 0; // p2 = parameter 2
3695                 apdu_data.Apdu[4] = 2; // p3 - parameter 3
3696
3697                 memcpy(&apdu_data.Apdu[5], &file_id, sizeof(unsigned short));
3698
3699                 err_code = tel_req_sap_transfer_apdu(&apdu_data, &request_id);
3700
3701                 if (err_code == TAPI_API_SUCCESS) {
3702                         TEST_DEBUG("TAPI API SUCCESS");
3703                 } else {
3704                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3705                 }
3706         }
3707
3708         else if (memcmp(buf, "sapsetproto", sizeof("sapsetproto") - 1) == 0) {
3709                 TEST_DEBUG("SAP set protocol ");
3710                 TelSimSapProtocol_t protocol = TAPI_SIM_SAP_PROTOCOL_T0;
3711
3712                 err_code = tel_req_sap_transport_protocol(protocol, &request_id);
3713
3714                 if (err_code != TAPI_API_SUCCESS) {
3715                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3716                 }
3717         }
3718
3719         else if (memcmp(buf, "sapsimpwr", sizeof("sapsimpwr") - 1) == 0) {
3720                 int tempi = 0;
3721                 TelSimSapMsgId_t msdId = 0;
3722
3723                 char dummy = 0;
3724
3725                 TEST_DEBUG("SAP SIM power  ");
3726
3727                 TEST_DEBUG("Please input SAP SIM power on(1) / off(!1): ");
3728
3729                 scanf("%d%c", &tempi, &dummy);
3730                 if (tempi == 1)
3731                         msdId = TAPI_SIM_SAP_POWER_SIM_ON_REQ;
3732                 else
3733                         msdId = TAPI_SIM_SAP_POWER_SIM_OFF_REQ;
3734
3735                 err_code = tel_req_sap_power_operation(msdId, &request_id);// only for testing
3736
3737                 if (err_code != TAPI_API_SUCCESS) {
3738                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3739                 }
3740         }
3741
3742         if (memcmp(buf, "close", sizeof("close") - 1) == 0) {
3743                 TEST_DEBUG(" close reuqest ");
3744
3745                 //      err_code = tapi_sim_close(92);
3746
3747                 //err_code = tapi_sim_close(g_test_hsim);
3748                 TEST_DEBUG(" ret value from close [0x%x]", err_code);
3749
3750                 if (err_code == TAPI_API_SUCCESS) {
3751                         TEST_DEBUG(" sim close OK!");
3752                 } else {
3753                         TEST_DEBUG(" SIM close request returned error [0x%x] !",err_code );
3754                 }
3755                 TEST_DEBUG("Request ID [0x%x]", request_id);
3756         }
3757
3758         if (memcmp(buf, "q", sizeof("q") - 1) == 0) {
3759                 TEST_DEBUG("Finished Testing this module, Going back to Main Menu");
3760                 return -1;
3761                 //exit(0);
3762         }
3763
3764         return 0;
3765 }
3766
3767 void sim_select_loop(void) {
3768         int ret;
3769         fd_set readfds;
3770
3771         while (1) {
3772                 FD_ZERO(&readfds);
3773                 FD_SET(0, &readfds);
3774
3775                 ret = select(0 + 1, &readfds, NULL, NULL, NULL);
3776                 if (ret) {
3777
3778                         if (FD_ISSET(0, &readfds)) {
3779                                 if (sim_read_key_input() < 0)
3780                                         break;
3781                         }
3782                 }
3783         }
3784 }
3785
3786 void* sim_test_thread_loop(void* data) {
3787         TEST_DEBUG(" sim_test_thread_loop : called...");
3788
3789         sim_select_loop();
3790
3791         TEST_DEBUG(" sim_test_thread_loop : stdin Loop exited");
3792
3793         pthread_exit(NULL);
3794 }
3795
3796 int sim_main(int argc, char *argv[]) {
3797         pthread_t p_thread;
3798
3799         p_thread = pthread_create(&p_thread, NULL, sim_test_thread_loop, NULL);
3800
3801         if (p_thread != 0) {
3802                 TEST_DEBUG("Failed while creating a thread to read from stdin");
3803                 return -1;
3804         } else {
3805                 TEST_DEBUG("A thread was created to read from stdin ..");
3806         }
3807
3808         sim_test_subscribe_tapi_events();
3809
3810         pthread_join(p_thread, NULL);
3811
3812         TEST_DEBUG("Exiting sim test program bye bye !");
3813
3814         return 0;
3815 }
3816