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