Fix for the VOS_ASSERT in add station time.

Change the TDLS capability to eTDLS_CAP_SUPPORTED at the time of
sending discovery response or set_up response to the peer device.
Clean up some debug prints for easing the debugging.

CRs-Fixed: 462352
Change-Id: I668a51ebd00663dbd17fdacc4bc10050718701f0
diff --git a/CORE/HDD/inc/wlan_hdd_tdls.h b/CORE/HDD/inc/wlan_hdd_tdls.h
index 7b2d753..c1cc03d 100644
--- a/CORE/HDD/inc/wlan_hdd_tdls.h
+++ b/CORE/HDD/inc/wlan_hdd_tdls.h
@@ -155,7 +155,7 @@
 
 hddTdlsPeer_t *wlan_hdd_tdls_get_peer(hdd_adapter_t *pAdapter, u8 *mac);
 
-void wlan_hdd_tdls_set_cap(hdd_adapter_t *pAdapter, u8* mac, tTDLSCapType cap);
+int wlan_hdd_tdls_set_cap(hdd_adapter_t *pAdapter, u8* mac, tTDLSCapType cap);
 
 void wlan_hdd_tdls_set_peer_link_status(hddTdlsPeer_t *curr_peer, tTDLSLinkStatus status);
 
@@ -191,6 +191,8 @@
 
 void wlan_hdd_tdls_check_bmps(hdd_adapter_t *pAdapter);
 
+u8 wlan_hdd_tdls_is_peer_progress(hdd_adapter_t *pAdapter, u8 *mac);
+
 u8 wlan_hdd_tdls_is_progress(hdd_adapter_t *pAdapter, u8* mac, u8 skip_self);
 
 void wlan_hdd_tdls_set_mode(hdd_context_t *pHddCtx, eTDLSSupportMode tdls_mode);
@@ -199,6 +201,6 @@
 
 tANI_U32 wlan_hdd_tdls_discovery_sent_cnt(hdd_context_t *pHddCtx);
 
-void wlan_hdd_tdls_set_power_save_prohibited(hdd_adapter_t *pAdapter);
+void wlan_hdd_tdls_check_power_save_prohibited(hdd_adapter_t *pAdapter);
 
 #endif // __HDD_TDSL_H
diff --git a/CORE/HDD/src/wlan_hdd_cfg80211.c b/CORE/HDD/src/wlan_hdd_cfg80211.c
index 4891e9e..50bc480 100755
--- a/CORE/HDD/src/wlan_hdd_cfg80211.c
+++ b/CORE/HDD/src/wlan_hdd_cfg80211.c
@@ -2725,7 +2725,18 @@
         return -EBUSY;
     }
 
-    if ((0 == update) && wlan_hdd_tdls_is_progress(pAdapter, mac, FALSE))
+    /* when self is on-going, we dont' want to change link_status */
+    if ((0 == update) && wlan_hdd_tdls_is_peer_progress(pAdapter, mac))
+    {
+        VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
+                   "%s: " MAC_ADDRESS_STR
+                   " TDLS setup is ongoing. Request declined.",
+                   __func__, MAC_ADDR_ARRAY(mac));
+        return -EPERM;
+    }
+
+    /* when others are on-going, we want to change link_status to idle */
+    if (wlan_hdd_tdls_is_progress(pAdapter, mac, TRUE))
     {
         VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
                    "%s: " MAC_ADDRESS_STR
@@ -2781,13 +2792,13 @@
         VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
                 "%s: timeout waiting for tdls add station indication",
                 __func__);
-        goto error;
+        return -EPERM;
     }
     if ( eHAL_STATUS_SUCCESS != pAdapter->tdlsAddStaStatus)
     {
         VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
                 "%s: Add Station is unsucessful", __func__);
-        goto error;
+        return -EPERM;
     }
 
     return 0;
@@ -6758,8 +6769,8 @@
         {
              VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
                         "%s: " MAC_ADDRESS_STR
-                        " TDLS mode is disabled. Request declined.",
-                        __func__, MAC_ADDR_ARRAY(peer));
+                        " TDLS mode is disabled. action %d declined.",
+                        __func__, MAC_ADDR_ARRAY(peer), action_code);
 
         return -ENOTSUPP;
         }
@@ -6771,9 +6782,9 @@
         {
             VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
                        "%s: " MAC_ADDRESS_STR
-                       " TDLS setup is ongoing. Request declined.",
-                       __func__, MAC_ADDR_ARRAY(peer));
-            goto error;
+                       " TDLS setup is ongoing. action %d declined.",
+                       __func__, MAC_ADDR_ARRAY(peer), action_code);
+            return -EPERM;
         }
     }
 
@@ -6790,8 +6801,8 @@
             {
                 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
                            "%s: " MAC_ADDRESS_STR
-                           " TDLS Max peer already connected. Request declined.",
-                           __func__, MAC_ADDR_ARRAY(peer));
+                           " TDLS Max peer already connected. action %d declined.",
+                           __func__, MAC_ADDR_ARRAY(peer), action_code);
                 goto error;
             }
             else
@@ -6815,8 +6826,8 @@
             if (pTdlsPeer && (eTDLS_LINK_CONNECTED == pTdlsPeer->link_status))
             {
                 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
-                        "%s:" MAC_ADDRESS_STR " already connected. Request declined.",
-                        __func__, MAC_ADDR_ARRAY(peer));
+                        "%s:" MAC_ADDRESS_STR " already connected. action %d declined.",
+                        __func__, MAC_ADDR_ARRAY(peer), action_code);
                 return -EPERM;
             }
         }
@@ -6863,7 +6874,7 @@
     {
         VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
                 "%s: sme_SendTdlsMgmtFrame failed!", __func__);
-        goto error;
+        return -EPERM;
     }
 
     /* not block discovery request, as it is called from timer callback */
@@ -6879,7 +6890,7 @@
             VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
                       "%s: Mgmt Tx Completion failed status %ld TxCompletion %lu",
                       __func__, rc, pAdapter->mgmtTxCompletionStatus);
-            goto error;
+            return -EPERM;
         }
     }
 
diff --git a/CORE/HDD/src/wlan_hdd_tdls.c b/CORE/HDD/src/wlan_hdd_tdls.c
index a6371d4..2ffe997 100644
--- a/CORE/HDD/src/wlan_hdd_tdls.c
+++ b/CORE/HDD/src/wlan_hdd_tdls.c
@@ -268,10 +268,9 @@
             curr_peer = list_entry (pos, hddTdlsPeer_t, node);
 
             VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
-                       "hdd update cb - %d: " MAC_ADDRESS_STR " -> %d link_status -> %d"
-                       "tdls_support -> %d", i,
-                       MAC_ADDR_ARRAY(curr_peer->peerMac),
-                       curr_peer->tx_pkt, curr_peer->link_status, curr_peer->tdls_support);
+                       "hdd update cb " MAC_ADDRESS_STR " link_status %d"
+                       " tdls_support %d", MAC_ADDR_ARRAY(curr_peer->peerMac),
+                       curr_peer->link_status, curr_peer->tdls_support);
 
             if (eTDLS_CAP_SUPPORTED == curr_peer->tdls_support) {
                 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
@@ -288,7 +287,7 @@
                         if (HDD_MAX_NUM_TDLS_STA > wlan_hdd_tdlsConnectedPeers(pHddTdlsCtx->pAdapter))
                         {
 
-                            VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL, "-> Tput trigger TDLS SETUP");
+                            VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL, "Tput trigger TDLS pre-setup");
 #ifdef CONFIG_TDLS_IMPLICIT
                             wlan_hdd_tdls_pre_setup(pHddTdlsCtx, curr_peer);
 #endif
@@ -301,11 +300,6 @@
                         }
                         goto next_peer;
                     }
-#ifdef WLAN_FEATURE_TDLS_DEBUG
-                    else  {
-                        VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL, "-> ignored.");
-                    }
-#endif
                     if ((((tANI_S32)curr_peer->rssi >
                             (tANI_S32)(pHddTdlsCtx->threshold_config.rssi_hysteresis +
                                 pHddTdlsCtx->ap_rssi)) ||
@@ -386,6 +380,7 @@
 
                         if (++curr_peer->discovery_attempt <
                                  pHddTdlsCtx->threshold_config.discovery_tries_n) {
+                            VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL, "TDLS UNKNOWN discover ");
                             wlan_hdd_tdls_pre_setup(pHddTdlsCtx, curr_peer);
                         }
                         else
@@ -393,10 +388,6 @@
                             curr_peer->tdls_support = eTDLS_CAP_NOT_SUPPORTED;
                             curr_peer->link_status  = eTDLS_LINK_IDLE;
                         }
-
-                        VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
-                                "Tput triggering TDLS discovery: " MAC_ADDRESS_STR "!",
-                                   MAC_ADDR_ARRAY(curr_peer->peerMac));
                     }
                 }
             }
@@ -474,7 +465,7 @@
     }
 
     pHddTdlsCtx->discovery_sent_cnt = 0;
-    wlan_hdd_tdls_set_power_save_prohibited(pHddTdlsCtx->pAdapter);
+    wlan_hdd_tdls_check_power_save_prohibited(pHddTdlsCtx->pAdapter);
 
     mutex_unlock(&tdls_lock);
 
@@ -746,19 +737,19 @@
     return peer;
 }
 
-void wlan_hdd_tdls_set_cap(hdd_adapter_t *pAdapter,
+int wlan_hdd_tdls_set_cap(hdd_adapter_t *pAdapter,
                                    u8* mac,
                                    tTDLSCapType cap)
 {
     hddTdlsPeer_t *curr_peer;
 
-    curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac);
+    curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
     if (curr_peer == NULL)
-        return;
+        return -1;
 
     curr_peer->tdls_support = cap;
 
-    return;
+    return 0;
 }
 
 void wlan_hdd_tdls_set_peer_link_status(hddTdlsPeer_t *curr_peer, tTDLSLinkStatus status)
@@ -801,7 +792,7 @@
     if (pHddTdlsCtx->discovery_sent_cnt)
         pHddTdlsCtx->discovery_sent_cnt--;
 
-    wlan_hdd_tdls_set_power_save_prohibited(pAdapter);
+    wlan_hdd_tdls_check_power_save_prohibited(pAdapter);
     if (0 == pHddTdlsCtx->discovery_sent_cnt)
     {
         vos_timer_stop(&pHddTdlsCtx->peerDiscoveryTimeoutTimer);
@@ -814,13 +805,14 @@
 
     if (eTDLS_LINK_DISCOVERING == curr_peer->link_status)
     {
+        curr_peer->link_status = eTDLS_LINK_DISCOVERED;
+
         VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
                    "Indicating Set-Up to supplicant");
         cfg80211_tdls_oper_request(pAdapter->dev,
                                    curr_peer->peerMac,
                                    NL80211_TDLS_SETUP, FALSE,
                                    GFP_KERNEL);
-        curr_peer->link_status = eTDLS_LINK_DISCOVERED;
     }
     else
     {
@@ -1283,7 +1275,7 @@
     {
        wlan_hdd_tdls_peer_reset_discovery_processed(pHddTdlsCtx);
        pHddTdlsCtx->discovery_sent_cnt = 0;
-       wlan_hdd_tdls_set_power_save_prohibited(pHddTdlsCtx->pAdapter);
+       wlan_hdd_tdls_check_power_save_prohibited(pHddTdlsCtx->pAdapter);
 
 #ifdef FEATURE_WLAN_TDLS_INTERNAL
        vos_timer_start(&pHddTdlsCtx->peerDiscoverTimer,
@@ -1313,7 +1305,7 @@
         return;
     }
     pHddTdlsCtx->discovery_sent_cnt = 0;
-    wlan_hdd_tdls_set_power_save_prohibited(pHddTdlsCtx->pAdapter);
+    wlan_hdd_tdls_check_power_save_prohibited(pHddTdlsCtx->pAdapter);
 
     wlan_hdd_tdls_timers_stop(pHddTdlsCtx);
     wlan_hdd_tdls_free_list(pHddTdlsCtx);
@@ -1336,7 +1328,7 @@
     if (NULL == pHddCtx) return;
 
     pHddCtx->connected_peer_count++;
-    wlan_hdd_tdls_set_power_save_prohibited(pAdapter);
+    wlan_hdd_tdls_check_power_save_prohibited(pAdapter);
 
     VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL, "%s: %d",
                __func__, pHddCtx->connected_peer_count);
@@ -1350,7 +1342,7 @@
 
     if (pHddCtx->connected_peer_count)
         pHddCtx->connected_peer_count--;
-    wlan_hdd_tdls_set_power_save_prohibited(pAdapter);
+    wlan_hdd_tdls_check_power_save_prohibited(pAdapter);
 
     VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL, "%s: %d",
                __func__, pHddCtx->connected_peer_count);
@@ -1387,6 +1379,17 @@
     return;
 }
 
+u8 wlan_hdd_tdls_is_peer_progress(hdd_adapter_t *pAdapter, u8 *mac)
+{
+    hddTdlsPeer_t *curr_peer;
+
+    curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac);
+    if (curr_peer == NULL)
+        return 0;
+
+    return (eTDLS_LINK_CONNECTING == curr_peer->link_status);
+}
+
 /* return TRUE if TDLS is ongoing
  * mac - if NULL check for all the peer list, otherwise, skip this mac when skip_self is TRUE
  * skip_self - if TRUE, skip this mac. otherwise, check all the peer list. if
@@ -1425,7 +1428,7 @@
                 if (eTDLS_LINK_CONNECTING == curr_peer->link_status)
                 {
                   VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
-                            "%s:" MAC_ADDRESS_STR "is in eTDLS_LINK_CONNECTING",
+                            "%s:" MAC_ADDRESS_STR " eTDLS_LINK_CONNECTING",
                             __func__, MAC_ADDR_ARRAY(curr_peer->peerMac));
                   mutex_unlock(&tdls_lock);
                   return TRUE;
@@ -1457,7 +1460,7 @@
     wlan_hdd_tdls_peer_reset_discovery_processed(pHddTdlsCtx);
     pHddTdlsCtx->discovery_sent_cnt = 0;
     wlan_tdd_tdls_reset_tx_rx(pHddTdlsCtx);
-    wlan_hdd_tdls_set_power_save_prohibited(pHddTdlsCtx->pAdapter);
+    wlan_hdd_tdls_check_power_save_prohibited(pHddTdlsCtx->pAdapter);
 
 
 #ifdef FEATURE_WLAN_TDLS_INTERNAL
@@ -1519,7 +1522,7 @@
                           WLAN_TDLS_DISCOVERY_REQUEST,
                           1, 0, NULL, 0, 0);
     pHddTdlsCtx->discovery_sent_cnt++;
-    wlan_hdd_tdls_set_power_save_prohibited(pHddTdlsCtx->pAdapter);
+    wlan_hdd_tdls_check_power_save_prohibited(pHddTdlsCtx->pAdapter);
     VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL, "%s: discovery count %lu timeout %lu msec",
                __func__, pHddTdlsCtx->discovery_sent_cnt,
                pHddTdlsCtx->threshold_config.tx_period_t - TDLS_DISCOVERY_TIMEOUT_BEFORE_UPDATE);
@@ -1558,7 +1561,7 @@
     return count;
 }
 
-void wlan_hdd_tdls_set_power_save_prohibited(hdd_adapter_t *pAdapter)
+void wlan_hdd_tdls_check_power_save_prohibited(hdd_adapter_t *pAdapter)
 {
     tdlsCtx_t *pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
     hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
diff --git a/CORE/SME/src/sme_common/sme_Api.c b/CORE/SME/src/sme_common/sme_Api.c
index 7dda7ec..c88ce73 100644
--- a/CORE/SME/src/sme_common/sme_Api.c
+++ b/CORE/SME/src/sme_common/sme_Api.c
@@ -921,6 +921,10 @@
          break;
       }
 
+#ifdef FEATURE_WLAN_TDLS
+      pMac->isTdlsPowerSaveProhibited = 0;
+#endif
+
 #ifndef WLAN_MDM_CODE_REDUCTION_OPT
       status = sme_QosOpen(pMac);
       if ( ! HAL_STATUS_SUCCESS( status ) ) {