Fix osp_server unregister issue
[platform/core/connectivity/bluetooth-frwk.git] / bt-service-adaptation / services / bt-request-handler.c
index 47175a5..4e230df 100644 (file)
@@ -23,6 +23,7 @@
 #include <gio/gunixfdlist.h>
 #include <cynara-client.h>
 #include <cynara-creds-gdbus.h>
+#include <systemd/sd-daemon.h>
 
 #include "bluetooth-api.h"
 #include "bluetooth-audio-api.h"
@@ -91,6 +92,12 @@ static const gchar bt_service_introspection_xml[] =
 "                      <arg type='i' name='output_param1' direction='out' />"
 "                      <arg type='v' name='output_param2' direction='out' />"
 "              </method>"
+#ifdef TIZEN_FEATURE_BT_AVC_TARGET
+"              <method name='get_avc_mode'>"
+                       /* Out Parameters */
+"                      <arg type='u' name='avc_mode' direction='out' />"
+"              </method>"
+#endif
 "      </interface>"
 "</node>";
 
@@ -193,9 +200,7 @@ static void __bt_service_get_parameters(GVariant *in_param,
 static gboolean __bt_is_sync_function(int service_function)
 {
        /*TODO: Keep adding sync methods with expect replies from bluetooth service */
-       if (service_function == BT_ENABLE_ADAPTER
-                       || service_function == BT_DISABLE_ADAPTER
-                       || service_function == BT_GET_LOCAL_ADDRESS
+       if (service_function == BT_GET_LOCAL_ADDRESS
                        || service_function == BT_GET_LOCAL_NAME
                        || service_function == BT_GET_LOCAL_VERSION
                        || service_function == BT_GET_BONDED_DEVICES
@@ -223,6 +228,7 @@ static gboolean __bt_is_sync_function(int service_function)
                        || service_function == BT_GATT_SERVER_DELETE_SERVICE
                        || service_function == BT_START_LE_DISCOVERY
                        || service_function == BT_STOP_LE_DISCOVERY
+                       || service_function == BT_GET_CONNECTABLE
 #ifdef TIZEN_GATT_CLIENT
                        || service_function == BT_GATT_CLIENT_REGISTER
                        || service_function == BT_GATT_GET_PRIMARY_SERVICES
@@ -242,7 +248,6 @@ void _bt_save_invocation_context(GDBusMethodInvocation *invocation, int result,
                char *sender, int service_function,
                gpointer invocation_data)
 {
-       BT_DBG("Saving the invocation context: service_function [%d]", service_function);
        invocation_info_t *info;
        info = g_malloc0(sizeof(invocation_info_t));
        info->context = invocation;
@@ -254,6 +259,24 @@ void _bt_save_invocation_context(GDBusMethodInvocation *invocation, int result,
 
 }
 
+static int __bt_service_get_sender_pid(const char *unique_name, pid_t *pid)
+{
+       int ret;
+       char err_msg[256] = {0, };
+
+       retv_if(bt_service_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       ret = cynara_creds_gdbus_get_pid(bt_service_conn, unique_name, pid);
+       if (ret != CYNARA_API_SUCCESS) {
+               cynara_strerror(ret, err_msg, sizeof(err_msg));
+               BT_ERR("Fail to get user credential: %s", err_msg);
+
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
 static int __bt_bm_request_data(_bt_battery_data_t *latest)
 {
        int ret = _bt_bm_read_data(latest);
@@ -369,8 +392,8 @@ static void __bt_service_method(GDBusConnection *connection,
 
                if (request_type == BT_ASYNC_REQ ||
                                __bt_is_sync_function(service_function)) {
-                       BT_INFO("Do not send reply to bt-api over dbus,"
-                               " Invocation context is already saved in service_function");
+                       /* Do not send reply to bt-api over dbus,
+                               Invocation context is already saved in service_function */
                        goto done;
                }
 
@@ -412,6 +435,19 @@ fail:
                g_variant_unref(param4);
                g_variant_unref(param5);
        }
+#ifdef TIZEN_FEATURE_BT_AVC_TARGET
+       else if (g_strcmp0(method_name, "get_avc_mode") == 0) {
+               unsigned int mode = 0;
+
+               if (_bt_audio_get_avc_mode(&mode) != BLUETOOTH_ERROR_NONE)
+                       BT_ERR("Fail to get the avc mode");
+
+               BT_DBG("Absolute Volume Control mode: %d", mode);
+
+               g_dbus_method_invocation_return_value(invocation,
+                       g_variant_new("(u)", mode));
+       }
+#endif
 
        FN_END;
        return;
@@ -441,24 +477,10 @@ int __bt_bluez_request(int function_name,
        switch (function_name) {
        case BT_ENABLE_ADAPTER: {
                result = _bt_enable_adapter();
-               /* Save invocation */
-               if (result == BLUETOOTH_ERROR_NONE) {
-                       BT_DBG("_bt_enable_adapter scheduled successfully! save invocation context");
-                       sender = (char*)g_dbus_method_invocation_get_sender(context);
-                       _bt_save_invocation_context(context, result, sender,
-                                       function_name, NULL);
-               }
                break;
        }
        case BT_DISABLE_ADAPTER: {
                result = _bt_disable_adapter();
-               /* Save invocation */
-               if (result == BLUETOOTH_ERROR_NONE) {
-                       BT_DBG("_bt_disable_adapter scheduled successfully! save invocation context");
-                       sender = (char*)g_dbus_method_invocation_get_sender(context);
-                       _bt_save_invocation_context(context, result, sender,
-                                       function_name, NULL);
-               }
                break;
        }
        case BT_RECOVER_ADAPTER:
@@ -478,6 +500,9 @@ int __bt_bluez_request(int function_name,
                dbus_data.session_end_time = data->session_end_time;
                dbus_data.session_scan_time = data->session_scan_time;
                dbus_data.session_connected_time = data->session_connected_time;
+               dbus_data.tx_time = data->tx_time;
+               dbus_data.rx_time = data->rx_time;
+               dbus_data.idle_time = data->idle_time;
 
                /*Populating app data*/
                int n = 0;
@@ -488,7 +513,7 @@ int __bt_bluez_request(int function_name,
                }
                dbus_data.num_app = n;
                g_array_append_vals(*out_param1, &dbus_data, sizeof(bt_battery_dbus_data_t));
-               g_slist_free(data->atm_list);
+               g_slist_free_full(data->atm_list, g_free);
                g_free(data);
                data = NULL;
                break;
@@ -513,6 +538,7 @@ int __bt_bluez_request(int function_name,
                unsigned short max_response;
                unsigned short discovery_duration;
                unsigned int classOfDeviceMask;
+               uid_t uid;
 
                __bt_service_get_parameters(in_param1,
                                &max_response, sizeof(unsigned short));
@@ -520,8 +546,22 @@ int __bt_bluez_request(int function_name,
                                &discovery_duration, sizeof(unsigned short));
                __bt_service_get_parameters(in_param3,
                                &classOfDeviceMask, sizeof(unsigned int));
+               __bt_service_get_parameters(in_param4, &uid, sizeof(uid_t));
 
                result = _bt_start_discovery(max_response, discovery_duration, classOfDeviceMask);
+
+               if (result == BLUETOOTH_ERROR_NONE) {
+                       pid_t pid;
+
+                       sender = (char*)g_dbus_method_invocation_get_sender(context);
+
+                       if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
+                               BT_ERR("Fail to get the sender pid");
+
+                       BT_DBG("Remeber pid / uid for the scan operation");
+                       _bt_bm_add_scan_app(SCAN_REGACY, uid, pid);
+               }
+
                break;
        }
        case BT_START_CUSTOM_DISCOVERY: {
@@ -613,6 +653,17 @@ int __bt_bluez_request(int function_name,
                g_array_append_vals(*out_param1, &is_connectable, sizeof(gboolean));
                break;
        }
+       case BT_GET_CONNECTABLE: {
+               result  = _bt_get_connectable();
+
+               /* Save invocation */
+               if (result == BLUETOOTH_ERROR_NONE) {
+                        sender = (char*)g_dbus_method_invocation_get_sender(context);
+                        _bt_save_invocation_context(context, result, sender,
+                                        function_name, NULL);
+               }
+               break;
+       }
        case BT_SET_CONNECTABLE: {
                gboolean is_connectable;
 
@@ -696,7 +747,6 @@ int __bt_bluez_request(int function_name,
                if (result == BLUETOOTH_ERROR_NONE) {
                        char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
                        _bt_convert_addr_type_to_string(addr, address.addr);
-                       BT_DBG("_bt_bond_device scheduled successfully! save invocation context");
                        sender = (char*)g_dbus_method_invocation_get_sender(context);
                        _bt_save_invocation_context(context, result, sender,
                                        function_name, (gpointer)addr);
@@ -725,7 +775,6 @@ int __bt_bluez_request(int function_name,
                if (result == BLUETOOTH_ERROR_NONE) {
                        char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
                        _bt_convert_addr_type_to_string(addr, address.addr);
-                       BT_DBG("_bt_bond_device_by_type invoked successfully! save invocation context");
                        sender = (char*)g_dbus_method_invocation_get_sender(context);
                        _bt_save_invocation_context(context, result, sender,
                                        function_name, (gpointer)addr);
@@ -751,7 +800,6 @@ int __bt_bluez_request(int function_name,
                if (result == BLUETOOTH_ERROR_NONE) {
                        char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
                        _bt_convert_addr_type_to_string(addr, address.addr);
-                       BT_DBG("_bt_unbond_device scheduled successfully! save invocation context");
                        sender = (char*)g_dbus_method_invocation_get_sender(context);
                        _bt_save_invocation_context(context, result, sender,
                                        function_name, (gpointer)addr);
@@ -774,7 +822,6 @@ int __bt_bluez_request(int function_name,
                if (result == BLUETOOTH_ERROR_NONE) {
                        char * addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
                        _bt_convert_addr_type_to_string(addr, address.addr);
-                       BT_DBG("BT Device Service Search Request scheduled successfully! save invocation context");
                        sender = (char*)g_dbus_method_invocation_get_sender(context);
                        _bt_save_invocation_context(context, result, sender,
                                        function_name, (gpointer)addr);
@@ -900,6 +947,31 @@ int __bt_bluez_request(int function_name,
                result = _bt_set_white_list(&address, address_type, is_add);
                break;
         }
+       case BT_UPDATE_LE_CONNECTION_MODE: {
+               char *sender = NULL;
+               bluetooth_device_address_t remote_address = { { 0 } };
+               bluetooth_le_connection_param_t parameters = { 0 };
+               bluetooth_le_connection_mode_t mode = BLUETOOTH_LE_CONNECTION_MODE_BALANCED;
+
+               __bt_service_get_parameters(in_param1, &remote_address,
+                               sizeof(bluetooth_device_address_t));
+               __bt_service_get_parameters(in_param2, &mode,
+                               sizeof(bluetooth_le_connection_mode_t));
+
+               result = _bt_get_le_connection_parameter(mode, &parameters);
+               if (result != BLUETOOTH_ERROR_NONE)
+                       break;
+
+               sender = (char *)g_dbus_method_invocation_get_sender(context);
+
+               result = _bt_le_connection_update(sender,
+                               remote_address.addr,
+                               parameters.interval_min,
+                               parameters.interval_max,
+                               parameters.latency,
+                               parameters.timeout);
+               break;
+       }
        case BT_SET_MANUFACTURER_DATA: {
                bluetooth_manufacturer_data_t m_data = { 0 };
                __bt_service_get_parameters(in_param1,
@@ -1378,7 +1450,6 @@ int __bt_bluez_request(int function_name,
                                        sizeof(bluetooth_rfcomm_connection_t));
                } else {
                        char *addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
-                       BT_ERR("BT_RFCOMM_CLIENT_CONNECT success, save context");
                        _bt_convert_addr_type_to_string(addr, address.addr);
                        sender = (char*)g_dbus_method_invocation_get_sender(context);
                        _bt_save_invocation_context(context, result, sender, function_name, addr);
@@ -1418,8 +1489,6 @@ int __bt_bluez_request(int function_name,
 
                result = _bt_rfcomm_socket_listen(sender, uuid, true);
                if (result > 0) {
-                       BT_ERR("BT_RFCOMM_LISTEN_AND_ACCEPT success, save context");
-
                        result = BLUETOOTH_ERROR_NONE;
                        _bt_save_invocation_context(context,
                                        result, sender, function_name, NULL);
@@ -1437,8 +1506,6 @@ int __bt_bluez_request(int function_name,
 
                result = _bt_rfcomm_socket_listen(sender, uuid, false);
                if (result > 0) {
-                       BT_ERR("BT_RFCOMM_LISTEN success, save context");
-
                        result = BLUETOOTH_ERROR_NONE;
                        _bt_save_invocation_context(context,
                                        result, sender, function_name, NULL);
@@ -1490,7 +1557,23 @@ int __bt_bluez_request(int function_name,
                BT_DBG("Sending details to bluetooth battery monitor: %ld, %ld, %d", (long int)uid, (long int)pid, size);
                _bt_bm_add_transaction_details(uid, pid, size, TX_DATA);
                break;
-        }
+       }
+       case BT_RFCOMM_SERVER_UPDATE_CONNECTION_INFO: {
+               gboolean connected = FALSE;
+               int client_fd = -1;
+
+               sender = (char *)g_dbus_method_invocation_get_sender(context);
+
+               __bt_service_get_parameters(in_param1, &connected, sizeof(gboolean));
+               __bt_service_get_parameters(in_param2, &client_fd, sizeof(int));
+
+               if (connected == TRUE)
+                       result = _bt_rfcomm_server_conn_added(sender, client_fd);
+               else
+                       result = _bt_rfcomm_server_conn_removed(sender, client_fd);
+
+               break;
+       }
        case BT_AUDIO_SELECT_ROLE: {
                bluetooth_audio_role_t role;
 
@@ -1505,6 +1588,31 @@ int __bt_bluez_request(int function_name,
                }
                break;
        }
+#ifdef TIZEN_FEATURE_BT_AVC_TARGET
+       case BT_AUDIO_SET_ABSOLUTE_VOLUME: {
+               unsigned int volume = 0;
+
+               __bt_service_get_parameters(in_param1,
+                               &volume, sizeof(unsigned int));
+
+               result = _bt_audio_set_absolute_volume(volume);
+               break;
+       }
+       case BT_AUDIO_GET_ABSOLUTE_VOLUME: {
+               unsigned int volume = 0;
+
+               result = _bt_audio_get_absolute_volume(&volume);
+               g_array_append_vals(*out_param1, &volume, sizeof(unsigned int));
+               break;
+       }
+       case BT_AUDIO_IS_AVC_ACTIVATED: {
+               bool activated = 0;
+
+               result = _bt_audio_is_avc_activated(&activated);
+               g_array_append_vals(*out_param1, &activated, sizeof(bool));
+               break;
+       }
+#endif
        case BT_AV_CONNECT: {
                bluetooth_device_address_t address = { {0} };
                __bt_service_get_parameters(in_param1,
@@ -2263,14 +2371,13 @@ int __bt_bluez_request(int function_name,
                char *app;
 
                app = (char *)g_dbus_method_invocation_get_sender(context);
-               BT_INFO("GATT Server Unique Name [%s]", app);
+               BT_DBG("GATT Server Unique Name [%s]", app);
 
                /* No ADV handle: Set 0 */
                result = _bt_register_server_instance(app, 0);
-               BT_INFO("GATT Server: Register Server result [%d]", result);
 
                if (result != BLUETOOTH_ERROR_NONE) {
-                       BT_ERR("GATT Server registration failed!!");
+                       BT_ERR("GATT Server registration failed. result %d", result);
                } else {
                        _bt_save_invocation_context(context, result, app,
                                        function_name, NULL);
@@ -2303,15 +2410,12 @@ int __bt_bluez_request(int function_name,
                __bt_service_get_parameters(in_param4, &instance_id,
                                sizeof(int));
 
-               BT_INFO("GATT Server Service UUID [%s]", svc_uuid);
                result = _bt_gatt_server_add_service(app, service_type, num_handles, svc_uuid, instance_id);
                if (result != BLUETOOTH_ERROR_NONE) {
                        BT_ERR("GATT Server Add Service failed!!");
                } else {
                        tmp_inst_id = g_malloc0(sizeof(int));
                        *tmp_inst_id = instance_id;
-                       BT_INFO("GATT Server: Save Instance ID in request Inst id [%d] request_id [%d]",
-                                       *tmp_inst_id, instance_id);
                        _bt_save_invocation_context(context, result, app,
                                        function_name, (gpointer)tmp_inst_id);
                }
@@ -2331,16 +2435,13 @@ int __bt_bluez_request(int function_name,
                                sizeof(bluetooth_gatt_server_attribute_params_t));
                char_uuid = (char *)g_variant_get_data(in_param2);
 
-               BT_INFO("GATT Server Characteristic UUID [%s]", char_uuid);
-
                result = _bt_gatt_server_add_characteristic(app, char_uuid, &param);
                if (result != BLUETOOTH_ERROR_NONE) {
                        BT_ERR("GATT Server Add Service failed!!");
                } else {
                        tmp_inst_id = g_malloc0(sizeof(int));
                        *tmp_inst_id = param.instance_id;
-                       BT_INFO("GATT Server: Save Instance ID in request Inst id [%d] request_id [%d]",
-                                       *tmp_inst_id, param.instance_id);
+
                        _bt_save_invocation_context(context, result, app,
                                        function_name, (gpointer)tmp_inst_id);
                }
@@ -2366,16 +2467,12 @@ int __bt_bluez_request(int function_name,
                __bt_service_get_parameters(in_param3, &perm,
                                sizeof(bt_gatt_permission_t));
 
-               BT_INFO("GATT Server Descriptor UUID [%s]", desc_uuid);
-
                result = _bt_gatt_server_add_descriptor(app, desc_uuid, &perm, service_handle, instance_id);
                if (result != BLUETOOTH_ERROR_NONE) {
                        BT_ERR("GATT Server Add Service failed!!");
                } else {
                        tmp_inst_id = g_malloc0(sizeof(int));
                        *tmp_inst_id = instance_id;
-                       BT_INFO("GATT Server: Save Instance ID in request Inst id [%d] request_id [%d]",
-                                       *tmp_inst_id, instance_id);
                        _bt_save_invocation_context(context, result, app,
                                        function_name, (gpointer)tmp_inst_id);
                }
@@ -2399,8 +2496,6 @@ int __bt_bluez_request(int function_name,
                if (BLUETOOTH_ERROR_NONE == result) {
                        tmp_inst_id = g_malloc0(sizeof(int));
                        *tmp_inst_id = instance_id;
-                       BT_INFO("GATT Server: Save Instance ID in request Inst id [%d] request_id [%d]",
-                                       *tmp_inst_id, instance_id);
                        _bt_save_invocation_context(context, result, app,
                                        function_name, (gpointer)tmp_inst_id);
                }
@@ -2423,8 +2518,6 @@ int __bt_bluez_request(int function_name,
                if (BLUETOOTH_ERROR_NONE == result) {
                        tmp_inst_id = g_malloc0(sizeof(int));
                        *tmp_inst_id = instance_id;
-                       BT_INFO("GATT Server: Save Instance ID in request Inst id [%d] request_id [%d]",
-                                       *tmp_inst_id, instance_id);
                        _bt_save_invocation_context(context, result, app,
                                        function_name, (gpointer)tmp_inst_id);
                }
@@ -2447,8 +2540,6 @@ int __bt_bluez_request(int function_name,
                if (BLUETOOTH_ERROR_NONE == result) {
                        tmp_inst_id = g_malloc0(sizeof(int));
                        *tmp_inst_id = instance_id;
-                       BT_INFO("GATT Server: Save Instance ID in request Inst id [%d] request_id [%d]",
-                                       *tmp_inst_id, instance_id);
                        _bt_save_invocation_context(context, result, app,
                                        function_name, (gpointer)tmp_inst_id);
                }
@@ -2594,6 +2685,48 @@ int __bt_bluez_request(int function_name,
                }
                break;
        }
+       case BT_REQ_ATT_MTU: {
+               bluetooth_device_address_t address = { {0} };
+               unsigned int mtu;
+               char *addr;
+
+               sender = (char*)g_dbus_method_invocation_get_sender(context);
+
+               __bt_service_get_parameters(in_param1,
+                               &address, sizeof(bluetooth_device_address_t));
+               __bt_service_get_parameters(in_param2,
+                               &mtu, sizeof(unsigned int));
+               BT_DBG("BT_REQ_ATT_MTU: %d", mtu);
+               result = _bt_request_att_mtu(&address, mtu);
+               if (BLUETOOTH_ERROR_NONE == result) {
+                       addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
+
+                       _bt_convert_addr_type_to_string(addr, address.addr);
+
+                       /* Save the informations to invocation */
+                       _bt_save_invocation_context(context, result, sender,
+                                       function_name, (gpointer)addr);
+               } else {
+                       g_array_append_vals(*out_param1, &address,
+                                       sizeof(bluetooth_device_address_t));
+               }
+               break;
+       }
+       case BT_GET_DEVICE_IDA: {
+               bluetooth_device_address_t address = { {0} };
+               bluetooth_device_address_t id_addr = { {0} };
+
+               __bt_service_get_parameters(in_param1,
+                               &address, sizeof(bluetooth_device_address_t));
+
+               result = _bt_device_get_ida(&address, &id_addr);
+
+               if (result == BLUETOOTH_ERROR_NONE) {
+                       g_array_append_vals(*out_param1, &id_addr,
+                                       sizeof(bluetooth_device_address_t));
+               }
+               break;
+       }
        case BT_SET_LE_STATIC_RANDOM_ADDRESS: {
                gboolean is_enable;
 
@@ -2620,7 +2753,6 @@ int __bt_bluez_request(int function_name,
                        addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
 
                        _bt_convert_addr_type_to_string(addr, address.addr);
-                       BT_INFO("GATT Client: Save Invocation data GATT CLient Register app[%s] address [%s]", sender, addr);
 
                        /* Save the informations to invocation */
                        _bt_save_invocation_context(context, result, sender,
@@ -2647,8 +2779,6 @@ int __bt_bluez_request(int function_name,
                int mtu = -1;
                bluetooth_gatt_client_char_prop_info_t param;
 
-               BT_INFO("GATT Client ACQUIRE WRITE recived");
-
                sender = (char*)g_dbus_method_invocation_get_sender(context);
 
                __bt_service_get_parameters(in_param1, &param,
@@ -2660,9 +2790,9 @@ int __bt_bluez_request(int function_name,
                g_array_append_vals(*out_param1, &mtu, sizeof(int));
 
                if (BLUETOOTH_ERROR_NONE == result)
-                       BT_INFO("GATT Client: Save Invocation data for characteristic props app[%s] fd[ %d]", sender, fd);
+                       BT_DBG("GATT Client: Save Invocation data for characteristic props app[%s] fd[ %d]", sender, fd);
                else {
-                       BT_ERR("Gatt Client Acqure Write");
+                       BT_ERR("GATT Client: gatt acquire write failed");
                        break;
                }
 
@@ -2698,20 +2828,20 @@ int __bt_bluez_request(int function_name,
                __bt_service_get_parameters(in_param3,
                                &client_id, sizeof(int));
 
-               BT_INFO("GATT Client: client_id[%d]", client_id);
+               BT_DBG("GATT Client: client_id[%d]", client_id);
                result = _bt_connect_le_device(&address, auto_connect, client_id);
                if (BLUETOOTH_ERROR_NONE == result) {
-
                        addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
-                       BT_INFO("GATT Client: Save Invocation data Connect LE app[%s]", sender);
-
                        _bt_convert_addr_type_to_string(addr, address.addr);
 
                        /* Save the informations to invocation */
                        _bt_save_invocation_context(context, result, sender,
                                        function_name, (gpointer)addr);
+
+                       if (auto_connect)
+                               _bt_handle_invocation_context(function_name, (void *)addr);
                } else {
-                       BT_INFO("GATT Client: gatt connect failed");
+                       BT_ERR("GATT Client: gatt connect failed. client_id[%d]", client_id);
                        g_array_append_vals(*out_param1, &address,
                                        sizeof(bluetooth_device_address_t));
                }
@@ -2734,7 +2864,6 @@ int __bt_bluez_request(int function_name,
                result = _bt_disconnect_le_device(&address, client_id);
                if (BLUETOOTH_ERROR_NONE == result) {
                        addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
-                       BT_INFO("GATT Client: Save Invocation data DisConnect LE app[%s]", sender);
 
                        _bt_convert_addr_type_to_string(addr, address.addr);
 
@@ -2747,6 +2876,46 @@ int __bt_bluez_request(int function_name,
                }
                break;
        }
+       /* Sync */
+       case BT_GET_GATT_DATA_BATCHING_AVAILABLE_PACKETS: {
+               guint available_packets = 0;
+
+               result = _bt_gatt_get_data_batching_available_packets(&available_packets);
+               BT_DBG("LE batching available packets %u", available_packets);
+               if (result == BLUETOOTH_ERROR_NONE) {
+                       g_array_append_vals(*out_param1, &available_packets,
+                                       sizeof(guint));
+               }
+
+               break;
+       }
+       /* Sync */
+       case BT_ENABLE_GATT_DATA_BATCHING: {
+               bluetooth_device_address_t address = { {0} };
+               int packet_threshold;
+               int timeout;
+
+               __bt_service_get_parameters(in_param1,
+                               &address, sizeof(bluetooth_device_address_t));
+               __bt_service_get_parameters(in_param2,
+                               &packet_threshold, sizeof(int));
+               __bt_service_get_parameters(in_param3,
+                               &timeout, sizeof(int));
+               result = _bt_gatt_enable_data_batching(&address, packet_threshold, timeout);
+
+               break;
+       }
+       /* Sync */
+       case BT_DISABLE_GATT_DATA_BATCHING: {
+               bluetooth_device_address_t address = { {0} };
+
+               __bt_service_get_parameters(in_param1,
+                               &address, sizeof(bluetooth_device_address_t));
+               result = _bt_gatt_disable_data_batching(&address);
+
+               break;
+       }
+
        case BT_GATT_GET_PRIMARY_SERVICES: {
                char *addr;
 
@@ -2761,8 +2930,6 @@ int __bt_bluez_request(int function_name,
 
                result = _bt_gatt_get_primary_services(addr);
                if (BLUETOOTH_ERROR_NONE == result) {
-                       BT_INFO("GATT Client: Save Remote GATT Server address addr [%s] app[%s]",
-                                       addr, sender);
                        _bt_save_invocation_context(context, result, sender,
                                        function_name, (gpointer)addr);
                } else
@@ -2781,8 +2948,6 @@ int __bt_bluez_request(int function_name,
 
                result = _bt_gatt_get_all_characteristic(&param);
                if (BLUETOOTH_ERROR_NONE == result) {
-                       BT_INFO("GATT Client: Save Invocation data for Service props app[%s]", sender);
-
                        /* Save the informations to invocation */
                        _bt_save_invocation_context(context, result, sender,
                                        function_name,
@@ -2801,8 +2966,6 @@ int __bt_bluez_request(int function_name,
 
                result = _bt_gatt_get_all_characteristic_properties(&param);
                if (BLUETOOTH_ERROR_NONE == result) {
-                       BT_INFO("GATT Client: Save Invocation data for characteristic props app[%s]", sender);
-
                        /* Save the informations to invocation */
                        _bt_save_invocation_context(context, result, sender,
                                        function_name,
@@ -2822,8 +2985,6 @@ int __bt_bluez_request(int function_name,
 
                result = _bt_gatt_read_characteristic_value(&param);
                if (BLUETOOTH_ERROR_NONE == result) {
-                       BT_INFO("GATT Client: Save Invocation data for characteristic props app[%s]", sender);
-
                        /* Save the informations to invocation */
                        _bt_save_invocation_context(context, result, sender,
                                        function_name,
@@ -2843,8 +3004,6 @@ int __bt_bluez_request(int function_name,
 
                result = _bt_gatt_read_descriptor_value(&param);
                if (BLUETOOTH_ERROR_NONE == result) {
-                       BT_INFO("GATT Client: Save Invocation data for Descriptor's props app[%s]", sender);
-
                        /* Save the informations to invocation */
                        _bt_save_invocation_context(context, result, sender,
                                        function_name,
@@ -2872,8 +3031,6 @@ int __bt_bluez_request(int function_name,
 
                result = _bt_gatt_write_characteristic_value_by_type(&param , &data, write_type);
                if (BLUETOOTH_ERROR_NONE == result) {
-                       BT_INFO("GATT Client: Save Invocation data for characteristic props app[%s]", sender);
-
                        /* Save the informations to invocation */
                        _bt_save_invocation_context(context, result, sender,
                                        function_name,
@@ -2900,8 +3057,6 @@ int __bt_bluez_request(int function_name,
 
                result = _bt_gatt_write_descriptor_value_by_type(&param, &data, write_type);
                if (BLUETOOTH_ERROR_NONE == result) {
-                       BT_INFO("GATT Client: Save Invocation data for descriptor props app[%s]", sender);
-
                        /* Save the informations to invocation */
                        _bt_save_invocation_context(context, result, sender,
                                        function_name,
@@ -2939,7 +3094,7 @@ int __bt_bluez_request(int function_name,
                if (is_indicate == false) {
                        result   = _bt_gatt_acquire_notify(&param , &fd, &mtu);
                        if (BLUETOOTH_ERROR_NONE == result && fd > -1) {
-                               BT_INFO("GATT Client: Save Invocation data for characteristic props app[%s] fd[ %d]", sender, fd);
+                               BT_DBG("GATT Client: Save Invocation data for characteristic props app[%s] fd[ %d]", sender, fd);
 
                                GUnixFDList *fd_list = NULL;
                                GError *error = NULL;
@@ -2961,8 +3116,6 @@ int __bt_bluez_request(int function_name,
 normal:
                        result = _bt_gatt_watch_characteristic(&param , client_id, is_notify);
                        if (BLUETOOTH_ERROR_NONE == result) {
-                               BT_INFO("GATT Client: Save Invocation data for characteristic props app[%s]", sender);
-
                                /* Save the informations to invocation */
                                _bt_save_invocation_context(context, result, sender, function_name,
                                         (gpointer)g_memdup(&param, sizeof(bluetooth_gatt_client_char_prop_info_t)));
@@ -3007,21 +3160,46 @@ normal:
        }
 #endif
        case BT_START_LE_DISCOVERY: {
+               uid_t uid = 0;
+               pid_t pid = 0;
+
+               __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
+
                sender = (char *)g_dbus_method_invocation_get_sender(context);
-               result = _bt_start_le_scan(sender);
+
+               if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
+                       BT_ERR("Fail to get the sender pid");
+
+               result = _bt_start_le_scan(sender, uid, pid);
                if (result == BLUETOOTH_ERROR_NONE) {
                        _bt_save_invocation_context(context, result, sender,
                                        function_name, NULL);
+
+                       BT_DBG("Remeber pid / uid for the scan operation");
+                       _bt_bm_add_scan_app(SCAN_LE, uid, pid);
                }
                break;
        }
        case BT_STOP_LE_DISCOVERY: {
+               uid_t uid = 0;
+               pid_t pid = 0;
+
+               __bt_service_get_parameters(in_param1, &uid, sizeof(uid_t));
+
                sender = (char *)g_dbus_method_invocation_get_sender(context);
+
+               if (__bt_service_get_sender_pid(sender, &pid) != BLUETOOTH_ERROR_NONE)
+                       BT_ERR("Fail to get the sender pid");
+
                result = _bt_stop_le_scan(sender);
                if (result == BLUETOOTH_ERROR_NONE) {
                        _bt_save_invocation_context(context, result, sender,
                                        function_name, NULL);
                }
+
+               BT_DBG("Remove pid / uid for the scan operation");
+               _bt_bm_remove_scan_app(SCAN_LE, uid, pid);
+
                break;
        }
        case BT_IS_LE_DISCOVERYING: {
@@ -3034,6 +3212,7 @@ normal:
        }
        case BT_SET_SCAN_PARAMETERS: {
                bluetooth_le_scan_params_t scan_params;
+
                __bt_service_get_parameters(in_param1, &scan_params,
                                sizeof(bluetooth_le_scan_params_t));
 
@@ -3627,13 +3806,15 @@ int __bt_agent_request(int function_name,
                char *uuid;
                char *path;
                int fd;
+               char *sender;
 
+               sender = (char *)g_dbus_method_invocation_get_sender(context);
                __bt_service_get_parameters(in_param1, &type, sizeof(int));
                uuid = (char *)g_variant_get_data(in_param2);
                path = (char *)g_variant_get_data(in_param3);
                __bt_service_get_parameters(in_param4, &fd, sizeof(int));
 
-               result = _bt_register_osp_server_in_agent(type, uuid, path, fd);
+               result = _bt_register_osp_server_in_agent(sender, type, uuid, path, fd);
                break;
        }
        case BT_UNSET_AUTHORIZATION: {
@@ -3818,11 +3999,18 @@ gboolean __bt_service_check_privilege(int function_name,
        case BT_SEARCH_SERVICE:
 
        case BT_RFCOMM_CLIENT_CONNECT:
+               if (function_name == BT_RFCOMM_CLIENT_CONNECT)
+                       BT_PERMANENT_LOG("Connect socket");
        case BT_RFCOMM_CLIENT_CANCEL_CONNECT:
        case BT_RFCOMM_SOCKET_DISCONNECT:
+               if (function_name == BT_RFCOMM_SOCKET_DISCONNECT)
+                       BT_PERMANENT_LOG("Disconnect socket");
        case BT_RFCOMM_SOCKET_WRITE:
        case BT_RFCOMM_CREATE_SOCKET:
        case BT_RFCOMM_REMOVE_SOCKET:
+       case BT_RFCOMM_SEND_RX_DETAILS:
+       case BT_RFCOMM_SEND_TX_DETAILS:
+       case BT_RFCOMM_SERVER_UPDATE_CONNECTION_INFO:
 
        case BT_OPP_PUSH_FILES:
        case BT_OPP_CANCEL_PUSH:
@@ -3856,6 +4044,12 @@ gboolean __bt_service_check_privilege(int function_name,
        case BT_AVRCP_SET_PROPERTIES:
        case BT_AVRCP_CONTROL_SET_PROPERTY:
 
+#ifdef TIZEN_FEATURE_BT_AVC_TARGET
+       case BT_AUDIO_SET_ABSOLUTE_VOLUME:
+       case BT_AUDIO_GET_ABSOLUTE_VOLUME:
+       case BT_AUDIO_IS_AVC_ACTIVATED:
+#endif
+
        case BT_HF_CONNECT:
        case BT_HF_DISCONNECT:
 
@@ -3996,8 +4190,6 @@ gboolean __bt_service_check_privilege(int function_name,
        }
        break;
 
-       case BT_RFCOMM_SEND_RX_DETAILS:
-        case BT_RFCOMM_SEND_TX_DETAILS:
        case BT_ENABLE_ADAPTER:
        case BT_DISABLE_ADAPTER:
        case BT_RESET_ADAPTER:
@@ -4041,6 +4233,10 @@ gboolean __bt_service_check_privilege(int function_name,
        case BT_LE_OOB_READ_LOCAL_DATA:
        case BT_LE_OOB_ADD_REMOTE_DATA:
 
+       case BT_GET_GATT_DATA_BATCHING_AVAILABLE_PACKETS:
+       case BT_ENABLE_GATT_DATA_BATCHING:
+       case BT_DISABLE_GATT_DATA_BATCHING:
+
        case BT_LE_IPSP_INIT:
        case BT_LE_IPSP_DEINIT:
        case BT_LE_IPSP_CONNECT:
@@ -4104,6 +4300,7 @@ gboolean __bt_service_check_privilege(int function_name,
        case BT_IS_DISCOVERYING:
        case BT_IS_LE_DISCOVERYING:
        case BT_IS_CONNECTABLE:
+       case BT_GET_CONNECTABLE:
        case BT_GET_BONDED_DEVICES:
        case BT_GET_PROFILE_CONNECTED_DEVICES:
        case BT_GET_BONDED_DEVICE:
@@ -4219,6 +4416,9 @@ static void __name_owner_changed(GDBusConnection *connection,
 
        /* Check if le_scanning app is terminated */
        _bt_check_le_scanner_app_termination(name);
+
+       /* Check if RFCOMM server is terminated */
+       _bt_rfcomm_server_check_termination(name);
 }
 
 static void __bt_service_bus_acquired_handler(GDBusConnection *connection,
@@ -4259,6 +4459,19 @@ gboolean _is_name_acquired(void)
        return name_acquired;
 }
 
+void _bt_service_unref_connection(void)
+{
+       BT_INFO("+");
+
+       if (bt_service_conn) {
+               g_dbus_connection_flush_sync(bt_service_conn, NULL, NULL);
+               g_object_unref(bt_service_conn);
+               bt_service_conn = NULL;
+       }
+
+       BT_INFO("-");
+}
+
 int _bt_service_register(void)
 {
        GDBusConnection *conn;
@@ -4300,21 +4513,20 @@ fail:
 void _bt_service_unregister(void)
 {
        if (bt_service_conn) {
+               sd_notify(0, "STOPPING=1");
+
                if (owner_sig_id > 0) {
                        g_dbus_connection_signal_unsubscribe(
                                        bt_service_conn, owner_sig_id);
                        owner_sig_id = 0;
                }
 
-               __bt_service_register_object(bt_service_conn, NULL, FALSE);
-               if (bt_service_conn) {
-                       g_object_unref(bt_service_conn);
-                       bt_service_conn = NULL;
-               }
                if (owner_id > 0) {
                        g_bus_unown_name(owner_id);
                        owner_id = 0;
                }
+
+               __bt_service_register_object(bt_service_conn, NULL, FALSE);
        }
 }
 
@@ -4359,24 +4571,22 @@ void _bt_service_method_return(GDBusMethodInvocation *invocation,
                GArray *out_param, int result)
 {
        GVariant *out_var;
-       BT_DBG("+");
+       BT_DBG("");
        out_var = g_variant_new_from_data((const GVariantType *)"ay",
                        out_param->data, out_param->len, TRUE, NULL, NULL);
 
        g_dbus_method_invocation_return_value(invocation,
                        g_variant_new("(iv)", result, out_var));
-       BT_DBG("-");
 }
 
 void _bt_service_method_return_with_unix_fd_list(GDBusMethodInvocation *invocation,
                GArray *out_param, int result, GUnixFDList *fd_list)
 {
        GVariant *out_var;
-       BT_DBG("+");
+       BT_DBG("");
        out_var = g_variant_new_from_data((const GVariantType *)"ay",
                        out_param->data, out_param->len, TRUE, NULL, NULL);
 
        g_dbus_method_invocation_return_value_with_unix_fd_list(invocation,
                        g_variant_new("(iv)", result, out_var), fd_list);
-       BT_DBG("-");
 }