blob: d0808206e219fb27728d512f51bee2bb686b5cf7 [file] [log] [blame]
Kiran V1ccee932012-12-12 14:49:46 -08001/*
Pradeep Reddy POTTETIc7822df2015-02-19 20:15:41 +05302 * Copyright (c) 2012-2015 The Linux Foundation. All rights reserved.
Kiet Lam842dad02014-02-18 18:44:02 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
Gopichand Nakkala0c1331e2013-01-07 22:49:07 -080020 */
Kiet Lam842dad02014-02-18 18:44:02 -080021
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
Kiran V1ccee932012-12-12 14:49:46 -080028/**========================================================================
29
30 \file wlan_hdd_tdls.c
31
Chilam NG571c65a2013-01-19 12:27:36 +053032 \brief WLAN Host Device Driver implementation for TDLS
Kiran V1ccee932012-12-12 14:49:46 -080033
Kiran V1ccee932012-12-12 14:49:46 -080034 ========================================================================*/
35
36#include <wlan_hdd_includes.h>
37#include <wlan_hdd_hostapd.h>
38#include <net/cfg80211.h>
39#include <linux/netdevice.h>
40#include <linux/skbuff.h>
Chilam NG571c65a2013-01-19 12:27:36 +053041#include <linux/list.h>
Kiran V1ccee932012-12-12 14:49:46 -080042#include <linux/etherdevice.h>
43#include <net/ieee80211_radiotap.h>
44#include "wlan_hdd_tdls.h"
Chilam NG571c65a2013-01-19 12:27:36 +053045#include "wlan_hdd_cfg80211.h"
Masti, Narayanraddi1fb32a92015-06-29 13:14:06 +053046#include "wlan_hdd_assoc.h"
47#include "sme_Api.h"
Mahesh A Saptasagar8b231b32014-08-11 11:58:15 +053048#include "vos_sched.h"
Chilam NG571c65a2013-01-19 12:27:36 +053049
Gopichand Nakkala4327a152013-03-04 23:22:42 -080050static tANI_S32 wlan_hdd_get_tdls_discovery_peer_cnt(tdlsCtx_t *pHddTdlsCtx);
51static tANI_S32 wlan_hdd_tdls_peer_reset_discovery_processed(tdlsCtx_t *pHddTdlsCtx);
52static void wlan_hdd_tdls_timers_destroy(tdlsCtx_t *pHddTdlsCtx);
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +053053static void wlan_hdd_tdls_peer_timers_destroy(tdlsCtx_t *pHddTdlsCtx);
Sunil Dutt41de4e22013-11-14 18:09:02 +053054int wpa_tdls_is_allowed_force_peer(tdlsCtx_t *pHddTdlsCtx, u8 *mac);
Hoonki Leed37cbb32013-04-20 00:31:14 -070055#ifdef CONFIG_TDLS_IMPLICIT
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +053056static void wlan_hdd_tdls_implicit_send_discovery_request(tdlsCtx_t *pHddTdlsCtx);
Hoonki Leed37cbb32013-04-20 00:31:14 -070057#endif
Chilam NG571c65a2013-01-19 12:27:36 +053058
Anand N Sunkadb3ab97d2015-07-29 09:58:13 +053059static u8 wlan_hdd_tdls_hash_key (
60#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
61 const u8 *mac
62#else
63 u8 *mac
64#endif
65 )
Hoonki Leef63df0d2013-01-16 19:29:14 -080066{
67 int i;
Hoonki Lee387663d2013-02-05 18:08:43 -080068 u8 key = 0;
69
70 for (i = 0; i < 6; i++)
71 key ^= mac[i];
72
73 return key;
74}
75
Masti, Narayanraddifdde4d02015-04-16 14:41:51 +053076/**
77 * wlan_hdd_tdls_disable_offchan_and_teardown_links - Disable offchannel
78 * and teardown TDLS links
79 * @hddCtx : pointer to hdd context
80 *
81 * Return: None
82 */
83void wlan_hdd_tdls_disable_offchan_and_teardown_links(hdd_context_t *hddctx)
84{
85 u16 connected_tdls_peers = 0;
Masti, Narayanraddi1fb32a92015-06-29 13:14:06 +053086 u8 staIdx;
Masti, Narayanraddi471e9382015-07-23 18:51:29 +053087 hddTdlsPeer_t *curr_peer = NULL;
Masti, Narayanraddifdde4d02015-04-16 14:41:51 +053088 hdd_adapter_t *adapter = NULL;
89
90 if (eTDLS_SUPPORT_NOT_ENABLED == hddctx->tdls_mode) {
91 hddLog(LOG1, FL("TDLS mode is disabled OR not enabled in FW"));
92 return ;
93 }
94
95 adapter = hdd_get_adapter(hddctx, WLAN_HDD_INFRA_STATION);
96
97 if (adapter == NULL) {
98 hddLog(LOGE, FL("Station Adapter Not Found"));
Masti, Narayanraddi70e5b472015-08-04 12:54:16 +053099 goto done;
Masti, Narayanraddifdde4d02015-04-16 14:41:51 +0530100 }
101
102 connected_tdls_peers = wlan_hdd_tdlsConnectedPeers(adapter);
Masti, Narayanraddi1fb32a92015-06-29 13:14:06 +0530103 if (!connected_tdls_peers) {
Masti, Narayanraddi70e5b472015-08-04 12:54:16 +0530104 hddLog(LOG1, FL("No TDLS connected peers to delete TDLS peers"));
105 goto done;
Masti, Narayanraddi1fb32a92015-06-29 13:14:06 +0530106 }
Masti, Narayanraddifdde4d02015-04-16 14:41:51 +0530107
Masti, Narayanraddi471e9382015-07-23 18:51:29 +0530108 /* TDLS is not supported in case of concurrency
109 * Disable TDLS Offchannel to avoid more than two concurrent channels.
110 */
111 if (connected_tdls_peers == 1) {
112 curr_peer = wlan_hdd_tdls_get_connected_peer(adapter);
113 if (curr_peer && (curr_peer->isOffChannelConfigured == TRUE)) {
114 hddLog(LOG1, FL("%s: Concurrency detected, Disable "
115 "TDLS channel switch"), __func__);
116 curr_peer->isOffChannelEstablished = FALSE;
117 sme_SendTdlsChanSwitchReq(WLAN_HDD_GET_HAL_CTX(adapter),
118 adapter->sessionId,
119 curr_peer->peerMac,
120 curr_peer->peerParams.channel,
121 TDLS_OFF_CHANNEL_BW_OFFSET,
122 TDLS_CHANNEL_SWITCH_DISABLE);
Masti, Narayanraddifdde4d02015-04-16 14:41:51 +0530123 }
124 }
Masti, Narayanraddi471e9382015-07-23 18:51:29 +0530125
126 /* Send Msg to PE for sending deauth and deleting all the TDLS peers */
127 sme_DeleteAllTDLSPeers(hddctx->hHal, adapter->sessionId);
128
129 /* As mentioned above TDLS is not supported in case of concurrency
130 * Find the connected peer and generate TDLS teardown indication to
131 * supplicant.
132 */
133 for (staIdx = 0; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++) {
134 if (!hddctx->tdlsConnInfo[staIdx].staId)
135 continue;
136
137 curr_peer = wlan_hdd_tdls_find_all_peer(hddctx,
138 hddctx->tdlsConnInfo[staIdx].peerMac.bytes);
139
140 if (!curr_peer)
141 continue;
142
143 /* Del Sta happened already as part of sme_DeleteAllTDLSPeers
144 * Hence clear hdd data structure.
145 */
146 hdd_roamDeregisterTDLSSTA(adapter,
147 hddctx->tdlsConnInfo[staIdx].staId);
148 wlan_hdd_tdls_decrement_peer_count(adapter);
149 wlan_hdd_tdls_reset_peer(adapter, curr_peer->peerMac);
150
151 hddctx->tdlsConnInfo[staIdx].staId = 0 ;
152 hddctx->tdlsConnInfo[staIdx].sessionId = 255;
153 vos_mem_zero(&hddctx->tdlsConnInfo[staIdx].peerMac,
154 sizeof(v_MACADDR_t)) ;
155 wlan_hdd_tdls_check_bmps(adapter);
156
157 hddLog(LOG1, FL("indicate TDLS teardown (staId %d)"),
158 curr_peer->staId);
159
160 /* Indicate teardown to supplicant */
161 wlan_hdd_tdls_indicate_teardown(
162 curr_peer->pHddTdlsCtx->pAdapter,
163 curr_peer,
164 eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON);
165 }
166
Masti, Narayanraddi70e5b472015-08-04 12:54:16 +0530167done:
Masti, Narayanraddifdde4d02015-04-16 14:41:51 +0530168 wlan_hdd_tdls_set_mode(hddctx, eTDLS_SUPPORT_DISABLED, FALSE);
169 hddLog(LOG1, FL("TDLS Support Disabled"));
170}
171
172/**
173 * hdd_tdls_notify_mode_change - Notify mode change
174 * @adapter: pointer to hdd adapter
175 * @hddCtx : pointer to hdd context
176 *
177 * Return: None
178 */
179void hdd_tdls_notify_mode_change(hdd_adapter_t *adapter, hdd_context_t *hddctx)
180{
181 if (adapter->device_mode != WLAN_HDD_INFRA_STATION)
182 wlan_hdd_tdls_disable_offchan_and_teardown_links(hddctx);
183}
184
Gopichand Nakkala4327a152013-03-04 23:22:42 -0800185static v_VOID_t wlan_hdd_tdls_start_peer_discover_timer(tdlsCtx_t *pHddTdlsCtx,
186 tANI_BOOLEAN mutexLock,
187 v_U32_t discoveryExpiry)
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800188{
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800189 hdd_station_ctx_t *pHddStaCtx;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530190 hdd_context_t *pHddCtx;
191
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530192 ENTER();
193
c_hpothu7f63e882013-10-02 19:13:35 +0530194 if ((NULL == pHddTdlsCtx) || (NULL == pHddTdlsCtx->pAdapter) )
195 {
196 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
197 FL(" pHddTdlsCtx or pAdapter points to NULL"));
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530198 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530199 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530200
201 pHddCtx = WLAN_HDD_GET_CTX( pHddTdlsCtx->pAdapter );
202
c_hpothu7f63e882013-10-02 19:13:35 +0530203 if(0 != (wlan_hdd_validate_context(pHddCtx)))
204 {
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530205 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530206 }
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800207
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800208 if ( mutexLock )
209 {
Rajesh Chauhana34c6e62014-03-25 16:37:58 +0530210 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800211 }
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800212
Gopichand Nakkala4327a152013-03-04 23:22:42 -0800213 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pHddTdlsCtx->pAdapter);
Deepthi Gowri681c9432015-05-14 11:51:11 +0530214
Gopichand Nakkala3046fc92013-03-23 13:56:43 -0700215 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "beacon rssi: %d",
216 pHddTdlsCtx->ap_rssi);
217
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800218 if ( mutexLock )
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530219 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800220
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530221 EXIT();
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800222 return;
223}
224
Hoonki Leed37cbb32013-04-20 00:31:14 -0700225#ifdef TDLS_USE_SEPARATE_DISCOVERY_TIMER
Hoonki Lee387663d2013-02-05 18:08:43 -0800226static v_VOID_t wlan_hdd_tdls_discover_peer_cb( v_PVOID_t userData )
227{
228 int i;
229 struct list_head *head;
230 struct list_head *pos;
Chilam NG571c65a2013-01-19 12:27:36 +0530231 hddTdlsPeer_t *curr_peer;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530232 hdd_context_t *pHddCtx;
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530233 tdlsCtx_t *pHddTdlsCtx;
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800234 int discover_req_sent = 0;
235 v_U32_t discover_expiry = TDLS_SUB_DISCOVERY_PERIOD;
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800236 tANI_BOOLEAN doMutexLock = eANI_BOOLEAN_TRUE;
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530237 v_CONTEXT_t pVosContext;
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800238
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530239 ENTER();
240
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530241 pVosContext = vos_get_global_context(VOS_MODULE_ID_HDD, NULL);
242 if (NULL == pVosContext)
c_hpothu7f63e882013-10-02 19:13:35 +0530243 {
244 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530245 FL("pVosContext points to NULL"));
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530246 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530247 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530248
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530249 pHddCtx = vos_get_context(VOS_MODULE_ID_HDD, pVosContext);
250 if (0 != (wlan_hdd_validate_context(pHddCtx)))
Sushant Kaushik15c4c522014-08-14 12:24:49 +0530251 {
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530252 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530253 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530254
Rajesh Chauhana34c6e62014-03-25 16:37:58 +0530255 mutex_lock(&pHddCtx->tdls_lock);
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530256 pHddTdlsCtx = (tdlsCtx_t *)userData;
257 if (0 != (wlan_hdd_validate_tdls_context(pHddCtx, pHddTdlsCtx)))
258 {
259 mutex_unlock(&pHddCtx->tdls_lock);
260 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
261 FL("Invalid pHddTdlsCtx context"));
262 return;
263 }
Hoonki Leebfee0342013-01-21 16:43:45 -0800264
Hoonki Lee387663d2013-02-05 18:08:43 -0800265 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: ", __func__);
266
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800267 if (0 == pHddTdlsCtx->discovery_peer_cnt)
Gopichand Nakkala4327a152013-03-04 23:22:42 -0800268 pHddTdlsCtx->discovery_peer_cnt = wlan_hdd_get_tdls_discovery_peer_cnt(pHddTdlsCtx);
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800269
Chilam NG571c65a2013-01-19 12:27:36 +0530270 for (i = 0; i < 256; i++) {
Hoonki Lee387663d2013-02-05 18:08:43 -0800271 head = &pHddTdlsCtx->peer_list[i];
Chilam NG571c65a2013-01-19 12:27:36 +0530272
Hoonki Lee387663d2013-02-05 18:08:43 -0800273 list_for_each (pos, head) {
274 curr_peer = list_entry (pos, hddTdlsPeer_t, node);
Chilam NG571c65a2013-01-19 12:27:36 +0530275
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530276 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Chilam Ng01120412013-02-19 18:32:21 -0800277 "%d " MAC_ADDRESS_STR " %d %d, %d %d %d %d", i,
278 MAC_ADDR_ARRAY(curr_peer->peerMac),
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800279 curr_peer->discovery_processed,
280 discover_req_sent,
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -0800281 curr_peer->tdls_support,
282 curr_peer->link_status,
283 curr_peer->discovery_attempt,
284 pHddTdlsCtx->threshold_config.discovery_tries_n);
Hoonki Lee387663d2013-02-05 18:08:43 -0800285
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800286 if (discover_req_sent < TDLS_MAX_DISCOVER_REQS_PER_TIMER) {
287 if (!curr_peer->discovery_processed) {
Chilam NG571c65a2013-01-19 12:27:36 +0530288
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800289 curr_peer->discovery_processed = 1;
290 discover_req_sent++;
291 pHddTdlsCtx->discovery_peer_cnt--;
292
293 if ((eTDLS_CAP_UNKNOWN == curr_peer->tdls_support) &&
Gopichand Nakkala901e8922013-03-04 23:45:58 -0800294 (eTDLS_LINK_IDLE == curr_peer->link_status) &&
Gopichand Nakkalab88f6772013-02-27 18:12:56 -0800295 (curr_peer->tx_pkt >=
296 pHddTdlsCtx->threshold_config.tx_packet_n)) {
Gopichand Nakkala273d5a02013-02-19 15:15:09 -0800297
298 if (curr_peer->discovery_attempt <
299 pHddTdlsCtx->threshold_config.discovery_tries_n) {
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +0530300 cfg80211_tdls_oper_request(
301 pHddTdlsCtx->pAdapter->dev,
302 curr_peer->peerMac,
303 NL80211_TDLS_DISCOVERY_REQ,
304 FALSE,
305 GFP_KERNEL);
Gopichand Nakkala273d5a02013-02-19 15:15:09 -0800306 curr_peer->discovery_attempt++;
307 }
308 else
309 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530310 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Gopichand Nakkala273d5a02013-02-19 15:15:09 -0800311 "%s: Maximum Discovery retries reached", __func__);
312 curr_peer->tdls_support = eTDLS_CAP_NOT_SUPPORTED;
313 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800314
315 }
316 }
Chilam NG571c65a2013-01-19 12:27:36 +0530317 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800318 else
319 goto exit_loop;
Hoonki Lee387663d2013-02-05 18:08:43 -0800320 }
Hoonki Leef63df0d2013-01-16 19:29:14 -0800321 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800322exit_loop:
Hoonki Leef63df0d2013-01-16 19:29:14 -0800323
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800324 if (0 != pHddTdlsCtx->discovery_peer_cnt) {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530325 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800326 "discovery_peer_cnt is %d , Starting SUB_DISCOVERY_TIMER",
327 pHddTdlsCtx->discovery_peer_cnt);
328 discover_expiry = TDLS_SUB_DISCOVERY_PERIOD;
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800329 doMutexLock = eANI_BOOLEAN_FALSE;
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800330 goto done;
331 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800332 discover_expiry = pHddTdlsCtx->threshold_config.discovery_period_t;
333
Gopichand Nakkala4327a152013-03-04 23:22:42 -0800334 wlan_hdd_tdls_peer_reset_discovery_processed(pHddTdlsCtx);
Chilam NG571c65a2013-01-19 12:27:36 +0530335
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530336 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala638ebc72013-03-21 18:04:02 -0700337
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800338 /* Commenting out the following function as it was introducing
339 * a race condition when pHddTdlsCtx is deleted. Also , this
340 * function is consuming more time in the timer callback.
341 * RSSI based trigger needs to revisit this part of the code.
342 */
343
344 /*
345 * wlan_hdd_get_rssi(pAdapter, &pHddTdlsCtx->ap_rssi);
346 */
Chilam NG571c65a2013-01-19 12:27:36 +0530347
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800348done:
Gopichand Nakkala4327a152013-03-04 23:22:42 -0800349 wlan_hdd_tdls_start_peer_discover_timer(pHddTdlsCtx, doMutexLock, discover_expiry);
Gopichand Nakkala91b09262013-02-10 14:27:02 -0800350
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800351 if ( !doMutexLock )
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530352 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530353 EXIT();
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800354 return;
Hoonki Leef63df0d2013-01-16 19:29:14 -0800355}
Hoonki Leed37cbb32013-04-20 00:31:14 -0700356#endif
Chilam NG571c65a2013-01-19 12:27:36 +0530357
Hoonki Lee387663d2013-02-05 18:08:43 -0800358static v_VOID_t wlan_hdd_tdls_update_peer_cb( v_PVOID_t userData )
Chilam NG571c65a2013-01-19 12:27:36 +0530359{
360 int i;
Hoonki Lee387663d2013-02-05 18:08:43 -0800361 struct list_head *head;
362 struct list_head *pos;
Chilam NG571c65a2013-01-19 12:27:36 +0530363 hddTdlsPeer_t *curr_peer;
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530364 tdlsCtx_t *pHddTdlsCtx;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530365 hdd_context_t *pHddCtx;
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530366 v_CONTEXT_t pVosContext;
Hoonki Leebfee0342013-01-21 16:43:45 -0800367
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530368 ENTER();
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530369 pVosContext = vos_get_global_context(VOS_MODULE_ID_HDD, NULL);
370 if (NULL == pVosContext)
c_hpothu7f63e882013-10-02 19:13:35 +0530371 {
372 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530373 FL("pVosContext points to NULL"));
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530374 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530375 }
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530376 pHddCtx = vos_get_context(VOS_MODULE_ID_HDD, pVosContext);
377 if (0 != (wlan_hdd_validate_context(pHddCtx)))
Sushant Kaushik15c4c522014-08-14 12:24:49 +0530378 {
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530379 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530380 }
Rajesh Chauhana34c6e62014-03-25 16:37:58 +0530381 mutex_lock(&pHddCtx->tdls_lock);
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530382 pHddTdlsCtx = (tdlsCtx_t *)userData;
383 if (0 != (wlan_hdd_validate_tdls_context(pHddCtx, pHddTdlsCtx)))
384 {
385 mutex_unlock(&pHddCtx->tdls_lock);
386 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
387 FL("Invalid pHddTdlsCtx context"));
388 return;
389 }
Chilam NG571c65a2013-01-19 12:27:36 +0530390 for (i = 0; i < 256; i++) {
Hoonki Lee387663d2013-02-05 18:08:43 -0800391 head = &pHddTdlsCtx->peer_list[i];
Chilam NG571c65a2013-01-19 12:27:36 +0530392
Hoonki Lee387663d2013-02-05 18:08:43 -0800393 list_for_each (pos, head) {
394 curr_peer = list_entry (pos, hddTdlsPeer_t, node);
Chilam NG571c65a2013-01-19 12:27:36 +0530395
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530396 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee66b75f32013-04-16 18:30:07 -0700397 "%s: " MAC_ADDRESS_STR " link_status %d"
398 " tdls_support %d", __func__, MAC_ADDR_ARRAY(curr_peer->peerMac),
Gopichand Nakkala34d1b062013-03-19 15:28:33 -0700399 curr_peer->link_status, curr_peer->tdls_support);
Hoonki Lee387663d2013-02-05 18:08:43 -0800400
Chilam NG571c65a2013-01-19 12:27:36 +0530401 if (eTDLS_CAP_SUPPORTED == curr_peer->tdls_support) {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530402 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee66b75f32013-04-16 18:30:07 -0700403 "tx %d, rx %d (thr.pkt %d/idle %d), rssi %d (thr.trig %d/hys %d/tear %d)",
404 curr_peer->tx_pkt, curr_peer->rx_pkt,
Hoonki Lee5a4b2172013-01-29 01:45:53 -0800405 pHddTdlsCtx->threshold_config.tx_packet_n,
Hoonki Lee66b75f32013-04-16 18:30:07 -0700406 pHddTdlsCtx->threshold_config.idle_packet_n,
407 curr_peer->rssi,
408 pHddTdlsCtx->threshold_config.rssi_trigger_threshold,
409 pHddTdlsCtx->threshold_config.rssi_hysteresis,
410 pHddTdlsCtx->threshold_config.rssi_teardown_threshold);
Chilam Ng01120412013-02-19 18:32:21 -0800411
Gopichand Nakkala901e8922013-03-04 23:45:58 -0800412 if ((eTDLS_LINK_IDLE == curr_peer->link_status) ||
413 (eTDLS_LINK_DISCOVERING == curr_peer->link_status)){
Sunil Dutt961ecbd2013-11-28 20:04:07 +0530414
415 if (pHddCtx->cfg_ini->fTDLSExternalControl &&
416 (FALSE == curr_peer->isForcedPeer)) {
417 continue;
418 }
419
Chilam NG571c65a2013-01-19 12:27:36 +0530420 if (curr_peer->tx_pkt >=
421 pHddTdlsCtx->threshold_config.tx_packet_n) {
Hoonki Lee5a4b2172013-01-29 01:45:53 -0800422
Gopichand Nakkala8b00c632013-03-08 19:47:52 -0800423 if (HDD_MAX_NUM_TDLS_STA > wlan_hdd_tdlsConnectedPeers(pHddTdlsCtx->pAdapter))
Gopichand Nakkalab977a972013-02-18 19:15:09 -0800424 {
425
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530426 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
427 "Tput trigger TDLS pre-setup");
Chilam NG571c65a2013-01-19 12:27:36 +0530428#ifdef CONFIG_TDLS_IMPLICIT
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +0530429 pHddTdlsCtx->curr_candidate = curr_peer;
430 wlan_hdd_tdls_implicit_send_discovery_request(pHddTdlsCtx);
Chilam NG571c65a2013-01-19 12:27:36 +0530431#endif
Gopichand Nakkalab977a972013-02-18 19:15:09 -0800432 }
433 else
434 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530435 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkala8b00c632013-03-08 19:47:52 -0800436 "%s: Maximum peer connected already! %d",
437 __func__, wlan_hdd_tdlsConnectedPeers(pHddTdlsCtx->pAdapter) );
Gopichand Nakkalab977a972013-02-18 19:15:09 -0800438 }
Hoonki Leecdd8e962013-01-20 00:45:46 -0800439 goto next_peer;
Chilam NG571c65a2013-01-19 12:27:36 +0530440 }
Hoonki Leefb8df672013-04-10 18:20:34 -0700441 }
442 else if (eTDLS_LINK_CONNECTED == curr_peer->link_status) {
Chilam Ng01120412013-02-19 18:32:21 -0800443 if ((tANI_S32)curr_peer->rssi <
444 (tANI_S32)pHddTdlsCtx->threshold_config.rssi_teardown_threshold) {
Hoonki Lee5a4b2172013-01-29 01:45:53 -0800445
Chilam Ng01120412013-02-19 18:32:21 -0800446 VOS_TRACE( VOS_MODULE_ID_HDD,
447 VOS_TRACE_LEVEL_WARN,
448 "Tear down - low RSSI: " MAC_ADDRESS_STR "!",
449 MAC_ADDR_ARRAY(curr_peer->peerMac));
450#ifdef CONFIG_TDLS_IMPLICIT
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -0700451 wlan_hdd_tdls_indicate_teardown(pHddTdlsCtx->pAdapter,
452 curr_peer,
453 eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON);
Chilam Ng01120412013-02-19 18:32:21 -0800454#endif
Hoonki Leecdd8e962013-01-20 00:45:46 -0800455 goto next_peer;
Chilam NG571c65a2013-01-19 12:27:36 +0530456 }
Chilam Ng01120412013-02-19 18:32:21 -0800457
Naresh Jayaramdb4514b2013-11-25 18:08:10 +0530458 /* Only teardown based on non zero idle packet threshold, to address a use
459 * case where this threshold does not get consider for TEAR DOWN.
460 */
461
462 if (( 0 != pHddTdlsCtx->threshold_config.idle_packet_n ) &&
463 ((curr_peer->tx_pkt <
Chilam Ng01120412013-02-19 18:32:21 -0800464 pHddTdlsCtx->threshold_config.idle_packet_n) &&
465 (curr_peer->rx_pkt <
Naresh Jayaramdb4514b2013-11-25 18:08:10 +0530466 pHddTdlsCtx->threshold_config.idle_packet_n))) {
Chilam Ng01120412013-02-19 18:32:21 -0800467 if (VOS_TIMER_STATE_RUNNING !=
468 vos_timer_getCurrentState(&curr_peer->peerIdleTimer)) {
469 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
470 "Tx/Rx Idle timer start: " MAC_ADDRESS_STR "!",
471 MAC_ADDR_ARRAY(curr_peer->peerMac));
Gopichand Nakkala3046fc92013-03-23 13:56:43 -0700472 wlan_hdd_tdls_timer_restart(pHddTdlsCtx->pAdapter,
473 &curr_peer->peerIdleTimer,
474 pHddTdlsCtx->threshold_config.idle_timeout_t);
Chilam Ng01120412013-02-19 18:32:21 -0800475 }
476 } else {
Hoonki Lee5a4b2172013-01-29 01:45:53 -0800477 if (VOS_TIMER_STATE_RUNNING ==
478 vos_timer_getCurrentState(&curr_peer->peerIdleTimer)) {
Chilam Ng01120412013-02-19 18:32:21 -0800479 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
480 "Tx/Rx Idle timer stop: " MAC_ADDRESS_STR "!",
481 MAC_ADDR_ARRAY(curr_peer->peerMac));
482 vos_timer_stop( &curr_peer->peerIdleTimer);
Hoonki Lee5a4b2172013-01-29 01:45:53 -0800483 }
Hoonki Lee5a4b2172013-01-29 01:45:53 -0800484 }
Chilam Ng01120412013-02-19 18:32:21 -0800485
Hoonki Leecdd8e962013-01-20 00:45:46 -0800486// if (curr_peer->rssi <
487// (pHddTdlsCtx->threshold_config.rssi_hysteresis +
488// pHddTdlsCtx->ap_rssi)) {
489//
490//#ifdef CONFIG_TDLS_IMPLICIT
491// cfg80211_tdls_oper_request(pHddTdlsCtx->dev,
492// curr_peer->peerMac,
493// NL80211_TDLS_TEARDOWN, FALSE,
494// GFP_KERNEL);
495//#endif
496// }
Chilam NG571c65a2013-01-19 12:27:36 +0530497 }
Chilam Ng01120412013-02-19 18:32:21 -0800498 } else if (eTDLS_CAP_UNKNOWN == curr_peer->tdls_support) {
Sunil Dutt961ecbd2013-11-28 20:04:07 +0530499
500 if (pHddCtx->cfg_ini->fTDLSExternalControl &&
501 (FALSE == curr_peer->isForcedPeer)) {
502 continue;
503 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -0700504 if (!TDLS_IS_CONNECTED(curr_peer)) {
Chilam Ng01120412013-02-19 18:32:21 -0800505 if (curr_peer->tx_pkt >=
506 pHddTdlsCtx->threshold_config.tx_packet_n) {
Chilam Ng01120412013-02-19 18:32:21 -0800507
Sunil Duttb0d39242014-09-10 23:54:51 +0530508 /* Ignore discovery attempt if External Control is enabled, that
509 * is, peer is forced. In that case, continue discovery attempt
510 * regardless attempt count
511 */
512 if (curr_peer->isForcedPeer || curr_peer->discovery_attempt++ <
Chilam Ng01120412013-02-19 18:32:21 -0800513 pHddTdlsCtx->threshold_config.discovery_tries_n) {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530514 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
515 "TDLS UNKNOWN discover ");
Hoonki Leed37cbb32013-04-20 00:31:14 -0700516#ifdef CONFIG_TDLS_IMPLICIT
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +0530517 pHddTdlsCtx->curr_candidate = curr_peer;
518 wlan_hdd_tdls_implicit_send_discovery_request(pHddTdlsCtx);
Hoonki Leed37cbb32013-04-20 00:31:14 -0700519#endif
Chilam Ng01120412013-02-19 18:32:21 -0800520 }
Gopichand Nakkala901e8922013-03-04 23:45:58 -0800521 else
Gopichand Nakkala8b00c632013-03-08 19:47:52 -0800522 {
Gopichand Nakkala901e8922013-03-04 23:45:58 -0800523 curr_peer->tdls_support = eTDLS_CAP_NOT_SUPPORTED;
Atul Mittal115287b2014-07-08 13:26:33 +0530524 wlan_hdd_tdls_set_peer_link_status(
525 curr_peer,
526 eTDLS_LINK_IDLE,
527 eTDLS_LINK_NOT_SUPPORTED);
528
Gopichand Nakkala8b00c632013-03-08 19:47:52 -0800529 }
Chilam Ng01120412013-02-19 18:32:21 -0800530 }
531 }
Chilam NG571c65a2013-01-19 12:27:36 +0530532 }
533
Hoonki Leecdd8e962013-01-20 00:45:46 -0800534next_peer:
Chilam NG571c65a2013-01-19 12:27:36 +0530535 curr_peer->tx_pkt = 0;
Chilam Ng1279e232013-01-25 15:06:52 -0800536 curr_peer->rx_pkt = 0;
Hoonki Lee387663d2013-02-05 18:08:43 -0800537 }
Chilam NG571c65a2013-01-19 12:27:36 +0530538 }
539
Gopichand Nakkala3046fc92013-03-23 13:56:43 -0700540 wlan_hdd_tdls_timer_restart(pHddTdlsCtx->pAdapter,
541 &pHddTdlsCtx->peerUpdateTimer,
542 pHddTdlsCtx->threshold_config.tx_period_t);
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530543 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530544 EXIT();
Chilam NG571c65a2013-01-19 12:27:36 +0530545}
546
Chilam Ng1279e232013-01-25 15:06:52 -0800547static v_VOID_t wlan_hdd_tdls_idle_cb( v_PVOID_t userData )
548{
Lee Hoonkic1262f22013-01-24 21:59:00 -0800549#ifdef CONFIG_TDLS_IMPLICIT
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530550 hddTdlsPeer_t *curr_peer;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530551 tdlsCtx_t *pHddTdlsCtx;
552 hdd_context_t *pHddCtx;
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530553 v_CONTEXT_t pVosContext;
Chilam Ng1279e232013-01-25 15:06:52 -0800554
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530555 ENTER();
556
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530557 pVosContext = vos_get_global_context(VOS_MODULE_ID_HDD, NULL);
558 if (NULL == pVosContext)
559 {
560 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
561 FL("pVosContext points to NULL"));
562 return;
563 }
564 pHddCtx = vos_get_context(VOS_MODULE_ID_HDD, pVosContext);
565 if (0 != (wlan_hdd_validate_context(pHddCtx)))
566 {
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530567 return;
568 }
569
570 mutex_lock(&pHddCtx->tdls_lock);
571
572 curr_peer = (hddTdlsPeer_t *)userData;
Rajesh Chauhan1ace6002013-04-18 18:08:21 -0700573 if (NULL == curr_peer)
574 {
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530575 mutex_unlock(&pHddCtx->tdls_lock);
Rajesh Chauhan1ace6002013-04-18 18:08:21 -0700576 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
c_hpothu7f63e882013-10-02 19:13:35 +0530577 FL("Invalid tdls idle timer expired"));
Rajesh Chauhan1ace6002013-04-18 18:08:21 -0700578 return;
579 }
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530580
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530581 pHddTdlsCtx = curr_peer->pHddTdlsCtx;
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530582 if (0 != (wlan_hdd_validate_tdls_context(pHddCtx, pHddTdlsCtx)))
c_hpothu7f63e882013-10-02 19:13:35 +0530583 {
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530584 mutex_unlock(&pHddCtx->tdls_lock);
c_hpothu7f63e882013-10-02 19:13:35 +0530585 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530586 FL("Invalid pHddTdlsCtx context"));
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530587 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530588 }
Rajesh Chauhan1ace6002013-04-18 18:08:21 -0700589
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530590 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -0800591 "%s: Tx/Rx Idle " MAC_ADDRESS_STR " tx_pkt: %d, rx_pkt: %d, idle_packet_n: %d",
Rajesh Chauhan1ace6002013-04-18 18:08:21 -0700592 __func__, MAC_ADDR_ARRAY(curr_peer->peerMac),
593 curr_peer->tx_pkt,
594 curr_peer->rx_pkt,
595 curr_peer->pHddTdlsCtx->threshold_config.idle_packet_n);
596
Rajesh Chauhan1ace6002013-04-18 18:08:21 -0700597 /* Check tx/rx statistics on this tdls link for recent activities and
598 * then decide whether to tear down the link or keep it.
599 */
600 if ((curr_peer->tx_pkt >= curr_peer->pHddTdlsCtx->threshold_config.idle_packet_n) || (curr_peer->rx_pkt >= curr_peer->pHddTdlsCtx->threshold_config.idle_packet_n))
601 {
602 /* this tdls link got back to normal, so keep it */
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530603 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Rajesh Chauhan1ace6002013-04-18 18:08:21 -0700604 "%s: tdls link to " MAC_ADDRESS_STR " back to normal, will stay",
605 __func__, MAC_ADDR_ARRAY(curr_peer->peerMac));
606 }
607 else
608 {
609 /* this tdls link needs to get torn down */
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530610 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Rajesh Chauhan1ace6002013-04-18 18:08:21 -0700611 "%s: trigger tdls link to " MAC_ADDRESS_STR " down",
612 __func__, MAC_ADDR_ARRAY(curr_peer->peerMac));
613
614 wlan_hdd_tdls_indicate_teardown(curr_peer->pHddTdlsCtx->pAdapter,
615 curr_peer,
616 eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON);
617 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530618 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530619 EXIT();
Chilam Ng1279e232013-01-25 15:06:52 -0800620#endif
621}
622
Gopichand Nakkala75e7b282013-03-15 18:37:13 -0700623static v_VOID_t wlan_hdd_tdls_discovery_timeout_peer_cb(v_PVOID_t userData)
624{
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -0700625 int i;
626 struct list_head *head;
627 hddTdlsPeer_t *tmp;
628 struct list_head *pos, *q;
Gopichand Nakkala75e7b282013-03-15 18:37:13 -0700629 tdlsCtx_t *pHddTdlsCtx;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530630 hdd_context_t *pHddCtx;
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530631 v_CONTEXT_t pVosContext;
Gopichand Nakkala75e7b282013-03-15 18:37:13 -0700632
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530633 ENTER();
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530634 pVosContext = vos_get_global_context(VOS_MODULE_ID_HDD, NULL);
635 if (NULL == pVosContext)
c_hpothu7f63e882013-10-02 19:13:35 +0530636 {
637 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530638 FL("pVosContext points to NULL"));
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530639 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530640 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530641
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530642 pHddCtx = vos_get_context(VOS_MODULE_ID_HDD, pVosContext);
643 if (0 != (wlan_hdd_validate_context(pHddCtx)))
Sushant Kaushik15c4c522014-08-14 12:24:49 +0530644 {
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530645 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530646 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530647
Rajesh Chauhana34c6e62014-03-25 16:37:58 +0530648 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -0700649
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530650 pHddTdlsCtx = (tdlsCtx_t *)userData;
651 if (0 != (wlan_hdd_validate_tdls_context(pHddCtx, pHddTdlsCtx)))
652 {
653 mutex_unlock(&pHddCtx->tdls_lock);
654 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
655 FL("Invalid pHddTdlsCtx context"));
656 return;
657 }
658
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -0700659 for (i = 0; i < 256; i++) {
660 head = &pHddTdlsCtx->peer_list[i];
661 list_for_each_safe (pos, q, head) {
662 tmp = list_entry(pos, hddTdlsPeer_t, node);
663 if (eTDLS_LINK_DISCOVERING == tmp->link_status)
664 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530665 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -0700666 "%s: " MAC_ADDRESS_STR " to idle state", __func__,
667 MAC_ADDR_ARRAY(tmp->peerMac));
Atul Mittal115287b2014-07-08 13:26:33 +0530668 wlan_hdd_tdls_set_peer_link_status(
669 tmp,
670 eTDLS_LINK_IDLE,
Atul Mittalad630e42014-10-07 19:19:14 +0530671 eTDLS_LINK_NOT_SUPPORTED);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -0700672 }
673 }
674 }
Gopichand Nakkala75e7b282013-03-15 18:37:13 -0700675
676 pHddTdlsCtx->discovery_sent_cnt = 0;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -0700677 wlan_hdd_tdls_check_power_save_prohibited(pHddTdlsCtx->pAdapter);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -0700678
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530679 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -0700680
Gopichand Nakkala75e7b282013-03-15 18:37:13 -0700681 wlan_hdd_tdls_check_bmps(pHddTdlsCtx->pAdapter);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530682 EXIT();
Gopichand Nakkala75e7b282013-03-15 18:37:13 -0700683 return;
684}
685
Hoonki Lee14621352013-04-16 17:51:19 -0700686static v_VOID_t wlan_hdd_tdls_initiator_wait_cb( v_PVOID_t userData )
687{
688 hddTdlsPeer_t *curr_peer = (hddTdlsPeer_t *)userData;
689 tdlsCtx_t *pHddTdlsCtx;
690
Mahesh A Saptasagar4534e2b2015-03-05 20:45:41 +0530691 ENTER();
Hoonki Lee14621352013-04-16 17:51:19 -0700692 if ( NULL == curr_peer )
c_hpothu7f63e882013-10-02 19:13:35 +0530693 {
694 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
695 FL("curr_peer is NULL"));
Hoonki Lee14621352013-04-16 17:51:19 -0700696 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530697 }
Hoonki Lee14621352013-04-16 17:51:19 -0700698
699 pHddTdlsCtx = curr_peer->pHddTdlsCtx;
700
701 if ( NULL == pHddTdlsCtx )
c_hpothu7f63e882013-10-02 19:13:35 +0530702 {
703 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
704 FL("pHddTdlsCtx is NULL"));
Hoonki Lee14621352013-04-16 17:51:19 -0700705 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530706 }
Mahesh A Saptasagar4534e2b2015-03-05 20:45:41 +0530707 if (0 != (wlan_hdd_validate_context(
708 WLAN_HDD_GET_CTX(pHddTdlsCtx->pAdapter))))
709 {
710 return;
711 }
Hoonki Lee14621352013-04-16 17:51:19 -0700712 WLANTL_ResumeDataTx( (WLAN_HDD_GET_CTX(pHddTdlsCtx->pAdapter))->pvosContext,
713 (v_U8_t *)&curr_peer->staId);
Mahesh A Saptasagar4534e2b2015-03-05 20:45:41 +0530714 EXIT();
Hoonki Lee14621352013-04-16 17:51:19 -0700715}
716
Gopichand Nakkala4327a152013-03-04 23:22:42 -0800717static void wlan_hdd_tdls_free_list(tdlsCtx_t *pHddTdlsCtx)
Gopichand Nakkala91b09262013-02-10 14:27:02 -0800718{
719 int i;
720 struct list_head *head;
721 hddTdlsPeer_t *tmp;
722 struct list_head *pos, *q;
723
c_hpothu7f63e882013-10-02 19:13:35 +0530724 if (NULL == pHddTdlsCtx)
725 {
726 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
727 FL("pHddTdlsCtx is NULL"));
728 return;
729 }
Gopichand Nakkala91b09262013-02-10 14:27:02 -0800730
731 for (i = 0; i < 256; i++) {
732 head = &pHddTdlsCtx->peer_list[i];
733 list_for_each_safe (pos, q, head) {
734 tmp = list_entry(pos, hddTdlsPeer_t, node);
735 list_del(pos);
736 vos_mem_free(tmp);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -0800737 tmp = NULL;
Gopichand Nakkala91b09262013-02-10 14:27:02 -0800738 }
739 }
Gopichand Nakkala91b09262013-02-10 14:27:02 -0800740}
741
Sameer Thalappilbee426e2013-10-30 10:30:30 -0700742static void wlan_hdd_tdls_schedule_scan(struct work_struct *work)
743{
744 tdls_scan_context_t *scan_ctx =
745 container_of(work, tdls_scan_context_t, tdls_scan_work.work);
746
747 if (NULL == scan_ctx)
c_hpothu7f63e882013-10-02 19:13:35 +0530748 {
749 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
750 FL("scan_ctx is NULL"));
Sameer Thalappilbee426e2013-10-30 10:30:30 -0700751 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530752 }
Sameer Thalappilbee426e2013-10-30 10:30:30 -0700753
754 if (unlikely(TDLS_CTX_MAGIC != scan_ctx->magic))
755 return;
756
757 scan_ctx->attempt++;
758
759 wlan_hdd_cfg80211_scan(scan_ctx->wiphy,
760#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
761 scan_ctx->dev,
762#endif
763 scan_ctx->scan_request);
764}
765
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530766void wlan_hdd_tdls_btCoex_cb(void *data, int indType)
767{
768 hdd_adapter_t *pAdapter;
769 hdd_context_t *pHddCtx;
770 u16 connectedTdlsPeers;
771 tdlsCtx_t *pHddTdlsCtx;
772 hddTdlsPeer_t *currPeer;
773 hdd_scaninfo_t *pScanInfo;
774
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530775 ENTER();
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530776 if ((NULL == data) || (indType < 0))
777 {
778 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
779 FL("Invalid arguments"));
780 return;
781 }
782
783 pHddCtx = (hdd_context_t *)data;
784 if (0 != (wlan_hdd_validate_context(pHddCtx)))
785 {
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530786 return;
787 }
788
789 /* if tdls is not enabled, then continue btCoex */
790 if (eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode)
791 {
792 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
793 FL("tdls is not enabled"));
794 return;
795 }
796
797 /* get pAdapter context, do we need WLAN_HDD_P2P_CLIENT */
798 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
799 if (NULL == pAdapter)
800 {
801 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
802 FL("pAdapter is not valid"));
803 return;
804 }
805
806 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
807 if (NULL == pHddTdlsCtx)
808 {
809 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
810 FL("pHddTdlsCtx is not valid"));
811 return;
812 }
813
814 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
815 "%s: BtCoex notification type %d", __func__, indType);
816 /* BtCoex notification type enabled, Disable TDLS */
817 if (indType == SIR_COEX_IND_TYPE_TDLS_DISABLE)
818 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530819 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530820 FL("BtCoex notification, Disable TDLS"));
821
822 pScanInfo = &pHddCtx->scan_info;
823 // Lets do abort scan if scan is pending
824 if ((pScanInfo != NULL) && pScanInfo->mScanPending)
825 {
826 hdd_abort_mac_scan(pHddCtx, pScanInfo->sessionId,
827 eCSR_SCAN_ABORT_DEFAULT);
828 }
829
830 /* tdls is in progress */
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +0530831 currPeer = wlan_hdd_tdls_is_progress(pHddCtx, NULL, 0, TRUE);
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530832 if (NULL != currPeer)
833 {
834 wlan_hdd_tdls_set_peer_link_status (currPeer,
835 eTDLS_LINK_IDLE,
836 eTDLS_LINK_UNSPECIFIED);
837 }
838
839 /* while tdls is up */
840 if (eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode ||
841 eTDLS_SUPPORT_EXPLICIT_TRIGGER_ONLY == pHddCtx->tdls_mode)
842 {
843 connectedTdlsPeers = wlan_hdd_tdlsConnectedPeers(pAdapter);
844 /* disable implicit trigger logic & tdls operatoin */
845 wlan_hdd_tdls_set_mode(pHddCtx, eTDLS_SUPPORT_DISABLED, FALSE);
846 pHddCtx->is_tdls_btc_enabled = FALSE;
847
848 /* teardown the peers on the btcoex */
849 if (connectedTdlsPeers)
850 {
851 tANI_U8 staIdx;
852 hddTdlsPeer_t *curr_peer;
853
854 for (staIdx = 0; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
855 {
856 if (pHddCtx->tdlsConnInfo[staIdx].staId)
857 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530858 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
859 ("%s: indicate TDLS teardown (staId %d)"),
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530860 __func__,pHddCtx->tdlsConnInfo[staIdx].staId);
861
862 #ifdef CONFIG_TDLS_IMPLICIT
863 curr_peer = wlan_hdd_tdls_find_all_peer(pHddCtx,
864 pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes);
865 if(curr_peer) {
866 wlan_hdd_tdls_indicate_teardown(
867 curr_peer->pHddTdlsCtx->pAdapter, curr_peer,
868 eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON);
869 }
870 #endif
871 }
872 }
873 }
874 }
875 }
876 /* BtCoex notification type enabled, Enable TDLS */
877 else if (indType == SIR_COEX_IND_TYPE_TDLS_ENABLE)
878 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530879 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530880 FL("BtCoex notification, Enable TDLS"));
881 /* if tdls was enabled before btCoex, re-enable tdls mode */
882 if (eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode_last ||
883 eTDLS_SUPPORT_EXPLICIT_TRIGGER_ONLY == pHddCtx->tdls_mode_last)
884 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530885 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530886 ("%s: revert tdls mode %d"), __func__,
887 pHddCtx->tdls_mode_last);
888 pHddCtx->is_tdls_btc_enabled = TRUE;
889 wlan_hdd_tdls_set_mode(pHddCtx, pHddCtx->tdls_mode_last, FALSE);
890 }
891 }
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530892 EXIT();
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530893 return;
894}
895
Agarwal Ashish4b87f922014-06-18 03:03:21 +0530896/* initialize TDLS global context */
897void wlan_hdd_tdls_init(hdd_context_t *pHddCtx )
898{
899 v_U8_t staIdx;
Chandrasekaran, Manishekar0de84dc2015-03-10 15:12:34 +0530900 eHalStatus status;
Sameer Thalappilbee426e2013-10-30 10:30:30 -0700901
Agarwal Ashish4b87f922014-06-18 03:03:21 +0530902 pHddCtx->connected_peer_count = 0;
903
904 pHddCtx->tdls_scan_ctxt.magic = 0;
905 pHddCtx->tdls_scan_ctxt.attempt = 0;
906 pHddCtx->tdls_scan_ctxt.reject = 0;
907 pHddCtx->tdls_scan_ctxt.scan_request = NULL;
908
909 for (staIdx = 0; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
910 {
911 pHddCtx->tdlsConnInfo[staIdx].staId = 0;
912 pHddCtx->tdlsConnInfo[staIdx].sessionId = 255;
913 vos_mem_zero(&pHddCtx->tdlsConnInfo[staIdx].peerMac,
914 sizeof(v_MACADDR_t)) ;
915 }
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530916 pHddCtx->is_tdls_btc_enabled = TRUE;
Chandrasekaran, Manishekar0de84dc2015-03-10 15:12:34 +0530917 status = sme_RegisterBtCoexTDLSCallback(pHddCtx->hHal,
918 wlan_hdd_tdls_btCoex_cb);
919 if (status != eHAL_STATUS_SUCCESS) {
920 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to register BT Coex TDLS callback"));
921 }
Agarwal Ashish4b87f922014-06-18 03:03:21 +0530922
923 if (FALSE == pHddCtx->cfg_ini->fEnableTDLSImplicitTrigger)
924 {
925 pHddCtx->tdls_mode = eTDLS_SUPPORT_EXPLICIT_TRIGGER_ONLY;
926 hddLog(VOS_TRACE_LEVEL_ERROR, "%s TDLS Implicit trigger not enabled!", __func__);
927 }
928 else
929 {
930 pHddCtx->tdls_mode = eTDLS_SUPPORT_ENABLED;
931 }
932}
933
934int wlan_hdd_sta_tdls_init(hdd_adapter_t *pAdapter)
Chilam Ng01120412013-02-19 18:32:21 -0800935{
Chilam Ng01120412013-02-19 18:32:21 -0800936 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
Hoonki Lee27511902013-03-14 18:19:06 -0700937 tdlsCtx_t *pHddTdlsCtx;
Chilam Ng01120412013-02-19 18:32:21 -0800938 int i;
Sunil Dutt66485cb2013-12-19 19:05:03 +0530939 if (NULL == pHddCtx)
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +0530940 {
941 hddLog(VOS_TRACE_LEVEL_ERROR, "%s pHddCtx is NULL", __func__);
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530942 return -EINVAL;
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +0530943 }
Sunil Dutt66485cb2013-12-19 19:05:03 +0530944
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +0530945 if (test_bit(TDLS_INIT_DONE, &pAdapter->event_flags))
946 {
947 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530948 "%s: TDLS INIT DONE set to 1, no point in re-init", __func__);
949 return -EALREADY;
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +0530950 }
Sunil Dutt66485cb2013-12-19 19:05:03 +0530951
Hoonki Lee27511902013-03-14 18:19:06 -0700952 if ((FALSE == pHddCtx->cfg_ini->fEnableTDLSSupport) ||
953 (FALSE == sme_IsFeatureSupportedByFW(TDLS)))
954 {
955 pHddCtx->tdls_mode = eTDLS_SUPPORT_NOT_ENABLED;
956 pAdapter->sessionCtx.station.pHddTdlsCtx = NULL;
957 hddLog(VOS_TRACE_LEVEL_ERROR, "%s TDLS not enabled (%d) or FW doesn't support (%d)!",
958 __func__, pHddCtx->cfg_ini->fEnableTDLSSupport,
959 sme_IsFeatureSupportedByFW(TDLS));
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530960 return -EINVAL;
Gopichand Nakkala4327a152013-03-04 23:22:42 -0800961 }
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +0530962 /* TDLS is supported only in STA / P2P Client modes,
963 * hence the check for TDLS support in a specific Device mode.
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +0530964 */
965 if (0 == WLAN_HDD_IS_TDLS_SUPPORTED_ADAPTER(pAdapter))
966 {
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +0530967 hddLog(VOS_TRACE_LEVEL_ERROR, "%s TDLS is not supported in mode : %d", __func__, pAdapter->device_mode);
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530968 return -EINVAL;
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +0530969 }
970 /* Check for the valid pHddTdlsCtx. If valid do not further
971 * allocate the memory, rather continue with the initialization.
972 * If tdls_initialization would get reinvoked without tdls_exit
973 * getting invoked (SSR) there is no point to further proceed
974 * with the memory allocations.
975 */
976 if (NULL == pAdapter->sessionCtx.station.pHddTdlsCtx)
977 {
978 pHddTdlsCtx = vos_mem_malloc(sizeof(tdlsCtx_t));
Gopichand Nakkala4327a152013-03-04 23:22:42 -0800979
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +0530980 if (NULL == pHddTdlsCtx) {
981 hddLog(VOS_TRACE_LEVEL_ERROR, "%s malloc failed!", __func__);
982 pAdapter->sessionCtx.station.pHddTdlsCtx = NULL;
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530983 return -ENOMEM;
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +0530984 }
985 /* initialize TDLS pAdater context */
986 vos_mem_zero(pHddTdlsCtx, sizeof(tdlsCtx_t));
987#ifdef TDLS_USE_SEPARATE_DISCOVERY_TIMER
988 vos_timer_init(&pHddTdlsCtx->peerDiscoverTimer,
989 VOS_TIMER_TYPE_SW,
990 wlan_hdd_tdls_discover_peer_cb,
991 pHddTdlsCtx);
992#endif
Hoonki Lee27511902013-03-14 18:19:06 -0700993
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +0530994 vos_timer_init(&pHddTdlsCtx->peerUpdateTimer,
995 VOS_TIMER_TYPE_SW,
996 wlan_hdd_tdls_update_peer_cb,
997 pHddTdlsCtx);
998 vos_timer_init(&pHddTdlsCtx->peerDiscoveryTimeoutTimer,
999 VOS_TIMER_TYPE_SW,
1000 wlan_hdd_tdls_discovery_timeout_peer_cb,
1001 pHddTdlsCtx);
1002
1003 pAdapter->sessionCtx.station.pHddTdlsCtx = pHddTdlsCtx;
Hoonki Lee27511902013-03-14 18:19:06 -07001004 }
1005
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +05301006 pHddTdlsCtx = pAdapter->sessionCtx.station.pHddTdlsCtx;
Hoonki Lee27511902013-03-14 18:19:06 -07001007
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07001008 sme_SetTdlsPowerSaveProhibited(WLAN_HDD_GET_HAL_CTX(pAdapter), 0);
Hoonki Lee27511902013-03-14 18:19:06 -07001009
Hoonki Lee27511902013-03-14 18:19:06 -07001010 pHddTdlsCtx->pAdapter = pAdapter;
1011
1012 for (i = 0; i < 256; i++)
1013 {
1014 INIT_LIST_HEAD(&pHddTdlsCtx->peer_list[i]);
1015 }
1016
Hoonki Leed37cbb32013-04-20 00:31:14 -07001017 pHddTdlsCtx->curr_candidate = NULL;
1018 pHddTdlsCtx->magic = 0;
1019
Hoonki Lee27511902013-03-14 18:19:06 -07001020 /* remember configuration even if it is not used right now. it could be used later */
1021 pHddTdlsCtx->threshold_config.tx_period_t = pHddCtx->cfg_ini->fTDLSTxStatsPeriod;
1022 pHddTdlsCtx->threshold_config.tx_packet_n = pHddCtx->cfg_ini->fTDLSTxPacketThreshold;
1023 pHddTdlsCtx->threshold_config.discovery_period_t = pHddCtx->cfg_ini->fTDLSDiscoveryPeriod;
1024 pHddTdlsCtx->threshold_config.discovery_tries_n = pHddCtx->cfg_ini->fTDLSMaxDiscoveryAttempt;
1025 pHddTdlsCtx->threshold_config.idle_timeout_t = pHddCtx->cfg_ini->fTDLSIdleTimeout;
1026 pHddTdlsCtx->threshold_config.idle_packet_n = pHddCtx->cfg_ini->fTDLSIdlePacketThreshold;
1027 pHddTdlsCtx->threshold_config.rssi_hysteresis = pHddCtx->cfg_ini->fTDLSRSSIHysteresis;
1028 pHddTdlsCtx->threshold_config.rssi_trigger_threshold = pHddCtx->cfg_ini->fTDLSRSSITriggerThreshold;
1029 pHddTdlsCtx->threshold_config.rssi_teardown_threshold = pHddCtx->cfg_ini->fTDLSRSSITeardownThreshold;
Chilam NG571c65a2013-01-19 12:27:36 +05301030
Anand N Sunkaddc63c792015-06-03 14:33:24 +05301031 vos_init_delayed_work(&pHddCtx->tdls_scan_ctxt.tdls_scan_work,
1032 wlan_hdd_tdls_schedule_scan);
1033 set_bit(TDLS_INIT_DONE, &pAdapter->event_flags);
Hoonki Lee27511902013-03-14 18:19:06 -07001034
1035 return 0;
Chilam NG571c65a2013-01-19 12:27:36 +05301036}
1037
Pradeep Reddy POTTETI2d4d5c42015-03-03 14:34:19 +05301038void wlan_hdd_tdls_exit(hdd_adapter_t *pAdapter, tANI_BOOLEAN mutexLock)
Chilam NG571c65a2013-01-19 12:27:36 +05301039{
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001040 tdlsCtx_t *pHddTdlsCtx;
Hoonki Lee93e67ff2013-03-19 15:49:25 -07001041 hdd_context_t *pHddCtx;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001042
Chandrasekaran, Manishekar41b8e1f2015-03-10 13:30:28 +05301043 if (!pAdapter) {
1044 hddLog(VOS_TRACE_LEVEL_ERROR, FL("HDD adpater is NULL"));
1045 return;
1046 }
1047
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301048 /*
1049 * NOTE: The Callers of this function should ensure to acquire the
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +05301050 * tdls_lock to avoid any concurrent access to the Adapter and logp
1051 * protection has to be ensured.
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301052 */
1053
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05301054 pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
Agarwal Ashish9ffa5b92014-11-18 21:07:02 +05301055
1056 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05301057 {
Agarwal Ashish9ffa5b92014-11-18 21:07:02 +05301058 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1059 "%s: HDD context is Null", __func__);
1060 return ;
1061 }
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +05301062 if (!test_bit(TDLS_INIT_DONE, &pAdapter->event_flags))
Agarwal Ashish9ffa5b92014-11-18 21:07:02 +05301063 {
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +05301064 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1065 "%s: TDLS INIT DONE set to 0, no point in exit", __func__);
1066 return;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05301067 }
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +05301068 clear_bit(TDLS_INIT_DONE, &pAdapter->event_flags);
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05301069
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001070 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001071 if (NULL == pHddTdlsCtx)
1072 {
c_hpothu7f63e882013-10-02 19:13:35 +05301073 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1074 FL("pHddTdlsCtx is NULL"));
Hoonki Leebfee0342013-01-21 16:43:45 -08001075 return;
1076 }
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +05301077
Anand N Sunkad860e5ea2015-03-30 14:41:51 +05301078 vos_flush_delayed_work(&pHddCtx->tdls_scan_ctxt.tdls_scan_work);
Hoonki Leebfee0342013-01-21 16:43:45 -08001079
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001080 /* must stop timer here before freeing peer list, because peerIdleTimer is
1081 part of peer list structure. */
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001082 wlan_hdd_tdls_timers_destroy(pHddTdlsCtx);
1083 wlan_hdd_tdls_free_list(pHddTdlsCtx);
Chilam Nga75d8b62013-01-29 01:35:59 -08001084
Hoonki Lee93e67ff2013-03-19 15:49:25 -07001085 wlan_hdd_tdls_free_scan_request(&pHddCtx->tdls_scan_ctxt);
Sushant Kaushik15c4c522014-08-14 12:24:49 +05301086 pHddTdlsCtx->magic = 0;
1087 pHddTdlsCtx->pAdapter = NULL;
Chilam Nga75d8b62013-01-29 01:35:59 -08001088 vos_mem_free(pHddTdlsCtx);
Pradeep Reddy POTTETI59c90d62014-03-24 19:45:47 +05301089 pAdapter->sessionCtx.station.pHddTdlsCtx = NULL;
Chilam Nga75d8b62013-01-29 01:35:59 -08001090 pHddTdlsCtx = NULL;
Chilam NG571c65a2013-01-19 12:27:36 +05301091}
1092
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +05301093/* stop all monitoring timers per Adapter */
1094static void wlan_hdd_tdls_monitor_timers_stop(tdlsCtx_t *pHddTdlsCtx)
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001095{
Hoonki Leed37cbb32013-04-20 00:31:14 -07001096#ifdef TDLS_USE_SEPARATE_DISCOVERY_TIMER
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001097 vos_timer_stop(&pHddTdlsCtx->peerDiscoverTimer);
Hoonki Leed37cbb32013-04-20 00:31:14 -07001098#endif
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001099 vos_timer_stop(&pHddTdlsCtx->peerUpdateTimer);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001100 vos_timer_stop(&pHddTdlsCtx->peerDiscoveryTimeoutTimer);
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +05301101}
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001102
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +05301103/* stop all per peer timers */
1104static void wlan_hdd_tdls_peer_timers_stop(tdlsCtx_t *pHddTdlsCtx)
1105{
1106 int i;
1107 struct list_head *head;
1108 struct list_head *pos;
1109 hddTdlsPeer_t *curr_peer;
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001110 for (i = 0; i < 256; i++)
1111 {
1112 head = &pHddTdlsCtx->peer_list[i];
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001113 list_for_each (pos, head) {
1114 curr_peer = list_entry (pos, hddTdlsPeer_t, node);
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05301115 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Chilam Ng01120412013-02-19 18:32:21 -08001116 "%s: " MAC_ADDRESS_STR " -> stop idle timer",
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001117 __func__,
Chilam Ng01120412013-02-19 18:32:21 -08001118 MAC_ADDR_ARRAY(curr_peer->peerMac));
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001119 vos_timer_stop ( &curr_peer->peerIdleTimer );
Hoonki Lee14621352013-04-16 17:51:19 -07001120 vos_timer_stop( &curr_peer->initiatorWaitTimeoutTimer );
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001121 }
1122 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001123}
1124
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +05301125/* stop all the tdls timers running */
1126static void wlan_hdd_tdls_timers_stop(tdlsCtx_t *pHddTdlsCtx)
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001127{
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +05301128 wlan_hdd_tdls_monitor_timers_stop(pHddTdlsCtx);
1129 wlan_hdd_tdls_peer_timers_stop(pHddTdlsCtx);
1130}
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001131
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +05301132static void wlan_hdd_tdls_monitor_timers_destroy(tdlsCtx_t *pHddTdlsCtx)
1133{
Hoonki Leed37cbb32013-04-20 00:31:14 -07001134#ifdef TDLS_USE_SEPARATE_DISCOVERY_TIMER
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001135 vos_timer_stop(&pHddTdlsCtx->peerDiscoverTimer);
1136 vos_timer_destroy(&pHddTdlsCtx->peerDiscoverTimer);
Hoonki Leed37cbb32013-04-20 00:31:14 -07001137#endif
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001138 vos_timer_stop(&pHddTdlsCtx->peerUpdateTimer);
1139 vos_timer_destroy(&pHddTdlsCtx->peerUpdateTimer);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001140 vos_timer_stop(&pHddTdlsCtx->peerDiscoveryTimeoutTimer);
1141 vos_timer_destroy(&pHddTdlsCtx->peerDiscoveryTimeoutTimer);
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +05301142}
1143/*Free all the timers related to the TDLS peer */
1144static void wlan_hdd_tdls_peer_timers_destroy(tdlsCtx_t *pHddTdlsCtx)
1145{
1146 int i;
1147 struct list_head *head;
1148 struct list_head *pos;
1149 hddTdlsPeer_t *curr_peer;
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001150 for (i = 0; i < 256; i++)
1151 {
1152 head = &pHddTdlsCtx->peer_list[i];
1153
1154 list_for_each (pos, head) {
1155 curr_peer = list_entry (pos, hddTdlsPeer_t, node);
1156
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05301157 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Chilam Ng01120412013-02-19 18:32:21 -08001158 "%s: " MAC_ADDRESS_STR " -> destroy idle timer",
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001159 __func__,
Chilam Ng01120412013-02-19 18:32:21 -08001160 MAC_ADDR_ARRAY(curr_peer->peerMac));
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001161 vos_timer_stop ( &curr_peer->peerIdleTimer );
1162 vos_timer_destroy ( &curr_peer->peerIdleTimer );
Hoonki Lee14621352013-04-16 17:51:19 -07001163 vos_timer_stop(&curr_peer->initiatorWaitTimeoutTimer);
1164 vos_timer_destroy(&curr_peer->initiatorWaitTimeoutTimer);
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001165 }
1166 }
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +05301167
1168}
1169
1170/* destroy all the tdls timers running */
1171static void wlan_hdd_tdls_timers_destroy(tdlsCtx_t *pHddTdlsCtx)
1172{
1173 wlan_hdd_tdls_monitor_timers_destroy(pHddTdlsCtx);
1174 wlan_hdd_tdls_peer_timers_destroy(pHddTdlsCtx);
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001175}
1176
Hoonki Lee387663d2013-02-05 18:08:43 -08001177/* if mac address exist, return pointer
1178 if mac address doesn't exist, create a list and add, return pointer
1179 return NULL if fails to get new mac address
1180*/
Anand N Sunkadb3ab97d2015-07-29 09:58:13 +05301181hddTdlsPeer_t *wlan_hdd_tdls_get_peer(hdd_adapter_t *pAdapter,
1182#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
1183 const u8 *mac
1184#else
1185 u8 *mac
1186#endif
1187 )
Chilam NG571c65a2013-01-19 12:27:36 +05301188{
Hoonki Lee387663d2013-02-05 18:08:43 -08001189 struct list_head *head;
1190 hddTdlsPeer_t *peer;
1191 u8 key;
Gopichand Nakkala4ddf0192013-03-27 13:41:20 -07001192 tdlsCtx_t *pHddTdlsCtx;
Chandrasekaran, Manishekar41b8e1f2015-03-10 13:30:28 +05301193 hdd_context_t *pHddCtx;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05301194
Chandrasekaran, Manishekar41b8e1f2015-03-10 13:30:28 +05301195
1196 if (!pAdapter) {
1197 hddLog(VOS_TRACE_LEVEL_ERROR, FL("HDD adpater is NULL"));
1198 return NULL;
1199 }
1200
1201 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
1202 if (0 != (wlan_hdd_validate_context(pHddCtx)))
c_hpothu7f63e882013-10-02 19:13:35 +05301203 {
c_hpothu7f63e882013-10-02 19:13:35 +05301204 return 0;
1205 }
Hoonki Leebfee0342013-01-21 16:43:45 -08001206
Hoonki Lee387663d2013-02-05 18:08:43 -08001207 /* if already there, just update */
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301208 peer = wlan_hdd_tdls_find_peer(pAdapter, mac, FALSE);
Hoonki Lee387663d2013-02-05 18:08:43 -08001209 if (peer != NULL)
1210 {
1211 return peer;
Chilam NG571c65a2013-01-19 12:27:36 +05301212 }
1213
Hoonki Lee387663d2013-02-05 18:08:43 -08001214 /* not found, allocate and add the list */
1215 peer = vos_mem_malloc(sizeof(hddTdlsPeer_t));
1216 if (NULL == peer) {
1217 hddLog(VOS_TRACE_LEVEL_ERROR, "%s peer malloc failed!", __func__);
1218 return NULL;
1219 }
Chilam NG571c65a2013-01-19 12:27:36 +05301220
Gopichand Nakkala4ddf0192013-03-27 13:41:20 -07001221 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
1222
1223 if (NULL == pHddTdlsCtx)
1224 {
1225 vos_mem_free(peer);
Hema Aparna Medicharla8bb6f782015-03-09 12:35:05 +05301226 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
1227 FL("pHddTdlsCtx is NULL"));
Gopichand Nakkala4ddf0192013-03-27 13:41:20 -07001228 return NULL;
1229 }
1230
1231 key = wlan_hdd_tdls_hash_key(mac);
1232 head = &pHddTdlsCtx->peer_list[key];
Chilam NG571c65a2013-01-19 12:27:36 +05301233
Hoonki Lee387663d2013-02-05 18:08:43 -08001234 vos_mem_zero(peer, sizeof(hddTdlsPeer_t));
1235 vos_mem_copy(peer->peerMac, mac, sizeof(peer->peerMac));
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001236 peer->pHddTdlsCtx = pHddTdlsCtx;
Hoonki Lee387663d2013-02-05 18:08:43 -08001237
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001238 vos_timer_init(&peer->peerIdleTimer,
1239 VOS_TIMER_TYPE_SW,
1240 wlan_hdd_tdls_idle_cb,
1241 peer);
1242
Hoonki Lee14621352013-04-16 17:51:19 -07001243 vos_timer_init(&peer->initiatorWaitTimeoutTimer,
1244 VOS_TIMER_TYPE_SW,
1245 wlan_hdd_tdls_initiator_wait_cb,
1246 peer);
1247
Hoonki Lee387663d2013-02-05 18:08:43 -08001248 list_add_tail(&peer->node, head);
Hoonki Lee387663d2013-02-05 18:08:43 -08001249
1250 return peer;
1251}
1252
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07001253int wlan_hdd_tdls_set_cap(hdd_adapter_t *pAdapter,
Hoonki Lee27511902013-03-14 18:19:06 -07001254 u8* mac,
1255 tTDLSCapType cap)
1256{
1257 hddTdlsPeer_t *curr_peer;
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301258 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Hoonki Lee27511902013-03-14 18:19:06 -07001259
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301260 if (0 != (wlan_hdd_validate_context(pHddCtx)))
1261 return -EINVAL;
1262
1263 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07001264 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Hoonki Lee27511902013-03-14 18:19:06 -07001265 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301266 {
1267 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1268 "%s: curr_peer is NULL", __func__);
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301269 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07001270 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301271 }
Hoonki Lee27511902013-03-14 18:19:06 -07001272
1273 curr_peer->tdls_support = cap;
1274
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301275 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07001276 return 0;
Hoonki Lee27511902013-03-14 18:19:06 -07001277}
1278
Atul Mittal115287b2014-07-08 13:26:33 +05301279void wlan_hdd_tdls_set_peer_link_status(hddTdlsPeer_t *curr_peer,
1280 tTDLSLinkStatus status,
1281 tTDLSLinkReason reason)
Hoonki Lee387663d2013-02-05 18:08:43 -08001282{
Atul Mittal115287b2014-07-08 13:26:33 +05301283 /*EXT TDLS*/
1284 tANI_S32 state = 0;
1285 tANI_S32 res = 0;
1286 /*EXT TDLS*/
Hoonki Lee387663d2013-02-05 18:08:43 -08001287 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301288 {
1289 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1290 "%s: curr_peer is NULL", __func__);
Hoonki Lee387663d2013-02-05 18:08:43 -08001291 return;
c_hpothu7f63e882013-10-02 19:13:35 +05301292 }
Hoonki Lee387663d2013-02-05 18:08:43 -08001293
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001294 hddLog(VOS_TRACE_LEVEL_WARN, "tdls set peer " MAC_ADDRESS_STR " link status to %u",
Chilam Ng01120412013-02-19 18:32:21 -08001295 MAC_ADDR_ARRAY(curr_peer->peerMac), status);
Chilam NG571c65a2013-01-19 12:27:36 +05301296
1297 curr_peer->link_status = status;
1298
Atul Mittal115287b2014-07-08 13:26:33 +05301299 /*EXT TDLS*/
1300 if (curr_peer->isForcedPeer && curr_peer->state_change_notification)
1301 {
1302 /*save the reason for any further query*/
1303 curr_peer->reason = reason;
1304 wlan_hdd_tdls_get_wifi_hal_state(curr_peer, &state, &res);
1305
1306 (curr_peer->state_change_notification)(
1307 curr_peer->peerMac,
1308 state,
1309 res,
1310 curr_peer->pHddTdlsCtx->pAdapter);
1311
1312 }
1313 /*EXT TDLS*/
1314
Chilam NG571c65a2013-01-19 12:27:36 +05301315}
1316
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001317void wlan_hdd_tdls_set_link_status(hdd_adapter_t *pAdapter,
Anand N Sunkadb3ab97d2015-07-29 09:58:13 +05301318#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
1319 const u8 *mac,
1320#else
1321 u8 *mac,
1322#endif
Atul Mittal115287b2014-07-08 13:26:33 +05301323 tTDLSLinkStatus linkStatus,
1324 tTDLSLinkReason reason)
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001325{
Atul Mittal115287b2014-07-08 13:26:33 +05301326
1327 /*EXT TDLS*/
1328 tANI_S32 state = 0;
1329 tANI_S32 res = 0;
1330 /*EXT TDLS*/
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001331 hddTdlsPeer_t *curr_peer;
1332
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301333 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001334 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301335 {
1336 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1337 "%s: curr_peer is NULL", __func__);
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001338 return;
c_hpothu7f63e882013-10-02 19:13:35 +05301339 }
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001340
1341 curr_peer->link_status= linkStatus;
1342
Atul Mittal115287b2014-07-08 13:26:33 +05301343 /*EXT TDLS*/
1344
1345 if (curr_peer->isForcedPeer && curr_peer->state_change_notification)
1346 {
1347 /*save the reason for any further query*/
1348 curr_peer->reason = reason;
1349 wlan_hdd_tdls_get_wifi_hal_state(curr_peer, &state, &res);
1350
1351 (*curr_peer->state_change_notification)(mac,
1352 state,
1353 res,
1354 curr_peer->pHddTdlsCtx->pAdapter);
1355
1356 }
1357 /*EXT TDLS*/
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001358 return;
1359}
1360
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001361int wlan_hdd_tdls_recv_discovery_resp(hdd_adapter_t *pAdapter, u8 *mac)
Chilam NG571c65a2013-01-19 12:27:36 +05301362{
1363 hddTdlsPeer_t *curr_peer;
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001364 tdlsCtx_t *pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301365 hdd_context_t *pHddCtx;
1366
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05301367 ENTER();
1368
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301369 if ( NULL == pHddTdlsCtx )
c_hpothu7f63e882013-10-02 19:13:35 +05301370 {
1371 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05301372 FL("pHddTdlsCtx is NULL device mode = %d"), pAdapter->device_mode);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301373 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301374 }
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301375
1376 pHddCtx = WLAN_HDD_GET_CTX(pHddTdlsCtx->pAdapter);
1377
c_hpothu7f63e882013-10-02 19:13:35 +05301378 if(0 != (wlan_hdd_validate_context(pHddCtx)))
1379 {
c_hpothu7f63e882013-10-02 19:13:35 +05301380 return 0;
1381 }
Chilam NG571c65a2013-01-19 12:27:36 +05301382
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301383 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001384 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001385
1386 if (NULL == curr_peer)
c_hpothu7f63e882013-10-02 19:13:35 +05301387 {
1388 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1389 FL("curr_peer is NULL"));
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301390 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Lee387663d2013-02-05 18:08:43 -08001391 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301392 }
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301393 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001394
1395 if (pHddTdlsCtx->discovery_sent_cnt)
1396 pHddTdlsCtx->discovery_sent_cnt--;
1397
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05301398 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301399
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07001400 wlan_hdd_tdls_check_power_save_prohibited(pAdapter);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301401
1402 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001403 if (0 == pHddTdlsCtx->discovery_sent_cnt)
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07001404 {
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001405 vos_timer_stop(&pHddTdlsCtx->peerDiscoveryTimeoutTimer);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07001406 }
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001407
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05301408 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07001409 "Discovery(%u) Response from " MAC_ADDRESS_STR " link_status %d",
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001410 pHddTdlsCtx->discovery_sent_cnt, MAC_ADDR_ARRAY(curr_peer->peerMac),
1411 curr_peer->link_status);
1412
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001413 if (eTDLS_LINK_DISCOVERING == curr_peer->link_status)
Gopichand Nakkala901e8922013-03-04 23:45:58 -08001414 {
Shailender Karmuchi13c0d082013-03-26 14:41:39 -07001415 /* Since we are here, it means Throughput threshold is alredy met. Make sure RSSI
1416 threshold is also met before setting up TDLS link*/
1417 if ((tANI_S32) curr_peer->rssi > (tANI_S32) pHddTdlsCtx->threshold_config.rssi_trigger_threshold)
1418 {
Atul Mittal115287b2014-07-08 13:26:33 +05301419 wlan_hdd_tdls_set_peer_link_status(curr_peer,
1420 eTDLS_LINK_DISCOVERED,
1421 eTDLS_LINK_SUCCESS);
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05301422 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Shailender Karmuchi13c0d082013-03-26 14:41:39 -07001423 "Rssi Threshold met: "MAC_ADDRESS_STR" rssi = %d threshold= %d" ,
1424 MAC_ADDR_ARRAY(curr_peer->peerMac), curr_peer->rssi,
1425 pHddTdlsCtx->threshold_config.rssi_trigger_threshold);
1426 cfg80211_tdls_oper_request(pAdapter->dev, curr_peer->peerMac, NL80211_TDLS_SETUP, FALSE, GFP_KERNEL);
1427 }
1428 else
1429 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05301430 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Shailender Karmuchi13c0d082013-03-26 14:41:39 -07001431 "Rssi Threshold not met: "MAC_ADDRESS_STR" rssi = %d threshold = %d ",
1432 MAC_ADDR_ARRAY(curr_peer->peerMac), curr_peer->rssi,
1433 pHddTdlsCtx->threshold_config.rssi_trigger_threshold);
Sunil Duttb0d39242014-09-10 23:54:51 +05301434
1435 /* if RSSI threshold is not met then allow further discovery
1436 * attempts by decrementing count for the last attempt
1437 */
1438 if (curr_peer->discovery_attempt)
1439 curr_peer->discovery_attempt--;
1440
Atul Mittal115287b2014-07-08 13:26:33 +05301441 wlan_hdd_tdls_set_peer_link_status(curr_peer,
1442 eTDLS_LINK_IDLE,
1443 eTDLS_LINK_UNSPECIFIED);
Shailender Karmuchi13c0d082013-03-26 14:41:39 -07001444 }
Gopichand Nakkala901e8922013-03-04 23:45:58 -08001445 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07001446 else
1447 {
1448 wlan_hdd_tdls_check_bmps(pAdapter);
1449 }
Chilam NG571c65a2013-01-19 12:27:36 +05301450
Gopichand Nakkala901e8922013-03-04 23:45:58 -08001451 curr_peer->tdls_support = eTDLS_CAP_SUPPORTED;
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05301452 EXIT();
Hoonki Lee387663d2013-02-05 18:08:43 -08001453 return 0;
Chilam NG571c65a2013-01-19 12:27:36 +05301454}
1455
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301456int wlan_hdd_tdls_set_peer_caps(hdd_adapter_t *pAdapter,
Anand N Sunkadb3ab97d2015-07-29 09:58:13 +05301457#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
1458 const u8 *mac,
1459#else
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301460 u8 *mac,
Anand N Sunkadb3ab97d2015-07-29 09:58:13 +05301461#endif
Naresh Jayaram3180aa42014-02-12 21:47:26 +05301462 tCsrStaParams *StaParams,
1463 tANI_BOOLEAN isBufSta,
1464 tANI_BOOLEAN isOffChannelSupported)
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301465{
1466 hddTdlsPeer_t *curr_peer;
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301467 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301468
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301469 if (0 != (wlan_hdd_validate_context(pHddCtx)))
1470 return -EINVAL;
1471
1472 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301473 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
1474 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301475 {
1476 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1477 "%s: curr_peer is NULL", __func__);
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301478 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301479 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301480 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301481
Naresh Jayaram3180aa42014-02-12 21:47:26 +05301482 curr_peer->uapsdQueues = StaParams->uapsd_queues;
1483 curr_peer->maxSp = StaParams->max_sp;
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301484 curr_peer->isBufSta = isBufSta;
Naresh Jayaram3180aa42014-02-12 21:47:26 +05301485 curr_peer->isOffChannelSupported = isOffChannelSupported;
1486
1487 vos_mem_copy(curr_peer->supported_channels,
1488 StaParams->supported_channels,
1489 StaParams->supported_channels_len);
1490
1491 curr_peer->supported_channels_len =
1492 StaParams->supported_channels_len;
1493
1494 vos_mem_copy(curr_peer->supported_oper_classes,
1495 StaParams->supported_oper_classes,
1496 StaParams->supported_oper_classes_len);
1497
1498 curr_peer->supported_oper_classes_len =
1499 StaParams->supported_oper_classes_len;
Agarwal Ashish16020c42014-12-29 22:01:11 +05301500 curr_peer->qos = StaParams->capability & CAPABILITIES_QOS_OFFSET;
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301501
1502 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301503 return 0;
1504}
1505
1506int wlan_hdd_tdls_get_link_establish_params(hdd_adapter_t *pAdapter, u8 *mac,
1507 tCsrTdlsLinkEstablishParams* tdlsLinkEstablishParams)
1508{
1509 hddTdlsPeer_t *curr_peer;
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301510 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301511
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301512 if (0 != (wlan_hdd_validate_context(pHddCtx)))
1513 return -EINVAL;
1514
1515 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301516 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
1517 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301518 {
1519 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1520 "%s: curr_peer is NULL", __func__);
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301521 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301522 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301523 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301524
1525 tdlsLinkEstablishParams->isResponder = curr_peer->is_responder;
1526 tdlsLinkEstablishParams->uapsdQueues = curr_peer->uapsdQueues;
1527 tdlsLinkEstablishParams->maxSp = curr_peer->maxSp;
1528 tdlsLinkEstablishParams->isBufSta = curr_peer->isBufSta;
Naresh Jayaram3180aa42014-02-12 21:47:26 +05301529 tdlsLinkEstablishParams->isOffChannelSupported =
1530 curr_peer->isOffChannelSupported;
1531
1532 vos_mem_copy(tdlsLinkEstablishParams->supportedChannels,
1533 curr_peer->supported_channels,
1534 curr_peer->supported_channels_len);
1535
1536 tdlsLinkEstablishParams->supportedChannelsLen =
1537 curr_peer->supported_channels_len;
1538
1539 vos_mem_copy(tdlsLinkEstablishParams->supportedOperClasses,
1540 curr_peer->supported_oper_classes,
1541 curr_peer->supported_oper_classes_len);
1542
1543 tdlsLinkEstablishParams->supportedOperClassesLen =
1544 curr_peer->supported_oper_classes_len;
Agarwal Ashish16020c42014-12-29 22:01:11 +05301545 tdlsLinkEstablishParams->qos = curr_peer->qos;
1546
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301547 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301548 return 0;
1549}
1550
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001551int wlan_hdd_tdls_set_rssi(hdd_adapter_t *pAdapter, u8 *mac, tANI_S8 rxRssi)
Chilam NG571c65a2013-01-19 12:27:36 +05301552{
1553 hddTdlsPeer_t *curr_peer;
Chilam NG571c65a2013-01-19 12:27:36 +05301554
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301555 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Hoonki Lee387663d2013-02-05 18:08:43 -08001556 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301557 {
1558 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1559 "%s: curr_peer is NULL", __func__);
Hoonki Lee387663d2013-02-05 18:08:43 -08001560 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301561 }
Chilam NG571c65a2013-01-19 12:27:36 +05301562
1563 curr_peer->rssi = rxRssi;
1564
Hoonki Lee387663d2013-02-05 18:08:43 -08001565 return 0;
Chilam NG571c65a2013-01-19 12:27:36 +05301566}
1567
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001568int wlan_hdd_tdls_set_responder(hdd_adapter_t *pAdapter, u8 *mac, tANI_U8 responder)
Hoonki Leea34dd892013-02-05 22:56:02 -08001569{
1570 hddTdlsPeer_t *curr_peer;
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301571 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Hoonki Leea34dd892013-02-05 22:56:02 -08001572
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301573 if (0 != (wlan_hdd_validate_context(pHddCtx)))
1574 return -EINVAL;
1575
1576 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001577 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001578 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301579 {
1580 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1581 "%s: curr_peer is NULL", __func__);
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301582 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Leea34dd892013-02-05 22:56:02 -08001583 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301584 }
Hoonki Leea34dd892013-02-05 22:56:02 -08001585
1586 curr_peer->is_responder = responder;
1587
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301588 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Leea34dd892013-02-05 22:56:02 -08001589 return 0;
1590}
1591
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001592int wlan_hdd_tdls_get_responder(hdd_adapter_t *pAdapter, u8 *mac)
Hoonki Leea34dd892013-02-05 22:56:02 -08001593{
1594 hddTdlsPeer_t *curr_peer;
1595
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301596 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001597 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301598 {
1599 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1600 "%s: curr_peer is NULL", __func__);
Hoonki Leea34dd892013-02-05 22:56:02 -08001601 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301602 }
Hoonki Leea34dd892013-02-05 22:56:02 -08001603
1604 return (curr_peer->is_responder);
1605}
1606
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001607int wlan_hdd_tdls_set_signature(hdd_adapter_t *pAdapter, u8 *mac, tANI_U8 uSignature)
Hoonki Lee11f7dda2013-02-14 16:55:44 -08001608{
1609 hddTdlsPeer_t *curr_peer;
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301610 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08001611
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301612 if (0 != (wlan_hdd_validate_context(pHddCtx)))
1613 return -EINVAL;
1614
1615 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001616 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08001617 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301618 {
1619 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1620 "%s: curr_peer is NULL", __func__);
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301621 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08001622 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301623 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08001624
1625 curr_peer->signature = uSignature;
1626
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301627 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08001628 return 0;
1629}
1630
Hoonki Leea34dd892013-02-05 22:56:02 -08001631
Hoonki Lee387663d2013-02-05 18:08:43 -08001632void wlan_hdd_tdls_extract_da(struct sk_buff *skb, u8 *mac)
Chilam NG571c65a2013-01-19 12:27:36 +05301633{
Chilam NG571c65a2013-01-19 12:27:36 +05301634 memcpy(mac, skb->data, 6);
Chilam NG571c65a2013-01-19 12:27:36 +05301635}
1636
Hoonki Lee387663d2013-02-05 18:08:43 -08001637void wlan_hdd_tdls_extract_sa(struct sk_buff *skb, u8 *mac)
Chilam Ng1279e232013-01-25 15:06:52 -08001638{
Chilam Ng1279e232013-01-25 15:06:52 -08001639 memcpy(mac, skb->data+6, 6);
Chilam Ng1279e232013-01-25 15:06:52 -08001640}
1641
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001642int wlan_hdd_tdls_increment_pkt_count(hdd_adapter_t *pAdapter, u8 *mac, u8 tx)
Chilam NG571c65a2013-01-19 12:27:36 +05301643{
Hoonki Lee387663d2013-02-05 18:08:43 -08001644 hddTdlsPeer_t *curr_peer;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001645 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Chilam NG571c65a2013-01-19 12:27:36 +05301646
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301647 if (0 != (wlan_hdd_validate_context(pHddCtx)))
1648 return -EINVAL;
1649
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001650 if (eTDLS_SUPPORT_ENABLED != pHddCtx->tdls_mode)
1651 return -1;
Hoonki Leebfee0342013-01-21 16:43:45 -08001652
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301653 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001654 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Hoonki Lee387663d2013-02-05 18:08:43 -08001655 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301656 {
c_hpothue21931b2014-09-08 14:02:14 +05301657 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
1658 FL("curr_peer is NULL"));
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301659 mutex_unlock(&pHddCtx->tdls_lock);
Chilam NG571c65a2013-01-19 12:27:36 +05301660 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301661 }
Chilam NG571c65a2013-01-19 12:27:36 +05301662
Chilam Ng1279e232013-01-25 15:06:52 -08001663 if (tx)
1664 curr_peer->tx_pkt++;
1665 else
1666 curr_peer->rx_pkt++;
Chilam NG571c65a2013-01-19 12:27:36 +05301667
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301668 mutex_unlock(&pHddCtx->tdls_lock);
Chilam NG571c65a2013-01-19 12:27:36 +05301669 return 0;
1670}
1671
Hoonki Lee27511902013-03-14 18:19:06 -07001672static int wlan_hdd_tdls_check_config(tdls_config_params_t *config)
1673{
1674 if (config->tdls > 2)
1675 {
1676 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 1st argument %d. <0...2>", __func__, config->tdls);
1677 return -1;
1678 }
1679 if (config->tx_period_t < CFG_TDLS_TX_STATS_PERIOD_MIN ||
1680 config->tx_period_t > CFG_TDLS_TX_STATS_PERIOD_MAX)
1681 {
Jeff Johnson0299d0a2013-10-30 12:37:43 -07001682 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 2nd argument %d. <%d...%ld>", __func__, config->tx_period_t,
Hoonki Lee27511902013-03-14 18:19:06 -07001683 CFG_TDLS_TX_STATS_PERIOD_MIN, CFG_TDLS_TX_STATS_PERIOD_MAX);
1684 return -1;
1685 }
1686 if (config->tx_packet_n < CFG_TDLS_TX_PACKET_THRESHOLD_MIN ||
1687 config->tx_packet_n > CFG_TDLS_TX_PACKET_THRESHOLD_MAX)
1688 {
Jeff Johnson0299d0a2013-10-30 12:37:43 -07001689 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 3rd argument %d. <%d...%ld>", __func__, config->tx_packet_n,
Hoonki Lee27511902013-03-14 18:19:06 -07001690 CFG_TDLS_TX_PACKET_THRESHOLD_MIN, CFG_TDLS_TX_PACKET_THRESHOLD_MAX);
1691 return -1;
1692 }
1693 if (config->discovery_period_t < CFG_TDLS_DISCOVERY_PERIOD_MIN ||
1694 config->discovery_period_t > CFG_TDLS_DISCOVERY_PERIOD_MAX)
1695 {
Jeff Johnson0299d0a2013-10-30 12:37:43 -07001696 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 4th argument %d. <%d...%ld>", __func__, config->discovery_period_t,
Hoonki Lee27511902013-03-14 18:19:06 -07001697 CFG_TDLS_DISCOVERY_PERIOD_MIN, CFG_TDLS_DISCOVERY_PERIOD_MAX);
1698 return -1;
1699 }
1700 if (config->discovery_tries_n < CFG_TDLS_MAX_DISCOVERY_ATTEMPT_MIN ||
1701 config->discovery_tries_n > CFG_TDLS_MAX_DISCOVERY_ATTEMPT_MAX)
1702 {
1703 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 5th argument %d. <%d...%d>", __func__, config->discovery_tries_n,
1704 CFG_TDLS_MAX_DISCOVERY_ATTEMPT_MIN, CFG_TDLS_MAX_DISCOVERY_ATTEMPT_MAX);
1705 return -1;
1706 }
1707 if (config->idle_timeout_t < CFG_TDLS_IDLE_TIMEOUT_MIN ||
1708 config->idle_timeout_t > CFG_TDLS_IDLE_TIMEOUT_MAX)
1709 {
1710 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 6th argument %d. <%d...%d>", __func__, config->idle_timeout_t,
1711 CFG_TDLS_IDLE_TIMEOUT_MIN, CFG_TDLS_IDLE_TIMEOUT_MAX);
1712 return -1;
1713 }
1714 if (config->idle_packet_n < CFG_TDLS_IDLE_PACKET_THRESHOLD_MIN ||
1715 config->idle_packet_n > CFG_TDLS_IDLE_PACKET_THRESHOLD_MAX)
1716 {
1717 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 7th argument %d. <%d...%d>", __func__, config->idle_packet_n,
1718 CFG_TDLS_IDLE_PACKET_THRESHOLD_MIN, CFG_TDLS_IDLE_PACKET_THRESHOLD_MAX);
1719 return -1;
1720 }
1721 if (config->rssi_hysteresis < CFG_TDLS_RSSI_HYSTERESIS_MIN ||
1722 config->rssi_hysteresis > CFG_TDLS_RSSI_HYSTERESIS_MAX)
1723 {
1724 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 8th argument %d. <%d...%d>", __func__, config->rssi_hysteresis,
1725 CFG_TDLS_RSSI_HYSTERESIS_MIN, CFG_TDLS_RSSI_HYSTERESIS_MAX);
1726 return -1;
1727 }
1728 if (config->rssi_trigger_threshold < CFG_TDLS_RSSI_TRIGGER_THRESHOLD_MIN ||
1729 config->rssi_trigger_threshold > CFG_TDLS_RSSI_TRIGGER_THRESHOLD_MAX)
1730 {
1731 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 9th argument %d. <%d...%d>", __func__, config->rssi_trigger_threshold,
1732 CFG_TDLS_RSSI_TRIGGER_THRESHOLD_MIN, CFG_TDLS_RSSI_TRIGGER_THRESHOLD_MAX);
1733 return -1;
1734 }
1735 if (config->rssi_teardown_threshold < CFG_TDLS_RSSI_TEARDOWN_THRESHOLD_MIN ||
1736 config->rssi_teardown_threshold > CFG_TDLS_RSSI_TEARDOWN_THRESHOLD_MAX)
1737 {
1738 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 10th argument %d. <%d...%d>", __func__, config->rssi_teardown_threshold,
1739 CFG_TDLS_RSSI_TEARDOWN_THRESHOLD_MIN, CFG_TDLS_RSSI_TEARDOWN_THRESHOLD_MAX);
1740 return -1;
1741 }
1742 return 0;
1743}
1744
Chilam Ng01120412013-02-19 18:32:21 -08001745int wlan_hdd_tdls_set_params(struct net_device *dev, tdls_config_params_t *config)
Chilam NG571c65a2013-01-19 12:27:36 +05301746{
Chilam Ng01120412013-02-19 18:32:21 -08001747 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
1748 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001749 tdlsCtx_t *pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
Hoonki Lee27511902013-03-14 18:19:06 -07001750 eTDLSSupportMode req_tdls_mode;
Hoonki Leebfee0342013-01-21 16:43:45 -08001751
Hoonki Lee27511902013-03-14 18:19:06 -07001752 if (NULL == pHddTdlsCtx)
1753 {
c_hpothu7f63e882013-10-02 19:13:35 +05301754 hddLog(VOS_TRACE_LEVEL_ERROR, FL("TDLS not enabled!"));
Hoonki Lee27511902013-03-14 18:19:06 -07001755 return -1;
Chilam Ng01120412013-02-19 18:32:21 -08001756 }
Chilam NG571c65a2013-01-19 12:27:36 +05301757
Hoonki Lee27511902013-03-14 18:19:06 -07001758 if (wlan_hdd_tdls_check_config(config) != 0)
1759 {
1760 return -1;
1761 }
1762
1763 /* config->tdls is mapped to 0->1, 1->2, 2->3 */
1764 req_tdls_mode = config->tdls + 1;
1765 if (pHddCtx->tdls_mode == req_tdls_mode)
1766 {
1767 hddLog(VOS_TRACE_LEVEL_ERROR, "%s already in mode %d", __func__, config->tdls);
1768 return -1;
1769 }
1770
1771 /* copy the configuration only when given tdls mode is implicit trigger enable */
1772 if (eTDLS_SUPPORT_ENABLED == req_tdls_mode)
1773 {
Chilam Ng01120412013-02-19 18:32:21 -08001774 memcpy(&pHddTdlsCtx->threshold_config, config, sizeof(tdls_config_params_t));
1775 }
Chilam NG571c65a2013-01-19 12:27:36 +05301776
Chilam Ng01120412013-02-19 18:32:21 -08001777 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1778 "iw set tdls params: %d %d %d %d %d %d %d %d %d %d",
1779 config->tdls,
1780 config->tx_period_t,
1781 config->tx_packet_n,
1782 config->discovery_period_t,
1783 config->discovery_tries_n,
1784 config->idle_timeout_t,
1785 config->idle_packet_n,
1786 config->rssi_hysteresis,
1787 config->rssi_trigger_threshold,
1788 config->rssi_teardown_threshold);
Chilam NG571c65a2013-01-19 12:27:36 +05301789
Gopichand Nakkaladcbcf4e2013-03-23 14:32:39 -07001790 wlan_hdd_tdls_set_mode(pHddCtx, req_tdls_mode, TRUE);
Chilam Ng01120412013-02-19 18:32:21 -08001791
Chilam NG571c65a2013-01-19 12:27:36 +05301792 return 0;
1793}
1794
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001795int wlan_hdd_tdls_set_sta_id(hdd_adapter_t *pAdapter, u8 *mac, u8 staId)
Kiran V1ccee932012-12-12 14:49:46 -08001796{
Hoonki Lee387663d2013-02-05 18:08:43 -08001797 hddTdlsPeer_t *curr_peer;
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301798 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Kiran V1ccee932012-12-12 14:49:46 -08001799
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301800 if (0 != (wlan_hdd_validate_context(pHddCtx)))
1801 return -EINVAL;
1802
1803 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001804 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Hoonki Lee387663d2013-02-05 18:08:43 -08001805 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301806 {
1807 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1808 "%s: curr_peer is NULL", __func__);
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301809 mutex_unlock(&pHddCtx->tdls_lock);
Chilam NG571c65a2013-01-19 12:27:36 +05301810 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301811 }
Chilam NG571c65a2013-01-19 12:27:36 +05301812
Hoonki Lee387663d2013-02-05 18:08:43 -08001813 curr_peer->staId = staId;
Chilam NG571c65a2013-01-19 12:27:36 +05301814
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301815 mutex_unlock(&pHddCtx->tdls_lock);
Chilam NG571c65a2013-01-19 12:27:36 +05301816 return 0;
Kiran V1ccee932012-12-12 14:49:46 -08001817}
1818
Naresh Jayaram937abdf2013-11-26 19:50:25 +05301819int wlan_hdd_tdls_set_force_peer(hdd_adapter_t *pAdapter, u8 *mac,
1820 tANI_BOOLEAN forcePeer)
Sunil Dutt41de4e22013-11-14 18:09:02 +05301821{
Naresh Jayaram937abdf2013-11-26 19:50:25 +05301822 hddTdlsPeer_t *curr_peer;
Sunil Dutt41de4e22013-11-14 18:09:02 +05301823 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
1824
1825 if ((NULL == pHddCtx)) return -1;
1826
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05301827 mutex_lock(&pHddCtx->tdls_lock);
1828
Naresh Jayaram937abdf2013-11-26 19:50:25 +05301829 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, FALSE);
1830 if (curr_peer == NULL)
Sunil Dutt41de4e22013-11-14 18:09:02 +05301831 goto error;
Naresh Jayaram937abdf2013-11-26 19:50:25 +05301832 curr_peer->isForcedPeer = forcePeer;
Naresh Jayaramca7bc3a2014-02-04 23:03:04 +05301833
1834 mutex_unlock(&pHddCtx->tdls_lock);
1835 return 0;
Sunil Dutt41de4e22013-11-14 18:09:02 +05301836error:
1837 mutex_unlock(&pHddCtx->tdls_lock);
1838 return -1;
1839}
1840
Hoonki Lee387663d2013-02-05 18:08:43 -08001841/* if peerMac is found, then it returns pointer to hddTdlsPeer_t
1842 otherwise, it returns NULL
1843*/
Anand N Sunkadb3ab97d2015-07-29 09:58:13 +05301844hddTdlsPeer_t *wlan_hdd_tdls_find_peer(hdd_adapter_t *pAdapter,
1845#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
1846 const u8 *mac,
1847#else
1848 u8 *mac,
1849#endif
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301850 tANI_BOOLEAN mutexLock)
Kiran V1ccee932012-12-12 14:49:46 -08001851{
Hoonki Lee387663d2013-02-05 18:08:43 -08001852 u8 key;
1853 struct list_head *pos;
1854 struct list_head *head;
1855 hddTdlsPeer_t *curr_peer;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001856 tdlsCtx_t *pHddTdlsCtx;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05301857 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Hoonki Lee387663d2013-02-05 18:08:43 -08001858
c_hpothu7f63e882013-10-02 19:13:35 +05301859 if(0 != (wlan_hdd_validate_context(pHddCtx)))
1860 {
c_hpothu7f63e882013-10-02 19:13:35 +05301861 return 0;
1862 }
Hoonki Lee387663d2013-02-05 18:08:43 -08001863
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301864 if ( mutexLock )
Hoonki Lee387663d2013-02-05 18:08:43 -08001865 {
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05301866 mutex_lock(&pHddCtx->tdls_lock);
Hoonki Lee387663d2013-02-05 18:08:43 -08001867 }
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001868 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08001869 if (NULL == pHddTdlsCtx)
1870 {
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301871 if ( mutexLock )
1872 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08001873 return NULL;
1874 }
1875
1876 key = wlan_hdd_tdls_hash_key(mac);
1877
1878 head = &pHddTdlsCtx->peer_list[key];
Hoonki Lee387663d2013-02-05 18:08:43 -08001879
1880 list_for_each(pos, head) {
1881 curr_peer = list_entry (pos, hddTdlsPeer_t, node);
1882 if (!memcmp(mac, curr_peer->peerMac, 6)) {
1883 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
1884 "findTdlsPeer: found staId %d", curr_peer->staId);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301885 if ( mutexLock )
1886 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Lee387663d2013-02-05 18:08:43 -08001887 return curr_peer;
1888 }
1889 }
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301890 if ( mutexLock )
1891 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05301892
Hoonki Lee387663d2013-02-05 18:08:43 -08001893 return NULL;
1894}
1895
Hoonki Leea6d49be2013-04-05 09:43:25 -07001896hddTdlsPeer_t *wlan_hdd_tdls_find_all_peer(hdd_context_t *pHddCtx, u8 *mac)
1897{
1898 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
1899 hdd_adapter_t *pAdapter = NULL;
1900 tdlsCtx_t *pHddTdlsCtx = NULL;
1901 hddTdlsPeer_t *curr_peer= NULL;
1902 VOS_STATUS status = 0;
1903
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05301904 mutex_lock(&pHddCtx->tdls_lock);
Hoonki Leea6d49be2013-04-05 09:43:25 -07001905 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
1906 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
1907 {
1908 pAdapter = pAdapterNode->pAdapter;
1909
1910 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
1911 if (NULL != pHddTdlsCtx)
1912 {
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301913 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, FALSE);
Hoonki Leea6d49be2013-04-05 09:43:25 -07001914 if (curr_peer)
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301915 {
1916 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Leea6d49be2013-04-05 09:43:25 -07001917 return curr_peer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301918 }
Hoonki Leea6d49be2013-04-05 09:43:25 -07001919 }
1920 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
1921 pAdapterNode = pNext;
1922 }
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301923 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Leea6d49be2013-04-05 09:43:25 -07001924 return curr_peer;
1925}
1926
1927
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001928int wlan_hdd_tdls_reset_peer(hdd_adapter_t *pAdapter, u8 *mac)
Hoonki Lee387663d2013-02-05 18:08:43 -08001929{
Chilam Ng01120412013-02-19 18:32:21 -08001930 hdd_context_t *pHddCtx;
Chilam NG571c65a2013-01-19 12:27:36 +05301931 hddTdlsPeer_t *curr_peer;
Kiran V1ccee932012-12-12 14:49:46 -08001932
Chilam Ng01120412013-02-19 18:32:21 -08001933 pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
1934
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301935 if (0 != (wlan_hdd_validate_context(pHddCtx)))
1936 return -EINVAL;
1937
1938 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001939 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Hoonki Lee387663d2013-02-05 18:08:43 -08001940 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301941 {
1942 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1943 "%s: curr_peer is NULL", __func__);
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301944 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Lee387663d2013-02-05 18:08:43 -08001945 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301946 }
Chilam NG571c65a2013-01-19 12:27:36 +05301947
Atul Mittal115287b2014-07-08 13:26:33 +05301948 wlan_hdd_tdls_set_peer_link_status(curr_peer,
1949 eTDLS_LINK_IDLE,
1950 eTDLS_LINK_UNSPECIFIED);
Hoonki Leecdd8e962013-01-20 00:45:46 -08001951 curr_peer->staId = 0;
Hoonki Lee387663d2013-02-05 18:08:43 -08001952
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05301953 /* Throughput Monitor shall disable the split scan when
1954 * TDLS scan coexistance is disabled.At this point of time
1955 * since TDLS scan coexistance is not meeting the criteria
1956 * to be operational, explicitly make it false to enable
1957 * throughput monitor takes the control of split scan.
1958 */
1959 if (pHddCtx->isTdlsScanCoexistence == TRUE)
1960 {
1961 pHddCtx->isTdlsScanCoexistence = FALSE;
1962 }
1963
Chilam Ng01120412013-02-19 18:32:21 -08001964 if(eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode) {
Chilam Nga75d8b62013-01-29 01:35:59 -08001965 vos_timer_stop( &curr_peer->peerIdleTimer );
Chilam Nga75d8b62013-01-29 01:35:59 -08001966 }
Masti, Narayanraddi6dbcdbb2015-05-13 10:28:06 +05301967
1968 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Lee387663d2013-02-05 18:08:43 -08001969 return 0;
Hoonki Leecdd8e962013-01-20 00:45:46 -08001970}
1971
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07001972/* Caller has to take the lock before calling this function */
Hoonki Lee27511902013-03-14 18:19:06 -07001973static void wlan_tdd_tdls_reset_tx_rx(tdlsCtx_t *pHddTdlsCtx)
1974{
1975 int i;
1976 struct list_head *head;
1977 hddTdlsPeer_t *tmp;
1978 struct list_head *pos, *q;
1979
Hoonki Lee27511902013-03-14 18:19:06 -07001980 for (i = 0; i < 256; i++) {
1981 head = &pHddTdlsCtx->peer_list[i];
1982 list_for_each_safe (pos, q, head) {
1983 tmp = list_entry(pos, hddTdlsPeer_t, node);
1984 tmp->tx_pkt = 0;
1985 tmp->rx_pkt = 0;
1986 }
1987 }
Hoonki Lee27511902013-03-14 18:19:06 -07001988
1989 return ;
1990}
1991
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07001992/* Caller has to take the lock before calling this function */
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001993static tANI_S32 wlan_hdd_tdls_peer_reset_discovery_processed(tdlsCtx_t *pHddTdlsCtx)
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001994{
1995 int i;
1996 struct list_head *head;
1997 hddTdlsPeer_t *tmp;
1998 struct list_head *pos, *q;
1999
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002000 pHddTdlsCtx->discovery_peer_cnt = 0;
2001
2002 for (i = 0; i < 256; i++) {
2003 head = &pHddTdlsCtx->peer_list[i];
2004 list_for_each_safe (pos, q, head) {
2005 tmp = list_entry(pos, hddTdlsPeer_t, node);
2006 tmp->discovery_processed = 0;
2007 }
2008 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002009
2010 return 0;
2011}
2012
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002013static tANI_S32 wlan_hdd_get_tdls_discovery_peer_cnt(tdlsCtx_t *pHddTdlsCtx)
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002014{
2015 int i;
2016 struct list_head *head;
2017 struct list_head *pos, *q;
2018 int discovery_peer_cnt=0;
2019 hddTdlsPeer_t *tmp;
2020
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002021 /*
2022 * This function expects the callers to acquire the Mutex.
2023 */
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002024
2025 for (i = 0; i < 256; i++) {
2026 head = &pHddTdlsCtx->peer_list[i];
2027 list_for_each_safe (pos, q, head) {
2028 tmp = list_entry(pos, hddTdlsPeer_t, node);
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302029 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Chilam Ng01120412013-02-19 18:32:21 -08002030 "%s, %d, " MAC_ADDRESS_STR, __func__, i,
2031 MAC_ADDR_ARRAY(tmp->peerMac));
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002032 discovery_peer_cnt++;
2033 }
2034 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002035 return discovery_peer_cnt;
2036}
2037
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002038tANI_U16 wlan_hdd_tdlsConnectedPeers(hdd_adapter_t *pAdapter)
Lee Hoonkic1262f22013-01-24 21:59:00 -08002039{
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +05302040 hdd_context_t *pHddCtx = NULL;
2041
2042 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
2043 {
2044 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2045 FL("invalid pAdapter: %p"), pAdapter);
2046 return 0;
2047 }
2048 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002049
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302050 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302051 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2052 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002053 return 0;
c_hpothu7f63e882013-10-02 19:13:35 +05302054 }
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302055 EXIT();
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002056 return pHddCtx->connected_peer_count;
Lee Hoonkic1262f22013-01-24 21:59:00 -08002057}
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002058
Pradeep Reddy POTTETIe309c152015-02-06 13:21:07 +05302059hddTdlsPeer_t *wlan_hdd_tdls_get_connected_peer(hdd_adapter_t *pAdapter)
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302060{
2061 int i;
2062 struct list_head *head;
2063 struct list_head *pos;
2064 hddTdlsPeer_t *curr_peer = NULL;
2065 tdlsCtx_t *pHddTdlsCtx;
2066 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2067
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302068 ENTER();
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302069 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2070 {
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302071 return NULL;
2072 }
2073
2074 mutex_lock(&pHddCtx->tdls_lock);
2075 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2076 if (NULL == pHddTdlsCtx) {
2077 mutex_unlock(&pHddCtx->tdls_lock);
2078 return NULL;
2079 }
2080 for (i = 0; i < 256; i++) {
2081 head = &pHddTdlsCtx->peer_list[i];
2082
2083 list_for_each(pos, head) {
2084 curr_peer= list_entry (pos, hddTdlsPeer_t, node);
Pradeep Reddy POTTETI8a623132014-06-26 16:07:06 +05302085 if (curr_peer && (curr_peer->link_status == eTDLS_LINK_CONNECTED))
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302086 {
2087 mutex_unlock(&pHddCtx->tdls_lock);
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302088 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETI8a623132014-06-26 16:07:06 +05302089 "%s: " MAC_ADDRESS_STR " eTDLS_LINK_CONNECTED",
2090 __func__, MAC_ADDR_ARRAY(curr_peer->peerMac));
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302091 return curr_peer;
2092 }
2093 }
2094 }
2095 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302096
2097 EXIT();
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302098 return NULL;
2099}
2100
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002101int wlan_hdd_tdls_get_all_peers(hdd_adapter_t *pAdapter, char *buf, int buflen)
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002102{
2103 int i;
2104 int len, init_len;
Hoonki Lee387663d2013-02-05 18:08:43 -08002105 struct list_head *head;
2106 struct list_head *pos;
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002107 hddTdlsPeer_t *curr_peer;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002108 tdlsCtx_t *pHddTdlsCtx;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302109 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2110
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302111 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302112 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2113 {
c_hpothu7f63e882013-10-02 19:13:35 +05302114 return 0;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302115 }
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002116
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002117 init_len = buflen;
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002118 len = scnprintf(buf, buflen, "\n%-18s%-3s%-4s%-3s%-5s\n",
2119 "MAC", "Id", "cap", "up", "RSSI");
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002120 buf += len;
2121 buflen -= len;
2122 /* 1234567890123456789012345678901234567 */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002123 len = scnprintf(buf, buflen, "---------------------------------\n");
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002124 buf += len;
2125 buflen -= len;
2126
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05302127 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002128 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002129 if (NULL == pHddTdlsCtx) {
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302130 mutex_unlock(&pHddCtx->tdls_lock);
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002131 len = scnprintf(buf, buflen, "TDLS not enabled\n");
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002132 return len;
2133 }
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002134 for (i = 0; i < 256; i++) {
Hoonki Lee387663d2013-02-05 18:08:43 -08002135 head = &pHddTdlsCtx->peer_list[i];
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002136
Hoonki Lee387663d2013-02-05 18:08:43 -08002137 list_for_each(pos, head) {
2138 curr_peer= list_entry (pos, hddTdlsPeer_t, node);
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002139
Hoonki Lee387663d2013-02-05 18:08:43 -08002140 if (buflen < 32+1)
2141 break;
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002142 len = scnprintf(buf, buflen,
Chilam Ng01120412013-02-19 18:32:21 -08002143 MAC_ADDRESS_STR"%3d%4s%3s%5d\n",
2144 MAC_ADDR_ARRAY(curr_peer->peerMac),
Hoonki Lee387663d2013-02-05 18:08:43 -08002145 curr_peer->staId,
2146 (curr_peer->tdls_support == eTDLS_CAP_SUPPORTED) ? "Y":"N",
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002147 TDLS_IS_CONNECTED(curr_peer) ? "Y":"N",
Hoonki Lee387663d2013-02-05 18:08:43 -08002148 curr_peer->rssi);
2149 buf += len;
2150 buflen -= len;
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002151 }
2152 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302153 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302154
2155 EXIT();
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002156 return init_len-buflen;
2157}
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002158
2159void wlan_hdd_tdls_connection_callback(hdd_adapter_t *pAdapter)
2160{
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302161 tdlsCtx_t *pHddTdlsCtx;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302162 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala9d76a9b2013-02-28 15:38:37 -08002163
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302164 if ((NULL == pHddCtx))
c_hpothu7f63e882013-10-02 19:13:35 +05302165 {
Agarwal Ashishbf98caf2014-03-25 13:29:11 +05302166 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
2167 FL("pHddCtx or pHddTdlsCtx points to NULL"));
c_hpothu7f63e882013-10-02 19:13:35 +05302168 return;
2169 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302170
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05302171 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07002172
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302173 if (0 != wlan_hdd_sta_tdls_init(pAdapter))
2174 {
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302175 mutex_unlock(&pHddCtx->tdls_lock);
Hema Aparna Medicharla8bb6f782015-03-09 12:35:05 +05302176 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wlan_hdd_sta_tdls_init failed",__func__);
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302177 return;
2178 }
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302179
2180 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2181 if ((NULL == pHddTdlsCtx))
2182 {
Hema Aparna Medicharla8bb6f782015-03-09 12:35:05 +05302183 mutex_unlock(&pHddCtx->tdls_lock);
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302184 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
2185 FL("pHddCtx or pHddTdlsCtx points to NULL device mode = %d"), pAdapter->device_mode);
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302186 return;
2187 }
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302188 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002189 "%s, update %d discover %d", __func__,
2190 pHddTdlsCtx->threshold_config.tx_period_t,
2191 pHddTdlsCtx->threshold_config.discovery_period_t);
2192
Gopichand Nakkala9d76a9b2013-02-28 15:38:37 -08002193 if (eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode)
2194 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002195 wlan_hdd_tdls_peer_reset_discovery_processed(pHddTdlsCtx);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002196 pHddTdlsCtx->discovery_sent_cnt = 0;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002197 wlan_hdd_tdls_check_power_save_prohibited(pHddTdlsCtx->pAdapter);
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002198
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002199 wlan_hdd_tdls_timer_restart(pHddTdlsCtx->pAdapter,
2200 &pHddTdlsCtx->peerUpdateTimer,
2201 pHddTdlsCtx->threshold_config.tx_period_t);
Gopichand Nakkala9d76a9b2013-02-28 15:38:37 -08002202 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302203 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002204
2205}
2206
2207void wlan_hdd_tdls_disconnection_callback(hdd_adapter_t *pAdapter)
2208{
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002209 tdlsCtx_t *pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302210 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2211
Deepthi Gowribfd17132014-11-14 17:59:04 +05302212 if (NULL == pHddCtx)
c_hpothu7f63e882013-10-02 19:13:35 +05302213 {
2214 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Deepthi Gowribfd17132014-11-14 17:59:04 +05302215 FL(" pHddCtx points to NULL"));
c_hpothu7f63e882013-10-02 19:13:35 +05302216 return;
2217 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002218
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302219 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"%s", __func__);
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002220
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002221 if (NULL == pHddTdlsCtx)
2222 {
Hema Aparna Medicharla8bb6f782015-03-09 12:35:05 +05302223 mutex_unlock(&pHddCtx->tdls_lock);
c_hpothu7f63e882013-10-02 19:13:35 +05302224 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2225 FL("pHddTdlsCtx is NULL"));
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002226 return;
2227 }
Masti, Narayanraddide96b992015-01-08 13:00:58 +05302228
Pradeep Reddy POTTETI2d4d5c42015-03-03 14:34:19 +05302229 mutex_lock(&pHddCtx->tdls_lock);
Masti, Narayanraddide96b992015-01-08 13:00:58 +05302230
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002231 pHddTdlsCtx->discovery_sent_cnt = 0;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002232 wlan_hdd_tdls_check_power_save_prohibited(pHddTdlsCtx->pAdapter);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002233
Pradeep Reddy POTTETI2d4d5c42015-03-03 14:34:19 +05302234 wlan_hdd_tdls_exit(pAdapter, TRUE);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002235
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302236 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002237}
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002238
2239void wlan_hdd_tdls_mgmt_completion_callback(hdd_adapter_t *pAdapter, tANI_U32 statusCode)
2240{
2241 pAdapter->mgmtTxCompletionStatus = statusCode;
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302242 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2243 "%s: Mgmt TX Completion %d",__func__, statusCode);
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002244 complete(&pAdapter->tdls_mgmt_comp);
2245}
2246
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002247void wlan_hdd_tdls_increment_peer_count(hdd_adapter_t *pAdapter)
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002248{
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002249 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002250
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302251 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302252 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2253 {
c_hpothu7f63e882013-10-02 19:13:35 +05302254 return;
2255 }
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002256
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05302257 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302258
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002259 pHddCtx->connected_peer_count++;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002260 wlan_hdd_tdls_check_power_save_prohibited(pAdapter);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002261
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302262 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: %d",
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002263 __func__, pHddCtx->connected_peer_count);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302264
2265 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302266
2267 EXIT();
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002268}
2269
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002270void wlan_hdd_tdls_decrement_peer_count(hdd_adapter_t *pAdapter)
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002271{
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002272 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002273
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302274 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302275 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2276 {
c_hpothu7f63e882013-10-02 19:13:35 +05302277 return;
2278 }
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002279
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05302280 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302281
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002282 if (pHddCtx->connected_peer_count)
2283 pHddCtx->connected_peer_count--;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002284 wlan_hdd_tdls_check_power_save_prohibited(pAdapter);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002285
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302286 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: %d",
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002287 __func__, pHddCtx->connected_peer_count);
2288
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302289 mutex_unlock(&pHddCtx->tdls_lock);
2290
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302291 EXIT();
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002292}
2293
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002294void wlan_hdd_tdls_check_bmps(hdd_adapter_t *pAdapter)
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002295{
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +05302296
2297 tdlsCtx_t *pHddTdlsCtx = NULL;
2298 hdd_context_t *pHddCtx = NULL;
Hoonki Lee14621352013-04-16 17:51:19 -07002299 hddTdlsPeer_t *curr_peer;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002300
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +05302301 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
2302 {
2303 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2304 FL("invalid pAdapter: %p"), pAdapter);
2305 return;
2306 }
2307
2308 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2309 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2310
c_hpothu7f63e882013-10-02 19:13:35 +05302311 if ((NULL == pHddCtx) || (NULL == pHddTdlsCtx))
2312 {
Sushant Kaushik125ae692014-11-25 17:38:48 +05302313 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
c_hpothu7f63e882013-10-02 19:13:35 +05302314 FL(" pHddCtx or pHddTdlsCtx points to NULL"));
2315 return;
2316 }
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002317
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302318 curr_peer = wlan_hdd_tdls_is_progress(pHddCtx, NULL, 0, TRUE);
Hoonki Lee14621352013-04-16 17:51:19 -07002319 if (NULL != curr_peer)
2320 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302321 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee14621352013-04-16 17:51:19 -07002322 "%s: tdls in progress. Dont check for BMPS " MAC_ADDRESS_STR,
2323 __func__, MAC_ADDR_ARRAY (curr_peer->peerMac));
2324 return;
2325 }
2326
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002327 if ((TDLS_CTX_MAGIC != pHddCtx->tdls_scan_ctxt.magic) &&
2328 (0 == pHddCtx->connected_peer_count) &&
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002329 (0 == pHddTdlsCtx->discovery_sent_cnt))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002330 {
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002331 if (FALSE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pAdapter)))
2332 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302333 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002334 "%s: No TDLS peer connected/discovery sent. Enable BMPS",
2335 __func__);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002336 hdd_enable_bmps_imps(pHddCtx);
2337 }
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002338 }
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002339 else
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002340 {
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002341 if (TRUE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pAdapter)))
2342 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302343 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002344 "%s: TDLS peer connected. Disable BMPS", __func__);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002345 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
2346 }
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002347 }
2348 return;
2349}
2350
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002351u8 wlan_hdd_tdls_is_peer_progress(hdd_adapter_t *pAdapter, u8 *mac)
2352{
2353 hddTdlsPeer_t *curr_peer;
2354
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302355 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002356 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05302357 {
2358 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2359 "%s: curr_peer is NULL", __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002360 return 0;
c_hpothu7f63e882013-10-02 19:13:35 +05302361 }
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002362
2363 return (eTDLS_LINK_CONNECTING == curr_peer->link_status);
2364}
2365
Hoonki Leefb8df672013-04-10 18:20:34 -07002366/* return pointer to hddTdlsPeer_t if TDLS is ongoing. Otherwise return NULL.
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002367 * mac - if NULL check for all the peer list, otherwise, skip this mac when skip_self is TRUE
2368 * skip_self - if TRUE, skip this mac. otherwise, check all the peer list. if
2369 mac is NULL, this argument is ignored, and check for all the peer list.
2370 */
Anand N Sunkadb3ab97d2015-07-29 09:58:13 +05302371static hddTdlsPeer_t *wlan_hdd_tdls_find_progress_peer(hdd_adapter_t *pAdapter,
2372#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
2373 const u8 *mac,
2374#else
2375 u8 *mac,
2376#endif
2377 u8 skip_self)
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002378{
2379 int i;
2380 struct list_head *head;
2381 hddTdlsPeer_t *curr_peer;
2382 struct list_head *pos;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302383 tdlsCtx_t *pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302384
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302385 if (NULL == pHddTdlsCtx)
c_hpothu7f63e882013-10-02 19:13:35 +05302386 {
2387 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2388 FL("pHddTdlsCtx is NULL"));
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302389 return NULL;
c_hpothu7f63e882013-10-02 19:13:35 +05302390 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302391
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002392 for (i = 0; i < 256; i++) {
2393 head = &pHddTdlsCtx->peer_list[i];
2394 list_for_each(pos, head) {
2395 curr_peer = list_entry (pos, hddTdlsPeer_t, node);
2396 if (skip_self && mac && !memcmp(mac, curr_peer->peerMac, 6)) {
2397 continue;
2398 }
2399 else
2400 {
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08002401 if (eTDLS_LINK_CONNECTING == curr_peer->link_status)
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002402 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302403 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002404 "%s:" MAC_ADDRESS_STR " eTDLS_LINK_CONNECTING",
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07002405 __func__, MAC_ADDR_ARRAY(curr_peer->peerMac));
Hoonki Leefb8df672013-04-10 18:20:34 -07002406 return curr_peer;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002407 }
2408 }
2409 }
2410 }
Hoonki Leefb8df672013-04-10 18:20:34 -07002411 return NULL;
2412}
2413
Anand N Sunkadb3ab97d2015-07-29 09:58:13 +05302414hddTdlsPeer_t *wlan_hdd_tdls_is_progress(hdd_context_t *pHddCtx,
2415#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0))
2416 const u8 *mac,
2417#else
2418 u8 *mac,
2419#endif
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302420 u8 skip_self, tANI_BOOLEAN mutexLock)
Hoonki Leefb8df672013-04-10 18:20:34 -07002421{
2422 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
2423 hdd_adapter_t *pAdapter = NULL;
2424 tdlsCtx_t *pHddTdlsCtx = NULL;
2425 hddTdlsPeer_t *curr_peer= NULL;
2426 VOS_STATUS status = 0;
2427
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302428 if (mutexLock)
2429 {
2430 mutex_lock(&pHddCtx->tdls_lock);
2431 }
Hoonki Leefb8df672013-04-10 18:20:34 -07002432 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
2433 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
2434 {
2435 pAdapter = pAdapterNode->pAdapter;
2436
2437 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2438 if (NULL != pHddTdlsCtx)
2439 {
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302440 curr_peer = wlan_hdd_tdls_find_progress_peer(pAdapter, mac, skip_self);
Hoonki Leefb8df672013-04-10 18:20:34 -07002441 if (curr_peer)
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302442 {
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302443 if (mutexLock)
2444 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Leefb8df672013-04-10 18:20:34 -07002445 return curr_peer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302446 }
Hoonki Leefb8df672013-04-10 18:20:34 -07002447 }
2448 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
2449 pAdapterNode = pNext;
2450 }
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302451 if (mutexLock)
2452 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Leefb8df672013-04-10 18:20:34 -07002453 return NULL;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002454}
Hoonki Lee27511902013-03-14 18:19:06 -07002455
2456static void wlan_hdd_tdls_implicit_disable(tdlsCtx_t *pHddTdlsCtx)
2457{
Hoonki Lee27511902013-03-14 18:19:06 -07002458 wlan_hdd_tdls_timers_stop(pHddTdlsCtx);
Hoonki Lee27511902013-03-14 18:19:06 -07002459}
2460
2461static void wlan_hdd_tdls_implicit_enable(tdlsCtx_t *pHddTdlsCtx)
2462{
2463 wlan_hdd_tdls_peer_reset_discovery_processed(pHddTdlsCtx);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002464 pHddTdlsCtx->discovery_sent_cnt = 0;
Hoonki Lee27511902013-03-14 18:19:06 -07002465 wlan_tdd_tdls_reset_tx_rx(pHddTdlsCtx);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002466 wlan_hdd_tdls_check_power_save_prohibited(pHddTdlsCtx->pAdapter);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002467
Hoonki Lee27511902013-03-14 18:19:06 -07002468
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002469 wlan_hdd_tdls_timer_restart(pHddTdlsCtx->pAdapter,
2470 &pHddTdlsCtx->peerUpdateTimer,
2471 pHddTdlsCtx->threshold_config.tx_period_t);
Hoonki Lee27511902013-03-14 18:19:06 -07002472}
2473
Gopichand Nakkaladcbcf4e2013-03-23 14:32:39 -07002474void wlan_hdd_tdls_set_mode(hdd_context_t *pHddCtx,
2475 eTDLSSupportMode tdls_mode,
2476 v_BOOL_t bUpdateLast)
Hoonki Lee27511902013-03-14 18:19:06 -07002477{
2478 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
2479 VOS_STATUS status;
2480 hdd_adapter_t *pAdapter;
2481 tdlsCtx_t *pHddTdlsCtx;
2482
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302483 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2484 "%s mode %d", __func__, (int)tdls_mode);
c_hpothu7f63e882013-10-02 19:13:35 +05302485
2486 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2487 {
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302488 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302489 }
Hoonki Lee27511902013-03-14 18:19:06 -07002490
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05302491 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07002492
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002493 if (pHddCtx->tdls_mode == tdls_mode)
2494 {
Hema Aparna Medicharla8bb6f782015-03-09 12:35:05 +05302495 mutex_unlock(&pHddCtx->tdls_lock);
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302496 hddLog(VOS_TRACE_LEVEL_INFO, "%s already in mode %d", __func__,
2497 (int)tdls_mode);
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002498 return;
2499 }
2500
Hoonki Lee27511902013-03-14 18:19:06 -07002501 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
2502
2503 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
2504 {
2505 pAdapter = pAdapterNode->pAdapter;
Hoonki Leea6d49be2013-04-05 09:43:25 -07002506 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2507 if (NULL != pHddTdlsCtx)
Hoonki Lee27511902013-03-14 18:19:06 -07002508 {
Hoonki Leea6d49be2013-04-05 09:43:25 -07002509 if(eTDLS_SUPPORT_ENABLED == tdls_mode)
2510 wlan_hdd_tdls_implicit_enable(pHddTdlsCtx);
2511 else if((eTDLS_SUPPORT_DISABLED == tdls_mode) ||
2512 (eTDLS_SUPPORT_EXPLICIT_TRIGGER_ONLY == tdls_mode))
2513 wlan_hdd_tdls_implicit_disable(pHddTdlsCtx);
Hoonki Lee27511902013-03-14 18:19:06 -07002514 }
2515 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
2516 pAdapterNode = pNext;
2517 }
Gopichand Nakkaladcbcf4e2013-03-23 14:32:39 -07002518 if(bUpdateLast)
2519 {
2520 pHddCtx->tdls_mode_last = tdls_mode;
2521 }
2522 else
2523 {
2524 pHddCtx->tdls_mode_last = pHddCtx->tdls_mode;
2525 }
Hoonki Lee27511902013-03-14 18:19:06 -07002526 pHddCtx->tdls_mode = tdls_mode;
Gopichand Nakkaladcbcf4e2013-03-23 14:32:39 -07002527
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302528 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302529
Hoonki Lee27511902013-03-14 18:19:06 -07002530}
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002531
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302532static
2533void wlan_hdd_tdls_implicit_send_discovery_request(tdlsCtx_t * pHddTdlsCtx)
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002534{
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302535 hdd_context_t *pHddCtx = NULL;
2536 hddTdlsPeer_t *curr_peer = NULL, *temp_peer = NULL;
Hoonki Leed37cbb32013-04-20 00:31:14 -07002537
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302538 ENTER();
Hoonki Leed37cbb32013-04-20 00:31:14 -07002539 if (NULL == pHddTdlsCtx)
c_hpothu7f63e882013-10-02 19:13:35 +05302540 {
2541 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2542 FL("pHddTdlsCtx is NULL"));
Hoonki Leed37cbb32013-04-20 00:31:14 -07002543 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302544 }
Hoonki Leed37cbb32013-04-20 00:31:14 -07002545
Hoonki Leed37cbb32013-04-20 00:31:14 -07002546 pHddCtx = WLAN_HDD_GET_CTX(pHddTdlsCtx->pAdapter);
Hoonki Leefb8df672013-04-10 18:20:34 -07002547
c_hpothu7f63e882013-10-02 19:13:35 +05302548 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2549 {
Hoonki Leefb8df672013-04-10 18:20:34 -07002550 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302551 }
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002552
Hoonki Leed37cbb32013-04-20 00:31:14 -07002553 curr_peer = pHddTdlsCtx->curr_candidate;
Hoonki Leed37cbb32013-04-20 00:31:14 -07002554 if (NULL == curr_peer)
c_hpothu7f63e882013-10-02 19:13:35 +05302555 {
2556 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2557 FL("curr_peer is NULL"));
2558
Hoonki Leed37cbb32013-04-20 00:31:14 -07002559 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302560 }
Hoonki Leed37cbb32013-04-20 00:31:14 -07002561
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002562 if (TRUE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pHddTdlsCtx->pAdapter)))
2563 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302564 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2565 "%s: Disable BMPS", __func__);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002566 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
2567 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002568
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302569 /* This function is called in mutex_lock */
2570 temp_peer = wlan_hdd_tdls_is_progress(pHddCtx, NULL, 0, FALSE);
Hoonki Leefb8df672013-04-10 18:20:34 -07002571 if (NULL != temp_peer)
2572 {
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302573 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2574 "%s: " MAC_ADDRESS_STR " ongoing. pre_setup ignored",
2575 __func__, MAC_ADDR_ARRAY(temp_peer->peerMac));
Hoonki Leed37cbb32013-04-20 00:31:14 -07002576 goto done;
Hoonki Leefb8df672013-04-10 18:20:34 -07002577 }
2578
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002579 if (eTDLS_CAP_UNKNOWN != curr_peer->tdls_support)
Atul Mittal115287b2014-07-08 13:26:33 +05302580 wlan_hdd_tdls_set_peer_link_status(curr_peer,
2581 eTDLS_LINK_DISCOVERING,
2582 eTDLS_LINK_SUCCESS);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002583
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302584 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2585 "%s: Implicit TDLS, Send Discovery request event", __func__);
Hoonki Leed37cbb32013-04-20 00:31:14 -07002586
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302587 cfg80211_tdls_oper_request(pHddTdlsCtx->pAdapter->dev,
2588 curr_peer->peerMac,
2589 NL80211_TDLS_DISCOVERY_REQ,
2590 FALSE,
2591 GFP_KERNEL);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002592 pHddTdlsCtx->discovery_sent_cnt++;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302593
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002594 wlan_hdd_tdls_check_power_save_prohibited(pHddTdlsCtx->pAdapter);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302595
Pradeep Reddy POTTETI219ced32014-11-14 16:33:57 +05302596 wlan_hdd_tdls_timer_restart(pHddTdlsCtx->pAdapter,
2597 &pHddTdlsCtx->peerDiscoveryTimeoutTimer,
2598 pHddTdlsCtx->threshold_config.tx_period_t - TDLS_DISCOVERY_TIMEOUT_BEFORE_UPDATE);
2599
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302600 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2601 "%s: discovery count %u timeout %u msec",
2602 __func__, pHddTdlsCtx->discovery_sent_cnt,
2603 pHddTdlsCtx->threshold_config.tx_period_t - TDLS_DISCOVERY_TIMEOUT_BEFORE_UPDATE);
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002604
Hoonki Leed37cbb32013-04-20 00:31:14 -07002605done:
2606 pHddTdlsCtx->curr_candidate = NULL;
2607 pHddTdlsCtx->magic = 0;
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302608 EXIT();
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002609 return;
2610}
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002611
2612tANI_U32 wlan_hdd_tdls_discovery_sent_cnt(hdd_context_t *pHddCtx)
2613{
2614 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
2615 hdd_adapter_t *pAdapter = NULL;
2616 tdlsCtx_t *pHddTdlsCtx = NULL;
2617 VOS_STATUS status = 0;
2618 tANI_U32 count = 0;
2619
2620 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
2621 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
2622 {
2623 pAdapter = pAdapterNode->pAdapter;
2624
Hoonki Leea6d49be2013-04-05 09:43:25 -07002625 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2626 if (NULL != pHddTdlsCtx)
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002627 {
Hoonki Leea6d49be2013-04-05 09:43:25 -07002628 count = count + pHddTdlsCtx->discovery_sent_cnt;
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002629 }
2630 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
2631 pAdapterNode = pNext;
2632 }
2633 return count;
2634}
2635
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002636void wlan_hdd_tdls_check_power_save_prohibited(hdd_adapter_t *pAdapter)
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002637{
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +05302638 tdlsCtx_t *pHddTdlsCtx = NULL;
2639 hdd_context_t *pHddCtx = NULL;
Chandrasekaran, Manishekar41b8e1f2015-03-10 13:30:28 +05302640
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +05302641
2642 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
2643 {
2644 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2645 FL("invalid pAdapter: %p"), pAdapter);
Chandrasekaran, Manishekar41b8e1f2015-03-10 13:30:28 +05302646 return;
2647 }
2648
2649 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2650 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002651
2652 if ((NULL == pHddTdlsCtx) || (NULL == pHddCtx))
c_hpothu7f63e882013-10-02 19:13:35 +05302653 {
2654 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2655 FL(" pHddCtx or pHddTdlsCtx points to NULL"));
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002656 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302657 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002658
2659 if ((0 == pHddCtx->connected_peer_count) &&
2660 (0 == wlan_hdd_tdls_discovery_sent_cnt(pHddCtx)))
2661 {
2662 sme_SetTdlsPowerSaveProhibited(WLAN_HDD_GET_HAL_CTX(pHddTdlsCtx->pAdapter), 0);
2663 return;
2664 }
2665 sme_SetTdlsPowerSaveProhibited(WLAN_HDD_GET_HAL_CTX(pHddTdlsCtx->pAdapter), 1);
2666 return;
2667}
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002668
2669void wlan_hdd_tdls_free_scan_request (tdls_scan_context_t *tdls_scan_ctx)
2670{
2671 if (NULL == tdls_scan_ctx)
c_hpothu7f63e882013-10-02 19:13:35 +05302672 {
2673 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2674 FL("tdls_scan_ctx is NULL"));
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002675 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302676 }
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002677
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002678 tdls_scan_ctx->attempt = 0;
Hoonki Leefb8df672013-04-10 18:20:34 -07002679 tdls_scan_ctx->reject = 0;
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002680 tdls_scan_ctx->magic = 0;
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002681 tdls_scan_ctx->scan_request = NULL;
2682 return;
2683}
2684
2685int wlan_hdd_tdls_copy_scan_context(hdd_context_t *pHddCtx,
2686 struct wiphy *wiphy,
2687#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2688 struct net_device *dev,
2689#endif
2690 struct cfg80211_scan_request *request)
2691{
2692 tdls_scan_context_t *scan_ctx;
2693
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302694 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302695 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2696 {
c_hpothu7f63e882013-10-02 19:13:35 +05302697 return 0;
2698 }
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002699
2700 scan_ctx = &pHddCtx->tdls_scan_ctxt;
2701
2702 scan_ctx->wiphy = wiphy;
2703#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2704 scan_ctx->dev = dev;
2705#endif
2706
2707 scan_ctx->scan_request = request;
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302708
2709 EXIT();
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002710 return 0;
2711}
2712
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002713static void wlan_hdd_tdls_scan_init_work(hdd_context_t *pHddCtx,
2714 struct wiphy *wiphy,
2715#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2716 struct net_device *dev,
2717#endif
2718 struct cfg80211_scan_request *request,
2719 unsigned long delay)
2720{
2721 if (TDLS_CTX_MAGIC != pHddCtx->tdls_scan_ctxt.magic)
2722 {
2723#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2724 wlan_hdd_tdls_copy_scan_context(pHddCtx, wiphy, dev, request);
2725#else
2726 wlan_hdd_tdls_copy_scan_context(pHddCtx, wiphy, request);
2727#endif
2728 pHddCtx->tdls_scan_ctxt.attempt = 0;
2729 pHddCtx->tdls_scan_ctxt.magic = TDLS_CTX_MAGIC;
2730 }
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002731 schedule_delayed_work(&pHddCtx->tdls_scan_ctxt.tdls_scan_work, delay);
2732}
2733
2734/* return negative = caller should stop and return error code immediately
2735 return 0 = caller should stop and return success immediately
2736 return 1 = caller can continue to scan
2737 */
2738int wlan_hdd_tdls_scan_callback (hdd_adapter_t *pAdapter,
2739 struct wiphy *wiphy,
2740#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2741 struct net_device *dev,
2742#endif
2743 struct cfg80211_scan_request *request)
2744{
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002745 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2746 u16 connectedTdlsPeers;
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302747 hddTdlsPeer_t *curr_peer, *connected_peer;
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002748 unsigned long delay;
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302749 hdd_config_t *cfg_param = pHddCtx->cfg_ini;
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002750
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302751 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302752 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2753 {
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002754 return 0;
c_hpothu7f63e882013-10-02 19:13:35 +05302755 }
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002756
2757 /* if tdls is not enabled, then continue scan */
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +05302758 if ((eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode) ||
2759 (pHddCtx->is_tdls_btc_enabled == FALSE))
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002760 return 1;
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302761 curr_peer = wlan_hdd_tdls_is_progress(pHddCtx, NULL, 0, TRUE);
Hoonki Leefb8df672013-04-10 18:20:34 -07002762 if (NULL != curr_peer)
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002763 {
Hoonki Leefb8df672013-04-10 18:20:34 -07002764 if (pHddCtx->tdls_scan_ctxt.reject++ >= TDLS_MAX_SCAN_REJECT)
2765 {
2766 pHddCtx->tdls_scan_ctxt.reject = 0;
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302767 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Leefb8df672013-04-10 18:20:34 -07002768 "%s: " MAC_ADDRESS_STR ". scan rejected %d. force it to idle",
2769 __func__, MAC_ADDR_ARRAY (curr_peer->peerMac), pHddCtx->tdls_scan_ctxt.reject);
2770
Atul Mittal115287b2014-07-08 13:26:33 +05302771 wlan_hdd_tdls_set_peer_link_status (curr_peer,
2772 eTDLS_LINK_IDLE,
2773 eTDLS_LINK_UNSPECIFIED);
Hoonki Leefb8df672013-04-10 18:20:34 -07002774 return 1;
2775 }
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302776 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Leefb8df672013-04-10 18:20:34 -07002777 "%s: tdls in progress. scan rejected %d",
2778 __func__, pHddCtx->tdls_scan_ctxt.reject);
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002779 return -EBUSY;
2780 }
2781
2782 /* tdls teardown is ongoing */
2783 if (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode)
2784 {
2785 connectedTdlsPeers = wlan_hdd_tdlsConnectedPeers(pAdapter);
2786 if (connectedTdlsPeers && (pHddCtx->tdls_scan_ctxt.attempt < TDLS_MAX_SCAN_SCHEDULE))
2787 {
2788 delay = (unsigned long)(TDLS_DELAY_SCAN_PER_CONNECTION*connectedTdlsPeers);
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302789 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002790 "%s: tdls disabled, but still connected_peers %d attempt %d. schedule scan %lu msec",
2791 __func__, connectedTdlsPeers, pHddCtx->tdls_scan_ctxt.attempt, delay);
2792
2793 wlan_hdd_tdls_scan_init_work (pHddCtx, wiphy,
2794#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2795 dev,
2796#endif
2797 request,
2798 msecs_to_jiffies(delay));
2799 /* scan should not continue */
2800 return 0;
2801 }
2802 /* no connected peer or max retry reached, scan continue */
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302803 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002804 "%s: tdls disabled. connected_peers %d attempt %d. scan allowed",
2805 __func__, connectedTdlsPeers, pHddCtx->tdls_scan_ctxt.attempt);
2806 return 1;
2807 }
Agarwal Ashishef54a182014-12-16 15:07:31 +05302808
2809 /* if fEnableTDLSScan flag is 1 ; driverwill allow scan even if
2810 * peer station is not buffer STA capable
2811 *
2812 * RX: If there is any RX activity, device will lose RX packets,
2813 * as peer will not be aware that device is off channel.
2814 * TX: TX is stopped whenever device initiate scan.
2815 */
2816 if (pHddCtx->cfg_ini->fEnableTDLSScan == 1)
2817 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302818 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Agarwal Ashishef54a182014-12-16 15:07:31 +05302819 FL("Allow SCAN in all TDLS cases"));
2820 return 1;
2821 }
2822
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002823 /* while tdls is up, first time scan */
2824 else if (eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode ||
2825 eTDLS_SUPPORT_EXPLICIT_TRIGGER_ONLY == pHddCtx->tdls_mode)
2826 {
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002827 connectedTdlsPeers = wlan_hdd_tdlsConnectedPeers(pAdapter);
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302828
2829 /* check the TDLS link and Scan coexistance Capability */
2830 if ( (TRUE == pHddCtx->cfg_ini->fEnableTDLSScanCoexSupport) &&
2831 (TRUE == sme_IsFeatureSupportedByFW(TDLS_SCAN_COEXISTENCE)) &&
2832 (connectedTdlsPeers == 1) )
2833 {
2834 /* get connected peer information */
Pradeep Reddy POTTETIe309c152015-02-06 13:21:07 +05302835 connected_peer = wlan_hdd_tdls_get_connected_peer(pAdapter);
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302836 if (NULL == connected_peer) {
2837 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
2838 "%s: Invalid connected_peer, Continue Scanning", __func__);
2839 /* scan should continue */
2840 return 1;
2841 }
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302842 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302843 ("%s: TDLS Scan Co-exist supported connectedTdlsPeers =%d buffersta =%d"),
2844 __func__,connectedTdlsPeers,connected_peer->isBufSta);
2845
2846 if (connected_peer->isBufSta)
2847 {
2848 pHddCtx->isTdlsScanCoexistence = TRUE;
2849 if ((cfg_param->dynSplitscan) && (!pHddCtx->issplitscan_enabled))
2850 {
2851 pHddCtx->issplitscan_enabled = TRUE;
2852 sme_enable_disable_split_scan(
2853 WLAN_HDD_GET_HAL_CTX(pAdapter),
2854 cfg_param->nNumStaChanCombinedConc,
2855 cfg_param->nNumP2PChanCombinedConc);
2856 }
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302857 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302858 ("%s:%d TDLS Scan Co-exist supported splitscan_enabled =%d "),
2859 __func__, __LINE__, pHddCtx->issplitscan_enabled);
2860 return 1;
2861 }
2862
2863 }
2864 else
2865 {
2866 /* Throughput Monitor shall disable the split scan when
2867 * TDLS scan coexistance is disabled.At this point of time
2868 * since TDLS scan coexistance is not meeting the criteria
2869 * to be operational, explicitly make it false to enable
2870 * throughput monitor takes the control of split scan.
2871 */
2872 pHddCtx->isTdlsScanCoexistence = FALSE;
2873 }
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302874 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302875 ("%s: TDLS Scan Co-exist not supported connectedTdlsPeers =%d"
2876 " TDLSScanCoexSupport param =%d TDLS_SCAN_COEXISTENCE =%d"),
2877 __func__, connectedTdlsPeers,
2878 pHddCtx->cfg_ini->fEnableTDLSScanCoexSupport,
2879 sme_IsFeatureSupportedByFW(TDLS_SCAN_COEXISTENCE));
2880
Atul Mittal5803b342014-09-04 15:31:19 +05302881 /* disable implicit trigger logic & tdls operatoin */
2882 wlan_hdd_tdls_set_mode(pHddCtx, eTDLS_SUPPORT_DISABLED, FALSE);
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302883 /* fall back to the implementation of teardown the peers on the scan
2884 * when the number of connected peers are more than one. TDLS Scan
2885 * coexistance feature is exercised only when a single peer is
2886 * connected and the DUT shall not advertize the Buffer Sta capability,
2887 * so that the peer shall not go to the TDLS power save
2888 */
2889
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002890 if (connectedTdlsPeers)
2891 {
2892 tANI_U8 staIdx;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002893 hddTdlsPeer_t *curr_peer;
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002894
2895 for (staIdx = 0; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
2896 {
2897 if (pHddCtx->tdlsConnInfo[staIdx].staId)
2898 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302899 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2900 ("%s: indicate TDLS teardown (staId %d)"), __func__, pHddCtx->tdlsConnInfo[staIdx].staId) ;
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002901
2902#ifdef CONFIG_TDLS_IMPLICIT
Hoonki Leea6d49be2013-04-05 09:43:25 -07002903 curr_peer = wlan_hdd_tdls_find_all_peer(pHddCtx, pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes);
2904 if(curr_peer)
2905 wlan_hdd_tdls_indicate_teardown(curr_peer->pHddTdlsCtx->pAdapter, curr_peer, eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON);
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002906#endif
2907 }
2908 }
2909 /* schedule scan */
2910 delay = (unsigned long)(TDLS_DELAY_SCAN_PER_CONNECTION*connectedTdlsPeers);
2911
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302912 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002913 "%s: tdls enabled (mode %d), connected_peers %d. schedule scan %lu msec",
2914 __func__, pHddCtx->tdls_mode, wlan_hdd_tdlsConnectedPeers(pAdapter),
2915 delay);
2916
2917 wlan_hdd_tdls_scan_init_work (pHddCtx, wiphy,
2918#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2919 dev,
2920#endif
2921 request,
2922 msecs_to_jiffies(delay));
2923 /* scan should not continue */
2924 return 0;
2925 }
2926 /* no connected peer, scan continue */
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302927 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002928 "%s: tdls_mode %d, and no tdls connection. scan allowed",
2929 __func__, pHddCtx->tdls_mode);
2930 }
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302931 EXIT();
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002932 return 1;
2933}
2934
2935void wlan_hdd_tdls_scan_done_callback(hdd_adapter_t *pAdapter)
2936{
2937 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002938
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302939 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302940 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2941 {
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002942 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302943 }
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002944
Pradeep Reddy POTTETIc7822df2015-02-19 20:15:41 +05302945 /* if tdls is not enabled or BtCoex is on then don't revert tdls mode */
2946 if ((eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode) ||
Chandrasekaran, Manishekar0de84dc2015-03-10 15:12:34 +05302947 (pHddCtx->is_tdls_btc_enabled == FALSE)) {
2948 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to revert: Mode=%d, BTC enabled=%d"),
2949 pHddCtx->tdls_mode, pHddCtx->is_tdls_btc_enabled);
Pradeep Reddy POTTETIc7822df2015-02-19 20:15:41 +05302950 return;
Chandrasekaran, Manishekar0de84dc2015-03-10 15:12:34 +05302951 }
Sunil Dutt41de4e22013-11-14 18:09:02 +05302952
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002953 /* free allocated memory at scan time */
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002954 wlan_hdd_tdls_free_scan_request (&pHddCtx->tdls_scan_ctxt);
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002955
2956 /* if tdls was enabled before scan, re-enable tdls mode */
2957 if(eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode_last ||
2958 eTDLS_SUPPORT_EXPLICIT_TRIGGER_ONLY == pHddCtx->tdls_mode_last)
2959 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302960 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002961 ("%s: revert tdls mode %d"), __func__, pHddCtx->tdls_mode_last);
2962
Gopichand Nakkaladcbcf4e2013-03-23 14:32:39 -07002963 wlan_hdd_tdls_set_mode(pHddCtx, pHddCtx->tdls_mode_last, FALSE);
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002964 }
2965 wlan_hdd_tdls_check_bmps(pAdapter);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302966
2967 EXIT();
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002968}
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002969
2970void wlan_hdd_tdls_timer_restart(hdd_adapter_t *pAdapter,
2971 vos_timer_t *timer,
2972 v_U32_t expirationTime)
2973{
2974 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
2975
2976 if (NULL == pHddStaCtx)
c_hpothu7f63e882013-10-02 19:13:35 +05302977 {
2978 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2979 FL("pHddStaCtx is NULL"));
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002980 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302981 }
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002982
2983 /* Check whether driver load unload is in progress */
2984 if(vos_is_load_unload_in_progress( VOS_MODULE_ID_VOSS, NULL))
2985 {
2986 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
2987 "%s: Driver load/unload is in progress.", __func__);
2988 return;
2989 }
2990
2991 if (hdd_connIsConnected(pHddStaCtx))
2992 {
2993 vos_timer_stop(timer);
2994 vos_timer_start(timer, expirationTime);
2995 }
2996}
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002997void wlan_hdd_tdls_indicate_teardown(hdd_adapter_t *pAdapter,
2998 hddTdlsPeer_t *curr_peer,
2999 tANI_U16 reason)
3000{
Pradeep Reddy POTTETI8a623132014-06-26 16:07:06 +05303001 hdd_context_t *pHddCtx;
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05303002
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +05303003 if ((NULL == pAdapter || WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic) ||
3004 (NULL == curr_peer))
c_hpothu7f63e882013-10-02 19:13:35 +05303005 {
3006 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3007 FL("parameters passed are invalid"));
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003008 return;
c_hpothu7f63e882013-10-02 19:13:35 +05303009 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003010
Pradeep Reddy POTTETI8a623132014-06-26 16:07:06 +05303011 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3012
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003013 if (eTDLS_LINK_CONNECTED != curr_peer->link_status)
3014 return;
3015
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05303016 /* Throughput Monitor shall disable the split scan when
3017 * TDLS scan coexistance is disabled.At this point of time
3018 * since TDLS scan coexistance is not meeting the criteria
3019 * to be operational, explicitly make it false to enable
3020 * throughput monitor takes the control of split scan.
3021 */
Pradeep Reddy POTTETI8a623132014-06-26 16:07:06 +05303022 if (pHddCtx && (pHddCtx->isTdlsScanCoexistence == TRUE))
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05303023 {
3024 pHddCtx->isTdlsScanCoexistence = FALSE;
3025 }
3026
Atul Mittal115287b2014-07-08 13:26:33 +05303027 wlan_hdd_tdls_set_peer_link_status(curr_peer,
3028 eTDLS_LINK_TEARING,
Atul Mittal271a7652014-09-12 13:18:22 +05303029 eTDLS_LINK_UNSPECIFIED);
Agarwal Ashisha7ef41d2015-06-25 18:00:26 +05303030 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3031 FL("Setting NL80211_TDLS_TEARDOWN, reason %d"), reason);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07003032 cfg80211_tdls_oper_request(pAdapter->dev,
3033 curr_peer->peerMac,
3034 NL80211_TDLS_TEARDOWN,
3035 reason,
3036 GFP_KERNEL);
3037}
Atul Mittal115287b2014-07-08 13:26:33 +05303038
3039
3040/*EXT TDLS*/
3041int wlan_hdd_set_callback(hddTdlsPeer_t *curr_peer,
3042 cfg80211_exttdls_callback callback)
3043{
3044
3045 hdd_context_t *pHddCtx;
3046 hdd_adapter_t *pAdapter;
3047
3048 if (!curr_peer) return -1;
3049
3050 pAdapter = curr_peer->pHddTdlsCtx->pAdapter;
3051 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
3052 if ((NULL == pHddCtx)) return -1;
3053
3054 mutex_lock(&pHddCtx->tdls_lock);
3055
3056 curr_peer->state_change_notification = callback;
3057
3058 mutex_unlock(&pHddCtx->tdls_lock);
3059 return 0;
3060
3061
3062}
3063
3064void wlan_hdd_tdls_get_wifi_hal_state(hddTdlsPeer_t *curr_peer,
3065 tANI_S32 *state,
3066 tANI_S32 *reason)
3067{
3068 *reason = curr_peer->reason;
3069
3070 switch(curr_peer->link_status)
3071 {
3072 case eTDLS_LINK_IDLE:
Atul Mittal115287b2014-07-08 13:26:33 +05303073 case eTDLS_LINK_DISCOVERED:
3074 *state = WIFI_TDLS_ENABLED;
3075 break;
Atul Mittalad630e42014-10-07 19:19:14 +05303076 case eTDLS_LINK_DISCOVERING:
Atul Mittal115287b2014-07-08 13:26:33 +05303077 case eTDLS_LINK_CONNECTING:
3078 *state = WIFI_TDLS_TRYING;
3079 break;
3080 case eTDLS_LINK_CONNECTED:
Pradeep Reddy POTTETIf3148e82015-04-16 12:10:33 +05303081 if (TRUE == curr_peer->isOffChannelEstablished)
Pradeep Reddy POTTETI16d83332015-03-26 18:28:13 +05303082 {
3083 *state = WIFI_TDLS_ESTABLISHED_OFF_CHANNEL;
3084 }
3085 else
3086 {
3087 *state = WIFI_TDLS_ESTABLISHED;
3088 }
Atul Mittal115287b2014-07-08 13:26:33 +05303089 break;
3090 case eTDLS_LINK_TEARING:
3091 *state = WIFI_TDLS_DROPPED;
3092 break;
3093 }
3094
3095}
3096
3097int wlan_hdd_tdls_get_status(hdd_adapter_t *pAdapter,
3098 tANI_U8* mac,
3099 tANI_S32 *state,
3100 tANI_S32 *reason)
3101{
3102
3103 hddTdlsPeer_t *curr_peer;
Atul Mittala75fced2014-10-06 13:59:07 +05303104 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Atul Mittal115287b2014-07-08 13:26:33 +05303105 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
3106 if (curr_peer == NULL)
3107 {
Atul Mittala75fced2014-10-06 13:59:07 +05303108 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Atul Mittal115287b2014-07-08 13:26:33 +05303109 FL("curr_peer is NULL"));
Atul Mittal115287b2014-07-08 13:26:33 +05303110
Atul Mittala75fced2014-10-06 13:59:07 +05303111 *state = WIFI_TDLS_DISABLED;
3112 *reason = eTDLS_LINK_UNSPECIFIED;
3113 }
3114 else
3115 {
3116 if (pHddCtx->cfg_ini->fTDLSExternalControl &&
3117 (FALSE == curr_peer->isForcedPeer))
3118 {
3119 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3120 FL("curr_peer is not Forced"));
3121 *state = WIFI_TDLS_DISABLED;
3122 *reason = eTDLS_LINK_UNSPECIFIED;
3123 }
3124 else
3125 {
3126 wlan_hdd_tdls_get_wifi_hal_state(curr_peer, state, reason);
3127 }
3128 }
Atul Mittal115287b2014-07-08 13:26:33 +05303129 return (0);
3130}
3131
Agarwal Ashishef54a182014-12-16 15:07:31 +05303132int hdd_set_tdls_scan_type(hdd_adapter_t *pAdapter,
3133 tANI_U8 *ptr)
3134{
3135 int tdls_scan_type;
Hema Aparna Medicharla26b98042015-01-21 15:02:01 +05303136 hdd_context_t *pHddCtx;
Agarwal Ashishef54a182014-12-16 15:07:31 +05303137 if (NULL == pAdapter)
3138 {
3139 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3140 "%s: pAdapter is NULL", __func__);
3141 return -EINVAL;
3142 }
Hema Aparna Medicharla26b98042015-01-21 15:02:01 +05303143 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Agarwal Ashishef54a182014-12-16 15:07:31 +05303144 tdls_scan_type = ptr[9] - '0';
3145
3146 if (tdls_scan_type <= 2)
3147 {
3148 pHddCtx->cfg_ini->fEnableTDLSScan = tdls_scan_type;
3149 return 0;
3150 }
3151 else
3152 {
3153 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3154 " Wrong value is given for tdls_scan_type "
3155 " Making fEnableTDLSScan as 0 ");
3156 pHddCtx->cfg_ini->fEnableTDLSScan = 0;
3157 return -EINVAL;
3158 }
3159}
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +05303160int wlan_hdd_validate_tdls_context(hdd_context_t *pHddCtx,
3161 tdlsCtx_t *pHddTdlsCtx)
3162{
3163 VOS_STATUS status;
3164 int found = 0;
3165 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
3166 hdd_adapter_t *pAdapter;
Agarwal Ashishef54a182014-12-16 15:07:31 +05303167
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +05303168 if (NULL == pHddTdlsCtx)
3169 {
3170 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3171 FL("TDLS context is NULL"));
3172 return -EINVAL;
3173 }
3174 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
3175 while (NULL != pAdapterNode && VOS_STATUS_SUCCESS == status)
3176 {
3177 pAdapter = pAdapterNode->pAdapter;
3178 if (NULL != pAdapter)
3179 {
3180 if (pHddTdlsCtx == pAdapter->sessionCtx.station.pHddTdlsCtx &&
3181 (NULL != pHddTdlsCtx->pAdapter) &&
3182 (WLAN_HDD_ADAPTER_MAGIC == pHddTdlsCtx->pAdapter->magic))
3183 {
3184 found = 1;
3185 break;
3186 }
3187 }
3188 status = hdd_get_next_adapter (pHddCtx, pAdapterNode, &pNext);
3189 pAdapterNode = pNext;
3190 }
3191 if (found == 1)
3192 {
3193 return 0;
3194 }
3195 else
3196 {
3197 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3198 FL("TDLS context doesnot belongs to valid adapter"));
3199 return -EINVAL;
3200 }
3201}
Atul Mittal115287b2014-07-08 13:26:33 +05303202/*EXT TDLS*/
3203