Initialize TDLS only for the STA or P2P_CLIENT mode.

This gerrit addresses the following to handle the issues
related to the TDLS initialization and exit.
In tdls_init(), proceed with the initialization/allocation only
for STA or P2P_CLIENT device_modes.Also check for the existance of
TDLS context before proceeding with the allocation.
Also invoke tdls_init when the device_mode changes to P2P_CLIENT
for the P2P Adapter.

Change-Id: Ia03fde0b0d5357a9c19b02f0a4cbc88f9be15165
CRs-fixed: 501059
diff --git a/CORE/HDD/src/wlan_hdd_cfg80211.c b/CORE/HDD/src/wlan_hdd_cfg80211.c
index 867b657..3993408 100644
--- a/CORE/HDD/src/wlan_hdd_cfg80211.c
+++ b/CORE/HDD/src/wlan_hdd_cfg80211.c
@@ -2543,6 +2543,23 @@
                     pAdapter->device_mode = (type == NL80211_IFTYPE_STATION) ?
                                 WLAN_HDD_INFRA_STATION: WLAN_HDD_P2P_CLIENT;
                 }
+#ifdef FEATURE_WLAN_TDLS
+                /* The open adapter for the p2p shall skip initializations in
+                 * tdls_init if the device mode is WLAN_HDD_P2P_DEVICE, for
+                 * TDLS is supported only on WLAN_HDD_P2P_CLIENT. Hence invoke
+                 * tdls_init when the change_iface sets the device mode to
+                 * WLAN_HDD_P2P_CLIENT.
+                 */
+
+                if ( pAdapter->device_mode == WLAN_HDD_P2P_CLIENT)
+                {
+                    if (0 != wlan_hdd_tdls_init (pAdapter))
+                    {
+                        return -EINVAL;
+                    }
+                }
+#endif
+
                 break;
             case NL80211_IFTYPE_ADHOC:
                 hddLog(VOS_TRACE_LEVEL_INFO,