]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
P2P: Use latest BSS entry if multiple P2P Device Addr matches found
authorHu Wang <huw@codeaurora.org>
Wed, 11 Sep 2019 03:04:40 +0000 (11:04 +0800)
committerJouni Malinen <j@w1.fi>
Fri, 13 Sep 2019 13:22:05 +0000 (16:22 +0300)
If an AP (P2P GO) has changed its operating channel or SSID recently,
the BSS table may have multiple entries for the same BSSID.

Commit 702621e6dd35 ('WPS: Use latest updated BSS entry if multiple
BSSID matches found') fetches latest updated BSS entry based on
BSSID. Do the same when fetching an entry based on the P2P Device
Address.

Signed-off-by: Jouni Malinen <jouni@codeaurora.org>
wpa_supplicant/bss.c

index 441529cb0fd536fdf7cce20731d3bb8cdae2f6fd..943a34081640d6f88142e052aaa5cf083a755177 100644 (file)
@@ -1038,23 +1038,30 @@ struct wpa_bss * wpa_bss_get_bssid_latest(struct wpa_supplicant *wpa_s,
 
 #ifdef CONFIG_P2P
 /**
- * wpa_bss_get_p2p_dev_addr - Fetch a BSS table entry based on P2P Device Addr
+ * wpa_bss_get_p2p_dev_addr - Fetch the latest BSS table entry based on P2P Device Addr
  * @wpa_s: Pointer to wpa_supplicant data
  * @dev_addr: P2P Device Address of the GO
  * Returns: Pointer to the BSS entry or %NULL if not found
+ *
+ * This function tries to find the entry that has the most recent update. This
+ * can help in finding the correct entry in cases where the SSID of the P2P
+ * Device may have changed recently.
  */
 struct wpa_bss * wpa_bss_get_p2p_dev_addr(struct wpa_supplicant *wpa_s,
                                          const u8 *dev_addr)
 {
-       struct wpa_bss *bss;
+       struct wpa_bss *bss, *found = NULL;
        dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss, list) {
                u8 addr[ETH_ALEN];
                if (p2p_parse_dev_addr((const u8 *) (bss + 1), bss->ie_len,
-                                      addr) == 0 &&
-                   os_memcmp(addr, dev_addr, ETH_ALEN) == 0)
-                       return bss;
+                                      addr) != 0 ||
+                   os_memcmp(addr, dev_addr, ETH_ALEN) != 0)
+                       continue;
+               if (!found ||
+                   os_reltime_before(&found->last_update, &bss->last_update))
+                       found = bss;
        }
-       return NULL;
+       return found;
 }
 #endif /* CONFIG_P2P */