fe95de95890caa244071cfdc23e829a8f87f3979
[framework/telephony/tel-plugin-socket_communicator.git] / plugin / src / socket_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-object.h>
26
27 #include <tcore.h>
28 #include <server.h>
29 #include <plugin.h>
30 #include <hal.h>
31 #include <communicator.h>
32 #include <core_object.h>
33 #include <queue.h>
34 #include <user_request.h>
35 #include <util.h>
36 #include <co_sim.h>
37
38 #include "sipc.h"
39 #include "tapi_common.h"
40 #include "module_req.h"
41
42 gboolean scomm_service_reqeust_sim(unsigned int ch_id, Communicator *c, TcorePlugin *plugin, tapi_service_command_e cmd, gchar *data, void **outparam)
43 {
44         GSList *co_list = NULL;
45         CoreObject *co_sim = NULL;
46         UserRequest *ur = NULL;
47         struct tcore_user_info ui = { 0, 0, 0, NULL,0,0, NULL };
48         int ret = 0;
49
50         gchar *tmp = NULL;
51         int tmp_len = 0;
52         struct _tapi_service_object out_o = {0,};
53         struct _sipc_marshal_object *in_o;
54
55         co_list = tcore_plugin_get_core_objects_bytype(plugin, CORE_OBJECT_TYPE_SIM);
56         if (!co_list) {
57                 dbg("err-no sim core object list in current plugin");
58                 return FALSE;
59         }
60
61         co_sim = (CoreObject *)co_list->data;
62         if (!co_sim) {
63                 dbg("err-no sim core object in current plugin");
64                 return FALSE;
65         }
66
67         g_slist_free(co_list);
68
69         if (cmd == TAPI_SERVICE_SIM_GET_SIMINITINFO || cmd == TAPI_SERVICE_SIM_GET_TYPE
70                         || cmd == TAPI_SERVICE_SIM_GET_IMSI ) {
71                 /*synchronous data return case*/
72                 out_o.cmd = cmd;
73                 out_o.mo = sipc_util_marshal_object_create();
74         } else {
75                 /*asynchronous data return case*/
76                 ur = tcore_user_request_new(c, tcore_plugin_get_description(plugin)->name);
77                 if (!ur) {
78                         dbg("err - ur creation failed");
79                         return FALSE;
80                 }
81
82                 ui.channel_id = ch_id;
83                 ui.client_cmd = cmd;
84                 tcore_user_request_set_user_info(ur, &ui);
85
86                 in_o = sipc_util_marshal_object_deserializer(data);
87                 if(in_o){
88                         dbg("err - data deserializer failed");
89                         return FALSE;
90                 }
91         }
92
93         switch (cmd) {
94                 case TAPI_SERVICE_SIM_GET_SIMINITINFO : {
95                         enum tel_sim_status sim_status = SIM_STATUS_UNKNOWN;
96                         gboolean sim_changed = FALSE;
97                         sim_status = tcore_sim_get_status(co_sim);
98                         sipc_util_marshal_object_add_data(out_o.mo, "status", &sim_status,
99                                         SIPC_MARSHAL_DATA_INT_TYPE);
100                         sipc_util_marshal_object_add_data(out_o.mo, "new_sim", &sim_changed,
101                                         SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
102                         tmp = sipc_util_marshal_object_serializer(out_o.mo);
103                         tmp_len = strlen(tmp);
104                         *outparam = g_new0(char, tmp_len+1);
105                         memcpy(*outparam, tmp, tmp_len);
106                         g_free(tmp);
107                 }
108                         break;
109
110                 case TAPI_SERVICE_SIM_GET_TYPE : {
111                         enum tel_sim_type type = SIM_TYPE_UNKNOWN;
112                         type = tcore_sim_get_type(co_sim);
113                         sipc_util_marshal_object_add_data(out_o.mo, "type", &type,
114                                         SIPC_MARSHAL_DATA_INT_TYPE);
115                         tmp = sipc_util_marshal_object_serializer(out_o.mo);
116                         tmp_len = strlen(tmp);
117                         *outparam = g_new0(char, tmp_len+1);
118                         memcpy(*outparam, tmp, tmp_len);
119                         g_free(tmp);
120                 }
121                         break;
122
123                 case TAPI_SERVICE_SIM_GET_IMSI : {
124                         struct tel_sim_imsi *n_imsi = NULL;
125                         n_imsi = tcore_sim_get_imsi(co_sim);
126                         if (n_imsi != NULL) {
127                                 dbg("n_imsi->plmn[%s]", n_imsi->plmn);
128                                 sipc_util_marshal_object_add_data(out_o.mo, "mcc", n_imsi->plmn,
129                                                 SIPC_MARSHAL_DATA_STRING_TYPE);
130                                 sipc_util_marshal_object_add_data(out_o.mo, "mnc", n_imsi->plmn + 3,
131                                                 SIPC_MARSHAL_DATA_STRING_TYPE);
132                                 sipc_util_marshal_object_add_data(out_o.mo, "msin", n_imsi->msin,
133                                                 SIPC_MARSHAL_DATA_STRING_TYPE);
134                                 tmp = sipc_util_marshal_object_serializer(out_o.mo);
135                                 tmp_len = strlen(tmp);
136                                 *outparam = g_new0(char, tmp_len+1);
137                                 memcpy(*outparam, tmp, tmp_len);
138                                 g_free(tmp);
139                         }
140                 }
141                         break;
142
143                 case TAPI_SERVICE_SIM_GET_ECC :
144                         tcore_user_request_set_command(ur, TREQ_SIM_GET_ECC);
145                         break;
146
147                 case TAPI_SERVICE_SIM_GET_ICCID :
148                         tcore_user_request_set_command(ur, TREQ_SIM_GET_ICCID);
149                         break;
150
151                 case TAPI_SERVICE_SIM_GET_LANGUAGE :
152                         tcore_user_request_set_command(ur, TREQ_SIM_GET_LANGUAGE);
153                         break;
154
155                 case TAPI_SERVICE_SIM_SET_LANGUAGE : {
156                         struct treq_sim_set_language set_language = { 0, };
157                         enum tel_sim_language_type      g_language;
158                         g_language = sipc_util_marshal_object_get_int(in_o, "language");
159
160                         set_language.language = g_language;
161
162                         tcore_user_request_set_data(ur, sizeof(struct treq_sim_set_language), &set_language);
163                         tcore_user_request_set_command(ur, TREQ_SIM_SET_LANGUAGE);
164                 }
165                         break;
166
167                 case TAPI_SERVICE_SIM_GET_CF :
168                         tcore_user_request_set_command(ur, TREQ_SIM_GET_CALLFORWARDING);
169                         break;
170
171                 case TAPI_SERVICE_SIM_SET_CF :
172                         /*not defined value yet*/
173                         break;
174
175                 case TAPI_SERVICE_SIM_GET_MW :
176                         tcore_user_request_set_command(ur, TREQ_SIM_GET_MESSAGEWAITING);
177                         break;
178
179                 case TAPI_SERVICE_SIM_SET_MW :
180                         /*not defined value yet*/
181                         break;
182
183                 case TAPI_SERVICE_SIM_GET_MB :
184                         tcore_user_request_set_command(ur, TREQ_SIM_GET_MAILBOX);
185                         break;
186
187                 case TAPI_SERVICE_SIM_SET_MB :
188                         /*not defined value yet*/
189                         break;
190
191                 case TAPI_SERVICE_SIM_GET_CPHSINFO :
192                         tcore_user_request_set_command(ur, TREQ_SIM_GET_CPHS_INFO);
193                         break;
194
195                 case TAPI_SERVICE_SIM_AUTHENTICATION : {
196                         struct treq_sim_req_authentication req_auth = { 0, };
197                         enum tel_sim_auth_type g_auth_type;
198                         unsigned int g_autn_length;
199                         unsigned char *g_autn_data;
200                         unsigned int g_rand_length;
201                         unsigned char *g_rand_data;
202                         g_auth_type = sipc_util_marshal_object_get_int(in_o, "type");
203                         g_autn_data = sipc_util_marshal_object_get_string(in_o, "autn_data");
204                         g_autn_length = strlen(g_autn_data);
205                         g_rand_data = sipc_util_marshal_object_get_string(in_o, "rand_data");
206                         g_rand_length = strlen(g_rand_data);
207
208                         req_auth.auth_type = g_auth_type;
209                         req_auth.autn_length = g_autn_length;
210                         if(req_auth.autn_length)
211                                 memcpy(req_auth.autn_data, g_autn_data, req_auth.autn_length);
212                         req_auth.rand_length = g_rand_length;
213                         if(req_auth.rand_length)
214                                 memcpy(req_auth.rand_data, g_rand_data, req_auth.rand_length);
215
216                         tcore_user_request_set_data(ur, sizeof(struct treq_sim_req_authentication), &req_auth);
217                         tcore_user_request_set_command(ur, TREQ_SIM_REQ_AUTHENTICATION);
218                 }
219                         break;
220
221                 case TAPI_SERVICE_SIM_VERIFYSEC : {
222                         struct treq_sim_verify_pins verify_pins = { 0, };
223                         enum tel_sim_pin_type g_pin_type;
224                         unsigned int g_pin_length;
225                         unsigned char *g_pin;
226                         g_pin_type = sipc_util_marshal_object_get_int(in_o, "type");
227                         g_pin = sipc_util_marshal_object_get_string(in_o, "pw");
228                         g_pin_length = strlen(g_pin);
229
230                         verify_pins.pin_type = g_pin_type;
231                         verify_pins.pin_length = g_pin_length;
232                         memcpy(verify_pins.pin, g_pin, verify_pins.pin_length);
233
234                         tcore_user_request_set_data(ur, sizeof(struct treq_sim_verify_pins), &verify_pins);
235                         tcore_user_request_set_command(ur, TREQ_SIM_VERIFY_PINS);
236                 }
237                         break;
238
239                 case TAPI_SERVICE_SIM_VERIFYPUK : {
240                         struct treq_sim_verify_puks verify_puks = { 0, };
241                         enum tel_sim_pin_type g_puk_type;
242                         unsigned int g_puk_length;
243                         unsigned char *g_puk;
244                         unsigned int g_pin_length;
245                         unsigned char *g_pin;
246                         g_puk_type = sipc_util_marshal_object_get_int(in_o, "type");
247                         g_puk = sipc_util_marshal_object_get_string(in_o, "puk");
248                         g_puk_length = strlen(g_puk);
249                         g_pin = sipc_util_marshal_object_get_string(in_o, "pin");
250                         g_pin_length = strlen(g_pin);
251
252                         verify_puks.puk_type = g_puk_type;
253                         verify_puks.puk_length = g_puk_length;
254                         memcpy(verify_puks.puk, g_puk, verify_puks.puk_length);
255                         verify_puks.pin_length = g_pin_length;
256                         memcpy(verify_puks.pin, g_pin, verify_puks.pin_length);
257
258                         tcore_user_request_set_data(ur, sizeof(struct treq_sim_verify_puks), &verify_puks);
259                         tcore_user_request_set_command(ur, TREQ_SIM_VERIFY_PUKS);
260                 }
261                         break;
262
263                 case TAPI_SERVICE_SIM_CHANGEPIN : {
264                         struct treq_sim_change_pins change_pins = { 0, };
265                         enum tel_sim_pin_type g_type;
266                         unsigned int g_old_pw_length;
267                         unsigned char *g_old_pw;
268                         unsigned int g_new_pw_length;
269                         unsigned char *g_new_pw;
270                         g_type = sipc_util_marshal_object_get_int(in_o, "type");
271                         g_old_pw = sipc_util_marshal_object_get_string(in_o, "old_pw");
272                         g_old_pw_length = strlen(g_old_pw);
273                         g_new_pw = sipc_util_marshal_object_get_string(in_o, "new_pw");
274                         g_new_pw_length = strlen(g_new_pw);
275
276                         change_pins.type = g_type;
277                         change_pins.old_pin_length = g_old_pw_length;
278                         memcpy(change_pins.old_pin, g_old_pw, change_pins.old_pin_length);
279                         change_pins.new_pin_length = g_new_pw_length;
280                         memcpy(change_pins.new_pin, g_new_pw, change_pins.new_pin_length);
281
282                         tcore_user_request_set_data(ur, sizeof(struct treq_sim_change_pins), &change_pins);
283                         tcore_user_request_set_command(ur, TREQ_SIM_CHANGE_PINS);
284                 }
285                         break;
286
287                 case TAPI_SERVICE_SIM_DISABLE_FACILITY : {
288                         struct treq_sim_disable_facility dis_facility = { 0, };
289                         enum tel_sim_facility_type g_dis_type;
290                         unsigned int g_dis_pw_length;
291                         unsigned char *g_dis_pw;
292                         g_dis_type = sipc_util_marshal_object_get_int(in_o, "type");
293                         g_dis_pw = sipc_util_marshal_object_get_string(in_o, "pw");
294                         g_dis_pw_length = strlen(g_dis_pw);
295
296                         dis_facility.type = g_dis_type;
297                         dis_facility.password_length = g_dis_pw_length;
298                         memcpy(dis_facility.password, g_dis_pw, dis_facility.password_length);
299
300                         tcore_user_request_set_data(ur, sizeof(struct treq_sim_disable_facility), &dis_facility);
301                         tcore_user_request_set_command(ur, TREQ_SIM_DISABLE_FACILITY);
302                 }
303                         break;
304
305                 case TAPI_SERVICE_SIM_ENABLE_FACILITY : {
306                         struct treq_sim_enable_facility en_facility = { 0, };
307                         enum tel_sim_facility_type g_en_type;
308                         unsigned int g_en_pw_length;
309                         unsigned char *g_en_pw;
310                         g_en_type = sipc_util_marshal_object_get_int(in_o, "type");
311                         g_en_pw = sipc_util_marshal_object_get_string(in_o, "pw");
312                         g_en_pw_length = strlen(g_en_pw);
313
314                         en_facility.type = g_en_type;
315                         en_facility.password_length = g_en_pw_length;
316                         memcpy(en_facility.password, g_en_pw, en_facility.password_length);
317
318                         tcore_user_request_set_data(ur, sizeof(struct treq_sim_enable_facility), &en_facility);
319                         tcore_user_request_set_command(ur, TREQ_SIM_ENABLE_FACILITY);
320                 }
321                         break;
322
323                 case TAPI_SERVICE_SIM_GET_FACILITY : {
324                         struct treq_sim_get_facility_status facility = { 0, };
325                         enum tel_sim_facility_type g_facility_type;
326                         sipc_util_marshal_object_get_data(in_o, "type", (void **)&g_facility_type, TAPI_OBJECT_DATA_TYPE_INT);
327
328                         facility.type = g_facility_type;
329
330                         tcore_user_request_set_data(ur, sizeof(struct treq_sim_get_facility_status), &facility);
331                         tcore_user_request_set_command(ur, TREQ_SIM_GET_FACILITY_STATUS);
332                 }
333                         break;
334
335                 case TAPI_SERVICE_SIM_APDU : {
336                         struct treq_sim_transmit_apdu send_apdu ={ 0, };
337                         gint g_apdu_length;
338                         gchar *g_apdu;
339                         g_apdu = sipc_util_marshal_object_get_string(in_o, "apdu");
340                         g_apdu_length = strlen(g_apdu);
341
342                         send_apdu.apdu_length = (unsigned int)g_apdu_length;
343                         memcpy(send_apdu.apdu, g_apdu, send_apdu.apdu_length);
344
345                         tcore_user_request_set_data(ur, sizeof(struct treq_sim_transmit_apdu), &send_apdu);
346                         tcore_user_request_set_command(ur, TREQ_SIM_TRANSMIT_APDU);
347                 }
348                         break;
349
350                 case TAPI_SERVICE_SIM_ATR :
351                         tcore_user_request_set_command(ur, TREQ_SIM_GET_ATR);
352                         break;
353
354                 default :
355                         dbg("not handled command [%d] here",cmd);
356                         break;
357         }
358
359         if (cmd == TAPI_SERVICE_SIM_GET_SIMINITINFO || cmd == TAPI_SERVICE_SIM_GET_TYPE
360                         || cmd == TAPI_SERVICE_SIM_GET_IMSI ) {
361                 /*synchronous data return case*/
362
363         } else {
364                 /*asynchronous data return case*/
365                 ret = tcore_communicator_dispatch_request(c, ur);
366                 if (ret != TCORE_RETURN_SUCCESS) {
367                         return FALSE;
368                 }
369         }
370
371         return TRUE;
372 }
373
374 gboolean scomm_service_response_sim(Communicator *comm, UserRequest *ur, enum tcore_response_command command,
375                 unsigned int data_len, const void *data)
376 {
377         const struct tresp_sim_verify_pins *resp_verify_pins = data;
378         const struct tresp_sim_verify_puks *resp_verify_puks = data;
379         const struct tresp_sim_change_pins *resp_change_pins = data;
380         const struct tresp_sim_get_facility_status *resp_get_facility = data;
381         const struct tresp_sim_disable_facility *resp_dis_facility = data;
382         const struct tresp_sim_enable_facility *resp_en_facility = data;
383         const struct tresp_sim_transmit_apdu *resp_apdu = data;
384         const struct tresp_sim_get_atr *resp_get_atr = data;
385         const struct tresp_sim_read *resp_read = data;
386         const struct tresp_sim_req_authentication *resp_auth = data;
387         const struct tresp_sim_set_language *resp_set_language = data;
388         int count =0;
389         int ret = 0, i;
390         gchar *out_d= NULL, *serial_d = NULL;
391         gchar *entry_key = NULL;
392         struct custom_data *ctx = NULL;
393         const struct tcore_user_info *ui;
394         sipc_server_t *s = NULL;
395         struct _tapi_header hdr;
396         struct _sipc_marshal_object* out_o = NULL;
397         struct _sipc_marshal_object* entry_o = NULL;
398
399         memset(&hdr, 0, sizeof(struct _tapi_header));
400
401         ctx = tcore_communicator_ref_user_data(comm);
402         if (!ctx) {
403                 dbg("user_data is NULL");
404                 return FALSE;
405         }
406
407         ui = tcore_user_request_ref_user_info(ur);
408         s = ctx->sk_server;
409
410         dbg("application channel id(%d), Command = [0x%x], data_len = %d", ui->channel_id, command, data_len);
411         hdr.cmd = (tapi_service_command_e)ui->client_cmd;
412
413         out_o = sipc_util_marshal_object_create();
414
415         switch (command) {
416                 case TRESP_SIM_VERIFY_PINS:
417                         dbg("resp comm - TRESP_SIM_VERIFY_PINS");
418                         sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_verify_pins->result, SIPC_MARSHAL_DATA_INT_TYPE);
419                         sipc_util_marshal_object_add_data(out_o, "type", (void*)&resp_verify_pins->pin_type, SIPC_MARSHAL_DATA_INT_TYPE);
420                         sipc_util_marshal_object_add_data(out_o, "remain_count", (void*)&resp_verify_pins->retry_count, SIPC_MARSHAL_DATA_INT_TYPE);
421                         break;
422
423                 case TRESP_SIM_VERIFY_PUKS:
424                         dbg("resp comm - TRESP_SIM_VERIFY_PUKS");
425                         sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_verify_puks->result, SIPC_MARSHAL_DATA_INT_TYPE);
426                         sipc_util_marshal_object_add_data(out_o, "type", (void*)&resp_verify_puks->pin_type, SIPC_MARSHAL_DATA_INT_TYPE);
427                         sipc_util_marshal_object_add_data(out_o, "remain_count", (void*)&resp_verify_puks->retry_count, SIPC_MARSHAL_DATA_INT_TYPE);
428                         break;
429
430                 case TRESP_SIM_CHANGE_PINS:
431                         dbg("resp comm - TRESP_SIM_CHANGE_PINS");
432                         sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_change_pins->result, SIPC_MARSHAL_DATA_INT_TYPE);
433                         sipc_util_marshal_object_add_data(out_o, "type", (void*)&resp_change_pins->pin_type, SIPC_MARSHAL_DATA_INT_TYPE);
434                         sipc_util_marshal_object_add_data(out_o, "remain_count", (void*)&resp_change_pins->retry_count, SIPC_MARSHAL_DATA_INT_TYPE);
435                         break;
436
437                 case TRESP_SIM_GET_FACILITY_STATUS:
438                         dbg("resp comm - TRESP_SIM_GET_FACILITY_STATUS");
439                         sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_get_facility->result, SIPC_MARSHAL_DATA_INT_TYPE);
440                         sipc_util_marshal_object_add_data(out_o, "type", (void*)&resp_get_facility->type, SIPC_MARSHAL_DATA_INT_TYPE);
441                         sipc_util_marshal_object_add_data(out_o, "enabled", (void*)&resp_get_facility->b_enable, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
442                         break;
443
444                 case TRESP_SIM_DISABLE_FACILITY:
445                         dbg("resp comm - TRESP_SIM_DISABLE_FACILITY");
446                         sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_dis_facility->result, SIPC_MARSHAL_DATA_INT_TYPE);
447                         sipc_util_marshal_object_add_data(out_o, "type", (void*)&resp_dis_facility->type, SIPC_MARSHAL_DATA_INT_TYPE);
448                         sipc_util_marshal_object_add_data(out_o, "remain_count", (void*)&resp_dis_facility->retry_count, SIPC_MARSHAL_DATA_INT_TYPE);
449                         break;
450
451                 case TRESP_SIM_ENABLE_FACILITY:
452                         dbg("resp comm - TRESP_SIM_ENABLE_FACILITY");
453                         sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_en_facility->result, SIPC_MARSHAL_DATA_INT_TYPE);
454                         sipc_util_marshal_object_add_data(out_o, "type", (void*)&resp_en_facility->type, SIPC_MARSHAL_DATA_INT_TYPE);
455                         sipc_util_marshal_object_add_data(out_o, "remain_count", (void*)&resp_en_facility->retry_count, SIPC_MARSHAL_DATA_INT_TYPE);
456                         break;
457
458                 case TRESP_SIM_TRANSMIT_APDU:
459                         dbg("resp comm - TRESP_SIM_TRANSMIT_APDU");
460                         sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_apdu->result, SIPC_MARSHAL_DATA_INT_TYPE);
461                         sipc_util_marshal_object_add_data(out_o, "apdu", (void*)&resp_apdu->apdu_resp, SIPC_MARSHAL_DATA_STRING_TYPE);
462                         break;
463
464                 case TRESP_SIM_GET_ATR:
465                         dbg("resp comm - TRESP_SIM_GET_ATR");
466                         sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_get_atr->result, SIPC_MARSHAL_DATA_INT_TYPE);
467                         sipc_util_marshal_object_add_data(out_o, "atr", (void*)&resp_get_atr->atr, SIPC_MARSHAL_DATA_STRING_TYPE);
468                         break;
469
470                 case TRESP_SIM_REQ_AUTHENTICATION:
471                         dbg("resp comm - TRESP_SIM_REQ_AUTHENTICATION");
472                         sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_auth->auth_result, SIPC_MARSHAL_DATA_INT_TYPE);
473                         sipc_util_marshal_object_add_data(out_o, "type", (void*)&resp_auth->auth_type, SIPC_MARSHAL_DATA_STRING_TYPE);
474                         if(resp_auth->authentication_key_length)
475                                 sipc_util_marshal_object_add_data(out_o, "authentication_key", (void*)&resp_auth->authentication_key, SIPC_MARSHAL_DATA_STRING_TYPE);
476                         if(resp_auth->cipher_length)
477                                 sipc_util_marshal_object_add_data(out_o, "cipher_data", (void*)&resp_auth->cipher_data, SIPC_MARSHAL_DATA_STRING_TYPE);
478                         if(resp_auth->integrity_length)
479                                 sipc_util_marshal_object_add_data(out_o, "integrity_data", (void*)&resp_auth->integrity_data, SIPC_MARSHAL_DATA_STRING_TYPE);
480                         if(resp_auth->resp_length)
481                                 sipc_util_marshal_object_add_data(out_o, "resp_data", (void*)&resp_auth->resp_data, SIPC_MARSHAL_DATA_STRING_TYPE);
482                         break;
483
484                 case TRESP_SIM_SET_LANGUAGE:
485                         dbg("resp comm - TRESP_SIM_SET_LANGUAGE");
486                         sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_set_language->result, SIPC_MARSHAL_DATA_INT_TYPE);
487                         break;
488
489                 case TRESP_SIM_GET_ECC:
490                         dbg("resp comm - TRESP_SIM_GET_ECC");
491                         sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_read->result, SIPC_MARSHAL_DATA_INT_TYPE);
492                         sipc_util_marshal_object_add_data(out_o, "count", (void*)&resp_read->data.ecc.ecc_count, SIPC_MARSHAL_DATA_INT_TYPE);
493                         entry_o = sipc_util_marshal_object_create();
494                         for(i=0;i < resp_read->data.ecc.ecc_count; i++){
495                                 gchar *entry_key = NULL;
496                                 sipc_util_marshal_object_add_data(entry_o, "name", (void*)&resp_read->data.ecc.ecc[i].ecc_string, SIPC_MARSHAL_DATA_STRING_TYPE);
497                                 sipc_util_marshal_object_add_data(entry_o, "number", (void*)&resp_read->data.ecc.ecc[i].ecc_num, SIPC_MARSHAL_DATA_STRING_TYPE);
498                                 sipc_util_marshal_object_add_data(entry_o, "category", (void*)&resp_read->data.ecc.ecc[i].ecc_category, SIPC_MARSHAL_DATA_INT_TYPE);
499                                 entry_key = g_strdup_printf("%d", i);
500                                 sipc_util_marshal_object_add_data(out_o, entry_key, entry_o, SIPC_MARSHAL_DATA_OBJECT_TYPE);
501                         }
502                         break;
503
504                 case TRESP_SIM_GET_LANGUAGE:
505                         dbg("resp comm - TRESP_SIM_GET_LANGUAGE");
506                         sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_read->result, SIPC_MARSHAL_DATA_INT_TYPE);
507                         sipc_util_marshal_object_add_data(out_o, "language", (void*)&resp_read->data.language.language[0] , SIPC_MARSHAL_DATA_INT_TYPE);
508                         break;
509
510                 case TRESP_SIM_GET_ICCID:
511                         dbg("resp comm - TRESP_SIM_GET_ICCID");
512                         sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_read->result, SIPC_MARSHAL_DATA_INT_TYPE);
513                         sipc_util_marshal_object_add_data(out_o, "iccid", (void*)&resp_read->data.iccid.iccid , SIPC_MARSHAL_DATA_STRING_TYPE);
514                         break;
515
516                 case TRESP_SIM_GET_MAILBOX:
517                         dbg("resp comm - TRESP_SIM_GET_MAILBOX");
518                         sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_read->result, SIPC_MARSHAL_DATA_INT_TYPE);
519                         entry_o = sipc_util_marshal_object_create();
520                         if(resp_read->data.mailbox.voice1.DiallingnumLength){
521                                 count ++;
522                                 sipc_util_marshal_object_add_data(entry_o, "type", "voice1", SIPC_MARSHAL_DATA_STRING_TYPE);
523                                 sipc_util_marshal_object_add_data(entry_o, "name", (void*)&resp_read->data.mailbox.voice1.AlphaId, SIPC_MARSHAL_DATA_STRING_TYPE);
524                                 sipc_util_marshal_object_add_data(entry_o, "number", (void*)&resp_read->data.mailbox.voice1.DiallingNum , SIPC_MARSHAL_DATA_STRING_TYPE);
525                                 sipc_util_marshal_object_add_data(entry_o, "ton", (void*)&resp_read->data.mailbox.voice1.TypeOfNumber , SIPC_MARSHAL_DATA_INT_TYPE);
526                                 sipc_util_marshal_object_add_data(entry_o, "npi", (void*)&resp_read->data.mailbox.voice1.NumberingPlanIdent , SIPC_MARSHAL_DATA_INT_TYPE);
527                                 entry_key = g_strdup_printf("%d", count);
528                                 sipc_util_marshal_object_add_data(out_o, entry_key, entry_o, SIPC_MARSHAL_DATA_OBJECT_TYPE);
529                         }
530
531                         if(resp_read->data.mailbox.voice2.DiallingnumLength){
532                                 count ++;
533                                 sipc_util_marshal_object_add_data(entry_o, "type", "voice2", SIPC_MARSHAL_DATA_STRING_TYPE);
534                                 sipc_util_marshal_object_add_data(entry_o, "name", (void*)&resp_read->data.mailbox.voice2.AlphaId, SIPC_MARSHAL_DATA_STRING_TYPE);
535                                 sipc_util_marshal_object_add_data(entry_o, "number", (void*)&resp_read->data.mailbox.voice2.DiallingNum , SIPC_MARSHAL_DATA_STRING_TYPE);
536                                 sipc_util_marshal_object_add_data(entry_o, "ton", (void*)&resp_read->data.mailbox.voice2.TypeOfNumber , SIPC_MARSHAL_DATA_INT_TYPE);
537                                 sipc_util_marshal_object_add_data(entry_o, "npi", (void*)&resp_read->data.mailbox.voice2.NumberingPlanIdent , SIPC_MARSHAL_DATA_INT_TYPE);
538                                 entry_key = g_strdup_printf("%d", count);
539                                 sipc_util_marshal_object_add_data(out_o, entry_key, entry_o, SIPC_MARSHAL_DATA_OBJECT_TYPE);
540                         }
541
542                         if(resp_read->data.mailbox.fax.DiallingnumLength){
543                                 count ++;
544                                 sipc_util_marshal_object_add_data(entry_o, "type", "fax", SIPC_MARSHAL_DATA_STRING_TYPE);
545                                 sipc_util_marshal_object_add_data(entry_o, "name", (void*)&resp_read->data.mailbox.fax.AlphaId, SIPC_MARSHAL_DATA_STRING_TYPE);
546                                 sipc_util_marshal_object_add_data(entry_o, "number", (void*)&resp_read->data.mailbox.fax.DiallingNum , SIPC_MARSHAL_DATA_STRING_TYPE);
547                                 sipc_util_marshal_object_add_data(entry_o, "ton", (void*)&resp_read->data.mailbox.fax.TypeOfNumber , SIPC_MARSHAL_DATA_INT_TYPE);
548                                 sipc_util_marshal_object_add_data(entry_o, "npi", (void*)&resp_read->data.mailbox.fax.NumberingPlanIdent , SIPC_MARSHAL_DATA_INT_TYPE);
549                                 entry_key = g_strdup_printf("%d", count);
550                                 sipc_util_marshal_object_add_data(out_o, entry_key, entry_o, SIPC_MARSHAL_DATA_OBJECT_TYPE);
551                         }
552
553                         if(resp_read->data.mailbox.video.DiallingnumLength){
554                                 count ++;
555                                 sipc_util_marshal_object_add_data(entry_o, "type", "video", SIPC_MARSHAL_DATA_STRING_TYPE);
556                                 sipc_util_marshal_object_add_data(entry_o, "name", (void*)&resp_read->data.mailbox.video.AlphaId, SIPC_MARSHAL_DATA_STRING_TYPE);
557                                 sipc_util_marshal_object_add_data(entry_o, "number", (void*)&resp_read->data.mailbox.video.DiallingNum , SIPC_MARSHAL_DATA_STRING_TYPE);
558                                 sipc_util_marshal_object_add_data(entry_o, "ton", (void*)&resp_read->data.mailbox.video.TypeOfNumber , SIPC_MARSHAL_DATA_INT_TYPE);
559                                 sipc_util_marshal_object_add_data(entry_o, "npi", (void*)&resp_read->data.mailbox.video.NumberingPlanIdent , SIPC_MARSHAL_DATA_INT_TYPE);
560                                 entry_key = g_strdup_printf("%d", count);
561                                 sipc_util_marshal_object_add_data(out_o, entry_key, entry_o, SIPC_MARSHAL_DATA_OBJECT_TYPE);
562                         }
563                         break;
564
565                 case TRESP_SIM_GET_CALLFORWARDING:
566                         dbg("resp comm - TRESP_SIM_GET_CALLFORWARDING");
567                         sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_read->result, SIPC_MARSHAL_DATA_INT_TYPE);
568                         sipc_util_marshal_object_add_data(out_o, "line1_status", (void*)&resp_read->data.cf.voice1, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
569                         sipc_util_marshal_object_add_data(out_o, "line2_status", (void*)&resp_read->data.cf.voice2, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
570                         break;
571
572                 case TRESP_SIM_GET_MESSAGEWAITING:
573                         dbg("resp comm - TRESP_SIM_GET_MESSAGEWAITING");
574                         sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_read->result, SIPC_MARSHAL_DATA_INT_TYPE);
575                         if (resp_read->data.mw.b_cphs) {
576                                 sipc_util_marshal_object_add_data(out_o, "line1_count", (void*)&resp_read->data.mw.mw_data_u.cphs_mw.b_voice1, SIPC_MARSHAL_DATA_INT_TYPE);
577                                 sipc_util_marshal_object_add_data(out_o, "line2_count", (void*)&resp_read->data.mw.mw_data_u.cphs_mw.b_voice2, SIPC_MARSHAL_DATA_INT_TYPE);
578                                 sipc_util_marshal_object_add_data(out_o, "fax_count", (void*)&resp_read->data.mw.mw_data_u.cphs_mw.b_fax, SIPC_MARSHAL_DATA_INT_TYPE);
579                                 sipc_util_marshal_object_add_data(out_o, "video_count", (void*)&resp_read->data.mw.mw_data_u.cphs_mw.b_data, SIPC_MARSHAL_DATA_INT_TYPE);
580                         } else {
581                                 sipc_util_marshal_object_add_data(out_o, "line1_count", (void*)&resp_read->data.mw.mw_data_u.mw.voice_count, SIPC_MARSHAL_DATA_INT_TYPE);
582 /*                              sipc_util_marshal_object_add_data(out_o, "line2_count", (void*)&resp_read->result, SIPC_MARSHAL_DATA_INT_TYPE);*/
583                                 sipc_util_marshal_object_add_data(out_o, "fax_count", (void*)&resp_read->data.mw.mw_data_u.mw.fax_count, SIPC_MARSHAL_DATA_INT_TYPE);
584                                 sipc_util_marshal_object_add_data(out_o, "video_count", (void*)&resp_read->data.mw.mw_data_u.mw.video_count, SIPC_MARSHAL_DATA_INT_TYPE);
585                         }
586                         break;
587
588                 case TRESP_SIM_GET_CPHS_INFO:
589                         dbg("resp comm - TRESP_SIM_GET_CPHS_INFO");
590                         sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_read->result, SIPC_MARSHAL_DATA_INT_TYPE);
591                         break;
592
593                 case TRESP_SIM_GET_MSISDN:
594                         dbg("resp comm - TRESP_SIM_GET_MSISDN");
595                         sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_read->result, SIPC_MARSHAL_DATA_INT_TYPE);
596                         sipc_util_marshal_object_add_data(out_o, "count", (void*)&resp_read->data.msisdn_list.count, SIPC_MARSHAL_DATA_INT_TYPE);
597                         entry_o = sipc_util_marshal_object_create();
598                         for(i=0;i < resp_read->data.msisdn_list.count; i++){
599                                 gchar *entry_key = NULL;
600                                 sipc_util_marshal_object_add_data(entry_o, "name", (void*)&resp_read->data.msisdn_list.msisdn[i].name, SIPC_MARSHAL_DATA_STRING_TYPE);
601                                 sipc_util_marshal_object_add_data(entry_o, "number", (void*)&resp_read->data.msisdn_list.msisdn[i].num, SIPC_MARSHAL_DATA_STRING_TYPE);
602                                 entry_key = g_strdup_printf("%d", i);
603                                 sipc_util_marshal_object_add_data(out_o, entry_key, entry_o, SIPC_MARSHAL_DATA_OBJECT_TYPE);
604                         }
605                         break;
606
607                 case TRESP_SIM_GET_OPLMNWACT:
608                         dbg("resp comm - TRESP_SIM_GET_OPLMNWACT");
609                         sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_read->result, SIPC_MARSHAL_DATA_INT_TYPE);
610                         sipc_util_marshal_object_add_data(out_o, "count", (void*)&resp_read->data.opwa.opwa_count, SIPC_MARSHAL_DATA_INT_TYPE);
611                         entry_o = sipc_util_marshal_object_create();
612                         for(i=0;i < resp_read->data.opwa.opwa_count; i++){
613                                 gchar *entry_key = NULL;
614                                 sipc_util_marshal_object_add_data(entry_o, "plmn", (void*)&resp_read->data.opwa.opwa[i].plmn, SIPC_MARSHAL_DATA_STRING_TYPE);
615                                 sipc_util_marshal_object_add_data(entry_o, "b_umts", (void*)&resp_read->data.opwa.opwa[i].b_umts, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
616                                 sipc_util_marshal_object_add_data(entry_o, "b_gsm", (void*)&resp_read->data.opwa.opwa[i].b_gsm, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
617                                 entry_key = g_strdup_printf("%d", i);
618                                 sipc_util_marshal_object_add_data(out_o, entry_key, entry_o, SIPC_MARSHAL_DATA_OBJECT_TYPE);
619                         }
620                         break;
621
622                 default:
623                         dbg("not handled command [%d] here",command);
624                         break;
625         }
626
627         if(out_o){
628                 serial_d = sipc_util_marshal_object_serializer(out_o);
629                 hdr.data_len = strlen(serial_d);
630                 sipc_util_marshal_object_destory(out_o);
631         }
632
633         out_d = g_new0(char, sizeof(struct _tapi_header)+hdr.data_len);
634         memcpy(out_d, &hdr, sizeof(struct _tapi_header));
635         if(serial_d){
636                 memcpy(out_d+sizeof(struct _tapi_header), serial_d, hdr.data_len);
637                 g_free(serial_d);
638         }
639
640         ret = sipc_server_send(s, ui->channel_id, out_d, sizeof(struct _tapi_header)+hdr.data_len, SIPC_SEND_DATA_ASYNC);
641         g_free(out_d);
642
643         if(ret < 0){
644                 return FALSE;
645         }
646
647         return TRUE;
648 }
649
650
651 gboolean scomm_service_notification_sim(Communicator *comm, CoreObject *source, enum tcore_notification_command command,
652                 unsigned int data_len, const void *data)
653 {
654         const struct tnoti_sim_status *n_sim_status = data;
655         int ret = 0;
656         gchar *out_d = NULL, *serial_d = NULL;
657
658         struct custom_data *ctx = NULL;
659         sipc_server_t *s = NULL;
660
661         struct _tapi_header hdr;
662         struct _sipc_marshal_object* out_o = NULL;
663
664         memset(&hdr, 0, sizeof(struct _tapi_header));
665
666         ctx = tcore_communicator_ref_user_data(comm);
667         if (!ctx) {
668                 dbg("user_data is NULL");
669                 return FALSE;
670         }
671
672         s = ctx->sk_server;
673         dbg("notification !!! (command = 0x%x, data_len = %d)", command, data_len);
674
675         out_o = sipc_util_marshal_object_create();
676
677         switch (command) {
678                 case TNOTI_SIM_STATUS :
679                         dbg("notified sim_status[%d]", n_sim_status->sim_status);
680                         sipc_util_marshal_object_add_data(out_o, "status", (void*)&n_sim_status->sim_status, SIPC_MARSHAL_DATA_INT_TYPE);
681                         sipc_util_marshal_object_add_data(out_o, "new_sim", (void*)&n_sim_status->b_changed, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
682                         break;
683
684                 default :
685                         dbg("not handled command [%d] here",command);
686                         break;
687         }
688
689         if(out_o){
690                 serial_d = sipc_util_marshal_object_serializer(out_o);
691                 hdr.data_len = strlen(serial_d);
692                 sipc_util_marshal_object_destory(out_o);
693         }
694
695         out_d = g_new0(char, sizeof(struct _tapi_header)+hdr.data_len);
696         memcpy(out_d, &hdr, sizeof(struct _tapi_header));
697         if(serial_d){
698                 memcpy(out_d+sizeof(struct _tapi_header), serial_d, hdr.data_len);
699                 g_free(serial_d);
700         }
701
702         ret = sipc_server_broadcast(s, out_d, sizeof(struct _tapi_header)+hdr.data_len);
703         g_free(out_d);
704
705         if(ret < 0){
706                 return FALSE;
707         }
708         return TRUE;
709 }