From 4ea6a47133c00abfbf363343d0d07ae0e7dd5130 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Tue, 31 Dec 2013 09:38:55 +0200 Subject: [PATCH] nl80211: Prefer newer scan result over older during duplicate removal Previously, it was possible for bss_info_handler() to end up dropping a newer scan result entry if there were two entries with the same BSSID and SSID (i.e., only frequency was different) and we were not associated with either. This could happen, e.g., in some P2P use cases where device discovery may happen on different channels. Fix this by checking the age of the scan entries as well to prefer the most recent response. Signed-hostap: Jouni Malinen --- src/drivers/driver_nl80211.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c index fd4059c83..58d6fd620 100644 --- a/src/drivers/driver_nl80211.c +++ b/src/drivers/driver_nl80211.c @@ -4996,7 +4996,8 @@ static int bss_info_handler(struct nl_msg *msg, void *arg) * BSSID,SSID pair is seen on multiple channels. wpa_supplicant does * not use frequency as a separate key in the BSS table, so filter out * duplicated entries. Prefer associated BSS entry in such a case in - * order to get the correct frequency into the BSS table. + * order to get the correct frequency into the BSS table. Similarly, + * prefer newer entries over older. */ for (i = 0; i < res->num; i++) { const u8 *s1, *s2; @@ -5014,8 +5015,9 @@ static int bss_info_handler(struct nl_msg *msg, void *arg) wpa_printf(MSG_DEBUG, "nl80211: Remove duplicated scan result " "for " MACSTR, MAC2STR(r->bssid)); - if ((r->flags & WPA_SCAN_ASSOCIATED) && - !(res->res[i]->flags & WPA_SCAN_ASSOCIATED)) { + if (((r->flags & WPA_SCAN_ASSOCIATED) && + !(res->res[i]->flags & WPA_SCAN_ASSOCIATED)) || + r->age < res->res[i]->age) { os_free(res->res[i]); res->res[i] = r; } else