From 7a3e397e2cc0c275f81eec419fa144ad258b4b87 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 24 Dec 2008 11:42:18 +0100 Subject: Add support for device power functions --- include/device.h | 2 ++ src/device.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/include/device.h b/include/device.h index 1645a085..4985f6e8 100644 --- a/include/device.h +++ b/include/device.h @@ -95,6 +95,8 @@ struct connman_device_driver { int priority; int (*probe) (struct connman_device *device); void (*remove) (struct connman_device *device); + int (*enable) (struct connman_device *device); + int (*disable) (struct connman_device *device); int (*scan) (struct connman_device *device); }; diff --git a/src/device.c b/src/device.c index 5c95d686..d39f18c8 100644 --- a/src/device.c +++ b/src/device.c @@ -28,6 +28,31 @@ #include "connman.h" +static int set_powered(struct connman_device *device, gboolean powered) +{ + struct connman_device_driver *driver = device->driver; + int err; + + DBG("device %p powered %d", device, powered); + + if (!driver) + return -EINVAL; + + if (powered == TRUE) { + if (driver->enable) + err = driver->enable(device); + else + err = -EINVAL; + } else { + if (driver->disable) + err = driver->disable(device); + else + err = -EINVAL; + } + + return err; +} + static DBusMessage *get_properties(DBusConnection *conn, DBusMessage *msg, void *data) { @@ -59,7 +84,7 @@ static DBusMessage *get_properties(DBusConnection *conn, static DBusMessage *set_property(DBusConnection *conn, DBusMessage *msg, void *data) { - struct connman_element *element = data; + struct connman_device *device = data; DBusMessageIter iter, value; const char *name; @@ -75,7 +100,21 @@ static DBusMessage *set_property(DBusConnection *conn, if (__connman_security_check_privileges(msg) < 0) return __connman_error_permission_denied(msg); - __connman_element_store(element); + if (g_str_equal(name, "Powered") == TRUE) { + gboolean powered; + int err; + + dbus_message_iter_get_basic(&value, &powered); + + if (device->powered == powered) + return __connman_error_invalid_arguments(msg); + + err = set_powered(device, powered); + if (err < 0 && err != -EINPROGRESS) + return __connman_error_failed(msg); + } + + __connman_element_store(device->element); return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); } -- cgit v1.2.3