+static void server_register_reply(DBusPendingCall *call, void *user_data)
+{
+ struct connman_technology *technology = user_data;
+ DBusError error;
+ DBusMessage *reply;
+
+ DBG("");
+
+ reply = dbus_pending_call_steal_reply(call);
+
+ dbus_error_init(&error);
+
+ if (dbus_set_error_from_message(&error, reply) == TRUE) {
+ connman_error("%s", error.message);
+ dbus_error_free(&error);
+ dbus_message_unref(reply);
+ dbus_pending_call_unref(call);
+ return;
+ }
+
+ dbus_message_unref(reply);
+ dbus_pending_call_unref(call);
+
+ connman_technology_tethering_notify(technology, TRUE);
+}
+
+static void server_unregister_reply(DBusPendingCall *call, void *user_data)
+{
+ struct connman_technology *technology = user_data;
+ DBusError error;
+ DBusMessage *reply;
+
+ DBG("");
+
+ reply = dbus_pending_call_steal_reply(call);
+
+ dbus_error_init(&error);
+
+ if (dbus_set_error_from_message(&error, reply) == TRUE) {
+ connman_error("%s", error.message);
+ dbus_error_free(&error);
+ dbus_message_unref(reply);
+ dbus_pending_call_unref(call);
+ return;
+ }
+
+ dbus_message_unref(reply);
+ dbus_pending_call_unref(call);
+
+ connman_technology_tethering_notify(technology, FALSE);
+}
+
+
+static void server_register(const char *path, const char *uuid,
+ struct connman_technology *technology,
+ const char *bridge, connman_bool_t enabled)
+{
+ DBusMessage *message;
+ DBusPendingCall *call;
+ char *command;
+
+ DBG("path %s enabled %d", path, enabled);
+
+ command = enabled ? REGISTER : UNREGISTER;
+
+ message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
+ BLUEZ_NETWORK_SERVER, command);
+ if (message == NULL)
+ return;
+
+ dbus_message_set_auto_start(message, FALSE);
+
+ dbus_message_append_args(message, DBUS_TYPE_STRING, &uuid,
+ DBUS_TYPE_INVALID);
+
+ if (enabled == TRUE)
+ dbus_message_append_args(message, DBUS_TYPE_STRING, &bridge,
+ DBUS_TYPE_INVALID);
+
+ if (dbus_connection_send_with_reply(connection, message,
+ &call, TIMEOUT) == FALSE) {
+ connman_error("Failed to enable PAN server");
+ dbus_message_unref(message);
+ return;
+ }
+
+ if (call == NULL) {
+ connman_error("D-Bus connection not available");
+ dbus_message_unref(message);
+ return;
+ }
+
+ if (enabled == TRUE)
+ dbus_pending_call_set_notify(call, server_register_reply,
+ technology, NULL);
+ else
+ dbus_pending_call_set_notify(call, server_unregister_reply,
+ technology, NULL);
+
+ dbus_message_unref(message);
+}
+
+struct tethering_info {
+ struct connman_technology *technology;
+ const char *bridge;
+};
+
+static void enable_nap(gpointer key, gpointer value, gpointer user_data)
+{
+ struct tethering_info *info = user_data;
+ struct connman_device *device = value;
+ const char *path;
+
+ DBG("");
+
+ path = connman_device_get_string(device, "Path");
+
+ server_register(path, "nap", info->technology, info->bridge, TRUE);
+}
+
+static void disable_nap(gpointer key, gpointer value, gpointer user_data)
+{
+ struct tethering_info *info = user_data;
+ struct connman_device *device = value;
+ const char *path;
+
+ DBG("");
+
+ path = connman_device_get_string(device, "Path");
+
+ server_register(path, "nap", info->technology, info->bridge, FALSE);
+}
+