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