CAPI/Device: Add function bt_panu_disconnect() 45/19045/1
authorWu Jiangbo <jiangbox.wu@intel.com>
Thu, 3 Apr 2014 10:46:58 +0000 (18:46 +0800)
committerWu Jiangbo <jiangbox.wu@intel.com>
Fri, 4 Apr 2014 11:33:55 +0000 (19:33 +0800)
Change-Id: Ia42ea1edc2c70a2171302bf049bfd5807048caf2
Signed-off-by: Wu Jiangbo <jiangbox.wu@intel.com>
capi/bluetooth.c
test/bluez-capi-test.c

index 4616249..e3af6ab 100644 (file)
@@ -3547,3 +3547,71 @@ done:
 
        return ret;
 }
+
+int bt_panu_disconnect(const char *remote_address)
+{
+       GDBusConnection *connection;
+       char *path, *adapter_address;
+       bluez_device_t *device;
+       int connected, ret;
+       GError *error = NULL;
+
+       DBG("");
+
+       if (initialized == false)
+               return BT_ERROR_NOT_INITIALIZED;
+
+       if (default_adapter == NULL)
+               return BT_ERROR_ADAPTER_NOT_FOUND;
+
+       if (!remote_address)
+               return BT_ERROR_INVALID_PARAMETER;
+
+       device = bluez_adapter_get_device_by_address(default_adapter,
+                                                       remote_address);
+
+       if (device == NULL)
+               return BT_ERROR_OPERATION_FAILED;
+
+       bluez_device_network_get_property_connected(device, &connected);
+       if (connected == FALSE)
+               return BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED;
+
+       adapter_address = bluez_adapter_get_property_address(default_adapter);
+       if (adapter_address == NULL)
+               return BT_ERROR_OPERATION_FAILED;
+
+       path = get_connman_service_path(adapter_address, remote_address);
+       if (path == NULL) {
+               free(adapter_address);
+               return BT_ERROR_OPERATION_FAILED;
+       }
+
+       DBG("path %s", path);
+
+       connection = get_system_dbus_connect();
+       if (connection == NULL) {
+               ret = BT_ERROR_OPERATION_FAILED;
+               goto done;
+       }
+
+       g_dbus_connection_call_sync(connection, CONNMAN_DBUS_NAME, path,
+                                       "net.connman.Service", "Disconnect",
+                                       NULL, NULL, 0, -1, NULL, &error);
+
+       if (error) {
+               DBG("error %s", error->message);
+               g_error_free(error);
+               ret = BT_ERROR_OPERATION_FAILED;
+
+               goto done;
+       }
+
+       ret = BT_SUCCESS;
+
+done:
+       free(path);
+       free(adapter_address);
+
+       return ret;
+}
index ab065d2..71ddf7f 100644 (file)
@@ -1432,6 +1432,22 @@ static int panu_connect(const char *p1, const char *p2)
        return 0;
 }
 
+static int panu_disconnect(const char *p1, const char *p2)
+{
+       int ret;
+
+       if (p1 == NULL) {
+               ERROR("panu_disconnect need remote address");
+               return 0;
+       }
+
+       ret = bt_panu_disconnect(p1);
+       if (ret != BT_SUCCESS)
+               DBG("bt_panu_disconnect failed %d", ret);
+
+       return 0;
+}
+
 struct {
        const char *command;
        int (*function)(const char *p1, const char *p2);
@@ -1623,6 +1639,9 @@ struct {
        {"panu_connect", panu_connect,
                "Usage: panu_connect 70:F9:27:64:DF:65\n\tconnect address for panu"},
 
+       {"panu_disconnect", panu_disconnect,
+               "Usage: panu_disconnect 70:F9:27:64:DF:65\n\tdisconnect address for panu"},
+
        {"q", quit,
                "Usage: q\n\tQuit"},