Correct the privilege check for BT_UPDATE_LE_CONNECTION_MODE
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / services / bt-request-handler.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *              http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <string.h>
19 #include <stdio.h>
20 #include <glib.h>
21 #include <dlog.h>
22 #include <gio/gio.h>
23 #include <gio/gunixfdlist.h>
24 #include <cynara-client.h>
25 #include <cynara-creds-gdbus.h>
26 #include <systemd/sd-daemon.h>
27 #include <aul.h>
28
29 #include "bluetooth-api.h"
30 #include "bluetooth-audio-api.h"
31 #include "bluetooth-gatt-server-api.h"
32 #include "bluetooth-mesh-api.h"
33 #include "bt-request-handler.h"
34 #include "bt-service-common.h"
35 #include "bt-service-util.h"
36
37 #include "bt-service-core-adapter.h"
38 #include "bt-service-core-adapter-le.h"
39 #include "bt-service-core-device.h"
40
41 #include "bt-service-audio-common.h"
42 #include "bt-service-avrcp-tg.h"
43 #include "bt-service-avrcp-ctrl.h"
44 #include "bt-service-gatt.h"
45 #include "bt-service-mesh-main.h"
46 #include "bt-service-mesh-util.h"
47 #include "bt-service-mesh-network.h"
48 #include "bt-service-mesh-config-client.h"
49 #include "bt-service-mesh-model.h"
50 #include "bt-service-dpm.h"
51 #include "bt-service-hidhost.h"
52 #include "bt-service-rfcomm.h"
53 #include "bt-service-hdp.h"
54 #include "bt-service-tds.h"
55
56 /*Obex*/
57 #include "bt-service-obex-server.h"
58 #include "bt-service-opp-client.h"
59 #include "bt-service-map-client.h"
60 #include "bt-service-pbap.h"
61 #include "bt-service-oob.h"
62
63 #include "bt-service-battery-monitor.h"
64
65 #ifdef TIZEN_FEATURE_BT_PAN_NAP
66 #include "bt-service-network.h"
67 #endif
68
69 #ifdef TIZEN_FEATURE_BT_IPSP
70 #include "bt-service-ipsp.h"
71 #endif
72 /* For maintaining Application Sync API call requests */
73 static GSList *invocation_list = NULL;
74
75 static GDBusConnection *bt_service_conn;
76 static guint owner_id = 0;
77 static guint owner_sig_id = 0;
78 static gboolean is_le_intended = FALSE;
79
80 static cynara *p_cynara;
81 static cynara_configuration *conf;
82 static const char *requester_unique_creds = NULL;
83
84 static const gchar bt_service_introspection_xml[] =
85 "<node name='/org/projectx/bt_service'>"
86 "       <interface name='org.projectx.bt'>"
87 "               <method name='service_request'>"
88                         /* Input Parameters */
89 "                       <arg type='i' name='service_type' direction='in' />"
90 "                       <arg type='i' name='service_function' direction='in' />"
91 "                       <arg type='i' name='request_type' direction='in' />"
92 "                       <arg type='ay' name='input_param1' direction='in' />"
93 "                       <arg type='ay' name='input_param2' direction='in' />"
94 "                       <arg type='ay' name='input_param3' direction='in' />"
95 "                       <arg type='ay' name='input_param4' direction='in' />"
96 "                       <arg type='ay' name='input_param5' direction='in' />"
97                         /* Return Parameters */
98 "                       <arg type='i' name='output_param1' direction='out' />"
99 "                       <arg type='v' name='output_param2' direction='out' />"
100 "               </method>"
101 "               <method name='get_avc_mode'>"
102                         /* Out Parameters */
103 "                       <arg type='u' name='avc_mode' direction='out' />"
104 "               </method>"
105 "       </interface>"
106 "</node>";
107
108 static gboolean name_acquired = FALSE;
109
110 static char *current_sender_playing = NULL;
111
112 GDBusNodeInfo *node_info_g = NULL;
113
114 static void __bt_fill_garray_from_variant(GVariant *var, GArray *param);
115
116 static void __bt_service_method(GDBusConnection *connection,
117                 const gchar *sender,
118                 const gchar *object_path,
119                 const gchar *interface_name,
120                 const gchar *method_name,
121                 GVariant *parameters,
122                 GDBusMethodInvocation *invocation,
123                 gpointer user_data);
124
125 int __bt_bluez_request(int function_name,
126                 int request_type,
127                 int request_id,
128                 GDBusMethodInvocation *context,
129                 GVariant *in_param1,
130                 GVariant *in_param2,
131                 GVariant *in_param3,
132                 GVariant *in_param4,
133                 GArray **out_param1);
134 int __bt_obexd_request(int function_name,
135                 int request_type,
136                 int request_id,
137                 GDBusMethodInvocation *context,
138                 GVariant *in_param1,
139                 GVariant *in_param2,
140                 GVariant *in_param3,
141                 GVariant *in_param4,
142                 GArray **out_param1);
143 int __bt_agent_request(int function_name,
144                 int request_type,
145                 int request_id,
146                 GDBusMethodInvocation *context,
147                 GVariant *in_param1,
148                 GVariant *in_param2,
149                 GVariant *in_param3,
150                 GVariant *in_param4,
151                 GArray **out_param1);
152 int __bt_core_request(int function_name,
153                 int request_type,
154                 int request_id,
155                 GDBusMethodInvocation *context,
156                 GVariant *in_param1);
157
158 gboolean __bt_service_check_privilege(int function_name,
159                                         int service_type,
160                                         const char *unique_name);
161
162 /* Function definitions*/
163 GSList *_bt_get_invocation_list(void)
164 {
165         return invocation_list;
166 }
167
168 void _bt_free_info_from_invocation_list(invocation_info_t *req_info)
169 {
170         ret_if(NULL == req_info);
171         invocation_list = g_slist_remove(invocation_list, req_info);
172         g_free(req_info->sender);
173         g_free(req_info->user_data);
174         g_free(req_info);
175 }
176
177 void _bt_set_le_intended_status(gboolean value)
178 {
179         is_le_intended = value;
180 }
181
182 static void __bt_service_get_parameters(GVariant *in_param,
183                 void *value, int size)
184 {
185         void *buf = NULL;
186         buf = (void *)g_variant_get_data(in_param);
187         memcpy(value, buf, size);
188 }
189
190 static gboolean __bt_is_sync_function(int service_function)
191 {
192         /*TODO: Keep adding sync methods with expect replies from bluetooth service */
193         if (service_function == BT_GET_LOCAL_ADDRESS
194                         || service_function == BT_GET_LOCAL_NAME
195                         || service_function == BT_GET_LOCAL_VERSION
196                         || service_function == BT_GET_BONDED_DEVICES
197                         || service_function == BT_GET_BONDED_DEVICE
198                         || service_function == BT_GET_PROFILE_CONNECTED_DEVICES
199                         || service_function == BT_GET_IS_ALIAS_SET
200                         || service_function == BT_GET_CONNECTED_LINK_TYPE
201                         || service_function == BT_IS_SERVICE_USED
202                         || service_function == BT_RFCOMM_LISTEN_AND_ACCEPT
203                         || service_function == BT_RFCOMM_LISTEN
204                         || service_function == BT_HDP_REGISTER_SINK_APP
205                         || service_function == BT_HDP_UNREGISTER_SINK_APP
206                         || service_function == BT_HDP_GET_FD
207                         || service_function == BT_AVRCP_GET_TRACK_INFO
208                         || service_function == BT_AVRCP_CONTROL_GET_PROPERTY
209                         || service_function == BT_SET_ADVERTISING_DATA
210                         || service_function == BT_SET_SCAN_RESPONSE_DATA
211                         || service_function == BT_SET_ADVERTISING
212                         || service_function == BT_SET_CUSTOM_ADVERTISING
213                         || service_function == BT_GATT_SERVER_REGISTER
214                         || service_function == BT_GATT_SERVER_ADD_SERVICE
215                         || service_function == BT_GATT_SERVER_ADD_CHARACTERISTIC
216                         || service_function == BT_GATT_SERVER_ADD_DESCRIPTOR
217                         || service_function == BT_GATT_SERVER_START_SERVICE
218                         || service_function == BT_GATT_SERVER_STOP_SERVICE
219                         || service_function == BT_GATT_SERVER_DELETE_SERVICE
220                         || service_function == BT_START_LE_DISCOVERY
221                         || service_function == BT_STOP_LE_DISCOVERY
222                         || service_function == BT_GET_CONNECTABLE
223                         || service_function == BT_GATT_CLIENT_REGISTER
224                         || service_function == BT_GATT_GET_PRIMARY_SERVICES
225                         || service_function == BT_GATT_GET_SERVICE_PROPERTIES
226                         || service_function == BT_GATT_GET_INCLUDED_SERVICES
227                         || service_function == BT_GATT_GET_CHARACTERISTIC_PROPERTIES
228                         || service_function == BT_GATT_WATCH_CHARACTERISTIC
229                         || service_function == BT_GATT_ACQUIRE_WRITE
230                         || service_function == BT_AUDIO_SELECT_ROLE
231                         /* Mesh API's */
232                         || service_function == BT_MESH_INIT
233                         || service_function == BT_MESH_NETWORK_CREATE
234                         || service_function == BT_MESH_NETWORK_DESTROY
235                         || service_function == BT_MESH_NETWORK_LOAD
236                         || service_function == BT_MESH_NETWORK_SCAN
237                         || service_function == BT_MESH_NETWORK_ADD_NETKEY
238                         || service_function == BT_MESH_NETWORK_DELETE_NETKEY
239                         || service_function == BT_MESH_NETWORK_UPDATE_NETKEY
240                         || service_function == BT_MESH_NETWORK_ADD_APPKEY
241                         || service_function == BT_MESH_NETWORK_DELETE_APPKEY
242                         || service_function == BT_MESH_NETWORK_UPDATE_APPKEY)
243                 return TRUE;
244         else
245                 return FALSE;
246 }
247
248 void _bt_save_invocation_context(GDBusMethodInvocation *invocation, int result,
249                 char *sender, int service_function,
250                 gpointer invocation_data)
251 {
252         invocation_info_t *info;
253         info = g_malloc0(sizeof(invocation_info_t));
254         info->context = invocation;
255         info->result = result;
256         info->sender = g_strdup(sender);
257         info->service_function = service_function;
258         info->user_data = invocation_data;
259         invocation_list = g_slist_append(invocation_list, info);
260
261 }
262
263 static int __bt_service_get_sender_pid(const char *unique_name, pid_t *pid)
264 {
265         int ret;
266         char err_msg[256] = {0, };
267
268         retv_if(bt_service_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
269
270         ret = cynara_creds_gdbus_get_pid(bt_service_conn, unique_name, pid);
271         if (ret != CYNARA_API_SUCCESS) {
272                 cynara_strerror(ret, err_msg, sizeof(err_msg));
273                 BT_ERR("Fail to get user credential: %s", err_msg);
274
275                 return BLUETOOTH_ERROR_INTERNAL;
276         }
277
278         return BLUETOOTH_ERROR_NONE;
279 }
280
281 static int __bt_bm_request_data(_bt_battery_data_t *latest)
282 {
283         int ret = _bt_bm_read_data(latest);
284         if (ret == BLUETOOTH_ERROR_NONE) {
285                 BT_DBG("Received data from bluetooth battery monitor: %ld %ld %d %d",
286                         latest->session_start_time, latest->session_end_time,
287                                 latest->session_scan_time, latest->session_connected_time);
288
289                 if (latest->atm_list == NULL) {
290                         BT_DBG("No app data transaction for this session");
291                         return ret;
292                 }
293
294                 for (GSList *l = latest->atm_list; l != NULL; l = g_slist_next(l)) {
295                         _bt_battery_app_data_t *t = (_bt_battery_app_data_t *)(l->data);
296                         BT_DBG("%ld %ld %d %d", (long int)(t->uid), (long int)(t->pid), t->rx_bytes, t->tx_bytes);
297                 }
298         }
299         else
300                 BT_ERR("Error encountered");
301         return ret;
302 }
303
304 static void __bt_service_method(GDBusConnection *connection,
305                 const gchar *sender,
306                 const gchar *object_path,
307                 const gchar *interface_name,
308                 const gchar *method_name,
309                 GVariant *parameters,
310                 GDBusMethodInvocation *invocation,
311                 gpointer user_data)
312 {
313         FN_START;
314
315         BT_DBG("Method[%s] Object Path[%s] Interface Name[%s]",
316                         method_name, object_path, interface_name);
317
318         if (g_strcmp0(method_name, "service_request") == 0) {
319                 int service_type;
320                 int service_function;
321                 int request_type;
322                 GVariant *param1 = NULL;
323                 GVariant *param2 = NULL;
324                 GVariant *param3 = NULL;
325                 GVariant *param4 = NULL;
326                 GVariant *param5 = NULL;
327                 GArray *out_param1 = NULL;
328                 GVariant *out_var = NULL;
329                 GVariant *temp = NULL;
330                 int result = 0;
331                 int request_id = -1;
332
333                 g_variant_get(parameters, "(iii@ay@ay@ay@ay@ay)", &service_type,
334                                 &service_function, &request_type,
335                                 &param1, &param2, &param3, &param4, &param5);
336
337                 out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
338
339                 if (service_type == BT_CORE_SERVICE) {
340                         BT_DBG("No need to check privilege from bt-core");
341                 } else if (__bt_service_check_privilege(service_function,
342                                         service_type, (const char *)sender) == FALSE) {
343                         BT_ERR("Client don't have the privilege to excute this function");
344                         result = BLUETOOTH_ERROR_PERMISSION_DEINED;
345                         goto fail;
346                 }
347
348                 BT_DBG("SERVICE TYPE [%d] SERVICE FUNC [%d]",
349                                 service_type, service_function);
350                 switch (service_type) {
351                 case BT_BLUEZ_SERVICE:
352                         result = __bt_bluez_request(service_function,
353                                         request_type, request_id,
354                                         invocation, param1, param2,
355                                         param3, param4, &out_param1);
356                         break;
357                 case BT_OBEX_SERVICE:
358                         result = __bt_obexd_request(service_function,
359                                         request_type, request_id,
360                                         invocation, param1,
361                                         param2, param3,
362                                         param4, &out_param1);
363                         break;
364                 case BT_AGENT_SERVICE:
365                         result = __bt_agent_request(service_function,
366                                         request_type, request_id,
367                                         invocation, param1,
368                                         param2, param3,
369                                         param4, &out_param1);
370                         break;
371                 case BT_CORE_SERVICE:
372                         result = __bt_core_request(service_function,
373                                         request_type, request_id,
374                                         invocation, param1);
375                         break;
376                 case BT_CHECK_PRIVILEGE:
377                         result = BLUETOOTH_ERROR_NONE;
378                         break;
379                 default:
380                         BT_ERR("Unknown service type");
381                         result = BLUETOOTH_ERROR_INTERNAL;
382                         goto fail;
383                 }
384
385                 if (result != BLUETOOTH_ERROR_NONE)
386                         goto fail;
387
388                 if (service_type == BT_CHECK_PRIVILEGE)
389                         goto send_reply;
390
391                 if (service_function == BT_OPP_PUSH_FILES)
392                         goto done;
393
394                 if (request_type == BT_ASYNC_REQ ||
395                                 __bt_is_sync_function(service_function)) {
396                         /* Do not send reply to bt-api over dbus,
397                                 Invocation context is already saved in service_function */
398                         goto done;
399                 }
400
401 send_reply:
402                 out_var = g_variant_new_from_data((const GVariantType *)"ay",
403                                 out_param1->data, out_param1->len,
404                                 TRUE, NULL, NULL);
405
406                 temp = g_variant_new("(iv)", result, out_var);
407                 g_dbus_method_invocation_return_value(invocation, temp);
408                 g_array_free(out_param1, TRUE);
409                 out_param1 = NULL;
410
411 done:
412                 g_variant_unref(param1);
413                 g_variant_unref(param2);
414                 g_variant_unref(param3);
415                 g_variant_unref(param4);
416                 g_variant_unref(param5);
417                 FN_END;
418                 return;
419 fail:
420                 BT_ERR_C("Request is failed [%s] [0x%x]",
421                                 _bt_convert_error_to_string(result), result);
422
423                 out_var = g_variant_new_from_data((const GVariantType *)"ay",
424                                 out_param1->data, out_param1->len,
425                                 TRUE, NULL, NULL);
426
427                 temp = g_variant_new("(iv)", result, out_var);
428                 g_dbus_method_invocation_return_value(invocation, temp);
429
430                 g_array_free(out_param1, TRUE);
431                 out_param1 = NULL;
432
433                 g_variant_unref(param1);
434                 g_variant_unref(param2);
435                 g_variant_unref(param3);
436                 g_variant_unref(param4);
437                 g_variant_unref(param5);
438         }
439         else if (g_strcmp0(method_name, "get_avc_mode") == 0) {
440                 unsigned int mode = 0;
441
442                 if (_bt_audio_get_avc_mode(&mode) != BLUETOOTH_ERROR_NONE)
443                         BT_ERR("Fail to get the avc mode");
444
445                 BT_DBG("Absolute Volume Control mode: %d", mode);
446
447                 g_dbus_method_invocation_return_value(invocation,
448                         g_variant_new("(u)", mode));
449         }
450
451         FN_END;
452         return;
453 }
454
455
456 static const GDBusInterfaceVTable method_table = {
457         __bt_service_method,
458         NULL,
459         NULL,
460         {0}
461 };
462
463 int __bt_bluez_request(int function_name,
464                 int request_type,
465                 int request_id,
466                 GDBusMethodInvocation *context,
467                 GVariant *in_param1,
468                 GVariant *in_param2,
469                 GVariant *in_param3,
470                 GVariant *in_param4,
471                 GArray **out_param1)
472 {
473         int result = BLUETOOTH_ERROR_NONE;
474         char *sender = NULL;
475
476         switch (function_name) {
477         case BT_ENABLE_ADAPTER: {
478                 result = _bt_enable_adapter();
479                 _bt_adapter_start_enable_timer();
480                 break;
481         }
482         case BT_DISABLE_ADAPTER: {
483                 result = _bt_disable_adapter();
484                 break;
485         }
486         case BT_RECOVER_ADAPTER:
487                  result = _bt_recover_adapter();
488                  break;
489         case BT_RESET_ADAPTER:
490                 result = _bt_reset_adapter();
491                 break;
492         case BT_BATTERY_READ_DATA: {
493                 _bt_battery_data_t *data = NULL;
494                 data = g_malloc0(sizeof(_bt_battery_data_t));
495                 result = __bt_bm_request_data(data);
496
497                 bt_battery_dbus_data_t dbus_data;
498                 memset(&dbus_data, 0, sizeof(bt_battery_dbus_data_t));
499                 dbus_data.session_start_time = data->session_start_time;
500                 dbus_data.session_end_time = data->session_end_time;
501                 dbus_data.session_scan_time = data->session_scan_time;
502                 dbus_data.session_connected_time = data->session_connected_time;
503                 dbus_data.tx_time = data->tx_time;
504                 dbus_data.rx_time = data->rx_time;
505                 dbus_data.idle_time = data->idle_time;
506
507                 /*Populating app data*/
508                 int n = 0;
509                 for (GSList *l = data->atm_list; l != NULL; l = g_slist_next(l)) {
510                         bt_battery_app_data *t = (bt_battery_app_data *)(l->data);
511                         memcpy(&dbus_data.app_data[n], t, sizeof(bt_battery_app_data));
512                         n++;
513                 }
514                 dbus_data.num_app = n;
515                 g_array_append_vals(*out_param1, &dbus_data, sizeof(bt_battery_dbus_data_t));
516                 g_slist_free_full(data->atm_list, g_free);
517                 g_free(data);
518                 data = NULL;
519                 break;
520         }
521         case BT_CHECK_ADAPTER: {
522                 int enabled = BT_ADAPTER_DISABLED;
523                 result = _bt_check_adapter(&enabled);
524
525                 g_array_append_vals(*out_param1, &enabled,
526                                 sizeof(int));
527                 break;
528         }
529         case BT_ENABLE_ADAPTER_LE:
530                 _bt_set_le_intended_status(TRUE);
531                 result = _bt_enable_adapter_le();
532                 break;
533         case BT_DISABLE_ADAPTER_LE:
534                 _bt_set_le_intended_status(FALSE);
535                 result = _bt_disable_adapter_le();
536                 break;
537         case BT_START_DISCOVERY: {
538                 unsigned short max_response;
539                 unsigned short discovery_duration;
540                 unsigned int classOfDeviceMask;
541                 uid_t uid;
542
543                 __bt_service_get_parameters(in_param1,
544                                 &max_response, sizeof(unsigned short));
545                 __bt_service_get_parameters(in_param2,
546                                 &discovery_duration, sizeof(unsigned short));
547                 __bt_service_get_parameters(in_param3,
548                                 &classOfDeviceMask, sizeof(unsigned int));
549                 __bt_service_get_parameters(in_param4, &uid, sizeof(uid_t));
550
551                 result = _bt_start_discovery(max_response, discovery_duration, classOfDeviceMask);
552
553                 if (result == BLUETOOTH_ERROR_NONE) {
554                         pid_t pid;
555
556                         sender = (char*)g_dbus_method_invocation_get_sender(context);
557
558                         if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
559                                 BT_ERR("Fail to get the sender pid");
560
561                         BT_DBG("Remeber pid / uid for the scan operation");
562                         _bt_bm_add_scan_app(SCAN_REGACY, uid, pid);
563                 }
564
565                 break;
566         }
567         case BT_START_CUSTOM_DISCOVERY: {
568                 bt_discovery_role_type_t role;
569
570                 __bt_service_get_parameters(in_param1,
571                                 &role, sizeof(bt_discovery_role_type_t));
572                 result = _bt_start_custom_discovery(role);
573
574                 break;
575         }
576         case BT_CANCEL_DISCOVERY:
577                 result = _bt_cancel_discovery();
578                 break;
579         case BT_IS_DISCOVERYING: {
580                 gboolean discovering = FALSE;
581                 discovering = _bt_is_discovering();
582                 g_array_append_vals(*out_param1,
583                                 &discovering, sizeof(gboolean));
584                 break;
585         }
586         case BT_GET_LOCAL_ADDRESS: {
587                 result = _bt_get_local_address();
588
589                 /* Save invocation */
590                 if (result == BLUETOOTH_ERROR_NONE) {
591                         sender = (char*)g_dbus_method_invocation_get_sender(context);
592                         _bt_save_invocation_context(context, result, sender,
593                                         function_name, NULL);
594                 }
595                 break;
596         }
597         case BT_GET_LOCAL_VERSION: {
598                 result = _bt_get_local_version();
599
600                 /* Save invocation */
601                 if (result == BLUETOOTH_ERROR_NONE) {
602                         sender = (char*)g_dbus_method_invocation_get_sender(context);
603                         _bt_save_invocation_context(context, result, sender,
604                                         function_name, NULL);
605                 }
606                 break;
607         }
608         case BT_GET_LOCAL_NAME: {
609                 result = _bt_get_local_name();
610
611                 /* Save invocation */
612                 if (result == BLUETOOTH_ERROR_NONE) {
613                         sender = (char*)g_dbus_method_invocation_get_sender(context);
614                         _bt_save_invocation_context(context, result, sender,
615                                         function_name, NULL);
616                 }
617                 break;
618         }
619         case BT_SET_LOCAL_NAME: {
620                 bluetooth_device_name_t local_name = { {0} };
621                 __bt_service_get_parameters(in_param1,
622                                 &local_name, sizeof(bluetooth_device_name_t));
623                 result = _bt_set_local_name(local_name.name);
624                 break;
625         }
626         case BT_GET_DISCOVERABLE_MODE: {
627                 int discoverable_mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
628                 result = _bt_get_discoverable_mode(&discoverable_mode);
629                 g_array_append_vals(*out_param1, &discoverable_mode, sizeof(int));
630                 break;
631         }
632         case BT_GET_DISCOVERABLE_TIME: {
633                 int timeout = 0;
634
635                 result = _bt_get_timeout_value(&timeout);
636                 g_array_append_vals(*out_param1, &timeout, sizeof(int));
637                 break;
638         }
639         case BT_SET_DISCOVERABLE_MODE: {
640                 int mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
641                 int time = 0;
642
643                 __bt_service_get_parameters(in_param1, &mode, sizeof(int));
644                 __bt_service_get_parameters(in_param2, &time, sizeof(int));
645
646                 result = _bt_set_discoverable_mode(mode, time);
647                 break;
648         }
649         case BT_IS_CONNECTABLE: {
650                 gboolean is_connectable = FALSE;
651
652                 is_connectable = _bt_is_connectable();
653                 g_array_append_vals(*out_param1, &is_connectable, sizeof(gboolean));
654                 break;
655         }
656         case BT_GET_CONNECTABLE: {
657                 result  = _bt_get_connectable();
658
659                 /* Save invocation */
660                 if (result == BLUETOOTH_ERROR_NONE) {
661                          sender = (char*)g_dbus_method_invocation_get_sender(context);
662                          _bt_save_invocation_context(context, result, sender,
663                                          function_name, NULL);
664                 }
665                 break;
666         }
667         case BT_SET_CONNECTABLE: {
668                 gboolean is_connectable;
669
670                 __bt_service_get_parameters(in_param1,
671                                 &is_connectable, sizeof(gboolean));
672                 result = _bt_set_connectable(is_connectable);
673                 break;
674         }
675         case BT_IS_SERVICE_USED: {
676                 char *uuid = NULL;
677
678                 uuid = (char *)g_variant_get_data(in_param1);
679                 BT_INFO("UUID to be searched [%s]", uuid);
680                 result = _bt_is_service_used();
681
682                 /* Save invocation */
683                 if (result == BLUETOOTH_ERROR_NONE) {
684                         sender = (char*)g_dbus_method_invocation_get_sender(context);
685                         _bt_save_invocation_context(context, result, sender,
686                                         function_name, g_strdup(uuid));
687                 }
688                 break;
689         }
690         case BT_GET_BONDED_DEVICES: {
691                 result = _bt_get_bonded_devices();
692                 /* Save invocation */
693                 if (result == BLUETOOTH_ERROR_NONE) {
694                         sender = (char*)g_dbus_method_invocation_get_sender(context);
695                         _bt_save_invocation_context(context, result, sender,
696                                         function_name, NULL);
697                 }
698                 break;
699         }
700         case BT_GET_BONDED_DEVICE: {
701                 bluetooth_device_address_t address = { {0} };
702
703                 __bt_service_get_parameters(in_param1,
704                                 &address, sizeof(bluetooth_device_address_t));
705
706                 result = _bt_get_bonded_device_info(&address);
707                 /* Save invocation */
708                 if (result == BLUETOOTH_ERROR_NONE) {
709                         char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
710                         if (!addr) {
711                                 result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
712                                 break;
713                         }
714
715                         _bt_convert_addr_type_to_string(addr, address.addr);
716                         sender = (char*)g_dbus_method_invocation_get_sender(context);
717                         _bt_save_invocation_context(context, result, sender,
718                                         function_name, addr);
719                 }
720                 break;
721         }
722         case BT_GET_PROFILE_CONNECTED_DEVICES: {
723                 char *uuid;
724                 uuid = (char *)g_variant_get_data(in_param1);
725                 result = _bt_get_profile_connected_devices(uuid);
726
727                 /* Save invocation */
728                 if (result == BLUETOOTH_ERROR_NONE) {
729                         sender = (char *)g_dbus_method_invocation_get_sender(context);
730                         _bt_save_invocation_context(context, result, sender,
731                                         function_name, NULL);
732                 }
733                 break;
734         }
735         case BT_SET_ALIAS: {
736                 bluetooth_device_address_t address = { {0} };
737                 const char *local_name;
738
739                 __bt_service_get_parameters(in_param1,
740                                 &address, sizeof(bluetooth_device_address_t));
741                 local_name = (const char *)g_variant_get_data(in_param2);
742
743                 result = _bt_set_alias(&address, local_name);
744                 break;
745         }
746         case BT_BOND_DEVICE: {
747                 bluetooth_device_address_t address = { {0} };
748
749                 __bt_service_get_parameters(in_param1,
750                                 &address, sizeof(bluetooth_device_address_t));
751                 result = _bt_bond_device(&address, BLUETOOTH_DEV_CONN_DEFAULT, out_param1);
752
753                 /* Save invocation */
754                 if (result == BLUETOOTH_ERROR_NONE) {
755                         char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
756                         _bt_convert_addr_type_to_string(addr, address.addr);
757                         sender = (char*)g_dbus_method_invocation_get_sender(context);
758                         _bt_save_invocation_context(context, result, sender,
759                                         function_name, (gpointer)addr);
760                 } else {
761                         bluetooth_device_info_t dev_info;
762
763                         memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
764                         memcpy(&dev_info.device_address, &address,
765                                         sizeof(bluetooth_device_address_t));
766                         g_array_append_vals(*out_param1, &dev_info,
767                                         sizeof(bluetooth_device_info_t));
768                 }
769                 break;
770         }
771         case BT_BOND_DEVICE_BY_TYPE: {
772                 bluetooth_device_address_t address = { {0} };
773                 unsigned short conn_type = 0;
774
775                 __bt_service_get_parameters(in_param1,
776                                 &address, sizeof(bluetooth_device_address_t));
777                 __bt_service_get_parameters(in_param2,
778                                 &conn_type, sizeof(unsigned short));
779
780                 result = _bt_bond_device(&address, conn_type, out_param1);
781                 /* Save invocation */
782                 if (result == BLUETOOTH_ERROR_NONE) {
783                         char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
784                         _bt_convert_addr_type_to_string(addr, address.addr);
785                         sender = (char*)g_dbus_method_invocation_get_sender(context);
786                         _bt_save_invocation_context(context, result, sender,
787                                         function_name, (gpointer)addr);
788                 } else {
789                         bluetooth_device_info_t dev_info;
790
791                         memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
792                         memcpy(&dev_info.device_address, &address,
793                                         sizeof(bluetooth_device_address_t));
794                         g_array_append_vals(*out_param1, &dev_info,
795                                         sizeof(bluetooth_device_info_t));
796                 }
797                 break;
798         }
799         case BT_UNBOND_DEVICE: {
800                 bluetooth_device_address_t address = { {0} };
801
802                 __bt_service_get_parameters(in_param1,
803                                 &address, sizeof(bluetooth_device_address_t));
804                 result = _bt_unbond_device(&address, out_param1);
805
806                 /* Save invocation */
807                 if (result == BLUETOOTH_ERROR_NONE) {
808                         char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
809                         _bt_convert_addr_type_to_string(addr, address.addr);
810                         sender = (char*)g_dbus_method_invocation_get_sender(context);
811                         _bt_save_invocation_context(context, result, sender,
812                                         function_name, (gpointer)addr);
813                 } else {
814                         g_array_append_vals(*out_param1, &address,
815                                         sizeof(bluetooth_device_address_t));
816                 }
817                 break;
818         }
819         case BT_CANCEL_BONDING:{
820                 result = _bt_cancel_bonding();
821                 break;
822         }
823         case BT_SEARCH_SERVICE: {
824                 bluetooth_device_address_t address = { {0} };
825                 __bt_service_get_parameters(in_param1,
826                                 &address, sizeof(bluetooth_device_address_t));
827                 result = _bt_search_device(&address);
828                 /* Save invocation */
829                 if (result == BLUETOOTH_ERROR_NONE) {
830                         char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
831                         _bt_convert_addr_type_to_string(addr, address.addr);
832                         sender = (char*)g_dbus_method_invocation_get_sender(context);
833                         _bt_save_invocation_context(context, result, sender,
834                                         function_name, (gpointer)addr);
835                 } else {
836                         bt_sdp_info_t sdp_info;
837
838                         memset(&sdp_info, 0x00, sizeof(bt_sdp_info_t));
839                         memcpy(&sdp_info.device_addr, &address,
840                                         sizeof(bluetooth_device_address_t));
841                         g_array_append_vals(*out_param1, &sdp_info, sizeof(bt_sdp_info_t));
842                 }
843                 break;
844         }
845         case BT_CANCEL_SEARCH_SERVICE: {
846                 result = _bt_cancel_search_device();
847                 break;
848         }
849         case BT_SET_PASSKEY_NOTIFICATION: {
850                 char *sender = NULL;
851                 gboolean enable;
852
853                 sender = (char *)g_dbus_method_invocation_get_sender(context);
854                 __bt_service_get_parameters(in_param1,
855                                 &enable, sizeof(gboolean));
856
857                 result = _bt_set_passkey_notification(sender, enable);
858                 break;
859         }
860         case BT_SET_PIN_CODE: {
861                 bluetooth_device_address_t address = { {0} };
862                 bluetooth_device_pin_code_t pin_code = { {0} };
863
864                 __bt_service_get_parameters(in_param1,
865                                 &address, sizeof(bluetooth_device_address_t));
866                 __bt_service_get_parameters(in_param2,
867                                 &pin_code, sizeof(bluetooth_device_pin_code_t));
868
869                 result = _bt_set_pin_code(&address, &pin_code);
870                 break;
871         }
872         case BT_UNSET_PIN_CODE: {
873                 bluetooth_device_address_t address = { {0} };
874
875                 __bt_service_get_parameters(in_param1,
876                                 &address, sizeof(bluetooth_device_address_t));
877
878                 result = _bt_unset_pin_code(&address);
879                 break;
880         }
881         case BT_PASSKEY_REPLY: {
882                 const char *passkey = NULL;
883                 gboolean authentication_reply = FALSE;
884                 passkey = g_variant_get_data(in_param1);
885                 __bt_service_get_parameters(in_param2,
886                                 &authentication_reply, sizeof(gboolean));
887                 result = _bt_passkey_reply(passkey, authentication_reply);
888                 break;
889         }
890         case BT_PASSKEY_CONFIRMATION_REPLY: {
891                 gboolean confirmation_reply = FALSE;
892                 __bt_service_get_parameters(in_param1,
893                                 &confirmation_reply, sizeof(gboolean));
894                 result = _bt_passkey_confirmation_reply(confirmation_reply);
895                 break;
896         }
897         case BT_GET_IS_ALIAS_SET: {
898                 bluetooth_device_address_t address = { {0} };
899
900                 __bt_service_get_parameters(in_param1,
901                                 &address, sizeof(bluetooth_device_address_t));
902
903                 result = _bt_is_alias_set(&address);
904                 if (result == BLUETOOTH_ERROR_NONE) {
905                         char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
906                         if (!addr) {
907                                 result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
908                                 break;
909                         }
910
911                         _bt_convert_addr_type_to_string(addr, address.addr);
912                         sender = (char*)g_dbus_method_invocation_get_sender(context);
913                         _bt_save_invocation_context(context, result, sender,
914                                         function_name, addr);
915                 }
916                 break;
917         }
918         case BT_SET_AUTHORIZATION: {
919                 bluetooth_device_address_t address = { {0} };
920                 gboolean authorize;
921                 __bt_service_get_parameters(in_param1,
922                                 &address, sizeof(bluetooth_device_address_t));
923                 __bt_service_get_parameters(in_param2,
924                                 &authorize, sizeof(gboolean));
925                 result = _bt_set_authorization(&address, authorize);
926                 break;
927         }
928         case BT_SET_LE_PRIVACY: {
929                gboolean set_privacy;
930                __bt_service_get_parameters(in_param1, &set_privacy,
931                                 sizeof(gboolean));
932                result = _bt_set_le_privacy(set_privacy);
933                break;
934         }
935         case BT_ADD_WHITE_LIST: {
936                 bluetooth_device_address_t address = { {0} };
937                 int address_type = 0;
938                 bool is_add = true;
939                 __bt_service_get_parameters(in_param1,
940                                 &address, sizeof(bluetooth_device_address_t));
941                 __bt_service_get_parameters(in_param2,
942                                 &address_type, sizeof(int));
943                 result = _bt_set_white_list(&address, address_type, is_add);
944                 break;
945         }
946         case BT_REMOVE_WHITE_LIST: {
947                 bluetooth_device_address_t address = { {0} };
948                 int address_type = 0;
949                 bool is_add = false;
950                 __bt_service_get_parameters(in_param1,
951                                 &address, sizeof(bluetooth_device_address_t));
952                 __bt_service_get_parameters(in_param2,
953                                 &address_type, sizeof(int));
954                 result = _bt_set_white_list(&address, address_type, is_add);
955                 break;
956         }
957         case BT_UPDATE_LE_CONNECTION_MODE: {
958                 char *sender = NULL;
959                 bluetooth_device_address_t remote_address = { { 0 } };
960                 bluetooth_le_connection_param_t parameters = { 0 };
961                 bluetooth_le_connection_mode_t mode = BLUETOOTH_LE_CONNECTION_MODE_BALANCED;
962
963                 __bt_service_get_parameters(in_param1, &remote_address,
964                                 sizeof(bluetooth_device_address_t));
965                 __bt_service_get_parameters(in_param2, &mode,
966                                 sizeof(bluetooth_le_connection_mode_t));
967
968                 result = _bt_get_le_connection_parameter(mode, &parameters);
969                 if (result != BLUETOOTH_ERROR_NONE)
970                         break;
971
972                 sender = (char *)g_dbus_method_invocation_get_sender(context);
973
974                 result = _bt_le_connection_update(sender,
975                                 remote_address.addr,
976                                 parameters.interval_min,
977                                 parameters.interval_max,
978                                 parameters.latency,
979                                 parameters.timeout);
980                 break;
981         }
982         case BT_SET_MANUFACTURER_DATA: {
983                 bluetooth_manufacturer_data_t m_data = { 0 };
984                 __bt_service_get_parameters(in_param1,
985                                 &m_data, sizeof(bluetooth_manufacturer_data_t));
986                 result = _bt_set_manufacturer_data(&m_data);
987                 break;
988         }
989
990         case BT_IS_DEVICE_CONNECTED: {
991                 bluetooth_device_address_t address = { {0} };
992                 gboolean connected = FALSE;
993                 int service_type;
994
995                 __bt_service_get_parameters(in_param1,
996                                 &address, sizeof(bluetooth_device_address_t));
997                 __bt_service_get_parameters(in_param2,
998                                 &service_type, sizeof(int));
999
1000 #if defined(TIZEN_FEATURE_BT_PAN_NAP)
1001                 if ((service_type == BLUETOOTH_NAP_SERVICE) || (service_type == BLUETOOTH_NAP_SERVER_SERVICE))
1002                         connected = _bt_is_nap_panu_device_connected(&address, service_type);
1003                 else
1004                         connected = _bt_is_device_connected(&address, service_type);
1005 #else
1006                 connected = _bt_is_device_connected(&address, service_type);
1007 #endif
1008                 BT_INFO("is_connected: %d", connected);
1009                 g_array_append_vals(*out_param1, &connected, sizeof(gboolean));
1010                 break;
1011         }
1012         case BT_GET_CONNECTED_LINK_TYPE: {
1013                 bluetooth_device_address_t address = { {0} };
1014
1015                 __bt_service_get_parameters(in_param1,
1016                                 &address, sizeof(bluetooth_device_address_t));
1017
1018                 result = _bt_get_connected_link(&address);
1019                 if (result == BLUETOOTH_ERROR_NONE) {
1020                         char *addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
1021                         if (!addr) {
1022                                 result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
1023                                 break;
1024                         }
1025
1026                         _bt_convert_addr_type_to_string(addr, address.addr);
1027                         sender = (char*)g_dbus_method_invocation_get_sender(context);
1028                         _bt_save_invocation_context(context, result, sender,
1029                                         function_name, addr);
1030                 }
1031                 break;
1032         }
1033         case BT_IS_SCAN_FILTER_SUPPORTED:{
1034                 int is_supported = 0;
1035
1036                 if (_bt_is_scan_filter_supported() == TRUE)
1037                         is_supported = 1;
1038
1039                 g_array_append_vals(*out_param1,
1040                                 &is_supported, sizeof(int));
1041
1042                 break;
1043         }
1044         case BT_ENABLE_RSSI: {
1045                 bluetooth_device_address_t bd_addr;
1046                 int link_type;
1047                 bt_rssi_threshold_t rssi_threshold;
1048                 int low_threshold;
1049                 int in_range_threshold;
1050                 int high_threshold;
1051
1052                 BT_DBG("Enable RSSI");
1053
1054                 __bt_service_get_parameters(in_param1,
1055                                 &bd_addr, sizeof(bluetooth_device_address_t));
1056                 __bt_service_get_parameters(in_param2,
1057                                 &link_type, sizeof(int));
1058                 __bt_service_get_parameters(in_param3,
1059                                 &rssi_threshold, sizeof(bt_rssi_threshold_t));
1060
1061                 low_threshold = rssi_threshold.low_threshold;
1062                 in_range_threshold = rssi_threshold.in_range_threshold;
1063                 high_threshold = rssi_threshold.high_threshold;
1064
1065                 result = _bt_enable_rssi(&bd_addr, link_type, low_threshold,
1066                                 in_range_threshold, high_threshold);
1067                 break;
1068         }
1069         case BT_GET_RSSI: {
1070                 int link_type;
1071                 bluetooth_device_address_t bd_addr;
1072
1073                 BT_DBG("Get RSSI Strength");
1074
1075                 __bt_service_get_parameters(in_param1,
1076                                 &bd_addr, sizeof(bluetooth_device_address_t));
1077                 __bt_service_get_parameters(in_param2,
1078                                 &link_type, sizeof(int));
1079
1080                 result = _bt_get_rssi_strength(&bd_addr, link_type);
1081                 break;
1082         }
1083         case BT_SET_PROFILE_TRUSTED: {
1084                 bluetooth_device_address_t bd_addr = { {0} };
1085                 int profile;
1086                 int trust;
1087
1088                 __bt_service_get_parameters(in_param1, &bd_addr,
1089                                 sizeof(bluetooth_device_address_t));
1090                 __bt_service_get_parameters(in_param2, &profile, sizeof(int));
1091                 __bt_service_get_parameters(in_param3, &trust, sizeof(int));
1092
1093                 result = _bt_set_trust_profile(&bd_addr, profile, trust);
1094                 break;
1095         }
1096         case BT_GET_PROFILE_TRUSTED: {
1097                 bluetooth_device_address_t bd_addr = { {0} };
1098                 int profile;
1099                 guint trusted_profile = 0;
1100
1101                 __bt_service_get_parameters(in_param1, &bd_addr,
1102                                 sizeof(bluetooth_device_address_t));
1103                 __bt_service_get_parameters(in_param2, &profile, sizeof(int));
1104
1105                 result = _bt_get_trust_profile(&bd_addr, profile, &trusted_profile);
1106                 BT_DBG("TRUST %d", trusted_profile);
1107                 if (result == BLUETOOTH_ERROR_NONE) {
1108                         g_array_append_vals(*out_param1, &trusted_profile,
1109                                         sizeof(guint));
1110                 }
1111
1112                 break;
1113         }
1114         case BT_HID_CONNECT: {
1115                 bluetooth_device_address_t address = { {0} };
1116
1117                 __bt_service_get_parameters(in_param1,
1118                                 &address, sizeof(bluetooth_device_address_t));
1119
1120                 result = _bt_hid_connect(&address);
1121                 if (result != BLUETOOTH_ERROR_NONE) {
1122                         g_array_append_vals(*out_param1, &address,
1123                                         sizeof(bluetooth_device_address_t));
1124                 } else {
1125                         char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1126                         _bt_convert_addr_type_to_string(addr, address.addr);
1127                         sender = (char*)g_dbus_method_invocation_get_sender(context);
1128                         _bt_save_invocation_context(context, result, sender,
1129                                         function_name, (gpointer)addr);
1130                 }
1131                 break;
1132         }
1133         case BT_HID_DISCONNECT: {
1134                 bluetooth_device_address_t address = { {0} };
1135
1136                 __bt_service_get_parameters(in_param1,
1137                                 &address, sizeof(bluetooth_device_address_t));
1138
1139                 result = _bt_hid_disconnect(&address);
1140                 if (result != BLUETOOTH_ERROR_NONE) {
1141                         g_array_append_vals(*out_param1, &address,
1142                                         sizeof(bluetooth_device_address_t));
1143                 } else {
1144                         char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1145                         _bt_convert_addr_type_to_string(addr, address.addr);
1146                         sender = (char*)g_dbus_method_invocation_get_sender(context);
1147                         _bt_save_invocation_context(context, result, sender,
1148                                         function_name, (gpointer)addr);
1149                 }
1150                 break;
1151         }
1152         case BT_DPM_SET_ALLOW_BT_MODE: {
1153                 dpm_bt_allow_t value = DPM_BT_ERROR;
1154
1155                 __bt_service_get_parameters(in_param1, &value,
1156                                 sizeof(int));
1157
1158                 result = _bt_dpm_set_allow_bluetooth_mode(value);
1159                 break;
1160         }
1161         case BT_DPM_GET_ALLOW_BT_MODE: {
1162                 int value = DPM_BT_ERROR;
1163
1164                 result = _bt_dpm_get_allow_bluetooth_mode(&value);
1165                 g_array_append_vals(*out_param1, &value, sizeof(int));
1166                 break;
1167         }
1168         case BT_DPM_SET_DEVICE_RESTRITION: {
1169                 dpm_status_t value = DPM_STATUS_ERROR;
1170
1171                 __bt_service_get_parameters(in_param1, &value,
1172                                 sizeof(int));
1173
1174                 result = _bt_dpm_activate_bluetooth_device_restriction(value);
1175                 break;
1176         }
1177         case BT_DPM_GET_DEVICE_RESTRITION: {
1178                 int value = DPM_STATUS_ERROR;
1179
1180                 result = _bt_dpm_is_bluetooth_device_restriction_active(&value);
1181                 g_array_append_vals(*out_param1, &value, sizeof(int));
1182                 break;
1183         }
1184         case BT_DPM_SET_UUID_RESTRITION: {
1185                 dpm_status_t value = DPM_STATUS_ERROR;
1186
1187                 __bt_service_get_parameters(in_param1, &value,
1188                                 sizeof(int));
1189
1190                 result = _bt_dpm_activate_bluetoooth_uuid_restriction(value);
1191                 break;
1192         }
1193         case BT_DPM_GET_UUID_RESTRITION: {
1194                 int value = DPM_STATUS_ERROR;
1195
1196                 result = _bt_dpm_is_bluetooth_uuid_restriction_active(&value);
1197                 g_array_append_vals(*out_param1, &value, sizeof(int));
1198                 break;
1199         }
1200         case BT_DPM_ADD_DEVICES_BLACKLIST: {
1201                 bluetooth_device_address_t address = { {0} };
1202
1203                 __bt_service_get_parameters(in_param1, &address,
1204                         sizeof(bluetooth_device_address_t));
1205
1206                 result = _bt_dpm_add_bluetooth_devices_to_blacklist(&address);
1207                 break;
1208         }
1209         case BT_DPM_ADD_DEVICES_WHITELIST: {
1210                 bluetooth_device_address_t address = { {0} };
1211
1212                 __bt_service_get_parameters(in_param1, &address,
1213                         sizeof(bluetooth_device_address_t));
1214
1215                 result = _bt_dpm_add_bluetooth_devices_to_whitelist(&address);
1216                 break;
1217         }
1218         case BT_DPM_ADD_UUIDS_BLACKLIST: {
1219                 const char *uuid = NULL;
1220
1221                 uuid = g_variant_get_data(in_param1);
1222
1223                 result = _bt_dpm_add_bluetooth_uuids_to_blacklist(uuid);
1224                 break;
1225         }
1226         case BT_DPM_ADD_UUIDS_WHITELIST: {
1227                 const char *uuid = NULL;
1228
1229                 uuid = g_variant_get_data(in_param1);
1230
1231                 result = _bt_dpm_add_bluetooth_uuids_to_whitelist(uuid);
1232                 break;
1233         }
1234         case BT_DPM_CLEAR_DEVICES_BLACKLIST: {
1235                 result = _bt_dpm_clear_bluetooth_devices_from_blacklist();
1236                 break;
1237         }
1238         case BT_DPM_CLEAR_DEVICES_WHITELIST: {
1239                 result = _bt_dpm_clear_bluetooth_devices_from_whitelist();
1240                 break;
1241         }
1242         case BT_DPM_CLEAR_UUIDS_BLACKLIST: {
1243                 result = _bt_dpm_clear_bluetooth_uuids_from_blacklist();
1244                 break;
1245         }
1246         case BT_DPM_CLEAR_UUIDS_WHITELIST: {
1247                 result = _bt_dpm_clear_bluetooth_uuids_from_whitelist();
1248                 break;
1249         }
1250         case BT_DPM_REMOVE_DEVICE_BLACKLIST: {
1251                 bluetooth_device_address_t address = { {0} };
1252
1253                 __bt_service_get_parameters(in_param1, &address,
1254                         sizeof(bluetooth_device_address_t));
1255
1256                 result = _bt_dpm_remove_bluetooth_devices_from_blacklist(&address);
1257                 break;
1258         }
1259         case BT_DPM_REMOVE_DEVICE_WHITELIST: {
1260                 bluetooth_device_address_t address = { {0} };
1261
1262                 __bt_service_get_parameters(in_param1, &address,
1263                         sizeof(bluetooth_device_address_t));
1264
1265                 result = _bt_dpm_remove_bluetooth_devices_from_whitelist(&address);
1266                 break;
1267         }
1268         case BT_DPM_REMOVE_UUID_BLACKLIST: {
1269                 const char *uuid = NULL;
1270
1271                 uuid = g_variant_get_data(in_param1);
1272
1273                 result = _bt_dpm_remove_bluetooth_uuids_from_blacklist(uuid);
1274                 break;
1275         }
1276         case BT_DPM_REMOVE_UUID_WHITELIST: {
1277                 const char *uuid = NULL;
1278
1279                 uuid = g_variant_get_data(in_param1);
1280
1281                 result = _bt_dpm_remove_bluetooth_uuids_from_whitelist(uuid);
1282
1283                 break;
1284         }
1285         case BT_DPM_GET_DEVICES_BLACKLIST: {
1286                 result = _bt_dpm_get_bluetooth_devices_from_blacklist(out_param1);
1287                 break;
1288         }
1289         case BT_DPM_GET_DEVICES_WHITELIST: {
1290                 result = _bt_dpm_get_bluetooth_devices_from_whitelist(out_param1);
1291                 break;
1292         }
1293         case BT_DPM_GET_UUIDS_BLACKLIST: {
1294                 result = _bt_dpm_get_bluetooth_uuids_from_blacklist(out_param1);
1295                 break;
1296         }
1297         case BT_DPM_GET_UUIDS_WHITELIST: {
1298                 result = _bt_dpm_get_bluetooth_uuids_from_whitelist(out_param1);
1299                 break;
1300         }
1301         case BT_DPM_SET_ALLOW_OUTGOING_CALL: {
1302                 dpm_status_t value = DPM_STATUS_ERROR;
1303
1304                 __bt_service_get_parameters(in_param1, &value,
1305                                 sizeof(int));
1306
1307                 result = _bt_dpm_set_allow_bluetooth_outgoing_call(value);
1308
1309                 break;
1310         }
1311         case BT_DPM_GET_ALLOW_OUTGOING_CALL: {
1312                 int value = DPM_STATUS_ERROR;
1313
1314                 result = _bt_dpm_get_allow_bluetooth_outgoing_call(&value);
1315                 g_array_append_vals(*out_param1, &value, sizeof(int));
1316                 break;
1317         }
1318         case BT_DPM_SET_PAIRING_STATE: {
1319                 dpm_status_t value = DPM_STATUS_ERROR;
1320
1321                 __bt_service_get_parameters(in_param1, &value,
1322                                 sizeof(int));
1323
1324                 result = _bt_dpm_set_bluetooth_pairing_state(value);
1325
1326                 break;
1327         }
1328         case BT_DPM_GET_PAIRING_STATE: {
1329                 int value = DPM_STATUS_ERROR;
1330
1331                 result = _bt_dpm_get_bluetooth_pairing_state(&value);
1332                 g_array_append_vals(*out_param1, &value, sizeof(int));
1333                 break;
1334         }
1335         case BT_DPM_SET_PROFILE_STATE: {
1336                 int value = DPM_STATUS_ERROR;
1337                 int profile = DPM_PROFILE_NONE;
1338
1339                 __bt_service_get_parameters(in_param1, &profile,
1340                                 sizeof(int));
1341                 __bt_service_get_parameters(in_param2, &value,
1342                                 sizeof(int));
1343
1344                 result = _bt_dpm_set_bluetooth_profile_state(profile, value);
1345
1346                 break;
1347         }
1348         case BT_DPM_GET_PROFILE_STATE: {
1349                 int value = DPM_STATUS_ERROR;
1350                 int profile = DPM_PROFILE_NONE;
1351
1352                 __bt_service_get_parameters(in_param1, &profile,
1353                                 sizeof(int));
1354
1355                 result = _bt_dpm_get_bluetooth_profile_state(profile, &value);
1356                 g_array_append_vals(*out_param1, &value, sizeof(int));
1357                 break;
1358         }
1359         case BT_DPM_SET_DESKROP_CONNECTIVITY_STATE: {
1360                 int value = DPM_BT_ERROR;
1361
1362                 __bt_service_get_parameters(in_param1, &value,
1363                                 sizeof(int));
1364
1365                 result = _bt_dpm_set_bluetooth_desktop_connectivity_state(value);
1366
1367                 break;
1368         }
1369         case BT_DPM_GET_DESKROP_CONNECTIVITY_STATE: {
1370                 int value = DPM_STATUS_ERROR;
1371
1372                 result = _bt_dpm_get_bluetooth_desktop_connectivity_state(&value);
1373                 g_array_append_vals(*out_param1, &value, sizeof(int));
1374                 break;
1375         }
1376         case BT_DPM_SET_DISCOVERABLE_STATE: {
1377                 int value = DPM_STATUS_ERROR;
1378
1379                 __bt_service_get_parameters(in_param1, &value,
1380                                 sizeof(int));
1381
1382                 result = _bt_dpm_set_bluetooth_discoverable_state(value);
1383
1384                 break;
1385         }
1386         case BT_DPM_GET_DISCOVERABLE_STATE: {
1387                 int value = DPM_STATUS_ERROR;
1388
1389                 result = _bt_dpm_get_bluetooth_discoverable_state(&value);
1390                 g_array_append_vals(*out_param1, &value, sizeof(int));
1391                 break;
1392         }
1393         case BT_DPM_SET_LIMITED_DISCOVERABLE_STATE: {
1394                 int value = DPM_STATUS_ERROR;
1395
1396                 __bt_service_get_parameters(in_param1, &value,
1397                                 sizeof(int));
1398
1399                 result = _bt_dpm_set_bluetooth_limited_discoverable_state(value);
1400
1401                 break;
1402         }
1403         case BT_DPM_GET_LIMITED_DISCOVERABLE_STATE: {
1404                 int value = DPM_STATUS_ERROR;
1405
1406                 result = _bt_dpm_get_bluetooth_limited_discoverable_state(&value);
1407                 g_array_append_vals(*out_param1, &value, sizeof(int));
1408                 break;
1409         }
1410         case BT_DPM_SET_DATA_TRANSFER_STATE: {
1411                 int value = DPM_STATUS_ERROR;
1412
1413                 __bt_service_get_parameters(in_param1, &value,
1414                                 sizeof(int));
1415
1416                 result = _bt_dpm_set_bluetooth_data_transfer_state(value);
1417
1418                 break;
1419         }
1420         case BT_DPM_GET_DATA_TRANSFER_STATE: {
1421                 int value = DPM_STATUS_ERROR;
1422
1423                 result = _bt_dpm_get_allow_bluetooth_data_transfer_state(&value);
1424                 g_array_append_vals(*out_param1, &value, sizeof(int));
1425                 break;
1426         }
1427         case BT_RFCOMM_CLIENT_CONNECT: {
1428                 bluetooth_device_address_t address = { {0} };
1429                 char *input_string;
1430                 int connect_type;
1431
1432                 __bt_service_get_parameters(in_param1,
1433                                 &address, sizeof(bluetooth_device_address_t));
1434                 input_string = (char *)g_variant_get_data(in_param2);
1435                 __bt_service_get_parameters(in_param3, &connect_type, sizeof(int));
1436
1437                 if (connect_type == BT_RFCOMM_UUID)
1438                         result = _bt_rfcomm_connect_using_uuid(&address, input_string);
1439                 else
1440                         result = _bt_rfcomm_connect_using_channel(&address, input_string);
1441
1442                 if (result != BLUETOOTH_ERROR_NONE) {
1443                         bluetooth_rfcomm_connection_t conn_info;
1444
1445                         BT_ERR("BT_RFCOMM_CLIENT_CONNECT failed, send error");
1446                         memset(&conn_info, 0x00, sizeof(bluetooth_rfcomm_connection_t));
1447                         if (connect_type == BT_RFCOMM_UUID)
1448                                 g_strlcpy(conn_info.uuid, input_string, BLUETOOTH_UUID_STRING_MAX);
1449                         else
1450                                 g_strlcpy(conn_info.uuid, "not_used", BLUETOOTH_UUID_STRING_MAX);
1451
1452                         conn_info.device_role = RFCOMM_ROLE_CLIENT;
1453                         conn_info.socket_fd = -1;
1454                         g_array_append_vals(*out_param1, &conn_info,
1455                                         sizeof(bluetooth_rfcomm_connection_t));
1456                 } else {
1457                         char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1458                         _bt_convert_addr_type_to_string(addr, address.addr);
1459                         sender = (char*)g_dbus_method_invocation_get_sender(context);
1460                         _bt_save_invocation_context(context, result, sender, function_name, addr);
1461                 }
1462                 break;
1463         }
1464         case BT_RFCOMM_SOCKET_DISCONNECT: {
1465                 /*
1466                  * Bluetooth RFCOMM socket disconnection will be done from bt-api, call to bt-service
1467                  * is only used for privilege check, so return BLUETOOTH_ERROR_NONE from here.
1468                  */
1469                 result = BLUETOOTH_ERROR_NONE;
1470                 break;
1471         }
1472         case BT_RFCOMM_SOCKET_WRITE: {
1473                 /*
1474                  * This call to bt-service is only used for privilege check, so return
1475                  * BLUETOOTH_ERROR_NONE from here.
1476                  */
1477                 result = BLUETOOTH_ERROR_NONE;
1478                 break;
1479         }
1480         case BT_RFCOMM_CREATE_SOCKET: {
1481                 /*
1482                  * This call to bt-service is only used for privilege check, so return
1483                  * BLUETOOTH_ERROR_NONE from here.
1484                  */
1485                 result = BLUETOOTH_ERROR_NONE;
1486                 break;
1487         }
1488         case BT_RFCOMM_LISTEN_AND_ACCEPT: {
1489                 char *uuid;
1490                 int socket_fd = -1;
1491
1492                 sender = (char *)g_dbus_method_invocation_get_sender(context);
1493                 uuid = (char *)g_variant_get_data(in_param1);
1494
1495                 result = _bt_rfcomm_socket_listen(sender, uuid, true);
1496                 if (result > 0) {
1497                         result = BLUETOOTH_ERROR_NONE;
1498                         _bt_save_invocation_context(context,
1499                                         result, sender, function_name, NULL);
1500                 } else {
1501                         g_array_append_vals(*out_param1, &socket_fd, sizeof(int));
1502                 }
1503                 break;
1504         }
1505         case BT_RFCOMM_LISTEN: {
1506                 char *uuid;
1507                 int socket_fd = -1;
1508
1509                 sender = (char *)g_dbus_method_invocation_get_sender(context);
1510                 uuid = (char *)g_variant_get_data(in_param1);
1511
1512                 result = _bt_rfcomm_socket_listen(sender, uuid, false);
1513                 if (result > 0) {
1514                         result = BLUETOOTH_ERROR_NONE;
1515                         _bt_save_invocation_context(context,
1516                                         result, sender, function_name, NULL);
1517                 } else {
1518                         g_array_append_vals(*out_param1, &socket_fd, sizeof(int));
1519                 }
1520                 break;
1521         }
1522         case BT_RFCOMM_ACCEPT_CONNECTION: {
1523                 char *address;
1524
1525                 address = (char *)g_variant_get_data(in_param1);
1526                 result = _bt_rfcomm_reply_conn_authorization(address, TRUE);
1527                 break;
1528         }
1529         case BT_RFCOMM_REJECT_CONNECTION: {
1530                 char *address;
1531
1532                 address = (char *)g_variant_get_data(in_param1);
1533                 result = _bt_rfcomm_reply_conn_authorization(address, FALSE);
1534                 break;
1535         }
1536         case BT_RFCOMM_REMOVE_SOCKET: {
1537                 /*
1538                  * This call to bt-service is only used for privilege check, so return
1539                  * BLUETOOTH_ERROR_NONE from here.
1540                  */
1541                 result = BLUETOOTH_ERROR_NONE;
1542                 break;
1543         }
1544         case BT_RFCOMM_SEND_RX_DETAILS: {
1545                 uid_t uid;
1546                 pid_t pid;
1547                 int size;
1548                 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
1549                 __bt_service_get_parameters(in_param2, &pid, sizeof(pid_t));
1550                 __bt_service_get_parameters(in_param3, &size, sizeof(unsigned int));
1551                 _bt_bm_add_transaction_details(uid, pid, size, RX_DATA);
1552                 break;
1553         }
1554         case BT_RFCOMM_SEND_TX_DETAILS: {
1555                 uid_t uid;
1556                 pid_t pid;
1557                 int size;
1558                 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
1559                 __bt_service_get_parameters(in_param2, &pid, sizeof(pid_t));
1560                 __bt_service_get_parameters(in_param3, &size, sizeof(unsigned int));
1561                 _bt_bm_add_transaction_details(uid, pid, size, TX_DATA);
1562                 break;
1563         }
1564         case BT_RFCOMM_UPDATE_CONNECTION_INFO: {
1565                 gboolean connected = FALSE;
1566                 int socket_fd = -1;
1567                 int role = RFCOMM_ROLE_SERVER;
1568
1569                 sender = (char *)g_dbus_method_invocation_get_sender(context);
1570
1571                 __bt_service_get_parameters(in_param1, &role, sizeof(int));
1572                 __bt_service_get_parameters(in_param2, &connected, sizeof(gboolean));
1573                 __bt_service_get_parameters(in_param3, &socket_fd, sizeof(int));
1574
1575                 if (connected == TRUE)
1576                         result = _bt_rfcomm_conn_added(sender, role, socket_fd);
1577                 else
1578                         result = _bt_rfcomm_conn_removed(sender, role, socket_fd);
1579
1580                 break;
1581         }
1582         case BT_AUDIO_SELECT_ROLE: {
1583                 bluetooth_audio_role_t role;
1584
1585                 __bt_service_get_parameters(in_param1,
1586                                 &role, sizeof(bluetooth_audio_role_t));
1587
1588                 result = _bt_audio_select_role(role);
1589                 if (result == BLUETOOTH_ERROR_NONE) {
1590                         sender = (char*)g_dbus_method_invocation_get_sender(context);
1591                         _bt_save_invocation_context(context, result, sender,
1592                                         function_name, NULL);
1593                 }
1594                 break;
1595         }
1596         case BT_AUDIO_SET_ABSOLUTE_VOLUME: {
1597                 unsigned int volume = 0;
1598
1599                 __bt_service_get_parameters(in_param1,
1600                                 &volume, sizeof(unsigned int));
1601
1602                 result = _bt_audio_set_absolute_volume(volume);
1603                 break;
1604         }
1605         case BT_AUDIO_GET_ABSOLUTE_VOLUME: {
1606                 unsigned int volume = 0;
1607
1608                 result = _bt_audio_get_absolute_volume(&volume);
1609                 g_array_append_vals(*out_param1, &volume, sizeof(unsigned int));
1610                 break;
1611         }
1612         case BT_AUDIO_IS_AVC_ACTIVATED: {
1613                 bool activated = 0;
1614
1615                 result = _bt_audio_is_avc_activated(&activated);
1616                 g_array_append_vals(*out_param1, &activated, sizeof(bool));
1617                 break;
1618         }
1619         case BT_AV_CONNECT: {
1620                 bluetooth_device_address_t address = { {0} };
1621                 __bt_service_get_parameters(in_param1,
1622                                 &address, sizeof(bluetooth_device_address_t));
1623
1624                 result = _bt_audio_is_profile_connection_in_progress(BT_AV_CONNECT, &address);
1625
1626                 if (result == BLUETOOTH_ERROR_NONE)
1627                         result = _bt_audio_connect(BT_AUDIO_A2DP, &address);
1628
1629                 if (result != BLUETOOTH_ERROR_NONE) {
1630                         BT_ERR("AV Connect Request has failed to execute");
1631                         char addr[BT_ADDRESS_STRING_SIZE];
1632                         _bt_convert_addr_type_to_string(addr, address.addr);
1633                         g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1634                 } else {
1635                         char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1636                         _bt_convert_addr_type_to_string(addr, address.addr);
1637                         sender = (char*)g_dbus_method_invocation_get_sender(context);
1638                         _bt_save_invocation_context(context, result, sender,
1639                                         function_name, (gpointer)addr);
1640                 }
1641                 break;
1642         }
1643         case BT_AUDIO_CONNECT: {
1644                 bluetooth_device_address_t address = { {0} };
1645                 __bt_service_get_parameters(in_param1,
1646                                 &address, sizeof(bluetooth_device_address_t));
1647
1648                 result = _bt_audio_is_profile_connection_in_progress(BT_AUDIO_CONNECT, &address);
1649
1650                 if (result == BLUETOOTH_ERROR_NONE)
1651                         result = _bt_audio_connect(BT_AUDIO_ALL, &address);
1652
1653                 if (result != BLUETOOTH_ERROR_NONE) {
1654                         BT_ERR("Audio All Connect Request has failed to execute");
1655                         char addr[BT_ADDRESS_STRING_SIZE];
1656                         _bt_convert_addr_type_to_string(addr, address.addr);
1657                         g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1658                 } else {
1659                         char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1660                         _bt_convert_addr_type_to_string(addr, address.addr);
1661                         sender = (char*)g_dbus_method_invocation_get_sender(context);
1662                         _bt_save_invocation_context(context, result, sender,
1663                                         function_name, (gpointer)addr);
1664                 }
1665                 break;
1666         }
1667         case BT_AUDIO_DISCONNECT: {
1668                 bluetooth_device_address_t address = { {0} };
1669                 __bt_service_get_parameters(in_param1,
1670                                 &address, sizeof(bluetooth_device_address_t));
1671
1672                 result = _bt_audio_disconnect(BT_AUDIO_ALL, &address);
1673
1674                 if (result != BLUETOOTH_ERROR_NONE) {
1675                         char addr[BT_ADDRESS_STRING_SIZE];
1676                         _bt_convert_addr_type_to_string(addr, address.addr);
1677                         g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1678                 } else {
1679                         char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1680                         _bt_convert_addr_type_to_string(addr, address.addr);
1681                         sender = (char*)g_dbus_method_invocation_get_sender(context);
1682                         _bt_save_invocation_context(context, result, sender,
1683                                         function_name, (gpointer)addr);
1684                 }
1685                 break;
1686         }
1687         case BT_AV_DISCONNECT: {
1688                 bluetooth_device_address_t address = { {0} };
1689                 __bt_service_get_parameters(in_param1,
1690                                 &address, sizeof(bluetooth_device_address_t));
1691
1692                 result = _bt_audio_disconnect(BT_AUDIO_A2DP, &address);
1693
1694                 if (result != BLUETOOTH_ERROR_NONE) {
1695                         char addr[BT_ADDRESS_STRING_SIZE];
1696                         _bt_convert_addr_type_to_string(addr, address.addr);
1697                         g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1698                 } else {
1699                         char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1700                         _bt_convert_addr_type_to_string(addr, address.addr);
1701                         sender = (char*)g_dbus_method_invocation_get_sender(context);
1702                         _bt_save_invocation_context(context, result, sender,
1703                                         function_name, (gpointer)addr);
1704                 }
1705                 break;
1706         }
1707         case BT_AG_CONNECT: {
1708                 bluetooth_device_address_t address = { {0} };
1709                 __bt_service_get_parameters(in_param1,
1710                                 &address, sizeof(bluetooth_device_address_t));
1711
1712                 result = _bt_audio_is_profile_connection_in_progress(BT_AG_CONNECT, &address);
1713
1714                 if (result == BLUETOOTH_ERROR_NONE)
1715                         result = _bt_audio_connect(BT_AUDIO_HSP, &address);
1716
1717                 if (result != BLUETOOTH_ERROR_NONE) {
1718                         BT_ERR("AG Connect Request has failed to execute");
1719                         char addr[BT_ADDRESS_STRING_SIZE];
1720                         _bt_convert_addr_type_to_string(addr, address.addr);
1721                         g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1722                 } else {
1723                         char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1724                         _bt_convert_addr_type_to_string(addr, address.addr);
1725                         sender = (char*)g_dbus_method_invocation_get_sender(context);
1726                         _bt_save_invocation_context(context, result, sender,
1727                                         function_name, (gpointer)addr);
1728                 }
1729                 break;
1730         }
1731         case BT_AG_DISCONNECT: {
1732                 bluetooth_device_address_t address = { {0} };
1733
1734                 __bt_service_get_parameters(in_param1,
1735                                 &address, sizeof(bluetooth_device_address_t));
1736
1737                 result = _bt_audio_disconnect(BT_AUDIO_HSP, &address);
1738
1739                 if (result != BLUETOOTH_ERROR_NONE) {
1740                         char addr[BT_ADDRESS_STRING_SIZE];
1741                         _bt_convert_addr_type_to_string(addr, address.addr);
1742                         g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1743                 } else {
1744                         char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1745                         _bt_convert_addr_type_to_string(addr, address.addr);
1746                         sender = (char*)g_dbus_method_invocation_get_sender(context);
1747                         _bt_save_invocation_context(context, result, sender,
1748                                         function_name, (gpointer)addr);
1749                 }
1750                 break;
1751         }
1752         case BT_AV_SOURCE_CONNECT: {
1753                 bluetooth_device_address_t address = { {0} };
1754
1755                 __bt_service_get_parameters(in_param1,
1756                                 &address, sizeof(bluetooth_device_address_t));
1757
1758                 result = _bt_audio_is_profile_connection_in_progress(BT_AV_SOURCE_CONNECT,
1759                                 &address);
1760
1761                 if (result == BLUETOOTH_ERROR_NONE)
1762                         result = _bt_audio_connect(BT_AUDIO_A2DP_SOURCE, &address);
1763
1764                 if (result != BLUETOOTH_ERROR_NONE) {
1765                         BT_ERR("A2DP Source Connect Request has failed to execute");
1766                         char addr[BT_ADDRESS_STRING_SIZE];
1767                         _bt_convert_addr_type_to_string(addr, address.addr);
1768                         g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1769                 } else {
1770                         char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1771                         _bt_convert_addr_type_to_string(addr, address.addr);
1772                         sender = (char*)g_dbus_method_invocation_get_sender(context);
1773                         _bt_save_invocation_context(context, result, sender,
1774                                         function_name, (gpointer)addr);
1775                 }
1776                 break;
1777         }
1778         case BT_AV_SOURCE_DISCONNECT: {
1779                 bluetooth_device_address_t address = { {0} };
1780
1781                 __bt_service_get_parameters(in_param1,
1782                                 &address, sizeof(bluetooth_device_address_t));
1783
1784                 result = _bt_audio_disconnect(BT_AUDIO_A2DP_SOURCE, &address);
1785                 if (result != BLUETOOTH_ERROR_NONE) {
1786                         char addr[BT_ADDRESS_STRING_SIZE];
1787                         _bt_convert_addr_type_to_string(addr, address.addr);
1788                         g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1789                 } else {
1790                         char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1791                         _bt_convert_addr_type_to_string(addr, address.addr);
1792                         sender = (char*)g_dbus_method_invocation_get_sender(context);
1793                         _bt_save_invocation_context(context, result, sender,
1794                                         function_name, (gpointer)addr);
1795                 }
1796                 break;
1797         }
1798         case BT_HF_CONNECT: {
1799                 bluetooth_device_address_t address = { {0} };
1800
1801                 __bt_service_get_parameters(in_param1,
1802                                 &address, sizeof(bluetooth_device_address_t));
1803
1804                 result = _bt_audio_is_profile_connection_in_progress(BT_HF_CONNECT,
1805                                 &address);
1806
1807                 if (result == BLUETOOTH_ERROR_NONE)
1808                         result = _bt_hf_connect(&address);
1809
1810                 if (result != BLUETOOTH_ERROR_NONE) {
1811                         BT_ERR("HF Connect Request has failed to execute");
1812                         char addr[BT_ADDRESS_STRING_SIZE];
1813                         _bt_convert_addr_type_to_string(addr, address.addr);
1814                         g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1815                 } else {
1816                         char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1817                         _bt_convert_addr_type_to_string(addr, address.addr);
1818                         sender = (char*)g_dbus_method_invocation_get_sender(context);
1819                         _bt_save_invocation_context(context, result, sender,
1820                                         function_name, (gpointer)addr);
1821                 }
1822                 break;
1823         }
1824         case BT_HF_DISCONNECT: {
1825                 bluetooth_device_address_t address = { {0} };
1826
1827                 __bt_service_get_parameters(in_param1,
1828                                 &address, sizeof(bluetooth_device_address_t));
1829
1830                 result = _bt_hf_disconnect(&address);
1831                 if (result != BLUETOOTH_ERROR_NONE) {
1832                         char addr[BT_ADDRESS_STRING_SIZE];
1833                         _bt_convert_addr_type_to_string(addr, address.addr);
1834                         g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1835                 } else {
1836                         char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1837                         _bt_convert_addr_type_to_string(addr, address.addr);
1838                         sender = (char*)g_dbus_method_invocation_get_sender(context);
1839                         _bt_save_invocation_context(context, result, sender,
1840                                         function_name, (gpointer)addr);
1841                 }
1842                 break;
1843         }
1844         case BT_AVRCP_TARGET_CONNECT: {
1845                 bluetooth_device_address_t address = { {0} };
1846
1847                 __bt_service_get_parameters(in_param1,
1848                                 &address, sizeof(bluetooth_device_address_t));
1849
1850                 result = _bt_audio_is_profile_connection_in_progress(BT_AVRCP_TARGET_CONNECT,
1851                                 &address);
1852
1853                 if (result == BLUETOOTH_ERROR_NONE)
1854                         result = _bt_audio_connect(BT_AVRCP_TARGET, &address);
1855
1856                 if (result != BLUETOOTH_ERROR_NONE) {
1857                         BT_ERR("AVRCP Target Connect Request has failed to execute");
1858                         char addr[BT_ADDRESS_STRING_SIZE];
1859                         _bt_convert_addr_type_to_string(addr, address.addr);
1860                         g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1861                 } else {
1862                         char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1863                         _bt_convert_addr_type_to_string(addr, address.addr);
1864                         sender = (char*)g_dbus_method_invocation_get_sender(context);
1865                         _bt_save_invocation_context(context, result, sender,
1866                                         function_name, (gpointer)addr);
1867                 }
1868                 break;
1869         }
1870         case BT_AVRCP_TARGET_DISCONNECT: {
1871                 bluetooth_device_address_t address = { {0} };
1872
1873                 __bt_service_get_parameters(in_param1,
1874                                 &address, sizeof(bluetooth_device_address_t));
1875
1876                 result = _bt_audio_disconnect(BT_AVRCP_TARGET, &address);
1877                 if (result != BLUETOOTH_ERROR_NONE) {
1878                         char addr[BT_ADDRESS_STRING_SIZE];
1879                         _bt_convert_addr_type_to_string(addr, address.addr);
1880                         g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1881                 } else {
1882                         char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1883                         _bt_convert_addr_type_to_string(addr, address.addr);
1884                         sender = (char*)g_dbus_method_invocation_get_sender(context);
1885                         _bt_save_invocation_context(context, result, sender,
1886                                         function_name, (gpointer)addr);
1887                 }
1888                 break;
1889         }
1890         case BT_AVRCP_CONTROL_CONNECT: {
1891                 bluetooth_device_address_t address = { {0} };
1892
1893                 __bt_service_get_parameters(in_param1,
1894                                 &address, sizeof(bluetooth_device_address_t));
1895
1896                 result = _bt_audio_is_profile_connection_in_progress(BT_AVRCP_CONTROL_CONNECT,
1897                                 &address);
1898
1899                 if (result == BLUETOOTH_ERROR_NONE)
1900                         result = _bt_audio_connect(BT_AVRCP, &address);
1901
1902                 if (result != BLUETOOTH_ERROR_NONE) {
1903                         BT_ERR("AVRCP Control Connect Request has failed to execute");
1904                         char addr[BT_ADDRESS_STRING_SIZE];
1905                         _bt_convert_addr_type_to_string(addr, address.addr);
1906                         g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1907                 } else {
1908                         char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1909                         _bt_convert_addr_type_to_string(addr, address.addr);
1910                         sender = (char*)g_dbus_method_invocation_get_sender(context);
1911                         _bt_save_invocation_context(context, result, sender,
1912                                         function_name, (gpointer)addr);
1913                 }
1914                 break;
1915         }
1916         case BT_AVRCP_CONTROL_DISCONNECT: {
1917                 bluetooth_device_address_t address = { {0} };
1918
1919                 __bt_service_get_parameters(in_param1,
1920                                 &address, sizeof(bluetooth_device_address_t));
1921
1922                 result = _bt_audio_disconnect(BT_AVRCP, &address);
1923                 if (result != BLUETOOTH_ERROR_NONE) {
1924                         char addr[BT_ADDRESS_STRING_SIZE];
1925                         _bt_convert_addr_type_to_string(addr, address.addr);
1926                         g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
1927                 } else {
1928                         char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
1929                         _bt_convert_addr_type_to_string(addr, address.addr);
1930                         sender = (char*)g_dbus_method_invocation_get_sender(context);
1931                         _bt_save_invocation_context(context, result, sender,
1932                                         function_name, (gpointer)addr);
1933                 }
1934                 break;
1935         }
1936         case BT_AVRCP_HANDLE_CONTROL: {
1937                 int key_code;
1938                 __bt_service_get_parameters(in_param1, &key_code, sizeof(int));
1939                 result = _bt_avrcp_control_cmd(key_code);
1940                 break;
1941         }
1942         case BT_AVRCP_HANDLE_CONTROL_TO_DEST: {
1943                 int key_code;
1944                 bluetooth_device_address_t address = { { 0 } };
1945
1946                 __bt_service_get_parameters(in_param1, &key_code, sizeof(int));
1947                 __bt_service_get_parameters(in_param2,
1948                                                 &address, sizeof(bluetooth_device_address_t));
1949
1950                 result = _bt_avrcp_control_cmd_to_dest(key_code, &address);
1951                 break;
1952         }
1953         case BT_AVRCP_CONTROL_SET_PROPERTY: {
1954                 int type;
1955                 unsigned int value;
1956
1957                 __bt_service_get_parameters(in_param1,
1958                                 &type, sizeof(int));
1959                 __bt_service_get_parameters(in_param2,
1960                                 &value, sizeof(unsigned int));
1961
1962                 result = _bt_avrcp_control_set_property(type, value);
1963                 break;
1964         }
1965         case BT_AVRCP_TRANSPORT_SET_PROPERTY: {
1966                 int type;
1967                 unsigned int value;
1968                 BT_DBG("+");
1969
1970                 __bt_service_get_parameters(in_param1,
1971                                 &type, sizeof(int));
1972                 __bt_service_get_parameters(in_param2,
1973                                 &value, sizeof(unsigned int));
1974
1975                 result = _bt_avrcp_transport_set_property(type, value);
1976                 BT_DBG("-");
1977                 break;
1978         }
1979         case BT_AVRCP_CONTROL_GET_PROPERTY: {
1980                 int type;
1981
1982                 __bt_service_get_parameters(in_param1, &type, sizeof(int));
1983
1984                 result = _bt_avrcp_control_get_property(type);
1985                 /* Save invocation */
1986                 if (result == BLUETOOTH_ERROR_NONE) {
1987                         sender = (char*)g_dbus_method_invocation_get_sender(context);
1988                         _bt_save_invocation_context(context, result, sender,
1989                                         function_name, g_memdup(&type, sizeof(int)));
1990                 }
1991                 break;
1992         }
1993         case BT_AVRCP_GET_TRACK_INFO: {
1994                 result = _bt_avrcp_control_get_track_info();
1995                 /* Save invocation */
1996                 if (result == BLUETOOTH_ERROR_NONE) {
1997                         sender = (char*)g_dbus_method_invocation_get_sender(context);
1998                         _bt_save_invocation_context(context, result, sender,
1999                                         function_name, NULL);
2000                 }
2001                 break;
2002         }
2003         case BT_HDP_REGISTER_SINK_APP: {
2004                 unsigned short data_type;
2005                 bt_hdp_role_type_t role;
2006                 bt_hdp_qos_type_t channel_type;
2007                 int *app_id = g_new0(int, 1);
2008
2009                 __bt_service_get_parameters(in_param1,
2010                                 &data_type, sizeof(short));
2011                 __bt_service_get_parameters(in_param2,
2012                                 &role, sizeof(bt_hdp_role_type_t));
2013                 __bt_service_get_parameters(in_param3,
2014                                 &channel_type, sizeof(bt_hdp_qos_type_t));
2015                 sender = (char*)g_dbus_method_invocation_get_sender(context);
2016
2017                 result = _bt_hdp_app_register(role,
2018                                 channel_type, data_type, sender, app_id);
2019                 if (result != BLUETOOTH_ERROR_NONE) {
2020                         g_array_append_vals(*out_param1, &app_id, sizeof(app_id));
2021                         g_free(app_id);
2022                 } else {
2023                         _bt_save_invocation_context(context, result, sender,
2024                                         function_name, (gpointer)app_id);
2025                 }
2026                 break;
2027         }
2028         case BT_HDP_UNREGISTER_SINK_APP: {
2029                 char *app_handle;
2030                 int *app_id = g_new0(int, 1);
2031
2032                 app_handle = (char *)g_variant_get_data(in_param1);
2033                 sscanf(app_handle, "health_app_%d", app_id);
2034                 result = _bt_hdp_app_unregister(*app_id);
2035                 if (result != BLUETOOTH_ERROR_NONE) {
2036                         g_free(app_id);
2037                 } else {
2038                         sender = (char*)g_dbus_method_invocation_get_sender(context);
2039                         _bt_save_invocation_context(context, result, sender,
2040                                         function_name, (gpointer)app_id);
2041                 }
2042                 break;
2043         }
2044         case BT_HDP_CONNECT: {
2045                 int app_id = -1;
2046                 char *app_handle;
2047
2048                 bt_hdp_connected_t *conn_info = NULL;
2049
2050                 conn_info = g_malloc0(sizeof(bt_hdp_connected_t));
2051
2052                 app_handle = (char *)g_variant_get_data(in_param1);
2053                 conn_info->app_handle = app_handle;
2054                 sscanf(app_handle, "health_app_%d", &app_id);
2055
2056                 __bt_service_get_parameters(in_param2,
2057                                 &(conn_info->type), sizeof(bt_hdp_qos_type_t));
2058                 __bt_service_get_parameters(in_param3,
2059                                 &(conn_info->device_address),
2060                                 sizeof(bluetooth_device_address_t));
2061
2062                 result = _bt_hdp_connect(app_id, &(conn_info->device_address),
2063                                 conn_info->type, (int *)(&(conn_info->channel_id)));
2064                 if (result != BLUETOOTH_ERROR_NONE) {
2065                         g_array_append_vals(*out_param1, conn_info,
2066                                         sizeof(bt_hdp_connected_t));
2067                         g_free(conn_info);
2068                 } else {
2069                         sender = (char*)g_dbus_method_invocation_get_sender(context);
2070                         _bt_save_invocation_context(context, result, sender,
2071                                         function_name, (gpointer)conn_info);
2072                 }
2073                 break;
2074         }
2075         case BT_HDP_DISCONNECT: {
2076                 bt_hdp_disconnected_t *hdp_disconn_info = NULL;
2077
2078                 hdp_disconn_info = g_malloc0(sizeof(bt_hdp_disconnected_t));
2079
2080                 __bt_service_get_parameters(in_param1,
2081                                 &(hdp_disconn_info->channel_id), sizeof(int));
2082                 __bt_service_get_parameters(in_param2,
2083                                 &(hdp_disconn_info->device_address),
2084                                 sizeof(bluetooth_device_address_t));
2085
2086                 result = _bt_hdp_disconnect(hdp_disconn_info->channel_id);
2087                 if (result != BLUETOOTH_ERROR_NONE) {
2088                         g_array_append_vals(*out_param1, hdp_disconn_info,
2089                                         sizeof(bt_hdp_disconnected_t));
2090                         g_free(hdp_disconn_info);
2091                 } else {
2092                         sender = (char*)g_dbus_method_invocation_get_sender(context);
2093                         _bt_save_invocation_context(context, result, sender,
2094                                         function_name, (gpointer)hdp_disconn_info);
2095                 }
2096                 break;
2097         }
2098         case BT_HDP_GET_FD: {
2099                 int *channel_id = g_new0(int, 1);
2100
2101                 __bt_service_get_parameters(in_param1, channel_id, sizeof(int));
2102
2103                 result = _bt_hdp_get_fd(*channel_id);
2104                 if (result != BLUETOOTH_ERROR_NONE) {
2105                         g_free(channel_id);
2106                 } else {
2107                         sender = (char*)g_dbus_method_invocation_get_sender(context);
2108                         _bt_save_invocation_context(context, result, sender,
2109                                         function_name, (gpointer)channel_id);
2110                 }
2111                 break;
2112         }
2113         case BT_HDP_SEND_DATA: {
2114                 /*
2115                  * This call to bt-service is only used for privilege check, so return
2116                  * BLUETOOTH_ERROR_NONE from here.
2117                  */
2118                 result = BLUETOOTH_ERROR_NONE;
2119                 break;
2120         }
2121         case BT_OOB_READ_LOCAL_DATA: {  //208
2122                 bt_oob_data_t local_oob_data;
2123
2124                 memset(&local_oob_data, 0x00, sizeof(bt_oob_data_t));
2125                 result = _bt_oob_read_local_data(&local_oob_data);
2126
2127                 g_array_append_vals(*out_param1, &local_oob_data,
2128                                 sizeof(bt_oob_data_t));
2129
2130                 break;
2131         }
2132         case BT_OOB_ADD_REMOTE_DATA: {   //209
2133                 bluetooth_device_address_t address = { {0} };
2134                 unsigned short address_type;
2135                 bt_oob_data_t remote_oob_data;
2136
2137                 __bt_service_get_parameters(in_param1,
2138                                 &address, sizeof(bluetooth_device_address_t));
2139                 __bt_service_get_parameters(in_param2,
2140                                 &address_type, sizeof(unsigned short));
2141                 __bt_service_get_parameters(in_param3,
2142                                 &remote_oob_data, sizeof(bt_oob_data_t));
2143
2144                 result = _bt_oob_add_remote_data(&address, address_type, &remote_oob_data);
2145
2146                 break;
2147         }
2148         case BT_OOB_REMOVE_REMOTE_DATA: {       //210
2149                 bluetooth_device_address_t address = { {0} };
2150
2151                 __bt_service_get_parameters(in_param1,
2152                                 &address, sizeof(bluetooth_device_address_t));
2153
2154                 result = _bt_oob_remove_remote_data(&address);
2155
2156                 break;
2157         }
2158         case BT_LE_OOB_READ_LOCAL_DATA: {
2159                 bt_oob_data_t local_oob_data;
2160                 bt_oob_data_t *local_oob_cache_data;
2161
2162                 local_oob_cache_data = _bt_le_oob_get_local_cache_data();
2163                 if (local_oob_cache_data && local_oob_cache_data->eir_len) {
2164                         g_array_append_vals(*out_param1, local_oob_cache_data,
2165                                 sizeof(bt_oob_data_t));
2166                         return BLUETOOTH_ERROR_NONE;
2167                 }
2168
2169                 /* We should modify this logic in later */
2170                 if (_bt_is_le_static_random_address_enabled() == false) {
2171                         /* Seperate BT & LE address */
2172                         _bt_set_le_static_random_address(TRUE);
2173                 }
2174
2175                 result = _bt_le_oob_read_local_data(&local_oob_data);
2176                 _bt_le_oob_set_local_cache_data(&local_oob_data);
2177
2178                 g_array_append_vals(*out_param1, &local_oob_data,
2179                                 sizeof(bt_oob_data_t));
2180
2181                 break;
2182         }
2183         case BT_LE_OOB_ADD_REMOTE_DATA: {
2184                 bluetooth_device_address_t address = { {0} };
2185                 unsigned short address_type;
2186                 bt_oob_data_t remote_oob_data;
2187
2188                 __bt_service_get_parameters(in_param1,
2189                                 &address, sizeof(bluetooth_device_address_t));
2190                 __bt_service_get_parameters(in_param2,
2191                                 &address_type, sizeof(unsigned short));
2192                 __bt_service_get_parameters(in_param3,
2193                                 &remote_oob_data, sizeof(bt_oob_data_t));
2194
2195                 result = _bt_oob_add_remote_data(&address, address_type, &remote_oob_data);
2196
2197                 break;
2198         }
2199         case BT_AVRCP_SET_TRACK_INFO: {
2200                 media_metadata_t data;
2201                 media_metadata_attributes_t meta_data;
2202
2203                 memset(&data, 0x00, sizeof(media_metadata_t));
2204                 memset(&meta_data, 0x00, sizeof(media_metadata_attributes_t));
2205
2206                 __bt_service_get_parameters(in_param1,
2207                                 &data, sizeof(media_metadata_t));
2208
2209                 meta_data.title = g_strdup(data.title);
2210                 meta_data.artist = g_strdup(data.artist);
2211                 meta_data.album = g_strdup(data.album);
2212                 meta_data.genre = g_strdup(data.genre);
2213                 meta_data.total_tracks = data.total_tracks;
2214                 meta_data.number = data.number;
2215                 meta_data.duration = (int64_t) data.duration;
2216
2217                 result = _bt_avrcp_set_track_info(&meta_data);
2218
2219                 g_free((gpointer)meta_data.title);
2220                 g_free((gpointer)meta_data.artist);
2221                 g_free((gpointer)meta_data.album);
2222                 g_free((gpointer)meta_data.genre);
2223
2224                 break;
2225         }
2226         case BT_AVRCP_SET_PROPERTY: {
2227                 int type;
2228                 unsigned int value;
2229
2230                 sender = (char *)g_dbus_method_invocation_get_sender(context);
2231
2232                 __bt_service_get_parameters(in_param1,
2233                                 &type, sizeof(int));
2234                 __bt_service_get_parameters(in_param2,
2235                                 &value, sizeof(unsigned int));
2236
2237                 if (value == STATUS_PLAYING) {
2238                         if (current_sender_playing)
2239                                 g_free(current_sender_playing);
2240                         current_sender_playing = g_strdup(sender);
2241                 }
2242                 if (g_strcmp0(sender, current_sender_playing) == 0 ||
2243                         current_sender_playing == NULL) {
2244                         BT_INFO("Current Player Status %d type %d Sender %s", value, type, sender);
2245                 } else {
2246                         BT_INFO("Current Player and this sender (%s) are different", sender);
2247                         result = BLUETOOTH_ERROR_NONE;
2248                         break;
2249                 }
2250                 result = _bt_avrcp_set_property(type, value);
2251
2252                 break;
2253         }
2254         case BT_AVRCP_SET_PROPERTIES: {
2255                 media_player_settings_t properties;
2256
2257                 memset(&properties, 0x00, sizeof(media_player_settings_t));
2258                 __bt_service_get_parameters(in_param1,
2259                                 &properties, sizeof(media_player_settings_t));
2260
2261                 result = _bt_avrcp_set_properties(&properties);
2262
2263                 break;
2264         }
2265         case BT_SET_ADVERTISING_DATA: {
2266                 char *app = NULL;
2267                 int *adv_handle;
2268                 bluetooth_advertising_data_t adv = { {0} };
2269                 int length;
2270                 gboolean use_reserved_slot = FALSE;
2271
2272                 app = (char *)g_dbus_method_invocation_get_sender(context);
2273                 adv_handle = g_malloc0(sizeof(int));
2274
2275                 __bt_service_get_parameters(in_param1,
2276                                 adv_handle, sizeof(int));
2277                 __bt_service_get_parameters(in_param3,
2278                                 &length, sizeof(int));
2279                 __bt_service_get_parameters(in_param2,
2280                                 &adv, length);
2281                 __bt_service_get_parameters(in_param4,
2282                                 &use_reserved_slot, sizeof(gboolean));
2283                 result = _bt_set_advertising_data(app, *adv_handle,
2284                                 &adv, length, use_reserved_slot);
2285                 if (result != BLUETOOTH_ERROR_NONE) {
2286                         BT_ERR("Set Advertising data failed!!");
2287                         g_free(adv_handle);
2288                 } else {
2289                         _bt_save_invocation_context(context, result, app,
2290                                         function_name, (gpointer)adv_handle);
2291                 }
2292                 break;
2293         }
2294         case BT_SET_SCAN_RESPONSE_DATA: {
2295                 char *app = NULL;
2296                 int *adv_handle;
2297                 bluetooth_scan_resp_data_t rsp = { {0} };
2298                 int length;
2299                 gboolean use_reserved_slot = FALSE;
2300
2301                 app = (char *)g_dbus_method_invocation_get_sender(context);
2302                 adv_handle = g_malloc0(sizeof(int));
2303
2304                 __bt_service_get_parameters(in_param1,
2305                                 adv_handle, sizeof(int));
2306                 __bt_service_get_parameters(in_param3,
2307                                 &length, sizeof(int));
2308                 __bt_service_get_parameters(in_param2,
2309                                 &rsp, length);
2310                 __bt_service_get_parameters(in_param4,
2311                                 &use_reserved_slot, sizeof(gboolean));
2312
2313                 result = _bt_set_scan_response_data(app, *adv_handle,
2314                                 &rsp, length, use_reserved_slot);
2315
2316                 if (result != BLUETOOTH_ERROR_NONE) {
2317                         BT_ERR("Set Scan Response Data failed!!");
2318                         g_free(adv_handle);
2319                 } else {
2320                         _bt_save_invocation_context(context, result, app,
2321                                         function_name, (gpointer)adv_handle);
2322                 }
2323                 break;
2324         }
2325         case BT_SET_ADVERTISING: {
2326                 char *app = NULL;
2327                 int *adv_handle;
2328                 gboolean enable = FALSE;
2329                 gboolean use_reserved_slot = FALSE;
2330
2331                 adv_handle = g_malloc0(sizeof(int));
2332                 __bt_service_get_parameters(in_param1,
2333                                 adv_handle, sizeof(int));
2334                 __bt_service_get_parameters(in_param2,
2335                                 &enable, sizeof(gboolean));
2336                 __bt_service_get_parameters(in_param3,
2337                                 &use_reserved_slot, sizeof(gboolean));
2338
2339                 app = (char *)g_dbus_method_invocation_get_sender(context);
2340
2341                 result = _bt_set_advertising(app, *adv_handle,
2342                                 enable, use_reserved_slot);
2343                 if (result != BLUETOOTH_ERROR_NONE) {
2344                         BT_ERR("Start Advertising failed!!");
2345                         g_free(adv_handle);
2346                 } else {
2347                         _bt_save_invocation_context(context, result, app,
2348                                         function_name, (gpointer)adv_handle);
2349                 }
2350                 break;
2351         }
2352         case BT_SET_CUSTOM_ADVERTISING: {
2353                 char *app = NULL;
2354                 int *adv_handle;
2355                 gboolean enable = FALSE;
2356                 bluetooth_advertising_params_t adv_params;
2357                 gboolean use_reserved_slot = FALSE;
2358
2359                 app = (char *)g_dbus_method_invocation_get_sender(context);
2360                 adv_handle = g_malloc0(sizeof(int));
2361
2362                 __bt_service_get_parameters(in_param1, adv_handle,
2363                                 sizeof(int));
2364                 __bt_service_get_parameters(in_param2, &enable,
2365                                 sizeof(gboolean));
2366                 __bt_service_get_parameters(in_param3, &adv_params,
2367                                 sizeof(bluetooth_advertising_params_t));
2368                 __bt_service_get_parameters(in_param4, &use_reserved_slot,
2369                                 sizeof(gboolean));
2370
2371                 BT_DBG("bluetooth_advertising_params_t [%d %d %d %d %d]",
2372                                 adv_params.interval_min, adv_params.interval_max,
2373                                 adv_params.filter_policy, adv_params.type, adv_params.tx_power_level);
2374                 result = _bt_set_custom_advertising(app, *adv_handle,
2375                                 enable, &adv_params, use_reserved_slot);
2376                 if (result != BLUETOOTH_ERROR_NONE) {
2377                         BT_ERR("Start Custom Advertising failed!!");
2378                         g_free(adv_handle);
2379                 } else {
2380                         _bt_save_invocation_context(context, result, app,
2381                                         function_name, (gpointer)adv_handle);
2382                 }
2383                 break;
2384         }
2385         case BT_GET_SCAN_RESPONSE_DATA: {
2386                 bluetooth_scan_resp_data_t rsp = { {0} };
2387                 char *app = NULL;
2388                 int length = 0;
2389                 int adv_handle;
2390                 app = (char *)g_dbus_method_invocation_get_sender(context);
2391
2392                 __bt_service_get_parameters(in_param1, &adv_handle,
2393                                 sizeof(int));
2394
2395                 result = _bt_get_scan_response_data(app, adv_handle, &rsp, &length);
2396                 if (result == BLUETOOTH_ERROR_NONE)
2397                         g_array_append_vals(*out_param1, rsp.data, length);
2398
2399                 break;
2400         }
2401         case BT_GET_ADVERTISING_DATA: {
2402                 bluetooth_advertising_data_t adv = { {0} };
2403                 char *app = NULL;
2404                 int length = 0;
2405                 int adv_handle;
2406                 app = (char *)g_dbus_method_invocation_get_sender(context);
2407
2408                 __bt_service_get_parameters(in_param1, &adv_handle,
2409                                 sizeof(int));
2410
2411                 result = _bt_get_advertising_data(app, adv_handle, &adv, &length);
2412                 if (result == BLUETOOTH_ERROR_NONE)
2413                         g_array_append_vals(*out_param1, adv.data, length);
2414
2415                 break;
2416         }
2417         case BT_GATT_REGISTER_APPLICATION: {
2418                 BT_DBG("Register GATT application:Unhandled!!");
2419                 break;
2420         }
2421         case BT_GATT_SERVER_REGISTER: {
2422                 BT_DBG("GATT Server instance initialization");
2423                 char *app;
2424
2425                 app = (char *)g_dbus_method_invocation_get_sender(context);
2426                 BT_DBG("GATT Server Unique Name [%s]", app);
2427
2428                 /* No ADV handle: Set 0 */
2429                 result = _bt_register_server_instance(app, 0);
2430
2431                 if (result != BLUETOOTH_ERROR_NONE) {
2432                         BT_ERR("GATT Server registration failed. result %d", result);
2433                 } else {
2434                         _bt_save_invocation_context(context, result, app,
2435                                         function_name, NULL);
2436                 }
2437                 break;
2438         }
2439         case BT_GATT_SERVER_DEREGISTER: {
2440                 char *app;
2441                 app = (char*)g_dbus_method_invocation_get_sender(context);
2442
2443                 result = _bt_unregister_server_instance(app, 0/* Adv Handle*/);
2444                 break;
2445         }
2446         case BT_GATT_SERVER_ADD_SERVICE: {
2447                 BT_DBG("GATT Server Add Service");
2448                 int service_type;
2449                 int num_handles;
2450                 char *svc_uuid;
2451                 int instance_id;
2452                 char *app;
2453                 int *tmp_inst_id = NULL;
2454
2455                 app = (char *)g_dbus_method_invocation_get_sender(context);
2456
2457                 __bt_service_get_parameters(in_param1, &service_type,
2458                                 sizeof(int));
2459                 __bt_service_get_parameters(in_param2, &num_handles,
2460                                 sizeof(int));
2461                 svc_uuid = (char *)g_variant_get_data(in_param3);
2462                 __bt_service_get_parameters(in_param4, &instance_id,
2463                                 sizeof(int));
2464
2465                 result = _bt_gatt_server_add_service(app, service_type, num_handles, svc_uuid, instance_id);
2466                 if (result != BLUETOOTH_ERROR_NONE) {
2467                         BT_ERR("GATT Server Add Service failed!!");
2468                 } else {
2469                         tmp_inst_id = g_malloc0(sizeof(int));
2470                         *tmp_inst_id = instance_id;
2471                         _bt_save_invocation_context(context, result, app,
2472                                         function_name, (gpointer)tmp_inst_id);
2473                 }
2474                 break;
2475         }
2476         case BT_GATT_SERVER_ADD_CHARACTERISTIC: {
2477                 BT_DBG("GATT Server Add Characteristic");
2478                 char *char_uuid;
2479                 char *app;
2480                 int *tmp_inst_id = NULL;
2481                 bluetooth_gatt_server_attribute_params_t param;
2482                 memset(&param, 0, sizeof(bluetooth_gatt_server_attribute_params_t));
2483
2484                 app = (char*)g_dbus_method_invocation_get_sender(context);
2485
2486                 __bt_service_get_parameters(in_param1, &param,
2487                                 sizeof(bluetooth_gatt_server_attribute_params_t));
2488                 char_uuid = (char *)g_variant_get_data(in_param2);
2489
2490                 result = _bt_gatt_server_add_characteristic(app, char_uuid, &param);
2491                 if (result != BLUETOOTH_ERROR_NONE) {
2492                         BT_ERR("GATT Server Add Service failed!!");
2493                 } else {
2494                         tmp_inst_id = g_malloc0(sizeof(int));
2495                         *tmp_inst_id = param.instance_id;
2496
2497                         _bt_save_invocation_context(context, result, app,
2498                                         function_name, (gpointer)tmp_inst_id);
2499                 }
2500                 break;
2501         }
2502         case BT_GATT_SERVER_ADD_DESCRIPTOR: {
2503                 BT_DBG("GATT Server Add Descriptor");
2504                 char *desc_uuid;
2505                 int instance_id;
2506                 int service_handle;
2507                 bt_gatt_permission_t perm;
2508                 char *app;
2509                 int *tmp_inst_id = NULL;
2510                 memset(&perm, 0, sizeof(bt_gatt_permission_t));
2511
2512                 app = (char *)g_dbus_method_invocation_get_sender(context);
2513
2514                 __bt_service_get_parameters(in_param1, &service_handle,
2515                                 sizeof(int));
2516                 __bt_service_get_parameters(in_param2, &instance_id,
2517                                 sizeof(int));
2518                 desc_uuid = (char *)g_variant_get_data(in_param4);
2519                 __bt_service_get_parameters(in_param3, &perm,
2520                                 sizeof(bt_gatt_permission_t));
2521
2522                 result = _bt_gatt_server_add_descriptor(app, desc_uuid, &perm, service_handle, instance_id);
2523                 if (result != BLUETOOTH_ERROR_NONE) {
2524                         BT_ERR("GATT Server Add Service failed!!");
2525                 } else {
2526                         tmp_inst_id = g_malloc0(sizeof(int));
2527                         *tmp_inst_id = instance_id;
2528                         _bt_save_invocation_context(context, result, app,
2529                                         function_name, (gpointer)tmp_inst_id);
2530                 }
2531                 break;
2532         }
2533         case BT_GATT_SERVER_START_SERVICE: {
2534                 int service_handle;
2535                 int instance_id;
2536
2537                 char *app;
2538                 int *tmp_inst_id = NULL;
2539                 app = (char*)g_dbus_method_invocation_get_sender(context);
2540
2541                 __bt_service_get_parameters(in_param1, &service_handle,
2542                                 sizeof(int));
2543                 __bt_service_get_parameters(in_param2, &instance_id,
2544                                 sizeof(int));
2545
2546                 result = _bt_gatt_server_start_service(app, service_handle, instance_id);
2547
2548                 if (BLUETOOTH_ERROR_NONE == result) {
2549                         tmp_inst_id = g_malloc0(sizeof(int));
2550                         *tmp_inst_id = instance_id;
2551                         _bt_save_invocation_context(context, result, app,
2552                                         function_name, (gpointer)tmp_inst_id);
2553                 }
2554                 break;
2555         }
2556         case BT_GATT_SERVER_STOP_SERVICE: {
2557                 int service_handle;
2558                 int instance_id;
2559                 char *app;
2560                 int *tmp_inst_id = NULL;
2561                 app = (char*)g_dbus_method_invocation_get_sender(context);
2562
2563                 __bt_service_get_parameters(in_param1, &service_handle,
2564                                 sizeof(int));
2565                 __bt_service_get_parameters(in_param2, &instance_id,
2566                                 sizeof(int));
2567
2568                 result = _bt_gatt_server_stop_service(app, service_handle, instance_id);
2569
2570                 if (BLUETOOTH_ERROR_NONE == result) {
2571                         tmp_inst_id = g_malloc0(sizeof(int));
2572                         *tmp_inst_id = instance_id;
2573                         _bt_save_invocation_context(context, result, app,
2574                                         function_name, (gpointer)tmp_inst_id);
2575                 }
2576                 break;
2577         }
2578         case BT_GATT_SERVER_DELETE_SERVICE: {
2579                 int service_handle;
2580                 int instance_id;
2581                 int *tmp_inst_id = NULL;
2582                 char *app;
2583                 app = (char*)g_dbus_method_invocation_get_sender(context);
2584
2585                 __bt_service_get_parameters(in_param1, &service_handle,
2586                                 sizeof(int));
2587                 __bt_service_get_parameters(in_param2, &instance_id,
2588                                 sizeof(int));
2589
2590                 result = _bt_gatt_server_delete_service(app, service_handle, instance_id);
2591
2592                 if (BLUETOOTH_ERROR_NONE == result) {
2593                         tmp_inst_id = g_malloc0(sizeof(int));
2594                         *tmp_inst_id = instance_id;
2595                         _bt_save_invocation_context(context, result, app,
2596                                         function_name, (gpointer)tmp_inst_id);
2597                 }
2598                 break;
2599         }
2600         case BT_GATT_SERVER_SEND_RESPONSE: {
2601                 bluetooth_gatt_server_response_params_t param;
2602                 bluetooth_gatt_att_data_t data;
2603                 char *app;
2604
2605                 memset(&param, 0x00, sizeof(bluetooth_gatt_server_response_params_t));
2606                 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
2607
2608                 app = (char*)g_dbus_method_invocation_get_sender(context);
2609
2610                 __bt_service_get_parameters(in_param1, &data,
2611                                 sizeof(bluetooth_gatt_att_data_t));
2612                 __bt_service_get_parameters(in_param2, &param,
2613                                 sizeof(bluetooth_gatt_server_response_params_t));
2614
2615                 result = _bt_gatt_server_send_response(app, &data, &param);
2616
2617                 break;
2618         }
2619         case BT_GATT_SERVER_ACQURE_WRITE_RESPONSE: {
2620
2621                 bluetooth_gatt_server_acquire_response_params_t param;
2622                 char *app;
2623                 GDBusMessage *msg;
2624                 msg = g_dbus_method_invocation_get_message(context);
2625                 GUnixFDList *fd_list;
2626                 int fd  = -1;;
2627                 int *fd_list_array;
2628                 int len;
2629
2630                 fd_list = g_dbus_message_get_unix_fd_list(msg);
2631
2632                 memset(&param, 0x00, sizeof(bluetooth_gatt_server_acquire_response_params_t));
2633
2634                 app = (char*)g_dbus_method_invocation_get_sender(context);
2635
2636                 __bt_service_get_parameters(in_param1, &param,
2637                                 sizeof(bluetooth_gatt_server_acquire_response_params_t));
2638
2639                 fd_list_array = (int *)g_unix_fd_list_peek_fds(fd_list, &len);
2640                 BT_DBG("Num fds in fd_list is : %d, fd_list[0]: %d", len, fd_list_array[0]);
2641                 fd = fd_list_array[0];
2642
2643                 param.fd = fd;
2644                 result = _bt_gatt_server_acquire_send_response(app, &param, fd_list);
2645
2646                 break;
2647         }
2648         case BT_GATT_SERVER_ACQUIRE_NOTIFY_RESPONSE: {
2649
2650                 bluetooth_gatt_server_acquire_response_params_t param;
2651                 char *app;
2652                 GDBusMessage *msg;
2653                 msg = g_dbus_method_invocation_get_message(context);
2654                 GUnixFDList *fd_list;
2655                 int fd  = -1;
2656                 int *fd_list_array;
2657                 int len;
2658
2659                 fd_list = g_dbus_message_get_unix_fd_list(msg);
2660
2661                 memset(&param, 0x00, sizeof(bluetooth_gatt_server_acquire_response_params_t));
2662
2663                 app = (char*)g_dbus_method_invocation_get_sender(context);
2664
2665                 __bt_service_get_parameters(in_param1, &param,
2666                                 sizeof(bluetooth_gatt_server_acquire_response_params_t));
2667
2668                 fd_list_array = (int *)g_unix_fd_list_peek_fds(fd_list, &len);
2669                 BT_DBG("Num fds in fd_list is : %d, fd_list[0]: %d", len, fd_list_array[0]);
2670                 fd = fd_list_array[0];
2671
2672                 param.fd = fd;
2673                 result = _bt_gatt_server_acquire_send_response(app, &param, fd_list);
2674
2675                 break;
2676         }
2677         case BT_GATT_SERVER_SEND_INDICATION: {
2678                 bluetooth_gatt_server_indication_params_t param;
2679                 bluetooth_gatt_att_data_t data;
2680                 bluetooth_device_address_t address;
2681
2682                 char *app;
2683                 app = (char*)g_dbus_method_invocation_get_sender(context);
2684
2685                 memset(&param, 0x00, sizeof(bluetooth_gatt_server_indication_params_t));
2686                 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
2687                 memset(&address, 0x00, sizeof(bluetooth_device_address_t));
2688
2689                 __bt_service_get_parameters(in_param1, &data,
2690                                 sizeof(bluetooth_gatt_att_data_t));
2691                 __bt_service_get_parameters(in_param2, &param,
2692                                 sizeof(bluetooth_gatt_server_indication_params_t));
2693                 __bt_service_get_parameters(in_param3, &address,
2694                                 sizeof(bluetooth_device_address_t));
2695
2696                 result = _bt_gatt_server_send_indication(app, &address, &data, &param);
2697
2698                 break;
2699         }
2700         case BT_GATT_SERVER_UPDATE_VALUE: {
2701                 bluetooth_gatt_server_update_value_t param;
2702                 int instance_id;
2703                 char *app;
2704
2705                 memset(&param, 0x00, sizeof(bluetooth_gatt_server_update_value_t));
2706
2707                 app = (char*)g_dbus_method_invocation_get_sender(context);
2708
2709                 __bt_service_get_parameters(in_param1, &instance_id,
2710                                 sizeof(int));
2711                 __bt_service_get_parameters(in_param2, &param,
2712                                 sizeof(bluetooth_gatt_server_update_value_t));
2713
2714                 result = _bt_gatt_server_update_attribute_value(app, instance_id, &param);
2715                 break;
2716         }
2717         case BT_GET_ATT_MTU: {
2718                 bluetooth_device_address_t address = { {0} };
2719                 unsigned int mtu = 0;
2720
2721                 __bt_service_get_parameters(in_param1,
2722                                 &address, sizeof(bluetooth_device_address_t));
2723                 result = _bt_get_att_mtu(&address, &mtu);
2724                 BT_DBG("MTU: %d", mtu);
2725
2726                 if (result == BLUETOOTH_ERROR_NONE) {
2727                         g_array_append_vals(*out_param1, &mtu,
2728                                         sizeof(unsigned int));
2729                 }
2730                 break;
2731         }
2732         case BT_REQ_ATT_MTU: {
2733                 bluetooth_device_address_t address = { {0} };
2734                 unsigned int mtu;
2735                 char *addr;
2736
2737                 sender = (char*)g_dbus_method_invocation_get_sender(context);
2738
2739                 __bt_service_get_parameters(in_param1,
2740                                 &address, sizeof(bluetooth_device_address_t));
2741                 __bt_service_get_parameters(in_param2,
2742                                 &mtu, sizeof(unsigned int));
2743                 BT_DBG("BT_REQ_ATT_MTU: %d", mtu);
2744                 result = _bt_request_att_mtu(&address, mtu);
2745                 if (BLUETOOTH_ERROR_NONE == result) {
2746                         addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2747
2748                         _bt_convert_addr_type_to_string(addr, address.addr);
2749
2750                         /* Save the informations to invocation */
2751                         _bt_save_invocation_context(context, result, sender,
2752                                         function_name, (gpointer)addr);
2753                 } else {
2754                         g_array_append_vals(*out_param1, &address,
2755                                         sizeof(bluetooth_device_address_t));
2756                 }
2757                 break;
2758         }
2759         case BT_GET_DEVICE_IDA: {
2760                 bluetooth_device_address_t address = { {0} };
2761                 bluetooth_device_address_t id_addr = { {0} };
2762
2763                 __bt_service_get_parameters(in_param1,
2764                                 &address, sizeof(bluetooth_device_address_t));
2765
2766                 result = _bt_device_get_ida(&address, &id_addr);
2767
2768                 if (result == BLUETOOTH_ERROR_NONE) {
2769                         g_array_append_vals(*out_param1, &id_addr,
2770                                         sizeof(bluetooth_device_address_t));
2771                 }
2772                 break;
2773         }
2774         case BT_SET_LE_STATIC_RANDOM_ADDRESS: {
2775                 gboolean is_enable;
2776
2777                 __bt_service_get_parameters(in_param1, &is_enable,
2778                                 sizeof(gboolean));
2779
2780                 result = _bt_set_le_static_random_address(is_enable);
2781
2782                 break;
2783         }
2784         /* Local Async */
2785         case BT_GATT_CLIENT_REGISTER: {
2786                 bluetooth_device_address_t address = { {0} };
2787                 char *addr;
2788
2789                 sender = (char*)g_dbus_method_invocation_get_sender(context);
2790
2791                 __bt_service_get_parameters(in_param1,
2792                                 &address, sizeof(bluetooth_device_address_t));
2793
2794                 result = _bt_register_gatt_client_instance(sender, &address);
2795                 if (BLUETOOTH_ERROR_NONE == result) {
2796                         addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2797
2798                         _bt_convert_addr_type_to_string(addr, address.addr);
2799
2800                         /* Save the informations to invocation */
2801                         _bt_save_invocation_context(context, result, sender,
2802                                         function_name, (gpointer)addr);
2803                 }
2804                 break;
2805         }
2806         /* Sync */
2807         case BT_GATT_CLIENT_UNREGISTER: {
2808                 int client_id;
2809
2810                 sender = (char*)g_dbus_method_invocation_get_sender(context);
2811                 __bt_service_get_parameters(in_param1,
2812                                 &client_id, sizeof(int));
2813
2814                 result = _bt_unregister_gatt_client_instance(sender, client_id);
2815                 break;
2816         }
2817
2818         /* Async: Remote Interaction  */
2819         case BT_GATT_ACQUIRE_WRITE: {
2820
2821                 int fd = -1;
2822                 int mtu = -1;
2823                 bluetooth_gatt_client_char_prop_info_t param;
2824
2825                 sender = (char*)g_dbus_method_invocation_get_sender(context);
2826
2827                 __bt_service_get_parameters(in_param1, &param,
2828                                         sizeof(bluetooth_gatt_client_char_prop_info_t));
2829
2830
2831                 result   = _bt_gatt_acquire_write(&param , &fd, &mtu);
2832
2833                 g_array_append_vals(*out_param1, &mtu, sizeof(int));
2834
2835                 if (BLUETOOTH_ERROR_NONE == result)
2836                         BT_DBG("GATT Client: Save Invocation data for characteristic props app[%s] fd[ %d]", sender, fd);
2837                 else {
2838                         BT_ERR("GATT Client: gatt acquire write failed");
2839                         break;
2840                 }
2841
2842                 GUnixFDList *fd_list = NULL;
2843                 GError *error = NULL;
2844
2845                 /* Add socket fd to unix_fd_list */
2846                 fd_list = g_unix_fd_list_new();
2847                 g_unix_fd_list_append(fd_list, fd, &error);
2848                 g_assert_no_error(error);
2849
2850                 _bt_service_method_return_with_unix_fd_list(
2851                                 context, *out_param1, result, fd_list);
2852
2853                 close(fd);
2854                 g_object_unref(fd_list);
2855
2856                 break;
2857         }
2858         /* Async: Remote Interaction  */
2859         case BT_CONNECT_LE: {
2860                 bluetooth_device_address_t address = { {0} };
2861                 gboolean auto_connect;
2862                 char *addr;
2863                 int client_id;
2864
2865                 sender = (char*)g_dbus_method_invocation_get_sender(context);
2866
2867                 __bt_service_get_parameters(in_param1,
2868                                 &address, sizeof(bluetooth_device_address_t));
2869                 __bt_service_get_parameters(in_param2,
2870                                 &auto_connect, sizeof(gboolean));
2871                 __bt_service_get_parameters(in_param3,
2872                                 &client_id, sizeof(int));
2873
2874                 BT_DBG("GATT Client: client_id[%d]", client_id);
2875                 result = _bt_connect_le_device(&address, auto_connect, client_id);
2876                 if (BLUETOOTH_ERROR_NONE == result) {
2877                         addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2878                         _bt_convert_addr_type_to_string(addr, address.addr);
2879
2880                         /* Save the informations to invocation */
2881                         _bt_save_invocation_context(context, result, sender,
2882                                         function_name, (gpointer)addr);
2883
2884                         if (auto_connect)
2885                                 _bt_handle_invocation_context(function_name, (void *)addr);
2886                 } else {
2887                         BT_ERR("GATT Client: gatt connect failed. client_id[%d]", client_id);
2888                         g_array_append_vals(*out_param1, &address,
2889                                         sizeof(bluetooth_device_address_t));
2890                 }
2891                 break;
2892         }
2893         /* Async: Remote Interaction  */
2894         case BT_DISCONNECT_LE: {
2895                 bluetooth_device_address_t address = { {0} };
2896                 char *addr;
2897                 int client_id;
2898
2899                 sender = (char*)g_dbus_method_invocation_get_sender(context);
2900
2901                 __bt_service_get_parameters(in_param1,
2902                                 &address, sizeof(bluetooth_device_address_t));
2903                 __bt_service_get_parameters(in_param2,
2904                                 &client_id, sizeof(int));
2905
2906                 BT_INFO("GATT Disconnect using client Interface [%d]", client_id);
2907                 result = _bt_disconnect_le_device(&address, client_id);
2908                 if (BLUETOOTH_ERROR_NONE == result) {
2909                         addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
2910
2911                         _bt_convert_addr_type_to_string(addr, address.addr);
2912
2913                         /* Save the informations to invocation */
2914                         _bt_save_invocation_context(context, result, sender,
2915                                         function_name, (gpointer)addr);
2916                 } else {
2917                         g_array_append_vals(*out_param1, &address,
2918                                         sizeof(bluetooth_device_address_t));
2919                 }
2920                 break;
2921         }
2922         /* Sync */
2923         case BT_GET_GATT_DATA_BATCHING_AVAILABLE_PACKETS: {
2924                 guint available_packets = 0;
2925
2926                 result = _bt_gatt_get_data_batching_available_packets(&available_packets);
2927                 BT_DBG("LE batching available packets %u", available_packets);
2928                 if (result == BLUETOOTH_ERROR_NONE) {
2929                         g_array_append_vals(*out_param1, &available_packets,
2930                                         sizeof(guint));
2931                 }
2932
2933                 break;
2934         }
2935         /* Sync */
2936         case BT_ENABLE_GATT_DATA_BATCHING: {
2937                 bluetooth_device_address_t address = { {0} };
2938                 int packet_threshold;
2939                 int timeout;
2940
2941                 __bt_service_get_parameters(in_param1,
2942                                 &address, sizeof(bluetooth_device_address_t));
2943                 __bt_service_get_parameters(in_param2,
2944                                 &packet_threshold, sizeof(int));
2945                 __bt_service_get_parameters(in_param3,
2946                                 &timeout, sizeof(int));
2947                 result = _bt_gatt_enable_data_batching(&address, packet_threshold, timeout);
2948
2949                 break;
2950         }
2951         /* Sync */
2952         case BT_DISABLE_GATT_DATA_BATCHING: {
2953                 bluetooth_device_address_t address = { {0} };
2954
2955                 __bt_service_get_parameters(in_param1,
2956                                 &address, sizeof(bluetooth_device_address_t));
2957                 result = _bt_gatt_disable_data_batching(&address);
2958
2959                 break;
2960         }
2961
2962         case BT_GATT_GET_PRIMARY_SERVICES: {
2963                 char *addr;
2964
2965                 sender = (char*)g_dbus_method_invocation_get_sender(context);
2966                 bluetooth_device_address_t address = { {0} };
2967
2968                 __bt_service_get_parameters(in_param1, &address,
2969                                 sizeof(bluetooth_device_address_t));
2970
2971                 addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
2972                 _bt_convert_addr_type_to_string(addr, address.addr);
2973
2974                 result = _bt_gatt_get_primary_services(addr);
2975                 if (BLUETOOTH_ERROR_NONE == result) {
2976                         _bt_save_invocation_context(context, result, sender,
2977                                         function_name, (gpointer)addr);
2978                 } else
2979                         g_free(addr);
2980                 break;
2981         }
2982         /* Local Async */
2983         case BT_GATT_GET_SERVICE_PROPERTIES: {
2984                 bluetooth_gatt_client_svc_prop_info_t param;
2985
2986                 sender = (char*)g_dbus_method_invocation_get_sender(context);
2987                 memset(&param, 0x00, sizeof(bluetooth_gatt_client_svc_prop_info_t));
2988
2989                 __bt_service_get_parameters(in_param1, &param,
2990                                 sizeof(bluetooth_gatt_client_svc_prop_info_t));
2991
2992                 result = _bt_gatt_get_all_characteristic(&param);
2993                 if (BLUETOOTH_ERROR_NONE == result) {
2994                         /* Save the informations to invocation */
2995                         _bt_save_invocation_context(context, result, sender,
2996                                         function_name,
2997                                         (gpointer)g_memdup(&param, sizeof(bluetooth_gatt_client_svc_prop_info_t)));
2998                 }
2999                 break;
3000         }
3001         case BT_GATT_GET_CHARACTERISTIC_PROPERTIES: {
3002                 bluetooth_gatt_client_char_prop_info_t param;
3003
3004                 sender = (char*)g_dbus_method_invocation_get_sender(context);
3005                 memset(&param, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3006
3007                 __bt_service_get_parameters(in_param1, &param,
3008                                 sizeof(bluetooth_gatt_client_char_prop_info_t));
3009
3010                 result = _bt_gatt_get_all_characteristic_properties(&param);
3011                 if (BLUETOOTH_ERROR_NONE == result) {
3012                         /* Save the informations to invocation */
3013                         _bt_save_invocation_context(context, result, sender,
3014                                         function_name,
3015                                         (gpointer)g_memdup(&param, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3016                 }
3017                 break;
3018         }
3019         /* Async: Remote Interaction  */
3020         case BT_GATT_READ_CHARACTERISTIC: {
3021                 bluetooth_gatt_client_char_prop_info_t param;
3022
3023                 sender = (char*)g_dbus_method_invocation_get_sender(context);
3024                 memset(&param, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3025
3026                 __bt_service_get_parameters(in_param1, &param,
3027                                 sizeof(bluetooth_gatt_client_char_prop_info_t));
3028
3029                 result = _bt_gatt_read_characteristic_value(&param);
3030                 if (BLUETOOTH_ERROR_NONE == result) {
3031                         /* Save the informations to invocation */
3032                         _bt_save_invocation_context(context, result, sender,
3033                                         function_name,
3034                                         (gpointer)g_memdup(&param, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3035                 }
3036                 break;
3037         }
3038         /* Async: Remote Interaction  */
3039         case BT_GATT_READ_DESCRIPTOR_VALUE: {
3040                 bluetooth_gatt_client_desc_prop_info_t param;
3041
3042                 sender = (char*)g_dbus_method_invocation_get_sender(context);
3043                 memset(&param, 0x00, sizeof(bluetooth_gatt_client_desc_prop_info_t));
3044
3045                 __bt_service_get_parameters(in_param1, &param,
3046                                 sizeof(bluetooth_gatt_client_desc_prop_info_t));
3047
3048                 result = _bt_gatt_read_descriptor_value(&param);
3049                 if (BLUETOOTH_ERROR_NONE == result) {
3050                         /* Save the informations to invocation */
3051                         _bt_save_invocation_context(context, result, sender,
3052                                         function_name,
3053                                         (gpointer)g_memdup(&param, sizeof(bluetooth_gatt_client_desc_prop_info_t)));
3054                 }
3055                 break;
3056         }
3057         /* Async: Remote Interaction  */
3058         case BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE: {
3059                 bluetooth_gatt_client_char_prop_info_t param;
3060                 bluetooth_gatt_att_data_t data;
3061                 bluetooth_gatt_write_type_e write_type;
3062
3063                 sender = (char*)g_dbus_method_invocation_get_sender(context);
3064
3065                 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
3066                 memset(&param, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3067
3068                 __bt_service_get_parameters(in_param1, &param,
3069                                 sizeof(bluetooth_gatt_client_char_prop_info_t));
3070                 __bt_service_get_parameters(in_param2, &data,
3071                                 sizeof(bluetooth_gatt_att_data_t));
3072                 __bt_service_get_parameters(in_param3, &write_type,
3073                                 sizeof(bluetooth_gatt_write_type_e));
3074
3075                 result = _bt_gatt_write_characteristic_value_by_type(&param , &data, write_type);
3076                 if (BLUETOOTH_ERROR_NONE == result) {
3077                         /* Save the informations to invocation */
3078                         _bt_save_invocation_context(context, result, sender,
3079                                         function_name,
3080                                         (gpointer)g_memdup(&param, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3081                 }
3082                 break;
3083         }
3084         /* Async: Remote Interaction  */
3085         case BT_GATT_WRITE_DESCRIPTOR_VALUE: {
3086                 bluetooth_gatt_client_desc_prop_info_t param;
3087                 bluetooth_gatt_att_data_t data;
3088                 bluetooth_gatt_write_type_e write_type;
3089
3090                 sender = (char*)g_dbus_method_invocation_get_sender(context);
3091                 memset(&data, 0x00, sizeof(bluetooth_gatt_att_data_t));
3092                 memset(&param, 0x00, sizeof(bluetooth_gatt_client_desc_prop_info_t));
3093
3094                 __bt_service_get_parameters(in_param1, &param,
3095                                 sizeof(bluetooth_gatt_client_desc_prop_info_t));
3096                 __bt_service_get_parameters(in_param2, &data,
3097                                 sizeof(bluetooth_gatt_att_data_t));
3098                 __bt_service_get_parameters(in_param3, &write_type,
3099                                 sizeof(bluetooth_gatt_write_type_e));
3100
3101                 result = _bt_gatt_write_descriptor_value_by_type(&param, &data, write_type);
3102                 if (BLUETOOTH_ERROR_NONE == result) {
3103                         /* Save the informations to invocation */
3104                         _bt_save_invocation_context(context, result, sender,
3105                                         function_name,
3106                                         (gpointer)g_memdup(&param, sizeof(bluetooth_gatt_client_desc_prop_info_t)));
3107                 }
3108                 break;
3109         }
3110         /* Local Async */
3111         case BT_GATT_WATCH_CHARACTERISTIC: {
3112                 bluetooth_gatt_client_char_prop_info_t param;
3113                 int client_id;
3114                 gboolean is_notify;
3115                 int fd = -1;
3116                 int mtu = 0;
3117                 gboolean is_indicate;
3118
3119
3120                 memset(&param, 0x00, sizeof(bluetooth_gatt_client_char_prop_info_t));
3121
3122                 sender = (char*)g_dbus_method_invocation_get_sender(context);
3123
3124                 __bt_service_get_parameters(in_param1, &param,
3125                                 sizeof(bluetooth_gatt_client_char_prop_info_t));
3126                 __bt_service_get_parameters(in_param2, &client_id,
3127                                 sizeof(int));
3128                 __bt_service_get_parameters(in_param3, &is_notify,
3129                                 sizeof(gboolean));
3130                 __bt_service_get_parameters(in_param4, &is_indicate,
3131                                 sizeof(gboolean));
3132
3133 #ifdef TIZEN_FEATURE_BT_GATT_CLIENT_FD_DISABLE
3134                 goto normal;
3135 #endif
3136
3137                 if (is_indicate == false) {
3138                         result   = _bt_gatt_acquire_notify(&param , &fd, &mtu);
3139                         if (BLUETOOTH_ERROR_NONE == result && fd > -1) {
3140                                 BT_DBG("GATT Client: Save Invocation data for characteristic props app[%s] fd[ %d]", sender, fd);
3141
3142                                 GUnixFDList *fd_list = NULL;
3143                                 GError *error = NULL;
3144
3145                                 g_array_append_vals(*out_param1, &mtu, sizeof(int));
3146                                 /* Add socket fd to unix_fd_list */
3147                                 fd_list = g_unix_fd_list_new();
3148                                 g_unix_fd_list_append(fd_list, fd, &error);
3149                                 g_assert_no_error(error);
3150                                 close(fd);
3151                                 _bt_service_method_return_with_unix_fd_list(
3152                                 context, *out_param1, result, fd_list);
3153
3154                                 g_object_unref(fd_list);
3155                         } else
3156                                 goto normal;
3157                 } else {
3158
3159 normal:
3160                         result = _bt_gatt_watch_characteristic(&param , client_id, is_notify);
3161                         if (BLUETOOTH_ERROR_NONE == result) {
3162                                 /* Save the informations to invocation */
3163                                 _bt_save_invocation_context(context, result, sender, function_name,
3164                                          (gpointer)g_memdup(&param, sizeof(bluetooth_gatt_client_char_prop_info_t)));
3165                         }
3166                 }
3167                 break;
3168         }
3169         case BT_GATT_WATCH_SERVICE_CHANGED_INDICATION: {
3170                 gboolean is_enabled;
3171                 bluetooth_device_address_t address;
3172
3173                 sender = (char*)g_dbus_method_invocation_get_sender(context);
3174
3175                 __bt_service_get_parameters(in_param1,
3176                                 &address, sizeof(bluetooth_device_address_t));
3177                 __bt_service_get_parameters(in_param2, &is_enabled,
3178                                 sizeof(gboolean));
3179                 result = _bt_gatt_watch_service_changed_indication(sender, &address, is_enabled);
3180                 BT_INFO("Service changed indication from app [%s]", sender);
3181
3182                 break;
3183         }
3184         case BT_LE_CONN_UPDATE: {
3185                 char *sender = NULL;
3186                 bluetooth_device_address_t local_address = { {0} };
3187                 bluetooth_le_connection_param_t parameters = {0};
3188
3189                 sender = (char *)g_dbus_method_invocation_get_sender(context);
3190
3191                 __bt_service_get_parameters(in_param1, &local_address,
3192                                 sizeof(bluetooth_device_address_t));
3193                 __bt_service_get_parameters(in_param2, &parameters,
3194                                 sizeof(bluetooth_le_connection_param_t));
3195
3196                 result = _bt_le_connection_update(sender,
3197                                         local_address.addr,
3198                                         parameters.interval_min,
3199                                         parameters.interval_max,
3200                                         parameters.latency,
3201                                         parameters.timeout);
3202                 break;
3203         }
3204         case BT_START_LE_DISCOVERY: {
3205                 uid_t uid = 0;
3206                 pid_t pid = 0;
3207
3208                 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
3209
3210                 sender = (char *)g_dbus_method_invocation_get_sender(context);
3211
3212                 if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
3213                         BT_ERR("Fail to get the sender pid");
3214
3215                 result = _bt_start_le_scan(sender, uid, pid);
3216                 if (result == BLUETOOTH_ERROR_NONE) {
3217                         _bt_save_invocation_context(context, result, sender,
3218                                         function_name, NULL);
3219
3220                         BT_DBG("Remeber pid / uid for the scan operation");
3221                         _bt_bm_add_scan_app(SCAN_LE, uid, pid);
3222                 }
3223                 break;
3224         }
3225         case BT_STOP_LE_DISCOVERY: {
3226                 uid_t uid = 0;
3227                 pid_t pid = 0;
3228
3229                 __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
3230
3231                 sender = (char *)g_dbus_method_invocation_get_sender(context);
3232
3233                 if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
3234                         BT_ERR("Fail to get the sender pid");
3235
3236                 result = _bt_stop_le_scan(sender);
3237                 if (result == BLUETOOTH_ERROR_NONE) {
3238                         _bt_save_invocation_context(context, result, sender,
3239                                         function_name, NULL);
3240                 }
3241
3242                 BT_DBG("Remove pid / uid for the scan operation");
3243                 _bt_bm_remove_scan_app(SCAN_LE, uid, pid);
3244
3245                 break;
3246         }
3247         case BT_IS_LE_DISCOVERYING: {
3248                 gboolean le_discovering = FALSE;
3249
3250                 le_discovering = _bt_is_le_scanning();
3251                 g_array_append_vals(*out_param1,
3252                                 &le_discovering, sizeof(gboolean));
3253                 break;
3254         }
3255         case BT_SET_SCAN_PARAMETERS: {
3256                 bluetooth_le_scan_params_t scan_params;
3257
3258                 __bt_service_get_parameters(in_param1, &scan_params,
3259                                 sizeof(bluetooth_le_scan_params_t));
3260
3261                 BT_DBG("bluetooth_le_scan_params_t [%f %f %d]",
3262                                 scan_params.interval, scan_params.window,
3263                                 scan_params.type);
3264
3265                 result = _bt_prepare_scan_parameters(&scan_params, 0);
3266                 break;
3267         }
3268         case BT_SET_SCAN_TYPE: {
3269                 int scan_type = 0;
3270                 __bt_service_get_parameters(in_param1, &scan_type, sizeof(int));
3271
3272                 BT_DBG("bluetooth_le_scan_type [%d]", scan_type);
3273                 result = _bt_prepare_scan_parameters(NULL, scan_type);
3274                 break;
3275         }
3276 #ifdef TIZEN_FEATURE_BT_PAN_NAP
3277         case BT_NETWORK_ACTIVATE:
3278                 BT_DBG("BT_NETWORK_ACTIVATE Request recieved Request Handler ");
3279                 result = _bt_network_activate();
3280                 break;
3281         case BT_NETWORK_DEACTIVATE:
3282                 result = _bt_network_deactivate();
3283                 break;
3284         case BT_NETWORK_CONNECT: {
3285                 bluetooth_device_address_t address = { {0} };
3286                 int role;
3287
3288                 __bt_service_get_parameters(in_param1,
3289                                 &address, sizeof(bluetooth_device_address_t));
3290                 __bt_service_get_parameters(in_param2,
3291                                 &role, sizeof(int));
3292
3293                 result = _bt_network_connect(request_id, role, &address);
3294                 if (result != BLUETOOTH_ERROR_NONE) {
3295                         g_array_append_vals(*out_param1, &address,
3296                                         sizeof(bluetooth_device_address_t));
3297                 }
3298                 break;
3299         }
3300         case BT_NETWORK_DISCONNECT: {
3301                 bluetooth_device_address_t address = { {0} };
3302
3303                 __bt_service_get_parameters(in_param1,
3304                                 &address, sizeof(bluetooth_device_address_t));
3305
3306                 result = _bt_network_disconnect(request_id, &address);
3307                 if (result != BLUETOOTH_ERROR_NONE) {
3308                         g_array_append_vals(*out_param1, &address,
3309                                         sizeof(bluetooth_device_address_t));
3310                 }
3311                 break;
3312         }
3313         case BT_NETWORK_SERVER_DISCONNECT: {
3314                 bluetooth_device_address_t address = { {0} };
3315
3316                 __bt_service_get_parameters(in_param1,
3317                                 &address, sizeof(bluetooth_device_address_t));
3318
3319                 result = _bt_network_server_disconnect(request_id, &address);
3320                 if (result != BLUETOOTH_ERROR_NONE) {
3321                         g_array_append_vals(*out_param1, &address,
3322                                         sizeof(bluetooth_device_address_t));
3323                 }
3324                 break;
3325         }
3326
3327 #endif
3328 #ifdef TIZEN_FEATURE_BT_IPSP
3329         case BT_LE_IPSP_INIT:
3330                 result = _bt_initialize_ipsp();
3331                 break;
3332         case BT_LE_IPSP_DEINIT:
3333                 result = _bt_deinitialize_ipsp();
3334                 break;
3335         case BT_LE_IPSP_CONNECT: {
3336                 bluetooth_device_address_t address = { {0} };
3337                 __bt_service_get_parameters(in_param1, &address,
3338                                 sizeof(bluetooth_device_address_t));
3339                 result = _bt_connect_le_ipsp_device(&address);
3340                 break;
3341         }
3342         case BT_LE_IPSP_DISCONNECT: {
3343                 bluetooth_device_address_t address = { {0} };
3344                 __bt_service_get_parameters(in_param1, &address,
3345                                 sizeof(bluetooth_device_address_t));
3346                 result = _bt_disconnect_le_ipsp_device(&address);
3347                 break;
3348         }
3349 #endif
3350         case BT_IS_ADVERTISING: {
3351                 gboolean advertising = FALSE;
3352                 advertising = _bt_is_advertising();
3353                 g_array_append_vals(*out_param1, &advertising,
3354                                 sizeof(gboolean));
3355                 break;
3356         }
3357         case BT_IS_LE_2M_PHY_SUPPORTED: {
3358                 gboolean is_2m_phy_supported = FALSE;
3359
3360                 is_2m_phy_supported = _bt_is_le_2m_phy_supported();
3361                 g_array_append_vals(*out_param1, &is_2m_phy_supported, sizeof(gboolean));
3362                 break;
3363         }
3364         case BT_IS_LE_CODED_PHY_SUPPORTED: {
3365                 gboolean is_coded_phy_supported = FALSE;
3366
3367                 is_coded_phy_supported = _bt_is_le_coded_phy_supported();
3368                 g_array_append_vals(*out_param1, &is_coded_phy_supported, sizeof(gboolean));
3369                 break;
3370         }
3371         case BT_DISCONNECT_DEVICE: {
3372                 bluetooth_device_address_t address = { {0} };
3373
3374                 __bt_service_get_parameters(in_param1,
3375                                 &address, sizeof(bluetooth_device_address_t));
3376
3377                 result = _bt_disconnect_device(&address);
3378                 break;
3379         }
3380         case BT_REGISTER_SCAN_FILTER: {
3381                 bluetooth_le_scan_filter_t scan_filter;
3382
3383                 sender = (char*)g_dbus_method_invocation_get_sender(context);
3384                 __bt_service_get_parameters(in_param1, &scan_filter,
3385                                 sizeof(bluetooth_le_scan_filter_t));
3386
3387                 BT_DBG("bluetooth_le_scan_filter_t [features : 0x%.2x]",
3388                                 scan_filter.added_features);
3389
3390                 result = _bt_register_scan_filter(sender, &scan_filter);
3391
3392                 break;
3393         }
3394
3395         case BT_TDS_PROVIDER_REGISTER: {
3396                 char *sender = NULL;
3397
3398                 sender = (char *)g_dbus_method_invocation_get_sender(context);
3399                 result = _bt_tds_provider_register(sender);
3400
3401                 break;
3402         }
3403
3404         case BT_TDS_PROVIDER_UNREGISTER: {
3405                 char *sender = NULL;
3406
3407                 sender = (char *)g_dbus_method_invocation_get_sender(context);
3408                 result = _bt_tds_provider_unregister(sender);
3409
3410                 break;
3411         }
3412
3413         case BT_TDS_PROVIDER_SET_MANUF_DATA: {
3414                 char *sender = NULL;
3415                 unsigned int length = 0;
3416                 bluetooth_advertising_data_t manuf_data;
3417
3418                 __bt_service_get_parameters(in_param1,
3419                                 &length, sizeof(unsigned int));
3420                 __bt_service_get_parameters(in_param2,
3421                                 &manuf_data, sizeof(bluetooth_advertising_data_t));
3422                 sender = (char *)g_dbus_method_invocation_get_sender(context);
3423
3424                 result = _bt_tds_provider_set_manuf_data(sender, manuf_data.data, length);
3425                 break;
3426         }
3427
3428         case BT_TDS_PROVIDER_CREATE: {
3429                 char *sender = NULL;
3430                 unsigned int tds_handle = 0;
3431                 int transport;
3432
3433                 __bt_service_get_parameters(in_param1,
3434                                 &tds_handle, sizeof(unsigned int));
3435                 __bt_service_get_parameters(in_param2,
3436                                 &transport, sizeof(int));
3437                 sender = (char *)g_dbus_method_invocation_get_sender(context);
3438                 result = _bt_tds_provider_transport_create(sender, transport, tds_handle);
3439
3440                 break;
3441         }
3442
3443         case BT_TDS_PROVIDER_DESTROY: {
3444                 char *sender = NULL;
3445                 unsigned int tds_handle = 0;
3446
3447                 __bt_service_get_parameters(in_param1,
3448                                 &tds_handle, sizeof(unsigned int));
3449                 sender = (char *)g_dbus_method_invocation_get_sender(context);
3450                 result = _bt_tds_provider_transport_remove(sender, tds_handle);
3451
3452                 break;
3453         }
3454
3455         case BT_TDS_PROVIDER_SET_TRANSPORT_DATA: {
3456                 char *sender = NULL;
3457                 unsigned int tds_handle = 0;
3458                 int transport_state = 0;
3459                 bluetooth_tds_data_t tds_data;
3460
3461                 __bt_service_get_parameters(in_param1,
3462                                 &tds_handle, sizeof(unsigned int));
3463                 __bt_service_get_parameters(in_param2,
3464                                 &transport_state, sizeof(int));
3465                 __bt_service_get_parameters(in_param3,
3466                                 &tds_data, sizeof(bluetooth_tds_data_t));
3467                 sender = (char *)g_dbus_method_invocation_get_sender(context);
3468
3469                 result = _bt_tds_provider_set_transport_data(sender, tds_handle,
3470                                 transport_state, tds_data.data, tds_data.length);
3471                 break;
3472         }
3473
3474         case BT_TDS_SEND_ACTIVATION_RESPONSE: {
3475                 bluetooth_device_address_t address = { {0} };
3476                 bluetooth_tds_data_t tds_data;
3477                 char *sender = NULL;
3478                 unsigned int tds_handle = 0;
3479                 int response;
3480
3481                 __bt_service_get_parameters(in_param1,
3482                                 &tds_handle, sizeof(unsigned int));
3483                 __bt_service_get_parameters(in_param2,
3484                                 &response, sizeof(int));
3485                 __bt_service_get_parameters(in_param3, &address,
3486                         sizeof(bluetooth_device_address_t));
3487                 __bt_service_get_parameters(in_param4,
3488                                 &tds_data, sizeof(bluetooth_tds_data_t));
3489                 sender = (char *)g_dbus_method_invocation_get_sender(context);
3490
3491                 result = _bt_tds_provider_send_activation_response(sender, tds_handle,
3492                                 &address, response, tds_data.data, tds_data.length);
3493                 break;
3494         }
3495
3496         case BT_MESH_INIT:
3497                 sender = (char*)g_dbus_method_invocation_get_sender(context);
3498                 BT_INFO("Mesh: Init by [%s]", sender);
3499                 result = _bt_mesh_init(sender);
3500                 /* Save invocation */
3501                 if (result == BLUETOOTH_ERROR_NONE) {
3502                         BT_INFO("Mesh: Save Invoation");
3503                         sender = (char*)g_dbus_method_invocation_get_sender(context);
3504                         _bt_save_invocation_context(context,
3505                                         result, sender,
3506                                         function_name, NULL);
3507                 }
3508                 break;
3509
3510         case BT_MESH_DEINIT:
3511                 sender = (char*)g_dbus_method_invocation_get_sender(context);
3512                 BT_INFO("Mesh: De-Init by [%s]", sender);
3513                 result = _bt_mesh_deinit(sender);
3514                 break;
3515
3516         case BT_MESH_NETWORK_CREATE: {
3517                 bluetooth_mesh_node_t node;
3518                 GSList *model_list = NULL;
3519                 int total_models = 0;
3520                 GArray *param3;
3521                 int i = 0;
3522                 const char *network_name = NULL;
3523                 bluetooth_mesh_network_t *network;
3524
3525                 memset(&node, 0x00, sizeof(bluetooth_mesh_node_t));
3526                 sender = (char*)g_dbus_method_invocation_get_sender(context);
3527
3528                 __bt_service_get_parameters(in_param1,
3529                                 &node, sizeof(bluetooth_mesh_node_t));
3530                 network_name = (const char *)g_variant_get_data(in_param2);
3531
3532                 BT_INFO("MESH: Network name [%s]", network_name);
3533
3534                 param3 = g_array_new(TRUE, TRUE, sizeof(gchar));
3535                 __bt_fill_garray_from_variant(in_param3, param3);
3536
3537                 total_models = (param3->len) / sizeof(bluetooth_mesh_model_t);
3538                 for (i = 0; i < total_models; i++) {
3539                         bluetooth_mesh_model_t *info = NULL;
3540                         bluetooth_mesh_model_t *mod = NULL;
3541
3542                         info = &g_array_index(param3,
3543                                         bluetooth_mesh_model_t, i);
3544
3545                         mod = g_memdup(info, sizeof(bluetooth_mesh_model_t));
3546
3547                         if (mod)
3548                                 model_list = g_slist_append(model_list,
3549                                                         (gpointer)mod);
3550                 }
3551                 result = _bt_mesh_network_create(requester_unique_creds,
3552                                 sender, network_name,  &node, model_list);
3553
3554                  /* Save invocation */
3555                 if (result == BLUETOOTH_ERROR_NONE) {
3556                         BT_INFO("Mesh: Save Invoation");
3557                         network =  g_malloc0(sizeof(bluetooth_mesh_network_t));
3558
3559                         /* Save Network name & UUID, Token will be received in event */
3560                         _bt_mesh_util_convert_hex_to_string(
3561                                         (uint8_t *) node.uuid, 16,
3562                                         network->uuid,
3563                                         BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
3564                         BT_INFO("Mesh: Mesh Netwok UUID [%s]", network->uuid);
3565                         g_strlcpy(network->name.name, network_name,
3566                                 sizeof(network->name.name));
3567                         g_strlcpy(network->app_cred,
3568                                 requester_unique_creds,
3569                                 sizeof(network->app_cred));
3570                         sender = (char*)g_dbus_method_invocation_get_sender(context);
3571                         BT_INFO("Mesh: Network Create by [%s]", sender);
3572                         _bt_save_invocation_context(context,
3573                                         result, sender,
3574                                         function_name, (gpointer)network);
3575                 } else {
3576                         g_array_append_vals(*out_param1, &node, sizeof(bluetooth_mesh_node_t));
3577                         BT_ERR("Mesh: Mesh Network creation schedule failed");
3578                         g_slist_free_full(model_list, g_free);
3579                 }
3580
3581                 /* Cleanup */
3582                 BT_INFO("Mesh: Cleanup");
3583                 g_free((gpointer)requester_unique_creds);
3584                 g_array_free(param3, TRUE);
3585                 BT_INFO("Mesh: Cleanup Done");
3586                 break;
3587         }
3588         case BT_MESH_NETWORK_DESTROY: {
3589                 bluetooth_mesh_network_t network;
3590                 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3591
3592                 __bt_service_get_parameters(in_param1,
3593                                 &network, sizeof(bluetooth_mesh_network_t));
3594
3595                 BT_INFO("Mesh: Destroy Network");
3596                 result = _bt_mesh_network_destroy(requester_unique_creds,
3597                                 sender, &network);
3598
3599                 if (result != BLUETOOTH_ERROR_NONE) {
3600                         g_array_append_vals(*out_param1,
3601                                 &network, sizeof(bluetooth_mesh_network_t));
3602                 } else {
3603                         BT_INFO("Mesh: Destroy Network scheduled: add invocation");
3604                         bluetooth_mesh_network_t *net =  \
3605                                         g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3606
3607                         sender = (char*)g_dbus_method_invocation_get_sender(context);
3608                         _bt_save_invocation_context(context, result, sender,
3609                                         function_name, (gpointer)net);
3610                 }
3611                 break;
3612         }
3613         case BT_MESH_NETWORK_LOAD: {
3614                 char *token = NULL;
3615                 bluetooth_mesh_network_t *network;
3616                 token = (char *)g_variant_get_data(in_param1);
3617                 BT_INFO("MESH: Network Load: Token string [%s]", token);
3618                 result = _bt_mesh_network_load(requester_unique_creds, sender, token);
3619                 /* Save invocation */
3620                 if (result == BLUETOOTH_ERROR_NONE) {
3621                         network =  g_malloc0(sizeof(bluetooth_mesh_network_t));
3622                         g_strlcpy(network->token.token, token,
3623                                         BLUETOOTH_MESH_NETWORK_TOKEN_STRING_LENGTH + 1);
3624                         g_strlcpy(network->app_cred, requester_unique_creds,
3625                                         sizeof(network->app_cred));
3626
3627                         sender = (char*)g_dbus_method_invocation_get_sender(context);
3628                         _bt_save_invocation_context(context, result, sender,
3629                                         function_name, (gpointer)network);
3630                 }
3631                 g_free((gpointer)requester_unique_creds);
3632                 break;
3633         }
3634         case BT_MESH_NETWORK_UNLOAD: {
3635                 bluetooth_mesh_network_t network;
3636                 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3637
3638                 __bt_service_get_parameters(in_param1,
3639                                 &network, sizeof(bluetooth_mesh_network_t));
3640
3641                 BT_INFO("MESH: Network Unload: Network UUID [%s]", network.uuid);
3642                 result = _bt_mesh_network_unload(requester_unique_creds,
3643                                 sender, &network);
3644                 break;
3645         }
3646         case BT_MESH_NETWORK_JOIN: {
3647                 bluetooth_mesh_node_t node;
3648                 GSList *model_list = NULL;
3649                 int total_models = 0;
3650                 GArray *param2;
3651                 int i = 0;
3652
3653                 memset(&node, 0x00, sizeof(bluetooth_mesh_node_t));
3654                 sender = (char*)g_dbus_method_invocation_get_sender(context);
3655
3656                 __bt_service_get_parameters(in_param1,
3657                                 &node, sizeof(bluetooth_mesh_node_t));
3658
3659                 param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
3660                 __bt_fill_garray_from_variant(in_param2, param2);
3661
3662                 total_models = (param2->len) / sizeof(bluetooth_mesh_model_t);
3663                 for (i = 0; i < total_models; i++) {
3664                         bluetooth_mesh_model_t *info = NULL;
3665                         bluetooth_mesh_model_t *mod = NULL;
3666                         info = &g_array_index(param2,
3667                                 bluetooth_mesh_model_t, i);
3668                         mod = g_memdup(info, sizeof(bluetooth_mesh_model_t));
3669
3670                         if (mod)
3671                                 model_list = g_slist_append(model_list,
3672                                         (gpointer)mod);
3673                 }
3674
3675                 BT_INFO("MESH: Network Join bt-service");
3676                 //result = BLUETOOTH_ERROR_NONE;
3677                 result = _bt_mesh_network_join(requester_unique_creds,
3678                                 sender, &node, model_list);
3679                 if (result != BLUETOOTH_ERROR_NONE) {
3680                         g_array_append_vals(*out_param1, &node, sizeof(bluetooth_mesh_node_t));
3681                         BT_ERR("Mesh: Mesh Join Network schedule failed");
3682                         g_slist_free_full(model_list, g_free);
3683                 }
3684
3685                 BT_INFO("return of _bt_mesh_network_join : [%d]", result);
3686                 break;
3687         }
3688         case BT_MESH_CANCEL_JOIN: {
3689                 bluetooth_mesh_node_info_t node;
3690                 memset(&node, 0x00, sizeof(bluetooth_mesh_node_info_t));
3691
3692                 __bt_service_get_parameters(in_param1,
3693                                 &node, sizeof(bluetooth_mesh_node_info_t));
3694
3695                 BT_INFO("Mesh: Cancel Join request");
3696                 result = _bt_mesh_cancel_join(requester_unique_creds,
3697                                 sender, &node);
3698                 if (result != BLUETOOTH_ERROR_NONE) {
3699                         g_array_append_vals(*out_param1,
3700                                         &node, sizeof(bluetooth_mesh_node_t));
3701                 }
3702                 break;
3703         }
3704         case BT_MESH_NETWORK_SCAN: {
3705                 bluetooth_mesh_network_t network;
3706                 bluetooth_mesh_scan_param_t param;
3707                 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3708                 memset(&param, 0x00, sizeof(bluetooth_mesh_scan_param_t));
3709
3710                 __bt_service_get_parameters(in_param1,
3711                                 &network, sizeof(bluetooth_mesh_network_t));
3712
3713                 __bt_service_get_parameters(in_param2,
3714                                 &param, sizeof(bluetooth_mesh_scan_param_t));
3715
3716                 result = _bt_mesh_network_scan(requester_unique_creds,
3717                                 sender, &network, &param);
3718
3719                 if (result != BLUETOOTH_ERROR_NONE) {
3720                         g_array_append_vals(*out_param1,
3721                                 &network, sizeof(bluetooth_mesh_network_t));
3722                 } else {
3723                         bluetooth_mesh_network_t *net =  \
3724                                         g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3725
3726                         sender = (char*)g_dbus_method_invocation_get_sender(context);
3727                         _bt_save_invocation_context(context, result, sender,
3728                                         function_name, (gpointer)net);
3729                 }
3730                 break;
3731         }
3732         case BT_MESH_NETWORK_CANCEL_SCAN: {
3733                 bluetooth_mesh_network_t network;
3734                 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3735
3736                 __bt_service_get_parameters(in_param1,
3737                                 &network, sizeof(bluetooth_mesh_network_t));
3738
3739                 result = _bt_mesh_network_scan_cancel(requester_unique_creds,
3740                         sender, &network);
3741
3742                 if (result != BLUETOOTH_ERROR_NONE)
3743                         g_array_append_vals(*out_param1,
3744                                 &network, sizeof(bluetooth_mesh_network_t));
3745                 break;
3746         }
3747         case BT_MESH_NETWORK_SET_CAPABILITIES: {
3748                 bluetooth_mesh_network_t network;
3749                 bluetooth_mesh_provisioner_caps_t caps;
3750                 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3751                 memset(&caps, 0x00, sizeof(bluetooth_mesh_provisioner_caps_t));
3752
3753                 __bt_service_get_parameters(in_param1,
3754                                 &network, sizeof(bluetooth_mesh_network_t));
3755
3756                 __bt_service_get_parameters(in_param2,
3757                                 &caps, sizeof(bluetooth_mesh_provisioner_caps_t));
3758
3759                 result = _bt_mesh_network_set_provisioner_caps(
3760                                 requester_unique_creds, sender, &network, &caps);
3761
3762                 break;
3763         }
3764         case BT_MESH_NETWORK_PROVISION_DEVICE: {
3765                 bluetooth_mesh_provisioning_request_t req;
3766                 memset(&req, 0x00, sizeof(bluetooth_mesh_provisioning_request_t));
3767
3768                 __bt_service_get_parameters(in_param1,
3769                                 &req, sizeof(bluetooth_mesh_provisioning_request_t));
3770
3771                 BT_INFO("Mesh: Provision Device UUID [%s]", req.dev_uuid);
3772                 BT_INFO("Mesh: Provision Device in network[%s]", req.net_uuid);
3773
3774                 result = _bt_mesh_network_provision_device(
3775                                 requester_unique_creds, sender, &req);
3776
3777                 /* Save invocation */
3778                 if (result != BLUETOOTH_ERROR_NONE) {
3779                         g_array_append_vals(*out_param1, &req,
3780                                 sizeof(bluetooth_mesh_provisioning_request_t));
3781                 } else {
3782                         bluetooth_mesh_provisioning_request_t *param =  \
3783                                 g_memdup(&req, sizeof(bluetooth_mesh_provisioning_request_t));
3784
3785                         sender = (char*)g_dbus_method_invocation_get_sender(context);
3786                         _bt_save_invocation_context(context, result, sender,
3787                                         function_name, (gpointer)param);
3788                 }
3789                 break;
3790         }
3791         case BT_MESH_AUTHENTICATION_REPLY: {
3792                 BT_INFO("Mesh: BT_MESH_AUTHENTICATION_REPLY");
3793                 const char *auth_value = NULL;
3794                 gboolean authentication_reply = FALSE;
3795                 int auth_type;
3796                 auth_value = g_variant_get_data(in_param2);
3797                 __bt_service_get_parameters(in_param3,
3798                                 &authentication_reply, sizeof(gboolean));
3799                 __bt_service_get_parameters(in_param1,
3800                                 &auth_type, sizeof(int));
3801                 BT_INFO("Mesh: Auth Reply Type [%d]", auth_type);
3802                 BT_INFO("Mesh: Auth Value [%s]", auth_value);
3803                 BT_INFO("Mesh: Auth Accept [%d]", authentication_reply);
3804                 result = _bt_mesh_authentication_reply(auth_type,
3805                                 auth_value, authentication_reply);
3806                 break;
3807         }
3808         case BT_MESH_NETWORK_SET_NAME: {
3809                 bluetooth_mesh_network_t network;
3810                 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3811
3812                 __bt_service_get_parameters(in_param1,
3813                                 &network, sizeof(bluetooth_mesh_network_t));
3814
3815                 result = _bt_mesh_network_set_name(requester_unique_creds, sender, &network);
3816
3817                 break;
3818         }
3819         case BT_MESH_NETWORK_ADD_NETKEY: {
3820                 bluetooth_mesh_network_t network;
3821                 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3822
3823                 __bt_service_get_parameters(in_param1,
3824                                 &network, sizeof(bluetooth_mesh_network_t));
3825
3826                 result = _bt_mesh_network_add_netkey(requester_unique_creds,
3827                         sender, &network);
3828
3829                 if (result != BLUETOOTH_ERROR_NONE) {
3830                         g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3831                 } else {
3832                         bluetooth_mesh_network_t *net =  g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3833
3834                         sender = (char*)g_dbus_method_invocation_get_sender(context);
3835                         _bt_save_invocation_context(context, result, sender,
3836                                         function_name, (gpointer)net);
3837                 }
3838                 break;
3839         }
3840         case BT_MESH_NETWORK_DELETE_NETKEY: {
3841                 bluetooth_mesh_network_t network;
3842                 uint16_t index;
3843
3844                 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3845
3846                 __bt_service_get_parameters(in_param1,
3847                                 &network, sizeof(bluetooth_mesh_network_t));
3848                 __bt_service_get_parameters(in_param2,
3849                                 &index, sizeof(guint16));
3850
3851                 result = _bt_mesh_network_delete_netkey(requester_unique_creds,
3852                                 sender, &network, index);
3853
3854                 if (result != BLUETOOTH_ERROR_NONE) {
3855                         g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3856                 } else {
3857                         bluetooth_mesh_network_t *net =  g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3858
3859                         sender = (char*)g_dbus_method_invocation_get_sender(context);
3860                         _bt_save_invocation_context(context, result, sender,
3861                                         function_name, (gpointer)net);
3862                 }
3863                 break;
3864         }
3865         case BT_MESH_NETWORK_UPDATE_NETKEY: {
3866                 bluetooth_mesh_network_t network;
3867                 uint16_t index;
3868
3869                 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3870
3871                 __bt_service_get_parameters(in_param1,
3872                                 &network, sizeof(bluetooth_mesh_network_t));
3873                 __bt_service_get_parameters(in_param2,
3874                                 &index, sizeof(guint16));
3875
3876                 result = _bt_mesh_network_update_netkey(requester_unique_creds,
3877                                 sender, &network, index);
3878
3879                 if (result != BLUETOOTH_ERROR_NONE) {
3880                         g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3881                 } else {
3882                         bluetooth_mesh_network_t *net =  g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3883
3884                         sender = (char*)g_dbus_method_invocation_get_sender(context);
3885                         _bt_save_invocation_context(context, result, sender,
3886                                         function_name, (gpointer)net);
3887                 }
3888                 break;
3889         }
3890         case BT_MESH_NETWORK_ADD_APPKEY: {
3891                 bluetooth_mesh_network_t network;
3892                 uint16_t net_idx;
3893
3894                 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3895
3896                 __bt_service_get_parameters(in_param1,
3897                                 &network, sizeof(bluetooth_mesh_network_t));
3898                 __bt_service_get_parameters(in_param2,
3899                                 &net_idx, sizeof(guint16));
3900
3901                 result = _bt_mesh_network_add_appkey(requester_unique_creds,
3902                                 sender, &network, net_idx);
3903
3904                 if (result != BLUETOOTH_ERROR_NONE) {
3905                         g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3906                 } else {
3907                         bluetooth_mesh_network_t *net =  g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3908
3909                         sender = (char*)g_dbus_method_invocation_get_sender(context);
3910                         _bt_save_invocation_context(context, result, sender,
3911                                         function_name, (gpointer)net);
3912                 }
3913                 break;
3914         }
3915         case BT_MESH_NETWORK_UPDATE_APPKEY: {
3916                 bluetooth_mesh_network_t network;
3917                 uint16_t net_idx;
3918                 uint16_t app_idx;
3919
3920                 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3921
3922                 __bt_service_get_parameters(in_param1,
3923                                 &network, sizeof(bluetooth_mesh_network_t));
3924                 __bt_service_get_parameters(in_param2,
3925                                 &net_idx, sizeof(guint16));
3926                 __bt_service_get_parameters(in_param3,
3927                                 &app_idx, sizeof(guint16));
3928
3929                 result = _bt_mesh_network_update_appkey(requester_unique_creds,
3930                                 sender, &network, net_idx, app_idx);
3931
3932                 if (result != BLUETOOTH_ERROR_NONE) {
3933                         g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3934                 } else {
3935                         bluetooth_mesh_network_t *net =  g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3936
3937                         sender = (char*)g_dbus_method_invocation_get_sender(context);
3938                         _bt_save_invocation_context(context, result, sender,
3939                                         function_name, (gpointer)net);
3940                 }
3941                 break;
3942         }
3943         case BT_MESH_NETWORK_DELETE_APPKEY: {
3944                 bluetooth_mesh_network_t network;
3945                 uint16_t net_idx;
3946                 uint16_t app_idx;
3947
3948                 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3949
3950                 __bt_service_get_parameters(in_param1,
3951                                 &network, sizeof(bluetooth_mesh_network_t));
3952                 __bt_service_get_parameters(in_param2,
3953                                 &net_idx, sizeof(guint16));
3954                 __bt_service_get_parameters(in_param3,
3955                                 &app_idx, sizeof(guint16));
3956
3957                 result = _bt_mesh_network_delete_appkey(requester_unique_creds,
3958                                 sender, &network, net_idx, app_idx);
3959
3960                 if (result != BLUETOOTH_ERROR_NONE) {
3961                         g_array_append_vals(*out_param1, &network, sizeof(bluetooth_mesh_network_t));
3962                 } else {
3963                         bluetooth_mesh_network_t *net =  g_memdup(&network, sizeof(bluetooth_mesh_network_t));
3964
3965                         sender = (char*)g_dbus_method_invocation_get_sender(context);
3966                         _bt_save_invocation_context(context, result, sender,
3967                                         function_name, (gpointer)net);
3968                 }
3969                 break;
3970         }
3971         case BT_MESH_NETWORK_GET_NETKEYS: {
3972                 bluetooth_mesh_network_t network;
3973                 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3974                 __bt_service_get_parameters(in_param1,
3975                                 &network, sizeof(bluetooth_mesh_network_t));
3976                 result = _bt_mesh_network_get_netkeys(requester_unique_creds,
3977                                 sender, &network, out_param1);
3978                 break;
3979         }
3980         case BT_MESH_NETWORK_GET_APPKEYS: {
3981                 bluetooth_mesh_network_t network;
3982                 uint16_t net_idx;
3983
3984                 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3985                 __bt_service_get_parameters(in_param1,
3986                                 &network, sizeof(bluetooth_mesh_network_t));
3987                 __bt_service_get_parameters(in_param2,
3988                                 &net_idx, sizeof(guint16));
3989                 result = _bt_mesh_network_get_appkeys(
3990                                 requester_unique_creds, sender,
3991                                         &network, net_idx, out_param1);
3992                 break;
3993         }
3994         case BT_MESH_NETWORK_GET_NODES: {
3995                 bluetooth_mesh_network_t network;
3996                 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
3997                 __bt_service_get_parameters(in_param1,
3998                                 &network, sizeof(bluetooth_mesh_network_t));
3999                 result = _bt_mesh_network_get_nodes(
4000                                 requester_unique_creds, sender,
4001                                         &network, out_param1);
4002                 break;
4003         }
4004         case BT_MESH_ELEMENT_GET_MODELS: {
4005                 bluetooth_mesh_network_t network;
4006                 uint16_t node_addr;
4007                 int elem_idx;
4008
4009                 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4010                 __bt_service_get_parameters(in_param1,
4011                                 &network, sizeof(bluetooth_mesh_network_t));
4012                 __bt_service_get_parameters(in_param2,
4013                                 &node_addr, sizeof(guint16));
4014                 __bt_service_get_parameters(in_param3,
4015                                 &elem_idx, sizeof(int));
4016                 result = _bt_mesh_element_get_models(requester_unique_creds, sender,
4017                                 &network, node_addr, elem_idx, out_param1);
4018                 break;
4019         }
4020         case BT_MESH_NODE_BROWSE: {
4021                 bluetooth_mesh_node_discover_t req;
4022                 memset(&req, 0x00, sizeof(bluetooth_mesh_node_discover_t));
4023
4024                 __bt_service_get_parameters(in_param1,
4025                                 &req, sizeof(bluetooth_mesh_node_discover_t));
4026
4027                 result = _bt_mesh_browse_remote_node(
4028                                 requester_unique_creds, sender, &req);
4029
4030                 /* Save invocation */
4031                 if (result != BLUETOOTH_ERROR_NONE) {
4032                         g_array_append_vals(*out_param1, &req,
4033                                 sizeof(bluetooth_mesh_node_discover_t));
4034                 } else {
4035                         bluetooth_mesh_node_discover_t *param = \
4036                                 g_memdup(&req, sizeof(bluetooth_mesh_node_discover_t));
4037
4038                         sender = (char*)g_dbus_method_invocation_get_sender(context);
4039                         _bt_save_invocation_context(context, result, sender,
4040                                         function_name, (gpointer)param);
4041                 }
4042                 break;
4043         }
4044         case BT_MESH_NODE_GET_VENDOR_FEATURES: {
4045                 bluetooth_mesh_node_features_t req;
4046                 memset(&req, 0x00, sizeof(bluetooth_mesh_node_features_t));
4047
4048                 __bt_service_get_parameters(in_param1,
4049                                 &req, sizeof(bluetooth_mesh_node_features_t));
4050
4051                 result = _bt_mesh_node_discover_vendor_features(
4052                                 requester_unique_creds, sender, &req);
4053
4054                 /* Save invocation */
4055                 if (result != BLUETOOTH_ERROR_NONE) {
4056                         g_array_append_vals(*out_param1,
4057                                 &req, sizeof(bluetooth_mesh_node_features_t));
4058                 } else {
4059                         bluetooth_mesh_node_features_t *param =  \
4060                                 g_memdup(&req, sizeof(bluetooth_mesh_node_features_t));
4061
4062                         sender = (char*)g_dbus_method_invocation_get_sender(context);
4063                         _bt_save_invocation_context(context, result, sender,
4064                                         function_name, (gpointer)param);
4065                 }
4066                 break;
4067         }
4068         case BT_MESH_NODE_CONFIGURE_KEY: {
4069                 bluetooth_mesh_key_configure_t req;
4070
4071                 memset(&req, 0x00, sizeof(bluetooth_mesh_key_configure_t));
4072
4073                 __bt_service_get_parameters(in_param1,
4074                                 &req, sizeof(bluetooth_mesh_key_configure_t));
4075
4076                 result = _bt_mesh_node_configure_key(
4077                                 requester_unique_creds, sender, &req);
4078
4079                 /* Save invocation */
4080                 if (result != BLUETOOTH_ERROR_NONE) {
4081                         g_array_append_vals(*out_param1,
4082                                 &req, sizeof(bluetooth_mesh_key_configure_t));
4083                 } else {
4084                         bluetooth_mesh_key_configure_t *param = \
4085                                 g_memdup(&req, sizeof(bluetooth_mesh_key_configure_t));
4086
4087                         sender = (char*)g_dbus_method_invocation_get_sender(context);
4088                         _bt_save_invocation_context(context, result, sender,
4089                                         function_name, (gpointer)param);
4090                 }
4091                 break;
4092         }
4093         case BT_MESH_NODE_TTL_EXECUTE: {
4094                 bluetooth_mesh_node_ttl_info_t req;
4095
4096                 memset(&req, 0x00, sizeof(bluetooth_mesh_node_ttl_info_t));
4097
4098                 __bt_service_get_parameters(in_param1,
4099                                 &req, sizeof(bluetooth_mesh_node_ttl_info_t));
4100
4101                 result = _bt_mesh_ttl_execute_remote_node(
4102                                 requester_unique_creds, sender, &req);
4103
4104                 /* Save invocation */
4105                 if (result != BLUETOOTH_ERROR_NONE) {
4106                         g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_node_ttl_info_t));
4107                 } else {
4108                         bluetooth_mesh_node_ttl_info_t *param =  \
4109                                 g_memdup(&req, sizeof(bluetooth_mesh_node_ttl_info_t));
4110
4111                         sender = (char*)g_dbus_method_invocation_get_sender(context);
4112                         _bt_save_invocation_context(context, result, sender,
4113                                         function_name, (gpointer)param);
4114                 }
4115                 break;
4116         }
4117         case BT_MESH_MODEL_CONFIGURE_APPKEY: {
4118                 bluetooth_mesh_model_configure_t req;
4119
4120                 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4121
4122                 __bt_service_get_parameters(in_param1,
4123                                 &req, sizeof(bluetooth_mesh_model_configure_t));
4124
4125                 result = _bt_mesh_node_model_appkey_execute(
4126                                 requester_unique_creds, sender, &req);
4127
4128                 /* Save invocation */
4129                 if (result != BLUETOOTH_ERROR_NONE) {
4130                         g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4131                 } else {
4132                         bluetooth_mesh_model_configure_t *param =  \
4133                                 g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4134
4135                         sender = (char*)g_dbus_method_invocation_get_sender(context);
4136                         _bt_save_invocation_context(context, result, sender,
4137                                         function_name, (gpointer)param);
4138                 }
4139                 break;
4140         }
4141         case BT_MESH_MODEL_EXECUTE_MSG: {
4142                 bluetooth_mesh_model_msg_t req;
4143
4144                 memset(&req, 0x00, sizeof(bluetooth_mesh_model_msg_t));
4145
4146                 __bt_service_get_parameters(in_param1,
4147                                 &req, sizeof(bluetooth_mesh_model_msg_t));
4148
4149                 result = _bt_mesh_model_execute_msg(
4150                                 requester_unique_creds, sender, &req);
4151
4152                 /* Save invocation */
4153                 if (result != BLUETOOTH_ERROR_NONE) {
4154                         g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_msg_t));
4155                 } else {
4156                         bluetooth_mesh_model_msg_t *param =  \
4157                                 g_memdup(&req, sizeof(bluetooth_mesh_model_msg_t));
4158
4159                         sender = (char*)g_dbus_method_invocation_get_sender(context);
4160                         _bt_save_invocation_context(context, result, sender,
4161                                         function_name, (gpointer)param);
4162                 }
4163                 break;
4164         }
4165         case BT_MESH_NODE_GET_NETKEYS: {
4166                 bluetooth_mesh_node_discover_t node;
4167                 memset(&node, 0x00, sizeof(bluetooth_mesh_node_discover_t));
4168                 __bt_service_get_parameters(in_param1,
4169                                 &node, sizeof(bluetooth_mesh_node_discover_t));
4170                 result = _bt_mesh_network_node_get_netkeys(
4171                                 requester_unique_creds, &node, out_param1);
4172                 break;
4173         }
4174         case BT_MESH_NODE_GET_APPKEYS: {
4175                 bluetooth_mesh_node_discover_t node;
4176                 memset(&node, 0x00, sizeof(bluetooth_mesh_node_discover_t));
4177                 __bt_service_get_parameters(in_param1,
4178                                 &node, sizeof(bluetooth_mesh_node_discover_t));
4179                 result = _bt_mesh_network_node_get_appkeys(
4180                                 requester_unique_creds, sender, &node, out_param1);
4181                 break;
4182         }
4183         case BT_MESH_NODE_RESET: {
4184                 bluetooth_mesh_node_info_t node;
4185                 memset(&node, 0x00, sizeof(bluetooth_mesh_node_info_t));
4186
4187                 __bt_service_get_parameters(in_param1,
4188                                 &node, sizeof(bluetooth_mesh_node_info_t));
4189
4190                 BT_INFO("Mesh: Reset the Node");
4191                 result = _bt_mesh_network_reset_node(requester_unique_creds,
4192                                 sender, &node);
4193
4194                 break;
4195         }
4196         case BT_MESH_MODEL_GET_APPKEY_LIST: {
4197                 bluetooth_mesh_model_configure_t req;
4198
4199                 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4200
4201                 __bt_service_get_parameters(in_param1,
4202                                 &req, sizeof(bluetooth_mesh_model_configure_t));
4203
4204                 result = _bt_mesh_node_model_get_appkey_list(
4205                                         requester_unique_creds, sender, &req);
4206
4207                 /* Save invocation */
4208                 if (result != BLUETOOTH_ERROR_NONE) {
4209                         g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4210                 } else {
4211                         bluetooth_mesh_model_configure_t *param = \
4212                                 g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4213
4214                         sender = (char*)g_dbus_method_invocation_get_sender(context);
4215                         _bt_save_invocation_context(context, result, sender,
4216                                         function_name, (gpointer)param);
4217                 }
4218                 break;
4219         }
4220         case BT_MESH_MODEL_GET_SUBSCRIPTION_LIST: {
4221                 bluetooth_mesh_model_configure_t req;
4222
4223                 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4224
4225                 __bt_service_get_parameters(in_param1,
4226                                 &req, sizeof(bluetooth_mesh_model_configure_t));
4227
4228                 result = _bt_mesh_node_model_get_subscription_list(
4229                                 requester_unique_creds, sender, &req);
4230
4231                 /* Save invocation */
4232                 if (result != BLUETOOTH_ERROR_NONE) {
4233                         g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4234                 } else {
4235                         bluetooth_mesh_model_configure_t *param =  \
4236                                 g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4237
4238                         sender = (char*)g_dbus_method_invocation_get_sender(context);
4239                         _bt_save_invocation_context(context, result, sender,
4240                                         function_name, (gpointer)param);
4241                 }
4242
4243                 break;
4244         }
4245         case BT_MESH_NETWORK_CREATE_GROUP: {
4246                 bluetooth_mesh_network_t net;
4247                 bluetooth_mesh_network_group_info_t res;
4248                 gboolean is_virtual;
4249                 uint16_t grp_addr;
4250
4251                 memset(&net, 0x00, sizeof(bluetooth_mesh_network_t));
4252                 memset(&res, 0x00, sizeof(bluetooth_mesh_network_group_info_t));
4253
4254                 __bt_service_get_parameters(in_param1,
4255                                 &net, sizeof(bluetooth_mesh_network_t));
4256                 __bt_service_get_parameters(in_param2,
4257                                 &is_virtual, sizeof(gboolean));
4258                 __bt_service_get_parameters(in_param3,
4259                                 &grp_addr, sizeof(guint16));
4260
4261                 result = _bt_mesh_network_create_group(
4262                                 requester_unique_creds, sender, &net,
4263                                         is_virtual, grp_addr, &res);
4264
4265                 if (result == BLUETOOTH_ERROR_NONE)
4266                         g_array_append_vals(*out_param1, &res,
4267                                 sizeof(bluetooth_mesh_network_group_info_t));
4268                 break;
4269         }
4270         case BT_MESH_NETWORK_REMOVE_GROUP: {
4271                 bluetooth_mesh_network_t net;
4272                 bluetooth_mesh_network_group_info_t req;
4273
4274                 memset(&net, 0x00, sizeof(bluetooth_mesh_network_t));
4275                 memset(&req, 0x00, sizeof(bluetooth_mesh_network_group_info_t));
4276
4277                 __bt_service_get_parameters(in_param1,
4278                                 &net, sizeof(bluetooth_mesh_network_t));
4279                 __bt_service_get_parameters(in_param2,
4280                                 &req, sizeof(bluetooth_mesh_network_group_info_t));
4281
4282                 result = _bt_mesh_network_remove_group(
4283                                 requester_unique_creds, sender, &net, &req);
4284
4285                 break;
4286         }
4287         case BT_MESH_MODEL_CONFIG_GROUP_SUB: {
4288                 bluetooth_mesh_model_configure_t req;
4289
4290                 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4291
4292                 __bt_service_get_parameters(in_param1,
4293                                 &req, sizeof(bluetooth_mesh_model_configure_t));
4294
4295                 result = _bt_mesh_model_configure_group_subscription(
4296                                 requester_unique_creds, sender, &req);
4297
4298                 /* Save invocation */
4299                 if (result != BLUETOOTH_ERROR_NONE) {
4300                         g_array_append_vals(*out_param1,
4301                                 &req, sizeof(bluetooth_mesh_model_configure_t));
4302                 } else {
4303                         bluetooth_mesh_model_configure_t *param =  \
4304                                 g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4305
4306                         sender = (char*)g_dbus_method_invocation_get_sender(context);
4307                         _bt_save_invocation_context(context, result, sender,
4308                                         function_name, (gpointer)param);
4309                 }
4310                 break;
4311         }
4312         case BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB: {
4313                 bluetooth_mesh_model_configure_t req;
4314
4315                 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4316
4317                 __bt_service_get_parameters(in_param1,
4318                                 &req, sizeof(bluetooth_mesh_model_configure_t));
4319
4320                 result = _bt_mesh_model_configure_virtual_group_subscription(
4321                                 requester_unique_creds, sender, &req);
4322
4323                 /* Save invocation */
4324                 if (result != BLUETOOTH_ERROR_NONE) {
4325                         g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4326                 } else {
4327                         bluetooth_mesh_model_configure_t *param =  \
4328                                 g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4329
4330                         sender = (char*)g_dbus_method_invocation_get_sender(context);
4331                         _bt_save_invocation_context(context, result, sender,
4332                                         function_name, (gpointer)param);
4333                 }
4334                 break;
4335         }
4336         case BT_MESH_MODEL_SET_PUBLICATION: {
4337                 bluetooth_mesh_model_configure_t req;
4338
4339                 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4340
4341                 __bt_service_get_parameters(in_param1,
4342                                 &req, sizeof(bluetooth_mesh_model_configure_t));
4343
4344                 result = _bt_mesh_model_set_publication(
4345                                 requester_unique_creds, sender, &req);
4346
4347                 /* Save invocation */
4348                 if (result != BLUETOOTH_ERROR_NONE) {
4349                         g_array_append_vals(*out_param1, &req, sizeof(bluetooth_mesh_model_configure_t));
4350                 } else {
4351                         bluetooth_mesh_model_configure_t *param = g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4352
4353                         sender = (char*)g_dbus_method_invocation_get_sender(context);
4354                         _bt_save_invocation_context(context, result, sender,
4355                                         function_name, (gpointer)param);
4356                 }
4357                 break;
4358         }
4359         case BT_MESH_MODEL_GET_PUBLICATION: {
4360                 bluetooth_mesh_model_configure_t req;
4361
4362                 memset(&req, 0x00, sizeof(bluetooth_mesh_model_configure_t));
4363
4364                 __bt_service_get_parameters(in_param1,
4365                                 &req, sizeof(bluetooth_mesh_model_configure_t));
4366
4367                 result = _bt_mesh_model_get_publication(
4368                                         requester_unique_creds, sender, &req);
4369
4370                 /* Save invocation */
4371                 if (result != BLUETOOTH_ERROR_NONE) {
4372                         g_array_append_vals(*out_param1,
4373                                 &req, sizeof(bluetooth_mesh_model_configure_t));
4374                 } else {
4375                         bluetooth_mesh_model_configure_t *param =  \
4376                                 g_memdup(&req, sizeof(bluetooth_mesh_model_configure_t));
4377
4378                         sender = (char*)g_dbus_method_invocation_get_sender(context);
4379                         _bt_save_invocation_context(context, result, sender,
4380                                         function_name, (gpointer)param);
4381                 }
4382                 break;
4383         }
4384         case BT_MESH_NETWORK_GET_GROUPS: {
4385                 bluetooth_mesh_network_t network;
4386                 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
4387                 __bt_service_get_parameters(in_param1,
4388                                 &network, sizeof(bluetooth_mesh_network_t));
4389                 BT_INFO("Mesh: Request:: Get Groups");
4390                 result = _bt_mesh_network_get_groups(
4391                                 requester_unique_creds, sender, &network, out_param1);
4392                 break;
4393         }
4394         default:
4395                 BT_INFO("UnSupported function [%d]", function_name);
4396                 result = BLUETOOTH_ERROR_NOT_SUPPORT;
4397                 break;
4398         }
4399
4400         return result;
4401 }
4402 #ifdef TIZEN_FEATURE_BT_OBEX
4403 /* Function definitions*/
4404 static void __bt_fill_garray_from_variant(GVariant *var, GArray *param)
4405 {
4406         char *data;
4407         int size;
4408
4409         size = g_variant_get_size(var);
4410         if (size > 0) {
4411                 data = (char *)g_variant_get_data(var);
4412                 if (data)
4413                         param = g_array_append_vals(param, data, size);
4414
4415         }
4416 }
4417 #endif
4418
4419 int __bt_obexd_request(int function_name,
4420                 int request_type,
4421                 int request_id,
4422                 GDBusMethodInvocation *context,
4423                 GVariant *in_param1,
4424                 GVariant *in_param2,
4425                 GVariant *in_param3,
4426                 GVariant *in_param4,
4427                 GArray **out_param1)
4428 {
4429         BT_DBG("+");
4430
4431         int result = BLUETOOTH_ERROR_NONE;
4432
4433         BT_DBG("function_name : %x", function_name);
4434
4435         switch (function_name) {
4436         case BT_OPP_PUSH_FILES: {
4437                 BT_DBG("BT_OPP_PUSH_FILES");
4438                 int i;
4439                 bluetooth_device_address_t address = { {0} };
4440                 bt_file_path_t *path;
4441                 char **file_path;
4442                 int file_count;
4443                 GArray *param2;
4444
4445                 __bt_service_get_parameters(in_param1, &address,
4446                                 sizeof(bluetooth_device_address_t));
4447                 __bt_service_get_parameters(in_param3, &file_count,
4448                                 sizeof(int));
4449
4450                 file_path = g_new0(char *, file_count + 1);
4451
4452                 param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
4453                 __bt_fill_garray_from_variant(in_param2, param2);
4454
4455                 for (i = 0; i < file_count; i++) {
4456                         path = &g_array_index(param2, bt_file_path_t, i);
4457                         file_path[i] = g_strdup(path->path);
4458                 }
4459                 BT_DBG("_bt_opp_client_push_files");
4460                 result = _bt_opp_client_push_files(request_id, context,
4461                                                 &address, file_path,
4462                                                 file_count);
4463
4464                 for (i = 0; i < file_count; i++)
4465                         g_free(file_path[i]);
4466
4467                 g_free(file_path);
4468                 g_array_free(param2, TRUE);
4469
4470                 break;
4471         }
4472         case BT_OPP_CANCEL_PUSH: {
4473                 result = _bt_opp_client_cancel_push();
4474
4475                 break;
4476         }
4477         case BT_OPP_IS_PUSHING_FILES: {
4478                 gboolean is_sending = FALSE;
4479
4480                 result = _bt_opp_client_is_sending(&is_sending);
4481
4482                 g_array_append_vals(*out_param1, &is_sending,
4483                                 sizeof(gboolean));
4484                 break;
4485         }
4486         case BT_OPP_GET_TRANSFER_PROGRESS: {
4487                 int direction;
4488                 int transfer_id;
4489                 guint8 progress = 0;
4490
4491                 __bt_service_get_parameters(in_param1, &direction,
4492                                 sizeof(int));
4493                 __bt_service_get_parameters(in_param2, &transfer_id,
4494                                 sizeof(int));
4495                 if (direction)
4496                         result = _bt_opp_get_client_progress(&progress);
4497                 else
4498                         result = _bt_opp_get_server_progress(transfer_id, &progress);
4499
4500                 g_array_append_vals(*out_param1, &progress,
4501                                 sizeof(guint8));
4502
4503                 break;
4504         }
4505
4506         case BT_MAP_CREATE_SESSION: {
4507                 BT_DBG("BT_MAP_CREATE_SESSION");
4508                 char *address = (char *)g_variant_get_data(in_param1);
4509                 char *session_id = NULL;
4510                 result = _bt_create_session_sync(address, &session_id);
4511                 if (result == BLUETOOTH_ERROR_NONE)
4512                         g_array_append_vals(*out_param1, session_id, strlen(session_id)+1);
4513                 break;
4514         }
4515
4516         case BT_MAP_DESTROY_SESSION: {
4517                 BT_DBG("BT_MAP_DESTROY_SESSION");
4518                 char* session_id = (char *)g_variant_get_data(in_param1);
4519                 result = _bt_destroy_session_sync(session_id);
4520                 if (result == BLUETOOTH_ERROR_NONE)
4521                         BT_DBG("successfully destroyed session");
4522                 break;
4523         }
4524
4525         case BT_MAP_SET_FOLDER: {
4526                 BT_DBG("BT_MAP_SET_FOLDER");
4527                 char *session_id = (char *)g_variant_get_data(in_param1);
4528                 char *name = (char *)g_variant_get_data(in_param2);
4529                 result = _bt_map_client_set_folder(session_id, name);
4530                 break;
4531         }
4532
4533         case BT_MAP_LIST_FOLDERS: {
4534                 BT_DBG("BT_MAP_LIST_FOLDERS");
4535
4536                 char* session_id = (char *)g_variant_get_data(in_param1);
4537                 char* filter_serialized = (char*)g_variant_get_data(in_param2);
4538
4539                 result = _bt_map_client_list_folders(request_id, context, session_id, filter_serialized);
4540                 if (result == BLUETOOTH_ERROR_NONE)
4541                         BT_DBG("_bt_map_client_list_folders succeed");
4542
4543                 break;
4544         }
4545
4546         case BT_MAP_LIST_FILTER_FIELDS: {
4547                 BT_DBG("BT_MAP_LIST_FILTER_FIELDS");
4548
4549                 char* session_id = (char *)g_variant_get_data(in_param1);
4550
4551                 result = _bt_map_client_list_filter_fields(request_id, context, session_id);
4552                 if (result == BLUETOOTH_ERROR_NONE)
4553                         BT_DBG("_bt_map_client_list_filter_fields succeed");
4554
4555                 break;
4556         }
4557
4558         case BT_MAP_LIST_MESSAGES: {
4559                 BT_DBG("BT_MAP_LIST_MESSAGES");
4560
4561                 char* session_id = (char*)g_variant_get_data(in_param1);
4562                 char* folder = (char*)g_variant_get_data(in_param2);
4563                 char* filter_serialized = (char*)g_variant_get_data(in_param3);
4564
4565                 result = _bt_map_client_list_messages(request_id, context, session_id, folder, filter_serialized);
4566                 if (result == BLUETOOTH_ERROR_NONE)
4567                         BT_DBG("_bt_map_client_list_messages succeed");
4568                 else
4569                         BT_DBG("_bt_map_client_list_messages failed");
4570
4571                 break;
4572         }
4573
4574         case BT_MAP_UPDATE_INBOX: {
4575                 BT_DBG("BT_MAP_UPDATE_INBOX");
4576                 char* session_id = (char *)g_variant_get_data(in_param1);
4577                 result = _bt_map_client_update_inbox(session_id);
4578                 break;
4579         }
4580
4581         case BT_MAP_PUSH_MESSAGE: {
4582                 BT_DBG("BT_MAP_PUSH_MESSAGE");
4583
4584                 char* session_id = (char *)g_variant_get_data(in_param1);
4585                 char* source_file = (char *)g_variant_get_data(in_param2);
4586                 char* folder = (char *)g_variant_get_data(in_param3);
4587                 char* args_serialized = (char *)g_variant_get_data(in_param4);
4588
4589                 result = _bt_map_client_push_message(
4590                                 request_id, context, session_id, source_file, folder, args_serialized);
4591                 if (result == BLUETOOTH_ERROR_NONE)
4592                         BT_DBG("_bt_map_client_push_message succeed");
4593                 else
4594                         BT_ERR("_bt_map_client_push_message failed");
4595
4596                 break;
4597         }
4598
4599         case BT_MAP_GET_MESSAGE: {
4600                 BT_DBG("BT_MAP_GET_MESSAGE");
4601                 // TODO session currently is not used, but should be valid
4602                 //char* session_id = (char *)g_variant_get_data(in_param1);
4603                 char* message_object = (char *)g_variant_get_data(in_param2);
4604                 char* target_file = (char *)g_variant_get_data(in_param3);
4605                 bool attachment = false;
4606                 __bt_service_get_parameters(in_param4, &attachment, sizeof(bool));
4607
4608                 result = _bt_map_client_get_message(request_id, context, message_object,
4609                                 target_file, attachment);
4610                 if (result == BLUETOOTH_ERROR_NONE)
4611                         BT_DBG("_bt_map_client_get_message succeed");
4612
4613                 break;
4614         }
4615
4616         case BT_OBEX_SERVER_ALLOCATE: {
4617                 int app_pid;
4618                 gboolean is_native;
4619                 char *path;
4620                 char *sender;
4621
4622                 sender = (char *)g_dbus_method_invocation_get_sender(context);
4623
4624                 path = (char *)g_variant_get_data(in_param1);
4625                 __bt_service_get_parameters(in_param2, &is_native,
4626                                 sizeof(gboolean));
4627                 __bt_service_get_parameters(in_param3, &app_pid,
4628                                 sizeof(int));
4629
4630                 result = _bt_obex_server_allocate(sender,
4631                                 path, app_pid, is_native);
4632
4633                 break;
4634         }
4635         case BT_OBEX_SERVER_DEALLOCATE: {
4636                 int app_pid;
4637                 gboolean is_native;
4638
4639                 __bt_service_get_parameters(in_param1, &is_native,
4640                                 sizeof(gboolean));
4641                 __bt_service_get_parameters(in_param2, &app_pid,
4642                                 sizeof(int));
4643
4644                 result = _bt_obex_server_deallocate(app_pid, is_native);
4645                 break;
4646         }
4647         case BT_OBEX_SERVER_IS_ACTIVATED: {
4648                 gboolean is_activated = FALSE;
4649
4650                 result = _bt_obex_server_is_activated(&is_activated);
4651
4652                 g_array_append_vals(*out_param1, &is_activated,
4653                                 sizeof(gboolean));
4654
4655                 break;
4656         }
4657         case BT_OBEX_SERVER_ACCEPT_CONNECTION: {
4658                 result = _bt_obex_server_accept_connection(request_id);
4659
4660                 break;
4661         }
4662         case BT_OBEX_SERVER_REJECT_CONNECTION: {
4663                 result = _bt_obex_server_reject_connection();
4664
4665                 break;
4666         }
4667         case BT_OBEX_SERVER_ACCEPT_FILE: {
4668                 char *file_name;
4669
4670                 file_name = (char *)g_variant_get_data(in_param1);
4671
4672                 result = _bt_obex_server_accept_authorize(file_name, TRUE);
4673
4674                 break;
4675         }
4676         case BT_OBEX_SERVER_REJECT_FILE: {
4677                 result = _bt_obex_server_reject_authorize();
4678
4679                 break;
4680         }
4681         case BT_OBEX_SERVER_SET_PATH: {
4682                 gboolean is_native;
4683                 char *destination_path;
4684
4685                 destination_path = (char *)g_variant_get_data(in_param1);
4686                 __bt_service_get_parameters(in_param2, &is_native,
4687                                 sizeof(gboolean));
4688
4689                 result = _bt_obex_server_set_destination_path(destination_path,
4690                                                         is_native);
4691
4692                 break;
4693         }
4694         case BT_OBEX_SERVER_SET_ROOT: {
4695                 char *root;
4696
4697                 root = (char *)g_variant_get_data(in_param1);
4698
4699                 result = _bt_obex_server_set_root(root);
4700
4701                 break;
4702         }
4703         case BT_OBEX_SERVER_CANCEL_TRANSFER: {
4704                 int transfer_id;
4705
4706                 __bt_service_get_parameters(in_param1, &transfer_id,
4707                                 sizeof(int));
4708
4709                 result = _bt_obex_server_cancel_transfer(transfer_id);
4710
4711                 break;
4712         }
4713         case BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS: {
4714                 result = _bt_obex_server_cancel_all_transfers();
4715
4716                 break;
4717         }
4718         case BT_OBEX_SERVER_IS_RECEIVING: {
4719                 gboolean is_receiving = FALSE;
4720
4721                 result = _bt_obex_server_is_receiving(&is_receiving);
4722
4723                 g_array_append_vals(*out_param1, &is_receiving,
4724                                 sizeof(gboolean));
4725                 break;
4726         }
4727         case BT_PBAP_CONNECT: {
4728                 bluetooth_device_address_t address = { {0} };
4729
4730                 __bt_service_get_parameters(in_param1, &address,
4731                                 sizeof(bluetooth_device_address_t));
4732
4733                 result = _bt_pbap_connect(&address);
4734                 break;
4735         }
4736         case BT_PBAP_DISCONNECT: {
4737                 bluetooth_device_address_t address = { {0} };
4738
4739                 __bt_service_get_parameters(in_param1, &address,
4740                                 sizeof(bluetooth_device_address_t));
4741
4742                 result = _bt_pbap_disconnect(&address);
4743                 break;
4744         }
4745         case BT_PBAP_GET_PHONEBOOK_SIZE: {
4746                 bluetooth_device_address_t address = { {0} };
4747                 bt_pbap_folder_t folder = { 0, };
4748
4749                 __bt_service_get_parameters(in_param1, &address,
4750                                 sizeof(bluetooth_device_address_t));
4751                 __bt_service_get_parameters(in_param2, &folder,
4752                                 sizeof(bt_pbap_folder_t));
4753
4754                 result = _bt_pbap_get_phonebook_size(&address,
4755                                 folder.addressbook, folder.folder_type);
4756                 break;
4757         }
4758         case BT_PBAP_GET_PHONEBOOK: {
4759                 bluetooth_device_address_t address = { {0} };
4760                 bt_pbap_folder_t folder = { 0, };
4761                 bt_pbap_pull_parameters_t app_param = { 0, };
4762
4763                 __bt_service_get_parameters(in_param1, &address,
4764                                 sizeof(bluetooth_device_address_t));
4765                 __bt_service_get_parameters(in_param2, &folder,
4766                                 sizeof(bt_pbap_folder_t));
4767                 __bt_service_get_parameters(in_param3, &app_param,
4768                                 sizeof(bt_pbap_pull_parameters_t));
4769
4770                 result = _bt_pbap_get_phonebook(&address, folder.addressbook,
4771                                 folder.folder_type, &app_param);
4772                 break;
4773         }
4774         case BT_PBAP_GET_LIST: {
4775                 bluetooth_device_address_t address = { {0} };
4776                 bt_pbap_folder_t folder = { 0, };
4777                 bt_pbap_list_parameters_t app_param = { 0, };
4778
4779                 __bt_service_get_parameters(in_param1, &address,
4780                                 sizeof(bluetooth_device_address_t));
4781                 __bt_service_get_parameters(in_param2, &folder,
4782                                 sizeof(bt_pbap_folder_t));
4783                 __bt_service_get_parameters(in_param3, &app_param,
4784                                 sizeof(bt_pbap_list_parameters_t));
4785
4786                 result = _bt_pbap_get_list(&address, folder.addressbook,
4787                                 folder.folder_type, &app_param);
4788                 break;
4789         }
4790         case BT_PBAP_PULL_VCARD: {
4791                 bluetooth_device_address_t address = { {0} };
4792                 bt_pbap_folder_t folder = { 0, };
4793                 bt_pbap_pull_vcard_parameters_t app_param = { 0, };
4794
4795                 __bt_service_get_parameters(in_param1, &address,
4796                                 sizeof(bluetooth_device_address_t));
4797                 __bt_service_get_parameters(in_param2, &folder,
4798                                 sizeof(bt_pbap_folder_t));
4799                 __bt_service_get_parameters(in_param3, &app_param,
4800                                 sizeof(bt_pbap_pull_vcard_parameters_t));
4801
4802                 result = _bt_pbap_pull_vcard(&address, folder.addressbook,
4803                                 folder.folder_type, &app_param);
4804                 break;
4805         }
4806         case BT_PBAP_PHONEBOOK_SEARCH: {
4807                 bluetooth_device_address_t address = { {0} };
4808                 bt_pbap_folder_t folder = { 0, };
4809                 bt_pbap_search_parameters_t app_param = { 0, };
4810
4811                 __bt_service_get_parameters(in_param1, &address,
4812                                 sizeof(bluetooth_device_address_t));
4813                 __bt_service_get_parameters(in_param2, &folder,
4814                                 sizeof(bt_pbap_folder_t));
4815                 __bt_service_get_parameters(in_param3, &app_param,
4816                                 sizeof(bt_pbap_search_parameters_t));
4817
4818                 result = _bt_pbap_phonebook_search(&address, folder.addressbook,
4819                                 folder.folder_type, &app_param);
4820                 break;
4821         }
4822
4823         default:
4824                 BT_ERR("Unknown function!");
4825                 result = BLUETOOTH_ERROR_INTERNAL;
4826                 break;
4827         }
4828
4829         FN_END;
4830
4831         return result;
4832 }
4833
4834 int __bt_agent_request(int function_name,
4835                 int request_type,
4836                 int request_id,
4837                 GDBusMethodInvocation *context,
4838                 GVariant *in_param1,
4839                 GVariant *in_param2,
4840                 GVariant *in_param3,
4841                 GVariant *in_param4,
4842                 GArray **out_param1)
4843 {
4844         int result;
4845         switch (function_name) {
4846         case BT_SET_AUTHORIZATION: {
4847                 int type;
4848                 char *uuid;
4849                 char *path;
4850                 int fd;
4851                 char *sender;
4852
4853                 sender = (char *)g_dbus_method_invocation_get_sender(context);
4854                 __bt_service_get_parameters(in_param1, &type, sizeof(int));
4855                 uuid = (char *)g_variant_get_data(in_param2);
4856                 path = (char *)g_variant_get_data(in_param3);
4857                 __bt_service_get_parameters(in_param4, &fd, sizeof(int));
4858
4859                 result = _bt_register_osp_server_in_agent(sender, type, uuid, path, fd);
4860                 break;
4861         }
4862         case BT_UNSET_AUTHORIZATION: {
4863                 int type;
4864                 char *uuid;
4865
4866                 __bt_service_get_parameters(in_param1, &type, sizeof(int));
4867                 uuid = (char *)g_variant_get_data(in_param2);
4868
4869                 result = _bt_unregister_osp_server_in_agent(type, uuid);
4870                 break;
4871         }
4872         default:
4873                 BT_ERR("Unknown function!");
4874                 result = BLUETOOTH_ERROR_INTERNAL;
4875                 break;
4876         }
4877
4878         return result;
4879 }
4880
4881 int __bt_core_request(int function_name,
4882                 int request_type,
4883                 int request_id,
4884                 GDBusMethodInvocation *context,
4885                 GVariant *in_param1)
4886 {
4887         int result;
4888
4889         switch (function_name) {
4890         case BT_ENABLE_ADAPTER:
4891         {
4892                 bt_status_t status;
4893                 _bt_set_adapter_request_state(TRUE);
4894                 status = _bt_adapter_get_status();
4895
4896                 if (status == BT_ACTIVATING) {
4897                         BT_DBG("Enabling in progress");
4898                         result = BLUETOOTH_ERROR_IN_PROGRESS;
4899                 } else if (status == BT_ACTIVATED) {
4900                         BT_DBG("Already enabled");
4901                         result = BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
4902                 } else {
4903                         _bt_adapter_set_status(BT_ACTIVATING);
4904                         result = BLUETOOTH_ERROR_NONE;
4905                 }
4906
4907                 break;
4908         }
4909         case BT_DISABLE_ADAPTER:
4910         {
4911                 bt_status_t status;
4912
4913                 status = _bt_adapter_get_status();
4914                 if (status == BT_DEACTIVATING) {
4915                                 BT_DBG("Disabling in progress");
4916                                 result = BLUETOOTH_ERROR_IN_PROGRESS;
4917                 } else if (status == BT_DEACTIVATED) {
4918                                 BT_DBG("Already disabled");
4919                                 result = BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
4920                 } else {
4921                         _bt_adapter_set_status(BT_DEACTIVATING);
4922                         result = BLUETOOTH_ERROR_NONE;
4923                 }
4924
4925                 break;
4926         }
4927         case BT_ENABLE_ADAPTER_LE:
4928         {
4929                 bt_le_status_t le_status;
4930                 _bt_set_le_request_state(TRUE);
4931                 le_status = _bt_adapter_get_le_status();
4932                 if (le_status == BT_LE_ACTIVATING) {
4933                         BT_DBG("Enabling in progress");
4934                         result = BLUETOOTH_ERROR_IN_PROGRESS;
4935                 } else if (le_status == BT_LE_ACTIVATED) {
4936                         BT_DBG("Already enabled");
4937                         result = BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
4938                 } else {
4939                         _bt_adapter_set_le_status(BT_LE_ACTIVATING);
4940                         result = BLUETOOTH_ERROR_NONE;
4941                 }
4942
4943                 break;
4944         }
4945         case BT_DISABLE_ADAPTER_LE:
4946         {
4947                 bt_le_status_t le_status;
4948
4949                 le_status = _bt_adapter_get_le_status();
4950                 if (le_status == BT_LE_DEACTIVATING) {
4951                                 BT_DBG("Disabling in progress");
4952                                 result = BLUETOOTH_ERROR_IN_PROGRESS;
4953                 } else if (le_status == BT_LE_DEACTIVATED) {
4954                                 BT_DBG("Already disabled");
4955                                 result = BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
4956                 } else {
4957                         _bt_adapter_set_le_status(BT_LE_DEACTIVATING);
4958                         result = BLUETOOTH_ERROR_NONE;
4959                 }
4960
4961                 break;
4962         }
4963         default:
4964                 BT_ERR("Unknown function!");
4965                 result = BLUETOOTH_ERROR_INTERNAL;
4966                 break;
4967         }
4968
4969         return result;
4970 }
4971
4972 static int __bt_service_get_requester_app_id(const char *unique_name, char *app_id, int len)
4973 {
4974         int ret;
4975         pid_t pid = 0;
4976
4977         retv_if(bt_service_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
4978         retv_if(unique_name == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
4979
4980         ret = __bt_service_get_sender_pid(unique_name, &pid);
4981         if (ret != BLUETOOTH_ERROR_NONE) {
4982                 BT_ERR("Fail to get the sender pid");
4983                 return ret;
4984         }
4985
4986         ret = aul_app_get_appid_bypid(pid, app_id, len);
4987         if (ret != AUL_R_OK) {
4988                 BT_ERR("app_id not found");
4989                 return BLUETOOTH_ERROR_NOT_SUPPORT;
4990         }
4991         BT_DBG("Sender app_id: %s", app_id);
4992
4993         return BLUETOOTH_ERROR_NONE;
4994 }
4995
4996 gboolean __bt_service_check_privilege(int function_name,
4997                                         int service_type,
4998                                         const char *unique_name)
4999 {
5000         int ret_val;
5001         gboolean result = TRUE;
5002         char *client_creds = NULL;
5003         char *user_creds = NULL;
5004         char *client_session = "";
5005         enum cynara_client_creds client_creds_method = CLIENT_METHOD_SMACK;
5006         enum cynara_user_creds user_creds_method = USER_METHOD_UID;
5007         char err_msg[256] = {0, };
5008
5009         retv_if(unique_name == NULL, FALSE);
5010         retv_if(bt_service_conn == NULL, FALSE);
5011
5012         ret_val = cynara_creds_get_default_client_method(&client_creds_method);
5013         if (ret_val != CYNARA_API_SUCCESS) {
5014                 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
5015                 BT_ERR("Fail to get default client method: %s", err_msg);
5016                 return FALSE;
5017         }
5018
5019         ret_val = cynara_creds_get_default_user_method(&user_creds_method);
5020         if (ret_val != CYNARA_API_SUCCESS) {
5021                 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
5022                 BT_ERR("Fail to get default user method: %s", err_msg);
5023                 return FALSE;
5024         }
5025
5026         ret_val = cynara_creds_gdbus_get_client(bt_service_conn, unique_name, client_creds_method, &client_creds);
5027         if (ret_val != CYNARA_API_SUCCESS) {
5028                 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
5029                 BT_ERR("Fail to get client credential: %s", err_msg);
5030                 return FALSE;
5031         }
5032
5033         ret_val = cynara_creds_gdbus_get_user(bt_service_conn, unique_name, user_creds_method, &user_creds);
5034         if (ret_val != CYNARA_API_SUCCESS) {
5035                 cynara_strerror(ret_val, err_msg, sizeof(err_msg));
5036                 BT_ERR("Fail to get user credential: %s", err_msg);
5037                 if (client_creds)
5038                         free(client_creds);
5039                 return FALSE;
5040         }
5041
5042         BT_DBG("%s, %s, %s", unique_name, client_creds, user_creds);
5043
5044         switch (function_name) {
5045         case BT_SET_LOCAL_NAME:
5046         case BT_START_DISCOVERY:
5047         case BT_START_CUSTOM_DISCOVERY:
5048         case BT_CANCEL_DISCOVERY:
5049         case BT_OOB_ADD_REMOTE_DATA:
5050         case BT_OOB_REMOVE_REMOTE_DATA:
5051         case BT_OOB_READ_LOCAL_DATA:
5052         case BT_SET_ADVERTISING:
5053         case BT_SET_CUSTOM_ADVERTISING:
5054         case BT_SET_ADVERTISING_PARAMETERS:
5055         case BT_START_LE_DISCOVERY:
5056         case BT_STOP_LE_DISCOVERY:
5057         case BT_SET_SCAN_PARAMETERS:
5058         case BT_SET_SCAN_TYPE:
5059         case BT_UPDATE_LE_CONNECTION_MODE:
5060
5061         case BT_BOND_DEVICE:
5062         case BT_CANCEL_BONDING:
5063         case BT_UNBOND_DEVICE:
5064         case BT_SET_ALIAS:
5065         case BT_SET_AUTHORIZATION:
5066         case BT_UNSET_AUTHORIZATION:
5067         case BT_SEARCH_SERVICE:
5068
5069         case BT_RFCOMM_CLIENT_CONNECT:
5070                 if (function_name == BT_RFCOMM_CLIENT_CONNECT)
5071                         BT_PERMANENT_LOG("Connect socket");
5072         case BT_RFCOMM_CLIENT_CANCEL_CONNECT:
5073         case BT_RFCOMM_SOCKET_DISCONNECT:
5074                 if (function_name == BT_RFCOMM_SOCKET_DISCONNECT)
5075                         BT_PERMANENT_LOG("Disconnect socket");
5076         case BT_RFCOMM_SOCKET_WRITE:
5077         case BT_RFCOMM_CREATE_SOCKET:
5078         case BT_RFCOMM_REMOVE_SOCKET:
5079         case BT_RFCOMM_SEND_RX_DETAILS:
5080         case BT_RFCOMM_SEND_TX_DETAILS:
5081         case BT_RFCOMM_UPDATE_CONNECTION_INFO:
5082
5083         case BT_OPP_PUSH_FILES:
5084         case BT_OPP_CANCEL_PUSH:
5085         /* TODO: MAP? MAP functions, see above */
5086
5087         case BT_OBEX_SERVER_ACCEPT_CONNECTION:
5088         case BT_OBEX_SERVER_REJECT_CONNECTION:
5089         case BT_OBEX_SERVER_ACCEPT_FILE:
5090         case BT_OBEX_SERVER_REJECT_FILE:
5091         case BT_OBEX_SERVER_SET_PATH:
5092         case BT_OBEX_SERVER_SET_ROOT:
5093         case BT_OBEX_SERVER_CANCEL_TRANSFER:
5094         case BT_OBEX_SERVER_CANCEL_ALL_TRANSFERS:
5095
5096         case BT_AUDIO_SELECT_ROLE:
5097         case BT_AUDIO_CONNECT:
5098         case BT_AUDIO_DISCONNECT:
5099         case BT_AG_CONNECT:
5100         case BT_AG_DISCONNECT:
5101         case BT_AV_CONNECT:
5102         case BT_AV_DISCONNECT:
5103         case BT_AV_SOURCE_CONNECT:
5104         case BT_AV_SOURCE_DISCONNECT:
5105         case BT_AVRCP_TARGET_CONNECT:
5106         case BT_AVRCP_TARGET_DISCONNECT:
5107         case BT_AVRCP_CONTROL_CONNECT:
5108         case BT_AVRCP_CONTROL_DISCONNECT:
5109         case BT_AVRCP_HANDLE_CONTROL:
5110         case BT_AVRCP_SET_TRACK_INFO:
5111         case BT_AVRCP_SET_PROPERTY:
5112         case BT_AVRCP_SET_PROPERTIES:
5113         case BT_AVRCP_CONTROL_SET_PROPERTY:
5114
5115         case BT_AUDIO_SET_ABSOLUTE_VOLUME:
5116         case BT_AUDIO_GET_ABSOLUTE_VOLUME:
5117         case BT_AUDIO_IS_AVC_ACTIVATED:
5118
5119         case BT_HF_CONNECT:
5120         case BT_HF_DISCONNECT:
5121
5122         case BT_HID_CONNECT:
5123         case BT_HID_DISCONNECT:
5124
5125         case BT_HID_DEVICE_ACTIVATE:
5126         case BT_HID_DEVICE_DEACTIVATE:
5127         case BT_HID_DEVICE_CONNECT:
5128         case BT_HID_DEVICE_DISCONNECT:
5129         case BT_HID_DEVICE_SEND_MOUSE_EVENT:
5130         case BT_HID_DEVICE_SEND_KEY_EVENT:
5131         case BT_HID_DEVICE_SEND_REPLY_TO_REPORT:
5132         case BT_HID_DEVICE_SEND_CUSTOM_EVENT:
5133
5134         case BT_CONNECT_LE:
5135         case BT_DISCONNECT_LE:
5136
5137         case BT_SET_ADVERTISING_DATA:
5138         case BT_SET_SCAN_RESPONSE_DATA:
5139
5140         case BT_HDP_CONNECT:
5141         case BT_HDP_DISCONNECT:
5142         case BT_HDP_SEND_DATA:
5143         case BT_HDP_REGISTER_SINK_APP:
5144         case BT_HDP_UNREGISTER_SINK_APP:
5145         case BT_HDP_GET_FD:
5146
5147         case BT_DPM_SET_ALLOW_BT_MODE:
5148         case BT_DPM_GET_ALLOW_BT_MODE:
5149         case BT_DPM_SET_DEVICE_RESTRITION:
5150         case BT_DPM_GET_DEVICE_RESTRITION:
5151         case BT_DPM_SET_UUID_RESTRITION:
5152         case BT_DPM_GET_UUID_RESTRITION:
5153         case BT_DPM_ADD_DEVICES_BLACKLIST:
5154         case BT_DPM_ADD_DEVICES_WHITELIST:
5155         case BT_DPM_ADD_UUIDS_BLACKLIST:
5156         case BT_DPM_ADD_UUIDS_WHITELIST:
5157         case BT_DPM_CLEAR_DEVICES_BLACKLIST:
5158         case BT_DPM_CLEAR_DEVICES_WHITELIST:
5159         case BT_DPM_CLEAR_UUIDS_BLACKLIST:
5160         case BT_DPM_CLEAR_UUIDS_WHITELIST:
5161         case BT_DPM_REMOVE_DEVICE_BLACKLIST:
5162         case BT_DPM_REMOVE_DEVICE_WHITELIST:
5163         case BT_DPM_REMOVE_UUID_BLACKLIST:
5164         case BT_DPM_REMOVE_UUID_WHITELIST:
5165         case BT_DPM_GET_DEVICES_BLACKLIST:
5166         case BT_DPM_GET_DEVICES_WHITELIST:
5167         case BT_DPM_GET_UUIDS_BLACKLIST:
5168         case BT_DPM_GET_UUIDS_WHITELIST:
5169         case BT_DPM_SET_ALLOW_OUTGOING_CALL:
5170         case BT_DPM_GET_ALLOW_OUTGOING_CALL:
5171         case BT_DPM_SET_PAIRING_STATE:
5172         case BT_DPM_GET_PAIRING_STATE:
5173         case BT_DPM_SET_PROFILE_STATE:
5174         case BT_DPM_GET_PROFILE_STATE:
5175         case BT_DPM_SET_DESKROP_CONNECTIVITY_STATE:
5176         case BT_DPM_GET_DESKROP_CONNECTIVITY_STATE:
5177         case BT_DPM_SET_DISCOVERABLE_STATE:
5178         case BT_DPM_GET_DISCOVERABLE_STATE:
5179         case BT_DPM_SET_LIMITED_DISCOVERABLE_STATE:
5180         case BT_DPM_GET_LIMITED_DISCOVERABLE_STATE:
5181         case BT_DPM_SET_DATA_TRANSFER_STATE:
5182         case BT_DPM_GET_DATA_TRANSFER_STATE:
5183
5184         case BT_NETWORK_ACTIVATE:
5185         case BT_NETWORK_DEACTIVATE:
5186         case BT_NETWORK_CONNECT:
5187         case BT_NETWORK_DISCONNECT:
5188         case BT_NETWORK_SERVER_DISCONNECT:
5189
5190         case BT_GATT_GET_PRIMARY_SERVICES:
5191         case BT_GATT_GET_SERVICE_PROPERTIES:             /* GATT Client */
5192         case BT_GATT_GET_CHARACTERISTIC_PROPERTIES:      /* GATT Client */
5193         case BT_GATT_WATCH_SERVICE_CHANGED_INDICATION:   /* GATT Client */
5194         case BT_GATT_DISCOVER_CHARACTERISTICS:
5195         case BT_GATT_SET_PROPERTY_REQUEST:
5196         case BT_GATT_READ_CHARACTERISTIC:
5197         case BT_GATT_READ_DESCRIPTOR_VALUE:              /* GATT Client */
5198         case BT_GATT_WRITE_CHARACTERISTIC_VALUE_BY_TYPE: /* GATT Client */
5199         case BT_GATT_ACQUIRE_WRITE:
5200         case BT_GATT_WRITE_DESCRIPTOR_VALUE:             /* GATT Client */
5201         case BT_GATT_WATCH_CHARACTERISTIC:               /* GATT Client */
5202         case BT_GATT_CLIENT_REGISTER:                    /* GATT Client */
5203         case BT_GATT_CLIENT_UNREGISTER:                   /* GATT Client */
5204         case BT_GATT_DISCOVER_CHARACTERISTICS_DESCRIPTOR:
5205         case BT_GATT_REGISTER_APPLICATION:
5206         case BT_GATT_REGISTER_SERVICE:
5207         case BT_GATT_SEND_RESPONSE:
5208 #ifndef GATT_DIRECT
5209         case BT_GATT_SERVER_REGISTER:
5210         case BT_GATT_SERVER_ADD_SERVICE:
5211         case BT_GATT_SERVER_ADD_CHARACTERISTIC:
5212         case BT_GATT_SERVER_ADD_DESCRIPTOR:
5213         case BT_GATT_SERVER_START_SERVICE:
5214         case BT_GATT_SERVER_STOP_SERVICE:
5215         case BT_GATT_SERVER_DELETE_SERVICE:
5216         case BT_GATT_SERVER_SEND_RESPONSE:
5217         case BT_GATT_SERVER_ACQURE_WRITE_RESPONSE:
5218         case BT_GATT_SERVER_ACQUIRE_NOTIFY_RESPONSE:
5219         case BT_GATT_SERVER_SEND_INDICATION:
5220         case BT_GATT_SERVER_UPDATE_VALUE:
5221         case BT_GATT_SERVER_DEREGISTER:
5222 #endif
5223         case BT_REQ_ATT_MTU:
5224         case BT_PBAP_CONNECT:
5225         case BT_PBAP_DISCONNECT:
5226         case BT_PBAP_GET_PHONEBOOK_SIZE:
5227         case BT_PBAP_GET_PHONEBOOK:
5228         case BT_PBAP_GET_LIST:
5229         case BT_PBAP_PULL_VCARD:
5230         case BT_PBAP_PHONEBOOK_SEARCH:
5231
5232         case BT_RFCOMM_LISTEN_AND_ACCEPT:
5233
5234         ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
5235                                                 BT_PRIVILEGE_PUBLIC);
5236
5237         BT_INFO("Client Credentials [%s]", client_creds);
5238         if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
5239                 BT_ERR("Fail to access: %s", BT_PRIVILEGE_PUBLIC);
5240                 result = FALSE;
5241         }
5242
5243         /* Need to check mediastorage privilege */
5244         if (function_name == BT_PBAP_GET_PHONEBOOK ||
5245                 function_name == BT_PBAP_PULL_VCARD) {
5246                 ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
5247                                                         MEDIASTORAGE_PRIVILEGE);
5248
5249                 if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
5250                 BT_ERR("Fail to access: %s", MEDIASTORAGE_PRIVILEGE);
5251                 result = FALSE;
5252                 }
5253         }
5254         break;
5255
5256         case BT_ENABLE_ADAPTER:
5257         case BT_DISABLE_ADAPTER:
5258         case BT_RESET_ADAPTER:
5259         case BT_RECOVER_ADAPTER:
5260         case BT_BATTERY_READ_DATA:
5261         case BT_ENABLE_ADAPTER_LE:
5262         case BT_DISABLE_ADAPTER_LE:
5263         case BT_SET_CONNECTABLE:
5264         case BT_SET_DISCOVERABLE_MODE:
5265         case BT_ADD_WHITE_LIST:
5266         case BT_REMOVE_WHITE_LIST:
5267         case BT_CLEAR_WHITE_LIST:
5268         case BT_SET_MANUFACTURER_DATA:
5269
5270         case BT_CANCEL_SEARCH_SERVICE:
5271         case BT_ENABLE_RSSI:
5272         case BT_DISCONNECT_DEVICE:
5273
5274         case BT_RFCOMM_ACCEPT_CONNECTION:
5275         case BT_RFCOMM_REJECT_CONNECTION:
5276         case BT_RFCOMM_LISTEN:
5277
5278         case BT_HID_ENABLE_BARCODE_FEATURE:
5279
5280         case BT_AVRCP_TRANSPORT_SET_PROPERTY:
5281         case BT_AVRCP_HANDLE_CONTROL_TO_DEST:
5282
5283         case BT_SET_CONTENT_PROTECT:
5284         case BT_BOND_DEVICE_BY_TYPE:
5285         case BT_SET_LE_PRIVACY:
5286         case BT_SET_LE_STATIC_RANDOM_ADDRESS:
5287         case BT_LE_CONN_UPDATE:
5288         case BT_GET_DEVICE_IDA:
5289         case BT_LE_READ_MAXIMUM_DATA_LENGTH:
5290         case BT_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH:
5291         case BT_LE_READ_HOST_SUGGESTED_DATA_LENGTH:
5292         case BT_LE_SET_DATA_LENGTH:
5293         case BT_LE_OOB_READ_LOCAL_DATA:
5294         case BT_LE_OOB_ADD_REMOTE_DATA:
5295
5296         case BT_GET_GATT_DATA_BATCHING_AVAILABLE_PACKETS:
5297         case BT_ENABLE_GATT_DATA_BATCHING:
5298         case BT_DISABLE_GATT_DATA_BATCHING:
5299
5300         case BT_LE_IPSP_INIT:
5301         case BT_LE_IPSP_DEINIT:
5302         case BT_LE_IPSP_CONNECT:
5303         case BT_LE_IPSP_DISCONNECT:
5304         case BT_PXP_MONITOR_SET_PROPERTY:
5305         case BT_PXP_MONITOR_GET_PROPERTY:
5306         case BT_PXP_MONITOR_GET_SUPPORTED_SERIVCES:
5307         case BT_PXP_REPORTER_REGISTER:
5308         case BT_PXP_REPORTER_UNREGISTER:
5309         case BT_PXP_REPORTER_GET_PROPERTY:
5310
5311         /* TDS */
5312         case BT_TDS_PROVIDER_REGISTER:
5313         case BT_TDS_PROVIDER_UNREGISTER:
5314         case BT_TDS_PROVIDER_SET_MANUF_DATA:
5315         case BT_TDS_PROVIDER_CREATE:
5316         case BT_TDS_PROVIDER_DESTROY:
5317         case BT_TDS_PROVIDER_SET_TRANSPORT_DATA:
5318         case BT_TDS_SEND_ACTIVATION_RESPONSE:
5319         case BT_TDS_READ_TRANSPORT_DATA:
5320         case BT_TDS_ENABLE_CONTROL_POINT:
5321         case BT_TDS_ACTIVATE_CONTROL_POINT:
5322
5323         /* OTP Server */
5324         case BT_OTP_SERVER_INIT:
5325         case BT_OTP_SERVER_DEINIT:
5326         case BT_OTP_READ_VALUE:
5327         case BT_OTP_ENABLE_NOTIFICATION:
5328         case BT_OTP_WRITE_VALUE:
5329         case BT_LE_OTC_CONNECT:
5330         case BT_LE_OTC_DISCONNECT:
5331
5332         case BT_MAP_CREATE_SESSION:
5333         case BT_MAP_DESTROY_SESSION:
5334         case BT_MAP_SET_FOLDER:
5335         case BT_MAP_LIST_FOLDERS:
5336         case BT_MAP_LIST_FILTER_FIELDS:
5337         case BT_MAP_LIST_MESSAGES:
5338         case BT_MAP_UPDATE_INBOX:
5339         case BT_MAP_PUSH_MESSAGE:
5340         case BT_MAP_GET_MESSAGE:
5341
5342         case BT_MESH_INIT:
5343         case BT_MESH_DEINIT:
5344         case BT_MESH_NETWORK_CREATE:
5345         case BT_MESH_NETWORK_DESTROY:
5346         case BT_MESH_NETWORK_LOAD:
5347         case BT_MESH_NETWORK_UNLOAD:
5348         case BT_MESH_NETWORK_JOIN:
5349         case BT_MESH_CANCEL_JOIN:
5350         case BT_MESH_NETWORK_SCAN:
5351         case BT_MESH_NETWORK_CANCEL_SCAN:
5352         case BT_MESH_NETWORK_SET_CAPABILITIES:
5353         case BT_MESH_NETWORK_PROVISION_DEVICE:
5354         case BT_MESH_AUTHENTICATION_REPLY:
5355         case BT_MESH_NETWORK_SET_NAME:
5356         case BT_MESH_NETWORK_ADD_NETKEY:
5357         case BT_MESH_NETWORK_DELETE_NETKEY:
5358         case BT_MESH_NETWORK_UPDATE_NETKEY:
5359         case BT_MESH_NETWORK_ADD_APPKEY:
5360         case BT_MESH_NETWORK_DELETE_APPKEY:
5361         case BT_MESH_NETWORK_UPDATE_APPKEY:
5362         case BT_MESH_NETWORK_GET_NETKEYS:
5363         case BT_MESH_NETWORK_GET_APPKEYS:
5364         case BT_MESH_NETWORK_GET_NODES:
5365         case BT_MESH_ELEMENT_GET_MODELS:
5366         case BT_MESH_NODE_BROWSE:
5367         case BT_MESH_NODE_GET_VENDOR_FEATURES:
5368         case BT_MESH_NODE_CONFIGURE_KEY:
5369         case BT_MESH_NODE_TTL_EXECUTE:
5370         case BT_MESH_NODE_GET_NETKEYS:
5371         case BT_MESH_NODE_GET_APPKEYS:
5372         case BT_MESH_NODE_RESET:
5373         case BT_MESH_MODEL_CONFIGURE_APPKEY:
5374         case BT_MESH_MODEL_GET_APPKEY_LIST:
5375         case BT_MESH_MODEL_EXECUTE_MSG:
5376         case BT_MESH_NETWORK_CREATE_GROUP:
5377         case BT_MESH_NETWORK_REMOVE_GROUP:
5378         case BT_MESH_MODEL_CONFIG_GROUP_SUB:
5379         case BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB:
5380         case BT_MESH_MODEL_GET_SUBSCRIPTION_LIST:
5381         case BT_MESH_MODEL_SET_PUBLICATION:
5382         case BT_MESH_MODEL_GET_PUBLICATION:
5383         case BT_MESH_NETWORK_GET_GROUPS:
5384
5385         ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
5386                                 BT_PRIVILEGE_PLATFORM);
5387
5388         if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
5389                 BT_ERR("Fail to access: %s", BT_PRIVILEGE_PLATFORM);
5390                 result = FALSE;
5391         }
5392         break;
5393
5394         case BT_CHECK_ADAPTER:
5395         case BT_GET_RSSI:
5396
5397         case BT_GET_LOCAL_NAME:
5398         case BT_GET_LOCAL_ADDRESS:
5399         case BT_GET_LOCAL_VERSION:
5400         case BT_IS_SERVICE_USED:
5401         case BT_GET_DISCOVERABLE_MODE:
5402         case BT_GET_DISCOVERABLE_TIME:
5403         case BT_IS_DISCOVERYING:
5404         case BT_IS_LE_DISCOVERYING:
5405         case BT_IS_CONNECTABLE:
5406         case BT_GET_CONNECTABLE:
5407         case BT_GET_BONDED_DEVICES:
5408         case BT_GET_PROFILE_CONNECTED_DEVICES:
5409         case BT_GET_BONDED_DEVICE:
5410         case BT_PASSKEY_REPLY:
5411         case BT_PASSKEY_CONFIRMATION_REPLY:
5412         case BT_GET_IS_ALIAS_SET:
5413         case BT_IS_DEVICE_CONNECTED:
5414         case BT_GET_CONNECTED_LINK_TYPE:
5415         case BT_SET_PROFILE_TRUSTED:
5416         case BT_GET_PROFILE_TRUSTED:
5417         case BT_GET_SPEAKER_GAIN:
5418         case BT_SET_SPEAKER_GAIN:
5419         case BT_RFCOMM_CLIENT_IS_CONNECTED:
5420         case BT_RFCOMM_IS_UUID_AVAILABLE:
5421         case BT_GET_ADVERTISING_DATA:
5422         case BT_GET_SCAN_RESPONSE_DATA:
5423         case BT_IS_ADVERTISING:
5424         case BT_IS_LE_2M_PHY_SUPPORTED:
5425         case BT_IS_LE_CODED_PHY_SUPPORTED:
5426         case BT_REGISTER_SCAN_FILTER:
5427         case BT_IS_SCAN_FILTER_SUPPORTED:
5428         case BT_GET_ATT_MTU:
5429
5430         case BT_OBEX_SERVER_ALLOCATE:
5431         case BT_OBEX_SERVER_DEALLOCATE:
5432         case BT_OBEX_SERVER_IS_ACTIVATED:
5433         case BT_OPP_GET_TRANSFER_PROGRESS:
5434         case BT_AVRCP_CONTROL_GET_PROPERTY:
5435         case BT_AVRCP_GET_TRACK_INFO:
5436                 /* Non-privilege control */
5437                 break;
5438         default:
5439                 BT_ERR("Unknown function!");
5440                 result = FALSE;
5441                 break;
5442         }
5443
5444         if (function_name >= BT_FUNC_MESH_BASE) {
5445                 BT_INFO("MESH Function called");
5446                 char app_id[256] = { 0, };
5447
5448                 if (BLUETOOTH_ERROR_NONE == __bt_service_get_requester_app_id(unique_name,
5449                                         app_id, sizeof(app_id))) {
5450                         requester_unique_creds = g_strdup(app_id);
5451                 } else {
5452                         BT_DBG("Requester app_id not found, use client creds");
5453                         requester_unique_creds = g_strdup(client_creds);
5454                 }
5455                 BT_DBG("Requester unique_creds: %s", requester_unique_creds);
5456         } else {
5457                 BT_INFO("Non MESH Function called client creds [%s]", client_creds);
5458         }
5459
5460         if (client_creds)
5461                 free(client_creds);
5462
5463         if (user_creds)
5464                 free(user_creds);
5465
5466         return result;
5467 }
5468
5469 GDBusNodeInfo *__bt_service_create_method_node_info
5470                                         (const gchar *introspection_data)
5471 {
5472         GError *err = NULL;
5473         GDBusNodeInfo *node_info = NULL;
5474
5475         if (introspection_data == NULL) {
5476                 BT_ERR("Introspection XML not present");
5477                 return NULL;
5478         }
5479
5480         node_info = g_dbus_node_info_new_for_xml(introspection_data, &err);
5481
5482         if (err) {
5483                 BT_ERR("Unable to create node: %s", err->message);
5484                 g_clear_error(&err);
5485         }
5486         return node_info;
5487 }
5488
5489 int __bt_service_register_object(GDBusConnection *conn,
5490                 GDBusNodeInfo *node_info, gboolean reg)
5491 {
5492         static guint service_id = 0;
5493         GError *error = NULL;
5494
5495         if (reg) {
5496                 if (node_info == NULL)
5497                         return -1;
5498
5499                 service_id = g_dbus_connection_register_object(conn,
5500                                 BT_SERVICE_PATH,
5501                                 node_info->interfaces[0],
5502                                 &method_table,
5503                                 NULL, NULL, &error);
5504                 if (service_id == 0)
5505                         return -1;
5506         } else {
5507                 if (service_id > 0) {
5508                         g_dbus_connection_unregister_object(conn,
5509                                         service_id);
5510                         service_id = 0;
5511                 }
5512         }
5513
5514         return 0;
5515 }
5516
5517 static void __name_owner_changed(GDBusConnection *connection,
5518                 const gchar *sender_name,
5519                 const gchar *object_path,
5520                 const gchar *interface_name,
5521                 const gchar *signal_name,
5522                 GVariant *parameters,
5523                 gpointer user_data)
5524 {
5525         const char *name = NULL;
5526         const char *old_owner = NULL;
5527         const char *new_owner = NULL;
5528
5529         g_variant_get(parameters, "(&s&s&s)", &name, &old_owner, &new_owner);
5530         if (*new_owner != '\0')
5531                 return;
5532
5533         _bt_check_hdp_app_termination(name);
5534
5535         /* Advertising App Termination */
5536         _bt_check_adv_app_termination(name);
5537
5538         /* Check if le_scanning app is terminated */
5539         _bt_check_le_scanner_app_termination(name);
5540
5541         /* Check if RFCOMM app is terminated */
5542         _bt_rfcomm_check_termination(name);
5543
5544         /* Mesh App Termination */
5545         _bt_check_mesh_app_termination(name);
5546
5547         /* Stop the Transport Discovery service */
5548         _bt_tds_stop_by_terminated_process(name);
5549 }
5550
5551 static void __bt_service_bus_acquired_handler(GDBusConnection *connection,
5552                 const gchar *name, gpointer user_data)
5553 {
5554         GDBusNodeInfo *node_info = NULL;
5555
5556         BT_INFO("bus acquired");
5557
5558         ret_if(connection == NULL);
5559
5560         node_info = __bt_service_create_method_node_info(
5561                         bt_service_introspection_xml);
5562         ret_if(node_info == NULL);
5563
5564         __bt_service_register_object(connection, node_info, TRUE);
5565         g_dbus_node_info_unref(node_info);
5566
5567         bt_service_conn = connection;
5568 }
5569
5570 static void __bt_service_name_acquired_handler(GDBusConnection *connection,
5571                 const gchar *name, gpointer user_data)
5572 {
5573         BT_INFO("name acquired");
5574         name_acquired = TRUE;
5575 }
5576
5577 static void __bt_service_name_lost_handler(GDBusConnection *connection,
5578                 const gchar *name, gpointer user_data)
5579 {
5580         BT_INFO("name lost");
5581         name_acquired = FALSE;
5582 }
5583
5584 gboolean _is_name_acquired(void)
5585 {
5586         return name_acquired;
5587 }
5588
5589 void _bt_service_unref_connection(void)
5590 {
5591         BT_INFO("+");
5592
5593         if (bt_service_conn) {
5594                 g_dbus_connection_flush_sync(bt_service_conn, NULL, NULL);
5595                 g_object_unref(bt_service_conn);
5596                 bt_service_conn = NULL;
5597         }
5598
5599         BT_INFO("-");
5600 }
5601
5602 int _bt_service_register(void)
5603 {
5604         GDBusConnection *conn;
5605         GError *err = NULL;
5606
5607         conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
5608         retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
5609         bt_service_conn = conn;
5610
5611         owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
5612                                 BT_SERVICE_NAME,
5613                                 G_BUS_NAME_OWNER_FLAGS_NONE,
5614                                 __bt_service_bus_acquired_handler,
5615                                 __bt_service_name_acquired_handler,
5616                                 __bt_service_name_lost_handler,
5617                                 NULL, NULL);
5618         BT_DBG("owner_id is [%d]", owner_id);
5619         if (owner_id == 0)
5620                 goto fail;
5621
5622         /* Subscribe for name owner changed signal */
5623         owner_sig_id = g_dbus_connection_signal_subscribe(conn,
5624                         BT_FREEDESKTOP_SERVICE, BT_FREEDESKTOP_INTERFACE,
5625                         BT_NAME_OWNER_CHANGED, NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
5626                         __name_owner_changed, NULL, NULL);
5627         BT_INFO("owner_sig_id: %d", owner_sig_id);
5628
5629         return BLUETOOTH_ERROR_NONE;
5630
5631 fail:
5632         if (bt_service_conn) {
5633                 g_object_unref(bt_service_conn);
5634                 bt_service_conn = NULL;
5635         }
5636
5637         return BLUETOOTH_ERROR_INTERNAL;
5638 }
5639
5640 void _bt_service_unregister(void)
5641 {
5642         if (bt_service_conn) {
5643                 sd_notify(0, "STOPPING=1");
5644
5645                 if (owner_sig_id > 0) {
5646                         g_dbus_connection_signal_unsubscribe(
5647                                         bt_service_conn, owner_sig_id);
5648                         owner_sig_id = 0;
5649                 }
5650
5651                 if (owner_id > 0) {
5652                         g_bus_unown_name(owner_id);
5653                         owner_id = 0;
5654                 }
5655
5656                 __bt_service_register_object(bt_service_conn, NULL, FALSE);
5657         }
5658 }
5659
5660 int _bt_service_cynara_init(void)
5661 {
5662         int result;
5663         char err_msg[256] = {0, };
5664
5665         retv_if(p_cynara != NULL, BLUETOOTH_ERROR_ALREADY_INITIALIZED);
5666
5667         result = cynara_initialize(&p_cynara, conf);
5668
5669         if (result != CYNARA_API_SUCCESS) {
5670                 cynara_strerror(result, err_msg, sizeof(err_msg));
5671                 BT_ERR("Fail to initialize cynara: [%s]", err_msg);
5672                 return BLUETOOTH_ERROR_INTERNAL;
5673         }
5674
5675         return BLUETOOTH_ERROR_NONE;
5676 }
5677
5678 void _bt_service_cynara_deinit(void)
5679 {
5680         int result;
5681         char err_msg[256] = {0, };
5682
5683         ret_if(p_cynara == NULL);
5684
5685         result = cynara_finish(p_cynara);
5686
5687         if (result != CYNARA_API_SUCCESS) {
5688                 cynara_strerror(result, err_msg, sizeof(err_msg));
5689                 BT_ERR("Fail to finish cynara: [%s]", err_msg);
5690                 return;
5691         }
5692
5693         p_cynara = NULL;
5694         conf = NULL;
5695 }
5696
5697 void _bt_service_method_return(GDBusMethodInvocation *invocation,
5698                 GArray *out_param, int result)
5699 {
5700         GVariant *out_var;
5701         BT_DBG("");
5702         out_var = g_variant_new_from_data((const GVariantType *)"ay",
5703                         out_param->data, out_param->len, TRUE, NULL, NULL);
5704
5705         g_dbus_method_invocation_return_value(invocation,
5706                         g_variant_new("(iv)", result, out_var));
5707 }
5708
5709 void _bt_service_method_return_with_unix_fd_list(GDBusMethodInvocation *invocation,
5710                 GArray *out_param, int result, GUnixFDList *fd_list)
5711 {
5712         GVariant *out_var;
5713         BT_DBG("");
5714         out_var = g_variant_new_from_data((const GVariantType *)"ay",
5715                         out_param->data, out_param->len, TRUE, NULL, NULL);
5716
5717         g_dbus_method_invocation_return_value_with_unix_fd_list(invocation,
5718                         g_variant_new("(iv)", result, out_var), fd_list);
5719 }