loopback: Return a More Descriptive Error Code
[framework/connectivity/connman.git] / plugins / bluetooth.c
index 03a01dc..d112f87 100644 (file)
@@ -99,7 +99,8 @@ static void connect_reply(DBusPendingCall *call, void *user_data)
        if (dbus_set_error_from_message(&error, reply) == TRUE) {
                connman_error("%s", error.message);
                dbus_error_free(&error);
-               goto done;
+
+               goto err;
        }
 
        if (dbus_message_get_args(reply, &error,
@@ -110,11 +111,11 @@ static void connect_reply(DBusPendingCall *call, void *user_data)
                        dbus_error_free(&error);
                } else
                        connman_error("Wrong arguments for connect");
-               goto done;
+               goto err;
        }
 
        if (interface == NULL)
-               goto done;
+               goto err;
 
        DBG("interface %s", interface);
 
@@ -124,7 +125,15 @@ static void connect_reply(DBusPendingCall *call, void *user_data)
 
        connman_network_set_connected(network, TRUE);
 
-done:
+       dbus_message_unref(reply);
+
+       dbus_pending_call_unref(call);
+
+       return;
+err:
+
+       connman_network_set_connected(network, FALSE);
+
        dbus_message_unref(reply);
 
        dbus_pending_call_unref(call);
@@ -206,6 +215,7 @@ done:
 
        dbus_pending_call_unref(call);
 
+       connman_network_unregister(network);
        connman_network_unref(network);
 }
 
@@ -429,6 +439,8 @@ static void network_properties_reply(DBusPendingCall *call, void *user_data)
        if (network == NULL)
                goto done;
 
+       connman_network_register(network);
+
        connman_network_set_string(network, "Path", path);
 
        connman_network_set_name(network, name);
@@ -948,6 +960,7 @@ static void tech_remove(struct connman_technology *technology)
 
 static void server_register_reply(DBusPendingCall *call, void *user_data)
 {
+       struct connman_technology *technology = user_data;
        DBusError error;
        DBusMessage *reply;
 
@@ -968,11 +981,12 @@ static void server_register_reply(DBusPendingCall *call, void *user_data)
        dbus_message_unref(reply);
        dbus_pending_call_unref(call);
 
-       connman_technology_tethering_notify(NULL, TRUE);
+       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;
 
@@ -993,11 +1007,12 @@ static void server_unregister_reply(DBusPendingCall *call, void *user_data)
        dbus_message_unref(reply);
        dbus_pending_call_unref(call);
 
-       connman_technology_tethering_notify(NULL, FALSE);
+       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;
@@ -1037,60 +1052,60 @@ static void server_register(const char *path, const char *uuid,
 
        if (enabled == TRUE)
                dbus_pending_call_set_notify(call, server_register_reply,
-                                               NULL, NULL);
+                                               technology, NULL);
        else
                dbus_pending_call_set_notify(call, server_unregister_reply,
-                                               NULL, NULL);
+                                               technology, NULL);
 
        dbus_message_unref(message);
 }
 
-static void enable_nap(gpointer key, gpointer value,
-                                               gpointer user_data)
+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 *bridge = user_data;
        const char *path;
 
        DBG("");
 
        path = connman_device_get_string(device, "Path");
 
-       server_register(path, "nap", bridge, TRUE);
+       server_register(path, "nap", info->technology, info->bridge, TRUE);
 }
 
-static void disable_nap(gpointer key, gpointer value,
-                                               gpointer user_data)
+static void disable_nap(gpointer key, gpointer value, gpointer user_data)
 {
+       struct tethering_info *info = user_data;
        struct connman_device *device = value;
-       const char *bridge = user_data;
        const char *path;
 
        DBG("");
 
        path = connman_device_get_string(device, "Path");
 
-       server_register(path, "nap", bridge, FALSE);
+       server_register(path, "nap", info->technology, info->bridge, FALSE);
 }
 
 static int tech_set_tethering(struct connman_technology *technology,
+                               const char *identifier, const char *passphrase,
                                const char *bridge, connman_bool_t enabled)
 {
-       char *bridge_name = g_strdup(bridge);
+       struct tethering_info info = {
+               .technology     = technology,
+               .bridge         = bridge,
+       };
 
        DBG("bridge %s", bridge);
 
-       if (bridge_name == NULL)
-               return -ENOMEM;
-
        if (enabled)
-               g_hash_table_foreach(bluetooth_devices,
-                                       enable_nap, bridge_name);
+               g_hash_table_foreach(bluetooth_devices, enable_nap, &info);
        else
-               g_hash_table_foreach(bluetooth_devices,
-                                       disable_nap, bridge_name);
-
-       g_free(bridge_name);
+               g_hash_table_foreach(bluetooth_devices, disable_nap, &info);
 
        return 0;
 }