Handling le connection interval
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-device.c
index 32297fc..49bc041 100644 (file)
@@ -19,6 +19,7 @@
 #include <gio/gio.h>
 #include <dlog.h>
 #include <string.h>
+#include <syspopup_caller.h>
 #include <vconf.h>
 #include <bundle_internal.h>
 
@@ -36,7 +37,6 @@
 #include "bt-service-network.h"
 #include "bt-service-adapter.h"
 #include "bt-service-gap-agent.h"
-#include "bt-service-pbap.h"
 
 #define BT_SYSPOPUP_IPC_RESPONSE_OBJECT "/org/projectx/bt_syspopup_res"
 #define BT_SYSPOPUP_INTERFACE "User.Bluetooth.syspopup"
@@ -66,9 +66,6 @@
 #define BT_LE_CONN_PARAM_LOW_POWER_SLAVE_LATENCY       2       /* event */
 
 #define PROFILE_SUPPORTED 0x3 /* This corresponds to binary 0b11*/
-#define PROFILE_TRUSTED 0x2 /* This corresponds to binary 0b10*/
-#define PROFILE_BLOCKED 0x1 /* This corresponds to binary 0b01*/
-#define PROFILE_SHOW_AUTH 0x0 /* This corresponds to binary 0b00*/
 
 typedef struct {
        int req_id;
@@ -211,6 +208,63 @@ done:
        BT_DBG("-");
 } */
 
+#ifdef TIZEN_PROFILE_WEARABLE
+static gboolean __bt_syspopup_timer_cb(gpointer user_data)
+{
+       int ret;
+       bundle *b;
+       retv_if(user_data == NULL, FALSE);
+
+       b = (bundle *)user_data;
+
+       ret = syspopup_launch("bt-syspopup", b);
+       if (ret < 0) {
+               BT_ERR("Sorry!! Cannot launch popup return = %d, Retrying...", ret);
+       } else {
+               BT_DBG("Hurray!!! Finally Popup launched");
+               bundle_free(b);
+       }
+       return (ret < 0) ? TRUE : FALSE;
+}
+
+static gboolean __bt_launch_unable_to_pairing_syspopup(int result)
+{
+       BT_DBG("+");
+       int ret = 0;
+       bundle *b = NULL;
+       GDBusConnection *conn;
+
+       conn = _bt_gdbus_get_system_gconn();
+       if (conn == NULL)
+               return FALSE;
+
+       b = bundle_create();
+       if (b == NULL)
+               return FALSE;
+
+       bundle_add(b, "event-type", "unable-to-pairing");
+
+       if (result == BLUETOOTH_ERROR_TIMEOUT)
+               bundle_add(b, "error", "timeout");
+       else if (result == BLUETOOTH_ERROR_AUTHENTICATION_FAILED)
+               bundle_add(b, "error", "authfailed");
+       else
+               bundle_add(b, "error", "error");
+
+       ret = syspopup_launch("bt-syspopup", b);
+       if (0 > ret) {
+               BT_ERR("Popup launch failed...retry %d \n", ret);
+               g_timeout_add(200, (GSourceFunc) __bt_syspopup_timer_cb,
+                               b);
+       } else {
+               bundle_free(b);
+       }
+
+       BT_DBG("-");
+       return TRUE;
+}
+#endif
+
 gboolean _bt_is_device_creating(void)
 {
        return is_device_creating;
@@ -279,12 +333,8 @@ static void __bt_get_uuids(GVariant *value, bt_remote_dev_info_t *info)
        ret_if(value == NULL);
        ret_if(info == NULL);
 
-       gsize uuid_count = 0;
-
-       info->uuids = g_variant_dup_strv(value, &uuid_count);
-       info->uuid_count = (unsigned int)uuid_count;
-
-       BT_DBG("uuid count : %d", uuid_count);
+       info->uuid_count = g_variant_get_size(value);
+       info->uuids = g_variant_dup_strv(value, &info->uuid_count);
 }
 
 bt_remote_dev_info_t *_bt_get_remote_device_info(char *address)
@@ -422,7 +472,7 @@ bt_remote_dev_info_t *_bt_get_remote_device_info_by_object_path(
                        g_variant_unref(tmp_value);
                }
 
-               tmp_value = g_variant_lookup_value(value, "ManufacturerDataLen", G_VARIANT_TYPE_UINT16);
+               tmp_value = g_variant_lookup_value(value, "LegacyManufacturerDataLen", G_VARIANT_TYPE_UINT16);
                if (tmp_value) {
                        dev_info->manufacturer_data_len = g_variant_get_uint16(tmp_value);
                        if (dev_info->manufacturer_data_len > BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
@@ -433,7 +483,7 @@ bt_remote_dev_info_t *_bt_get_remote_device_info_by_object_path(
                } else
                        dev_info->manufacturer_data_len = 0;
 
-               tmp_value = g_variant_lookup_value(value, "ManufacturerData", G_VARIANT_TYPE_ARRAY);
+               tmp_value = g_variant_lookup_value(value, "LegacyManufacturerData", G_VARIANT_TYPE_ARRAY);
                if (tmp_value) {
                        if ((dev_info->manufacturer_data_len == 0) ||
                                        dev_info->manufacturer_data_len != g_variant_get_size(tmp_value)) {
@@ -457,9 +507,8 @@ bt_remote_dev_info_t *_bt_get_remote_device_info_by_object_path(
                g_variant_get(tmp_value, "s", &address);
                g_variant_unref(tmp_value);
 
-               dev_info->address = g_strdup(address);
-               dev_info->name = g_strdup(name);
-               g_free(name);
+               dev_info->address = address;
+               dev_info->name = name;
                g_variant_unref(value);
        } else {
                BT_ERR("result  is NULL\n");
@@ -470,70 +519,20 @@ bt_remote_dev_info_t *_bt_get_remote_device_info_by_object_path(
        return dev_info;
 }
 
-char *_bt_get_device_name(const char *bdaddress)
+char *_bt_get_bonded_device_name(char *address)
 {
-       char *device_path = NULL;
-       const gchar *name = NULL;
-       gchar *dev_name = NULL;
-       gsize name_len = 0;
-       GVariant *result = NULL;
-       GError *err = NULL;
-       GDBusProxy *device_proxy;
-       GDBusConnection *conn;
-
-       retv_if(bdaddress == NULL, NULL);
+       bluetooth_device_address_t device_address = { {0} };
+       bluetooth_device_info_t dev_info;
 
-       device_path = _bt_get_device_object_path((char *)bdaddress);
-       retv_if(device_path == NULL, NULL);
+       retv_if(address == NULL, strdup(""));
 
-       conn = _bt_gdbus_get_system_gconn();
-       retv_if(conn == NULL, NULL);
-       INFO_SECURE("Device_path %s", device_path);
-       device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
-                               NULL, BT_BLUEZ_NAME, device_path,
-                               BT_PROPERTIES_INTERFACE, NULL, &err);
+       _bt_convert_addr_string_to_type(device_address.addr, address);
 
-       g_free(device_path);
-       retv_if(device_proxy == NULL, NULL);
-
-       result = g_dbus_proxy_call_sync(device_proxy, "Get",
-                       g_variant_new("(ss)", BT_DEVICE_INTERFACE, "Alias"),
-                       G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
-       if (err) {
-               BT_ERR("DBus Error : %s", err->message);
-               g_clear_error(&err);
-       } else {
-               GVariant *value;
-               g_variant_get(result, "(v)", &value);
-               name = g_variant_get_string(value, &name_len);
-               INFO_SECURE("Alias Name [%s]", name);
-               if (name_len)
-                       dev_name = g_strdup(name);
-               g_variant_unref(value);
-               g_variant_unref(result);
-       }
+       memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
 
-       if (name_len == 0) {
-               GVariant *value;
-               result = g_dbus_proxy_call_sync(device_proxy, "Get",
-                       g_variant_new("(ss)", BT_DEVICE_INTERFACE, "Name"),
-                       G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
-               if (err) {
-                       ERR("DBus Error : %s", err->message);
-                       g_clear_error(&err);
-               } else {
-                       g_variant_get(result, "(v)", &value);
-                       name = g_variant_get_string(value, &name_len);
-                       INFO_SECURE("Name = %s", name);
-                       if (name_len)
-                               dev_name = g_strdup(name);
-                       g_variant_unref(value);
-                       g_variant_unref(result);
-               }
-       }
+       _bt_get_bonded_device_info(&device_address, &dev_info);
 
-       g_object_unref(device_proxy);
-       return dev_name;
+       return g_strdup(dev_info.device_name.name);
 }
 
 static gboolean __ignore_auto_pairing_request(const char *address)
@@ -647,8 +646,6 @@ static int __bt_retry_bond(void)
        BT_CHECK_PARAMETER(bonding_info, return);
        BT_CHECK_PARAMETER(bonding_info->addr, return);
 
-       is_device_creating = TRUE;
-
        g_dbus_proxy_call(bonding_info->device_proxy, "Pair",
                                g_variant_new("(y)", bonding_info->conn_type),
                                G_DBUS_CALL_FLAGS_NONE,
@@ -674,7 +671,18 @@ static int __bt_remove_and_bond(void)
        adapter_proxy = _bt_get_adapter_proxy();
        retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       device_path = _bt_get_device_object_path(bonding_info->addr);
+       result = g_dbus_proxy_call_sync(adapter_proxy, "FindDevice",
+                               g_variant_new("(s)", bonding_info->addr),
+                               G_DBUS_CALL_FLAGS_NONE,
+                               -1,
+                               NULL,
+                               NULL);
+       if (result == NULL)
+               return BLUETOOTH_ERROR_INTERNAL;
+
+       g_variant_get(result , "(o)", &device_path);
+       g_variant_unref(result);
+
        retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        result = g_dbus_proxy_call_sync(adapter_proxy, "UnpairDevice",
@@ -684,15 +692,12 @@ static int __bt_remove_and_bond(void)
                                NULL,
                                &err);
        g_free(device_path);
-       if (result == NULL) {
-               if (err != NULL) {
-                       BT_ERR("UnpairDevice Fail: %s", err->message);
-                       g_error_free(err);
-               }
+       if (err != NULL) {
+               BT_ERR("UnpairDevice Fail: %s", err->message);
+               g_error_free(err);
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
-       g_variant_unref(result);
        return __bt_retry_bond();
 }
 
@@ -723,8 +728,7 @@ static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res,
        GVariant *param;
 
        /* Terminate ALL system popup */
-       if (headed_plugin_info->plugin_headed_enabled)
-               headed_plugin_info->headed_plugin->bt_destroy_popup_all();
+       syspopup_destroy_all();
 
        reply = g_dbus_proxy_call_finish(proxy, res, &err);
        if (reply)
@@ -805,19 +809,17 @@ static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res,
                        result == BLUETOOTH_ERROR_AUTHENTICATION_FAILED ||
                        result == BLUETOOTH_ERROR_TIMEOUT ||
                        result == BLUETOOTH_ERROR_HOST_DOWN) {
-               if (TIZEN_PROFILE_WEARABLE) {
-                       int is_sw_running = 0;
+#ifdef TIZEN_PROFILE_WEARABLE
+               int is_sw_running = 0;
 
-                       if (vconf_get_int(VCONFKEY_SETUP_WIZARD_STATE, &is_sw_running))
-                               BT_ERR("vconf_get_int for setup wizard state failed");
+               if (vconf_get_int(VCONFKEY_SETUP_WIZARD_STATE, &is_sw_running))
+                       BT_ERR("vconf_get_int for setup wizard state failed");
 
-                       if (!is_sw_running) {
-                               if (headed_plugin_info->plugin_headed_enabled)
-                                       headed_plugin_info->headed_plugin->bt_launch_unable_to_pairing_syspopup(result);
-                       } else {
-                               BT_ERR("Unable to pair");
-                       }
-               }
+               if (!is_sw_running)
+                       __bt_launch_unable_to_pairing_syspopup(result);
+               else
+                       BT_ERR("Unable to pair");
+#endif
                bonding_info->result = result;
        }
 
@@ -920,6 +922,8 @@ dbus_return:
        g_dbus_method_invocation_return_value(req_info->context,
                        g_variant_new("(iv)", result, out_param1));
 
+       g_variant_unref(out_param1);
+
        _bt_delete_request_list(req_info->req_id);
 done:
        if (err)
@@ -1723,12 +1727,8 @@ int _bt_is_device_connected(bluetooth_device_address_t *device_address,
                BT_DBG("uuid %s [%s]", uuid, _bt_convert_uuid_to_string(uuid));
 
                object_path = _bt_get_device_object_path(address);
-               if (!object_path) {
-                       BT_ERR("object_path is NULL");
-                       g_free(uuid);
-                       return BLUETOOTH_ERROR_NOT_PAIRED;
-               }
-
+               retv_if(object_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED);
+               BT_DBG("object_path: %s", object_path);
                device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
                                                                        NULL, BT_BLUEZ_NAME,
                                                                        object_path, BT_DEVICE_INTERFACE,  NULL, NULL);
@@ -1945,41 +1945,14 @@ fail:
 
 static gboolean __bt_connect_le_timer_cb(gpointer user_data)
 {
-       int ret;
-
        BT_INFO("Try to initiate pending LE connection");
 
        pending_le_conn_timer_id = 0;
 
-       ret = __bt_connect_le_device_internal(pending_le_conn_info->req_id,
-                       &pending_le_conn_info->bd_addr,
-                       pending_le_conn_info->auto_connect);
-       if (ret != BLUETOOTH_ERROR_NONE) {
-               request_info_t *req_info = NULL;
-               GVariant *out_param1;
-
-               req_info = _bt_get_request_info(pending_le_conn_info->req_id);
-               if (req_info == NULL) {
-                       BT_ERR("req_info is NULL");
-                       goto done;
-               }
-
-               if (req_info->context == NULL) {
-                       BT_ERR("req_info->context is NULL");
-                       _bt_delete_request_list(req_info->req_id);
-                       goto done;
-               }
-
-               out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
-                               &pending_le_conn_info->bd_addr,
-                               sizeof(bluetooth_device_address_t), TRUE,
-                               NULL, NULL);
-
-               g_dbus_method_invocation_return_value(req_info->context,
-                               g_variant_new("(iv)", ret, out_param1));
-       }
+       __bt_connect_le_device_internal(pending_le_conn_info->req_id,
+               &pending_le_conn_info->bd_addr,
+               pending_le_conn_info->auto_connect);
 
-done:
        g_free(pending_le_conn_info);
        pending_le_conn_info = NULL;
 
@@ -2014,10 +1987,10 @@ int _bt_connect_le_device(int req_id, const bluetooth_device_address_t *bd_addr,
                        g_timeout_add(1000, __bt_connect_le_timer_cb, NULL);
 
                return BLUETOOTH_ERROR_NONE;
-       } else if (ret != BLUETOOTH_ERROR_NOT_IN_OPERATION) {
-               BT_ERR("Unable to hold advertising");
        }
 
+       BT_ERR("Unable to hold advertising");
+
        return __bt_connect_le_device_internal(req_id, bd_addr, auto_connect);
 }
 
@@ -2133,17 +2106,8 @@ int _bt_connect_le_ipsp_device(const bluetooth_device_address_t *bd_addr)
                g_object_unref(device_proxy);
                return BLUETOOTH_ERROR_INTERNAL;
        }
-       g_object_unref(device_proxy);
-
-       /* IPSP daemon launch */
-       GDBusProxy *ipsp_proxy;
 
-       ipsp_proxy = _bt_get_ipsp_proxy();
-       retv_if(ipsp_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
-       g_dbus_proxy_call(ipsp_proxy, "EnableIpsp",
-                       NULL, G_DBUS_CALL_FLAGS_NONE,
-                       -1, NULL, NULL, NULL);
+       g_object_unref(device_proxy);
 
        return ret;
 }
@@ -2257,47 +2221,6 @@ int _bt_connect_profile(char *address, char *uuid,
        return BLUETOOTH_ERROR_NONE;
 }
 
-int _bt_disconnect_all(char *address)
-{
-       int ret = BLUETOOTH_ERROR_NONE;
-       char *object_path;
-       GDBusProxy *proxy;
-       GDBusConnection *conn;
-       GVariant *result = NULL;
-       GError *err = NULL;
-
-       BT_DBG("");
-       conn = _bt_gdbus_get_system_gconn();
-       retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
-       object_path = _bt_get_device_object_path(address);
-       retv_if(object_path == NULL, BLUETOOTH_ERROR_INTERNAL);
-
-       proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
-                                       NULL, BT_BLUEZ_NAME,
-                                       object_path, BT_DEVICE_INTERFACE,  NULL, NULL);
-       g_free(object_path);
-       retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
-       result = g_dbus_proxy_call_sync(proxy, "Disconnect",
-               NULL,
-               G_DBUS_CALL_FLAGS_NONE,
-               -1, NULL,
-               &err);
-
-       if (err != NULL) {
-               BT_ERR("Dbus Call Error:[%s]", err->message);
-               g_error_free(err);
-               ret = BLUETOOTH_ERROR_INTERNAL;
-       }
-
-       g_object_unref(proxy);
-       if (result)
-               g_variant_unref(result);
-
-       return ret;
-}
-
 int _bt_disconnect_profile(char *address, char *uuid,
                                                void *cb, gpointer func_data)
 {
@@ -2906,7 +2829,7 @@ int _bt_get_le_connection_parameter(bluetooth_le_connection_mode_t mode,
 int _bt_get_trusted_profile_from_flag(bluetooth_trusted_profile_t profile,
                guint trusted_profile_flag, guint *trusted)
 {
-       int trust_profile = FALSE;
+       int trust_profile;
        *trusted = FALSE;
 
        switch (profile) {
@@ -2928,24 +2851,6 @@ int _bt_get_trusted_profile_from_flag(bluetooth_trusted_profile_t profile,
                else
                        return BLUETOOTH_ERROR_NOT_SUPPORT;
                break;
-       case TRUSTED_PROFILE_HFP_HF: {
-               guint flag = (trusted_profile_flag & (PROFILE_SUPPORTED << 6)) >> 6;
-               BT_DBG("trusted_profile_flag %x", trusted_profile_flag);
-               if (flag != PROFILE_BLOCKED)
-                       trust_profile = TRUE;
-               else
-                       *trusted = FALSE;
-               break;
-       }
-       case TRUSTED_PROFILE_A2DP: {
-               guint flag = (trusted_profile_flag & (PROFILE_SUPPORTED << 8)) >> 8;
-               BT_DBG("trusted_profile_flag %x", trusted_profile_flag);
-               if (flag != PROFILE_BLOCKED)
-                       trust_profile = TRUE;
-               else
-                       *trusted = FALSE;
-               break;
-       }
        case TRUSTED_PROFILE_ALL: /* Return Flag for All profiles*/
                *trusted = trusted_profile_flag;
                return BLUETOOTH_ERROR_NONE;
@@ -2959,6 +2864,29 @@ int _bt_get_trusted_profile_from_flag(bluetooth_trusted_profile_t profile,
        return BLUETOOTH_ERROR_NONE;
 }
 
+int _bt_get_restricted_profile_from_flag(bluetooth_restricted_profile_t profile,
+               guint restricted_profile_flag, guint *restricted)
+{
+       int restrict_profile;
+       *restricted = FALSE;
+
+       switch (profile) {
+       case RESTRICTED_PROFILE_HFP_HS:
+                       restrict_profile = restricted_profile_flag & (1 << 0);
+               break;
+       case RESTRICTED_PROFILE_A2DP:
+                       restrict_profile = restricted_profile_flag & (1 << 2);
+               break;
+       default:
+               return BLUETOOTH_ERROR_NOT_SUPPORT;
+       }
+
+       if (restrict_profile)
+               *restricted = TRUE;
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
 char *_bt_get_trusted_profile_uuid(bluetooth_trusted_profile_t profile)
 {
        switch (profile) {
@@ -2968,10 +2896,6 @@ char *_bt_get_trusted_profile_uuid(bluetooth_trusted_profile_t profile)
                return g_strdup("00001134-0000-1000-8000-00805f9b34fb");
        case TRUSTED_PROFILE_SAP:
                return g_strdup("0000112D-0000-1000-8000-00805f9b34fb");
-       case TRUSTED_PROFILE_HFP_HF:
-               return g_strdup("0000111e-0000-1000-8000-00805f9b34fb");
-       case TRUSTED_PROFILE_A2DP:
-               return g_strdup("0000110b-0000-1000-8000-00805f9b34fb");
        case TRUSTED_PROFILE_ALL:
                return NULL;
        }
@@ -2979,6 +2903,18 @@ char *_bt_get_trusted_profile_uuid(bluetooth_trusted_profile_t profile)
        return NULL;
 }
 
+char *_bt_get_restricted_profile_uuid(bluetooth_restricted_profile_t profile)
+{
+       switch (profile) {
+       case RESTRICTED_PROFILE_HFP_HS:
+               return g_strdup("0000111e-0000-1000-8000-00805f9b34fb");
+       case RESTRICTED_PROFILE_A2DP:
+               return g_strdup("0000110b-0000-1000-8000-00805f9b34fb");
+       }
+
+       return NULL;
+}
+
 bluetooth_trusted_profile_t _bt_get_trusted_profile_enum(const char *uuid)
 {
        if (g_strcmp0("0000112f-0000-1000-8000-00805f9b34fb", uuid) == 0)
@@ -3117,6 +3053,132 @@ int _bt_get_trust_profile(bluetooth_device_address_t *bd_addr,
        return ret;
 }
 
+int _bt_set_restrict_profile(bluetooth_device_address_t *bd_addr,
+               bluetooth_restricted_profile_t profile, gboolean restricted)
+{
+       int ret = BLUETOOTH_ERROR_NONE;
+       GDBusConnection *conn;
+       GDBusProxy *proxy;
+       GError *error = NULL;
+       char *device_path = NULL;
+       char *uuid = NULL;
+       char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+       GVariant *reply;
+
+       BT_CHECK_PARAMETER(bd_addr, return);
+       BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X] profile[%d] restricted[%d]",
+                       bd_addr->addr[0], bd_addr->addr[1],
+                       bd_addr->addr[2], bd_addr->addr[3],
+                       bd_addr->addr[4], bd_addr->addr[5],
+                       profile, restricted);
+
+       conn = _bt_gdbus_get_system_gconn();
+       retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       _bt_convert_addr_type_to_string(address, bd_addr->addr);
+
+       device_path = _bt_get_device_object_path(address);
+       retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+                       NULL, BT_BLUEZ_NAME, device_path,
+                       BT_DEVICE_INTERFACE, NULL, NULL);
+
+       g_free(device_path);
+       retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       uuid = _bt_get_restricted_profile_uuid(profile);
+       if (uuid == NULL) {
+               g_object_unref(proxy);
+               return BLUETOOTH_ERROR_NOT_SUPPORT;
+       }
+
+       reply = g_dbus_proxy_call_sync(proxy, "SetRestrictedProfile",
+                       g_variant_new("(sb)", uuid, restricted),
+                       G_DBUS_CALL_FLAGS_NONE, -1,
+                       NULL, &error);
+       g_object_unref(proxy);
+
+       if (reply == NULL) {
+               BT_ERR("Failed to Set Profile Restricted");
+               ret = BLUETOOTH_ERROR_INTERNAL;
+               if (error) {
+                       BT_ERR("Error %s[%s]", error->message, address);
+                       g_error_free(error);
+               }
+               goto finish;
+       }
+       g_variant_unref(reply);
+
+finish:
+       g_free(uuid);
+       return ret;
+}
+
+int _bt_get_restrict_profile(bluetooth_device_address_t *bd_addr,
+               bluetooth_restricted_profile_t profile, guint *restricted)
+{
+       int ret = BLUETOOTH_ERROR_NONE;
+       GDBusConnection *conn;
+       GDBusProxy *proxy;
+       GError *error = NULL;
+       char *device_path = NULL;
+       guint restricted_profile_flag;
+       char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+       GVariant *reply;
+
+       BT_CHECK_PARAMETER(bd_addr, return);
+       BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X] profile[%d] restricted[%d]",
+                       bd_addr->addr[0], bd_addr->addr[1],
+                       bd_addr->addr[2], bd_addr->addr[3],
+                       bd_addr->addr[4], bd_addr->addr[5],
+                       profile, *restricted);
+
+       conn = _bt_gdbus_get_system_gconn();
+       retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       _bt_convert_addr_type_to_string(address, bd_addr->addr);
+
+       device_path = _bt_get_device_object_path(address);
+       retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+                       NULL, BT_BLUEZ_NAME, device_path,
+                       BT_PROPERTIES_INTERFACE, NULL, NULL);
+
+       g_free(device_path);
+       retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       reply = g_dbus_proxy_call_sync(proxy, "Get",
+                       g_variant_new("(ss)", BT_DEVICE_INTERFACE, "RestrictedProfiles"),
+                       G_DBUS_CALL_FLAGS_NONE, -1,
+                       NULL, &error);
+       g_object_unref(proxy);
+
+       if (reply == NULL) {
+               BT_ERR("Failed to Get Profile Restricted");
+               ret = BLUETOOTH_ERROR_INTERNAL;
+               if (error) {
+                       BT_ERR("Error %s[%s]", error->message, address);
+                       g_error_free(error);
+               }
+               *restricted = 0;
+       } else {
+               GVariant *temp;
+               g_variant_get(reply, "(v)", &temp);
+               restricted_profile_flag = g_variant_get_uint32(temp);
+               BT_DBG("Restricted_FLAG %d", restricted_profile_flag);
+
+               ret = _bt_get_restricted_profile_from_flag(profile,
+                               restricted_profile_flag, restricted);
+               g_variant_unref(temp);
+               g_variant_unref(reply);
+       }
+
+       BT_DBG("TRUST %d", *restricted);
+       return ret;
+}
+
 static void __bt_request_att_mtu_device_cb(GDBusProxy *proxy, GAsyncResult *res,
                                        gpointer user_data)
 {
@@ -3244,6 +3306,12 @@ int _bt_request_att_mtu(int request_id, bluetooth_device_address_t *device_addre
        g_free(device_path);
        retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
+       if (device_path == NULL) {
+               BT_DBG("device_path NULL");
+               ret = BLUETOOTH_ERROR_INTERNAL;
+               goto fail;
+       }
+
        att_mtu_req_info = g_malloc0(sizeof(bt_funcion_data_t));
        att_mtu_req_info->addr = (char *)g_strdup(address);
        att_mtu_req_info->req_id = request_id;
@@ -3256,7 +3324,7 @@ int _bt_request_att_mtu(int request_id, bluetooth_device_address_t *device_addre
                                NULL,
                                (GAsyncReadyCallback)__bt_request_att_mtu_device_cb,
                                NULL);
-
+fail:
        return ret;
 }
 
@@ -3331,47 +3399,36 @@ int _bt_get_device_ida(bluetooth_device_address_t *device_address,
        retv_if(device_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED);
 
        device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
-                                                               NULL, BT_BLUEZ_NAME,
-                                                               device_path, BT_DEVICE_INTERFACE,  NULL, NULL);
+                       NULL, BT_BLUEZ_NAME,
+                       device_path, BT_DEVICE_INTERFACE,  NULL, NULL);
        g_free(device_path);
        if (!device_proxy) {
                BT_ERR("Unable to get proxy");
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
-       result = g_dbus_proxy_call_sync(device_proxy, "GetIDAddress",
-                                NULL,
-                                G_DBUS_CALL_FLAGS_NONE,
-                                -1,
-                                NULL,
-                                &error);
-
+       result = g_dbus_proxy_call_sync(device_proxy, "GetIDAddress", NULL,
+                       G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
        if (result == NULL) {
                BT_ERR("Failed to get device ID address");
                if (error != NULL) {
-                       BT_ERR("Error occured in Proxy call [%s]\n", error->message);
+                       BT_ERR("Error occured in Proxy call [%s]", error->message);
                        g_error_free(error);
                }
                g_object_unref(device_proxy);
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
-       g_variant_get(result , "(s)", &idaddress);
-       g_variant_unref(result);
-
+       g_variant_get(result , "(&s)", &idaddress);
        if (idaddress == NULL) {
                BT_ERR("No paired device");
-               g_object_unref(device_proxy);
-               return BLUETOOTH_ERROR_NOT_PAIRED;
-       }
-
-       BT_DBG("ID Address:%s", idaddress);
-
-       if (idaddress)
+               ret = BLUETOOTH_ERROR_NOT_PAIRED;
+       } else {
+               DBG_SECURE("ID Address : %s", idaddress);
                _bt_convert_addr_string_to_type(id_address->addr, idaddress);
-       else
-               ret = BLUETOOTH_ERROR_INTERNAL;
+       }
 
+       g_variant_unref(result);
        g_object_unref(device_proxy);
 
        return ret;