TDLS Support for the P2P interface

Make the HDD TDLS Context separate for each interface and have the
TDLS connection information common for both interface in HDD global
context.

CRs-Fixed: 458139
Change-Id: I07f06f3caa446d6d57645ff1abcb0dd09f4b0ea4
diff --git a/CORE/HDD/inc/wlan_hdd_main.h b/CORE/HDD/inc/wlan_hdd_main.h
index 8146310..9bce4c6 100644
--- a/CORE/HDD/inc/wlan_hdd_main.h
+++ b/CORE/HDD/inc/wlan_hdd_main.h
@@ -108,6 +108,7 @@
 #define WMM_INIT_DONE          (1<<3)
 #define SOFTAP_BSS_STARTED     (1<<4)
 #define DEVICE_IFACE_OPENED    (1<<5)
+#define TDLS_INIT_DONE         (1<<6)
 
 /** Maximum time(ms)to wait for disconnect to complete **/
 #define WLAN_WAIT_TIME_DISCONNECT  500
@@ -491,6 +492,11 @@
   /** Handle to the Wireless Extension State */
    hdd_wext_state_t WextState;
 
+#ifdef FEATURE_WLAN_TDLS
+   tdlsCtx_t *pHddTdlsCtx;
+#endif
+
+
    /**Connection information*/
    connection_info_t conn_info;
 
@@ -780,6 +786,9 @@
 #define WLAN_HDD_GET_HAL_CTX(pAdapter)  (((hdd_context_t*)(pAdapter->pHddCtx))->hHal)
 #define WLAN_HDD_GET_HOSTAP_STATE_PTR(pAdapter) (&(pAdapter)->sessionCtx.ap.HostapdState)
 #define WLAN_HDD_GET_CFG_STATE_PTR(pAdapter)  (&(pAdapter)->cfg80211State)
+#ifdef FEATURE_WLAN_TDLS
+#define WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter) ((tdlsCtx_t*)(pAdapter)->sessionCtx.station.pHddTdlsCtx)
+#endif
 
 typedef struct hdd_adapter_list_node
 {
@@ -934,6 +943,9 @@
 
 #ifdef FEATURE_WLAN_TDLS
     eTDLSSupportMode tdls_mode;
+    tdlsConnInfo_t tdlsConnInfo[HDD_MAX_NUM_TDLS_STA];
+    /* TDLS peer connected count */
+    tANI_U16 connected_peer_count;
 #endif
 };
 
diff --git a/CORE/HDD/inc/wlan_hdd_tdls.h b/CORE/HDD/inc/wlan_hdd_tdls.h
index ed07f91..7dda53a 100644
--- a/CORE/HDD/inc/wlan_hdd_tdls.h
+++ b/CORE/HDD/inc/wlan_hdd_tdls.h
@@ -96,7 +96,18 @@
 } tdls_rssi_config_t;
 
 typedef struct {
+    struct list_head peer_list[256];
+    hdd_adapter_t   *pAdapter;
+    vos_timer_t     peerDiscoverTimer;
+    vos_timer_t     peerUpdateTimer;
+    tdls_config_params_t threshold_config;
+    tANI_S32        discovery_peer_cnt;
+    tANI_S8         ap_rssi;
+} tdlsCtx_t;
+
+typedef struct {
     struct list_head node;
+    tdlsCtx_t   *pHddTdlsCtx;
     tSirMacAddr peerMac;
     tANI_U16    staId ;
     tANI_S8     rssi;
@@ -112,53 +123,50 @@
     tANI_U8         isTDLSInProgress;
 } hddTdlsPeer_t;
 
-
 typedef struct {
-    struct list_head peer_list[256];
-    struct net_device *dev;
-    vos_timer_t     peerDiscoverTimer;
-    vos_timer_t     peerUpdateTimer;
-    tdls_config_params_t threshold_config;
-    tANI_S32        discovery_peer_cnt;
-    tANI_U16        connected_peer_count;
-    tANI_S8         ap_rssi;
-} tdlsCtx_t;
+    /* Session ID */
+    tANI_U8 sessionId;
+    /*TDLS peer station id */
+    v_U8_t staId;
+    /* TDLS peer mac Address */
+    v_MACADDR_t peerMac;
+} tdlsConnInfo_t;
 
-int wlan_hdd_tdls_init(struct net_device *dev);
+int wlan_hdd_tdls_init(hdd_adapter_t *pAdapter);
 
-void wlan_hdd_tdls_exit(void);
+void wlan_hdd_tdls_exit(hdd_adapter_t *pAdapter);
 
 void wlan_hdd_tdls_extract_da(struct sk_buff *skb, u8 *mac);
 
 void wlan_hdd_tdls_extract_sa(struct sk_buff *skb, u8 *mac);
 
-int wlan_hdd_tdls_increment_pkt_count(u8 *mac, u8 tx);
+int wlan_hdd_tdls_increment_pkt_count(hdd_adapter_t *pAdapter, u8 *mac, u8 tx);
 
-int wlan_hdd_tdls_set_sta_id(u8 *mac, u8 staId);
+int wlan_hdd_tdls_set_sta_id(hdd_adapter_t *pAdapter, u8 *mac, u8 staId);
 
-hddTdlsPeer_t *wlan_hdd_tdls_find_peer(u8 *mac);
+hddTdlsPeer_t *wlan_hdd_tdls_find_peer(hdd_adapter_t *pAdapter, u8 *mac);
 
-hddTdlsPeer_t *wlan_hdd_tdls_get_peer(u8 *mac);
+hddTdlsPeer_t *wlan_hdd_tdls_get_peer(hdd_adapter_t *pAdapter, u8 *mac);
 
 void wlan_hdd_tdls_set_link_status(hddTdlsPeer_t *curr_peer, int status);
 
-int wlan_hdd_tdls_recv_discovery_resp(u8 *mac);
+int wlan_hdd_tdls_recv_discovery_resp(hdd_adapter_t *pAdapter, u8 *mac);
 
-int wlan_hdd_tdls_set_rssi(u8 *mac, tANI_S8 rxRssi);
+int wlan_hdd_tdls_set_rssi(hdd_adapter_t *pAdapter, u8 *mac, tANI_S8 rxRssi);
 
-int wlan_hdd_tdls_set_responder(u8 *mac, tANI_U8 responder);
+int wlan_hdd_tdls_set_responder(hdd_adapter_t *pAdapter, u8 *mac, tANI_U8 responder);
 
-int wlan_hdd_tdls_get_responder(u8 *mac);
+int wlan_hdd_tdls_get_responder(hdd_adapter_t *pAdapter, u8 *mac);
 
-int wlan_hdd_tdls_set_signature(u8 *mac, tANI_U8 uSignature);
+int wlan_hdd_tdls_set_signature(hdd_adapter_t *pAdapter, u8 *mac, tANI_U8 uSignature);
 
 int wlan_hdd_tdls_set_params(struct net_device *dev, tdls_config_params_t *config);
 
-int wlan_hdd_tdls_reset_peer(u8 *mac);
+int wlan_hdd_tdls_reset_peer(hdd_adapter_t *pAdapter, u8 *mac);
 
-tANI_U16 wlan_hdd_tdlsConnectedPeers(void);
+tANI_U16 wlan_hdd_tdlsConnectedPeers(hdd_adapter_t *pAdapter);
 
-int wlan_hdd_tdls_get_all_peers(char *buf, int buflen);
+int wlan_hdd_tdls_get_all_peers(hdd_adapter_t *pAdapter, char *buf, int buflen);
 
 void wlan_hdd_tdls_connection_callback(hdd_adapter_t *pAdapter);
 
@@ -166,14 +174,14 @@
 
 void wlan_hdd_tdls_mgmt_completion_callback(hdd_adapter_t *pAdapter, tANI_U32 statusCode);
 
-void wlan_hdd_tdls_increment_peer_count(void);
+void wlan_hdd_tdls_increment_peer_count(hdd_adapter_t *pAdapter);
 
-void wlan_hdd_tdls_decrement_peer_count(void);
+void wlan_hdd_tdls_decrement_peer_count(hdd_adapter_t *pAdapter);
 
-void wlan_hdd_tdls_check_bmps(hdd_context_t *pHddCtx);
+void wlan_hdd_tdls_check_bmps(hdd_adapter_t *pAdapter);
 
-void wlan_hdd_tdls_set_connection_progress(u8* mac, u8 isProgress);
+void wlan_hdd_tdls_set_connection_progress(hdd_adapter_t *pAdapter, u8* mac, u8 isProgress);
 
-u8 wlan_hdd_tdls_is_progress(u8* mac, u8 skip_self);
+u8 wlan_hdd_tdls_is_progress(hdd_adapter_t *pAdapter, u8* mac, u8 skip_self);
 
 #endif // __HDD_TDSL_H
diff --git a/CORE/HDD/src/wlan_hdd_assoc.c b/CORE/HDD/src/wlan_hdd_assoc.c
index 7008901..1dc994a 100755
--- a/CORE/HDD/src/wlan_hdd_assoc.c
+++ b/CORE/HDD/src/wlan_hdd_assoc.c
@@ -1884,7 +1884,7 @@
                                                 eRoamCmdStatus roamStatus, 
                                                   eCsrRoamResult roamResult)
 {
-    hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
+    hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
     eHalStatus status = eHAL_STATUS_FAILURE ;
     tANI_U8 staIdx;
 
@@ -1915,37 +1915,35 @@
             }
             else
             {
-                /*
-                 * 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 = 1; staIdx <= HDD_MAX_NUM_TDLS_STA; staIdx++ )
-                {
-                    if (0 == pHddStaCtx->conn_info.staId[staIdx] )
-                    {
-                        pHddStaCtx->conn_info.staId[staIdx] = pRoamInfo->staId;
 
-                        VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
+                /* check if there is available index for this new TDLS STA */
+                for ( staIdx = 0; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++ )
+                {
+                    if (0 == pHddCtx->tdlsConnInfo[staIdx].staId )
+                    {
+                        pHddCtx->tdlsConnInfo[staIdx].sessionId = pRoamInfo->sessionId;
+                        pHddCtx->tdlsConnInfo[staIdx].staId = pRoamInfo->staId;
+
+                        VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
                          ("TDLS: STA IDX at %d is %d "
                                   "of mac %02x:%02x:%02x:%02x:%02x:%02x"),
-                                  staIdx, pHddStaCtx->conn_info.staId[staIdx],
-                                                    pRoamInfo->peerMac[0],
-                                                    pRoamInfo->peerMac[1],
-                                                    pRoamInfo->peerMac[2],
-                                                    pRoamInfo->peerMac[3],
-                                                    pRoamInfo->peerMac[4],
-                                                    pRoamInfo->peerMac[5]) ;
+                                  staIdx, pHddCtx->tdlsConnInfo[staIdx].staId,
+                                          pRoamInfo->peerMac[0],
+                                          pRoamInfo->peerMac[1],
+                                          pRoamInfo->peerMac[2],
+                                          pRoamInfo->peerMac[3],
+                                          pRoamInfo->peerMac[4],
+                                          pRoamInfo->peerMac[5]) ;
 
-                        vos_copy_macaddr(
-                                  &pHddStaCtx->conn_info.peerMacAddress[staIdx],
+                        vos_copy_macaddr(&pHddCtx->tdlsConnInfo[staIdx].peerMac,
                                          (v_MACADDR_t *)pRoamInfo->peerMac) ;
                         status = eHAL_STATUS_SUCCESS ;
                         break ;
                     }
                 }
-                if (staIdx <= HDD_MAX_NUM_TDLS_STA)
+                if (staIdx < HDD_MAX_NUM_TDLS_STA)
                 {
-                    if (-1 == wlan_hdd_tdls_set_sta_id(pRoamInfo->peerMac, pRoamInfo->staId)) {
+                    if (-1 == wlan_hdd_tdls_set_sta_id(pAdapter, pRoamInfo->peerMac, pRoamInfo->staId)) {
                         VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
                                      "wlan_hdd_tdls_set_sta_id() failed");
                         return VOS_FALSE;
@@ -1955,7 +1953,7 @@
                     /* store the ucast signature which will be used later when
                        registering to TL
                      */
-                    wlan_hdd_tdls_set_signature( pRoamInfo->peerMac, pRoamInfo->ucastSig );
+                    wlan_hdd_tdls_set_signature( pAdapter, pRoamInfo->peerMac, pRoamInfo->ucastSig );
                 }
                 else
                 {
@@ -1970,24 +1968,25 @@
         }
         case eCSR_ROAM_RESULT_DELETE_TDLS_PEER:
         {
-            /* 0 staIdx is assigned to AP we dont want to touch that */
-            for ( staIdx = 1; staIdx <= HDD_MAX_NUM_TDLS_STA; staIdx++ )
+            for ( staIdx = 0; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++ )
             {
-                if (pRoamInfo->staId == pHddStaCtx->conn_info.staId[staIdx] )
+                if ((pHddCtx->tdlsConnInfo[staIdx].sessionId == pRoamInfo->sessionId) &&
+                    pRoamInfo->staId == pHddCtx->tdlsConnInfo[staIdx].staId)
                 {
-                    VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
+                    VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
                                    ("HDD: del STA IDX = %x"), pRoamInfo->staId) ;
 
-                    wlan_hdd_tdls_reset_peer(pRoamInfo->peerMac);
+                    wlan_hdd_tdls_reset_peer(pAdapter, pRoamInfo->peerMac);
                     hdd_roamDeregisterTDLSSTA ( pAdapter, pRoamInfo->staId );
-                    wlan_hdd_tdls_decrement_peer_count();
+                    wlan_hdd_tdls_decrement_peer_count(pAdapter);
 
                     (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],
+                    pHddCtx->tdlsConnInfo[staIdx].staId = 0 ;
+                    pHddCtx->tdlsConnInfo[staIdx].sessionId = 255;
+                    vos_mem_zero(&pHddCtx->tdlsConnInfo[staIdx].peerMac,
                                                sizeof(v_MACADDR_t)) ;
-                    wlan_hdd_tdls_check_bmps(WLAN_HDD_GET_CTX( pAdapter ));
+                    wlan_hdd_tdls_check_bmps(pAdapter);
                     status = eHAL_STATUS_SUCCESS ;
                     break ;
                 }
@@ -2013,31 +2012,33 @@
         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++ )
+            for ( staIdx = 0; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++ )
             {
-                if (pHddStaCtx->conn_info.staId[staIdx])
+                if ((pHddCtx->tdlsConnInfo[staIdx].sessionId == pRoamInfo->sessionId) &&
+                    pHddCtx->tdlsConnInfo[staIdx].staId)
                 {
-                    VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
+                    VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
                               ("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_tdls_decrement_peer_count();
+                                pHddCtx->tdlsConnInfo[staIdx].staId,
+                                pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes[0],
+                                pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes[1],
+                                pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes[2],
+                                pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes[3],
+                                pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes[4],
+                                pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes[5]) ;
+                    wlan_hdd_tdls_reset_peer(pAdapter, pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes);
+                    hdd_roamDeregisterTDLSSTA ( pAdapter,  pHddCtx->tdlsConnInfo[staIdx].staId );
+                    wlan_hdd_tdls_decrement_peer_count(pAdapter);
 
                     (WLAN_HDD_GET_CTX(pAdapter))->sta_to_adapter[staIdx] = NULL;
-                    vos_mem_zero(&pHddStaCtx->conn_info.peerMacAddress[staIdx],
+                    vos_mem_zero(&pHddCtx->tdlsConnInfo[staIdx].peerMac,
                                                sizeof(v_MACADDR_t)) ;
-                    pHddStaCtx->conn_info.staId[staIdx] = 0 ;
+                    pHddCtx->tdlsConnInfo[staIdx].staId = 0 ;
+                    pHddCtx->tdlsConnInfo[staIdx].sessionId = 255;
 
                     status = eHAL_STATUS_SUCCESS ;
                 }
-                wlan_hdd_tdls_check_bmps(WLAN_HDD_GET_CTX( pAdapter ));
+                wlan_hdd_tdls_check_bmps(pAdapter);
             }
             break ;
         }
diff --git a/CORE/HDD/src/wlan_hdd_cfg80211.c b/CORE/HDD/src/wlan_hdd_cfg80211.c
index 2b99eb3..36fae0a 100755
--- a/CORE/HDD/src/wlan_hdd_cfg80211.c
+++ b/CORE/HDD/src/wlan_hdd_cfg80211.c
@@ -5240,6 +5240,7 @@
     int status = 0;
     hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
 #ifdef FEATURE_WLAN_TDLS
+    hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
     tANI_U8 staIdx;
 #endif
     
@@ -5292,19 +5293,20 @@
 
 #ifdef FEATURE_WLAN_TDLS
             /* First clean up the tdls peers if any */
-            for (staIdx = 1 ; staIdx <= HDD_MAX_NUM_TDLS_STA; staIdx++)
+            for (staIdx = 0 ; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
             {
-                if (pHddStaCtx->conn_info.staId[staIdx])
+                if ((pHddCtx->tdlsConnInfo[staIdx].sessionId == pAdapter->sessionId) &&
+                    (pHddCtx->tdlsConnInfo[staIdx].staId))
                 {
                     uint8 *mac;
-                    mac = pHddStaCtx->conn_info.peerMacAddress[staIdx].bytes;
+                    mac = pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes;
                     VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
                             "%s: call sme_DeleteTdlsPeerSta staId %d sessionId %d %02x:%02x:%02x:%02x:%02x:%02x",
-                            __func__, pHddStaCtx->conn_info.staId[staIdx], pAdapter->sessionId,
+                            __func__, pHddCtx->tdlsConnInfo[staIdx].staId, pAdapter->sessionId,
                             mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] );
                     sme_DeleteTdlsPeerSta(WLAN_HDD_GET_HAL_CTX(pAdapter),
-                              pAdapter->sessionId,
-                              pHddStaCtx->conn_info.peerMacAddress[staIdx].bytes);
+                                          pAdapter->sessionId,
+                                          mac);
                 }
             }
 #endif
@@ -6305,7 +6307,7 @@
         return -ENOTSUPP;
     }
 
-    if (wlan_hdd_tdls_is_progress(mac, TRUE))
+    if (wlan_hdd_tdls_is_progress(pAdapter, mac, TRUE))
     {
         VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
             "%s: TDLS setup is ongoing. Request declined.",__func__);
@@ -6315,7 +6317,7 @@
     /* first to check if we reached to maximum supported TDLS peer.
        TODO: for now, return -EPERM looks working fine,
        but need to check if any other errno fit into this category.*/
-    if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers())
+    if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
     {
         VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
                 "%s: TDLS Max peer already connected. Request declined. \n",
@@ -6325,7 +6327,7 @@
     else
     {
         hddTdlsPeer_t *pTdlsPeer;
-        pTdlsPeer = wlan_hdd_tdls_find_peer(mac);
+        pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac);
         if (pTdlsPeer && (eTDLS_LINK_CONNECTED == pTdlsPeer->link_status))
         {
             VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
@@ -6335,7 +6337,7 @@
         }
     }
 
-    wlan_hdd_tdls_set_connection_progress(mac,TRUE);
+    wlan_hdd_tdls_set_connection_progress(pAdapter, mac, TRUE);
 
     INIT_COMPLETION(pAdapter->tdls_add_station_comp);
 
@@ -6350,14 +6352,14 @@
         VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
                 "%s: timeout waiting for tdls add station indication",
                 __func__);
-        wlan_hdd_tdls_set_connection_progress(mac, FALSE);
+        wlan_hdd_tdls_set_connection_progress(pAdapter, mac, FALSE);
         return -EPERM;
     }
     if ( eHAL_STATUS_SUCCESS != pAdapter->tdlsAddStaStatus)
     {
         VOS_TRACE(VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
                 "%s: Add Station is unsucessful", __func__);
-        wlan_hdd_tdls_set_connection_progress(mac, FALSE);
+        wlan_hdd_tdls_set_connection_progress(pAdapter, mac, FALSE);
         return -EPERM;
     }
 
@@ -6571,7 +6573,7 @@
 
     if (WLAN_IS_TDLS_SETUP_ACTION(action_code))
     {
-        if (wlan_hdd_tdls_is_progress(peer, TRUE))
+        if (wlan_hdd_tdls_is_progress(pAdapter, peer, TRUE))
         {
             VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
                        "%s: TDLS setup is ongoing. Request declined.", __func__);
@@ -6582,7 +6584,7 @@
     if (SIR_MAC_TDLS_SETUP_REQ == action_code ||
         SIR_MAC_TDLS_SETUP_RSP == action_code )
     {
-        if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers())
+        if (HDD_MAX_NUM_TDLS_STA <= wlan_hdd_tdlsConnectedPeers(pAdapter))
         {
             /* supplicant still sends tdls_mgmt(SETUP_REQ) even after
                we return error code at 'add_station()'. Hence we have this
@@ -6611,7 +6613,7 @@
         else
         {
             hddTdlsPeer_t *pTdlsPeer;
-            pTdlsPeer = wlan_hdd_tdls_find_peer(peer);
+            pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer);
             if (pTdlsPeer && (eTDLS_LINK_CONNECTED == pTdlsPeer->link_status))
             {
                 VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
@@ -6634,8 +6636,8 @@
     responder = 0;
     if (SIR_MAC_TDLS_TEARDOWN == action_code)
     {
-       responder = wlan_hdd_tdls_get_responder(peerMac);
-       if (-1 == responder)
+       responder = wlan_hdd_tdls_get_responder(pAdapter, peerMac);
+       if(-1 == responder)
        {
             VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
                      "%s: %02x:%02x:%02x:%02x:%02x:%02x) peer doesn't exist dialog_token %d status %d, len = %d",
@@ -6647,7 +6649,7 @@
 
     if (ret == 0 && /* if failure, don't need to set the progress bit */
        (WLAN_IS_TDLS_SETUP_ACTION(action_code)))
-        wlan_hdd_tdls_set_connection_progress(peer, TRUE);
+        wlan_hdd_tdls_set_connection_progress(pAdapter, peer, TRUE);
 
     INIT_COMPLETION(pAdapter->tdls_mgmt_comp);
 
@@ -6658,7 +6660,7 @@
     {
         if(ret == 0 && /* if failure, don't need to set the progress bit */
            (WLAN_IS_TDLS_SETUP_ACTION(action_code)))
-           wlan_hdd_tdls_set_connection_progress(peer, FALSE);
+           wlan_hdd_tdls_set_connection_progress(pAdapter, peer, FALSE);
 
         VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
                 "%s: sme_SendTdlsMgmtFrame failed!", __func__);
@@ -6677,7 +6679,7 @@
         {
             if (ret == 0 && /* if failure, don't need to set the progress bit */
                (WLAN_IS_TDLS_SETUP_ACTION(action_code)))
-                wlan_hdd_tdls_set_connection_progress(peer, FALSE);
+                wlan_hdd_tdls_set_connection_progress(pAdapter, peer, FALSE);
 
             VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
                       "%s: Mgmt Tx Completion failed status %ld TxCompletion %lu",
@@ -6691,11 +6693,11 @@
 
     if (SIR_MAC_TDLS_SETUP_RSP == action_code)
     {
-        wlan_hdd_tdls_set_responder(peerMac, TRUE);
+        wlan_hdd_tdls_set_responder(pAdapter, peerMac, TRUE);
     }
     else if (SIR_MAC_TDLS_SETUP_CNF == action_code)
     {
-        wlan_hdd_tdls_set_responder(peerMac, FALSE);
+        wlan_hdd_tdls_set_responder(pAdapter, peerMac, FALSE);
     }
 
     return 0;
@@ -6756,7 +6758,7 @@
                 VOS_STATUS status;
 
                 if (peer) {
-                    pTdlsPeer = wlan_hdd_tdls_find_peer(peer);
+                    pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, peer);
 
                     hddLog(VOS_TRACE_LEVEL_INFO_HIGH, 
                             "%s: TDLS_LINK_ENABLE %2x:%2x:%2x:%2x:%2x:%2x",
@@ -6776,10 +6778,10 @@
                     {
                         /* start TDLS client registration with TL */
                         status = hdd_roamRegisterTDLSSTA( pAdapter, peer, pTdlsPeer->staId, pTdlsPeer->signature);
-                        wlan_hdd_tdls_increment_peer_count();
+                        wlan_hdd_tdls_increment_peer_count(pAdapter);
                         wlan_hdd_tdls_set_link_status(pTdlsPeer, eTDLS_LINK_CONNECTED);
-                        wlan_hdd_tdls_check_bmps(pHddCtx);
-                        wlan_hdd_tdls_set_connection_progress(peer, FALSE);
+                        wlan_hdd_tdls_check_bmps(pAdapter);
+                        wlan_hdd_tdls_set_connection_progress(pAdapter, peer, FALSE);
                     }
 
                 } else {
@@ -6789,7 +6791,7 @@
             break;
         case NL80211_TDLS_DISABLE_LINK:
             {
-                hddTdlsPeer_t *curr_peer = wlan_hdd_tdls_find_peer(peer);
+                hddTdlsPeer_t *curr_peer = wlan_hdd_tdls_find_peer(pAdapter, peer);
 
                 if(NULL != curr_peer)
                 {
diff --git a/CORE/HDD/src/wlan_hdd_main.c b/CORE/HDD/src/wlan_hdd_main.c
index 7f79fb3..ae56f40 100644
--- a/CORE/HDD/src/wlan_hdd_main.c
+++ b/CORE/HDD/src/wlan_hdd_main.c
@@ -1848,8 +1848,23 @@
 
    set_bit(WMM_INIT_DONE, &pAdapter->event_flags);
 
+#ifdef FEATURE_WLAN_TDLS
+   if(0 != wlan_hdd_tdls_init(pAdapter))
+   {
+       status = VOS_STATUS_E_FAILURE;
+       hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wlan_hdd_tdls_init failed",__func__);
+       goto error_tdls_init;
+   }
+   set_bit(TDLS_INIT_DONE, &pAdapter->event_flags);
+#endif
+
    return VOS_STATUS_SUCCESS;
 
+#ifdef FEATURE_WLAN_TDLS
+error_tdls_init:
+   clear_bit(WMM_INIT_DONE, &pAdapter->event_flags);
+   hdd_wmm_adapter_close(pAdapter);
+#endif
 error_wmm_init:
    clear_bit(INIT_TX_RX_SUCCESS, &pAdapter->event_flags);
    hdd_deinit_tx_rx(pAdapter);
@@ -1917,6 +1932,13 @@
          }
 
          hdd_cleanup_actionframe(pHddCtx, pAdapter);
+#ifdef FEATURE_WLAN_TDLS
+         if(test_bit(TDLS_INIT_DONE, &pAdapter->event_flags))
+         {
+            wlan_hdd_tdls_exit(pAdapter);
+            clear_bit(TDLS_INIT_DONE, &pAdapter->event_flags);
+         }
+#endif
 
          break;
       }
@@ -3283,10 +3305,6 @@
       hddLog(VOS_TRACE_LEVEL_FATAL,"%s: hddDevTmUnregisterNotifyCallback failed",__func__);
    }
 
-#ifdef FEATURE_WLAN_TDLS
-    wlan_hdd_tdls_exit();
-#endif
-
    // Cancel any outstanding scan requests.  We are about to close all
    // of our adapters, but an adapter structure is what SME passes back
    // to our callback function.  Hence if there are any outstanding scan
@@ -4227,14 +4245,6 @@
    // Initialize the restart logic
    wlan_hdd_restart_init(pHddCtx);
 
-#ifdef FEATURE_WLAN_TDLS
-   if(0 != wlan_hdd_tdls_init(pAdapter->dev))
-   {
-       hddLog(VOS_TRACE_LEVEL_FATAL,"%s: wlan_hdd_tdls_init failed",__func__);
-       goto err_nl_srv;
-   }
-#endif
-  
    goto success;
 
 err_nl_srv:
diff --git a/CORE/HDD/src/wlan_hdd_p2p.c b/CORE/HDD/src/wlan_hdd_p2p.c
index 889ce5d..806c716 100644
--- a/CORE/HDD/src/wlan_hdd_p2p.c
+++ b/CORE/HDD/src/wlan_hdd_p2p.c
@@ -1487,8 +1487,8 @@
 #ifdef FEATURE_WLAN_TDLS
             else if(pbFrames[WLAN_HDD_PUBLIC_ACTION_FRAME_OFFSET+1] == WLAN_HDD_PUBLIC_ACTION_TDLS_DISC_RESP)
             {
-                wlan_hdd_tdls_recv_discovery_resp(&pbFrames[WLAN_HDD_80211_FRM_DA_OFFSET+6]);
-                wlan_hdd_tdls_set_rssi(&pbFrames[WLAN_HDD_80211_FRM_DA_OFFSET+6], rxRssi);
+                wlan_hdd_tdls_recv_discovery_resp(pAdapter, &pbFrames[WLAN_HDD_80211_FRM_DA_OFFSET+6]);
+                wlan_hdd_tdls_set_rssi(pAdapter, &pbFrames[WLAN_HDD_80211_FRM_DA_OFFSET+6], rxRssi);
                 hddLog(VOS_TRACE_LEVEL_ERROR,"[TDLS] TDLS Discovery Response <--- OTA");
             }
 #endif
diff --git a/CORE/HDD/src/wlan_hdd_tdls.c b/CORE/HDD/src/wlan_hdd_tdls.c
index a835a67..941f2e4 100644
--- a/CORE/HDD/src/wlan_hdd_tdls.c
+++ b/CORE/HDD/src/wlan_hdd_tdls.c
@@ -39,11 +39,10 @@
 #include "wlan_hdd_cfg80211.h"
 
 
-static tdlsCtx_t *pHddTdlsCtx;
 static struct mutex tdls_lock;
-static tANI_S32 wlan_hdd_get_tdls_discovery_peer_cnt(void);
-static tANI_S32 wlan_hdd_tdls_peer_reset_discovery_processed(void);
-static void wlan_hdd_tdls_timers_destroy(void);
+static tANI_S32 wlan_hdd_get_tdls_discovery_peer_cnt(tdlsCtx_t *pHddTdlsCtx);
+static tANI_S32 wlan_hdd_tdls_peer_reset_discovery_processed(tdlsCtx_t *pHddTdlsCtx);
+static void wlan_hdd_tdls_timers_destroy(tdlsCtx_t *pHddTdlsCtx);
 
 #ifndef WLAN_FEATURE_TDLS_DEBUG
 #define TDLS_LOG_LEVEL VOS_TRACE_LEVEL_INFO
@@ -62,13 +61,12 @@
     return key;
 }
 
-static v_VOID_t wlan_hdd_tdls_start_peer_discover_timer(tANI_BOOLEAN mutexLock, v_U32_t discoveryExpiry)
+static v_VOID_t wlan_hdd_tdls_start_peer_discover_timer(tdlsCtx_t *pHddTdlsCtx,
+                                                        tANI_BOOLEAN mutexLock,
+                                                        v_U32_t discoveryExpiry)
 {
-    hdd_adapter_t *pAdapter;
-    hdd_context_t *pHddCtx;
     hdd_station_ctx_t *pHddStaCtx;
 
-
     if ( mutexLock )
     {
         if (mutex_lock_interruptible(&tdls_lock))
@@ -85,17 +83,14 @@
         return;
     }
 
-    pAdapter = WLAN_HDD_GET_PRIV_PTR(pHddTdlsCtx->dev);
-
-    if (NULL == pAdapter)
+    if (NULL == pHddTdlsCtx->pAdapter)
     {
         if ( mutexLock )
             mutex_unlock(&tdls_lock);
         return;
     }
 
-    pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
-    pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
+    pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pHddTdlsCtx->pAdapter);
     if (hdd_connIsConnected( pHddStaCtx ))
     {
         vos_timer_start(&pHddTdlsCtx->peerDiscoverTimer, discoveryExpiry);
@@ -114,9 +109,8 @@
     struct list_head *head;
     struct list_head *pos;
     hddTdlsPeer_t *curr_peer;
-    hdd_adapter_t *pAdapter;
-    hdd_context_t *pHddCtx;
     hdd_station_ctx_t *pHddStaCtx;
+    tdlsCtx_t *pHddTdlsCtx = (tdlsCtx_t *)userData;
     int discover_req_sent = 0;
     v_U32_t discover_expiry = TDLS_SUB_DISCOVERY_PERIOD;
     tANI_BOOLEAN doMutexLock = eANI_BOOLEAN_TRUE;
@@ -134,21 +128,18 @@
         return;
     }
 
-    pAdapter = WLAN_HDD_GET_PRIV_PTR(pHddTdlsCtx->dev);
-
-    if (NULL == pAdapter)
+    if (NULL == pHddTdlsCtx->pAdapter)
     {
         mutex_unlock(&tdls_lock);
         return;
     }
 
-    pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
-    pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
+    pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pHddTdlsCtx->pAdapter);
 
     VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: ", __func__);
 
     if (0 == pHddTdlsCtx->discovery_peer_cnt)
-        pHddTdlsCtx->discovery_peer_cnt = wlan_hdd_get_tdls_discovery_peer_cnt();
+        pHddTdlsCtx->discovery_peer_cnt = wlan_hdd_get_tdls_discovery_peer_cnt(pHddTdlsCtx);
 
     for (i = 0; i < 256; i++) {
         head = &pHddTdlsCtx->peer_list[i];
@@ -182,10 +173,10 @@
                             pHddTdlsCtx->threshold_config.discovery_tries_n) {
 
                             VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
-                                      "sme_SendTdlsMgmtFrame(%d)", pAdapter->sessionId);
+                                      "sme_SendTdlsMgmtFrame(%d)", pHddTdlsCtx->pAdapter->sessionId);
 
-                            sme_SendTdlsMgmtFrame(WLAN_HDD_GET_HAL_CTX(pAdapter),
-                                                  pAdapter->sessionId,
+                            sme_SendTdlsMgmtFrame(WLAN_HDD_GET_HAL_CTX(pHddTdlsCtx->pAdapter),
+                                                  pHddTdlsCtx->pAdapter->sessionId,
                                                   curr_peer->peerMac,
                                                   WLAN_TDLS_DISCOVERY_REQUEST,
                                                   1, 0, NULL, 0, 0);
@@ -219,7 +210,7 @@
 
     mutex_unlock(&tdls_lock);
 
-    wlan_hdd_tdls_peer_reset_discovery_processed();
+    wlan_hdd_tdls_peer_reset_discovery_processed(pHddTdlsCtx);
 
     /* Commenting out the following function as it was introducing
      * a race condition when pHddTdlsCtx is deleted. Also , this
@@ -232,7 +223,7 @@
      */
 
 done:
-    wlan_hdd_tdls_start_peer_discover_timer(doMutexLock, discover_expiry);
+    wlan_hdd_tdls_start_peer_discover_timer(pHddTdlsCtx, doMutexLock, discover_expiry);
 
     if ( !doMutexLock )
         mutex_unlock(&tdls_lock);
@@ -245,8 +236,7 @@
     struct list_head *head;
     struct list_head *pos;
     hddTdlsPeer_t *curr_peer;
-    hdd_adapter_t *pAdapter;
-
+    tdlsCtx_t *pHddTdlsCtx;
 
     if (mutex_lock_interruptible(&tdls_lock))
     {
@@ -254,16 +244,14 @@
                  "%s: unable to lock list", __func__);
        return;
     }
-
+    pHddTdlsCtx = (tdlsCtx_t *)userData;
     if (NULL == pHddTdlsCtx)
     {
         mutex_unlock(&tdls_lock);
         return;
     }
 
-    pAdapter = WLAN_HDD_GET_PRIV_PTR(pHddTdlsCtx->dev);
-
-    if (NULL == pAdapter)
+    if (NULL == pHddTdlsCtx->pAdapter)
     {
         mutex_unlock(&tdls_lock);
         return;
@@ -293,7 +281,7 @@
                     if (curr_peer->tx_pkt >=
                             pHddTdlsCtx->threshold_config.tx_packet_n) {
 
-                        if (HDD_MAX_NUM_TDLS_STA > wlan_hdd_tdlsConnectedPeers() &&
+                        if (HDD_MAX_NUM_TDLS_STA > wlan_hdd_tdlsConnectedPeers(pHddTdlsCtx->pAdapter) &&
                             (FALSE == curr_peer->isTDLSInProgress))
                         {
 
@@ -301,8 +289,8 @@
 #ifdef CONFIG_TDLS_IMPLICIT
 
                             curr_peer->link_status = eTDLS_LINK_DISCOVERING;
-                            sme_SendTdlsMgmtFrame(WLAN_HDD_GET_HAL_CTX(pAdapter),
-                                                  pAdapter->sessionId,
+                            sme_SendTdlsMgmtFrame(WLAN_HDD_GET_HAL_CTX(pHddTdlsCtx->pAdapter),
+                                                  pHddTdlsCtx->pAdapter->sessionId,
                                                   curr_peer->peerMac,
                                                   WLAN_TDLS_DISCOVERY_REQUEST,
                                                   1, 0, NULL, 0, 0);
@@ -312,7 +300,7 @@
                         {
                             VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
                                       "%s: Skip Tput trigger due to isTDLSInProgress %u or connected_peer_count %d",
-                                      __func__, curr_peer->isTDLSInProgress, wlan_hdd_tdlsConnectedPeers() );
+                                      __func__, curr_peer->isTDLSInProgress, wlan_hdd_tdlsConnectedPeers(pHddTdlsCtx->pAdapter) );
                         }
                         goto next_peer;
                     }
@@ -326,7 +314,7 @@
                                 pHddTdlsCtx->ap_rssi)) ||
                          ((tANI_S32)(curr_peer->rssi >
                             pHddTdlsCtx->threshold_config.rssi_trigger_threshold))) &&
-                         (HDD_MAX_NUM_TDLS_STA > wlan_hdd_tdlsConnectedPeers())
+                         (HDD_MAX_NUM_TDLS_STA > wlan_hdd_tdlsConnectedPeers(pHddTdlsCtx->pAdapter))
                          && (FALSE == curr_peer->isTDLSInProgress)) {
 
                         VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
@@ -338,7 +326,7 @@
                                 curr_peer->peerMac[3], curr_peer->peerMac[4], curr_peer->peerMac[5]);
 
 #ifdef CONFIG_TDLS_IMPLICIT
-                        cfg80211_tdls_oper_request(pHddTdlsCtx->dev,
+                        cfg80211_tdls_oper_request(pHddTdlsCtx->pAdapter->dev,
                                                    curr_peer->peerMac,
                                                    NL80211_TDLS_SETUP, FALSE,
                                                    GFP_KERNEL);
@@ -353,7 +341,7 @@
                                            "Tear down - low RSSI: " MAC_ADDRESS_STR "!",
                                            MAC_ADDR_ARRAY(curr_peer->peerMac));
 #ifdef CONFIG_TDLS_IMPLICIT
-                        cfg80211_tdls_oper_request(pHddTdlsCtx->dev,
+                        cfg80211_tdls_oper_request(pHddTdlsCtx->pAdapter->dev,
                                                    curr_peer->peerMac,
                                                    NL80211_TDLS_TEARDOWN, FALSE,
                                                    GFP_KERNEL);
@@ -399,14 +387,12 @@
                 if (eTDLS_LINK_CONNECTED != curr_peer->link_status) {
                     if (curr_peer->tx_pkt >=
                             pHddTdlsCtx->threshold_config.tx_packet_n) {
-                        hdd_adapter_t *pAdapter;
-
-                        pAdapter = WLAN_HDD_GET_PRIV_PTR(pHddTdlsCtx->dev);
 
                         if (++curr_peer->discovery_attempt <
                                  pHddTdlsCtx->threshold_config.discovery_tries_n) {
-                            sme_SendTdlsMgmtFrame(WLAN_HDD_GET_HAL_CTX(pAdapter),
-                                                  pAdapter->sessionId,
+
+                            sme_SendTdlsMgmtFrame(WLAN_HDD_GET_HAL_CTX(pHddTdlsCtx->pAdapter),
+                                                  pHddTdlsCtx->pAdapter->sessionId,
                                                   curr_peer->peerMac,
                                                   WLAN_TDLS_DISCOVERY_REQUEST,
                                                   1, 0, NULL, 0, 0);
@@ -437,7 +423,6 @@
 #ifdef CONFIG_TDLS_IMPLICIT
     hddTdlsPeer_t *curr_peer = (hddTdlsPeer_t *)userData;
 
-
     VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
                "%s: Tx/Rx Idle " MAC_ADDRESS_STR " trigger teardown",
                __func__,
@@ -449,7 +434,7 @@
        return;
     }
 
-    cfg80211_tdls_oper_request(pHddTdlsCtx->dev,
+    cfg80211_tdls_oper_request(curr_peer->pHddTdlsCtx->pAdapter->dev,
                                curr_peer->peerMac,
                                NL80211_TDLS_TEARDOWN,
                                eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON,
@@ -458,7 +443,7 @@
 #endif
 }
 
-static void wlan_hdd_tdls_free_list(void)
+static void wlan_hdd_tdls_free_list(tdlsCtx_t *pHddTdlsCtx)
 {
     int i;
     struct list_head *head;
@@ -478,11 +463,12 @@
     }
 }
 
-static int wlan_hdd_tdls_core_init(struct net_device *dev, tdls_config_params_t *config)
+static int wlan_hdd_tdls_core_init(hdd_adapter_t *pAdapter, tdls_config_params_t *config)
 {
-    hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
     hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
+    tdlsCtx_t *pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
     int i;
+    v_U8_t staIdx;
 
     if (NULL == pHddTdlsCtx) {
         pHddTdlsCtx = vos_mem_malloc(sizeof(tdlsCtx_t));
@@ -525,7 +511,16 @@
             INIT_LIST_HEAD(&pHddTdlsCtx->peer_list[i]);
         }
 
-        pHddTdlsCtx->dev = dev;
+        pHddTdlsCtx->pAdapter = pAdapter;
+    }
+
+    pHddCtx->connected_peer_count= 0;
+    for (staIdx = 0; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
+    {
+         pHddCtx->tdlsConnInfo[staIdx].staId = 0;
+         pHddCtx->tdlsConnInfo[staIdx].sessionId = 255;
+         vos_mem_zero(&pHddCtx->tdlsConnInfo[staIdx].peerMac,
+                                            sizeof(v_MACADDR_t)) ;
     }
 
     vos_timer_init(&pHddTdlsCtx->peerDiscoverTimer,
@@ -545,13 +540,13 @@
         vos_timer_start( &pHddTdlsCtx->peerUpdateTimer,
                             pHddTdlsCtx->threshold_config.tx_period_t );
     }
+    pAdapter->sessionCtx.station.pHddTdlsCtx = pHddTdlsCtx;
 
     return 0;
 }
 
-int wlan_hdd_tdls_init(struct net_device *dev)
+int wlan_hdd_tdls_init(hdd_adapter_t *pAdapter)
 {
-    hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
     hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
 
     mutex_init(&tdls_lock);
@@ -571,17 +566,21 @@
         hddLog(VOS_TRACE_LEVEL_ERROR, "%s TDLS Implicit trigger not enabled!", __func__);
     }
 
-    return wlan_hdd_tdls_core_init(dev, NULL);
+    return wlan_hdd_tdls_core_init(pAdapter, NULL);
 }
 
-void wlan_hdd_tdls_exit()
+void wlan_hdd_tdls_exit(hdd_adapter_t *pAdapter)
 {
+    tdlsCtx_t *pHddTdlsCtx;
+
     if (mutex_lock_interruptible(&tdls_lock))
     {
        VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
                  "%s: unable to lock list", __func__);
        return;
     }
+
+    pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
     if (NULL == pHddTdlsCtx)
     {
         mutex_unlock(&tdls_lock);
@@ -591,8 +590,8 @@
 
     /* must stop timer here before freeing peer list, because peerIdleTimer is
     part of peer list structure. */
-    wlan_hdd_tdls_timers_destroy();
-    wlan_hdd_tdls_free_list();
+    wlan_hdd_tdls_timers_destroy(pHddTdlsCtx);
+    wlan_hdd_tdls_free_list(pHddTdlsCtx);
 
     vos_mem_free(pHddTdlsCtx);
     pHddTdlsCtx = NULL;
@@ -600,7 +599,7 @@
 }
 
 /* stop all the tdls timers running */
-static void wlan_hdd_tdls_timers_stop(void)
+static void wlan_hdd_tdls_timers_stop(tdlsCtx_t *pHddTdlsCtx)
 {
     int i;
     struct list_head *head;
@@ -628,7 +627,7 @@
 }
 
 /* destroy all the tdls timers running */
-static void wlan_hdd_tdls_timers_destroy(void)
+static void wlan_hdd_tdls_timers_destroy(tdlsCtx_t *pHddTdlsCtx)
 {
     int i;
     struct list_head *head;
@@ -661,17 +660,22 @@
    if mac address doesn't exist, create a list and add, return pointer
    return NULL if fails to get new mac address
 */
-hddTdlsPeer_t *wlan_hdd_tdls_get_peer(u8 *mac)
+hddTdlsPeer_t *wlan_hdd_tdls_get_peer(hdd_adapter_t *pAdapter, u8 *mac)
 {
     struct list_head *head;
     hddTdlsPeer_t *peer;
     u8 key;
+    tdlsCtx_t *pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
 
     if (NULL == pHddTdlsCtx)
+    {
+        VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
+                  "%s: pHddTdlsCtx is NULL", __func__);
         return NULL;
+    }
 
     /* if already there, just update */
-    peer = wlan_hdd_tdls_find_peer(mac);
+    peer = wlan_hdd_tdls_find_peer(pAdapter, mac);
     if (peer != NULL)
     {
         return peer;
@@ -696,6 +700,7 @@
 
     vos_mem_zero(peer, sizeof(hddTdlsPeer_t));
     vos_mem_copy(peer->peerMac, mac, sizeof(peer->peerMac));
+    peer->pHddTdlsCtx = pHddTdlsCtx;
 
     vos_timer_init(&peer->peerIdleTimer,
                     VOS_TIMER_TYPE_SW,
@@ -720,13 +725,11 @@
 
 }
 
-int wlan_hdd_tdls_recv_discovery_resp(u8 *mac)
+int wlan_hdd_tdls_recv_discovery_resp(hdd_adapter_t *pAdapter, u8 *mac)
 {
     hddTdlsPeer_t *curr_peer;
 
-    if (NULL == pHddTdlsCtx) return -1;
-
-    curr_peer = wlan_hdd_tdls_get_peer(mac);
+    curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
     if (curr_peer == NULL)
         return -1;
     VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
@@ -734,7 +737,7 @@
                MAC_ADDR_ARRAY(curr_peer->peerMac), curr_peer->link_status);
     if (curr_peer->link_status == eTDLS_LINK_DISCOVERING)
     {
-        cfg80211_tdls_oper_request(pHddTdlsCtx->dev,
+        cfg80211_tdls_oper_request(pAdapter->dev,
                                    curr_peer->peerMac,
                                    NL80211_TDLS_SETUP, FALSE,
                                    GFP_KERNEL);
@@ -749,13 +752,11 @@
     return 0;
 }
 
-int wlan_hdd_tdls_set_rssi(u8 *mac, tANI_S8 rxRssi)
+int wlan_hdd_tdls_set_rssi(hdd_adapter_t *pAdapter, u8 *mac, tANI_S8 rxRssi)
 {
     hddTdlsPeer_t *curr_peer;
 
-    if (NULL == pHddTdlsCtx) return -1;
-
-    curr_peer = wlan_hdd_tdls_get_peer(mac);
+    curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
     if (curr_peer == NULL)
         return -1;
 
@@ -764,13 +765,11 @@
     return 0;
 }
 
-int wlan_hdd_tdls_set_responder(u8 *mac, tANI_U8 responder)
+int wlan_hdd_tdls_set_responder(hdd_adapter_t *pAdapter, u8 *mac, tANI_U8 responder)
 {
     hddTdlsPeer_t *curr_peer;
 
-    if (NULL == pHddTdlsCtx) return -1;
-
-    curr_peer = wlan_hdd_tdls_get_peer(mac);
+    curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
     if (curr_peer == NULL)
         return -1;
 
@@ -779,26 +778,22 @@
     return 0;
 }
 
-int wlan_hdd_tdls_get_responder(u8 *mac)
+int wlan_hdd_tdls_get_responder(hdd_adapter_t *pAdapter, u8 *mac)
 {
     hddTdlsPeer_t *curr_peer;
 
-    if (NULL == pHddTdlsCtx) return -1;
-
-    curr_peer = wlan_hdd_tdls_find_peer(mac);
+    curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac);
     if (curr_peer == NULL)
         return -1;
 
     return (curr_peer->is_responder);
 }
 
-int wlan_hdd_tdls_set_signature(u8 *mac, tANI_U8 uSignature)
+int wlan_hdd_tdls_set_signature(hdd_adapter_t *pAdapter, u8 *mac, tANI_U8 uSignature)
 {
     hddTdlsPeer_t *curr_peer;
 
-    if (NULL == pHddTdlsCtx) return -1;
-
-    curr_peer = wlan_hdd_tdls_get_peer(mac);
+    curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
     if (curr_peer == NULL)
         return -1;
 
@@ -818,13 +813,15 @@
     memcpy(mac, skb->data+6, 6);
 }
 
-int wlan_hdd_tdls_increment_pkt_count(u8 *mac, u8 tx)
+int wlan_hdd_tdls_increment_pkt_count(hdd_adapter_t *pAdapter, u8 *mac, u8 tx)
 {
     hddTdlsPeer_t *curr_peer;
+    hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
 
-    if (NULL == pHddTdlsCtx) return -1;
+    if (eTDLS_SUPPORT_ENABLED != pHddCtx->tdls_mode)
+        return -1;
 
-    curr_peer = wlan_hdd_tdls_get_peer(mac);
+    curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
     if (curr_peer == NULL)
         return -1;
 
@@ -840,6 +837,7 @@
 {
     hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
     hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
+    tdlsCtx_t *pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
 
     if ((eTDLS_SUPPORT_DISABLED == config->tdls) &&
         ((NULL == pHddTdlsCtx) ||
@@ -854,7 +852,7 @@
         memcpy(&pHddTdlsCtx->threshold_config, config, sizeof(tdls_config_params_t));
     }
 
-    wlan_hdd_tdls_peer_reset_discovery_processed();
+    wlan_hdd_tdls_peer_reset_discovery_processed(pHddTdlsCtx);
 
     VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
             "iw set tdls params: %d %d %d %d %d %d %d %d %d %d",
@@ -872,21 +870,19 @@
     pHddCtx->tdls_mode = config->tdls;
 
     if (eTDLS_SUPPORT_DISABLED == config->tdls) {
-        wlan_hdd_tdls_exit();
+        wlan_hdd_tdls_exit(pAdapter);
     } else {
-        wlan_hdd_tdls_core_init(dev, config);
+        wlan_hdd_tdls_core_init(pAdapter, config);
     }
 
     return 0;
 }
 
-int wlan_hdd_tdls_set_sta_id(u8 *mac, u8 staId)
+int wlan_hdd_tdls_set_sta_id(hdd_adapter_t *pAdapter, u8 *mac, u8 staId)
 {
     hddTdlsPeer_t *curr_peer;
 
-    if (NULL == pHddTdlsCtx) return -1;
-
-    curr_peer = wlan_hdd_tdls_get_peer(mac);
+    curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
     if (curr_peer == NULL)
         return -1;
 
@@ -898,12 +894,13 @@
 /* if peerMac is found, then it returns pointer to hddTdlsPeer_t
    otherwise, it returns NULL
 */
-hddTdlsPeer_t *wlan_hdd_tdls_find_peer(u8 *mac)
+hddTdlsPeer_t *wlan_hdd_tdls_find_peer(hdd_adapter_t *pAdapter, u8 *mac)
 {
     u8 key;
     struct list_head *pos;
     struct list_head *head;
     hddTdlsPeer_t *curr_peer;
+    tdlsCtx_t *pHddTdlsCtx;
 
 
     if (mutex_lock_interruptible(&tdls_lock))
@@ -912,9 +909,12 @@
                  "%s: unable to lock list", __func__);
        return NULL;
     }
+    pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
     if (NULL == pHddTdlsCtx)
     {
         mutex_unlock(&tdls_lock);
+        VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
+                  "%s: pHddTdlsCtx is NULL", __func__);
         return NULL;
     }
 
@@ -936,18 +936,14 @@
     return NULL;
 }
 
-int wlan_hdd_tdls_reset_peer(u8 *mac)
+int wlan_hdd_tdls_reset_peer(hdd_adapter_t *pAdapter, u8 *mac)
 {
-    hdd_adapter_t *pAdapter;
     hdd_context_t *pHddCtx;
     hddTdlsPeer_t *curr_peer;
 
-    if (NULL == pHddTdlsCtx) return -1;
-
-    pAdapter = WLAN_HDD_GET_PRIV_PTR(pHddTdlsCtx->dev);
     pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
 
-    curr_peer = wlan_hdd_tdls_get_peer(mac);
+    curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
     if (curr_peer == NULL)
         return -1;
 
@@ -960,7 +956,7 @@
     return 0;
 }
 
-static tANI_S32 wlan_hdd_tdls_peer_reset_discovery_processed(void)
+static tANI_S32 wlan_hdd_tdls_peer_reset_discovery_processed(tdlsCtx_t *pHddTdlsCtx)
 {
     int i;
     struct list_head *head;
@@ -993,7 +989,7 @@
     return 0;
 }
 
-static tANI_S32 wlan_hdd_get_tdls_discovery_peer_cnt(void)
+static tANI_S32 wlan_hdd_get_tdls_discovery_peer_cnt(tdlsCtx_t *pHddTdlsCtx)
 {
     int i;
     struct list_head *head;
@@ -1018,21 +1014,24 @@
     return discovery_peer_cnt;
 }
 
-tANI_U16 wlan_hdd_tdlsConnectedPeers(void)
+tANI_U16 wlan_hdd_tdlsConnectedPeers(hdd_adapter_t *pAdapter)
 {
-    if (NULL == pHddTdlsCtx)
+    hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
+
+    if (NULL == pHddCtx)
         return 0;
 
-    return pHddTdlsCtx->connected_peer_count;
+    return pHddCtx->connected_peer_count;
 }
 
-int wlan_hdd_tdls_get_all_peers(char *buf, int buflen)
+int wlan_hdd_tdls_get_all_peers(hdd_adapter_t *pAdapter, char *buf, int buflen)
 {
     int i;
     int len, init_len;
     struct list_head *head;
     struct list_head *pos;
     hddTdlsPeer_t *curr_peer;
+    tdlsCtx_t *pHddTdlsCtx;
 
 
     init_len = buflen;
@@ -1050,6 +1049,7 @@
                  "%s: unable to lock list", __func__);
        return init_len-buflen;
     }
+    pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
     if (NULL == pHddTdlsCtx) {
         mutex_unlock(&tdls_lock);
         len = snprintf(buf, buflen, "TDLS not enabled\n");
@@ -1081,6 +1081,7 @@
 void wlan_hdd_tdls_connection_callback(hdd_adapter_t *pAdapter)
 {
     hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
+    tdlsCtx_t *pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
 
     if (NULL == pHddTdlsCtx) return;
 
@@ -1089,11 +1090,9 @@
         pHddTdlsCtx->threshold_config.tx_period_t,
         pHddTdlsCtx->threshold_config.discovery_period_t);
 
-    pHddTdlsCtx->connected_peer_count = 0;
-
     if (eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode)
     {
-       wlan_hdd_tdls_peer_reset_discovery_processed();
+       wlan_hdd_tdls_peer_reset_discovery_processed(pHddTdlsCtx);
 
        vos_timer_start(&pHddTdlsCtx->peerDiscoverTimer,
                        pHddTdlsCtx->threshold_config.discovery_period_t);
@@ -1107,6 +1106,7 @@
 
 void wlan_hdd_tdls_disconnection_callback(hdd_adapter_t *pAdapter)
 {
+    tdlsCtx_t *pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
 
     VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,"%s", __func__);
 
@@ -1122,9 +1122,8 @@
         return;
     }
 
-
-    wlan_hdd_tdls_timers_stop();
-    wlan_hdd_tdls_free_list();
+    wlan_hdd_tdls_timers_stop(pHddTdlsCtx);
+    wlan_hdd_tdls_free_list(pHddTdlsCtx);
 
     mutex_unlock(&tdls_lock);
 }
@@ -1137,31 +1136,37 @@
     complete(&pAdapter->tdls_mgmt_comp);
 }
 
-void wlan_hdd_tdls_increment_peer_count(void)
+void wlan_hdd_tdls_increment_peer_count(hdd_adapter_t *pAdapter)
 {
-    if (NULL == pHddTdlsCtx) return;
+    hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
 
-    pHddTdlsCtx->connected_peer_count++;
+    if (NULL == pHddCtx) return;
+
+    pHddCtx->connected_peer_count++;
 }
 
-void wlan_hdd_tdls_decrement_peer_count(void)
+void wlan_hdd_tdls_decrement_peer_count(hdd_adapter_t *pAdapter)
 {
-    if (NULL == pHddTdlsCtx) return;
+    hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
 
-    if (pHddTdlsCtx->connected_peer_count)
-        pHddTdlsCtx->connected_peer_count--;
+    if (NULL == pHddCtx) return;
+
+    if (pHddCtx->connected_peer_count)
+        pHddCtx->connected_peer_count--;
 }
 
-void wlan_hdd_tdls_check_bmps(hdd_context_t *pHddCtx)
+void wlan_hdd_tdls_check_bmps(hdd_adapter_t *pAdapter)
 {
-    if (NULL == pHddTdlsCtx) return;
+    hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
 
-    if (0 == pHddTdlsCtx->connected_peer_count)
+    if (NULL == pHddCtx) return;
+
+    if (0 == pHddCtx->connected_peer_count)
     {
         VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,"No TDLS peer connected so Enable BMPS");
         hdd_enable_bmps_imps(pHddCtx);
     }
-    else if (1 == pHddTdlsCtx->connected_peer_count)
+    else if (1 == pHddCtx->connected_peer_count)
     {
         VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,"TDLS peer connected so Disable BMPS");
         hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
@@ -1174,12 +1179,13 @@
  * skip_self - if TRUE, skip this mac. otherwise, check all the peer list. if
    mac is NULL, this argument is ignored, and check for all the peer list.
  */
-u8 wlan_hdd_tdls_is_progress(u8 *mac, u8 skip_self)
+u8 wlan_hdd_tdls_is_progress(hdd_adapter_t *pAdapter, u8 *mac, u8 skip_self)
 {
     int i;
     struct list_head *head;
     hddTdlsPeer_t *curr_peer;
     struct list_head *pos;
+    tdlsCtx_t *pHddTdlsCtx;
 
     if (mutex_lock_interruptible(&tdls_lock))
     {
@@ -1187,6 +1193,7 @@
                  "%s: unable to lock list", __func__);
        return FALSE;
     }
+    pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
     if (NULL == pHddTdlsCtx)
     {
         mutex_unlock(&tdls_lock);
@@ -1215,13 +1222,11 @@
     return FALSE;
 }
 
-void wlan_hdd_tdls_set_connection_progress(u8* mac, u8 isProgress)
+void wlan_hdd_tdls_set_connection_progress(hdd_adapter_t *pAdapter, u8* mac, u8 isProgress)
 {
     hddTdlsPeer_t *curr_peer;
 
-    if (NULL == pHddTdlsCtx) return;
-
-    curr_peer = wlan_hdd_tdls_find_peer(mac);
+    curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac);
     if (curr_peer == NULL)
         return;
 
diff --git a/CORE/HDD/src/wlan_hdd_tx_rx.c b/CORE/HDD/src/wlan_hdd_tx_rx.c
index b5d3d3f..e84948a 100644
--- a/CORE/HDD/src/wlan_hdd_tx_rx.c
+++ b/CORE/HDD/src/wlan_hdd_tx_rx.c
@@ -1073,7 +1073,7 @@
                       "extract mac:%x %x %x %x %x %x",
                       mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] );
 
-            wlan_hdd_tdls_increment_pkt_count(mac, 1);
+            wlan_hdd_tdls_increment_pkt_count(pAdapter, mac, 1);
         } else {
             VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_MED,
                        "packet da is bssid, not adding to peer list");
@@ -1392,7 +1392,7 @@
                       "rx extract mac:%x %x %x %x %x %x",
                       mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] );
 
-            wlan_hdd_tdls_increment_pkt_count(mac, 0);
+            wlan_hdd_tdls_increment_pkt_count(pAdapter, mac, 0);
         } else {
             VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_MED,
                        "rx packet sa is bssid, not adding to peer list");
diff --git a/CORE/HDD/src/wlan_hdd_wext.c b/CORE/HDD/src/wlan_hdd_wext.c
index c5247d3..461811a 100644
--- a/CORE/HDD/src/wlan_hdd_wext.c
+++ b/CORE/HDD/src/wlan_hdd_wext.c
@@ -4097,7 +4097,7 @@
 #ifdef FEATURE_WLAN_TDLS
         case WE_GET_TDLS_PEERS:
         {
-            wrqu->data.length = wlan_hdd_tdls_get_all_peers(extra, WE_MAX_STR_LEN)+1;
+            wrqu->data.length = wlan_hdd_tdls_get_all_peers(pAdapter, extra, WE_MAX_STR_LEN)+1;
             break;
         }
 #endif