Adapt device disconnect to BT HAL framework
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / bluez_hal / src / bt-hal-device-dbus-handler.c
index b1f4671..f659ad8 100644 (file)
@@ -566,7 +566,7 @@ done:
        ev->num_props = 0;
        size = sizeof(*ev);
        ERR("Error: Failed to get Remote device properties after SDP,"
-                       " Num Prop [%d] total size [%d]", ev->num_props, size);
+                       " Num Prop [%d] total size [%zd]", ev->num_props, size);
        event_cb(HAL_EV_REMOTE_DEVICE_PROPS, (void*) buf, size);
 
 cleanup:
@@ -633,7 +633,7 @@ static void __bt_device_parse_services(GVariant *result)
        }
 
        DBG("Send Remote Device services to HAL,"
-                       " Num Prop [%d] total size [%d]", ev->num_props, size);
+                       " Num Prop [%d] total size [%zd]", ev->num_props, size);
        event_cb(HAL_EV_REMOTE_DEVICE_PROPS, (void*) buf, size);
 
        g_variant_unref(result);
@@ -936,10 +936,10 @@ static gboolean __bt_device_bonded_device_info_cb(gpointer user_data)
                                ev->num_props = num_props_tmp + 1;
                                g_free(uuid_value);
                        }
-               } else if (!g_strcmp0(key, "ManufacturerDataLen")) {
+               } else if (!g_strcmp0(key, "LegacyManufacturerDataLen")) {
                        data_len = g_variant_get_uint16(value);
-                       DBG("ManufacturerDataLen [%d]", data_len);
-               } else if (!g_strcmp0(key, "ManufacturerData")) {
+                       DBG("LegacyManufacturerDataLen [%d]", data_len);
+               } else if (!g_strcmp0(key, "LegacyManufacturerData")) {
                        manufacturer_data = g_byte_array_new();
                        g_variant_get(value, "ay", &char_value_iter);
                        while (g_variant_iter_loop(char_value_iter, "y", &char_value))
@@ -978,12 +978,12 @@ static gboolean __bt_device_bonded_device_info_cb(gpointer user_data)
                ev->num_props = 0;
                size = sizeof(*ev);
                DBG("Send Remote Device properties event to HAL,"
-                               " Num Prop [%d] total size [%d]", ev->num_props, size);
+                               " Num Prop [%d] total size [%zd]", ev->num_props, size);
                event_cb(HAL_EV_REMOTE_DEVICE_PROPS, (void*) buf, size);
        } else {
                if (size > 2) {
                        DBG("Send Remote Device properties event to HAL,"
-                               " Num Prop [%d] total size [%d]", ev->num_props, size);
+                               " Num Prop [%d] total size [%zd]", ev->num_props, size);
                        event_cb(HAL_EV_REMOTE_DEVICE_PROPS, (void*) buf, size);
                }
        }
@@ -1675,4 +1675,59 @@ int _bt_hal_device_get_connected_link_rssi_strength(const bt_bdaddr_t *bd_addr,
        DBG("-");
        return BT_STATUS_SUCCESS;
 }
+
+
+int _bt_hal_device_disconnect(const bt_bdaddr_t *bd_addr)
+{
+       GDBusProxy *proxy;
+       char address[BT_HAL_ADDRESS_STRING_SIZE] = { 0 };
+       GError *error = NULL;
+       GVariant *result = NULL;
+       GDBusConnection *conn;
+       char *device_path = NULL;
+       DBG("+");
+
+       conn = _bt_hal_get_system_gconn();
+       if (!conn) {
+               DBG("Could not get DBUS connection!");
+               return BT_STATUS_FAIL;
+       }
+
+       _bt_hal_convert_addr_type_to_string(address, bd_addr->address);
+       device_path = _bt_hal_get_device_object_path(address);
+
+       if (device_path == NULL) {
+               ERR("No created device with address:[%s] in statck", address);
+               return BT_STATUS_FAIL;
+       }
+       proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+                       NULL, BT_HAL_BLUEZ_NAME,
+                       device_path, BT_HAL_DEVICE_INTERFACE, NULL, NULL);
+
+       g_free(device_path);
+       if (proxy == NULL) {
+               ERR("Could not get Device Proxy");
+               return BT_STATUS_FAIL;
+       }
+
+       result = g_dbus_proxy_call_sync(proxy, "Disconnect",
+                       NULL,
+                       G_DBUS_CALL_FLAGS_NONE,
+                       -1, NULL,
+                       &error);
+
+       if (error != NULL) {
+               ERR("Dbus Call Error:[%s]", error->message);
+               g_clear_error(&error);
+               g_object_unref(proxy);
+               return BT_STATUS_FAIL;
+       }
+
+       g_object_unref(proxy);
+       if (result)
+               g_variant_unref(result);
+
+       DBG("-");
+       return BT_STATUS_SUCCESS;
+}
 #endif