TDLS: Send WMM Elements in tdls setup frames

Advertize WMM capability by including WMM IE's in TDLS Setup
Request/Response and WMM Parameter Element in TDLS Setup
Confirmation frames.
This capability shall be enabled based on the
gEnableTDLSWmmMode parameter.
Also, ensure to include the WMM Parameter Element in TDLS Setup
Confirmation frames only when the peer is WMM capable.

CRs-fixed: 646551
Change-Id: Iaef63dee00dad757ae6177e9148e1df21cefce33
diff --git a/CORE/HDD/inc/wlan_hdd_cfg.h b/CORE/HDD/inc/wlan_hdd_cfg.h
index 820244b..d863ec4 100644
--- a/CORE/HDD/inc/wlan_hdd_cfg.h
+++ b/CORE/HDD/inc/wlan_hdd_cfg.h
@@ -1827,6 +1827,11 @@
 #define CFG_TDLS_OFF_CHANNEL_SUPPORT_ENABLE_MIN      (0)
 #define CFG_TDLS_OFF_CHANNEL_SUPPORT_ENABLE_MAX      (1)
 #define CFG_TDLS_OFF_CHANNEL_SUPPORT_ENABLE_DEFAULT  (0)
+
+#define CFG_TDLS_WMM_MODE_ENABLE                     "gEnableTDLSWmmMode"
+#define CFG_TDLS_WMM_MODE_ENABLE_MIN                 (0)
+#define CFG_TDLS_WMM_MODE_ENABLE_MAX                 (1)
+#define CFG_TDLS_WMM_MODE_ENABLE_DEFAULT             (0)
 #endif
 
 #ifdef WLAN_ACTIVEMODE_OFFLOAD_FEATURE
@@ -2547,6 +2552,7 @@
    v_U32_t                     fTDLSRxFrameThreshold;
    v_BOOL_t                    fTDLSExternalControl;
    v_U32_t                     fEnableTDLSOffChannel;
+   v_U32_t                     fEnableTDLSWmmMode;
 #endif
    v_U32_t                     enableLpwrImgTransition;
 #ifdef WLAN_SOFTAP_VSTA_FEATURE
diff --git a/CORE/HDD/src/wlan_hdd_cfg.c b/CORE/HDD/src/wlan_hdd_cfg.c
index f5342b3..eeac9af 100644
--- a/CORE/HDD/src/wlan_hdd_cfg.c
+++ b/CORE/HDD/src/wlan_hdd_cfg.c
@@ -2524,6 +2524,13 @@
               CFG_TDLS_EXTERNAL_CONTROL_DEFAULT,
               CFG_TDLS_EXTERNAL_CONTROL_MIN,
               CFG_TDLS_EXTERNAL_CONTROL_MAX ),
+
+REG_VARIABLE( CFG_TDLS_WMM_MODE_ENABLE, WLAN_PARAM_Integer,
+              hdd_config_t, fEnableTDLSWmmMode,
+              VAR_FLAGS_OPTIONAL | VAR_FLAGS_RANGE_CHECK_ASSUME_DEFAULT,
+              CFG_TDLS_WMM_MODE_ENABLE_DEFAULT,
+              CFG_TDLS_WMM_MODE_ENABLE_MIN,
+              CFG_TDLS_WMM_MODE_ENABLE_MAX ),
 #endif
 
 #ifdef WLAN_SOFTAP_VSTA_FEATURE
@@ -4606,6 +4613,14 @@
       hddLog(LOGE, "Could not pass on WNI_CFG_TDLS_BUF_STA_ENABLED to CCM\n");
    }
 
+   if (ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_TDLS_WMM_MODE_ENABLED,
+                    pConfig->fEnableTDLSWmmMode, NULL,
+                    eANI_BOOLEAN_FALSE)==eHAL_STATUS_FAILURE)
+   {
+      fStatus = FALSE;
+      hddLog(LOGE, "Could not pass on WNI_CFG_TDLS_WMM_MODE_ENABLED to CCM\n");
+   }
+
 #endif
 
    if (ccmCfgSetInt(pHddCtx->hHal, WNI_CFG_ENABLE_ADAPT_RX_DRAIN,
diff --git a/CORE/MAC/inc/aniGlobal.h b/CORE/MAC/inc/aniGlobal.h
index 6526cdc..bc7b4a9 100644
--- a/CORE/MAC/inc/aniGlobal.h
+++ b/CORE/MAC/inc/aniGlobal.h
@@ -656,6 +656,8 @@
     tANI_U8 gLimTDLSBufStaEnabled;
     tANI_U8 gLimTDLSUapsdMask;
     tANI_U8 gLimTDLSOffChannelEnabled;
+    // TDLS WMM Mode
+    tANI_U8 gLimTDLSWmmMode;
 #endif
 
 
diff --git a/CORE/MAC/inc/wniCfgAp.h b/CORE/MAC/inc/wniCfgAp.h
index 31d4837..afe80b8 100644
--- a/CORE/MAC/inc/wniCfgAp.h
+++ b/CORE/MAC/inc/wniCfgAp.h
@@ -378,6 +378,7 @@
 #define WNI_CFG_BTC_CRITICAL_HID_NSNIFF_BLK_GUIDANCE    331
 #define WNI_CFG_BTC_DYN_A2DP_TX_QUEUE_THOLD    332
 #define WNI_CFG_BTC_DYN_OPP_TX_QUEUE_THOLD    333
+#define WNI_CFG_TDLS_WMM_MODE_ENABLED    334
 
 /*
  * String parameter lengths 
@@ -2801,10 +2802,18 @@
 #define WNI_CFG_BTC_DYN_OPP_TX_QUEUE_THOLD_APMAX    3
 #define WNI_CFG_BTC_DYN_OPP_TX_QUEUE_THOLD_APDEF    1
 
-#define CFG_PARAM_MAX_NUM         334
-#define CFG_AP_IBUF_MAX_SIZE      273
+#define WNI_CFG_TDLS_WMM_MODE_ENABLED_STAMIN    0
+#define WNI_CFG_TDLS_WMM_MODE_ENABLED_STAMAX    1
+#define WNI_CFG_TDLS_WMM_MODE_ENABLED_STADEF    0
+
+#define WNI_CFG_TDLS_WMM_MODE_ENABLED_APMIN    0
+#define WNI_CFG_TDLS_WMM_MODE_ENABLED_APMAX    1
+#define WNI_CFG_TDLS_WMM_MODE_ENABLED_APDEF    0
+
+#define CFG_PARAM_MAX_NUM         335
+#define CFG_AP_IBUF_MAX_SIZE      274
 #define CFG_AP_SBUF_MAX_SIZE      3422
-#define CFG_STA_IBUF_MAX_SIZE     268
+#define CFG_STA_IBUF_MAX_SIZE     269
 #define CFG_STA_SBUF_MAX_SIZE     3388
 #define CFG_SEM_MAX_NUM           19
 
diff --git a/CORE/MAC/inc/wniCfgSta.h b/CORE/MAC/inc/wniCfgSta.h
index 4d2e34d..bd7cf26 100644
--- a/CORE/MAC/inc/wniCfgSta.h
+++ b/CORE/MAC/inc/wniCfgSta.h
@@ -372,6 +372,7 @@
 #define WNI_CFG_BTC_CRITICAL_HID_NSNIFF_BLK_GUIDANCE    331
 #define WNI_CFG_BTC_DYN_A2DP_TX_QUEUE_THOLD    332
 #define WNI_CFG_BTC_DYN_OPP_TX_QUEUE_THOLD    333
+#define WNI_CFG_TDLS_WMM_MODE_ENABLED    334
 
 /*
  * String parameter lengths 
@@ -1790,8 +1791,12 @@
 #define WNI_CFG_BTC_DYN_OPP_TX_QUEUE_THOLD_STAMAX    3
 #define WNI_CFG_BTC_DYN_OPP_TX_QUEUE_THOLD_STADEF    1
 
-#define CFG_PARAM_MAX_NUM        334
-#define CFG_STA_IBUF_MAX_SIZE    268
+#define WNI_CFG_TDLS_WMM_MODE_ENABLED_STAMIN    0
+#define WNI_CFG_TDLS_WMM_MODE_ENABLED_STAMAX    1
+#define WNI_CFG_TDLS_WMM_MODE_ENABLED_STADEF    0
+
+#define CFG_PARAM_MAX_NUM        335
+#define CFG_STA_IBUF_MAX_SIZE    269
 #define CFG_STA_SBUF_MAX_SIZE    3388
 #define CFG_SEM_MAX_NUM          19
 
diff --git a/CORE/MAC/src/cfg/cfgParamName.c b/CORE/MAC/src/cfg/cfgParamName.c
index 1a59004..d5ebc65 100644
--- a/CORE/MAC/src/cfg/cfgParamName.c
+++ b/CORE/MAC/src/cfg/cfgParamName.c
@@ -368,6 +368,7 @@
     (unsigned char *)"BTC_CRITICAL_HID_NSNIFF_BLK_GUIDANCE",
     (unsigned char *)"BTC_DYN_A2DP_TX_QUEUE_THOLD",
     (unsigned char *)"BTC_DYN_OPP_TX_QUEUE_THOLD",
+    (unsigned char *)"TDLS_WMM_MODE_ENABLED",
 };
 
 
diff --git a/CORE/MAC/src/cfg/cfgUtil/cfg.txt b/CORE/MAC/src/cfg/cfgUtil/cfg.txt
index d3c63a3..e8f6a20 100644
--- a/CORE/MAC/src/cfg/cfgUtil/cfg.txt
+++ b/CORE/MAC/src/cfg/cfgUtil/cfg.txt
@@ -4928,3 +4928,15 @@
 0    3    1
 *
 *
+
+*
+*TDLS WMM Mode
+*
+*
+WNI_CFG_TDLS_WMM_MODE_ENABLED   I   4   7
+V    RW    NP
+LIM
+0    1    0
+V    RW    NP
+LIM
+0    1    0
diff --git a/CORE/MAC/src/pe/lim/limApi.c b/CORE/MAC/src/pe/lim/limApi.c
index 2036399..37ad9e7 100644
--- a/CORE/MAC/src/pe/lim/limApi.c
+++ b/CORE/MAC/src/pe/lim/limApi.c
@@ -628,7 +628,14 @@
        limLog(pMac, LOGP, FL("cfg get LimTDLSUapsdMask failed"));
        return eSIR_FAILURE;
    }
+
+   if(wlan_cfgGetInt(pMac, WNI_CFG_TDLS_WMM_MODE_ENABLED,(tANI_U32 *) &pMac->lim.gLimTDLSWmmMode) != eSIR_SUCCESS)
+   {
+       limLog(pMac, LOGP, FL("cfg get LimTDLSWmmMode failed"));
+       return eSIR_FAILURE;
+   }
 #endif
+
    if (eSIR_SUCCESS !=
        wlan_cfgGetInt(pMac, WNI_CFG_DEBUG_P2P_REMAIN_ON_CHANNEL,
                       (tANI_U32 *)&pMac->lim.gDebugP2pRemainOnChannel))
diff --git a/CORE/MAC/src/pe/lim/limProcessTdls.c b/CORE/MAC/src/pe/lim/limProcessTdls.c
index b4758cc..7e06359 100644
--- a/CORE/MAC/src/pe/lim/limProcessTdls.c
+++ b/CORE/MAC/src/pe/lim/limProcessTdls.c
@@ -1274,22 +1274,30 @@
     /* Populate extended supported rates */
     PopulateDot11fTdlsExtCapability( pMac, &tdlsSetupReq.ExtCap );
 
-   /*
-     * TODO: we need to see if we have to support conditions where we have
-     * EDCA parameter info element is needed a) if we need different QOS
-     * parameters for off channel operations or QOS is not supported on
-     * AP link and we wanted to QOS on direct link.
-     */
-    /* Populate QOS info, needed for Peer U-APSD session */
-    /* TODO: Now hardcoded, because PopulateDot11fQOSCapsStation() depends on AP's capability, and
-    TDLS doesn't want to depend on AP's capability */
-    tdlsSetupReq.QOSCapsStation.present = 1;
-    tdlsSetupReq.QOSCapsStation.max_sp_length = 0;
-    tdlsSetupReq.QOSCapsStation.qack = 0;
-    tdlsSetupReq.QOSCapsStation.acbe_uapsd = ((pMac->lim.gLimTDLSUapsdMask & 0x08) >> 3) ;
-    tdlsSetupReq.QOSCapsStation.acbk_uapsd = ((pMac->lim.gLimTDLSUapsdMask & 0x04)>> 2);
-    tdlsSetupReq.QOSCapsStation.acvi_uapsd = ((pMac->lim.gLimTDLSUapsdMask & 0x02)>> 1);
-    tdlsSetupReq.QOSCapsStation.acvo_uapsd = (pMac->lim.gLimTDLSUapsdMask & 0x01);
+    if ( 1 == pMac->lim.gLimTDLSWmmMode )
+    {
+        /* include WMM IE */
+        PopulateDot11fWMMInfoStation( pMac, &tdlsSetupReq.WMMInfoStation );
+    }
+    else
+    {
+        /*
+         * TODO: we need to see if we have to support conditions where we have
+         * EDCA parameter info element is needed a) if we need different QOS
+         * parameters for off channel operations or QOS is not supported on
+         * AP link and we wanted to QOS on direct link.
+         */
+        /* Populate QOS info, needed for Peer U-APSD session */
+        /* TODO: Now hardcoded, because PopulateDot11fQOSCapsStation() depends on AP's capability, and
+         TDLS doesn't want to depend on AP's capability */
+        tdlsSetupReq.QOSCapsStation.present = 1;
+        tdlsSetupReq.QOSCapsStation.max_sp_length = 0;
+        tdlsSetupReq.QOSCapsStation.qack = 0;
+        tdlsSetupReq.QOSCapsStation.acbe_uapsd = ((pMac->lim.gLimTDLSUapsdMask & 0x08) >> 3);
+        tdlsSetupReq.QOSCapsStation.acbk_uapsd = ((pMac->lim.gLimTDLSUapsdMask & 0x04) >> 2);
+        tdlsSetupReq.QOSCapsStation.acvi_uapsd = ((pMac->lim.gLimTDLSUapsdMask & 0x02) >> 1);
+        tdlsSetupReq.QOSCapsStation.acvo_uapsd = (pMac->lim.gLimTDLSUapsdMask & 0x01);
+    }
 
     /*
      * we will always try to init TDLS link with 11n capabilities
@@ -1691,22 +1699,30 @@
     /* Populate extended supported rates */
     PopulateDot11fTdlsExtCapability( pMac, &tdlsSetupRsp.ExtCap );
 
-    /* 
-     * TODO: we need to see if we have to support conditions where we have
-     * EDCA parameter info element is needed a) if we need different QOS
-     * parameters for off channel operations or QOS is not supported on 
-     * AP link and we wanted to QOS on direct link.
-     */
-    /* Populate QOS info, needed for Peer U-APSD session */
-    /* TODO: Now hardcoded, because PopulateDot11fQOSCapsStation() depends on AP's capability, and
-    TDLS doesn't want to depend on AP's capability */
-    tdlsSetupRsp.QOSCapsStation.present = 1;
-    tdlsSetupRsp.QOSCapsStation.max_sp_length = 0;
-    tdlsSetupRsp.QOSCapsStation.qack = 0;
-    tdlsSetupRsp.QOSCapsStation.acbe_uapsd = ((pMac->lim.gLimTDLSUapsdMask & 0x08) >> 3);
-    tdlsSetupRsp.QOSCapsStation.acbk_uapsd = ((pMac->lim.gLimTDLSUapsdMask & 0x04) >> 2);
-    tdlsSetupRsp.QOSCapsStation.acvi_uapsd = ((pMac->lim.gLimTDLSUapsdMask & 0x02) >> 1);
-    tdlsSetupRsp.QOSCapsStation.acvo_uapsd = (pMac->lim.gLimTDLSUapsdMask & 0x01);
+    if ( 1 == pMac->lim.gLimTDLSWmmMode )
+    {
+        /* include WMM IE */
+        PopulateDot11fWMMInfoStation( pMac, &tdlsSetupRsp.WMMInfoStation );
+    }
+    else
+    {
+        /*
+         * TODO: we need to see if we have to support conditions where we have
+         * EDCA parameter info element is needed a) if we need different QOS
+         * parameters for off channel operations or QOS is not supported on
+         * AP link and we wanted to QOS on direct link.
+         */
+        /* Populate QOS info, needed for Peer U-APSD session */
+        /* TODO: Now hardcoded, because PopulateDot11fQOSCapsStation() depends on AP's capability, and
+         TDLS doesn't want to depend on AP's capability */
+        tdlsSetupRsp.QOSCapsStation.present = 1;
+        tdlsSetupRsp.QOSCapsStation.max_sp_length = 0;
+        tdlsSetupRsp.QOSCapsStation.qack = 0;
+        tdlsSetupRsp.QOSCapsStation.acbe_uapsd = ((pMac->lim.gLimTDLSUapsdMask & 0x08) >> 3);
+        tdlsSetupRsp.QOSCapsStation.acbk_uapsd = ((pMac->lim.gLimTDLSUapsdMask & 0x04) >> 2);
+        tdlsSetupRsp.QOSCapsStation.acvi_uapsd = ((pMac->lim.gLimTDLSUapsdMask & 0x02) >> 1);
+        tdlsSetupRsp.QOSCapsStation.acvo_uapsd = (pMac->lim.gLimTDLSUapsdMask & 0x01);
+    }
 
     wlan_cfgGetInt(pMac,WNI_CFG_DOT11_MODE,&selfDot11Mode);
 
@@ -1894,6 +1910,12 @@
      * AP link and we wanted to QOS on direct link.
      */
 
+    /* Check self and peer WMM capable */
+    if ((1 == pMac->lim.gLimTDLSWmmMode) && (CHECK_BIT(peerCapability, TDLS_PEER_WMM_CAP)))
+    {
+       PopulateDot11fWMMParams(pMac, &tdlsSetupCnf.WMMParams, psessionEntry);
+    }
+
      /* Check peer is VHT capable*/
     if (CHECK_BIT(peerCapability, TDLS_PEER_VHT_CAP))
     {
diff --git a/firmware_bin/WCNSS_cfg.dat b/firmware_bin/WCNSS_cfg.dat
index 324b379..507b85a 100644
--- a/firmware_bin/WCNSS_cfg.dat
+++ b/firmware_bin/WCNSS_cfg.dat
Binary files differ