Add update of mac address to supplicant

This commit adds the update of the mac address to supplicant
when the feature UPDATE_SUPPLICANT_MAC_ADDR is enabled

Bug: 162713738
Test: Verify device can connect to a secure network with
      mac randomizatoin enabled
Change-Id: I309a77e0912981d52a7fd8676c8396d6c0a29235
diff --git a/wpa_supplicant/Android.mk b/wpa_supplicant/Android.mk
index 5cc9c65..b440497 100644
--- a/wpa_supplicant/Android.mk
+++ b/wpa_supplicant/Android.mk
@@ -16,6 +16,10 @@
   CONFIG_DRIVER_NL80211_QCA=y
 endif
 
+ifeq ($(WIFI_UPDATE_SUPPLICANT_MAC_ADDR), enabled)
+  FEATURE_UPDATE_STA_MAC_ADDR=y
+endif
+
 include $(LOCAL_PATH)/android.config
 
 # To ignore possible wrong network configurations
diff --git a/wpa_supplicant/hidl/1.4/sta_network.cpp b/wpa_supplicant/hidl/1.4/sta_network.cpp
index fa4edc1..d5c7f87 100644
--- a/wpa_supplicant/hidl/1.4/sta_network.cpp
+++ b/wpa_supplicant/hidl/1.4/sta_network.cpp
@@ -1863,6 +1863,11 @@
 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
 	wpa_s->scan_min_time.sec = 0;
 	wpa_s->scan_min_time.usec = 0;
+#ifdef FEATURE_UPDATE_STA_MAC_ADDR
+	// Make sure that the supplicant is updated to the latest
+	// MAC address, which might have changed due to MAC randomization.
+	wpa_supplicant_update_mac_addr(wpa_s);
+#endif
 	wpa_supplicant_select_network(wpa_s, wpa_ssid);
 	return {SupplicantStatusCode::SUCCESS, ""};
 }