d9cbe7902d04b6630b6dd682287d85598adcc452
[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_ISIM_AUTHENTICATION_CNF: {
1310                         TEST_DEBUG("*****************IMS Authentication **********************");
1311                         TelSimIsimAuthenticationResponse_t *auth_resp =
1312                                         (TelSimIsimAuthenticationResponse_t*) sim_event->pData;
1313
1314                         TEST_DEBUG("SIM ISIM authentication event status = [0x%x]", sim_event->Status);
1315
1316                         TEST_DEBUG(" auth resp data [%s]",auth_resp->ResponeData);
1317                         TEST_DEBUG("  auth string [%s]",auth_resp->AuthenticationString);
1318                         TEST_DEBUG(" auth cipher key [%s]",auth_resp->CipherKey);
1319                         TEST_DEBUG(" auth integrity key [%s]",auth_resp->IntegrityKey);
1320                 }
1321                         break;
1322
1323                 case TAPI_EVENT_SIM_SAP_CONNECT_CNF: {
1324                         TEST_DEBUG("*********** SAP CONNECT RESP *************");
1325
1326                         TelSimSapConnect_t *sap_conn_resp =
1327                                         (TelSimSapConnect_t*) sim_event->pData;
1328
1329                         TEST_DEBUG("SIM SAP connect request event status  = [0x%x]", sim_event->Status);
1330
1331                         TEST_DEBUG(" message id [0x%x]", sap_conn_resp->MsgId);
1332                         TEST_DEBUG("connection status [0x%x] ", sap_conn_resp->ConnectionStatus);
1333                         TEST_DEBUG("max message size [%d]", sap_conn_resp->MaxMsgSize);
1334
1335                         TEST_DEBUG("*****************************************");
1336                 }
1337                         break;
1338
1339                 case TAPI_EVENT_SIM_SAP_CONNECT_STATUS_CNF: {
1340                         TEST_DEBUG("*********** SAP CONNECT STATUS *************");
1341
1342                         TEST_DEBUG("SIM SAP connect event status = [0x%x]", sim_event->Status);
1343
1344                         TelSimSapStatusInfo_t *sap_conn_status =
1345                                         (TelSimSapStatusInfo_t*) sim_event->pData;
1346                         TEST_DEBUG(" connection status info [0x%x]", *sap_conn_status);
1347
1348                         TEST_DEBUG("*****************************************");
1349                 }
1350                         break;
1351
1352                 case TAPI_EVENT_SIM_SAP_TRANSFER_ATR_CNF: {
1353                         TEST_DEBUG("*********** SAP TRANSFER ATR *************");
1354
1355                         int i = 0;
1356                         TelSimSapAtrInfo_t *sap_transfer_atr =
1357                                         (TelSimSapAtrInfo_t*) sim_event->pData;
1358
1359                         TEST_DEBUG("SIM SAP trasfer ATR event status  = [0x%x]", sim_event->Status);
1360
1361                         TEST_DEBUG(" ATR result [0x%x]", sap_transfer_atr->AtrResult);
1362                         TEST_DEBUG(" ATR length [%lu]", sap_transfer_atr->AtrLength);
1363                         TEST_DEBUG(" ATR data ---> " );
1364                         for (i = 0; i < sap_transfer_atr->AtrLength; i++)
1365                                 TEST_DEBUG(" [0x%x]", sap_transfer_atr->AtrData[i]);
1366
1367                         TEST_DEBUG("*****************************************");
1368                 }
1369                         break;
1370
1371                 case TAPI_EVENT_SIM_SAP_TRANSFER_APDU_CNF: {
1372                         TEST_DEBUG("*********** SAP TRANSFER APDU *************");
1373
1374                         int i = 0;
1375                         TelSimSapApduData_t *sap_transfer_apdu =
1376                                         (TelSimSapApduData_t*) sim_event->pData;
1377
1378                         TEST_DEBUG("SIM SAP trasfer APDU event status  = [0x%x]", sim_event->Status);
1379
1380                         TEST_DEBUG(" APDU  length [0x%x]", sap_transfer_apdu->ApduLength);
1381                         TEST_DEBUG(" APDU  data ---> " );
1382                         for (i = 0; i < sap_transfer_apdu->ApduLength; i++)
1383                                 TEST_DEBUG(" [0x%x]", sap_transfer_apdu->Apdu[i]);
1384
1385                         TEST_DEBUG("*****************************************");
1386                 }
1387                         break;
1388
1389                 case TAPI_EVENT_SIM_SAP_SET_PROTOCOL_CNF: {
1390                         TEST_DEBUG("*********** SAP SET PROTOCOL  *************");
1391
1392                         TelSimSapProtocol_t *sap_result_code =
1393                                         (TelSimSapProtocol_t*) sim_event->pData;
1394
1395                         TEST_DEBUG("SIM SAP set protocol event status  = [0x%x]", sim_event->Status);
1396                         TEST_DEBUG("SAP SET protocol  result [0x%x]", *sap_result_code );
1397
1398                         TEST_DEBUG("*****************************************");
1399                 }
1400                         break;
1401
1402                 case TAPI_EVENT_SIM_SAP_SET_SIM_POWER_CNF: {
1403                         TEST_DEBUG("*********** SAP SET SIM POWER ON/OFF  *************");
1404
1405                         TelSimSapPower_t *sap_sim_power =
1406                                         (TelSimSapPower_t*) sim_event->pData;
1407
1408                         TEST_DEBUG("SIM SAP set SIM power  event status  = [0x%x]", sim_event->Status);
1409
1410                         TEST_DEBUG("message id [0x%x]", sap_sim_power->MsgId);
1411                         TEST_DEBUG(" sim power on/off result [0x%x]", sap_sim_power->SimPowerResult);
1412
1413                         TEST_DEBUG("*****************************************");
1414                 }
1415                         break;
1416
1417                 case TAPI_EVENT_SIM_SAP_CARD_READER_STATUS_CNF: {
1418                         TEST_DEBUG("*********** SAP CARD READER STATUS *************");
1419
1420                         TelSimCardReaderStatus_t *sap_card_reader_status =
1421                                         (TelSimCardReaderStatus_t*) sim_event->pData;
1422
1423                         TEST_DEBUG("SIM SAP card reader event status  = [0x%x]", sim_event->Status);
1424
1425                         TEST_DEBUG(" card reader result [0x%x] ", sap_card_reader_status->CardReaderResult);
1426                         TEST_DEBUG(" card reader status bitwise encoded data [%d]", sap_card_reader_status->CardReaderStatus);
1427
1428                         TEST_DEBUG("*****************************************");
1429                 }
1430                         break;
1431 #endif
1432
1433                         /******************************************************************************************************************************/
1434                         /*                                                                              NEW EVENT                                                                               */
1435                         /******************************************************************************************************************************/
1436                 case TAPI_EVENT_SIM_RSIM_ACCESS_CNF: {
1437                         TEST_DEBUG("********NEW*TAPI_EVENT_SIM_RSIM_ACCESS_CNF**********");
1438
1439                         TelSimReadFileRaw_t * rsim_resp =
1440                                         (TelSimReadFileRaw_t*) sim_event->pData;
1441
1442                         if (sim_event->Status == TAPI_SIM_ACCESS_SUCCESS) {
1443                                 TEST_DEBUG("rsim_resp->sw1[0x%x]", rsim_resp->sw1);
1444                                 TEST_DEBUG("rsim_resp->sw2[0x%x]", rsim_resp->sw2);
1445                                 TEST_DEBUG("rsim_resp->DataLen[%d]", rsim_resp->DataLen);
1446                                 TEST_DEBUG("rsim_resp->Data[%s]", rsim_resp->Data);
1447                         } else {
1448                                 TEST_DEBUG("OPERATION FAILED");
1449                         }
1450
1451                         TEST_DEBUG("********NEW*TAPI_EVENT_SIM_RSIM_ACCESS_CNF**********");
1452                 }
1453                         break;
1454
1455                 case TAPI_EVENT_SIM_VERIFY_SEC_CNF: {
1456                         TEST_DEBUG("********NEW*TAPI_EVENT_SIM_VERIFY_SEC_CNF**********");
1457
1458                         TelSimSecResult_t *pPinInfo = (TelSimSecResult_t*) sim_event->pData;
1459
1460                         //TEST_DEBUG("SIM Verify PIN event status = [0x%x]", sim_event->Status);
1461
1462                         if (sim_event->Status == TAPI_SIM_OPERATION_TIMEOUT) {
1463                                 TEST_DEBUG("TAPI SIM Operation Timeout!!");
1464                         } else if (sim_event->Status == TAPI_SIM_PIN_OPERATION_SUCCESS) {
1465                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN1) {
1466                                         TEST_DEBUG("PIN1 Verification Success!");
1467                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_SIM) {
1468                                         TEST_DEBUG("PIN1 Verification Success!");
1469                                 } else {
1470                                         TEST_DEBUG("PIN2 Vefication Success!");
1471                                 }
1472                         } else {
1473                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN1) {
1474                                         TEST_DEBUG("PIN1 Verification Failed! - PIN Required ");
1475                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1476                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PUK1) {
1477                                         TEST_DEBUG("PIN1 Verification Failed! - PUK Required ");
1478                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1479                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2) {
1480                                         TEST_DEBUG("PIN2 Verification Failed! - PIN2 Required ");
1481                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1482                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PUK2) {
1483                                         TEST_DEBUG("PIN2 Verification Failed! - PUK2 Required ");
1484                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1485                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_SIM) {
1486                                         TEST_DEBUG("SIM Lock Verification Failed! - SIM Lock code Required");
1487                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1488                                 }
1489                         }
1490                         TEST_DEBUG("********************************************");
1491                 }
1492                         break;
1493
1494                 case TAPI_EVENT_SIM_VERIFY_PUK_CNF: {
1495                         TEST_DEBUG("**********NEW*TAPI_EVENT_SIM_VERIFY_PUK_CNF********");
1496
1497                         TelSimSecResult_t *pPinInfo = (TelSimSecResult_t*) sim_event->pData;
1498
1499                         //TEST_DEBUG("SIM Unblock PIN event status = [0x%x]", sim_event->Status);
1500
1501                         if (sim_event->Status == TAPI_SIM_PIN_OPERATION_SUCCESS) {
1502                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN1) {
1503                                         TEST_DEBUG("Unblock PIN1 Success!");
1504                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2) {
1505                                         TEST_DEBUG("Unblock PIN2 Success!");
1506                                 }
1507                         } else {
1508                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN1) {
1509                                         TEST_DEBUG("PIN1 Verification Failed! - PIN Required ");
1510                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1511                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PUK1) {
1512                                         TEST_DEBUG("PIN1 Verification Failed! - PUK Required ");
1513                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1514                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2) {
1515                                         TEST_DEBUG("PIN2 Verification Failed! - PIN2 Required ");
1516                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1517                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PUK2) {
1518                                         TEST_DEBUG("PIN2 Verification Failed! - PUK2 Required ");
1519                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1520                                 }
1521                         }
1522                         TEST_DEBUG("********************************************");
1523                 }
1524                         break;
1525
1526                 case TAPI_EVENT_SIM_CHANGE_PINS_CNF: {
1527                         TEST_DEBUG("********NEW*TAPI_EVENT_SIM_CHANGE_PINS_CNF***************************");
1528
1529                         TelSimSecResult_t *pPinInfo = (TelSimSecResult_t*) sim_event->pData;
1530
1531                         //TEST_DEBUG("SIM Change PIN event status = [0x%x], pinType[%d]", sim_event->Status, pPinInfo->PinType);
1532                         TEST_DEBUG("PinType[%d]", pPinInfo->type);
1533
1534                         if (sim_event->Status == TAPI_SIM_PIN_OPERATION_SUCCESS) {
1535                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN1) {
1536                                         TEST_DEBUG("Change PIN1 Success!");
1537                                 } else {
1538                                         TEST_DEBUG("Change PIN2 Success!");
1539                                 }
1540                         } else {
1541                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN1) {
1542                                         TEST_DEBUG("PIN1 Verification Failed! - PIN Required ");
1543                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1544                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PUK1) {
1545                                         TEST_DEBUG("PIN1 Verification Failed! - PUK Required ");
1546                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1547                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2) {
1548                                         TEST_DEBUG("PIN2 Verification Failed! - PIN2 Required ");
1549                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1550                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PUK2) {
1551                                         TEST_DEBUG("PIN2 Verification Failed! - PUK2 Required ");
1552                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1553                                 }
1554                         }
1555                         TEST_DEBUG("********************************************");
1556                 }
1557                         break;
1558
1559                 case TAPI_EVENT_SIM_DISABLE_SEC_CNF: {
1560                         TEST_DEBUG("****************NEW*TAPI_EVENT_SIM_DISABLE_SEC_CNF****************");
1561
1562                         TelSimSecResult_t *pPinInfo = (TelSimSecResult_t*) sim_event->pData;
1563
1564                         //TEST_DEBUG("SIM Disable SEC event status = [0x%x]", sim_event->Status);
1565
1566                         if (sim_event->Status == TAPI_SIM_PIN_OPERATION_SUCCESS) {
1567                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN1) {
1568                                         TEST_DEBUG("Disable PIN1 Success!");
1569                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2) {
1570                                         TEST_DEBUG("Disable PIN2 Success!");
1571                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_SIM) {
1572                                         TEST_DEBUG("Disable SIM LOCK Success!");
1573                                 }
1574                         } else {
1575                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN1) {
1576                                         TEST_DEBUG("PIN1 Verification Failed! - PIN1Required ");
1577                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1578                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2) {
1579                                         TEST_DEBUG("PIN2 Verification Failed! - PIN2 Required ");
1580                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1581                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PUK1) {
1582                                         TEST_DEBUG("PIN1 Verification Failed! - PUK1 Required ");
1583                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1584                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PUK2) {
1585                                         TEST_DEBUG("PIN2 Verification Failed! - PUK2 Required ");
1586                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1587                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_SIM) {
1588                                         TEST_DEBUG("SIM LOCK Verification Failed! - SIM LOCK CODE Required ");
1589                                         TEST_DEBUG("Remainint attempts [%d] - Useless value", pPinInfo->retry_count);
1590                                 }
1591                         }
1592                         TEST_DEBUG("********************************************");
1593
1594                 }
1595                         break;
1596
1597                 case TAPI_EVENT_SIM_ENABLE_SEC_CNF: {
1598                         TEST_DEBUG("****************NEW*TAPI_EVENT_SIM_ENABLE_SEC_CNF****************");
1599
1600                         TelSimSecResult_t *pPinInfo = (TelSimSecResult_t*) sim_event->pData;
1601
1602                         //TEST_DEBUG("SIM ENABLE SEC event status = [0x%x]", sim_event->Status);
1603
1604                         if (sim_event->Status == TAPI_SIM_PIN_OPERATION_SUCCESS) {
1605                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN1) {
1606                                         TEST_DEBUG("Enable PIN1 Success!");
1607                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2) {
1608                                         TEST_DEBUG("Enable PIN2 Success!");
1609                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_SIM) {
1610                                         TEST_DEBUG("Enable SIM LOCK Success!");
1611                                 }
1612                         } else {
1613                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN1) {
1614                                         TEST_DEBUG("PIN1 Verification Failed! - PIN1Required ");
1615                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1616                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2) {
1617                                         TEST_DEBUG("PIN2 Verification Failed! - PIN2 Required ");
1618                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1619                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PUK1) {
1620                                         TEST_DEBUG("PIN1 Verification Failed! - PUK1 Required ");
1621                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1622                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PUK2) {
1623                                         TEST_DEBUG("PIN2 Verification Failed! - PUK2 Required ");
1624                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1625                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_SIM) {
1626                                         TEST_DEBUG("SIM LOCK Verification Failed! - SIM LOCK CODE Required ");
1627                                         TEST_DEBUG("Remainint attempts [%d] - Useless value", pPinInfo->retry_count);
1628                                 }
1629                         }
1630                         TEST_DEBUG("********************************************");
1631                 }
1632                         break;
1633
1634                 case TAPI_EVENT_SIM_DISABLE_FDNMODE_CNF: {
1635                         TEST_DEBUG("****************NEW*TAPI_EVENT_SIM_DISABLE_FDNMODE_CNF****************");
1636
1637                         TelSimSecResult_t *pPinInfo = (TelSimSecResult_t*) sim_event->pData;
1638
1639                         //TEST_DEBUG("SIM Disable FDN event status = [0x%x]", sim_event->Status);
1640
1641                         if (sim_event->Status == TAPI_SIM_PIN_OPERATION_SUCCESS) {
1642                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2) {
1643                                         TEST_DEBUG("Disable FDN Success!");
1644                                 } else {
1645                                         TEST_DEBUG("Unhandled type[%d]", pPinInfo->type);
1646                                 }
1647                         } else {
1648                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2) {
1649                                         TEST_DEBUG("PIN2 Verification Failed! - PIN2 Required ");
1650                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1651                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PUK2) {
1652                                         TEST_DEBUG("PIN2 Verification Failed! - PUK2 Required ");
1653                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1654                                 } else {
1655                                         TEST_DEBUG("Unhandled type[%d]", pPinInfo->type);
1656                                 }
1657                         }
1658                         TEST_DEBUG("********************************************");
1659                 }
1660                         break;
1661
1662                 case TAPI_EVENT_SIM_ENABLE_FDNMODE_CNF: {
1663                         TEST_DEBUG("****************NEW*TAPI_EVENT_SIM_ENABLE_FDNMODE_CNF****************");
1664
1665                         TelSimSecResult_t *pPinInfo = (TelSimSecResult_t*) sim_event->pData;
1666
1667                         //TEST_DEBUG("SIM Enable FDN event status = [0x%x]", sim_event->Status);
1668
1669                         if (sim_event->Status == TAPI_SIM_PIN_OPERATION_SUCCESS) {
1670                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2) {
1671                                         TEST_DEBUG("Enable FDN Success!");
1672                                 } else {
1673                                         TEST_DEBUG("Unhandled type[%d]", pPinInfo->type);
1674                                 }
1675                         } else {
1676                                 if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2) {
1677                                         TEST_DEBUG("PIN2 Verification Failed! - PIN2 Required ");
1678                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1679                                 } else if (pPinInfo->type == TAPI_SIM_PTYPE_PUK2) {
1680                                         TEST_DEBUG("PIN2 Verification Failed! - PUK2 Required ");
1681                                         TEST_DEBUG("Remainint attempts [%d]", pPinInfo->retry_count);
1682                                 } else {
1683                                         TEST_DEBUG("Unhandled type[%d]", pPinInfo->type);
1684                                 }
1685                         }
1686                         TEST_DEBUG("********************************************");
1687                 }
1688                         break;
1689
1690                 case TAPI_EVENT_SIM_PERS_STATUS_CNF: {
1691                         TelSimPersStatus_t* pers_status =
1692                                         (TelSimPersStatus_t*) sim_event->pData;
1693
1694                         printf(
1695                                         "[SIM APP]**********NEW* TAPI_EVENT_SIM_PERS_STATUS_CNF************\n");
1696                         printf("[SIM APP]SIM lock personalisation event status = [%x]\n",
1697                                         sim_event->Status);
1698                         printf(
1699                                         "[SIM APP]SIM lock personalisation status - net0-ns1-sp2-cp3  = [%d]\n",
1700                                         pers_status->type);
1701                         printf(
1702                                         "[SIM APP]SIM lock personalisation status - unlock0-lock1  = [%d]\n",
1703                                         pers_status->mode);
1704                         printf(
1705                                         "[SIM APP]***************************************************\n");
1706                 }
1707                         break;
1708
1709                 case TAPI_EVENT_SIM_DISABLE_PERS_CNF: {
1710                         TelSimPinOperationResult_t opResult =
1711                                         (TelSimPinOperationResult_t) sim_event->Status;
1712
1713                         printf(
1714                                         "[SIM APP]*********NEW*TAPI_EVENT_SIM_DISABLE_PERS_CNF************\n");
1715                         printf("[SIM APP]Eable Personalization event status = [%x]\n",
1716                                         opResult);
1717
1718                         if (opResult == TAPI_SIM_PIN_OPERATION_SUCCESS) {
1719                                 printf("[SIM APP]Disable Personalization Success!\n");
1720                         } else {
1721                                 printf(
1722                                                 "[SIM APP]Verification Failed! - Correct Password Required\n");
1723                         }
1724                         printf(
1725                                         "\n***************************************************************\n");
1726                 }
1727                         break;
1728
1729                 case TAPI_EVENT_SIM_ENABLE_PERS_CNF: {
1730                         TelSimPinOperationResult_t opResult =
1731                                         (TelSimPinOperationResult_t) sim_event->Status;
1732
1733                         printf(
1734                                         "[SIM APP]*********NEW*TAPI_EVENT_SIM_ENABLE_PERS_CNF************\n");
1735                         printf("[SIM APP]Eable Personalization event status = [%x]\n",
1736                                         opResult);
1737
1738                         if (opResult == TAPI_SIM_PIN_OPERATION_SUCCESS) {
1739                                 printf("[SIM APP]Enable Personalization Success!\n");
1740                         } else {
1741                                 printf(
1742                                                 "[SIM APP]Verification Failed! - Correct Password Required\n");
1743                         }
1744                         printf(
1745                                         "\n***************************************************************\n");
1746                 }
1747                         break;
1748
1749                 case TAPI_EVENT_SIM_SET_LANGUAGE_CNF: {
1750                         TEST_DEBUG("*********NEW*TAPI_EVENT_SIM_SET_LANGUAGE_CNF************");
1751                         TEST_DEBUG("update event status = [0x%x]", sim_event->Status);
1752                         TEST_DEBUG("**********************************************************");
1753                 }
1754                         break;
1755
1756                 case TAPI_EVENT_SIM_APDU_CNF: {
1757                         TelSimApduResp_t* apdu_resp = (TelSimApduResp_t*) sim_event->pData;
1758                         int i = 0;
1759                         TEST_DEBUG("*********NEW*TAPI_EVENT_SIM_APDU_CNF************");
1760                         TEST_DEBUG("update event status = [0x%x]", sim_event->Status);
1761
1762                         if (sim_event->Status == 1234) {
1763                                 TEST_DEBUG("timeout happended. this means, modem didn`t reply");
1764                                 return;
1765                         }
1766
1767                         if (apdu_resp != NULL) {
1768                                 TEST_DEBUG("apdu_resp->apdu_resp_len[%d]",apdu_resp->apdu_resp_len);
1769
1770                                 for (i = 0; i < apdu_resp->apdu_resp_len; i++)
1771                                         TEST_DEBUG("apdu_resp->apdu_resp[%d]=[0x%x]",i,apdu_resp->apdu_resp[i]);
1772
1773                         } else {
1774                                 TEST_DEBUG("atr_resp == NULL");
1775                         }
1776                         TEST_DEBUG("**********************************************************");;
1777                 }
1778                         break;
1779
1780                 case TAPI_EVENT_SIM_ATR_CNF: {
1781                         TelSimAtrResp_t* atr_resp = (TelSimAtrResp_t*) sim_event->pData;
1782                         int i = 0;
1783
1784                         TEST_DEBUG("*********NEW*TAPI_EVENT_SIM_ATR_CNF************");
1785                         TEST_DEBUG("update event status = [0x%x]", sim_event->Status);
1786
1787                         if (sim_event->Status == 1234) {
1788                                 TEST_DEBUG("timeout happended. this means, modem didn`t reply");
1789                                 return;
1790                         }
1791
1792                         if (atr_resp != NULL) {
1793                                 TEST_DEBUG("atr_resp->atr_resp_len[%d]",atr_resp->atr_resp_len);
1794
1795                                 for (i = 0; i < atr_resp->atr_resp_len; i++)
1796                                         TEST_DEBUG("atr_resp->atr_resp[%d]=[0x%x]",i,atr_resp->atr_resp[i]);
1797                         } else {
1798                                 TEST_DEBUG("atr_resp == NULL");
1799                         }
1800                         TEST_DEBUG("**********************************************************");
1801                 }
1802                         break;
1803
1804 #if 0
1805
1806                         case TAPI_SIM_EVENT_PB_GET_STORAGE_LIST:
1807                         {
1808                                 TEST_DEBUG("****************TAPI_SIM_EVENT_PB_GET_STORAGE_LIST****************************");
1809                                 char *p = (char*)&sim_event->pData;
1810
1811                                 TEST_DEBUG("SIM phone book storage list Information ");
1812                                 if(*p & 0x01)
1813                                 TEST_DEBUG("IPC_PB_STORAGE_TYPE_DC - ME Dailled Call list");
1814                                 if(*p & 0x02)
1815                                 TEST_DEBUG("IPC_PB_STORAGE_TYPE_EN - Emergency Number");
1816                                 if(*p & 0x03)
1817                                 TEST_DEBUG("IPC_PB_STORAGE_TYPE_FD - Fixed dialing phonebook");
1818                                 if(*p & 0x04)
1819                                 TEST_DEBUG("IPC_PB_STORAGE_TYPE_LD - Last dialled phonebook");
1820                                 if(*p & 0x05)
1821                                 TEST_DEBUG("IPC_PB_STORAGE_TYPE_MC -Missed call list");
1822                                 if(*p & 0x06)
1823                                 TEST_DEBUG("IPC_PB_STORAGE_TYPE_ME - ME phone book");
1824                                 if(*p & 0x07)
1825                                 TEST_DEBUG("IPC_PB_STORAGE_TYPE_MT - ME and sim combined phone book");
1826                                 if(*p & 0x08)
1827                                 TEST_DEBUG("IPC_PB_STORAGE_TYPE_ON - My own number - MSISDN");
1828                                 if(*p & 0x09)
1829                                 TEST_DEBUG("IPC_PB_STORAGE_TYPE_RC - ME Received calls");
1830                                 if(*p & 0x0A)
1831                                 TEST_DEBUG("IPC_PB_STORAGE_TYPE_SIM - SIM phone book");
1832                                 if(*p & 0x0B)
1833                                 TEST_DEBUG("IPC_PB_STORAGE_TYPE_SDN - Service dailing number");
1834
1835                                 TEST_DEBUG("********************************************");
1836                         }
1837                         break;
1838 #endif
1839
1840                 default:
1841                         TEST_DEBUG("Undhandled event type [0x%x]",sim_event->EventType)
1842                         ;
1843                 }
1844                 printf("\n");
1845         }//end switch (Type)
1846         else {
1847                 TEST_DEBUG("Undhandled EventClass [0x%x]",sim_event->EventClass);
1848         }
1849         return;
1850
1851 }// end func
1852
1853
1854 int sim_read_key_input(void) {
1855         char buf[256] = { 0, };
1856         int ret = 0;
1857         TapiResult_t err_code = TAPI_API_SUCCESS;
1858         char ch;
1859
1860         ret = read(0, buf, sizeof(buf));
1861
1862         if (ret < 0) {
1863                 if (errno == EINTR)
1864                         perror("read(1)");
1865                 return -1;
1866
1867         } else if (ret == 0)
1868                 return ret;
1869
1870         printf("************************************\n");
1871         printf("op : show all OP | q : quit sim test app \n");
1872         printf("************************************\n");
1873         printf("SIM OP in : %s\n", buf);
1874
1875         if (memcmp(buf, "op", sizeof("op") - 1) == 0) {
1876                 printf("***************************** NEW Asynchronous APIs *******************************\n");
1877                 printf("rsim : rsim \n");
1878                 printf("pin1 : verify pin1 number \n");
1879                 printf("pin2 : verify pin2 number\n");
1880                 printf("sim : verify sim lock number\n");
1881                 printf("puk1 : Unblocking CHV1 \n");
1882                 printf("puk2 : Unblocking CHV2 \n");
1883                 printf("chpin1 : change pin1 number \n");
1884                 printf("chpin2 : change pin2 number \n");
1885                 printf("enpin : CHV enable\n");
1886                 printf("dispin : CHV disable\n");
1887                 printf("enfdn : FDN enable\n");
1888                 printf("disfdn : FDN disable\n");
1889                 printf("ensim : enable sim lock\n");
1890                 printf("dissim : disable sim lock\n");
1891                 printf("getpers : Get lock personalisation information \n");
1892                 printf("medepers : de-personalization test\n");
1893                 printf("mepers : personalization test\n");
1894                 printf("setlang : update sim language info\n");
1895                 printf("apdu : send apdu\n");
1896                 printf("atr : request atr\n");
1897                 printf("***************************** Synchronous APIs *******************************\n");
1898                 printf("siminit : Get SIM init Information\n");
1899                 printf("getpin1 : Get CHV1 status info\n");
1900                 printf("getfdn : Get FDN status info\n");
1901                 printf("getpin2 : Get CHV2 status Info \n");
1902                 printf("getsim : Get CHV2 status Info \n");
1903                 printf("gettype : show Sim Card Type\n");
1904                 printf("getimsi : show Sim IMSI\n");
1905                 printf("geticcid : show Sim ICCID\n");
1906                 printf("getlang:Language Indication Info\n");
1907                 printf("getecc : get SIM ECC\n");
1908                 printf("getuecc : get USIM ECC\n");
1909                 printf("getmb : get mailbox number\n");
1910                 printf("getmw : get message waiting information\n");
1911                 printf("getcf : get callforwarding information\n");
1912                 printf("getcphs : get cphs information\n");
1913                 printf("getmsisdn : get msisdn information\n");
1914                 printf("******************************* PHONE BOOK ***********************************\n");
1915                 printf("pbinit : Get pb init info\n");
1916                 printf("pbcapa : pb capability info \n");
1917                 printf("pbcnt : phonebook used and total count\n");
1918                 printf("pbentry : phonebook entry info\n");
1919                 printf("pbadd : phonebook add\n");
1920                 printf("pbdel : phonebook delete\n");
1921                 printf("pbread:phonebook read\n");
1922                 //              printf("****************************** SAP commands **********************************\n");
1923                 //              printf("sapconnect: SAP Connect request\n");
1924                 //              printf("sapstatus : SAP current connection status request \n");
1925                 //              printf("sapatr: SAP transfer atr request\n");
1926                 //              printf("sapapdu: SAP transfer apdu request\n");
1927                 //              printf("sapsetproto: SAP set protocol request\n");
1928                 //              printf("sapsimpwr: SAP SIM power on/off request\n");
1929                 //              printf("sapreaderstat: SAP card reader status request\n");
1930                 //              printf("*****************************************************************************\n");
1931         }
1932
1933         /*NEW API -START*/
1934         if (memcmp(buf, "siminit", sizeof("siminit") - 1) == 0) {
1935                 TelSimCardStatus_t status = 0x00;
1936                 int b_card_changed = 0;
1937
1938                 err_code = tel_get_sim_init_info(&status, &b_card_changed);
1939
1940                 if (err_code == TAPI_API_SUCCESS) {
1941                         TEST_DEBUG("*************************************************************");
1942                         __PrintCardStatus("CardStatus: ", status);
1943                         TEST_DEBUG("b_card_changed[%d]\n",b_card_changed);
1944                         TEST_DEBUG("*************************************************************");
1945                 } else {
1946                         TEST_DEBUG("TAPI Fail: Error Code [%d]\n",err_code);
1947                 }
1948         } else if (memcmp(buf, "rsim", sizeof("rsim") - 1) == 0) {
1949                 TEST_DEBUG("rsim....");
1950
1951                 TelSimRSimReq_t rsim = { 0, };
1952
1953                 rsim.file_id = 0x6F60;
1954                 rsim.rsim_cmd = TAPI_SIM_GET_RESPONSE;
1955
1956                 err_code = tel_req_sim_access((const TelSimRSimReq_t*) &rsim,
1957                                 &request_id);
1958                 if (err_code != TAPI_API_SUCCESS) {
1959                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
1960                 }
1961         } else if (memcmp(buf, "pin1", sizeof("pin1") - 1) == 0) {
1962                 TEST_DEBUG("Pin1 Verification");
1963                 int length = TAPI_SIM_PIN_LENGTH + 1;
1964                 char init_pin_val[TAPI_SIM_PIN_LENGTH + 1];
1965
1966                 getchar();
1967
1968                 TEST_DEBUG(" PUT PIN1 CODE: ");
1969
1970                 _fgets(init_pin_val, 9);
1971
1972                 TelSimSecPw_t pin_data = { 0, };
1973
1974                 pin_data.type = TAPI_SIM_PTYPE_PIN1; // 0x00
1975                 pin_data.pw_len = strlen(init_pin_val);
1976
1977                 TEST_DEBUG("pw_len[%d]", pin_data.pw_len);
1978
1979                 pin_data.pw = (unsigned char*) malloc(length);
1980                 memcpy(pin_data.pw, init_pin_val, length);
1981
1982                 err_code = tel_verifiy_sim_pins(&pin_data, &request_id);
1983
1984                 if (err_code != TAPI_API_SUCCESS) {
1985                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
1986                 }
1987
1988         } else if (memcmp(buf, "pin2", sizeof("pin2") - 1) == 0) {
1989                 TEST_DEBUG("Pin2 Verification");
1990                 int length = TAPI_SIM_PIN_LENGTH + 1;
1991                 char init_pin_val[TAPI_SIM_PIN_LENGTH + 1];
1992
1993                 getchar();
1994
1995                 TEST_DEBUG(" PUT PIN2 CODE: ");
1996
1997                 _fgets(init_pin_val, 9);
1998
1999                 TelSimSecPw_t pin_data = { 0, };
2000
2001                 pin_data.type = TAPI_SIM_PTYPE_PIN2; // 0x00
2002                 pin_data.pw_len = strlen(init_pin_val);
2003                 TEST_DEBUG("pw_len[%d]", pin_data.pw_len);
2004
2005                 pin_data.pw = (unsigned char*) malloc(length);
2006                 memcpy(pin_data.pw, init_pin_val, length);
2007
2008                 err_code = tel_verifiy_sim_pins(&pin_data, &request_id);
2009
2010                 if (err_code != TAPI_API_SUCCESS) {
2011                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2012                 }
2013
2014         } else if (memcmp(buf, "sim", sizeof("sim") - 1) == 0) {
2015                 TEST_DEBUG("sim lock verification");
2016                 int length = TAPI_SIM_PIN_LENGTH + 1;
2017                 char init_pin_val[TAPI_SIM_PIN_LENGTH + 1];
2018
2019                 //puts("Flushing input - Enter \ to exit! ");
2020                 //while ((ch = getchar()) != '\n' && ch != EOF);
2021                 getchar();
2022
2023                 TEST_DEBUG(" PUT SIM LOCK CODE: 4 DIGIT ");
2024
2025                 _fgets(init_pin_val, 9);
2026
2027                 TelSimSecPw_t pin_data = { 0, };
2028
2029                 pin_data.type = TAPI_SIM_PTYPE_SIM; // 0x06
2030                 pin_data.pw_len = strlen(init_pin_val);
2031                 TEST_DEBUG("pw_len[%d]", pin_data.pw_len);
2032
2033                 pin_data.pw = (unsigned char*) malloc(length);
2034                 memcpy(pin_data.pw, init_pin_val, length);
2035
2036                 err_code = tel_verifiy_sim_pins(&pin_data, &request_id);
2037
2038                 if (err_code != TAPI_API_SUCCESS) {
2039                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2040                 }
2041         }
2042         // Disable pin1
2043         else if (memcmp(buf, "dispin", sizeof("dispin") - 1) == 0) {
2044                 getchar();
2045
2046                 TEST_DEBUG("Disable npin1");
2047                 TEST_DEBUG("Plese input PIN1 CODE: ");
2048
2049                 int length = TAPI_SIM_PIN_LENGTH + 1;
2050                 char init_pin_val[length];
2051
2052                 _fgets(init_pin_val, 9);
2053
2054                 TelSimSecPw_t sec_data = { 0, };
2055                 sec_data.type = TAPI_SIM_PTYPE_PIN1; // 0x00
2056                 sec_data.pw_len = strlen(init_pin_val);
2057                 TEST_DEBUG("pw_len[%d]", sec_data.pw_len);
2058
2059                 sec_data.pw = (unsigned char*) malloc(length);
2060                 memcpy(sec_data.pw, init_pin_val, length);
2061
2062                 err_code = tel_disable_sim_security(&sec_data, &request_id);
2063
2064                 if (err_code != TAPI_API_SUCCESS) {
2065                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2066                 }
2067         }
2068
2069         // Enable pin1
2070         else if (memcmp(buf, "enpin", sizeof("enpin") - 1) == 0) {
2071                 //TEST_DEBUG("Flushing input - Enter \ to exit!");
2072                 //while ((ch = getchar()) != '\n' && ch != EOF);
2073                 getchar();
2074
2075                 TEST_DEBUG("Enable npin1");
2076                 TEST_DEBUG("Plese input PIN1 CODE: ");
2077
2078                 int length = TAPI_SIM_PIN_LENGTH + 1;
2079                 char init_pin_val[length];
2080
2081                 _fgets(init_pin_val, 9);
2082
2083                 TelSimSecPw_t sec_data = { 0, };
2084                 sec_data.type = TAPI_SIM_PTYPE_PIN1; // 0x00
2085                 sec_data.pw_len = strlen(init_pin_val);
2086                 TEST_DEBUG("pw_len[%d]", sec_data.pw_len);
2087
2088                 sec_data.pw = (unsigned char*) malloc(length);
2089                 memcpy(sec_data.pw, init_pin_val, length);
2090
2091                 err_code = tel_enable_sim_security(&sec_data, &request_id);
2092
2093                 if (err_code != TAPI_API_SUCCESS) {
2094                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2095                 }
2096         }
2097
2098         // Disable sim lock
2099         else if (memcmp(buf, "dissim", sizeof("dissim") - 1) == 0) {
2100                 getchar();
2101
2102                 TEST_DEBUG("Disable ndissim");
2103                 TEST_DEBUG("Plese input SIM LOCK CODE: ");
2104
2105                 int length = TAPI_SIM_PIN_LENGTH + 1;
2106                 char init_pin_val[length];
2107
2108                 _fgets(init_pin_val, 9);
2109
2110                 TelSimSecPw_t sec_data = { 0, };
2111                 sec_data.type = TAPI_SIM_PTYPE_SIM; // 0x00
2112                 sec_data.pw_len = strlen(init_pin_val);
2113                 TEST_DEBUG("pw_len[%d]", sec_data.pw_len);
2114
2115                 sec_data.pw = (unsigned char*) malloc(length);
2116                 memcpy(sec_data.pw, init_pin_val, length);
2117
2118                 err_code = tel_disable_sim_security(&sec_data, &request_id);
2119
2120                 if (err_code != TAPI_API_SUCCESS) {
2121                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2122                 }
2123         }
2124
2125         // Enable pin1
2126         else if (memcmp(buf, "ensim", sizeof("ensim") - 1) == 0) {
2127                 getchar();
2128
2129                 TEST_DEBUG("Enable nensim");
2130                 TEST_DEBUG("Plese input SIM LOCK CODE: ");
2131
2132                 int length = TAPI_SIM_PIN_LENGTH + 1;
2133                 char init_pin_val[length];
2134
2135                 _fgets(init_pin_val, 9);
2136
2137                 TelSimSecPw_t sec_data = { 0, };
2138                 sec_data.type = TAPI_SIM_PTYPE_SIM; // 0x00
2139                 sec_data.pw_len = strlen(init_pin_val);
2140                 TEST_DEBUG("pw_len[%d]", sec_data.pw_len);
2141
2142                 sec_data.pw = (unsigned char*) malloc(length);
2143                 memcpy(sec_data.pw, init_pin_val, length);
2144
2145                 err_code = tel_enable_sim_security(&sec_data, &request_id);
2146
2147                 if (err_code != TAPI_API_SUCCESS) {
2148                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2149                 }
2150         }
2151
2152         // get pin1 status
2153         else if (memcmp(buf, "getpin1", sizeof("getpin1") - 1) == 0) {
2154                 TelSimPinType_t type = TAPI_SIM_PTYPE_PIN1;
2155                 TelSimPinStatus_t status = -1;
2156                 TEST_DEBUG("Get pin1 status");
2157
2158                 err_code = tel_get_sim_security_status(type, &status);
2159
2160                 if (err_code == TAPI_API_SUCCESS) {
2161
2162                         TEST_DEBUG(" *****************************************************");
2163                         switch (status) {
2164                         case TAPI_SIM_PIN_STATUS_DISABLED: {
2165                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_DISABLED ");
2166                         }
2167                                 break;
2168
2169                         case TAPI_SIM_PIN_STATUS_ENABLED: {
2170                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_ENABLED ");
2171                         }
2172                                 break;
2173
2174                         case TAPI_SIM_PIN_STATUS_BLOCKED: {
2175                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_BLOCKED ");
2176                         }
2177                                 break;
2178
2179                         case TAPI_SIM_PIN_STATUS_PUK_BLOCKED: {
2180                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_PUK_BLOCKED ");
2181                         }
2182                                 break;
2183
2184                         case TAPI_SIM_PIN_STATUS_UNKNOWN: {
2185                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_UNKNOWN ");
2186                         }
2187                                 break;
2188
2189                         default:
2190                                 TEST_DEBUG(" Default case statment: pin1_status(%d)", status)
2191                                 ;
2192                         }
2193                 } else {
2194                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2195                 }
2196
2197                 TEST_DEBUG("*****************************************************");
2198         }
2199         // get pin2 status
2200         else if (memcmp(buf, "getpin2", sizeof("getpin2") - 1) == 0) {
2201                 TelSimPinType_t type = TAPI_SIM_PTYPE_PIN2;
2202                 TelSimPinStatus_t status = -1;
2203                 TEST_DEBUG("Get pin2 status");
2204
2205                 err_code = tel_get_sim_security_status(type, &status);
2206
2207                 if (err_code == TAPI_API_SUCCESS) {
2208
2209                         TEST_DEBUG(" *****************************************************");
2210                         switch (status) {
2211                         case TAPI_SIM_PIN_STATUS_DISABLED: {
2212                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_DISABLED ");
2213                         }
2214                                 break;
2215
2216                         case TAPI_SIM_PIN_STATUS_ENABLED: {
2217                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_ENABLED ");
2218                         }
2219                                 break;
2220
2221                         case TAPI_SIM_PIN_STATUS_BLOCKED: {
2222                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_BLOCKED ");
2223                         }
2224                                 break;
2225
2226                         case TAPI_SIM_PIN_STATUS_PUK_BLOCKED: {
2227                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_PUK_BLOCKED ");
2228                         }
2229                                 break;
2230
2231                         case TAPI_SIM_PIN_STATUS_UNKNOWN: {
2232                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_UNKNOWN ");
2233                         }
2234                                 break;
2235
2236                         default:
2237                                 TEST_DEBUG(" Default case statment: pin2_status(%d)", status)
2238                                 ;
2239                         }
2240                 } else {
2241                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2242                 }
2243
2244                 TEST_DEBUG("*****************************************************");
2245         } else if (memcmp(buf, "getsim", sizeof("getsim") - 1) == 0) {
2246                 TelSimPinType_t type = TAPI_SIM_PTYPE_SIM;
2247                 TelSimPinStatus_t status = -1;
2248                 TEST_DEBUG("Get SIM LOCK status");
2249
2250                 err_code = tel_get_sim_security_status(type, &status);
2251
2252                 if (err_code == TAPI_API_SUCCESS) {
2253
2254                         TEST_DEBUG(" *****************************************************");
2255                         switch (status) {
2256                         case TAPI_SIM_PIN_STATUS_DISABLED: {
2257                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_DISABLED ");
2258                         }
2259                                 break;
2260
2261                         case TAPI_SIM_PIN_STATUS_ENABLED: {
2262                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_ENABLED ");
2263                         }
2264                                 break;
2265
2266                         case TAPI_SIM_PIN_STATUS_BLOCKED: {
2267                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_BLOCKED ");
2268                         }
2269                                 break;
2270
2271                         case TAPI_SIM_PIN_STATUS_PUK_BLOCKED: {
2272                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_PUK_BLOCKED ");
2273                         }
2274                                 break;
2275
2276                         case TAPI_SIM_PIN_STATUS_UNKNOWN: {
2277                                 TEST_DEBUG("TAPI_SIM_PIN_STATUS_UNKNOWN ");
2278                         }
2279                                 break;
2280
2281                         default:
2282                                 TEST_DEBUG(" Default case statment: sim_status(%d)", status)
2283                                 ;
2284                         }
2285                 } else {
2286                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2287                 }
2288
2289                 TEST_DEBUG("*****************************************************");
2290         }
2291         // Enable FDN
2292         else if (memcmp(buf, "enfdn", sizeof("enfdn") - 1) == 0) {
2293                 //puts("Flushing input - Enter \ to exit! ");
2294                 //while ((ch = getchar()) != '\n' && ch != EOF);
2295                 getchar();
2296
2297                 TEST_DEBUG("Enable FDN");
2298                 TEST_DEBUG("Plese input PIN2 CODE: ");
2299
2300                 int length = TAPI_SIM_PIN_LENGTH + 1;
2301                 char init_pin_val[length];
2302
2303                 _fgets(init_pin_val, 9);
2304
2305                 TelSimSecPw_t sec_data = { 0, };
2306                 sec_data.type = TAPI_SIM_PTYPE_PIN2; // 0x00
2307                 sec_data.pw_len = strlen(init_pin_val);
2308                 TEST_DEBUG("pw_len[%d]", sec_data.pw_len);
2309
2310                 sec_data.pw = (unsigned char*) malloc(length);
2311                 memcpy(sec_data.pw, init_pin_val, length);
2312
2313                 err_code = tel_enable_sim_fdn(sec_data.pw, (int *)&sec_data.pw_len,
2314                                 &request_id);
2315
2316                 if (err_code != TAPI_API_SUCCESS) {
2317                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2318                 }
2319         }
2320         // Disable FDN
2321         else if (memcmp(buf, "disfdn", sizeof("disfdn") - 1) == 0) {
2322                 getchar();
2323
2324                 TEST_DEBUG("Disable FDN");
2325                 TEST_DEBUG("Plese input PIN2 CODE");
2326
2327                 int length = TAPI_SIM_PIN_LENGTH + 1;
2328                 char init_pin_val[length];
2329
2330                 _fgets(init_pin_val, 9);
2331
2332                 TelSimSecPw_t sec_data = { 0, };
2333                 sec_data.type = TAPI_SIM_PTYPE_PIN2; // 0x00
2334                 sec_data.pw_len = strlen(init_pin_val);
2335                 TEST_DEBUG("pw_len[%d]", sec_data.pw_len);
2336
2337                 sec_data.pw = (unsigned char*) malloc(length);
2338                 memcpy(sec_data.pw, init_pin_val, length);
2339
2340                 err_code = tel_disable_sim_fdn(sec_data.pw, (int *)&sec_data.pw_len,
2341                                 &request_id);
2342
2343                 if (err_code != TAPI_API_SUCCESS) {
2344                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2345                 }
2346         }
2347         // get FDN status
2348         else if (memcmp(buf, "getfdn", sizeof("getfdn") - 1) == 0) {
2349                 TEST_DEBUG("Get FDN status");
2350                 int fdn_status = 0;
2351
2352                 err_code = tel_get_sim_fdn_status(&fdn_status);
2353
2354                 if (err_code == TAPI_API_SUCCESS) {
2355                         if (fdn_status == 0) {
2356                                 TEST_DEBUG("*************************");
2357                                 TEST_DEBUG("FDN disabled ");
2358                                 TEST_DEBUG("*************************");
2359                         } else {
2360                                 TEST_DEBUG("*************************");
2361                                 TEST_DEBUG("FDN enabled");
2362                                 TEST_DEBUG("*************************");
2363                         }
2364                 } else {
2365                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2366                 }
2367         } else if (memcmp(buf, "gettype", sizeof("gettype") - 1) == 0) {
2368                 TelSimCardType_t cardInfo;
2369                 TEST_DEBUG("Get card type !!!");
2370                 err_code = tel_get_sim_type(&cardInfo);
2371
2372                 if (err_code == TAPI_API_SUCCESS) {
2373                         TEST_DEBUG("*************************************************************");
2374                         __PrintCardType("", cardInfo);
2375                         TEST_DEBUG("*************************************************************");
2376                 } else {
2377                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2378                 }
2379         } else if (memcmp(buf, "getimsi", sizeof("getimsi") - 1) == 0) {
2380                 TelSimImsiInfo_t imsi;
2381                 TEST_DEBUG("Get IMSI type !!!");
2382                 err_code = tel_get_sim_imsi(&imsi);
2383
2384                 if (err_code == TAPI_API_SUCCESS) {
2385                         TEST_DEBUG("*************************************************************");
2386                         TEST_DEBUG("* imsi.bValid[%d]",imsi.bValid);
2387                         TEST_DEBUG("* imsi.szMcc[%s]",imsi.szMcc);
2388                         TEST_DEBUG("* imsi.szMnc[%s]",imsi.szMnc);
2389                         TEST_DEBUG("* imsi.szMsin[%s]",imsi.szMsin);
2390                         TEST_DEBUG("*************************************************************");
2391                 } else {
2392                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2393                 }
2394         } else if (memcmp(buf, "geticcid", sizeof("geticcid") - 1) == 0) {
2395                 TelSimIccIdInfo_t iccid;
2396                 TEST_DEBUG("Get ICCID  !!!");
2397                 err_code = tel_get_sim_iccid(&iccid);
2398                 int i = 0;
2399
2400                 if (err_code == TAPI_API_SUCCESS) {
2401                         TEST_DEBUG("*************************************************************");
2402                         TEST_DEBUG("* iccid.icc_length[%d]",iccid.icc_length);
2403                         for (i = 0; i < iccid.icc_length; i++) {
2404                                 TEST_DEBUG("* iccid.icc_num[%c]",iccid.icc_num[i]);
2405                         }
2406                         TEST_DEBUG("*************************************************************");
2407                 } else {
2408                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2409                 }
2410         }
2411
2412         else if (memcmp(buf, "getlang", sizeof("getlang") - 1) == 0) {
2413                 TEST_DEBUG("Language Preference INFO ");
2414                 int i;
2415                 TelSimLanguageInfo_t li_info = { 0, };
2416
2417                 err_code = tel_get_sim_language(&li_info);
2418
2419                 if (err_code == TAPI_API_SUCCESS) {
2420                         TEST_DEBUG(" ============================================");
2421                         TEST_DEBUG("************ LI  INFO ***********************");
2422                         TEST_DEBUG("LpCount: [%lu]", li_info.LpCount);
2423                         for (i = 0; i < li_info.LpCount; i++) {
2424                                 fprintf(stderr, "Loop(%d), ", i);
2425                                 __PrintLangInfo("LpCode: ", li_info.Lp[i]);
2426                         }
2427                         TEST_DEBUG("============================================");
2428                 } else {
2429                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2430                 }
2431         }
2432
2433         else if (memcmp(buf, "getecc", sizeof("getecc") - 1) == 0) {
2434                 TEST_DEBUG(" Get SIM ECC  ");
2435                 int ecc_rec_count = 0;
2436                 TelSimEccData_t ecc_info = { { { 0, } } };
2437                 TelSimEccInfo_t SimEccInfo = { { 0, } };
2438
2439                 err_code = tel_get_sim_ecc(&ecc_info, &ecc_rec_count);
2440
2441                 if (err_code == TAPI_API_SUCCESS) {
2442                         SimEccInfo = ecc_info.EccInfo;
2443                         TEST_DEBUG(" ============================================");
2444                         TEST_DEBUG(" EEC count [%d]", ecc_rec_count);
2445                         TEST_DEBUG(" ============================================");
2446
2447                         if (ecc_rec_count != 0) {
2448                                 TEST_DEBUG("ECC1 [%s]", SimEccInfo.szEcc1);
2449                                 TEST_DEBUG("ECC2 [%s]", SimEccInfo.szEcc2);
2450                                 TEST_DEBUG("ECC3 [%s]", SimEccInfo.szEcc3);
2451                                 TEST_DEBUG("ECC4 [%s]", SimEccInfo.szEcc4);
2452                                 TEST_DEBUG("ECC5 [%s]", SimEccInfo.szEcc5);
2453                         }
2454                         TEST_DEBUG(" ============================================");
2455                 } else {
2456                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2457                 }
2458         }
2459
2460         else if (memcmp(buf, "getuecc", sizeof("getuecc") - 1) == 0) {
2461                 int i = 0;
2462                 int uecc_rec_count = 0;
2463
2464                 TEST_DEBUG(" Get USIM ECC  ");
2465
2466                 TelSimEccData_t uecc_info = { { { 0, } } };
2467
2468                 err_code = tel_get_sim_ecc(&uecc_info, &uecc_rec_count);
2469
2470                 if (err_code == TAPI_API_SUCCESS) {
2471
2472                         TEST_DEBUG("ECC count [%d]",uecc_rec_count );
2473
2474                         for (i = 0; i < uecc_rec_count; i++) {
2475                                 TEST_DEBUG("Loop(%d): ", i);
2476                                 TEST_DEBUG(" ECC Used [%d]", uecc_info.UeccInfo[i].bUsed);
2477                                 TEST_DEBUG(" ECC Len [%d]", uecc_info.UeccInfo[i].EccLen);
2478
2479                                 if (NULL != uecc_info.UeccInfo[i].szEcc) {
2480                                         TEST_DEBUG("ECC string [%s]", uecc_info.UeccInfo[i].szEcc);
2481                                 } else {
2482                                         TEST_DEBUG("ECC string [null]");
2483                                 }
2484
2485                                 TEST_DEBUG("ECC alphaID [%s]",uecc_info.UeccInfo[i].szEccAlphaIdentifier);
2486                                 __PrintECCSvcInfo(uecc_info.UeccInfo[i].EccEmergencyServiceInfo);
2487                         }
2488
2489                 } else {
2490                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2491                 }
2492         }
2493
2494         else if (memcmp(buf, "getimsi", sizeof("getimsi") - 1) == 0) {
2495                 TEST_DEBUG("Get IMSI INFO ");
2496
2497                 TelSimImsiInfo_t sim_imsi_info;
2498
2499                 err_code = tel_get_sim_imsi(&sim_imsi_info);
2500
2501                 if (err_code == TAPI_API_SUCCESS) {
2502                         TEST_DEBUG(" ============================================");
2503                         TEST_DEBUG(" IMSI [mcc,mnc,msin]= ");
2504                         TEST_DEBUG(" [%s]",sim_imsi_info.szMcc);
2505                         TEST_DEBUG(" [%s]",sim_imsi_info.szMnc);
2506                         TEST_DEBUG(" [%s]",sim_imsi_info.szMsin);
2507                         TEST_DEBUG(" ============================================");
2508                 } else {
2509                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2510                 }
2511         }
2512
2513         else if (memcmp(buf, "getmb", sizeof("getmb") - 1) == 0) {
2514                 TEST_DEBUG("Get MAILBOX INFO ");
2515
2516                 TelSimMailboxNumbers_s mbox;
2517
2518                 err_code = tel_get_sim_mailbox_info(&mbox);
2519
2520                 if (err_code == TAPI_API_SUCCESS) {
2521                         TEST_DEBUG(" ============================================");
2522
2523                         if (mbox.b_cphs) {
2524                                 TEST_DEBUG("Current SIM is CPHS");
2525                         } else {
2526                                 TEST_DEBUG("Current SIM is not CPHS but 3GPP");
2527                         }
2528                         TEST_DEBUG(" ============================================");
2529                         TEST_DEBUG(" voice_line1.bUsed[%d]",mbox.voice_line1.bUsed);
2530                         TEST_DEBUG(" voice_line1.AlphaIdLength[%lu]",mbox.voice_line1.AlphaIdLength);
2531                         TEST_DEBUG(" voice_line1.AlphaId[%s]",mbox.voice_line1.AlphaId);
2532                         TEST_DEBUG(" voice_line1.DiallingnumLength[%lu]",mbox.voice_line1.DiallingnumLength);
2533                         TEST_DEBUG(" voice_line1.DiallingNum[%s]",mbox.voice_line1.DiallingNum);
2534                         TEST_DEBUG(" voice_line1.NumberingPlanIdent[%d]",mbox.voice_line1.NumberingPlanIdent);
2535                         TEST_DEBUG(" voice_line1.TypeOfNumber[%u]",mbox.voice_line1.TypeOfNumber);
2536                         TEST_DEBUG(" ============================================");
2537                         TEST_DEBUG(" voice_line2.bUsed[%d]",mbox.voice_line2.bUsed);
2538                         TEST_DEBUG(" voice_line2.AlphaIdLength[%lu]",mbox.voice_line2.AlphaIdLength);
2539                         TEST_DEBUG(" voice_line2.AlphaId[%s]",mbox.voice_line2.AlphaId);
2540                         TEST_DEBUG(" voice_line2.DiallingnumLength[%lu]",mbox.voice_line2.DiallingnumLength);
2541                         TEST_DEBUG(" voice_line2.DiallingNum[%s]",mbox.voice_line2.DiallingNum);
2542                         TEST_DEBUG(" voice_line2.NumberingPlanIdent[%d]",mbox.voice_line2.NumberingPlanIdent);
2543                         TEST_DEBUG(" voice_line2.TypeOfNumber[%d]",mbox.voice_line2.TypeOfNumber);
2544                         TEST_DEBUG(" ============================================");
2545                         TEST_DEBUG(" video.bUsed[%d]",mbox.video.bUsed);
2546                         TEST_DEBUG(" video.AlphaIdLength[%lu]",mbox.video.AlphaIdLength);
2547                         TEST_DEBUG(" video.AlphaId[%s]",mbox.video.AlphaId);
2548                         TEST_DEBUG(" video.DiallingnumLength[%lu]",mbox.video.DiallingnumLength);
2549                         TEST_DEBUG(" video.DiallingNum[%s]",mbox.video.DiallingNum);
2550                         TEST_DEBUG(" video.NumberingPlanIdent[%d]",mbox.video.NumberingPlanIdent);
2551                         TEST_DEBUG(" video.TypeOfNumber[%d]",mbox.video.TypeOfNumber);
2552                         TEST_DEBUG(" ============================================");
2553                         TEST_DEBUG(" fax.bUsed[%d]",mbox.fax.bUsed);
2554                         TEST_DEBUG(" fax.AlphaIdLength[%lu]",mbox.fax.AlphaIdLength);
2555                         TEST_DEBUG(" fax.AlphaId[%s]",mbox.fax.AlphaId);
2556                         TEST_DEBUG(" fax.DiallingnumLength[%lu]",mbox.fax.DiallingnumLength);
2557                         TEST_DEBUG(" fax.DiallingNum[%s]",mbox.fax.DiallingNum);
2558                         TEST_DEBUG(" fax.NumberingPlanIdent[%d]",mbox.fax.NumberingPlanIdent);
2559                         TEST_DEBUG(" fax.TypeOfNumber[%d]",mbox.fax.TypeOfNumber);
2560                         TEST_DEBUG(" ============================================");
2561                         TEST_DEBUG(" email.bUsed[%d]",mbox.email.bUsed);
2562                         TEST_DEBUG(" email.AlphaIdLength[%lu]",mbox.email.AlphaIdLength);
2563                         TEST_DEBUG(" email.AlphaId[%s]",mbox.email.AlphaId);
2564                         TEST_DEBUG(" email.DiallingnumLength[%lu]",mbox.email.DiallingnumLength);
2565                         TEST_DEBUG(" email.DiallingNum[%s]",mbox.email.DiallingNum);
2566                         TEST_DEBUG(" email.NumberingPlanIdent[%d]",mbox.email.NumberingPlanIdent);
2567                         TEST_DEBUG(" email.TypeOfNumber[%d]",mbox.email.TypeOfNumber);
2568                         TEST_DEBUG(" ============================================");
2569
2570                 } else {
2571                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2572                 }
2573         }
2574
2575         else if (memcmp(buf, "getmw", sizeof("getmw") - 1) == 0) {
2576                 TEST_DEBUG("Get MESSAGE WAITING INFO ");
2577
2578                 TelSimMessageWaiting_s mw;
2579
2580                 err_code = tel_get_sim_messagewaiting_info(&mw);
2581
2582                 if (err_code == TAPI_API_SUCCESS) {
2583                         TEST_DEBUG(" ============================================");
2584
2585                         if (mw.b_cphs) {
2586                                 TEST_DEBUG("Current SIM is CPHS");
2587                                 TEST_DEBUG(" ============================================");
2588                                 TEST_DEBUG(" cphs_mw.bWaitVoiceMsgLine1[%d]",mw.mw_data_u.cphs_mw.bWaitVoiceMsgLine1);
2589                                 TEST_DEBUG(" cphs_mw.bWaitVoiceMsgLine2[%d]",mw.mw_data_u.cphs_mw.bWaitVoiceMsgLine2);
2590                                 TEST_DEBUG(" cphs_mw.bWaitFaxMsg[%d]",mw.mw_data_u.cphs_mw.bWaitFaxMsg);
2591                                 TEST_DEBUG(" cphs_mw.bWaitDataMsg[%d]",mw.mw_data_u.cphs_mw.bWaitDataMsg);
2592
2593                         } else {
2594                                 TEST_DEBUG("Current SIM is not CPHS but 3GPP");
2595                                 TEST_DEBUG(" ============================================");
2596                                 TEST_DEBUG(" mw_data_u.mw.IndicatorType[0x%x]",mw.mw_data_u.mw.IndicatorType);
2597                                 TEST_DEBUG(" mw_data_u.mw.VoiceMailCount[%d]",mw.mw_data_u.mw.VoiceMailCount);
2598                                 TEST_DEBUG(" mw_data_u.mw.FaxCount[%d]",mw.mw_data_u.mw.FaxCount);
2599                                 TEST_DEBUG(" mw_data_u.mw.EmailCount[%d]",mw.mw_data_u.mw.EmailCount);
2600                                 TEST_DEBUG(" mw_data_u.mw.OtherCount[%d]",mw.mw_data_u.mw.OtherCount);
2601                                 TEST_DEBUG(" mw_data_u.mw.VideoMailCount[%d]",mw.mw_data_u.mw.VideoMailCount);
2602                         }
2603                         TEST_DEBUG(" ============================================");
2604
2605                 } else {
2606                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2607                 }
2608         }
2609
2610         else if (memcmp(buf, "getcf", sizeof("getcf") - 1) == 0) {
2611                 TEST_DEBUG("Get CALLFORWARDING INFO ");
2612
2613                 TelSimCallForwarding_s cf;
2614
2615                 err_code = tel_get_sim_callforwarding_info(&cf);
2616
2617                 if (err_code == TAPI_API_SUCCESS) {
2618                         TEST_DEBUG(" ============================================");
2619
2620                         if (cf.b_cphs) {
2621                                 TEST_DEBUG("Current SIM is CPHS");
2622                                 TEST_DEBUG(" ============================================");
2623                                 TEST_DEBUG(" cphs_cf.bCallForwardUnconditionalLine1[%d]",cf.cf_data_u.cphs_cf.bCallForwardUnconditionalLine1);
2624                                 TEST_DEBUG(" cphs_cf.bCallForwardUnconditionalLine2[%d]",cf.cf_data_u.cphs_cf.bCallForwardUnconditionalLine2);
2625                                 TEST_DEBUG(" cphs_cf.bCallForwardUnconditionalFax[%d]",cf.cf_data_u.cphs_cf.bCallForwardUnconditionalFax);
2626                                 TEST_DEBUG(" cphs_cf.bCallForwardUnconditionalData[%d]",cf.cf_data_u.cphs_cf.bCallForwardUnconditionalData);
2627                                 TEST_DEBUG(" cphs_cf.bCallForwardUnconditionalSms[%d]",cf.cf_data_u.cphs_cf.bCallForwardUnconditionalSms);
2628                                 TEST_DEBUG(" cphs_cf.bCallForwardUnconditionalBearer[%d]",cf.cf_data_u.cphs_cf.bCallForwardUnconditionalBearer);
2629                         } else {
2630                                 TEST_DEBUG("Current SIM is not CPHS but 3GPP");
2631                                 TEST_DEBUG(" ============================================");
2632                                 TEST_DEBUG(" cf.bUsed[%d]",cf.cf_data_u.cf.bUsed);
2633                                 TEST_DEBUG(" cf.MspNumber[%d]",cf.cf_data_u.cf.MspNumber);
2634                                 TEST_DEBUG(" cf.Status[0x%x]",cf.cf_data_u.cf.Status);
2635                                 TEST_DEBUG(" cf.DiallingnumLen[%lu]",cf.cf_data_u.cf.DiallingnumLen);
2636                                 TEST_DEBUG(" cf.TypeOfNumber[%d]",cf.cf_data_u.cf.TypeOfNumber);
2637                                 TEST_DEBUG(" cf.NumberingPlanIdent[%d]",cf.cf_data_u.cf.NumberingPlanIdent);
2638                                 TEST_DEBUG(" cf.DiallingNum[%s]",cf.cf_data_u.cf.DiallingNum);
2639                         }
2640                         TEST_DEBUG(" ============================================");
2641                 } else {
2642                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2643                 }
2644         }
2645
2646         else if (memcmp(buf, "getcphs", sizeof("getcphs") - 1) == 0) {
2647                 TEST_DEBUG("Get CPHS INFO ");
2648
2649                 TelSimCphsLocalInfo_t cphs;
2650
2651                 err_code = tel_get_sim_cphs_info(&cphs);
2652
2653                 if (err_code == TAPI_API_SUCCESS) {
2654                         TEST_DEBUG(" ============================================");
2655
2656                         if (cphs.b_used) {
2657                                 TEST_DEBUG("Current SIM is CPHS");
2658                                 TEST_DEBUG(" ============================================");
2659                                 TEST_DEBUG("cphs.cphsinfo.CphsPhase[%d]",cphs.cphsinfo.CphsPhase);
2660                                 TEST_DEBUG("cphs.cphsinfo.CphsServiceTable.bCustomerServiceProfile[%d]",cphs.cphsinfo.CphsServiceTable.bCustomerServiceProfile);
2661                                 TEST_DEBUG("cphs.cphsinfo.CphsServiceTable.bServiceStringTable[%d]",cphs.cphsinfo.CphsServiceTable.bServiceStringTable);
2662                                 TEST_DEBUG("cphs.cphsinfo.CphsServiceTable.bMailBoxNumbers[%d]",cphs.cphsinfo.CphsServiceTable.bMailBoxNumbers);
2663                                 TEST_DEBUG("cphs.cphsinfo.CphsServiceTable.bOperatorNameShortForm[%d]",cphs.cphsinfo.CphsServiceTable.bOperatorNameShortForm);
2664                                 TEST_DEBUG("cphs.cphsinfo.CphsServiceTable.bInformationNumbers[%d]",cphs.cphsinfo.CphsServiceTable.bInformationNumbers);
2665                                 TEST_DEBUG(" ============================================");
2666                                 TEST_DEBUG("cphs.csp.ServiceProfileEntry[0].CustomerServiceGroup[%d]",cphs.csp.ServiceProfileEntry[0].CustomerServiceGroup);
2667                                 TEST_DEBUG(" ============================================");
2668                                 TEST_DEBUG("cphs.infn.bUsed[%d]",cphs.infn.bUsed);
2669                                 TEST_DEBUG("cphs.infn.AlphaIdLength[%d]",cphs.infn.AlphaIdLength);
2670                                 TEST_DEBUG("cphs.infn.IndexLevelIndicator[%d]",cphs.infn.IndexLevelIndicator);
2671                                 TEST_DEBUG("cphs.infn.PremiumServiceIndicator[%d]",cphs.infn.PremiumServiceIndicator);
2672                                 TEST_DEBUG("cphs.infn.NetworkSpecificIndicator[%d]",cphs.infn.NetworkSpecificIndicator);
2673                                 TEST_DEBUG("cphs.infn.Alpha_id[%s]",cphs.infn.Alpha_id);
2674                                 TEST_DEBUG("cphs.infn.DiallingnumLength[%lu]",cphs.infn.DiallingnumLength);
2675                                 TEST_DEBUG("cphs.infn.TypeOfNumber[%d]",cphs.infn.TypeOfNumber);
2676                                 TEST_DEBUG("cphs.infn.NumberingPlanIdentity[%d]",cphs.infn.NumberingPlanIdentity);
2677                                 TEST_DEBUG("cphs.infn.DiallingNum[%s]",cphs.infn.DiallingNum);
2678                                 TEST_DEBUG("cphs.infn.Ext1RecordId[%d]",cphs.infn.Ext1RecordId);
2679                                 TEST_DEBUG(" ============================================");
2680                                 TEST_DEBUG("cphs.opname.NameLength[%d]",cphs.opname.NameLength);
2681                                 TEST_DEBUG("cphs.opname.OperatorName[%s]",cphs.opname.OperatorName);
2682                                 TEST_DEBUG(" ============================================");
2683                                 TEST_DEBUG("cphs.opshortform.ShortNameLength[%d]",cphs.opshortform.ShortNameLength);
2684                                 TEST_DEBUG("cphs.opshortform.OperatorShortName[%s]",cphs.opshortform.OperatorShortName);
2685                                 TEST_DEBUG(" ============================================");
2686                                 TEST_DEBUG("cphs.dflagsinfo.DynamicFlags[%d]",cphs.dflagsinfo.DynamicFlags);
2687                                 TEST_DEBUG(" ============================================");
2688                                 TEST_DEBUG("cphs.d2flagsinfo.Dynamic2Flag[%d]",cphs.d2flagsinfo.Dynamic2Flag);
2689                         } else {
2690                                 TEST_DEBUG("Current SIM is not CPHS but 3GPP");
2691                                 TEST_DEBUG(" ============================================");
2692
2693                         }
2694                         TEST_DEBUG(" ============================================");
2695                 } else {
2696                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2697                 }
2698
2699         } else if (memcmp(buf, "getmsisdn", sizeof("getmsisdn") - 1) == 0) {
2700                 TEST_DEBUG("Get MSISDN INFO ");
2701
2702                 TelSimSubscriberInfo_t msisdn;
2703
2704                 err_code = tel_get_sim_msisdn(&msisdn);
2705
2706                 if (err_code == TAPI_API_SUCCESS) {
2707                         TEST_DEBUG(" ============================================");
2708                         TEST_DEBUG("name[%s]",msisdn.name);
2709                         TEST_DEBUG("num[%s]",msisdn.num);
2710                         if (msisdn.name == '\0')
2711                                 TEST_DEBUG("name is null string");
2712
2713                         if (msisdn.num == '\0')
2714                                 TEST_DEBUG("number is null string");
2715                 } else {
2716                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2717                 }
2718         } else if (memcmp(buf, "pbinit", sizeof("pbinit") - 1) == 0) {
2719                 TEST_DEBUG("npbinit status");
2720
2721                 int valid_index = 0;
2722                 TelSimPbList_t pb_list = { 0, };
2723                 int pPbInitCompleted = 0;
2724
2725                 err_code = tel_get_sim_pb_init_info(&pPbInitCompleted, &pb_list,
2726                                 &valid_index);
2727
2728                 if (err_code == TAPI_API_SUCCESS) {
2729                         if (pPbInitCompleted == 0) {
2730                                 TEST_DEBUG(" SIM PB INIT NOT completed ");
2731                         } else {
2732                                 TEST_DEBUG("SIM PB INIT completed");
2733                                 /* if no sim records at all then valid_index = 0xFF */TEST_DEBUG("ADN First index is [%d]",valid_index);
2734                                 TEST_DEBUG("SIM phone book storage list Information ");
2735                                 TEST_DEBUG("********************************************");
2736                                 TEST_DEBUG("pb_list.b_fdn[%d]",pb_list.b_fdn);
2737                                 TEST_DEBUG("pb_list.b_msisdn[%d]",pb_list.b_msisdn);
2738                                 TEST_DEBUG("pb_list.b_adn[%d]",pb_list.b_adn);
2739                                 TEST_DEBUG("pb_list.b_sdn[%d]",pb_list.b_sdn);
2740                                 TEST_DEBUG("pb_list.b_3g[%d]",pb_list.b_3g);
2741                                 TEST_DEBUG("pb_list.b_aas[%d]",pb_list.b_aas);
2742                                 TEST_DEBUG("pb_list.b_gas[%d]",pb_list.b_gas);
2743
2744                                 /*
2745                                  if(pb_list & 0x01)
2746                                  TEST_DEBUG("ME dialed calls list stored in NV");
2747                                  if(pb_list & 0x02)
2748                                  TEST_DEBUG("SIM(or ME) emergency number");
2749                                  if(pb_list & 0x03)
2750                                  TEST_DEBUG("SIM fixed-dialing phonebook");
2751                                  if(pb_list & 0x04)
2752                                  TEST_DEBUG("SIM last-dialing phonebook");
2753                                  if(pb_list & 0x05)
2754                                  TEST_DEBUG("ME missed calls list");
2755                                  if(pb_list & 0x06)
2756                                  TEST_DEBUG("ME phonebook");
2757                                  if(pb_list & 0x07)
2758                                  TEST_DEBUG("Combined ME and SIM phonebook");
2759                                  if(pb_list & 0x08)
2760                                  TEST_DEBUG("SIM(or ME) own numbers ( MSISDNs) list");
2761                                  if(pb_list & 0x09)
2762                                  TEST_DEBUG("ME received calls list stored in NV");
2763                                  if(pb_list & 0x0A)
2764                                  TEST_DEBUG("2G SIM phonebook");
2765                                  if(pb_list & 0x0B)
2766                                  TEST_DEBUG("Service Dialing Number");
2767                                  if(pb_list & 0x0C)
2768                                  TEST_DEBUG("3G SIM phonebook");
2769                                  if(pb_list & 0x0D)
2770                                  TEST_DEBUG("Incoming Call Information");
2771                                  if(pb_list & 0x0E)
2772                                  TEST_DEBUG("Outgoing Call Information");
2773                                  if(pb_list & 0x0F)
2774                                  TEST_DEBUG("Additional Number Alpha String");
2775                                  if(pb_list & 0x10)
2776                                  TEST_DEBUG("Grouping Information Alpha String");
2777                                  */
2778                                 /*
2779                                  PB_DC  0x01    ME dialed calls list stored in NV
2780                                  PB_EN  0x02    SIM(or ME) emergency number
2781                                  PB_FD  0x03    SIM fixed-dialing phonebook
2782                                  PB_LD  0x04    SIM last-dialing phonebook
2783                                  PB_MC  0x05    ME missed calls list
2784                                  PB_ME  0x06    ME phonebook
2785                                  PB_MT  0x07    Combined ME and SIM phonebook
2786                                  PB_ON  0x08    SIM(or ME) own numbers ( MSISDNs) list
2787                                  PB_RC  0x09    ME received calls list stored in NV
2788                                  PB_SIM 0x0A    2G SIM phonebook
2789                                  PB_SDN 0x0B    Service Dialing Number
2790                                  PB_3GSIM       0x0C    3G SIM phonebook
2791                                  PB_ICI 0x0D    Incoming Call Information
2792                                  PB_OCI 0x0E    Outgoing Call Information
2793                                  PB_AAS 0x0F    Additional Number Alpha String
2794                                  PB_GAS 0x10    Grouping Information Alpha String
2795                                  */
2796
2797                                 TEST_DEBUG("********************************************");
2798                         }
2799                 } else {
2800                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2801                 }
2802
2803         }
2804
2805         //change pin1 number
2806         else if (memcmp(buf, "chpin1", sizeof("chpin1") - 1) == 0) {
2807                 int length = TAPI_SIM_PIN_LENGTH + 1;
2808                 char init_old_pin_val[length];
2809                 char init_new_pin_val[length];
2810
2811                 memset(&init_old_pin_val, 0, length);
2812                 memset(&init_new_pin_val, 0, length);
2813
2814                 TelSimSecPw_t old_pin = { 0, };
2815                 TelSimSecPw_t new_pin = { 0, };
2816
2817                 getchar();
2818
2819                 TEST_DEBUG("Change PIN1 CODE");
2820                 TEST_DEBUG("Input Current PIN1 Code: ");
2821
2822                 _fgets(init_old_pin_val, 9);
2823
2824                 old_pin.type = TAPI_SIM_PTYPE_PIN1; // 0x00
2825                 old_pin.pw_len = strlen(init_old_pin_val);
2826                 TEST_DEBUG("pw_len[%d]", old_pin.pw_len);
2827                 old_pin.pw = (unsigned char*) malloc(length);
2828                 memcpy(old_pin.pw, init_old_pin_val, length);
2829
2830                 TEST_DEBUG("Input New PIN1 Code: ");
2831
2832                 _fgets(init_new_pin_val, 9);
2833
2834                 new_pin.type = TAPI_SIM_PTYPE_PIN1; // 0x00
2835                 new_pin.pw_len = strlen(init_new_pin_val);
2836                 TEST_DEBUG("pw_len[%d]", new_pin.pw_len);
2837                 new_pin.pw = (unsigned char*) malloc(length);
2838                 memcpy(new_pin.pw, init_new_pin_val, length);
2839
2840                 err_code = tel_change_sim_pins(&old_pin, &new_pin, &request_id);
2841
2842                 if (err_code != TAPI_API_SUCCESS) {
2843                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2844                 }
2845         }
2846
2847         //change pin2 number
2848         else if (memcmp(buf, "chpin2", sizeof("chpin2") - 1) == 0) {
2849                 int length = TAPI_SIM_PIN_LENGTH + 1;
2850                 char init_old_pin_val[length];
2851                 char init_new_pin_val[length];
2852
2853                 memset(&init_old_pin_val, 0, length);
2854                 memset(&init_new_pin_val, 0, length);
2855
2856                 TelSimSecPw_t old_pin = { 0, };
2857                 TelSimSecPw_t new_pin = { 0, };
2858
2859                 getchar();
2860
2861                 TEST_DEBUG("Change PIN2 CODE");
2862                 TEST_DEBUG("Input Current PIN2 Code: ");
2863
2864                 _fgets(init_old_pin_val, 9);
2865
2866                 old_pin.type = TAPI_SIM_PTYPE_PIN2; // 0x00
2867                 old_pin.pw_len = strlen(init_old_pin_val);
2868                 TEST_DEBUG("pw_len[%d]", old_pin.pw_len);
2869                 old_pin.pw = (unsigned char*) malloc(length);
2870                 memcpy(old_pin.pw, init_old_pin_val, length);
2871
2872                 TEST_DEBUG("Input New PIN2 Code: ");
2873
2874                 _fgets(init_new_pin_val, 9);
2875
2876                 new_pin.type = TAPI_SIM_PTYPE_PIN2; // 0x00
2877                 new_pin.pw_len = strlen(init_new_pin_val);
2878                 TEST_DEBUG("pw_len[%d]", new_pin.pw_len);
2879                 new_pin.pw = (unsigned char*) malloc(length);
2880                 memcpy(new_pin.pw, init_new_pin_val, length);
2881
2882                 err_code = tel_change_sim_pins(&old_pin, &new_pin, &request_id);
2883
2884                 if (err_code != TAPI_API_SUCCESS) {
2885                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2886                 }
2887         }
2888
2889         // unblock CHV and enter new pin code
2890         else if (memcmp(buf, "puk1", sizeof("puk1") - 1) == 0) {
2891                 getchar();
2892
2893                 TEST_DEBUG("PUK1 verification");
2894
2895                 int length = TAPI_SIM_PIN_LENGTH + 1;
2896                 char init_pin_val[length];
2897                 char init_puk_val[length];
2898
2899                 TEST_DEBUG("Plese input PUK CODE: ");
2900
2901                 _fgets(init_puk_val, 9);
2902
2903                 TEST_DEBUG("NEW PIN1 CODE: ");
2904                 _fgets(init_pin_val, 9);
2905
2906                 TelSimSecPw_t puk_data = { 0, };
2907                 TelSimSecPw_t new_pin_data = { 0, };
2908
2909                 puk_data.type = TAPI_SIM_PTYPE_PUK1; // 0x00
2910                 puk_data.pw_len = strlen(init_puk_val);
2911                 TEST_DEBUG("pw_len[%d]", puk_data.pw_len);
2912                 puk_data.pw = (unsigned char*) malloc(length);
2913                 memcpy(puk_data.pw, init_puk_val, length);
2914
2915                 new_pin_data.type = TAPI_SIM_PTYPE_PIN1; // 0x00
2916                 new_pin_data.pw_len = strlen(init_pin_val);
2917                 TEST_DEBUG("pw_len[%d]", new_pin_data.pw_len);
2918                 new_pin_data.pw = (unsigned char*) malloc(length);
2919                 memcpy(new_pin_data.pw, init_pin_val, length);
2920
2921                 //  sim pin init
2922                 TEST_DEBUG("PUKtype Value %d",puk_data.type);
2923                 TEST_DEBUG("PUK Value %s",puk_data.pw);
2924                 TEST_DEBUG("New Pin Value %s",new_pin_data.pw);
2925
2926                 err_code = tel_verify_sim_puks(&puk_data, &new_pin_data, &request_id);
2927
2928                 if (err_code != TAPI_API_SUCCESS) {
2929                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2930                 }
2931         }
2932
2933         // unblock CHV2 and enter new pin2 code
2934         else if (memcmp(buf, "puk2", sizeof("puk2") - 1) == 0) {
2935                 getchar();
2936
2937                 TEST_DEBUG("PUK2 verification");
2938
2939                 int length = TAPI_SIM_PIN_LENGTH + 1;
2940                 char init_pin_val[length];
2941                 char init_puk_val[length];
2942
2943                 TEST_DEBUG("Plese input PUK2 CODE: ");
2944
2945                 _fgets(init_puk_val, 9);
2946
2947                 TEST_DEBUG("NEW PIN2 CODE: ");
2948                 _fgets(init_pin_val, 9);
2949
2950                 TelSimSecPw_t puk_data = { 0, };
2951                 TelSimSecPw_t new_pin_data = { 0, };
2952
2953                 puk_data.type = TAPI_SIM_PTYPE_PUK2; // 0x00
2954                 puk_data.pw_len = strlen(init_puk_val);
2955                 TEST_DEBUG("pw_len[%d]", puk_data.pw_len);
2956                 puk_data.pw = (unsigned char*) malloc(length);
2957                 memcpy(puk_data.pw, init_puk_val, length);
2958
2959                 new_pin_data.type = TAPI_SIM_PTYPE_PIN2; // 0x00
2960                 new_pin_data.pw_len = strlen(init_pin_val);
2961                 TEST_DEBUG("pw_len[%d]", new_pin_data.pw_len);
2962                 new_pin_data.pw = (unsigned char*) malloc(length);
2963                 memcpy(new_pin_data.pw, init_pin_val, length);
2964
2965                 //  sim pin init
2966                 TEST_DEBUG("PUKtype Value %d",puk_data.type);
2967                 TEST_DEBUG("PUK Value %s",puk_data.pw);
2968                 TEST_DEBUG("New Pin Value %s",new_pin_data.pw);
2969
2970                 err_code = tel_verify_sim_puks(&puk_data, &new_pin_data, &request_id);
2971
2972                 if (err_code != TAPI_API_SUCCESS) {
2973                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
2974                 }
2975         }
2976
2977         else if (memcmp(buf, "mepers", sizeof("mepers") - 1) == 0) {
2978                 int tempi;
2979                 char dummy;
2980
2981                 TelSimPersPw_t lock_pers = { 0, };
2982
2983                 printf("------------------------------ \n");
2984                 printf("Personalization Type : \n");
2985                 printf("------------------------------ \n");
2986                 printf("1 - Network  \n");
2987                 printf("2 - Network Subset \n");
2988                 printf("3 - Service Provider \n");
2989                 printf("4 - Corporate \n");
2990                 printf("------------------------------ \n");
2991
2992                 printf("\nPlease input type: \n");
2993                 scanf("%d%c", &tempi, &dummy);
2994
2995                 switch (tempi) {
2996                 case 1: {
2997                         lock_pers.type = TAPI_SIM_PERS_NET;
2998                 }
2999                         break;
3000
3001                 case 2: {
3002                         lock_pers.type = TAPI_SIM_PERS_NS;
3003                 }
3004                         break;
3005
3006                 case 3: {
3007                         lock_pers.type = TAPI_SIM_PERS_SP;
3008                 }
3009                         break;
3010
3011                 case 4: {
3012                         lock_pers.type = TAPI_SIM_PERS_CP;
3013                 }
3014                         break;
3015
3016                 default: {
3017                         printf("wrong pers type! exit!\n");
3018                         exit(1);
3019                 }
3020                         break;
3021                 }
3022
3023                 switch (lock_pers.type) {
3024                 case TAPI_SIM_PERS_NET: {
3025                         puts("Flushing input - Enter \\n to exit! ");
3026
3027                         while ((ch = getchar()) != '\n' && ch != EOF)
3028                                 ;
3029
3030                         printf("Lock Personalisation MCC+MNC 5\n");
3031                         printf(
3032                                         "Plese input Network Lock CODE : length of MCC+MNC, MCC, MNC, NCK\n");
3033                         printf(
3034                                         "We need to use this for testing : length of MCC+MNC(5), MCC(450), MNC(01), NCK(12345678) => 54500112345678\n");
3035
3036                         int length = 14 + 1;
3037                         char init_password_val[length];
3038                         _fgets(init_password_val, 15);
3039
3040                         lock_pers.pw_len = 14;
3041                         lock_pers.pw = (unsigned char*) malloc(length);
3042                         memcpy(lock_pers.pw, init_password_val, length);
3043
3044                 }
3045                         break;
3046
3047                 case TAPI_SIM_PERS_NS: {
3048                         puts("Flushing input - Enter \\n to exit! ");
3049
3050                         while ((ch = getchar()) != '\n' && ch != EOF)
3051                                 ;
3052
3053                         printf(
3054                                         "Network Subset Personalisation MCC+MNC 5 byte, subset 2byte \n");
3055                         printf(
3056                                         "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");
3057
3058                         int length = 17 + 1;
3059                         char init_password_val[length];
3060                         _fgets(init_password_val, 18);
3061
3062                         lock_pers.pw_len = 17;
3063                         lock_pers.pw = (unsigned char*) malloc(length);
3064                         memcpy(lock_pers.pw, init_password_val, length);
3065                 }
3066                         break;
3067
3068                 case TAPI_SIM_PERS_SP: {
3069                         puts("Flushing input - Enter \\n to exit! ");
3070
3071                         while ((ch = getchar()) != '\n' && ch != EOF)
3072                                 ;
3073
3074                         printf(
3075                                         "Service Provider Personalisation MCC+MNC 5 byte, SP 2byte \n");
3076                         printf(
3077                                         "We need to use this for testing : length of MCC+MNC(5), MCC(450), MNC(01), SP(11) SPCK(12345678) => 5450011112345678\n");
3078
3079                         int length = 16 + 1;
3080                         char init_password_val[length];
3081                         _fgets(init_password_val, 17);
3082
3083                         lock_pers.pw_len = 16;
3084                         lock_pers.pw = (unsigned char*) malloc(length);
3085                         memcpy(lock_pers.pw, init_password_val, length);
3086                 }
3087                         break;
3088
3089                 case TAPI_SIM_PERS_CP: {
3090                         puts("Flushing input - Enter \\n to exit! ");
3091
3092                         while ((ch = getchar()) != '\n' && ch != EOF)
3093                                 ;
3094
3095                         printf(
3096                                         "Corporate Personalisation MCC+MNC 5 byte, SP 2byte CP 2byte \n");
3097                         printf(
3098                                         "We need to use this for testing : length of MCC+MNC(5), MCC(450), MNC(01), SP(11) CP(11) CPCK(12345678) => 545001111112345678\n");
3099
3100                         int length = 18 + 1;
3101                         char init_password_val[length];
3102                         _fgets(init_password_val, 19);
3103
3104                         lock_pers.pw_len = 18;
3105                         lock_pers.pw = (unsigned char*) malloc(length);
3106                         memcpy(lock_pers.pw, init_password_val, length);
3107                 }
3108                         break;
3109
3110                 default: {
3111                         printf("wrong condition exit\n");
3112                         exit(1);
3113                 }
3114                         break;
3115                 }
3116
3117                 err_code = tel_enable_sim_personalization(&lock_pers, &request_id);
3118                 printf("Error Code [%x]\n", err_code);
3119
3120         }
3121
3122         if (memcmp(buf, "medepers", sizeof("medepers") - 1) == 0) {
3123                 int tempi;
3124                 char dummy;
3125
3126                 TelSimPersPw_t lock_pers = { 0, };
3127
3128                 printf("------------------------------ \n");
3129                 printf("de-Personalization Type : \n");
3130                 printf("------------------------------ \n");
3131                 printf("1 - Network  \n");
3132                 printf("2 - Network Subset \n");
3133                 printf("3 - Service Provider \n");
3134                 printf("4 - Corporate \n");
3135                 printf("------------------------------ \n");
3136
3137                 printf("\nPlease input type: \n");
3138                 scanf("%d%c", &tempi, &dummy);
3139
3140                 switch (tempi) {
3141                 case 1: {
3142                         lock_pers.type = TAPI_SIM_PERS_NET;
3143                 }
3144                         break;
3145
3146                 case 2: {
3147                         lock_pers.type = TAPI_SIM_PERS_NS;
3148                 }
3149                         break;
3150
3151                 case 3: {
3152                         lock_pers.type = TAPI_SIM_PERS_SP;
3153                 }
3154                         break;
3155
3156                 case 4: {
3157                         lock_pers.type = TAPI_SIM_PERS_CP;
3158                 }
3159                         break;
3160
3161                 default: {
3162                         printf("wrong pers type! exit!\n");
3163                         exit(1);
3164                 }
3165                         break;
3166                 }
3167
3168                 puts("Flushing input - Enter \\n to exit! ");
3169
3170                 while ((ch = getchar()) != '\n' && ch != EOF)
3171                         ;
3172
3173                 printf("de Personalisation key is 8 byte \n");
3174                 printf("We need to use this for testing : 12345678\n");
3175
3176                 int length = 8 + 1;
3177                 char init_password_val[length];
3178                 _fgets(init_password_val, 9);
3179
3180                 lock_pers.pw_len = 8 /*control key*/;
3181                 lock_pers.pw = (unsigned char*) malloc(length);
3182                 memcpy(lock_pers.pw, init_password_val, length);
3183
3184                 err_code = tel_disable_sim_personalization(&lock_pers, &request_id);
3185
3186                 printf("Error Code [%x]\n", err_code);
3187
3188         }
3189
3190         if (memcmp(buf, "getpers", sizeof("getpers") - 1) == 0) {
3191                 int tempi = 0;
3192                 char dummy = 0;
3193
3194                 TelSimPersType_t type = 0;
3195
3196                 puts("Flushing input - Enter \\n to exit! ");
3197
3198                 while ((ch = getchar()) != '\n' && ch != EOF)
3199                         ;
3200
3201                 printf("getpers status\n");
3202                 printf("Here - 1\n");
3203                 printf(
3204                                 "================================================================ \n");
3205                 printf("TAPI_SIM_PERS_NET               = 0x00, /**< Network Lock */ \n");
3206                 printf("TAPI_SIM_PERS_NS                = 0x01, /**< Nettwork Subset Lock */\n");
3207                 printf("TAPI_SIM_PERS_SP                = 0x02, /**< Service Provider Lock */\n");
3208                 printf("TAPI_SIM_PERS_CP                = 0x03, /**< Coporate Lock */\n");
3209                 printf(
3210                                 "================================================================ \n");
3211                 printf("Plese input Lock type \n");
3212
3213                 scanf("%d%c", &tempi, &dummy);
3214                 type = tempi;
3215
3216                 err_code = tel_get_sim_personalization_status(type, &request_id);
3217                 printf("Error Code [%x]\n", err_code);
3218
3219         } else if (memcmp(buf, "setlang", sizeof("setlang") - 1) == 0) {
3220                 int tempi;
3221                 char dummy;
3222
3223                 TelSimLanguagePreferenceCode_t language = 0x00;
3224
3225                 printf("------------------------------ \n");
3226                 printf("select language which will be updated: \n");
3227                 printf("------------------------------ \n");
3228                 printf("should select inside here ( 0.DE / 1.EN / 2.IT / 3.FR ) \n");
3229                 printf(
3230                                 "should select inside here ( 4.SPANISH / 5.DUTCH / 6.SWEDISH / 7.DANISH ) \n");
3231                 printf(
3232                                 "should select inside here ( 8.PORTUGUESE / 9.FINNISH / 10.NORWEGIAN / 11.GREEK ) \n");
3233                 printf(
3234                                 "should select inside here ( 12.TURKISH / 13.HUNGARIAN / 14.POLISH / 15.KOREAN ) \n");
3235                 printf(
3236                                 "should select inside here ( 16.CHINESE / 17.RUSSIAN / 18.JAPANESE ) \n");
3237                 printf("------------------------------ \n");
3238
3239                 printf("\nPlease input type: \n");
3240                 scanf("%d%c", &tempi, &dummy);
3241
3242                 language = (TelSimLanguagePreferenceCode_t) tempi;
3243
3244                 err_code = tel_set_sim_language(language, &request_id);
3245
3246                 if (err_code == TAPI_API_SUCCESS) {
3247                         TEST_DEBUG("TAPI API SUCCESS");
3248                 } else {
3249                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3250                 }
3251
3252         } else if (memcmp(buf, "apdu", sizeof("apdu") - 1) == 0) {
3253                 printf("------------------------------ \n");
3254                 printf("APDU\n");
3255                 printf("------------------------------ \n");
3256
3257                 TelSimApdu_t apdu_data = { 0, };
3258
3259                 char tmp_apdu[4] = { 0x41, 0xC0, 0x05, 0x6f };
3260
3261                 apdu_data.apdu_len = 4;
3262                 apdu_data.apdu = (unsigned char*) &tmp_apdu;
3263
3264                 err_code = tel_req_sim_apdu(&apdu_data, &request_id);
3265
3266                 if (err_code == TAPI_API_SUCCESS) {
3267                         TEST_DEBUG("TAPI API SUCCESS");
3268                 } else {
3269                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3270                 }
3271
3272         } else if (memcmp(buf, "atr", sizeof("atr") - 1) == 0) {
3273                 printf("------------------------------ \n");
3274                 printf("ATR request: \n");
3275                 printf("------------------------------ \n");
3276
3277                 err_code = tel_req_sim_atr(&request_id);
3278
3279                 if (err_code == TAPI_API_SUCCESS) {
3280                         TEST_DEBUG("TAPI API SUCCESS");
3281                 } else {
3282                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3283                 }
3284
3285         }
3286
3287         ////////////////////////////////////////////////////////////////////////
3288         ///////////////////////  Phone Book ///////////////////////////////////
3289         ///////////////////////////////////////////////////////////////////////
3290         else if (memcmp(buf, "pbcapa", sizeof("pbcapa") - 1) == 0) {
3291                 TEST_DEBUG("PB capability info");
3292
3293                 err_code = tel_get_sim_pb_3g_meta_info(&request_id);
3294                 if (err_code != TAPI_API_SUCCESS) {
3295                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3296                 }
3297         }
3298
3299         else if (memcmp(buf, "pbcnt", sizeof("pbcnt") - 1) == 0) {
3300                 TEST_DEBUG("PB storage count info");
3301
3302                 TelSimPbFileType_t storage_type = __InputStorageType();
3303
3304                 __PrintStorageType(storage_type);
3305
3306                 err_code = tel_get_sim_pb_count(storage_type, &request_id);
3307
3308                 if (err_code != TAPI_API_SUCCESS) {
3309                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3310                 }
3311         }
3312
3313         else if (memcmp(buf, "pbentry", sizeof("pbentry") - 1) == 0) {
3314                 TEST_DEBUG("PB Entry info");
3315
3316                 TelSimPbFileType_t storage_type = __InputStorageType();
3317
3318                 err_code = tel_get_sim_pb_meta_info(storage_type, &request_id);
3319
3320                 if (err_code != TAPI_API_SUCCESS) {
3321                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3322                 }
3323         }
3324
3325         ///////////////////////////////////
3326         /*
3327          0x01 : ADD
3328          0x02 : DELETE
3329          0x03 : EDIT
3330          0x04 : WRITE (�ش� index�� data ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ unconditional write)
3331          0x05 : DELETE ALL (�ش� phone book id�� ï¿½ï¿½ï¿½ï¿½ ï¿½ï¿½ï¿½ï¿½ï¿½Ï´ï¿½ ï¿½ï¿½ï¿½ ï¿½ï¿½ï¿½ï¿½ï¿½Í¸ï¿½ delete)
3332          */
3333         else if (memcmp(buf, "pbadd", sizeof("pbadd") - 1) == 0) {
3334                 TelSimPbRecordData_t pb_add = { 0, };
3335                 char dummy;
3336                 char unicode_text[256];
3337                 int unicode_text_len = 0;
3338                 int index = 0;
3339
3340                 TelSimPbFileType_t storage_type = __InputStorageType();
3341                 pb_add.StorageFileType = storage_type;
3342
3343                 TEST_DEBUG("Plese input index : ");
3344                 scanf("%d%c", &index, &dummy);
3345                 pb_add.Index = index;
3346
3347                 if (pb_add.StorageFileType == TAPI_SIM_PB_EN || pb_add.StorageFileType
3348                                 == TAPI_SIM_PB_FDN || pb_add.StorageFileType
3349                                 == TAPI_SIM_PB_MSISDN || pb_add.StorageFileType
3350                                 == TAPI_SIM_PB_LDN || pb_add.StorageFileType == TAPI_SIM_PB_ADN
3351                                 || pb_add.StorageFileType == TAPI_SIM_PB_SDN) {
3352                         int tmpInput;
3353                         TEST_DEBUG("2g phone book entry");
3354
3355                         TEST_DEBUG(" Number Types are below ");
3356                         TEST_DEBUG(" 1 - INTERNATIONAL");
3357                         TEST_DEBUG(" 2 - NATIONAL");
3358                         TEST_DEBUG(" 3 - NETWORK");
3359                         TEST_DEBUG(" 4 - DEDICATE");
3360                         TEST_DEBUG("Select Numer Type: ");
3361
3362                         scanf("%d%c", &tmpInput, &dummy);
3363                         pb_add.ContactInfo.Pb2GData.NumType = tmpInput;
3364
3365                         TEST_DEBUG("Plese input contact number : ");
3366                         _fgets((char *) pb_add.ContactInfo.Pb2GData.Number, 15);
3367                         pb_add.ContactInfo.Pb2GData.NumLen = strlen(
3368                                         (char*) pb_add.ContactInfo.Pb2GData.Number);
3369
3370                         TEST_DEBUG(" Encryption Types are below ");
3371                         TEST_DEBUG(" 1 - ASCII - DO NOT SUPPORT");
3372                         TEST_DEBUG(" 2 - GSM7 Bit");
3373                         TEST_DEBUG(" 3 - UCS2");
3374                         TEST_DEBUG(" 4 - HEX - DO NOT SUPPORT");
3375                         TEST_DEBUG("Select Text Encryption Type: ");
3376
3377                         scanf("%d%c", &tmpInput, &dummy);
3378                         pb_add.ContactInfo.Pb2GData.NameEncryptType = tmpInput - 1;
3379
3380                         TEST_DEBUG("Plese input contact name : ");
3381                         _fgets((char *) pb_add.ContactInfo.Pb2GData.Name, 20);
3382
3383                         if (pb_add.ContactInfo.Pb2GData.NameEncryptType
3384                                         == TAPI_SIM_TEXT_ENC_UCS2) {
3385                                 TEST_DEBUG("TAPI_SIM_TEXT_ENC_UCS2 Encoding");
3386                                 /* unicode encoding */
3387                                 if (FALSE == __encode_text_unicode(
3388                                                 strlen((char *) pb_add.ContactInfo.Pb2GData.Name),
3389                                                 (char*) pb_add.ContactInfo.Pb2GData.Name,
3390                                                 (char *) &unicode_text_len, unicode_text)) {
3391                                         TEST_DEBUG("Encoding failed ! ");
3392
3393                                 } else {
3394                                         pb_add.ContactInfo.Pb2GData.NameLen = unicode_text_len;
3395                                         memcpy(pb_add.ContactInfo.Pb2GData.Name, unicode_text,
3396                                                         unicode_text_len);
3397                                 }
3398                         } else {
3399                                 pb_add.ContactInfo.Pb2GData.NameLen = strlen(
3400                                                 (char *) pb_add.ContactInfo.Pb2GData.Name);
3401                         }
3402                 } else if (pb_add.StorageFileType == TAPI_SIM_PB_3GSIM) {
3403                         int tempi;
3404                         char num_field_type;
3405                         int i = 0;
3406
3407                         TEST_DEBUG("3g phone book entry");
3408
3409                         TEST_DEBUG("Input Nuumber of fields to be entered: ");
3410
3411                         scanf("%d%c", &tempi, &dummy);
3412
3413                         num_field_type = tempi;
3414
3415                         pb_add.ContactInfo.Pb3GData.FileTypeCount = num_field_type;
3416
3417                         for (i = 0; i < num_field_type; i++) {
3418                                 TEST_DEBUG(" Field Types are below ");
3419                                 TEST_DEBUG(" 1 - Contact Name : (EF_ADN)");
3420                                 TEST_DEBUG(" 2 - Contact Mobile Number (EF_ADN)");
3421                                 TEST_DEBUG(" 3 - Contact Another Number (EF_ANR)");
3422                                 TEST_DEBUG(" 4 - Contact Email (EF_EMAIL)");
3423                                 TEST_DEBUG(" 5 - Contact Nick Name (EF_SNE)");
3424                                 TEST_DEBUG(" 6 - Contact Group (EF_GRP)");
3425                                 TEST_DEBUG(" 7 - Contact Hidden entry (EF_PBC) - NOT SUPPORT YET");
3426                                 TEST_DEBUG(" 8 - Contact Another Number A (EF_ANRA)");
3427                                 TEST_DEBUG(" 9 - Contact Another Number B (EF_ANRB)");
3428
3429                                 TEST_DEBUG("Select Field type: ");
3430
3431                                 scanf("%d%c", &tempi, &dummy);
3432
3433                                 pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileType = tempi;
3434
3435                                 if (tempi == 1 || tempi == 4 || tempi == 5 || tempi == 6) {
3436                                         TEST_DEBUG(" Encryption Types are below ");
3437                                         TEST_DEBUG(" 1 - ASCII");
3438                                         TEST_DEBUG(" 2 - GSM7 Bit");
3439                                         TEST_DEBUG(" 3 - UCS2");
3440                                         TEST_DEBUG(" 4 - HEX");
3441                                         TEST_DEBUG("Select Text Encryption Type: ");
3442
3443                                         scanf("%d%c", &tempi, &dummy);
3444                                         pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileDataType.EncryptionType
3445                                                         = tempi - 1;
3446
3447                                 } else {
3448                                         TEST_DEBUG(" Number Types are below ");
3449                                         TEST_DEBUG(" 1 - INTERNATIONAL");
3450                                         TEST_DEBUG(" 2 - NATIONAL");
3451                                         TEST_DEBUG(" 3 - NETWORK");
3452                                         TEST_DEBUG(" 4 - DEDICATE");
3453                                         TEST_DEBUG("Select Numer Type: ");
3454
3455                                         scanf("%d%c", &tempi, &dummy);
3456                                         pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileDataType.NumType
3457                                                         = tempi;
3458                                 }
3459
3460                                 if (pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileType
3461                                                 == TAPI_PB_3G_GRP) {
3462                                         int c, count, k = 0;
3463
3464                                         TEST_DEBUG("Please input number of index to add in GRP");
3465                                         scanf("%d%c", &tempi, &dummy);
3466
3467                                         count = tempi;
3468                                         for (c = 0; c < count; c++) {
3469                                                 TEST_DEBUG("Please input index of GRP: ");
3470                                                 scanf("%d%c", &tempi, &dummy);
3471
3472                                                 pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileData[k]
3473                                                                 = tempi;
3474                                                 k++;
3475                                                 //pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileData[k] = 0;
3476                                                 //k++;
3477                                         }
3478                                         pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileDataLength
3479                                                         = count;
3480                                 } else if (pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileType
3481                                                 == TAPI_PB_3G_NAME
3482                                                 || pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileType
3483                                                                 == TAPI_PB_3G_EMAIL
3484                                                 || pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileType
3485                                                                 == TAPI_PB_3G_SNE) {
3486                                         TEST_DEBUG("Plese input  field string data: ");
3487                                         _fgets(
3488                                                         (char *) pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileData,
3489                                                         30);
3490
3491                                         TEST_DEBUG("strlen about input data[%d]",strlen((char *)pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileData) );
3492
3493                                         if (pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileDataType.EncryptionType
3494                                                         == TAPI_SIM_TEXT_ENC_UCS2) {
3495                                                 /* unicode encoding */
3496                                                 if (FALSE
3497                                                                 == __encode_text_unicode(
3498                                                                                 strlen(
3499                                                                                                 (char *) pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileData),
3500                                                                                 (char *) pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileData,
3501                                                                                 (char *) &unicode_text_len,
3502                                                                                 unicode_text)) {
3503                                                         TEST_DEBUG("Encoding failed ! ");
3504                                                 } else {
3505                                                         memcpy(
3506                                                                         pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileData,
3507                                                                         unicode_text, unicode_text_len);
3508                                                         pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileDataLength
3509                                                                         = unicode_text_len;
3510                                                 }
3511                                         } else {
3512                                                 pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileDataLength
3513                                                                 = strlen(
3514                                                                                 (char *) pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileData);
3515                                         }
3516                                 } else {
3517                                         TEST_DEBUG("Plese input  field data: ");
3518                                         _fgets(
3519                                                         (char *) pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileData,
3520                                                         20);
3521                                         pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileDataLength
3522                                                         = strlen(
3523                                                                         (char *) pb_add.ContactInfo.Pb3GData.PbFileDataInfo[i].FileData);
3524                                 }
3525
3526                         }
3527
3528                 } else if (pb_add.StorageFileType == TAPI_SIM_PB_AAS
3529                                 || pb_add.StorageFileType == TAPI_SIM_PB_GAS) {
3530                         TEST_DEBUG("additional num Alpha string or Group Alpha string ");
3531
3532                         TEST_DEBUG("Plese input Alpha name : ");
3533                         _fgets(
3534                                         (char *) pb_add.ContactInfo.PbAdditionalNumStringData.TextData,
3535                                         20);
3536 #if 0
3537                         /* GSM 7bit conversion */
3538                         __encode_gsm_7_bit_chars(strlen((char *)pb_add.ContactInfo.PbAdditionalNumStringData.TextData) ,
3539                                         (char *)pb_add.ContactInfo.PbAdditionalNumStringData.TextData, (char *)&unicode_text_len, unicode_text);
3540
3541                         memcpy(pb_add.ContactInfo.PbAdditionalNumStringData.TextData, unicode_text, unicode_text_len );
3542
3543                         pb_add.ContactInfo.PbAdditionalNumStringData.TextLength = unicode_text_len;
3544
3545                         pb_add.ContactInfo.PbAdditionalNumStringData.EncryptionType = TAPI_SIM_TEXT_ENC_GSM7BIT; // always 2 for GAS and AAS
3546 #endif
3547                         pb_add.ContactInfo.PbAdditionalNumStringData.TextLength
3548                                         = strlen(
3549                                                         (char *) pb_add.ContactInfo.PbAdditionalNumStringData.TextData);
3550                         pb_add.ContactInfo.PbAdditionalNumStringData.EncryptionType
3551                                         = TAPI_SIM_TEXT_ENC_GSM7BIT; // But real type is ASCII (because current GSM7 is GSM7 with bit 8 set to '0')
3552
3553                 } else {
3554                         TEST_DEBUG("Undefined Storage File Type [0x%x]", pb_add.StorageFileType);
3555
3556                 }
3557
3558                 err_code = tel_update_sim_pb_record(&pb_add, &request_id);
3559
3560                 if (err_code != TAPI_API_SUCCESS) {
3561                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3562                 }
3563
3564         } else if (memcmp(buf, "pbdel", sizeof("pbdel") - 1) == 0) {
3565                 TelSimPbFileType_t storage_type = __InputStorageType();
3566
3567                 TEST_DEBUG(" PB delete ");
3568
3569                 unsigned short index = 0;
3570                 char dummy = 0;
3571                 TEST_DEBUG("Plese input index : ");
3572                 scanf("%d%c", (int *)&index, &dummy);
3573
3574                 err_code = tel_delete_sim_pb_record(storage_type, index, &request_id);
3575
3576                 if (err_code != TAPI_API_SUCCESS) {
3577                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3578                 }
3579
3580         } else if (memcmp(buf, "pbread", sizeof("pbread") - 1) == 0) {
3581                 TEST_DEBUG("PB read");
3582
3583                 unsigned short index = 0;
3584                 char dummy = 0;
3585
3586                 TelSimPbFileType_t storage_type = __InputStorageType();
3587
3588                 TEST_DEBUG("Plese input index : ");
3589                 scanf("%d%c", (int *)&index, &dummy);
3590
3591                 err_code = tel_read_sim_pb_record(storage_type, index, &request_id);
3592
3593                 if (err_code != TAPI_API_SUCCESS) {
3594                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3595                 }
3596         }
3597
3598         else if (memcmp(buf, "isimauth", sizeof("isimauth") - 1) == 0) {
3599                 TEST_DEBUG("ISIM Authentication ");
3600
3601                 getchar();
3602
3603                 TelSimIsimAuthenticationData_t auth_req = { 0, };
3604
3605                 memset(&auth_req, 0, sizeof(TelSimIsimAuthenticationData_t));
3606
3607                 TEST_DEBUG(" Enter  RAND data ");
3608                 _fgets((char *) &auth_req.RandomAccessData, 20);
3609
3610                 auth_req.RandomAccessLength
3611                                 = strlen((char *) auth_req.RandomAccessData);
3612
3613                 TEST_DEBUG(" Enter Authentication  data ");
3614                 _fgets((char *) &auth_req.AuthData, 20);
3615
3616                 auth_req.AuthDataLength = strlen((char *) auth_req.AuthData);
3617
3618                 TEST_DEBUG("TelTapiSimIsimAuthenticationRequest is not tested yet!");
3619                 /*
3620                  err_code = TelTapiSimIsimAuthenticationRequest( &auth_req, &request_id);
3621
3622                  if(err_code == TAPI_API_SUCCESS)
3623                  {
3624                  TEST_DEBUG("TAPI API SUCCESS");
3625                  }
3626                  else
3627                  {
3628                  TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3629                  }
3630                  */
3631
3632         }
3633
3634         else if (memcmp(buf, "sapcon", sizeof("sapcon") - 1) == 0) {
3635                 TEST_DEBUG("SAP Connect request  ");
3636                 TelSimSapConnect_t con_req = { 0, };
3637                 con_req.MsgId = TAPI_SIM_SAP_CONNECT_REQ;
3638                 con_req.MaxMsgSize = 10; //temp for testing only - not clear
3639
3640                 err_code = tel_req_sap_connection(&con_req, &request_id);
3641
3642                 if (err_code != TAPI_API_SUCCESS) {
3643                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3644                 }
3645         }
3646
3647         else if (memcmp(buf, "sapdiscon", sizeof("sapdiscon") - 1) == 0) {
3648                 TEST_DEBUG("SAP Disconnect request  ");
3649                 TelSimSapConnect_t con_req = { 0, };
3650                 con_req.MsgId = TAPI_SIM_SAP_DISCONNECT_REQ;
3651                 con_req.MaxMsgSize = 10; //temp for testing only - not clear
3652
3653                 err_code = tel_req_sap_connection(&con_req, &request_id);
3654
3655                 if (err_code != TAPI_API_SUCCESS) {
3656                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3657                 }
3658         }
3659
3660         else if (memcmp(buf, "sapstatus", sizeof("sapstatus") - 1) == 0) {
3661                 TEST_DEBUG("SAP Status request  ");
3662
3663                 err_code = tel_req_sap_connection_status(&request_id);
3664
3665                 if (err_code != TAPI_API_SUCCESS) {
3666                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3667                 }
3668         }
3669
3670         else if (memcmp(buf, "sapatr", sizeof("sapatr") - 1) == 0) {
3671                 TEST_DEBUG("SAP ATR request  ");
3672
3673                 err_code = tel_req_sap_transfer_atr(&request_id);
3674
3675                 if (err_code != TAPI_API_SUCCESS) {
3676                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3677                 }
3678         }
3679
3680         else if (memcmp(buf, "sapapdu", sizeof("sapapdu") - 1) == 0) {
3681                 TEST_DEBUG("SAP APDU transfer  ");
3682
3683                 int file_id = TAPI_SIM_EFILE_ICCID;
3684
3685                 /* for selecting EF ICCID */
3686                 TelSimSapApduData_t apdu_data;
3687
3688                 apdu_data.ApduLength = 7;
3689                 apdu_data.Apdu[0] = 0xA0; // class
3690                 apdu_data.Apdu[1] = 0xA4; // instruction
3691                 apdu_data.Apdu[2] = 0; // p1 = parameter 1
3692                 apdu_data.Apdu[3] = 0; // p2 = parameter 2
3693                 apdu_data.Apdu[4] = 2; // p3 - parameter 3
3694
3695                 memcpy(&apdu_data.Apdu[5], &file_id, sizeof(unsigned short));
3696
3697                 err_code = tel_req_sap_transfer_apdu(&apdu_data, &request_id);
3698
3699                 if (err_code == TAPI_API_SUCCESS) {
3700                         TEST_DEBUG("TAPI API SUCCESS");
3701                 } else {
3702                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3703                 }
3704         }
3705
3706         else if (memcmp(buf, "sapsetproto", sizeof("sapsetproto") - 1) == 0) {
3707                 TEST_DEBUG("SAP set protocol ");
3708                 TelSimSapProtocol_t protocol = TAPI_SIM_SAP_PROTOCOL_T0;
3709
3710                 err_code = tel_req_sap_transport_protocol(protocol, &request_id);
3711
3712                 if (err_code != TAPI_API_SUCCESS) {
3713                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3714                 }
3715         }
3716
3717         else if (memcmp(buf, "sapsimpwr", sizeof("sapsimpwr") - 1) == 0) {
3718                 int tempi = 0;
3719                 TelSimSapMsgId_t msdId = 0;
3720
3721                 char dummy = 0;
3722
3723                 TEST_DEBUG("SAP SIM power  ");
3724
3725                 TEST_DEBUG("Please input SAP SIM power on(1) / off(!1): ");
3726
3727                 scanf("%d%c", &tempi, &dummy);
3728                 if (tempi == 1)
3729                         msdId = TAPI_SIM_SAP_POWER_SIM_ON_REQ;
3730                 else
3731                         msdId = TAPI_SIM_SAP_POWER_SIM_OFF_REQ;
3732
3733                 err_code = tel_req_sap_power_operation(msdId, &request_id);// only for testing
3734
3735                 if (err_code != TAPI_API_SUCCESS) {
3736                         TEST_DEBUG("TAPI API FAIL: Error Code [0x%x]",err_code);
3737                 }
3738         }
3739
3740         if (memcmp(buf, "close", sizeof("close") - 1) == 0) {
3741                 TEST_DEBUG(" close reuqest ");
3742
3743                 //      err_code = tapi_sim_close(92);
3744
3745                 //err_code = tapi_sim_close(g_test_hsim);
3746                 TEST_DEBUG(" ret value from close [0x%x]", err_code);
3747
3748                 if (err_code == TAPI_API_SUCCESS) {
3749                         TEST_DEBUG(" sim close OK!");
3750                 } else {
3751                         TEST_DEBUG(" SIM close request returned error [0x%x] !",err_code );
3752                 }
3753                 TEST_DEBUG("Request ID [0x%x]", request_id);
3754         }
3755
3756         if (memcmp(buf, "q", sizeof("q") - 1) == 0) {
3757                 TEST_DEBUG("Finished Testing this module, Going back to Main Menu");
3758                 return -1;
3759                 //exit(0);
3760         }
3761
3762         return 0;
3763 }
3764
3765 void sim_select_loop(void) {
3766         int ret;
3767         fd_set readfds;
3768
3769         while (1) {
3770                 FD_ZERO(&readfds);
3771                 FD_SET(0, &readfds);
3772
3773                 ret = select(0 + 1, &readfds, NULL, NULL, NULL);
3774                 if (ret) {
3775
3776                         if (FD_ISSET(0, &readfds)) {
3777                                 if (sim_read_key_input() < 0)
3778                                         break;
3779                         }
3780                 }
3781         }
3782 }
3783
3784 void* sim_test_thread_loop(void* data) {
3785         TEST_DEBUG(" sim_test_thread_loop : called...");
3786
3787         sim_select_loop();
3788
3789         TEST_DEBUG(" sim_test_thread_loop : stdin Loop exited");
3790
3791         pthread_exit(NULL);
3792 }
3793
3794 int sim_main(int argc, char *argv[]) {
3795         pthread_t p_thread;
3796
3797         p_thread = pthread_create(&p_thread, NULL, sim_test_thread_loop, NULL);
3798
3799         if (p_thread != 0) {
3800                 TEST_DEBUG("Failed while creating a thread to read from stdin");
3801                 return -1;
3802         } else {
3803                 TEST_DEBUG("A thread was created to read from stdin ..");
3804         }
3805
3806         sim_test_subscribe_tapi_events();
3807
3808         pthread_join(p_thread, NULL);
3809
3810         TEST_DEBUG("Exiting sim test program bye bye !");
3811
3812         return 0;
3813 }
3814