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