add exception code for g_variant_iter_free()
[profile/ivi/tel-plugin-dbus_tapi.git] / src / sim.c
1 /*
2  * tel-plugin-socket-communicator
3  *
4  * Copyright (c) 2012 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 <string.h>
23 #include <stdlib.h>
24 #include <errno.h>
25 #include <glib.h>
26 #include <glib-object.h>
27 #include <gio/gio.h>
28
29 #include <tcore.h>
30 #include <server.h>
31 #include <plugin.h>
32 #include <hal.h>
33 #include <communicator.h>
34 #include <core_object.h>
35 #include <queue.h>
36 #include <user_request.h>
37 #include <util.h>
38 #include <co_sim.h>
39
40 #include "generated-code.h"
41 #include "common.h"
42
43 #define g_variant_iter_free0( iter ) \
44         if ( iter ) \
45                 g_variant_iter_free( iter );\
46         else \
47                 dbg("iter : 0");
48
49 static gboolean dbus_sim_data_request(struct custom_data *ctx, enum tel_sim_status sim_status )
50 {
51         UserRequest *ur = NULL;
52         TcorePlugin *plugin = NULL;
53
54         switch(sim_status){
55                 case SIM_STATUS_INITIALIZING :
56                 case SIM_STATUS_PIN_REQUIRED :
57                 case SIM_STATUS_PUK_REQUIRED :
58                 case SIM_STATUS_CARD_BLOCKED :
59                 case SIM_STATUS_NCK_REQUIRED :
60                 case SIM_STATUS_NSCK_REQUIRED :
61                 case SIM_STATUS_SPCK_REQUIRED :
62                 case SIM_STATUS_CCK_REQUIRED :
63                 case SIM_STATUS_LOCK_REQUIRED :
64                         if(ctx->sim_recv_first_status == FALSE){
65                                 dbg("received sim status at first time");
66                                 plugin = tcore_server_find_plugin(ctx->server, TCORE_PLUGIN_DEFAULT);
67
68                                 dbg("req - TREQ_SIM_GET_ECC ");
69                                 ur = tcore_user_request_new(ctx->comm, tcore_plugin_get_description(plugin)->name);
70                                 tcore_user_request_set_command(ur, TREQ_SIM_GET_ECC);
71                                 tcore_communicator_dispatch_request(ctx->comm, ur);
72                                 ctx->sim_recv_first_status = TRUE;
73                         }
74                         break;
75
76                 default :
77                         break;
78         }
79         return TRUE;
80 }
81
82 static gboolean on_sim_get_init_status(TelephonySim *sim, GDBusMethodInvocation *invocation,
83                 gpointer user_data)
84 {
85         struct custom_data *ctx = user_data;
86         gint tmp_cardstatus = 0xff;
87         gboolean b_changed = FALSE;
88         GSList *co_list = NULL;
89         CoreObject *co_sim = NULL;
90         TcorePlugin *plugin = NULL;
91
92         dbg("Func Entrance");
93
94         plugin = tcore_server_find_plugin(ctx->server, TCORE_PLUGIN_DEFAULT);
95         co_list = tcore_plugin_get_core_objects_bytype(plugin, CORE_OBJECT_TYPE_SIM);
96         if (!co_list) {
97                 dbg("error- co_list is NULL");
98         }
99         co_sim = (CoreObject *)co_list->data;
100         g_slist_free(co_list);
101
102         if (!co_sim) {
103                 dbg("error- co_sim is NULL");
104         }
105
106         tmp_cardstatus = tcore_sim_get_status(co_sim);
107         b_changed = tcore_sim_get_identification(co_sim);
108         dbg("sim init info - cardstatus[%d],changed[%d]", tmp_cardstatus, b_changed);
109
110         telephony_sim_complete_get_init_status(sim, invocation, tmp_cardstatus, b_changed);
111
112         return TRUE;
113 }
114
115 static gboolean on_sim_get_card_type(TelephonySim *sim, GDBusMethodInvocation *invocation,
116                 gpointer user_data)
117 {
118         struct custom_data *ctx = user_data;
119         enum tel_sim_type type = SIM_TYPE_UNKNOWN;
120         GSList *co_list = NULL;
121         CoreObject *co_sim = NULL;
122         TcorePlugin *plugin = NULL;
123
124         dbg("Func Entrance");
125
126         plugin = tcore_server_find_plugin(ctx->server, TCORE_PLUGIN_DEFAULT);
127         co_list = tcore_plugin_get_core_objects_bytype(plugin, CORE_OBJECT_TYPE_SIM);
128         if (!co_list) {
129                 dbg("error- co_list is NULL");
130         }
131         co_sim = (CoreObject *)co_list->data;
132         g_slist_free(co_list);
133
134         if (!co_sim) {
135                 dbg("error- co_sim is NULL");
136         }
137
138         type = tcore_sim_get_type(co_sim);
139
140         telephony_sim_complete_get_card_type(sim, invocation, type);
141
142         return TRUE;
143 }
144
145 static gboolean on_sim_get_imsi(TelephonySim *sim, GDBusMethodInvocation *invocation,
146                 gpointer user_data)
147 {
148         struct custom_data *ctx = user_data;
149         struct tel_sim_imsi *n_imsi;
150         GSList *co_list = NULL;
151         CoreObject *co_sim = NULL;
152         TcorePlugin *plugin = NULL;
153
154         dbg("Func Entrance");
155         plugin = tcore_server_find_plugin(ctx->server, TCORE_PLUGIN_DEFAULT);
156         co_list = tcore_plugin_get_core_objects_bytype(plugin, CORE_OBJECT_TYPE_SIM);
157         if (!co_list) {
158                 dbg("error- co_list is NULL");
159         }
160         co_sim = (CoreObject *)co_list->data;
161         g_slist_free(co_list);
162
163         if (!co_sim) {
164                 dbg("error- co_sim is NULL");
165         }
166
167         n_imsi = tcore_sim_get_imsi(co_sim);
168         dbg("n_imsi->plmn[%s]", n_imsi->plmn);
169         dbg("n_imsi->msin[%s]", n_imsi->msin);
170         telephony_sim_complete_get_imsi(sim, invocation, n_imsi->plmn, n_imsi->msin);
171         return TRUE;
172 }
173
174 static gboolean on_sim_get_ecc(TelephonySim *sim, GDBusMethodInvocation *invocation,
175                 gpointer user_data)
176 {
177         struct custom_data *ctx = user_data;
178         GVariant *gv = NULL;
179         GVariantBuilder b;
180         int i;
181
182         dbg("Func Entrance");
183
184         g_variant_builder_init(&b, G_VARIANT_TYPE("aa{sv}"));
185
186         for (i = 0; i < ctx->cached_sim_ecc.ecc_count; i++) {
187                 g_variant_builder_open(&b, G_VARIANT_TYPE("a{sv}"));
188                 g_variant_builder_add(&b, "{sv}", "name", g_variant_new_string(ctx->cached_sim_ecc.ecc[i].ecc_string));
189                 g_variant_builder_add(&b, "{sv}", "number", g_variant_new_string(ctx->cached_sim_ecc.ecc[i].ecc_num));
190                 g_variant_builder_add(&b, "{sv}", "category", g_variant_new_int32(ctx->cached_sim_ecc.ecc[i].ecc_category));
191                 g_variant_builder_close(&b);
192         }
193         gv = g_variant_builder_end(&b);
194
195         if (!gv)
196                 dbg("error - ecc gv is NULL");
197
198         telephony_sim_complete_get_ecc(sim, invocation, gv);
199
200         return TRUE;
201 }
202
203 static gboolean on_sim_get_iccid(TelephonySim *sim, GDBusMethodInvocation *invocation,
204                 gpointer user_data)
205 {
206         struct custom_data *ctx = user_data;
207         UserRequest *ur = NULL;
208
209         dbg("Func Entrance");
210         ur = MAKE_UR(ctx, sim, invocation);
211
212         tcore_user_request_set_command(ur, TREQ_SIM_GET_ICCID);
213         tcore_communicator_dispatch_request(ctx->comm, ur);
214
215         return TRUE;
216 }
217
218 static gboolean on_sim_get_language(TelephonySim *sim, GDBusMethodInvocation *invocation,
219                 gpointer user_data)
220 {
221         struct custom_data *ctx = user_data;
222         UserRequest *ur = NULL;
223
224         ur = MAKE_UR(ctx, sim, invocation);
225
226         tcore_user_request_set_command(ur, TREQ_SIM_GET_LANGUAGE);
227         tcore_communicator_dispatch_request(ctx->comm, ur);
228
229         return TRUE;
230 }
231
232 static gboolean on_sim_set_language(TelephonySim *sim, GDBusMethodInvocation *invocation,
233                 gint arg_language, gpointer user_data)
234 {
235         struct custom_data *ctx = user_data;
236         UserRequest *ur = NULL;
237
238         struct treq_sim_set_language set_language;
239         memset(&set_language, 0, sizeof(struct treq_sim_set_language));
240         set_language.language = arg_language;
241
242         dbg("set_language.language[%d]", set_language.language);
243         ur = MAKE_UR(ctx, sim, invocation);
244
245         tcore_user_request_set_data(ur, sizeof(struct treq_sim_set_language), &set_language);
246         tcore_user_request_set_command(ur, TREQ_SIM_SET_LANGUAGE);
247         tcore_communicator_dispatch_request(ctx->comm, ur);
248
249         return TRUE;
250 }
251
252 static gboolean on_sim_get_callforwarding(TelephonySim *sim, GDBusMethodInvocation *invocation,
253                 gpointer user_data)
254 {
255         struct custom_data *ctx = user_data;
256         UserRequest *ur = NULL;
257
258         ur = MAKE_UR(ctx, sim, invocation);
259
260         tcore_user_request_set_command(ur, TREQ_SIM_GET_CALLFORWARDING);
261         tcore_communicator_dispatch_request(ctx->comm, ur);
262
263         return TRUE;
264 }
265
266 static gboolean on_sim_get_message_waiting(TelephonySim *sim, GDBusMethodInvocation *invocation,
267                 gpointer user_data)
268 {
269         struct custom_data *ctx = user_data;
270         UserRequest *ur = NULL;
271
272         ur = MAKE_UR(ctx, sim, invocation);
273
274         tcore_user_request_set_command(ur, TREQ_SIM_GET_MESSAGEWAITING);
275         tcore_communicator_dispatch_request(ctx->comm, ur);
276
277         return TRUE;
278 }
279
280 static gboolean on_sim_get_mailbox(TelephonySim *sim, GDBusMethodInvocation *invocation,
281                 gpointer user_data)
282 {
283         struct custom_data *ctx = user_data;
284         UserRequest *ur = NULL;
285
286         ur = MAKE_UR(ctx, sim, invocation);
287
288         tcore_user_request_set_command(ur, TREQ_SIM_GET_MAILBOX);
289         tcore_communicator_dispatch_request(ctx->comm, ur);
290
291         return TRUE;
292 }
293
294
295 static gboolean on_sim_get_cphsinfo(TelephonySim *sim, GDBusMethodInvocation *invocation,
296                 gpointer user_data)
297 {
298         struct custom_data *ctx = user_data;
299         UserRequest *ur = NULL;
300
301         ur = MAKE_UR(ctx, sim, invocation);
302
303         tcore_user_request_set_command(ur, TREQ_SIM_GET_CPHS_INFO);
304         tcore_communicator_dispatch_request(ctx->comm, ur);
305
306         return TRUE;
307 }
308
309 static gboolean on_sim_get_msisdn(TelephonySim *sim, GDBusMethodInvocation *invocation,
310                 gpointer user_data)
311 {
312         struct custom_data *ctx = user_data;
313         UserRequest *ur = NULL;
314
315         ur = MAKE_UR(ctx, sim, invocation);
316
317         tcore_user_request_set_command(ur, TREQ_SIM_GET_MSISDN);
318         tcore_communicator_dispatch_request(ctx->comm, ur);
319
320         return TRUE;
321 }
322
323 static gboolean on_sim_get_oplmnwact(TelephonySim *sim, GDBusMethodInvocation *invocation,
324                 gpointer user_data)
325 {
326         struct custom_data *ctx = user_data;
327         UserRequest *ur = NULL;
328
329         ur = MAKE_UR(ctx, sim, invocation);
330
331         tcore_user_request_set_command(ur, TREQ_SIM_GET_OPLMNWACT);
332         tcore_communicator_dispatch_request(ctx->comm, ur);
333
334
335         return TRUE;
336 }
337
338 static gboolean on_sim_get_spn(TelephonySim *sim, GDBusMethodInvocation *invocation,
339                 gpointer user_data)
340 {
341         struct custom_data *ctx = user_data;
342         UserRequest *ur = NULL;
343
344         ur = MAKE_UR(ctx, sim, invocation);
345
346         tcore_user_request_set_command(ur, TREQ_SIM_GET_SPN);
347         tcore_communicator_dispatch_request(ctx->comm, ur);
348
349         return TRUE;
350 }
351
352 static gboolean on_sim_get_cphs_netname(TelephonySim *sim, GDBusMethodInvocation *invocation,
353                 gpointer user_data)
354 {
355         struct custom_data *ctx = user_data;
356         UserRequest *ur = NULL;
357
358         ur = MAKE_UR(ctx, sim, invocation);
359
360         tcore_user_request_set_command(ur, TREQ_SIM_GET_CPHS_NETNAME);
361         tcore_communicator_dispatch_request(ctx->comm, ur);
362
363         return TRUE;
364 }
365
366 static gboolean on_sim_authentication(TelephonySim *sim, GDBusMethodInvocation *invocation,
367                 gint arg_type,
368             GVariant *arg_rand,
369             GVariant *arg_autn,
370             gpointer user_data)
371 {
372         struct custom_data *ctx = user_data;
373         UserRequest *ur = NULL;
374         GVariantIter *iter = NULL;
375         GVariant *rand_gv = NULL;
376         GVariant *autn_gv = NULL;
377         guchar rt_i;
378         int i =0;
379
380         struct treq_sim_req_authentication req_auth;
381         memset(&req_auth, 0, sizeof(struct treq_sim_req_authentication));
382
383         req_auth.auth_type = arg_type;
384
385         rand_gv = g_variant_get_variant(arg_rand);
386         g_variant_get(rand_gv, "ay", &iter);
387         while ( g_variant_iter_loop (iter, "y", &rt_i)) {
388                 req_auth.rand_data[i] = rt_i;
389                 i++;
390         }
391         req_auth.rand_length = (unsigned int)i;
392
393         i = 0;
394         autn_gv = g_variant_get_variant(arg_autn);
395         g_variant_get(autn_gv, "ay", &iter);
396         while ( g_variant_iter_loop (iter, "y", &rt_i)) {
397                 req_auth.autn_data[i] = rt_i;
398                 i++;
399         }
400         req_auth.autn_length = (unsigned int)i;
401
402         ur = MAKE_UR(ctx, sim, invocation);
403         tcore_user_request_set_data(ur, sizeof(struct treq_sim_req_authentication), &req_auth);
404         tcore_user_request_set_command(ur, TREQ_SIM_REQ_AUTHENTICATION);
405         tcore_communicator_dispatch_request(ctx->comm, ur);
406
407         return TRUE;
408 }
409
410 static gboolean on_sim_verify_sec(TelephonySim *sim, GDBusMethodInvocation *invocation,
411             gint arg_type,
412             const gchar *arg_password,
413                 gpointer user_data)
414 {
415         struct custom_data *ctx = user_data;
416         UserRequest *ur = NULL;
417
418         struct treq_sim_verify_pins verify_pins;
419         memset(&verify_pins, 0, sizeof(struct treq_sim_verify_pins));
420
421         verify_pins.pin_type = arg_type;
422         verify_pins.pin_length = strlen(arg_password);
423         memcpy(verify_pins.pin, arg_password, verify_pins.pin_length);
424
425         ur = MAKE_UR(ctx, sim, invocation);
426         tcore_user_request_set_data(ur, sizeof(struct treq_sim_verify_pins), &verify_pins);
427         tcore_user_request_set_command(ur, TREQ_SIM_VERIFY_PINS);
428         tcore_communicator_dispatch_request(ctx->comm, ur);
429
430         return TRUE;
431 }
432
433 static gboolean on_sim_verify_puk(TelephonySim *sim, GDBusMethodInvocation *invocation,
434             gint arg_type,
435             const gchar *arg_puk,
436             const gchar *arg_new_pin,
437                 gpointer user_data)
438 {
439         struct custom_data *ctx = user_data;
440         UserRequest *ur = NULL;
441
442         struct treq_sim_verify_puks verify_puks;
443         memset(&verify_puks, 0, sizeof(struct treq_sim_verify_puks));
444
445         verify_puks.puk_type = arg_type;
446         verify_puks.puk_length = strlen(arg_puk);
447         memcpy(verify_puks.puk, arg_puk, verify_puks.puk_length);
448         verify_puks.pin_length = strlen(arg_new_pin);
449         memcpy(verify_puks.pin, arg_new_pin, verify_puks.pin_length);
450
451         ur = MAKE_UR(ctx, sim, invocation);
452         tcore_user_request_set_data(ur, sizeof(struct treq_sim_verify_puks), &verify_puks);
453         tcore_user_request_set_command(ur, TREQ_SIM_VERIFY_PUKS);
454         tcore_communicator_dispatch_request(ctx->comm, ur);
455
456         return TRUE;
457 }
458
459 static gboolean on_sim_change_pin(TelephonySim *sim, GDBusMethodInvocation *invocation,
460             gint arg_type,
461             const gchar *arg_old_password,
462             const gchar *arg_new_password,
463                 gpointer user_data)
464 {
465         struct custom_data *ctx = user_data;
466         UserRequest *ur = NULL;
467
468         struct treq_sim_change_pins change_pins;
469         memset(&change_pins, 0, sizeof(struct treq_sim_change_pins));
470
471         change_pins.type = arg_type;
472         change_pins.old_pin_length = strlen(arg_old_password);
473         memcpy(change_pins.old_pin, arg_old_password, change_pins.old_pin_length);
474         change_pins.new_pin_length = strlen(arg_new_password);
475         memcpy(change_pins.new_pin, arg_new_password, change_pins.new_pin_length);
476
477         ur = MAKE_UR(ctx, sim, invocation);
478         tcore_user_request_set_data(ur, sizeof(struct treq_sim_change_pins), &change_pins);
479         tcore_user_request_set_command(ur, TREQ_SIM_CHANGE_PINS);
480         tcore_communicator_dispatch_request(ctx->comm, ur);
481
482         return TRUE;
483 }
484
485 static gboolean on_sim_disable_facility(TelephonySim *sim, GDBusMethodInvocation *invocation,
486             gint arg_type,
487             const gchar *arg_password,
488                 gpointer user_data)
489 {
490         struct custom_data *ctx = user_data;
491         UserRequest *ur = NULL;
492
493         struct treq_sim_disable_facility dis_facility;
494         memset(&dis_facility, 0, sizeof(struct treq_sim_disable_facility));
495
496         dbg("arg_type[%d]", arg_type);
497         switch (arg_type) {
498                 case 1:
499                         dis_facility.type = SIM_FACILITY_PS;
500                         break;
501                 case 3:
502                         dis_facility.type = SIM_FACILITY_SC;
503                         break;
504                 case 4:
505                         dis_facility.type = SIM_FACILITY_FD;
506                         break;
507                 case 5:
508                         dis_facility.type = SIM_FACILITY_PN;
509                         break;
510                 case 6:
511                         dis_facility.type = SIM_FACILITY_PU;
512                         break;
513                 case 7:
514                         dis_facility.type = SIM_FACILITY_PP;
515                         break;
516                 case 8:
517                         dis_facility.type = SIM_FACILITY_PC;
518                         break;
519                 default:
520                         dbg("error - not handled type[%d]", arg_type);
521                         break;
522         }
523         dis_facility.password_length = strlen(arg_password);
524         memcpy(dis_facility.password, arg_password, dis_facility.password_length);
525
526         ur = MAKE_UR(ctx, sim, invocation);
527         tcore_user_request_set_data(ur, sizeof(struct treq_sim_disable_facility), &dis_facility);
528         tcore_user_request_set_command(ur, TREQ_SIM_DISABLE_FACILITY);
529         tcore_communicator_dispatch_request(ctx->comm, ur);
530
531         return TRUE;
532 }
533
534 static gboolean on_sim_enable_facility(TelephonySim *sim, GDBusMethodInvocation *invocation,
535             gint arg_type,
536             const gchar *arg_password,
537                 gpointer user_data)
538 {
539         struct custom_data *ctx = user_data;
540         UserRequest *ur = NULL;
541
542         struct treq_sim_enable_facility en_facility;
543         memset(&en_facility, 0, sizeof(struct treq_sim_enable_facility));
544
545         dbg("arg_type[%d]", arg_type);
546         switch (arg_type) {
547                 case 1:
548                         en_facility.type = SIM_FACILITY_PS;
549                         break;
550                 case 3:
551                         en_facility.type = SIM_FACILITY_SC;
552                         break;
553                 case 4:
554                         en_facility.type = SIM_FACILITY_FD;
555                         break;
556                 case 5:
557                         en_facility.type = SIM_FACILITY_PN;
558                         break;
559                 case 6:
560                         en_facility.type = SIM_FACILITY_PU;
561                         break;
562                 case 7:
563                         en_facility.type = SIM_FACILITY_PP;
564                         break;
565                 case 8:
566                         en_facility.type = SIM_FACILITY_PC;
567                         break;
568                 default:
569                         dbg("error - not handled type[%d]", arg_type);
570                         break;
571         }
572         en_facility.password_length = strlen(arg_password);
573         memcpy(en_facility.password, arg_password, en_facility.password_length);
574
575         ur = MAKE_UR(ctx, sim, invocation);
576         tcore_user_request_set_data(ur, sizeof(struct treq_sim_enable_facility), &en_facility);
577         tcore_user_request_set_command(ur, TREQ_SIM_ENABLE_FACILITY);
578         tcore_communicator_dispatch_request(ctx->comm, ur);
579
580         return TRUE;
581 }
582
583 static gboolean on_sim_get_facility(TelephonySim *sim, GDBusMethodInvocation *invocation,
584             gint arg_type,
585                 gpointer user_data)
586 {
587         struct custom_data *ctx = user_data;
588         UserRequest *ur = NULL;
589
590         struct treq_sim_get_facility_status facility;
591         memset(&facility, 0, sizeof(struct treq_sim_get_facility_status));
592
593         dbg("arg_type[%d]", arg_type);
594         switch (arg_type) {
595                 case 1:
596                         facility.type = SIM_FACILITY_PS;
597                         break;
598                 case 3:
599                         facility.type = SIM_FACILITY_SC;
600                         break;
601                 case 4:
602                         facility.type = SIM_FACILITY_FD;
603                         break;
604                 case 5:
605                         facility.type = SIM_FACILITY_PN;
606                         break;
607                 case 6:
608                         facility.type = SIM_FACILITY_PU;
609                         break;
610                 case 7:
611                         facility.type = SIM_FACILITY_PP;
612                         break;
613                 case 8:
614                         facility.type = SIM_FACILITY_PC;
615                         break;
616                 default:
617                         dbg("error - not handled type[%d]", arg_type);
618                         break;
619         }
620
621         ur = MAKE_UR(ctx, sim, invocation);
622         tcore_user_request_set_data(ur, sizeof(struct treq_sim_get_facility_status), &facility);
623         tcore_user_request_set_command(ur, TREQ_SIM_GET_FACILITY_STATUS);
624         tcore_communicator_dispatch_request(ctx->comm, ur);
625
626         return TRUE;
627 }
628
629 static gboolean on_sim_get_lock_info(TelephonySim *sim, GDBusMethodInvocation *invocation,
630             gint arg_type,
631                 gpointer user_data)
632 {
633         struct custom_data *ctx = user_data;
634         UserRequest *ur = NULL;
635
636         struct treq_sim_get_lock_info lock_info;
637         memset(&lock_info, 0, sizeof(struct treq_sim_get_lock_info));
638
639         dbg("arg_type[%d]", arg_type);
640         switch (arg_type) {
641                 case 1:
642                         lock_info.type = SIM_FACILITY_PS;
643                         break;
644                 case 3:
645                         lock_info.type = SIM_FACILITY_SC;
646                         break;
647                 case 4:
648                         lock_info.type = SIM_FACILITY_FD;
649                         break;
650                 case 5:
651                         lock_info.type = SIM_FACILITY_PN;
652                         break;
653                 case 6:
654                         lock_info.type = SIM_FACILITY_PU;
655                         break;
656                 case 7:
657                         lock_info.type = SIM_FACILITY_PP;
658                         break;
659                 case 8:
660                         lock_info.type = SIM_FACILITY_PC;
661                         break;
662                 default:
663                         dbg("error - not handled type[%d]", arg_type);
664                         break;
665         }
666
667         ur = MAKE_UR(ctx, sim, invocation);
668         tcore_user_request_set_data(ur, sizeof(struct treq_sim_get_lock_info), &lock_info);
669         tcore_user_request_set_command(ur, TREQ_SIM_GET_LOCK_INFO);
670         tcore_communicator_dispatch_request(ctx->comm, ur);
671
672         return TRUE;
673 }
674
675 static gboolean on_sim_transfer_apdu(TelephonySim *sim, GDBusMethodInvocation *invocation,
676                 GVariant *arg_apdu,
677                 gpointer user_data)
678 {
679         struct custom_data *ctx = user_data;
680         UserRequest *ur = NULL;
681         struct treq_sim_transmit_apdu send_apdu;
682
683         GVariantIter *iter = NULL;
684         GVariant *inner_gv = NULL;
685         guchar rt_i;
686         int i =0;
687
688         dbg("Func Entrance");
689         memset(&send_apdu, 0, sizeof(struct treq_sim_transmit_apdu));
690
691         inner_gv = g_variant_get_variant(arg_apdu);
692
693         g_variant_get(inner_gv, "ay", &iter);
694         while ( g_variant_iter_loop (iter, "y", &rt_i)) {
695                 send_apdu.apdu[i] = rt_i;
696                 i++;
697         }
698         send_apdu.apdu_length = (unsigned int)i;
699         g_variant_iter_free0(iter);
700         g_variant_unref(inner_gv);
701         g_variant_unref(arg_apdu);
702
703         for(i=0; i < (int)send_apdu.apdu_length; i++)
704                 dbg("apdu[%d][0x%02x]",i, send_apdu.apdu[i]);
705
706         ur = MAKE_UR(ctx, sim, invocation);
707         tcore_user_request_set_data(ur, sizeof(struct treq_sim_transmit_apdu), &send_apdu);
708         tcore_user_request_set_command(ur, TREQ_SIM_TRANSMIT_APDU);
709         tcore_communicator_dispatch_request(ctx->comm, ur);
710
711         return TRUE;
712 }
713
714 static gboolean on_sim_get_atr(TelephonySim *sim, GDBusMethodInvocation *invocation,
715                 gpointer user_data)
716 {
717         struct custom_data *ctx = user_data;
718         UserRequest *ur = NULL;
719
720         ur = MAKE_UR(ctx, sim, invocation);
721
722         tcore_user_request_set_command(ur, TREQ_SIM_GET_ATR);
723         tcore_communicator_dispatch_request(ctx->comm, ur);
724
725         return TRUE;
726 }
727
728 gboolean dbus_plugin_setup_sim_interface(TelephonyObjectSkeleton *object, struct custom_data *ctx)
729 {
730         TelephonySim *sim;
731
732         sim = telephony_sim_skeleton_new();
733         telephony_object_skeleton_set_sim(object, sim);
734         g_object_unref(sim);
735
736         dbg("sim = %p", sim);
737
738         g_signal_connect (sim,
739                         "handle-get-init-status",
740                         G_CALLBACK (on_sim_get_init_status),
741                         ctx);
742
743         g_signal_connect (sim,
744                         "handle-get-card-type",
745                         G_CALLBACK (on_sim_get_card_type),
746                         ctx);
747
748         g_signal_connect (sim,
749                         "handle-get-imsi",
750                         G_CALLBACK (on_sim_get_imsi),
751                         ctx);
752
753         g_signal_connect (sim,
754                         "handle-get-ecc",
755                         G_CALLBACK (on_sim_get_ecc),
756                         ctx);
757
758         g_signal_connect (sim,
759                         "handle-get-iccid",
760                         G_CALLBACK (on_sim_get_iccid),
761                         ctx);
762
763         g_signal_connect (sim,
764                         "handle-get-language",
765                         G_CALLBACK (on_sim_get_language),
766                         ctx);
767
768         g_signal_connect (sim,
769                         "handle-set-language",
770                         G_CALLBACK (on_sim_set_language),
771                         ctx);
772
773         g_signal_connect (sim,
774                         "handle-get-callforwarding",
775                         G_CALLBACK (on_sim_get_callforwarding),
776                         ctx);
777
778         g_signal_connect (sim,
779                         "handle-get-message-waiting",
780                         G_CALLBACK (on_sim_get_message_waiting),
781                         ctx);
782
783         g_signal_connect (sim,
784                         "handle-get-mailbox",
785                         G_CALLBACK (on_sim_get_mailbox),
786                         ctx);
787
788         g_signal_connect (sim,
789                         "handle-get-cphsinfo",
790                         G_CALLBACK (on_sim_get_cphsinfo),
791                         ctx);
792
793         g_signal_connect (sim,
794                         "handle-get-msisdn",
795                         G_CALLBACK (on_sim_get_msisdn),
796                         ctx);
797
798         g_signal_connect (sim,
799                         "handle-get-oplmnwact",
800                         G_CALLBACK (on_sim_get_oplmnwact),
801                         ctx);
802
803         g_signal_connect (sim,
804                         "handle-get-spn",
805                         G_CALLBACK (on_sim_get_spn),
806                         ctx);
807
808         g_signal_connect (sim,
809                         "handle-get-cphs-net-name",
810                         G_CALLBACK (on_sim_get_cphs_netname),
811                         ctx);
812
813         g_signal_connect (sim,
814                         "handle-authentication",
815                         G_CALLBACK (on_sim_authentication),
816                         ctx);
817
818         g_signal_connect (sim,
819                         "handle-verify-sec",
820                         G_CALLBACK (on_sim_verify_sec),
821                         ctx);
822
823         g_signal_connect (sim,
824                         "handle-verify-puk",
825                         G_CALLBACK (on_sim_verify_puk),
826                         ctx);
827
828         g_signal_connect (sim,
829                         "handle-change-pin",
830                         G_CALLBACK (on_sim_change_pin),
831                         ctx);
832
833         g_signal_connect (sim,
834                         "handle-disable-facility",
835                         G_CALLBACK (on_sim_disable_facility),
836                         ctx);
837
838         g_signal_connect (sim,
839                         "handle-enable-facility",
840                         G_CALLBACK (on_sim_enable_facility),
841                         ctx);
842
843         g_signal_connect (sim,
844                         "handle-get-facility",
845                         G_CALLBACK (on_sim_get_facility),
846                         ctx);
847
848         g_signal_connect (sim,
849                         "handle-get-lock-info",
850                         G_CALLBACK (on_sim_get_lock_info),
851                         ctx);
852
853         g_signal_connect (sim,
854                         "handle-transfer-apdu",
855                         G_CALLBACK (on_sim_transfer_apdu),
856                         ctx);
857
858         g_signal_connect (sim,
859                         "handle-get-atr",
860                         G_CALLBACK (on_sim_get_atr),
861                         ctx);
862
863         return TRUE;
864 }
865
866 gboolean dbus_plugin_sim_response(struct custom_data *ctx, UserRequest *ur,
867                 struct dbus_request_info *dbus_info, enum tcore_response_command command,
868                 unsigned int data_len, const void *data)
869 {
870         const struct tresp_sim_verify_pins *resp_verify_pins = data;
871         const struct tresp_sim_verify_puks *resp_verify_puks = data;
872         const struct tresp_sim_change_pins *resp_change_pins = data;
873         const struct tresp_sim_get_facility_status *resp_get_facility = data;
874         const struct tresp_sim_disable_facility *resp_dis_facility = data;
875         const struct tresp_sim_enable_facility *resp_en_facility = data;
876         const struct tresp_sim_transmit_apdu *resp_apdu = data;
877         const struct tresp_sim_get_atr *resp_get_atr = data;
878         const struct tresp_sim_read *resp_read = data;
879         const struct tresp_sim_req_authentication *resp_auth = data;
880         const struct tresp_sim_set_language *resp_set_language = data;
881         const struct tresp_sim_get_lock_info *resp_lock = data;
882         gint f_type =0;
883         int i =0;
884         dbg("Command = [0x%x], data_len = %d", command, data_len);
885
886         switch (command) {
887                 case TRESP_SIM_GET_ECC: {
888                         dbg("resp comm - TRESP_SIM_GET_ECC");
889                         /*                      GVariant *gv = NULL;
890                         GVariantBuilder b;
891                         g_variant_builder_init(&b, G_VARIANT_TYPE("aa{sv}"));
892
893                         for (i = 0; i < resp_read->data.ecc.ecc_count; i++) {
894                                 g_variant_builder_open(&b, G_VARIANT_TYPE("a{sv}"));
895                                 g_variant_builder_add(&b, "{sv}", "name", g_variant_new_string(resp_read->data.ecc.ecc[i].ecc_string));
896                                 g_variant_builder_add(&b, "{sv}", "number", g_variant_new_string(resp_read->data.ecc.ecc[i].ecc_num));
897                                 g_variant_builder_add(&b, "{sv}", "category", g_variant_new_int32(resp_read->data.ecc.ecc[i].ecc_category));
898                                 g_variant_builder_close(&b);
899                         }
900                         gv = g_variant_builder_end(&b);
901                         ctx->cached_sim_ecc = gv;*/
902                         memcpy((void*)&ctx->cached_sim_ecc, (const void*)&resp_read->data.ecc, sizeof(struct tel_sim_ecc_list));
903                 }
904                         break;
905
906                 case TRESP_SIM_GET_ICCID:
907                         dbg("resp comm - TRESP_SIM_GET_ICCID");
908                         dbg("dbus_info->interface_object[%p], dbus_info->invocation[%p],dbus_info->interface_object, dbus_info->invocation");
909                         dbg("result[%d], iccid[%s]", resp_read->result, resp_read->data.iccid.iccid);
910                         telephony_sim_complete_get_iccid(dbus_info->interface_object, dbus_info->invocation,
911                                         resp_read->result,
912                                         resp_read->data.iccid.iccid);
913                         break;
914
915                 case TRESP_SIM_GET_LANGUAGE:
916                         dbg("resp comm - TRESP_SIM_GET_LANGUAGE");
917                         telephony_sim_complete_get_language(dbus_info->interface_object, dbus_info->invocation,
918                                         resp_read->result,
919                                         resp_read->data.language.language[0]);
920                         break;
921
922                 case TRESP_SIM_SET_LANGUAGE:
923                         dbg("resp comm - TRESP_SIM_SET_LANGUAGE");
924                         telephony_sim_complete_set_language(dbus_info->interface_object, dbus_info->invocation,
925                                         resp_set_language->result);
926                         break;
927
928                 case TRESP_SIM_GET_CALLFORWARDING:
929                         dbg("resp comm - TRESP_SIM_GET_CALLFORWARDING");
930                         telephony_sim_complete_get_callforwarding (dbus_info->interface_object, dbus_info->invocation,
931                                         resp_read->result,
932                                         resp_read->data.cf.voice1,
933                                         resp_read->data.cf.voice2);
934                         break;
935
936                 case TRESP_SIM_GET_MESSAGEWAITING:
937                         dbg("resp comm - TRESP_SIM_GET_MESSAGEWAITING");
938                         if (resp_read->data.mw.b_cphs) {
939                                 telephony_sim_complete_get_message_waiting(dbus_info->interface_object, dbus_info->invocation,
940                                                 resp_read->result,
941                                                 resp_read->data.mw.mw_data_u.cphs_mw.b_voice1,
942                                                 resp_read->data.mw.mw_data_u.cphs_mw.b_voice2,
943                                                 resp_read->data.mw.mw_data_u.cphs_mw.b_fax,
944                                                 resp_read->data.mw.mw_data_u.cphs_mw.b_data);
945                         } else {
946                                 telephony_sim_complete_get_message_waiting(dbus_info->interface_object, dbus_info->invocation,
947                                                 resp_read->result,
948                                                 resp_read->data.mw.mw_data_u.mw.voice_count,
949                                                 0,
950                                                 resp_read->data.mw.mw_data_u.mw.fax_count,
951                                                 resp_read->data.mw.mw_data_u.mw.video_count);
952                         }
953                         break;
954
955                 case TRESP_SIM_GET_MAILBOX: {
956                         GVariant *gv = NULL;
957                         GVariantBuilder b;
958                         dbg("resp comm - TRESP_SIM_GET_MAILBOX");
959
960                         g_variant_builder_init(&b, G_VARIANT_TYPE("aa{sv}"));
961
962                         if(resp_read->data.mailbox.voice1.DiallingnumLength){
963                                 g_variant_builder_open(&b, G_VARIANT_TYPE("a{sv}"));
964                                 g_variant_builder_add(&b, "{sv}", "type", g_variant_new_string("voice1"));
965                                 g_variant_builder_add(&b, "{sv}", "name", g_variant_new_string(resp_read->data.mailbox.voice1.AlphaId));
966                                 g_variant_builder_add(&b, "{sv}", "number", g_variant_new_string(resp_read->data.mailbox.voice1.DiallingNum));
967                                 g_variant_builder_add(&b, "{sv}", "ton", g_variant_new_int32(resp_read->data.mailbox.voice1.TypeOfNumber));
968                                 g_variant_builder_close(&b);
969                         }
970
971                         if(resp_read->data.mailbox.voice2.DiallingnumLength){
972                                 g_variant_builder_open(&b, G_VARIANT_TYPE("a{sv}"));
973                                 g_variant_builder_add(&b, "{sv}", "type", g_variant_new_string("voice2"));
974                                 g_variant_builder_add(&b, "{sv}", "name", g_variant_new_string(resp_read->data.mailbox.voice2.AlphaId));
975                                 g_variant_builder_add(&b, "{sv}", "number", g_variant_new_string(resp_read->data.mailbox.voice2.DiallingNum));
976                                 g_variant_builder_add(&b, "{sv}", "ton", g_variant_new_int32(resp_read->data.mailbox.voice2.TypeOfNumber));
977                                 g_variant_builder_close(&b);
978                         }
979
980                         if(resp_read->data.mailbox.fax.DiallingnumLength){
981                                 g_variant_builder_open(&b, G_VARIANT_TYPE("a{sv}"));
982                                 g_variant_builder_add(&b, "{sv}", "type", g_variant_new_string("fax"));
983                                 g_variant_builder_add(&b, "{sv}", "name", g_variant_new_string(resp_read->data.mailbox.fax.AlphaId));
984                                 g_variant_builder_add(&b, "{sv}", "number", g_variant_new_string(resp_read->data.mailbox.fax.DiallingNum));
985                                 g_variant_builder_add(&b, "{sv}", "ton", g_variant_new_int32(resp_read->data.mailbox.fax.TypeOfNumber));
986                                 g_variant_builder_close(&b);
987                         }
988
989                         if(resp_read->data.mailbox.video.DiallingnumLength){
990                                 g_variant_builder_open(&b, G_VARIANT_TYPE("a{sv}"));
991                                 g_variant_builder_add(&b, "{sv}", "type", g_variant_new_string("video"));
992                                 g_variant_builder_add(&b, "{sv}", "name", g_variant_new_string(resp_read->data.mailbox.video.AlphaId));
993                                 g_variant_builder_add(&b, "{sv}", "number", g_variant_new_string(resp_read->data.mailbox.video.DiallingNum));
994                                 g_variant_builder_add(&b, "{sv}", "ton", g_variant_new_int32(resp_read->data.mailbox.video.TypeOfNumber));
995                                 g_variant_builder_close(&b);
996                         }
997                         gv = g_variant_builder_end(&b);
998                         telephony_sim_complete_get_mailbox (dbus_info->interface_object, dbus_info->invocation,
999                                         resp_read->result,
1000                                         gv);
1001                         g_variant_unref(gv);
1002                 }
1003                         break;
1004
1005                 case TRESP_SIM_GET_CPHS_INFO:
1006                         dbg("resp comm - TRESP_SIM_GET_CPHS_INFO");
1007                         telephony_sim_complete_get_cphsinfo (dbus_info->interface_object, dbus_info->invocation,
1008                                         resp_read->result,
1009                                         resp_read->data.cphs.CphsPhase,
1010                                         resp_read->data.cphs.CphsServiceTable.bOperatorNameShortForm,
1011                                         resp_read->data.cphs.CphsServiceTable.bMailBoxNumbers,
1012                                         resp_read->data.cphs.CphsServiceTable.bServiceStringTable,
1013                                         resp_read->data.cphs.CphsServiceTable.bCustomerServiceProfile,
1014                                         resp_read->data.cphs.CphsServiceTable.bInformationNumbers);
1015                         break;
1016
1017                 case TRESP_SIM_GET_SPN:
1018                         dbg("resp comm - TRESP_SIM_GET_SPN");
1019                         telephony_sim_complete_get_spn (dbus_info->interface_object, dbus_info->invocation,
1020                                         resp_read->result,
1021                                         resp_read->data.spn.display_condition, (const gchar *)resp_read->data.spn.spn);
1022                         break;
1023
1024                 case TRESP_SIM_GET_CPHS_NETNAME:
1025                         dbg("resp comm - TRESP_SIM_GET_CPHS_NETNAME");
1026                         telephony_sim_complete_get_cphs_net_name (dbus_info->interface_object, dbus_info->invocation,
1027                                         resp_read->result,
1028                                         (const gchar *)resp_read->data.cphs_net.full_name, (const gchar *)resp_read->data.cphs_net.short_name);
1029                         break;
1030
1031                 case TRESP_SIM_GET_MSISDN:{
1032                         GVariant *gv = NULL;
1033                         GVariantBuilder b;
1034                         dbg("resp comm - TRESP_SIM_GET_MSISDN");
1035                         g_variant_builder_init(&b, G_VARIANT_TYPE("aa{sv}"));
1036
1037                         for(i=0;i < resp_read->data.msisdn_list.count; i++){
1038                                 g_variant_builder_open(&b,G_VARIANT_TYPE("a{sv}"));
1039                                 g_variant_builder_add(&b, "{sv}", "name", g_variant_new_string((const gchar *)resp_read->data.msisdn_list.msisdn[i].name));
1040                                 g_variant_builder_add(&b, "{sv}", "number", g_variant_new_string((const gchar *)resp_read->data.msisdn_list.msisdn[i].num));
1041                                 g_variant_builder_close(&b);
1042                         }
1043                         gv = g_variant_builder_end(&b);
1044
1045                         telephony_sim_complete_get_msisdn (dbus_info->interface_object, dbus_info->invocation,
1046                                         resp_read->result,
1047                                         gv);
1048                         g_variant_unref(gv);
1049                 }
1050                         break;
1051
1052                 case TRESP_SIM_GET_OPLMNWACT:{
1053                         GVariant *gv = NULL;
1054                         GVariantBuilder b;
1055                         dbg("resp comm - TRESP_SIM_GET_OPLMNWACT");
1056                         g_variant_builder_init(&b, G_VARIANT_TYPE("aa{sv}"));
1057
1058                         for(i=0;i < resp_read->data.opwa.opwa_count; i++){
1059                                 g_variant_builder_open(&b,G_VARIANT_TYPE("a{sv}"));
1060                                 g_variant_builder_add(&b, "{sv}", "plmn", g_variant_new_string((const gchar *)resp_read->data.opwa.opwa[i].plmn));
1061                                 g_variant_builder_add(&b, "{sv}", "b_umts", g_variant_new_boolean(resp_read->data.opwa.opwa[i].b_umts));
1062                                 g_variant_builder_add(&b, "{sv}", "b_gsm", g_variant_new_boolean(resp_read->data.opwa.opwa[i].b_gsm));
1063                                 g_variant_builder_close(&b);
1064                         }
1065                         gv = g_variant_builder_end(&b);
1066
1067                         telephony_sim_complete_get_oplmnwact (dbus_info->interface_object, dbus_info->invocation,
1068                                         resp_read->result,
1069                                         gv);
1070                         g_variant_unref(gv);
1071                 }
1072                         break;
1073
1074                 case TRESP_SIM_REQ_AUTHENTICATION: {
1075                         GVariantBuilder *builder = NULL;
1076                         GVariant *ak = NULL;
1077                         GVariant *cp = NULL;
1078                         GVariant *it = NULL;
1079                         GVariant *resp = NULL;
1080                         GVariant *ak_gv = NULL;
1081                         GVariant *cp_gv = NULL;
1082                         GVariant *it_gv = NULL;
1083                         GVariant *resp_gv = NULL;
1084                         int i =0;
1085
1086                         dbg("resp comm - TRESP_SIM_REQ_AUTHENTICATION");
1087
1088                         builder = g_variant_builder_new (G_VARIANT_TYPE ("ay"));
1089                         for(i = 0; i < (int)resp_auth->authentication_key_length; i++) {
1090                                 dbg("resp_auth->authentication_key[%d][0x%02x]", i,resp_auth->authentication_key[i]);
1091                                 g_variant_builder_add (builder, "y", resp_auth->authentication_key[i]);
1092                         }
1093                         ak = g_variant_builder_end(builder);
1094                         ak_gv = g_variant_new("v", ak);
1095
1096                         builder = g_variant_builder_new (G_VARIANT_TYPE ("ay"));
1097                         for(i = 0; i < (int)resp_auth->cipher_length; i++) {
1098                                 dbg("resp_auth->cipher_data[%d][0x%02x]", i,resp_auth->cipher_data[i]);
1099                                 g_variant_builder_add (builder, "y", resp_auth->cipher_data[i]);
1100                         }
1101                         cp = g_variant_builder_end(builder);
1102                         cp_gv = g_variant_new("v", cp);
1103
1104                         builder = g_variant_builder_new (G_VARIANT_TYPE ("ay"));
1105                         for(i = 0; i < (int)resp_auth->integrity_length; i++) {
1106                                 dbg("resp_auth->integrity_data[%d][0x%02x]", i,resp_auth->integrity_data[i]);
1107                                 g_variant_builder_add (builder, "y", resp_auth->integrity_data[i]);
1108                         }
1109                         it = g_variant_builder_end(builder);
1110                         it_gv = g_variant_new("v", it);
1111
1112                         builder = g_variant_builder_new (G_VARIANT_TYPE ("ay"));
1113                         for(i = 0; i < (int)resp_auth->resp_length; i++) {
1114                                 dbg("resp_auth->resp_data[%d][0x%02x]", i,resp_auth->resp_data[i]);
1115                                 g_variant_builder_add (builder, "y", resp_auth->resp_data[i]);
1116                         }
1117                         resp = g_variant_builder_end(builder);
1118                         resp_gv = g_variant_new("v", resp);
1119
1120                         telephony_sim_complete_authentication (dbus_info->interface_object, dbus_info->invocation,
1121                                         resp_auth->result,
1122                                         resp_auth->auth_type,
1123                                         resp_auth->auth_result,
1124                                         ak_gv,
1125                                         cp_gv,
1126                                         it_gv,
1127                                         resp_gv);
1128                 }
1129                         break;
1130
1131                 case TRESP_SIM_VERIFY_PINS:
1132                         dbg("resp comm - TRESP_SIM_VERIFY_PINS");
1133                         telephony_sim_complete_verify_sec(dbus_info->interface_object, dbus_info->invocation,
1134                                         resp_verify_pins->result,
1135                                         resp_verify_pins->pin_type,
1136                                         resp_verify_pins->retry_count);
1137                         break;
1138
1139                 case TRESP_SIM_VERIFY_PUKS:
1140                         dbg("resp comm - TRESP_SIM_VERIFY_PUKS");
1141                         telephony_sim_complete_verify_puk (dbus_info->interface_object, dbus_info->invocation,
1142                                         resp_verify_puks->result,
1143                                         resp_verify_puks->pin_type,
1144                                         resp_verify_puks->retry_count);
1145                         break;
1146
1147                 case TRESP_SIM_CHANGE_PINS:
1148                         dbg("resp comm - TRESP_SIM_CHANGE_PINS");
1149                         telephony_sim_complete_change_pin(dbus_info->interface_object, dbus_info->invocation,
1150                                         resp_change_pins->result,
1151                                         resp_change_pins->pin_type,
1152                                         resp_change_pins->retry_count);
1153                         break;
1154
1155                 case TRESP_SIM_DISABLE_FACILITY:
1156                         dbg("resp comm - TRESP_SIM_DISABLE_FACILITY");
1157                         dbg("resp_dis_facility->type[%d]", resp_dis_facility->type);
1158                         switch (resp_dis_facility->type) {
1159                                 case SIM_FACILITY_PS:
1160                                         f_type = 1;
1161                                         break;
1162                                 case SIM_FACILITY_SC:
1163                                         f_type = 3;
1164                                         break;
1165                                 case SIM_FACILITY_FD:
1166                                         f_type = 4;
1167                                         break;
1168                                 case SIM_FACILITY_PN:
1169                                         f_type = 5;
1170                                         break;
1171                                 case SIM_FACILITY_PU:
1172                                         f_type = 6;
1173                                         break;
1174                                 case SIM_FACILITY_PP:
1175                                         f_type = 7;
1176                                         break;
1177                                 case SIM_FACILITY_PC:
1178                                         f_type = 8;
1179                                         break;
1180                                 default:
1181                                         dbg("error - not handled type[%d]", resp_dis_facility->type);
1182                                         break;
1183                         }
1184                         telephony_sim_complete_disable_facility(dbus_info->interface_object, dbus_info->invocation,
1185                                         resp_dis_facility->result,
1186                                         f_type,
1187                                         resp_dis_facility->retry_count);
1188                         break;
1189
1190                 case TRESP_SIM_ENABLE_FACILITY:
1191                         dbg("resp comm - TRESP_SIM_ENABLE_FACILITY");
1192                         dbg("resp_en_facility->type[%d]", resp_en_facility->type);
1193                         switch (resp_en_facility->type) {
1194                                 case SIM_FACILITY_PS:
1195                                         f_type = 1;
1196                                         break;
1197                                 case SIM_FACILITY_SC:
1198                                         f_type = 3;
1199                                         break;
1200                                 case SIM_FACILITY_FD:
1201                                         f_type = 4;
1202                                         break;
1203                                 case SIM_FACILITY_PN:
1204                                         f_type = 5;
1205                                         break;
1206                                 case SIM_FACILITY_PU:
1207                                         f_type = 6;
1208                                         break;
1209                                 case SIM_FACILITY_PP:
1210                                         f_type = 7;
1211                                         break;
1212                                 case SIM_FACILITY_PC:
1213                                         f_type = 8;
1214                                         break;
1215                                 default:
1216                                         dbg("error - not handled type[%d]", resp_en_facility->type);
1217                                         break;
1218                         }
1219                         telephony_sim_complete_enable_facility(dbus_info->interface_object, dbus_info->invocation,
1220                                         resp_en_facility->result,
1221                                         f_type,
1222                                         resp_en_facility->retry_count);
1223                         break;
1224
1225                 case TRESP_SIM_GET_FACILITY_STATUS:
1226                         dbg("resp comm - TRESP_SIM_GET_FACILITY_STATUS");
1227                         dbg("resp_get_facility->type[%d]", resp_get_facility->type);
1228                         switch (resp_get_facility->type) {
1229                                 case SIM_FACILITY_PS:
1230                                         f_type = 1;
1231                                         break;
1232                                 case SIM_FACILITY_SC:
1233                                         f_type = 3;
1234                                         break;
1235                                 case SIM_FACILITY_FD:
1236                                         f_type = 4;
1237                                         break;
1238                                 case SIM_FACILITY_PN:
1239                                         f_type = 5;
1240                                         break;
1241                                 case SIM_FACILITY_PU:
1242                                         f_type = 6;
1243                                         break;
1244                                 case SIM_FACILITY_PP:
1245                                         f_type = 7;
1246                                         break;
1247                                 case SIM_FACILITY_PC:
1248                                         f_type = 8;
1249                                         break;
1250                                 default:
1251                                         dbg("error - not handled type[%d]", resp_get_facility->type);
1252                                         break;
1253                         }
1254                         telephony_sim_complete_get_facility(dbus_info->interface_object, dbus_info->invocation,
1255                                         resp_get_facility->result,
1256                                         f_type,
1257                                         resp_get_facility->b_enable);
1258                         break;
1259
1260                 case TRESP_SIM_GET_LOCK_INFO:
1261                         dbg("resp comm - TRESP_SIM_GET_LOCK_INFO");
1262                         dbg("resp_lock->type[%d]", resp_lock->type);
1263                         switch (resp_lock->type) {
1264                                 case SIM_FACILITY_PS:
1265                                         f_type = 1;
1266                                         break;
1267                                 case SIM_FACILITY_SC:
1268                                         f_type = 3;
1269                                         break;
1270                                 case SIM_FACILITY_FD:
1271                                         f_type = 4;
1272                                         break;
1273                                 case SIM_FACILITY_PN:
1274                                         f_type = 5;
1275                                         break;
1276                                 case SIM_FACILITY_PU:
1277                                         f_type = 6;
1278                                         break;
1279                                 case SIM_FACILITY_PP:
1280                                         f_type = 7;
1281                                         break;
1282                                 case SIM_FACILITY_PC:
1283                                         f_type = 8;
1284                                         break;
1285                                 default:
1286                                         dbg("error - not handled type[%d]", resp_lock->type);
1287                                         break;
1288                         }
1289                         telephony_sim_complete_get_lock_info(dbus_info->interface_object, dbus_info->invocation,
1290                                         resp_lock->result,
1291                                         f_type,
1292                                         resp_lock->lock_status,
1293                                         resp_lock->retry_count);
1294                         break;
1295
1296                 case TRESP_SIM_TRANSMIT_APDU: {
1297                         GVariantBuilder *builder = NULL;
1298                         GVariant * apdu_gv = NULL;
1299                         GVariant *inner_gv = NULL;
1300                         int i =0;
1301
1302                         dbg("resp comm - TRESP_SIM_TRANSMIT_APDU");
1303                         builder = g_variant_builder_new (G_VARIANT_TYPE ("ay"));
1304                         for(i = 0; i < (int)resp_apdu->apdu_resp_length; i++) {
1305                                 dbg("resp_apdu->apdu_resp[%d][0x%02x]", i,resp_apdu->apdu_resp[i]);
1306                                 g_variant_builder_add (builder, "y", resp_apdu->apdu_resp[i]);
1307                         }
1308                         inner_gv = g_variant_builder_end(builder);
1309 /*                      g_variant_builder_unref (builder);*/
1310                         apdu_gv = g_variant_new("v", inner_gv);
1311
1312                         telephony_sim_complete_transfer_apdu(dbus_info->interface_object, dbus_info->invocation,
1313                                         resp_apdu->result,
1314                                         apdu_gv);
1315                 }
1316                         break;
1317
1318                 case TRESP_SIM_GET_ATR:{
1319                         GVariantBuilder *builder = NULL;
1320                         GVariant * atr_gv = NULL;
1321                         GVariant *inner_gv = NULL;
1322                         int i =0;
1323
1324                         dbg("resp comm - TRESP_SIM_GET_ATR");
1325                         builder = g_variant_builder_new (G_VARIANT_TYPE ("ay"));
1326                         for(i = 0; i < (int)resp_get_atr->atr_length; i++) {
1327                                 dbg("resp_apdu->apdu_resp[%d][0x%02x]", i,resp_get_atr->atr[i]);
1328                                 g_variant_builder_add (builder, "y", resp_get_atr->atr[i]);
1329                         }
1330                         inner_gv = g_variant_builder_end(builder);
1331 /*                      g_variant_builder_unref (builder);*/
1332                         atr_gv = g_variant_new("v", inner_gv);
1333
1334                         telephony_sim_complete_get_atr(dbus_info->interface_object, dbus_info->invocation,
1335                                         resp_get_atr->result,
1336                                         atr_gv);
1337                 }
1338                         break;
1339
1340                 default:
1341                         dbg("not handled TRESP type[%d]", command);
1342                         break;
1343         }
1344         return TRUE;
1345 }
1346
1347 gboolean dbus_plugin_sim_notification(struct custom_data *ctx, const char *plugin_name,
1348                 TelephonyObjectSkeleton *object, enum tcore_notification_command command,
1349                 unsigned int data_len, const void *data)
1350 {
1351         TelephonySim *sim;
1352         const struct tnoti_sim_status *n_sim_status = data;
1353
1354         if (!object) {
1355                 dbg("object is NULL");
1356                 return FALSE;
1357         }
1358
1359         sim = telephony_object_peek_sim(TELEPHONY_OBJECT(object));
1360         dbg("sim = %p", sim);
1361
1362         dbg("notification !!! (command = 0x%x, data_len = %d)", command, data_len);
1363
1364         switch (command) {
1365                 case TNOTI_SIM_STATUS:
1366                         dbg("notified sim_status[%d]", n_sim_status->sim_status);
1367                         dbus_sim_data_request(ctx, n_sim_status->sim_status);
1368                         telephony_sim_emit_status (sim, n_sim_status->sim_status);
1369                         break;
1370
1371                 default:
1372                 dbg("not handled command[%d]", command);
1373                 break;
1374         }
1375
1376         return TRUE;
1377 }