Fix the crash dump in FHUB efl TCT
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-event-receiver.c
index 08e665b..f3d50f3 100644 (file)
 #include "bt-service-pbap.h"
 #include "bt-service-headset-connection.h"
 #include "bt-service-avrcp-controller.h"
+#include "bt-service-hid.h"
+#include "bt-service-proximity.h"
 
 #include "bt-service-opp-client.h"
+#include "bt-service-map-client.h"
+#include "bt-service-tds.h"
+#include "bt-service-otp.h"
 
-#ifdef TIZEN_DPM_ENABLE
+#ifdef TIZEN_FEATURE_BT_DPM
 #include "bt-service-dpm.h"
 #endif
 
 static GDBusConnection *manager_conn;
 static GDBusConnection *obexd_conn;
 static GDBusConnection *opc_obexd_conn;
+static GDBusConnection *map_obexd_conn;
 
 static GList *p_cache_list = NULL;
 
 static guint event_id;
+static guint le_scan_event_id = 0;
+static guint session_reinit_timer;
 guint nap_connected_device_count = 0;
 static guint hid_connected_device_count = 0;
-static GList *p_adv_ind_list;
+static GList *p_adv_ind_list = NULL;
 
 typedef struct {
        bt_remote_dev_info_t *dev_info;
@@ -71,22 +79,32 @@ typedef enum {
        OBEX_PBAP = (1 << 4),
        OBEX_IRMC = (1 << 5),
        OBEX_PCSUITE = (1 << 6),
-       OBEX_SYNCEVOLUTION =    (1 << 7),
+       OBEX_SYNCEVOLUTION = (1 << 7),
        OBEX_MAS = (1 << 8),
+       OBEX_MAP = (1 << 9),
 } bluetooth_obex_connection_type_t;
 
 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path);
 void _bt_opc_property_changed_event(GVariant *msg, char *path);
+void _bt_map_property_changed_event(GVariant *msg, const char *path);
 int _bt_register_service_event(GDBusConnection *g_conn, int event_type);
 void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type);
 void _bt_opp_client_event_deinit(void);
+void _bt_map_client_event_deinit(void);
 void _bt_handle_network_client_event(GVariant *msg_iter,
                                const char *path);
 void __bt_gatt_char_property_changed_event(GVariant *msg_iter,
                                const char *path);
+void _bt_map_on_transfer_finished(const char *transfer_object_path, const int error);
 
-static void __bt_free_bt_le_adv_info_t(bt_le_adv_info_t *adv_info)
+static void __bt_free_bt_le_adv_info_t(gpointer data)
 {
+       bt_le_adv_info_t *adv_info = data;
+
+       if (adv_info->timer_id)
+               g_source_remove(adv_info->timer_id);
+       adv_info->timer_id = 0;
+
        g_free(adv_info->addr);
        g_free(adv_info->data);
        g_free(adv_info);
@@ -99,21 +117,23 @@ static bt_le_adv_info_t *__bt_get_adv_ind_info(char *addr)
        GList *current = g_list_first((GList *)p_adv_ind_list);
        while (current && current->data) {
                adv_info = (bt_le_adv_info_t *)current->data;
-               retv_if(adv_info && !g_strcmp0(adv_info->addr, addr), adv_info);
+               if (adv_info && !g_strcmp0(adv_info->addr, addr))
+                       return adv_info;
                current = g_list_next(current);
        }
        return NULL;
 }
 
-static void __bt_add_adv_ind_info(bt_le_adv_info_t *adv_info)
+static int __bt_add_adv_ind_info(bt_le_adv_info_t *adv_info)
 {
-       ret_if(!adv_info);
+       retv_if(!adv_info, -1);
        if (__bt_get_adv_ind_info(adv_info->addr) != NULL) {
-               BT_ERR("adv_info is already added");
                __bt_free_bt_le_adv_info_t(adv_info);
-               return;
+               return -1;
        }
        p_adv_ind_list = g_list_append(p_adv_ind_list, adv_info);
+
+       return 0;
 }
 
 static void __bt_del_adv_ind_info(char *addr)
@@ -133,6 +153,26 @@ static void __bt_del_adv_ind_info(char *addr)
        }
 }
 
+static gboolean __bt_adv_scan_req_timeout_cb(gpointer user_data)
+{
+       bt_remote_le_dev_info_t le_dev_info;
+       bt_le_adv_info_t *adv_info = (bt_le_adv_info_t*)user_data;
+
+       memset(&le_dev_info, 0x00, sizeof(bt_remote_le_dev_info_t));
+
+       le_dev_info.address = adv_info->addr;
+       le_dev_info.addr_type = adv_info->addr_type;
+       le_dev_info.rssi = adv_info->rssi;
+       le_dev_info.adv_data = adv_info->data;
+       le_dev_info.adv_data_len = 0;
+       adv_info->timer_id = 0;
+
+       _bt_send_scan_result_event(&le_dev_info, adv_info);
+       __bt_del_adv_ind_info(adv_info->addr);
+
+       return FALSE;
+}
+
 static void __bt_free_cache_info(bt_cache_info_t *cache_info)
 {
        ret_if(cache_info == NULL);
@@ -160,7 +200,7 @@ static gboolean __bt_parse_device_properties(GVariant *item,
                        if (dev_info->name == NULL)
                                dev_info->name = g_variant_dup_string(val, &len);
                } else if (strcasecmp(key, "Connected") == 0) {
-                       dev_info->connected = g_variant_get_uint32(val);
+                       dev_info->connected = g_variant_get_byte(val);
                } else if (strcasecmp(key, "paired") == 0) {
                        dev_info->paired = g_variant_get_boolean(val);
                } else if (strcasecmp(key, "Trusted") == 0) {
@@ -187,7 +227,7 @@ static gboolean __bt_parse_device_properties(GVariant *item,
                                g_free(uuid_value);
                        }
                } else if (strcasecmp(key, "ManufacturerDataLen") == 0) {
-                       g_variant_get(val, "(i)", &dev_info->manufacturer_data_len);
+                       g_variant_get(val, "q", &dev_info->manufacturer_data_len);
                        if (dev_info->manufacturer_data_len > BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
                                BT_ERR("manufacturer_data_len is too long(len = %d)", dev_info->manufacturer_data_len);
                                dev_info->manufacturer_data_len = BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX;
@@ -196,18 +236,21 @@ static gboolean __bt_parse_device_properties(GVariant *item,
                        if (dev_info->manufacturer_data_len == 0)
                                dev_info->manufacturer_data = g_strdup("");
                } else if (strcasecmp(key, "ManufacturerData") == 0) {
+                       int i = 0;
                        int len = 0;
-                       GVariant *manufacturer_var;
-                       g_variant_get(val, "@ay", &manufacturer_var);
-                       len = g_variant_get_size(manufacturer_var);
-                       if (len > 0) {
-                               char *manufacturer_data = (char *)g_variant_get_data(manufacturer_var);
-                               dev_info->manufacturer_data = g_malloc0(len);
-                               if (dev_info->manufacturer_data)
-                                       memcpy(dev_info->manufacturer_data, manufacturer_data,
-                                               len);
-                       }
-                       g_variant_unref(manufacturer_var);
+                       GVariantIter *value_iter;
+                       guint8 m_value;
+
+                       len = g_variant_get_size(val);
+                       if (len <= 0)
+                               continue;
+
+                       dev_info->manufacturer_data = g_malloc0(len);
+
+                       g_variant_get(val, "ay", &value_iter);
+                       while (g_variant_iter_loop(value_iter, "y", &m_value))
+                               dev_info->manufacturer_data[i++] = m_value;
+                       g_variant_iter_free(value_iter);
                }
        }
 
@@ -219,7 +262,7 @@ static gboolean __bt_parse_interface(GVariant *msg,
                                        bt_remote_dev_info_t *dev_info)
 {
        char *path = NULL;
-       GVariant *optional_param;
+       GVariant *optional_param = NULL;
        GVariantIter iter;
        GVariant *child;
        char *interface_name = NULL;
@@ -228,6 +271,8 @@ static gboolean __bt_parse_interface(GVariant *msg,
                                        &path, &optional_param);
        g_variant_iter_init(&iter, optional_param);
 
+       retv_if(optional_param == NULL, FALSE);
+
        while ((child = g_variant_iter_next_value(&iter))) {
                g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter);
                if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
@@ -247,7 +292,7 @@ static gboolean __bt_parse_interface(GVariant *msg,
                        }
                }
                g_variant_unref(inner_iter);
-       g_variant_unref(child);
+               g_variant_unref(child);
        }
 
        g_variant_unref(optional_param);
@@ -273,18 +318,16 @@ void __bt_set_device_values(gboolean connected, int state)
 {
        int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
 
-       if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0) {
+       if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
                BT_ERR("vconf_get_int failed");
-       }
 
        if (connected == TRUE)
                bt_device_state |= state;
        else if (bt_device_state & state)
                bt_device_state ^= state;
 
-       if (vconf_set_int(VCONFKEY_BT_DEVICE, bt_device_state) != 0) {
+       if (vconf_set_int(VCONFKEY_BT_DEVICE, bt_device_state) != 0)
                BT_ERR("vconf_set_int failed");
-       }
 }
 
 gboolean _bt_discovery_finished_cb(gpointer user_data)
@@ -293,9 +336,8 @@ gboolean _bt_discovery_finished_cb(gpointer user_data)
        event_id = 0;
        GVariant *param = NULL;
        if (_bt_get_discovering_property(DISCOVERY_ROLE_BREDR) == FALSE) {
-               if (_bt_get_cancel_by_user() == TRUE) {
+               if (_bt_get_cancel_by_user() == TRUE)
                        result = BLUETOOTH_ERROR_CANCEL_BY_USER;
-               }
 
                _bt_set_cancel_by_user(FALSE);
                _bt_set_discovery_status(FALSE);
@@ -311,15 +353,17 @@ gboolean _bt_discovery_finished_cb(gpointer user_data)
 static gboolean __bt_le_discovery_finished_cb(gpointer user_data)
 {
        int result = BLUETOOTH_ERROR_NONE;
-       event_id = 0;
+       le_scan_event_id = 0;
        GVariant *param = NULL;
        if (_bt_get_discovering_property(DISCOVERY_ROLE_LE) == FALSE) {
-               if (_bt_get_cancel_by_user() == TRUE) {
+               if (_bt_get_cancel_by_user() == TRUE)
                        result = BLUETOOTH_ERROR_CANCEL_BY_USER;
-               }
+
+               g_list_free_full(p_adv_ind_list, __bt_free_bt_le_adv_info_t);
+               p_adv_ind_list = NULL;
 
                _bt_set_cancel_by_user(FALSE);
-                _bt_disable_all_scanner_status();
+               _bt_disable_all_scanner_status();
                _bt_set_le_scan_status(FALSE);
                param = g_variant_new("(i)", result);
                _bt_send_event(BT_LE_ADAPTER_EVENT,
@@ -365,34 +409,20 @@ 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)
+gboolean __bt_handle_is_flight_mode_enabled(void)
 {
-       int result = BLUETOOTH_ERROR_NONE;
-       int i;
-       GVariant *param = NULL;
-       BT_DBG("+");
+       int is_flight_mode = 0;
+       int ret = -1;
 
-       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;
+       if (TIZEN_FEATURE_FLIGHTMODE_ENABLED) {
+               ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &is_flight_mode);
+               if (ret != 0)
+                       BT_ERR("vconf_get_bool failed");
 
-                               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;
-                       }
-               }
+               return (is_flight_mode == 0) ? FALSE : TRUE;
+       } else {
+               return FALSE;
        }
-
-       BT_DBG("-");
 }
 
 void _bt_handle_adapter_event(GVariant *msg, const char *member)
@@ -416,7 +446,7 @@ void _bt_handle_adapter_event(GVariant *msg, const char *member)
                g_variant_get(msg, "(&o)", &object_path);
                _bt_convert_device_path_to_address((const char*)object_path, address);
 
-               remote_dev_info = _bt_get_remote_device_info(address);
+               remote_dev_info = _bt_get_remote_device_info_by_object_path(object_path);
                if (remote_dev_info == NULL) {
                        g_free(address);
                        return;
@@ -433,11 +463,8 @@ void _bt_handle_adapter_event(GVariant *msg, const char *member)
 
                /* Bonding from remote device */
                address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-               g_variant_get(msg, "(&o)", &object_path);
 
-               /* Fix : NULL_RETURNS */
-               if (address == NULL)
-                       return;
+               g_variant_get(msg, "(&o)", &object_path);
 
                _bt_convert_device_path_to_address((const char *)object_path, address);
 
@@ -485,18 +512,21 @@ void _bt_handle_adapter_event(GVariant *msg, const char *member)
                param = g_variant_new("(ii)", result,
                                        adv_handle);
 
-#if 0
                const char *sender;
                sender = _bt_get_adv_slot_owner(slot_id);
                _bt_send_event_to_dest(sender, BT_ADAPTER_EVENT,
                                event,
                                param);
-#else
-               _bt_send_event(BT_ADAPTER_EVENT, event, param);
-#endif
 
-               if (event == BLUETOOTH_EVENT_ADVERTISING_STOPPED)
+               if (event == BLUETOOTH_EVENT_ADVERTISING_STOPPED) {
+                       char *name = g_strdup(sender);
+
                        _bt_unregister_adv_slot_owner(slot_id);
+
+                       /* Advertising disabled, notify TDS */
+                       _bt_tds_handle_adv_disabled(name, adv_handle);
+                       g_free(name);
+               }
        } else if (strcasecmp(member, "RssiEnabled") == 0) {
                BT_DBG("RSSI Enabled");
                gboolean status = FALSE;
@@ -543,11 +573,17 @@ void _bt_handle_adapter_event(GVariant *msg, const char *member)
                                param);
                g_free(address);
        } else if (strcasecmp(member, BT_HARDWARE_ERROR) == 0) {
-               BT_ERR_C("Hardware error received from BLUEZ");
+               BT_ERR_C("### Hardware error received from BLUEZ");
+/* Don't add the recovery logic into platform */
+#if 0
                _bt_recover_adapter();
+#endif
        } else if (strcasecmp(member, BT_TX_TIMEOUT_ERROR) == 0) {
-               BT_ERR_C("Tx timeout error received from BLUEZ");
+               BT_ERR_C("### Tx timeout error received from BLUEZ");
+/* Don't add the recovery logic into platform */
+#if 0
                _bt_recover_adapter();
+#endif
        }
        BT_DBG("-");
 }
@@ -559,18 +595,25 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
        int result = BLUETOOTH_ERROR_NONE;
        GVariantIter value_iter;
        GVariant *val = NULL;
+       GVariant *ret = NULL;
        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);
@@ -578,13 +621,15 @@ 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 */
-                               g_dbus_proxy_call_sync(adapter_proxy, "StopDiscovery",
+                               ret = g_dbus_proxy_call_sync(adapter_proxy, "StopDiscovery",
                                        NULL,
                                        G_DBUS_CALL_FLAGS_NONE,
                                        DBUS_TIMEOUT, NULL,
@@ -593,6 +638,8 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
                                        BT_ERR("Dbus Error : %s", err->message);
                                        g_clear_error(&err);
                                }
+                               if (ret)
+                                       g_variant_unref(ret);
 
                                event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
                                  (GSourceFunc)_bt_discovery_finished_cb, NULL);
@@ -600,52 +647,60 @@ 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(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 */
-                               g_dbus_proxy_call_sync(adapter_proxy, "StopLEDiscovery",
-                                       NULL,
-                                       G_DBUS_CALL_FLAGS_NONE,
-                                       DBUS_TIMEOUT, NULL,
-                                       &err);
+                               ret = g_dbus_proxy_call_sync(adapter_proxy, "StopLEDiscovery",
+                                               NULL,
+                                               G_DBUS_CALL_FLAGS_NONE,
+                                               DBUS_TIMEOUT, NULL,
+                                               &err);
                                if (err) {
                                        BT_ERR("Dbus Error %s", err->message);
                                        g_clear_error(&err);
                                }
+                               if (ret)
+                                       g_variant_unref(ret);
 
-                               event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
+                               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;
 
@@ -654,27 +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);
-                                       g_dbus_proxy_call_sync(adapter_proxy, "Set",
-                                       g_variant_new("(ssv)", BT_ADAPTER_INTERFACE,
-                                               "DiscoverableTimeout",
-                                               g_variant_new("i", time)),
-                                       G_DBUS_CALL_FLAGS_NONE,
-                                       DBUS_TIMEOUT, NULL,
-                                       &err);
+                                       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("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,
@@ -683,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]");
@@ -701,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;
@@ -722,22 +777,24 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
                        g_variant_get(val, "b", &powered);
                        BT_DBG("Powered = %d", powered);
                        if (powered == FALSE) {
-#ifdef USB_BLUETOOTH
-                               _bt_handle_adapter_removed();
-#else
-                               if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_state) == 0 &&
-                               bt_state != VCONFKEY_BT_STATUS_OFF) {
-                                       _bt_disable_adapter();
+                               if (TIZEN_FEATURE_BT_USB_DONGLE) {
+                                       _bt_handle_adapter_removed();
+                               } else {
+                                       if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_state) == 0 &&
+                                       bt_state != VCONFKEY_BT_STATUS_OFF) {
+                                               if (__bt_handle_is_flight_mode_enabled() == FALSE)
+                                                       _bt_disable_adapter();
+                                               else
+                                                       _bt_handle_adapter_removed();
+                                       }
                                }
-#endif
                                if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_state) == 0 &&
                                        bt_state != VCONFKEY_BT_LE_STATUS_OFF) {
                                        _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
                                }
                        } else {
-#ifdef USB_BLUETOOTH
-                               _bt_handle_adapter_added();
-#endif
+                               if (TIZEN_FEATURE_BT_USB_DONGLE)
+                                       _bt_handle_adapter_added();
                        }
                } else if (strcasecmp(property, "Connectable") == 0) {
                        gboolean connectable = FALSE;
@@ -759,17 +816,18 @@ 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);
-                       if (iter) {
-                               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");
-                               }
-                               g_variant_iter_free(iter);
+                       if (iter == NULL)
+                               continue;
+
+                       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;
 
@@ -781,6 +839,8 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
                        _bt_send_event(BT_ADAPTER_EVENT,
                                        BLUETOOTH_EVENT_IPSP_INIT_STATE_CHANGED,
                                        param);
+               } else {
+                       BT_DBG("Unhandled property : [%s]", property);
                }
        }
 }
@@ -815,11 +875,16 @@ static void __bt_obex_property_changed_event(GVariant *msg, const char *path)
                        }
                        g_free(status);
                } else if (strcasecmp(property, "Transferred") == 0) {
-                       static int transferred  = 0;
+                       guint64 transferred  = 0;
+                       /* As Transferred is expected guint64 so change int to guint64 and
+                        * eariler transferred is static because of it can overwrite data
+                        * on present on opc_obex_conn or obexd_conn as these are
+                        * static memory are in sequential */
                        g_variant_get(val, "t", &transferred);
 
                        _bt_obex_transfer_progress(path, transferred);
                }
+               /* TODO: MAP, "Complete"? see above */
                g_free(property);
                g_variant_unref(val);
                g_variant_unref(child);
@@ -838,8 +903,10 @@ 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;
+#endif
        while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
                BT_DBG("Property %s", property);
                if (strcasecmp(property, "Connected") == 0) {
@@ -858,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(address);
-
-                       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,
@@ -881,11 +939,12 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path)
                        _bt_convert_device_path_to_address(path, address);
                        BT_DBG("address: %s", address);
 
-                       remote_dev_info = _bt_get_remote_device_info(address);
+                       g_free(address);
+
+                       remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
                        if (remote_dev_info == NULL) {
                                g_free(property);
                                g_variant_unref(val);
-                               g_free(address);
                                return;
                        }
                        BT_DBG("Address type  %d", remote_dev_info->addr_type);
@@ -893,9 +952,9 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path)
                        if (remote_dev_info->addr_type == 0) {
                                BT_DBG("Name %s", remote_dev_info->name);
 
-#ifdef TIZEN_DPM_ENABLE
-                               if (_bt_dpm_get_bluetooth_desktop_connectivity_state() ==
-                                                       DPM_RESTRICTED) {
+#ifdef TIZEN_FEATURE_BT_DPM
+                               _bt_dpm_get_bluetooth_desktop_connectivity_state(&desktop_state);
+                               if (desktop_state == DPM_RESTRICTED) {
                                        bluetooth_device_class_t device_class;
                                        _bt_divide_device_class(&device_class, remote_dev_info->class);
 
@@ -904,7 +963,6 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path)
                                                _bt_free_device_info(remote_dev_info);
                                                g_free(property);
                                                g_variant_unref(val);
-                                               g_free(address);
                                                return;
                                        }
                                }
@@ -941,7 +999,6 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path)
                                _bt_send_event(BT_ADAPTER_EVENT,
                                        BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
                                        param);
-                               g_free(address);
                        }
                        _bt_free_device_info(remote_dev_info);
                } else if (strcasecmp(property, "GattConnected") == 0) {
@@ -983,7 +1040,7 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path)
 
                        _bt_convert_device_path_to_address(path, address);
 
-                       remote_dev_info = _bt_get_remote_device_info(address);
+                       remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
                        if (remote_dev_info == NULL) {
                                g_free(property);
                                g_variant_unref(val);
@@ -998,8 +1055,21 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path)
                                _bt_send_event(BT_ADAPTER_EVENT,
                                        BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
                                        param);
+#ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
+                               {
+                                       char *last_connected = NULL;
+                                       last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
+                                       if (!g_strcmp0(address, last_connected))
+                                               _bt_audio_set_auto_connect_device_addr("");
+                                       if (last_connected)
+                                               free(last_connected);
+                               }
+#endif
                        } else {
-                               BT_INFO("Paired: %s", address);
+                               char secure_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
+
+                               _bt_convert_addr_string_to_secure_string(secure_addr, address);
+                               BT_INFO("### Paired: %s", secure_addr);
                                __bt_update_remote_cache_devinfo(address, TRUE);
 
                                if (_bt_is_device_creating() == TRUE) {
@@ -1046,6 +1116,7 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path)
                } else if (strcasecmp(property, "LegacyPaired") == 0) {
                        gboolean paired = FALSE;
                        bt_remote_dev_info_t *remote_dev_info;
+                       unsigned char auth_info[5] = {0, };
 
                        if (_bt_adapter_get_status() != BT_ACTIVATED) {
                                BT_DBG("BT is not activated, so ignore this");
@@ -1059,18 +1130,31 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path)
                        BT_DBG("LegacyPaired: %d", paired);
                        _bt_convert_device_path_to_address(path, address);
 
-                       remote_dev_info = _bt_get_remote_device_info(address);
+                       remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
                        if (remote_dev_info == NULL) {
                                g_free(address);
                                g_free(property);
                                g_variant_unref(val);
                                return;
                        }
+                       if (remote_dev_info->is_alias_set == FALSE) {
+                               /*minimum Size of the samsung specific manufacturer data is greater than 30 */
+                               if ((remote_dev_info->manufacturer_data_len > 30) &&
+                                       (remote_dev_info->manufacturer_data[0] == 0x00) &&
+                                       (remote_dev_info->manufacturer_data[1] == 0x75)) {
+
+                                       /* 2  samsung (0x00 0x75) + 1 (control and version) + 1 (service ID) +
+                                       1 (discovery version) + 1 (associated service ID)
+                                       2 (Proxamity and locality) + 2 (Device type and icon) = 10 */
+
+                                       memcpy(auth_info, &(remote_dev_info->manufacturer_data[10]), 5);
+                               }
+                       }
 
-                       BT_DBG("LegacyPairing Failed with %s. Show Error Popup",
-                                       remote_dev_info->name);
-                       _bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE,
-                                               remote_dev_info->name, NULL, NULL, NULL);
+                       BT_DBG("LegacyPairing Failed with %s. Show Error Popup", remote_dev_info->name);
+                       if (headed_plugin_info->plugin_headed_enabled)
+                               headed_plugin_info->headed_plugin->bt_launch_system_popup(BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE,
+                                               remote_dev_info->name, auth_info, NULL, NULL, NULL);
 
                        _bt_free_device_info(remote_dev_info);
                        g_free(address);
@@ -1094,6 +1178,19 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path)
                                        event,
                                        param);
                        g_free(address);
+               } else if (strcasecmp(property, "TrustedProfiles") == 0) {
+                       int trusted = 0;
+
+                       g_variant_get(val, "u", &trusted);
+
+                       address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+                       _bt_convert_device_path_to_address(path, address);
+
+                       BT_DBG("Address: %s, TrustedProfiles: %d", address, trusted);
+                       _bt_send_event(BT_DEVICE_EVENT,
+                                       BLUETOOTH_EVENT_SUPPORTED_PROFILE_TRUSTED,
+                                       g_variant_new("(isi)", result, address, trusted));
+                       g_free(address);
                } else if (strcasecmp(property, "IpspConnected") == 0) {
                        gboolean connected = FALSE;
 
@@ -1101,7 +1198,7 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path)
 
 
                        event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
-                                       BLUETOOTH_EVENT_IPSP_DISCONNECTED;
+                                                       BLUETOOTH_EVENT_IPSP_DISCONNECTED;
 
                        address = g_malloc0(BT_ADDRESS_STRING_SIZE);
 
@@ -1131,7 +1228,7 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path)
 
                        /* Send event to application */
                        _bt_send_event(BT_DEVICE_EVENT,
-                                       BLUETOOTH_EVENT_IPSP_BT_INTERFACE_INFO,
+                                       BLUETOOTH_EVENT_IPSP_INTERFACE_INFO,
                                        param);
                        g_free(address);
                }
@@ -1148,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))) {
@@ -1169,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,
@@ -1190,6 +1279,71 @@ static void __bt_media_control_changed_event(GVariant *msg, const char *path)
        BT_DBG("-");
 }
 
+int get_alert_level_enum(const char *alert)
+{
+       int lvl = -1;
+
+       if (strcmp(alert, "none") == 0)
+               lvl = BT_PXP_ALERT_NONE;
+       else if (strcmp(alert, "mild") == 0)
+               lvl = BT_PXP_ALERT_MILD;
+       else if (strcmp(alert, "high") == 0)
+               lvl = BT_PXP_ALERT_HIGH;
+
+       return lvl;
+}
+
+static void _bt_handle_pxp_property_changed_event(GVariant *msg, const char *path, int role)
+{
+       int result = BLUETOOTH_ERROR_NONE;
+       int service_type;
+       int alert_lvl = -1;
+       GVariantIter value_iter;
+       char *property = NULL;
+       char *address;
+       GVariant *val = NULL;
+       GVariant *child = NULL;
+       GVariant *param = NULL;
+       g_variant_iter_init(&value_iter, msg);
+
+       BT_DBG("+");
+       while ((child = g_variant_iter_next_value(&value_iter))) {
+               g_variant_get(child, "{sv}", &property, &val);
+               BT_INFO("Property %s", property);
+
+               if ((strcasecmp(property, "LinkLossAlertLevel") == 0) ||
+                       (strcasecmp(property, "ImmediateAlertLevel") == 0)) {
+                       char *alert_str = NULL;
+
+                       address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+                       _bt_convert_device_path_to_address(path, address);
+
+                       if (strcasecmp(property, "LinkLossAlertLevel") == 0)
+                               service_type = BT_PXP_PROPERTY_LLS;
+                       else
+                               service_type = BT_PXP_PROPERTY_IAS;
+
+                       g_variant_get(val, "s", &alert_str);
+                       if (alert_str)
+                               alert_lvl = get_alert_level_enum(alert_str);
+
+                       param = g_variant_new("(isiii)", result, address,
+                                                               role, service_type, alert_lvl);
+
+                       /* Send event to application */
+                       _bt_send_event(BT_DEVICE_EVENT,
+                                       BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED,
+                                       param);
+                       g_free(address);
+                       g_free(alert_str);
+               }
+               g_free(property);
+               g_variant_unref(child);
+               g_variant_unref(val);
+       }
+       BT_DBG("-");
+}
+
 void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
 {
        char *interface_name = NULL;
@@ -1219,6 +1373,10 @@ void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
        } else if (strcasecmp(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
                __bt_gatt_char_property_changed_event(val,
                                        object_path);
+       } else if (strcasecmp(interface_name, BT_PROXIMITY_REPORTER_INTERFACE) == 0) {
+               BT_DBG("BT_PROXIMITY_REPORTER_INTERFACE");
+               _bt_handle_pxp_property_changed_event(val,
+                                       object_path, BT_PXP_REPORTER_ROLE);
        }
        g_variant_unref(val);
 }
@@ -1232,7 +1390,7 @@ void __bt_opc_property_changed_event(GVariant *msg,
        GVariant *child = NULL;
 
        g_variant_iter_init(&value_iter, msg);
-       while ((child = g_variant_iter_next_value(&value_iter))) {
+       if ((child = g_variant_iter_next_value(&value_iter))) {
                g_variant_get(child, "{sv}", &property, &val);
                ret_if(property == NULL);
 
@@ -1241,16 +1399,16 @@ void __bt_opc_property_changed_event(GVariant *msg,
                        g_variant_get(val, "s", &status);
                        BT_DBG("Status is %s", status);
 
-                       if (strcasecmp(status, "active") == 0) {
+                       if (strcasecmp(status, "active") == 0)
                                _bt_obex_client_started(path);
-                       } else if (strcasecmp(status, "complete") == 0) {
+                       else if (strcasecmp(status, "complete") == 0)
                                _bt_obex_client_completed(path, TRUE);
-                       } else if (strcasecmp(status, "error") == 0) {
+                       else if (strcasecmp(status, "error") == 0)
                                _bt_obex_client_completed(path, FALSE);
-                       }
+
                        g_free(status);
                } else if (strcasecmp(property, "Transferred") == 0) {
-                       static int transferred  = 0;
+                       guint64 transferred  = 0;
                        g_variant_get(val, "t", &transferred);
 
                        _bt_obex_client_progress(path, transferred);
@@ -1279,6 +1437,68 @@ void _bt_opc_property_changed_event(GVariant *msg, char *path)
 }
 
 
+void __bt_map_property_changed_event(GVariant *msg,
+                                               const char *path)
+{
+       BT_DBG("Entered");
+       GVariantIter value_iter;
+       char *property = NULL;
+       GVariant *val = NULL;
+       GVariant *child = NULL;
+
+       g_variant_iter_init(&value_iter, msg);
+       while ((child = g_variant_iter_next_value(&value_iter))) {
+               g_variant_get(child, "{sv}", &property, &val);
+               ret_if(property == NULL);
+
+               if (strcasecmp(property, "Status") == 0) {
+                       char *status = NULL;
+                       g_variant_get(val, "s", &status);
+                       BT_DBG("Status is %s", status);
+
+                       if (strcasecmp(status, "active") == 0) {
+                               BT_DBG("EVENT : STARTED");
+                               // currently doing nothing
+                       } else if (strcasecmp(status, "complete") == 0) {
+                               BT_DBG("EVENT : COMPLETED");
+                               _bt_map_on_transfer_finished(path, BLUETOOTH_ERROR_NONE);
+                       } else if (strcasecmp(status, "error") == 0) {
+                               BT_DBG("EVENT : FAILED");
+                               _bt_map_on_transfer_finished(path, BLUETOOTH_ERROR_INTERNAL);
+                       }
+                       g_free(status);
+               } else if (strcasecmp(property, "Transferred") == 0) {
+                       guint64 transferred  = 0;
+                       g_variant_get(val, "t", &transferred);
+
+                       BT_DBG("EVENT : PROGRESS CALLBACK");
+                       // currently doing nothing - progress callback type is not used
+               } else {
+                       BT_DBG("OTHER EVENT : property : [%s]", property);
+               }
+               g_free(property);
+               g_variant_unref(child);
+               g_variant_unref(val);
+       }
+}
+
+void _bt_map_property_changed_event(GVariant *msg, const char *path)
+{
+       BT_DBG("Entered _bt_map_property_changed_event");
+       char *interface_name = NULL;
+       GVariant *value = NULL;
+       g_variant_get(msg, "(&s@a{sv}@as)", &interface_name, &value, NULL);
+       BT_INFO("interface_name = %s", interface_name);
+       if (strcasecmp(interface_name, BT_OBEX_TRANSFER_INTERFACE) == 0) {
+               __bt_map_property_changed_event(value,
+                               path);
+       } else {
+               BT_DBG("interface_name : [%s]", interface_name);
+       }
+       g_variant_unref(value);
+}
+
+
 void _bt_handle_input_event(GVariant *msg, const char *path)
 {
        int result = BLUETOOTH_ERROR_NONE;
@@ -1310,7 +1530,7 @@ void _bt_handle_input_event(GVariant *msg, const char *path)
                        _bt_send_event(BT_HID_EVENT, event,
                                param);
                        /* Check HID connection type (Keyboard or Mouse) and update the status */
-                       remote_dev_info = _bt_get_remote_device_info(address);
+                       remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
 
                        if (property_flag == TRUE) {
                                hid_connected_device_count++;
@@ -1327,19 +1547,15 @@ void _bt_handle_input_event(GVariant *msg, const char *path)
                                BT_DBG("HID device class [%x]", remote_dev_info->class);
                                if (remote_dev_info->class &
                                        BLUETOOTH_DEVICE_MINOR_CLASS_KEY_BOARD) {
-#ifdef ENABLE_TIZEN_2_4
                                        __bt_set_device_values(property_flag,
                                                VCONFKEY_BT_DEVICE_HID_KEYBOARD_CONNECTED);
-#endif
 
                                }
 
                                if (remote_dev_info->class &
                                                BLUETOOTH_DEVICE_MINOR_CLASS_POINTING_DEVICE) {
-#ifdef ENABLE_TIZEN_2_4
                                        __bt_set_device_values(property_flag,
                                                        VCONFKEY_BT_DEVICE_HID_MOUSE_CONNECTED);
-#endif
                                }
                                _bt_free_device_info(remote_dev_info);
                        }
@@ -1433,99 +1649,44 @@ void __bt_gatt_char_property_changed_event(GVariant *msg,
 {
        GVariantIter value_iter;
        char *property = NULL;
-       char * char_handle = NULL;
        GVariant *val = NULL;
-       int result = BLUETOOTH_ERROR_NONE;
-       GVariant *param = NULL;
        g_variant_iter_init(&value_iter, msg);
-       char_handle = g_strdup(path);
        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");
-               } else if (strcasecmp(property, "ChangedValue") == 0) {
-                       int len = 0;
-                       GByteArray *gp_byte_array = NULL;
-                       BT_INFO("Type '%s'\n", g_variant_get_type_string(val));
-
-                       if (val) {
-                               gp_byte_array = g_byte_array_new();
-                               len = g_variant_get_size(val);
-                               BT_DBG("Len = %d", len);
-                               g_byte_array_append(gp_byte_array,
-                                       (const guint8 *) g_variant_get_data(val), len);
-                               if (gp_byte_array->len != 0) {
-                                       GVariant *byte_array = NULL;
-                                       byte_array = g_variant_new_from_data(
-                                                               G_VARIANT_TYPE_BYTESTRING,
-                                                               gp_byte_array->data,
-                                                               gp_byte_array->len,
-                                                               TRUE, NULL, NULL);
-                                       param = g_variant_new("(is@ay)", result, char_handle,
-                                                               byte_array);
-
-                                       /* Send event only registered client */
-                                       _bt_send_char_value_changed_event(param);
-                               }
-                               g_byte_array_free(gp_byte_array, TRUE);
-                       }
+                       BT_INFO("Notifying is %s", property_flag ? "enabled" : "disabled");
                }
        }
-       g_free(char_handle);
 }
 
 void _bt_handle_gatt_event(GVariant *msg, const char *member, const char *path)
 {
        ret_if(path == NULL);
-
        if (strcasecmp(member, "GattValueChanged") == 0) {
-
-#if 0 // Debug Only
-               /*** Debug only ***/
-               GVariant *value = NULL;
-               int value_len = 0;
-               char *buffer = NULL;
-
-               g_variant_get(msg, "(is@ay)", NULL, NULL, &value);
-               value_len = g_variant_get_size(value);
-               if (value_len > 0) {
-                       char buf[8 * 5 + 1] = { 0 };
-                       int i;
-                       int to;
-                       buffer = (char *)g_variant_get_data(value);
-                       to = value_len > (sizeof(buf) / 5) ? sizeof(buf) / 5 : value_len;
-
-                       for (i = 0; i < to; i++)
-                               snprintf(&buf[i * 5], 6, "0x%02x ", buffer[i]);
-                       buf[i * 5] = '\0';
-                       BT_DBG("GATT Val[%d] %s", value_len, buf);
-               }
-               g_variant_unref(value);
-               /******/
+               /* Check TDS seekers waiting for Indication  */
+               _bt_tds_check_indication(path, msg);
+#ifdef TIZEN_FEATURE_BT_OTP
+               _bt_otp_check_indication(path, msg);
 #endif
-
-               /* Send event only registered client */
-               _bt_send_char_value_changed_event(msg);
+       } else {
+               BT_INFO("Unhandled event");
        }
 }
 
-
 void _bt_handle_device_event(GVariant *msg, const char *member, const char *path)
 {
        int event = 0;
        int result = BLUETOOTH_ERROR_NONE;
        char *address;
-       char *dev_name;
+       char *dev_name = NULL;
        const char *property = NULL;
        GVariant *param = NULL;
+       char secure_address[BT_ADDRESS_STRING_SIZE] = { 0 };
        ret_if(path == NULL);
 
        if (strcasecmp(member, "PropertyChanged") == 0) {
@@ -1538,7 +1699,6 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                        gboolean connected = FALSE;
                        char *address;
                        address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-                       ret_if(address == NULL);
 
                        _bt_convert_device_path_to_address(path, address);
                        g_variant_get(msg, "(b)", &connected);
@@ -1571,11 +1731,10 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                        }
 
                        address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-                       ret_if(address == NULL);
 
                        _bt_convert_device_path_to_address(path, address);
 
-                       remote_dev_info = _bt_get_remote_device_info(address);
+                       remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
                        if (remote_dev_info == NULL) {
                                g_free(address);
                                return;
@@ -1622,11 +1781,10 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                        ret_if(_bt_is_device_creating() == TRUE);
 
                        address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-                       ret_if(address == NULL);
 
                        _bt_convert_device_path_to_address(path, address);
 
-                       remote_dev_info = _bt_get_remote_device_info(address);
+                       remote_dev_info = _bt_get_remote_device_info_by_object_path(path);
                        if (remote_dev_info == NULL) {
                                g_free(address);
                                return;
@@ -1672,20 +1830,20 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                g_variant_get(msg, "(y)", &addr_type);
 
                address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-               ret_if(address == NULL);
 
                _bt_convert_device_path_to_address(path, address);
-               dev_name = _bt_get_bonded_device_name(address);
+               dev_name = _bt_get_device_name(address);
 
-               BT_INFO("Address : %s Type : %d", address, addr_type);
-               BT_ERR_C("Connected [%s] [%s]", !addr_type ? "BREDR" : "LE",
-                               !addr_type ? dev_name : address);
+               _bt_convert_addr_string_to_secure_string(secure_address, address);
+               BT_INFO("Address : %s Type : %d", secure_address, addr_type);
+               BT_ERR_C("### Connected [%s] [%s]", !addr_type ? "BREDR" : "LE",
+                               !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);
-#ifdef ENABLE_TIZEN_2_4
-               journal_bt_connected();
-#endif
                param = g_variant_new("(isy)", result, address, addr_type);
                /*Send event to application*/
                _bt_send_event(BT_DEVICE_EVENT,
@@ -1695,78 +1853,114 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
        } else if (strcasecmp(member, "Disconnected") == 0) {
                unsigned char disc_reason = 0;
                unsigned char addr_type = 0;
+               char *dev_name = NULL;
                gboolean sending = FALSE;
 
-               g_variant_get(msg, "(yy)", &addr_type, &disc_reason);
+               g_variant_get(msg, "(yys)", &addr_type, &disc_reason, &dev_name);
 
                result = disc_reason;
 
                address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-               ret_if(address == NULL);
 
                _bt_convert_device_path_to_address(path, address);
-               dev_name = _bt_get_bonded_device_name(address);
-#ifdef ENABLE_TIZEN_2_4
-               journal_bt_disconnected();
-#endif
 
                /* 0x00 BDADDR_BRDER
                      0x01 BDADDR_LE_PUBLIC
                      0x02 BDADDR_LE_RANDOM */
-               BT_INFO("Address : %s Type : %d", 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 : address);
+               _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] [%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);
 
-               /*Check for any OPP transfer on the device and cancel
-                * the transfer
-                */
-               _bt_obex_check_pending_transfer(address);
-               _bt_opp_client_is_sending(&sending);
-               if (sending == TRUE)
-                       _bt_opp_client_check_pending_transfer(address);
-               param = g_variant_new("(isy)", result, address, addr_type);
-               _bt_send_event(BT_DEVICE_EVENT,
-                                       BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
-                                       param);
+               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;
+
+                               if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
+                                       BT_ERR("vconf_get_int failed");
+
+                               BT_INFO("conn_state[0x%x], adapter_state [%d]",
+                                                       bt_device_state, _bt_adapter_get_status());
+
+                               if (disc_reason == BLUETOOTH_ERROR_CONNECTION_TIMEOUT) {
+                                       _bt_audio_start_auto_connect(TRUE);
+                               } else if (bt_device_state &
+                                                       VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED) {
+                                       BT_INFO("Disconnected due to turning BT off. Skip a address");
+                               } else {
+                                       char *last_connected = NULL;
+                                       last_connected = vconf_get_str(BT_LAST_CONNECTED_DEVICE);
+                                       if (!g_strcmp0(address, last_connected))
+                                               _bt_audio_set_auto_connect_device_addr("");
+                                       if (last_connected)
+                                               free(last_connected);
+                               }
+                       }
+
+#endif
+                       /*Check for any OPP transfer on the device and cancel
+                        * the transfer
+                        */
+                       _bt_obex_check_pending_transfer(address);
+                       _bt_opp_client_is_sending(&sending);
+                       if (sending == TRUE)
+                               _bt_opp_client_check_pending_transfer(address);
+                       /* TODO: MAP? see above */
+               }
+               param = g_variant_new("(isy)", result, address, addr_type);
+               _bt_send_event(BT_DEVICE_EVENT,
+                                       BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
+                                       param);
                g_free(address);
        } else if (strcasecmp(member, "ProfileStateChanged") == 0) {
                int state = 0;
                char *profile_uuid = NULL;
                bt_headset_wait_t *wait_list;
+               bluetooth_device_address_t bd_addr;
 
                g_variant_get(msg, "(si)", &profile_uuid, &state);
 
                address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-               ret_if(address == NULL);
 
                _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", 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)) {
 
                        int event = BLUETOOTH_EVENT_AV_CONNECTED;
-                       char connected_address[BT_ADDRESS_STRING_SIZE + 1];
+#ifndef TIZEN_BT_DUAL_HEADSET_CONNECT
                        bluetooth_device_address_t device_address;
+                       char connected_address[BT_ADDRESS_STRING_SIZE + 1];
                        gboolean connected;
+#endif
                        bt_headset_wait_t *wait_list;
+                       guint trusted = TRUE;
 
                        __bt_set_device_values(TRUE,
                                VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
 
                        __bt_connection_manager_set_state(address, event);
 
-                       if (_bt_headset_get_local_connection() == FALSE)
-                               _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
-                       else {
+                       _bt_get_trust_profile(&bd_addr, TRUSTED_PROFILE_HFP_HF, &trusted);
+
+                       if (_bt_headset_get_local_connection() == FALSE) {
+                               if (trusted == TRUE) /* not restricted*/
+                                       _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
+                       } else {
                                /* Connection Started from local device therefore no need to
                                 * intiate connection for pending profile */
                                _bt_headset_set_local_connection(FALSE);
@@ -1774,6 +1968,10 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                        param = g_variant_new("(is)", result, address);
                        _bt_send_event(BT_HEADSET_EVENT, event,
                                param);
+#ifdef TIZEN_BT_DUAL_HEADSET_CONNECT
+                       _bt_check_already_connected_headset(BT_AUDIO_A2DP,
+                                               address);
+#else
                        connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP,
                                                connected_address);
                        if (connected) {
@@ -1785,7 +1983,7 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                                                &device_address, NULL);
                                }
                        }
-
+#endif
                        _bt_add_headset_to_list(BT_AUDIO_A2DP,
                                                BT_STATE_CONNECTED, address);
 
@@ -1834,7 +2032,7 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                                _bt_audio_connect(wait_list->req_id,
                                                        wait_list->type,
                                                        &device_address,
-                                                       wait_list->out_param1);
+                                                       NULL);
                        }
                } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) {
 
@@ -1875,13 +2073,44 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                        if (state == BT_PROFILE_STATE_CONNECTED) {
                                int event = BLUETOOTH_EVENT_AV_SOURCE_CONNECTED;
                                BT_INFO("A2DP Source is connected");
+#ifdef TIZEN_BT_A2DP_SINK_ENABLE
+                               __bt_set_device_values(TRUE,
+                                               VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
+#endif
+
+#ifdef TIZEN_BT_A2DP_SINK_AUTO_CONNECT
+                               _bt_audio_set_auto_connect_device_addr(address);
+                               _bt_audio_stop_auto_connect();
+#endif
+                               _bt_add_headset_to_list(BT_AUDIO_A2DP_SOURCE,
+                                               BT_STATE_CONNECTED, address);
                                _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
                                        g_variant_new("(is)", result, address));
                        } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
                                int event = BLUETOOTH_EVENT_AV_SOURCE_DISCONNECTED;
                                BT_INFO("A2DP Source Disconnected");
+#ifdef TIZEN_BT_A2DP_SINK_ENABLE
+                               __bt_set_device_values(FALSE,
+                                               VCONFKEY_BT_DEVICE_A2DP_SOURCE_CONNECTED);
+#endif
+                               _bt_remove_headset_from_list(BT_AUDIO_A2DP_SOURCE, address);
                                _bt_send_event(BT_A2DP_SOURCE_EVENT, event,
                                                g_variant_new("(is)", result, address));
+
+                               wait_list = _bt_get_audio_wait_data();
+                               if (wait_list && wait_list->type == BT_AUDIO_A2DP_SOURCE) {
+                                       bluetooth_device_address_t device_address;
+                                       _bt_convert_addr_string_to_type(
+                                                       device_address.addr,
+                                                       wait_list->address);
+
+                                       _bt_audio_connect(wait_list->req_id,
+                                                       wait_list->type,
+                                                       &device_address,
+                                                       NULL);
+                                       /* Now free the wait list */
+                                       _bt_rel_wait_data();
+                               }
                        }
                } else if ((strcmp(profile_uuid, HID_UUID) == 0) &&
                        ((state == BT_PROFILE_STATE_CONNECTED) ||
@@ -1895,12 +2124,30 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                        _bt_send_event(BT_HID_EVENT, event,
                                param);
 
-                       if (state == BT_PROFILE_STATE_CONNECTED)
+                       /* Set the vconf value for device */
+                       if (state == BT_PROFILE_STATE_CONNECTED) {
+                               hid_connected_device_count++;
                                __bt_set_device_values(TRUE,
-                                       VCONFKEY_BT_DEVICE_HID_CONNECTED);
-                       else
-                               __bt_set_device_values(FALSE,
-                                       VCONFKEY_BT_DEVICE_HID_CONNECTED);
+                                               VCONFKEY_BT_DEVICE_HID_CONNECTED);
+                       } else {
+                               hid_connected_device_count--;
+                               if (hid_connected_device_count == 0)
+                                       __bt_set_device_values(FALSE,
+                                               VCONFKEY_BT_DEVICE_HID_CONNECTED);
+                       }
+               } else if (strcmp(profile_uuid, HID_DEVICE_UUID) == 0) {
+                       if (state == BT_PROFILE_STATE_CONNECTED) {
+                               int event;
+                               event = BLUETOOTH_HID_DEVICE_CONNECTED;
+                               param = g_variant_new("(is)", result, address);
+                               _bt_send_event(BT_HID_DEVICE_EVENT, event,
+                                       param);
+                       } else if (state == BT_PROFILE_STATE_DISCONNECTED) {
+                               event = BLUETOOTH_HID_DEVICE_DISCONNECTED;
+                               param = g_variant_new("(is)", result, address);
+                               _bt_send_event(BT_HID_DEVICE_EVENT, event,
+                                       param);
+                       }
                }
                g_free(address);
                g_free(profile_uuid);
@@ -1914,15 +2161,21 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                ret_if(_bt_is_le_scanning() == FALSE);
 
                le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
-               if (le_dev_info == NULL)
+
+               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);
                        return;
+               }
+
+               _bt_convert_device_path_to_address(path, le_dev_info->address);
 
-               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);
                buffer_len = g_variant_get_size(value);
                if (buffer_len > 0)
                        buffer = (char *)g_variant_get_data(value);
@@ -1944,22 +2197,18 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
 
                if (le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) {       /* ADV_IND */
                        adv_info = g_malloc0(sizeof(bt_le_adv_info_t));
-                       if (adv_info == NULL) {
-                               _bt_free_le_device_info(le_dev_info);
-                               g_variant_unref(value);
-                               return;
-                       }
-
                        adv_info->addr = g_strdup(le_dev_info->address);
+                       adv_info->addr_type = le_dev_info->addr_type;
+                       adv_info->rssi = le_dev_info->rssi;
                        adv_info->data_len = le_dev_info->adv_data_len;
                        adv_info->data = g_malloc0(le_dev_info->adv_data_len);
-                       if (adv_info->data) {
-                               memcpy(adv_info->data, le_dev_info->adv_data,
-                                               le_dev_info->adv_data_len);
+                       memcpy(adv_info->data, le_dev_info->adv_data,
+                                       le_dev_info->adv_data_len);
 
-                               __bt_add_adv_ind_info(adv_info);
+                       if (__bt_add_adv_ind_info(adv_info) == 0) {
+                               adv_info->timer_id = g_timeout_add(1000,
+                                       (GSourceFunc)__bt_adv_scan_req_timeout_cb, (void*)adv_info);
                        }
-
                } else {     /* SCAN_RSP */
                        adv_info = __bt_get_adv_ind_info(le_dev_info->address);
                        if (adv_info) {
@@ -1970,13 +2219,13 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                _bt_free_le_device_info(le_dev_info);
                g_variant_unref(value);
        } else if  (strcasecmp(member, "LEDataLengthChanged") == 0) {
-               int tx_octets = 0;
-               int tx_time = 0;
-               int rx_octets = 0;
-               int rx_time = 0;
+               guint16 tx_octets = 0;
+               guint16 tx_time = 0;
+               guint16 rx_octets = 0;
+               guint16 rx_time = 0;
 
                g_variant_get(msg, "(qqqq)",
-                               tx_octets, tx_time, rx_octets, rx_time);
+                               &tx_octets, &tx_time, &rx_octets, &rx_time);
 
                address = g_malloc0(BT_ADDRESS_STRING_SIZE);
                _bt_convert_device_path_to_address(path, address);
@@ -1984,10 +2233,104 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                param = g_variant_new("(isqqqq)", result, address, tx_octets, tx_time,
                                rx_octets, rx_time);
                /* Send event to application */
-               _bt_send_event(BT_DEVICE_EVENT, event, param);
+               _bt_send_event(BT_DEVICE_EVENT,
+                               BLUETOOTH_EVENT_LE_DATA_LENGTH_CHANGED, param);
                g_free(address);
-       }
+       } else if  (strcasecmp(member, "IpspStateChanged") == 0) {
+               gboolean connected = FALSE;
+               char *ifname = NULL;
+               GVariant *ipsp_param = NULL;
+
+               g_variant_get(msg, "(bs)", &connected, &ifname);
+
+               event = connected ? BLUETOOTH_EVENT_IPSP_CONNECTED :
+                                               BLUETOOTH_EVENT_IPSP_DISCONNECTED;
+
+               address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+               _bt_convert_device_path_to_address(path, 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) {
+                       BT_DBG("IPSP connected, Set Ipv6 Addr");
+                       ipsp_proxy = _bt_get_ipsp_proxy();
+                       if (ipsp_proxy == NULL) {
+                               BT_ERR("can not get ipsp proxy");
+                               g_free(address);
+                               g_variant_unref(param);
+                               g_variant_unref(ipsp_param);
+                               return;
+                       }
+
+                       g_dbus_proxy_call(ipsp_proxy, "SetIpv6Addr",
+                                       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;
+                       }
+
+                       g_dbus_proxy_call(ipsp_proxy, "DisableIpsp",
+                                       NULL, G_DBUS_CALL_FLAGS_NONE,
+                                       -1, NULL, NULL, NULL);
+               }
+
+               /* Send event to application */
+               _bt_send_event(BT_DEVICE_EVENT, event, param);
+               g_free(address);
+       } else if (strcasecmp(member, "AttMtuChanged") == 0) {
+               int result = BLUETOOTH_ERROR_NONE;
+               guint16 mtu = 0;
+               guint8 status = 0;
+
+               g_variant_get(msg, "(q)", &mtu);
+
+               address = g_malloc0(BT_ADDRESS_STRING_SIZE);
+
+               _bt_convert_device_path_to_address(path, address);
+               BT_DBG("Address : %s MTU changed : %d", address, mtu);
+
+               param = g_variant_new("(isqy)",
+                       result,
+                       address,
+                       mtu,
+                       status);
+
+               /* Send the event to application */
+               _bt_send_event(BT_DEVICE_EVENT,
+                       BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED,
+                       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);
+       }
 }
 
 void __bt_set_audio_values(gboolean connected, char *address)
@@ -1996,24 +2339,19 @@ void __bt_set_audio_values(gboolean connected, char *address)
        int bt_device_state = VCONFKEY_BT_DEVICE_NONE;
 
        /*  Set the headset name */
-       if (connected == TRUE) {
-               name = _bt_get_bonded_device_name(address);
-       } else {
+       if (connected == TRUE)
+               name = _bt_get_device_name(address);
+       else
                name = g_strdup("");
-       }
 
-       if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME,
-                                       name) != 0) {
+       if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME, name) != 0)
                BT_ERR("vconf_set_str failed");
-       }
 
        g_free(name);
 
        /*  Set the headset state */
-       if (vconf_get_int(VCONFKEY_BT_DEVICE,
-                               &bt_device_state) != 0) {
-               BT_ERR("vconf_get_str failed");
-       }
+       if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0)
+               BT_ERR("vconf_get_int failed");
 
 #ifdef TIZEN_SUPPORT_DUAL_HF
        if ((connected == TRUE) &&
@@ -2024,11 +2362,10 @@ void __bt_set_audio_values(gboolean connected, char *address)
                bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
        }
 #else
-       if (connected == TRUE) {
+       if (connected == TRUE)
                bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
-       } else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) {
+       else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED)
                bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED;
-       }
 #endif
 
        if (vconf_set_int(VCONFKEY_BT_DEVICE,
@@ -2045,6 +2382,7 @@ void _bt_handle_headset_event(GVariant *msg, const char *path)
        GVariant *value = NULL;
        GVariant *param = NULL;
        g_variant_get(msg, "(sv)", &property, &value);
+       bluetooth_device_address_t bd_addr;
 
        ret_if(property == NULL);
 
@@ -2054,21 +2392,22 @@ void _bt_handle_headset_event(GVariant *msg, const char *path)
                int event = BLUETOOTH_EVENT_NONE;
                bt_headset_wait_t *wait_list;
                char *address;
+               guint trusted = TRUE;
                g_variant_get(value, "b", &property_flag);
 
                address = g_malloc0(BT_ADDRESS_STRING_SIZE);
 
-               /* Fix : NULL_RETURNS */
-               if (address == NULL)
-                       return;
-
                _bt_convert_device_path_to_address(path, address);
+               _bt_convert_addr_string_to_type(bd_addr.addr, address);
 
                if (property_flag == TRUE) {
                        event = BLUETOOTH_EVENT_AG_CONNECTED;
-                       if (_bt_headset_get_local_connection() == FALSE)
-                               _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
-                       else
+                       _bt_get_trust_profile(&bd_addr, TRUSTED_PROFILE_A2DP, &trusted);
+
+                       if (_bt_headset_get_local_connection() == FALSE) {
+                               if (trusted == TRUE) /* not restricted*/
+                                       _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
+                       } else
                                _bt_headset_set_local_connection(FALSE);
                } else {
                        int previous_state;
@@ -2103,8 +2442,7 @@ void _bt_handle_headset_event(GVariant *msg, const char *path)
                        _bt_convert_addr_string_to_type(device_address.addr,
                                                        wait_list->address);
                        _bt_audio_connect(wait_list->req_id, wait_list->type,
-                                       &device_address, wait_list->out_param1);
-                       _bt_rel_wait_data();
+                                       &device_address, NULL);
                } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
                        /* Add data to the connected list */
                        _bt_add_headset_to_list(BT_AUDIO_HSP,
@@ -2145,8 +2483,11 @@ void _bt_handle_headset_event(GVariant *msg, const char *path)
 
                _bt_convert_device_path_to_address(path, address);
 
-               g_variant_get(value, "i", &spkr_gain);
-               param = g_variant_new("(isq)", result, address, spkr_gain);
+               spkr_gain = g_variant_get_uint16(value);
+
+               BT_DBG("spkr_gain: %d", spkr_gain);
+
+               param = g_variant_new("(i&sq)", result, address, spkr_gain);
                _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_SPEAKER_GAIN,
                        param);
 
@@ -2159,8 +2500,9 @@ void _bt_handle_headset_event(GVariant *msg, const char *path)
 
                _bt_convert_device_path_to_address(path, address);
 
-               g_variant_get(value, "i", &mic_gain);
-               param = g_variant_new("(isq)", result, address, mic_gain);
+               mic_gain = g_variant_get_uint16(value);
+
+               param = g_variant_new("(i&sq)", result, address, mic_gain);
                _bt_send_event(BT_HEADSET_EVENT, BLUETOOTH_EVENT_AG_MIC_GAIN,
                        param);
                g_free(address);
@@ -2169,7 +2511,7 @@ void _bt_handle_headset_event(GVariant *msg, const char *path)
        if (property)
                g_free(property);
        g_variant_unref(value);
- }
+}
 
 void _bt_handle_sink_event(GVariant *msg, const char *path)
 {
@@ -2236,7 +2578,7 @@ void _bt_handle_sink_event(GVariant *msg, const char *path)
                                        _bt_audio_connect(wait_list->req_id,
                                                                wait_list->type,
                                                                &device_address,
-                                                               wait_list->out_param1);
+                                                               NULL);
                                }
                                g_free(address);
                        } else if (strcasecmp(value, "Connected") == 0) {
@@ -2299,8 +2641,7 @@ void _bt_handle_agent_event(GVariant *msg, const char *member)
                _bt_send_event(BT_OPP_SERVER_EVENT,
                        BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
                        param);
-               g_free(address);
-               g_free(name);
+               /* TODO: MAP? see above */
        } else if (strcasecmp(member, "RfcommAuthorize") == 0) {
                bt_rfcomm_server_info_t *server_info;
 
@@ -2314,9 +2655,34 @@ 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);
+       }
+}
+
+void _bt_handle_tds_provider_event(GVariant *msg, const char *member, const char *path)
+{
+       BT_INFO("member: %s, path: %s", member, path);
+
+       ret_if(path == NULL);
+
+       if (strcasecmp(member, "TdsActivationRequested") == 0) {
+               GVariant *value = NULL;
+               int len = 0;
+               unsigned char *buffer = NULL;
+               unsigned char org_id;
+
+               g_variant_get(msg, "(y@ay)", &org_id, &value);
+               BT_DBG("org_id: %.2x", org_id);
+               len = g_variant_get_size(value);
+               if (len > 0) {
+                       int i;
+                       buffer = (unsigned char *)g_variant_get_data(value);
+                       for (i = 0; i < len; i++)
+                               BT_DBG("%.2x", buffer[i]);
+               }
+
+               /* Send event only registered client */
+               _bt_tds_handle_activation_request(path, org_id, buffer, len);
+               g_variant_unref(value);
        }
 }
 
@@ -2398,29 +2764,29 @@ static  void __bt_manager_event_filter(GDBusConnection *connection,
                g_variant_get(parameters, "(&o@a{sa{sv}})", &obj_path, &value);
 
                if (strcasecmp(obj_path, BT_BLUEZ_HCI_PATH) == 0) {
-#ifdef USB_BLUETOOTH
-                       BT_DBG("Enable Adapter");
-                       _bt_enable_adapter();
-#else
-                       _bt_handle_adapter_added();
-#endif
+                       if (TIZEN_FEATURE_BT_USB_DONGLE) {
+                               BT_DBG("Enable Adapter");
+                               _bt_enable_adapter();
+                       } else {
+                               _bt_handle_adapter_added();
+                       }
                } else {
                        bt_event = __bt_parse_event(value);
                        if (bt_event == BT_DEVICE_EVENT) {
                                bt_cache_info_t *cache_info;
                                bt_remote_dev_info_t *dev_info;
-
-                               ret_if(_bt_is_discovering() == FALSE &&
-                                               _bt_is_le_scanning() == FALSE);
+#ifdef TIZEN_FEATURE_BT_DPM
+                               int desktop_state = DPM_BT_ERROR;
+#endif
+                               if (_bt_is_discovering() == FALSE &&
+                                   _bt_is_le_scanning() == FALSE) {
+                                       g_variant_unref(value);
+                                       return;
+                               }
 
                                cache_info = g_malloc0(sizeof(bt_cache_info_t));
-                               ret_if(cache_info == NULL);
 
                                dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
-                               if (dev_info == NULL) {
-                                       __bt_free_cache_info(cache_info);
-                                       return;
-                               }
 
                                cache_info->dev_info = dev_info;
 
@@ -2446,9 +2812,9 @@ static  void __bt_manager_event_filter(GDBusConnection *connection,
                                         */
                                        dev_info->name = g_strdup(dev_info->address);
 
-#ifdef TIZEN_DPM_ENABLE
-                               if (_bt_dpm_get_bluetooth_desktop_connectivity_state() ==
-                                                       DPM_RESTRICTED) {
+#ifdef TIZEN_FEATURE_BT_DPM
+                               _bt_dpm_get_bluetooth_desktop_connectivity_state(&desktop_state);
+                               if (desktop_state == DPM_RESTRICTED) {
                                        bluetooth_device_class_t device_class;
                                        _bt_divide_device_class(&device_class, dev_info->class);
                                        BT_DBG("[%s]device_class.major_class : %d", dev_info->name, device_class.major_class);
@@ -2500,17 +2866,17 @@ static  void __bt_manager_event_filter(GDBusConnection *connection,
                }
                g_variant_unref(value);
        } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) {
-#ifdef USB_BLUETOOTH
-               BT_DBG("InterfacesRemoved");
-               _bt_handle_adapter_removed();
-#endif
-               if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0) {
+               if (TIZEN_FEATURE_BT_USB_DONGLE) {
+                       BT_DBG("InterfacesRemoved");
+                       _bt_handle_adapter_removed();
+               }
+               if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0)
                        bt_event = BT_MEDIA_TRANSFER_EVENT;
-               } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
+               else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0)
                        bt_event = BT_DEVICE_EVENT;
-               } else if (g_strcmp0(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) {
+               else if (g_strcmp0(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0)
                        bt_event = BT_AVRCP_CONTROL_EVENT;
-               }
+
                if ((bt_event != 0) && (bt_event != BT_MEDIA_TRANSFER_EVENT)) {
                        _bt_handle_adapter_event(parameters, signal_name);
                        if (bt_event == BT_AVRCP_CONTROL_EVENT) {
@@ -2529,22 +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 (strcasecmp(name, BT_BLUEZ_NAME) == 0) {
-                       BT_DBG("Bluetoothd is terminated");
-                       if (_bt_adapter_get_status() == BT_ACTIVATED)
-                                __bt_disable_cb();
+               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("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);
@@ -2561,13 +2928,19 @@ 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 */
                _bt_stop_le_scan(name);
-               g_free(name);
-               g_free(previous);
-               g_free(current);
+
+               /* Stop the Proximity reporter service */
+               _bt_proximity_reporter_stop_by_terminated_process(name);
+
+               /* Stop the Transport Discovery service */
+               _bt_tds_stop_by_terminated_process(name);
        } else if (g_strcmp0(interface_name, BT_PROPERTIES_INTERFACE) == 0) {
                const char *path = object_path;
 
@@ -2590,6 +2963,8 @@ static  void __bt_manager_event_filter(GDBusConnection *connection,
                _bt_handle_agent_event(parameters, signal_name);
        } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) {
                _bt_handle_device_event(parameters, signal_name, object_path);
+       } else if (g_strcmp0(interface_name, BT_TDS_PROVIDER_INTERFACE) == 0) {
+               _bt_handle_tds_provider_event(parameters, signal_name, object_path);
        } else if (g_strcmp0(interface_name, BT_GATT_CHAR_INTERFACE) == 0) {
                _bt_handle_gatt_event(parameters, signal_name, object_path);
        }
@@ -2632,9 +3007,10 @@ static  void __bt_obexd_event_filter(GDBusConnection *connection,
                        BT_ERR("Fail to get the path");
                        return;
                }
-               BT_INFO("object_path = [%s]", object_path);
+               BT_INFO("object_path = [%s]", obj_path);
 
                /*Handle OPP_SERVER_CONNECTED_EVENT here */
+               /* TODO: MAP? see above */
                if (strncmp(obj_path, BT_SESSION_BASEPATH_SERVER,
                                strlen(BT_SESSION_BASEPATH_SERVER)) != 0) {
                        g_free(obj_path);
@@ -2643,16 +3019,17 @@ static  void __bt_obexd_event_filter(GDBusConnection *connection,
 
                if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
                        BT_DBG("Obex_Server_Session_Transfer connected");
-                       _bt_obex_transfer_connected();
+                       _bt_obex_transfer_connected(obj_path);
                }
                g_free(obj_path);
        } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
                /*Handle OPP_SERVER_DISCONNECTED_EVENT here */
+               /* TODO: MAP? see above */
                if (__bt_get_object_path(parameters, &obj_path)) {
                        BT_ERR("Fail to get the path");
                        return;
                }
-               BT_INFO("object_path = [%s]", object_path);
+               BT_INFO("object_path = [%s]", obj_path);
 
                if (strncmp(obj_path, BT_SESSION_BASEPATH_CLIENT,
                                strlen(BT_SESSION_BASEPATH_CLIENT)) == 0) {
@@ -2667,8 +3044,10 @@ static  void __bt_obexd_event_filter(GDBusConnection *connection,
                }
 
                if (g_strrstr(obj_path, "session") && g_strrstr(obj_path, "transfer")) {
-                       BT_DBG("Obex_Server_Session_Transfer disconnected");
-                       _bt_obex_transfer_disconnected();
+                       BT_DBG("Obex_Server_Session_Transfer disconnected %s",
+                                                               obj_path);
+
+                       _bt_obex_transfer_disconnected(obj_path);
                }
                g_free(obj_path);
        } else if (__bt_is_obexd_event(parameters, interface_name) == TRUE) {
@@ -2765,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) {
@@ -2796,56 +3175,118 @@ void _bt_opp_client_event_deinit(void)
        }
 }
 
+static  void __bt_map_event_filter(GDBusConnection *connection,
+                                       const gchar *sender_name,
+                                       const gchar *object_path,
+                                       const gchar *interface_name,
+                                       const gchar *signal_name,
+                                       GVariant *parameters,
+                                       gpointer user_data)
+{
+       BT_DBG("Entered __bt_map_event_filter");
+       const char *member = signal_name;
+
+       if (strcasecmp(member, "InterfacesAdded") == 0) {
+               BT_DBG("------------------------------------ADDED------------------------------------");
+               // currently doing nothing
+       } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
+               BT_DBG("------------------------------------REMOVED------------------------------------");
+               // TODO check if something should be called here?
+               //_bt_map_on_transfer_finished(object_path, error);
+       } else if (__bt_is_obexd_client_event(parameters, interface_name) == TRUE) {
+               BT_DBG("------------------------------------CLIENT EVENT------------------------------------");
+               _bt_map_property_changed_event(parameters, object_path);
+       }
+
+       return;
+}
+
+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_SYSTEM, NULL, &error);
+
+               if (!map_obexd_conn) {
+                       if (error) {
+                               BT_ERR("Unable to connect to dbus: %s", error->message);
+                               g_clear_error(&error);
+                       }
+               return BLUETOOTH_ERROR_INTERNAL;
+               }
+       }
+
+       if (_bt_register_service_event(map_obexd_conn,
+                       BT_MAP_CLIENT_EVENT) != BLUETOOTH_ERROR_NONE) {
+                       g_object_unref(map_obexd_conn);
+                       map_obexd_conn = NULL;
+                       return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
+void _bt_map_client_event_deinit(void)
+{
+       if (map_obexd_conn) {
+               _bt_unregister_service_event(map_obexd_conn,
+                                               BT_MAP_CLIENT_EVENT);
+                g_object_unref(map_obexd_conn);
+                map_obexd_conn = NULL;
+       }
+}
+
 int _bt_register_manager_subscribe_signal(GDBusConnection *conn,
                int subscribe)
 {
        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,
@@ -2853,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;
@@ -2891,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,
@@ -2902,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;
@@ -2917,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,
@@ -2928,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;
@@ -2943,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,
@@ -2962,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;
@@ -2982,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,
@@ -3001,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;
@@ -3021,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,
@@ -3049,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;
@@ -3074,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,
@@ -3102,20 +3543,73 @@ 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;
+}
+
+int _bt_register_map_client_subscribe_signal(GDBusConnection *conn,
+               int subscribe)
+{
+       if (conn == NULL)
+               return -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 == 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 == 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 == 0) {
+                       subs_map_client_property_id = g_dbus_connection_signal_subscribe(conn,
+                               NULL, BT_PROPERTIES_INTERFACE,
+                               BT_PROPERTIES_CHANGED, NULL, NULL, 0,
+                               __bt_map_event_filter,
+                               NULL, NULL);
+               }
+       } else {
+               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 = 0;
+               }
+               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 = 0;
+               }
+               if (subs_map_client_property_id > 0) {
+                       g_dbus_connection_signal_unsubscribe(conn,
+                                       subs_map_client_property_id);
+                       subs_map_client_property_id = 0;
                }
        }
        return 0;
@@ -3127,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,
@@ -3146,15 +3640,78 @@ 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;
+}
+
+int _bt_register_tds_provider_subscribe_signal(GDBusConnection *conn, int subscribe)
+{
+       if (conn == NULL)
+               return -1;
+
+       static guint subs_custom_id = 0;
+
+       if (subscribe) {
+               if (subs_custom_id == 0) {
+                       subs_custom_id = g_dbus_connection_signal_subscribe(conn,
+                               NULL, BT_TDS_PROVIDER_INTERFACE,
+                               NULL, NULL, NULL, 0,
+                               __bt_manager_event_filter,
+                               NULL, NULL);
+               }
+       } else {
+               if (subs_custom_id > 0) {
+                       g_dbus_connection_signal_unsubscribe(conn,
+                                       subs_custom_id);
+                       subs_custom_id = 0;
+               }
+       }
+
+       return 0;
+}
+
+static void __bt_dump_event_filter(GDBusConnection *connection,
+                                       const gchar *sender_name,
+                                       const gchar *object_path,
+                                       const gchar *interface_name,
+                                       const gchar *signal_name,
+                                       GVariant *parameters,
+                                       gpointer user_data)
+{
+       return;
+}
+
+int __bt_register_dump_subscribe_signal(GDBusConnection *conn,
+               gboolean subscribe)
+{
+       if (conn == NULL)
+               return -1;
+
+       static guint subs_source_id = 0;
+
+       if (subscribe) {
+               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,
+                               __bt_dump_event_filter,
+                               NULL, NULL);
+               }
+       } else {
+               if (subs_source_id > 0) {
+                       g_dbus_connection_signal_unsubscribe(conn,
+                                       subs_source_id);
+                       subs_source_id = 0;
                }
        }
        return 0;
@@ -3182,19 +3739,27 @@ int _bt_register_service_event(GDBusConnection *g_conn, int event_type)
        case BT_HEADSET_EVENT:
                _bt_register_audio_subscribe_signal(g_conn, TRUE);
                break;
-
        case BT_OPP_SERVER_EVENT:
                BT_ERR("BT_OPP_SERVER_EVENT: register service event");
                _bt_register_opp_server_subscribe_signal(g_conn, TRUE);
                break;
+
        case BT_OPP_CLIENT_EVENT:
                BT_ERR("BT_OPP_CLIENT_EVENT: register service event");
                _bt_register_opp_client_subscribe_signal(g_conn, TRUE);
                break;
+       case BT_MAP_CLIENT_EVENT:
+               BT_ERR("BT_MAP_CLIENT_EVENT: register service event");
+               _bt_register_map_client_subscribe_signal(g_conn, TRUE);
+               break;
        case BT_A2DP_SOURCE_EVENT:
                BT_INFO("A2dp Source event");
                _bt_register_a2dp_subscribe_signal(g_conn, TRUE);
                break;
+       case BT_TDS_EVENT:
+               BT_INFO("TDS provider event");
+               _bt_register_tds_provider_subscribe_signal(g_conn, TRUE);
+               break;
        default:
                BT_ERR("Unknown event");
                return BLUETOOTH_ERROR_INTERNAL;
@@ -3223,6 +3788,9 @@ void _bt_unregister_service_event(GDBusConnection *g_conn, int event_type)
        case BT_OPP_CLIENT_EVENT:
                _bt_register_opp_client_subscribe_signal(g_conn, FALSE);
                break;
+       case BT_MAP_CLIENT_EVENT:
+               _bt_register_map_client_subscribe_signal(g_conn, FALSE);
+               break;
        default:
                BT_ERR("Unknown event");
                return;
@@ -3264,6 +3832,12 @@ static int __bt_init_manager_receiver(void)
        if (_bt_register_service_event(manager_conn,
                                BT_NETWORK_EVENT) != BLUETOOTH_ERROR_NONE)
                goto fail;
+
+       if (_bt_register_service_event(manager_conn,
+                               BT_TDS_EVENT) != BLUETOOTH_ERROR_NONE)
+               goto fail;
+
+       __bt_register_dump_subscribe_signal(manager_conn, TRUE);
        return BLUETOOTH_ERROR_NONE;
 fail:
        if (manager_conn) {
@@ -3279,31 +3853,61 @@ fail:
 static int __bt_init_obexd_receiver(void)
 {
        BT_DBG("+");
-#ifndef TIZEN_TV /* TODO: obexd doesn't work in TV profile. It should be resolved later. */
-       GError *error = NULL;
+       if (!TIZEN_PROFILE_TV) { /* TODO: obexd doesn't work in TV profile. It should be resolved later. */
+               GError *error = NULL;
 
-       if (obexd_conn == NULL) {
-               obexd_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
-               if (error != NULL) {
-                       BT_ERR("ERROR: Can't get on session bus [%s]", error->message);
-                       g_clear_error(&error);
+               if (obexd_conn == NULL) {
+                       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);
+                       }
+                       retv_if(obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
                }
-               retv_if(obexd_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-       }
 
-       if (_bt_register_service_event(obexd_conn,
-                               BT_OPP_SERVER_EVENT) != BLUETOOTH_ERROR_NONE) {
-               BT_ERR("Error while registering service event");
-               g_object_unref(obexd_conn);
-               obexd_conn = NULL;
-               return BLUETOOTH_ERROR_INTERNAL;
+               if (_bt_register_service_event(obexd_conn,
+                                       BT_OPP_SERVER_EVENT) != BLUETOOTH_ERROR_NONE) {
+                       BT_ERR("Error while registering service event");
+                       g_object_unref(obexd_conn);
+                       obexd_conn = NULL;
+                       return BLUETOOTH_ERROR_INTERNAL;
+               }
        }
-#endif
        BT_DBG("-");
 
        return BLUETOOTH_ERROR_NONE;
 }
 
+gboolean __bt_reinit_obexd_receiver(gpointer user_data)
+{
+       static int retry_cnt = 0;
+       int result = BLUETOOTH_ERROR_NONE;
+
+       BT_DBG("+");
+
+       result = __bt_init_obexd_receiver();
+       if (result != BLUETOOTH_ERROR_NONE) {
+               /* 20 ms * 50 = 10 seconds. During 10 seconds fail to initialize,
+                  then it is not the timing issue. Just can't use the session bus connection */
+               if (retry_cnt > 100) {
+                       BT_ERR("Fail to init obexd receiver by 50 times.");
+                       retry_cnt = 0;
+                       session_reinit_timer = 0;
+                       return FALSE;
+               }
+               retry_cnt++;
+               BT_DBG("Retry to initialize the obexd receiver");
+               return TRUE;
+       }
+
+       retry_cnt = 0;
+       session_reinit_timer = 0;
+
+       BT_DBG("-");
+
+       return FALSE;
+}
+
 /* To receive the event from bluez */
 int _bt_init_service_event_receiver(void)
 {
@@ -3315,9 +3919,17 @@ int _bt_init_service_event_receiver(void)
        retv_if(result != BLUETOOTH_ERROR_NONE, result);
 
        result = __bt_init_obexd_receiver();
-       if (result != BLUETOOTH_ERROR_NONE)
+       if (result != BLUETOOTH_ERROR_NONE) {
                BT_ERR("Fail to init obexd receiver");
 
+               /* Try to re-initialize obexd receiver in the timer */
+               if (session_reinit_timer > 0)
+                       g_source_remove(session_reinit_timer);
+
+               session_reinit_timer = g_timeout_add(BT_SESSION_BUS_GET_TIMEOUT,
+                                                       (GSourceFunc)__bt_reinit_obexd_receiver, NULL);
+       }
+
        BT_DBG("-");
 
        return BLUETOOTH_ERROR_NONE;
@@ -3331,6 +3943,8 @@ void _bt_deinit_service_event_receiver(void)
 
        _bt_unregister_service_event(obexd_conn, BT_OPP_SERVER_EVENT);
 
+       __bt_register_dump_subscribe_signal(manager_conn, FALSE);
+
        if (manager_conn) {
                g_object_unref(manager_conn);
                manager_conn = NULL;
@@ -3343,6 +3957,12 @@ void _bt_deinit_service_event_receiver(void)
 
        if (event_id > 0)
                g_source_remove(event_id);
+       event_id = 0;
+
+       if (le_scan_event_id > 0)
+               g_source_remove(le_scan_event_id);
+       le_scan_event_id = 0;
 
        BT_DBG("-");
 }
+