wlan: Do not attempt TDLS connection in case of concurrency.

Currently TDLS is operational only when there is a single
active session. Hence, ensure that TDLS sessions are not
created during multiple active concurrent sessions.
Thus , this commit speaks to not attempt TDLS connection when
another concurrent session is trying to get established.
This goes with the assumption that before the concurrent
session is attempted to form , the supplicant shall issue
the scan's which shall ensure that the TDLS sessions on the
current active session are deleted / torn down.
CRs-Fixed: 669605
Change-Id: I7ebfa1c43251b86a522f5f66939083fd04c1ff7d
diff --git a/CORE/HDD/inc/wlan_hdd_tdls.h b/CORE/HDD/inc/wlan_hdd_tdls.h
index d032bcd..0cc6bba 100644
--- a/CORE/HDD/inc/wlan_hdd_tdls.h
+++ b/CORE/HDD/inc/wlan_hdd_tdls.h
@@ -185,7 +185,9 @@
     v_MACADDR_t peerMac;
 } tdlsConnInfo_t;
 
-int wlan_hdd_tdls_init(hdd_adapter_t *pAdapter);
+int wlan_hdd_sta_tdls_init(hdd_adapter_t *pAdapter);
+
+void wlan_hdd_tdls_init(hdd_context_t * pHddCtx);
 
 void wlan_hdd_tdls_exit(hdd_adapter_t *pAdapter);
 
diff --git a/CORE/HDD/src/wlan_hdd_cfg80211.c b/CORE/HDD/src/wlan_hdd_cfg80211.c
index 4ad62e6..a3e6d06 100644
--- a/CORE/HDD/src/wlan_hdd_cfg80211.c
+++ b/CORE/HDD/src/wlan_hdd_cfg80211.c
@@ -6405,7 +6405,7 @@
 
                 if ( pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
                 {
-                    if (0 != wlan_hdd_tdls_init (pAdapter))
+                    if (0 != wlan_hdd_sta_tdls_init (pAdapter))
                     {
                         hddLog(VOS_TRACE_LEVEL_ERROR,
                             "%s: tdls initialization failed", __func__);
@@ -12714,6 +12714,12 @@
 
         return -ENOTSUPP;
         }
+
+        if (vos_max_concurrent_connections_reached())
+        {
+            hddLog(VOS_TRACE_LEVEL_INFO, FL("Reached max concurrent connections"));
+            return -EINVAL;
+        }
     }
 
     if (WLAN_IS_TDLS_SETUP_ACTION(action_code))
diff --git a/CORE/HDD/src/wlan_hdd_early_suspend.c b/CORE/HDD/src/wlan_hdd_early_suspend.c
index 08e5f60..1e2e3c5 100644
--- a/CORE/HDD/src/wlan_hdd_early_suspend.c
+++ b/CORE/HDD/src/wlan_hdd_early_suspend.c
@@ -2226,7 +2226,7 @@
    vos_set_logp_in_progress(VOS_MODULE_ID_VOSS, FALSE);
    pHddCtx->hdd_mcastbcast_filter_set = FALSE;
    hdd_register_mcast_bcast_filter(pHddCtx);
-
+   wlan_hdd_tdls_init(pHddCtx);
    /* Register with platform driver as client for Suspend/Resume */
    vosStatus = hddRegisterPmOps(pHddCtx);
    if ( !VOS_IS_STATUS_SUCCESS( vosStatus ) )
diff --git a/CORE/HDD/src/wlan_hdd_main.c b/CORE/HDD/src/wlan_hdd_main.c
index d919ca1..d5c1f60 100644
--- a/CORE/HDD/src/wlan_hdd_main.c
+++ b/CORE/HDD/src/wlan_hdd_main.c
@@ -5833,10 +5833,10 @@
    set_bit(WMM_INIT_DONE, &pAdapter->event_flags);
 
 #ifdef FEATURE_WLAN_TDLS
-   if(0 != wlan_hdd_tdls_init(pAdapter))
+   if(0 != wlan_hdd_sta_tdls_init(pAdapter))
    {
        status = VOS_STATUS_E_FAILURE;
-       hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wlan_hdd_tdls_init failed",__func__);
+       hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wlan_hdd_sta_tdls_init failed",__func__);
        goto error_tdls_init;
    }
    set_bit(TDLS_INIT_DONE, &pAdapter->event_flags);
@@ -8927,6 +8927,8 @@
    }
 #endif
 
+   wlan_hdd_tdls_init(pHddCtx);
+
    sme_Register11dScanDoneCallback(pHddCtx->hHal, hdd_11d_scan_done);
 
    /* Register with platform driver as client for Suspend/Resume */
diff --git a/CORE/HDD/src/wlan_hdd_tdls.c b/CORE/HDD/src/wlan_hdd_tdls.c
index 2b40444..e228607 100644
--- a/CORE/HDD/src/wlan_hdd_tdls.c
+++ b/CORE/HDD/src/wlan_hdd_tdls.c
@@ -616,13 +616,42 @@
                            scan_ctx->scan_request);
 }
 
+/* initialize TDLS global context */
+void  wlan_hdd_tdls_init(hdd_context_t *pHddCtx )
+{
+    v_U8_t staIdx;
 
-int wlan_hdd_tdls_init(hdd_adapter_t *pAdapter)
+    pHddCtx->connected_peer_count = 0;
+
+    pHddCtx->tdls_scan_ctxt.magic = 0;
+    pHddCtx->tdls_scan_ctxt.attempt = 0;
+    pHddCtx->tdls_scan_ctxt.reject = 0;
+    pHddCtx->tdls_scan_ctxt.scan_request = NULL;
+
+    for (staIdx = 0; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
+    {
+         pHddCtx->tdlsConnInfo[staIdx].staId = 0;
+         pHddCtx->tdlsConnInfo[staIdx].sessionId = 255;
+         vos_mem_zero(&pHddCtx->tdlsConnInfo[staIdx].peerMac,
+                                            sizeof(v_MACADDR_t)) ;
+    }
+
+    if (FALSE == pHddCtx->cfg_ini->fEnableTDLSImplicitTrigger)
+    {
+        pHddCtx->tdls_mode = eTDLS_SUPPORT_EXPLICIT_TRIGGER_ONLY;
+        hddLog(VOS_TRACE_LEVEL_ERROR, "%s TDLS Implicit trigger not enabled!", __func__);
+    }
+    else
+    {
+        pHddCtx->tdls_mode = eTDLS_SUPPORT_ENABLED;
+    }
+}
+
+int wlan_hdd_sta_tdls_init(hdd_adapter_t *pAdapter)
 {
     hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
     tdlsCtx_t *pHddTdlsCtx;
     int i;
-    v_U8_t staIdx;
 
     if (NULL == pHddCtx)
         return -1;
@@ -694,23 +723,8 @@
 
     pHddTdlsCtx = pAdapter->sessionCtx.station.pHddTdlsCtx;
 
-    /* initialize TDLS global context */
-    pHddCtx->connected_peer_count = 0;
     sme_SetTdlsPowerSaveProhibited(WLAN_HDD_GET_HAL_CTX(pAdapter), 0);
 
-    pHddCtx->tdls_scan_ctxt.magic = 0;
-    pHddCtx->tdls_scan_ctxt.attempt = 0;
-    pHddCtx->tdls_scan_ctxt.reject = 0;
-    pHddCtx->tdls_scan_ctxt.scan_request = NULL;
-
-    for (staIdx = 0; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
-    {
-         pHddCtx->tdlsConnInfo[staIdx].staId = 0;
-         pHddCtx->tdlsConnInfo[staIdx].sessionId = 255;
-         vos_mem_zero(&pHddCtx->tdlsConnInfo[staIdx].peerMac,
-                                            sizeof(v_MACADDR_t)) ;
-    }
-
     pHddTdlsCtx->pAdapter = pAdapter;
 
     for (i = 0; i < 256; i++)
@@ -732,15 +746,6 @@
     pHddTdlsCtx->threshold_config.rssi_trigger_threshold = pHddCtx->cfg_ini->fTDLSRSSITriggerThreshold;
     pHddTdlsCtx->threshold_config.rssi_teardown_threshold = pHddCtx->cfg_ini->fTDLSRSSITeardownThreshold;
 
-    if (FALSE == pHddCtx->cfg_ini->fEnableTDLSImplicitTrigger)
-    {
-        pHddCtx->tdls_mode = eTDLS_SUPPORT_EXPLICIT_TRIGGER_ONLY;
-        hddLog(VOS_TRACE_LEVEL_ERROR, "%s TDLS Implicit trigger not enabled!", __func__);
-    }
-    else
-    {
-        pHddCtx->tdls_mode = eTDLS_SUPPORT_ENABLED;
-    }
     INIT_WORK(&pHddTdlsCtx->implicit_setup, wlan_hdd_tdls_pre_setup);
     INIT_DELAYED_WORK(&pHddCtx->tdls_scan_ctxt.tdls_scan_work, wlan_hdd_tdls_schedule_scan);
     mutex_unlock(&pHddCtx->tdls_lock);