prima: ioctl enable or disable 20/40 bss coex IE in TDLS setup Req/Rsp

This commit implements a private ioctl to enable or disable 20/40
bss coexistence IE in tdls setup frames.

CRs-Fixed: 822849
Change-Id: Icffe4d1dc99ad755d23e8e4e677dc546eff36b86
diff --git a/CORE/HDD/src/wlan_hdd_wext.c b/CORE/HDD/src/wlan_hdd_wext.c
index 9af3329..8872172 100644
--- a/CORE/HDD/src/wlan_hdd_wext.c
+++ b/CORE/HDD/src/wlan_hdd_wext.c
@@ -166,6 +166,9 @@
 #define  WE_SET_SCAN_BAND_PREFERENCE     17
 #define  WE_SET_MIRACAST_VENDOR_CONFIG     18
 #define WE_GET_FRAME_LOG                 19
+#ifdef FEATURE_WLAN_TDLS
+#define  WE_SET_TDLS_2040_BSS_COEXISTENCE 20
+#endif
 
 /* Private ioctls and their sub-ioctls */
 #define WLAN_PRIV_SET_NONE_GET_INT    (SIOCIWFIRSTPRIV + 1)
@@ -5846,6 +5849,21 @@
             break;
         }
 
+        case WE_SET_TDLS_2040_BSS_COEXISTENCE:
+        {
+            VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
+                      "%s: TDLS_2040_BSS_COEXISTENCE %d", __func__, set_value);
+            if (set_value == 0 || set_value == 1)
+            {
+                sme_SetTdls2040BSSCoexistence(WLAN_HDD_GET_HAL_CTX(pAdapter),
+                                              set_value);
+            }
+            else
+                ret = -EINVAL;
+
+            break;
+        }
+
         default:
         {
             hddLog(LOGE, "Invalid IOCTL setvalue command %d value %d",
@@ -10090,6 +10108,14 @@
         IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
         0, "setMiracstConf" },
 
+#ifdef FEATURE_WLAN_TDLS
+    {
+        WE_SET_TDLS_2040_BSS_COEXISTENCE,
+        IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
+        0,
+        "tdls_2040bsscox" },
+#endif
+
     /* handlers for main ioctl */
     {   WLAN_PRIV_SET_NONE_GET_INT,
         0,
diff --git a/CORE/MAC/inc/aniGlobal.h b/CORE/MAC/inc/aniGlobal.h
index dfe0169..ad541c3 100644
--- a/CORE/MAC/inc/aniGlobal.h
+++ b/CORE/MAC/inc/aniGlobal.h
@@ -927,6 +927,7 @@
      */
     tANI_U32 remOnChnSeqNum;
     tANI_U32 txBdToken;
+    tANI_U32 EnableTdls2040BSSCoexIE;
 } tAniSirLim, *tpAniSirLim;
 
 typedef struct sLimMgmtFrameRegistration
diff --git a/CORE/MAC/inc/sirApi.h b/CORE/MAC/inc/sirApi.h
index eb4c82d..0eeed9a 100644
--- a/CORE/MAC/inc/sirApi.h
+++ b/CORE/MAC/inc/sirApi.h
@@ -5729,4 +5729,13 @@
     tANI_U32 txCompleteStatus;
     tANI_U32 txBdToken;
 }tSirTxBdStatus, *tpSirTxBdStatus;
+
+/* enable or disable 20_40 BSS Coexistence IE in TDLS frames*/
+typedef struct
+{
+    // Common for all types are requests
+    tANI_U16    msgType;    // message type is same as the request type
+    tANI_U16    msgLen;     // length of the entire request
+    tANI_U8     SetTdls2040BSSCoex; //enabled or disabled
+} tAniSetTdls2040BSSCoex, *tpAniSetTdls2040BSSCoex;
 #endif /* __SIR_API_H */
diff --git a/CORE/MAC/inc/wniApi.h b/CORE/MAC/inc/wniApi.h
index 824395f..03b415a 100644
--- a/CORE/MAC/inc/wniApi.h
+++ b/CORE/MAC/inc/wniApi.h
@@ -391,6 +391,7 @@
     eWNI_SME_ENCRYPT_MSG_RSP,
     eWNI_SME_UPDATE_MAX_RATE_IND,
     eWNI_SME_NAN_EVENT,
+    eWNI_SME_SET_TDLS_2040_BSSCOEX_REQ,
     eWNI_SME_MSG_TYPES_END
 };
 
diff --git a/CORE/MAC/src/pe/lim/limApi.c b/CORE/MAC/src/pe/lim/limApi.c
index ed18255..29df5f7 100644
--- a/CORE/MAC/src/pe/lim/limApi.c
+++ b/CORE/MAC/src/pe/lim/limApi.c
@@ -352,6 +352,8 @@
     pMac->lim.probeCounter = 0;
     pMac->lim.maxProbe = 0;
     pMac->lim.txBdToken = 0;
+
+    pMac->lim.EnableTdls2040BSSCoexIE = 1;
 }
 
 static void __limInitAssocVars(tpAniSirGlobal pMac)
diff --git a/CORE/MAC/src/pe/lim/limProcessMessageQueue.c b/CORE/MAC/src/pe/lim/limProcessMessageQueue.c
index 08c07a1..45444d0 100644
--- a/CORE/MAC/src/pe/lim/limProcessMessageQueue.c
+++ b/CORE/MAC/src/pe/lim/limProcessMessageQueue.c
@@ -2339,6 +2339,12 @@
        limProcessMlmSpoofMacAddrRsp(pMac, (tSirRetStatus)limMsg->bodyval);
        break;
 
+    case eWNI_SME_SET_TDLS_2040_BSSCOEX_REQ:
+         limProcessSmeSetTdls2040BSSCoexReq(pMac, limMsg->bodyptr);
+         vos_mem_free((v_VOID_t*)limMsg->bodyptr);
+         limMsg->bodyptr = NULL;
+        break;
+
     default:
         vos_mem_free((v_VOID_t*)limMsg->bodyptr);
         limMsg->bodyptr = NULL;
diff --git a/CORE/MAC/src/pe/lim/limProcessTdls.c b/CORE/MAC/src/pe/lim/limProcessTdls.c
index 68c4258..1ef6377 100644
--- a/CORE/MAC/src/pe/lim/limProcessTdls.c
+++ b/CORE/MAC/src/pe/lim/limProcessTdls.c
@@ -1141,11 +1141,14 @@
                                             &tdlsDisRsp.SuppChannels,
                                             &tdlsDisRsp.SuppOperatingClasses);
 
-    if ( 1 == pMac->lim.gLimTDLSOffChannelEnabled &&
-         ( pMac->roam.configParam.bandCapability != eCSR_BAND_24) )
+    if (TRUE == pMac->lim.EnableTdls2040BSSCoexIE)
     {
-        tdlsDisRsp.HT2040BSSCoexistence.present = 1;
-        tdlsDisRsp.HT2040BSSCoexistence.infoRequest = 1;
+        if ( 1 == pMac->lim.gLimTDLSOffChannelEnabled &&
+            ( pMac->roam.configParam.bandCapability != eCSR_BAND_24) )
+        {
+            tdlsDisRsp.HT2040BSSCoexistence.present = 1;
+            tdlsDisRsp.HT2040BSSCoexistence.infoRequest = 1;
+        }
     }
     /* 
      * now we pack it.  First, how much space are we going to need?
@@ -1457,11 +1460,14 @@
                                             &tdlsSetupReq.SuppChannels,
                                             &tdlsSetupReq.SuppOperatingClasses);
 
-    if ( 1 == pMac->lim.gLimTDLSOffChannelEnabled &&
-         ( pMac->roam.configParam.bandCapability != eCSR_BAND_24))
+    if (TRUE == pMac->lim.EnableTdls2040BSSCoexIE)
     {
-        tdlsSetupReq.HT2040BSSCoexistence.present = 1;
-        tdlsSetupReq.HT2040BSSCoexistence.infoRequest = 1;
+        if ( 1 == pMac->lim.gLimTDLSOffChannelEnabled &&
+            ( pMac->roam.configParam.bandCapability != eCSR_BAND_24))
+        {
+            tdlsSetupReq.HT2040BSSCoexistence.present = 1;
+            tdlsSetupReq.HT2040BSSCoexistence.infoRequest = 1;
+        }
     }
 
     /*
@@ -1911,11 +1917,14 @@
 
     tdlsSetupRsp.Status.status = setupStatus ;
 
-    if ( 1 == pMac->lim.gLimTDLSOffChannelEnabled &&
-         ( pMac->roam.configParam.bandCapability != eCSR_BAND_24))
+    if (TRUE == pMac->lim.EnableTdls2040BSSCoexIE)
     {
-        tdlsSetupRsp.HT2040BSSCoexistence.present = 1;
-        tdlsSetupRsp.HT2040BSSCoexistence.infoRequest = 1;
+        if ( 1 == pMac->lim.gLimTDLSOffChannelEnabled &&
+            ( pMac->roam.configParam.bandCapability != eCSR_BAND_24))
+        {
+            tdlsSetupRsp.HT2040BSSCoexistence.present = 1;
+            tdlsSetupRsp.HT2040BSSCoexistence.infoRequest = 1;
+        }
     }
     /* 
      * now we pack it.  First, how much space are we going to need?
@@ -2109,11 +2118,14 @@
        PopulateDot11fHTInfo( pMac, &tdlsSetupCnf.HTInfo, psessionEntry );
     }
 
-    if ( 1 == pMac->lim.gLimTDLSOffChannelEnabled &&
-         ( pMac->roam.configParam.bandCapability != eCSR_BAND_24))
+    if (TRUE == pMac->lim.EnableTdls2040BSSCoexIE)
     {
-        tdlsSetupCnf.HT2040BSSCoexistence.present = 1;
-        tdlsSetupCnf.HT2040BSSCoexistence.infoRequest = 1;
+        if ( 1 == pMac->lim.gLimTDLSOffChannelEnabled &&
+            ( pMac->roam.configParam.bandCapability != eCSR_BAND_24))
+        {
+            tdlsSetupCnf.HT2040BSSCoexistence.present = 1;
+            tdlsSetupCnf.HT2040BSSCoexistence.infoRequest = 1;
+        }
     }
 
     /* 
@@ -6251,3 +6263,23 @@
     return eSIR_FAILURE;
 }
 
+/*
+ * Set 20_40 BSS Coex IE in TDLS frames.
+ */
+tSirRetStatus limProcessSmeSetTdls2040BSSCoexReq(tpAniSirGlobal pMac,
+                                                 tANI_U32 *pMsgBuf)
+{
+    tAniSetTdls2040BSSCoex *pmsg = NULL;
+    pmsg = (tAniSetTdls2040BSSCoex*) pMsgBuf ;
+
+    if (NULL != pmsg) {
+        pMac->lim.EnableTdls2040BSSCoexIE = pmsg->SetTdls2040BSSCoex;
+    }
+    VOS_TRACE(VOS_MODULE_ID_PE, VOS_TRACE_LEVEL_INFO,
+              "%s: 20_40 BSS Coex IE in TDLS frames "
+              "pMac->lim.EnableTdls2040BSSCoexIE %d ", __func__,
+              pMac->lim.EnableTdls2040BSSCoexIE);
+
+    return eSIR_SUCCESS;
+}
+
diff --git a/CORE/MAC/src/pe/lim/limTypes.h b/CORE/MAC/src/pe/lim/limTypes.h
index 7b15b9e..e504441 100644
--- a/CORE/MAC/src/pe/lim/limTypes.h
+++ b/CORE/MAC/src/pe/lim/limTypes.h
@@ -1114,5 +1114,7 @@
 int limProcessRemainOnChnlReq(tpAniSirGlobal pMac, tANI_U32 *pMsg);
 void limRemainOnChnRsp(tpAniSirGlobal pMac, eHalStatus status, tANI_U32 *data);
 void limProcessMlmSpoofMacAddrRsp(tpAniSirGlobal pMac, tSirRetStatus rspStatus);
+tSirRetStatus limProcessSmeSetTdls2040BSSCoexReq(tpAniSirGlobal pMac,
+                                                 tANI_U32 *pMsgBuf);
 #endif /* __LIM_TYPES_H */
 
diff --git a/CORE/SME/inc/sme_Api.h b/CORE/SME/inc/sme_Api.h
index b988bcc..15d4563 100644
--- a/CORE/SME/inc/sme_Api.h
+++ b/CORE/SME/inc/sme_Api.h
@@ -3659,4 +3659,14 @@
                                       tANI_U32 set_value);
 
 void sme_SetDefDot11Mode(tHalHandle hHal);
+
+/* ---------------------------------------------------------------------------
+    \fn sme_SetTdls2040BSSCoexistence
+    \brief  API to enable or disable 20_40 BSS Coexistence IE in TDLS frames.
+
+    \param  isEnabled - Enable or Disable.
+    \- return VOS_STATUS_SUCCES
+   -------------------------------------------------------------------------*/
+eHalStatus sme_SetTdls2040BSSCoexistence(tHalHandle hHal, tANI_S32 isEnabled);
+
 #endif //#if !defined( __SME_API_H )
diff --git a/CORE/SME/src/sme_common/sme_Api.c b/CORE/SME/src/sme_common/sme_Api.c
index 04bd65a..b94eaa6 100644
--- a/CORE/SME/src/sme_common/sme_Api.c
+++ b/CORE/SME/src/sme_common/sme_Api.c
@@ -12610,3 +12610,54 @@
     csrSetDefaultDot11Mode(pMac);
 }
 
+/* ---------------------------------------------------------------------------
+    \fn sme_SetTdls2040BSSCoexistence
+    \brief  API to enable or disable 20_40 BSS Coexistence IE in TDLS frames.
+
+    \param  isEnabled - Enable or Disable.
+    \- return VOS_STATUS_SUCCES
+    -------------------------------------------------------------------------*/
+eHalStatus sme_SetTdls2040BSSCoexistence(tHalHandle hHal,
+                                     tANI_S32 isTdls2040BSSCoexEnabled)
+{
+    eHalStatus          status    = eHAL_STATUS_SUCCESS;
+    tpAniSirGlobal      pMac      = PMAC_STRUCT(hHal);
+    vos_msg_t           msg;
+    tAniSetTdls2040BSSCoex  *pMsg;
+
+    status = sme_AcquireGlobalLock( &pMac->sme );
+    if (HAL_STATUS_SUCCESS( status ))
+    {
+        VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO,
+                  "%s: is2040BSSCoexEnabled %d ",
+                  __func__, isTdls2040BSSCoexEnabled);
+        pMsg = vos_mem_malloc(sizeof(tAniSetTdls2040BSSCoex));
+        if (NULL == pMsg )
+        {
+            smsLog(pMac, LOGE, "failed to allocate mem for SetTdls2040BSSCoex");
+            sme_ReleaseGlobalLock( &pMac->sme );
+            return eHAL_STATUS_FAILURE;
+        }
+
+        pMsg->msgType = pal_cpu_to_be16(
+                        (tANI_U16)eWNI_SME_SET_TDLS_2040_BSSCOEX_REQ);
+        pMsg->msgLen = (tANI_U16)sizeof(tAniSetTdls2040BSSCoex);
+        pMsg->SetTdls2040BSSCoex = isTdls2040BSSCoexEnabled;
+
+        msg.type = eWNI_SME_SET_TDLS_2040_BSSCOEX_REQ;
+        msg.reserved = 0;
+        msg.bodyptr = pMsg;
+        msg.bodyval = 0;
+
+        if(VOS_STATUS_SUCCESS != vos_mq_post_message(VOS_MQ_ID_PE, &msg))
+        {
+            smsLog(pMac, LOGE,
+                   "sme_SetTdls2040BSSCoexistence failed to post msg to PE ");
+            vos_mem_free((void *)pMsg);
+            status = eHAL_STATUS_FAILURE;
+        }
+        smsLog(pMac, LOG1, FL(" returned"));
+        sme_ReleaseGlobalLock( &pMac->sme );
+    }
+    return status;
+}