Toggle to flush BSS entries when interface is disabled

Add globally configurable option to not flush cache when interface goes
down.

Bug: 73301881
Test: Verify that the connected MAC randomization ~3 second delay problem is gone
Test: b/122700105 regression testing completed

Change-Id: Ic1ec89afad3cd244858b95dcfdf5729b6522702a
diff --git a/wpa_supplicant/config.c b/wpa_supplicant/config.c
index a8987a6..be6fc5d 100644
--- a/wpa_supplicant/config.c
+++ b/wpa_supplicant/config.c
@@ -4757,6 +4757,7 @@
 	{ INT(p2p_device_random_mac_addr), 0 },
 	{ STR(p2p_device_persistent_mac_addr), 0 },
 	{ INT(p2p_interface_random_mac_addr), 0 },
+	{ INT_RANGE(bss_no_flush_when_down, 0, 1), 0 },
 };
 
 #undef FUNC
diff --git a/wpa_supplicant/config.h b/wpa_supplicant/config.h
index ee20a93..e431b9c 100644
--- a/wpa_supplicant/config.h
+++ b/wpa_supplicant/config.h
@@ -1499,6 +1499,13 @@
 	 */
 	int p2p_interface_random_mac_addr;
 
+	/**
+	 * bss_no_flush_when_down - Whether to flush BSS entries when the interface is disabled
+	 *
+	 * 0 = Flush BSS entries when the interface becomes disabled (Default)
+	 * 1 = Do not flush BSS entries when the interface becomes disabled
+	 */
+	int bss_no_flush_when_down;
 };
 
 
diff --git a/wpa_supplicant/config_file.c b/wpa_supplicant/config_file.c
index 3a6dae5..1cdfbc2 100644
--- a/wpa_supplicant/config_file.c
+++ b/wpa_supplicant/config_file.c
@@ -1520,6 +1520,9 @@
 	if (config->p2p_interface_random_mac_addr)
 		fprintf(f, "p2p_interface_random_mac_addr=%d\n",
 			config->p2p_interface_random_mac_addr);
+	if (config->bss_no_flush_when_down)
+		fprintf(f, "bss_no_flush_when_down=%d\n",
+			config->bss_no_flush_when_down);
 
 }
 
diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c
index 29fb7ec..7eb25ea 100644
--- a/wpa_supplicant/events.c
+++ b/wpa_supplicant/events.c
@@ -4569,7 +4569,8 @@
 				wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
 		}
 		wpa_supplicant_mark_disassoc(wpa_s);
-		wpa_bss_flush(wpa_s);
+		if (!wpa_s->conf->bss_no_flush_when_down)
+			wpa_bss_flush(wpa_s);
 		radio_remove_works(wpa_s, NULL, 0);
 
 		wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);