Fix for the crash in wlan_hdd_tdls_update_peer_cb

Prevent the start of the update peer timer with mutex lock when
we enable implicit trigger or we connect to an AP.
Enable the rescheduling of scan till all the TDLS link torn down
when there is already some TDLS link.
Check the device mode with WLAN_HDD_INFRA_STATION or
WLAN_HDD_P2P_CLIENT while going through the adapters in function
wlan_hdd_tdls_set_mode.

Change-Id: I496ecf90a55efb8e6dbb865e8346f86cb1675af3
CRs-Fixed: 464577, 466452
diff --git a/CORE/HDD/src/wlan_hdd_cfg80211.c b/CORE/HDD/src/wlan_hdd_cfg80211.c
index a8070f9..678baba 100755
--- a/CORE/HDD/src/wlan_hdd_cfg80211.c
+++ b/CORE/HDD/src/wlan_hdd_cfg80211.c
@@ -4196,6 +4196,10 @@
      * to process the connect request to AP */
     hdd_allow_suspend_timeout(100);
 
+#ifdef FEATURE_WLAN_TDLS
+    wlan_hdd_tdls_scan_done_callback(pAdapter);
+#endif
+
     EXIT();
     return 0;
 }
@@ -4357,28 +4361,21 @@
         return -EBUSY;
     }
 #ifdef FEATURE_WLAN_TDLS
-    if (wlan_hdd_tdlsConnectedPeers(pAdapter))
-    {
-        tANI_U8 staIdx;
-
-        for (staIdx = 0; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
-        {
-            if (pHddCtx->tdlsConnInfo[staIdx].staId)
-            {
-                VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
-                          ("scan: indicate TDLS teadown (staId %d)"), pHddCtx->tdlsConnInfo[staIdx].staId);
-            }
-#ifdef CONFIG_TDLS_IMPLICIT
-            cfg80211_tdls_oper_request(pAdapter->dev,
-                                       pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes,
-                                       NL80211_TDLS_TEARDOWN,
-                                       eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON,
-                                       GFP_KERNEL);
+    /* if tdls disagree scan right now, return immediately.
+       tdls will schedule the scan when scan is allowed. (return SUCCESS)
+       or will reject the scan if any TDLS is in progress. (return -EBUSY)
+    */
+    status = wlan_hdd_tdls_scan_callback (pAdapter,
+                                          wiphy,
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
+                                          dev,
 #endif
-        }
-        return -EBUSY;
+                                          request);
+    if(status <= 0)
+    {
+        hddLog(VOS_TRACE_LEVEL_INFO, "%s: TDLS Pending %d", __func__, status);
+        return status;
     }
-
 #endif
 
     if (mutex_lock_interruptible(&pHddCtx->tmInfo.tmOperationLock))