Fix double unref issue.
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-device.c
index e9ce2f1..56a7ac7 100644 (file)
@@ -66,6 +66,9 @@
 #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;
@@ -454,9 +457,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");
@@ -467,20 +469,70 @@ bt_remote_dev_info_t *_bt_get_remote_device_info_by_object_path(
        return dev_info;
 }
 
-char *_bt_get_bonded_device_name(char *address)
+char *_bt_get_device_name(const char *bdaddress)
 {
-       bluetooth_device_address_t device_address = { {0} };
-       bluetooth_device_info_t dev_info;
+       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(address == NULL, strdup(""));
+       retv_if(bdaddress == NULL, NULL);
 
-       _bt_convert_addr_string_to_type(device_address.addr, address);
+       device_path = _bt_get_device_object_path((char *)bdaddress);
+       retv_if(device_path == NULL, NULL);
 
-       memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
+       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);
+
+       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);
+       }
 
-       _bt_get_bonded_device_info(&device_address, &dev_info);
+       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);
+               }
+       }
 
-       return g_strdup(dev_info.device_name.name);
+       g_object_unref(device_proxy);
+       return dev_name;
 }
 
 static gboolean __ignore_auto_pairing_request(const char *address)
@@ -621,18 +673,7 @@ static int __bt_remove_and_bond(void)
        adapter_proxy = _bt_get_adapter_proxy();
        retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       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);
-
+       device_path = _bt_get_device_object_path(bonding_info->addr);
        retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        result = g_dbus_proxy_call_sync(adapter_proxy, "UnpairDevice",
@@ -642,12 +683,15 @@ static int __bt_remove_and_bond(void)
                                NULL,
                                &err);
        g_free(device_path);
-       if (err != NULL) {
-               BT_ERR("UnpairDevice Fail: %s", err->message);
-               g_error_free(err);
+       if (result == NULL) {
+               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();
 }
 
@@ -1460,7 +1504,6 @@ int _bt_set_authorization(bluetooth_device_address_t *device_address,
        GDBusConnection *conn;
        GVariant *result = NULL;
        GVariant *temp = NULL;
-       int ret = BLUETOOTH_ERROR_NONE;
 
        BT_CHECK_PARAMETER(device_address, return);
 
@@ -1504,8 +1547,7 @@ int _bt_set_authorization(bluetooth_device_address_t *device_address,
        if (previous_value == authorize) {
                BT_ERR("Same value: %d", previous_value);
                g_object_unref(device_proxy);
-               ret = BLUETOOTH_ERROR_INVALID_PARAM;
-               goto done;
+               return BLUETOOTH_ERROR_INVALID_PARAM;
        }
 
        result = g_dbus_proxy_call_sync(device_proxy, "Set",
@@ -1519,13 +1561,12 @@ int _bt_set_authorization(bluetooth_device_address_t *device_address,
        if (error) {
                 BT_ERR("SetProperty error: [%s]", error->message);
                 g_error_free(error);
-                ret = BLUETOOTH_ERROR_INTERNAL;
+                return BLUETOOTH_ERROR_INTERNAL;
        }
-done:
-       if (result)
-               g_variant_unref(result);
 
-       return ret;
+       g_variant_unref(result);
+
+       return BLUETOOTH_ERROR_NONE;
 }
 
 int _bt_is_gatt_connected(bluetooth_device_address_t *device_address,
@@ -1537,7 +1578,6 @@ int _bt_is_gatt_connected(bluetooth_device_address_t *device_address,
        GDBusProxy *device_proxy;
        GError *error = NULL;
        GVariant *value;
-       GVariant *tmp_value;
        GDBusConnection *conn;
        GVariant *result = NULL;
        int ret = BLUETOOTH_ERROR_NONE;
@@ -1558,8 +1598,9 @@ int _bt_is_gatt_connected(bluetooth_device_address_t *device_address,
        g_free(object_path);
        retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       result = g_dbus_proxy_call_sync(device_proxy, "GetAll",
-                       g_variant_new("(s)", BT_DEVICE_INTERFACE),
+       result = g_dbus_proxy_call_sync(device_proxy, "Get",
+                       g_variant_new("(ss)", BT_DEVICE_INTERFACE,
+                               "GattConnected"),
                        G_DBUS_CALL_FLAGS_NONE,
                        -1,
                        NULL,
@@ -1573,21 +1614,12 @@ int _bt_is_gatt_connected(bluetooth_device_address_t *device_address,
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
-       g_variant_get(result , "(@a{sv})", &value);
+       g_variant_get(result, "(v)", &value);
+       *is_connected = g_variant_get_boolean(value);
        g_variant_unref(result);
 
-       tmp_value = g_variant_lookup_value(value, "GattConnected", G_VARIANT_TYPE_BOOLEAN);
-       if (tmp_value == NULL) {
-               g_object_unref(device_proxy);
-               g_variant_unref(value);
-               return BLUETOOTH_ERROR_INTERNAL;
-       }
-
-       *is_connected = g_variant_get_boolean(tmp_value);
-
        BT_DBG("gatt is connected : %d", *is_connected);
 
-       g_variant_unref(tmp_value);
        g_variant_unref(value);
        g_object_unref(device_proxy);
 
@@ -1741,7 +1773,6 @@ int _bt_get_connected_link(bluetooth_device_address_t *device_address,
        GDBusProxy *device_proxy;
        GError *error = NULL;
        GDBusConnection *conn;
-       GVariant *tmp_value = NULL;
        GVariant *value = NULL;
        GVariant *result = NULL;
 
@@ -1764,33 +1795,24 @@ int _bt_get_connected_link(bluetooth_device_address_t *device_address,
                return BLUETOOTH_ERROR_NONE;
        }
 
-       result = g_dbus_proxy_call_sync(device_proxy, "GetAll",
-                                       g_variant_new("(s)", BT_DEVICE_INTERFACE),
-                                       G_DBUS_CALL_FLAGS_NONE,
-                                       -1,
-                                       NULL,
-                                       &error);
+       result = g_dbus_proxy_call_sync(device_proxy, "Get",
+                       g_variant_new("(ss)", BT_DEVICE_INTERFACE, "Connected"),
+                       G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
 
        if (error != NULL) {
                BT_ERR("Error occured in Proxy call [%s]\n", error->message);
                g_error_free(error);
                g_object_unref(device_proxy);
                return BLUETOOTH_ERROR_INTERNAL;
+       } else {
+               g_variant_get(result, "(v)", &value);
+               *connected = g_variant_get_byte(value);
+               g_variant_unref(value);
+               g_variant_unref(result);
        }
 
-       g_variant_get(result , "(@a{sv})", &value);
-       g_variant_unref(result);
-
-       tmp_value = g_variant_lookup_value(value, "Connected", G_VARIANT_TYPE_BYTE);
-       if (tmp_value != NULL) {
-               *connected = g_variant_get_byte(tmp_value);
-               g_variant_unref(tmp_value);
-               g_object_unref(device_proxy);
-               return BLUETOOTH_ERROR_NONE;
-       } else  {
-               BT_ERR("g_variant value is NULL");
-               return BLUETOOTH_ERROR_INTERNAL;
-       }
+       g_object_unref(device_proxy);
+       return BLUETOOTH_ERROR_NONE;
 }
 
 static void __le_connection_req_cb(GDBusProxy *proxy, GAsyncResult *res,
@@ -2880,7 +2902,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;
+       int trust_profile = FALSE;
        *trusted = FALSE;
 
        switch (profile) {
@@ -2902,6 +2924,24 @@ 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;
@@ -2915,29 +2955,6 @@ 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) {
@@ -2947,20 +2964,12 @@ 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_ALL:
-               return NULL;
-       }
-
-       return NULL;
-}
-
-char *_bt_get_restricted_profile_uuid(bluetooth_restricted_profile_t profile)
-{
-       switch (profile) {
-       case RESTRICTED_PROFILE_HFP_HS:
+       case TRUSTED_PROFILE_HFP_HF:
                return g_strdup("0000111e-0000-1000-8000-00805f9b34fb");
-       case RESTRICTED_PROFILE_A2DP:
+       case TRUSTED_PROFILE_A2DP:
                return g_strdup("0000110b-0000-1000-8000-00805f9b34fb");
+       case TRUSTED_PROFILE_ALL:
+               return NULL;
        }
 
        return NULL;
@@ -3104,132 +3113,6 @@ 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)
 {
@@ -3382,10 +3265,8 @@ int _bt_get_att_mtu(bluetooth_device_address_t *device_address,
        GDBusProxy *device_proxy;
        GError *error = NULL;
        GVariant *value;
-       GVariant *tmp_value;
        GDBusConnection *conn;
        GVariant *result = NULL;
-       int ret = BLUETOOTH_ERROR_NONE;
 
        BT_CHECK_PARAMETER(device_address, return);
 
@@ -3403,40 +3284,24 @@ int _bt_get_att_mtu(bluetooth_device_address_t *device_address,
        g_free(object_path);
        retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       result = g_dbus_proxy_call_sync(device_proxy, "GetAll",
-                       g_variant_new("(s)", BT_DEVICE_INTERFACE),
-                       G_DBUS_CALL_FLAGS_NONE,
-                       -1,
-                       NULL,
-                       &error);
-       if (result == NULL) {
-               if (error != NULL) {
-                       BT_ERR("Error occured in Proxy call [%s]\n", error->message);
-                       g_error_free(error);
-               }
+       result = g_dbus_proxy_call_sync(device_proxy, "Get",
+                       g_variant_new("(ss)", BT_DEVICE_INTERFACE, "AttMtu"),
+                       G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (error) {
+               ERR("DBus Error : %s", error->message);
+               g_clear_error(&error);
                g_object_unref(device_proxy);
                return BLUETOOTH_ERROR_INTERNAL;
-       }
-
-       g_variant_get(result , "(@a{sv})", &value);
-       g_variant_unref(result);
-
-       tmp_value = g_variant_lookup_value(value, "AttMtu", G_VARIANT_TYPE_UINT16);
-       if (tmp_value == NULL) {
-               g_object_unref(device_proxy);
+       } else {
+               g_variant_get(result, "(v)", &value);
+               *mtu = g_variant_get_uint16(value);
+               BT_DBG("ATT MTU : %d", *mtu);
                g_variant_unref(value);
-               return BLUETOOTH_ERROR_INTERNAL;
+               g_variant_unref(result);
        }
 
-       *mtu = g_variant_get_uint16(tmp_value);
-
-       BT_DBG("ATT MTU : %d", *mtu);
-
-       g_variant_unref(tmp_value);
-       g_variant_unref(value);
        g_object_unref(device_proxy);
-
-       return ret;
+       return BLUETOOTH_ERROR_NONE;
 }
 
 int _bt_get_device_ida(bluetooth_device_address_t *device_address,
@@ -3462,47 +3327,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;