Make sure ACKs are always sent after receiving a Probe Response

Previously during active scan, STA will send 5 probe requests
at 0th,10th,20th,30th,40th msec of scan interval.But with MAX
channel timeout at 40th msec, STA after sending probe request,
immediately switches the channel resulting in unacked probe
response.This patch makes sure STA will not send probe request
at MAX channel time slot.Also a dump command to configure num-
ber of probe request is provided.

Change-Id: I3bd9cb917662e8bffcff1b0d5f6a26ed83383de3
CRs-fixed: 507103
diff --git a/CORE/MAC/inc/aniGlobal.h b/CORE/MAC/inc/aniGlobal.h
index fc12fa1..ac91b2f 100644
--- a/CORE/MAC/inc/aniGlobal.h
+++ b/CORE/MAC/inc/aniGlobal.h
@@ -925,6 +925,8 @@
     tSirDFSChannelList    dfschannelList;
     tANI_U8 deauthMsgCnt;
     tANI_U8 gLimIbssStaLimit;
+    tANI_U8 probeCounter;
+    tANI_U8 maxProbe;
 } tAniSirLim, *tpAniSirLim;
 
 typedef struct sLimMgmtFrameRegistration
diff --git a/CORE/MAC/src/pe/lim/limApi.c b/CORE/MAC/src/pe/lim/limApi.c
index 660a3e4..778c9f7 100644
--- a/CORE/MAC/src/pe/lim/limApi.c
+++ b/CORE/MAC/src/pe/lim/limApi.c
@@ -355,6 +355,8 @@
 
     //Scan in Power Save Flag
     pMac->lim.gScanInPowersave = 0;
+    pMac->lim.probeCounter = 0;
+    pMac->lim.maxProbe = 0;
 }
 
 static void __limInitAssocVars(tpAniSirGlobal pMac)
diff --git a/CORE/MAC/src/pe/lim/limLogDump.c b/CORE/MAC/src/pe/lim/limLogDump.c
index 67fd15d..80771c7 100644
--- a/CORE/MAC/src/pe/lim/limLogDump.c
+++ b/CORE/MAC/src/pe/lim/limLogDump.c
@@ -2393,6 +2393,116 @@
 }
 #endif
 
+#ifdef WLAN_FEATURE_RELIABLE_MCAST
+
+static char *
+dump_lim_enable_reliable_mcast_data_path
+(                 
+    tpAniSirGlobal pMac,
+    tANI_U32 arg1,    
+    tANI_U32 arg2,       
+    tANI_U32 arg3,           
+    tANI_U32 arg4,
+    char *p
+)                  
+{
+    v_MACADDR_t reliableMcastTransmitterAddr;
+    v_VOID_t * pVosContext = vos_get_global_context(VOS_MODULE_ID_WDA, NULL);
+
+    reliableMcastTransmitterAddr.bytes[0] = (tANI_U8)((arg1 & 0xFF000000) >> 24);
+    reliableMcastTransmitterAddr.bytes[1] = (tANI_U8)((arg1 & 0x00FF0000) >> 16);
+    reliableMcastTransmitterAddr.bytes[2] = (tANI_U8)((arg1 & 0x0000FF00) >>  8);
+    reliableMcastTransmitterAddr.bytes[3] = (tANI_U8)((arg1 & 0x000000FF));
+    reliableMcastTransmitterAddr.bytes[4] = (tANI_U8)((arg2 & 0xFF000000) >> 24);
+    reliableMcastTransmitterAddr.bytes[5] = (tANI_U8)((arg2 & 0x00FF0000) >> 16);
+
+    limLog(pMac, LOGE,
+        FL("Enable RMCAST data path for MCAST transmitter:" MAC_ADDRESS_STR),
+        MAC_ADDR_ARRAY( reliableMcastTransmitterAddr.bytes));
+
+    /*Input format is in MAC address fromat for example
+      iwpriv wlan0 dump 0xaabbccdd 0xeeff0000 translates into enable RMCAST for
+      MAC address 0xaa:0xbb:0xcc:0xdd:0xee:0xff*/
+
+    /*Enable TL data path*/
+    WLANTL_EnableReliableMcast( pVosContext, &reliableMcastTransmitterAddr );
+
+  return p;
+}
+
+static char *
+dump_lim_disable_reliable_mcast_data_path
+(                 
+    tpAniSirGlobal pMac,
+    tANI_U32 arg1,    
+    tANI_U32 arg2,       
+    tANI_U32 arg3,           
+    tANI_U32 arg4,
+    char *p
+)                  
+{
+    v_MACADDR_t reliableMcastTransmitterAddr;
+    v_VOID_t * pVosContext = vos_get_global_context(VOS_MODULE_ID_WDA, NULL);
+
+    reliableMcastTransmitterAddr.bytes[0] = (tANI_U8)((arg1 & 0xFF000000) >> 24);
+    reliableMcastTransmitterAddr.bytes[1] = (tANI_U8)((arg1 & 0x00FF0000) >> 16);
+    reliableMcastTransmitterAddr.bytes[2] = (tANI_U8)((arg1 & 0x0000FF00) >>  8);
+    reliableMcastTransmitterAddr.bytes[3] = (tANI_U8)((arg1 & 0x000000FF));
+    reliableMcastTransmitterAddr.bytes[4] = (tANI_U8)((arg2 & 0xFF000000) >> 24);
+    reliableMcastTransmitterAddr.bytes[5] = (tANI_U8)((arg2 & 0x00FF0000) >> 16);
+
+
+    limLog(pMac, LOGE,
+        FL("Disable RMCAST data path for MCAST transmitter:" MAC_ADDRESS_STR),
+        MAC_ADDR_ARRAY( reliableMcastTransmitterAddr.bytes));
+
+    /*Input format is in MAC address fromat for example
+      iwpriv wlan0 dump 0xaabbccdd 0xeeff0000 translates into enable RMCAST for
+      MAC address 0xaa:0xbb:0xcc:0xdd:0xee:0xff*/
+
+
+    /*Disable TL data path*/
+    WLANTL_DisableReliableMcast( pVosContext, &reliableMcastTransmitterAddr );
+
+    return p;
+}
+
+static char *
+dump_lim_rmc_status(tpAniSirGlobal pMac, tANI_U32 arg1, tANI_U32 arg2,
+             tANI_U32 arg3, tANI_U32 arg4, char *p)
+{
+    limRmcDumpStatus(pMac);
+    return p;
+}
+
+static char *
+dump_set_mcast_dup_detect(tpAniSirGlobal pMac, tANI_U32 arg1, tANI_U32 arg2,
+             tANI_U32 arg3, tANI_U32 arg4, char *p)
+{
+    v_VOID_t * pVosContext = vos_get_global_context(VOS_MODULE_ID_WDA, NULL);
+    v_U8_t enable;
+
+    enable = (tANI_U8)arg1;
+
+    /* Enable or Disable Multicast Duplicate Detection */
+    WLANTL_SetMcastDuplicateDetection( pVosContext, enable);
+
+    return p;
+}
+#endif /* WLAN_FEATURE_RELIABLE_MCAST */
+
+static char *
+dump_set_max_probe_req(tpAniSirGlobal pMac, tANI_U32 arg1, tANI_U32 arg2,
+             tANI_U32 arg3, tANI_U32 arg4, char *p)
+{
+    if ((arg1 <= 0) || (arg1 > 4)){
+       limLog(pMac, LOGE,
+           FL("invalid number. valid range 1 - 4 \n"));
+       return p;
+    }
+    pMac->lim.maxProbe = arg1;
+    return p;
+}
 /* API to fill Rate Info based on mac efficiency
  * arg 1: mac efficiency to be used to calculate mac thorughput for a given rate index
  * arg 2: starting rateIndex to apply the macEfficiency to
@@ -2481,7 +2591,18 @@
     {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
-    {373,   "PE.LIM: MAS RX stats MAC eff <MAC eff in percentage>",  dump_limRateInfoBasedOnMacEff},
+#ifdef WLAN_FEATURE_RELIABLE_MCAST
+    {371,   "PE.LIM: Enable RMCAST data path in TL for input MCAST addr",
+        dump_lim_enable_reliable_mcast_data_path },
+    {372,   "PE.LIM: Disable RMCAST data path in TL for input MCAST addr",
+        dump_lim_disable_reliable_mcast_data_path },
+    {373,   "PE.LIM: Dump RMCAST transmitter and leader status", dump_lim_rmc_status },
+#endif /* WLAN_FEATURE_RELIABLE_MCAST */           
+    {374,   "PE.LIM: MAS RX stats MAC eff <MAC eff in percentage>",  dump_limRateInfoBasedOnMacEff},
+#ifdef WLAN_FEATURE_RELIABLE_MCAST 
+    {375,   "PE.LIM: Enable(1)/Disable(0) RMCAST duplicate detection", dump_set_mcast_dup_detect },
+#endif /* WLAN_FEATURE_RELIABLE_MCAST */               
+    {376,   "PE.LIM: max number of probe per scan", dump_set_max_probe_req },
 };
 
 
diff --git a/CORE/MAC/src/pe/lim/limProcessMlmReqMessages.c b/CORE/MAC/src/pe/lim/limProcessMlmReqMessages.c
index c351731..a4a9882 100644
--- a/CORE/MAC/src/pe/lim/limProcessMlmReqMessages.c
+++ b/CORE/MAC/src/pe/lim/limProcessMlmReqMessages.c
@@ -440,6 +440,7 @@
         TX_TIMER *periodicScanTimer;
         PELOG2(limLog(pMac, LOG2, FL("ACTIVE Scan chan %d, sending probe"), channelNum);)
 
+        pMac->lim.probeCounter++;
         do
         {
             /* Prepare and send Probe Request frame for all the SSIDs present in the saved MLM 
@@ -3751,6 +3752,7 @@
         pMac->lim.limTimers.gLimPeriodicProbeReqTimer.sessionId = 0xff;
         limDeactivateAndChangeTimer(pMac, eLIM_MIN_CHANNEL_TIMER);
         limDeactivateAndChangeTimer(pMac, eLIM_PERIODIC_PROBE_REQ_TIMER);
+        pMac->lim.probeCounter = 0;
         if (pMac->lim.gLimCurrentScanChannelId <=
                 (tANI_U32)(pMac->lim.gpLimMlmScanReq->channelList.numChannels - 1))
         {
@@ -3827,6 +3829,8 @@
         limDeactivateAndChangeTimer(pMac, eLIM_MAX_CHANNEL_TIMER);
         limDeactivateAndChangeTimer(pMac, eLIM_PERIODIC_PROBE_REQ_TIMER);
         pMac->lim.limTimers.gLimPeriodicProbeReqTimer.sessionId = 0xff;
+        pMac->lim.probeCounter = 0;
+
         if (pMac->lim.gLimCurrentScanChannelId <=
                 (tANI_U32)(pMac->lim.gpLimMlmScanReq->channelList.numChannels - 1))
         {
@@ -3896,10 +3900,11 @@
     }
 
     if ((pMac->lim.gLimMlmState == eLIM_MLM_WT_PROBE_RESP_STATE) &&
-        (pPeriodicProbeReqTimer->sessionId != 0xff))
+        (pPeriodicProbeReqTimer->sessionId != 0xff) && (pMac->lim.probeCounter < pMac->lim.maxProbe))
     {
         tLimMlmScanReq *pLimMlmScanReq = pMac->lim.gpLimMlmScanReq;
         PELOG1(limLog(pMac, LOG1, FL("Scanning : Periodic scanning"));)
+        pMac->lim.probeCounter++;
         /**
          * Periodic channel timer timed out
          * to send probe request.
diff --git a/CORE/MAC/src/pe/lim/limProcessMlmRspMessages.c b/CORE/MAC/src/pe/lim/limProcessMlmRspMessages.c
index c248274..76bb3d3 100644
--- a/CORE/MAC/src/pe/lim/limProcessMlmRspMessages.c
+++ b/CORE/MAC/src/pe/lim/limProcessMlmRspMessages.c
@@ -3519,6 +3519,7 @@
                  */
                 pMac->lim.gLimNumOfConsecutiveBkgndScanFailure = 0;
                 pMac->lim.gLimNumOfBackgroundScanSuccess += 1;
+                pMac->lim.probeCounter = 0;
             }
             limContinueChannelScan(pMac);
             break;
diff --git a/CORE/MAC/src/pe/lim/limTimerUtils.c b/CORE/MAC/src/pe/lim/limTimerUtils.c
index 6dce210..f1e5878 100644
--- a/CORE/MAC/src/pe/lim/limTimerUtils.c
+++ b/CORE/MAC/src/pe/lim/limTimerUtils.c
@@ -101,6 +101,7 @@
 limCreateTimers(tpAniSirGlobal pMac)
 {
     tANI_U32 cfgValue, i=0;
+    tANI_U32 cfgValue1;
 
     PELOG1(limLog(pMac, LOG1, FL("Creating Timers used by LIM module in Role %d"), pMac->lim.gLimSystemRole);)
 
@@ -134,14 +135,14 @@
      * timer expires
      */
 
-    cfgValue = cfgValue/2 ;
-    if( cfgValue >= 1)
+    cfgValue1 = cfgValue/2 ;
+    if( cfgValue1 >= 1)
     {
         // Create periodic probe request timer and activate them later
         if (tx_timer_create(&pMac->lim.limTimers.gLimPeriodicProbeReqTimer,
                            "Periodic Probe Request Timer",
                            limTimerHandler, SIR_LIM_PERIODIC_PROBE_REQ_TIMEOUT,
-                           cfgValue, 0,
+                           cfgValue1, 0,
                            TX_NO_ACTIVATE) != TX_SUCCESS)
         {
            /// Could not start Periodic Probe Req timer.
@@ -164,6 +165,9 @@
     }
     cfgValue = SYS_MS_TO_TICKS(cfgValue);
 
+    /* Limiting max numm of probe req for each channel scan */
+    pMac->lim.maxProbe = (cfgValue/cfgValue1);
+
     if (tx_timer_create(&pMac->lim.limTimers.gLimMaxChannelTimer,
                         "MAX CHANNEL TIMEOUT",
                         limTimerHandler, SIR_LIM_MAX_CHANNEL_TIMEOUT,