blob: 0ac63834e5d6bbea008fb1b95867d9eb562d6a71 [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"
Mahesh A Saptasagar8b231b32014-08-11 11:58:15 +053046#include "vos_sched.h"
Chilam NG571c65a2013-01-19 12:27:36 +053047
Gopichand Nakkala4327a152013-03-04 23:22:42 -080048static tANI_S32 wlan_hdd_get_tdls_discovery_peer_cnt(tdlsCtx_t *pHddTdlsCtx);
49static tANI_S32 wlan_hdd_tdls_peer_reset_discovery_processed(tdlsCtx_t *pHddTdlsCtx);
50static void wlan_hdd_tdls_timers_destroy(tdlsCtx_t *pHddTdlsCtx);
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +053051static void wlan_hdd_tdls_peer_timers_destroy(tdlsCtx_t *pHddTdlsCtx);
Sunil Dutt41de4e22013-11-14 18:09:02 +053052int wpa_tdls_is_allowed_force_peer(tdlsCtx_t *pHddTdlsCtx, u8 *mac);
Hoonki Leed37cbb32013-04-20 00:31:14 -070053#ifdef CONFIG_TDLS_IMPLICIT
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +053054static void wlan_hdd_tdls_implicit_send_discovery_request(tdlsCtx_t *pHddTdlsCtx);
Hoonki Leed37cbb32013-04-20 00:31:14 -070055#endif
Chilam NG571c65a2013-01-19 12:27:36 +053056
Hoonki Lee387663d2013-02-05 18:08:43 -080057static u8 wlan_hdd_tdls_hash_key (u8 *mac)
Hoonki Leef63df0d2013-01-16 19:29:14 -080058{
59 int i;
Hoonki Lee387663d2013-02-05 18:08:43 -080060 u8 key = 0;
61
62 for (i = 0; i < 6; i++)
63 key ^= mac[i];
64
65 return key;
66}
67
Masti, Narayanraddifdde4d02015-04-16 14:41:51 +053068/**
69 * wlan_hdd_tdls_disable_offchan_and_teardown_links - Disable offchannel
70 * and teardown TDLS links
71 * @hddCtx : pointer to hdd context
72 *
73 * Return: None
74 */
75void wlan_hdd_tdls_disable_offchan_and_teardown_links(hdd_context_t *hddctx)
76{
77 u16 connected_tdls_peers = 0;
78 u8 staidx;
79 hddTdlsPeer_t *curr_peer = NULL;
80 hdd_adapter_t *adapter = NULL;
81
82 if (eTDLS_SUPPORT_NOT_ENABLED == hddctx->tdls_mode) {
83 hddLog(LOG1, FL("TDLS mode is disabled OR not enabled in FW"));
84 return ;
85 }
86
87 adapter = hdd_get_adapter(hddctx, WLAN_HDD_INFRA_STATION);
88
89 if (adapter == NULL) {
90 hddLog(LOGE, FL("Station Adapter Not Found"));
91 return;
92 }
93
94 connected_tdls_peers = wlan_hdd_tdlsConnectedPeers(adapter);
95
96 if (!connected_tdls_peers)
97 return ;
98
99 /* TDLS is not supported in case of concurrency
100 * Disable TDLS Offchannel to avoid more than two concurrent channels.
101 */
102 if (connected_tdls_peers == 1) {
103 curr_peer = wlan_hdd_tdls_get_connected_peer(adapter);
104 if (curr_peer && (curr_peer->isOffChannelConfigured == TRUE)) {
105 hddLog(LOG1, FL("%s: Concurrency detected, Disable "
106 "TDLS channel switch"), __func__);
107
108 sme_SendTdlsChanSwitchReq(WLAN_HDD_GET_HAL_CTX(adapter),
109 adapter->sessionId,
110 curr_peer->peerMac,
111 curr_peer->peerParams.channel,
112 TDLS_OFF_CHANNEL_BW_OFFSET,
113 TDLS_CHANNEL_SWITCH_DISABLE);
114 }
115 }
116
117 /* As mentioned above TDLS is not supported in case of concurrency
118 * Find the connected peer and generate TDLS teardown indication to
119 * supplicant.
120 */
121 for (staidx = 0; staidx < HDD_MAX_NUM_TDLS_STA; staidx++) {
122 if (!hddctx->tdlsConnInfo[staidx].staId)
123 continue;
124
125 curr_peer = wlan_hdd_tdls_find_all_peer(hddctx,
126 hddctx->tdlsConnInfo[staidx].peerMac.bytes);
127
128 if (!curr_peer)
129 continue;
130
131 hddLog(LOG1, FL("indicate TDLS teardown (staId %d)"),
132 curr_peer->staId);
133
134 wlan_hdd_tdls_indicate_teardown(
135 curr_peer->pHddTdlsCtx->pAdapter,
136 curr_peer,
137 eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON);
138 }
139 wlan_hdd_tdls_set_mode(hddctx, eTDLS_SUPPORT_DISABLED, FALSE);
140 hddLog(LOG1, FL("TDLS Support Disabled"));
141}
142
143/**
144 * hdd_tdls_notify_mode_change - Notify mode change
145 * @adapter: pointer to hdd adapter
146 * @hddCtx : pointer to hdd context
147 *
148 * Return: None
149 */
150void hdd_tdls_notify_mode_change(hdd_adapter_t *adapter, hdd_context_t *hddctx)
151{
152 if (adapter->device_mode != WLAN_HDD_INFRA_STATION)
153 wlan_hdd_tdls_disable_offchan_and_teardown_links(hddctx);
154}
155
Gopichand Nakkala4327a152013-03-04 23:22:42 -0800156static v_VOID_t wlan_hdd_tdls_start_peer_discover_timer(tdlsCtx_t *pHddTdlsCtx,
157 tANI_BOOLEAN mutexLock,
158 v_U32_t discoveryExpiry)
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800159{
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800160 hdd_station_ctx_t *pHddStaCtx;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530161 hdd_context_t *pHddCtx;
162
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530163 ENTER();
164
c_hpothu7f63e882013-10-02 19:13:35 +0530165 if ((NULL == pHddTdlsCtx) || (NULL == pHddTdlsCtx->pAdapter) )
166 {
167 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
168 FL(" pHddTdlsCtx or pAdapter points to NULL"));
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530169 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530170 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530171
172 pHddCtx = WLAN_HDD_GET_CTX( pHddTdlsCtx->pAdapter );
173
c_hpothu7f63e882013-10-02 19:13:35 +0530174 if(0 != (wlan_hdd_validate_context(pHddCtx)))
175 {
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530176 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530177 }
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800178
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800179 if ( mutexLock )
180 {
Rajesh Chauhana34c6e62014-03-25 16:37:58 +0530181 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800182 }
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800183
Gopichand Nakkala4327a152013-03-04 23:22:42 -0800184 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pHddTdlsCtx->pAdapter);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -0700185#ifdef FEATURE_WLAN_TDLS_INTERNAL
Gopichand Nakkala3046fc92013-03-23 13:56:43 -0700186 wlan_hdd_tdls_timer_restart(pHddTdlsCtx->pAdapter,
187 &pHddTdlsCtx->peerDiscoverTimer,
188 discoveryExpiry);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -0700189#endif
Gopichand Nakkala3046fc92013-03-23 13:56:43 -0700190 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "beacon rssi: %d",
191 pHddTdlsCtx->ap_rssi);
192
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800193 if ( mutexLock )
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530194 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800195
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530196 EXIT();
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800197 return;
198}
199
Hoonki Leed37cbb32013-04-20 00:31:14 -0700200#ifdef TDLS_USE_SEPARATE_DISCOVERY_TIMER
Hoonki Lee387663d2013-02-05 18:08:43 -0800201static v_VOID_t wlan_hdd_tdls_discover_peer_cb( v_PVOID_t userData )
202{
203 int i;
204 struct list_head *head;
205 struct list_head *pos;
Chilam NG571c65a2013-01-19 12:27:36 +0530206 hddTdlsPeer_t *curr_peer;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530207 hdd_context_t *pHddCtx;
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530208 tdlsCtx_t *pHddTdlsCtx;
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800209 int discover_req_sent = 0;
210 v_U32_t discover_expiry = TDLS_SUB_DISCOVERY_PERIOD;
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800211 tANI_BOOLEAN doMutexLock = eANI_BOOLEAN_TRUE;
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530212 v_CONTEXT_t pVosContext;
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800213
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530214 ENTER();
215
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530216 pVosContext = vos_get_global_context(VOS_MODULE_ID_HDD, NULL);
217 if (NULL == pVosContext)
c_hpothu7f63e882013-10-02 19:13:35 +0530218 {
219 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530220 FL("pVosContext points to NULL"));
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530221 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530222 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530223
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530224 pHddCtx = vos_get_context(VOS_MODULE_ID_HDD, pVosContext);
225 if (0 != (wlan_hdd_validate_context(pHddCtx)))
Sushant Kaushik15c4c522014-08-14 12:24:49 +0530226 {
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530227 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530228 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530229
Rajesh Chauhana34c6e62014-03-25 16:37:58 +0530230 mutex_lock(&pHddCtx->tdls_lock);
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530231 pHddTdlsCtx = (tdlsCtx_t *)userData;
232 if (0 != (wlan_hdd_validate_tdls_context(pHddCtx, pHddTdlsCtx)))
233 {
234 mutex_unlock(&pHddCtx->tdls_lock);
235 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
236 FL("Invalid pHddTdlsCtx context"));
237 return;
238 }
Hoonki Leebfee0342013-01-21 16:43:45 -0800239
Hoonki Lee387663d2013-02-05 18:08:43 -0800240 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: ", __func__);
241
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800242 if (0 == pHddTdlsCtx->discovery_peer_cnt)
Gopichand Nakkala4327a152013-03-04 23:22:42 -0800243 pHddTdlsCtx->discovery_peer_cnt = wlan_hdd_get_tdls_discovery_peer_cnt(pHddTdlsCtx);
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800244
Chilam NG571c65a2013-01-19 12:27:36 +0530245 for (i = 0; i < 256; i++) {
Hoonki Lee387663d2013-02-05 18:08:43 -0800246 head = &pHddTdlsCtx->peer_list[i];
Chilam NG571c65a2013-01-19 12:27:36 +0530247
Hoonki Lee387663d2013-02-05 18:08:43 -0800248 list_for_each (pos, head) {
249 curr_peer = list_entry (pos, hddTdlsPeer_t, node);
Chilam NG571c65a2013-01-19 12:27:36 +0530250
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530251 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Chilam Ng01120412013-02-19 18:32:21 -0800252 "%d " MAC_ADDRESS_STR " %d %d, %d %d %d %d", i,
253 MAC_ADDR_ARRAY(curr_peer->peerMac),
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800254 curr_peer->discovery_processed,
255 discover_req_sent,
Gopichand Nakkala2a0a1572013-02-10 21:39:16 -0800256 curr_peer->tdls_support,
257 curr_peer->link_status,
258 curr_peer->discovery_attempt,
259 pHddTdlsCtx->threshold_config.discovery_tries_n);
Hoonki Lee387663d2013-02-05 18:08:43 -0800260
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800261 if (discover_req_sent < TDLS_MAX_DISCOVER_REQS_PER_TIMER) {
262 if (!curr_peer->discovery_processed) {
Chilam NG571c65a2013-01-19 12:27:36 +0530263
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800264 curr_peer->discovery_processed = 1;
265 discover_req_sent++;
266 pHddTdlsCtx->discovery_peer_cnt--;
267
268 if ((eTDLS_CAP_UNKNOWN == curr_peer->tdls_support) &&
Gopichand Nakkala901e8922013-03-04 23:45:58 -0800269 (eTDLS_LINK_IDLE == curr_peer->link_status) &&
Gopichand Nakkalab88f6772013-02-27 18:12:56 -0800270 (curr_peer->tx_pkt >=
271 pHddTdlsCtx->threshold_config.tx_packet_n)) {
Gopichand Nakkala273d5a02013-02-19 15:15:09 -0800272
273 if (curr_peer->discovery_attempt <
274 pHddTdlsCtx->threshold_config.discovery_tries_n) {
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +0530275 cfg80211_tdls_oper_request(
276 pHddTdlsCtx->pAdapter->dev,
277 curr_peer->peerMac,
278 NL80211_TDLS_DISCOVERY_REQ,
279 FALSE,
280 GFP_KERNEL);
Gopichand Nakkala273d5a02013-02-19 15:15:09 -0800281 curr_peer->discovery_attempt++;
282 }
283 else
284 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530285 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Gopichand Nakkala273d5a02013-02-19 15:15:09 -0800286 "%s: Maximum Discovery retries reached", __func__);
287 curr_peer->tdls_support = eTDLS_CAP_NOT_SUPPORTED;
288 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800289
290 }
291 }
Chilam NG571c65a2013-01-19 12:27:36 +0530292 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800293 else
294 goto exit_loop;
Hoonki Lee387663d2013-02-05 18:08:43 -0800295 }
Hoonki Leef63df0d2013-01-16 19:29:14 -0800296 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800297exit_loop:
Hoonki Leef63df0d2013-01-16 19:29:14 -0800298
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800299 if (0 != pHddTdlsCtx->discovery_peer_cnt) {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530300 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800301 "discovery_peer_cnt is %d , Starting SUB_DISCOVERY_TIMER",
302 pHddTdlsCtx->discovery_peer_cnt);
303 discover_expiry = TDLS_SUB_DISCOVERY_PERIOD;
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800304 doMutexLock = eANI_BOOLEAN_FALSE;
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800305 goto done;
306 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800307 discover_expiry = pHddTdlsCtx->threshold_config.discovery_period_t;
308
Gopichand Nakkala4327a152013-03-04 23:22:42 -0800309 wlan_hdd_tdls_peer_reset_discovery_processed(pHddTdlsCtx);
Chilam NG571c65a2013-01-19 12:27:36 +0530310
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530311 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala638ebc72013-03-21 18:04:02 -0700312
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800313 /* Commenting out the following function as it was introducing
314 * a race condition when pHddTdlsCtx is deleted. Also , this
315 * function is consuming more time in the timer callback.
316 * RSSI based trigger needs to revisit this part of the code.
317 */
318
319 /*
320 * wlan_hdd_get_rssi(pAdapter, &pHddTdlsCtx->ap_rssi);
321 */
Chilam NG571c65a2013-01-19 12:27:36 +0530322
Gopichand Nakkalac3694582013-02-13 20:51:22 -0800323done:
Gopichand Nakkala4327a152013-03-04 23:22:42 -0800324 wlan_hdd_tdls_start_peer_discover_timer(pHddTdlsCtx, doMutexLock, discover_expiry);
Gopichand Nakkala91b09262013-02-10 14:27:02 -0800325
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800326 if ( !doMutexLock )
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530327 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530328 EXIT();
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -0800329 return;
Hoonki Leef63df0d2013-01-16 19:29:14 -0800330}
Hoonki Leed37cbb32013-04-20 00:31:14 -0700331#endif
Chilam NG571c65a2013-01-19 12:27:36 +0530332
Hoonki Lee387663d2013-02-05 18:08:43 -0800333static v_VOID_t wlan_hdd_tdls_update_peer_cb( v_PVOID_t userData )
Chilam NG571c65a2013-01-19 12:27:36 +0530334{
335 int i;
Hoonki Lee387663d2013-02-05 18:08:43 -0800336 struct list_head *head;
337 struct list_head *pos;
Chilam NG571c65a2013-01-19 12:27:36 +0530338 hddTdlsPeer_t *curr_peer;
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530339 tdlsCtx_t *pHddTdlsCtx;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530340 hdd_context_t *pHddCtx;
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530341 v_CONTEXT_t pVosContext;
Hoonki Leebfee0342013-01-21 16:43:45 -0800342
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530343 ENTER();
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530344 pVosContext = vos_get_global_context(VOS_MODULE_ID_HDD, NULL);
345 if (NULL == pVosContext)
c_hpothu7f63e882013-10-02 19:13:35 +0530346 {
347 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530348 FL("pVosContext points to NULL"));
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530349 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530350 }
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530351 pHddCtx = vos_get_context(VOS_MODULE_ID_HDD, pVosContext);
352 if (0 != (wlan_hdd_validate_context(pHddCtx)))
Sushant Kaushik15c4c522014-08-14 12:24:49 +0530353 {
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530354 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530355 }
Rajesh Chauhana34c6e62014-03-25 16:37:58 +0530356 mutex_lock(&pHddCtx->tdls_lock);
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530357 pHddTdlsCtx = (tdlsCtx_t *)userData;
358 if (0 != (wlan_hdd_validate_tdls_context(pHddCtx, pHddTdlsCtx)))
359 {
360 mutex_unlock(&pHddCtx->tdls_lock);
361 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
362 FL("Invalid pHddTdlsCtx context"));
363 return;
364 }
Chilam NG571c65a2013-01-19 12:27:36 +0530365 for (i = 0; i < 256; i++) {
Hoonki Lee387663d2013-02-05 18:08:43 -0800366 head = &pHddTdlsCtx->peer_list[i];
Chilam NG571c65a2013-01-19 12:27:36 +0530367
Hoonki Lee387663d2013-02-05 18:08:43 -0800368 list_for_each (pos, head) {
369 curr_peer = list_entry (pos, hddTdlsPeer_t, node);
Chilam NG571c65a2013-01-19 12:27:36 +0530370
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530371 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee66b75f32013-04-16 18:30:07 -0700372 "%s: " MAC_ADDRESS_STR " link_status %d"
373 " tdls_support %d", __func__, MAC_ADDR_ARRAY(curr_peer->peerMac),
Gopichand Nakkala34d1b062013-03-19 15:28:33 -0700374 curr_peer->link_status, curr_peer->tdls_support);
Hoonki Lee387663d2013-02-05 18:08:43 -0800375
Chilam NG571c65a2013-01-19 12:27:36 +0530376 if (eTDLS_CAP_SUPPORTED == curr_peer->tdls_support) {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530377 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee66b75f32013-04-16 18:30:07 -0700378 "tx %d, rx %d (thr.pkt %d/idle %d), rssi %d (thr.trig %d/hys %d/tear %d)",
379 curr_peer->tx_pkt, curr_peer->rx_pkt,
Hoonki Lee5a4b2172013-01-29 01:45:53 -0800380 pHddTdlsCtx->threshold_config.tx_packet_n,
Hoonki Lee66b75f32013-04-16 18:30:07 -0700381 pHddTdlsCtx->threshold_config.idle_packet_n,
382 curr_peer->rssi,
383 pHddTdlsCtx->threshold_config.rssi_trigger_threshold,
384 pHddTdlsCtx->threshold_config.rssi_hysteresis,
385 pHddTdlsCtx->threshold_config.rssi_teardown_threshold);
Chilam Ng01120412013-02-19 18:32:21 -0800386
Gopichand Nakkala901e8922013-03-04 23:45:58 -0800387 if ((eTDLS_LINK_IDLE == curr_peer->link_status) ||
388 (eTDLS_LINK_DISCOVERING == curr_peer->link_status)){
Sunil Dutt961ecbd2013-11-28 20:04:07 +0530389
390 if (pHddCtx->cfg_ini->fTDLSExternalControl &&
391 (FALSE == curr_peer->isForcedPeer)) {
392 continue;
393 }
394
Chilam NG571c65a2013-01-19 12:27:36 +0530395 if (curr_peer->tx_pkt >=
396 pHddTdlsCtx->threshold_config.tx_packet_n) {
Hoonki Lee5a4b2172013-01-29 01:45:53 -0800397
Gopichand Nakkala8b00c632013-03-08 19:47:52 -0800398 if (HDD_MAX_NUM_TDLS_STA > wlan_hdd_tdlsConnectedPeers(pHddTdlsCtx->pAdapter))
Gopichand Nakkalab977a972013-02-18 19:15:09 -0800399 {
400
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530401 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
402 "Tput trigger TDLS pre-setup");
Chilam NG571c65a2013-01-19 12:27:36 +0530403#ifdef CONFIG_TDLS_IMPLICIT
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +0530404 pHddTdlsCtx->curr_candidate = curr_peer;
405 wlan_hdd_tdls_implicit_send_discovery_request(pHddTdlsCtx);
Chilam NG571c65a2013-01-19 12:27:36 +0530406#endif
Gopichand Nakkalab977a972013-02-18 19:15:09 -0800407 }
408 else
409 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530410 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkala8b00c632013-03-08 19:47:52 -0800411 "%s: Maximum peer connected already! %d",
412 __func__, wlan_hdd_tdlsConnectedPeers(pHddTdlsCtx->pAdapter) );
Gopichand Nakkalab977a972013-02-18 19:15:09 -0800413 }
Hoonki Leecdd8e962013-01-20 00:45:46 -0800414 goto next_peer;
Chilam NG571c65a2013-01-19 12:27:36 +0530415 }
Hoonki Leefb8df672013-04-10 18:20:34 -0700416 }
417 else if (eTDLS_LINK_CONNECTED == curr_peer->link_status) {
Chilam Ng01120412013-02-19 18:32:21 -0800418 if ((tANI_S32)curr_peer->rssi <
419 (tANI_S32)pHddTdlsCtx->threshold_config.rssi_teardown_threshold) {
Hoonki Lee5a4b2172013-01-29 01:45:53 -0800420
Chilam Ng01120412013-02-19 18:32:21 -0800421 VOS_TRACE( VOS_MODULE_ID_HDD,
422 VOS_TRACE_LEVEL_WARN,
423 "Tear down - low RSSI: " MAC_ADDRESS_STR "!",
424 MAC_ADDR_ARRAY(curr_peer->peerMac));
425#ifdef CONFIG_TDLS_IMPLICIT
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -0700426 wlan_hdd_tdls_indicate_teardown(pHddTdlsCtx->pAdapter,
427 curr_peer,
428 eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON);
Chilam Ng01120412013-02-19 18:32:21 -0800429#endif
Hoonki Leecdd8e962013-01-20 00:45:46 -0800430 goto next_peer;
Chilam NG571c65a2013-01-19 12:27:36 +0530431 }
Chilam Ng01120412013-02-19 18:32:21 -0800432
Naresh Jayaramdb4514b2013-11-25 18:08:10 +0530433 /* Only teardown based on non zero idle packet threshold, to address a use
434 * case where this threshold does not get consider for TEAR DOWN.
435 */
436
437 if (( 0 != pHddTdlsCtx->threshold_config.idle_packet_n ) &&
438 ((curr_peer->tx_pkt <
Chilam Ng01120412013-02-19 18:32:21 -0800439 pHddTdlsCtx->threshold_config.idle_packet_n) &&
440 (curr_peer->rx_pkt <
Naresh Jayaramdb4514b2013-11-25 18:08:10 +0530441 pHddTdlsCtx->threshold_config.idle_packet_n))) {
Chilam Ng01120412013-02-19 18:32:21 -0800442 if (VOS_TIMER_STATE_RUNNING !=
443 vos_timer_getCurrentState(&curr_peer->peerIdleTimer)) {
444 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
445 "Tx/Rx Idle timer start: " MAC_ADDRESS_STR "!",
446 MAC_ADDR_ARRAY(curr_peer->peerMac));
Gopichand Nakkala3046fc92013-03-23 13:56:43 -0700447 wlan_hdd_tdls_timer_restart(pHddTdlsCtx->pAdapter,
448 &curr_peer->peerIdleTimer,
449 pHddTdlsCtx->threshold_config.idle_timeout_t);
Chilam Ng01120412013-02-19 18:32:21 -0800450 }
451 } else {
Hoonki Lee5a4b2172013-01-29 01:45:53 -0800452 if (VOS_TIMER_STATE_RUNNING ==
453 vos_timer_getCurrentState(&curr_peer->peerIdleTimer)) {
Chilam Ng01120412013-02-19 18:32:21 -0800454 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
455 "Tx/Rx Idle timer stop: " MAC_ADDRESS_STR "!",
456 MAC_ADDR_ARRAY(curr_peer->peerMac));
457 vos_timer_stop( &curr_peer->peerIdleTimer);
Hoonki Lee5a4b2172013-01-29 01:45:53 -0800458 }
Hoonki Lee5a4b2172013-01-29 01:45:53 -0800459 }
Chilam Ng01120412013-02-19 18:32:21 -0800460
Hoonki Leecdd8e962013-01-20 00:45:46 -0800461// if (curr_peer->rssi <
462// (pHddTdlsCtx->threshold_config.rssi_hysteresis +
463// pHddTdlsCtx->ap_rssi)) {
464//
465//#ifdef CONFIG_TDLS_IMPLICIT
466// cfg80211_tdls_oper_request(pHddTdlsCtx->dev,
467// curr_peer->peerMac,
468// NL80211_TDLS_TEARDOWN, FALSE,
469// GFP_KERNEL);
470//#endif
471// }
Chilam NG571c65a2013-01-19 12:27:36 +0530472 }
Chilam Ng01120412013-02-19 18:32:21 -0800473 } else if (eTDLS_CAP_UNKNOWN == curr_peer->tdls_support) {
Sunil Dutt961ecbd2013-11-28 20:04:07 +0530474
475 if (pHddCtx->cfg_ini->fTDLSExternalControl &&
476 (FALSE == curr_peer->isForcedPeer)) {
477 continue;
478 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -0700479 if (!TDLS_IS_CONNECTED(curr_peer)) {
Chilam Ng01120412013-02-19 18:32:21 -0800480 if (curr_peer->tx_pkt >=
481 pHddTdlsCtx->threshold_config.tx_packet_n) {
Chilam Ng01120412013-02-19 18:32:21 -0800482
Sunil Duttb0d39242014-09-10 23:54:51 +0530483 /* Ignore discovery attempt if External Control is enabled, that
484 * is, peer is forced. In that case, continue discovery attempt
485 * regardless attempt count
486 */
487 if (curr_peer->isForcedPeer || curr_peer->discovery_attempt++ <
Chilam Ng01120412013-02-19 18:32:21 -0800488 pHddTdlsCtx->threshold_config.discovery_tries_n) {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530489 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
490 "TDLS UNKNOWN discover ");
Hoonki Leed37cbb32013-04-20 00:31:14 -0700491#ifdef CONFIG_TDLS_IMPLICIT
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +0530492 pHddTdlsCtx->curr_candidate = curr_peer;
493 wlan_hdd_tdls_implicit_send_discovery_request(pHddTdlsCtx);
Hoonki Leed37cbb32013-04-20 00:31:14 -0700494#endif
Chilam Ng01120412013-02-19 18:32:21 -0800495 }
Gopichand Nakkala901e8922013-03-04 23:45:58 -0800496 else
Gopichand Nakkala8b00c632013-03-08 19:47:52 -0800497 {
Gopichand Nakkala901e8922013-03-04 23:45:58 -0800498 curr_peer->tdls_support = eTDLS_CAP_NOT_SUPPORTED;
Atul Mittal115287b2014-07-08 13:26:33 +0530499 wlan_hdd_tdls_set_peer_link_status(
500 curr_peer,
501 eTDLS_LINK_IDLE,
502 eTDLS_LINK_NOT_SUPPORTED);
503
Gopichand Nakkala8b00c632013-03-08 19:47:52 -0800504 }
Chilam Ng01120412013-02-19 18:32:21 -0800505 }
506 }
Chilam NG571c65a2013-01-19 12:27:36 +0530507 }
508
Hoonki Leecdd8e962013-01-20 00:45:46 -0800509next_peer:
Chilam NG571c65a2013-01-19 12:27:36 +0530510 curr_peer->tx_pkt = 0;
Chilam Ng1279e232013-01-25 15:06:52 -0800511 curr_peer->rx_pkt = 0;
Hoonki Lee387663d2013-02-05 18:08:43 -0800512 }
Chilam NG571c65a2013-01-19 12:27:36 +0530513 }
514
Gopichand Nakkala3046fc92013-03-23 13:56:43 -0700515 wlan_hdd_tdls_timer_restart(pHddTdlsCtx->pAdapter,
516 &pHddTdlsCtx->peerUpdateTimer,
517 pHddTdlsCtx->threshold_config.tx_period_t);
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530518 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530519 EXIT();
Chilam NG571c65a2013-01-19 12:27:36 +0530520}
521
Chilam Ng1279e232013-01-25 15:06:52 -0800522static v_VOID_t wlan_hdd_tdls_idle_cb( v_PVOID_t userData )
523{
Lee Hoonkic1262f22013-01-24 21:59:00 -0800524#ifdef CONFIG_TDLS_IMPLICIT
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530525 hddTdlsPeer_t *curr_peer;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530526 tdlsCtx_t *pHddTdlsCtx;
527 hdd_context_t *pHddCtx;
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530528 v_CONTEXT_t pVosContext;
Chilam Ng1279e232013-01-25 15:06:52 -0800529
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530530 ENTER();
531
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530532 pVosContext = vos_get_global_context(VOS_MODULE_ID_HDD, NULL);
533 if (NULL == pVosContext)
534 {
535 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
536 FL("pVosContext points to NULL"));
537 return;
538 }
539 pHddCtx = vos_get_context(VOS_MODULE_ID_HDD, pVosContext);
540 if (0 != (wlan_hdd_validate_context(pHddCtx)))
541 {
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530542 return;
543 }
544
545 mutex_lock(&pHddCtx->tdls_lock);
546
547 curr_peer = (hddTdlsPeer_t *)userData;
Rajesh Chauhan1ace6002013-04-18 18:08:21 -0700548 if (NULL == curr_peer)
549 {
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530550 mutex_unlock(&pHddCtx->tdls_lock);
Rajesh Chauhan1ace6002013-04-18 18:08:21 -0700551 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
c_hpothu7f63e882013-10-02 19:13:35 +0530552 FL("Invalid tdls idle timer expired"));
Rajesh Chauhan1ace6002013-04-18 18:08:21 -0700553 return;
554 }
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530555
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530556 pHddTdlsCtx = curr_peer->pHddTdlsCtx;
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530557 if (0 != (wlan_hdd_validate_tdls_context(pHddCtx, pHddTdlsCtx)))
c_hpothu7f63e882013-10-02 19:13:35 +0530558 {
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530559 mutex_unlock(&pHddCtx->tdls_lock);
c_hpothu7f63e882013-10-02 19:13:35 +0530560 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530561 FL("Invalid pHddTdlsCtx context"));
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530562 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530563 }
Rajesh Chauhan1ace6002013-04-18 18:08:21 -0700564
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530565 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Arif Hussain6d2a3322013-11-17 19:50:10 -0800566 "%s: Tx/Rx Idle " MAC_ADDRESS_STR " tx_pkt: %d, rx_pkt: %d, idle_packet_n: %d",
Rajesh Chauhan1ace6002013-04-18 18:08:21 -0700567 __func__, MAC_ADDR_ARRAY(curr_peer->peerMac),
568 curr_peer->tx_pkt,
569 curr_peer->rx_pkt,
570 curr_peer->pHddTdlsCtx->threshold_config.idle_packet_n);
571
Rajesh Chauhan1ace6002013-04-18 18:08:21 -0700572 /* Check tx/rx statistics on this tdls link for recent activities and
573 * then decide whether to tear down the link or keep it.
574 */
575 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))
576 {
577 /* this tdls link got back to normal, so keep it */
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530578 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Rajesh Chauhan1ace6002013-04-18 18:08:21 -0700579 "%s: tdls link to " MAC_ADDRESS_STR " back to normal, will stay",
580 __func__, MAC_ADDR_ARRAY(curr_peer->peerMac));
581 }
582 else
583 {
584 /* this tdls link needs to get torn down */
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530585 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Rajesh Chauhan1ace6002013-04-18 18:08:21 -0700586 "%s: trigger tdls link to " MAC_ADDRESS_STR " down",
587 __func__, MAC_ADDR_ARRAY(curr_peer->peerMac));
588
589 wlan_hdd_tdls_indicate_teardown(curr_peer->pHddTdlsCtx->pAdapter,
590 curr_peer,
591 eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON);
592 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530593 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530594 EXIT();
Chilam Ng1279e232013-01-25 15:06:52 -0800595#endif
596}
597
Gopichand Nakkala75e7b282013-03-15 18:37:13 -0700598static v_VOID_t wlan_hdd_tdls_discovery_timeout_peer_cb(v_PVOID_t userData)
599{
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -0700600 int i;
601 struct list_head *head;
602 hddTdlsPeer_t *tmp;
603 struct list_head *pos, *q;
Gopichand Nakkala75e7b282013-03-15 18:37:13 -0700604 tdlsCtx_t *pHddTdlsCtx;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530605 hdd_context_t *pHddCtx;
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530606 v_CONTEXT_t pVosContext;
Gopichand Nakkala75e7b282013-03-15 18:37:13 -0700607
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530608 ENTER();
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530609 pVosContext = vos_get_global_context(VOS_MODULE_ID_HDD, NULL);
610 if (NULL == pVosContext)
c_hpothu7f63e882013-10-02 19:13:35 +0530611 {
612 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530613 FL("pVosContext points to NULL"));
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530614 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530615 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530616
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530617 pHddCtx = vos_get_context(VOS_MODULE_ID_HDD, pVosContext);
618 if (0 != (wlan_hdd_validate_context(pHddCtx)))
Sushant Kaushik15c4c522014-08-14 12:24:49 +0530619 {
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530620 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530621 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530622
Rajesh Chauhana34c6e62014-03-25 16:37:58 +0530623 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -0700624
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530625 pHddTdlsCtx = (tdlsCtx_t *)userData;
626 if (0 != (wlan_hdd_validate_tdls_context(pHddCtx, pHddTdlsCtx)))
627 {
628 mutex_unlock(&pHddCtx->tdls_lock);
629 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
630 FL("Invalid pHddTdlsCtx context"));
631 return;
632 }
633
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -0700634 for (i = 0; i < 256; i++) {
635 head = &pHddTdlsCtx->peer_list[i];
636 list_for_each_safe (pos, q, head) {
637 tmp = list_entry(pos, hddTdlsPeer_t, node);
638 if (eTDLS_LINK_DISCOVERING == tmp->link_status)
639 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530640 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -0700641 "%s: " MAC_ADDRESS_STR " to idle state", __func__,
642 MAC_ADDR_ARRAY(tmp->peerMac));
Atul Mittal115287b2014-07-08 13:26:33 +0530643 wlan_hdd_tdls_set_peer_link_status(
644 tmp,
645 eTDLS_LINK_IDLE,
Atul Mittalad630e42014-10-07 19:19:14 +0530646 eTDLS_LINK_NOT_SUPPORTED);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -0700647 }
648 }
649 }
Gopichand Nakkala75e7b282013-03-15 18:37:13 -0700650
651 pHddTdlsCtx->discovery_sent_cnt = 0;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -0700652 wlan_hdd_tdls_check_power_save_prohibited(pHddTdlsCtx->pAdapter);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -0700653
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +0530654 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -0700655
Gopichand Nakkala75e7b282013-03-15 18:37:13 -0700656 wlan_hdd_tdls_check_bmps(pHddTdlsCtx->pAdapter);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530657 EXIT();
Gopichand Nakkala75e7b282013-03-15 18:37:13 -0700658 return;
659}
660
Hoonki Lee14621352013-04-16 17:51:19 -0700661static v_VOID_t wlan_hdd_tdls_initiator_wait_cb( v_PVOID_t userData )
662{
663 hddTdlsPeer_t *curr_peer = (hddTdlsPeer_t *)userData;
664 tdlsCtx_t *pHddTdlsCtx;
665
Mahesh A Saptasagar4534e2b2015-03-05 20:45:41 +0530666 ENTER();
Hoonki Lee14621352013-04-16 17:51:19 -0700667 if ( NULL == curr_peer )
c_hpothu7f63e882013-10-02 19:13:35 +0530668 {
669 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
670 FL("curr_peer is NULL"));
Hoonki Lee14621352013-04-16 17:51:19 -0700671 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530672 }
Hoonki Lee14621352013-04-16 17:51:19 -0700673
674 pHddTdlsCtx = curr_peer->pHddTdlsCtx;
675
676 if ( NULL == pHddTdlsCtx )
c_hpothu7f63e882013-10-02 19:13:35 +0530677 {
678 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
679 FL("pHddTdlsCtx is NULL"));
Hoonki Lee14621352013-04-16 17:51:19 -0700680 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530681 }
Mahesh A Saptasagar4534e2b2015-03-05 20:45:41 +0530682 if (0 != (wlan_hdd_validate_context(
683 WLAN_HDD_GET_CTX(pHddTdlsCtx->pAdapter))))
684 {
685 return;
686 }
Hoonki Lee14621352013-04-16 17:51:19 -0700687 WLANTL_ResumeDataTx( (WLAN_HDD_GET_CTX(pHddTdlsCtx->pAdapter))->pvosContext,
688 (v_U8_t *)&curr_peer->staId);
Mahesh A Saptasagar4534e2b2015-03-05 20:45:41 +0530689 EXIT();
Hoonki Lee14621352013-04-16 17:51:19 -0700690}
691
Gopichand Nakkala4327a152013-03-04 23:22:42 -0800692static void wlan_hdd_tdls_free_list(tdlsCtx_t *pHddTdlsCtx)
Gopichand Nakkala91b09262013-02-10 14:27:02 -0800693{
694 int i;
695 struct list_head *head;
696 hddTdlsPeer_t *tmp;
697 struct list_head *pos, *q;
698
c_hpothu7f63e882013-10-02 19:13:35 +0530699 if (NULL == pHddTdlsCtx)
700 {
701 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
702 FL("pHddTdlsCtx is NULL"));
703 return;
704 }
Gopichand Nakkala91b09262013-02-10 14:27:02 -0800705
706 for (i = 0; i < 256; i++) {
707 head = &pHddTdlsCtx->peer_list[i];
708 list_for_each_safe (pos, q, head) {
709 tmp = list_entry(pos, hddTdlsPeer_t, node);
710 list_del(pos);
711 vos_mem_free(tmp);
Srinivas Girigowda8d2348f2013-12-12 12:14:15 -0800712 tmp = NULL;
Gopichand Nakkala91b09262013-02-10 14:27:02 -0800713 }
714 }
Gopichand Nakkala91b09262013-02-10 14:27:02 -0800715}
716
Sameer Thalappilbee426e2013-10-30 10:30:30 -0700717static void wlan_hdd_tdls_schedule_scan(struct work_struct *work)
718{
719 tdls_scan_context_t *scan_ctx =
720 container_of(work, tdls_scan_context_t, tdls_scan_work.work);
721
722 if (NULL == scan_ctx)
c_hpothu7f63e882013-10-02 19:13:35 +0530723 {
724 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
725 FL("scan_ctx is NULL"));
Sameer Thalappilbee426e2013-10-30 10:30:30 -0700726 return;
c_hpothu7f63e882013-10-02 19:13:35 +0530727 }
Sameer Thalappilbee426e2013-10-30 10:30:30 -0700728
729 if (unlikely(TDLS_CTX_MAGIC != scan_ctx->magic))
730 return;
731
732 scan_ctx->attempt++;
733
734 wlan_hdd_cfg80211_scan(scan_ctx->wiphy,
735#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
736 scan_ctx->dev,
737#endif
738 scan_ctx->scan_request);
739}
740
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530741void wlan_hdd_tdls_btCoex_cb(void *data, int indType)
742{
743 hdd_adapter_t *pAdapter;
744 hdd_context_t *pHddCtx;
745 u16 connectedTdlsPeers;
746 tdlsCtx_t *pHddTdlsCtx;
747 hddTdlsPeer_t *currPeer;
748 hdd_scaninfo_t *pScanInfo;
749
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530750 ENTER();
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530751 if ((NULL == data) || (indType < 0))
752 {
753 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
754 FL("Invalid arguments"));
755 return;
756 }
757
758 pHddCtx = (hdd_context_t *)data;
759 if (0 != (wlan_hdd_validate_context(pHddCtx)))
760 {
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530761 return;
762 }
763
764 /* if tdls is not enabled, then continue btCoex */
765 if (eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode)
766 {
767 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
768 FL("tdls is not enabled"));
769 return;
770 }
771
772 /* get pAdapter context, do we need WLAN_HDD_P2P_CLIENT */
773 pAdapter = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION);
774 if (NULL == pAdapter)
775 {
776 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
777 FL("pAdapter is not valid"));
778 return;
779 }
780
781 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
782 if (NULL == pHddTdlsCtx)
783 {
784 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
785 FL("pHddTdlsCtx is not valid"));
786 return;
787 }
788
789 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
790 "%s: BtCoex notification type %d", __func__, indType);
791 /* BtCoex notification type enabled, Disable TDLS */
792 if (indType == SIR_COEX_IND_TYPE_TDLS_DISABLE)
793 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530794 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530795 FL("BtCoex notification, Disable TDLS"));
796
797 pScanInfo = &pHddCtx->scan_info;
798 // Lets do abort scan if scan is pending
799 if ((pScanInfo != NULL) && pScanInfo->mScanPending)
800 {
801 hdd_abort_mac_scan(pHddCtx, pScanInfo->sessionId,
802 eCSR_SCAN_ABORT_DEFAULT);
803 }
804
805 /* tdls is in progress */
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +0530806 currPeer = wlan_hdd_tdls_is_progress(pHddCtx, NULL, 0, TRUE);
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530807 if (NULL != currPeer)
808 {
809 wlan_hdd_tdls_set_peer_link_status (currPeer,
810 eTDLS_LINK_IDLE,
811 eTDLS_LINK_UNSPECIFIED);
812 }
813
814 /* while tdls is up */
815 if (eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode ||
816 eTDLS_SUPPORT_EXPLICIT_TRIGGER_ONLY == pHddCtx->tdls_mode)
817 {
818 connectedTdlsPeers = wlan_hdd_tdlsConnectedPeers(pAdapter);
819 /* disable implicit trigger logic & tdls operatoin */
820 wlan_hdd_tdls_set_mode(pHddCtx, eTDLS_SUPPORT_DISABLED, FALSE);
821 pHddCtx->is_tdls_btc_enabled = FALSE;
822
823 /* teardown the peers on the btcoex */
824 if (connectedTdlsPeers)
825 {
826 tANI_U8 staIdx;
827 hddTdlsPeer_t *curr_peer;
828
829 for (staIdx = 0; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
830 {
831 if (pHddCtx->tdlsConnInfo[staIdx].staId)
832 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530833 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
834 ("%s: indicate TDLS teardown (staId %d)"),
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530835 __func__,pHddCtx->tdlsConnInfo[staIdx].staId);
836
837 #ifdef CONFIG_TDLS_IMPLICIT
838 curr_peer = wlan_hdd_tdls_find_all_peer(pHddCtx,
839 pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes);
840 if(curr_peer) {
841 wlan_hdd_tdls_indicate_teardown(
842 curr_peer->pHddTdlsCtx->pAdapter, curr_peer,
843 eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON);
844 }
845 #endif
846 }
847 }
848 }
849 }
850 }
851 /* BtCoex notification type enabled, Enable TDLS */
852 else if (indType == SIR_COEX_IND_TYPE_TDLS_ENABLE)
853 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530854 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530855 FL("BtCoex notification, Enable TDLS"));
856 /* if tdls was enabled before btCoex, re-enable tdls mode */
857 if (eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode_last ||
858 eTDLS_SUPPORT_EXPLICIT_TRIGGER_ONLY == pHddCtx->tdls_mode_last)
859 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +0530860 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530861 ("%s: revert tdls mode %d"), __func__,
862 pHddCtx->tdls_mode_last);
863 pHddCtx->is_tdls_btc_enabled = TRUE;
864 wlan_hdd_tdls_set_mode(pHddCtx, pHddCtx->tdls_mode_last, FALSE);
865 }
866 }
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +0530867 EXIT();
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530868 return;
869}
870
Agarwal Ashish4b87f922014-06-18 03:03:21 +0530871/* initialize TDLS global context */
872void wlan_hdd_tdls_init(hdd_context_t *pHddCtx )
873{
874 v_U8_t staIdx;
Chandrasekaran, Manishekar0de84dc2015-03-10 15:12:34 +0530875 eHalStatus status;
Sameer Thalappilbee426e2013-10-30 10:30:30 -0700876
Agarwal Ashish4b87f922014-06-18 03:03:21 +0530877 pHddCtx->connected_peer_count = 0;
878
879 pHddCtx->tdls_scan_ctxt.magic = 0;
880 pHddCtx->tdls_scan_ctxt.attempt = 0;
881 pHddCtx->tdls_scan_ctxt.reject = 0;
882 pHddCtx->tdls_scan_ctxt.scan_request = NULL;
883
884 for (staIdx = 0; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
885 {
886 pHddCtx->tdlsConnInfo[staIdx].staId = 0;
887 pHddCtx->tdlsConnInfo[staIdx].sessionId = 255;
888 vos_mem_zero(&pHddCtx->tdlsConnInfo[staIdx].peerMac,
889 sizeof(v_MACADDR_t)) ;
890 }
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +0530891 pHddCtx->is_tdls_btc_enabled = TRUE;
Chandrasekaran, Manishekar0de84dc2015-03-10 15:12:34 +0530892 status = sme_RegisterBtCoexTDLSCallback(pHddCtx->hHal,
893 wlan_hdd_tdls_btCoex_cb);
894 if (status != eHAL_STATUS_SUCCESS) {
895 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to register BT Coex TDLS callback"));
896 }
Agarwal Ashish4b87f922014-06-18 03:03:21 +0530897
898 if (FALSE == pHddCtx->cfg_ini->fEnableTDLSImplicitTrigger)
899 {
900 pHddCtx->tdls_mode = eTDLS_SUPPORT_EXPLICIT_TRIGGER_ONLY;
901 hddLog(VOS_TRACE_LEVEL_ERROR, "%s TDLS Implicit trigger not enabled!", __func__);
902 }
903 else
904 {
905 pHddCtx->tdls_mode = eTDLS_SUPPORT_ENABLED;
906 }
907}
908
909int wlan_hdd_sta_tdls_init(hdd_adapter_t *pAdapter)
Chilam Ng01120412013-02-19 18:32:21 -0800910{
Chilam Ng01120412013-02-19 18:32:21 -0800911 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
Hoonki Lee27511902013-03-14 18:19:06 -0700912 tdlsCtx_t *pHddTdlsCtx;
Chilam Ng01120412013-02-19 18:32:21 -0800913 int i;
Sunil Dutt66485cb2013-12-19 19:05:03 +0530914 if (NULL == pHddCtx)
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +0530915 {
916 hddLog(VOS_TRACE_LEVEL_ERROR, "%s pHddCtx is NULL", __func__);
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530917 return -EINVAL;
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +0530918 }
Sunil Dutt66485cb2013-12-19 19:05:03 +0530919
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +0530920 if (test_bit(TDLS_INIT_DONE, &pAdapter->event_flags))
921 {
922 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530923 "%s: TDLS INIT DONE set to 1, no point in re-init", __func__);
924 return -EALREADY;
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +0530925 }
Sunil Dutt66485cb2013-12-19 19:05:03 +0530926
Hoonki Lee27511902013-03-14 18:19:06 -0700927 if ((FALSE == pHddCtx->cfg_ini->fEnableTDLSSupport) ||
928 (FALSE == sme_IsFeatureSupportedByFW(TDLS)))
929 {
930 pHddCtx->tdls_mode = eTDLS_SUPPORT_NOT_ENABLED;
931 pAdapter->sessionCtx.station.pHddTdlsCtx = NULL;
932 hddLog(VOS_TRACE_LEVEL_ERROR, "%s TDLS not enabled (%d) or FW doesn't support (%d)!",
933 __func__, pHddCtx->cfg_ini->fEnableTDLSSupport,
934 sme_IsFeatureSupportedByFW(TDLS));
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530935 return -EINVAL;
Gopichand Nakkala4327a152013-03-04 23:22:42 -0800936 }
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +0530937 /* TDLS is supported only in STA / P2P Client modes,
938 * hence the check for TDLS support in a specific Device mode.
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +0530939 */
940 if (0 == WLAN_HDD_IS_TDLS_SUPPORTED_ADAPTER(pAdapter))
941 {
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +0530942 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 +0530943 return -EINVAL;
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +0530944 }
945 /* Check for the valid pHddTdlsCtx. If valid do not further
946 * allocate the memory, rather continue with the initialization.
947 * If tdls_initialization would get reinvoked without tdls_exit
948 * getting invoked (SSR) there is no point to further proceed
949 * with the memory allocations.
950 */
951 if (NULL == pAdapter->sessionCtx.station.pHddTdlsCtx)
952 {
953 pHddTdlsCtx = vos_mem_malloc(sizeof(tdlsCtx_t));
Gopichand Nakkala4327a152013-03-04 23:22:42 -0800954
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +0530955 if (NULL == pHddTdlsCtx) {
956 hddLog(VOS_TRACE_LEVEL_ERROR, "%s malloc failed!", __func__);
957 pAdapter->sessionCtx.station.pHddTdlsCtx = NULL;
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +0530958 return -ENOMEM;
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +0530959 }
960 /* initialize TDLS pAdater context */
961 vos_mem_zero(pHddTdlsCtx, sizeof(tdlsCtx_t));
962#ifdef TDLS_USE_SEPARATE_DISCOVERY_TIMER
963 vos_timer_init(&pHddTdlsCtx->peerDiscoverTimer,
964 VOS_TIMER_TYPE_SW,
965 wlan_hdd_tdls_discover_peer_cb,
966 pHddTdlsCtx);
967#endif
Hoonki Lee27511902013-03-14 18:19:06 -0700968
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +0530969 vos_timer_init(&pHddTdlsCtx->peerUpdateTimer,
970 VOS_TIMER_TYPE_SW,
971 wlan_hdd_tdls_update_peer_cb,
972 pHddTdlsCtx);
973 vos_timer_init(&pHddTdlsCtx->peerDiscoveryTimeoutTimer,
974 VOS_TIMER_TYPE_SW,
975 wlan_hdd_tdls_discovery_timeout_peer_cb,
976 pHddTdlsCtx);
977
978 pAdapter->sessionCtx.station.pHddTdlsCtx = pHddTdlsCtx;
Hoonki Lee27511902013-03-14 18:19:06 -0700979 }
980
Madan Mohan Koyyalamudi81746922013-07-17 14:38:51 +0530981 pHddTdlsCtx = pAdapter->sessionCtx.station.pHddTdlsCtx;
Hoonki Lee27511902013-03-14 18:19:06 -0700982
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -0700983 sme_SetTdlsPowerSaveProhibited(WLAN_HDD_GET_HAL_CTX(pAdapter), 0);
Hoonki Lee27511902013-03-14 18:19:06 -0700984
Hoonki Lee27511902013-03-14 18:19:06 -0700985 pHddTdlsCtx->pAdapter = pAdapter;
986
987 for (i = 0; i < 256; i++)
988 {
989 INIT_LIST_HEAD(&pHddTdlsCtx->peer_list[i]);
990 }
991
Hoonki Leed37cbb32013-04-20 00:31:14 -0700992 pHddTdlsCtx->curr_candidate = NULL;
993 pHddTdlsCtx->magic = 0;
994
Hoonki Lee27511902013-03-14 18:19:06 -0700995 /* remember configuration even if it is not used right now. it could be used later */
996 pHddTdlsCtx->threshold_config.tx_period_t = pHddCtx->cfg_ini->fTDLSTxStatsPeriod;
997 pHddTdlsCtx->threshold_config.tx_packet_n = pHddCtx->cfg_ini->fTDLSTxPacketThreshold;
998 pHddTdlsCtx->threshold_config.discovery_period_t = pHddCtx->cfg_ini->fTDLSDiscoveryPeriod;
999 pHddTdlsCtx->threshold_config.discovery_tries_n = pHddCtx->cfg_ini->fTDLSMaxDiscoveryAttempt;
1000 pHddTdlsCtx->threshold_config.idle_timeout_t = pHddCtx->cfg_ini->fTDLSIdleTimeout;
1001 pHddTdlsCtx->threshold_config.idle_packet_n = pHddCtx->cfg_ini->fTDLSIdlePacketThreshold;
1002 pHddTdlsCtx->threshold_config.rssi_hysteresis = pHddCtx->cfg_ini->fTDLSRSSIHysteresis;
1003 pHddTdlsCtx->threshold_config.rssi_trigger_threshold = pHddCtx->cfg_ini->fTDLSRSSITriggerThreshold;
1004 pHddTdlsCtx->threshold_config.rssi_teardown_threshold = pHddCtx->cfg_ini->fTDLSRSSITeardownThreshold;
Chilam NG571c65a2013-01-19 12:27:36 +05301005
Sameer Thalappilbee426e2013-10-30 10:30:30 -07001006 INIT_DELAYED_WORK(&pHddCtx->tdls_scan_ctxt.tdls_scan_work, wlan_hdd_tdls_schedule_scan);
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +05301007 set_bit(TDLS_INIT_DONE, &pAdapter->event_flags);
Hoonki Lee27511902013-03-14 18:19:06 -07001008
1009 return 0;
Chilam NG571c65a2013-01-19 12:27:36 +05301010}
1011
Pradeep Reddy POTTETI2d4d5c42015-03-03 14:34:19 +05301012void wlan_hdd_tdls_exit(hdd_adapter_t *pAdapter, tANI_BOOLEAN mutexLock)
Chilam NG571c65a2013-01-19 12:27:36 +05301013{
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001014 tdlsCtx_t *pHddTdlsCtx;
Hoonki Lee93e67ff2013-03-19 15:49:25 -07001015 hdd_context_t *pHddCtx;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001016
Chandrasekaran, Manishekar41b8e1f2015-03-10 13:30:28 +05301017 if (!pAdapter) {
1018 hddLog(VOS_TRACE_LEVEL_ERROR, FL("HDD adpater is NULL"));
1019 return;
1020 }
1021
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301022 /*
1023 * NOTE: The Callers of this function should ensure to acquire the
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +05301024 * tdls_lock to avoid any concurrent access to the Adapter and logp
1025 * protection has to be ensured.
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301026 */
1027
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05301028 pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
Agarwal Ashish9ffa5b92014-11-18 21:07:02 +05301029
1030 if (NULL == pHddCtx || NULL == pHddCtx->cfg_ini)
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05301031 {
Agarwal Ashish9ffa5b92014-11-18 21:07:02 +05301032 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1033 "%s: HDD context is Null", __func__);
1034 return ;
1035 }
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +05301036 if (!test_bit(TDLS_INIT_DONE, &pAdapter->event_flags))
Agarwal Ashish9ffa5b92014-11-18 21:07:02 +05301037 {
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +05301038 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1039 "%s: TDLS INIT DONE set to 0, no point in exit", __func__);
1040 return;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05301041 }
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +05301042 clear_bit(TDLS_INIT_DONE, &pAdapter->event_flags);
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05301043
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001044 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001045 if (NULL == pHddTdlsCtx)
1046 {
c_hpothu7f63e882013-10-02 19:13:35 +05301047 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1048 FL("pHddTdlsCtx is NULL"));
Hoonki Leebfee0342013-01-21 16:43:45 -08001049 return;
1050 }
Mahesh A Saptasagarf5b8eff2015-01-31 01:07:07 +05301051
Anand N Sunkad860e5ea2015-03-30 14:41:51 +05301052 vos_flush_delayed_work(&pHddCtx->tdls_scan_ctxt.tdls_scan_work);
Hoonki Leebfee0342013-01-21 16:43:45 -08001053
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001054 /* must stop timer here before freeing peer list, because peerIdleTimer is
1055 part of peer list structure. */
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001056 wlan_hdd_tdls_timers_destroy(pHddTdlsCtx);
1057 wlan_hdd_tdls_free_list(pHddTdlsCtx);
Chilam Nga75d8b62013-01-29 01:35:59 -08001058
Hoonki Lee93e67ff2013-03-19 15:49:25 -07001059 wlan_hdd_tdls_free_scan_request(&pHddCtx->tdls_scan_ctxt);
Sushant Kaushik15c4c522014-08-14 12:24:49 +05301060 pHddTdlsCtx->magic = 0;
1061 pHddTdlsCtx->pAdapter = NULL;
Chilam Nga75d8b62013-01-29 01:35:59 -08001062 vos_mem_free(pHddTdlsCtx);
Pradeep Reddy POTTETI59c90d62014-03-24 19:45:47 +05301063 pAdapter->sessionCtx.station.pHddTdlsCtx = NULL;
Chilam Nga75d8b62013-01-29 01:35:59 -08001064 pHddTdlsCtx = NULL;
Chilam NG571c65a2013-01-19 12:27:36 +05301065}
1066
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +05301067/* stop all monitoring timers per Adapter */
1068static void wlan_hdd_tdls_monitor_timers_stop(tdlsCtx_t *pHddTdlsCtx)
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001069{
Hoonki Leed37cbb32013-04-20 00:31:14 -07001070#ifdef TDLS_USE_SEPARATE_DISCOVERY_TIMER
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001071 vos_timer_stop(&pHddTdlsCtx->peerDiscoverTimer);
Hoonki Leed37cbb32013-04-20 00:31:14 -07001072#endif
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001073 vos_timer_stop(&pHddTdlsCtx->peerUpdateTimer);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001074 vos_timer_stop(&pHddTdlsCtx->peerDiscoveryTimeoutTimer);
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +05301075}
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001076
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +05301077/* stop all per peer timers */
1078static void wlan_hdd_tdls_peer_timers_stop(tdlsCtx_t *pHddTdlsCtx)
1079{
1080 int i;
1081 struct list_head *head;
1082 struct list_head *pos;
1083 hddTdlsPeer_t *curr_peer;
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001084 for (i = 0; i < 256; i++)
1085 {
1086 head = &pHddTdlsCtx->peer_list[i];
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001087 list_for_each (pos, head) {
1088 curr_peer = list_entry (pos, hddTdlsPeer_t, node);
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05301089 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Chilam Ng01120412013-02-19 18:32:21 -08001090 "%s: " MAC_ADDRESS_STR " -> stop idle timer",
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001091 __func__,
Chilam Ng01120412013-02-19 18:32:21 -08001092 MAC_ADDR_ARRAY(curr_peer->peerMac));
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001093 vos_timer_stop ( &curr_peer->peerIdleTimer );
Hoonki Lee14621352013-04-16 17:51:19 -07001094 vos_timer_stop( &curr_peer->initiatorWaitTimeoutTimer );
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001095 }
1096 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001097}
1098
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +05301099/* stop all the tdls timers running */
1100static void wlan_hdd_tdls_timers_stop(tdlsCtx_t *pHddTdlsCtx)
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001101{
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +05301102 wlan_hdd_tdls_monitor_timers_stop(pHddTdlsCtx);
1103 wlan_hdd_tdls_peer_timers_stop(pHddTdlsCtx);
1104}
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001105
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +05301106static void wlan_hdd_tdls_monitor_timers_destroy(tdlsCtx_t *pHddTdlsCtx)
1107{
Hoonki Leed37cbb32013-04-20 00:31:14 -07001108#ifdef TDLS_USE_SEPARATE_DISCOVERY_TIMER
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001109 vos_timer_stop(&pHddTdlsCtx->peerDiscoverTimer);
1110 vos_timer_destroy(&pHddTdlsCtx->peerDiscoverTimer);
Hoonki Leed37cbb32013-04-20 00:31:14 -07001111#endif
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001112 vos_timer_stop(&pHddTdlsCtx->peerUpdateTimer);
1113 vos_timer_destroy(&pHddTdlsCtx->peerUpdateTimer);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001114 vos_timer_stop(&pHddTdlsCtx->peerDiscoveryTimeoutTimer);
1115 vos_timer_destroy(&pHddTdlsCtx->peerDiscoveryTimeoutTimer);
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +05301116}
1117/*Free all the timers related to the TDLS peer */
1118static void wlan_hdd_tdls_peer_timers_destroy(tdlsCtx_t *pHddTdlsCtx)
1119{
1120 int i;
1121 struct list_head *head;
1122 struct list_head *pos;
1123 hddTdlsPeer_t *curr_peer;
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001124 for (i = 0; i < 256; i++)
1125 {
1126 head = &pHddTdlsCtx->peer_list[i];
1127
1128 list_for_each (pos, head) {
1129 curr_peer = list_entry (pos, hddTdlsPeer_t, node);
1130
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05301131 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Chilam Ng01120412013-02-19 18:32:21 -08001132 "%s: " MAC_ADDRESS_STR " -> destroy idle timer",
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001133 __func__,
Chilam Ng01120412013-02-19 18:32:21 -08001134 MAC_ADDR_ARRAY(curr_peer->peerMac));
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001135 vos_timer_stop ( &curr_peer->peerIdleTimer );
1136 vos_timer_destroy ( &curr_peer->peerIdleTimer );
Hoonki Lee14621352013-04-16 17:51:19 -07001137 vos_timer_stop(&curr_peer->initiatorWaitTimeoutTimer);
1138 vos_timer_destroy(&curr_peer->initiatorWaitTimeoutTimer);
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001139 }
1140 }
Madan Mohan Koyyalamudi693275b2013-07-22 19:14:09 +05301141
1142}
1143
1144/* destroy all the tdls timers running */
1145static void wlan_hdd_tdls_timers_destroy(tdlsCtx_t *pHddTdlsCtx)
1146{
1147 wlan_hdd_tdls_monitor_timers_destroy(pHddTdlsCtx);
1148 wlan_hdd_tdls_peer_timers_destroy(pHddTdlsCtx);
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001149}
1150
Hoonki Lee387663d2013-02-05 18:08:43 -08001151/* if mac address exist, return pointer
1152 if mac address doesn't exist, create a list and add, return pointer
1153 return NULL if fails to get new mac address
1154*/
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001155hddTdlsPeer_t *wlan_hdd_tdls_get_peer(hdd_adapter_t *pAdapter, u8 *mac)
Chilam NG571c65a2013-01-19 12:27:36 +05301156{
Hoonki Lee387663d2013-02-05 18:08:43 -08001157 struct list_head *head;
1158 hddTdlsPeer_t *peer;
1159 u8 key;
Gopichand Nakkala4ddf0192013-03-27 13:41:20 -07001160 tdlsCtx_t *pHddTdlsCtx;
Chandrasekaran, Manishekar41b8e1f2015-03-10 13:30:28 +05301161 hdd_context_t *pHddCtx;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05301162
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05301163 ENTER();
Chandrasekaran, Manishekar41b8e1f2015-03-10 13:30:28 +05301164
1165 if (!pAdapter) {
1166 hddLog(VOS_TRACE_LEVEL_ERROR, FL("HDD adpater is NULL"));
1167 return NULL;
1168 }
1169
1170 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
1171 if (0 != (wlan_hdd_validate_context(pHddCtx)))
c_hpothu7f63e882013-10-02 19:13:35 +05301172 {
c_hpothu7f63e882013-10-02 19:13:35 +05301173 return 0;
1174 }
Hoonki Leebfee0342013-01-21 16:43:45 -08001175
Hoonki Lee387663d2013-02-05 18:08:43 -08001176 /* if already there, just update */
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301177 peer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Hoonki Lee387663d2013-02-05 18:08:43 -08001178 if (peer != NULL)
1179 {
1180 return peer;
Chilam NG571c65a2013-01-19 12:27:36 +05301181 }
1182
Hoonki Lee387663d2013-02-05 18:08:43 -08001183 /* not found, allocate and add the list */
1184 peer = vos_mem_malloc(sizeof(hddTdlsPeer_t));
1185 if (NULL == peer) {
1186 hddLog(VOS_TRACE_LEVEL_ERROR, "%s peer malloc failed!", __func__);
1187 return NULL;
1188 }
Chilam NG571c65a2013-01-19 12:27:36 +05301189
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05301190 mutex_lock(&pHddCtx->tdls_lock);
1191
Gopichand Nakkala4ddf0192013-03-27 13:41:20 -07001192 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
1193
1194 if (NULL == pHddTdlsCtx)
1195 {
1196 vos_mem_free(peer);
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05301197 mutex_unlock(&pHddCtx->tdls_lock);
Hema Aparna Medicharla8bb6f782015-03-09 12:35:05 +05301198 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
1199 FL("pHddTdlsCtx is NULL"));
Gopichand Nakkala4ddf0192013-03-27 13:41:20 -07001200 return NULL;
1201 }
1202
1203 key = wlan_hdd_tdls_hash_key(mac);
1204 head = &pHddTdlsCtx->peer_list[key];
Chilam NG571c65a2013-01-19 12:27:36 +05301205
Hoonki Lee387663d2013-02-05 18:08:43 -08001206 vos_mem_zero(peer, sizeof(hddTdlsPeer_t));
1207 vos_mem_copy(peer->peerMac, mac, sizeof(peer->peerMac));
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001208 peer->pHddTdlsCtx = pHddTdlsCtx;
Hoonki Lee387663d2013-02-05 18:08:43 -08001209
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001210 vos_timer_init(&peer->peerIdleTimer,
1211 VOS_TIMER_TYPE_SW,
1212 wlan_hdd_tdls_idle_cb,
1213 peer);
1214
Hoonki Lee14621352013-04-16 17:51:19 -07001215 vos_timer_init(&peer->initiatorWaitTimeoutTimer,
1216 VOS_TIMER_TYPE_SW,
1217 wlan_hdd_tdls_initiator_wait_cb,
1218 peer);
1219
Hoonki Lee387663d2013-02-05 18:08:43 -08001220 list_add_tail(&peer->node, head);
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05301221 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Lee387663d2013-02-05 18:08:43 -08001222
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05301223 EXIT();
Hoonki Lee387663d2013-02-05 18:08:43 -08001224 return peer;
1225}
1226
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07001227int wlan_hdd_tdls_set_cap(hdd_adapter_t *pAdapter,
Hoonki Lee27511902013-03-14 18:19:06 -07001228 u8* mac,
1229 tTDLSCapType cap)
1230{
1231 hddTdlsPeer_t *curr_peer;
1232
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07001233 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Hoonki Lee27511902013-03-14 18:19:06 -07001234 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301235 {
1236 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1237 "%s: curr_peer is NULL", __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07001238 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301239 }
Hoonki Lee27511902013-03-14 18:19:06 -07001240
1241 curr_peer->tdls_support = cap;
1242
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07001243 return 0;
Hoonki Lee27511902013-03-14 18:19:06 -07001244}
1245
Atul Mittal115287b2014-07-08 13:26:33 +05301246void wlan_hdd_tdls_set_peer_link_status(hddTdlsPeer_t *curr_peer,
1247 tTDLSLinkStatus status,
1248 tTDLSLinkReason reason)
Hoonki Lee387663d2013-02-05 18:08:43 -08001249{
Atul Mittal115287b2014-07-08 13:26:33 +05301250 /*EXT TDLS*/
1251 tANI_S32 state = 0;
1252 tANI_S32 res = 0;
1253 /*EXT TDLS*/
Hoonki Lee387663d2013-02-05 18:08:43 -08001254 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301255 {
1256 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1257 "%s: curr_peer is NULL", __func__);
Hoonki Lee387663d2013-02-05 18:08:43 -08001258 return;
c_hpothu7f63e882013-10-02 19:13:35 +05301259 }
Hoonki Lee387663d2013-02-05 18:08:43 -08001260
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001261 hddLog(VOS_TRACE_LEVEL_WARN, "tdls set peer " MAC_ADDRESS_STR " link status to %u",
Chilam Ng01120412013-02-19 18:32:21 -08001262 MAC_ADDR_ARRAY(curr_peer->peerMac), status);
Chilam NG571c65a2013-01-19 12:27:36 +05301263
1264 curr_peer->link_status = status;
1265
Atul Mittal115287b2014-07-08 13:26:33 +05301266 /*EXT TDLS*/
1267 if (curr_peer->isForcedPeer && curr_peer->state_change_notification)
1268 {
1269 /*save the reason for any further query*/
1270 curr_peer->reason = reason;
1271 wlan_hdd_tdls_get_wifi_hal_state(curr_peer, &state, &res);
1272
1273 (curr_peer->state_change_notification)(
1274 curr_peer->peerMac,
1275 state,
1276 res,
1277 curr_peer->pHddTdlsCtx->pAdapter);
1278
1279 }
1280 /*EXT TDLS*/
1281
Chilam NG571c65a2013-01-19 12:27:36 +05301282}
1283
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001284void wlan_hdd_tdls_set_link_status(hdd_adapter_t *pAdapter,
1285 u8* mac,
Atul Mittal115287b2014-07-08 13:26:33 +05301286 tTDLSLinkStatus linkStatus,
1287 tTDLSLinkReason reason)
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001288{
Atul Mittal115287b2014-07-08 13:26:33 +05301289
1290 /*EXT TDLS*/
1291 tANI_S32 state = 0;
1292 tANI_S32 res = 0;
1293 /*EXT TDLS*/
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001294 hddTdlsPeer_t *curr_peer;
1295
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301296 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001297 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301298 {
1299 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1300 "%s: curr_peer is NULL", __func__);
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001301 return;
c_hpothu7f63e882013-10-02 19:13:35 +05301302 }
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001303
1304 curr_peer->link_status= linkStatus;
1305
Atul Mittal115287b2014-07-08 13:26:33 +05301306 /*EXT TDLS*/
1307
1308 if (curr_peer->isForcedPeer && curr_peer->state_change_notification)
1309 {
1310 /*save the reason for any further query*/
1311 curr_peer->reason = reason;
1312 wlan_hdd_tdls_get_wifi_hal_state(curr_peer, &state, &res);
1313
1314 (*curr_peer->state_change_notification)(mac,
1315 state,
1316 res,
1317 curr_peer->pHddTdlsCtx->pAdapter);
1318
1319 }
1320 /*EXT TDLS*/
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001321 return;
1322}
1323
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001324int wlan_hdd_tdls_recv_discovery_resp(hdd_adapter_t *pAdapter, u8 *mac)
Chilam NG571c65a2013-01-19 12:27:36 +05301325{
1326 hddTdlsPeer_t *curr_peer;
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001327 tdlsCtx_t *pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301328 hdd_context_t *pHddCtx;
1329
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05301330 ENTER();
1331
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301332 if ( NULL == pHddTdlsCtx )
c_hpothu7f63e882013-10-02 19:13:35 +05301333 {
1334 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05301335 FL("pHddTdlsCtx is NULL device mode = %d"), pAdapter->device_mode);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301336 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301337 }
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301338
1339 pHddCtx = WLAN_HDD_GET_CTX(pHddTdlsCtx->pAdapter);
1340
c_hpothu7f63e882013-10-02 19:13:35 +05301341 if(0 != (wlan_hdd_validate_context(pHddCtx)))
1342 {
c_hpothu7f63e882013-10-02 19:13:35 +05301343 return 0;
1344 }
Chilam NG571c65a2013-01-19 12:27:36 +05301345
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001346 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001347
1348 if (NULL == curr_peer)
c_hpothu7f63e882013-10-02 19:13:35 +05301349 {
1350 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1351 FL("curr_peer is NULL"));
Hoonki Lee387663d2013-02-05 18:08:43 -08001352 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301353 }
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001354
1355 if (pHddTdlsCtx->discovery_sent_cnt)
1356 pHddTdlsCtx->discovery_sent_cnt--;
1357
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05301358 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301359
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07001360 wlan_hdd_tdls_check_power_save_prohibited(pAdapter);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301361
1362 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001363 if (0 == pHddTdlsCtx->discovery_sent_cnt)
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07001364 {
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001365 vos_timer_stop(&pHddTdlsCtx->peerDiscoveryTimeoutTimer);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07001366 }
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001367
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05301368 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Jeff Johnson0299d0a2013-10-30 12:37:43 -07001369 "Discovery(%u) Response from " MAC_ADDRESS_STR " link_status %d",
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07001370 pHddTdlsCtx->discovery_sent_cnt, MAC_ADDR_ARRAY(curr_peer->peerMac),
1371 curr_peer->link_status);
1372
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08001373 if (eTDLS_LINK_DISCOVERING == curr_peer->link_status)
Gopichand Nakkala901e8922013-03-04 23:45:58 -08001374 {
Shailender Karmuchi13c0d082013-03-26 14:41:39 -07001375 /* Since we are here, it means Throughput threshold is alredy met. Make sure RSSI
1376 threshold is also met before setting up TDLS link*/
1377 if ((tANI_S32) curr_peer->rssi > (tANI_S32) pHddTdlsCtx->threshold_config.rssi_trigger_threshold)
1378 {
Atul Mittal115287b2014-07-08 13:26:33 +05301379 wlan_hdd_tdls_set_peer_link_status(curr_peer,
1380 eTDLS_LINK_DISCOVERED,
1381 eTDLS_LINK_SUCCESS);
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05301382 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Shailender Karmuchi13c0d082013-03-26 14:41:39 -07001383 "Rssi Threshold met: "MAC_ADDRESS_STR" rssi = %d threshold= %d" ,
1384 MAC_ADDR_ARRAY(curr_peer->peerMac), curr_peer->rssi,
1385 pHddTdlsCtx->threshold_config.rssi_trigger_threshold);
1386 cfg80211_tdls_oper_request(pAdapter->dev, curr_peer->peerMac, NL80211_TDLS_SETUP, FALSE, GFP_KERNEL);
1387 }
1388 else
1389 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05301390 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Shailender Karmuchi13c0d082013-03-26 14:41:39 -07001391 "Rssi Threshold not met: "MAC_ADDRESS_STR" rssi = %d threshold = %d ",
1392 MAC_ADDR_ARRAY(curr_peer->peerMac), curr_peer->rssi,
1393 pHddTdlsCtx->threshold_config.rssi_trigger_threshold);
Sunil Duttb0d39242014-09-10 23:54:51 +05301394
1395 /* if RSSI threshold is not met then allow further discovery
1396 * attempts by decrementing count for the last attempt
1397 */
1398 if (curr_peer->discovery_attempt)
1399 curr_peer->discovery_attempt--;
1400
Atul Mittal115287b2014-07-08 13:26:33 +05301401 wlan_hdd_tdls_set_peer_link_status(curr_peer,
1402 eTDLS_LINK_IDLE,
1403 eTDLS_LINK_UNSPECIFIED);
Shailender Karmuchi13c0d082013-03-26 14:41:39 -07001404 }
Gopichand Nakkala901e8922013-03-04 23:45:58 -08001405 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07001406 else
1407 {
1408 wlan_hdd_tdls_check_bmps(pAdapter);
1409 }
Chilam NG571c65a2013-01-19 12:27:36 +05301410
Gopichand Nakkala901e8922013-03-04 23:45:58 -08001411 curr_peer->tdls_support = eTDLS_CAP_SUPPORTED;
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05301412 EXIT();
Hoonki Lee387663d2013-02-05 18:08:43 -08001413 return 0;
Chilam NG571c65a2013-01-19 12:27:36 +05301414}
1415
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301416int wlan_hdd_tdls_set_peer_caps(hdd_adapter_t *pAdapter,
1417 u8 *mac,
Naresh Jayaram3180aa42014-02-12 21:47:26 +05301418 tCsrStaParams *StaParams,
1419 tANI_BOOLEAN isBufSta,
1420 tANI_BOOLEAN isOffChannelSupported)
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301421{
1422 hddTdlsPeer_t *curr_peer;
1423
1424 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
1425 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301426 {
1427 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1428 "%s: curr_peer is NULL", __func__);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301429 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301430 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301431
Naresh Jayaram3180aa42014-02-12 21:47:26 +05301432 curr_peer->uapsdQueues = StaParams->uapsd_queues;
1433 curr_peer->maxSp = StaParams->max_sp;
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301434 curr_peer->isBufSta = isBufSta;
Naresh Jayaram3180aa42014-02-12 21:47:26 +05301435 curr_peer->isOffChannelSupported = isOffChannelSupported;
1436
1437 vos_mem_copy(curr_peer->supported_channels,
1438 StaParams->supported_channels,
1439 StaParams->supported_channels_len);
1440
1441 curr_peer->supported_channels_len =
1442 StaParams->supported_channels_len;
1443
1444 vos_mem_copy(curr_peer->supported_oper_classes,
1445 StaParams->supported_oper_classes,
1446 StaParams->supported_oper_classes_len);
1447
1448 curr_peer->supported_oper_classes_len =
1449 StaParams->supported_oper_classes_len;
Agarwal Ashish16020c42014-12-29 22:01:11 +05301450 curr_peer->qos = StaParams->capability & CAPABILITIES_QOS_OFFSET;
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301451 return 0;
1452}
1453
1454int wlan_hdd_tdls_get_link_establish_params(hdd_adapter_t *pAdapter, u8 *mac,
1455 tCsrTdlsLinkEstablishParams* tdlsLinkEstablishParams)
1456{
1457 hddTdlsPeer_t *curr_peer;
1458
1459 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
1460 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301461 {
1462 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1463 "%s: curr_peer is NULL", __func__);
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301464 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301465 }
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301466
1467 tdlsLinkEstablishParams->isResponder = curr_peer->is_responder;
1468 tdlsLinkEstablishParams->uapsdQueues = curr_peer->uapsdQueues;
1469 tdlsLinkEstablishParams->maxSp = curr_peer->maxSp;
1470 tdlsLinkEstablishParams->isBufSta = curr_peer->isBufSta;
Naresh Jayaram3180aa42014-02-12 21:47:26 +05301471 tdlsLinkEstablishParams->isOffChannelSupported =
1472 curr_peer->isOffChannelSupported;
1473
1474 vos_mem_copy(tdlsLinkEstablishParams->supportedChannels,
1475 curr_peer->supported_channels,
1476 curr_peer->supported_channels_len);
1477
1478 tdlsLinkEstablishParams->supportedChannelsLen =
1479 curr_peer->supported_channels_len;
1480
1481 vos_mem_copy(tdlsLinkEstablishParams->supportedOperClasses,
1482 curr_peer->supported_oper_classes,
1483 curr_peer->supported_oper_classes_len);
1484
1485 tdlsLinkEstablishParams->supportedOperClassesLen =
1486 curr_peer->supported_oper_classes_len;
Agarwal Ashish16020c42014-12-29 22:01:11 +05301487 tdlsLinkEstablishParams->qos = curr_peer->qos;
1488
Gopichand Nakkala79ff85d2013-05-27 17:05:29 +05301489 return 0;
1490}
1491
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001492int wlan_hdd_tdls_set_rssi(hdd_adapter_t *pAdapter, u8 *mac, tANI_S8 rxRssi)
Chilam NG571c65a2013-01-19 12:27:36 +05301493{
1494 hddTdlsPeer_t *curr_peer;
Chilam NG571c65a2013-01-19 12:27:36 +05301495
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301496 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Hoonki Lee387663d2013-02-05 18:08:43 -08001497 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301498 {
1499 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1500 "%s: curr_peer is NULL", __func__);
Hoonki Lee387663d2013-02-05 18:08:43 -08001501 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301502 }
Chilam NG571c65a2013-01-19 12:27:36 +05301503
1504 curr_peer->rssi = rxRssi;
1505
Hoonki Lee387663d2013-02-05 18:08:43 -08001506 return 0;
Chilam NG571c65a2013-01-19 12:27:36 +05301507}
1508
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001509int wlan_hdd_tdls_set_responder(hdd_adapter_t *pAdapter, u8 *mac, tANI_U8 responder)
Hoonki Leea34dd892013-02-05 22:56:02 -08001510{
1511 hddTdlsPeer_t *curr_peer;
1512
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001513 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001514 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301515 {
1516 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1517 "%s: curr_peer is NULL", __func__);
Hoonki Leea34dd892013-02-05 22:56:02 -08001518 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301519 }
Hoonki Leea34dd892013-02-05 22:56:02 -08001520
1521 curr_peer->is_responder = responder;
1522
1523 return 0;
1524}
1525
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001526int wlan_hdd_tdls_get_responder(hdd_adapter_t *pAdapter, u8 *mac)
Hoonki Leea34dd892013-02-05 22:56:02 -08001527{
1528 hddTdlsPeer_t *curr_peer;
1529
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301530 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Gopichand Nakkala91b09262013-02-10 14:27:02 -08001531 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301532 {
1533 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1534 "%s: curr_peer is NULL", __func__);
Hoonki Leea34dd892013-02-05 22:56:02 -08001535 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301536 }
Hoonki Leea34dd892013-02-05 22:56:02 -08001537
1538 return (curr_peer->is_responder);
1539}
1540
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001541int wlan_hdd_tdls_set_signature(hdd_adapter_t *pAdapter, u8 *mac, tANI_U8 uSignature)
Hoonki Lee11f7dda2013-02-14 16:55:44 -08001542{
1543 hddTdlsPeer_t *curr_peer;
1544
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001545 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08001546 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301547 {
1548 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1549 "%s: curr_peer is NULL", __func__);
Hoonki Lee11f7dda2013-02-14 16:55:44 -08001550 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301551 }
Hoonki Lee11f7dda2013-02-14 16:55:44 -08001552
1553 curr_peer->signature = uSignature;
1554
1555 return 0;
1556}
1557
Hoonki Leea34dd892013-02-05 22:56:02 -08001558
Hoonki Lee387663d2013-02-05 18:08:43 -08001559void wlan_hdd_tdls_extract_da(struct sk_buff *skb, u8 *mac)
Chilam NG571c65a2013-01-19 12:27:36 +05301560{
Chilam NG571c65a2013-01-19 12:27:36 +05301561 memcpy(mac, skb->data, 6);
Chilam NG571c65a2013-01-19 12:27:36 +05301562}
1563
Hoonki Lee387663d2013-02-05 18:08:43 -08001564void wlan_hdd_tdls_extract_sa(struct sk_buff *skb, u8 *mac)
Chilam Ng1279e232013-01-25 15:06:52 -08001565{
Chilam Ng1279e232013-01-25 15:06:52 -08001566 memcpy(mac, skb->data+6, 6);
Chilam Ng1279e232013-01-25 15:06:52 -08001567}
1568
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001569int wlan_hdd_tdls_increment_pkt_count(hdd_adapter_t *pAdapter, u8 *mac, u8 tx)
Chilam NG571c65a2013-01-19 12:27:36 +05301570{
Hoonki Lee387663d2013-02-05 18:08:43 -08001571 hddTdlsPeer_t *curr_peer;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001572 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Chilam NG571c65a2013-01-19 12:27:36 +05301573
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001574 if (eTDLS_SUPPORT_ENABLED != pHddCtx->tdls_mode)
1575 return -1;
Hoonki Leebfee0342013-01-21 16:43:45 -08001576
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001577 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Hoonki Lee387663d2013-02-05 18:08:43 -08001578 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301579 {
c_hpothue21931b2014-09-08 14:02:14 +05301580 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
1581 FL("curr_peer is NULL"));
Chilam NG571c65a2013-01-19 12:27:36 +05301582 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301583 }
Chilam NG571c65a2013-01-19 12:27:36 +05301584
Chilam Ng1279e232013-01-25 15:06:52 -08001585 if (tx)
1586 curr_peer->tx_pkt++;
1587 else
1588 curr_peer->rx_pkt++;
Chilam NG571c65a2013-01-19 12:27:36 +05301589
Chilam NG571c65a2013-01-19 12:27:36 +05301590 return 0;
1591}
1592
Hoonki Lee27511902013-03-14 18:19:06 -07001593static int wlan_hdd_tdls_check_config(tdls_config_params_t *config)
1594{
1595 if (config->tdls > 2)
1596 {
1597 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 1st argument %d. <0...2>", __func__, config->tdls);
1598 return -1;
1599 }
1600 if (config->tx_period_t < CFG_TDLS_TX_STATS_PERIOD_MIN ||
1601 config->tx_period_t > CFG_TDLS_TX_STATS_PERIOD_MAX)
1602 {
Jeff Johnson0299d0a2013-10-30 12:37:43 -07001603 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 2nd argument %d. <%d...%ld>", __func__, config->tx_period_t,
Hoonki Lee27511902013-03-14 18:19:06 -07001604 CFG_TDLS_TX_STATS_PERIOD_MIN, CFG_TDLS_TX_STATS_PERIOD_MAX);
1605 return -1;
1606 }
1607 if (config->tx_packet_n < CFG_TDLS_TX_PACKET_THRESHOLD_MIN ||
1608 config->tx_packet_n > CFG_TDLS_TX_PACKET_THRESHOLD_MAX)
1609 {
Jeff Johnson0299d0a2013-10-30 12:37:43 -07001610 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 3rd argument %d. <%d...%ld>", __func__, config->tx_packet_n,
Hoonki Lee27511902013-03-14 18:19:06 -07001611 CFG_TDLS_TX_PACKET_THRESHOLD_MIN, CFG_TDLS_TX_PACKET_THRESHOLD_MAX);
1612 return -1;
1613 }
1614 if (config->discovery_period_t < CFG_TDLS_DISCOVERY_PERIOD_MIN ||
1615 config->discovery_period_t > CFG_TDLS_DISCOVERY_PERIOD_MAX)
1616 {
Jeff Johnson0299d0a2013-10-30 12:37:43 -07001617 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 4th argument %d. <%d...%ld>", __func__, config->discovery_period_t,
Hoonki Lee27511902013-03-14 18:19:06 -07001618 CFG_TDLS_DISCOVERY_PERIOD_MIN, CFG_TDLS_DISCOVERY_PERIOD_MAX);
1619 return -1;
1620 }
1621 if (config->discovery_tries_n < CFG_TDLS_MAX_DISCOVERY_ATTEMPT_MIN ||
1622 config->discovery_tries_n > CFG_TDLS_MAX_DISCOVERY_ATTEMPT_MAX)
1623 {
1624 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 5th argument %d. <%d...%d>", __func__, config->discovery_tries_n,
1625 CFG_TDLS_MAX_DISCOVERY_ATTEMPT_MIN, CFG_TDLS_MAX_DISCOVERY_ATTEMPT_MAX);
1626 return -1;
1627 }
1628 if (config->idle_timeout_t < CFG_TDLS_IDLE_TIMEOUT_MIN ||
1629 config->idle_timeout_t > CFG_TDLS_IDLE_TIMEOUT_MAX)
1630 {
1631 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 6th argument %d. <%d...%d>", __func__, config->idle_timeout_t,
1632 CFG_TDLS_IDLE_TIMEOUT_MIN, CFG_TDLS_IDLE_TIMEOUT_MAX);
1633 return -1;
1634 }
1635 if (config->idle_packet_n < CFG_TDLS_IDLE_PACKET_THRESHOLD_MIN ||
1636 config->idle_packet_n > CFG_TDLS_IDLE_PACKET_THRESHOLD_MAX)
1637 {
1638 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 7th argument %d. <%d...%d>", __func__, config->idle_packet_n,
1639 CFG_TDLS_IDLE_PACKET_THRESHOLD_MIN, CFG_TDLS_IDLE_PACKET_THRESHOLD_MAX);
1640 return -1;
1641 }
1642 if (config->rssi_hysteresis < CFG_TDLS_RSSI_HYSTERESIS_MIN ||
1643 config->rssi_hysteresis > CFG_TDLS_RSSI_HYSTERESIS_MAX)
1644 {
1645 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 8th argument %d. <%d...%d>", __func__, config->rssi_hysteresis,
1646 CFG_TDLS_RSSI_HYSTERESIS_MIN, CFG_TDLS_RSSI_HYSTERESIS_MAX);
1647 return -1;
1648 }
1649 if (config->rssi_trigger_threshold < CFG_TDLS_RSSI_TRIGGER_THRESHOLD_MIN ||
1650 config->rssi_trigger_threshold > CFG_TDLS_RSSI_TRIGGER_THRESHOLD_MAX)
1651 {
1652 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 9th argument %d. <%d...%d>", __func__, config->rssi_trigger_threshold,
1653 CFG_TDLS_RSSI_TRIGGER_THRESHOLD_MIN, CFG_TDLS_RSSI_TRIGGER_THRESHOLD_MAX);
1654 return -1;
1655 }
1656 if (config->rssi_teardown_threshold < CFG_TDLS_RSSI_TEARDOWN_THRESHOLD_MIN ||
1657 config->rssi_teardown_threshold > CFG_TDLS_RSSI_TEARDOWN_THRESHOLD_MAX)
1658 {
1659 hddLog(VOS_TRACE_LEVEL_ERROR, "%s invalid 10th argument %d. <%d...%d>", __func__, config->rssi_teardown_threshold,
1660 CFG_TDLS_RSSI_TEARDOWN_THRESHOLD_MIN, CFG_TDLS_RSSI_TEARDOWN_THRESHOLD_MAX);
1661 return -1;
1662 }
1663 return 0;
1664}
1665
Chilam Ng01120412013-02-19 18:32:21 -08001666int wlan_hdd_tdls_set_params(struct net_device *dev, tdls_config_params_t *config)
Chilam NG571c65a2013-01-19 12:27:36 +05301667{
Chilam Ng01120412013-02-19 18:32:21 -08001668 hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
1669 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001670 tdlsCtx_t *pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
Hoonki Lee27511902013-03-14 18:19:06 -07001671 eTDLSSupportMode req_tdls_mode;
Hoonki Leebfee0342013-01-21 16:43:45 -08001672
Hoonki Lee27511902013-03-14 18:19:06 -07001673 if (NULL == pHddTdlsCtx)
1674 {
c_hpothu7f63e882013-10-02 19:13:35 +05301675 hddLog(VOS_TRACE_LEVEL_ERROR, FL("TDLS not enabled!"));
Hoonki Lee27511902013-03-14 18:19:06 -07001676 return -1;
Chilam Ng01120412013-02-19 18:32:21 -08001677 }
Chilam NG571c65a2013-01-19 12:27:36 +05301678
Hoonki Lee27511902013-03-14 18:19:06 -07001679 if (wlan_hdd_tdls_check_config(config) != 0)
1680 {
1681 return -1;
1682 }
1683
1684 /* config->tdls is mapped to 0->1, 1->2, 2->3 */
1685 req_tdls_mode = config->tdls + 1;
1686 if (pHddCtx->tdls_mode == req_tdls_mode)
1687 {
1688 hddLog(VOS_TRACE_LEVEL_ERROR, "%s already in mode %d", __func__, config->tdls);
1689 return -1;
1690 }
1691
1692 /* copy the configuration only when given tdls mode is implicit trigger enable */
1693 if (eTDLS_SUPPORT_ENABLED == req_tdls_mode)
1694 {
Chilam Ng01120412013-02-19 18:32:21 -08001695 memcpy(&pHddTdlsCtx->threshold_config, config, sizeof(tdls_config_params_t));
1696 }
Chilam NG571c65a2013-01-19 12:27:36 +05301697
Chilam Ng01120412013-02-19 18:32:21 -08001698 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1699 "iw set tdls params: %d %d %d %d %d %d %d %d %d %d",
1700 config->tdls,
1701 config->tx_period_t,
1702 config->tx_packet_n,
1703 config->discovery_period_t,
1704 config->discovery_tries_n,
1705 config->idle_timeout_t,
1706 config->idle_packet_n,
1707 config->rssi_hysteresis,
1708 config->rssi_trigger_threshold,
1709 config->rssi_teardown_threshold);
Chilam NG571c65a2013-01-19 12:27:36 +05301710
Gopichand Nakkaladcbcf4e2013-03-23 14:32:39 -07001711 wlan_hdd_tdls_set_mode(pHddCtx, req_tdls_mode, TRUE);
Chilam Ng01120412013-02-19 18:32:21 -08001712
Chilam NG571c65a2013-01-19 12:27:36 +05301713 return 0;
1714}
1715
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001716int wlan_hdd_tdls_set_sta_id(hdd_adapter_t *pAdapter, u8 *mac, u8 staId)
Kiran V1ccee932012-12-12 14:49:46 -08001717{
Hoonki Lee387663d2013-02-05 18:08:43 -08001718 hddTdlsPeer_t *curr_peer;
Kiran V1ccee932012-12-12 14:49:46 -08001719
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001720 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Hoonki Lee387663d2013-02-05 18:08:43 -08001721 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301722 {
1723 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1724 "%s: curr_peer is NULL", __func__);
Chilam NG571c65a2013-01-19 12:27:36 +05301725 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301726 }
Chilam NG571c65a2013-01-19 12:27:36 +05301727
Hoonki Lee387663d2013-02-05 18:08:43 -08001728 curr_peer->staId = staId;
Chilam NG571c65a2013-01-19 12:27:36 +05301729
1730 return 0;
Kiran V1ccee932012-12-12 14:49:46 -08001731}
1732
Naresh Jayaram937abdf2013-11-26 19:50:25 +05301733int wlan_hdd_tdls_set_force_peer(hdd_adapter_t *pAdapter, u8 *mac,
1734 tANI_BOOLEAN forcePeer)
Sunil Dutt41de4e22013-11-14 18:09:02 +05301735{
Naresh Jayaram937abdf2013-11-26 19:50:25 +05301736 hddTdlsPeer_t *curr_peer;
Sunil Dutt41de4e22013-11-14 18:09:02 +05301737 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
1738
1739 if ((NULL == pHddCtx)) return -1;
1740
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05301741 mutex_lock(&pHddCtx->tdls_lock);
1742
Naresh Jayaram937abdf2013-11-26 19:50:25 +05301743 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, FALSE);
1744 if (curr_peer == NULL)
Sunil Dutt41de4e22013-11-14 18:09:02 +05301745 goto error;
Naresh Jayaram937abdf2013-11-26 19:50:25 +05301746 curr_peer->isForcedPeer = forcePeer;
Naresh Jayaramca7bc3a2014-02-04 23:03:04 +05301747
1748 mutex_unlock(&pHddCtx->tdls_lock);
1749 return 0;
Sunil Dutt41de4e22013-11-14 18:09:02 +05301750error:
1751 mutex_unlock(&pHddCtx->tdls_lock);
1752 return -1;
1753}
1754
Hoonki Lee387663d2013-02-05 18:08:43 -08001755/* if peerMac is found, then it returns pointer to hddTdlsPeer_t
1756 otherwise, it returns NULL
1757*/
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301758hddTdlsPeer_t *wlan_hdd_tdls_find_peer(hdd_adapter_t *pAdapter, u8 *mac,
1759 tANI_BOOLEAN mutexLock)
Kiran V1ccee932012-12-12 14:49:46 -08001760{
Hoonki Lee387663d2013-02-05 18:08:43 -08001761 u8 key;
1762 struct list_head *pos;
1763 struct list_head *head;
1764 hddTdlsPeer_t *curr_peer;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001765 tdlsCtx_t *pHddTdlsCtx;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05301766 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Hoonki Lee387663d2013-02-05 18:08:43 -08001767
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05301768 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05301769 if(0 != (wlan_hdd_validate_context(pHddCtx)))
1770 {
c_hpothu7f63e882013-10-02 19:13:35 +05301771 return 0;
1772 }
Hoonki Lee387663d2013-02-05 18:08:43 -08001773
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301774 if ( mutexLock )
Hoonki Lee387663d2013-02-05 18:08:43 -08001775 {
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05301776 mutex_lock(&pHddCtx->tdls_lock);
Hoonki Lee387663d2013-02-05 18:08:43 -08001777 }
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001778 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08001779 if (NULL == pHddTdlsCtx)
1780 {
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301781 if ( mutexLock )
1782 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08001783 return NULL;
1784 }
1785
1786 key = wlan_hdd_tdls_hash_key(mac);
1787
1788 head = &pHddTdlsCtx->peer_list[key];
Hoonki Lee387663d2013-02-05 18:08:43 -08001789
1790 list_for_each(pos, head) {
1791 curr_peer = list_entry (pos, hddTdlsPeer_t, node);
1792 if (!memcmp(mac, curr_peer->peerMac, 6)) {
1793 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
1794 "findTdlsPeer: found staId %d", curr_peer->staId);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301795 if ( mutexLock )
1796 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Lee387663d2013-02-05 18:08:43 -08001797 return curr_peer;
1798 }
1799 }
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301800 if ( mutexLock )
1801 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05301802
1803 EXIT();
Hoonki Lee387663d2013-02-05 18:08:43 -08001804 return NULL;
1805}
1806
Hoonki Leea6d49be2013-04-05 09:43:25 -07001807hddTdlsPeer_t *wlan_hdd_tdls_find_all_peer(hdd_context_t *pHddCtx, u8 *mac)
1808{
1809 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
1810 hdd_adapter_t *pAdapter = NULL;
1811 tdlsCtx_t *pHddTdlsCtx = NULL;
1812 hddTdlsPeer_t *curr_peer= NULL;
1813 VOS_STATUS status = 0;
1814
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05301815 mutex_lock(&pHddCtx->tdls_lock);
Hoonki Leea6d49be2013-04-05 09:43:25 -07001816 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
1817 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
1818 {
1819 pAdapter = pAdapterNode->pAdapter;
1820
1821 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
1822 if (NULL != pHddTdlsCtx)
1823 {
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301824 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, FALSE);
Hoonki Leea6d49be2013-04-05 09:43:25 -07001825 if (curr_peer)
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301826 {
1827 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Leea6d49be2013-04-05 09:43:25 -07001828 return curr_peer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301829 }
Hoonki Leea6d49be2013-04-05 09:43:25 -07001830 }
1831 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
1832 pAdapterNode = pNext;
1833 }
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05301834 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Leea6d49be2013-04-05 09:43:25 -07001835 return curr_peer;
1836}
1837
1838
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001839int wlan_hdd_tdls_reset_peer(hdd_adapter_t *pAdapter, u8 *mac)
Hoonki Lee387663d2013-02-05 18:08:43 -08001840{
Chilam Ng01120412013-02-19 18:32:21 -08001841 hdd_context_t *pHddCtx;
Chilam NG571c65a2013-01-19 12:27:36 +05301842 hddTdlsPeer_t *curr_peer;
Kiran V1ccee932012-12-12 14:49:46 -08001843
Chilam Ng01120412013-02-19 18:32:21 -08001844 pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
1845
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001846 curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
Hoonki Lee387663d2013-02-05 18:08:43 -08001847 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05301848 {
1849 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1850 "%s: curr_peer is NULL", __func__);
Hoonki Lee387663d2013-02-05 18:08:43 -08001851 return -1;
c_hpothu7f63e882013-10-02 19:13:35 +05301852 }
Chilam NG571c65a2013-01-19 12:27:36 +05301853
Atul Mittal115287b2014-07-08 13:26:33 +05301854 wlan_hdd_tdls_set_peer_link_status(curr_peer,
1855 eTDLS_LINK_IDLE,
1856 eTDLS_LINK_UNSPECIFIED);
Hoonki Leecdd8e962013-01-20 00:45:46 -08001857 curr_peer->staId = 0;
Hoonki Lee387663d2013-02-05 18:08:43 -08001858
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05301859 /* Throughput Monitor shall disable the split scan when
1860 * TDLS scan coexistance is disabled.At this point of time
1861 * since TDLS scan coexistance is not meeting the criteria
1862 * to be operational, explicitly make it false to enable
1863 * throughput monitor takes the control of split scan.
1864 */
1865 if (pHddCtx->isTdlsScanCoexistence == TRUE)
1866 {
1867 pHddCtx->isTdlsScanCoexistence = FALSE;
1868 }
1869
Chilam Ng01120412013-02-19 18:32:21 -08001870 if(eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode) {
Chilam Nga75d8b62013-01-29 01:35:59 -08001871 vos_timer_stop( &curr_peer->peerIdleTimer );
Chilam Nga75d8b62013-01-29 01:35:59 -08001872 }
Hoonki Lee387663d2013-02-05 18:08:43 -08001873 return 0;
Hoonki Leecdd8e962013-01-20 00:45:46 -08001874}
1875
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07001876/* Caller has to take the lock before calling this function */
Hoonki Lee27511902013-03-14 18:19:06 -07001877static void wlan_tdd_tdls_reset_tx_rx(tdlsCtx_t *pHddTdlsCtx)
1878{
1879 int i;
1880 struct list_head *head;
1881 hddTdlsPeer_t *tmp;
1882 struct list_head *pos, *q;
1883
Hoonki Lee27511902013-03-14 18:19:06 -07001884 for (i = 0; i < 256; i++) {
1885 head = &pHddTdlsCtx->peer_list[i];
1886 list_for_each_safe (pos, q, head) {
1887 tmp = list_entry(pos, hddTdlsPeer_t, node);
1888 tmp->tx_pkt = 0;
1889 tmp->rx_pkt = 0;
1890 }
1891 }
Hoonki Lee27511902013-03-14 18:19:06 -07001892
1893 return ;
1894}
1895
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07001896/* Caller has to take the lock before calling this function */
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001897static tANI_S32 wlan_hdd_tdls_peer_reset_discovery_processed(tdlsCtx_t *pHddTdlsCtx)
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001898{
1899 int i;
1900 struct list_head *head;
1901 hddTdlsPeer_t *tmp;
1902 struct list_head *pos, *q;
1903
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001904 pHddTdlsCtx->discovery_peer_cnt = 0;
1905
1906 for (i = 0; i < 256; i++) {
1907 head = &pHddTdlsCtx->peer_list[i];
1908 list_for_each_safe (pos, q, head) {
1909 tmp = list_entry(pos, hddTdlsPeer_t, node);
1910 tmp->discovery_processed = 0;
1911 }
1912 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001913
1914 return 0;
1915}
1916
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001917static tANI_S32 wlan_hdd_get_tdls_discovery_peer_cnt(tdlsCtx_t *pHddTdlsCtx)
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001918{
1919 int i;
1920 struct list_head *head;
1921 struct list_head *pos, *q;
1922 int discovery_peer_cnt=0;
1923 hddTdlsPeer_t *tmp;
1924
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08001925 /*
1926 * This function expects the callers to acquire the Mutex.
1927 */
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001928
1929 for (i = 0; i < 256; i++) {
1930 head = &pHddTdlsCtx->peer_list[i];
1931 list_for_each_safe (pos, q, head) {
1932 tmp = list_entry(pos, hddTdlsPeer_t, node);
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05301933 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Chilam Ng01120412013-02-19 18:32:21 -08001934 "%s, %d, " MAC_ADDRESS_STR, __func__, i,
1935 MAC_ADDR_ARRAY(tmp->peerMac));
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001936 discovery_peer_cnt++;
1937 }
1938 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -08001939 return discovery_peer_cnt;
1940}
1941
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001942tANI_U16 wlan_hdd_tdlsConnectedPeers(hdd_adapter_t *pAdapter)
Lee Hoonkic1262f22013-01-24 21:59:00 -08001943{
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +05301944 hdd_context_t *pHddCtx = NULL;
1945
1946 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
1947 {
1948 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
1949 FL("invalid pAdapter: %p"), pAdapter);
1950 return 0;
1951 }
1952 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001953
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05301954 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05301955 if(0 != (wlan_hdd_validate_context(pHddCtx)))
1956 {
Gopichand Nakkalab977a972013-02-18 19:15:09 -08001957 return 0;
c_hpothu7f63e882013-10-02 19:13:35 +05301958 }
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05301959 EXIT();
Gopichand Nakkala4327a152013-03-04 23:22:42 -08001960 return pHddCtx->connected_peer_count;
Lee Hoonkic1262f22013-01-24 21:59:00 -08001961}
Chilam Ng16a2a1c2013-01-29 01:27:29 -08001962
Pradeep Reddy POTTETIe309c152015-02-06 13:21:07 +05301963hddTdlsPeer_t *wlan_hdd_tdls_get_connected_peer(hdd_adapter_t *pAdapter)
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05301964{
1965 int i;
1966 struct list_head *head;
1967 struct list_head *pos;
1968 hddTdlsPeer_t *curr_peer = NULL;
1969 tdlsCtx_t *pHddTdlsCtx;
1970 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
1971
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05301972 ENTER();
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05301973 if(0 != (wlan_hdd_validate_context(pHddCtx)))
1974 {
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05301975 return NULL;
1976 }
1977
1978 mutex_lock(&pHddCtx->tdls_lock);
1979 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
1980 if (NULL == pHddTdlsCtx) {
1981 mutex_unlock(&pHddCtx->tdls_lock);
1982 return NULL;
1983 }
1984 for (i = 0; i < 256; i++) {
1985 head = &pHddTdlsCtx->peer_list[i];
1986
1987 list_for_each(pos, head) {
1988 curr_peer= list_entry (pos, hddTdlsPeer_t, node);
Pradeep Reddy POTTETI8a623132014-06-26 16:07:06 +05301989 if (curr_peer && (curr_peer->link_status == eTDLS_LINK_CONNECTED))
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05301990 {
1991 mutex_unlock(&pHddCtx->tdls_lock);
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05301992 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETI8a623132014-06-26 16:07:06 +05301993 "%s: " MAC_ADDRESS_STR " eTDLS_LINK_CONNECTED",
1994 __func__, MAC_ADDR_ARRAY(curr_peer->peerMac));
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05301995 return curr_peer;
1996 }
1997 }
1998 }
1999 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302000
2001 EXIT();
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302002 return NULL;
2003}
2004
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002005int wlan_hdd_tdls_get_all_peers(hdd_adapter_t *pAdapter, char *buf, int buflen)
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002006{
2007 int i;
2008 int len, init_len;
Hoonki Lee387663d2013-02-05 18:08:43 -08002009 struct list_head *head;
2010 struct list_head *pos;
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002011 hddTdlsPeer_t *curr_peer;
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002012 tdlsCtx_t *pHddTdlsCtx;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302013 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2014
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302015 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302016 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2017 {
c_hpothu7f63e882013-10-02 19:13:35 +05302018 return 0;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302019 }
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002020
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002021 init_len = buflen;
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002022 len = scnprintf(buf, buflen, "\n%-18s%-3s%-4s%-3s%-5s\n",
2023 "MAC", "Id", "cap", "up", "RSSI");
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002024 buf += len;
2025 buflen -= len;
2026 /* 1234567890123456789012345678901234567 */
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002027 len = scnprintf(buf, buflen, "---------------------------------\n");
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002028 buf += len;
2029 buflen -= len;
2030
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05302031 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002032 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002033 if (NULL == pHddTdlsCtx) {
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302034 mutex_unlock(&pHddCtx->tdls_lock);
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002035 len = scnprintf(buf, buflen, "TDLS not enabled\n");
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002036 return len;
2037 }
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002038 for (i = 0; i < 256; i++) {
Hoonki Lee387663d2013-02-05 18:08:43 -08002039 head = &pHddTdlsCtx->peer_list[i];
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002040
Hoonki Lee387663d2013-02-05 18:08:43 -08002041 list_for_each(pos, head) {
2042 curr_peer= list_entry (pos, hddTdlsPeer_t, node);
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002043
Hoonki Lee387663d2013-02-05 18:08:43 -08002044 if (buflen < 32+1)
2045 break;
Sameer Thalappilb0a30232013-09-27 15:37:48 -07002046 len = scnprintf(buf, buflen,
Chilam Ng01120412013-02-19 18:32:21 -08002047 MAC_ADDRESS_STR"%3d%4s%3s%5d\n",
2048 MAC_ADDR_ARRAY(curr_peer->peerMac),
Hoonki Lee387663d2013-02-05 18:08:43 -08002049 curr_peer->staId,
2050 (curr_peer->tdls_support == eTDLS_CAP_SUPPORTED) ? "Y":"N",
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002051 TDLS_IS_CONNECTED(curr_peer) ? "Y":"N",
Hoonki Lee387663d2013-02-05 18:08:43 -08002052 curr_peer->rssi);
2053 buf += len;
2054 buflen -= len;
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002055 }
2056 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302057 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302058
2059 EXIT();
Chilam Ng16a2a1c2013-01-29 01:27:29 -08002060 return init_len-buflen;
2061}
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002062
2063void wlan_hdd_tdls_connection_callback(hdd_adapter_t *pAdapter)
2064{
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302065 tdlsCtx_t *pHddTdlsCtx;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302066 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkala9d76a9b2013-02-28 15:38:37 -08002067
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302068 if ((NULL == pHddCtx))
c_hpothu7f63e882013-10-02 19:13:35 +05302069 {
Agarwal Ashishbf98caf2014-03-25 13:29:11 +05302070 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
2071 FL("pHddCtx or pHddTdlsCtx points to NULL"));
c_hpothu7f63e882013-10-02 19:13:35 +05302072 return;
2073 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302074
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05302075 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07002076
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302077 if (0 != wlan_hdd_sta_tdls_init(pAdapter))
2078 {
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302079 mutex_unlock(&pHddCtx->tdls_lock);
Hema Aparna Medicharla8bb6f782015-03-09 12:35:05 +05302080 hddLog(VOS_TRACE_LEVEL_ERROR,"%s: wlan_hdd_sta_tdls_init failed",__func__);
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302081 return;
2082 }
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302083
2084 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2085 if ((NULL == pHddTdlsCtx))
2086 {
Hema Aparna Medicharla8bb6f782015-03-09 12:35:05 +05302087 mutex_unlock(&pHddCtx->tdls_lock);
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302088 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
2089 FL("pHddCtx or pHddTdlsCtx points to NULL device mode = %d"), pAdapter->device_mode);
Mahesh A Saptasagar36cdc802015-01-07 18:41:17 +05302090 return;
2091 }
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302092 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002093 "%s, update %d discover %d", __func__,
2094 pHddTdlsCtx->threshold_config.tx_period_t,
2095 pHddTdlsCtx->threshold_config.discovery_period_t);
2096
Gopichand Nakkala9d76a9b2013-02-28 15:38:37 -08002097 if (eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode)
2098 {
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002099 wlan_hdd_tdls_peer_reset_discovery_processed(pHddTdlsCtx);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002100 pHddTdlsCtx->discovery_sent_cnt = 0;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002101 wlan_hdd_tdls_check_power_save_prohibited(pHddTdlsCtx->pAdapter);
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002102
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002103#ifdef FEATURE_WLAN_TDLS_INTERNAL
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002104 wlan_hdd_tdls_timer_restart(pHddTdlsCtx->pAdapter,
2105 &pHddTdlsCtx->peerDiscoverTimer,
2106 pHddTdlsCtx->threshold_config.discovery_period_t);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002107#endif
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002108 wlan_hdd_tdls_timer_restart(pHddTdlsCtx->pAdapter,
2109 &pHddTdlsCtx->peerUpdateTimer,
2110 pHddTdlsCtx->threshold_config.tx_period_t);
Gopichand Nakkala9d76a9b2013-02-28 15:38:37 -08002111 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302112 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002113
2114}
2115
2116void wlan_hdd_tdls_disconnection_callback(hdd_adapter_t *pAdapter)
2117{
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002118 tdlsCtx_t *pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302119 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2120
Deepthi Gowribfd17132014-11-14 17:59:04 +05302121 if (NULL == pHddCtx)
c_hpothu7f63e882013-10-02 19:13:35 +05302122 {
2123 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Deepthi Gowribfd17132014-11-14 17:59:04 +05302124 FL(" pHddCtx points to NULL"));
c_hpothu7f63e882013-10-02 19:13:35 +05302125 return;
2126 }
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002127
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302128 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"%s", __func__);
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002129
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002130 if (NULL == pHddTdlsCtx)
2131 {
Hema Aparna Medicharla8bb6f782015-03-09 12:35:05 +05302132 mutex_unlock(&pHddCtx->tdls_lock);
c_hpothu7f63e882013-10-02 19:13:35 +05302133 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2134 FL("pHddTdlsCtx is NULL"));
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002135 return;
2136 }
Masti, Narayanraddide96b992015-01-08 13:00:58 +05302137
Pradeep Reddy POTTETI2d4d5c42015-03-03 14:34:19 +05302138 mutex_lock(&pHddCtx->tdls_lock);
Masti, Narayanraddide96b992015-01-08 13:00:58 +05302139
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002140 pHddTdlsCtx->discovery_sent_cnt = 0;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002141 wlan_hdd_tdls_check_power_save_prohibited(pHddTdlsCtx->pAdapter);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002142
Pradeep Reddy POTTETI2d4d5c42015-03-03 14:34:19 +05302143 wlan_hdd_tdls_exit(pAdapter, TRUE);
Gopichand Nakkalaeb69b602013-02-27 11:40:31 -08002144
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302145 mutex_unlock(&pHddCtx->tdls_lock);
Gopichand Nakkalac3694582013-02-13 20:51:22 -08002146}
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002147
2148void wlan_hdd_tdls_mgmt_completion_callback(hdd_adapter_t *pAdapter, tANI_U32 statusCode)
2149{
2150 pAdapter->mgmtTxCompletionStatus = statusCode;
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302151 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2152 "%s: Mgmt TX Completion %d",__func__, statusCode);
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002153 complete(&pAdapter->tdls_mgmt_comp);
2154}
2155
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002156void wlan_hdd_tdls_increment_peer_count(hdd_adapter_t *pAdapter)
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002157{
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002158 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002159
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302160 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302161 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2162 {
c_hpothu7f63e882013-10-02 19:13:35 +05302163 return;
2164 }
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002165
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05302166 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302167
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002168 pHddCtx->connected_peer_count++;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002169 wlan_hdd_tdls_check_power_save_prohibited(pAdapter);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002170
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302171 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: %d",
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002172 __func__, pHddCtx->connected_peer_count);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302173
2174 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302175
2176 EXIT();
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002177}
2178
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002179void wlan_hdd_tdls_decrement_peer_count(hdd_adapter_t *pAdapter)
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002180{
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002181 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002182
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302183 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302184 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2185 {
c_hpothu7f63e882013-10-02 19:13:35 +05302186 return;
2187 }
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002188
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05302189 mutex_lock(&pHddCtx->tdls_lock);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302190
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002191 if (pHddCtx->connected_peer_count)
2192 pHddCtx->connected_peer_count--;
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002193 wlan_hdd_tdls_check_power_save_prohibited(pAdapter);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002194
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302195 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: %d",
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002196 __func__, pHddCtx->connected_peer_count);
2197
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302198 mutex_unlock(&pHddCtx->tdls_lock);
2199
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302200 EXIT();
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002201}
2202
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002203void wlan_hdd_tdls_check_bmps(hdd_adapter_t *pAdapter)
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002204{
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +05302205
2206 tdlsCtx_t *pHddTdlsCtx = NULL;
2207 hdd_context_t *pHddCtx = NULL;
Hoonki Lee14621352013-04-16 17:51:19 -07002208 hddTdlsPeer_t *curr_peer;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002209
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +05302210 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
2211 {
2212 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2213 FL("invalid pAdapter: %p"), pAdapter);
2214 return;
2215 }
2216
2217 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2218 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2219
c_hpothu7f63e882013-10-02 19:13:35 +05302220 if ((NULL == pHddCtx) || (NULL == pHddTdlsCtx))
2221 {
Sushant Kaushik125ae692014-11-25 17:38:48 +05302222 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
c_hpothu7f63e882013-10-02 19:13:35 +05302223 FL(" pHddCtx or pHddTdlsCtx points to NULL"));
2224 return;
2225 }
Gopichand Nakkala4327a152013-03-04 23:22:42 -08002226
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302227 curr_peer = wlan_hdd_tdls_is_progress(pHddCtx, NULL, 0, TRUE);
Hoonki Lee14621352013-04-16 17:51:19 -07002228 if (NULL != curr_peer)
2229 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302230 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee14621352013-04-16 17:51:19 -07002231 "%s: tdls in progress. Dont check for BMPS " MAC_ADDRESS_STR,
2232 __func__, MAC_ADDR_ARRAY (curr_peer->peerMac));
2233 return;
2234 }
2235
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002236 if ((TDLS_CTX_MAGIC != pHddCtx->tdls_scan_ctxt.magic) &&
2237 (0 == pHddCtx->connected_peer_count) &&
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002238 (0 == pHddTdlsCtx->discovery_sent_cnt))
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002239 {
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002240 if (FALSE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pAdapter)))
2241 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302242 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_WARN,
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002243 "%s: No TDLS peer connected/discovery sent. Enable BMPS",
2244 __func__);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002245 hdd_enable_bmps_imps(pHddCtx);
2246 }
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002247 }
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002248 else
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002249 {
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002250 if (TRUE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pAdapter)))
2251 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302252 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002253 "%s: TDLS peer connected. Disable BMPS", __func__);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002254 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
2255 }
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002256 }
2257 return;
2258}
2259
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002260u8 wlan_hdd_tdls_is_peer_progress(hdd_adapter_t *pAdapter, u8 *mac)
2261{
2262 hddTdlsPeer_t *curr_peer;
2263
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302264 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002265 if (curr_peer == NULL)
c_hpothu7f63e882013-10-02 19:13:35 +05302266 {
2267 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2268 "%s: curr_peer is NULL", __func__);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002269 return 0;
c_hpothu7f63e882013-10-02 19:13:35 +05302270 }
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002271
2272 return (eTDLS_LINK_CONNECTING == curr_peer->link_status);
2273}
2274
Hoonki Leefb8df672013-04-10 18:20:34 -07002275/* return pointer to hddTdlsPeer_t if TDLS is ongoing. Otherwise return NULL.
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002276 * mac - if NULL check for all the peer list, otherwise, skip this mac when skip_self is TRUE
2277 * skip_self - if TRUE, skip this mac. otherwise, check all the peer list. if
2278 mac is NULL, this argument is ignored, and check for all the peer list.
2279 */
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302280static hddTdlsPeer_t *wlan_hdd_tdls_find_progress_peer(hdd_adapter_t *pAdapter, u8 *mac, u8 skip_self)
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002281{
2282 int i;
2283 struct list_head *head;
2284 hddTdlsPeer_t *curr_peer;
2285 struct list_head *pos;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302286 tdlsCtx_t *pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);;
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302287
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302288 if (NULL == pHddTdlsCtx)
c_hpothu7f63e882013-10-02 19:13:35 +05302289 {
2290 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2291 FL("pHddTdlsCtx is NULL"));
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302292 return NULL;
c_hpothu7f63e882013-10-02 19:13:35 +05302293 }
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302294
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002295 for (i = 0; i < 256; i++) {
2296 head = &pHddTdlsCtx->peer_list[i];
2297 list_for_each(pos, head) {
2298 curr_peer = list_entry (pos, hddTdlsPeer_t, node);
2299 if (skip_self && mac && !memcmp(mac, curr_peer->peerMac, 6)) {
2300 continue;
2301 }
2302 else
2303 {
Gopichand Nakkala8b00c632013-03-08 19:47:52 -08002304 if (eTDLS_LINK_CONNECTING == curr_peer->link_status)
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002305 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302306 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002307 "%s:" MAC_ADDRESS_STR " eTDLS_LINK_CONNECTING",
Gopichand Nakkalac87400e2013-03-13 18:51:00 -07002308 __func__, MAC_ADDR_ARRAY(curr_peer->peerMac));
Hoonki Leefb8df672013-04-10 18:20:34 -07002309 return curr_peer;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002310 }
2311 }
2312 }
2313 }
Hoonki Leefb8df672013-04-10 18:20:34 -07002314 return NULL;
2315}
2316
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302317hddTdlsPeer_t *wlan_hdd_tdls_is_progress(hdd_context_t *pHddCtx, u8 *mac,
2318 u8 skip_self, tANI_BOOLEAN mutexLock)
Hoonki Leefb8df672013-04-10 18:20:34 -07002319{
2320 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
2321 hdd_adapter_t *pAdapter = NULL;
2322 tdlsCtx_t *pHddTdlsCtx = NULL;
2323 hddTdlsPeer_t *curr_peer= NULL;
2324 VOS_STATUS status = 0;
2325
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302326 if (mutexLock)
2327 {
2328 mutex_lock(&pHddCtx->tdls_lock);
2329 }
Hoonki Leefb8df672013-04-10 18:20:34 -07002330 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
2331 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
2332 {
2333 pAdapter = pAdapterNode->pAdapter;
2334
2335 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2336 if (NULL != pHddTdlsCtx)
2337 {
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302338 curr_peer = wlan_hdd_tdls_find_progress_peer(pAdapter, mac, skip_self);
Hoonki Leefb8df672013-04-10 18:20:34 -07002339 if (curr_peer)
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302340 {
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302341 if (mutexLock)
2342 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Leefb8df672013-04-10 18:20:34 -07002343 return curr_peer;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302344 }
Hoonki Leefb8df672013-04-10 18:20:34 -07002345 }
2346 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
2347 pAdapterNode = pNext;
2348 }
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302349 if (mutexLock)
2350 mutex_unlock(&pHddCtx->tdls_lock);
Hoonki Leefb8df672013-04-10 18:20:34 -07002351 return NULL;
Gopichand Nakkalab977a972013-02-18 19:15:09 -08002352}
Hoonki Lee27511902013-03-14 18:19:06 -07002353
2354static void wlan_hdd_tdls_implicit_disable(tdlsCtx_t *pHddTdlsCtx)
2355{
Hoonki Lee27511902013-03-14 18:19:06 -07002356 wlan_hdd_tdls_timers_stop(pHddTdlsCtx);
Hoonki Lee27511902013-03-14 18:19:06 -07002357}
2358
2359static void wlan_hdd_tdls_implicit_enable(tdlsCtx_t *pHddTdlsCtx)
2360{
2361 wlan_hdd_tdls_peer_reset_discovery_processed(pHddTdlsCtx);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002362 pHddTdlsCtx->discovery_sent_cnt = 0;
Hoonki Lee27511902013-03-14 18:19:06 -07002363 wlan_tdd_tdls_reset_tx_rx(pHddTdlsCtx);
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002364 wlan_hdd_tdls_check_power_save_prohibited(pHddTdlsCtx->pAdapter);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002365
Hoonki Lee27511902013-03-14 18:19:06 -07002366
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002367#ifdef FEATURE_WLAN_TDLS_INTERNAL
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002368 wlan_hdd_tdls_timer_restart(pHddTdlsCtx->pAdapter,
2369 &pHddTdlsCtx->peerDiscoverTimer,
2370 pHddTdlsCtx->threshold_config.discovery_period_t);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002371#endif
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002372 wlan_hdd_tdls_timer_restart(pHddTdlsCtx->pAdapter,
2373 &pHddTdlsCtx->peerUpdateTimer,
2374 pHddTdlsCtx->threshold_config.tx_period_t);
Hoonki Lee27511902013-03-14 18:19:06 -07002375}
2376
Gopichand Nakkaladcbcf4e2013-03-23 14:32:39 -07002377void wlan_hdd_tdls_set_mode(hdd_context_t *pHddCtx,
2378 eTDLSSupportMode tdls_mode,
2379 v_BOOL_t bUpdateLast)
Hoonki Lee27511902013-03-14 18:19:06 -07002380{
2381 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
2382 VOS_STATUS status;
2383 hdd_adapter_t *pAdapter;
2384 tdlsCtx_t *pHddTdlsCtx;
2385
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302386 ENTER();
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302387 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2388 "%s mode %d", __func__, (int)tdls_mode);
c_hpothu7f63e882013-10-02 19:13:35 +05302389
2390 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2391 {
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302392 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302393 }
Hoonki Lee27511902013-03-14 18:19:06 -07002394
Rajesh Chauhana34c6e62014-03-25 16:37:58 +05302395 mutex_lock(&pHddCtx->tdls_lock);
Gopichand Nakkala638ebc72013-03-21 18:04:02 -07002396
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002397 if (pHddCtx->tdls_mode == tdls_mode)
2398 {
Hema Aparna Medicharla8bb6f782015-03-09 12:35:05 +05302399 mutex_unlock(&pHddCtx->tdls_lock);
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302400 hddLog(VOS_TRACE_LEVEL_INFO, "%s already in mode %d", __func__,
2401 (int)tdls_mode);
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002402 return;
2403 }
2404
Hoonki Lee27511902013-03-14 18:19:06 -07002405 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
2406
2407 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
2408 {
2409 pAdapter = pAdapterNode->pAdapter;
Hoonki Leea6d49be2013-04-05 09:43:25 -07002410 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2411 if (NULL != pHddTdlsCtx)
Hoonki Lee27511902013-03-14 18:19:06 -07002412 {
Hoonki Leea6d49be2013-04-05 09:43:25 -07002413 if(eTDLS_SUPPORT_ENABLED == tdls_mode)
2414 wlan_hdd_tdls_implicit_enable(pHddTdlsCtx);
2415 else if((eTDLS_SUPPORT_DISABLED == tdls_mode) ||
2416 (eTDLS_SUPPORT_EXPLICIT_TRIGGER_ONLY == tdls_mode))
2417 wlan_hdd_tdls_implicit_disable(pHddTdlsCtx);
Hoonki Lee27511902013-03-14 18:19:06 -07002418 }
2419 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
2420 pAdapterNode = pNext;
2421 }
Gopichand Nakkaladcbcf4e2013-03-23 14:32:39 -07002422 if(bUpdateLast)
2423 {
2424 pHddCtx->tdls_mode_last = tdls_mode;
2425 }
2426 else
2427 {
2428 pHddCtx->tdls_mode_last = pHddCtx->tdls_mode;
2429 }
Hoonki Lee27511902013-03-14 18:19:06 -07002430 pHddCtx->tdls_mode = tdls_mode;
Gopichand Nakkaladcbcf4e2013-03-23 14:32:39 -07002431
Madan Mohan Koyyalamudi263cec12013-10-07 10:57:50 +05302432 mutex_unlock(&pHddCtx->tdls_lock);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302433
2434 EXIT();
Hoonki Lee27511902013-03-14 18:19:06 -07002435}
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002436
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302437static
2438void wlan_hdd_tdls_implicit_send_discovery_request(tdlsCtx_t * pHddTdlsCtx)
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002439{
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302440 hdd_context_t *pHddCtx = NULL;
2441 hddTdlsPeer_t *curr_peer = NULL, *temp_peer = NULL;
Hoonki Leed37cbb32013-04-20 00:31:14 -07002442
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302443 ENTER();
Hoonki Leed37cbb32013-04-20 00:31:14 -07002444 if (NULL == pHddTdlsCtx)
c_hpothu7f63e882013-10-02 19:13:35 +05302445 {
2446 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2447 FL("pHddTdlsCtx is NULL"));
Hoonki Leed37cbb32013-04-20 00:31:14 -07002448 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302449 }
Hoonki Leed37cbb32013-04-20 00:31:14 -07002450
Hoonki Leed37cbb32013-04-20 00:31:14 -07002451 pHddCtx = WLAN_HDD_GET_CTX(pHddTdlsCtx->pAdapter);
Hoonki Leefb8df672013-04-10 18:20:34 -07002452
c_hpothu7f63e882013-10-02 19:13:35 +05302453 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2454 {
Hoonki Leefb8df672013-04-10 18:20:34 -07002455 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302456 }
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002457
Hoonki Leed37cbb32013-04-20 00:31:14 -07002458 curr_peer = pHddTdlsCtx->curr_candidate;
Hoonki Leed37cbb32013-04-20 00:31:14 -07002459 if (NULL == curr_peer)
c_hpothu7f63e882013-10-02 19:13:35 +05302460 {
2461 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2462 FL("curr_peer is NULL"));
2463
Hoonki Leed37cbb32013-04-20 00:31:14 -07002464 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302465 }
Hoonki Leed37cbb32013-04-20 00:31:14 -07002466
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002467 if (TRUE == sme_IsPmcBmps(WLAN_HDD_GET_HAL_CTX(pHddTdlsCtx->pAdapter)))
2468 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302469 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2470 "%s: Disable BMPS", __func__);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002471 hdd_disable_bmps_imps(pHddCtx, WLAN_HDD_INFRA_STATION);
2472 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002473
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302474 /* This function is called in mutex_lock */
2475 temp_peer = wlan_hdd_tdls_is_progress(pHddCtx, NULL, 0, FALSE);
Hoonki Leefb8df672013-04-10 18:20:34 -07002476 if (NULL != temp_peer)
2477 {
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302478 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2479 "%s: " MAC_ADDRESS_STR " ongoing. pre_setup ignored",
2480 __func__, MAC_ADDR_ARRAY(temp_peer->peerMac));
Hoonki Leed37cbb32013-04-20 00:31:14 -07002481 goto done;
Hoonki Leefb8df672013-04-10 18:20:34 -07002482 }
2483
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002484 if (eTDLS_CAP_UNKNOWN != curr_peer->tdls_support)
Atul Mittal115287b2014-07-08 13:26:33 +05302485 wlan_hdd_tdls_set_peer_link_status(curr_peer,
2486 eTDLS_LINK_DISCOVERING,
2487 eTDLS_LINK_SUCCESS);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002488
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302489 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2490 "%s: Implicit TDLS, Send Discovery request event", __func__);
Hoonki Leed37cbb32013-04-20 00:31:14 -07002491
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302492 cfg80211_tdls_oper_request(pHddTdlsCtx->pAdapter->dev,
2493 curr_peer->peerMac,
2494 NL80211_TDLS_DISCOVERY_REQ,
2495 FALSE,
2496 GFP_KERNEL);
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002497 pHddTdlsCtx->discovery_sent_cnt++;
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302498
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002499 wlan_hdd_tdls_check_power_save_prohibited(pHddTdlsCtx->pAdapter);
Madan Mohan Koyyalamudi96797442013-10-08 16:04:42 +05302500
Pradeep Reddy POTTETI219ced32014-11-14 16:33:57 +05302501 wlan_hdd_tdls_timer_restart(pHddTdlsCtx->pAdapter,
2502 &pHddTdlsCtx->peerDiscoveryTimeoutTimer,
2503 pHddTdlsCtx->threshold_config.tx_period_t - TDLS_DISCOVERY_TIMEOUT_BEFORE_UPDATE);
2504
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302505 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2506 "%s: discovery count %u timeout %u msec",
2507 __func__, pHddTdlsCtx->discovery_sent_cnt,
2508 pHddTdlsCtx->threshold_config.tx_period_t - TDLS_DISCOVERY_TIMEOUT_BEFORE_UPDATE);
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002509
Hoonki Leed37cbb32013-04-20 00:31:14 -07002510done:
2511 pHddTdlsCtx->curr_candidate = NULL;
2512 pHddTdlsCtx->magic = 0;
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302513 EXIT();
Gopichand Nakkala75e7b282013-03-15 18:37:13 -07002514 return;
2515}
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002516
2517tANI_U32 wlan_hdd_tdls_discovery_sent_cnt(hdd_context_t *pHddCtx)
2518{
2519 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
2520 hdd_adapter_t *pAdapter = NULL;
2521 tdlsCtx_t *pHddTdlsCtx = NULL;
2522 VOS_STATUS status = 0;
2523 tANI_U32 count = 0;
2524
2525 status = hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
2526 while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
2527 {
2528 pAdapter = pAdapterNode->pAdapter;
2529
Hoonki Leea6d49be2013-04-05 09:43:25 -07002530 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2531 if (NULL != pHddTdlsCtx)
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002532 {
Hoonki Leea6d49be2013-04-05 09:43:25 -07002533 count = count + pHddTdlsCtx->discovery_sent_cnt;
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002534 }
2535 status = hdd_get_next_adapter ( pHddCtx, pAdapterNode, &pNext );
2536 pAdapterNode = pNext;
2537 }
2538 return count;
2539}
2540
Gopichand Nakkala34d1b062013-03-19 15:28:33 -07002541void wlan_hdd_tdls_check_power_save_prohibited(hdd_adapter_t *pAdapter)
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002542{
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +05302543 tdlsCtx_t *pHddTdlsCtx = NULL;
2544 hdd_context_t *pHddCtx = NULL;
Chandrasekaran, Manishekar41b8e1f2015-03-10 13:30:28 +05302545
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +05302546
2547 if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic))
2548 {
2549 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2550 FL("invalid pAdapter: %p"), pAdapter);
Chandrasekaran, Manishekar41b8e1f2015-03-10 13:30:28 +05302551 return;
2552 }
2553
2554 pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
2555 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002556
2557 if ((NULL == pHddTdlsCtx) || (NULL == pHddCtx))
c_hpothu7f63e882013-10-02 19:13:35 +05302558 {
2559 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2560 FL(" pHddCtx or pHddTdlsCtx points to NULL"));
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002561 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302562 }
Gopichand Nakkalaccd3a382013-03-19 13:56:10 -07002563
2564 if ((0 == pHddCtx->connected_peer_count) &&
2565 (0 == wlan_hdd_tdls_discovery_sent_cnt(pHddCtx)))
2566 {
2567 sme_SetTdlsPowerSaveProhibited(WLAN_HDD_GET_HAL_CTX(pHddTdlsCtx->pAdapter), 0);
2568 return;
2569 }
2570 sme_SetTdlsPowerSaveProhibited(WLAN_HDD_GET_HAL_CTX(pHddTdlsCtx->pAdapter), 1);
2571 return;
2572}
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002573
2574void wlan_hdd_tdls_free_scan_request (tdls_scan_context_t *tdls_scan_ctx)
2575{
2576 if (NULL == tdls_scan_ctx)
c_hpothu7f63e882013-10-02 19:13:35 +05302577 {
2578 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2579 FL("tdls_scan_ctx is NULL"));
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002580 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302581 }
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002582
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002583 tdls_scan_ctx->attempt = 0;
Hoonki Leefb8df672013-04-10 18:20:34 -07002584 tdls_scan_ctx->reject = 0;
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002585 tdls_scan_ctx->magic = 0;
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002586 tdls_scan_ctx->scan_request = NULL;
2587 return;
2588}
2589
2590int wlan_hdd_tdls_copy_scan_context(hdd_context_t *pHddCtx,
2591 struct wiphy *wiphy,
2592#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2593 struct net_device *dev,
2594#endif
2595 struct cfg80211_scan_request *request)
2596{
2597 tdls_scan_context_t *scan_ctx;
2598
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302599 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302600 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2601 {
c_hpothu7f63e882013-10-02 19:13:35 +05302602 return 0;
2603 }
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002604
2605 scan_ctx = &pHddCtx->tdls_scan_ctxt;
2606
2607 scan_ctx->wiphy = wiphy;
2608#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2609 scan_ctx->dev = dev;
2610#endif
2611
2612 scan_ctx->scan_request = request;
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302613
2614 EXIT();
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002615 return 0;
2616}
2617
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002618static void wlan_hdd_tdls_scan_init_work(hdd_context_t *pHddCtx,
2619 struct wiphy *wiphy,
2620#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2621 struct net_device *dev,
2622#endif
2623 struct cfg80211_scan_request *request,
2624 unsigned long delay)
2625{
2626 if (TDLS_CTX_MAGIC != pHddCtx->tdls_scan_ctxt.magic)
2627 {
2628#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2629 wlan_hdd_tdls_copy_scan_context(pHddCtx, wiphy, dev, request);
2630#else
2631 wlan_hdd_tdls_copy_scan_context(pHddCtx, wiphy, request);
2632#endif
2633 pHddCtx->tdls_scan_ctxt.attempt = 0;
2634 pHddCtx->tdls_scan_ctxt.magic = TDLS_CTX_MAGIC;
2635 }
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002636 schedule_delayed_work(&pHddCtx->tdls_scan_ctxt.tdls_scan_work, delay);
2637}
2638
2639/* return negative = caller should stop and return error code immediately
2640 return 0 = caller should stop and return success immediately
2641 return 1 = caller can continue to scan
2642 */
2643int wlan_hdd_tdls_scan_callback (hdd_adapter_t *pAdapter,
2644 struct wiphy *wiphy,
2645#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2646 struct net_device *dev,
2647#endif
2648 struct cfg80211_scan_request *request)
2649{
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002650 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2651 u16 connectedTdlsPeers;
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302652 hddTdlsPeer_t *curr_peer, *connected_peer;
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002653 unsigned long delay;
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302654 hdd_config_t *cfg_param = pHddCtx->cfg_ini;
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002655
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302656 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302657 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2658 {
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002659 return 0;
c_hpothu7f63e882013-10-02 19:13:35 +05302660 }
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002661
2662 /* if tdls is not enabled, then continue scan */
Pradeep Reddy POTTETIf0569d72014-12-13 16:54:03 +05302663 if ((eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode) ||
2664 (pHddCtx->is_tdls_btc_enabled == FALSE))
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002665 return 1;
Pradeep Reddy POTTETI9db32f02015-01-29 15:22:54 +05302666 curr_peer = wlan_hdd_tdls_is_progress(pHddCtx, NULL, 0, TRUE);
Hoonki Leefb8df672013-04-10 18:20:34 -07002667 if (NULL != curr_peer)
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002668 {
Hoonki Leefb8df672013-04-10 18:20:34 -07002669 if (pHddCtx->tdls_scan_ctxt.reject++ >= TDLS_MAX_SCAN_REJECT)
2670 {
2671 pHddCtx->tdls_scan_ctxt.reject = 0;
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302672 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Leefb8df672013-04-10 18:20:34 -07002673 "%s: " MAC_ADDRESS_STR ". scan rejected %d. force it to idle",
2674 __func__, MAC_ADDR_ARRAY (curr_peer->peerMac), pHddCtx->tdls_scan_ctxt.reject);
2675
Atul Mittal115287b2014-07-08 13:26:33 +05302676 wlan_hdd_tdls_set_peer_link_status (curr_peer,
2677 eTDLS_LINK_IDLE,
2678 eTDLS_LINK_UNSPECIFIED);
Hoonki Leefb8df672013-04-10 18:20:34 -07002679 return 1;
2680 }
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302681 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Leefb8df672013-04-10 18:20:34 -07002682 "%s: tdls in progress. scan rejected %d",
2683 __func__, pHddCtx->tdls_scan_ctxt.reject);
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002684 return -EBUSY;
2685 }
2686
2687 /* tdls teardown is ongoing */
2688 if (eTDLS_SUPPORT_DISABLED == pHddCtx->tdls_mode)
2689 {
2690 connectedTdlsPeers = wlan_hdd_tdlsConnectedPeers(pAdapter);
2691 if (connectedTdlsPeers && (pHddCtx->tdls_scan_ctxt.attempt < TDLS_MAX_SCAN_SCHEDULE))
2692 {
2693 delay = (unsigned long)(TDLS_DELAY_SCAN_PER_CONNECTION*connectedTdlsPeers);
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302694 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002695 "%s: tdls disabled, but still connected_peers %d attempt %d. schedule scan %lu msec",
2696 __func__, connectedTdlsPeers, pHddCtx->tdls_scan_ctxt.attempt, delay);
2697
2698 wlan_hdd_tdls_scan_init_work (pHddCtx, wiphy,
2699#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2700 dev,
2701#endif
2702 request,
2703 msecs_to_jiffies(delay));
2704 /* scan should not continue */
2705 return 0;
2706 }
2707 /* no connected peer or max retry reached, scan continue */
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302708 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002709 "%s: tdls disabled. connected_peers %d attempt %d. scan allowed",
2710 __func__, connectedTdlsPeers, pHddCtx->tdls_scan_ctxt.attempt);
2711 return 1;
2712 }
Agarwal Ashishef54a182014-12-16 15:07:31 +05302713
2714 /* if fEnableTDLSScan flag is 1 ; driverwill allow scan even if
2715 * peer station is not buffer STA capable
2716 *
2717 * RX: If there is any RX activity, device will lose RX packets,
2718 * as peer will not be aware that device is off channel.
2719 * TX: TX is stopped whenever device initiate scan.
2720 */
2721 if (pHddCtx->cfg_ini->fEnableTDLSScan == 1)
2722 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302723 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Agarwal Ashishef54a182014-12-16 15:07:31 +05302724 FL("Allow SCAN in all TDLS cases"));
2725 return 1;
2726 }
2727
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002728 /* while tdls is up, first time scan */
2729 else if (eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode ||
2730 eTDLS_SUPPORT_EXPLICIT_TRIGGER_ONLY == pHddCtx->tdls_mode)
2731 {
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002732 connectedTdlsPeers = wlan_hdd_tdlsConnectedPeers(pAdapter);
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302733
2734 /* check the TDLS link and Scan coexistance Capability */
2735 if ( (TRUE == pHddCtx->cfg_ini->fEnableTDLSScanCoexSupport) &&
2736 (TRUE == sme_IsFeatureSupportedByFW(TDLS_SCAN_COEXISTENCE)) &&
2737 (connectedTdlsPeers == 1) )
2738 {
2739 /* get connected peer information */
Pradeep Reddy POTTETIe309c152015-02-06 13:21:07 +05302740 connected_peer = wlan_hdd_tdls_get_connected_peer(pAdapter);
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302741 if (NULL == connected_peer) {
2742 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL,
2743 "%s: Invalid connected_peer, Continue Scanning", __func__);
2744 /* scan should continue */
2745 return 1;
2746 }
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302747 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302748 ("%s: TDLS Scan Co-exist supported connectedTdlsPeers =%d buffersta =%d"),
2749 __func__,connectedTdlsPeers,connected_peer->isBufSta);
2750
2751 if (connected_peer->isBufSta)
2752 {
2753 pHddCtx->isTdlsScanCoexistence = TRUE;
2754 if ((cfg_param->dynSplitscan) && (!pHddCtx->issplitscan_enabled))
2755 {
2756 pHddCtx->issplitscan_enabled = TRUE;
2757 sme_enable_disable_split_scan(
2758 WLAN_HDD_GET_HAL_CTX(pAdapter),
2759 cfg_param->nNumStaChanCombinedConc,
2760 cfg_param->nNumP2PChanCombinedConc);
2761 }
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302762 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302763 ("%s:%d TDLS Scan Co-exist supported splitscan_enabled =%d "),
2764 __func__, __LINE__, pHddCtx->issplitscan_enabled);
2765 return 1;
2766 }
2767
2768 }
2769 else
2770 {
2771 /* Throughput Monitor shall disable the split scan when
2772 * TDLS scan coexistance is disabled.At this point of time
2773 * since TDLS scan coexistance is not meeting the criteria
2774 * to be operational, explicitly make it false to enable
2775 * throughput monitor takes the control of split scan.
2776 */
2777 pHddCtx->isTdlsScanCoexistence = FALSE;
2778 }
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302779 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302780 ("%s: TDLS Scan Co-exist not supported connectedTdlsPeers =%d"
2781 " TDLSScanCoexSupport param =%d TDLS_SCAN_COEXISTENCE =%d"),
2782 __func__, connectedTdlsPeers,
2783 pHddCtx->cfg_ini->fEnableTDLSScanCoexSupport,
2784 sme_IsFeatureSupportedByFW(TDLS_SCAN_COEXISTENCE));
2785
Atul Mittal5803b342014-09-04 15:31:19 +05302786 /* disable implicit trigger logic & tdls operatoin */
2787 wlan_hdd_tdls_set_mode(pHddCtx, eTDLS_SUPPORT_DISABLED, FALSE);
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302788 /* fall back to the implementation of teardown the peers on the scan
2789 * when the number of connected peers are more than one. TDLS Scan
2790 * coexistance feature is exercised only when a single peer is
2791 * connected and the DUT shall not advertize the Buffer Sta capability,
2792 * so that the peer shall not go to the TDLS power save
2793 */
2794
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002795 if (connectedTdlsPeers)
2796 {
2797 tANI_U8 staIdx;
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002798 hddTdlsPeer_t *curr_peer;
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002799
2800 for (staIdx = 0; staIdx < HDD_MAX_NUM_TDLS_STA; staIdx++)
2801 {
2802 if (pHddCtx->tdlsConnInfo[staIdx].staId)
2803 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302804 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
2805 ("%s: indicate TDLS teardown (staId %d)"), __func__, pHddCtx->tdlsConnInfo[staIdx].staId) ;
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002806
2807#ifdef CONFIG_TDLS_IMPLICIT
Hoonki Leea6d49be2013-04-05 09:43:25 -07002808 curr_peer = wlan_hdd_tdls_find_all_peer(pHddCtx, pHddCtx->tdlsConnInfo[staIdx].peerMac.bytes);
2809 if(curr_peer)
2810 wlan_hdd_tdls_indicate_teardown(curr_peer->pHddTdlsCtx->pAdapter, curr_peer, eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON);
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002811#endif
2812 }
2813 }
2814 /* schedule scan */
2815 delay = (unsigned long)(TDLS_DELAY_SCAN_PER_CONNECTION*connectedTdlsPeers);
2816
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302817 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002818 "%s: tdls enabled (mode %d), connected_peers %d. schedule scan %lu msec",
2819 __func__, pHddCtx->tdls_mode, wlan_hdd_tdlsConnectedPeers(pAdapter),
2820 delay);
2821
2822 wlan_hdd_tdls_scan_init_work (pHddCtx, wiphy,
2823#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0))
2824 dev,
2825#endif
2826 request,
2827 msecs_to_jiffies(delay));
2828 /* scan should not continue */
2829 return 0;
2830 }
2831 /* no connected peer, scan continue */
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302832 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002833 "%s: tdls_mode %d, and no tdls connection. scan allowed",
2834 __func__, pHddCtx->tdls_mode);
2835 }
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302836 EXIT();
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002837 return 1;
2838}
2839
2840void wlan_hdd_tdls_scan_done_callback(hdd_adapter_t *pAdapter)
2841{
2842 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002843
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302844 ENTER();
c_hpothu7f63e882013-10-02 19:13:35 +05302845 if(0 != (wlan_hdd_validate_context(pHddCtx)))
2846 {
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002847 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302848 }
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002849
Pradeep Reddy POTTETIc7822df2015-02-19 20:15:41 +05302850 /* if tdls is not enabled or BtCoex is on then don't revert tdls mode */
2851 if ((eTDLS_SUPPORT_NOT_ENABLED == pHddCtx->tdls_mode) ||
Chandrasekaran, Manishekar0de84dc2015-03-10 15:12:34 +05302852 (pHddCtx->is_tdls_btc_enabled == FALSE)) {
2853 hddLog(VOS_TRACE_LEVEL_ERROR, FL("Failed to revert: Mode=%d, BTC enabled=%d"),
2854 pHddCtx->tdls_mode, pHddCtx->is_tdls_btc_enabled);
Pradeep Reddy POTTETIc7822df2015-02-19 20:15:41 +05302855 return;
Chandrasekaran, Manishekar0de84dc2015-03-10 15:12:34 +05302856 }
Sunil Dutt41de4e22013-11-14 18:09:02 +05302857
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002858 /* free allocated memory at scan time */
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002859 wlan_hdd_tdls_free_scan_request (&pHddCtx->tdls_scan_ctxt);
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002860
2861 /* if tdls was enabled before scan, re-enable tdls mode */
2862 if(eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode_last ||
2863 eTDLS_SUPPORT_EXPLICIT_TRIGGER_ONLY == pHddCtx->tdls_mode_last)
2864 {
Masti, Narayanraddi34e0e562015-03-05 18:23:03 +05302865 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002866 ("%s: revert tdls mode %d"), __func__, pHddCtx->tdls_mode_last);
2867
Gopichand Nakkaladcbcf4e2013-03-23 14:32:39 -07002868 wlan_hdd_tdls_set_mode(pHddCtx, pHddCtx->tdls_mode_last, FALSE);
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002869 }
2870 wlan_hdd_tdls_check_bmps(pAdapter);
Hanumantha Reddy Pothula7dc0e6c2015-03-06 15:11:16 +05302871
2872 EXIT();
Hoonki Lee93e67ff2013-03-19 15:49:25 -07002873}
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002874
2875void wlan_hdd_tdls_timer_restart(hdd_adapter_t *pAdapter,
2876 vos_timer_t *timer,
2877 v_U32_t expirationTime)
2878{
2879 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
2880
2881 if (NULL == pHddStaCtx)
c_hpothu7f63e882013-10-02 19:13:35 +05302882 {
2883 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2884 FL("pHddStaCtx is NULL"));
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002885 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302886 }
Gopichand Nakkala3046fc92013-03-23 13:56:43 -07002887
2888 /* Check whether driver load unload is in progress */
2889 if(vos_is_load_unload_in_progress( VOS_MODULE_ID_VOSS, NULL))
2890 {
2891 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
2892 "%s: Driver load/unload is in progress.", __func__);
2893 return;
2894 }
2895
2896 if (hdd_connIsConnected(pHddStaCtx))
2897 {
2898 vos_timer_stop(timer);
2899 vos_timer_start(timer, expirationTime);
2900 }
2901}
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002902void wlan_hdd_tdls_indicate_teardown(hdd_adapter_t *pAdapter,
2903 hddTdlsPeer_t *curr_peer,
2904 tANI_U16 reason)
2905{
Pradeep Reddy POTTETI8a623132014-06-26 16:07:06 +05302906 hdd_context_t *pHddCtx;
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302907
Hanumantha Reddy Pothulada0fe362015-02-27 18:37:03 +05302908 if ((NULL == pAdapter || WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic) ||
2909 (NULL == curr_peer))
c_hpothu7f63e882013-10-02 19:13:35 +05302910 {
2911 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
2912 FL("parameters passed are invalid"));
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002913 return;
c_hpothu7f63e882013-10-02 19:13:35 +05302914 }
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002915
Pradeep Reddy POTTETI8a623132014-06-26 16:07:06 +05302916 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2917
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002918 if (eTDLS_LINK_CONNECTED != curr_peer->link_status)
2919 return;
2920
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302921 /* Throughput Monitor shall disable the split scan when
2922 * TDLS scan coexistance is disabled.At this point of time
2923 * since TDLS scan coexistance is not meeting the criteria
2924 * to be operational, explicitly make it false to enable
2925 * throughput monitor takes the control of split scan.
2926 */
Pradeep Reddy POTTETI8a623132014-06-26 16:07:06 +05302927 if (pHddCtx && (pHddCtx->isTdlsScanCoexistence == TRUE))
Pradeep Reddy POTTETIedaeb5f2014-05-22 23:34:41 +05302928 {
2929 pHddCtx->isTdlsScanCoexistence = FALSE;
2930 }
2931
Atul Mittal115287b2014-07-08 13:26:33 +05302932 wlan_hdd_tdls_set_peer_link_status(curr_peer,
2933 eTDLS_LINK_TEARING,
Atul Mittal271a7652014-09-12 13:18:22 +05302934 eTDLS_LINK_UNSPECIFIED);
Gopichand Nakkalae7cbc5d2013-03-27 21:09:23 -07002935 cfg80211_tdls_oper_request(pAdapter->dev,
2936 curr_peer->peerMac,
2937 NL80211_TDLS_TEARDOWN,
2938 reason,
2939 GFP_KERNEL);
2940}
Atul Mittal115287b2014-07-08 13:26:33 +05302941
2942
2943/*EXT TDLS*/
2944int wlan_hdd_set_callback(hddTdlsPeer_t *curr_peer,
2945 cfg80211_exttdls_callback callback)
2946{
2947
2948 hdd_context_t *pHddCtx;
2949 hdd_adapter_t *pAdapter;
2950
2951 if (!curr_peer) return -1;
2952
2953 pAdapter = curr_peer->pHddTdlsCtx->pAdapter;
2954 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
2955 if ((NULL == pHddCtx)) return -1;
2956
2957 mutex_lock(&pHddCtx->tdls_lock);
2958
2959 curr_peer->state_change_notification = callback;
2960
2961 mutex_unlock(&pHddCtx->tdls_lock);
2962 return 0;
2963
2964
2965}
2966
2967void wlan_hdd_tdls_get_wifi_hal_state(hddTdlsPeer_t *curr_peer,
2968 tANI_S32 *state,
2969 tANI_S32 *reason)
2970{
2971 *reason = curr_peer->reason;
2972
2973 switch(curr_peer->link_status)
2974 {
2975 case eTDLS_LINK_IDLE:
Atul Mittal115287b2014-07-08 13:26:33 +05302976 case eTDLS_LINK_DISCOVERED:
2977 *state = WIFI_TDLS_ENABLED;
2978 break;
Atul Mittalad630e42014-10-07 19:19:14 +05302979 case eTDLS_LINK_DISCOVERING:
Atul Mittal115287b2014-07-08 13:26:33 +05302980 case eTDLS_LINK_CONNECTING:
2981 *state = WIFI_TDLS_TRYING;
2982 break;
2983 case eTDLS_LINK_CONNECTED:
Pradeep Reddy POTTETIf3148e82015-04-16 12:10:33 +05302984 if (TRUE == curr_peer->isOffChannelEstablished)
Pradeep Reddy POTTETI16d83332015-03-26 18:28:13 +05302985 {
2986 *state = WIFI_TDLS_ESTABLISHED_OFF_CHANNEL;
2987 }
2988 else
2989 {
2990 *state = WIFI_TDLS_ESTABLISHED;
2991 }
Atul Mittal115287b2014-07-08 13:26:33 +05302992 break;
2993 case eTDLS_LINK_TEARING:
2994 *state = WIFI_TDLS_DROPPED;
2995 break;
2996 }
2997
2998}
2999
3000int wlan_hdd_tdls_get_status(hdd_adapter_t *pAdapter,
3001 tANI_U8* mac,
3002 tANI_S32 *state,
3003 tANI_S32 *reason)
3004{
3005
3006 hddTdlsPeer_t *curr_peer;
Atul Mittala75fced2014-10-06 13:59:07 +05303007 hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Atul Mittal115287b2014-07-08 13:26:33 +05303008 curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, TRUE);
3009 if (curr_peer == NULL)
3010 {
Atul Mittala75fced2014-10-06 13:59:07 +05303011 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Atul Mittal115287b2014-07-08 13:26:33 +05303012 FL("curr_peer is NULL"));
Atul Mittal115287b2014-07-08 13:26:33 +05303013
Atul Mittala75fced2014-10-06 13:59:07 +05303014 *state = WIFI_TDLS_DISABLED;
3015 *reason = eTDLS_LINK_UNSPECIFIED;
3016 }
3017 else
3018 {
3019 if (pHddCtx->cfg_ini->fTDLSExternalControl &&
3020 (FALSE == curr_peer->isForcedPeer))
3021 {
3022 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3023 FL("curr_peer is not Forced"));
3024 *state = WIFI_TDLS_DISABLED;
3025 *reason = eTDLS_LINK_UNSPECIFIED;
3026 }
3027 else
3028 {
3029 wlan_hdd_tdls_get_wifi_hal_state(curr_peer, state, reason);
3030 }
3031 }
Atul Mittal115287b2014-07-08 13:26:33 +05303032 return (0);
3033}
3034
Agarwal Ashishef54a182014-12-16 15:07:31 +05303035int hdd_set_tdls_scan_type(hdd_adapter_t *pAdapter,
3036 tANI_U8 *ptr)
3037{
3038 int tdls_scan_type;
Hema Aparna Medicharla26b98042015-01-21 15:02:01 +05303039 hdd_context_t *pHddCtx;
Agarwal Ashishef54a182014-12-16 15:07:31 +05303040 if (NULL == pAdapter)
3041 {
3042 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3043 "%s: pAdapter is NULL", __func__);
3044 return -EINVAL;
3045 }
Hema Aparna Medicharla26b98042015-01-21 15:02:01 +05303046 pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
Agarwal Ashishef54a182014-12-16 15:07:31 +05303047 tdls_scan_type = ptr[9] - '0';
3048
3049 if (tdls_scan_type <= 2)
3050 {
3051 pHddCtx->cfg_ini->fEnableTDLSScan = tdls_scan_type;
3052 return 0;
3053 }
3054 else
3055 {
3056 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3057 " Wrong value is given for tdls_scan_type "
3058 " Making fEnableTDLSScan as 0 ");
3059 pHddCtx->cfg_ini->fEnableTDLSScan = 0;
3060 return -EINVAL;
3061 }
3062}
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +05303063int wlan_hdd_validate_tdls_context(hdd_context_t *pHddCtx,
3064 tdlsCtx_t *pHddTdlsCtx)
3065{
3066 VOS_STATUS status;
3067 int found = 0;
3068 hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
3069 hdd_adapter_t *pAdapter;
Agarwal Ashishef54a182014-12-16 15:07:31 +05303070
Mahesh A Saptasagar170b5082015-02-16 18:50:54 +05303071 if (NULL == pHddTdlsCtx)
3072 {
3073 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3074 FL("TDLS context is NULL"));
3075 return -EINVAL;
3076 }
3077 status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
3078 while (NULL != pAdapterNode && VOS_STATUS_SUCCESS == status)
3079 {
3080 pAdapter = pAdapterNode->pAdapter;
3081 if (NULL != pAdapter)
3082 {
3083 if (pHddTdlsCtx == pAdapter->sessionCtx.station.pHddTdlsCtx &&
3084 (NULL != pHddTdlsCtx->pAdapter) &&
3085 (WLAN_HDD_ADAPTER_MAGIC == pHddTdlsCtx->pAdapter->magic))
3086 {
3087 found = 1;
3088 break;
3089 }
3090 }
3091 status = hdd_get_next_adapter (pHddCtx, pAdapterNode, &pNext);
3092 pAdapterNode = pNext;
3093 }
3094 if (found == 1)
3095 {
3096 return 0;
3097 }
3098 else
3099 {
3100 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
3101 FL("TDLS context doesnot belongs to valid adapter"));
3102 return -EINVAL;
3103 }
3104}
Atul Mittal115287b2014-07-08 13:26:33 +05303105/*EXT TDLS*/
3106