From 15a1cf2d279ff7a2e8bf85e8a52cfec1cde0e525 Mon Sep 17 00:00:00 2001 From: Mohamed Abbas Date: Wed, 26 Jan 2011 00:31:54 +0100 Subject: [PATCH] wifi: Balance scanning states 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 | 1 + plugins/wifi.c | 16 ++++++++++------ src/device.c | 17 +++++++++++++++++ 3 files changed, 28 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..4f8643b 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,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 -- 2.7.4