+static void pan_remove(struct connman_network *network)
+{
+ struct network_data *data = connman_network_get_data(network);
+
+ DBG("network %p", network);
+
+ connman_network_set_data(network, NULL);
+
+ g_free(data);
+}
+
+static void connect_reply(DBusPendingCall *call, void *user_data)
+{
+ struct connman_network *network = user_data;
+ struct network_data *data = connman_network_get_data(network);
+ DBusMessage *reply;
+ DBusError error;
+ const char *interface = NULL;
+ int index;
+
+ DBG("network %p", network);
+
+ reply = dbus_pending_call_steal_reply(call);
+ if (reply == NULL)
+ return;
+
+ dbus_error_init(&error);
+
+ if (dbus_message_get_args(reply, &error,
+ DBUS_TYPE_STRING, &interface,
+ DBUS_TYPE_INVALID) == FALSE) {
+ if (dbus_error_is_set(&error) == TRUE) {
+ connman_error("%s", error.message);
+ dbus_error_free(&error);
+ } else
+ connman_error("Wrong arguments for connect");
+ goto done;
+ }
+
+ if (interface == NULL)
+ goto done;
+
+ DBG("interface %s", interface);
+
+ data->interface = g_strdup(interface);
+
+ index = inet_name2index(interface);
+
+ connman_network_set_index(network, index);
+ connman_network_set_connected(network, TRUE);
+
+done:
+ dbus_message_unref(reply);
+}
+
+static int pan_connect(struct connman_network *network)
+{
+ struct network_data *data = connman_network_get_data(network);
+ const char *path = connman_network_get_string(network, "Node");
+ const char *uuid = "nap";
+ DBusMessage *message;
+ DBusPendingCall *call;
+
+ DBG("network %p", network);
+
+ message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
+ BLUEZ_NETWORK_INTERFACE, CONNECT);
+ if (message == NULL)
+ return -ENOMEM;
+
+ dbus_message_append_args(message, DBUS_TYPE_STRING, &uuid,
+ DBUS_TYPE_INVALID);
+
+ if (dbus_connection_send_with_reply(data->connection, message,
+ &call, TIMEOUT * 10) == FALSE) {
+ connman_error("Failed to connect service");
+ dbus_message_unref(message);
+ return -EINVAL;
+ }
+
+ if (call == NULL) {
+ connman_error("D-Bus connection not available");
+ dbus_message_unref(message);
+ return -EINVAL;
+ }
+
+ dbus_pending_call_set_notify(call, connect_reply, network, NULL);
+
+ dbus_message_unref(message);
+
+ return -EINPROGRESS;
+}
+
+static void disconnect_reply(DBusPendingCall *call, void *user_data)
+{
+ struct connman_network *network = user_data;
+ struct network_data *data = connman_network_get_data(network);
+ DBusMessage *reply;
+ DBusError error;
+
+ DBG("network %p", network);
+
+ reply = dbus_pending_call_steal_reply(call);
+ if (reply == NULL)
+ return;
+
+ dbus_error_init(&error);
+
+ if (dbus_message_get_args(reply, &error, DBUS_TYPE_INVALID) == FALSE) {
+ if (dbus_error_is_set(&error) == TRUE) {
+ connman_error("%s", error.message);
+ dbus_error_free(&error);
+ } else
+ connman_error("Wrong arguments for disconnect");
+ goto done;
+ }
+
+ g_free(data->interface);
+ data->interface = NULL;
+
+ connman_network_set_connected(network, FALSE);
+ connman_network_set_index(network, -1);
+
+done:
+ dbus_message_unref(reply);
+}
+
+static int pan_disconnect(struct connman_network *network)
+{
+ struct network_data *data = connman_network_get_data(network);
+ const char *path = connman_network_get_string(network, "Node");
+ DBusMessage *message;
+ DBusPendingCall *call;
+
+ DBG("network %p", network);
+
+ if (data->interface == NULL)
+ return -EINVAL;
+
+ message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
+ BLUEZ_NETWORK_INTERFACE, DISCONNECT);
+ if (message == NULL)
+ return -ENOMEM;
+
+ dbus_message_append_args(message, DBUS_TYPE_INVALID);
+
+ if (dbus_connection_send_with_reply(data->connection, message,
+ &call, TIMEOUT) == FALSE) {
+ connman_error("Failed to disconnect service");
+ dbus_message_unref(message);
+ return -EINVAL;
+ }
+
+ if (call == NULL) {
+ connman_error("D-Bus connection not available");
+ dbus_message_unref(message);
+ return -EINVAL;
+ }
+
+ dbus_pending_call_set_notify(call, disconnect_reply, network, NULL);
+
+ dbus_message_unref(message);
+
+ return -EINPROGRESS;
+}
+
+static struct connman_network_driver pan_driver = {
+ .name = "bluetooth-pan",
+ .type = CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN,
+ .probe = pan_probe,
+ .remove = pan_remove,
+ .connect = pan_connect,
+ .disconnect = pan_disconnect,
+};
+
+static int bluetooth_probe(struct connman_device *adapter)
+{
+ struct adapter_data *data;
+
+ DBG("adapter %p", adapter);
+
+ data = g_try_new0(struct adapter_data, 1);
+ if (data == NULL)
+ return -ENOMEM;
+
+ data->connection = connman_dbus_get_connection();
+ if (data->connection == NULL) {
+ g_free(data);
+ return -EIO;
+ }
+
+ connman_device_set_data(adapter, data);
+
+ return 0;
+}
+
+static void bluetooth_remove(struct connman_device *adapter)
+{
+ struct adapter_data *data = connman_device_get_data(adapter);
+
+ DBG("adapter %p", adapter);
+
+ connman_device_set_data(adapter, NULL);
+
+ dbus_connection_unref(data->connection);
+
+ g_free(data);
+}
+
+static void powered_reply(DBusPendingCall *call, void *user_data)
+{
+ DBusMessage *reply;
+
+ DBG("");
+
+ reply = dbus_pending_call_steal_reply(call);
+
+ dbus_message_unref(reply);
+}
+
+static int change_powered(DBusConnection *connection, const char *path,
+ dbus_bool_t powered)
+{
+ DBusMessage *message;
+ DBusMessageIter iter;
+ DBusPendingCall *call;
+
+ DBG("");
+
+ message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
+ BLUEZ_ADAPTER_INTERFACE, SET_PROPERTY);
+ if (message == NULL)
+ return -ENOMEM;
+
+ dbus_message_iter_init_append(message, &iter);
+ connman_dbus_property_append_variant(&iter, "Powered",
+ DBUS_TYPE_BOOLEAN, &powered);
+
+ if (dbus_connection_send_with_reply(connection, message,
+ &call, TIMEOUT) == FALSE) {
+ connman_error("Failed to change Powered property");
+ dbus_message_unref(message);
+ return -EINVAL;
+ }
+
+ if (call == NULL) {
+ connman_error("D-Bus connection not available");
+ dbus_message_unref(message);
+ return -EINVAL;
+ }
+
+ dbus_pending_call_set_notify(call, powered_reply, NULL, NULL);
+
+ dbus_message_unref(message);
+
+ return -EINPROGRESS;
+}
+
+static int bluetooth_enable(struct connman_device *adapter)
+{
+ struct adapter_data *data = connman_device_get_data(adapter);
+ const char *path = connman_device_get_string(adapter, "Node");
+
+ DBG("adapter %p", adapter);
+
+ return change_powered(data->connection, path, TRUE);
+}
+
+static int bluetooth_disable(struct connman_device *adapter)