device: Support already powered devices
[platform/upstream/connman.git] / src / device.c
index 813e3bc..91806b7 100644 (file)
 #include <errno.h>
 #include <string.h>
 
-#include <gdbus.h>
-
 #include "connman.h"
 
-static DBusConnection *connection = NULL;
-
 struct connman_device {
        struct connman_element element;
        enum connman_device_type type;
-       enum connman_device_mode mode;
        connman_bool_t offlinemode;
        connman_bool_t blocked;
        connman_bool_t powered;
@@ -49,7 +44,6 @@ struct connman_device {
        char *node;
        char *address;
        char *interface;
-       char *control;
        char *ident;
        int phyindex;
        unsigned int connections;
@@ -58,14 +52,9 @@ struct connman_device {
        struct connman_device_driver *driver;
        void *driver_data;
 
-       connman_bool_t registered;
-
        char *last_network;
        struct connman_network *network;
        GHashTable *networks;
-
-       DBusMessage *pending;
-       guint timeout;
 };
 
 static gboolean device_scan_trigger(gpointer user_data)
@@ -187,25 +176,11 @@ enum connman_service_type __connman_device_get_service_type(struct connman_devic
        return CONNMAN_SERVICE_TYPE_UNKNOWN;
 }
 
-static void powered_changed(struct connman_device *device)
-{
-       connman_dbus_property_changed_basic(device->element.path,
-                               CONNMAN_DEVICE_INTERFACE, "Powered",
-                                       DBUS_TYPE_BOOLEAN, &device->powered);
-}
-
-static void blocked_changed(struct connman_device *device)
-{
-       connman_dbus_property_changed_basic(device->element.path,
-                               CONNMAN_DEVICE_INTERFACE, "Blocked",
-                                       DBUS_TYPE_BOOLEAN, &device->blocked);
-}
-
 int __connman_device_enable(struct connman_device *device)
 {
        int err;
 
-       DBG("device %p", device);
+       DBG("device %p %d", device, device->blocked);
 
        if (!device->driver || !device->driver->enable)
                return -EOPNOTSUPP;
@@ -217,14 +192,21 @@ int __connman_device_enable(struct connman_device *device)
                return -ENOLINK;
 
        err = device->driver->enable(device);
-       if (err < 0) {
-               if (err == -EINPROGRESS)
+       if (err < 0 && err != -EALREADY) {
+               if (err == -EINPROGRESS) {
                        device->powered_pending = TRUE;
+                       device->offlinemode = FALSE;
+                       if (__connman_profile_get_offlinemode() == TRUE)
+                               __connman_profile_set_offlinemode(FALSE, FALSE);
+               }
                return err;
        }
 
        device->powered_pending = TRUE;
        device->powered = TRUE;
+       device->offlinemode = FALSE;
+       if (__connman_profile_get_offlinemode() == TRUE)
+               __connman_profile_set_offlinemode(FALSE, FALSE);
 
        __connman_technology_enable_device(device);
 
@@ -253,7 +235,7 @@ int __connman_device_disable(struct connman_device *device)
        g_hash_table_remove_all(device->networks);
 
        err = device->driver->disable(device);
-       if (err < 0) {
+       if (err < 0 && err != -EALREADY) {
                if (err == -EINPROGRESS)
                        device->powered_pending = FALSE;
                return err;
@@ -277,292 +259,12 @@ static int set_powered(struct connman_device *device, connman_bool_t powered)
                return __connman_device_disable(device);
 }
 
-void __connman_device_list(DBusMessageIter *iter, void *user_data)
-{
-       __connman_element_list(NULL, CONNMAN_ELEMENT_TYPE_DEVICE, iter);
-}
-
-static void append_path(gpointer key, gpointer value, gpointer user_data)
-{
-       struct connman_element *element = value;
-       DBusMessageIter *iter = user_data;
-
-       dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
-                                                       &element->path);
-}
-
-static void append_networks(DBusMessageIter *iter, void *user_data)
-{
-       struct connman_device *device = user_data;
-
-       g_hash_table_foreach(device->networks, append_path, iter);
-}
-
-static DBusMessage *get_properties(DBusConnection *conn,
-                                       DBusMessage *msg, void *data)
-{
-       struct connman_device *device = data;
-       DBusMessage *reply;
-       DBusMessageIter array, dict;
-       const char *str;
-
-       DBG("conn %p", conn);
-
-       if (__connman_security_check_privilege(msg,
-                                       CONNMAN_SECURITY_PRIVILEGE_PUBLIC) < 0)
-               return __connman_error_permission_denied(msg);
-
-       reply = dbus_message_new_method_return(msg);
-       if (reply == NULL)
-               return NULL;
-
-       dbus_message_iter_init_append(reply, &array);
-
-       connman_dbus_dict_open(&array, &dict);
-
-       if (device->name != NULL)
-               connman_dbus_dict_append_basic(&dict, "Name",
-                                       DBUS_TYPE_STRING, &device->name);
-
-       str = type2string(device->type);
-       if (str != NULL)
-               connman_dbus_dict_append_basic(&dict, "Type",
-                                               DBUS_TYPE_STRING, &str);
-
-       if (device->address != NULL)
-               connman_dbus_dict_append_basic(&dict, "Address",
-                                       DBUS_TYPE_STRING, &device->address);
-
-       if (device->interface != NULL)
-               connman_dbus_dict_append_basic(&dict, "Interface",
-                                       DBUS_TYPE_STRING, &device->interface);
-
-       connman_dbus_dict_append_basic(&dict, "Powered",
-                                       DBUS_TYPE_BOOLEAN, &device->powered);
-
-       connman_dbus_dict_append_basic(&dict, "Blocked",
-                                       DBUS_TYPE_BOOLEAN, &device->blocked);
-
-       if (device->driver && device->driver->scan)
-               connman_dbus_dict_append_basic(&dict, "Scanning",
-                                       DBUS_TYPE_BOOLEAN, &device->scanning);
-
-       switch (device->mode) {
-       case CONNMAN_DEVICE_MODE_UNKNOWN:
-               break;
-       case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
-       case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
-               if (device->scan_interval > 0)
-                       connman_dbus_dict_append_basic(&dict, "ScanInterval",
-                               DBUS_TYPE_UINT16, &device->scan_interval);
-
-               connman_dbus_dict_append_array(&dict, "Networks",
-                               DBUS_TYPE_OBJECT_PATH, append_networks, device);
-               break;
-       }
-
-       connman_dbus_dict_close(&array, &dict);
-
-       return reply;
-}
-
-static gboolean powered_timeout(gpointer user_data)
-{
-       struct connman_device *device = user_data;
-
-       DBG("device %p", device);
-
-       device->timeout = 0;
-
-       if (device->pending != NULL) {
-               DBusMessage *reply;
-
-               reply = __connman_error_operation_timeout(device->pending);
-               if (reply != NULL)
-                       g_dbus_send_message(connection, reply);
-
-               dbus_message_unref(device->pending);
-               device->pending = NULL;
-       }
-
-       return FALSE;
-}
-
-static DBusMessage *set_property(DBusConnection *conn,
-                                       DBusMessage *msg, void *data)
-{
-       struct connman_device *device = data;
-       DBusMessageIter iter, value;
-       const char *name;
-       int type;
-
-       DBG("conn %p", conn);
-
-       if (dbus_message_iter_init(msg, &iter) == FALSE)
-               return __connman_error_invalid_arguments(msg);
-
-       dbus_message_iter_get_basic(&iter, &name);
-       dbus_message_iter_next(&iter);
-       dbus_message_iter_recurse(&iter, &value);
-
-       if (__connman_security_check_privilege(msg,
-                                       CONNMAN_SECURITY_PRIVILEGE_MODIFY) < 0)
-               return __connman_error_permission_denied(msg);
-
-       type = dbus_message_iter_get_arg_type(&value);
-
-       if (g_str_equal(name, "Powered") == TRUE) {
-               connman_bool_t powered;
-               int err;
-
-               if (type != DBUS_TYPE_BOOLEAN)
-                       return __connman_error_invalid_arguments(msg);
-
-               dbus_message_iter_get_basic(&value, &powered);
-
-               device->powered_persistent = powered;
-
-               __connman_storage_save_device(device);
-
-               if (device->powered == powered)
-                       return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
-
-               if (device->pending != NULL)
-                       return __connman_error_in_progress(msg);
-
-               err = set_powered(device, powered);
-               if (err < 0) {
-                       if (err != -EINPROGRESS)
-                               return __connman_error_failed(msg, -err);
-
-                       device->pending = dbus_message_ref(msg);
-
-                       device->timeout = g_timeout_add_seconds(15,
-                                               powered_timeout, device);
-
-                       return NULL;
-               }
-       } else if (g_str_equal(name, "ScanInterval") == TRUE) {
-               connman_uint16_t interval;
-
-               switch (device->mode) {
-               case CONNMAN_DEVICE_MODE_UNKNOWN:
-               case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
-               case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
-                       break;
-               }
-
-               if (type != DBUS_TYPE_UINT16)
-                       return __connman_error_invalid_arguments(msg);
-
-               dbus_message_iter_get_basic(&value, &interval);
-
-               if (device->scan_interval != interval) {
-                       device->scan_interval = interval;
-
-                       __connman_storage_save_device(device);
-
-                       reset_scan_trigger(device);
-               }
-       } else
-               return __connman_error_invalid_property(msg);
-
-       return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
-}
-
-static DBusMessage *propose_scan(DBusConnection *conn,
-                                       DBusMessage *msg, void *data)
-{
-       struct connman_device *device = data;
-       int err;
-
-       DBG("conn %p", conn);
-
-       switch (device->mode) {
-       case CONNMAN_DEVICE_MODE_UNKNOWN:
-               return __connman_error_not_supported(msg);
-       case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
-       case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
-               break;
-       }
-
-       err = __connman_device_scan(device);
-       if (err < 0)
-               return __connman_error_failed(msg, -err);
-
-       return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
-}
-
-static GDBusMethodTable device_methods[] = {
-       { "GetProperties", "",      "a{sv}", get_properties },
-       { "SetProperty",   "sv",    "",      set_property,
-                                               G_DBUS_METHOD_FLAG_ASYNC },
-       { "ProposeScan",   "",      "",      propose_scan   },
-       { },
-};
-
-static GDBusSignalTable device_signals[] = {
-       { "PropertyChanged", "sv" },
-       { },
-};
-
-static int register_interface(struct connman_element *element)
-{
-       struct connman_device *device = element->device;
-
-       DBG("element %p name %s", element, element->name);
-
-       if (g_dbus_register_interface(connection, element->path,
-                                       CONNMAN_DEVICE_INTERFACE,
-                                       device_methods, device_signals,
-                                       NULL, device, NULL) == FALSE) {
-               connman_error("Failed to register %s device", element->path);
-               return -EIO;
-       }
-
-       device->registered = TRUE;
-
-       return 0;
-}
-
-static void unregister_interface(struct connman_element *element)
-{
-       struct connman_device *device = element->device;
-
-       DBG("element %p name %s", element, element->name);
-
-       device->registered = FALSE;
-
-       g_dbus_unregister_interface(connection, element->path,
-                                               CONNMAN_DEVICE_INTERFACE);
-}
-
 static int setup_device(struct connman_device *device)
 {
-       int err;
-
        DBG("device %p", device);
 
-       err = register_interface(&device->element);
-       if (err < 0) {
-               if (device->driver->remove)
-                       device->driver->remove(device);
-               device->driver = NULL;
-               return err;
-       }
-
        __connman_technology_add_device(device);
 
-       switch (device->mode) {
-       case CONNMAN_DEVICE_MODE_UNKNOWN:
-       case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
-       case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
-               break;
-       }
-
-       if (__connman_udev_get_blocked(device->phyindex) == TRUE)
-               return 0;
-
        if (device->offlinemode == FALSE &&
                                device->powered_persistent == TRUE)
                __connman_device_enable(device);
@@ -590,6 +292,8 @@ static void probe_driver(struct connman_element *element, gpointer user_data)
 
        element->device->driver = driver;
 
+       __connman_element_set_driver(element);
+
        setup_device(element->device);
 }
 
@@ -599,17 +303,8 @@ static void remove_device(struct connman_device *device)
 
        __connman_device_disable(device);
 
-       switch (device->mode) {
-       case CONNMAN_DEVICE_MODE_UNKNOWN:
-       case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
-       case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
-               break;
-       }
-
        __connman_technology_remove_device(device);
 
-       unregister_interface(&device->element);
-
        if (device->driver->remove)
                device->driver->remove(device);
 
@@ -634,7 +329,7 @@ connman_bool_t __connman_device_has_driver(struct connman_device *device)
        if (device == NULL || device->driver == NULL)
                return FALSE;
 
-       return device->registered;
+       return TRUE;
 }
 
 static GSList *driver_list = NULL;
@@ -692,6 +387,8 @@ static void unregister_network(gpointer data)
 
        connman_element_unregister((struct connman_element *) network);
 
+       __connman_network_set_device(network, NULL);
+
        connman_network_unref(network);
 }
 
@@ -701,23 +398,12 @@ static void device_destruct(struct connman_element *element)
 
        DBG("element %p name %s", element, element->name);
 
-       if (device->timeout > 0) {
-               g_source_remove(device->timeout);
-               device->timeout = 0;
-       }
-
        clear_scan_trigger(device);
 
-       if (device->pending != NULL) {
-               dbus_message_unref(device->pending);
-               device->pending = NULL;
-       }
-
        g_free(device->ident);
        g_free(device->node);
        g_free(device->name);
        g_free(device->address);
-       g_free(device->control);
        g_free(device->interface);
 
        g_free(device->last_network);
@@ -740,6 +426,7 @@ struct connman_device *connman_device_create(const char *node,
 {
        struct connman_device *device;
        const char *str;
+       enum connman_service_type service_type;
 
        DBG("node %s type %d", node, type);
 
@@ -766,12 +453,14 @@ struct connman_device *connman_device_create(const char *node,
 
        device->type = type;
        device->name = g_strdup(type2description(device->type));
-       device->mode = CONNMAN_DEVICE_MODE_UNKNOWN;
 
        device->powered_persistent = TRUE;
 
        device->phyindex = -1;
 
+       service_type = __connman_device_get_service_type(device);
+       device->blocked = __connman_technology_get_blocked(service_type);
+
        switch (type) {
        case CONNMAN_DEVICE_TYPE_UNKNOWN:
        case CONNMAN_DEVICE_TYPE_VENDOR:
@@ -843,28 +532,6 @@ enum connman_device_type connman_device_get_type(struct connman_device *device)
 }
 
 /**
- * connman_device_get_name:
- * @device: device structure
- *
- * Get unique name of device
- */
-const char *connman_device_get_name(struct connman_device *device)
-{
-       return device->element.name;
-}
-
-/**
- * connman_device_get_path:
- * @device: device structure
- *
- * Get path name of device
- */
-const char *connman_device_get_path(struct connman_device *device)
-{
-       return device->element.path;
-}
-
-/**
  * connman_device_set_index:
  * @device: device structure
  * @index: index number
@@ -902,12 +569,11 @@ void __connman_device_set_phyindex(struct connman_device *device,
  * connman_device_set_interface:
  * @device: device structure
  * @interface: interface name
- * @control: control interface
  *
  * Set interface name of device
  */
 void connman_device_set_interface(struct connman_device *device,
-                               const char *interface, const char *control)
+                                               const char *interface)
 {
        g_free(device->element.devname);
        device->element.devname = g_strdup(interface);
@@ -915,9 +581,6 @@ void connman_device_set_interface(struct connman_device *device,
        g_free(device->interface);
        device->interface = g_strdup(interface);
 
-       g_free(device->control);
-       device->control = g_strdup(control);
-
        if (device->name == NULL) {
                const char *str = type2description(device->type);
                if (str != NULL && device->interface != NULL)
@@ -926,11 +589,6 @@ void connman_device_set_interface(struct connman_device *device,
        }
 }
 
-const char *connman_device_get_control(struct connman_device *device)
-{
-       return device->control;
-}
-
 /**
  * connman_device_set_ident:
  * @device: device structure
@@ -945,36 +603,12 @@ void connman_device_set_ident(struct connman_device *device,
        device->ident = g_strdup(ident);
 }
 
-const char *__connman_device_get_ident(struct connman_device *device)
+const char *connman_device_get_ident(struct connman_device *device)
 {
        return device->ident;
 }
 
 /**
- * connman_device_set_mode:
- * @device: device structure
- * @mode: network mode
- *
- * Change network mode of device
- */
-void connman_device_set_mode(struct connman_device *device,
-                                               enum connman_device_mode mode)
-{
-       device->mode = mode;
-}
-
-/**
- * connman_device_get_mode:
- * @device: device structure
- *
- * Get network mode of device
- */
-enum connman_device_mode connman_device_get_mode(struct connman_device *device)
-{
-       return device->mode;
-}
-
-/**
  * connman_device_set_powered:
  * @device: device structure
  * @powered: powered state
@@ -984,20 +618,9 @@ enum connman_device_mode connman_device_get_mode(struct connman_device *device)
 int connman_device_set_powered(struct connman_device *device,
                                                connman_bool_t powered)
 {
-       DBG("driver %p powered %d", device, powered);
-
-       if (device->timeout > 0) {
-               g_source_remove(device->timeout);
-               device->timeout = 0;
-       }
-
-       if (device->pending != NULL) {
-               g_dbus_send_reply(connection, device->pending,
-                                                       DBUS_TYPE_INVALID);
+       int err;
 
-               dbus_message_unref(device->pending);
-               device->pending = NULL;
-       }
+       DBG("driver %p powered %d", device, powered);
 
        if (device->powered == powered) {
                device->powered_pending = powered;
@@ -1005,9 +628,12 @@ int connman_device_set_powered(struct connman_device *device,
        }
 
        if (powered == TRUE)
-               __connman_device_enable(device);
+               err = __connman_device_enable(device);
        else
-               __connman_device_disable(device);
+               err = __connman_device_disable(device);
+
+       if (err < 0 && err != -EINPROGRESS)
+               return err;
 
        device->powered = powered;
        device->powered_pending = powered;
@@ -1017,22 +643,15 @@ int connman_device_set_powered(struct connman_device *device,
        else
                __connman_technology_disable_device(device);
 
-       if (device->offlinemode == TRUE && powered == TRUE) {
-               powered_changed(device);
+       if (device->offlinemode == TRUE && powered == TRUE)
                return connman_device_set_powered(device, FALSE);
-       }
-
-       if (device->registered == FALSE)
-               return 0;
-
-       powered_changed(device);
 
        if (powered == FALSE)
                return 0;
 
        reset_scan_trigger(device);
 
-       if (device->driver->scan)
+       if (device->driver && device->driver->scan)
                device->driver->scan(device);
 
        return 0;
@@ -1047,8 +666,6 @@ int __connman_device_set_blocked(struct connman_device *device,
 
        device->blocked = blocked;
 
-       blocked_changed(device);
-
        if (device->offlinemode == TRUE)
                return 0;
 
@@ -1062,6 +679,11 @@ int __connman_device_set_blocked(struct connman_device *device,
        return set_powered(device, powered);
 }
 
+connman_bool_t __connman_device_get_blocked(struct connman_device *device)
+{
+       return device->blocked;
+}
+
 int __connman_device_scan(struct connman_device *device)
 {
        if (!device->driver || !device->driver->scan)
@@ -1087,11 +709,12 @@ int __connman_device_enable_persistent(struct connman_device *device)
 
        err = __connman_device_enable(device);
        if (err == 0 || err == -EINPROGRESS) {
+               device->offlinemode = FALSE;
                if (__connman_profile_get_offlinemode() == TRUE) {
-                       device->offlinemode = FALSE;
                        __connman_profile_set_offlinemode(FALSE, FALSE);
-               }
 
+                       __connman_profile_save_default();
+               }
        }
 
        return err;
@@ -1175,13 +798,6 @@ void __connman_device_cleanup_networks(struct connman_device *device)
                                        remove_unavailable_network, NULL);
 }
 
-static void scanning_changed(struct connman_device *device)
-{
-       connman_dbus_property_changed_basic(device->element.path,
-                               CONNMAN_DEVICE_INTERFACE, "Scanning",
-                                       DBUS_TYPE_BOOLEAN, &device->scanning);
-}
-
 /**
  * connman_device_set_scanning:
  * @device: device structure
@@ -1202,8 +818,6 @@ int connman_device_set_scanning(struct connman_device *device,
 
        device->scanning = scanning;
 
-       scanning_changed(device);
-
        if (scanning == TRUE) {
                reset_scan_trigger(device);
 
@@ -1238,14 +852,6 @@ int connman_device_set_disconnected(struct connman_device *device,
 {
        DBG("device %p disconnected %d", device, disconnected);
 
-       switch (device->mode) {
-       case CONNMAN_DEVICE_MODE_UNKNOWN:
-               return -EINVAL;
-       case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
-       case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
-               break;
-       }
-
        if (device->disconnected == disconnected)
                return -EALREADY;
 
@@ -1313,6 +919,8 @@ const char *connman_device_get_string(struct connman_device *device,
                return device->name;
        else if (g_str_equal(key, "Node") == TRUE)
                return device->node;
+       else if (g_str_equal(key, "Interface") == TRUE)
+               return device->interface;
 
        return connman_element_get_string(&device->element, key);
 }
@@ -1330,6 +938,9 @@ static void set_offlinemode(struct connman_element *element, gpointer user_data)
 
        device->offlinemode = offlinemode;
 
+       if (device->blocked == TRUE)
+               return;
+
        powered = (offlinemode == TRUE) ? FALSE : TRUE;
 
        if (device->powered == powered)
@@ -1355,11 +966,17 @@ int __connman_device_set_offlinemode(connman_bool_t offlinemode)
 
 void __connman_device_increase_connections(struct connman_device *device)
 {
+       if (device == NULL)
+               return;
+
        device->connections++;
 }
 
 void __connman_device_decrease_connections(struct connman_device *device)
 {
+       if (device == NULL)
+               return;
+
        device->connections--;
 }
 
@@ -1381,14 +998,6 @@ int connman_device_add_network(struct connman_device *device,
        if (identifier == NULL)
                return -EINVAL;
 
-       switch (device->mode) {
-       case CONNMAN_DEVICE_MODE_UNKNOWN:
-               return -EINVAL;
-       case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
-       case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
-               break;
-       }
-
        __connman_network_set_device(network, device);
 
        err = connman_element_register((struct connman_element *) network,
@@ -1624,18 +1233,11 @@ static int device_load(struct connman_device *device)
                device->powered_persistent = powered;
        g_clear_error(&error);
 
-       switch (device->mode) {
-       case CONNMAN_DEVICE_MODE_UNKNOWN:
-               break;
-       case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
-       case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
-               val = g_key_file_get_integer(keyfile, identifier,
+       val = g_key_file_get_integer(keyfile, identifier,
                                                "ScanInterval", &error);
-               if (error == NULL && val > 0)
-                       device->scan_interval = val;
-               g_clear_error(&error);
-               break;
-       }
+       if (error == NULL)
+               device->scan_interval = val;
+       g_clear_error(&error);
 
 done:
        g_free(identifier);
@@ -1664,16 +1266,8 @@ static int device_save(struct connman_device *device)
        g_key_file_set_boolean(keyfile, identifier,
                                        "Powered", device->powered_persistent);
 
-       switch (device->mode) {
-       case CONNMAN_DEVICE_MODE_UNKNOWN:
-               break;
-       case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
-       case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
-               if (device->scan_interval > 0)
-                       g_key_file_set_integer(keyfile, identifier,
+       g_key_file_set_integer(keyfile, identifier,
                                        "ScanInterval", device->scan_interval);
-               break;
-       }
 
 done:
        g_free(identifier);
@@ -1694,8 +1288,6 @@ int __connman_device_init(void)
 {
        DBG("");
 
-       connection = connman_dbus_get_connection();
-
        if (connman_storage_register(&device_storage) < 0)
                connman_error("Failed to register device storage");
 
@@ -1709,6 +1301,4 @@ void __connman_device_cleanup(void)
        connman_driver_unregister(&device_driver);
 
        connman_storage_unregister(&device_storage);
-
-       dbus_connection_unref(connection);
 }