From: Patrik Flykt <[email protected]>

Add checks for the device being powered and the device driver
implementing a scan function before calling reset_scan_trigger()
or force_scan_trigger().
---
 include/device.h |    2 +-
 src/device.c     |   44 ++++++++++++++++++++++++++++++--------------
 2 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/include/device.h b/include/device.h
index 54beb65..b39bd2a 100644
--- a/include/device.h
+++ b/include/device.h
@@ -101,7 +101,7 @@ int connman_device_remove_network(struct connman_device 
*device,
                                        struct connman_network *network);
 void connman_device_remove_all_networks(struct connman_device *device);
 
-void connman_device_schedule_scan(struct connman_device *device);
+int connman_device_schedule_scan(struct connman_device *device);
 
 int connman_device_register(struct connman_device *device);
 void connman_device_unregister(struct connman_device *device);
diff --git a/src/device.c b/src/device.c
index e7568f6..3e003b0 100644
--- a/src/device.c
+++ b/src/device.c
@@ -77,13 +77,13 @@ static gboolean device_scan_trigger(gpointer user_data)
 
        DBG("device %p", device);
 
-       if (device->driver == NULL) {
+       if (device->driver == NULL || device->driver->scan == NULL) {
+               connman_warn("Device scan not properly stopped");
                device->scan_timeout = 0;
                return FALSE;
        }
 
-       if (device->driver->scan)
-               device->driver->scan(device);
+       device->driver->scan(device);
 
        return TRUE;
 }
@@ -137,9 +137,17 @@ static void force_scan_trigger(struct connman_device 
*device)
                                        device_scan_trigger, device);
 }
 
-void connman_device_schedule_scan(struct connman_device *device)
+int connman_device_schedule_scan(struct connman_device *device)
 {
+       if (device->driver == NULL || device->driver->scan == NULL)
+               return -EOPNOTSUPP;
+
+       if (device->powered == FALSE)
+               return -ENOLINK;
+
        reset_scan_trigger(device);
+
+       return 0;
 }
 
 static const char *type2description(enum connman_device_type type)
@@ -704,25 +712,24 @@ int connman_device_set_powered(struct connman_device 
*device,
        connman_device_set_disconnected(device, FALSE);
        device->scanning = FALSE;
 
-       reset_scan_trigger(device);
-
-       if (device->driver && device->driver->scan_fast)
+       if (device->driver && device->driver->scan_fast) {
                device->driver->scan_fast(device);
-       else if (device->driver && device->driver->scan)
+               reset_scan_trigger(device);
+       } else if (device->driver && device->driver->scan) {
                device->driver->scan(device);
+               reset_scan_trigger(device);
+       }
 
        return 0;
 }
 
 static int device_scan(struct connman_device *device)
 {
-       if (!device->driver || !device->driver->scan)
-               return -EOPNOTSUPP;
-
-       if (device->powered == FALSE)
-               return -ENOLINK;
+       int ret;
 
-       reset_scan_trigger(device);
+       ret = connman_device_schedule_scan(device);
+       if (ret < 0)
+               return ret;
 
        return device->driver->scan(device);
 }
@@ -834,6 +841,9 @@ int connman_device_set_scanning(struct connman_device 
*device,
        if (device->scanning == scanning)
                return -EALREADY;
 
+       if (device->powered == FALSE)
+               return -ENOLINK;
+
        device->scanning = scanning;
 
        if (scanning == TRUE) {
@@ -875,6 +885,12 @@ int connman_device_set_disconnected(struct connman_device 
*device,
 
        if (disconnected == TRUE)
        {
+               if (device->driver == NULL || device->driver->scan == NULL)
+                       return 0;
+
+               if (device->powered == FALSE)
+                       return 0;
+
                force_scan_trigger(device);
                device->backoff_interval = SCAN_INITIAL_DELAY;
        }
-- 
1.7.9.1

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to