The proplem related unbalnced call to connman_device_set_scanning with
TRUE/FALSE this will end up leaving device->scanning in wrong state
causing autoconnect to be not called. This patch also add
connman_device_reset_scannind api to reset device->scanning to false
if scan for some reason did not start.
---
 include/device.h |    1 +
 plugins/wifi.c   |   16 ++++++++++------
 src/device.c     |   22 ++++++++++++++++++++++
 3 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/include/device.h b/include/device.h
index c5e005d..5cb34d7 100644
--- a/include/device.h
+++ b/include/device.h
@@ -72,6 +72,7 @@ int connman_device_set_powered(struct connman_device *device,
                                                connman_bool_t powered);
 int connman_device_set_scanning(struct connman_device *device,
                                                connman_bool_t scanning);
+void connman_device_reset_scanning(struct connman_device *device);
 
 int connman_device_set_disconnected(struct connman_device *device,
                                                connman_bool_t disconnected);
diff --git a/plugins/wifi.c b/plugins/wifi.c
index 040d2f9..b7685ee 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -253,17 +253,25 @@ static void scan_callback(int result, 
GSupplicantInterface *interface,
 
        DBG("result %d", result);
 
-       connman_device_set_scanning(device, FALSE);
+       if (result < 0)
+               connman_device_reset_scanning(device);
+       else
+               connman_device_set_scanning(device, FALSE);
 }
 
 static int wifi_scan(struct connman_device *device)
 {
        struct wifi_data *wifi = connman_device_get_data(device);
+       int ret;
 
        DBG("device %p %p", device, wifi->interface);
 
-       return g_supplicant_interface_scan(wifi->interface, scan_callback,
+       ret = g_supplicant_interface_scan(wifi->interface, scan_callback,
                                                                device);
+       if (ret == 0)
+               connman_device_set_scanning(device, TRUE);
+
+       return ret;
 }
 
 static struct connman_device_driver wifi_ng_driver = {
@@ -366,7 +374,6 @@ static void interface_state(GSupplicantInterface *interface)
 
        switch (state) {
        case G_SUPPLICANT_STATE_SCANNING:
-               connman_device_set_scanning(device, TRUE);
                break;
 
        case G_SUPPLICANT_STATE_AUTHENTICATING:
@@ -440,9 +447,6 @@ static void scan_started(GSupplicantInterface *interface)
 
        if (wifi == NULL)
                return;
-
-       if (wifi->device)
-               connman_device_set_scanning(wifi->device, TRUE);
 }
 
 static void scan_finished(GSupplicantInterface *interface)
diff --git a/src/device.c b/src/device.c
index 6eef940..0e2f36c 100644
--- a/src/device.c
+++ b/src/device.c
@@ -784,6 +784,14 @@ int __connman_device_disconnect(struct connman_device 
*device)
        return 0;
 }
 
+static void mark_network_available(gpointer key, gpointer value,
+                                                        gpointer user_data)
+{
+       struct connman_network *network = value;
+
+       connman_network_set_available(network, TRUE);
+}
+
 static void mark_network_unavailable(gpointer key, gpointer value,
                                                        gpointer user_data)
 {
@@ -820,6 +828,20 @@ connman_bool_t __connman_device_scanning(struct 
connman_device *device)
        return device->scanning;
 }
 
+/* scan failed just reset device->scanning without calling
+ * __connman_device_cleanup_networks since this will cause
+ * al network to be lost since there are no scan result.
+ */
+void connman_device_reset_scanning(struct connman_device *device)
+{
+
+       device->scanning = FALSE;
+
+       g_hash_table_foreach(device->networks,
+                               mark_network_available, NULL);
+
+}
+
 /**
  * connman_device_set_scanning:
  * @device: device structure
-- 
1.7.2.3

_______________________________________________
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman

Reply via email to