46c064846240b0b06db8545fcf6e2e64abc63538
[framework/telephony/tel-plugin-socket_communicator.git] / plugin / src / socket_network.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_network.h>
37
38 #include "sipc.h"
39 #include "tapi_common.h"
40 #include "module_req.h"
41
42 static void _request_fail(UserRequest *ur, int cmd, int resp_len, void *resp)
43 {
44         tcore_user_request_send_response(ur, cmd, resp_len, resp);
45         tcore_user_request_free(ur);
46 }
47
48 gboolean scomm_service_request_network(unsigned int ch_id, Communicator *c, TcorePlugin *plugin,
49                 tapi_service_command_e cmd, gchar *data, void **outparam)
50 {
51         int ret = 0;
52         struct _sipc_marshal_object *out_obj;
53         struct _sipc_marshal_object *in_obj;
54         gboolean result = TRUE;
55         UserRequest *ur = NULL;
56         struct tcore_user_info ui = { 0, 0, 0, NULL, 0, 0, NULL };
57
58         in_obj = sipc_util_marshal_object_deserializer(data);
59         if (!in_obj) {
60                 dbg("in_obj is NULL");
61                 result = FALSE;
62                 goto RETURN;
63         }
64
65         ur = tcore_user_request_new(c, tcore_plugin_get_description(plugin)->name);
66         if (!ur) {
67                 dbg("ur is NULL");
68                 result = FALSE;
69                 goto RETURN;
70         }
71
72         ui.channel_id = ch_id;
73         ui.client_cmd = cmd;
74         tcore_user_request_set_user_info(ur, &ui);
75
76         switch (cmd) {
77                 case TAPI_SERVICE_NETWORK_SEARCH:
78                         tcore_user_request_set_data(ur, 0, NULL);
79                         tcore_user_request_set_command(ur, TREQ_NETWORK_SEARCH);
80                         break;
81
82                 case TAPI_SERVICE_NETWORK_SET_PLMN_SELECTION_MODE: {
83                         struct treq_network_set_plmn_selection_mode data_plmn_select;
84                         struct tresp_network_set_plmn_selection_mode resp;
85                         gchar *mode = NULL;
86                         gchar *plmn = NULL;
87
88                         mode = sipc_util_marshal_object_get_string(in_obj, "mode");
89                         if (!mode) {
90                                 resp.result = TCORE_RETURN_EINVAL;
91                                 _request_fail(ur, TRESP_NETWORK_SET_PLMN_SELECTION_MODE, sizeof(struct tresp_network_set_plmn_selection_mode), &resp);
92                                 result = FALSE;
93                                 break;
94                         }
95
96                         plmn = sipc_util_marshal_object_get_string(in_obj, "plmn");
97
98                         memset(&data_plmn_select, 0, sizeof(struct treq_network_set_plmn_selection_mode));
99                         if (!g_strcmp0(mode, "automatic")) {
100                                 data_plmn_select.mode = NETWORK_SELECT_MODE_GSM_AUTOMATIC;
101                         }
102                         else if (!g_strcmp0(mode, "manual")) {
103                                 data_plmn_select.mode = NETWORK_SELECT_MODE_GSM_MANUAL;
104                                 snprintf(data_plmn_select.plmn, 6, "%s", plmn);
105                                 if (strlen(data_plmn_select.plmn) <= 5)
106                                         data_plmn_select.plmn[5] = '#';
107                         }
108                         else {
109                                 /* fail */
110                                 g_free(mode);
111                                 g_free(plmn);
112
113                                 resp.result = TCORE_RETURN_EINVAL;
114                                 _request_fail(ur, TRESP_NETWORK_SET_PLMN_SELECTION_MODE, sizeof(struct tresp_network_set_plmn_selection_mode), &resp);
115                                 result = FALSE;
116                                 break;
117                         }
118
119                         g_free(mode);
120                         g_free(plmn);
121
122                         tcore_user_request_set_data(ur, sizeof(struct treq_network_set_plmn_selection_mode), &data_plmn_select);
123                         tcore_user_request_set_command(ur, TREQ_NETWORK_SET_PLMN_SELECTION_MODE);
124                 }
125                         break;
126
127                 case TAPI_SERVICE_NETWORK_GET_PLMN_SELECTION_MODE:
128                         tcore_user_request_set_data(ur, 0, NULL);
129                         tcore_user_request_set_command(ur, TREQ_NETWORK_GET_PLMN_SELECTION_MODE);
130                         break;
131
132                 case TAPI_SERVICE_NETWORK_SET_SERVICE_DOMAIN: {
133                         struct treq_network_set_service_domain data_service_domain;
134                         struct tresp_network_set_service_domain resp;
135                         gchar *domain = NULL;
136
137                         domain = sipc_util_marshal_object_get_string(in_obj, "domain");
138                         if (!domain) {
139                                 resp.result = TCORE_RETURN_EINVAL;
140                                 _request_fail(ur, TRESP_NETWORK_SET_SERVICE_DOMAIN, sizeof(struct tresp_network_set_service_domain), &resp);
141                                 result = FALSE;
142                                 break;
143                         }
144
145                         if (!g_strcmp0(domain, "circuit")) {
146                                 data_service_domain.domain = NETWORK_SERVICE_DOMAIN_CS;
147                         }
148                         else if (!g_strcmp0(domain, "packet")) {
149                                 data_service_domain.domain = NETWORK_SERVICE_DOMAIN_PS;
150                         }
151                         else if (!g_strcmp0(domain, "combined")) {
152                                 data_service_domain.domain = NETWORK_SERVICE_DOMAIN_COMBINED;
153                         }
154                         else {
155                                 /* fail */
156                                 g_free(domain);
157                                 result = FALSE;
158                                 resp.result = TCORE_RETURN_EINVAL;
159                                 _request_fail(ur, TRESP_NETWORK_SET_SERVICE_DOMAIN, sizeof(struct tresp_network_set_service_domain), &resp);
160                                 break;
161                         }
162
163                         g_free(domain);
164
165                         tcore_user_request_set_data(ur, sizeof(struct treq_network_set_service_domain), &data_service_domain);
166                         tcore_user_request_set_command(ur, TREQ_NETWORK_SET_SERVICE_DOMAIN);
167                 }
168                         break;
169
170                 case TAPI_SERVICE_NETWORK_GET_SERVICE_DOMAIN:
171                         tcore_user_request_set_data(ur, 0, NULL);
172                         tcore_user_request_set_command(ur, TREQ_NETWORK_GET_SERVICE_DOMAIN);
173                         break;
174
175                 case TAPI_SERVICE_NETWORK_SET_BAND :{
176                         struct treq_network_set_band data_band;
177                         struct tresp_network_set_band resp;
178                         gchar *mode = NULL;
179                         gint band;
180
181                         mode = sipc_util_marshal_object_get_string(in_obj, "mode");
182                         if (!mode) {
183                                 result = FALSE;
184                                 resp.result = TCORE_RETURN_EINVAL;
185                                 _request_fail(ur, TRESP_NETWORK_SET_BAND, sizeof(struct tresp_network_set_band), &resp);
186                                 break;
187                         }
188
189                         band = sipc_util_marshal_object_get_int(in_obj, "band");
190
191                         if (!g_strcmp0(mode, "only")) {
192                                 data_band.mode = NETWORK_BAND_MODE_ONLY;
193                         }
194                         else if (!g_strcmp0(mode, "preferred")) {
195                                 data_band.mode = NETWORK_BAND_MODE_PREFERRED;
196                         }
197                         else {
198                                 /* fail */
199                                 g_free(mode);
200                                 result = FALSE;
201                                 resp.result = TCORE_RETURN_EINVAL;
202                                 _request_fail(ur, TRESP_NETWORK_SET_BAND, sizeof(struct tresp_network_set_band), &resp);
203                                 break;
204                         }
205
206                         data_band.band = band;
207
208                         g_free(mode);
209
210                         tcore_user_request_set_data(ur, sizeof(struct treq_network_set_band), &data_band);
211                         tcore_user_request_set_command(ur, TREQ_NETWORK_SET_BAND);
212                 }
213                         break;
214
215                 case TAPI_SERVICE_NETWORK_GET_BAND:
216                         tcore_user_request_set_data(ur, 0, NULL);
217                         tcore_user_request_set_command(ur, TREQ_NETWORK_GET_BAND);
218                         break;
219
220                 case TAPI_SERVICE_NETWORK_SET_PREFERRED_PLMN :{
221                         struct treq_network_set_preferred_plmn data_preferred_plmn;
222                         struct tresp_network_set_preferred_plmn resp;
223                         gchar *mode = NULL;
224                         gchar *plmn = NULL;
225                         gint act;
226                         gint ef_index;
227
228                         mode = sipc_util_marshal_object_get_string(in_obj, "mode");
229                         if (!mode) {
230                                 result = FALSE;
231                                 resp.result = TCORE_RETURN_EINVAL;
232                                 _request_fail(ur, TRESP_NETWORK_SET_PREFERRED_PLMN, sizeof(struct tresp_network_set_preferred_plmn), &resp);
233                                 break;
234                         }
235
236                         plmn = sipc_util_marshal_object_get_string(in_obj, "plmn");
237                         if (!plmn) {
238                                 g_free(mode);
239                                 result = FALSE;
240                                 resp.result = TCORE_RETURN_EINVAL;
241                                 _request_fail(ur, TRESP_NETWORK_SET_PREFERRED_PLMN, sizeof(struct tresp_network_set_preferred_plmn), &resp);
242                                 break;
243                         }
244
245                         act = sipc_util_marshal_object_get_int(in_obj, "act");
246                         ef_index = sipc_util_marshal_object_get_int(in_obj, "ef_index");
247
248                         if (!g_strcmp0(mode, "add")) {
249                                 data_preferred_plmn.operation = NETWORK_PREF_PLMN_ADD;
250
251                         }
252                         else if (!g_strcmp0(mode, "edit")) {
253                                 data_preferred_plmn.operation = NETWORK_PREF_PLMN_EDIT;
254
255                         }
256                         else if (!g_strcmp0(mode, "delete")) {
257                                 data_preferred_plmn.operation = NETWORK_PREF_PLMN_DELETE;
258                         }
259                         else {
260                                 /* fail */
261                                 g_free(mode);
262                                 g_free(plmn);
263                                 result = FALSE;
264                                 resp.result = TCORE_RETURN_EINVAL;
265                                 _request_fail(ur, TRESP_NETWORK_SET_PREFERRED_PLMN, sizeof(struct tresp_network_set_preferred_plmn), &resp);
266                                 break;
267                         }
268
269                         snprintf(data_preferred_plmn.plmn, 6, "%s", plmn);
270                         if (strlen(data_preferred_plmn.plmn) <= 5)
271                                 data_preferred_plmn.plmn[5] = '#';
272
273                         data_preferred_plmn.act = act;
274                         data_preferred_plmn.ef_index = ef_index;
275
276                         g_free(mode);
277                         g_free(plmn);
278
279                         tcore_user_request_set_data(ur, sizeof(struct treq_network_set_preferred_plmn), &data_preferred_plmn);
280                         tcore_user_request_set_command(ur, TREQ_NETWORK_SET_PREFERRED_PLMN);
281                 }
282                         break;
283
284                 case TAPI_SERVICE_NETWORK_GET_PREFERRED_PLMN:
285                         tcore_user_request_set_data(ur, 0, NULL);
286                         tcore_user_request_set_command(ur, TREQ_NETWORK_GET_PREFERRED_PLMN);
287                         break;
288
289                 case TAPI_SERVICE_NETWORK_SET_ORDER :{
290                         struct treq_network_set_order data_order;
291                         struct tresp_network_set_order resp;
292                         gchar *order = NULL;
293
294                         order = sipc_util_marshal_object_get_string(in_obj, "order");
295                         if (!order) {
296                                 result = FALSE;
297                                 resp.result = TCORE_RETURN_EINVAL;
298                                 _request_fail(ur, TRESP_NETWORK_SET_ORDER, sizeof(struct tresp_network_set_order), &resp);
299                                 break;
300                         }
301
302                         if (!g_strcmp0(order, "auto")) {
303                                 data_order.order = NETWORK_ORDER_AUTO;
304                         }
305                         else if (!g_strcmp0(order, "gsm")) {
306                                 data_order.order = NETWORK_ORDER_GSM_FIRST;
307                         }
308                         else if (!g_strcmp0(order, "wcdma")) {
309                                 data_order.order = NETWORK_ORDER_WCDMA_FIRST;
310                         }
311                         else if (!g_strcmp0(order, "no_change")) {
312                                 data_order.order = NETWORK_ORDER_NO_CHANGE;
313                         }
314                         else {
315                                 g_free(order);
316                                 result = FALSE;
317                                 resp.result = TCORE_RETURN_EINVAL;
318                                 _request_fail(ur, TRESP_NETWORK_SET_ORDER, sizeof(struct tresp_network_set_order), &resp);
319                                 break;
320                         }
321
322                         g_free(order);
323
324                         tcore_user_request_set_data(ur, sizeof(struct treq_network_set_order), &data_order);
325                         tcore_user_request_set_command(ur, TREQ_NETWORK_SET_ORDER);
326                 }
327                         break;
328
329                 case TAPI_SERVICE_NETWORK_GET_ORDER:
330                         tcore_user_request_set_data(ur, 0, NULL);
331                         tcore_user_request_set_command(ur, TREQ_NETWORK_GET_ORDER);
332                         break;
333
334                 case TAPI_SERVICE_NETWORK_SET_POWER_ON_ATTACH :{
335                         struct treq_network_set_power_on_attach data_power_on_attach;
336                         gboolean enable;
337
338                         enable = sipc_util_marshal_object_get_boolean(in_obj, "enable");
339
340                         data_power_on_attach.enable = enable;
341
342                         tcore_user_request_set_data(ur, sizeof(struct treq_network_set_power_on_attach), &data_power_on_attach);
343                         tcore_user_request_set_command(ur, TREQ_NETWORK_SET_POWER_ON_ATTACH);
344                 }
345                         break;
346
347                 case TAPI_SERVICE_NETWORK_GET_POWER_ON_ATTACH:
348                         tcore_user_request_set_data(ur, 0, NULL);
349                         tcore_user_request_set_command(ur, TREQ_NETWORK_GET_POWER_ON_ATTACH);
350                         break;
351
352                 case TAPI_SERVICE_NETWORK_SET_CANCEL_MANUAL_SEARCH:
353                         tcore_user_request_set_data(ur, 0, NULL);
354                         tcore_user_request_set_command(ur, TREQ_NETWORK_SET_CANCEL_MANUAL_SEARCH);
355                         break;
356
357                 case TAPI_SERVICE_NETWORK_GET_SERVING_NETWORK:
358                         tcore_user_request_set_data(ur, 0, NULL);
359                         tcore_user_request_set_command(ur, TREQ_NETWORK_GET_SERVING_NETWORK);
360                         break;
361         }
362
363 RETURN:
364         sipc_util_marshal_object_destory(in_obj);
365         out_obj = sipc_util_marshal_object_create();
366         sipc_util_marshal_object_add_data(out_obj, "result", &result, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
367
368         dbg("result = %d", result);
369
370         *outparam = sipc_util_marshal_object_serializer(out_obj);
371         sipc_util_marshal_object_destory(out_obj);
372
373         if (result == FALSE) {
374                 tcore_user_request_free(ur);
375                 return FALSE;
376         }
377
378         ret = tcore_communicator_dispatch_request(c, ur);
379         if (ret != TCORE_RETURN_SUCCESS) {
380                 return FALSE;
381         }
382
383         return TRUE;
384 }
385
386 gboolean scomm_service_response_network(Communicator *comm, UserRequest *ur, enum tcore_response_command command,
387                 unsigned int data_len, const void *data)
388 {
389         const struct tresp_network_search *resp_network_search = data;
390         const struct tresp_network_set_plmn_selection_mode *resp_set_plmn_selection_mode = data;
391         const struct tresp_network_get_plmn_selection_mode *resp_get_plmn_selection_mode = data;
392         const struct tresp_network_set_service_domain *resp_set_service_domain = data;
393         const struct tresp_network_get_service_domain *resp_get_service_domain = data;
394         const struct tresp_network_set_band *resp_set_band = data;
395         const struct tresp_network_get_band *resp_get_band = data;
396         const struct tresp_network_set_preferred_plmn *resp_set_preferred_plmn = data;
397         const struct tresp_network_get_preferred_plmn *resp_get_preferred_plmn = data;
398         const struct tresp_network_set_order *resp_set_order = data;
399         const struct tresp_network_get_order *resp_get_order = data;
400         const struct tresp_network_set_power_on_attach *resp_set_power_on_attach = data;
401         const struct tresp_network_get_power_on_attach *resp_get_power_on_attach = data;
402         const struct tresp_network_set_cancel_manual_search *resp_set_cancel_manual_search = data;
403
404         int ret = 0;
405         int i = 0;
406         gchar *out_d = NULL;
407         gchar *serial_d = NULL;
408         gchar entry_key[10] = { 0, };
409         struct custom_data *ctx = NULL;
410         const struct tcore_user_info *ui;
411         struct _tapi_header hdr;
412         struct _sipc_marshal_object* out_obj = NULL;
413         struct _sipc_marshal_object* entry_obj = NULL;
414         struct _sipc_marshal_object* in_obj = NULL;
415
416         ctx = tcore_communicator_ref_user_data(comm);
417         if (!ctx) {
418                 dbg("ctx is NULL");
419                 return FALSE;
420         }
421
422         ui = tcore_user_request_ref_user_info(ur);
423
424         dbg("response command = [0x%x], data_len = %d", command, data_len);
425         dbg("channel_id = %d, client_cmd = %d", ui->channel_id, ui->client_cmd);
426
427         memset(&hdr, 0, sizeof(struct _tapi_header));
428         hdr.cmd = (tapi_service_command_e) ui->client_cmd;
429
430         out_obj = sipc_util_marshal_object_create();
431
432         switch (command) {
433                 case TRESP_NETWORK_SEARCH:
434                         sipc_util_marshal_object_add_data(out_obj, "count", &resp_network_search->list_count,
435                                         SIPC_MARSHAL_DATA_INT_TYPE);
436
437                         dbg("count = %d", resp_network_search->list_count);
438                         entry_obj = sipc_util_marshal_object_create();
439                         for (i = 0; i < resp_network_search->list_count; i++) {
440                                 sipc_util_marshal_object_add_data(entry_obj, "plmn", resp_network_search->list[0].plmn,
441                                                 SIPC_MARSHAL_DATA_STRING_TYPE);
442                                 sipc_util_marshal_object_add_data(entry_obj, "status", &resp_network_search->list[0].status,
443                                                 SIPC_MARSHAL_DATA_INT_TYPE);
444                                 sipc_util_marshal_object_add_data(entry_obj, "act", &resp_network_search->list[0].act,
445                                                 SIPC_MARSHAL_DATA_INT_TYPE);
446
447                                 snprintf(entry_key, 10, "%d", i);
448                                 sipc_util_marshal_object_add_data(out_obj, entry_key, entry_obj, SIPC_MARSHAL_DATA_OBJECT_TYPE);
449
450                                 dbg(
451                                                 "key=%s, plmn=%s, status=%d, act=%d",
452                                                 entry_key, resp_network_search->list[0].plmn, resp_network_search->list[0].status, resp_network_search->list[0].act);
453                         }
454                         break;
455
456                 case TRESP_NETWORK_SET_PLMN_SELECTION_MODE:
457                         sipc_util_marshal_object_add_data(out_obj, "result", &resp_set_plmn_selection_mode->result,
458                                         SIPC_MARSHAL_DATA_INT_TYPE);
459                         break;
460
461                 case TRESP_NETWORK_GET_PLMN_SELECTION_MODE:
462                         sipc_util_marshal_object_add_data(out_obj, "mode", &resp_get_plmn_selection_mode->mode,
463                                         SIPC_MARSHAL_DATA_INT_TYPE);
464                         break;
465
466                 case TRESP_NETWORK_SET_SERVICE_DOMAIN:
467                         sipc_util_marshal_object_add_data(out_obj, "result", &resp_set_service_domain->result,
468                                         SIPC_MARSHAL_DATA_INT_TYPE);
469                         break;
470
471                 case TRESP_NETWORK_GET_SERVICE_DOMAIN:
472                         sipc_util_marshal_object_add_data(out_obj, "domain", &resp_get_service_domain->domain,
473                                         SIPC_MARSHAL_DATA_INT_TYPE);
474                         break;
475
476                 case TRESP_NETWORK_SET_BAND:
477                         sipc_util_marshal_object_add_data(out_obj, "result", &resp_set_band->result, SIPC_MARSHAL_DATA_INT_TYPE);
478                         break;
479
480                 case TRESP_NETWORK_GET_BAND:
481                         sipc_util_marshal_object_add_data(out_obj, "band", &resp_get_band->band, SIPC_MARSHAL_DATA_INT_TYPE);
482                         break;
483
484                 case TRESP_NETWORK_SET_PREFERRED_PLMN:
485                         sipc_util_marshal_object_add_data(out_obj, "result", &resp_set_preferred_plmn->result,
486                                         SIPC_MARSHAL_DATA_INT_TYPE);
487                         break;
488
489                 case TRESP_NETWORK_GET_PREFERRED_PLMN:
490                         sipc_util_marshal_object_add_data(out_obj, "count", &resp_get_preferred_plmn->list_count,
491                                         SIPC_MARSHAL_DATA_INT_TYPE);
492
493                         entry_obj = sipc_util_marshal_object_create();
494                         for (i = 0; i < resp_network_search->list_count; i++) {
495                                 sipc_util_marshal_object_add_data(entry_obj, "plmn", resp_get_preferred_plmn->list[0].plmn,
496                                                 SIPC_MARSHAL_DATA_STRING_TYPE);
497                                 sipc_util_marshal_object_add_data(entry_obj, "ef_index", &resp_get_preferred_plmn->list[0].ef_index,
498                                                 SIPC_MARSHAL_DATA_INT_TYPE);
499                                 sipc_util_marshal_object_add_data(entry_obj, "act", &resp_get_preferred_plmn->list[0].act,
500                                                 SIPC_MARSHAL_DATA_INT_TYPE);
501                                 snprintf(entry_key, 10, "%d", i);
502                                 sipc_util_marshal_object_add_data(out_obj, entry_key, entry_obj, SIPC_MARSHAL_DATA_OBJECT_TYPE);
503                         }
504                         break;
505
506                 case TRESP_NETWORK_SET_ORDER:
507                         sipc_util_marshal_object_add_data(out_obj, "result", &resp_set_order->result, SIPC_MARSHAL_DATA_INT_TYPE);
508                         break;
509
510                 case TRESP_NETWORK_GET_ORDER:
511                         sipc_util_marshal_object_add_data(out_obj, "result", &resp_get_order->order, SIPC_MARSHAL_DATA_INT_TYPE);
512                         break;
513
514                 case TRESP_NETWORK_SET_POWER_ON_ATTACH:
515                         sipc_util_marshal_object_add_data(out_obj, "result", &resp_set_power_on_attach->result,
516                                         SIPC_MARSHAL_DATA_INT_TYPE);
517                         break;
518
519                 case TRESP_NETWORK_GET_POWER_ON_ATTACH:
520                         sipc_util_marshal_object_add_data(out_obj, "enabled", &resp_get_power_on_attach->enabled,
521                                         SIPC_MARSHAL_DATA_INT_TYPE);
522                         break;
523
524                 case TRESP_NETWORK_SET_CANCEL_MANUAL_SEARCH:
525                         sipc_util_marshal_object_add_data(out_obj, "result", &resp_set_cancel_manual_search->result,
526                                         SIPC_MARSHAL_DATA_INT_TYPE);
527                         break;
528
529                 case TRESP_NETWORK_GET_SERVING_NETWORK:
530                         //
531                         break;
532         }
533
534         if (out_obj) {
535                 serial_d = sipc_util_marshal_object_serializer(out_obj);
536                 hdr.data_len = strlen(serial_d);
537                 dbg("data_len = %d", hdr.data_len);
538                 sipc_util_marshal_object_destory(out_obj);
539         }
540
541         if (entry_obj) {
542                 sipc_util_marshal_object_destory(out_obj);
543         }
544
545         out_d = g_new0(char, sizeof(struct _tapi_header) + hdr.data_len);
546         memcpy(out_d, &hdr, sizeof(struct _tapi_header));
547
548         if (serial_d) {
549                 memcpy(out_d + sizeof(struct _tapi_header), serial_d, hdr.data_len);
550                 dbg("serial_d = [%s]", serial_d);
551                 g_free(serial_d);
552         }
553
554         ret = sipc_server_send(ctx->sk_server, ui->channel_id, out_d, sizeof(struct _tapi_header) + hdr.data_len,
555                         SIPC_SEND_DATA_ASYNC);
556         g_free(out_d);
557
558         if (ret < 0) {
559                 dbg("ret = %d", ret);
560                 return FALSE;
561         }
562
563         return TRUE;
564 }
565
566 gboolean scomm_service_notification_network(Communicator *comm, CoreObject *source, enum tcore_notification_command command,
567                 unsigned int data_len, const void *data)
568 {
569         const struct tnoti_network_registration_status *noti_registration_status = data;
570         const struct tnoti_network_location_cellinfo *noti_location_cellinfo = data;
571         const struct tnoti_network_icon_info *noti_icon_info = data;
572         const struct tnoti_network_change *noti_change = data;
573         const struct tnoti_network_timeinfo *noti_timeinfo = data;
574
575         int ret = 0;
576         struct custom_data *ctx = NULL;
577         struct _tapi_header hdr;
578         struct _sipc_marshal_object* out_obj = NULL;
579         gchar *out_d = NULL, *serial_d = NULL;
580
581         ctx = tcore_communicator_ref_user_data(comm);
582         if (!ctx) {
583                 dbg("user_data is NULL");
584                 return FALSE;
585         }
586
587         dbg("notification !!! (command = 0x%x, data_len = %d)", command, data_len);
588
589         switch (command) {
590                 case TNOTI_NETWORK_REGISTRATION_STATUS:
591                         hdr.cmd = TAPI_NOTI_NETWORK_REGISTRATION_STATUS;
592
593                         out_obj = sipc_util_marshal_object_create();
594                         sipc_util_marshal_object_add_data(out_obj, "cs_domain_status", &noti_registration_status->cs_domain_status, SIPC_MARSHAL_DATA_INT_TYPE);
595                         sipc_util_marshal_object_add_data(out_obj, "ps_domain_status", &noti_registration_status->ps_domain_status, SIPC_MARSHAL_DATA_INT_TYPE);
596                         sipc_util_marshal_object_add_data(out_obj, "service_type", &noti_registration_status->service_type, SIPC_MARSHAL_DATA_INT_TYPE);
597                         sipc_util_marshal_object_add_data(out_obj, "roaming_status", &noti_registration_status->roaming_status, SIPC_MARSHAL_DATA_INT_TYPE);
598                         break;
599
600                 case TNOTI_NETWORK_LOCATION_CELLINFO:
601                         hdr.cmd = TAPI_NOTI_NETWORK_LOCATION_CELLINFO;
602
603                         out_obj = sipc_util_marshal_object_create();
604                         sipc_util_marshal_object_add_data(out_obj, "lac", &noti_location_cellinfo->lac, SIPC_MARSHAL_DATA_INT_TYPE);
605                         sipc_util_marshal_object_add_data(out_obj, "cell_id", &noti_location_cellinfo->cell_id, SIPC_MARSHAL_DATA_INT_TYPE);
606                         break;
607
608                 case TNOTI_NETWORK_ICON_INFO:
609                         hdr.cmd = TAPI_NOTI_NETWORK_ICON_INFO;
610
611                         out_obj = sipc_util_marshal_object_create();
612                         sipc_util_marshal_object_add_data(out_obj, "type", &noti_icon_info->type, SIPC_MARSHAL_DATA_INT_TYPE);
613                         sipc_util_marshal_object_add_data(out_obj, "rssi", &noti_icon_info->rssi, SIPC_MARSHAL_DATA_INT_TYPE);
614                         sipc_util_marshal_object_add_data(out_obj, "battery", &noti_icon_info->battery, SIPC_MARSHAL_DATA_INT_TYPE);
615                         sipc_util_marshal_object_add_data(out_obj, "hdr_rssi", &noti_icon_info->hdr_rssi, SIPC_MARSHAL_DATA_INT_TYPE);
616                         break;
617
618                 case TNOTI_NETWORK_CHANGE:
619                         hdr.cmd = TAPI_NOTI_NETWORK_CHANGE;
620
621                         out_obj = sipc_util_marshal_object_create();
622                         sipc_util_marshal_object_add_data(out_obj, "plmn", noti_change->plmn, SIPC_MARSHAL_DATA_STRING_TYPE);
623                         sipc_util_marshal_object_add_data(out_obj, "act", &noti_change->act, SIPC_MARSHAL_DATA_INT_TYPE);
624                         sipc_util_marshal_object_add_data(out_obj, "lac", &noti_change->gsm.lac, SIPC_MARSHAL_DATA_INT_TYPE);
625                         sipc_util_marshal_object_add_data(out_obj, "carrier", &noti_change->cdma.carrier, SIPC_MARSHAL_DATA_INT_TYPE);
626                         sipc_util_marshal_object_add_data(out_obj, "sid", &noti_change->cdma.sid, SIPC_MARSHAL_DATA_INT_TYPE);
627                         sipc_util_marshal_object_add_data(out_obj, "nid", &noti_change->cdma.nid, SIPC_MARSHAL_DATA_INT_TYPE);
628                         sipc_util_marshal_object_add_data(out_obj, "bs_id", &noti_change->cdma.bs_id, SIPC_MARSHAL_DATA_INT_TYPE);
629                         sipc_util_marshal_object_add_data(out_obj, "bs_lat", &noti_change->cdma.bs_lat, SIPC_MARSHAL_DATA_INT_TYPE);
630                         sipc_util_marshal_object_add_data(out_obj, "bs_long", &noti_change->cdma.bs_long, SIPC_MARSHAL_DATA_INT_TYPE);
631                         sipc_util_marshal_object_add_data(out_obj, "reg_sonze", &noti_change->cdma.reg_sonze, SIPC_MARSHAL_DATA_INT_TYPE);
632                         sipc_util_marshal_object_add_data(out_obj, "pilot_pn", &noti_change->cdma.pilot_pn, SIPC_MARSHAL_DATA_INT_TYPE);
633                         break;
634
635                 case TNOTI_NETWORK_TIMEINFO:
636                         hdr.cmd = TAPI_NOTI_NETWORK_TIMEINFO;
637
638                         out_obj = sipc_util_marshal_object_create();
639                         sipc_util_marshal_object_add_data(out_obj, "plmn", noti_timeinfo->plmn, SIPC_MARSHAL_DATA_STRING_TYPE);
640                         sipc_util_marshal_object_add_data(out_obj, "year", &noti_timeinfo->year, SIPC_MARSHAL_DATA_INT_TYPE);
641                         sipc_util_marshal_object_add_data(out_obj, "month", &noti_timeinfo->month, SIPC_MARSHAL_DATA_INT_TYPE);
642                         sipc_util_marshal_object_add_data(out_obj, "day", &noti_timeinfo->day, SIPC_MARSHAL_DATA_INT_TYPE);
643                         sipc_util_marshal_object_add_data(out_obj, "hour", &noti_timeinfo->hour, SIPC_MARSHAL_DATA_INT_TYPE);
644                         sipc_util_marshal_object_add_data(out_obj, "minute", &noti_timeinfo->minute, SIPC_MARSHAL_DATA_INT_TYPE);
645                         sipc_util_marshal_object_add_data(out_obj, "second", &noti_timeinfo->second, SIPC_MARSHAL_DATA_INT_TYPE);
646                         sipc_util_marshal_object_add_data(out_obj, "wday", &noti_timeinfo->wday, SIPC_MARSHAL_DATA_INT_TYPE);
647                         sipc_util_marshal_object_add_data(out_obj, "gmtoff", &noti_timeinfo->gmtoff, SIPC_MARSHAL_DATA_INT_TYPE);
648                         sipc_util_marshal_object_add_data(out_obj, "dstoff", &noti_timeinfo->dstoff, SIPC_MARSHAL_DATA_INT_TYPE);
649                         sipc_util_marshal_object_add_data(out_obj, "isdst", &noti_timeinfo->isdst, SIPC_MARSHAL_DATA_INT_TYPE);
650                         break;
651
652                 default:
653                         break;
654         }
655
656         if (out_obj) {
657                 serial_d = sipc_util_marshal_object_serializer(out_obj);
658                 hdr.data_len = strlen(serial_d);
659                 sipc_util_marshal_object_destory(out_obj);
660         }
661
662         out_d = g_new0(char, sizeof(struct _tapi_header)+hdr.data_len);
663         memcpy(out_d, &hdr, sizeof(struct _tapi_header));
664         if (serial_d) {
665                 memcpy(out_d + sizeof(struct _tapi_header), serial_d, hdr.data_len);
666                 g_free(serial_d);
667         }
668
669         dbg("len = %d, out_d = [%s]", sizeof(struct _tapi_header) + hdr.data_len, out_d);
670
671         ret = sipc_server_broadcast(ctx->sk_server, out_d, sizeof(struct _tapi_header) + hdr.data_len);
672         dbg("ret = %d", ret);
673         g_free(out_d);
674
675         return TRUE;
676 }