Debug code in TL to print the RSSI and rate Index histogram

Added TL profiling code to print the RSSI and rate index of the pkts received.
Added 2 new dump commands to print the num of pkts received with certain RSSI (370) and rate index (369),
iwpriv wlan0 dump 369
iwpriv wlan0 dump 370

Change-Id: I61f6c4b89581da0df755d0e87096037120384ac7
CRs-fixed: 430405
diff --git a/CORE/MAC/src/pe/lim/limLogDump.c b/CORE/MAC/src/pe/lim/limLogDump.c
index 3670bc2..57c3e3c 100644
--- a/CORE/MAC/src/pe/lim/limLogDump.c
+++ b/CORE/MAC/src/pe/lim/limLogDump.c
@@ -73,6 +73,10 @@
 #include "wlan_qct_wda.h"
 
 void WDA_TimerTrafficStatsInd(tWDA_CbContext *pWDA);
+#ifdef WLANTL_DEBUG
+extern void WLANTLPrintPktsRcvdPerRssi(v_PVOID_t pAdapter, v_U8_t staId, v_BOOL_t flush);
+extern void WLANTLPrintPktsRcvdPerRateIdx(v_PVOID_t pAdapter, v_U8_t staId, v_BOOL_t flush);
+#endif
 
 static char *getRole( tLimSystemRole role )
 {
@@ -2528,6 +2532,36 @@
    return p;
 }
 
+#ifdef WLANTL_DEBUG
+/* API to print number of pkts received based on rate index */
+/* arg1 = station Id */
+/* arg2 = BOOLEAN value to either or not flush the counters */
+static char *
+dump_lim_get_pkts_rcvd_per_rate_idx( tpAniSirGlobal pMac, tANI_U32 arg1, tANI_U32 arg2, tANI_U32 arg3, tANI_U32 arg4, char *p)
+{
+    /* if anything other than 1, then we need not flush the counters */
+    if( arg2 != 1)
+        arg2 = FALSE;
+
+    WLANTLPrintPktsRcvdPerRateIdx(pMac->roam.gVosContext, (tANI_U8)arg1, (v_BOOL_t)arg2);
+    return p;
+}
+
+/* API to print number of pkts received based on rssi */
+/* arg1 = station Id */
+/* arg2 = BOOLEAN value to either or not flush the counters */
+static char *
+dump_lim_get_pkts_rcvd_per_rssi_values( tpAniSirGlobal pMac, tANI_U32 arg1, tANI_U32 arg2, tANI_U32 arg3, tANI_U32 arg4, char *p)
+{
+    /* if anything other than 1, then we need not flush the counters */
+    if( arg2 != 1)
+        arg2 = FALSE;
+
+    WLANTLPrintPktsRcvdPerRssi(pMac->roam.gVosContext, (tANI_U8)arg1, (v_BOOL_t)arg2);
+    return p;
+}
+#endif
+
 static tDumpFuncEntry limMenuDumpTable[] = {
     {0,     "PE (300-499)",                                          NULL},
     {300,   "LIM: Dump state(s)/statistics <session id>",            dump_lim_info},
@@ -2599,6 +2633,10 @@
     {367,   "PE.LIM: Send a VHT Channel Switch Announcement",        dump_lim_vht_channel_switch_notification},
     {368,   "PE.LIM: MCC Policy Maker",                              dump_lim_mcc_policy_maker},
 #endif
+#ifdef WLANTL_DEBUG
+    {369,   "PE.LIM: pkts/rateIdx: iwpriv wlan0 dump 368 <staId> <boolean to flush counter>",    dump_lim_get_pkts_rcvd_per_rate_idx},
+    {370,   "PE.LIM: pkts/rssi: : iwpriv wlan0 dump 369 <staId> <boolean to flush counter>",    dump_lim_get_pkts_rcvd_per_rssi_values},
+#endif
 };
 
 
diff --git a/CORE/SAP/inc/sapApi.h b/CORE/SAP/inc/sapApi.h
index 0a4b3e8..3207089 100644
--- a/CORE/SAP/inc/sapApi.h
+++ b/CORE/SAP/inc/sapApi.h
@@ -558,6 +558,12 @@
     } sapwpsie;
 } tSap_WPSIE, *tpSap_WPSIE;
 
+#ifdef WLANTL_DEBUG
+#define MAX_RATE_INDEX      136
+#define MAX_NUM_RSSI        100
+#define MAX_RSSI_INTERVAL     5
+#endif
+
 typedef struct sap_SoftapStats_s {
    v_U32_t txUCFcnt;
    v_U32_t txMCFcnt;
@@ -574,6 +580,10 @@
    v_U32_t rxBcnt;
    v_U32_t rxBcntCRCok;
    v_U32_t rxRate;
+#ifdef WLANTL_DEBUG
+   v_U32_t pktCounterRateIdx[MAX_RATE_INDEX];
+   v_U32_t pktCounterRssi[MAX_NUM_RSSI];
+#endif
 } tSap_SoftapStats, *tpSap_SoftapStats;
 
 
diff --git a/CORE/TL/inc/wlan_qct_tl.h b/CORE/TL/inc/wlan_qct_tl.h
index c362cad..81da974 100644
--- a/CORE/TL/inc/wlan_qct_tl.h
+++ b/CORE/TL/inc/wlan_qct_tl.h
@@ -39,8 +39,6 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/*
- * */
 
 #ifndef WLAN_QCT_WLANTL_H
 #define WLAN_QCT_WLANTL_H
@@ -510,6 +508,13 @@
 #ifdef WLAN_SOFTAP_FEATURE
 typedef tSap_SoftapStats WLANTL_TRANSFER_STA_TYPE;
 #else
+
+#ifdef WLANTL_DEBUG
+#define MAX_RATE_INDEX      136
+#define MAX_NUM_RSSI        100
+#define MAX_RSSI_INTERVAL     5
+#endif
+
 typedef struct
 {
    v_U32_t txUCFcnt;
@@ -527,6 +532,10 @@
    v_U32_t rxBcnt;
    v_U32_t rxBcntCRCok;
    v_U32_t rxRate;
+#ifdef WLANTL_DEBUG
+   v_U32_t pktCounterRateIdx[MAX_RATE_INDEX];
+   v_U32_t pktCounterRssi[MAX_NUM_RSSI];
+#endif
 }WLANTL_TRANSFER_STA_TYPE;
 #endif
 
diff --git a/CORE/TL/src/wlan_qct_tl.c b/CORE/TL/src/wlan_qct_tl.c
index 260cb9b..253a593 100644
--- a/CORE/TL/src/wlan_qct_tl.c
+++ b/CORE/TL/src/wlan_qct_tl.c
@@ -8635,7 +8635,7 @@
 /*=============================================================================
    BEGIN LOG FUNCTION    !!! Remove me or clean me
 =============================================================================*/
-#ifdef WLANTL_DEBUG 
+#if 0 //def WLANTL_DEBUG
 
 #define WLANTL_DEBUG_FRAME_BYTE_PER_LINE    16
 #define WLANTL_DEBUG_FRAME_BYTE_PER_BYTE    4
diff --git a/CORE/TL/src/wlan_qct_tl_hosupport.c b/CORE/TL/src/wlan_qct_tl_hosupport.c
index da8c951..abd3778 100644
--- a/CORE/TL/src/wlan_qct_tl_hosupport.c
+++ b/CORE/TL/src/wlan_qct_tl_hosupport.c
@@ -212,6 +212,98 @@
 }
 #endif /* WLANTL_HO_DEBUG_MSG */
 
+#ifdef WLANTL_DEBUG
+void WLANTLPrintPktsRcvdPerRateIdx(v_PVOID_t pAdapter, v_U8_t staId, v_BOOL_t flush)
+{
+    v_U16_t  ii;
+    WLANTL_CbType  *tlCtxt = VOS_GET_TL_CB(pAdapter);
+
+    if(NULL == tlCtxt)
+    {
+        TLLOGE(VOS_TRACE(VOS_MODULE_ID_TL, VOS_TRACE_LEVEL_ERROR,"Invalid TL handle"));
+        return;
+    }
+
+    if(tlCtxt->atlSTAClients[staId].ucExists == 0)
+    {
+        TLLOGE(VOS_TRACE(VOS_MODULE_ID_TL, VOS_TRACE_LEVEL_ERROR,"WLAN TL: %d STA ID does not exist", staId));
+        return;
+    }
+
+    if(flush)
+    {
+        TLLOG1(VOS_TRACE(VOS_MODULE_ID_TL, VOS_TRACE_LEVEL_ERROR,
+                         "flushed rateIdx counters"));
+
+        for(ii = 0; ii < MAX_RATE_INDEX; ii++)
+            tlCtxt->atlSTAClients[staId].trafficStatistics.pktCounterRateIdx[ii] = 0;
+
+        return;
+    }
+
+    TLLOG1(VOS_TRACE(VOS_MODULE_ID_TL, VOS_TRACE_LEVEL_ERROR, "pkts per rate Index"));
+
+    for(ii = 0; ii < MAX_RATE_INDEX; ii++)
+    {
+        /* printing int the below format
+         * " rateIndex = pktCount "*/
+        TLLOG1(VOS_TRACE(VOS_MODULE_ID_TL, VOS_TRACE_LEVEL_ERROR,
+                         "%d = %ld", ii+1,
+                         tlCtxt->atlSTAClients[staId].trafficStatistics.pktCounterRateIdx[ii]));
+    }
+
+    return;
+}
+
+void WLANTLPrintPktsRcvdPerRssi(v_PVOID_t pAdapter, v_U8_t staId, v_BOOL_t flush)
+{
+    v_U16_t ii,jj;
+    v_U32_t count = 0;
+    WLANTL_CbType  *tlCtxt = VOS_GET_TL_CB(pAdapter);
+
+    if(NULL == tlCtxt)
+    {
+        TLLOGE(VOS_TRACE(VOS_MODULE_ID_TL, VOS_TRACE_LEVEL_ERROR,"Invalid TL handle"));
+        return;
+    }
+
+    if(tlCtxt->atlSTAClients[staId].ucExists == 0)
+    {
+        TLLOGE(VOS_TRACE(VOS_MODULE_ID_TL, VOS_TRACE_LEVEL_ERROR,"WLAN TL: %d STA ID does not exist", staId));
+        return;
+    }
+
+    if(flush)
+    {
+        TLLOG1(VOS_TRACE(VOS_MODULE_ID_TL, VOS_TRACE_LEVEL_ERROR,
+                         "flushed rssi counters"));
+
+        for(ii = 0; ii < MAX_NUM_RSSI; ii++)
+            tlCtxt->atlSTAClients[staId].trafficStatistics.pktCounterRssi[ii] = 0;
+
+        return;
+    }
+
+    TLLOG1(VOS_TRACE(VOS_MODULE_ID_TL, VOS_TRACE_LEVEL_ERROR, "pkts per RSSI"));
+
+    for(ii = 0; ii < MAX_NUM_RSSI; ii += MAX_RSSI_INTERVAL)
+    {
+        count = 0;
+
+        for(jj = ii; jj < (ii + MAX_RSSI_INTERVAL); jj++)
+            count += tlCtxt->atlSTAClients[staId].trafficStatistics.pktCounterRssi[jj];
+
+        /* prints are in the below format
+         * " fromRSSI - toRSSI = pktCount " */
+        TLLOG1(VOS_TRACE(VOS_MODULE_ID_TL, VOS_TRACE_LEVEL_ERROR,
+                         " %d - %d = %ld",
+                         ii, ii+(MAX_RSSI_INTERVAL - 1), count));
+    }
+
+    return;
+}
+#endif
+
 /*==========================================================================
 
    FUNCTION
@@ -503,7 +595,17 @@
 
    /* TODO caculation is needed, dimension of 500kbps */
    statistics->rxRate = WDA_GET_RX_MAC_RATE_IDX(pBDHeader);
-   
+
+#ifdef WLANTL_DEBUG
+   if( (statistics->rxRate - 1) < MAX_RATE_INDEX)
+     tlCtxt->atlSTAClients[STAid].trafficStatistics.pktCounterRateIdx[statistics->rxRate - 1]++;
+
+   /* Check if the +ve value of RSSI is within the valid range.
+    * And increment pkt counter based on RSSI */
+   if( (v_U16_t)((WDA_GET_RX_RSSI_DB(pBDHeader)) * (-1)) < MAX_NUM_RSSI)
+     tlCtxt->atlSTAClients[STAid].trafficStatistics.pktCounterRssi[(v_U16_t)((WDA_GET_RX_RSSI_DB(pBDHeader)) * (-1))]++;
+#endif
+
    TLLOG1(VOS_TRACE (VOS_MODULE_ID_TL, VOS_TRACE_LEVEL_INFO_MED,
                   "****Received rate Index = %ld type=%d subtype=%d****\n",
                   statistics->rxRate,WDA_GET_RX_TYPE(pBDHeader),WDA_GET_RX_SUBTYPE(pBDHeader)));
diff --git a/Kbuild b/Kbuild
index c7cd1c1..fa2967a 100644
--- a/Kbuild
+++ b/Kbuild
@@ -522,6 +522,7 @@
 		-DWLAN_FEATURE_P2P_DEBUG \
                 -DWLAN_FEATURE_TDLS_DEBUG \
 		-DWLAN_ENABLE_AGEIE_ON_SCAN_RESULTS \
+		-DWLANTL_DEBUG\
 		-DWLAN_ACTIVEMODE_OFFLOAD_FEATURE \
         	-DWLAN_FEATURE_HOLD_RX_WAKELOCK \
 		-DWLAN_SOFTAP_VSTA_FEATURE