- device->reconnect = FALSE;
-
- clear_scan_trigger(device);
-
- g_hash_table_remove_all(device->networks);
-
- err = device->driver->disable(device);
- if (err < 0) {
- if (err == -EINPROGRESS)
- device->powered_pending = FALSE;
- return err;
- }
-
- device->powered_pending = FALSE;
- device->powered = FALSE;
-
- __connman_technology_disable_device(device);
-
- return 0;
-}
-
-static int set_powered(struct connman_device *device, connman_bool_t powered)
-{
- DBG("device %p powered %d", device, powered);
-
- if (powered == TRUE)
- return __connman_device_enable(device);
- else
- 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);
-
- 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);
-}