From: Hu Wang Date: Wed, 11 Sep 2019 03:04:40 +0000 (+0800) Subject: P2P: Use latest BSS entry if multiple P2P Device Addr matches found X-Git-Tag: hostap_2_10~2371 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8214b45ba01ea629382b7c0339451246fc19dfa0;p=thirdparty%2Fhostap.git P2P: Use latest BSS entry if multiple P2P Device Addr matches found 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 --- diff --git a/wpa_supplicant/bss.c b/wpa_supplicant/bss.c index 441529cb0..943a34081 100644 --- a/wpa_supplicant/bss.c +++ b/wpa_supplicant/bss.c @@ -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 */