+ if (scanning == TRUE) {
+ if (device->scan_timeout > 0) {
+ g_source_remove(device->scan_timeout);
+ device->scan_timeout = 0;
+ }
+
+ if (device->scan_interval > 0) {
+ guint interval = device->scan_interval;
+ device->scan_timeout = g_timeout_add_seconds(interval,
+ device_scan_trigger, device);
+ }
+
+ g_hash_table_foreach(device->networks,
+ mark_network_unavailable, NULL);
+ return 0;
+ }
+
+ g_hash_table_foreach_remove(device->networks,
+ remove_unavailable_network, NULL);
+
+ if (device->connections > 0)
+ return 0;
+
+ if (device->disconnected == TRUE)
+ return 0;
+
+ if (device->policy != CONNMAN_DEVICE_POLICY_AUTO)
+ return 0;
+
+ connect_known_network(device);
+
+ return 0;
+}
+
+/**
+ * connman_device_set_disconnected:
+ * @device: device structure
+ * @disconnected: disconnected state
+ *
+ * Change disconnected state of device (only for device with networks)
+ */
+int connman_device_set_disconnected(struct connman_device *device,
+ connman_bool_t disconnected)
+{
+ DBG("driver %p disconnected %d", device, disconnected);
+
+ switch (device->mode) {
+ case CONNMAN_DEVICE_MODE_UNKNOWN:
+ case CONNMAN_DEVICE_MODE_TRANSPORT_IP:
+ return -EINVAL;
+ case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
+ case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
+ break;
+ }
+
+ if (device->disconnected == disconnected)
+ return -EALREADY;
+
+ device->disconnected = disconnected;
+
+ return 0;
+}
+
+/**
+ * connman_device_set_string:
+ * @device: device structure
+ * @key: unique identifier
+ * @value: string value
+ *
+ * Set string value for specific key
+ */
+int connman_device_set_string(struct connman_device *device,
+ const char *key, const char *value)
+{
+ DBG("device %p key %s value %s", device, key, value);
+
+ if (g_str_equal(key, "Address") == TRUE) {
+ g_free(device->address);
+ device->address = g_strdup(value);
+ } else if (g_str_equal(key, "Name") == TRUE) {
+ g_free(device->name);
+ device->name = g_strdup(value);
+ } else if (g_str_equal(key, "Node") == TRUE) {
+ g_free(device->node);
+ device->node = g_strdup(value);
+ }
+
+ return connman_element_set_string(&device->element, key, value);
+}
+
+/**
+ * connman_device_get_string:
+ * @device: device structure
+ * @key: unique identifier
+ *
+ * Get string value for specific key
+ */
+const char *connman_device_get_string(struct connman_device *device,
+ const char *key)
+{
+ DBG("device %p key %s", device, key);
+
+ if (g_str_equal(key, "Address") == TRUE)
+ return device->address;
+ else if (g_str_equal(key, "Name") == TRUE)
+ return device->name;
+ else if (g_str_equal(key, "Node") == TRUE)
+ return device->node;
+
+ return connman_element_get_string(&device->element, key);
+}
+
+static void set_offlinemode(struct connman_element *element, gpointer user_data)
+{
+ struct connman_device *device = element->device;
+ connman_bool_t offlinemode = GPOINTER_TO_UINT(user_data);
+ connman_bool_t powered;
+
+ DBG("element %p name %s", element, element->name);
+
+ if (device == NULL)
+ return;
+
+ powered = (offlinemode == TRUE) ? FALSE : TRUE;
+
+ if (device->powered == powered)
+ return;
+
+ set_powered(device, powered);
+}
+
+int __connman_device_set_offlinemode(connman_bool_t offlinemode)
+{
+ DBG("offlinmode %d", offlinemode);
+
+ __connman_element_foreach(NULL, CONNMAN_ELEMENT_TYPE_DEVICE,
+ set_offlinemode, GUINT_TO_POINTER(offlinemode));
+
+ __connman_notifier_offline_mode(offlinemode);
+