Change TDLS run-time enable/disable scheme

Introduce new TDLS mode NOT_ENABLED to completely disable TDLS
implicit trigger and not respond to incoming TDLS request.
Add checking the valid range of each parameter at iwpriv
setTdlsConfig.
Do not deallocate hddTdlsCtx as it cause run-time crash.
Set peer TDLS capability when SETUP/DIS response is sent to peer.
Introduce tdls_set_mode API to handle changing tdls_mode in
run-time.

Change-Id: I18a7d0030067222bd24289daa2d0fa23ef8abbc1
CRs-Fixed: 459176,459169,459177
diff --git a/CORE/HDD/src/wlan_hdd_cfg80211.c b/CORE/HDD/src/wlan_hdd_cfg80211.c
index e1fffb7..56b5281 100755
--- a/CORE/HDD/src/wlan_hdd_cfg80211.c
+++ b/CORE/HDD/src/wlan_hdd_cfg80211.c
@@ -2706,6 +2706,17 @@
                 "Invalid arguments");
         return -EINVAL;
     }
+
+    if ((eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode) ||
+        (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode))
+    {
+         VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
+                    "%s: TDLS mode is disabled OR not enabled in FW."
+                    MAC_ADDRESS_STR " Request declined.",
+                    __func__, MAC_ADDR_ARRAY(mac));
+        return -ENOTSUPP;
+    }
+
     if (pHddCtx->isLogpInProgress)
     {
         VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
@@ -2714,15 +2725,6 @@
         return -EBUSY;
     }
 
-    if (FALSE == pHddCtx->cfg_ini->fEnableTDLSSupport ||
-        FALSE == sme_IsFeatureSupportedByFW(TDLS))
-    {
-        VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
-                "TDLS Disabled in INI OR not enabled in FW.\
-                Cannot process TDLS commands \n");
-        return -ENOTSUPP;
-    }
-
     if (wlan_hdd_tdls_is_progress(pAdapter, mac, TRUE))
     {
         VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
@@ -6733,15 +6735,36 @@
         return -EBUSY;
     }
 
-    if (FALSE == pHddCtx->cfg_ini->fEnableTDLSSupport ||
-        FALSE == sme_IsFeatureSupportedByFW(TDLS)) 
+    if (eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode)
     {
-        VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, 
-                "TDLS Disabled in INI OR not enabled in FW.\
-                Cannot process TDLS commands \n");
+         VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
+                    "%s: TDLS mode is disabled OR not enabled in FW."
+                    MAC_ADDRESS_STR " action %d declined.",
+                    __func__, MAC_ADDR_ARRAY(peer), action_code);
         return -ENOTSUPP;
     }
 
+    if ((SIR_MAC_TDLS_SETUP_RSP == action_code) ||
+        (SIR_MAC_TDLS_DIS_RSP == action_code))
+    {
+        wlan_hdd_tdls_set_cap (pAdapter, peerMac, eTDLS_CAP_SUPPORTED);
+    }
+
+    /* other than teardown frame, other mgmt frames are not sent if disabled */
+    if (SIR_MAC_TDLS_TEARDOWN != action_code)
+    {
+       /* if tdls_mode is disabled to respond to peer's request */
+        if (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode)
+        {
+             VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
+                        "%s: " MAC_ADDRESS_STR
+                        " TDLS mode is disabled. Request declined.",
+                        __func__, MAC_ADDR_ARRAY(peer));
+
+        return -ENOTSUPP;
+        }
+    }
+
     if (WLAN_IS_TDLS_SETUP_ACTION(action_code))
     {
         if (wlan_hdd_tdls_is_progress(pAdapter, peer, TRUE))