wlan: Added ioctl to enable/disable Traffic Monitor Feature Dynamically

Added ioctl to enable/disable Traffic Monitor Feature Dynamically

Change-Id: I63f389295ca94b9b27c9b8df5cb1274fc616afbd
CRs-fixed: 567334
diff --git a/CORE/HDD/src/wlan_hdd_softap_tx_rx.c b/CORE/HDD/src/wlan_hdd_softap_tx_rx.c
index 6b78c63..035b045 100644
--- a/CORE/HDD/src/wlan_hdd_softap_tx_rx.c
+++ b/CORE/HDD/src/wlan_hdd_softap_tx_rx.c
@@ -125,6 +125,8 @@
    if (pHddCtx->cfg_ini->trafficIdleTimeout <
        (currentTS - pHddCtx->traffic_monitor.lastFrameTs))
    {
+      VOS_TRACE( VOS_MODULE_ID_HDD_SOFTAP, VOS_TRACE_LEVEL_INFO,
+          "%s: No Data Activity calling Wlan Suspend", __func__ );
       hdd_set_wlan_suspend_mode(1);
       atomic_set(&pHddCtx->traffic_monitor.isActiveMode, 0);
    }
@@ -137,6 +139,79 @@
    return;
 }
 
+VOS_STATUS hdd_start_trafficMonitor( hdd_adapter_t *pAdapter )
+{
+
+    hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
+    VOS_STATUS status = VOS_STATUS_SUCCESS;
+
+    status = wlan_hdd_validate_context(pHddCtx);
+
+    if (0 != status)
+    {
+        VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
+                   "%s: HDD context is not valid", __func__);
+        return status;
+    }
+
+    if ((pHddCtx->cfg_ini->enableTrafficMonitor) &&
+        (!pHddCtx->traffic_monitor.isInitialized))
+    {
+        atomic_set(&pHddCtx->traffic_monitor.isActiveMode, 1);
+        vos_timer_init(&pHddCtx->traffic_monitor.trafficTimer,
+                      VOS_TIMER_TYPE_SW,
+                      hdd_softap_traffic_monitor_timeout_handler,
+                      pHddCtx);
+        vos_lock_init(&pHddCtx->traffic_monitor.trafficLock);
+        pHddCtx->traffic_monitor.isInitialized = 1;
+        pHddCtx->traffic_monitor.lastFrameTs   = 0;
+        /* Start traffic monitor timer here
+         * If no AP assoc, immediatly go into suspend */
+        VOS_TRACE( VOS_MODULE_ID_HDD_SOFTAP, VOS_TRACE_LEVEL_INFO,
+                  "%s  Start Traffic Monitor Timer", __func__);
+        vos_timer_start(&pHddCtx->traffic_monitor.trafficTimer,
+                      pHddCtx->cfg_ini->trafficIdleTimeout);
+    }
+    else
+    {
+        VOS_TRACE( VOS_MODULE_ID_HDD_SOFTAP, VOS_TRACE_LEVEL_INFO,
+                  "%s  Traffic Monitor is not Enable in ini file", __func__);
+    }
+    return status;
+}
+
+VOS_STATUS hdd_stop_trafficMonitor( hdd_adapter_t *pAdapter )
+{
+    hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
+    VOS_STATUS status = VOS_STATUS_SUCCESS;
+
+    status = wlan_hdd_validate_context(pHddCtx);
+
+    if (0 != status)
+    {
+        VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
+                   "%s: HDD context is not valid", __func__);
+        return status;
+    }
+
+    if (pHddCtx->traffic_monitor.isInitialized)
+    {
+        if (VOS_TIMER_STATE_STOPPED !=
+            vos_timer_getCurrentState(&pHddCtx->traffic_monitor.trafficTimer))
+        {
+            VOS_TRACE( VOS_MODULE_ID_HDD_SOFTAP, VOS_TRACE_LEVEL_INFO,
+                      "%s  Stop Traffic Monitor Timer", __func__);
+            vos_timer_stop(&pHddCtx->traffic_monitor.trafficTimer);
+        }
+        VOS_TRACE( VOS_MODULE_ID_HDD_SOFTAP, VOS_TRACE_LEVEL_INFO,
+                  "%s  Destroy Traffic Monitor Timer", __func__);
+        vos_timer_destroy(&pHddCtx->traffic_monitor.trafficTimer);
+        vos_lock_destroy(&pHddCtx->traffic_monitor.trafficLock);
+        pHddCtx->traffic_monitor.isInitialized = 0;
+    }
+    return status;
+}
+
 /**============================================================================
   @brief hdd_softap_flush_tx_queues() - Utility function to flush the TX queues
 
@@ -578,8 +653,6 @@
                            HDD_SOFTAP_VO_WEIGHT_DEFAULT
                          };
 
-   hdd_context_t *pHddCtx = NULL;
-
    pAdapter->isVosOutOfResource = VOS_FALSE;
    pAdapter->isVosLowResource = VOS_FALSE;
 
@@ -607,35 +680,15 @@
       }
    }
 
-   pHddCtx = (hdd_context_t *)pAdapter->pHddCtx;
-   if (NULL == pHddCtx)
-   {
-      VOS_TRACE( VOS_MODULE_ID_HDD_SOFTAP, VOS_TRACE_LEVEL_ERROR,
-                 "%s: Invalid HDD cntxt", __func__ );
-      return VOS_STATUS_E_INVAL;
-   }
-
    /* Update the AC weights suitable for SoftAP mode of operation */
    WLANTL_SetACWeights((WLAN_HDD_GET_CTX(pAdapter))->pvosContext, pACWeights);
 
-   /* Initialize SAP/P2P-GO traffin monitor */
-   if ((pHddCtx->cfg_ini->enableTrafficMonitor) &&
-       (!pHddCtx->traffic_monitor.isInitialized))
+   if (VOS_STATUS_SUCCESS != hdd_start_trafficMonitor(pAdapter))
    {
-      atomic_set(&pHddCtx->traffic_monitor.isActiveMode, 1);
-      vos_timer_init(&pHddCtx->traffic_monitor.trafficTimer,
-                     VOS_TIMER_TYPE_SW,
-                     hdd_softap_traffic_monitor_timeout_handler,
-                     pHddCtx);
-      vos_lock_init(&pHddCtx->traffic_monitor.trafficLock);
-      pHddCtx->traffic_monitor.isInitialized = 1;
-      pHddCtx->traffic_monitor.lastFrameTs   = 0;
-      /* Start traffic monitor timer here
-       * If no AP assoc, immediatly go into suspend */
-      vos_timer_start(&pHddCtx->traffic_monitor.trafficTimer,
-                      pHddCtx->cfg_ini->trafficIdleTimeout);
+       VOS_TRACE( VOS_MODULE_ID_HDD_SOFTAP, VOS_TRACE_LEVEL_ERROR,
+          "%s: failed to start Traffic Monito timer ", __func__ );
+       return VOS_STATUS_E_INVAL;
    }
-
    return status;
 }
 
@@ -650,25 +703,12 @@
 VOS_STATUS hdd_softap_deinit_tx_rx( hdd_adapter_t *pAdapter )
 {
    VOS_STATUS status = VOS_STATUS_SUCCESS;
-   hdd_context_t *pHddCtx = NULL;
 
-   pHddCtx = (hdd_context_t *)pAdapter->pHddCtx;
-   if (NULL == pHddCtx)
+   if (VOS_STATUS_SUCCESS != hdd_stop_trafficMonitor(pAdapter))
    {
-      VOS_TRACE( VOS_MODULE_ID_HDD_SOFTAP, VOS_TRACE_LEVEL_ERROR,
-                 "%s: Invalid HDD cntxt", __func__ );
-      return VOS_STATUS_E_INVAL;
-   }
-   if (pHddCtx->traffic_monitor.isInitialized)
-   {
-      if (VOS_TIMER_STATE_STOPPED !=
-          vos_timer_getCurrentState(&pHddCtx->traffic_monitor.trafficTimer))
-      {
-         vos_timer_stop(&pHddCtx->traffic_monitor.trafficTimer);
-      }
-      vos_timer_destroy(&pHddCtx->traffic_monitor.trafficTimer);
-      vos_lock_destroy(&pHddCtx->traffic_monitor.trafficLock);
-      pHddCtx->traffic_monitor.isInitialized = 0;
+       VOS_TRACE( VOS_MODULE_ID_HDD_SOFTAP, VOS_TRACE_LEVEL_ERROR,
+                 "%s: Fail to Stop Traffic Monito timer", __func__ );
+       return VOS_STATUS_E_INVAL;
    }
 
    status = hdd_softap_flush_tx_queues(pAdapter);