Fix device power state changes tracking with RFKILL notifications
authorMarcel Holtmann <marcel@holtmann.org>
Thu, 23 Jul 2009 07:53:18 +0000 (09:53 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 23 Jul 2009 07:53:18 +0000 (09:53 +0200)
src/device.c

index 0e94999..53ff6f4 100644 (file)
@@ -40,6 +40,7 @@ struct connman_device {
        connman_bool_t offlinemode;
        connman_bool_t blocked;
        connman_bool_t powered;
+       connman_bool_t powered_pending;
        connman_bool_t powered_persistent;
        connman_bool_t carrier;
        connman_bool_t scanning;
@@ -301,9 +302,11 @@ static int set_powered(struct connman_device *device, connman_bool_t powered)
 
        DBG("device %p powered %d", device, powered);
 
-       if (device->powered == powered)
+       if (device->powered_pending == powered)
                return -EALREADY;
 
+       device->powered_pending = powered;
+
        if (!driver)
                return -EINVAL;
 
@@ -1175,6 +1178,7 @@ int connman_device_set_powered(struct connman_device *device,
                return -EALREADY;
 
        device->powered = powered;
+       device->powered_pending = powered;
 
        type = __connman_device_get_service_type(device);
 
@@ -1206,9 +1210,6 @@ int __connman_device_set_blocked(struct connman_device *device,
 
        DBG("device %p blocked %d", device, blocked);
 
-       if (device->blocked == blocked)
-               return -EALREADY;
-
        device->blocked = blocked;
 
        if (device->offlinemode == TRUE)
@@ -1272,9 +1273,11 @@ int __connman_device_enable(struct connman_device *device)
        if (!device->driver || !device->driver->enable)
                return -EOPNOTSUPP;
 
-       if (device->powered == TRUE)
+       if (device->powered_pending == TRUE)
                return -EALREADY;
 
+       device->powered_pending = TRUE;
+
        err = device->driver->enable(device);
        if (err < 0)
                return err;
@@ -1311,6 +1314,11 @@ int __connman_device_disable(struct connman_device *device)
        if (device->powered == FALSE)
                return -ENOLINK;
 
+       if (device->powered_pending == FALSE)
+               return -EALREADY;
+
+       device->powered_pending = FALSE;
+
        clear_scan_trigger(device);
 
        g_hash_table_remove_all(device->networks);