wifi: Balance scanning states
authorMohamed Abbas <mabbas@linux.intel.com>
Tue, 25 Jan 2011 23:31:54 +0000 (00:31 +0100)
committerSamuel Ortiz <sameo@linux.intel.com>
Tue, 25 Jan 2011 23:31:54 +0000 (00:31 +0100)
By setting the scan state to TRUE from wifi_scan() and setting it back
to FALSE in the callback, the wifi device scanning state is consistent.

Fixes BMC#12104

include/device.h
plugins/wifi.c
src/device.c

index c5e005d..5cb34d7 100644 (file)
@@ -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);
index 040d2f9..b7685ee 100644 (file)
@@ -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)
index 6eef940..4f8643b 100644 (file)
@@ -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,15 @@ connman_bool_t __connman_device_scanning(struct connman_device *device)
        return device->scanning;
 }
 
+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