diff --git a/src/device.c b/src/device.c index 4a47b8f4..dcd84d31 100644 --- a/src/device.c +++ b/src/device.c @@ -321,7 +321,8 @@ static bool bss_match(const void *a, const void *b) * Used when scan results were obtained; either from passive scan running * inside device.c or active scans running in other state machines, e.g. wsc.c */ -void device_set_scan_results(struct device *device, struct l_queue *bss_list) +void device_set_scan_results(struct device *device, struct l_queue *bss_list, + bool add_to_autoconnect) { struct network *network; const struct l_queue_entry *bss_entry; @@ -342,13 +343,8 @@ void device_set_scan_results(struct device *device, struct l_queue *bss_list) struct scan_bss *bss = bss_entry->data; struct network *network = add_seen_bss(device, bss); - if (!network) - continue; - - if (device->state != DEVICE_STATE_AUTOCONNECT) - continue; - - add_autoconnect_bss(device, network, bss); + if (network && add_to_autoconnect) + add_autoconnect_bss(device, network, bss); } if (device->connected_bss) { @@ -374,9 +370,6 @@ void device_set_scan_results(struct device *device, struct l_queue *bss_list) l_queue_destroy(device->old_bss_list, bss_free); device->old_bss_list = NULL; - - if (device->state == DEVICE_STATE_AUTOCONNECT) - device_autoconnect_next(device); } static bool new_scan_results(uint32_t wiphy_id, uint32_t ifindex, int err, @@ -384,6 +377,7 @@ static bool new_scan_results(uint32_t wiphy_id, uint32_t ifindex, int err, { struct device *device = userdata; struct l_dbus *dbus = dbus_get_bus(); + bool autoconnect = device->state == DEVICE_STATE_AUTOCONNECT; if (device->scanning) { device->scanning = false; @@ -398,7 +392,10 @@ static bool new_scan_results(uint32_t wiphy_id, uint32_t ifindex, int err, if (netdev_get_iftype(device->netdev) != NETDEV_IFTYPE_STATION) return false; - device_set_scan_results(device, bss_list); + device_set_scan_results(device, bss_list, autoconnect); + + if (autoconnect) + device_autoconnect_next(device); return true; } diff --git a/src/device.h b/src/device.h index 5201c783..d3c8de47 100644 --- a/src/device.h +++ b/src/device.h @@ -53,7 +53,8 @@ uint32_t device_add_state_watch(struct device *device, device_destroy_func_t destroy); bool device_remove_state_watch(struct device *device, uint32_t id); -void device_set_scan_results(struct device *device, struct l_queue *bss_list); +void device_set_scan_results(struct device *device, struct l_queue *bss_list, + bool add_to_autoconnect); struct network *device_network_find(struct device *device, const char *ssid, enum security security); diff --git a/src/wsc.c b/src/wsc.c index 75ce748d..c70aa22c 100644 --- a/src/wsc.c +++ b/src/wsc.c @@ -666,7 +666,7 @@ static bool push_button_scan_results(uint32_t wiphy_id, uint32_t ifindex, } wsc_cancel_scan(wsc); - device_set_scan_results(wsc->device, bss_list); + device_set_scan_results(wsc->device, bss_list, false); l_debug("Found AP to connect to: %s", util_address_to_string(target->addr)); @@ -813,7 +813,7 @@ static bool pin_scan_results(uint32_t wiphy_id, uint32_t ifindex, int err, } wsc_cancel_scan(wsc); - device_set_scan_results(wsc->device, bss_list); + device_set_scan_results(wsc->device, bss_list, false); l_debug("Found AP to connect to: %s", util_address_to_string(target->addr));