P2P: get cached scan results on iface creation to avoid scan

This allows the p2p client to fast associate if the GO is already in the
scan cache without doing a full scan. This effectively reverts CL
14782089 and moves that optimization into core supplicant with the
intent of upstreaming.

Bug: 233925161
Test: Manual file transfer using Photos app, logs show that scan results
are updated directly from driver after interface creation and we fast
associate

09-08 03:26:19.538 D/wpa_supplicant( 2489): p2p-p2p0-0: Added interface p2p-p2p0-0
…
09-08 03:26:19.568 D/wpa_supplicant( 2489): nl80211: Received scan results (18 BSSes)
09-08 03:26:19.569 D/wpa_supplicant( 2489): p2p-p2p0-0: BSS: Start scan result update 1
09-08 03:26:19.569 D/wpa_supplicant( 2489): p2p-p2p0-0: BSS: Add new id 0 BSSID be:9b:d7:f0:a7:0e SSID 'DIRECT-30-16C8C7' freq 5180
…
09-08 03:26:19.569 D/wpa_supplicant( 2489): p2p-p2p0-0: Scan results matching the currently selected network
09-08 03:26:19.569 D/wpa_supplicant( 2489): p2p-p2p0-0: 0: be:9b:d7:f0:a7:0e freq=5180 level=-28 snr=75 est_throughput=390001
09-08 03:26:19.569 D/wpa_supplicant( 2489): p2p-p2p0-0: Selecting BSS from priority group 0
09-08 03:26:19.569 D/wpa_supplicant( 2489): p2p-p2p0-0: 0: be:9b:d7:f0:a7:0e ssid='DIRECT-30-16C8C7' wpa_ie_len=0 rsn_ie_len=20 caps=0x1031 level=-28 freq=5180  wps p2p
09-08 03:26:19.569 D/wpa_supplicant( 2489): p2p-p2p0-0:    selected based on RSN IE
09-08 03:26:19.569 D/wpa_supplicant( 2489): p2p-p2p0-0:    selected BSS be:9b:d7:f0:a7:0e ssid='DIRECT-30-16C8C7'
09-08 03:26:19.569 D/wpa_supplicant( 2489): p2p-p2p0-0: Considering connect request: reassociate: 1  selected: be:9b:d7:f0:a7:0e  bssid: 00:00:00:00:00:00  pending: 00:00:00:00:00:00  wpa_state: DISCONNECTED  ssid=0xb400007517a446e0  current_ssid=0xb400007517a446e0
09-08 03:26:19.569 D/wpa_supplicant( 2489): p2p-p2p0-0: Request association with be:9b:d7:f0:a7:0e
Test: wifi picker - preference - wifi direct, negotation still works

Change-Id: I73b2ab21bf5dcb6f21c6573139494ff3aefdcdc4
diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index 2e7cc4c..a8cab8d 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -6950,6 +6950,8 @@
 				 int freq, int force_scan)
 {
 	struct wpa_ssid *ssid;
+	int other_iface_found = 0;
+	struct wpa_supplicant *ifs;
 
 	wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 0);
 	if (wpa_s == NULL)
@@ -6994,6 +6996,26 @@
 	wpa_s->p2p_go_group_formation_completed = 0;
 	wpa_s->global->p2p_group_formation = wpa_s;
 
+	/*
+	 * Get latest scan results from driver in case cached scan results from
+	 * interfaces on the same wiphy allow us to skip the next scan by fast
+	 * associating. Also update the scan time to the most recent scan result
+	 * fetch time on the same radio so it reflects the actual time the last
+	 * scan result event occurred.
+	 */
+	wpa_supplicant_update_scan_results(wpa_s);
+	dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
+			 radio_list) {
+		if (ifs == wpa_s)
+			continue;
+		if (!other_iface_found || os_reltime_before(&wpa_s->last_scan,
+							    &ifs->last_scan)) {
+			other_iface_found = 1;
+			wpa_s->last_scan.sec = ifs->last_scan.sec;
+			wpa_s->last_scan.usec = ifs->last_scan.usec;
+		}
+	}
+
 	eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->p2pdev,
 			     NULL);
 	eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0,