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 3ffb6a7..f659ad8 100644 (file)
@@ -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