wlan: Update gEnableMacAddrSpoof ini parameter

Added support for mac spoofing of firmware initiated scans only.

gEnableMacAddrSpoof can now take the following values:
0 -> disable mac spoofing
1 -> Enable mac spoofing for host and firmware scans
2 -> Enable mac spoofing for firmware scans only (disabled in host scans)

Change-Id: Ieeb407cb6c08695a73fafe9bef08813b86ac4a0a
CRs-Fixed: 930151
diff --git a/CORE/HDD/inc/wlan_hdd_cfg.h b/CORE/HDD/inc/wlan_hdd_cfg.h
index 2a4dfa4..fac1dca 100644
--- a/CORE/HDD/inc/wlan_hdd_cfg.h
+++ b/CORE/HDD/inc/wlan_hdd_cfg.h
@@ -2359,10 +2359,15 @@
 #define CFG_ENABLE_DEAUTH_BEFORE_CONNECTION_MAX              (1)
 #define CFG_ENABLE_DEAUTH_BEFORE_CONNECTION_DEFAULT          (0)
 
+/* gEnableMacAddrSpoof = 0 => disable mac spoofing
+                       = 1 => enable mac spoofing in both HOST and FW
+                       = 2 => enable mac spoofing in FW and
+                              disable mac spoofing in HOST
+ */
 #define CFG_ENABLE_MAC_ADDR_SPOOFING                         "gEnableMacAddrSpoof"
 #define CFG_ENABLE_MAC_ADDR_SPOOFING_MIN                     (0)
-#define CFG_ENABLE_MAC_ADDR_SPOOFING_MAX                     (1)
-#define CFG_ENABLE_MAC_ADDR_SPOOFING_DEFAULT                 (1)
+#define CFG_ENABLE_MAC_ADDR_SPOOFING_MAX                     (2)
+#define CFG_ENABLE_MAC_ADDR_SPOOFING_DEFAULT                 (0)
 
 /* Disable Mac Spoof for p2p Scan */
 #define CFG_DISABLE_P2P_MAC_ADDR_SPOOFING              "gDisableP2PMacAddrSpoof"
@@ -3057,7 +3062,7 @@
 #endif
    v_U32_t                     deferImpsTime;
    v_BOOL_t                    sendDeauthBeforeCon;
-   v_BOOL_t                    enableMacSpoofing;
+   v_U8_t                      enableMacSpoofing;
    v_BOOL_t                    disableP2PMacSpoofing;
    v_BOOL_t                    enableFatalEvent;
    v_BOOL_t                    enableMgmtLogging;
diff --git a/CORE/HDD/src/wlan_hdd_cfg.c b/CORE/HDD/src/wlan_hdd_cfg.c
index b324823..fae3dd1 100644
--- a/CORE/HDD/src/wlan_hdd_cfg.c
+++ b/CORE/HDD/src/wlan_hdd_cfg.c
@@ -5454,6 +5454,15 @@
       fStatus = FALSE;
       hddLog(LOGE, "Could not pass on WNI_CFG_ACTIVE_PASSIVE_CON ");
    }
+
+   if (ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_ENABLE_MAC_ADDR_SPOOFING,
+                    pConfig->enableMacSpoofing, NULL,
+                    eANI_BOOLEAN_FALSE) == eHAL_STATUS_FAILURE)
+   {
+      fStatus = FALSE;
+      hddLog(LOGE, "Could not pass on WNI_CFG_ENABLE_MAC_ADDR_SPOOFING ");
+   }
+
    return fStatus;
 }
 
diff --git a/CORE/HDD/src/wlan_hdd_cfg80211.c b/CORE/HDD/src/wlan_hdd_cfg80211.c
index 9c5642c..1d43e6d 100644
--- a/CORE/HDD/src/wlan_hdd_cfg80211.c
+++ b/CORE/HDD/src/wlan_hdd_cfg80211.c
@@ -173,6 +173,14 @@
  */
 #define EXTTDLS_EVENT_BUF_SIZE 4096
 
+/*
+ * Values for Mac spoofing feature
+ *
+ */
+#define MAC_ADDR_SPOOFING_FW_HOST_DISABLE           0
+#define MAC_ADDR_SPOOFING_FW_HOST_ENABLE            1
+#define MAC_ADDR_SPOOFING_FW_ENABLE_HOST_DISABLE    2
+
 static const u32 hdd_cipher_suites[] =
 {
     WLAN_CIPHER_SUITE_WEP40,
@@ -5053,7 +5061,7 @@
     if (0 != wlan_hdd_validate_context(pHddCtx)){
         return -EINVAL;
     }
-    if (FALSE == pHddCtx->cfg_ini->enableMacSpoofing) {
+    if (0 == pHddCtx->cfg_ini->enableMacSpoofing) {
         hddLog(VOS_TRACE_LEVEL_INFO, FL("MAC_SPOOFED_SCAN disabled in ini"));
         return -ENOTSUPP;
     }
@@ -12617,7 +12625,9 @@
     cfg80211_scan_done(req, aborted);
     complete(&pScanInfo->abortscan_event_var);
 
-    if (pHddCtx->spoofMacAddr.isEnabled || pHddCtx->spoofMacAddr.isReqDeferred) {
+    if ((pHddCtx->cfg_ini->enableMacSpoofing == MAC_ADDR_SPOOFING_FW_HOST_ENABLE
+       ) && (pHddCtx->spoofMacAddr.isEnabled
+         ||  pHddCtx->spoofMacAddr.isReqDeferred)) {
         /* Generate new random mac addr for next scan */
         hddLog(VOS_TRACE_LEVEL_INFO, "scan completed - generate new spoof mac addr");
         hdd_processSpoofMacAddrRequest(pHddCtx);
@@ -13183,7 +13193,8 @@
            scanRequest.minChnTime, scanRequest.maxChnTime,
            scanRequest.p2pSearch, scanRequest.skipDfsChnlInP2pSearch);
 
-    if (pHddCtx->spoofMacAddr.isEnabled)
+    if (pHddCtx->spoofMacAddr.isEnabled &&
+        pHddCtx->cfg_ini->enableMacSpoofing == 1)
     {
         hddLog(VOS_TRACE_LEVEL_INFO,
                         "%s: MAC Spoofing enabled for current scan", __func__);
diff --git a/CORE/MAC/inc/wniCfg.h b/CORE/MAC/inc/wniCfg.h
index ddb5278..5888b99 100644
--- a/CORE/MAC/inc/wniCfg.h
+++ b/CORE/MAC/inc/wniCfg.h
@@ -388,7 +388,8 @@
      WNI_CFG_LINK_FAIL_TX_CNT,
      WNI_CFG_OPTIMIZE_CA_EVENT,
      WNI_CFG_ACTIVE_PASSIVE_CON,
-     WNI_CFG_EXT_SCAN_CONC_MODE
+     WNI_CFG_EXT_SCAN_CONC_MODE,
+     WNI_CFG_ENABLE_MAC_ADDR_SPOOFING
 };
 
 /*
@@ -1901,8 +1902,12 @@
 #define WNI_CFG_EXT_SCAN_CONC_MODE_MAX    2
 #define WNI_CFG_EXT_SCAN_CONC_MODE_DEF    1
 
-#define CFG_PARAM_MAX_NUM        355
-#define CFG_STA_IBUF_MAX_SIZE    289
+#define WNI_CFG_ENABLE_MAC_ADDR_SPOOFING_MIN 0
+#define WNI_CFG_ENABLE_MAC_ADDR_SPOOFING_MAX 2
+#define WNI_CFG_ENABLE_MAC_ADDR_SPOOFING_DEF 1
+
+#define CFG_PARAM_MAX_NUM        356
+#define CFG_STA_IBUF_MAX_SIZE    290
 #define CFG_STA_SBUF_MAX_SIZE    3389
 
 #define CFG_STA_MAGIC_DWORD    0xbeefbeef
diff --git a/CORE/MAC/src/cfg/cfgProcMsg.c b/CORE/MAC/src/cfg/cfgProcMsg.c
index 7e6be46..a7b0484 100644
--- a/CORE/MAC/src/cfg/cfgProcMsg.c
+++ b/CORE/MAC/src/cfg/cfgProcMsg.c
@@ -1687,6 +1687,11 @@
      WNI_CFG_EXT_SCAN_CONC_MODE_MIN,
      WNI_CFG_EXT_SCAN_CONC_MODE_MAX,
      WNI_CFG_EXT_SCAN_CONC_MODE_DEF},
+    {WNI_CFG_ENABLE_MAC_ADDR_SPOOFING,
+     CFG_CTL_VALID | CFG_CTL_RE | CFG_CTL_WE | CFG_CTL_INT | CFG_CTL_NTF_HAL,
+     WNI_CFG_ENABLE_MAC_ADDR_SPOOFING_MIN,
+     WNI_CFG_ENABLE_MAC_ADDR_SPOOFING_MAX,
+     WNI_CFG_ENABLE_MAC_ADDR_SPOOFING_DEF}
 };
 
 tAniSirCfgStaticString cfgStaticString[CFG_MAX_STATIC_STRING] =
diff --git a/CORE/MAC/src/pe/lim/limProcessMlmRspMessages.c b/CORE/MAC/src/pe/lim/limProcessMlmRspMessages.c
index 3eda9c9..f7ff64e 100644
--- a/CORE/MAC/src/pe/lim/limProcessMlmRspMessages.c
+++ b/CORE/MAC/src/pe/lim/limProcessMlmRspMessages.c
@@ -5232,11 +5232,20 @@
 
 void limProcessMlmSpoofMacAddrRsp(tpAniSirGlobal pMac, tSirRetStatus rspStatus)
 {
+    tANI_U32 val;
 
-    if ((rspStatus != eSIR_SUCCESS) ||
+    if (wlan_cfgGetInt(pMac, WNI_CFG_ENABLE_MAC_ADDR_SPOOFING, &val)
+                        != eSIR_SUCCESS)
+    {
+        limLog(pMac, LOGP, FL("fail to Get WNI_CFG_ENABLE_MAC_ADDR_SPOOFING"));
+        /*If we here means mac spoofing is enable. So enable both Host and
+          FW spoofing */
+        val = 1;
+    }
+    if ((rspStatus != eSIR_SUCCESS) || (val != 1) ||
        (TRUE == vos_is_macaddr_zero((v_MACADDR_t *)&pMac->lim.spoofMacAddr)))
     {
-        limLog(pMac, LOG1, FL(" LIM Disabling Spoofing"));
+        limLog(pMac, LOG1, FL(" LIM Disabling Spoofing %d"), val);
         pMac->lim.isSpoofingEnabled = FALSE;
     } else {
         limLog(pMac, LOG1, FL(" LIM Enabling Spoofing"));