device: Remove redundant connection numbers check
[framework/connectivity/connman.git] / src / device.c
index cdd9118..b830688 100644 (file)
@@ -221,11 +221,8 @@ static gboolean device_pending_reset(gpointer user_data)
        DBG("device %p", device);
 
        /* Power request timedout, reset power pending state. */
-       if (device->pending_timeout > 0) {
-               g_source_remove(device->pending_timeout);
-               device->pending_timeout = 0;
-               device->powered_pending = PENDING_NONE;
-       }
+       device->pending_timeout = 0;
+       device->powered_pending = PENDING_NONE;
 
        return FALSE;
 }
@@ -297,6 +294,7 @@ int __connman_device_disable(struct connman_device *device)
        if (device->powered_pending == PENDING_NONE && device->powered == FALSE)
                return -EALREADY;
 
+       device->powered_pending = PENDING_DISABLE;
        device->reconnect = FALSE;
 
        clear_scan_trigger(device);
@@ -663,9 +661,12 @@ int connman_device_set_powered(struct connman_device *device,
        if (device->powered == powered)
                return -EALREADY;
 
-       /* Reset pending request */
-       g_source_remove(device->pending_timeout);
-       device->pending_timeout = 0;
+       if (device->pending_timeout) {
+               /* Reset pending request */
+               g_source_remove(device->pending_timeout);
+               device->pending_timeout = 0;
+       }
+
        device->powered_pending = PENDING_NONE;
 
        device->powered = powered;
@@ -687,7 +688,9 @@ int connman_device_set_powered(struct connman_device *device,
 
        reset_scan_trigger(device);
 
-       if (device->driver && device->driver->scan)
+       if (device->driver && device->driver->scan_fast)
+               device->driver->scan_fast(device);
+       else if (device->driver && device->driver->scan)
                device->driver->scan(device);
 
        return 0;
@@ -826,9 +829,6 @@ int connman_device_set_scanning(struct connman_device *device,
 
        __connman_device_cleanup_networks(device);
 
-       if (device->connections > 0)
-               return 0;
-
        __connman_service_auto_connect();
 
        return 0;
@@ -1062,7 +1062,13 @@ static gboolean match_driver(struct connman_device *device,
        return FALSE;
 }
 
-static int device_probe(struct connman_device *device)
+/**
+ * connman_device_register:
+ * @device: device structure
+ *
+ * Register device with the system
+ */
+int connman_device_register(struct connman_device *device)
 {
        GSList *list;
 
@@ -1091,27 +1097,6 @@ static int device_probe(struct connman_device *device)
        return __connman_technology_add_device(device);
 }
 
-static void device_remove(struct connman_device *device)
-{
-       DBG("device %p name %s", device, device->name);
-
-       if (device->driver == NULL)
-               return;
-
-       remove_device(device);
-}
-
-/**
- * connman_device_register:
- * @device: device structure
- *
- * Register device with the system
- */
-int connman_device_register(struct connman_device *device)
-{
-       return device_probe(device);
-}
-
 /**
  * connman_device_unregister:
  * @device: device structure
@@ -1120,7 +1105,12 @@ int connman_device_register(struct connman_device *device)
  */
 void connman_device_unregister(struct connman_device *device)
 {
-       device_remove(device);
+       DBG("device %p name %s", device, device->name);
+
+       if (device->driver == NULL)
+               return;
+
+       remove_device(device);
 }
 
 /**