Fix to delete all connected tdls peer

We are not clearing the TDLS peers information from lim/sme
and also not unregistering the peers from TL when we are
getting diassoc/deauth from the AP in case we are leaving
the BSS or AP goes down. Also, we are not sending teardown
or deauth frame on direct link to all the connected peers.

CRs-Fixed: 445085
Change-Id: Ia701d287ddb9059abe1af89fab2f691d952d4129
diff --git a/CORE/HDD/src/wlan_hdd_assoc.c b/CORE/HDD/src/wlan_hdd_assoc.c
index 4f0baed..44fe9d9 100755
--- a/CORE/HDD/src/wlan_hdd_assoc.c
+++ b/CORE/HDD/src/wlan_hdd_assoc.c
@@ -1876,6 +1876,7 @@
 {
     hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
     eHalStatus status = eHAL_STATUS_FAILURE ;
+    tANI_U8 staIdx;
 
 #ifdef WLAN_FEATURE_TDLS_DEBUG
     VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
@@ -1883,6 +1884,7 @@
       roamResult == eCSR_ROAM_RESULT_ADD_TDLS_PEER ? "ADD_TDLS_PEER" :
       roamResult == eCSR_ROAM_RESULT_DELETE_TDLS_PEER ? "DEL_TDLS_PEER" :
       roamResult == eCSR_ROAM_RESULT_TEARDOWN_TDLS_PEER_IND ? "DEL_TDLS_PEER_IND" :
+      roamResult == eCSR_ROAM_RESULT_DELETE_ALL_TDLS_PEER_IND? "DEL_ALL_TDLS_PEER_IND" :
       "UNKNOWN",
        pRoamInfo->staId,
        pRoamInfo->peerMac[0],
@@ -1896,8 +1898,6 @@
     {
         case eCSR_ROAM_RESULT_ADD_TDLS_PEER:
         {
-            tANI_U8 staIdx = 0 ;
-
             if(eSIR_SME_SUCCESS != pRoamInfo->statusCode)
             {
                 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
@@ -1908,8 +1908,7 @@
              * check if there is available index for this new TDLS STA
              * since TDLS is setup in BSS, we need to start from +1
              */
-            for ( staIdx = 0 ; 
-                             staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++ )
+            for ( staIdx = 1; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++ )
             {
                 if (0 == pHddStaCtx->conn_info.staId[staIdx] )
                 {
@@ -1949,33 +1948,29 @@
             break ;
         }
         case eCSR_ROAM_RESULT_DELETE_TDLS_PEER:
-        {         
-            tANI_U8 staIdx = 0 ;
-            status = eHAL_STATUS_FAILURE ;
-
-            for ( staIdx = 0 ; 
-                             staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++ )
+        {
+            /* 0 staIdx is assigned to AP we dont want to touch that */
+            for ( staIdx = 1; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++ )
             {
                 if (pRoamInfo->staId == pHddStaCtx->conn_info.staId[staIdx] )
                 {
+                    VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
+                                   ("HDD: del STA IDX = %x"), pRoamInfo->staId) ;
+
+                    wlan_hdd_tdls_reset_peer(pRoamInfo->peerMac);
+                    hdd_roamDeregisterTDLSSTA ( pAdapter, pRoamInfo->staId );
+
+                    (WLAN_HDD_GET_CTX(pAdapter))->sta_to_adapter[pRoamInfo->staId] = NULL;
+
                     pHddStaCtx->conn_info.staId[staIdx] = 0 ;
                     vos_mem_zero(&pHddStaCtx->conn_info.peerMacAddress[staIdx],
                                                sizeof(v_MACADDR_t)) ;
                     status = eHAL_STATUS_SUCCESS ;
-
                     break ;
                 }
             }
-            if(eHAL_STATUS_SUCCESS == status)
-            {
-                VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
-                               ("HDD: del STA IDX = %x\n"), pRoamInfo->staId) ;
-                wlan_hdd_tdls_reset_peer(pRoamInfo->peerMac);
-                hdd_roamDeregisterTDLSSTA ( pAdapter, pRoamInfo->staId );
-                (WLAN_HDD_GET_CTX(pAdapter))->sta_to_adapter[pRoamInfo->staId] = NULL;
-            }
-            break ; 
         }
+        break ;
         case eCSR_ROAM_RESULT_TEARDOWN_TDLS_PEER_IND:
         {
             VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
@@ -1989,6 +1984,36 @@
                                        pRoamInfo->reasonCode,
                                        GFP_KERNEL);
 #endif
+            status = eHAL_STATUS_SUCCESS ;
+            break ;
+        }
+        case eCSR_ROAM_RESULT_DELETE_ALL_TDLS_PEER_IND:
+        {
+            /* 0 staIdx is assigned to AP we dont want to touch that */
+            for ( staIdx = 1; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++ )
+            {
+                if (pHddStaCtx->conn_info.staId[staIdx])
+                {
+                    VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
+                              ("hdd_tdlsStatusUpdate: staIdx %d %02x:%02x:%02x:%02x:%02x:%02x"),
+                                pHddStaCtx->conn_info.staId[staIdx],
+                                pHddStaCtx->conn_info.peerMacAddress[staIdx].bytes[0],
+                                pHddStaCtx->conn_info.peerMacAddress[staIdx].bytes[1],
+                                pHddStaCtx->conn_info.peerMacAddress[staIdx].bytes[2],
+                                pHddStaCtx->conn_info.peerMacAddress[staIdx].bytes[3],
+                                pHddStaCtx->conn_info.peerMacAddress[staIdx].bytes[4],
+                                pHddStaCtx->conn_info.peerMacAddress[staIdx].bytes[5]) ;
+                    wlan_hdd_tdls_reset_peer(pHddStaCtx->conn_info.peerMacAddress[staIdx].bytes);
+                    hdd_roamDeregisterTDLSSTA ( pAdapter,  pHddStaCtx->conn_info.staId[staIdx] );
+
+                    (WLAN_HDD_GET_CTX(pAdapter))->sta_to_adapter[staIdx] = NULL;
+                    vos_mem_zero(&pHddStaCtx->conn_info.peerMacAddress[staIdx],
+                                               sizeof(v_MACADDR_t)) ;
+                    pHddStaCtx->conn_info.staId[staIdx] = 0 ;
+
+                    status = eHAL_STATUS_SUCCESS ;
+                }
+            }
             break ;
         }
         default:
diff --git a/CORE/HDD/src/wlan_hdd_cfg80211.c b/CORE/HDD/src/wlan_hdd_cfg80211.c
index 7076e29..1634b92 100755
--- a/CORE/HDD/src/wlan_hdd_cfg80211.c
+++ b/CORE/HDD/src/wlan_hdd_cfg80211.c
@@ -5330,6 +5330,9 @@
                     &(WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter))->roamProfile;
     int status = 0;
     hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
+#ifdef FEATURE_WLAN_TDLS
+    tANI_U8 staIdx;
+#endif
     
     ENTER();
     
@@ -5378,6 +5381,18 @@
             (WLAN_HDD_GET_CTX(pAdapter))->isAmpAllowed = VOS_TRUE;
             INIT_COMPLETION(pAdapter->disconnect_comp_var);
 
+#ifdef FEATURE_WLAN_TDLS
+            /* First clean up the tdls peers if any */
+            for (staIdx = 1 ; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
+            {
+                if (pHddStaCtx->conn_info.staId[staIdx])
+                {
+                    sme_DeleteTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
+                              pAdapter->sessionId,
+                              pHddStaCtx->conn_info.peerMacAddress[staIdx].bytes);
+                }
+            }
+#endif
             /*issue disconnect*/
             status = sme_RoamDisconnect( WLAN_HDD_GET_HAL_CTX(pAdapter), 
                                          pAdapter->sessionId, reasonCode);
diff --git a/CORE/HDD/src/wlan_hdd_tdls.c b/CORE/HDD/src/wlan_hdd_tdls.c
index 0089925..4380554 100644
--- a/CORE/HDD/src/wlan_hdd_tdls.c
+++ b/CORE/HDD/src/wlan_hdd_tdls.c
@@ -88,14 +88,18 @@
         list_for_each (pos, head) {
             curr_peer = list_entry (pos, hddTdlsPeer_t, node);
 
-            VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
-                       "%d %02x:%02x:%02x:%02x:%02x:%02x", i,
+            VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
+                       "%d %02x:%02x:%02x:%02x:%02x:%02x %d %d %d %d", i,
                        curr_peer->peerMac[0],
                        curr_peer->peerMac[1],
                        curr_peer->peerMac[2],
                        curr_peer->peerMac[3],
                        curr_peer->peerMac[4],
-                       curr_peer->peerMac[5]);
+                       curr_peer->peerMac[5],
+                       curr_peer->tdls_support,
+                       curr_peer->link_status,
+                       curr_peer->discovery_attempt,
+                       pHddTdlsCtx->threshold_config.discovery_tries_n);
 
             if ((eTDLS_CAP_UNKNOWN == curr_peer->tdls_support) &&
                 (eTDLS_LINK_NOT_CONNECTED == curr_peer->link_status) &&
@@ -703,7 +707,8 @@
     pAdapter = WLAN_HDD_GET_PRIV_PTR(pHddTdlsCtx->dev);
     pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
 
-    for (staIdx = 0 ; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
+    /* 0 staIdx is assigned to AP we dont want to touch that */
+    for (staIdx = 1 ; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
     {
         if (0 != pHddStaCtx->conn_info.staId[staIdx] )
             count++;