qcacld-2.0: Update MAC addresses only once

Propagation from qcacld-3.0 to qcacld-2.0

Currently MAC addresses are getting updated at the time of rx_ready
indication and at the time of initialization.

First time addressses are updated in when first rx_ready indication
comes in hdd_update_tgt_cfg api.
At the time of initialization mac addresses are getting updated
from platform driver or MAC.bin. If platform driver and MAC.bin
doesn't provide the addresses then addresses updated in
hdd_update_tgt_cfg are used.
If platform driver or MAC.bin provides MAC addresses then those
addresses must be used. Currently on every rx_ready indication
MAC addresses are updated, losing the addresses provided by
platform driver or MAC.bin.

Move the complete address management logic to
hdd_initialize_mac_address api so the MAC addresses will be
updated only once.
Change-Id: I64910063e51c08916c9835e547ef1d7b58de33e6
CRs-Fixed: 2190513
diff --git a/CORE/HDD/inc/wlan_hdd_main.h b/CORE/HDD/inc/wlan_hdd_main.h
index ad7121a..82e8d7d 100644
--- a/CORE/HDD/inc/wlan_hdd_main.h
+++ b/CORE/HDD/inc/wlan_hdd_main.h
@@ -2133,6 +2133,7 @@
 #endif
     /* flag to show whether moniotr mode is enabled */
     bool is_mon_enable;
+    v_MACADDR_t hw_macaddr;
 };
 
 /*---------------------------------------------------------------------------
diff --git a/CORE/HDD/src/wlan_hdd_main.c b/CORE/HDD/src/wlan_hdd_main.c
index 631f435..066046c 100644
--- a/CORE/HDD/src/wlan_hdd_main.c
+++ b/CORE/HDD/src/wlan_hdd_main.c
@@ -9395,13 +9395,12 @@
 
     if (!vos_is_macaddr_zero(&cfg->hw_macaddr))
     {
-        hdd_update_macaddr(hdd_ctx->cfg_ini, cfg->hw_macaddr);
+        vos_mem_copy(&hdd_ctx->hw_macaddr, &cfg->hw_macaddr,
+                     VOS_MAC_ADDR_SIZE);
     }
     else {
         hddLog(VOS_TRACE_LEVEL_ERROR,
-               "%s: Invalid MAC passed from target, using MAC from ini file"
-               MAC_ADDRESS_STR, __func__,
-               MAC_ADDR_ARRAY(hdd_ctx->cfg_ini->intfMacAddr[0].bytes));
+               "%s: HW MAC is zero", __func__);
     }
 
     hdd_ctx->target_fw_version = cfg->target_fw_version;
@@ -16199,6 +16198,22 @@
 			      WLAN_MAC_FILE, status);
 			return -EIO;
 		}
+		return 0;
+	}
+
+	if (!vos_is_macaddr_zero(&hdd_ctx->hw_macaddr)) {
+		hdd_update_macaddr(hdd_ctx->cfg_ini, hdd_ctx->hw_macaddr);
+	} else {
+		tSirMacAddr customMacAddr;
+
+		hddLog(VOS_TRACE_LEVEL_ERROR,
+		       "%s: Invalid MAC passed from target, using MAC from ini"
+		       MAC_ADDRESS_STR, __func__,
+		       MAC_ADDR_ARRAY(hdd_ctx->cfg_ini->intfMacAddr[0].bytes));
+		vos_mem_copy(&customMacAddr,
+			     &hdd_ctx->cfg_ini->intfMacAddr[0].bytes,
+			     VOS_MAC_ADDR_SIZE);
+			     sme_SetCustomMacAddr(customMacAddr);
 	}
 	return 0;
 }