prima: Enable TDLS after SAP turn off

Currently, as part of start bss TDLS clients are tore down
and TDLS mode is set to disabled with source bit map p2p.
After SAP turn off TDLS mode is not changed to enable again.

Disable the TDLS with concurrency bit map for SAP turn on,
and reenable as part of SAP turn off.

Change-Id: Ie5b786425aed2dccc10a188ffc39474630a3e7aa
CRs-Fixed: 2267011
diff --git a/CORE/HDD/inc/wlan_hdd_tdls.h b/CORE/HDD/inc/wlan_hdd_tdls.h
index c9731f1..193916f 100644
--- a/CORE/HDD/inc/wlan_hdd_tdls.h
+++ b/CORE/HDD/inc/wlan_hdd_tdls.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012-2017 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2012-2018 The Linux Foundation. All rights reserved.
  *
  * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  *
@@ -78,7 +78,7 @@
     HDD_SET_TDLS_MODE_SOURCE_SCAN = 2,
     HDD_SET_TDLS_MODE_SOURCE_OFFCHANNEL = 4,
     HDD_SET_TDLS_MODE_SOURCE_BTC = 8,
-    HDD_SET_TDLS_MODE_SOURCE_P2P = 16
+    HDD_SET_TDLS_MODE_SOURCE_CONCURRENCY = 16
 };
 
 typedef struct
diff --git a/CORE/HDD/src/wlan_hdd_cfg80211.c b/CORE/HDD/src/wlan_hdd_cfg80211.c
index 4c615d2..fda4797 100644
--- a/CORE/HDD/src/wlan_hdd_cfg80211.c
+++ b/CORE/HDD/src/wlan_hdd_cfg80211.c
@@ -11061,7 +11061,8 @@
             hdd_update_indoor_channel(pHddCtx, false);
             VOS_TRACE(VOS_MODULE_ID_SAP, VOS_TRACE_LEVEL_ERROR,
                  FL("Can't start BSS: update channel list failed"));
-            return eHAL_STATUS_FAILURE;
+            ret = eHAL_STATUS_FAILURE;
+            goto tdls_enable;
         }
 
         /* check if STA is on indoor channel */
@@ -11683,6 +11684,11 @@
     }
 
    clear_bit(SOFTAP_INIT_DONE, &pHostapdAdapter->event_flags);
+
+tdls_enable:
+        if (ret != eHAL_STATUS_SUCCESS)
+            wlan_hdd_tdls_reenable(pHddCtx);
+
    return ret;
 }
 
@@ -12364,9 +12370,9 @@
     /* Reset the current device mode bit mask*/
     wlan_hdd_clear_concurrency_mode(pHddCtx, pAdapter->device_mode);
 
-    if ((pAdapter->device_mode == WLAN_HDD_P2P_DEVICE) &&
-        ((type == NL80211_IFTYPE_P2P_CLIENT) ||
-         (type == NL80211_IFTYPE_P2P_GO)))
+    if (((pAdapter->device_mode == WLAN_HDD_P2P_DEVICE) &&
+        (type == NL80211_IFTYPE_P2P_CLIENT || type == NL80211_IFTYPE_P2P_GO)) ||
+        type == NL80211_IFTYPE_AP)
     {
         /* Notify Mode change in case of concurrency.
          * Below function invokes TDLS teardown Functionality Since TDLS is
diff --git a/CORE/HDD/src/wlan_hdd_hostapd.c b/CORE/HDD/src/wlan_hdd_hostapd.c
index 2ea38a9..1da4a72 100644
--- a/CORE/HDD/src/wlan_hdd_hostapd.c
+++ b/CORE/HDD/src/wlan_hdd_hostapd.c
@@ -1331,13 +1331,6 @@
 
             pHddApCtx->operatingChannel = 0; //Invalidate the channel info.
 
-            if (pHostapdAdapter->device_mode == WLAN_HDD_P2P_GO)
-            {
-                hddLog(LOG1,
-                       FL("P2P Go is getting removed and we are trying to re-enable TDLS"));
-                wlan_hdd_tdls_reenable(pHddCtx);
-            }
-
             goto stopbss;
         case eSAP_STA_SET_KEY_EVENT:
             //TODO: forward the message to hostapd once implementtation is done for now just print
@@ -1753,6 +1746,14 @@
         wireless_send_event(dev, we_event, &wrqu, (char *)we_custom_event_generic);
         hdd_dump_concurrency_info(pHddCtx);
     }
+        if (pHostapdAdapter->device_mode == WLAN_HDD_P2P_GO ||
+            pHostapdAdapter->device_mode == WLAN_HDD_SOFTAP)
+        {
+            hddLog(LOG1,
+                   FL("SAP or Go is getting removed and we are trying to re-enable TDLS"));
+            wlan_hdd_tdls_reenable(pHddCtx);
+        }
+
     return VOS_STATUS_SUCCESS;
 }
 
diff --git a/CORE/HDD/src/wlan_hdd_p2p.c b/CORE/HDD/src/wlan_hdd_p2p.c
index d159b9c..dfb9083 100644
--- a/CORE/HDD/src/wlan_hdd_p2p.c
+++ b/CORE/HDD/src/wlan_hdd_p2p.c
@@ -2385,8 +2385,8 @@
 #endif
     }
 
-    if ((type == NL80211_IFTYPE_P2P_CLIENT) ||
-          (type == NL80211_IFTYPE_P2P_GO))
+    if (type == NL80211_IFTYPE_P2P_CLIENT || type == NL80211_IFTYPE_P2P_GO ||
+        type == NL80211_IFTYPE_AP)
     {
         /* Below function Notifies Mode change and
          * If p2p session is detected then invokes functionality to
diff --git a/CORE/HDD/src/wlan_hdd_tdls.c b/CORE/HDD/src/wlan_hdd_tdls.c
index eb26cb4..13da124 100644
--- a/CORE/HDD/src/wlan_hdd_tdls.c
+++ b/CORE/HDD/src/wlan_hdd_tdls.c
@@ -239,8 +239,6 @@
             continue;
         }
 
-        wlan_hdd_tdls_reset_peer(adapter, curr_peer->peerMac);
-
         hddLog(LOG1, FL("indicate TDLS teardown (staId %d)"),
                          curr_peer->staId);
 
@@ -251,6 +249,8 @@
                 eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON);
         hdd_send_wlan_tdls_teardown_event(eTDLS_TEARDOWN_CONCURRENCY,
                                             curr_peer->peerMac);
+        wlan_hdd_tdls_reset_peer(adapter, curr_peer->peerMac);
+
         mutex_unlock(&hddctx->tdls_lock);
 
         /* Del Sta happened already as part of sme_DeleteAllTDLSPeers
@@ -269,7 +269,7 @@
 
 done:
     wlan_hdd_tdls_set_mode(hddctx, eTDLS_SUPPORT_DISABLED, FALSE,
-                           HDD_SET_TDLS_MODE_SOURCE_P2P);
+                           HDD_SET_TDLS_MODE_SOURCE_CONCURRENCY);
     hddLog(LOG1, FL("TDLS Support Disabled"));
 }
 
@@ -3596,7 +3596,8 @@
              */
              hddLog(LOG1, FL("TDLS mode set to %d"), pHddCtx->tdls_mode_last);
              wlan_hdd_tdls_set_mode(pHddCtx, pHddCtx->tdls_mode_last,
-                                    FALSE, HDD_SET_TDLS_MODE_SOURCE_P2P);
+                                    FALSE,
+                                    HDD_SET_TDLS_MODE_SOURCE_CONCURRENCY);
     }
 }