Fix the crash dump in FHUB efl TCT
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-event-receiver.c
index c1b7037..f3d50f3 100644 (file)
@@ -44,6 +44,7 @@
 #include "bt-service-opp-client.h"
 #include "bt-service-map-client.h"
 #include "bt-service-tds.h"
+#include "bt-service-otp.h"
 
 #ifdef TIZEN_FEATURE_BT_DPM
 #include "bt-service-dpm.h"
@@ -408,36 +409,6 @@ void __bt_update_remote_cache_devinfo(const char *address, gboolean paired_statu
        BT_DBG("-");
 }
 
-static void __bt_device_remote_connected_properties(
-                               bt_remote_dev_info_t *remote_dev_info,
-                               char *address, gboolean connected)
-{
-       int result = BLUETOOTH_ERROR_NONE;
-       int i;
-       GVariant *param = NULL;
-       BT_DBG("+");
-
-       if (remote_dev_info->uuid_count > 0) {
-               for (i = 0; i < remote_dev_info->uuid_count; i++) {
-                       char *uuid = remote_dev_info->uuids[i];
-                       if (strcasecmp(uuid, HID_UUID) == 0) {
-                               int event = BLUETOOTH_EVENT_NONE;
-
-                               event = (connected == TRUE) ?
-                                       BLUETOOTH_HID_CONNECTED :
-                                       BLUETOOTH_HID_DISCONNECTED;
-                               param = g_variant_new("(is)", result,
-                                                       address);
-                               _bt_send_event(BT_HID_EVENT, event,
-                                       param);
-                               break;
-                       }
-               }
-       }
-
-       BT_DBG("-");
-}
-
 gboolean __bt_handle_is_flight_mode_enabled(void)
 {
        int is_flight_mode = 0;
@@ -628,15 +599,21 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
        GError *err = NULL;
        char *property = NULL;
        GVariant *param = NULL;
+
        g_variant_iter_init(&value_iter, msg);
        while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
                BT_INFO("Property %s", property);
 
                if (strcasecmp(property, "Discovering") == 0) {
                        gboolean discovering = FALSE;
+
+                       if (_bt_adapter_get_status() != BT_ACTIVATED)
+                               continue;
+
                        g_variant_get(val, "b", &discovering);
-                       /* Send event to application */
                        BT_DBG("Discovering %d", discovering);
+
+                       /* Send event to application */
                        if (discovering == TRUE) {
                                _bt_set_discovery_status(TRUE);
                                param = g_variant_new("(i)", result);
@@ -644,10 +621,12 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
                                        BLUETOOTH_EVENT_DISCOVERY_STARTED,
                                        param);
                        } else {
-                               ret_if(event_id > 0);
+                               if (event_id > 0)
+                                       continue;
 
                                adapter_proxy = _bt_get_adapter_proxy();
-                               ret_if(adapter_proxy == NULL);
+                               if (adapter_proxy == NULL)
+                                       continue;
 
                                /* Need to stop searching */
                                ret = g_dbus_proxy_call_sync(adapter_proxy, "StopDiscovery",
@@ -668,26 +647,34 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
                } else if (strcasecmp(property, "LEDiscovering") == 0) {
                        gboolean le_discovering = FALSE;
 
+                       if (_bt_adapter_get_status() != BT_ACTIVATED ||
+                           _bt_adapter_get_le_status() != BT_LE_ACTIVATED)
+                               continue;
+
                        g_variant_get(val, "b", &le_discovering);
+                       BT_DBG("LEDiscovering %d", le_discovering);
+
                        /* Send event to application */
                        if (le_discovering == TRUE) {
                                _bt_set_le_scan_status(TRUE);
                                param = g_variant_new("(i)", result);
                                _bt_send_event(BT_LE_ADAPTER_EVENT,
-                               BLUETOOTH_EVENT_LE_DISCOVERY_STARTED,
-                               param);
+                                       BLUETOOTH_EVENT_LE_DISCOVERY_STARTED,
+                                       param);
                        } else {
-                               ret_if(le_scan_event_id > 0);
+                               if (le_scan_event_id > 0)
+                                       continue;
 
                                adapter_proxy = _bt_get_adapter_proxy();
-                               ret_if(adapter_proxy == NULL);
+                               if (adapter_proxy == NULL)
+                                       continue;
 
                                /* Need to stop searching */
                                ret = g_dbus_proxy_call_sync(adapter_proxy, "StopLEDiscovery",
-                                       NULL,
-                                       G_DBUS_CALL_FLAGS_NONE,
-                                       DBUS_TIMEOUT, NULL,
-                                       &err);
+                                               NULL,
+                                               G_DBUS_CALL_FLAGS_NONE,
+                                               DBUS_TIMEOUT, NULL,
+                                               &err);
                                if (err) {
                                        BT_ERR("Dbus Error %s", err->message);
                                        g_clear_error(&err);
@@ -697,25 +684,23 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
 
                                le_scan_event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
                                                (GSourceFunc)__bt_le_discovery_finished_cb, NULL);
-                               }
+                       }
                } else if (strcasecmp(property, "Name") == 0) {
                        char *name = NULL;
-                       g_variant_get(val, "s", &name);
+                       g_variant_get(val, "&s", &name);
                        param = g_variant_new("(is)", result, name);
                        /* Send event to application */
                        _bt_send_event(BT_ADAPTER_EVENT,
                                BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
                                param);
-                       g_free(name);
                } else if (strcasecmp(property, "Alias") == 0) {
                        char *alias = NULL;
-                       g_variant_get(val, "s", &alias);
+                       g_variant_get(val, "&s", &alias);
                        param = g_variant_new("(is)", result, alias);
                        /* Send event to application */
                        _bt_send_event(BT_ADAPTER_EVENT,
                                BLUETOOTH_EVENT_LOCAL_NAME_CHANGED,
                                param);
-                       g_free(alias);
                } else if (strcasecmp(property, "Discoverable") == 0) {
                        gboolean discoverable = FALSE;
 
@@ -724,29 +709,33 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
 
                        if (discoverable == FALSE) {
                                if (_bt_get_discoverable_timeout_property() > 0) {
-                                       int time = 0;
+                                       unsigned int time = 0;
+
                                        adapter_proxy = _bt_get_adapter_properties_proxy();
-                                       ret_if(adapter_proxy == NULL);
+                                       if (adapter_proxy == NULL)
+                                               continue;
+
                                        ret = g_dbus_proxy_call_sync(adapter_proxy, "Set",
                                                g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
                                                "DiscoverableTimeout",
-                                               g_variant_new("i", time)),
+                                               g_variant_new("u", time)),
                                                G_DBUS_CALL_FLAGS_NONE,
                                                DBUS_TIMEOUT, NULL,
                                                &err);
-
                                        if (err != NULL) {
-                                               BT_ERR("StopLEDiscovery Failed: %s", err->message);
-                                               g_error_free(err);
+                                               BT_ERR("Set DiscoverableTimeout Failed: %s", err->message);
+                                               g_clear_error(&err);
                                        }
                                        if (ret)
                                                g_variant_unref(ret);
                                }
 
+                               _bt_stop_visibility_timer();
+
                                mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
 
                                /* Send event to application */
-                               BT_INFO("[Connectable]");
+                               BT_INFO("[Non Discoverable]");
                                param = g_variant_new("(in)", result, mode);
                                _bt_send_event(BT_ADAPTER_EVENT,
                                        BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
@@ -755,11 +744,8 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
                                _bt_get_discoverable_mode(&mode);
 
                                /* Event will be sent by "DiscoverableTimeout" signal */
-                               if (mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
-                                       g_free(property);
-                                       g_variant_unref(val);
-                                       return;
-                               }
+                               if (mode != BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE)
+                                       continue;
 
                                /* Send event to application */
                                BT_INFO("[General Discoverable]");
@@ -773,19 +759,16 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
 
                        /* Event was already sent by "Discoverable" signal */
                        if (mode == BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE ||
-                               mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE) {
-                               g_free(property);
-                               g_variant_unref(val);
-                               return;
-                       }
+                           mode == BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE)
+                               continue;
 
                        /* Send event to application */
                        BT_INFO("[Limited Discoverable (Timeout %u secs)]",
-                       _bt_get_discoverable_timeout_property());
+                                       _bt_get_discoverable_timeout_property());
                        param = g_variant_new("(in)", result, mode);
                        _bt_send_event(BT_ADAPTER_EVENT,
-                               BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
-                               param);
+                                       BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED,
+                                       param);
                } else if (strcasecmp(property, "Powered") == 0) {
                        /* TODO: Need to check this operation!! */
                        gboolean powered = FALSE;
@@ -833,18 +816,17 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
                        char *name = NULL;
                        char *value = NULL;
                        GVariantIter *iter = NULL;
-                       g_variant_get(val, "as", &iter);
 
-                       ret_if(iter == NULL);
+                       g_variant_get(val, "as", &iter);
+                       if (iter == NULL)
+                               continue;
 
-                       while (g_variant_iter_loop(iter, "s", &name)) {
-                               BT_DBG("name = %s", name);
-                               g_variant_iter_loop(iter, "s", &value);
-                               BT_DBG("Value = %s", value);
-                               if (FALSE == _bt_update_le_feature_support(name, value))
-                                       BT_INFO("Fail to update LE feature info");
+                       while (g_variant_iter_next(iter, "&s", &name) &&
+                              g_variant_iter_next(iter, "&s", &value)) {
+                               BT_DBG("name = %s, Value = %s", name, value);
+                               if (!_bt_update_le_feature_support(name, value))
+                                       BT_ERR("Failed to update LE feature (name = %s, value = %s)", name, value);
                        }
-
                        g_variant_iter_free(iter);
                } else if (strcasecmp(property, "IpspInitStateChanged") == 0) {
                        gboolean ipsp_initialized = FALSE;
@@ -858,7 +840,7 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
                                        BLUETOOTH_EVENT_IPSP_INIT_STATE_CHANGED,
                                        param);
                } else {
-                       BT_DBG("property : [%s]", property);
+                       BT_DBG("Unhandled property : [%s]", property);
                }
        }
 }
@@ -921,7 +903,6 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path)
        char *property = NULL;
        char *address;
        GVariant *param = NULL;
-       bt_remote_dev_info_t *remote_dev_info;
        g_variant_iter_init(&value_iter, msg);
 #ifdef TIZEN_FEATURE_BT_DPM
        int desktop_state = DPM_BT_ERROR;
@@ -944,15 +925,6 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path)
                        BT_DBG("connected: %d", connected);
                        BT_DBG("address: %s", address);
 
-                       remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
-
-                       if (remote_dev_info != NULL) {
-                               __bt_device_remote_connected_properties(
-                                               remote_dev_info, address,
-                                               connected != BLUETOOTH_CONNECTED_LINK_NONE ?
-                                               TRUE : FALSE);
-                               _bt_free_device_info(remote_dev_info);
-                       }
                        param = g_variant_new("(is)", result, address);
                        /* Send event to application */
                        _bt_send_event(BT_DEVICE_EVENT,
@@ -1273,7 +1245,6 @@ static void __bt_media_control_changed_event(GVariant *msg, const char *path)
        char *address;
        GVariant *val = NULL;
        GVariant *child = NULL;
-       bt_remote_dev_info_t *remote_dev_info;
        GVariant *param = NULL;
        g_variant_iter_init(&value_iter, msg);
        while ((child = g_variant_iter_next_value(&value_iter))) {
@@ -1294,13 +1265,6 @@ static void __bt_media_control_changed_event(GVariant *msg, const char *path)
                        BT_DBG("connected: %d", connected);
                        BT_DBG("address: %s", address);
 
-                       remote_dev_info = _bt_get_remote_device_info(address);
-
-                       if (remote_dev_info != NULL) {
-                               __bt_device_remote_connected_properties(
-                               remote_dev_info, address, connected);
-                               _bt_free_device_info(remote_dev_info);
-                       }
                        param = g_variant_new("(is)", result, address);
                        /* Send event to application */
                        _bt_send_event(BT_AVRCP_EVENT,
@@ -1688,17 +1652,14 @@ void __bt_gatt_char_property_changed_event(GVariant *msg,
        GVariant *val = NULL;
        g_variant_iter_init(&value_iter, msg);
        while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
-               BT_INFO("Property %s", property);
+               BT_DBG("Property %s", property);
 
                ret_if(property == NULL);
 
                if (strcasecmp(property, "Notifying") == 0) {
                        gboolean property_flag = FALSE;
                        g_variant_get(val, "b", &property_flag);
-                       if (property_flag == TRUE)
-                               BT_DBG("notifying is enabled");
-                       else
-                               BT_DBG("notifying is disabled");
+                       BT_INFO("Notifying is %s", property_flag ? "enabled" : "disabled");
                }
        }
 }
@@ -1709,6 +1670,9 @@ void _bt_handle_gatt_event(GVariant *msg, const char *member, const char *path)
        if (strcasecmp(member, "GattValueChanged") == 0) {
                /* Check TDS seekers waiting for Indication  */
                _bt_tds_check_indication(path, msg);
+#ifdef TIZEN_FEATURE_BT_OTP
+               _bt_otp_check_indication(path, msg);
+#endif
        } else {
                BT_INFO("Unhandled event");
        }
@@ -1868,7 +1832,7 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                address = g_malloc0(BT_ADDRESS_STRING_SIZE);
 
                _bt_convert_device_path_to_address(path, address);
-               dev_name = _bt_get_bonded_device_name(address);
+               dev_name = _bt_get_device_name(address);
 
                _bt_convert_addr_string_to_secure_string(secure_address, address);
                BT_INFO("Address : %s Type : %d", secure_address, addr_type);
@@ -1876,6 +1840,9 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                                !addr_type ? dev_name : secure_address);
                g_free(dev_name);
 
+               if (addr_type)
+                       _bt_add_le_connected_dev_info(address);
+
                _bt_logging_connection(TRUE, addr_type);
                param = g_variant_new("(isy)", result, address, addr_type);
                /*Send event to application*/
@@ -1902,15 +1869,17 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                      0x02 BDADDR_LE_RANDOM */
                _bt_convert_addr_string_to_secure_string(secure_address, address);
                BT_INFO("Address : %s Type : %d", secure_address, addr_type);
-               BT_ERR_C("### Disconnected [%s] [%d : %s] [%s]", !addr_type ? "BREDR" : "LE",
-                               disc_reason, _bt_convert_disc_reason_to_string(disc_reason),
-                               !addr_type ? dev_name : secure_address);
+               BT_ERR_C("### Disconnected [%s] [%s] [%d : %s]", !addr_type ? "BREDR" : "LE",
+                               !addr_type ? dev_name : secure_address,
+                               disc_reason, _bt_convert_disc_reason_to_string(disc_reason));
                g_free(dev_name);
 
                _bt_headset_set_local_connection(FALSE);
                _bt_logging_connection(FALSE, addr_type);
 
-               if (!addr_type) {
+               if (addr_type)
+                       _bt_remove_le_connected_dev_info(address);
+               else {
 #ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
                        {
                                int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
@@ -1963,11 +1932,11 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
 
                _bt_convert_device_path_to_address(path, address);
                _bt_convert_addr_string_to_type(bd_addr.addr, address);
-
                _bt_convert_addr_string_to_secure_string(secure_address, address);
-               BT_DBG("Address: %s", secure_address);
-               BT_DBG("Profile UUID: %s", profile_uuid);
-               BT_DBG("State: %d", state);
+
+               BT_INFO_C("[%s] state: %s, addr: %s",
+                       _bt_convert_uuid_to_string(profile_uuid),
+                       _bt_convert_profile_state_to_string(state), secure_address);
 
                if ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0)  &&
                        (state == BT_PROFILE_STATE_CONNECTED)) {
@@ -1979,17 +1948,17 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                        gboolean connected;
 #endif
                        bt_headset_wait_t *wait_list;
-                       guint restricted = 0x0;
+                       guint trusted = TRUE;
 
                        __bt_set_device_values(TRUE,
                                VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
 
                        __bt_connection_manager_set_state(address, event);
 
-                       _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_HFP_HS, &restricted);
+                       _bt_get_trust_profile(&bd_addr, TRUSTED_PROFILE_HFP_HF, &trusted);
 
                        if (_bt_headset_get_local_connection() == FALSE) {
-                               if (restricted == 0x0) /* not restricted*/
+                               if (trusted == TRUE) /* not restricted*/
                                        _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
                        } else {
                                /* Connection Started from local device therefore no need to
@@ -2193,12 +2162,12 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
 
                le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
 
-               g_variant_get(msg, "(syyii@ay)", &le_dev_info->address,
-                                               &le_dev_info->addr_type,
-                                               &le_dev_info->adv_type,
-                                               &le_dev_info->rssi,
-                                               &le_dev_info->adv_data_len,
-                                               &value);
+               g_variant_get(msg, "(&syyii@ay)", &le_dev_info->address,
+                                                 &le_dev_info->addr_type,
+                                                 &le_dev_info->adv_type,
+                                                 &le_dev_info->rssi,
+                                                 &le_dev_info->adv_data_len,
+                                                 &value);
 
                if (value == NULL) {
                        _bt_free_le_device_info(le_dev_info);
@@ -2280,11 +2249,13 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                address = g_malloc0(BT_ADDRESS_STRING_SIZE);
                _bt_convert_device_path_to_address(path, address);
 
-               BT_DBG("Ipsp BT Interface Name: %s", ifname);
-               BT_DBG("address: %s", address);
+               BT_DBG("Ipsp BT Interface Name: %s, address: %s", ifname, address);
+
                param = g_variant_new("(iss)", result, address, ifname);
                ipsp_param = g_variant_new("(ss)", ifname, address);
 
+               g_free(ifname);
+
                /* Set Ipv6 Addr */
                GDBusProxy *ipsp_proxy;
                if (connected) {
@@ -2293,6 +2264,8 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                        if (ipsp_proxy == NULL) {
                                BT_ERR("can not get ipsp proxy");
                                g_free(address);
+                               g_variant_unref(param);
+                               g_variant_unref(ipsp_param);
                                return;
                        }
 
@@ -2300,11 +2273,13 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                                        ipsp_param, G_DBUS_CALL_FLAGS_NONE,
                                        -1, NULL, NULL, NULL);
                } else {
+                       g_variant_unref(ipsp_param);
                        BT_DBG("IPSP disconnected");
                        ipsp_proxy = _bt_get_ipsp_proxy();
                        if (ipsp_proxy == NULL) {
                                BT_ERR("can not get ipsp proxy");
                                g_free(address);
+                               g_variant_unref(param);
                                return;
                        }
 
@@ -2314,9 +2289,7 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                }
 
                /* Send event to application */
-               _bt_send_event(BT_DEVICE_EVENT,
-                                               event,
-                                               param);
+               _bt_send_event(BT_DEVICE_EVENT, event, param);
                g_free(address);
        } else if (strcasecmp(member, "AttMtuChanged") == 0) {
                int result = BLUETOOTH_ERROR_NONE;
@@ -2328,8 +2301,7 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                address = g_malloc0(BT_ADDRESS_STRING_SIZE);
 
                _bt_convert_device_path_to_address(path, address);
-               _bt_convert_addr_string_to_secure_string(secure_address, address);
-               BT_DBG("Address : %s MTU changed : %d", secure_address, mtu);
+               BT_DBG("Address : %s MTU changed : %d", address, mtu);
 
                param = g_variant_new("(isqy)",
                        result,
@@ -2343,6 +2315,21 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                        param);
 
                g_free(address);
+       }  else if (strcasecmp(member, "OtcDisconnected") == 0) {
+               gboolean connected = FALSE;
+               GVariant *otc_param = NULL;
+
+               address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+               _bt_convert_device_path_to_address(path, address);
+
+               BT_DBG("OTC Disconnected, address: %s", address);
+               otc_param = g_variant_new("(ibsn)", result, connected, address);
+
+               /* Send event to application */
+               _bt_send_event(BT_OTP_EVENT,
+                                               BLUETOOTH_EVENT_OTC_STATE_CHANGED,
+                                               otc_param);
+               g_free(address);
        }
 }
 
@@ -2353,7 +2340,7 @@ void __bt_set_audio_values(gboolean connected, char *address)
 
        /*  Set the headset name */
        if (connected == TRUE)
-               name = _bt_get_bonded_device_name(address);
+               name = _bt_get_device_name(address);
        else
                name = g_strdup("");
 
@@ -2405,7 +2392,7 @@ void _bt_handle_headset_event(GVariant *msg, const char *path)
                int event = BLUETOOTH_EVENT_NONE;
                bt_headset_wait_t *wait_list;
                char *address;
-               guint restricted = 0x0;
+               guint trusted = TRUE;
                g_variant_get(value, "b", &property_flag);
 
                address = g_malloc0(BT_ADDRESS_STRING_SIZE);
@@ -2415,10 +2402,10 @@ void _bt_handle_headset_event(GVariant *msg, const char *path)
 
                if (property_flag == TRUE) {
                        event = BLUETOOTH_EVENT_AG_CONNECTED;
-                       _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_A2DP, &restricted);
+                       _bt_get_trust_profile(&bd_addr, TRUSTED_PROFILE_A2DP, &trusted);
 
                        if (_bt_headset_get_local_connection() == FALSE) {
-                               if (restricted == 0x0) /* not restricted*/
+                               if (trusted == TRUE) /* not restricted*/
                                        _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
                        } else
                                _bt_headset_set_local_connection(FALSE);
@@ -2456,7 +2443,6 @@ void _bt_handle_headset_event(GVariant *msg, const char *path)
                                                        wait_list->address);
                        _bt_audio_connect(wait_list->req_id, wait_list->type,
                                        &device_address, NULL);
-                       _bt_rel_wait_data();
                } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
                        /* Add data to the connected list */
                        _bt_add_headset_to_list(BT_AUDIO_HSP,
@@ -2656,8 +2642,6 @@ void _bt_handle_agent_event(GVariant *msg, const char *member)
                        BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
                        param);
                /* TODO: MAP? see above */
-               g_free(address);
-               g_free(name);
        } else if (strcasecmp(member, "RfcommAuthorize") == 0) {
                bt_rfcomm_server_info_t *server_info;
 
@@ -2671,9 +2655,6 @@ void _bt_handle_agent_event(GVariant *msg, const char *member)
                _bt_send_event(BT_RFCOMM_SERVER_EVENT,
                        BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
                        param);
-               g_free(address);
-               g_free(uuid);
-               g_free(name);
        }
 }
 
@@ -2797,8 +2778,11 @@ static  void __bt_manager_event_filter(GDBusConnection *connection,
 #ifdef TIZEN_FEATURE_BT_DPM
                                int desktop_state = DPM_BT_ERROR;
 #endif
-                               ret_if(_bt_is_discovering() == FALSE &&
-                                               _bt_is_le_scanning() == FALSE);
+                               if (_bt_is_discovering() == FALSE &&
+                                   _bt_is_le_scanning() == FALSE) {
+                                       g_variant_unref(value);
+                                       return;
+                               }
 
                                cache_info = g_malloc0(sizeof(bt_cache_info_t));
 
@@ -2911,24 +2895,23 @@ static  void __bt_manager_event_filter(GDBusConnection *connection,
                        return;
                }
 
-               if (*current != '\0') {
-                       g_free(current);
-                       if (name)
-                               g_free(name);
-                       if (previous)
-                               g_free(previous);
+               if (*current != '\0')
+                       return;
+
+               if (name == NULL)
                        return;
-               }
 
                if (strcasecmp(name, BT_BLUEZ_NAME) == 0) {
                        BT_INFO_C("### Bluetoothd is terminated");
                        if (_bt_adapter_get_status() != BT_DEACTIVATING &&
                                _bt_adapter_get_status() != BT_DEACTIVATED) {
-                               BT_INFO_C("### Recover it");
-                               _bt_recover_adapter();
+                               BT_INFO_C("Turn Off Bluetooth");
+                               _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
+                               _bt_disable_cb();
                        }
                        _bt_handle_adapter_removed();
                        __bt_devices_list_free();
+                       _bt_service_adapter_le_deinit();
                }
 
                _bt_obex_server_check_allocation(&value);
@@ -2945,6 +2928,9 @@ static  void __bt_manager_event_filter(GDBusConnection *connection,
                        _bt_rfcomm_server_check_termination(name);
                }
 
+               /* Reset connection interval */
+               _bt_remove_all_le_conn_param_info(name);
+
                /* Stop advertising started by terminated process */
                _bt_stop_advertising_by_terminated_process(name);
                /* Stop LE Scan */
@@ -2955,10 +2941,6 @@ static  void __bt_manager_event_filter(GDBusConnection *connection,
 
                /* Stop the Transport Discovery service */
                _bt_tds_stop_by_terminated_process(name);
-
-               g_free(name);
-               g_free(previous);
-               g_free(current);
        } else if (g_strcmp0(interface_name, BT_PROPERTIES_INTERFACE) == 0) {
                const char *path = object_path;
 
@@ -3162,7 +3144,7 @@ int _bt_opp_client_event_init(void)
        GError *error = NULL;
 
        if (opc_obexd_conn == NULL) {
-               opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
+               opc_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
 
                if (!opc_obexd_conn) {
                        if (error) {
@@ -3224,7 +3206,7 @@ int _bt_map_client_event_init(void)
        GError *error = NULL;
 
        if (map_obexd_conn == NULL) {
-               map_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
+               map_obexd_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
 
                if (!map_obexd_conn) {
                        if (error) {
@@ -3261,50 +3243,50 @@ int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
        if (conn == NULL)
                return -1;
 
-       static int subs_interface_added_id = -1;
-       static int subs_interface_removed_id = -1;
-       static int subs_name_owner_id = -1;
-       static int subs_property_id = -1;
-       static int subs_adapter_id = -1;
-       static int subs_gatt_id = -1;
+       static guint subs_interface_added_id;
+       static guint subs_interface_removed_id;
+       static guint subs_name_owner_id;
+       static guint subs_property_id;
+       static guint subs_adapter_id;
+       static guint subs_gatt_id;
 
        if (subscribe) {
-               if (subs_interface_added_id == -1) {
+               if (subs_interface_added_id == 0) {
                        subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_MANAGER_INTERFACE,
                                BT_INTERFACES_ADDED, NULL, NULL, 0,
                                __bt_manager_event_filter,
                                NULL, NULL);
                }
-               if (subs_interface_removed_id == -1) {
+               if (subs_interface_removed_id == 0) {
                        subs_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_MANAGER_INTERFACE,
                                BT_INTERFACES_REMOVED, NULL, NULL, 0,
                                __bt_manager_event_filter,
                                NULL, NULL);
                }
-               if (subs_name_owner_id == -1) {
+               if (subs_name_owner_id == 0) {
                        subs_name_owner_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_FREEDESKTOP_INTERFACE,
                                BT_NAME_OWNER_CHANGED, NULL, NULL, 0,
                                __bt_manager_event_filter,
                                NULL, NULL);
                }
-               if (subs_property_id == -1) {
+               if (subs_property_id == 0) {
                        subs_property_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_PROPERTIES_INTERFACE,
                                BT_PROPERTIES_CHANGED, NULL, NULL, 0,
                                __bt_manager_event_filter,
                                NULL, NULL);
                }
-               if (subs_adapter_id == -1) {
+               if (subs_adapter_id == 0) {
                        subs_adapter_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_ADAPTER_INTERFACE,
                                NULL, NULL, NULL, 0,
                                __bt_manager_event_filter,
                                NULL, NULL);
                }
-               if (subs_gatt_id == -1) {
+               if (subs_gatt_id == 0) {
                        subs_gatt_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_GATT_CHAR_INTERFACE,
                                NULL, NULL, NULL, 0,
@@ -3312,33 +3294,33 @@ int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
                                NULL, NULL);
                }
        } else {
-               if (subs_interface_added_id != -1) {
+               if (subs_interface_added_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_interface_added_id);
-                       subs_interface_added_id = -1;
+                       subs_interface_added_id = 0;
                }
-               if (subs_interface_removed_id != -1) {
+               if (subs_interface_removed_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_interface_removed_id);
-                       subs_interface_removed_id = -1;
+                       subs_interface_removed_id = 0;
                }
-               if (subs_name_owner_id != -1) {
+               if (subs_name_owner_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_name_owner_id);
-                       subs_name_owner_id = -1;
+                       subs_name_owner_id = 0;
                }
-               if (subs_property_id != -1) {
+               if (subs_property_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_property_id);
-                       subs_property_id = -1;
+                       subs_property_id = 0;
                }
-               if (subs_adapter_id != -1) {
+               if (subs_adapter_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn, subs_adapter_id);
-                       subs_adapter_id = -1;
+                       subs_adapter_id = 0;
                }
-               if (subs_gatt_id != -1) {
+               if (subs_gatt_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn, subs_gatt_id);
-                       subs_gatt_id = -1;
+                       subs_gatt_id = 0;
                }
        }
        return 0;
@@ -3350,10 +3332,10 @@ int _bt_register_device_subscribe_signal(GDBusConnection *conn,
        if (conn == NULL)
                return -1;
 
-       static int subs_device_id = -1;
+       static guint subs_device_id = 0;
 
        if (subscribe) {
-               if (subs_device_id == -1) {
+               if (subs_device_id == 0) {
                        subs_device_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_DEVICE_INTERFACE,
                                NULL, NULL, NULL, 0,
@@ -3361,10 +3343,10 @@ int _bt_register_device_subscribe_signal(GDBusConnection *conn,
                                NULL, NULL);
                }
        } else {
-               if (subs_device_id != -1) {
+               if (subs_device_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_device_id);
-                       subs_device_id = -1;
+                       subs_device_id = 0;
                }
        }
        return 0;
@@ -3376,10 +3358,10 @@ int _bt_register_input_subscribe_signal(GDBusConnection *conn,
        if (conn == NULL)
                return -1;
 
-       static int subs_input_id = -1;
+       static int subs_input_id = 0;
 
        if (subscribe) {
-               if (subs_input_id == -1) {
+               if (subs_input_id == 0) {
                        subs_input_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_INPUT_INTERFACE,
                                NULL, NULL, NULL, 0,
@@ -3387,10 +3369,10 @@ int _bt_register_input_subscribe_signal(GDBusConnection *conn,
                                NULL, NULL);
                }
        } else {
-               if (subs_input_id != -1) {
+               if (subs_input_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_input_id);
-                       subs_input_id = -1;
+                       subs_input_id = 0;
                }
        }
        return 0;
@@ -3402,18 +3384,18 @@ int _bt_register_network_subscribe_signal(GDBusConnection *conn,
        if (conn == NULL)
                return -1;
 
-       static int subs_serv_id = -1;
-       static int subs_client_id = -1;
+       static guint subs_serv_id = 0;
+       static guint subs_client_id = 0;
 
        if (subscribe) {
-               if (subs_serv_id == -1) {
+               if (subs_serv_id == 0) {
                        subs_serv_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_NETWORK_SERVER_INTERFACE,
                                NULL, NULL, NULL, 0,
                                __bt_manager_event_filter,
                                NULL, NULL);
                }
-               if (subs_client_id == -1) {
+               if (subs_client_id == 0) {
                        subs_client_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_NETWORK_CLIENT_INTERFACE,
                                NULL, NULL, NULL, 0,
@@ -3421,15 +3403,15 @@ int _bt_register_network_subscribe_signal(GDBusConnection *conn,
                                NULL, NULL);
                }
        } else {
-               if (subs_serv_id != -1) {
+               if (subs_serv_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_serv_id);
-                       subs_serv_id = -1;
+                       subs_serv_id = 0;
                }
-               if (subs_client_id != -1) {
+               if (subs_client_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_client_id);
-                       subs_client_id = -1;
+                       subs_client_id = 0;
                }
        }
        return 0;
@@ -3441,18 +3423,18 @@ int _bt_register_audio_subscribe_signal(GDBusConnection *conn,
        if (conn == NULL)
                return -1;
 
-       static int subs_headset_id = -1;
-       static int subs_sink_id = -1;
+       static guint subs_headset_id = 0;
+       static guint subs_sink_id = 0;
 
        if (subscribe) {
-               if (subs_headset_id == -1) {
+               if (subs_headset_id == 0) {
                        subs_headset_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_HEADSET_INTERFACE,
                                NULL, NULL, NULL, 0,
                                __bt_manager_event_filter,
                                NULL, NULL);
                }
-               if (subs_sink_id == -1) {
+               if (subs_sink_id == 0) {
                        subs_sink_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_SINK_INTERFACE,
                                NULL, NULL, NULL, 0,
@@ -3460,15 +3442,15 @@ int _bt_register_audio_subscribe_signal(GDBusConnection *conn,
                                NULL, NULL);
                }
        } else {
-               if (subs_headset_id != -1) {
+               if (subs_headset_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_headset_id);
-                       subs_headset_id = -1;
+                       subs_headset_id = 0;
                }
-               if (subs_sink_id != -1) {
+               if (subs_sink_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_sink_id);
-                       subs_sink_id = -1;
+                       subs_sink_id = 0;
                }
        }
        return 0;
@@ -3480,27 +3462,27 @@ int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
        if (conn == NULL)
                return -1;
 
-       static int subs_opp_server_interface_added_id = -1;
-       static int subs_opp_server_interface_removed_id = -1;
-       static int subs_opp_server_property_id = -1;
+       static guint subs_opp_server_interface_added_id = 0;
+       static guint subs_opp_server_interface_removed_id = 0;
+       static guint subs_opp_server_property_id = 0;
 
 
        if (subscribe) {
-               if (subs_opp_server_interface_added_id == -1) {
+               if (subs_opp_server_interface_added_id == 0) {
                        subs_opp_server_interface_added_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_MANAGER_INTERFACE,
                                BT_INTERFACES_ADDED, NULL, NULL, 0,
                                __bt_obexd_event_filter,
                                NULL, NULL);
                }
-               if (subs_opp_server_interface_removed_id == -1) {
+               if (subs_opp_server_interface_removed_id == 0) {
                        subs_opp_server_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_MANAGER_INTERFACE,
                                BT_INTERFACES_REMOVED, NULL, NULL, 0,
                                __bt_obexd_event_filter,
                                NULL, NULL);
                }
-               if (subs_opp_server_property_id == -1) {
+               if (subs_opp_server_property_id == 0) {
                        subs_opp_server_property_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_PROPERTIES_INTERFACE,
                                BT_PROPERTIES_CHANGED, NULL, NULL, 0,
@@ -3508,20 +3490,20 @@ int _bt_register_opp_server_subscribe_signal(GDBusConnection *conn,
                                NULL, NULL);
                }
        } else {
-               if (subs_opp_server_interface_added_id != -1) {
+               if (subs_opp_server_interface_added_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_opp_server_interface_added_id);
-                       subs_opp_server_interface_added_id = -1;
+                       subs_opp_server_interface_added_id = 0;
                }
-               if (subs_opp_server_interface_removed_id != -1) {
+               if (subs_opp_server_interface_removed_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_opp_server_interface_removed_id);
-                       subs_opp_server_interface_removed_id = -1;
+                       subs_opp_server_interface_removed_id = 0;
                }
-               if (subs_opp_server_property_id != -1) {
+               if (subs_opp_server_property_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_opp_server_property_id);
-                       subs_opp_server_property_id = -1;
+                       subs_opp_server_property_id = 0;
                }
        }
        return 0;
@@ -3533,27 +3515,27 @@ int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn,
        if (conn == NULL)
                return -1;
 
-       static int subs_opp_client_interface_added_id = -1;
-       static int subs_opp_client_interface_removed_id = -1;
-       static int subs_opp_client_property_id = -1;
+       static guint subs_opp_client_interface_added_id = 0;
+       static guint subs_opp_client_interface_removed_id = 0;
+       static guint subs_opp_client_property_id = 0;
 
 
        if (subscribe) {
-               if (subs_opp_client_interface_added_id == -1) {
+               if (subs_opp_client_interface_added_id == 0) {
                        subs_opp_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_MANAGER_INTERFACE,
                                BT_INTERFACES_ADDED, NULL, NULL, 0,
                                __bt_opc_event_filter,
                                NULL, NULL);
                }
-               if (subs_opp_client_interface_removed_id == -1) {
+               if (subs_opp_client_interface_removed_id == 0) {
                        subs_opp_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_MANAGER_INTERFACE,
                                BT_INTERFACES_REMOVED, NULL, NULL, 0,
                                __bt_opc_event_filter,
                                NULL, NULL);
                }
-               if (subs_opp_client_property_id == -1) {
+               if (subs_opp_client_property_id == 0) {
                        subs_opp_client_property_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_PROPERTIES_INTERFACE,
                                BT_PROPERTIES_CHANGED, NULL, NULL, 0,
@@ -3561,20 +3543,20 @@ int _bt_register_opp_client_subscribe_signal(GDBusConnection *conn,
                                NULL, NULL);
                }
        } else {
-               if (subs_opp_client_interface_added_id != -1) {
+               if (subs_opp_client_interface_added_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_opp_client_interface_added_id);
-                       subs_opp_client_interface_added_id = -1;
+                       subs_opp_client_interface_added_id = 0;
                }
-               if (subs_opp_client_interface_removed_id != -1) {
+               if (subs_opp_client_interface_removed_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_opp_client_interface_removed_id);
-                       subs_opp_client_interface_removed_id = -1;
+                       subs_opp_client_interface_removed_id = 0;
                }
-               if (subs_opp_client_property_id != -1) {
+               if (subs_opp_client_property_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_opp_client_property_id);
-                       subs_opp_client_property_id = -1;
+                       subs_opp_client_property_id = 0;
                }
        }
        return 0;
@@ -3586,27 +3568,27 @@ int _bt_register_map_client_subscribe_signal(GDBusConnection *conn,
        if (conn == NULL)
                return -1;
 
-       static int subs_map_client_interface_added_id = -1;
-       static int subs_map_client_interface_removed_id = -1;
-       static int subs_map_client_property_id = -1;
+       static guint subs_map_client_interface_added_id = 0;
+       static guint subs_map_client_interface_removed_id = 0;
+       static guint subs_map_client_property_id = 0;
 
 
        if (subscribe) {
-               if (subs_map_client_interface_added_id == -1) {
+               if (subs_map_client_interface_added_id == 0) {
                        subs_map_client_interface_added_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_MANAGER_INTERFACE,
                                BT_INTERFACES_ADDED, NULL, NULL, 0,
                                __bt_map_event_filter,
                                NULL, NULL);
                }
-               if (subs_map_client_interface_removed_id == -1) {
+               if (subs_map_client_interface_removed_id == 0) {
                        subs_map_client_interface_removed_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_MANAGER_INTERFACE,
                                BT_INTERFACES_REMOVED, NULL, NULL, 0,
                                __bt_map_event_filter,
                                NULL, NULL);
                }
-               if (subs_map_client_property_id == -1) {
+               if (subs_map_client_property_id == 0) {
                        subs_map_client_property_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_PROPERTIES_INTERFACE,
                                BT_PROPERTIES_CHANGED, NULL, NULL, 0,
@@ -3614,20 +3596,20 @@ int _bt_register_map_client_subscribe_signal(GDBusConnection *conn,
                                NULL, NULL);
                }
        } else {
-               if (subs_map_client_interface_added_id != -1) {
+               if (subs_map_client_interface_added_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_map_client_interface_added_id);
-                       subs_map_client_interface_added_id = -1;
+                       subs_map_client_interface_added_id = 0;
                }
-               if (subs_map_client_interface_removed_id != -1) {
+               if (subs_map_client_interface_removed_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_map_client_interface_removed_id);
-                       subs_map_client_interface_removed_id = -1;
+                       subs_map_client_interface_removed_id = 0;
                }
-               if (subs_map_client_property_id != -1) {
+               if (subs_map_client_property_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_map_client_property_id);
-                       subs_map_client_property_id = -1;
+                       subs_map_client_property_id = 0;
                }
        }
        return 0;
@@ -3639,18 +3621,18 @@ int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn,
        if (conn == NULL)
                return -1;
 
-       static int subs_a2dp_source_id = -1;
-       static int subs_a2dp_sink_id = -1;
+       static guint subs_a2dp_source_id = 0;
+       static guint subs_a2dp_sink_id = 0;
 
        if (subscribe) {
-               if (subs_a2dp_source_id == -1) {
+               if (subs_a2dp_source_id == 0) {
                        subs_a2dp_source_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_A2DP_SOURCE_INTERFACE,
                                NULL, NULL, NULL, 0,
                                __bt_opc_event_filter,
                                NULL, NULL);
                }
-               if (subs_a2dp_sink_id == -1) {
+               if (subs_a2dp_sink_id == 0) {
                        subs_a2dp_sink_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_SINK_INTERFACE,
                                NULL, NULL, NULL, 0,
@@ -3658,15 +3640,15 @@ int _bt_register_a2dp_subscribe_signal(GDBusConnection *conn,
                                NULL, NULL);
                }
        } else {
-               if (subs_a2dp_source_id != -1) {
+               if (subs_a2dp_source_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_a2dp_source_id);
-                       subs_a2dp_source_id = -1;
+                       subs_a2dp_source_id = 0;
                }
-               if (subs_a2dp_sink_id != -1) {
+               if (subs_a2dp_sink_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_a2dp_sink_id);
-                       subs_a2dp_sink_id = -1;
+                       subs_a2dp_sink_id = 0;
                }
        }
        return 0;
@@ -3677,10 +3659,10 @@ int _bt_register_tds_provider_subscribe_signal(GDBusConnection *conn, int subscr
        if (conn == NULL)
                return -1;
 
-       static int subs_custom_id = -1;
+       static guint subs_custom_id = 0;
 
        if (subscribe) {
-               if (subs_custom_id == -1) {
+               if (subs_custom_id == 0) {
                        subs_custom_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_TDS_PROVIDER_INTERFACE,
                                NULL, NULL, NULL, 0,
@@ -3688,10 +3670,10 @@ int _bt_register_tds_provider_subscribe_signal(GDBusConnection *conn, int subscr
                                NULL, NULL);
                }
        } else {
-               if (subs_custom_id != -1) {
+               if (subs_custom_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_custom_id);
-                       subs_custom_id = -1;
+                       subs_custom_id = 0;
                }
        }
 
@@ -3715,10 +3697,10 @@ int __bt_register_dump_subscribe_signal(GDBusConnection *conn,
        if (conn == NULL)
                return -1;
 
-       static int subs_source_id = -1;
+       static guint subs_source_id = 0;
 
        if (subscribe) {
-               if (subs_source_id == -1) {
+               if (subs_source_id == 0) {
                        subs_source_id = g_dbus_connection_signal_subscribe(conn,
                                NULL, BT_DUMP_SERVICE_INTERFACE,
                                BT_DUMP_SERVICE_SIGNAL, BT_DUMP_SERVICE_PATH, NULL, 0,
@@ -3726,10 +3708,10 @@ int __bt_register_dump_subscribe_signal(GDBusConnection *conn,
                                NULL, NULL);
                }
        } else {
-               if (subs_source_id != -1) {
+               if (subs_source_id > 0) {
                        g_dbus_connection_signal_unsubscribe(conn,
                                        subs_source_id);
-                       subs_source_id = -1;
+                       subs_source_id = 0;
                }
        }
        return 0;
@@ -3875,7 +3857,7 @@ static int __bt_init_obexd_receiver(void)
                GError *error = NULL;
 
                if (obexd_conn == NULL) {
-                       obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
+                       obexd_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
                        if (error != NULL) {
                                BT_ERR("ERROR: Can't get on session bus [%s]", error->message);
                                g_clear_error(&error);