Initialize Tizen 2.3
[framework/telephony/libslp-tapi.git] / test_src / sim.c
1 /*
2  * libslp-tapi
3  *
4  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Ja-young Gu <jygu@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 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <sys/time.h>
25 #include <unistd.h>
26 #include <glib.h>
27
28 #include <tapi_common.h>
29 #include <ITapiSim.h>
30 #include <TapiUtility.h>
31
32 #include "menu.h"
33 #include "sim.h"
34
35 #define CHECK_RT(x) \
36 { \
37         if((x) != 0) { \
38                 msg("api call failed with[%d]",x); \
39                 return 0; \
40         } \
41 }
42
43 #define CHECK_ACCESS_RT(x) \
44 { \
45         if((x) != 0) { \
46                 msg("api call failed with[%d]",x); \
47                 return; \
48         } \
49 }
50
51 static char data_sim_set_language[MENU_DATA_SIZE + 1] = { 0x01, };
52 static char data_sim_set_state[MENU_DATA_SIZE + 1] = { 0x01, };
53
54
55 static char data_sim_set_cf_b_cphs[MENU_DATA_SIZE + 1] = { };
56 static char data_sim_set_cf_rec_index[MENU_DATA_SIZE + 1] = { };
57 static char data_sim_set_cf_msp_num[MENU_DATA_SIZE + 1] = { };
58 static char data_sim_set_cf_cfu_status[MENU_DATA_SIZE + 1] = { };
59 static char data_sim_set_cf_ton[MENU_DATA_SIZE + 1] = { };
60 static char data_sim_set_cf_npi[MENU_DATA_SIZE + 1] = { };
61 static char data_sim_set_cf_number[MENU_DATA_SIZE + 1] = { };
62 static char data_sim_set_cf_cc2_id[MENU_DATA_SIZE + 1] = { };
63 static char data_sim_set_cf_ext7_id[MENU_DATA_SIZE + 1] = { };
64 static char data_sim_set_cf_cphs_line1[MENU_DATA_SIZE + 1] = { };
65 static char data_sim_set_cf_cphs_line2[MENU_DATA_SIZE + 1] = { };
66 static char data_sim_set_cf_cphs_fax[MENU_DATA_SIZE + 1] = { };
67 static char data_sim_set_cf_cphs_data[MENU_DATA_SIZE + 1] = { };
68
69 static char data_sim_set_mw_b_cphs[MENU_DATA_SIZE + 1] = { };
70 static char data_sim_set_mw_rec_index[MENU_DATA_SIZE + 1] = { };
71 static char data_sim_set_mw_indicator_status[MENU_DATA_SIZE + 1] = { };
72 static char data_sim_set_mw_voice_cnt[MENU_DATA_SIZE + 1] = { };
73 static char data_sim_set_mw_fax_cnt[MENU_DATA_SIZE + 1] = { };
74 static char data_sim_set_mw_email_cnt[MENU_DATA_SIZE + 1] = { };
75 static char data_sim_set_mw_other_cnt[MENU_DATA_SIZE + 1] = { };
76 static char data_sim_set_mw_video_cnt[MENU_DATA_SIZE + 1] = { };
77 static char data_sim_set_mw_cphs_voice1[MENU_DATA_SIZE + 1] = { };
78 static char data_sim_set_mw_cphs_voice2[MENU_DATA_SIZE + 1] = { };
79 static char data_sim_set_mw_cphs_fax[MENU_DATA_SIZE + 1] = { };
80 static char data_sim_set_mw_cphs_data[MENU_DATA_SIZE + 1] = { };
81
82 static char data_sim_set_mb_b_cphs[MENU_DATA_SIZE + 1] = { };
83 static char data_sim_set_mb_type[MENU_DATA_SIZE + 1] = { };
84 static char data_sim_set_mb_rec_index[MENU_DATA_SIZE + 1] = { };
85 static char data_sim_set_mb_profile_num[MENU_DATA_SIZE + 1] = { };
86 static char data_sim_set_mb_alpha_id_max_len[MENU_DATA_SIZE + 1] = { };
87 static char data_sim_set_mb_alpha_id[MENU_DATA_SIZE + 1] = { };
88 static char data_sim_set_mb_ton[MENU_DATA_SIZE + 1] = { };
89 static char data_sim_set_mb_npi[MENU_DATA_SIZE + 1] = { };
90 static char data_sim_set_mb_number[MENU_DATA_SIZE + 1] = { };
91 static char data_sim_set_mb_cc_id[MENU_DATA_SIZE + 1] = { };
92 static char data_sim_set_mb_ext1_id[MENU_DATA_SIZE + 1] = { };
93
94 static char data_sim_req_authentication_type[MENU_DATA_SIZE + 1] = { 0x01, }; //SIM_AUTH_TYPE_GSM
95 static char data_sim_req_authentication_autn_data[MENU_DATA_SIZE + 1] = { 200,
96                 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200,
97                 200, };
98 static char data_sim_req_authentication_rand_data[MENU_DATA_SIZE + 1] = { 200,
99                 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200,
100                 200, };
101
102 static char data_sim_verify_pins_type[MENU_DATA_SIZE + 1] = "0";
103 static char data_sim_verify_pins_pw[MENU_DATA_SIZE + 1] = { };
104
105 static char data_sim_verify_puks_type[MENU_DATA_SIZE + 1] = "2";
106 static char data_sim_verify_puks_puk[MENU_DATA_SIZE + 1] = { };
107 static char data_sim_verify_puks_pin[MENU_DATA_SIZE + 1] = { };
108
109 static char data_sim_change_pins_type[MENU_DATA_SIZE + 1] = "0";
110 static char data_sim_change_pins_old_pw[MENU_DATA_SIZE + 1] = "";
111 static char data_sim_change_pins_new_pw[MENU_DATA_SIZE + 1] = "";
112
113 static char data_sim_disable_facility_type[MENU_DATA_SIZE + 1] = "1";
114 static char data_sim_disable_facility_pw[MENU_DATA_SIZE + 1] = { };
115
116 static char data_sim_enable_facility_type[MENU_DATA_SIZE + 1] = { };
117 static char data_sim_enable_facility_pw[MENU_DATA_SIZE + 1] = { };
118
119 static char data_sim_get_facility_type[MENU_DATA_SIZE + 1] = "1";
120
121 static char data_sim_get_lock_type[MENU_DATA_SIZE + 1] = "1";
122
123 static char data_sim_transmit_apdu_apdu[MENU_DATA_SIZE + 1] = "0070000000";
124
125 static int _sim_str_to_hex (char a)
126 {
127         int ret = 0;
128
129         if (a >= '0' && a <= '9')
130                 ret = a - '0';
131         else if (a >= 'a' && a <= 'f')
132                 ret = a - 'a' + 10;
133         //printf("'%c' => %d(0x%x)\n", a, ret, ret);
134         return ret;
135 }
136
137 static void on_noti_sim_status (TapiHandle *handle, const char *noti_id,
138                 void *data, void *user_data)
139 {
140         TelSimCardStatus_t *status = data;
141
142         msg("");
143         msgb("event(%s) receive !!", TAPI_NOTI_SIM_STATUS);
144         msg("status[%d]", *status);
145 }
146
147 static void on_noti_sim_cf_state(TapiHandle *handle, const char *noti_id,
148                 void *data, void *user_data)
149 {
150         int *status = data;
151         msg("");
152         msgp ("property(%s) receive !!", TAPI_PROP_SIM_CALL_FORWARD_STATE);
153         if(status)
154                 msg("status[%d]", *status);
155 }
156
157 static int run_sim_get_init_info (MManager *mm, struct menu_data *menu)
158 {
159         TapiHandle *handle = menu_manager_ref_user_data (mm);
160         int rt = 0;
161         TelSimCardStatus_t o_status = 0;
162         gboolean o_new = FALSE;
163
164         msg("call [%s] tapi service !!!", menu->title);
165
166         rt = tel_get_sim_init_info (handle, &o_status, &o_new);
167         CHECK_RT(rt);
168
169         msg("status[%d]", o_status);
170         msg("new_sim[%d]", o_new);
171         return 0;
172 }
173
174 static int run_sim_get_card_type (MManager *mm, struct menu_data *menu)
175 {
176         TapiHandle *handle = menu_manager_ref_user_data (mm);
177         int rt = 0;
178         TelSimCardType_t o_type = 0;
179
180         msg("call [%s] tapi service !!!", menu->title);
181
182         rt = tel_get_sim_type (handle, &o_type);
183         CHECK_RT(rt);
184
185         msg("card type[%d]", o_type);
186         return 0;
187 }
188
189 static int run_sim_get_imsi (MManager *mm, struct menu_data *menu)
190 {
191         TapiHandle *handle = menu_manager_ref_user_data (mm);
192         int rt = 0;
193         TelSimImsiInfo_t imsi;
194         memset (&imsi, 0, sizeof(TelSimImsiInfo_t));
195
196         msg("call [%s] tapi service !!!", menu->title);
197
198         rt = tel_get_sim_imsi (handle, &imsi);
199         CHECK_RT(rt);
200
201         msg("mcc[%s]", imsi.szMcc);
202         msg("mnc[%s]", imsi.szMnc);
203         msg("msin[%s]", imsi.szMsin);
204         return 0;
205 }
206
207 static int run_sim_get_ecc (MManager *mm, struct menu_data *menu)
208 {
209         TapiHandle *handle = menu_manager_ref_user_data (mm);
210         int rt = 0;
211         TelSimEccList_t ecc_list;
212         int i = 0;
213         memset (&ecc_list, 0, sizeof(TelSimEccList_t));
214
215         msg("call [%s] tapi service !!!", menu->title);
216
217         rt = tel_get_sim_ecc (handle, &ecc_list);
218         CHECK_RT(rt);
219
220         msg("ecc_list.ecc_count[%d]", ecc_list.ecc_count);
221
222         for (i = 0; i < ecc_list.ecc_count; i++) {
223                 msg("ecc_list.list[%d].name[%s]", i, ecc_list.list[i].name);
224                 msg("ecc_list.list[%d].number[%s]", i, ecc_list.list[i].number);
225                 msg("ecc_list.list[%d].category[%d]", i, ecc_list.list[i].category);
226         }
227         return 0;
228 }
229
230 static void on_sim_get_iccid (TapiHandle *handle, int result, void *data,
231                 void *user_data)
232 {
233         TelSimAccessResult_t access_rt = result;
234         TelSimIccIdInfo_t *iccid = data;
235
236         msg("TAPI_SERVICE_SIM_GET_ICCID response received");
237
238         CHECK_ACCESS_RT(access_rt);
239
240         msg("access_rt[%d]", access_rt);
241         msg("iccid length[%d]", iccid->icc_length);
242         msg("iccid[%s]", iccid->icc_num);
243 }
244
245 static int run_sim_get_iccid (MManager *mm, struct menu_data *menu)
246 {
247         TapiHandle *handle = menu_manager_ref_user_data (mm);
248         int rt = 0;
249
250         msg("call [%s] tapi service !!!", menu->title);
251
252         rt = tel_get_sim_iccid (handle, on_sim_get_iccid, NULL );
253         CHECK_RT(rt);
254         return 0;
255 }
256
257 static void on_sim_get_language (TapiHandle *handle, int result, void *data,
258                 void *user_data)
259 {
260         TelSimLanguagePreferenceCode_t *language = data;
261         TelSimAccessResult_t access_rt = result;
262
263         msg("TAPI_SERVICE_SIM_GET_LANGUAGE response received");
264
265         CHECK_ACCESS_RT(access_rt);
266
267         msg("access rt[%d]", access_rt);
268         msg("language[%d]", *language);
269 }
270
271 static int run_sim_get_language (MManager *mm, struct menu_data *menu)
272 {
273         TapiHandle *handle = menu_manager_ref_user_data (mm);
274         int rt = 0;
275
276         msg("call [%s] tapi service !!!", menu->title);
277
278         rt = tel_get_sim_language (handle, on_sim_get_language, NULL );
279         CHECK_RT(rt);
280         return 0;
281 }
282
283 static void on_sim_set_language (TapiHandle *handle, int result, void *data,
284                 void *user_data)
285 {
286         TelSimAccessResult_t access_rt = result;
287
288         msg("TAPI_SERVICE_SIM_SET_LANGUAGE response received");
289
290         CHECK_ACCESS_RT(access_rt);
291
292         msg("access_rt[%d]", access_rt);
293 }
294
295 static int run_sim_set_language (MManager *mm, struct menu_data *menu)
296 {
297         TapiHandle *handle = menu_manager_ref_user_data (mm);
298         int rt = 0;
299
300         msg("call [%s] tapi service !!!", menu->title);
301         data_sim_set_language[0] = data_sim_set_language[0] - '0';
302         rt = tel_set_sim_language (handle, data_sim_set_language[0],
303                         on_sim_set_language, NULL );
304         CHECK_RT(rt);
305         return 0;
306 }
307
308 static void on_sim_get_cf (TapiHandle *handle, int result, void *data,
309                 void *user_data)
310 {
311         TelSimAccessResult_t access_rt = result;
312         TelSimCallForwardingResp_t *cf = data;
313         int i = 0;
314         msg("TAPI_SERVICE_SIM_GET_CF response received");
315
316         CHECK_ACCESS_RT(access_rt);
317
318         msg("access_rt[%d]", access_rt);
319         msg("cf->b_cphs[%d]", cf->b_cphs);
320
321         if (cf->b_cphs) {
322                 msg("cf->cphs_cf.b_line1[%d]", cf->cphs_cf.b_line1);
323                 msg("cf->cphs_cf.b_line2[%d]", cf->cphs_cf.b_line2);
324                 msg("cf->cphs_cf.b_fax[%d]", cf->cphs_cf.b_fax);
325                 msg("cf->cphs_cf.b_data[%d]", cf->cphs_cf.b_data);
326         }
327         else {
328                 for (i = 0; i < cf->cf_list.profile_count; i++) {
329                         msg("cf->cf_list.cf[%d].rec_index[%d]", i,
330                                         cf->cf_list.cf[i].rec_index);
331                         msg("cf->cf_list.cf[%d].msp_num[%d]", i, cf->cf_list.cf[i].msp_num);
332                         msg("cf->cf_list.cf[%d].cfu_status[0x%x]", i,
333                                         cf->cf_list.cf[i].cfu_status);
334                         msg("cf->cf_list.cf[%d].cfu_num[%s]", i, cf->cf_list.cf[i].cfu_num);
335                         msg("cf->cf_list.cf[%d].ton[%d]", i, cf->cf_list.cf[i].ton);
336                         msg("cf->cf_list.cf[%d].npi[%d]", i, cf->cf_list.cf[i].npi);
337                         msg("cf->cf_list.cf[%d].cc2_id[0x%x]", i, cf->cf_list.cf[i].cc2_id);
338                         msg("cf->cf_list.cf[%d].ext7_id[0x%x]", i,
339                                         cf->cf_list.cf[i].ext7_id);
340                 }
341         }
342 }
343
344 static int run_sim_get_cf (MManager *mm, struct menu_data *menu)
345 {
346         TapiHandle *handle = menu_manager_ref_user_data (mm);
347         int rt = 0;
348
349         msg("call [%s] tapi service !!!", menu->title);
350         rt = tel_get_sim_callforwarding_info (handle, on_sim_get_cf, NULL );
351         CHECK_RT(rt);
352         return 0;
353 }
354
355 static void on_sim_set_cf (TapiHandle *handle, int result, void *data,
356                 void *user_data)
357 {
358         TelSimAccessResult_t access_rt = result;
359
360         msg("response received");
361
362         CHECK_ACCESS_RT(access_rt);
363
364         msg("access_rt[%d]", access_rt);
365 }
366
367 static int run_sim_set_cf (MManager *mm, struct menu_data *menu)
368 {
369         TapiHandle *handle = menu_manager_ref_user_data (mm);
370         int rt = 0;
371         TelSimCallForwardingReq_t cf;
372         memset (&cf, 0, sizeof(TelSimCallForwardingReq_t));
373
374         msg("call [%s] tapi service !!!", menu->title);
375
376         cf.b_cphs = data_sim_set_cf_b_cphs[0] - '0';
377         if (cf.b_cphs) {
378                 cf.cf_data_u.cphs_cf.b_line1 = data_sim_set_cf_cphs_line1[0] - '0';
379                 cf.cf_data_u.cphs_cf.b_line2 = data_sim_set_cf_cphs_line2[0] - '0';
380                 cf.cf_data_u.cphs_cf.b_fax = data_sim_set_cf_cphs_fax[0] - '0';
381                 cf.cf_data_u.cphs_cf.b_data = data_sim_set_cf_cphs_data[0] - '0';
382         }
383         else {
384                 cf.cf_data_u.cf.rec_index = data_sim_set_cf_rec_index[0] - '0';
385                 cf.cf_data_u.cf.msp_num = data_sim_set_cf_msp_num[0] - '0';
386                 cf.cf_data_u.cf.cfu_status = data_sim_set_cf_cfu_status[0] - '0';
387                 cf.cf_data_u.cf.ton = data_sim_set_cf_ton[0] - '0';
388                 cf.cf_data_u.cf.npi = data_sim_set_cf_npi[0] - '0';
389                 memcpy (&cf.cf_data_u.cf.cfu_num, data_sim_set_cf_number,
390                                 sizeof (cf.cf_data_u.cf.cfu_num));
391                 cf.cf_data_u.cf.cc2_id = data_sim_set_cf_cc2_id[0] - '0';
392                 cf.cf_data_u.cf.ext7_id = data_sim_set_cf_ext7_id[0] - '0';
393         }
394
395         rt = tel_set_sim_callforwarding_info (handle, &cf, on_sim_set_cf, NULL );
396         CHECK_RT(rt);
397         return 0;
398 }
399
400 static void on_sim_get_mw (TapiHandle *handle, int result, void *data,
401                 void *user_data)
402 {
403         TelSimAccessResult_t access_rt = result;
404         TelSimMessageWaitingResp_t *mw = data;
405         int i = 0;
406
407         msg("TAPI_SERVICE_SIM_GET_MW response received");
408
409         CHECK_ACCESS_RT(access_rt);
410
411         msg("access_rt[%d]", access_rt);
412         msg("mw->b_cphs[%d]", mw->b_cphs);
413
414         if (mw->b_cphs) {
415                 msg("mw->cphs_mw.b_voice1[%d]", mw->cphs_mw.b_voice1);
416                 msg("mw->cphs_mw.b_voice2[%d]", mw->cphs_mw.b_voice2);
417                 msg("mw->cphs_mw.b_fax[%d]", mw->cphs_mw.b_fax);
418                 msg("mw->cphs_mw.b_data[%d]", mw->cphs_mw.b_data);
419         }
420         else {
421                 for (i = 0; i < mw->mw_list.profile_count; i++) {
422                         msg("mw->mw_list.mw[%d].rec_index[%d]", i,
423                                         mw->mw_list.mw[i].rec_index);
424                         msg("mw->mw_list.mw[%d].indicator_status[0x%x]", i,
425                                         mw->mw_list.mw[i].indicator_status);
426                         msg("mw->mw_list.mw[%d].voice_count[%d]", i,
427                                         mw->mw_list.mw[i].voice_count);
428                         msg("mw->mw_list.mw[%d].fax_count[%d]", i,
429                                         mw->mw_list.mw[i].fax_count);
430                         msg("mw->mw_list.mw[%d].email_count[%d]", i,
431                                         mw->mw_list.mw[i].email_count);
432                         msg("mw->mw_list.mw[%d].other_count[%d]", i,
433                                         mw->mw_list.mw[i].other_count);
434                         msg("mw->mw_list.mw[%d].video_count[%d]", i,
435                                         mw->mw_list.mw[i].video_count);
436                 }
437         }
438 }
439
440 static int run_sim_get_mw (MManager *mm, struct menu_data *menu)
441 {
442         TapiHandle *handle = menu_manager_ref_user_data (mm);
443         int rt = 0;
444
445         msg("call [%s] tapi service !!!", menu->title);
446         rt = tel_get_sim_messagewaiting_info (handle, on_sim_get_mw, NULL );
447         CHECK_RT(rt);
448         return 0;
449 }
450
451 static void on_sim_set_mw (TapiHandle *handle, int result, void *data,
452                 void *user_data)
453 {
454         TelSimAccessResult_t access_rt = result;
455
456         msg("response received");
457
458         CHECK_ACCESS_RT(access_rt);
459
460         msg("access_rt[%d]", access_rt);
461 }
462
463 static int run_sim_set_mw (MManager *mm, struct menu_data *menu)
464 {
465         TapiHandle *handle = menu_manager_ref_user_data (mm);
466         int rt = 0;
467         TelSimMessageWaitingReq_t mw;
468
469         memset (&mw, 0, sizeof(TelSimMessageWaitingReq_t));
470
471         msg("call [%s] tapi service !!!", menu->title);
472
473         mw.b_cphs = data_sim_set_mw_b_cphs[0] - '0';
474
475         if (mw.b_cphs) {
476                 mw.mw_data_u.cphs_mw.b_voice1 = data_sim_set_mw_cphs_voice1[0] - '0';
477                 mw.mw_data_u.cphs_mw.b_voice2 = data_sim_set_mw_cphs_voice2[0] - '0';
478                 mw.mw_data_u.cphs_mw.b_fax = data_sim_set_mw_cphs_fax[0] - '0';
479                 mw.mw_data_u.cphs_mw.b_data = data_sim_set_mw_cphs_data[0] - '0';
480         }
481         else {
482                 mw.mw_data_u.mw.rec_index = data_sim_set_mw_rec_index[0] - '0';
483                 mw.mw_data_u.mw.indicator_status = data_sim_set_mw_indicator_status[0]
484                                 - '0';
485                 mw.mw_data_u.mw.voice_count = data_sim_set_mw_voice_cnt[0] - '0';
486                 mw.mw_data_u.mw.fax_count = data_sim_set_mw_fax_cnt[0] - '0';
487                 mw.mw_data_u.mw.email_count = data_sim_set_mw_email_cnt[0] - '0';
488                 mw.mw_data_u.mw.other_count = data_sim_set_mw_other_cnt[0] - '0';
489                 mw.mw_data_u.mw.video_count = data_sim_set_mw_video_cnt[0] - '0';
490         }
491
492         rt = tel_set_sim_messagewaiting_info (handle, &mw, on_sim_set_mw, NULL );
493         CHECK_RT(rt);
494         return 0;
495 }
496
497 static void on_sim_get_mb (TapiHandle *handle, int result, void *data,
498                 void *user_data)
499 {
500         TelSimAccessResult_t access_rt = result;
501         TelSimMailboxList_t *list = data;
502         int i = 0;
503
504         msg("TAPI_SERVICE_SIM_GET_MB response received");
505
506         CHECK_ACCESS_RT(access_rt);
507
508         msg("access_rt[%d]", access_rt);
509         msg("count[%d]", list->count);
510
511         for (i = 0; i < list->count; i++) {
512                 msg("list->list[%d].b_cphs[%d]", i, list->list[i].b_cphs);
513                 msg("list->list[%d].rec_index[%d]", i, list->list[i].rec_index);
514                 msg("list->list[%d].profile_num[%d]", i, list->list[i].profile_num);
515                 msg("list->list[%d].mb_type[%d]", i, list->list[i].mb_type);
516                 msg("list->list[%d].alpha_id_max_len[%d]", i,
517                                 list->list[i].alpha_id_max_len);
518                 msg("list->list[%d].alpha_id[%s]", i, list->list[i].alpha_id);
519                 msg("list->list[%d].ton[0x%x]", i, list->list[i].ton);
520                 msg("list->list[%d].npi[0x%x]", i, list->list[i].npi);
521                 msg("list->list[%d].num[%s]", i, list->list[i].num);
522                 msg("list->list[%d].cc_id[0x%x]", i, list->list[i].cc_id);
523                 msg("list->list[%d].ext1_id[0x%x]", i, list->list[i].ext1_id);
524         }
525 }
526
527 static int run_sim_get_mb (MManager *mm, struct menu_data *menu)
528 {
529         TapiHandle *handle = menu_manager_ref_user_data (mm);
530         int rt = 0;
531
532         msg("call [%s] tapi service !!!", menu->title);
533         rt = tel_get_sim_mailbox_info (handle, on_sim_get_mb, NULL );
534         CHECK_RT(rt);
535         return 0;
536 }
537
538 static void on_sim_set_mb (TapiHandle *handle, int result, void *data,
539                 void *user_data)
540 {
541         TelSimAccessResult_t access_rt = result;
542
543         msg("response received");
544
545         CHECK_ACCESS_RT(access_rt);
546
547         msg("access_rt[%d]", access_rt);
548 }
549
550 static int run_sim_set_mb (MManager *mm, struct menu_data *menu)
551 {
552         TapiHandle *handle = menu_manager_ref_user_data (mm);
553         int rt = 0;
554         TelSimMailBoxNumber_t mb;
555
556         msg("call [%s] tapi service !!!", menu->title);
557
558         memset (&mb, 0, sizeof(TelSimMailBoxNumber_t));
559
560         mb.b_cphs = data_sim_set_mb_b_cphs[0] - '0';
561         mb.mb_type = data_sim_set_mb_type[0] - '0';
562         mb.rec_index = data_sim_set_mb_rec_index[0] - '0';
563         mb.profile_num = data_sim_set_mb_profile_num[0] - '0';
564         mb.alpha_id_max_len = data_sim_set_mb_alpha_id_max_len[0] - '0';
565         memcpy (&mb.alpha_id, data_sim_set_mb_alpha_id,
566                         TAPI_SIM_XDN_ALPHA_ID_MAX_LEN);
567         mb.ton = data_sim_set_mb_ton[0] - '0';
568         mb.npi = data_sim_set_mb_npi[0] - '0';
569         memcpy (&mb.num, data_sim_set_mb_number, sizeof (mb.num));
570         mb.cc_id = data_sim_set_mb_cc_id[0] - '0';
571         mb.ext1_id = data_sim_set_mb_ext1_id[0] - '0';
572
573         rt = tel_set_sim_mailbox_info (handle, &mb, on_sim_set_mb, NULL );
574         CHECK_RT(rt);
575         return 0;
576 }
577
578 static void on_sim_get_cphs_info (TapiHandle *handle, int result, void *data,
579                 void *user_data)
580 {
581         TelSimAccessResult_t access_rt = result;
582         TelSimCphsInfo_t *cphs = data;
583
584         msg("TAPI_SERVICE_SIM_GET_CPHSINFO response received");
585
586         CHECK_ACCESS_RT(access_rt);
587
588         msg("access_rt[%d]", access_rt);
589         msg("cphs->CphsPhase[%d]", cphs->CphsPhase);
590         msg("cphs->CphsServiceTable.bOperatorNameShortForm[%d]",
591                         cphs->CphsServiceTable.bOperatorNameShortForm);
592         msg("cphs->CphsServiceTable.bMailBoxNumbers[%d]",
593                         cphs->CphsServiceTable.bMailBoxNumbers);
594         msg("cphs->CphsServiceTable.bServiceStringTable[%d]",
595                         cphs->CphsServiceTable.bServiceStringTable);
596         msg("cphs->CphsServiceTable.bCustomerServiceProfile[%d]",
597                         cphs->CphsServiceTable.bCustomerServiceProfile);
598         msg("cphs->CphsServiceTable.bInformationNumbers[%d]",
599                         cphs->CphsServiceTable.bInformationNumbers);
600 }
601
602 static void on_sim_get_service_table (TapiHandle *handle, int result,
603                 void *data, void *user_data)
604 {
605         TelSimAccessResult_t access_rt = result;
606         TelSimServiceTable_t *svct = (TelSimServiceTable_t *) data;
607
608         msg("TAPI_SERVICE_SIM_GET_SERVICE_TABLE response received");
609
610         CHECK_ACCESS_RT(access_rt);
611
612         msg("access_rt[%d]", access_rt);
613
614         if (svct->sim_type == TAPI_SIM_CARD_TYPE_GSM) {
615                 int i = 0, size = sizeof(TelSimSST_t);
616                 char *temp = NULL;
617                 if ( (temp = (char *) calloc (size + 1, 1)) != NULL ) {
618                         memcpy (temp, &svct->table.sst, size);
619                         for (i = 0; i < size; i++) {
620                                 if (temp[i] == 1)
621                                         temp[i] = '1';
622                                 else
623                                         temp[i] = '0';
624                         }
625                         msg("svct->table.sst=[%s]", temp);
626                         free (temp);
627                 }
628         }
629         else if (svct->sim_type == TAPI_SIM_CARD_TYPE_USIM) {
630                 int i = 0, size = sizeof(TelSimUST_t);
631                 char *temp = NULL;
632                 if ( (temp = (char *) calloc (size + 1, 1)) != NULL ) {
633                         memcpy (temp, &svct->table.ust, size);
634                         for (i = 0; i < size; i++) {
635                                 if (temp[i] == 1)
636                                         temp[i] = '1';
637                                 else
638                                         temp[i] = '0';
639                         }
640                         msg("svct->table.ust=[%s]", temp);
641                         free (temp);
642                 }
643         }
644         else {
645                 msg("Unknown sim type");
646         }
647 }
648
649 static int run_sim_get_cphs_info (MManager *mm, struct menu_data *menu)
650 {
651         TapiHandle *handle = menu_manager_ref_user_data (mm);
652         int rt = 0;
653
654         msg("call [%s] tapi service !!!", menu->title);
655         rt = tel_get_sim_cphs_info (handle, on_sim_get_cphs_info, NULL );
656         CHECK_RT(rt);
657         return 0;
658 }
659
660 static int run_sim_get_service_table (MManager *mm, struct menu_data *menu)
661 {
662         TapiHandle *handle = menu_manager_ref_user_data (mm);
663         int rt = 0;
664
665         msg("call [%s] tapi service !!!", menu->title);
666         rt = tel_get_sim_service_table (handle, on_sim_get_service_table, NULL );
667         CHECK_RT(rt);
668         return 0;
669 }
670
671 static void on_sim_get_msisdn (TapiHandle *handle, int result, void *data,
672                 void *user_data)
673 {
674         TelSimAccessResult_t access_rt = result;
675         TelSimMsisdnList_t *list = data;
676         int i = 0;
677         msg("TAPI_SERVICE_SIM_GET_MSISDN response received");
678
679         CHECK_ACCESS_RT(access_rt);
680
681         msg("access_rt[%d]", access_rt);
682
683         msg("list->count[%d]", list->count);
684
685         for (i = 0; i < list->count; i++)
686                 msg("index[%d] - name[%s], num[%s]", i, list->list[i].name,
687                                 list->list[i].num);
688 }
689
690 static int run_sim_get_msisdn (MManager *mm, struct menu_data *menu)
691 {
692         TapiHandle *handle = menu_manager_ref_user_data (mm);
693         int rt = 0;
694
695         msg("call [%s] tapi service !!!", menu->title);
696         rt = tel_get_sim_msisdn (handle, on_sim_get_msisdn, NULL );
697         CHECK_RT(rt);
698         return 0;
699 }
700
701 static void on_sim_get_oplmnwact (TapiHandle *handle, int result, void *data,
702                 void *user_data)
703 {
704         TelSimAccessResult_t access_rt = result;
705         TelSimOplmnwactList_t *list = data;
706         int i = 0;
707
708         msg("TAPI_SERVICE_SIM_GET_OPLMNWACT response received");
709
710         CHECK_ACCESS_RT(access_rt);
711
712         msg("access_rt[%d]", access_rt);
713         msg("list->count[%d]", list->count);
714
715         for (i = 0; i < list->count; i++) {
716                 msg("index[%d] - plmn[%s], b_umts[%d], b_gsm[%d]", i,
717                                 list->list[i].plmn, list->list[i].b_umts, list->list[i].b_gsm);
718         }
719 }
720
721 static int run_sim_get_oplmnwact (MManager *mm, struct menu_data *menu)
722 {
723         TapiHandle *handle = menu_manager_ref_user_data (mm);
724         int rt = 0;
725
726         msg("call [%s] tapi service !!!", menu->title);
727         rt = tel_get_sim_oplmnwact (handle, on_sim_get_oplmnwact, NULL );
728         CHECK_RT(rt);
729         return 0;
730 }
731
732 static void on_sim_get_spn (TapiHandle *handle, int result, void *data,
733                 void *user_data)
734 {
735         TelSimAccessResult_t access_rt = result;
736         TelSimSpn_t *spn_info = data;
737
738         msg("TAPI_SERVICE_SIM_GET_SPN response received");
739
740         CHECK_ACCESS_RT(access_rt);
741
742         msg("access_rt[%d]", access_rt);
743         msg("spn name[%s]", spn_info->spn);
744         msg("spn condition[0x%x]", spn_info->display_condition);
745 }
746
747 static int run_sim_get_spn (MManager *mm, struct menu_data *menu)
748 {
749         TapiHandle *handle = menu_manager_ref_user_data (mm);
750         int rt = 0;
751
752         msg("call [%s] tapi service !!!", menu->title);
753         rt = tel_get_sim_spn (handle, on_sim_get_spn, NULL );
754         CHECK_RT(rt);
755         return 0;
756 }
757
758 static void on_sim_get_cphs_netname (TapiHandle *handle, int result, void *data,
759                 void *user_data)
760 {
761         TelSimAccessResult_t access_rt = result;
762         TelSimCphsNetName_t *cphs_net = data;
763
764         msg("TAPI_SERVICE_SIM_GET_CPHS_NETNAME response received");
765
766         CHECK_ACCESS_RT(access_rt);
767
768         msg("access_rt[%d]", access_rt);
769         msg("cphs full name[%s]", cphs_net->full_name);
770         msg("cphs short name[%s]", cphs_net->short_name);
771 }
772
773 static int run_sim_get_cphs_netname (MManager *mm, struct menu_data *menu)
774 {
775         TapiHandle *handle = menu_manager_ref_user_data (mm);
776         int rt = 0;
777
778         msg("call [%s] tapi service !!!", menu->title);
779         rt = tel_get_sim_cphs_netname (handle, on_sim_get_cphs_netname, NULL );
780         CHECK_RT(rt);
781         return 0;
782 }
783
784 static void on_sim_req_authentication (TapiHandle *handle, int result,
785                 void *data, void *user_data)
786 {
787         TelSimAccessResult_t access_rt = result;
788         TelSimAuthenticationResponse_t *auth_resp = data;
789         int i = 0;
790
791         msg("TAPI_SERVICE_SIM_AUTHENTICATION response received");
792
793         CHECK_ACCESS_RT(access_rt);
794
795         msg("access_rt[%d]", access_rt);
796         msg("auth_resp->auth_type[%d]", auth_resp->auth_type);
797         msg("auth_resp->auth_result[%d]", auth_resp->auth_result);
798
799         msg("auth_resp->authentication_key_length[%d]",
800                         auth_resp->authentication_key_length);
801         if (auth_resp->authentication_key_length) {
802                 for (i = 0; i < auth_resp->authentication_key_length; i++)
803                         msg("auth_resp->authentication_key[%d][0x%2x]", i,
804                                         auth_resp->authentication_key[i]);
805         }
806
807         msg("auth_resp->cipher_length[%d]", auth_resp->cipher_length);
808         if (auth_resp->cipher_length) {
809                 for (i = 0; i < auth_resp->cipher_length; i++)
810                         msg("auth_resp->cipher_data[%d][0x%2x]", i,
811                                         auth_resp->cipher_data[i]);
812         }
813
814         msg("auth_resp->integrity_length[%d]", auth_resp->integrity_length);
815         if (auth_resp->integrity_length) {
816                 for (i = 0; i < auth_resp->integrity_length; i++)
817                         msg("auth_resp->integrity_data[%d][0x%2x]", i,
818                                         auth_resp->integrity_data[i]);
819         }
820
821         msg("auth_resp->resp_length[%d]", auth_resp->resp_length);
822         if (auth_resp->resp_length) {
823                 for (i = 0; i < auth_resp->resp_length; i++)
824                         msg("auth_resp->resp_data[%d][0x%2x]", i, auth_resp->resp_data[i]);
825         }
826
827 }
828
829 static int run_sim_req_authentication (MManager *mm, struct menu_data *menu)
830 {
831         TapiHandle *handle = menu_manager_ref_user_data (mm);
832         int rt = 0;
833         TelSimAuthenticationData_t auth;
834         memset (&auth, 0, sizeof(TelSimAuthenticationData_t));
835
836         msg("call [%s] tapi service !!!", menu->title);
837
838         data_sim_req_authentication_type[0] = data_sim_req_authentication_type[0]
839                         - '0';
840
841         auth.auth_type = data_sim_req_authentication_type[0];
842         auth.autn_length = strlen (data_sim_req_authentication_autn_data);
843         memcpy (&auth.autn_data, data_sim_req_authentication_autn_data,
844                         auth.autn_length);
845         auth.rand_length = strlen (data_sim_req_authentication_rand_data);
846         memcpy (&auth.rand_data, data_sim_req_authentication_rand_data,
847                         auth.rand_length);
848
849         rt = tel_req_sim_authentication (handle, &auth, on_sim_req_authentication,
850                         NULL );
851         CHECK_RT(rt);
852         return 0;
853 }
854
855 static void on_sim_security_op_resp (TapiHandle *handle, int result, void *data,
856                 void *user_data)
857 {
858         TelSimPinOperationResult_t sec_rt = result;
859         TelSimSecResult_t *rt = data;
860
861         msg("TAPI_SERVICE_SIM security response received");
862
863         if (sec_rt == TAPI_SIM_PIN_INCORRECT_PASSWORD ||
864                 sec_rt == TAPI_SIM_PUK_INCORRECT_PASSWORD) {
865                 msg("SIM operation: Password Incorrect[%d]",sec_rt);
866         } else {
867                 CHECK_ACCESS_RT(sec_rt);
868         }
869
870         msg("sec_rt[%d]", sec_rt);
871         msg("rt->type[%d]", rt->type);
872         msg("rt->retry_count[%d]", rt->retry_count);
873 }
874
875 static int run_sim_verify_pins (MManager *mm, struct menu_data *menu)
876 {
877         TapiHandle *handle = menu_manager_ref_user_data (mm);
878         int rt = 0;
879         TelSimSecPw_t pwt;
880         memset (&pwt, 0, sizeof(TelSimSecPw_t));
881
882         msg("call [%s] tapi service !!!", menu->title);
883
884         data_sim_verify_pins_type[0] = data_sim_verify_pins_type[0] - '0';
885         data_sim_verify_pins_pw[MENU_DATA_SIZE] = '\0';
886         pwt.type = data_sim_verify_pins_type[0];
887         pwt.pw_len = strlen (data_sim_verify_pins_pw);
888         pwt.pw = (unsigned char *) data_sim_verify_pins_pw;
889
890         rt = tel_verifiy_sim_pins (handle, &pwt, on_sim_security_op_resp, NULL );
891         CHECK_RT(rt);
892         return 0;
893 }
894
895 static int run_sim_verify_puks (MManager *mm, struct menu_data *menu)
896 {
897         TapiHandle *handle = menu_manager_ref_user_data (mm);
898         int rt = 0;
899         TelSimSecPw_t puk_t;
900         TelSimSecPw_t new_pin_t;
901         memset (&puk_t, 0, sizeof(TelSimSecPw_t));
902         memset (&new_pin_t, 0, sizeof(TelSimSecPw_t));
903         msg("call [%s] tapi service !!!", menu->title);
904
905         data_sim_verify_puks_type[0] = data_sim_verify_puks_type[0] - '0';
906         data_sim_verify_puks_puk[MENU_DATA_SIZE] = '\0';
907         puk_t.type = data_sim_verify_puks_type[0];
908         puk_t.pw_len = strlen (data_sim_verify_puks_puk);
909         puk_t.pw = (unsigned char*) data_sim_verify_puks_puk;
910
911         if (puk_t.type == TAPI_SIM_PTYPE_PUK1)
912                 new_pin_t.type = TAPI_SIM_PTYPE_PIN1;
913         if (puk_t.type == TAPI_SIM_PTYPE_PUK2)
914                 new_pin_t.type = TAPI_SIM_PTYPE_PIN2;
915
916         data_sim_verify_puks_pin[MENU_DATA_SIZE] = '\0';
917         new_pin_t.pw_len = strlen (data_sim_verify_puks_pin);
918         new_pin_t.pw = (unsigned char*) data_sim_verify_puks_pin;
919
920         rt = tel_verify_sim_puks (handle, &puk_t, &new_pin_t,
921                         on_sim_security_op_resp, NULL );
922         CHECK_RT(rt);
923         return 0;
924 }
925
926 static int run_sim_change_pins (MManager *mm, struct menu_data *menu)
927 {
928         TapiHandle *handle = menu_manager_ref_user_data (mm);
929         int rt = 0;
930         TelSimSecPw_t old;
931         TelSimSecPw_t new;
932         memset (&old, 0, sizeof(TelSimSecPw_t));
933         memset (&new, 0, sizeof(TelSimSecPw_t));
934
935         msg("call [%s] tapi service !!!", menu->title);
936
937         data_sim_change_pins_type[0] = data_sim_change_pins_type[0] - '0';
938
939         data_sim_change_pins_old_pw[MENU_DATA_SIZE] = '\0';
940         old.type = data_sim_change_pins_type[0];
941         old.pw_len = strlen (data_sim_change_pins_old_pw);
942         old.pw = (unsigned char*) data_sim_change_pins_old_pw;
943
944         data_sim_change_pins_new_pw[MENU_DATA_SIZE] = '\0';
945         new.type = data_sim_change_pins_type[0];
946         new.pw_len = strlen (data_sim_change_pins_new_pw);
947         new.pw = (unsigned char*) data_sim_change_pins_new_pw;
948
949         rt = tel_change_sim_pins (handle, &old, &new, on_sim_security_op_resp,
950                         NULL );
951         CHECK_RT(rt);
952         return 0;
953 }
954
955 static void on_sim_facility_op_resp (TapiHandle *handle, int result, void *data,
956                 void *user_data)
957 {
958         TelSimPinOperationResult_t sec_rt = result;
959         TelSimFacilityResult_t *f_rt = data;
960
961         msg("TAPI_SERVICE_SIM facility response received");
962
963         if (sec_rt == TAPI_SIM_PIN_INCORRECT_PASSWORD ||
964                 sec_rt == TAPI_SIM_PUK_INCORRECT_PASSWORD) {
965                 msg("SIM operation: Password Incorrect[%d]",sec_rt);
966         } else {
967                 CHECK_ACCESS_RT(sec_rt);
968         }
969
970         msg("sec_rt[%d]", sec_rt);
971         msg("f_rt->type[%d]", f_rt->type);
972         msg("f_rt->retry_count[%d]", f_rt->retry_count);
973 }
974
975 static int run_sim_disable_facility (MManager *mm, struct menu_data *menu)
976 {
977         TapiHandle *handle = menu_manager_ref_user_data (mm);
978         int rt = 0;
979         TelSimFacilityPw_t fpw;
980         msg("call [%s] tapi service !!!", menu->title);
981
982         memset (&fpw, 0, sizeof (fpw));
983
984         data_sim_disable_facility_type[0] = data_sim_disable_facility_type[0] - '0';
985         data_sim_disable_facility_pw[MENU_DATA_SIZE] = '\0';
986         fpw.lock_type = data_sim_disable_facility_type[0];
987         fpw.pw_len = strlen (data_sim_disable_facility_pw);
988         fpw.pw = (unsigned char*) data_sim_disable_facility_pw;
989
990         msg("fpw.lock_type[%d], fpw.pw_len[%d], fpw.pw[%s]", fpw.lock_type,
991                         fpw.pw_len, fpw.pw);
992         rt = tel_disable_sim_facility (handle, &fpw, on_sim_facility_op_resp,
993                         NULL );
994         CHECK_RT(rt);
995         return 0;
996 }
997
998 static int run_sim_enable_facility (MManager *mm, struct menu_data *menu)
999 {
1000         TapiHandle *handle = menu_manager_ref_user_data (mm);
1001         int rt = 0;
1002         TelSimFacilityPw_t fpw;
1003         msg("call [%s] tapi service !!!", menu->title);
1004
1005         memset (&fpw, 0, sizeof (fpw));
1006
1007         data_sim_enable_facility_type[0] = data_sim_enable_facility_type[0] - '0';
1008         data_sim_enable_facility_pw[MENU_DATA_SIZE] = '\0';
1009         fpw.lock_type = data_sim_enable_facility_type[0];
1010         fpw.pw_len = strlen (data_sim_enable_facility_pw);
1011         fpw.pw = (unsigned char*) data_sim_enable_facility_pw;
1012
1013         msg("fpw.lock_type[%d], fpw.pw_len[%d], fpw.pw[%s]", fpw.lock_type,
1014                         fpw.pw_len, fpw.pw);
1015         rt = tel_enable_sim_facility (handle, &fpw, on_sim_facility_op_resp, NULL );
1016         CHECK_RT(rt);
1017         return 0;
1018 }
1019
1020 static void on_sim_get_facility (TapiHandle *handle, int result, void *data,
1021                 void *user_data)
1022 {
1023         TelSimPinOperationResult_t sec_rt = result;
1024         TelSimFacilityInfo_t *fi = data;
1025
1026         msg("TAPI_SERVICE_SIM facility response received");
1027
1028         CHECK_ACCESS_RT(sec_rt);
1029
1030         msg("sec_rt[%d]", sec_rt);
1031         msg("fi->type[%d]", fi->type);
1032         msg("fi->f_status[%d]", fi->f_status);
1033 }
1034
1035 static int run_sim_get_facility (MManager *mm, struct menu_data *menu)
1036 {
1037         TapiHandle *handle = menu_manager_ref_user_data (mm);
1038         int rt = 0;
1039         TelSimLockType_t t = 0;
1040         msg("call [%s] tapi service !!!", menu->title);
1041
1042         data_sim_get_facility_type[0] = data_sim_get_facility_type[0] - '0';
1043
1044         switch (data_sim_get_facility_type[0]) {
1045                 case 1:
1046                         t = TAPI_SIM_LOCK_PS;
1047                         break;
1048                 case 2:
1049                         t = TAPI_SIM_LOCK_PF;
1050                         break;
1051                 case 3:
1052                         t = TAPI_SIM_LOCK_SC;
1053                         break;
1054                 case 4:
1055                         t = TAPI_SIM_LOCK_FD;
1056                         break;
1057                 case 5:
1058                         t = TAPI_SIM_LOCK_PN;
1059                         break;
1060                 case 6:
1061                         t = TAPI_SIM_LOCK_PU;
1062                         break;
1063                 case 7:
1064                         t = TAPI_SIM_LOCK_PP;
1065                         break;
1066                 case 8:
1067                         t = TAPI_SIM_LOCK_PC;
1068                         break;
1069                 default:
1070                         msg("not handled type[%d]", data_sim_get_facility_type[0])
1071                         ;
1072                         break;
1073         }
1074         rt = tel_get_sim_facility (handle, t, on_sim_get_facility, NULL );
1075         CHECK_RT(rt);
1076         return 0;
1077 }
1078
1079 static void on_sim_get_lock_info (TapiHandle *handle, int result, void *data,
1080                 void *user_data)
1081 {
1082         TelSimPinOperationResult_t sec_rt = result;
1083         TelSimLockInfo_t *lock = data;
1084
1085         msg("TAPI_SERVICE_SIM lock info response received");
1086
1087         CHECK_ACCESS_RT(sec_rt);
1088
1089         msg("sec_rt[%d]", sec_rt);
1090         msg("lock->lock_type[%d]", lock->lock_type);
1091         msg(
1092                         "lock->lock_status[%d]-0:not need, 1:pin, 2:puk, 3:pin2, 4:puk2, 5:blocked",
1093                         lock->lock_status);
1094         msg("lock->retry_count[%d]", lock->retry_count);
1095 }
1096
1097 static int run_sim_get_lock_info (MManager *mm, struct menu_data *menu)
1098 {
1099         TapiHandle *handle = menu_manager_ref_user_data (mm);
1100         int rt = 0;
1101         TelSimLockType_t t = 0;
1102         msg("call [%s] tapi service !!!", menu->title);
1103
1104         data_sim_get_lock_type[0] = data_sim_get_lock_type[0] - '0';
1105
1106         switch (data_sim_get_lock_type[0]) {
1107                 case 1:
1108                         t = TAPI_SIM_LOCK_PS;
1109                         break;
1110                 case 2:
1111                         t = TAPI_SIM_LOCK_PF;
1112                         break;
1113                 case 3:
1114                         t = TAPI_SIM_LOCK_SC;
1115                         break;
1116                 case 4:
1117                         t = TAPI_SIM_LOCK_FD;
1118                         break;
1119                 case 5:
1120                         t = TAPI_SIM_LOCK_PN;
1121                         break;
1122                 case 6:
1123                         t = TAPI_SIM_LOCK_PU;
1124                         break;
1125                 case 7:
1126                         t = TAPI_SIM_LOCK_PP;
1127                         break;
1128                 case 8:
1129                         t = TAPI_SIM_LOCK_PC;
1130                         break;
1131                 default:
1132                         msg("not handled type[%d]", data_sim_get_lock_type[0])
1133                         ;
1134                         break;
1135         }
1136         rt = tel_get_sim_lock_info (handle, t, on_sim_get_lock_info, NULL );
1137         CHECK_RT(rt);
1138         return 0;
1139 }
1140
1141 static void on_sim_transmit_apdu (TapiHandle *handle, int result, void *data,
1142                 void *user_data)
1143 {
1144         TelSimAccessResult_t access_rt = result;
1145         TelSimApduResp_t *r_apdu = data;
1146         int i = 0;
1147
1148         msg("TAPI_SERVICE_SIM_APDU response received");
1149
1150         CHECK_ACCESS_RT(access_rt);
1151
1152         msg("access_rt[%d]", access_rt);
1153         msg("r_apdu->apdu_resp_len[%d]", r_apdu->apdu_resp_len);
1154         if (r_apdu->apdu_resp_len) {
1155                 for (i = 0; i < r_apdu->apdu_resp_len; i++)
1156                         msg("[%d]`s byte is [0x%x]", i, r_apdu->apdu_resp[i]);
1157         }
1158 }
1159
1160 static int run_sim_transmit_apdu (MManager *mm, struct menu_data *menu)
1161 {
1162         TapiHandle *handle = menu_manager_ref_user_data (mm);
1163         int rt = 0;
1164         TelSimApdu_t t_apdu;
1165         unsigned char result_apdu[MENU_DATA_SIZE + 1] = { 0, };
1166         int i = 0, j = 0, len = 0, hex = 0;
1167
1168         memset (&t_apdu, 0, sizeof(TelSimApdu_t));
1169
1170         msg("call [%s] tapi service !!!", menu->title);
1171
1172         len = strlen (data_sim_transmit_apdu_apdu);
1173
1174         for (i = 0, j = 0; i < len; i += 2, j++) {
1175                 hex = (_sim_str_to_hex (data_sim_transmit_apdu_apdu[i]) << 4)
1176                                 | (_sim_str_to_hex (data_sim_transmit_apdu_apdu[i + 1]));
1177                 printf ("0x%x\n", hex);
1178
1179                 result_apdu[j] = hex;
1180         }
1181
1182         for (i = 0; i < len / 2; i++) {
1183                 printf ("[%02d] = 0x%02x\n", i, result_apdu[i]);
1184         }
1185
1186         t_apdu.apdu_len = len / 2;
1187         t_apdu.apdu = (unsigned char*) malloc (t_apdu.apdu_len);
1188         memcpy (t_apdu.apdu, result_apdu, t_apdu.apdu_len);
1189
1190         rt = tel_req_sim_apdu (handle, &t_apdu, on_sim_transmit_apdu, NULL );
1191         if (t_apdu.apdu)
1192                 free(t_apdu.apdu);
1193         CHECK_RT(rt);
1194         return 0;
1195 }
1196
1197 static void on_sim_get_atr (TapiHandle *handle, int result, void *data,
1198                 void *user_data)
1199 {
1200         TelSimAccessResult_t access_rt = result;
1201         TelSimAtrResp_t *r_atr = data;
1202         int i = 0;
1203         msg("TAPI_SERVICE_SIM_APDU response received");
1204
1205         CHECK_ACCESS_RT(access_rt);
1206
1207         msg("access_rt[%d]", access_rt);
1208         msg("r_atr->atr_resp_len[%d]", r_atr->atr_resp_len);
1209         if (r_atr->atr_resp_len) {
1210                 for (i = 0; i < r_atr->atr_resp_len; i++)
1211                         msg("[%d]`s byte is [0x%x]", i, r_atr->atr_resp[i]);
1212         }
1213 }
1214
1215 static int run_sim_get_atr(MManager *mm, struct menu_data *menu)
1216 {
1217         TapiHandle *handle = menu_manager_ref_user_data(mm);
1218         int rt = 0;
1219
1220         msg("call [%s] tapi service !!!", menu->title);
1221
1222         rt = tel_req_sim_atr(handle, on_sim_get_atr, NULL);
1223         CHECK_RT(rt);
1224         return 0;
1225 }
1226
1227 static void on_sim_set_power_state (TapiHandle *handle, int result, void *data,
1228                 void *user_data)
1229 {
1230         TelSimPowerSetResult_t access_rt = result;
1231
1232         msg("TAPI_SERVICE_SIM_SET_POWER_STATE response received");
1233
1234         CHECK_ACCESS_RT(access_rt);
1235
1236         msg("access_rt[%d]", access_rt);
1237 }
1238
1239 static int run_sim_set_power_state(MManager *mm, struct menu_data *menu)
1240 {
1241         TapiHandle *handle = menu_manager_ref_user_data (mm);
1242         int rt = 0;
1243
1244         msg("call [%s] tapi service !!!", menu->title);
1245         data_sim_set_state[0] = data_sim_set_state[0] - '0';
1246         rt = tel_set_sim_power_state (handle, data_sim_set_state[0],
1247                         on_sim_set_power_state, NULL );
1248         CHECK_RT(rt);
1249         return 0;
1250 }
1251
1252
1253 static struct menu_data menu_sim_get_init_info[] = {
1254         { "1", "run", NULL, run_sim_get_init_info, NULL},
1255         { NULL, NULL, },
1256 };
1257
1258 static struct menu_data menu_sim_get_card_type[] = {
1259         { "1", "run", NULL, run_sim_get_card_type, NULL},
1260         { NULL, NULL, },
1261 };
1262
1263 static struct menu_data menu_sim_get_imsi[] = {
1264         { "1", "run", NULL, run_sim_get_imsi, NULL},
1265         { NULL, NULL, },
1266 };
1267
1268 static struct menu_data menu_sim_get_ecc[] = {
1269         { "1", "run", NULL, run_sim_get_ecc, NULL},
1270         { NULL, NULL, },
1271 };
1272
1273 static struct menu_data menu_sim_get_iccid[] = {
1274         { "1", "run", NULL, run_sim_get_iccid, NULL},
1275         { NULL, NULL, },
1276 };
1277
1278 static struct menu_data menu_sim_get_language[] = {
1279                 {"1", "run", NULL, run_sim_get_language, NULL},
1280                 {NULL, NULL},
1281 };
1282
1283 static struct menu_data menu_sim_set_language[] = {
1284                 {"1", "select language", NULL, NULL, (char*)data_sim_set_language},
1285                 {"2", "run", NULL, run_sim_set_language, NULL},
1286                 {NULL, NULL},
1287 };
1288
1289 static struct menu_data menu_sim_change_state[] = {
1290                 {"1", "change state(0:OFF, 1:ON)", NULL, NULL, (char*)data_sim_set_state},
1291                 {"2", "run", NULL, run_sim_set_power_state, NULL},
1292                 {NULL, NULL},
1293 };
1294
1295
1296 static struct menu_data menu_sim_get_cf[] = {
1297                 {"1", "run", NULL, run_sim_get_cf, NULL},
1298                 {NULL, NULL},
1299 };
1300
1301 static struct menu_data menu_sim_set_cf[] = {
1302                 {"1", "b_cphs no/yes => 0/1", NULL, NULL, data_sim_set_cf_b_cphs},
1303                 {"2", "rec_index int", NULL, NULL, data_sim_set_cf_rec_index},
1304                 {"3", "msp_num int", NULL, NULL, data_sim_set_cf_msp_num},
1305                 {"4", "cfu_status int", NULL, NULL, data_sim_set_cf_cfu_status},
1306                 {"5", "ton int", NULL, NULL, data_sim_set_cf_ton},
1307                 {"6", "npi int", NULL, NULL, data_sim_set_cf_npi},
1308                 {"7", "number string", NULL, NULL, data_sim_set_cf_number},
1309                 {"8", "cc2_id int", NULL, NULL, data_sim_set_cf_cc2_id},
1310                 {"9", "ext7_id int", NULL, NULL, data_sim_set_cf_ext7_id},
1311                 {"10", "cphs_line1 no/yes => 0/1", NULL, NULL, data_sim_set_cf_cphs_line1},
1312                 {"11", "cphs_line2 no/yes => 0/1", NULL, NULL, data_sim_set_cf_cphs_line2},
1313                 {"12", "cphs_fax no/yes => 0/1", NULL, NULL, data_sim_set_cf_cphs_fax},
1314                 {"13", "cphs_data no/yes => 0/1", NULL, NULL, data_sim_set_cf_cphs_data},
1315                 {"14", "run", NULL, run_sim_set_cf, NULL},
1316                 {NULL, NULL},
1317 };
1318
1319 static struct menu_data menu_sim_get_mw[] = {
1320                 {"1", "run", NULL, run_sim_get_mw, NULL},
1321                 {NULL, NULL},
1322 };
1323
1324 static struct menu_data menu_sim_set_mw[] = {
1325                 {"1", "b_cphs no/yes => 0/1", NULL, NULL, data_sim_set_mw_b_cphs},
1326                 {"2", "rec_index int", NULL, NULL, data_sim_set_mw_rec_index},
1327                 {"3", "indicator_status int", NULL, NULL, data_sim_set_mw_indicator_status},
1328                 {"4", "voice_cnt int", NULL, NULL, data_sim_set_mw_voice_cnt},
1329                 {"5", "fax_cnt int", NULL, NULL, data_sim_set_mw_fax_cnt},
1330                 {"6", "email_cnt int", NULL, NULL, data_sim_set_mw_email_cnt},
1331                 {"7", "other_cnt int", NULL, NULL, data_sim_set_mw_other_cnt},
1332                 {"8", "video_cnt int", NULL, NULL, data_sim_set_mw_video_cnt},
1333                 {"9", "cphs_voice1 no/yes => 0/1", NULL, NULL, data_sim_set_mw_cphs_voice1},
1334                 {"10", "cphs_voice2 no/yes => 0/1", NULL, NULL, data_sim_set_mw_cphs_voice2},
1335                 {"11", "cphs_fax no/yes => 0/1", NULL, NULL, data_sim_set_mw_cphs_fax},
1336                 {"12", "cphs_data no/yes => 0/1", NULL, NULL, data_sim_set_mw_cphs_data},
1337                 {"13", "run", NULL, run_sim_set_mw, NULL},
1338                 {NULL, NULL},
1339 };
1340
1341 static struct menu_data menu_sim_get_mb[] = {
1342                 {"1", "run", NULL, run_sim_get_mb, NULL},
1343                 {NULL, NULL},
1344 };
1345
1346 static struct menu_data menu_sim_set_mb[] = {
1347                 {"1", "b_cphs no/yes => 0/1", NULL, NULL, data_sim_set_mb_b_cphs},
1348                 {"2", "type 1voice 2voice2 3fax 4data 5email 6other  int", NULL, NULL, data_sim_set_mb_type},
1349                 {"3", "rec_index int", NULL, NULL, data_sim_set_mb_rec_index},
1350                 {"4", "profile_num int", NULL, NULL, data_sim_set_mb_profile_num},
1351                 {"5", "alpha_id_max_len int", NULL, NULL, data_sim_set_mb_alpha_id_max_len},
1352                 {"6", "alpha_id string", NULL, NULL, data_sim_set_mb_alpha_id},
1353                 {"7", "ton int", NULL, NULL, data_sim_set_mb_ton},
1354                 {"8", "npi int", NULL, NULL, data_sim_set_mb_npi},
1355                 {"9", "number string", NULL, NULL, data_sim_set_mb_number},
1356                 {"10", "cc_id int", NULL, NULL, data_sim_set_mb_cc_id},
1357                 {"11", "ext1_id int", NULL, NULL, data_sim_set_mb_ext1_id},
1358                 {"12", "run", NULL, run_sim_set_mb, NULL},
1359                 {NULL, NULL},
1360 };
1361
1362 static struct menu_data menu_sim_get_cphs_info[] = {
1363                 {"1", "run", NULL, run_sim_get_cphs_info, NULL},
1364                 {NULL, NULL},
1365 };
1366
1367 static struct menu_data menu_sim_get_service_table[] = {
1368                 {"1", "run", NULL, run_sim_get_service_table, NULL},
1369                 {NULL, NULL},
1370 };
1371
1372 static struct menu_data menu_sim_get_msisdn[] = {
1373                 {"1", "run", NULL, run_sim_get_msisdn, NULL},
1374                 {NULL, NULL},
1375 };
1376
1377 static struct menu_data menu_sim_get_oplmnwact[] = {
1378                 {"1", "run", NULL, run_sim_get_oplmnwact, NULL},
1379                 {NULL, NULL},
1380 };
1381
1382 static struct menu_data menu_sim_get_spn[] = {
1383                 {"1", "run", NULL, run_sim_get_spn, NULL},
1384                 {NULL, NULL},
1385 };
1386
1387 static struct menu_data menu_sim_get_cphs_netname[] = {
1388                 {"1", "run", NULL, run_sim_get_cphs_netname, NULL},
1389                 {NULL, NULL},
1390 };
1391
1392 static struct menu_data menu_sim_req_authentication[] = {
1393                 {"1", "type", NULL, NULL, data_sim_req_authentication_type},
1394                 {"2", "autn_data", NULL, NULL, data_sim_req_authentication_autn_data},
1395                 {"3", "rand_data", NULL, NULL, data_sim_req_authentication_rand_data},
1396                 {"4", "run", NULL, run_sim_req_authentication, NULL},
1397                 {NULL, NULL},
1398 };
1399
1400 static struct menu_data menu_sim_verify_pins[] = {
1401                 {"1", "type(0:pin1, 1:pin2, 6:sim)", NULL, NULL, data_sim_verify_pins_type},
1402                 {"2", "pw", NULL, NULL, data_sim_verify_pins_pw},
1403                 {"3", "run", NULL, run_sim_verify_pins, NULL},
1404                 {NULL, NULL},
1405 };
1406
1407 static struct menu_data menu_sim_verify_puks[] = {
1408                 {"1", "type(2:puk1, 3:puk2)", NULL, NULL, data_sim_verify_puks_type},
1409                 {"2", "puk", NULL, NULL, data_sim_verify_puks_puk},
1410                 {"3", "pin", NULL, NULL, data_sim_verify_puks_pin},
1411                 {"4", "run", NULL, run_sim_verify_puks, NULL},
1412                 {NULL, NULL},
1413 };
1414
1415 static struct menu_data menu_sim_change_pins[] = {
1416                 {"1", "type(0:pin1, 1:pin2)", NULL, NULL, data_sim_change_pins_type},
1417                 {"2", "old_pw", NULL, NULL, data_sim_change_pins_old_pw},
1418                 {"3", "new_pw", NULL, NULL, data_sim_change_pins_new_pw},
1419                 {"4", "run", NULL, run_sim_change_pins, NULL},
1420                 {NULL, NULL},
1421 };
1422
1423 static struct menu_data menu_sim_disable_facility[] = {
1424                 {"1", "type(1:simlock, 3:pinlock., 4:fdnlock, 5:net, 6:netsub, 7:sp, 8:cp)", NULL, NULL, data_sim_disable_facility_type},
1425                 {"2", "pw", NULL, NULL, data_sim_disable_facility_pw},
1426                 {"3", "run", NULL, run_sim_disable_facility, NULL},
1427                 {NULL, NULL},
1428 };
1429
1430 static struct menu_data menu_sim_enable_facility[] = {
1431                 {"1", "type(1:simlock, 3:pinlock., 4:fdnlock, 5:net, 6:netsub, 7:sp, 8:cp)", NULL, NULL, data_sim_enable_facility_type},
1432                 {"2", "pw", NULL, NULL, data_sim_enable_facility_pw},
1433                 {"3", "run", NULL, run_sim_enable_facility, NULL},
1434                 {NULL, NULL},
1435 };
1436
1437 static struct menu_data menu_sim_get_facility[] = {
1438                 {"1", "type(1:simlock, 3:pinlock., 4:fdnlock, 5:net, 6:netsub, 7:sp, 8:cp)", NULL, NULL, data_sim_get_facility_type},
1439                 {"2", "run", NULL, run_sim_get_facility, NULL},
1440                 {NULL, NULL},
1441 };
1442
1443 static struct menu_data menu_sim_get_lock_info[] = {
1444                 {"1", "type(1:simlock, 3:pinlock., 4:fdnlock, 5:net, 6:netsub, 7:sp, 8:cp)", NULL, NULL, data_sim_get_lock_type},
1445                 {"2", "run", NULL, run_sim_get_lock_info, NULL},
1446                 {NULL, NULL},
1447 };
1448
1449 static struct menu_data menu_sim_transmit_apdu[] = {
1450                 {"1", "apdu", NULL, NULL, data_sim_transmit_apdu_apdu},
1451                 {"2", "run", NULL, run_sim_transmit_apdu, NULL},
1452                 {NULL, NULL},
1453 };
1454
1455 static struct menu_data menu_sim_get_atr[] = {
1456                 {"1", "run", NULL, run_sim_get_atr, NULL},
1457                 {NULL, NULL},
1458 };
1459
1460 struct menu_data menu_sim[] = {
1461         {"1", "sim init info", menu_sim_get_init_info, NULL, NULL},
1462         {"2", "card type", menu_sim_get_card_type, NULL, NULL},
1463         {"3", "imsi", menu_sim_get_imsi, NULL, NULL},
1464         {"4", "ecc", menu_sim_get_ecc, NULL, NULL},
1465         {"5", "iccid", menu_sim_get_iccid, NULL, NULL},
1466         {"6", "language", menu_sim_get_language, NULL, NULL},
1467         {"7", "update language", menu_sim_set_language, NULL, NULL},
1468         {"8", "cf info", menu_sim_get_cf, NULL, NULL},
1469         {"9", "update cf info", menu_sim_set_cf, NULL, NULL},
1470         {"10", "mw info", menu_sim_get_mw, NULL, NULL},
1471         {"11", "update mw info", menu_sim_set_mw, NULL, NULL},
1472         {"12", "mailbox info", menu_sim_get_mb, NULL, NULL},
1473         {"13", "update mailbox info", menu_sim_set_mb, NULL, NULL},
1474         {"14", "cphs info(svc table, phase)", menu_sim_get_cphs_info, NULL, NULL},
1475         {"15", "msisdn", menu_sim_get_msisdn, NULL, NULL},
1476         {"16", "oplmnwact", menu_sim_get_oplmnwact, NULL, NULL},
1477         {"17", "spn", menu_sim_get_spn, NULL, NULL},
1478         {"18", "cphs operator name info", menu_sim_get_cphs_netname, NULL, NULL},
1479         {"19", "authentication", menu_sim_req_authentication, NULL, NULL},
1480         {"20", "verify pins", menu_sim_verify_pins, NULL, NULL},
1481         {"21", "verify puks", menu_sim_verify_puks, NULL, NULL},
1482         {"22", "change pins", menu_sim_change_pins, NULL, NULL},
1483         {"23", "disable facility", menu_sim_disable_facility, NULL, NULL},
1484         {"24", "enable facility", menu_sim_enable_facility, NULL, NULL},
1485         {"25", "facility(en/dis status) info", menu_sim_get_facility, NULL, NULL},
1486         {"26", "lock status(status,retry count) info", menu_sim_get_lock_info, NULL, NULL},
1487         {"27", "apdu", menu_sim_transmit_apdu, NULL, NULL},
1488         {"28", "atr info", menu_sim_get_atr, NULL, NULL},
1489         {"29", "service table", menu_sim_get_service_table, NULL, NULL},
1490         {"30", "Change State", menu_sim_change_state, NULL, NULL},
1491         { NULL, NULL, },
1492 };
1493
1494 void register_sim_event (TapiHandle *handle)
1495 {
1496         int ret;
1497
1498         /* SIM */
1499         ret = tel_register_noti_event (handle, TAPI_NOTI_SIM_STATUS,
1500                         on_noti_sim_status, NULL );
1501         ret = tel_register_noti_event (handle, TAPI_PROP_SIM_CALL_FORWARD_STATE,
1502                         on_noti_sim_cf_state, NULL );
1503         if (ret != TAPI_API_SUCCESS) {
1504                 msg("event register failed(%d)", ret);
1505         }
1506 }